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


C# Mesh.GetIndices方法代码示例

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


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

示例1: CreateOverlayMesh

		/**
		 *	Creates a new mesh using only the @src positions, normals, and a new color array.
		 */
		public static Mesh CreateOverlayMesh(Mesh src)
		{
			Mesh m = new Mesh();
			m.name = "Overlay Mesh: " + src.name;
			m.vertices = src.vertices;
			m.normals = src.normals;
			m.colors = z_Util.Fill<Color>(new Color(0f, 0f, 0f, 0f), m.vertexCount);
			m.subMeshCount = src.subMeshCount;
			for(int i = 0; i < src.subMeshCount; i++)
			{
				if(src.GetTopology(i) == MeshTopology.Triangles)
				{
					int[] tris = src.GetIndices(i);
					int[] lines = new int[tris.Length * 2];
					int index = 0;
					for(int n = 0; n < tris.Length; n+=3)
					{
						lines[index++] = tris[n+0];
						lines[index++] = tris[n+1];
						lines[index++] = tris[n+1];
						lines[index++] = tris[n+2];
						lines[index++] = tris[n+2];
						lines[index++] = tris[n+0];
					}
					m.SetIndices(lines, MeshTopology.Lines, i);
				}
				else
				{
					m.SetIndices(src.GetIndices(i), src.GetTopology(i), i);
				}
			}
			return m;
		}
开发者ID:alex-carlson,项目名称:PixelitisGGJ,代码行数:36,代码来源:z_MeshUtility.cs

示例2: GetMeshTriangleBoundsList

    public static List<Bounds> GetMeshTriangleBoundsList(Mesh mesh)
    {
        List<Bounds> ret = new List<Bounds>();

        MeshTopology meshTopo = mesh.GetTopology(0);
        int stride = 3;
        if (meshTopo == MeshTopology.Triangles) stride = 3;
        else if (meshTopo == MeshTopology.Quads) stride = 4;
        else return ret;

        for (int subMesh = 0; subMesh < mesh.subMeshCount; ++subMesh)
        {
            var indices = mesh.GetIndices(subMesh);
            var vertices = mesh.vertices;
            for (int i = 0; i + stride <= indices.Length; i += stride)
            {
                Bounds bounds = new Bounds(vertices[indices[i]], Vector3.zero);
                for (int j = 1; j < stride; ++j)
                {
                    bounds.Encapsulate(vertices[indices[i + j]]);
                }
                ret.Add(bounds);
            }
        }

        return ret;
    }
开发者ID:WaylandGod,项目名称:learn_unity,代码行数:27,代码来源:SpatialUtils.cs

示例3: VertexHelper

 public VertexHelper(Mesh m)
 {
   this.m_Positions.AddRange((IEnumerable<Vector3>) m.vertices);
   this.m_Colors.AddRange((IEnumerable<Color32>) m.colors32);
   this.m_Uv0S.AddRange((IEnumerable<Vector2>) m.uv);
   this.m_Uv1S.AddRange((IEnumerable<Vector2>) m.uv2);
   this.m_Normals.AddRange((IEnumerable<Vector3>) m.normals);
   this.m_Tangents.AddRange((IEnumerable<Vector4>) m.tangents);
   this.m_Indices.AddRange((IEnumerable<int>) m.GetIndices(0));
 }
开发者ID:NetherDrk,项目名称:Eternal-Empire,代码行数:10,代码来源:VertexHelper.cs

