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


C# Mesh.GetTriangles方法代码示例

本文整理汇总了C#中UnityEngine.Mesh.GetTriangles方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.GetTriangles方法的具体用法?C# Mesh.GetTriangles怎么用?C# Mesh.GetTriangles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Mesh的用法示例。


在下文中一共展示了Mesh.GetTriangles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportToString

		public static string ExportToString (Mesh mesh, Renderer renderer, bool uselhcoords = true, bool separateSubmeshes = true){
			Material[] mats = renderer.sharedMaterials;
			// Initiation
			StringBuilder sb = new StringBuilder();
			//Header
			sb.Append("o ").Append("Plane").Append("\n");
			foreach(Vector3 v in mesh.vertices) {
				sb.Append(string.Format("v {0:0.000000} {1:0.000000} {2:0.000000}\n",(uselhcoords?-v.x:v.x),v.y,v.z));
			}
			sb.Append("\n");
			foreach(Vector3 v in mesh.normals) {
				sb.Append(string.Format("vn {0:0.000000} {1:0.000000} {2:0.000000}\n",v.x,v.y,v.z));
			}
			sb.Append("\n");
			foreach(Vector3 v in mesh.uv) {
				sb.Append(string.Format("vt {0:0.000000} {1:0.000000}\n",v.x,v.y));
			}
			for (int material=0; material < mesh.subMeshCount; material ++) {
				sb.Append("\n");
				if (separateSubmeshes){
					sb.Append("g ").Append(mats[material].name).Append("\n");
				}
				sb.Append("usemtl ").Append(mats[material].name).Append("\n");
				sb.Append("usemap ").Append(mats[material].name).Append("\n");
				
				int[] triangles = mesh.GetTriangles(material);
				for (int i=0;i<triangles.Length;i+=3) {
					sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", 
					                        triangles[(uselhcoords?i+1:i)]+1, triangles[(uselhcoords?i:i+1)]+1, triangles[i+2]+1));
				}
			}
			return sb.ToString();
		}
开发者ID:anteaterho,项目名称:SpoutTestTemp,代码行数:33,代码来源:ObjTools.cs

示例2: CloneMesh

    static Mesh CloneMesh(Mesh mesh)
    {
        Mesh clonemesh = new Mesh();
        clonemesh.vertices = mesh.vertices;
        clonemesh.uv1 = mesh.uv1;
        clonemesh.uv2 = mesh.uv2;
        clonemesh.uv = mesh.uv;
        clonemesh.normals = mesh.normals;
        clonemesh.tangents = mesh.tangents;
        clonemesh.colors = mesh.colors;

        clonemesh.subMeshCount = mesh.subMeshCount;

        for ( int s = 0; s < mesh.subMeshCount; s++ )
        {
            clonemesh.SetTriangles(mesh.GetTriangles(s), s);
        }

        //clonemesh.triangles = mesh.triangles;

        clonemesh.boneWeights = mesh.boneWeights;
        clonemesh.bindposes = mesh.bindposes;
        clonemesh.name = mesh.name + "_copy";
        clonemesh.RecalculateBounds();

        return clonemesh;
    }
开发者ID:jsr2k1,项目名称:videojocjj,代码行数:27,代码来源:MegaCopyObjects.cs

示例3: CloneMesh

        //todo this really needs to be threaded, some meshes are quite large
        public static Mesh CloneMesh(Mesh mesh)
        {
            Mesh newmesh = new Mesh();
            newmesh.name = mesh.name;
            var newverts = new Vector3[mesh.vertices.Length];
            for (int i = 0; i < mesh.vertices.Length; i++)
            {
                var vertex = mesh.vertices[i];
                Vector3 v = qRotateX * vertex;
                newverts[i] = qRotateZ * v;
            }
            newmesh.vertices = newverts;
            newmesh.subMeshCount = mesh.subMeshCount;
            for (int i = 0; i < mesh.subMeshCount; i++)
            {
                int[] triangles = mesh.GetTriangles(i);
                newmesh.SetTriangles(triangles, i);
            }
            newmesh.uv = mesh.uv;
            newmesh.uv2 = mesh.uv2;
            newmesh.uv2 = mesh.uv2;
            newmesh.normals = mesh.normals;
            newmesh.colors = mesh.colors;
            newmesh.tangents = mesh.tangents;

            return newmesh;
        }
