I’m glad to announce that we finally have an option to load a model and duplicate it as much as you want without reloading it!!!
To do so, you have to load it into an AssetContainer
and then use the new instantiateModelsToScene
function:
BABYLON.SceneLoader.LoadAssetContainer("https://models.babylonjs.com/", "alien.glb", scene, function (container) {
container.instantiateModelsToScene();
}
Demo: Babylon.js Playground
Documentation: Use an AssetContainer - Babylon.js Documentation
17 Likes
Hi @Deltakosh , coming to this a little late but just discovered this method and want to make sure I’m understanding it the right way. Am I right that this is “cloning” the underlying models, and not instancing them? When I saw the word “instantiate” I immediately thought “instances”, but then when I log the models I see the id says “clone of root node”, etc, so I expect based on that and the above that they are “clones”.
The reason I’m really interested in this method is because overall it seems a lot easier than what it have to do to instance a gltf model that contains a few meshes. To do that, it seems like I have to loop through the meshes and instance each one - correct me if I’m wrong. Whereas with this method, I can just pass the container to the method and it just does what it needs to do. But if it is cloning vs. instancing, then it has the drawbacks associated with that tradeoff (I see my draw calls go up significantly with cloning, as expected).
Anyway, let me know what you think about the above! This is an awesome method.
1 Like
Hello, it will clone or instantiate based on what is possible It will always try to instantiate if possible
1 Like
What would determine whether it is cloned or instancing? What are the factors involved in that?
Thanks for your help @Deltakosh !
-Gabe
1 Like
Hmm, am I missing something or does instantiateModelsToScene()
never actually try to instantiate though @Deltakosh: Babylon.js/assetContainer.ts at 6f11ef5fe85ee9ed264d6bc0bd7d4cbc0d2beebb · BabylonJS/Babylon.js · GitHub
These options prevent it from ever using instancing here, right?
Is there a reason for that?
Thanks a lot!
Dennis
Good one! It is clearly a miss! Sorry about that
Will fix in next release
1 Like
Maybe it makes sense to make that options
object available/passable as parameter as well?
Hi here,
some news about instances ? (one year later… ^^)
In my BabylonJs Version (V4) it’s seems to not be ok…
Thanks
1 Like