> ## 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 motion

> Capture 3D motion from a video or generate it from text, then export GLB or FBX for Mixamo, MetaHuman or a Viggle 3D character.

JST-2 produces 3D skeletal animation two ways: it captures the movement of a person in a video, or it generates a movement from a text prompt. Either way you get a Motion (`mot_`) that you export as GLB or FBX, rigged for Mixamo, MetaHuman or a Viggle [3D character](https://docs.viggle.ai/v1/3d/characters.md). Use it to animate game characters, previs shots or splat characters without a mocap suit.

## Pick a source

All three create a Motion. Only the first two produce 3D files.

| Source | Call | Output | Price |
| - | - | - | - |
| A video of a person | `POST /v1/motions`, multipart, `type=glb` | GLB and FBX in three rigs | \$0.05 per source second, rounded up |
| A text prompt | `POST /v1/motions`, JSON with `text` | GLB and FBX in three rigs | \$0.10 flat |
| A Viggle motion template | `POST /v1/motions/import` | A motion for [Video Remix](https://docs.viggle.ai/v1/video/video-remix), no 3D export | $0.01 per template second, minimum $0.01 |

> [!NOTE]
>
> A Motion generated from text, or created from video with `type=glb`, is 3D only. It cannot drive a Video Remix. To reuse a video's motion in Video Remix as well, create it with `type=all`.

## Parameters

### From video

Send `multipart/form-data` (a JSON body also works).

| Parameter | Required | Default | Values |
| - | - | - | - |
| `motion_video` or `motion_video_url` | Yes | | Video file or public URL. Up to 100 MiB, 0.5–600 seconds, at least 64×64 with even width and height |
| `type` | Yes for 3D | `render` | `glb` for 3D only. `all` adds a 2D motion for Video Remix |
| `enable_smoothing` | No | `false` | Smooths joint jitter. May soften abrupt moves |
| `target_fps` | No | service default | Frame rate of the extracted animation, greater than 0 |
| `render_mp4` | No | `false` | `true` also renders an MP4 preview of the animation. Needs `type=glb` or `all` |
| `name` | No | | A label for `type=all`. A `glb`-only Motion reads back with an empty name |

### From text

Send `application/json`. Unknown fields are rejected with `400`.

| Parameter | Required | Default | Values |
| - | - | - | - |
| `text` | Yes | | The movement to generate, up to 400 bytes. Name the action, direction, pace and body parts |
| `duration_seconds` | No | `5` | 3–60 |
| `guidance_scale` | No | `5` | 0–30. Higher follows the text more strictly |
| `smooth` | No | `true` | Smooths the generated animation |
| `render_mp4` | No | `false` | `true` also renders an MP4 preview of the animation |
| `name` | No | | Echoed on the create response only |

Every field is in the API reference: [create a motion](https://docs.viggle.ai/v1/api-reference/motions/create-a-motion.md) and [import a motion template](https://docs.viggle.ai/v1/api-reference/motions/import-a-motion-template.md).

## Price

* From video: `ceil(source seconds) × 5` credits. A 10.1-second clip bills as 11 seconds: 55 credits (\$0.55). `type=all` costs the same, because the 2D motion is free. `enable_smoothing`, `target_fps` and `render_mp4` don't change it.
* From text: 10 credits (\$0.10) per request, whatever `duration_seconds` you ask for.
* Template import: 1 credit per second of the template, not rounded, minimum 1. A 7.5-second template costs 7.5 credits (\$0.075).

A failed motion is refunded.

> [!WARNING]
>
> Capture from video and text-to-motion are accepted even when your balance cannot cover them. The Motion is `queued`, then ends `failed` with `glb.error.code: "INSUFFICIENT_CREDITS"`. Template import checks the balance up front and answers `402 INSUFFICIENT_CREDITS`.

## Generate, wait and export

This script generates a 5-second motion from text, polls every 5 seconds, then saves the MetaHuman body rig as GLB. It needs no input files.

```bash cURL theme={null}
#!/usr/bin/env bash
set -euo pipefail
API="https://apis.viggle.ai/v1"
AUTH="Authorization: Bearer $VIGGLE_API_KEY"

motion_id=$(curl -sf -X POST "$API/motions" -H "$AUTH" \
  -H "Content-Type: application/json" \
  -d '{"text":"a person doing a cartwheel","duration_seconds":5}' | jq -r '.id')
echo "created $motion_id"

while true; do
  motion=$(curl -sf "$API/motions/$motion_id" -H "$AUTH")
  case "$(echo "$motion" | jq -r '.status')" in
    ready) break ;;
    failed) echo "failed: $(echo "$motion" | jq -c '.glb.error')" >&2; exit 1 ;;
  esac
  sleep 5
done

exported=$(curl -sf "$API/motions/$motion_id/export?download_type=glb" -H "$AUTH")
url=$(echo "$exported" | jq -r '.metahuman_body_url')
curl -sf -o motion.glb "$url"
echo "saved motion.glb; mixamo rig: $(echo "$exported" | jq -r '.mixamo_url')"
```

```javascript Node.js theme={null}
import { writeFile } from "node:fs/promises";

const API = "https://apis.viggle.ai/v1";
const auth = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };

async function call(path, init = {}) {
  const res = await fetch(`${API}${path}`, { ...init, headers: { ...auth, ...init.headers } });
  const body = await res.json();
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${JSON.stringify(body.error)}`);
  return body;
}

let motion = await call("/motions", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: "a person doing a cartwheel", duration_seconds: 5 }),
});
console.log(`created ${motion.id}`);

