图层栈栈导航
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(堆叠:堆叠) -> List[LayerNode | GroupLayerNode | PaintLayerNode | InstanceLayerNode | FillLayerNode] substance_painter.layerstack.get_root_layer_nodes
获取堆叠的根图层,按图层堆叠中的顺序排列。
参数: 堆叠 (堆叠) — 查询堆叠。
引发: ValueError — 如果堆叠无效。
返回:堆叠的根层。
返回类型: 列表[LayerNode | 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。
引发: ValueError — 如果给定的uid没有对应于有效的节点。
返回:具有给定uid的节点。
返回类型: 列表[LayerNode | GroupLayerNode | PaintLayerNode | InstanceLayerNode | FillLayerNode | GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode]
节点对象
类substance_painter.layerstack.Node(uid) substance_painter.layerstack.Node
用于处理图层堆叠节点公共属性的抽象类。 每个节点由节点UID标识。
调用具有不正确UID的Node的方法会引发ValueError。 当手动实例化提供其uid的Node时,或者当Node不再引用图层堆叠中的现有数据时,可能会发生这种情况。
get_type() -> NodeType substance_painter.layerstack.Node.get_type
检查节点的类型。
返回:节点类型。
返回类型: NodeType
get_texture_set() -> TextureSet substance_painter.layerstack.Node.get_texture_set
获取此节点所属的TextureSet。
返回:此节点所属的TextureSet。
返回类型: TextureSet
is_visible() -> bool substance_painter.layerstack.Node.is_visible
检查此节点是否呈现。
返回:是否呈现此节点。
返回类型: bool
set_visible(visible: bool) substance_painter.layerstack.Node.set_visible
启用此节点以进行渲染。
参数: 可见 (bool) — 是否启用此节点以进行渲染。
get_name() -> str substance_painter.layerstack.Node.get_name
获取分配给此节点的名称。
返回:节点名称。
返回类型: str
set_name(名称:str) substance_painter.layerstack.Node.set_name
更改此节点名称。
参数: 名称 (str) — 要使用的新名称。
is_in_mask_堆叠() -> bool substance_painter.layerstack.Node.is_in_mask_stack
检查此节点是否为蒙版堆叠的一部分。
返回:此节点是否为掩码堆叠的一部分。
返回类型: bool
has_blending() -> bool substance_painter.layerstack.Node.has_blending
检查此节点是否支持混合信息(混合模式+不透明度)。 混合可以是针对常规节点的每通道类型,也可以是针对蒙版堆叠内节点的单通道。
返回:此节点是否支持混合信息。
返回类型: bool
is_in_mask_stack(),混合模式文档get_blending_mode(channel: ChannelType |无=无) ->混合模式 substance_painter.layerstack.Node.get_blending_mode
获取节点的混合模式。 如果节点不在掩码堆叠中,则必须提供“Channel Type”(通道类型)。 如果节点在蒙版堆叠中,则“通道类型”必须为“无”。
参数: 通道 (通道类型 | 无) — 要查询的通道类型或掩码节点为“无”。
引发:
ValueError — 如果节点具有每个通道类型的混合信息但未提供通道类型,或者节点具有没有通道类型和通道类型的混合信息。
返回:此节点对于给定通道类型或掩码的混合模式。
返回类型: 混合模式
set_blending_mode(blending_mode: BlendingMode,通道: ChannelType |无=无) substance_painter.layerstack.Node.set_blending_mode
设置节点的混合模式。 如果节点不在掩码堆叠中,则必须提供“Channel Type”(通道类型)。 如果节点在蒙版堆叠中,则“通道类型”必须为“无”。
参数:
- 混合_mode (混合模式) — 要应用的新混合模式。
- 通道 (ChannelType | 无) — 要更新的通道类型或蒙版节点为“无”。
引发:
ValueError — 如果节点具有每个通道类型的混合信息但未提供通道类型,或者节点具有没有通道类型和通道类型的混合信息。
get_opacity(channel: ChannelType |无=无) ->浮动 substance_painter.layerstack.Node.get_opacity
获取节点的不透明度。 如果节点不在掩码堆叠中,则必须提供“Channel Type”(通道类型)。 如果节点在蒙版堆叠中,则“通道类型”必须为“无”。
参数: 通道 (通道类型 | 无) — 要查询的通道类型或掩码节点为“无”。
引发:
ValueError — 如果节点具有每个通道类型的混合信息但未提供通道类型,或者节点具有没有通道类型和通道类型的混合信息。
返回:此节点对于给定通道类型或掩码的不透明度。
返回类型:浮动
set_opacity(不透明度:浮点,通道:通道类型 |无=无) substance_painter.layerstack.Node.set_opacity
设置节点的不透明度。 如果节点不在掩码堆叠中,则必须提供“Channel Type”(通道类型)。 如果节点在蒙版堆叠中,则“通道类型”必须为“无”。
参数:
- 不透明度 (浮动) — 要应用的新不透明度,值介于0.0和1.0之间。
- 通道 (ChannelType | 无) — 要更新的通道类型或蒙版节点为“无”。
引发:
ValueError — 如果节点具有每个通道类型的混合信息但未提供通道类型,或者节点具有没有通道类型和通道类型的混合信息。
get_堆叠() ->堆叠 substance_painter.layerstack.Node.get_stack
获取包含此堆叠的节点。
返回:包含此堆叠的节点。
返回类型: 堆叠
get_parent() ->节点 substance_painter.layerstack.Node.get_parent
获取此节点的父级。
返回:此节点的父级,如果此节点是根图层,则返回“无”。
返回类型: 节点
get_next_sibling() ->节点 substance_painter.layerstack.Node.get_next_sibling
获取此节点的下一个同级。
返回:此节点的下一个同级,如果此节点是第一个同级,则返回“无”。
返回类型: 节点
get_previous_sibling() ->节点 substance_painter.layerstack.Node.get_previous_sibling
获取此节点的上一个同级节点。
返回:此节点的上一个同级,如果此节点是最后一个同级,则返回“无”。
返回类型: 节点
uid() -> int substance_painter.layerstack.Node.uid
获取对象内部UID。
返回:作为整数的对象的内部标识符。
返回类型:整型
类substance_painter.layerstack.LayerNode(uid) substance_painter.layerstack.LayerNode
基数: Node
作为主层次结构一部分的节点。 每个图层(如绘画或填充图层)以及组都组织成这种层次结构。 这样,您可以查询子图层(在LayerNode是组的情况下),但也可以关联内容效果和蒙版效果(如色阶和滤镜等)。
content_effects() -> List[GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode] substance_painter.layerstack.LayerNode.content_effects
查询此图层堆叠的内容效果,按顺序排列。
返回:此节点的内容效果。
返回类型: 列表[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
查询此图层堆叠的蒙版效果,按节点中的顺序排列。
返回:此节点的蒙版效果。
返回类型: 列表[GeneratorEffectNode | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode]
instances() -> List[LayerNode] substance_painter.layerstack.LayerNode.instances
返回此层的实例列表。 如果您不熟悉概念,请参阅有关图层实例化的文档: 图层实例化文档。
返回:此节点的实例。
返回类型: 列表[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
设置要应用到此节点的几何蒙版类型。 仅在相应的纹理集使用UV 平铺时支持GeometryMaskType.UVTile。
参数: geometry_mask_type (GeometryMaskType) — 此图层节点的几何蒙版类型。
引发:
ValueError — 当请求GeometryMaskType.UVTile且项目不支持UV 平铺时。
substance_painter.layerstack.LayerNode.set_geometry_mask()。get_geometry_mask_enabled_网格() ->列表[str] substance_painter.layerstack.LayerNode.get_geometry_mask_enabled_meshes
获取为几何图形蒙版启用的网格的列表。 不在此列表中的网格将被禁用。 要获取网格的完整列表,请参阅substance_painter.textureset.TextureSet.all_mesh_names()。
返回:为几何图形蒙版启用的网格列表。
返回类型: 列表[ str]
set_geometry_mask_enabled_网格(网格名称:列表[str]) substance_painter.layerstack.LayerNode.set_geometry_mask_enabled_meshes
为几何图形蒙版设置已启用网格的列表。 不在此列表中的网格将被禁用。 要获取网格的完整列表,请参阅substance_painter.textureset.TextureSet.all_mesh_names()。
参数: 网格_names (列表 [ str*]*) — 要为几何图形蒙版启用的网格列表。
引发: 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 平铺列表。
返回类型: 列表[UVTile]
set_geometry_mask_enabled_uv_tiles(uv_tiles: List[UVTile]) substance_painter.layerstack.LayerNode.set_geometry_mask_enabled_uv_tiles
为几何图形蒙版设置已启用UV 平铺的列表。 不在此列表中的UV 平铺将被禁用。 要获取UV 平铺的完整列表,请参阅substance_painter.textureset.TextureSet.all_uv_tiles()。
参数: uv_tiles (列表*[*UVTile *]*) — 要为几何图形蒙版启用的UV 平铺列表。
引发: 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(params: GeometryMaskMeshParams | GeometryMaskUVTilesParams) substance_painter.layerstack.LayerNode.set_geometry_mask
设置几何蒙版设置。
参数: 参数 (GeometryMaskMeshParams | GeometryMaskUVTilesParams) — 几何蒙版参数。
引发: ValueError — 如果参数不一致或包含无效元素。
has_mask() -> bool substance_painter.layerstack.LayerNode.has_mask
检查此节点是否有蒙版。
返回:此节点是否具有掩码。
返回类型: bool
add_mask(background: 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() -> MaskBackground substance_painter.layerstack.LayerNode.get_mask_background
查询此节点使用的掩码类型。
引发:
ValueError — 如果此节点上不存在蒙版。 使用has_mask()检查节点是否具有蒙版。
返回:应用于此节点的蒙版背景。
返回类型: MaskBackground
set_mask_background(background: MaskBackground) substance_painter.layerstack.LayerNode.set_mask_background
在此节点上设置蒙版背景。
参数: 背景 (蒙版背景) — 要应用于此节点蒙版的蒙版背景。
引发:
ValueError — 如果此节点上不存在蒙版。 使用has_mask()检查节点是否具有蒙版。
is_mask_enabled() -> bool substance_painter.layerstack.LayerNode.is_mask_enabled
查询蒙版当前是否已启用。
引发:
ValueError — 如果此节点上不存在蒙版。 使用has_mask()检查节点是否具有蒙版。
返回:当前是否启用了蒙版。
返回类型: bool
enable_mask(enabled: bool) substance_painter.layerstack.LayerNode.enable_mask
设置蒙版当前是否已启用。
参数: 已启用 (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
GeneratorEffectNode的别名 | PaintEffectNode | FillEffectNode | LevelsEffectNode | CompareMaskEffectNode | FilterEffectNode | ColorSelectionEffectNode | AnchorPointEffectNode
枚举
类substance_painter.layerstack.NodeType(value) substance_painter.layerstack.NodeType
有关图层和效果的更多信息,请参阅图层和效果。
成员:
PaintLayerPaintEffectFillLayerFillEffectGeneratorEffectFilterEffectLevelsEffectCompareMaskEffectColorSelectionEffectGroupLayerInstanceLayerAnchorPointEffect类substance_painter.layerstack.MaskBackground(value) substance_painter.layerstack.MaskBackground
成员:
BlackWhite类substance_painter.layerstack.BlendingMode(value) substance_painter.layerstack.BlendingMode
混合模式允许以不同方式将图层结果与下方其他图层混合。 有关详细信息,请参阅混合模式文档。
成员:
NormalPassThroughDisableReplaceMultiplyDivideInverseDivideDarkenLightenLinearDodgeSubtractInverseSubtractDifferenceExclusionSignedAdditionOverlayScreenLinearBurnColorBurnColorDodgeSoftLightHardLightVividLightLinearLightPinLightTintSaturationColorValueNormalMapCombineNormalMapDetailNormalMapInverseDetail类substance_painter.layerstack.GeometryMaskType(value) substance_painter.layerstack.GeometryMaskType
成员:
MeshUVTile