コード例 #1
0
        internal static Mesh MTDMeshFromMayaMesh(MFnMesh mayaMesh, MSpace.Space space)
        {
            PointList vertices = new PointList(mayaMesh.numVertices);

            ;
            List <IndexGroup> faceIndexList = new List <IndexGroup>(mayaMesh.numPolygons);

            MPointArray mayaVerts = new MPointArray();

            mayaMesh.getPoints(mayaVerts, space);
            if (MGlobal.isYAxisUp)
            {
                vertices.AddRange(mayaVerts.Select(v => Point.ByCoordinates(v.x, -v.z, v.y)));
            }
            else
            {
                vertices.AddRange(mayaVerts.Select(v => Point.ByCoordinates(v.x, v.y, v.z)));
            }

            MIntArray faceIndex = new MIntArray();

            for (int i = 0; i < mayaMesh.numPolygons; i++)
            {
                mayaMesh.getPolygonVertices(i, faceIndex);
                if (faceIndex.length > 4)
                {
                    WarningException wa = new WarningException("The DynMesh will not show in Dynamo if it has any faces with 4 verts or more. The DynMesh can be represented as closed curves .");
                    return(null);
                }
                if (faceIndex.length == 3)
                {
                    faceIndexList.Add(IndexGroup.ByIndices((uint)faceIndex[0], (uint)faceIndex[1], (uint)faceIndex[2]));
                }
                else
                {
                    faceIndexList.Add(IndexGroup.ByIndices((uint)faceIndex[0], (uint)faceIndex[1], (uint)faceIndex[2],
                                                           (uint)faceIndex[3]));
                }
            }
            mayaMesh.Dispose();
            mayaVerts.Dispose();
            faceIndex.Dispose();


            using (vertices)
            {
                return(Mesh.ByPointsFaceIndices(vertices, faceIndexList));
            }
        }