while (motion.status !== "ready") {
  if (motion.status === "failed") throw new Error(`failed: ${JSON.stringify(motion.glb?.error)}`);
  await new Promise((r) => setTimeout(r, 5000));
  motion = await call(`/motions/${motion.id}`);
}

const exported = await call(`/motions/${motion.id}/export?download_type=glb`);
const file = await fetch(exported.metahuman_body_url);
await writeFile("motion.glb", Buffer.from(await file.arrayBuffer()));
console.log(`saved motion.glb; mixamo rig: ${exported.mixamo_url}`);
```

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

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

res = requests.post(
    f"{API}/motions",
    headers=headers,
    json={"text": "a person doing a cartwheel", "duration_seconds": 5},
)
res.raise_for_status()
motion = res.json()
print(f"created {motion['id']}")

while motion["status"] != "ready":
    if motion["status"] == "failed":
        raise RuntimeError(f"failed: {(motion.get('glb') or {}).get('error')}")
    time.sleep(5)
    res = requests.get(f"{API}/motions/{motion['id']}", headers=headers)
    res.raise_for_status()
    motion = res.json()

res = requests.get(
    f"{API}/motions/{motion['id']}/export",
    params={"download_type": "glb"},
    headers=headers,
)
res.raise_for_status()
exported = res.json()
with open("motion.glb", "wb") as f:
    f.write(requests.get(exported["metahuman_body_url"]).content)
print(f"saved motion.glb; mixamo rig: {exported['mixamo_url']}")
```

To capture motion from a video instead, change only the create call. Poll and export are the same:

```bash theme={null}
curl -X POST https://apis.viggle.ai/v1/motions \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F "motion_video_url=https://assets.viggle.ai/pub/www/developers/sample-motion-97bb074a.mp4" \
  -F "type=glb"
```

## Get the result

Poll `GET /v1/motions/{motion_id}` until `status` is `ready` or `failed`. A failure's reason is in `glb.error`, not the top-level `error`. A ready Motion lists `glb.skeletons: ["mixamo", "metahuman"]`.

Then call `GET /v1/motions/{motion_id}/export` with `download_type=glb` or `fbx`. The format applies to all three rigs, which come back together:

| Field | Rig | Use it for |
| - | - | - |
| `mixamo_url` | Mixamo skeleton | Retargeting onto your own mesh in Unity, Unreal, Blender or Maya |
| `metahuman_url` | MetaHuman, 441 joints with the face | A Viggle 3D character created with `joint_set=full` |
| `metahuman_body_url` | MetaHuman body, 86 joints | A Viggle 3D character with the default `joint_set=body` |

If you created the Motion with `render_mp4=true`, the export also returns `mp4_url`, an MP4 preview of the Mixamo animation, whatever `download_type` you ask for. Otherwise `mp4_url` is null.

There is no rig for a character created with `joint_set=expression` (119 joints); create characters with `body` or `full` to play these clips.

Both formats are generated up front, so switching `download_type` never waits. Each link lasts one hour and every export call signs a fresh one. The files are part of the Motion and stay available until you delete it (`DELETE /v1/motions/{motion_id}`, `204` with an empty body). A motion from text or `type=glb`, and the export of any motion, is visible only to the API key that created it; other keys get `404 MOTION_NOT_FOUND`. Export what you need before you rotate that key. Motions from text or `type=glb` don't appear in `GET /v1/motions`; keep their IDs.

## Import a motion template

`POST /v1/motions/import` copies a Viggle motion template into a Motion you own, ready for Video Remix. Find template IDs on [viggle.ai](https://viggle.ai): an official template from the Viggle template catalog, or a template made in the Viggle app (its ID may start with `3s`; send it as copied). The API has no endpoint that lists templates. A multi-person template keeps one track per person, so each can get its own character through `character_mapping` in a [Video Remix](https://docs.viggle.ai/v1/video/video-remix) render.

```bash theme={null}
curl -X POST https://apis.viggle.ai/v1/motions/import \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"template_id": "YOUR_TEMPLATE_ID", "name": "Dance loop"}'
```

```json theme={null}
{ "id": "mot_550e8400-e29b-41d4-a716-446655440000", "status": "queued", "progress": 0 }
```

An unknown template answers `404`. A template that has not finished person tracking answers `400`. Poll `GET /v1/motions/{motion_id}` for the name and status.

## Next steps

> [card] [3D characters](https://docs.viggle.ai/v1/3d/characters.md)
>
> Rigged `.vsplat` characters to play these clips on.

> [card] [Unity quickstart](https://docs.viggle.ai/v1/3d/unity-quickstart.md)
>
> Import the FBX and drive a splat character.

> [card] [API reference](https://docs.viggle.ai/v1/api-reference/motions/export-a-3d-motion.md)
>
> Every field of create, import and export.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.