How can I determine which mesh is underneath?


In the pic you can see that I have 2 intersecting roof planes. I have figured out how to split them into separate meshes at the intersection but I want to dispose of the 2 little pieces underneath.

I have read about various strategies like ray casting and occlusions but I’m wondering in anyone has ideas for a simpler approach.

Thanks for any thoughts.


It looks like you’re using predefined roof sections, so one approach would be to have an invisible “cutter mesh” that accompanies your roof section, then you can use this mesh volume in a subtractive boolean operation on overlapping roof sections.

Another approach would be to have fully parametric roof sections that are “aware” of adjacent roof sections (i.e. roof sections within a roofing “system”), and build the roof geometry so that you get a perfect join without requiring a CSG boolean operation.

1 Like

What I ended up doing was to scan a matrix of rays from above to see which meshes they intersect. It works well:

const isExposedToSky = function(mesh: BABYLON.Mesh){
var isExposed = false;
for(var x = 0; x < 100; x += .5){
for(var z = 0; z < 100; z += .5){
var origin = new BABYLON.Vector3(x,100,z);
var ray = new BABYLON.Ray(origin,BABYLON.Vector3.Down());
var pickingInfo = scene.pickWithRay(ray);
if(pickingInfo?.pickedMesh === mesh)
isExposed = true
return isExposed;

1 Like