Optimising a complex exported model in BJS

Hi all,

I have a very complex model I have coded for everything I need, camera’s, fog, buttons for the camera’s, highlight layers, pop-up text. Everything I need now to move forward to launch bar the performance.

This model is a very reduced playground of the full city and I’m still struggling to get past the 10fps. I have even put in some code to optimize it but I have very little understanding of this.

My main model uses incremental.babylon to help with the loading but because of the size of the full city (100mb) it’s not a great user experience. I’ve optimized the model to the max in blender without destroying the shape of the buildings.

This is the reduced city scape with just a few models in. If someone could help me with understanding how I could optimize this that would be a great help. I’ve tried looking through the forum but most models aren’t exported.

https://playground.babylonjs.com/#9Z476P#69

The main model has 600 buildings by the way :slight_smile: I can share any screenshots needed from the main playground but I didn’t want to share that to the world. I was hoping to optimize on this easier playground first.

Hmmm I think the first step on optimization will be understanding what is taking the most time with your model. Is it the geometry, the materials, culling, etc? For this, you’ll want to check the performance tab of your browser, and The Performance Profiler | Babylon.js Documentation (babylonjs.com). Play with them a bit and see if there is anything that catches your attention there and share with us.

Hi, this is the performance indicators. I couldn’t manage to run the realtime one for my complex model as no data was feeding through.


Apart from it being quite a complex model, there nothing really stands out to me as I’m still new to coding and babylonjs.

You may try to group meshes with similar materials to reduce the draw calls
8 millions vertices is a lot:)

You can also try to call ‘scene.freezeActiveMeshes()’

Is there a way to freeze specific meshes once they have loaded? I’ll need everything else for highlighting and selecting as that function won’t work.

Re grouping meshes, is that something you can do in babylon for an exported model? There are quite a few grouped meshes (identical buildings / meshes) already but I also need to be able to select meshes for highlighting buildings (individual ones rather than the group).

you can “freeze()” individual materials or flag some meshes as always active to skip the selection phase

You can find a lot of other ideas here: Optimizing Your Scene | Babylon.js Documentation (babylonjs.com)

You can merge several meshes with Mesh.MergeMeshes

2 Likes

Thank you. I’ll give that a try. I was also thinking maybe to keep static camera’s in for my incremental file so that it reduces the initial load. I may struggle to get the above coded correctly but I’ll give it a go.

Thank you!

Hi, is there any chance you could show me how to freeze only certain meshes please? I can freeze them all but then I can’t highlight them after that. Also the merge meshes is very complicated. I looked at the code in the documents and I can’t get my head around it. I don’t know whether it’s because my objects have a cube.001 etc. rather than a clean name (no dots). But it’s probably my attempt at coding.

If there’s any chance you can show an updated view on my playground that would be of great help.

You have several option to freeze a mesh:

  • mesh.alwaysSelectAsActiveMesh = true will skip the frustum phase
  • mesh.freezeWorldMatrix() will freeze the world matrix
  • mesh.material.freeze() will freeze the material data
1 Like

For your issue with MergeMeshes, if you can repro in a simple PG maybe we can guide you

Hi,

This is the one from earlier https://playground.babylonjs.com/#9Z476P#69 3

I can freeze world matrix in blender. Is that a good option then? I have done that for a few items already.

yes it will help with performance

The best for you is to try and see what works for you

1 Like