Example #1
0
def shuai_autoFacialRig():
    global path
    path = mc.getModulePath(moduleName='hq_maya')
    if mc.window('autoFacialRigWin', ex=1):
        mc.deleteUI('autoFacialRigWin')
    autoFacialWin = mc.window('autoFacialRigWin',
                              t='Auto Facial Rig Window',
                              w=300,
                              h=200)
    mc.columnLayout(adjustableColumn=1)
    mc.button(l='导入表情控制器面板',
              c='fb.rig.FacialRig.autoFacialRig.importFacialTmp()')
    mc.text('选择做好设置的头部模型,获取到下面')
    mc.textFieldButtonGrp('getSouceObj',
                          bl='获取',
                          l='头部蒙皮模型:',
                          adjustableColumn=2,
                          bc='fb.rig.FacialRig.autoFacialRig.getSouceObjCmd()')
    mc.text('选择所有目标体,然后点击“连接blendshapes”按钮')
    mc.button(l='连接blendshapes',
              c='fb.rig.FacialRig.autoFacialRig.buildBlendshapeConnections()')
    mc.text('下面显示的目标体没有正确连接,可能是因为命名问题:')
    mc.textFieldButtonGrp(
        'WrongObjsWin',
        ed=0,
        bl='选择',
        l='问题目标体:',
        adjustableColumn=2,
        bc='fb.rig.FacialRig.autoFacialRig.selectWrongObjCmd()')
    mc.separator(style="double")
    mc.button(l='导入dx11Shader节点网络',
              c='fb.rig.FacialRig.autoFacialRig.importDX11Shader()')
    mc.text('贴图路径,如:( O:/LaMaChuanQi/Rigging/LuoCha/sourceimages/LuoCha )')
    mc.textFieldButtonGrp('mapsPath',
                          bl='浏览',
                          l='绝对路径:',
                          adjustableColumn=2,
                          bc='fb.rig.FacialRig.autoFacialRig.getMapsPath()')
    mc.button(l='自动读取贴图', c='fb.rig.FacialRig.autoFacialRig.readMaps()')
    mc.separator(style="double")
    mc.textFieldButtonGrp('SGNodeWin',
                          bl='获取',
                          l='获取渲染SG节点:',
                          adjustableColumn=2,
                          bc='fb.rig.FacialRig.autoFacialRig.getSGNodeCmd()')
    mc.button(l='连接到SG节点',
              c='fb.rig.FacialRig.autoFacialRig.connectToSgNode()')
    mc.separator(style="double")
    mc.button(l='提取blendshapes',
              c='fb.rig.FacialRig.autoFacialRig.getBlendshapes()')
    mc.separator(style="double")
    mc.button(l='选择环线切头', c='fb.rig.FacialRig.autoFacialRig.getcuthead()')
    mc.showWindow(autoFacialWin)
Example #2
0
    def __init__(self,
                 name="Tools",
                 iconPath=(mc.getModulePath(moduleName="VertexLightBaker")) +
                 "/icons/"):
        self.name = name

        self.iconPath = iconPath

        self.labelBackground = (0, 0, 0, 0)
        self.labelColour = (.9, .9, .9)

        self._cleanOldShelf()
        mc.setParent(self.name)
        self.build()
Example #3
0
def set_maya_env():
    module_name = "miraEnv"
    module_path = mc.getModulePath(moduleName=module_name)
    mira_dir = module_path.split(module_name)[0]
    # add mira to PYTHONPATH
    add_to_python_path(mira_dir)
    # add python path
    miraLibs_dir = os.path.join(mira_dir, "miraLibs")
    site_packages_dir = os.path.join(miraLibs_dir, "site-packages")
    add_to_python_path(site_packages_dir)
    # add current python packages to PYTHONPATH
    python_version = get_python_version()
    current_python_dir = os.path.join(site_packages_dir, python_version)
    add_to_python_path(current_python_dir)
    # add .egg files to PYTHONPATH
    egg_files = glob.glob("%s/*.egg" % site_packages_dir)
    if egg_files:
        for egg_file in egg_files:
            add_to_python_path(egg_file)
