Ejemplo n.º 1
0
def ModifyControllerColorAndShape():
    exSphere = [u'Lf_canthusOut_M', u'Lf_canthusIn_M', u'Rt_canthusIn_M', u'Rt_canthusOut_M', u'Lf_mouth_M', u'Rt_mouth_M']#球形控制器
    SV = rig.getAttr('Face_Scale_Grp.scaleVal')
    controller = CreateControler(13,[0.05*SV,0.05*SV,0.05*SV])
    cons = rig.listConnections('Face_Scale_Grp.signA',s = False,d = True)
    for con in cons:
        conColor = 13 #控制器默认颜色
        if ('_dnEyelid_' in con) or ('_dnLip_' in con):
            conColor = 22
        
        controller.setColor(conColor)
        if con in exSphere:
            NewCon = controller.SK_b03('TemName_Controllers')
        else:
            NewCon = controller.SK_b08('TemName_Controllers') #新控制器默认形状
        

                   
        conShape = rig.listRelatives(con,s = True)
        rig.delete(conShape)
        NewConShape = rig.listRelatives(NewCon,s = True)[0]
        rig.rename(NewConShape,conShape)
        rig.setAttr(NewCon+'.tz',0.05*SV)
        rig.setAttr(NewCon+'.rx',90)
        rig.makeIdentity(NewCon,apply = True,r = True,t = True) 
        rig.parent(conShape,con,add = True,s = True)
        rig.delete(NewCon)
Ejemplo n.º 2
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])
Ejemplo n.º 3
0
def SK_SKTOCON(objs):
    Con = CreateControler(13)
    N = len(objs)
    for i, obj in enumerate(objs):
        M = getAttr(obj + '.worldMatrix')

        conName = Con.SK_b08(obj.replace(obj.split('_')[-1], str(i) + '_M'))
        setAttr(conName + '.rz', 90)
        makeIdentity(conName, apply=True, s=True, r=True, t=True)
        conGrp = group(conName, n=conName + '_GRP')
        xform(conGrp, matrix=M)
        parentConstraint(conName, obj, mo=True)

        if 0 != i:
            parent(conGrp, obj.replace(obj.split('_')[-1], str(i - 1) + '_M'))
Ejemplo n.º 4
0
 def createFaceCon(self):
     controller = CreateControler(13)
     controlName = controller.SK_b08('Face_Con')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'headFOL')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'headSKIN')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyeLeft')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyeRight')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'upTooth')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'dnTooth')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyebrowLeft')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyebrowRight')
     rig.addAttr('Face_ConShape',dt = 'string',ln = 'tongue')
     rig.addAttr( controlName, ln='scaleValue',at = 'double')
     rig.setAttr(controlName+'.rx',90)
     rig.makeIdentity(controlName,apply = True,t = True,r = True,s = True)
     return controlName
Ejemplo n.º 5
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])
Ejemplo n.º 6
0
class FC_ControlPosition(object):
    def __init__(self,eyeSign,tongueSign,faceSign,eyebrowSign,toothSign,face,signRun = True):
        self.eyeSn = eyeSign
        self.tongueSign = tongueSign
        self.faceSn = faceSign
        self.eyebrowSn = eyebrowSign
        self.toothSn = toothSign
        self.faceUI = face
        self.controller = CreateControler(13,[0.02,0.02,0.02])
        self.controller.signValue = 78
        self.positionInfo = {u'Lf_upLip_1_P': [[0.4577522202940788, -0.88940796081633167, 1.417898534744211], 22], u'Rt_upLip_1_P': [[-0.45775222778320313, -0.8894079327583313, 1.4178985357284546], 22], u'Lf_eyebrow_1_P': [[1.4552631170435382, 1.0109427040846835, 0.71208507180728153], 6], u'Lf_ear_P': [[1.6969779911728109, 0.30225545212855426, -0.83550711061509519], 22], u'Lf_eyebrow_3_P': [[0.83952074318038761, 1.2762483953898438, 1.3866029424173725], 6], u'Rt_upLip_2_P': [[-0.24067594110965729, -0.82347398996353149, 1.5329214334487915], 22], u'Rt_nose_P': [[-0.28455081582069397, -0.29319655895233154, 1.5947476625442505], 13], u'Lf_mouth_P': [[0.59368043681559712, -0.94644514607242525, 1.1507955018474469], 13], u'Rt_dnLip_1_P': [[-0.40149763226509094, -1.0502012968063354, 1.3711462020874023], 12], u'Rt_eyebrow_1_P': [[-1.4552631378173828, 1.0109426975250244, 0.7120850682258606], 6], u'Lf_dnLip_2_P': [[0.21610563619760767, -1.0877709665250357, 1.5105537251473589], 12], u'Lf_eyebrow_4_P': [[0.36489604932817388, 1.1127071207027288, 1.5045110865908411], 6], u'Rt_dnEyelid_3_P': [[-0.97799999999999998, 0.60090496740722077, 1.0512626650116561], 10], u'Lf_dnEyelid_2_P': [[0.80561238526187084, 0.56115445658376806, 1.1145096040896882], 10], u'Lf_dnEyelid_3_P': [[0.97829695568744968, 0.60090496740722077, 1.0512626650116561], 10], u'Lf_pull_P': [[1.1940568236640083, -0.74121844106321233, 0.60184938648410746], 6], u'Lf_dnLip_1_P': [[0.40149764130798138, -1.0502013047415499, 1.3711461657738258], 12], u'Rt_eyebrow_4_P': [[-0.36489605903625488, 1.1127071380615234, 1.5045111179351807], 6], u'Rt_eyebrow_3_P': [[-0.83952075242996216, 1.2762483358383179, 1.3866029977798462], 6], u'Mid_dnLip_P': [[0.0, -1.0725690595054045, 1.5188097774357625], 12], u'Rt_canthusOut_P': [[-1.1433006525039673, 0.70208227634429932, 0.92102342844009399], 13], u'Mid_base_P': [[0.0, 0.0, 0.0], 16],u'Rt_upEyelid_3_P': [[-0.98499999999999999, 0.81146603544601237, 1.0737908090959429], 22], u'Lf_eyebrow_2_P': [[1.2554887462609086, 1.2242805206272087, 1.0934283695974849], 6], u'Lf_canthusIn_P': [[0.43909954407376683, 0.6311377754074402, 1.0586760528711641], 13], u'Rt_ear_P': [[-1.696977972984314, 0.30225545167922974, -0.8355070948600769], 22], u'Rt_upEyelid_2_P': [[-0.76296061277389526, 0.84621930122375488, 1.1415883302688599], 22], u'Lf_cheekbone_P': [[1.2649382178275159, -0.13004048109449998, 0.95846824899201755], 22], u'Rt_dnLip_2_P': [[-0.21610563993453979, -1.087770938873291, 1.5105537176132202], 12], u'Lf_canthusOut_P': [[1.1433007061180056, 0.70208226194515522, 0.92102340618126766], 13], u'Rt_cheekbone_P': [[-1.2649382352828979, -0.1300404816865921, 0.95846825838088989], 22], u'Rt_upEyelid_1_P': [[-0.58767658472061157, 0.79538941383361816, 1.1090470552444458], 22], u'Lf_nose_P': [[0.28455081409851524, -0.2931965624518485, 1.594747668867244], 13], u'Lf_upLip_2_P': [[0.24067594423116645, -0.82347398074313027, 1.5329214512325766], 22], u'Rt_eyebrow_2_P': [[-1.2554887533187866, 1.2242804765701294, 1.093428373336792], 6], u'Lf_dnEyelid_1_P': [[0.59532230907410022, 0.58211628344290467, 1.0920294918149343], 10], u'Lf_upEyelid_1_P': [[0.58767656543479574, 0.79538939863679392, 1.1090470759223556], 22], u'Rt_canthusIn_P': [[-0.43909955024719238, 0.63113778829574585, 1.05867600440979], 13], u'Rt_dnEyelid_2_P': [[-0.80561238527297974, 0.56115448474884033, 1.1145095825195312], 10], u'Rt_dnEyelid_1_P': [[-0.59532231092453003, 0.58211630582809448, 1.0920294523239136], 10], u'Mid_upLip_P': [[0.0, -0.79989685162339896, 1.5986444439336869], 22], u'Rt_pull_P': [[-1.1940568685531616, -0.7412184476852417, 0.60184937715530396], 6], u'Lf_upEyelid_3_P': [[0.98455660606281059, 0.81146603544601237, 1.0737908090959429], 22], u'Mid_nose_P': [[0.0, -0.1841173100719343, 1.8619454284092736], 22], u'Lf_upEyelid_2_P': [[0.76296061594693798, 0.84621928539927671, 1.1415883252920129], 22], u'Rt_mouth_P': [[-0.59368044137954712, -0.94644516706466675, 1.1507954597473145], 13]}
        self.eyebrowPosInfo = {u'Lf_ebw_2_P': [[1.2539269262641821, 1.446814944148378, 1.0537070623711431], 13], u'Lf_ebw_1_P': [[1.4084910234031645, 1.3076079841558128, 0.80211524813419777], 13], u'Rt_ebw_4_P': [[-0.64794783800161104, 1.4254101271982282, 1.4431839608606198], 13], u'Lf_ebw_3_P': [[1.0037106276394581, 1.4898388225433679, 1.2718257991365869], 13], u'Lf_ebw_4_P': [[0.64794783800161104, 1.4254101271982282, 1.4431839608606198], 13], u'Rt_ebw_2_P': [[-1.2539269262641821, 1.446814944148378, 1.0537070623711431], 13], u'Rt_ebw_1_P': [[-1.4084910234031645, 1.3076079841558128, 0.80211524813419777], 13], u'Rt_ebw_3_P': [[-1.0037106276394581, 1.4898388225433679, 1.2718257991365869], 13]}
        if signRun:
            self.combine()
        
    def getPosition(self,controllers = []):
        positionDictData = dict([(obj,[rig.xform(obj,q = True,t = True,ws = True),rig.getAttr((rig.listRelatives(obj,s = True)[0])+'.overrideColor')])for obj in controllers ])
        return positionDictData
    
    def creatController(self,dictData):
        for eachControl in dictData:
            controlValue = dictData[eachControl]
            self.controller.setColor(int(controlValue[1]))
            controlName = self.controller.SK_b03(eachControl)
            rig.xform(controlName,t = controlValue[0],ws = True)
            
    def lockHideConnectCon(self,dictData):
        locks = LockHideAttr(1,0,0,0)
        for eachControl in dictData:
