I have some issues with shrinkwrapping files which are going to be 3D printed.
In my grasshopper definition I’m using Isopod and then shrinkwrap to lower the mesh density and a bit of smoothing. The mesh output is closed but some of the faces are basically overlapping.
And I clauded something to eliminate the slivers in Grasshopper.
using System;
using System.Collections.Generic;
using System.Linq;
using Rhino.Geometry;
public class Script_Instance : GH_ScriptInstance
{
private void RunScript(Mesh M, double MaxAR, int MaxIter, ref object OutMesh, ref object Log)
{
if (M == null) return;
if (MaxAR <= 1.0) MaxAR = 25.0;
if (MaxIter <= 0) MaxIter = 100;
Mesh work = M.DuplicateMesh();
work.Faces.ConvertQuadsToTriangles();
work.Vertices.CombineIdentical(true, true);
work.Vertices.CullUnused();
int startFaces = work.Faces.Count;
int totalCollapsed = 0;
int pass = 0;
for (pass = 0; pass < MaxIter; pass++)
{
int n = work.CollapseFacesByByAspectRatio(MaxAR); // modifies 'work' in place
if (n == 0) break;
totalCollapsed += n;
// tidy up so the next pass sees a clean mesh
work.Faces.CullDegenerateFaces();
work.Vertices.CullUnused();
work.Compact();
}
work.Faces.CullDegenerateFaces();
work.Vertices.CullUnused();
work.Normals.ComputeNormals();
work.Compact();
// Report what is left, using Rhino's own aspect ratio measure
int remaining = 0;
double worst = 0;
for (int i = 0; i < work.Faces.Count; i++)
{
double ar = work.Faces.GetFaceAspectRatio(i);
if (ar > MaxAR) remaining++;
if (ar > worst) worst = ar;
}
OutMesh = work;
Log = string.Format(
"Passes: {0} | Collapsed: {1} | Faces: {2} -> {3} | Faces still > {4}: {5} | Worst AR: {6:0.##}",
pass + 1, totalCollapsed, startFaces, work.Faces.Count, MaxAR, remaining, worst);
}
}