Detecting collisions on meshes that don't fill bounding boxes

Hi All-

I am working on an application that uses custom meshes based on boxes. When they get skewed intersectsMesh is unable to detect intersections. Look at this playground and you can see why.

The bounding boxes on the skewed mesh has vertical and horizontal planes.

I have been doing a workaround using CSG intersections which works ok but is more resource intensive. It uses the private variable ‘polygons’. See playground.

Does anyone know of a better way to do this?

Thanks for any thoughts.


Adding @Cedric

Let me take a look

I checked the code and intersectsMesh only uses bounding volume. For a per triangle check, I only see CSG (like you did). Maybe using a physic engine might help but I don’t think any one available supports trimesh/trimesh collision detection.

Do you know any other way to detect per triangle collision detection ? @RaananW @sebavan

The collision system checks triangle intersection, but against an ellipsoid. So it’s not mesh-to-mesh, but mesh-to-bounding.
Rays also check triangle intersections (intersectsWithRay), so this might be a possible solution as well?
Triangle-to-triangles intersection can be very expensive (depending on the number of triangles).

Thanks for your feedback. What I might try doing is keeping a copy of all the objects that have meshes on the server and doing the collision detection there. I have not tried running babylonjs in node it seems to me that would work.

It’s not a game so the latency is not so much an issue. CPU power is. My laptop is burning up right now.

Hello @flex just checking in if your question was answered :smiley:

Yup! The approach below works reliably for detecting mesh collisions without using bounding boxes:

static intersectsMesh(mesh1: BABYLON.Mesh, mesh2: BABYLON.Mesh): boolean {
    var csg1 = BABYLON.CSG.FromMesh(mesh1);
    var csg2 = BABYLON.CSG.FromMesh(mesh2);
    return (csg1.intersect(csg2) as any).polygons.length > 0;