Skip to content

Tutorial

Coordinates and cameras

Every scene uses the same axes: x to the right, y into the scene, z up. axes() draws them, so a reader never has to guess.

Where things go
Where things gox runs right, y runs into the scene, z runs up. Always.yy = 3xx = 3z = 2z

Drag to turn, scroll or pinch to zoom, double click to reset.

Objects sit on the ground. box({ at: [x, y, 0] }) puts the centre of the box’s base at that point, so at is where it stands. A flat diagram is a scene seen from the front, with y as depth you do not use.

The default camera is parallel (axonometric): lines that are parallel in the scene stay parallel on the page. This is the look of technical illustration, and the one where placing things on planes is exact.

A parallel camera
A parallel cameraYaw and pitch set the angle. Parallel lines stay parallel.yxz

Drag to turn, scroll or pinch to zoom, double click to reset.

import { Scene } from 'cseen';
// 'iso' | 'front' | 'side' | 'top'
const s = new Scene({ view: 'top' });
// or explicit angles in degrees
const t = new Scene({ view: { yaw: 40, pitch: 20 } });

Yaw turns the scene about the vertical axis. Pitch tips it towards the viewer: 0 looks along the ground, 90 looks straight down. The window controls above each demo (Iso, Front, Side, Top) set these.

For a vanishing point, use a pinhole camera. This is the same scene as above, seen from a point in space: compare the two.

A perspective camera
A perspective cameraThe same scene from a pinhole camera: distant things get smaller.yzx

Drag to turn, scroll or pinch to zoom, double click to reset.

import { Scene, Camera } from 'cseen';
const s = new Scene({
view: Camera.perspective({ position: [5, -9, 5], target: [0, 0, 1], fov: 35 }),
});

Try the Perspective button on any demo. Two things behave differently under perspective: an imported SVG can only be sheared by the renderer, so it is cut into small pieces and approximated, and charts placed on planes are approximate for the same reason.

You wantUse
A technical illustration, exact placement on planesparallel: view: 'iso' or { yaw, pitch }
A flat diagramparallel: view: 'front' or 'top'
Depth and a sense of spaceCamera.perspective(...)
The reader chooses the angleeither, plus orbit controls

A camera is animatable like anything else: yaw, pitch and zoom for a parallel camera, position, target and fov for a perspective one.

import { Scene, Timeline, tween } from 'cseen';
const s = new Scene();
const tl = new Timeline();
tl.play(tween(s.camera, { yaw: 120, pitch: 40 }, { duration: 2 }));
Moving the camera
Moving the cameraThe camera animates with the same tween as everything else.xzy

Drag to turn, scroll or pinch to zoom, double click to reset.

By default the scene is refitted to its contents every frame. Two alternatives keep the picture steady:

  • tl.lockFit(scene) fixes the framing to fit every moment of a timeline.
  • fit: 'sphere' frames the bounding sphere, so the object keeps its size however the camera turns. Use it with orbit controls.

The figure above does both: drag it and the scene keeps its size, and the timeline never crops it.