重新貼圖 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
    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 布局,而不是重新生成 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-6 時,還會額外生成自發光貼圖;但在 texture_resolution: 8k 下不會生成自發光貼圖。meshy-7latest 不會生成自發光貼圖。

  • Name
    texture_resolution
    Type
    string
    預設值 2k
    Description

    基礎色貼圖的解析度。可選值為 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

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

  • 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_urlmultiview_image_urls 其中之一。
    • 風格輸入衝突multiview_image_urls 不能與 text_style_promptimage_style_url 同時使用。
    • 模型不支援多視角multiview_image_urls 需要 ai_model: "meshy-7"(或 latest)。
    • 模型不可用ai_model: "meshy-7" 正在逐步放量,尚未對你的帳號啟用。
    • 輸入任務無效input_task_id 必須引用一個來自支援模型的成功任務。
    • 模型格式無效model_url 指向的檔案副檔名不受支持。
    • URL 不可訪問model_urlimage_style_urlmultiview_image_urls 中的某個元素無法下載。
  • 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
    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

    任務開始的時間戳,單位為毫秒。如果任務尚未開始,則該屬性為 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
}