MergeAllFaces bug

There are issues with MergeAllFaces that causes bad objects, this is an example.

Extracting the coplanar surfaces in “pairs” and using Cap gives a good result, so I see no real reason for MergeAll to fail.

Thanks for taking a look.

mergeall bug.3dm (248.1 KB)

Looks like the polysurface has two caps. When I explode, remove one cap, then join, the polysurface MergeAllFaces just fine.

Hi rajaa… that is peculiar, because if I open that file, and explode and seldup there are no duplicates, and if I count the surfaces there are no double caps… are you sure you found two?

You are right. It was a close surface, but not duplicate. It is a bug. I’v added it to the heap:

When I extract the outer surfaces in the above image from the polysurface, then MergeAllFaces the remaining part, it merges fine. I was able then to rejoin the extracted surface. MergeAllFaces had trouble rejoining that outer face correctly after merging the rest of the piece.

Thanks Rajaa!

Hi Rajaa,
I have had an idea on how to improve MergeAll, so I just spent some hours coding a solution.
First I found that it generated the same error, but not a bad object, so I replaced rs.DuplicateEdgeCurves() with rs.DuplicateSurfaceBorder() and then it works fine.

The tool I made is fast and accurate now. It handles surfaces that are coplanar but not joinable and gives a better result on multi coplanar surfaces.

Rhinos tool tool over 3 minutes on a polysurface that my script used 6 seconds to complete, with better result:

Rhino’s tool is faster at finding if there are no coplanar surfaces, but my solution is faster at solving the result.

Did another test:

Rhino’s result is the middle object and it took 8,5 seconds to calculate. The script took 0.69 seconds.

How fast will it do the attached…? MergeAllFaces takes… takes… well, I’m still waiting…


OK, finally it finished - I don’t know how long it took, but about 15 minutes I guess - however there are holes everywhere… Not a really fair test though, there are non-manifold edges everywhere… I’m just being nasty. (896.3 KB)

This is probably a fairer test - 144 overlapping boxes, no non-manifold edges to confuse things.

Your script finished in a little over 6 seconds here, but didn’t get most of the upper/lower “merge-able” surfaces. MergeAllFaces took around 5 minutes, but did get them all…

–Mitch (1.2 MB)

I allready sent you the script in a PM :wink:

Got it…

Answer: 49 seconds.

I’ll add a % counter to the script so one isn’t left in the dark

As you know, a general solution that carters for most cases can be much slower than one that solves a subset of cases, but it sure is important to find ways to improve the speed of the command. Here are a couple example cases that would be interesting to see if your script merges. (22.5 KB)

Yes, except it didn’t merge any of the top faces…


It does, it checks for any coplanar surfaces, so it should be robust.

And I found the bug @Helvetosaur (and @John_Brock ), the command “rs.JoinSurfaces()” returns only one surface, even if the result is multiple surfaces…

Can you share the script?

In order for rs.JoinSurfaces to work, they have to be in “joinable” order (which is unlikely in your case). Otherwise, you’re better off scripting rs.Command("_Join") - or perhaps RhinoCommon Rhino.Geometry.Brep.JoinBreps() method, which I think can deal with stuff that’s out of order.


1 Like

I am working on it, to fix some other bugs, but did a stupid thing and pasted it onto an empty script, and then I terminated Rhino and lost it all… pft… have to re do it, I had solved the multiple coplanar surfaces that didn’t join.

I just ended up rewriting the tool, so it handled some other situations better.
But I ran into a problem with planar surf, it doesn’t handle self intersecting curves like it should.
I’ll post that as a new topic.


would be a great new feature, if such a command could merge also cylinder faces. Still better it would be if even divide 3d curved G2 surfaces within a PolySrf could be merged in a smart manner.

Thanks a lot!