SplineDolly

Moves the camera along a path.

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

SettingDescriptionDefault
splineThe path. See The path.
closedthree.js and React only. Whether a path given as points loops back to the first one.false
tensionthree.js and React only. How sharply a path given as a curve or points turns at each knot. See The path.0
positionWhere on the path the camera is, in positionUnits.0
positionUnits'normalized', 'distance' or 'knot'. See Position.'normalized'
splineOffsetOffset from the path: x to the side, y up, z along it.[0, 0, 0]
dampingSeconds to travel to a new position along the path. 0 is instant. See Damping.0
automaticDollyMoves the camera by itself. See automaticDolly.null
targetWhat nearestPointToTarget keeps level with. See Targets.
debugReact only. Draws the path. See Debugging.false

Position

positionUnits sets what position counts:

Unitsposition isEnd of the path
'normalized'How far along the path, from 0 to 1.1
'distance'Distance from the start, in world units.Its length
'knot'The knot the camera is at: 2 is the third knot, 2.5 halfway to the fourth.Number of knots, or one less on an open path

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

MethodMoves the camera
{ method: 'fixedSpeed', speed }By speed positions per second, starting from position each time its camera becomes the active one. It stops at the end of an open path and goes round a closed one.
{ method: 'duration', from, to, duration, curve, loop }From from to to in duration seconds, along a blend curve, linear by default. It starts over each time its camera becomes the active one, also on a cut in a SequencerCamera, so each shot plays from its start. loop is 'once', 'loop' or 'pingPong'.
{ method: 'nearestPointToTarget', positionOffset, searchResolution, searchIteration }To the point of the path nearest the target, positionOffset positions further on. searchResolution is how many points it tries on each stretch between knots, 4 by default, and searchIteration how many times it then looks closer, 2 by default.

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, and spline.pointAt, spline.tangentAt, spline.nearest and the unit conversions read it.
  • In three.js, SplineDollyBodyThree takes the path as a CatmullRomCurve3, as points, or as a built path. createSpline(curve) builds one to set on body.spline later.
  • In React, spline takes a curve, points or a built path. The path is built again when the spline, closed or tension prop 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();