示例4: VertexHelper

 public VertexHelper(Mesh m)
 {
     this.m_Positions = ListPool<Vector3>.Get();
     this.m_Colors = ListPool<Color32>.Get();
     this.m_Uv0S = ListPool<Vector2>.Get();
     this.m_Uv1S = ListPool<Vector2>.Get();
     this.m_Normals = ListPool<Vector3>.Get();
     this.m_Tangents = ListPool<Vector4>.Get();
     this.m_Indices = ListPool<int>.Get();
     this.m_Positions.AddRange(m.vertices);
     this.m_Colors.AddRange(m.colors32);
     this.m_Uv0S.AddRange(m.uv);
     this.m_Uv1S.AddRange(m.uv2);
     this.m_Normals.AddRange(m.normals);
     this.m_Tangents.AddRange(m.tangents);
     this.m_Indices.AddRange(m.GetIndices(0));
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:17,代码来源:VertexHelper.cs

示例5: ShapeCacheData

 public ShapeCacheData(Mesh mesh)
 {
     if (mesh)
     {
         vertices = mesh.vertices;
         normals  = mesh.normals;
         tangents = mesh.tangents;
         uv       = mesh.uv;
         indices  = mesh.GetIndices(0);
     }
     else
     {
         // An empty mesh was given; replaces with a two-sided quad.
         vertices = new Vector3[] {
             new Vector3 (-1, +1, 0), new Vector3 (+1, +1, 0),
             new Vector3 (-1, -1, 0), new Vector3 (+1, -1, 0),
             new Vector3 (+1, +1, 0), new Vector3 (-1, +1, 0),
             new Vector3 (+1, -1, 0), new Vector3 (-1, -1, 0)
         };
         normals = new Vector3[] {
              Vector3.forward,  Vector3.forward,
              Vector3.forward,  Vector3.forward,
             -Vector3.forward, -Vector3.forward,
             -Vector3.forward, -Vector3.forward,
         };
         tangents = new Vector4[] {
             new Vector4( 1, 0, 0, 1), new Vector4( 1, 0, 0, 1),
             new Vector4( 1, 0, 0, 1), new Vector4( 1, 0, 0, 1),
             new Vector4(-1, 0, 0, 1), new Vector4(-1, 0, 0, 1),
             new Vector4(-1, 0, 0, 1), new Vector4(-1, 0, 0, 1)
         };
         uv = new Vector2[] {
             new Vector2(0, 1), new Vector2(1, 1),
             new Vector2(0, 0), new Vector2(1, 0),
             new Vector2(1, 1), new Vector2(0, 1),
             new Vector2(1, 0), new Vector2(0, 0)
         };
         indices = new int[] {0, 1, 2, 3, 2, 1, 4, 5, 6, 7, 6, 5};
     }
 }
开发者ID:dgkae,项目名称:Teatro,代码行数:40,代码来源:BulkMesh.cs

示例6: CreateTileMesh

    public static Mesh CreateTileMesh(int _divX, int _divY, Color _vertCol)
    {
        int vertNum = (_divX+1)*(_divY+1);
        int quadNum = _divX*_divY;
        int[] triangles = new int[quadNum*6];
        Vector3[] vertices = new Vector3[vertNum];
        Vector2[] uv = new Vector2[vertNum];
        Color[] colors = new Color[vertNum];
        Vector3[] normals = new Vector3[vertNum];
        Vector4[] tangents = new Vector4[vertNum];

        for(int yy = 0; yy < (_divY+1); ++yy){
            for(int xx = 0; xx < (_divX+1); ++xx){
                Vector2 uvPos = new Vector2((float)xx/(float)_divX,(float)yy/(float)_divY);
                vertices[yy*(_divX+1)+xx] = new Vector3(uvPos.x-0.5f,uvPos.y-0.5f,0.0f);
                uv[yy*(_divX+1)+xx] = uvPos;
                colors[yy*(_divX+1)+xx] = _vertCol;
                normals[yy*(_divX+1)+xx] = new Vector3(0.0f,0.0f,-1.0f);
                tangents[yy*(_divX+1)+xx] = new Vector4(1.0f,0.0f,0.0f);
                if((xx<_divX)&&(yy<_divY)){
                    int[] sw={0,0,1,1,1,0,1,1,0,0,0,1};
                    for(int ii = 0; ii < 6; ++ii){
                        triangles[(yy*_divX+xx)*6+ii] = (yy+sw[ii*2+1])*(_divX+1)+(xx+sw[ii*2+0]);
                    }
                }
            }
        }

        Mesh mesh = new Mesh();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.uv = uv;
        mesh.colors = colors;
        mesh.normals = normals;
        mesh.tangents = tangents;
        //		mesh.RecalculateNormals ();
        mesh.RecalculateBounds ();
        mesh.Optimize();
        mesh.SetIndices(mesh.GetIndices(0),MeshTopology.Triangles,0);
        return mesh;
    }
开发者ID:hiyijia,项目名称:unity_mylib,代码行数:41,代码来源:TmUtils.cs

示例7: DuplicateMesh

	// Duplicate mesh 
	public static Mesh DuplicateMesh( Mesh a_rMeshToDuplicate )
	{
		Mesh rNewMesh = new Mesh( );

		if( a_rMeshToDuplicate == null )
		{
			return rNewMesh;
		}

		rNewMesh.vertices  = a_rMeshToDuplicate.vertices;
		rNewMesh.uv        = a_rMeshToDuplicate.uv;
		rNewMesh.uv2       = a_rMeshToDuplicate.uv2;
		rNewMesh.colors32  = a_rMeshToDuplicate.colors32;
		rNewMesh.tangents  = a_rMeshToDuplicate.tangents;
		rNewMesh.normals   = a_rMeshToDuplicate.normals;

		rNewMesh.boneWeights = a_rMeshToDuplicate.boneWeights;
		rNewMesh.bindposes   = a_rMeshToDuplicate.bindposes;
		rNewMesh.bounds      = a_rMeshToDuplicate.bounds;

		rNewMesh.name        = a_rMeshToDuplicate.name;
	
		// Iterate submeshes to copy their triangles
		int iSubMeshCount      = a_rMeshToDuplicate.subMeshCount;
		rNewMesh.subMeshCount  = iSubMeshCount;
		for( int iSubMeshIndex = 0; iSubMeshIndex < iSubMeshCount; ++iSubMeshIndex )
		{
			#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
			rNewMesh.SetTriangles( a_rMeshToDuplicate.GetTriangles( iSubMeshIndex ), iSubMeshIndex );
			#else
			rNewMesh.SetIndices( a_rMeshToDuplicate.GetIndices( iSubMeshIndex ), a_rMeshToDuplicate.GetTopology( iSubMeshIndex ), iSubMeshIndex );
			#endif
		}

		rNewMesh.RecalculateBounds( );
		rNewMesh.Optimize( );
		
		return rNewMesh;
	}
开发者ID:kenzo0107,项目名称:MamekoRun2D,代码行数:40,代码来源:Uni2DEditorResourceCopyUtils.cs

示例8: Cut

        /// <summary>
        /// Cut the specified victim, blade_plane and capMaterial.
        /// </summary>
        /// <param name="victim">Victim.</param>
        /// <param name="blade_plane">Blade plane.</param>
        /// <param name="capMaterial">Cap material.</param>
        public static GameObject[] Cut(GameObject victim, Vector3 anchorPoint, Vector3 normalDirection, Material capMaterial)
        {
            // set the blade relative to victim
            blade = new Plane(victim.transform.InverseTransformDirection(-normalDirection),
                victim.transform.InverseTransformPoint(anchorPoint));

            // get the victims mesh
            victim_mesh = victim.GetComponent<MeshFilter>().mesh;

            // reset values
            new_vertices.Clear();
            left_side.ClearAll();
            right_side.ClearAll();

            bool[] sides = new bool[3];
            int[] indices;
            int   p1,p2,p3;

            // go throught the submeshes
            for(int sub=0; sub<victim_mesh.subMeshCount; sub++){

                indices = victim_mesh.GetIndices(sub);

                left_side.subIndices.Add(new List<int>());
                right_side.subIndices.Add(new List<int>());

                for(int i=0; i<indices.Length; i+=3){

                    p1 = indices[i];
                    p2 = indices[i+1];
                    p3 = indices[i+2];

                    sides[0] = blade.GetSide(victim_mesh.vertices[p1]);
                    sides[1] = blade.GetSide(victim_mesh.vertices[p2]);
                    sides[2] = blade.GetSide(victim_mesh.vertices[p3]);

                    // whole triangle
                    if(sides[0] == sides[1] && sides[0] == sides[2]){

                        if(sides[0]){ // left side
                            left_side.AddTriangle(p1,p2,p3,sub);
                        }else{
                            right_side.AddTriangle(p1,p2,p3,sub);
                        }

                    }else{ // cut the triangle

                        Cut_this_Face(sub, sides, p1, p2, p3);
                    }
                }
            }

            Material[] mats = victim.GetComponent<MeshRenderer>().sharedMaterials;

            if(mats[mats.Length-1].name != capMaterial.name){ // add cap indices

                left_side.subIndices.Add(new List<int>());
                right_side.subIndices.Add(new List<int>());

                Material[] newMats = new Material[mats.Length+1];
                mats.CopyTo(newMats, 0);
                newMats[mats.Length] = capMaterial;
                mats = newMats;
            }

            // cap the opennings
            Capping();

            // Left Mesh

            Mesh left_HalfMesh = new Mesh();
            left_HalfMesh.name =  "Split Mesh Left";
            left_HalfMesh.vertices  = left_side.vertices.ToArray();
            left_HalfMesh.triangles = left_side.triangles.ToArray();
            left_HalfMesh.normals   = left_side.normals.ToArray();
            left_HalfMesh.uv        = left_side.uvs.ToArray();

            left_HalfMesh.subMeshCount = left_side.subIndices.Count;
            for(int i=0; i<left_side.subIndices.Count; i++)
                left_HalfMesh.SetIndices(left_side.subIndices[i].ToArray(), MeshTopology.Triangles, i);

            // Right Mesh

            Mesh right_HalfMesh = new Mesh();
            right_HalfMesh.name = "Split Mesh Right";
            right_HalfMesh.vertices  = right_side.vertices.ToArray();
            right_HalfMesh.triangles = right_side.triangles.ToArray();
            right_HalfMesh.normals   = right_side.normals.ToArray();
            right_HalfMesh.uv        = right_side.uvs.ToArray();

            right_HalfMesh.subMeshCount = right_side.subIndices.Count;
            for(int i=0; i<right_side.subIndices.Count; i++)
                right_HalfMesh.SetIndices(right_side.subIndices[i].ToArray(), MeshTopology.Triangles, i);

//.........这里部分代码省略.........
开发者ID:Zagorouiko,项目名称:Unity_SteamVR_Prototypes,代码行数:101,代码来源:MeshCut.cs

示例9: ConvertTrianglesToVoxels

	public void ConvertTrianglesToVoxels(Blocks MyBlocks, Mesh InputMesh) {
		resolution = Mathf.Pow (resolution, 2);
		InputMesh.RecalculateBounds ();
		MyBounds = InputMesh.bounds;
		// draws the bounding box
		DebugShapes.DrawCube (transform.position + InputMesh.bounds.center, InputMesh.bounds.extents, Color.green);


		Debug.LogError ("Converting mesh to voxels");
		MyBlocks = GetManager.GetDataManager().BlockStructuresList[BlockStructureIndex].MyBlocks;
		float SizeOfGrid = 1f;
		//real block size is x2 whatever i set here
		
		Vector3 Bounds = InputMesh.bounds.extents;

		float LargestSize = Bounds.x;
		if (LargestSize < Bounds.y)
			LargestSize = Bounds.y;
		if (LargestSize < Bounds.z)
			LargestSize = Bounds.z;
		//LargestSize = Mathf.CeilToInt (LargestSize);
		GridLength = Mathf.CeilToInt (LargestSize * resolution);
		Vector3 GridSize = new Vector3 (GridLength, GridLength, GridLength);
		BlockLength = Mathf.CeilToInt (LargestSize) / resolution;
		BlockSize = new Vector3 (BlockLength, BlockLength, BlockLength);


		//GridSize = GridSize / 2f;

		// calculate block size depending on the bounds size of the model
		// so if bounds size is 3, have block size as 3
		// then set grid size to block size divided by resolution
		
		MyBlocks.Size = GridSize;
		MyBlocks.InitilizeData();

		Vector3[] Verticies = InputMesh.vertices;
		int[] Indicies = InputMesh.GetIndices (0);
		Vector3[] Normals = InputMesh.normals;

		// i have to make the grid size the same as the bounding box
		 
		//Vector3 BlockSize = new Vector3(resolution, resolution, resolution); 
		//BlockSize = 2f*(BlockSize/(MyBounds.extents.magnitude));
		Debug.LogError("Block Size is: " + BlockSize.ToString());
		Debug.LogError("Indicies Size is: " + Indicies.Length.ToString());
		for (int z = 0; z < Indicies.Length; z += 3) {
			Vector3 Vertex1 = Verticies[Indicies[z+0]];
			Vector3 Vertex2 = Verticies[Indicies[z+1]];
			Vector3 Vertex3 = Verticies[Indicies[z+2]];
			if (IsNormalsDebug) {
				Debug.DrawLine (transform.position+Vertex1,transform.position+Vertex1 + Normals[Indicies[z+0]]*NormalsLength, Color.blue, 5);
				Debug.DrawLine (transform.position+Vertex2,transform.position+Vertex2 + Normals[Indicies[z+1]]*NormalsLength, Color.blue, 5);
				Debug.DrawLine (transform.position+Vertex3,transform.position+Vertex3 + Normals[Indicies[z+2]]*NormalsLength, Color.blue, 5);
			}

			//Debug.LogError ("Triangle " + (z/3) + ": " + Vertex1.ToString() + "---" + Vertex2.ToString() + "---" + Vertex3.ToString());

			//Debug.DrawLine (transform.position+new Vector3(startX, startY, startZ),transform.position+new Vector3(endX,endY,endZ), Color.red, 5);
			// should only do this for the blocks around the triangles
			// need to optimize this asap
			// for blocks around triangle?
			//Vector3 StartBlock = new Vector3();
			//StartBlock.x = Mathf.FloorToInt();	// minimum size of the Vertex AARB

			// find the size of each triangle as an Axis Aligned Rectangle Bounds - AARB
			Vector3 TrianglePosition = (Vertex2 + Vertex3)/2f;
			Vector3 TriangleMinimum = new Vector3 (Mathf.Min (Vertex1.x, Vertex2.x, Vertex3.x), Mathf.Min (Vertex1.y, Vertex2.y, Vertex3.y), Mathf.Min (Vertex1.z, Vertex2.z, Vertex3.z));
			Vector3 TriangleMaximum = new Vector3 (Mathf.Max (Vertex1.x, Vertex2.x, Vertex3.x), Mathf.Max (Vertex1.y, Vertex2.y, Vertex3.y), Mathf.Max (Vertex1.z, Vertex2.z, Vertex3.z));
			Vector3 TriangleSize = new Vector3();
			TriangleSize = TriangleMaximum - TriangleMinimum;
			TriangleSize *= 0.5f;
			TrianglePosition = TriangleMinimum + TriangleSize;
			TrianglePosition += InputMesh.bounds.extents;
			int StartX =  Mathf.FloorToInt((TrianglePosition.x-TriangleSize.x));	// before it was 0
			int EndX = Mathf.CeilToInt((TrianglePosition.x+TriangleSize.x)/resolution);//MyBlocks.Size.x; i++)
			int StartY =  Mathf.FloorToInt((TrianglePosition.y-TriangleSize.y));	
			int EndY = Mathf.CeilToInt((TrianglePosition.y+TriangleSize.y)/resolution);
			int StartZ =  Mathf.FloorToInt((TrianglePosition.z-TriangleSize.z));
			int EndZ = Mathf.CeilToInt((TrianglePosition.z+TriangleSize.z)/resolution);
			StartX = 0; StartY = 0; StartZ = 0;
			EndX = Mathf.CeilToInt(MyBlocks.Size.x)-1; EndY = Mathf.CeilToInt(MyBlocks.Size.y)-1; EndZ = Mathf.CeilToInt(MyBlocks.Size.z)-1;

			Debug.LogError (z + " || StartX: " + StartX + " - EndX: " + EndX + 
			                " || StartY: " + StartY + " - EndY: " + EndY + 
			                " || StartZ: " + StartZ + " - EndZ: " + EndZ);

			Debug.Break ();
			for (int i = StartX; i <= EndX; i++)
				for (int j = StartY; j <= EndY; j++)
					for (int k = StartZ; k <= EndZ; k++) 
				{
					if (MyBlocks.GetBlockType(new Vector3(i,j,k)) == 0) {
						Vector3 BlockPosition = BlockSize + MyBounds.center;
						BlockPosition += 2f*(new Vector3(i*BlockSize.x,j*BlockSize.y,k*BlockSize.z));
						if (IsTriangleInGrid(BlockPosition, BlockSize, TrianglePosition, TriangleSize)) {
								MyBlocks.UpdateBlock(new Vector3(i,j,k), 1);
						}// else
								//MyBlocks.UpdateBlock(new Vector3(i,j,k), 0);
					}
//.........这里部分代码省略.........
开发者ID:Deus0,项目名称:Zeltex,代码行数:101,代码来源:Voxelization.cs

示例10: Copy

		/**
		 * Duplicate @src mesh to @dstMesh
		 */
		public static void Copy(Mesh destMesh, Mesh src)
		{
			destMesh.Clear();

			destMesh.name = src.name;
			destMesh.vertices = src.vertices;
			destMesh.uv = src.uv;
			destMesh.uv2 = src.uv2;
#if UNITY_5
			destMesh.uv3 = src.uv3;
			destMesh.uv4 = src.uv4;
#endif
			destMesh.normals = src.normals;
			destMesh.tangents = src.tangents;
			destMesh.boneWeights = src.boneWeights;
			destMesh.colors = src.colors;
			destMesh.colors32 = src.colors32;
			destMesh.bindposes = src.bindposes;

			destMesh.subMeshCount = src.subMeshCount;
			for(int i = 0; i < src.subMeshCount; i++)
				destMesh.SetIndices(src.GetIndices(i), src.GetTopology(i), i);
		}
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:26,代码来源:pb_MeshUtility.cs

示例11: SaveMesh

    public static string SaveMesh(Mesh mesh, string path)
    {
        if (savedMeshes.ContainsKey(mesh.name))
        {
            if (savedMeshes[mesh.name].GetInstanceID() != mesh.GetInstanceID())
            {
                Debug.LogError("有重名mesh:"+mesh.name);
            }
            return mesh.name;
        }
        if (System.IO.Directory.Exists(path) == false)
        {
            System.IO.Directory.CreateDirectory(path);
        }
        using (System.IO.Stream s = System.IO.File.Open(System.IO.Path.Combine(path, mesh.name + ".mesh.bytes"), System.IO.FileMode.Create))
        {
            byte[] buf = BitHelper.getBytes(mesh.bounds);
            s.Write(buf, 0, 24);
            UInt32 vc = (UInt32)mesh.vertexCount;
            buf = BitConverter.GetBytes(vc);
            s.Write(buf, 0, 4);
            if (mesh.vertices != null && mesh.vertices.Length != 0)
            {
                s.WriteByte(1);//1 vb pos tag
                for (int i = 0; i < vc; i++)
                {
                    s.Write(BitHelper.getBytes(mesh.vertices[i]), 0, 12);
                    if (i == 0)
                    {
                        Debug.Log("pos0:" + mesh.vertices[i]);
                    }
                }
            }
            if (mesh.colors32 != null && mesh.colors32.Length != 0)
            {

                s.WriteByte(2);//2 vb color tag;
                for (int i = 0; i < vc; i++)
                {
                    s.Write(BitHelper.getBytes(mesh.colors32[i]), 0, 4);
                    Debug.Log("color0:" + mesh.colors32[i]);
                    if (i == 0)
                    {
                        Debug.Log("pos0:" + mesh.vertices[i]);
                    }
                }
            }
            if (mesh.normals != null && mesh.normals.Length != 0)
            {
                s.WriteByte(3);//3 vb normal tag;
                for (int i = 0; i < vc; i++)
                {
                    s.Write(BitHelper.getBytes(mesh.normals[i]), 0, 12);
                    if (i == 0)
                    {
                        Debug.Log("normal0:" + mesh.normals[i]);
                    }
                }
            }
            if (mesh.uv != null && mesh.uv.Length != 0)
            {
                s.WriteByte(4);//4 vb uv tag;
                for (int i = 0; i < vc; i++)
                {
                    s.Write(BitHelper.getBytes(mesh.uv[i]), 0, 8);
                    if (i == 0)
                    {
                        Debug.Log("uv0:" + mesh.uv[i]);
                    }
                }
            }
            if (mesh.uv1 != null && mesh.uv1.Length != 0)
            {
                s.WriteByte(5);//5 vb uv1 tag;
                for (int i = 0; i < vc; i++)
                {
                    s.Write(BitHelper.getBytes(mesh.uv1[i]), 0, 8);
                }
            }
            if (mesh.uv2 != null && mesh.uv2.Length != 0)
            {
                s.WriteByte(6);//6 vb uv2 tag;
                for (int i = 0; i < vc; i++)
                {
                    s.Write(BitHelper.getBytes(mesh.uv[i]), 0, 8);
                }
            }
            s.WriteByte(255);//vb end
            int sub = mesh.subMeshCount;
            s.WriteByte((byte)sub);
            {
                Debug.Log("sub:" + sub);
            }
            for (int i = 0; i < sub; i++)
            {
                int tv = (int)mesh.GetTopology(i);//绘制方式
                s.Write(BitConverter.GetBytes(tv), 0, 4);
                var indices = mesh.GetIndices(i);//索引
                UInt16 length = (UInt16)indices.Length;
                s.Write(BitConverter.GetBytes(length), 0, 2);
//.........这里部分代码省略.........
开发者ID:guozanhua,项目名称:easydown,代码行数:101,代码来源:AssetMgr.cs

示例12: WriteMesh


//.........这里部分代码省略.........
            }
        }
        if (mesh.uv != null && mesh.uv.Length != 0)
        {
            s.WriteByte(4);//4 vb uv tag;
            for (int i = 0; i < vc; i++)
            {
                s.Write(BitHelper.getBytes(mesh.uv[i]), 0, 8);
                //if (i == 0)
                //{
                //    Debug.Log("uv0:" + mesh.uv[i]);
                //}
            }
        }
        if (mesh.uv2 != null && mesh.uv2.Length != 0)
        {
            s.WriteByte(5);//5 vb uv2 tag;
            for (int i = 0; i < vc; i++)
            {
                s.Write(BitHelper.getBytes(mesh.uv2[i]), 0, 8);
            }
        }
        if (mesh.uv3 != null && mesh.uv3.Length != 0)
        {
            s.WriteByte(6);//6 vb uv3 tag;
            for (int i = 0; i < vc; i++)
            {
                s.Write(BitHelper.getBytes(mesh.uv3[i]), 0, 8);
            }
        }
        if (mesh.tangents != null && mesh.tangents.Length != 0)
        {
            s.WriteByte(7);//7 tangents tag;
            for (int i = 0; i < vc; i++)
            {
                s.Write(BitHelper.getBytes(mesh.tangents[i]), 0, 16);
            }
        }
        if (mesh.uv4 != null && mesh.uv4.Length != 0)
        {
            s.WriteByte(8);//8 vb uv4 tag;
            for (int i = 0; i < vc; i++)
            {
                s.Write(BitHelper.getBytes(mesh.uv4[i]), 0, 8);
            }
        }
        if (mesh.bindposes != null && mesh.bindposes.Length != 0)
        {
            s.WriteByte(16);//16 bindposes
            s.WriteByte((byte)mesh.bindposes.Length);//length diff
            for (int i = 0; i < mesh.bindposes.Length; i++)
            {
                Vector3 pos;
                Vector3 scale;
                Quaternion quat;
                BitHelper.MatrixDeCompose(mesh.bindposes[i], out pos, out scale, out quat);
                s.Write(BitHelper.getBytes(pos), 0, 12);
                s.Write(BitHelper.getBytes(scale), 0, 12);
                s.Write(BitHelper.getBytes(quat), 0, 16);
                //Debug.Log(mesh.bindposes[i] + "\n pos:" + pos + "\n scale:" + scale  + "\n quat:" + quat + "\n euler:" + quat.ToEuler());
            }
            //mesh.bindposes = mesh.bindposes;
            //mesh.UploadMeshData(false);
        }
        if (mesh.boneWeights != null && mesh.boneWeights.Length != 0)
        {
            s.WriteByte(17);//17 boneweights
            for (int i = 0; i < vc; i++)
            {
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].boneIndex0), 0, 4);
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].boneIndex1), 0, 4);
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].boneIndex2), 0, 4);
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].boneIndex3), 0, 4);
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].weight0), 0, 4);
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].weight1), 0, 4);
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].weight2), 0, 4);
                s.Write(BitConverter.GetBytes(mesh.boneWeights[i].weight3), 0, 4);
            }
        }
        s.WriteByte(255);//vb end
        int sub = mesh.subMeshCount;
        s.WriteByte((byte)sub);
        {
            Debug.Log("sub:" + sub);
        }
        for (int i = 0; i < sub; i++)
        {
            int tv = (int)mesh.GetTopology(i);//绘制方式
            s.Write(BitConverter.GetBytes(tv), 0, 4);
            var indices = mesh.GetIndices(i);//索引
            UInt32 length = (UInt32)indices.Length;
            Debug.Log("indlength:" + sub);

            s.Write(BitConverter.GetBytes(length), 0, 4);
            for (int j = 0; j < length; j++)
            {
                s.Write(BitConverter.GetBytes(indices[j]), 0, 4);
            }
        }
    }
