# GLTF Export Bug: Skinning has errors

**URL:** https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744
**Category:** Bugs
**Created:** [August 28, 2020, 8:30am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744 "2020-08-28T08:30:13Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)
#### Post date: [August 28, 2020, 8:30am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/1 "2020-08-28T08:30:13Z")

</div>

So I exported a GLB via BJS GLB serializer, and re-imported it back in BJS to test it. Turns out the mesh skinning has issues. I could show a video but it says “new users cannot upload attachments”

 ![bjs_fail_skin](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/a1c1f1637ef23f066229603d533ab97dd69c3898.png)

---

<div class="post-metadata">

### Author: ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)
#### Post date: [August 28, 2020, 8:47am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/2 "2020-08-28T08:47:46Z")

</div>

I think a PG will help looking for the problem on our end.

---

<div class="post-metadata">

### Author: ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)
#### Post date: [August 28, 2020, 8:53am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/3 "2020-08-28T08:53:19Z")

</div>

How should I do this then. Show a PG that loads the original mesh, then exports it as a GLB, then re-imports the newly exported GLB?

---

<div class="post-metadata">

### Author: ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)
#### Post date: [August 28, 2020, 8:53am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/4 "2020-08-28T08:53:54Z")

</div>

Probably easier if I just send the mesh itself?

---

<div class="post-metadata">

### Author: ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)
#### Post date: [August 28, 2020, 8:58am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/5 "2020-08-28T08:58:44Z")

</div>

Here’s the link to the “mutant.glb” btw

> **[mutant.glb](https://drive.google.com/file/d/1yqXYDk4mE_doSYV-c6l-PHdcGpm9yqHp/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

### Author: ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)
#### Post date: [August 28, 2020, 9:39am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/6 "2020-08-28T09:39:16Z")

</div>

A nice repro would be to host your file in a server and udpate this PG to point to it:

[https://playground.babylonjs.com/#SYQW69#391](https://playground.babylonjs.com/#SYQW69#391)

This doc can help you regarding hosting the asset:

[https://doc.babylonjs.com/resources/external\_pg\_assets](https://doc.babylonjs.com/resources/external_pg_assets)

---

<div class="post-metadata">

### Author: ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)
#### Post date: [August 28, 2020, 10:54am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/8 "2020-08-28T10:54:20Z")

</div>

There you go [https://playground.babylonjs.com/#SYQW69#397](https://playground.babylonjs.com/#SYQW69#397)

---

<div class="post-metadata">

### Author: ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)
#### Post date: [August 28, 2020, 10:58am UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/9 "2020-08-28T10:58:19Z")

</div>

Thanks.

I think at this point I need to summon @Drigax 🙂

---

<div class="post-metadata">

### Author: ![Drigax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drigax/32/16585_2.png) [@Drigax](https://forum.babylonjs.com/u/Drigax)
#### Post date: [August 28, 2020, 3:55pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/10 "2020-08-28T15:55:26Z")

</div>

Bizarre, the gizmo is broken after reimporting and even throws exceptions if you try to see whats up with the bone node positions…  
[https://playground.babylonjs.com/#SYQW69#399](https://playground.babylonjs.com/#SYQW69#399)

I’ll try to take a look today

---

<div class="post-metadata">

### Author: ![Drigax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drigax/32/16585_2.png) [@Drigax](https://forum.babylonjs.com/u/Drigax)
#### Post date: [August 31, 2020, 10:13pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/12 "2020-08-31T22:13:13Z")

</div>

I think I figured out what’s going on here, currently the vertices appear to be improperly skinned to joints in the skeleton:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/c/c7d9f1f799ab49ec574f5e3747a90b26a391caf3.png)  
[https://playground.babylonjs.com/#SYQW69#405](https://playground.babylonjs.com/#SYQW69#405)

Looking at the working source glb we can see that the joints array is in descending order:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/7/7522b0cea50e1b0b97bc64676855489b66be49b5.png)

Which breaks our output glb, since we didn’t modify the JOINTS\_0 attribute to match the new joints array:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/2/250a82349a375f4029ba26b5456bfea555aebeb8.png)

I’ll look at how we can rewrite this attribute to match the actual scene, this probably should not be preserved from the source mesh data.

---

<div class="post-metadata">

### Author: ![Drigax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drigax/32/16585_2.png) [@Drigax](https://forum.babylonjs.com/u/Drigax)
#### Post date: [September 1, 2020, 5:19pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/13 "2020-09-01T17:19:24Z")

</div>

Problem was definitely with how we were exporting our joint order:

Turns out we shouldn’t assume that order of elements in `Skeleton.bones` is equivalent to the actual Skeleton joint order, which is indicated by the individual joints via `Bone.getIndex()`.

> <https://github.com/BabylonJS/Babylon.js/blob/b3e4378bd4755ec40436901ae2ae84c3893d4968/serializers/src/glTF/2.0/glTFExporter.ts#L1892-L1904>

Changing this logic so that we now properly export bones in increasing index value appears to address the issue properly.

> <https://github.com/BabylonJS/Babylon.js/pull/8847>

---

<div class="post-metadata">

### Author: ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)
#### Post date: [September 1, 2020, 5:45pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-skinning-has-errors/13744/14 "2020-09-01T17:45:51Z")

</div>

YASSS!
