Compressing a GLTF textures with KTX2

I’m currently trying to compress textures inside a GLTF with KTX2, but nothing I’ve tried so far worked. Maybe someone more familiar with the process could help me find out what I’m missing. Most likely @donmccurdy?

I’ve tried the following:

- 1/ using gltf-transform:

gltf-transform etc1s start.glb output.glb --verbose gets me the error error: Cannot convert undefined or null to object. I’ve tried with version 2.2.0 as well as 2.2.1-alpha.0 built from the repo.

- 2/ by editing the json file:

Following the instructions here and here

where I’d add the following to the json:


and setting the textures like this:


And while I can create a glb file from this using gltf-pipeline, I get the error THREE.GLTFLoader: Couldn't load texture blob when trying to read it. And reading it also fails on

Here is what the glb should look like:

I’ve attached the glb used as input in 1/ and the files zipped together for 2/.
Thanks a lot in advance if anyone can spot what I miss.

start.glb (383.4 KB) (158.8 KB)

Could you try with v2.2.1? There was a bug in v2.2.0 and the alpha prerelease. For me this works —

> gltf-transform etc1s ~/Desktop/start.glb ~/Desktop/end.glb --verbose
debug: toktx: Found KTX-Software v4.1.0-rc1.
debug: toktx:texture(1/1): Slots → [baseColorTexture]
debug: toktx:texture(1/1): Spawning → toktx --genmipmap --bcmp /var/folders/cg/frb94_8j2kz7lzqs56bpnmnc0000gp/T/tmp-71170-X2SN5n6DTURH-.ktx2 /var/folders/cg/frb94_8j2kz7lzqs56bpnmnc0000gp/T/tmp-71170-nWsKX0Jma02B-.jpg
debug: toktx:texture(1/1): 336.15 KB → 169.17 KB bytes
debug: unpartition: Complete.
info: start.glb (392.58 KB) → end.glb (225.11 KB)

If it’s still failing for you, it may help to know what version of node.js you’re using. Also make sure that KTX-Software is installed. It’s supposed to detect and warn if that’s not installed, but maybe that warning has broken…

1 Like

ah looks like it works! Thanks a lot for your very quick help again @donmccurdy , it’s great.

And just to clarify on the files I sent, my post was confusing: start.glb only contains a .jpg, so the sample command I wrote should have used start2.gltf (contained in the zip) as an input, as this is the one which should be linked to a ktx2 texture.

Nevertheless, I’ve installed ktx-software and used gltf-transform v2.2.1 and that did the trick. It now works perfectly well on start2.gltf

Happy Friday!

1 Like