diff --git a/MatterControlLib/DesignTools/SupportGenerator.cs b/MatterControlLib/DesignTools/SupportGenerator.cs index f19e7338f..c38f2926a 100644 --- a/MatterControlLib/DesignTools/SupportGenerator.cs +++ b/MatterControlLib/DesignTools/SupportGenerator.cs @@ -80,8 +80,8 @@ namespace MatterHackers.MatterControl.DesignTools public class SupportGenerator { - private double minimumSupportHeight; - private InteractiveScene scene; + private readonly double minimumSupportHeight; + private readonly InteractiveScene scene; public SupportGenerator(InteractiveScene scene, double minimumSupportHeight) { @@ -427,14 +427,15 @@ namespace MatterHackers.MatterControl.DesignTools { // add a single plane at the bed so we always know the bed is a top detectedPlanes.Add((x, y), new List<(double z, bool bottom)>()); - detectedPlanes[(x, y)].Add((0, false)); IntersectInfo upHit = null; - for (double yOffset = -1; yOffset <= 1; yOffset++) { for (double xOffset = -1; xOffset <= 1; xOffset++) { + var singlXyPlanes = new List<(double z, bool bottom)>(); + singlXyPlanes.Add((0, false)); + var halfPillar = PillarSize / 2; var yPos = (gridBounds.Bottom + y) * PillarSize + halfPillar + (yOffset * halfPillar); var xPos = (gridBounds.Left + x) * PillarSize + halfPillar + (xOffset * halfPillar); @@ -446,7 +447,7 @@ namespace MatterHackers.MatterControl.DesignTools upHit = traceData.GetClosestIntersection(upRay); if (upHit != null) { - detectedPlanes[(x, y)].Add((upHit.HitPosition.Z, true)); + singlXyPlanes.Add((upHit.HitPosition.Z, true)); // make a new ray just past the last hit to keep looking for up hits upRay = new Ray(new Vector3(xPos, yPos, upHit.HitPosition.Z + .001), Vector3.UnitZ, intersectionType: IntersectionType.FrontFace); @@ -460,12 +461,14 @@ namespace MatterHackers.MatterControl.DesignTools upHit = traceData.GetClosestIntersection(upRay); if (upHit != null) { - detectedPlanes[(x, y)].Add((upHit.HitPosition.Z, false)); + singlXyPlanes.Add((upHit.HitPosition.Z, false)); // make a new ray just past the last hit to keep looking for up hits upRay = new Ray(new Vector3(xPos, yPos, upHit.HitPosition.Z + .001), Vector3.UnitZ, intersectionType: IntersectionType.BackFace); } } while (upHit != null); + + // union the sigleXyPlanes into detectedPlanes[(x, y)] } } } diff --git a/Tests/MatterControl.Tests/MatterControl/SupportGeneratorTests.cs b/Tests/MatterControl.Tests/MatterControl/SupportGeneratorTests.cs index 458404354..599c4256f 100644 --- a/Tests/MatterControl.Tests/MatterControl/SupportGeneratorTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/SupportGeneratorTests.cs @@ -36,6 +36,8 @@ using MatterHackers.Agg.Platform; using MatterHackers.DataConverters3D; using MatterHackers.MatterControl.DesignTools; using MatterHackers.MatterControl.Tests.Automation; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; using MatterHackers.VectorMath; using NUnit.Framework; @@ -468,6 +470,28 @@ namespace MatterControl.Tests.MatterControl Assert.AreEqual(bedSupportCount, airSupportCount, "Same number of support columns in each space."); } + + // load a complex part that should have no support required + { + InteractiveScene scene = new InteractiveScene(); + + var meshPath = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "NoSupportNeeded.stl"); + + var supportObject = new Object3D() + { + Mesh = StlProcessing.Load(meshPath, CancellationToken.None) + }; + + var aabbCube = supportObject.GetAxisAlignedBoundingBox(); + // move it so the bottom is on the bed + supportObject.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabbCube.MinXYZ.Z); + scene.Children.Add(supportObject); + + var supportGenerator = new SupportGenerator(scene, minimumSupportHeight); + supportGenerator.SupportType = SupportGenerator.SupportGenerationType.Normal; + await supportGenerator.Create(null, CancellationToken.None); + Assert.AreEqual(1, scene.Children.Count, "We should not have added support"); + } } [Test, Category("Support Generator")] diff --git a/Tests/TestData/TestParts/NoSupportNeeded.stl b/Tests/TestData/TestParts/NoSupportNeeded.stl new file mode 100644 index 000000000..7099d570c Binary files /dev/null and b/Tests/TestData/TestParts/NoSupportNeeded.stl differ