Exemplo n.º 1
0
def assignShader2():
    shaderInfoNode = pm.PyNode('shaderInfoNode')
    numAttr = shaderInfoNode.shaderInfos.numChildren()
    message = ''
    for i in range(numAttr):
        shaderInfos = json.loads(
            shaderInfoNode.attr('shaderInfos{}'.format(i)).get())
        try:
            pm.select(shaderInfos.get('geometry'))

            surfaceShader = pm.PyNode(shaderInfos.get('surfaceShader'))
            pm.hyperShade(assign=surfaceShader)
            pm.select(cl=True)
            try:
                if shaderInfos.get('displacement'):
                    displacement = pm.PyNode(shaderInfos.get('displacement'))
                    sg = surfaceShader.outColor.outputs()[0]
                    displacement.displacement.connect(sg.displacementShader)
            except:
                message += (str(shaderInfos.get('displacement')) + '-->' +
                            sg.name() + '\n')
        except:
            message += (str(shaderInfos.get('surfaceShader')) + '-->' +
                        str(shaderInfos.get('geometry')) + '\n')

    shaderInfoNode.unlock()
    pm.delete(shaderInfoNode)
    return message
Exemplo n.º 2
0
 def assign_shader(self, sh, Utile, Vtile):
     self.sel = pm.ls(selection=True)
     if not pm.objExists(sh):
         self.create_shader(sh)
     pm.select(self.sel)
     pm.hyperShade(assign=pm.PyNode(sh))
     self.disp_uv_tile_val(sh, Utile, Vtile)
     return None
Exemplo n.º 3
0
 def copy_shader(self):
     cp_sel = pm.ls(selection=True)
     sel_shader = None
     sh_eng = pm.ls(pm.listHistory(cp_sel[0], f=1), type="shadingEngine")[0]
     if sh_eng:
         sel_shader = pm.listConnections(str(sh_eng) + ".surfaceShader")[0]
     if sel_shader:
         pm.hyperShade(cp_sel[1], assign=sel_shader)
     return None
Exemplo n.º 4
0
def deleteShader(mod):
    try:
        pm.select(mod)
        lambert = pm.PyNode('lambert1')
        pm.hyperShade(assign=lambert)
        pm.select(cl=True)
        pm.mel.eval('MLdeleteUnused;')
        return True
    except:
        return False
Exemplo n.º 5
0
def importYeti(path):
    msg = ''
    try:
        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)

        cmds.file(path,
                  pr=1,
                  ignoreVersion=1,
                  i=1,
                  type="mayaBinary",
                  mergeNamespacesOnClash=False,
                  options="v=0;")
        #pm.importFile(path)
        if not pm.objExists('yetiInfoNode'):
            msg += u'"yetiInfoNode"가 존재 하지 않습니다.'
    except:
        return msg

    if not pm.objExists('time1'):
        timeNode = pm.createNode('time', n='time1')

    timeNode = pm.PyNode('time1')

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

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

            pm.select(yetiParent)
            surfaceShader = pm.PyNode(shaderName)
            pm.hyperShade(assign=surfaceShader)
        except:
            msg += u'{}노드와 {}쉐이더를  어싸인 하는데 실패 했습니다'.format(
                yetiNodeName, shaderName)

    return msg
