# Motion Mesh Pipeline Tools

Three tools registered by the project-local pi extension `.pi/extensions/pipeline.ts`.
They are callable by the agent (and visible via `/tools`) in any session started
in this directory, once the project is trusted.

## validate_rig

Pure-TypeScript glTF/GLB validator (no external dependencies). Checks:

- exactly one skin, all joints named, single root hierarchy
- bone naming convention (regex, default: uppercase first letter)
- triangle budget (default 3500) and vertex count
- max influences per vertex (default 4) — reads WEIGHTS_0 from GLB or .gltf
  (+ data-URI / external .bin buffers)
- height bounds (default 0.5–4.0 m, Y-up, from POSITION accessor min/max)
- lists animation clips with durations

Returns PASS/FAIL plus an issues list; `details.pass` is machine-readable.

```text
validate_rig { "path": "assets/orc.glb", "maxTriangles": 3500 }
```

## export_gltf

Headless Blender export via `pipeline/blender_export.py`:

```text
export_gltf { "blendFile": "assets/orc.blend", "outputFile": "assets/orc.glb" }
```

Requires `blender` on `PATH` (or `$BLENDER_PATH`, or the `blenderPath` param).
The preset caps influences at 4, exports skin + armature + actions, +Y up.

## check_bevy_import

Loads the asset with the **real Bevy asset stack** (`pipeline/bevy-check`, a
minimal `bevy_asset` + `bevy_gltf` app, currently pinned to Bevy 0.20):

```text
check_bevy_import { "assetPath": "assets/orc.glb" }
```

- exit 0 = Bevy imported the asset; exit 1 = loader failure (the exact
  `bevy_gltf` error is returned); exit 2 = timeout
- first run compiles Bevy (several minutes, cached afterwards)
- `bevyVersion` param re-pins the crate version to match the target game and
  rebuilds

## Testing

Verified end-to-end (see git history / test assets in `/tmp/mm-test`):

- `rig_valid.gltf` / `.glb` → validate_rig PASS, bevy-check OK (exit 0)
- `rig_badnames.gltf` (bone `toe_bone`) → validate_rig FAIL (naming)
- `broken.gltf` → bevy-check FAIL with exact loader error (exit 1)
