本文整理汇总了C#中pb_Object.TriangleCount方法的典型用法代码示例。如果您正苦于以下问题:C# pb_Object.TriangleCount方法的具体用法?C# pb_Object.TriangleCount怎么用?C# pb_Object.TriangleCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pb_Object
的用法示例。
在下文中一共展示了pb_Object.TriangleCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Triangulate
/**
* Triangulate an entire pb_Object.
*/
public static void Triangulate(pb_Object pb)
{
Vector3[] v = pb.vertices;
Color[] c = pb.colors;
Vector2[] u = pb.uv;
int triangleCount = pb.TriangleCount();
// int triangleCount = pb_Face.AllTriangles(pb.faces).Length; // pb.msh.triangles.Length;
if(triangleCount == v.Length)
{
Debug.LogWarning("We can't pull over any further!\npb_Object: " + pb.name + " is already triangulated.");
}
int vertexCount = triangleCount;
int faceCount = vertexCount / 3;
Vector3[] tri_vertices = new Vector3[vertexCount];
Color[] tri_colors = new Color[vertexCount];
Vector2[] tri_uvs = new Vector2[vertexCount];
pb_Face[] tri_faces = new pb_Face[faceCount];
int n = 0, f = 0;
foreach(pb_Face face in pb.faces)
{
int[] indices = face.indices;
for(int i = 0; i < indices.Length; i+=3)
{
tri_vertices[n+0] = v[indices[i+0]];
tri_vertices[n+1] = v[indices[i+1]];
tri_vertices[n+2] = v[indices[i+2]];
tri_colors[n+0] = c[indices[i+0]];
tri_colors[n+1] = c[indices[i+1]];
tri_colors[n+2] = c[indices[i+2]];
tri_uvs[n+0] = u[indices[i+0]];
tri_uvs[n+1] = u[indices[i+1]];
tri_uvs[n+2] = u[indices[i+2]];
tri_faces[f++] = new pb_Face( new int[] { n+0, n+1, n+2 },
face.material,
face.uv,
face.smoothingGroup,
face.textureGroup, // textureGroup -> force to manual uv mode
face.elementGroup,
face.manualUV
);
n += 3;
}
}
pb.SetVertices(tri_vertices);
pb.SetColors(tri_colors);
pb.SetUV(tri_uvs);
pb.SetFaces(tri_faces);
pb.SetSharedIndices( pb_IntArrayUtility.ExtractSharedIndices(tri_vertices) );
pb.SetSharedIndicesUV( new pb_IntArray[0] );
}