improving csg subtract

This commit is contained in:
LarsBrubaker 2021-07-22 10:02:43 -07:00 committed by Lars Brubaker
parent 9142b4a942
commit 5f8edfb500
3 changed files with 70 additions and 16 deletions

View file

@ -147,7 +147,10 @@ namespace MatterHackers.PolygonMesh
var implicitMeshs = new List<BoundedImplicitFunction3d>();
foreach (var item in items)
{
implicitMeshs.Add(GetImplicitFunction(item.mesh, item.matrix, processingMode == ProcessingModes.Polygons, 1 << (int)inputResolution));
var meshCopy = item.mesh.Copy(CancellationToken.None);
meshCopy.Transform(item.matrix);
implicitMeshs.Add(GetImplicitFunction(meshCopy, processingMode == ProcessingModes.Polygons, 1 << (int)inputResolution));
}
DMesh3 GenerateMeshF(BoundedImplicitFunction3d root, int numCells)
@ -396,17 +399,23 @@ namespace MatterHackers.PolygonMesh
}
else
{
if (inMeshA.Faces.Count < 4)
var meshA = inMeshA.Copy(CancellationToken.None);
meshA.Transform(matrixA);
var meshB = inMeshB.Copy(CancellationToken.None);
meshB.Transform(matrixB);
if (meshA.Faces.Count < 4)
{
return inMeshB;
return meshB;
}
else if (inMeshB.Faces.Count > 4)
else if (meshB.Faces.Count < 4)
{
return inMeshA;
return meshA;
}
var implicitA = GetImplicitFunction(inMeshA, matrixA, processingMode == ProcessingModes.Polygons, (int)inputResolution);
var implicitB = GetImplicitFunction(inMeshB, matrixB, processingMode == ProcessingModes.Polygons, (int)inputResolution);
var implicitA = GetImplicitFunction(inMeshA, processingMode == ProcessingModes.Polygons, (int)inputResolution);
var implicitB = GetImplicitFunction(inMeshB, processingMode == ProcessingModes.Polygons, (int)inputResolution);
DMesh3 GenerateMeshF(BoundedImplicitFunction3d root, int numCells)
{
@ -468,12 +477,9 @@ namespace MatterHackers.PolygonMesh
}
public static BoundedImplicitFunction3d GetImplicitFunction(Mesh mesh, Matrix4X4 matrix, bool exact, int numCells)
public static BoundedImplicitFunction3d GetImplicitFunction(Mesh mesh, bool exact, int numCells)
{
var meshCopy = mesh.Copy(CancellationToken.None);
meshCopy.Transform(matrix);
var meshA3 = meshCopy.ToDMesh3();
var meshA3 = mesh.ToDMesh3();
// Interesting experiment, this produces an extremely accurate surface representation but is quite slow (even though fast) compared to voxel lookups.
if (exact)

@ -1 +1 @@
Subproject commit f2c5f1365f0f30010ff36a64af8dccea4d471163
Subproject commit e519298ff2a1464dcf135827245e078f83251a73

View file

@ -1,4 +1,6 @@
using System.Threading;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
@ -16,12 +18,16 @@ namespace MatterHackers.MatterControl.Tests.Automation
[TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)]
public class PrimitiveAndSheetsTests
{
[Test]
public void SheetEditorLayoutAndNavigation()
[SetUp]
public void TestSetup()
{
StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData");
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
}
[Test]
public void SheetEditorLayoutAndNavigation()
{
var systemWindow = new SystemWindow(800, 600)
{
Name = "Main Window",
@ -158,5 +164,47 @@ namespace MatterHackers.MatterControl.Tests.Automation
return Task.CompletedTask;
}, overrideWidth: 1300, maxTimeToRun: 60);
}
[Test]
public void SheetEditorNavigationTests()
{
var systemWindow = new SystemWindow(800, 600)
{
Name = "Main Window",
};
Application.AddTextWidgetRightClickMenu();
AutomationRunner.TimeToMoveMouse = .1;
var theme = ApplicationController.Instance.Theme;
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Stretch,
};
systemWindow.AddChild(container);
var sheetData = new SheetData(5, 5);
var undoBuffer = new UndoBuffer();
var sheetEditorWidget = new SheetEditorWidget(sheetData, undoBuffer, theme);
container.AddChild(sheetEditorWidget);
systemWindow.RunTest(testRunner =>
{
testRunner.Delay(60);
return Task.CompletedTask;
},
2000);
}
}
public static class RunnerX
{
public static Task RunTest(this SystemWindow systemWindow, AutomationTest automationTest, int timeout)
{
return AutomationRunner.ShowWindowAndExecuteTests(systemWindow, automationTest, timeout);
}
}
}