Example #1
0
    def setupTeeth(self):
        allCons = []
        conGrps = []
        ConObj = CreateControler(
            13, (0.1 * self.scale, 0.1 * self.scale, 0.1 * self.scale))
        ConObj.signValue = 54861
        for i, jnt in enumerate(self.jnts):
            jntMat = rig.getAttr(jnt + '.worldMatrix')
            con = ConObj.SK_b08(jnt.split('_')[0] + '_M')
            allCons.append(con)
            rig.xform(con, ro=(90, 0, 0), wd=True)
            rig.makeIdentity(apply=True, r=True)
            rig.xform(con, m=jntMat)

            conGrp = CA.addGrp().grp(con, 'Freeze')
            conGrps.append(conGrp)

            rig.parentConstraint(con, jnt, mo=True)
            rig.scaleConstraint(con, jnt, mo=True)

        self.Connect.connect(self.grp, allCons)  #连接控制器属性
        newGrp = rig.group(conGrps, n=self.grp + '_CTRLGrp')
        rig.parent(newGrp, self.grp)

        #连接visibility属性
        Connect = CA.connectAttribute()
        Connect.sourceAttr = 'conVis'
        Connect.targetAttr = 'visibility'
        Connect.connect(self.grp,
                        [rig.listRelatives(con, p=True)[0] for con in allCons])
Example #2
0
    def eyeLid(self):
        self.newAddJnts = []
        for lip in self.lips:
            rig.select(cl = True)
            pos = rig.xform(lip, q = True, t = True, ws = True)
            Njnt = rig.joint(p = pos, n = lip+'_Joint')
#            self.newAddJnts.append(Njnt)
            rig.hide(Njnt)
            NjntGrp = rig.group(Njnt, n = Njnt+'_GRP')
            
            jntTemp = re.compile('_UpLid_|_DnLid_').sub('_Eye_',lip)
            jnt = re.compile('M\Z').sub('Joint',jntTemp)
            lipGrp = rig.group(empty = True, n = lip+'_GRP')
            lipGrpUp = rig.group(lipGrp, n = lip+'_GRP_UP')
            lipGrpTop = rig.group(lipGrpUp, n = lip+'_GRP_TOP')
            jntParent = rig.listRelatives(jnt, p = True)[0]
            jntMat = rig.getAttr(jnt+'.worldMatrix')
            rig.xform(lipGrpTop, m = jntMat)
            aimNode = rig.aimConstraint(lip ,lipGrpTop, aimVector = (0, 0, 1), upVector = (0, 1, 0), worldUpType = 'object', worldUpObject = jnt+'_Loc_GRP') 
            rig.delete(aimNode)
            
            lipCon = CA.addGrp().grp(lip,'AimRotate')#增加 组
            
            #连接旋转和位移
            rig.connectAttr(lip+'.rotateZ', lipGrp+'.rotateZ')
            rig.connectAttr(lip+'.scaleX', lipGrp+'.scaleX')
            rig.connectAttr(lip+'.scaleZ', lipGrp+'.scaleZ')
            translateMD = rig.createNode('multiplyDivide', n = lip +'_translate_MD', ss = True)
            lipRoateGrp = rig.listRelatives(lip, p = True)[0]
            print lipRoateGrp
            rig.addAttr(lipRoateGrp, at = 'float', ln = 'Move', dv = -157/self.scale, k = True)
            rig.connectAttr(lip+'.translateY', translateMD+'.input1X')
            rig.connectAttr(lipRoateGrp+'.Move', translateMD+'.input2X')            
            rig.connectAttr(translateMD+'.outputX', lipGrpUp+'.rotateX')                 
            
            rig.parent(lipGrpTop, lipCon, jnt+'_CTRL_GRP')
            rig.parent(NjntGrp, lipGrp)
                  
        jnts = [jnt for jnt in rig.listConnections(self.eye+'.CTRLJoint', s = False, d = True)]#列出眼睛控制器骨骼,注意:不包含新增加的眼皮骨骼
        for jnt in jnts:
            con = re.compile('Joint\Z').sub('M',jnt)#得到控制器名字
            lipCon = CA.addGrp().grp(con,'freeze')#增加 组
