I am searching for a way to import a mesh from a .babylon file that has property materialId set to some material that’s not present in the .babylon file. The reason for doing so is that i want to load the material from somewhere else as soon as i really need it. In the meantime, the mesh should just hold a reference to it.
However, if the importer cannot find the referenced material, the actual material set on the loaded mesh defaults to some fallback, leaving me unable to know what material should be assigned to my mesh later on.
I’d really appreciate some pointers into the right direction here.
Hi,
It might be odd to say but why don’t you set an id to your mesh? Since the material is not there, obviously the materialID will also not export (i guess). You can next look to all meshes with this ID (not unique ID, just mesh.id) and assign the corresponding material, no?
Thanks for your answer, @mawa. What you are suggesting would require some additional mapping, if I understand correctly. What I want to do is to import the mesh along with information about the missing material, such that it can be loaded from somewhere else, later on.
Sorry, @mawa, I do not fully understand what you’re trying to say.
When importing a mesh from a .babylon file, i need to know the materialId of the missing material (i.e. the material that was referenced by the mesh, but wasn’t defined in the .babylon file). Importing these meshes leaves me without clue about what materials they actually need. This information is what i want to add to these meshes at loading time, because i will want to load these materials from somewhere else later on.
I was simply suggesting to assign your meshes an id (in babylon). Instead of materialID, use mesh.id on your meshes. Next (outside bjs) you look for all meshes with id and assign the corresponding material. I don’t see any difference in this except you are setting your id to a mesh that exists (in BJS) as opposed to a materialID for a material that does not exist in BJS.
@carolhmj you are talking about introducing a second import pass that reads the .babylon file as JSON, and produces a map of missing materials and meshes/mesh-ids that want to use those? If so, that would be possible. However, I’d also need to make this work for GLB files later on, so, maybe I could use a temporary custom file loader for that instead.