diff --git a/MatterControlLib/PartPreviewWindow/GenerateSupportPannel.cs b/MatterControlLib/PartPreviewWindow/GenerateSupportPannel.cs index 363025e76..6de723e14 100644 --- a/MatterControlLib/PartPreviewWindow/GenerateSupportPannel.cs +++ b/MatterControlLib/PartPreviewWindow/GenerateSupportPannel.cs @@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; using MatterHackers.Localizations; @@ -34,8 +35,10 @@ using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.DesignTools; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.PolygonMesh; +using MatterHackers.RayTracer; using MatterHackers.VectorMath; using System; +using System.Collections.Generic; using System.Linq; namespace MatterHackers.MatterControl.PartPreviewWindow @@ -50,6 +53,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public class GenerateSupportPannel : FlowLayoutWidget { + /// + /// The amount ot reduce the pilars so they are separated in the 3D view + /// + private double reduceAmount => PillarSize / 8; + private InteractiveScene scene; private ThemeConfig theme; @@ -61,9 +69,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow VAnchor = VAnchor.Fit; HAnchor = HAnchor.Absolute; - Width = 400; - - // put in support pillar size + Width = 300; // support pillar resolution var pillarSizeField = new DoubleField(theme); @@ -118,16 +124,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public double PillarSize { get; private set; } = 4; - void RemoveExisting() + private void AddSupportColumn(double gridX, double gridY, double bottomZ, double topZ) { - var existingSupports = scene.Children.Where(i => i.GetType() == typeof(GeneratedSupportObject3D)); - - scene.Children.Modify((list) => + scene.Children.Add(new GeneratedSupportObject3D() { - foreach (var item in existingSupports) - { - list.Remove(item); - } + Mesh = PlatonicSolids.CreateCube(PillarSize - reduceAmount, PillarSize - reduceAmount, topZ - bottomZ), + Matrix = Matrix4X4.CreateTranslation(gridX, gridY, bottomZ + (topZ - bottomZ) / 2) }); } @@ -137,7 +139,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var visibleMeshes = scene.Children.SelectMany(i => i.VisibleMeshes()); var selectedItem = scene.SelectedItem; - if(selectedItem != null) + if (selectedItem != null) { visibleMeshes = selectedItem.VisibleMeshes(); } @@ -145,8 +147,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var supportCandidates = visibleMeshes.Where(i => i.OutputType != PrintOutputTypes.Support); // find all the faces that are candidates for support - var verts = new Vector3List(); - var faces = new FaceList(); + var upVerts = new Vector3List(); + var upFaces = new FaceList(); + var downVerts = new Vector3List(); + var downFaces = new FaceList(); foreach (var item in supportCandidates) { var matrix = item.WorldMatrix(scene); @@ -159,28 +163,63 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { foreach (var triangle in face.AsTriangles()) { - faces.Add(new int[] { verts.Count, verts.Count + 1, verts.Count + 2 }); - verts.Add(Vector3.Transform(triangle.p0, matrix)); - verts.Add(Vector3.Transform(triangle.p0, matrix)); - verts.Add(Vector3.Transform(triangle.p0, matrix)); + downFaces.Add(new int[] { downVerts.Count, downVerts.Count + 1, downVerts.Count + 2 }); + downVerts.Add(Vector3.Transform(triangle.p0, matrix)); + downVerts.Add(Vector3.Transform(triangle.p1, matrix)); + downVerts.Add(Vector3.Transform(triangle.p2, matrix)); + } + } + + if(angle > 0) + { + foreach (var triangle in face.AsTriangles()) + { + upFaces.Add(new int[] { upVerts.Count, upVerts.Count + 1, upVerts.Count + 2 }); + upVerts.Add(Vector3.Transform(triangle.p0, matrix)); + upVerts.Add(Vector3.Transform(triangle.p1, matrix)); + upVerts.Add(Vector3.Transform(triangle.p2, matrix)); } } } } - if (faces.Count > 0) + if (downFaces.Count > 0) { + var downTraceData = downFaces.CreateTraceData(downVerts, 0); + var upTraceData = upFaces.CreateTraceData(upVerts, 0); + // get the bounds of all verts - var bounds = verts.Bounds(); + var bounds = downVerts.Bounds(); // create the gird of possible support + RectangleDouble gridBounds = new RectangleDouble(Math.Floor(bounds.minXYZ.X / PillarSize), + Math.Floor(bounds.minXYZ.Y / PillarSize), + Math.Ceiling(bounds.maxXYZ.X / PillarSize), + Math.Ceiling(bounds.maxXYZ.Y / PillarSize)); + + var supportGrid = new List>((int)(gridBounds.Width * gridBounds.Height)); + + // at the center of every grid item add in a list of all the top faces to look down from + for(int y=0; y i.GetType() == typeof(GeneratedSupportObject3D)); + + scene.Children.Modify((list) => { - Mesh = PlatonicSolids.CreateCube(PillarSize / 2, PillarSize / 2, topZ - bottomZ), - Matrix = Matrix4X4.CreateTranslation(gridX, gridY, bottomZ + (topZ - bottomZ) / 2) + foreach (var item in existingSupports) + { + list.Remove(item); + } }); } } + + public static class FaceListExtensions + { + public static IPrimitive CreateTraceData(this FaceList faceList, Vector3List vertexList, int maxRecursion = int.MaxValue) + { + List allPolys = new List(); + + foreach (var face in faceList) + { + allPolys.Add(new TriangleShape(vertexList[face[0]], vertexList[face[1]], vertexList[face[2]], null)); + } + + return BoundingVolumeHierarchy.CreateNewHierachy(allPolys, maxRecursion); + } + } } \ No newline at end of file diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index dfdd6ede1..04321d099 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit dfdd6ede10f6f2c680b4b7b0f0c25c22b330e97f +Subproject commit 04321d099ffb1c27fbd52c8f8114826446771d3d