def organize(): """ Create group structure to hold the helpers rig """ rigHelpersGrp = pm.group(name='rigHelpers_grp', em=True) for side in ['L', 'R']: pm.parent(side + '_leg_0_rigHelper', rigHelpersGrp) pm.parent(side + '_arm0_rigHelper', rigHelpersGrp) pm.parent('M_spine0_rigHelper', rigHelpersGrp) crvsGrp = pm.group(n='crvs_grp', em=True) for side in ['L','R']: pm.parent(side + '_leg_helper_grp', crvsGrp) pm.parent(side + '_arm_helper_grp', crvsGrp) pm.parent('M_spine_helper_grp', crvsGrp) scaleCtrl = pm.circle(n='scale_ctrl', r=1, nr=(0,1,0)) rigUtils.setControlColor(scaleCtrl[0]) pm.parent(rigHelpersGrp, scaleCtrl[0]) helpersGrp = pm.group(n='helpers_grp', em=True) pm.parent(crvsGrp, helpersGrp) pm.parent(scaleCtrl[0], helpersGrp)
def createRigStructure(): pm.promptDialog (m='Enter character name:', title='Autorig') characterName = pm.promptDialog(query=True, text=True) # create group structre for the rig mainGrp = pm.group(name=characterName, em=True) pm.group(name='mesh_grp', em=True, p=mainGrp) rigGrp = pm.group(name='rig_grp', em=True, p=mainGrp) # create main ctrl for the rig mainCtrlGrp = rigUtils.createRigControl('cross') mainCtrlGrp = pm.rename(mainCtrlGrp, 'main_ctrl') rigUtils.setControlColor(mainCtrlGrp) """ pm.group(name='m_head_grp', em=True, p=mainCtrlGrp) pm.group(name='m_spine_grp', em=True, p=mainCtrlGrp) pm.group(name='l_leg_grp', em=True, p=mainCtrlGrp) pm.group(name='l_leg_grp', em=True, p=mainCtrlGrp) pm.group(name='l_arm_grp', em=True, p=mainCtrlGrp) pm.group(name='r_arm_grp', em=True, p=mainCtrlGrp) pm.group(name='l_foot_grp', em=True, p=mainCtrlGrp) pm.group(name='r_foot_grp', em=True, p=mainCtrlGrp) """ pm.parent(mainCtrlGrp, rigGrp)
def createHandControl(self): """ Create hand control and sets the color based on the name :return - string - name of the created control """ crv = mel.eval('curve -d 3 -p 0 0 0 -p 0.4 0 0.111111 -p 1.2 0 0.333333 -p 1.2 0 -1.333333 -p 0.4 0 -1.111111 ' '-p 0 0 -1 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 3 -k 3 ;') pm.setAttr(crv + '.tz', 0.5) pm.makeIdentity(a=True, t=True) pm.xform(crv, piv=(0.0, 0.0, 0.0)) pm.scale(0.4, 0.4, 0.4) pm.makeIdentity(a=True, s=True) crv = pm.rename(crv, self.side + '_hand_ctrl') rigUtils.setControlColor(crv) #self.setControlColor(crv) # mirror the controller for the Right side if self.side == 'R': pm.scale(crv, (-1, 1, 1)) pm.makeIdentity(a=True, s=True) return crv
def createFKControl(self, jnt): """ Create controls for the spine replacing the shape in the joints for a nurbs curve (control) :param jnt: string - first joint for the spine chain """ ctrlCrv = pm.circle(name=jnt.replace('_jnt', '_ctrl'), nr=(0, 1, 0), r=2.0)[0] rigUtils.setControlColor(ctrlCrv) pm.scale(0.12, 0.12, 0.12) pm.makeIdentity(a=True, s=True) pm.parent(ctrlCrv, jnt) # resets the transforms for the controller for trans in ['.tx', '.ty', '.tz', '.rx', '.ry', '.rz']: pm.setAttr(ctrlCrv + trans, 0) # unparent the control and parent the shape from the control to the joint, so we are adding a shape node to # the joint interact with the animator pm.parent(world=True) ctrlCrvShape = pm.listRelatives(ctrlCrv) pm.select(ctrlCrvShape) pm.select(jnt, add=True) pm.parent(r=True, s=True) pm.delete(ctrlCrv) pm.delete(ch=True) return ctrlCrv
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 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 createNeckCtrl(self): headCtrl = rigUtils.createRigControl('circle') headCtrl = pm.rename(headCtrl[0], 'M_head_ctrl') rigUtils.setControlColor(headCtrl) pm.move( headCtrl, (self.headRootPos[0], self.headRootPos[1], self.headRootPos[2])) pm.rotate(headCtrl, (0, 0, 90)) pm.scale(headCtrl, (1.5, 1.5, 1.5)) pm.makeIdentity(a=True, r=True, t=True, s=True)
def createCOGCtrl(self): """ create and place COG control in the COG joint """ cogCtrl = rigUtils.createRigControl('COG') pm.delete(pm.pointConstraint(self.starJoint, cogCtrl)) pm.makeIdentity(cogCtrl, a=True, t=True) rigUtils.setControlColor(cogCtrl) cogCtrl = pm.rename(cogCtrl, 'COG_ctrl') pm.parent(self.starJoint, cogCtrl)
def placeCtrl(self, jnt=None, type=None): """ snaps the control to the given joint with the same orientation :return string - ctrl name """ # create different control based on the type IK/FK if type == 'fk': ctrlCrv = rigUtils.createRigControl('sphere') ctrlCrv = pm.rename(ctrlCrv, self.side + '_' + self.limbPart + '_' + ctrlCrv) rigUtils.setControlColor(ctrlCrv) pm.delete(pm.orientConstraint(jnt, ctrlCrv)) pm.scale(0.12, 0.12, 0.12) pm.makeIdentity(a=True, s=True) pm.parent(ctrlCrv, jnt) # resets the transforms for the controller for trans in ['.tx', '.ty', '.tz', '.rx', '.ry', '.rz']: pm.setAttr(ctrlCrv + trans, 0) # unparent the control and parent the shape from the control to the joint, so we are adding a shape node to # the joint interact with the animator pm.parent(world=True) ctrlCrvShape = pm.listRelatives(ctrlCrv) pm.select(ctrlCrvShape) pm.select(jnt, add=True) pm.parent(r=True, s=True) pm.delete(ctrlCrv) elif type == 'ik': ctrlCrv = rigUtils.createRigControl('cross') pm.delete(pm.orientConstraint(jnt, ctrlCrv)) pm.scale(ctrlCrv, (0.08, 0.08, 0.08)) pm.makeIdentity(s=True, t=True, r=True, a=True) ctrlCrv = pm.rename(ctrlCrv, self.side + '_' + self.limbPart + '_ik_ctrl') pm.delete(pm.pointConstraint(self.endJoint, ctrlCrv)) pm.makeIdentity(a=True, t=True) if self.limbPart == 'arm': pm.rotate(ctrlCrv, (0,0,90)) pm.makeIdentity(a=True, r=True) return ctrlCrv
def placePoleVectorCtrl(self, jntList): """ place pole vector controller in the middle joint and offsets the position :param jntList: string list- list of 3 limb joints """ armlimbLenght = self.getLimbLength(self.side + '_arm1_rigHelper', self.side + '_arm3_rigHelper') leglimbLenght = self.getLimbLength(self.side + '_leg_0_rigHelper', self.side + '_leg_2_rigHelper') start = pm.xform(jntList[0], q=1, ws=1, t=1) mid = pm.xform(jntList[1], q=1, ws=1, t=1) end = pm.xform(jntList[2], q=1, ws=1, t=1) startV = OpenMaya.MVector(start[0], start[1], start[2]) midV = OpenMaya.MVector(mid[0], mid[1], mid[2]) endV = OpenMaya.MVector(end[0], end[1], end[2]) startEnd = endV - startV startMid = midV - startV dotP = startMid * startEnd proj = float(dotP) / float(startEnd.length()) startEndN = startEnd.normal() projV = startEndN * proj arrowV = startMid - projV arrowV *= 8.0 finalV = arrowV + midV # create poleVector controller self.poleVectCtrl = rigUtils.createRigControl('poleVector') self.poleVectCtrl = pm.rename(self.poleVectCtrl, self.side + '_' + self.limbPart + '_' + self.poleVectCtrl) pm.select(self.poleVectCtrl) pm.xform(ws=1, t=(finalV.x, finalV.y, finalV.z)) pm.makeIdentity(self.poleVectCtrl, a=True, t=True) rigUtils.setControlColor(self.poleVectCtrl)
def createFootCtrl(self): """ Create foot nurbs curve and place in the feel of the character. The control will have the size from the heel helper to the end foot helper """ footCtrl = rigUtils.createRigControl('foot') pm.rename(footCtrl, self.side + footCtrl) footCtrl = self.side + footCtrl # mirror ctrl if we are doing the right side if self.side == 'R': pm.scale(footCtrl, (-1, 1, 1)) pm.makeIdentity(footCtrl, a=True, s=True) # place the foot ctrl in the 3rd rig helper (heel) pm.delete(pm.pointConstraint(self.side + '_leg_3_rigHelper', footCtrl)) pm.makeIdentity(footCtrl, a=True, t=True) endFootHelper = pm.PyNode(self.side + '_leg_5_rigHelper') endFootCtrl = pm.PyNode(self.side + '_foot_ctrl') # gets the heel helper world position and the bounding box of the foot controller endFootHelperPos = endFootHelper.getTranslation('world') bbox = pm.exactWorldBoundingBox(footCtrl) # gets the correct scale to feet the helpers scaleFactor = (endFootHelperPos[2] - bbox[5]) + 1 pm.scale(footCtrl, scaleFactor, scaleFactor, scaleFactor) pm.makeIdentity(footCtrl, a=True, s=True) # parent the control to the new created foot chain rigUtils.setControlColor(footCtrl) pm.parent(self.footJnt, self.side + '_foot_ctrl') return footCtrl