So I am trying to figure out a way to decrease our large furnished-office-space models, beyond just compression, and the current angle we are looking at is dynamically loading in furniture sets and materials upon in-app selection.
I can load in another glb easily enough, but what I am struggling with is figuring out how to dynamically load a material. Correct me if I’m wrong, but it seems for the most part a material must be associated with a mesh in Blender. Because of this, we have created a lot of duplicate meshes just to carry variant materials based on design selections.
So, in Blender, when exporting a glb/gltf, we are looking at creating an extension that decouples the duplicate meshes that carry material variants for the same type of object (ie a chair) from the scene, and instead, create a reference JSON that links a URL of a texture, its associated property data, UVMap, and shader data, etc. to the mesh. Then, when in Babylon, when that material is selected, I want to create a new PBRMaterial on the fly by loading in the texture and setting all the associated property values. My issue, however, is that when grabbing data from the .gltf, the UVMap and atlassing data needed to create the material is obviously missing (in the .bin I presume).
Does anyone know where I can find how Babylon reads in all the data necessary to identify and create a Material from the gltf/glb binary?
I’ve been looking through the github here: Babylon.js/babylon.glTFFileLoader.js at 6eddbac20810c74a2a6e08ba632f50842ae83f07 · BabylonJS/Babylon.js · GitHub
but there’s so much going on that I could use a bit of direction.
Also, during my research into this process, I discovered the Khronos extension for material variants, which is cool and probably useful:
However, I am wondering if, given the size of our office building models with furniture, it would still make sense to decouple the variant materials from the geometry and load them in as needed based on what the user selects. In which case, even if I use the Khronos extension, I need to figure out how to load in a material (shader, texture, properties, UVMaps for atlassing, etc.) dynamically (possibly from a JSON file that was created via our export extension in Blender) and create it during runtime.
Finding out what to extract from the .gltf and especially .bin when exporting from Blender, based on how the exported material data may be read/dynamically created on the Babylon side, is the hard part, and any guidance would be very helpful!