A function that returns the paths (complete or incomplete) for a plane intersecting with a mesh

I’d like to get the polygons describing these multiple lakes and then “empty” / “fill” the lakes independently of each other. At the moment they are all represented by one plane of reflective water:

From: https://www.babylonjs-playground.com/#ZH0IX6#24

I think I need a function that intersects a plane with a mesh and returns all the complete and incomplete intersections with that mesh. Perhaps there’s a solution using getClosestFacetAtCoordinates or some linear algebra but this is not a strong point for me. If it could also close the polygons / join together multiple polygons that overlap the “edge” that’d be super helpful as I definitely have no idea how to do that performantly or robustly.

I asked an AI to produce me some code and after many errors it gave up and I’m left with “e is undefined” as an error :slight_smile: https://playground.babylonjs.com/#B7U1UY#1 or https://playground.babylonjs.com/#B7U1UY#3 (uncomment lines 32 to get an error). Any help appreciated.

I think if you use CSG to intersect the terrain mesh with a deep box, such that you are left with the bottom parts of the terrain, it might get you what you need.