Incorrect number of triangle points on collision _testTriangle

Hello everyone!

I have a 3D model that gives an error on collision. Here is the PG Link: https://playground.babylonjs.com/#KQT1V0#2

I could debug that in AbstractMesh._collideForSubMesh, one submesh had 5 vertices. Therefore eventually in Collider._testTriangle, one point is missing for a triangle. It is no direct relation but I checked the file in Babylon Sandbox and it’s a valid glTF.

How can I make it work? I appreciate any help.

Thank you!!!

Hello :slight_smile:

5 vertices is fine as long as triangles are defined on them. Doesn’t mean that necessary a triangle is missing… For example :


That said, indeed the issue comes from topology. Your mesh node0 is only edges, no surface :

Avoiding it solves the issue : Playground


But still, I kinda agree it’s a bug. Best would be that it doesn’t trigger an error, but simply go through.

++
Tricotou

2 Likes

I academically agree but practically disagree :slight_smile:
The code for collisions is quite complex and I try to keep it as simple as possible. If we need to test for mesh validity per frame per triangle, the cost will be prohibitive

1 Like

Agreed. I was thinking about a topology check at first enabling of mesh.checkCollisions = true; in order not to trigger an error at collision check :slight_smile:

1 Like

yes but even that could happen on a complex object in the middle of a frame. If i was able to run that off thread, I would sign right now but JS is still living like a caveman with no real thread support :wink:

2 Likes

@Tricotou’s answer works for me. I’m already doing some kind of validation on setting collisions, so I’ll just modify my logic as something like mesh.checkCollisions = flag && !!mesh.getTotalIndices();. I think the slight performance change will be worth the trade-off :slight_smile:

Thanks a lot! Always a pleasure having you guys looking after me :grin:

Hold my beer :beer:


Ahah joking of course :joy: . Makes me think about this awesome prez about JS main event loop. 6 years later, I’m still waiting for a JS version with real multithreading/multiprocessing :grin:

Pleasure ! :slight_smile: