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)); } }
internal static Curve CurveFromMfnNurbsCurveFromDag(MDagPath dagPath, MSpace.Space space) { Point3DCollection controlVertices; List <double> weights, knots; int degree; bool closed, rational; decomposeMayaCurve(dagPath, space, out controlVertices, out weights, out knots, out degree, out closed, out rational); // var controlPoints = new List<Point>(controlVertices.Count); var curvePoints = new PointList(controlVertices.Count); if (MGlobal.isYAxisUp) { curvePoints.AddRange(controlVertices.Select(cv => Point.ByCoordinates(cv.X, -cv.Z, cv.Y))); } else { curvePoints.AddRange(controlVertices.Select(cv => Point.ByCoordinates(cv.X, cv.Y, cv.Z))); } Curve theCurve; if (closed) { theCurve = NurbsCurve.ByControlPoints(curvePoints, degree, true); } else { theCurve = NurbsCurve.ByControlPointsWeightsKnots(curvePoints, weights.ToArray(), knots.ToArray(), degree); } curvePoints.Dispose(); return(theCurve); }