public static Mesh ToDynamoElement(MFnMesh mMesh, string space) { MSpace.Space mspace = MSpace.Space.kWorld; Enum.TryParse(space, out mspace); return(MTDMeshFromMayaMesh(mMesh, mspace)); }
public DMSurface(MDagPath dagShape, MSpace.Space space) : base(dagShape, space) { DagShape = dagShape; AddEvents(dagShape); DagNode = new MFnDagNode(dagShape); }
public DMLocator(MDagPath dagPath, MSpace.Space space) : base(dagPath, space) { DagShape = dagPath; AddEvents(dagPath); DagNode = new MFnDagNode(dagPath); }
public DMBase(MDagPath dagShape, MDagPath dagTransform, MSpace.Space mspace) { DagShape = dagShape; AddCoreEvents(dagShape); DagNode = new MFnDagNode(dagShape); dagName = dagTransform.partialPathName; space = mspace.ToString(); }
public DMMesh(MDagPath dagPath, MSpace.Space mspace = MSpace.Space.kWorld) { DagPath = dagPath; AddEvents(dagPath); DagNode = new MFnDagNode(dagPath); dagName = DagPath.partialPathName; space = mspace.ToString(); }
internal static Surface mNurbsSurfaceToDynamoSurfaceFromName(string dagName, string space) { MSpace.Space mspace = MSpace.Space.kWorld; Enum.TryParse(space, out mspace); MDagPath dagPath = DMInterop.getDagNode(dagName); return(mNurbsSurfaceToDynamoSurfaceFromDag(dagPath, mspace)); }
internal static Mesh MTDMeshFromName(string dagName, string space) { MDagPath dagPath = DMInterop.getDagNode(dagName); MSpace.Space mspace = MSpace.Space.kWorld; Enum.TryParse(space, out mspace); return(MTDMeshFromDag(dagPath, mspace)); }
public static MFnMesh GetMayaMesh(string dagName, string space) { MDagPath dagPath = DMInterop.getDagNode(dagName); MSpace.Space mspace = MSpace.Space.kWorld; Enum.TryParse(space, out mspace); MFnMesh mayaMesh = new MFnMesh(dagPath); return(mayaMesh); }
public static MFnNurbsSurface GetMayaObject(string dagName, string space) { MDagPath dagPath = DMInterop.getDagNode(dagName); MSpace.Space mspace = MSpace.Space.kWorld; Enum.TryParse(space, out mspace); MFnNurbsSurface mayaObject = new MFnNurbsSurface(dagPath); return(mayaObject); }
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 CoordinateSystem mLocatorFromName(string dagName, string space) { MDagPath dagPath = DMInterop.getDagNode(dagName); MSpace.Space mspace = MSpace.Space.kWorld; Enum.TryParse(space, out mspace); // MObject obj = DMInterop.getDependNode(dagName); MMatrix worldPos = dagPath.inclusiveMatrix; double x = worldPos[3, 0]; double y = worldPos[3, 1]; double z = worldPos[3, 2]; MEulerRotation rot = new MEulerRotation(); double xr = worldPos[3, 0]; double yr = worldPos[3, 1]; double zr = worldPos[3, 2]; //MFnTransform loc = new MFnTransform(dagShape.node); //var vec = loc.transformation.getTranslation(mspace); //return Point.ByCoordinates(vec.x, vec.y, vec.z); ; CoordinateSystem cs; if (MGlobal.isZAxisUp) { cs = CoordinateSystem.ByOrigin(x, y, z); cs.Rotate(cs.Origin, Vector.XAxis(), x); cs.Rotate(cs.Origin, Vector.YAxis(), y); cs.Rotate(cs.Origin, Vector.ZAxis(), z); return(cs); } else { cs = CoordinateSystem.ByOrigin(x, -z, y); cs.Rotate(cs.Origin, Vector.XAxis(), x); cs.Rotate(cs.Origin, Vector.YAxis(), y); cs.Rotate(cs.Origin, Vector.ZAxis(), z); return(cs); } }
public static List <int[]> GetFaceVertexIdx(string dagName, string space) { MDagPath dagPath = DMInterop.getDagNode(dagName); MSpace.Space mspace = MSpace.Space.kWorld; Enum.TryParse(space, out mspace); MFnMesh mayaMesh = new MFnMesh(dagPath); List <int[]> vtxIds = new List <int[]>(mayaMesh.numPolygons); MIntArray ids = new MIntArray(); for (int i = 0; i < mayaMesh.numPolygons; i++) { mayaMesh.getPolygonVertices(i, ids); vtxIds.Add(ids.ToArray()); } return(vtxIds); }
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); }
public DMCurve(MDagPath dagPath, MSpace.Space space) : base(dagPath, space) { }
internal static Surface mNurbsSurfaceToDynamoSurface(MFnNurbsSurface surface, MSpace.Space space) { MPointArray cvs = new MPointArray(); surface.getCVs(cvs, space); MDoubleArray knotU = new MDoubleArray(); MDoubleArray knotV = new MDoubleArray(); surface.getKnotsInU(knotU); surface.getKnotsInV(knotV); double Us = knotU[0], Ue = knotU[knotU.Count - 1], Vs = knotV[0], Ve = knotV[knotV.Count - 1]; //surface.getKnotDomain(ref Us, ref Ue, ref Vs, ref Ve); knotU.insert(Us, 0); knotU.Add(Ue); knotV.insert(Vs, 0); knotV.Add(Ve); int cvUct = surface.numCVsInU; int cvVct = surface.numCVsInV; int uDeg = surface.degreeU; int vDeg = surface.degreeV; Point[][] ctrlPts = new Point[cvUct][]; double[][] weights = new double[cvUct][]; for (int i = 0; i < cvUct; i++) { ctrlPts[i] = new Point[cvVct]; weights[i] = new double[cvVct]; for (int j = 0; j < cvVct; j++) { weights[i][j] = 1; if (MGlobal.isZAxisUp) { ctrlPts[i][j] = Point.ByCoordinates(cvs[(i * cvVct) + j].x, cvs[(i * cvVct) + j].y, cvs[(i * cvVct) + j].z); } else { ctrlPts[i][j] = Point.ByCoordinates(cvs[(i * cvVct) + j].x, -cvs[(i * cvVct) + j].z, cvs[(i * cvVct) + j].y); } } } //Surface result = NurbsSurface.ByControlPoints(ctrlPts, uDeg, vDeg); Surface result = NurbsSurface.ByControlPointsWeightsKnots(ctrlPts, weights, knotU.ToArray(), knotV.ToArray(), uDeg, vDeg); return(result); }
internal static Surface mNurbsSurfaceToDynamoSurfaceFromDag(MDagPath dagPath, MSpace.Space space) { MFnNurbsSurface surface = new MFnNurbsSurface(dagPath); return(mNurbsSurfaceToDynamoSurface(surface, space)); }
// // Calls applyRotationLocks && applyRotationLimits // This method verifies that the passed value can be set on the // rotate plugs. In the base class, limits as well as locking are // checked by this method. // // The compute, validateAndSetValue, and rotateTo functions // all use this method. // protected override void checkAndSetRotation(MDataBlock block, MPlug plug, MEulerRotation newRotation, MSpace.Space space) { MDGContext context = block.context; updateMatrixAttrs(context); MEulerRotation outRotation = newRotation; if (context.isNormal) { // For easy reading. // MPxTransformationMatrix xformMat = baseTransformationMatrix; // Get the current translation in transform space for // clamping and locking. // MEulerRotation savedRotation = xformMat.eulerRotation(MSpace.Space.kTransform); // Translate to transform space, since the limit test needs the // values in transform space. The locking test needs the values // in the same space as the savedR value - which is transform // space as well. // baseTransformationMatrix.rotateTo(newRotation, space); outRotation = xformMat.eulerRotation(MSpace.Space.kTransform); // Now that everything is in the same space, apply limits // and change the value to adhere to plug locking. // outRotation = applyRotationLimits(outRotation, block); outRotation = applyRotationLocks(outRotation, savedRotation); // The value that remain is in transform space. // xformMat.rotateTo(outRotation, MSpace.Space.kTransform); // Get the value that was just set. It needs to be in transform // space since it is used to set the datablock values at the // end of this method. Getting the vaolue right before setting // ensures that the transformation matrix and data block will // be synchronized. // outRotation = xformMat.eulerRotation(MSpace.Space.kTransform); } else { // Get the rotation for clamping and locking. This will get the // rotate value in transform space. // double[] s3 = block.inputValue(rotate).Double3; MEulerRotation savedRotation = new MEulerRotation(s3[0], s3[1], s3[2]); // Create a local transformation matrix for non-normal context // calculations. // MPxTransformationMatrix local = createTransformationMatrix(); if (null == local) { throw new InvalidOperationException("rockingTransformCheck::checkAndSetRotation internal error"); } // Fill the newly created transformation matrix. // computeLocalTransformation(local, block); // Translate the values to transform space. This will allow the // limit and locking tests to work properly. // local.rotateTo(newRotation, space); outRotation = local.eulerRotation(MSpace.Space.kTransform); // Apply limits // outRotation = applyRotationLimits(outRotation, block); outRotation = applyRotationLocks(outRotation, savedRotation); local.rotateTo(outRotation, MSpace.Space.kTransform); // Get the rotate value in transform space for placement in the // data block. // outRotation = local.eulerRotation(MSpace.Space.kTransform); local.Dispose(); } MDataHandle handle = block.outputValue(plug); if (plug.equalEqual(rotate)) { handle.set(outRotation.x, outRotation.y, outRotation.z); } else if (plug.equalEqual(rotateX)) { handle.set(outRotation.x); } else if (plug.equalEqual(rotateY)) { handle.set(outRotation.y); } else { handle.set(outRotation.z); } return; }
internal static void decomposeMayaCurve(MDagPath dagnode, MSpace.Space space, out Point3DCollection controlVertices, out List <double> weights, out List <double> knots, out int degree, out bool closed, out bool rational) { var nc = new MFnNurbsCurve(dagnode); var cvct = nc.numSpans; var p_aCVs = new MPointArray(); degree = nc.degree; closed = nc.form == MFnNurbsCurve.Form.kPeriodic ? true : false; rational = true; nc.getCVs(p_aCVs, space); controlVertices = new Point3DCollection(); weights = new List <double>(); if (MGlobal.isYAxisUp) { if (closed) { for (var i = 0; i < cvct; i++) { controlVertices.Add(new Point3D(p_aCVs[i].x, p_aCVs[i].y, p_aCVs[i].z)); weights.Add(1.0); } } else { foreach (var p in p_aCVs) { controlVertices.Add(new Point3D(p.x, p.y, p.z)); weights.Add(1.0); } } } else { if (closed) { for (var i = 0; i < cvct; i++) { controlVertices.Add(new Point3D(p_aCVs[i].x, -p_aCVs[i].z, p_aCVs[i].y)); weights.Add(1.0); } } else { foreach (var p in p_aCVs) { controlVertices.Add(new Point3D(p.x, -p.z, p.y)); weights.Add(1.0); } } } double min = 0, max = 0; nc.getKnotDomain(ref min, ref max); var d_aKnots = new MDoubleArray(); nc.getKnots(d_aKnots); knots = new List <double>(); knots.Add(min); knots.AddRange(d_aKnots); knots.Add(max); nc.Dispose(); d_aKnots.Dispose(); }
public DMMesh(MDagPath dagShape, MDagPath dagTransform, MSpace.Space mspace) : base(dagShape, dagTransform, mspace) { // MayaMesh = new MFnMesh(dagShape); }
internal static Mesh MTDMeshFromDag(MDagPath dagPath, MSpace.Space space) { return(MTDMeshFromMayaMesh(new MFnMesh(dagPath), space)); }
public DMMesh(MDagPath dagPath, MSpace.Space mspace) : base(dagPath, mspace) { //MayaMesh = new MFnMesh(dagPath); }