# Scene rendering performance optimization plugin based on instance object

**URL:** <https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083>\
**Category:** Demos and projects\
**Tags:** performance\
**Created:** [March 16, 2023, 7:39am UTC](https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083 "2023-03-16T07:39:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [March 16, 2023, 7:39am UTC](https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083/1 "2023-03-16T07:39:32Z")

</div>

[1 | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#HH8T00#181)  
This is an instance object-based performance optimization plugin that organizes all grids using the same geometry and materials and turns them into instance objects for rendering.  
It has all the disadvantages of the instance object, but you can still manipulate the source grid of the instance object map, and the plug-in will update automatically.  
When using rays to get to the generated instance object, you can get the mapping source grid via getSourceMesh.  
You can also get its instance objects directly using the source grid’s getInstanceInfo.  
In some cases, such as the model in this case, the number of render calls can be drastically reduced to improve rendering performance.  
It should be noted that if there is skeleton skin or animation in the model, it may cause problems. For unnecessary models, it can be excluded by addExcludedMesh.

---

<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 17, 2023, 2:14pm UTC](https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083/2 "2023-03-17T14:14:54Z")

</div>

Very neat, thanks for sharing! 😃

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [March 20, 2023, 2:01am UTC](https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083/3 "2023-03-20T02:01:23Z")

</div>

Fixed instance objects not updating properly when the source grid scale was changed to 0.  
[1 | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#HH8T00#181)

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [March 20, 2023, 5:31am UTC](https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083/4 "2023-03-20T05:31:34Z")

</div>

Note: If the isVisible of the source grid is changed in the animation, there will be a problem. Because the two isVisible are not the same, simple proxy mapping cannot be done, such as highlighting with HighlightLayer if a single grid needs to be selected, because instance object constraints require that the source grid isVisible be set to true in order to render the correct HighlightLayer.

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [March 20, 2023, 7:47am UTC](https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083/5 "2023-03-20T07:47:57Z")

</div>

[1 | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#HH8T00#182)  
This is the proxy scheme using Object.defineProperty, modifying isVisible of the source grid will be proxyed to isVisible of the instance Object, and you need to modify \_isVisible to manipulate the source grid if instance objects exist.

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [August 14, 2023, 4:13am UTC](https://forum.babylonjs.com/t/scene-rendering-performance-optimization-plugin-based-on-instance-object/39083/6 "2023-08-14T04:13:11Z")

</div>

[1 | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#HH8T00#214)  
isEnable fix version
