Layerstack edition

layerstackモジュールを使用すると、レイヤーおよび効果を挿入および削除できます。

例

import substance_painter as sp

# Get the currently displayed stack
stack = sp.textureset.get_active_stack()

# Get all Layer nodes at the root of the stack
stack_root_nodes = sp.layerstack.get_root_layer_nodes(stack)
# Find the layer at the very bottom
bottom_layer = stack_root_nodes[len(stack_root_nodes) - 1]

# Create the position where to insert the Group
# Get the very bottom Layer Position
position_stack_bottom = sp.layerstack.InsertPosition.below_node(bottom_layer)

# Insert the Group Layer
my_group = sp.layerstack.insert_group(position_stack_bottom)
my_group.set_name("My Group")
my_group.set_collapsed(False)

# Insert a Fill Layer into the group and assign a Material from the starter asset library
position_group_content = sp.layerstack.InsertPosition.inside_node(
    my_group, sp.layerstack.NodeStack.Substack)
# Insert Fill Layer
my_fill_layer = sp.layerstack.insert_fill(position_group_content)
my_fill_layer.set_name("My Fill Layer")
# Search and isolate a Substance material
fill_layer_resource = sp.resource.search("s:starterassets "
                                         "u:substance "
                                         "n:Paper\\ Grainy=")[0]
# Apply material from the library Substance ID in the Fill Layer
my_fill_layer.set_material_source(fill_layer_resource.identifier())

# Insert Fill effect into the "my_fill_layer"'s effect stack
position_effect_stack = sp.layerstack.InsertPosition.inside_node(
    my_fill_layer, sp.layerstack.NodeStack.Content)

my_fill_effect = sp.layerstack.insert_fill(position_effect_stack)
my_fill_effect.set_name("My Fill Effect")

# Insert Fill effect into the "my_fill_layer"'s mask effects stack
if not my_fill_layer.has_mask():  # If Layer has no Mask, create it
    mask_background = sp.layerstack.MaskBackground.White  # Create Background Color for the mask
    my_fill_layer.add_mask(mask_background)  # Add a mask to the Fill Layer
position_mask_effect_stack = sp.layerstack.InsertPosition.inside_node(
    my_fill_layer, sp.layerstack.NodeStack.Mask)

my_mask_fill_effect = sp.layerstack.insert_fill(position_mask_effect_stack)
my_mask_fill_effect.set_name("My Mask Fill Effect")

# We can notice, in the lines above, that the same 'insert_fill()' method
# is called to create either a Fill Layer, a Fill Effect or a mask fill effect.
# Paint Layers insertion will work the same using 'insert_paint()'

# Insert a Blur Filter Effect in "my_fill_layer" stack
filter_resource = sp.resource.search("s:starterassets "
                                     "u:filter "
                                     "n:Blur=")[0]
sp.layerstack.insert_filter_effect(position_effect_stack, filter_resource.identifier())

# Insert a Smart Material from the library into "My Group"
# Get the first Smart Material named 'Bronze Armor' in the starter asset library
smart_mat_resource = sp.resource.search("s:starterassets "
                                        "u:smartmaterial "
                                        "n:Bronze\\ Armor=")[0]
# Insert smart material in the group and connect a resource found into the library
sp.layerstack.insert_smart_material(position_group_content, smart_mat_resource.identifier())

挿入

レイヤーまたはエフェクトの挿入は、次のいずれかの機能を使用して行うことができます。 詳しくは、レイヤーとエフェクトを参照してください。

substance_painter.layerstack.InsertPosition(node_id: int, node_スタック: int |なし) substance_painter.layerstack.InsertPosition

InsertPositionは、レイヤースタック階層内で挿入を行う場所を示すためにすべてのinsertメソッドで使用されるオブジェクトです。

目的に応じて、適切な静的メソッドを使用してインスタンスを作成します。 次の例を参照してください。

例

import substance_painter as sp

# Insert at the top of the given textureset layer stack
insert_position = sp.layerstack.InsertPosition.from_textureset_stack(
    sp.textureset.get_active_stack())
new_layer = sp.layerstack.insert_fill(insert_position)
new_layer.set_name("First layer")

# Insert a layer above new_layer
insert_position = sp.layerstack.InsertPosition.above_node(new_layer)
sp.layerstack.insert_fill(insert_position)

# Insert an effect in the content stack of new_layer
insert_position = sp.layerstack.InsertPosition.inside_node(
    new_layer, sp.layerstack.NodeStack.Content)
new_effect = sp.layerstack.insert_fill(insert_position)
new_effect.set_name("First effect")

# Insert an effect below new_effect
insert_position = sp.layerstack.InsertPosition.below_node(new_effect)
sp.layerstack.insert_fill(insert_position)

パラメーター:

  • node_id (int)
  • node_スタック (int | なし)

static from_textureset_スタック(スタック:スタック) -> InsertPosition substance_painter.layerstack.InsertPosition.from_textureset_stack

スタックの上部にInsertPositionを生成します。

スタックの上部に挿入できるのはLayerNodeのみです。 詳細については、ノードがLayerNodeの場合の挿入ルールを参照してください。

挿入するPararm スタック: スタック。

パラメーター: スタック (スタック)

戻り値の型: InsertPosition

static above_node(node: Node) -> InsertPosition substance_painter.layerstack.InsertPosition.above_node

指定されたノードの上に挿入するInsertPositionを生成します。

