From af30e9784c8a3194e7b2a19dcd344d9f8d806c1f Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 29 Jan 2018 17:05:55 -0800 Subject: [PATCH] Improved maintain height code --- DesignTools/Primitives/ConeObject3D.cs | 14 +++++++------- DesignTools/Primitives/CubeObject3D.cs | 18 +++++++++--------- .../Primitives/CylinderAdvancedObject3D.cs | 14 +++++++------- DesignTools/Primitives/CylinderObject3D.cs | 14 +++++++------- DesignTools/Primitives/PyramidObject3D.cs | 13 ++++++------- DesignTools/Primitives/SphereObject3D.cs | 14 +++++++------- DesignTools/Primitives/TextObject3D.cs | 7 +++++++ DesignTools/Primitives/TorusObject3D.cs | 14 +++++++------- Submodules/agg-sharp | 2 +- 9 files changed, 58 insertions(+), 52 deletions(-) diff --git a/DesignTools/Primitives/ConeObject3D.cs b/DesignTools/Primitives/ConeObject3D.cs index a61544e9b..eb1975bb5 100644 --- a/DesignTools/Primitives/ConeObject3D.cs +++ b/DesignTools/Primitives/ConeObject3D.cs @@ -60,12 +60,8 @@ namespace MatterHackers.MatterControl.DesignTools public void Rebuild() { - var aabb = AxisAlignedBoundingBox.Zero; - if (Mesh != null) - { - // Keep track of the mesh height so it does not move around unexpectedly - this.GetAxisAlignedBoundingBox(); - } + var aabb = this.GetAxisAlignedBoundingBox(); + var path = new VertexStorage(); path.MoveTo(0, 0); path.LineTo(Diameter / 2, 0); @@ -73,7 +69,11 @@ namespace MatterHackers.MatterControl.DesignTools Mesh = VertexSourceToMesh.Revolve(path, Sides); Mesh.CleanAndMergeMesh(CancellationToken.None); - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/CubeObject3D.cs b/DesignTools/Primitives/CubeObject3D.cs index f9a8e8b22..45560503e 100644 --- a/DesignTools/Primitives/CubeObject3D.cs +++ b/DesignTools/Primitives/CubeObject3D.cs @@ -144,9 +144,9 @@ public class ChairFoot2 : MatterCadObject3D public double Depth { get; set; } = 20; public double Height { get; set; } = 20; - public static ConeObject3D Create() + public static CubeObject3D Create() { - var item = new ConeObject3D(); + var item = new CubeObject3D(); item.Rebuild(); return item; } @@ -166,15 +166,15 @@ public class ChairFoot2 : MatterCadObject3D public void Rebuild() { - var aabb = AxisAlignedBoundingBox.Zero; - if (Mesh != null) - { - // Keep track of the mesh height so it does not move around unexpectedly - this.GetAxisAlignedBoundingBox(); - } + var aabb = this.GetAxisAlignedBoundingBox(); + Mesh = PlatonicSolids.CreateCube(Width, Depth, Height); Mesh.CleanAndMergeMesh(CancellationToken.None); - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/CylinderAdvancedObject3D.cs b/DesignTools/Primitives/CylinderAdvancedObject3D.cs index 8b02baa4e..b1d6612c5 100644 --- a/DesignTools/Primitives/CylinderAdvancedObject3D.cs +++ b/DesignTools/Primitives/CylinderAdvancedObject3D.cs @@ -72,12 +72,7 @@ namespace MatterHackers.MatterControl.DesignTools public void Rebuild() { - var aabb = AxisAlignedBoundingBox.Zero; - if (Mesh != null) - { - // Keep track of the mesh height so it does not move around unexpectedly - this.GetAxisAlignedBoundingBox(); - } + var aabb = this.GetAxisAlignedBoundingBox(); var path = new VertexStorage(); path.MoveTo(0, -Height / 2); @@ -109,7 +104,12 @@ namespace MatterHackers.MatterControl.DesignTools } Mesh.CleanAndMergeMesh(CancellationToken.None); - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/CylinderObject3D.cs b/DesignTools/Primitives/CylinderObject3D.cs index b196ae6db..4fbc5874f 100644 --- a/DesignTools/Primitives/CylinderObject3D.cs +++ b/DesignTools/Primitives/CylinderObject3D.cs @@ -57,12 +57,8 @@ namespace MatterHackers.MatterControl.DesignTools public void Rebuild() { - var aabb = AxisAlignedBoundingBox.Zero; - if (Mesh != null) - { - // Keep track of the mesh height so it does not move around unexpectedly - this.GetAxisAlignedBoundingBox(); - } + var aabb = this.GetAxisAlignedBoundingBox(); + var path = new VertexStorage(); path.MoveTo(0, 0); path.LineTo(Diameter / 2, 0); @@ -71,7 +67,11 @@ namespace MatterHackers.MatterControl.DesignTools Mesh = VertexSourceToMesh.Revolve(path, Sides); Mesh.CleanAndMergeMesh(CancellationToken.None); - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/PyramidObject3D.cs b/DesignTools/Primitives/PyramidObject3D.cs index 298a00dbf..49c4816c5 100644 --- a/DesignTools/Primitives/PyramidObject3D.cs +++ b/DesignTools/Primitives/PyramidObject3D.cs @@ -57,12 +57,7 @@ namespace MatterHackers.MatterControl.DesignTools public void Rebuild() { - var aabb = AxisAlignedBoundingBox.Zero; - if (Mesh != null) - { - // Keep track of the mesh height so it does not move around unexpectedly - this.GetAxisAlignedBoundingBox(); - } + var aabb = this.GetAxisAlignedBoundingBox(); var path = new VertexStorage(); path.MoveTo(0, 0); @@ -73,7 +68,11 @@ namespace MatterHackers.MatterControl.DesignTools Mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2, Depth / 2, 1)); Mesh.CleanAndMergeMesh(CancellationToken.None); - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/SphereObject3D.cs b/DesignTools/Primitives/SphereObject3D.cs index d9c518c29..2ba6d8788 100644 --- a/DesignTools/Primitives/SphereObject3D.cs +++ b/DesignTools/Primitives/SphereObject3D.cs @@ -59,12 +59,8 @@ namespace MatterHackers.MatterControl.DesignTools public void Rebuild() { - var aabb = AxisAlignedBoundingBox.Zero; - if (Mesh != null) - { - // Keep track of the mesh height so it does not move around unexpectedly - this.GetAxisAlignedBoundingBox(); - } + var aabb = this.GetAxisAlignedBoundingBox(); + var path = new VertexStorage(); var angleDelta = MathHelper.Tau / 2 / LatitudeSides; var angle = -MathHelper.Tau / 4; @@ -77,7 +73,11 @@ namespace MatterHackers.MatterControl.DesignTools } Mesh = VertexSourceToMesh.Revolve(path, LongitudeSides); - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/TextObject3D.cs b/DesignTools/Primitives/TextObject3D.cs index d34903ca3..13134bb6a 100644 --- a/DesignTools/Primitives/TextObject3D.cs +++ b/DesignTools/Primitives/TextObject3D.cs @@ -89,6 +89,8 @@ namespace MatterHackers.MatterControl.DesignTools public void Rebuild() { + var aabb = this.GetAxisAlignedBoundingBox(); + var letterPrinter = new TypeFacePrinter(NameToWrite, new StyledTypeFace(NamedTypeFaceCache.GetTypeFace(Font), PointSize * 0.352778)); IObject3D nameMesh = new Object3D() @@ -102,6 +104,11 @@ namespace MatterHackers.MatterControl.DesignTools list.Clear(); list.Add(nameMesh); }); + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/TorusObject3D.cs b/DesignTools/Primitives/TorusObject3D.cs index 4e4712e3a..886e04c74 100644 --- a/DesignTools/Primitives/TorusObject3D.cs +++ b/DesignTools/Primitives/TorusObject3D.cs @@ -63,12 +63,8 @@ namespace MatterHackers.MatterControl.DesignTools public void Rebuild() { - var aabb = AxisAlignedBoundingBox.Zero; - if (Mesh != null) - { - // Keep track of the mesh height so it does not move around unexpectedly - this.GetAxisAlignedBoundingBox(); - } + var aabb = this.GetAxisAlignedBoundingBox(); + var poleRadius = (OuterDiameter / 2 - InnerDiameter / 2) / 2; var toroidRadius = InnerDiameter / 2 + poleRadius; var path = new VertexStorage(); @@ -84,7 +80,11 @@ namespace MatterHackers.MatterControl.DesignTools Mesh = VertexSourceToMesh.Revolve(path, ToroidSides); Mesh.CleanAndMergeMesh(CancellationToken.None); - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + if (aabb.ZSize > 0) + { + // If the part was already created and at a height, maintain the height. + PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + } } } } \ No newline at end of file diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index b0c51144b..6b6552e23 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit b0c51144b762d465bea298efa7e80452966268f7 +Subproject commit 6b6552e231b9b382f030558d1e6f5795f4a6f5fb