当前位置: 首页>>代码示例>>C#>>正文


C# CombineInstance.Where方法代码示例

本文整理汇总了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);

//.........这里部分代码省略.........
开发者ID:TK-97,项目名称:ICO_AGM_Asg02,代码行数:101,代码来源:MeshCombiner.cs


注:本文中的UnityEngine.CombineInstance.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。