资源模块
通过此模块,可操作Substance 3D Painter资源和工具架。
Substance 3D Painter将纹理、材料、画笔等视为资源,并使用URL进行识别。 资源可以在工具架中,也可以直接嵌入在项目中(例如,烘焙ambient occlusion纹理)。
类substance_painter.resource.Type(value) substance_painter.resource.Type
描述给定资源的类型的枚举。
成员:
ABR_PACKAGEBRUSHEXPORTFONTIMAGEPRESETRESOURCESCRIPTSHADERSMART_MASKSMART_MATERIALSUBSTANCESUBSTANCE_PACKAGEVECTORIAL类substance_painter.resource.UpdateProjectError(old_resource_id: ResourceID, new_resource_id: ResourceID,详细信息: List[str]) substance_painter.resource.UpdateProjectError
replace_project_resources()操作期间出错。
参数:
- old_id — 无法更新的资源的标识符。
- new_id — 应替换旧资源的资源标识符。
- 详细信息 (列表 [ 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。 可以直接对其进行操作,而不保证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)))
Importing resources
新资源可以导入到具有import_project_resource()的当前项目、具有import_session_resource()的当前会话或具有Shelf.import_resource()的工具架。 所有三个函数都采用要导入的资源的路径、Usage指明该资源的类型,以及名称和组(可选)。 此功能对应于“导入资源”窗口。
资源可以导入到工具架中,只要它不是只读工具架。 沿应用程序安装的工具架是只读的。 如果工具架在文件系统上的路径是只读的,则该路径也是只读的。 可与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会保留文件副本以便能够处理该文件。
通过重新加载资源,将再次导入原始文件,并在工具架、会话或项目中更新该资源。 请注意,这不会更新项目文档中当前使用的资源(layerstack、着色器、env map等)。 若要更新项目文档中当前使用的资源,请通过调用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资源。
参数: 句柄 (_substance_painter.resource.ResourceHandle)
标识符() ->资源ID substance_painter.resource.Resource.identifier
获取此资源标识符。
返回:资源标识符。
返回类型: ResourceID
引发: RuntimeError — 如果资源无效。
ResourceID。location() -> ResourceLocation substance_painter.resource.Resource.location
获取此资源的位置。
返回:此资源的位置。
返回类型: ResourceLocation
引发: RuntimeError — 如果资源无效。
静态检索(标识符:资源ID) substance_painter.resource.Resource.retrieve
检索与给定标识符匹配的资源的列表。
参数: 标识符 (ResourceID) — 资源标识符。
引发:
- ValueError — 如果标识符的名称为空或标识符的上下文不存在。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
返回:
与给定标识符匹配的资源的列表。 如果标识符具有有效版本,此方法将仅返回一个或零个资源,否则列表可能包含多个资源。 如果返回多个资源,则最新资源将位于列表的开头。
返回类型: 列表[资源]
set_custom_preview(preview_image: str) -> None substance_painter.resource.Resource.set_custom_preview
将此资源的当前预览替换为自定义图像。
参数:
preview_image (str) — 磁盘上用作新预览的图像的文件路径。
引发:
- ValueError — 如果无法修改资源元数据。
- ValueError — 如果
preview_image不是有效图像的有效路径。 - ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
返回类型:无
category() -> str substance_painter.resource.Resource.category
获取此资源的类别,例如:材料的“wood”。
引发: RuntimeError — 如果资源无效。
返回:此资源的类别
返回类型: str
usages() ->列出[用法] substance_painter.resource.Resource.usages
获取此资源的使用情况。
引发: RuntimeError — 如果资源无效。
返回:此资源的使用情况
返回类型: 列表[用法]
Usagegui_name() -> str substance_painter.resource.Resource.gui_name
获取此资源的GUI名称。
引发: RuntimeError — 如果资源无效。
返回:此资源的GUI名称
返回类型: str
type() -> Type substance_painter.resource.Resource.type
获取此资源的类型。
引发: RuntimeError — 如果资源无效。
返回:此资源的类型
返回类型: 类型
Type标记() ->列表[str] substance_painter.resource.Resource.tags
获取此资源的标记。
引发: RuntimeError — 如果资源无效。
返回:此资源的标记
返回类型: 列表[ str]
internal_properties() -> dict substance_painter.resource.Resource.internal_properties
获取资源内部属性的词典。 目前的实现仅提取Substance资源的元数据。
引发: RuntimeError — 如果资源无效。
返回:包含有关此资源的内部属性的词典
返回类型: dict
children() ->列表[资源] substance_painter.resource.Resource.children
获取子资源。 例如,Substance包的Substance图形。
引发: RuntimeError — 如果资源无效。
返回:此资源中包含的资源。
返回类型: 列表[资源]
parent() ->资源 |无 substance_painter.resource.Resource.parent
获取父资源。 例如,Substance图形源自的Substance包。
引发: 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尚未启动其所有服务。
返回类型:无
show_resources_in_ui()。类substance_painter.resource.ResourceID(上下文:str,名称:str,版本:str |无=无) substance_painter.resource.ResourceID
Substance 3D Painter资源标识符。
资源由上下文、名称和版本标识。 上下文和名称是必需的,而版本是可选的。 版本是一个看起来像哈希的字符串,可能还包含扩展名。
substance_painter.display。参数:
- 上下文 (str)
- 名称 (str)
- 版本 (str)
classmethod from_project(名称:str,版本:str) |无=无) substance_painter.resource.ResourceID.from_project
为位于当前项目中的资源创建ResourceID对象。
参数:
- 名称 (str) — 资源名称。
- 版本 (str*,* 可选) — 资源版本(类似哈希的字符串)。
返回:与给定名称对应的资源。
返回类型: ResourceID
classmethod from_session(名称:str,版本:str) |无=无) substance_painter.resource.ResourceID.from_session
为位于当前会话中的资源创建ResourceID对象。
参数:
- 名称 (str) — 资源名称。
- 版本 (str*,* 可选) — 资源版本(类似哈希的字符串)。
返回:与给定名称对应的资源。
返回类型: ResourceID
classmethod from_url(url: str) substance_painter.resource.ResourceID.from_url
通过其URL创建ResourceID对象。 URL必须将resource://作为方案。 版本被编码为查询字符串,看起来像哈希。
资源URL如下所示:
resource://context/name?version=0123456789abcdef0123456789abcdef01234567.image
参数: url (str) — 资源URL。
返回:与给定URL对应的资源。
返回类型: ResourceID
引发:
- ValueError — 如果
url不是有效的URL。 - ValueError — 如果URL方案不是
resource://。 - ValueError — 如果资源名称无效。
location() -> ResourceLocation substance_painter.resource.ResourceID.location
获取此ResourceID的位置。
返回:此资源的位置。
返回类型: ResourceLocation
url() -> str substance_painter.resource.ResourceID.url
获取此ResourceID的URL表单。
返回:资源的URL。
返回类型: str
引发:
- ValueError — 如果ResourceID没有上下文。
- ValueError — 如果ResourceID没有名称。
上下文: str substance_painter.resource.ResourceID.context
资源的上下文。
类型: str
名称:str substance_painter.resource.ResourceID.name
资源的名称。
类型: str
版本: str =无 substance_painter.resource.ResourceID.version
标识资源版本的哈希。
类型: str
类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())
类substance_painter.resource.StandardQuery substance_painter.resource.StandardQuery
标准资源查询。
成员:
ALL_RESOURCESPROJECT_RESOURCESSESSION_RESOURCESSHELVES_RESOURCESsearch()。类substance_painter.resource.Usage(value) substance_painter.resource.Usage
描述应该如何使用给定资源的枚举。
成员:
ALPHABASE_MATERIALBRUSHCOLOR_LUTEMITTERENVIRONMENTEXPORTFILTERFONTGENERATORPARTICLEPROCEDURALRECEIVERSHADERSMART_MASKSMART_MATERIALTEXTURETOOLsubstance_painter.resource.search(query: str) -> List[资源] substance_painter.resource.search
列出与给定查询匹配的Substance 3D Painter资源。
参数: 查询 (str) — 资源查询字符串。 请参阅文本查询文档。
返回:与给定查询匹配的资源列表。
返回类型:列表[资源]
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
StandardQuery。substance_painter.resource.list_project_resources() -> List[ResourceID] substance_painter.resource.list_project_resources
列出当前项目中使用的资源。 项目资源是指项目中使用的所有资源(在图层栈栈、着色器、环境图等)。
返回:资源标识符的列表。
返回类型:列表[ResourceID]
引发:
- ProjectError — 如果未打开项目。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
replace_project_resources()。substance_painter.resource.list_project_outdated_resources() -> Dict[ResourceID,ResourceID] substance_painter.resource.list_project_outdated_resources
列出当前项目中使用的已过时的资源。 项目资源是指项目中使用的所有资源(在图层栈栈、着色器、环境图等)。 过期资源是指已在应用程序中重新加载,但尚未在项目中更新的资源。
返回:
使用旧资源标识符作为关键字,使用新资源标识符作为值的词典。
返回类型: Dict[ResourceID,ResourceID]
引发:
- ProjectError — 如果未打开项目。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
replace_project_resources()。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 *]) — 要更新的资源标识符的词典(键:旧,值:新)。 词典必须包含有效的
ResourceID。 如果任何资源标识符无效,或者键与项目中的现有资源不对应,则操作将失败。 如果字典为空,则不执行任何操作。 - allow_parameters_mismatch (bool*,* 可选) — 默认情况下(
False),如果已在新版本中重命名或删除了参数,则将阻止更新项目中使用的带有参数的资源(例如.sbsar、.ai文件),以避免对纹理结果做出意外更改。 如果检测到任何参数不匹配,操作将失败。 如果True,任何不匹配的参数都将重置为默认值。
返回:操作的结果。
返回类型: UpdateProjectResult
引发:
- ProjectError — 如果未打开项目。
- RuntimeError — 如果应用程序不在绘画模式下。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
类substance_painter.resource.UpdateProjectResult(status: UpdateProjectStatus, errors: List[UpdateProjectError]) substance_painter.resource.UpdateProjectResult
replace_project_resources()操作的结果。
参数:
- 状态 (UpdateProjectStatus) — 操作的状态。
- 错误 (列表*[*UpdateProjectError *]*) — 如果操作失败,则显示错误列表。 如果操作成功,则此列表为空。
类substance_painter.resource.UpdateProjectStatus(value) substance_painter.resource.UpdateProjectStatus
replace_project_resources()操作的状态。
成员:
SUCCESSERRORsubstance_painter.resource.import_project_resource(file_path: str, resource_usage:用法,名称: str |无=无,组:str |无=无) ->资源 substance_painter.resource.import_project_resource
将资源导入到当前打开的项目。
参数:
- file_path (str) — 要导入的资源的文件路径。
- 资源_usage (使用情况) — 资源使用情况。
- 名称 (str*,* 可选) — 资源的名称(如果与文件名不同)。
- 组 (str*,* 可选) — 可选的组名,可用于资源查询。
返回:导入的资源对象。
返回类型: 资源
引发:
- ProjectError — 如果未打开项目。
- ValueError — 参数验证失败。
- 运行时错误 — 如果导入失败。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
substance_painter.resource.import_session_resource(file_path: str, resource_usage:用法,名称: str |无=无,组:str |无=无) ->资源 substance_painter.resource.import_session_resource
将资源导入当前会话。
参数:
- file_path (str) — 要导入的资源的文件路径。
- 资源_usage (使用情况) — 资源使用情况。
- 名称 (str*,* 可选) — 资源的名称(如果与文件名不同)。
- 组 (str*,* 可选) — 可选的组名,可用于资源查询。
返回:导入的资源对象。
返回类型: 资源
引发:
- ValueError — 参数验证失败。
- 运行时错误 — 如果导入失败。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
substance_painter.resource.show_resources_in_ui(resources: List[资源]) -> None substance_painter.resource.show_resources_in_ui
在应用程序工具架UI(“资源”窗口)中突出显示资源列表。
参数: 资源 (列表*[资源]*) — 要突出显示的资源
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
返回类型:无
Resource.show_in_ui()。substance_painter.resource.is_reload_modified_resources_running() -> bool substance_painter.resource.is_reload_modified_resources_running
检查重新加载修改的资源操作当前是否正在运行。
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
返回类型: bool
substance_painter.resource.reload_modified_resources_async(resource_filter: AllResourcesFilter |项目过滤器 | ResourcesListFilter | ResourcesUsedByProjectFilter |会话过滤器 | 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 — 给定筛选器的格式不正确(例如,指向不存在的资源)时。 异常为每个问题提供一条消息,作为List[str]
重新加载过滤器
类substance_painter.resource.AllResourcesFilter substance_painter.resource.AllResourcesFilter
用于重新加载Substance 3D Painter已知的所有已修改资源的过滤器,其中包括所有工具架中的资源、会话范围的资源和项目范围的资源。
类substance_painter.resource.ProjectFilter substance_painter.resource.ProjectFilter
用于重新加载项目上下文中包含的已修改资源的过滤器。 这不包括项目使用的资源(在图层栈栈、着色器、环境图等) 它们是否包含在工具架或会话中。
类substance_painter.resource.ResourcesListFilter(resources: List[ResourceID]) substance_painter.resource.ResourcesListFilter
用于在给定的资源列表中重新加载修改过的资源的过滤器。
参数: 资源 (列表*[*ResourceID *]*) — 要重新加载的资源列表。
类substance_painter.resource.ResourcesUsedByProjectFilter substance_painter.resource.ResourcesUsedByProjectFilter
用于重新加载项目当前正在使用的已修改资源的筛选器。 这包括来自任何上下文(项目、工具架、会话)的资源,只要它们当前被项目引用。
类substance_painter.resource.SessionFilter substance_painter.resource.SessionFilter
用于重新加载会话中包含的已修改资源的过滤器。
类substance_painter.resource.ShelvesListFilter(工具架: List[工具架]) substance_painter.resource.ShelvesListFilter
用于重新加载指定工具架中包含的已修改资源的过滤器。
参数: 工具架 (列表*[工具架]*) — 要重新加载的工具架列表。
工具架
另请参阅:
: 配置工具架。
类substance_painter.resource.工具架(_name: str) substance_painter.resource.Shelf
提供有关给定工具架的信息的类。 货架由唯一名称标识。
参数: _name (str)
can_import_resources() -> bool substance_painter.resource.Shelf.can_import_resources
检查是否可以将资源导入此托架。 资源可以导入到工具架中,只要它不是只读工具架。 沿应用程序安装的工具架是只读的。 如果工具架在文件系统上的路径是只读的,则该路径也是只读的。
如果可以导入资源,则返回: True。
返回类型: bool
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
import_resource(file_path: str, resource_usage: Usage, name: str |无=无,组:str |无=无,uuid: str |无=无) ->资源 substance_painter.resource.Shelf.import_resource
将资源导入此工具架。
参数:
- file_path (str) — 要导入的资源的文件路径。
- 资源_usage (使用情况) — 资源使用情况。
- 名称 (str*,* 可选) — 资源的名称(如果与文件名不同)。
- 组 (str*,* 可选) — 可选的组名,可用于资源查询。
- uuid (str*,* 可选) — 可选uuid。 如果已存在具有相同UUID的资源,则将替换该资源。
返回:导入的资源对象。
返回类型: 资源
引发:
- ValueError — 参数验证失败。
- 运行时错误 — 如果导入失败。
- 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
返回:
工具架名称。 每个工具架都由唯一名称标识。
返回类型: str
path() -> str substance_painter.resource.Shelf.path
返回:关联的路径
引发:
- ValueError — 如果工具架不再存在。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
返回类型: str
refresh() substance_painter.resource.Shelf.refresh
强制发现工具架文件夹中的资源。 当应用程序窗口成为焦点时,发现功能也会自动完成。
引发: ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
资源(查询: str = ") ->列表[资源] substance_painter.resource.Shelf.resources
获取此工具架中包含的资源。 可以提供可选的查询字符串以缩小结果范围。
参数: 查询 (str*,* 可选) — 资源查询字符串。
返回:此工具架的资源列表。
返回类型: 列表[资源]
search()。类substance_painter.resource.工具架 substance_painter.resource.Shelves
用于处理工具架的静态方法的集合。
静态add(name: str, path: str) ->工具架 substance_painter.resource.Shelves.add
添加新工具架。 此工具架仅在应用会话期间有效。 该工具架将不会从应用程序常规设置菜单中显示。
参数:
- 名称 (str) — 新工具架的名称。 此名称必须是唯一的,并且只能包含小写字母、数字、下划线或连字符。 使用
Shelves.exists()检查名称是否已被使用。 - 路径 (str) — 要监视的文件夹路径。
返回:新添加的工具架。
返回类型: 工具架
引发:
- ValueError — 如果
name或str无效。 有关详细信息,请参阅日志。 - ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
Shelves.exists()。 Shelf.refresh().static all() -> List[工具架] substance_painter.resource.Shelves.all
列出所有工具架。
返回:现有工具架的列表。
返回类型: 列表[工具架]
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
static application_application() ->工具架 substance_painter.resource.Shelves.application_shelf
这是包含应用程序附带的默认内容的工具架。
返回类型: 工具架
static exists(name: str) -> bool substance_painter.resource.Shelves.exists
指示是否存在具有给定名称的工具架。
参数: 名称 (str) — 要搜索的名称工具架。
如果具有给定名称的工具架存在,则返回: True。
返回类型: bool
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
static refresh_all() substance_painter.resource.Shelves.refresh_all
强制发现所有工具架文件夹中的资源。 当应用程序窗口成为焦点时,发现功能也会自动完成。
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
Shelf.refresh()。static remove(name: str) substance_painter.resource.Shelves.remove
删除工具架。 不能打开任何项目。 无法删除不是由Python API创建的工具架,并将引发异常。
参数:
名称 (str) — 要删除的工具架的名称。 使用Shelves.exists()检查工具架是否存在。
引发:
- ProjectError — 如果项目已打开。
- ValueError — 如果工具架不存在。
- ValueError — 如果不是使用Python API创建工具架。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
Shelves.exists()。static user_user() ->工具架 substance_painter.resource.Shelves.user_shelf
这是位于user Documents文件夹中的工具架,默认情况下,会在其中创建新资源。 用户可以在设置中选择其他默认工具架,此功能将在使用时反映出来。
引发:
ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
返回类型: 工具架
已弃用
以下函数已弃用,保留它们是为了提供可追溯兼容性,不应在新代码中使用。
substance_painter.resource.list_layer_resources() -> List[ResourceID] substance_painter.resource.list_layer_stack_resources
列出当前项目的图层堆叠和网格图引用的资源。
返回:引用的资源标识符列表。
返回类型:列表[ResourceID]
引发:
- ProjectError — 如果未打开项目。
- ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
list_project_resources()。substance_painter.resource.update_layer_resource_resource(old_resource_id: ResourceID, new_resource: Resource) -> List[ResourceID] substance_painter.resource.update_layer_stack_resource
替换当前项目中图层堆叠和网格图的资源。
给定资源标识符,用新资源替换任何具有相同标识符的资源。 新资源必须与其所替换的资源兼容(请参见注意);否则,将引发错误。
- 如果资源是材料,则必须具有相同的输出数量和名称。
- 如果资源是Substance筛选器,则其输入和输出的数量和名称必须相同。
返回:
已替换的所有资源的标识符列表。
返回类型:列表[ResourceID]
参数:
- old_resource_id (ResourceID) — 要更新的资源的标识符。
- new_resource (资源) — 要改用的新资源。
引发:
- ProjectError — 如果未打开项目。
- TypeError — 如果
old_resource_id不是资源ID。 - TypeError — 如果
new_resource不是资源。 - RuntimeError — 如果
new_resource不是有效的资源。 - RuntimeError — 如果无法使用
new_resource代替old_resource_id。 - ServiceNotFoundError — 如果Substance 3D Painter尚未启动其所有服务。
replace_project_resources(),这样效率更高。replace_project_resources()。