Solid Boolean

Hi guys

I have created a solid box in the memory. I want to use this brep to subtract another solid. It doesn’t work. I notice that I have to save this box into the Rhino Doc, then I can use it to do the boolean operation. Why?
Regards
John

Here is the code simplified snippet:

    ...
// after add box into Rhino docs, then use the brep box, it works fine.
    rt = RhinoBooleanDifference(InBreps_main, box_in_doc, tol, &rt_flag, OutBreps, InputIndexForOutput);
	
...
// if not add brep box into docs, it doesn't work.
rt = RhinoBooleanDifference(InBreps_main, box_NOT_in_doc, tol, &rt_flag, OutBreps, InputIndexForOutput);

Hi guys,

A little bit more info. I develop grasshopper component. In c#, I call the c++ functions to do the basic geometric operation. I am not sure whether that is the reason or not.

Regards
John

Please send a complete code example that does not work.

1 Like

Hi Menno Deij,

I have created a simplified project just to repeat this issue. I use vs 2022 and rhino 8. You have to compile the project and save the dll & grasshopper component in a proper directory, don’t use the default one in the solution as I use it for debugging. The part is box.3dm, the grasshopper test file is also attached.
The boolean function is crucial important to us. We hope this issue can be fixed. If you have any questions, please let me know.

Regards
John
TestSrc.zip (99.4 KB)

@smartunfold I have tried to reproduce the problem you reported, but I do not see the problem that the box Brep needs to be added to the Rhino doc, see screenshot below.

So, the first question I have is: which version of Rhino do you use, and do you also see this in Rhino 8 SR8 (which is what I’m using).

Hi Menno Deij,

Thank you very much for your reply. But the result is not right. The green one should be the big box. I have saved the two boxes in the layers InBreps_main and InBreps_box,

(box in InBreps_main) - (box in InBreps_box)

If you see (box in InBreps_box), then it is exactly what you have shown in the image, which is NOT right.

Regards
John

I see, I was expecting an error message but I understand the problem now.

What is happening is that when you create the box brep, it has an “inside out” orientation with face normals pointing inwards. When it is added to the Rhino document, Rhino will see that it is a closed object with an inside-out orientation and fix that for you. So after the object is added to the document, the orientation is correct with normals pointing outwards.

You can do two things: check that you give the 8 corners in the correct way, see the documentation of ON_BrepBox, or you can add the following lines to the code after the box brep is created:

    if (-1 == (*brep_box)->SolidOrientation())
      (*brep_box)->Flip();
1 Like

thank you. It works.