Retexture API
根据文本 prompt 或参考图片,为现有的 3D 模型生成新的纹理。该模型可以来自另一个 Meshy 任务,也可以来自模型文件。
创建 Retexture 任务
创建一个 Retexture 任务。该任务在后台运行。关于任务通常需要多长时间,请参阅处理时间。
Request
# Retexture with text prompt
curl https://api.meshy.ai/openapi/v1/retexture \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"model_url": "https://cdn.meshy.ai/model/example_model_2.glb",
"text_style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
"enable_original_uv": true,
"enable_pbr": true
}'
# Retexture with image style and PBR
curl https://api.meshy.ai/openapi/v1/retexture \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"model_url": "https://cdn.meshy.ai/model/example_model_2.glb",
"image_style_url": "<your publicly accessible image url or base64-encoded data URI>",
"ai_model": "latest",
"enable_pbr": true,
"enable_original_uv": true
}'
Response
{
"result": "018a210d-8ba4-705c-b111-1f1776f7f578"
}
参数
- Name
- input_task_id
- Type
- string
- 必选
- Description
除非你发送
model_url,否则为必填项。生成了待贴图 3D 模型的任务 ID,例如 Text to 3D、Image to 3D、Remesh 或 Retexture 任务。该任务必须是你通过 API 创建、且状态为SUCCEEDED的任务。Meshy 会为该任务的 GLB 生成贴图。
- Name
- model_url
- Type
- string
- 必选
- Description
除非你发送
input_task_id,否则为必填项。要贴图的模型,可以是公开 URL 或 data URI。如果两者都发送,Meshy 会使用input_task_id。该模型必须是 GLB、glTF、OBJ、FBX 或 STL 文件,来自
http或httpsURL 时最大为 400 MB,作为 data URI 时最大为 100 MB。对于 data URI,请使用 MIME typeapplication/octet-stream,例如data:application/octet-stream;base64,<你的 base64 编码模型数据>。超过 100 MB 的文件还必须遵循以下规则:
- GLB、glTF、FBX 或 OBJ 文件最多可有 10,000,000 个面。Meshy 以三角形计算面数,因此一个四边形算作 2 个面,重复绘制的 mesh 每个副本算一次。
- FBX 文件必须是 7.1 或更新版本的二进制 FBX。
- GLB 或 glTF 文件不得使用 Draco 压缩。
请发送以下三种风格输入之一。
- Name
- text_style_prompt
- Type
- string
- 必选
- Description
除非你发送
image_style_url或multiview_image_urls,否则为必填项。描述你想要的贴图的文本,最多 800 个字符。更长的文本会返回400。
- Name
- image_style_url
- Type
- string
- 必选
- Description
除非你发送
text_style_prompt或multiview_image_urls,否则为必填项。贴图将遵循其风格的 2D 图像,可以是公开 URL 或 data URI(data:image/jpeg;base64,<你的 base64 编码图像数据>)。如果你同时发送text_style_prompt和image_style_url,Meshy 会使用image_style_url。该图像必须是
.jpg、.jpeg、.png或.webp文件,最大为 20 MB。当图像中的物体形状与模型相差很大时,贴图可能不太合适。
- Name
- multiview_image_urls
- Type
- string[]
- 必选
- Description
除非你发送
text_style_prompt或image_style_url,否则为必填项。来自同一物体不同视角的一到四张图像。第一张图像为主视图(正面)。其他视图(左、后、右)的顺序不限。空数组或超过四张图像会返回400。每张图像遵循与
image_style_url相同的格式和大小规则,每张图像最大 20 MB。你不能将multiview_image_urls与text_style_prompt或image_style_url一起使用。multiview_image_urls需要显式指定"ai_model": "meshy-7"。使用任何其他ai_model(包括默认值latest)都会返回400。
- Name
- ai_model
- Type
- string
- 默认值 latest
- Description
用于生成贴图的 AI 模型。
可用值:
meshy-6-litemeshy-6meshy-7latest:Meshy 7
- Name
- enable_original_uv
- Type
- boolean
- 默认值 false
- Description
是否保留模型原有的 UV 布局,而不是生成新的布局。
- 对于 Meshy 生成的模型(来自
input_task_id或指向 Meshy 输出的model_url),使用true以复用其优化后的 UV 布局。 - 对于你从别处上传的模型,如果其 UV 已经很好,使用
true来保留它。保持为false则让 Meshy 生成新的 UV,适用于没有适当 UV 映射的模型。
- 对于 Meshy 生成的模型(来自
- Name
- enable_pbr
- Type
- boolean
- 默认值 false
- Description
是否在生成基础色之外还生成 PBR 贴图(金属度、粗糙度和法线)。使用
meshy-6时,Meshy 还会生成一张自发光贴图,但texture_resolution为8k时除外。meshy-6-lite、meshy-7和latest不生成自发光贴图。
- Name
- texture_resolution
- Type
- string
- 默认值 2k
- Description
基础色贴图的大小。分辨率越高,捕捉到的表面细节越多。
可用值:
2k:2048 × 2048 像素4k:4096 × 4096 像素8k:8192 × 8192 像素
4k和8k需要ai_model为meshy-6、meshy-7或latest。使用meshy-6-lite时会返回400。在8k下,Meshy 不生成自发光贴图。
- Name
- hd_texture
- Type
- boolean
- ⚠ 已弃用
- 默认值 false
- Description
请改用
texture_resolution。true等同于texture_resolution: "4k"。如果两者都发送,Meshy 会使用texture_resolution。
- Name
- remove_lighting
- Type
- boolean
- 默认值 true
- Description
是否从基础色贴图中移除高光和阴影。此结果在你自己的光照下效果更好。
Meshy 仅在使用
meshy-6,且texture_resolution为2k或4k时应用该设置。使用meshy-7或latest,或在8k下,Meshy 会接受该参数但忽略它。使用meshy-6-lite时,发送该参数(无论何值)都会返回400。
- Name
- target_formats
- Type
- string[]
- Description
要生成的文件格式。Meshy 只会生成你列出的格式,这可以缩短任务时间。如果省略此项,Meshy 会生成除
3mf以外的所有格式。可用值:
glbobjfbxstlusdz3mf
- Name
- alpha_thumbnail
- Type
- boolean
- 默认值 false
- Description
是否同时渲染一张带透明背景(RGBA)的预览图,会在获取任务时通过
alpha_thumbnail_url返回。thumbnail_url不会改变。
返回值
响应的 result 字段保存新 Retexture 任务的 ID。
失败模式
- Name
400 - Bad Request- Description
请求无法运行。错误消息会说明发现的问题。例如:
- 缺少参数:既没有发送
model_url也没有发送input_task_id。 - 缺少风格:
text_style_prompt、image_style_url和multiview_image_urls均未发送。 - 风格输入冲突:
multiview_image_urls与text_style_prompt或image_style_url一起发送。 - 多视图不支持该模型:发送了
multiview_image_urls,但未显式指定"ai_model": "meshy-7"。 - 输入任务无效:
input_task_id不是受支持类型的成功任务。 - 模型格式无效:
model_url文件的扩展名不受支持。 - URL 无法访问:Meshy 无法下载
model_url文件、image_style_url图像或某个multiview_image_urls图像。 - 模型文件过大:
model_url文件来自http或httpsURL 时超过 400 MB,或作为 data URI 时超过 100 MB。 - 面数过多:
model_url文件超过 100 MB,且面数超过 10,000,000。请减少面数后重新发送文件。 - ASCII FBX 超过 100 MB:
model_url文件是超过 100 MB 的 ASCII FBX。请以二进制 FBX 或 GLB 格式发送。 - 模型文件不可读:
model_url文件超过 100 MB,且 Meshy 无法读取其头部信息。例如,它是经过 Draco 压缩的 GLB 或 glTF,或是早于 7.1 版本的二进制 FBX。 - 模型头部信息过于复杂:
model_url文件超过 100 MB,且其头部信息中要检查的 mesh、节点或记录过多。请减少文件中的对象数量后重新发送。 - 图像过大:
image_style_url图像或某个multiview_image_urls图像超过 20 MB。
请修正请求后重新发送。参阅 Errors。
- 缺少参数:既没有发送
- Name
401 - Unauthorized- Description
API key 缺失或无效。请检查
Authorization请求头。
- Name
402 - Payment Required- Description
例如:
- 积分不足:账户没有足够的积分来执行此任务,或账户已达到积分限额。请检查你的积分 balance,然后重试。
- 免费方案:创建任务需要付费方案。请在你的subscription 设置中升级方案,然后重试。
- Name
403 - Forbidden- Description
input_task_id是一个浮雕模型,此 endpoint 无法对其进行 Retexture。消息为This model type does not support this operation。请发送其他模型。
- Name
404 - Not Found- Description
input_task_id与你的任何任务都不匹配。请检查任务 ID,然后重新发送请求。
- Name
429 - Too Many Requests- Description
你已超出速率限制。请稍候后重试。参阅速率限制。
获取 Retexture 任务
根据 ID 返回一个 Retexture 任务。
Request
curl https://api.meshy.ai/openapi/v1/retexture/018a210d-8ba4-705c-b111-1f1776f7f578 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "retexture",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
"fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
"obj": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.obj?Expires=***",
"usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***",
"mtl": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.mtl?Expires=***",
"stl": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.stl?Expires=***"
},
"thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
"text_style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
"texture_image_url": "",
"progress": 100,
"started_at": 1692771667037,
"created_at": 1692771650657,
"expires_at": 1692771679037,
"finished_at": 1692771669037,
"status": "SUCCEEDED",
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
"metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
"normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX",
"roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX"
}
],
"task_error": {
"message": ""
},
"consumed_credits": 10
}
删除一个 Retexture 任务
永久删除一个 Retexture 任务,包括其模型和数据。删除操作无法撤销。
Request
curl --request DELETE \
--url https://api.meshy.ai/openapi/v1/retexture/a43b5c6d-7e8f-901a-234b-567c890d1e2f \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
// 200 OK on success, with an empty body.
//
// 409 Conflict when the task is IN_PROGRESS. The task keeps running:
{
"message": "Task is IN_PROGRESS and cannot be deleted. Credits for a task the worker has already started are not refundable; wait for it to reach SUCCEEDED, FAILED or CANCELED, then delete it."
}
路径参数
- Name
- id
- Type
- path
- Description
要删除的任务的 ID。
任务状态
删除一个 PENDING 任务会退还创建该任务时所使用的积分。
IN_PROGRESS 任务无法被删除。请求会返回 409 Conflict,
任务会继续运行。Meshy 不会为已经开始的任务退款,
因此删除它会让你同时损失积分和结果。请等待它
变为 SUCCEEDED、FAILED 或 CANCELED 状态后再删除。
删除处于最终状态(SUCCEEDED、FAILED 或 CANCELED)的任务
不会退还其积分。
返回值
任务被删除时返回 200 OK,当任务处于
IN_PROGRESS 状态时返回 409 Conflict。
获取 Retexture 任务列表
返回你的 Retexture 任务列表。
Request
curl https://api.meshy.ai/openapi/v1/retexture?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
[
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "retexture",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
"fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
"usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***"
},
"thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
"text_style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
"progress": 100,
"started_at": 1692771667037,
"created_at": 1692771650657,
"expires_at": 1692771679037,
"finished_at": 1692771669037,
"status": "SUCCEEDED",
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
"metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
"normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX",
"roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX"
}
],
"preceding_tasks": 0,
"task_error": {
"message": ""
},
"consumed_credits": 10
}
]
参数
- Name
- page_num
- Type
- integer
- 默认值 1
- Description
要返回的页码。
- Name
- page_size
- Type
- integer
- 默认值 10
- Description
每页的任务数量,最多为
100。
- Name
- sort_by
- Type
- string
- Description
排序方式。
可选值:
+created_at:最早的在前-created_at:最新的在前
返回值
一个分页的 Retexture 任务对象列表。
流式获取 Retexture 任务
以 Server-Sent Events(SSE)的形式流式返回 Retexture 任务的更新。
Request
curl -N https://api.meshy.ai/openapi/v1/retexture/018a210d-8ba4-705c-b111-1f1776f7f578/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response Stream
// Error event example
event: error
data: {
"status_code": 404,
"message": "Task not found"
}
// Message event examples illustrate task progress.
// These examples are shortened. Each event holds the full task object.
event: message
data: {
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"progress": 0,
"status": "PENDING"
}
event: message
data: {
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"progress": 50,
"status": "IN_PROGRESS"
}
event: message
data: {
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "retexture",
"progress": 100,
"status": "SUCCEEDED",
"created_at": 1692771650657,
"started_at": 1692771667037,
"finished_at": 1692771669037,
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
"fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
"obj": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.obj?Expires=***",
"usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***",
"mtl": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.mtl?Expires=***",
"stl": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.stl?Expires=***"
},
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
"metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
"normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX",
"roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX"
}
],
"preceding_tasks": 0,
"task_error": {
"message": ""
},
"consumed_credits": 10
}
参数
- Name
- id
- Type
- path
- Description
创建响应中返回的任务 ID。
返回值
以 Server-Sent Events 形式返回的 Retexture 任务对象 流。
每个事件都包含完整的任务对象,格式与 Get endpoint 返回的相同。当任务处于 PENDING 或 IN_PROGRESS 状态时,其结果字段尚无值。
Retexture 任务对象
Retexture 任务对象描述了一次 3D 模型的 retexture 操作。它保存着任务的状态、进度,以及任务成功后的模型和 texture 文件。
属性
Example Retexture Task Model
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "retexture",
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***",
"fbx": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.fbx?Expires=***",
"usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***"
},
"text_style_prompt": "red fangs, Samurai outfit that fused with japanese batik style",
"image_style_url": "https://assets.meshy.ai/***/image/example_image.jpg?Expires=***",
"thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
"progress": 100,
"started_at": 1692771667037,
"created_at": 1692771650657,
"expires_at": 1692771679037,
"finished_at": 1692771669037,
"status": "SUCCEEDED",
"texture_urls": [
{
"base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
"metallic": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_metallic.png?Expires=XXX",
"normal": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_normal.png?Expires=XXX",
"roughness": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_roughness.png?Expires=XXX"
}
],
"preceding_tasks": 0,
"task_error": {
"message": ""
},
"consumed_credits": 10
}
- Name
- id
- Type
- string
- Description
任务 ID。请将其视为不透明字符串,不要依赖其格式。
- Name
- type
- Type
- string
- Description
任务类型,始终为
retexture。
- Name
- model_urls
- Type
- object
- Description
已添加 texture 的 3D 模型的下载链接,每种文件格式对应一个。
- Name
glb- Type
- string
- Description
GLB 文件。
- Name
fbx- Type
- string
- Description
FBX 文件。
- Name
obj- Type
- string
- Description
OBJ 文件。
- Name
usdz- Type
- string
- Description
USDZ 文件。
- Name
mtl- Type
- string
- Description
MTL 文件。当模型带有 texture 时,Meshy 会随 OBJ 文件一起返回该文件。
- Name
stl- Type
- string
- Description
STL 文件。
- Name
3mf- Type
- string
- Description
3MF 文件。仅当
target_formats中包含3mf时才会出现。
- Name
- text_style_prompt
- Type
- string
- Description
你创建任务时使用的文本 prompt。
- Name
- image_style_url
- Type
- string
- Description
你创建任务时使用的风格图像。
- Name
- multiview_image_urls
- Type
- string[]
- Description
你创建任务时使用的多视图参考图像的下载链接。仅当你使用
multiview_image_urls创建任务时才会出现。
- Name
- thumbnail_url
- Type
- string
- Description
模型缩略图的下载链接。
- Name
- alpha_thumbnail_url
- Type
- string
- Description
thumbnail_url的透明背景版本(RGBA)的下载链接。仅当你使用alpha_thumbnail: true创建任务且 Meshy 渲染了透明预览图时才会出现。
- Name
- progress
- Type
- integer
- Description
任务的完成进度,以百分比表示。任务开始前为
0,成功后为100。
- Name
- started_at
- Type
- timestamp
- Description
任务开始的时间,使用 Unix 毫秒表示。任务开始前为
0。
- Name
- created_at
- Type
- timestamp
- Description
任务创建的时间,使用 Unix 毫秒表示。
- Name
- expires_at
- Type
- timestamp
- Description
任务结果过期的时间,使用 Unix 毫秒表示。
- Name
- finished_at
- Type
- timestamp
- Description
任务完成的时间,使用 Unix 毫秒表示。任务完成前为
0。
- Name
- status
- Type
- string
- Description
任务状态,取值为
PENDING、IN_PROGRESS、SUCCEEDED、FAILED或CANCELED之一。
- Name
- texture_urls
- Type
- array
- Description
生成的 texture 的下载链接,以对象数组的形式给出。该数组通常只包含一个对象。每个对象包含以下字段:
- Name
base_color- Type
- string
- Description
基础颜色贴图的下载链接。
- Name
metallic- Type
- string
- Description
金属度贴图的下载链接。当你使用
enable_pbr: false创建任务时,Meshy 不会包含该字段。
- Name
normal- Type
- string
- Description
法线贴图的下载链接。当你使用
enable_pbr: false创建任务时,Meshy 不会包含该字段。
- Name
roughness- Type
- string
- Description
粗糙度贴图的下载链接。当你使用
enable_pbr: false创建任务时,Meshy 不会包含该字段。
- Name
emission- Type
- string
- Description
自发光贴图的下载链接。当你使用以下任一设置创建任务时,Meshy 不会包含该字段:
enable_pbr: falseai_model为meshy-6-lite、meshy-7或latesttexture_resolution: 8k
- Name
- preceding_tasks
- Type
- integer
- Description
队列中排在该任务之前的任务数量。仅在任务处于
PENDING状态时才会出现。
- Name
- task_error
- Type
- object
- Description
任务失败时的错误详情。参见Errors。
- Name
- consumed_credits
- Type
- integer
- Description
该任务消耗的积分数量。当状态为
PENDING、IN_PROGRESS或SUCCEEDED时会出现。对于FAILED的任务,该值为0,因为 Meshy 会在任务失败时退还积分。