我想向渲染层添加一个名为“ myBlinn”的着色器替代。 到目前为止,我已经能够创建渲染层并创建一个包含场景中所有对象的集合。我现在不知道如何使用python创建着色器覆盖。你们可以帮忙吗?
这是到目前为止的代码。
import maya.app.renderSetup.model.override as override
import maya.app.renderSetup.model.selector as selector
import maya.app.renderSetup.model.collection as collection
import maya.app.renderSetup.model.renderLayer as renderLayer
import maya.app.renderSetup.model.renderSetup as renderSetup
rs = renderSetup.instance()
rl = rs.createRenderLayer("MyRenderSetupLayer")
c1 = rl.createCollection("meshCollection")
c1.getSelector().setPattern('**')
rs.switchToLayer(rl)
答案 0 :(得分:1)
这是在Maya 2019.1中测试过的代码
import maya.cmds as cmds
import maya.app.renderSetup.model.override as override
import maya.app.renderSetup.model.selector as selector
import maya.app.renderSetup.model.collection as collection
import maya.app.renderSetup.model.renderLayer as renderLayer
import maya.app.renderSetup.model.renderSetup as renderSetup
rs = renderSetup.instance()
try: rl = rs.getRenderLayer("myRenderSetupLayer")
except: rl = rs.createRenderLayer("myRenderSetupLayer")
try: c1 = rl.getCollectionByName("meshCollection")
except: c1 = rl.createCollection("meshCollection")
# shading group filter
try: c2 = c1.getCollectionByName("SGs")
except: c2 = c1.createCollection("SGs")
sl2= c2.getSelector()
sl2.setFilterType(11) # Collection Filters = Shading engines
sl2.setPattern('*') # 從上層 Collection 繼承的所有對象
# Shader Override
try: so = c2.getOverrides()[0] # 返回 Collection 下的 Override 列表
except: so = c2.createOverride("anyName", "shaderOverride")
# assign shader
so.setShader("myBlinn")