Spostamento tra i livelli
Il modulo layerstack consente di eseguire query su livelli ed effetti e sul loro contenuto.
Esempi
Cercare e selezionare un nodo specifico
# This example shows how to recursively navigate into the layerstack to search for a specific
# substance resource and select the node containing it.
import substance_painter as sp
def match_resource_name(source: sp.source.Source, resource_name: str):
if type(source) is sp.layerstack.SourceSubstance:
return source.resource_id.name == resource_name
return False
def find_node_with_substance(
node: sp.layerstack.Node, resource_name: str):
# If the node is a Group, iterate over its sub-layers
if type(node) is sp.layerstack.GroupLayerNode:
for child in node.sub_layers():
result = find_node_with_substance(child, resource_name)
if result:
return result
# If the node is a Layer, iterate over its content stack and mask stack
if isinstance(node, sp.layerstack.LayerNode):
for content_effect in node.content_effects():
result = find_node_with_substance(content_effect, resource_name)
if result:
return result
for mask_effect in node.mask_effects():
result = find_node_with_substance(mask_effect, resource_name)
if result:
return result
# Check if the node itself contains the resource
if type(node) is sp.layerstack.FillLayerNode or type(node) is sp.layerstack.FillEffectNode:
# Check if the Fill is in material mode (the source write to multiple channels)
if node.source_mode == sp.source.SourceMode.Material:
if match_resource_name(node.get_material_source(), resource_name):
return node
# Check if the Fill is in split mode (each source write to a single channel)
elif node.source_mode == sp.source.SourceMode.Split:
# Iterate over the active channels of the Fill
for channel in node.active_channels:
if match_resource_name(node.get_source(channel), resource_name):
return node
# This case happens only in the mask stack, where there is no channel
else:
source = node.get_source(None) # There is no channel in the mask stack
if match_resource_name(source, resource_name):
return node
elif (type(node) is sp.layerstack.GeneratorEffectNode
or type(node) is sp.layerstack.FilterEffectNode):
if match_resource_name(node.get_source(), resource_name):
return node
return None
def find_substance_in_layerstack(resource_name: str):
# Retrieve the list of all texture sets
texture_sets = sp.textureset.all_texture_sets()
# Iterate over all texture sets
for texture_set in texture_sets:
# Iterate over all stacks in the texture set
for stack in texture_set.all_stacks():
# Get all Layer nodes at the root of the stack
stack_root_nodes = sp.layerstack.get_root_layer_nodes(stack)
# Iterate over the layers to find the one containing the substance
for layer in stack_root_nodes:
# Check if the layer contains the substance
node = find_node_with_substance(layer, resource_name)
if node:
return node
# Open the French Restaurant Table sample
# Note: you should replace <PATH_TO_PAINTER> with the path where
# Substance 3D Painter is installed on your machine
sp.project.open("<PATH_TO_PAINTER>/resources/samples/FrenchRestaurantTable.spp")
resource_name = "fabric_linen/fabric_linen"
node = find_substance_in_layerstack(resource_name)
if node:
# Ensure the stack containing the node is active
stack = node.get_stack()
if stack != sp.textureset.get_active_stack():
sp.textureset.set_active_stack(stack)
# Select the node
sp.layerstack.set_selected_nodes([node])
Manipolazione della maschera Geometria
# This example shows how to manipulate Geometry Masks in the layerstack
import substance_painter as sp
# Open the French Restaurant Table sample
# Note: you should replace <PATH_TO_PAINTER> with the path where
# Substance 3D Painter is installed on your machine
sp.project.open("<PATH_TO_PAINTER>/resources/samples/FrenchRestaurantTable.spp")
# Select the 'Table' texture set
for textureset in sp.textureset.all_texture_sets():
if textureset.name() == "Table":
stack = textureset.get_stack()
break
sp.textureset.set_active_stack(stack)
# Get the root layers from the stack
stack_root_layers = sp.layerstack.get_root_layer_nodes(stack)
# Get the layer at the top of the stack
first_layer = stack_root_layers[0]
# Get the layer's texture set
first_layer_texture_set = first_layer.get_texture_set()
# Avoid error checking if Layer has UDIM (UV Tiles)
if first_layer_texture_set.has_uv_tiles():
# Define which UV Tile should be activated (will deactivate the other ones)
first_layer.set_geometry_mask(
sp.layerstack.GeometryMaskUVTilesParams(
inclusion_list=True,
uv_tiles=[
first_layer_texture_set.uv_tile(0, 0), # UDIM 1001
first_layer_texture_set.uv_tile(1, 0), # UDIM 1002
]
)
)
# Create a Fill Layer at the top of the stack
fill_layer_position = sp.layerstack.InsertPosition.from_textureset_stack(stack)
fill_layer = sp.layerstack.insert_fill(fill_layer_position)
plant_group_meshes = []
# Get the Fill layer's texture set
plant_group_texture_set = fill_layer.get_texture_set()
# List all meshes where name contains 'flower'
for mesh in plant_group_texture_set.all_mesh_names():
if "flower" in mesh:
plant_group_meshes.append(mesh)
# Enable Meshes into the Geometry Mask
fill_layer.set_geometry_mask(
sp.layerstack.GeometryMaskMeshParams(
inclusion_list=True,
meshes=plant_group_meshes,
)
)
# Activate Base Color (to see the result)
fill_layer.active_channels = {sp.textureset.ChannelType.BaseColor}
# Select the modified layers
sp.layerstack.set_selected_nodes([first_layer, fill_layer])
Ottieni nodi
substance_painter.layerstack.get_root_layer_node(stack: Stack) -> List[LayerNode | GroupLayerNode | PaintLayerNode | InstanceLayerNode | FillLayerNode] substance_painter.layerstack.get_root_layer_nodes
Ottieni i livelli principali di una pila, in ordine come nella Pila livelli.
Parametri: stack (stack) - Stack su query.
Generazioni: ValueError - Se lo stack non è valido.
Restituisce: i livelli principali della pila.
Tipo di valore restituito: Elenco[NodoLivello | GroupLayerNode | PaintLayerNode | InstanceLayerNode | FillLayerNode]
substance_painter.layerstack.get_node_by_uid(node_id: int) -> List[LayerNode | GroupLayerNode | PaintLayerNode | InstanceLayerNode | NodoLivelloRiempimento | GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode] substance_painter.layerstack.get_node_by_uid
Ottiene un nodo in base all’identificatore interno.
Parametri: node_id (int) - Uid del nodo.
Genera: ValueError - Se l’uid specificato non corrisponde a un nodo valido.
Restituisce: Il nodo con l’uid specificato.
Tipo di valore restituito: Elenco[NodoLivello | GroupLayerNode | PaintLayerNode | InstanceLayerNode | FillLayerNode | GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode]
Oggetti nodo
classe substance_painter.layerstack.Node(uid) substance_painter.layerstack.Node
Classe astratta per modificare le proprietà comuni di un nodo di Pila livelli. Ogni nodo è identificato da un uid del nodo.
La chiamata ai metodi di un nodo con un uid errato genera un errore Value. Ciò può verificarsi quando si installa un nodo che fornisce il suo uid manualmente o quando il nodo non fa più riferimento ai dati esistenti nella Pila livelli.
substance_painter.layerstack.get_node_by_uid(), sezione Inserimento.get_type() -> NodeType substance_painter.layerstack.Node.get_type
Controllare il tipo di nodo.
Restituisce: Il tipo di nodo.
Tipo restituito: NodeType
get_texture_set() -> TextureSet substance_painter.layerstack.Node.get_texture_set
Ottiene l’elemento TextureSet a cui appartiene il nodo.
Restituisce: l’elemento TextureSet a cui appartiene il nodo.
Tipo restituito: TextureSet
is_visible() -> bool substance_painter.layerstack.Node.is_visible
Verificare se il rendering del nodo è stato eseguito.
Restituisce: Indica se il nodo è sottoposto a rendering.
Tipo restituito: bool
set_visible(visible: bool) substance_painter.layerstack.Node.set_visible
Abilita questo nodo per il rendering.
Parametri: visible (bool): se abilitare il nodo per il rendering.
get_name() -> str substance_painter.layerstack.Node.get_name
Ottiene il nome assegnato a questo nodo.
Restituisce: Il nome del nodo.
Tipo restituito: str
set_name(name: str) substance_painter.layerstack.Node.set_name
Modificare il nome del nodo.
Parametri: name (str) - Nuovo nome da utilizzare.
is_in_mask_stack() -> bool substance_painter.layerstack.Node.is_in_mask_stack
Verificare se il nodo fa parte di una serie di maschere.
Restituisce: Se il nodo fa parte di una serie di maschere.
Tipo restituito: bool
has_blending() -> bool substance_painter.layerstack.Node.has_blending
Verificare se questo nodo supporta le informazioni di fusione (metodo di fusione + opacità). La fusione può essere per tipo di canale per i nodi regolari o monocanale per i nodi all’interno di una serie di maschere.
Restituisce: Indica se questo nodo supporta le informazioni di fusione.
Tipo restituito: bool
is_in_mask_stack(), Documentazione sui metodi di fusioneget_blending_mode(canale: ChannelType | Nessuno = Nessuno) -> BlendingMode substance_painter.layerstack.Node.get_blending_mode
Ottieni il metodo di fusione per un nodo. Se il nodo non si trova in una pila di maschere, è necessario specificare un tipo di canale. Se il nodo si trova in una pila di maschere, Tipo canale deve essere Nessuno.
Parametri: canale (ChannelType | Nessuno) - Tipo di canale da interrogare o Nessuno per i nodi maschera.
Generazioni:
Errore valore - Se il nodo dispone di informazioni di fusione per tipo di canale e non viene fornito alcun tipo di canale, oppure se il nodo dispone di informazioni di fusione senza tipo di canale e viene fornito un tipo di canale.
Restituisce: Metodo di fusione del nodo per il tipo di canale specificato o per la maschera.
Tipo restituito: BlendingMode
set_blending_mode(blending_mode: BlendingMode, channel: ChannelType | Nessuno = Nessuno) substance_painter.layerstack.Node.set_blending_mode
Imposta il metodo di fusione per un nodo. Se il nodo non si trova in una pila di maschere, è necessario specificare un tipo di canale. Se il nodo si trova in una pila di maschere, Tipo canale deve essere Nessuno.
Parametri:
- metodo fusione_mode (Metodo fusione) - Nuovo metodo fusione da applicare.
- canale (ChannelType | Nessuno) - Tipo di canale da aggiornare o Nessuno per i nodi maschera.
Generazioni:
Errore valore - Se il nodo dispone di informazioni di fusione per tipo di canale e non viene fornito alcun tipo di canale, oppure se il nodo dispone di informazioni di fusione senza tipo di canale e viene fornito un tipo di canale.
get_opacity(canale: ChannelType | Nessuno = Nessuno) -> a virgola mobile substance_painter.layerstack.Node.get_opacity
Ottiene l’opacità per un nodo. Se il nodo non si trova in una pila di maschere, è necessario specificare un tipo di canale. Se il nodo si trova in una pila di maschere, Tipo canale deve essere Nessuno.
Parametri: canale (ChannelType | Nessuno) - Tipo di canale da interrogare o Nessuno per i nodi maschera.
Generazioni:
Errore valore - Se il nodo dispone di informazioni di fusione per tipo di canale e non viene fornito alcun tipo di canale, oppure se il nodo dispone di informazioni di fusione senza tipo di canale e viene fornito un tipo di canale.
Restituisce: l’opacità del nodo per il tipo di canale specificato o per la maschera.
Tipo restituito: float
is_in_mask_stack() has_blending()set_opacity(opacità: float, canale: ChannelType | Nessuno = Nessuno) substance_painter.layerstack.Node.set_opacity
Impostare l’opacità per un nodo. Se il nodo non si trova in una pila di maschere, è necessario specificare un tipo di canale. Se il nodo si trova in una pila di maschere, Tipo canale deve essere Nessuno.
Parametri:
- opacità (float) - Nuova opacità da applicare, valore compreso tra 0,0 e 1,0.
- canale (ChannelType | Nessuno) - Tipo di canale da aggiornare o Nessuno per i nodi maschera.
Generazioni:
Errore valore - Se il nodo dispone di informazioni di fusione per tipo di canale e non viene fornito alcun tipo di canale, oppure se il nodo dispone di informazioni di fusione senza tipo di canale e viene fornito un tipo di canale.
is_in_mask_stack() has_blending()get_stack() -> Stack substance_painter.layerstack.Node.get_stack
Ottiene lo stack che contiene il nodo.
Restituisce: Lo stack che contiene questo nodo.
Tipo restituito: Stack
get_parent() -> Nodo substance_painter.layerstack.Node.get_parent
Ottiene l’elemento padre di questo nodo.
Restituisce: l’elemento padre di questo nodo o Nessuno se questo nodo è un livello radice.
Tipo restituito: Nodo
get_next_sibling() -> Nodo substance_painter.layerstack.Node.get_next_sibling
Ottiene il nodo di pari livello successivo.
Restituisce: il nodo di pari livello successivo di questo nodo oppure Nessuno se questo nodo è il primo di pari livello.
Tipo restituito: Nodo
get_PREVIOUS_sibling() -> Nodo substance_painter.layerstack.Node.get_previous_sibling
Ottiene il nodo di pari livello precedente del nodo.
Restituisce: il nodo di pari livello precedente di questo nodo o Nessuno se questo nodo è l’ultimo di pari livello.
Tipo restituito: Nodo
uid() -> int substance_painter.layerstack.Node.uid
Ottiene l’uid interno dell’oggetto.
Restituisce: L’identificatore interno dell’oggetto come numero intero.
Tipo restituito: int
classe substance_painter.layerstack.LayerNode(uid) substance_painter.layerstack.LayerNode
Basi: Node
Nodo che fa parte della gerarchia principale. Ogni livello, ad esempio un livello pittura o di riempimento, così come i gruppi, sono organizzati in questa gerarchia. È quindi possibile eseguire query sui livelli secondari, nel caso in cui Nodo livello sia un gruppo, ma anche associare effetti di contenuto ed effetti maschera, ad esempio livelli, filtri e così via.
substance_painter.layerstack.get_node_by_uid(), sezione Inserimento.content_effects() -> Elenco[GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode] substance_painter.layerstack.LayerNode.content_effects
Eseguire una query degli effetti contenuto di questo nodo, in ordine come nella Pila livelli.
Restituisce: gli effetti contenuto di questo nodo.
Tipo di valore restituito: Elenco[GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode]
mask_effects() -> List[GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode] substance_painter.layerstack.LayerNode.mask_effects
Eseguire una query sugli effetti maschera di questo nodo, in ordine come nella Pila livelli.
Restituisce: gli effetti maschera del nodo.
Tipo di valore restituito: Elenco[GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode]
instance() -> List[LayerNode] substance_painter.layerstack.LayerNode.instances
Restituisce l’elenco delle istanze di questo livello. Se non hai dimestichezza con il concetto, consulta la documentazione su istanza dei livelli: documentazione su Istanze del livello.
Restituisce: le istanze di questo nodo.
Tipo restituito: Elenco[NodoLivello]
get_geometry_mask_type() -> GeometryMaskType substance_painter.layerstack.LayerNode.get_geometry_mask_type
Eseguire la query del tipo di maschera della geometria attualmente applicato al nodo.
Restituisce: Il tipo di maschera di geometria per questo nodo di livello.
Tipo restituito: GeometryMaskType
set_geometry_mask_type(geometry_mask_type: GeometryMaskType) substance_painter.layerstack.LayerNode.set_geometry_mask_type
Impostare il tipo di maschera della geometria da applicare al nodo. GeometryMaskType.UVTile è supportato solo quando il set di texture corrispondente utilizza Porzioni UV.
Parametri: geometry_mask_type (GeometryMaskType): il tipo di maschera di geometria per questo nodo di livello.
Generazioni:
Errore valore - Quando GeometryMaskType.UVTile è richiesto e il progetto non supporta Porzioni UV.
substance_painter.layerstack.LayerNode.set_geometry_mask().get_geometry_mask_enabled_meshes() -> Elenco[str] substance_painter.layerstack.LayerNode.get_geometry_mask_enabled_meshes
Visualizza l’elenco delle trame abilitate per la maschera di geometria. Le trame non presenti in questo elenco sono disattivate. Per ottenere l’elenco completo delle trame, vedere substance_painter.textureset.TextureSet.all_mesh_names().
Restituisce: l’elenco delle trame abilitate per la maschera della geometria.
Tipo restituito: Elenco[ str]
set_geometry_mask_enabled_meshes(nomi_mesh: List[str]) substance_painter.layerstack.LayerNode.set_geometry_mask_enabled_meshes
Impostate l’elenco delle trame abilitate per la maschera di geometria. Le trame non presenti in questo elenco verranno disattivate. Per ottenere l’elenco completo delle trame, vedere substance_painter.textureset.TextureSet.all_mesh_names().
Parametri: mesh_names (List [ str*]*) - Elenco di trame da abilitare per la maschera della geometria.
Generazioni: Errore valore - Se un nome di trama non appartiene ad alcun set di texture nel progetto.
substance_painter.layerstack.LayerNode.set_geometry_mask().get_geometry_mask_enabled_uv_tiles() -> Elenco[UVTile] substance_painter.layerstack.LayerNode.get_geometry_mask_enabled_uv_tiles
Visualizza l’elenco delle Porzioni UV abilitate per la maschera di geometria. Le porzioni UV non incluse in questo elenco sono disattivate. Per ottenere l’elenco completo delle Porzioni UV, vedere substance_painter.textureset.TextureSet.all_uv_tiles().
Restituisce: l’elenco delle Porzioni UV abilitate per la maschera della geometria.
Tipo di valore restituito: Elenco[UVTile]
set_geometry_mask_enabled_uv_tiles(uv_tiles: List[UVTile]) substance_painter.layerstack.LayerNode.set_geometry_mask_enabled_uv_tiles
Impostate l’elenco delle Porzioni UV abilitate per la maschera di geometria. Le porzioni UV non presenti in questo elenco verranno disabilitate. Per ottenere l’elenco completo delle Porzioni UV, vedere substance_painter.textureset.TextureSet.all_uv_tiles().
Parametri: uv_tiles (Elenco*[*UVTile *]*) - Elenco di Porzioni UV da abilitare per la maschera di geometria.
Generazioni: Errore valore - Se una Porzione UV non appartiene a questo set di texture.
substance_painter.layerstack.LayerNode.set_geometry_mask().get_geometry_mask() -> GeometryMaskMeshParams | GeometryMaskUVTilesParams substance_painter.layerstack.LayerNode.get_geometry_mask
Ottenete le impostazioni correnti della maschera di geometria.
Restituisce: parametri della maschera Geometria, inclusi tipo, modalità elenco ed elementi elencati.
Tipo di valore restituito: GeometryMaskMeshParams | GeometryMaskUVTilesParams
set_geometry_mask(params: GeometryMaskMeshParams | GeometryMaskUVTilesParams) substance_painter.layerstack.LayerNode.set_geometry_mask
Impostate le impostazioni della maschera di geometria.
Parametri: param (GeometryMaskMeshParams | GeometryMaskUVTilesParams) - Parametri della maschera Geometria.
Generazioni: ValueError - Se i parametri non sono coerenti o contengono elementi non validi.
has_mask() -> bool substance_painter.layerstack.LayerNode.has_mask
Verificare se il nodo dispone di una maschera.
Restituisce: Indica se il nodo dispone di una maschera.
Tipo restituito: bool
add_mask(background: MaskBackground) substance_painter.layerstack.LayerNode.add_mask
Aggiungi una maschera a questo nodo con lo sfondo specificato.
Generazioni:
Errore valore - Se una maschera è già impostata su questo nodo. Utilizzare has_mask() per verificare se il nodo dispone di una maschera.
Parametri: sfondo (MaskBackground)
remove_mask() substance_painter.layerstack.LayerNode.remove_mask
Rimuovi la maschera del nodo, inclusi tutti i suoi effetti.
Generazioni:
Errore valore - Se non esiste alcuna maschera in questo nodo. Utilizzare has_mask() per verificare se il nodo dispone di una maschera.
get_mask_background() -> MaskBackground substance_painter.layerstack.LayerNode.get_mask_background
Eseguire una query sul tipo di maschera utilizzato dal nodo.
Generazioni:
Errore valore - Se non esiste alcuna maschera in questo nodo. Utilizzare has_mask() per verificare se il nodo dispone di una maschera.
Restituisce: Lo sfondo della maschera applicato a questo nodo.
Tipo restituito: MaskBackground
set_mask_background(sfondo: MaskBackground) substance_painter.layerstack.LayerNode.set_mask_background
Imposta lo sfondo della maschera su questo nodo.
Parametri: sfondo (MaskBackground) - Sfondo maschera da applicare alla maschera nodo.
Generazioni:
Errore valore - Se non esiste alcuna maschera in questo nodo. Utilizzare has_mask() per verificare se il nodo dispone di una maschera.
is_mask_enabled() -> bool substance_painter.layerstack.LayerNode.is_mask_enabled
Consente di stabilire se la maschera è attualmente abilitata.
Generazioni:
Errore valore - Se non esiste alcuna maschera in questo nodo. Utilizzare has_mask() per verificare se il nodo dispone di una maschera.
Restituisce: se la maschera è attualmente abilitata.
Tipo restituito: bool
enable_mask(enabled: bool) substance_painter.layerstack.LayerNode.enable_mask
Consente di impostare se la maschera è attualmente attivata.
Parametri: enabled (bool) - Indica se abilitare la maschera.
Generazioni:
Errore valore - Se non esiste alcuna maschera in questo nodo. Utilizzare has_mask() per verificare se il nodo dispone di una maschera.
substance_painter.layerstack.HierarchicalNode substance_painter.layerstack.HierarchicalNode
alias di LayerNode | GroupLayerNode | PaintLayerNode | InstanceLayerNode | FillLayerNode
substance_painter.layerstack.EffectNode substance_painter.layerstack.EffectNode
alias di GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode
Enums
class substance_painter.layerstack.NodeType(value) substance_painter.layerstack.NodeType
Per ulteriori informazioni su livelli ed effetti, consultate Livelli ed effetti.
Membri:
PaintLayerPaintEffectFillLayerFillEffectGeneratorEffectFilterEffectLevelsEffectCompareMaskEffectColorSelectionEffectGroupLayerInstanceLayerAnchorPointEffectclasse substance_painter.layerstack.MaskBackground(value) substance_painter.layerstack.MaskBackground
Membri:
BlackWhiteclass substance_painter.layerstack.BlendingMode(value) substance_painter.layerstack.BlendingMode
I metodi di fusione consentono di miscelare il risultato di un livello con gli altri livelli sottostanti in modi diversi. Per ulteriori informazioni, consulta la documentazione sui metodi di fusione.
Membri:
NormalPassThroughDisableReplaceMultiplyDivideInverseDivideDarkenLightenLinearDodgeSubtractInverseSubtractDifferenceExclusionSignedAdditionOverlayScreenLinearBurnColorBurnColorDodgeSoftLightHardLightVividLightLinearLightPinLightTintSaturationColorValueNormalMapCombineNormalMapDetailNormalMapInverseDetailclasse substance_painter.layerstack.GeometryMaskType(value) substance_painter.layerstack.GeometryMaskType
Membri:
MeshUVTile