RenderSetupをPythonで操る方法 part3

takkun
どうも!たっくんです!

あれこれ試したりし、解析したりした内容になりますが、今回は「オーバーライド」周りを書いていきたいと思います!

RenderSetupをPythonで操る方法 part1

2020.04.08

RenderSetupをPythonで操る方法 part2

2020.04.09

RenderSetupをPythonで操る方法 part4

2020.04.11

RenderSetupをPythonで操る方法 part5

2020.04.12

Absolute Overrideの作成/値の設定

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')

# Absolute Overrideを作成。
override = collect.createAbsoluteOverride('persp', 'visibility')
override.setAttrValue(False)

Relative Overrideの作成/値の設定

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')

# Relative Overrideの作成
override = collect.createRelativeOverride('persp', 'tx')
override.setMultiply(1)
override.setOffset(1)

Connection Overrideの作成/値の設定

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')

# Connection Overrideの作成
override = collect.createConnectionOverride('persp', 'v')
override.setSource('locator1.v')

Shader Overrideの作成/値の設定

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')

# Shader Overrideの作成
# 汎用的なcreateOverrideを使って、Typeを指定する
override = collect.createOverride('lambert2SG', typeIDs.shaderOverride)
override.setShader('blinn1', '.outColor')

Type内容
typeIDs.absOverrideAbsolute Override
typeIDs.relOverrideRelative Override
typeIDs.connectionOverrideConnection Override
typeIDs.shaderOverrideShader Override
typeIDs.materialOverrideMaterial Override

Matrial Overrideの作成/値の設定

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')

# Matrial Overrideの作成
# 汎用的なcreateOverrideを使って、Typeを指定する
override = collect.createOverride('lambert2SG', typeIDs.materialOverride)
override.setMaterial('blinn1SG')
Type内容
typeIDs.absOverrideAbsolute Override
typeIDs.relOverrideRelative Override
typeIDs.connectionOverrideConnection Override
typeIDs.shaderOverrideShader Override
typeIDs.materialOverrideMaterial Override

オーバーライドの取得

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')

# コレクションのオーバーライドを全て取得
overrides = collect.getOverrides()

オーバーライドの削除

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')
overrides = collect.getOverrides()

for override_ in overrides:
    override.delete(override_)
オーバーライドの削除は、overrideモジュールのdeleteを使います。

オーバーライド名の取得/設定

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')
overrides = collect.getOverrides()

for override_ in overrides:
    # 名前の取得
    print override_.name()
    
    # 名前の設定
    print override_.name('Override_' + override_.name())

オーバーライドの有効/無効

rs = renderSetup.instance()
layer = rs.getRenderLayer('renderSetupLayer1')
collect = layer.getCollectionByName('collection1')
overrides = collect.getOverrides()
for override_ in overrides:
    # 有効/無効の取得
    print override_.isSelfEnabled()
    
    # 有効/無効の設定
    override_.setSelfEnabled(False)