# gizlang/motion

motion files as takes that move onto a character (gizlang/retarget), one way for every kind of file: a rigged GLB's animations, a BVH take, and a packed motion (a NumPy archive of SOMA's or SMPL-H's joints, as Kimodo and HY-Motion write them). A take is whole unless its reading asks for its loop.

```gizlang
import * as Motion from "gizlang/motion";
```

## Types

### `Take`

```gizlang
type Take = { name: string; frames: Frames; way: Way; }
```

A motion that becomes a clip NAME of a character, moved as WAY says.

- `name`: `string`
- `frames`: `gizlang_retarget.Frames`
- `way`: `gizlang_retarget.Way`

### `Reading`

```gizlang
type Reading = { clips: Vec<string>; reference: string; fps: f64; loop: bool; }
```

How to read a motion file: of a GLB, the animations taken (all when none is named) and the one whose mean pose
every take is moved about ("": each its own; `rest`: the file's rest pose); the frames a second it is sampled at;
and whether each take is cut to its best loop and played in place (a walk) rather than whole.

- `clips`: `Vec<string>`
- `reference`: `string`
- `fps`: `f64`
- `loop`: `bool`

## Functions

### `takesOf`

```gizlang
function takesOf(name: string, file: bytes, how: Reading): Vec<Take> throws string
```

The takes of motion file FILE called NAME (its extension says its kind: .glb, .bvh or .npz), read as HOW says. A
BVH or packed file is one take of that name; a GLB's takes are named as its animations.

Effects: fail, read, write, console, io, alloc.

### `packed`

```gizlang
function packed(file: bytes): Frames throws string
```

The motion of a packed clip FILE (a NumPy archive) of SOMA's 77 joints (Kimodo's) or SMPL-H's 22 body joints
(HY-Motion's), by how many it has: `quats`, each frame's joints' world turns away from the skeleton's rest pose
(w, x, y, z); `joints0`, the joints' places in the first frame; `hips`, the hips' place a frame; `fps`. At rest the
skeleton stands in that pose: a joint's offset is its place from its parent's in the first frame, turned back by its
parent's turn there.

Effects: fail, read, write, console, io, alloc.

### `clipsOf`

```gizlang
function clipsOf(takes: Vec<Take>, target: Rest, fps: f64 = 30.0): Vec<Clip> throws string
```

TAKES moved onto skeleton TARGET (gizlang/retarget), as clips of FPS frames a second.

Effects: fail, read, write, console, io, alloc.

### `withClips`

```gizlang
function withClips(model: bytes, target: Rest, clips: Vec<Clip>): bytes throws string
```

The rigged humanoid GLB MODEL with CLIPS added, its humanoid joints named as VRM names them.

Effects: fail, read, write, console, io, alloc.

### `moved`

```gizlang
function moved(model: bytes, takes: Vec<Take>): bytes throws string
```

The rigged humanoid GLB MODEL moving as TAKES do.

Effects: fail, read, write, console, io, alloc.

