It is by design for rhe same reson that you can not specify the material of an instanced mesh.
Basically instances render in one call so you can not individually add them in. Cause we would need to separate the calls and lose the instances advantage.
In your Case the easiest is to keep one uninstanced and the rest as instances so you can highlight the none instanced one.
Thanks. But the one that should be highlighted changes with by a user interaction. Like when the user points with the mouse to a mesh. And they are 500 of these meshes on the scene.
From my limited knowledge about instancing I though that it is the geometry that is shared, but the instances could vary in things like position and color. Turns out they can vary in position and not in colors.
Is clone/dispose the only way to have 500-1000 instancedmeshes on the scree and quickly highlight 300 of them, than 2 of them, then 1000, then 732, than 1?
The reason I have not though about it is because the InstancedMesh(es) get created by GLTFLoader and I have no control over which meshes are InstancedMesh and which are not.
Good afternoon. I bring up an old topic so as not to create a new one (I apologize, if necessary, vice versa). I had a similar problem, in my development I plan to use a lot of models, so instances were chosen for optimization, but when I tried to use “HighlightLayer” highlighting, I ran into the same problem.
And I have a question - is there an alternative? Or maybe there is some advice on what to do in my situation. As in the usual strategy, I need to highlight the selected units, enemy and allies. I cannot refuse instances, since several thousand models will kill the system, and I also cannot select a parent, since my bootloader is arranged in this way for all loaded models (universal):
async function _loadAsset(file) {
let a = await BABYLON.SceneLoader.ImportMeshAsync("", “./images/”, file, scene)
a = a.meshes[1]
a.position.y = -2
a.setEnabled(false)
return a
}
@kekeqy feel free to improve it, it is all open source, you can make a PR for it.
@Lazarus_Rainhard the main issue boils down to the underlying tech. there is not much to do here. Maybe you could rely on a custom shader where you would use a custom attribute to enable/disable highlights in the effect layer.
In this case the simplest is to keep one none instanced mesh and when you need a highlight, hide the instance to lit, clone it s position rotation scale into the none instanced one and it would visually looks the same
Hi, I did not understand at all what is required, later I will make a detailed PG what is happening and how, otherwise it’s difficult for me to understand without clarity
https://playground.babylonjs.com/#AHP3J7#6
compiled a PG close to my reality: a universal loader of simple models loads a model, writes the base to the “Models” object and creates instances based on the basics. I could use highlighting for Models.neutralBase or Models.redBase (base), for example “hl.addMesh (Models.neutralBase, BABYLON.Color3.Green ());”, but then all instances of this base will be highlighted, but I need specifically selected.
To understand what exactly is required, you need to comment out lines 197 and 207 (enabling and disabling “hl”)
I apologize, if it is not very clear written, I have to use a translator
Heya, here’s a simple implementation for example.
The source mesh is cloned once to create a highlighted mesh. Then on select this highlighted clone is set enabled and made a child of the selected mesh, which is set invisible. And on deselect, the highlighted clone is set to disabled and the previously selected mesh is made visible again.
I also changed it to only select when the picked mesh is an instance of the source mesh, otherwise deselect is called.