What I am trying to do is create a PrototypeFactory I can use to produce copies of glTF loaded assets within my scene to create a 3D environment: use assetManager to load once, and reuse the glTF model everywhere. Things such as FloorTiles are in abundance and I’m trying to evaluate what would be the best performance
What are the pros/cons to the following cloning objects/meshes methods? I am trying to figure out the best approach that would cover the needs I have, but I don’t know what I loose/gain with each copy approach.
For the whole GLTF model it is better to speak here about rootMesh.Clone(). But it is possible to use TransformNode as well.
Cloning is the “slowest” method (regarding the performance), but it allows to use different materials and even to change geometry in cloned meshes. Be aware that this method by itself will not clone neither skeleton nor animations (if there are any), you need to worry about it yourself.
Here is a small example with cloning GLB barrel model and changing clone’s geometry - https://playground.babylonjs.com/#4AJ16M#823
This method will create instance of the given mesh, but will not instance its children. In order to do that one needs to use rootMesh.instantiateHierarchy() - Mesh | Babylon.js Documentation
(and again, you may choose between cloning and instancing here with doNotInstantiate parameter).
This will not work, you need to iterate over all child meshes and position your thin instances through matrix operations. Example with 25 thin instances added to the same barrel PG example - https://playground.babylonjs.com/#4AJ16M#822 As one may see, the number of draw calls is the same (10) as here.
Thin instancing is the most performant way to render a huge number of identical meshes.
all thin instances are always all drawn (if the mesh is deemed visible) or none. It’s all or nothing.
adding / removing a thin instance is more costly than with InstancedMesh
Instances are the golden middle. all of the instances to share a material, again to manage draw calls, but remember you have custom buffers to pass information to specific instances. You can use the custom buffers to add variation to your instances as you can see in this Medium article.
Thin instances are the most performant after creation but have some limitations.