How to clone a .glb model and play seperate animation on each clone?

I’m importing the .glb file to babylonjs. Then I clone. The cloning is successful. Animation can be managed in the mesh I imported, but there is no animation in the meshes I cloned. What could be the reason? Can you help me?

The cloned mesh requires the skeleton and the animation groups added to it, otherwise you won’t be able to animate it.

Can I recommend using the Asset Container to load the model? This way you can duplicate the model as many times as you wish (of course - with performance in mind):

If you require further help, a playground will be awesome.

1 Like

Babylon.js Playground (babylonjs.com)

Thanks for your answer. Unfortunately, I want to do this with clone instead of instance. As you can see in the example, I cannot change the material of the mesh when I import it as an instance.

I am implementing the skeleton and animation grub for the clone. I can clone all your requirements. I am preparing a playground for you.

You don’t have to create an instance, you can clone. it is configurable in the options:

1 Like

I try now, thank you.

Here is the example - https://playground.babylonjs.com/#AJA5J6#139

1 Like

animating-clones-from-glb | Babylon.js Playground (babylonjs.com)

Thanks for your answer. However, I wanted to use the clone() function because I could not meet some requirements with this method. As in the example, the material does not change with this method.

Here is the example with changed material - https://playground.babylonjs.com/#AJA5J6#146
This line is defines whether it will be clone or instance:

let entries = container.instantiateModelsToScene(undefined, false, { doNotInstantiate: true });

For cloning use

{ doNotInstantiate: true }

For instancing use

{ doNotInstantiate: false}
1 Like

You are very good. I will see if I can integrate this method without clone at the first opportunity. Thanks.

Without cloning (with instancing) you will not be able to use neither different materials nor animations.

1 Like

animating-clones-from-glb | Babylon.js Playground (babylonjs.com) use material but not clone.

The line 11 at your example https://playground.babylonjs.com/#AJA5J6#146

        let entries = container.instantiateModelsToScene(undefined, false, { doNotInstantiate: true });

has the option

{ doNotInstantiate: true }

When it is true it makes a clone of the GLB model and you can change material, animations etc.
When it is false it makes an instance of the GLB model.

Hello guys,

unfortunately a have a problem with cloning the animation groups. I can’t reproduce the problem in pg, even though I use exactly the same code locally: Babylon.js Playground

Meshes and skeletons get cloned correctly but the animation group seems to ne the same one. The name of the cloned animation group equals the original one (but it should be “Clone of …”). And I can’t play the animation of the cloned mesh.

Any idea what the problem could be?

EDIT:

It is working on beta-11. I was on beta-7 before.

1 Like