Custom method to evaluate active meshes

Hi,
I have a number of character meshes that can dynamically change their clothing, hair or weapons.
To do this I simply load the required mesh and attach it to the character’s skeleton.

As there can be a lot of these added meshes I would like to extend the mechanism that exists within Babylon.js to evaluate the active meshes (frustrum culling) so that if a character is judged to be visible, then all of the character’s hair, clothing and weapons are also judged to be visible.

This way I avoid frustrum checking on many small meshes and I avoid drawing the meshes if the character is not deemed to be visible.

I was thinking of performing this logic for the characters and it’s submeshes within my own custom version of scene.getActiveMeshCandidates, in which I:

  1. Call the original scene.getActiveMeshCandidates to get a list of meshes.
  2. Frustrum check each character mesh
  3. Set any character (along with all of it’s additional meshes) not within the frustrum to be inactive
  4. Set any character (along with all of it’s additional meshes) within the frustrum to be active and alwaysSelectAsActiveMesh=true
  5. Return the array of all meshes for standard evaluation by scene._evaluateActiveMeshes() knowing that the characters and all submeshes are already set to be drawn or ignored.

Before I implement this I wanted to confirm that I wasn’t missing an existing mechanism that would be better than my plan.

Thanks.

It is a good one

Other option would be to register to onBeforeActiveMeshesEvaluationObservable and then flag the meshes you want to have inside the rendering list with mesh.alwaysSelectAsActiveMesh = true and flag the meshes you do not want with mesh.isVisible = false

2 Likes

Thanks for the advice :smiley: I always forget to look for an observable that may be in the right location

1 Like