How to optimize a scene with 10k mesh instances?

An octree is useful only if your geometry is at least moderately complex and span a large area in your scene. If all / most of your meshes are always visible it is of no use, and the additional time to traverse the tree will actually make your fps worse, as you could see.

You can call mesh.material.freeze() right away, even if the mesh is not loaded yet. The system will really freeze the material only after it has been fully generated (meaning when the underlying effect has been correctly created).

If you freeze the active meshes, call the function by passing it true:

scene.freezeActiveMeshes(true);

That way, computeWorldMatrix won’t be called on any mesh without you having to call mesh.freezeWorldMatrix on all meshes beforehand (also, small performance gain as you will avoid a loop on all meshes inside scene._evaluateActiveMeshes).

By doing so, if you want to update a mesh afterward, just update the position/rotation/scale properties and call mesh.computeWorldMatrix, no need to call unfreezeWorldMatrix / freezeWorldMatrix before/after.

I don’t think so, as it is still a single draw call to the GPU. So it all depends on the GPU, you could double your instances for free if the GPU is fast enough to process the rendering in parallel to the javascript code needed to handle a frame. You will have to perform testing to know for sure, however.

No idea as I don’t know mobile dev. If freezing all meshes + all materials, the javascript code load is reduced to a minimum, so much of the time will be passed on the rendering GPU side.

Note that _evaluateActiveMeshes is called in the course of renderFromCamera, so the timing of both functions are linked.

2 Likes