示例#1
0
文件: bumbleBee.py 项目: mappp7/tools
    def etc_set(self):
        ### attribute
        # sup con vis
        for x in range(8):
            cmds.addAttr(TP.AA['PL'][x],
                         ln='sub_con_vis',
                         at='enum',
                         en='off:on:')
            cmds.setAttr(TP.AA['PL'][x] + '.sub_con_vis', e=1, keyable=1)
            cmds.connectAttr(TP.AA['PL'][x] + '.sub_con_vis',
                             TP.AA['CL'][x] + '.visibility')
        # FK / IK switch
        for x in range(2):
            switchCon = controllerShape(TP.conVis['key'][x][0] + '_CON',
                                        'cross', 'yellow')
            switchNul = cmds.group(switchCon,
                                   n=TP.conVis['key'][x][0] + '_NUL')
            cmds.delete(cmds.pointConstraint(TP.conVis['key'][x][1],
                                             switchNul))
            cmds.parent(switchNul, TP.conVis['key'][x][1])
            cmds.move(5, 0, 0, ws=1, r=1)
            cmds.addAttr(switchCon,
                         ln=TP.conVis['attr'][0],
                         at='enum',
                         en='off:on:')
            cmds.setAttr(switchCon + '.' + TP.conVis['attr'][0],
                         e=1,
                         keyable=1)
            cmds.addAttr(switchCon,
                         ln=TP.conVis['attr'][1],
                         at='enum',
                         en='off:on:')
            cmds.setAttr(switchCon + '.' + TP.conVis['attr'][1],
                         e=1,
                         keyable=1)
        for x in range(2):
            top_list = TP.conVis['vis'][x]
            for y in top_list:
                for z in y:
                    if len(y) == 1:
                        cmds.connectAttr(
                            TP.conVis['key'][x][0] + '_CON.' +
                            TP.conVis['attr'][0], z + '.visibility')
                    else:
                        cmds.connectAttr(
                            TP.conVis['key'][x][0] + '_CON.' +
                            TP.conVis['attr'][1], z + '.visibility')
                    cmds.setAttr(TP.conVis['key'][x][0] + '_CON.IK_con_vis', 1)
        ### Parent node
        cmds.group(p='noneTransform_GRP', em=1, n='locator_GRP')
        cmds.parent(TP.noneTrans_list, 'locator_GRP')
        cmds.parent(TP.attach_list, 'attach_GRP')
        cmds.parent(TP.auxillary_list, 'auxillary_GRP')
        cmds.parent(TP.neck_list, 'C_neck_GRP')
        cmds.parent(TP.spine_list, 'C_spine_GRP')
        cmds.parent(TP.L_foreLeg_list, 'L_foreLeg_GRP')
        cmds.parent(TP.R_foreLeg_list, 'R_foreLeg_GRP')
        cmds.parent(TP.L_hindLeg_list, 'L_hindLeg_GRP')
        cmds.parent(TP.R_hindLeg_list, 'R_hindLeg_GRP')
        cmds.parent(TP.tail_list, 'C_tail_GRP')
        cmds.delete(TP.delete_list)
        cmds.select(TP.noneTrans_list, r=1)
        cmds.select('templateJoint_GRP', tgl=1)
        cmds.select(TP.hide_list, tgl=1)
        cmds.select(TP.hide_list2, tgl=1)
        cmds.HideSelectedObjects()

        ### Rotate controler
        self.controlerRotate(TP.rotate_con_list_A, 0, 0, -90)
        self.controlerRotate(TP.rotate_con_list_B, -90, 0, 0)

        ### controler Color
        for x in TP.R_con_list:
            conShapeName = cmds.listRelatives(x, s=1)[0]
            cmds.setAttr(conShapeName + '.overrideEnabled', 1)
            cmds.setAttr(conShapeName + '.overrideColor', 13)
        for x in TP.switch_con_list:
            conShapeName = cmds.listRelatives(x, s=1)[0]
            cmds.setAttr(conShapeName + '.overrideEnabled', 1)
            cmds.setAttr(conShapeName + '.overrideColor', 14)

        ### controler Scale
        for x in TP.scale_con_list:
            scale_value = 2
            CRV_shape_name = cmds.listRelatives(x, s=1)[0]
            CRV_span_num = cmds.getAttr(CRV_shape_name + '.spans')
            cmds.select(x + '.cv[0:%s]' % (CRV_span_num))
            cmds.scale(scale_value, scale_value, scale_value, r=1)

        ### controler Parent
        for x in range(2):
            PL = TP.parent_list['PL'][x]
            for y in TP.parent_list['CL'][x]:
                cmds.parentConstraint(PL, y, mo=1)
        ### hindLeg Parent
        cmds.setAttr('L_rig_hip_JNT.inheritsTransform', 0)
        cmds.setAttr('R_rig_hip_JNT.inheritsTransform', 0)
        itemList = ['.sx', '.sy', '.sz']
        for x in TP.targetjointList:
            for y in itemList:
                cmds.connectAttr('place_CON.globalScale', x + y)
