Text to 3D API
透過一次呼叫,將文字 prompt 轉換為 3D 模型。
Text to 3D 已經運行在 /openapi/v2/text-to-3d 上,因此你的建立請求可以繼續正常運作。有兩條新規則:同時傳送 texture_prompt 和 texture_image_url 會回傳 400;而省略 mode 的帶材質的一次性呼叫請求,則需要提供 texture_model。請像處理其他任務一樣,透過 Tasks 讀取其任務資訊,並從 output 中讀取結果。設定為 v2 的 webhook 會以該格式投遞 Text to 3D 任務。詳見 Text to 3D 的變更內容。
創建 Text to 3D 任務
curl https://api.meshy.ai/openapi/v2/text-to-3d \
-X POST \
-H "Authorization: Bearer ${MESHY_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"prompt": "a stylized adult male explorer with short brown hair and a stubble beard, wearing an orange jacket, beige cargo pants and brown boots, full body, standing",
"ai_model": "meshy-7.1",
"should_texture": true,
"texture_model": "meshy-7"
}'參數
- Name
- should_texture
- Type
- boolean
- 預設值 true
- Description
是否為模型生成 texture。
true回傳帶 texture 的模型,false則只回傳 mesh。設為false時,Meshy 會忽略texture_model以及其他 texture 相關參數。如果想在生成 texture 之前先檢查 mesh,可以傳送false,然後用 Retexture 對已完成的任務進行貼圖,將其id用作input_task_id。如果同時傳送了mode,Meshy 會忽略此設定。試用並預覽
- Name
- mode
- Type
- string
- ⚠ 已棄用
- Description
兩步式任務中的步驟,供已經使用 preview 和 refine 的整合方使用。請改為傳送
should_texture。可選值:
preview:生成未帶 texture 的 meshrefine:為 preview 任務的 mesh 新增 texture
- Name
- prompt
- Type
- string
- 必選
- Description
一次性(one-call)任務和 preview 任務為必填項。描述要生成的模型的文字,最多 800 個字元。超出長度將回傳
400。refine 會改用其對應 preview 的 prompt。
- Name
- preview_task_id
- Type
- string
- 必選
- ⚠ 已棄用
- Description
請改為傳送
should_texture: true,或使用 Retexture 為現有任務新增 texture。refine 任務為必填項。待貼圖的 preview 任務的 ID。該任務必須是你自己的 preview 任務,且狀態為SUCCEEDED。
- 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 列印件),請參閱模型。
在 refine 中,
ai_model選擇的是 texture 模型,因為 mesh 來自 preview。留空則使用與 preview 相符的模型進行貼圖。關於 refine 可接受的取值,請參閱 Legacy preview 和 refine。
- Name
- model_type
- Type
- string
- ⚠ 已棄用
- Description
請留空。由
ai_model選擇模型。
- Name
- geometry_resolution
- Type
- string
- 預設值 standard
- Description
生成多少 geometry 細節。僅適用於一次性(one-call)任務和 preview 任務。帶此參數的 refine 會回傳
400。試用並預覽可選值:
standard2k:增加 Ultra pass4k:增加 Ultra pass,然後再增加超解析度 pass
2k和4k需要meshy-7.1或latest。使用其他模型時將回傳400。
- Name
- should_remesh
- Type
- boolean
- 預設值 true (meshy-6-lite), false (other models)
- Description
生成後是否對模型進行 remesh。
false保持生成時的 mesh 不變。僅適用於一次性(one-call)任務和 preview 任務。Smart Topology 模型會忽略此設定。試用並預覽
should_remesh = true- Name
- topology
- Type
- string
- 預設值 triangle
- Description
重新生成 mesh 後模型的面類型,
triangle或quad。Smart Topology 模型只生成三角形,因此在 Smart Topology 模型下使用quad會回傳400。使用texture_model: "meshy-n1"時,quad會回傳400。試用並預覽在
ai_model為meshy-7.1且should_remesh為true時生效。選擇一個值會同時設定它。
- Name
- decimation_mode
- Type
- integer
- Description
按等級設定的自適應面數。設定此項時,Meshy 會忽略
target_polycount。可選值:
1:ultra2:high3:medium4:low
- Name
- target_polycount
- Type
- integer
- Description
目標面數。僅適用於一次性(one-call)任務和 preview 任務。取值範圍和預設值取決於 mesh 的建構方式:
Mesh 範圍 預設值 Remeshed 100到30000030000meshy-t2.5或meshy-smart-topology-latest100到3000015000meshy-t2100到150004000超出範圍的值將回傳
400。對於 low-poly 遊戲資產,建議使用 Smart Topology 模型,而不是對標準模型做 remesh。請參閱模型。
- Name
- pose_mode
- Type
- string
- Description
角色模型的姿勢,
a-pose或t-pose。留空表示不設定姿勢。僅適用於一次性(one-call)任務和 preview 任務。試用並預覽
should_texture = true- Name
- texture_model
- Type
- string
- 必選
- Description
除非
should_texture為false,否則為必填項。為一次性(one-call)任務生成 texture 的模型。每個ai_model都接受以下各個值。可選值:
meshy-7:Meshy 7,帶 PBR 貼圖、文字 prompt,texture 最高可達 8Kmeshy-n1:Meshy N1,僅根據參考圖像生成 2K 基礎色 texturemeshy-6-lite:Meshy 6 Lite,2K texture
使用
meshy-6或meshy-6-lite時,meshy-n1需要texture_image_url,因為這些模型不會根據 prompt 生成參考圖像。未提供texture_model的帶貼圖請求會回傳400,texture 模型不支援的選項也會回傳400。設定了mode時,Meshy 會忽略texture_model。請參閱 Texture 模型。
- Name
- texture_prompt
- Type
- string
- Description
用於指導 texture 生成的文字,最多 800 個字元。超出長度將回傳
400。請只傳送texture_prompt或texture_image_url其中之一,不要同時傳送兩者。同時傳送會回傳400。使用meshy-n1時傳送此參數會回傳400。
- Name
- texture_image_url
- Type
- string
- Description
用於指導 texture 生成的圖像,可以是公開 URL 或 Data URI(
data:image/png;base64,...)。使用meshy-n1時,Meshy 會以該圖像作為正視圖來生成 texture。當一次性(one-call)任務使用texture_model: "meshy-n1",且ai_model為meshy-6或meshy-6-lite時,此參數為必填項。圖像必須為 JPG、JPEG、PNG 或 WebP 檔案,大小不超過 20 MB,每邊至少 32 像素,像素總數(寬 × 高)不超過 178,956,970。
- Name
- enable_pbr
- Type
- boolean
- 預設值 false
- Description
是否同時生成金屬度、粗糙度和法線貼圖。使用
meshy-n1時,設為true會回傳400。試用並預覽
- Name
- texture_resolution
- Type
- string
- 預設值 2k
- Description
基礎色 texture 的尺寸。帶此參數的 preview 會回傳
400。試用並預覽可選值:
2k4k8k
無論是在一次性(one-call)任務中由
texture_model選定,還是在 refine 中由ai_model選定,使用meshy-n1或meshy-6-lite時4k和8k都會回傳400。
- Name
- remove_lighting
- Type
- boolean
- 預設值 true
- Description
是否從基礎色 texture 中移除高光和陰影。只有
meshy-6使用此設定。Meshy 7 和 Smart Topology 模型會忽略它。使用meshy-6-lite時傳送此參數會回傳400。
- Name
- target_formats
- Type
- string[]
- 預設值 ["glb", "obj", "fbx", "stl", "usdz"]
- Description
要生成的檔案格式。
可選值:
glbobjfbxstlusdz3mf
Text to 3D 不會套用其他 v2 端點對列印檔案所用的 150 mm 上限。STL 檔案會保留模型原始尺寸,而 Meshy 會將
3mf檔案縮放至 75 mm 高。
- Name
- alpha_thumbnail
- Type
- boolean
- 預設值 false
- Description
是否同時渲染一張背景透明的預覽圖,結果會回傳在
output.alpha_thumbnail_url中。
- Name
- thumbnail_resolution
- Type
- integer
- 預設值 512
- Description
任務預覽圖的寬高(像素):
512或1024。該設定適用於output.thumbnail_url以及你請求的任何可選預覽圖。其他任何值都會回傳400。
- Name
- moderation
- Type
- boolean
- 預設值 false
- Description
是否在生成前對以下輸入內容進行有害內容篩查:
prompttexture_prompttexture_image_url
- Name
- auto_size
- Type
- boolean
- 預設值 false
- Description
是否估算物體的真實世界高度,並據此縮放模型。
auto_size = true- Name
- origin_at
- Type
- string
- 預設值 bottom
- Description
模型原點的放置位置,
bottom或center。
回傳值
回傳 202 Accepted,包含任務物件。任務起始狀態為 PENDING,input 中包含你的請求內容,output 為 null。回應中還包含 result,其值與 id 相同,供 v2 之前編寫的客戶端使用。
以下回應標頭可幫助你追蹤任務:
失敗模式
- Name
400 - Bad Request- Description
請求無法執行。例如:
- 缺少
prompt - 帶 texture 的一次性(one-call)任務未傳送
texture_model - 一次性(one-call)任務傳送了
texture_model: "meshy-n1",並使用meshy-6或meshy-6-lite,但未提供texture_image_url - texture 模型不支援請求中的某個選項,例如對
meshy-n1使用enable_pbr: true preview_task_id與你任何狀態為SUCCEEDED的 preview 任務都不相符。錯誤訊息會說明該任務不存在、尚未完成,還是不是 preview 任務- 同時傳送了
texture_prompt和texture_image_url - 在 preview 中傳送了
texture_resolution - 在 refine 中傳送了
geometry_resolution,或該參數傳送給了不支援它的模型 - 一次性(one-call)任務請求了
meshy-7(請改為傳送meshy-7.1) - 一次性(one-call)任務傳送了 Text to 3D 未定義的參數,例如拼錯的參數名稱。設定了
mode時,Meshy 會忽略它。
錯誤訊息會說明具體發現的問題。請參閱Errors。
- 缺少
- Name
401 - Unauthorized- Description
API key 缺失或無效。請檢查
Authorization請求標頭。
- Name
402 - Payment Required- Description
以下情況之一適用:
- 帳戶 credits 不足。
- 帳戶已達到 credits 限額。
- 帳戶使用的是免費方案。
請檢查你的 credits 和方案,然後重試。
- Name
403 - Forbidden- Description
內容審核攔截了 prompt 或輸入圖像。請修改輸入內容後重試。
- Name
429 - Too Many Requests- Description
達到以下限制之一:
- 你傳送的請求過多。請等待
Retry-After中給出的秒數後重試。 - 你排隊或正在執行的任務過多。請等待部分任務完成後重試。
- 在無限制方案下且 credits 已用盡時,達到了無需 credits 即可執行的任務數量上限。請等待某個任務完成,或增加 credits。
- 你傳送的請求過多。請等待
獲取結果
讀取 Text to 3D 任務的方式與其他所有 v2 任務相同,均透過 Tasks 路由完成。要列出 Text to 3D 任務,可依 type 進行篩選:
text-to-3d:全部三種 Text to 3D 任務text-to-3d-preview:僅 preview 任務text-to-3d-refine:僅 refine 任務
單次呼叫任務沒有自己的篩選條件。
| 目的 | 呼叫 |
|---|---|
| 獲取單個任務 | GET /openapi/v2/tasks/{id} |
| 等待更新 | GET /openapi/v2/tasks/{id}/stream 或使用 webhook |
| 列出你的任務 | GET /openapi/v2/tasks?type=text-to-3d |
| 刪除任務 | DELETE /openapi/v2/tasks/{id} |
Text to 3D output
當任務成功後,output 會包含以下欄位。task 物件的其餘部分對所有任務類型都是一樣的。
對於文字生成 3D,expires_at 始終為 null。Meshy 仍會在任務完成 3 天後刪除該任務,因此請在此期限內下載檔案。企業帳戶的任務會被保留。參閱資產保留期。
curl https://api.meshy.ai/openapi/v2/tasks/01a1aeae-2720-72bd-952d-008784fbd525 \
-H "Authorization: Bearer ${MESHY_API_KEY}"載入中…- Name
- model_urls
- Type
- object
- Description
生成檔案的簽名 URL,按格式分類存放。
target_formats中的每種格式都會對應一個 URL,若未指定該欄位,則對應預設格式。帶貼圖的obj還會附帶一個mtl鍵,用於存放其材質檔案的 URL。
- Name
- thumbnail_url
- Type
- string
- Description
模型預覽圖的簽名 URL。
- Name
- alpha_thumbnail_url
- Type
- string | null
- Description
帶透明背景的預覽圖簽名 URL。除非你發送了
alpha_thumbnail: true,否則該值為null。
- Name
- texture_urls
- Type
- array
- Description
每個貼圖集對應一項,其中包含以下各貼圖的簽名 URL:
base_colormetallicroughnessnormalmetallic_roughnessemission
未生成的貼圖為
null。對於預覽以及未貼圖的一次性呼叫任務,該陣列為空。
舊版 preview 和 refine
mode 已deprecated,但對於已經使用它的整合仍然可以正常運作。新的整合使用 should_texture 透過一次呼叫生成模型,其花費與一次 preview 加一次 refine 相同。
- 使用
"mode": "preview"、你的prompt以及 geometry 參數(例如geometry_resolution和should_remesh)建立一個 preview。preview 會生成未貼圖的 mesh。 - 等待該 preview 的狀態變為
SUCCEEDED。 - 使用
"mode": "refine"、將該 preview 的id作為preview_task_id,以及 texture 參數,建立一個 refine。refine 會沿用該 preview 的 prompt 和 mesh。不設定ai_model時,將使用與該 preview 相匹配的模型進行 texture 處理;對於 Smart Topology 的 preview,這即是 Meshy 7。
在 refine 中,ai_model 指定 texture 模型,Meshy 會忽略 texture_model:
meshy-7:Meshy 7latest:最新的 texture 模型,目前為 Meshy 7meshy-6:Meshy 6meshy-6-lite:Meshy 6 Litemeshy-n1:Meshy N1,僅根據參考圖生成 2K 的 base color texture
Smart Topology 的 preview(meshy-t2、meshy-t2.5)不支援 Meshy 6 Lite 貼圖:對其使用 meshy-6-lite 進行 refine 時,會改用 Meshy 6 進行 texture 處理,因此在 enable_pbr: true 時也會回傳一張 emission map。對 Meshy 6、Meshy 6 Lite 或 Meshy 7 的 preview 使用 meshy-6-lite 進行 refine 則不會回傳 emission map,對未設定 ai_model 的 Smart Topology preview 進行 refine 同樣不會回傳。
要使用 Meshy N1 進行 refine,請傳送 "ai_model": "meshy-n1"。Meshy 會根據 texture_image_url,或根據 meshy-7.1 或 latest 的 preview 所儲存的參考圖進行 texture 處理。任何其他 preview 在未傳送 texture_image_url 的情況下都會回傳 400。Meshy N1 僅生成 2K 的 base color texture。同時傳送以下任意一項都會回傳 400:
texture_promptenable_pbr: trueremove_lighting: truetexture_resolution為4k或8k
preview 的三角面數最多為 7,999,999。對已 remesh 為四邊形網格的 preview 進行此操作會回傳 400。要對一次呼叫的任務使用 Meshy N1 進行 texture 處理,請使用 Retexture。
在 preview 被刪除之前,你可以對同一個 preview 進行多次 refine,例如使用不同的 texture prompt。你無法對一次呼叫的任務進行 refine。Meshy 會在 Text to 3D 任務完成 3 天後將其刪除,Enterprise 帳戶則會保留其任務。對已刪除的 preview 進行 refine 會回傳 400;在保留期結束後,還會附帶錯誤碼 input_task_expired。請參閱資產保留期。
Legacy routes
v2 之前的文字生成 3D 讀取路由仍然可用,因此你現有的程式碼可以繼續運作。對於新程式碼,請使用 Tasks。
| 路由 | 替代方案 |
|---|---|
GET /openapi/v2/text-to-3d/{id} | GET /openapi/v2/tasks/{id} |
GET /openapi/v2/text-to-3d/{id}/stream | GET /openapi/v2/tasks/{id}/stream |
GET /openapi/v2/text-to-3d | GET /openapi/v2/tasks?type=text-to-3d |
DELETE /openapi/v2/text-to-3d/{id} | DELETE /openapi/v2/tasks/{id} |
這些路由會回傳原始文字生成 3D 任務物件的欄位,其中 task_error 採用其 v2 形式。它們也會回傳以下欄位,與 Tasks 相同:
inputoutputexpires_at
列表路由會回傳一個普通陣列,不包含 has_more。
/v2/text-to-3d 下(不帶 /openapi)的相同路由已被已棄用。它們的回應中會帶有 Deprecation 標頭,以及一個指向 /openapi/v2/text-to-3d 路由的 Link 標頭。