CreateClipsFromMorphTargetSequences static method
dynamic
CreateClipsFromMorphTargetSequences(
- dynamic morphTargets,
- dynamic fps,
- dynamic noLoop
Implementation
static CreateClipsFromMorphTargetSequences(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 = [];
// for ( var name in animationToMorphTargets ) {
animationToMorphTargets.forEach((name, value) {
clips.add(AnimationClip.CreateFromMorphTargetSequence(
name, animationToMorphTargets[name], fps, noLoop));
});
return clips;
}