Drawcalls not decreasing with instances

Hi BJS Community !
As you can see in the BJS playground below, I instanciated panels, trying to get only 2 drawcalls like in the forest example[BJS documentation]. I have done evething like this. But as you can see in the screenshot, at list 40 drawcalls remains for my instances

my BJS playground

Thank you for your help !

however no problem with thinInstances [1 drawcall]

Actually, there are exactly 1000 draw calls in your PG.
The reason is that instances with a world matrix where determinant is different than root mesh world matrix will be rendered separately (like a regular mesh). This mostly happens when the sign of the scaling vector is different between an instance and the root - as in your case.
To overcome this just set null parent to the mesh - https://playground.babylonjs.com/#4I8BA5#5

4 Likes

And it’s in the docs as well:

https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances#limitations

1 Like

There should not be a warning or info in the console when user tries to use createInstance which will not be work?

Why should the framework waste extra CPU cycles by testing the inputs when it’s clearly documented?

1 Like

As you can see above the clearly documented not useful enough in some cases. Otherwise this topic won’t be exist.

1 Like

Catch 20. Diving into the document and better still, diving into code allows a developer understand the engine in the best way. This is why code commenting is important. It becomes a requirement for quality and complex projects. The more documentation we have, the more an average user reads through so there’s a balance to be made.

2 Likes

I have to disagree with you. … or better said extend your comment, saying

…that’s precisely why we have this forum (and this community packed with very skilled members (not me :grin:) willing to answer for free 24/24 and 7/7). If we would put everything in the doc, would you read it? (I wouldn’t). If the inspector or the scene would check on everything, wouldn’t it just become a mess, you would all disable in the first place? Just asking…

1 Like

Anyway, thank you a lot for your help it works !
hace a nice day

2 Likes

Could you please mark the solution provided by @labris as the accepted solution? Thanks!

1 Like

The problem is that there is only a few who reads the manual.

If everyone would read, this article and gazillions of RTFM memes wouldn’t exist:
RTFM - Wikipedia.

I think RTFB is always the answer.

Blockquote RTFM - Wikipedia.

1 Like

Come to think of it. This is the code in question:

//scene.meshes = [gltfRoot, myActualMesh];
myActualMesh.parent === gltfRoot
gltfRoot.scaling.x === -1
myActualMesh.scaling.equalsAll(1)
//^^^created as is by Babylon
myActualMesh.createInstance("i2"); //<- fails

An imported gltf/glb file always comes with a root node by default. This root node has negative scaling.

Even if you have a perfectly normalized mesh/mesh hierarchy, the gltf node, that Babylon automatically prepends by default, will cause instancing to fail.

Differently and directly put, Babylon screws you over without you doing anything. So maybe add a warning in the loader - if it is the gltf root node that causes the determinant difference?

2 Likes

The problem is the perf here. Any warning needs us to check beforehand and thus perf is impacted.

This case is complex because if you create your instance and give it the same parent then no problem.

Initially I was for not breaking the instances and let them render. Most of the time that would be enough but in some cases the culling would be inverted.

We have no easy fix here besides docs + forum

1 Like

That being said…I may have an idea

Stay tuned ;D

no please don’t! I’m sure this is CLEARLY a misunderstanding.

Your question totally makes sense and I know the documentation is not enough here (Hence why I’m thinking about a new solution).

Do not take answer too directly, it is tough on a forum to communicate feelings but I know everyone here and I can assure you that no one is insulting you (if this is the case please tell me and I will take care of that)

Also remember: we are all from different cultures and the way some people talk could be offensive for others whereas the intention is CLEARLY to only help

1 Like

all right thank you :+1:

2 Likes

ok folks! here is the fix:
Fix issue when creating instances from a gltf object by deltakosh · Pull Request #15724 · BabylonJS/Babylon.js

I flagged it as breaking change because it changes a bit (but I think it is minimal) the behavior and honestly the current behavior is broken

The createInstance will now attach the new instance to the same parent as the source. So no more world determinant difference when using ford :slight_smile:

@franky3D your initial PG will work with no change after that PR will be published:
Fix issue when creating instances from a gltf object by deltakosh · Pull Request #15724 · BabylonJS/Babylon.js

4 Likes

Insults, really? Now where was that? I hope it wasn’t me :sweat_smile: With my bad english, short messages always have a chance to lead to a misunderstanding :face_with_hand_over_mouth:
This is a friendly place to share questions and advice (and sometimes our mood :stuck_out_tongue_winking_eye:) but what it is NOT, is a place to insult people or post inappropriate content of any type :unamused:
If you see some of these (and I’d rather think they’re not many), what you should do is, eventually try to clarify with the poster (could be a misunderstanding) or else FLAG IT as inappropriate. I’m pretty sure the Team would want to be aware of such behavior because I believe this is a NO GO :stop_sign: The last thing you should do is take it for yourself and quit. If one has to quit this forum, it’s certainly not the victim of such misbehavior. My opinion only :innocent:
Well I do hope that despite this experience, you are actually enjoying your time with BJS and I hope to see you soon in this Forum again. Meanwhile, have a great day :sunglasses: