Moving around a hole in a mesh in real-time

Hello,

Apologies if this question is a duplicate; I’ve looked at existing similar questions, but they seemed to address different problems. Also, I’m new to Babylon, especially on the graphics end of it, so please be patient with me if able.

What I’m trying to do is make a “cutout” of a mesh that can be moved around in real time- not making a new subtracted mesh. Think cutting a hole in a table, and then being able to drag that hole around to different places on the table’s surface.

Here’s the playground link: https://playground.babylonjs.com/#XTO3Z8#1

The idea is that the blue square would be empty space so that you’d be able to see the lower red table (or whatever else) underneath.

If this has already been answered, then if someone could at least point me in the right direction, that would be great.

Thank you!

Hello,

You could achieve this using CSG2 like so: https://playground.babylonjs.com/#XTO3Z8#2 For simple meshes like this it is a fine solution.

For more complex meshes you might want to csg subtract only once, select those vertices of the hole and just update their positions in a drag observable (however this will fail if you move the hole at the edges of the table). Another option is using a shader to create a hole, however that won’t show the vertical faces of the hole.

Thank you for the quick reply! That certainly could work, but I might look into the shader option too; I’m using pretty simple and thin meshes.

Keeping an original (non-hole) mesh as CSG2, then the hole-maker mesh create and convert to CSG2 can be very quick.