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


C# Mesh.SetTriangleStrip方法代码示例

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


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

示例1: Combine


//.........这里部分代码省略.........
                Matrix4x4 invTranspose = combine.transform;
                invTranspose = invTranspose.inverse.transpose;
                CopyNormal(combine.mesh.vertexCount, combine.mesh.normals, normals, ref offset, invTranspose);
            }

        }
        offset=0;
        foreach( MeshInstance combine in combines )
        {
            if (combine.mesh)
            {
                Matrix4x4 invTranspose = combine.transform;
                invTranspose = invTranspose.inverse.transpose;
                CopyTangents(combine.mesh.vertexCount, combine.mesh.tangents, tangents, ref offset, invTranspose);
            }

        }
        offset=0;
        foreach( MeshInstance combine in combines )
        {
            if (combine.mesh)
                Copy(combine.mesh.vertexCount, combine.mesh.uv, uv, ref offset);
        }

        offset=0;
        foreach( MeshInstance combine in combines )
        {
            if (combine.mesh)
                Copy(combine.mesh.vertexCount, combine.mesh.uv1, uv1, ref offset);
        }

        offset=0;
        foreach( MeshInstance combine in combines )
        {
            if (combine.mesh)
                CopyColors(combine.mesh.vertexCount, combine.mesh.colors, colors, ref offset);
        }

        int triangleOffset=0;
        int stripOffset=0;
        int vertexOffset=0;
        foreach( MeshInstance combine in combines )
        {
            if (combine.mesh)
            {
                if (generateStrips)
                {
                    int[] inputstrip = combine.mesh.GetTriangleStrip(combine.subMeshIndex);
                    if (stripOffset != 0)
                    {
                        if ((stripOffset & 1) == 1)
                        {
                            strip[stripOffset+0] = strip[stripOffset-1];
                            strip[stripOffset+1] = inputstrip[0] + vertexOffset;
                            strip[stripOffset+2] = inputstrip[0] + vertexOffset;
                            stripOffset+=3;
                        }
                        else
                        {
                            strip[stripOffset+0] = strip[stripOffset-1];
                            strip[stripOffset+1] = inputstrip[0] + vertexOffset;
                            stripOffset+=2;
                        }
                    }

                    for (int i=0;i<inputstrip.Length;i++)
                    {
                        strip[i+stripOffset] = inputstrip[i] + vertexOffset;
                    }
                    stripOffset += inputstrip.Length;
                }
                else
                {
                    int[]  inputtriangles = combine.mesh.GetTriangles(combine.subMeshIndex);
                    for (int i=0;i<inputtriangles.Length;i++)
                    {
                        triangles[i+triangleOffset] = inputtriangles[i] + vertexOffset;
                    }
                    triangleOffset += inputtriangles.Length;
                }

                vertexOffset += combine.mesh.vertexCount;
            }
        }

        Mesh mesh = new Mesh();
        mesh.name = "Combined Mesh";
        mesh.vertices = vertices;
        mesh.normals = normals;
        mesh.colors = colors;
        mesh.uv = uv;
        mesh.uv1 = uv1;
        mesh.tangents = tangents;
        if (generateStrips)
            mesh.SetTriangleStrip(strip, 0);
        else
            mesh.triangles = triangles;

        return mesh;
    }
开发者ID:Nimgoble,项目名称:War3FPS,代码行数:101,代码来源:MeshCombineUtility.cs

示例2: CreateVideoMesh

	void CreateVideoMesh()
	{
		videoPlaneMesh = new Mesh();
		
		videoPlaneMesh.vertices = new Vector3[] {
			new Vector3(-1, -1, 0),
			new Vector3(1, -1, 0),
			new Vector3(-1, 1, 0),
			new Vector3(1, 1, 0)};
		
		videoPlaneMesh.uv = new Vector2[] {
			new Vector2(0, 1),
			new Vector2(1, 1),
			new Vector2(0, 0),
			new Vector2(1, 0)};
		
		videoPlaneMesh.SetTriangleStrip(new int[] {0, 1, 2, 3}, 0);
	}
