GLTFLoader: Forcing the format of a texture after execution of the texture loader.

Description of the problem

In our project, we have an Uber texture loader that is replacing JPG/PNG textures from a GLTF model by the corresponding compressed texture (DXT, ETC, PVRTC, ASTC) dynamically. It then calls either the KTX Loader for compressed textures or the Texture Loader if no compressed texture was found.

But if the original GLTF file contains a mimeType for the texture, the GLTF loader is replacing our compressed texture format to either RGB or RGBA just after even if the texture returned by the loader is a compressed one and it will result in an invalid texture.

GLTF file contains:

"images" : [
  {
    "mimeType" : "image/jpeg",
    "name" : "test",
    "uri" : "test.jpg"
  }
],

GLTF Loader source: https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/GLTFLoader.js#L2201-L2206

Is this behavior really needed ? because the Texture loader should take care of updating the texture format beforehand.

Texture Loader source:
see: https://github.com/mrdoob/three.js/blob/dev/src/loaders/TextureLoader.js#L36

Our workaround is to save the texture format in the Uber texture loader and re-apply it after execution of the GLTF loader.

We’re still not happy on how we manage the compressed textures for each platform so if you have suggestions I’ll be happy to read them.

Thanks,

Original commit: c8407b4

Three.js version
  • Dev
Browser
  • All of them
OS
  • All of them
Hardware Requirements (graphics card, VR Device, …)

N/A

Author: Fantashit

1 thought on “GLTFLoader: Forcing the format of a texture after execution of the texture loader.

  1. This was fixed a while back, the changes to .format are only applied if the texture is not compressed.

Comments are closed.