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[] BindIKControl(MDagPath rootDagPath, MDagPath endDagPath, JointProcess.IKSolverType iKSolverType = JointProcess.IKSolverType.RotatePlane, MDagPath ctlDagPath = null) { MFnTransform endTrans = new MFnTransform(endDagPath); MDagPath middleDagPath = MDagPath.getAPathTo(endTrans.parent(0)); if (ctlDagPath == null) { ctlDagPath = BasicFunc.AddChildCircle(endDagPath); BasicFunc.UnparentTransform(ctlDagPath); BasicFunc.FreezeTransform(new MFnTransform(ctlDagPath)); } //string resultStr = MGlobal.executeCommandStringResult("ikHandle -sj " + rootObject.fullPathName() + " -ee " + endObject.fullPathName() + " -sol ikRPsolver -n ik_" + rootObject.partialPathName() + "_" + endObject.partialPathName(),true); //string resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + rootDagPath.fullPathName + "',ee='" + endDagPath.fullPathName + "',sol='ikRPsolver',n='ik_" + rootDagPath.partialPathName + "_" + endDagPath.partialPathName + "')"); //[u'ik_joint1_joint4', u'effector1'] string[] resultArr = JointProcess.AddIKHandle(rootDagPath, endDagPath, iKSolverType, ctlDagPath.fullPathName); MGlobal.executeCommandStringResult("pointConstraint " + ctlDagPath.fullPathName + " " + resultArr[0]); if (iKSolverType == JointProcess.IKSolverType.RotatePlane) { MDagPath locDagPath = AddRPIKPole(middleDagPath); if (locDagPath != null) { BasicFunc.FreezeTransform(new MFnTransform(locDagPath)); //begin to add constriant BasicFunc.AddConstraint(locDagPath.fullPathName, resultArr[0], ConstantValue.ConstraintType.PoleVector); //string poleConstraintResult = MGlobal.executeCommandStringResult("poleVectorConstraint " + locDagPath.fullPathName + " " + resultArr[0]); //Debug.Log(poleConstraintResult); return(new MDagPath[3] { BasicFunc.GetDagPathByName(resultArr[0]), ctlDagPath, locDagPath }); } } return(new MDagPath[2] { BasicFunc.GetDagPathByName(resultArr[0]), ctlDagPath }); }