IntersectsMesh function not working properly?

Hello everybody,

I have a problem when using the IntersectsMesh function. Here it is :

I want to catch all meshes of the scene which are intersected by my cone and I show the bounding box of all of these and the bounding box of the cone.

Here are two screenshots to show you

Here’s my code, quite simple :

for (let i=0;i<scene.meshes.length;i++){

if (scene.meshes[i].intersectsMesh(cone_light,true) == true){
      scene.meshes[i].showBoundingBox = true
                   
}

}

What I don’t understand :

  • Why my axes arrow are intersected because they are behind the bounding box of the cone ?
  • Why the red mesh is intersected because it is above the bounding box of the cone?

The problem is exactly the same when I use intersectsMesh(cone_light,false) .

Is it an issue or do I make a mistake ?

Thanks for your answers.

Boris

It seems precise=true should do it, as the OBBs don’t intersect…

Are you able to setup a simple repro in the Playground for us to test with?

I really think there is an issue or I don’t understand anything… what is also possible :wink:

The world matrices are not computed yet:

1 Like

Ok, I think I’ve found. I did not “recompute” the WorldMatrix of the meshes before the InterSectsMesh function.

:wink:

Same answer. Ok, you’re right. Wound it not be possible to include the computeWorldMatrix of the two meshes in the intersectsMesh function ?

The world matrix computation is done during the normal processing of the main loop. In the case of the PG, we are not in the loop yet, so the matrices have not been computed yet.

1 Like

Yes, but in my application, it does not work either. I think it is a little bit annoying that a function does work only if you code something elsewhere.

Have you tried to call computeWorldMatrix() in your application? We try to avoid calling computeWorldMatrix when not necessary, as this function is a bit heavy.

Yes, I’ve made another prototype function (see below) and it works now perfectly, that’s why I think it could be probably done in the intersectsMesh function, maybe with a third boolean if you don’t want to use the computeWorldMatrix function every time.

BABYLON.AbstractMesh.prototype.intersectionMesh = function(mesh,accurate = false,submeshes = false){
    this.computeWorldMatrix(true)
    mesh.computeWorldMatrix(true)
    return this.intersectsMesh(mesh,accurate,submeshes)
}