Loading a mesh with instances

I’m trying to store and reload meshes with instances - which I can do - but I can’t get the colors restored correctly. Based on an earlier answer to the beginning of this quest, I’m storing the instance colors in a metadata field, but can’t seem to get it to work. Any help is appreciated. My attempt is in the loadMeshFile function in this playground, mesh w/instance playground

To use this, hit the Save Mesh button and save the mesh somewhere, then click the Browse… button and choose the same file to load it back in.

Also, if you look at the console, you see these two lines:
instance Name: tetra, isInstance: YES, # of submeshes: 1, n vertices: 12, parent: NONE has color undefined
instance Name: itetra, isInstance: NO, # of submeshes: 1 has color undefined

However, the isInstance field is inverted, the ‘tetra’ object is a mesh, not an instance, and the ‘itetra’ object is an instance of the tetra mesh. I think this is a bug.

This is a bug indeed but in your code I believe as the color needs to be serialized and parsed. also in the foreach statement you need to access through ndx not through the index https://playground.babylonjs.com/#WTMRVE#6

1 Like

doh: BABYLON.Color4.fromArray…


Here’s a playground with a few more fixes to show it works with more than one instance

1 Like