AnimationPlayer class final

Plays AnimationClips onto animation targets.

The player writes through setPosition / setRotation / setScale, which is all it has to do: the version counters on a scene node make everything derived from a transform — world matrices, bounds, normal matrices — refresh on their own. There is no invalidation to remember and no update pass to run in the right order.

One clip at a time, crossfading between two: crossFadeTo keeps the clip being left over playing while the new one comes in, because cutting straight to the new pose is what makes a character look as though it teleports between animations.

And layers over the top of that, each one a clip on the joints its mask names — an upper body that reloads while the legs keep running. A crossfade moves the whole skeleton; a layer moves part of it and leaves the rest alone. See AnimationLayer, which says why it overrides rather than adds, and AnimationMask, which says why a mask is indices.

The base is applied first and a layer writes over it, so a player with no layers poses exactly as it did before there were any — animation_layer_test holds that, because a feature that moved every existing character by a hair would have been a feature that moved every golden.

Additive blending is still a separate feature. What is missing above this is a state machine that decides which clip — that belongs to the game layer, not here.

Constructors

AnimationPlayer({required List<AnimationClip> clips, required List<AnimationTarget?> targets, List<MorphSink?>? morphs})

Properties

clip AnimationClip?
no setter
clipIndex int
no setter
clipNames List<String>
Names of the clips, for a UI that lets the user pick one.
no setter
clips List<AnimationClip>
final
duration double
no setter
fadeWeight double
How far the crossfade has come, from 0 (all the old clip) to 1 (all the new one).
no setter
hasClips bool
no setter
hashCode int
The hash code for this object.
no setterinherited
isCrossFading bool
Whether a crossfade is in progress.
no setter
isPlaying bool
no setter
layers List<AnimationLayer>
Clips playing over the base, in the order they are written.
final
morphs List<MorphSink?>
Where a weights track goes, index-aligned with targets.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
speed double
Playback rate. Negative values run the clip backwards.
getter/setter pair
targets List<AnimationTarget?>
Node for each index a track can address, null where the instance created none. Index-aligned with the model's node list, which is what an animation channel addresses.
final
time double
Current playhead position in seconds.
no setter
wrap AnimationWrap
getter/setter pair

Methods

addLayer(AnimationLayer layer) AnimationLayer
Adds layer and returns it, for the one-liner a caller usually wants.
apply() → void
Writes the pose at the current time onto the target nodes.
crossFadeTo(int index, {double duration = 0.15}) → void
Switches to index, blending out of whatever is playing.
crossFadeToNamed(String name, {double duration = 0.15}) bool
Fades to the clip called name, if there is one.
layerOf(int clip) AnimationLayer?
The first layer playing clip, or null.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pause() → void
play([int? index]) → void
Starts a clip by index, or resumes the current one when index is null.
playLayer(int clip, {AnimationMask? mask, AnimationWrap wrap = AnimationWrap.once, double fadeIn = 0.15, double speed = 1.0}) AnimationLayer
Starts clip over mask and returns the layer driving it.
playNamed(String name) bool
Starts the first clip whose name matches, returning false when there is none.
seek(double seconds) → void
Moves the playhead, clamped to the clip, and applies the pose.
stop() → void
Stops and rewinds, leaving the first pose applied.
toString() String
A string representation of this object.
override
update(double deltaSeconds) → void
Advances by deltaSeconds and applies the resulting pose.

Operators

operator ==(Object other) bool
The equality operator.
inherited