def setChannelBoxAttrs(self, ctrl): rigUtils.hideAttributes(ctrl, trans=False, scale=True, rot=False, vis=True, radius=False)
def build_head(): headJnts = pm.ls('*_head*_jnt') ctrl = rigUtils.createRigControl('circle')[0] pm.rotate(90, 0, 0) pm.makeIdentity(ctrl, a=True, t=True, r=True) pm.rename(ctrl, 'head_ctrl') rigUtils.setControlColor(ctrl) pm.delete(pm.pointConstraint(headJnts[0], ctrl)) orientConst = pm.orientConstraint(headJnts[0], ctrl, mo=False) pm.delete(orientConst) pm.makeIdentity(ctrl, a=True, t=True, r=True) pm.parent(headJnts[0], ctrl) headGrp = pm.group(n='head_grp', em=True) pm.parent(ctrl, headGrp) spineJntList = pm.ls('M_spine*_jnt') pm.parent(headGrp, 'neck_ctrl') rigUtils.hideAttributes(ctrl=ctrl, trans=True, rot=False, scale=True, vis=True, radius=False) pm.delete(ctrl, ch=1)
def _build(self, side): """ main building block for rigging the limb """ # Duplicate and rename new joint chains (IK and FK) self.duplicateLimbChain(jnt=self.startJoint, FK=True) self.duplicateLimbChain(jnt=self.startJoint, IK=True) # FK Build controls for the limb for jnt in [self.startJoint, self.midJoint]: self.placeCtrl(jnt.replace('_jnt', '_FK_ctrl'), type='fk') # Create IK handle and control for switching IK/FK in the correct place self.buildIkCtrlSetup(side=self.side) # # IK/FK Blend Setup for jnt in [self.startJoint, self.midJoint, self.endJoint]: self.createIkFkBlendConnections(jnt) # hide rotations and scale and visibility from the channel box for ctrl in [self.startJoint.replace('_jnt', '_FK_ctrl'), self.midJoint.replace('_jnt', '_FK_ctrl'), self.endJoint.replace('_jnt', '_FK_ctrl')]: rigUtils.hideAttributes(ctrl, trans=True, scale=True, rot=False, vis=True, radius=True) self.organizeLimbGrps(limbPart=self.limbPart)
def buildIkCtrlSetup(self, side): """ Builds IK control for the limb. Create a controller and it places the controller to the right place and create the pole vector and the constrains plus connections :param side: string - 'L' or 'R' """ ikCtrl = self.placeCtrl(self.endJoint, type='ik') if not self.limbPart == 'leg': pm.delete(pm.orientConstraint(self.endJoint, ikCtrl, mo=True)) # create ik handle and pole vector for the IK limb ikh = pm.ikHandle(name=side + '_' + self.limbPart + '_limb_ikh', sj=self.startJoint.replace('_jnt', '_IK_jnt'), ee=self.endJoint.replace('_jnt', '_IK_jnt'), sol='ikRPsolver')[0] rigUtils.setControlColor(ikCtrl) self.placePoleVectorCtrl((self.startJoint, self.midJoint, self.endJoint)) pm.poleVectorConstraint(self.poleVectCtrl, ikh) # End limb control constraint # pm.parentConstraint(ikCtrl, ikh) if self.limbPart == 'arm': pm.parent(self.side + '_arm_limb_ikh', self.side + '_arm_ik_ctrl') else: pm.parent(self.side + '_leg_limb_ikh', self.side + '_leg_ik_ctrl') rigUtils.hideAttributes(ikCtrl, trans=False, scale=True, rot=False, vis=True, radius=False) rigUtils.hideAttributes(self.poleVectCtrl, trans=False, scale=True, rot=True, vis=True, radius=False)
def setupHandBehavior(self): """ Main proc for creating the IK / FK arm switch """ handRootNode = pm.PyNode(self.side + '_hand0_jnt') handRootPos = handRootNode.getTranslation('world') # create locators for the blending FK/IK arm and groups. # to set hand position into the right place orientFKLoc = pm.spaceLocator(name=self.side + '_armFKOrient_loc') orientIKLoc = pm.spaceLocator(name=self.side + '_armIKOrient_loc') orientFKGrp = pm.group(name=self.side + '_armFKOrient_grp', em=True) orientIKGrp = pm.group(name=self.side + '_armIKOrient_grp', em=True) locFKShape = pm.listRelatives(orientFKLoc, s=1)[0] locIKShape = pm.listRelatives(orientIKLoc, s=1)[0] # setup a smaller locator and move it to the wrist joint (handRoot) for loc in [locFKShape, locIKShape]: for scale in ['.localScaleX', '.localScaleY', '.localScaleZ']: pm.setAttr(loc + scale, 0.0005) pm.move(loc, (handRootPos[0], handRootPos[1], handRootPos[2])) # parent each locator to the corresponding group for loc, grp in zip([orientFKLoc, orientIKLoc], [orientFKGrp, orientIKGrp]): pm.parent(loc, grp) # parent each locator group (IK and FK) to the right place pm.parent(orientFKGrp, self.side + '_arm1_jnt') pm.parent(orientIKGrp, self.side + '_arm_ik_ctrl') self.handOrientConst = pm.orientConstraint(orientIKLoc, orientFKLoc, self.side + '_hand_grp') # pointConstraint blend arm joint and handGrp pm.pointConstraint(self.side + '_arm2_jnt', self.side + '_hand_grp') # connect orientConstraint weights to handCtrl to be able to switch the weights from the FK/IK attribute pm.connectAttr(self.side + '_hand_ctrl.FK_IK', self.handOrientConst + '.' + self.side + '_armFKOrient_locW1') handReverseNode = pm.createNode('reverse', name=self.side + '_handRev') pm.connectAttr(self.side + '_hand_ctrl.FK_IK', handReverseNode + '.input.inputX') pm.connectAttr(handReverseNode + '.output.outputX', self.handOrientConst + '.' + self.side + '_armIKOrient_locW0') # orient constraint hand module with the bind joints #pm.orientConstraint(self.side + '_hand_IK_jnt', self.side + '_hand0_jnt', mo=True) pm.parent(self.side + '_arm_limb_ikh',self.side + '_arm_ik_ctrl') pm.parent(self.side + '_hand_grp', 'main_ctrl') rigUtils.hideAttributes(ctrl=self.side + '_hand_ctrl', trans=True, scale=False, rot=False, vis=True, radius=False)
def _build(self): spineJntChainList = pm.ls('M_spine*_jnt') for i in range(len(spineJntChainList) - 1): print(spineJntChainList[i]) if i != 0: self.createFKControl(spineJntChainList[i]) rigUtils.hideAttributes(spineJntChainList[i], trans=True, scale=True, rot=False, vis=True, radius=True) self.createCOGCtrl() rigUtils.hideAttributes('COG_ctrl', trans=False, scale=True, rot=False, vis=True, radius=False) self.organizeSpine()
def _buid(self): self.createFootJointChain(self.footJnt) footCtrl = self.createFootCtrl() rigUtils.hideAttributes(footCtrl, trans=True, scale=True, rot=False, vis=True, radius=False) self.addChannelBoxFootAttrs(footCtrl) self.createFootGroupSetup() self.createFootConnections(footCtrl) self.setFootGroupPivot() self.connectFKIKBlendAttrs() self.setupFootBehavior() self.setupVisibility()
def spaceSwitchHeadSetup(self): mainFollowLoc = pm.spaceLocator(name='M_headFollowMain_loc') headFollowLoc = pm.spaceLocator(name='M_headFollowHead_loc') # reduce local scale for loc in [mainFollowLoc, headFollowLoc]: pm.setAttr(loc + 'Shape.localScaleX', 0.015) pm.setAttr(loc + 'Shape.localScaleY', 0.015) pm.setAttr(loc + 'Shape.localScaleZ', 0.015) mainFollowGrp = pm.group(name='M_headFollowMain_grp', em=True) headFollowGrp = pm.group(name='M_headFollowHead_grp', em=True) pm.parent(mainFollowLoc, mainFollowGrp) pm.parent(mainFollowGrp, 'main_ctrl') pm.parent(headFollowLoc, headFollowGrp) # pm.parent(headFollowGrp, 'M_head_ctrl') pm.move( mainFollowGrp, (self.headRootPos[0], self.headRootPos[1], self.headRootPos[2])) pm.move( headFollowGrp, (self.headRootPos[0], self.headRootPos[1], self.headRootPos[2])) neckCtrlNum = (len(pm.ls('M_spine*_jnt')) - 1) pm.select('M_spine%s_jnt' % neckCtrlNum) neckCtrl = pm.ls(sl=True)[0] neckCtrl = pm.PyNode(neckCtrl) neckPos = neckCtrl.getTranslation('world') headFollowHeadGrp = pm.group(n='M_followHead_grp') pm.parent(headFollowGrp, headFollowHeadGrp) pm.xform(headFollowGrp, piv=neckPos, ws=True) followOrientConst = pm.orientConstraint('M_headFollowMain_loc', 'M_headFollowHead_loc', headFollowHeadGrp, mo=True) print('NeckCtrl: %s' % neckCtrl) pm.parent('M_head_ctrl', neckCtrl) rigUtils.hideAttributes(ctrl='M_head_ctrl', trans=True, scale=True, rot=False, vis=True, radius=False) # add channel box attributes to switch space pm.addAttr('M_head_ctrl', ln="follow", at="enum", en="main:head:") pm.setAttr('M_head_ctrl.follow', e=True, keyable=True) # create connections from the follow attrs to the orientConstraint headFollowInvNode = pm.createNode('reverse', name='headFollow_inv') pm.connectAttr( 'M_head_ctrl.follow', 'M_followHead_grp_orientConstraint1.M_headFollowHead_locW1', f=True) pm.connectAttr('M_head_ctrl.follow', headFollowInvNode + '.inputX', f=True) pm.connectAttr( headFollowInvNode + '.outputX', 'M_followHead_grp_orientConstraint1.M_headFollowMain_locW0', f=True)