GLTFLoader: option to keep or prefer original texture or image name as name of loaded texture


Name is defined in GLTF spec as Any top-level glTF object MAY have a name string property for this purpose. These property values are not guaranteed to be unique as they are intended to contain values created when the asset was authored.

In some exported GLTF files, name can exist in both textures and images like:

   "textures": [
            "name": "MyTextureName",
            "sampler": 0,
            "source": 0
    "images": [
            "name": "MyImageName",
            "uri": "data:image/png;base64,..."

When using Babylon.js internal GLTFLoader, the name of loaded texture is set like this:

And name of GLTF’s texture or image is lost.

Playground Example

The file is silghtly modified from BoxTextured.gltf from glTF-Sample-Models.


Add an option, statically or instance-bound, to make GLTFLoader prefer to use original texture or image name as name of loaded texture whenever possible, which could has false by default to keep backwards compatibility with existing code.

cc @bghgary

We need to consider that a glTF texture is not a Babylon texture.

Here is how the mapping goes:

  • glTF textureInfo → Babylon.js Texture
  • glTF texture → Babylon.js InternalTexture
  • glTF image → no equivalent

glTF textureInfo is not a top-level glTF object with a name. Multiple glTF textureInfo can point to the same glTF texture. Multiple glTF texture can point to the same glTF image.

Maybe storing a name on the Babylon.js InternalTexture would work?