Example #4
0
    def build(self):
        crScriptPath = cmds.getModulePath(
            moduleName='mnt_poseScope') + '/scripts/'

        self.addButton(label='',
                       icon='mntController.png',
                       enable=True,
                       ann='Create Mnt Locator Node',
                       command='cmds.createNode(\'mnt_locator\')')

        self.addButton(label = '', icon = 'mnt_createPoseScope.png', enable = True, command = 'import mnt_poseScopeUI\nposeScopeUI = mnt_poseScopeUI.mnt_poseScopeUI()',\
            ann = 'Opens Mnt_poseScopes Editor')

        self.addSymbolCheckBox(
            icon='mnt_poseTool.png',
            enable=True,
            onCommand=
            'import mnt_poseTool as mnt_poseTool\nposeTool = mnt_poseTool.mnt_DynSelection()',
            offCommand='poseTool.__del__()')
        self.addButton(
            label='',
            icon='mnt_togglePoseScopeVisibility.png',
            enable=True,
            command=
            'import maya.cmds as cmds\ncmds.togglePoseScopeShapesVisibility()')

        self.addSeparator()

        self.addButton(label='',
                       icon='mntNode.png',
                       enable=True,
                       ann='Open Node Editor',
                       command='cmds.NodeEditorWindow()')
        self.addButton(label='',
                       icon='mnt_delUnusedNodes.png',
                       enable=True,
                       command='mel.eval(\'MLdeleteUnused;\')',
                       ann='Delete unused nodes')
Example #5
0
# -*- coding: UTF-8 -*-
#.@FileName:ModelClean_link
#.@Date:2019-03-15:18:53
#.@Aurhor:LuoOu
import maya.mel as mel
import maya.cmds as cmds

modlePath = cmds.getModulePath(moduleName='LuoOu_tools')


def main(*args):
    mel.eval(
        'source "{}/scripts/ScriptPackages/Model/ModelCleaner";asModelCleaner'.
        format(modlePath))
    def buildUI(self):
        iconPath = cmds.getModulePath(
            moduleName='mnt_poseScope') + '/icons/mntShelf/'
        windowwidth = 200

        if cmds.workspaceControl('mnt_poseScopes_editor', ex=True):
            cmds.deleteUI('mnt_poseScopes_editor')

        cmds.workspaceControl('mnt_poseScopes_editor',
                              w=windowwidth,
                              r=True,
                              clp=False)

        cmds.columnLayout(adj=True)
        cmds.text('Mnt poseScopes Editor',
                  fn='boldLabelFont',
                  h=32,
                  ebg=True,
                  bgc=(0.15, 0.15, 0.15))
        cmds.paneLayout('mntDenoiseToolPane', cn='vertical2')

        cmds.columnLayout(adj=True)
        cmds.iconTextButton(style='iconAndTextVertical', l = 'Create or Update poseScope', i = iconPath + 'mnt_createPoseScope.png',\
            c = 'import maya.cmds as cmds\ncmds.createPoseScopeShape()', ann = 'Select some polySurface face components.\nThen select a transform node using the outliner and click button to create a poseScope.\n If no transform node is selected a default one is created.')
        cmds.iconTextButton(style='iconAndTextVertical', l = 'Mirror poseScope', i = iconPath + 'mnt_mirrorPoseScope.png',\
            c = 'import maya.cmds as cmds\ncmds.mirrorPoseScope()', ann = 'Creates a new mirrored poseScope\nfrom the selected one.')
        cmds.iconTextButton(style='iconAndTextVertical', l = 'Delete poseScope', i = iconPath + 'mnt_deletePoseScope.png',\
            c = cmds.deletePoseScope, ann = 'Delete poseScope from the selected transform node.')
        cmds.iconTextButton(style='iconAndTextVertical', l = 'Edit poseScope components', i = iconPath + 'mnt_editPoseScopeComponents.png',\
            c = 'cmds.editPoseScopeComponents()', ann = 'Select polySurface components associated\nto the selected poseScope.')
        cmds.iconTextButton(style='iconAndTextVertical', l = 'Transfert poseScopes', i = iconPath + 'mnt_transfertposeScopes.png',\
            c = 'cmds.transfertPoseScopes()', ann = 'Transfers poseScopes from  first selected polySurface A\nto a second selected polySurface B.')
        cmds.iconTextButton(style='iconAndTextVertical', l = 'Import poseScopes from json file', i = iconPath + 'mnt_importPoseScopes.png',\
            c = self.importPoseScopeInfos, ann = 'Imports poseScopes from a json file.')
        cmds.iconTextButton(style='iconAndTextVertical', l = 'Export poseScopes from json file', i = iconPath + 'mnt_exportPoseScopes.png',\
            c = self.savePoseScopeInfos, ann = 'Exports poseScopes to a json file.')
        cmds.setParent('..')

        cmds.columnLayout(adj=True, w=500)
        cmds.text('PoseScopes Table', h=24, bgc=(0.2, 0.2, 0.2))
        cmds.textFieldButtonGrp('getInfosControl', label = 'PolySurface Name : ', text = 'None', buttonLabel = 'Get Posescopes', cat = (1, 'left', 0),\
            ct3 = ('left', 'left', 'left'), cw3 = (100, 170, 100), bc = self.updatePoseScopeTable)
        form = cmds.formLayout()

        table = cmds.scriptTable('table', rows = 0, columns = 3, label = [(1, 'Controller Name'), (2, 'Components List'), (3, 'PoseScope Visibility')], h = 530,\
            cw = (2, 200), ed = False, cellChangedCmd = self.edit_cell, sm = 3, sb = 1, mee = False)
        cmds.scriptTable('table', edit=True, cw=(1, 150))
        cmds.scriptTable('table', edit=True, cw=(3, 110))
        cmds.scriptTable('table',
                         edit=True,
                         selectionChangedCmd=self.cellSelected,
                         cbc=self.setBackgroundColor)

        cmds.formLayout(form,
                        edit=True,
                        attachForm=[
                            (table, 'top', 0),
                            (table, 'left', 0),
                            (table, 'right', 0),
                        ])
        cmds.setParent('..')

        cmds.setParent('..')
