Make mesh merge on export an option

This commit is contained in:
LarsBrubaker 2022-08-14 20:51:01 -07:00
parent 9e2aad8651
commit 33cb9dafd2
8 changed files with 60 additions and 12 deletions

View file

@ -156,7 +156,7 @@ namespace MatterHackers.MatterControl
if (plugin is IExportWithOptions pluginWithOptions)
{
var optionPanel = pluginWithOptions.GetOptionsPanel();
var optionPanel = pluginWithOptions.GetOptionsPanel(libraryItems);
if (optionPanel != null)
{
optionPanel.HAnchor = HAnchor.Stretch;

View file

@ -57,7 +57,7 @@ namespace MatterHackers.MatterControl.Library.Export
var firstItem = libraryItems.OfType<ILibraryAsset>().FirstOrDefault();
if (firstItem is ILibraryAsset libraryItem)
{
bool exportSuccessful = await MeshExport.ExportMesh(libraryItem, outputPath, progress);
bool exportSuccessful = await MeshExport.ExportMesh(libraryItem, outputPath, true, progress);
if (exportSuccessful)
{
return null;

View file

@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.Library.Export
public virtual bool ExportPossible(ILibraryAsset libraryItem) => true;
public GuiWidget GetOptionsPanel()
public GuiWidget GetOptionsPanel(IEnumerable<ILibraryItem> libraryItems)
{
var container = new FlowLayoutWidget()
{
@ -132,7 +132,7 @@ namespace MatterHackers.MatterControl.Library.Export
}
else
{
spiralVaseOverride = SpiralVaseOptions.FORCE_ON;
spiralVaseOverride = SpiralVaseOptions.USE_SETTINGS;
}
};
container.AddChild(spiralVaseCheckbox);

View file

@ -62,6 +62,6 @@ namespace MatterHackers.MatterControl
public interface IExportWithOptions : IExportPlugin
{
GuiWidget GetOptionsPanel();
GuiWidget GetOptionsPanel(IEnumerable<ILibraryItem> libraryItems);
}
}

View file

@ -40,7 +40,7 @@ namespace MatterHackers.MatterControl.Library.Export
{
public static class MeshExport
{
public static async Task<bool> ExportMesh(ILibraryItem source, string filePathToSave, IProgress<ProgressStatus> progress)
public static async Task<bool> ExportMesh(ILibraryItem source, string filePathToSave, bool mergeMeshes, IProgress<ProgressStatus> progress)
{
try
{
@ -53,7 +53,7 @@ namespace MatterHackers.MatterControl.Library.Export
{
// If the content is an IObject3D, then we need to load it and MeshFileIO save to the target path
var content = await contentItem.GetObject3D(null);
return Object3D.Save(content, filePathToSave, CancellationToken.None, reportProgress: (ratio, name) =>
return Object3D.Save(content, filePathToSave, mergeMeshes, CancellationToken.None, reportProgress: (ratio, name) =>
{
status.Progress0To1 = ratio;
progress.Report(status);
@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.Library.Export
IObject3D item = Object3D.Load(result.Stream, Path.GetExtension(streamContent.FileName), CancellationToken.None);
if (item != null)
{
return Object3D.Save(item, filePathToSave, CancellationToken.None, reportProgress: (ratio, name) =>
return Object3D.Save(item, filePathToSave, mergeMeshes, CancellationToken.None, reportProgress: (ratio, name) =>
{
status.Progress0To1 = ratio;
progress.Report(status);

View file

@ -37,13 +37,16 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
namespace MatterHackers.MatterControl.Library.Export
{
public class StlExport : IExportPlugin
public class StlExport : IExportPlugin, IExportWithOptions
{
public int Priority => 2;
private bool mergeMeshes = true;
public int Priority => 2;
public string ButtonText => "STL File".Localize();
@ -79,7 +82,7 @@ namespace MatterHackers.MatterControl.Library.Export
first = false;
}
if (!await MeshExport.ExportMesh(item, filename, progress))
if (!await MeshExport.ExportMesh(item, filename, mergeMeshes, progress))
{
badExports.Add(item.Name);
}
@ -99,5 +102,44 @@ namespace MatterHackers.MatterControl.Library.Export
}
};
}
public GuiWidget GetOptionsPanel(IEnumerable<ILibraryItem> libraryItems)
{
var exportMeshCount = 0;
foreach (var item in libraryItems.OfType<ILibraryAsset>())
{
if (item is ILibraryObject3D contentItem)
{
var object3D = contentItem.GetObject3D(null).Result;
exportMeshCount += object3D.VisibleMeshes().Count();
}
}
if (exportMeshCount < 2)
{
return null;
}
var container = new FlowLayoutWidget()
{
Margin = new BorderDouble(left: 40, bottom: 10),
};
var theme = AppContext.Theme;
var unionAllPartsCheckbox = new CheckBox("Merge faces into single mesh".Localize(), theme.TextColor, 10)
{
Checked = true,
Cursor = Cursors.Hand,
ToolTipText = "Disable to expart all faces without merging".Localize()
};
unionAllPartsCheckbox.CheckedStateChanged += (s, e) =>
{
mergeMeshes = unionAllPartsCheckbox.Checked;
};
container.AddChild(unionAllPartsCheckbox);
return container;
}
}
}

View file

@ -1327,6 +1327,9 @@ Translated:Direction
English:Disable Fan For The First
Translated:Disable Fan For The First
English:Disable to expart all faces without merging
Translated:Disable to expart all faces without merging
English:Disabled: {0}
Translated:Disabled: {0}
@ -2887,6 +2890,9 @@ Translated:Medium Precision
English:Merge
Translated:Merge
English:Merge faces into single mesh
Translated:Merge faces into single mesh
English:Merge Overlapping Lines
Translated:Merge Overlapping Lines

@ -1 +1 @@
Subproject commit 837ccc782954724ae26d080a9b063112a70a527b
Subproject commit 0fee6ab0d2d61107717114258b06182815bc11d7