createFromMorphTargetSequence static method
Returns an array of new AnimationClips created from the morph target sequences of a geometry, trying to sort morph target names into animation-group-based patterns like "Walk_001, Walk_002, Run_001, Run_002...".
Implementation
/// sequences of a geometry, trying to sort morph target names into
/// animation-group-based patterns like "Walk_001, Walk_002, Run_001, Run_002...".
static AnimationClip createFromMorphTargetSequence(
String name,
List<MorphTarget> morphTargetSequence,
int fps,
bool noLoop
) {
final numMorphTargets = morphTargetSequence.length;
final List<KeyframeTrack> tracks = [];
for (int 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]);
final 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).scale(1.0 / fps));
}
return AnimationClip(name, -1, tracks);
}