How to create mesh instances without a base mesh?

I’m importing a gltf model, and using it as a blueprint for new starships in my game. I don’t need the imported model for anything else, so Ideally I would want to get rid of it.

Using (AssetContainer).meshes[0].instantiateHierarchy() I can make new starships, though I can’t hide or dispose the imported mesh or the instances will have no vertices.

I can’t use (AssetContainer).instantiateModelsToScene() (from this thread) as I need to get the bounding box info (using [mesh].getHierarchyBoundingVectors()) and InstantiatedEntries does not inherit from node and does not have the function.

As I was just going over the docs, I noticed (InstantiatedEntries).rootNodes. Could I use (AssetContainer).instantiateModelsToScene().rootNodes[0] to get the new instance? If so this could save a lot of work, as I will not have any “base” mesh to instantiate from. Thanks!

Hey there! Apologies for not answering earlier :sweat: From what I see, rootMeshes refers to the new root nodes that are added to the scene: InstantiatedEntries | Babylon.js Documentation (babylonjs.com) so they aren’t a reference to the original node.

1 Like

@carolhmj,

Since my original post, I’ve figured out how InstantiatedEntries works though I did not close/mark this thread as solved. Thanks!

1 Like

Nice! How did you end up solving it, if I may ask? :slight_smile:

I originally thought that (AssetContainer).instantiateModelsToScene() directy returned the instantiated mesh. Of course, after reading the docs I realized that I had to use (InstantiatedEntries).rootNodes[n]. Since the rootNodes (transform nodes) have the getHierarchyBoundingVectors method, it works.

2 Likes