Here’s a CompositeMesh
class which is doing something along the lines of the “static batching” of Unity:
https://playground.babylonjs.com/#46PNW4#6
It will create some big vertex buffers for position/normal/uv to hold all the meshes+their thin instances you pass when calling addMesh
. If you update the position/rotation/scaling of the mesh or the matrices of the thin instances (or thinInstanceCount
) you will need to call update()
to refresh the buffers, which can be slow if there are a lot of data to regenerate.
Of course, if you use a lot of meshes and/or thin instances, the vertex buffers can get very big. It’s a trade-off between using more memory/having better perf.
Using this class in your PG:
https://playground.babylonjs.com/#STN960#9
If you want the thin instance picking to work with the composite mesh, you must:
- enable thin instance picking on the meshes that have thin instances
- override the
scene.pointerDownPredicate
property so that it does not check that the mesh is enabled: when using theCompositeMesh
class, the meshes you pass to theaddMesh
method are disabled so that they are not displayed by Babylon
See:
https://playground.babylonjs.com/#STN960#7
Regarding the update()
method being slow, you could improve it by only updating the data that you know have changed.