clipAction method
Returns an AnimationAction for the passed clip, optionally using a root object different from the mixer's default root. The first parameter can be either an AnimationClip object or the name of an AnimationClip.
If an action fitting the clip and root parameters doesn't yet exist, it will be created by this method. Calling this method several times with the same clip and root parameters always returns the same clip instance.
Implementation
AnimationAction? clipAction(AnimationClip? clip, [Object3D? optionalRoot, int? blendMode]) {
final root = optionalRoot ?? this.root;
final rootUuid = root.uuid;
AnimationClip? clipObject = clip;
final clipUuid = clip?.uuid ?? root.uuid;
final actionsForClip = actionsByClip[clipUuid];
AnimationAction? prototypeAction;
if (blendMode == null) {
if (clipObject != null) {
blendMode = clipObject.blendMode;
}
else {
blendMode = NormalAnimationBlendMode;
}
}
if (actionsForClip != null) {
final existingAction = actionsForClip?['actionByRoot'][rootUuid];
if (existingAction != null && existingAction['blendMode'] == blendMode) {
return existingAction;
}
// we know the clip, so we don't have to parse all
// the bindings again but can just copy
prototypeAction = actionsForClip['knownActions'][0];
// also, take the clip from the prototype action
clipObject ??= prototypeAction?.clip;
}
// clip must be known when specified via string
if (clipObject == null) return null;
// allocate all resources required to run it
final newAction = AnimationAction(
this,
clipObject,
localRoot: optionalRoot,
blendMode: blendMode
);
_bindAction(newAction, prototypeAction);
// and make the action known to the memory manager
_addInactiveAction(newAction, clipUuid, rootUuid);
return newAction;
}