How can I get a texture from a .glb (GLTF) when that texture is not referenced by any mesh or material?

Hello,

Apologies in advance, I know this is a strange request which will probably lead you to think: “Why are you even trying to do this?” but please bear with me :wink:.

I have a .glb file which contains textures that are not used by any mesh or material. IE the JSON portion of the glb has “textures” and “images” which are not referenced by anything else. This has been achieved by using the “Unused Textures & Images” export options in blender. (See https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html#data-material)

I’ve previously loaded this .glb in unity via gLTFast, which permits access to such textures. I then use the textures in conjunction with extra-data/metadata to do some complex behaviour not normally available within the gltf standard.

I’d like to recreate the same behaviour in Babylon.js, but the GLTFFileLoader doesn’t seem to load any textures which are not referenced by a mesh/material.

Does anyone know any way to get these textures or am I going to need to edit the GLTFFileLoader itself to get these?

@bghgary would know for sure if this is possible with the GLTFFileLoader, and if not how hard it would be to make this behavior configurable.

Do you have a sample glb file you can share (e.g. one with unreferenced textures)?

Welcome to babylon.js @Tom !
If you are using Blender the file export process will exclude the unassigned texture. :frowning:

This is not currently possible with the GLTFFileLoader which traverses the scene hierarchy to load only the necessary entities. Someone at some point added an option for materials that allow loading of unused materials. I suppose we can do the same for textures.

Thanks everyone, sorry for the late response. I’ll spare you an example glb file since we have our answer. For now, I’ve just got the artists I’m working with to include every one of our “complex behaviour textures” on scale 0 planes as a workaround. I expect there’s a tiny overhead, but it’ll do the job.

@bghgary adding a “loadAllTextures” option would certainly be useful. It would also generally be more convenient if the babylonjs texture’s get named after their corresponding texture in the gltf file rather than the material slot they occupy, if possible. Where’s the most appropriate place for me to post feature requests like that? The Github Issues?

1 Like

It’s not that straight-forward unfortunately. See here.

Yes, a GitHub issue would be fine. A contribution would be even better. :slight_smile:

2 Likes

Sorry guys I have to remind myself here.

The GLTExporter in Blender removes the unused textures so it’s not the babylon.js GLTLoader which doesn’t load unassigned textures. Even if you fake the user:

1 Like

That’s kind of ‘expected’, isnt’it? Although,…

…I would actually upvote :+1: a tick box to include all (unassigned) textures, as (in my opinion) this can make sense depending on design. It should remain ‘off’ by default.

I would say no. I could have a material with two diffuse textures changed programatically.

The GLTExporter in Blender removes the unused textures so it’s not the babylon.js GLTLoader which doesn’t load unassigned textures. Even if you fake the user:

Apologies but while you would have been right about this a while back, I believe that’s not the case anymore. As I said in my initial post, if you check the “Unused Textures & Images” export options in blender you can force it to include all the textures, even if they’re unused/unassigned.

I can prove this because I can load .glb files (which I’ve exported from blender using these checkboxes) with gLTFast and load/access the unassigned textures from the glb. I can also open the glb in notepad++, extract the human readable bit, and see them referenced in there.

I can make a .glb with some unassigned textures inside it as evidence and upload it if you want, but you could probably make your own alot faster if you want to see for yourself.

What is the version of your Blender?

Can you post a glb please? I’d like to investigate it. Thanks!

Sorry I have two versions installed neither has that check box.

I do see those checkboxes (v 4.1.1), but the resulting glb still has no mention of the unused materials

The resulting glb is below, unused material is named “unused”