Create Instances of Imported Meshes (gilt file)

I’m unable to create Instances of the Meshes that I have imported. The error I was getting was that you can create Instances of only those Meshes which have a geometry. Then I tried using the MergeMeshes method by merging the TransformNodes of different components of the Mesh with an invisible plane. But I couldn’t select the nodes even by using the method getTransformNodeByID. Is there any better way of doing this?

Here's a picture of the mesh in Babylon Scene Inspector

1 Like

I’m having a similar problem. Would definitely appreciate some help.

The question is why do you want to do that? If you want to group meshes and transformNodes, you can simply create a new transformNode and make it the parent of the meshes

You cannot create an instance of something which has no geometry as it makes no sense :slight_smile: Instances are GPU command that replicate geometries: Use Instances - Babylon.js Documentation

What I also recommend is to use mesh.instantiateHierarchy(). It will deal automatically with createInstance / clone problem for you (beware though I just found that I did a typo and this function will REALLY be available with the next nightly)

1 Like

I want to do it because instances use less draw calls. And @Wingnut suggested that use MergeMeshes method to merge it with a (invisible) plane so that it gets a geometry.

I didn’t know about THAT call. Understandable… I guess… no experience with this. I’m still learning this GLB/GLTF import stuff. Sorry if I led you astray, @nikhilkrgautam and Sahilnare.

I tried using Mesh.instantiateHierarychy() but it’s giving the error: Instances should only be created for meshes with geometry. Here’s the code:

Ya got a little spelling issue with ‘instantiateHierarchy’. I’m not sure if that is an issue in your actual project, but I saw it, and thought I should mention it. Ignore me as needed. :slight_smile:

But in the documentation, ‘hierarychy’ is used: Mesh - Babylon.js Documentation

Yeah, its a typo in the docs. Actual method name only has ending ‘y’.

github search

Not sure what DK found, but, we’ll look at it all again tomorrow… after tonight’s nightly build, eh? You might want to find something else to work-on… for 8+ hours. :slight_smile: Hopefully, “nightly builds” happen nightly… like tonight.

Using the correct spelling I’m getting this error: Unable to import meshes from textures/fence/scene.gltf: Error in onSuccess callback: TypeError: fence[0].instantiateHierarchy is not a function. (In ‘fence[0].instantiateHierarchy()’, ‘fence[0].instantiateHierarchy’ is undefined)

Good test.

Did you take that github search link? It shows that instantiateHierarchy() is a method on transformNodes and mesh.

So, that error sort of indicates that fence[0]… is NEITHER of those object types. hmm. I wonder what it is. hmm. You should put a console.log(fence[0]) in place of the instantiateHierarchy call… and drill into the object at console… see if you can tell what type of object it is.

It is Mesh. I tried the MergeMesh method and now I’m getting a new error: Unable to import meshes from textures/fence/scene.gltf: Error in onSuccess callback: Error: Positions are required

Again merging meshes means merging geometries so you need geometries :slight_smile:

So, instantiateHierarchy is a thing that causes NO NEED for MergeMesh… because it creates an instance of all the submesh (the entire model). I think that’s true.

instantiateHierarchy() bypasses the need for mergeMeshes() and createInstance(). It’s a lone ranger. :slight_smile:

At least I think that’s how it works. You need to call it for EACH new multi-mesh instance that needs creating. It never merges the mesh… it doesn’t need-to. interesting. I hope I got it figged. How bout you, nik?

Why are models SO DIFFICULT to make portable/plug’n’play, eh? I hear ya. :slight_smile:

1 Like

But instantiateHierarchy is for TransformNodes and my root is a Mesh. So it doesn’t work and is giving the error: Positions are required.

Nope it is for transformNode and meshes :slight_smile:

Can you help me in this example: https://www.babylonjs-playground.com/#J62R3F#8