SplineDolly
Moves the camera along a path, like a camera on a dolly track or a crane. Set where it is with position, or let it move by itself: at a fixed speed, from one point to another in a set time, or level with a target. Good for shots with their own movement, fly-throughs, tours driven by scrolling or by slide, and cameras riding a rail next to something.
The path is a smooth curve through its knots, the same one three.js draws with a CatmullRomCurve3. Pair the Body with an Aim: SplineDollyLookAtTargets looks along the path or at points placed along it, HardLookAt keeps a subject in the middle. SplineRoll banks the path like a roller coaster.
Settings
Position
positionUnits sets what position counts:
On an open path, positions past the ends stop at them. On a closed one they go round: 1.25 in 'normalized' is the same spot as 0.25. The camera travels the way position changes, so from 0.9 it goes forward through the start to 1.1, and back through the middle to 0.1.
body.state.distance is the distance along the path the camera is at after damping, and body.state.position the position it heads to, in positionUnits.
automaticDolly
position stays as you set it while the camera moves by itself. With null, the camera goes back to position.
Damping
damping eases the camera along the path. The first frame after the camera turns on goes straight to its position. With a position in the camera's initialState, the first activation starts from the point of the path nearest to it instead.
remaining() tells how far the eased camera still has to go, in positionUnits, and is 0 once it arrives. Use it to wait for the camera, for example before switching to the next shot. In core, splineDolly.remaining(state, params) does the same.
The path
The path is built once from its knots. To change it, build a new one.
tension sets how sharply the path turns at its knots: one value for all of them, or an array with one per knot. At 0 the curve rounds through a knot, toward 1 the turn tightens, and at 1 it becomes a sharp corner. Knots missing from the array keep 0.
- In core,
spline.create(knots, { closed, tension })builds it, andspline.pointAt,spline.tangentAt,spline.nearestand the unit conversions read it. - In three.js,
SplineDollyBodyThreetakes the path as aCatmullRomCurve3, as points, or as a built path.createSpline(curve)builds one to set onbody.splinelater. - In React,
splinetakes a curve, points or a built path. The path is built again when thespline,closedortensionprop changes, not when its points move.
Usage
import { spline, SplineDollyBody, SplineDollyLookAtTargetsAim } from '@pmndrs/klipp';
const path = spline.create(
[
[-8, 2, 6],
[0, 3, 9],
[8, 2, 6],
],
{ tension: [0, 0.5, 0] },
);
camera.body = new SplineDollyBody({
spline: path,
automaticDolly: { method: 'duration', from: 0, to: 1, duration: 6 },
});
camera.aim = new SplineDollyLookAtTargetsAim();
import { CatmullRomCurve3, Vector3 } from 'three';
import { SplineDollyBodyThree, SplineDollyLookAtTargetsAimThree } from '@pmndrs/klipp/three';
const curve = new CatmullRomCurve3([new Vector3(-8, 2, 6), new Vector3(0, 3, 9), new Vector3(8, 2, 6)]);
camera.body = new SplineDollyBodyThree({
spline: curve,
automaticDolly: { method: 'duration', from: 0, to: 1, duration: 6 },
});
camera.aim = new SplineDollyLookAtTargetsAimThree();
const track: [number, number, number][] = [
[-8, 2, 6],
[0, 3, 9],
[8, 2, 6],
];
<VirtualCamera name="track" priority={10}>
<Body.SplineDolly spline={track} automaticDolly={{ method: 'duration', from: 0, to: 1, duration: 6 }} />
<Aim.SplineDollyLookAtTargets />
</VirtualCamera>
ref gives you the SplineDollyBodyThree.