def _createIkSolvers(self): """Create the ik solver for the normal IK and spring IK. """ ik_grp = mc.group(n="{}_{}_ikHandles_{}_{}".format(self.side, self.name, self.suffix, self.instance_num), p=self.mod_dict["noTransform"], em=1) ikspring = mc.ikHandle(sj=self.joint_dict["hip" + "SPRING"], ee=self.joint_dict["ball" + "SPRING"], sol="ikSpringSolver", n="{}_{}_hip_iks_{}".format(self.side, self.name, self.instance_num)) ikrps = mc.ikHandle(sj=self.joint_dict["hip" + "IK"], ee=self.joint_dict["foot" + "IK"], sol="ikRPsolver", n="{}_{}_hip_iss_{}".format(self.side, self.name, self.instance_num)) for i in [ikspring, ikrps]: mc.parent(i[0], ik_grp) self.ikSolvers[i[0].split("_")[3]] = i[0] hock_grp = mc.listRelatives(self.ik_controllers["footIkOffset"], pa=1)[1] rjc.constrain_object(hock_grp, ikspring[0], "point", 1) auto_hock_hook = mc.group(n=self.joint_dict["footSPRING"].replace("_jnt", "hook_grp"), em=1) pos = mc.xform(self.joint_dict["footSPRING"], q=1, ws=1, t=1) mc.xform(auto_hock_hook, ws=1, t=pos) mc.parent(auto_hock_hook, self.joint_dict["footSPRING"]) self.misc["hockmaster2"] = auto_hock_hook rjc.constrain_object(self.misc["footHook"], ikrps[0], "point", 0)
def _createBendControls(self): """Create bendy controls. """ bendy_grp = mc.group(n="{}_{}_bendy_{}_{}".format(self.side, self.name, self.suffix, self.instance_num), p=self.mod_dict["FKcontrol"], em=1) for limb in [["upper", self.nurbs["hip"]], ["lower", self.nurbs["knee"]]]: if limb[0] == "upper": cnstr = ["hip", "knee"] else: cnstr = ["knee", "foot"] ctl = mc.circle(n=limb[1].replace("_nrb", "Bendy_ctl"), r=2)[0] grp = mc.group(ctl, n=ctl.replace("ctl", "grp")) rjc.constrain_object([self.clusters[cnstr[0] + "0jnt"], self.clusters[cnstr[0] + "2jnt"]], grp, "point", 0) mc.parent(grp, bendy_grp) mc.aimConstraint(self.clusters[cnstr[0] + "2jnt"], grp, aimVector=[0, 0, 1], upVector=[0, 1, 0], worldUpType="objectrotation", worldUpVector=[0, 0, -1], worldUpObject=self.clusters[cnstr[0] + "0jnt"], n=grp.replace("grp", "aic")) rjc.constrain_object(ctl, self.clusters[cnstr[0] + "1"], "parent", 1) mc.skinCluster(self.nurb_drivers[limb[0]], limb[1], mi=1, dr=10, tsb=1)
def _constrainHockSubGroup(self): """Make orient constraint to change space of hock control. """ rjc.constrain_object([self.misc["hockmaster1"], self.misc["hockmaster2"]], self.misc["hockslave1"], "orient", 1) mc.connectAttr(self.ik_controllers["hindleg"] + ".autoHock", self.misc["hockslave1"] + "." + self.misc["hockmaster2"] + "_orient_matrix_constraint") rev = mc.createNode("reverse", n=self.misc["hockmaster2"].replace("hook_grp", "_rev")) mc.connectAttr(self.ik_controllers["hindleg"] + ".autoHock", rev + ".inputX") mc.connectAttr(rev + ".outputX", self.misc["hockslave1"] + "." + self.misc["hockmaster1"] + "_orient_matrix_constraint")
def _createMasterControl(self): """Create main hindleg control with attrs.""" hindleg_main_ctl = mc.circle(n="{}_{}_ctl_{}".format(self.side, self.name, self.instance_num), r=1)[0] hindleg_offset_grp = mc.group(hindleg_main_ctl, n=hindleg_main_ctl.replace("ctl", "grp")) hindleg_zero_grp = mc.group(hindleg_offset_grp, n=hindleg_main_ctl.replace("ctl", "zero"), p=self.mod_dict["FKcontrol"]) pos = mc.xform(self.joint_dict["footFINAL"], q=1, ws=1, t=1) mc.xform(hindleg_zero_grp, ws=1, t=pos) mc.xform(hindleg_offset_grp, t=[1, 0, 0]) self._createIkFootAttrs(hindleg_main_ctl) self.ik_controllers[hindleg_main_ctl.split("_")[1]] = hindleg_main_ctl rjc.constrain_object(self.joint_dict["footFINAL"], hindleg_zero_grp, "parent", 1)
def _constrainNurbsDrivers(self): """Constrain nurbs driver joints. """ rjc.constrain_object(self.joint_dict["hipFINAL"], self.clusters["hip0"], "parent", 1) rjc.constrain_object(self.joint_dict["kneeFINAL"], self.clusters["hip2"], "parent", 1) rjc.constrain_object(self.joint_dict["kneeFINAL"], self.clusters["knee0"], "parent", 1) rjc.constrain_object(self.joint_dict["footFINAL"], self.clusters["knee2"], "parent", 1)
def _createFootFkHierarchy(self): """Create the FK chain for the leg.""" prev_control = None fk_master_grp = mc.group(n="{}_{}_footFk_{}_{}".format(self.side, self.name, self.suffix, self.instance_num), p=self.mod_dict["FKcontrol"], em=1) for i, joint in enumerate(["pelvis", "hip", "knee", "foot", "ball"]): ref_joint = self.joint_dict[joint + "FK"] pos = mc.xform(ref_joint, q=1, ws=1, matrix=1) fk_ctl = mc.circle(n=ref_joint.replace("jnt", "ctl"), r=1)[0] fk_grp = mc.group(fk_ctl, n=fk_ctl.replace("ctl", "grp")) fk_zero = mc.group(fk_grp, n=fk_ctl.replace("ctl", "zero")) mc.xform(fk_zero, ws=1, matrix=pos) rjc.constrain_object(fk_ctl, self.joint_dict[joint + "FK"], "point", 1) mc.orientConstraint(fk_ctl, self.joint_dict[joint + "FK"], n=fk_ctl + "_orc", mo=1) self.fk_controllers[fk_ctl.split("_")[2]] = fk_ctl if i == 0: mc.parent(fk_zero, fk_master_grp) prev_control = fk_ctl elif i == 1: rev = mc.createNode("reverse", n=fk_ctl.replace("ctl", "rev")) mc.connectAttr(self.ik_controllers["hindleg"] + ".ikFk", rev + ".inputX") mc.connectAttr(rev + ".outputX", fk_zero + ".v") mc.parent(fk_zero, prev_control) prev_control = fk_ctl else: mc.parent(fk_zero, prev_control) prev_control = fk_ctl rjc.constrain_object(self.fk_controllers["pelvisFK"], self.ik_controllers["hipIk"].replace("ctl", "zero"), "parent", 1) mc.parentConstraint(self.fk_controllers["pelvisFK"], self.joint_dict["pelvisIK"], n=self.joint_dict["pelvisIK"].replace("jnt", "prc"), mo=1) mult = mc.createNode("multDoubleLinear", n=self.misc["footHookCth"].replace("cth", "_rev")) mc.setAttr(mult + ".input2", -1) mc.connectAttr(self.ik_controllers["hindleg"] + ".stretchHock", mult + ".input1") mc.connectAttr(mult + ".output", self.misc["footHookCth"] + ".tx")
def _createPoleVector(self): """Position pole vector control. """ root_pos = self.guides["hip"][1] mid_pos = self.guides["knee"][1] end_pos = self.guides["foot"][1] root_joint_vec = om.MVector(root_pos) mid_joint_vec = om.MVector(mid_pos) end_joint_vec = om.MVector(end_pos) line = (end_joint_vec - root_joint_vec) point = (mid_joint_vec - root_joint_vec) scale_value = (line * point) / (line * line) proj_vec = line * scale_value + root_joint_vec root_to_mid_len = (mid_joint_vec - root_joint_vec).length() mid_to_end_len = (end_joint_vec - mid_joint_vec).length() total_length = mid_to_end_len + root_to_mid_len pole_vec_pos = (mid_joint_vec - proj_vec).normal() * total_length + mid_joint_vec pole_vec = '{}_{}_pole_ctl_{}'.format(self.side, self.name, self.instance_num) mc.circle(n=pole_vec, r=.5) pole_grp = mc.group(pole_vec, n=pole_vec.replace('ctl', 'grp')) mc.move(pole_vec_pos.x, pole_vec_pos.y, pole_vec_pos.z, pole_grp) rjc.constrain_object(self.ik_controllers["footIk"], pole_grp, "parent", 1) # parent pole grp mc.parent(pole_grp, self.mod_dict["IKcontrol"]) item = pole_vec.split('_')[2] self.ik_controllers[item] = pole_vec mc.poleVectorConstraint(pole_vec, self.ikSolvers["iks"], n=self.ikSolvers["iks"].replace("_iks", "01_pvc")) mc.poleVectorConstraint(pole_vec, self.ikSolvers["iss"], n=self.ikSolvers["iss"].replace("_iss", "02_pvc"))
def _createHockIkHierarchy(self): """Create IK hock control hierarchy. """ ik_hock_ctl = mc.circle(n="{}_{}_hockIk_ctl_{}".format(self.side, self.name, self.instance_num), r=1)[0] ik_hock_grp = mc.group(ik_hock_ctl, n=ik_hock_ctl.replace("ctl", "grp")) ik_hock_zero = mc.group(ik_hock_grp, n=ik_hock_ctl.replace("ctl", "zero")) inverse_hock_grp = mc.group(n=ik_hock_ctl.replace("_ctl", "_Inverse_grp"), em=1) inverse_hock_zero = mc.group(inverse_hock_grp, n=ik_hock_ctl.replace("_ctl", "_Inverse_zero")) mc.setAttr(inverse_hock_grp + ".rotateOrder", 5) mc.connectAttr(self.ik_controllers["hindleg"] + ".ikFk", ik_hock_zero + ".v") mc.parent(inverse_hock_zero, ik_hock_ctl) mc.parent(ik_hock_zero, self.mod_dict["IKcontrol"]) mc.xform(ik_hock_zero, ws=1, matrix=self.guides["foot"][2]) par_del = mc.parentConstraint(self.ik_controllers["footIk"], inverse_hock_zero) mc.delete(par_del) mult = mc.createNode("multiplyDivide", n=inverse_hock_grp.replace("grp", "mdn")) mc.setAttr(mult + ".input2X", -1) mc.setAttr(mult + ".input2Y", -1) mc.setAttr(mult + ".input2Z", -1) mc.connectAttr(self.misc["hockslave1"] + ".r", mult + ".input1") mc.connectAttr(mult + ".output", inverse_hock_grp + ".r") hock_grp = mc.listRelatives(self.ik_controllers["footIkOffset"], ad=1)[1] rjc.constrain_object(hock_grp, ik_hock_zero, "parent", 1) rollIn_grp = mc.group(n=ik_hock_ctl.replace("ctl", "rollIn_org"), em=1) rollOut_grp = mc.group(n=ik_hock_ctl.replace("ctl", "rollOut_org"), em=1) rollHeel_ctl = mc.circle(n=ik_hock_ctl.replace("ctl", "rollHeel_ctl"), r=.4)[0] rollHeel_cth = mc.group(rollHeel_ctl, n=ik_hock_ctl.replace("ctl", "rollHeel_cth")) rollHeel_org = mc.group(rollHeel_cth, n=ik_hock_ctl.replace("ctl", "rollHeel_org")) rollToe_ctl = mc.circle(n=ik_hock_ctl.replace("ctl", "rollToe_ctl"), r=.4)[0] rollToe_cth = mc.group(rollToe_ctl, n=ik_hock_ctl.replace("ctl", "rollToe_cth")) rollToe_org = mc.group(rollToe_cth, n=ik_hock_ctl.replace("ctl", "rollToe_org")) ballIk_ctl = mc.circle(n=ik_hock_ctl.replace("hockIk_ctl", "ballIk_ctl"), r=.4)[0] ballIk_cth = mc.group(ballIk_ctl, n=ballIk_ctl.replace("ctl", "cth")) ballIk_org = mc.group(ballIk_cth, n=ballIk_ctl.replace("ctl", "org")) footIk_grp = mc.group(n=ik_hock_ctl.replace("ctl", "footHook_grp"), em=1) footIk_cth = mc.group(footIk_grp, n=footIk_grp.replace("grp", "cth")) footIk_org = mc.group(footIk_cth, n=footIk_grp.replace("grp", "org")) footIkRev_org = mc.group(footIk_org, n=footIk_grp.replace("_grp", "Inverse_org")) footIkAttr_org = mc.group(footIkRev_org, n=footIk_grp.replace("_grp", "Attr_org")) mc.xform(rollIn_grp, ws=1, t=self.guides["rollIn"][1]) mc.xform(rollOut_grp, ws=1, t=self.guides["rollOut"][1]) mc.xform(rollHeel_org, ws=1, t=self.guides["rollHeel"][1]) mc.xform(rollToe_org, ws=1, t=self.guides["toeEnd"][1]) mc.xform(ballIk_org, ws=1, t=self.guides["ball"][1]) mc.xform(footIkAttr_org, ws=1, t=self.guides["ball"][1]) mc.xform(footIk_org, ws=1, matrix=self.guides["foot"][2]) mc.parent(rollIn_grp, inverse_hock_grp) mc.parent(rollOut_grp, rollIn_grp) mc.parent(rollHeel_org, rollOut_grp) mc.parent(rollToe_org, rollHeel_ctl) mc.parent(ballIk_org, rollToe_ctl) mc.parent(footIkAttr_org, ballIk_ctl) mc.connectAttr(self.misc["hockslave1"] + ".r", footIkRev_org + ".r") mc.parentConstraint(ballIk_cth, self.joint_dict["ball" + "IK"], n=ballIk_cth.replace("cth", "prc"), mo=1) par = mc.parentConstraint(ballIk_cth, self.joint_dict["ball" + "FK"], self.joint_dict["ball" + "FINAL"], n=self.joint_dict["ball" + "FK"].replace("jnt", "prc").replace("parentConstraint1", ""), mo=1)[0] mc.connectAttr(self.ik_controllers["hindleg"] + ".ikFk", par + "." + ballIk_cth + "W0") rev = mc.createNode("reverse", n=self.joint_dict["ball" + "FK"].replace("jnt", "rev")) mc.connectAttr(self.ik_controllers["hindleg"] + ".ikFk", rev + ".inputX") mc.connectAttr(rev + ".outputX", par + "." + self.joint_dict["ball" + "FK"] + "W1") self.misc["footHook"] = footIk_grp self.misc["footHookCth"] = footIk_cth self.misc["footHookAttr"] = footIkAttr_org self.misc["rollToe"] = rollToe_cth self.misc["rollHeel"] = rollHeel_cth self.misc["rollIn"] = rollIn_grp self.misc["rollOut"] = rollOut_grp