Hey!
My project is a 3d editor there is some functionality to export gltf file, but i’ve noticed that CompressedTextures are not showing well in gltf. Wanna try decompression before creating glft.
I used KTX2Loader to compress textures.
Are there any ways to decompress CompressedTexture?
The screenshot clarified things. The three.js editor does not supported compressed textures since this type of textures does not support serialization/deserialization yet, see:
There is no tool in the repository that can decompress a KTX2 texture into raw RGBA textures. At least KTX2Loader will always produce some sort of compressed texture.
@donmccurdy What do you recommend for such a use case.
If @Dmitry-Romanchuk-Unilimes is building a 3D editor, the best thing would be to keep the original uncompressed textures around somewhere. KTX2 compression is lossy, so going from PNG → KTX2 → PNG is not ideal.
If you do need to decompress a KTX2 texture though, libktx.js can do it (I haven’t used this before), or you can always create a WebGLRenderer with the same dimensions as the texture, draw the texture to a plane with MeshBasicMaterial, and save the result. I’ve done that to render small preview tiles for KTX2 images in the past.
Hey @donmccurdy
Thx for ideas, will try something tomorrow.
Also i’ve found this thread, looks like somebody tried to add decompression to three.js texture utils.
Yes, I think the code you see in that PR under examples/jsm/utils/TextureUtils.js is a good way to decompress textures from KTX2 to traditional image formats using THREE.WebGLRenderer.
@Mugen87 The problem is we have glb files on a bucket and they are already compressed themselves with Meshopt and have compressed textures with KTX2, so to load them i use this stuff:
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath(
//url
);
const ktx2Loader = new KTX2Loader();
ktx2Loader.setTranscoderPath(
//url
);
const __GLTFLoader = new GLTFLoader()
.setCrossOrigin('anonymous')
.setDRACOLoader( dracoLoader )
.setKTX2Loader( ktx2Loader.detectSupport( new THREE.WebGLRenderer() ) )
.setMeshoptDecoder( MeshoptDecoder );
Not sure I have access to original image in this case (will be very happy if i’m wrong).
I’ve used decompression functionality like it’s on my previous post, but it didn’t work as expected for me (also will be very happy if it’s my mistake).
Are there any other ideas? Thx!
As the PR you linked to is still open and under review, I can’t offer you a working solution. That PR is the most complete code I have seen for the purpose.
We could also provide a way to configure KTX2Loader so that it always transcodes to RGBA8, instead of using a GPU compression format, perhaps. Then GLTFExporter should be able to handle the rest, with some minor changes?