From e1ce3419f2a64864d5295c5bdcf28ef60bda19eb Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 11 Jan 2019 16:49:34 -0800 Subject: [PATCH] simple mesh --- .../RenderFeatures/RenderFeatureBase.cs | 18 +- .../RenderFeatures/RenderFeatureExtrusion.cs | 8 +- .../RenderFeatures/RenderFeatureRetract.cs | 2 +- .../RenderFeatures/RenderFeatureTravel.cs | 12 +- .../GCode/PrinterMachineInstruction.cs | 24 +- .../ApplicationView/ApplicationController.cs | 4 + .../PrinterExtensionMethods.cs | 20 +- .../Braille/BrailleCardObject3D.cs | 2 +- .../DesignTools/Braille/BrailleObject3D.cs | 2 +- MatterControlLib/DesignTools/Lithophane.cs | 205 +++++++++--------- .../Obsolete/FitToBoundsObject3D.cs | 6 +- .../DesignTools/Obsolete/RotateObject3D.cs | 2 +- .../DesignTools/Operations/AlignObject3D.cs | 56 ++--- .../Operations/ArrayAdvancedObject3D.cs | 2 +- .../DesignTools/Operations/CurveObject3D.cs | 123 ++++++----- .../Operations/FitToBoundsObject3D_2.cs | 6 +- .../Operations/Image/ImageToPathObject3D.cs | 8 +- .../DesignTools/Operations/MirrorObject3D.cs | 4 +- .../DesignTools/Operations/PinchObject3D.cs | 22 +- .../DesignTools/Operations/ScaleObject3D.cs | 2 +- .../DesignTools/Primitives/BaseObject3D.cs | 6 +- .../DesignTools/Primitives/ConeObject3D.cs | 2 +- .../DesignTools/Primitives/CubeObject3D.cs | 2 +- .../Primitives/CylinderObject3D.cs | 2 +- .../Primitives/HalfCylinderObject3D.cs | 2 +- .../Primitives/HalfSphereObject3D.cs | 2 +- .../Primitives/HalfWedgeObject3D.cs | 2 +- .../DesignTools/Primitives/ImageObject3D.cs | 4 +- .../DesignTools/Primitives/PyramidObject3D.cs | 2 +- .../DesignTools/Primitives/RingObject3D.cs | 2 +- .../DesignTools/Primitives/SphereObject3D.cs | 2 +- .../DesignTools/Primitives/TextObject3D.cs | 12 +- .../DesignTools/Primitives/TorusObject3D.cs | 2 +- .../DesignTools/Primitives/WedgeObject3D.cs | 2 +- .../Library/Export/GCodeExport.cs | 2 +- .../Library/Widgets/InsertionGroupObject3D.cs | 2 +- .../PartPreviewWindow/CreateDiscreteMeshes.cs | 123 +++++------ .../PartPreviewWindow/GenerateSupportPanel.cs | 136 ++++++------ .../PartPreviewWindow/PlatingHelper.cs | 22 +- .../View3D/Actions/BooleanProcessing.cs | 6 +- .../View3D/BedMeshGenerator.cs | 36 +-- .../PartPreviewWindow/View3D/DebugBvh.cs | 21 +- .../View3D/Gui3D/MoveInZControl.cs | 16 +- .../View3D/Gui3D/SnapingIndicator.cs | 8 +- .../View3D/InteractionLayer.cs | 16 +- .../View3D/InteractionVolume.cs | 6 +- .../View3D/MeshViewerWidget.cs | 82 +++---- .../PartPreviewWindow/View3D/SceneActions.cs | 82 ++++--- .../View3D/TumbleCubeControl.cs | 21 +- .../PartPreviewWindow/View3D/View3DWidget.cs | 18 +- .../PrinterControls/PrintLevelingPlane.cs | 4 +- .../Slicing/SliceLayers.cs | 65 +++--- Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- .../MatterControl/MeshCsgTests.cs | 169 ++++++++------- 55 files changed, 713 insertions(+), 698 deletions(-) diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs index b49b2b478..71acebe74 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs @@ -71,8 +71,8 @@ namespace MatterHackers.GCodeVisualizer for (int i = 0; i < steps; i++) { // create tube ends verts - Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); - Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); + Vector3 tubeNormal = Vector3Ex.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); + Vector3 offset = Vector3Ex.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); offset *= scale; Vector3 tubeStart = startPos + offset; @@ -84,9 +84,9 @@ namespace MatterHackers.GCodeVisualizer colorVertexData.Add(new ColorVertexData(tubeEnd, tubeNormal, color)); // create cap verts - Vector3 rotateAngle = Vector3.Cross(startSweepDirection, direction); - Vector3 capStartNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(rotateAngle, MathHelper.Tau / 8)); - capStartNormal = Vector3.Transform(capStartNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); + Vector3 rotateAngle = Vector3Ex.Cross(startSweepDirection, direction); + Vector3 capStartNormal = Vector3Ex.Transform(startSweepDirection, Matrix4X4.CreateRotation(rotateAngle, MathHelper.Tau / 8)); + capStartNormal = Vector3Ex.Transform(capStartNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capStartNormal = (capStartNormal * scale).GetNormal(); Vector3 capStartOffset = capStartNormal * radius; capStartOffset *= scale; @@ -94,8 +94,8 @@ namespace MatterHackers.GCodeVisualizer capStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capStart, capStartNormal, color)); - Vector3 capEndNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(-rotateAngle, MathHelper.Tau / 8)); - capEndNormal = Vector3.Transform(capEndNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); + Vector3 capEndNormal = Vector3Ex.Transform(startSweepDirection, Matrix4X4.CreateRotation(-rotateAngle, MathHelper.Tau / 8)); + capEndNormal = Vector3Ex.Transform(capEndNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capEndNormal = (capEndNormal * scale).GetNormal(); Vector3 capEndOffset = capEndNormal * radius; capEndOffset *= scale; @@ -163,8 +163,8 @@ namespace MatterHackers.GCodeVisualizer for (int i = 0; i < steps; i++) { // create tube ends verts - Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); - Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); + Vector3 tubeNormal = Vector3Ex.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); + Vector3 offset = Vector3Ex.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs index 5ad70566c..6379d29d2 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs @@ -143,10 +143,10 @@ namespace MatterHackers.GCodeVisualizer { Vector3Float startF = this.GetStart(renderInfo); Vector3Float endF = this.GetEnd(renderInfo); - Vector2 start = new Vector2(startF.x, startF.y); + Vector2 start = new Vector2(startF.X, startF.Y); renderInfo.Transform.transform(ref start); - Vector2 end = new Vector2(endF.x, endF.y); + Vector2 end = new Vector2(endF.X, endF.Y); renderInfo.Transform.transform(ref end); graphics2DGl.DrawAALineRounded(start, end, extrusionLineWidths / 2, extrusionColor); @@ -163,8 +163,8 @@ namespace MatterHackers.GCodeVisualizer Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); - pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.MoveTo); - pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo); + pathStorage.Add(start.X, start.Y, ShapePath.FlagsAndCommand.MoveTo); + pathStorage.Add(end.X, end.Y, ShapePath.FlagsAndCommand.LineTo); graphics2D.Render(stroke, extrusionColor); } diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs index f117bd02e..005410420 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs @@ -100,7 +100,7 @@ namespace MatterHackers.GCodeVisualizer if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions) { double radius = Radius(renderInfo.LayerScale); - Vector2 position = new Vector2(this.position.x, this.position.y); + Vector2 position = new Vector2(this.position.X, this.position.Y); renderInfo.Transform.transform(ref position); diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs index ff17db354..babcbc3d7 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs @@ -82,10 +82,10 @@ namespace MatterHackers.GCodeVisualizer { Vector3Float startF = this.GetStart(renderInfo); Vector3Float endF = this.GetEnd(renderInfo); - Vector2 start = new Vector2(startF.x, startF.y); + Vector2 start = new Vector2(startF.X, startF.Y); renderInfo.Transform.transform(ref start); - Vector2 end = new Vector2(endF.x, endF.y); + Vector2 end = new Vector2(endF.X, endF.Y); renderInfo.Transform.transform(ref end); if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion)) @@ -107,14 +107,14 @@ namespace MatterHackers.GCodeVisualizer Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); - pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.MoveTo); - if (end.x != start.x || end.y != start.y) + pathStorage.Add(start.X, start.Y, ShapePath.FlagsAndCommand.MoveTo); + if (end.X != start.X || end.Y != start.Y) { - pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo); + pathStorage.Add(end.X, end.Y, ShapePath.FlagsAndCommand.LineTo); } else { - pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.LineTo); + pathStorage.Add(end.X + .01, end.Y, ShapePath.FlagsAndCommand.LineTo); } graphics2D.Render(stroke, movementColor); diff --git a/MatterControl.Printing/GCode/PrinterMachineInstruction.cs b/MatterControl.Printing/GCode/PrinterMachineInstruction.cs index d240aac69..bd8a78e05 100644 --- a/MatterControl.Printing/GCode/PrinterMachineInstruction.cs +++ b/MatterControl.Printing/GCode/PrinterMachineInstruction.cs @@ -100,56 +100,56 @@ namespace MatterControl.Printing get { return new Vector3(xyzPosition); } set { - xyzPosition.x = (float)value.X; - xyzPosition.y = (float)value.Y; - xyzPosition.z = (float)value.Z; + xyzPosition.X = (float)value.X; + xyzPosition.Y = (float)value.Y; + xyzPosition.Z = (float)value.Z; } } public double X { - get { return xyzPosition.x; } + get { return xyzPosition.X; } set { if (MovementType == MovementTypes.Absolute) { - xyzPosition.x = (float)value; + xyzPosition.X = (float)value; } else { - xyzPosition.x += (float)value; + xyzPosition.X += (float)value; } } } public double Y { - get { return xyzPosition.y; } + get { return xyzPosition.Y; } set { if (MovementType == MovementTypes.Absolute) { - xyzPosition.y = (float)value; + xyzPosition.Y = (float)value; } else { - xyzPosition.y += (float)value; + xyzPosition.Y += (float)value; } } } public double Z { - get { return xyzPosition.z; } + get { return xyzPosition.Z; } set { if (MovementType == MovementTypes.Absolute) { - xyzPosition.z = (float)value; + xyzPosition.Z = (float)value; } else { - xyzPosition.z += (float)value; + xyzPosition.Z += (float)value; } } } diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 375ccad69..4109ab10f 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -291,6 +291,10 @@ namespace MatterHackers.MatterControl popupMenu.CreateSeparator(); +#if DEBUG + GC.Collect(); +#endif + var selectedItemType = selectedItem.GetType(); var menuTheme = this.MenuTheme; diff --git a/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs b/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs index 3c5c7399b..0d0218227 100644 --- a/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs +++ b/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs @@ -53,8 +53,8 @@ namespace MatterHackers.MatterControl var bed = printerConfig.Bed; if (bed.BuildHeight > 0 - && aabb.maxXYZ.Z >= bed.BuildHeight - || aabb.maxXYZ.Z <= 0) + && aabb.MaxXYZ.Z >= bed.BuildHeight + || aabb.MaxXYZ.Z <= 0) { // object completely below the bed or any part above the build volume return false; @@ -63,10 +63,10 @@ namespace MatterHackers.MatterControl switch (bed.BedShape) { case BedShape.Rectangular: - if (aabb.minXYZ.X < bed.BedCenter.X - bed.ViewerVolume.X / 2 - || aabb.maxXYZ.X > bed.BedCenter.X + bed.ViewerVolume.X / 2 - || aabb.minXYZ.Y < bed.BedCenter.Y - bed.ViewerVolume.Y / 2 - || aabb.maxXYZ.Y > bed.BedCenter.Y + bed.ViewerVolume.Y / 2) + if (aabb.MinXYZ.X < bed.BedCenter.X - bed.ViewerVolume.X / 2 + || aabb.MaxXYZ.X > bed.BedCenter.X + bed.ViewerVolume.X / 2 + || aabb.MinXYZ.Y < bed.BedCenter.Y - bed.ViewerVolume.Y / 2 + || aabb.MaxXYZ.Y > bed.BedCenter.Y + bed.ViewerVolume.Y / 2) { return false; } @@ -75,10 +75,10 @@ namespace MatterHackers.MatterControl case BedShape.Circular: // This could be much better if it checked the actual vertex data of the mesh against the cylinder // first check if any of it is outside the bed rect - if (aabb.minXYZ.X < bed.BedCenter.X - bed.ViewerVolume.X / 2 - || aabb.maxXYZ.X > bed.BedCenter.X + bed.ViewerVolume.X / 2 - || aabb.minXYZ.Y < bed.BedCenter.Y - bed.ViewerVolume.Y / 2 - || aabb.maxXYZ.Y > bed.BedCenter.Y + bed.ViewerVolume.Y / 2) + if (aabb.MinXYZ.X < bed.BedCenter.X - bed.ViewerVolume.X / 2 + || aabb.MaxXYZ.X > bed.BedCenter.X + bed.ViewerVolume.X / 2 + || aabb.MinXYZ.Y < bed.BedCenter.Y - bed.ViewerVolume.Y / 2 + || aabb.MaxXYZ.Y > bed.BedCenter.Y + bed.ViewerVolume.Y / 2) { // TODO: then check if all of it is outside the bed circle return false; diff --git a/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs b/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs index fbeca9291..435f18af3 100644 --- a/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs +++ b/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs @@ -125,7 +125,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs b/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs index 72ee1d3a4..14afbb9c6 100644 --- a/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs +++ b/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs @@ -263,7 +263,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Lithophane.cs b/MatterControlLib/DesignTools/Lithophane.cs index cc2f6e885..9b0a505d1 100644 --- a/MatterControlLib/DesignTools/Lithophane.cs +++ b/MatterControlLib/DesignTools/Lithophane.cs @@ -16,141 +16,142 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane { class PixelInfo { - public IVertex Top { get; set; } - public IVertex Bottom { get; set; } + public Vector3 Top { get; set; } + public Vector3 Bottom { get; set; } } public static Mesh Generate(IImageData resizedImage, double maxZ, double nozzleWidth, double pixelsPerMM, bool invert, IProgress reporter) { - // TODO: Move this to a user supplied value - double baseThickness = nozzleWidth; // base thickness (in mm) - double zRange = maxZ - baseThickness; + throw new NotImplementedException(); + //// TODO: Move this to a user supplied value + //double baseThickness = nozzleWidth; // base thickness (in mm) + //double zRange = maxZ - baseThickness; - // Dimensions of image - var width = resizedImage.Width; - var height = resizedImage.Height; + //// Dimensions of image + //var width = resizedImage.Width; + //var height = resizedImage.Height; - var zScale = zRange / 255; + //var zScale = zRange / 255; - var pixelData = resizedImage.Pixels; + //var pixelData = resizedImage.Pixels; - Stopwatch stopwatch = Stopwatch.StartNew(); + //Stopwatch stopwatch = Stopwatch.StartNew(); - var mesh = new Mesh(); + //var mesh = new Mesh(); - //var rescale = (double)onPlateWidth / imageData.Width; - var rescale = 1; + ////var rescale = (double)onPlateWidth / imageData.Width; + //var rescale = 1; - var progressStatus = new ProgressStatus(); + //var progressStatus = new ProgressStatus(); - // Build an array of PixelInfo objects from each pixel - // Collapse from 4 bytes per pixel to one - makes subsequent processing more logical and has minimal cost - var pixels = pixelData.Where((x, i) => i % 4 == 0) + //// Build an array of PixelInfo objects from each pixel + //// Collapse from 4 bytes per pixel to one - makes subsequent processing more logical and has minimal cost + //var pixels = pixelData.Where((x, i) => i % 4 == 0) - // Interpolate the pixel color to zheight - .Select(b => baseThickness + (invert ? 255 - b : b) * zScale) + // // Interpolate the pixel color to zheight + // .Select(b => baseThickness + (invert ? 255 - b : b) * zScale) - // Create a Vector3 for each pixel at the computed x/y/z - .Select((z, i) => mesh.CreateVertex(new Vector3( - i % width * rescale, - (i - i % width) / width * rescale * -1, - z))) + // // Create a Vector3 for each pixel at the computed x/y/z + // .Select((z, i) => mesh.CreateVertex(new Vector3( + // i % width * rescale, + // (i - i % width) / width * rescale * -1, + // z))) - // Create a mirrored vector for the pixel at z0 and return with top/bottom paired together - .Select(vec => new PixelInfo() - { - Top = vec, - Bottom = mesh.CreateVertex(new Vector3( - vec.Position.X, - vec.Position.Y, - 0)) - }).ToArray(); + // // Create a mirrored vector for the pixel at z0 and return with top/bottom paired together + // .Select(vec => new PixelInfo() + // { + // Top = vec, + // Bottom = mesh.CreateVertex(new Vector3( + // vec.Position.X, + // vec.Position.Y, + // 0)) + // }).ToArray(); - Console.WriteLine("ElapsedTime - PixelInfo Linq Generation: {0}", stopwatch.ElapsedMilliseconds); - stopwatch.Restart(); + //Console.WriteLine("ElapsedTime - PixelInfo Linq Generation: {0}", stopwatch.ElapsedMilliseconds); + //stopwatch.Restart(); - // Select pixels along image edges - var backRow = pixels.Take(width).Reverse().ToArray(); - var frontRow = pixels.Skip((height - 1) * width).Take(width).ToArray(); - var leftRow = pixels.Where((x, i) => i % width == 0).ToArray(); - var rightRow = pixels.Where((x, i) => (i + 1) % width == 0).Reverse().ToArray(); + //// Select pixels along image edges + //var backRow = pixels.Take(width).Reverse().ToArray(); + //var frontRow = pixels.Skip((height - 1) * width).Take(width).ToArray(); + //var leftRow = pixels.Where((x, i) => i % width == 0).ToArray(); + //var rightRow = pixels.Where((x, i) => (i + 1) % width == 0).Reverse().ToArray(); - int k, - nextJ, - nextK; + //int k, + // nextJ, + // nextK; - var notificationInterval = 100; + //var notificationInterval = 100; - var workCount = (resizedImage.Width - 1) * (resizedImage.Height - 1) + - (height - 1) + - (width - 1); + //var workCount = (resizedImage.Width - 1) * (resizedImage.Height - 1) + + // (height - 1) + + // (width - 1); - double workIndex = 0; + //double workIndex = 0; - // Vertical faces: process each row and column, creating the top and bottom faces as appropriate - for (int i = 0; i < resizedImage.Height - 1; ++i) - { - var startAt = i * width; + //// Vertical faces: process each row and column, creating the top and bottom faces as appropriate + //for (int i = 0; i < resizedImage.Height - 1; ++i) + //{ + // var startAt = i * width; - // Process each column - for (int j = startAt; j < startAt + resizedImage.Width - 1; ++j) - { - k = j + 1; - nextJ = j + resizedImage.Width; - nextK = nextJ + 1; + // // Process each column + // for (int j = startAt; j < startAt + resizedImage.Width - 1; ++j) + // { + // k = j + 1; + // nextJ = j + resizedImage.Width; + // nextK = nextJ + 1; - // Create north, then south face - mesh.CreateFace(new IVertex[] { pixels[k].Top, pixels[j].Top, pixels[nextJ].Top, pixels[nextK].Top }); - mesh.CreateFace(new IVertex[] { pixels[j].Bottom, pixels[k].Bottom, pixels[nextK].Bottom, pixels[nextJ].Bottom }); - workIndex++; + // // Create north, then south face + // mesh.CreateFace(new IVertex[] { pixels[k].Top, pixels[j].Top, pixels[nextJ].Top, pixels[nextK].Top }); + // mesh.CreateFace(new IVertex[] { pixels[j].Bottom, pixels[k].Bottom, pixels[nextK].Bottom, pixels[nextJ].Bottom }); + // workIndex++; - if (workIndex % notificationInterval == 0) - { - progressStatus.Progress0To1 = workIndex / workCount; - reporter.Report(progressStatus); - } - } - } + // if (workIndex % notificationInterval == 0) + // { + // progressStatus.Progress0To1 = workIndex / workCount; + // reporter.Report(progressStatus); + // } + // } + //} - // Side faces: East/West - for (int j = 0; j < height - 1; ++j) - { - //Next row - k = j + 1; + //// Side faces: East/West + //for (int j = 0; j < height - 1; ++j) + //{ + // //Next row + // k = j + 1; - // Create east, then west face - mesh.CreateFace(new IVertex[] { leftRow[k].Top, leftRow[j].Top, leftRow[j].Bottom, leftRow[k].Bottom }); - mesh.CreateFace(new IVertex[] { rightRow[k].Top, rightRow[j].Top, rightRow[j].Bottom, rightRow[k].Bottom }); - workIndex++; + // // Create east, then west face + // mesh.CreateFace(new IVertex[] { leftRow[k].Top, leftRow[j].Top, leftRow[j].Bottom, leftRow[k].Bottom }); + // mesh.CreateFace(new IVertex[] { rightRow[k].Top, rightRow[j].Top, rightRow[j].Bottom, rightRow[k].Bottom }); + // workIndex++; - if (workIndex % notificationInterval == 0) - { - progressStatus.Progress0To1 = workIndex / workCount; - reporter.Report(progressStatus); - } - } + // if (workIndex % notificationInterval == 0) + // { + // progressStatus.Progress0To1 = workIndex / workCount; + // reporter.Report(progressStatus); + // } + //} - // Side faces: North/South - for (int j = 0; j < width - 1; ++j) - { - // Next row - k = j + 1; + //// Side faces: North/South + //for (int j = 0; j < width - 1; ++j) + //{ + // // Next row + // k = j + 1; - // Create north, then south face - mesh.CreateFace(new IVertex[] { frontRow[k].Top, frontRow[j].Top, frontRow[j].Bottom, frontRow[k].Bottom }); - mesh.CreateFace(new IVertex[] { backRow[k].Top, backRow[j].Top, backRow[j].Bottom, backRow[k].Bottom }); - workIndex++; + // // Create north, then south face + // mesh.CreateFace(new IVertex[] { frontRow[k].Top, frontRow[j].Top, frontRow[j].Bottom, frontRow[k].Bottom }); + // mesh.CreateFace(new IVertex[] { backRow[k].Top, backRow[j].Top, backRow[j].Bottom, backRow[k].Bottom }); + // workIndex++; - if (workIndex % notificationInterval == 0) - { - progressStatus.Progress0To1 = workIndex / workCount; - reporter.Report(progressStatus); - } - } + // if (workIndex % notificationInterval == 0) + // { + // progressStatus.Progress0To1 = workIndex / workCount; + // reporter.Report(progressStatus); + // } + //} - Console.WriteLine("ElapsedTime - Face Generation: {0}", stopwatch.ElapsedMilliseconds); + //Console.WriteLine("ElapsedTime - Face Generation: {0}", stopwatch.ElapsedMilliseconds); - return mesh; + //return mesh; } public interface IImageData diff --git a/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs b/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs index 3292cd608..4b784f1ad 100644 --- a/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs @@ -171,7 +171,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } @@ -254,8 +254,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations var minXyz = center - new Vector3(Width / 2, Depth / 2, Height / 2); var maxXyz = center + new Vector3(Width / 2, Depth / 2, Height / 2); var bounds = new AxisAlignedBoundingBox(minXyz, maxXyz); - //var leftW = Vector3.Transform(, worldMatrix); - var right = Vector3.Transform(center + new Vector3(Width / 2, 0, 0), worldMatrix); + //var leftW = Vector3Ex.Transform(, worldMatrix); + var right = Vector3Ex.Transform(center + new Vector3(Width / 2, 0, 0), worldMatrix); // layer.World.Render3DLine(left, right, Agg.Color.Red); layer.World.RenderAabb(bounds, worldMatrix, Agg.Color.Red, 1, 1); } diff --git a/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs b/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs index 6bbef3be1..cb5ebe857 100644 --- a/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs @@ -90,7 +90,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (startingAabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, startingAabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, startingAabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Operations/AlignObject3D.cs b/MatterControlLib/DesignTools/Operations/AlignObject3D.cs index 2e8e4640e..068a46023 100644 --- a/MatterControlLib/DesignTools/Operations/AlignObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/AlignObject3D.cs @@ -122,27 +122,27 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (IsSet(boundingFacesToAlign, FaceAlign.Left, FaceAlign.Right)) { - positionToAlignTo.X = positionToAlignTo.X - bounds.minXYZ.X; + positionToAlignTo.X = positionToAlignTo.X - bounds.MinXYZ.X; } if (IsSet(boundingFacesToAlign, FaceAlign.Right, FaceAlign.Left)) { - positionToAlignTo.X = positionToAlignTo.X - bounds.minXYZ.X - (bounds.maxXYZ.X - bounds.minXYZ.X); + positionToAlignTo.X = positionToAlignTo.X - bounds.MinXYZ.X - (bounds.MaxXYZ.X - bounds.MinXYZ.X); } if (IsSet(boundingFacesToAlign, FaceAlign.Front, FaceAlign.Back)) { - positionToAlignTo.Y = positionToAlignTo.Y - bounds.minXYZ.Y; + positionToAlignTo.Y = positionToAlignTo.Y - bounds.MinXYZ.Y; } if (IsSet(boundingFacesToAlign, FaceAlign.Back, FaceAlign.Front)) { - positionToAlignTo.Y = positionToAlignTo.Y - bounds.minXYZ.Y - (bounds.maxXYZ.Y - bounds.minXYZ.Y); + positionToAlignTo.Y = positionToAlignTo.Y - bounds.MinXYZ.Y - (bounds.MaxXYZ.Y - bounds.MinXYZ.Y); } if (IsSet(boundingFacesToAlign, FaceAlign.Bottom, FaceAlign.Top)) { - positionToAlignTo.Z = positionToAlignTo.Z - bounds.minXYZ.Z; + positionToAlignTo.Z = positionToAlignTo.Z - bounds.MinXYZ.Z; } if (IsSet(boundingFacesToAlign, FaceAlign.Top, FaceAlign.Bottom)) { - positionToAlignTo.Z = positionToAlignTo.Z - bounds.minXYZ.Z - (bounds.maxXYZ.Z - bounds.minXYZ.Z); + positionToAlignTo.Z = positionToAlignTo.Z - bounds.MinXYZ.Z - (bounds.MaxXYZ.Z - bounds.MinXYZ.Z); } Matrix *= Matrix4X4.CreateTranslation(positionToAlignTo); @@ -245,27 +245,27 @@ namespace MatterHackers.MatterControl.DesignTools.Operations Vector3 positionToAlignTo = new Vector3(); if (IsSet(boundingFacesToAlignTo, FaceAlign.Left, FaceAlign.Right)) { - positionToAlignTo.X = objectToAlignTo.GetAxisAlignedBoundingBox().minXYZ.X; + positionToAlignTo.X = objectToAlignTo.GetAxisAlignedBoundingBox().MinXYZ.X; } if (IsSet(boundingFacesToAlignTo, FaceAlign.Right, FaceAlign.Left)) { - positionToAlignTo.X = objectToAlignTo.GetAxisAlignedBoundingBox().maxXYZ.X; + positionToAlignTo.X = objectToAlignTo.GetAxisAlignedBoundingBox().MaxXYZ.X; } if (IsSet(boundingFacesToAlignTo, FaceAlign.Front, FaceAlign.Back)) { - positionToAlignTo.Y = objectToAlignTo.GetAxisAlignedBoundingBox().minXYZ.Y; + positionToAlignTo.Y = objectToAlignTo.GetAxisAlignedBoundingBox().MinXYZ.Y; } if (IsSet(boundingFacesToAlignTo, FaceAlign.Back, FaceAlign.Front)) { - positionToAlignTo.Y = objectToAlignTo.GetAxisAlignedBoundingBox().maxXYZ.Y; + positionToAlignTo.Y = objectToAlignTo.GetAxisAlignedBoundingBox().MaxXYZ.Y; } if (IsSet(boundingFacesToAlignTo, FaceAlign.Bottom, FaceAlign.Top)) { - positionToAlignTo.Z = objectToAlignTo.GetAxisAlignedBoundingBox().minXYZ.Z; + positionToAlignTo.Z = objectToAlignTo.GetAxisAlignedBoundingBox().MinXYZ.Z; } if (IsSet(boundingFacesToAlignTo, FaceAlign.Top, FaceAlign.Bottom)) { - positionToAlignTo.Z = objectToAlignTo.GetAxisAlignedBoundingBox().maxXYZ.Z; + positionToAlignTo.Z = objectToAlignTo.GetAxisAlignedBoundingBox().MaxXYZ.Z; } return positionToAlignTo + extraOffset; } @@ -329,7 +329,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations }); } - this.Children.Modify(list => + this.Children.Modify((Action>)((List list) => { if (list.Count == 0) { @@ -348,7 +348,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (i < OriginalChildrenBounds.Count) { // make sure it is where it started - AlignAxis(0, Align.Min, OriginalChildrenBounds[i].minXYZ.X, 0, child); + AlignAxis(0, Align.Min, (double)OriginalChildrenBounds[i].MinXYZ.X, 0, child); } } @@ -357,7 +357,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations { if (i < OriginalChildrenBounds.Count) { - AlignAxis(1, Align.Min, OriginalChildrenBounds[i].minXYZ.Y, 0, child); + AlignAxis(1, Align.Min, (double)OriginalChildrenBounds[i].MinXYZ.Y, 0, child); } } @@ -366,7 +366,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations { if (i < OriginalChildrenBounds.Count) { - AlignAxis(2, Align.Min, OriginalChildrenBounds[i].minXYZ.Z, 0, child); + AlignAxis(2, Align.Min, (double)OriginalChildrenBounds[i].MinXYZ.Z, 0, child); } } i++; @@ -382,8 +382,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (XAlign == Align.Origin) { // find the origin in world space of the child - var firstOrigin = Vector3.Transform(Vector3.Zero, AnchorObject.WorldMatrix()); - var childOrigin = Vector3.Transform(Vector3.Zero, child.WorldMatrix()); + var firstOrigin = Vector3Ex.Transform(Vector3.Zero, AnchorObject.WorldMatrix()); + var childOrigin = Vector3Ex.Transform(Vector3.Zero, child.WorldMatrix()); child.Translate(new Vector3(-(childOrigin - firstOrigin).X + (Advanced ? XOffset : 0), 0, 0)); } else @@ -398,8 +398,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (YAlign == Align.Origin) { // find the origin in world space of the child - var firstOrigin = Vector3.Transform(Vector3.Zero, AnchorObject.WorldMatrix()); - var childOrigin = Vector3.Transform(Vector3.Zero, child.WorldMatrix()); + var firstOrigin = Vector3Ex.Transform(Vector3.Zero, AnchorObject.WorldMatrix()); + var childOrigin = Vector3Ex.Transform(Vector3.Zero, child.WorldMatrix()); child.Translate(new Vector3(0, -(childOrigin - firstOrigin).Y + (Advanced ? YOffset : 0), 0)); } else @@ -414,8 +414,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (ZAlign == Align.Origin) { // find the origin in world space of the child - var firstOrigin = Vector3.Transform(Vector3.Zero, AnchorObject.WorldMatrix()); - var childOrigin = Vector3.Transform(Vector3.Zero, child.WorldMatrix()); + var firstOrigin = Vector3Ex.Transform(Vector3.Zero, AnchorObject.WorldMatrix()); + var childOrigin = Vector3Ex.Transform(Vector3.Zero, child.WorldMatrix()); child.Translate(new Vector3(0, 0, -(childOrigin - firstOrigin).Z + (Advanced ? ZOffset : 0))); } else @@ -425,7 +425,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } i++; } - }); + })); } Invalidate(new InvalidateArgs(this, InvalidateType.Matrix, null)); @@ -442,7 +442,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations foreach (var child in Children) { // Where you are minus where you started to get back to where you started - child.Translate(-(child.GetAxisAlignedBoundingBox().minXYZ - OriginalChildrenBounds[i].minXYZ)); + child.Translate(-(child.GetAxisAlignedBoundingBox().MinXYZ - OriginalChildrenBounds[i].MinXYZ)); i++; } } @@ -491,7 +491,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations switch (align) { case Align.Min: - translate[axis] = alignTo - aabb.minXYZ[axis] + offset; + translate[axis] = alignTo - aabb.MinXYZ[axis] + offset; break; case Align.Center: @@ -499,7 +499,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations break; case Align.Max: - translate[axis] = alignTo - aabb.maxXYZ[axis] + offset; + translate[axis] = alignTo - aabb.MaxXYZ[axis] + offset; break; } @@ -511,13 +511,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations switch (alignTo) { case Align.Min: - return currentChildrenBounds[AnchorObjectIndex].minXYZ[axis]; + return currentChildrenBounds[AnchorObjectIndex].MinXYZ[axis]; case Align.Center: return currentChildrenBounds[AnchorObjectIndex].Center[axis]; case Align.Max: - return currentChildrenBounds[AnchorObjectIndex].maxXYZ[axis]; + return currentChildrenBounds[AnchorObjectIndex].MaxXYZ[axis]; default: throw new NotImplementedException(); diff --git a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs index 8f62976a7..e73ec4f28 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs @@ -102,7 +102,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } var next = lastChild.Clone(); - offset = Vector3.Transform(offset, Matrix4X4.CreateRotationZ(rotateRadians)); + offset = Vector3Ex.Transform(offset, Matrix4X4.CreateRotationZ(rotateRadians)); next.Matrix *= Matrix4X4.CreateTranslation(offset); if (RotatePart) diff --git a/MatterControlLib/DesignTools/Operations/CurveObject3D.cs b/MatterControlLib/DesignTools/Operations/CurveObject3D.cs index dabc20270..7374a3266 100644 --- a/MatterControlLib/DesignTools/Operations/CurveObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/CurveObject3D.cs @@ -50,56 +50,57 @@ namespace MatterHackers.MatterControl.DesignTools { public static class Teselate { - public static void SplitEdges(Vector3List vL, FaceList fL, double maxLength) + public static void SplitEdges(List vL, FaceList fL, double maxLength) { - var maxLengthSqrd = maxLength * maxLength; - var facesToRemove = new HashSet(); - // check every face - for (int faceIndex = 0; faceIndex < fL.Count; faceIndex++) - { - var face = fL[faceIndex]; - // check the edge of every face - for (int i = 0; i < 3; i++) - { - var endIndex = face[((i + 1) % 3)]; - var startIndex = face[i]; - var start = vL[startIndex]; - var end = vL[endIndex]; - var lengthSqrd = (end.X - start.X) * (end.X - start.X); - //var lengthSqrd = (end - start).LengthSquared; - // if the edge is > maxXLength - if (lengthSqrd > maxLengthSqrd) - { - int lastIndex = face[((i + 2) % 3)]; - // add a new vertex at the split - var newPosition = (start + end) / 2; - var newIndex = vL.Count; - vL.Add(newPosition); - // add two new faces - // start, new, last - fL.Add(new int[] { startIndex, newIndex, lastIndex }); - // new, end, last - fL.Add(new int[] { newIndex, endIndex, lastIndex }); - // mark this face for removal - facesToRemove.Add(faceIndex); - // go on to next face - break; - } - } - } + throw new NotImplementedException(); + //var maxLengthSqrd = maxLength * maxLength; + //var facesToRemove = new HashSet(); + //// check every face + //for (int faceIndex = 0; faceIndex < fL.Count; faceIndex++) + //{ + // var face = fL[faceIndex]; + // // check the edge of every face + // for (int i = 0; i < 3; i++) + // { + // var endIndex = face[((i + 1) % 3)]; + // var startIndex = face[i]; + // var start = vL[startIndex]; + // var end = vL[endIndex]; + // var lengthSqrd = (end.X - start.X) * (end.X - start.X); + // //var lengthSqrd = (end - start).LengthSquared; + // // if the edge is > maxXLength + // if (lengthSqrd > maxLengthSqrd) + // { + // int lastIndex = face[((i + 2) % 3)]; + // // add a new vertex at the split + // var newPosition = (start + end) / 2; + // var newIndex = vL.Count; + // vL.Add(newPosition); + // // add two new faces + // // start, new, last + // fL.Add(new int[] { startIndex, newIndex, lastIndex }); + // // new, end, last + // fL.Add(new int[] { newIndex, endIndex, lastIndex }); + // // mark this face for removal + // facesToRemove.Add(faceIndex); + // // go on to next face + // break; + // } + // } + //} - // remove all the faces that are marked for removal (make a new list with only keep) - var fLN = new FaceList(); - for (int i = 0; i < fL.Count; i++) - { - if (!facesToRemove.Contains(i)) - { - fLN.Add(fL[i]); - } - } + //// remove all the faces that are marked for removal (make a new list with only keep) + //var fLN = new FaceList(); + //for (int i = 0; i < fL.Count; i++) + //{ + // if (!facesToRemove.Contains(i)) + // { + // fLN.Add(fL[i]); + // } + //} - fL.Clear(); - fL.AddRange(fLN); + //fL.Clear(); + //fL.AddRange(fLN); } } @@ -160,16 +161,16 @@ namespace MatterHackers.MatterControl.DesignTools { var radius = Diameter / 2; var circumference = MathHelper.Tau * radius; - rotationCenter = new Vector2(aabb.minXYZ.X + (aabb.maxXYZ.X - aabb.minXYZ.X) * (StartPercent / 100), aabb.maxXYZ.Y + radius); + rotationCenter = new Vector2(aabb.MinXYZ.X + (aabb.MaxXYZ.X - aabb.MinXYZ.X) * (StartPercent / 100), aabb.MaxXYZ.Y + radius); foreach (var object3Ds in meshWrapperEnumerator) { var matrix = object3Ds.original.WorldMatrix(this); if (!BendCcw) { // rotate around so it will bend correctly - matrix *= Matrix4X4.CreateTranslation(0, -aabb.maxXYZ.Y, 0); + matrix *= Matrix4X4.CreateTranslation(0, -aabb.MaxXYZ.Y, 0); matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 2); - matrix *= Matrix4X4.CreateTranslation(0, aabb.maxXYZ.Y - aabb.YSize, 0); + matrix *= Matrix4X4.CreateTranslation(0, aabb.MaxXYZ.Y - aabb.YSize, 0); } var matrixInv = matrix.Inverted; @@ -187,10 +188,11 @@ namespace MatterHackers.MatterControl.DesignTools // convert the mesh into vertex and face arrays double[] v; int[] f; - curvedMesh.ToVerticesAndFaces(out v, out f); + v = curvedMesh.Vertices.ToDoubleArray(object3Ds.meshCopy.Matrix); + f = curvedMesh.Faces.ToIntArray(); // make lists so we can add to them - var vL = new Vector3List(v); + var vL = v.ToVector3List(); vL.Transform(matrix); var fL = new FaceList(f); @@ -204,15 +206,16 @@ namespace MatterHackers.MatterControl.DesignTools for (int i = 0; i < curvedMesh.Vertices.Count; i++) { - var worldPosition = Vector3.Transform(curvedMesh.Vertices[i].Position, (Matrix4X4)matrix); + throw new NotImplementedException(); + //var worldPosition = Vector3Ex.Transform(curvedMesh.Vertices[i].Position, (Matrix4X4)matrix); - var angleToRotate = ((worldPosition.X - rotationCenter.X) / circumference) * MathHelper.Tau - MathHelper.Tau / 4; - var distanceFromCenter = rotationCenter.Y - worldPosition.Y; + //var angleToRotate = ((worldPosition.X - rotationCenter.X) / circumference) * MathHelper.Tau - MathHelper.Tau / 4; + //var distanceFromCenter = rotationCenter.Y - worldPosition.Y; - var rotatePosition = new Vector3(Math.Cos(angleToRotate), Math.Sin(angleToRotate), 0) * distanceFromCenter; - rotatePosition.Z = worldPosition.Z; - var worldWithBend = rotatePosition + new Vector3(rotationCenter.X, radius + aabb.maxXYZ.Y, 0); - curvedMesh.Vertices[i].Position = Vector3.Transform(worldWithBend, matrixInv); + //var rotatePosition = new Vector3(Math.Cos(angleToRotate), Math.Sin(angleToRotate), 0) * distanceFromCenter; + //rotatePosition.Z = worldPosition.Z; + //var worldWithBend = rotatePosition + new Vector3(rotationCenter.X, radius + aabb.maxXYZ.Y, 0); + //curvedMesh.Vertices[i].Position = Vector3Ex.Transform(worldWithBend, matrixInv); } // the vertices need to be resorted as they have moved relative to each other @@ -225,7 +228,7 @@ namespace MatterHackers.MatterControl.DesignTools if (!BendCcw) { // fix the stored center so we draw correctly - rotationCenter = new Vector2(rotationCenter.X, aabb.minXYZ.Y - radius); + rotationCenter = new Vector2(rotationCenter.X, aabb.MinXYZ.Y - radius); } } diff --git a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs index 98aa564d2..fcb9e3fb9 100644 --- a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs @@ -103,8 +103,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations var minXyz = center - new Vector3(SizeX / 2, SizeY / 2, SizeZ / 2); var maxXyz = center + new Vector3(SizeX / 2, SizeY / 2, SizeZ / 2); var bounds = new AxisAlignedBoundingBox(minXyz, maxXyz); - //var leftW = Vector3.Transform(, worldMatrix); - var right = Vector3.Transform(center + new Vector3(SizeX / 2, 0, 0), worldMatrix); + //var leftW = Vector3Ex.Transform(, worldMatrix); + var right = Vector3Ex.Transform(center + new Vector3(SizeX / 2, 0, 0), worldMatrix); // layer.World.Render3DLine(left, right, Agg.Color.Red); layer.World.RenderAabb(bounds, worldMatrix, Agg.Color.Red, 1, 1); } @@ -181,7 +181,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs index 4682535fe..ec0d94046 100644 --- a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs @@ -217,13 +217,13 @@ namespace MatterHackers.MatterControl.DesignTools } else if (vertex.IsLineTo) { - GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.maxXYZ.Z + 0.002); - GL.Vertex3(position.X, position.Y, aabb.maxXYZ.Z + 0.002); + GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.MaxXYZ.Z + 0.002); + GL.Vertex3(position.X, position.Y, aabb.MaxXYZ.Z + 0.002); } else if (vertex.IsClose) { - GL.Vertex3(firstMove.X, firstMove.Y, aabb.maxXYZ.Z + 0.002); - GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.maxXYZ.Z + 0.002); + GL.Vertex3(firstMove.X, firstMove.Y, aabb.MaxXYZ.Z + 0.002); + GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.MaxXYZ.Z + 0.002); } lastPosition = position; diff --git a/MatterControlLib/DesignTools/Operations/MirrorObject3D.cs b/MatterControlLib/DesignTools/Operations/MirrorObject3D.cs index 59580753d..9eaa1edc0 100644 --- a/MatterControlLib/DesignTools/Operations/MirrorObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/MirrorObject3D.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 System; using System.ComponentModel; using System.Linq; using System.Threading; @@ -86,7 +87,8 @@ namespace MatterHackers.MatterControl.DesignTools // move it to us then mirror then move it back item.meshCopy.Mesh.Transform(meshCopyToThis * mirrorMatrix * meshCopyToThis.Inverted); - item.meshCopy.Mesh.ReverseFaceEdges(); + throw new NotImplementedException(); + //item.meshCopy.Mesh.ReverseFaceEdges(); item.meshCopy.Mesh.CalculateNormals(); item.meshCopy.Mesh.MarkAsChanged(); } diff --git a/MatterControlLib/DesignTools/Operations/PinchObject3D.cs b/MatterControlLib/DesignTools/Operations/PinchObject3D.cs index a81664503..2a80db860 100644 --- a/MatterControlLib/DesignTools/Operations/PinchObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/PinchObject3D.cs @@ -32,6 +32,7 @@ using MatterHackers.DataConverters3D; using MatterHackers.Localizations; using MatterHackers.MatterControl.PartPreviewWindow.View3D; using MatterHackers.VectorMath; +using System; using System.ComponentModel; using System.Threading; @@ -91,21 +92,22 @@ namespace MatterHackers.MatterControl.DesignTools for (int i = 0; i < originalMesh.Vertices.Count; i++) { - var pos = originalMesh.Vertices[i].Position; - pos = Vector3.Transform(pos, itemMatrix); + throw new NotImplementedException(); + //var pos = originalMesh.Vertices[i].Position; + //pos = Vector3Ex.Transform(pos, itemMatrix); - var ratioToApply = PinchRatio; + //var ratioToApply = PinchRatio; - var distFromCenter = pos.X - aabb.Center.X; - var distanceToPinch = distFromCenter * (1 - PinchRatio); - var delta = (aabb.Center.X + distFromCenter * ratioToApply) - pos.X; + //var distFromCenter = pos.X - aabb.Center.X; + //var distanceToPinch = distFromCenter * (1 - PinchRatio); + //var delta = (aabb.Center.X + distFromCenter * ratioToApply) - pos.X; - // find out how much to pinch based on y position - var amountOfRatio = (pos.Y - aabb.minXYZ.Y) / aabb.YSize; + //// find out how much to pinch based on y position + //var amountOfRatio = (pos.Y - aabb.minXYZ.Y) / aabb.YSize; - var newPos = new Vector3(pos.X + delta * amountOfRatio, pos.Y, pos.Z); + //var newPos = new Vector3(pos.X + delta * amountOfRatio, pos.Y, pos.Z); - transformedMesh.Vertices[i].Position = Vector3.Transform(newPos, invItemMatrix); + //transformedMesh.Vertices[i].Position = Vector3Ex.Transform(newPos, invItemMatrix); } // the vertices need to be resorted as they have moved relative to each other diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs index a7766e085..4e92d8027 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs @@ -65,7 +65,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations base.WrapItem(item, undoBuffer); var aabb = item.GetAxisAlignedBoundingBox(); - var newCenter = new Vector3(aabb.Center.X, aabb.Center.Y, aabb.minXYZ.Z); + var newCenter = new Vector3(aabb.Center.X, aabb.Center.Y, aabb.MinXYZ.Z); item.Translate(-newCenter); this.Translate(newCenter); } diff --git a/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs b/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs index d088a5214..da2beedb4 100644 --- a/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs @@ -81,7 +81,7 @@ namespace MatterHackers.MatterControl.DesignTools if (startingAabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, startingAabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, startingAabb.MinXYZ.Z); } } @@ -158,12 +158,12 @@ namespace MatterHackers.MatterControl.DesignTools // Convert VertexSource into expected Polygons Polygons polygonShape = (vertexSource == null) ? null : vertexSource.CreatePolygons(); - GenerateBase(polygonShape, firstChild.GetAxisAlignedBoundingBox().minXYZ.Z); + GenerateBase(polygonShape, firstChild.GetAxisAlignedBoundingBox().MinXYZ.Z); if (startingAabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, startingAabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, startingAabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs b/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs index 0d161bd73..2a2ba7130 100644 --- a/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs @@ -92,7 +92,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs index 8970eff75..f3b6b854d 100644 --- a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs @@ -101,7 +101,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs index ce5d7da3a..e7825f5ee 100644 --- a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs @@ -169,7 +169,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs index 3a1067d46..6ce89d3cf 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs @@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs index 99b1d71a8..7a80ed054 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs @@ -106,7 +106,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs index f867ad3ad..53249a622 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs @@ -89,7 +89,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs b/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs index d24eda6f1..7c39b899b 100644 --- a/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs @@ -157,7 +157,7 @@ namespace MatterHackers.MatterControl.DesignTools { if (!string.IsNullOrWhiteSpace(this.AssetPath) // TODO: Remove this hack needed to work around Persistable = false - && (base.Mesh == null || base.Mesh.FaceTexture.Count <= 0)) + && (base.Mesh == null || base.Mesh.FaceTextures.Count <= 0)) { using (this.RebuildLock()) { @@ -186,7 +186,7 @@ namespace MatterHackers.MatterControl.DesignTools double height = ScaleMmPerPixels * imageBuffer.Height; Mesh textureMesh = PlatonicSolids.CreateCube(width, height, 0.2); - MeshHelper.PlaceTextureOnFace(textureMesh.Faces[0], imageBuffer); + textureMesh.PlaceTextureOnFace(0, imageBuffer); return textureMesh; } diff --git a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs index f2f4ddafe..af95b119a 100644 --- a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs @@ -89,7 +89,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/RingObject3D.cs b/MatterControlLib/DesignTools/Primitives/RingObject3D.cs index 37f7fb5ee..027aac253 100644 --- a/MatterControlLib/DesignTools/Primitives/RingObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/RingObject3D.cs @@ -124,7 +124,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs b/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs index 7c020f0e0..17cb26f93 100644 --- a/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs @@ -126,7 +126,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs index 7be124365..e082119f3 100644 --- a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs @@ -110,14 +110,14 @@ namespace MatterHackers.MatterControl.DesignTools public override Task Rebuild() { - return Task.Run(() => + return Task.Run((System.Action)(() => { - this.DebugDepth("Rebuild"); + (this).DebugDepth("Rebuild"); using (RebuildLock()) { - var aabb = this.GetAxisAlignedBoundingBox(); + var aabb = (this).GetAxisAlignedBoundingBox(); - this.Children.Modify((list) => + this.Children.Modify((List list) => { list.Clear(); @@ -145,10 +145,10 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, (double)aabb.MinXYZ.Z); } } - }); + })); } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs b/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs index e1b2d3e79..ae73424e5 100644 --- a/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs @@ -124,7 +124,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs index 639a7c024..40608135c 100644 --- a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs @@ -89,7 +89,7 @@ namespace MatterHackers.MatterControl.DesignTools if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. - PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); + PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z); } } diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index 27b0774c2..5fb868746 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -204,7 +204,7 @@ namespace MatterHackers.MatterControl.Library.Export // Move to bed center var bedCenter = printer.Bed.BedCenter; - loadedItem.Matrix *= Matrix4X4.CreateTranslation((double)-aabb.Center.X, (double)-aabb.Center.Y, (double)-aabb.minXYZ.Z) * Matrix4X4.CreateTranslation(bedCenter.X, bedCenter.Y, 0); + loadedItem.Matrix *= Matrix4X4.CreateTranslation((double)-aabb.Center.X, (double)-aabb.Center.Y, (double)-aabb.MinXYZ.Z) * Matrix4X4.CreateTranslation(bedCenter.X, bedCenter.Y, 0); } string originalSpiralVase = printer.Settings.GetValue(SettingsKey.spiral_vase); diff --git a/MatterControlLib/Library/Widgets/InsertionGroupObject3D.cs b/MatterControlLib/Library/Widgets/InsertionGroupObject3D.cs index e697dae4d..e19275aac 100644 --- a/MatterControlLib/Library/Widgets/InsertionGroupObject3D.cs +++ b/MatterControlLib/Library/Widgets/InsertionGroupObject3D.cs @@ -113,7 +113,7 @@ namespace MatterHackers.MatterControl.Library placeholderItem.Visible = false; // Copy scale/rotation/translation from the source and Center - loadedItem.Matrix = loadedItem.Matrix * Matrix4X4.CreateTranslation((double)-aabb.Center.X, (double)-aabb.Center.Y, (double)-aabb.minXYZ.Z) * placeholderItem.Matrix; + loadedItem.Matrix = loadedItem.Matrix * Matrix4X4.CreateTranslation((double)-aabb.Center.X, (double)-aabb.Center.Y, (double)-aabb.MinXYZ.Z) * placeholderItem.Matrix; // check if the item has 0 height (it is probably an image) if(loadedItem.ZSize() == 0) diff --git a/MatterControlLib/PartPreviewWindow/CreateDiscreteMeshes.cs b/MatterControlLib/PartPreviewWindow/CreateDiscreteMeshes.cs index 300c6c857..7c4970ff5 100644 --- a/MatterControlLib/PartPreviewWindow/CreateDiscreteMeshes.cs +++ b/MatterControlLib/PartPreviewWindow/CreateDiscreteMeshes.cs @@ -52,74 +52,75 @@ namespace MatterHackers.MatterControl { public static List SplitVolumesIntoMeshes(Mesh meshToSplit, CancellationToken cancellationToken, Action reportProgress) { - Stopwatch maxProgressReport = Stopwatch.StartNew(); - List discreetVolumes = new List(); - HashSet facesThatHaveBeenAdded = new HashSet(); - Mesh meshFromCurrentVolume = null; - Stack attachedFaces = new Stack(); - int faceCount = meshToSplit.Faces.Count; - for (int faceIndex = 0; faceIndex < faceCount; faceIndex++) - { - if (reportProgress != null) - { - if (maxProgressReport.ElapsedMilliseconds > 200) - { - reportProgress(faceIndex / (double)faceCount, "Merging Mesh Edges"); - maxProgressReport.Restart(); - if (cancellationToken.IsCancellationRequested) - { - return null; - } - } - } + throw new NotImplementedException(); + //Stopwatch maxProgressReport = Stopwatch.StartNew(); + //List discreetVolumes = new List(); + //HashSet facesThatHaveBeenAdded = new HashSet(); + //Mesh meshFromCurrentVolume = null; + //Stack attachedFaces = new Stack(); + //int faceCount = meshToSplit.Faces.Count; + //for (int faceIndex = 0; faceIndex < faceCount; faceIndex++) + //{ + // if (reportProgress != null) + // { + // if (maxProgressReport.ElapsedMilliseconds > 200) + // { + // reportProgress(faceIndex / (double)faceCount, "Merging Mesh Edges"); + // maxProgressReport.Restart(); + // if (cancellationToken.IsCancellationRequested) + // { + // return null; + // } + // } + // } - Face currentFace = meshToSplit.Faces[faceIndex]; - // If this face as not been added to any volume, create a new volume and add all of the attached faces. - if (!facesThatHaveBeenAdded.Contains(currentFace)) - { - attachedFaces.Push(currentFace); - meshFromCurrentVolume = new Mesh(); + // Face currentFace = meshToSplit.Faces[faceIndex]; + // // If this face as not been added to any volume, create a new volume and add all of the attached faces. + // if (!facesThatHaveBeenAdded.Contains(currentFace)) + // { + // attachedFaces.Push(currentFace); + // meshFromCurrentVolume = new Mesh(); - while (attachedFaces.Count > 0) - { - Face faceToAdd = attachedFaces.Pop(); - foreach (IVertex attachedVertex in faceToAdd.Vertices()) - { - foreach (Face faceAttachedToVertex in attachedVertex.ConnectedFaces()) - { - if (!facesThatHaveBeenAdded.Contains(faceAttachedToVertex)) - { - // mark that this face has been taken care of - facesThatHaveBeenAdded.Add(faceAttachedToVertex); - // add it to the list of faces we need to walk - attachedFaces.Push(faceAttachedToVertex); + // while (attachedFaces.Count > 0) + // { + // Face faceToAdd = attachedFaces.Pop(); + // foreach (IVertex attachedVertex in faceToAdd.Vertices()) + // { + // foreach (Face faceAttachedToVertex in attachedVertex.ConnectedFaces()) + // { + // if (!facesThatHaveBeenAdded.Contains(faceAttachedToVertex)) + // { + // // mark that this face has been taken care of + // facesThatHaveBeenAdded.Add(faceAttachedToVertex); + // // add it to the list of faces we need to walk + // attachedFaces.Push(faceAttachedToVertex); - // Add a new face to the new mesh we are creating. - var faceVertices = new List(); - foreach (FaceEdge faceEdgeToAdd in faceAttachedToVertex.FaceEdges()) - { - var newVertex = meshFromCurrentVolume.CreateVertex(faceEdgeToAdd.FirstVertex.Position, CreateOption.CreateNew, SortOption.WillSortLater); - faceVertices.Add(newVertex); - } + // // Add a new face to the new mesh we are creating. + // var faceVertices = new List(); + // foreach (FaceEdge faceEdgeToAdd in faceAttachedToVertex.FaceEdges()) + // { + // var newVertex = meshFromCurrentVolume.CreateVertex(faceEdgeToAdd.FirstVertex.Position, CreateOption.CreateNew, SortOption.WillSortLater); + // faceVertices.Add(newVertex); + // } - meshFromCurrentVolume.CreateFace(faceVertices.ToArray(), CreateOption.CreateNew); - } - } - } - } + // meshFromCurrentVolume.CreateFace(faceVertices.ToArray(), CreateOption.CreateNew); + // } + // } + // } + // } - discreetVolumes.Add(meshFromCurrentVolume); - meshFromCurrentVolume = null; - } + // discreetVolumes.Add(meshFromCurrentVolume); + // meshFromCurrentVolume = null; + // } - if (reportProgress != null) - { - double progress = faceIndex / (double)meshToSplit.Faces.Count; - reportProgress(progress, "Split Into Meshes"); - } - } + // if (reportProgress != null) + // { + // double progress = faceIndex / (double)meshToSplit.Faces.Count; + // reportProgress(progress, "Split Into Meshes"); + // } + //} - return discreetVolumes; + //return discreetVolumes; } public static bool PointInPolygon(Polygon polygon, IntPoint testPosition) diff --git a/MatterControlLib/PartPreviewWindow/GenerateSupportPanel.cs b/MatterControlLib/PartPreviewWindow/GenerateSupportPanel.cs index 5c2edd894..3bc8cd6a9 100644 --- a/MatterControlLib/PartPreviewWindow/GenerateSupportPanel.cs +++ b/MatterControlLib/PartPreviewWindow/GenerateSupportPanel.cs @@ -147,7 +147,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private void Rebuild() { - Task.Run(() => + Task.Run((Action)(() => { // Get visible meshes for each of them var visibleMeshes = scene.Children.SelectMany(i => i.VisibleMeshes()); @@ -161,39 +161,40 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var supportCandidates = visibleMeshes.Where(i => i.OutputType != PrintOutputTypes.Support); // find all the faces that are candidates for support - var upVerts = new Vector3List(); + var upVerts = new List(); var upFaces = new FaceList(); - var downVerts = new Vector3List(); + var downVerts = new List(); var downFaces = new FaceList(); foreach (var item in supportCandidates) { var matrix = item.WorldMatrix(scene); foreach (var face in item.Mesh.Faces) { - var face0Normal = Vector3.TransformVector(face.Normal, matrix).GetNormal(); - var angle = MathHelper.RadiansToDegrees(Math.Acos(Vector3.Dot(-Vector3.UnitZ, face0Normal))); + throw new NotImplementedException(); + //var face0Normal = Vector3Ex.TransformVector(face.Normal, matrix).GetNormal(); + //var angle = MathHelper.RadiansToDegrees(Math.Acos(Vector3Ex.Dot(-Vector3.UnitZ, face0Normal))); - if (angle < MaxOverHangAngle) - { - foreach (var triangle in face.AsTriangles()) - { - 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 < MaxOverHangAngle) + //{ + // foreach (var triangle in face.AsTriangles()) + // { + // downFaces.Add(new int[] { downVerts.Count, downVerts.Count + 1, downVerts.Count + 2 }); + // downVerts.Add(Vector3Ex.Transform(triangle.p0, matrix)); + // downVerts.Add(Vector3Ex.Transform(triangle.p1, matrix)); + // downVerts.Add(Vector3Ex.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 (angle > 0) + //{ + // foreach (var triangle in face.AsTriangles()) + // { + // upFaces.Add(new int[] { upVerts.Count, upVerts.Count + 1, upVerts.Count + 2 }); + // upVerts.Add(Vector3Ex.Transform(triangle.p0, matrix)); + // upVerts.Add(Vector3Ex.Transform(triangle.p1, matrix)); + // upVerts.Add(Vector3Ex.Transform(triangle.p2, matrix)); + // } + //} } } @@ -206,10 +207,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow 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 gridBounds = new RectangleDouble(Math.Floor((double)(bounds.MinXYZ.X / PillarSize)), + Math.Floor((double)(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)); @@ -252,7 +253,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // trace down from the top to the first bottom hit (or bed) // add a support column var first = downFaces.First(); - var position = downVerts[first[0]]; + var position = downVerts[first.v0]; //AddSupportColumn(position.X, position.Y, position.Z, 0); } @@ -262,7 +263,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // make a new patch group at the z of the hit (these will be the bottoms) // find the outline of the patch groups (these will be the walls of the top and bottom patches // make a new mesh object with the top, bottom and walls, add it to the scene and mark it as support - }); + })); } private void RemoveExisting() @@ -280,55 +281,56 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public static bool RequiresSupport(InteractiveScene scene) { - bool supportInScene = scene.VisibleMeshes().Any(i => i.WorldOutputType() == PrintOutputTypes.Support); - if (!supportInScene) - { - // there is no support in the scene check if there are faces that require support - var supportCandidates = scene.VisibleMeshes().Where(i => i.OutputType != PrintOutputTypes.Support); + throw new NotImplementedException(); + //bool supportInScene = scene.VisibleMeshes().Any(i => i.WorldOutputType() == PrintOutputTypes.Support); + //if (!supportInScene) + //{ + // // there is no support in the scene check if there are faces that require support + // var supportCandidates = scene.VisibleMeshes().Where(i => i.OutputType != PrintOutputTypes.Support); - // find all the faces that are candidates for support - foreach (var item in supportCandidates) - { - var matrix = item.WorldMatrix(scene); - foreach (var face in item.Mesh.Faces) - { - bool aboveBed = false; - foreach(var vertex in face.Vertices()) - { - if(Vector3.Transform(vertex.Position, matrix).Z > .01) - { - aboveBed = true; - break; - } - } - if (aboveBed) - { - var face0Normal = Vector3.TransformVector(face.Normal, matrix).GetNormal(); - var angle = MathHelper.RadiansToDegrees(Math.Acos(Vector3.Dot(-Vector3.UnitZ, face0Normal))); + // // find all the faces that are candidates for support + // foreach (var item in supportCandidates) + // { + // var matrix = item.WorldMatrix(scene); + // foreach (var face in item.Mesh.Faces) + // { + // bool aboveBed = false; + // foreach(var vertex in face.Vertices()) + // { + // if(Vector3Ex.Transform(vertex.Position, matrix).Z > .01) + // { + // aboveBed = true; + // break; + // } + // } + // if (aboveBed) + // { + // var face0Normal = Vector3Ex.TransformVector(face.Normal, matrix).GetNormal(); + // var angle = MathHelper.RadiansToDegrees(Math.Acos(Vector3Ex.Dot(-Vector3.UnitZ, face0Normal))); - if (angle < MaxOverHangAngle) - { - // TODO: consider how much area all supported polygons represent - return true; - } - } - } - } - } + // if (angle < MaxOverHangAngle) + // { + // // TODO: consider how much area all supported polygons represent + // return true; + // } + // } + // } + // } + //} - return false; + //return false; } } public static class FaceListExtensions { - public static IPrimitive CreateTraceData(this FaceList faceList, Vector3List vertexList, int maxRecursion = int.MaxValue) + public static IPrimitive CreateTraceData(this FaceList faceList, List vertexList, int maxRecursion = int.MaxValue) { var allPolys = new List(); foreach (var face in faceList) { - allPolys.Add(new TriangleShape(vertexList[face[0]], vertexList[face[1]], vertexList[face[2]], null)); + allPolys.Add(new TriangleShape(vertexList[face.v0], vertexList[face.v1], vertexList[face.v2], null)); } return BoundingVolumeHierarchy.CreateNewHierachy(allPolys, maxRecursion); diff --git a/MatterControlLib/PartPreviewWindow/PlatingHelper.cs b/MatterControlLib/PartPreviewWindow/PlatingHelper.cs index d486df78e..bccbb9371 100644 --- a/MatterControlLib/PartPreviewWindow/PlatingHelper.cs +++ b/MatterControlLib/PartPreviewWindow/PlatingHelper.cs @@ -88,7 +88,7 @@ namespace MatterHackers.MatterControl for (int meshGroupIndex = 0; meshGroupIndex < object3DList.Count; meshGroupIndex++) { var object3D = object3DList[meshGroupIndex]; - Vector3 meshLowerLeft = object3D.GetAxisAlignedBoundingBox(Matrix4X4.Identity).minXYZ; + Vector3 meshLowerLeft = object3D.GetAxisAlignedBoundingBox(Matrix4X4.Identity).MinXYZ; object3D.Matrix *= Matrix4X4.CreateTranslation(-meshLowerLeft); PlatingHelper.MoveToOpenPositionRelativeGroup(object3D, scene.Children); @@ -107,7 +107,7 @@ namespace MatterHackers.MatterControl bounds = AxisAlignedBoundingBox.Union(bounds, object3DList[i].GetAxisAlignedBoundingBox(Matrix4X4.Identity)); } - Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2; + Vector3 boundsCenter = (bounds.MaxXYZ + bounds.MinXYZ) / 2; for (int i = 0; i < object3DList.Count; i++) { object3DList[i].Matrix *= Matrix4X4.CreateTranslation(-boundsCenter + new Vector3(0, 0, bounds.ZSize / 2) + bedCenter); @@ -125,7 +125,7 @@ namespace MatterHackers.MatterControl public static void PlaceOnBed(IObject3D object3D) { AxisAlignedBoundingBox bounds = object3D.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2; + Vector3 boundsCenter = (bounds.MaxXYZ + bounds.MinXYZ) / 2; object3D.Matrix *= Matrix4X4.CreateTranslation(new Vector3(0, 0, -boundsCenter.Z + bounds.ZSize / 2)); } @@ -134,9 +134,9 @@ namespace MatterHackers.MatterControl { AxisAlignedBoundingBox bounds = objectToMove.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - if (bounds.minXYZ.Z != zHeight) + if (bounds.MinXYZ.Z != zHeight) { - objectToMove.Matrix *= Matrix4X4.CreateTranslation(new Vector3(0, 0, zHeight - bounds.minXYZ.Z)); + objectToMove.Matrix *= Matrix4X4.CreateTranslation(new Vector3(0, 0, zHeight - bounds.MinXYZ.Z)); } } @@ -156,12 +156,12 @@ namespace MatterHackers.MatterControl AxisAlignedBoundingBox allPlacedMeshBounds = itemsToAvoid.GetUnionedAxisAlignedBoundingBox(); // move the part to the total bounds lower left side - Vector3 meshLowerLeft = objectToAdd.GetAxisAlignedBoundingBox(Matrix4X4.Identity).minXYZ; - objectToAdd.Matrix *= Matrix4X4.CreateTranslation(-meshLowerLeft + allPlacedMeshBounds.minXYZ); + Vector3 meshLowerLeft = objectToAdd.GetAxisAlignedBoundingBox(Matrix4X4.Identity).MinXYZ; + objectToAdd.Matrix *= Matrix4X4.CreateTranslation(-meshLowerLeft + allPlacedMeshBounds.MinXYZ); // make sure it is on the 0 plane var aabb = objectToAdd.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - objectToAdd.Matrix *= Matrix4X4.CreateTranslation(0, 0, -aabb.minXYZ.Z); + objectToAdd.Matrix *= Matrix4X4.CreateTranslation(0, 0, -aabb.MinXYZ.Z); // keep moving the item until its in an open slot MoveToOpenPosition(objectToAdd, itemsToAvoid); @@ -178,8 +178,8 @@ namespace MatterHackers.MatterControl AxisAlignedBoundingBox itemToMoveBounds = itemToMove.GetAxisAlignedBoundingBox(Matrix4X4.Identity); // add in a few mm so that it will not be touching - itemToMoveBounds.minXYZ -= new Vector3(2, 2, 0); - itemToMoveBounds.maxXYZ += new Vector3(2, 2, 0); + itemToMoveBounds.MinXYZ -= new Vector3(2, 2, 0); + itemToMoveBounds.MaxXYZ += new Vector3(2, 2, 0); Matrix4X4 transform = Matrix4X4.Identity; int currentSize = 1; @@ -234,7 +234,7 @@ namespace MatterHackers.MatterControl double yStepAmount = 5; Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(xStep * xStepAmount, yStep * yStepAmount, 0); - Vector3 newPosition = Vector3.Transform(Vector3.Zero, positionTransform); + Vector3 newPosition = Vector3Ex.Transform(Vector3.Zero, positionTransform); transform = Matrix4X4.CreateTranslation(newPosition); diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/BooleanProcessing.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/BooleanProcessing.cs index 3fa0587ae..ebeed6d87 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/BooleanProcessing.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/BooleanProcessing.cs @@ -60,10 +60,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D { double[] va; int[] fa; - inMeshA.ToVerticesAndFaces(matrixA, out va, out fa); + va = inMeshA.Vertices.ToDoubleArray(matrixA); + fa = inMeshA.Faces.ToIntArray(); double[] vb; int[] fb; - inMeshB.ToVerticesAndFaces(matrixB, out vb, out fb); + vb = inMeshB.Vertices.ToDoubleArray(matrixB); + fb = inMeshB.Faces.ToIntArray(); int vcCount; int fcCount; diff --git a/MatterControlLib/PartPreviewWindow/View3D/BedMeshGenerator.cs b/MatterControlLib/PartPreviewWindow/View3D/BedMeshGenerator.cs index e8a49da2f..8ce8a5aa4 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/BedMeshGenerator.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/BedMeshGenerator.cs @@ -86,9 +86,9 @@ namespace MatterHackers.MatterControl if (displayVolumeToBuild.Z > 0) { buildVolume = PlatonicSolids.CreateCube(displayVolumeToBuild); - foreach (Vertex vertex in buildVolume.Vertices) + for(int i=0; i< buildVolume.Vertices.Count; i++) { - vertex.Position = vertex.Position + new Vector3(0, 0, displayVolumeToBuild.Z / 2); + buildVolume.Vertices[i] = buildVolume.Vertices[i] + new Vector3Float(0, 0, displayVolumeToBuild.Z / 2); } var bspTree = FaceBspTree.Create(buildVolume); buildVolume.FaceBspTree = bspTree; @@ -96,8 +96,7 @@ namespace MatterHackers.MatterControl printerBed = PlatonicSolids.CreateCube(displayVolumeToBuild.X, displayVolumeToBuild.Y, 1.8); { - Face face = printerBed.Faces[0]; - MeshHelper.PlaceTextureOnFace(face, bedplateImage); + printerBed.PlaceTextureOnFace(0, bedplateImage); } break; @@ -106,27 +105,10 @@ namespace MatterHackers.MatterControl if (displayVolumeToBuild.Z > 0) { buildVolume = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolumeToBuild.X / 2, displayVolumeToBuild.Y / 2), displayVolumeToBuild.Z); - foreach (Vertex vertex in buildVolume.Vertices) - { - vertex.Position = vertex.Position + new Vector3(0, 0, .2); - } } printerBed = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolumeToBuild.X / 2, displayVolumeToBuild.Y / 2), 1.8); - { - foreach (Face face in printerBed.Faces) - { - if (face.Normal.Z > 0) - { - face.SetTexture(0, bedplateImage); - foreach (FaceEdge faceEdge in face.FaceEdges()) - { - faceEdge.SetUv(0, new Vector2((displayVolumeToBuild.X / 2 + faceEdge.FirstVertex.Position.X) / displayVolumeToBuild.X, - (displayVolumeToBuild.Y / 2 + faceEdge.FirstVertex.Position.Y) / displayVolumeToBuild.Y)); - } - } - } - } + printerBed.PlaceTextureOnFace(0, bedplateImage); } break; @@ -134,17 +116,17 @@ namespace MatterHackers.MatterControl throw new NotImplementedException(); } - var zTop = printerBed.GetAxisAlignedBoundingBox().maxXYZ.Z; - foreach (Vertex vertex in printerBed.Vertices) + var zTop = printerBed.GetAxisAlignedBoundingBox().MaxXYZ.Z; + for (int i = 0; i < printerBed.Vertices.Count; i++) { - vertex.Position = vertex.Position - new Vector3(-printer.Bed.BedCenter, zTop + .02); + printerBed.Vertices[i] = printerBed.Vertices[i] - new Vector3Float(-printer.Bed.BedCenter, zTop + .02); } if (buildVolume != null) { - foreach (Vertex vertex in buildVolume.Vertices) + for (int i = 0; i < buildVolume.Vertices.Count; i++) { - vertex.Position = vertex.Position - new Vector3(-printer.Bed.BedCenter, 2.2); + buildVolume.Vertices[i] = buildVolume.Vertices[i] - new Vector3Float(-printer.Bed.BedCenter, zTop + .02); } } diff --git a/MatterControlLib/PartPreviewWindow/View3D/DebugBvh.cs b/MatterControlLib/PartPreviewWindow/View3D/DebugBvh.cs index e7ef0a877..0b84628ec 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/DebugBvh.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/DebugBvh.cs @@ -99,20 +99,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // the sides RenderLine(transform.Peek(), - new Vector3(aabb.minXYZ.X, aabb.minXYZ.Y, aabb.minXYZ.Z), - new Vector3(aabb.minXYZ.X, aabb.minXYZ.Y, aabb.maxXYZ.Z), + new Vector3(aabb.MinXYZ.X, aabb.MinXYZ.Y, aabb.MinXYZ.Z), + new Vector3(aabb.MinXYZ.X, aabb.MinXYZ.Y, aabb.MaxXYZ.Z), color); RenderLine(transform.Peek(), - new Vector3(aabb.maxXYZ.X, aabb.minXYZ.Y, aabb.minXYZ.Z), - new Vector3(aabb.maxXYZ.X, aabb.minXYZ.Y, aabb.maxXYZ.Z), + new Vector3(aabb.MaxXYZ.X, aabb.MinXYZ.Y, aabb.MinXYZ.Z), + new Vector3(aabb.MaxXYZ.X, aabb.MinXYZ.Y, aabb.MaxXYZ.Z), color); RenderLine(transform.Peek(), - new Vector3(aabb.minXYZ.X, aabb.maxXYZ.Y, aabb.minXYZ.Z), - new Vector3(aabb.minXYZ.X, aabb.maxXYZ.Y, aabb.maxXYZ.Z), + new Vector3(aabb.MinXYZ.X, aabb.MaxXYZ.Y, aabb.MinXYZ.Z), + new Vector3(aabb.MinXYZ.X, aabb.MaxXYZ.Y, aabb.MaxXYZ.Z), color); RenderLine(transform.Peek(), - new Vector3(aabb.maxXYZ.X, aabb.maxXYZ.Y, aabb.minXYZ.Z), - new Vector3(aabb.maxXYZ.X, aabb.maxXYZ.Y, aabb.maxXYZ.Z), + new Vector3(aabb.MaxXYZ.X, aabb.MaxXYZ.Y, aabb.MinXYZ.Z), + new Vector3(aabb.MaxXYZ.X, aabb.MaxXYZ.Y, aabb.MaxXYZ.Z), color); } @@ -132,11 +132,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - public void RenderRecursive(MeshFaceTraceable objectToProcess, int level = 0) - { - RenderBounds(objectToProcess.GetAxisAlignedBoundingBox()); - } - public void RenderRecursive(Transform objectToProcess, int level = 0) { RenderBounds(objectToProcess.GetAxisAlignedBoundingBox()); diff --git a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs index 9129a07fb..ed9154c59 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs @@ -120,7 +120,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - var moveAmount = newZPosition - originalSelectedBounds.minXYZ.Z; + var moveAmount = newZPosition - originalSelectedBounds.MinXYZ.Z; if (moveAmount != 0) { @@ -177,9 +177,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public Vector3 GetTopPosition(IObject3D selectedItem) { AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - if (originalSelectedBounds.minXYZ.X != double.PositiveInfinity) + if (originalSelectedBounds.MinXYZ.X != double.PositiveInfinity) { - return new Vector3(originalSelectedBounds.Center.X, originalSelectedBounds.Center.Y, originalSelectedBounds.maxXYZ.Z); + return new Vector3(originalSelectedBounds.Center.X, originalSelectedBounds.Center.Y, originalSelectedBounds.MaxXYZ.Z); } return Vector3.Zero; @@ -197,7 +197,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow zHeightDisplayInfo.Visible = true; - double distanceToHit = Vector3.Dot(mouseEvent3D.info.HitPosition, mouseEvent3D.MouseRay.directionNormal); + double distanceToHit = Vector3Ex.Dot(mouseEvent3D.info.HitPosition, mouseEvent3D.MouseRay.directionNormal); hitPlane = new PlaneShape(mouseEvent3D.MouseRay.directionNormal, distanceToHit, null); initialHitPosition = mouseEvent3D.info.HitPosition; @@ -230,7 +230,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { var delta = info.HitPosition.Z - initialHitPosition.Z; - double newZPosition = mouseDownSelectedBounds.minXYZ.Z + delta; + double newZPosition = mouseDownSelectedBounds.MinXYZ.Z + delta; if (InteractionContext.SnapGridDistance > 0) { @@ -242,7 +242,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - var moveAmount = newZPosition - originalSelectedBounds.minXYZ.Z; + var moveAmount = newZPosition - originalSelectedBounds.MinXYZ.Z; if (moveAmount != 0) { @@ -283,7 +283,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); Vector3 topPosition = GetTopPosition(selectedItem); - Vector3 bottomPosition = new Vector3(topPosition.X, topPosition.Y, selectedBounds.minXYZ.Z); + Vector3 bottomPosition = new Vector3(topPosition.X, topPosition.Y, selectedBounds.MinXYZ.Z); double distBetweenPixelsWorldSpace = InteractionContext.World.GetWorldUnitsPerScreenPixelAtPosition(topPosition); Vector3 boxCenter = topPosition; @@ -326,7 +326,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - zHeightDisplayInfo.Value = selectedBounds.minXYZ.Z; + zHeightDisplayInfo.Value = selectedBounds.MinXYZ.Z; zHeightDisplayInfo.OriginRelativeParent = lines[1] + new Vector2(10, - zHeightDisplayInfo.LocalBounds.Center.Y); } } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/SnapingIndicator.cs b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/SnapingIndicator.cs index c1089abf3..933f72526 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/SnapingIndicator.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/SnapingIndicator.cs @@ -62,7 +62,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { case HitQuadrant.LB: { - Vector3 cornerPoint = new Vector3(selectedBounds.minXYZ.X, selectedBounds.minXYZ.Y, 0); + Vector3 cornerPoint = new Vector3(selectedBounds.MinXYZ.X, selectedBounds.MinXYZ.Y, 0); double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint); lines[0] = world.GetScreenPosition(cornerPoint - new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0)); @@ -75,7 +75,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow case HitQuadrant.LT: { - Vector3 cornerPoint = new Vector3(selectedBounds.minXYZ.X, selectedBounds.maxXYZ.Y, 0); + Vector3 cornerPoint = new Vector3(selectedBounds.MinXYZ.X, selectedBounds.MaxXYZ.Y, 0); double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint); lines[0] = world.GetScreenPosition(cornerPoint - new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0)); @@ -88,7 +88,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow case HitQuadrant.RB: { - Vector3 cornerPoint = new Vector3(selectedBounds.maxXYZ.X, selectedBounds.minXYZ.Y, 0); + Vector3 cornerPoint = new Vector3(selectedBounds.MaxXYZ.X, selectedBounds.MinXYZ.Y, 0); double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint); lines[0] = world.GetScreenPosition(cornerPoint + new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0)); @@ -101,7 +101,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow case HitQuadrant.RT: { - Vector3 cornerPoint = new Vector3(selectedBounds.maxXYZ.X, selectedBounds.maxXYZ.Y, 0); + Vector3 cornerPoint = new Vector3(selectedBounds.MaxXYZ.X, selectedBounds.MaxXYZ.Y, 0); double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint); lines[0] = world.GetScreenPosition(cornerPoint + new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0)); diff --git a/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs b/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs index 1698a00df..5e85ff66b 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs @@ -101,7 +101,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var bvhIterator = new BvhIterator(Scene?.TraceData(), decentFilter: (x) => { var center = x.Bvh.GetCenter(); - var worldCenter = Vector3.Transform(center, x.TransformToWorld); + var worldCenter = Vector3Ex.Transform(center, x.TransformToWorld); if (worldCenter.Z > 0) { return true; @@ -119,16 +119,16 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { for (int i = 0; i < 4; i++) { - Vector3 bottomStartPosition = Vector3.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetBottomCorner(i), x.TransformToWorld); + Vector3 bottomStartPosition = Vector3Ex.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetBottomCorner(i), x.TransformToWorld); var bottomStartScreenPos = World.GetScreenPosition(bottomStartPosition); - Vector3 bottomEndPosition = Vector3.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetBottomCorner((i + 1) % 4), x.TransformToWorld); + Vector3 bottomEndPosition = Vector3Ex.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetBottomCorner((i + 1) % 4), x.TransformToWorld); var bottomEndScreenPos = World.GetScreenPosition(bottomEndPosition); - Vector3 topStartPosition = Vector3.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetTopCorner(i), x.TransformToWorld); + Vector3 topStartPosition = Vector3Ex.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetTopCorner(i), x.TransformToWorld); var topStartScreenPos = World.GetScreenPosition(topStartPosition); - Vector3 topEndPosition = Vector3.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetTopCorner((i + 1) % 4), x.TransformToWorld); + Vector3 topEndPosition = Vector3Ex.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetTopCorner((i + 1) % 4), x.TransformToWorld); var topEndScreenPos = World.GetScreenPosition(topEndPosition); e.Graphics2D.Line(bottomStartScreenPos, bottomEndScreenPos, Color.Black); @@ -136,13 +136,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow e.Graphics2D.Line(topStartScreenPos, bottomStartScreenPos, Color.Black); } - TriangleShape tri = x.Bvh as TriangleShape; + ITriangle tri = x.Bvh as ITriangle; if (tri != null) { for (int i = 0; i < 3; i++) { var vertexPos = tri.GetVertex(i); - var screenCenter = Vector3.Transform(vertexPos, x.TransformToWorld); + var screenCenter = Vector3Ex.Transform(vertexPos, x.TransformToWorld); var screenPos = World.GetScreenPosition(screenCenter); e.Graphics2D.Circle(screenPos, 3, Color.Red); @@ -151,7 +151,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow else { var center = x.Bvh.GetCenter(); - var worldCenter = Vector3.Transform(center, x.TransformToWorld); + var worldCenter = Vector3Ex.Transform(center, x.TransformToWorld); var screenPos2 = World.GetScreenPosition(worldCenter); e.Graphics2D.Circle(screenPos2, 3, Color.Yellow); e.Graphics2D.DrawString($"{x.Depth},", screenPos2.X + 12 * x.Depth, screenPos2.Y); diff --git a/MatterControlLib/PartPreviewWindow/View3D/InteractionVolume.cs b/MatterControlLib/PartPreviewWindow/View3D/InteractionVolume.cs index b0dfb5ba8..098c1f382 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/InteractionVolume.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/InteractionVolume.cs @@ -128,11 +128,11 @@ namespace MatterHackers.MeshVisualizer public static Vector3 SetBottomControlHeight(AxisAlignedBoundingBox originalSelectedBounds, Vector3 cornerPosition) { - if (originalSelectedBounds.minXYZ.Z < 0) + if (originalSelectedBounds.MinXYZ.Z < 0) { - if (originalSelectedBounds.maxXYZ.Z < 0) + if (originalSelectedBounds.MaxXYZ.Z < 0) { - cornerPosition.Z = originalSelectedBounds.maxXYZ.Z; + cornerPosition.Z = originalSelectedBounds.MaxXYZ.Z; } else { diff --git a/MatterControlLib/PartPreviewWindow/View3D/MeshViewerWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/MeshViewerWidget.cs index cb1503453..bc8c22ac5 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -72,13 +72,13 @@ namespace MatterHackers.MeshVisualizer for (int i = 0; i < sides; i++) { var rotatedPoint = new Vector3(Math.Cos(MathHelper.Tau * i / sides), Math.Sin(MathHelper.Tau * i / sides), 0) * Diameter / 2; - var sideTop = Vector3.Transform(center + rotatedPoint + new Vector3(0, 0, Height / 2), worldMatrix); - var sideBottom = Vector3.Transform(center + rotatedPoint + new Vector3(0, 0, -Height / 2), worldMatrix); + var sideTop = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, Height / 2), worldMatrix); + var sideBottom = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, -Height / 2), worldMatrix); var rotated2Point = new Vector3(Math.Cos(MathHelper.Tau * (i + 1) / sides), Math.Sin(MathHelper.Tau * (i + 1) / sides), 0) * Diameter / 2; var topStart = sideTop; - var topEnd = Vector3.Transform(center + rotated2Point + new Vector3(0, 0, Height / 2), worldMatrix); + var topEnd = Vector3Ex.Transform(center + rotated2Point + new Vector3(0, 0, Height / 2), worldMatrix); var bottomStart = sideBottom; - var bottomEnd = Vector3.Transform(center + rotated2Point + new Vector3(0, 0, -Height / 2), worldMatrix); + var bottomEnd = Vector3Ex.Transform(center + rotated2Point + new Vector3(0, 0, -Height / 2), worldMatrix); if (extendLineLength > 0) { @@ -101,14 +101,14 @@ namespace MatterHackers.MeshVisualizer Frustum frustum = world.GetClippingFrustum(); for (int i = 0; i < 4; i++) { - Vector3 sideStartPosition = Vector3.Transform(bounds.GetBottomCorner(i), matrix); - Vector3 sideEndPosition = Vector3.Transform(bounds.GetTopCorner(i), matrix); + Vector3 sideStartPosition = Vector3Ex.Transform(bounds.GetBottomCorner(i), matrix); + Vector3 sideEndPosition = Vector3Ex.Transform(bounds.GetTopCorner(i), matrix); Vector3 bottomStartPosition = sideStartPosition; - Vector3 bottomEndPosition = Vector3.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix); + Vector3 bottomEndPosition = Vector3Ex.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix); Vector3 topStartPosition = sideEndPosition; - Vector3 topEndPosition = Vector3.Transform(bounds.GetTopCorner((i + 1) % 4), matrix); + Vector3 topEndPosition = Vector3Ex.Transform(bounds.GetTopCorner((i + 1) % 4), matrix); if (extendLineLength > 0) { @@ -136,11 +136,11 @@ namespace MatterHackers.MeshVisualizer { var min = position; min[i] -= length[i]; - Vector3 start = Vector3.Transform(min, matrix); + Vector3 start = Vector3Ex.Transform(min, matrix); var max = position; max[i] += length[i]; - Vector3 end = Vector3.Transform(max, matrix); + Vector3 end = Vector3Ex.Transform(max, matrix); var color = Agg.Color.Red; switch (i) @@ -172,10 +172,10 @@ namespace MatterHackers.MeshVisualizer // draw center line { var min = axis.Origin - length; - Vector3 start = Vector3.Transform(min, matrix); + Vector3 start = Vector3Ex.Transform(min, matrix); var max = axis.Origin + length; - Vector3 end = Vector3.Transform(max, matrix); + Vector3 end = Vector3Ex.Transform(max, matrix); world.Render3DLineNoPrep(frustum, start, end, color, 1); } @@ -186,13 +186,13 @@ namespace MatterHackers.MeshVisualizer bool first = true; var firstEnd = Vector3.Zero; var lastEnd = Vector3.Zero; - var center = Vector3.Transform(axis.Origin, matrix); + var center = Vector3Ex.Transform(axis.Origin, matrix); for (int i = 0; i < count; i++) { - var rotation = size/4 * Vector3.Transform(perpendicular, Matrix4X4.CreateRotation(axis.Normal, MathHelper.Tau * i / count)); + var rotation = size/4 * Vector3Ex.Transform(perpendicular, Matrix4X4.CreateRotation(axis.Normal, MathHelper.Tau * i / count)); // draw center line var max = axis.Origin + rotation; - Vector3 end = Vector3.Transform(max, matrix); + Vector3 end = Vector3Ex.Transform(max, matrix); world.Render3DLineNoPrep(frustum, center, end, color, 1); if (!first) @@ -473,7 +473,8 @@ namespace MatterHackers.MeshVisualizer && item.Mesh.Faces.Count > 0) { ImageBuffer faceTexture = null; - item.Mesh.FaceTexture.TryGetValue((item.Mesh.Faces[0], 0), out faceTexture); + + //item.Mesh.FaceTexture.TryGetValue((item.Mesh.Faces[0], 0), out faceTexture); bool hasPersistableTexture = faceTexture == MeshViewerWidget.ViewOnlyTexture; if (item.WorldPersistable()) @@ -525,8 +526,10 @@ namespace MatterHackers.MeshVisualizer } } + bool hasTransparentTextures = item.Mesh.FaceTextures.Any((ft) => ft.Value.image.HasTransparency); + if ((drawColor.alpha == 255 - && !item.Mesh.FaceTexture.Where((ft) => ft.Value.HasTransparency).Any()) + && !hasTransparentTextures) || isDebugItem) { // Render as solid @@ -628,24 +631,25 @@ namespace MatterHackers.MeshVisualizer private void RenderNormals(IObject3D renderData) { - var frustum = World.GetClippingFrustum(); + throw new NotImplementedException(); + //var frustum = World.GetClippingFrustum(); - foreach (var face in renderData.Mesh.Faces) - { - int vertexCount = 0; - Vector3 faceCenter = Vector3.Zero; - foreach (var vertex in face.Vertices()) - { - faceCenter += vertex.Position; - vertexCount++; - } - faceCenter /= vertexCount; + //foreach (var face in renderData.Mesh.Faces) + //{ + // int vertexCount = 0; + // Vector3 faceCenter = Vector3.Zero; + // foreach (var vertex in face.Vertices()) + // { + // faceCenter += vertex.Position; + // vertexCount++; + // } + // faceCenter /= vertexCount; - var transformed1 = Vector3.Transform(faceCenter, renderData.Matrix); - var normal = Vector3.TransformNormal(face.Normal, renderData.Matrix).GetNormal(); + // var transformed1 = Vector3Ex.Transform(faceCenter, renderData.Matrix); + // var normal = Vector3Ex.TransformNormal(face.Normal, renderData.Matrix).GetNormal(); - World.Render3DLineNoPrep(frustum, transformed1, transformed1 + normal, Color.Red, 2); - } + // World.Render3DLineNoPrep(frustum, transformed1, transformed1 + normal, Color.Red, 2); + //} } private void RenderSelection(IObject3D item, Frustum frustum, Color selectionColor) @@ -703,13 +707,13 @@ namespace MatterHackers.MeshVisualizer return -1; } - var aCenterWorld = Vector3.Transform(meshA.GetAxisAlignedBoundingBox().Center, a.Object3D.Matrix); + var aCenterWorld = Vector3Ex.Transform(meshA.GetAxisAlignedBoundingBox().Center, a.Object3D.Matrix); aCenterWorld.Z = 0; // we only want to look at the distance on xy in world space - var aCenterInViewSpace = Vector3.Transform(aCenterWorld, World.ModelviewMatrix); + var aCenterInViewSpace = Vector3Ex.Transform(aCenterWorld, World.ModelviewMatrix); - var bCenterWorld = Vector3.Transform(meshB.GetAxisAlignedBoundingBox().Center, b.Object3D.Matrix); + var bCenterWorld = Vector3Ex.Transform(meshB.GetAxisAlignedBoundingBox().Center, b.Object3D.Matrix); bCenterWorld.Z = 0; // we only want to look at the distance on xy in world space - var bCenterInViewSpace = Vector3.Transform(bCenterWorld, World.ModelviewMatrix); + var bCenterInViewSpace = Vector3Ex.Transform(bCenterWorld, World.ModelviewMatrix); return bCenterInViewSpace.LengthSquared.CompareTo(aCenterInViewSpace.LengthSquared); } @@ -745,9 +749,9 @@ namespace MatterHackers.MeshVisualizer transparentMeshes.Sort(BackToFrontXY); - var bedNormalInViewSpace = Vector3.TransformNormal(Vector3.UnitZ, World.ModelviewMatrix).GetNormal(); - var pointOnBedInViewSpace = Vector3.Transform(new Vector3(10, 10, 0), World.ModelviewMatrix); - var lookingDownOnBed = Vector3.Dot(bedNormalInViewSpace, pointOnBedInViewSpace) < 0; + var bedNormalInViewSpace = Vector3Ex.TransformNormal(Vector3.UnitZ, World.ModelviewMatrix).GetNormal(); + var pointOnBedInViewSpace = Vector3Ex.Transform(new Vector3(10, 10, 0), World.ModelviewMatrix); + var lookingDownOnBed = Vector3Ex.Dot(bedNormalInViewSpace, pointOnBedInViewSpace) < 0; if (lookingDownOnBed) { diff --git a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs index 314726f00..bcfbc0835 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs @@ -114,12 +114,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } progressStatus.Status = "Clean".Localize(); reporter.Report(progressStatus); - ungroupMesh.CleanAndMergeMesh(cancellationToken, 0, (progress0To1, processingState) => - { - progressStatus.Progress0To1 = .2 + progress0To1 * .3; - progressStatus.Status = processingState; - reporter.Report(progressStatus); - }); + throw new NotImplementedException(); + //ungroupMesh.CleanAndMergeMesh(cancellationToken, 0, (progress0To1, processingState) => + //{ + // progressStatus.Progress0To1 = .2 + progress0To1 * .3; + // progressStatus.Status = processingState; + // reporter.Report(progressStatus); + //}); if (cancellationToken.IsCancellationRequested) { return Task.CompletedTask; @@ -326,7 +327,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow newItem.Matrix *= Matrix4X4.CreateTranslation( (sceneContext.BedCenter.X - center.X), (sceneContext.BedCenter.Y - center.Y), - -aabb.minXYZ.Z); + -aabb.MinXYZ.Z); } // Create and perform a new insert operation @@ -358,16 +359,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow IObject3D objectToLayFlat = objectToLayFlatGroup; - IVertex lowestVertex = null; - Vector3 lowestVertexPosition = Vector3.Zero; + Vector3Float lowestPosition = Vector3Float.PositiveInfinity; + Vector3Float sourceVertexPosition = Vector3Float.NegativeInfinity; IObject3D itemToLayFlat = null; + Mesh meshWithLowest = null; // Process each child, checking for the lowest vertex foreach (var itemToCheck in objectToLayFlat.VisibleMeshes()) { var meshToCheck = itemToCheck.Mesh.GetConvexHull(false); - if(meshToCheck == null + if (meshToCheck == null && meshToCheck.Vertices.Count < 3) { continue; @@ -377,41 +379,53 @@ namespace MatterHackers.MatterControl.PartPreviewWindow for (int testIndex = 0; testIndex < meshToCheck.Vertices.Count; testIndex++) { var vertex = meshToCheck.Vertices[testIndex]; - Vector3 vertexPosition = Vector3.Transform(vertex.Position, itemToCheck.WorldMatrix()); + var vertexPosition = vertex.Transform(itemToCheck.WorldMatrix()); if (firstVertex) { - lowestVertex = meshToCheck.Vertices[testIndex]; - lowestVertexPosition = vertexPosition; + meshWithLowest = meshToCheck; + lowestPosition = vertexPosition; + sourceVertexPosition = vertex; itemToLayFlat = itemToCheck; firstVertex = false; } - else if (vertexPosition.Z < lowestVertexPosition.Z) + else if (vertexPosition.Z < lowestPosition.Z) { - lowestVertex = meshToCheck.Vertices[testIndex]; - lowestVertexPosition = vertexPosition; + meshWithLowest = meshToCheck; + lowestPosition = vertexPosition; + sourceVertexPosition = vertex; itemToLayFlat = itemToCheck; } } } - if (lowestVertex == null) + if (meshWithLowest == null) { // didn't find any selected mesh return; } - PolygonMesh.Face faceToLayFlat = null; + int faceToLayFlat = -1; double lowestAngleOfAnyFace = double.MaxValue; // Check all the faces that are connected to the lowest point to find out which one to lay flat. - foreach (var face in lowestVertex.ConnectedFaces()) + for (int faceIndex=0; faceIndex faceVertices = new List(); - foreach (IVertex vertex in faceToLayFlat.Vertices()) + var lowestFace = meshWithLowest.Faces[faceToLayFlat]; + var lowestFaceIndices = new int[] { lowestFace.v0, lowestFace.v1, lowestFace.v2 }; + var faceVertices = new List(); + foreach (var vertex in lowestFaceIndices) { - Vector3 vertexPosition = Vector3.Transform(vertex.Position, itemToLayFlat.WorldMatrix()); + var vertexPosition = meshWithLowest.Vertices[vertex].Transform(itemToLayFlat.WorldMatrix()); faceVertices.Add(vertexPosition); - maxDistFromLowestZ = Math.Max(maxDistFromLowestZ, vertexPosition.Z - lowestVertexPosition.Z); + maxDistFromLowestZ = Math.Max(maxDistFromLowestZ, vertexPosition.Z - lowestPosition.Z); } if (maxDistFromLowestZ > .001) { - Vector3 xPositive = (faceVertices[1] - faceVertices[0]).GetNormal(); - Vector3 yPositive = (faceVertices[2] - faceVertices[0]).GetNormal(); - Vector3 planeNormal = Vector3.Cross(xPositive, yPositive).GetNormal(); + var xPositive = (faceVertices[1] - faceVertices[0]).GetNormal(); + var yPositive = (faceVertices[2] - faceVertices[0]).GetNormal(); + var planeNormal = xPositive.Cross(yPositive).GetNormal(); // this code takes the minimum rotation required and looks much better. - Quaternion rotation = new Quaternion(planeNormal, new Vector3(0, 0, -1)); + Quaternion rotation = new Quaternion(planeNormal, new Vector3Float(0, 0, -1)); Matrix4X4 partLevelMatrix = Matrix4X4.CreateRotation(rotation); // rotate it diff --git a/MatterControlLib/PartPreviewWindow/View3D/TumbleCubeControl.cs b/MatterControlLib/PartPreviewWindow/View3D/TumbleCubeControl.cs index 8823b1d12..013395b86 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/TumbleCubeControl.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/TumbleCubeControl.cs @@ -172,13 +172,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // this data needs to be made on the ui thread UiThread.RunOnIdle(() => { - cube.CleanAndMergeMesh(CancellationToken.None); - TextureFace(cube.Faces[0], "Top"); - TextureFace(cube.Faces[1], "Left", Matrix4X4.CreateRotationZ(MathHelper.Tau / 4)); - TextureFace(cube.Faces[2], "Right", Matrix4X4.CreateRotationZ(-MathHelper.Tau / 4)); - TextureFace(cube.Faces[3], "Bottom", Matrix4X4.CreateRotationZ(MathHelper.Tau / 2)); - TextureFace(cube.Faces[4], "Back", Matrix4X4.CreateRotationZ(MathHelper.Tau / 2)); - TextureFace(cube.Faces[5], "Front"); + TextureFace(0, "Top"); + TextureFace(1, "Left", Matrix4X4.CreateRotationZ(MathHelper.Tau / 4)); + TextureFace(2, "Right", Matrix4X4.CreateRotationZ(-MathHelper.Tau / 4)); + TextureFace(3, "Bottom", Matrix4X4.CreateRotationZ(MathHelper.Tau / 2)); + TextureFace(4, "Back", Matrix4X4.CreateRotationZ(MathHelper.Tau / 2)); + TextureFace(5, "Front"); cube.MarkAsChanged(); connections.Add(new ConnectedFaces(2, 1, 1, 5, 2, 4)); @@ -208,10 +207,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow world = new WorldView(screenSpaceBounds.Width, screenSpaceBounds.Height); var forward = -Vector3.UnitZ; - var directionForward = Vector3.TransformNormal(forward, interactionLayer.World.InverseModelviewMatrix); + var directionForward = Vector3Ex.TransformNormal(forward, interactionLayer.World.InverseModelviewMatrix); var up = Vector3.UnitY; - var directionUp = Vector3.TransformNormal(up, interactionLayer.World.InverseModelviewMatrix); + var directionUp = Vector3Ex.TransformNormal(up, interactionLayer.World.InverseModelviewMatrix); world.RotationMatrix = Matrix4X4.LookAt(Vector3.Zero, directionForward, directionUp) * Matrix4X4.CreateScale(.8); GLHelper.SetGlContext(world, screenSpaceBounds, lighting); @@ -580,7 +579,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow lastHitData = new HitData(); } - private void TextureFace(Face face, string name, Matrix4X4? initialRotation = null) + private void TextureFace(int face, string name, Matrix4X4? initialRotation = null) { ImageBuffer sourceTexture = new ImageBuffer(256, 256); var frontGraphics = sourceTexture.NewGraphics2D(); @@ -594,7 +593,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow frontGraphics.Render(new Stroke(new RoundedRect(.5, .5, 254.5, 254.4, 0), 6), Color.DarkGray); var activeTexture = new ImageBuffer(sourceTexture); ImageGlPlugin.GetImageGlPlugin(activeTexture, true); - MeshHelper.PlaceTextureOnFace(face, activeTexture, MeshHelper.GetMaxFaceProjection(face, activeTexture, initialRotation)); + cube.PlaceTextureOnFace(face, activeTexture, cube.GetMaxFaceProjection(face, activeTexture, initialRotation)); textureDatas.Add(new TextureData() { diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index bec8e7206..cd2af7656 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -1026,7 +1026,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var sourceItemBounds = insertionGroup.GetAxisAlignedBoundingBox(Matrix4X4.Identity); var center = sourceItemBounds.Center; - insertionGroup.Matrix *= Matrix4X4.CreateTranslation(-center.X, -center.Y, -sourceItemBounds.minXYZ.Z); + insertionGroup.Matrix *= Matrix4X4.CreateTranslation(-center.X, -center.Y, -sourceItemBounds.MinXYZ.Z); insertionGroup.Matrix *= Matrix4X4.CreateTranslation(new Vector3(intersectInfo.HitPosition)); CurrentSelectInfo.PlaneDownHitPos = intersectInfo.HitPosition; @@ -1163,13 +1163,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { return false; } - if (x.Bvh is TriangleShape tri) + if (x.Bvh is ITriangle tri) { // check if any vertex in screen rect // calculate all the top and bottom screen positions for (int i = 0; i < 3; i++) { - Vector3 bottomStartPosition = Vector3.Transform(tri.GetVertex(i), x.TransformToWorld); + Vector3 bottomStartPosition = Vector3Ex.Transform(tri.GetVertex(i), x.TransformToWorld); traceBottoms[i] = this.World.GetScreenPosition(bottomStartPosition); } @@ -1187,10 +1187,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // calculate all the top and bottom screen positions for (int i = 0; i < 4; i++) { - Vector3 bottomStartPosition = Vector3.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetBottomCorner(i), x.TransformToWorld); + Vector3 bottomStartPosition = Vector3Ex.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetBottomCorner(i), x.TransformToWorld); traceBottoms[i] = this.World.GetScreenPosition(bottomStartPosition); - Vector3 topStartPosition = Vector3.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetTopCorner(i), x.TransformToWorld); + Vector3 topStartPosition = Vector3Ex.Transform(x.Bvh.GetAxisAlignedBoundingBox().GetTopCorner(i), x.TransformToWorld); traceTops[i] = this.World.GetScreenPosition(topStartPosition); } @@ -1534,26 +1534,26 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // snap this position to the grid AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - double xSnapOffset = selectedBounds.minXYZ.X; + double xSnapOffset = selectedBounds.MinXYZ.X; // snap the x position if (CurrentSelectInfo.HitQuadrant == HitQuadrant.RB || CurrentSelectInfo.HitQuadrant == HitQuadrant.RT) { // switch to the other side - xSnapOffset = selectedBounds.maxXYZ.X; + xSnapOffset = selectedBounds.MaxXYZ.X; } double xToSnap = xSnapOffset + delta.X; double snappedX = ((int)((xToSnap / snapGridDistance) + .5)) * snapGridDistance; delta.X = snappedX - xSnapOffset; - double ySnapOffset = selectedBounds.minXYZ.Y; + double ySnapOffset = selectedBounds.MinXYZ.Y; // snap the y position if (CurrentSelectInfo.HitQuadrant == HitQuadrant.LT || CurrentSelectInfo.HitQuadrant == HitQuadrant.RT) { // switch to the other side - ySnapOffset = selectedBounds.maxXYZ.Y; + ySnapOffset = selectedBounds.MaxXYZ.Y; } double yToSnap = ySnapOffset + delta.Y; diff --git a/MatterControlLib/PrinterControls/PrintLevelingPlane.cs b/MatterControlLib/PrinterControls/PrintLevelingPlane.cs index 38b17464f..8846ea7ee 100644 --- a/MatterControlLib/PrinterControls/PrintLevelingPlane.cs +++ b/MatterControlLib/PrinterControls/PrintLevelingPlane.cs @@ -30,12 +30,12 @@ namespace MatterHackers.MatterControl public Vector3 ApplyLeveling(Vector3 inPosition) { - return Vector3.TransformPosition(inPosition, bedLevelMatrix); + return Vector3Ex.TransformPosition(inPosition, bedLevelMatrix); } public Vector3 ApplyLevelingRotation(Vector3 inPosition) { - return Vector3.TransformVector(inPosition, bedLevelMatrix); + return Vector3Ex.TransformVector(inPosition, bedLevelMatrix); } public string ApplyLeveling(Vector3 currentDestination, string lineBeingSent) diff --git a/MatterControlLib/SlicerConfiguration/Slicing/SliceLayers.cs b/MatterControlLib/SlicerConfiguration/Slicing/SliceLayers.cs index ef397a02a..8aab3b859 100644 --- a/MatterControlLib/SlicerConfiguration/Slicing/SliceLayers.cs +++ b/MatterControlLib/SlicerConfiguration/Slicing/SliceLayers.cs @@ -88,40 +88,41 @@ namespace MatterHackers.MatterControl.Slicing currentZ += otherLayerHeights; } - foreach (Face face in meshToSlice.Faces) - { - double minZ = double.MaxValue; - double maxZ = double.MinValue; - foreach (FaceEdge faceEdge in face.FaceEdges()) - { - minZ = Math.Min(minZ, faceEdge.FirstVertex.Position.Z); - maxZ = Math.Max(maxZ, faceEdge.FirstVertex.Position.Z); - } + throw new NotImplementedException(); + //foreach (Face face in meshToSlice.Faces) + //{ + // double minZ = double.MaxValue; + // double maxZ = double.MinValue; + // foreach (FaceEdge faceEdge in face.FaceEdges()) + // { + // minZ = Math.Min(minZ, faceEdge.FirstVertex.Position.Z); + // maxZ = Math.Max(maxZ, faceEdge.FirstVertex.Position.Z); + // } - for (int layerIndex = 0; layerIndex < layerCount; layerIndex++) - { - SliceLayer layer = AllLayers[layerIndex]; - double zHeight = layer.SlicePlane.DistanceToPlaneFromOrigin; - if (zHeight < minZ) - { - // not up to the start of the face yet - continue; - } - if (zHeight > maxZ) - { - // done with this face - break; - } - Plane cutPlane = new Plane(Vector3.UnitZ, zHeight); + // for (int layerIndex = 0; layerIndex < layerCount; layerIndex++) + // { + // SliceLayer layer = AllLayers[layerIndex]; + // double zHeight = layer.SlicePlane.DistanceToPlaneFromOrigin; + // if (zHeight < minZ) + // { + // // not up to the start of the face yet + // continue; + // } + // if (zHeight > maxZ) + // { + // // done with this face + // break; + // } + // Plane cutPlane = new Plane(Vector3.UnitZ, zHeight); - var start = Vector3.Zero; - var end = Vector3.Zero; - if (face.GetCutLine(cutPlane, ref start, ref end)) - { - layer.UnorderedSegments.Add(new Segment(new Vector2(start.X, start.Y), new Vector2(end.X, end.Y))); - } - } - } + // var start = Vector3.Zero; + // var end = Vector3.Zero; + // if (face.GetCutLine(cutPlane, ref start, ref end)) + // { + // layer.UnorderedSegments.Add(new Segment(new Vector2(start.X, start.Y), new Vector2(end.X, end.Y))); + // } + // } + //} } } } \ No newline at end of file diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 81ae9b656..d041c689f 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 81ae9b6564598d427b98d7258229189d20494ec5 +Subproject commit d041c689ff696b8accd173e5cd4521a8f64eb62d diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 603665336..684fb89ec 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 603665336c2dac367c5fbb083a8c73df068b126e +Subproject commit 684fb89ecf7397faa8412c890095964ef6c14340 diff --git a/Tests/MatterControl.Tests/MatterControl/MeshCsgTests.cs b/Tests/MatterControl.Tests/MatterControl/MeshCsgTests.cs index aa25c4738..86a243a76 100644 --- a/Tests/MatterControl.Tests/MatterControl/MeshCsgTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/MeshCsgTests.cs @@ -56,12 +56,12 @@ namespace MatterHackers.PolygonMesh.UnitTests { // split edge 0 { - var vt = new Vector3List(new double[] + var vt = new double[] { 0, 0, 0, 12, 0, 0, 6, 6, 0, - }); + }.ToVector3List(); var ft = new FaceList(new int[] { 0, 1, 2 @@ -73,12 +73,12 @@ namespace MatterHackers.PolygonMesh.UnitTests } // split edge 1 { - var vt = new Vector3List(new double[] + var vt = new double[] { 0, 0, 0, 12, 0, 0, 6, 6, 0, - }); + }.ToVector3List(); var ft = new FaceList(new int[] { 1, 2, 0 @@ -90,12 +90,12 @@ namespace MatterHackers.PolygonMesh.UnitTests } // split edge 2 { - var vt = new Vector3List(new double[] + var vt = new double[] { 0, 0, 0, 12, 0, 0, 6, 6, 0, - }); + }.ToVector3List(); var ft = new FaceList(new int[] { 2, 0, 1 @@ -110,100 +110,101 @@ namespace MatterHackers.PolygonMesh.UnitTests [Test] public void CsgCylinderMinusCylinder() { - AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); - MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); + throw new NotImplementedException(); + //AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); + //MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); - AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData")); - MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5)); + //AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData")); + //MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5)); - // check that we subtract two 3 sided cylinders - { - double topHeight = 10; - int sides = 3; - IObject3D keep = CylinderObject3D.Create(20, topHeight * 2, sides); - IObject3D subtract = CylinderObject3D.Create(10, topHeight * 2, sides); + //// check that we subtract two 3 sided cylinders + //{ + // double topHeight = 10; + // int sides = 3; + // IObject3D keep = CylinderObject3D.Create(20, topHeight * 2, sides); + // IObject3D subtract = CylinderObject3D.Create(10, topHeight * 2, sides); - var keepMesh = keep.Mesh; - var subtractMesh = subtract.Mesh; + // var keepMesh = keep.Mesh; + // var subtractMesh = subtract.Mesh; - if (false) - { - var split1 = new DebugFace() - { - EvaluateHeight = topHeight, - FileName = "Split1" - }; + // if (false) + // { + // var split1 = new DebugFace() + // { + // EvaluateHeight = topHeight, + // FileName = "Split1" + // }; - BooleanModeller.Object1SplitFace = split1.Split; - BooleanModeller.Object1SplitResults = split1.Result; + // BooleanModeller.Object1SplitFace = split1.Split; + // BooleanModeller.Object1SplitResults = split1.Result; - BooleanModeller.Object1ClassifyFace = split1.Classify1; - BooleanModeller.Object2ClassifyFace = split1.Classify2; - } + // BooleanModeller.Object1ClassifyFace = split1.Classify1; + // BooleanModeller.Object2ClassifyFace = split1.Classify2; + // } - var resultMesh = keepMesh.Subtract(subtractMesh, null, CancellationToken.None); + // var resultMesh = keepMesh.Subtract(subtractMesh, null, CancellationToken.None); - // this is for debugging the operation - //split1.FinishOutput(); - //resultMesh.Save("c:/temp/mesh1.stl", CancellationToken.None); + // // this is for debugging the operation + // //split1.FinishOutput(); + // //resultMesh.Save("c:/temp/mesh1.stl", CancellationToken.None); - var topZero = new Vector3(0, 0, topHeight); - foreach (var topVertex in keepMesh.Vertices - .Where((v) => v.Position.Z == topHeight && v.Position != topZero) - .Select((gv) => gv.Position)) - { - Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes"); - } - foreach (var topVertex in subtractMesh.Vertices - .Where((v) => v.Position.Z == topHeight && v.Position != topZero) - .Select((gv) => gv.Position)) - { - Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes"); - } - } + // var topZero = new Vector3(0, 0, topHeight); + // foreach (var topVertex in keepMesh.Vertices + // .Where((v) => v.Position.Z == topHeight && v.Position != topZero) + // .Select((gv) => gv.Position)) + // { + // Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes"); + // } + // foreach (var topVertex in subtractMesh.Vertices + // .Where((v) => v.Position.Z == topHeight && v.Position != topZero) + // .Select((gv) => gv.Position)) + // { + // Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes"); + // } + //} - // check that we subtract two 3 side cylinders - { - int sides = 3; - IObject3D keep = CylinderObject3D.Create(20, 20, sides); - IObject3D subtract = CylinderObject3D.Create(10, 22, sides); + //// check that we subtract two 3 side cylinders + //{ + // int sides = 3; + // IObject3D keep = CylinderObject3D.Create(20, 20, sides); + // IObject3D subtract = CylinderObject3D.Create(10, 22, sides); - var keepMesh = keep.Mesh; - var subtractMesh = subtract.Mesh; + // var keepMesh = keep.Mesh; + // var subtractMesh = subtract.Mesh; - if (false) - { - var split1 = new DebugFace() - { - EvaluateHeight = 10, - FileName = "Split2" - }; + // if (false) + // { + // var split1 = new DebugFace() + // { + // EvaluateHeight = 10, + // FileName = "Split2" + // }; - BooleanModeller.Object1SplitFace = split1.Split; - BooleanModeller.Object1SplitResults = split1.Result; - } + // BooleanModeller.Object1SplitFace = split1.Split; + // BooleanModeller.Object1SplitResults = split1.Result; + // } - var resultMesh = keepMesh.Subtract(subtractMesh, null, CancellationToken.None); + // var resultMesh = keepMesh.Subtract(subtractMesh, null, CancellationToken.None); - // this is for debugging the operation - //split1.FinishOutput(); - //resultMesh.Save("c:/temp/mesh2.stl", CancellationToken.None); + // // this is for debugging the operation + // //split1.FinishOutput(); + // //resultMesh.Save("c:/temp/mesh2.stl", CancellationToken.None); - foreach (var topVertex in keepMesh.Vertices - .Where((v) => v.Position.Z == 10 && v.Position != new Vector3(0, 0, 10)) - .Select((gv) => gv.Position)) - { - Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes"); - } - foreach (var topVertex in subtractMesh.Vertices - .Where((v) => v.Position.Z == 11 && v.Position != new Vector3(0, 0, 11)) - .Select((gv) => gv.Position)) - { - Assert.IsTrue(resultMesh.Vertices - .Where((v) => v.Position.Equals(new Vector3(topVertex.X, topVertex.Y, 10), .0001)) - .Any(), "Have all top vertexes"); - } - } + // foreach (var topVertex in keepMesh.Vertices + // .Where((v) => v.Position.Z == 10 && v.Position != new Vector3(0, 0, 10)) + // .Select((gv) => gv.Position)) + // { + // Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes"); + // } + // foreach (var topVertex in subtractMesh.Vertices + // .Where((v) => v.Position.Z == 11 && v.Position != new Vector3(0, 0, 11)) + // .Select((gv) => gv.Position)) + // { + // Assert.IsTrue(resultMesh.Vertices + // .Where((v) => v.Position.Equals(new Vector3(topVertex.X, topVertex.Y, 10), .0001)) + // .Any(), "Have all top vertexes"); + // } + //} } }