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