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


C# Mesh.GetTopology方法代码示例

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


在下文中一共展示了Mesh.GetTopology方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: CheckMesh

        private void CheckMesh()
        {
            if (MeshFilter == null || MeshFilter.sharedMesh == null)
            {
                meshHelper = null;
            }
            else if (MeshFilter.sharedMesh != previousMesh)
            {
                previousMesh = MeshFilter.sharedMesh;
                meshHelper = new MeshHelper(previousMesh);

#if DEBUG

                if (previousMesh.GetTopology(0) != MeshTopology.Triangles)
                {
                    Debug.LogError("Mesh topology must be triangles");
                }

#endif

            }
        }
开发者ID:jquentin,项目名称:LaserPin,代码行数:22,代码来源:LightningMeshSurfaceScript.cs

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: Build

    public void Build(Mesh mesh, Matrix4x4 transform)
    {
        if (mesh.subMeshCount != 1){
            Debug.LogError("Invalid mesh.subMeshCount. Must be 1.");
        }
        if (mesh.GetTopology(0) != MeshTopology.Triangles){
            Debug.LogError("Only triangles supported.");
        }
        List<Vertex> vertexList = new List<Vertex>();
        Dictionary<uint, Halfedge> halfedgeByVertexID = new Dictionary<uint, Halfedge>();

        // Create a list of (HMesh) Vertices
        bool hasUv1 = mesh.uv != null && mesh.uv.Length == mesh.vertices.Length;
        bool hasUv2 = mesh.uv2 != null && mesh.uv2.Length == mesh.vertices.Length;
        for (int i=0;i<mesh.vertices.Length;i++){
            var newV = CreateVertex();
            newV.position = transform.MultiplyPoint(mesh.vertices[i]);
            if (hasUv1){
                newV.uv1 = mesh.uv[i];
            }
            if (hasUv2){
                newV.uv2 = mesh.uv2[i];
            }
            vertexList.Add(newV);
        }

        // create faces and half edges
        for (int i=0;i<mesh.triangles.Length;i+=3){
            int[] idx = new int[]{
                mesh.triangles[i],
                mesh.triangles[i+1],
                mesh.triangles[i+2]};
            Halfedge[] edges = new Halfedge[3];
            Face face = CreateFace();
            for (int j=0;j<3;j++){
                Halfedge edge = CreateHalfedge();
                edge.Link(face);
                edges[j] = edge;
            }
            for (int j=0;j<3;j++){
                int from = idx[j];
                int to = idx[(j+1)%3];
                edges[j].Link(edges[(j+1)%3]);
                edges[j].vert = vertexList[to];
                vertexList[to].halfedge = edges[j].next;
                uint edgeId = EdgeKey(from,to);
                halfedgeByVertexID.Add(edgeId, edges[j]);
            }
        }
        int glued = 0;
        // glue all opposite half edges
        for (int i=0;i<mesh.triangles.Length;i+=3){
            int[] idx = new int[]{
                mesh.triangles[i],
                mesh.triangles[i+1],
                mesh.triangles[i+2]};
            for (int j=0;j<3;j++){
                int from = idx[j];
                int to = idx[(j+1)%3];
                uint key = EdgeKey(from,to);
                uint oppKey = EdgeKey(to,from);
                Halfedge edge = halfedgeByVertexID[key];
                bool isOppUnassigned = edge.opp == null;
                if (isOppUnassigned && halfedgeByVertexID.ContainsKey(oppKey)){
                    Halfedge oppEdge = halfedgeByVertexID[oppKey];
                    edge.Glue(oppEdge);
                    glued++;
                }
            }
        }
    }
开发者ID:mortennobel,项目名称:UnityUtils,代码行数:71,代码来源:HMesh.cs

