SourceSubstance
SourceSubstance是一种源类型,您可以在其中连接substance资源。
有关详细信息,请参阅模块resource和colormanagement。
示例
import substance_painter as sp
# Get the currently displayed stack
stack = sp.textureset.get_active_stack()
# Insert a fill layer
position = sp.layerstack.InsertPosition.from_textureset_stack(stack)
fill = sp.layerstack.insert_fill(position)
# Apply "Graphic to Material" in `Material` mode
graphic_to_material = sp.resource.search("s:starterassets "
"u:substance "
'n:"graphictomaterial"')[0]
source = fill.set_material_source(graphic_to_material.identifier())
# Substances can have image inputs which are sources themselves
# In this case, we use the input identifier instead of the channel type to query and edit the source
logo = sp.resource.search("s:starterassets "
"u:alpha "
'n:"logo painter"')[0]
assert "custom_image" in source.image_inputs
input_source = source.set_source("custom_image", logo)
# `input_source` is now a BitmapSource
# see BitmapSource example for further information on its interface
# In `Material` mode, you can specify how the outputs of the substance are plugged in the fill's channels
default_mapping = {
sp.textureset.ChannelType.BaseColor: "basecolor",
sp.textureset.ChannelType.Metallic: "metallic",
sp.textureset.ChannelType.Roughness: "roughness",
sp.textureset.ChannelType.Height: "height"
}
for dst_chn, identifier in default_mapping.items():
assert identifier in source.image_outputs
source.output_mapping[dst_chn] = identifier
# If not in `Material` mode, choose which output of the substance is active
# source.active_output = "basecolor"
# Retrieve and edit the substance parameters
params = source.get_parameters()
for prop_name in params.keys():
print(prop_name)
new_params = {
"outline_color": sp.colormanagement.Color(0.9, 0.7, 0.4),
"roughness": params["roughness"] / 2,
# Boolean parameters are treated as integer, if you use `True` or `False` you will get an error message:
# >>> Bad value for property 'channel_roughness': expected value of type <int32> but got <bool>
"channel_roughness": 1,
}
source.set_parameters(new_params)
# Query embedded presets and apply the first one
presets = source.get_preset_list()
for preset_name in presets:
print(preset_name)
if presets:
source.apply_preset(presets[0])
# Select the Fill layer
sp.layerstack.set_selected_nodes([fill])
类substance_painter.source.SourceSubstance(uid) substance_painter.source.SourceSubstance
表示程序化源的类。
属性resource_id:资源ID substance_painter.source.SourceSubstance.resource_id
源的当前Substance资源。
Getter:返回源的资源。
属性output_mapping: OutputMapping substance_painter.source.SourceSubstance.output_mapping
多个输出上下文中的输出映射属性。
Getter:返回输出映射属性。
Setter:设置输出映射属性。
属性active_output: str substance_painter.source.SourceSubstance.active_output
单个输出上下文中的源活动输出。
Getter:返回输出标识符。
Setter:设置输出标识符。
属性mask_output: str substance_painter.source.SourceSubstance.mask_output
在多个输出上下文中的源的蒙版输出标识符。
Getter:返回蒙版输出标识符。
Setter:设置蒙版输出标识符。
属性image_inputs: List[str] substance_painter.source.SourceSubstance.image_inputs
图像列表输入来自当前图形的标识符。
Getter:返回标识符的图像输入列表。
属性image_outputs: List[str] substance_painter.source.SourceSubstance.image_outputs
来自当前图形的图像输出标识符的列表。
Getter:返回标识符的列表。
get_source(标识符: str) -> SourceUniformColor |源位图 | SourceVector | SourceSubstance | SourceReference | SourceFont substance_painter.source.SourceSubstance.get_source
获取给定输入标识符的源。
参数: 标识符 (str) — 输入标识符。
返回:输入的源。
返回类型: SourceUniformColor | 源位图 | 源矢量图 | SourceSubstance | 源引用 | SourceFont
set_source(标识符:str,源:资源ID |颜色 | AnchorPointEffectNode) -> SourceUniformColor |源位图 | SourceVector | SourceSubstance | SourceReference | SourceFont substance_painter.source.SourceSubstance.set_source
设置给定输入标识符的源。
参数:
- 标识符 (str) — 输入标识符。
- source (ResourceID | Color | AnchorPointEffectNode) — 源参数。
返回:输入的源。
返回类型: SourceUniformColor | 源位图 | 源矢量图 | SourceSubstance | 源引用 | SourceFont
reset_source(标识符:str) ->无 substance_painter.source.SourceSubstance.reset_source
重置给定输入标识符的源。
参数: 标识符 (str) — 输入标识符。
返回类型:无
remove_source(标识符:str) ->无 substance_painter.source.SourceSubstance.remove_source
删除给定输入标识符的源。
参数: 标识符 (str) — 输入标识符。
返回类型:无
get_parameters() -> Dict[str, bool |整数 | Tuple[int, int] | Tuple[int, int, int] | Tuple[int, int, int, int] |浮动 |元组[浮动,浮动] |元组[浮动,浮动,浮动] |颜色 |元组[颜色,浮动] |元组[浮动、浮动、浮动、浮动] | str] substance_painter.source.SourceSubstance.get_parameters
获取源程序化参数。 对于源的每个属性,生成的词典都包含一个条目,其中属性名称作为key ,属性值作为value。
返回:源程序化参数。
返回类型: Dict[str, bool |整数 | 元组[ int,int] | Tuple[ int, int, int] | Tuple[ int, int, int, int] |浮动 | 元组[浮动,浮动] | 元组[浮动,浮动,浮动] | 颜色 | 元组[颜色,浮点] | 元组[浮动,浮动,浮动,浮动] | str]
set_parameters(property_values: Dict[str, bool |整数 | Tuple[int, int] | Tuple[int, int, int] | Tuple[int, int, int, int] |浮动 |元组[浮动,浮动] |元组[浮动,浮动,浮动] |颜色 |元组[颜色,浮动] |元组[浮动、浮动、浮动、浮动] | str]) ->无 substance_painter.source.SourceSubstance.set_parameters
设置源程序化参数。
参数: 属性_值 (Dict [ str**, 布尔值 | int | 元组**[int, int**] | Tuple元组**[int, int , int] | 元组 [ int**, int **, int**, int*]* | 浮动 元组 [ 浮动**, 浮动*]* | 元组 [ 浮动**, 浮动*,* 浮动**] | 颜色 | B tuple*[颜色,* 浮点**] | 元组*[浮点,* 浮点**, 浮点*,* 浮点**] | str*) — 要用其属性设置的属性**
返回类型:无
>>> Bad value for property ‘<property\_name>’: expected value of type <int32> but got <bool>get_properties() -> Dict[str,属性] substance_painter.source.SourceSubstance.get_properties
获取源程序化属性。
返回:源程序化属性。
返回类型: Dict[str, 属性]
get_preset_list() ->列表[str] substance_painter.source.SourceSubstance.get_preset_list
获取此源的所有可用预设的列表。
返回:所有预设名称的数组。
返回类型: 列表[ str]
apply_preset(名称:str) substance_painter.source.SourceSubstance.apply_preset
根据预设名称应用预设。 如果未找到具有此名称的预设,则不执行任何操作。
参数: 名称 (str) — 要应用的预设的名称。
属性解析:ResolutionOverride substance_painter.source.SourceSubstance.resolution
此物质的分辨率参数。
Getter:返回分辨率参数。
Setter:设置分辨率参数。
引发:
ValueError — 如果在substance_painter.layerstack.FilterEffectNode中使用了源。
类substance_painter.source.OutputMapping(uid) substance_painter.source.OutputMapping
此类允许以类似命令的方式访问源程序化的输出映射。 请参阅output_mapping属性。
示例:
import substance_painter as sp
mapping = a_substance_source.output_mapping
mapping[sp.textureset.ChannelType.BaseColor] = sp.textureset.ChannelType.Specular
for channel in mapping:
print(mapping[channel])