示例#1
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
示例#2
0
    def selectObjects(self, node = None, attribute = None):
        if node is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass')
            return 
        pm.select(cl=True)
        for myConnected in pm.listConnections(node + '.' + attribute, destination=False, source=True):
            pm.select(myConnected, add=True)

        print '[Arsenal] Object(s) selection done.'
示例#3
0
 def initAttributes(self, attribut = None, renderPass = None, connection = False, fromRenderGlobal = False):
     if attribut is None and renderPass is None:
         OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass')
         return 
     arsenalPass = pm.PyNode(renderPass + '_arsenalPass')
     if not connection:
         if fromRenderGlobal:
             value = pm.getAttr('vraySettings.' + attribut)
         else:
             value = pm.getAttr(arsenalPass.name() + '.' + attribut)
     elif fromRenderGlobal:
         value = pm.listConnections('vraySettings.' + attribut, destination=False, source=True)
     else:
         value = pm.listConnections(arsenalPass.name() + '.' + attribut, destination=False, source=True)
     if renderPass not in self.passName:
         self.passName[renderPass] = ArsenalPass()
         self.passName[renderPass].passName = renderPass
         self.multiMatteAttributes(myRenderLayer=renderPass)
     cmd = 'self.passName[renderPass].' + str(attribut) + ' = ' + str(value).replace('nt.', 'pm.nt.')
     exec cmd
 def get_skin_cluster(self, **kwargs):
     node = kwargs.get("node", None)
     if isinstance(node, str):
         node = pm.PyNode(node)
     if isinstance(node, pm.Transform):
         node = node.getShape()
     if not node:
         return self.FAIL
     skin_cluster = pm.listConnections(node, type="skinCluster")
     if skin_cluster:
         return skin_cluster[0]
     return skin_cluster
示例#5
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
示例#6
0
    def deleteObjects(self, selection = None, node = None, attribute = None):
        if selection is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select some poly object(s)')
            return 
        if node is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass')
            return 
        for mySel in selection:
            for myConnected in pm.listConnections(node + '.' + attribute, shapes=True, connections=True):
                if mySel in myConnected:
                    pm.disconnectAttr(mySel + '.message', myConnected[0])


        print '[Arsenal] Object(s) delete done.'
示例#7
0
    def deletePass(self, layer = None):
        if layer is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass')
            return 
        pm.editRenderLayerGlobals(currentRenderLayer='defaultRenderLayer')
        for dependance in pm.listConnections(layer + '.message', destination=True, source=False, type='arsenalPass'):
            pm.lockNode(dependance, lock=False)
            print '[Arsenal] ' + dependance + ' deleted.'
            pm.delete(dependance)

        if pm.objExists(layer):
            pm.delete(layer)
            print '[Arsenal] ' + layer + ' deleted.'
        if layer in self.passName:
            del self.passName[layer]
示例#8
0
 def setSimpleValue(self, selection = list(), attribute = None, value = None, message = None):
     if len(selection) == 0:
         OpenMaya.MGlobal.displayError('[Arsenal] You must to have a selection')
         return 
     if attribute is None:
         OpenMaya.MGlobal.displayError('[Arsenal] Attribute not found')
         return 
     if value is None:
         OpenMaya.MGlobal.displayError('[Arsenal] No value gave')
         return 
     for sel in selection:
         if pm.objExists(sel + '.' + attribute):
             con = pm.listConnections(sel + '.' + attribute, d=False, s=True)
             if con:
                 if len(con) != 0:
                     return 
             print '[Arsenal] ' + str(sel) + ' :'
             pm.setAttr(sel + '.' + attribute, value)
             if message is not None:
                 print '         ' + message
示例#9
0
    def addObjects(self, selection = None, renderPass = None, attribute = None):
        if selection is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select some poly object(s)')
            return 
        if renderPass is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass')
            return 
        self.multiMatteAttributes(myRenderLayer=renderPass)
        cmd = 'self.passName[renderPass].' + str(attribute) + ' = ' + str(selection).replace('nt.', 'pm.nt.')
        exec cmd
        exec 'newValue = self.passName[renderPass].' + str(attribute)
        arsenalPass = pm.PyNode(renderPass + '_arsenalPass.' + attribute)
        for mySelect in newValue:
            arrayList = arsenalPass.getArrayIndices()
            finalNumber = 0
            if arrayList:
                finalNumber = arrayList[-1] + 1
            if mySelect not in pm.listConnections(renderPass + '_arsenalPass.' + attribute, destination=False, source=True):
                pm.connectAttr(mySelect + '.message', renderPass + '_arsenalPass.' + attribute + '[' + str(finalNumber) + ']', f=True)

        print '[Arsenal] Object(s) add done.'
