Creating instance of a mesh from exported blender scene and optimization

Second post on here so far, again I am new so bear with me… lol

So I have a basic model that I created in blender, joined the objects together then exported the model as a GLTF. This model I am planning on creating multiple duplicates with it being the exact same. No differences just different locations. So I am not sure if clone is better for me in this scenario because I am not really changing anything with the duplicate.

I went through and created my full on project locally and then looked at the scene debug layer and noticed I had 175 draw calls and im only rendering 11 objects on the scene, so I started down the route of instancing or cloning.

I then went to import the mesh and followed the createInstance tutorial on the babylon js guides.

Through research I tried following the route of the IsVisible solution and the .SetEnabled path also.

I cannot get them to duplicate, is it because the meshes that are imported has more than one? If so, does the blender “join” functionality not work as expected? lol

Cloning will work but I just want to see why the instance isnt? Reading through the guides and docs, instances seem to be what I need, just trying to make it as performant as possible.


this is because you are not cloning the right object :slight_smile:
This is how your scene looks like:

The mesh you want to clone is Cube and not root (meshes[0])

But no worries, we’ve got you covered with instantiateHierarchy():

1 Like

Man, I love this community :slight_smile: hahah thank you so much

1 Like

Couple of questions for you, is there any reason why it would be working in the playground but not in my local project?

Copied and pasted the code from here and I am getting “root.instantiateHierarchy is not a function”. Importing the same exact mesh and doing the same exact code. Am I out of date or using the wront import library or something?

And would this instantiateHiearchy be a performant way of making duplicates? Would it be better to merge all the meshes from the import method then create an instance?

What version of BJS are you using?

I have ^4.0.3 in my package.json

Anyone have an idea what could be going wrong?

Yep this is a new feature of 4.1. You should use this version on npm:

Thank you for the help this far!

I got everything upgrade to the latest, just now running into this:

BJS - [16:55:33]: Unable to import meshes from …/assets/gltf/gateway.gltf: importMesh of unknown

This line of code hasnt changed from the previous version of BJS to the new version.


This means that you have an exception inside the callback of the importMesh function

Set chrome to stop on all exceptions to see it

So wrapped this in a try/catch and its not hitting the catch and its not even getting to the first line within the callback. Any ideas? Like I said, this was only after the update.

I deleted my node_modules and did a clean install and it works now (facepalm) lol. Thanks for all the help guys!

1 Like