glTF-Transform icon indicating copy to clipboard operation
glTF-Transform copied to clipboard

Query which KTX codecs were used?

Open echadwick-artist opened this issue 3 years ago • 2 comments

Is there a way to query which KTX codecs were used to compress various textures in a glTF file? For example, was the baseColor.ktx compressed with ETC1S while the normalTexture.ktx wwas compressed with UASTC?

Thanks Don!

echadwick-artist avatar Feb 08 '22 19:02 echadwick-artist

The information is in the file, but not currently exposed by CLI or other tools. In a script you could extract that data from the KTX2 container like this:

import { NodeIO } from '@gltf-transform/core';
import { KHRONOS_EXTENSIONS } from '@gltf-transform/extensions';
import { read as readKTX } from 'ktx-parse';

const io = new NodeIO().registerExtensions(KHRONOS_EXTENSIONS);

const document = await io.read('path/to/model.glb');

for (const texture of document.getRoot().listTextures()) {
  if (image.getMimeType() === 'image/ktx2') {
    const container = readKTX(texture.getImage());
    const dfd = container.dataFormatDescriptor[0];
    if (dfd.colorModel === KTX2Model.ETC1S) {
      // ...
    } else if (dfd.colorModel === KTX2Model.UASTC) {
      // ...
    }
  }
}

I haven't planned to expose that information through the inspect command, but would probably do so if there were a good way to include it in the MIME type, similar to https://github.com/KhronosGroup/glTF/issues/2064.

donmccurdy avatar Feb 08 '22 20:02 donmccurdy

Thanks!

I found out this is exposed in UX3D's Gestaltor tool. https://gestaltor.io

2022-02-11 13_40_27-Gestaltor 2021 7 1 (Community) - _jcj12671_lod1 glb

echadwick-artist avatar Feb 11 '22 18:02 echadwick-artist

Thanks Don!

echadwick-artist avatar Dec 30 '22 14:12 echadwick-artist