Example #3
0
    def extraAddLid(self):
        exLids = [con for con in self.allCons if re.match('.+LidMin_\d+M',con)]
        print exLids
        for lid in exLids:
            if re.match('Lf_', lid):
                LR = 'Lf_'
            else:
                LR = 'Rt_'
                
            if re.match('\w\w_Up', lid):
                UD = 'Up'
            elif re.match('\w\w_Dn', lid):
                UD = 'Dn'
            else:
                UD = None
                
            pos = rig.xform(lid, q = True, t = True)
            rig.select(cl = True)
            jnt = rig.joint(p = pos ,n = lid+'_Joint')#创建骨骼
            rig.parent(jnt, lid)
            rig.hide(jnt)
            self.newAddJnts.append(jnt)
            
            ConGrp = CA.addGrp().grp(lid, 'Rotate')
            
            if UD:
                parentJnt = LR+UD+'Lid_0M_GRP_UP'
                mat = rig.getAttr(parentJnt+'.worldMatrix')
                grp = rig.group(empty = True, n = ConGrp+'_Rotate')
                rig.xform(grp, m = mat)
                rig.parent(ConGrp, grp)                
                rig.parent(grp, LR+UD+'Lid_0M_GRP')
                
                parentLid = rig.listRelatives(lid, p = True)[0]
                if re.match('\w+_2M\Z', lid):
                    v = 1
                else:
                    v = -0.3
                rig.addAttr(parentLid, at = 'float', ln = 'RotateRX', k = True, dv = v)
#                rig.addAttr(parentLid, at = 'float', ln = 'RotateRY', k = True, dv = 1)
#                rig.addAttr(parentLid, at = 'float', ln = 'RotateRZ', k = True, dv = 1)
                RotateRoMD = rig.createNode('multiplyDivide', n = lid+'_Roate_MD')
                rig.connectAttr(parentJnt+'.rotate', RotateRoMD+'.input2')
                rig.connectAttr(parentLid+'.RotateRX', RotateRoMD+'.input1X')
#                rig.connectAttr(parentLid+'.RotateRY', RotateRoMD+'.input1Y')
#                rig.connectAttr(parentLid+'.RotateRZ', RotateRoMD+'.input1Z')
                rig.connectAttr(RotateRoMD+'.output', grp+'.rotate') 
                
#                rig.parent(ConGrp, LR+UD+'Lid_0M_GRP')
            else:
                parentJnt = LR+'Eye_0Joint_CTRL_GRP'
                rig.parent(ConGrp, parentJnt)
Example #4
0
 def setupTongue(self):
     #对骨骼校正轴向
     oj = 'zyx'
     secondaryAxisOrient = 'yup'
     orientJoints = [jnt for jnt in self.jnts]#排除不需要校正轴向的骨骼
     for jnt in orientJoints:
         rig.joint(jnt,e = True, oj = oj, secondaryAxisOrient = secondaryAxisOrient, ch = False, zso = True)
     rig.joint(self.jnts[-1],e = True, oj = 'none', ch = False, zso = True)
     
     
     #生成控制器并增加父子约束
     allCons = []
     preCon  = ''
     ConObj = CreateControler(13, (0.1*self.scale, 0.1*self.scale, 0.1*self.scale))
     ConObj.signValue = 32547
     for i,jnt in enumerate(self.jnts):
         jntMat = rig.getAttr(jnt+'.worldMatrix')
         con = ConObj.SK_b08(jnt.split('_')[0]+'_'+str(i)+'M')
         allCons.append(con)
         rig.xform(con, ro = (90, 0, 0), wd = True)
         rig.makeIdentity(apply = True, r = True)
         rig.xform(con, m = jntMat)
         
         conGrp = CA.addGrp().grp(con, 'Freeze')
         if i != 0:
             rig.parent(conGrp, preCon)
         preCon = con
         
         rig.parentConstraint(con, jnt, mo = True)
     
     self.Connect.connect(self.grp, allCons)#连接控制器属性
     
     #连接visibility属性
     self.Connect.sourceAttr = 'conVis'
     self.Connect.targetAttr = 'visibility'
     self.Connect.connect(self.grp, [rig.listRelatives(con, p = True)[0] for con in allCons])