#  连接位移值
            if('Lf' == eachControl.split('_')[0]):
                RtConName = eachControl.replace('Lf','Rt')
                if(rig.objExists(RtConName)):
                    conNode = rig.createNode('multiplyDivide',n = eachControl+'_MD',ss = True)
                    rig.setAttr(conNode+'.input2X',-1)
                    rig.connectAttr(eachControl+'.translate',conNode+'.input1')
                    rig.connectAttr(conNode+'.output',RtConName+'.translate')
#   锁定translatex                             
            if ('Mid' == eachControl.split('_')[0]):
                rig.setAttr(eachControl+'.tx',cb = False,k = False,l = True)
#   锁定隐藏属性            
            locks.hideAndLockObj(eachControl)
            
    def createFaceCon(self):
        controller = CreateControler(13)
        controlName = controller.SK_b08('Face_Con')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'headFOL')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'headSKIN')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyeLeft')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyeRight')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'upTooth')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'dnTooth')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyebrowLeft')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'eyebrowRight')
        rig.addAttr('Face_ConShape',dt = 'string',ln = 'tongue')
        rig.addAttr( controlName, ln='scaleValue',at = 'double')
        rig.setAttr(controlName+'.rx',90)
        rig.makeIdentity(controlName,apply = True,t = True,r = True,s = True)
        return controlName
    
    
    def creatJawjoint(self):
        jntNames = [u'JawTip_JNT_P', u'Jaw_JNT_P', u'HeadRoot_JNT_P']
        jntPos = [[-1.9721522630525295e-031, -1.6991611811361911, 1.2772460195315276], [-1.9721522630525295e-031, -0.24193316678545695, -0.71455524677275717], [0.0, -3.877232277010112, -1.9775230127662995]] 
        for i,jnt in enumerate(jntNames):
            rig.select(cl = True)
            curJNT = rig.joint(n = jnt)
            rig.xform(curJNT,t = jntPos[i],ws = True)
        rig.parent('JawTip_JNT_P','Jaw_JNT_P')
        rig.parent('Jaw_JNT_P','HeadRoot_JNT_P')
        rig.parent('HeadRoot_JNT_P',self.FaceCon)
        
        self.controller.setColor(17)
        self.controller.signValue = 73
        jawCon = self.controller.SK_b03('Jaw_M') 
        rig.xform(jawCon,matrix = [11.093766471162281, 0.0, 0.0, 0.0, 0.0, 11.093766471162281, 0.0, 0.0, 0.0, 0.0, 11.093766471162281, 0.0, 0.0, -1.9479364224911047, 1.5001411259496222, 1.0])           
        rig.parent(jawCon,self.FaceCon)    
        rig.makeIdentity(jawCon,apply = True,s = True,r = True,t = True)
        
    def addEyebrow(self,sign):
        if sign:
            self.controller.signValue = 71
            self.creatController(self.eyebrowPosInfo)
            self.lockHideConnectCon(self.eyebrowPosInfo)        
            rig.parent(self.eyebrowPosInfo.keys(),self.grpName)

        
    def addMainController(self):
        self.creatController(self.positionInfo)
        self.lockHideConnectCon(self.positionInfo)
        rig.parent(self.positionInfo.keys(),self.grpName)
        
    def addEye(self,sign):
        if sign:
            LfJnt = rig.joint(n = 'Lf_EYE_JNT_P')
            rig.xform(LfJnt,t = [0.76887053415707951, 0.76097599414167427, 0.62705611174469811],ws = True)
            RtJnt = rig.joint(n = 'Rt_EYE_JNT_P')
            rig.xform(RtJnt,t = [-0.76887053415707951, 0.76097599414167427, 0.62705611174469811],ws = True)
            rig.parent(LfJnt,RtJnt,self.FaceCon)
            
            
            self.controller.setObjScale((1,1,1))
            self.controller.setColor(6)
            self.controller.signValue = 73
            eyeAllCon = self.controller.SK_b08('eye_M')
            rig.xform(eyeAllCon,matrix = [0.98195796671303204, 0.0, 0.0, 0.0, 0.0, 2.1803846877178224e-016, 0.98195796671303204, 0.0, 0.0, -0.4017168114352116, 8.9199050686874858e-017, 0.0, 0.0, 0.74691933784829889, 5.0041701361715383, 1.0])
            LfEyeCon = self.controller.SK_b08('Lf_eye_M')
            rig.xform(LfEyeCon,matrix = [0.27600951299477411, 0.0, 0.0, 0.0, 0.0, 6.1286423268474912e-017, 0.27600951299477416, 0.0, 0.0, -0.27600951299477416, 6.1286423268474912e-017, 0.0, 0.76756054849076027, 0.74691933784829911, 5.0041701361715401, 1.0])
            RtEyeCon = self.controller.SK_b08('Rt_eye_M')
            rig.xform(RtEyeCon,matrix = [-0.27600951299477411, 0.0, 0.0, 0.0, 0.0, 6.1286423268474912e-017, 0.27600951299477416, 0.0, 0.0, -0.27600951299477416, 6.1286423268474912e-017, 0.0, -0.76756054849076027, 0.74691933784829911, 5.0041701361715401, 1.0])
            rig.parent(LfEyeCon,RtEyeCon,eyeAllCon)
            rig.parent(eyeAllCon,self.grpName)
            rig.makeIdentity(eyeAllCon,apply = True,s = True,r = True,t = True)
            
    def addTongue(self,sign):
        if sign:
            jnts = [u'Tongue_1_JNT_P', u'Tongue_2_JNT_P', u'Tongue_3_JNT_P', u'Tongue_4_JNT_P', u'Tongue_5_JNT_P'] 
            jntPos = [[-2.4074124304840448e-034, -1.1828907427397966, 0.39945317842483419], [-1.9352787993130288e-019, -1.0414296961573679, 0.547367817822622], [-1.9352787993136451e-019, -0.98892292574879703, 0.74994385199198321], [-1.9352787993136451e-019, -1.0101921438931105, 0.98285235913741198], [-1.9352787993130904e-019, -1.1000491650967648, 1.1555898993095108]]
            rig.select(cl = True)
            for i,jnt in enumerate(jnts):
                curJnt = rig.joint(n = jnt)
                rig.xform(curJnt,t = jntPos[i],ws = True)
            rig.select(cl = True)
            rig.parent('Tongue_1_JNT_P',self.FaceCon)
            
            self.controller.setColor(13)
            self.controller.signValue = 73
            tongueCon = self.controller.SK_b03('Tongue_M') 
            rig.xform(tongueCon,matrix = [0.06444328794870588, 0.0, 0.0, 0.0, 0.0, 0.06444328794870588, 0.0, 0.0, 0.0, 0.0, 0.06444328794870588, 0.0, 0.0, -1.3071946345318575, 1.650696183174968, 1.0] )           
            rig.parent(tongueCon,self.FaceCon)    
            rig.makeIdentity(tongueCon,apply = True,s = True,r = True,t = True)
    def addTooth(self,sign):
        if sign:
            rig.select(cl = True)
            UpTooth = rig.joint(n = 'UpTooth_JNT_P')
            rig.xform(UpTooth,t = [0.0, -0.67428806973770494, 0.83475947289697605],ws = True)
            rig.select(cl = True)
            DnTooth = rig.joint(n = 'DnTooth_JNT_P')
            rig.xform(DnTooth,t = [0.0, -1.1574310052199537, 0.74481897781780426],ws = True)
            rig.parent(UpTooth,DnTooth,self.FaceCon)
                            
    def addFaceUI(self,sign):
        if sign:
            faceCon = faceCoustom()
            signStr = rig.textField(self.faceUI.bsFaceTF,q = True,tx = True)
            if signStr:
                strShape = signStr.split(' ')
                faceCon.extraE = strShape
            faceGrp = faceCon.merging()
            con = rig.group(faceGrp,n = 'Face_ALL_M_CON_GRP')
            rig.xform(con,ro = (-90,-180,0),wd = True)
            rig.xform(con,t = (-1.538,0,-4.267),wd = True)            
            
            
            
    def combine(self):
        self.FaceCon = self.createFaceCon()
        self.grpName = rig.group(n = 'face_Postion',empty = True)
        
        self.addMainController()
        self.addEyebrow(self.eyebrowSn)
        rig.parent(self.grpName,self.FaceCon)
        self.creatJawjoint()
        self.addEye(self.eyeSn)
        self.addTongue(self.tongueSign)
        self.addTooth(self.toothSn)
        self.addFaceUI(self.faceSn)
