Animation API
為已綁定骨骼的角色套用動畫,並列出可套用的動畫。
創建 Animation 任務
創建一個 Animation 任務,將動畫套用到你先前已綁骨的角色上。動畫可以是以下之一:
- 來自動畫庫的預設動作(
action_id) - 合併到一個檔案中的多個預設動作(
action_ids) - 你使用 Text to Motion API
生成的動作片段(motion_task_id)
你還可以對輸出進行後處理。該任務在後台執行。關於任務通常需要多長時間,請參閱處理時間。
Request
# Animate a rigged model with required params only
curl https://api.meshy.ai/openapi/v1/animations \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"rig_task_id": "018b314a-a1b5-716d-c222-2f1776f7f579",
"action_id": 92
}'
# Apply several preset actions and get one file with one clip per action
curl https://api.meshy.ai/openapi/v1/animations \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"rig_task_id": "018b314a-a1b5-716d-c222-2f1776f7f579",
"action_ids": [10, 25, 92]
}'
# Apply a generated Text to Motion clip instead of a preset action
curl https://api.meshy.ai/openapi/v1/animations \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"rig_task_id": "018b314a-a1b5-716d-c222-2f1776f7f579",
"motion_task_id": "018c425b-b2c6-727e-d333-3c1887i9h791"
}'
# With post-processing to change FPS
curl https://api.meshy.ai/openapi/v1/animations \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"rig_task_id": "018b314a-a1b5-716d-c222-2f1776f7f579",
"action_id": 92,
"post_process": {
"operation_type": "change_fps",
"fps": 24
}
}'
Response
{
"result": "018c425b-b2c6-727e-d333-3c1887i9h791"
}
參數
- Name
- rig_task_id
- Type
- string
- 必選
- Description
要為其角色設定動畫的 Rigging 任務的 ID,來自
POST /openapi/v1/rigging。該任務的狀態必須為SUCCEEDED。
請只發送 action_id、action_ids 和 motion_task_id 其中之一。
- Name
- action_id
- Type
- integer
- 必選
- Description
除非你發送
action_ids或motion_task_id,否則此項為必填。要套用的預設動畫的 ID。完整動畫清單請參閱 Animation Library 參考 或列出動畫。動畫的
rig_type必須與該骨架相符,否則請求將回傳400。任何quadruped動畫都可用於任何四足骨架,無論其category所命名的是哪種動物。
- Name
- action_ids
- Type
- array of integers
- 必選
- Description
除非你發送
action_id或motion_task_id,否則此項為必填。一次要套用的 1 到 10 個預設動畫的 ID,不可重複。超過 10 個 ID,或存在重複 ID,將回傳400。ID 清單請參閱 Animation Library 參考 。Meshy 會回傳一個檔案,其中每個動作對應一個動畫片段,適合用於遊戲引擎中的狀態機。Meshy 會對清單中的每個動作單獨計費。參見 Pricing。
只含一個 ID 的清單,效果與將該 ID 作為
action_id發送相同。若某個動畫的
rig_type與骨架不符,將回傳400。
- Name
- motion_task_id
- Type
- string
- 必選
- Description
除非你發送
action_id或action_ids,否則此項為必填。要套用的 Text to Motion 任務片段的 ID,用以取代預設動作。該任務的狀態必須為SUCCEEDED,且骨架必須為雙足骨架。Meshy 會將該片段重定向到已綁骨的角色上。建立此任務時會複製該片段,因此即使之後 Text to Motion 任務過期或你刪除了它,也不會影響此任務。Meshy 會保留 Text to Motion 任務的檔案 3 天,請在此之前套用該片段。
在 GLB 和 FBX 檔案中,該片段命名為
retarget_clip。
- Name
- post_process
- Type
- object
- Description
對動畫輸出進行後處理。不填則取得標準動畫檔案。
使用
motion_task_id時,重定向可能只會生成 GLB 格式的動畫。如果你發送了post_process但沒有可用的 FBX 檔案,任務將以task_error失敗,Meshy 會退還你的積分。不發送post_process時,任務會成功,且animation_fbx_url為空。
post_process is set- Name
- operation_type
- Type
- string
- Description
要執行的操作。不填寫時,Meshy 不會生成額外檔案。不在以下清單中的值將回傳
400。可用值:
change_fps:將幀率變更為fpsfbx2usdz:將動畫轉換為 USDZextract_armature:將 armature 匯出為 FBX 檔案
- Name
- fps
- Type
- integer
- 預設值 30
- Description
要變更為的幀率,可選
24、25、30或60之一。僅當operation_type為change_fps時適用。其他任何值都會回傳400。
使用 action_ids 時,任務會回傳一個合併檔案,而非每個動作一個檔案。animation_glb_url 和 animation_fbx_url 各自指向一個檔案,該檔案以獨立片段的形式容納所有請求的動作。在該檔案中:
- 片段順序:按
action_ids陣列的順序排列,而非 ID 的數字順序。 - 片段名稱:使用動畫在庫中的名稱。這些名稱與你從 Meshy 網頁應用程式將角色的所有動畫匯出為一個檔案時得到的名稱一致。如果兩個請求的 ID 有相同的片段名稱,Meshy 會將
action_id加入後一個片段名中以保持名稱唯一。 - 後處理:Meshy 會將其套用於合併後的檔案,而非每個單獨的片段。
回傳值
回應的 result 欄位中存放著新建 Animation 任務的 ID。
失敗模式
- Name
400 - Bad Request- Description
請求無法執行。錯誤訊息會說明發現了哪個問題。例如:
- 缺少參數:缺少
rig_task_id,或未發送action_id、action_ids、motion_task_id中的任何一個。 - 參數衝突:請求中同時包含了
action_id、action_ids、motion_task_id中的多個。請只發送一個。 - Rigging 任務無效:
rig_task_id不是有效的任務 ID,不是 Rigging 任務,或指向的任務尚未成功。 - 動作 ID 無效:
action_id,或action_ids中的某一項,不是有效的動畫。 - 動作過多:
action_ids中的 ID 超過 10 個。 - 動作重複:
action_ids中存在重複的 ID。 - 動作任務尚未就緒:
motion_task_id對應的任務尚未達到SUCCEEDED狀態。 - 骨架不受支援:
motion_task_id需要雙足骨架,Meshy 會拒絕四足骨架。 - 骨架類型不符:某個動畫的
rig_type與該骨架不符。
請修正請求後重新發送。參見 Errors。
- 缺少參數:缺少
- Name
401 - Unauthorized- Description
API 金鑰缺失或無效。請檢查
Authorization請求標頭。
- Name
402 - Payment Required- Description
例如:
- 積分不足:帳戶沒有足夠的積分來完成此任務,或帳戶已達到積分限額。請檢查你的 Balance,然後重試。
- 免費方案:建立任務需要付費方案。請在訂閱設定中升級你的方案,然後重試。
- Name
403 - Forbidden- Description
rig_task_id對應的任務是浮雕模型,此端點無法為其設定動畫。錯誤資訊為This model type does not support this operation。請為其他模型綁骨。
- Name
404 - Not Found- Description
Meshy 找不到請求所需的任務或檔案。可能是以下情況之一:
- Meshy 在你的任務中找不到
rig_task_id對應的任務。請檢查該 ID。 rig_task_id任務的檔案在其expires_at之後已被 Meshy 刪除。請重新為角色綁骨。- Meshy 找不到
motion_task_id對應的任務。請檢查該 ID。 - 動作片段已過期,因為 Meshy 只保留 Text to Motion 任務的檔案 3 天。請建立另一個 Text to Motion 任務。
- Meshy 在你的任務中找不到
- Name
429 - Too Many Requests- Description
你已超出速率限制。請稍候後重試。參見速率限制。
取得 Animation 任務
根據 ID 回傳一個 Animation 任務。
Request
curl https://api.meshy.ai/openapi/v1/animations/018c425b-b2c6-727e-d333-3c1887i9h791 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
{
"id": "018c425b-b2c6-727e-d333-3c1887i9h791",
"type": "animate",
"status": "SUCCEEDED",
"created_at": 1747032440896,
"progress": 100,
"started_at": 1747032441210,
"finished_at": 1747032457530,
"expires_at": 1747291657530,
"task_error": null,
"consumed_credits": 3,
"result": {
"animation_glb_url": "https://assets.meshy.ai/0630d47c-84b8-4d37-bc02-69e45d9272c1/tasks/018c425b-b2c6-727e-d333-3c1887i9h791/output/Animation_Reaping_Swing_withSkin.glb?Expires=...",
"animation_fbx_url": "https://assets.meshy.ai/0630d47c-84b8-4d37-bc02-69e45d9272c1/tasks/018c425b-b2c6-727e-d333-3c1887i9h791/output/Animation_Reaping_Swing_withSkin.fbx?Expires=...",
"processed_usdz_url": "https://assets.meshy.ai/0630d47c-84b8-4d37-bc02-69e45d9272c1/tasks/018c425b-b2c6-727e-d333-3c1887i9h791/output/processed.usdz?Expires=...",
"processed_armature_fbx_url": "https://assets.meshy.ai/0630d47c-84b8-4d37-bc02-69e45d9272c1/tasks/018c425b-b2c6-727e-d333-3c1887i9h791/output/processed_armature.fbx?Expires=...",
"processed_animation_fps_fbx_url": "https://assets.meshy.ai/0630d47c-84b8-4d37-bc02-69e45d9272c1/tasks/018c425b-b2c6-727e-d333-3c1887i9h791/output/processed_60fps.fbx?Expires=..."
}
}
刪除 Animation 任務
永久刪除一個 Animation 任務,包括其模型和資料。刪除操作無法復原。
Request
curl --request DELETE \
--url https://api.meshy.ai/openapi/v1/animations/018b314a-a1b5-716d-c222-2f1776f7f579 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
// 200 OK on success, with an empty body.
//
// 409 Conflict when the task is IN_PROGRESS. The task keeps running:
{
"message": "Task is IN_PROGRESS and cannot be deleted. Credits for a task the worker has already started are not refundable; wait for it to reach SUCCEEDED, FAILED or CANCELED, then delete it."
}
路徑參數
- Name
- id
- Type
- path
- Description
要刪除的任務的 ID。
任務狀態
刪除一個 PENDING 任務會退還建立該任務時所使用的積分。
IN_PROGRESS 任務無法被刪除。該請求會回傳 409 Conflict,
且任務會繼續運作。Meshy 不會為已經開始的任務退款,
因此刪除它既會損失積分,也會損失結果。請等待它
變為 SUCCEEDED、FAILED 或 CANCELED 狀態後,再進行刪除。
刪除處於最終狀態(SUCCEEDED、FAILED 或 CANCELED)的任務
不會退還其積分。
回傳值
任務刪除成功時回傳 200 OK;當任務處於
IN_PROGRESS 狀態時回傳 409 Conflict。
查詢 Animation 任務列表
回傳你的 Animation 任務的分頁列表,依最新優先排序。如需翻頁瀏覽列表,請使用 page_num 和 page_size。
透過 API 建立的任務不會出現在網頁應用程式的我的資產中,因此你需要透過 API 來管理它們。如果你遺失了某個任務的 ID,可以使用此 endpoint 來查找它。
Request
curl "https://api.meshy.ai/openapi/v1/animations?page_num=1&page_size=20" \
-H "Authorization: Bearer ${YOUR_API_KEY}"
串流傳輸 Animation 任務
以伺服器發送事件(SSE)的形式串流傳輸 Animation 任務的更新。
Request
curl -N https://api.meshy.ai/openapi/v1/animations/018c425b-b2c6-727e-d333-3c1887i9h791/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.
// These examples are shortened. Each event holds the full task object.
event: message
data: {
"id": "018c425b-b2c6-727e-d333-3c1887i9h791",
"progress": 0,
"status": "PENDING"
}
event: message
data: {
"id": "018c425b-b2c6-727e-d333-3c1887i9h791",
"progress": 50,
"status": "IN_PROGRESS"
}
event: message
data: { // Example of a SUCCEEDED task stream item, with the same structure as the Animation task object
"id": "018c425b-b2c6-727e-d333-3c1887i9h791",
"type": "animate",
"status": "SUCCEEDED",
"created_at": 1747032440896,
"progress": 100,
"started_at": 1747032441210,
"finished_at": 1747032457530,
"expires_at": 1747291657530,
"task_error": null,
"consumed_credits": 3,
"result": {
"animation_glb_url": "https://assets.meshy.ai/.../Animation_Reaping_Swing_withSkin.glb?...",
"animation_fbx_url": "https://assets.meshy.ai/.../Animation_Reaping_Swing_withSkin.fbx?...",
"processed_usdz_url": "https://assets.meshy.ai/.../processed.usdz?...",
"processed_armature_fbx_url": "https://assets.meshy.ai/.../processed_armature.fbx?...",
"processed_animation_fps_fbx_url": "https://assets.meshy.ai/.../processed_60fps.fbx?..."
}
}
參數
- Name
- id
- Type
- path
- Description
來自建立回應的任務 ID。
回傳
以伺服器發送事件的形式回傳 Animation 任務物件 的串流。
每個事件都包含完整的任務物件,其結構與 Get endpoint 回傳的結構相同。當任務處於 PENDING 或 IN_PROGRESS 狀態時,其結果欄位尚無值。
動畫任務物件
動畫任務物件描述應用於綁定骨骼角色的一個動畫。它包含狀態、進度,以及任務成功時的動畫檔案。
屬性
Example Animation Task Object
{
"id": "018c425b-b2c6-727e-d333-3c1887i9h791",
"type": "animate",
"status": "SUCCEEDED",
"created_at": 1747032440896,
"progress": 100,
"started_at": 1747032441210,
"finished_at": 1747032457530,
"expires_at": 1747291657530,
"task_error": null,
"consumed_credits": 3,
"result": {
"animation_glb_url": "https://assets.meshy.ai/.../Animation_Reaping_Swing_withSkin.glb?...",
"animation_fbx_url": "https://assets.meshy.ai/.../Animation_Reaping_Swing_withSkin.fbx?...",
"processed_usdz_url": "https://assets.meshy.ai/.../processed.usdz?...",
"processed_armature_fbx_url": "https://assets.meshy.ai/.../processed_armature.fbx?...",
"processed_animation_fps_fbx_url": "https://assets.meshy.ai/.../processed_60fps.fbx?..."
}
}
- Name
- id
- Type
- string
- Description
任務 ID。將其視為不透明字串,不要依賴其格式。
- Name
- type
- Type
- string
- Description
任務類型,始終為
animate。
- Name
- status
- Type
- string
- Description
任務狀態,為
PENDING、IN_PROGRESS、SUCCEEDED、FAILED或CANCELED之一。
- Name
- progress
- Type
- integer
- Description
任務完成的百分比。在任務開始前為
0,成功後為100。
- Name
- created_at
- Type
- timestamp
- Description
任務建立的時間,以 Unix 毫秒表示。
- Name
- started_at
- Type
- timestamp
- Description
任務開始的時間,以 Unix 毫秒表示。在任務開始前為
0。
- Name
- finished_at
- Type
- timestamp
- Description
任務結束的時間,以 Unix 毫秒表示。在任務結束前為
0。
- Name
- expires_at
- Type
- timestamp
- Description
任務結果檔案過期的時間,以 Unix 毫秒表示。
- Name
- task_error
- Type
- object
- Description
任務失敗時的錯誤詳情。除非狀態為
FAILED,否則為null。請參閱錯誤。
- Name
- consumed_credits
- Type
- integer
- Description
任務使用的積分數量。當狀態為
PENDING、IN_PROGRESS或SUCCEEDED時存在。對於FAILED的任務,該值為0,因為 Meshy 會在任務失敗時退還積分。
- Name
- result
- Type
- object
- Description
當任務狀態為
SUCCEEDED時,動畫檔案的下載 URL。- Name
animation_glb_url- Type
- string
- Description
- GLB 格式的動畫檔案。對於使用
action_ids建立的任務,這一個檔案會將每個請求的動作作為單獨的剪輯儲存其中。
- Name
animation_fbx_url- Type
- string
- Description
- FBX 格式的動畫檔案。對於使用
action_ids建立的任務,這一個檔案會將每個請求的動作作為單獨的剪輯儲存其中。
- Name
processed_usdz_url- Type
- string
- Description
- 經過處理的 USDZ 格式動畫檔案。
- Name
processed_armature_fbx_url- Type
- string
- Description
- 經過處理的 FBX 格式 armature 檔案。
- Name
processed_animation_fps_fbx_url- Type
- string
- Description
- 按變更後的影格率生成的 FBX 格式動畫檔案,例如使用了
change_fps操作時。
- Name
- preceding_tasks
- Type
- integer
- Description
排在此任務之前的佇列中任務數量。該值僅在任務為
PENDING時才有意義。當值為0時將省略該欄位。
列出動畫
回傳動畫庫中的每一個動畫,依 action_id 排序。回應是完整清單,不分頁,因此一次呼叫就能填滿一個動作選擇器。篩選條件可以縮小結果範圍。若要取得全部動畫,請將它們全部留空。
如果想在瀏覽同一清單的同時查看每個動作的動畫預覽,請參閱動畫庫參考。
此請求不消耗積分。
Request
curl "https://api.meshy.ai/openapi/v1/animations/library?category=Fighting" \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
[
{
"action_id": 4,
"name": "Attack",
"key": "Attack",
"category": "Fighting",
"sub_category": "AttackingwithWeapon",
"preview_url": "https://cdn.meshy.ai/webapp-assets/feature-demo/animation/preview/biped/Attack.gif",
"rig_type": "biped"
},
{
"action_id": 92,
"name": "Double Combo Attack",
"key": "Double_Combo_Attack",
"category": "Fighting",
"sub_category": "AttackingwithWeapon",
"preview_url": "https://cdn.meshy.ai/webapp-assets/feature-demo/animation/preview/biped/Double_Combo_Attack.gif",
"rig_type": "biped"
}
]
參數
- Name
- search
- Type
- string
- Description
要搜尋的文字。Meshy 會回傳
name或key包含此文字的動畫,不區分大小寫。Meshy 按字面比對文字,因此%和_不是萬用字元。
- Name
- category
- Type
- string
- Description
要列出的分類,須完全相符。未知分類將回傳空清單。
biped動畫的分類有:WalkAndRunBodyMovementsDailyActionsFightingDancing
quadruped動畫的分類是一種動物,例如dog或horse。
- Name
- sub_category
- Type
- string
- Description
要列出的子分類,須完全相符。你可以在不帶
category的情況下傳送它。子分類名稱在各分類之間並不唯一。例如,Transitioning同時存在於Fighting和DailyActions之下。因此在不帶category的情況下,此篩選條件會比對每個分類下的該子分類。
- Name
- action_ids
- Type
- string
- Description
要回傳的動畫,最多可傳入 200 個以逗號分隔的
action_id值。可用它來查找特定 ID,而非逐一瀏覽。超過 200 個 ID 將回傳400。回應會排除沒有對應動畫的 ID。因此你也可以用這個篩選條件來檢查你儲存的 ID 是否仍然可用。
組合篩選條件
Meshy 會將這些篩選條件組合套用。每一個都會縮小結果範圍,因此只有當一個動畫同時符合所有條件時,Meshy 才會回傳它。在同一個篩選條件內,其任一值都可以相符。例如,search 會比對 name 或 key,而 action_ids 會比對清單中的任意一個 ID。
因此,沒有交集的組合會回傳空陣列,而不是錯誤。動作 92 是「Double Combo Attack」,屬於 Fighting 動畫。例如:
?action_ids=92&category=Fighting會回傳動作92。?action_ids=92&category=Dancing會回傳[],因為它不是Dancing動畫。?action_ids=92&search=walk會回傳[],因為它的名稱與walk不符。
若要取得任意分類下的特定動畫,只需單獨傳送 action_ids。
回傳值
一個動畫物件清單。
建立 Animation 任務接受此 endpoint 回傳的每一個 action_id,而此 endpoint 也會回傳建立任務所接受的每一個 ID。兩者都不包含已下線的動畫。如果你快取了動畫庫,請定期重新整理它,以免已下線的 ID 仍然留在你的選擇器中。
動畫物件
動畫物件描述動畫庫中的一個動畫。
Example Animation Object
{
"action_id": 92,
"name": "Double Combo Attack",
"key": "Double_Combo_Attack",
"category": "Fighting",
"sub_category": "AttackingwithWeapon",
"preview_url": "https://cdn.meshy.ai/webapp-assets/feature-demo/animation/preview/biped/Double_Combo_Attack.gif",
"rig_type": "biped"
}
- Name
- action_id
- Type
- integer
- Description
建立 Animation 任務時作為
action_id發送的值。它是唯一且穩定的,但不是連續的。已下線的動畫會在編號中留下空缺,因此不要假設某個範圍內的每個 ID 都是有效的。
- Name
- name
- Type
- string
- Description
該動畫的顯示名稱。它並不唯一,因為有些動畫會與另一個變體共用同一個名稱。要識別某個動畫,請使用
action_id或key。
- Name
- key
- Type
- string
- Description
該動畫的唯一、穩定的識別字串。當你需要一個非數字 ID 來作為自己儲存的鍵值時,可以使用它。
- Name
- category
- Type
- string
- Description
頂層分組,例如
Fighting。對於quadruped動畫,它是一種動物,例如dog或horse。
- Name
- sub_category
- Type
- string
- Description
類別內的分組,例如
AttackingwithWeapon。
- Name
- preview_url
- Type
- string
- Description
該動作的動圖預覽 URL。你可以在自己的選擇器中直接展示它。
- Name
- rig_type
- Type
- string
- Description
該動畫所適用的骨骼類型,
biped或quadruped。它與 Rigging 任務的animation_type相符。一個 rig 只能使用與其自身類型相同的動畫。