本文整理汇总了C#中Mesh.CreateVertex方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.CreateVertex方法的具体用法?C# Mesh.CreateVertex怎么用?C# Mesh.CreateVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.CreateVertex方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWireFrameTriangle
public void CreateWireFrameTriangle()
{
Mesh testMesh = new Mesh();
Vertex leftVertexBottom = testMesh.CreateVertex(-1, 0, 0);
Vertex rightVertexBottom = testMesh.CreateVertex(1, 0, 0);
Vertex centerVertexTop = testMesh.CreateVertex(0, 0, 2);
// create the first mesh edge and check stuff
MeshEdge meshEdge0 = testMesh.CreateMeshEdge(leftVertexBottom, rightVertexBottom);
Assert.IsTrue(meshEdge0.VertexOnEnd[0] == leftVertexBottom);
Assert.IsTrue(meshEdge0.firstFaceEdge == null);
Assert.IsTrue(meshEdge0.NextMeshEdgeFromEnd[0] == meshEdge0.NextMeshEdgeFromEnd[1]);
Assert.IsTrue(meshEdge0.NextMeshEdgeFromEnd[0] == meshEdge0);
Assert.IsTrue(meshEdge0.VertexOnEnd[1] == rightVertexBottom);
Assert.IsTrue(meshEdge0.NextMeshEdgeFromEnd[1] == meshEdge0);
// create the second mesh edge and check stuff
MeshEdge meshEdge1 = testMesh.CreateMeshEdge(rightVertexBottom, centerVertexTop);
Assert.IsTrue(meshEdge0.VertexOnEnd[0] == leftVertexBottom);
Assert.IsTrue(meshEdge0.firstFaceEdge == null);
Assert.IsTrue(meshEdge0.NextMeshEdgeFromEnd[0] == meshEdge0);
Assert.IsTrue(meshEdge0.VertexOnEnd[1] == rightVertexBottom);
Assert.IsTrue(meshEdge0.NextMeshEdgeFromEnd[1] == meshEdge1);
Assert.IsTrue(meshEdge1.VertexOnEnd[0] == rightVertexBottom);
Assert.IsTrue(meshEdge1.firstFaceEdge == null);
Assert.IsTrue(meshEdge1.NextMeshEdgeFromEnd[0] == meshEdge0);
Assert.IsTrue(meshEdge1.VertexOnEnd[1] == centerVertexTop);
Assert.IsTrue(meshEdge1.NextMeshEdgeFromEnd[1] == meshEdge1);
// create the third mesh edge and test
MeshEdge meshEdge2 = testMesh.CreateMeshEdge(centerVertexTop, leftVertexBottom);
Assert.IsTrue(meshEdge0.VertexOnEnd[0] == leftVertexBottom);
Assert.IsTrue(meshEdge0.VertexOnEnd[1] == rightVertexBottom);
Assert.IsTrue(meshEdge0.firstFaceEdge == null);
Assert.IsTrue(meshEdge0.NextMeshEdgeFromEnd[0] == meshEdge2);
Assert.IsTrue(meshEdge0.NextMeshEdgeFromEnd[1] == meshEdge1);
Assert.IsTrue(meshEdge1.VertexOnEnd[0] == rightVertexBottom);
Assert.IsTrue(meshEdge1.VertexOnEnd[1] == centerVertexTop);
Assert.IsTrue(meshEdge1.firstFaceEdge == null);
Assert.IsTrue(meshEdge1.NextMeshEdgeFromEnd[0] == meshEdge0);
Assert.IsTrue(meshEdge1.NextMeshEdgeFromEnd[1] == meshEdge2);
Assert.IsTrue(meshEdge2.VertexOnEnd[0] == centerVertexTop);
Assert.IsTrue(meshEdge2.VertexOnEnd[1] == leftVertexBottom);
Assert.IsTrue(meshEdge2.firstFaceEdge == null);
Assert.IsTrue(meshEdge2.NextMeshEdgeFromEnd[0] == meshEdge1);
Assert.IsTrue(meshEdge2.NextMeshEdgeFromEnd[1] == meshEdge0);
SaveDebugInfo(testMesh);
}
示例2: SortAndQueryWork
public void SortAndQueryWork()
{
double size = 10;
double increment = 1;
Random positionRand = new Random();
Mesh mesh = new Mesh();
List<Vector3Float> positions = new List<Vector3Float>();
int numPosition = 50;
for (int i = 0; i < numPosition; i++)
{
positions.Add(new Vector3Float(positionRand.NextDouble() * size, positionRand.NextDouble() * size, positionRand.NextDouble() * size));
mesh.CreateVertex(new Vector3(positions[i].x, positions[i].y, positions[i].z), CreateOption.CreateNew, SortOption.WillSortLater);
}
mesh.SortVertices();
for (double distance = 0; distance < size; distance += increment)
{
for (int i = 0; i < numPosition; i++)
{
List<Vertex> found1 = mesh.FindVertices(new Vector3(positions[i].x, positions[i].y, positions[i].z), distance);
List<Vector3Float> found2 = FindWithinDist(positions, positions[i], distance);
Assert.IsTrue(found1.Count == found2.Count);
}
}
}
示例3: MeshFromPolygons
public static Mesh MeshFromPolygons(List<CsgPolygon> polygons)
{
Mesh model = new Mesh();
HashSet<PolygonMesh.Vertex> vertices = new HashSet<PolygonMesh.Vertex>();
for (int polygonIndex = 0; polygonIndex < polygons.Count; polygonIndex++)
{
CsgPolygon poly = polygons[polygonIndex];
vertices.Clear();
for (int vertexIndex = 0; vertexIndex < poly.vertices.Count; vertexIndex++)
{
vertices.Add(model.CreateVertex(poly.vertices[vertexIndex].Position));
}
if (vertices.Count > 2)
{
model.CreateFace(vertices.ToArray());
}
}
return model;
}
示例4: MeshCopy
public void MeshCopy()
{
{
Mesh testMesh = new Mesh();
Vertex left = testMesh.CreateVertex(-1, -1, 0);
Vertex middle = testMesh.CreateVertex(0, 1, 0);
Vertex right = testMesh.CreateVertex(1, -1, 0);
Vertex top = testMesh.CreateVertex(0, 0, 1);
testMesh.CreateFace(new Vertex[] { left, top, middle });
testMesh.CreateFace(new Vertex[] { left, right, top });
testMesh.CreateFace(new Vertex[] { right, middle, top });
testMesh.CreateFace(new Vertex[] { left, middle, right });
testMesh.MergeVertices();
MeshFileIo.Save(testMesh, "control.stl", new MeshOutputSettings(MeshOutputSettings.OutputType.Ascii));
SaveDebugInfo(testMesh, "MeshCopy (orig)");
Mesh copyMesh = Mesh.Copy(testMesh);
MeshFileIo.Save(testMesh, "test.stl", new MeshOutputSettings(MeshOutputSettings.OutputType.Ascii));
SaveDebugInfo(copyMesh, "MeshCopy (copy)");
Mesh copyMesh2 = Mesh.Copy(copyMesh);
MeshFileIo.Save(copyMesh2, "test2.stl", new MeshOutputSettings(MeshOutputSettings.OutputType.Ascii));
SaveDebugInfo(copyMesh, "MeshCopy (copy2)");
}
}
示例5: MeshEdgeSplitAndUnsplitTests
public void MeshEdgeSplitAndUnsplitTests()
{
// split edge and create vert (not part of a polygon, just a wire mesh)
{
Mesh testMesh = new Mesh();
Vertex leftVertex = testMesh.CreateVertex(-1, 0, 0);
Vertex rightVertex = testMesh.CreateVertex(1, 0, 0);
MeshEdge edgeToSplit = testMesh.CreateMeshEdge(leftVertex, rightVertex);
Assert.IsTrue(edgeToSplit.VertexOnEnd[0] == leftVertex, "The edgeToSplit is connected the way we expect.");
Assert.IsTrue(edgeToSplit.VertexOnEnd[1] == rightVertex, "The edgeToSplit is connected the way we expect.");
Assert.IsTrue(leftVertex.firstMeshEdge == edgeToSplit, "First edge of left vertex is the edge.");
Assert.IsTrue(rightVertex.firstMeshEdge == edgeToSplit, "First edge of right vertex is the edge.");
MeshEdge edgeCreatedDuringSplit;
Vertex vertexCreatedDuringSplit;
testMesh.SplitMeshEdge(edgeToSplit, out vertexCreatedDuringSplit, out edgeCreatedDuringSplit);
Assert.IsTrue(edgeToSplit.VertexOnEnd[1] == vertexCreatedDuringSplit);
Assert.IsTrue(edgeToSplit.NextMeshEdgeFromEnd[0] == edgeToSplit);
Assert.IsTrue(edgeToSplit.NextMeshEdgeFromEnd[1] == edgeCreatedDuringSplit);
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[0] == vertexCreatedDuringSplit, "The edgeCreatedDuringSplit is connected the way we expect.");
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[1] == rightVertex, "The edgeCreatedDuringSplit is connected the way we expect.");
Assert.IsTrue(vertexCreatedDuringSplit.firstMeshEdge == edgeCreatedDuringSplit, "First edge of new vertex is the edge we split.");
Assert.IsTrue(edgeCreatedDuringSplit.NextMeshEdgeFromEnd[0] == edgeToSplit, "The next edge is the one we created.");
Assert.IsTrue(edgeCreatedDuringSplit.NextMeshEdgeFromEnd[1] == edgeCreatedDuringSplit, "The other side is connected to itself.");
testMesh.UnsplitMeshEdge(edgeToSplit, vertexCreatedDuringSplit);
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[0] == null && edgeCreatedDuringSplit.VertexOnEnd[1] == null, "The edgeCreatedDuringSplit is no longer connected to Vertices.");
Assert.IsTrue(edgeToSplit.VertexOnEnd[0] == leftVertex, "The unsplit edge is connected back the way it was.");
Assert.IsTrue(edgeToSplit.VertexOnEnd[1] == rightVertex, "The unsplit edge is connected back the way it was.");
}
// split a polygon's edge and create vert
{
Mesh testMesh = new Mesh();
Vertex leftVertex = testMesh.CreateVertex(-1, 0, 1);
Vertex rightVertex = testMesh.CreateVertex(1, 0, 1);
Vertex topVertex = testMesh.CreateVertex(-1, 0, -1);
Face newFace = testMesh.CreateFace(new Vertex[] { rightVertex, topVertex, leftVertex });
Assert.IsTrue(newFace.normal == Vector3.UnitY);
Assert.IsTrue(newFace.NumVertices == 3, "We have a 3 vertex face.");
Assert.IsTrue(newFace.FaceEdgeLoopIsGood());
MeshEdge edgeToSplit = testMesh.FindMeshEdges(leftVertex, rightVertex)[0];
Assert.IsTrue(edgeToSplit.VertexOnEnd[0] == leftVertex, "The edgeToSplit is connected the way we expect.");
Assert.IsTrue(edgeToSplit.VertexOnEnd[1] == rightVertex, "The edgeToSplit is connected the way we expect.");
MeshEdge edgeCreatedDuringSplit;
Vertex vertexCreatedDuringSplit;
SaveDebugInfo(testMesh);
testMesh.SplitMeshEdge(edgeToSplit, out vertexCreatedDuringSplit, out edgeCreatedDuringSplit);
SaveDebugInfo(testMesh);
Assert.IsTrue(newFace.NumVertices == 4, "After SplitEdge it is a 4 vertex face.");
Assert.IsTrue(newFace.FaceEdgeLoopIsGood());
Assert.IsTrue(edgeCreatedDuringSplit.firstFaceEdge != null, "First face edge is connected.");
Assert.IsTrue(edgeCreatedDuringSplit.firstFaceEdge.meshEdge == edgeCreatedDuringSplit, "The new face edge is connected to the created mesh edge.");
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[0] != null && edgeCreatedDuringSplit.VertexOnEnd[1] != null, "The edgeCreatedDuringSplit is connected to Vertices.");
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[0].GetConnectedMeshEdges().Contains(edgeCreatedDuringSplit), "The vertex connected to this mesh edege contains this mesh edge.");
//Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[1].GetConnectedMeshEdges().Contains(edgeCreatedDuringSplit), "The vertex connected to this mesh edege contains this mesh edge.");
testMesh.UnsplitMeshEdge(edgeToSplit, vertexCreatedDuringSplit);
Assert.IsTrue(newFace.FaceEdgeLoopIsGood());
Assert.IsTrue(newFace.NumVertices == 3, "Back to 3 after UnsplitEdge.");
Assert.IsTrue(edgeCreatedDuringSplit.firstFaceEdge == null, "First face edge is disconnected.");
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[0] == null && edgeCreatedDuringSplit.VertexOnEnd[1] == null, "The edgeCreatedDuringSplit is no longer connected to Vertices.");
Assert.IsTrue(edgeToSplit.VertexOnEnd[0] == leftVertex, "The unsplit edge is connected back the way it was.");
Assert.IsTrue(edgeToSplit.VertexOnEnd[1] == rightVertex, "The unsplit edge is connected back the way it was.");
// split again then unsplit the created edge rather than the original edge
testMesh.SplitMeshEdge(edgeToSplit, out vertexCreatedDuringSplit, out edgeCreatedDuringSplit);
testMesh.UnsplitMeshEdge(edgeCreatedDuringSplit, vertexCreatedDuringSplit);
Assert.IsTrue(newFace.FaceEdgeLoopIsGood());
Assert.IsTrue(newFace.NumVertices == 3, "Back to 3 after UnsplitEdge.");
Assert.IsTrue(edgeToSplit.firstFaceEdge == null, "First face edge is disconnected.");
Assert.IsTrue(edgeToSplit.VertexOnEnd[0] == null && edgeToSplit.VertexOnEnd[1] == null, "The edgeToSplit is no longer connected to Vertices.");
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[0] == leftVertex, "The unsplit edge is connected back the way it was.");
Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[1] == rightVertex, "The unsplit edge is connected back the way it was.");
}
// make sure that the data on FaceEdges is correct (split the center edge of an extruded plus).
{
// make an extruded pluss sign.
Mesh testMesh = new Mesh();
Vertex centerVertex = testMesh.CreateVertex(0, 0, 0);
Vertex leftVertex = testMesh.CreateVertex(-1, 0, 0);
Vertex rightVertex = testMesh.CreateVertex(1, 0, 0);
Vertex frontVertex = testMesh.CreateVertex(0, -1, 0);
Vertex backVertex = testMesh.CreateVertex(0, 1, 0);
//.........这里部分代码省略.........
示例6: MeshFaceSplitAndUnspiltTests
public void MeshFaceSplitAndUnspiltTests()
{
{
// centerVertexTop (0, 0, 2)
//
//
//
//
// leftVertexBottom (-1, 0, 0) centerVertexBottom (0, 0, 0) rightVertexBottom (1, 0, 0)
Mesh testMesh = new Mesh();
Vertex leftVertexBottom = testMesh.CreateVertex(-1, 0, 0);
Vertex centerVertexBottom = testMesh.CreateVertex(0, 0, 0);
Vertex rightVertexBottom = testMesh.CreateVertex(1, 0, 0);
Vertex centerVertexTop = testMesh.CreateVertex(0, 0, 1);
Face originalFace = testMesh.CreateFace(new Vertex[] { leftVertexBottom, centerVertexBottom, rightVertexBottom, centerVertexTop });
SaveDebugInfo(testMesh);
// *
// / \
// / \
// / \
// / \
// *----*----*
Assert.IsTrue(testMesh.FindMeshEdges(leftVertexBottom, centerVertexBottom).Count == 1);
MeshEdge firstFaceEdgeMeshEdge = testMesh.FindMeshEdges(leftVertexBottom, centerVertexBottom)[0];
Assert.IsTrue(originalFace.firstFaceEdge.meshEdge == firstFaceEdgeMeshEdge);
Assert.IsTrue(originalFace.NumVertices == 4, "The original face has 4 vertices.");
MeshEdge edgeLeftCenter = testMesh.FindMeshEdges(leftVertexBottom, centerVertexBottom)[0];
MeshEdge edgeCenterRight = testMesh.FindMeshEdges(centerVertexBottom, rightVertexBottom)[0];
MeshEdge edgeTopLeft = testMesh.FindMeshEdges(centerVertexTop, leftVertexBottom)[0];
MeshEdge edgeRightTop = testMesh.FindMeshEdges(centerVertexTop, rightVertexBottom)[0];
Assert.IsTrue(edgeTopLeft.NextMeshEdgeFromEnd[0] == edgeRightTop);
Assert.IsTrue(edgeTopLeft.NextMeshEdgeFromEnd[1] == edgeLeftCenter);
Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 2);
string connectionInfoBeforeSplit = testMesh.GetConnectionInfoAsString();
// split the face and test the result
Face faceCreatedDuringSplit;
MeshEdge meshEdgeCreatedDuringSplit;
testMesh.SplitFace(originalFace, centerVertexBottom, centerVertexTop, out meshEdgeCreatedDuringSplit, out faceCreatedDuringSplit);
SaveDebugInfo(testMesh);
// *
// /|\
// / | \
// / | \
// / | \
// *----*----*
testMesh.Validate();
//Debug.Write(testMesh.GetConnectionInfoAsString());
Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[0] == centerVertexBottom);
Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[1] == centerVertexTop);
Assert.IsTrue(edgeLeftCenter.NextMeshEdgeFromEnd[1] == meshEdgeCreatedDuringSplit);
Assert.IsTrue(edgeTopLeft.NextMeshEdgeFromEnd[1] == edgeLeftCenter);
Assert.IsTrue(originalFace.firstFaceEdge.meshEdge == meshEdgeCreatedDuringSplit);
Assert.IsTrue(originalFace.NumVertices == 3, "The original face now has 3 vertices.");
Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 3);
Assert.IsTrue(meshEdgeCreatedDuringSplit.GetNumFacesSharingEdge() == 2, "The edge we split on now has 2 faces attached to it.");
Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
Assert.IsTrue(centerVertexTop.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
Assert.IsTrue(leftVertexBottom.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
Assert.IsTrue(rightVertexBottom.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
Assert.IsTrue(faceCreatedDuringSplit.NumVertices == 3, "The created now has 3 vertices.");
// Unsplit the faces keeping the original face, and test the result.
testMesh.UnsplitFace(originalFace, faceCreatedDuringSplit, meshEdgeCreatedDuringSplit);
SaveDebugInfo(testMesh);
// *
// / \
// / \
// / \
// / \
// *----*----*
string connectionInfoAfterUnsplit = testMesh.GetConnectionInfoAsString();
testMesh.Validate();
foreach (FaceEdge faceEdge in originalFace.FaceEdges())
{
// make sure none of them are connected to the deleted MeshEdge
Assert.IsTrue(faceEdge.meshEdge != meshEdgeCreatedDuringSplit);
Assert.IsTrue(faceEdge.meshEdge.NextMeshEdgeFromEnd[0] != meshEdgeCreatedDuringSplit);
Assert.IsTrue(faceEdge.meshEdge.NextMeshEdgeFromEnd[1] != meshEdgeCreatedDuringSplit);
}
//Debug.Write(testMesh.GetConnectionInfoAsString());
Assert.IsTrue(originalFace.NumVertices == 4, "The original face is back to 4 vertices.");
Assert.IsTrue(meshEdgeCreatedDuringSplit.firstFaceEdge == null, "The data for the deleted edge is all null to help debugging.");
Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[0] == null, "The data for the deleted edge is all null to help debugging.");
Assert.IsTrue(meshEdgeCreatedDuringSplit.NextMeshEdgeFromEnd[0] == null, "The data for the deleted edge is all null to help debugging.");
Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[1] == null, "The data for the deleted edge is all null to help debugging.");
Assert.IsTrue(meshEdgeCreatedDuringSplit.NextMeshEdgeFromEnd[1] == null, "The data for the deleted edge is all null to help debugging.");
Assert.IsTrue(faceCreatedDuringSplit.firstFaceEdge == null, "The data for the deleted face is all null to help debugging.");
Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");
Assert.IsTrue(centerVertexTop.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");
}
//.........这里部分代码省略.........
示例7: MergeMeshEdges
public void MergeMeshEdges()
{
{
Mesh testMesh = new Mesh();
Vertex leftVertexBottom = testMesh.CreateVertex(-1, 0, 0);
Vertex centerVertexBottom = testMesh.CreateVertex(0, 0, 0);
Vertex centerVertexTop = testMesh.CreateVertex(0, 0, 1);
Face leftFace = testMesh.CreateFace(new Vertex[] { leftVertexBottom, centerVertexBottom, centerVertexTop });
SaveDebugInfo(testMesh);
Vertex rightVertexBottom = testMesh.CreateVertex(1, 0, 0);
Face rightFace = testMesh.CreateFace(new Vertex[] { centerVertexBottom, rightVertexBottom, centerVertexTop }, CreateOption.CreateNew);
SaveDebugInfo(testMesh);
foreach (MeshEdge meshEdge in testMesh.MeshEdges)
{
Assert.IsTrue(meshEdge.firstFaceEdge != null);
}
Assert.IsTrue(testMesh.MeshEdges.Count == 6);
Assert.IsTrue(testMesh.FindMeshEdges(centerVertexTop, centerVertexBottom).Count == 2);
testMesh.MergeMeshEdges();
SaveDebugInfo(testMesh);
Assert.IsTrue(testMesh.MeshEdges.Count == 5);
}
}
示例8: MergeVertices
public void MergeVertices()
{
{
Mesh testMesh = new Mesh();
Vertex leftVertexBottom = testMesh.CreateVertex(-1, 0, 0);
Vertex rightVertexBottom = testMesh.CreateVertex(1, 0, 0);
Vertex centerVertexMiddle1 = testMesh.CreateVertex(0, 0, 1);
MeshEdge meshEdgeBottomLeftRight = testMesh.CreateMeshEdge(leftVertexBottom, rightVertexBottom);
MeshEdge meshEdgeBottomRightCenter = testMesh.CreateMeshEdge(rightVertexBottom, centerVertexMiddle1);
MeshEdge meshEdgeBottomCenterLeft = testMesh.CreateMeshEdge(centerVertexMiddle1, leftVertexBottom);
Vertex leftVertexTop = testMesh.CreateVertex(-1, 0, 2);
Vertex centerVertexMiddle2 = testMesh.CreateVertex(0, 0, 1, CreateOption.CreateNew);
Vertex rightVertexTop = testMesh.CreateVertex(1, 0, 2);
MeshEdge meshEdgeTopLeftCenter = testMesh.CreateMeshEdge(leftVertexTop, centerVertexMiddle2);
MeshEdge meshEdgeTopCenterRight = testMesh.CreateMeshEdge(centerVertexMiddle2, rightVertexTop);
MeshEdge meshEdgeTopRightLeft = testMesh.CreateMeshEdge(rightVertexTop, leftVertexTop);
Assert.IsTrue(meshEdgeBottomRightCenter.VertexOnEnd[1] == centerVertexMiddle1);
Assert.IsTrue(meshEdgeTopLeftCenter.VertexOnEnd[1] == centerVertexMiddle2);
SaveDebugInfo(testMesh);
testMesh.MergeVertices(centerVertexMiddle1, centerVertexMiddle2);
Assert.IsTrue(!testMesh.Vertices.ContainsVertex(centerVertexMiddle2));
Assert.IsTrue(meshEdgeBottomRightCenter.VertexOnEnd[1] == centerVertexMiddle1);
Assert.IsTrue(meshEdgeBottomCenterLeft.VertexOnEnd[0] == centerVertexMiddle1);
Assert.IsTrue(meshEdgeTopLeftCenter.VertexOnEnd[1] == centerVertexMiddle1);
Assert.IsTrue(meshEdgeTopCenterRight.VertexOnEnd[0] == centerVertexMiddle1);
int connectedCount = 0;
foreach (MeshEdge meshEdge in centerVertexMiddle1.ConnectedMeshEdges())
{
connectedCount++;
}
Assert.IsTrue(connectedCount == 4);
SaveDebugInfo(testMesh);
}
{
Mesh testMesh = new Mesh();
Vertex leftVertexBottom = testMesh.CreateVertex(-1, 0, 0);
Vertex rightVertexBottom = testMesh.CreateVertex(1, 0, 0);
Vertex centerVertexMiddle1 = testMesh.CreateVertex(0, 0, 1);
MeshEdge meshEdgeBottomLeftRight = testMesh.CreateMeshEdge(leftVertexBottom, rightVertexBottom);
MeshEdge meshEdgeBottomRightCenter = testMesh.CreateMeshEdge(rightVertexBottom, centerVertexMiddle1);
MeshEdge meshEdgeBottomCenterLeft = testMesh.CreateMeshEdge(centerVertexMiddle1, leftVertexBottom);
Vertex leftVertexTop = testMesh.CreateVertex(-1, 0, 2);
Vertex centerVertexMiddle2 = testMesh.CreateVertex(0, 0, 1, CreateOption.CreateNew);
Vertex rightVertexTop = testMesh.CreateVertex(1, 0, 2);
MeshEdge meshEdgeTopLeftCenter = testMesh.CreateMeshEdge(leftVertexTop, centerVertexMiddle2);
MeshEdge meshEdgeTopCenterRight = testMesh.CreateMeshEdge(centerVertexMiddle2, rightVertexTop);
MeshEdge meshEdgeTopRightLeft = testMesh.CreateMeshEdge(rightVertexTop, leftVertexTop);
Assert.IsTrue(meshEdgeBottomRightCenter.VertexOnEnd[1] == centerVertexMiddle1);
Assert.IsTrue(meshEdgeTopLeftCenter.VertexOnEnd[1] == centerVertexMiddle2);
SaveDebugInfo(testMesh);
testMesh.MergeVertices(centerVertexMiddle2, centerVertexMiddle1);
Assert.IsTrue(testMesh.Vertices.ContainsVertex(centerVertexMiddle2));
Assert.IsTrue(meshEdgeBottomRightCenter.VertexOnEnd[1] == centerVertexMiddle2);
Assert.IsTrue(meshEdgeBottomCenterLeft.VertexOnEnd[0] == centerVertexMiddle2);
Assert.IsTrue(meshEdgeTopLeftCenter.VertexOnEnd[1] == centerVertexMiddle2);
Assert.IsTrue(meshEdgeTopCenterRight.VertexOnEnd[0] == centerVertexMiddle2);
int connectedCount = 0;
foreach (MeshEdge meshEdge in centerVertexMiddle2.ConnectedMeshEdges())
{
connectedCount++;
}
Assert.IsTrue(connectedCount == 4);
SaveDebugInfo(testMesh);
}
{
Mesh testMesh = new Mesh();
Vertex leftVertexBottom = testMesh.CreateVertex(-1, 0, 0);
Vertex rightVertexBottom = testMesh.CreateVertex(1, 0, 0);
Vertex centerVertexMiddle1 = testMesh.CreateVertex(0, 0, 1);
Face bottomFace = testMesh.CreateFace(new Vertex[] { leftVertexBottom, rightVertexBottom, centerVertexMiddle1 });
Vertex leftVertexTop = testMesh.CreateVertex(-1, 0, 2);
Vertex centerVertexMiddle2 = testMesh.CreateVertex(0, 0, 1, CreateOption.CreateNew);
Vertex rightVertexTop = testMesh.CreateVertex(1, 0, 2);
Face top = testMesh.CreateFace(new Vertex[] { leftVertexTop, centerVertexMiddle2, rightVertexTop });
//.........这里部分代码省略.........
示例9: DoMerge
public static Mesh DoMerge(List<MeshGroup> meshGroupsToMerge, MeshOutputSettings outputInfo)
{
Mesh allPolygons = new Mesh();
if (outputInfo.CsgOptionState == MeshOutputSettings.CsgOption.DoCsgMerge)
{
foreach (MeshGroup meshGroup in meshGroupsToMerge)
{
foreach (Mesh mesh in meshGroup.Meshes)
{
allPolygons = CsgOperations.Union(allPolygons, mesh);
}
}
}
else
{
foreach (MeshGroup meshGroup in meshGroupsToMerge)
{
foreach (Mesh mesh in meshGroup.Meshes)
{
int currentMeshMaterialIntdex = MeshMaterialData.Get(mesh).MaterialIndex;
if (outputInfo.MaterialIndexsToSave == null || outputInfo.MaterialIndexsToSave.Contains(currentMeshMaterialIntdex))
{
foreach (Face face in mesh.Faces)
{
List<Vertex> faceVertices = new List<Vertex>();
foreach (FaceEdge faceEdgeToAdd in face.FaceEdges())
{
// we allow duplicates (the true) to make sure we are not changing the loaded models acuracy.
Vertex newVertex = allPolygons.CreateVertex(faceEdgeToAdd.firstVertex.Position, CreateOption.CreateNew, SortOption.WillSortLater);
faceVertices.Add(newVertex);
}
// we allow duplicates (the true) to make sure we are not changing the loaded models acuracy.
allPolygons.CreateFace(faceVertices.ToArray(), CreateOption.CreateNew);
}
}
}
}
allPolygons.CleanAndMergMesh();
}
return allPolygons;
}
示例10: ReadVolume
private static Mesh ReadVolume(XmlReader xmlTree, List<Vector3> vertices, ProgressData progressData)
{
Mesh newMesh = new Mesh();
while (xmlTree.Read())
{
if (xmlTree.Name == "triangle")
{
using (XmlReader triangleTree = xmlTree.ReadSubtree())
{
while (triangleTree.Read())
{
int[] indices = new int[3];
while (triangleTree.Read())
{
switch (triangleTree.Name)
{
case "v1":
string v1 = triangleTree.ReadString();
indices[0] = int.Parse(v1);
break;
case "v2":
string v2 = triangleTree.ReadString();
indices[1] = int.Parse(v2);
break;
case "v3":
string v3 = triangleTree.ReadString();
indices[2] = int.Parse(v3);
break;
case "map":
using (XmlReader mapTree = triangleTree.ReadSubtree())
{
}
// a texture map, has u1...un and v1...vn
break;
default:
break;
}
}
if (indices[0] != indices[1]
&& indices[0] != indices[2]
&& indices[1] != indices[2]
&& vertices[indices[0]] != vertices[indices[1]]
&& vertices[indices[1]] != vertices[indices[2]]
&& vertices[indices[2]] != vertices[indices[0]])
{
Vertex[] triangle = new Vertex[]
{
newMesh.CreateVertex(vertices[indices[0]], CreateOption.CreateNew, SortOption.WillSortLater),
newMesh.CreateVertex(vertices[indices[1]], CreateOption.CreateNew, SortOption.WillSortLater),
newMesh.CreateVertex(vertices[indices[2]], CreateOption.CreateNew, SortOption.WillSortLater),
};
newMesh.CreateFace(triangle, CreateOption.CreateNew);
}
bool continueProcessing;
progressData.ReportProgress0To50(out continueProcessing);
if (!continueProcessing)
{
// this is what we should do but it requires a bit more debugging.
return null;
}
}
}
}
}
return newMesh;
}
示例11: ParseFileContents
public static Mesh ParseFileContents(Stream stlStream, ReportProgressRatio reportProgress)
{
Stopwatch time = new Stopwatch();
time.Start();
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
double parsingFileRatio = .5;
if (stlStream == null)
{
return null;
}
//MemoryStream stlStream = new MemoryStream();
//stlStreamIn.CopyTo(stlStream);
Stopwatch maxProgressReport = new Stopwatch();
maxProgressReport.Start();
Mesh meshFromStlFile = new Mesh();
//meshFromStlFile.MaxDistanceToConsiderVertexAsSame = .0000005;
long bytesInFile = stlStream.Length;
if (bytesInFile <= 80)
{
return null;
}
byte[] first160Bytes = new byte[160];
stlStream.Read(first160Bytes, 0, 160);
byte[] ByteOredrMark = new byte[] { 0xEF, 0xBB, 0xBF };
int startOfString = 0;
if (first160Bytes[0] == ByteOredrMark[0] && first160Bytes[0] == ByteOredrMark[0] && first160Bytes[0] == ByteOredrMark[0])
{
startOfString = 3;
}
string first160BytesOfSTLFile = System.Text.Encoding.UTF8.GetString(first160Bytes, startOfString, first160Bytes.Length - startOfString);
if (first160BytesOfSTLFile.StartsWith("solid") && first160BytesOfSTLFile.Contains("facet"))
{
stlStream.Position = 0;
StreamReader stlReader = new StreamReader(stlStream);
int vectorIndex = 0;
Vector3 vector0 = new Vector3(0, 0, 0);
Vector3 vector1 = new Vector3(0, 0, 0);
Vector3 vector2 = new Vector3(0, 0, 0);
string line = stlReader.ReadLine();
Regex onlySingleSpaces = new Regex("\\s+", RegexOptions.Compiled);
while (line != null)
{
line = onlySingleSpaces.Replace(line, " ");
var parts = line.Trim().Split(' ');
if (parts[0].Trim() == "vertex")
{
vectorIndex++;
switch (vectorIndex)
{
case 1:
vector0.x = Convert.ToDouble(parts[1]);
vector0.y = Convert.ToDouble(parts[2]);
vector0.z = Convert.ToDouble(parts[3]);
break;
case 2:
vector1.x = Convert.ToDouble(parts[1]);
vector1.y = Convert.ToDouble(parts[2]);
vector1.z = Convert.ToDouble(parts[3]);
break;
case 3:
vector2.x = Convert.ToDouble(parts[1]);
vector2.y = Convert.ToDouble(parts[2]);
vector2.z = Convert.ToDouble(parts[3]);
if (!Vector3.Collinear(vector0, vector1, vector2))
{
Vertex vertex1 = meshFromStlFile.CreateVertex(vector0, CreateOption.CreateNew, SortOption.WillSortLater);
Vertex vertex2 = meshFromStlFile.CreateVertex(vector1, CreateOption.CreateNew, SortOption.WillSortLater);
Vertex vertex3 = meshFromStlFile.CreateVertex(vector2, CreateOption.CreateNew, SortOption.WillSortLater);
meshFromStlFile.CreateFace(new Vertex[] { vertex1, vertex2, vertex3 }, CreateOption.CreateNew);
}
vectorIndex = 0;
break;
}
}
line = stlReader.ReadLine();
if (reportProgress != null && maxProgressReport.ElapsedMilliseconds > 200)
{
bool continueProcessing;
reportProgress(stlStream.Position / (double)bytesInFile * parsingFileRatio, "Loading Polygons", out continueProcessing);
if (!continueProcessing)
{
stlStream.Close();
return null;
}
maxProgressReport.Restart();
}
}
}
else
{
// load it as a binary stl
// skip the first 80 bytes
//.........这里部分代码省略.........