本文整理汇总了C#中Mesh.CleanAndMergMesh方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.CleanAndMergMesh方法的具体用法?C# Mesh.CleanAndMergMesh怎么用?C# Mesh.CleanAndMergMesh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.CleanAndMergMesh方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: MeshEdgeSplitAndUnsplitTests
//.........这里部分代码省略.........
// 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);
Vertex centerVertexTop = testMesh.CreateVertex(0, 0, 1);
Vertex leftVertexTop = testMesh.CreateVertex(-1, 0, 1);
Vertex rightVertexTop = testMesh.CreateVertex(1, 0, 1);
Vertex frontVertexTop = testMesh.CreateVertex(0, -1, 1);
Vertex backVertexTop = testMesh.CreateVertex(0, 1, 1);
testMesh.CreateFace(new Vertex[] { centerVertex, centerVertexTop, frontVertexTop, frontVertex });
MeshEdge centerEdge = testMesh.FindMeshEdges(centerVertex, centerVertexTop)[0];
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 1, "There should be 1 faces on this edge.");
testMesh.CreateFace(new Vertex[] { centerVertex, centerVertexTop, rightVertexTop, rightVertex });
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 2, "There should be 2 faces on this edge.");
testMesh.CreateFace(new Vertex[] { centerVertex, centerVertexTop, backVertexTop, backVertex });
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 3, "There should be 3 faces on this edge.");
testMesh.CreateFace(new Vertex[] { centerVertex, centerVertexTop, leftVertexTop, leftVertex });
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 4, "There should be 4 faces on this edge.");
foreach (Face face in centerEdge.FacesSharingMeshEdgeIterator())
{
Assert.IsTrue(face.NumVertices == 4, "The faces should all have 4 vertices.");
}
Vertex createdVertx;
MeshEdge createdEdge;
testMesh.SplitMeshEdge(centerEdge, out createdVertx, out createdEdge);
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 4, "There should still be 4 faces on this edge.");
Assert.IsTrue(createdEdge.GetNumFacesSharingEdge() == 4, "There should be 4 faces on this new edge.");
foreach (Face face in centerEdge.FacesSharingMeshEdgeIterator())
{
Assert.IsTrue(face.NumVertices == 5, "The faces should all now have 5 vertices.");
}
testMesh.UnsplitMeshEdge(centerEdge, createdVertx);
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 4, "There should again be 4 faces on this edge.");
foreach (Face face in centerEdge.FacesSharingMeshEdgeIterator())
{
Assert.IsTrue(face.NumVertices == 4, "The faces should all finally have 4 vertices.");
}
}
// make sure that the data on FaceEdges is correct (split the center edge of an extruded plus).
if (false)
{
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 centerVertexTop = testMesh.CreateVertex(0, 0, 1);
Vertex leftVertexTop = testMesh.CreateVertex(-1, 0, 1);
Vertex rightVertexTop = testMesh.CreateVertex(1, 0, 1);
testMesh.CreateFace(new Vertex[] { centerVertex, centerVertexTop, leftVertexTop, leftVertex });
MeshEdge centerEdge = testMesh.FindMeshEdges(centerVertex, centerVertexTop)[0];
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 1, "There should be 1 faces on this edge.");
testMesh.CreateFace(new Vertex[] { centerVertexTop, centerVertex, rightVertex, rightVertexTop });
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 2, "There should be 2 faces on this edge.");
foreach (Face face in centerEdge.FacesSharingMeshEdgeIterator())
{
Assert.IsTrue(face.NumVertices == 4, "The faces should all have 4 vertices.");
}
SaveDebugInfo(testMesh);
testMesh.CleanAndMergMesh();
SaveDebugInfo(testMesh);
Vertex createdVertx;
MeshEdge createdEdge;
testMesh.SplitMeshEdge(centerEdge, out createdVertx, out createdEdge);
SaveDebugInfo(testMesh);
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 4, "There should still be 4 faces on this edge.");
Assert.IsTrue(createdEdge.GetNumFacesSharingEdge() == 4, "There should be 4 faces on this new edge.");
foreach (Face face in centerEdge.FacesSharingMeshEdgeIterator())
{
Assert.IsTrue(face.NumVertices == 5, "The faces should all now have 5 vertices.");
}
testMesh.CleanAndMergMesh();
testMesh.UnsplitMeshEdge(centerEdge, createdVertx);
Assert.IsTrue(centerEdge.GetNumFacesSharingEdge() == 4, "There should again be 4 faces on this edge.");
foreach (Face face in centerEdge.FacesSharingMeshEdgeIterator())
{
Assert.IsTrue(face.NumVertices == 4, "The faces should all finally have 4 vertices.");
}
testMesh.CleanAndMergMesh();
}
}
示例3: ParseFileContents
//.........这里部分代码省略.........
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
// read in the number of triangles
stlStream.Position = 0;
BinaryReader br = new BinaryReader(stlStream);
byte[] fileContents = br.ReadBytes((int)stlStream.Length);
int currentPosition = 80;
uint numTriangles = System.BitConverter.ToUInt32(fileContents, currentPosition);
long bytesForNormals = numTriangles * 3 * 4;
long bytesForVertices = numTriangles * 3 * 4 * 3;
long bytesForAttributs = numTriangles * 2;
currentPosition += 4;
long numBytesRequiredForVertexData = currentPosition + bytesForNormals + bytesForVertices + bytesForAttributs;
if (fileContents.Length < numBytesRequiredForVertexData || numTriangles < 4)
{
stlStream.Close();
return null;
}
Vector3[] vector = new Vector3[3];
for (int i = 0; i < numTriangles; i++)
{
// skip the normal
currentPosition += 3 * 4;
for (int j = 0; j < 3; j++)
{
vector[j] = new Vector3(
System.BitConverter.ToSingle(fileContents, currentPosition + 0 * 4),
System.BitConverter.ToSingle(fileContents, currentPosition + 1 * 4),
System.BitConverter.ToSingle(fileContents, currentPosition + 2 * 4));
currentPosition += 3 * 4;
}
currentPosition += 2; // skip the attribute
if (reportProgress != null && maxProgressReport.ElapsedMilliseconds > 200)
{
bool continueProcessing;
reportProgress(i / (double)numTriangles * parsingFileRatio, "Loading Polygons", out continueProcessing);
if (!continueProcessing)
{
stlStream.Close();
return null;
}
maxProgressReport.Restart();
}
if (!Vector3.Collinear(vector[0], vector[1], vector[2]))
{
Vertex vertex1 = meshFromStlFile.CreateVertex(vector[0], CreateOption.CreateNew, SortOption.WillSortLater);
Vertex vertex2 = meshFromStlFile.CreateVertex(vector[1], CreateOption.CreateNew, SortOption.WillSortLater);
Vertex vertex3 = meshFromStlFile.CreateVertex(vector[2], CreateOption.CreateNew, SortOption.WillSortLater);
meshFromStlFile.CreateFace(new Vertex[] { vertex1, vertex2, vertex3 }, CreateOption.CreateNew);
}
}
//uint numTriangles = System.BitConverter.ToSingle(fileContents, 80);
}
// merge all the vetexes that are in the same place together
bool finishedCleanAndMerge = true;
meshFromStlFile.CleanAndMergMesh(
(double progress0To1, string processingState, out bool continueProcessing) =>
{
if (reportProgress != null)
{
reportProgress(parsingFileRatio + progress0To1 * (1 - parsingFileRatio), processingState, out continueProcessing);
if (!continueProcessing)
{
finishedCleanAndMerge = false;
}
}
else
{
continueProcessing = true;
}
}
);
if (!finishedCleanAndMerge)
{
return null;
}
time.Stop();
Debug.WriteLine(string.Format("STL Load in {0:0.00}s", time.Elapsed.TotalSeconds));
stlStream.Close();
return meshFromStlFile;
}