Animations
Thermion supports three kinds of animation, all driven through the ThermionAsset
returned by viewer.loadGltf(...):
- glTF animations — skeletal/morph animations baked into the glTF file.
- Morph targets — manually driving individual morph target weights.
- Bone animation — manually constructing per-bone animation frame data.
glTF animations
Section titled “glTF animations”A glTF asset can embed one or more named animations. List them, then play by index or name:
final asset = await viewer.loadGltf("assets/character.glb");
final names = await asset.getGltfAnimationNames();// e.g. ["Walk", "Run", "Idle"]
final duration = await asset.getGltfAnimationDuration(0); // seconds
await asset.playGltfAnimation(0, crossfade: 0.2, // seconds to blend in replaceActive: true, // stop other animations loop: true,);
// laterawait asset.stopGltfAnimation(0);// or by name:await asset.stopGltfAnimationByName("Walk");To advance playback, call FilamentApp.instance!.animationManager.update(dt)
each frame — this advances all active animations on the render thread.
You can also scrub to a specific time with setGltfAnimationTime(index, seconds).
Morph targets
Section titled “Morph targets”Morph targets let you blend between vertex states (e.g. facial expressions). Discovering them returns both the renderable entity and an ordered list of targets, so you do not need to guess which entity owns them or how long a weight list should be:
final asset = await viewer.loadGltf("assets/cube_with_morph_targets.glb");
final morphs = (await asset.getMorphTargetSets()).single;for (final target in morphs.targets) { print('${target.index}: ${target.name ?? '(unnamed)'}');}
// Named and indexed updates leave all other target weights unchanged.await morphs.setWeight('Open', 1.0);await morphs.setWeightAt(1, 0.25);
// A complete pose must contain exactly one value per target, in target order.await morphs.setAllWeights(List.filled(morphs.targets.length, 0.0));Use asset.getMorphTargets(entity) when you already know the renderable entity.
Target names are optional, so indexed updates remain available for procedural or
unnamed targets. Weights must be finite; 0.0 is the base shape and 1.0 fully
applies a target.
For keyframed morph animation, build a MorphAnimationData and pass it to
setMorphAnimationData. An active animation writes its target weights on every
animation tick, so a manual setWeight, setWeightAt, or setAllWeights call
is temporary for any target that animation controls. Stop custom morph
animations before taking persistent manual control:
await asset.clearMorphAnimationData(morphs.entity);await morphs.setWeight('Open', 0.8);When multiple custom morph animations control the same target, the most
recently added animation has priority. clearMorphAnimationData clears all
custom morph animations for the entity; it does not stop morph channels in an
active glTF animation.
Bones / skeletal animation
Section titled “Bones / skeletal animation”You can inspect and directly animate a skeleton:
final bones = await asset.getBones(); // List<ThermionEntity>final boneNames = await asset.getBoneNames(); // List<String>final count = await asset.getBoneCount();To play a custom bone animation, reset bones to their rest pose first, then enqueue the animation:
await asset.resetBones();await asset.addBoneAnimation(animation); // BoneAnimationDataBy default, bone animation frame data is interpreted in bone space
(Space.Bone): each bone’s transform is anchored at its rest-position root,
with Y pointing towards the bone’s “tail”, so “rotate around X” means “rotate
this bone around its local X axis in its rest position”. BoneAnimationData
also accepts space: Space.ParentWorldRotation — a rotation around the bone’s
parent’s origin, but around world-space axes (this is how BVH data describes
each bone’s rotation) — plus Space.World and Space.Model.
You can also set a bone’s transform directly with
setBoneTransform(boneEntity, Matrix4 transform).
- Call
asset.addAnimationComponent()to attach an animation component if one isn’t present, andremoveAnimationComponent()to detach it. - Don’t call animation methods while the app is backgrounded — see the Animations when backgrounded footgun.
- A runnable example mixing glTF animations and morph targets is in
examples/flutter/animations.
