# Optimising a complex exported model in BJS

**URL:** <https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886>\
**Category:** Questions\
**Created:** [March 30, 2022, 8:27am UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886 "2022-03-30T08:27:15Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![James1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/james1/32/20679_2.png) [@James1](https://forum.babylonjs.com/u/James1)\
**Post date:** [March 30, 2022, 8:27am UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/1 "2022-03-30T08:27:15Z")

</div>

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](https://playground.babylonjs.com/#9Z476P#69)

The main model has 600 buildings by the way 🙂 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.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [March 30, 2022, 12:08pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/2 "2022-03-30T12:08:12Z")

</div>

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)](https://doc.babylonjs.com/toolsAndResources/tools/performanceProfiler). Play with them a bit and see if there is anything that catches your attention there and share with us.

---

<div class="post-metadata">

**Author:** ![James1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/james1/32/20679_2.png) [@James1](https://forum.babylonjs.com/u/James1)\
**Post date:** [March 30, 2022, 12:28pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/3 "2022-03-30T12:28:12Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/c/ace869561a787c9e20a0f5d9dde5ce7be0c4fca8.png)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/7/67707b9a8c44d2e2b1b1258a86d46d9b08685e17.png)

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [March 30, 2022, 2:43pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/4 "2022-03-30T14:43:44Z")

</div>

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()’

---

<div class="post-metadata">

**Author:** ![James1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/james1/32/20679_2.png) [@James1](https://forum.babylonjs.com/u/James1)\
**Post date:** [March 30, 2022, 3:29pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/5 "2022-03-30T15:29:24Z")

</div>

> [@Deltakosh](#):
>
> 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).

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [March 30, 2022, 5:10pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/6 "2022-03-30T17:10:32Z")

</div>

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)](https://doc.babylonjs.com/divingDeeper/scene/optimize_your_scene)

You can merge several meshes with `Mesh.MergeMeshes`

---

<div class="post-metadata">

**Author:** ![James1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/james1/32/20679_2.png) [@James1](https://forum.babylonjs.com/u/James1)\
**Post date:** [March 31, 2022, 7:59am UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/7 "2022-03-31T07:59:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Luyar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/luyar/32/23201_2.png) [@Luyar](https://forum.babylonjs.com/u/Luyar)\
**Post date:** [April 1, 2022, 7:23pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/8 "2022-04-01T19:23:27Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![James1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/james1/32/20679_2.png) [@James1](https://forum.babylonjs.com/u/James1)\
**Post date:** [April 5, 2022, 3:05pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/9 "2022-04-05T15:05:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 5, 2022, 3:37pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/10 "2022-04-05T15:37:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 5, 2022, 3:37pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/11 "2022-04-05T15:37:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![James1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/james1/32/20679_2.png) [@James1](https://forum.babylonjs.com/u/James1)\
**Post date:** [April 5, 2022, 5:11pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/13 "2022-04-05T17:11:23Z")

</div>

Hi,

This is the one from earlier [https://playground.babylonjs.com/#9Z476P#69](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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 5, 2022, 5:22pm UTC](https://forum.babylonjs.com/t/optimising-a-complex-exported-model-in-bjs/28886/14 "2022-04-05T17:22:24Z")

</div>

yes it will help with performance

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