导出模块
本模块公开了从项目中将资源(纹理和网格)以多种格式导出的功能。 它相当于“导出纹理”和“导出网格”窗口的脚本编写功能。
对于导出纹理,导出配置是使用JSON 文件定义的,但也可以使用现有的导出预设。
类substance_painter.export.ExportStatus(value) substance_painter.export.ExportStatus
导出过程的状态代码。
成员:
SuccessCancelledWarningError导出纹理
substance_painter.export.list_project_纹理(json_config: dict) -> Dict[元组[str, str], List[str]] substance_painter.export.list_project_textures
获取将根据给定JSON配置导出的纹理的列表。
参数:
json_config (dict) — 表示要使用的导出配置的JSON对象。 请参阅JSON配置。
返回:
将导出的纹理文件的列表,按堆叠(纹理集名称、堆叠名称)分组。
返回类型: Dict[元组[ str, str],列表[ str]]
引发:
- ProjectError — 如果未打开项目。
- ValueError — 如果
json_config格式不正确,或者在当前项目的上下文中无效。 包含人类可读消息。
export_project_textures()。类substance_painter.export.TextureExportResult(状态:导出状态,消息:str,纹理:Dict[元组[str,str],列表[str]]) substance_painter.export.TextureExportResult
导出纹理流程的结果
参数:
- 状态 (导出状态) — 状态代码。
- 消息 (str) — 可读状态消息。
- 纹理 (Dict [ 元组 [ str**, str*] ,* 列表*[ str ]]*) — 已写入磁盘的纹理文件的列表,按堆叠分组(纹理集名称、堆叠名称)。
substance_painter.export.export_project_纹理(json_config: dict) -> TextureExportResult substance_painter.export.export_project_textures
根据给定的JSON配置导出文档纹理。 返回值包含写入磁盘的纹理文件的列表。
返回值的状态不能为“错误”,任何导致导出失败的错误都会引发异常。 但是,如果导出失败,则关联事件ExportTextureEnded将确实收到“错误”作为状态。 如果用户取消导出,则函数返回值的状态将为“已取消”,并包含取消导出之前写入磁盘的纹理文件列表。
参数:
json_config (dict) -
表示要使用的导出配置的JSON对象。 请参阅JSON配置。
返回:导出过程的结果。
返回类型: TextureExportResult
引发:
- ProjectError — 如果未打开项目。
- ValueError — 如果
json_config格式不正确,或者在当前项目的上下文中无效。 包含详述该问题的人可读消息。
示例:
import substance_painter.export
# Open a project we want to export from (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")
# Choose an export preset to use (see substance_painter.resource). This
# step is not mandatory as you can alternatively describe the export
# preset entirely in JSON (see the full example at the bottom of the
# page).
# Note: in this example the preset file format and bit depth are
# overridden below for '03_Base', but otherwise follow the export preset
# configuration.
import substance_painter.resource
export_preset = substance_painter.resource.ResourceID(
context="starter_assets", name="Arnold (AiStandard)")
# Set the details of the export (a comprehensive example of all the
# configuration options is presented at the bottom of the page):
export_config = {
"exportShaderParams": False,
"exportPath": "C:/export",
"defaultExportPreset" : export_preset.url(),
"exportList": [
{
"rootPath": "01_Head"
},
{
"rootPath": "02_Body"
},
{
"rootPath": "03_Base"
}],
"exportParameters": [
# No filters: those parameters apply to all exported maps
{
"parameters": {
"dithering": True,
"paddingAlgorithm": "infinite"
}
},
# Force file format and bitDepth for all maps in '03_Base'
{
"filter": {"dataPaths": ["03_Base"]},
"parameters": {
"fileFormat" : "png",
"bitDepth" : "8"
}
},
# Force 2K size for all maps in '01_Head'
{
"filter": {"dataPaths": ["01_Head"]},
"parameters": {
"sizeLog2": 11
}
}]
}
# Display the list of textures that should be exported, according to the
# configuration:
export_list = substance_painter.export.list_project_textures(export_config)
for k,v in export_list.items():
print("Stack {0}:".format(k))
for to_export in v:
print(to_export)
# Actual export operation:
export_result = substance_painter.export.export_project_textures(export_config)
# In case of error, display a human readable message:
if export_result.status != substance_painter.export.ExportStatus.Success:
print(export_result.message)
# Display the details of what was exported:
for k,v in export_result.textures.items():
print("Stack {0}:".format(k))
for exported in v:
print(exported)
substance_painter.export.get_default_export_path() -> str substance_painter.export.get_default_export_path
获取用于导出纹理的应用程序默认导出路径。 此路径不依赖于项目,是创建新项目时使用的默认值。
返回:应用程序的默认导出路径。
返回类型: str
类substance_painter.export.PredefinedExportPreset(名称:str,url:str) substance_painter.export.PredefinedExportPreset
导出预设(输出模板)控制导出过程的行为。 预定义预设具有根据项目导出的映射的动态列表,并且可具有生成自定义数据(例如glTF)的前/后过程。 此类型的导出预设已嵌入在应用程序中,无法编辑。
示例:
import substance_painter.export
import substance_painter.project
import substance_painter.textureset
# A project needs to be opened to introspect the output maps of a predefined export preset
substance_painter.project.open("C:/projects/MeetMat.spp")
# Retrieve all predefined export presets
predefined_presets = substance_painter.export.list_predefined_export_presets()
# Retrieve data of the first preset
predefined_preset = predefined_presets[0]
print("Name: " + predefined_preset.name + ", url: " + predefined_preset.url)
stack = substance_painter.textureset.get_active_stack()
print(predefined_preset.list_output_maps(stack))
参数:
- 名称 (str) — 预设的名称。
- url (str) — 预设的URL。
list_output_maps(堆叠:堆叠) -> list substance_painter.export.PredefinedExportPreset.list_output_maps
根据给定堆叠上可用的声道获取输出映射的列表。 输出映射的格式与JSON配置中的maps列表相同。
参数: 堆叠 (substance_painter.textureset.堆叠) — 从中获取输出映射的堆叠。
返回:
给定堆叠上可用声道上的输出映射列表。 输出映射的格式与JSON配置中的maps列表相同。 请参阅JSON配置。
返回类型: dict
引发:
- ProjectError — 如果未打开项目。
- ValueError — 如果给定的堆叠无效。
substance_painter.export.list_predefined_export_presets() -> List[PredefinedExportPreset] substance_painter.export.list_predefined_export_presets
获取预定义导出预设(输出模板)的列表。
返回:预定义导出预设的列表。
返回类型:列表[PredefinedExportPreset]
PredefinedExportPreset中的示例类substance_painter.export.ResourceExportPreset(resource_id: ResourceID) substance_painter.export.ResourceExportPreset
导出预设(输出模板)控制导出过程的行为。 工具架导出预设是具有Export substance_painter.resource.Type的资源。 用户可以通过UI修改它。
示例:
import substance_painter.export
import substance_painter.project
substance_painter.project.open("C:/projects/MeetMat.spp")
# Retrieve all resource export presets
resource_presets = substance_painter.export.list_resource_export_presets()
# Retrieve PBR Metalllic Roughness export preset
preset = ""
match = "PBR Metallic Roughness"
for resource_preset in resource_presets :
if resource_preset.resource_id.name == "PBR Metallic Roughness":
print("Name: {}, url: {}".format(
resource_preset.resource_id.name,
resource_preset.resource_id.url()))
preset = resource_preset
break
maps = preset.list_output_maps()
# Add new output map 2D View
maps.append({
'channels': [{
'destChannel': 'R',
'srcChannel': 'R',
'srcMapName': 'View_2D',
'srcMapType': 'virtualMap',
'srcPath': ''
}, {
'destChannel': 'G',
'srcChannel': 'G',
'srcMapName': 'View_2D',
'srcMapType': 'virtualMap',
'srcPath': ''
}, {
'destChannel': 'B',
'srcChannel': 'B',
'srcMapName': 'View_2D',
'srcMapType': 'virtualMap',
'srcPath': ''
}, {
'destChannel': 'A',
'srcChannel': 'A',
'srcMapName': 'View_2D',
'srcMapType': 'virtualMap',
'srcPath': ''
}],
'fileName':
'$mesh_$textureSet_2D_View',
'parameters': {
'bitDepth': '8',
'dithering': False,
'fileFormat': 'png'
}
})
# Create a new preset
newPresetName = "PBR Metallic Roughness 2D View"
newPreset = {
"name": newPresetName,
"maps": maps
}
# Use the preset in the export configuration
export_config = {
"exportShaderParams": False,
"exportPath": "C:/export",
"defaultExportPreset" : newPresetName,
"exportPresets": [newPreset],
"exportList": [
{
"rootPath": "01_Head"
},
{
"rootPath": "02_Body"
},
{
"rootPath": "03_Base"
}],
"exportParameters": [
{
"parameters": {
"dithering": True,
"paddingAlgorithm": "infinite"
}
}]
}
substance_painter.export.export_project_textures(export_config)
参数: 资源_id (资源ID) — 导出预设的资源ID。
substance_painter.resource,创建导出预设。list_output_maps() -> list substance_painter.export.ResourceExportPreset.list_output_maps
获取给定预设的输出映射列表。 输出映射的格式与JSON配置中的maps列表相同。
返回:
给定预设的输出映射列表。 输出映射的格式与JSON配置中的maps列表相同。 请参阅JSON配置。
返回类型: dict
引发: ValueError — 如果给定的预设无效。
substance_painter.export.list_resource_export_presets() -> List[ResourceExportPreset] substance_painter.export.list_resource_export_presets
获取导出预设(输出模板)的列表。 此列表包含工具架中提供的所有导出预设(默认提供的预设和自定义预设(如果有))。
返回:导出预设的列表。
返回类型:列表[ResourceExportPreset]
ResourceExportPreset中的示例完整json_config dict可能性
{
// Path to the root folder where texture files will be exported.
"exportPath": "C:/export",
// Whether to export shader instances to a JSON file.
"exportShaderParams": true,
// (optional) Export preset to be used when no export preset is provided in
// "exportList.exportPreset".
// The value can be the name of a preset defined in the "exportPresets" part
// of the configuration JSON:
"defaultExportPreset": "preset1",
// Alternatively the value can be a URL to an existing preset file (see
// substance_painter.resource) listed in the export dialog:
// "defaultExportPreset" : substance_painter.resource.ResourceID(
// context="starter_assets",
// name="PBR Metallic Roughness").url(),
// (optional) List of export presets definitions.
"exportPresets": [
{
// Defines the name of the export preset. This name can be referenced in
// "defaultExportPreset" and/or "exportList.exportPreset".
"name": "preset1",
// List of maps making up this export preset.
"maps": [
{
// Filename of the texture file written to disk; may contain wildcards
// resolved at export time.
// (e.g. "$project_$mesh_$textureSet_$udim_$sceneMaterial_BaseColor")
//
// $colorSpace: Current color space.
// $mesh: Filename of the imported mesh.
// $project: Project name.
// $sceneMaterial: Current material name, as found in the imported
// mesh.
// $textureSet: Current Texture Set.
// $udim: Current UV Tile (e.g. 1001).
// $uvTileName: Current UV Tile name.
"fileName": "$textureSet_color",
// List of source/destination defining which channels will make up the
// texture file.
"channels": [
{
// Channel to write to.
// L (Luminance), R (Red), G (Green), B (Blue), A (Alpha)
//
// In addition to alpha channel, either R+G+B must be specified, or
// either L only.
"destChannel": "R",
// Channel to read from.
// L, R, G, B, A
//
// When the source map is color, L will generate a mix of R+G+B.
"srcChannel": "R",
// The type of map to read from:
// documentMap: Maps present in the document (e.g. "baseColor").
// meshMap: Baked mesh maps (e.g. "normal").
// virtualMap: Generated map (e.g. "f0").
// defaultMap: Constant color (e.g. "black").
"srcMapType": "documentMap",
// Name of the map of type scrMapType.
//
// For type documentMap:
// basecolor, height, specular, opacity, emissive, displacement,
// glossiness, roughness, anisotropylevel, anisotropyangle,
// transmissive, scattering, reflection, ior, metallic, normal,
// ambientOcclusion, diffuse, specularlevel, blendingmask, user0,
// user1, user2, user3, user4, user5, user6, user7.
//
// For type meshMap:
// ambient_occlusion, id, curvature, normal_base,
// world_space_normals, position, thickness.
//
// For type virtualMap:
// Normal_OpenGL, Normal_DirectX, AO_Mixed, Diffuse, Specular,
// Glossiness, Unity4Diff, Unity4Gloss, reflection, 1/ior,
// Glossiness2, f0, View_2D.
//
// For type defaultMap:
// black, white.
"srcMapName": "baseColor"
}
],
// (optional) Export parameters to be used for this export preset map.
//
// When "parameters" is not provided, the existing parameters are used.
// When "parameters" is provided, it overrides the existing parameters.
//
// Each individual parameter is optional and, when defined, overrides
// previously defined parameters. See in exportList.parameters how the
// rules are applied.
//
// It is important to understand that even though this section is
// optional, if after evaluating all the rules some parameters remain
// undefined, the configuration is invalid.
"parameters": {
// (optional) File format (and file extension) of the generated
// texture file.
"fileFormat": "png",
// (optional) Bit depth.
//
// The bit depth must be supported by the file format.
"bitDepth": "16",
// (optional) Whether to use dithering.
"dithering": False,
// (optional) Size of the texture file in log2.
// (i.e. 10 means 2^10 = 1024)
//
// When "sizeLog2" is not provided, the texture size from the project
// is used.
//
// It can either be a single integer, or an array of two integers.
//
// If it's a single integer, it represents the biggest of width and
// height, and will maintain the aspect ratio.
// (i.e. 10 means a 2048x4086 map will be exported as 512x1024)
//
// If it's an array of two integers, the original aspect ratio will be
// ignored.
// (i.e. [10, 12] means a 2048x4086 map will be exported as 1024x4096)
"sizeLog2": 10,
// (optional) Padding algorithm used to fill holes in rendered
// texture.
//
// The possible values are:
// passthrough, color, transparent, diffusion, infinite.
"paddingAlgorithm": "diffusion",
// (optional) When padding algorithm needs it, distance in pixels used
// by the padding algorithm.
//
// Dilation distance is needed for transparent, color and diffusion
// padding algorithms.
"dilationDistance": 16
}
}
]
}
],
// List of subparts of the document to export.
"exportList": [
{
// Root path of the document structure this subpart applies to.
//
// For Texture Sets without stacks, this is a Texture Set name.
// (e.g. "O1_Head")
// For Texture Sets with stacks, this is Texture Set name + stack name
// separated by /
"rootPath": "02_Body/Mask",
// (optional) In the selected rootPath, which maps to export.
//
// When "filter" is not provided, export everything.
"filter": {
// Which maps to export, as an array of map names.
//
// The map names are to be used as defined in
// exportPresets.maps.fileName, including wildcards.
// (e.g. ["$textureSet_color", "$textureSet_normal"])
"outputMaps": [
"$textureSet_color"
],
// Which UV Tiles to export, as an array of tile coordinates.
// A tile coordinate is a 2 dimensional array of U and V coordinates.
// (e.g. [[1, 1], [1, 2]] to export tiles U=1, V=1 and U=1, V=2)
"uvTiles": [
[
1,
1
]
]
},
// (optional) Export preset to use. If undefined, fall back to
// "defaultExportPreset" value.
// The value can be the name of a preset defined in "exportPresets":
"exportPreset": "preset1"
// Alternatively the value can be a URL to an existing preset file (see
// substance_painter.resource) listed in the export dialog:
// "defaultExportPreset" : substance_painter.resource.ResourceID(
// context="starter_assets",
// name="PBR Metallic Roughness").url(),
}
],
// List of rules used to override export parameters of texture files.
//
// For each exported texture file, the export process will go through this
// list, in the order they are provided, to override export parameters.
// Available export parameters are:
// fileFormat, bitDepth, dithering, sizeLog2, paddingAlgorithm and
// dilationDistance.
// (see exportPresets.map.parameters)
//
// For each possible export parameter of each texture file:
// First, the parameter is initialized with the value provided by the
// exportPreset.maps.parameters, if any.
// Then, the export process iterates the rules of exportParameters and tries
// to match the texture file with the filter.
// If the filter matches, the parameter is overridden by this rule, else it
// stays untouched.
//
// At the end of the process, every parameter of every texture file must be
// defined for the export process to be able to continue.
// To achieve this, a good practice may be to define a default value for all
// the parameters:
// - For each preset map
// - With a global exportParameters rule using a filter that always matches
"exportParameters": [
{
// (optional) Select which texture files match the current rule.
// (i.e. for which texture files this rule will override parameters)
//
// When "filter" is not provided, select everything.
//
// Examples:
// Filter that matches all:
// "filter" : {}
//
// Filter that matches some Texture Sets:
// "filter" : {"dataPaths": ["01_Head", "02_Body"]}
//
// Filter that matches some outputMaps:
// "filter" : {"outputMaps": ["$textureSet_color"]}
//
// Filter that matches nothing:
// "filter" : {"dataPaths": []}
//
// Use of a combined filter to match a Texture Set for some
// outputMaps:
// "filter" : {"dataPaths": ["01_Head"],
// "outputMaps" : ["$textureSet_color"]}
"filter": {
// List of rootPaths to match.
//
// This can be a mix of:
// - Texture Set names only, even for Texture Sets with stacks
// - Stack names, when stacks are used
"dataPaths": [
"01_Head",
"02_Body/Mask"
],
// List of map names to match.
//
// The map names are to be used as defined in "exportPresets.maps.fileName",
// including wildcards.
"outputMaps": [
"$textureSet_color"
],
// List of UV Tiles to match, as an array of tile coordinates.
// A tile coordinate is a 2 dimensional array of U and V coordinates.
// (e.g. [[1, 1], [1, 2]] to export tiles U=1, V=1 and U=1, V=2)
"uvTiles": [
[
1,
1
]
]
},
// (optional) Parameters to apply to the matched texture files as per the
// current rule.
//
// When "parameters" is not provided, the existing parameters are used.
// When "parameters" is provided, it overrides the existing parameters.
//
// Each individual parameter is optional and, when defined, overrides
// previously defined parameters (coming from the selected preset).
//
// It is important to understand that even though this section is
// optional, if after evaluating all the rules some parameters remain
// undefined, the configuration is invalid.
//
// In this example, we're setting a different texture size for the color
// map of both 01_Head and 02_Body/Mask, leaving settings on maps and
// other data paths, and leaving the other parameters untouched.
"parameters": {
"sizeLog2": 11
}
}
]
}
活动
导出纹理(无论通过Python API启动还是在UI中启动)可能会触发以下事件。 有关更多详细信息,请参阅substance_painter.event。
类substance_painter.event.ExportTexturesAboutToStart(纹理: Dict[Tuple[str, str], List[str]])
纹理在导出前触发。
参数:
纹理 (Dict [ 元组 [ str**, str*] ,* 列表*[ str ]]*) — 要写入磁盘的纹理文件的列表,按堆叠分组(纹理集名称、堆叠名称)。
类substance_painter.event.ExportTexturesEnded(状态:导出状态,消息:str,纹理:Dict[元组[str,str],列表[str]])
纹理导出完成后触发的事件。
参数:
- 状态 (导出状态) — 状态代码。
- 消息 (str) — 可读状态消息。
- 纹理 (Dict [ 元组 [ str**, str*] ,* 列表*[ str ]]*) — 已写入磁盘的纹理文件的列表,按堆叠分组(纹理集名称、堆叠名称)。
导出网格
substance_painter.export.场景_is_triangulated() -> bool substance_painter.export.scene_is_triangulated
检查场景是否只有三角形(只有三边的多边形)。
如果当前场景仅包含三角形,则返回: True,否则返回False。
返回类型: bool
引发: ProjectError — 如果未打开项目。
substance_painter.export.场景_has_曲面细分() -> bool substance_painter.export.scene_has_tessellation
检查场景是否启用了位移/曲面细分。
如果当前场景具有位移/曲面细分,则返回: True,否则返回False。
返回类型: bool
引发: ProjectError — 如果未打开项目。
类substance_painter.export.MeshExportOption(value) substance_painter.export.MeshExportOption
可用于网格导出的选项。
成员:
BaseMeshTriangulatedMeshTessellationNormalsBaseMeshTessellationRecomputeNormals类substance_painter.export.MeshExportResult(状态:ExportStatus,消息:str) substance_painter.export.MeshExportResult
导出网格流程的结果
参数:
- 状态 (导出状态) — 状态代码。
- 消息 (str) — 可读状态消息。
substance_painter.export.export_path(file_网格:str,选项:MeshExportOption) -> MeshExportResult substance_painter.export.export_mesh
将当前网格导出为给定文件路径。
参数:
- file_path (string) — 导出网格的完整文件路径。 文件格式由扩展名推导。 支持的扩展包括:
.usd、.obj、.fbx、.dae、.ply、.gltf。 - 选项 (MeshExportOption) — 要使用的导出选项。
返回:导出过程的结果。
返回类型: MeshExportResult
引发:
- ProjectError — 如果未打开项目。
- ValueError — 如果
file_path或option在当前项目的上下文中无效。 包含详述该问题的人可读消息。
示例:
import substance_painter.export
# Open a project we want to export from (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")
# Choose an export option to use
export_option = substance_painter.export.MeshExportOption.BaseMesh
if not substance_painter.export.scene_is_triangulated():
export_option = substance_painter.export.MeshExportOption.TriangulatedMesh
if substance_painter.export.scene_has_tessellation():
export_option = substance_painter.export.MeshExportOption.TessellationNormalsBaseMesh
# Actual export mesh operation:
filename = "C:/projects/MeetMat.obj"
export_result = substance_painter.export.export_mesh(filename, export_option)
# In case of error, display a human readable message:
if export_result.status != substance_painter.export.ExportStatus.Success:
print(export_result.message)
substance_painter.project,导出文档。