Copy Animations

Hi,

I was trying to clone the basic animation like walking. Based on the link trying to make the avatar walk.
The approach i tried:

  1. I imported 2 avatars walking avatar and t shape posed avatars
  2. Read the animation group from walking avatar
  3. copy tjhe cloned animations to t-shape avatar(stuck here).

Can somebody share some idea how to clone or copy the animations.

There is an animationGroup.clone()-function:

If targets are bones with identical names on both skeletons (or you have to rename bone or clone skeleton), you can use this:

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

You’ll have to iterate through all the animations contained in the animation group, get the corresponding target on the avatar you want to copy to, and add a new targeted animation with this modified target in a new animation group. Here’s a simple example: AnimationGroup demo | Babylon.js Playground (babylonjs.com)

EDIT: or as Takemura pointed out, the clone funcion is even simpler :rofl:

1 Like

Thanks carol…
am trying by your logic, how do u import complete mesh into variable so that i clone it…
pls correct me if i am doing wrong

If you’re using ImportMesh, then the first argument of the callback function is the mesh. You’re already getting it into your code as “dude”

got it thanks,

i declared global variable and copied the animations to second mesh, still there seems to be some issue.
am i missing anything.

First thing you did wrong is combining both methods. There is no need to use clone and addTargetedAnimation together. You have to stick to one way. Next is that in your first .glb-import, you unneccessarily cloned animationGroup and then you clone again in second .glb-import. Cloning in second would be enough here. Also you created an animationGroup, which is already imported, then you try to addTargetedAnimation to the createdAnimationGroup with importedAnimationGroup as animation and clonedAnimationGroup as target. Then you did this all again for second .glb-file with slight difference, that this time you iterate through targetedAnimations of first createdAnimationGroup with second ClonedAnimationGroup as target. Your parameters of clone-function missing targetConverter.

To make it short:
AnimationGroup != Animation
AnimationGroup != Target (Bone, Mesh)

At last you need to check if names are identical, found atleast one (RootNode !== RootNode1):

2 Likes

Thanks Takemura for the help
its fixed with new approach