def changeConSize(self): size = rig.floatSliderGrp(self.sizeFSG, q=True, v=True) rig.floatSliderGrp(self.sizeFSG, e=True, v=1) Con = WDBase.changeController() objs = rig.ls(sl=True) if objs: obj = objs[0] if re.match('\ALf[A-Z]+|\ARt[A-Z]+', obj): Con.size = size Con.operate = 'changeSize' Con.selectTypes('small') elif re.match('\ALf_.+Macro_M\Z|\ARt_.+Macro_M\Z', obj): Con.size = size Con.operate = 'changeSize' Con.selectTypes('macro') elif re.match('\ALf_.+_M\Z|\ARt_.+_M\Z', obj): Con.size = size Con.operate = 'changeSize' Con.selectTypes('main')
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) #隐藏骨骼
def displayConntroller(self, conType, hd): Con = WDBase.changeController() hideSign = Con.operate Con.operate = hd Con.selectTypes(conType)