Hiding/showing a mesh with freezeActiveMeshes

Dear community,

We are currently having performance issues and experimenting with “freezeActiveMeshes” as detailed in this page:

It works fine, however, I have issues with quickly showing and hiding a mesh. If I change the visibility via setEnabled or isVisible, it is not updated - I have to unfreeze/freeze active meshes which is too expensive.

I created a PG example:
https://www.babylonjs-playground.com/#BYVXY4

The ground is supposed to be shown/hidden if the sphere is clicked. Is there any option to show/hide a mesh quickly without calling unfreeze/freezeActiveMeshes on the scene?

Kind regards
Zacherl

One solution is to simply move the mesh out of camera view when needing to hide it

2 Likes

Is this the way to go or are there other options? It seems a bit hacky.

In your case you should not freeze the mesh themselves : https://www.babylonjs-playground.com/#BYVXY4#1

Or unfreeze/freeze only the mesh on demand not the full scene: https://www.babylonjs-playground.com/#BYVXY4#2 But as this is internal only the API might change, @Deltakosh I wonder if there should be a kind of lambda based function to apply changes to a frozen list ???

1 Like

@zacherl
Didn’t have time earlier, other options covered by @sebavan are good non-hacky methods :slight_smile:

If mesh._freeze / _unfreeze were to be exposed that would be great.

Just throwing in a sample for completeness.
https://www.babylonjs-playground.com/#BYVXY4#5

1 Like

Thank you for all your feedback!

@sebavan , I tried to use your second solution, but I found a slight problem - if the mesh is disabled at the beginning, it does not work. I modified your PG:

https://www.babylonjs-playground.com/#BYVXY4#6

See line 29/30 for the change. Can I do something to fix it?

Yup this is exactly why those both functions are not publicly exposed as they intent to be as fast as possible in the restricted situation they are meant to be used.

In your case the simplest is enable all your meshes and set mesh.alwaysSelectAsActiveMesh = true; A couple frame after once the scene is fully ready disable/enable what you want with the previous hack.

2 Likes

Thanks a lot for your answers! We decided to move the mesh out of the camera sight for the moment, so we’ll go with the first option.

1 Like