示例#10
0
    def optimizeMat(self, layerMode = False, minSub = 8, maxSubd = 92):
        maxGlo = 1
        minGlo = 0
        allMaterials = pm.ls(type=['VRayCarPaintMtl', 'VRayFastSSS2', 'VRayMtl'])
        for myMat in allMaterials:
            reflectanceAttributes = {'["reflectionGlossiness"]': 'reflectionSubdivs',
             '["refractionGlossiness"]': 'refractionSubdivs',
             '["glossiness"]': 'reflectionSubdivs',
             '["coat_glossiness", "base_glossiness"]': 'subdivs'}
            for gloAttList in reflectanceAttributes:
                if pm.objExists(myMat + '.' + reflectanceAttributes[gloAttList]):
                    if not pm.getAttr(myMat + '.' + reflectanceAttributes[gloAttList], lock=True) and len(pm.listConnections(myMat + '.' + reflectanceAttributes[gloAttList], d=False, s=True)) == 0:
                        lastMoyeneValue = 1
                        first = True
                        go = False
                        for gloAtt in eval(gloAttList):
                            if pm.objExists(myMat + '.' + gloAtt) and len(pm.listConnections(myMat + '.' + gloAtt, d=False, s=True)) == 0:
                                gloValue = pm.getAttr(myMat + '.' + gloAtt)
                                if first:
                                    lastMoyeneValue = gloValue
                                    first = False
                                else:
                                    lastMoyeneValue = (lastMoyeneValue + gloValue) / 2
                                go = True

                        if go:
                            value = (lastMoyeneValue - maxGlo) * (maxSubd - minSub) / (minGlo - maxGlo) + minSub
                            if layerMode:
                                if pm.editRenderLayerGlobals(query=True, currentRenderLayer=True) == 'defaultRenderLayer':
                                    OpenMaya.MGlobal.displayError('[Arsenal Quality] You can not use layerMode if you are on masterLayer')
                                    return 
                                pm.editRenderLayerAdjustment(myMat + '.' + reflectanceAttributes[str(gloAttList)])
                            pm.setAttr(myMat.name() + '.' + reflectanceAttributes[str(gloAttList)], value)
                            print '[Arsenal Quality] ' + str(value) + ' setted on attribute ' + reflectanceAttributes[str(gloAttList)] + ' for material ' + myMat.name()


        print '[Arsenal Quality] All materials optimized.'
示例#11
0
def getShaderInfo(shadingEngine):
    """ 입력 받은 shading Engine으로 부터 surface shader, displacement, geometry 값을 얻어 
    json으로 넘기기 위해  dict 으로 리턴 한다.
    
    :param shadingEngine: shading Engine
    :type shadingEngine: nt.ShadingEngine
    :returns: {'surfaceShader': surfaceShader, 'displacement':displacementShader, 'geometry':geometries}
    :rtype: dict
    
    .. note:: geometry는 shape 이름들의 list 입니다.

    """
    surface = shadingEngine.surfaceShader.inputs()
    displacement = shadingEngine.displacementShader.inputs()
    geometry = pm.listConnections(shadingEngine, type='mesh')

    if surface:
        surfaceShaderName = surface[0].name()
    else:
        surfaceShaderName = ''

    if displacement:
        displacementShaderName = displacement[0].name()
    else:
        displacementShaderName = ''

    geometryList = []
    for geo in geometry:
        geometryList.append(geo.name())

    info = {
        'surfaceShader': surfaceShaderName,
        'displacement': displacementShaderName,
        'geometry': geometryList
    }

    return info
