Merge all coplanar faces in a mesh

This topic was brought up multiple times before, but going through all the threads could not solve my misunderstanding.
When I try to use the Rhinocommon MeshAllCoplanarFaces on a mesh the output mesh always has the exact same number of faces, only the mesh edge count seems to be affected.

import Grasshopper as gh
import scriptcontext as sc

if __name__ == "__main__":
    if M:
        if not t:
            t = sc.doc.ModelAbsoluteTolerance
        merged = M.MergeAllCoplanarFaces(t)
            "Input parameter M failed to collect data"
        ) (7.9 KB)

Is the method supposed to work like this and I just need to follow it up with more steps of reconstructing the mesh (adding ngon faces / culling unused vertices)?
Basically I want the script from above to return a mesh cube with just 6 faces.

Well … this Method is not available in R5 SDK (for the type of limited usage that R/GH have in the practice this combo is more than enough).

Anyway … I would suggest to try the analytic way (after doing a FF conn Tree). Use a bool [mesh.Faces.Count] , and call it, say, taken - in order to avoid dating the same girl twice. Notify if you want a C# that does that (but there’s no auto C# to P translation).

BTW: Use MTV connectivity (Vertices on a per Mesh basis) instead of MV (Vertices on a per Face basis). M.Vertices.CombineIdentical is a must as well

Hi @Christoph2,

If you bake the output, you’ll see that co-planar faces are merged.

Mesh.MergeAllCoplanarFaces doesn’t modify the mesh faces. Rather, it just constructs n-gons where possible.

– Dale

1 Like

First of all thank you for your quick reply! Could you elaborate what you mean by FF conn Tree? (Face connectivity tree?). On first sight I was not able to put your approach together with the standard Rhinocommon methods.

Indeed FF is for Face/Face connectivity Tree (R SDK provides all what you need to do that classic Tree - plus all what you need for a full “merge” solution ).

The only puzzle if to find the fastest and most effective FF coplanarity check Method (Face Plane/Plane comparison comes to mind - planes defined by Face center and Face Normal. But of course there’s various other ways to cut the mustard)

Hello Dale,
I tried baking the script’s output mesh, but when I re-reference it into grasshopper again or export it as .obj, it just looks in its structure exactly like the input mesh and I see no point in applying the method.

Does this mean then, that Mesh.MergeAllCoplanarFaces and AddPlanarNgons return the same unmodified mesh? How could I simply filter out every face except the newly constructed n-gons?

Hi @Christoph2,

When exporting to .OBJ, make sure to check the “Preserve NGons” option:

Attached is a modified version of your solution that shows how the mesh structure changes. (7.5 KB)

– Dale


Thank you Dale, the OBJ export option does the trick! I tried to further simplify the mesh by culling redundant vertices with Kangaroo 2 Combine&Clean but it seems to damage something in the mesh. All in all I am not able to put together a sufficient alternative to Moment Of Inspiration’s OBJ export mesher.

Try welding the mesh. (10.2 KB)

If you don’t want to modify your working mesh, then just weld when exporting.

– Dale