Why do we need to set mesh.alwaysSelectAsActiveMesh = true for instances?

The playground on the instances docs page https://playground.babylonjs.com/#8L50Q3#203 runs mesh.alwaysSelectAsActiveMesh = true . Setting it to false on the playground causes a weird strobing behavior. However, I’m not seeing such behavior in my scene which uses instances when the value is false.

mesh.alwaysSelectAsActiveMesh = true forces frustrum culling to be off - which causes an increase in draw calls. I’m afraid to set it to false as I feel it may have unintended consequences for some users.

Under what conditions would you recommend running mesh.alwaysSelectAsActiveMesh = true is not required?

Interesting. However, I assume removing this instruction should work (works for me). I must say I actually never used this. I’ve always thought the good practice is to make the original mesh invisible (isVisible = false) and work only from the instances. But then, I could be wrong…

That’s because this PG manages the instance color vertex buffer itself. It creates the buffer once and for all, and does not reorganize the data in the buffer depending on the visible/hidden instances. So, if, for eg, the first instance is not in the camera frustum anymore, it won’t be added to the draw call, meaning it’s now instance #2 which will be drawn with the color #1.

If you use the registerInstancedBuffer method to create an instance buffer, the system will manage the reordering for you:

2 Likes

@mawa i thought the best practice is to do mesh.setEnabled(false) and not isVisible.

1 Like

Yes, you’re right. That’s even better :smiley:

1 Like