Retexture API

Retexture API 是一项功能,可让你将 Meshy 的 AI 重新贴图能力集成到你自己的应用程序中。在本节中,你将找到开始使用此 API 所需的所有信息。


POST/openapi/v1/retexture

Create a Retexture Task

此 endpoint 允许你创建一个新的 Retexture 任务。请参阅 The Retexture Task Object 以查看 Retexture 任务对象包含哪些属性。

参数

  • Name
    input_task_id
    Type
    string
    必选
    Description

    你希望重新贴图的已完成 Image to 3D 或 Text to 3D 任务的 ID。 该任务必须是以下任务之一:Text to 3D Preview、Text to 3D Refine、Image to 3D 或 Remesh。此外,其状态必须为 SUCCEEDED

  • Name
    model_url
    Type
    string
    必选
    Description

    提供一个 3D 模型供 Meshy 进行贴图处理。支持的格式:.glb.gltf.obj.fbx.stl

    提供模型的方式有两种:

    • 可公开访问的 URL:可从公共互联网访问的 URL。
    • Data URI:模型的 base64 编码 data URI。使用 MIME type application/octet-stream。示例:data:application/octet-stream;base64,<your base64-encoded model data>
  • Name
    text_style_prompt
    Type
    string
    必选
    Description

    使用文本描述你想要的物体贴图样式。最多 800 个字符。

  • Name
    image_style_url
    Type
    string
    必选
    Description

    提供一张 2D 图片以指导贴图过程。目前支持 .jpg.jpeg.png 格式。

    提供图片的方式有两种:

    • 可公开访问的 URL:可从公共互联网访问的 URL
    • Data URI:图片的 base64 编码 data URI。data URI 示例:data:image/jpeg;base64,<your base64-encoded image data>
  • Name
    multiview_image_urls
    Type
    string[]
    必选
    Description

    提供 1 至 4 张从不同视角展示同一物体的图片,以指导贴图过程。第一张图片为主视图(正面),其余视角(左、后、右)的顺序不作要求。

    每个元素接受与 image_style_url 相同的格式(可公开访问的 URL 或 base64 data URI,.jpg/.jpeg/.png)。

  • Name
    ai_model
    Type
    string
    默认值 latest
    Description

    用于重新贴图的 AI 模型 ID。可用值:meshy-6-litemeshy-6meshy-7latest(Meshy 7)。

  • Name
    enable_original_uv
    Type
    boolean
    默认值 false
    Description

    保留模型现有的 UV 布局,而不是生成新的 UV 布局。

    • 如果你要重新贴图的是 Meshy 生成的模型(通过 input_task_id,或指向 Meshy 输出结果的 model_url),请将此项设为 true,以复用其优化过的 UV 布局。
    • 如果你要重新贴图的是自己上传的第三方模型,当它已经具有良好的 UV 且你希望保留时设为 true;否则保留为 false,让 Meshy 重新展开全新的 UV(适用于缺乏合适 UV 映射的模型)。
  • Name
    enable_pbr
    Type
    boolean
    默认值 false
    Description

    在基础颜色之外生成 PBR 贴图(金属度、粗糙度、法线)。当 ai_modelmeshy-6 时还会包含一张自发光贴图,但在 texture_resolution: 8k 时除外。meshy-6-litemeshy-7latest 不生成自发光贴图。

  • Name
    texture_resolution
    Type
    string
    默认值 2k
    Description

    基础颜色 texture 的分辨率。可选值为 2k(2048×2048)、4k(4096×4096)或 8k(8192×8192)。分辨率越高,捕捉的表面细节越多。

  • Name
    hd_texture
    Type
    boolean
    已弃用
    默认值 false
    Description

    请改用 texture_resolution——效果等同于 texture_resolution: "4k"。当两者同时设置时,以 texture_resolution 为准。

  • Name
    remove_lighting
    Type
    boolean
    默认值 true
    Description

    从基础颜色 texture 中移除高光和阴影,生成更干净的结果,在自定义光照环境下效果更佳。

  • Name
    target_formats
    Type
    string[]
    Description

    指定输出中要包含的 3D 文件格式。只会生成并返回所请求的格式,这有助于缩短任务完成时间。省略时,将包含所有支持的格式。

    可用值:glbobjfbxstlusdz3mf

  • Name
    alpha_thumbnail
    Type
    boolean
    默认值 false
    Description

    设为 true 时,任务会额外渲染一个透明背景(RGBA)版本的预览图,并在 GET 响应中以 alpha_thumbnail_url 返回。现有的 thumbnail_url 字段保持不变。

