本文整理汇总了C#中pb_Face.isValid方法的典型用法代码示例。如果您正苦于以下问题:C# pb_Face.isValid方法的具体用法?C# pb_Face.isValid怎么用?C# pb_Face.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pb_Face
的用法示例。
在下文中一共展示了pb_Face.isValid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendVerticesToFace
/**
* Given a face and a point, this will add a vertex to the pb_Object and retriangulate the face.
*/
public static bool AppendVerticesToFace(this pb_Object pb, pb_Face face, List<Vector3> points, out pb_Face newFace)
{
if(!face.isValid())
{
newFace = face;
return false;
}
// First order of business - project face to 2d
int[] distinctIndices = face.distinctIndices;
Vector3[] verts = pb.GetVertices(distinctIndices);
// Get the face normal before modifying the vertex array
Vector3 nrm = pb_Math.Normal(pb.GetVertices(face.indices));
Vector3 projAxis = pb_Math.GetProjectionAxis(nrm).ToVector3();
// Add the new point
Vector3[] t_verts = new Vector3[verts.Length + points.Count];
System.Array.Copy(verts, 0, t_verts, 0, verts.Length);
System.Array.Copy(points.ToArray(), 0, t_verts, verts.Length, points.Count);
verts = t_verts;
// Project
List<Vector2> plane = new List<Vector2>(pb_Math.VerticesTo2DPoints(verts, projAxis));
// Save the sharedIndices index for each distinct vertex
pb_IntArray[] sharedIndices = pb.sharedIndices;
int[] sharedIndex = new int[distinctIndices.Length+points.Count];
for(int i = 0; i < distinctIndices.Length; i++)
sharedIndex[i] = sharedIndices.IndexOf(distinctIndices[i]);
for(int i = distinctIndices.Length; i < distinctIndices.Length+points.Count; i++)
sharedIndex[i] = -1; // add the new vertex to it's own sharedIndex
// Triangulate the face with the new point appended
int[] tris = Delauney.Triangulate(plane).ToIntArray();
// Check to make sure the triangulated face is facing the same direction, and flip if not
Vector3 del = Vector3.Cross( verts[tris[2]] - verts[tris[0]], verts[tris[1]]-verts[tris[0]]).normalized;
if(Vector3.Dot(nrm, del) > 0) System.Array.Reverse(tris);
// Compose new face
newFace = pb.AppendFace(verts, new pb_Face(tris, face.material, new pb_UV(face.uv), face.smoothingGroup, face.textureGroup, -1, face.color), sharedIndex);
// And delete the old
pb.DeleteFace(face);
return true;
}