diff --git a/Library/ContentProviders/MeshContentProvider.cs b/Library/ContentProviders/MeshContentProvider.cs index 1bca5897e..24e42e7f5 100644 --- a/Library/ContentProviders/MeshContentProvider.cs +++ b/Library/ContentProviders/MeshContentProvider.cs @@ -136,20 +136,6 @@ namespace MatterHackers.MatterControl if (object3D != null) { - if (object3D.Mesh == null && object3D.HasChildren) - { - object3D = new Object3D() - { - ItemType = Object3DTypes.Model, - Mesh = MeshFileIo.DoMerge(object3D.ToMeshGroupList(), new MeshOutputSettings()) - }; - } - - if (object3D.Mesh == null) - { - return; - } - bool RenderOrthographic = UserSettings.Instance.get(UserSettingsKey.ThumbnailRenderingMode) == "orthographic"; var thumbnail = ThumbnailEngine.Generate( diff --git a/PartPreviewWindow/CreateDiscreteMeshes.cs b/PartPreviewWindow/CreateDiscreteMeshes.cs index 52897cc05..7d564081f 100644 --- a/PartPreviewWindow/CreateDiscreteMeshes.cs +++ b/PartPreviewWindow/CreateDiscreteMeshes.cs @@ -128,117 +128,6 @@ namespace MatterHackers.MatterControl return discreetVolumes; } - public static Mesh[] SplitIntoMeshesOnOrthographicZ(Mesh meshToSplit, Vector3 buildVolume, Action reportProgress) - { - // check if the part is bigger than the build plate (if it is we need to use that as our size) - AxisAlignedBoundingBox partBounds = meshToSplit.GetAxisAlignedBoundingBox(); - - buildVolume.x = Math.Max(buildVolume.x, partBounds.XSize + 2); - buildVolume.y = Math.Max(buildVolume.y, partBounds.YSize + 2); - buildVolume.z = Math.Max(buildVolume.z, partBounds.ZSize + 2); - - // Find all the separate objects that are on the plate - // Create a 2D image the size of the printer bed at some scale with the parts draw on it top down - - double scaleFactor = 5; - ImageBuffer partPlate = new ImageBuffer((int)(buildVolume.x * scaleFactor), (int)(buildVolume.y * scaleFactor)); - Vector2 renderOffset = new Vector2(buildVolume.x / 2, buildVolume.y / 2) - new Vector2(partBounds.Center.x, partBounds.Center.y); - - PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partPlate.NewGraphics2D(), meshToSplit, renderOffset, scaleFactor, RGBA_Bytes.White); - - reportProgress?.Invoke(.2, ""); - - //ImageIO.SaveImageData("test part plate 0.png", partPlate); - // expand the bounds a bit so that we can collect all the vertices and polygons within each bound - Dilate.DoDilate3x3Binary(partPlate, 1); - //ImageIO.SaveImageData("test part plate 1.png", partPlate); - - // trace all the bounds of the objects on the plate - PolyTree polyTreeForPlate = FindDistictObjectBounds(partPlate); - if (polyTreeForPlate == null) - { - Mesh[] singleMesh = new Mesh[1]; - singleMesh[0] = meshToSplit; - return singleMesh; - } - - // get all the discrete areas that are polygons so we can search them - Polygons discreteAreas = new Polygons(); - GetAreasRecursive(polyTreeForPlate, discreteAreas); - if (discreteAreas.Count == 0) - { - return null; - } - else if (discreteAreas.Count == 1) - { - Mesh[] singleMesh = new Mesh[1]; - singleMesh[0] = meshToSplit; - return singleMesh; - } - - Graphics2D graphics2D = partPlate.NewGraphics2D(); - graphics2D.Clear(RGBA_Bytes.Black); - Random rand = new Random(); - foreach (Polygon polygon in discreteAreas) - { - graphics2D.Render(PlatingHelper.PolygonToPathStorage(polygon), new RGBA_Bytes(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255))); - } - - reportProgress?.Invoke(.5, ""); - - //ImageIO.SaveImageData("test part plate 2.png", partPlate); - - // add each of the separate bounds polygons to new meshes - Mesh[] discreteMeshes = new Mesh[discreteAreas.Count]; - for (int i = 0; i < discreteAreas.Count; i++) - { - discreteMeshes[i] = new Mesh(); - } - - foreach (Face face in meshToSplit.Faces) - { - bool faceDone = false; - // figure out which area one or more of the vertices are in add the face to the right new mesh - foreach (FaceEdge faceEdge in face.FaceEdges()) - { - Vector2 position = new Vector2(faceEdge.FirstVertex.Position.x, faceEdge.FirstVertex.Position.y); - position += renderOffset; - position *= scaleFactor; - - for (int areaIndex = discreteAreas.Count - 1; areaIndex >= 0; areaIndex--) - { - if (PointInPolygon(discreteAreas[areaIndex], new IntPoint((int)position.x, (int)position.y))) - { - var faceVertices = new List(); - foreach (FaceEdge faceEdgeToAdd in face.FaceEdges()) - { - var newVertex = discreteMeshes[areaIndex].CreateVertex(faceEdgeToAdd.FirstVertex.Position); - faceVertices.Add(newVertex); - } - - discreteMeshes[areaIndex].CreateFace(faceVertices.ToArray()); - faceDone = true; - break; - } - } - - if (faceDone) - { - break; - } - } - } - - reportProgress?.Invoke(.8, ""); - - for (int i = 0; i < discreteMeshes.Count(); i++) - { - Mesh mesh = discreteMeshes[i]; - } - - return discreteMeshes; - } - public static bool PointInPolygon(Polygon polygon, IntPoint testPosition) { int numPoints = polygon.Count; diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index 7ec01460e..4cb3da417 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -251,7 +251,7 @@ namespace MatterHackers.MeshVisualizer renderType = value; foreach(var renderTransfrom in Scene.VisibleMeshes(Matrix4X4.Identity)) { - renderTransfrom.MeshData.MarkAsChanged(); + renderTransfrom.Mesh.MarkAsChanged(); } } } @@ -613,14 +613,15 @@ namespace MatterHackers.MeshVisualizer public bool IsActive { get; set; } = true; + RGBA_Bytes lastDrawColor; private void DrawObject(IObject3D object3D, Matrix4X4 transform, bool parentSelected) { - foreach(MeshAndTransform meshAndTransform in object3D.VisibleMeshes(transform)) + foreach(MeshRenderData renderData in object3D.VisibleMeshes(transform)) { bool isSelected = parentSelected || Scene.HasSelection && (object3D == Scene.SelectedItem || Scene.SelectedItem.Children.Contains(object3D)); - RGBA_Bytes drawColor = object3D.Color; + RGBA_Bytes drawColor = renderData.Color; if(object3D.OutputType == PrintOutputTypes.Support) { drawColor = new RGBA_Bytes(RGBA_Bytes.Yellow, 120); @@ -632,11 +633,14 @@ namespace MatterHackers.MeshVisualizer if (drawColor.Alpha0To1 == 0) { - int extruderIndex = Math.Max(0, object3D.ExtruderIndex); - drawColor = isSelected ? GetSelectedExtruderColor(extruderIndex) : GetExtruderColor(extruderIndex); + drawColor = lastDrawColor; + } + else + { + lastDrawColor = drawColor; } - GLHelper.Render(meshAndTransform.MeshData, drawColor, meshAndTransform.Matrix, RenderType); + GLHelper.Render(renderData.Mesh, drawColor, renderData.Matrix, RenderType); } } diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index 39065a647..dc94a3106 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -2383,9 +2383,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow UserSettings.Instance.set("defaultRenderSetting", meshViewerWidget.RenderType.ToString()); foreach (var meshAndTransform in scene.VisibleMeshes(Matrix4X4.Identity)) { - meshAndTransform.MeshData.MarkAsChanged(); + meshAndTransform.Mesh.MarkAsChanged(); // change the color to be the right thing - GLMeshTrianglePlugin glMeshPlugin = GLMeshTrianglePlugin.Get(meshAndTransform.MeshData, (faceEdge) => + GLMeshTrianglePlugin glMeshPlugin = GLMeshTrianglePlugin.Get(meshAndTransform.Mesh, (faceEdge) => { Vector3 normal = faceEdge.ContainingFace.normal; normal = Vector3.TransformVector(normal, meshAndTransform.Matrix).GetNormal(); diff --git a/Queue/OptionsMenu/PartsSheetCreator.cs b/Queue/OptionsMenu/PartsSheetCreator.cs index 36962b882..3bd12e1ca 100644 --- a/Queue/OptionsMenu/PartsSheetCreator.cs +++ b/Queue/OptionsMenu/PartsSheetCreator.cs @@ -136,22 +136,14 @@ namespace MatterHackers.MatterControl await contentResult.MeshLoaded; - List loadedMeshGroups = contentResult.Object3D?.ToMeshGroupList(); + var loadedMeshGroups = contentResult.Object3D.VisibleMeshes(Matrix4X4.Identity).ToList(); if (loadedMeshGroups?.Count > 0) { - bool firstMeshGroup = true; - AxisAlignedBoundingBox aabb = null; - foreach (MeshGroup meshGroup in loadedMeshGroups) + AxisAlignedBoundingBox aabb = loadedMeshGroups[0].Mesh.GetAxisAlignedBoundingBox(loadedMeshGroups[0].Matrix); + + for (int i = 1; i < loadedMeshGroups.Count; i++) { - if (firstMeshGroup) - { - aabb = meshGroup.GetAxisAlignedBoundingBox(); - firstMeshGroup = false; - } - else - { - aabb = AxisAlignedBoundingBox.Union(aabb, meshGroup.GetAxisAlignedBoundingBox()); - } + aabb = AxisAlignedBoundingBox.Union(aabb, loadedMeshGroups[i].Mesh.GetAxisAlignedBoundingBox(loadedMeshGroups[i].Matrix)); } RectangleDouble bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y); @@ -176,12 +168,9 @@ namespace MatterHackers.MatterControl Stroke rectOutline = new Stroke(rect, strokeWidth); partGraphics2D.Render(rectOutline, RGBA_Bytes.DarkGray); - foreach (MeshGroup meshGroup in loadedMeshGroups) + foreach (var meshGroup in loadedMeshGroups) { - foreach (Mesh loadedMesh in meshGroup.Meshes) - { - PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black); - } + PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, meshGroup.Mesh, meshGroup.Matrix, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black); } partGraphics2D.Render(typeFacePrinter, RGBA_Bytes.Black); diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 592850ee8..8527327fc 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 592850ee8828c9527f265147f77964a61db18241 +Subproject commit 8527327fcdd703f5eb2836b54ebff8559e625e07