本文整理汇总了C#中UnityEngine.CombineInstance.Where方法的典型用法代码示例。如果您正苦于以下问题:C# CombineInstance.Where方法的具体用法?C# CombineInstance.Where怎么用?C# CombineInstance.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.CombineInstance
的用法示例。
在下文中一共展示了CombineInstance.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMesh
public Mesh GetMesh(CombineInstance[] combines,int vertexCount)
{
combines = combines.Where(c => c.mesh !=null).ToArray();
if (combines.Length == 0)
return null;
Vector3[] vertices = new Vector3[vertexCount];
Vector3[] normals = new Vector3[vertexCount];
Vector4[] tangents = new Vector4[vertexCount];
List<Vector2> uv = new List<Vector2>();
List<Vector2> uv1 = new List<Vector2>();
List<Vector2> uv2 = new List<Vector2>();
List<Color> colors = new List<Color>();
int offset = 0;
#region vertices
offset = 0;
foreach(var combine in combines)
{
GetVertices(combine.mesh.vertexCount,combine.mesh.vertices,vertices,ref offset,combine.transform);
}
#endregion
#region normals
offset = 0;
foreach(var combine in combines)
{
GetNormal(combine.mesh.vertexCount,combine.mesh.normals,normals,ref offset,combine.transform);
}
#endregion
#region tangents
offset = 0;
foreach(var combine in combines)
{
GetTangents(combine.mesh.vertexCount,combine.mesh.tangents,tangents,ref offset,combine.transform);
}
#endregion
#region triangles
List<int[]> triangles = new List<int[]>();
for(int i = 0;i < combines[0].subMeshIndex;i++)
{
int curTrianglesCount = 0;
foreach (var combine in combines)
{
curTrianglesCount = curTrianglesCount + combine.mesh.GetTriangles(i).Length;
}
int[] curTriangles = new int[curTrianglesCount];
int triangleOffset = 0;
int vertexOffset = 0;
foreach (var combine in combines)
{
int[] inputtriangles = combine.mesh.GetTriangles(i);
for (int c = 0; c < inputtriangles.Length; c++)
{
curTriangles[c + triangleOffset] = inputtriangles[c] + vertexOffset;
}
triangleOffset += inputtriangles.Length;
vertexOffset += combine.mesh.vertexCount;
}
triangles.Add(curTriangles);
}
#endregion
foreach(var combine in combines)
{
uv.AddRange(new Queue<Vector2>(combine.mesh.uv));
uv1.AddRange(new Queue<Vector2>(combine.mesh.uv2));
uv2.AddRange(new Queue<Vector2>(combine.mesh.uv2));
colors.AddRange(new Queue<Color>(combine.mesh.colors));
}
Mesh mesh = new Mesh();
mesh.name = "CombineMesh";
mesh.vertices = vertices;
mesh.normals = normals;
mesh.tangents = tangents;
mesh.subMeshCount = combines[0].subMeshIndex;
mesh.uv = uv.ToArray();
mesh.RecalculateBounds();
if(triangles.Count !=1)
{
for(int i = 0;i < combines[0].subMeshIndex;i++)
{
mesh.SetTriangles(triangles[i],i);
}
}
else
mesh.SetTriangles(triangles[0],0);
//.........这里部分代码省略.........