示例#12
0
    def start(self,
              renderPass=None,
              blackHoleMembers=list(),
              blackHoleMembersReceiveShd=list(),
              giMembersGenerate=list(),
              giMembersReceive=list(),
              primaryMembersOff=list(),
              reflectionMembersOff=list(),
              refractionMembersOff=list(),
              shadowCastsMembersOff=list(),
              lightSelectNormalMembers=list(),
              lightSelectDiffuseMembers=list(),
              lightSelectRawMembers=list(),
              lightSelectSpecularMembers=list()):
        if renderPass is None:
            renderPass = pm.editRenderLayerGlobals(query=True,
                                                   currentRenderLayer=True)
        arsenalPassName = str(renderPass) + '_arsenalPass'
        if not pm.objExists(arsenalPassName):
            OpenMaya.MGlobal.displayError('[Arsenal] ' + arsenalPassName +
                                          ' not found.')
            return
        if not blackHoleMembers:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.blackHoleMembers',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    blackHoleMembers.append(dag)

        if not blackHoleMembersReceiveShd:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.blackHoleMembersReceiveShd',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    blackHoleMembersReceiveShd.append(dag)

        if not giMembersGenerate:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.giMembersGenerate',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    giMembersGenerate.append(dag)

        if not giMembersReceive:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.giMembersReceive',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    giMembersReceive.append(dag)

        if not primaryMembersOff:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.primaryMembersOff',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    primaryMembersOff.append(dag)

        if not reflectionMembersOff:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.reflectionMembersOff',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    reflectionMembersOff.append(dag)

        if not refractionMembersOff:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.refractionMembersOff',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    refractionMembersOff.append(dag)

        if not shadowCastsMembersOff:
            myConnected = pm.listConnections(arsenalPassName +
                                             '.shadowCastsMembersOff',
                                             destination=False,
                                             source=True)
            for dag in self.getAllChildShapes(selection=myConnected,
                                              type=['mesh', 'VRayPlane']):
                if not dag.intermediateObject.get():
                    shadowCastsMembersOff.append(dag)

        allGroups = {}
        allGroups['blackHoleMembers'] = blackHoleMembers
        allGroups['blackHoleMembersReceiveShd'] = blackHoleMembersReceiveShd
        allGroups['giMembersGenerate'] = giMembersGenerate
        allGroups['giMembersReceive'] = giMembersReceive
        allGroups['primaryMembersOff'] = primaryMembersOff
        allGroups['reflectionMembersOff'] = reflectionMembersOff
        allGroups['refractionMembersOff'] = refractionMembersOff
        allGroups['shadowCastsMembersOff'] = shadowCastsMembersOff
        dicoInverse = {}
        for p in allGroups.keys():
            for o in allGroups[p]:
                if dicoInverse.has_key(o):
                    dicoInverse[o].append(p)
                else:
                    dicoInverse[o] = []
                    dicoInverse[o].append(p)

        liste = {}
        for dk in dicoInverse.keys():
            if liste.has_key(str(dicoInverse[dk])):
                liste[str(dicoInverse[dk])].append(dk)
            else:
                liste[str(dicoInverse[dk])] = []
                liste[str(dicoInverse[dk])].append(dk)

        liste_finale = {}
        for lk in liste.keys():
            liste_finale[str(liste[lk])] = lk

        vrayLambertMtl = None
        vrayLambert = False
        if pm.getAttr(arsenalPassName + '.vrayLambert'):
            vrayLambert = True
            vrayLambertbrdfMtlName = 'vrayLambertBRDFMtl_arsenal@diffuse'
            if not vrUtils.findByName(vrayLambertbrdfMtlName):
                vrUtils.create('BRDFDiffuse', vrayLambertbrdfMtlName)
            vrayLambertbrdfMtl = vrUtils.findByName(vrayLambertbrdfMtlName)
            gamaValue = pm.getAttr('vraySettings.cmap_gamma')
            if float('%.2f' % gamaValue) == 2.2 and not pm.getAttr(
                    'vraySettings.cmap_linearworkflow'):
                vrayLambertCOlorCorrectMtlName = 'vrayLambertCOlorCorrect_arsenal'
                if not vrUtils.findByName(vrayLambertCOlorCorrectMtlName):
                    vrUtils.create('ColorCorrect',
                                   vrayLambertCOlorCorrectMtlName)
                vrayLambertCOlorCorrect = vrUtils.findByName(
                    vrayLambertCOlorCorrectMtlName)
                vrayLambertCOlorCorrect[0].set(
                    'texture_map', vrUtils.AColor(0.7, 0.7, 0.7, 1))
                vrayLambertCOlorCorrect[0].set('preprocess', 1)
                vrayLambertCOlorCorrect[0].set('pre_gamma', 2.2)
                vrayLambertbrdfMtl[0].set('color', vrUtils.Color(0, 0, 0))
                vrayLambertbrdfMtl[0].set('color_tex',
                                          vrayLambertCOlorCorrect[0])
            else:
                vrayLambertbrdfMtl[0].set('color',
                                          vrUtils.Color(0.7, 0.7, 0.7))
        if vrayLambert:
            allNodes = vrUtils.findByType('Node')
        i = 0
        for result in liste_finale:
            listObjects = eval(result.replace('nt', 'pm.nt'))
            i += 1
            for mySel in listObjects:
                strObj = str(mySel.name()).replace(':', '__')
                node = vrUtils.findByName(strObj + '@node')
                if len(node) == 0:
                    continue
                baseMat = node[0].get('material')
                mode = 0
                if 'primaryMembersOff' in liste_finale[
                        result] or 'reflectionMembersOff' in liste_finale[
                            result] or 'refractionMembersOff' in liste_finale[
                                result] or 'shadowCastsMembersOff' in liste_finale[
                                    result]:
                    mode = 1
                    mtlRenderStatsName = baseMat.name(
                    ) + '_arsenal%d@renderStats' % i
                    if not vrUtils.findByName(mtlRenderStatsName):
                        vrUtils.create('MtlRenderStats', mtlRenderStatsName)
                    mtlRenderStats = vrUtils.findByName(mtlRenderStatsName)
                    if 'primaryMembersOff' in liste_finale[result]:
                        mtlRenderStats[0].set('camera_visibility', 0)
                    if 'reflectionMembersOff' in liste_finale[result]:
                        mtlRenderStats[0].set('reflections_visibility', 0)
                    if 'refractionMembersOff' in liste_finale[result]:
                        mtlRenderStats[0].set('refractions_visibility', 0)
                    if 'shadowCastsMembersOff' in liste_finale[result]:
                        mtlRenderStats[0].set('shadows_visibility', 0)
                if 'blackHoleMembers' in liste_finale[
                        result] or 'blackHoleMembersReceiveShd' in liste_finale[
                            result] or 'giMembersGenerate' in liste_finale[
                                result] or 'giMembersReceive' in liste_finale[
                                    result]:
                    if mode == 1:
                        mode = 3
                    else:
                        mode = 2
                    wrapperName = baseMat.name() + '_arsenal%d@mtlwrapper' % i
                    if not vrUtils.findByName(wrapperName):
                        vrUtils.create('MtlWrapper', wrapperName)
                    wrapper = vrUtils.findByName(wrapperName)
                    if 'blackHoleMembers' in liste_finale[result]:
                        wrapper[0].set('matte_surface', 1)
                        wrapper[0].set('alpha_contribution', -1)
                        wrapper[0].set('reflection_amount', 0)
                        wrapper[0].set('refraction_amount', 0)
                        if 'generate_render_elements' in vrUtils.getPluginParams(
                                wrapper[0]):
                            wrapper[0].set('generate_render_elements', 0)
                        if 'blackHoleMembersReceiveShd' in liste_finale[
                                result]:
                            wrapper[0].set('shadows', 1)
                            wrapper[0].set('affect_alpha', 1)
                    if 'giMembersGenerate' in liste_finale[result]:
                        wrapper[0].set('generate_gi', 0)
                    if 'giMembersReceive' in liste_finale[result]:
                        wrapper[0].set('receive_gi', 0)
                if mode == 1:
                    mtlRenderStats[0].set('base_mtl', baseMat)
                    node[0].set('material', mtlRenderStats)
                elif mode == 2:
                    wrapper[0].set('base_material', baseMat)
                    node[0].set('material', wrapper)
                elif mode == 3:
                    wrapper[0].set('base_material', baseMat)
                    mtlRenderStats[0].set('base_mtl', wrapper)
                    node[0].set('material', mtlRenderStats)

        if vrayLambert:
            vrayBumpNodes = vrUtils.findByType('BRDFBump')
            for vrayBumpNode in vrayBumpNodes:
                vrayBumpNode.set('base_brdf', vrayLambertbrdfMtl[0])

            vrayBlendNodeNodes = vrUtils.findByType('BRDFLayered')
            for vrayBlendNodeNode in vrayBlendNodeNodes:
                goodListBrdf = list()
                listBrdfs = vrayBlendNodeNode.get('brdfs')
                for listBrdf in listBrdfs:
                    if listBrdf in vrayBumpNodes:
                        goodListBrdf.append(listBrdf)
                    else:
                        goodListBrdf.append(vrayLambertbrdfMtl[0])

                vrayBlendNodeNode.set('brdfs', goodListBrdf)

            vraySimpleBRDFNodes = vrUtils.findByType('MtlSingleBRDF')
            for vraySimpleBRDFNode in vraySimpleBRDFNodes:
                inBRDF = vraySimpleBRDFNode.get('brdf')
                if inBRDF not in vrayBumpNodes and inBRDF not in vrayBlendNodeNodes:
                    vraySimpleBRDFNode.set('brdf', vrayLambertbrdfMtl[0])

        actualList = pm.getAttr(arsenalPassName + '.multimatteMaskName')
        if actualList not in ('', '{}'):
            actualList = eval(actualList)
            for matteNumber in actualList:
                extraTexName = arsenalPassName + '_VRayUserColorMultimatte_number' + str(
                    matteNumber)
                vrUtils.create('TexUserColor', extraTexName)
                variableName = actualList[matteNumber] + '_' + arsenalPassName
                extraTex = vrUtils.findByName(extraTexName)
                extraTex[0].set('default_color', vrUtils.AColor(0, 0, 0, 1))
                extraTex[0].set('user_attribute', variableName)
                extraTexRenderElementName = arsenalPassName + '_RenderElementMultimatte_number' + str(
                    matteNumber)
                vrUtils.create('RenderChannelExtraTex',
                               extraTexRenderElementName)
                extraTexRenderElement = vrUtils.findByName(
                    extraTexRenderElementName)
                extraTexRenderElement[0].set('name', actualList[matteNumber])
                extraTexRenderElement[0].set('consider_for_aa', 1)
                extraTexRenderElement[0].set('affect_matte_objects', 1)
                extraTexRenderElement[0].set('texmap', extraTex[0])
                extraTexRenderElement[0].set('filtering', 1)
                myConnected = pm.listConnections(
                    arsenalPassName + '.multimatteMaskMembers[' +
                    str(matteNumber) + '].multimatteMaskMembersRed',
                    destination=False,
                    source=True)
                for dag in self.getAllChildShapes(selection=myConnected,
                                                  type=['mesh', 'VRayPlane']):
                    if not dag.intermediateObject.get():
                        strObj = str(dag.name()).replace(':', '__')
                        node = vrUtils.findByName(strObj + '@node')
                        if len(node) == 0:
                            continue
                        currentUserAttr = node[0].get('user_attributes')
                        value = variableName + '=1,0,0;' + currentUserAttr
                        node[0].set('user_attributes', value)
                        pm.mel.warning(strObj + '@node')
                        pm.mel.warning(variableName)

                myConnected = pm.listConnections(
                    arsenalPassName + '.multimatteMaskMembers[' +
                    str(matteNumber) + '].multimatteMaskMembersGreen',
                    destination=False,
                    source=True)
                for dag in self.getAllChildShapes(selection=myConnected,
                                                  type=['mesh', 'VRayPlane']):
                    if not dag.intermediateObject.get():
                        strObj = str(dag.name()).replace(':', '__')
                        node = vrUtils.findByName(strObj + '@node')
                        if len(node) == 0:
                            continue
                        currentUserAttr = node[0].get('user_attributes')
                        value = variableName + '=0,1,0;' + currentUserAttr
                        node[0].set('user_attributes', value)

                myConnected = pm.listConnections(
                    arsenalPassName + '.multimatteMaskMembers[' +
                    str(matteNumber) + '].multimatteMaskMembersBlue',
                    destination=False,
                    source=True)
                for dag in self.getAllChildShapes(selection=myConnected,
                                                  type=['mesh', 'VRayPlane']):
                    if not dag.intermediateObject.get():
                        strObj = str(dag.name()).replace(':', '__')
                        node = vrUtils.findByName(strObj + '@node')
                        if len(node) == 0:
                            continue
                        currentUserAttr = node[0].get('user_attributes')
                        value = variableName + '=0,0,1;' + currentUserAttr
                        node[0].set('user_attributes', value)

        if pm.getAttr(arsenalPassName + '.vrayMaterialID'):
            self.deeXMaterialIDGeneratorFunc()
        if pm.getAttr(arsenalPassName + '.vrayProxyObjectID'):
            self.deeXProxyObjectIDGeneratorFunc()
        if not lightSelectNormalMembers:
            if pm.getAttr(arsenalPassName + '.lightSelectAllNormal'):
                lightSelectNormalMembers = vrUtils.findByType(
                    'Light*') + vrUtils.findByType('MayaLight*')
            else:
                myConnected = pm.listConnections(arsenalPassName +
                                                 '.lightSelectNormalMembers',
                                                 destination=False,
                                                 source=True)
                for dag in self.getAllChildShapes(
                        selection=myConnected, type=pm.listNodeTypes('light')):
                    if not dag.intermediateObject.get():
                        strObj = str(dag.name()).replace(':', '__')
                        node = vrUtils.findByName(strObj)
                        lightSelectNormalMembers.append(node[0])

        if not lightSelectDiffuseMembers:
            if pm.getAttr(arsenalPassName + '.lightSelectAllDiffuse'):
                lightSelectDiffuseMembers = vrUtils.findByType(
                    'Light*') + vrUtils.findByType('MayaLight*')
            else:
                myConnected = pm.listConnections(arsenalPassName +
                                                 '.lightSelectDiffuseMembers',
                                                 destination=False,
                                                 source=True)
                for dag in self.getAllChildShapes(
                        selection=myConnected, type=pm.listNodeTypes('light')):
                    if not dag.intermediateObject.get():
                        strObj = str(dag.name()).replace(':', '__')
                        node = vrUtils.findByName(strObj)
                        lightSelectDiffuseMembers.append(node[0])

        if not lightSelectRawMembers:
            if pm.getAttr(arsenalPassName + '.lightSelectAllRaw'):
                lightSelectRawMembers = vrUtils.findByType(
                    'Light*') + vrUtils.findByType('MayaLight*')
            else:
                myConnected = pm.listConnections(arsenalPassName +
                                                 '.lightSelectRawMembers',
                                                 destination=False,
                                                 source=True)
                for dag in self.getAllChildShapes(
                        selection=myConnected, type=pm.listNodeTypes('light')):
                    if not dag.intermediateObject.get():
                        strObj = str(dag.name()).replace(':', '__')
                        node = vrUtils.findByName(strObj)
                        lightSelectRawMembers.append(node[0])

        if not lightSelectSpecularMembers:
            if pm.getAttr(arsenalPassName + '.lightSelectAllSpecular'):
                lightSelectSpecularMembers = vrUtils.findByType(
                    'Light*') + vrUtils.findByType('MayaLight*')
            else:
                myConnected = pm.listConnections(arsenalPassName +
                                                 '.lightSelectSpecularMembers',
                                                 destination=False,
                                                 source=True)
                for dag in self.getAllChildShapes(
                        selection=myConnected, type=pm.listNodeTypes('light')):
                    if not dag.intermediateObject.get():
                        strObj = str(dag.name()).replace(':', '__')
                        node = vrUtils.findByName(strObj)
                        lightSelectSpecularMembers.append(node[0])

        self.deeXLightSelectGeneratorFunc(
            lightNormal=lightSelectNormalMembers,
            lightDiffuse=lightSelectDiffuseMembers,
            lightRaw=lightSelectRawMembers,
            lightSpecular=lightSelectSpecularMembers)
