Performance optimization can cause meshes disappear

Hi everybody,

I am working on a project that can have very large mesh counts (at now for about 2500 but expected to have more in the future). Every mesh may have different shapes and dimensions which means that I cannot use instance. So, I decided to use if there are other solutions for me to optimize the scene.

I am now having at max 2500 drawcalls (since I don’t need always show them all) about 10 materials, 1 light and no textures. I am experiencing about only 20 frames per second.

To make the problem feel clear, I would like to do a brief introduction on my project and how I have done till now to try to fix the problem:

  1. It is a simulation project (digital twin) that can connect to real world situations. Because of that, I will have to do a lot of calculation on the position and rotation on the coordinate to make it work in BJS. Currently I found that the TransformNode.lookAt() and TransformNode.rotate() takes a lot of time to compute.


    You can see that it is doing a lot of computeWorldMatrix.

  2. So, I decided to make these functions to be called at a web worker. However, this seems does not to work when I pass anything inside BJS to the webworker(e.g., TransformNode or Vector3). And at here, I notice that the performance issue may not related to the calculation, since it was stuck at the same framerate no matter I do the calculation or not.

  3. Then I went to the documentation of optimizing the scene, (Optimizing Your Scene | Not updating the bounding info). By adding mesh.doNotSyncBoundingInfo = true; My scene looks really weird like this:
    Honeycam 2023-10-25 09-29-15
    What it normally shows is this:
    Honeycam 2023-10-25 09-31-57
    You can see that some of the meshes can be disappeared.

Does anybody have ideas on this?

The doc says “In conjonction with mesh.alwaysSelectAsActiveMesh”, so set mesh.alwaysSelectAsActiveMesh = true and see if it works.

Thanks for the fast reply!

Yes, it seems to be displayed correctly, however, the draw calls stay in 2000, that is what I do not want, since this make the framerate even worser.

Do you have any other ideas on how I can improve the performance?

Join meshes with the same material if they are not required to move (TRS or bone animations)
Thin Instances can also be used if many meshes share the same vertex and material.
EXT_mesh_gpu_instancing can be imported as thin instances.

1 Like

Thanks! I know that people can use instance to reduce draw call, but how can I use instance on my situation? In my knowledge, instance can only be used when you have a lot of similar(identical) objects, the only thing you can adjust on the dimension of the mesh is scale. In my case, I have made all of these meshes “manually”, meaning that I generate them using their vertex coordinates, so it is likely that they are different to each other. Are there still other solutions for this case?

Did you try those ? Optimizing Your Scene | Babylon.js Documentation

Also mergeMeshes in your case might help a lot I guess.

Assuming the meshes in your scene is static, another way is to export your scene to gltf and run things like dedup, flatten, instance, join, and import it back.

1 Like