def _editSpaceAttr(self, sCtrl, sType, lKeys, lIndex, lPlugs, iDefaultA, iDefaultB): iDefaultA_orig = cmds.addAttr('%s.spaceA%s' %(sCtrl, sType.upper()), q = True, dv = True) iDefaultB_orig = cmds.addAttr('%s.spaceB%s' %(sCtrl, sType.upper()), q = True, dv = True) sEnumName_orig = cmds.addAttr('%s.spaceA%s' %(sCtrl, sType.upper()), q = True, en = True) sEnumName_orig += ':' if iDefaultA == None: iDefaultA = iDefaultA_orig if iDefaultB == None: iDefaultB = iDefaultB_orig for i, sKey in enumerate(lKeys): sEnumName_orig += '%s=%s:' %(sKey, lIndex[i]) cmds.addAttr('%s.spaceA%s' %(sCtrl, sType.upper()), e = True, en = sEnumName_orig[:-1], dv = iDefaultA) cmds.addAttr('%s.spaceB%s' %(sCtrl, sType.upper()), e = True, en = sEnumName_orig[:-1], dv = iDefaultB) oCtrl = controls.oControl(sCtrl) sChoiceA = naming.oName(sType = 'choice', sSide = oCtrl.sSide, sPart = '%sSpaceA%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName sChoiceB = naming.oName(sType = 'choice', sSide = oCtrl.sSide, sPart = '%sSpaceB%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName for i, sPlug in enumerate(lPlugs): sPlug_space = self._spaceMatrix(sCtrl, sPlug, lKeys[i]) cmds.connectAttr(sPlug_space, '%s.input[%d]' %(sChoiceA, lIndex[i]), f = True) cmds.connectAttr(sPlug_space, '%s.input[%d]' %(sChoiceB, lIndex[i]), f = True)
def _addSpaceAttr(self, sCtrl, sType, lKeys, lIndex, lPlugs, iDefaultA, iDefaultB): oCtrl = controls.oControl(sCtrl) sEnumName = '' for i, sKey in enumerate(lKeys): sEnumName += '%s=%d:' %(sKey, lIndex[i]) if iDefaultA == None: iDefaultA = lIndex[0] if iDefaultB == None: iDefaultB = lIndex[0] attributes.addDivider([sCtrl], 'space%s' %sType.upper()) cmds.addAttr(sCtrl, ln = 'spaceA%s' %sType.upper(), nn = 'Space A %s' %sType.upper(), at = 'enum', keyable = True, en = sEnumName[:-1], dv = iDefaultA) cmds.addAttr(sCtrl, ln = 'spaceB%s' %sType.upper(), nn = 'Space B %s' %sType.upper(), at = 'enum', keyable = True, en = sEnumName[:-1], dv = iDefaultB) cmds.addAttr(sCtrl, ln = 'spaceBlend%s' %sType.upper(), at = 'float', keyable = True, min = 0, max = 10) sMultBlend = naming.oName(sType = 'multDoubleLinear', sSide = oCtrl.sSide, sPart = '%sSpaceBlendOutput%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName cmds.createNode('multDoubleLinear', name = sMultBlend) cmds.connectAttr('%s.spaceBlend%s'%(sCtrl, sType.upper()), '%s.input1' %sMultBlend) cmds.setAttr('%s.input2' %sMultBlend, 0.1, lock = True) sRvsBlend = naming.oName(sType = 'reverse', sSide = oCtrl.sSide, sPart = '%sSpaceBlendOutput%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName cmds.createNode('reverse', name = sRvsBlend) cmds.connectAttr('%s.output' %sMultBlend, '%s.inputX' %sRvsBlend) ## choice sChoiceA = naming.oName(sType = 'choice', sSide = oCtrl.sSide, sPart = '%sSpaceA%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName sChoiceB = naming.oName(sType = 'choice', sSide = oCtrl.sSide, sPart = '%sSpaceB%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName sWtAddMatrix = naming.oName(sType = 'wtAddMatrix', sSide = oCtrl.sSide, sPart = '%sSpace%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName cmds.createNode('choice', name = sChoiceA) cmds.createNode('choice', name = sChoiceB) cmds.createNode('wtAddMatrix', name = sWtAddMatrix) cmds.connectAttr('%s.spaceA%s' %(sCtrl, sType.upper()), '%s.selector' %sChoiceA) cmds.connectAttr('%s.spaceB%s' %(sCtrl, sType.upper()), '%s.selector' %sChoiceB) cmds.connectAttr('%s.output' %sChoiceA, '%s.wtMatrix[0].matrixIn' %sWtAddMatrix) cmds.connectAttr('%s.output' %sChoiceB, '%s.wtMatrix[1].matrixIn' %sWtAddMatrix) cmds.connectAttr('%s.outputX' %sRvsBlend, '%s.wtMatrix[0].weightIn' %sWtAddMatrix) cmds.connectAttr('%s.output' %sMultBlend, '%s.wtMatrix[1].weightIn' %sWtAddMatrix) sMultMatrix = naming.oName(sType = 'multMatrix', sSide = oCtrl.sSide, sPart = '%sSpace%s' %(oCtrl.sPart, sType.upper()), iIndex = oCtrl.iIndex).sName cmds.createNode('multMatrix', name = sMultMatrix) cmds.connectAttr('%s.matrixSum' %sWtAddMatrix, '%s.matrixIn[0]' %sMultMatrix) cmds.connectAttr('%s.worldInverseMatrix[0]' %oCtrl.sPasser, '%s.matrixIn[1]' %sMultMatrix) for i, sPlug in enumerate(lPlugs): sPlug_space = self._spaceMatrix(sCtrl, sPlug, lKeys[i]) cmds.connectAttr(sPlug_space, '%s.input[%d]' %(sChoiceA, lIndex[i]), f = True) cmds.connectAttr(sPlug_space, '%s.input[%d]' %(sChoiceB, lIndex[i]), f = True) lSkipTranslate = ['x', 'y', 'z'] lSkipRotate = ['x', 'y', 'z'] lSkipScale = ['x', 'y', 'z'] if sType == 't': lSkipTranslate = [] elif sType == 'r': lSkipRotate = [] else: lSkipScale = [] constraints.matrixConnect(sMultMatrix, [oCtrl.sSpace], 'matrixSum', lSkipTranslate = lSkipTranslate, lSkipRotate = lSkipRotate, lSkipScale = lSkipScale)
def __init__(self): super(cogRig, self).__init__() self._sBpJnt = naming.oName(sType='blueprint', sSide='m', sPart='cog').sName oCtrlLocal = controls.oControl( naming.oName(sType='ctrl', sSide='m', sPart='local').sName) self._sConnectInCtrl = oCtrlLocal.sOutput self._sConnectInJnt = 'rigJoints' self._bSub = True
def _spaceMatrix(self, sCtrl, sPlug, sKey): oCtrl = controls.oControl(sCtrl) sMultMatrix = naming.oName(sType = 'multMatrix', sSide = oCtrl.sSide, sPart = '%sSpace%sMatrix' %(oCtrl.sPart, sKey.title()), iIndex = oCtrl.iIndex).sName if not cmds.objExists(sMultMatrix): cmds.createNode('multMatrix', name = sMultMatrix) lPlugMatrix = cmds.getAttr(sPlug) lMatrixLocal = apiUtils.getLocalMatrixInMatrix(oCtrl.sSpace, lPlugMatrix, sNodeAttr = 'worldMatrix[0]') cmds.setAttr('%s.matrixIn[0]' %sMultMatrix, lMatrixLocal, type = 'matrix') attributes.connectAttrs([sPlug], ['%s.matrixIn[1]' %sMultMatrix], bForce = True) attributes.connectAttrs([self._sWorldMatrixRvsPlug], ['%s.matrixIn[2]' %sMultMatrix], bForce = True) return '%s.matrixSum' %sMultMatrix
def createComponent(self): super(baseFkOnIkSplineLimb, self).createComponent() iRotateOrder = self._iRotateOrder ## get reverse rotateOrder lRotateOrderRvs = [5, 3, 4, 1, 2, 0] iRotateOrderRvs = lRotateOrderRvs[iRotateOrder] ## top and bot ik control lCtrlBend = [] lCtrlBendName = [] lGrpRvs = [] lGrpRvsZero = [] lCtrlOffset = [] lCtrlCls = [] lCtrlClsEnd = [] sGrp_topRvsZero = transforms.createTransformNode(naming.oName(sType = 'zero', sSide = self._sSide, sPart = '%sTopBendRvs' %self._sName, iIndex = self._iIndex).sName, iRotateOrder = iRotateOrder, sParent = self._sComponentControls, sPos = self._lCtrls[-2]) sGrp_topRvs = transforms.createTransformNode(naming.oName(sType = 'null', sSide = self._sSide, sPart = '%sTopBendRvs' %self._sName, iIndex = self._iIndex).sName, iRotateOrder = iRotateOrderRvs, sParent = sGrp_topRvsZero, sPos = sGrp_topRvsZero) oCtrlTop = controls.create('%sTopIk' %self._sName, sSide = self._sSide, iIndex = self._iIndex, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sParent = sGrp_topRvs, sPos = sGrp_topRvs, sShape = 'cube', fSize = 6, lLockHideAttrs = ['sx', 'sy', 'sz', 'v']) oCtrlOffset_top = controls.create('%sTopIkOffset' %self._sName, sSide = self._sSide, iIndex = self._iIndex, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sParent = oCtrlTop.sOutput, sPos = oCtrlTop.sOutput, sShape = 'cube', fSize = 3, lLockHideAttrs = ['sx', 'sy', 'sz', 'v']) if self._bTop: lCtrlBend.append(oCtrlTop) lCtrlBendName.append('Top') lGrpRvs.append(sGrp_topRvs) lGrpRvsZero.append(sGrp_topRvsZero) lCtrlOffset.append(oCtrlOffset_top) lCtrlCls.append(self._lCtrls[-2]) lCtrlClsEnd.append(self._lCtrls[-1]) else: cmds.setAttr('%s.v' %oCtrlTop.sZero, 0) sGrp_botRvsZero = transforms.createTransformNode(naming.oName(sType = 'zero', sSide = self._sSide, sPart = '%sBotBendRvs' %self._sName, iIndex = self._iIndex).sName, iRotateOrder = iRotateOrder, sParent = self._sComponentControls, sPos = self._lCtrls[1]) sGrp_botRvs = transforms.createTransformNode(naming.oName(sType = 'null', sSide = self._sSide, sPart = '%sBotBendRvs' %self._sName, iIndex = self._iIndex).sName, iRotateOrder = iRotateOrderRvs, sParent = sGrp_botRvsZero, sPos = sGrp_botRvsZero) oCtrlBot = controls.create('%sBotIk' %self._sName, sSide = self._sSide, iIndex = self._iIndex, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sParent = sGrp_botRvs, sPos = sGrp_botRvs, sShape = 'cube', fSize = 6, lLockHideAttrs = ['sx', 'sy', 'sz', 'v']) oCtrlOffset_bot = controls.create('%sBotIkOffset' %self._sName, sSide = self._sSide, iIndex = self._iIndex, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sParent = oCtrlBot.sOutput, sPos = oCtrlBot.sOutput, sShape = 'cube', fSize = 3, lLockHideAttrs = ['sx', 'sy', 'sz', 'v']) if self._bBot: lCtrlBend.append(oCtrlBot) lCtrlBendName.append('Bot') lGrpRvs.append(sGrp_botRvs) lGrpRvsZero.append(sGrp_botRvsZero) lCtrlOffset.append(oCtrlOffset_bot) lCtrlCls.append(self._lCtrls[1]) lCtrlClsEnd.append(self._lCtrls[0]) else: cmds.setAttr('%s.v' %oCtrlBot.sZero, 0) ###### matrix connect, add multiply attrs lRotatePlug = [] for i, oCtrl in enumerate(lCtrlBend): attributes.addDivider([oCtrl.sName], 'RotMult') for j in range(1, len(self._lCtrls) - 1): cmds.addAttr(oCtrl.sName, ln = 'rotMult%02d' %j, at = 'float', min = 0, max = 1, dv = 1, keyable = True) sDecomposeMatrix = cmds.createNode('decomposeMatrix', name = naming.oName(sType = 'decomposeMatrix', sSide = self._sSide, sPart = '%s%sBend' %(self._sName, lCtrlBendName[i])).sName) sQuatToEuler = cmds.createNode('quatToEuler', name = naming.oName(sType = 'quatToEuler', sSide = self._sSide, sPart = '%s%sBend' %(self._sName, lCtrlBendName[i])).sName) cmds.connectAttr('%s.matrixOutputLocal' %oCtrl.sName, '%s.inputMatrix' %sDecomposeMatrix) cmds.connectAttr('%s.outputQuat' %sDecomposeMatrix, '%s.inputQuat' %sQuatToEuler) cmds.connectAttr('%s.ro' %oCtrl.sName, '%s.inputRotateOrder' %sQuatToEuler) sMult = cmds.createNode('multiplyDivide', name = naming.oName(sType = 'multiplyDivide', sSide = self._sSide, sPart = '%s%sBend' %(self._sName, lCtrlBendName[i])).sName) cmds.setAttr('%s.operation' %sMult, 2) sMultRvs = cmds.createNode('multiplyDivide', name = naming.oName(sType = 'multiplyDivide', sSide = self._sSide, sPart = '%s%sBendRvs' %(self._sName, lCtrlBendName[i])).sName) for sAxis in ['X', 'Y', 'Z']: cmds.connectAttr('%s.outputRotate%s' %(sQuatToEuler, sAxis), '%s.input1%s' %(sMult, sAxis)) cmds.setAttr('%s.input2%s' %(sMult, sAxis), len(self._lCtrls) - 2) cmds.connectAttr('%s.outputRotate%s' %(sQuatToEuler, sAxis), '%s.input1%s' %(sMultRvs, sAxis)) cmds.setAttr('%s.input2%s' %(sMultRvs, sAxis), -1) cmds.connectAttr('%s.output%s' %(sMultRvs, sAxis), '%s.rotate%s' %(lGrpRvs[i], sAxis)) lRotatePlug.append(sMult) ###### create individual bend control for each cluster (no top nor bot end cluster) sParent_ctrl = self._sComponentControls lGrpBend_top = [] lGrpBend_bot = [] for i, sCtrl in enumerate(self._lCtrls[1:len(self._lCtrls)-1]): lMultRot = [] lCtrlBendIndiv = [] if self._bTop: oCtrl_top = controls.create('%sTopBend' %self._sName, sSide = self._sSide, iIndex = i + 1, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sPos = sCtrl, sParent = sParent_ctrl, sShape = 'cube', fSize = 4, lLockHideAttrs = ['sx', 'sy', 'sz', 'v'] ) lGrpBend_top.append(oCtrl_top) sMultRot_top = cmds.createNode('multiplyDivide', name = naming.oName(sType = 'multiplyDivide', sSide = self._sSide, sPart = '%sTopBendMult' %self._sName, iIndex = i + 1).sName) lMultRot.append(sMultRot_top) lCtrlBendIndiv.append(oCtrl_top) if self._bBot: oCtrl_bot = controls.create('%sBotBend' %self._sName, sSide = self._sSide, iIndex = len(self._lCtrls) - i - 2, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sPos = sCtrl, sParent = sParent_ctrl, sShape = 'cube', fSize = 4, lLockHideAttrs = ['sx', 'sy', 'sz', 'v'] ) lGrpBend_bot.append(oCtrl_bot) sMultRot_bot = cmds.createNode('multiplyDivide', name = naming.oName(sType = 'multiplyDivide', sSide = self._sSide, sPart = '%sBotBendMult' %self._sName, iIndex = len(self._lCtrls) - i - 2).sName) lMultRot.append(sMultRot_bot) lCtrlBendIndiv.append(oCtrl_bot) for sAxis in ['X', 'Y', 'Z']: for j, sMultRot in enumerate(lMultRot): cmds.connectAttr('%s.output%s' %(lRotatePlug[j], sAxis), '%s.input1%s' %(sMultRot, sAxis)) cmds.connectAttr('%s.rotMult%02d' %(lCtrlBend[j].sName, i + 1), '%s.input2%s' %(sMultRot, sAxis)) cmds.connectAttr('%s.output%s' %(sMultRot, sAxis), '%s.rotate%s' %(lCtrlBendIndiv[j].lStacks[0], sAxis)) lGrpBend_bot.reverse() lGrpBend = [] for lCtrls in [lGrpBend_top, lGrpBend_bot]: if lCtrls: lGrpBend.append(lCtrls) for i, oCtrl in enumerate(lCtrls[1:]): oParent = lCtrls[i] cmds.parent(oCtrl.sZero, oParent.sOutput) ## add world matrix cmds.addAttr(oCtrl.sName, ln = 'matrixOutputBend', at = 'matrix') sMultMatrix = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrl.sSide, sPart = '%sMatrixOutputBend' %oCtrl.sPart, iIndex = oCtrl.iIndex).sName) cmds.connectAttr('%s.matrixOutputWorld' %oCtrl.sName, '%s.matrixIn[0]' %sMultMatrix) if i > 0: cmds.connectAttr('%s.matrixOutputBend' %oParent.sName, '%s.matrixIn[1]' %sMultMatrix) else: cmds.connectAttr('%s.matrixOutputWorld' %oParent.sName, '%s.matrixIn[1]' %sMultMatrix) cmds.connectAttr('%s.matrixSum' %sMultMatrix, '%s.matrixOutputBend' %oCtrl.sName) ## connect bend matrix to top and bot ik bend ctrl for i, lGrp in enumerate(lGrpBend): constraints.matrixConnect(lGrpBend[i][-1].sName, [lGrpRvsZero[i]], 'matrixOutputBend', lSkipScale = ['X', 'Y', 'Z']) ## get top bot ik bend ctrl translate matrix lMultMatrix = [] for i, oCtrl in enumerate(lCtrlBend): sGrpRvs = lGrpRvs[i] sMultMatrix = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = self._sSide, sPart = '%s%sMatrix' %(self._sName, lCtrlBendName[i]), iIndex = self._iIndex).sName) lMultMatrix.append(sMultMatrix) sGrpRvsZero = lGrpRvsZero[i] sGrpBend = lGrpBend[i][-1].sName oCtrlOffset = lCtrlOffset[i] sCtrlCls = lCtrlCls[i] oCtrlCls = controls.oControl(sCtrlCls) cmds.connectAttr('%s.matrixOutputWorld' %oCtrlOffset.sName, '%s.matrixIn[0]' %sMultMatrix) cmds.connectAttr('%s.matrixOutputWorld' %oCtrl.sName, '%s.matrixIn[1]' %sMultMatrix) cmds.connectAttr('%s.matrix' %sGrpRvs, '%s.matrixIn[2]' %sMultMatrix) cmds.connectAttr('%s.matrix' %sGrpRvsZero, '%s.matrixIn[3]' %sMultMatrix) sMultMatrixCls = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlCls.sSide, sPart = '%sMatrixOutput' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) lMatrix = apiUtils.getLocalMatrixInNode(oCtrlCls.sPasser, oCtrlOffset.sName, sNodeAttr = 'worldMatrix[0]', sParentAttr = 'worldMatrix[0]') lInverseMatrix = cmds.getAttr('%s.inverseMatrix' %oCtrlCls.sZero) cmds.setAttr('%s.matrixIn[0]' %sMultMatrixCls, lMatrix, type = 'matrix') cmds.connectAttr('%s.matrixSum' %sMultMatrix, '%s.matrixIn[1]' %sMultMatrixCls) cmds.setAttr('%s.matrixIn[2]' %sMultMatrixCls, lInverseMatrix, type = 'matrix') constraints.matrixConnect(sMultMatrixCls, [oCtrlCls.sPasser], 'matrixSum', lSkipTranslate = [], lSkipRotate = [], lSkipScale = ['x', 'y', 'z'], bForce = True) sCtrlClsEnd = lCtrlClsEnd[i] oCtrlClsEnd = controls.oControl(sCtrlClsEnd) sMultMatrixClsEnd = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlClsEnd.sSide, sPart = '%sMatrixOutput' %oCtrlClsEnd.sPart, iIndex = oCtrlClsEnd.iIndex).sName) lMatrix = apiUtils.getLocalMatrixInNode(oCtrlClsEnd.sPasser, oCtrlOffset.sName, sNodeAttr = 'worldMatrix[0]', sParentAttr = 'worldMatrix[0]') lInverseMatrix = cmds.getAttr('%s.inverseMatrix' %oCtrlClsEnd.sZero) cmds.setAttr('%s.matrixIn[0]' %sMultMatrixClsEnd, lMatrix, type = 'matrix') cmds.connectAttr('%s.matrixSum' %sMultMatrix, '%s.matrixIn[1]' %sMultMatrixClsEnd) cmds.setAttr('%s.matrixIn[2]' %sMultMatrixClsEnd, lInverseMatrix, type = 'matrix') constraints.matrixConnect(sMultMatrixClsEnd, [oCtrlClsEnd.sPasser], 'matrixSum', lSkipTranslate = [], lSkipRotate = [], lSkipScale = ['x', 'y', 'z'], bForce = True) ##### mid cls connect iNum = len(self._lCtrls[2:]) - 1 #### get top bot local translate lMinusTranslate = [] for i, sMatrix in enumerate(lMultMatrix): oNameMatrix = naming.oName(sMatrix) sGrpBend = lGrpBend[i][-1].sName oNameGrp = naming.oName(sGrpBend) oNameMatrix.sType = 'decomposeMatrix' oNameGrp.sType = 'decomposeMatrix' sDecomposeMatrix_ctrl = cmds.createNode('decomposeMatrix', name = oNameMatrix.sName) sDecomposeMatrix_grp = cmds.createNode('decomposeMatrix', name = oNameGrp.sName) cmds.connectAttr('%s.matrixSum' %sMatrix, '%s.inputMatrix' %sDecomposeMatrix_ctrl) cmds.connectAttr('%s.matrixOutputBend' %sGrpBend, '%s.inputMatrix' %sDecomposeMatrix_grp) oNameMatrix.sType = 'plusMinusAverage' oNameMatrix.sPart = '%sLocalTranslate' %oNameMatrix.sPart sMinus = cmds.createNode('plusMinusAverage', name = oNameMatrix.sName) cmds.setAttr('%s.operation' %sMinus, 2) cmds.connectAttr('%s.outputTranslate' %sDecomposeMatrix_ctrl, '%s.input3D[0]' %sMinus) cmds.connectAttr('%s.outputTranslate' %sDecomposeMatrix_grp, '%s.input3D[1]' %sMinus) lMinusTranslate.append(sMinus) for i, sCtrlCls in enumerate(self._lCtrls[2:iNum + 1]): oCtrlCls = controls.oControl(sCtrlCls) sAddMatrix = cmds.createNode('addMatrix', name = naming.oName(sType = 'addMatrix', sSide = oCtrlCls.sSide, sPart = '%sMatrixBend' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) sMultMatrixRotCls = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlCls.sSide, sPart = '%sMatrixBendRot' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) sMultMatrixCls = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlCls.sSide, sPart = '%sMatrixBend' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) cmds.connectAttr('%s.matrixSum' %sAddMatrix, '%s.matrixIn[0]' %sMultMatrixCls) lInverseMatrix = cmds.getAttr('%s.inverseMatrix' %oCtrlCls.sZero) cmds.setAttr('%s.matrixIn[1]' %sMultMatrixCls, lInverseMatrix, type = 'matrix') fWeight = (i + 1) / float(iNum) sPlus = cmds.createNode('plusMinusAverage', name = naming.oName(sType = 'plusMinusAverage', sSide = oCtrlCls.sSide, sPart = '%sTranslateOutput' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) for j, sPos in enumerate(lCtrlBendName): sMult = cmds.createNode('multiplyDivide', name = naming.oName(sType = 'multiplyDivide', sSide = oCtrlCls.sSide, sPart = '%s%sTranslate' %(oCtrlCls.sPart, sPos), iIndex = oCtrlCls.iIndex).sName) if sPos == 'Top': sGrpBend = lGrpBend[j][i + 1].sName for sAxis in ['X', 'Y', 'Z']: cmds.setAttr('%s.input2%s' %(sMult, sAxis), fWeight) else: sGrpBend = lGrpBend[j][-i - 2].sName for sAxis in ['X', 'Y', 'Z']: cmds.setAttr('%s.input2%s' %(sMult, sAxis), 1-fWeight) cmds.connectAttr('%s.matrixOutputBend' %sGrpBend, '%s.matrixIn[%d]' %(sAddMatrix, j)) cmds.connectAttr('%s.matrixOutputBend' %sGrpBend, '%s.matrixIn[%d]' %(sMultMatrixRotCls, j)) cmds.connectAttr('%s.output3D' %lMinusTranslate[j], '%s.input1' %sMult) cmds.connectAttr('%s.output' %sMult, '%s.input3D[%d]' %(sPlus, j)) sDecomposeMatrix = cmds.createNode('decomposeMatrix', name = naming.oName(sType = 'decomposeMatrix', sSide = oCtrlCls.sSide, sPart = '%sMatrixBend' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) cmds.connectAttr('%s.matrixSum' %sMultMatrixCls, '%s.inputMatrix' %sDecomposeMatrix) cmds.connectAttr('%s.outputTranslate' %sDecomposeMatrix, '%s.input3D[2]' %sPlus) sDecomposeMatrixRot = cmds.createNode('decomposeMatrix', name = naming.oName(sType = 'decomposeMatrix', sSide = oCtrlCls.sSide, sPart = '%sMatrixBendRot' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) cmds.connectAttr('%s.matrixSum' %sMultMatrixRotCls, '%s.inputMatrix' %sDecomposeMatrixRot) sQuatToEuler = cmds.createNode('quatToEuler', name = naming.oName(sType = 'quatToEuler', sSide = oCtrlCls.sSide, sPart = '%sMatrixBend' %oCtrlCls.sPart, iIndex = oCtrlCls.iIndex).sName) cmds.connectAttr('%s.outputQuat' %sDecomposeMatrixRot, '%s.inputQuat' %sQuatToEuler) cmds.connectAttr('%s.ro' %oCtrlCls.sPasser, '%s.inputRotateOrder' %sQuatToEuler) for sAxis in ['X', 'Y', 'Z']: cmds.connectAttr('%s.output3D%s' %(sPlus, sAxis.lower()), '%s.translate%s' %(oCtrlCls.sPasser, sAxis)) cmds.connectAttr('%s.outputRotate%s' %(sQuatToEuler, sAxis), '%s.rotate%s' %(oCtrlCls.sPasser, sAxis)) #### twist matrix connect lMultMatrixTwist = [] for i, sPos in enumerate(['Top', 'Bot']): sMultMatrixTwist = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = self._sSide, sPart = '%sMatrixTwist%s' %(self._sName, sPos), iIndex = self._iIndex).sName) lMatrix = apiUtils.getLocalMatrixInNode([self._lJnts[-1], self._lJnts[0]][i], [oCtrlTop, oCtrlBot][i].sName) cmds.setAttr('%s.matrixIn[0]' %sMultMatrixTwist, lMatrix, type = 'matrix') cmds.connectAttr('%s.matrixOutputWorld' %[oCtrlOffset_top, oCtrlOffset_bot][i].sName, '%s.matrixIn[1]' %sMultMatrixTwist) cmds.connectAttr('%s.matrixOutputWorld' %[oCtrlTop, oCtrlBot][i].sName, '%s.matrixIn[2]' %sMultMatrixTwist) cmds.connectAttr('%s.matrix' %[sGrp_topRvs, sGrp_botRvs][i], '%s.matrixIn[3]' %sMultMatrixTwist) cmds.connectAttr('%s.matrix' %[sGrp_topRvsZero, sGrp_botRvsZero][i], '%s.matrixIn[4]' %sMultMatrixTwist) lMultMatrixTwist.append(sMultMatrixTwist) cmds.setAttr('%s.dTwistControlEnable' %self._sIkHnd, 1) cmds.setAttr('%s.dWorldUpType' %self._sIkHnd, 4) for i, sMultMatrixTwist in enumerate(lMultMatrixTwist): cmds.connectAttr('%s.matrixSum' %sMultMatrixTwist, '%s.%s' %(self._sIkHnd, ['dWorldUpMatrixEnd', 'dWorldUpMatrix'][i])) ## hide controls for sCtrl in [self._lCtrls[0], self._lCtrls[1], self._lCtrls[-2], self._lCtrls[-1]]: oCtrl = controls.oControl(sCtrl) cmds.setAttr('%s.v' %oCtrl.sZero, 0, lock = True) sCtrlShape = naming.oName(sType = 'ctrl', sSide = self._sSide, sPart = self._sName, iIndex = self._iIndex).sName lCtrls = [oCtrlTop, oCtrlBot, oCtrlOffset_top, oCtrlOffset_bot] + lGrpBend_top + lGrpBend_bot lCtrlsName = [] for oCtrl in lCtrls: lCtrlsName.append(oCtrl.sName) lCtrlsName += self._lCtrls[2: len(self._lCtrls) - 2] controls.addCtrlShape(lCtrlsName, sCtrlShape, bVis = False) for i, sPos in enumerate(lCtrlBendName): cmds.addAttr(sCtrlShape, ln = '%sBendCtrlVis' %sPos.lower(), at = 'long', min = 0, max = 1, keyable = False) cmds.setAttr('%s.%sBendCtrlVis' %(sCtrlShape, sPos.lower()), channelBox = True) for oCtrl in lGrpBend[i]: cmds.connectAttr('%s.%sBendCtrlVis' %(sCtrlShape, sPos.lower()), '%s.v' %oCtrl.sZero) cmds.addAttr(sCtrlShape, ln = 'tweakCtrlVis', at = 'long', min = 0, max = 1, keyable = False) cmds.setAttr('%s.tweakCtrlVis' %sCtrlShape, channelBox = True) for sCtrl in self._lCtrls[2: len(self._lCtrls) - 2]: oCtrl = controls.oControl(sCtrl) cmds.connectAttr('%s.tweakCtrlVis' %sCtrlShape, '%s.v' %oCtrl.sZero) for i, sCtrl in enumerate([oCtrlTop.sName, oCtrlBot.sName]): oCtrlOffset = [oCtrlOffset_top, oCtrlOffset_bot][i] cmds.addAttr(sCtrl, ln = 'offsetCtrlVis', at = 'long', min = 0, max = 1, keyable = False) cmds.setAttr('%s.offsetCtrlVis' %sCtrl, channelBox = True) cmds.connectAttr('%s.offsetCtrlVis' %sCtrl, '%s.v' %oCtrlOffset.sZero) ## write component info self._writeGeneralComponentInfo('baseFkOnIkSplineLimb', self._lJnts, lCtrlsName, self._lBindJnts, self._lBindRootJnts) self._getComponentInfo(self._sComponentMaster)
def createComponent(self): super(baseIkOnFkSplineLimb, self).createComponent() ## create temp controller sCrv = cmds.curve(p=[[0,0,0], [1,0,0]], k=[0,1], d=1, per = False, name = 'TEMP_CRV') sCtrlShape = naming.oName(sType = 'ctrl', sSide = self._sSide, sPart = self._sName, iIndex = self._iIndex).sName controls.addCtrlShape([sCrv], sCtrlShape, bVis = False, dCtrlShapeInfo = None, bTop = False) cmds.addAttr(sCtrlShape, ln = 'bendCtrlVis', at = 'long', min = 0, max = 1, keyable = False) cmds.setAttr('%s.bendCtrlVis' %sCtrlShape, channelBox = True) ## top bot control lCtrls = [] lRotateOrder = [] lParts = [] for sBpCtrl in self._lBpCtrls: oName = naming.oName(sBpCtrl) iRotateOrder = cmds.getAttr('%s.ro' %sBpCtrl) oCtrl = controls.create('%sIk' %oName.sPart, sSide = oName.sSide, iIndex = oName.iIndex, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sParent = self._sComponentControls, sPos = sBpCtrl, sShape = 'cube', fSize = 6, lLockHideAttrs = ['sx', 'sy', 'sz', 'v']) lCtrls.append(oCtrl) lRotateOrder.append(iRotateOrder) lParts.append(oName.sPart) cmds.setAttr('%s.v' %lCtrls[1].sZero, self._bRvsBend) ## bend controls lCtrls_bend = [] lCtrls_bendRvs = [] iBend = 1 iBendRvs = len(self._lCtrls) - 3 for i, sCtrl_tweak in enumerate(self._lCtrls): if i != 1 and i != len(self._lCtrls) - 2: if i < len(self._lCtrls) - 1: oCtrl_bend = controls.create('%sBend' %self._sName, sSide = oName.sSide, iIndex = iBend, iStacks = self._iStacks, bSub = True, iRotateOrder = lRotateOrder[0], sParent = self._sComponentControls, sShape = 'square', fSize = 6, lLockHideAttrs = self._lLockHideAttrs) cmds.delete(cmds.pointConstraint(sCtrl_tweak, oCtrl_bend.sZero, mo = False)) cmds.delete(cmds.orientConstraint(lCtrls[1].sName, oCtrl_bend.sZero, mo = False)) lCtrls_bend.append(oCtrl_bend) iBend += 1 if self._bRvsBend: if i > 0: oCtrl_bendRvs = controls.create('%sBendRvs' %self._sName, sSide = oName.sSide, iIndex = iBendRvs, iStacks = self._iStacks, bSub = True, iRotateOrder = lRotateOrder[1], sParent = self._sComponentControls, sShape = 'square', fSize = 6, lLockHideAttrs = self._lLockHideAttrs) cmds.delete(cmds.pointConstraint(sCtrl_tweak, oCtrl_bendRvs.sZero, mo = False)) cmds.delete(cmds.orientConstraint(lCtrls[0].sName, oCtrl_bendRvs.sZero, mo = False)) lCtrls_bendRvs.append(oCtrl_bendRvs) iBendRvs -= 1 lCtrls_bend.reverse() lBends = [] lBends.append(lCtrls_bend) cmds.connectAttr('%s.bendCtrlVis' %sCtrlShape, '%s.v' %lCtrls_bend[-1].sZero) if lCtrls_bendRvs: lBends.append(lCtrls_bendRvs) cmds.addAttr(sCtrlShape, ln = 'bendRvsCtrlVis', at = 'long', min = 0, max = 1, keyable = False) cmds.setAttr('%s.bendRvsCtrlVis' %sCtrlShape, channelBox = True) cmds.connectAttr('%s.bendRvsCtrlVis' %sCtrlShape, '%s.v' %lCtrls_bendRvs[-1].sZero) lMultMatrix = [] for iPos, lCtrls_bendFk in enumerate(lBends): sMultMatrix = naming.oName(sType = 'multMatrix', sSide = self._sSide, sPart = '%sBend%sMatrix' %(self._sName, ['', 'Rvs'][iPos]), iIndex = self._iIndex).sName cmds.createNode('multMatrix', name = sMultMatrix) lMultMatrix.append(sMultMatrix) for i, oCtrl in enumerate(lCtrls_bendFk[:-1]): cmds.parent(oCtrl.sZero, lCtrls_bendFk[i+1].sOutput) cmds.connectAttr(oCtrl.sMatrixOutputWorldPlug, '%s.matrixIn[%d]' %(sMultMatrix, i+1)) cmds.connectAttr(lCtrls_bendFk[-1].sMatrixOutputWorldPlug, '%s.matrixIn[%d]' %(sMultMatrix, i+2)) ## connect ik ctrl lMatrixLocal = apiUtils.getLocalMatrixInNode(lCtrls[iPos].sName, lCtrls_bendFk[0].sName) cmds.setAttr('%s.matrixIn[0]' %sMultMatrix, lMatrixLocal, type = 'matrix') cmds.connectAttr('%s.inverseMatrix' %lCtrls[iPos].sZero, '%s.matrixIn[%d]' %(sMultMatrix, i + 3)) constraints.matrixConnect(sMultMatrix, [lCtrls[iPos].sPasser], 'matrixSum', lSkipScale = ['X', 'Y', 'Z']) cmds.addAttr(sCtrlShape, ln = 'tweakCtrlVis', at = 'long', min = 0, max = 1, keyable = False) cmds.setAttr('%s.tweakCtrlVis' %sCtrlShape, channelBox = True) ## connect tweak controls for i, sCtrl_tweak in enumerate(self._lCtrls): oCtrl_tweak = controls.oControl(sCtrl_tweak) if i < 2 or i > len(self._lCtrls) - 3: if i < 2: oCtrl_ik = lCtrls[1] else: oCtrl_ik = lCtrls[0] cmds.delete(cmds.orientConstraint(oCtrl_ik.sName, oCtrl_tweak.sZero, mo = False)) sMultMatrix = naming.oName(sType = 'multMatrix', sSide = oCtrl_tweak.sSide, sPart = '%sMatrix' %oCtrl_tweak.sPart, iIndex = oCtrl_tweak.iIndex).sName cmds.createNode('multMatrix', name = sMultMatrix) self._connectCtrlToNode(oCtrl_tweak, oCtrl_ik.sName, oCtrl_ik.sMatrixOutputWorldPlug, sMultMatrix) cmds.setAttr('%s.v' %oCtrl_tweak.sZero, 0, lock = True) else: fWeight = 1 - ((i-1) / float(len(self._lCtrls)-3)) sOrient = cmds.orientConstraint(lCtrls[0].sName, lCtrls[1].sName, oCtrl_tweak.sZero, mo = False)[0] cmds.setAttr('%s.interpType' %sOrient, 2) cmds.setAttr('%s.%sW0' %(sOrient, lCtrls[0].sName), fWeight) cmds.setAttr('%s.%sW1' %(sOrient, lCtrls[1].sName), 1 - fWeight) cmds.delete(sOrient) cmds.addAttr(oCtrl_tweak.sName, ln = 'weight', at = 'float', min = 0, max = 1, dv = fWeight, keyable = True) lMatrixPasser_01 = apiUtils.getLocalMatrixInNode(oCtrl_tweak.sName, lCtrls[0].sName) lMatrixPasser_02 = apiUtils.getLocalMatrixInNode(oCtrl_tweak.sName, lCtrls[1].sName) sMultMatrixTop = naming.oName(sType = 'multMatrix', sSide = oCtrl_tweak.sSide, sPart = '%sMatrix%s%s' %(oCtrl_tweak.sPart, lParts[0][0].upper(), lParts[0][1:]), iIndex = oCtrl_tweak.iIndex).sName cmds.createNode('multMatrix', name = sMultMatrixTop) sMultMatrixBot = naming.oName(sType = 'multMatrix', sSide = oCtrl_tweak.sSide, sPart = '%sMatrix%s%s' %(oCtrl_tweak.sPart, lParts[1][0].upper(), lParts[1][1:]), iIndex = oCtrl_tweak.iIndex).sName cmds.createNode('multMatrix', name = sMultMatrixBot) cmds.setAttr('%s.matrixIn[0]' %sMultMatrixTop, lMatrixPasser_01, type = 'matrix') cmds.setAttr('%s.matrixIn[0]' %sMultMatrixBot, lMatrixPasser_02, type = 'matrix') cmds.connectAttr(lCtrls[0].sMatrixOutputWorldPlug, '%s.matrixIn[1]' %sMultMatrixTop) cmds.connectAttr(lCtrls[1].sMatrixOutputWorldPlug, '%s.matrixIn[1]' %sMultMatrixBot) cmds.connectAttr('%s.inverseMatrix' %oCtrl_tweak.sZero, '%s.matrixIn[2]' %sMultMatrixTop) cmds.connectAttr('%s.inverseMatrix' %oCtrl_tweak.sZero, '%s.matrixIn[2]' %sMultMatrixBot) sRvs = naming.oName(sType = 'reverse', sSide = oCtrl_tweak.sSide, sPart = '%sMatrixWeight' %oCtrl_tweak.sPart, iIndex = oCtrl_tweak.iIndex).sName cmds.createNode('reverse', name = sRvs) cmds.connectAttr('%s.weight' %oCtrl_tweak.sName, '%s.inputX' %sRvs) sWtAddMatrix = naming.oName(sType = 'wtAddMatrix', sSide = oCtrl_tweak.sSide, sPart = '%sMatrix' %oCtrl_tweak.sPart, iIndex = oCtrl_tweak.iIndex).sName cmds.createNode('wtAddMatrix', name = sWtAddMatrix) cmds.connectAttr('%s.matrixSum' %sMultMatrixTop, '%s.wtMatrix[0].matrixIn' %sWtAddMatrix) cmds.connectAttr('%s.matrixSum' %sMultMatrixBot, '%s.wtMatrix[1].matrixIn' %sWtAddMatrix) cmds.connectAttr('%s.weight' %oCtrl_tweak.sName, '%s.wtMatrix[0].weightIn' %sWtAddMatrix) cmds.connectAttr('%s.outputX' %sRvs, '%s.wtMatrix[1].weightIn' %sWtAddMatrix) constraints.matrixConnect(sWtAddMatrix, [oCtrl_tweak.sPasser], 'matrixSum', lSkipScale = ['X', 'Y', 'Z']) cmds.connectAttr('%s.tweakCtrlVis' %sCtrlShape, '%s.v' %oCtrl_tweak.sZero) ## fk jnt if self._bFkJnt: for i, sJnt in enumerate([self._lJnts[-1], self._lJnts[0]]): oCtrl = lCtrls[i] oBpCtrl = naming.oName(self._lBpCtrls[i]) oJntFk = naming.oName(sType = 'jnt', sSide = oBpCtrl.sSide, sPart = oBpCtrl.sPart, iIndex = oBpCtrl.iIndex) sJntFk = joints.createJntOnExistingNode(sJnt, sJnt, oJntFk.sName, sParent = sJnt) cmds.delete(cmds.orientConstraint(oCtrl.sName, sJntFk, mo = False)) cmds.makeIdentity(sJntFk, apply = True, t = 1, r = 1, s = 1) ## parent bind jnt if self._bBind: oJntFk.sType = 'bindJoint' sJntBind = [self._lBindJnts[-1], self._lBindJnts[0]][i] sJntBindFk = joints.createJntOnExistingNode(sJntFk, sJntFk, oJntFk.sName, sParent = sJntBind) createDriveJoints.tagBindJoint(sJntBindFk, sJntFk) ## create control iRotateOrder = cmds.getAttr('%s.ro' %sJnt) oCtrlFk = controls.create('%sFk' %oBpCtrl.sPart, sSide = oBpCtrl.sSide, iIndex = oBpCtrl.iIndex, iStacks = self._iStacks, bSub = True, iRotateOrder = iRotateOrder, sParent = self._sComponentControls, sPos = [self._lJnts[-1], self._lJnts[0]][i], sShape = 'cube', fSize = 6, lLockHideAttrs = ['sx', 'sy', 'sz', 'v']) cmds.delete(cmds.orientConstraint(oCtrl.sName, oCtrlFk.sZero, mo = False)) sMultMatrix_t = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlFk.sSide, sPart = '%sTranslate' %oCtrlFk.sPart, iIndex = oCtrlFk.iIndex).sName) lMatrixPasser = apiUtils.getLocalMatrixInNode(oCtrlFk.sName, [self._lJnts[-1], self._lJnts[0]][i]) cmds.setAttr('%s.matrixIn[0]' %sMultMatrix_t, lMatrixPasser, type = 'matrix') cmds.connectAttr('%s.outputMatrixLocal%03d' %(self._sComponentMaster, [len(self._lJnts) - 1, 0][i]), '%s.matrixIn[1]' %sMultMatrix_t) cmds.connectAttr('%s.inverseMatrix' %oCtrlFk.sZero, '%s.matrixIn[2]' %sMultMatrix_t) sMultMatrix_r = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlFk.sSide, sPart = '%sRotate' %oCtrlFk.sPart, iIndex = oCtrlFk.iIndex).sName) lMatrixPasser = apiUtils.getLocalMatrixInNode(oCtrlFk.sName, oCtrl.sName) cmds.setAttr('%s.matrixIn[0]' %sMultMatrix_r, lMatrixPasser, type = 'matrix') cmds.connectAttr(oCtrl.sMatrixOutputWorldPlug, '%s.matrixIn[1]' %sMultMatrix_r) cmds.connectAttr('%s.inverseMatrix' %oCtrlFk.sZero, '%s.matrixIn[2]' %sMultMatrix_r) constraints.matrixConnect(sMultMatrix_t, [oCtrlFk.sPasser], 'matrixSum', lSkipScale = ['X', 'Y', 'Z'], lSkipRotate = ['X', 'Y', 'Z']) constraints.matrixConnect(sMultMatrix_r, [oCtrlFk.sPasser], 'matrixSum', lSkipScale = ['X', 'Y', 'Z'], lSkipTranslate = ['X', 'Y', 'Z']) cmds.addAttr(oCtrl.sName, ln = 'fkCtrlVis', at = 'long', min = 0, max = 1, dv = 0) cmds.setAttr('%s.fkCtrlVis' %oCtrl.sName, channelBox = True) cmds.connectAttr('%s.fkCtrlVis' %oCtrl.sName, '%s.v' %oCtrlFk.sZero) sMultMatrix = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlFk.sSide, sPart = '%sOutputJntMatrix' %oCtrlFk.sPart, iIndex = oCtrlFk.iIndex).sName) cmds.connectAttr(oCtrlFk.sMatrixOutputWorldPlug, '%s.matrixIn[0]' %sMultMatrix) sInverseMatrix = cmds.createNode('inverseMatrix', name = naming.oName(sType = 'inverseMatrix', sSide = oCtrlFk.sSide, sPart = '%sOutputJntMatrix' %oCtrlFk.sPart, iIndex = oCtrlFk.iIndex).sName) cmds.connectAttr('%s.outputMatrixLocal%03d' %(self._sComponentMaster, [len(self._lJnts) - 1, 0][i]), '%s.inputMatrix' %sInverseMatrix) cmds.connectAttr('%s.outputMatrix' %sInverseMatrix, '%s.matrixIn[1]' %sMultMatrix) constraints.matrixConnectJnt(sMultMatrix, sJntFk, 'matrixSum', lSkipTranslate = [], lSkipRotate = [], lSkipScale = ['X', 'Y', 'Z'], bForce = True) ## component info cmds.addAttr(self._sComponentMaster, ln = 's%sFkCtrl' %['Top', 'Bot'][i], dt = 'string') cmds.addAttr(self._sComponentMaster, ln = 's%sFkBindJnt' %['Top', 'Bot'][i], dt = 'string') cmds.addAttr(self._sComponentMaster, ln = 'outputMatrixLocal%sFk' %['Top', 'Bot'][i], dt = 'matrix') cmds.addAttr(self._sComponentMaster, ln = 'outputMatrixWorld%sFk' %['Top', 'Bot'][i], dt = 'matrix') cmds.setAttr('%s.s%sFkCtrl' %(self._sComponentMaster, ['Top', 'Bot'][i]), oCtrlFk.sName, type = 'string') if self._bBind: sBind = sJntBindFk else: sBind = '' cmds.setAttr('%s.s%sFkBindJnt' %(self._sComponentMaster, ['Top', 'Bot'][i]), sBind, type = 'string') sMultMatrixLocal = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlFk.sSide, sPart = '%sOutputMatrixLocal' %oCtrlFk.sPart, iIndex = oCtrlFk.iIndex).sName) sMultMatrixWorld = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = oCtrlFk.sSide, sPart = '%sOutputMatrixWorld' %oCtrlFk.sPart, iIndex = oCtrlFk.iIndex).sName) cmds.connectAttr('%s.matrix' %sJntFk, '%s.matrixIn[0]' %sMultMatrixLocal) cmds.connectAttr('%s.matrix' %sJntFk, '%s.matrixIn[0]' %sMultMatrixWorld) cmds.connectAttr('%s.outputMatrixLocal%03d'%(self._sComponentMaster, [len(self._lJnts) - 1, 0][i]), '%s.matrixIn[1]' %sMultMatrixLocal) cmds.connectAttr('%s.outputMatrixWorld%03d'%(self._sComponentMaster, [len(self._lJnts) - 1, 0][i]), '%s.matrixIn[1]' %sMultMatrixWorld) cmds.connectAttr('%s.matrixSum' %sMultMatrixLocal, '%s.outputMatrixLocal%sFk' %(self._sComponentMaster, ['Top', 'Bot'][i])) cmds.connectAttr('%s.matrixSum' %sMultMatrixWorld, '%s.outputMatrixWorld%sFk' %(self._sComponentMaster, ['Top', 'Bot'][i])) #### twist matrix connect lMultMatrixTwist = [] for i, sPos in enumerate(['Top', 'Bot']): sMultMatrixTwist = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = self._sSide, sPart = '%sMatrixTwist%s' %(self._sName, sPos), iIndex = self._iIndex).sName) lMatrix = apiUtils.getLocalMatrixInNode([self._lJnts[-1], self._lJnts[0]][i], lCtrls[i].sName) cmds.setAttr('%s.matrixIn[0]' %sMultMatrixTwist, lMatrix, type = 'matrix') cmds.connectAttr(lCtrls[i].sMatrixOutputWorldPlug, '%s.matrixIn[1]' %sMultMatrixTwist) lMultMatrixTwist.append(sMultMatrixTwist) cmds.setAttr('%s.dTwistControlEnable' %self._sIkHnd, 1) cmds.setAttr('%s.dWorldUpType' %self._sIkHnd, 4) for i, sMultMatrixTwist in enumerate(lMultMatrixTwist): cmds.connectAttr('%s.matrixSum' %sMultMatrixTwist, '%s.%s' %(self._sIkHnd, ['dWorldUpMatrixEnd', 'dWorldUpMatrix'][i])) self._lTweakCtrls = self._lCtrls self._sTopCtrl = lCtrls[0].sName self._sBotCtrl = lCtrls[1].sName lCtrls_bend.reverse() lCtrls_bendRvs.reverse() self._lBendCtrls = [] for oCtrl in lCtrls_bend: self._lBendCtrls.append(oCtrl.sName) self._lBendRvsCtrls = [] for oCtrl in lCtrls_bendRvs: self._lBendRvsCtrls.append(oCtrl.sName) self._lCtrls = [self._sTopCtrl] + [self._sBotCtrl] + self._lBendCtrls + self._lBendRvsCtrls + self._lTweakCtrls controls.addCtrlShape(self._lCtrls, sCtrlShape, bVis = False, dCtrlShapeInfo = None, bTop = False) cmds.delete(sCrv) ## write component info self._writeGeneralComponentInfo('baseIkOnFkSplineLimb', self._lJnts, self._lCtrls, self._lBindJnts, self._lBindRootJnts) sBendCtrls = componentInfo.composeListToString(self._lBendCtrls) sBendRvsCtrls = componentInfo.composeListToString(self._lBendRvsCtrls) sTweakCtrls = componentInfo.composeListToString(self._lTweakCtrls) lValues = [self._sTopCtrl, self._sBotCtrl, sBendCtrls, sBendRvsCtrls, sTweakCtrls] for i, sAttr in enumerate(['sTopCtrl', 'sBotCtrl', 'lBendCtrls', 'lBendRvsCtrls', 'lTweakCtrls']): cmds.addAttr(self._sComponentMaster, ln = sAttr, dt = 'string') cmds.setAttr('%s.%s' %(self._sComponentMaster, sAttr), lValues[i], lock = True, type = 'string') self._getComponentInfo(self._sComponentMaster)
def create(self): sGrp = transforms.createTransformNode( naming.oName(sType='grp', sSide=self._sSide, sPart='%s%sRig' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sConnectInJnt) sGrpCtrl = transforms.createTransformNode( naming.oName(sType='grp', sSide=self._sSide, sPart='%s%sCtrl' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sConnectInCtrl) sGrpNode = transforms.createTransformNode( naming.oName(sType='grp', sSide=self._sSide, sPart='%s%sNode' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sGrpNode) ## twist locs sMatcherBot, sOffsetBot = transforms.createTransformMatcherNode( self._lBpJnts[0], sParent=None) sMatcherTop, sOffsetTop = transforms.createTransformMatcherNode( self._lBpJnts[-1], sParent=None) ## create curve lBot = [] lTop = [] if self._bOrientTop: lTop.append(sMatcherTop) if self._bOrientBot: lBot.append(sMatcherBot) sCrv = curves.createCurveOnNodes(naming.oName( sType='curve', sSide=self._sSide, sPart='%s%s' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lBot + self._lBpCtrls + lTop, iDegree=3, sParent=sGrpNode) cmds.setAttr('%s.v' % sCrv, 0) ## create joints sParent_jnt = sGrp lJnts = [] for i, sBpJnt in enumerate(self._lBpJnts): oJntName = naming.oName(sBpJnt) oJntName.sType = 'jnt' oJntName.sPart = '%s%s' % (oJntName.sPart, self._sName) sJnt = joints.createJntOnExistingNode(sBpJnt, sBpJnt, oJntName.sName, sParent=sParent_jnt) lJnts.append(sJnt) sParent_jnt = sJnt ## create cluster lClsHnds = curves.clusterCurve(sCrv) ## create contorls lCtrls = [] if not self._lBpCtrls: self._lBpCtrls = self._lBpJnts for i, sJnt in enumerate(self._lBpCtrls): oJntName = naming.oName(sJnt) iRotateOrder = cmds.getAttr('%s.ro' % sJnt) oCtrl = controls.create('%s%s' % (oJntName.sPart, self._sName), sSide=oJntName.sSide, iIndex=oJntName.iIndex, iStacks=self._iStacks, bSub=self._bSub, sParent=sGrpCtrl, sPos=sJnt, iRotateOrder=iRotateOrder, sShape='cube', fSize=8, lLockHideAttrs=self._lLockHideAttrs) if self._lCtrlOrient: transforms.worldOrientTransform(oCtrl.sPasser, sFoward=self._lCtrlOrient[0], sUp=self._lCtrlOrient[1]) if self._bOrientBot: cmds.parent(lClsHnds[i + 1], oCtrl.sOutput) if i == 0: cmds.parent(lClsHnds[0], oCtrl.sOutput) else: cmds.parent(lClsHnds[i], oCtrl.sOutput) if self._bOrientTop: if i == len(self._lBpCtrls) - 1: cmds.parent(lClsHnds[-1], oCtrl.sOutput) lCtrls.append(oCtrl.sName) ## rebuild curve curves.rebuildCurveWithSameCvNum(sCrv) ## spline ik handle sIkHnd = naming.oName(sType='ikHandle', sSide=self._sSide, sPart='%s%s' % (self._sPart, self._sName), iindex=self._iIndex).sName cmds.ikHandle(sj=lJnts[0], ee=lJnts[-1], sol='ikSplineSolver', c=sCrv, ccv=False, pcv=False, name=sIkHnd) cmds.makeIdentity(lJnts, apply=True, t=1, r=1, s=1) cmds.parent(sIkHnd, sGrpCtrl) cmds.setAttr('%s.v' % sIkHnd, 0) ## advanced twist for i, sCtrl in enumerate([lCtrls[0], lCtrls[-1]]): oCtrl = controls.oControl(sCtrl) cmds.parent([sOffsetBot, sOffsetTop][i], oCtrl.sOutput) cmds.setAttr('%s.dTwistControlEnable' % sIkHnd, 1) cmds.setAttr('%s.dWorldUpType' % sIkHnd, 4) attributes.connectAttrs([ '%s.worldMatrix[0]' % sMatcherBot, '%s.worldMatrix[0]' % sMatcherTop ], ['%s.dWorldUpMatrix' % sIkHnd, '%s.dWorldUpMatrixEnd' % sIkHnd], bForce=True) #### control connect out node sConnectOutCtrl = transforms.createTransformNode(naming.oName( sType='grp', sSide=self._sSide, sPart='%s%sRigConnectOutCtrl' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=sGrpCtrl, bVis=True) constraints.constraint([lJnts[-1], sConnectOutCtrl], sType='parent', bForce=True, bMaintainOffset=True) #### control root connect out node sConnectOutRootCtrl = transforms.createTransformNode(naming.oName( sType='grp', sSide=self._sSide, sPart='%s%sRigConnectOutRootCtrl' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=sGrpCtrl, bVis=True) constraints.constraint([lJnts[0], sConnectOutRootCtrl], sType='parent', bForce=True, bMaintainOffset=True) ## write rig info sString_lJnts = self._convertListToString(lJnts) sString_lCtrls = self._convertListToString(lCtrls) lRigInfo = [ 'ikSplineRig', self._sConnectInJnt, self._sConnectInCtrl, lJnts[-1], sConnectOutCtrl, sConnectOutRootCtrl, sString_lJnts, sString_lCtrls, sIkHnd, sGrpCtrl, sGrp ] lAttrs = [ 'sModuleType', 'sConnectInJnt', 'sConnectInCtrl', 'sConnectOutJnt', 'sConnectOutCtrl', 'sConnectOutRootCtrl', 'lJnts', 'lCtrls', 'sIkHnd', 'sGrpCtrl', 'sModuleNode' ] self._writeRigInfo(sGrp, lRigInfo, lAttrs) self._getRigInfo(sGrp)
def create(self): self._lBpCtrlsSpine = self._lBpCtrls self._lBpCtrls = [self._lBpCtrlsPelvis[1]] + self._lBpCtrls sGrp = transforms.createTransformNode(naming.oName(sType = 'grp', sSide = self._sSide, sPart = '%s%sRig' %(self._sPart, self._sNameRig), iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sConnectInJnt) sGrpCtrl = transforms.createTransformNode(naming.oName(sType = 'grp', sSide = self._sSide, sPart = '%s%sCtrl' %(self._sPart, self._sNameRig), iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sConnectInCtrl) sGrpNode = transforms.createTransformNode(naming.oName(sType = 'grp', sSide = self._sSide, sPart = '%s%sNode' %(self._sPart, self._sNameRig), iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sGrpNode) self._sConnectInJnt = sGrp self._sConnectInCtrl = sGrpCtrl self._sGrpNode = sGrpNode super(spineRig, self).create() ## fk rig oSpineFk = fkJointChainRig.fkJointChainRig( sName = 'Fk', sSide = self._sSide, sPart = self._sPart, iIndex = self._iIndex, lBpJnts = self._lBpCtrlsSpine, sConnectInCtrl = self._sConnectInCtrl, sConnectInJnt = self._sConnectInJnt, bSub = self._bSub, iStacks = self._iStacks, lLockHideAttrs = self._lLockHideAttrs) oSpineFk.create() ## pelvis rig oPelvisFk = fkJointChainRig.fkJointChainRig( sName = 'Fk', sSide = self._sSide, sPart = self._sPartPelvis, iIndex = self._iIndex, lBpJnts = self._lBpCtrlsPelvis, sConnectInCtrl = self._sConnectInCtrl, sConnectInJnt = self._sConnectInJnt, bSub = self._bSub, iStacks = self._iStacks, lLockHideAttrs = self._lLockHideAttrs ) oPelvisFk.create() ## ik spline oSpineIk = ikSplineRig.ikSplineRig( sName = 'ikSpline', sSide = self._sSide, sPart = self._sPart, iIndex = self._iIndex, lBpJnts = self._lBpCtrls, sConnectInCtrl = self._sConnectInCtrl, sConnectInJnt = self._sConnectInJnt, sGrpNode = self._sGrpNode, bSub = self._bSub, iStacks = self._iStacks, lLockHideAttrs = self._lLockHideAttrs, lBpCtrls = self._lBpCtrlsSpine[:-1], bOrientTop = True, bOrientBot = True, lCtrlOrient = self._lCtrlOrient, ) oSpineIk.create() ## constraint and hidde ribbon controls for i, sCtrl in enumerate(self._lCtrls): oCtrl = controls.oControl(sCtrl) cmds.parentConstraint(oSpineIk.lJnts[i], oCtrl.sPasser, mo = False) cmds.setAttr('%s.v' %oCtrl.sPasser, 0) ## constraint ik controls ## pelvis oCtrl = controls.oControl(oSpineIk.lCtrls[0]) constraints.constraint([oPelvisFk.lJnts[0], oCtrl.sPasser], sType = 'parent', bMaintainOffset = True) ## spine for i, sCtrl in enumerate(oSpineIk.lCtrls[1:]): oCtrl = controls.oControl(sCtrl) if i == 0: constraints.constraint([oSpineFk.lJnts[i], oCtrl.sPasser], sType = 'parent', bMaintainOffset = True) else: constraints.constraint([oSpineFk.lJnts[i + 1], oCtrl.sPasser], sType = 'parent', bMaintainOffset = True) ## add ctrl shape sCtrlShape = naming.oName(sType = 'ctrl', sSide = self._sSide, sPart = self._sPart, iIndex = self._iIndex).sName controls.addCtrlShape(oSpineIk.lCtrls + oSpineFk.lCtrls + oPelvisFk.lCtrls, sCtrlShape, bVis = False) cmds.addAttr(sCtrlShape, ln = 'ikCtrlVis', at = 'long', min = 0, max = 1) cmds.setAttr('%s.ikCtrlVis' %sCtrlShape, channelBox = True) attributes.connectAttrs(['%s.ikCtrlVis' %sCtrlShape], ['%s.v' %oSpineIk.sGrpCtrl], bForce = True) ## write rig info sModuleNodes = '%s,%s,%s' %(oSpineFk.sModuleNode, oPelvisFk.sModuleNode, oSpineIk.sModuleNode) sString_lJnts = self._convertListToString(self._lJnts) sString_lCtrls = self._convertListToString(oSpineFk.lCtrls + oPelvisFk.lCtrls + oSpineIk.lCtrls) lRigInfo = ['spineRig', self._sConnectInJnt, self._sConnectInCtrl, self._sConnectOutJnt, self._sConnectOutCtrl, self._sConnectOutRootCtrl,sString_lJnts, sString_lCtrls, sGrpCtrl, sModuleNodes, sGrp] lAttrs = ['sModuleType', 'sConnectInJnt', 'sConnectInCtrl', 'sConnectOutJnt', 'sConnectOutCtrl', 'sConnectOutRootCtrl', 'lJnts', 'lCtrls', 'sGrpCtrl', 'lModuleNodes', 'sModuleNode'] self._writeRigInfo(sGrp, lRigInfo, lAttrs) self._getRigInfo(sGrp)
def create(self): sGrp = transforms.createTransformNode( naming.oName(sType='grp', sSide=self._sSide, sPart='%s%sRig' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sConnectInJnt) sGrpCtrl = transforms.createTransformNode( naming.oName(sType='grp', sSide=self._sSide, sPart='%s%sCtrl' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sConnectInCtrl) sParent_jnt = sGrp lJnts = [] for i, sBpJnt in enumerate(self._lBpJnts): oJntName = naming.oName(sBpJnt) oJntName.sType = 'jnt' oJntName.sPart = '%s%s' % (oJntName.sPart, self._sName) sJnt = joints.createJntOnExistingNode(sBpJnt, sBpJnt, oJntName.sName, sParent=sParent_jnt) lJnts.append(sJnt) sParent_jnt = sJnt lCtrls = [] for i, sBpJnt in enumerate([self._sBpRoot, self._sBpPv, self._sBpCtrl]): oJntName = naming.oName(sBpJnt) iRotateOrder = cmds.getAttr('%s.ro' % sBpJnt) if i == 2: lLockHideAttrs = self._lLockHideAttrs else: lLockHideAttrs = ['rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'] oCtrl = controls.create(oJntName.sPart, sSide=oJntName.sSide, iIndex=oJntName.iIndex, iStacks=self._iStacks, bSub=self._bSub, sParent=sGrpCtrl, sPos=sBpJnt, iRotateOrder=iRotateOrder, sShape='cube', fSize=8, lLockHideAttrs=lLockHideAttrs) lCtrls.append(oCtrl.sName) ## ik handle if self._bOrient: sJntEnd_rp = lJnts[-2] sIkHnd_sc = naming.oName(sType='ikHandle', sSide=self._sSide, sPart='%sSCsolver' % self._sPart, iIndex=self._iIndex).sName cmds.ikHandle(sj=lJnts[-2], ee=lJnts[-1], sol='ikSCsolver', name=sIkHnd_sc) else: sJntEnd_rp = lJnts[-1] sIkHnd_sc = None sIkHnd_rp = naming.oName(sType='ikHandle', sSide=self._sSide, sPart='%sRPsolver' % self._sPart, iIndex=self._iIndex).sName cmds.ikHandle(sj=lJnts[0], ee=sJntEnd_rp, sol='ikRPsolver', name=sIkHnd_rp) #### parent ik handle oCtrl = controls.oControl(lCtrls[2]) sGrpIkHndle = transforms.createTransformNode( naming.oName(sType='grp', sSide=self._sSide, sPart='%s%sRigIkHndle' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=oCtrl.sOutput, bVis=False) cmds.parent(sIkHnd_rp, sGrpIkHndle) if sIkHnd_sc: cmds.parent(sIkHnd_sc, sGrpIkHndle) #### pole vector oCtrl = controls.oControl(lCtrls[1]) cmds.poleVectorConstraint(oCtrl.sOutput, sIkHnd_rp) ## pole vector line curves.createCurveLine(naming.oName(sType='curve', sSide=self._sSide, sPart='%sPvLineIk' % self._sPart, iIndex=self._iIndex).sName, [lJnts[1], oCtrl.sOutput], sParent=sGrpCtrl) #### root control oCtrl = controls.oControl(lCtrls[0]) cmds.pointConstraint(oCtrl.sOutput, lJnts[0], mo=False) #### control connect out node sConnectOutCtrl = transforms.createTransformNode(naming.oName( sType='grp', sSide=self._sSide, sPart='%s%sRigConnectOutCtrl' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=oCtrl.sOutput, bVis=True) constraints.constraint([lJnts[-1], sConnectOutCtrl], sType='parent', bForce=True, bMaintainOffset=True) ## write rig info sString_lJnts = self._convertListToString(lJnts) sString_lCtrls = self._convertListToString(lCtrls) lRigInfo = [ 'ikRPsolverRig', self._sConnectInJnt, self._sConnectInCtrl, lJnts[-1], sConnectOutCtrl, sString_lJnts, sString_lCtrls, sIkHnd_rp, sGrpCtrl, sGrp ] lAttrs = [ 'sModuleType', 'sConnectInJnt', 'sConnectInCtrl', 'sConnectOutJnt', 'sConnectOutCtrl', 'lJnts', 'lCtrls', 'sIkHnd', 'sGrpCtrl', 'sModuleNode' ] self._writeRigInfo(sGrp, lRigInfo, lAttrs) self._getRigInfo(sGrp)
def create(self): self._lBpJnts = [ naming.oName(sType='bpJnt', sSide=self._sSide, sPart='upperLeg').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='knee').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='ankle').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='ball').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='toe').sName, ] self._sBpCtrl = naming.oName(sType='bpJnt', sSide=self._sSide, sPart='footIk').sName self._sBpPv = naming.oName(sType='bpJnt', sSide=self._sSide, sPart='kneePvIk').sName self._sBpRoot = naming.oName(sType='bpJnt', sSide=self._sSide, sPart='upperLegIk').sName self._lBpJntsFootRvs = [ naming.oName(sType='bpJnt', sSide=self._sSide, sPart='footTwistRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='heelRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='toeTipRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='footEndRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='footOutRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='footInnRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='ballRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='ankleRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='ankleEndRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='toeRvs').sName, naming.oName(sType='bpJnt', sSide=self._sSide, sPart='toeEndRvs').sName, ] self._lBpJntsFoot = self._lBpJnts[2:5] self._lBpJnts = self._lBpJnts[0:3] super(legIkRig, self).create() ## foot joints sParent_jnt = self._lJnts[-1] for sBpJnt in self._lBpJntsFoot[1:]: oJntName = naming.oName(sBpJnt) oJntName.sType = 'jnt' oJntName.sPart = '%s%s' % (oJntName.sPart, self._sName) sJnt = joints.createJntOnExistingNode(sBpJnt, sBpJnt, oJntName.sName, sParent=sParent_jnt) self._lJnts.append(sJnt) sParent_jnt = sJnt ## ik handle oName = naming.oName(self._lJnts[3]) sIkHnd_ball = naming.oName(sType='ikHandle', sSide=oName.sSide, sPart='%sSCsolver' % oName.sPart, iIndex=oName.iIndex).sName cmds.ikHandle(sj=self._lJnts[2], ee=self._lJnts[3], sol='ikSCsolver', name=sIkHnd_ball) oName = naming.oName(self._lJnts[-1]) sIkHnd_toe = naming.oName(sType='ikHandle', sSide=oName.sSide, sPart='%sSCsolver' % oName.sPart, iIndex=oName.iIndex).sName cmds.ikHandle(sj=self._lJnts[-2], ee=self._lJnts[-1], sol='ikSCsolver', name=sIkHnd_toe) ## foot rvs lJntsFootRvs = [] for sBpJnt in self._lBpJntsFootRvs: oJntName = naming.oName(sBpJnt) oJntName.sType = 'jnt' sJnt = joints.createJntOnExistingNode(sBpJnt, sBpJnt, oJntName.sName, sParent=sParent_jnt) lJntsFootRvs.append(sJnt) if sBpJnt == self._lBpJntsFootRvs[0]: oCtrl = controls.oControl(self._lCtrls[-1]) cmds.parent(sJnt, oCtrl.sOutput) cmds.setAttr('%s.v' % sJnt, 0) else: sParentBp = cmds.listRelatives(sBpJnt, p=True)[0] oJntNameParent = naming.oName(sParentBp) oJntNameParent.sType = 'jnt' sJntParent = oJntNameParent.sName cmds.parent(sJnt, sJntParent) sIkGrp = cmds.listRelatives(self._sIkHnd, p=True)[0] #### parent ik handles cmds.parent(self._sIkHnd, lJntsFootRvs[8]) cmds.parent(sIkHnd_ball, lJntsFootRvs[6]) cmds.parent(sIkHnd_toe, lJntsFootRvs[-1]) cmds.delete(sIkGrp) #### foot rig ###### add attrs attributes.addDivider([self._lCtrls[2]], 'footCtrl') for sAttr in [ 'footRoll', 'toeTap', 'ballRoll', 'toeRoll', 'heelRoll', 'footBank', 'toeSlide', 'heelSlide', 'ballSlide', 'toeWiggle', 'toeTwist', 'footSlide' ]: cmds.addAttr(self._lCtrls[2], ln=sAttr, at='float', keyable=True) attributes.addDivider([self._lCtrls[2]], 'footExtraCtrl') for sAttr in ['toeLift', 'toeStraight']: cmds.addAttr(self._lCtrls[2], ln=sAttr, at='float', min=0, max=90, keyable=True) cmds.setAttr('%s.toeLift' % self._lCtrls[2], 30) cmds.setAttr('%s.toeStraight' % self._lCtrls[2], 45) #### ball Roll sClamp_footRoll = cmds.createNode('clamp', name=naming.oName( sType='clamp', sSide=self._sSide, sPart='footRoll').sName) cmds.connectAttr('%s.footRoll' % self._lCtrls[2], '%s.inputR' % sClamp_footRoll) cmds.connectAttr('%s.toeLift' % self._lCtrls[2], '%s.maxR' % sClamp_footRoll) sPlus_ballRoll = cmds.createNode('addDoubleLinear', name=naming.oName( sType='add', sSide=self._sSide, sPart='ballRoll').sName) cmds.connectAttr('%s.outputR' % sClamp_footRoll, '%s.input1' % sPlus_ballRoll) sRemap_ballRoll = cmds.createNode('remapValue', name=naming.oName( sType='remap', sSide=self._sSide, sPart='ballRollStraight').sName) cmds.connectAttr('%s.footRoll' % self._lCtrls[2], '%s.inputValue' % sRemap_ballRoll) cmds.connectAttr('%s.toeLift' % self._lCtrls[2], '%s.inputMin' % sRemap_ballRoll) cmds.connectAttr('%s.toeStraight' % self._lCtrls[2], '%s.inputMax' % sRemap_ballRoll) cmds.connectAttr('%s.outValue' % sRemap_ballRoll, '%s.input2' % sPlus_ballRoll) sMult_ballRollLift = cmds.createNode( 'multDoubleLinear', name=naming.oName(sType='mult', sSide=self._sSide, sPart='ballRollLiftNeg').sName) cmds.connectAttr('%s.toeLift' % self._lCtrls[2], '%s.input1' % sMult_ballRollLift) cmds.setAttr('%s.input2' % sMult_ballRollLift, -1, lock=True) cmds.connectAttr('%s.output' % sMult_ballRollLift, '%s.outputMax' % sRemap_ballRoll) sPlus_ballRollSum = cmds.createNode('addDoubleLinear', name=naming.oName( sType='add', sSide=self._sSide, sPart='ballRollSum').sName) cmds.connectAttr('%s.output' % sPlus_ballRoll, '%s.input1' % sPlus_ballRollSum) cmds.connectAttr('%s.ballRoll' % self._lCtrls[2], '%s.input2' % sPlus_ballRollSum) cmds.connectAttr('%s.output' % sPlus_ballRollSum, '%s.rz' % lJntsFootRvs[7]) #### toe roll sRemap_toeRoll = cmds.createNode('remapValue', name=naming.oName( sType='remapValue', sSide=self._sSide, sPart='toeRoll').sName) cmds.connectAttr('%s.footRoll' % self._lCtrls[2], '%s.inputValue' % sRemap_toeRoll) cmds.connectAttr('%s.toeLift' % self._lCtrls[2], '%s.inputMin' % sRemap_toeRoll) cmds.connectAttr('%s.toeStraight' % self._lCtrls[2], '%s.inputMax' % sRemap_toeRoll) sMult_toeRoll = cmds.createNode('multDoubleLinear', name=naming.oName( sType='mult', sSide=self._sSide, sPart='toeRoll').sName) cmds.connectAttr('%s.footRoll' % self._lCtrls[2], '%s.input1' % sMult_toeRoll) cmds.connectAttr('%s.outValue' % sRemap_toeRoll, '%s.input2' % sMult_toeRoll) sPlus_toeRollSum = cmds.createNode('addDoubleLinear', name=naming.oName( sType='add', sSide=self._sSide, sPart='toeRollSum').sName) cmds.connectAttr('%s.output' % sMult_toeRoll, '%s.input1' % sPlus_toeRollSum) cmds.connectAttr('%s.toeRoll' % self._lCtrls[2], '%s.input2' % sPlus_toeRollSum) cmds.connectAttr('%s.output' % sPlus_toeRollSum, '%s.rz' % lJntsFootRvs[2]) #### heel Roll sCond_heel = cmds.createNode('condition', name=naming.oName(sType='condition', sSide=self._sSide, sPart='heelRoll').sName) cmds.connectAttr('%s.footRoll' % self._lCtrls[2], '%s.firstTerm' % sCond_heel) cmds.setAttr('%s.operation' % sCond_heel, 4) cmds.setAttr('%s.colorIfFalseR' % sCond_heel, 0) sMult_heelRoll = cmds.createNode('multDoubleLinear', name=naming.oName( sType='multDoubleLinear', sSide=self._sSide, sPart='heelRollRvs').sName) cmds.connectAttr('%s.footRoll' % self._lCtrls[2], '%s.input1' % sMult_heelRoll) cmds.setAttr('%s.input2' % sMult_heelRoll, -1, lock=True) cmds.connectAttr('%s.output' % sMult_heelRoll, '%s.colorIfTrueR' % sCond_heel) sPlus_heelRollSum = cmds.createNode('addDoubleLinear', name=naming.oName( sType='addDoubleLinear', sSide=self._sSide, sPart='heelRollSum').sName) cmds.connectAttr('%s.outColorR' % sCond_heel, '%s.input1' % sPlus_heelRollSum) cmds.connectAttr('%s.heelRoll' % self._lCtrls[2], '%s.input2' % sPlus_heelRollSum) cmds.connectAttr('%s.output' % sPlus_heelRollSum, '%s.rz' % lJntsFootRvs[1]) #### toe tap cmds.connectAttr('%s.toeTap' % self._lCtrls[2], '%s.rz' % lJntsFootRvs[-2]) #### foot bank sMult_footBank = cmds.createNode('multDoubleLinear', name=naming.oName( sType='mult', sSide=self._sSide, sPart='footBankRvs').sName) cmds.connectAttr('%s.footBank' % self._lCtrls[2], '%s.input1' % sMult_footBank) cmds.setAttr('%s.input2' % sMult_footBank, -1, lock=True) cmds.connectAttr('%s.footBank' % self._lCtrls[2], '%s.rz' % lJntsFootRvs[4]) cmds.connectAttr('%s.output' % sMult_footBank, '%s.rz' % lJntsFootRvs[5]) cmds.transformLimits(lJntsFootRvs[4], rz=[0, 360], erz=[1, 0]) cmds.transformLimits(lJntsFootRvs[4], rz=[0, 360], erz=[1, 0]) #### toeSlide cmds.connectAttr('%s.toeSlide' % self._lCtrls[2], '%s.ry' % lJntsFootRvs[2]) #### heelSlide cmds.connectAttr('%s.heelSlide' % self._lCtrls[2], '%s.ry' % lJntsFootRvs[1]) #### ballSlide ballTwist cmds.connectAttr('%s.ballSlide' % self._lCtrls[2], '%s.ry' % lJntsFootRvs[7]) #### toeWiggle toeTwist cmds.connectAttr('%s.toeWiggle' % self._lCtrls[2], '%s.ry' % lJntsFootRvs[-2]) cmds.connectAttr('%s.toeTwist' % self._lCtrls[2], '%s.rx' % lJntsFootRvs[-2]) #### footSlide cmds.connectAttr('%s.footSlide' % self._lCtrls[2], '%s.ry' % lJntsFootRvs[0]) sString_lJntsOutput = self._convertListToString(self._lJnts[:-1]) lRigInfo = ['legIkRig', sString_lJntsOutput] lAttrs = ['sModuleType', 'lJntsOutput'] self._writeRigInfo(self._sModuleNode, lRigInfo, lAttrs) self._getRigInfo(self._sModuleNode)