开发者ID:lightszero,项目名称:EgretUnity,代码行数:101,代码来源:BitHelper.cs

示例13: CreateGridXY

    public static Mesh CreateGridXY(int _width, int _height, Color _vertCol)
    {
        Vector3[] vertices = new Vector3[(_width+1)*(_height+1)*2];
        int[] triangles = new int[(((_width+1)*(_height+1)*2)/3+1)*3];
        Vector2[] uv = new Vector2[(_width+1)*(_height+1)*2];
        Color[] colors = new Color[(_width+1)*(_height+1)*2];
        Vector3[] normals = new Vector3[(_width+1)*(_height+1)*2];
        Vector4[] tangents = new Vector4[(_width+1)*(_height+1)*2];

        int cnt = 0;
        for(int ix = 0; ix <= _width; ++ix){
            vertices[cnt*2+0] = new Vector3(((float)ix/(float)_width - 0.5f),-0.5f,0.0f);
            vertices[cnt*2+1] = new Vector3(((float)ix/(float)_width - 0.5f), 0.5f,0.0f);
            triangles[cnt*2+0] = cnt*2+0;
            triangles[cnt*2+1] = cnt*2+1;
            uv[cnt*2+0] = new Vector2(vertices[cnt*2+0].x+0.5f,vertices[cnt*2+0].y+0.5f);
            uv[cnt*2+1] = new Vector2(vertices[cnt*2+1].x+0.5f,vertices[cnt*2+1].y+0.5f);
            colors[cnt*2+0] = colors[cnt*2+1] = new Color(0.5f,0.5f,0.5f,1.0f);
            normals[cnt*2+0] = normals[cnt*2+1] = new Vector3(0.0f,0.0f,-1.0f);
            tangents[cnt*2+0] = tangents[cnt*2+1] = new Vector4(1.0f,0.0f,0.0f,0.0f);
            cnt++;
        }
        for(int iy = 0; iy <= _height; ++iy){
            vertices[cnt*2+0] = new Vector3(-0.5f,((float)iy/(float)_height - 0.5f),0.0f);
            vertices[cnt*2+1] = new Vector3( 0.5f,((float)iy/(float)_height - 0.5f),0.0f);
            triangles[cnt*2+0] = cnt*2+0;
            triangles[cnt*2+1] = cnt*2+1;
            uv[cnt*2+0] = new Vector2(vertices[cnt*2+0].x+0.5f,vertices[cnt*2+0].y+0.5f);
            uv[cnt*2+1] = new Vector2(vertices[cnt*2+1].x+0.5f,vertices[cnt*2+1].y+0.5f);
            colors[cnt*2+0] = colors[cnt*2+1] = new Color(0.5f,0.5f,0.5f,1.0f);
            normals[cnt*2+0] = normals[cnt*2+1] = new Vector3(0.0f,0.0f,-1.0f);
            tangents[cnt*2+0] = tangents[cnt*2+1] = new Vector4(1.0f,0.0f,0.0f,0.0f);
            cnt++;
        }
        Mesh mesh = new Mesh();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.uv = uv;
        mesh.colors = colors;
        mesh.normals = normals;
        mesh.tangents = tangents;
        //		mesh.RecalculateNormals ();
        mesh.RecalculateBounds ();
        mesh.Optimize();
        mesh.SetIndices(mesh.GetIndices(0),MeshTopology.Lines,0);
        return mesh;
    }