返回值

响应的 result 属性包含新创建的 Retexture 任务的 id

失败模式

  • Name
    400 - Bad Request
    Description

    请求不可接受。常见原因:

    • 缺少参数:必须提供 model_urlinput_task_id 之一。
    • 缺少样式:必须提供 text_style_promptimage_style_urlmultiview_image_urls 中的一个。
    • 样式输入冲突multiview_image_urls 不能与 text_style_promptimage_style_url 组合使用。
    • 多视图不支持的模型multiview_image_urls 需要显式指定 ai_model: "meshy-7"
    • 模型尚不可用ai_model: "meshy-7"ai_model: "meshy-6-lite" 正在逐步推出,你的账户可能尚未启用。
    • 输入任务无效input_task_id 必须指向来自受支持模型的成功任务。
    • 模型格式无效model_url 指向的文件扩展名不受支持。
    • URL 无法访问:无法下载 model_urlimage_style_urlmultiview_image_urls 中的某个元素。
  • Name
    401 - Unauthorized
    Description

    身份验证失败。请检查你的 API key。

  • Name
    402 - Payment Required
    Description

    credits 不足,无法执行此任务。

  • Name
    429 - Too Many Requests
    Description

    你已超出速率限制。

Request

POST
/openapi/v1/retexture
# 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": "https://cdn.meshy.ai/image/example_image.jpg",
    "ai_model": "latest",
    "enable_pbr": true,
    "enable_original_uv": true
  }'

Response

{
  "result": "018a210d-8ba4-705c-b111-1f1776f7f578"
}

GET/openapi/v1/retexture/:id

检索 Retexture 任务

此 endpoint 允许您根据有效的任务 id 检索一个 Retexture 任务。 请参阅 Retexture 任务对象 以了解 Retexture 任务对象包含哪些属性。

参数

  • Name
    id
    Type
    path
    Description

    要检索的 Retexture 任务的唯一标识符。

返回值

响应中包含 Retexture 任务对象。详情请查看 Retexture 任务对象 部分。

Request

GET
/openapi/v1/retexture/018a210d-8ba4-705c-b111-1f1776f7f578
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",
      "emission": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_emission.png?Expires=XXX"
    }
  ],
  "task_error": {

    "message": ""

  },

  "consumed_credits": 10
}

DELETE/openapi/v1/retexture/:id

删除一个 Retexture 任务

此 endpoint 会永久删除一个 retexture 任务,包括所有关联的模型和数据。此操作不可逆。

路径参数

  • Name
    id
    Type
    path
    Description

    要删除的 retexture 任务的 ID。

任务状态

仍处于 PENDING 状态的任务会被删除,并且在创建时消耗的 credits 会被退还。

已经处于 IN_PROGRESS 状态的任务无法被删除:请求会被 以 409 Conflict 拒绝,任务将继续运行。工作进程已经开始处理的任务,其 credits 不可退还,因此在运行过程中删除该任务会让你同时损失 credits 和结果。请等待任务到达 SUCCEEDEDFAILEDCANCELED 状态后再删除。

处于终止状态(SUCCEEDEDFAILEDCANCELED)的任务会被删除, 且不会退还 credits。

返回值

成功时返回 200 OK;当任务处于 IN_PROGRESS 状态时返回 409 Conflict

Request

DELETE
/openapi/v1/retexture/a43b5c6d-7e8f-901a-234b-567c890d1e2f
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 is left 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."
}

GET/openapi/v1/retexture

获取 Retexture 任务列表

此 endpoint 允许您获取 Retexture 任务的列表。

参数

  • 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 任务对象 列表。

Request

GET
/openapi/v1/retexture
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",
        "emission": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_emission.png?Expires=XXX"
      }
    ],
    "preceding_tasks": 0,
    "task_error": {

      "message": ""

    },

    "consumed_credits": 10
  }
]

GET/openapi/v1/retexture/:id/stream

流式获取 Retexture 任务

此 endpoint 使用 Server-Sent Events(SSE)流式传输 Retexture 任务的实时更新。

参数

  • Name
    id
    Type
    path
    Description

    要进行流式传输的 Retexture 任务的唯一标识符。

返回

以 Server-Sent Events 的形式返回一个 Retexture 任务对象 的流。

对于 PENDINGIN_PROGRESS 状态的任务,响应流中只会包含必要的 progressstatus 字段。

Request

