def setupMeasure(self, prefixList, x): """sets up the measure joint portion of the the limb rig""" #set values for this chain, side thisChain = self.measureChains[x] side = self.prefixList[x] self.measureUp = "%s_%s_upDistance"%(side, self.limbName) self.measureLow = "%s_%s_lowDistance"%(side, self.limbName) self.totalDistAdd = "%s_%s_lengthADL"%(side, self.limbName) #measure top two joints rig.measureDistance(self.measureUp, thisChain[0], thisChain[1]) #----------add these to a list of lists of arm measures #measure low two joints rig.measureDistance(self.measureLow, thisChain[1], thisChain[2]) #add the results thisTotal = rig.createAdd(self.totalDistAdd, "%s.distance"%self.measureUp, "%s.distance"%self.measureLow) self.measureAdds.append(thisTotal) #call to start the IK setup part of the rig self.setupIK(x)
def setupIK(self, x): """sets up the IK portion of the limb rig""" #set values for this chain, side thisChain = self.IKChains[x] side = self.prefixList[x] thisBind = self.bindChains[x] #create ik control from joint 0 to 2 mainIK = "%s_%s_IK"%(side, self.limbName) IKHandle = cmds.ikHandle(n=mainIK, sj=thisChain[0], ee=thisChain[2], sol="ikRPsolver")[0] self.IKHandles.append(IKHandle) #create a control for the ik IKCtrl = self.setupIKCtrl(x, IKHandle) #call pole vector method? - pass IK name, normal or no flip #-----------------get argument from UI about what kind of handles thisPv = self.setupPV(IKHandle, "normal", x) #create stretchy bits cmds.addAttr(IKCtrl, ln="__EXTRA__", nn="__EXTRA__", at="short", k=True) cmds.setAttr("%s.__EXTRA__"%IKCtrl, l=True) cmds.addAttr(IKCtrl, ln="autoStretch", at="float", min=0, max=1, k=True) cmds.addAttr(IKCtrl, ln="scaleMin", at="float", min=0.5, max=3, k=True, dv=1) #add "upScale" and "lowScale" (.5-3) cmds.addAttr(IKCtrl, ln="upScale", at="float", min=0.3, max=3, k=True, dv=1.0) cmds.addAttr(IKCtrl, ln="lowScale", at="float", min=0.3, max=3, k=True, dv=1.0) #from measure, get final add node add = self.measureAdds[x] #orient the IK wrist to the control? do it here or elsewhere (for inheritance?) cmds.orientConstraint(IKCtrl, thisChain[2]) #create distance node from thigh to ctrl distance = rig.measureDistance("%s_%s_ikCtrlDistance"%(side, self.limbName), self.measureChains[x][0], IKCtrl) ratioMult, defaultMult, defaultBlend, conditional, upScaleMult, loScaleMult = rig.scaleStretchIK(("%s_%s"%(side, self.limbName)), thisChain[0], thisChain[1], thisChain[2], "%s.output"%add, "%s.distance"%distance, IKCtrl, self.jAxis1) #create the ik switch (call as "diamond") ikSwitchName = "%s_%s_FKIKSwitch"%(side, self.limbName) if x == 0: thisIKSwitch = rig.createControl(ikSwitchName, "diamond", self.jAxis1, "lightBlue") if x == 1: thisIKSwitch = rig.createControl(ikSwitchName, "diamond", self.jAxis1, "pink") rig.stripTransforms(thisIKSwitch) cmds.addAttr(thisIKSwitch, ln="FKIK", k=True, at="float", min=0, max=1, dv=0) #create reverse thisIKSwitchRev = cmds.shadingNode("reverse", asUtility=True, n="%s_%s_IKSwtchReverse"%(side, self.limbName)) cmds.connectAttr("%s.FKIK"%thisIKSwitch, "%s.inputX"%thisIKSwitchRev) rig.groupOrient(thisBind[2], thisIKSwitch, self.groupSuffix) IKSwitchGrp = cmds.listRelatives(thisIKSwitch, p=True) #do stuff here to push the IKFK switch in the right direction if x== 0: offset = -3 if x==1: offset = 3 cmds.xform(IKSwitchGrp, os=True, r=True, t=(0, 0, offset)) self.IKSwitches.append(thisIKSwitch) self.IKSwitchesRev.append(thisIKSwitchRev) #set up visibility switching from this for IK and PV controls #get pv parent group pvGroup = cmds.listRelatives(thisPv, p=True)[0] ikCtrlGroup = cmds.listRelatives(IKCtrl, p=True)[0] cmds.connectAttr("%s.FKIK"%thisIKSwitch, "%s.v"%pvGroup) cmds.connectAttr("%s.FKIK"%thisIKSwitch, "%s.v"%ikCtrlGroup) #pass onto the FK part of the rig self.setupFK(x)
def setupIK(self, x): """sets up the IK portion of the limb rig""" #set values for this chain, side thisChain = self.IKChains[x] side = self.prefixList[x] thisBind = self.bindChains[x] #create ik control from joint 0 to 2 mainIK = "%s_%s_IK"%(side, self.limbName) IKHandle = cmds.ikHandle(n=mainIK, sj=thisChain[0], ee=thisChain[2], sol="ikRPsolver")[0] self.IKHandles.append(IKHandle) #create a control for the ik IKCtrl = self.setupIKCtrl(x, IKHandle) #call pole vector method? - pass IK name, normal or no flip #-----------------get argument from UI about what kind of handles thisPv = self.setupPV(IKHandle, "normal", x) #create stretchy bits cmds.addAttr(IKCtrl, ln="__EXTRA__", nn="__EXTRA__", at="short", k=True) cmds.setAttr("%s.__EXTRA__"%IKCtrl, l=True) cmds.addAttr(IKCtrl, ln="autoStretch", at="float", min=0, max=1, k=True) cmds.addAttr(IKCtrl, ln="scaleMin", at="float", min=0.5, max=3, k=True, dv=1) #add "upScale" and "lowScale" (.5-3) cmds.addAttr(IKCtrl, ln="upScale", at="float", min=0.3, max=3, k=True, dv=1.0) cmds.addAttr(IKCtrl, ln="lowScale", at="float", min=0.3, max=3, k=True, dv=1.0) cmds.addAttr(IKCtrl, ln="__IKFOOT__", nn="__EXTRA__", at="short", k=True) cmds.setAttr("%s.__IKFOOT__"%IKCtrl, l=True) cmds.addAttr(IKCtrl, ln="ballRoll", at="float", k=True, dv=0) cmds.addAttr(IKCtrl, ln="toeRoll", at="float", k=True, dv=0) cmds.addAttr(IKCtrl, ln="heelRoll", at="float", k=True, dv=0) cmds.addAttr(IKCtrl, ln="toePivot", at="float", k=True, dv=0) cmds.addAttr(IKCtrl, ln="heelPivot", at="float", k=True, dv=0) cmds.addAttr(IKCtrl, ln="toeFlap", at="float", k=True, dv=0) #from measure, get final add node add = self.measureAdds[x] #orient the IK wrist to the control? do it here or elsewhere (for inheritance?) cmds.orientConstraint(IKCtrl, thisChain[2], mo=True) #create distance node from thigh to ctrl distance = rig.measureDistance("%s_%s_ikCtrlDistance"%(side, self.limbName), self.measureChains[x][0], IKCtrl) ratioMult, defaultMult, defaultBlend, conditional, upScaleMult, loScaleMult = rig.scaleStretchIK(("%s_%s"%(side, self.limbName)), thisChain[0], thisChain[1], thisChain[2], "%s.output"%add, "%s.distance"%distance, IKCtrl, self.jAxis1) #create the ik switch (call as "diamond") ikSwitchName = "%s_%s_FKIKSwitch"%(side, self.limbName) if x == 0: thisIKSwitch = rig.createControl(ikSwitchName, "diamond", self.jAxis1, "lightBlue") if x == 1: thisIKSwitch = rig.createControl(ikSwitchName, "diamond", self.jAxis1, "pink") rig.stripTransforms(thisIKSwitch) cmds.addAttr(thisIKSwitch, ln="FKIK", k=True, at="float", min=0, max=1, dv=0) #create reverse thisIKSwitchRev = cmds.shadingNode("reverse", asUtility=True, n="%s_%s_IKSwtchReverse"%(side, self.limbName)) cmds.connectAttr("%s.FKIK"%thisIKSwitch, "%s.inputX"%thisIKSwitchRev) rig.groupOrient(thisBind[2], thisIKSwitch, self.groupSuffix) IKSwitchGrp = cmds.listRelatives(thisIKSwitch, p=True) #do stuff here to push the IKFK switch in the right direction if x== 0: offset = -3 if x==1: offset = 3 cmds.xform(IKSwitchGrp, os=True, r=True, t=(0, 0, offset)) self.IKSwitches.append(thisIKSwitch) self.IKSwitchesRev.append(thisIKSwitchRev) #set up visibility switching from this for IK and PV controls #get pv parent group pvGroup = cmds.listRelatives(thisPv, p=True)[0] ikCtrlGroup = cmds.listRelatives(IKCtrl, p=True)[0] cmds.connectAttr("%s.FKIK"%thisIKSwitch, "%s.v"%pvGroup) cmds.connectAttr("%s.FKIK"%thisIKSwitch, "%s.v"%ikCtrlGroup) #pass onto the FK part of the rig self.setupFK(x)
def smallIKStretch(*args): """ create the 2 joint chain at the start and end of the shock/spring/whatever. select the base joint and run this.Then you'll hook up the top/bottom locators to whatever they're connected to (parentConstraint, etc) and hook the geo onto the original joints (parentConstraint, etc) """ #select the joint, give as arg the name(?) of the setup sel = cmds.ls(sl=True) origJnt = sel[0] #get child joint of this joint origChild = cmds.listRelatives(origJnt, c=True)[0] #create locators at joint start and end positions orig1Pos = cmds.xform(origJnt, ws=True, q=True, rp=True) orig2Pos = cmds.xform(origChild, ws=True, q=True, rp=True) orig1Loc = cmds.spaceLocator(n="%s_LOC"%origJnt)[0] orig2Loc = cmds.spaceLocator(n="%s_LOC"%origChild)[0] cmds.xform(orig1Loc, ws=True, t=orig1Pos) cmds.xform(orig2Loc, ws=True, t=orig2Pos) #dupe the joint, rename it, measure it dupeJnts = cmds.duplicate(origJnt) mJnt1Orig = dupeJnts[0] mJnt1 = cmds.rename(mJnt1Orig, "measure_%s"%origJnt) mJnt2orig = cmds.listRelatives(mJnt1, c=True, f=True)[0] mJnt2 = cmds.rename(mJnt2orig, "measure_%s"%origChild) #create IK handles on orig joints, parent handle to second loc ik = cmds.ikHandle( n="%s_IK"%origJnt, sj=origJnt, ee=origChild)[0] cmds.parent(ik, orig2Loc) print orig2Loc #measure from the base measure joint to the ik handle origM = rig.measureDistance((origJnt+"orig_dist"), mJnt1, mJnt2) activeM = rig.measureDistance((origJnt+"active_dist"), mJnt1, orig2Loc) #create mult node to compare the two measures mult = cmds.shadingNode("multiplyDivide", asUtility=True, n="%s_mult"%origJnt) cmds.setAttr("%s.operation"%mult, 2) cmds.connectAttr("%s.distance"%activeM, "%s.input1X"%mult) cmds.connectAttr("%s.distance"%origM, "%s.input2X"%mult) #---use this code if you want to set up a non-scaling piston geo # #create a condition node to tell when to use what value # cond = cmds.shadingNode("condition", asUtility=True, n="%s_cond"%origJnt) # cmds.setAttr("%s.secondTerm"%cond, 1) # cmds.setAttr("%s.operation"%cond, 2) # cmds.connectAttr("%s.outputX"%mult, "%s.firstTerm"%cond) # cmds.connectAttr("%s.outputX"%mult, "%s.colorIfTrueR"%cond) # cmds.setAttr("%s.colorIfFalseR"%cond, 1) # #hook the condition node into the scale of the ik joint (in x for now) # cmds.connectAttr("%s.outColorR"%cond, "%s.sx"%origJnt) #hook the mult into the scale of the joint (comment this line out if you use the commented code above) cmds.connectAttr("%s.outputX"%mult, "%s.sx"%origJnt) #connect the orig joint to the base of the setup (loc) cmds.parentConstraint(orig1Loc, origJnt, mo=True) #hide measure joints cmds.setAttr("%s.visibility"%mJnt1, 0) #package up objects in group group = cmds.group(empty=True, n="%s_GRP"%origJnt) cmds.parent(mJnt1, origJnt, orig1Loc) cmds.parent(orig1Loc, orig2Loc, group)