开发者ID:hiyijia,项目名称:unity_mylib,代码行数:47,代码来源:TmUtils.cs

示例14: CreatePolyRing

    public static Mesh CreatePolyRing(int _vertNum, float _minRad, float _maxRad, Color _color)
    {
        Vector3[] vertices = new Vector3[(_vertNum+1)*2];
        int[] triangles = new int[(_vertNum+1)*6];
        Vector2[] uv = new Vector2[(_vertNum+1)*2];
        Color[] colors = new Color[(_vertNum+1)*2];
        Vector3[] normals = new Vector3[(_vertNum+1)*2];
        Vector4[] tangents = new Vector4[(_vertNum+1)*2];

        int cnt = 0;
        for(int ii = 0; ii <= _vertNum; ++ii){
            float fx = Mathf.Cos(Mathf.PI*2.0f * ((float)ii / (float)_vertNum));
            float fy = Mathf.Sin(Mathf.PI*2.0f * ((float)ii / (float)_vertNum));
            vertices[cnt*2+0] = new Vector3(fx*_maxRad*0.5f,fy*_maxRad*0.5f,0.0f);
            vertices[cnt*2+1] = new Vector3(fx*_minRad*0.5f,fy*_minRad*0.5f,0.0f);
            triangles[cnt*6+0] = cnt*2+0;
            triangles[cnt*6+1] = cnt*2+1;
            triangles[cnt*6+2] = (ii<(_vertNum)) ? (cnt*2+2) : 0;
            triangles[cnt*6+3] = cnt*2+0;
            triangles[cnt*6+4] = (ii>0) ? (cnt*2-1) : 0;
            triangles[cnt*6+5] = cnt*2+1;
            uv[cnt*2+0] = new Vector2((float)ii/(float)_vertNum,0.0f);
            uv[cnt*2+1] = new Vector2((float)ii/(float)_vertNum,1.0f);
            colors[cnt*2+0] = colors[cnt*2+1] = _color;
            normals[cnt*2+0] = normals[cnt*2+1] = new Vector3(0.0f,0.0f,-1.0f);
            tangents[cnt*2+0] = tangents[cnt*2+1] = new Vector4(1.0f,0.0f,0.0f,0.0f);
            cnt++;
        }
        Mesh mesh = new Mesh();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.uv = uv;
        mesh.colors = colors;
        mesh.normals = normals;
        mesh.tangents = tangents;
        mesh.RecalculateNormals ();
        mesh.RecalculateBounds ();
        mesh.Optimize();
        mesh.SetIndices(mesh.GetIndices(0),MeshTopology.Triangles,0);
        return mesh;
    }