开发者ID:shaunvxc,项目名称:Infamy,代码行数:28,代码来源:ImportHelpers.cs

示例4: MergeVertices

		/**
		 * Merge indices to a single vertex.  Operates on a Mesh, not pb_Object.
		 */
		public static void MergeVertices(List<List<int>> InIndices, ref Mesh InMesh)
		{
			Dictionary<int, int> swapTable = new Dictionary<int, int>();

			foreach(List<int> group in InIndices)
			{
				for(int i = 1; i < group.Count; i++)
				{
					swapTable.Add(group[i], group[0]);
				}
			}				

			// Iterate triangles and point collapse-able verts to the first index
			for(int submeshIndex = 0; submeshIndex < InMesh.subMeshCount; submeshIndex++)
			{
				int[] tris = InMesh.GetTriangles(submeshIndex);

				for(int i = 0; i < tris.Length; i++)
				{
					if( swapTable.ContainsKey(tris[i]) )
						tris[i] = swapTable[tris[i]];
				}
				InMesh.SetTriangles(tris, submeshIndex);
			}

			// populate list of unused vertices post-collapse
			List<int> unused = InIndices.SelectMany( x => x.GetRange(1, x.Count - 1) ).ToList();

			RemoveVertices(unused, ref InMesh);
		}
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:33,代码来源:pb_MeshUtility.cs

示例5: MeshToString

        /** Generates an obj file from supplied Mesh object */
        public static string MeshToString(Mesh m)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("g ").Append(m.name).Append("\n");
            foreach(Vector3 v in m.vertices) {
                sb.Append(string.Format("v {0} {1} {2}\n",v.x,v.y,v.z));
            }
            sb.Append("\n");
            foreach(Vector3 v in m.normals) {
                sb.Append(string.Format("vn {0} {1} {2}\n",v.x,v.y,v.z));
            }
            sb.Append("\n");
            foreach(Vector3 v in m.uv) {
                sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
            }
            for (int material=0; material < m.subMeshCount; material ++) {
                sb.Append("\n");

                int[] triangles = m.GetTriangles(material);
                for (int i=0;i<triangles.Length;i+=3) {
                    sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n",
                        triangles[i]+1, triangles[i+1]+1, triangles[i+2]+1));
                }
            }
            return sb.ToString();
        }
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:28,代码来源:ObjExporter.cs

示例6: RecalculateNormals

 void RecalculateNormals(Mesh mesh)
 {
     var triangles = mesh.GetTriangles(0);
     var vertices = mesh.vertices;
     var triNormals = new Vector3[triangles.Length / 3]; //Holds the normal of each triangle
     var normals = new Vector3[vertices.Length];
 }
开发者ID:MylesBell,项目名称:Unity,代码行数:7,代码来源:Water.cs

示例7: RotateMesh

	//"rotate" the mesh data
	private void RotateMesh(Mesh mesh)
	{
		int index = 0;

		//switch all vertex z values with y values
		Vector3[] vertices = mesh.vertices;
		for (index = 0; index < vertices.Length; index++)
		{
			vertices[index] = new Vector3(vertices[index].x, vertices[index].z, vertices[index].y);
		}
		mesh.vertices = vertices;

		//for each submesh, we invert the order of vertices for all triangles
		//for some reason changing the vertex positions flips all the normals???
		for (int submesh = 0; submesh < mesh.subMeshCount; submesh++)
		{
			int[] triangles = mesh.GetTriangles(submesh);
			for (index = 0; index < triangles.Length; index += 3)
			{
				int intermediate = triangles[index];
				triangles[index] = triangles[index + 2];
				triangles[index + 2] = intermediate;
			}
			mesh.SetTriangles(triangles, submesh);
		}

		//recalculate other relevant mesh data
		mesh.RecalculateNormals();
		mesh.RecalculateBounds();
	}
