Merge coplanar faces not working

Hello, I have a closed polysurface like this and I want to merge all coplanar faces. When I use the standard command (merge all coplanar faces), the faces get merged as expected, but when I use ‘MergeCoplanarFaces’ in rhinocommon using c#, it doesn’t work as expected.

Here is some additional info, and the file with the geometry (at the end of the screenshots). Any help is greatly appreciated as I have no idea why this is occuring.

… maybe these arrows are the issue?

Also, these are trimmed surfaces (3), the rest are untrimmed.

solid.3dm (120.3 KB)

Can you share the script you’re trying to run?

The script if longer than this, but I’ll share the most relevant part.

The basic idea of the script is to create a simple wall and floor schema. The idea is to get a simple polysurface that would show the walls of the room with the floor, like this:

I derive this schema from the following geometry - the inner box of the room (shown yellow) and the outer box of the room (shown green)

I further conceptually divide these boxes into ‘lower’ part (where the floor will be) and ‘upper part’ (where walls will be). I basically use plane intersections to get the curves that I’ll use to construct the final schema - in this example the curves are the red bottom one (for the floor) and blue ones (for the walls). Each of the parts will get extruded up a specific height (in this case the floor will get extruded 20 cm, walls 260 cm).

When I get the curves (called BDsAndClusterCuts below), I than extrude the curves to first form the vertical surfaces for both the ‘upper’ and the ‘lower’ part respectively.

var BDsAndClusterCuts = new List<Curve>();
BDsAndClusterCuts.AddRange(BDAcuts); // BDAcuts are cuts with the yellow box
BDsAndClusterCuts.AddRange(clusterCuts); //clusterCuts are cuts with green box

List<Surface> surfaces = new List<Surface>();
Vector3d v = new Vector3d(0, 0, height);

foreach (var crv in BDsAndClusterCuts)
{
   var s = Extrusion.CreateExtrusion(crv, v);
   surfaces.Add(s);
}

foreach (var s in surfaces)
{
   var sToBrep = s.ToBrep();
   breps.Add(sToBrep); // this breps collection collects breps from both lower and upper parts
}

… which ends up looking like this:

I than simply try to do the following : join breps, merge breps, cap planar holes and merge coplanar faces:

 var joinedBreps = Brep.JoinBreps(breps, GlobalSettings.Tolerance);
 var mergedBreps = Brep.MergeBreps(joinedBreps, GlobalSettings.Tolerance);
 var cappedBreps = mergedBreps.CapPlanarHoles(GlobalSettings.Tolerance);
 cappedBreps.MergeCoplanarFaces(GlobalSettings.Tolerance);
 RhinoDoc.ActiveDoc.Objects.Add(cappedBreps);

… and I end up with the brep without the merged coplanar faces.

Hi @Sven_Duplić,

Try splitting kinky faces (BrepFaceList. SplitKinkyFaces) before capping and merging planar faces.

– Dale