protected static DB3D.IndexBuffer ToWireframeBuffer(Mesh mesh, out int linesCount) { linesCount = (mesh.Faces.Count * 3) + mesh.Faces.QuadCount; if (linesCount > 0) { var ib = new DB3D.IndexBuffer(linesCount * DB3D.IndexLine.GetSizeInShortInts()); ib.Map(linesCount * DB3D.IndexLine.GetSizeInShortInts()); using (var istream = ib.GetIndexStreamLine()) { foreach (var face in mesh.Faces) { istream.AddLine(new DB3D.IndexLine(face.A, face.B)); istream.AddLine(new DB3D.IndexLine(face.B, face.C)); istream.AddLine(new DB3D.IndexLine(face.C, face.D)); if (face.IsQuad) { istream.AddLine(new DB3D.IndexLine(face.D, face.A)); } } } ib.Unmap(); return(ib); } return(null); }
protected static DB3D.IndexBuffer ToTrianglesBuffer ( Mesh mesh, Primitive.Part part, out int triangleCount ) { triangleCount = part.FaceCount; { var faces = mesh.Faces; for (int f = part.StartFaceIndex; f < part.EndFaceIndex; ++f) { if (faces[f].IsQuad) { triangleCount++; } } } if (triangleCount > 0) { var ib = new DB3D.IndexBuffer(triangleCount * DB3D.IndexTriangle.GetSizeInShortInts()); ib.Map(triangleCount * DB3D.IndexTriangle.GetSizeInShortInts()); using (var istream = ib.GetIndexStreamTriangle()) { var faces = mesh.Faces; for (int f = part.StartFaceIndex; f < part.EndFaceIndex; ++f) { var face = faces[f]; istream.AddTriangle(new DB3D.IndexTriangle(face.A - part.StartVertexIndex, face.B - part.StartVertexIndex, face.C - part.StartVertexIndex)); if (face.IsQuad) { istream.AddTriangle(new DB3D.IndexTriangle(face.C - part.StartVertexIndex, face.D - part.StartVertexIndex, face.A - part.StartVertexIndex)); } } } ib.Unmap(); return(ib); } return(null); }
static DB3D.IndexBuffer IndexPointsBuffer(int pointsCount) { Debug.Assert(pointsCount <= VertexThreshold); if (indexPointsBuffer == null) { indexPointsBuffer = new DB3D.IndexBuffer(VertexThreshold * DB3D.IndexPoint.GetSizeInShortInts()); indexPointsBuffer.Map(VertexThreshold * DB3D.IndexPoint.GetSizeInShortInts()); using (var istream = indexPointsBuffer.GetIndexStreamPoint()) { for (int vi = 0; vi < VertexThreshold; ++vi) { istream.AddPoint(new DB3D.IndexPoint(vi)); } } indexPointsBuffer.Unmap(); } Debug.Assert(indexPointsBuffer.IsValid()); return(indexPointsBuffer); }
protected static DB3D.IndexBuffer ToEdgeBuffer ( Mesh mesh, Primitive.Part part, out int linesCount ) { if (part.VertexCount != mesh.Vertices.Count) { if (part.VertexCount > 0) { linesCount = -part.VertexCount; return(IndexPointsBuffer(part.VertexCount)); } linesCount = 0; } else { var edgeIndices = new List <IndexPair>(); if (mesh.Ngons.Count > 0) { foreach (var ngon in mesh.Ngons) { var boundary = ngon.BoundaryVertexIndexList(); if ((boundary?.Length ?? 0) > 1) { for (int b = 0; b < boundary.Length - 1; ++b) { edgeIndices.Add(new IndexPair((int)boundary[b], (int)boundary[b + 1])); } edgeIndices.Add(new IndexPair((int)boundary[boundary.Length - 1], (int)boundary[0])); } } } else { var vertices = mesh.TopologyVertices; var edges = mesh.TopologyEdges; var edgeCount = edges.Count; for (int e = 0; e < edgeCount; ++e) { if (edges.IsEdgeUnwelded(e) || edges.GetConnectedFaces(e).Length < 2) { var pair = edges.GetTopologyVertices(e); pair.I = vertices.MeshVertexIndices(pair.I)[0]; pair.J = vertices.MeshVertexIndices(pair.J)[0]; edgeIndices.Add(pair); } } } linesCount = edgeIndices.Count; if (linesCount > 0) { var ib = new DB3D.IndexBuffer(linesCount * DB3D.IndexLine.GetSizeInShortInts()); ib.Map(linesCount * DB3D.IndexLine.GetSizeInShortInts()); using (var istream = ib.GetIndexStreamLine()) { foreach (var edge in edgeIndices) { Debug.Assert(0 <= edge.I && edge.I < part.VertexCount); Debug.Assert(0 <= edge.J && edge.J < part.VertexCount); istream.AddLine(new DB3D.IndexLine(edge.I, edge.J)); } } ib.Unmap(); return(ib); } } return(null); }