def hand(self, side='', axis='rz', ctrlSize=1.0): abc = list(string.ascii_lowercase) name = side + '_fingers' if side == '': name = 'fingers' module = rig_module(name) self.fingersModule = module ctrlSizeHalf = [ctrlSize / 2.0, ctrlSize / 2.0, ctrlSize / 2.0] ctrlSize = [ctrlSize, ctrlSize, ctrlSize] rotateAxis = ['rx', 'ry', 'rz'] rotateAxis.remove(axis) skipAxis = rotateAxis + ['tx', 'ty', 'tz'] for finger in (self.fngThumb, self.fngIndex, self.fngMid, self.fngRing, self.fngPinky): fng = finger if side != '': fng = side + '_' + fng print 'finger is ' + fng if pm.objExists(fng): chainFingers = rig_chain(fng) childrenFngs = chainFingers.chainChildren childrenFngs.pop(len(childrenFngs) - 1) simpleControls(fng, modify=2, scale=ctrlSize, parentOffset=module.controls, lockHideAttrs=['tx', 'ty', 'tz']) simpleControls(childrenFngs, modify=2, scale=ctrlSize, parentOffset=module.controls, lockHideAttrs=skipAxis) else: print fng + ' does not exist...Skipping.' return
def shoulder(self, side='', ctrlSize=1): name = side + '_shoulder' if side == '': name = 'shoulder' module = self.armModule if self.armModule == '': module = rig_module(name) self.shoulderModule = module shoulder = self.clavicleName if side != '': shoulder = side + '_' + shoulder pm.parent(shoulder, module.skeleton) print 'shoulder ' + shoulder ctrlSizeHalf = [ctrlSize / 2.0, ctrlSize / 2.0, ctrlSize / 2.0] ctrlSize = [ctrlSize, ctrlSize, ctrlSize] self.shoulderControl = rig_control(side=side, name='shoulder', shape='pyramid', targetOffset=shoulder, modify=1, parentOffset=module.controls, lockHideAttrs=['tx', 'ty', 'tz'], constrain=shoulder, scale=ctrlSize, rotateOrder=0) if pm.objExists(self.spineConnection): pm.parentConstraint(self.spineConnection, self.shoulderControl.offset, mo=True) if pm.objExists('rigModules_GRP'): pm.parent(module.top, 'rigModules_GRP') return module
def gizmoRigModules(): print 'Create gizmo rig modules' biped = rig_biped() biped.elbowAxis = 'ry' biped.spine(ctrlSize=6) biped.pelvis(ctrlSize=5) biped.neck(ctrlSize=2.5) biped.head(ctrlSize=5) for side in ['l', 'r']: armModule = biped.arm(side, ctrlSize=3) fingersModule = biped.hand(side, ctrlSize=0.5) shoulderModule = biped.shoulder(side, ctrlSize=2) biped.connectArmShoulder(side) legModule = biped.leg(side, ctrlSize=3) toesModule = biped.foot(side, ctrlSize=0.5) biped.connectLegPelvis() # make tail ''' tailModule = rig_ikChainSpline('tail', 'tailJA_JNT', ctrlSize=1, parent='pelvisJA_JNT', numIkControls=4, numFkControls=4) chainList = rig_chain('tailJOTip_JNT').chain print '====== MAKING TAIL TIP ==============' fkCtrls = fkControlChain(chainList, modify=1, scale=[1, 1, 1], directCon=1) for fk in fkCtrls: pm.parent(fk.offset, tailModule.controls) ''' tailModule = rig_ikChainSpline('tail', 'tailHiJA_JNT', ctrlSize=1, parent='pelvisJA_JNT', numIkControls=12, numFkControls=12) # tail upgrade tailJnts = pm.listRelatives('tailskeleton_GRP', type='joint') for i in range(1, len(tailJnts)): tailNme = tailJnts[i].stripNamespace() tailIK = tailJnts[i] tailFK = tailNme.replace('IK', 'FK') tailFK = tailFK.replace('_JNT', '') constrainObject(tailFK + 'Modify2_GRP', [tailIK, tailFK + 'Modify1_GRP'], tailFK + '_CTRL', ['IK', 'parent'], type='parentConstraint') pm.parentConstraint('tailFKACon_GRP', 'tailBaseIKOffset_GRP', mo=True) constrainObject('tailMidAIKOffset_GRP', ['tailFKACon_GRP', 'pelvisCon_GRP', 'worldSpace_GRP'], 'tailMidAIK_CTRL', ['base', 'pelvis', 'world'], type='parentConstraint') constrainObject('tailMidBIKOffset_GRP', [ 'tailFKACon_GRP', 'tailMidAIKCon_GRP', 'pelvisCon_GRP', 'worldSpace_GRP' ], 'tailMidBIK_CTRL', ['base', 'FK', 'pelvis', 'world'], type='parentConstraint') constrainObject('tailTipIKOffset_GRP', [ 'tailFKACon_GRP', 'tailMidBIKCon_GRP', 'pelvisCon_GRP', 'worldSpace_GRP' ], 'tailTipIK_CTRL', ['base', 'FK', 'pelvis', 'world'], type='parentConstraint') tailPointer = rig_control(name='tailPointer', shape='pyramid', scale=(1, 2, 1), lockHideAttrs=['rx', 'ry', 'rz'], colour='white', parentOffset=tailModule.controls, rotateOrder=2) pm.delete(pm.parentConstraint('tailHiJEnd_JNT', tailPointer.offset)) constrainObject( tailPointer.offset, ['pelvisCon_GRP', 'spineFullBodyCon_GRP', 'worldSpace_GRP'], tailPointer.ctrl, ['pelvis', 'fullBody', 'world'], type='parentConstraint') tailPointerBase = rig_transform(0, name='tailPointerBase', type='locator', parent=tailModule.parts, target='tailFKA_CTRL').object tailPointerTip = rig_transform(0, name='tailPointerTip', type='locator', parent=tailModule.parts, target=tailPointer.con).object pm.rotate(tailPointerBase, 0, 0, -90, r=True, os=True) pm.rotate(tailPointerTip, 0, 0, -90, r=True, os=True) pm.parentConstraint('pelvisCon_GRP', tailPointerBase, mo=True) pm.parentConstraint(tailPointer.con, tailPointerTip, mo=True) tailPointerTop = mm.eval('rig_makePiston("' + tailPointerBase + '", "' + tailPointerTip + '", "tailPointerAim");') pm.orientConstraint(tailPointerBase.replace('LOC', 'JNT'), 'tailFKAModify2_GRP', mo=True) pm.parent('tailMidAIKOffset_GRP', 'tailMidBIKOffset_GRP', 'tailTipIKOffset_GRP', tailModule.controls) pm.parent(tailJnts, tailModule.skeleton) pm.parent('tail_cMUS', 'tailBaseIKOffset_GRP', tailPointerTop, tailModule.parts) pm.setAttr(tailModule.skeleton + '.inheritsTransform', 0) # build facial facialModule = rig_module('facial') pm.parent(facialModule.top, 'rigModules_GRP') # build shape locators for side in ['l', 'r']: muzzleCtrl = fourWayShapeControl( side + '_muzzleShape_LOC', (side + 'MuzzleUp', side + 'MuzzleDown', side + 'MuzzleForward', side + 'MuzzleBack'), 'headShapeWorld_GRP', ctrlSize=1) pm.rotate(muzzleCtrl.ctrl.cv, 0, 0, 90, r=True, os=True) pm.rotate(muzzleCtrl.ctrl.cv, -45, 0, 0, r=True, os=True) browCtrl = twoWayShapeControl(side + '_browShape_LOC', (side + 'BrowUp', side + 'BrowDown'), 'headShapeWorld_GRP', ctrlSize=0.8) pm.rotate(browCtrl.ctrl.cv, 90, 0, 0, r=True, os=True) pm.rotate(browCtrl.ctrl.cv, 0, -75, 0, r=True, os=True) blinkCtrl = oneWayShapeControl(side + '_blinkShape_LOC', side + 'Blink', 'headShapeWorld_GRP', ctrlSize=0.5) if side == 'r': pm.rotate(blinkCtrl.ctrl.cv, 0, 0, 180, r=True, os=True) #pm.move(blinkCtrl.ctrl.cv, 0, -0.4, 0, relative=True) #pm.parent( muzzleCtrl.offset, browCtrl.offset , blinkCtrl.offset ,facialModule.controls) pm.parent('headShapeWorld_GRP', facialModule.controls) pm.parentConstraint('headJA_JNT', 'headShapeWorld_GRP') # build simple controllers facialLocalWorldControllers(facialModule, 'headJAWorld_GRP', ctrlSize=0.1) pm.parentConstraint('headJA_JNT', 'headJAWorld_GRP') pm.parent('headJAWorld_GRP', facialModule.controlsSec) pm.move(pm.PyNode('noseTwk_CTRL').cv, 0.15, 0, 0, r=True, os=True) pm.scale(pm.PyNode('noseTwk_CTRL').cv, 2.5, 2.5, 2.5) # jaw control jawControl = rig_control(name='jaw', shape='circle', scale=(2, 2, 2), lockHideAttrs=['rx'], parentOffset=facialModule.controls, colour='white') pm.rotate(jawControl.ctrl.cv, -90, 0, 0, r=True, os=True) pm.move(jawControl.ctrl.cv, 2, 0, 0, r=True, os=True) pm.delete(pm.parentConstraint('jawJA_JNT', jawControl.offset)) pm.parentConstraint('headJA_JNT', jawControl.offset, mo=True) pm.parent('jawHeadOffset_LOC', jawControl.offset) pm.pointConstraint(jawControl.con, 'jawHeadOffset_LOC', mo=True) facialLoc = 'facialShapeDriver_LOC' rig_animDrivenKey(jawControl.ctrl.rotateY, (0, 35), facialLoc + '.jawOpen', (0, 1)) rig_animDrivenKey(jawControl.ctrl.rotateY, (0, -5), facialLoc + '.jawClosed', (0, 1)) rig_animDrivenKey(jawControl.ctrl.rotateZ, (0, -10), facialLoc + '.rJawSide', (0, 1)) rig_animDrivenKey(jawControl.ctrl.rotateZ, (0, 10), facialLoc + '.lJawSide', (0, 1)) pm.transformLimits(jawControl.ctrl, ry=(-5, 35), ery=(1, 1)) pm.transformLimits(jawControl.ctrl, rz=(-10, 10), erz=(1, 1)) pm.transformLimits(jawControl.ctrl, tx=(-0.1, 0.1), etx=(1, 1)) pm.transformLimits(jawControl.ctrl, ty=(-0.1, 0.1), ety=(1, 1)) pm.transformLimits(jawControl.ctrl, tz=(0, 0.1), etz=(1, 1)) upperLipCtrls = pm.ls("*upperLip*Twk*CTRL") for c in upperLipCtrls: pm.scale(c.cv, 0.6, 0.6, 0.6, r=True) pm.move(c.cv, 0, 0, 0.3, r=True) pm.move(c.cv, 0, 0.1, 0, r=True) lowerLipCtrls = pm.ls("*lowerLip*Twk*CTRL") for c in lowerLipCtrls: pm.scale(c.cv, 0.6, 0.6, 0.6, r=True) pm.move(c.cv, 0, 0, 0.3, r=True) pm.move(c.cv, 0, -0.1, 0, r=True) pm.setAttr(facialModule.parts + '.inheritsTransform', 0) pm.parent('tongueControls_GRP', facialModule.controls) # eye controls eyeModule = rig_module('eye') pm.parent(eyeModule.top, 'rigModules_GRP') eyeControl = rig_control(name='eye', shape='circle', modify=1, parentOffset=eyeModule.controls, scale=(1, 1, 1), rotateOrder=2, lockHideAttrs=['rx', 'ry', 'rz']) pm.delete(pm.parentConstraint('eyeAim_LOC', eyeControl.offset)) #pm.parentConstraint( 'headCon_GRP', eyeControl.offset, mo=True ) pm.rotate(eyeControl.ctrl.cv, 90, 0, 0, r=True, os=True) pm.select(eyeControl.ctrl.cv[1], r=True) pm.select(eyeControl.ctrl.cv[5], add=True) pm.scale(0, 0, 0, r=True) constrainObject(eyeControl.offset, ['headCon_GRP', 'worldSpace_GRP'], eyeControl.ctrl, ['head', 'world'], type='parentConstraint') pm.parent('eyeAim_LOC', eyeControl.con) pm.hide('eyeAim_LOC') for side in ('l', 'r'): eyeBase = rig_transform(0, name=side + '_eyeBase', type='locator', target=side + '_eyeJA_JNT', parent=eyeModule.parts).object eyeTarget = rig_transform(0, name=side + '_eyeTarget', type='locator', target='eyeAim_LOC', parent=eyeModule.parts).object pm.parentConstraint('headJA_JNT', eyeBase, mo=True) pm.parentConstraint('eyeAim_LOC', eyeTarget, mo=True) eyeAimTop = mm.eval('rig_makePiston("' + eyeBase + '", "' + eyeTarget + '", ' '"' + side + '_eyeAim");') pm.orientConstraint(side + '_eyeBase_JNT', side + '_eyeJA_JNT', mo=True) pm.parent(eyeAimTop, eyeModule.parts) upperEyeControl = rig_control( side=side, name='eyeUpper', shape='circle', modify=1, parentOffset=eyeModule.controlsSec, scale=(0.1, 0.1, 0.1), constrain=side + '_upperEyeLidRotateOffset_GRP', rotateOrder=2, directCon=1, lockHideAttrs=['tx', 'ty', 'tz', 'rx', 'ry']) pm.delete( pm.parentConstraint(side + '_eyeLocalOffset_GRP', upperEyeControl.offset)) pm.delete( pm.pointConstraint(side + '_eyeJA_JNT', upperEyeControl.offset)) lowerEyeControl = rig_control( side=side, name='eyeLower', shape='circle', modify=1, parentOffset=eyeModule.controlsSec, scale=(0.1, 0.1, 0.1), constrain=side + '_lowerEyeLidRotateOffset_GRP', rotateOrder=2, directCon=1, lockHideAttrs=['tx', 'ty', 'tz', 'rx', 'ry']) pm.delete( pm.parentConstraint(side + '_eyeLocalOffset_GRP', lowerEyeControl.offset)) pm.delete( pm.pointConstraint(side + '_eyeJA_JNT', lowerEyeControl.offset)) ''' eyeControl = rig_control(side=side, name='eye', shape='circle', modify=1, parentOffset=eyeModule.controls, scale=(1,1,1), rotateOrder=2, lockHideAttrs=['rx', 'ry', 'rz']) ''' # ear controls chainEars = rig_chain(side + '_earJA_JNT').chain earCtrls = fkControlChain( [side + '_earJA_JNT', side + '_earJB_JNT', side + '_earJC_JNT'], modify=0, scale=[0.8, 0.8, 0.8], directCon=0) # parent ears to headJA_JNT for ctrl in earCtrls: pm.parent(ctrl.parent, 'headControlsSecondary_GRP')
def kiddoRigModules(): print 'Create kiddo rig modules' bodyModule = rig_module('body') pm.parent('mainJA_JNT', bodyModule.skeleton) main = rig_control(name='main', shape='box', targetOffset='mainJA_JNT', constrain='mainJA_JNT', parentOffset=bodyModule.controls, scale=(45, 10, 50), colour='white') main.gimbal = createCtrlGimbal(main) main.pivot = createCtrlPivot(main, overrideScale=(10, 10, 10)) upperBody = rig_control(name='upperBody', shape='box', modify=1, targetOffset='mainJA_JNT', constrainOffset=main.con, scale=(35, 15, 40), colour='yellow', parentOffset=bodyModule.controls, lockHideAttrs=['tx', 'ty', 'tz'], rotateOrder=2) pm.move(upperBody.ctrl.cv, [0, 10, 0], relative=True, objectSpace=True) upperWaistXYZ = simpleControls( ['upperWaistY_JA_JNT', 'upperWaistZ_JA_JNT', 'upperWaistX_JA_JNT'], modify=1, scale=(45, 10, 50), parentOffset=bodyModule.parts, lockHideAttrs=['tx', 'ty', 'tz']) upperWaistY = upperWaistXYZ['upperWaistY_JA_JNT'] upperWaistZ = upperWaistXYZ['upperWaistZ_JA_JNT'] upperWaistX = upperWaistXYZ['upperWaistX_JA_JNT'] pm.hide(upperWaistY.offset, upperWaistZ.offset, upperWaistX.offset) constrainObject(upperBody.modify, [upperBody.offset, 'worldSpace_GRP'], upperBody.ctrl, ['main', 'world'], type='orientConstraint') constrainObject(upperWaistY.modify, [upperWaistY.offset, 'worldSpace_GRP'], upperBody.ctrl, ['main', 'world'], type='orientConstraint', skip=('x', 'z')) constrainObject(upperWaistZ.modify, [upperWaistZ.offset, 'worldSpace_GRP'], upperBody.ctrl, ['main', 'world'], type='orientConstraint', skip=('x', 'y')) constrainObject(upperWaistX.modify, [upperWaistX.offset, 'worldSpace_GRP'], upperBody.ctrl, ['main', 'world'], type='orientConstraint', skip=('z', 'y')) pm.connectAttr(upperBody.ctrl.rotateX, upperWaistX.ctrl.rotateX) pm.connectAttr(upperBody.ctrl.rotateY, upperWaistY.ctrl.rotateY) pm.connectAttr(upperBody.ctrl.rotateZ, upperWaistZ.ctrl.rotateZ) lowerBody = rig_control(name='lowerBody', shape='box', modify=1, targetOffset='lowerBodyJA_JNT', constrainOffset=main.con, scale=(40, 20, 30), colour='green', parentOffset=bodyModule.controls, lockHideAttrs=['tx', 'ty', 'tz', 'rx', 'rz'], rotateOrder=2) constrainObject(lowerBody.modify, [lowerBody.offset, 'worldSpace_GRP'], lowerBody.ctrl, ['main', 'world'], type='orientConstraint', skip=('x', 'z')) pm.parentConstraint(lowerBody.con, 'lowerBodyJA_JNT', mo=True) pm.move(lowerBody.ctrl.cv, [0, -10, 0], relative=True, objectSpace=True) biped = rig_biped() biped.spineConnection = 'upperWaistX_JA_JNT' biped.pelvisConnection = 'lowerBodyJA_JNT' biped.centerConnection = 'mainJA_JNT' for side in ['l', 'r']: armModule = biped.arm(side, ctrlSize=10) fingersModule = biped.hand(side, ctrlSize=2.5) shoulderModule = biped.shoulder(side, ctrlSize=12) biped.connectArmShoulder(side) secColour = 'deepskyblue' if side == 'r': secColour = 'magenta' # make leg legName = side + '_leg' legModule = rig_module(legName) hipZJnt = side + '_hipZ_JA_JNT' hipYJnt = side + '_hipY_JA_JNT' legJnt = side + '_legJA_JNT' kneeJnt = side + '_kneeJA_JNT' ankleJnt = side + '_ankleJA_JNT' footJnt = side + '_footJA_JNT' pm.setAttr(hipYJnt + '.rotateOrder', 2) # chain IK legJntIK = rig_transform(0, name=side + '_legIK', type='joint', target=legJnt, parent=legModule.parts).object kneeJntIK = rig_transform(0, name=side + '_kneeIK', type='joint', target=kneeJnt).object ankleJntIK = rig_transform( 0, name=side + '_ankleIK', type='joint', target=ankleJnt, ).object footJntIK = rig_transform( 0, name=side + '_footIK', type='joint', target=footJnt, ).object chainIK = [legJntIK, kneeJntIK, ankleJntIK, footJntIK] chainParent(chainIK) chainIK.reverse() # create ik ik = rig_ik(legName, legJntIK, footJntIK, 'ikSpringSolver') pm.parent(ik.handle, legModule.parts) # pole vector legPoleVector = rig_control(side=side, name='legPV', shape='pointer', modify=1, lockHideAttrs=['rx', 'ry', 'rz'], targetOffset=[legJnt, footJnt], parentOffset=legModule.parts, scale=(2, 2, 2)) pm.delete(pm.aimConstraint(ankleJnt, legPoleVector.offset, mo=False)) kneePos = pm.xform(kneeJnt, translation=True, query=True, ws=True) poleVectorPos = pm.xform(legPoleVector.con, translation=True, query=True, ws=True) pvDistance = lengthVector(kneePos, poleVectorPos) pm.xform(legPoleVector.offset, translation=[-25, 0, 0], os=True, r=True) pm.poleVectorConstraint(legPoleVector.con, ik.handle) # create pv #pm.parentConstraint(biped.centerConnection, legPoleVector.offset, mo=True) pm.parentConstraint(hipYJnt, legPoleVector.offset, mo=True) if side == 'r': pm.rotate(legPoleVector.ctrl.cv, 0, -90, 0, r=True, os=True) else: pm.rotate(legPoleVector.ctrl.cv, 0, 90, 0, r=True, os=True) # create foot control foot = rig_control(side=side, name='foot', shape='box', modify=1, scale=(13, 13, 13), parentOffset=legModule.controls, lockHideAttrs=['rx', 'ry', 'rz']) pm.delete(pm.pointConstraint(footJnt, foot.offset)) pm.parentConstraint(foot.con, ik.handle, mo=True) #pm.pointConstraint( foot.con, legPoleVector.modify, mo=True ) foot.gimbal = createCtrlGimbal(foot) foot.pivot = createCtrlPivot(foot) constrainObject( foot.offset, [biped.pelvisConnection, biped.centerConnection, 'worldSpace_GRP'], foot.ctrl, ['pelvis', 'main', 'world'], type='parentConstraint') pm.setAttr(foot.ctrl.space, 2) pm.addAttr(foot.ctrl, longName='twist', at='float', k=True) pm.addAttr(foot.ctrl, longName='springBiasBottom', at='float', min=0, max=1, k=True, dv=0) pm.addAttr(foot.ctrl, longName='springBiasTop', at='float', min=0, max=1, k=True, dv=0.5) pm.connectAttr(foot.ctrl.twist, ik.handle.twist) pm.connectAttr(foot.ctrl.springBiasBottom, ik.handle + '.springAngleBias[0].springAngleBias_FloatValue', f=True) pm.connectAttr(foot.ctrl.springBiasTop, ik.handle + '.springAngleBias[1].springAngleBias_FloatValue', f=True) # create hip aims hipAimZ_loc = rig_transform(0, name=side + '_hipAimZ', type='locator', parent=legModule.parts, target=hipZJnt).object footAimZ_loc = rig_transform(0, name=side + '_footAimZ', type='locator', parent=legModule.parts).object pm.pointConstraint(biped.pelvisConnection, hipAimZ_loc, mo=True) pm.parentConstraint(foot.con, footAimZ_loc) # z rotation hipAimZ = mm.eval('rig_makePiston("' + footAimZ_loc + '", "' + hipAimZ_loc + '", "' + side + '_hipAimZ");') hipZ = rig_control(side=side, name='hipRoll', shape='sphere', modify=1, scale=(5, 5, 7), parentOffset=legModule.parts, targetOffset=hipZJnt, lockHideAttrs=['tx', 'ty', 'tz', 'rx', 'ry'], rotateOrder=0) pm.parentConstraint(hipZ.con, hipZJnt, mo=True) pm.parentConstraint(lowerBody.con, hipZ.offset, mo=True) rotCon = pm.orientConstraint(hipZ.offset, hipAimZ_loc, hipZ.modify, mo=True, skip=('x', 'y')) targetZ = rotCon.getWeightAliasList() #pm.addAttr(hipZ.ctrl, longName='aim', at='float', k=True, min=0, max=1, # dv=1) #pm.connectAttr ( hipZ.ctrl.aim, target ) # y rotation hipAimY_loc = rig_transform(0, name=side + '_hipAimY', type='locator', parent=legModule.parts, target=hipYJnt).object footAimY_loc = rig_transform(0, name=side + '_footAimY', type='locator', parent=legModule.parts).object pm.pointConstraint(hipZJnt, hipAimY_loc, mo=True) pm.parentConstraint(foot.con, footAimY_loc) hipAimY = mm.eval('rig_makePiston("' + footAimY_loc + '", "' + hipAimY_loc + '", ' '"' + side + '_hipAimY");') pm.setAttr(side + '_hipAimZ_LOC.rotateOrder', 4) hipY = rig_control(side=side, name='hipYaw', shape='sphere', modify=2, scale=(5, 7, 5), parentOffset=legModule.controls, targetOffset=hipYJnt, lockHideAttrs=['tx', 'ty', 'tz', 'rx', 'rz'], rotateOrder=2) pm.parentConstraint(hipY.con, hipYJnt, mo=True) pm.parentConstraint(hipZ.con, hipY.offset, mo=True) #rotCon = pm.parentConstraint(hipAimY_loc, hipY.modify, mo=True, # skipTranslate=('x', 'y', 'z'), # skipRotate=('x', 'z')) rotCon = pm.orientConstraint(hipY.offset, hipAimY_loc, hipY.modify[0], mo=True, skip=('x', 'z')) targetY = rotCon.getWeightAliasList() pm.addAttr(hipY.ctrl, longName='aim', at='float', k=True, min=0, max=1, dv=1) pm.connectAttr(hipY.ctrl.aim, targetY[1]) pm.connectAttr(hipY.ctrl.aim, targetZ[1]) connectReverse(name=side + '_leg', input=(hipY.ctrl.aim, hipY.ctrl.aim, 0), output=(targetY[0], targetZ[0], 0)) pm.setAttr(rotCon.interpType, 2) pm.transformLimits(hipY.modify[0], ry=(-30, 10), ery=(1, 1)) pm.addAttr(hipY.ctrl, longName='aimRotation', at='float', k=True, min=0, max=10, dv=0) pm.addAttr(hipY.ctrl, longName='limitOutRotation', at='float', k=True, min=0, max=10, dv=3) pm.addAttr(hipY.ctrl, longName='limitInRotation', at='float', k=True, min=0, max=10, dv=0) hipY.ctrl.limitOutRotation.set(cb=True) hipY.ctrl.limitInRotation.set(cb=True) pm.setDrivenKeyframe(hipY.modify[0] + '.minRotYLimit', cd=hipY.ctrl.limitOutRotation, dv=0, v=-45) pm.setDrivenKeyframe(hipY.modify[0] + '.minRotYLimit', cd=hipY.ctrl.limitOutRotation, dv=10, v=0) pm.setDrivenKeyframe(hipY.modify[0] + '.maxRotYLimit', cd=hipY.ctrl.limitInRotation, dv=0, v=10) pm.setDrivenKeyframe(hipY.modify[0] + '.maxRotYLimit', cd=hipY.ctrl.limitInRotation, dv=10, v=0) rotCon = pm.orientConstraint(hipY.offset, hipY.modify[0], hipY.modify[1], mo=True) conTargets = rotCon.getWeightAliasList() pm.setDrivenKeyframe(conTargets[0], cd=hipY.ctrl.aimRotation, dv=0, v=1) pm.setDrivenKeyframe(conTargets[0], cd=hipY.ctrl.aimRotation, dv=10, v=0) connectReverse(name=side + '_hipYTarget', input=(conTargets[0], 0, 0), output=(conTargets[1], 0, 0)) # constrain shizzle legTop = rig_transform(0, name=side + '_legTop', target=legJnt, parent=legModule.skeleton).object pm.setAttr(legTop + '.inheritsTransform', 0) pm.scaleConstraint('worldSpace_GRP', legTop) legSkeletonParts = rig_transform(0, name=side + '_legSkeletonParts', parent=legTop).object pm.parent(hipAimY, hipAimZ, legModule.parts) pm.parent(legJntIK, legJnt, legSkeletonParts) pm.hide(legJntIK) pm.parentConstraint(hipYJnt, legTop, mo=True, skipRotate=('x', 'y', 'z')) #pm.connectAttr(legJntIK+'.rotate', legJnt+'.rotate') pm.connectAttr(kneeJntIK + '.rotate', kneeJnt + '.rotate') pm.connectAttr(ankleJntIK + '.rotate', ankleJnt + '.rotate') multiplyDivideNode('legRotate', 'multiply', input1=[ legJntIK + '.rotateX', legJntIK + '.rotateY', legJntIK + '.rotateZ' ], input2=[1, hipY.ctrl.aim, hipY.ctrl.aim], output=[ legJnt + '.rotateX', legJnt + '.rotateY', legJnt + '.rotateZ' ]) pm.parent(hipZJnt, legModule.skeleton) pm.parent(hipYJnt, legModule.skeleton) footJnts = [ side + '_heelRotY_JA_JNT', side + '_footRotX_JA_JNT', side + '_footRotY_JA_JNT', side + '_footRotZ_JA_JNT' ] footControls = simpleControls(footJnts, modify=2, scale=(11, 3, 20), parentOffset=legModule.parts, colour=secColour, lockHideAttrs=['tx', 'ty', 'tz']) #footControls[side+''] ankle = rig_control(side=side, name='ankle', shape='box', modify=1, scale=(10, 6, 8), colour=secColour, parentOffset=legModule.controls, targetOffset=side + '_footRotZ_JA_JNT', lockHideAttrs=['tx', 'ty', 'tz', 'ry']) pm.parentConstraint(footJnt, ankle.offset, mo=True) heel = footControls[side + '_heelRotY_JA_JNT'] footRotX = footControls[side + '_footRotX_JA_JNT'] footRotY = footControls[side + '_footRotY_JA_JNT'] footRotZ = footControls[side + '_footRotZ_JA_JNT'] pm.parent(heel.offset, legModule.controls) heel.ctrl.rotateX.setKeyable(False) heel.ctrl.rotateX.setLocked(True) heel.ctrl.rotateZ.setKeyable(False) heel.ctrl.rotateZ.setLocked(True) pm.parentConstraint(footRotY.con, heel.modify[0], mo=True) pm.parentConstraint(footRotZ.con, footRotY.modify[0], mo=True) pm.parentConstraint(footRotX.con, footRotZ.modify[0], mo=True) footSpace = footJnt if side == 'l': footSpace = rig_transform(0, name='l_footSpace', parent=legModule.parts, target=footJnt).object pm.setAttr(footSpace + '.rotateX', 0) pm.parentConstraint(footJnt, footSpace, mo=True) toeSpaceList = ('lowerBody', 'foot', 'main', 'world') constrainObject(heel.modify[1], [ biped.pelvisConnection, footSpace, biped.centerConnection, 'worldSpace_GRP' ], heel.ctrl, toeSpaceList, type='orientConstraint', skip=('x', 'z')) constrainObject(footRotX.modify[0], [ biped.pelvisConnection, footSpace, biped.centerConnection, 'worldSpace_GRP' ], footRotX.ctrl, toeSpaceList, type='orientConstraint', skip=('y', 'z')) constrainObject(footRotZ.modify[1], [ biped.pelvisConnection, footSpace, biped.centerConnection, 'worldSpace_GRP' ], footRotZ.ctrl, toeSpaceList, type='orientConstraint', skip=('x', 'y')) pm.connectAttr(ankle.ctrl.rotateX, footRotX.ctrl.rotateX) #pm.connectAttr( ankle.ctrl.rotateY, heel.ctrl.rotateY ) #connectNegative(ankle.ctrl.rotateY, heel.ctrl.rotateY) pm.connectAttr(ankle.ctrl.rotateZ, footRotZ.ctrl.rotateZ) pm.addAttr(ankle.ctrl, ln='SPACES', at='enum', enumName='___________', k=True) ankle.ctrl.SPACES.setLocked(True) pm.addAttr(ankle.ctrl, ln='rollSpace', at='enum', enumName='lowerBody:foot:main:world', k=True) #pm.addAttr(ankle.ctrl, ln='yawSpace', at='enum', # enumName='lowerBody:foot:main:world', k=True) pm.addAttr(ankle.ctrl, ln='pitchSpace', at='enum', enumName='lowerBody:foot:main:world', k=True) pm.connectAttr(ankle.ctrl.rollSpace, footRotX.ctrl.space) #pm.connectAttr( ankle.ctrl.yawSpace, heel.ctrl.space) pm.connectAttr(ankle.ctrl.pitchSpace, footRotZ.ctrl.space) pm.addAttr(ankle.ctrl, ln='MOTION', at='enum', enumName='___________', k=True) ankle.ctrl.MOTION.setLocked(True) pm.addAttr(ankle.ctrl, longName='footFangs', at='float', k=True, min=0, max=10, dv=0) pm.addAttr(ankle.ctrl, longName='toeFangs', at='float', k=True, min=0, max=10, dv=0) fangsJnt = pm.PyNode(side + '_toeFangsJA_JNT') toeFangsJnt = pm.PyNode(side + '_footFangsJA_JNT') fangsTranslate = fangsJnt.translate.get() pm.setDrivenKeyframe(fangsJnt.translateX, cd=ankle.ctrl.footFangs, dv=0, v=fangsTranslate[0]) pm.setDrivenKeyframe(fangsJnt.translateY, cd=ankle.ctrl.footFangs, dv=0, v=fangsTranslate[1]) pm.setDrivenKeyframe(fangsJnt.translateZ, cd=ankle.ctrl.footFangs, dv=0, v=fangsTranslate[2]) pm.move(0, 1.5, 0, fangsJnt, r=True, os=True) fangsTranslate = fangsJnt.translate.get() pm.move(0, -1.5, 0, fangsJnt, r=True, os=True) pm.setDrivenKeyframe(fangsJnt.translateX, cd=ankle.ctrl.footFangs, dv=10, v=fangsTranslate[0]) pm.setDrivenKeyframe(fangsJnt.translateY, cd=ankle.ctrl.footFangs, dv=10, v=fangsTranslate[1]) pm.setDrivenKeyframe(fangsJnt.translateZ, cd=ankle.ctrl.footFangs, dv=10, v=fangsTranslate[2]) # foot fangs fangsTranslate = toeFangsJnt.translate.get() pm.setDrivenKeyframe(toeFangsJnt.translateX, cd=ankle.ctrl.toeFangs, dv=0, v=fangsTranslate[0]) pm.setDrivenKeyframe(toeFangsJnt.translateY, cd=ankle.ctrl.toeFangs, dv=0, v=fangsTranslate[1]) pm.setDrivenKeyframe(toeFangsJnt.translateZ, cd=ankle.ctrl.toeFangs, dv=0, v=fangsTranslate[2]) pm.move(0, 0, -4.7, toeFangsJnt, r=True, os=True) fangsTranslate = toeFangsJnt.translate.get() pm.move(0, 0, 4.7, toeFangsJnt, r=True, os=True) pm.setDrivenKeyframe(toeFangsJnt.translateX, cd=ankle.ctrl.toeFangs, dv=10, v=fangsTranslate[0]) pm.setDrivenKeyframe(toeFangsJnt.translateY, cd=ankle.ctrl.toeFangs, dv=10, v=fangsTranslate[1]) pm.setDrivenKeyframe(toeFangsJnt.translateZ, cd=ankle.ctrl.toeFangs, dv=10, v=fangsTranslate[2]) pm.addAttr(ankle.ctrl, longName='toeCapRotate', at='float', k=True, dv=0) if side == 'l': pm.connectAttr(ankle.ctrl.toeCapRotate, 'l_footCapJA_JNT.rotateX', f=True) else: connectReverse(ankle.ctrl.toeCapRotate, 'r_footCapJA_JNT.rotateX') # simple controls legSidesSimpleControls(legModule, side, secColour) armSidesSimpleControls(armModule, side, secColour) # asymettrical controls bodySimpleControls(bodyModule)
def arm(self, side='', ctrlSize=1.0): name = side + '_arm' if side == '': name = 'arm' module = rig_module(name) self.armModule = module arm = self.armName elbow = self.elbowName hand = self.handName if side != '': arm = side + '_' + arm elbow = side + '_' + elbow hand = side + '_' + hand chain = [arm, elbow, hand] pm.parent(arm, module.skeleton) print 'arm ' + arm print 'elbow ' + elbow print 'hand ' + hand ctrlSizeHalf = [ctrlSize / 4.0, ctrlSize / 4.0, ctrlSize / 4.0] ctrlSize = [ctrlSize, ctrlSize, ctrlSize] self.armTop = rig_transform(0, name=side + '_armTop', target=arm, parent=module.parts).object armSkeletonParts = rig_transform(0, name=side + '_armSkeletonParts', parent=self.armTop).object # chain result armResult = rig_transform(0, name=side + '_armResult', type='joint', target=arm, parent=armSkeletonParts, rotateOrder=2).object elbowResult = rig_transform(0, name=side + '_elbowResult', type='joint', target=elbow, rotateOrder=2).object handResult = rig_transform(0, name=side + '_handResult', type='joint', target=hand, rotateOrder=2).object chainResult = [armResult, elbowResult, handResult] chainParent(chainResult) chainResult.reverse() # chain FK armFK = rig_transform(0, name=side + '_armFK', type='joint', target=arm, parent=armSkeletonParts, rotateOrder=2).object elbowFK = rig_transform(0, name=side + '_elbowFK', type='joint', target=elbow, rotateOrder=2).object handFK = rig_transform(0, name=side + '_handFK', type='joint', target=hand, rotateOrder=2).object chainFK = [armFK, elbowFK, handFK] chainParent(chainFK) chainFK.reverse() # chain IK armIK = rig_transform(0, name=side + '_armIK', type='joint', target=arm, parent=armSkeletonParts, rotateOrder=2).object elbowIK = rig_transform(0, name=side + '_elbowIK', type='joint', target=elbow, rotateOrder=2).object handIK = rig_transform(0, name=side + '_handIK', type='joint', target=hand, rotateOrder=2).object chainIK = [armIK, elbowIK, handIK] chainParent(chainIK) chainIK.reverse() # create ik ik = rig_ik(name, armIK, handIK, 'ikRPsolver') pm.parent(ik.handle, module.parts) poleVector = rig_control(side=side, name='armPV', shape='pointer', modify=1, lockHideAttrs=['rx', 'ry', 'rz'], targetOffset=[arm, hand], parentOffset=module.controls, scale=ctrlSizeHalf) if side == 'r': pm.rotate(poleVector.ctrl.cv, 90, 0, 0, r=True, os=True) else: pm.rotate(poleVector.ctrl.cv, -90, 0, 0, r=True, os=True) pm.connectAttr(module.top.ikFkSwitch, poleVector.offset + '.visibility') self.armControls['poleVector'] = poleVector pm.delete(pm.aimConstraint(elbow, poleVector.offset, mo=False)) handPos = pm.xform(hand, translation=True, query=True, ws=True) elbowPos = pm.xform(elbow, translation=True, query=True, ws=True) poleVectorPos = pm.xform(poleVector.con, translation=True, query=True, ws=True) pvDistance = lengthVector(elbowPos, poleVectorPos) pm.xform(poleVector.offset, translation=[pvDistance, 0, 0], os=True, r=True) pm.poleVectorConstraint(poleVector.con, ik.handle) # create pv pm.move(poleVector.offset, [0, -pvDistance * 40, 0], relative=True, objectSpace=True) ''' pvDistance = lengthVector(handPos, elbowPos) pm.move(poleVector.offset, [pvDistance*2, 0, 0], relative=True, objectSpace=True) ''' print 'ik handle ' + ik.handle handControl = rig_control(side=side, name='hand', shape='box', modify=2, parentOffset=module.controls, scale=ctrlSize, rotateOrder=2) pm.delete(pm.pointConstraint(hand, handControl.offset)) pm.parentConstraint(handControl.con, ik.handle, mo=True) handControl.gimbal = createCtrlGimbal(handControl) handControl.pivot = createCtrlPivot(handControl) constrainObject( handControl.offset, [self.spineConnection, self.centerConnection, 'worldSpace_GRP'], handControl.ctrl, ['spine', 'main', 'world'], type='parentConstraint') pm.addAttr(handControl.ctrl, longName='twist', at='float', k=True) pm.connectAttr(handControl.ctrl.twist, ik.handle.twist) pm.connectAttr(module.top.ikFkSwitch, handControl.offset + '.visibility') self.armControls['hand'] = handControl handIK_loc = rig_transform(0, name=side + '_handIKBuffer', type='locator', target=handIK, parent=handControl.con).object pm.hide(handIK_loc) pm.parentConstraint(handIK_loc, handIK, mo=True, skipTranslate=('x', 'y', 'z')) # auto pole vector autoPVOffset = rig_transform(0, name=side + '_autoPVOffset', parent=module.parts, target=poleVector.con).object autoPVLoc = rig_transform(0, name=side + '_autoPV', type='locator', parent=autoPVOffset, target=autoPVOffset).object pm.parentConstraint(self.spineConnection, autoPVOffset, mo=True) pm.pointConstraint(self.spineConnection, handControl.con, autoPVLoc, mo=True) constrainObject(poleVector.offset, [ autoPVLoc, self.spineConnection, self.centerConnection, 'worldSpace_GRP' ], poleVector.ctrl, ['auto', 'spine', 'main', 'world'], type='parentConstraint') # create fk print 'fk chain ' + str(chainFK) fkCtrls = fkControlChain(chainFK, scale=ctrlSize) for fk in fkCtrls: pm.parent(fk.offset, module.controls) pm.setDrivenKeyframe(fk.offset + '.visibility', cd=module.top.ikFkSwitch, dv=1, v=0) pm.setDrivenKeyframe(fk.offset + '.visibility', cd=module.top.ikFkSwitch, dv=0, v=1) elbowFk = fkCtrls[1] rotateAxis = ['rx', 'ry', 'rz'] if self.elbowAxis in rotateAxis: rotateAxis.remove(self.elbowAxis) for at in rotateAxis: elbowFk.ctrl.attr(at).setKeyable(False) elbowFk.ctrl.attr(at).setLocked(True) self.armControls['fk'] = fkCtrls self.connectIkFkSwitch(chains=[chainResult, chainIK, chainFK], module=module, name=name) # constrain result to skeleton for i in range(0, len(chain)): pm.parentConstraint(chainResult[i], chain[i], mo=True) return module