Layerstack 版本

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_stack: int |無) substance_painter.layerstack.InsertPosition

InsertPosition 是所有插入方法用來表達你希望插入在層堆疊階層中發生的位置的物件。

根據你想做的事,使用適當的靜態方法建立實例。 請參考以下範例。

範例

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)
  • 節點_stack (int | 無)

靜態from_textureset_stack(堆疊:堆疊)-> 插入位置 substance_painter.layerstack.InsertPosition.from_textureset_stack

在一個檔案堆頂產生一個 InsertPosition 。

只能將 a LayerNode 插入堆疊頂端。 更多細節請參見 節點為層節點時的插入規則。

平行堆疊: 你想插入的疊疊。

參數:​堆疊(堆疊)

回傳類型:​InsertPosition

靜態above_node(節點:節點)-> 插入位置 substance_painter.layerstack.InsertPosition.above_node

在給定節點上方產生 InsertPosition 插入 。

只有 a LayerNode 可以入 。LayerNode只有 可以在 EffectNode 上方插入 EffectNode。 更多細節請參見 「當節點是 LayerNode 時的插入規則」以及 「當節點是 EffectNode 時的插入規則」。

參數:​ node ​(Node)– 該節點。

回傳類型:​InsertPosition

靜態below_node(節點:節點)-> 插入位置 substance_painter.layerstack.InsertPosition.below_node

產生一個 InsertPosition ,插入該節點下方。

只有 a LayerNode 可以入 。LayerNode只有 可以在 EffectNode 上方插入 EffectNode。 更多細節請參見 「當節點是 LayerNode 時的插入規則」以及 「當節點是 EffectNode 時的插入規則」。

參數:​ node ​(Node)– 該節點。

回傳類型:​InsertPosition

靜態inside_node(node: Node, node_stack: NodeStack) -> InsertPosition substance_painter.layerstack.InsertPosition.inside_node

在給定的節點堆疊中產生 插入 InsertPosition 。

只有當節點為 NodeStack.Substack時,才能將 a LayerNode 插入 GroupLayerNode _stack 。只有當節點為NodeStack.Content或 NodeStack.Mask時,才能插入 LayerNode _stack EffectNode 。更多細節請參見 「當節點是 LayerNode 時的插入規則」以及 「當節點是 EffectNode 時的插入規則」。

參數:

  • 節點 (Node)-該節點。
  • node_stack​(NodeStack)– 指示你想插入哪一層的堆疊(僅適用於層節點)。

回傳類型:​InsertPosition

當節點為層節點時的插入規則

節點類型
從貼圖集堆疊 上方 節點下方 節點下方 內部節點(子堆疊)
內部節點(內容)
內部節點(遮罩)
塗料
x
x
x
填滿
x
x
x
發電機
x
x
濾鏡
x
x
關卡
x
x
比較面具
x
色彩選擇
x
群組
x
錨點
x
x
智慧口罩
x
智慧材料
x
執行個體
x

當節點是 EffectNode 時的插入規則

節點類型
來自貼圖集堆疊內部節點
內容堆疊中的節點:節點上 節點下方
遮罩堆疊中的節點:節點上 節點下方
塗料
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 可用來將多個層堆疊修改呼叫合併成一個可執行的指令。

名稱會顯示在軟體歷史紀錄中。

此物件可用於:

  • 避免將邏輯上層堆疊修改群組在唯一名稱後面,來污染歷史。
  • 只有當我們離開陳述句時 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()

class 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

刪除給定節點。

參數:​node (Node) – 節點要刪除。

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