update method
Advances all registered clips by deltaSeconds and applies their
blended result to the bound nodes.
Resets each animated node to its bind pose, advances every clip by
the delta, normalizes weights when their sum exceeds 1, and then
writes the resulting (translation, rotation, scale) decomposition
back to Node.localTransform.
Implementation
void update(double deltaSeconds) {
// Reset the animated pose state.
for (final transforms in _targetTransforms.values) {
transforms.animatedPose = transforms.bindPose.clone();
transforms.rotationBlendWeight = 1;
final bindWeights = transforms.bindMorphWeights;
if (bindWeights != null) {
transforms.animatedMorphWeights!.setAll(0, bindWeights);
}
for (final state in transforms.paths.values) {
state.animated.setAll(0, state.bind);
}
}
// Compute a weight multiplier for normalizing the animation.
double totalWeight = 0.0;
for (final clip in _clips.values) {
totalWeight += clip.weight;
}
double weightMultiplier = totalWeight > 1.0 ? 1.0 / totalWeight : 1.0;
// Seed each node's rotation blend with the weight its clips leave to the
// bind pose, so clips that fully cover a rotation don't blend toward it.
for (final clip in _clips.values) {
final weight = clip.weight * weightMultiplier;
for (final binding in clip._bindings) {
if (binding.channel.bindTarget.property == AnimationProperty.rotation) {
final transforms = _targetTransforms[binding.node];
if (transforms == null) continue;
transforms.rotationBlendWeight =
transforms.rotationBlendWeight! - weight;
}
}
}
for (final transforms in _targetTransforms.values) {
transforms.rotationBlendWeight = max(
0.0,
transforms.rotationBlendWeight!,
);
}
// Update and apply all clips to the animation pose state.
for (final clip in _clips.values) {
clip.advance(deltaSeconds);
clip.applyToBindings(_targetTransforms, weightMultiplier);
}
// Apply the animated pose to the bound joints, keeping the
// decomposition so a later rebind anchors to consistent scale signs.
// Nodes bound only by weights channels keep their manual transform.
for (final entry in _targetTransforms.entries) {
final node = entry.key;
final transforms = entry.value;
if (transforms.drivesTransform) {
node.setLocalTransformTrs(transforms.animatedPose);
}
final animatedWeights = transforms.animatedMorphWeights;
if (animatedWeights != null && node.internalMorphWeights != null) {
node.setMorphWeights(animatedWeights);
}
for (final state in transforms.paths.values) {
state.flush();
}
}
}