Created
July 11, 2016 08:26
-
-
Save tokejepsen/d1da98fe2d09bcd5d4a418528089ddcf to your computer and use it in GitHub Desktop.
Maya: Render Mattes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Select the geometry to make the renderlayers from. | |
Will find all the materials (lambert), make a renderlayer per material only showing that material. | |
""" | |
import traceback | |
import pymel.core | |
selection = pymel.core.ls(selection=True) | |
shader = pymel.core.shadingNode('lambert', name='no_alpha_mat', asShader=1) | |
shader.matteOpacity.set(0) | |
shader.colorR.set(0) | |
shader.colorG.set(0) | |
shader.colorB.set(0) | |
shader_sg = pymel.core.sets(renderable=1, noSurfaceShader=1, empty=1, name='no_alpha_mat_SG') | |
pymel.core.connectAttr( shader + ".outColor", shader_sg + ".surfaceShader", force=1) | |
materials = {} | |
for node in selection: | |
for shp in node.getShapes(): | |
for mat in shp.listConnections(type='shadingEngine'): | |
if mat in materials: | |
materials[mat].append(node) | |
else: | |
materials[mat] = [node] | |
drg = pymel.core.PyNode('defaultRenderGlobals') | |
for sg in materials: | |
mat = None | |
try: | |
mat = sg.listConnections(type='lambert')[0] | |
except: | |
continue | |
layer = pymel.core.rendering.createRenderLayer(name=mat.name().split(':')[-1], empty=True) | |
layer.addMembers(selection) | |
layer.setCurrent() | |
layer.addAdjustments(drg.currentRenderer) | |
drg.currentRenderer.set('mayaSoftware') | |
layer.addAdjustments(drg.imageFormat) | |
drg.imageFormat.set(32) | |
for node in selection: | |
if node not in materials[sg]: | |
pymel.core.sets(shader_sg, edit=1, forceElement=node) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment