# GLTF mesh with skeleton, clone problem

**URL:** <https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293>\
**Category:** Bugs\
**Created:** [May 17, 2019, 8:28am UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293 "2019-05-17T08:28:00Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Estraven](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/estraven/32/2380_2.png) [@Estraven](https://forum.babylonjs.com/u/Estraven)\
**Post date:** [May 17, 2019, 8:28am UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/1 "2019-05-17T08:28:00Z")

</div>

Hello fellow babylonians 🙂

I’ve run into a weird behavior : I import a skinned GLTF mesh into a scene, using babylon 4.0.3,

`BABYLON.SceneLoader.ImportMeshAsync("", "FOLDER_PATH", "robot.gltf", scene)`

Then I modify the bones rotations to a random quaternion.  
Note : the robot is made of several mesh, all sharing the same skeleton. So i only change the first mesh skeleton.

```
mesh.skeleton.bones.forEach((b) => {
       b.setRotationQuaternion(BABYLON.Quaternion.FromEulerAngles(0.2, 0.5, 0.3));
});

```

The mesh is properly following the bones structure (See image on the left)

Now : I need to clone this mesh to have several of these in the scene

```
let clonedRobot = new BABYLON.AbstractMesh(id, scene);
let clonedSkeleton: BABYLON.Skeleton;
let clonedParts: BABYLON.AbstractMesh[] = []; // used to clone proper hierarchy
meshes.forEach(originalPart => {

	let clonedPart = originalPart.clone(id + "." + originalPart.name, clonedRobot );
	clonedParts[originalPart.name] = clonedPart;
	if (!originalPart.parent) {
		clonedPart.parent = clonedRobot ;
	} else {
		clonedPart.parent = clonedParts[originalPart.parent.name];
	}
	if (originalPart.skeleton) {
		if (!clonedSkeleton) { // use only one skeleton per clone, shared by all meshes
			clonedSkeleton = originalPart.skeleton.clone(id + "." + originalPart.skeleton.name, id + "." + originalPart.skeleton.id);
		}
		clonedPart.skeleton = clonedSkeleton;
	}
});

```

Now, using the same bone rotation as before, the result is weird. The bones are in the same location, but the skinning seems to fail.

See image on the right

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/e/ea50a9b2a6288a289ffb69cf5c349ac977693f0f.jpeg)

I could really use some help. I can’t share the model, I could maybe try to use a similar one to replicate in the playground if needed.

I’m guessing i’m doing something wrong while cloning, OR maybe there is a bug in the clone process of babylonJS.

M.

---

<div class="post-metadata">

**Author:** ![Estraven](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/estraven/32/2380_2.png) [@Estraven](https://forum.babylonjs.com/u/Estraven)\
**Post date:** [May 17, 2019, 9:49am UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/2 "2019-05-17T09:49:31Z")

</div>

Here is a Playground example  
[https://www.babylonjs-playground.com/indexStable.html#7LJ10I#2](https://www.babylonjs-playground.com/indexStable.html#7LJ10I#2)

There is many thinngs don’t understand.

- Why is the “original robot” not moving with it’s skeleton ?
- Why the cloned robot has every meshes twice, one moving, not the other ?
- Whe the cloned robot mesh that is moving skinning is broken ?

---

<div class="post-metadata">

**Author:** ![Estraven](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/estraven/32/2380_2.png) [@Estraven](https://forum.babylonjs.com/u/Estraven)\
**Post date:** [May 17, 2019, 1:57pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/3 "2019-05-17T13:57:00Z")

</div>

Fixed original mesh not moving (another problem, another ticket)

[https://www.babylonjs-playground.com/indexStable.html#7LJ10I#3](https://www.babylonjs-playground.com/indexStable.html#7LJ10I#3)

---

<div class="post-metadata">

**Author:** ![Estraven](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/estraven/32/2380_2.png) [@Estraven](https://forum.babylonjs.com/u/Estraven)\
**Post date:** [May 17, 2019, 2:38pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/4 "2019-05-17T14:38:48Z")

</div>

Ok, it seems it’s a GLTF importer problem

I fixed everything, it works properly on a .babylon file.

[https://www.babylonjs-playground.com/indexStable.html#7LJ10I#7](https://www.babylonjs-playground.com/indexStable.html#7LJ10I#7)

but the very same code bug on .gltf file

[https://www.babylonjs-playground.com/indexStable.html#7LJ10I#6](https://www.babylonjs-playground.com/indexStable.html#7LJ10I#6)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 17, 2019, 5:17pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/5 "2019-05-17T17:17:51Z")

</div>

pinging @bghgary

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [May 17, 2019, 6:48pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/6 "2019-05-17T18:48:45Z")

</div>

Cloning a glTF asset with skinning is not easy right now. There are a bunch of features we added to support glTF like skeleton.overrideMesh and bone.linkTransformNode() which are not cloned and can’t really be cloned easily.

We’re currently thinking about adding a clone method to an AssetContainer: [Make sure we can clone an asset container · Issue #6358 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/issues/6358)

For now, the best option is to load the glTF multiple times.

---

<div class="post-metadata">

**Author:** ![Estraven](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/estraven/32/2380_2.png) [@Estraven](https://forum.babylonjs.com/u/Estraven)\
**Post date:** [May 20, 2019, 7:16am UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/7 "2019-05-20T07:16:07Z")

</div>

Ok, good to know.  
Thanks for the reply.

M.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 6, 2020, 7:30pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/8 "2020-04-06T19:30:31Z")

</div>

Yo @bghgary …  
Please let me know what you come up with here as well 🙂

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 6, 2020, 7:32pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/9 "2020-04-06T19:32:23Z")

</div>

The support for this was added by @Deltakosh. See [Use an AssetContainer - Babylon.js Documentation](https://doc.babylonjs.com/how_to/how_to_use_assetcontainer#duplicating-the-models)

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 7, 2020, 6:21pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/10 "2020-04-07T18:21:15Z")

</div>

So are you saying to manually create asset container… add GLTF Mesh with skeleton to asset container and then call asset instantiate to scene ?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 7, 2020, 7:36pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/11 "2020-04-07T19:36:05Z")

</div>

No, use loadAssetContainer 🙂

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 7, 2020, 7:59pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/12 "2020-04-07T19:59:41Z")

</div>

I’m sorry, I don’t get it… use loadAssetContainer to load the whole GLTF scene ???

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 7, 2020, 10:27pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/13 "2020-04-07T22:27:33Z")

</div>

Use [LoadAssetContainer](https://doc.babylonjs.com/api/classes/babylon.sceneloader#loadassetcontainer) to load from a glTF into an asset container. Then you can call [instantiateModelsToScene](https://doc.babylonjs.com/api/classes/babylon.assetcontainer#instantiatemodelstoscene) on the asset container multiple times to get duplicates.

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 7, 2020, 10:29pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/14 "2020-04-07T22:29:59Z")

</div>

Here is the PG referenced from the docs: [Babylon.js Playground](https://www.babylonjs-playground.com/#S7E00P)

@Deltakosh This scene seems to be broken though? It works in 4.1 but not the latest preview.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/a15c132626c6ffcff7cb307865fea4c41dc013f4.jpeg)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 8, 2020, 2:55pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/15 "2020-04-08T14:55:05Z")

</div>

On it!

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 8, 2020, 3:54pm UTC](https://forum.babylonjs.com/t/gltf-mesh-with-skeleton-clone-problem/3293/16 "2020-04-08T15:54:24Z")

</div>

Will be in next nightly!
