VDBSequence

Play a NanoVDB frame sequence through one pool id, with a prefetch ring and no rebinds.

See it play in the EmberGen sequence demo (sparse, one pool id) and the explosion demo (dense, into the froxel renderer).

VDBSequence swaps each frame of an animation into one pool id with pool.replace(id, frame), scheduled by a prefetch ring and a frame-time clock. It does not touch three: the target is { pool, id }. It also plays dense .wvdb frames into a vdbDenseTextures source: new VDBSequence<WvdbDenseVolume>({ urls, loader }) and start({ source }) (see Froxel renderer).

The pool contract

Add the grid with capacity set to the largest frame. Then every replace writes in place: no move, no pool.version change, no VDBGridNode rebind and no new bind group. Per rendered frame:

  1. sequence.update(now) (may replace),
  2. pool.flush() (writes it),
  3. grids.update() (rebinds only after a growth),
  4. render.
import { NvdbFile } from '@pmndrs/vdb/tools';
import { VDBSequence } from '@pmndrs/vdb/three';

// Reserve the largest frame, so every replace() writes in place: no move, no `version` change,
// no rebind of the VDBGridNode, no new bind group.
const id = pool.add(firstFrame, { capacity: largestFrameBytes });

const sequence = new VDBSequence({
    urls: (index) => `/frames/smoke_${String(index).padStart(4, '0')}.nvdb`,
    frameCount: 120,
    fps: 24,
    prefetch: 4, // frames decoded ahead
    loopMode: 'repeat', // or 'pingpong', or 'once' (hold the last frame)
    // The default loader fetches and parses a .nvdb; override it to load from anywhere.
    loader: async (url) => (await NvdbFile.fromURL(url)).gridImage(0),
    onError: (error, index) => console.warn('frame', index, error),
});
await sequence.preload(); // the first frames, so playback starts without a stall
sequence.start({ pool, id });

// Each rendered frame: update() may replace() the grid, then flush and render as usual.
const frame = (now: number) => {
    sequence.update(now);
    pool.flush();
};

Options

OptionMeaning
urlsAn array, or a function of the frame index
frameCount, fpsLength and playback rate
prefetchFrames decoded ahead of the playhead
range[start, end], inclusive: play only these frames (default all of them)
loopModeAt the end of the range: 'repeat' (wrap, default), 'pingpong' (forward then backward; each end frame is shown once per turn) or 'once' (hold the last frame)
loader(url, index) => Promise<TFrame> (a grid image by default); the default fetches and parses a .nvdb; required for a { source } target
nowThe clock, default performance.now; pass your own to step deterministically
onFrame, onErrorStats after each swap, and per-frame load failures

stats reports frame, decodedAhead, stalls (a swap that had to wait for a decode), replaceMs, swaps and failed. Control it with start(target, now?), stop(), resume(), seek(index), preload(count?) and dispose(). A seek (before or after a stop()) shows the frame once it is decoded; a frame the clock made due that is still decoding when you stop() is not shown later. A seek is wrapped into the clip, then clamped into the range. setRange([start, end]) and setLoopMode(mode) change them while playing (playback continues from the shown frame, clamped into the new range); range and loopMode read them back. Switching to 'once' past the end holds there, and back to 'repeat' plays on. A ping-pong keeps its direction across stop() / resume(), seek() and setRange(). A bad range or mode throws VDB_BAD_OPTION.

A dense frame with another .wvdb box moves a VDBFrameVolume's box with it (each frame keeps its own world box, so the voxels do not stretch), unless the volume was given a bbox.