GET
/openapi/v1/retexture/018a210d-8ba4-705c-b111-1f1776f7f578/stream
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.
// For PENDING or IN_PROGRESS tasks, the response stream will not include all fields.
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",
      "emission": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_emission.png?Expires=XXX"
    }
  ],
  "preceding_tasks": 0,
  "task_error": {

    "message": ""

  },

  "consumed_credits": 10
}

Retexture 任务对象

Retexture 任务对象是 Meshy 用来根据文本或图像输入生成 3D texture 的工作单元。 该模型具有以下属性:

属性

  • Name
    id
    Type
    string
    Description

    任务的唯一标识符。虽然我们在实现细节上使用 k-sortable UUID 作为任务 id,但你应该对 id 的格式做任何假设。

  • Name
    type
    Type
    string
    Description

    Retexture 任务的类型。值为 retexture

  • Name
    model_urls
    Type
    object
    Description

    指向 Meshy 生成的带贴图 3D 模型文件的可下载 URL。

    • Name
      glb
      Type
      string
      Description

      指向 GLB 文件的可下载 URL。

    • Name
      fbx
      Type
      string
      Description

      指向 FBX 文件的可下载 URL。

    • Name
      obj
      Type
      string
      Description

      指向 OBJ 文件的可下载 URL。

    • Name
      usdz
      Type
      string
      Description

      指向 USDZ 文件的可下载 URL。

    • Name
      mtl
      Type
      string
      Description

      指向 MTL 文件的可下载 URL,在存在 texture 时会随 OBJ 导出一同返回。

    • Name
      stl
      Type
      string
      Description

      指向 STL 文件的可下载 URL。

    • Name
      3mf
      Type
      string
      Description

      指向 3MF 文件的可下载 URL。仅当通过 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

    指向用于创建贴图任务的多视图参考图像的可下载 URL。仅当任务是通过 multiview_image_urls 创建时才会出现。

  • Name
    thumbnail_url
    Type
    string
    Description

    指向模型文件缩略图的可下载 URL。

  • Name
    alpha_thumbnail_url
    Type
    string
    Description

    指向 thumbnail_url 的透明背景(RGBA)版本的可下载 URL。仅当任务是通过 alpha_thumbnail: true 创建且透明预览渲染成功时才会出现;否则该字段将被省略。

  • Name
    progress
    Type
    integer
    Description

    任务的进度。如果任务尚未开始,该属性为 0。一旦任务成功完成,该值将变为 100

  • Name
    started_at
    Type
    timestamp
    Description

    任务开始时间的 timestamp,以毫秒为单位。如果任务尚未开始,该属性为 0

  • Name
    created_at
    Type
    timestamp
    Description

    任务创建时间的 timestamp,以毫秒为单位。

  • Name
    expires_at
    Type
    timestamp
    Description

    任务结果过期时间的 timestamp,以毫秒为单位。

  • Name
    finished_at
    Type
    timestamp
    Description

    任务完成时间的 timestamp,以毫秒为单位。如果任务尚未完成,该属性为 0

  • Name
    status
    Type
    string
    Description

    任务的状态。可能的值为 PENDINGIN_PROGRESSSUCCEEDEDFAILEDCANCELED 之一。

  • Name
    texture_urls
    Type
    array
    Description

    由该任务生成的 texture URL 对象数组。通常这里只包含一个 texture URL 对象。每个 texture URL 具有以下属性:

    • Name
      base_color
      Type
      string
      Description

      指向基础颜色贴图图像的可下载 URL。

    • Name
      metallic
      Type
      string
      Description

      指向金属度贴图图像的可下载 URL。

    • Name
      normal
      Type
      string
      Description

      指向法线贴图图像的可下载 URL。

    • Name
      roughness
      Type
      string
      Description

      指向粗糙度贴图图像的可下载 URL。

    • Name
      emission
      Type
      string
      Description

      指向自发光贴图图像的可下载 URL。

  • Name
    preceding_tasks
    Type
    integer
    Description

    排在前面的任务数量。

  • Name
    task_error
    Type
    object
    Description

    失败任务的错误详情。完整的 task_error 对象参考请参见 Errors

  • Name
    consumed_credits
    Type
    integer
    Description

    该任务消耗的 credits 数量。当任务状态为 PENDINGIN_PROGRESSSUCCEEDED 时会出现。对于 FAILED 任务返回 0(失败时 credits 会被退回)。

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",
      "emission": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0_emission.png?Expires=XXX"
    }
  ],
  "preceding_tasks": 0,
  "task_error": {

    "message": ""

  },

  "consumed_credits": 10
}