示例#2
0
def main(*args):
    mmSelectedInScene = cmds.ls(sl = 1)

    mmOverallBoundingBoxList = cmds.exactWorldBoundingBox( )
    print "mmOverallBoundingBoxList", mmOverallBoundingBoxList

    mmOverallXMin = mmOverallBoundingBoxList[0]
    mmOverallYMin = mmOverallBoundingBoxList[1]
    mmOverallZMin = mmOverallBoundingBoxList[2]
    mmOverallXMax = mmOverallBoundingBoxList[3]
    mmOverallYMax = mmOverallBoundingBoxList[4]
    mmOverallZMax = mmOverallBoundingBoxList[5]

    #Find size user wants
    #Find total size
    mmOverallXTotal = abs(mmOverallXMax - mmOverallXMin)
    mmOverallYTotal = abs(mmOverallYMax - mmOverallYMin)
    mmOverallZTotal = abs(mmOverallZMax - mmOverallZMin)
    '''
    print "mmBoundingBoxList[5]", mmBoundingBoxList[5]
    print "mmOverallZMax", mmOverallZMax
    print "mmOverallZMin", mmOverallZMin
    print "mmOverallZTotal", mmOverallZTotal
    '''

    #Find halfway point (i.e. center of object)
    mmOverallXMidPoint = mmOverallXMax - mmOverallXTotal/2
    mmOverallYMidPoint = mmOverallYMax - mmOverallYTotal/2
    mmOverallZMidPoint = mmOverallZMax - mmOverallZTotal/2
    '''
    print "mmOverallZMidPoint", mmOverallZMidPoint
    '''

    for mmItem in mmSelectedInScene:
        
        cmds.select(mmItem, r = 1)
        
        mmScaleGrowValueOverall = 0.01
        mmScaleRateOfShrink = 1.05 #Must be higher than 1
        mmCheckerValue = 5
        mmLatticeSize = 10
        
        mmNewLattice = cmds.lattice(  divisions = (mmLatticeSize, mmLatticeSize, mmLatticeSize), objectCentered = True, ldv = ( 2, 2, 2) )

        mmLatticeMax = mmLatticeSize

        mmLatticeHigh = mmLatticeMax-1
        mmLatticeLow = 0

        
        
        mmBoundingBoxList = cmds.exactWorldBoundingBox( )
        #print "mmBoundingBoxList", mmBoundingBoxList

        mmXMin = mmBoundingBoxList[0]
        mmYMin = mmBoundingBoxList[1]
        mmZMin = mmBoundingBoxList[2]
        mmXMax = mmBoundingBoxList[3]
        mmYMax = mmBoundingBoxList[4]
        mmZMax = mmBoundingBoxList[5]

        #Find size user wants
        #Find total size
        mmXTotal = abs(mmXMax - mmXMin)
        mmYTotal = abs(mmYMax - mmYMin)
        mmZTotal = abs(mmZMax - mmZMin)

        #Find halfway point (i.e. center of object)
        mmXMidPoint = mmXMax - mmXTotal/2
        mmYMidPoint = mmYMax - mmYTotal/2
        mmZMidPoint = mmZMax - mmZTotal/2
        
        #print "mmNewLattice[1]", mmNewLattice[1]

        #mmPivot = [ mmXMidPoint, mmYMidPoint, mmZMidPoint ]
        mmCheckFunction = mmOverallZMidPoint - mmZMidPoint
        #print "mmCheckFunction", mmCheckFunction
        #print "mmOverallZMidPoint", mmOverallZMidPoint
        #print "mmZMidPoint", mmZMidPoint
        

        #Modify the pivot point based on various information
        mmXFinalValue = mmXMidPoint
        mmYFinalValue = mmYMidPoint
        mmZFinalValue = mmZMidPoint

        #if the bounding box Ymin of the current selection equates to the bounding box Ymin of the all selections
        if ( mmYMin == mmOverallYMin ):
            
            mmYFinalValue = mmYMin
        
        #if the mmCheckFunction is greater than the mmCheckerValue, than move the pivot to the mmZMax
        if ( mmCheckFunction > mmCheckerValue ):
            
            mmZFinalValue = mmZMax
            
        #if the mmCheckFunction is less than the mmCheckerValue, than move the pivot to the mmZMin
        elif ( mmCheckFunction < mmCheckerValue  ):

            mmZFinalValue = mmZMin
            



        #Setting final values
        mmPivot = [ mmXFinalValue, mmYFinalValue, mmZFinalValue ]        
        
        mmListX = [1]
        mmListY = [0]
        mmListZ = [0]
        
        #print mmListX
        
        #Pass 1 - in X
        mmScaleGrowValue = mmScaleGrowValueOverall
        mmLatticeLow = mmLatticeMax/2-1
        mmLatticeHigh = mmLatticeMax/2
        
        mmScaleGrowValue = mmScaleGrowValueOverall
        
        while ( mmLatticeLow != 0 ):
            #cmds.select( mmNewLattice[1] + ".pt" + str(mmListX) + str(mmListY) + str(mmListZ), r = 1 )
            #print mmNewLattice[1] + ".pt[" + str(mmLatticeLow) +" : " + str(mmLatticeHigh) + "][0:" + str(mmLatticeMax) + "][0:" + str(mmLatticeMax) + "]"
            
            cmds.select( mmNewLattice[1] + ".pt[" + str(mmLatticeLow) +" : " + str(mmLatticeHigh) + "][0:" + str(mmLatticeMax) + "][0:" + str(mmLatticeMax) + "]", r = 1 )
            
            cmds.scale( 1, 1 + mmScaleGrowValue, 1 + mmScaleGrowValue, pivot = mmPivot )
            mmScaleGrowValue = mmScaleGrowValue*mmScaleRateOfShrink
            mmLatticeHigh += 1
            mmLatticeLow -= 1


        #Pass 2new - in Y
        
        #Reset Values        
        mmScaleGrowValue = mmScaleGrowValueOverall
        mmLatticeLow = mmLatticeMax/2-1
        mmLatticeHigh = mmLatticeMax/2
        
        while ( mmLatticeLow != 0 ):
            #cmds.select( mmNewLattice[1] + ".pt" + str(mmListX) + str(mmListY) + str(mmListZ), r = 1 )
            
            cmds.select( mmNewLattice[1] + ".pt[0:" + str(mmLatticeMax) + "][" + str(mmLatticeLow) +" : " + str(mmLatticeHigh) + "][0:" + str(mmLatticeMax) + "]", r = 1 )
            
            cmds.scale( 1 + mmScaleGrowValue, 1, 1+ mmScaleGrowValue, pivot = mmPivot )
            mmScaleGrowValue = mmScaleGrowValue*mmScaleRateOfShrink
            mmLatticeHigh += 1
            mmLatticeLow -= 1


        #Pass 3new - in Z
        
        #Reset Values        
        mmScaleGrowValue = mmScaleGrowValueOverall
        mmLatticeLow = mmLatticeMax/2-1
        mmLatticeHigh = mmLatticeMax/2

        while ( mmLatticeLow != 0 ):
            #cmds.select( mmNewLattice[1] + ".pt" + str(mmListX) + str(mmListY) + str(mmListZ), r = 1 )
            
            cmds.select( mmNewLattice[1] + ".pt[0:" + str(mmLatticeMax) + "][0:" + str(mmLatticeMax) + "][" + str(mmLatticeLow) +" : " + str(mmLatticeHigh) + "]", r = 1 )
            
            cmds.scale( 1 + mmScaleGrowValue, 1+ mmScaleGrowValue, 1, pivot = mmPivot )
            mmScaleGrowValue = mmScaleGrowValue*mmScaleRateOfShrink
            mmLatticeHigh += 1
            mmLatticeLow -= 1



        cmds.select(mmNewLattice, r = 1)
        
        cmds.HideSelectedObjects()