Ejemplo n.º 1
0
        public static UnityEngine.Mesh SimpleMeshToUnityMesh(SimpleMesh m, bool bSwapLeftRight)
        {
            if (m.VertexCount > 65000 || m.TriangleCount > 65000)
            {
                Debug.Log("[SimpleMeshReader] attempted to import object larger than 65000 verts/tris, not supported by Unity!");
                return(null);
            }

            UnityEngine.Mesh unityMesh = new UnityEngine.Mesh();

            Vector3[] vertices = dvector_to_vector3(m.Vertices);
            Vector3[] normals  = (m.HasVertexNormals) ? dvector_to_vector3(m.Normals) : null;
            if (bSwapLeftRight)
            {
                int nV = vertices.Length;
                for (int i = 0; i < nV; ++i)
                {
                    vertices[i].x = -vertices[i].x;
                    vertices[i].z = -vertices[i].z;
                    if (normals != null)
                    {
                        normals[i].x = -normals[i].x;
                        normals[i].z = -normals[i].z;
                    }
                }
            }

            unityMesh.vertices = vertices;
            if (m.HasVertexNormals)
            {
                unityMesh.normals = normals;
            }
            if (m.HasVertexColors)
            {
                unityMesh.colors = dvector_to_color(m.Colors);
            }
            if (m.HasVertexUVs)
            {
                unityMesh.uv = dvector_to_vector2(m.UVs);
            }
            unityMesh.triangles = m.GetTriangleArray();

            if (m.HasVertexNormals == false)
            {
                unityMesh.RecalculateNormals();
            }

            return(unityMesh);
        }