GH: Script or Component for Isotropic remeshing

OK, so I need to do some remeshing, preferably isotropic (or, as close to isotropic as possible), but I try to avoid using third party tools, and especially not external tools. So therefore I wonder if there’s any component that can produce something similar to the remeshed items below (perhaps some algorithm with tweaked settings?) or, if anyone has a script that does the trick.

I would like to stay within a tolerances of say 0.05 and 0.1 mm to the original mesh, which is often a low quality mess (mot mesh). Something like this, from messy left to more isotropic right:

// Rolf

MeshMachine (part of Kangaroo1) does triangular remeshing. I believe @DanielPiker also made some scripting examples available for how to approach this. These do not explicitly depend on the Kangaroo libraries as I recall. They do use Plankton though.

Thanks Anders.
Also - I posted here a rhino command line plugin version of the same thing that might be suitable here. The grasshopper version has a lot more options, but for something like this where what you want is an even isotropic mesh the rhp is probably easier since the only input is a mesh and a target edge length:

1 Like

I will try that.

I would have tried already but I got stuck on hye command Rhino.Geometry.Mesh.ExtractNonManifoldEdges(…) command (doesn’t exist, although the RhinoCommon documentation says that it exists).

Thanks, I’ll try that one as well. Too bad if the command doesn’t take tolerance parameters as well. But I can use the GH version if need be.

// Rolf

I tried the Rhino command MMTriangles. Nothing happens (I set edge length > 0.5 but no go).

I also tried the Gh version but I can’t get any meaningful output from the MeshMachine. The output is of type “Plankton.PlanktonMesh”. Where can I find such a component? I would need a Mesh or GH_Mesh type.

I tried after install to search for “Plankton” etc but no such component names show up. The std preview in GH doesn’t draw the result (i.e. the Plankton.PlanktonMesh).

What to try next?

// Rolf

Ping; @DanielPiker and @DavidRutten,

Where can I find and utilize a Plankton.PlanktonMesh? Or, how can cast the PlanktonMesh to something useful?

I also found several plankton.dll’s in my GrassHopper libraries, among them in the folder for MeshEdit. But I can’t see any mesh components of that kind in my menus.

Anyhow, can a PlanktonMesh be converted to Rhino.Geometry.Mesh?

// Rolf

Hi Rolf,

I was forgetting that the MMTriangles command currently only works with a Brep input. I’ll try and make a version that can work from a starting mesh too.

For the casting of the Plankton output - you should have a PlanktonMesh param component under the Params>Geometry tab. If you connect this to the output of MeshMachine, you can either bake it directly or convert to a regular Rhino mesh.
planktoncomponent

Ah yes, there it was.

Strange that it didn’t show up when I searched for the component names though (perhaps there was a conflict when I had newer and older Kangaroo & Plankton dll’s installed…). Unfortunately I get an exception when running the component

Same error as i get when I tried compiling into a GH Component some code you had in a C# script component in a Gh definition (“Remeshimg.gha”) which was commented by you like so:

        // Dynamic remeshing script
        // Daniel Piker 07/01/2014
        // This approach is loosely based on that described in
        // "A Remeshing Approach to Multiresolution Modeling" by Botsch and Kobbelt

however, I keep getting a runtime error (probably from a Plankton.dll) saying so:

bild

