Attach animation to the glb from another glb file

Hi everyone
is it possible to have a file with the 3D model on the one hand, and a file with only the animations on the other.
I have two glb files, the first one is contains of skeleton and two animations and the second one is contains of the avatar with the same skeleton, i want to know how can i attach the first glb file animation to the second glb file? i mean i want to add the walking animation in the first glb to the second glb. here is my PG: https://www.babylonjs-playground.com/#G187QX#1

To my knowledge, there are atleast two possible ways to do this:

1. animationGroup.clone()-function:

If bone names are identical on both skeletons (else you have to rename), the targetConverter would look similar to this:

(target) => {
     let idx = skeletons1[0].getBoneIndexByName(target.name)
    return skeletons1[0].bones[idx]
}

2. create animationGroup and add animations with targets:

var newAnimationGroup = new BABYLON.AnimationGroup("newGroup");
for (var {target, animation} of importedAnimationGroup.targetedAnimations) {
    newAnimationGroup.addTargetedAnimation(animation, newTarget);
}

Playground of carolhmj:

3 Likes

Great, thank u so much