示例#1
0
def importShader(path):
    try:
        pm.importFile(path)
        print 'Success import {}'.format(path)
    except:
        print 'Failed import {}'.format(path)
        return
    assignShader()
示例#2
0
def importShader(path):
    """입력 받은 경로에 shader를 import 한후 쉐이더를 적용 한다.
    
    :param path: 파일 경로
    :type path: str
    
    """
    try:
        pm.importFile(path)
        print 'Success import {}'.format(path)
    except:
        print 'Failed import {}'.format(path)
        return
    assignShader()
def dae_to_mb(dae_path, mb_path):
    """Convert a dae file to Maya binary

    Args:
        dae_path (str): Path to dae file
    """
    pm.newFile(force=True)
    pm.importFile(dae_path)

    name = os.path.basename(dae_path).split('.')[0]

    pm.select(pm.ls(type='mesh'))

    group = pm.group(world=True, name=name + '_meshGroup')

    for loc in pm.ls(type='locator'):
        pm.delete(loc.getParent())
    pm.saveAs(mb_path)
def import_mesh(vehicle_path):
    """Import mesh. cache it to a mb file if one doesn't exists.

    Args:
        dae_path (str): Path to dae file
    """

    pm.newFile(force=True)

    mb_paths = []

    for dae_path in glob.glob(os.path.join(vehicle_path, '*.dae')):
        # import_mesh(dae_path=dae_path)

        ext = dae_path.split('.')[-1]
        mb_path = dae_path.replace('.' + ext, '.mb')
        if not os.path.exists(mb_path):
            dae_to_mb(dae_path=dae_path, mb_path=mb_path)

        mb_paths.append(mb_path)

        # name = os.path.basename(dae_path).split('.')[0]

    pm.newFile(force=True)

    for f in mb_paths:
        pm.importFile(f)

    # Cleanup

    # Remove lights
    for light in pm.ls(type='pointLight'):
        pm.delete(light.getParent())

    # Group mesh
    root_grp = pm.group(empty=True, world=True, name='mesh')
    for grp in pm.ls(assemblies=True):
        if grp != root_grp and not grp.getShape():
            grp.setParent(root_grp)
示例#5
0
def importYeti(path):
    """입력 받은 경로에 shader를 import 한후 쉐이더를 적용 한다.
    
    :param path: 파일 경로
    :type path: str
    
    """
    yetiInfo = getYetiInfo()
    if yetiInfo:
        for yetiNode, shader in yetiInfo.items():
            if pm.objExists(yetiNode):
                pm.delete(yetiNode)
            if pm.objExists(shader):
                pm.delete(shader)

    if pm.objExists('yetiInfoNode'):
        yetiInfoNode = pm.PyNode('yetiInfoNode')
        yetiInfoNode.unlock()
        pm.delete(yetiInfoNode)

    pm.importFile(path)
    if not pm.objExists('yetiInfoNode'):
        pm.error(u'"yetiInfoNode"가 존재 하지 않습니다.')

    yetiInfoNode = pm.PyNode('yetiInfoNode')
    yetiInfo = json.loads(yetiInfoNode.yetiInfo.get())

    for yetiNodeName, shaderName in yetiInfo.items():
        yetiNode = pm.createNode('pgYetiMaya', n=yetiNodeName + 'Shape')
        yetiParent = yetiNode.getParent()
        yetiParent.rename(yetiNodeName)
        yetiNode.renderDensity.set(1)
        yetiNode.aiOpaque.set(0)

        pm.select(yetiParent)
        surfaceShader = pm.PyNode(shaderName)
        pm.hyperShade(assign=surfaceShader)
示例#6
0
    def importPass(self, paths = list()):
        if not paths:
            return 
        for path in paths:
            splited = path.split('.')
            splited.pop(-1)
            arpassinfo = '.'.join(splited) + '.arpassinfo'
            strFile = self.readTxtFile(path=arpassinfo)
            objectsNotFound = []
            if strFile:
                dico = eval(strFile)
                if not pm.objExists(dico['layer']['name']):
                    renderLayer = pm.createRenderLayer(name=dico['layer']['name'], g=dico['layer']['global'])
                else:
                    renderLayer = pm.PyNode(dico['layer']['name'])
                arsenalPassName = renderLayer.name() + '_arsenalPass'
                if pm.objExists(arsenalPassName):
                    pm.lockNode(arsenalPassName, lock=False)
                    pm.delete(arsenalPassName)
                pm.importFile(path, defaultNamespace=True)
                if renderLayer.name() != 'defaultRenderLayer':
                    for member in dico['layer']['members']:
                        listMembers = dico['layer']['members'][member]
                        if pm.objExists(listMembers[0]):
                            renderLayer.addMembers(listMembers[0])
                        elif pm.objExists(listMembers[1]):
                            if len(pm.ls(listMembers[1])) == 1:
                                renderLayer.addMembers(listMembers[1])
                        elif pm.objExists(listMembers[2]):
                            if len(pm.ls(listMembers[2])) == 1:
                                renderLayer.addMembers(listMembers[2])
                        elif pm.objExists(listMembers[3]):
                            if len(pm.ls(listMembers[3])) == 1:
                                renderLayer.addMembers(listMembers[3])
                        else:
                            objectsNotFound.append(listMembers[0])

                for member in dico['connections']:
                    dicoMembers = dico['connections'][member]
                    dsts = dicoMembers['destination']
                    listMembers = dicoMembers['sources']
                    if pm.objExists(listMembers[0]):
                        for dst in dsts:
                            pm.connectAttr(listMembers[0], dst, f=True)

                    elif pm.objExists(listMembers[1]):
                        if len(pm.ls(listMembers[1])) == 1:
                            for dst in dsts:
                                pm.connectAttr(listMembers[1], dst, f=True)

                    elif pm.objExists(listMembers[2]):
                        if len(pm.ls(listMembers[2])) == 1:
                            for dst in dsts:
                                pm.connectAttr(listMembers[2], dst, f=True)

                    elif pm.objExists(listMembers[3]):
                        if len(pm.ls(listMembers[3])) == 1:
                            for dst in dsts:
                                pm.connectAttr(listMembers[3], dst, f=True)


            else:
                OpenMaya.MGlobal.displayError('[Arsenal] Can not open ' + arpassinfo)
                return 
            if objectsNotFound:
                OpenMaya.MGlobal.displayError('[Arsenal] Object(s) not found in the scene : \n' + '\n'.join(objectsNotFound))
                return 
            self.refreshArsenalPass()