Example #5
0
    def connectTranslateToMacro(self):
        rigGrp = CA.getRigGrp().createGrp()  #创建rig组
        #--------------------------------------------------- 连接main控制器到macro控制器上
        mainCons = [u'Nose_M']
        for con in mainCons:
            macroCon = re.compile('_M\Z').sub('Macro_M', con)
            macroConShape = rig.listRelatives(macroCon, s=True)[0]
            rig.hide(macroConShape)  #隐藏形节点
            rig.connectAttr(con + '.translate',
                            macroCon + '.translate')  #连接translate
            noseJnt = re.compile('_M\Z').sub('_Joint', con)
            rig.connectAttr(con + '.rotate', noseJnt + '.rotate')  #连接 rotate

        #---------------------------------------------------------------- 设置嘴唇旋转
        backCons = [
            con for con in rig.listConnections(
                self.main + '.CTRLCurve', s=False, d=True)
            if re.match('\w+Lip_Back_\d+M\Z', con)
        ]
        allBackCons = [
            con for con in rig.listConnections(
                self.main + '.CTRLCurve', s=False, d=True)
            if re.match('\w+_Back_\d+M\Z', con)
        ]
        allBackGRP = rig.group([con + '_GRP' for con in allBackCons],
                               n=self.main + '_BackCon')
        upLipCons = [
            con for con in backCons if re.match('\w+UpLip_Back_\d+M\Z', con)
        ]
        dnLipCons = [
            con for con in backCons if re.match('\w+DnLip_Back_\d+M\Z', con)
        ]

        upSmallCon = []  #上嘴唇back控制器
        if len(upLipCons) % 2:
            i = (len(upLipCons) - 1) / 2 - 1
            upSmallCon.append('LfUpLip_Back_' + str(i) + 'M')
            upSmallCon.append('RtUpLip_Back_' + str(i) + 'M')
            upSmallCon.append('MdUpLip_Back_' + str(0) + 'M')
        else:
            i = len(upLipCons) / 2 - 1
            upSmallCon.append('LfUpLip_Back_' + str(i) + 'M')
            upSmallCon.append('RtUpLip_Back_' + str(i) + 'M')

        dnSmallCon = []  #下嘴唇back控制器
        if len(upLipCons) % 2:
            i = (len(dnLipCons) - 1) / 2 - 1
            dnSmallCon.append('LfDnLip_Back_' + str(i) + 'M')
            dnSmallCon.append('RtDnLip_Back_' + str(i) + 'M')
            dnSmallCon.append('MdDnLip_Back_' + str(0) + 'M')
        else:
            i = len(upLipCons) / 2 - 1
            dnSmallCon.append('LfDnLip_Back_' + str(i) + 'M')
            dnSmallCon.append('RtDnLip_Back_' + str(i) + 'M')

        rotateJointGrp = []
        for con in upSmallCon:
            lipJoint = 'Up_Lip_Joint'
            lipCon = 'Up_Lip_M'
            if not rig.objExists(lipJoint + '_RotateLip'):
                lipRotateJoint = rig.duplicate(lipJoint,
                                               n=lipJoint + '_RotateLip')[0]
                lipGrp = rig.group(lipRotateJoint,
                                   n=lipJoint + '_RotateLip_GRP')
                rig.connectAttr(lipCon + '.rotate', lipRotateJoint + '.rotate')
            else:
                lipRotateJoint = lipJoint + '_RotateLip'
                lipGrp = lipJoint + '_RotateLip_GRP'

            conParent = rig.listRelatives(con + '_GRP', p=True)[0]
            posMat = rig.getAttr(con + '_GRP.worldMatrix')
            posGrp = rig.group(empty=True, n=con + '_Loc_GRP')
            rig.xform(posGrp, m=posMat)
            rig.parent(posGrp, conParent)

            rig.parentConstraint(lipRotateJoint, posGrp, mo=True)

            rig.connectAttr(posGrp + '.translate', con + '_GRP.translate')

            rotateJointGrp.append(lipGrp)
        for con in dnSmallCon:
            lipJoint = 'Dn_Lip_Joint'
            lipCon = 'Dn_Lip_M'
            if not rig.objExists(lipJoint + '_RotateLip'):
                lipRotateJoint = rig.duplicate(lipJoint,
                                               n=lipJoint + '_RotateLip')[0]
                lipGrp = rig.group(lipRotateJoint,
                                   n=lipJoint + '_RotateLip_GRP')
                rig.connectAttr(lipCon + '.rotate', lipRotateJoint + '.rotate')
            else:
                lipRotateJoint = lipJoint + '_RotateLip'
                lipGrp = lipJoint + '_RotateLip_GRP'

            conParent = rig.listRelatives(con + '_GRP', p=True)[0]
            posMat = rig.getAttr(con + '_GRP.worldMatrix')
            posGrp = rig.group(empty=True, n=con + '_Loc_GRP')
            rig.xform(posGrp, m=posMat)
            rig.parent(posGrp, conParent)

            rig.parentConstraint(lipRotateJoint, posGrp, mo=True)

            rig.connectAttr(posGrp + '.translate', con + '_GRP.translate')

            rotateJointGrp.append(lipGrp)

        rotateGrp = rig.group(rotateJointGrp, n='Mouth_rotate_GRP')
        rig.parent(rotateGrp, rigGrp)
        #--------------------------------------------------- 将main和macroCon控制器放到适当的jaw骨骼下
        cons = [
            u'Lf_CornerLip_M', u'Rt_CornerLip_M', u'Dn_Lip_M', u'Mouth_Tip_M'
        ]
        jaw = 'Jaw_Joint'
        jawSwivle = 'Jaw_Swivle_Joint_UP'
        moutTip = 'jawSwivel_M'

        jawSwivleMat = rig.getAttr(jawSwivle + '.worldMatrix')
        jawMat = rig.getAttr(jaw + '.worldMatrix')
        jawGrpUp = rig.group(empty=True, n=jaw.replace('_Joint', 'Move_Up'))
        jawGrpTop = rig.group(jawGrpUp, n=jaw.replace('_Joint', 'Move_Top'))
        rig.xform(jawGrpTop, m=jawMat)

        SwivleGrp = rig.group(empty=True, n='awSwivle_Rotate_GRP')
        rig.xform(SwivleGrp, m=jawSwivleMat)
        SwivleGrpTop = CA.addGrp().grp(SwivleGrp, 'mouth')

        for con in cons:
            jntUP = re.compile('_M\Z').sub('_Joint_Up', con)
            mainCon = re.compile('_M\Z').sub('_M_GRP', con)
            macroCon = re.compile('_M\Z').sub('Macro_M_GRP', con)

            jntTop = rig.listRelatives(jntUP, p=True)[0]
            TopMat = rig.getAttr(jntTop + '.worldMatrix')

            newUp = rig.group(empty=True, n=jntUP.replace('_Joint', 'Move'))
            newTop = rig.group(newUp, n=jntTop.replace('_Joint', 'Move'))

            rig.xform(newTop, m=TopMat)
            rig.connectAttr(jntUP + '.rotate', newUp + '.rotate')

            rig.parent(mainCon, newUp)
            rig.parent(macroCon, newUp)
            rig.parent(newTop, jawGrpUp)

        rig.connectAttr(jaw + '.rotate', jawGrpUp + '.rotate')
        rig.connectAttr(moutTip + '.rotate', jawSwivle + '.rotate')
        rig.connectAttr(moutTip + '.rotate', SwivleGrp + '.rotate')
        rig.parent(jawGrpTop, SwivleGrp)
        rig.parent(SwivleGrpTop, rigGrp)

        rig.parentConstraint(moutTip, 'JawMain_M_GRP', mo=True)
        rig.parentConstraint(moutTip, 'Up_Lip_M_GRP', mo=True)

        #-------------------------------------------------------------- 将控制器P给rigGrp
        rig.parent(self.head + '_CTRLBsCurve', rigGrp)
        rig.parent(self.head + '_CTRLMacroCurve', rigGrp)
        rig.parent(self.main + '_CTRLCurve', rigGrp)

        #----------------------------------------------------------------- 隐藏控制器
        for con in allBackCons:  #隐藏back控制器的shape节点
            conShape = rig.listRelatives(con, s=True)[0]
            rig.hide(conShape)

        hideCon = CA.changeController()
        hideCon.operate = 'hide'
        hideCon.selectTypes('small')  #隐藏main控制器
        hideCon.selectTypes('macro')  #隐藏macro控制器
        hideCon.selectTypes('cross')  #隐藏cross控制器

        hideJnts = [
            u'Lf_CornerLip_Joint', u'Rt_CornerLip_Joint', u'Mouth_Tip_Joint',
            u'Dn_Lip_Joint', u'JawMain_Joint', u'Lf_Cheek_Joint',
            u'Rt_Cheek_Joint', u'Up_Lip_Joint', u'Up_Lip_Joint_RotateLip',
            u'Dn_Lip_Joint_RotateLip', u'Rt_Brow_Joint', u'Lf_Brow_Joint',
            u'Nose_Joint'
        ]
        rig.hide(hideJnts)  #隐藏骨骼