Ejemplo n.º 7
0
class FC_FaceSetup(object):
    def __init__(self,
                 eyeSign,
                 tongueSign,
                 faceSign,
                 eyebrowSign,
                 toothSign,
                 face,
                 signRun=True):
        self.Lock = LockHideAttr(False, False, False, False)
        self.eyeSn = eyeSign
        self.tongueSign = tongueSign
        self.faceSn = faceSign
        self.eyebrowSn = eyebrowSign
        self.toothSn = toothSign
        self.face = face
        if signRun:
            self.combine()

    def distanceBetween(self, parA, parB):
        Apos = rig.xform(parA, q=True, t=True, ws=True)
        Bpos = rig.xform(parB, q=True, t=True, ws=True)
        dis = math.sqrt((Apos[0] - Bpos[0])**2 + (Apos[1] - Bpos[1])**2 +
                        (Apos[2] - Bpos[2])**2)
        return dis

    def getTFstr(self, inputData):
        data = rig.textField(inputData, q=True, tx=True)
        return data

    def genBaseFace(self, mesh):
        skinMesh = rig.duplicate(mesh, n=mesh + '_Skin_Mesh')[0]
        self.skinMesh = skinMesh
        self.Mesh = mesh
        rig.transferAttributes(self.Mesh,
                               self.skinMesh,
                               transferUVs=1,
                               sampleSpace=5)
        rig.select(self.skinMesh)
        mel.eval('DeleteHistory')
        skinMeshShape = rig.listRelatives(skinMesh, s=True, ni=True)[0]
        meshShape = rig.listRelatives(mesh, s=True, ni=True)[0]

        self.scaleVal = self.distanceBetween('Lf_ear_P',
                                             'Rt_ear_P') / 3.39395596416
        FaceFolScale = rig.group(empty=True, n='Face_Scale_Grp')
        FaceDeformersGrp = rig.group(empty=True, n='Face_Deformers_Grp')
        self.faceRig = rig.group(empty=True, n='Face_Rigging_GRP')
        rig.addAttr(FaceFolScale, at='float', ln='scaleVal', dv=self.scaleVal)
        rig.addAttr(FaceFolScale, at='float', ln='signA', dv=11)
        rig.addAttr(FaceFolScale, at='float', ln='signB', dv=22)
        self.controller = CreateControler(
            13,
            [0.05 * self.scaleVal, 0.05 * self.scaleVal, 0.05 * self.scaleVal])

        cons = [
            objCon for objCon in [
                obj for obj in rig.ls(type='transform')
                if rig.attributeQuery('sign', n=obj, ex=True)
            ] if (78 == rig.getAttr(objCon +
                                    '.sign') or 71 == rig.getAttr(objCon +
                                                                  '.sign'))
        ]

        CLM = rig.createNode('closestPointOnMesh', n='Face_CLM', ss=True)
        rig.connectAttr(meshShape + '.outMesh', CLM + '.inMesh')

        JNTS = []
        FOLS = []
        EXFOLS = []
        self.allCons = []
        for con in cons:
            pos = rig.xform(con, q=True, t=True, ws=True)
            rig.setAttr(CLM + '.inPositionX', pos[0])
            rig.setAttr(CLM + '.inPositionY', pos[1])
            rig.setAttr(CLM + '.inPositionZ', pos[2])
            U = rig.getAttr(CLM + '.result.parameterU')
            V = rig.getAttr(CLM + '.result.parameterV')

            FOLShape = rig.createNode('follicle', n=con + '_FOLShape', ss=True)
            rig.connectAttr(meshShape + '.worldMesh[0]',
                            FOLShape + '.inputMesh')
            FOL = rig.listRelatives(FOLShape, p=True)[0]
            rig.connectAttr(FaceFolScale + '.scale', FOL + '.scale')
            rig.connectAttr(meshShape + '.worldMatrix[0]',
                            FOL + '.inputWorldMatrix')
            newFol = rig.rename(FOL, con + '_FOL')
            rig.connectAttr(FOLShape + '.outTranslate', newFol + '.translate')
            rig.connectAttr(FOLShape + '.outRotate', newFol + '.rotate')
            rig.setAttr(FOLShape + '.parameterU', U)
            rig.setAttr(FOLShape + '.parameterV', V)
            rig.setAttr(FOLShape + '.simulationMethod', 0)

            #        创建控制器
            CurConName = con.replace('_P', '_M')
            ConName = self.controller.SK_b03(CurConName)
            if 78 == rig.getAttr(con + '.sign'):
                rig.connectAttr(FaceFolScale + '.signA', ConName + '.sign')
            else:
                rig.connectAttr(FaceFolScale + '.signB', ConName + '.sign')
            ConNameShape = rig.listRelatives(ConName, s=True)[0]
            ConColor = rig.getAttr(
                rig.listRelatives(con, s=True)[0] + '.overrideColor')
            rig.setAttr(ConNameShape + '.overrideColor', ConColor)
            ConGRP = rig.group(ConName, n=ConName + '_GRP')
            MirrorGRP = rig.group(ConGRP, n=ConName + '_Mirror_GRP')

            #        生�骨骼
            rig.select(cl=True)
            FOLMatrix = rig.getAttr(FOLShape + '.worldMatrix[0]')
            jntName = rig.joint(n=CurConName + '_JNT')
            JNTGrp = rig.group(jntName, n=jntName + '_GRP')

            rig.parent(JNTGrp, ConName)
            rig.xform(MirrorGRP, matrix=FOLMatrix)
            rig.parent(MirrorGRP, FOL)

            rig.setAttr(jntName + '.visibility', 0)
            rig.setAttr(FOLShape + '.visibility', 0)
            if 11 == rig.getAttr(ConName + '.sign'):
                JNTS.append(jntName)
            else:
                EXFOLS.append(FOLShape)
            FOLS.append(FOL)
            self.allCons.append(ConName)

        SkinClus = rig.skinCluster(JNTS, skinMesh, n='Face_BlendShape_SKIN')[0]
        infs = rig.skinCluster(SkinClus, q=True, inf=True)
        for i, inf in enumerate(infs):
            MirrorGRP = inf.replace('_M_JNT', '_M_Mirror_GRP')
            rig.connectAttr(MirrorGRP + '.worldInverseMatrix[0]',
                            SkinClus + '.bindPreMatrix[' + str(i) + ']')

            #            if 'Rt' == MirrorGRP.split('_')[0]:
            #                rig.setAttr(MirrorGRP+'.sx',-1)
            #                rig.setAttr(MirrorGRP+'.sy',-1)
            #            if 'Lf' == MirrorGRP.split('_')[0]:
            #                rig.setAttr(MirrorGRP+'.rx',180)
            #                rig.setAttr(MirrorGRP+'.sz',-1)

            #            校正控制器轴向到世界
            #            rig.rotate(0,0,0,MirrorGRP,ws = True)
            #            校正控制器轴向到法线向上方向指向世界的Y方向。
            #            MirrorMatrix = rig.getAttr(MirrorGRP+'.worldMatrix[0]')
            #            aimEmptyGrp = rig.group(n = MirrorGRP+'_Aim',empty = True)
            #            rig.xform(aimEmptyGrp,matrix = MirrorMatrix)
            #            rig.parent(aimEmptyGrp,MirrorGRP)
            #            rig.setAttr(aimEmptyGrp+'.tz',1)
            #            rig.parent(aimEmptyGrp,w = True)
            #            rig.aimConstraint(aimEmptyGrp,MirrorGRP,aimVector = (0,0,1),upVector = (0,1,0),worldUpType = 'scene')
            #            rig.delete(aimEmptyGrp)

            #            根据规定的轴向校正
            SK_ConOrientation(MirrorGRP.replace('_Mirror_GRP', ''))

        if EXFOLS:
            for fol in EXFOLS:
                rig.connectAttr(skinMeshShape + '.worldMesh[0]',
                                fol + '.inputMesh',
                                f=True)
                MirrorGRP = fol.replace('_P_FOLShape', '_M_Mirror_GRP')
                #                rig.setAttr(childGrp+'.sz',-1)

                #               校正控制器轴向到世界
                #               rig.rotate(0,0,0,MirrorGRP,ws = True)
                #               校正控制器轴向到法线向上方向指向世界的Y方向。
                #                MirrorMatrix = rig.getAttr(MirrorGRP+'.worldMatrix[0]')
                #                aimEmptyGrp = rig.group(n = MirrorGRP+'_Aim',empty = True)
                #                rig.xform(aimEmptyGrp,matrix = MirrorMatrix)
                #                rig.parent(aimEmptyGrp,MirrorGRP)
                #                rig.setAttr(aimEmptyGrp+'.tz',1)
                #                rig.parent(aimEmptyGrp,w = True)
                #                rig.aimConstraint(aimEmptyGrp,MirrorGRP,aimVector = (0,0,1),upVector = (0,1,0),worldUpType = 'scene')
                #                rig.delete(aimEmptyGrp)

                #                根据规定的轴向校正
                SK_ConOrientation(MirrorGRP.replace('_Mirror_GRP', ''))

        FOLALLGRP = rig.group(FOLS, n='All_FOLS_GRP')
        rig.parent(FaceFolScale, self.Mesh, self.skinMesh, FOLALLGRP,
                   FaceDeformersGrp)

    def findSkinCluster(self, Mesh):
        skinName = ''
        hisNode = rig.listHistory(Mesh, pdo=True)
        if hisNode:
            sign = [
                skinCL for skinCL in rig.listHistory(Mesh, pdo=True)
                if ('skinCluster' == rig.nodeType(skinCL))
            ]
            if sign:
                skinName = sign[0]
        return skinName

    def connectFaceModel(self, skinModel):
        rig.select(cl=True)
        rig.hide('Mid_base_M')
        jawHeads = [u'HeadRoot_JNT_P', u'Jaw_JNT_P', u'JawTip_JNT_P']
        for jnt in jawHeads:
            pos = rig.xform(jnt, q=True, t=True, ws=True)
            NJnt = rig.joint(n=jnt.replace('_JNT_P', '_JNT'))
            rig.xform(NJnt, t=pos, ws=True)
            if 'Jaw_JNT_P' == jnt:
                jawUP = rig.joint(n=jnt.replace('_JNT_P', '_UP_JNT'))
                rig.xform(jawUP, t=pos, ws=True)
                jawUPA = rig.joint(n=jnt.replace('_JNT_P', '_UPA_JNT'))
                rig.xform(jawUPA, t=pos, ws=True)
                jawUPB = rig.joint(n=jnt.replace('_JNT_P', '_UPB_JNT'))
                rig.xform(jawUPB, t=pos, ws=True)

        jaw = 'Jaw_M'
        rig.addAttr(jaw, at='enum', ln='vis_second', en='OFF:ON', k=False)
        rig.setAttr(jaw + '.vis_second', cb=True)
        jawPos = rig.xform(jaw, q=True, piv=True, ws=True)[0:3]
        rig.xform('JawTip_JNT', t=jawPos, ws=True)
        rig.parent(jaw, w=True)
        rig.makeIdentity(jaw, apply=True, t=True, s=True, r=True)

        IK = rig.ikHandle(sj='Jaw_UPB_JNT', ee='JawTip_JNT', n='Jaw_IK')[0]
        rig.parent(IK, jaw)
        rig.connectAttr(jaw + '.rz', IK + '.twist')
        rig.connectAttr(jaw + '.tz', 'Jaw_UPA_JNT' + '.tz')

        sign = self.findSkinCluster(skinModel)
        if sign:
            rig.skinCluster(sign, e=True, ai='Jaw_UPB_JNT', lw=True, wt=0)
        else:
            rig.skinCluster('Jaw_UPB_JNT',
                            'HeadRoot_JNT',
                            skinModel,
                            tsb=True,
                            n='Jaw_Skin')
        rig.blendShape(skinModel,
                       self.skinMesh,
                       w=(0, 1),
                       n='SKIN_BS',
                       foc=True)
        rig.blendShape(skinModel, self.Mesh, w=(0, 1), n='Mesh_BS')

        grpA = rig.group(jaw, n=jaw + '_GRPA', r=True)
        grpB = rig.group(grpA, n=jaw + '_GRPB', r=True)
        jntGrp = rig.group('HeadRoot_JNT', n='Head_JNT_GRP', r=True)
        rig.hide(jntGrp)
        rig.hide(IK)
        rig.parent(grpB, jntGrp, self.faceRig)

        allCons = self.allCons
        for con in allCons:
            rig.connectAttr(jaw + '.vis_second',
                            rig.listRelatives(con, p=True)[0] + '.visibility')

        self.Lock.hideInvertAttr(jaw, ('translateZ', 'translateY',
                                       'translateX', 'rotateZ', 'vis_Second'))

        rig.parent(skinModel, 'Face_Deformers_Grp')

    def eyeSetup(self, LfEye, RtEye):
        LfPos = rig.xform('Lf_EYE_JNT_P', q=True, t=True, ws=True)
        rig.select(cl=True)
        LfJnt = rig.joint(n='Lf_EYE_JNT')
        rig.xform(LfJnt, t=LfPos, ws=True)
        RtPos = rig.xform('Rt_EYE_JNT_P', q=True, t=True, ws=True)
        rig.select(cl=True)
        RtJnt = rig.joint(n='Rt_EYE_JNT')
        rig.xform(RtJnt, t=RtPos, ws=True)

        LfLoc = rig.spaceLocator(n=LfJnt + '_Loc')[0]
        RtLoc = rig.spaceLocator(n=RtJnt + '_Loc')[0]
        LfLocPos = (LfPos[0], LfPos[1] + self.scaleVal, LfPos[2])
        rig.xform(LfLoc, t=LfLocPos, ws=True)
        RtLocPos = (RtPos[0], RtPos[1] + self.scaleVal, RtPos[2])
        rig.xform(RtLoc, t=RtLocPos, ws=True)
        locEyeGrp = rig.group(LfLoc, RtLoc, n='Eye_LOC_GRP')
        rig.hide(locEyeGrp)

        eyeCon = 'eye_M'
        rig.addAttr(eyeCon,
                    at='enum',
                    ln='follow',
                    en='OFF:ON',
                    k=False,
                    dv=True)
        rig.setAttr(eyeCon + '.follow', cb=True)
        LfCon = 'Lf_eye_M'
        RtCon = 'Rt_eye_M'
        rig.parent(eyeCon, w=True)
        rig.setAttr(eyeCon + '.rx', 0)
        eyegroupA = rig.group(eyeCon, n='eye_GoupA', r=True)
        eyegroupB = rig.group(eyegroupA, n='eye_GoupB', r=True)
        Lf_conGrp = rig.group(LfCon, n=LfCon + '_GRP', r=True)
        Rt_conGrp = rig.group(RtCon, n=RtCon + '_GRP', r=True)

        grpL = rig.group('Lf_EYE_JNT', n='Eye_JNT_GRPL', r=True)
        grpR = rig.group('Rt_EYE_JNT', n='Eye_JNT_GRPR', r=True)
        rig.parent(grpL, grpR, locEyeGrp, eyegroupB, self.faceRig)

        rig.makeIdentity(eyegroupA, apply=True, s=True, t=True, r=True)
        #        aimConstraint
        rig.aimConstraint(LfCon,
                          LfJnt,
                          aimVector=(1, 0, 0),
                          upVector=(0, 1, 0),
                          worldUpType='object',
                          worldUpObject=LfLoc)
        rig.aimConstraint(RtCon,
                          RtJnt,
                          aimVector=(1, 0, 0),
                          upVector=(0, 1, 0),
                          worldUpType='object',
                          worldUpObject=RtLoc)

        #       skin
        if (LfEye and RtEye):
            rig.skinCluster(LfJnt, LfEye, tsb=True)
            rig.skinCluster(RtJnt, RtEye, tsb=True)

        RV = rig.createNode('reverse', n='EYE_C_RV', ss=True)
        rig.scaleConstraint(self.faceRig, 'Face_Scale_Grp', mo=True)
        parentNode = rig.parentConstraint(self.faceRig,
                                          'Face_Scale_Grp',
                                          eyegroupA,
                                          mo=True)[0]
        rig.connectAttr(eyeCon + '.follow',
                        parentNode + '.' + self.faceRig + 'W0')
        rig.connectAttr(RV + '.output.outputX',
                        parentNode + '.' + 'Face_Scale_Grp' + 'W1')
        rig.connectAttr(eyeCon + '.follow', RV + '.input.inputX')

    def toothSetup(self, upTooth, dnTooth):
        UpTooth = 'UpTooth_JNT_P'
        DnTooth = 'DnTooth_JNT_P'
        upPos = rig.xform(UpTooth, q=True, t=True, ws=True)
        dnPos = rig.xform(DnTooth, q=True, t=True, ws=True)
        rig.select(cl=True)
        upJnt = rig.joint(n=UpTooth.replace('_P', ''))
        rig.xform(upJnt, t=upPos, ws=True)
        rig.select(cl=True)
        dnJnt = rig.joint(n=DnTooth.replace('_P', ''))
        rig.xform(dnJnt, t=dnPos, ws=True)

        #        nurbsControl
        self.controller.setColor(6)
        self.controller.setObjScale(
            [0.2 * self.scaleVal, 0.2 * self.scaleVal, -0.2 * self.scaleVal])
        upCon = self.controller.SK_b09('UpTooth_M')
        dnCon = self.controller.SK_b09('DnTooth_M')
        rig.xform(upCon, t=upPos, ws=True)
        rig.xform(dnCon, t=dnPos, ws=True)
        upGrp = rig.group(upCon, n=upCon + 'GRP', r=True)
        dnGrp = rig.group(dnCon, n=dnCon + 'GRP', r=True)
        rig.makeIdentity(upCon,
                         apply=True,
                         s=True,
                         r=True,
                         t=True,
                         jointOrient=True)
        rig.makeIdentity(dnCon,
                         apply=True,
                         s=True,
                         r=True,
                         t=True,
                         jointOrient=True)

        rig.parent(upJnt, upCon)
        rig.parent(dnJnt, dnCon)
        rig.connectAttr('Jaw_M.vis_second', upGrp + '.visibility')
        rig.connectAttr('Jaw_M.vis_second', dnGrp + '.visibility')
        rig.skinCluster(upJnt, upTooth, tsb=True, n='UpTooth_Skin')
        rig.skinCluster(dnJnt, dnTooth, tsb=True, n='DnTooth_Skin')

        #        rig.parent(dnGrp,'Jaw_UPB_JNT')
        rig.parent(upGrp, dnGrp, self.faceRig)
        rig.parentConstraint('Jaw_UPB_JNT', dnGrp, mo=True)

    def tongueSetup(self, tongue):
        JNT = 'Tongue_1_JNT_P'
        cons = rig.listRelatives(JNT, c=True, ad=True)
        cons.append('Tongue_1_JNT_P')
        rig.select(cl=True)
        sign = ''
        conGrp = []
        NewJNTS = []
        for con in cons:
            pos = rig.xform(con, q=True, t=True, ws=True)
            jnt = rig.joint(n=con.replace('_P', ''))
            self.controller.setColor(15)
            jntCon = self.controller.SK_b08(jnt + '_M')
            rig.setAttr(jntCon + '.rx', 90)
            rig.xform(jntCon, t=pos, ws=True)
            rig.xform(jnt, t=pos, ws=True)
            rig.parent(jnt, jntCon)
            conUpGrp1 = rig.group(jntCon, n=jntCon + '_GRP1', r=True)
            conUpGrp2 = rig.group(conUpGrp1, n=jntCon + '_GRP2', r=True)

            if sign:
                rig.parent(sign, jnt)
            sign = conUpGrp2

            conGrp.append(conUpGrp1)
            NewJNTS.append(jnt)

        con = 'Tongue_M'
        rig.addAttr(con, at='enum', ln='vis_second', en='OFF:ON:', k=False)
        rig.setAttr(con + '.vis_second', cb=True)
        rig.makeIdentity('Tongue_1_JNT_M_GRP2',
                         apply=True,
                         t=True,
                         r=True,
                         s=True,
                         jointOrient=True)
        rig.connectAttr(con + '.vis_second', 'Tongue_1_JNT_M_GRP2.visibility')
        rig.select(cl=True)

        sc = self.scaleVal
        rig.parent(con, w=True)
        rig.makeIdentity(con, apply=True, s=True, r=True, t=True)

        #        newConGrp:组为排除根部第一个组
        removeGrp = conGrp[-1]
        newConGrp = conGrp.remove(removeGrp)

        conSR = rig.createNode('setRange', n='TongueRG', ss=True)
        rig.connectAttr(con + '.tx', conSR + '.valueX')
        rig.connectAttr(con + '.ty', conSR + '.valueY')
        rig.connectAttr(con + '.tz', conSR + '.valueZ')
        rig.setAttr(conSR + '.oldMaxX', 0.5 * sc)
        rig.setAttr(conSR + '.oldMaxY', 0.5 * sc)
        rig.setAttr(conSR + '.oldMaxZ', 2 * sc)
        rig.setAttr(conSR + '.oldMinX', -0.5 * sc)
        rig.setAttr(conSR + '.oldMinY', -0.5 * sc)
        rig.setAttr(conSR + '.oldMinZ', -2 * sc)
        rig.setAttr(conSR + '.maxX', 20)
        rig.setAttr(conSR + '.maxY', -20)
        rig.setAttr(conSR + '.maxZ', 0.5 * sc)
        rig.setAttr(conSR + '.minX', -20)
        rig.setAttr(conSR + '.minY', 20)
        rig.setAttr(conSR + '.minZ', -0.5 * sc)

        #        连接舌头的旋转
        for grp in conGrp:
            addName = grp.split('_JNT_')[0]
            rig.addAttr(con, at='float', ln=addName, dv=1)
            rig.addAttr(grp, at='float', ln='SV', dv=1)
            rig.connectAttr(con + '.' + addName, grp + '.SV')

            rig.connectAttr(con + '.rz', grp + '.rz')
            MD = rig.createNode('multiplyDivide', n=grp + '_MD', ss=True)
            rig.connectAttr(grp + '.SV', MD + '.input1X')
            rig.connectAttr(con + '.rx', MD + '.input2X')
            rig.connectAttr(MD + '.outputX', grp + '.rx')

            rig.connectAttr(grp + '.SV', MD + '.input1Y')
            rig.connectAttr(con + '.ry', MD + '.input2Y')
            rig.connectAttr(MD + '.outputY', grp + '.ry')

            rig.connectAttr(conSR + '.outValue.outValueZ', grp + '.tz')

