> ## Documentation Index
> Fetch the complete documentation index at: https://docs.viggle.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 快速入门：3D 动作

> 从动作视频提取可下载的 3D 动画。

\*\*3D 动作（Motion 3D）\*\*从驱动视频中提取 3D 骨骼动画，使用 `POST /v1/motions` 的 `type=glb` 模式。就绪后，通过[导出 3D 动作](/zh/v1/api-reference/motions/export)，指定 `?download_type=mixamo`（或 `metahuman`）获取 GLB。导出的 GLB 可用于 **Mixamo**、**MetaHuman** 以及其他兼容 **Unity** 的动画流程。如需可直接渲染的 2D 动作，见[动作快速入门](/zh/v1/guides/quickstart-motion)；如需直接用提示词生成 3D 动画，见[文本生成动作](/zh/v1/guides/quickstart-text-to-motion)。

设置环境变量 `VIGGLE_API_KEY`，并准备下方示例所需的动作视频。

## 准备工作

* 在 [Viggle 控制台](https://portal.viggle.ai/keys)创建 API 密钥，并导出为 `VIGGLE_API_KEY`。

<Note>
  示例中的 `https://assets.viggle.ai/samples/motion.mp4` 是占位地址。请替换为自己的 `motion_video`/`motion_video_url`，或使用 Viggle 正式发布的示例素材。
</Note>

## 创建、轮询并导出动作

<CodeGroup>
  ```bash cURL theme={null}
  #!/usr/bin/env bash
  set -euo pipefail

  response=$(curl -s -X POST "https://apis.viggle.ai/v1/motions" \
    -H "Authorization: Bearer $VIGGLE_API_KEY" \
    -F "motion_video_url=https://assets.viggle.ai/samples/motion.mp4" \
    -F "type=glb")
  motion_id=$(echo "$response" | jq -r '.id')

  for _ in $(seq 1 60); do
    motion=$(curl -s "https://apis.viggle.ai/v1/motions/$motion_id" \
      -H "Authorization: Bearer $VIGGLE_API_KEY")
    status=$(echo "$motion" | jq -r '.status')

    case "$status" in
      ready)
        exported=$(curl -s "https://apis.viggle.ai/v1/motions/$motion_id/export?download_type=mixamo" \
          -H "Authorization: Bearer $VIGGLE_API_KEY")
        echo "$exported" | jq -r '.glb_url'
        exit 0
        ;;
      failed)
        echo "Motion failed: $(echo "$motion" | jq -c '.error')" >&2
        exit 1
        ;;
    esac
    sleep 5
  done

  echo "Timed out waiting for motion $motion_id" >&2
  exit 1
  ```

  ```javascript Node theme={null}
  const baseUrl = "https://apis.viggle.ai/v1";
  const headers = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };

  async function createMotion() {
    const form = new FormData();
    form.append("motion_video_url", "https://assets.viggle.ai/samples/motion.mp4");
    form.append("type", "glb");

    const response = await fetch(`${baseUrl}/motions`, {
      method: "POST",
      headers,
      body: form,
    });
    if (!response.ok) {
      const body = await response.json().catch(() => ({}));
      throw new Error(`HTTP ${response.status}: ${JSON.stringify(body.error ?? body)}`);
    }
    return response.json();
  }

  async function waitForMotion(id) {
    for (let attempt = 0; attempt < 60; attempt++) {
      const response = await fetch(`${baseUrl}/motions/${id}`, { headers });
      if (!response.ok) {
        const body = await response.json().catch(() => ({}));
        throw new Error(`HTTP ${response.status}: ${JSON.stringify(body.error ?? body)}`);
      }
      const motion = await response.json();
      if (["ready", "failed"].includes(motion.status)) return motion;
      await new Promise((resolve) => setTimeout(resolve, 5000));
    }
    throw new Error(`Timed out waiting for motion ${id}`);
  }

  const created = await createMotion();
  const motion = await waitForMotion(created.id);

  if (motion.status !== "ready") {
    throw new Error(`Motion failed: ${JSON.stringify(motion.error)}`);
  }

  const exportResponse = await fetch(
    `${baseUrl}/motions/${motion.id}/export?download_type=mixamo`,
    { headers },
  );
  if (!exportResponse.ok) {
    const body = await exportResponse.json().catch(() => ({}));
    throw new Error(`HTTP ${exportResponse.status}: ${JSON.stringify(body.error ?? body)}`);
  }
  const exported = await exportResponse.json();
  console.log(exported.glb_url);
  ```

  ```python Python theme={null}
  import os
  import time
  import requests

  base_url = "https://apis.viggle.ai/v1"
  headers = {"Authorization": f"Bearer {os.environ['VIGGLE_API_KEY']}"}

  response = requests.post(
      f"{base_url}/motions",
      headers=headers,
      files={"motion_video_url": (None, "https://assets.viggle.ai/samples/motion.mp4")},
      data={"type": "glb"},
  )
  response.raise_for_status()
  motion = response.json()

  for _ in range(60):
      if motion["status"] in {"ready", "failed"}:
          break
      time.sleep(5)
      response = requests.get(f"{base_url}/motions/{motion['id']}", headers=headers)
      response.raise_for_status()
      motion = response.json()
  else:
      raise TimeoutError(f"Timed out waiting for motion {motion['id']}")

  if motion["status"] != "ready":
      error = motion.get("error") or {}
      raise RuntimeError(f"failed: {error.get('code')} {error.get('message')}")

  exported = requests.get(
      f"{base_url}/motions/{motion['id']}/export",
      params={"download_type": "mixamo"},
      headers=headers,
  )
  exported.raise_for_status()
  print(exported.json()["glb_url"])
  ```
</CodeGroup>

## 响应

```json theme={null}
{
  "id": "mot_123abc",
  "status": "queued",
  "name": "",
  "progress": 0,
  "capabilities": [],
  "created_at": "2026-07-21T10:00:00+00:00",
  "completed_at": null,
  "error": null,
  "type": "glb",
  "vsplat": null,
  "glb": null
}
```

每 5 秒轮询 `GET /v1/motions/{motion_id}`。当 `status` 为 `ready` 时，请求 `GET /v1/motions/{motion_id}/export?download_type=mixamo`。返回的 `glb_url` 指向生成的动画；签名链接有效期为 1 小时，每次调用都会重新签名。对同一 `motion_id` 使用 `download_type=metahuman` 即可获取另一种骨架。两种骨架会预先生成，因此切换时无需等待新的处理任务。不提供 `fbx` 输出。

`mixamo` 是通用的 50 关节骨架，需要重定向到自己的角色；`metahuman` 与 Viggle vsplat 角色的骨架一一对应，无需重定向。完整对比见[导出 3D 动作](/zh/v1/api-reference/motions/export)，其中也说明了 `metahuman` 的 441 关节（含面部）与 86 关节（仅身体）版本。

`glb` 提取按源视频时长计费，详见[计费与保留期限](/zh/v1/pricing#motion-3d)。

<Card title="从视频创建动作" icon="box" href="/zh/v1/api-reference/motions/create">
  查看全部请求和响应字段。
</Card>