The code line where it crashes (at "CollapseEdge) :

A problem with the mesh, or a dll mismatch?

// Rolf

That looks like it might a problem with the input mesh.
The triangle sizes and aspect ratios can be bad, but it does need to start out as a good mesh topologically.
If there are any naked edges they need to be restrained.
What does Rhino’s Mesh Repair command say about your input mesh?

Is there any analysis report tool inbuilt in Rhino? Anyway, it has non-manifold edges according to Gh analyis component (Elements*)

I also just noticed that the RhinoCommon command for M_Rhino_Geometry_Mesh_ExtractNonManifoldEdges doesn’t work. :frowning:

Two of the “clean components” I have tried doesn’t remove the non-manifold edges.

// Rolf

Yes - Type MeshRepair on the command line, then click Check Mesh.

Also - You might be able to get around the problems with the input mesh by only using it as a target, yet starting off from some other mesh with clean topology.

So you would make some clean mesh surrounding your object, such as a simple mesh sphere, put that into the Geom input of MeshMachine and initialise it by switching Reset from True to False.
Then you replace the Geom input with your actual target mesh. It will keep the valid topology from the sphere, but now will try and pull it onto the shape you want.

Hm, the thing is that I need to automate all this. But for now I used another mesh which was repaired with meshlab). The initial cleanup must not even be visible to the user. The user only opens up a file with the mesh which then gets cleaned and prepared for some geometric analysis. Some of these analyses are based on the vertices, which is why I need to have an isotropic mesh.

It seems difficult to make the MeshMachine end up with a specific edge length within a specific number of iterations. And if letting it run too long it fails with some error.

If you have any code that “goes right at it” i’d be very interested, otherwise I will have to let MeshLab or InstantMesher do the job in an external process (which I really want to avoid). If I’m not mistaken, it seems that RhinoCommon doesn’t have any mesh repair tools for fixing non-manifold etc).

// Rolf

@DanielPiker, I seemed like an interesting approach. However, I tried several times to shrink a sphere over my mesh, but the inital clean mesh doesn’t stop at the target mesh. It either doesn’t shrink at all or just keeps shrinking once I start the timer.

Could you think of making a demo definition in which it actually works, or a new component with a source and a target mesh?

// Rolf

Hi Rolf,

Here’s an example that shrinkwraps while remeshing, it also works without the timer.
Tested here on a bad mesh with non-manifold edges, degenerate and duplicate faces.
It uses a different build of the remesher that I don’t think I ever officially released before, so I’m including it below too. The first time you open the definition you’ll need to set the assembly locations in the script components.

Remesh_Shrinkwrap.gh (34.6 KB)
remesher.gha (20 KB)

Thank you very much!

I will try this right away.

// Rolf

1 Like

Unfortunately the component doesn’t show up, neither in Rh5 nor WIP. The first time I open up the GH definition I set the Plankton.dll’s, that was ok, but then it fails with the following message.

bild

I do have a MeshMachine installed (in a separate Kangaroo tab) but it seems like something is missing or I have the wrong version of the Meshmachine? (at least it doesn’t look like your version of MeshMachine in your earlier post in this thread):

bild

bild

Where can I download your version of the MM?

// Rolf

Hi Rolf,

The file remesher.gha in my last post above is the version you need. Did you already try installing this one? Are there any error messages on grasshopper startup?

Yes I tried installing the files in your last post, but I get error messages. In WIP I get this:

An error occured during GHA assembly loading:
  Path: C:\Users\RIL\AppData\Roaming\Grasshopper\Libraries\MeshMachine\remesher.gha
  Exception System.IO.FileLoadException: 
  Message: Could not load file or assembly 
  'file:///C:\Users\RIL\AppData\Roaming\Grasshopper\Libraries\MeshMachine\remesher.gha' 
  or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

  Exception System.NotSupportedException: 
  Message: An attempt was made to load an assembly from a network location which would have 
caused the assembly to be sandboxed in previous versions of the .NET Framework. This release 
of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. 
If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources 
switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

In Rhino 5 it doesn’t show up at all, not even attempting to.

In any case, I’m working on an application based on Rhino5 (still too many plugins missing for WIP for my project).

// Rolf

I just tested on another machine here in both R5 and the WIP and it works on both.
That error is often related to a file not being unblocked. Could you check that it is? Also, if there is another copy still in your downloads folder, try removing that.

Also, you might need to update to the latest Plankton release: https://github.com/meshmash/Plankton/releases