lowpoly 將於 2026年10月30日 下線。 meshy-7 作為 3D 生成模型將於 2026年12月31日 下線;作為貼圖模型仍可使用。 請在這些日期前切換模型,以免請求出錯。 查看所有棄用資訊

Model Edit API

透過用一句話描述變化來改變 3D 模型的形狀。可以編輯整個模型,也可以選擇變化發生所圍繞的面。


POST/openapi/v2/model-edit

創建模型編輯任務

創建一個模型編輯任務,並返回任務物件。該任務會按照 prompt 的描述重塑模型,並返回一個不帶貼圖的 GLB 檔案及預覽圖。透過 selection_face_indices,改動只會發生在你所選的面周圍;若不提供,模型的任何部分都可能發生改動。要讀取結果,請參閱獲取結果。

Meshy 在處理你的請求時會檢查模型,因此 Meshy 無法編輯的模型會在 Meshy 創建任務之前返回 400。模型必須滿足以下所有條件:

  • 來源:一個在 input_task_id 下列出的任務,或你以 model_url 發送的 GLB 檔案
  • 貼圖:無。帶貼圖的模型會返回 400。
  • 大小:至多 4,000,000 個面和 4,000,000 個頂點,且 geometry 不超過 134,217,728 位元組(128 MiB),計算方式為每個頂點 12 位元組加每個面 24 位元組。超過 4,000,000 個面的 model_url 檔案會返回 400。超過其餘兩項限制的 input_task_id 模型會返回 400。超過這些限制的 model_url 檔案,或 Meshy 沒有大小記錄的輸入任務,會使任務失敗,並顯示訊息 The source model is too large to edit,Meshy 會退還其積分。
  • 水密性(Watertight):model_url 檔案,或可列印性修復任務的結果,必須是沒有孔洞的封閉曲面。不滿足此條件的 model_url 檔案會返回 400。要修復它,請對其執行可列印性修復,然後將該任務的 id 作為 input_task_id 發送。模型仍有孔洞的可列印性修復任務會返回 400,且 Meshy 無法編輯該模型。Meshy 無法測量形狀的模型同樣會返回 400。

該任務花費 20 積分。Meshy 在創建任務時收取,若任務失敗則退還。參見 Pricing。

Request

POST
/openapi/v2/model-edit
# Edit the faces you selected on a Meshy task's model
curl https://api.meshy.ai/openapi/v2/model-edit \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "prompt": "Add a short horn to the top of the head",
    "selection_face_indices": [1204, 1205, 1206, 1311, 1312]
  }'

# Edit the whole model from a public GLB URL, with a reference image
curl https://api.meshy.ai/openapi/v2/model-edit \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "model_url": "https://example.com/models/dog.glb",
    "prompt": "Give the dog a pair of boots",
    "reference_image_urls": ["https://example.com/images/boots.png"]
  }'

Response

{
  "id": "019ad9e2-5b7c-7a41-9c3e-2f8d6b1a4e07",
  "type": "model-edit",
  "status": "PENDING",
  "progress": 0,
  "created_at": 1796421600000,
  "started_at": null,
  "finished_at": null,
  "expires_at": null,
  "preceding_tasks": 1,
  "consumed_credits": 20,
  "task_error": null,
  "input": {
    "input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "prompt": "Add a short horn to the top of the head",
    "selection_face_indices": [1204, 1205, 1206, 1311, 1312]
  },
  "output": null
}

