Cinematics — animation as a reading tool
A 3-D graph drawn on a flat screen throws away the axis it was drawn for. Depth comes back from motion, and that is what this module is for. The sci-fi styling is a side effect: honest 3-D navigation has always looked like this on film, for the same reason.
| What you cannot tell from a still frame | What answers it |
|---|---|
| Are these two nodes touching, or a thousand units apart? | orbit — parallax |
| Which cluster is in front? | <ScanPlaneLayer> — light one slab at a time |
| Where does this path actually go? | flyPath — fly it |
| How big is this neighbourhood, and in which directions? | <RadarSweepLayer> |
| How does the place I just jumped to relate to where I was? | warpTo + <WarpTunnelLayer> |
| Are the neighbours right behind this node or far back? | orbit, or a <ScanPlaneLayer> sweep |
Everything here is a layer or a pure function over the public extension points. No engine core changes, and nothing here moves the camera — the engine animates by moving the scene, and so does all of this.
Quick start
import { createCinematics, WarpTunnelLayer } from '@kineviz/gl';
const cine = createCinematics(api); // mounts one layer, draws nothing
await cine.establish(); // open on the whole graph
await cine.flyPath(['a', 'b', 'c', 'd']); // walk a path, holding at each hop
cine.playing; // is a shot running?
await cine.warpTo('z'); // jump, with streaks
cine.orbit('hub'); // park in an orbit (runs until stopped)
cine.stop();
cine.dispose(); // the view stays where it was left
// The streaks read their intensity from the director every frame, so they
// cannot drift out of step with the jump.
<GraphCanvas /* … */>
<WarpTunnelLayer intensity={() => cine.warp} />
</GraphCanvas>
Every method returns a promise that resolves when the move lands. A new move replaces whatever was playing; the interrupted promise resolves rather than being stranded.
The shots
| Method | Shot | Notable options |
|---|---|---|
flyPath(target, opts) |
Catmull-Rom through the hops, with a hold at each one — the hold is when the viewer actually reads the node | heading: "lead" | "chase" | "keep", dwell, travel, distance, bank, onWaypoint |
cuePath(target, opts) |
The same flight, installed but not running, for a host that owns the clock | everything flyPath takes |
orbit(target, opts) |
Circle the target. turns: Infinity by default |
period, turns, tilt, reverse |
warpTo(target, opts) |
Recoil → run → land, publishing warp for the streak layer |
duration, recoil, fovKick |
establish(target, opts) |
High, wide, off to one side, then descend | duration, tilt, pullback, fovWide |
frame(target, opts) |
Ease to a framed hold and level the horizon | duration, padding, level |
target is a node id, an array of ids, an array of THREE.Vector3, or omitted
for the whole graph. Unknown ids are dropped; an empty target resolves
immediately rather than hanging.
heading: "chase" turns the graph so the next hop comes at the camera — the
cockpit shot. It wants a layout with depth; on a flat 2-D layout it puts the
sheet edge-on, which is why the default is "lead" (it only leans).
Waypoints — what makes a flight an analysis tool
onWaypoint fires each time the flight reaches a hop, and with null when it
is scrubbed back before the first one. Everything that should happen at a node
hangs off it, on the flight's own clock, so it cannot drift out of step with
what is on screen:
await cine.flyPath(route, {
onWaypoint: (hit) => {
if (!hit) return clearPanel();
showCard(hit.nodeId); // null when the target was raw points
log(`hop ${hit.index} at ${hit.at}ms, leaves at ${hit.leaves}ms`);
},
});
| Field | Meaning |
|---|---|
index |
index into the target as you gave it |
nodeId |
the node id, or null for a raw point |
point |
where it is, in scene-local space |
at |
ms into the flight at which this waypoint is reached |
leaves |
ms at which the flight moves on again |
Without this, a caller has to run a second timer alongside the shot and guess at the leg lengths.
Binding a flight to data time
An analyst has exactly one clock, and it is the clock in the data. A played
flight runs on its own time, and the two have to be reconciled by hand every
time. cuePath builds the same flight but does not run it — you say what "now"
is, which makes a timeline cursor and a camera the same gesture:
const flight = cine.cuePath(route, { onWaypoint: (hit) => showCard(hit?.nodeId) });
api.timeline.onCursorChange((t) => flight.scrubFraction((t - t0) / (t1 - t0)));
interface CuedFlight {
readonly duration: number; // ms — the domain scrub() expects
scrub(ms: number): void; // idempotent, and fine to run backwards
scrubFraction(t: number): void; // the same by fraction, 0..1
release(): Promise<void>; // hand it back to the clock and play out from here
cancel(): void; // drop it; the view stays where the last scrub left it
}
cuePath returns null when the target resolves to nothing.
Layers
<ScanPlaneLayer>
A lit sheet sweeps one axis; nodes it crosses glow, with a Gaussian falloff so they brighten and fade rather than pop.
<ScanPlaneLayer
axis="z" period={7000} color="#38bdf8"
onSlice={(ids, position) => setPanel(ids)} // the analysis half
/>
mode="hold" with position parks the sheet so a slider can drive it.
onSlice is throttled to ~8/s and only fires when the contents change.
<RadarSweepLayer>
A beam sweeps out from a node, a point, or the middle of the graph. Each node flashes on contact and decays with how long ago the beam passed, so one revolution orders the whole neighbourhood by bearing; the range rings give it a scale.
<RadarSweepLayer origin="hub" period={5000} rings={5} onSweep={ids => list(ids)} />
<WarpTunnelLayer>
A screen-pinned streak overlay. It is the one layer that does not live in
the graph's space — its vertex shader writes gl_Position straight from the
vertex, ignoring the model and view matrices, so it stays nailed to the screen
while the director moves the scene underneath. At zero intensity it draws
nothing and stops asking for frames.
Both node-lit layers draw through createNodeShaderLayer, so any number of
nodes costs one draw call.
Layouts built to be flown
import { registerCinematicLayouts } from '@kineviz/gl';
registerCinematicLayouts(api); // once
await api.layout.applyByName('gl:helix', undefined, { turns: 8, axis: 'z' });
await api.layout.applyByName('gl:shells', undefined, { roots: ['hub'] });
gl:helix— an ordered sequence on a tube along the view axis: compact on screen, strictly ordered, and you can fly down the middle of it.strands: 2is the DNA look.orderis a callback, and it is the only place this module touches anything business-specific.gl:shells— radius is hop distance from a root. "How far is this from that" stops being something you trace by eye. Each shell is a Fibonacci sphere, so there is no bunching at the poles. Pair it withorbit: the shells come apart under parallax.
Both are ordinary pure layout functions (helixLayout, shellLayout), usable
directly if you would rather not register them.
Writing your own shot
A shot is just a duration and a sampler, so you do not need an extension point:
import { makeShotFrame } from '@kineviz/gl';
const spin = {
name: 'spin',
duration: 4000,
sample(ms, out) {
out.focus.set(0, 0, 0);
out.orientation.setFromAxisAngle(new THREE.Vector3(0, 1, 0), ms / 600);
out.distance = 800;
out.fov = null; // leave the lens alone
out.warp = 0;
},
};
await cine.director.play(spin);
How it works, and why it is a layer
The engine's camera never moves. It sits at (0, 0, cameraZ) looking down
−z, and cloudScene is what pans, zooms and turns. camera.flyTo works out a
delta from where the scene is now — right for one hop, wrong for a shot:
deltas accumulate, so a 90-frame flight drifts and cannot be re-sampled,
scrubbed or interrupted cleanly.
That delta formula has a fixed point, and the director assigns it every frame instead:
cloudScene.position = −(R·S·focus) + (0, 0, cameraZ − distance)
Applying it twice changes nothing, so a shot is a pure function of elapsed time
and the timeline is scrubbable by construction. The director is therefore an
ordinary LayerRenderer that draws nothing — no core change, and it composes
with every other layer.
The camera is not yours
The engine's camera belongs to the host. Map mode captures and restores it,
setViewState writes its z, and every effect in this engine — ripples, edge
flow, emphasis, the layouts, these shots — animates by moving the scene. So
the director writes cloudScene and nothing else, and there is no setting that
changes that by accident.
The one exception is quarantined. A true dolly zoom cannot be done with the
scene transform, and the reason is worth knowing, because it is the same reason
a scene scale cannot stand in for a lens anywhere else: scaling the scene
scales the depth separations with it. With scale S = c·d, a background node
at local depth δ sits at camera distance d + S·δ, so its size relative to
the subject is
d / (d + S·δ) = 1 / (1 + c·δ)
— independent of d. Move in as far as you like; the perspective compression
does not budge. Only camera.fov moves it.
So dollyZoomShot is exported from shots.ts but is deliberately not on
the createCinematics surface. A host that wants it opts in and owns the
consequences:
cine.director.update({ allowLens: true });
await cine.director.play(dollyZoomShot(centre, cine.director.captureStart()));
cine.stop(); // puts the lens back
See also
- Scenario: cinematic flythrough — every shot, both overlays and both layouts, on one page.
- Custom layers for the layer contract the director follows.
api.camerafor single, non-cinematic moves.- Node appearance — a flight holds far from
the graph, so
api.renderer.setNodeSizeScaleis usually what keeps nodes legible in flight.