createFromMorphTargetSequence static method

AnimationClip createFromMorphTargetSequence(
  1. dynamic name,
  2. dynamic morphTargetSequence,
  3. dynamic fps,
  4. dynamic noLoop,
)

Implementation

static AnimationClip createFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  var numMorphTargets = morphTargetSequence.length;
  var tracks = <KeyframeTrack>[];

  for (var i = 0; i < numMorphTargets; i++) {
    List<num> times = [];
    List<num> values = [];

    times.addAll([(i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets]);

    values.addAll([0, 1, 0]);

    var order = AnimationUtils.getKeyframeOrder(times);
    times = AnimationUtils.sortedArray(times, 1, order);
    values = AnimationUtils.sortedArray(values, 1, order);

    // if there is a key at the first frame, duplicate it as the
    // last frame as well for perfect loop.
    if (!noLoop && times[0] == 0) {
      times.add(numMorphTargets);
      values.add(values[0]);
    }

    tracks.add(NumberKeyframeTrack('.morphTargetInfluences[${morphTargetSequence[i].name}]', times, values, null)
        .scale(1.0 / fps));
  }

  return AnimationClip(name, -1, tracks);
}