本文整理汇总了C#中MeshBuilder.AddTri方法的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder.AddTri方法的具体用法?C# MeshBuilder.AddTri怎么用?C# MeshBuilder.AddTri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshBuilder
的用法示例。
在下文中一共展示了MeshBuilder.AddTri方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeshSplit
// Cut a mesh by the line origin->d and split it into two objects if necessary
public static void MeshSplit(Mesh mesh, Vector2 origin, Vector2 direction)
{
Vector3[] vertices = mesh.vertices;
MeshBuilder leftSide = new MeshBuilder(mesh, vertices);
MeshBuilder rightSide = new MeshBuilder(mesh, vertices);
// which side my vertices at?
bool[] side = new bool[vertices.Length];
bool allOnTheLeft = true, allOnTheRight = true;
for (int i = 0; i < vertices.Length; i++)
{
side [i] = direction.x * (vertices [i].y - origin.y) > direction.y * (vertices [i].x - origin.x);
if (side [i])
allOnTheRight = false;
else
allOnTheLeft = false;
}
if (allOnTheLeft || allOnTheRight)
return;
// build the mesh by adding triangles (possibly cut)
for (int i = 0; i < mesh.triangles.Length; i += 3)
{
int i1 = mesh.triangles [i], i2 = mesh.triangles [i + 1], i3 = mesh.triangles [i + 2];
switch ((side [i1] ? 1 : 0) | (side [i2] ? 2 : 0) | (side [i3] ? 4 : 0))
{
case 0 | 0 | 0:
leftSide.AddTri(i1, i2, i3);
break;
case 0 | 0 | 1:
MeshBuilder.AddCutTri(rightSide, leftSide, i1, i2, i3, origin, direction);
break;
case 0 | 2 | 0:
MeshBuilder.AddCutTri(rightSide, leftSide, i2, i3, i1, origin, direction);
break;
case 4 | 0 | 0:
MeshBuilder.AddCutTri(rightSide, leftSide, i3, i1, i2, origin, direction);
break;
case 4 | 2 | 0:
MeshBuilder.AddCutTri(leftSide, rightSide, i1, i2, i3, origin, direction);
break;
case 4 | 0 | 1:
MeshBuilder.AddCutTri(leftSide, rightSide, i2, i3, i1, origin, direction);
break;
case 0 | 2 | 1:
MeshBuilder.AddCutTri(leftSide, rightSide, i3, i1, i2, origin, direction);
break;
case 4 | 2 | 1:
rightSide.AddTri(i1, i2, i3);
break;
}
}
// degenerate?
if (leftSide.IsDegenerate(origin, direction))
return;
if (rightSide.IsDegenerate(origin, direction))
return;
mesh.Clear();
int finLength = leftSide.pos.Count + rightSide.pos.Count;
int finTrianglesLength = leftSide.tri.Count + rightSide.tri.Count;
int leftSideLength = leftSide.pos.Count;
int rightSideLength = rightSide.pos.Count;
int leftSideTrianglesLength = leftSide.tri.Count;
int rightSideTrianglesLength = rightSide.tri.Count;
Vector3[] finVertices = new Vector3[finLength];
Color32[] finColors = new Color32[finLength];
Vector2[] finUv = new Vector2[finLength];
Vector2[] finUv2 = new Vector2[finLength];
int[] finTriangles = new int[finTrianglesLength];
for(int i = 0; i < leftSideLength; i++)
{
finVertices[i] = leftSide.pos[i];
finColors[i] = leftSide.col[i];
finUv[i] = leftSide.uv[i];
finUv2[i] = leftSide.uv2[i];
}
int offsetIndex;
for(int i = 0; i < rightSideLength; i++)
{
offsetIndex = leftSideLength + i;
finVertices[offsetIndex] = rightSide.pos[i];
finColors[offsetIndex] = rightSide.col[i];
finUv[offsetIndex] = rightSide.uv[i];
finUv2[offsetIndex] = rightSide.uv2[i];
}
for(int i = 0; i < leftSideTrianglesLength; i++)
{
finTriangles[i] = leftSide.tri[i];
}
//.........这里部分代码省略.........