來源內容
SourceSubstance 是一種可以連結物質資源的來源。
更多資訊請參見模與resourcecolormanagement。
範例
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])
class substance_painter.source.SourceSubstance(uid) substance_painter.source.SourceSubstance
一個代表程序來源的類別。
屬性resource_id:ResourceID substance_painter.source.SourceSubstance.resource_id
目前的物質資源。
Getter: 回傳源頭的資源。
屬性output_mapping:輸出映射 substance_painter.source.SourceSubstance.output_mapping
多重輸出上下文中的輸出映射特性。
Getter: 回傳輸出映射屬性。
設定器: 設定輸出映射屬性。
性質active_output:力量 substance_painter.source.SourceSubstance.active_output
來源在單一輸出情境下的主動輸出。
Getter: 回傳輸出識別碼。
設定器: 設定輸出識別碼。
性質mask_output:力量 substance_painter.source.SourceSubstance.mask_output
來源在多重輸出情境中的遮罩輸出識別碼。
Getter: 回傳遮罩輸出識別碼。
Setter: 設定遮罩輸出識別碼。
屬性image_inputs:List[str] substance_painter.source.SourceSubstance.image_inputs
目前圖表中的影像輸入識別碼清單。
Getter: 回傳影像輸入識別碼清單。
屬性image_outputs:列表[強度] substance_painter.source.SourceSubstance.image_outputs
影像清單會從目前圖表輸出識別碼。
Getter: 回傳影像輸出識別碼清單。
get_source(識別碼:str)-> SourceUniformColor |SourceBitmap |SourceVectorial |SourceSubstance |SourceReference |SourceFont substance_painter.source.SourceSubstance.get_source
取得給定輸入識別碼的來源。
參數:識別碼(str)-輸入識別碼。
回傳: 輸入的來源。
回傳類型:SourceUniformColor | SourceBitmap | SourceVectorial | SourceSubstance | SourceReference | SourceFont
set_source(識別碼:str,來源:ResourceID |顏色 |AnchorPointEffectNode) -> SourceUniformColor |SourceBitmap |SourceVectorial |SourceSubstance |SourceReference |SourceFont substance_painter.source.SourceSubstance.set_source
設定給定輸入識別碼的來源。
參數:
- 識別碼 (STR)– 輸入識別碼。
- source(*ResourceID**|Color|* AnchorPointEffectNode)– 來源參數。
回波: 輸入的來源。
回傳類型:SourceUniformColor | SourceBitmap | SourceVectorial | SourceSubstance | SourceReference | SourceFont
reset_source(識別碼:力量)-> 無 substance_painter.source.SourceSubstance.reset_source
重設給定輸入識別碼的來源。
參數:識別碼(str)-輸入識別碼。
返回類型: 無
remove_source(識別碼:力量)-> 無 substance_painter.source.SourceSubstance.remove_source
移除給定輸入識別碼的來源。
參數:識別碼(str)-輸入識別碼。
返回類型: 無
get_parameters() -> Dict[str, bool | int |元組[int, int] |元組[int, int, int] |元組 int, int, int |元組[int, int, int,] int | float |元組[浮點, float] , float |元組[浮點, float, float] |顏色 |元組[顏色, float] |元組[浮點、float, float, float, float] | str] substance_painter.source.SourceSubstance.get_parameters
取得原始程序參數。 對於來源的每個屬性,所得字典會以屬性名稱為鍵,屬性值作為值。
回報: 原始程序參數。
回傳類型: Dict[str, bool | int | 元組[ int, int] | 元組[ int, int, int] | 元組[ int, int, int, int] | float | 元組[ float, float, float] | 元組[ float, float, float] | 顏色 | 元組[顏色, float] | 元組[ float, float, float, float] | str]**
set_parameters(property_values: Dict[str, bool | int |元組[int, int] |元組[int, int, int] |元組[int, int, int,] int | float |元組[float, float] , float |元組[float, float, float] |顏色 |元[組顏色, float] |元組[float, float, float,] float | str]) -> 無 substance_painter.source.SourceSubstance.set_parameters
設定原始碼程序參數。
參數: property_values (Dict[str , bool | int | 元組 [ int**, int*]* | 元組 int, int ,int ]|元組[ int , int ,int, int ] | float | [元組浮點**, 浮點*]* |元組[浮點, 浮點**, 浮點*]* *|*顏色 *|元組[顏色**,* 浮點*]* |* * [Tuplefloat[, float**, float*,* float**] | * str**]*)– 一個要設定屬性及其對應值的dict。
返回類型: 無
>>> 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, Property]
get_preset_list() -> 列表[強度] 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: 回傳解析度參數。
設定者: 設定解析度參數。
加薪:
ValueError – 如果來源被用於 substance_painter.layerstack.FilterEffectNode。
class 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])