createClipsFromMorphTargetSequences static method
Returns a new AnimationClip from the passed morph targets array of a geometry, taking a name and the number of frames per second.
/ Note: The fps parameter is required, but the animation speed can be
overridden in an AnimationAction
via animationAction.setDuration
.
Implementation
//// Note: The fps parameter is required, but the animation speed can be
/// overridden in an `AnimationAction` via [animationAction.setDuration].
static List<AnimationClip> createClipsFromMorphTargetSequences(List<MorphTarget> morphTargets, int fps, [bool noLoop = false]) {
final Map<String,List<MorphTarget>> animationToMorphTargets = {};
//TODO
// tested with https://regex101.com/ on trick sequences
// such flamingo_flyA_003, flamingo_run1_003, crdeath0059
RegExp pattern = RegExp(r"^([\w-]*?)([\d]+)$");
// sort morph target names into animation groups based
// patterns like Walk_001, Walk_002, Run_001, Run_002
for (final morphTarget in morphTargets) {
final parts = pattern.allMatches(morphTarget.name);
if(parts.isNotEmpty){
final name = parts.first.group(1)!;
List<MorphTarget>? animationMorphTargets = animationToMorphTargets[name];
if (animationMorphTargets == null) {
animationToMorphTargets[name] = animationMorphTargets = [];
}
animationMorphTargets.add(morphTarget);
}
}
List<AnimationClip> clips = [];
// for ( String name in animationToMorphTargets ) {
animationToMorphTargets.forEach((name, value) {
clips.add(AnimationClip.createFromMorphTargetSequence(name, value, fps, noLoop));
});
return clips;
}