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)
    else:
        ghenv.Component.AddRuntimeMessage(
            gh.Kernel.GH_RuntimeMessageLevel.Warning, 
            "Input parameter M failed to collect data"
        )

merge_coplanar.gh (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.

1 Like

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.

merge_coplanar.gh (7.5 KB)

– Dale

2 Likes

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.

merge_coplanars2.gh (10.2 KB)

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

– Dale

I am trying to get this to work on an Ngon Polyhedron that was created with Rhino, brought into Revit and then send back into Rhino…

baking the mesh and then merging all coplanar faces doesn’t do anything.

Hi @dale I was wondering if you have any insight into this.

Thanks.

Hi @ct.rhino,

Without some geometry, there isn’t anything can help with.

— Dale

mesh-reduce.gh (65.1 KB)
Here is the geometry. I am trying to reduce to 5 and 6-sided ngons.

Thanks.

Dale, this has been resolved. Thank you.

I am trying to use the script on this model but it does not reduce the mesh faces for me.
Actually every triangle contains three coplanar Mesh face.
mesh coplanar.gh (24.0 KB)

The Rhino command does not add any ngons.

I wass gonna ask, where are the ngons?

If you bake this mesh the shading will immediately reveal that the faces are not coplanar.

That said, just by using the face boundaries component on the initial mesh, you get the triangular boundaries of the desired result.

I don’t work with meshes a lot, so the following method is stupid, but it works.

Somebody else please explain how to rebuild a mesh using the output of face boundaries that won’t waste as much processor power in a larger scale scenario.

re_mesh coplanar.gh (45.5 KB)

1 Like

I dont want to add. I want to reduce. Check the screenshot.

Martin Siegrist via McNeel Forum <notifications@mcneel.discoursemail.com> ezt írta (időpont: 2025. ápr. 21., Hét 16:41):

see my script and ask someone to help you make a less brute force version.

(I’d also love an explanation of why face boundaries is ignoring the interior vertex being out of plane with the exterior vertices)