def rig_jointCopyChain(rootJoint, replaceName=('', '')): jointChain = rig_chain(rootJoint).chain #print 'rootJoint = '+rootJoint parent = pm.listRelatives(rootJoint, p=True) #print 'parent = '+parent if len(parent) == 0: parent = '' print 'No parent found' else: parent = parent[0] i = 0 firstJoint = '' for joint in jointChain: newJnt = rig_transform(0, name=joint.replace(replaceName[0], replaceName[1]), type='joint', target=joint, parent=parent).object parent = newJnt if i == 0: firstJoint = newJnt i += 1 return rig_chain(firstJoint).chain
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 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 make(self): listOrigJoints = mc.listRelatives(self.rootJoint, type="joint", ad=True) listOrigJoints.append(self.rootJoint) listOrigJoints.reverse() listJoints = [] if self.makeDynamic: listJoints = rig_jointCopyChain(self.rootJoint, replaceName=(self.name, self.name + 'ChainSpline')) self.origRootJoint = str(self.rootJoint) self.rootJoint = listJoints[0] else: listJoints = listOrigJoints ''' rig_makeSpline(string $baseName, int $nControls, string $controlType, int $detail, int $nRead, string $readType, string $ctrls[], string $reads[], int $bConstrainMid ) ''' # make cMus tail joints mm.eval('string $ctrls[];string $reads[];rig_makeSpline( "' + self.name + '", 4, "cube", 8, ' + str(self.numIKCtrls) + ', "joint", $ctrls, $reads, 0);') # place them every thirds if len(self.splinePosList) == 0: thirds = len(listJoints) / 3 pm.delete( pm.parentConstraint(self.rootJoint, self.name + 'BaseIKOffset_GRP')) pm.delete( pm.parentConstraint(listJoints[thirds], self.name + 'MidAIKOffset_GRP')) pm.delete( pm.parentConstraint(listJoints[thirds + thirds], self.name + 'MidBIKOffset_GRP')) pm.delete( pm.parentConstraint(listJoints[len(listJoints) - 2], self.name + 'TipIKOffset_GRP')) elif len(self.splinePosList) > 0: pm.delete( pm.parentConstraint(self.splinePosList[0], self.name + 'BaseIKOffset_GRP')) pm.delete( pm.parentConstraint(self.splinePosList[1], self.name + 'MidAIKOffset_GRP')) pm.delete( pm.parentConstraint(self.splinePosList[2], self.name + 'MidBIKOffset_GRP')) pm.delete( pm.parentConstraint(self.splinePosList[3], self.name + 'TipIKOffset_GRP')) tailModule = rig_ikChainSpline(self.name, self.rootJoint, ctrlSize=self.ctrlSize, parent=self.parent, numIkControls=self.numIKCtrls, numFkControls=self.numFKCtrls, dWorldUpAxis=self.dWorldUpAxis) fkBaseCtrl = pm.PyNode(self.name + 'FKA_CTRL') fkBaseName = self.name + 'FKA_CTRL' if self.makeLag: pm.addAttr(fkBaseCtrl, longName='startFrame', attributeType="long", defaultValue=1, keyable=True) pm.addAttr(fkBaseCtrl, ln='lagExpr', at='enum', enumName='___________', k=True) fkBaseCtrl.lagExpr.setLocked(True) pm.addAttr(fkBaseCtrl, longName='lagBlend', attributeType="double", min=0, max=10, defaultValue=10, keyable=True) pm.addAttr(fkBaseCtrl, longName='lagStiffness', attributeType="double", min=0, max=10, defaultValue=0, keyable=True) pm.addAttr(fkBaseCtrl, longName='lagStiffnessBlend', attributeType="double", min=0, max=1, defaultValue=0, keyable=False) rig_animDrivenKey(fkBaseCtrl.lagStiffness, (0, 10), fkBaseCtrl.lagStiffnessBlend, (0, 1)) pm.addAttr(fkBaseCtrl, longName='upDownMult', attributeType="long", min=0, max=1, defaultValue=1, keyable=True) pm.addAttr(fkBaseCtrl, longName='leftRightMult', attributeType="long", min=0, max=1, defaultValue=1, keyable=True) # tail upgrade prevCtrl = fkBaseName tailLagGrp = rig_transform(0, name=self.name + 'Lag', parent=tailModule.parts).object tailJnts = pm.listRelatives(self.name + 'SplineJoints_GRP', type='joint') dynJnts = [] if self.makeDynamic: for i in range(0, len(tailJnts)): tailNme = tailJnts[i].stripNamespace() tailDyn = tailNme.replace('IK', 'DynJ') tailDyn = tailDyn.replace('_JNT', '') tailDyn = rig_transform(0, name=tailDyn, type='joint', target=tailJnts[i]).object dynJnts.append(tailDyn) pm.addAttr(fkBaseCtrl, ln='Dynamics', at='enum', enumName='___________', k=True) pm.addAttr(fkBaseCtrl, longName='dynamicBlend', attributeType="double", min=0, max=10, defaultValue=0, keyable=True) pm.addAttr(fkBaseCtrl, longName='stiffness', attributeType="double", min=0, max=10, defaultValue=5, keyable=True) 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', [tailFK + 'Modify1_GRP', tailIK], tailFK + '_CTRL', ['parent', 'IK'], type='parentConstraint') # make lag reference locators if self.makeLag: lagOffset = rig_transform(0, name=tailFK + 'LagOffset', parent=tailLagGrp, target=tailFK + '_CTRL').object lagExpLoc = rig_transform(0, name=tailFK + 'Lag', type='locator', parent=lagOffset, target=tailFK + '_CTRL').object lagExpRefLoc = rig_transform(0, name=tailFK + 'LagRef', type='locator', parent=lagOffset, target=tailFK + '_CTRL').object lagExpDriveLoc = rig_transform(0, name=tailFK + 'LagDrive', type='locator', parent=lagExpRefLoc, target=tailFK + '_CTRL').object pm.parentConstraint(self.spine, lagOffset, mo=True) pm.parentConstraint(prevCtrl, lagExpRefLoc, mo=True) con = pm.parentConstraint(lagExpRefLoc, lagExpLoc, lagExpDriveLoc, mo=True, sr=('x', 'y', 'z')) targets = con.getWeightAliasList() rig_animDrivenKey(fkBaseCtrl.lagBlend, (0, 10), targets[0], (1, 0)) rig_animDrivenKey(fkBaseCtrl.lagBlend, (0, 10), targets[1], (0, 1)) mm.eval( 'expression -o ("' + lagExpLoc + '") -n ("' + tailFK + 'Lag_EXP") -s ("$attrStart = ' + fkBaseName + '.startFrame;vector $refLoc = <<' + lagExpRefLoc + '.translateX,' + lagExpRefLoc + '.translateY,' + lagExpRefLoc + '.translateZ>>;vector $ball = <<' + lagExpLoc + '.translateX,' + lagExpLoc + '.translateY,' + lagExpLoc + '.translateZ>>;$stiffness = 0.9+(0.1*' + fkBaseName + '.lagStiffnessBlend);$friction = 1.0;vector $velocity;vector $oldVelocity;$distanceVector = ($refLoc - $ball)/2.0;$force = $distanceVector * $stiffness;$oldVelocity = $oldVelocity +(($ball+$force)-$ball);' + lagExpLoc + '.translateX=((' + lagExpLoc + '.translateX+$oldVelocity.x)*$friction)*' + fkBaseName + '.leftRightMult;' + lagExpLoc + '.translateY=((' + lagExpLoc + '.translateY+$oldVelocity.y)*$friction)*' + fkBaseName + '.upDownMult;' + lagExpLoc + '.translateZ=((' + lagExpLoc + '.translateZ+$oldVelocity.z)*$friction)*' + fkBaseName + '.upDownMult;if(frame == $attrStart){$velocity = <<0,0,0>>;}if(frame == $attrStart){' + lagExpLoc + '.translateX = 0;' + lagExpLoc + '.translateY= 0;' + lagExpLoc + '.translateZ = 0;}") -ae 1 -uc all ;') for at in ('tx', 'ty', 'tz'): pm.connectAttr(lagExpDriveLoc + '.' + at, tailFK + 'Modify1_GRP.' + at, f=True) prevCtrl = tailFK + '_CTRL' pm.parentConstraint(self.name + 'FKACon_GRP', self.name + 'BaseIKOffset_GRP', mo=True) constrainObject( self.name + 'MidAIKOffset_GRP', [self.name + 'FKACon_GRP', self.parent, self.worldSpace], self.name + 'MidAIK_CTRL', ['base', self.parentName, 'world'], type='parentConstraint') constrainObject(self.name + 'MidBIKOffset_GRP', [ self.name + 'FKACon_GRP', self.name + 'MidAIKCon_GRP', self.parent, self.worldSpace ], self.name + 'MidBIK_CTRL', ['base', 'FK', self.parentName, 'world'], type='parentConstraint') constrainObject(self.name + 'TipIKOffset_GRP', [ self.name + 'FKACon_GRP', self.name + 'MidBIKCon_GRP', self.parent, self.worldSpace ], self.name + 'TipIK_CTRL', ['base', 'FK', self.parentName, 'world'], type='parentConstraint') ctrlSizeHalf = [ self.ctrlSize / 2.0, self.ctrlSize / 2.0, self.ctrlSize / 2.0 ] ctrlSizeQuarter = [ self.ctrlSize / 4.0, self.ctrlSize / 4.0, self.ctrlSize / 4.0 ] self.ctrlSize = [self.ctrlSize, self.ctrlSize, self.ctrlSize] # scale ctrls for ctrl in (self.name + 'MidAIK_CTRL', self.name + 'MidBIK_CTRL', self.name + 'TipIK_CTRL'): c = pm.PyNode(ctrl) pm.scale(c.cv, self.ctrlSize[0], self.ctrlSize[0], self.ctrlSize[0]) pm.move(c.cv, [0, 2 * self.ctrlSize[0], 0], relative=True, worldSpace=True) tailPointer = rig_control(name=self.name + 'Pointer', shape='pyramid', lockHideAttrs=['rx', 'ry', 'rz'], colour='white', parentOffset=tailModule.controls, rotateOrder=2, scale=self.ctrlSize) pm.delete( pm.parentConstraint(listJoints[len(listJoints) - 2], tailPointer.offset)) constrainObject(tailPointer.offset, [self.parent, self.spine, self.worldSpace], tailPointer.ctrl, [self.parentName, 'fullBody', 'world'], type='parentConstraint') tailPointerBase = rig_transform(0, name=self.name + 'PointerBase', type='locator', parent=tailModule.parts, target=self.name + 'FKA_CTRL').object tailPointerTip = rig_transform(0, name=self.name + 'PointerTip', 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(self.parent, tailPointerBase, mo=True) pm.parentConstraint(tailPointer.con, tailPointerTip, mo=True) tailPointerTop = mm.eval('rig_makePiston("' + tailPointerBase + '", "' + tailPointerTip + '", "' + self.name + 'PointerAim");') pm.orientConstraint(tailPointerBase.replace('LOC', 'JNT'), self.name + 'FKAModify2_GRP', mo=True) pm.parent(self.name + 'MidAIKOffset_GRP', self.name + 'MidBIKOffset_GRP', self.name + 'TipIKOffset_GRP', tailModule.controls) pm.parent(tailJnts, tailModule.skeleton) pm.parent(self.name + '_cMUS', self.name + 'BaseIKOffset_GRP', tailPointerTop, tailModule.parts) pm.parent(self.name + 'SplineSetup_GRP', self.name + 'BaseIKOffset_GRP', tailPointerTop, tailModule.parts) pm.setAttr(tailModule.skeleton + '.inheritsTransform', 0) if self.makeDynamic: chainParent(dynJnts, reverse=0) dynJnts.reverse() finalChain = rig_jointCopyChain(dynJnts[0], replaceName=('Dyn', 'Final')) mc.select(self.name + "SplineIK_CRV") mm.eval('makeCurvesDynamic 2 { "1", "0", "1", "1", "0"};') hairSystem = pm.ls("|hairSystem?")[0] nucleus = pm.ls("|nucleus?")[0] dynCurveGrp = pm.ls("|hairSystem?OutputCurves")[0] dynCurve = pm.listRelatives(dynCurveGrp, c=True)[0] dynCurve = pm.rename(dynCurve, self.name + 'Dyn_CRV') nmeUpper = self.name.capitalize() #ikData = pm.ikHandle(n='dyn'+nmeUpper, sj=dynJnts[0], ee=dynJnts[-1], # solver='ikSplineSolver',curve=dynCurve,ccv=False, ns=self.numFKCtrls) ikData = rig_ik('dyn' + nmeUpper, dynJnts[0], dynJnts[-1], 'ikSplineSolver', numSpans=self.numFKCtrls, curve=dynCurve, createCurve=False) # advanced twist pm.setAttr(ikData.handle + '.dTwistControlEnable', 1) pm.setAttr(ikData.handle + '.dWorldUpType', 2) # object up start and end pm.setAttr(ikData.handle + '.dForwardAxis', 2) # positive y pm.setAttr(ikData.handle + '.dWorldUpAxis', self.dWorldUpAxis) # positive x pm.connectAttr(self.name + 'UpperAim_LOCUp.worldMatrix[0]', ikData.handle.dWorldUpMatrixEnd, f=True) pm.connectAttr(self.name + 'LowerAim_LOCUp.worldMatrix[0]', ikData.handle.dWorldUpMatrix, f=True) mc.setAttr(hairSystem + ".collide", 0) mc.setAttr(hairSystem + ".stretchResistance", 25) mc.setAttr(hairSystem + ".bendResistance", .1) mc.setAttr(hairSystem + ".stiffness", 1) mc.setAttr(hairSystem + ".lengthFlex", 1) mc.setAttr(hairSystem + ".damp", .05) mc.setAttr(hairSystem + ".stretchDamp", 1) mc.setAttr(hairSystem + ".mass", .2) mc.setAttr(hairSystem + ".attractionDamp", 1) mc.setAttr(hairSystem + ".startCurveAttract", .5) mc.setAttr("follicleShape1.pointLock", 1) mc.setAttr("follicleShape1.overrideDynamics", 1) mc.setAttr("follicleShape1.collide", 0) mc.setAttr("follicleShape1.damp", .25) mc.setAttr("follicleShape1.stiffness", 0) #mc.setAttr( "follicleShape1.startCurveAttract" ,.3) # 0.3 default dyn stiffness at 0, 1 = 10 rig_animDrivenKey(fkBaseCtrl.stiffness, (0, 10), "follicleShape1.startCurveAttract", (0.3, 1)) pm.connectAttr(fkBaseCtrl.startFrame, 'nucleus1.startFrame', f=True) # create tail dyn controls with joints parentd underneath # creat another ikSPline 'tailDriven_CRV' and 'tailDriven_ikHandle' and drive final geo, with tail dyn jonints skinned to the ikPlane tail driven crv. sc = simpleControls(dynJnts, modify=1, constrainJoints=0, parentCon=1, colour='red') pm.parent(sc[dynJnts[0]].offset, tailModule.controlsSec) collections.OrderedDict(sorted(sc.items(), key=lambda t: t[0])) i = 0 for jnt in finalChain: driverJnt = jnt.replace('Final', 'Driver') dynJnt = jnt.replace('Final', 'Dyn') pm.parent(jnt, sc[dynJnt].con) con = pm.parentConstraint(driverJnt, dynJnt, sc[dynJnt].offset, mo=True) pm.setAttr(con.interpType, 2) targets = con.getWeightAliasList() rig_animDrivenKey(fkBaseCtrl.dynamicBlend, (0, 10), targets[0], (1, 0)) rig_animDrivenKey(fkBaseCtrl.dynamicBlend, (0, 10), targets[1], (0, 1)) i += 1 chainList = rig_chain(self.origRootJoint).chain ik = rig_ik(self.name + 'Driven', self.origRootJoint, chainList[-1], 'ikSplineSolver', numSpans=self.numIKCtrls) pm.parent(ik.handle, ik.curve, tailModule.parts) # advanced twist pm.setAttr(ik.handle + '.dTwistControlEnable', 1) pm.setAttr(ik.handle + '.dWorldUpType', 2) # object up start and end pm.setAttr(ik.handle + '.dForwardAxis', 2) # positive y pm.setAttr(ik.handle + '.dWorldUpAxis', self.dWorldUpAxis) # positive x pm.connectAttr(self.name + 'UpperAim_LOCUp.worldMatrix[0]', ik.handle.dWorldUpMatrixEnd, f=True) pm.connectAttr(self.name + 'LowerAim_LOCUp.worldMatrix[0]', ik.handle.dWorldUpMatrix, f=True) pm.skinCluster(finalChain, ik.curve, tsb=True) pm.setAttr(self.name + 'Dyn_CRV.inheritsTransform', 0) pm.parent(dynJnts[0], 'nucleus1', hairSystem, ikData.handle, ikData.curve, tailModule.parts) pm.delete('hairSystem1OutputCurves') self.module = tailModule
def rig_ikChainSpline(name, rootJnt, ctrlSize=1.0, **kwds): numIkControls = defaultReturn(5, 'numIkControls', param=kwds) numFkControls = defaultReturn(5, 'numFkControls', param=kwds) dWorldUpAxis = defaultReturn(6, 'dWorldUpAxis', param=kwds) parentRoot = defaultReturn('spineJA_JNT', 'parent', param=kwds) lockBase = defaultReturn(1, 'lockBase', param=kwds) module = rig_module(name) ctrlSizeHalf = [ctrlSize / 2.0, ctrlSize / 2.0, ctrlSize / 2.0] ctrlSizeQuarter = [ctrlSize / 4.0, ctrlSize / 4.0, ctrlSize / 4.0] ctrlSize = [ctrlSize, ctrlSize, ctrlSize] chainList = rig_chain(rootJnt).chain numJoints = len(chainList) ''' ctrlPos = [] for i in range(0, numJoints): if i % numFkControls == 0: ctrlPos.append(chainList[i]) ''' endJnt = defaultReturn(rootJnt.replace('JA_JNT', 'JEnd_JNT'), 'endJnt', param=kwds) ctrlPos = mm.eval('rig_chainBetweenTwoPoints("' + name + 'Pos", "' + rootJnt + '", "' + endJnt + '",' + str(numIkControls) + ');') #for jnt in ctrlPos: pm.parent(ctrlPos, w=True) for jnt in ctrlPos: pm.delete(pm.orientConstraint(rootJnt, jnt)) # make ik driver controls/joints fkControls = [] ikControls = [] driverJntList = [] fkScale = 1.5 for i in range(0, len(ctrlPos)): driverJnt = rig_transform(0, name=name + 'DriverJ' + ABC[i], type='joint', target=ctrlPos[i], parent=module.parts, rotateOrder=2).object driverJntList.append(driverJnt) driverCtrl = rig_control(name=name + 'Driver' + ABC[i], shape='box', modify=1, scale=ctrlSizeHalf, colour='green', parentOffset=module.controlsSec, rotateOrder=2) ikControls.append(driverCtrl) pm.delete(pm.parentConstraint(driverJnt, driverCtrl.offset)) pm.parentConstraint(driverCtrl.con, driverJnt, mo=True) lockTranslate = [] ctrlShape = 'circle' if i == 0: lockTranslate = ['tx', 'ty', 'tz'] ctrlShape = 'pyramid' else: lockTranslate = [] fkCtrl = rig_control(name=name + 'FK' + ABC[i], shape=ctrlShape, modify=2, targetOffset=ctrlPos[i], parentOffset=module.controls, lockHideAttrs=lockTranslate, scale=((ctrlSize[0]) * fkScale, (ctrlSize[1]) * fkScale, (ctrlSize[2]) * fkScale)) if i == 0: if pm.objExists(parentRoot): pm.parentConstraint(parentRoot, fkCtrl.offset, mo=True) if pm.objExists(parentRoot) and pm.objExists('worldSpace_GRP'): constrainObject(fkCtrl.modify[0], [fkCtrl.offset, 'worldSpace_GRP'], fkCtrl.ctrl, ['parent', 'world'], type='orientConstraint') pm.parentConstraint(fkCtrl.con, driverCtrl.offset, mo=True) if i > 0: parentOffset = fkControls[i - 1].con pm.parent(fkCtrl.offset, parentOffset) fkControls.append(fkCtrl) fkScale = fkScale - 0.1 pm.delete(ctrlPos) # shape controls rootCtrl = fkControls[0] pm.addAttr(rootCtrl.ctrl, ln='SHAPE', at='enum', enumName='___________', k=True) rootCtrl.ctrl.SHAPE.setLocked(True) pm.addAttr(rootCtrl.ctrl, longName='curl', at='float', k=True, min=-10, max=10, dv=0) pm.addAttr(rootCtrl.ctrl, longName='curlSide', at='float', k=True, min=-10, max=10, dv=0) for i in range(1, numIkControls): rig_animDrivenKey(rootCtrl.ctrl.curl, (-10, 0, 10), fkControls[i].modify[0] + '.rotateX', (-90, 0, 90)) rig_animDrivenKey(rootCtrl.ctrl.curlSide, (-10, 0, 10), fkControls[i].modify[0] + '.rotateZ', (-90, 0, 90)) ik = rig_ik(name, rootJnt, chainList[-1], 'ikSplineSolver', numSpans=numIkControls) pm.parent(ik.handle, ik.curve, module.parts) lowerAim = rig_transform(0, name=name + 'LowerAim', type='locator', parent=module.parts, target=ikControls[1].con).object upperAim = rig_transform(0, name=name + 'UpperAim', type='locator', parent=module.parts, target=ikControls[-2].con).object pm.rotate(lowerAim, 0, 0, -90, r=True, os=True) pm.rotate(upperAim, 0, 0, -90, r=True, os=True) pm.parentConstraint(ikControls[1].con, lowerAim, mo=True) pm.parentConstraint(ikControls[-2].con, upperAim, mo=True) aimTop = mm.eval('rig_makePiston("' + lowerAim + '", "' + upperAim + '", "' + name + 'Aim");') pm.move(upperAim + 'Up', 0, 30 * ctrlSize[0], 0, r=True, os=True) pm.move(lowerAim + 'Up', 0, 20 * ctrlSize[0], 0, r=True, os=True) # advanced twist pm.setAttr(ik.handle + '.dTwistControlEnable', 1) pm.setAttr(ik.handle + '.dWorldUpType', 2) # object up start and end pm.setAttr(ik.handle + '.dForwardAxis', 2) # positive y pm.setAttr(ik.handle + '.dWorldUpAxis', dWorldUpAxis) # positive x pm.connectAttr(upperAim + 'Up.worldMatrix[0]', ik.handle.dWorldUpMatrixEnd, f=True) pm.connectAttr(lowerAim + 'Up.worldMatrix[0]', ik.handle.dWorldUpMatrix, f=True) pm.parent(aimTop, module.parts) pm.select(ik.curve) curveShape = pm.pickWalk(direction='down') curveInfoNode = pm.arclen(curveShape[0], ch=True) curveInfo = pm.rename(curveInfoNode, name + '_splineIk_curveInfo') globalCurve = pm.duplicate(ik.curve) globalCurve = pm.rename(globalCurve, name + 'global_splineIk_curve') pm.select(globalCurve) globalCurveShape = pm.pickWalk(direction='down') globalCurveInfoNode = pm.arclen(globalCurveShape[0], ch=True) globalCurveInfo = pm.rename(globalCurveInfoNode, name + 'global_splineIk_curveInfo') pm.parent(globalCurve, module.parts) pm.setAttr(globalCurve + '.inheritsTransform', 1) distanceToStretch_PM = plusMinusNode(name + '_distanceToStretch', 'subtract', curveInfo, 'arcLength', globalCurveInfo, 'arcLength') correctAdd_Minus_MD = multiplyDivideNode( name + '_correctAdd_Minus', 'multiply', input1=[-1, 0, 0], input2=[distanceToStretch_PM + '.output1D', 0, 0], output=[]) toggleStretch_ctrl_MD = multiplyDivideNode( name + '_toggleStretch_ctrl', 'multiply', input1=[0, 0, 0], input2=[correctAdd_Minus_MD + '.outputX', 0, 0], output=[]) distanceStretchCurve_PM = plusMinusNode(name + '_distanceStretchCurve', 'sum', curveInfo, 'arcLength', toggleStretch_ctrl_MD, 'outputX') globalCurveStretchyFix_MD = multiplyDivideNode( name + '_globalCurveStretchyFix', 'divide', input1=[distanceStretchCurve_PM + '.output1D', 0, 0], input2=[globalCurveInfo + '.arcLength', 1, 1], output=[]) pm.addAttr(fkControls[0].ctrl, longName='stretch', shortName='ts', attributeType="double", min=0, max=1, defaultValue=0, keyable=True) connectReverse(input=(fkControls[0].ctrl + '.stretch', 0, 0), output=(toggleStretch_ctrl_MD + '.input1X', 0, 0)) for i in range(0, len(chainList) - 1): pm.connectAttr(globalCurveStretchyFix_MD + '.outputX', chainList[i] + '.scaleY', f=True) pm.skinCluster(driverJntList, ik.curve, tsb=True) return module