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 .
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?
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?
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:
…I would actually upvote 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.
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.
A blend file (zipped) which if opened in blender 4.1.1 and exported as a glb with the saved export settings will result in a .glb with “textures” and “images” (as in the gltf standard’s understanding of those words) which are not referenced by any “material” (again that’s a gltf standard material, not a blender material.) ToyCarWithUnreferencedTextures_blend.zip (6.6 MB)
A glb file (zipped) which was exported from said blend file and contains said unreferenced textures and images. ToyCarWithUnreferencedTextures_glb.zip (4.1 MB)
A screenshot of said glb file open in notepad++ with the unreferenced images highlighted. (Car_Base and Fabric_Base, originally the albedo/diffuse textures for the model, are not being used by the model or its gltf material, yet they are included in the file.)
A screenshot of how materials need to be set up in Blender to get the unreferenced images to be included. (The checkboxes in riven04’s first screenshot still need to be checked.) If you delete all references to the texture from any blender material then immediately export blender will, funnily enough, still pack the texture in the glb. However the next time you close/open the .blend file it’ll clear its orphan data and delete that texture, after which it will nolonger be included in glb exports.
@riven04 sorry I can’t tell you how to do unreferenced materials as I haven’t been trying to do so. I’ve only been doing unreferenced textures/images, which you can reference the resources attached to achieve. If somebody added an option for loading them as per bghgary’s post there must be a way. Perhaps you have to manually edit them into the file without blender? I’m guessing all the material’s data is serialized and in the JSON not the binary which would make such achievable, though messy…