Make sure that added vertices are aligned when possible with source vertices
This commit is contained in:
parent
ce314d51f3
commit
d4655f2d20
2 changed files with 31 additions and 4 deletions
|
|
@ -35,6 +35,7 @@ using ClipperLib;
|
|||
using MatterHackers.Agg;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.PolygonMesh.Csg;
|
||||
using MatterHackers.PolygonMesh.Processors;
|
||||
using MatterHackers.RayTracer;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
|
|
@ -197,11 +198,37 @@ namespace MatterHackers.PolygonMesh
|
|||
var preAddCount = resultsMesh.Vertices.Count;
|
||||
// mesh the new polygon and add it to the resultsMesh
|
||||
polygonShape.Vertices(1).TriangulateFaces(null, resultsMesh, 0, transformTo0Planes[cutPlane].inverted);
|
||||
var postAddCount = resultsMesh.Vertices.Count;
|
||||
|
||||
// TODO: map all the added vertices that can be back to the original polygon positions
|
||||
// for (int i = preAddCount; i< resultsMesh.Vertices.Count; i++)
|
||||
for (int addedIndex = preAddCount; addedIndex < postAddCount; addedIndex++)
|
||||
{
|
||||
|
||||
// TODO: map all the added vertices that can be back to the original polygon positions
|
||||
for (int meshIndex = 0; meshIndex < transformedMeshes.Count; meshIndex++)
|
||||
{
|
||||
var bvhAccelerator = bvhAccelerators[meshIndex];
|
||||
var mesh = transformedMeshes[meshIndex];
|
||||
var addedPosition = resultsMesh.Vertices[addedIndex];
|
||||
var touchingBvhItems = bvhAccelerator.GetTouching(new Vector3(addedPosition), .0001);
|
||||
foreach (var touchingBvhItem in touchingBvhItems)
|
||||
{
|
||||
if (touchingBvhItem is TriangleShape triangleShape)
|
||||
{
|
||||
var sourceFaceIndex = triangleShape.Index;
|
||||
var sourceFace = mesh.Faces[sourceFaceIndex];
|
||||
var sourceVertexIndices = new int[] { sourceFace.v0, sourceFace.v1, sourceFace.v2 };
|
||||
foreach (var sourceVertexIndex in sourceVertexIndices)
|
||||
{
|
||||
var sourcePosition = mesh.Vertices[sourceVertexIndex];
|
||||
var deltaSquared = (addedPosition - sourcePosition).LengthSquared;
|
||||
if (deltaSquared > 0 && deltaSquared < .00001)
|
||||
{
|
||||
// add the vertex and set the face position index to the new vertex
|
||||
resultsMesh.Vertices[addedIndex] = sourcePosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 6fc94acc7d613a118642aa909c05efbcbed76655
|
||||
Subproject commit 66f77f1cd52f85b7ac3ac6b8e711ad01f32519c5
|
||||
Loading…
Add table
Add a link
Reference in a new issue