diff --git a/MatterControlLib/SlicerConfiguration/EngineMappingsMatterSlice.cs b/MatterControlLib/SlicerConfiguration/EngineMappingsMatterSlice.cs index 36984a012..5f86e2356 100644 --- a/MatterControlLib/SlicerConfiguration/EngineMappingsMatterSlice.cs +++ b/MatterControlLib/SlicerConfiguration/EngineMappingsMatterSlice.cs @@ -294,7 +294,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration for (int extruderIndexIn = 0; extruderIndexIn < extruderCount; extruderIndexIn++) { var extruderIndex = extruderIndexIn; - IEnumerable itemsThisExtruder = Slicer.GetItemsForExtruder(meshItemsOnBuildPlate, extruderCount, extruderIndex, true); + IEnumerable itemsThisExtruder = Slicer.GetSolidsForExtruder(meshItemsOnBuildPlate, extruderCount, extruderIndex, true); itemsByExtruder.Add(itemsThisExtruder); if (Slicer.ExtrudersUsed[extruderIndex]) @@ -305,17 +305,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration var outputOptions = new List<(Matrix4X4 matrix, string fileName)>(); + var holes = Slicer.GetAllHoles(meshItemsOnBuildPlate); + int savedStlCount = 0; - bool first = true; + var firstExtruder = true; for (int extruderIndex = 0; extruderIndex < itemsByExtruder.Count; extruderIndex++) { - if (!first) + if (!firstExtruder) { mergeRules += ","; - first = false; } - - mergeRules += AddObjectsForExtruder(itemsByExtruder[extruderIndex], outputOptions, ref savedStlCount); + mergeRules += AddObjectsForExtruder(itemsByExtruder[extruderIndex], holes, outputOptions, ref savedStlCount); + firstExtruder = false; } var supportObjects = meshItemsOnBuildPlate.Where((item) => item.WorldOutputType() == PrintOutputTypes.Support); @@ -323,7 +324,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (supportObjects.Any()) { // add a flag to the merge rules to let us know there was support - mergeRules += ",S" + AddObjectsForExtruder(supportObjects, outputOptions, ref savedStlCount); + mergeRules += "S" + AddObjectsForExtruder(supportObjects, holes, outputOptions, ref savedStlCount); } var wipeTowerObjects = meshItemsOnBuildPlate.Where((item) => item.WorldOutputType() == PrintOutputTypes.WipeTower); @@ -331,7 +332,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (wipeTowerObjects.Any()) { // add a flag to the merge rules to let us know there was a wipe tower - mergeRules += ",W" + AddObjectsForExtruder(wipeTowerObjects, outputOptions, ref savedStlCount); + mergeRules += "W" + AddObjectsForExtruder(wipeTowerObjects, holes, outputOptions, ref savedStlCount); } var fuzzyObjects = meshItemsOnBuildPlate.Where((item) => item.WorldOutputType() == PrintOutputTypes.Fuzzy); @@ -339,11 +340,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (fuzzyObjects.Any()) { // add a flag to the merge rules to let us know there was a wipe tower - mergeRules += ",F" + AddObjectsForExtruder(fuzzyObjects, outputOptions, ref savedStlCount); + mergeRules += "F" + AddObjectsForExtruder(fuzzyObjects, holes, outputOptions, ref savedStlCount); } - mergeRules += " "; - return outputOptions; } @@ -600,36 +599,70 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } } - private static string AddObjectsForExtruder(IEnumerable items, List<(Matrix4X4 matrix, string fileName)> outputItems, ref int savedStlCount) + private static string AddObjectsForExtruder(IEnumerable solids, IEnumerable holes, List<(Matrix4X4 matrix, string fileName)> outputItems, ref int savedStlCount) { string mergeString = ""; - if (items.Any()) + if (solids.Any()) { - bool first = true; - foreach (var item in items) + bool firstSolid = true; + foreach (var solid in solids) { - if (!first) - { - mergeString += ","; - } - - var itemWorldMatrix = item.WorldMatrix(); - if (item is GeneratedSupportObject3D generatedSupportObject3D - && item.Mesh != null) + var itemWorldMatrix = solid.WorldMatrix(); + if (solid is GeneratedSupportObject3D generatedSupportObject3D + && solid.Mesh != null) { // grow the support columns by the amount they are reduced by - var aabbForCenter = item.Mesh.GetAxisAlignedBoundingBox(); - var aabbForSize = item.Mesh.GetAxisAlignedBoundingBox(item.Matrix); + var aabbForCenter = solid.Mesh.GetAxisAlignedBoundingBox(); + var aabbForSize = solid.Mesh.GetAxisAlignedBoundingBox(solid.Matrix); var xyScale = (aabbForSize.XSize + 2 * SupportGenerator.ColumnReduceAmount) / aabbForSize.XSize; itemWorldMatrix = itemWorldMatrix.ApplyAtPosition(aabbForCenter.Center.Transform(itemWorldMatrix), Matrix4X4.CreateScale(xyScale, xyScale, 1)); } - outputItems.Add((itemWorldMatrix, Path.Combine(ApplicationDataStorage.Instance.LibraryAssetsPath, item.MeshPath))); - mergeString += $"({savedStlCount++}"; - first = false; + outputItems.Add((itemWorldMatrix, Path.Combine(ApplicationDataStorage.Instance.LibraryAssetsPath, solid.MeshPath))); + mergeString += $"{savedStlCount++}"; + if (solids.Count() > 1) + { + if (firstSolid) + { + mergeString += ","; + firstSolid = false; + } + else + { + mergeString += "+"; + } + } + else if (holes.Any()) + { + mergeString += ","; + } } - mergeString += new string(')', items.Count()); + if (holes.Any()) + { + bool firstHole = true; + + foreach (var hole in holes) + { + var itemWorldMatrix = hole.WorldMatrix(); + outputItems.Add((itemWorldMatrix, Path.Combine(ApplicationDataStorage.Instance.LibraryAssetsPath, hole.MeshPath))); + mergeString += $"{savedStlCount++}"; + if (holes.Count() > 1) + { + if (firstHole) + { + mergeString += ","; + firstHole = false; + } + else + { + mergeString += "+"; + } + } + } + + mergeString += "-"; + } } else { @@ -646,7 +679,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration StlProcessing.Save(tinyMesh, tinyObjectFileName, CancellationToken.None); outputItems.Add((Matrix4X4.Identity, tinyObjectFileName)); - mergeString += $"({savedStlCount++})"; + mergeString += $"{savedStlCount++}"; } return mergeString; diff --git a/MatterControlLib/SlicerConfiguration/Slicer.cs b/MatterControlLib/SlicerConfiguration/Slicer.cs index 8cdc6db7d..cb1594aa0 100644 --- a/MatterControlLib/SlicerConfiguration/Slicer.cs +++ b/MatterControlLib/SlicerConfiguration/Slicer.cs @@ -95,7 +95,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++) { - IEnumerable itemsThisExtruder = GetItemsForExtruder(printableItems, extruderCount, extruderIndex, checkForMeshFile); + IEnumerable itemsThisExtruder = GetSolidsForExtruder(printableItems, extruderCount, extruderIndex, checkForMeshFile); extrudersUsed[extruderIndex] |= itemsThisExtruder.Any(); } } @@ -118,15 +118,34 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return false; } - public static IEnumerable GetItemsForExtruder(IEnumerable meshItemsOnBuildPlate, int extruderCount, int extruderIndex, bool checkForMeshFile) + public static IEnumerable GetSolidsForExtruder(IEnumerable meshItemsOnBuildPlate, int extruderCount, int extruderIndex, bool checkForMeshFile) { var itemsThisExtruder = meshItemsOnBuildPlate.Where((item) => - (!checkForMeshFile || (File.Exists(item.MeshPath) // Drop missing files - || File.Exists(Path.Combine(Object3D.AssetsPath, item.MeshPath)))) - && (item.WorldMaterialIndex() == extruderIndex - || (extruderIndex == 0 - && (item.WorldMaterialIndex() >= extruderCount || item.WorldMaterialIndex() == -1))) - && (item.WorldOutputType() == PrintOutputTypes.Solid || item.WorldOutputType() == PrintOutputTypes.Default)); + { + var outputType = item.WorldOutputType(); + var material = item.WorldMaterialIndex(); + + return (!checkForMeshFile + || File.Exists(item.MeshPath) // Drop missing files + || File.Exists(Path.Combine(Object3D.AssetsPath, item.MeshPath))) + && (material == extruderIndex || (extruderIndex == 0 && (material >= extruderCount || material == -1))) + && (outputType == PrintOutputTypes.Solid || outputType == PrintOutputTypes.Default); + }); + + return itemsThisExtruder; + } + + public static IEnumerable GetAllHoles(IEnumerable meshItemsOnBuildPlate) + { + var itemsThisExtruder = meshItemsOnBuildPlate.Where((item) => + { + var outputType = item.WorldOutputType(); + var material = item.WorldMaterialIndex(); + + return (File.Exists(item.MeshPath) // Drop missing files + || File.Exists(Path.Combine(Object3D.AssetsPath, item.MeshPath))) + && outputType == PrintOutputTypes.Hole; + }); return itemsThisExtruder; } diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index e754c8142..9578a32e7 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit e754c81428db89bb94fadac23f026de7579bff8f +Subproject commit 9578a32e7032236c2ff7fc1a588c6d099eec333d diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 444ce5470..9e115e537 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 444ce54704973489addef582e27353a0f84b59ac +Subproject commit 9e115e5373d44f9cc7fdcee0e3290b1e88c39970