开发者ID:ece1778github,项目名称:The-Mobile-Stage,代码行数:18,代码来源:StringWrapper.cs

示例3: GeneratePlane

    private Mesh GeneratePlane()
    {
        Mesh mesh = new Mesh();
        mesh.vertices = new Vector3[4] {
            new Vector3(-0.5f, 0.5f, 0.01f),
            new Vector3(-0.5f, -0.5f, 0.01f),
            new Vector3(0.5f, -0.5f, 0.01f),
            new Vector3(0.5f, 0.5f, 0.01f)

        };
        mesh.SetTriangleStrip(new int[4] {0, 1, 3, 2}, 0);
        mesh.RecalculateNormals();

        return mesh;
    }
开发者ID:BenjaminTaylor,项目名称:TinyQuest,代码行数:15,代码来源:Roga2dRenderObject.cs

示例4: SetMesh

 /// <summary>
 /// メッシュをセットする
 /// </summary>
 /// <param name="mesh">設定したいメッシュ</param>
 public void SetMesh(Mesh mesh)
 {
     mesh.vertices = this.vertices;
     if (this.useTriangleStrip)
         mesh.SetTriangleStrip(this.indices, 0);
     else
         mesh.SetTriangles(this.indices, 0);
     mesh.uv = this.uvs;
     mesh.normals = this.normals;
 }
开发者ID:GRGSIBERIA,项目名称:Lyapunov-Terrain,代码行数:14,代码来源:VerticesAbs.cs

示例5: Combine


//.........这里部分代码省略.........
		}

		offset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
			{
				Matrix4x4 invTranspose = combine.transform;
				invTranspose = invTranspose.inverse.transpose;
				CopyNormal(combine.mesh.vertexCount, combine.mesh.normals, normals, ref offset, invTranspose);
			}
				
		}
		offset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
			{
				Matrix4x4 invTranspose = combine.transform;
				invTranspose = invTranspose.inverse.transpose;
				CopyTangents(combine.mesh.vertexCount, combine.mesh.tangents, tangents, ref offset, invTranspose);
			}
				
		}
		offset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
				Copy(combine.mesh.vertexCount, combine.mesh.uv, uv, ref offset);
		}
		
		offset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
				Copy(combine.mesh.vertexCount, combine.mesh.uv1, uv1, ref offset);
		}
		
		int triangleOffset=0;
		int stripOffset=0;
		int vertexOffset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
			{
				if (generateStrips)
				{
					int[] inputstrip = combine.mesh.GetTriangleStrip(combine.subMeshIndex);
                    //int[] inputstrip = combine.mesh.GetTriangles(combine.subMeshIndex);
					if (stripOffset != 0)
					{
						if ((stripOffset & 1) == 1)
						{
							strip[stripOffset+0] = strip[stripOffset-1];
							strip[stripOffset+1] = inputstrip[0] + vertexOffset;
							strip[stripOffset+2] = inputstrip[0] + vertexOffset;
							stripOffset+=3;
						}
						else
						{
							strip[stripOffset+0] = strip[stripOffset-1];
							strip[stripOffset+1] = inputstrip[0] + vertexOffset;
							stripOffset+=2;
						}
					}
					
					for (int i=0;i<inputstrip.Length;i++)
					{
						strip[i+stripOffset] = inputstrip[i] + vertexOffset;
					}
					stripOffset += inputstrip.Length;
				}
				else
				{
					int[]  inputtriangles = combine.mesh.GetTriangles(combine.subMeshIndex);
					for (int i=0;i<inputtriangles.Length;i++)
					{
						triangles[i+triangleOffset] = inputtriangles[i] + vertexOffset;
					}
					triangleOffset += inputtriangles.Length;
				}
				
				vertexOffset += combine.mesh.vertexCount;
			}
		}
		Mesh mesh = new Mesh();
		mesh.name = "Combined Mesh";
		mesh.vertices = vertices;
		mesh.normals = normals;
		mesh.tangents = tangents;
		mesh.uv = uv;
		mesh.uv1 = uv1;
		if (generateStrips)
			mesh.SetTriangleStrip(strip, 0);
		else
			mesh.triangles = triangles;
        sw.Stop();
        Mogo.Util.LoggerHelper.Debug("Combine Mesh cost: " + sw.ElapsedMilliseconds);
        return mesh;
	}
