/// <summary> /// Return the type of the direct descendants of the node /// </summary> /// <param name="mDagPath"></param> /// <returns> Return Mesh, Camera, Light or Unknown</returns> private MFn.Type getApiTypeOfDirectDescendants(MDagPath mDagPath) { for (uint i = 0; i < mDagPath.childCount; i++) { MObject childObject = mDagPath.child(i); MFnDagNode nodeObject = new MFnDagNode(childObject); switch (childObject.apiType) { case MFn.Type.kMesh: if (IsMeshExportable(nodeObject, mDagPath)) { return(MFn.Type.kMesh); } break; case MFn.Type.kCamera: if (IsCameraExportable(nodeObject, mDagPath)) { return(MFn.Type.kCamera); } break; } // Lights api type are kPointLight, kSpotLight... // Easier to check if has generic light function set rather than check all cases if (mDagPath.hasFn(MFn.Type.kLight) && IsLightExportable(nodeObject, mDagPath)) { // Return generic kLight api type return(MFn.Type.kLight); } } return(MFn.Type.kUnknown); }
private static string GetParentName(MFnIkJoint Joint) { // Attempt to result var FullPath = Joint.fullPathName; var SplitPath = FullPath.Substring(1).Split('|'); if (SplitPath.Length > 2) { // We have parents, fetch second to last return(CleanNodeName(SplitPath[SplitPath.Length - 2])); } else if (SplitPath.Length == 2) { // We have parents, ensure this is a joint parent var SelectList = new MSelectionList(); SelectList.add(FullPath.Substring(0, FullPath.IndexOf("|", 1))); // Grab it var Result = new MDagPath(); SelectList.getDagPath(0, Result); // Check if (Result.hasFn(MFn.Type.kJoint)) { return(CleanNodeName(SplitPath[SplitPath.Length - 2])); } } // Root bone return(string.Empty); }
public static void BindBodySplineIK(MSelectionList jointList = null) { if (jointList == null) { jointList = BasicFunc.GetSelectedList(); } //check if all of selected objects are joint int count = (int)jointList.length; if (count < 2) { return; } MDagPath dag_breastJoint = new MDagPath(), dag_hipJoint = new MDagPath(); for (int i = 0; i < count; i++) { MDagPath jtDagPath = new MDagPath(); jointList.getDagPath((uint)i, jtDagPath); if (jtDagPath != null) { if (!jtDagPath.hasFn(MFn.Type.kJoint)) { return; } } else { return; } } jointList.getDagPath((uint)(count - 1), dag_breastJoint); jointList.getDagPath(0, dag_hipJoint); MFnIkJoint breastJoint = new MFnIkJoint(dag_breastJoint); MFnIkJoint hipJoint = new MFnIkJoint(dag_hipJoint); MDagPath dag_curve = JointProcess.CreateJointsCurve(jointList); MDagPath dag_jtctl_breast = JointProcess.CreateJoint(breastJoint, "jtctl_breast"); MDagPath dag_jtctl_hip = JointProcess.CreateJoint(hipJoint, "jtctl_hip"); MSelectionList bindSelectionList = new MSelectionList(); bindSelectionList.add(dag_curve); bindSelectionList.add(dag_jtctl_breast); bindSelectionList.add(dag_jtctl_hip); BasicFunc.Select(bindSelectionList); MGlobal.executeCommand("SmoothBindSkin"); string ikName = JointProcess.AddIKHandle(dag_hipJoint, dag_breastJoint, JointProcess.IKSolverType.Spline, dag_curve.fullPathName)[0]; MDagPath dag_ik = BasicFunc.GetDagPathByName(ikName); BasicFunc.ConnectAttr(dag_jtctl_breast.fullPathName + ".rotate.rotateY", dag_ik.fullPathName + ".twist", true, true); }
public static MDagPath CurveToHair(ref MDagPath hairSystemDagPath, MDagPath curveDagPath = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base) { if (curveDagPath == null) { curveDagPath = BasicFunc.GetSelectedDagPath(0); } bool hairSystemReady = !hairSystemDagPath.node.isNull; MSelectionList targetList = new MSelectionList(); targetList.add(curveDagPath); if (hairSystemReady) { Debug.Log("hair system ready"); targetList.add(hairSystemDagPath); } else { Debug.Log("hair system need to be created!"); } BasicFunc.Select(targetList); string cmdStr = "cmds.MakeCurvesDynamic(0,0,0,1,0)"; string resultStr = MGlobal.executePythonCommandStringResult(cmdStr); MDagPath result = new MDagPath(); //Debug.Log(curveDagPath.fullPathName); MFnTransform curveTrans = new MFnTransform(curveDagPath); if (curveTrans.parentCount > 0) { MDagPath follicleDagPath = MDagPath.getAPathTo(curveTrans.parent(0)); MGlobal.executeCommand(string.Format("setAttr {0}.pointLock {1}", follicleDagPath.fullPathName, (int)pointLock)); if (follicleDagPath.hasFn(MFn.Type.kFollicle)) { Debug.Log("follicle exist!"); ConvertHairSelection(HairSelectionType.OutputCurves, follicleDagPath); result = BasicFunc.GetSelectedDagPath(0); new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName); if (!hairSystemReady) { ConvertHairSelection(HairSelectionType.HairSystem); hairSystemDagPath = BasicFunc.GetSelectedDagPath(0); hairSystemReady = true; } } } return(result); }
/// <summary> /// /// </summary> /// <param name="isFull">If true all nodes are printed, otherwise only relevant ones</param> private void PrintDAG(bool isFull, MObject root = null) { var dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst); if (root != null) { dagIterator.reset(root); } RaiseMessage("DAG: " + (isFull ? "full" : "relevant")); while (!dagIterator.isDone) { MDagPath mDagPath = new MDagPath(); dagIterator.getPath(mDagPath); if (isFull || isNodeRelevantToExportRec(mDagPath) || mDagPath.apiType == MFn.Type.kMesh || mDagPath.apiType == MFn.Type.kCamera || mDagPath.hasFn(MFn.Type.kLight) || mDagPath.apiType == MFn.Type.kLocator) { RaiseMessage("name=" + mDagPath.partialPathName + "\t type=" + mDagPath.apiType, (int)dagIterator.depth + 1); } else { dagIterator.prune(); } dagIterator.next(); } }
bool hasLights(MDagPath path) { return(path.hasFn(MFn.Type.kDirectionalLight) || path.hasFn(MFn.Type.kPointLight) || path.hasFn(MFn.Type.kSpotLight)); }
bool hasMeshes(MDagPath path) { return(path.hasFn(MFn.Type.kMesh)); }
bool hasMeshes( MDagPath path ) { return path.hasFn(MFn.Type.kMesh); }
bool hasLights( MDagPath path ) { return path.hasFn(MFn.Type.kDirectionalLight) || path.hasFn(MFn.Type.kPointLight) || path.hasFn(MFn.Type.kSpotLight); }
/// <summary> /// return Dynamic Output Curve /// </summary> /// <param name="hairSystemDagPath">exist hairsystem or container of created hairsystem</param> /// <param name="curveList"></param> /// <param name="pointLock">0-none, 1-base, 2-end,3-both</param> /// <returns></returns> public static MDagPath[] CurvesToHairs(ref MDagPath hairSystemDagPath, MSelectionList curveList = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base) { if (curveList == null) { curveList = BasicFunc.GetSelectedList(); } bool hairSystemReady = false; if (!hairSystemDagPath.node.isNull) { //Debug.Log("hairSystem node is not null:" + hairSystemDagPath.fullPathName); curveList.add(hairSystemDagPath); hairSystemReady = true; } else { //Debug.Log("hairsystem node is null"); } MGlobal.setActiveSelectionList(curveList); string cmdStr = "cmds.MakeCurvesDynamic(0,0,0,1,0)"; string resultStr = MGlobal.executePythonCommandStringResult(cmdStr); if (hairSystemReady) { //Debug.Log("remove hairSystem Selection"); curveList.remove(curveList.length - 1); } List <MDagPath> results = new List <MDagPath>(); for (int i = 0; i < curveList.length; i++) { MDagPath curveDagPath = new MDagPath(); curveList.getDagPath((uint)i, curveDagPath); //Debug.Log(curveDagPath.fullPathName); MFnTransform curveTrans = new MFnTransform(curveDagPath); if (curveTrans.parentCount > 0) { MDagPath follicleDagPath = MDagPath.getAPathTo(curveTrans.parent(0)); MGlobal.executeCommand(string.Format("setAttr {0}.pointLock {1}", follicleDagPath.fullPathName, (int)pointLock)); if (follicleDagPath.hasFn(MFn.Type.kFollicle)) { Debug.Log("follicle exist!"); ConvertHairSelection(HairSelectionType.OutputCurves, follicleDagPath); MDagPath result = BasicFunc.GetSelectedDagPath(0); new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName); results.Add(result); if (!hairSystemReady) { ConvertHairSelection(HairSelectionType.HairSystem); hairSystemDagPath = BasicFunc.GetSelectedDagPath(0); //Debug.Log("assign hairSystem:" + hairSystemDagPath.fullPathName); hairSystemReady = true; } } } } //error return(results.ToArray()); }
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); }