def __baseControls(self): ## world control oCtrl_world = controls.create('world', sSide='middle', iStacks=1, sParent='controls', sShape='circle', fSize=10, sColor='yellow', lLockHideAttrs=['sx', 'sy', 'sz', 'v']) ## layout control oCtrl_layout = controls.create('layout', sSide='middle', iStacks=1, sParent=oCtrl_world.sOutput, sShape='triangle', fSize=9.5, sColor='royal heath', lLockHideAttrs=['sx', 'sy', 'sz', 'v']) ## local control oCtrl_local = controls.create('local', sSide='middle', iStacks=1, sParent=oCtrl_layout.sOutput, sShape='triangle', fSize=7.5, sColor='royal purple', lLockHideAttrs=['sx', 'sy', 'sz', 'v']) #### connect scale for sCtrl in [ oCtrl_world.sName, oCtrl_layout.sName, oCtrl_local.sName ]: cmds.addAttr(sCtrl, ln='rigScale', at='float', dv=1, min=0, keyable=True) attributes.connectAttrs([ '%s.rigScale' % sCtrl, '%s.rigScale' % sCtrl, '%s.rigScale' % sCtrl, ], ['%s.sx' % sCtrl, '%s.sy' % sCtrl, '%s.sz' % sCtrl], bForce=True) #### connect with xtrs for sRes in self.lRes: sGrpXtrs = naming.oName(sType='grp', sSide='m', sRes=sRes, sPart='xtrs').sName constraints.constraint([oCtrl_local.sName, sGrpXtrs], sType='all', bMaintainOffset=False, bForce=True)
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 sParent_ctrl = sGrpCtrl lJnts = [] lCtrls = [] 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) if i < len(self._lBpJnts) - 1: iRotateOrder = cmds.getAttr('%s.ro' %sJnt) oCtrl = controls.create(oJntName.sPart, sSide = oJntName.sSide, iIndex = oJntName.iIndex, iStacks = self._iStacks, bSub = self._bSub, sParent = sParent_ctrl, sPos = sJnt, iRotateOrder = iRotateOrder, sShape = 'square', fSize = 8, lLockHideAttrs = self._lLockHideAttrs) cmds.parentConstraint(oCtrl.sOutput, sJnt, mo = False) lCtrls.append(oCtrl.sName) sParent_jnt = sJnt sParent_ctrl = oCtrl.sOutput ## write rig info sString_lJnts = self._convertListToString(lJnts) sString_lCtrls = self._convertListToString(lCtrls) lRigInfo = ['fkJointChainRig', self._sConnectInJnt, self._sConnectInCtrl, sJnt, oCtrl.sOutput, sString_lJnts, sString_lCtrls, sGrpCtrl, sGrp] lAttrs = ['sModuleType', 'sConnectInJnt', 'sConnectInCtrl', 'sConnectOutJnt', 'sConnectOutCtrl', 'lJnts', 'lCtrls', 'sGrpCtrl', 'sModuleNode'] self._writeRigInfo(sGrp, lRigInfo, lAttrs) self._getRigInfo(sGrp)
def create(self): oName = naming.oName(self._sBpJnt) self._sSide = oName.sSide self._sPart = oName.sPart self._iIndex = oName.iIndex self._lPos = transforms.getNodeTransformInfo(self._sBpJnt) self._iRotateOrder = cmds.getAttr('%s.ro' %self._sBpJnt) sGrp = transforms.createTransformNode(naming.oName(sType = 'grp', sSide = self._sSide, sPart = '%sRig' %self._sPart, iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sConnectInJnt) sJnt = joints.createJntOnTransformInfo(naming.oName(sType = 'jnt', sSide = self._sSide, sPart = self._sPart, iIndex = self._iIndex).sName, self._lPos, iRotateOrder = self._iRotateOrder, sParent = sGrp) sGrpCtrl = transforms.createTransformNode(naming.oName(sType = 'grp', sSide = self._sSide, sPart = '%sCtrl' %self._sPart, iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sConnectInCtrl) oCtrl = controls.create(self._sPart, sSide = self._sSide, iIndex = self._iIndex, iStacks = self._iStacks, bSub = self._bSub, sParent = sGrpCtrl, iRotateOrder = self._iRotateOrder, sShape = 'circle', fSize = 10, lLockHideAttrs = self._lLockHideAttrs) transforms.setNodeTransform(oCtrl.sZero, self._lPos) constraints.constraint([oCtrl.sOutput, sJnt], sType = 'parent') ## write rig info lRigInfo = ['singleJointRig', self._sConnectInJnt, self._sConnectInCtrl, sJnt, oCtrl.sOutput, sJnt, oCtrl.sName, sGrpCtrl, sGrp] lAttrs = ['sModuleType', 'sConnectInJnt', 'sConnectInCtrl', 'sConnectOutJnt', 'sConnectOutCtrl', 'lJnts', 'lCtrls', 'sGrpCtrl', 'sModuleNode'] self._writeRigInfo(sGrp, lRigInfo, lAttrs) self._getRigInfo(sGrp)
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 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) 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=sGrp) lJnts.append(sJnt) ## create ribbon surface ## if no control bpjnt, create controls, cluster ribbon lCtrls = [] if not self._lBpCtrls: sRibbon = surfaces.createRibbonFromNodes(naming.oName( sType='surface', sSide=self._sSide, sPart='%s%s' % (self._sPart, self._sName), iIndex=self._iIndex).sName, lJnts, bAuto=True, fWidth=2, bNormalize=False, sParent=sGrpNode) cmds.setAttr('%s.v' % sRibbon, 0) lCls = surfaces.clusterSurface(sRibbon, sUV='u') cmds.rebuildSurface(sRibbon, ch=True, su=len(lJnts) - 1, sv=1, dv=3, du=3) for i, sCls in enumerate(lCls): oCtrl = controls.create('%s%s' % (self._sPart, self._sName), sSide=self._sSide, iIndex=i, iStacks=self._iStacks, bSub=self._bSub, sParent=sGrpCtrl, sPos=sCls, sShape='cube', fSize=4, lLockHideAttrs=self._lLockHideAttrs) cmds.parent(sCls, oCtrl.sOutput) lCtrls.append(oCtrl.sName) else: sRibbon = surfaces.createRibbonFromNodes(naming.oName( sType='surface', sSide=self._sSide, sPart='%s%s' % (self._sPart, self._sName), iIndex=self._iIndex).sName, self._lBpCtrls, bAuto=True, fWidth=2, bNormalize=False, sParent=sGrpNode) cmds.setAttr('%s.v' % sRibbon, 0) lCls = surfaces.clusterSurface(sRibbon, sUV='u') cmds.rebuildSurface(sRibbon, ch=True, su=len(lJnts) - 1, sv=1, dv=3, du=3) for i, sCls in enumerate(lCls): oJntName = naming.oName(self._lBpCtrls[i]) iRotateOrder = cmds.getAttr('%s.ro' % self._lBpCtrls[i]) oCtrl = controls.create('%s%s' % (oJntName.sPart, self._sName), sSide=oJntName.sSide, iIndex=oJntName.iIndex, iStacks=self._iStacks, bSub=self._bSub, sParent=sGrpCtrl, iRotateOrder=iRotateOrder, sPos=self._lBpCtrls[i], sShape='cube', fSize=4, lLockHideAttrs=self._lLockHideAttrs) cmds.parent(sCls, oCtrl.sOutput) lCtrls.append(oCtrl.sName) ### attach joints sGrpFollicle, lFollicles = constraints.follicleConstraint( sRibbon, lJnts, bMaintainOffset=True) cmds.parent(sGrpFollicle, sGrpNode) #### 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 = [ 'ribbonRig', self._sConnectInJnt, self._sConnectInCtrl, lJnts[-1], sConnectOutCtrl, sConnectOutRootCtrl, sString_lJnts, sString_lCtrls, sRibbon, sGrpCtrl, sGrp ] lAttrs = [ 'sModuleType', 'sConnectInJnt', 'sConnectInCtrl', 'sConnectOutJnt', 'sConnectOutCtrl', 'sConnectOutRootCtrl', 'lJnts', 'lCtrls', 'sRibbon', 'sGrpCtrl', '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) 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 ## ik handle sIkHnd = naming.oName(sType='ikHandle', sSide=self._sSide, sPart=self._sPart, iIndex=self._iIndex).sName cmds.ikHandle(sj=lJnts[0], ee=lJnts[-1], sol='ikSCsolver', name=sIkHnd) ## control if self._bCtrl: 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) iRotateOrder = cmds.getAttr('%s.ro' % lJnts[0]) oJntName = naming.oName(lJnts[0]) oCtrl_root = controls.create(oJntName.sPart, sSide=oJntName.sSide, iIndex=oJntName.iIndex, iStacks=self._iStacks, bSub=self._bSub, sParent=sGrpCtrl, sPos=lJnts[0], iRotateOrder=iRotateOrder, sShape='cube', fSize=4, lLockHideAttrs=self._lLockHideAttrs) oJntName = naming.oName(lJnts[-1]) oCtrl_aim = controls.create(oJntName.sPart, sSide=oJntName.sSide, iIndex=oJntName.iIndex, iStacks=self._iStacks, bSub=self._bSub, sParent=sGrpCtrl, sPos=lJnts[-1], iRotateOrder=iRotateOrder, sShape='cube', fSize=4, lLockHideAttrs=self._lLockHideAttrs) cmds.pointConstraint(oCtrl_root.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=False) sParentIk = oCtrl_aim.sOutput lCtrls = [oCtrl_root.sName, oCtrl_aim.sName] else: sParentIk = self._sConnectInCtrl lCtrls = '' 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=sParentIk, bVis=False) cmds.parent(sIkHnd, sGrpIkHndle) ## write rig info sString_lJnts = self._convertListToString(lJnts) sString_lCtrls = self._convertListToString(lCtrls) lRigInfo = [ 'ikSCsolverRig', self._sConnectInJnt, self._sConnectInCtrl, lJnts[-1], sConnectOutCtrl, sString_lJnts, sString_lCtrls, sIkHnd, sGrpCtrl, sGrp ] lAttrs = [ 'sModuleType', 'sConnectInJnt', 'sConnectInCtrl', 'sConnectOutJnt', 'sConnectOutCtrl', 'lJnts', 'lCtrls', 'sIkHnd', 'sGrpCtrl', 'sModuleNode' ] self._writeRigInfo(sGrp, lRigInfo, lAttrs) self._getRigInfo(sGrp)
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 createComponent(self): super(baseIkRPsolverLimb, self).createComponent() sParent_ctrl = self._sComponentControls ## put ik joint chain locally sGrp_ikJnts = transforms.createTransformNode(naming.oName(sType = 'group', sSide = self._sSide, sPart = '%sRPJointsLocal' %self._sName, iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sComponentRigNodesWorld) sParent_jntLocal = sGrp_ikJnts lJntsLocal = [] lJntsLocal, lBindJnts = createDriveJoints.createDriveJoints(self._lBpJnts, sParent = sGrp_ikJnts, sSuffix = 'IkRPLocal', bBind = False) lJnts, lBindJnts = createDriveJoints.createDriveJoints(self._lBpJnts, sParent = self._sComponentJoints, sSuffix = 'IkRP', bBind = self._bBind) for i, sJntLocal in enumerate(lJntsLocal): for sAxis in ['X', 'Y', 'Z']: cmds.connectAttr('%s.translate%s' %(sJntLocal, sAxis), '%s.translate%s' %(lJnts[i], sAxis)) cmds.connectAttr('%s.rotate%s' %(sJntLocal, sAxis), '%s.rotate%s' %(lJnts[i], sAxis)) cmds.connectAttr('%s.scale%s' %(sJntLocal, sAxis), '%s.scale%s' %(lJnts[i], sAxis)) ## ctrls lCtrls = [] for i, sBpCtrl in enumerate(self._lBpCtrls): oJntName = naming.oName(sBpCtrl) iRotateOrder = cmds.getAttr('%s.ro' %sBpCtrl) if i != 2: lLockHideAttrs = ['rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'] else: lLockHideAttrs = self._lLockHideAttrs oCtrl = controls.create(oJntName.sPart, sSide = oJntName.sSide, iIndex = oJntName.iIndex, iStacks = self._iStacks, bSub = True, sParent = self._sComponentControls, sPos = sBpCtrl, iRotateOrder = iRotateOrder, sShape = 'cube', fSize = 8, lLockHideAttrs = lLockHideAttrs) lCtrls.append(oCtrl.sName) ## ik handle sIkHnd = naming.oName(sType = 'ikHandle', sSide = self._sSide, sPart = '%sRPsolver' %self._sName, iIndex = self._iIndex).sName cmds.ikHandle(sj = lJntsLocal[0], ee = lJntsLocal[-1], sol = 'ikRPsolver', name = sIkHnd) #### offset group sGrpIk = transforms.createTransformNode(naming.oName(sType = 'group', sSide = self._sSide, sPart = '%sRPsolver' %self._sName, iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sComponentRigNodesWorld, sPos = lCtrls[-1]) sGrpPv = transforms.createTransformNode(naming.oName(sType = 'group', sSide = self._sSide, sPart = '%sPV' %self._sName, iIndex = self._iIndex).sName, lLockHideAttrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v'], sParent = self._sComponentRigNodesWorld, sPos = lCtrls[1]) cmds.parent(sIkHnd, sGrpIk) #### pole vector constraint cmds.poleVectorConstraint(sGrpPv, sIkHnd) #### pole vector line sCrv, lClsHnds = curves.createCurveLine(naming.oName(sType = 'curve', sSide = self._sSide, sPart = '%sPvLineIk' %self._sName, iIndex = self._iIndex).sName, [lJnts[1], lCtrls[1]], bConstraint = False) cmds.parent(lClsHnds, sCrv, self._sComponentControls) ## pass info to class self._lJnts = lJnts self._lCtrls = lCtrls self._lBindJnts = lBindJnts self._sGrpIk = sGrpIk self._sIkHnd = sIkHnd self._lJntsLocal = lJntsLocal if lBindJnts: self._lBindRootJnts = [lBindJnts[0]] else: self._lBindRootJnts = None ## matrix connect constraints.matrixConnect(lCtrls[0], [lJntsLocal[0]], 'matrixOutputWorld',lSkipRotate = ['X', 'Y', 'Z'], lSkipScale = ['X', 'Y', 'Z'], bForce = True) constraints.matrixConnect(lCtrls[1], [sGrpPv, lClsHnds[1]], 'matrixOutputWorld',lSkipRotate = ['X', 'Y', 'Z'], lSkipScale = ['X', 'Y', 'Z'], bForce = True) constraints.matrixConnect(lCtrls[2], [sGrpIk], 'matrixOutputWorld', lSkipScale = ['X', 'Y', 'Z'], bForce = True) sMultMatrixPv = cmds.createNode('multMatrix', name = naming.oName(sType = 'multMatrix', sSide = self._sSide, sPart = '%sPvMatrix' %self._sName, iIndex = self._iIndex).sName) cmds.connectAttr('%s.matrix' %lJnts[1], '%s.matrixIn[0]' %sMultMatrixPv) cmds.connectAttr('%s.matrix' %lJnts[0], '%s.matrixIn[1]' %sMultMatrixPv) constraints.matrixConnect(sMultMatrixPv, [lClsHnds[0]], 'matrixSum', lSkipRotate = ['X', 'Y', 'Z'], lSkipScale = ['X', 'Y', 'Z'], bForce = True) ## write component info self._writeGeneralComponentInfo('baseIkRPsolverLimb', lJnts, lCtrls, lBindJnts, self._lBindRootJnts) ## output matrix if self._bInfo: self._writeOutputMatrixInfo(lJnts) ## add twist joints addTwistJoints.twistJointsForLimb(self._iTwistJntNum, self._lSkipTwist, lJnts, self._lBpJnts, bBind = self._bBind, sNode = self._sComponentMaster, bInfo = self._bInfo) 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) 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 createComponent(self): super(baseIkSCsolverLimb, self).createComponent() sParent_jnt = self._sComponentJoints sParent_ctrl = self._sComponentControls lJnts = [] lCtrls = [] lBindJnts = [] ## controls oCtrlRoot = controls.create( '%sRoot' % self._sName, sSide=self._sSide, iIndex=self._iIndex, iStacks=self._iStacks, bSub=True, sParent=self._sComponentControls, sPos=self._lBpJnts[0], sShape='cube', fSize=8, lLockHideAttrs=['rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) lCtrls.append(oCtrlRoot.sName) oCtrlAim = controls.create('%sAim' % self._sName, sSide=self._sSide, iIndex=self._iIndex, iStacks=self._iStacks, bSub=True, sParent=self._sComponentControls, sPos=self._lBpJnts[-1], sShape='cube', fSize=8, lLockHideAttrs=['sx', 'sy', 'sz', 'v']) lCtrls.append(oCtrlAim.sName) ## put ik joint chain locally sGrp_ikJnts = transforms.createTransformNode( naming.oName(sType='group', sSide=self._sSide, sPart='%sSCJointsLocal' % self._sName, iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sComponentRigNodesWorld) sParent_jntLocal = sGrp_ikJnts lJntsLocal = [] lJntsLocal, lBindJnts = createDriveJoints.createDriveJoints( self._lBpJnts, sParent=sGrp_ikJnts, sSuffix='IkSCLocal', bBind=False) ## stretch if self._bStretch: ## add stretch attr attributes.addDivider([oCtrlAim.sName], 'stretch') cmds.addAttr(oCtrlAim.sName, ln='limitFactorPos', at='float', min=1, dv=self._lLimitFactor[1], keyable=True) cmds.addAttr(oCtrlAim.sName, ln='limitFactorNeg', at='float', min=0, max=1, dv=self._lLimitFactor[0], keyable=True) cmds.addAttr(oCtrlAim.sName, ln='factorYPos', at='float', min=0, dv=self._lFactorY[1], keyable=True) cmds.addAttr(oCtrlAim.sName, ln='factorZPos', at='float', min=0, dv=self._lFactorZ[1], keyable=True) cmds.addAttr(oCtrlAim.sName, ln='factorYNeg', at='float', min=0, dv=self._lFactorY[0], keyable=True) cmds.addAttr(oCtrlAim.sName, ln='factorZNeg', at='float', min=0, dv=self._lFactorZ[0], keyable=True) cmds.addAttr(oCtrlAim.sName, ln='stretchLengthOrig', at='float') sGrp_stretch = transforms.createTransformNode( naming.oName(sType='group', sSide=self._sSide, sPart='%sSCJointStretch' % self._sName, iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sComponentRigNodesWorld) ## distance measure sDistance = cmds.createNode('distanceBetween', name=naming.oName( sType='distanceBetween', sSide=self._sSide, sPart='%sStretch' % self._sName, iIndex=self._iIndex).sName) sNullRoot = transforms.createTransformNode(naming.oName( sType='null', sSide=self._sSide, sPart='%sRootStretch' % self._sName, iIndex=self._iIndex).sName, sPos=oCtrlRoot.sName, sParent=sGrp_stretch) sNullAim = transforms.createTransformNode(naming.oName( sType='null', sSide=self._sSide, sPart='%sAimStretch' % self._sName, iIndex=self._iIndex).sName, sPos=oCtrlAim.sName, sParent=sGrp_stretch) constraints.matrixConnect(oCtrlRoot.sName, [sNullRoot], 'matrixOutputWorld', lSkipRotate=['X', 'Y', 'Z'], lSkipScale=['X', 'Y', 'Z']) constraints.matrixConnect(oCtrlAim.sName, [sNullAim], 'matrixOutputWorld', lSkipRotate=['X', 'Y', 'Z'], lSkipScale=['X', 'Y', 'Z']) cmds.connectAttr('%s.t' % sNullRoot, '%s.point1' % sDistance) cmds.connectAttr('%s.t' % sNullAim, '%s.point2' % sDistance) fDis = cmds.getAttr('%s.distance' % sDistance) cmds.setAttr('%s.stretchLengthOrig' % oCtrlAim.sName, fDis, lock=True) sDivide = cmds.createNode( 'multiplyDivide', name=naming.oName(sType='multiplyDivide', sSide=self._sSide, sPart='%sStretchFactor' % self._sName, iIndex=self._iIndex).sName) cmds.setAttr('%s.operation' % sDivide, 2) cmds.connectAttr('%s.distance' % sDistance, '%s.input1X' % sDivide) cmds.connectAttr('%s.stretchLengthOrig' % oCtrlAim.sName, '%s.input2X' % sDivide) sConditionStretchOutput = cmds.createNode( 'condition', name=naming.oName(sType='condition', sSide=self._sSide, sPart='%sStretchOutput' % self._sName, iIndex=self._iIndex).sName) cmds.connectAttr('%s.outputX' % sDivide, '%s.firstTerm' % sConditionStretchOutput) cmds.setAttr('%s.secondTerm' % sConditionStretchOutput, 1) cmds.setAttr('%s.operation' % sConditionStretchOutput, 2) sConditionStretchPos = cmds.createNode( 'condition', name=naming.oName(sType='condition', sSide=self._sSide, sPart='%sStretchPos' % self._sName, iIndex=self._iIndex).sName) cmds.connectAttr('%s.outputX' % sDivide, '%s.firstTerm' % sConditionStretchPos) cmds.connectAttr('%s.limitFactorPos' % oCtrlAim.sName, '%s.secondTerm' % sConditionStretchPos) cmds.setAttr('%s.operation' % sConditionStretchPos, 4) cmds.connectAttr('%s.outputX' % sDivide, '%s.colorIfTrueR' % sConditionStretchPos) cmds.connectAttr('%s.limitFactorPos' % oCtrlAim.sName, '%s.colorIfFalseR' % sConditionStretchPos) cmds.connectAttr('%s.outColorR' % sConditionStretchPos, '%s.colorIfTrueR' % sConditionStretchOutput) sConditionStretchNeg = cmds.createNode( 'condition', name=naming.oName(sType='condition', sSide=self._sSide, sPart='%sStretchNeg' % self._sName, iIndex=self._iIndex).sName) cmds.connectAttr('%s.outputX' % sDivide, '%s.firstTerm' % sConditionStretchNeg) cmds.connectAttr('%s.limitFactorNeg' % oCtrlAim.sName, '%s.secondTerm' % sConditionStretchNeg) cmds.setAttr('%s.operation' % sConditionStretchNeg, 2) cmds.connectAttr('%s.outputX' % sDivide, '%s.colorIfTrueR' % sConditionStretchNeg) cmds.connectAttr('%s.limitFactorNeg' % oCtrlAim.sName, '%s.colorIfFalseR' % sConditionStretchNeg) cmds.connectAttr('%s.outColorR' % sConditionStretchNeg, '%s.colorIfFalseR' % sConditionStretchOutput) for i, lFactors in enumerate([self._lFactorY, self._lFactorZ]): sAxis = ['Y', 'Z'][i] sRemapPos = cmds.createNode( 'remapValue', name=naming.oName(sType='remapValue', sSide=self._sSide, sPart='%sStretch%sPos' % (self._sName, sAxis), iIndex=self._iIndex).sName) sRemapNeg = cmds.createNode( 'remapValue', name=naming.oName(sType='remapValue', sSide=self._sSide, sPart='%sStretch%sNeg' % (self._sName, sAxis), iIndex=self._iIndex).sName) cmds.connectAttr('%s.outputX' % sDivide, '%s.inputValue' % sRemapPos) cmds.connectAttr('%s.outputX' % sDivide, '%s.inputValue' % sRemapNeg) cmds.setAttr('%s.inputMin' % sRemapPos, 1) cmds.connectAttr('%s.limitFactorPos' % oCtrlAim.sName, '%s.inputMax' % sRemapPos) cmds.connectAttr('%s.limitFactorNeg' % oCtrlAim.sName, '%s.inputMin' % sRemapNeg) cmds.setAttr('%s.inputMax' % sRemapNeg, 1) cmds.setAttr('%s.outputMin' % sRemapPos, 1) cmds.setAttr('%s.outputMax' % sRemapNeg, 1) cmds.connectAttr('%s.factor%sPos' % (oCtrlAim.sName, sAxis), '%s.outputMax' % sRemapPos) cmds.connectAttr('%s.factor%sNeg' % (oCtrlAim.sName, sAxis), '%s.outputMin' % sRemapNeg) cmds.connectAttr( '%s.outValue' % sRemapPos, '%s.colorIfTrue%s' % (sConditionStretchOutput, ['G', 'B'][i])) cmds.connectAttr( '%s.outValue' % sRemapNeg, '%s.colorIfFalse%s' % (sConditionStretchOutput, ['G', 'B'][i])) sMultStretchX = cmds.createNode( 'multDoubleLinear', name=naming.oName(sType='multDoubleLinear', sSide=self._sSide, sPart='%sStretchX' % self._sName, iIndex=self._iIndex).sName) cmds.connectAttr('%s.stretchLengthOrig' % oCtrlAim.sName, '%s.input1' % sMultStretchX) cmds.connectAttr('%s.outColorR' % sConditionStretchOutput, '%s.input2' % sMultStretchX) cmds.connectAttr('%s.output' % sMultStretchX, '%s.tx' % lJntsLocal[-1]) cmds.connectAttr('%s.outColorG' % sConditionStretchOutput, '%s.sy' % lJntsLocal[0]) cmds.connectAttr('%s.outColorB' % sConditionStretchOutput, '%s.sz' % lJntsLocal[0]) lJnts, lBindJnts = createDriveJoints.createDriveJoints( self._lBpJnts, sParent=self._sComponentJoints, sSuffix='IkSC', bBind=self._bBind) for i, sJntLocal in enumerate(lJntsLocal): for sAxis in ['X', 'Y', 'Z']: cmds.connectAttr('%s.translate%s' % (sJntLocal, sAxis), '%s.translate%s' % (lJnts[i], sAxis)) cmds.connectAttr('%s.rotate%s' % (sJntLocal, sAxis), '%s.rotate%s' % (lJnts[i], sAxis)) cmds.connectAttr('%s.scale%s' % (sJntLocal, sAxis), '%s.scale%s' % (lJnts[i], sAxis)) ## ik handles sIkHnd = naming.oName(sType='ikHandle', sSide=self._sSide, sPart='%sSCsolver' % self._sName, iIndex=self._iIndex).sName cmds.ikHandle(sj=lJntsLocal[0], ee=lJntsLocal[-1], sol='ikSCsolver', name=sIkHnd) #### offset group sGrpIk = transforms.createTransformNode( naming.oName(sType='group', sSide=self._sSide, sPart='%sSCsolverOffset' % self._sName, iIndex=self._iIndex).sName, lLockHideAttrs=[ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ], sParent=self._sComponentRigNodesWorld, sPos=oCtrlAim.sName) cmds.parent(sIkHnd, sGrpIk) #### matrix connect constraints.matrixConnect(oCtrlAim.sName, [sGrpIk], 'matrixOutputWorld', lSkipScale=['X', 'Y', 'Z'], bForce=True) constraints.matrixConnect(oCtrlRoot.sName, [lJnts[0]], 'matrixOutputWorld', lSkipRotate=['X', 'Y', 'Z'], lSkipScale=['X', 'Y', 'Z'], bForce=True) ## pass info to class self._lJnts = lJnts self._lCtrls = lCtrls self._lBindJnts = lBindJnts self._sGrpIk = sGrpIk self._sIkHnd = sIkHnd self._lJntslocal = lJntsLocal if lBindJnts: self._lBindRootJnts = [lBindJnts[0]] else: self._lBindRootJnts = None ## write component info self._writeGeneralComponentInfo('baseIkSCsolverLimb', lJnts, lCtrls, lBindJnts, self._lBindRootJnts) ## output matrix if self._bInfo: self._writeOutputMatrixInfo(lJnts) ## add twist joints addTwistJoints.twistJointsForLimb(self._iTwistJntNum, self._lSkipTwist, lJnts, self._lBpJnts, bBind=self._bBind, sNode=self._sComponentMaster, bInfo=self._bInfo) self._getComponentInfo(self._sComponentMaster)
def createComponent(self): super(baseIkSplineSolverLimb, self).createComponent() sParent_jntLocal = self._sComponentRigNodesWorld lJntsLocal = [] lJntsBindName = [] lJntsLocal, lBindJnts = createDriveJoints.createDriveJoints( self._lBpJnts, sParent=self._sComponentRigNodesWorld, sSuffix='IkSplineLocal', bBind=False) ## generate curve sCurve = naming.oName(sType='curve', sSide=self._sSide, sPart='%sSplineSolver' % self._sName, iIndex=self._iIndex).sName if not self._sBpCrv: sCurve = curves.createCurveOnNodes(sCurve, lJntsLocal, iDegree=3, sParent=None) else: sCurve = cmds.duplicate(self._sBpCrv, name=sCurve)[0] lClsHnds = curves.clusterCurve(sCurve, bRelatives=True) #### rebuild curve iCvs = curves.getCurveCvNum(sCurve) cmds.rebuildCurve(sCurve, ch=1, rebuildType=0, degree=3, s=iCvs - 3, keepRange=0, rpo=True) #### set up ik sIkHnd = naming.oName(sType='ikHandle', sSide=self._sSide, sPart='%sIkSplineSolver' % self._sName, iIndex=self._iIndex).sName cmds.ikHandle(sj=lJntsLocal[0], ee=lJntsLocal[-1], sol='ikSplineSolver', ccv=False, scv=False, curve=sCurve, name=sIkHnd) cmds.makeIdentity(lJntsLocal[0], apply=True, t=1, r=1, s=1) ## spline joint and bind jnt lJnts, lBindJnts = createDriveJoints.createDriveJoints( lJntsLocal, sParent=self._sComponentJoints, sSuffix='', sRemove='Local', bBind=self._bBind, lBindNameOverride=self._lBpJnts) for i, sJntLocal in enumerate(lJntsLocal): for sAxis in ['X', 'Y', 'Z']: cmds.connectAttr('%s.translate%s' % (sJntLocal, sAxis), '%s.translate%s' % (lJnts[i], sAxis)) cmds.connectAttr('%s.rotate%s' % (sJntLocal, sAxis), '%s.rotate%s' % (lJnts[i], sAxis)) cmds.connectAttr('%s.scale%s' % (sJntLocal, sAxis), '%s.scale%s' % (lJnts[i], sAxis)) ## rig setup cmds.parent(sCurve, lClsHnds, sIkHnd, self._sComponentRigNodesWorld) #### controls lCtrls = [] for i, sClsHnd in enumerate(lClsHnds): oCtrl = controls.create( '%sSplineSolver' % self._sName, sSide=self._sSide, iIndex=i + 1, iStacks=self._iStacks, bSub=True, sParent=self._sComponentControls, sPos=sClsHnd, sShape='cube', fSize=4, lLockHideAttrs=['rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) sDecomposeMatrix = cmds.createNode( 'decomposeMatrix', name=naming.oName(sType='decomposeMatrix', sSide=self._sSide, sPart='%sSplineSolver' % self._sName, iIndex=i).sName) cmds.connectAttr('%s.matrixOutputLocal' % oCtrl.sName, '%s.inputMatrix' % sDecomposeMatrix) cmds.connectAttr('%s.outputTranslate' % sDecomposeMatrix, '%s.t' % sClsHnd) lCtrls.append(oCtrl.sName) ## pass info to class self._lJnts = lJnts self._lCtrls = lCtrls self._lBindJnts = lBindJnts self._sIkHnd = sIkHnd if lBindJnts: self._lBindRootJnts = [lBindJnts[0]] else: self._lBindRootJnts = None ## write component info self._writeGeneralComponentInfo('baseIkSplineSolverLimb', lJnts, lCtrls, lBindJnts, self._lBindRootJnts) ## output matrix if self._bInfo: self._writeOutputMatrixInfo(lJnts) self._getComponentInfo(self._sComponentMaster)