Example #7
0
def bin_dir():
    path = cmds.getModulePath(mn='TwinPipeBootstrap')
    return os.path.normpath(os.path.join(path, 'bin'))
Example #8
0
class _shelf():
    iconPath = cmds.getModulePath(
        moduleName='mnt_poseScope') + '/icons/mntShelf/'

    def __init__(self, name=_null, iconPath=iconPath):
        self.name = name

        self.iconPath = iconPath

        self.labelBackground = (0, 0, 0, 0)
        self.labelColor = (0.122, 0.122, 0.122)

        self._cleanOldShelf()
        cmds.setParent(self.name)
        self.build()

    def build(self):
        '''This method should be overwritten in derived classes to actually build the shelf
        elements. Otherwise, nothing is added to the shelf.'''
        pass

    def _cleanOldShelf(self):
        if cmds.shelfLayout(self.name, ex=1):
            if cmds.shelfLayout(self.name, q=1, ca=1):
                for each in cmds.shelfLayout(self.name, q=1, ca=1):
                    cmds.deleteUI(each)
        else:
            cmds.shelfLayout(self.name, p="ShelfLayout")

    def addButton(self,
                  label,
                  icon="pythonFamily.png",
                  ann=_null,
                  enable=_null,
                  command=_null,
                  doubleCommand=_null):
        '''Adds a shelf button with the specified label, command, double click command and image.'''
        cmds.setParent(self.name)
        if icon:
            icon = self.iconPath + icon
        cmds.shelfButton(width = 32, height = 32, image = icon, l = label, en = enable, command = command, dcc = doubleCommand, imageOverlayLabel=label, olb=self.labelBackground, olc=self.labelColor,\
                        ann = ann)

    def addSymbolCheckBox(self,
                          icon='pythonFamily.png',
                          ann=_null,
                          enable=_null,
                          onCommand=_null,
                          offCommand=_null):
        cmds.setParent(self.name)
        if icon:
            icon = self.iconPath + icon
        cmds.symbolCheckBox(self,
                            width=32,
                            height=32,
                            nbg=True,
                            image=icon,
                            en=enable,
                            onCommand=onCommand,
                            offCommand=offCommand)

    def addMenuItem(self, parent, label, enable=_null, command=_null, icon=""):
        if icon:
            icon = self.iconPath + icon
        return cmds.menuItem(p=parent, l=label, c=command, i=icon)

    def addSubMenu(self, parent, label, icon=None):
        if icon:
            icon = self.iconPath + icon
        return cmds.menuItem(p=parent, l=label, i=icon, subMenu=1)

    def addSeparator(self):
        cmds.separator(enable=True,
                       w=12,
                       h=35,
                       manage=True,
                       vis=True,
                       po=True,
                       highlightColor=(0.321, 0.521, 0.650),
                       style='shelf',
                       horizontal=False)