开发者ID:lbddk,项目名称:ahzs-client,代码行数:101,代码来源:MeshCombineUtility.cs

示例6: Combine


//.........这里部分代码省略.........
             Matrix4x4 matrix4x41 = meshInstance4.transform.inverse.transpose;
             MeshCombineUtility.CopyTangents(meshInstance4.mesh.vertexCount, meshInstance4.mesh.tangents, vector4Array, ref num2, matrix4x41);
         }
     }
     num2 = 0;
     MeshCombineUtility.MeshInstance[] meshInstanceArray5 = combines;
     for (int n = 0; n < (int)meshInstanceArray5.Length; n++)
     {
         MeshCombineUtility.MeshInstance meshInstance5 = meshInstanceArray5[n];
         if (meshInstance5.mesh)
         {
             MeshCombineUtility.Copy(meshInstance5.mesh.vertexCount, meshInstance5.mesh.uv, vector2Array, ref num2);
         }
     }
     num2 = 0;
     MeshCombineUtility.MeshInstance[] meshInstanceArray6 = combines;
     for (int o = 0; o < (int)meshInstanceArray6.Length; o++)
     {
         MeshCombineUtility.MeshInstance meshInstance6 = meshInstanceArray6[o];
         if (meshInstance6.mesh)
         {
             MeshCombineUtility.Copy(meshInstance6.mesh.vertexCount, meshInstance6.mesh.uv1, vector2Array1, ref num2);
         }
     }
     num2 = 0;
     MeshCombineUtility.MeshInstance[] meshInstanceArray7 = combines;
     for (int p = 0; p < (int)meshInstanceArray7.Length; p++)
     {
         MeshCombineUtility.MeshInstance meshInstance7 = meshInstanceArray7[p];
         if (meshInstance7.mesh)
         {
             MeshCombineUtility.CopyColors(meshInstance7.mesh.vertexCount, meshInstance7.mesh.colors, colorArray, ref num2);
         }
     }
     int length2 = 0;
     int length3 = 0;
     int num3 = 0;
     MeshCombineUtility.MeshInstance[] meshInstanceArray8 = combines;
     for (int q = 0; q < (int)meshInstanceArray8.Length; q++)
     {
         MeshCombineUtility.MeshInstance meshInstance8 = meshInstanceArray8[q];
         if (meshInstance8.mesh)
         {
             if (!generateStrips)
             {
                 int[] triangles = meshInstance8.mesh.GetTriangles(meshInstance8.subMeshIndex);
                 for (int r = 0; r < (int)triangles.Length; r++)
                 {
                     numArray[r + length2] = triangles[r] + num3;
                 }
                 length2 = length2 + (int)triangles.Length;
             }
             else
             {
                 int[] triangleStrip = meshInstance8.mesh.GetTriangleStrip(meshInstance8.subMeshIndex);
                 if (length3 != 0)
                 {
                     if ((length3 & 1) != 1)
                     {
                         numArray1[length3] = numArray1[length3 - 1];
                         numArray1[length3 + 1] = triangleStrip[0] + num3;
                         length3 = length3 + 2;
                     }
                     else
                     {
                         numArray1[length3] = numArray1[length3 - 1];
                         numArray1[length3 + 1] = triangleStrip[0] + num3;
                         numArray1[length3 + 2] = triangleStrip[0] + num3;
                         length3 = length3 + 3;
                     }
                 }
                 for (int s = 0; s < (int)triangleStrip.Length; s++)
                 {
                     numArray1[s + length3] = triangleStrip[s] + num3;
                 }
                 length3 = length3 + (int)triangleStrip.Length;
             }
             num3 = num3 + meshInstance8.mesh.vertexCount;
         }
     }
     Mesh mesh = new Mesh()
     {
         name = "Combined Mesh",
         vertices = vector3Array,
         normals = vector3Array1,
         colors = colorArray,
         uv = vector2Array,
         uv1 = vector2Array1,
         tangents = vector4Array
     };
     if (!generateStrips)
     {
         mesh.triangles = numArray;
     }
     else
     {
         mesh.SetTriangleStrip(numArray1, 0);
     }
     return mesh;
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:101,代码来源:MeshCombineUtility.cs