开发者ID:HandsomeCharming,项目名称:Free_Lunch,代码行数:31,代码来源:BlenderAssetProcessor.cs

示例8: RemoveVertices

		/**
		 * Rebuild mesh without InUnusedVertices, including shifting the triangle array to compensate.
		 */
		public static void RemoveVertices(List<int> InUnusedVertices, ref Mesh InMesh)
		{
			int vertexCount = InMesh.vertexCount;
			int unusedCount = InUnusedVertices.Count;

			Vector3[] v = InMesh.vertices, v_n = new Vector3[vertexCount - unusedCount];
			Vector3[] n = InMesh.normals, n_n = new Vector3[vertexCount - unusedCount];
			Vector4[] t = InMesh.tangents, t_n = new Vector4[vertexCount - unusedCount];
			Vector2[] u = InMesh.uv, u_n = new Vector2[vertexCount - unusedCount];
			Color[] c 	= InMesh.colors, c_n = new Color[vertexCount - unusedCount];

			InUnusedVertices.Sort();

			int unusedIndex = 0;

			// shift triangles
			for(int submeshIndex = 0; submeshIndex < InMesh.subMeshCount; submeshIndex++)
			{
				int[] tris = InMesh.GetTriangles(submeshIndex);

				for(int i = 0; i < tris.Length; i++)
				{
					unusedIndex = pbUtil.NearestIndexPriorToValue( InUnusedVertices, tris[i] ) + 1;
					tris[i] -= unusedIndex;
				}

				InMesh.SetTriangles(tris, submeshIndex);
			}

			unusedIndex = 0;
			int newIndex = 0;

			// rebuild vertex arrays without duplicate indices
			for(int i = 0; i < vertexCount; i++)
			{
				if(unusedIndex < unusedCount && i >= InUnusedVertices[unusedIndex])
				{
					unusedIndex++;
					continue;
				}

				v_n[newIndex] = v[i];
				n_n[newIndex] = n[i];
				t_n[newIndex] = t[i];
				u_n[newIndex] = u[i];
				c_n[newIndex] = c[i];

				newIndex++;
			}

			InMesh.vertices = v_n;
			InMesh.normals = n_n;
			InMesh.tangents = t_n;
			InMesh.uv = u_n;
			InMesh.colors = c_n;
		}
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:59,代码来源:pb_MeshUtility.cs

示例9: MergeSubmeshes

        // Merge Submeshes into one
        public static void MergeSubmeshes(Mesh mesh)
        {
            List<int> triangles = new List<int> ();

            for (int i = 0; i < mesh.subMeshCount; ++i) {
            triangles.AddRange (mesh.GetTriangles (i));
            }

            mesh.triangles = triangles.ToArray ();
        }
开发者ID:randomize,项目名称:unity3d-ttftext,代码行数:11,代码来源:TTFTextInternalUtilities.cs

示例10: MeshData

 public MeshData (Mesh target)
 {
     vertexCount = target.vertexCount;
     vertices = target.vertices;
     normals = target.normals;
     tangents = target.tangents;
     uv = target.uv;
     uv2 = target.uv2;
     colors = target.colors;
     if(target.GetTopology(0) == MeshTopology.Triangles)
         triangles = target.GetTriangles(0); // Will the submesh always be 0?
     else
         triangles = new int[0];
 }
开发者ID:Chronovore,项目名称:armok-vision,代码行数:14,代码来源:MeshData.cs

