ceateClipsFromMorphTargetSequences static method

List<AnimationClip> ceateClipsFromMorphTargetSequences(
  1. dynamic morphTargets,
  2. dynamic fps,
  3. dynamic noLoop
)

Implementation

static List<AnimationClip> ceateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  var animationToMorphTargets = {};

  // tested with https://regex101.com/ on trick sequences
  // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  var pattern = RegExp(r"^([\w-]*?)([\d]+)$");

  // sort morph target names into animation groups based
  // patterns like Walk_001, Walk_002, Run_001, Run_002
  for (var i = 0, il = morphTargets.length; i < il; i++) {
    var morphTarget = morphTargets[i];
    var parts = morphTarget.name.match(pattern);

    if (parts && parts.length > 1) {
      var name = parts[1];

      var animationMorphTargets = animationToMorphTargets[name];

      if (animationMorphTargets == null) {
        animationToMorphTargets[name] = animationMorphTargets = [];
      }

      animationMorphTargets.add(morphTarget);
    }
  }

  var clips = <AnimationClip>[];

  // for ( var name in animationToMorphTargets ) {
  animationToMorphTargets.forEach((name, value) {
    clips.add(AnimationClip.createFromMorphTargetSequence(name, animationToMorphTargets[name], fps, noLoop));
  });

  return clips;
}