public static Point[][] GetSurfaceCVs(MFnNurbsSurface mayaSurface) { MPointArray cvs = new MPointArray(); mayaSurface.getCVs(cvs, MSpace.Space.kWorld); int cvUct = mayaSurface.numCVsInU; int cvVct = mayaSurface.numCVsInV; //setup the points Point[][] ctrlPts = new Point[cvUct][]; for (int i = 0; i < cvUct; i++) { ctrlPts[i] = new Point[cvVct]; for (int j = 0; j < cvVct; j++) { 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); } } } return(ctrlPts); }
public static double[] GetKnotsV(MFnNurbsSurface mayaSurface) { MDoubleArray knotV = new MDoubleArray(); mayaSurface.getKnotsInV(knotV); return(knotV.ToArray()); }
public static double[] GetKnotsU(MFnNurbsSurface mayaSurface) { MDoubleArray knotU = new MDoubleArray(); mayaSurface.getKnotsInU(knotU); return(knotU.ToArray()); }
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); }
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); }
public static void ToMaya(Surface SurfaceToSend, string name, string groupName) { NurbsSurface dynSurf; try { dynSurf = SurfaceToSend.ToNurbsSurface(); } catch (Exception) { dynSurf = null; MGlobal.displayWarning("Surface has no nurbSurface form"); } //MFnNurbsSurface updatedSurface; MPointArray cvs = new MPointArray(); Point[][] ctrlPts = dynSurf.ControlPoints(); for (int i = 0; i < ctrlPts.Length; i++) { for (int j = 0; j < ctrlPts[i].Length; j++) { MPoint p = new MPoint(); if (MGlobal.isZAxisUp) { p.x = ctrlPts[i][j].X; p.y = ctrlPts[i][j].Y; p.z = ctrlPts[i][j].Z; } else { p.x = ctrlPts[i][j].X; p.y = ctrlPts[i][j].Z; p.z = -ctrlPts[i][j].Y; } cvs.Add(p); } } MDoubleArray uknot = new MDoubleArray(dynSurf.UKnots()); uknot.RemoveAt(0); uknot.RemoveAt(uknot.Count - 1); MDoubleArray vknot = new MDoubleArray(dynSurf.VKnots()); vknot.RemoveAt(0); vknot.RemoveAt(vknot.Count - 1); MFnNurbsSurface.Form formU = MFnNurbsSurface.Form.kInvalid; MFnNurbsSurface.Form formV = MFnNurbsSurface.Form.kInvalid; if (dynSurf.IsPeriodicInU) { formU = MFnNurbsSurface.Form.kPeriodic; } else if (dynSurf.ClosedInU) { formU = MFnNurbsSurface.Form.kClosed; } else { formU = MFnNurbsSurface.Form.kOpen; } if (dynSurf.IsPeriodicInV) { formV = MFnNurbsSurface.Form.kPeriodic; } else if (dynSurf.ClosedInV) { formV = MFnNurbsSurface.Form.kClosed; } else { formV = MFnNurbsSurface.Form.kOpen; } MDagPath existingDagPath = null; bool nodeExists = false; //trims //toDo: impement trims Task checkNode = null; try { checkNode = Task.Factory.StartNew(() => existingDagPath = DMInterop.getDagNode(name)); checkNode.Wait(500); nodeExists = true; } catch (Exception) { nodeExists = false; } MObject obj; if (nodeExists) { if (checkNode.IsCompleted) { MFnNurbsSurface existingSurface = new MFnNurbsSurface(existingDagPath); MDGModifier mdgModifier = new MDGModifier(); // if (existingSurface.degreeU == dynSurf.DegreeU && existingSurface.degreeV== dynSurf.DegreeV && existingSurface.numCVsInU == ctrlPts.Length && existingSurface.numCVsInV == ctrlPts[0].Length ) //{ if (existingSurface.degreeU != dynSurf.DegreeU || existingSurface.degreeV != dynSurf.DegreeV || existingSurface.numCVsInU != ctrlPts.Length || existingSurface.numCVsInV != ctrlPts[0].Length) { //this is a hack to rebuild the surface. proper way is to make new surface and assign as input to aold surface MGlobal.executeCommand(string.Format("rebuildSurface -du {0} -dv {1} -su {2} -sv {3} {4}", dynSurf.DegreeU, dynSurf.DegreeV, ctrlPts.Length - 3, ctrlPts[0].Length - 3, name)); } // updatedSurface = existingSurface; existingSurface.setCVs(cvs); existingSurface.setKnotsInU(uknot, 0, (uint)existingSurface.numKnotsInU - 1); existingSurface.setKnotsInV(vknot, 0, (uint)existingSurface.numKnotsInV - 1); existingSurface.updateSurface(); // } /* * else * * { * //get all the existing node types * MFnDagNode dagNodeExist = new MFnDagNode(existingDagPath); * MObject existSurfObj = existingDagPath.node; * MFnDependencyNode depNodeExist = new MFnDependencyNode(existSurfObj); * * * updatedSurface = new MFnNurbsSurface(); * var newSurfObj = dagNodeExist.duplicate(); * updatedSurface.isIntermediateObject = true; * * updatedSurface.create(cvs, uknot, vknot, (uint)dynSurf.DegreeU, (uint)dynSurf.DegreeV, formU, formV, dynSurf.IsRational, newSurfObj); * MFnDependencyNode depNodeNew = new MFnDependencyNode(newSurfObj); * * MPlug outSurf = depNodeExist.findPlug("outputSurface"); * MPlug inSurf = depNodeNew.findPlug("inputSurface"); * * * mdgModifier.connect(outSurf, inSurf); * * * } */ mdgModifier.doIt(); // MFnDependencyNode nodeFn = new MFnDagNode(mSurf); //nodeFn.setName(name); //MGlobal.executeCommand("sets -e -forceElement initialShadingGroup " + nodeFn.name); } } else { if (checkNode.IsCompleted) { MFnNurbsSurface updatedSurface = new MFnNurbsSurface(); obj = updatedSurface.create(cvs, uknot, vknot, (uint)dynSurf.DegreeU, (uint)dynSurf.DegreeV, formU, formV, dynSurf.IsRational); MFnDependencyNode nodeFn = new MFnDagNode(obj); nodeFn.setName(name); MGlobal.executeCommand("sets -e -forceElement initialShadingGroup " + nodeFn.name); } } if (groupName != "") { bool groupExists = false; try { DMInterop.getDagNode(groupName); groupExists = true; } catch { } if (groupExists) { MGlobal.executeCommand(string.Format("parent {0} {1}", groupName, name)); } else { MGlobal.executeCommand(string.Format("group -n {0} {1}", groupName, name)); } } }
internal static Surface mNurbsSurfaceToDynamoSurfaceFromDag(MDagPath dagPath, MSpace.Space space) { MFnNurbsSurface surface = new MFnNurbsSurface(dagPath); return(mNurbsSurfaceToDynamoSurface(surface, space)); }
private void doScan(MItDag.TraversalType traversalType, MFn.Type filter, bool quiet) { MItDag dagIterator = new MItDag(traversalType, filter); // Scan the entire DAG and output the name and depth of each node if (traversalType == MItDag.TraversalType.kBreadthFirst) { if (!quiet) { MGlobal.displayInfo(Environment.NewLine + "Starting Breadth First scan of the Dag"); } else if (!quiet) { MGlobal.displayInfo(Environment.NewLine + "Starting Depth First scan of the Dag"); } } switch (filter) { case MFn.Type.kCamera: if (!quiet) { MGlobal.displayInfo(": Filtering for Cameras\n"); } break; case MFn.Type.kLight: if (!quiet) { MGlobal.displayInfo(": Filtering for Lights\n"); } break; case MFn.Type.kNurbsSurface: if (!quiet) { MGlobal.displayInfo(": Filtering for Nurbs Surfaces\n"); } break; default: MGlobal.displayInfo(Environment.NewLine); break; } int objectCount = 0; for ( ; !dagIterator.isDone; dagIterator.next()) { MDagPath dagPath = new MDagPath(); try { dagIterator.getPath(dagPath); } catch (System.Exception) { continue; } MFnDagNode dagNode = null; try { dagNode = new MFnDagNode(dagPath); } catch (System.Exception) { continue; } if (!quiet) { MGlobal.displayInfo(dagNode.name + ": " + dagNode.typeName + Environment.NewLine); } if (!quiet) { MGlobal.displayInfo(" dagPath: " + dagPath.fullPathName + Environment.NewLine); } objectCount += 1; if (dagPath.hasFn(MFn.Type.kCamera)) { MFnCamera camera = null; try { camera = new MFnCamera(dagPath); } catch (System.Exception) { continue; } // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); // Extract some interesting Camera data // if (!quiet) { MGlobal.displayInfo(" eyePoint: " + MPointToString(camera.eyePoint(MSpace.Space.kWorld)) + Environment.NewLine); MGlobal.displayInfo(" upDirection: " + MVectorToString(camera.upDirection(MSpace.Space.kWorld)) + Environment.NewLine); MGlobal.displayInfo(" viewDirection: " + MVectorToString(camera.viewDirection(MSpace.Space.kWorld)) + Environment.NewLine); MGlobal.displayInfo(" aspectRatio: " + Convert.ToString(camera.aspectRatio) + Environment.NewLine); MGlobal.displayInfo(" horizontalFilmAperture: " + Convert.ToString(camera.horizontalFilmAperture) + Environment.NewLine); MGlobal.displayInfo(" verticalFilmAperture: " + Convert.ToString(camera.verticalFilmAperture) + Environment.NewLine); } } else if (dagPath.hasFn(MFn.Type.kLight)) { MFnLight light = null; try { light = new MFnLight(dagPath); } catch (System.Exception) { continue; } // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); // Extract some interesting Light data // MColor color = light.color; if (!quiet) { MGlobal.displayInfo(string.Format(" color: [%f, %f, %f]\n", color.r, color.g, color.b)); } color = light.shadowColor; if (!quiet) { MGlobal.displayInfo(string.Format(" shadowColor: [%f, %f, %f]\n", color.r, color.g, color.b)); MGlobal.displayInfo(" intensity: " + Convert.ToString(light.intensity) + Environment.NewLine); } } else if (dagPath.hasFn(MFn.Type.kNurbsSurface)) { MFnNurbsSurface surface = null; try { surface = new MFnNurbsSurface(dagPath); } catch (System.Exception) { continue; } // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); // Extract some interesting Surface data // if (!quiet) { MGlobal.displayInfo(string.Format(" numCVs: %d * %s", surface.numCVsInU, surface.numCVsInV) + Environment.NewLine); MGlobal.displayInfo(string.Format(" numKnots: %d * %s\n", surface.numKnotsInU, surface.numKnotsInV) + Environment.NewLine); MGlobal.displayInfo(string.Format(" numSpans: %d * %s\n", surface.numSpansInU, surface.numSpansInV) + Environment.NewLine); } } else { // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); } } setResult(objectCount); }
private void doScan(MItDag.TraversalType traversalType, MFn.Type filter, bool quiet) { MItDag dagIterator = new MItDag(traversalType, filter); // Scan the entire DAG and output the name and depth of each node if (traversalType == MItDag.TraversalType.kBreadthFirst) if (!quiet) MGlobal.displayInfo(Environment.NewLine + "Starting Breadth First scan of the Dag"); else if (!quiet) MGlobal.displayInfo(Environment.NewLine + "Starting Depth First scan of the Dag"); switch (filter) { case MFn.Type.kCamera: if (!quiet) MGlobal.displayInfo( ": Filtering for Cameras\n"); break; case MFn.Type.kLight: if (!quiet) MGlobal.displayInfo(": Filtering for Lights\n"); break; case MFn.Type.kNurbsSurface: if (!quiet) MGlobal.displayInfo(": Filtering for Nurbs Surfaces\n"); break; default: MGlobal.displayInfo(Environment.NewLine); break; } int objectCount = 0; for ( ; !dagIterator.isDone; dagIterator.next() ) { MDagPath dagPath = new MDagPath(); try { dagIterator.getPath(dagPath); } catch (System.Exception ) { continue; } MFnDagNode dagNode = null; try { dagNode = new MFnDagNode(dagPath); } catch (System.Exception ) { continue; } if (!quiet) MGlobal.displayInfo(dagNode.name + ": " + dagNode.typeName + Environment.NewLine); if (!quiet) MGlobal.displayInfo( " dagPath: " + dagPath.fullPathName + Environment.NewLine); objectCount += 1; if (dagPath.hasFn(MFn.Type.kCamera)) { MFnCamera camera = null; try { camera = new MFnCamera(dagPath); } catch (System.Exception) { continue; } // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); // Extract some interesting Camera data // if (!quiet) { MGlobal.displayInfo(" eyePoint: " + MPointToString(camera.eyePoint(MSpace.Space.kWorld)) + Environment.NewLine); MGlobal.displayInfo(" upDirection: " + MVectorToString( camera.upDirection(MSpace.Space.kWorld)) + Environment.NewLine); MGlobal.displayInfo(" viewDirection: " + MVectorToString( camera.viewDirection(MSpace.Space.kWorld)) + Environment.NewLine); MGlobal.displayInfo(" aspectRatio: " + Convert.ToString( camera.aspectRatio ) + Environment.NewLine); MGlobal.displayInfo(" horizontalFilmAperture: " + Convert.ToString(camera.horizontalFilmAperture ) + Environment.NewLine); MGlobal.displayInfo(" verticalFilmAperture: " + Convert.ToString(camera.verticalFilmAperture ) + Environment.NewLine); } } else if (dagPath.hasFn(MFn.Type.kLight)) { MFnLight light = null; try { light = new MFnLight(dagPath); } catch (System.Exception) { continue; } // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); // Extract some interesting Light data // MColor color = light.color; if (!quiet) { MGlobal.displayInfo(string.Format(" color: [%f, %f, %f]\n", color.r, color.g, color.b)); } color = light.shadowColor; if (!quiet) { MGlobal.displayInfo(string.Format(" shadowColor: [%f, %f, %f]\n", color.r, color.g, color.b)); MGlobal.displayInfo(" intensity: "+Convert.ToString(light.intensity) + Environment.NewLine); } } else if (dagPath.hasFn(MFn.Type.kNurbsSurface)) { MFnNurbsSurface surface= null; try { surface = new MFnNurbsSurface(dagPath); } catch (System.Exception ) { continue; } // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); // Extract some interesting Surface data // if (!quiet) { MGlobal.displayInfo(string.Format(" numCVs: %d * %s", surface.numCVsInU, surface.numCVsInV) + Environment.NewLine); MGlobal.displayInfo(string.Format(" numKnots: %d * %s\n", surface.numKnotsInU, surface.numKnotsInV) + Environment.NewLine); MGlobal.displayInfo(string.Format(" numSpans: %d * %s\n", surface.numSpansInU, surface.numSpansInV) + Environment.NewLine); } } else { // Get the translation/rotation/scale data // printTransformData(dagPath, quiet); } } setResult(objectCount); }