1 Draw call for each createInstance() of mesh loaded from GLTF

Hi guys,

I would like to ask why I’m having 1 draw call for each instance of my mesh. I should only have 1 draw call right? Anything I am missing out?

PG here:
https://playground.babylonjs.com/#CGDR8X#1

Btw, I tried to use 3D model without animation and the draw calls were still the same.

Does look like animations are the issue

no skeleton, no animation https://playground.babylonjs.com/#CGDR8X#2 draw calls 1
skeleton, no animation https://playground.babylonjs.com/#CGDR8X#3 draw calls 1
skeleton, animation https://playground.babylonjs.com/#CGDR8X#4 multiple draw calls

Hi JohnK,

Tried to use same mesh from gltf without animation:
https://playground.babylonjs.com/#CGDR8X#5

Still 50 draw calls.

I tried to play around with other 3d models that I have (obj, stl files) and I was able to instance their meshes with 1 draw call.

That’s because you are loading the right handed GLTF scene into a left handed Babylon scene, so Babylon has to modify “something somewhere” (I think it’s a -1 somewhere in a matrix) leading to not being able to batch all the draw calls.

Add scene.useRightHandedSystem = true; just after scene creation, and you will see a single draw call.

1 Like

Hi Evgeni_Popov,

It works, thanks! Big help for a newbie to 3D stuff like me.

I did instancing in OpenGL. how the different coordinate system can affect the batching process?
also, I am having the same problem. I wrote half of the game already and if I change the coordinateSystem, it will ruin the whole game. is there a way I can solve this problem without changing the coordinate system?

That’s because the side orientation of the master mesh is different from the side orientation of the children (instances), so Babylon can’t batch all the drawing in a single display.

What you can do is setting the parent of the instances to be the same parent than the master mesh: it is the parent of the master mesh that has a “-1” in the scaling matrix that leads to side orientation inversion. So, setting the same parent for the instances will make the master + instances share the same side orientation and thus a single draw call can be issued:

https://www.babylonjs-playground.com/#YBEKDT#3

When lowerDrawCalls is true, you get 3 draw calls and when it is false you get 9 (the fan is made of 3 meshes).

Thanks for the explanation. :slight_smile:
That makes sense. my instancing is working with the suggested solution but I also wanted to have different renderingGroupID for different instances. I realized I have to change the master mesh renderingGroupId to make it work. That’s not what I m looking for.

VertexBuffer doesn’t have a support for creating renderingGroupId which makes sense. How can I have different renderingGroupId working for different instances? Thank you for the support so far. :slight_smile:

The only solution I can see is splitting your meshes / instances depending on the number of different renderingGroupId you have:

  • have a master mesh with renderingGroupId = 0 and create some instances from it
  • create another master mesh with renderingGroupId = 1 and create some instances from it

So in the end you won’t have a single draw call for all the instances but as many as the different number of renderingGroupId values you have.

The question was stupid itself but you are right.

Rendering order is decided at CPU side and all batches needs to be single draw call. you cannot do much here. But I am employing the same solution you suggested. thanks a lot. B-)