Copy animationGroup with skeleton

Thanks for the mention Seb,

@Dshah_H in this playground, I retarget by cloning the animation group, then for each targetedAnimation, I set the target to be the driving node in the skeleton that I want the animation track to control. In this example, I search by name, since both the source skeleton and the target skeleton had matching hierarchy. However, you can define your own mapping and use that instead, if the skeletons aren’t identical.

One thing that isn’t taken into account would being able to set some offset in the animations to account for if the skeletons differ in convention (i.e: does each bone point +Y?)

        function retargetAnimationGroup(animationGroup, targetSkeleton)
        {
            //console.log("Retargeting animation group: " + animationGroup.name);
            animationGroup.targetedAnimations.forEach((targetedAnimation) => {
                 const newTargetBone = targetSkeleton.bones.filter((bone)=>{return bone.name === targetedAnimation.target.name})[0];
                //console.log("Retargeting bone: " + target.name + "->" + newTargetBone.name);
                targetedAnimation.target = newTargetBone? newTargetBone.getTransformNode() : null;
            });
        }
3 Likes