# KTX Textures get lost on GLB Export

**URL:** <https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605>\
**Category:** Questions\
**Created:** [March 21, 2022, 7:28am UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605 "2022-03-21T07:28:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheHOF](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thehof/32/19750_2.png) [@TheHOF](https://forum.babylonjs.com/u/TheHOF)\
**Post date:** [March 21, 2022, 7:28am UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/1 "2022-03-21T07:28:02Z")

</div>

Hi,  
I’m having issues with the GLB Exporter, if KTX2 compressed textures are involved in the model.

Open this [playground example](https://playground.babylonjs.com/#PEFFA8#19) of a model with KTX2 compressed textures only and trigger the GLB export using the built in inspector.  
When opening the exported GLB in the sandbox, you’ll see that the model is black and all textures are empty/transparent.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/3/83ce4f11b6adbc161d0cb2a1d248884c78409830.png)

However if the textures are additionally provided as png in the very same model, the export seems to work fine.  
In this [playground example](https://playground.babylonjs.com/#PEFFA8#8) the model is created with standard (png) textures and KTX2 compressed textures.  
In this case the export works and also the KTX model is shown correctly in the sandbox.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/0/f0df8152a4237fe0cbcad582621af1eede554b34.jpeg)

Is this a bug, or is GLB export with KTX2 textures not supposed to work right now?  
If not, do you have some kind of workaround in mind?

---

<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:** [March 21, 2022, 9:41am UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/2 "2022-03-21T09:41:25Z")

</div>

ping @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:** [March 21, 2022, 10:27pm UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/3 "2022-03-21T22:27:35Z")

</div>

> [@TheHOF](#):
>
> Is this a bug, or is GLB export with KTX2 textures not supposed to work right now?

I haven’t looked at this yet, but we certainly do not support exporting to ktx2 right now. I think I would expect the code to export as png.

---

<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:** [March 21, 2022, 10:27pm UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/4 "2022-03-21T22:27:39Z")

</div>

Assigned @bghgary on March 21, 2022, 10:27pm UTC



---

<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:** [March 22, 2022, 8:57pm UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/5 "2022-03-22T20:57:42Z")

</div>

I can repro. This is very odd. Will investigate.

---

<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:** [March 23, 2022, 9:08pm UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/6 "2022-03-23T21:08:50Z")

</div>

I know why this is now. The exporter doesn’t handle compressed textures at all right now. It happens to work for the second playground example to due an incorrect assumption in the exporter which causes the exporter to dedupe the ktx2 textures as the png textures from the other mesh.

This will likely take some time to fix all the places in the exporter. Can it wait until after the 5.0 release?

---

<div class="post-metadata">

**Author:** ![TheHOF](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thehof/32/19750_2.png) [@TheHOF](https://forum.babylonjs.com/u/TheHOF)\
**Post date:** [March 24, 2022, 5:11am UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/7 "2022-03-24T05:11:23Z")

</div>

@bghgary Thx for the investigation!  
Yes, waiting for 5.0 should be fine.

---

<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:** [March 24, 2022, 5:04pm UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/8 "2022-03-24T17:04:03Z")

</div>

Do you mind filing an issue on GitHub so we can keep track for after 5.0?

---

<div class="post-metadata">

**Author:** ![TheHOF](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thehof/32/19750_2.png) [@TheHOF](https://forum.babylonjs.com/u/TheHOF)\
**Post date:** [March 25, 2022, 5:41am UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/9 "2022-03-25T05:41:31Z")

</div>

Sure I’ll make an entry.

I think I misunderstood that in the first place.  
So it will not be part of 5.0?

---

<div class="post-metadata">

**Author:** ![TheHOF](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thehof/32/19750_2.png) [@TheHOF](https://forum.babylonjs.com/u/TheHOF)\
**Post date:** [March 25, 2022, 5:52am UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/10 "2022-03-25T05:52:11Z")

</div>

Here’s the [GitHub issue](https://github.com/BabylonJS/Babylon.js/issues/12257).

---

<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:** [March 25, 2022, 4:38pm UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/11 "2022-03-25T16:38:45Z")

</div>

Unassigned @bghgary on March 25, 2022, 4:38pm UTC



---

<div class="post-metadata">

**Author:** ![qillerneu](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qillerneu/32/18517_2.png) [@qillerneu](https://forum.babylonjs.com/u/qillerneu)\
**Post date:** [April 23, 2022, 3:49am UTC](https://forum.babylonjs.com/t/ktx-textures-get-lost-on-glb-export/28605/12 "2022-04-23T03:49:49Z")

</div>

I’ve ran into a similar issue, and the problem is that reading compressed textures is not supported in hardware, so there needs to be workaround. I’ve live-patched the Engine.\_readTexturePixelsSync method with something like this [patch-gettexture.js · GitHub](https://gist.github.com/sergeystoma/1b9bf7fce6e58ef8ae0f6a99a1c5a49f) and it seems to work well. Caveat: this version tested on WebGL 2 only.
