Skip to main content

Baked GPU Scenegraph Animation

Baked playback samples resolved scenegraph pose tracks once. The vertex shader then interpolates the baked transforms, joint palettes, and morph weights while the existing ScenegraphAnimator advances playback. Programmatic scenes and imported scenes use the same engine API.

Plan and bake a scene​

Create pose tracks with makeNodeAnimationBinding(). Translation, rotation, scale, and morph weight tracks can be baked. Visibility, interaction, and custom property tracks stay in the live mixer.

import {
AnimationClip,
AnimationMixer,
AnimationTrack,
GroupNode,
MixerAnimationClip,
ScenegraphAnimator,
ScenegraphGPUAnimationResources,
bakeScenegraphGPUAnimation,
getScenegraphGPUPlaybackClip,
makeNodeAnimationBinding,
planScenegraphGPUAnimation
} from '@luma.gl/engine';

const node = new GroupNode();
const clip = new AnimationClip({
name: 'move',
tracks: [
new AnimationTrack({
times: [0, 1],
values: [[0, 0, 0], [2, 0, 0]],
binding: makeNodeAnimationBinding(node, 'translation')
})
]
});

const {layout, fallbackReason} = planScenegraphGPUAnimation(
[clip],
[{jointCount: 0, morphTargetCount: 0}],
{sampleRate: 30},
device
);

const mixer = new AnimationMixer();
const playbackClip = layout ? getScenegraphGPUPlaybackClip(clip) : clip;
const animator = new ScenegraphAnimator(
[new MixerAnimationClip(playbackClip, mixer)],
mixer,
{autoplay: 'first'}
);

if (layout) {
const resources = new ScenegraphGPUAnimationResources(device, layout, 0, 0);
const updatePlayback = bakeScenegraphGPUAnimation({
scenes: [node],
clips: [clip],
layout,
targets: [{node, resources}]
});

const update = () => updatePlayback(animator);
animator.setUpdateHandler(update);
update();
// Attach resources to the primitive model using the configuration below.
} else {
console.debug('Using CPU playback', fallbackReason);
}

animator.update(deltaSeconds);

Use the original clips for baking and the playback clips for the live mixer. Pass each primitive's atlas size to the planner. The planner reports a reason when a request exceeds the frame budget, GPU byte budget, or device limits. The CPU staging arrays use additional memory. For a skinned scene, pass the resolved SkinBinding objects as skins and include their joint counts in the primitive layouts. The bake reads morph weights from the bound node.

Bind the baked pose to a model​

Add the gpuAnimation module from @luma.gl/shaders to a model. Merge resources.defines, resources.attributes, resources.bufferLayout, and resources.bindings into its configuration. The frame attributes advance per instance. For a single primitive, use one instance.

In the vertex shader, pass instanceAnimationFrames and instanceAnimationBlend to sampleGPUAnimationMatrix. The WGSL function takes the first atlas column and resources.animationFrameStride as its last two arguments. Use column zero for the node matrix. GLSL uses the configured frame stride. WebGPU reads a storage buffer and WebGL2 reads a float texture. Set relativeToBindPose: true on a target if your draw path already applies its authored bind transform.

The caller owns ScenegraphGPUAnimationResources. Give the resources to a ModelNode in managedResources or call resources.destroy() when the model is finished.

Playback behavior​

The GPU path supports one selected clip and one crossfade. Pose sampling changes GPU rendering while CPU node transforms and bounds stay at the authored pose. Use CPU playback when attachments, picking, or other systems need the current CPU pose. The sample rate trades memory for accuracy. Interpolation between baked matrices can differ from interpolation of the original keyframes.