开发者ID:hiyijia,项目名称:unity_mylib,代码行数:41,代码来源:TmUtils.cs

示例15: CreateLineCircle

    public static Mesh CreateLineCircle(int _vertNum, Color _color)
    {
        Vector3[] vertices = new Vector3[_vertNum];
        int[] triangles = new int[((_vertNum)/3+1)*3];
        Vector2[] uv = new Vector2[_vertNum];
        Color[] colors = new Color[_vertNum];
        Vector3[] normals = new Vector3[_vertNum];
        Vector4[] tangents = new Vector4[_vertNum];

        int cnt = 0;
        for(int ii = 0; ii < _vertNum; ++ii){
            float fx = Mathf.Cos(Mathf.PI*2.0f * ((float)ii / (float)_vertNum))*0.5f;
            float fy = Mathf.Sin(Mathf.PI*2.0f * ((float)ii / (float)_vertNum))*0.5f;
            vertices[cnt] = new Vector3(fx,fy,0.0f);
            triangles[cnt] = cnt;
            uv[cnt] = new Vector2(vertices[cnt].x+0.5f,vertices[cnt].y+0.5f);
            colors[cnt] = _color;
            normals[cnt] = new Vector3(0.0f,0.0f,-1.0f);
            tangents[cnt] = new Vector4(1.0f,0.0f,0.0f,0.0f);
            cnt++;
        }
        Mesh mesh = new Mesh();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.uv = uv;
        mesh.colors = colors;
        mesh.normals = normals;
        mesh.tangents = tangents;
        //		mesh.RecalculateNormals ();
        mesh.RecalculateBounds ();
        mesh.Optimize();
        mesh.SetIndices(mesh.GetIndices(0),MeshTopology.LineStrip,0);
        return mesh;
    }
开发者ID:hiyijia,项目名称:unity_mylib,代码行数:34,代码来源:TmUtils.cs


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