#        连接舌头的位移和缩放
        rig.connectAttr(con + '.tx', 'Tongue_1_JNT_M_GRP1.tx')
        rig.connectAttr(con + '.ty', 'Tongue_1_JNT_M_GRP1.ty')
        rig.connectAttr(con + '.sx', 'Tongue_1_JNT_M_GRP1.sx')
        rig.connectAttr(con + '.sy', 'Tongue_1_JNT_M_GRP1.sy')
        rig.connectAttr(con + '.sz', 'Tongue_1_JNT_M_GRP1.sz')

        rig.transformLimits(con, tx=(-1 * 0.5 * sc, 0.5 * sc), erx=(1, 1))
        rig.transformLimits(con, tx=(-1 * 0.5 * sc, 0.5 * sc), etx=(1, 1))
        rig.transformLimits(con, ty=(-1 * 0.5 * sc, 0.5 * sc), erx=(1, 1))
        rig.transformLimits(con, ty=(-1 * 0.5 * sc, 0.5 * sc), ety=(1, 1))
        rig.transformLimits(con, tz=(-1 * 0.5 * sc, 0.5 * sc), erx=(1, 1))
        rig.transformLimits(con, tz=(-1 * 2.0 * sc, 2.0 * sc), etz=(1, 1))

        rig.skinCluster(NewJNTS, tongue, tsb=True, n='Tongue_Skin')

        grpA = rig.group(con, n=con + '_GRPA', r=True)
        grpB = rig.group(grpA, n=con + '_GRPB', r=True)
        rig.parent(grpB, 'Tongue_1_JNT_M_GRP2', self.faceRig)
        rig.parentConstraint('Jaw_UPB_JNT', 'Tongue_1_JNT_M_GRP2', mo=True)
        self.Lock.hideInvertAttr(
            con,
            ('translateZ', 'translateY', 'translateX', 'vis_Second', 'rotateX',
             'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ'))

    def eyebrowSetup(self, lfEyebrow, rtEyebrow):
        SV = rig.getAttr('Face_Scale_Grp.scaleVal')
        LfJnts = rig.ls('Lf_ebw_*_M_JNT')
        LfCons = rig.ls('Lf_ebw_*_M')
        LfAkinMesh, LfAkinJnt, LfAllGrp, LfNewCons = SK_FollicleControl(
            LfCons, 2, SV, 'Lf_eyeBrow', 'Lf_eyeBrow_Loft', 'Face_Scale_Grp')
        RtJnts = rig.ls('Rt_ebw_*_M_JNT')
        RtCons = rig.ls('Rt_ebw_*_M')
        RtAkinMesh, RtAkinJnt, RtAllGrp, RtNewCons = SK_FollicleControl(
            RtCons, 2, SV, 'Rt_eyeBrow', 'Rt_eyeBrow_Loft', 'Face_Scale_Grp')

        #生成blendShape
        LfUP = rig.duplicate(LfAkinMesh, n=LfAkinMesh + '_UP')
        LfDN = rig.duplicate(LfAkinMesh, n=LfAkinMesh + '_DN')
        LfLF = rig.duplicate(LfAkinMesh, n=LfAkinMesh + '_LF')
        LfRT = rig.duplicate(LfAkinMesh, n=LfAkinMesh + '_RT')
        RtUP = rig.duplicate(RtAkinMesh, n=RtAkinMesh + '_UP')
        RtDN = rig.duplicate(RtAkinMesh, n=RtAkinMesh + '_DN')
        RtLF = rig.duplicate(RtAkinMesh, n=RtAkinMesh + '_LF')
        RtRT = rig.duplicate(RtAkinMesh, n=RtAkinMesh + '_RT')
        rig.blendShape(LfUP,
                       LfDN,
                       LfLF,
                       LfRT,
                       LfAkinMesh,
                       n=LfAkinMesh + '_BS')
        rig.blendShape(RtUP,
                       RtDN,
                       RtLF,
                       RtRT,
                       RtAkinMesh,
                       n=RtAkinMesh + '_BS')

        rig.skinCluster(LfJnts, LfAkinMesh, tsb=True, n='Lf_eyeBrow_M_Skin')
        rig.skinCluster(LfAkinJnt, lfEyebrow, tsb=True, n='Lf_eyeBrow_Skin')
        rig.skinCluster(RtJnts, RtAkinMesh, tsb=True, n='Rt_eyeBrow_M_Skin')
        rig.skinCluster(RtAkinJnt, rtEyebrow, tsb=True, n='Rt_eyeBrow_Skin')
        #        隐藏以前眉毛控制器
        LfCons.extend(RtCons)
        LfNewCons.extend(RtNewCons)
        rig.addAttr('All_FOLS_GRP',
                    at='enum',
                    ln='eyeBrow_Vis',
                    en='OFF:ON:',
                    k=True,
                    dv=0)
        for i, con in enumerate(LfCons):
            conShape = rig.listRelatives(con, s=True)[0]
            rig.setAttr(conShape + '.overrideColor', 6)
            rig.connectAttr('All_FOLS_GRP.eyeBrow_Vis', con + '.visibility')
            UpCon = rig.listRelatives(LfNewCons[i], p=True)[0]
            rig.connectAttr('Jaw_M.vis_second', UpCon + '.visibility')

        rig.parent(LfAllGrp, RtAllGrp, 'All_FOLS_GRP')

    def faceBsSetup(self, faceInfo):

        pass

    def extraControl(self):
        rig.setAttr('Face_Con.visibility', 0)

    def combine(self):
        head = self.getTFstr(self.face.headTF)
        skinHead = self.getTFstr(self.face.skinHeadTF)
        lfEye = self.getTFstr(self.face.loadLfEyeTF)
        rtEye = self.getTFstr(self.face.loadRtEyeTF)
        upTooth = self.getTFstr(self.face.loadUpToothTF)
        dnTooth = self.getTFstr(self.face.loadDnToothTF)
        lfEyebrow = self.getTFstr(self.face.loadLfEyebrowTF)
        rtEyebrow = self.getTFstr(self.face.loadRtEyebrowTF)
        tongue = self.getTFstr(self.face.loadTongueTF)
        faceInfo = self.getTFstr(self.face.bsFaceTF)

        self.genBaseFace(head)
        self.connectFaceModel(skinHead)
        if self.eyeSn:
            self.eyeSetup(lfEye, rtEye)
        if self.toothSn:
            self.toothSetup(upTooth, dnTooth)
        if self.toothSn:
            self.tongueSetup(tongue)
        if self.eyebrowSn:
            self.eyebrowSetup(lfEyebrow, rtEyebrow)
        if self.faceSn:
            self.faceBsSetup(faceInfo)
        self.extraControl()