class MntLocatorNode(OpenMayaUI.MPxLocatorNode):
    kPluginNodeName         = 'mnt_locator' #Name of the node.
    id                      = OpenMaya.MTypeId( 0xDAE2 ) # A unique ID associated to this node type.
    drawDbClassification    = "drawdb/geometry/MntLocatorNode"
    drawRegistrantId        = "MntLocatorNodePlugin"

    iconFolder              = cmds.getModulePath(moduleName = 'mnt_poseScope') + '/icons/mntLocators/'
    iconType                = OpenMaya.MObject()
    iconMainAxis            = OpenMaya.MObject()
    sizeAttribute           = OpenMaya.MObject()
    areaVisibility          = OpenMaya.MObject()
    colorAttribute          = OpenMaya.MObject()
    opacityAttribute        = OpenMaya.MObject()
    labelAttribute          = OpenMaya.MObject()
    showHierarchicalLinks   = OpenMaya.MObject()
    lineWidth               = OpenMaya.MObject()
    lineColor               = OpenMaya.MObject()
    dottedLine              = OpenMaya.MObject()
    dotsNumber              = OpenMaya.MObject()
    interactiveRefresh      = OpenMaya.MObject()
    
    def __init__(self):
        OpenMayaUI.MPxLocatorNode.__init__(self)
        self.BBox = OpenMaya.MBoundingBox()

    @staticmethod
    def creator():
        return MntLocatorNode()
 
    @staticmethod
    def initialize():
        ''' Defines the input and output attributes as static variables in our plug-in class. '''

        # Input Attributes

        # Creates needed function sets
        numericAttributeFn  = OpenMaya.MFnNumericAttribute()
        enumAttr            = OpenMaya.MFnEnumAttribute()
        stringAttrFn        = OpenMaya.MFnTypedAttribute()
        # ____________________________

        MntLocatorNode.sizeAttribute    = numericAttributeFn.create('size', 'size', OpenMaya.MFnNumericData.kFloat, 1)
        numericAttributeFn.writable     =  True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     =  True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.setMin( 0.01 )
        numericAttributeFn.setMax( 100.0 )
        MntLocatorNode.addAttribute(MntLocatorNode.sizeAttribute)

        MntLocatorNode.areaVisibility   = numericAttributeFn.create('area_Visibility', 'area_Visibility', OpenMaya.MFnNumericData.kBoolean, False)
        numericAttributeFn.writable     =  True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     =  True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.areaVisibility)

        MntLocatorNode.colorAttribute = numericAttributeFn.createColor('color', 'color')
        numericAttributeFn.writable     = True
        numericAttributeFn.keyable      = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.storable     = True
        numericAttributeFn.hidden       = False
        MntLocatorNode.addAttribute(MntLocatorNode.colorAttribute)

        MntLocatorNode.opacityAttribute = numericAttributeFn.create('opacity', 'opacity', OpenMaya.MFnNumericData.kFloat, 1.0)
        numericAttributeFn.writable     = True
        numericAttributeFn.keyable      = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.storable     = True
        numericAttributeFn.hidden       = False
        numericAttributeFn.setMin(0.0)
        numericAttributeFn.setMax(1.0)
        MntLocatorNode.addAttribute(MntLocatorNode.opacityAttribute)

        MntLocatorNode.iconType = enumAttr.create('iconType', 'it', 1)
        enumAttr.addField('Bone', 0)
        enumAttr.addField('Circle', 1)
        enumAttr.addField('Square', 2)
        enumAttr.addField('Skull', 3)
        enumAttr.addField('Pelvis', 4)
        enumAttr.addField('Ribcage', 5)
        enumAttr.addField('Sphere', 6)
        enumAttr.addField('Disc', 7)
        enumAttr.addField('Circle3D', 8)
        enumAttr.hidden     = False
        enumAttr.channelBox = True
        MntLocatorNode.addAttribute(MntLocatorNode.iconType)

        MntLocatorNode.iconMainAxis = enumAttr.create('iconMainAxis', 'ima', 0)
        enumAttr.addField('X', 0)
        enumAttr.addField('Y', 1)
        enumAttr.addField('Z', 2)
        enumAttr.hidden       = True
        enumAttr.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.iconMainAxis)

        MntLocatorNode.showHierarchicalLinks= numericAttributeFn.create('show_hierarchical_links', 'show_hierarchical_links', OpenMaya.MFnNumericData.kBoolean, False)
        numericAttributeFn.writable     = True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     = True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.showHierarchicalLinks)

        MntLocatorNode.dottedLine = numericAttributeFn.create('use_dotted_line', 'use_dotted_line', OpenMaya.MFnNumericData.kBoolean, False)
        numericAttributeFn.writable   = True 
        numericAttributeFn.keyable    = False
        numericAttributeFn.storable   = True
        numericAttributeFn.hidden     = False
        numericAttributeFn.channelBox = True
        MntLocatorNode.addAttribute(MntLocatorNode.dottedLine)

        MntLocatorNode.dotsNumber = numericAttributeFn.create('dots_number', 'dots_number', OpenMaya.MFnNumericData.kInt, 5)
        numericAttributeFn.writable   = True 
        numericAttributeFn.keyable    = False
        numericAttributeFn.storable   = True
        numericAttributeFn.hidden     = False
        numericAttributeFn.channelBox = True
        numericAttributeFn.setMin(1)
        numericAttributeFn.setMax(16)
        MntLocatorNode.addAttribute(MntLocatorNode.dotsNumber)

        MntLocatorNode.lineWidth = numericAttributeFn.create('line_width', 'line_width', OpenMaya.MFnNumericData.kInt, 4)
        numericAttributeFn.writable    = True
        numericAttributeFn.keyable     = True
        numericAttributeFn.storable    = True
        numericAttributeFn.hidden      = False
        numericAttributeFn.channelBox  = True
        numericAttributeFn.setMin(1)
        numericAttributeFn.setMax(16)
        MntLocatorNode.addAttribute(MntLocatorNode.lineWidth)

        MntLocatorNode.lineColor = numericAttributeFn.createColor('line_color', 'line_color')
        numericAttributeFn.writable     = True
        numericAttributeFn.keyable      = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.storable     = True
        numericAttributeFn.hidden       = False
        MntLocatorNode.addAttribute(MntLocatorNode.lineColor)

        MntLocatorNode.labelAttribute = stringAttrFn.create('label', 'label', OpenMaya.MFnData.kString)
        stringAttrFn.writable = True
        stringAttrFn.readable = True
        MntLocatorNode.addAttribute(MntLocatorNode.labelAttribute)

        MntLocatorNode.interactiveRefresh = numericAttributeFn.create('interactiveRefresh', 'ir', OpenMaya.MFnNumericData.kBoolean, True)
        numericAttributeFn.writable     = True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     = True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.interactiveRefresh)

    def isBounded(self):
        return True

    def boundingBox(self):
        return self.BBox

    def compute(self, plug, data):
        return

    def setDependentsDirty(self, plug, plugArray):
        if plug.attribute() == MntLocatorNode.iconType:
            iconMainAxisAttr = OpenMaya.MFnAttribute(MntLocatorNode.iconMainAxis)  

    def postConstructor(self):
        return