引數

  • Name
    input_task_id
    Type
    string
    必選
    Description

    除非你發送 model_url,否則此項為必填。要編輯其 GLB 的任務 ID。該任務必須是你用 API 創建且狀態為 SUCCEEDED 的任務。它必須是以下之一:

    • 一個 Text to 3D 預覽任務(mode: "preview"),或一個 should_texture: false 的 Image to 3D 或 Multi-Image to 3D 任務,使用 meshy-6 或 Meshy 7 模型(例如 meshy-7.1 或 latest)創建
    • 一個 Remesh 任務,其 input_task_id 來自第一項中的任務,且該任務沒有貼圖
    • 一個可列印性修復任務
    • 一個更早的模型編輯任務

    Meshy 6 Lite、Smart Topology(meshy-t2 和 meshy-t2.5)以及 geometry_resolution: "4k" 模型會返回 400。其他類型的任務,例如 Retexture 或一次呼叫內完成的 Text to 3D 任務,也會返回 400,但浮雕任務會返回 403。

  • Name
    model_url
    Type
    string
    必選
    Description

    除非你發送 input_task_id,否則此項為必填。要編輯的模型,可以是公開 URL 或 Data URI(data:model/gltf-binary;base64,...)。同時發送 input_task_id 和 model_url 會返回 400。

    該模型必須是 GLB 檔案,若透過 http 或 https URL(路徑以 .glb 結尾)提供,則至多 400 MB;若以 Data URI 提供,則至多 100 MB。不得使用 Draco 壓縮。要編輯其他格式,請先執行 Convert 轉換為 GLB,下載該 GLB,再以 model_url 發送。

  • Name
    prompt
    Type
    string
    必選
    Description

    要進行的改動,用一句話描述,最多 600 個字元。描述形狀上的改動,例如新增、移除、放大或重塑某個部分,例如 Give the dog a pair of boots。更長的文字會返回 400。

    要變更顏色或 material,請使用 Retexture。

  • Name
    selection_face_indices
    Type
    integer[]
    Description

    要圍繞其進行改動的面,以模型三角形的索引形式提供。關於 Meshy 如何為面編號,請參閱選擇面。不提供時,模型的任何部分都可以改動。

    發送 1 到 500,000 個索引,每個索引範圍從 0 到模型面數減 1。順序和重複不影響結果。空陣列、超出最後一個面的索引,或選區太小而無法產生改動,都會返回 400。

  • Name
    reference_image_urls
    Type
    string[]
    Description

    最多 5 張展示改動效果的參考圖片,每張以公開 URL 或 Data URI(data:image/png;base64,...)形式提供。每張圖片必須是 PNG、JPEG 或 WebP 檔案,大小至多 20 MB。超過 5 張圖片會返回 400。

返回值

202 Accepted,附帶任務物件。任務起始狀態為 PENDING,input 中是你的請求內容,output 設為 null。input.selection_face_indices 保存你發送時的索引。

兩個回應標頭有助於你讀取任務:

  • Location:該任務在 Tasks 上的 URL
  • Retry-After:你首次讀取它之前應等待的秒數

