This commit is contained in:
John Lewin 2020-03-04 00:11:55 -08:00
parent 44822e1c59
commit e4fa3475ef
2 changed files with 35 additions and 23 deletions

View file

@ -47,37 +47,54 @@ namespace MatterHackers.MatterControl.DesignTools
public double Distance { get; set; } = 2;
private readonly Func<DMesh3, int, double, BoundedImplicitFunction3d> meshToImplicitF = (meshIn, numcells, max_offset) =>
private DMesh3 GenerateMeshF(BoundedImplicitFunction3d root, int numcells)
{
double meshCellsize = meshIn.CachedBounds.MaxDim / numcells;
var levelSet = new MeshSignedDistanceGrid(meshIn, meshCellsize);
levelSet.ExactBandWidth = (int)(max_offset / meshCellsize) + 1;
levelSet.Compute();
return new DenseGridTrilinearImplicit(levelSet.Grid, levelSet.GridOrigin, levelSet.CellSize);
};
var bounds = root.Bounds();
var c = new MarchingCubes()
{
Implicit = root,
RootMode = MarchingCubes.RootfindingModes.LerpSteps, // cube-edge convergence method
RootModeSteps = 5, // number of iterations
Bounds = bounds,
CubeSize = bounds.MaxDim / numcells,
};
private readonly Func<BoundedImplicitFunction3d, int, DMesh3> generateMeshF = (root, numcells) => {
var c = new MarchingCubes();
c.Implicit = root;
c.RootMode = MarchingCubes.RootfindingModes.LerpSteps; // cube-edge convergence method
c.RootModeSteps = 5; // number of iterations
c.Bounds = root.Bounds();
c.CubeSize = c.Bounds.MaxDim / numcells;
c.Bounds.Expand(3 * c.CubeSize); // leave a buffer of cells
c.Generate();
MeshNormals.QuickCompute(c.Mesh); // generate normals
return c.Mesh;
};
}
public Mesh HollowOut(Mesh inMesh)
{
// Convert
var mesh = inMesh.ToDMesh3();
BoundedImplicitFunction3d implicitFunction = meshToImplicitF(mesh, 64, Distance);
// Create instance of BoundedImplicitFunction3d interface
int numcells = 64;
double meshCellsize = mesh.CachedBounds.MaxDim / numcells;
var implicitMesh = generateMeshF(implicitFunction, 128);
var insetMesh = generateMeshF(new ImplicitOffset3d() { A = implicitFunction, Offset = -Distance }, 128);
var levelSet = new MeshSignedDistanceGrid(mesh, meshCellsize)
{
ExactBandWidth = (int)(Distance / meshCellsize) + 1
};
levelSet.Compute();
// Outer shell
var implicitMesh = new DenseGridTrilinearImplicit(levelSet.Grid, levelSet.GridOrigin, levelSet.CellSize);
// Inner shell subtracted from outer
var insetMesh = GenerateMeshF(
new ImplicitOffset3d()
{
A = implicitMesh,
Offset = -Distance
},
128);
// Convert
return insetMesh.ToMesh();
}

View file

@ -7,14 +7,9 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MatterControl.Common\MatterControl.Common.csproj">
<Project>{2af30557-fc50-4de3-ad1c-7eb57131a9c5}</Project>
<Name>MatterControl.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\agg\Agg.csproj">
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\DataConverters3D\DataConverters3D.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\Localizations\Localizations.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\VectorMath\VectorMath.csproj">
</ProjectReference>
<ProjectReference Include="..\Submodules\geometry3Sharp\geometry3Sharp.csproj" />