Retexture API

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


POST/openapi/v1/retexture

创建 Retexture 任务

此 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

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

    提供模型有两种方式:

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

    使用文本描述您期望的物体贴图风格。最多 600 个字符。

  • Name
    image_style_url
    Type
    string
    必选
    Description

    提供一张 2D 图像来指导贴图过程。我们目前支持 .jpg.jpeg.png 格式。

    提供图像有两种方式:

    • 公开可访问的 URL:可从公共互联网访问的 URL
    • Data URI:图像的 base64 编码 data URI。data URI 示例:data:image/jpeg;base64,<您的 base64 编码图像数据>
  • 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-5meshy-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 映射的模型)。
  • Name
    enable_pbr
    Type
    boolean
    默认值 false
    Description

    除基础颜色外,还生成 PBR 贴图(金属度、粗糙度、法线)。当 ai_modelmeshy-6 时,还会包含自发光贴图,但 texture_resolution: 8k 除外。meshy-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" 正在逐步推出,您的账户尚未启用。
    • 输入任务无效input_task_id 必须指向来自受支持模型的成功任务。
    • 模型格式无效model_url 指向的文件扩展名不受支持。
    • URL 无法访问:无法下载 model_urlimage_style_urlmultiview_image_urls 中的某个元素。
  • Name
    401 - Unauthorized
    Description

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

  • Name
    402 - Payment Required
    Description

    积分不足,无法执行此任务。

  • 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。

返回

成功时返回 200 OK

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

// Returns 200 Ok on success.

GET/openapi/v1/retexture

获取 Retexture 任务列表

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

参数

  • Name
    page_num
    Type
    integer
    默认值 1
    Description

    用于分页的页码。

  • Name
    page_size
    Type
    integer
    默认值 10
    Description

    每页数量限制。最大允许 50 项。

  • 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 贴图的工作单元。 该模型具有以下属性:

属性

  • Name
    id
    Type
    string
    Description

    任务的唯一标识符。虽然我们在实现细节上使用 k-可排序的 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,当存在贴图时会随 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

    任务生成的贴图 URL 对象数组。通常这里只包含一个贴图 URL 对象。每个贴图 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
}