# GLB export of an instanced mesh fails

**URL:** <https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331>\
**Category:** Bugs\
**Created:** [March 24, 2023, 6:47pm UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331 "2023-03-24T18:47:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lowclouds](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lowclouds/32/26590_2.png) [@lowclouds](https://forum.babylonjs.com/u/lowclouds)\
**Post date:** [March 24, 2023, 6:47pm UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/1 "2023-03-24T18:47:18Z")

</div>

I’ve tested most of the basic shapes and it looks like anything more complicated than a plain plane or box will fail, so I’ve moved this from Questions to Bugs, although maybe there’s something I’m just missing.

> **[Babylon.js Playground](https://playground.babylonjs.com/#9U9MLX%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<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:** [March 24, 2023, 7:05pm UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/2 "2023-03-24T19:05:25Z")

</div>

I’m not sure because it works here:

> **[Babylon.js Playground](https://playground.babylonjs.com/#85SWEQ%2322)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Hmm it works with Cubes, but not spheres. That is interesting. We would have to go look at the parser and take a look but with the error that is dropping I’m assuming there is a index error on binding the color buffer for larger sets of vertices? Not sure, but kinda thinking thins might actually be a bug.

---

<div class="post-metadata">

**Author:** ![lowclouds](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lowclouds/32/26590_2.png) [@lowclouds](https://forum.babylonjs.com/u/lowclouds)\
**Post date:** [March 24, 2023, 7:27pm UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/3 "2023-03-24T19:27:03Z")

</div>

Thanks. I’ve never tried it with cubes, but it also fails with extruded meshes. This was just the simplest example I found

---

<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:** [March 24, 2023, 8:15pm UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/4 "2023-03-24T20:15:12Z")

</div>

So it for sure sounds like something along the path is not incrementing correctly while constructing the buffers. We would have to look at when the “registerInstancedBuffer” is parsed before being passed the the glb export is truly giving the correct data. If that is, then the next step would be to look at the glb exporter and how it is accessing that data.

But then again I’m not really sure tbh.

---

<div class="post-metadata">

**Author:** ![lowclouds](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lowclouds/32/26590_2.png) [@lowclouds](https://forum.babylonjs.com/u/lowclouds)\
**Post date:** [March 25, 2023, 1:01am UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/5 "2023-03-25T01:01:56Z")

</div>

Well, this pretty much kills a major use for my Lsystem generator, since I need to use instances to get reasonable performance

---

<div class="post-metadata">

**Author:** ![lowclouds](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lowclouds/32/26590_2.png) [@lowclouds](https://forum.babylonjs.com/u/lowclouds)\
**Post date:** [March 26, 2023, 12:44am UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/6 "2023-03-26T00:44:51Z")

</div>

If I don’t create an instancedBuffer for color, then all the examples work.

---

<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:** [March 27, 2023, 9:14am UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/7 "2023-03-27T09:14:36Z")

</div>



---

<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:** [March 27, 2023, 10:35am UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/8 "2023-03-27T10:35:51Z")

</div>

This PR will fix the problem:

> <https://github.com/BabylonJS/Babylon.js/pull/13677>
>
> See https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/6

Note, however, that glTF does not support instanced meshes (the `InstancedMesh` class of Babylon.js), so the instances are exported as regular meshes. Also, it does not support a “color per mesh” property, so the two spheres of the PG are exported with the same material and have the same color (the color from the material, not the color from the instance data).

---

<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:** [March 28, 2023, 9:52am UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/9 "2023-03-28T09:52:46Z")

</div>



---

<div class="post-metadata">

**Author:** ![lowclouds](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lowclouds/32/26590_2.png) [@lowclouds](https://forum.babylonjs.com/u/lowclouds)\
**Post date:** [March 28, 2023, 6:58pm UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/10 "2023-03-28T18:58:49Z")

</div>

Thanks! Are there any exporters that do support instances with colors? .babylon? The docs are a bit sketchy on most of the exporters, and most seem to be addressing importing

---

<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:** [March 28, 2023, 8:26pm UTC](https://forum.babylonjs.com/t/glb-export-of-an-instanced-mesh-fails/39331/11 "2023-03-28T20:26:34Z")

</div>

Yes, exporting to a .babylon file should normally support everything.