示例#13
0
	def start(self, renderPass = None, blackHoleMembers = list(), blackHoleMembersReceiveShd = list(), giMembersGenerate = list(), giMembersReceive = list(), primaryMembersOff = list(), reflectionMembersOff = list(), refractionMembersOff = list(), shadowCastsMembersOff = list(), lightSelectNormalMembers = list(), lightSelectDiffuseMembers = list(), lightSelectRawMembers = list(), lightSelectSpecularMembers = list()):
		if renderPass is None:
			renderPass = pm.editRenderLayerGlobals(query=True, currentRenderLayer=True)
		arsenalPassName = str(renderPass) + '_arsenalPass'
		if not pm.objExists(arsenalPassName):
			OpenMaya.MGlobal.displayError('[Arsenal] ' + arsenalPassName + ' not found.')
			return 
		if not blackHoleMembers:
			myConnected = pm.listConnections(arsenalPassName + '.blackHoleMembers', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					blackHoleMembers.append(dag)

		if not blackHoleMembersReceiveShd:
			myConnected = pm.listConnections(arsenalPassName + '.blackHoleMembersReceiveShd', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					blackHoleMembersReceiveShd.append(dag)

		if not giMembersGenerate:
			myConnected = pm.listConnections(arsenalPassName + '.giMembersGenerate', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					giMembersGenerate.append(dag)

		if not giMembersReceive:
			myConnected = pm.listConnections(arsenalPassName + '.giMembersReceive', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					giMembersReceive.append(dag)

		if not primaryMembersOff:
			myConnected = pm.listConnections(arsenalPassName + '.primaryMembersOff', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					primaryMembersOff.append(dag)

		if not reflectionMembersOff:
			myConnected = pm.listConnections(arsenalPassName + '.reflectionMembersOff', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					reflectionMembersOff.append(dag)

		if not refractionMembersOff:
			myConnected = pm.listConnections(arsenalPassName + '.refractionMembersOff', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					refractionMembersOff.append(dag)

		if not shadowCastsMembersOff:
			myConnected = pm.listConnections(arsenalPassName + '.shadowCastsMembersOff', destination=False, source=True)
			for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
				if not dag.intermediateObject.get():
					shadowCastsMembersOff.append(dag)

		allGroups = {}
		allGroups['blackHoleMembers'] = blackHoleMembers
		allGroups['blackHoleMembersReceiveShd'] = blackHoleMembersReceiveShd
		allGroups['giMembersGenerate'] = giMembersGenerate
		allGroups['giMembersReceive'] = giMembersReceive
		allGroups['primaryMembersOff'] = primaryMembersOff
		allGroups['reflectionMembersOff'] = reflectionMembersOff
		allGroups['refractionMembersOff'] = refractionMembersOff
		allGroups['shadowCastsMembersOff'] = shadowCastsMembersOff
		dicoInverse = {}
		for p in allGroups.keys():
			for o in allGroups[p]:
				if dicoInverse.has_key(o):
					dicoInverse[o].append(p)
				else:
					dicoInverse[o] = []
					dicoInverse[o].append(p)


		liste = {}
		for dk in dicoInverse.keys():
			if liste.has_key(str(dicoInverse[dk])):
				liste[str(dicoInverse[dk])].append(dk)
			else:
				liste[str(dicoInverse[dk])] = []
				liste[str(dicoInverse[dk])].append(dk)

		liste_finale = {}
		for lk in liste.keys():
			liste_finale[str(liste[lk])] = lk

		vrayLambertMtl = None
		vrayLambert = False
		if pm.getAttr(arsenalPassName + '.vrayLambert'):
			vrayLambert = True
			vrayLambertbrdfMtlName = 'vrayLambertBRDFMtl_arsenal@diffuse'
			if not vrUtils.findByName(vrayLambertbrdfMtlName):
				vrUtils.create('BRDFDiffuse', vrayLambertbrdfMtlName)
			vrayLambertbrdfMtl = vrUtils.findByName(vrayLambertbrdfMtlName)
			gamaValue = pm.getAttr('vraySettings.cmap_gamma')
			if float('%.2f' % gamaValue) == 2.2 and not pm.getAttr('vraySettings.cmap_linearworkflow'):
				vrayLambertCOlorCorrectMtlName = 'vrayLambertCOlorCorrect_arsenal'
				if not vrUtils.findByName(vrayLambertCOlorCorrectMtlName):
					vrUtils.create('ColorCorrect', vrayLambertCOlorCorrectMtlName)
				vrayLambertCOlorCorrect = vrUtils.findByName(vrayLambertCOlorCorrectMtlName)
				vrayLambertCOlorCorrect[0].set('texture_map', vrUtils.AColor(0.7, 0.7, 0.7, 1))
				vrayLambertCOlorCorrect[0].set('preprocess', 1)
				vrayLambertCOlorCorrect[0].set('pre_gamma', 2.2)
				vrayLambertbrdfMtl[0].set('color', vrUtils.Color(0, 0, 0))
				vrayLambertbrdfMtl[0].set('color_tex', vrayLambertCOlorCorrect[0])
			else:
				vrayLambertbrdfMtl[0].set('color', vrUtils.Color(0.7, 0.7, 0.7))
		if vrayLambert:
			allNodes = vrUtils.findByType('Node')
		i = 0
		for result in liste_finale:
			listObjects = eval(result.replace('nt', 'pm.nt'))
			i += 1
			for mySel in listObjects:
				strObj = str(mySel.name()).replace(':', '__')
				node = vrUtils.findByName(strObj + '@node')
				if len(node) == 0:
					continue
				baseMat = node[0].get('material')
				mode = 0
				if 'primaryMembersOff' in liste_finale[result] or 'reflectionMembersOff' in liste_finale[result] or 'refractionMembersOff' in liste_finale[result] or 'shadowCastsMembersOff' in liste_finale[result]:
					mode = 1
					mtlRenderStatsName = baseMat.name() + '_arsenal%d@renderStats' % i
					if not vrUtils.findByName(mtlRenderStatsName):
						vrUtils.create('MtlRenderStats', mtlRenderStatsName)
					mtlRenderStats = vrUtils.findByName(mtlRenderStatsName)
					if 'primaryMembersOff' in liste_finale[result]:
						mtlRenderStats[0].set('camera_visibility', 0)
					if 'reflectionMembersOff' in liste_finale[result]:
						mtlRenderStats[0].set('reflections_visibility', 0)
					if 'refractionMembersOff' in liste_finale[result]:
						mtlRenderStats[0].set('refractions_visibility', 0)
					if 'shadowCastsMembersOff' in liste_finale[result]:
						mtlRenderStats[0].set('shadows_visibility', 0)
				if 'blackHoleMembers' in liste_finale[result] or 'blackHoleMembersReceiveShd' in liste_finale[result] or 'giMembersGenerate' in liste_finale[result] or 'giMembersReceive' in liste_finale[result]:
					if mode == 1:
						mode = 3
					else:
						mode = 2
					wrapperName = baseMat.name() + '_arsenal%d@mtlwrapper' % i
					if not vrUtils.findByName(wrapperName):
						vrUtils.create('MtlWrapper', wrapperName)
					wrapper = vrUtils.findByName(wrapperName)
					if 'blackHoleMembers' in liste_finale[result]:
						wrapper[0].set('matte_surface', 1)
						wrapper[0].set('alpha_contribution', -1)
						wrapper[0].set('reflection_amount', 0)
						wrapper[0].set('refraction_amount', 0)
						if 'generate_render_elements' in vrUtils.getPluginParams(wrapper[0]):
							wrapper[0].set('generate_render_elements', 0)
						if 'blackHoleMembersReceiveShd' in liste_finale[result]:
							wrapper[0].set('shadows', 1)
							wrapper[0].set('affect_alpha', 1)
					if 'giMembersGenerate' in liste_finale[result]:
						wrapper[0].set('generate_gi', 0)
					if 'giMembersReceive' in liste_finale[result]:
						wrapper[0].set('receive_gi', 0)
				if mode == 1:
					mtlRenderStats[0].set('base_mtl', baseMat)
					node[0].set('material', mtlRenderStats)
				elif mode == 2:
					wrapper[0].set('base_material', baseMat)
					node[0].set('material', wrapper)
				elif mode == 3:
					wrapper[0].set('base_material', baseMat)
					mtlRenderStats[0].set('base_mtl', wrapper)
					node[0].set('material', mtlRenderStats)


		if vrayLambert:
			vrayBumpNodes = vrUtils.findByType('BRDFBump')
			for vrayBumpNode in vrayBumpNodes:
				vrayBumpNode.set('base_brdf', vrayLambertbrdfMtl[0])

			vrayBlendNodeNodes = vrUtils.findByType('BRDFLayered')
			for vrayBlendNodeNode in vrayBlendNodeNodes:
				goodListBrdf = list()
				listBrdfs = vrayBlendNodeNode.get('brdfs')
				for listBrdf in listBrdfs:
					if listBrdf in vrayBumpNodes:
						goodListBrdf.append(listBrdf)
					else:
						goodListBrdf.append(vrayLambertbrdfMtl[0])

				vrayBlendNodeNode.set('brdfs', goodListBrdf)

			vraySimpleBRDFNodes = vrUtils.findByType('MtlSingleBRDF')
			for vraySimpleBRDFNode in vraySimpleBRDFNodes:
				inBRDF = vraySimpleBRDFNode.get('brdf')
				if inBRDF not in vrayBumpNodes and inBRDF not in vrayBlendNodeNodes:
					vraySimpleBRDFNode.set('brdf', vrayLambertbrdfMtl[0])

		actualList = pm.getAttr(arsenalPassName + '.multimatteMaskName')
		if actualList not in ('', '{}'):
			actualList = eval(actualList)
			for matteNumber in actualList:
				extraTexName = arsenalPassName + '_VRayUserColorMultimatte_number' + str(matteNumber)
				vrUtils.create('TexUserColor', extraTexName)
				variableName = actualList[matteNumber] + '_' + arsenalPassName
				extraTex = vrUtils.findByName(extraTexName)
				extraTex[0].set('default_color', vrUtils.AColor(0, 0, 0, 1))
				extraTex[0].set('user_attribute', variableName)
				extraTexRenderElementName = arsenalPassName + '_RenderElementMultimatte_number' + str(matteNumber)
				vrUtils.create('RenderChannelExtraTex', extraTexRenderElementName)
				extraTexRenderElement = vrUtils.findByName(extraTexRenderElementName)
				extraTexRenderElement[0].set('name', actualList[matteNumber])
				extraTexRenderElement[0].set('consider_for_aa', 1)
				extraTexRenderElement[0].set('affect_matte_objects', 1)
				extraTexRenderElement[0].set('texmap', extraTex[0])
				extraTexRenderElement[0].set('filtering', 1)
				myConnected = pm.listConnections(arsenalPassName + '.multimatteMaskMembers[' + str(matteNumber) + '].multimatteMaskMembersRed', destination=False, source=True)
				for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
					if not dag.intermediateObject.get():
						strObj = str(dag.name()).replace(':', '__')
						node = vrUtils.findByName(strObj + '@node')
						if len(node) == 0:
							continue
						currentUserAttr = node[0].get('user_attributes')
						value = variableName + '=1,0,0;' + currentUserAttr
						node[0].set('user_attributes', value)
						pm.mel.warning(strObj + '@node')
						pm.mel.warning(variableName)

				myConnected = pm.listConnections(arsenalPassName + '.multimatteMaskMembers[' + str(matteNumber) + '].multimatteMaskMembersGreen', destination=False, source=True)
				for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
					if not dag.intermediateObject.get():
						strObj = str(dag.name()).replace(':', '__')
						node = vrUtils.findByName(strObj + '@node')
						if len(node) == 0:
							continue
						currentUserAttr = node[0].get('user_attributes')
						value = variableName + '=0,1,0;' + currentUserAttr
						node[0].set('user_attributes', value)

				myConnected = pm.listConnections(arsenalPassName + '.multimatteMaskMembers[' + str(matteNumber) + '].multimatteMaskMembersBlue', destination=False, source=True)
				for dag in self.getAllChildShapes(selection=myConnected, type=['mesh', 'VRayPlane']):
					if not dag.intermediateObject.get():
						strObj = str(dag.name()).replace(':', '__')
						node = vrUtils.findByName(strObj + '@node')
						if len(node) == 0:
							continue
						currentUserAttr = node[0].get('user_attributes')
						value = variableName + '=0,0,1;' + currentUserAttr
						node[0].set('user_attributes', value)


		if pm.getAttr(arsenalPassName + '.vrayMaterialID'):
			self.deeXMaterialIDGeneratorFunc()
		if pm.getAttr(arsenalPassName + '.vrayProxyObjectID'):
			self.deeXProxyObjectIDGeneratorFunc()
		if not lightSelectNormalMembers:
			if pm.getAttr(arsenalPassName + '.lightSelectAllNormal'):
				lightSelectNormalMembers = vrUtils.findByType('Light*') + vrUtils.findByType('MayaLight*')
			else:
				myConnected = pm.listConnections(arsenalPassName + '.lightSelectNormalMembers', destination=False, source=True)
				for dag in self.getAllChildShapes(selection=myConnected, type=pm.listNodeTypes('light')):
					if not dag.intermediateObject.get():
						strObj = str(dag.name()).replace(':', '__')
						node = vrUtils.findByName(strObj)
						lightSelectNormalMembers.append(node[0])

		if not lightSelectDiffuseMembers:
			if pm.getAttr(arsenalPassName + '.lightSelectAllDiffuse'):
				lightSelectDiffuseMembers = vrUtils.findByType('Light*') + vrUtils.findByType('MayaLight*')
			else:
				myConnected = pm.listConnections(arsenalPassName + '.lightSelectDiffuseMembers', destination=False, source=True)
				for dag in self.getAllChildShapes(selection=myConnected, type=pm.listNodeTypes('light')):
					if not dag.intermediateObject.get():
						strObj = str(dag.name()).replace(':', '__')
						node = vrUtils.findByName(strObj)
						lightSelectDiffuseMembers.append(node[0])

		if not lightSelectRawMembers:
			if pm.getAttr(arsenalPassName + '.lightSelectAllRaw'):
				lightSelectRawMembers = vrUtils.findByType('Light*') + vrUtils.findByType('MayaLight*')
			else:
				myConnected = pm.listConnections(arsenalPassName + '.lightSelectRawMembers', destination=False, source=True)
				for dag in self.getAllChildShapes(selection=myConnected, type=pm.listNodeTypes('light')):
					if not dag.intermediateObject.get():
						strObj = str(dag.name()).replace(':', '__')
						node = vrUtils.findByName(strObj)
						lightSelectRawMembers.append(node[0])

		if not lightSelectSpecularMembers:
			if pm.getAttr(arsenalPassName + '.lightSelectAllSpecular'):
				lightSelectSpecularMembers = vrUtils.findByType('Light*') + vrUtils.findByType('MayaLight*')
			else:
				myConnected = pm.listConnections(arsenalPassName + '.lightSelectSpecularMembers', destination=False, source=True)
				for dag in self.getAllChildShapes(selection=myConnected, type=pm.listNodeTypes('light')):
					if not dag.intermediateObject.get():
						strObj = str(dag.name()).replace(':', '__')
						node = vrUtils.findByName(strObj)
						lightSelectSpecularMembers.append(node[0])

		self.deeXLightSelectGeneratorFunc(lightNormal=lightSelectNormalMembers, lightDiffuse=lightSelectDiffuseMembers, lightRaw=lightSelectRawMembers, lightSpecular=lightSelectSpecularMembers)
示例#14
0
    def exportPass(self, layers = list(), path = None):
        if not layers:
            OpenMaya.MGlobal.displayError('[Arsenal] Please select pass')
            return 
        if not path:
            return 
        splited = os.path.basename(path[0]).split('__')
        director = os.path.dirname(path[0])
        if '.arpass' in splited[-1] and len(splited) != 1:
            splited.pop(-1)
        cleaned = '_'.join(splited)
        for layer in layers:
            renderLayer = pm.PyNode(layer)
            suffix = '__' + renderLayer.name()
            finalPath = os.path.join(director, cleaned.split('.')[0] + suffix + '.arpass')
            toExport = layer + '_arsenalPass'
            pm.select(toExport, r=True)
            pm.exportSelected(finalPath, force=True, options='v=0;', type='mayaAscii', pr=True, constructionHistory=False, channels=False, constraints=False, expressions=False, shader=False)
            shutil.move(finalPath + '.ma', finalPath)
            pm.select(cl=True)
            objConnected = pm.listConnections(toExport, plugs=True, c=True)
            if not objConnected:
                continue
            info = {}
            dicConnect = {}
            infoLayer = {}
            infoLayer['name'] = layer
            infoLayer['global'] = renderLayer.g.get()
            listMembersLayer = {}
            for strMember in renderLayer.listMembers(fullNames=True):
                member = pm.PyNode(strMember)
                shortName = member.name()
                longName = member.longName()
                longNameWithoutNameSpace = pm.NameParser(longName).stripNamespace()
                shortNameWithoutNamespace = member.stripNamespace()
                listMembersLayer[str(longName)] = [str(longName),
                 str(shortName),
                 str(longNameWithoutNameSpace),
                 str(shortNameWithoutNamespace)]

            infoLayer['members'] = listMembersLayer
            dicConnect['layer'] = infoLayer
            for connect in objConnected:
                dst = connect[0].name()
                src = connect[1]
                srcNodeName = src.nodeName()
                srcAttrName = src.attrName(longName=True)
                srcShort = src.name()
                srcAttr = src.longName(fullPath=True)
                srcShortWithoutNamespace = src.node().stripNamespace() + '.' + srcAttr
                srcLong = src.node().longName() + '.' + srcAttr
                srcLongWithoutNamespace = pm.NameParser(srcLong).stripNamespace()
                if str(srcLong) in info:
                    actualDst = info[str(srcLong)]['destination']
                    actualDst.append(dst)
                    info[str(srcLong)] = {'destination': actualDst,
                     'sources': [str(srcLong),
                                 str(srcShort),
                                 str(srcLongWithoutNamespace),
                                 str(srcShortWithoutNamespace)]}
                else:
                    info[str(srcLong)] = {'destination': [dst],
                     'sources': [str(srcLong),
                                 str(srcShort),
                                 str(srcLongWithoutNamespace),
                                 str(srcShortWithoutNamespace)]}

            dicConnect['connections'] = info
            path = os.path.join(director, cleaned.split('.')[0] + suffix + '.arpassinfo')
            if self.writeTxtFile(path=path, text=str(dicConnect)):
                print '[Arsenal] ' + path + ' writed.'
            else:
                OpenMaya.MGlobal.displayError('[Arsenal] Can not write ' + path)
                return