I’m fairly new to babylonjs, but think I have a somewhat solid grip on it. I’m loading in a single glb as the only component in my scene. ~30 megs before compression. When I load the glb, I iterate over the meshes and add metadata when applicable to each mesh based on a variety of factors. When the user hovers a mesh, all the meshes with the same metadata need to highlight. To accomplish this, I’m adding a function to scene.onPointerObservable that picks the mesh they’re hovering, then using the metadata attached to it, iterating over and adding all the meshes with similar metadata to a HighlightLayer. Checks are in place to not do this more than needed, so I’m not iterating over all the meshes every time they move the mouse.
This all works great. The issue, is that a new glb I’m working with uses instanced meshes. When I plug this glb into the existing logic, the instances each get different metadata at load, which is desired. However, When adding the meshes to the highlight layer, it seems to be all or nothing between the instances. I’ve done some googling, and it looks like the highlight layer can not highlight specific instances only.
My scene is not so complex as to need the optimization of instancing to be within my performance requirements. However, it might be a pain to ensure all models I use in the future don’t use instancing.
Does anyone know of a better solution than de-instancing these meshes? And if not, is there a better way of de-instancing the meshes than cloning the original ignoring children, copying the instance’s position, rotation and metadata onto the clone then disposing of the instance?