Exemplo n.º 6
0
def assignShader():
    """씬안에서 shaderInfoNode 노드를 검색 한다.\n
    shaderInfoNode 노드에 shaderInfos# 어트리뷰트를 검색한다.\n
    shaderInfos# 어트리뷰트의 값을 json 으로 가져 온다.\n
    어트리뷰트의 geometry, surfaceShader, displacement 키 값을 가져 온다.\n
    geometry에 surfaceShader, displacement 적용 한다.\n
    shaderInfoNode 삭제 한다.
    
    .. warning:: 
        씬안에 'shaderInfoNode' 노드가 없을 때 ``shaderInfoNode not exist!`` 예외 발생
    """
    try:
        shaderInfoNode = pm.PyNode('shaderInfoNode')
    except:
        print '"shaderInfoNode" not exist!'

    numAttr = shaderInfoNode.shaderInfos.numChildren()

    message = ''
    for i in range(numAttr):
        shaderInfos = json.loads(
            shaderInfoNode.attr('shaderInfos{}'.format(i)).get())
        geos = []
        for geo in shaderInfos.get('geometry'):
            if pm.objExists(geo):
                geos.append(geo)
        try:
            pm.select(geos)

            surfaceShader = pm.PyNode(shaderInfos.get('surfaceShader'))
            pm.hyperShade(assign=surfaceShader)
            pm.select(cl=True)
            try:
                if shaderInfos.get('displacement'):
                    displacement = pm.PyNode(shaderInfos.get('displacement'))
                    sg = surfaceShader.outColor.outputs()[0]
                    displacement.displacement.connect(sg.displacementShader)
            except:
                message += (str(shaderInfos.get('displacement')) + '-->' +
                            sg.name() + '\n')
        except:
            message += (str(shaderInfos.get('surfaceShader')) + '-->' +
                        str(geos) + '\n')

    shaderInfoNode.unlock()
    pm.delete(shaderInfoNode)

    if message:
        print 'Failed list:\n'
        print message
Exemplo n.º 7
0
    def create_blinn(self):
        """
        creates a blinn for observing how light interacts with the surface of an object
        """
        oSel = pm.ls(sl=True)

        self.normal_shader = pm.shadingNode('blinn', asShader=True)
        self.normal_shading_group = pm.sets(renderable=True,
                                            noSurfaceShader=True,
                                            empty=True)
        pm.connectAttr('%s.outColor' % self.normal_shader,
                       '%s.surfaceShader' % self.normal_shading_group)
        for objs in oSel:
            pm.select(objs)
            pm.hyperShade(assign='%s' % self.normal_shader)
        pm.select(oSel)
Exemplo n.º 8
0
    def delete_shader(self, sh, Utile, Vtile):

        if not pm.objExists(sh):
            pm.displayWarning("Shader does not exist")
            return None

        # get the shading engine connected
        sh_con = pm.listConnections(sh + ".outColor")
        obj = None
        for con in sh_con:
            print(con)
            # find the mesh connected with the shading engine
            obj = pm.listConnections(con, type="mesh")

        pm.delete(sh)
        pm.delete(sh + "_fileTexture")
        pm.delete(sh_con)
        pm.delete(sh + "_2dTex")
        if obj:
            pm.select(obj)
            pm.hyperShade(assign="lambert1")
        self.clear_uv_tile_val(sh, Utile, Vtile)
        return None
Exemplo n.º 9
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)
Exemplo n.º 10
0
def assignShader():
    try:
        shaderInfoNode = pm.PyNode('shaderInfoNode')
    except:
        print '"shaderInfoNode" not exist!'

    numAttr = shaderInfoNode.shaderInfos.numChildren()

    for i in range(numAttr):
        shaderInfos = json.loads(
            shaderInfoNode.attr('shaderInfos{}'.format(i)).get())
        pm.select(shaderInfos.get('geometry'))

        surfaceShader = pm.PyNode(shaderInfos.get('surfaceShader'))
        pm.hyperShade(assign=surfaceShader)
        pm.select(cl=True)

        if shaderInfos.get('displacement'):
            displacement = pm.PyNode(shaderInfos.get('displacement'))
            sg = surfaceShader.outColor.outputs()[0]
            displacement.outColor.connect(sg.displacementShader)

    shaderInfoNode.unlock()
    pm.delete(shaderInfoNode)
Exemplo n.º 11
0
def operator(meshA, meshB):
    booleanmode = get_boolean_mode()
    pma.polyBoolOp(meshA, meshB, op=booleanmode, n="basemesh")
    pma.hyperShade(
        assign="lambert1")  # REMINDER: Need to be replaced with the actual assigned material and not with a lambert1 so for who is working with other materials can easyly keep using that
Exemplo n.º 12
0
def fixMaterial():
    pma.hyperShade(assign="lambert1")