Edição de pilha de camadas

O módulo layerstack permite a inserção e a exclusão de camadas e efeitos.

Exemplo

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())

Inserção

A inserção de uma camada ou efeito pode ser feita usando uma das seguintes funções. Para obter mais detalhes, consulte Camadas e efeitos.

class substance_painter.layerstack.InsertPosition(node_id: int, node_stack: int | Nenhum) substance_painter.layerstack.InsertPosition

InsertPosition é o objeto usado por todos os métodos de inserção para expressar onde você deseja que a inserção ocorra na hierarquia de pilha de camadas.

Crie ocorrências usando os métodos estáticos apropriados, dependendo do que você deseja fazer. Consulte os exemplos a seguir.

Exemplo

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)

Parâmetros:

  • nó_id (int)
  • nó_pilha (int | Nenhum)

static from_textureset_stack(stack: Stack) -> InsertPosition substance_painter.layerstack.InsertPosition.from_textureset_stack

Gerar um InsertPosition no topo de uma pilha.

Somente um LayerNode pode ser inserido na parte superior da pilha. Para obter mais detalhes, consulte Regras de inserção quando o nó é um LayerNode.

Pilha de parâmetros: pilha na qual você deseja inserir.

Parâmetros: pilha (Pilha)

Tipo de retorno: InsertPosition

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

Gere um InsertPosition para inserir acima do nó especificado.

Somente um LayerNode pode ser inserido acima de um LayerNode. Somente um EffectNode pode ser inserido acima de um EffectNode. Para obter mais detalhes, consulte Regras de inserção quando o nó é um LayerNode e Regras de inserção quando o nó é um EffectNode.

Parâmetros: nó (Nó) - o nó.

Tipo de retorno: InsertPosition

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

Gere um InsertPosition para inserir abaixo do nó especificado.

Somente um LayerNode pode ser inserido acima de um LayerNode. Somente um EffectNode pode ser inserido acima de um EffectNode. Para obter mais detalhes, consulte Regras de inserção quando o nó é um LayerNode e Regras de inserção quando o nó é um EffectNode.

Parâmetros: nó (Nó) - o nó.

Tipo de retorno: InsertPosition

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

Gerar um InsertPosition para inserir dentro da pilha especificada de um nó.

Somente um LayerNode poderá ser inserido dentro de um GroupLayerNode se o nó_stack for NodeStack.Substack. Somente um EffectNode poderá ser inserido dentro de um LayerNode se o nó_stack for NodeStack.Content ou NodeStack.Mask. Para obter mais detalhes, consulte Regras de inserção quando o nó é um LayerNode e Regras de inserção quando o nó é um EffectNode.

Parâmetros:

  • nó (Nó) - o nó.
  • node_stack (NodeStack) - indique em qual pilha da camada você deseja inserir (Válido apenas para nós que são camadas).

Tipo de retorno: InsertPosition

Regras de inserção quando o nó é um LayerNode

Tipo de nó
Da pilha de textureset Acima do nó Abaixo do nó Interno (Subpilha)
Nó interno (Conteúdo)
Nó interno (Máscara)
Pintar
x
x
x
Preenchimento
x
x
x
Generator
x
x
Filtro
x
x
Níveis
x
x
Comparar máscara
x
Seleção de cor
x
Grupo
x
Ponto de ancoragem
x
x
Máscara inteligente
x
Material inteligente
x
Instância
x

Regras de inserção quando o nó é um EffectNode

Tipo de nó
Da pilha de textureset no nó interno
Nó na pilha de conteúdo: acima do nó Abaixo do nó
Nó na pilha de máscaras: acima do nó Abaixo do nó
Pintar
x
x
Preenchimento
x
x
Generator
x
x
Filtro
x
x
Níveis
x
x
Comparar máscara
x
Seleção de cor
x
Grupo
Ponto de ancoragem
x
x
Máscara inteligente
x
Material inteligente
Instância

classe substance_painter.layerstack.ScopedModification(nome) substance_painter.layerstack.ScopedModification

ScopedModification pode ser usado para agrupar muitas chamadas de modificação de pilha de camadas em um único comando desabilitável.

nome será exibido no histórico do software.

Esse objeto é útil para:

  • Evite poluir o histórico agrupando logicamente modificações de pilha de camadas atrás de um nome exclusivo.
  • A computação só acontecerá quando deixarmos a declaração with, o que significa que não perdemos tempo com resultados intermediários de computação que não precisamos.

Este objeto é um gerenciador de contexto utilizável com a instrução python with

Exemplo

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

Indique em qual pilha de nós você deseja inserir.

Membros:

Nome
Descrição
Substack
Inserir na subpilha de um nó (válido somente para um nó de Pasta).
Content
Inserir na pilha de conteúdo do nó.
Mask
Inserir na pilha de máscaras do nó.
NOTE
O nome usado para definir membros está disponível como uma cadeia de caracteres através do atributo .name (consulte python enum.Enum).

Exclusão

substance_painter.layerstack.delete_node(nó: Nó) substance_painter.layerstack.delete_node

Exclui o nó fornecido.

Parâmetros: nó (Nó) - Nó a ser excluído.

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