Ejemplo n.º 1
0
        public fMesh(int[] triangles, DMesh3 source, int[] source_vertices, bool bCopyNormals = false, bool bCopyColors = false, bool bCopyUVs = false)
        {
            int NV = source_vertices.Length;

            Vector3[] vertices = new Vector3[NV];
            for (int i = 0; i < NV; ++i)
            {
                vertices[i] = (Vector3)source.GetVertex(source_vertices[i]);
            }

            Mesh m = new Mesh();

            m.vertices = vertices;

            if (NV > 65000 || triangles.Length / 3 > 65000)
            {
                m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
            }
            m.triangles = triangles;

            if (bCopyNormals && source.HasVertexNormals)
            {
                Vector3[] normals = new Vector3[NV];
                for (int i = 0; i < NV; ++i)
                {
                    normals[i] = (Vector3)source.GetVertexNormal(source_vertices[i]);
                }
                m.normals = normals;
            }
            else
            {
                m.RecalculateNormals();
            }

            if (bCopyColors && source.HasVertexColors)
            {
                Color[] colors = new Color[NV];
                for (int i = 0; i < NV; ++i)
                {
                    colors[i] = (Color)source.GetVertexColor(source_vertices[i]);
                }
                m.colors = colors;
            }

            if (bCopyUVs && source.HasVertexUVs)
            {
                Vector2[] uvs = new Vector2[NV];
                for (int i = 0; i < NV; ++i)
                {
                    uvs[i] = source.GetVertexUV(source_vertices[i]);
                }
                m.uv = uvs;
            }

            mesh = m;
        }