失敗模式

  • Name
    400 - Bad Request
    Description

    請求無法執行。例如:

    • 未發送 input_task_id 也未發送 model_url,或 prompt 只包含空格。代碼為 parameter_missing。
    • 同時發送了 input_task_id 和 model_url。代碼為 parameters_conflict。
    • 請求中包含該 endpoint 不接受的 parameter。代碼為 parameter_unknown。
    • 某個值違反了欄位規則:prompt 缺失或超過 600 個字元,selection_face_indices 的索引超過 500,000 個或存在負數,或 reference_image_urls 超過 5 個。代碼為 request_invalid,訊息會說明每個問題。
    • 選區無法使用。代碼為 parameter_out_of_range。這涵蓋以下 selection_face_indices 問題:
      • 空陣列
      • 不是模型面的索引,例如 selection_face_indices: face 5000 is out of range: the model has 3322 faces。請按照選擇面中描述的方式為面編號。
      • 覆蓋區域不屬於 Meshy 可改動的模型部分。請選擇更大的區域。
    • model_url 檔案有孔洞、帶有貼圖、面數超過 4,000,000,或 Meshy 無法讀取或測量它。代碼為 input_file_invalid,訊息會說明具體問題,例如 model_url: the model is not watertight; repair it with POST /openapi/v2/print/repair first。
    • input_task_id 模型帶有貼圖、面數超過 4,000,000、超過大小限制,或其創建方式不是此 endpoint 可編輯的類型。代碼為 input_task_unsupported,例如訊息為 Model editing requires an untextured model。如果 Meshy 無法讀取輸入任務的 GLB,代碼為 input_file_invalid。
    • input_task_id 對應的可列印性修復任務的模型仍有孔洞,或 Meshy 無法測量它。代碼為 input_task_unsupported,例如訊息為 input_task_id: the repaired model is still not watertight, so it cannot be edited。
    • 輸入任務尚未成功完成。代碼為 input_task_not_ready。
    • 輸入任務的模型檔案已不存在,例如在其 expires_at 之後。代碼為 input_task_expired,訊息為 Missing model file。請重新創建輸入任務。
    • Meshy 無法下載 model_url 或某張 reference_image_urls 圖片。代碼為 input_download_failed。
    • 某張 reference_image_urls 圖片大於 20 MB,或 Meshy 無法讀取它。代碼為 input_file_invalid。

    錯誤訊息會說明發現的具體問題。參見 Errors。

  • Name
    401 - Unauthorized
    Description

    API key 缺失或無效。請檢查 Authorization 請求標頭。

  • Name
    402 - Payment Required
    Description

    以下情況之一:

    • 帳戶積分不足。
    • 帳戶達到積分限制。
    • 帳戶處於免費方案。

    請檢查你的積分和方案,然後重試。

  • Name
    403 - Forbidden
    Description

    以下情況之一:

    • 內容審核攔截了 prompt 或某張參考圖片。代碼以 moderation_blocked 開頭。請更改輸入內容,然後重試。
    • input_task_id 是一個浮雕模型,此 endpoint 無法編輯該類型。代碼為 input_task_unsupported。請發送其他模型。
  • Name
    404 - Not Found
    Description

    以下情況之一:

    • input_task_id 與你的任何任務都不符合。代碼為 input_task_not_found。
    • Meshy 在保留期後已移除該輸入任務。代碼為 input_task_expired。請重新創建輸入任務。
  • Name
    429 - Too Many Requests
    Description

    達到以下某個限制:

    • Meshy 正在轉換太多選區。代碼為 rate_limit_exceeded,訊息為 Selection processing is busy; try again shortly。請等待幾秒後重試。
    • 你發送的請求過多。請等待 Retry-After 中的秒數後重試。
    • 你排隊或執行中的任務過多。請等待部分任務完成後重試。
    • 在無限制方案下積分已用盡時,你達到了可在無積分情況下執行的任務數上限。請等待某個任務完成,或增加積分。
  • Name
    503 - Service Unavailable
    Description

    Meshy 無法檢查模型是否為水密(watertight)。代碼為 service_unavailable。請等待幾秒後重試。

對於返回錯誤的請求,Meshy 不收取任何費用。


選取面

selection_face_indices 按面在任務所編輯的 GLB 檔案三角形中的索引來指定面。該檔案是 input_task_id 任務的 output.model_urls.glb,或者你的 model_url 檔案。

Meshy 生成的模型是單一 mesh,所以面 i 是其索引緩衝區中 3i、3i + 1 和 3i + 2 這三個索引構成的三角形。

Select faces with trimesh

import os

import numpy as np
import requests
import trimesh

# Load the GLB as one mesh, keeping the file's face order
mesh = trimesh.load("model.glb", force="mesh", process=False)

# Select the faces whose center is in the top fifth of the model
# (glTF models are Y-up)
centers = mesh.triangles_center
top = mesh.bounds[1][1] - 0.2 * mesh.extents[1]
selection = np.flatnonzero(centers[:, 1] > top).tolist()

# A request takes 1 to 500,000 indices
assert 1 <= len(selection) <= 500_000, len(selection)

response = requests.post(
    "https://api.meshy.ai/openapi/v2/model-edit",
    headers={"Authorization": f"Bearer {os.environ['MESHY_API_KEY']}"},
    json={
        "input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
        "prompt": "Add a short horn to the top of the head",
        "selection_face_indices": selection,
    },
)
response.raise_for_status()
print(response.json()["id"])

從 3D 工具中取得索引

