# Compressing a GLTF textures with KTX2

**URL:** <https://discourse.threejs.org/t/compressing-a-gltf-textures-with-ktx2/40638>\
**Category:** Questions\
**Tags:** gltf\
**Created:** [July 22, 2022, 4:01pm UTC](https://discourse.threejs.org/t/compressing-a-gltf-textures-with-ktx2/40638 "2022-07-22T16:01:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gui](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gui/32/27258_2.png) [@gui](https://discourse.threejs.org/u/gui)\
**Post date:** [July 22, 2022, 4:01pm UTC](https://discourse.threejs.org/t/compressing-a-gltf-textures-with-ktx2/40638/1 "2022-07-22T16:01:33Z")

</div>

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](https://github.com/KhronosGroup/3D-Formats-Guidelines/blob/3b1158aaf1f8fe5cba2c8300f6ce1f034ad7fbf1/KTXArtistGuide.md#inserting-ktx-into-gltf) and [here](https://github.com/KhronosGroup/glTF/blob/1ab49ec412e638f2e5af0289e9fbb60c7271e457/extensions/2.0/Khronos/KHR_texture_basisu/README.md)

where I’d add the following to the json:

```javascript
"extensionsUsed":["KTX_texture_basisu"],
"extensionsRequired":["KTX_texture_basisu"],

```

and setting the textures like this:

```javascript
"textures":[
    {
        "source":0,
        "extensions":{
            "KTX_texture_basisu":{
                "source":0
            }
        }
    }
],
"images":[
    {
        "uri":"metal_grate_rusty_diff_1k.ktx2",
        "mimeType":"image/ktx2"
    }
],

```

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 [https://gltf-viewer.donmccurdy.com/](https://gltf-viewer.donmccurdy.com/)

Here is what the glb should look like:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/2/0/2093ea28776d0e4ca5dba979b1fbc266117a04e0.jpeg)

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](https://discourse.threejs.org/uploads/short-url/tcSjCSHFsDNXAqre268BjMGPVsr.glb) (383.4 KB)  
[gltf\_files\_with\_ktx2\_texture.zip](https://discourse.threejs.org/uploads/short-url/r4zV2tohHVx8O7DYJmTCuPq6Jsg.zip) (158.8 KB)

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [July 22, 2022, 4:56pm UTC](https://discourse.threejs.org/t/compressing-a-gltf-textures-with-ktx2/40638/2 "2022-07-22T16:56:26Z")

</div>

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

```javascript
> 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](https://github.com/KhronosGroup/KTX-Software/releases) is installed. It’s supposed to detect and warn if that’s not installed, but maybe that warning has broken…

 ![Screen Shot 2022-07-22 at 12.57.45 PM](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/c/e/ce73f59d2a44e4cff7a585103fde2b99771672f9.jpeg)

---

<div class="post-metadata">

**Author:** ![gui](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gui/32/27258_2.png) [@gui](https://discourse.threejs.org/u/gui)\
**Post date:** [July 22, 2022, 5:34pm UTC](https://discourse.threejs.org/t/compressing-a-gltf-textures-with-ktx2/40638/3 "2022-07-22T17:34:12Z")

</div>

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!