Example #10
0
"""
1. I set PYTHONPATH :+= scripts in mod file, so this userSetup.py is loaded automatically
"""
import os
import sys
import maya.cmds as cmds

modulePath = cmds.getModulePath(moduleName='node_template')
modulePath = modulePath.replace('\\','/')

# get fullpath of current py file
this_file_path = modulePath + '/scripts/userSetup.py';
print("this is: "+this_file_path);

# add common module to python path
commonPath = modulePath+'/../common';
sys.path.insert(0, commonPath);

"""
2. There are so many ``AETemplates`` directories, so I have to load the modules with the full path.
"""
import imp
imp.load_source('AETemplates.AEnode_templateTemplate', modulePath+'/scripts/AETemplates/AEnode_templateTemplate.py')
Example #11
0
"""
1. I set PYTHONPATH :+= scripts in mod file, so this userSetup.py is loaded automatically
"""
import os
import sys
import maya.cmds as cmds

modulePath = cmds.getModulePath(moduleName='tornado_field')
modulePath = modulePath.replace('\\','/')

# get fullpath of current py file
this_file_path = modulePath + '/scripts/userSetup.py';
print("this is: "+this_file_path);

# add common module to python path
commonPath = modulePath+'/../common';
sys.path.insert(0, commonPath);

"""
2. There are so many ``AETemplates`` directories, so I have to load the modules with the full path.
"""
import imp
imp.load_source('AETemplates.AEtornadoFieldTemplate', modulePath+'/scripts/AETemplates/AEtornadoFieldTemplate.py')
Example #12
0
"""
1. I set PYTHONPATH :+= scripts in mod file, so this userSetup.py is loaded automatically
"""
import os
import sys
import maya.cmds as cmds

modulePath = cmds.getModulePath(moduleName='version_control')
modulePath = modulePath.replace('\\','/')

# get fullpath of current py file
this_file_path = modulePath + '/scripts/userSetup.py';
print("this is: "+this_file_path);

# add common module to python path
commonPath = modulePath+'/../common';
sys.path.insert(0, commonPath);

