Moved raytracer code into polygon mesh

This commit is contained in:
LarsBrubaker 2021-11-21 07:09:33 -08:00
parent f01f1604b9
commit 25d941f634
6 changed files with 75 additions and 69 deletions

View file

@ -535,15 +535,15 @@ namespace MatterHackers.PolygonMesh
Matrix4X4 matrixB,
// operation
CsgModes operation,
ProcessingModes processingMode,
ProcessingResolution inputResolution,
ProcessingResolution outputResolution,
ProcessingModes processingMode = ProcessingModes.Polygons,
ProcessingResolution inputResolution = ProcessingResolution._64,
ProcessingResolution outputResolution = ProcessingResolution._64,
// reporting
IProgress<ProgressStatus> reporter,
double amountPerOperation,
double percentCompleted,
ProgressStatus progressStatus,
CancellationToken cancellationToken)
IProgress<ProgressStatus> reporter = null,
double amountPerOperation = 1,
double percentCompleted = 0,
ProgressStatus progressStatus = null,
CancellationToken cancellationToken = default(CancellationToken))
{
bool externalAssemblyExists = File.Exists(BooleanAssembly);
if (processingMode == ProcessingModes.Polygons)

View file

@ -93,59 +93,74 @@ namespace MatterHackers.PolygonMesh
}
public void SubtractFaces(Plane plane, List<Mesh> transformedMeshes, Mesh resultsMesh, Matrix4X4 flattenedMatrix, HashSet<int> faceIndicesToRemove)
{
// get all meshes that have faces on this plane
var meshesWithFaces = MeshIndicesForPlane(plane).ToList();
{
// get all meshes that have faces on this plane
var meshesWithFaces = MeshIndicesForPlane(plane).ToList();
// we need more than one mesh and one of them needs to be the source (mesh 0)
if (meshesWithFaces.Count < 2
|| !meshesWithFaces.Contains(0))
{
// no faces to add
return;
}
// we need more than one mesh and one of them needs to be the source (mesh 0)
if (meshesWithFaces.Count < 2
|| !meshesWithFaces.Contains(0))
{
// no faces to add
return;
}
// sort them so we can process each group into intersections
meshesWithFaces.Sort();
// sort them so we can process each group into intersections
meshesWithFaces.Sort();
// add the faces that we should
foreach (var meshIndex in meshesWithFaces)
{
foreach (var faces in FacesSetsForPlaneAndMesh(plane, meshIndex))
{
faceIndicesToRemove.Add(faces.destFaceIndex);
}
}
// add the faces that we should
foreach (var meshIndex in meshesWithFaces)
{
foreach (var faces in FacesSetsForPlaneAndMesh(plane, meshIndex))
{
faceIndicesToRemove.Add(faces.destFaceIndex);
}
}
// subtract every face from the mesh 0 faces
// teselate and add what is left
var keepPolygons = new Polygons();
foreach (var keepFaceSets in FacesSetsForPlaneAndMesh(plane, 0))
{
keepPolygons = keepPolygons.Union(GetFacePolygon(transformedMeshes[0], keepFaceSets.sourceFaceIndex, flattenedMatrix));
}
// subtract every face from the mesh 0 faces
// teselate and add what is left
var keepPolygons = new Polygons();
foreach (var keepFaceSets in FacesSetsForPlaneAndMesh(plane, 0))
{
var facePolygon = GetFacePolygon(transformedMeshes[0], keepFaceSets.sourceFaceIndex, flattenedMatrix);
keepPolygons = keepPolygons.Union(facePolygon);
}
// iterate all the meshes that need to be subtracted
var removePoygons = new Polygons();
for (int removeMeshIndex = 1; removeMeshIndex < meshesWithFaces.Count; removeMeshIndex++)
{
foreach (var removeFaceSets in FacesSetsForPlaneAndMesh(plane, removeMeshIndex))
{
removePoygons = removePoygons.Union(GetFacePolygon(transformedMeshes[removeMeshIndex], removeFaceSets.sourceFaceIndex, flattenedMatrix));
}
}
// iterate all the meshes that need to be subtracted
var removePoygons = new Polygons();
for (int removeMeshIndex = 1; removeMeshIndex < meshesWithFaces.Count; removeMeshIndex++)
{
foreach (var removeFaceSets in FacesSetsForPlaneAndMesh(plane, removeMeshIndex))
{
removePoygons = removePoygons.Union(GetFacePolygon(transformedMeshes[removeMeshIndex], removeFaceSets.sourceFaceIndex, flattenedMatrix));
}
}
var polygonShape = new Polygons();
var clipper = new Clipper();
clipper.AddPaths(keepPolygons, PolyType.ptSubject, true);
clipper.AddPaths(removePoygons, PolyType.ptClip, true);
clipper.Execute(ClipType.ctDifference, polygonShape);
var polygonShape = new Polygons();
var clipper = new Clipper();
clipper.AddPaths(keepPolygons, PolyType.ptSubject, true);
clipper.AddPaths(removePoygons, PolyType.ptClip, true);
clipper.Execute(ClipType.ctDifference, polygonShape);
// teselate and add all the new polygons
polygonShape.Vertices(1).TriangulateFaces(null, resultsMesh, 0, flattenedMatrix.Inverted);
}
// teselate and add all the new polygons
var countPreAdd = resultsMesh.Faces.Count;
polygonShape.Vertices(1).TriangulateFaces(null, resultsMesh, 0, flattenedMatrix.Inverted);
EnsureFaceNormals(plane, resultsMesh, countPreAdd);
}
public void IntersectFaces(Plane plane, List<Mesh> transformedMeshes, Mesh resultsMesh, Matrix4X4 flattenedMatrix, HashSet<int> faceIndicesToRemove)
private static void EnsureFaceNormals(Plane plane, Mesh resultsMesh, int countPreAdd)
{
// Check that the new face normals are pointed in the right direction
if ((new Vector3(resultsMesh.Faces[countPreAdd].normal) - plane.Normal).LengthSquared > .1)
{
for (int i = countPreAdd; i < resultsMesh.Faces.Count; i++)
{
resultsMesh.FlipFace(i);
}
}
}
public void IntersectFaces(Plane plane, List<Mesh> transformedMeshes, Mesh resultsMesh, Matrix4X4 flattenedMatrix, HashSet<int> faceIndicesToRemove)
{
// get all meshes that have faces on this plane
var meshesWithFaces = MeshIndicesForPlane(plane).ToList();
@ -192,7 +207,9 @@ namespace MatterHackers.PolygonMesh
}
// teselate and add all the new polygons
var countPreAdd = resultsMesh.Faces.Count;
total.Vertices(1).TriangulateFaces(null, resultsMesh, 0, flattenedMatrix.Inverted);
EnsureFaceNormals(plane, resultsMesh, countPreAdd);
}
public void UnionFaces(Plane plane, List<Mesh> transformedMeshes, Mesh resultsMesh, Matrix4X4 flattenedMatrix)
@ -254,7 +271,9 @@ namespace MatterHackers.PolygonMesh
}
// teselate and add all the new polygons
var countPreAdd = resultsMesh.Faces.Count;
totalSlices.Vertices(1).TriangulateFaces(null, resultsMesh, 0, flattenedMatrix.Inverted);
EnsureFaceNormals(plane, resultsMesh, countPreAdd);
}
public void StoreFaceAdd(PlaneNormalXSorter planeSorter,

View file

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28516.95
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tesselate", "Submodules\agg-sharp\Tesselate\Tesselate.csproj", "{AE37DE1F-22F7-49EE-8732-FC6BC8DC58D9}"
EndProject
@ -26,8 +26,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agg", "Submodules\agg-sharp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.CsharpSqlite", "Community.CsharpSqlite\Community.CsharpSqlite.csproj", "{F1653F20-D47D-4F29-8C55-3C835542AF5F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RayTracer", "Submodules\agg-sharp\RayTracer\RayTracer.csproj", "{1E01ABE0-B494-4FE4-B0D6-540133286887}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Localizations", "Submodules\agg-sharp\Localizations\Localizations.csproj", "{CA96058C-1A37-465D-A357-D6D695B13D25}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageProcessing", "Submodules\agg-sharp\ImageProcessing\ImageProcessing.csproj", "{036BCCBA-52D8-457C-84AE-8821F209FE4A}"
@ -204,14 +202,6 @@ Global
{F1653F20-D47D-4F29-8C55-3C835542AF5F}.Release|Any CPU.Build.0 = Release|Any CPU
{F1653F20-D47D-4F29-8C55-3C835542AF5F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F1653F20-D47D-4F29-8C55-3C835542AF5F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Release|Any CPU.Build.0 = Release|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1E01ABE0-B494-4FE4-B0D6-540133286887}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CA96058C-1A37-465D-A357-D6D695B13D25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA96058C-1A37-465D-A357-D6D695B13D25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA96058C-1A37-465D-A357-D6D695B13D25}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -522,7 +512,6 @@ Global
{86F6AAF2-9B50-40B8-A427-1897D76471C5} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}
{657DBC6D-C3EA-4398-A3FA-DDB73C14F71B} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}
{F1653F20-D47D-4F29-8C55-3C835542AF5F} = {FED00F38-E911-45E1-A788-26980E84C3D6}
{1E01ABE0-B494-4FE4-B0D6-540133286887} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}
{CA96058C-1A37-465D-A357-D6D695B13D25} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}
{036BCCBA-52D8-457C-84AE-8821F209FE4A} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}
{9B062971-A88E-4A3D-B3C9-12B78D15FA66} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}

View file

@ -74,7 +74,6 @@
<ProjectReference Include="..\Submodules\agg-sharp\ImageProcessing\ImageProcessing.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\MarchingSquares\MarchingSquares.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\MeshThumbnails\MeshThumbnails\MeshThumbnails.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\RayTracer\RayTracer.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\VectorMath\VectorMath.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\Tesselate\Tesselate.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\RenderOpenGl\RenderOpenGl.csproj" />

@ -1 +1 @@
Subproject commit 5ede7a0c6ae538b73eddf77195805d239c497064
Subproject commit a2677435dc039e3480e7ac31e70b16e4becc6e7f

View file

@ -47,7 +47,6 @@ namespace MatterControl.Tests
Gui.dll
Tesselate.dll
DataConverters2D.dll
RayTracer.dll
DataConverters3D.dll
Localizations.dll
Community.CsharpSqlite.dll