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

    您希望重新貼圖的已完成的 影象生成 3D 或 文字生成 3D 任務的 ID。 該任務必須是以下任務之一:Text to 3D Preview、Text to 3D Refine、影象生成 3D 或 重構網格。此外,其狀態必須為 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

    使用文字描述您想要的物體貼圖風格。最多 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,<您的 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

    基礎顏色貼圖解析度。可選 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 屬性包含新建立的 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 金鑰。

  • 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

串流取得重新貼圖任務

此 endpoint 使用 Server-Sent Events(SSE)串流傳輸重新貼圖任務的即時更新。

參數

  • Name
    id
    Type
    path
    Description

    要進行串流傳輸的重新貼圖任務的唯一識別碼。

回傳

以 Server-Sent Events 的形式回傳 重新貼圖任務物件 的串流。

對於 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
}

重新貼圖任務物件

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

屬性

  • Name
    id
    Type
    string
    Description

    任務的唯一識別碼。雖然我們在實作細節上使用 k-可排序的 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

      指向 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

    任務開始時的時間戳,單位為毫秒。如果任務尚未開始,此屬性值為 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(失敗時積分會被退還)。

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
}