示例7: CreateCombinedMesh

    /// <summary>
    /// Generate a single mesh from the instances that have been added to the combiner so far.
    /// </summary>
    /// <returns>A combined mesh.</returns>
    public Mesh CreateCombinedMesh()
    {
        var mesh = new Mesh
                       {
                           name = "Combined Mesh",
                           vertices = _vertices.ToArray(),
                           normals = _normals.ToArray(),
                           colors = _colors.ToArray(),
                           uv = _uv.ToArray(),
                           uv1 = _uv1.ToArray(),
                           tangents = _tangents.ToArray(),
                           subMeshCount = (_generateStrips) ? _strip.Count : _triangles.Count
                       };

        if (_generateStrips)
        {
            foreach (var targetSubmesh in _strip)
                mesh.SetTriangleStrip(targetSubmesh.Value.ToArray(), targetSubmesh.Key);
        }
        else
        {
            foreach (var targetSubmesh in _triangles)
                mesh.SetTriangles(targetSubmesh.Value.ToArray(), targetSubmesh.Key);
        }

        return mesh;
    }
开发者ID:merveilles,项目名称:OZML,代码行数:31,代码来源:MeshCombineUtility.cs

示例8: Combine


//.........这里部分代码省略.........
			if (combine.mesh)
				Copy(combine.mesh.vertexCount, combine.mesh.uv, uv, ref offset);
		}
		
		offset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
				Copy(combine.mesh.vertexCount, combine.mesh.uv2, uv1, ref offset);
		}
		
		offset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
				CopyColors(combine.mesh.vertexCount, combine.mesh.colors, colors, ref offset);
		}
		
		int triangleOffset=0;
		int stripOffset=0;
		int vertexOffset=0;
		foreach( MeshInstance combine in combines )
		{
			if (combine.mesh)
			{
				if (generateStrips)
				{
					#if UNITY_4_2 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
					int[] inputstrip = combine.mesh.GetTriangleStrip(combine.subMeshIndex);
					#endif

					#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5
					int[] inputstrip = combine.mesh.GetTriangles(combine.subMeshIndex);
					#endif

					if (stripOffset != 0)
					{
						if ((stripOffset & 1) == 1)
						{
							strip[stripOffset+0] = strip[stripOffset-1];
							strip[stripOffset+1] = inputstrip[0] + vertexOffset;
							strip[stripOffset+2] = inputstrip[0] + vertexOffset;
							stripOffset+=3;
						}
						else
						{
							strip[stripOffset+0] = strip[stripOffset-1];
							strip[stripOffset+1] = inputstrip[0] + vertexOffset;
							stripOffset+=2;
						}
					}
					
					for (int i=0;i<inputstrip.Length;i++)
					{
						strip[i+stripOffset] = inputstrip[i] + vertexOffset;
					}
					stripOffset += inputstrip.Length;
				}
				else
				{
					#if UNITY_4_2 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
					int[]  inputtriangles = combine.mesh.GetTriangleStrip(combine.subMeshIndex);
					#endif

					#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5
					int[]  inputtriangles = combine.mesh.GetTriangles(combine.subMeshIndex);
					#endif

					for (int i=0;i<inputtriangles.Length;i++)
					{
						triangles[i+triangleOffset] = inputtriangles[i] + vertexOffset;
					}
					triangleOffset += inputtriangles.Length;
				}
				
				vertexOffset += combine.mesh.vertexCount;
			}
		}
		
		Mesh mesh = new Mesh();
		mesh.name = "Combined Mesh";
		mesh.vertices = vertices;
		mesh.normals = normals;
		mesh.colors = colors;
		mesh.uv = uv;
		mesh.uv2 = uv1;
		mesh.tangents = tangents;
		if (generateStrips)
			#if UNITY_4_2 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
			mesh.SetTriangleStrip(strip, 0);
			#endif

			#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5
			mesh.SetTriangles(strip, 0);
			#endif
		else
			mesh.triangles = triangles;
		
		return mesh;
	}
