Boolean operation on mesh

Hi, I’m trying to achieve an effect like this, where a cylinder intersects a cube and it substracts its shape.

I tried using this port of CSG.js (GitHub - karl-/pb_CSG: A C# port of CSG.js by Evan W (http://evanw.github.io/csg.js/).) but it only seems to work okay with one intersection, not dragging your mouse, you can see my attempt here:


https://i.gyazo.com/6ad91e32334f25e049cebcd0d50353e5.mp4

It lags a lot and after various attempts the mesh gets destroyed. How would you approach achieving the effect in the beggining?


Yeah, you can already see in that green object how much extra geometry that punching these simple holes is generating. Doing what you suggest with CSG seems like it would end-up being ridiculous. Maybe you should try some shader-based solution instead (like a stencil buffer shader or something).

The shape needs to have collision.

CSG wont be an option if you want to run int. Besides current CSG implementations for unity are not robust enough for multiple operations.
In your case i would probably generate an extruded circle of triangle pairs for each circle segment. To make the collision work you can point the normals inwards so objects wont fall out.
It’s a bit tricky to combine two cicles. Probably the easies way is to go through each circle segment of a new circle and shoot a raycast with the distance of the segments width to test for intersections. You can then determine the intersection point and intersecting triangles (raycastHit.triangleIndex). Using that you can generate the new mesh basically.
Good luck!

Thanks, I found this library that might help me achieve what I want. (http://www.angusj.com/delphi/clipper.php)
I need to figure out how to convert the path that it returns to a mesh, do you have any idea?

I’d try using About ProBuilder | Package Manager UI website

JustAnotherDude, Probuilder uses PB_CSG and as far as its boolean operations go, it would be the same (if not worse) result as OP posted.

Don’t believe me? Create a cube (using Probuilder) then a torus. Now, cut the torus out of one corner of the cube. Probuilder isn’t a bad tool, just a TERRIBLE suggestion for boolean operations.