Instances vs thin instances and scene selection

Hi, I have a question about how to construct a large scene efficiently.

Suppose I have a large scene, using octrees for selection, and my octree has 100 blocks. Then suppose I have a mesh (e.g. grass) that needs to be duplicated 1000 times throughout the scene. I’d like to use instances or thin instances for the duplicated mesh, but I’d also like octree selection to work on them.

If I understand correctly, mesh instances work normally with scene selection but thin instances don’t, so there are two options for how to set up the scene:

  1. Make one copy of the mesh, create 1000 instances of that copy, and assign each instance to an octree block
  2. Make 100 clones of the mesh, assign each clone to an octree block, and then create 1000 thin instances of the clones (so that each thin instance is made from the mesh clone corresponding to its position)

Am I understanding instances/thin instances correctly, and is one of those options dramatically better or worse than the other? Or is there some other third option I’m not seeing?


1 Like

Yes, you are understanding instances and thin instances correctly!

I think for grass or small things like that that are duplicated a lot of times, thin instances is the only way to go because you will have probably tens of thousands (if not more) in your scene. Having so many individual meshes won’t work because they have to be scanned each frame to compute their visibility. In a complex scene, this scanning (in scene._evaluateActiveMeshes) is generally where most of the time is spent. You should trade more work on the GPU side (because some meshes may be sent to the GPU that would have been culled earlier) than on the CPU in that case. But profiling is of course always the best way to know what works for you given your goals / targetted devices.

1 Like


Regarding selection performance, I had thought that if I was using octrees it would override mesh selection, but it seems that octrees only exclude meshes, and all meshes inside a selected octree block then get individually tested.

Is it possible to override this, so that selection testing is only done on octree blocks, and any mesh in a selected block is just selected?

Octrees pre-select a list of mesh candidates, but then all meshes from this list are going through the testing/selection process in _evaluteActiveMeshes.

You can avoid some computations to determine if a mesh in this list is really visible by setting scene.skipFrustumClipping = true or mesh.alwaysSelectAsActiveMesh = true on all meshes. But you can’t avoid _evaluteActiveMeshes to go through the list of mesh candidates because some operations must be performed on each mesh to prepare them for rendering.

1 Like

It looks like mesh.alwaysSelectAsActiveMesh does what I need, thanks!