Dynamic CSG2 cutting and creation of sub meshes

I need to be able to load an stl dynamically, which could be any shape or size, and apply a “cookie cutter” mesh to the loaded stl source, slicing it into 8 smaller meshes that can each be individually rotated and manipulated. Before the slicing occurs, the user can drag the cookie cutter around to find the best location on their loaded file to slice at. I have a few questions:

  1. In this first playground link below, click the “Apply CSG cut” button to break the object into smaller pieces. How do get 8 sub meshes from a cut like this that I can individually rotate and assign positions to?

    https://playground.babylonjs.com/#RDBTFN#2

  2. I’m using masks and shaders to try and reduce how much of the cutter is actually shown, and allowing a user to move the cutter object by clicking shift while dragging. As you can see by comparing the previous link to this next one, the shaders and masks have resulted in a near skin tight red representation for the location of the cutter on the surface. Perfect. But, once you rotate the object around, you’ll see that the hidden geometries of the cutter are still obscuring loaded mesh when rotating around. How can I get that surface level detail showing exactly where the CSG cutting will occur without having it hiding the rest of that object? ( remember that this will change based on the geometries of the loaded stl file ) I don’t mind going in a totally different direction here if masking and shaders are not the way to go. As long as the user can drag that red representation of the cutter around live ( hit shift key and drag ) I don’t care how this is resolved. Any thoughts?

    THANK YOU IN ADVANCE FOR ANY HELP YOU CAN GIVE HERE!

    https://playground.babylonjs.com/#RDBTFN#3

1 Like
  1. csg will only create one final mesh so I would advise to do 8 times the same kind of operations to get each part separately.
  2. I am not sure to understand the question, can you share screenshots of the issue ?

Maybe one way to do this is:

  • take the main mesh, grow by small amount
  • subtract main mesh, retain “surface” csg2
  • intersect all slicer meshes with surface
  • this hopefully highlights slicer entry points into main mesh

It will take some effort to make this fast enough for UI, but CSG2 is fast enough to enable it if you save the correct intermediate CSG2 objects.

See my CSG2 sphere posts that show how quick CSG2 can be.

Edit: here

And here