Brep.CreateBooleanUnion in C# does a Boolean intersection?

Hi,

I’m trying to give surfaces a thickness and join them together and run into an issue. It seems like after using Brep.CreateBooleanUnion the result is more like what I would expect from Boolean Intersection?

For some reason I cannot recreate it with Python though.

This is what I’m using as input:


221201 Boolean Union.3dm (153.1 KB)

This is what I get after using Brep.CreateBooleanUnion using C#:

This is the code I’ve been using. I’ve been testing with RhinoCode in WIP but it’s actually code I copied and adjusted from a plug-in for Rhino 7 I work on in Visual studio:

using System.Collections.Generic;
using Rhino;
using Rhino.Commands;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
using Rhino.DocObjects;
using System.Linq;

var doc = RhinoDoc.ActiveDoc;

var tolerance = 0.01;

var go = new GetObject();
go.GeometryFilter = ObjectType.Brep;
go.SetCommandPrompt("Select Surfaces to Thicken");

var compInd = new List<ComponentIndex>();

while (true)
{
    GetResult res = go.GetMultiple(1,0);

    if (go.CommandResult() != Result.Success)
        return;

    if (res == GetResult.Option)
        continue;

    //Setup variable from command output
    break;
}

double thickness = 4;
var objrefs = go.Objects();
Brep[] brepsToThicken = objrefs.Select(x=>x.Brep()).ToArray();
var solids = new List<Brep>();
foreach (var brep in brepsToThicken)
{
    var OffsetSolids = Brep.CreateOffsetBrep(brep, thickness, true, true, tolerance, out Brep[] outblends, out Brep[] Outwalls);
    foreach (var s in OffsetSolids)
    {
        solids.Add(s);
        doc.Objects.AddBrep(s);
    }
}

var BUBreps = Brep.CreateBooleanUnion(solids, tolerance);

if (BUBreps.Count() != solids.Count)
{
    foreach (var s in BUBreps)
        doc.Objects.AddBrep(s);
}

What am I doing wrong?

This looks like a bug to me @dale @wim

For some reason the volumes are flipped so Volume are negative.
So you could do that, and it works

if (s.GetVolume()<0)s.Flip();

thicken and union.gh (1.9 KB)

1 Like

If you work with Breps in C# (or Grasshopper) you need to perform BrepFaceList.SplitKinkyFaces() and Brep.Flip(). These actions are automatically done when a Brep is added to Rhino, which makes boolean operations work as intended.

2 Likes

Thanks for your help.
Do you know why it is like that? Doesn’t seem to make sense to me

What i understand is that when you input a surface it uses its normal to extrude. This part is logical. Then surfaces are kept with the same orientation. So combined this give a solid that is not well oriented. Less logical in this case.

I didn’t try with real solid. But if logic is kept a solid offseted must keep the same orientation.

1 Like