Plane and Ground Mesh Intersection

Hello all,

is there a way to evaluate intersection between plane mesh and ground mesh? It does not work for me. Here my PG, iirc it did in the past, else i must have missed something.

Hmmm I tried checking your PG in 4.2.1 and it didn’t work either, but that makes sense, because intersectsMesh checks the bounding box (either object aligned or axis aligned), and in any of these cases the ground’s BB will be intersecting with the plane’s BB. If the collider wasn’t a plane moveWithCollisions could be an alternative Camera Collisions | Babylon.js Documentation (babylonjs.com), but the plane doesn’t work well with an ellipsoid collision shape…

For this case you’d probably have to check the triangle-plane intersection with all of the groundmap’s triangles, or do some kind of partial occlusion query… @Evgeni_Popov any ideas?

I tried triangle-plane intersection and got closer to the solution. The box & plane works, but not plane & heightmapGround intersection. Maybe I have to additionally consider normal/rotation of triangles?

May be ask @pirateJC The solution could be around using a cube for the heightmap.
Something around his hex video series and the other work he did on procedural terrain with raw textures? And then may be not, but I thought it was worth asking :smile:

I am not sure if this is the right thing, because I would love to be able to compare triangles of mesh-mesh intersection, that could be used for any mesh intersections.

Interesting question here. I’m sure you’ve already seen this, but if you were trying to simply detect when meshes intersect, this document should have everything you need: Mesh Intersections | Babylon.js Documentation

However, if I understand correctly, you’re trying to not only evaluate if a mesh is intersecting another mesh, but what specific triangles in the given meshes are intersecting?

Let’s bring in @Evgeni_Popov here who might be able to help guide us.

1 Like

You got it, I want to know if triangle-triangle intersection happened. Intersection of OBB and AABB won’t be precise enough to determine if the plane and ground with height intersects i.e. if there are hills. As far as I can tell it does always intersect because bounding box of ground uses max height.

I think mesh-mesh intersection on triangle level would be ā€œnice to haveā€ for the whole community, not only in case you want to place a building site.

Edit: Thanks to this PG of @Raggar, I got it:

Adapted PG for Plane-Ground:

1 Like

I can’t take credit for that PG, unfortunately :wink:

Yes. Let me upvote this one :+1:
In fine, your solution works nicely but it’s a lot of lines of code for something that (in my opinion) could be expected as a ā€˜built-in’ feature (as you say ā€œnice to haveā€). In other words, I don’t think it will be the only and last time this problem will occur. Actually, I’m gonna soak this right away :smiley: Although in my use case, I can (I am currently) deal(ing) with the less precise method. Though, it’s good to know that there’s this alternative :relieved:

2 Likes

Yeah, I guess I could optimize it for my use case too i.e. only compare triangles inside 3D plane. But it actually was just because I was curious how to determine intersection on triangle level.
In the current case it allows optimization of bounding boxes. To reduce code I use javascript and remove visibilty features. Maybe someone is able to implement it? Or are you satisfied with a reduced version?

1 Like

I won’t have use of it just now. As I said, I can do with the less precise version. I would have liked an ā€˜in between’ solution making a more precise bounding box from something like faces. I have the feeling that even making check with two simple bounding boxes will be less costly on performance. Currently I’m using this technique precisely for perf gain. I’m clearing ā€˜inner spaces’ (rooms) based on cam intersect. My only problem being that my rooms aren’t just square. But then, I was also thinking about other use cases (and may be future projects of mine) and thought this would indeed be a ā€œnice to haveā€. I guess at this point, if somebody wants to put additional efforts into it, there’s already a base to work from now. Makes it more engaging. We’ll see what eventually might come out of it in the future.
Anyways, thx a lot for sharing :hugs: and have a great day :sunglasses:

1 Like