Пример #1
0
    def createComponent(self):
        super(baseComponentsBlendLimb, self).createComponent()

        cmds.setAttr('%s.subComponents' % self._sComponentMaster, 1)

        lJnts, lBindJnts = createDriveJoints.createDriveJoints(
            self._lBpJnts,
            sParent=self._sComponentJoints,
            sSuffix='',
            bBind=self._bBind)

        ## 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)

        sEnumName = ''
        iIndexCustom = 90
        lKey = self._dComponents.keys()
        lIndex = []
        iDefaultA = None
        iDefaultB = None
        for sKey in lKey:
            if namingDict.dSpaceDict.has_key(sKey):
                iIndexKey = namingDict.dSpaceDict[sKey]
            else:
                iIndexKey = iIndexCustom
                iIndexCustom += 1
            lIndex.append(iIndexKey)
            sEnumName += '%s=%d:' % (sKey, iIndexKey)
            if sKey == self._sDefaultA:
                iDefaultA = iIndexKey
            if sKey == self._sDefaultB:
                iDefaultB = iIndexKey

        if iDefaultA == None:
            iDefaultA = lIndex[0]
        if iDefaultB == None:
            iDefaultB = lIndex[0]

        ## add attrs
        cmds.addAttr(sCtrlShape,
                     ln='moduleA',
                     at='enum',
                     keyable=True,
                     en=sEnumName[:-1],
                     dv=iDefaultA)
        cmds.addAttr(sCtrlShape,
                     ln='moduleB',
                     at='enum',
                     keyable=True,
                     en=sEnumName[:-1],
                     dv=iDefaultB)
        cmds.addAttr(sCtrlShape,
                     ln='moduleBlend',
                     at='float',
                     keyable=True,
                     min=0,
                     max=10)
        sMultBlend = naming.oName(sType='multDoubleLinear',
                                  sSide=self._sSide,
                                  sPart='%sModuleBlendOutput' % self._sName,
                                  iIndex=self._iIndex).sName
        cmds.createNode('multDoubleLinear', name=sMultBlend)
        cmds.connectAttr('%s.moduleBlend' % sCtrlShape,
                         '%s.input1' % sMultBlend)
        cmds.setAttr('%s.input2' % sMultBlend, 0.1, lock=True)
        sRvsBlend = naming.oName(sType='reverse',
                                 sSide=self._sSide,
                                 sPart='%sModuleBlendOutput' % self._sName,
                                 iIndex=self._iIndex).sName
        cmds.createNode('reverse', name=sRvsBlend)
        cmds.connectAttr('%s.output' % sMultBlend, '%s.inputX' % sRvsBlend)
        sCondBlend = naming.oName(sType='condition',
                                  sSide=self._sSide,
                                  sPart='%sModuleBlendIndex' % self._sName,
                                  iIndex=self._iIndex).sName
        cmds.createNode('condition', name=sCondBlend)
        cmds.connectAttr('%s.output' % sMultBlend, '%s.firstTerm' % sCondBlend)
        cmds.setAttr('%s.secondTerm' % sCondBlend, 0.5, lock=True)
        cmds.setAttr('%s.operation' % sCondBlend, 4)
        cmds.connectAttr('%s.moduleA' % sCtrlShape,
                         '%s.colorIfTrueR' % sCondBlend)
        cmds.connectAttr('%s.moduleB' % sCtrlShape,
                         '%s.colorIfFalseR' % sCondBlend)

        ## choice node
        lNodes = []
        for sJnt in lJnts:
            oJntName = naming.oName(sJnt)
            sChoiceA = naming.oName(sType='choice',
                                    sSide=oJntName.sSide,
                                    sPart='%sA' % oJntName.sPart,
                                    iIndex=oJntName.iIndex).sName
            sChoiceB = naming.oName(sType='choice',
                                    sSide=oJntName.sSide,
                                    sPart='%sB' % oJntName.sPart,
                                    iIndex=oJntName.iIndex).sName
            sWtAddMatrix = naming.oName(sType='wtAddMatrix',
                                        sSide=oJntName.sSide,
                                        sPart=oJntName.sPart,
                                        iIndex=oJntName.iIndex).sName
            cmds.createNode('choice', name=sChoiceA)
            cmds.createNode('choice', name=sChoiceB)
            cmds.createNode('wtAddMatrix', name=sWtAddMatrix)
            cmds.connectAttr('%s.moduleA' % sCtrlShape,
                             '%s.selector' % sChoiceA)
            cmds.connectAttr('%s.moduleB' % sCtrlShape,
                             '%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)
            constraints.matrixConnectJnt(sWtAddMatrix, sJnt, 'matrixSum')
            lNodes.append([sChoiceA, sChoiceB])

        dModuleInfo = {}
        for sKey in self._dComponents.keys():
            sModulePath = self._dComponents[sKey]['sModulePath']
            sModuleName = self._dComponents[sKey]['sModuleName']
            dKwargs = self._dComponents[sKey]['dKwargs']
            dKwargs.update({
                'bInfo':
                False,
                'lBpJnts':
                self._lBpJnts,
                'sParent':
                self._sComponentSubComponents,
                'sName':
                '%s%s%s' % (self._sName, sKey[0].upper(), sKey[1:]),
                'sSide':
                self._sSide,
                'iIndex':
                self._iIndex,
                'iTwistJntNum':
                0
            })

            oModule = importer.importModule(sModulePath)
            oLimb = getattr(oModule, sModuleName)(**dKwargs)
            oLimb.createComponent()

            ## connect attrs
            attributes.connectAttrs(
                ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'],
                ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'],
                sDriver=self._sComponentPasser,
                sDriven=oLimb._sComponentPasser,
                bForce=True)
            attributes.connectAttrs(
                ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'],
                ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'],
                sDriver=self._sComponentSpace,
                sDriven=oLimb._sComponentSpace,
                bForce=True)

            cmds.connectAttr('%s.inputMatrix' % self._sComponentMaster,
                             '%s.inputMatrix' % oLimb._sComponentMaster)
            cmds.connectAttr('%s.lWorldMatrix' % self._sComponentMaster,
                             '%s.lWorldMatrix' % oLimb._sComponentMaster)

            controls.addCtrlShape(oLimb._lCtrls,
                                  sCtrlShape,
                                  bVis=False,
                                  dCtrlShapeInfo=None,
                                  bTop=False)

            iNum = lKey.index(sKey)
            iIndex = lIndex[iNum]
            for i, sJnt in enumerate(lJnts):
                cmds.connectAttr('%s.matrix' % oLimb._lJnts[i],
                                 '%s.input[%d]' % (lNodes[i][0], iIndex))
                cmds.connectAttr('%s.matrix' % oLimb._lJnts[i],
                                 '%s.input[%d]' % (lNodes[i][1], iIndex))

            ## control vis
            sCondCtrlVis = naming.oName(sType='condition',
                                        sSide=self._sSide,
                                        sPart='%s%sCtrlVis' %
                                        (self._sName, sKey),
                                        iIndex=self._iIndex).sName
            cmds.createNode('condition', name=sCondCtrlVis)
            cmds.connectAttr('%s.outColorR' % sCondBlend,
                             '%s.firstTerm' % sCondCtrlVis)
            cmds.setAttr('%s.secondTerm' % sCondCtrlVis, iIndex, lock=True)
            cmds.setAttr('%s.colorIfTrueR' % sCondCtrlVis, 1, lock=True)
            cmds.setAttr('%s.colorIfFalseR' % sCondCtrlVis, 0, lock=True)
            sMultVis = naming.oName(sType='multDoubleLinear',
                                    sSide=self._sSide,
                                    sPart='%s%sCtrlVis' % (self._sName, sKey),
                                    iIndex=self._iIndex).sName
            cmds.createNode('multDoubleLinear', name=sMultVis)
            cmds.connectAttr('%s.outColorR' % sCondCtrlVis,
                             '%s.input1' % sMultVis)
            cmds.connectAttr('%s.controls' % self._sComponentMaster,
                             '%s.input2' % sMultVis)
            cmds.connectAttr('%s.output' % sMultVis,
                             '%s.controls' % oLimb._sComponentMaster)

            dModuleInfo.update({
                sKey: {
                    'sModulePath': sModulePath,
                    'sModuleName': sModuleName,
                    'sComponentNode': oLimb._sComponentMaster
                }
            })

        cmds.delete(sCrv)

        if lBindJnts:
            self._lBindRootJnts = [lBindJnts[0]]
        else:
            self._lBindRootJnts = None
        ## write component info
        self._writeGeneralComponentInfo('baseComponentsBlendLimb', lJnts,
                                        [sCtrlShape], lBindJnts,
                                        self._lBindRootJnts)
        cmds.addAttr(self._sComponentMaster, ln='dModuleInfo', dt='string')
        cmds.setAttr('%s.dModuleInfo' % self._sComponentMaster,
                     str(dModuleInfo),
                     type='string',
                     lock=True)
        ## 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)
Пример #2
0
    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)
Пример #3
0
	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)
Пример #4
0
    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)