"""
2. There are so many ``AETemplates`` directories, so I have to load the modules with the full path.
"""
import imp
imp.load_source('AETemplates.AEtestNodeATemplate', modulePath+'/scripts/AETemplates/AEtestNodeATemplate.py')
imp.load_source('AETemplates.AEtestNodeBTemplate', modulePath+'/scripts/AETemplates/AEtestNodeBTemplate.py')
Example #13
0
def k_tintplate():

    #k_cpath='//10.99.1.13/hq_tool3/Maya/hq_maya/icons/color_card.psd'
    k_cpath = cc.getModulePath(moduleName='hq_maya')+'/icons/color_card.psd'

    k_mesh=cc.ls(type=['mesh','nurbsSurface'])

    k_hair=cc.ls(type=['pfxHair','pgYetiGroom','pgYetiMaya'])

    k_shave=[]
    if cc.pluginInfo('shaveNode',q=1,loaded=1,name=1):
        k_shave=cc.ls(type=['shaveHair'])

    k_hide=k_mesh+k_hair+k_shave

    if cc.objExists('k_bak_disL'):
        cc.editDisplayLayerMembers('k_bak_disL',k_hide)
        cc.setAttr('k_bak_disL.visibility',0)
    else:
        cc.createDisplayLayer(name='k_bak_disL',e=1)
        cc.editDisplayLayerMembers('k_bak_disL',k_hide)
        cc.setAttr('k_bak_disL.visibility',0)


    mel.eval("postModelEditorSelectCamera modelPanel4 modelPanel4 0")
    k_cam=cc.ls(sl=1)



    if cc.nodeType(k_cam)!='camera':
        try:
            cc.listRelatives(k_cam,f=1,type='camera')[0]
        except:
            cc.confirmDialog( title='k_problem', message='select one camera')
            cc.error('didnot select one camera')
    elif cc.nodeType(k_cam)=='camera':
        k_cam[0]=cc.listRelatives(k_cam,f=1,parent=1)[0]



    if cc.objExists('k_colorball'):
        cc.delete('k_colorball')
        k_colorball=cc.group(em=True,name='k_colorball')
    else:k_colorball=cc.group(em=True,name='k_colorball')



    k_mbc_tx=cc.getAttr(k_cam[0]+'.tx')
    k_mbc_ty=cc.getAttr(k_cam[0]+'.ty')
    k_mbc_tz=cc.getAttr(k_cam[0]+'.tz')
    k_mbc_rx=cc.getAttr(k_cam[0]+'.rx')%360
    k_mbc_ry=cc.getAttr(k_cam[0]+'.ry')%360
    k_mbc_rz=cc.getAttr(k_cam[0]+'.rz')%360


    #k_max=max([abs(k_mbc_tx),abs(k_mbc_ty),abs(k_mbc_tz)])



    if cc.objExists('k_colorball_1'):
        cc.delete('k_colorball_1')
        cc.polySphere(ch=1,n='k_colorball_1')
        cc.move(-.6,0,0)
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_1','k_colorball')
        cc.setAttr('k_colorball_1Shape.castsShadows',0)
        cc.setAttr('k_colorball_1Shape.receiveShadows',0)
    else:
        cc.polySphere(ch=1,n='k_colorball_1')
        cc.move(-.6,0,0)
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_1','k_colorball')
        cc.setAttr('k_colorball_1Shape.castsShadows',0)
        cc.setAttr('k_colorball_1Shape.receiveShadows',0)



    if cc.objExists('k_colorball_2'):
        cc.delete('k_colorball_2')
        cc.polySphere(ch=1,n='k_colorball_2')
        cc.move(-.3,0,0)
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_2','k_colorball')
        cc.setAttr('k_colorball_2Shape.castsShadows',0)
        cc.setAttr('k_colorball_2Shape.receiveShadows',0)
    else:
        cc.polySphere(ch=1,n='k_colorball_2')
        cc.move(-.3,0,0)
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_2','k_colorball')
        cc.setAttr('k_colorball_2Shape.castsShadows',0)
        cc.setAttr('k_colorball_2Shape.receiveShadows',0)

    if cc.objExists('k_colorball_3'):
        cc.delete('k_colorball_3')
        cc.polySphere(ch=1,n='k_colorball_3')
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_3','k_colorball')
        cc.setAttr('k_colorball_3Shape.castsShadows',0)
        cc.setAttr('k_colorball_3Shape.receiveShadows',0)    
    else:
        cc.polySphere(ch=1,n='k_colorball_3')
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_3','k_colorball')
        cc.setAttr('k_colorball_3Shape.castsShadows',0)
        cc.setAttr('k_colorball_3Shape.receiveShadows',0)    

    if cc.objExists('k_colorball_4'):
        cc.delete('k_colorball_4')
        cc.polySphere(ch=1,n='k_colorball_4')
        cc.move(.3,0,0)
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_4','k_colorball')
        cc.setAttr('k_colorball_3Shape.castsShadows',0)
        cc.setAttr('k_colorball_3Shape.receiveShadows',0)    
    else:
        cc.polySphere(ch=1,n='k_colorball_4')
        cc.move(.3,0,0)
        cc.scale(.1,.1,.1)
        cc.parent('k_colorball_4','k_colorball')
        cc.setAttr('k_colorball_4Shape.castsShadows',0)
        cc.setAttr('k_colorball_4Shape.receiveShadows',0)    


    if cc.objExists('k_colorbox'):
        cc.delete('k_colorbox')
        cc.polyCube(ch=1,n='k_colorbox')
        cc.move(.8,0,0)
        cc.scale(.3,.2,.2)
        cc.rotate(0,10,0)
        cc.parent('k_colorbox','k_colorball')
        cc.setAttr('k_colorboxShape.castsShadows',0)
        cc.setAttr('k_colorboxShape.receiveShadows',0)    
    else:
        cc.polyCube(ch=1,n='k_colorbox')
        cc.move(.8,0,0)
        cc.scale(.3,.2,.2)
        cc.rotate(0,10,0)
        cc.parent('k_colorbox','k_colorball')
        cc.setAttr('k_colorboxShape.castsShadows',0)
        cc.setAttr('k_colorboxShape.receiveShadows',0)   

    cc.select(cl=1)

    try:
        cc.parentConstraint(k_cam[0],'k_colorball',n='k_colorball_parentC')
        cc.delete('k_colorball_parentC')
    except:
        cc.error('didnot select one camera')

    if cc.objExists('k_mbg'):
        cc.delete('k_mbg')
        k_colorball=cc.group(em=True,name='k_mbg')
    else:k_colorball=cc.group(em=True,name='k_mbg')

    cc.parent('k_mbg','k_colorball')


    if 85<(k_mbc_ry%180)<95:
        k_y=abs(k_mbc_tx)
    else:

        k_x=k_mbc_tz/math.cos(math.radians(k_mbc_ry%360))

        #if abs(k_mbc_rx)>40:k_mbc_rx=40
        k_y=k_x/math.cos(math.radians(abs(k_mbc_rx%360)))



    #print k_y
    
    cc.setAttr("k_mbg.translateX",0);
    cc.setAttr("k_mbg.translateY",0);
    cc.setAttr("k_mbg.translateZ",-abs(k_y));
    cc.setAttr("k_mbg.rotateX",0);
    cc.setAttr("k_mbg.rotateY",0);
    cc.setAttr("k_mbg.rotateZ",0);
    cc.parent('k_mbg',w=1)

    try:
        cc.parentConstraint('k_mbg','k_colorball',n='k_tmp_parentC')
        cc.delete('k_tmp_parentC')
    except:
        cc.error('something error')

    k_scale=.2*abs(k_y)

    cc.setAttr("k_colorball.scaleX",k_scale);
    cc.setAttr("k_colorball.scaleY",k_scale);
    cc.setAttr("k_colorball.scaleZ",k_scale);


    if not cc.objExists('k_wb1_SG'):
        cc.sets(empty=1,renderable=1,nss=1,n='k_wb1_SG')

    if not cc.objExists('k_wb1_shader'):
        cc.shadingNode('aiStandard',asShader=1,name='k_wb1_shader')
        cc.setAttr('k_wb1_shader.Kd',1)
        cc.setAttr('k_wb1_shader.color',.8,.8,.8,type='double3')
    else:
        cc.setAttr('k_wb1_shader.Kd',1)
        cc.setAttr('k_wb1_shader.color',.8,.8,.8,type='double3')

    if not cc.isConnected('k_wb1_shader.outColor','k_wb1_SG.surfaceShader'):
        cc.connectAttr ('k_wb1_shader.outColor','k_wb1_SG.surfaceShader',f=1)

    cc.sets('k_colorball_1Shape',e=1,fe='k_wb1_SG')


    if not cc.objExists('k_fb2_SG'):
        cc.sets(empty=1,renderable=1,nss=1,n='k_fb2_SG')

    if not cc.objExists('k_fb2_shader'):
        cc.shadingNode('aiStandard',asShader=1,name='k_fb2_shader')
        cc.setAttr('k_fb2_shader.Kd',0);
        cc.setAttr('k_fb2_shader.Ks',1);
        cc.setAttr('k_fb2_shader.specularRoughness',0)
    else:
        cc.setAttr('k_fb2_shader.Kd',0);
        cc.setAttr('k_fb2_shader.Ks',1);
        cc.setAttr('k_fb2_shader.specularRoughness',0)

    if not cc.isConnected('k_fb2_shader.outColor','k_fb2_SG.surfaceShader'):
        cc.connectAttr ('k_fb2_shader.outColor','k_fb2_SG.surfaceShader',f=1)

    cc.sets('k_colorball_2Shape',e=1,fe='k_fb2_SG')


    if not cc.objExists('k_hb3_SG'):
        cc.sets(empty=1,renderable=1,nss=1,n='k_hb3_SG')

    if not cc.objExists('k_hb3_shader'):
        cc.shadingNode('aiStandard',asShader=1,name='k_hb3_shader')
        cc.setAttr('k_hb3_shader.Kd',1)
        cc.setAttr('k_hb3_shader.color',.5,.5,.5,type='double3')
    else:
        cc.setAttr('k_hb3_shader.Kd',1)
        cc.setAttr('k_hb3_shader.color',.5,.5,.5,type='double3')

    if not cc.isConnected('k_hb3_shader.outColor','k_hb3_SG.surfaceShader'):
        cc.connectAttr ('k_hb3_shader.outColor','k_hb3_SG.surfaceShader',f=1)

    cc.sets('k_colorball_3Shape',e=1,fe='k_hb3_SG')





    if not cc.objExists('k_bb4_SG'):
        cc.sets(empty=1,renderable=1,nss=1,n='k_bb4_SG')

    if not cc.objExists('k_bb4_shader'):
        cc.shadingNode('aiStandard',asShader=1,name='k_bb4_shader')
        cc.setAttr('k_bb4_shader.Kd',0)
        cc.setAttr('k_bb4_shader.Ks',0.5)
        cc.setAttr('k_bb4_shader.specularRoughness',0.3)
        cc.setAttr('k_bb4_shader.KsColor',.5,.5,.5,type='double3')
    else:
        cc.setAttr('k_bb4_shader.Kd',0)
        cc.setAttr('k_bb4_shader.Ks',0.5)
        cc.setAttr('k_bb4_shader.specularRoughness',0.3)
        cc.setAttr('k_bb4_shader.KsColor',.5,.5,.5,type='double3')

    if not cc.isConnected('k_bb4_shader.outColor','k_bb4_SG.surfaceShader'):
        cc.connectAttr ('k_bb4_shader.outColor','k_bb4_SG.surfaceShader',f=1)

    cc.sets('k_colorball_4Shape',e=1,fe='k_bb4_SG')






    if not cc.objExists('k_card_SG'):
        cc.sets(empty=1,renderable=1,nss=1,n='k_card_SG')

    if not cc.objExists('k_card_file'):
        cc.shadingNode('file',asTexture=1,name='k_card_file')
        cc.setAttr('k_card_file.fileTextureName',k_cpath,type='string')

    else:cc.setAttr('k_card_file.fileTextureName',k_cpath,type='string')


    if not cc.objExists('k_card_shader'):
        cc.shadingNode('aiStandard',asShader=1,name='k_card_shader')
        cc.setAttr('k_card_shader.Kd',1)

    if not cc.isConnected('k_card_shader.outColor','k_card_SG.surfaceShader'):
        cc.connectAttr ('k_card_shader.outColor','k_card_SG.surfaceShader',f=1)

    if not cc.isConnected('k_card_file.outColor','k_card_shader.color'):
        cc.connectAttr ('k_card_file.outColor','k_card_shader.color',f=1)



    cc.sets('k_colorboxShape',e=1,fe='k_card_SG')


    cc.delete('k_mbg')



    if cc.objExists('k_colorball_disL'):
        cc.editDisplayLayerMembers('k_colorball_disL','k_colorball')
    else:
        cc.createDisplayLayer(name='k_colorball_disL',e=1)
        cc.editDisplayLayerMembers('k_colorball_disL','k_colorball')


    cc.select(cl=1)
Example #14
0
#!usr/bin/env python
#coding:utf-8
#-------------------------------
#    本脚本是为模型添加smooth节点
#    名称:smooth_UI()
#    编者:lsy(刘升耀)
#    时间:2015.10
#    版本:1.0
#-------------------------------

import maya.cmds as cmd
import maya.mel as mel

k_mel = cmd.getModulePath(
    moduleName='hq_maya') + "/scripts/fantabox/rigging/create/Controller.mel"

mel.eval('source "%s" ;' % k_mel)
#mel.eval('source "//10.99.1.13/hq_tool/Maya/hq_maya/scripts/fantabox/rigging/create/Controller.mel";')
#cmd.deleteUI("ControlWin")


def smooth_UI():
    if cmd.window("sm_win", exists=True):
        cmd.deleteUI("sm_win")
    cmd.window("sm_win", title="smooth节点关联")

    cmd.columnLayout(height=200, width=280)
    cmd.text("s_UI_text1", height=10, label="                   ")
    cmd.text("s_UI_text2", height=10, label="           读取头部骨骼名称,总位移控制器名称")
    cmd.text("s_UI_text4", height=30, label="            再选择需要smooth模型,之后执行即可")
    cmd.text("s_UI_text5", label="")