Need help with Brep.CreateBooleanUnion Method

Hello

I’m trying to voxelize an object in Rhino using C#. However, when I create the voxel representation, I want them to be joined into one solid body instead of separate cubes. For this when I try using the Brep.CreateBooleanUnion Method, the returned value is NULL. I did some testing and it seems like this method only returns union if the two objects share a side. In my case the voxels might just be sharing a corner.

I am also not sure why I get a NULL value when I call this method in the actual code. Can anyone please help me understand what a good way to join all the boxes might be?

Thank you

Hi @Ali16 ,
Two breps which are “touching” at their corner point can not be boolean unioned, because they do not overlap. That’s why you get Null.

If you would like to have one or more physically separated voxels joined into a single geometry, you should use Mesh.Append Method. That will create a single mesh from voxels, which are physically, or not - separated.

If you are still looking for breps, then use Brep.MergeBreps.
However, have in mind that such breps are “non-Manifold” and documentation suggests against their use:

Hello @djordje

Thank you for the response. I tried using the Brep.Append method where i iterate over the Brep List and append the Breps. Doing this I got a joined output, however, it seems that whenever I use more than 15 20 voxels in one dimension, the code takes too long to process and often freezes the program. I also used Brep.Compact and Brep.CullUnusedFaces to try and simplify the geometry of the Brep before adding it to the Document. I was not able to entirely understand their usecases and it didnt seem to help in making it more efficient.

Interestingly using 10 or less voxels in one dimension does not cause any issues and gives the same run time as it does without creating a unionized/joined object (11 seconds). But as soon as I enter 20 voxels, it just freezes or takes too long. Perhaps an exponential growth.

Any thoughts on this perhaps? I appreciate the help.

Also, Do you believe working with meshes in this case would be more efficient that Breps? I avoided meshes as I read it can cause abnormal results. I will try the MergeBreps Method and see what happens as well.

New to Rhino. Thank you once again.

Regards

Hi @Ali16 ,
Forget about Compact, CullUnusedFaces … You are trying to create a non-Manifold brep, with methods that probably had in mind Manifold breps.

Brep.MergeBreps will get you what you want - create a single Brep from physically separated breps. But the question is, if it can create problems later. I assume that was the point of the comment, in the last link I posted.

Meshes (and Manifold Breps) work perfectly in Rhino. What do you mean with “abnormal” results?