如果工具保留了檔案的三角形順序,它給出的索引就與 Meshy 相同。以下工具對單一 mesh 模型會保留該順序:

  • trimesh:使用 process=False 載入檔案。
  • Blender:使用預設的 glTF import 設定 import 檔案。
  • three.js:從 GLTFLoader 載入的模型上的射線檢測命中結果中讀取 faceIndex。

其他能保留順序的工具會給出相同的索引。任何改變三角形的步驟都會重新編號面,例如把三角形合併成四邊形、遊戲引擎的 mesh 最佳化,或者重新匯出檔案。

含多個 mesh 的檔案

對於含有多個 mesh 或 primitive 的檔案,Meshy 按以下順序為三角形編號:

  1. 檔案預設 scene 中的節點,按深度優先順序。每個節點自身的 mesh 排在其子節點之前,節點按檔案列出的順序排列。
  2. 在一個 mesh 內,按順序處理 mode 為 TRIANGLES 的每個 primitive。Meshy 不會為其他類型的 primitive(例如三角形帶)編號。
  3. 在一個 primitive 內,按其索引緩衝區儲存的順序排列三角形。沒有索引緩衝區的 primitive,則按順序每三個頂點構成一個三角形。

編輯的影響範圍有多大

Meshy 會把選中的面轉換為覆蓋模型的 16 × 16 × 16 網格單元,這與 Meshy 網頁應用程式中模型 editor 的做法相同。編輯操作作用於這些單元,因此影響範圍大約是你所選面周圍模型最長邊的十六分之一,而不僅僅是所選的面本身。選中一個面會選中它所在的整個單元,所以編輯操作無法針對比一個單元更小的區域。如果所選區域未覆蓋任何單元,將回傳 400,此時請選擇更大的區域。

Meshy 會重新生成整個 mesh,因此不保證所選區域之外的部分與輸入完全一致。

再次編輯結果

編輯後的模型是一個帶有新面索引的新 mesh。在再次編輯它之前,請先在新模型上選取面,然後將 Model Edit 任務的 id 作為 input_task_id 傳送。編輯操作通常會增加面和頂點,因此即便輸入模型未超出尺寸限制,編輯後的模型也可能超出限制。

你也可以把該任務的 id 作為 input_task_id 傳送給其他端點,例如使用 重新貼圖 為模型添加貼圖。編輯後的模型三角形數量通常會超過 Rigging 所能處理的範圍,所以在對其進行 rig 之前,請先對它執行 重構網格。


獲取結果

讀取 Model Edit 任務的方式與其他所有 v2 任務相同,均透過 Tasks 路由進行。若只想列出 Model Edit 任務,可透過 type=model-edit 進行篩選。


模型編輯輸出

當任務成功時,output 中會包含以下欄位。任務物件的其餘部分對所有任務類型都是相同的。output 中的 URL 會在 expires_at 之後失效。與其他任務檔案一樣,Meshy 會在任務完成後將編輯後的模型保留 3 天。請參閱資產保留期。

Succeeded Model Edit task

{
  "id": "019ad9e2-5b7c-7a41-9c3e-2f8d6b1a4e07",
  "type": "model-edit",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1796421600000,
  "started_at": 1796421605000,
  "finished_at": 1796421672000,
  "expires_at": 1796680872000,
  "preceding_tasks": 0,
  "consumed_credits": 20,
  "task_error": null,
  "input": {
    "input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "prompt": "Add a short horn to the top of the head",
    "selection_face_indices": [1204, 1205, 1206, 1311, 1312]
  },
  "output": {
    "model_urls": {
      "glb": "https://assets.meshy.ai/***/output/model.glb?Expires=***"
    },
    "thumbnail_url": "https://assets.meshy.ai/***/output/preview.png?Expires=***"
  }
}
  • Name
    model_urls
    Type
    object
    Description

    指向已編輯模型的簽名 URL,位於 glb 鍵下。該模型沒有 texture,其面會被重新編號。

  • Name
    thumbnail_url
    Type
    string
    Description

    指向已編輯模型預覽圖的簽名 URL。

模型編輯輸出沒有 texture_urls。

失敗的任務會帶有 task_error。其中有兩個錯誤代碼是模型編輯專有的:

請參閱 Errors。