示例11: Start

    void Start()
    {
        mesh=GetComponent<MeshFilter>().mesh;

         // unshare verts
         int subMeshCnt=mesh.subMeshCount;
         int[] tris=mesh.triangles;
         int triCnt=mesh.triangles.Length;
         int[] newTris=new int[triCnt];
         Vector3[] sourceVerts = mesh.vertices;
         Vector3[] sourceNorms = mesh.normals;
         Vector2[] sourceUVs = mesh.uv;

         Vector3[] newVertices = new Vector3[triCnt];
         Vector3[] newNorms = new Vector3[triCnt];
         Vector2[] newUVs = new Vector2[triCnt];

         int offsetVal=0;

         for (int k=0; k<subMeshCnt; k++)
         {
             int[] sourceIndices = mesh.GetTriangles(k);

             int[] newIndices = new int[sourceIndices.Length];

             // Create a unique vertex for every index in the original Mesh:
             for(int i = 0; i < sourceIndices.Length; i++)
             {
                 int newIndex=sourceIndices[i];
                 int iOffset=i+offsetVal;
                 newIndices[i] = iOffset;
                 newVertices[iOffset] = sourceVerts[newIndex];
                 newNorms[iOffset]=sourceNorms[newIndex];
                 newUVs[iOffset] = sourceUVs[newIndex];
             }
             offsetVal+=sourceIndices.Length;

             mesh.vertices = newVertices;
             mesh.normals=newNorms;
             mesh.uv = newUVs;

             mesh.SetTriangles(newIndices, k);
         }

         mesh.RecalculateNormals();
         mesh.RecalculateBounds();
         mesh.Optimize();
    }
开发者ID:MylesBell,项目名称:Unity,代码行数:48,代码来源:Water.cs

示例12: Combine

	Mesh Combine (Mesh mesh)
	{
		Mesh combinedMesh = InstanceMesh(mesh);
		SubmeshInfo[] initialSubmeshData = new SubmeshInfo[mesh.subMeshCount];
		for (int submeshIndex = 0; submeshIndex < mesh.subMeshCount; submeshIndex++)
		{
			initialSubmeshData[submeshIndex].triangles = new List<int>();
			int[] submeshTriangles = mesh.GetTriangles(submeshIndex);
			for (int triangleIndex = 0; triangleIndex < submeshTriangles.Length; triangleIndex++)
			{
				initialSubmeshData[submeshIndex].triangles.Add(submeshTriangles[triangleIndex]);
			}
		}
		List<int> affectedSubmeshes = new List<int>();
		SubmeshInfo[] combinedSubInfo = new SubmeshInfo[submeshesToCombine.Length];
		for (int combinedSubmeshesIndex = 0; combinedSubmeshesIndex < submeshesToCombine.Length; combinedSubmeshesIndex++)
		{
			combinedSubInfo[combinedSubmeshesIndex].triangles = new List<int>();
			for (int affectedSubmeshesIndex = 0; affectedSubmeshesIndex < submeshesToCombine[combinedSubmeshesIndex].submeshesToCombine.Length; affectedSubmeshesIndex++)
			{
				int affectedSubmesh = submeshesToCombine[combinedSubmeshesIndex].submeshesToCombine[affectedSubmeshesIndex];
				combinedSubInfo[combinedSubmeshesIndex].triangles.AddRange(initialSubmeshData[affectedSubmesh].triangles);
				affectedSubmeshes.Add(affectedSubmesh);
			}
		}
		int unaffectedSubmeshCount = mesh.subMeshCount - affectedSubmeshes.Count;
		int newSubmeshCount = submeshesToCombine.Length + unaffectedSubmeshCount;
		combinedMesh.subMeshCount = newSubmeshCount;

		int currentSubmesh = 0;
		for (int combinedSubmeshesIndex = 0; combinedSubmeshesIndex < combinedSubInfo.Length; combinedSubmeshesIndex++)
		{
			combinedMesh.SetTriangles(combinedSubInfo[combinedSubmeshesIndex].triangles, currentSubmesh);
			currentSubmesh++;
		}
		for (int originalSubmeshIndex = 0; originalSubmeshIndex < mesh.subMeshCount; originalSubmeshIndex++)
		{
			if (!affectedSubmeshes.Contains(originalSubmeshIndex))
			{
				combinedMesh.SetTriangles(initialSubmeshData[originalSubmeshIndex].triangles, currentSubmesh);
				currentSubmesh++;
			}
		}
		return combinedMesh;
	}
