Collision problem (bug?) with gltf mesh, without indexes

I seem to have a problem with camera collision detection with a mesh loaded as glb.

A glb/gltf mesh might not have indexes, just vertices. I that case the mesh is rendered like OpenGL draw array call. BabylonJS renders the mesh correctly, and it can also be picked, but collisions don’t seem to work.

I at least tried to track the code and ended in:

Collider.prototype._collide = function (trianglePlaneArray, pts, indices, indexStart, indexEnd, decal, hasMaterial, hostMesh) {

which expects the indices array. I did some quick testing by adding:
if (indices.length == 0){
for (var i = 0; i < pts.length; i += 3) {
var p1 = pts[i];
var p2 = pts[i+1];
var p3 = pts[i+2];
this._testTriangle(i, trianglePlaneArray, p3, p2, p1, hasMaterial, hostMesh);
}
}

which seems to activate collisions, but of course is not really correct,

Eero

pinging @RaananW

Hi @epa, sorry for a later reply!

That’s an interesting use case for collisions :slight_smile: Would you be able to provide me with a model to test on? will be very helpful in finding a solution for this

I tried to make an example case by butchering an existing Babylon playground example.I came up with this:

https://www.babylonjs-playground.com/#SYQW69#505

I used console logging, for checking collisions, as this camera/triangle combo was not clear enough? without it.

In the original form (the true branch at line 6), the triangle is facing the opposite direction,
so you have to rotate the scene in order to see it. The model used in false part, is posing directly when you start, and it is the one with no collisions behavior. If you look at inspector you see that the second model has 0 faces, which seems to be generally the case when gltf without indices is used.

It is possible that my example itself is broken, in that case let me know, and I will do a better one (outside the sandbox, which I don’t really know)

Eero

@RaananW, would be amazing if you can have a look.

Sorry for the late reply.

Yep, our collision system is using the indices to detect collisions. It’s not a bug bug simply a missing feature (such a developer answer! sorry for that :slight_smile: ). I have created a github issue for that - Collision detection doesn't support meshes without index array · Issue #9267 · BabylonJS/Babylon.js · GitHub , not sure if we can pack this into the 4.2 release or if it will have to wait a bit before being implemented

Fixed by: