Mesh boolean subtraction operation with SceneKit/RealityKit

I ma trying to figure out if there is a Boolean subtraction functionality native in SceneKit or RealityKit. Simple operation like cutting a hole in a box from a sphere.

If not, are there any libraries (free) that I can look into?

Answered by arthurfromberlin in 676672022

I think Model I/O offers this for Voxels: https://developer.apple.com/documentation/modelio/mdlvoxelarray

But you could take a look at this library to generate models which could be used in SceneKit via SCNGeometry(which in turn could be exported to USDZ and then used with RealityKit): https://github.com/nicklockwood/Euclid

Accepted Answer

I think Model I/O offers this for Voxels: https://developer.apple.com/documentation/modelio/mdlvoxelarray

But you could take a look at this library to generate models which could be used in SceneKit via SCNGeometry(which in turn could be exported to USDZ and then used with RealityKit): https://github.com/nicklockwood/Euclid

Model I/O can do it with voxels as mentioned. Using Voxels and BSP trees don't normally produce very clean results. Unfortunately there isn't a good library to use out-of-the-box. Here is a good article/algorithm for producing cleaner meshes: http://sandervanrossen.blogspot.com/2009/12/realtime-csg-part-1.html

I had same needs. I ended up porting MCUT to swift. you can take a look at my repo https://github.com/dariu5h/mcut-swift.git it's a swift package. Import it and go wild.

I will change it more in future but it works fine now. ask your ai of choise about it, it can make a fast sample code for you. I added some helpers for RealityKit MeshResource and MDLMesh from ModelIO

The original C++ library is https://cutdigital.github.io/mcut.site/

The most powefull library I worked with in 3D mesh opration was CGAL but you can not port it to iOS. But MCUT is only Boolean ops and In my package you can use it on iOS/macOS. I tried to surface must of the important operations and options.

Mesh boolean subtraction operation with SceneKit/RealityKit
 
 
Q