Ejemplo n.º 8
0
class BuildEyeController():
    def __init__(self):
        self.controller = CreateControler()
        self.grp = 'Eye_Control_GRP'
        self.ctrlName = 'Eye_M'
        self.num = 3
        self.conPos = [
            (0.0, 16.623626770105922, 4.1056612661848035),
            (0.47205042927365248, 16.623626770105922, 4.1056612661848035),
            (-0.47205042927365248, 16.623626770105922, 4.1056612661848035)
        ]
        self.jointPos = [
            ([0, 16.600944519043441, 1.3624849915501727]),
            (0.47289100288351393, 16.600944519043441, 1.3624849915501727),
            (-0.47289100288351393, 16.600944519043441, 1.3624849915501727)
        ]
        self.Lf_LidPos = [[
            0.51449495125093525, 16.614712948647536, 1.6282982423800447
        ], [0.51446175243023684, 16.524417626257684, 1.6211440872455507]]
        self.Rt_LidPos = [[
            -0.51449495125093525, 16.614712948647536, 1.6282982423800447
        ], [-0.51446175243023684, 16.524417626257684, 1.6211440872455507]]

    def getController(self):  #得到控制器名
        if self.num == 1:
            self.NewCons = [self.ctrlName]
        if self.num > 1:
            self.NewCons = []
            LfNum = 0  #左边编号
            RtNum = 0  #右边编号
            for i in range(self.num):
                if 0 == i:
                    self.NewCons.append(self.ctrlName)
                else:
                    mainPre = self.ctrlName.split('_')[0]
                    if i % 2:
                        self.NewCons.append('Lf_' + mainPre + '_' +
                                            str(LfNum) + 'M')
                        LfNum += 1
                    else:
                        self.NewCons.append('Rt_' + mainPre + '_' +
                                            str(RtNum) + 'M')
                        RtNum += 1

    def createCons(self):  #生成所有控制器
        for con in self.NewCons:
            if 'Lf_' == con[0:3]:
                self.controller.setColor(6)
                ts = self.conPos[1]
                jntPos = self.jointPos[1]
                sc = [1, 1, 1]
                self.eyelip(con, True)
            elif 'Rt_' == con[0:3]:
                self.controller.setColor(6)
                ts = self.conPos[2]
                jntPos = self.jointPos[2]
                sc = [1, 1, 1]
                self.eyelip(con, False)
            else:
                self.controller.setColor(13)  #对控制器设置颜色
                ts = self.conPos[0]
                jntPos = self.jointPos[0]
                sc = [4.373, 1, 1.828]

            rt = [90, 1, 1]
            self.singeCon(con, rt, ts, sc)

            #生成眼睛骨骼
            rig.select(cl=True)
            jntName = rig.joint(p=jntPos,
                                n=re.compile('M\Z').sub('Joint', con))
            self.connectAddAttr(jntName, 'CTRLJoint')  #连接属性

    def eyelip(self, name, UpDn):  #增加眼皮控制器
        if UpDn:
            UpPos = self.Lf_LidPos[0]
            DnPos = self.Lf_LidPos[1]
        else:
            UpPos = self.Rt_LidPos[0]
            DnPos = self.Rt_LidPos[1]

        self.controller.setObjScale([
            0.05,
            0.05,
            0.05,
        ])  #对控制器进行缩放
        self.controller.signValue = 1258
        Con = self.controller.SK_b03(name.replace('_Eye', '_UpLid'))
        self.connectAddAttr(Con, 'CTRLCurve')  #连接属性
        rig.xform(Con, t=UpPos, ws=True)
        Con = self.controller.SK_b03(name.replace('_Eye', '_DnLid'))
        self.connectAddAttr(Con, 'CTRLCurve')  #连接属性
        rig.xform(Con, t=DnPos, ws=True)

    def singeCon(self, name, rt, ts, sc):  #生成控制器

        self.controller.setObjScale([i * 0.135 for i in sc])  #对控制器进行缩放
        self.controller.signValue = 1548
        Con = self.controller.SK_b08(name)
        self.connectAddAttr(Con, 'CTRLCurve')  #连接属性
        rig.xform(Con, t=ts, ws=True)
        rig.xform(Con, ro=rt, ws=True)

    def createEmptyGrp(self):  #生成空组
        if rig.objExists(self.grp):
            self.grpName = self.grp
        else:
            self.grpName = rig.group(empty=True, n=self.grp)

    def connectAddAttr(self, AddObj, Attr):  #增加并连接属性
        rig.addAttr(AddObj, at='long', ln=Attr)
        if not rig.attributeQuery(Attr, node=self.grpName, ex=True):
            rig.addAttr(self.grpName, at='long', ln=Attr)
        rig.connectAttr(self.grpName + '.' + Attr, AddObj + '.' + Attr)

    def extraAddControl(self):
        posInfo = [
            [0.73614344582613733, 16.604239304623771, 1.4948541970870548],
            [0.65308174148532172, 16.645676611373496, 1.5729513008857312],
            [0.54766851673494632, 16.64837652763509, 1.6214938988508214],
            [0.44244251319713446, 16.643562775959364, 1.619578378724102],
            [0.32071235980511059, 16.597797824873869, 1.596789667911807],
            [0.4362284617401162, 16.559762331346164, 1.6209728592220456],
            [0.54223046060668201, 16.550345353518203, 1.6173481804777063],
            [0.64635945406333351, 16.546858303215856, 1.5722915627040193]
        ]
        LfName = [
            'Lf_CornerInLidMin_0', 'Lf_UpLidMin_1', 'Lf_UpLidMin_2',
            'Lf_UpLidMin_3', 'Lf_CornerOutLidMin_0', 'Lf_DnLidMin_3',
            'Lf_DnLidMin_2', 'Lf_DnLidMin_1'
        ]
        RtName = [
            'Rt_CornerInLidMin_0', 'Rt_UpLidMin_1', 'Rt_UpLidMin_2',
            'Rt_UpLidMin_3', 'Rt_CornerOutLidMin_0', 'Rt_DnLidMin_3',
            'Rt_DnLidMin_2', 'Rt_DnLidMin_1'
        ]

        for i, pos in enumerate(posInfo):
            self.controller.setColor(13)
            self.controller.setObjScale([
                0.02,
                0.02,
                0.02,
            ])  #对控制器进行缩放
            self.controller.signValue = 11548
            LfCon = self.controller.SK_b03(LfName[i] + 'M')
            RtCon = self.controller.SK_b03(RtName[i] + 'M')
            self.connectAddAttr(LfCon, 'CTRLCurve')  #连接属性
            self.connectAddAttr(RtCon, 'CTRLCurve')  #连接属性
            rig.xform(LfCon, t=pos, ws=True)
            pos[0] = pos[0] * -1
            rig.xform(RtCon, t=pos, ws=True)

    def Groups(self):  #整理层级
        CTRLCurves = rig.listConnections(self.grpName + '.CTRLCurve',
                                         s=False,
                                         d=True)
        CA.freezeObj().freeze(CTRLCurves)
        CTRLJoints = rig.listConnections(self.grpName + '.CTRLJoint',
                                         s=False,
                                         d=True)

        CTRLCurveGRP = rig.group(CTRLCurves, n=self.grpName + '_CTRLCurve')
        CTRLJointGRP = rig.group(CTRLJoints, n=self.grpName + '_CTRLJoint')

        mainCons = [con for con in CTRLCurves if re.match('Eye_M', con)]
        secCons = [
            con for con in CTRLCurves
            if re.match('\ALf_Eye_\d+M|\ARt_Eye_\d+M', con)
        ]
        if secCons:
            rig.parent(secCons, mainCons[0])

        rig.parent(CTRLCurveGRP, CTRLJointGRP, self.grpName)

    def done(self):
        self.createEmptyGrp()  #生成空组
        self.getController()
        self.createCons()
        self.extraAddControl()  #增加眼睛周围的控制器
        self.Groups()  #整理层级