LayerNodeの上に挿入できるのはLayerNodeのみです。 EffectNodeの上に挿入できるのはEffectNodeのみです。 詳細については、ノードがLayerNodeの場合の挿入ルールおよびノードがEffectNodeの場合の挿入ルールを参照してください。

パラメーター: ノード (ノード) – ノード。

戻り値の型: InsertPosition

static below_node(node: Node) -> InsertPosition substance_painter.layerstack.InsertPosition.below_node

指定されたノードの下に挿入するInsertPositionを生成します。

LayerNodeの上に挿入できるのはLayerNodeのみです。 EffectNodeの上に挿入できるのはEffectNodeのみです。 詳細については、ノードがLayerNodeの場合の挿入ルールおよびノードがEffectNodeの場合の挿入ルールを参照してください。

パラメーター: ノード (ノード) – ノード。

戻り値の型: InsertPosition

static inside_node(node: Node, node_node: NodeStack) -> InsertPosition substance_painter.layerstack.InsertPosition.inside_node

指定されたノードのスタック内に挿入するInsertPositionを生成します。

node_nodeがNodeStack.Substackの場合、GroupLayerNodeの内部にはLayerNodeしかスタックできません。 node_nodeがNodeStack.ContentまたはNodeStack.Maskの場合、LayerNode内にはEffectNodeしかスタックできません。 詳細については、ノードがLayerNodeの場合の挿入ルールおよびノードがEffectNodeの場合の挿入ルールを参照してください。

パラメーター:

  • ノード (ノード) – ノード。
  • node_node (NodeStack) – 挿入するレイヤーのスタックを指定します(レイヤーであるスタックに対してのみ有効)。

戻り値の型: InsertPosition

ノードがLayerNodeの場合の挿入規則

ノードタイプ
From textureset node Above node Below node Inside node (Substack)
内部ノード(コンテンツ)
内部ノード(マスク)
ペイント
X
X
X
塗りつぶし
X
X
X
ジェネレーター
X
X
フィルター
X
X
レベル
X
X
比較マスク
X
カラー選択
X
グループ
X
アンカーポイント
X
X
スマートマスク
X
スマートマテリアル
X
インスタンス
X

ノードがEffectNodeの場合の挿入規則

ノードタイプ
From textureset スタック Insideノード
コンテンツスタックのノード:ノードの上ノードノードの下
Node in Mask スタック: Above node Below node
ペイント
X
X
塗りつぶし
X
X
ジェネレーター
X
X
フィルター
X
X
レベル
X
X
比較マスク
X
カラー選択
X
グループ
アンカーポイント
X
X
スマートマスク
X
スマートマテリアル
インスタンス

class substance_painter.layerstack.ScopedModification(name) substance_painter.layerstack.ScopedModification

ScopedModificationを使用すると、1つの取り消し可能なコマンドで多数のレイヤースタック変更呼び出しをグループ化できます。

ソフトウェア履歴に名前が表示されます。

このオブジェクトは、次の場合に便利です。

  • 固有の名前の後ろに論理的にレイヤースタックの変更をグループ化して、履歴をポーリングしないようにします。
  • この計算が発生するのは、withステートメントが終了した場合だけです。このステートメントは、必要のない中間結果を計算するために時間を無駄にしないことを意味します。

このオブジェクトは、python withステートメントで使用できるコンテキストマネージャーです

例

import substance_painter as sp

def insert_many_fills():
    # Insert many layers inside the current texture set layer stack
    # and set their projection mode to tri-planar
    insert_position = sp.layerstack.InsertPosition.from_textureset_stack(
        sp.textureset.get_active_stack())
    fill = sp.layerstack.insert_fill(insert_position)
    fill.set_projection_mode(sp.layerstack.ProjectionMode.Triplanar)
    fill = sp.layerstack.insert_fill(insert_position)
    fill.set_projection_mode(sp.layerstack.ProjectionMode.Triplanar)
    fill = sp.layerstack.insert_fill(insert_position)
    fill.set_projection_mode(sp.layerstack.ProjectionMode.Triplanar)

# Calling this method will generate many history entries (1 for each
# inserted fill and 1 for each projection mode update) and
# Substance Painter will compute the textures each time a modification
# happens.
#
# Expected history:
#   * Add fill
#   * Update projection mode
#   * Add fill
#   * Update projection mode
#   * Add fill
#   * Update projection mode
#
# Potential texture update in the viewport: 6 (one for each modification)
insert_many_fills()

# With the ScopedModification below, only one entry will be added to Painter
# history. A single undo will remove all the fill inserted inside the

# Calling this method inside a ScopedModification will only generate one history
# entry and Substance Painter will compute the textures only once.
#
# Expected history:
#   * Insert many layers
#
# Potential texture update in the viewport: 1
with sp.layerstack.ScopedModification("Insert many layers"):
    insert_many_fills()

substance_painter.layerstack.NodeStack(value)クラス substance_painter.layerstack.NodeStack

挿入するノードスタックを指定します。

メンバー:

名前
説明
Substack
ノードのサブスタックに挿入します(フォルダノードでのみ有効)。
Content
ノードのコンテンツスタックに挿入します。
Mask
ノードのマスクスタックに挿入します。
NOTE
メンバーの定義に使用される名前は、.name属性を使用して文字列として使用できます(python enum.Enumを参照)。

削除

substance_painter.layerstack.delete_node(node: Node) substance_painter.layerstack.delete_node

指定されたノードを削除します。

パラメーター: ノード (ノード) – 削除するノード。

recommendation-more-help
substance-3d-dev-help-painter-python-guide