# GLTFExporter not working with morph targets

**URL:** <https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337>\
**Category:** Bugs\
**Created:** [June 15, 2024, 2:11am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337 "2024-06-15T02:11:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [June 15, 2024, 2:11am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/1 "2024-06-15T02:11:57Z")

</div>

I have a .babylon file that has morph targets which I need as a GLTF. I used the GLTFExporter from the latest CDN version of babylonjs and babylonjs serializer. When I import the GLTF file into Blender 3.3 or Blender 4.0 I get errors like this:

```auto
morph_vs = morph_vs[unique_indices]
IndexError: index 4564 is out of bounds for axis 0 with size 4564

```

I assume its related to the morph targets in my model (which is used for the facial expressions). Does anyone know how to get this working?

You can download the GLTF files and test it out by going to [https://punkoffice.com/vfashion](https://punkoffice.com/vfashion) and clicking on the DOWNLOAD GLTF button

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 17, 2024, 7:59am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/2 "2024-06-17T07:59:29Z")

</div>

cc @Deltakosh

---

<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:** [June 17, 2024, 3:31pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/3 "2024-06-17T15:31:12Z")

</div>

cc @ryantrem to check the exporter (I’m swamped this week)

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [June 18, 2024, 4:20pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/4 "2024-06-18T16:20:22Z")

</div>

I will take a look this week. @ozRocker can you share the .Babylon file as well? I assume the gltf you shared above is the result of the GLTFExporter?

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [June 18, 2024, 4:34pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/5 "2024-06-18T16:34:15Z")

</div>

Thanx mate. The .babylon file can be found here [punkoffice.com/vfashion/assets/morphs.babylon](https://punkoffice.com/vfashion/assets/morphs.babylon)

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [June 20, 2024, 10:45pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/6 "2024-06-20T22:45:47Z")

</div>

Just a quick update, I’m looking into this and it seems like morph targets are not being exported correctly when a mesh has multiple submeshes. I’ll update the thread again when I know more or have a fix.

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [June 24, 2024, 7:36pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/7 "2024-06-24T19:36:38Z")

</div>

This ended up requiring pretty much a rewrite of the morph targets related code in the `glTFExporter`. I have a PR out for this now: [Rewrite morph target gltf export by ryantrem · Pull Request #15229 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/15229)

If you want to test out the result, here is a glb export of your Babylon scene with my changes:  
[morphs.glb.zip](https://forum.babylonjs.com/uploads/short-url/k2qSVWoE1QXcE8Y6tPYaCxxGPLU.zip) (1.3 MB)

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [June 25, 2024, 12:54am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/8 "2024-06-25T00:54:03Z")

</div>

Oh wow you’ve completely fixed it! The morph targets on the head are all there too.

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [July 4, 2024, 10:10am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/9 "2024-07-04T10:10:49Z")

</div>

On closer inspection I just discovered that only the first mesh (body) has retained UV mapping. The remaining 5 objects have lost their UV mapping. Do you know how I can get the UV mapping back?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 4, 2024, 8:27pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/10 "2024-07-04T20:27:57Z")

</div>

Assigned @ryantrem on July 4, 2024, 8:27pm UTC



---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [July 5, 2024, 4:43pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/11 "2024-07-05T16:43:48Z")

</div>

Can you share the textures for your model to help with testing and investigation?

Also, did this UV issue repro before I fixed the morph targets issue, or only after that change?

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [July 6, 2024, 1:51am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/12 "2024-07-06T01:51:53Z")

</div>

The textures can be found here:  
[![](https://punkoffice.com/vfashion/assets/head_atlas.jpg) ](https://punkoffice.com/vfashion/assets/head_atlas.jpg)  
[![](https://punkoffice.com/vfashion/assets/body.jpg) ](https://punkoffice.com/vfashion/assets/body.jpg)  
[![](https://punkoffice.com/vfashion/assets/clothes_atlas.jpg) ](https://punkoffice.com/vfashion/assets/clothes_atlas.jpg)  
[![](https://punkoffice.com/vfashion/assets/body_atlas.png) ](https://punkoffice.com/vfashion/assets/body_atlas.png)

Before the morph target fix I could not even load the GLTF that comes from BabylonJS. I would just get this error

```auto
morph_vs = morph_vs[unique_indices]
IndexError: index 4564 is out of bounds for axis 0 with size 4564

```

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [July 8, 2024, 4:08pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/13 "2024-07-08T16:08:08Z")

</div>

I tried using these with the original .babylon file you attached to this thread but it didn’t look like it was rendering correctly. Can you try re-saving your .babylon file with `BABYLON.Texture.ForceSerializeBuffers = true;`, make sure it renders as you expect in [https://sandbox.babylonjs.com/](https://sandbox.babylonjs.com/), and then attach the new file?

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [July 10, 2024, 9:26am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/14 "2024-07-10T09:26:49Z")

</div>

Oh I just realised that it doesn’t work so easily. These are using texture atlases. Really sorry about wasting your time with those files. I separated the textures from the atlas and altered the .babylon file and tested it so it works without additional code. Here are the new files:

```auto
https://punkoffice.com/vfashion/newassets/avatar.babylon
https://punkoffice.com/vfashion/newassets/body.jpg
https://punkoffice.com/vfashion/newassets/eyelashes.png
https://punkoffice.com/vfashion/newassets/eyes.jpg
https://punkoffice.com/vfashion/newassets/hair.png
https://punkoffice.com/vfashion/newassets/head.jpg
https://punkoffice.com/vfashion/newassets/mouth.jpg
https://punkoffice.com/vfashion/newassets/shorts.jpg
https://punkoffice.com/vfashion/newassets/top.jpg

```

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [July 10, 2024, 4:43pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/15 "2024-07-10T16:43:50Z")

</div>

Thanks, this seems to be rendering as expected. I’ll try to take a closer look at the issue soon and will reply back to this thread.

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [July 10, 2024, 10:38pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/16 "2024-07-10T22:38:41Z")

</div>

> On closer inspection I just discovered that only the first mesh (body) has retained UV mapping. The remaining 5 objects have lost their UV mapping. Do you know how I can get the UV mapping back?

When I export to glb and then load the glb into Sandbox, I see a model that is mostly white (except the shoes). It looks like the shoes are not white because they use vertex color. Everything else is showing up white because the original model is using StandardMaterial with emissive at fully white. When we try to convert this to a PBRMaterial for the glTF, we retain the emissive as full white and the PBR shader ends up rendering all white.

In your original Babylon scene, if I change emissive to black and diffuse to white and re-export to glb, the model then renders approximately correctly and UVs all look fine. I also noticed that the final shader is about 50% bigger, so it seems like all white emissive is resulting in some different shader defines.

I think the problem then is either:

1. The standard shader is wrong
2. We aren’t doing as good a job of converting from standard material to pbr material as we could
3. We are doing the best conversion we can in this scenario and there isn’t a great solution on the Babylon side

I think we need @sebavan’s input on this one.

In the meantime, if you could switch from StandardMaterial to PBRMaterial in your Babylon scene that would avoid the conversion complexity and it’s highly likely everything would work exactly how you want. Alternatively, if you can avoid using emissive in your StandardMaterial I think that would also improve things.

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [July 11, 2024, 1:23am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/17 "2024-07-11T01:23:59Z")

</div>

I can fix up the shaders in Blender. If we can restore the original UV mapping then there’s enough info to re-do the materials as PBR materials.

---

<div class="post-metadata">

**Author:** ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)\
**Post date:** [July 15, 2024, 8:00am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/18 "2024-07-15T08:00:18Z")

</div>

I’ve noticed that the skeleton doesn’t come through. I have a new .babylon file [punkoffice.com/vfashion/newassets/avatar\_animation.babylon](https://punkoffice.com/vfashion/newassets/avatar_animation.babylon) that includes an animation (created via the serializer). The export to GLB works but there’s no skeleton or animation when I open it. Do you know what the problem could be?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 15, 2024, 11:10pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/19 "2024-07-15T23:10:15Z")

</div>

lets add @bghgary here for the gltf export.

---

<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:** [July 15, 2024, 11:52pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-morph-targets/51337/20 "2024-07-15T23:52:36Z")

</div>

Console logs says:

> Exporting a bone without a linked transform node is currently unsupported

We don’t currently support exporting bones that didn’t come from a glTF to begin with. You can try to create linked transform nodes manually, but it is difficult to do.
