重新纹理 API

重新纹理 API 是一项功能,允许您将 Meshy 的 AI 重新纹理能力集成到您自己的应用程序中。在本节中,您将找到开始使用此 API 所需的所有信息。


POST/openapi/v1/retexture

创建重新纹理任务

该端点允许您创建一个新的重新纹理任务。请参阅重新纹理任务对象以查看重新纹理任务对象包含哪些属性。

参数

必需属性

  • Name
    input_task_id
    Type
    string
    Description

    您想要重新纹理的已完成图像转3D或文本转3D任务的ID。 该任务必须是以下任务之一:文本转3D预览、文本转3D精化、图像转3D或重建网格。此外,它必须使用 meshy-4meshy-5 AI模型运行,并且状态为 SUCCEEDED

  • Name
    model_url
    Type
    string
    Description

    为 Meshy 提供一个 3D 模型以进行纹理处理。目前支持 .glb 格式的模型。

    提供模型有两种方式:

    • 可公开访问的 URL:一个可以从公共互联网访问的 URL。
    • Data URI:模型的 base64 编码数据 URI。Data URI 示例:data:application/octet-stream;base64,<your base64-encoded model data>
  • Name
    text_style_prompt
    Type
    string
    Description

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

  • Name
    image_style_url
    Type
    string
    Description

    提供一个2D图像来指导纹理处理过程。目前支持 .jpg.jpeg.png 格式。

    提供图像有两种方式:

    • 可公开访问的 URL:一个可以从公共互联网访问的 URL
    • Data URI:图像的 base64 编码数据 URI。Data URI 示例:data:image/jpeg;base64,<your base64-encoded image data>

可选属性

  • Name
    ai_model
    Type
    string
    Description

    用于重新纹理的AI模型ID。

    可选值:

    • meshy-4
    • meshy-5

    如果未指定,默认为 meshy-5

  • Name
    enable_original_uv
    Type
    boolean
    Description

    使用模型的原始 UV 而不是生成新的 UV。 如果模型没有原始 UV,输出质量可能不佳。 如果未指定,默认为 true

  • Name
    art_style
    Type
    string
    Description

    描述您期望的物体艺术风格。 如果未指定,默认为 realistic。可选值:

    • realistic:写实风格
    • cartoon:卡通风格

返回值

响应的 result 属性包含新创建的重新纹理任务的任务 id

请求

POST
/openapi/v1/retexture
## 使用文本纹理和输入模型示例
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,
    "art_style": "realistic"
  }'

 ## 使用图像纹理和输入任务示例
curl https://api.meshy.ai/openapi/v1/retexture \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "image_style_url": "https://cdn.meshy.ai/image/example_image.jpg",
    "enable_original_uv": true,
    "art_style": "realistic"
  }'

响应

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

GET/openapi/v1/retexture/:id

获取重新纹理任务

该端点允许您通过有效的任务 id 获取一个重新纹理任务。请参阅重新纹理任务对象以查看重新纹理任务对象包含哪些属性。

参数

  • Name
    id
    Type
    path
    Description

    要获取的重新纹理任务的唯一标识符。

返回值

响应包含重新纹理任务对象。详情请查阅重新纹理任务对象部分。

请求

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}"

响应

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "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",
  "texture_image_url": "",
  "art_style": "realistic",
  "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=***",
    }
  ],
  "task_error": {
    "message": ""
  }
}

DELETE/openapi/v1/retexture/:id

删除重新纹理任务

该端点永久删除重新纹理任务,包括所有相关模型和数据。此操作不可逆转。

路径参数

  • Name
    id
    Type
    path
    Description

    要删除的重新纹理任务的ID。

返回值

成功时返回 200 OK

请求

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}"

响应

// 成功时返回 200 OK。

GET/openapi/v1/retexture

列出重新纹理任务

该端点允许您获取重新纹理任务的列表。

参数

可选属性

  • Name
    page_num
    Type
    integer
    Description

    分页的页码。起始值和默认值为 1

  • Name
    page_size
    Type
    integer
    Description

    分页大小限制。默认 10 条,最大允许 50 条。

  • Name
    sort_by
    Type
    string
    Description

    排序字段。可选值:

    • +created_at:按创建时间升序排序。
    • -created_at:按创建时间降序排序。

返回值

返回重新纹理任务对象的分页列表。

请求

GET
/openapi/v1/retexture
curl https://api.meshy.ai/openapi/v1/retexture?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"

响应

[
  {
    "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "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",
    "art_style": "realistic",
    "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=***",
      }
    ],
    "preceding_tasks": 0,
    "task_error": {
      "message": ""
    }
  }
]

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

流式重新纹理任务

该端点通过服务器发送事件(SSE)流式返回重新纹理任务的实时更新。

参数

  • Name
    id
    Type
    path
    Description

    要流式的重新纹理任务的唯一标识符。

返回值

返回重新纹理任务对象的流式数据,格式为服务器发送事件(SSE)。

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

请求

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}"

响应流

// 错误事件示例
event: error
data: {
  "status_code": 404,
  "message": "Task not found"
}

// 消息事件示例,展示任务进度。
// 对于 PENDING 或 IN_PROGRESS 状态的任务,响应流不会包含所有字段。
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",
  "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=***",
    "usdz": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.usdz?Expires=***"
  },
  "texture_urls": [
    {
      "base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
    }
  ],
  "preceding_tasks": 0,
  "task_error": {
    "message": ""
  }
}

重新纹理任务对象

重新纹理任务对象是 Meshy 用于从文本或图像输入生成 3D 纹理的工作单元。 该模型具有以下属性:

属性

  • Name
    id
    Type
    string
    Description

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

  • Name
    model_urls
    Type
    object
    Description

    Meshy 生成的可下载带纹理 3D 模型文件的 URL。

    • Name
      glb
      Type
      string
      Description

      GLB 文件的可下载 URL。

    • Name
      fbx
      Type
      string
      Description

      FBX 文件的可下载 URL。

    • Name
      usdz
      Type
      string
      Description

      USDZ 文件的可下载 URL。

  • Name
    text_style_prompt
    Type
    string
    Description

    创建纹理任务时使用的文本提示。

  • Name
    image_style_url
    Type
    string
    Description

    创建纹理任务时使用的图像输入。

  • Name
    art_style
    Type
    string
    Description

    指导纹理任务的艺术风格。

  • Name
    thumbnail_url
    Type
    string
    Description

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

  • Name
    progress
    Type
    integer
    Description

    任务进度。如果任务尚未开始,则该属性为 0。任务成功后,该值为 100

  • Name
    started_at
    Type
    timestamp
    Description

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

  • Name
    created_at
    Type
    timestamp
    Description

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

  • Name
    expires_at
    Type
    timestamp
    Description

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

  • Name
    finished_at
    Type
    timestamp
    Description

    任务完成的时间戳,单位为毫秒。如果任务尚未完成,则该属性为 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
    preceding_tasks
    Type
    integer
    Description

    前置任务数量。

  • Name
    task_error
    Type
    object
    Description

    错误对象,包含任务失败时的错误信息。如果任务成功,message 属性应为空。

    • Name
      message
      Type
      string
      Description

      详细错误信息。

示例重新纹理任务模型

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "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=***",
  "art_style": "realistic",
  "thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
  "progress": 1,
  "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=***",
    }
  ],
  "preceding_tasks": 0,
  "task_error": {
    "message": ""
  }
}