KTX Textures get lost on GLB Export

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

Open this playground example 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.

However if the textures are additionally provided as png in the very same model, the export seems to work fine.
In this playground example 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.

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?

ping @bghgary

1 Like

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.

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

2 Likes

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?

2 Likes

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

1 Like

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

Sure I’ll make an entry.

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

Here’s the GitHub issue.

3 Likes

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 and it seems to work well. Caveat: this version tested on WebGL 2 only.