Making instances of an imported mesh

Hello.
I’m trying to create instances of a mesh I imported.
On my local project I’m successfully importing a mesh that was made in blender, but when I try to create instances of it nothing happens.
The mesh is really simple and similar to a block and I’ll need to display hundreds of them at once which is why the instancing is critical for our project.
The objects do get created and I can print them out to the console, but the mesh is not being displayed.

I made a playground where you can see this behavior.
I cannot create instances of the rabbit mesh just like I can’t create instances of my own mesh in my local project.
The tree mesh and simple blocks work just fine on both the playground and my local project.

https://playground.babylonjs.com/#UB332R#2

Are there certain criteria for a mesh to be able to be made an instance of?

Hi Stephan,

You just need to create an instance from the right mesh (which is not always the first in the array). It all depends on the file you are loading:

https://playground.babylonjs.com/#UB332R#3

2 Likes

Removed boxes and scaled rabbit to make instances of imported more obvious.

2 Likes

Hi gang. There’s mesh.instantiateHierarchy() too… https://www.babylonjs-playground.com/#5NIBE1#10

I don’t know much about it, but it sounds like a “tree-walking instantiator”… which somehow sounds important. :slight_smile: It might be used mostly for root-less models… not sure.

2 Likes

If you use loadAssetContainer, you can use the new function that @deltakosh added instantiateModelsToScene to duplicate all of the loaded models. This will duplicate skeletons, animation groups, etc. so that you can animate the duplicates separately.

3 Likes

Thank you @RaananW @JohnK @Wingnut @bghgary all of your posts made me understand what is going on better.

Using the second mesh from the array solved my issue like @RaananW suggested.
I’ll look more into mesh instantiateHierarchy() and the LoadAssetContainer as well :slight_smile:

Seeing how supportive this community and devs are makes me really excited to dive deeper into babylon. Hopefully I’ll also be able to also help someone down the road.

5 Likes