def addMainCnsCurve(self, ctls): crv_degree = 2 crv = helpers.addCnsCurve(self.crv_root, self.getName("mainCtl_crv"), ctls, crv_degree) ymt_util.setKeyableAttributesDontLockVisibility(crv[0], []) v = self.root.getTranslation(space="world") crv[0].setTranslation(v, om.MSpace.kWorld) self.mainCtlCurves.append(crv[0]) # create upvector curve to drive secondary control if self.secondary_ctl_check: mainCtlUpv = helpers.addCurve(self.crv_root, self.getName("mainCtl_upv"), ctls, crv_degree) ymt_util.setKeyableAttributesDontLockVisibility(mainCtlUpv, []) v = self.root.getTranslation(space="world") mainCtlUpv.setTranslation(v, om.MSpace.kWorld) # connect upv curve to mainCrv_ctl driver node. pm.connectAttr(crv[1].attr("outputGeometry[0]"), mainCtlUpv.getShape().attr("create")) # offset upv curve cvs = mainCtlUpv.getCVs(space="world") for i, cv in enumerate(cvs): offset = [cv[0], cv[1], cv[2] + self.FRONT_OFFSET] mainCtlUpv.setCV(i, offset, space='world') # collect mainCrv upv self.mainCtlUpvs.append(mainCtlUpv)
def addLookAtControlers(self, t_root, t_look): # Tracking # Eye aim control self.center_lookat = addTransform(self.over_ctl, self.getName("center_lookat"), t_root) radius = abs(self.getBboxRadius()[0] / 1.7) if True or not self.negate: ro = datatypes.Vector(0, 0, 0) po = datatypes.Vector(0, 0, radius) + self.offset else: ro = datatypes.Vector(math.pi, 0, 0) po = datatypes.Vector(0, 0, radius * -1.0) + self.offset self.arrow_npo = addTransform(self.root, self.getName("aim_npo"), t_look) self.arrow_ctl = self.addCtl( self.arrow_npo, "aim_%s" % self.ctlName, t_look, self.color_ik, "arrow", w=1, ro=ro, po=po, ) self.addToSubGroup(self.over_ctl, self.primaryControllersGroupName) ymt_util.setKeyableAttributesDontLockVisibility(self.arrow_ctl, params=["rx", "ry", "rz"])
def _visi_off_lock(node): """Short cuts.""" cmds.setAttr("{}.visibility".format(node.name()), l=False) node.visibility.set(False) try: ymt_util.setKeyableAttributesDontLockVisibility(node, []) except: pass
def addSecondaryCnsCurve(self, ctls): crv_degree = 2 crv = helpers.addCnsCurve(self.crv_root, self.getName("secCtl_crv"), ctls, crv_degree) ymt_util.setKeyableAttributesDontLockVisibility(crv[0], []) v = self.root.getTranslation(space="world") crv[0].setTranslation(v, om.MSpace.kWorld) self.secondaryCurves.append(crv[0]) self.rigCurves.append(crv[0])
def addObjects(self): """Add all the objects needed to create the component.""" if self.settings["neutralRotation"]: t = transform.getTransformFromPos(self.guide.pos["root"]) else: t = self.guide.tra["root"] if self._needToMirror(): scl = [1, 1, 1] scl[0] = -1 if self.settings["mirrorAxisX"] else 1 scl[1] = -1 if self.settings["mirrorAxisY"] else 1 scl[2] = -1 if self.settings["mirrorAxisZ"] else 1 t = transform.setMatrixScale(t, scl) rx = self.settings["mirrorAxisX"] * math.pi ry = self.settings["mirrorAxisY"] * math.pi rz = self.settings["mirrorAxisZ"] * math.pi # t = pm.datatypes.TransformationMatrix(t) # t.addRotation((rx, ry, rz), 'XYZ', 'object') else: scl = [1, 1, 1] t = transform.setMatrixScale(t, scl) self.ik_cns = primitive.addTransform( self.root, self.getName("ik_cns"), t) self.ctl = self.addCtl(self.ik_cns, "ctl", t, self.color_ik, self.settings["icon"], w=self.settings["ctlSize"] * self.size, h=self.settings["ctlSize"] * self.size, d=self.settings["ctlSize"] * self.size, tp=self.parentCtlTag) # we need to set the rotation order before lock any rotation axis if self.settings["k_ro"]: rotOderList = ["XYZ", "YZX", "ZXY", "XZY", "YXZ", "ZYX"] attribute.setRotOrder( self.ctl, rotOderList[self.settings["default_rotorder"]]) params = [s for s in ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"] if self.settings["k_" + s]] ymt_util.setKeyableAttributesDontLockVisibility(self.ctl, params) if self.settings["joint"]: self.jnt_pos.append([self.ctl, 0, None, self.settings["uniScale"]])
def addLengthCtrl(self, crv): t = getTransform(self.guide.root) t = self._getTransformWithRollByBlade(t) cvs = crv.length() tm = datatypes.TransformationMatrix(t) tm.addTranslation([0.0, cvs * 0.01, cvs * 1.4], om.MSpace.kObject) local_t = datatypes.Matrix(tm) self.length_npo = addTransform(self.aim_npo, self.getName("length_npo"), local_t) self.length_in = addTransform(self.length_npo, self.getName("sacle_in"), local_t) size = self.size w = size h = size d = size self.length_ctl = self.addCtl( self.length_in, "length_ctl", local_t, self.color_ik, "arrow", w=w, h=h, d=d, ro=datatypes.Vector([-math.pi / 2., math.pi / 2., 0.]) ) self.fk_upvectors = [] chain = getChainTransform2(self.guide.apos, self.normal, self.negate) for i, t in enumerate(chain): upv_npo = addTransform(self.length_in, self.getName("%s_fkupv_npo" % i), t) self.fk_upvectors.append(upv_npo) # global input self.scale_npo = addTransform(self.root, self.getName("scale_npo"), local_t) self.scale_in = addTransform(self.scale_npo, self.getName("sacle_in"), local_t) self.scale_ctl = self.addCtl( self.scale_in, "scale_ctl", local_t, self.color_ik, "cube", w=w*.2, h=h*.2, d=d*.2, ro=datatypes.Vector([-math.pi / 2., 0., 0.]) ) ymt_util.setKeyableAttributesDontLockVisibility(self.scale_ctl, self.s_params) ymt_util.setKeyableAttributesDontLockVisibility(self.length_ctl, ["tx", "ty", "tz"])
def addOverControllers(self, t): self.over_npo = addTransform(self.root, self.getName("center_lookatRoot"), t) self.over_ctl = self.addCtl(self.over_npo, "over_%s" % self.ctlName, t, self.color_ik, "square", w=self.getBboxRadius()[0], d=self.getBboxRadius()[1], ro=datatypes.Vector(1.57079633, 0, 0), po=self.offset, ) self.addToSubGroup(self.over_ctl, self.primaryControllersGroupName) ymt_util.setKeyableAttributesDontLockVisibility( self.over_ctl, params=["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"])
def addOperatorLengthExpression(self): rewrite_map = [ ["scale_ctl", self.length_ctl], ["fk0_npo", self.fk_npo[0]], ["curve_op", self.slv_crv_op], ["scale_cns", self.scale_npo], ["number_of_points", self.divisions], ["curve_length", self.slv_crv.length()] ] additional_code = "" for i, upv in enumerate(self.fk_upvectors): rate = (i + 1.) / len(self.fk_upvectors) additional_code += "\n{}.translateX = {}.translateX * {}".format(upv, self.length_ctl, rate) additional_code += "\n{}.translateY = {}.translateY * {}".format(upv, self.length_ctl, rate) additional_code += "\n{}.translateZ = {}.translateZ".format(upv, self.length_ctl) self.length_ctl.setTranslation(datatypes.Vector(0.0, self.slv_crv.length(), 0), space="preTransform") self.exprespy = create_exprespy_node(self.length_control_expression_archtype, self.getName("exprespy"), rewrite_map, additional_code) ymt_util.setKeyableAttributesDontLockVisibility(self.fk_upvectors, [])
def addContainers(self): t = getTransform(self.root) scl = [1, 1, 1] if self.negate: scl = [-1, 1, 1] t = transform.setMatrixScale(t, scl) self.crv_root = addTransform(self.root, self.getName("crvs"), t) self.rope_root = addTransform(self.root, self.getName("ropes"), t) self.browsHooks_root = addTransform(self.root, self.getName("hooks"), t) self._visi_off_lock(self.crv_root) self._visi_off_lock(self.rope_root) self._visi_off_lock(self.browsHooks_root) if self.connect_surface_slider: bt = getTransform(self.root) self.slider_root = addTransform(self.root, self.getName("sliders"), bt) ymt_util.setKeyableAttributesDontLockVisibility( self.slider_root, []) # self.mainControlParentGrp = addTransform(self.root, self.getName("mainControls"), t) w = (self.outPos - self.inPos).length() d = (self.upPos - self.lowPos).length() self.mainControlParentGrp = addTransform(self.root, self.getName("mainControls"), t) self.mainControl = self.addCtl(self.mainControlParentGrp, "main_ctl", t, self.color_ik, "square", w=w, d=d, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, 1.0)) self.addToSubGroup(self.mainControl, self.primaryControllersGroupName) self.secondaryControlsParentGrp = addTransform( self.root, self.getName("secondaryControls"), t)
def _add_loc_ctl(i, t, parent): loc = primitive.addTransform(parent, self.getName("bk%s_loc" % i), t) self.bk_loc.append(loc) if 0 < i: return loc ctl = self.addCtl(loc, "bk%s_ctl" % i, t, self.color_ik, "sphere", w=self.size * .15, tp=self.previousTag) ymt_util.setKeyableAttributesDontLockVisibility(ctl, self.r_params) self.previousTag = ctl self.bk_ctl.append(ctl) return ctl
def connect_slide_ghost(self, lipup_ref, liplow_ref, slide_c_ref, corner_l_ref, corner_r_ref): self.sliding_surface = pm.duplicate( self.guide.getObjects(self.guide.root)["sliding_surface"])[0] pm.parent(self.sliding_surface, self.root) self.sliding_surface.visibility.set(False) pm.makeIdentity(self.sliding_surface, apply=True, t=1, r=1, s=1, n=0, pn=1) # create interpose lvl for the ctl intTra = rigbits.createInterpolateTransform([lipup_ref, liplow_ref]) pm.rename(intTra, intTra.name() + "_int") # create ghost controls self.mouthSlide_ctl = self._createGhostCtl(slide_c_ref, intTra) self.cornerL_ctl = self._createGhostCtl(corner_l_ref, slide_c_ref) self.cornerR_ctl = self._createGhostCtl(corner_r_ref, slide_c_ref) # slide system ghostSliderForMouth([slide_c_ref, corner_l_ref, corner_r_ref], intTra, self.sliding_surface, self.root) # connect scale pm.connectAttr(self.mouthSlide_ctl.scale, slide_c_ref.scale) pm.connectAttr(self.cornerL_ctl.scale, corner_l_ref.scale) pm.connectAttr(self.cornerR_ctl.scale, corner_r_ref.scale) # connect pucker cmds.setAttr("{}.tz".format(slide_c_ref.name()), l=False) pm.connectAttr(self.mouthSlide_ctl.tz, slide_c_ref.tz) pm.parentConstraint(corner_l_ref, self.lips_L_Corner_npo, mo=True) pm.parentConstraint(corner_r_ref, self.lips_R_Corner_npo, mo=True) ymt_util.setKeyableAttributesDontLockVisibility(slide_c_ref, []) ymt_util.setKeyableAttributesDontLockVisibility(corner_l_ref, []) ymt_util.setKeyableAttributesDontLockVisibility(corner_r_ref, [])
def addObjects(self): """Add all the objects needed to create the component.""" self.detailControllersGroupName = "controllers_detail" # TODO: extract to settings self.primaryControllersGroupName = "controllers_primary" # TODO: extract to settings # jaw control t = transform.getTransformFromPos(self.guide.pos["jaw"]) self.ctl_npo = primitive.addTransform(self.root, self.getName("ctl_npo"), t) self.jaw_ctl = self.addCtl(self.ctl_npo, "jaw_ctl", t, self.color_fk, "circle", w=1 * self.size, ro=datatypes.Vector([1.5708, 0, 0]), tp=self.parentCtlTag) ymt_util.setKeyableAttributesDontLockVisibility( self.jaw_ctl, ["tx", "ty", "tz", "rz"]) # mouth center t = transform.getTransformFromPos(self.guide.pos["rotcenter"]) self.mouthCenter_npo = primitive.addTransform( self.root, self.getName("mouthCenter_npo"), t) self.mouthCenter = primitive.addTransform(self.mouthCenter_npo, self.getName("mouthCenter"), t) # jaw "UPPER" t = transform.getTransformFromPos(self.guide.pos["root"]) self.jawUp_npo = primitive.addTransform(self.mouthCenter, self.getName("jawUpper_npo"), t) self.jawUp_pos = primitive.addTransform(self.jawUp_npo, self.getName("jawUpper_pos"), t) self.jawUp_rot = primitive.addTransform(self.jawUp_pos, self.getName("jawUpper_rot"), t) # jaw "LOWER" t = transform.getTransformFromPos(self.guide.pos["root"]) self.jawLow_npo = primitive.addTransform(self.mouthCenter, self.getName("jaw_npo"), t) self.jawLow_pos = primitive.addTransform(self.jawLow_npo, self.getName("jawLow_pos"), t) self.jawLow_rot = primitive.addTransform(self.jawLow_pos, self.getName("jawLow_rot"), t) # lips t = transform.getTransformFromPos(self.guide.pos["lipup"]) self.lipup_npo = primitive.addTransform(self.jawUp_rot, self.getName("lipup_npo"), t) self.lipup_ctl = self.addCtl(self.lipup_npo, "lipup_ctl", t, self.color_fk, "square", d=.15 * self.size, w=1 * self.size, ro=datatypes.Vector([1.5708, 0, 0]), tp=self.jaw_ctl) t = transform.getTransformFromPos(self.guide.pos["liplow"]) self.liplow_npo = primitive.addTransform(self.jawLow_rot, self.getName("liplow_npo"), t) self.liplow_ctl = self.addCtl(self.liplow_npo, "liplow_ctl", t, self.color_fk, "square", d=.15 * self.size, w=1 * self.size, ro=datatypes.Vector([1.5708, 0, 0]), tp=self.jaw_ctl) # teeth t = transform.getTransformFromPos(self.guide.pos["lipup"]) self.teethup_npo = primitive.addTransform(self.jawUp_rot, self.getName("teethup_npo"), t) self.teethup_ctl = self.addCtl(self.teethup_npo, "teethup_ctl", t, self.color_ik, "square", d=.1 * self.size, w=.7 * self.size, ro=datatypes.Vector([1.5708, 0, 0]), tp=self.lipup_ctl) t = transform.getTransformFromPos(self.guide.pos["liplow"]) self.teethlow_npo = primitive.addTransform( self.jawLow_rot, self.getName("teethlow_npo"), t) self.teethlow_ctl = self.addCtl(self.teethlow_npo, "teethlow_ctl", t, self.color_ik, "square", d=.1 * self.size, w=.7 * self.size, ro=datatypes.Vector([1.5708, 0, 0]), tp=self.liplow_ctl) self.jnt_pos.append( [self.jawLow_rot, "jaw", "parent_relative_jnt", False]) self.jnt_pos.append( [self.lipup_ctl, "lipup", "parent_relative_jnt", False]) # relative 0 is the jaw jnt self.jnt_pos.append([self.liplow_ctl, "liplow", "jaw", False]) self.jnt_pos.append( [self.teethup_ctl, "teethup", "parent_relative_jnt", False]) self.jnt_pos.append([self.teethlow_ctl, "teethlow", "jaw", False]) self.addToSubGroup(self.teethup_ctl, self.primaryControllersGroupName) self.addToSubGroup(self.teethlow_ctl, self.primaryControllersGroupName) self.addToSubGroup(self.lipup_ctl, self.primaryControllersGroupName) self.addToSubGroup(self.liplow_ctl, self.primaryControllersGroupName) self.addToSubGroup(self.jaw_ctl, self.primaryControllersGroupName)
def _addObjectsFkControl(self, i, parentdiv, parentctl, t, parent_twistRef): # References tm = datatypes.TransformationMatrix(t) tm.addRotation([0., 0., math.pi / -2.], 'XYZ', om.MSpace.kObject) # TODO: align with convention tm.addRotation([0., math.pi / -2., 0], 'XYZ', om.MSpace.kObject) global_t = datatypes.Matrix(tm) # global input div_cns = addTransform(parentdiv, self.getName("%s_cns" % i)) div_cns_npo = addTransform(div_cns, self.getName("%s_cns_npo" % i)) pm.setAttr(div_cns + ".inheritsTransform", False) div_cns.setMatrix(global_t, worldSpace=True) self.div_cns.append(div_cns) self.div_cns_npo.append(div_cns_npo) parentdiv = div_cns # t = getTransform(parentctl) if i == 0: p = parentctl else: # p = self.scl_transforms[i - 1] p = self.fk_local_in[i - 1] fk_npo = addTransform(p, self.getName("fk%s_npo" % (i)), global_t) # local input fk_local_npo = addTransform(fk_npo, self.getName("fk%s_local_npo" % i), global_t) fk_local_in = addTransform(fk_local_npo, self.getName("fk%s_local_in" % i), global_t) self.fk_local_in.append(fk_local_in) if i < len(self.guide.apos) - 1: h = (self.guide.apos[i] - self.guide.apos[i + 1]).length() * .8 else: h = (self.guide.apos[-1] - self.guide.apos[0]).length() / (len(self.guide.apos) - 1) # FIXME: rotate by blade po = datatypes.Vector([0, h / 2., 0]) fk_ctl = self.addCtl( fk_local_in, "fk%s_ctl" % (i), global_t, self.color_fk, "cube", w=h * .66, h=h, d=h * 0.3, # ro=datatypes.Vector([0, -math.pi / 2., 0]), po=po, tp=self.preiviousCtlTag, mirrorConf=self.mirror_conf) ymt_util.setKeyableAttributesDontLockVisibility(self.fk_ctl) attribute.setRotOrder(fk_ctl, "ZXY") self.fk_ctl.append(fk_ctl) self.preiviousCtlTag = fk_ctl self.fk_npo.append(fk_npo) self.fk_local_npo.append(fk_local_npo) parentctl = fk_ctl scl_ref = addTransform(parentctl, self.getName("%s_scl_ref" % i), getTransform(parentctl)) self.scl_transforms.append(scl_ref) if i == 0 and self.settings["isSplitHip"]: t = self._getTransformWithRollByBlade(getTransform(self.guide.root)) h = (self.guide.apos[-1] - self.guide.apos[0]).length() / (len(self.guide.apos) - 1) po = datatypes.Vector([0, self.size / len(self.guide.apos) * -.8, 0]) hip_fk_local_in = addTransform(p, self.getName("hip_fk_local_in"), t) self.hip_fk_local_in = hip_fk_local_in self.fk_hip_ctl = self.addCtl( hip_fk_local_in, "fk_hip_ctl", t, self.color_fk, "cube", w=h * .66, h=h, d=h * 0.3, # ro=datatypes.Vector([0, -math.pi / 2., 0]), po=po, tp=self.preiviousCtlTag, mirrorConf=self.mirror_conf) hip_scl_ref = addTransform(self.fk_hip_ctl, self.getName("hip_scl_ref"), t) # Deformers (Shadow) if self.settings["addJoints"]: if self.settings["isSplitHip"]: if i == 0: self.jnt_pos.append([hip_scl_ref, 0]) self.jnt_pos.append([scl_ref, i + 1]) else: self.jnt_pos.append([scl_ref, i]) # Twist references (This objects will replace the spinlookup # slerp solver behavior) t = transform.getTransformLookingAt( self.guide.apos[0], self.guide.apos[-1], self.guide.blades["blade"].z * -1, "yx", self.negate) twister = addTransform( parent_twistRef, self.getName("%s_rot_ref" % i), t) ref_twist = addTransform( parent_twistRef, self.getName("%s_pos_ref" % i), t) ref_twist.setTranslation( datatypes.Vector(1.0, 0, 0), space="preTransform") self.twister.append(twister) self.ref_twist.append(ref_twist) for x in self.fk_ctl: attribute.setInvertMirror(x, ["tx", "rz", "ry"]) attribute.setInvertMirror(self.fk_hip_ctl, ["tx", "rz", "ry"]) return parentdiv, parentctl
def addObjectsChainIk(self, i, crv): cvs = crv.length() if i == 0: u = 0. else: u = crv.findParamFromLength(cvs / (self.settings["ikNb"] - 1) * i) self.ik_uv_param.append(1. / (self.settings["ikNb"] - 1) * i) space = om.MSpace.kWorld pos = crv.getPointAtParam(u, space) if i in [0, (self.settings["ikNb"] - 1)]: t = getTransform(self.guide.root) global_t = self._getTransformWithRollByBlade(t) else: u2 = crv.findParamFromLength(cvs / (self.settings["ikNb"] - 1) * i + 1) pos2 = crv.getPointAtParam(u2, space) t = getTransformLookingAt(pos, pos2, self.guide.blades["blade"].y, axis="yx", negate=self.negate) # FIXME: t = getTransform(self.guide.root) global_t = self._getTransformWithRollByBlade(t) global_t = setMatrixPosition(global_t, pos) local_t = global_t # global input ik_global_npo = addTransform(self.root, self.getName("ik%s_global_npo" % i), global_t) ik_global_in = addTransform(ik_global_npo, self.getName("ik%s_global_in" % i), global_t) self.ik_global_in.append(ik_global_in) # local input ik_local_npo = addTransform(ik_global_in, self.getName("ik%s_local_npo" % i), local_t) ik_local_in = addTransform(ik_local_npo, self.getName("ik%s_local_in" % i), local_t) self.ik_local_in.append(ik_local_in) ik_npo = addTransform(ik_local_in, self.getName("ik%s_npo" % i), local_t) self.ik_npo.append(ik_npo) # output ik_global_out_npo = addTransform(self.root, self.getName("ik%s_global_out_npo" % i), global_t) ik_global_out = addTransform(ik_global_out_npo, self.getName("ik%s_global_out" % i), global_t) self.ik_global_out.append(ik_global_out) # if i == 0 or i == (len(self.guide.apos) - 1): if i == 0 or i == (self.settings["ikNb"] - 1): ctl_form = "compas" col = self.color_ik size = self.size w = size h = size d = size else: ctl_form = "compas" # TODO: set more better col = self.color_ik size = self.size * .85 w = size h = size d = size ik_ctl = self.addCtl( ik_npo, "ik%s_ctl" % i, local_t, col, ctl_form, w=w, h=h, d=d, # ro=datatypes.Vector([0, -math.pi / 2., 0]), tp=self.previusTag, mirrorConf=self.mirror_conf) ymt_util.setKeyableAttributesDontLockVisibility(ik_ctl, self.tr_params) self.ik_ctl.append(ik_ctl) attribute.setInvertMirror(ik_ctl, ["tx", "rz", "ry"]) # ik global ref ik_global_ref = primitive.addTransform( ik_ctl, self.getName("ik%s_global_ref" % i), global_t) self.ik_global_ref.append(ik_global_ref) ymt_util.setKeyableAttributesDontLockVisibility(ik_global_ref, [])
def ghostSliderForMouth(ghostControls, intTra, surface, sliderParent): """Modify the ghost control behaviour to slide on top of a surface Args: ghostControls (dagNode): The ghost control surface (Surface): The NURBS surface sliderParent (dagNode): The parent for the slider. """ if not isinstance(ghostControls, list): ghostControls = [ghostControls] def conn(ctl, driver, ghost): for attr in ["translate", "scale", "rotate"]: try: pm.connectAttr("{}.{}".format(ctl, attr), "{}.{}".format(driver, attr)) pm.disconnectAttr("{}.{}".format(ctl, attr), "{}.{}".format(ghost, attr)) except RuntimeError: pass def connCenter(ctl, driver, ghost): # mul_node1 = pm.createNode("multMatrix") # mul_node2 = pm.createNode("multMatrix") down, _, up = ymt_util.findPathAtoB(ctl, driver) mult = pm.createNode("multMatrix") for i, d in enumerate(down): d.attr("matrix") >> mult.attr("matrixIn[{}]".format(i)) for j, u in enumerate(up[:-1]): u.attr("inverseMatrix") >> mult.attr( "matrixIn[{}]".format(i + j + 1)) decomp = pm.createNode("decomposeMatrix") dm_node = node.createDecomposeMatrixNode(mult.attr("matrixSum")) for attr in ["translate", "scale", "rotate"]: pm.connectAttr("{}.output{}".format(dm_node, attr.capitalize()), "{}.{}".format(driver, attr)) pm.disconnectAttr("{}.{}".format(ctl, attr), "{}.{}".format(ghost, attr)) surfaceShape = surface.getShape() sliders = [] for i, ctlGhost in enumerate(ghostControls): ctl = pm.listConnections(ctlGhost, t="transform")[-1] t = ctl.getMatrix(worldSpace=True) gDriver = primitive.addTransform(surface.getParent(), "{}_slideDriver".format(ctl.name()), t) if 0 == i: connCenter(ctl, gDriver, ctlGhost) else: conn(ctl, gDriver, ctlGhost) oParent = ctlGhost.getParent() npoName = "_".join(ctlGhost.name().split("_")[:-1]) + "_npo" oTra = pm.PyNode( pm.createNode("transform", n=npoName, p=oParent, ss=True)) oTra.setTransformation(ctlGhost.getMatrix()) pm.parent(ctlGhost, oTra) slider = primitive.addTransform(sliderParent, ctl.name() + "_slideDriven", t) sliders.append(slider) # connexion if 0 == i: dm_node = node.createDecomposeMatrixNode(gDriver.attr("matrix")) else: mul_node = pm.createNode("multMatrix") i = 0 parent = ctl while parent != sliderParent: parent.attr("matrix") >> mul_node.attr( "matrixIn[{}]".format(i)) parent = parent.getParent() i += 1 if 10 < i: logger.error("maximum recursion") break dm_node = node.createDecomposeMatrixNode( mul_node.attr("matrixSum")) cps_node = pm.createNode("closestPointOnSurface") dm_node.attr("outputTranslate") >> cps_node.attr("inPosition") surfaceShape.attr("local") >> cps_node.attr("inputSurface") cps_node.attr("position") >> slider.attr("translate") pm.normalConstraint(surfaceShape, slider, aimVector=[0, 0, 1], upVector=[0, 1, 0], worldUpType="objectrotation", worldUpVector=[0, 1, 0], worldUpObject=gDriver) pm.parent(ctlGhost.getParent(), slider) ymt_util.setKeyableAttributesDontLockVisibility(slider, []) for slider in sliders[1:]: _visi_off_lock(slider)
def addCurves(self, crv_root, plane): t = getTransform(self.root) gen = curve.createCurveFromOrderedEdges planeNode = pm.PyNode(plane.fullPathName()) # ------------------------------------------------------------------- edgeList = ["{}.e[{}]".format(plane.fullPathName(), 0)] for i in range(1, self.num_uplocs + 1): edgeList.append("{}.e[{}]".format(plane.fullPathName(), i * 2 + 1)) edgeList = [pm.PyNode(x) for x in edgeList] name = "main_crv" crv = gen(edgeList, planeNode.verts[1], self.getName("{}Crv".format(name)), parent=crv_root, m=t) crv.attr("visibility").set(False) ymt_util.setKeyableAttributesDontLockVisibility(crv, []) mainCtrlPos = helpers.divideSegment(crv, self.midDivisions) secCtrlPos = self.uplocsPos self.mainCurve = crv self.mainCurves.append(crv) # ------------------------------------------------------------------- mainCtrlOptions = [] secCtrlOptions = [] iterator = enumerate(mainCtrlPos) for i, ctlPos in iterator: isLast = (i == (len(mainCtrlPos) - 1)) mainCtrlOptions.extend(self._foreachMainCtrlPos(i, ctlPos, isLast)) if self.secondary_ctl_check: sec_number_index = len(secCtrlPos) - 1 controlType = "circle" iterator = enumerate(secCtrlPos) for i, ctlPos in iterator: secCtrlOptions.append( self._foreachSecCtrlPos(i, ctlPos, sec_number_index)) # mainCtrl = self.addCtl(self.root, ) self.mainControls = [] self.mainUpvs = [] for ctlOptions in mainCtrlOptions: ctl, upv = self._foreachControlOption(self.mainControl, ctlOptions) self.mainControls.append(ctl) self.mainUpvs.append(upv) self.addMainCnsCurve(self.mainControls) self.secondaryControls = [] self.secUpvs = [] for ctlOptions in secCtrlOptions: ctl, upv = self._foreachControlOption( self.secondaryControlsParentGrp, ctlOptions) self.secondaryControls.append(ctl) self.secUpvs.append(upv) self.addSecondaryCnsCurve(self.secondaryControls)
def ghostSliderForEyeBrow(self, ghostControls, surface, sliderParent): """Modify the ghost control behaviour to slide on top of a surface Args: ghostControls (dagNode): The ghost control surface (Surface): The NURBS surface sliderParent (dagNode): The parent for the slider. """ if not isinstance(ghostControls, list): ghostControls = [ghostControls] def conn(ctl, driver, ghost): for attr in ["translate", "scale", "rotate"]: pm.connectAttr("{}.{}".format(ctl, attr), "{}.{}".format(driver, attr)) # pm.disconnectAttr("{}.{}".format(ctl, attr), "{}.{}".format(ghost, attr)) surfaceShape = surface.getShape() sliders = [] for i, ctlGhost in enumerate(ghostControls): ctl = pm.listConnections(ctlGhost, t="transform")[-1] t = ctl.getMatrix(worldSpace=True) scl = [1, 1, 1] if self.negate: scl = [-1, 1, 1] # t = transform.setMatrixScale(t, scl) gDriver = primitive.addTransform( ctlGhost.getParent(), "{}_slideDriver".format(ctl.name()), t) # conn(ctl, gDriver, ctlGhost) # print("ctlGhost.getParent: {}, ctl: {}, gDriver: {}, ctlGhost: {}".format(ctlGhost.getParent(), ctl, gDriver, ctlGhost)) oParent = ctlGhost.getParent() npoName = "_".join(ctlGhost.name().split("_")[:-1]) + "_npo" npo = pm.PyNode( pm.createNode("transform", n=npoName, p=oParent, ss=True)) npo.setTransformation(ctlGhost.getMatrix()) ymt_util.setKeyableAttributesDontLockVisibility(npo, []) pm.parent(ctlGhost, npo) slider = primitive.addTransform(sliderParent, ctl.name() + "_slideDriven", t) sliders.append(slider) down, _, up = findPathAtoB(ctl, sliderParent) mul_node = pm.createNode("multMatrix") j = k = 0 for j, d in enumerate(down): d.attr("matrix") >> mul_node.attr("matrixIn[{}]".format(j)) _.attr("matrix") >> mul_node.attr("matrixIn[{}]".format(j + 1)) for k, u in enumerate(up): u.attr("inverseMatrix") >> mul_node.attr( "matrixIn[{}]".format(k + j + 1)) dm_node = node.createDecomposeMatrixNode( mul_node.attr("matrixSum")) cps_node = pm.createNode("closestPointOnSurface") dm_node.attr("outputTranslate") >> cps_node.attr("inPosition") surfaceShape.attr("local") >> cps_node.attr("inputSurface") cps_node.attr("position") >> slider.attr("translate") if self.negate: aim = [0, 0, -1] else: aim = [0, 0, 1] pm.normalConstraint(surfaceShape, slider, aimVector=aim, upVector=[0, 1, 0], worldUpType="objectrotation", worldUpVector=[0, 1, 0], worldUpObject=gDriver) pm.parent(ctlGhost.getParent(), slider) pm.parent(gDriver.getParent(), self.mainControl)
def _addCurveControllers(self, t, crv, ctlNames, inCtl=None, outCtl=None): cvs = crv.getCVs(space="world") if self.negate: # cvs = [cv for cv in reversed(cvs)] pass ctls = [] for i, cv in enumerate(cvs): if inCtl is not None and i == 0: ctls.append(inCtl) continue if outCtl is not None and (i == len(cvs) - 1): ctls.append(outCtl) continue if utils.is_odd(i): color = 14 wd = .5 offset = self.offset * 1.1 icon_shape = "circle" params = ["tx", "ty", "tz"] else: color = 4 wd = .7 offset = self.offset * 1.3 icon_shape = "square" params = ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"] t = setMatrixPosition(t, cvs[i]) npo = addTransform(self.center_lookat, self.getName("%s_npo" % ctlNames[i]), t) npoBase = npo if i == 2: # we add an extra level to input the tracking ofset values npo = addTransform(npo, self.getName("%s_trk" % ctlNames[i]), t) self.trackLvl.append(npo) ctl = self.addCtl(npo, "%s_%s" % (ctlNames[i], self.ctlName), t, color, icon_shape, w=wd, d=wd, ro=datatypes.Vector(1.57079633, 0, 0), po=offset ) self.addToSubGroup(self.over_ctl, self.primaryControllersGroupName) ymt_util.setKeyableAttributesDontLockVisibility(ctl, params) ctls.append(ctl) # adding parent average contrains to odd controls for i, ctl in enumerate(ctls): if utils.is_odd(i): s = ctls[i - 1] d = ctls[i + 1] pm.parentConstraint(s, d, ctl.getParent(), mo=True) applyop.gear_curvecns_op(crv, ctls) return ctls
def _addControls(self, crv_ctl, option, sidecut): cvs = crv_ctl.getCVs(space="world") pm.progressWindow(title='controls', progress=0, max=len(cvs)) v0 = transform.getTransformFromPos(cvs[0]) v1 = transform.getTransformFromPos(cvs[-1]) distSize = vector.getDistance(v0, v1) * 3 npos = [] ctls = [] upvs = [] params = ["tx", "ty", "tz", "rx", "ry", "rz"] joints = self.upJoints + self.lowJoints iterator = enumerate(cvs) if sidecut: iterator = enumerate(cvs[1:-1]) for i, cv in iterator: pm.progressWindow(e=True, step=1, status='\nCreating control for%s' % cv) t = transform.getTransformFromPos(cv) # Get nearest joint for orientation of controls nearest_joint = None nearest_distance = None for joint in joints: distance = vector.getDistance(transform.getTranslation(joint), cv) if nearest_distance is None or distance < nearest_distance: nearest_distance = distance nearest_joint = joint if nearest_joint: t = transform.setMatrixPosition( transform.getTransform(nearest_joint), cv) temp = addTransform(self.root, self.getName("temp"), t) # temp.rx.set(0) t = transform.getTransform(temp) pm.delete(temp) # print(i, nearest_joint, temp) oName = option[i][0] oSide = option[i][1] o_icon = option[i][2] color = option[i][3] wd = option[i][4] oPar = option[i][5] if oSide == "R": scl = [1, 1, -1] else: scl = [1, 1, 1] t = transform.setMatrixScale(t, scl) npo = addTransform(self.root, self.getName("%s_npo" % oName, oSide), t) npos.append(npo) ctl = self.addCtl( npo, self.getName("{}_{}".format(oName, self.ctlName), oSide), t, color, o_icon, w=wd * distSize, d=wd * distSize, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, .07 * distSize), ) ctls.append(ctl) ymt_util.setKeyableAttributesDontLockVisibility(ctl, params + oPar) upv = addTransform(ctl, self.getName("%s_upv" % oName, oSide), t) upv.attr("tz").set(self.FRONT_OFFSET) upvs.append(upv) self.addToSubGroup(ctl, self.primaryControllersGroupName) pm.progressWindow(e=True, endProgress=True) return npos, ctls, upvs
def addObjects(self): """Add all the objects needed to create the component.""" self.div_count = len(self.guide.apos) - 5 plane = [self.guide.apos[0], self.guide.apos[-4], self.guide.apos[-3]] self.normal = self.getNormalFromPos(plane) self.binormal = self.getBiNormalFromPos(plane) # Heel --------------------------------------------- # bank pivot t = transform.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) t = transform.setMatrixPosition(t, self.guide.pos["inpivot"]) self.in_npo = primitive.addTransform( self.root, self.getName("in_npo"), t) self.in_piv = primitive.addTransform( self.in_npo, self.getName("in_piv"), t) t = transform.setMatrixPosition(t, self.guide.pos["outpivot"]) self.out_piv = primitive.addTransform( self.in_piv, self.getName("out_piv"), t) # heel t = transform.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) self.heel_loc = primitive.addTransform( self.out_piv, self.getName("heel_loc"), t) attribute.setRotOrder(self.heel_loc, "YZX") self.heel_ctl = self.addCtl(self.heel_loc, "heel_ctl", t, self.color_ik, "sphere", w=self.size * .1, tp=self.parentCtlTag) ymt_util.setKeyableAttributesDontLockVisibility(self.heel_ctl, self.r_params) # Tip ---------------------------------------------- v = datatypes.Vector(self.guide.apos[1].x, self.guide.apos[-1].y, self.guide.apos[1].z) t = transform.setMatrixPosition(t, v) self.tip_ctl = self.addCtl(self.heel_ctl, "tip_ctl", t, self.color_ik, "circle", w=self.size, tp=self.heel_ctl) ymt_util.setKeyableAttributesDontLockVisibility(self.tip_ctl, self.r_params) # Roll --------------------------------------------- if self.settings["useRollCtl"]: t = transform.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) t = transform.setMatrixPosition(t, self.guide.pos["root"]) self.roll_np = primitive.addTransform( self.root, self.getName("roll_npo"), t) self.roll_ctl = self.addCtl(self.roll_np, "roll_ctl", t, self.color_ik, "cylinder", w=self.size * .5, h=self.size * .5, ro=datatypes.Vector(3.1415 * .5, 0, 0), tp=self.tip_ctl) ymt_util.setKeyableAttributesDontLockVisibility(self.roll_ctl, ["rx", "rz"]) # Backward Controlers ------------------------------ bk_pos = self.guide.apos[1:-3] bk_pos.reverse() parent = self.tip_ctl self.bk_ctl = [] self.bk_loc = [] self.previousTag = self.tip_ctl def _add_loc_ctl(i, t, parent): loc = primitive.addTransform(parent, self.getName("bk%s_loc" % i), t) self.bk_loc.append(loc) if 0 < i: return loc ctl = self.addCtl(loc, "bk%s_ctl" % i, t, self.color_ik, "sphere", w=self.size * .15, tp=self.previousTag) ymt_util.setKeyableAttributesDontLockVisibility(ctl, self.r_params) self.previousTag = ctl self.bk_ctl.append(ctl) return ctl for i, pos in enumerate(bk_pos): if i == 0: t = transform.getTransform(self.heel_ctl) t = transform.setMatrixPosition(t, bk_pos[0]) else: dir = bk_pos[i - 1] t = transform.getTransformLookingAt( pos, dir, self.normal, "xz", self.negate) parent = _add_loc_ctl(i, t, parent) # FK Reference ------------------------------------ self.fk_ref = primitive.addTransformFromPos(self.bk_loc[-1], self.getName("fk_ref"), self.guide.apos[0]) self.fk_npo = primitive.addTransform( self.fk_ref, self.getName("fk0_npo"), transform.getTransform(self.bk_loc[-1])) # Forward Controlers ------------------------------ self.fk_ctl = [] self.fk_loc = [] parent = self.fk_npo self.previousTag = self.tip_ctl for i, bk_loc in enumerate(reversed(self.bk_loc[2:])): t = transform.getTransform(bk_loc) dist = vector.getDistance(self.guide.apos[i + 1], self.guide.apos[i + 2]) fk_loc = primitive.addTransform( parent, self.getName("fk%s_loc" % i), t) po_vec = datatypes.Vector(dist * .5 * self.n_factor, 0, 0) fk_ctl = self.addCtl(fk_loc, "fk%s_ctl" % i, t, self.color_fk, "cube", w=dist, h=self.size * .5, d=self.size * .5, po=po_vec, tp=self.previousTag) self.previousTag = fk_ctl ymt_util.setKeyableAttributesDontLockVisibility(fk_ctl) self.jnt_pos.append([fk_ctl, i]) parent = fk_ctl self.fk_ctl.append(fk_ctl) self.fk_loc.append(fk_loc)
def _visi_off_lock(self, node): """Short cuts.""" node.visibility.set(False) ymt_util.setKeyableAttributesDontLockVisibility(node, []) cmds.setAttr("{}.visibility".format(node.name()), l=False)