Camera controls
OrbitControls from @typeshade/radiance-addons moves a camera about a target. Its names
follow three.js’s OrbitControls.
import { OrbitControls } from '@typeshade/radiance-addons';
const controls = new OrbitControls(camera, canvas);controls.target.set(0, 0.5, 0);controls.update();controls.saveState();
renderer.setAnimationLoop(async () => { controls.update(clock.getDelta()); renderer.preview = controls.moving ? 4 : 1; await renderer.render(scene, camera);});| Input | Move |
|---|---|
| Drag, or one finger | orbit about the target |
| Right drag, middle drag, or Shift and drag | pan: the target slides with the pointer |
| Wheel, or a trackpad pinch | dolly toward or away from the target |
| Two fingers | dolly and pan together |
| Double-click, R or Home | back to the saved view |
| Arrow keys, with Shift to pan. + and - | a step of each move |
A turn let go with speed keeps turning and slows down, as a turntable does, while
enableDamping is on.
Limits
Section titled “Limits”| Property | What it bounds |
|---|---|
minDistance, maxDistance |
the distance from the target |
minPolarAngle, maxPolarAngle |
the angle from straight up, in radians |
minAzimuthAngle, maxAzimuthAngle |
the turn about +y, in radians |
targetBounds |
a Box3 the target stays in when panning |
By default, the polar angle keeps a margin of 0.01 radian from each pole, so the view never flips.
The azimuth has no limit. Every example sets the distance, from 0.05 to 50 scene units. The two
Cornell box examples also set targetBounds. A drag can look at a scene from below, from the side
and from behind. A wheel turn can go inside the Cornell box or far outside it.
Events and state
Section titled “Events and state”update(dt)advances a coasting turn, places the camera, and answers whether it moved.movingis true while a pointer is down, the turn coasts, or a wheel just turned.start,changeandendfire throughaddEventListener.saveState()remembers the view.reset()returns to it.dispose()removes the listeners.
Fly controls
Section titled “Fly controls”FlyControls moves a camera freely, as a first-person view does. It has the contract of
OrbitControls: update(dt), moving, the events start, change and end, saveState(),
reset() and dispose().
import { FlyControls } from '@typeshade/radiance-addons';
const fly = new FlyControls(camera, canvas);fly.movementSpeed = 3;
renderer.setAnimationLoop(async () => { fly.update(clock.getDelta()); renderer.preview = fly.moving ? 4 : 1; await renderer.render(scene, camera);});| Input | Move |
|---|---|
| Drag, or one finger | look around: yaw about world up, pitch limited to 89 deg |
| W and S | forward and back along the view direction |
| A and D | strafe left and right |
| Q and E | down and up along world up |
| Left or right Shift | four times the speed |
movementSpeedis the speed of a key in scene units a second. The default is 1.rotationSpeedis the turn of a drag in radians for each pixel. The default is 0.0025.- Movement uses
dt, so the speed does not depend on the frame rate. - There is no collision, so the camera may pass through a wall.
- There is no pointer lock. A drag on the canvas turns the view, and no click is needed first.
- The keys are read by
KeyboardEvent.code, while the canvas or its page has focus.
The Sponza example starts in fly mode. The key F swaps it to the orbit controls and back, and the camera keeps its place and look. The inactive controls are disabled, not removed. The other examples keep the orbit controls only.