示例10: OnGUI

    void OnGUI()
    {
        GUILayout.BeginHorizontal();
        {
            obj = (GameObject)EditorGUILayout.ObjectField(obj, typeof(GameObject), true);
            if (obj == null)
            {
                mesh = null;
                SMR = null;
            }
            else if (obj.GetComponent<MeshFilter>() && (mesh == null || obj != oldObject))
            {
                SMR = null;
                mesh = obj.GetComponent<MeshFilter>().sharedMesh;
                topo = mesh.GetTopology(0);
            }
            else if (obj.GetComponent<SkinnedMeshRenderer>() && (mesh == null || obj != oldObject))
            {
                SMR = obj.GetComponent<SkinnedMeshRenderer>();
                mesh = SMR.sharedMesh;
                topo = mesh.GetTopology(0);
            }
            oldObject = obj;
            linkScroll = GUILayout.Toggle(linkScroll, "Link scroll bars");
            GUILayout.Label("Mesh Topology: ", GUILayout.Width(92));
            topo = (MeshTopology)EditorGUILayout.EnumPopup(topo);
        } GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        {
            showVerts = GUILayout.Toggle(showVerts, "Show Vertices");
            showNorm = GUILayout.Toggle(showNorm, "Show Normals");
            showTangents = GUILayout.Toggle(showTangents, "Show Tangents");
            showIndices = GUILayout.Toggle(showIndices, "Show Indices");
            showUVs = GUILayout.Toggle(showUVs, "Show UVs");
            showUV2s = GUILayout.Toggle(showUV2s, "Show UV2s");
            showBoneWeights = GUILayout.Toggle(showBoneWeights, "Show BoneWeights");
            showBindPoses = GUILayout.Toggle(showBindPoses, "Show BindPoses");
            showBones = GUILayout.Toggle(showBones, "Show Bones");
        } GUILayout.EndHorizontal();
        if (mesh)
        {
            GUILayout.BeginHorizontal();
            {
                if (showVerts)
                {
                    BeginScroll(ref vertScroll);
                    vertices = mesh.vertices;
                    for (int i = 0; i < mesh.vertexCount && i < MAX_DISPLAY; i++)
                    {
                        vertices[i] = EditorGUILayout.Vector3Field(i + ":", vertices[i]);
                    }
                    mesh.vertices = vertices;
                    GUILayout.EndScrollView();

                }
                if (showNorm)
                {
                    BeginScroll(ref normScroll);
                    normals = mesh.normals;
                    for (int i = 0; i < mesh.normals.Length && i < MAX_DISPLAY; i++)
                    {
                        normals[i] = EditorGUILayout.Vector3Field(i + ":", normals[i]);
                    }
                    mesh.normals = normals;
                    GUILayout.EndScrollView();
                }
                if (showTangents)
                {
                    BeginScroll(ref tangentScroll);
                    tangents = mesh.tangents;
                    for (int i = 0; i < mesh.tangents.Length && i < MAX_DISPLAY; i++)
                    {
                        tangents[i] = EditorGUILayout.Vector3Field(i + ":", tangents[i]);
                    }
                    mesh.tangents = tangents;
                    GUILayout.EndScrollView();
                }
                if (showBoneWeights)
                {
                    BeginScroll(ref boneWeightScroll);
                    boneWeights = mesh.boneWeights;
                    for (int i = 0; i < mesh.boneWeights.Length && i < MAX_DISPLAY; i++)
                    {
                        GUILayout.Label(i + ":");
                        boneWeights[i].boneIndex0 = EditorGUILayout.IntField("Bone 0 idx: ", boneWeights[i].boneIndex0);
                        boneWeights[i].boneIndex1 = EditorGUILayout.IntField("Bone 1 idx: ", boneWeights[i].boneIndex1);
                        boneWeights[i].boneIndex2 = EditorGUILayout.IntField("Bone 2 idx: ", boneWeights[i].boneIndex2);
                        boneWeights[i].boneIndex3 = EditorGUILayout.IntField("Bone 3 idx: ", boneWeights[i].boneIndex3);
                        boneWeights[i].weight0 = EditorGUILayout.FloatField("Bone 0 Weight: ", boneWeights[i].weight0);
                        boneWeights[i].weight1 = EditorGUILayout.FloatField("Bone 1 Weight: ", boneWeights[i].weight1);
                        boneWeights[i].weight2 = EditorGUILayout.FloatField("Bone 2 Weight: ", boneWeights[i].weight2);
                        boneWeights[i].weight3 = EditorGUILayout.FloatField("Bone 3 Weight: ", boneWeights[i].weight3);
                    }
                    //mesh.boneWeights = boneWeights;
                    GUILayout.EndScrollView();
                }
                if (showIndices)
                {
                    BeginScroll(ref triScroll);
                    triangles = mesh.GetIndices(0);
//.........这里部分代码省略.........
开发者ID:k-lock,项目名称:Unity3D,代码行数:101,代码来源:MeshViewer.cs

示例11: Copy

		/**
		 *	Copy @src mesh values to @dest
		 */
		public static void Copy(Mesh dest, Mesh src)
		{
			dest.Clear();
			dest.vertices = src.vertices;

			List<Vector4> uvs = new List<Vector4>();

			src.GetUVs(0, uvs); dest.SetUVs(0, uvs);
			src.GetUVs(1, uvs); dest.SetUVs(1, uvs);
			src.GetUVs(2, uvs); dest.SetUVs(2, uvs);
			src.GetUVs(3, uvs); dest.SetUVs(3, uvs);

			dest.normals = src.normals;
			dest.tangents = src.tangents;
			dest.boneWeights = src.boneWeights;
			dest.colors = src.colors;
			dest.colors32 = src.colors32;
			dest.bindposes = src.bindposes;

			dest.subMeshCount = src.subMeshCount;

			for(int i = 0; i < src.subMeshCount; i++)
				dest.SetIndices(src.GetIndices(i), src.GetTopology(i), i);

			dest.name = z_Util.IncrementPrefix("z", src.name);
		}
开发者ID:alex-carlson,项目名称:PixelitisGGJ,代码行数:29,代码来源:z_MeshUtility.cs


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