Freeze Active Meshes and instances

Hello, in my scene I would like to utilize freezing of active meshes as it gives huge performance boost. Usually some “falsely rendered meshes” are cheaper, than analyzing of their activeness each frame.

But I run into big trouble when using instances - in my scene, most of the instances are moving and I am unable to make it work. Each time I create an Instance, it becomes “motionless” as well as the origin mesh that normally moved before.

Please take a look at this playground: https://playground.babylonjs.com/#5APWUZ#1 and just comment this var box = BABYLON.MeshBuilder.CreateBox(“instancedBox”, {size: 0.1}, scene); and uncomment this var box = this.box.createInstance();

My typical approach is in each loop

  1. Unfreeze scene when I need to add some new meshes (or just to actualize active list sometimes)
  2. Do the creation of meshes
  3. Freeze scene at the end of each loop in which it was unfrozen

Do you have some hint whats wrong ? I am sure that I am not the only one facing this problem, but I was unable to find solution anywhere.

Thanx very much in advance !

cc @sebavan

In frozen mode, the list of active meshes is not recomputed and, by default, the world matrices of instances are not recomputed/updated neither.

To fix the problem, you can pass false for the freezeMeshes parameter of the scene.freezeActiveMeshes call. Or you can update the world matrices of the instances manually. See how it’s done in the PG of this post:

3 Likes

Thanx very much, that “false” argument to freezeActiveMeshes resolved this issue :wink:

1 Like