資源模組
此模組允許操作 Substance 3D Painter 的資源與書架。
Substance 3D Painter 將材質、材質、筆刷等視為資源,並使用 URL 來識別它們。 資源可以放在書架上,也可以直接嵌入專案中(例如烘焙的環境遮蔽材質)。
class substance_painter.resource.Type(value) substance_painter.resource.Type
描述特定資源類型的枚舉。
成員:
ABR_PACKAGEBRUSHEXPORTFONTIMAGEPRESETRESOURCESCRIPTSHADERSMART_MASKSMART_MATERIALSUBSTANCESUBSTANCE_PACKAGEVECTORIALclass substance_painter.resource.UpdateProjectError(old_resource_id: ResourceID, new_resource_id: ResourceID, details: List[str]) substance_painter.resource.UpdateProjectError
操作過程中 replace_project_resources() 發生的錯誤。
參數:
- old_id – 無法更新的資源識別碼。
- new_id – 原本應該取代舊資源的識別碼。
- details (List [ str*]*) – 錯誤訊息的清單。
- old_resource_id (ResourceID)
- new_resource_id (ResourceID)
概觀
資源操作
資源模組暴露 Resource類別 ,代表目前在 Substance 3D Painter 中可用的資源(可存放於當前專案、當前會議或書架中)。
列出書架上所有資源可以用 來完成 Shelf.resources(),而 search() 則可以搜尋特定資源。 特定資源可直接在資產視窗中以篩選器顯示,且 Resource.show_in_ui() show_resources_in_ui()。
import substance_painter.resource
# Get all the resources of a shelf:
my_shelf = substance_painter.resource.Shelf("myshelf")
all_shelf_resources = my_shelf.resources()
for resource in all_shelf_resources:
print(resource.identifier().name)
# Find all resources that match a name:
aluminium_resources = substance_painter.resource.search("aluminium")
for resource in aluminium_resources:
print(resource.identifier().name)
# Show a single resource in the shelf:
aluminium_resources[0].show_in_ui()
# Show the list of resources found in the shelf:
substance_painter.resource.show_resources_in_ui(aluminium_resources)
內部而言,資源以 URL 識別; ResourceID 包含該 URL。 它可以被直接操作,且無法保證該網址是否指向實際資源。
import substance_painter.resource
# Display the URL of a resource:
envmap_resources = substance_painter.resource.search("bonifacio")
for envmap in envmap_resources:
envmap_id = envmap.identifier()
print("The URL of the resource `{0}` is {1}"
.format(envmap_id.name, envmap_id.url()))
print("The location of the resource `{0}` is {1}"
.format(envmap_id.name, envmap_id.location()))
# It is possible to create a ResourceID from a URL. If there is no
# resource corresponding to the URL, the ResourceID is still valid
# but refers to a resource that doesn't exist.
envmap2_id = substance_painter.resource.ResourceID.from_url(
"resource://starter_assets/Bonifacio Street");
# It is possible to create a ResourceID from a context, a name and
# a version (optional). This is equivalent to the above, with the
# same caveat.
envmap3_id = substance_painter.resource.ResourceID(
context="starter_assets", name="Bonifacio Street")
envmap4_id = substance_painter.resource.ResourceID(
context="starter_assets", name="Bonifacio Street",
version="d30facd8d860fc212f864065641cdca4e8006510.image");
# It is possible to get the ResourceID of a resource embedded in the
# current project. This time it refers to an actual resource.
envmap5_id = substance_painter.resource.ResourceID.from_project(
name="Bonifacio Street");
# Finally, it is possible to get the ResourceID of a resource that
# was imported in the current session:
envmap6_id = substance_painter.resource.ResourceID.from_session(
name="Bonifacio Street");
如果資源存在,可以從其識別碼中檢索出。Resource.retrieve()當同一資源有多個版本時, Resource.retrieve() 會回傳整個清單,從最近的一個開始。 相反地,如果資源不存在或已被刪除, Resource.retrieve() 則會回傳一個空清單。
import substance_painter.resource
# Create a ResourceID:
envmap_id = substance_painter.resource.ResourceID(context="starter_assets",
name="Bonifacio Street")
# Get the resources corresponding to the ResourceID. There can be 0 if there
# is no such resource, or more than 1 if there are multiple versions of the
# resource.
envmap_resources = substance_painter.resource.Resource.retrieve(envmap_id)
print("{} resource(s) with that ID".format(len(envmap_resources)))
資源進口
新資源可以匯入,可以匯入目前專案(含 import_project_resource()),或import_session_resource() Shelf.import_resource()匯入 的 。這三個函式都會選擇一條路徑到要匯入的資源,A Usage 表示該資源的類型,並且可選擇性地提供名稱和群組。 此功能對應於「匯入資源」視窗。
資源可以匯入書架,只要不是唯讀書架。 Substance 架子安裝在應用程式旁,為唯讀。 如果書架在檔案系統上的路徑是唯讀,則該書架也是唯讀的。 這可以用 來檢驗 Shelf.can_import_resources()。
範例:
import substance_painter.resource
# Open a project we want to import into (see substance_painter.project
# for details). This step is not necessary if there is already a project
# opened in Substance 3D Painter.
import substance_painter.project
substance_painter.project.open("C:/projects/MeetMat.spp")
# Import a normal map to the project:
new_resource = substance_painter.resource.import_project_resource(
"C:/textures/MyBakedNormalMap.png",
substance_painter.resource.Usage.TEXTURE)
# Import a color LUT to the session:
new_color_lut = substance_painter.resource.import_session_resource(
"C:/textures/sepia.exr",
substance_painter.resource.Usage.COLOR_LUT)
# Set that color LUT (see substance_painter.display for details).
# This step is unrelated to import, and just meant to show how the
# imported resource can be used.
import substance_painter.display
substance_painter.display.set_color_lut_resource(new_color_lut.identifier())
# Import an environment map to the shelf.
my_shelf = substance_painter.resource.Shelf("myshelf")
if my_shelf.can_import_resources():
new_resource = my_shelf.import_resource(
"C:/textures/Bonifacio Street.exr",
substance_painter.resource.Usage.ENVIRONMENT)
else:
print("The shelf is read-only.")
另見:: 透過匯入視窗新增內容。
資源爬取
當 Substance 3D Painter 開啟時,它會瀏覽不同的書架,以發現並索引資源,並顯示縮圖。 當切換到其他應用程式後重新聚焦時,若使用者在架子資料夾新增資產,系統會再次聚焦。 這個過程稱為 資源爬取。
當一個書架開始爬行時,該書架會發出一個事件 substance_painter.event.ShelfCrawlingStarted 。 爬行結束後,該書架會發出事件 substance_painter.event.ShelfCrawlingEnded 。 隨時都能 Shelf.is_crawling() 判斷架子是否在爬行。
Python 腳本可以明確觸發一個新資源爬取。Shelves.refresh_all()
範例:
import substance_painter.resource
import substance_painter.event
# Two event handlers to show when crawling starts and ends:
def on_start_crawl(e):
print("Shelf `{}` started crawling.".format(e.shelf_name))
def on_end_crawl(e):
print("Shelf `{}` finished crawling.".format(e.shelf_name))
# Use the event handler to listen to ShelfCrawlingStarted and
# ShelfCrawlingEnded:
substance_painter.event.DISPATCHER.connect(
substance_painter.event.ShelfCrawlingStarted,
on_start_crawl)
substance_painter.event.DISPATCHER.connect(
substance_painter.event.ShelfCrawlingEnded,
on_end_crawl)
# At this point, the event handlers may or may not print something,
# depending on what the shelves are doing. It is possible to trigger
# a crawling by switching to another application, and coming back
# to Substance 3D Painter.
# It is also possible to trigger a crawling with this call:
substance_painter.resource.Shelves.refresh_all()
my_shelf = substance_painter.resource.Shelf("myshelf")
# Running this bloc at different moments will give different
# results:
if my_shelf.is_crawling():
print("The shelf is crawling...")
else:
print("The shelf is idle.")
資源重新載入
一旦資源已匯入架子、工作階段或專案中,修改匯入檔案就沒有影響,因為 Substance 3D Painter 會保留檔案副本以便使用。
透過重新載入資源,原始檔案會被重新匯入,資源也會在書架、工作階段或專案中更新。 請注意,這不會更新專案文件中目前使用的資源(層堆疊、著色器、環境貼圖等)。 若要更新專案文件中目前使用的資源,請透過呼叫 substance_painter.event.replace_project_resources()資源更新功能。
資源重新載入是透過呼叫 substance_painter.event.reload_modified_resources_async()來觸發的。
由於此過程可能需要一些時間,因此採用非同步方式。 當程序開始時觸發事件 substance_painter.event.ReloadResourcesStarted ,並提供操作範圍的資訊。 當程序結束時,事件 substance_painter.event.ReloadResourcesEnded 會觸發,並提供有關所產生資源狀態的資訊。 不允許同時進行資源重新載入。 可以透過呼叫 substance_painter.event.is_reload_modified_resources_running()來檢查某個程序是否已經在執行。
範例
import substance_painter as sp
# Two event handlers to show when reloading starts and ends
def on_reload_started(e: sp.event.ReloadResourcesStarted):
print("Resource reloading asynchronous process started")
if isinstance(e.filter, sp.resource.ResourcesListFilter):
print("Reloading specific resources:")
for res_id in e.filter.resources:
print(res_id.url())
else:
# Also possible to have other types of filters, see documentation
print("Examine filter if needed")
def on_reload_ended(e):
print("Resource reloading asynchronous process ended")
for reloaded in e.reloaded_resources:
print(f"Resource {reloaded.old_resource_id.url()} updated to {reloaded.new_resource_id.url()}")
for errors in e.resource_errors:
print(f"Resource {errors.resource_id.url()} was not reloaded: {errors.error_msg}")
# Use the event handlers to listen to ReloadResourcesStarted and ReloadResourcesEnded events
sp.event.DISPATCHER.connect(sp.event.ReloadResourcesStarted, on_reload_started)
sp.event.DISPATCHER.connect(sp.event.ReloadResourcesEnded, on_reload_ended)
# Find some resources in the current opened project and reload them
resources_to_reload = []
for project_resource_id in sp.resource.list_project_resources():
if project_resource_id.name == "a":
print(f"Will reload {project_resource_id.url()}")
resources_to_reload.append(project_resource_id)
sp.resource.reload_modified_resources_async(sp.resource.ResourcesListFilter(resources_to_reload))
專案使用的資源
更新專案中的過時資源
可以將專案的過時資源列出,並list_project_outdated_resources()用 更新。replace_project_resources()專案資源是指專案中使用的所有資源(在圖層堆疊、著色器、環境貼圖等)。
範例
import substance_painter as sp
# Before running this example, open a project with some outdated resources
# or modify a resource and reimport it in the shelf.
# Retrieve the list of outdated resources
outdated_resources = sp.resource.list_project_outdated_resources()
# Filter the list to keep only specific resources
resources_to_update = {}
for old_res, new_res in outdated_resources.items():
# Here the filter is based on the name of the resource
if old_res.name == 'my_resource':
resources_to_update[old_res] = new_res
# Print the list of filtered resources
for res in resources_to_update:
print(res)
# Update the resources in the project
# This call might take some time and can provoke a freeze of the application, depending on:
# - the number of resources to update and
# - the number of uses in the project
status = sp.resource.replace_project_resources(resources_to_update)
# Print the result of the update
print(f'status: {status}')
替換專案中的資源
可以將專案中使用的資源列出,並 list_project_resources()用 替換為 replace_project_resources()。
範例
import substance_painter as sp
# Get the currently displayed Stack
stack = sp.textureset.get_active_stack()
# Get top position of the Stack
position_stack_top = sp.layerstack.InsertPosition.from_textureset_stack(stack)
# Insert a material
metal_material = sp.resource.search("s:starterassets "
"u:basematerial "
"n:Metal Brushed ")[0]
my_fill = sp.layerstack.insert_fill(position_stack_top)
my_fill.set_material_source(metal_material.identifier())
# List all the resources referenced by the project:
used_resources_ids = sp.resource.list_project_resources()
for resource_id in used_resources_ids:
print(resource_id.name)
# Get the new resource
new_resource = sp.resource.search("s:starterassets "
"u:basematerial "
"n:Fabric ")[0]
# Find the resource to update:
resource_to_replace = None
for resource_id in used_resources_ids:
if 'metal_brushed' in resource_id.name:
resource_to_replace = resource_id
break
# Replace the old resources by the new one:
status = sp.resource.replace_project_resources(
{resource_to_replace: new_resource.identifier()})
# Print the result of the update
print(f'status: {status}')
自訂預覽
當資源匯入時,會自動產生縮圖。 你可以用 Resource.set_custom_preview(),將該縮圖替換成自訂預覽,或用 Resource.reset_preview()重置預覽。
範例:
import substance_painter.resource
aluminium_resources = substance_painter.resource.search("aluminium")
resource = aluminium_resources[0]
# Set the custom preview:
resource.set_custom_preview("C:/textures/MyCustomPreview.png")
# Remove the custom preview:
resource.reset_preview()
資源
類別 substance_painter.resource.Resource(handle: _substance_painter.resource.ResourceHandle) substance_painter.resource.Resource
一個 Substance 3D Painter 資源。
參數:handle (_substance_painter.resource.ResourceHandle)
identifier() -> ResourceID substance_painter.resource.Resource.identifier
取得這個資源識別碼。
回報: 資源識別碼。
返回類型:ResourceID
Raises:RuntimeError – 如果資源無效。
ResourceID。location() -> ResourceLocation(資源位置) substance_painter.resource.Resource.location
取得這個資源的位置。
回報: 此資源的位置。
返回類型:ResourceLocation
Raises:RuntimeError – 如果資源無效。
靜態擷取(識別碼:ResourceID) substance_painter.resource.Resource.retrieve
取得與該識別碼相符的資源清單。
參數:識別碼(ResourceID)– 資源識別碼。
加薪:
- ValueError – 如果識別碼名稱為空或該識別碼的上下文不存在。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
退貨:
與該識別碼相符的資源清單。 若識別碼有有效版本,此方法只會回傳一個或零個資源,否則清單可能包含多個資源。 若有多個資源被回傳,最新的資源會位於清單的開頭。
**回傳類型:**List[資源]
set_custom_preview(preview_image: 力量)-> 無 substance_painter.resource.Resource.set_custom_preview
將此資源目前的預覽替換為自訂圖片。
參數:
preview_image (str) – 磁碟上映像檔路徑,作為新預覽。
加薪:
- ValueError – 如果資源元資料無法被修改。
- ValueError – 如果
preview_image不是通往有效影像的有效路徑。 - ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
返回類型: 無
類別()-> 力量 substance_painter.resource.Resource.category
取得這個資源的分類,例如:「木材」代表某種材料。
Raises:RuntimeError – 如果資源無效。
回報: 此資源的類別
回傳類型: 力量
usages() -> List[使用] substance_painter.resource.Resource.usages
了解這個資源的用途。
Raises:RuntimeError – 如果資源無效。
回報: 此資源的使用情況
**回傳類型:**List[用法]
Usagegui_name() -> str substance_painter.resource.Resource.gui_name
取得這個資源的圖形介面名稱。
Raises:RuntimeError – 如果資源無效。
回傳: 此資源的 GUI 名稱
回傳類型: 力量
類型(type() ->型 substance_painter.resource.Resource.type
了解這些資源的類型。
Raises:RuntimeError – 如果資源無效。
回報: 此資源的類型
回傳類型:類型
Type標籤() -> 列表[力量] substance_painter.resource.Resource.tags
取得此資源的標籤。
Raises:RuntimeError – 如果資源無效。
退貨: 本資源標籤
**回傳類型:**列表[ str]
internal_properties() -> substance_painter.resource.Resource.internal_properties
取得資源內部屬性的字典。 目前的實作只提取 Substance 資源的元資料。
Raises:RuntimeError – 如果資源無效。
Returns: 包含該資源內部屬性的字典
回傳類型: dict
children() -> List[資源] substance_painter.resource.Resource.children
取得兒童資源。 例如,物質包的物質圖。
Raises:RuntimeError – 如果資源無效。
回報: 本資源中包含的資源。
**回傳類型:**List[資源]
parent() -> 資源 |無 substance_painter.resource.Resource.parent
取得家長資源。 例如,物質圖所來自的物質包。
Raises:RuntimeError – 如果資源無效。
回報: 擁有此資源的父資源。
**回傳類型:**可選[資源]
reset_preview() -> 沒有 substance_painter.resource.Resource.reset_preview
移除該資源的所有自訂預覽,並重置為預設預覽。
加薪:
- ValueError – 如果資源元資料無法被修改。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
返回類型: 無
show_in_ui() -> 沒有 substance_painter.resource.Resource.show_in_ui
在應用程式架的 UI(資產視窗)中選取此資源。
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
返回類型: 無
class substance_painter.resource.ResourceID(上下文:str,名稱:str,版本:str |None = None) substance_painter.resource.ResourceID
一個 Substance 3D Painter 資源識別碼。
資源由上下文、名稱和版本來識別。 上下文和名稱是必須的,而版本則是可選的。 這個版本是一個看起來像雜湊的字串,也可能包含一個副檔名。
參數:
- 情境 (STR)
- 名稱 (STR)
- 版本 (STR)
classmethod from_project(名稱:str,版本:str |None = None) substance_painter.resource.ResourceID.from_project
為目前專案中位於的資源建立一個 ResourceID 物件。
參數:
- 名稱 (str)– 資源名稱。
- 版本 (str*,* 可選)– 資源版本(類雜湊字串)。
回報: 對應名字的資源。
返回類型:ResourceID
classmethod from_session(名稱:str,版本:str |None = None) substance_painter.resource.ResourceID.from_session
為位於目前會話中的資源建立一個 ResourceID 物件。
參數:
- 名稱 (str)– 資源名稱。
- 版本 (str*,* 可選)– 資源版本(類雜湊字串)。
回報: 對應名字的資源。
返回類型:ResourceID
classmethod from_url(URL: str) substance_painter.resource.ResourceID.from_url
從 URL 建立一個 ResourceID 物件。 網址必須有 resource:// 作為一種方案。 這個版本是以查詢字串編碼,看起來像雜湊值。
資源網址長這樣:
resource://context/name?version=0123456789abcdef0123456789abcdef01234567.image
參數:URL (str) – 資源 URL。
回傳: 對應給定網址的資源。
返回類型:ResourceID
加薪:
- ValueError – If
url不是有效的 URL。 - ValueError – 如果 URL 方案不是
resource://。 - ValueError – 如果資源名稱無效。
location() -> ResourceLocation(資源位置) substance_painter.resource.ResourceID.location
取得這個 ResourceID 的位置。
回報: 此資源的位置。
返回類型:ResourceLocation
URL() -> str substance_painter.resource.ResourceID.url
取得此 ResourceID 的網址表單。
回傳: 資源網址。
回傳類型: 力量
加薪:
- ValueError – 如果 ResourceID 沒有上下文。
- ValueError – 如果 ResourceID 沒有名稱。
背景:力量 substance_painter.resource.ResourceID.context
資源的背景說明。
類型: 力量
名稱:STR substance_painter.resource.ResourceID.name
資源名稱。
類型: 力量
版本:STR = 無 substance_painter.resource.ResourceID.version
用雜湊來識別資源的版本。
類型: 力量
class substance_painter.resource.ResourceLocation(value) substance_painter.resource.ResourceLocation
每個資源都有其資料所在位置。
成員:
SESSIONPROJECTSHELF範例
import substance_painter.resource
# For a resource from the default shelf
aluminium = substance_painter.resource.ResourceID(
context="starter_assets", name="Aluminium Insulator");
# This will print:
# ResourceLocation.SHELF
print(aluminium.location())
# For an embedded resource, like a baked map
aomap = substance_painter.resource.ResourceID.from_project(
name="ambient_occlusion");
# This will print:
# ResourceLocation.PROJECT
print(aomap.location())
# Finally, for a temporary resource
test_envmap = substance_painter.resource.ResourceID.from_session(
name="Test Envmap");
# This will print:
# ResourceLocation.SESSION
print(test_envmap.location())
class substance_painter.resource.StandardQuery substance_painter.resource.StandardQuery
標準資源查詢。
成員:
ALL_RESOURCESPROJECT_RESOURCESSESSION_RESOURCESSHELVES_RESOURCESsearch()。class substance_painter.resource.Usage(value) substance_painter.resource.Usage
列舉描述特定資源的使用方式。
成員:
ALPHABASE_MATERIALBRUSHCOLOR_LUTEMITTERENVIRONMENTEXPORTFILTERFONTGENERATORPARTICLEPROCEDURALRECEIVERSHADERSMART_MASKSMART_MATERIALTEXTURETOOLsubstance_painter.resource.search(query: str) -> List[Resource] substance_painter.resource.search
列出符合該查詢的 Substance 3D Painter 資源。
參數:query (str) – 一個資源查詢字串。請參閱 文字查詢文件。
回報: 與該查詢相符的資源清單。
回傳類型: List[資源]
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
StandardQuery。substance_painter.resource.list_project_resources() -> List[ResourceID] substance_painter.resource.list_project_resources
列出目前專案中使用的資源。 專案資源是指專案中使用的所有資源(在圖層堆疊、著色器、環境貼圖等)。
返回: 資源識別碼的清單。
回傳類型: List[ResourceID]
加薪:
- ProjectError – 如果沒有專案被開啟。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
substance_painter.resource.list_project_outdated_resources() -> dict[ResourceID, ResourceID] substance_painter.resource.list_project_outdated_resources
列出目前專案中使用過時的資源。 專案資源是指專案中使用的所有資源(在圖層堆疊、著色器、環境貼圖等)。 過時資源是指已重新載入應用程式,但專案中尚未更新的資源。
退貨:
一個以舊資源識別碼為鍵,新資源識別碼為值的字典。
回傳類型:DictResourceID,ResourceID 🔗 []
加薪:
- ProjectError – 如果沒有專案被開啟。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
substance_painter.resource.replace_project_resources(ids: Dict[ResourceID, ResourceID], allow_parameters_mismatch: bool = False) -> UpdateProjectResult substance_painter.resource.replace_project_resources
替換現有專案的資源。 專案資源是指專案中使用的所有資源(在圖層堆疊、著色器、環境貼圖等)。
給定一對資源識別碼:
- 第一個元素是專案中使用的舊資源識別碼,
- 第二個元素是新的資源識別碼。
此操作會將任何具有相同識別碼的資源替換為新的資源。 新資源必須與它所取代的資源相容(見註);否則操作將失敗。
若在更新過程中發生錯誤,專案不會執行任何操作,並 UpdateProjectStatus 會提供錯誤清單。
參數:
- ids (Dict*[*ResourceID *,* *ResourceID *])— 一個需要更新的資源識別碼字典(key:舊,value:new)。 字典必須包含有效的
ResourceID。 若任何資源識別碼無效,或該金鑰與專案中現有資源不相符,操作將失敗。 若字典為空,則不執行任何操作。 - allow_parameters_mismatch (bool ,可選*)– 預設
False情況下,(),防止專案中使用參數(例如 .sbsar、.ai 檔案)的資源,若參數在新版本中被重新命名或移除,無法更新,以避免對紋理結果*的意外變更。若偵測到任何參數不匹配,操作將失敗。 若True,任何未匹配的參數將重置為預設值。
回報: 操作結果。
返回類型:UpdateProjectResult
加薪:
- ProjectError – 如果沒有專案被開啟。
- RuntimeError – 如果應用程式未處於繪圖模式。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
class substance_painter.resource.UpdateProjectResult(status: UpdateProjectStatus, errors: List[UpdateProjectError]) substance_painter.resource.UpdateProjectResult
手術的 replace_project_resources() 結果。
參數:
- status (UpdateProjectStatus)— 操作狀態。
- errors (List*[*UpdateProjectError *]*)— 若操作失敗時的錯誤清單。 如果操作成功,這個清單是空的。
class substance_painter.resource.UpdateProjectStatus(value) substance_painter.resource.UpdateProjectStatus
行動狀態 replace_project_resources() 。
成員:
SUCCESSERRORsubstance_painter.resource.import_project_resource(file_path: str, resource_usage: Usage, name: str |None = 無,群組: str |None = None) -> 資源 substance_painter.resource.import_project_resource
將資源匯入目前已開啟的專案。
參數:
- file_path (str) – 要匯入資源的檔案路徑。
- resource_usage(使用率)– 資源使用量。
- 名稱 (str*,* 可選)-若與檔名不同,則指資源名稱。
- 群組 (str*,* opional)-可選的群組名稱,可用於資源查詢。
返回: 匯入的資源物件。
回傳類型:資源
加薪:
- ProjectError – 如果沒有專案被開啟。
- ValueError – 如果參數驗證失敗。
- RuntimeError – 匯入失敗。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
substance_painter.resource.import_session_resource(file_path: str, resource_usage: Usage, name: str |None = 無,群組:str |None = None) -> 資源 substance_painter.resource.import_session_resource
將資源匯入目前的 session 中。
參數:
- file_path (str) – 要匯入資源的檔案路徑。
- resource_usage(使用率)– 資源使用量。
- 名稱 (str*,* 可選)-若與檔名不同,則指資源名稱。
- 群組 (str*,* opional)-可選的群組名稱,可用於資源查詢。
返回: 匯入的資源物件。
回傳類型:資源
加薪:
- ValueError – 如果參數驗證失敗。
- RuntimeError – 匯入失敗。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
substance_painter.resource.show_resources_in_ui(resources: List[Resource]) -> 無 substance_painter.resource.show_resources_in_ui
在應用程式架的介面(資產視窗)中選取資源清單。
參數:資源(List*[*Resource *]*)– 要標示的資源
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
返回類型: 無
substance_painter.resource.is_reload_modified_resources_running() -> bool substance_painter.resource.is_reload_modified_resources_running
檢查一下 reload 修改過的資源操作是否正在執行。
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
回傳類型: bool
substance_painter.resource.reload_modified_resources_async(resource_filter: AllResourcesFilter |專案過濾器 |資源列表過濾器 |ResourcesUsedByProjectFilter |SessionFilter |ShelvesListFilter) -> bool substance_painter.resource.reload_modified_resources_async
觸發重新載入使用該篩選條件找到的修改過的資源。 過時的資源不包括在內。
若已執行重載操作,此函式將回傳 False。 可以檢查是否已經有 的重新裝填操作正在執行。is_reload_modified_resources_running()
此函式為非同步,會傳送事件以通知操作進度:
參數:
resource_filter (*AllResourcesFilter *|*ResourcesListFilter *|ShelvesListFilter)– 一個標示需要重新載入的修改資源的過濾器。
回傳:True如果重新裝填操作已經開始,或False已經在執行。
回傳類型: bool
加薪:
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
- ValueError – 當給定的濾波器現在已是已知型態時。
- ValueError – 當給定的篩選器形成不良(例如指向不存在的資源)。 例外為每個問題提供一個訊息,作為列表[強度]
換彈濾鏡
類別 substance_painter.resource.AllResourcesFilter substance_painter.resource.AllResourcesFilter
用於重新載入 Substance 3D Painter 已知的所有修改過的資源,包括所有書架、工作階段範圍資源及專案範圍資源。
class substance_painter.resource.ProjectFilter substance_painter.resource.ProjectFilter
用於重新載入專案上下文中已修改過的資源的過濾器。 這不包含專案使用的資源(如圖層堆疊、著色器、環境貼圖等)。 如果它們被放在書架上或是整個療程中。
class substance_painter.resource.ResourcesListFilter(resources: List[ResourceID]) substance_painter.resource.ResourcesListFilter
用於在指定資源清單中重新載入修改過的資源的過濾器。
參數:資源(List*[*ResourceID *]*)— 需重新載入的資源清單。
類別 substance_painter.resource.ResourcesUsedByProjectFilter substance_painter.resource.ResourcesUsedByProjectFilter
用於重新載入專案目前正在使用的修改過的資源的過濾器。 這包括任何上下文(專案、書架、會議)的資源,只要專案目前有引用即可。
class substance_painter.resource.SessionFilter substance_painter.resource.SessionFilter
用於重新載入會話中已修改過的資源的過濾器。
class substance_painter.resource.ShelvesListFilter(shelves: List[Shelf]) substance_painter.resource.ShelvesListFilter
用於重新載入指定書架中已修改過的資源的過濾器。
參數:書架(List*[書架]*)——需重新載入的書架清單。
書架
另見:: 架子配置。
class substance_painter.resource.Shelf(_name: str) substance_painter.resource.Shelf
類別提供關於某個 Substance 3D Painter 書架的資訊。 書架有獨特的名稱。
參數:_name(力量)
can_import_resources() -> bool substance_painter.resource.Shelf.can_import_resources
檢查資源是否能匯入這個書架。 資源可以匯入書架,只要不是唯讀書架。 Substance 架子安裝在應用程式旁,為唯讀。 如果書架在檔案系統上的路徑是唯讀,則該書架也是唯讀的。
回報:True如果資源能被進口。
回傳類型: bool
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
import_resource(file_path:力量,resource_usage:用法,名稱:力量 |None = 無,群組:力量 |None = 無,uuid:力量 |None = 無) -> 資源 substance_painter.resource.Shelf.import_resource
將資源匯入這個書架。
參數:
- file_path (str) – 要匯入資源的檔案路徑。
- resource_usage(使用率)– 資源使用量。
- 名稱 (str*,* 可選)-若與檔名不同,則指資源名稱。
- 群組 (str*,* opional)-可選的群組名稱,可用於資源查詢。
- uuid (str*,* opional)– 一種可選的 uuid。 如果已有資源與 UUID 相同,則會被替換。
返回: 匯入的資源物件。
回傳類型:資源
加薪:
- ValueError – 如果參數驗證失敗。
- RuntimeError – 匯入失敗。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
is_crawling() -> bool substance_painter.resource.Shelf.is_crawling
檢查這個書架目前是否正在發現資料夾中的資源。
退貨:True如果這個書架正在發現資源,False否則就不行。
回傳類型: bool
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
name() -> str substance_painter.resource.Shelf.name
退貨:
書架名稱。 每個書架都有獨特的名稱。
回傳類型: 力量
path() -> str substance_painter.resource.Shelf.path
回報: 相關路徑
加薪:
- ValueError ——如果書架已經不存在了。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
回傳類型: 力量
refresh() substance_painter.resource.Shelf.refresh
迫使在書架資料夾中發現資源。 當應用程式視窗聚焦時,發現也會自動完成。
加注:ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
resources(query: str = ‘’) -> List[Resource] substance_painter.resource.Shelf.resources
把資源放進這個架子。 可選擇性查詢字串以縮小結果範圍。
參數:query (str*,* 可選) – 資源查詢字串。
退貨: 本書架的資源清單。
**回傳類型:**List[資源]
search()。類別 substance_painter.resource.shelves substance_painter.resource.Shelves
一系列靜態操作書架的方法。
靜態加法(名稱:STR,路徑:STR)-> 架 substance_painter.resource.Shelves.add
新增一個層架。 此書架僅在申請期間有效。 這個書架在應用程式一般設定選單中不會顯示。
參數:
- 名稱 (str)– 新書架名稱。 此名稱必須是唯一的,且只能包含小寫字母、數字、底線或連字號。 用來
Shelves.exists()確認名字是否已經使用。 - 路徑 (str)– 資料夾路徑到監控器。
退貨: 新增的書架。
退貨類型:書架
加薪:
- ValueError – 如果
name或str是無效。 詳情請參閱日誌。 - ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
static all() -> List[Shelf] substance_painter.resource.Shelves.all
列出所有書架。
退貨: 現有書架列表。
**退回類型:**清單[書架]
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
靜態application_shelf() -> 書架 substance_painter.resource.Shelves.application_shelf
這是放置應用程式預設內容的架子。
退貨類型:書架
靜態存在(名稱:STR) -> 布爾 substance_painter.resource.Shelves.exists
判斷是否有標示名字的書架。
參數:名稱(str)– 從架名到Searh。
退貨:True若有標示該名的書架。
回傳類型: bool
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
靜態refresh_all() substance_painter.resource.Shelves.refresh_all
所有書架資料夾中資源的發現。 當應用程式視窗聚焦時,發現也會自動完成。
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
Shelf.refresh()。靜態移除(名稱:STR) substance_painter.resource.Shelves.remove
拆掉一個層架。 任何專案都不能被開放。 刪除非 Python API 建立的書架是不可能的,且會觸發例外。
參數:
名稱 (str)– 要刪除的書架名稱。 用 Shelves.exists() 來確認是否有書架。
加薪:
- ProjectError – 如果專案被開啟。
- ValueError ——如果書架不存在。
- ValueError – 如果書架不是用 Python API 建立的。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
Shelves.exists()。靜態user_shelf() -> 書架 substance_painter.resource.Shelves.user_shelf
這是位於使用者文件資料夾中的書架,預設新資源會在那裡建立。 使用者可以在設定中選擇不同的預設書架,使用此功能時會反映出此功能。
加薪:
ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
退貨類型:書架
已棄用
以下函式已被棄用,保留以求回溯相容,且不應在新程式碼中使用。
substance_painter.resource.list_layer_stack_resources() -> List[ResourceID] substance_painter.resource.list_layer_stack_resources
列出目前專案的圖層堆疊和網格貼圖所參考的資源。
返回: 所引用的資源識別碼清單。
回傳類型: List[ResourceID]
加薪:
- ProjectError – 如果沒有專案被開啟。
- ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
list_project_resources() 。substance_painter.resource.update_layer_stack_resource(old_resource_id: ResourceID, new_resource: Resource) -> List[ResourceID] substance_painter.resource.update_layer_stack_resource
替換目前專案中圖層堆疊和網格貼圖中的資源。
給定一個資源識別碼,將任何具有相同識別碼的資源替換為新的資源。 新資源必須與它所取代的資源相容(見註解);否則會拋出錯誤。
- 如果資源是物質物質,則必須有相同的輸出數量和名稱。
- 如果資源是物質過濾器,則輸入與輸出的數量與名稱必須相同。
退貨:
所有已替換資源的識別碼清單。
回傳類型: List[ResourceID]
參數:
- old_resource_id (ResourceID) – 需更新資源的識別碼。
- new_resource (資源)– 新的資源。
加薪:
- ProjectError – 如果沒有專案被開啟。
- TypeError – If
old_resource_id不是 ResourceID。 - TypeError – If
new_resource不是資源。 - RuntimeError – 如果
new_resource不是有效資源。 - RuntimeError – 如果
new_resource不能替代old_resource_id。 - ServiceNotFoundError – 如果 Substance 3D Painter 尚未啟動所有服務。
replace_project_resources() 哪個比較有效率。replace_project_resources() 。