def makeClavicle(self, prefix, limbJoints, scapulaJnt, rigScale, rigmodule): clavicleCtrl = control.Control(prefix=prefix + 'Clavicle', translateTo=scapulaJnt, rotateTo=scapulaJnt, parent=rigmodule.controlsGrp, shape='sphere', lockChannels=['t', 's', 'v']) scapulaIk = pm.ikHandle(n=prefix + 'Scapula_IKH', sol='ikSCsolver', sj=scapulaJnt, ee=limbJoints[0])[0] pm.hide(scapulaIk) pm.parentConstraint(self.baseAttachGrp, clavicleCtrl.Off, mo=1) pm.parent(scapulaIk, clavicleCtrl.C) pm.pointConstraint(clavicleCtrl.C, scapulaJnt) return clavicleCtrl
def makePoleVector(self, ikHandle, autoElbowCtrl, rigScale, rigmodule): prefix = name.removeSuffix(ikHandle) pvInstance = poleVector.PoleVector(ikHandle) poleVectorLoc, poleVectorGrp = pvInstance.getPoleVector() pm.parent(poleVectorGrp, rigmodule.partsNoTransGrp) poleVectorCtrl = control.Control(prefix=prefix + 'PV', translateTo=poleVectorLoc, scale=rigScale, parent=rigmodule.controlsGrp, shape='sphere') # pm.parentConstraint(self.bodyAttachGrp, poleVectorCtrl.Off, mo=1) spaces.spaces([self.bodyAttachGrp, autoElbowCtrl], ['body', 'control'], poleVectorCtrl.Off, poleVectorCtrl.getControl()) poleVectorCtrl.getControl().space.set(1) pm.parentConstraint(poleVectorCtrl.getControl(), poleVectorLoc) # make pole vector connection line elbowJnt = ikHandle.getJointList()[1] pvLinePos1 = pm.xform(elbowJnt, q=1, t=1, ws=1) pvLinePos2 = pm.xform(poleVectorLoc, q=1, t=1, ws=1) poleVectorCrv = pm.curve(n=prefix + 'Pv_CRV', d=1, p=[pvLinePos1, pvLinePos2]) pm.cluster(poleVectorCrv + '.cv[0]', n=prefix + 'Pv1_CLS', wn=[elbowJnt, elbowJnt], bs=True) pm.cluster(poleVectorCrv + '.cv[1]', n=prefix + 'Pv2_CLS', wn=[poleVectorCtrl.C, poleVectorCtrl.C], bs=True) pm.parent(poleVectorCrv, rigmodule.controlsGrp) pm.setAttr(poleVectorCrv + '.template', 1) pm.setAttr(poleVectorCrv + '.it', 0) return poleVectorCtrl, poleVectorLoc
def createIKFK(self, mainCtrlAttachObj, scale): # make Display ikfkCtrl = control.Control(prefix='ikfk', scale=scale, parent=self.rigCtrlGrp, translateTo=mainCtrlAttachObj, rotateTo=self.rigCtrlLoc, lockChannels=['t', 'r', 's'], shape='ikfk', doOffset=True, doModify=True, objBBox=mainCtrlAttachObj) if pm.objExists(mainCtrlAttachObj): # constraint displayCtrl common.centerPivot(ikfkCtrl.getOffsetGrp()) common.centerPivot(ikfkCtrl.getControl()) pm.parentConstraint(mainCtrlAttachObj, ikfkCtrl.getOffsetGrp(), mo=True) ikfkCtrl.getModifyGrp().translateY.set(3 * ikfkCtrl.getCtrlScale()) return ikfkCtrl
def makeFK(self, limbJoints, topFingerJoints, rigScale, rigmodule): """ Do FK Arm/Leg, Metacarpal and Finger/Toe ctrl :param limbJoints: list(str), Arm/leg joints :param topFingerJoints: list(str), Metacarpal joints :param rigScale: float :param rigmodule: dict :return: """ limbCtrlInstanceList = [] handFeetCtrlInstanceList = [] limbCtrlConstraintList = [] handFeetCtrlConstraintList = [] # Arm/Leg for jnt in limbJoints: prefix = name.removeSuffix(jnt) parent = rigmodule.controlsGrp if len(limbCtrlInstanceList) > 0: parent = limbCtrlInstanceList[-1].C ctrl = control.Control(prefix=prefix, translateTo=jnt, rotateTo=jnt, parent=parent, shape='circleX') orientCnst = pm.orientConstraint(ctrl.getControl(), jnt, mo=True) limbCtrlConstraintList.append(orientCnst) limbCtrlInstanceList.append(ctrl)
def __init__(self, chainJoints, prefix='tail', rigScale=1.0, doDynamic=False, smallestScalePercent=0.1, fkParenting=True, baseRig=None): """ :param chainJoints: list( str ), list of chain joints :param prefix: str, prefix to name new objects :param rigScale: float, scale factor for size of controls :param smallestScalePercent: float, scale of smallest control at the end of chain compared to rigScale :param doDynamic: bool, setup dynamic curve :param fkParenting: bool, parent each control to previous one to make FK chain :param baseRig: instance of base.module.Base class :return: dictionary with rig module objects """ # :param chainCurve: str, name of chain cubic curve # make rig module self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig) # collision point collisionPoint = int(len(chainJoints)) # make IK handle chainIk, effector, chainCurve = pm.ikHandle( n=prefix + '_IKH', sol='ikSplineSolver', sj=chainJoints[0], ee=chainJoints[-1], # -2 createCurve=True, numSpans=collisionPoint) # rename curve pm.rename(chainCurve, prefix + '_CRV') # create ctrlCurve ctrlCurve = pm.duplicate(chainCurve, n=prefix + 'Ctrl_CRV')[0] # make chain curve clusters chainCurveCVs = pm.ls(ctrlCurve + '.cv[*]', fl=1) numChainCVs = len(chainCurveCVs) chainCurveClusters = [] for i in range(numChainCVs): cls = pm.cluster(chainCurveCVs[i], n=prefix + 'Cluster%d' % (i + 1))[1] chainCurveClusters.append(cls) pm.hide(chainCurveClusters) # parent chain curve pm.parent(chainCurve, self.rigmodule.partsNoTransGrp) pm.parent(ctrlCurve, self.rigmodule.partsNoTransGrp) # make attach groups self.baseAttachGrp = pm.group(n=prefix + 'BaseAttach_GRP', em=1, p=self.rigmodule.partsGrp) pm.delete(pm.pointConstraint(chainJoints[0], self.baseAttachGrp)) # make controls chainControls = [] controlScaleIncrement = (1.0 - smallestScalePercent) / numChainCVs mainCtrlScaleFactor = 1.0 # 5.0 for i in range(numChainCVs): ctrlScale = rigScale * mainCtrlScaleFactor * ( 1.0 - (i * controlScaleIncrement)) ctrl = control.Control(prefix=prefix + '%d' % (i + 1), translateTo=chainCurveClusters[i], scale=ctrlScale, parent=self.rigmodule.controlsGrp, shape='sphere') chainControls.append(ctrl) # parent controls if fkParenting: for i in range(numChainCVs): if i == 0: continue pm.parent(chainControls[i].Off, chainControls[i - 1].C) # attach clusters for i in range(numChainCVs): pm.parent(chainCurveClusters[i], chainControls[i].C) # attach controls pm.parentConstraint(self.baseAttachGrp, chainControls[0].Off, mo=1) pm.hide(chainIk) pm.parent(chainIk, self.rigmodule.partsNoTransGrp) # add twist attribute twistAt = 'twist' pm.addAttr(chainControls[-1].C, ln=twistAt, k=1) pm.connectAttr(chainControls[-1].C + '.' + twistAt, chainIk + '.twist') # save class attribute self.chainCurve = chainCurve self.controlCurve = ctrlCurve if doDynamic: self.dynCurve = self.makeDynamic(prefix, baseRig, self.rigmodule, chainControls, chainCurveClusters) deform.blendShapeDeformer(self.dynCurve.getInputCurve(), [self.controlCurve], nodeName=prefix + 'BlendShape', frontOfChain=True) deform.blendShapeDeformer(self.chainCurve, [self.dynCurve.getOutputCurve()], nodeName=prefix + 'BlendShape', frontOfChain=True) else: deform.blendShapeDeformer(self.chainCurve, [self.controlCurve], nodeName=prefix + 'BlendShape', frontOfChain=True)
def __init__(self, neckJoints, headJnt, # neckCurve, prefix='neck', rigScale=1.0, baseRig=None ): """ :param neckJoints: list( str ), list of neck joints :param headJnt: str, head joint at the end of neck joint chain :param prefix: str, prefix to name new objects :param rigScale: float, scale factor for size of controls :param baseRig: instance of base.module.Base class :return: dictionary with rig module objects """ # :param neckCurve: str, name of neck cubic curve with 5 CVs matching neck joints # make rig module self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig) # make IK handle neckIk, effector, neckCurve = pm.ikHandle(n=prefix + '_IKH', sol='ikSplineSolver', sj=neckJoints[0], ee=neckJoints[-1], createCurve=True, numSpans=2) # rename curve pm.rename(neckCurve, prefix + '_CRV') # make neck curve clusters neckCurveCVs = pm.ls(neckCurve + '.cv[*]', fl=1) numNeckCVs = len(neckCurveCVs) neckCurveClusters = [] for i in range(numNeckCVs): cls = pm.cluster(neckCurveCVs[i], n=prefix + 'Cluster%d' % (i + 1))[1] neckCurveClusters.append(cls) pm.hide(neckCurveClusters) # parent neck curve pm.parent(neckCurve, self.rigmodule.partsNoTransGrp) # make attach groups self.bodyAttachGrp = pm.group(n=prefix + 'BodyAttach_GRP', em=1, p=self.rigmodule.partsGrp) self.baseAttachGrp = pm.group(n=prefix + 'BaseAttach_GRP', em=1, p=self.rigmodule.partsGrp) pm.delete(pm.pointConstraint(neckJoints[0], self.baseAttachGrp)) # make controls headMainCtrl = control.Control(prefix=prefix + 'HeadMain', translateTo=neckJoints[-1], rotateTo=headJnt, scale=rigScale * 5, parent=self.rigmodule.controlsGrp, shape='head') headLocalCtrl = control.Control(prefix=prefix + 'HeadLocal', translateTo=headJnt, rotateTo=headJnt, scale=rigScale * 4, parent=headMainCtrl.C, shape='circleX', lockChannels=['t']) middleCtrl = control.Control(prefix=prefix + 'Middle', translateTo=neckCurveClusters[2], rotateTo=neckJoints[2], scale=rigScale * 4, parent=self.rigmodule.controlsGrp, shape='circleX', lockChannels=['r']) # attach controls pm.parentConstraint(headMainCtrl.C, self.baseAttachGrp, middleCtrl.Off, sr=['x', 'y', 'z'], mo=1) pm.orientConstraint(self.baseAttachGrp, middleCtrl.Off, mo=1) pm.parentConstraint(self.bodyAttachGrp, headMainCtrl.Off, mo=1) # attach clusters pm.parent(neckCurveClusters[3:], headMainCtrl.C) pm.parent(neckCurveClusters[2], middleCtrl.C) pm.parent(neckCurveClusters[:2], self.baseAttachGrp) # attach joints pm.orientConstraint(headLocalCtrl.C, headJnt, mo=1) pm.hide(neckIk) pm.parent(neckIk, self.rigmodule.partsNoTransGrp) # setup IK twist pm.setAttr(neckIk + '.dTwistControlEnable', 1) pm.setAttr(neckIk + '.dWorldUpType', 4) pm.connectAttr(headMainCtrl.C + '.worldMatrix[0]', neckIk + '.dWorldUpMatrixEnd') pm.connectAttr(self.baseAttachGrp + '.worldMatrix[0]', neckIk + '.dWorldUpMatrix')
def __init__(self, spineJoints, rootJnt, prefix='spine', rigScale=1.0, baseRig=None, bodyLocator='', chestLocator='', pelvisLocator=''): """ :param spineJoints: list( str ), list of 6 spine joints :param rootJnt: str, root joint :param prefix: str, prefix to name new objects :param rigScale: float, scale factor for size of controls :param baseRig: instance of base.module.Base class :param bodyLocator: str, reference transform for position of body control :param chestLocator: str, reference transform for position of chest control :param pelvisLocator: str, reference transform for position of pelvis control :return: dictionary with rig module objects """ # :param spineCurve: str, name of spine cubic curve with 5 CVs matching first 5 spine joints # make rig module self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig) # control locator reference position if bodyLocator == '' or chestLocator == '' or pelvisLocator == '': pass bodyLocator, chestLocator, pelvisLocator = self.makeControlLocatorReferencePosition( spineJoints) # make IK handle spineIk, effector, spineCurve = pm.ikHandle( n=prefix + '_IKH', sol='ikSplineSolver', sj=spineJoints[0], ee=spineJoints[-1], # -2 createCurve=True, numSpans=2) # rename curve pm.rename(spineCurve, prefix + '_CRV') # make spine curve clusters spineCurveCVs = pm.ls(spineCurve + '.cv[*]', fl=1) numSpineCVs = len(spineCurveCVs) spineCurveClusters = [] for i in range(numSpineCVs): cls = pm.cluster(spineCurveCVs[i], n=prefix + 'Cluster%d' % (i + 1))[1] spineCurveClusters.append(cls) pm.hide(spineCurveClusters) # parent spine curve pm.parent(spineCurve, self.rigmodule.partsNoTransGrp) # make controls self.bodyCtrl = control.Control(prefix=prefix + 'Body', translateTo=bodyLocator, rotateTo=spineJoints[-1], scale=rigScale * 4, parent=self.rigmodule.controlsGrp, shape='spine') chestCtrl = control.Control(prefix=prefix + 'Chest', translateTo=chestLocator, rotateTo=spineJoints[-1], scale=rigScale * 6, parent=self.bodyCtrl.C, shape='chest') pelvisCtrl = control.Control(prefix=prefix + 'Pelvis', translateTo=pelvisLocator, rotateTo=pelvisLocator, scale=rigScale * 6, parent=self.bodyCtrl.C, shape='hip') middleCtrl = control.Control(prefix=prefix + 'Middle', translateTo=spineCurveClusters[2], scale=rigScale * 3, parent=self.bodyCtrl.C, shape='sphere', lockChannels=['r']) # attach controls pm.parentConstraint(chestCtrl.C, pelvisCtrl.C, middleCtrl.Off, sr=['x', 'y', 'z'], mo=1) # attach clusters pm.parent(spineCurveClusters[3:], chestCtrl.C) pm.parent(spineCurveClusters[2], middleCtrl.C) pm.parent(spineCurveClusters[:2], pelvisCtrl.C) # attach chest joint pm.orientConstraint(chestCtrl.C, spineJoints[-1], mo=1) # -2 pm.hide(spineIk) pm.parent(spineIk, self.rigmodule.partsNoTransGrp) # setup IK twist pm.setAttr(spineIk + '.dTwistControlEnable', 1) pm.setAttr(spineIk + '.dWorldUpType', 4) pm.connectAttr(chestCtrl.C + '.worldMatrix[0]', spineIk + '.dWorldUpMatrixEnd') pm.connectAttr(pelvisCtrl.C + '.worldMatrix[0]', spineIk + '.dWorldUpMatrix') # attach root joint pm.parentConstraint(pelvisCtrl.C, rootJnt, mo=1) # clean locators pm.delete(bodyLocator, chestLocator, pelvisLocator)
def makeIK(self, limbJoints, topFingerJoints, rigScale, rigmodule, useMetacarpalJoint=False, smartFootRoll=True, lSide='l_'): """ Do IK Arm/Leg, Metacarpal and Finger/Toe ctrl :param limbJoints: list(str), Arm/leg joints :param topFingerJoints: list(str), Metacarpal joints :param rigScale: float :param rigmodule: dict :return: """ metacarpalJointList = topFingerJoints topFngJntList = [] endFngJntList = [] for mtJnt in metacarpalJointList: if useMetacarpalJoint: fngJnt = pm.listRelatives(mtJnt, type='joint', children=True)[0] else: fngJnt = mtJnt fngEndJnt = joint.listHierarchy(mtJnt, withEndJoints=True)[-1] topFngJntList.append(fngJnt) endFngJntList.append(fngEndJnt) footRoolInstance = footRoll.FootRoll(limbJoints[0], limbJoints[2], topFngJntList, endFngJntList) footRollGrpList = footRoolInstance.getGroupList() pm.parent(footRollGrpList[-1], rigmodule.partsNoTransGrp) prefix = name.removeSuffix(limbJoints[2]) # make controls mainIKCtrl = control.Control(prefix=prefix + 'IK', translateTo=limbJoints[2], rotateTo=limbJoints[2], parent=rigmodule.controlsGrp, shape='circleY') midFngIKIndex = int( round(len(footRoolInstance.getIkFingerList()) / 2.0)) - 1 midFngJnt = footRoolInstance.getIkFingerList( )[midFngIKIndex].getJointList()[0] ballCtrl = control.Control(prefix=prefix + 'BallIK', translateTo=midFngJnt, rotateTo=midFngJnt, parent=rigmodule.controlsGrp, shape='circleZ') # pm.parentConstraint(mainIKCtrl.C, ballCtrl.getTop(), mo=True) pm.parentConstraint(mainIKCtrl.C, footRollGrpList[-1], mo=True) pm.parentConstraint(footRollGrpList[1], ballCtrl.getOffsetGrp(), mo=True) handIKOrientContraint = pm.orientConstraint(mainIKCtrl.C, limbJoints[2], mo=True)
def makeIK(self, limbJoints, topFingerJoints, rigScale, rigmodule, useMetacarpalJoint=False, smartFootRoll=True, lSide='l_'): """ Do IK Arm/Leg, Metacarpal and Finger/Toe ctrl :param limbJoints: list(str), Arm/leg joints :param topFingerJoints: list(str), Metacarpal joints :param rigScale: float :param rigmodule: dict :return: """ topFingerJoints = pm.ls(topFingerJoints) metacarpalJointList = topFingerJoints topFngJntList = [] endFngJntList = [] for mtJnt in metacarpalJointList: if useMetacarpalJoint: fngJnt = pm.listRelatives(mtJnt, type='joint', children=True)[0] else: fngJnt = mtJnt fngEndJnt = joint.listHierarchy(mtJnt, withEndJoints=True)[-1] topFngJntList.append(fngJnt) endFngJntList.append(fngEndJnt) footRoolInstance = footRoll.FootRoll(limbJoints[0], limbJoints[2], topFngJntList, endFngJntList) footRollGrpList = footRoolInstance.getGroupList() pm.parent(footRollGrpList[-1], rigmodule.partsNoTransGrp) prefix = name.removeSuffix(limbJoints[2]) # make controls mainIKCtrl = control.Control(prefix=prefix + 'IK', translateTo=limbJoints[2], rotateTo=limbJoints[2], parent=rigmodule.controlsGrp, shape='circleY') midFngIKIndex = int( round(len(footRoolInstance.getIkFingerList()) / 2.0)) - 1 midFngJnt = footRoolInstance.getIkFingerList( )[midFngIKIndex].getJointList()[0] ballCtrl = control.Control(prefix=prefix + 'BallIK', translateTo=midFngJnt, rotateTo=midFngJnt, parent=rigmodule.controlsGrp, shape='circleZ') # pm.parentConstraint(mainIKCtrl.C, ballCtrl.getTop(), mo=True) toeIkControls = [] for topToeJnt in topFingerJoints: toePrefix = name.removeSuffix(topToeJnt) toeEndJnt = pm.listRelatives(topToeJnt, ad=1, type='joint')[0] toeIkCtrl = control.Control(prefix=toePrefix, translateTo=toeEndJnt, scale=rigScale, parent=ballCtrl.C, shape='circleY') toeIkControls.append(toeIkCtrl) # constraint IK for i, toeIK in enumerate(footRoolInstance.getIkFingerList()): pm.parentConstraint(toeIkControls[i].C, toeIK) pm.parentConstraint(mainIKCtrl.C, footRollGrpList[-1], mo=True) pm.parentConstraint(footRollGrpList[1], ballCtrl.getOffsetGrp(), mo=True) handIKOrientContraint = pm.orientConstraint(mainIKCtrl.C, limbJoints[2], mo=True) ballRollGrp = footRollGrpList[0] toeTapGrp = footRollGrpList[1] tippyToeGrp = footRollGrpList[2] frontRollGrp, backRollGrp, innerRollGrp, outerRollGrp = footRollGrpList[ 3:-1] if smartFootRoll and frontRollGrp and ballRollGrp and innerRollGrp and outerRollGrp: rollAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(), 'roll', defaultValue=0, keyable=True, minValue=-120, maxValue=120) bendLimitAttr = attributes.addFloatAttribute( mainIKCtrl.getControl(), 'bendLimitAngle', defaultValue=45, keyable=False) straightAngleAttr = attributes.addFloatAttribute( mainIKCtrl.getControl(), 'toeStraightAngle', defaultValue=70, keyable=False) heelClampNode = pm.shadingNode('clamp', asUtility=True, n=prefix + '_heelRotClamp') pm.connectAttr(rollAttr, heelClampNode.inputR) heelClampNode.minR.set(-90) pm.connectAttr(heelClampNode.outputR, backRollGrp.rotateX) ballClampNode = pm.shadingNode('clamp', asUtility=True, n=prefix + '_zeroToBendClamp') pm.connectAttr(rollAttr, ballClampNode.inputR) # heelClampNode.maxR.set(90) # pm.connectAttr(ballClampNode.outputR, ballRollGrp.rotateX) bendToStraightClampNode = pm.shadingNode('clamp', asUtility=True, n=prefix + '_bendToStraightClamp') pm.connectAttr(bendLimitAttr, bendToStraightClampNode.minR) pm.connectAttr(straightAngleAttr, bendToStraightClampNode.maxR) pm.connectAttr(rollAttr, bendToStraightClampNode.inputR) bendToStraightSetRangeNode = pm.shadingNode( 'setRange', asUtility=True, n=prefix + '_bendToStraightPercent') pm.connectAttr(bendToStraightClampNode.minR, bendToStraightSetRangeNode.oldMinX) pm.connectAttr(bendToStraightClampNode.maxR, bendToStraightSetRangeNode.oldMaxX) bendToStraightSetRangeNode.maxX.set(1) pm.connectAttr(bendToStraightClampNode.inputR, bendToStraightSetRangeNode.valueX) rollMultDivNode = pm.shadingNode('multiplyDivide', asUtility=True, n=prefix + '_rollMultDiv') pm.connectAttr(bendToStraightSetRangeNode.outValueX, rollMultDivNode.input1X) pm.connectAttr(bendToStraightClampNode.inputR, rollMultDivNode.input2X) pm.connectAttr(rollMultDivNode.outputX, tippyToeGrp.rotateX) pm.connectAttr(bendLimitAttr, ballClampNode.maxR) zeroToBendSetRangeNode = pm.shadingNode('setRange', asUtility=True, n=prefix + '_zeroToBendPercent') pm.connectAttr(ballClampNode.minR, zeroToBendSetRangeNode.oldMinX) pm.connectAttr(ballClampNode.maxR, zeroToBendSetRangeNode.oldMaxX) zeroToBendSetRangeNode.maxX.set(1) pm.connectAttr(ballClampNode.inputR, zeroToBendSetRangeNode.valueX) invertPercentNode = pm.shadingNode('plusMinusAverage', asUtility=True, n=prefix + '_invertPercent') invertPercentNode.input1D[0].set(1) invertPercentNode.input1D[1].set(1) pm.connectAttr(bendToStraightSetRangeNode.outValueX, invertPercentNode.input1D[1]) invertPercentNode.operation.set(2) ballPercentMultDivNode = pm.shadingNode('multiplyDivide', asUtility=True, n=prefix + '_ballPercentMultDiv') pm.connectAttr(zeroToBendSetRangeNode.outValueX, ballPercentMultDivNode.input1X) pm.connectAttr(invertPercentNode.output1D, ballPercentMultDivNode.input2X) ballRollMultDivNode = pm.shadingNode('multiplyDivide', asUtility=True, n=prefix + '_ballRollMultDiv') pm.connectAttr(ballPercentMultDivNode.outputX, ballRollMultDivNode.input1X) pm.connectAttr(rollAttr, ballRollMultDivNode.input2X) pm.connectAttr(ballRollMultDivNode.outputX, ballRollGrp.rotateX) # Tilt tiltAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(), 'tilt', defaultValue=0, keyable=True, minValue=-90, maxValue=90) if lSide in prefix: common.setDrivenKey(tiltAttr, [-90, 0, 90], innerRollGrp.rotateZ, [90, 0, 0]) common.setDrivenKey(tiltAttr, [-90, 0, 90], outerRollGrp.rotateZ, [0, 0, -90]) else: common.setDrivenKey(tiltAttr, [-90, 0, 90], innerRollGrp.rotateZ, [-90, 0, 0]) common.setDrivenKey(tiltAttr, [-90, 0, 90], outerRollGrp.rotateZ, [0, 0, 90]) # lean leanAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(), 'lean', defaultValue=0, keyable=True, minValue=-90, maxValue=90) pm.connectAttr(leanAttr, ballRollGrp.rotateZ) # toeSpin toeSpinAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(), 'toeSpin', defaultValue=0, keyable=True, minValue=-90, maxValue=90) pm.connectAttr(toeSpinAttr, tippyToeGrp.rotateY) tippyToeGrp.rotateOrder.set(2) # toeWiggle toeWiggleAttr = attributes.addFloatAttribute( mainIKCtrl.getControl(), 'toeWiggle', defaultValue=0, keyable=True, minValue=-90, maxValue=90) pm.connectAttr(toeWiggleAttr, toeTapGrp.rotateX) return mainIKCtrl, footRoolInstance.getLimbIK(), [ [ballCtrl], toeIkControls ], footRoolInstance.getIkFingerList(), footRoolInstance.getIkBallList( ), handIKOrientContraint
def makeFK(self, limbJoints, topFingerJoints, rigScale, rigmodule): """ Do FK Arm/Leg, Metacarpal and Finger/Toe ctrl :param limbJoints: list(str), Arm/leg joints :param topFingerJoints: list(str), Metacarpal joints :param rigScale: float :param rigmodule: dict :return: """ topFingerJoints = pm.ls(topFingerJoints) limbCtrlInstanceList = [] handFeetCtrlInstanceList = [] limbCtrlConstraintList = [] handFeetCtrlConstraintList = [] # Arm/Leg for jnt in limbJoints: prefix = name.removeSuffix(jnt) parent = rigmodule.controlsGrp if len(limbCtrlInstanceList) > 0: parent = limbCtrlInstanceList[-1].C ctrl = control.Control(prefix=prefix, translateTo=jnt, rotateTo=jnt, parent=parent, shape='circleX') orientCnst = pm.orientConstraint(ctrl.getControl(), jnt, mo=True) limbCtrlConstraintList.append(orientCnst) limbCtrlInstanceList.append(ctrl) # Hand/Foot fingerFootFKOffsetGrp = pm.group(n='fingerFootFKOffset_GRP', em=True, p=rigmodule.controlsGrp) pm.parentConstraint(limbCtrlInstanceList[-1].C, fingerFootFKOffsetGrp, mo=True) for topJntList in topFingerJoints: fnjJntList = joint.listHierarchy(topJntList, withEndJoints=False) fingerJointList = [] for jnt in fnjJntList: prefix = name.removeSuffix(jnt) parent = fingerFootFKOffsetGrp # limbCtrlInstanceList[-1].C if len(fingerJointList) > 0: parent = fingerJointList[-1].C ctrl = control.Control(prefix=prefix, translateTo=jnt, rotateTo=jnt, parent=parent, shape='circleX') orientCnst = pm.orientConstraint(ctrl.getControl(), jnt) fingerJointList.append(ctrl) handFeetCtrlConstraintList.append(orientCnst) handFeetCtrlInstanceList.extend(fingerJointList) return limbCtrlInstanceList, limbCtrlConstraintList, handFeetCtrlInstanceList, handFeetCtrlConstraintList
def __init__(self, characterName='new', scale=1.0, mainCtrlAttachObj=''): """ :param characterName: str, character name :param scale: float, general scale of the rig :return: None """ # top group self.topGrp = pm.group(n=characterName + '_rig_GRP', em=1) self.rigCtrlLoc = pm.spaceLocator(n='rigCtrl_LOC') pm.rotate(self.rigCtrlLoc, [0, -90, 0], r=True, ws=True) # common.freezeTranform(self.rigCtrlLoc) pm.delete(pm.pointConstraint(mainCtrlAttachObj, self.rigCtrlLoc)) characterNameAt = 'characterName' sceneObjectTypeAt = 'sceneObjectType' for at in [characterNameAt, sceneObjectTypeAt]: pm.addAttr(self.topGrp, ln=at, dt='string') pm.setAttr(self.topGrp + '.' + characterNameAt, characterName, type='string', l=1) pm.setAttr(self.topGrp + '.' + sceneObjectTypeAt, self.sceneObjectType, type='string', l=1) # make global control self.globalCtrl = control.Control(prefix='global', scale=scale * 1, parent=self.topGrp, lockChannels=['t', 'r', 'v'], shape='circleY', doModify=False, doOffset=False) self.mainCtrl = control.Control(prefix='main', scale=scale * 1, parent=self.globalCtrl.getControl(), lockChannels=['s', 'v'], shape='move', doModify=False, doOffset=False) # model group self.modelGrp = pm.group(n='model_GRP', em=1, p=self.topGrp) self.fastModelGrp = pm.group(n='fastModel_GRP', em=1, p=self.modelGrp) self.mediumModelGrp = pm.group(n='mediumModel_GRP', em=1, p=self.modelGrp) self.mediumSlowGrp = pm.group(n='mediumSlowModel_GRP', em=1, p=self.modelGrp) self.slowModelGrp = pm.group(n='slowModel_GRP', em=1, p=self.modelGrp) self.allModelGrp = pm.group(n='allModel_GRP', em=1, p=self.modelGrp) self.rigModelGrp = pm.group(n='rigModel_GRP', em=1, p=self.modelGrp) pm.hide(self.rigModelGrp) # rig group self.rigGrp = pm.group(n='rig_GRP', em=1, p=self.mainCtrl.getControl()) # World Scale self.scaleLocator = pm.spaceLocator(n='scale_LOC') self.scaleLocator.inheritsTransform.set(0) self.scaleLocator.visibility.set(0) pm.connectAttr(self.globalCtrl.getControl().scale, self.scaleLocator.scale) pm.parent(self.scaleLocator, self.rigGrp) # make more groups self.jointsGrp = pm.group(n='skeleton_GRP', em=1, p=self.mainCtrl.getControl()) self.modulesGrp = pm.group(n='modules_GRP', em=1, p=self.mainCtrl.getControl()) self.rigCtrlGrp = pm.group(n='rigctrl_GRP', em=1, p=self.globalCtrl.getControl()) util.lock_and_hide_all(self.rigCtrlGrp) self.partGrp = pm.group(n='parts_GRP', em=1, p=self.rigGrp) pm.setAttr(self.partGrp + '.it', 0, l=1) # make halo self.haloCtrl = control.Control(prefix='halo', scale=1, parent=self.rigCtrlGrp, translateTo=mainCtrlAttachObj, rotateTo=self.rigCtrlLoc, lockChannels=['s'], shape='circleX', doOffset=True, doModify=True, objBBox=mainCtrlAttachObj) self.haloCtrl.getOffsetGrp().visibility.set(0) self.createHalo(mainCtrlAttachObj, 1) mainVisAts = ['modelVis', 'jointsVis'] mainDispAts = ['modelDisp', 'jointsDisp'] mainObjList = [self.modelGrp, self.jointsGrp] mainObjVisDvList = [1, 0] # add rig visibility connections for at, obj, dfVal in zip(mainVisAts, mainObjList, mainObjVisDvList): pm.addAttr(self.globalCtrl.getControl(), ln=at, at='enum', enumName='off:on', k=1, dv=dfVal) pm.setAttr(self.globalCtrl.getControl() + '.' + at, cb=1) pm.connectAttr(self.globalCtrl.getControl() + '.' + at, obj + '.v') # add rig display type connections for at, obj in zip(mainDispAts, mainObjList): pm.addAttr(self.globalCtrl.getControl(), ln=at, at='enum', enumName='normal:template:reference', k=1, dv=2) pm.setAttr(self.globalCtrl.getControl() + '.' + at, cb=1) pm.setAttr(obj + '.ove', 1) pm.connectAttr(self.globalCtrl.getControl() + '.' + at, obj + '.ovdt') # add rig display level connection displayLevel = 'displayLevel' levelGrp = [self.fastModelGrp, self.mediumModelGrp, self.slowModelGrp] pm.addAttr(self.globalCtrl.getControl(), ln=displayLevel, at='enum', enumName='fast:medium:slow', k=1, dv=1) pm.setAttr(self.globalCtrl.getControl() + '.' + displayLevel, cb=1) common.setDrivenKey(self.globalCtrl.getControl() + '.' + displayLevel, [0, 1, 2], levelGrp[0] + '.v', [1, 0, 0]) common.setDrivenKey(self.globalCtrl.getControl() + '.' + displayLevel, [0, 1, 2], levelGrp[1] + '.v', [0, 1, 0]) common.setDrivenKey(self.globalCtrl.getControl() + '.' + displayLevel, [0, 1, 2], levelGrp[2] + '.v', [0, 0, 1]) common.setDrivenKey(self.globalCtrl.getControl() + '.' + displayLevel, [0, 1, 2], self.mediumSlowGrp + '.v', [0, 1, 1]) # create display control self.displayCtrl = self.createDisplay(mainCtrlAttachObj, 1) self.ikfkCtrl = self.createIKFK(mainCtrlAttachObj, 1) pm.delete(self.rigCtrlLoc)
def __init__(self, cvList, skinGeo, prefix='face', headJnt='head_JNT', pointsNumber=5, scale=0.1, baseRig=None ): """ Build Facial Setup :param cvList: list of facial curves :param prefix: str, prefix to name new objects :param rigScale: float, scale factor for size of controls :param baseRig: instance of base.module.Base class """ cvList = pm.ls(cvList) skinGeo = pm.ls(skinGeo)[0] headJnt = pm.ls(headJnt)[0] # make rig module self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig) # attributes self.spacing = 1.0 / (pointsNumber - 1) # setup deformation # geo setup faceGeo = pm.duplicate(skinGeo, n=prefix + '_GEO')[0] pm.parent(faceGeo, self.rigmodule.partsNoTransGrp) deform.blendShapeDeformer(skinGeo, [faceGeo], 'face_BS', frontOfChain=True) # joints setup headFaceJnt = pm.duplicate(headJnt, renameChildren=True)[0] jointsDuplicates = pm.listRelatives(headFaceJnt, c=True, ad=True) jointsDuplicates.append(headFaceJnt) for jnt in jointsDuplicates: pm.rename(jnt, str(jnt.name()).replace('_JNT1', 'Face_JNT')) pm.parent(jointsDuplicates[-1], self.rigmodule.jointsGrp) pm.skinCluster(faceGeo, headFaceJnt) faceGeoSkincluster = skin.findRelatedSkinCluster(faceGeo) pm.skinCluster(faceGeo, edit=True, ai=cvList, ug=True) faceGeoSkincluster.useComponents.set(1) pm.parent(pm.ls('*_CRVBase'), self.rigmodule.partsNoTransGrp) fullLocList = [] fullClusterList = [] for cv in pm.ls(cvList): pm.rebuildCurve(cv, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=1, kt=0, s=4, d=1, tol=0.01) pm.rebuildCurve(cv, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=1, kep=1, kt=0, s=4, d=3, tol=0.01) pm.parent(cv, self.rigmodule.partsNoTransGrp) locList = self.setupCurve(cv, pointsNumber) fullLocList.extend(locList) # cluster chainCurveCVs = pm.ls(cv + '.cv[*]', fl=1) numChainCVs = len(chainCurveCVs) curveClusters = [] for i in range(numChainCVs): cls = pm.cluster(chainCurveCVs[i], n=str(cv.name()) + 'Cluster%d' % (i + 1))[1] curveClusters.append(cls) fullClusterList.extend(curveClusters) clusterGrp = pm.group(fullClusterList, n='faceCluster_GRP', p=self.rigmodule.partsNoTransGrp) follicleList = [] for loc, cls in zip(fullLocList, fullClusterList): ctrl = control.Control(str(loc.name()).replace('_LOC', ''), translateTo=loc, shape='sphere', parent=self.rigmodule.controlsGrp, doModify=True, scale=scale) follicle = followCtrl.makeControlFollowSkin(skinGeo, ctrl.getControl(), cls)[-1] follicleList.extend([follicle]) follicleGrp = pm.group(follicleList, n='faceFollicle_GRP', p=self.rigmodule.partsNoTransGrp)