예제 #1
0
        public static List <Surface> meshToNurbs(MFnMesh mayaMesh)
        {
            MFnSubd subDmesh = new MFnSubd();

            subDmesh.isIntermediateObject = true;
            MPointArray mayaVerts = new MPointArray();

            mayaMesh.getPoints(mayaVerts, MSpace.Space.kWorld);

            MIntArray polyVertct = new MIntArray();


            MIntArray ids    = new MIntArray();
            MIntArray idList = new MIntArray();

            for (int i = 0; i < mayaMesh.numPolygons; i++)
            {
                mayaMesh.getPolygonVertices(i, ids);
                foreach (var id in ids)
                {
                    idList.Add(id);
                }
                polyVertct.Add(ids.Count);
            }
            subDmesh.createBaseMesh(false, mayaMesh.numVertices, mayaMesh.numPolygons, mayaVerts, polyVertct, idList);

            try
            {
                MUintArray   creaseEdgId   = new MUintArray();
                MDoubleArray creaseEdgeVal = new MDoubleArray();
                mayaMesh.getCreaseEdges(creaseEdgId, creaseEdgeVal);

                foreach (var edgId in creaseEdgId)
                {
                    subDmesh.edgeSetCrease(edgId, true);
                }
            }
            catch {}

            try
            {
                MUintArray   creaseVertId  = new MUintArray();
                MDoubleArray creaseVertVal = new MDoubleArray();
                mayaMesh.getCreaseVertices(creaseVertId, creaseVertVal);

                foreach (var vertId in creaseVertId)
                {
                    subDmesh.vertexSetCrease(vertId, true);
                }
            }
            catch { }


            subDmesh.updateAllEditsAndCreases();

            MObjectArray nurbsSurfs = new MObjectArray();

            subDmesh.convertToNurbs(nurbsSurfs);

            List <MFnNurbsSurface> mfnSurfaceList = new List <MFnNurbsSurface>(nurbsSurfs.Count);

            foreach (var surf in nurbsSurfs)
            {
                mfnSurfaceList.Add(new MFnNurbsSurface(surf));
            }

            List <Surface> dynSurfaceList = new List <Surface>(mfnSurfaceList.Count);

            foreach (var mfnNS in mfnSurfaceList)
            {
                dynSurfaceList.Add(DMSurface.mNurbsSurfaceToDynamoSurface(mfnNS, MSpace.Space.kObject));
            }

            MGlobal.deleteNode(subDmesh.model);
            return(dynSurfaceList);
        }