clipAction method

AnimationAction? clipAction(
  1. dynamic clip, [
  2. dynamic optionalRoot,
  3. dynamic blendMode
])

Implementation

AnimationAction? clipAction(clip, [optionalRoot, blendMode]) {
  var root = optionalRoot ?? this.root;
  var rootUuid = root.uuid;

  AnimationClip? clipObject = clip is String ? AnimationClip.findByName(root, clip) : clip;

  var clipUuid = clipObject != null ? clipObject.uuid : clip;

  var actionsForClip = _actionsByClip[clipUuid];
  dynamic prototypeAction;

  if (blendMode == null) {
    if (clipObject != null) {
      blendMode = clipObject.blendMode;
    } else {
      blendMode = NormalAnimationBlendMode;
    }
  }

  if (actionsForClip != null) {
    var 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
  var 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;
}