重新貼圖 API

重新貼圖 API 是一項功能,可讓您將 Meshy 的 AI 重新貼圖能力整合到您自己的應用程式中。在本節中,您將找到開始使用此 API 所需的所有資訊。


POST/openapi/v1/retexture

建立重新貼圖任務

此端點可讓您建立新的重新貼圖任務。請參閱重新貼圖任務物件,以查看重新貼圖任務物件包含哪些屬性。

參數

  • Name
    input_task_id
    Type
    string
    必选
    Description

    您想要重新貼圖的已完成圖像轉 3D 或文字轉 3D 任務的 ID。 該任務必須是以下任務之一:文字轉 3D 預覽、文字轉 3D 精修、圖像轉 3D 或重建網格。此外,它必須具有 SUCCEEDED 狀態。

  • Name
    model_url
    Type
    string
    必选
    Description

    為 Meshy 提供一個 3D 模型以進行貼圖處理。支援的格式:.glb.gltf.obj.fbx.stl

    提供模型有兩種方式:

    • 可公開存取的 URL:可從公開網際網路存取的 URL。
    • Data URI:模型的 base64 編碼資料 URI。MIME 類型使用 application/octet-stream。範例: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
    默认值 latest
    Description

    用於重新貼圖的 AI 模型 ID。可選值:meshy-5meshy-6latest(Meshy 6)。

  • Name
    enable_original_uv
    Type
    boolean
    默认值 false
    Description

    保留模型既有的 UV 佈局,而不是重新產生 UV。

    • 如果您要重新貼圖的是 Meshy 產生的模型(透過 input_task_id,或指向 Meshy 輸出的 model_url),請設為 true,以重複使用其已最佳化的 UV 佈局。
    • 如果您要重新貼圖的是自行上傳的第三方模型:當它已帶有想要保留的良好 UV 時設為 true;若模型缺少合適的 UV,則保持 false,讓 Meshy 重新展開新的 UV。
  • Name
    enable_pbr
    Type
    boolean
    默认值 false
    Description

    產生 PBR 貼圖(金屬度、粗糙度、法線)以及基礎色。當 ai_modelmeshy-6latest 時,還會額外產生自發光貼圖。

  • Name
    hd_texture
    Type
    boolean
    默认值 false
    Description

    以 4K(4096×4096)解析度產生基礎色貼圖,取得更高細節。

  • Name
    remove_lighting
    Type
    boolean
    默认值 true
    Description

    移除基礎色貼圖中的高光和陰影,產生更乾淨的效果,在自訂光照設定下表現更佳。

  • Name
    target_formats
    Type
    string[]
    Description

    指定輸出中包含的 3D 檔案格式。只會產生並返回所請求的格式,可縮短任務完成時間。省略時,將包含所有支援的格式。

    可選值:glbobjfbxstlusdz3mf

  • Name
    alpha_thumbnail
    Type
    boolean
    默认值 false
    Description

    當設定為 true 時,任務會額外算繪一張透明背景(RGBA)的預覽圖,並在 GET 回應的 alpha_thumbnail_url 欄位中返回。原有 thumbnail_url 欄位保持不變。

返回值

回應的 result 屬性包含新建立的重新貼圖任務的任務 id

失敗模式

  • Name
    400 - Bad Request
    Description

    請求不合法。常見原因:

    • 缺少參數:必須提供 model_urlinput_task_id 其中之一。
    • 缺少樣式:必須提供 text_style_promptimage_style_url 其中之一。
    • 輸入任務無效input_task_id 必須引用一個來自支援模型的成功任務。
    • 模型格式無效model_url 指向的檔案副檔名不受支援。
    • URL 無法存取model_urlimage_style_url 無法下載。
  • Name
    401 - Unauthorized
    Description

    驗證失敗。請檢查您的 API 金鑰。

  • Name
    402 - Payment Required
    Description

    點數不足,無法執行此任務。

  • Name
    429 - Too Many Requests
    Description

    您已超出請求頻率限制。

请求

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,
    "enable_pbr": true
  }'

# 使用图像风格和 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
  }'

响应

{
  "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",
  "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

刪除重新貼圖 任務

此端點會永久刪除重新貼圖 任務,包括所有相關模型和資料。此操作無法復原。

路徑參數

  • 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
    默认值 1
    Description

    分頁的頁碼。

  • Name
    page_size
    Type
    integer
    默认值 10
    Description

    分頁大小限制。最多允許 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",
    "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

串流重新貼圖任務

此端點會透過伺服器傳送事件(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",
  "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
}

重新貼圖 任務物件

重新貼圖 任務物件是 Meshy 用於從文字或圖像輸入生成 3D 貼圖的工作單元。 此模型具有以下屬性:

屬性

  • Name
    id
    Type
    string
    Description

    任務的唯一識別碼。雖然我們使用 k-sortable UUID 作為任務 id 的實作細節,但您不應對 id 的格式做任何假設。

  • Name
    type
    Type
    string
    Description

    重新貼圖任務的類型。值為 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

      當產生 OBJ 且包含貼圖時返回的 MTL 檔案下載連結。

    • Name
      stl
      Type
      string
      Description

      STL 檔案的可下載連結。

    • Name
      3mf
      Type
      string
      Description

      3MF 檔案的可下載連結。僅在透過 target_formats 請求 3mf 時返回。

  • Name
    text_style_prompt
    Type
    string
    Description

    建立貼圖任務時使用的文字提示。

  • Name
    image_style_url
    Type
    string
    Description

    建立貼圖任務時使用的圖片輸入。

  • 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

    任務開始的時間戳,單位為毫秒。如果任務尚未開始,則此屬性為 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
      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 物件參考請查看錯誤處理

  • Name
    consumed_credits
    Type
    integer
    Description

    此任務消耗的積分數。當任務狀態為 PENDINGIN_PROGRESSSUCCEEDED 時返回。對於 FAILED 任務返回 0(失敗時積分會被退還)。

示例重新纹理任务模型

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