Image to 3D API
將一張圖片轉換為 3D 模型,可選擇是否帶 texture,並指定所需的輸出格式。
從 v1 遷移?影象生成 3D 的主要變化如下:
ai_model是唯一的模型設定項。請求中若帶有model_type將回傳400。- 帶 texture 的模型需要
texture_model,即用於為 mesh 上色的模型。 target_formats預設值為 GLB。- 結果包含在
output中。
參見 影象生成 3D 的具體變化。
創建 Image to 3D 任務
curl https://api.meshy.ai/openapi/v2/image-to-3d \
-X POST \
-H "Authorization: Bearer ${MESHY_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"image_url": "https://cdn.meshy.ai/webapp-assets/doc/try-it/v2/inputs/santa.3dbe655f9980.jpg",
"ai_model": "meshy-7.1",
"should_texture": true,
"texture_model": "meshy-7"
}'參數
- Name
- image_url
- Type
- string
- 必選
- Description
除非你傳送
input_task_id,否則此項為必填。要轉換為模型的圖片,可以是公開 URL 或 data URI(data:image/png;base64,...)。該圖片必須是 JPG、JPEG、PNG 或 WebP 檔案,大小不超過 20 MB,每邊至少 32 像素,且不超過 178,956,970 像素(寬 × 高)。
- Name
- input_task_id
- Type
- string
- 必選
- Description
除非你傳送
image_url,否則此項為必填。用作輸入的 Text to Image 或 Image to Image 任務的 ID。該任務必須是你透過 API 建立的,狀態為SUCCEEDED,且只生成了一張圖片。如果你同時傳送image_url和input_task_id,Meshy 會使用input_task_id。對於多視圖圖片任務,請使用 Multi-Image to 3D。
- Name
- ai_model
- Type
- string
- 預設值 latest
- Description
生成 3D 模型的模型。這是唯一的模型設定項。
試用並預覽標準模型:
latest:Meshy 7.1meshy-7.1meshy-6meshy-6-litemeshy-standard-latest:與latest相同
Smart Topology 模型會按照你透過
target_polycount設定的面數,建構乾淨的三角形 mesh:meshy-t2.5:為遊戲資產提供更銳利的細節meshy-t2meshy-smart-topology-latest:Meshy T2.5,最新的 Smart Topology 模型。新模型發布時,結果可能會改變。如果希望結果保持不變,請傳送meshy-t2.5。
有關哪種模型適合你的專案(例如遊戲角色或 3D 列印),請參見模型。
- Name
- geometry_resolution
- Type
- string
- 預設值 standard
- Description
要生成多少 geometry 細節。
試用並預覽可用值:
standard2k:增加 Ultra 處理流程4k:增加 Ultra 處理流程,然後再進行超解析度處理
2k和4k需要meshy-7.1或latest。使用其他模型時會返回400。
- Name
- should_texture
- Type
- boolean
- 預設值 true
- Description
是否生成 texture。
true返回帶貼圖的模型,false返回不帶貼圖的 mesh。設為false時,Meshy 會忽略texture_model及其他 texture 參數。試用並預覽
should_texture = true- Name
- texture_model
- Type
- string
- 必選
- Description
除非
should_texture為false,否則此項為必填。在同一任務中為 3D 模型生成 texture 的模型。每個ai_model都可以接受以下每個值。可用值:
meshy-7:Meshy 7,帶 PBR 貼圖、文字 prompt,支援高達 8K 的 texturemeshy-n1:Meshy N1,僅根據參考圖像生成 2K 基礎色 texturemeshy-6-lite:Meshy 6 Lite,2K texture
未指定
texture_model的帶貼圖請求會返回400,texture 模型不支援的選項也會返回400。texture 模型不會改變 積分 消耗。請參見Texture 模型。
- Name
- enable_pbr
- Type
- boolean
- 預設值 false
- Description
是否同時生成金屬度、粗糙度和法線貼圖。使用
texture_model: "meshy-n1"時,設為true會返回400。試用並預覽
- Name
- texture_resolution
- Type
- string
- 預設值 2k
- Description
基礎色 texture 的尺寸。
試用並預覽可用值:
2k4k8k
4k和8k需要texture_model: "meshy-7"。使用meshy-n1或meshy-6-lite時會返回400。
- Name
- texture_prompt
- Type
- string
- Description
用於指導 texture 的文字,最多 800 個字元。超出長度會返回
400。請傳送texture_prompt或texture_image_url,不要同時傳送兩者。同時傳送會返回400。使用texture_model: "meshy-n1"時,傳送此參數會返回400。
- Name
- texture_image_url
- Type
- string
- Description
用於指導 texture 的圖片,可以是公開 URL 或 data URI。其格式和大小規則與
image_url相同。使用texture_model: "meshy-n1"時,Meshy 會將該圖片作為正面視圖生成 texture;若未提供,則使用輸入圖像。
- Name
- target_formats
- Type
- string[]
- 預設值 ["glb"]
- Description
要生成的檔案格式。Meshy 只會生成你列出的格式。
可用值:
glbobjfbxstlusdz3mf
Meshy 會將 STL 和 3MF 檔案縮放到最長邊不超過 150 mm。
- Name
- should_remesh
- Type
- boolean
- 預設值 true (meshy-6-lite), false (other models)
- Description
是否在生成後對模型進行 remesh。
false會保持生成時的 mesh 不變。Smart Topology 模型會忽略此設定。試用並預覽
should_remesh = true- Name
- topology
- Type
- string
- 預設值 triangle
- Description
重新生成 mesh 後的模型面類型,
triangle或quad。Smart Topology 模型只生成三角形,因此在 Smart Topology 模型上使用quad會返回400。使用texture_model: "meshy-n1"時,如果模型被 remesh(meshy-6-lite預設會執行),quad會返回400。試用並預覽在
ai_model為meshy-7.1且should_remesh為true時生效。選擇一個值會同時設定它。
- Name
- decimation_mode
- Type
- integer
- Description
按等級設定的自適應面數。設定此項時,Meshy 會忽略
target_polycount。可用值:
1:極致2:高3:中4:低
- Name
- save_pre_remeshed_model
- Type
- boolean
- 預設值 false
- Description
是否同時在
output.model_urls.pre_remeshed_glb中返回 remesh 之前的 GLB。
- Name
- target_polycount
- Type
- integer
- Description
目標面數。其取值範圍和預設值取決於 mesh 的建構方式:
Mesh 範圍 預設值 Remeshed 100至30000030000meshy-t2.5或meshy-smart-topology-latest100至3000015000meshy-t2100至150004000超出範圍的值會返回
400。對於 low-poly 的遊戲資產,建議使用 Smart Topology 模型,而不是對標準模型進行 remesh。請參見模型。
- Name
- auto_polycount
- Type
- boolean
- Description
設為
true時,Meshy 會在meshy-t2.5的取值範圍內,根據輸入圖像自動選擇面數。此選項僅適用於meshy-t2.5(或解析為該模型的meshy-smart-topology-latest)。使用其他ai_model,或與target_polycount同時使用時,請求會返回400(parameters_conflict)。如果 Meshy 無法為該圖像推薦面數,任務會使用
meshy-t2.5的預設值;請求仍會成功。任務的output.target_polycount會顯示任務實際使用的面數。預設為false。
- Name
- pose_mode
- Type
- string
- Description
角色模型的姿勢,
a-pose或t-pose。留空表示不設定姿勢。試用並預覽
- Name
- image_enhancement
- Type
- boolean
- 預設值 true
- Description
是否在生成前對輸入圖像進行清理。
false會完全按原樣使用圖像。meshy-6-lite和 Smart Topology 模型會忽略此設定。
- Name
- remove_lighting
- Type
- boolean
- 預設值 true
- Description
是否從基礎色 texture 中移除高光和陰影。
texture_model所支援的 texture 模型不使用此設定,因此 Meshy 會忽略它。
- Name
- moderation
- Type
- boolean
- 預設值 false
- Description
是否在生成前對以下輸入進行有害內容審查:
- 輸入圖像
texture_image_urltexture_prompt
- Name
- auto_size
- Type
- boolean
- 預設值 false
- Description
是否估算物體的真實世界高度,並據此縮放模型。
auto_size = true- Name
- origin_at
- Type
- string
- 預設值 bottom
- Description
模型 origin 的放置位置,
bottom或center。
- Name
- multi_view_thumbnails
- Type
- boolean
- 預設值 false
- Description
是否同時渲染正面、右側、背面和左側的預覽圖,並在
output.thumbnail_urls中返回。這會為任務增加約 5 秒的處理時間。
- Name
- thumbnail_resolution
- Type
- integer
- 預設值 512
- Description
任務預覽圖像的寬度和高度(像素):
512或1024。它適用於output.thumbnail_url以及你請求的任何可選預覽圖。任何其他值都會返回400。
返回值
202 Accepted,並返回任務物件。任務最初為 PENDING 狀態,input 為你的請求內容,output 設為 null。
兩個回應標頭可協助你讀取任務:
Location:任務在 Tasks 上的 URLRetry-After:首次讀取前需要等待的秒數
失敗情形
- Name
400 - Bad Request- Description
請求無法執行。例如:
- 既沒有傳送
image_url也沒有傳送input_task_id - 帶貼圖的請求未傳送
texture_model - 同時傳送了
texture_prompt和texture_image_url - 圖像無法下載、超過 20 MB,或超出像素限制
- 該模型不支援所選
geometry_resolution - texture 模型不支援請求中的某個選項,例如
enable_pbr: true,或在meshy-n1上使用4ktexture
錯誤資訊會說明具體發現的問題。請參見 Errors。
- 既沒有傳送
- Name
401 - Unauthorized- Description
API 金鑰缺失或無效。請檢查
Authorization請求標頭。
- Name
402 - Payment Required- Description
以下情形之一適用:
- 帳戶 積分 不足。
- 帳戶達到了 積分 限額。
- 帳戶使用的是免費方案。
請檢查你的 積分 和方案,然後重試。
- Name
403 - Forbidden- Description
內容審核攔截了 prompt 或輸入圖像。請更改輸入內容,然後重試。
- Name
404 - Not Found- Description
input_task_id與你的任何任務都不符合。
- Name
429 - Too Many Requests- Description
達到了以下限制之一:
- 你傳送的請求過多。請等待
Retry-After中指定的秒數,然後重試。 - 你排隊或正在執行的任務過多。請等待部分任務完成後再重試。
- 在積分用盡的無限額方案上,你已達到可在無 積分 情況下執行的任務數量上限。請等待某個任務完成,或增加 積分。
- 你傳送的請求過多。請等待
Texture models
ai_model 用於選擇建構網格的模型,texture_model 用於選擇為其繪製貼圖的模型。texture_model 沒有預設值,因此每個需要紋理的請求都必須傳入它。要為你的專案選擇合適的組合,請參閱 Models。
下表展示了每個 ai_model 在每個端點上可配合使用的紋理模型。任何其他組合都會回傳 400。
ai_model | Image to 3D | Multi-Image to 3D | Text to 3D |
|---|---|---|---|
meshy-7.1、latest 或 meshy-standard-latest | meshy-7、meshy-n1 或 meshy-6-lite | meshy-7 或 meshy-n1 | meshy-7、meshy-n1 或 meshy-6-lite |
meshy-6 | meshy-7、meshy-n1 或 meshy-6-lite | meshy-7 或 meshy-n1 | meshy-7、帶 texture_image_url 的 meshy-n1,或 meshy-6-lite |
meshy-6-lite | meshy-7、meshy-n1 或 meshy-6-lite | meshy-7 或 meshy-n1 | meshy-7、帶 texture_image_url 的 meshy-n1,或 meshy-6-lite |
meshy-t2.5、meshy-t2 或 meshy-smart-topology-latest | meshy-7、meshy-n1 或 meshy-6-lite | 無。Multi-Image to 3D 沒有 Smart Topology 模型。 | meshy-7、meshy-n1 或 meshy-6-lite |
Retexture 對任何模型都接受 meshy-7、meshy-n1 或 meshy-6-lite。
每個紋理模型支援一組不同的選項,下表列出了這些選項。如果請求向某個紋理模型提出了它不支援的選項,將回傳 400。
| 選項 | meshy-7 | meshy-n1 | meshy-6-lite |
|---|---|---|---|
texture_resolution | 2k、4k 或 8k | 2k | 2k |
enable_pbr: true | 支援 | 不支援 | 支援 |
texture_prompt | 支援 | 不支援 | 支援 |
texture_image_url | 支援 | 支援,作為正視圖 | 支援 |
多張參考圖:texture_image_urls 或 multiview_image_urls | 支援 | 支援 | 不支援 |
對已重構網格的模型使用 topology: "quad" | 支援 | 不支援 | 支援 |
Meshy N1 可為最多 7,999,999 個三角面的模型生成紋理。如果生成的模型超過該大小,任務會失敗,Meshy 會退還其積分。
紋理模型不會改變價格。一個帶紋理的任務的費用為網格費用加上對應解析度的紋理費用。請參閱 Pricing。
獲取結果
讀取 影象生成 3D 任務的方式與其他所有 v2 任務相同,均透過 Tasks 路由完成。若只想列出 影象生成 3D 任務,可使用 type=image-to-3d 進行篩選。
| 目的 | 呼叫 |
|---|---|
| 獲取單一任務 | GET /openapi/v2/tasks/{id} |
| 等待更新 | GET /openapi/v2/tasks/{id}/stream 或使用 webhook |
| 列出你的任務 | GET /openapi/v2/tasks?type=image-to-3d |
| 刪除任務 | DELETE /openapi/v2/tasks/{id} |
Image to 3D 輸出
當任務成功後,output 中包含以下欄位。task object 的其餘部分對每種任務類型都是一樣的。output 中的 URL 會在 expires_at 之後失效。
curl https://api.meshy.ai/openapi/v2/tasks/01a1aeac-afb0-77bf-a47b-47a43ee563bc \
-H "Authorization: Bearer ${MESHY_API_KEY}"載入中…- Name
- model_urls
- Type
- object
- Description
生成檔案的簽名 URL,
target_formats中每種格式對應一個,以格式作為鍵。還可能出現兩個額外的鍵:mtl:帶貼圖的obj的 material 檔案pre_remeshed_glb:當你傳送了save_pre_remeshed_model: true且模型經過了 remesh 時,remesh 之前的 GLB
- Name
- thumbnail_url
- Type
- string
- Description
模型 PNG 預覽圖的簽名 URL,背景為透明。
- Name
- thumbnail_urls
- Type
- object | null
- Description
各預覽圖的簽名 URL,以視角作為鍵:
frontrightbackleft
除非你傳送了
multi_view_thumbnails: true,否則為null。渲染失敗的視角會被省略。
- Name
- texture_urls
- Type
- array
- Description
每個 texture 集一項,其中包含以下每張貼圖的簽名 URL:
base_colormetallicroughnessnormalmetallic_roughnessemission
未生成的貼圖為
null。對於沒有 texture 的模型,該陣列為空。
- Name
- target_polycount
- Type
- integer
- Description
Smart Topology 任務(
meshy-t2或meshy-t2.5)生成時使用的面數:可能是你傳送的target_polycount、auto_polycount選定的值,或模型的預設值。其他任務類型不包含此欄位。