开发者ID:gato0429,项目名称:GlobalGame2016,代码行数:101,代码来源:uteMeshCombineUtility.cs

示例9: generateMeshData

	void generateMeshData()
	{
		Debug.Log ("Updating mesh data.");

		// Create a new mesh.
		Mesh mesh = new Mesh();

		/* Create the plane's true vertices by looping through the generated vertex list and duplicating each element,
		 * then pushing the duplicate through the z by the desired depth of the plane. */


		// TODO will need 2 submeshes. meshVertices will contain all visible vertices * 3, and the vertices will be generated so that it first generates the visible vertex, then the visible vertex with its z value set to the z depth, then the visible vertex with its y value set off the screen.
		// TODO looping through the vertices in the visible vertex list, and keeping track of i such that for each vertex i is at the visible vertex in the vertices array, the top (grass) indices will be i, i + 1; the side (dirt) will be i + 2, i

		Vector3[] meshVertices = new Vector3[visibleVertices.Count * 3];

		int[] grassMeshIndices = new int[visibleVertices.Count * 2];
		int[] dirtMeshIndices = new int[grassMeshIndices.Length];

		Vector2[] meshUV = new Vector2[meshVertices.Length];

		int i = 0;
		int j = 0;
		int u = (Mathf.Abs (visiblePoints.First.Value.x) % (xSpacing * 2)) > 0 ? 1 : 0;
		LinkedList<Vector2>.Enumerator vertex = visibleVertices.GetEnumerator();
		while (vertex.MoveNext())
		{
			// Write the near vertex.
			meshVertices[i].x = vertex.Current.x;
			meshVertices[i].y = vertex.Current.y;
			meshVertices[i].z = 0.0f;	// TODO make this based on current plane. (0.0f)

			// Write the near index. (shared)
			grassMeshIndices[j] = i;
			dirtMeshIndices[j] = i + 2;

			// Write the near (bottom) UV.
			meshUV[i].x = u;
			meshUV[i].y = 0.0f;

			++i;
			++j;

			// Write the far vertex.
			meshVertices[i].x = vertex.Current.x;
			meshVertices[i].y = vertex.Current.y;
			meshVertices[i].z = 0.0f + zDepth;	// TODO make this based on current plane. (0.0f)

			// Write the far index.
			grassMeshIndices[j] = i;

			// Write the far (top) UV.
			meshUV[i].x = u;
			meshUV[i].y = 1.0f;

			++i;
			++j;

			// Write the low vertex.
			meshVertices[i].x = vertex.Current.x;
			meshVertices[i].y = -10.0f;	// TODO make this based on....something?
			meshVertices[i].z = 0.0f;	// TODO make this based on the current plane. (0.0f)

			// Write the low index.
			dirtMeshIndices[j - 1] = i - 2;

			// Write the low (top) UV. (the texture will be upside down!)
			meshUV[i].x = u;
			meshUV[i].y = 1.0f;

			++i;

			// Move the u to the opposite side.
			u = u == 0 ? 1 : 0;
		}

		// Set the vertices.
		mesh.vertices = meshVertices;

		// Set the number of submeshes.
		mesh.subMeshCount = 2;

		// Set the grass and dirt indices.
		mesh.SetTriangleStrip(grassMeshIndices, 0);	// Obsolete function is actually useful!
		mesh.SetTriangleStrip(dirtMeshIndices, 1);

		// Set the UVs.
		mesh.uv = meshUV;

		// Calculate the normals.
		mesh.RecalculateNormals();

		// Set the meshfilter and meshcollider meshes to the generated mesh.
		meshFilter.mesh = mesh;
		GetComponent<MeshCollider>().sharedMesh = mesh;
	}
开发者ID:Abengoshis,项目名称:GrowingGarden,代码行数:96,代码来源:scrLandscapeGenerator.cs


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