From bc232506af4d38998b9250d23edffe999fa095e9 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sun, 11 Jul 2021 18:51:46 -0700 Subject: [PATCH] making first pass at dual contouring for union --- .../BooleanProcessing.cs | 41 +++++++++++++++---- .../Primitives/MarchingSquaresObject3D.cs | 8 ++-- Submodules/agg-sharp | 2 +- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/MatterControl.MeshOperations/BooleanProcessing.cs b/MatterControl.MeshOperations/BooleanProcessing.cs index 730cf967c..03387def0 100644 --- a/MatterControl.MeshOperations/BooleanProcessing.cs +++ b/MatterControl.MeshOperations/BooleanProcessing.cs @@ -34,6 +34,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading; +using DualContouring; using g3; using gs; using MatterHackers.Agg; @@ -176,17 +177,43 @@ namespace MatterHackers.PolygonMesh switch (operation) { case CsgModes.Union: - return GenerateMeshF(new ImplicitNaryUnion3d() { - Children = implicitMeshs - }, marchingCells).ToMesh(); + var bounds = implicitMeshs.First().Bounds(); + var root = Octree.BuildOctree((pos) => + { + var pos2 = new Vector3d(pos.X, pos.Y, pos.Z); + return implicitMeshs.First().Value(ref pos2); + }, new Vector3(bounds.Min.x, bounds.Min.y, bounds.Min.z), + new Vector3(bounds.Width, bounds.Depth, bounds.Height), + 5, + .001); + return Octree.GenerateMeshFromOctree(root); + + return GenerateMeshF(new ImplicitNaryUnion3d() + { + Children = implicitMeshs + }, marchingCells).ToMesh(); + } case CsgModes.Subtract: - return GenerateMeshF(new ImplicitNaryDifference3d() { - A = implicitMeshs.First(), - BSet = implicitMeshs.GetRange(0, implicitMeshs.Count - 1) - }, marchingCells).ToMesh(); + var bounds = implicitMeshs.First().Bounds(); + var root = Octree.BuildOctree((pos) => + { + var pos2 = new Vector3d(pos.X, pos.Y, pos.Z); + return implicitMeshs.First().Value(ref pos2); + }, new Vector3(bounds.Min.x, bounds.Min.y, bounds.Min.z), + new Vector3(bounds.Width, bounds.Depth, bounds.Height), + 5, + .001); + return Octree.GenerateMeshFromOctree(root); + + return GenerateMeshF(new ImplicitNaryDifference3d() + { + A = implicitMeshs.First(), + BSet = implicitMeshs.GetRange(0, implicitMeshs.Count - 1) + }, marchingCells).ToMesh(); + } case CsgModes.Intersect: return GenerateMeshF(new ImplicitNaryIntersection3d() diff --git a/MatterControlLib/DesignTools/Primitives/MarchingSquaresObject3D.cs b/MatterControlLib/DesignTools/Primitives/MarchingSquaresObject3D.cs index 10fe728d5..33f946b04 100644 --- a/MatterControlLib/DesignTools/Primitives/MarchingSquaresObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/MarchingSquaresObject3D.cs @@ -118,10 +118,10 @@ namespace MatterHackers.MatterControl.DesignTools Mesh = Octree.GenerateMeshFromOctree(root); #else - var c = new MarchingCubes(); - c.Generate(); - MeshNormals.QuickCompute(c.Mesh); // generate normals - Mesh = c.Mesh.ToMesh(); + var c = new MarchingCubes(); + c.Generate(); + MeshNormals.QuickCompute(c.Mesh); // generate normals + Mesh = c.Mesh.ToMesh(); #endif } } diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 59607c340..afd8e1a90 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 59607c340143d8a46ce3907931dbead5a081fc3b +Subproject commit afd8e1a909a478b9058724e6cc571144cb6d7c59