From 2acc7ed18043951aa809a266fff061b33c387284 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Thu, 30 Jun 2022 08:20:35 -0700 Subject: [PATCH] Working on union validation --- .../View3D/Actions/CombineObject3D_2.cs | 47 ++++++++++++++++++- Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs index f3e1d139f..4b6bb2905 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs @@ -72,7 +72,45 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D private ProcessingResolution InputResolution { get; set; } = ProcessingResolution._64; #endif public bool IsBuilding => this.cancellationToken != null; - + + public static void CheckManifoldData(CombineObject3D_2 item, IObject3D result) + { + bool IsManifold(Mesh mesh) + { + var meshEdgeList = mesh.NewMeshEdges(); + + foreach (var meshEdge in meshEdgeList) + { + if (meshEdge.Faces.Count() != 2) + { + return false; + } + } + + return true; + } + + if (!IsManifold(result.Mesh)) + { + // create a new combine of a and b and add it to the root + var combine = new CombineObject3D_2(); + + var participants = item.SourceContainer.VisibleMeshes().Where(m => m.WorldOutputType(item.SourceContainer) != PrintOutputTypes.Hole); + // all participants are manifold + foreach (var participant in participants) + { + combine.SourceContainer.Children.Add(new Object3D() + { + Mesh = participant.Mesh.Copy(new CancellationToken()), + Matrix = participant.Matrix + }); + } + + var scene = result.Parents().Last(); + scene.Children.Add(combine); + } + } + public override Task Rebuild() { this.DebugDepth("Rebuild"); @@ -183,7 +221,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D resultsItem.CopyProperties(participants.First(), Object3DPropertyFlags.All & (~Object3DPropertyFlags.Matrix)); this.Children.Add(resultsItem); - SourceContainer.Visible = false; +#if DEBUG + //resultsItem.Mesh.MergeVertices(.01); + //resultsItem.Mesh.CleanAndMerge(); + //CheckManifoldData(this, resultsItem); +#endif + SourceContainer.Visible = false; } public void UpdateControls(PublicPropertyChange change) diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index d30433b04..ab65243a2 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit d30433b04424d0af57fa22e0bf8cec077ac41b2a +Subproject commit ab65243a2b19b8e1a8668443ffb7c8ec0c2b2911 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 4af60a982..1d16b11a1 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 4af60a9822345f3bf6800ede7d5b6c6948ea0dc9 +Subproject commit 1d16b11a1d3eb375996808be4ae174e98600edf6