开发者ID:TheMasonX,项目名称:Project-True-Forest,代码行数:45,代码来源:CombineSubmeshes.cs

示例13: CreateMesh

        ///------------------------------------------------------------
        /// <summary>
        /// Create a new mesh with one of oldMesh's submesh
        /// </summary>
        ///--------------~~~~------------------------------------------------
        public static Mesh CreateMesh(Mesh oldMesh, int subIndex)
        {
            Mesh newMesh = new Mesh();

            List<int> triangles = new List<int>();
            triangles.AddRange(oldMesh.GetTriangles(subIndex)); // the triangles of the sub mesh

            List<Vector3> newVertices = new List<Vector3>();
            List<Vector2> newUvs = new List<Vector2>();

            // Mark's method.
            Dictionary<int, int> oldToNewIndices = new Dictionary<int, int>();
            int newIndex = 0;

            // Collect the vertices and uvs
            for (int i = 0; i < oldMesh.vertices.Length; i++)
            {
            if (triangles.Contains(i))
            {
                newVertices.Add(oldMesh.vertices[i]);
                newUvs.Add(oldMesh.uv[i]);
                oldToNewIndices.Add(i, newIndex);
                ++newIndex;
            }
            }

            int[] newTriangles = new int[triangles.Count];

            // Collect the new triangles indecies
            for (int i = 0; i < newTriangles.Length; i++)
            {
            newTriangles[i] = oldToNewIndices[triangles[i]];
            }
            // Assemble the new mesh with the new vertices/uv/triangles.
            newMesh.vertices = newVertices.ToArray();
            newMesh.uv = newUvs.ToArray();
            newMesh.triangles = newTriangles;

            // Re-calculate bounds and normals for the renderer.
            newMesh.RecalculateBounds();
            newMesh.RecalculateNormals();

            return newMesh;
        }
开发者ID:bman2338,项目名称:Foggle,代码行数:49,代码来源:MeshCreationHelper.cs

示例14: DuplicateMesh

	/// <summary>
	/// Duplicate a supplied mesh and return the duplicate
	/// </summary>
	/// <param name="mesh">
	/// A <see cref="Mesh"/>
	/// </param>
	/// <param name="newName">
	/// A <see cref="System.String"/>
	/// </param>
	/// <returns>
	/// A <see cref="Mesh"/>
	/// </returns>
	public static Mesh DuplicateMesh(Mesh mesh, string newName)
	{
		Mesh newMesh = new Mesh();
		
		newMesh.vertices = mesh.vertices;
		newMesh.colors = mesh.colors;
		newMesh.normals = mesh.normals;
		newMesh.subMeshCount = mesh.subMeshCount;
		for (int i=0; i<mesh.subMeshCount; i++) newMesh.SetTriangles(mesh.GetTriangles(i), i);
		newMesh.tangents = mesh.tangents;
		newMesh.uv = mesh.uv;
		newMesh.uv2 = mesh.uv2;
		
		newMesh.bindposes = mesh.bindposes;
		newMesh.boneWeights = mesh.boneWeights;
		
		newMesh.name = newName;
		
		return newMesh;
	}
开发者ID:dermisfit,项目名称:Paws,代码行数:32,代码来源:MeshHelpers.cs

示例15: ReverseMesh

        public ReverseMesh(Mesh meshToReverse)
        {
            mesh = meshToReverse;

            //reverse normals
            var normals = mesh.normals;
            for (int i = 0; i < normals.Length; i++)
                normals [i] = -normals [i];
            mesh.normals = normals;

            //rewind the triangles
            for (int m = 0; m < mesh.subMeshCount; m++)
            {
                int[] triangles = mesh.GetTriangles (m);
                for (int i = 0; i < triangles.Length; i += 3)
                {
                    int temp = triangles [i + 0];
                    triangles [i + 0] = triangles [i + 1];
                    triangles [i + 1] = temp;
                }
                mesh.SetTriangles (triangles, m);
            }
        }
开发者ID:HappyFaceIndustries,项目名称:KopernicusExpansion,代码行数:23,代码来源:ReverseMesh.cs


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