SerializeMesh to .babylon, ImportMesh, and materials disconnect; how to reconnect?

I’m using the .babylon format to serialize mesh[es] because it supports instances - and indeed, I can save and re-import a mesh with its instances. But, the saved mesh file does not include materials, and ImportMesh prints a console warning that it can’t assign a material to the loaded mesh. The imported mesh includes materialUniqueId and materialId that look like this:
“materialId”:“default material”,
Note that it does not include materialName, which would be nice.
My app uses a table of materials that are relatively consistent, but I’m unclear if I can set materialId or materialUniqueId on a material without screwing up some internal references. In other words can I do something like this when creating materials:
let m = new BABYLON.StandardMaterial(mname,scene);
m.Id = mname;
m.uniqueId = myId;

then I can manually associate existing materials with loaded meshes

Hi. You can write and use additional metadata on your meshes and materials and identify your mesh or material by any meta field


Cool demo, thanks! I had overlooked that property. I’m still working through some issues with saving and loading materials, but this help. I also realized that the id property gets set to the value of the name parameter in material creation

1 Like