層堆疊導航
Layerstack 模組允許查詢圖層、效果及其內容。
範例
搜尋並選擇特定節點
# 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])
幾何遮罩操作
# 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])
取得節點
substance_painter.layerstack.get_root_layer_nodes(stack: Stack) -> List[LayerNode |GroupLayerNode |PaintLayerNode |InstanceLayerNode |FillLayerNode] substance_painter.layerstack.get_root_layer_nodes
取得堆疊的根層,順序像層堆疊一樣。
參數:stack (Stack) – 從 Stack 查詢。
加注:ValueError – 如果堆疊無效。
回報: 堆疊的根層。
回傳類型: ListLayerNode *|* GroupLayerNode *|* PaintLayerNode *|* InstanceLayerNode *|* FillLayerNode *][***
substance_painter.layerstack.get_node_by_uid(node_id: int) -> List[LayerNode |GroupLayerNode |PaintLayerNode |InstanceLayerNode |FillLayerNode |GeneratorEffectNode |PaintEffectNode |FillEffectNode |LevelsEffectNode |CompareMaskEffectNode |FilterEffectNode |ColorSelectionEffectNode |AnchorPointEffectNode] substance_painter.layerstack.get_node_by_uid
透過內部識別碼取得節點。
參數:node_id (int) – 節點的 uid。
Raises: ValueError – 如果給定的 uid 不對應於有效節點。
回傳: 具有指定 uid 的節點。
回傳類型: ListLayerNode *|* GroupLayerNode *|* PaintLayerNode *|* InstanceLayerNode *|* FillLayerNode *|* GeneratorEffectNode *|* PaintEffectNode *|* FillEffectNode *|* LevelsEffectNode *|* 比較遮罩效果節點*|* FilterEffectNode *|[***ColorSelectionEffectNode | AnchorPointEffectNode]
節點物件
class substance_painter.layerstack.Node(uid) substance_painter.layerstack.Node
抽象類別用來操作層堆疊節點的常見屬性。 每個節點由節點 uid 來識別。
呼叫節點 uid 錯誤的方法會拋出 ValueError。 這可能發生在手動輸入節點提供 uid 的節點,或節點不再參考層堆疊中現有的資料時。
get_type() -> 節點類型 substance_painter.layerstack.Node.get_type
檢查節點的類型。
回報: 節點類型。
回傳類型:NodeType
get_texture_set() -> 貼圖集 substance_painter.layerstack.Node.get_texture_set
取得該節點所屬的 TextureSet。
回傳: 該節點所屬的 TextureSet。
回傳類型:TextureSet
is_visible() -> bool substance_painter.layerstack.Node.is_visible
檢查這個節點是否已被渲染。
回傳: 該節點是否被渲染。
回傳類型: bool
set_visible(可見:bool) substance_painter.layerstack.Node.set_visible
啟用此節點進行渲染。
參數:可見(bool)– 是否啟用此節點進行渲染。
get_name() -> str substance_painter.layerstack.Node.get_name
把這個節點的名稱分配給你。
回報: 節點名稱。
回傳類型: 力量
set_name(姓名:str) substance_painter.layerstack.Node.set_name
更改這個節點名稱。
參數:名稱(力量)– 新名稱。
is_in_mask_stack() -> bool substance_painter.layerstack.Node.is_in_mask_stack
檢查這個節點是否屬於遮罩堆疊。
回傳: 該節點是否屬於遮罩堆疊。
回傳類型: bool
has_blending() -> bool substance_painter.layerstack.Node.has_blending
檢查這個節點是否支援混合資訊(混合模式 + 不透明度)。 混合可能是針對一般節點的 Channel Type,或是遮罩堆疊內的節點採用單通道。
回報: 此節點是否支援資訊混合。
回傳類型: bool
is_in_mask_stack()混合模式文件get_blending_mode(通道:ChannelType |None = None) -> 混合模式 substance_painter.layerstack.Node.get_blending_mode
取得節點的混合模式。 若節點不在遮罩堆疊中,必須提供通道類型。 若節點處於遮罩堆疊中,通道類型必須為無。
參數:通道(ChannelType | 無)– 查詢通道類型或遮罩節點的無。
加薪:
ValueError – 若節點擁有各通道類型的混合資訊但未提供通道類型,或節點有混合資訊但沒有通道類型且提供通道類型。
回傳: 該節點在指定通道類型或遮罩下的混合模式。
回傳類型:BlendingMode
set_blending_mode(blending_mode:混合模式,通道:頻道類型 |無 = 無) substance_painter.layerstack.Node.set_blending_mode
設定節點的混合模式。 若節點不在遮罩堆疊中,必須提供通道類型。 若節點處於遮罩堆疊中,通道類型必須為無。
參數:
- blending_mode (BlendingMode)– 新增的混合模式。
- 通道 (通道類型 | 無)– 用於更新或遮罩節點的通道類型為 None。
加薪:
ValueError – 若節點擁有各通道類型的混合資訊但未提供通道類型,或節點有混合資訊但沒有通道類型且提供通道類型。
get_opacity(通道:ChannelType |None = None) ->浮點數 substance_painter.layerstack.Node.get_opacity
取得節點的不透明度。 若節點不在遮罩堆疊中,必須提供通道類型。 若節點處於遮罩堆疊中,通道類型必須為無。
參數:通道(ChannelType | 無)– 查詢通道類型或遮罩節點的無。
加薪:
ValueError – 若節點擁有各通道類型的混合資訊但未提供通道類型,或節點有混合資訊但沒有通道類型且提供通道類型。
回傳: 該節點在指定通道類型或遮罩下的不透明度。
回傳類型: float
set_opacity(不透明度:float,通道:ChannelType |None = None) substance_painter.layerstack.Node.set_opacity
設定節點的不透明度。 若節點不在遮罩堆疊中,必須提供通道類型。 若節點處於遮罩堆疊中,通道類型必須為無。
參數:
- 不透明度 (float)-需套用新的不透明度,值介於 0.0 到 1.0 之間。
- channel (ChannelType | None)– 用於更新的通道類型或遮罩節點的 None。
加薪:
ValueError – 若節點擁有各通道類型的混合資訊但未提供通道類型,或節點有混合資訊但沒有通道類型且提供通道類型。
get_stack() -> Stack substance_painter.layerstack.Node.get_stack
取得包含該節點的堆疊。
回傳: 包含此節點的堆疊。
回傳類型:堆疊
get_parent() -> 節點 substance_painter.layerstack.Node.get_parent
取得這個節點的父節點。
回傳: 該節點的父節點,若為根層則為 None。
回傳類型:節點
get_next_sibling() -> 節點 substance_painter.layerstack.Node.get_next_sibling
取得這個節點的下一個兄弟節點。
回傳: 該節點的下一個兄弟節點,若該節點是第一個兄弟節點則為 None。
回傳類型:節點
get_previous_sibling() -> 節點 substance_painter.layerstack.Node.get_previous_sibling
取得這個節點的前一個兄弟節點。
回傳: 該節點的前一個兄弟節點,或若該節點是最後一個兄弟節點,則為 None。
回傳類型:節點
uid() -> int substance_painter.layerstack.Node.uid
取得物件內部的 UID。
回傳: 物件的內部識別碼為整數。
回傳類型: int
class substance_painter.layerstack.LayerNode(uid) substance_painter.layerstack.LayerNode
基地: Node
一個屬於主階層結構的節點。 每個圖層,如繪畫圖層或填充圖層,以及群組,都被組織在這個階層中。 因此,你可以查詢子圖層(如果 LayerNode 是群組),也能關聯內容效果和遮罩效果(例如關卡、濾鏡等)。
content_effects() -> 列表[產生器EffectNode |PaintEffectNode |FillEffectNode |LevelsEffectNode |比較遮罩效果節點 |FilterEffectNode |ColorSelectionEffectNode |AnchorPointEffectNode] substance_painter.layerstack.LayerNode.content_effects
查詢這個節點的內容效果,順序像圖層堆疊一樣。
回報: 此節點的內容效果。
回傳類型: ListGeneratorEffectNode *|* PaintEffectNode *|* FillEffectNode *|* LevelsEffectNode *|* CompareMaskEffectNode *|* FilterEffectNode *|* ColorSelectionEffectNode *|* AnchorPointEffectNode *][***
mask_effects() -> 列表[產生器EffectNode |PaintEffectNode |FillEffectNode |LevelsEffectNode |CompareMaskEffectNode |FilterEffectNode |ColorSelectionEffectNode |AnchorPointEffectNode] substance_painter.layerstack.LayerNode.mask_effects
查詢這個節點的遮罩效果,順序跟圖層堆疊一樣。
回報: 這個節點的遮罩效果。
回傳類型: ListGeneratorEffectNode *|* PaintEffectNode *|* FillEffectNode *|* LevelsEffectNode *|* CompareMaskEffectNode *|* FilterEffectNode *|* ColorSelectionEffectNode *|* AnchorPointEffectNode *][***
instances() -> List[LayerNode] substance_painter.layerstack.LayerNode.instances
回傳此層的實例清單。 如果你不熟悉這個概念,請參閱關於層實例化的文件: Layer Instancing documentation。
回傳: 該節點的實例。
**回傳類型:**List[LayerNode]
get_geometry_mask_type() -> GeometryMaskType substance_painter.layerstack.LayerNode.get_geometry_mask_type
查詢目前套用到該節點的幾何遮罩類型。
回傳: 該圖層節點的幾何遮罩類型。
回傳類型:GeometryMaskType
set_geometry_mask_type(geometry_mask_type:GeometryMaskType) substance_painter.layerstack.LayerNode.set_geometry_mask_type
設定幾何遮罩類型套用到這個節點。 GeometryMaskType.UVTile 僅在對應的貼圖集使用 UV 圖塊時才支援。
參數:geometry_mask_type (GeometryMaskType) – 此圖層節點的幾何遮罩類型。
加薪:
ValueError – 當請求 GeometryMaskType.UVTile 且專案不支援 UV 圖塊時。
substance_painter.layerstack.LayerNode.set_geometry_mask() 。get_geometry_mask_enabled_meshes() -> 列表[力量] substance_painter.layerstack.LayerNode.get_geometry_mask_enabled_meshes
取得幾何遮罩啟用的網格清單。 不在這個清單裡的網格會被停用。 欲獲得完整的網格列表,請參見 substance_painter.textureset.TextureSet.all_mesh_names()。
返回: 幾何遮罩啟用的網格清單。
**回傳類型:**列表[ str]
set_geometry_mask_enabled_meshes(mesh_names:列表[力量]) substance_painter.layerstack.LayerNode.set_geometry_mask_enabled_meshes
設定幾何遮罩啟用的網格清單。 不在這個清單裡的網格將會被停用。 欲獲得完整的網格列表,請參見 substance_painter.textureset.TextureSet.all_mesh_names()。
參數:mesh_names (List [ str*]*) – 用於幾何遮罩的網格清單。
Raises:ValueError – 如果網格名稱不屬於專案中任何材質集。
substance_painter.layerstack.LayerNode.set_geometry_mask() 。get_geometry_mask_enabled_uv_tiles() -> 列表[UVTile] substance_painter.layerstack.LayerNode.get_geometry_mask_enabled_uv_tiles
取得幾何遮罩啟用的 UV 圖塊清單。 不在本列表中的 UV 圖塊已被禁用。 欲獲得完整的 UV 磚塊清單,請參見 substance_painter.textureset.TextureSet.all_uv_tiles()。
返回: 幾何遮罩啟用的 UV 圖塊清單。
**返回類型:**List[UVTile]
set_geometry_mask_enabled_uv_tiles(uv_tiles:列表[UVTile]) substance_painter.layerstack.LayerNode.set_geometry_mask_enabled_uv_tiles
設定幾何遮罩啟用的 UV 圖塊清單。 不在本列表中的 UV 磚塊會被關閉。 欲獲得完整的 UV 磚塊清單,請參見 substance_painter.textureset.TextureSet.all_uv_tiles()。
參數:uv_tiles (List*[*UVTile *]*) – 用於幾何遮罩啟用的 UV 磚塊清單。
Raises:ValueError – 如果 UV 圖塊不屬於此材質集。
substance_painter.layerstack.LayerNode.set_geometry_mask() 。get_geometry_mask() -> GeometryMaskMeshParams |GeometryMaskUVTilesParams substance_painter.layerstack.LayerNode.get_geometry_mask
取得幾何遮罩目前的設定。
回傳: 幾何遮罩參數,包括型別、列表模式及列出元素。
**回傳類型:**GeometryMaskMeshParams | GeometryMaskUVTilesParams
set_geometry_mask(參數:GeometryMaskMeshParams |GeometryMaskUVTilesParams) substance_painter.layerstack.LayerNode.set_geometry_mask
設定幾何遮罩設定。
參數:參數(GeometryMaskMeshParams | GeometryMaskUVTilesParams )– 幾何遮罩參數。
Raises:ValueError – 如果參數不一致或包含無效元素。
has_mask() -> bool substance_painter.layerstack.LayerNode.has_mask
檢查這個節點是否有遮罩。
回傳: 該節點是否有遮罩。
回傳類型: bool
add_mask(背景:MaskBackground) substance_painter.layerstack.LayerNode.add_mask
在這個節點上加上一個帶有指定背景的遮罩。
加薪:
ValueError – 如果該節點已經設定了遮罩。 用 has_mask() 來檢查節點是否有遮罩。
參數:背景(MaskBackground)
remove_mask() substance_painter.layerstack.LayerNode.remove_mask
移除這個節點遮罩,包括它所有的效果。
加薪:
ValueError – 如果此節點不存在遮罩。 用 has_mask() 來檢查節點是否有遮罩。
get_mask_background() -> 面具背景 substance_painter.layerstack.LayerNode.get_mask_background
查詢此節點所使用的遮罩類型。
加薪:
ValueError – 如果此節點不存在遮罩。 用 has_mask() 來檢查節點是否有遮罩。
回傳: 套用到此節點的遮罩背景。
回傳類型:MaskBackground
set_mask_background(背景:MaskBackground) substance_painter.layerstack.LayerNode.set_mask_background
在這個節點上設定遮罩背景。
參數:背景(MaskBackground)— 要套用在這個節點遮罩上的遮罩背景。
加薪:
ValueError – 如果此節點不存在遮罩。 用 has_mask() 來檢查節點是否有遮罩。
is_mask_enabled() -> bool substance_painter.layerstack.LayerNode.is_mask_enabled
查詢遮罩目前是否啟用。
加薪:
ValueError – 如果此節點不存在遮罩。 用 has_mask() 來檢查節點是否有遮罩。
回傳: 遮罩目前是否啟用。
回傳類型: bool
enable_mask(啟用:bool) substance_painter.layerstack.LayerNode.enable_mask
設定遮罩目前是否啟用。
參數:enabled (bool) – 是否啟用遮罩。
加薪:
ValueError – 如果此節點不存在遮罩。 用 has_mask() 來檢查節點是否有遮罩。
substance_painter.layerstack.HierarchicalNode substance_painter.layerstack.HierarchicalNode
別名 LayerNode | GroupLayerNode | PaintLayerNode | | InstanceLayerNode FillLayerNode
substance_painter.layerstack.EffectNode substance_painter.layerstack.EffectNode
別名 | | | | FilterEffectNode CompareMaskEffectNode LevelsEffectNode | | | ColorSelectionEffectNode FillEffectNode PaintEffectNode GeneratorEffectNode AnchorPointEffectNode
枚舉
class substance_painter.layerstack.NodeType(value) substance_painter.layerstack.NodeType
欲了解更多圖層與效果資訊,請參見 「圖層與特效」。
成員:
PaintLayerPaintEffectFillLayerFillEffectGeneratorEffectFilterEffectLevelsEffectCompareMaskEffectColorSelectionEffectGroupLayerInstanceLayerAnchorPointEffectclass substance_painter.layerstack.MaskBackground(value) substance_painter.layerstack.MaskBackground
成員:
BlackWhiteclass substance_painter.layerstack.BlendingMode(value) substance_painter.layerstack.BlendingMode
混合模式允許以不同方式將某一圖層的結果與下方其他圖層混合。 欲了解更多資訊,請參閱 混合模式文件。
成員:
NormalPassThroughDisableReplaceMultiplyDivideInverseDivideDarkenLightenLinearDodgeSubtractInverseSubtractDifferenceExclusionSignedAdditionOverlayScreenLinearBurnColorBurnColorDodgeSoftLightHardLightVividLightLinearLightPinLightTintSaturationColorValueNormalMapCombineNormalMapDetailNormalMapInverseDetailclass substance_painter.layerstack.GeometryMaskType(value) substance_painter.layerstack.GeometryMaskType
成員:
MeshUVTile