# C API reference

The reference for `include/sona.h` and the optional modules' headers (`sona_body.h`, `sona_track.h`, `sona_npc.h`, `sona_xr.h`, `sona_editor.h`, `sona_xsdk.h`), version 1.1 (`SONA_VERSION_MAJOR` 1, `SONA_VERSION_MINOR` 1), `SONA_ABI` 1. Every public function is listed once, under the part of the header that declares it, with its signature, its parameters, what it returns and its rules. Where this page and the header differ, the header wins. The same entries, with every struct and constant, are in [api/api.json](api/api.json) for tools.

Conventions are the web SDK's: metres, Y up, left-handed, avatars face -Z at turn 0 and stand about 1.8 m tall. Matrices are row-major and row-vector (`v' = v * M`).

## Version

This page is version 1.1.0 of the library: `sona_version()` returns `"1.1.0"`, and `SONA_ABI` is 1. 1.1 keeps every
1.0 call, struct and layout: a 1.0 host builds against the 1.1 header unchanged and draws the same, but for these:

- **Pictures.** A new renderer starts with the web's quality defaults: 4 samples on a hardware GPU (1 on a software rasteriser), mip chains and coverage-preserving mips. `sona_renderer_set_quality` with `msaa` 1 and `flags` 0 draws without them.
- **GL state.** With multisampling, GL and GLES also change the renderbuffer binding in `sona_draw` and `sona_snapshot`.

Within 1.x nothing breaks for two minor versions ([the stable ABI](guides/abi.md)). [The changelog](changelog.md) lists every addition.

---

## Rules every function follows

- **One owner thread.** All calls on one `sona_ctx`, and on its avatars and renderers, come from one thread at a time. The only exceptions are `sona_complete` and `sona_http_done`, which a source or an HTTP layer may call from any thread.
- **Completed exactly once.** Every `sona_request` and every `sona_http_reply` is completed exactly once, and stays valid until then: after `cancel` (which only asks), and after `sona_close`. A source must complete every read it accepted, also after `cancel`, and the host must not unload a source's code until its reads are complete.
- **Callbacks run on the owner thread.** The core calls a source's `read` and an HTTP layer's `send` only on the owner thread, inside `sona_open` or `sona_update`, so engines can start their own main-thread requests from them.
- **No blocking I/O.** Work that needs bytes returns `SONA_PENDING` or moves an avatar through its states. Results arrive through `sona_update` and `sona_poll_event`.
- **No allocation per frame.** After the first frames, `sona_update`, `sona_pose` and `sona_draw` do not allocate. Memory comes from the config's allocator and is counted against the budget.
- **Pointer lifetime.** Pointers handed out (`sona_pose_data`, event strings, clip info) stay valid until the next `sona_update` on that ctx, unless a function says otherwise.
- **Explicit padding.** Every public struct has explicit padding, so each field sits at its natural alignment on every ABI. `sona_struct_size` and `sona_struct_offset` let a binding check its mirror of every struct when it loads.

## Constants

| Name | Value | Meaning |
|---|---|---|
| `SONA_VERSION_MAJOR`, `_MINOR`, `_PATCH` | 1, 1, 0 | The header's version |
| `SONA_ABI` | 1 | Bumped when a public struct changes shape. Pass it in `sona_config.abi` |
| `SONA_MANIFEST_BYTES` | 1000 | An AvatarDescription |
| `SONA_JOINTS` | 72 | Palette slots; the avatar rig animates 71 |
| `SONA_PALETTE_FLOATS` | 864 | 72 joints x 3 float4 |
| `SONA_CB_FLOATS` | 896 | The HQ constant buffer: projection 0..15, shadow 16..31, palette from 32 |
| `SONA_VERTEX_STRIDE` | 76 | The runtime vertex (see `sona_mesh`) |
| `SONA_MAX_SOURCES` | 4 | Sources in one config |
| `SONA_ID_CHARS` | 37 | An item id, `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`, plus NUL |
| `SONA_JOINT_COUNT` | 72 | joint slots; joints 0..70 have names and matrices |
| `SONA_QUEUE_MAX` | 8 | clips one avatar can have queued |
| `SONA_CLIP_EVENT_MAX` | 32 | clip events held per avatar |
| `SONA_MARK_MAX` | 16 | clip marks per avatar |
| `SONA_MSAA_AUTO` | 0 | 4 samples on a hardware GPU, 1 on a software rasteriser |

On Windows the library is a DLL: `SONA_API` is `dllimport` unless `SONA_STATIC` is defined. Elsewhere it marks default visibility.

## Results and errors

`sona_result` is the return code of almost every call. `SONA_OK` is 0, `SONA_PENDING` is 1 (not finished; call again after `sona_update`), and every error is negative:

| Code | Value | When |
|---|---|---|
| `SONA_E_UNSUPPORTED` | -1 | No usable backend, API version or feature |
| `SONA_E_ORIGIN` | -2 | Web only; kept so codes line up with the web SDK |
| `SONA_E_LICENCE` | -3 | The app has not accepted the SDK Licence, or the licence file is missing or bad |
| `SONA_E_APP` | -4 | No such app, or it was turned off |
| `SONA_E_GATE` | -5 | 360sona could not be reached |
| `SONA_E_MANIFEST` | -6 | That avatar could not be read or built |
| `SONA_E_CONTEXT` | -7 | The graphics device failed or was lost |
| `SONA_E_READBACK` | -8 | A picture could not be read back |
| `SONA_E_LIMIT` | -9 | Too many avatars or requests, over the daily use, or over the memory budget |
| `SONA_E_DESTROYED` | -10 | The ctx, avatar or renderer is gone |
| `SONA_E_PLATFORM` | -11 | This build is not licensed for this platform |
| `SONA_E_BUILD` | -12 | This build was revoked; download a new one |
| `SONA_E_ARGUMENT` | -13 | A bad argument |
| `SONA_E_MEMORY` | -14 | The allocator returned NULL |
| `SONA_E_NOT_FOUND` | -15 | No source has that asset |
| `SONA_E_IO` | -16 | A source failed; a retry may work |
| `SONA_E_CORRUPT` | -17 | Bytes did not decode |
| `SONA_E_NOT_READY` | -18 | The avatar is not ready |
| `SONA_E_UNIMPLEMENTED` | -19 | Not in this build |

`sona_error_info` holds `code`, `message` and `fix`: what went wrong and what to do about it.

### sona_result_name

```c
const char *sona_result_name(sona_result r);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_result` | A result code | - |

**Returns** `const char *`.

**Example** (also in [Troubleshooting and error codes](troubleshooting.md)):

```c
sona_config_defaults(&cfg);   /* then the licence and the sources */
sona_result r = sona_open(&cfg, &ctx);
if (r != SONA_OK) {
  sona_error_info e = sona_last_error(NULL);
  fprintf(stderr, "%s (%d): %s\n  %s\n", sona_result_name(r), (int)r, e.message, e.fix ? e.fix : "");
}
```

The name of a code (`"licence"`, `"gate"`, ...): the same words as the web SDK's `SonaError.code`.

### sona_last_error

```c
sona_error_info sona_last_error(const sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |

**Returns** `sona_error_info`.

**Example** (also in [Troubleshooting and error codes](troubleshooting.md)):

```c
sona_config_defaults(&cfg);   /* then the licence and the sources */
sona_result r = sona_open(&cfg, &ctx);
if (r != SONA_OK) {
  sona_error_info e = sona_last_error(NULL);
  fprintf(stderr, "%s (%d): %s\n  %s\n", sona_result_name(r), (int)r, e.message, e.fix ? e.fix : "");
}
```

The last error on a ctx. Its strings live until the next error.

## Handles

Every handle is an opaque pointer: its struct is not in the header, so a program holds it and passes it back, never
reads into it or copies it. The library makes each one in the call that gives it out (through an out-parameter, the
`**out` last argument) and frees it in the one call named below; nothing else frees it, and a handle is not used after
that call. Calls on a `sona_ctx` and on everything made from it come from one thread at a time ([Rules every function
follows](#rules-every-function-follows)).

| Handle | What it is | Made by | Freed by |
|---|---|---|---|
| `sona_ctx` | The library's state: sources, caches, the clock, the job system | `sona_open` | `sona_close`, after the avatars and renderers made from it are freed |
| `sona_avatar` | One avatar in a ctx | `sona_avatar_add`, `sona_avatar_add_base64`, `sona_avatar_add_state`, `sona_avatar_add_waiting`, `sona_item_preview_add` | `sona_avatar_remove` |
| `sona_renderer` | A renderer on the host's device, or a headless one | `sona_renderer_create`, `sona_headless_renderer` | `sona_renderer_destroy` |
| `sona_request` | One read in flight from a host-written source | the core, when it calls the source's `read` | the core, once the source calls `sona_complete` on it (exactly once) |
| `sona_http_reply` | One request in flight on a host's HTTP layer | the core, when it calls the layer's `send` | the core, once the layer calls `sona_http_done` on it (exactly once; valid until then, even after `sona_close`) |
| `sona_catalogue` | The offline catalogue, loaded | `sona_catalogue_load`, `sona_catalogue_load_memory` | `sona_catalogue_free` |
| `sona_maker` | A catalogue's outfit rules, indexed for making avatars | `sona_maker_create` | `sona_maker_free` |
| `sona_filter` | A content filter's rules | `sona_filter_create` | `sona_filter_free` |
| `sona_blend_space` | A blend of clips by one or two values | `sona_blend_space_create` | `sona_blend_space_destroy` |
| `sona_state_machine` | Clip states and the moves between them | `sona_state_machine_create` | `sona_state_machine_destroy` |
| `sona_interaction` | Two avatars acting together | `sona_interaction_start` | `sona_interaction_remove` |
| `sona_prop_mesh` | A stock prop's mesh, read for a host's own drawing | `sona_prop_mesh_stock` | `sona_prop_mesh_release` |
| `sona_sheet` | A sprite sheet of a clip | `sona_sheet_render` | `sona_sheet_free` |
| `sona_lipsync` | Mouth shapes from sound | `sona_lipsync_create` | `sona_lipsync_destroy` |
| `sona_headless` | A renderer with no window, for pictures and video | `sona_headless_open` | `sona_headless_close` |
| `sona_video` | A video or picture sequence being written | `sona_video_open` | `sona_video_finish` (also on an error) |
| `sona_print` | A mesh for 3D printing | `sona_print_avatars`, `sona_print_triangles` | `sona_print_free` |
| `sona_anim_file` | An animation file read for import | `sona_anim_file_open` | `sona_anim_file_free` |
| `sona_players` | Players looked up by gamertag or id | `sona_players_open` | `sona_players_close` |
| `sona_net_sender`, `sona_net_receiver` | One avatar's state sent over a network, and received | `sona_net_sender_create`, `sona_net_receiver_create` | `sona_net_sender_destroy`, `sona_net_receiver_destroy` |
| `sona_recorder`, `sona_replay` | A recording of avatars' states, and its playback | `sona_recorder_create`, `sona_replay_open` | `sona_recorder_destroy`, `sona_replay_close` |
| `sona_screen` | A ready-made screen: the quick creator or the wardrobe picker | `sona_quick_open`, `sona_wardrobe_open` | `sona_screen_destroy` (the avatars it shows, from `sona_screen_view_avatar`, are its own) |

## Host services: memory, jobs, logging

`sona_allocator` holds `alloc(user, size, align)`, `free(user, ptr, size)` and `user`. `alloc` returns NULL on failure. All zero means `malloc` and `free`.

`sona_budget` is the memory budget in bytes. Zero fields take the defaults. Caches evict idle entries, oldest first, to stay inside their share; if what is live does not fit, the avatar that needed more fails with `SONA_E_LIMIT`.

| Field | Default |
|---|---|
| `total` | 0: no overall cap. Xbox 360 hosts should set it |
| `assets` | 256 MiB of decoded items |
| `clips` | 32 MiB of retained clip blocks |
| `faces` | 64 MiB of baked face sheets, at most 512 sheets, as the web |
| `source_cache` | 64 MiB of fetched container bytes, in memory only |
| `gpu_idle` | 64 MiB of GPU objects no avatar uses any more, as the web |

`sona_jobs` is a host job system: `{user, workers, run(user, fn, arg)}`. `run` runs `fn(arg)` once, on any thread; `workers` says how many run at once. The core hands it independent jobs (decode, face bake, build, skinning slices) and never waits on one inside a call that must not block.

Log levels are `SONA_LOG_ERROR` (0), `SONA_LOG_WARN`, `SONA_LOG_INFO` and `SONA_LOG_DEBUG` (3), passed to `sona_config.log`.

## HTTP

The core's network traffic (the gate source and the native check) goes through a `sona_http`, which holds `user` and `send(user, request, reply)`. `send` starts the request and returns; the layer finishes it later, from any thread, with `sona_http_done`. A `sona_http_request` holds `method` ("GET" or "POST"), `url`, `headers` (NULL-terminated "Name: value" strings, may be NULL), `body`, `body_len` and `timeout_ms`.

A layer the host supplies sees every URL, header and answer in clear, the gate's session key included.

### sona_http_done

```c
void sona_http_done(sona_http_reply *reply, int status, const void *body, size_t len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `reply` | `sona_http_reply *` | The reply the layer was handed | required |
| `status` | `int` | The HTTP status; 0 or less when the request failed | - |
| `body` | `const void *` | The reply's body | required |
| `len` | `size_t` | How many bytes there are | - |

**Returns** Nothing.

Finishes one HTTP request. `status` is the HTTP status, or 0 when the request could not be made. The body is copied. Call it exactly once per reply; the reply stays valid until then, even after `sona_close`. May be called from any thread.

### sona_http_platform

```c
const sona_http *sona_http_platform(void);
```

**Returns** `const sona_http *`.

**Example**:

```c
const sona_http * x_got = sona_http_platform();
printf("sona_http_platform: %s\n", x_got ? "a value" : "none");
```

The platform's own layer: WinHTTP on Windows, libcurl loaded at run time on Linux, NSURLSession on Apple platforms. NULL where there is none (Xbox 360, WASM, Linux without libcurl): the host must then pass its own in `sona_config.http`.

## Asset sources

A read asks for one of two kinds (`sona_read_kind`):

- `SONA_READ_ASSET`: `name` is a lowercase item id in the 36-character form above.
- `SONA_READ_DATA`: `name` is a data file: `"avatar-rig.json"`, `"ColorSets.json"`, `"irradiance-cube.csv"`, `"ssao/poisson_512x32_r8g8snorm.bin"` or `"bin/tocassetdependencies.bin"`.

Container bytes are the file as stored: YTGR-wrapped, raw STRB, or an STFS package holding `asset_v2.bin`.

A source is described by a `sona_source_desc {kind, location, custom}`:

| Kind | `location` |
|---|---|
| `SONA_SOURCE_CUSTOM` | Unused; `custom` points at a host-written `sona_source` |
| `SONA_SOURCE_GATE` | The gate base; NULL for 360sona's own. Not in the WASM build |
| `SONA_SOURCE_DIR` | A folder of item files the user owns, laid out as the gate serves them. The core reads it and never writes to it |
| `SONA_SOURCE_CONSOLE` | A Content root, such as `"uda0:/Content"` on an Xbox 360, or a PC path to a copied one |

A host-written `sona_source` holds `user`, `read(user, kind, name, req)`, `cancel(user, req)` and `destroy(user)`. `read` starts a read and returns at once; the source finishes it, now or later, from any thread, with `sona_complete`. `cancel` is optional and only asks. `destroy` is optional and is called by `sona_close`.

Sources are asked in order; the first that has an asset wins. Fetched bytes are cached in memory only, against `budget.source_cache`.

### sona_complete

```c
void sona_complete(sona_request *req, sona_result status, const void *bytes, size_t len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `req` | `sona_request *` | The read request | required |
| `status` | `sona_result` | `SONA_OK`, or why the read failed | - |
| `bytes` | `const void *` | The file's bytes | required |
| `len` | `size_t` | How many bytes there are | - |

**Returns** Nothing.

Finishes one read, exactly once, also after `cancel`; the request stays valid until then. `status` is one of:

- `SONA_OK` with the bytes, which the core copies;
- `SONA_E_NOT_FOUND` when the source has no such asset: the next source in the chain is asked;
- `SONA_E_IO` when it failed: the read is retried later, as the web retries.

May be called from any thread.

## The context

`sona_config` holds everything `sona_open` needs:

| Field | Meaning |
|---|---|
| `abi` | `SONA_ABI` |
| `app_id` | NULL: the app id stamped into this build. Release builds refuse an id that differs from the stamp |
| `licence`, `licence_len` | `sona-licence.json` from the download, as bytes. The WASM build has none |
| `sources[SONA_MAX_SOURCES]`, `source_count` | Asked in order; the first that has an asset wins |
| `http` | NULL: `sona_http_platform()` |
| `allocator` | All zero: `malloc` and `free` |
| `budget` | See `sona_budget` |
| `worker_threads` | -1: cores - 1 (the default); 0: none, work runs inside `sona_update` |
| `jobs` | When `.run` is set it replaces `worker_threads` |
| `seed` | Idle and start-time randomness; 0: from the clock. A fixed seed makes runs repeatable |
| `max_avatars` | Default 256, at most 16384 |
| `build_budget_ms` | Building allowed per `sona_update`; default 6 |
| `face_size` | 0: auto (512 up to 4 avatars, 256 up to 32, else 128); or 128, 256, 512 |
| `flags` | `SONA_CFG_*`, below |
| `log`, `log_user` | `log(user, level, msg)` |
| `check_host` | NULL: `https://test.360sona.com`, the developer site, where the native check answers. Release builds accept only an `https://` host, and only a signed answer from 360sona opens the gate, so a proxy works but cannot stand in for the server |

Flags:

- `SONA_CFG_STILL_FACES`: one face per avatar (the web's `faces: "still"`).
- `SONA_CFG_APP_BEHAVIOUR`: the app-faithful idle player with crossfades, instead of the web SDK's idle chooser.
- `SONA_CFG_NO_CPU_SKIN`: never allocate CPU-skinned vertex buffers.

### sona_config_defaults

```c
void sona_config_defaults(sona_config *cfg);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cfg` | `sona_config *` | The [`sona_config`](reference/fields.md#sona_config) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Signed releases, stamped downloads and revocation](guides/release.md)):

```c
sona_config_defaults(&cfg);
cfg.licence = licence;          /* the bytes of sona-licence.json */
cfg.licence_len = licence_len;
sona_result r = sona_open(&cfg, &ctx);
```

Sets `abi` and leaves everything else at its default.

### sona_open

```c
sona_result sona_open(const sona_config *cfg, sona_ctx **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cfg` | `const sona_config *` | The configuration, a [`sona_config`](reference/fields.md#sona_config) | required |
| `out` | `sona_ctx **` | Receives the new context | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_GATE`, `SONA_E_LICENCE`, `SONA_E_PLATFORM` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Signed releases, stamped downloads and revocation](guides/release.md)):

```c
sona_config_defaults(&cfg);
cfg.licence = licence;          /* the bytes of sona-licence.json */
cfg.licence_len = licence_len;
sona_result r = sona_open(&cfg, &ctx);
```

Opens a context. The licence file is checked at once: its signature, its app and build against the ones stamped into this library, and this library's platform in its list. A failure is `SONA_E_LICENCE` or `SONA_E_PLATFORM`, and no source opens.

The native check with 360sona runs in the background, and gate reads wait for it. A failed check arrives as a `SONA_EVENT_ERROR` and turns the gate source off; a passed one as `SONA_EVENT_LICENCE_OK`. Over the daily use (`SONA_E_LIMIT`), the gate source stays off until the next UTC day. Local sources (dir and console) need only the licence file, work offline and are never counted: only reads that reach the gate count toward its caps (3,000 distinct items and 20,000 answers per ctx). If no source can give the avatar rig (`avatar-rig.json`), the ctx raises one `SONA_EVENT_ERROR` with `SONA_E_GATE` and its avatars fail with the same code.

### sona_close

```c
void sona_close(sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |

**Returns** Nothing.

**Example** (also in [Getting started](getting-started.md)):

```c
sona_avatar_remove(avatar);       /* frees what only it used */
sona_renderer_destroy(renderer);  /* before your device goes */
sona_close(ctx);
```

Closes a context. It calls `cancel` on every read in flight, then each source's `destroy`, and frees everything else. Reads still open are freed by their own completion, whose result is dropped.

### sona_app_id

```c
const char *sona_app_id(const sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |

**Returns** `const char *`.

**Example**:

```c
const char * x_got = sona_app_id(ctx);
printf("sona_app_id: %s\n", x_got ? "a value" : "none");
```

The app id this context runs as.

### sona_version

```c
const char *sona_version(void);
```

**Returns** `const char *`.

**Example** (also in [Installing](install.md)):

```c
printf("sona %s on %s\n", sona_version(), sona_platform());
```

The library's version, `"1.1.0"`.

### sona_platform

```c
const char *sona_platform(void);
```

**Returns** `const char *`.

**Example** (also in [Installing](install.md)):

```c
printf("sona %s on %s\n", sona_version(), sona_platform());
```

The binary platform id compiled into this library: `"windows-x64"`, `"linux-x64"`, `"linux-arm64"`, `"macos-arm64"`, `"macos-x64"`, `"ios-arm64"`, `"android-arm64"`, `"android-x64"`, `"xbox360"` or `"wasm"`. The licence file lists these ids. They are not the download names (`macos`, `unity`, ...): one download can hold several.

### sona_struct_size

```c
uint32_t sona_struct_size(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A public struct's name, such as `"sona_config"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_struct_size("sona_config");
printf("sona_struct_size: %lld\n", (long long)x_got);
```

`sizeof` a public struct by its name (`"sona_config"`, `"sona_pose_data"`, ...); 0 if unknown.

### sona_struct_offset

```c
uint32_t sona_struct_offset(const char *struct_dot_field);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `struct_dot_field` | `const char *` | `"struct.field"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_struct_offset("example");
printf("sona_struct_offset: %lld\n", (long long)x_got);
```

`offsetof` a field, by `"struct.field"`: `"sona_manifest.xuid"`, `"sona_device_desc.u.vk.queue_family"`; `UINT32_MAX` if unknown. Bindings check the size of every struct and the offset of every field they mirror when they load, and refuse to run on a mismatch.

### sona_abi_query

```c
sona_result sona_abi_query(sona_abi_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `out` | `sona_abi_info *` | Receives the [`sona_abi_info`](reference/fields.md#sona_abi_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The stable ABI and the deprecation policy](guides/abi.md)):

```c
sona_abi_info i = { 0 };
i.size = sizeof i;
if (sona_abi_query(&i) == SONA_OK && SONA_ABI >= i.oldest_abi && SONA_ABI <= i.abi) {
  /* this program, built against SONA_ABI, can use the library */
}
```

The ABI of the library that is loaded, for hosts and bindings that load it at run time: `abi` is its `SONA_ABI`, `oldest_abi` the oldest `SONA_ABI` a caller may be built against and still load it (nothing breaks for two minor versions), and its version as numbers. Set `out->size` first.

## Events

A `sona_event` holds `type`, `avatar`, `code`, `message` and `fix`. `message` and `fix` are valid until the next `sona_poll_event`.

| Type | Meaning |
|---|---|
| `SONA_EVENT_NONE` | Nothing |
| `SONA_EVENT_READY` | An avatar is built and drawable (`avatar` is set) |
| `SONA_EVENT_FAILED` | An avatar could not be built; `code` says why (`avatar` is set) |
| `SONA_EVENT_ERROR` | Context-wide: licence, app, platform, build, limit, gate or context |
| `SONA_EVENT_LICENCE_OK` | The native check passed |

### sona_poll_event

```c
int sona_poll_event(sona_ctx *ctx, sona_event *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `out` | `sona_event *` | Receives the [`sona_event`](reference/fields.md#sona_event) | required |

**Returns** `int`.

**Example**:

```c
sona_event x_event;
memset(&x_event, 0, sizeof x_event);
int x_got = sona_poll_event(ctx, &x_event);
printf("sona_poll_event: %lld\n", (long long)x_got);
```

1 when an event was written to `*out`, 0 when there are none. Call it in a loop after `sona_update`.

## Avatars

An avatar moves through `SONA_AVATAR_QUEUED`, `LOADING`, `READY`, and ends in `FAILED` or `REMOVED`.

`sona_placement` holds `position[3]` (metres, default 0, 0, 0), `turn_deg` (degrees about Y; 0 faces -Z) and `scale` (default 1).

`sona_add_options`:

| Field | Meaning |
|---|---|
| `place` | Where it stands |
| `clip` | A clip key, a raw clip id, `"prop"`, `"idle"` or `"still"`; NULL: `"idle"` |
| `loop` | Default 1 |
| `speed` | Default 1 |
| `start_at` | Seconds; negative means random, to desynchronise a crowd |
| `visible` | Default 1 |
| `priority` | Higher builds sooner; default 0 |

`sona_play_options` holds `loop` (default 1), `speed` (default 1) and `from` (seconds into the clip, default 0).

### sona_add_defaults

```c
void sona_add_defaults(sona_add_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_add_options *` | The [`sona_add_options`](reference/fields.md#sona_add_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Crowds: level of detail and sprites](guides/crowd.md)):

```c
/* 10,000 avatars in rows round a pitch, facing in */
sona_lod_set(ctx, NULL);
for (i = 0; i < 10000; i++) {
  sona_add_options o;
  sona_add_defaults(&o);
  seat(i, o.place.position, &o.place.turn_deg);   /* your layout */
  o.start_at = -1;                                 /* random start: a crowd out of step */
  sona_avatar_add_base64(ctx, looks[i % 12], &o, &av[i]);
}
```

Fills `*o` with the defaults above.

### sona_avatar_add

```c
sona_result sona_avatar_add(sona_ctx *ctx, const uint8_t manifest[SONA_MANIFEST_BYTES],
                            const sona_add_options *opts, sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required |
| `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](reference/fields.md#sona_add_options) | required |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Untrusted files, long sessions and speed](guides/hardening.md)):

```c
sona_manifest m;
if (sona_manifest_parse(manifest, &m) != SONA_OK)   /* any 1,000 bytes from a player */
  puts("not an avatar");                            /* SONA_E_MANIFEST */
else
  sona_avatar_add(ctx, manifest, NULL, &avatar);    /* its items load through your sources */
```

Queues an avatar and returns at once. A bad manifest does not fail here: the avatar moves to `FAILED` with `SONA_E_MANIFEST`, as the web's `add()` never throws for one. It fails at once only with `SONA_E_LIMIT` (over `max_avatars`) or `SONA_E_ARGUMENT`.

### sona_avatar_add_base64

```c
sona_result sona_avatar_add_base64(sona_ctx *ctx, const char *b64,
                                   const sona_add_options *opts, sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `b64` | `const char *` | The manifest as base64 text, at most 4096 characters | required |
| `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](reference/fields.md#sona_add_options) | required |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Getting started](getting-started.md)):

```c
sona_avatar *avatar = NULL;
sona_avatar_add_base64(ctx, b64, NULL, &avatar);   /* b64: the manifest; returns at once */
sona_avatar_play(avatar, "GenericWave", NULL);     /* remembered until it is ready */
```

The same, from base64 text of at most 4096 characters, as the web.

### sona_avatar_state_of

```c
sona_avatar_state sona_avatar_state_of(const sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |

**Returns** `sona_avatar_state`.

**Example** (also in [VR and XR bodies (sona_xr)](guides/xr.md)):

```c
sona_xr_input in;
sona_xr_input_defaults(&in);
in.time = now;                                  /* seconds, rising */
in.flags = SONA_XR_HAS_HEAD;                    /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */
in.head.position[0] = head_pos[0];
in.head.position[1] = head_pos[1];
in.head.position[2] = head_pos[2];
sona_xr_feed(xr, &in);
if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar);
sona_update(ctx, dt, &view, NULL);
```

The avatar's state.

### sona_avatar_id

```c
uint32_t sona_avatar_id(const sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |

**Returns** `uint32_t`.

**Example** (also in [Lip sync: a microphone or any audio drives the mouth](guides/lipsync.md)):

```c
sona_voice_mouth v[64];
for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i], sona_avatar_id(avatars[i]));
/* each frame: */
uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt);
```

A number unique within the ctx.

### sona_avatar_play

```c
sona_result sona_avatar_play(sona_avatar *a, const char *clip, const sona_play_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `clip` | `const char *` | A clip key or id | required |
| `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](reference/fields.md#sona_play_options) | `NULL`: the defaults |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Getting started](getting-started.md)):

```c
sona_avatar *avatar = NULL;
sona_avatar_add_base64(ctx, b64, NULL, &avatar);   /* b64: the manifest; returns at once */
sona_avatar_play(avatar, "GenericWave", NULL);     /* remembered until it is ready */
```

Plays a clip. Called before `READY`, it is remembered and applied when the avatar appears. NULL `opts` takes the defaults. Since 1.1 it also clears the clip queue, and returns `SONA_E_ARGUMENT` for an item preview.

### sona_avatar_stop

```c
void sona_avatar_stop(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example** (also in [3D print export](guides/print3d.md)):

```c
sona_play_options pl = { 0, 1.0f, 1.25f };          /* no loop, speed 1, from 1.25 s */
sona_avatar_play(a, "GenericWave", &pl);
sona_update(ctx, 0, NULL, NULL);
sona_avatar_stop(a);
sona_update(ctx, 0, NULL, NULL);
sona_print_avatars(&a, 1, &opts, &print);
```

Holds the current pose.

### sona_avatar_move

```c
void sona_avatar_move(sona_avatar *a, const sona_placement *to, float over_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `to` | `const sona_placement *` | Where to stand, a [`sona_placement`](reference/fields.md#sona_placement) | required |
| `over_seconds` | `float` | Seconds to ease over; 0: at once | `0`: at once |

**Returns** Nothing.

**Example** (also in [Getting started](getting-started.md)):

```c
sona_placement to = { { 1.0f, 0.0f, -2.0f }, 90.0f, 1.0f };
sona_avatar_move(avatar, &to, 0.5f);                  /* over half a second */
sona_avatar_crossfade(avatar, "GenericWave", NULL, 0.2f);
```

Moves the avatar to a new placement over `over_seconds`.

### sona_avatar_set_visible

```c
void sona_avatar_set_visible(sona_avatar *a, int visible);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `visible` | `int` | 1 drawn, 0 hidden | - |

**Returns** Nothing.

**Example**:

```c
sona_avatar_set_visible(avatar, 1);
```

Shows or hides it. A hidden avatar is not drawn. It does nothing to an item preview, which `sona_draw` never draws.

### sona_avatar_bounds

```c
void sona_avatar_bounds(const sona_avatar *a, float center[3], float *radius);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `center` | `float [3]` | Receives the centre of the bounding sphere, world space | required |
| `radius` | `float *` | Receives the sphere's radius | required |

**Returns** Nothing.

A bounding sphere, in metres.

### sona_avatar_remove

```c
void sona_avatar_remove(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_avatar_remove(avatar);
```

Removes the avatar and frees what only it used. The handle must not be used afterwards.

## Game features

Joints by name, pose overrides, clip crossfades and queues, a collision capsule, expressions, clip events and root motion. Like every avatar call they belong to the ctx's owner thread. Calls that return a `sona_result` give `SONA_E_ARGUMENT` for a NULL avatar or pointer. `sona_joint_world`, `sona_avatar_override`, `_queue`, `_capsule`, `_expression` and `_expression_counts` also give `SONA_E_DESTROYED` for an avatar that is being removed.

`sona_capsule` holds `a[3]`, `b[3]` and `radius`: 28 bytes of floats, world metres.

`sona_clip_event` holds `kind`, `mark`, `clip` and `time`, 16 bytes:

| Field | Meaning |
|---|---|
| `kind` | `SONA_CLIP_STARTED` (1), `SONA_CLIP_LOOPED` (2), `SONA_CLIP_ENDED` (3), `SONA_CLIP_FOOT_LEFT` (4), `SONA_CLIP_FOOT_RIGHT` (5), `SONA_CLIP_MARK` (6) |
| `mark` | The id given to `sona_avatar_mark`, for MARK events; else 0 |
| `clip` | The `sona_clip_get` index of the clip; -1 for a prop's clip or a raw clip id |
| `time` | Seconds into the clip |

### sona_joint_find

```c
int32_t sona_joint_find(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A joint's name | required |

**Returns** `int32_t`.

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
sona_mask_preset(SONA_MASK_UPPER_BODY, m);
sona_mask_branch(m, sona_joint_find("Spine"), 0.5f);    /* half the wave in the spine ... */
sona_mask_branch(m, sona_joint_find("Chest"), 1.0f);    /* ... all of it from the chest up */
```

A joint's number from its name: a humanoid name (`Hips`, `Spine`, `Chest`, `Neck`, `Head`, `LeftUpperArm`, ... `PropLeft`, `PropRight`), `shape_NN` for a body-shape joint, or `joint_NN` for any joint by number. -1 when the name is unknown or NULL.

### sona_joint_name

```c
const char *sona_joint_name(uint32_t joint);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - |

**Returns** `const char *`.

**Example**:

```c
const char * x_got = sona_joint_name(0);
printf("sona_joint_name: %s\n", x_got ? "a value" : "none");
```

The name of joints 0 to 70: the humanoid name, or `shape_NN`. NULL past the last joint. The string is static.

### sona_joint_world

```c
sona_result sona_joint_world(const sona_avatar *a, uint32_t joint, float out[16]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - |
| `out` | `float [16]` | Receives a row-major 4x4 matrix | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
float hand[16];
if (sona_joint_world(avatar, (uint32_t)sona_joint_find("RightHand"), hand) == SONA_OK) {
  float x = hand[12], y = hand[13], z = hand[14];
  (void)x; (void)y; (void)z;                       /* your object's position */
}
```

The joint's world matrix at the last `sona_update`: row-vector, metres, with the avatar's placement applied. `SONA_E_ARGUMENT` for a joint past 70. `SONA_E_NOT_READY` before the avatar is READY and posed. A sprite (see crowds) keeps the last pose computed before it became one.

### sona_avatar_override

```c
sona_result sona_avatar_override(sona_avatar *a, uint32_t joint, const float rotation[4], float weight,
                                 uint32_t mode);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - |
| `rotation` | `const float [4]` | A unit quaternion (x, y, z, w); NULL clears the joint | required |
| `weight` | `float` | A weight from 0 to 1 | - |
| `mode` | `uint32_t` | `SONA_OVERRIDE_REPLACE` or `SONA_OVERRIDE_ADD` | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
float x_rotation[4];
memset(x_rotation, 0, sizeof x_rotation);
sona_result result = sona_avatar_override(avatar, 0, x_rotation, 0.5f, 0);
if (result != SONA_OK) printf("sona_avatar_override: %s\n", sona_result_name(result));
```

A rotation applied after the clip each frame, for look-at and aiming. `rotation` is a quaternion (x, y, z, w); it is normalised, and a zero or non-finite one is `SONA_E_ARGUMENT`. `mode` `SONA_OVERRIDE_REPLACE` (0) sets the joint's rotation from its rest orientation; `SONA_OVERRIDE_ADD` (1) rotates on top of the clip's. `weight` blends from the clip, 0 to 1 (above 1 counts as 1). A weight of 0 or a NULL `rotation` clears that joint. Joints the clip does not move are not affected while no clip plays. `SONA_E_ARGUMENT` for a joint past 70 or another mode.

### sona_avatar_clear_overrides

```c
void sona_avatar_clear_overrides(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example**:

```c
sona_avatar_clear_overrides(avatar);
```

Clears every override of the avatar. NULL is ignored.

### sona_avatar_crossfade

```c
sona_result sona_avatar_crossfade(sona_avatar *a, const char *clip, const sona_play_options *opts, float seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `clip` | `const char *` | A clip key or id | required |
| `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](reference/fields.md#sona_play_options) | required |
| `seconds` | `float` | Seconds to blend from the current pose; 0: a cut | `0`: a cut |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Getting started](getting-started.md)):

```c
sona_placement to = { { 1.0f, 0.0f, -2.0f }, 90.0f, 1.0f };
sona_avatar_move(avatar, &to, 0.5f);                  /* over half a second */
sona_avatar_crossfade(avatar, "GenericWave", NULL, 0.2f);
```

`sona_avatar_play`, blending from the current pose over `seconds`. 0, a negative or a non-finite value is a cut. It clears the queue. It returns what `sona_avatar_play` returns, so `SONA_E_ARGUMENT` for an item preview.

### sona_avatar_queue

```c
sona_result sona_avatar_queue(sona_avatar *a, const char *clip, const sona_play_options *opts, float fade_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `clip` | `const char *` | A clip key or id | required |
| `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](reference/fields.md#sona_play_options) | `NULL`: the defaults |
| `fade_seconds` | `float` | Seconds to blend over | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_LIMIT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
/* once: loop 0, speed 1, from the start */
sona_play_options once = { 0, 1.0f, 0.0f };
sona_avatar_crossfade(avatar, "GenericWave", &once, 0.2f);
sona_avatar_queue(avatar, "idle", NULL, 0.3f);
```

Plays `clip` when the current one ends, blending over `fade_seconds` (0: a cut). A looping clip never ends, so queue after a non-looping one. NULL `opts` takes the defaults. Up to `SONA_QUEUE_MAX` clips wait; `SONA_E_LIMIT` past that. `SONA_E_ARGUMENT` for a NULL or over-long clip name, or an item preview. `sona_avatar_play` and `sona_avatar_crossfade` clear the queue.

### sona_avatar_queued

```c
uint32_t sona_avatar_queued(const sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_avatar_queued(avatar);
printf("sona_avatar_queued: %lld\n", (long long)x_got);
```

How many clips are waiting in the queue. 0 for NULL.

### sona_avatar_capsule

```c
sona_result sona_avatar_capsule(const sona_avatar *a, sona_capsule *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_capsule *` | Receives the [`sona_capsule`](reference/fields.md#sona_capsule) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_capsule x_capsule;
memset(&x_capsule, 0, sizeof x_capsule);
sona_result result = sona_avatar_capsule(avatar, &x_capsule);
if (result != SONA_OK) printf("sona_avatar_capsule: %s\n", sona_result_name(result));
```

A vertical capsule around the posed body, in world space, for collisions: the segment `a`..`b` and its `radius`, scaled with the avatar. `SONA_E_NOT_READY` before the avatar is READY and posed.

### sona_avatar_expression

```c
sona_result sona_avatar_expression(sona_avatar *a, const uint8_t values[5]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `values` | `const uint8_t [5]` | The shape of the mouth, both eyebrows and both eyes; 255 leaves one as it is | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
uint8_t face[5] = { 6, 255, 255, 255, 255 };     /* mouth 6 is happy; brows and eyes from the clip */
sona_avatar_expression(avatar, face);
```

Sets the face. `values` are mouth, left eyebrow, right eyebrow, left eye, right eye, each a shape index (0 is the face's neutral shape) or 255 to leave that part as the clip has it. NULL hands the whole face back to the clip. The face texture is baked again when the shapes change; each combination is baked once and cached. `sona_pose_data.expression` reports what is shown.

Mouth shapes 0 to 6 are moods: neutral, sad, angry, confused, laughing, shocked, happy. 7 to 13 are speech shapes for lip sync: `SONA_MOUTH_O` (7), `SONA_MOUTH_AI`, `SONA_MOUTH_EE`, `SONA_MOUTH_FV`, `SONA_MOUTH_W`, `SONA_MOUTH_L`, `SONA_MOUTH_DTH` (13). `SONA_MOUTH_NEUTRAL` is 0. A sprite does not show expressions.

### sona_avatar_expression_counts

```c
sona_result sona_avatar_expression_counts(const sona_avatar *a, uint32_t counts[3]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `counts` | `uint32_t [3]` | Receives how many mouth, eyebrow and eye shapes the avatar has | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
uint32_t x_counts[3];
memset(x_counts, 0, sizeof x_counts);
sona_result result = sona_avatar_expression_counts(avatar, x_counts);
if (result != SONA_OK) printf("sona_avatar_expression_counts: %s\n", sona_result_name(result));
```

How many shapes this face has: `counts[0]` mouth, `counts[1]` eyebrows, `counts[2]` eyes. 0 for a part the face lacks. `SONA_E_NOT_READY` before READY.

### sona_avatar_clip_events

```c
uint32_t sona_avatar_clip_events(sona_avatar *a, sona_clip_event *out, uint32_t max);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `out` | `sona_clip_event *` | Receives the [`sona_clip_event`](reference/fields.md#sona_clip_event) | required |
| `max` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example**:

```c
sona_clip_event x_clip_event;
memset(&x_clip_event, 0, sizeof x_clip_event);
uint32_t x_got = sona_avatar_clip_events(avatar, &x_clip_event, 1);
printf("sona_avatar_clip_events: %lld\n", (long long)x_got);
```

Moves up to `max` events into `out`, oldest first, and returns how many. They are what happened on the avatar's clip since the last call. 0 for NULL arguments or `max` 0. Footfalls come from the evaluated pose, so an avatar that is not posed (culled, a sprite, or not READY) has none. Up to `SONA_CLIP_EVENT_MAX` are held; past that the oldest go.

### sona_avatar_mark

```c
sona_result sona_avatar_mark(sona_avatar *a, float seconds, uint32_t id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `seconds` | `float` | The clip time the mark sits at, seconds | - |
| `id` | `uint32_t` | An id of your own, given back with the event | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_mark(avatar, 0.5f, 0);
if (result != SONA_OK) printf("sona_avatar_mark: %s\n", sona_result_name(result));
```

A MARK event with this `id` each time the current clip passes `seconds`. Marks go when another clip starts. `SONA_E_ARGUMENT` for a negative or NaN time; `SONA_E_LIMIT` past `SONA_MARK_MAX` marks.

### sona_avatar_clear_marks

```c
void sona_avatar_clear_marks(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example**:

```c
sona_avatar_clear_marks(avatar);
```

Removes the avatar's marks. NULL is ignored.

### sona_avatar_root_motion

```c
sona_result sona_avatar_root_motion(sona_avatar *a, uint32_t mode);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `mode` | `uint32_t` | `SONA_ROOT_MOTION_OFF`, `_EXTRACT` or `_APPLY` | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
float upper[SONA_JOINT_COUNT];
sona_layer_options lo;

sona_avatar_play(a, "00400000-0064-0003-c1c8-f109a19cb2e0", NULL);   /* the stock walk */
sona_avatar_root_motion(a, SONA_ROOT_MOTION_EXTRACT);                /* walk in place, the game moves the avatar */

sona_mask_preset(SONA_MASK_UPPER_BODY, upper);
sona_layer_defaults(&lo);
lo.mask = upper;
sona_avatar_layer_play(a, 1, "GenericWave", &lo);                  /* layer 1: the wave, on Spine and above */
```

What happens to the clip's sideways travel of the hips. `SONA_ROOT_MOTION_OFF` (0) leaves it in the pose. `SONA_ROOT_MOTION_EXTRACT` (1) holds the hips where the clip starts and collects the travel for `sona_avatar_take_root_motion`. `SONA_ROOT_MOTION_APPLY` (2) moves the avatar's placement by it each update. Setting a mode drops what was collected. `SONA_E_ARGUMENT` for another mode.

### sona_avatar_take_root_motion

```c
sona_result sona_avatar_take_root_motion(sona_avatar *a, float delta[3]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `delta` | `float [3]` | Receives the root motion since the last call, world space | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
float x_delta[3];
memset(x_delta, 0, sizeof x_delta);
sona_result result = sona_avatar_take_root_motion(avatar, x_delta);
if (result != SONA_OK) printf("sona_avatar_take_root_motion: %s\n", sona_result_name(result));
```

The travel collected since the last call, in world metres (the avatar's turn and scale applied), and clears it.

## Animation layers

Section 3.8c of the header. The guide, with examples, the rules for root motion, threads and crowds, and the measured
cost, is [Animation layers and states](guides/layers.md). New structs: `sona_layer_options` (48 bytes, 44 with 4-byte
pointers), `sona_layer_info` (40), `sona_layer_event` (20), `sona_blend_sample` (24 / 16), `sona_blend_space_desc`
(48 / 36), `sona_state_desc` (32 / 20), `sona_condition` (16 / 12), `sona_transition_desc` (96 / 72),
`sona_state_machine_desc` (40 / 28), and the opaque `sona_blend_space` and `sona_state_machine`. Structs with a `size`
field are filled from their `_defaults` call (or `size` set to `sizeof`); a smaller `size` is `SONA_E_ARGUMENT`.
Every layer call returns `SONA_E_ARGUMENT` for a NULL avatar, a layer past `SONA_LAYER_MAX - 1` or an item preview,
and `SONA_E_DESTROYED` for a removed one.

### sona_layer_defaults

```c
void sona_layer_defaults(sona_layer_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_layer_options *` | The [`sona_layer_options`](reference/fields.md#sona_layer_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
float upper[SONA_JOINT_COUNT];
sona_layer_options lo;

sona_avatar_play(a, "00400000-0064-0003-c1c8-f109a19cb2e0", NULL);   /* the stock walk */
sona_avatar_root_motion(a, SONA_ROOT_MOTION_EXTRACT);                /* walk in place, the game moves the avatar */

sona_mask_preset(SONA_MASK_UPPER_BODY, upper);
sona_layer_defaults(&lo);
lo.mask = upper;
sona_avatar_layer_play(a, 1, "GenericWave", &lo);                  /* layer 1: the wave, on Spine and above */
```

`size` set, `SONA_LAYER_OVERRIDE`, no flags, `loop` 1, `weight` 1, `fade_seconds` 0.2, `speed` 1, `from` 0,
`additive_ref` 0, `mask` NULL. NULL is ignored.

### sona_avatar_layer_play

```c
sona_result sona_avatar_layer_play(sona_avatar *a, uint32_t layer, const char *clip, const sona_layer_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `clip` | `const char *` | A clip key or id | required |
| `opts` | `const sona_layer_options *` | The options, a [`sona_layer_options`](reference/fields.md#sona_layer_options) | `NULL`: the defaults |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
float upper[SONA_JOINT_COUNT];
sona_layer_options lo;

sona_avatar_play(a, "00400000-0064-0003-c1c8-f109a19cb2e0", NULL);   /* the stock walk */
sona_avatar_root_motion(a, SONA_ROOT_MOTION_EXTRACT);                /* walk in place, the game moves the avatar */

sona_mask_preset(SONA_MASK_UPPER_BODY, upper);
sona_layer_defaults(&lo);
lo.mask = upper;
sona_avatar_layer_play(a, 1, "GenericWave", &lo);                  /* layer 1: the wave, on Spine and above */
```

Plays a clip key or raw clip id on the layer, crossfading from what it showed over `fade_seconds`. NULL `opts`: the
defaults. `SONA_E_ARGUMENT` also for `"idle"`, `"still"`, `"prop"`, an unknown key and an option out of range
(`weight` outside 0..1, a negative or NaN time or speed, a mask weight outside 0..1). Changing between OVERRIDE and
ADDITIVE cuts instead of crossfading.

### sona_avatar_layer_blend

```c
sona_result sona_avatar_layer_blend(sona_avatar *a, uint32_t layer, sona_blend_space *b, const sona_layer_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `b` | `sona_blend_space *` | The blend space | required |
| `opts` | `const sona_layer_options *` | The options, a [`sona_layer_options`](reference/fields.md#sona_layer_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
sona_blend_sample s[3] = {
  { "Stand0", 0.0f, 0, 1 },                              /* clip, x, y, playback rate */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 },  /* walk */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */
};
sona_blend_space_desc d;
sona_blend_space *move;
sona_blend_space_defaults(&d);
d.param_x = "speed";
d.samples = s;
d.sample_count = 3;
sona_blend_space_create(ctx, &d, &move);
sona_avatar_layer_blend(a, 0, move, NULL);
sona_blend_space_destroy(move);                          /* the avatar keeps it while it plays */
```

Plays a blend space of the same ctx on the layer. `from` is the fraction 0..1 of its shared cycle (seconds with
`SONA_BLEND_UNSYNCED`).

### sona_avatar_layer_machine

```c
sona_result sona_avatar_layer_machine(sona_avatar *a, uint32_t layer, sona_state_machine *m, const sona_layer_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `m` | `sona_state_machine *` | The state machine | required |
| `opts` | `const sona_layer_options *` | The options, a [`sona_layer_options`](reference/fields.md#sona_layer_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Runs a state machine of the same ctx on the layer from its initial state (a `STATE` event with `from_state` -1).
`speed` scales every state's speed; each state says whether it loops.

### sona_avatar_layer_goto

```c
sona_result sona_avatar_layer_goto(sona_avatar *a, uint32_t layer, uint32_t state, float fade_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `state` | `uint32_t` | A state's index | - |
| `fade_seconds` | `float` | Seconds to blend over | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_layer_goto(avatar, 0, 0, 0.5f);
if (result != SONA_OK) printf("sona_avatar_layer_goto: %s\n", sona_result_name(result));
```

Sends a machine layer to `state` now, crossfading over `fade_seconds`. `SONA_E_ARGUMENT` when the layer runs no
machine or the state is past its last.

### sona_avatar_layer_weight

```c
sona_result sona_avatar_layer_weight(sona_avatar *a, uint32_t layer, float weight, float over_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `weight` | `float` | A weight from 0 to 1 | - |
| `over_seconds` | `float` | Seconds to ease over; 0: at once | `0`: at once |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_layer_weight(avatar, 0, 0.5f, 0.5f);
if (result != SONA_OK) printf("sona_avatar_layer_weight: %s\n", sona_result_name(result));
```

Moves the layer's weight linearly to `weight` (0..1) over `over_seconds`; 0 or less sets it at once.

### sona_avatar_layer_mask

```c
sona_result sona_avatar_layer_mask(sona_avatar *a, uint32_t layer, const float *mask);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `mask` | `const float *` | A weight per joint, `SONA_JOINT_COUNT` of them; NULL: the whole body | `NULL`: the whole body |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Copies `SONA_JOINT_COUNT` weights (each 0..1); NULL is every joint. Takes effect at the next pose.

### sona_avatar_layer_stop

```c
sona_result sona_avatar_layer_stop(sona_avatar *a, uint32_t layer, float fade_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `fade_seconds` | `float` | Seconds to blend over | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_layer_stop(avatar, 0, 0.5f);
if (result != SONA_OK) printf("sona_avatar_layer_stop: %s\n", sona_result_name(result));
```

Fades the layer out over `fade_seconds` and then empties it (a `STOPPED` event); 0 empties it now. An empty layer
is `SONA_OK`.

### sona_avatar_layer_info

```c
sona_result sona_avatar_layer_info(const sona_avatar *a, uint32_t layer, sona_layer_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - |
| `out` | `sona_layer_info *` | Receives the [`sona_layer_info`](reference/fields.md#sona_layer_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_layer_info x_layer_info;
memset(&x_layer_info, 0, sizeof x_layer_info);
x_layer_info.size = sizeof x_layer_info;
sona_result result = sona_avatar_layer_info(avatar, 0, &x_layer_info);
if (result != SONA_OK) printf("sona_avatar_layer_info: %s\n", sona_result_name(result));
```

The layer now: `kind`, `mode`, `state` (machines, else -1), `clip` (the `sona_clip_get` index, -1 for a raw id),
`weight` with fades, `time` and `normalized` through the clip or cycle, `ready` (its clips have loaded) and
`fading`. The caller sets `out->size`.

### sona_avatar_layer_events

```c
uint32_t sona_avatar_layer_events(sona_avatar *a, sona_layer_event *out, uint32_t max);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `out` | `sona_layer_event *` | Receives the [`sona_layer_event`](reference/fields.md#sona_layer_event) | required |
| `max` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example**:

```c
sona_layer_event x_layer_event;
memset(&x_layer_event, 0, sizeof x_layer_event);
uint32_t x_got = sona_avatar_layer_events(avatar, &x_layer_event, 1);
printf("sona_avatar_layer_events: %lld\n", (long long)x_got);
```

Moves up to `max` events, oldest first, into `out` and returns how many: `STARTED`, `LOOPED`, `ENDED`, `STATE`,
`STOPPED`, each with its `layer`, `state` and `from_state` (machines; else -1) and `time` (seconds into the clip).
Up to `SONA_LAYER_EVENT_MAX` are held; past that the oldest go.

### sona_mask_preset

```c
sona_result sona_mask_preset(uint32_t preset, float mask[SONA_JOINT_COUNT]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `preset` | `uint32_t` | Which preset, one of the header's constants for it | - |
| `mask` | `float [SONA_JOINT_COUNT]` | Receives a weight per joint | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
sona_mask_preset(SONA_MASK_UPPER_BODY, m);
sona_mask_branch(m, sona_joint_find("Spine"), 0.5f);    /* half the wave in the spine ... */
sona_mask_branch(m, sona_joint_find("Chest"), 1.0f);    /* ... all of it from the chest up */
```

Fills a mask: `SONA_MASK_NONE`, `_FULL`, `_UPPER_BODY` (Spine and below it), `_LOWER_BODY` (the hips and legs),
`_HEAD` (from the Neck), `_LEFT_ARM`, `_RIGHT_ARM`, `_ARMS` (from the shoulders). Joint 71 is always 0.

### sona_mask_branch

```c
sona_result sona_mask_branch(float mask[SONA_JOINT_COUNT], uint32_t joint, float weight);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mask` | `float [SONA_JOINT_COUNT]` | Receives a weight per joint | required |
| `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - |
| `weight` | `float` | A weight from 0 to 1 | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
sona_mask_preset(SONA_MASK_UPPER_BODY, m);
sona_mask_branch(m, sona_joint_find("Spine"), 0.5f);    /* half the wave in the spine ... */
sona_mask_branch(m, sona_joint_find("Chest"), 1.0f);    /* ... all of it from the chest up */
```

Sets `joint` and every joint below it in the rig to `weight` (0..1); the rest is kept.

### sona_param_id

```c
int32_t sona_param_id(sona_ctx *ctx, const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `name` | `const char *` | A parameter's name, 1 to 31 bytes | required |

**Returns** `int32_t`.

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
int32_t speed = sona_param_id(ctx, "speed");      /* 0 */
int32_t turn = sona_param_id(ctx, "turn");        /* 1 */
/* ... */
float p[2] = { player_speed, player_turn };
sona_avatar_set_params(a, 0, p, 2);               /* each frame, before sona_update */
```

The id of a parameter name (1 to 31 bytes), made on first use and numbered from 0 in that order; -1 for a bad name
or past `SONA_PARAM_MAX` (32) names.

### sona_avatar_set_param

```c
sona_result sona_avatar_set_param(sona_avatar *a, int32_t param, float value);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `param` | `int32_t` | A parameter id, from `sona_param_id` | - |
| `value` | `float` | The value to set | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_set_param(avatar, 0, 0.5f);
if (result != SONA_OK) printf("sona_avatar_set_param: %s\n", sona_result_name(result));
```

Sets one parameter on the avatar; read at the next `sona_update`. `SONA_E_ARGUMENT` for an id outside 0..31 or a
value that is not finite.

### sona_avatar_set_params

```c
sona_result sona_avatar_set_params(sona_avatar *a, uint32_t first, const float *values, uint32_t count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `first` | `uint32_t` | The id of the first parameter to set | - |
| `values` | `const float *` | The values, `count` of them | required |
| `count` | `uint32_t` | How many entries the array holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
int32_t speed = sona_param_id(ctx, "speed");      /* 0 */
int32_t turn = sona_param_id(ctx, "turn");        /* 1 */
/* ... */
float p[2] = { player_speed, player_turn };
sona_avatar_set_params(a, 0, p, 2);               /* each frame, before sona_update */
```

Sets parameters `first .. first + count - 1`: a game's one call a frame. Nothing is set when any value is not
finite or the range passes `SONA_PARAM_MAX`.

### sona_avatar_param

```c
float sona_avatar_param(const sona_avatar *a, int32_t param);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `param` | `int32_t` | A parameter id, from `sona_param_id` | - |

**Returns** `float`.

**Example**:

```c
float x_got = sona_avatar_param(avatar, 0);
printf("sona_avatar_param: %g\n", (double)x_got);
```

A parameter's value; 0 when unset or unknown. Triggers read 0 once their transition fired.

### sona_blend_space_defaults

```c
void sona_blend_space_defaults(sona_blend_space_desc *d);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `d` | `sona_blend_space_desc *` | The [`sona_blend_space_desc`](reference/fields.md#sona_blend_space_desc) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
sona_blend_sample s[3] = {
  { "Stand0", 0.0f, 0, 1 },                              /* clip, x, y, playback rate */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 },  /* walk */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */
};
sona_blend_space_desc d;
sona_blend_space *move;
sona_blend_space_defaults(&d);
d.param_x = "speed";
d.samples = s;
d.sample_count = 3;
sona_blend_space_create(ctx, &d, &move);
sona_avatar_layer_blend(a, 0, move, NULL);
sona_blend_space_destroy(move);                          /* the avatar keeps it while it plays */
```

`size` set, `dims` 1, no samples, `smooth_seconds` 0.1.

### sona_blend_space_create

```c
sona_result sona_blend_space_create(sona_ctx *ctx, const sona_blend_space_desc *d, sona_blend_space **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `d` | `const sona_blend_space_desc *` | The options, a [`sona_blend_space_desc`](reference/fields.md#sona_blend_space_desc) | required |
| `out` | `sona_blend_space **` | Receives the new blend space | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
sona_blend_sample s[3] = {
  { "Stand0", 0.0f, 0, 1 },                              /* clip, x, y, playback rate */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 },  /* walk */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */
};
sona_blend_space_desc d;
sona_blend_space *move;
sona_blend_space_defaults(&d);
d.param_x = "speed";
d.samples = s;
d.sample_count = 3;
sona_blend_space_create(ctx, &d, &move);
sona_avatar_layer_blend(a, 0, move, NULL);
sona_blend_space_destroy(move);                          /* the avatar keeps it while it plays */
```

Checks and copies the desc and starts loading its clips. `SONA_E_ARGUMENT`, with the bad sample named in
`sona_last_error`: `dims` not 1 or 2, 0 or over 16 samples, a missing parameter name, a clip that is not a key or id,
two samples at one point, a negative or NaN value. 2D samples are triangulated here.

### sona_blend_space_destroy

```c
void sona_blend_space_destroy(sona_blend_space *b);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `b` | `sona_blend_space *` | The blend space | required |

**Returns** Nothing.

**Example** (also in [Animation layers, masks, blend spaces and state machines](guides/layers.md)):

```c
sona_blend_sample s[3] = {
  { "Stand0", 0.0f, 0, 1 },                              /* clip, x, y, playback rate */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 },  /* walk */
  { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */
};
sona_blend_space_desc d;
sona_blend_space *move;
sona_blend_space_defaults(&d);
d.param_x = "speed";
d.samples = s;
d.sample_count = 3;
sona_blend_space_create(ctx, &d, &move);
sona_avatar_layer_blend(a, 0, move, NULL);
sona_blend_space_destroy(move);                          /* the avatar keeps it while it plays */
```

Lets go of the host's handle. Avatars and states that play it keep it until they stop; `sona_close` frees the
rest.

### sona_blend_space_weights

```c
uint32_t sona_blend_space_weights(const sona_blend_space *b, float x, float y, float *weights);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `b` | `const sona_blend_space *` | The blend space | required |
| `x` | `float` | The blend space's first input | - |
| `y` | `float` | The blend space's second input | - |
| `weights` | `float *` | Receives a weight per sample | required |

**Returns** `uint32_t`.

Writes each sample's weight at `(x, y)` (they sum to 1; `y` is ignored in 1D) and returns how many are above 0
(1 to 3). 0 for a NULL argument or a NaN point.

### sona_state_machine_defaults

```c
void sona_state_machine_defaults(sona_state_machine_desc *d);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `d` | `sona_state_machine_desc *` | The [`sona_state_machine_desc`](reference/fields.md#sona_state_machine_desc) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_state_machine_desc x_state_machine_desc;
memset(&x_state_machine_desc, 0, sizeof x_state_machine_desc);
x_state_machine_desc.size = sizeof x_state_machine_desc;
sona_state_machine_defaults(&x_state_machine_desc);
```

`size` set, everything else zero.

### sona_state_machine_create

```c
sona_result sona_state_machine_create(sona_ctx *ctx, const sona_state_machine_desc *d, sona_state_machine **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `d` | `const sona_state_machine_desc *` | The options, a [`sona_state_machine_desc`](reference/fields.md#sona_state_machine_desc) | required |
| `out` | `sona_state_machine **` | Receives the new state machine | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Resolves every name to an index once. `SONA_E_ARGUMENT`, naming the state, transition or condition in
`sona_last_error`: 0 or over 32 states, over 64 transitions, a state name that is empty, over 31 bytes or used
twice, a state with both or neither of a clip and a blend space, a transition naming an unknown state, a negative
fade, more than 4 conditions, an unknown op, a bad parameter name, a value that is not finite, an unknown initial
state.

### sona_state_machine_destroy

```c
void sona_state_machine_destroy(sona_state_machine *m);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_state_machine *` | The state machine | required |

**Returns** Nothing.

As `sona_blend_space_destroy`.

### sona_state_machine_find

```c
int32_t sona_state_machine_find(const sona_state_machine *m, const char *state);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const sona_state_machine *` | The state machine | required |
| `state` | `const char *` | A state's name | required |

**Returns** `int32_t`.

A state's index by name, -1 if unknown.

### sona_state_machine_state_name

```c
const char *sona_state_machine_state_name(const sona_state_machine *m, uint32_t state);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const sona_state_machine *` | The state machine | required |
| `state` | `uint32_t` | A state's index | - |

**Returns** `const char *`.

A state's name, NULL past the last. Valid while the machine lives.

## Clips

`sona_clip_info` holds `key` ("GenericWave", "Stand0", ...), `id` (the clip's item id, or NULL for "idle", "still" and "prop"), `seconds` (negative when not known until decoded), `prop` (1 for the held prop's own clip) and `caption` (may be NULL).

### sona_clip_count

```c
uint32_t sona_clip_count(const sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_clip_count(ctx);
printf("sona_clip_count: %lld\n", (long long)x_got);
```

How many clips the context knows.

### sona_clip_get

```c
sona_result sona_clip_get(const sona_ctx *ctx, uint32_t index, sona_clip_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_clip_info *` | Receives the [`sona_clip_info`](reference/fields.md#sona_clip_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_clip_info x_clip_info;
memset(&x_clip_info, 0, sizeof x_clip_info);
sona_result result = sona_clip_get(ctx, 0, &x_clip_info);
if (result != SONA_OK) printf("sona_clip_get: %s\n", sona_result_name(result));
```

One clip by index, `0 .. sona_clip_count() - 1`.

## The frame

`sona_view` holds doubles, as the JavaScript keeps plain numbers: the camera maths runs in double and stores float matrices only at the end.

| Field | Meaning |
|---|---|
| `eye[3]`, `target[3]` | Up is always +Y (look-at, left-handed), as the web camera |
| `fov_deg` | Vertical field of view in degrees; default 28.65, as the web |
| `near_z` | Default 0.05 |
| `far_z` | Default 200 (the web SDK's; the editor uses 20) |
| `width`, `height` | The target size in pixels, for LOD and culling |

`sona_frame_stats` reports one update: `ms` (the dt passed in), `cpu_ms` (time inside `sona_update`), `drawn`, `culled`, `draw_calls` (main-pass draws of the last `sona_draw`) and `built` (build steps run).

`sona_scene_stats` is the running picture, as the web's `stats()`: `fps`, `ms_per_frame`, `p95_ms`, `cpu_ms_per_frame`, `avatars`, `ready`, `queued`, `drawn`, `draw_calls`, `geometries`, `textures`, `gpu_mb`, `cpu_mb`, `build_ms_avg`, `build_ms_max`, and `long_frames` (frames over the 33.4 ms threshold, counted over a window set to 2 s).

### sona_view_defaults

```c
void sona_view_defaults(sona_view *v);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `v` | `sona_view *` | The [`sona_view`](reference/fields.md#sona_view) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
sona_view_defaults(&x_view);
```

The web's full-body framing.

### sona_update

```c
sona_result sona_update(sona_ctx *ctx, double dt_seconds, const sona_view *view, sona_frame_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `dt_seconds` | `double` | Seconds since the last update | - |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | `NULL` allowed (below) |
| `out` | `sona_frame_stats *` | Receives the [`sona_frame_stats`](reference/fields.md#sona_frame_stats) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_IO`, `SONA_E_GATE` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The NPC kit (sona_npc)](guides/npc.md)):

```c
sona_npc_update(npc, dt);
sona_update(ctx, dt, NULL, NULL);

sona_npc_state st;
st.size = sizeof st;
sona_npc_state_get(npc, &st);   /* SONA_NPC_IDLE, _SPEAKING (st.line), _EMOTING; st.queued */
```

Advances every avatar by `dt_seconds` (clamped to 0..0.1 s, as the web), runs build steps inside the build budget, culls against the view and poses what is due (the web's LOD rules). It also drains finished reads and jobs. `view` may be NULL: then nothing is culled and every avatar poses every frame. The view is used only for culling and LOD; palettes are folded with each draw's own view in `sona_draw` and `sona_snapshot`.

### sona_stats

```c
void sona_stats(const sona_ctx *ctx, sona_scene_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `out` | `sona_scene_stats *` | Receives the [`sona_scene_stats`](reference/fields.md#sona_scene_stats) | required |

**Returns** Nothing.

**Example**:

```c
sona_scene_stats x_scene_stats;
memset(&x_scene_stats, 0, sizeof x_scene_stats);
sona_stats(ctx, &x_scene_stats);
```

Fills `*out` with the scene statistics.

## Crowds: level of detail and sprites

The guide, with the measured stadium numbers, is [Crowds](guides/crowd.md).

Each `sona_update` with a view gives every avatar in view a step from its height on screen in pixels:

| Step | When | Posed | Drawn as |
|---|---|---|---|
| `SONA_LOD_FULL` (0) | at or above `full_px` | every frame | its meshes |
| `SONA_LOD_SAMPLED` (1) | from `quarter_px` up to `full_px` | when the clip reaches a new frame | its meshes |
| `SONA_LOD_QUARTER` (2) | below `quarter_px` | as SAMPLED, and at most every 4th frame | its meshes |
| `SONA_LOD_SPRITE` (3) | below `sprite_px`, its look baked | never | one textured quad |

A sprite is a picture of the avatar, baked once per look (the manifest's bytes) and turn. Avatars cross between mesh and sprite over `fade_seconds`. A ctx opens with sprites off (`sprite_px` 0) and thresholds 120 and 40 until `sona_lod_set`.

`sona_lod_options`, 32 bytes:

| Field | Range | Default | Meaning |
|---|---|---|---|
| `full_px` | `>= quarter_px` | 120 | At or above: FULL |
| `quarter_px` | `0 .. full_px` | 40 | Below: QUARTER |
| `sprite_px` | `>= 0` | 48 | Below: SPRITE. 0: never |
| `fade_seconds` | `0 .. 10` | 0.25 | The mesh-to-sprite crossfade; 0 is a cut |
| `sprite_angles` | `4 .. 32` | 8 | Turns baked per look |
| `sprite_height` | `32 .. 512`, even | 64 | Pixels per baked picture; half as wide |
| `max_looks` | `1 .. 65536` | 16384 | Baked looks kept per renderer; avatars past it stay meshes |
| `bake_ms` | `>= 0` | 4 | Baking time per `sona_draw`; at least one batch of looks is baked when one is needed |

`sprite_angles * sprite_height / 2` must be 4096 or less.

`sona_lod_stats`, 32 bytes: `full`, `sampled`, `quarter`, `sprite` (avatars in view per step at the last `sona_update`), `fading` (of those, crossing between a mesh and a sprite), `looks` (baked looks over every renderer), `bakes` (looks baked by the last `sona_draw` or `sona_snapshot`), `bake_ms` (the time those took).

Rules for sprites:

- **Bakes happen inside `sona_draw` and `sona_snapshot`,** straight into the renderer's atlas pages. `sona_draw` records the bake into the host's frame, ahead of the picture (on Vulkan into the target's command buffer: nothing is submitted and nothing waits); a draw that bakes uses two frame indices. `sona_snapshot` bakes through the backend's readback, as it draws.
- **Sheets belong to a renderer.** An avatar becomes a sprite only when every renderer that drew it since the last `sona_update` has its look baked. While a renderer without sprites draws the ctx, far avatars stay meshes on every renderer, and no renderer ever loses an avatar.
- **Backends.** Vulkan, GL and GLES draw sprites. D3D11, D3D12, Metal and Xenos do not; far avatars stay meshes at the QUARTER rate there.
- **The bake must fit the device.** One look's sheet is `sprite_angles * (h / 2 + 2 * (h / 16))` pixels wide and `h + 2 * (h / 16)` tall (`h` = `sprite_height`), and a bake pass holds up to 32 sheets in a column. A device whose largest texture is smaller bakes fewer looks a pass; one that cannot fit a sheet draws no sprites.

### sona_lod_defaults

```c
void sona_lod_defaults(sona_lod_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_lod_options *` | The [`sona_lod_options`](reference/fields.md#sona_lod_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_lod_options x_lod_options;
memset(&x_lod_options, 0, sizeof x_lod_options);
sona_lod_defaults(&x_lod_options);
```

Writes the defaults in the table above, with sprites on at 48 px. NULL is ignored.

### sona_lod_set

```c
sona_result sona_lod_set(sona_ctx *ctx, const sona_lod_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_lod_options *` | The options, a [`sona_lod_options`](reference/fields.md#sona_lod_options) | `NULL`: the defaults |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Crowds: level of detail and sprites](guides/crowd.md)):

```c
/* 10,000 avatars in rows round a pitch, facing in */
sona_lod_set(ctx, NULL);
for (i = 0; i < 10000; i++) {
  sona_add_options o;
  sona_add_defaults(&o);
  seat(i, o.place.position, &o.place.turn_deg);   /* your layout */
  o.start_at = -1;                                 /* random start: a crowd out of step */
  sona_avatar_add_base64(ctx, looks[i % 12], &o, &av[i]);
}
```

Sets the options; NULL sets the defaults. Takes effect at the next `sona_update`. Changing `sprite_angles` or `sprite_height` drops every baked sheet; they are baked again as needed.

- `SONA_E_ARGUMENT`: `ctx` is NULL, a value is out of range or NaN, or `sprite_px` is above 0 and a renderer already on the ctx has a device too small for one sheet of the bake. Nothing changes then.
- `SONA_E_MEMORY`: the allocator failed (first call only).
- A renderer made later on a device too small for the options draws no sprites. It logs a warning once.

### sona_lod_get

```c
sona_result sona_lod_get(const sona_ctx *ctx, sona_lod_options *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `out` | `sona_lod_options *` | Receives the [`sona_lod_options`](reference/fields.md#sona_lod_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_lod_options x_lod_options;
memset(&x_lod_options, 0, sizeof x_lod_options);
sona_result result = sona_lod_get(ctx, &x_lod_options);
if (result != SONA_OK) printf("sona_lod_get: %s\n", sona_result_name(result));
```

Copies the current options: before any `sona_lod_set`, thresholds 120 and 40 and no sprites (`sprite_px` 0). `SONA_E_ARGUMENT` for a NULL argument.

### sona_avatar_lod

```c
uint32_t sona_avatar_lod(const sona_avatar *a, float *fade);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `fade` | `float *` | Receives the crossfade between two levels, 0 to 1; may be NULL | `NULL` allowed (below) |

**Returns** `uint32_t`.

The avatar's step at the last `sona_update`, and in `*fade` how far it is from its mesh (0) to its sprite (1). `SONA_LOD_FULL` and 0 for NULL, an avatar that is not READY, and one that was not in view at that update (culled or hidden). Back in view it has its step again. `fade` may be NULL.

### sona_lod_stats_get

```c
void sona_lod_stats_get(const sona_ctx *ctx, sona_lod_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `out` | `sona_lod_stats *` | Receives the [`sona_lod_stats`](reference/fields.md#sona_lod_stats) | required |

**Returns** Nothing.

**Example**:

```c
sona_lod_stats x_lod_stats;
memset(&x_lod_stats, 0, sizeof x_lod_stats);
sona_lod_stats_get(ctx, &x_lod_stats);
```

Fills `*out`. All zero before the first `sona_lod_set`. NULL arguments are ignored.

## The data API

For hosts and engines that draw with their own renderer. A posed avatar is a `sona_pose_data`:

| Field | Meaning |
|---|---|
| `build_version` | Bumps when meshes, materials or textures change |
| `world[16]` | `W = scale * rotateY(turn) * translate(position)`, row-vector |
| `palette` | 864 floats: per joint 3 float4, columns 0..2 of the row-vector skin matrix, in avatar space |
| `view_joints` | 72 x 3 floats: each joint's translation before `W` |
| `meshes`, `mesh_count` | In draw order |
| `materials`, `material_count` | The materials the meshes draw with: each a `sona_material` (shader family, `SONA_MAT_*` flags, parameters, textures); a mesh names one by index |
| `textures`, `texture_count` | The face sheet is one of them (its material has `SONA_MAT_FACE`) |
| `props`, `prop_count` | Palettes for held props (up to 4), then, with sway on, one for each swaying mesh ([sway](guides/sway.md)), so `prop_count` can pass 4; size arrays by it |
| `expression[5]` | Mouth, left eyebrow, right eyebrow, left eye, right eye |

A `sona_mesh` holds `item` (the item it came from), `mask` (its AssetMask), `batch`, `material` (index into materials), `pass` (SONA_PASS_OPAQUE or SONA_PASS_TRANSPARENT), `palette` (-1: the body; else an index into props), `vertex_count`, `index_count`, `vertices`, `indices` (uint16 triangle list) and `key`. `key` is stable while the geometry lives and is shared by avatars wearing the same item, so a host can cache uploads by it.

The runtime vertex is 76 bytes, in host byte order:

| Offset | Type | What |
|---|---|---|
| +0 | float3 | Position (bind pose, avatar space) |
| +12 | uint8 x4 | Joint index x 3 (the palette's float4 row) |
| +16 | uint8 x4 | Weight (sum 255) |
| +20 | uint8 x4 | Normal, `(n * 0.5 + 0.5) * 255`; byte 23 is 0 |
| +24 | uint8 x4 | Vertex colour (baked occlusion and alpha) |
| +28 | float4 | uv0.xy, uv1.xy |
| +44 | float4 | uv2.xy, uv3.xy (the HQ shaders read uv2 only) |
| +60 | float4 | uv4.xy, uv5.xy |

A `sona_material` holds `shader_id` (0..4, the app's material family), `flags` (SONA_MAT_*), `params[40]` (AvatarShaderParams, 10 float4; the baked shaders read only 36..39), `transparency`, `color_tex`, `intensity_tex`, `decal_tex`, `color_addr`, `intensity_addr` and `decal_addr`. A texture index of -1 means neutral: white for colour, (0,0,0,255) for intensity and decal. The decal slot holds the matcap for reflective materials. Address modes: bit 0 set means U wraps, bit 1 set means V wraps; clear means clamp.

Material flags: `SONA_MAT_SKIN` (the skin program), `SONA_MAT_REFLECTIVE` (the decal slot holds the matcap), `SONA_MAT_FACE` (the colour texture is the face sheet), `SONA_MAT_TRANSPARENT`, `SONA_MAT_CARRYABLE` (drawn with a prop palette, or not drawn when it has none).

A `sona_texture` holds `key` (stable while it lives), `version` (bumps when the pixels change, as the face sheet does), `format`, `width`, `height`, `data` and `bytes`. Formats: `SONA_TEX_RGBA8_SRGB` (decoded and preprocessed, as the web uploads it; `width * height * 4` bytes), `SONA_TEX_RGBA16F_CUBE` (the irradiance cube: 6 faces, +X -X +Y -Y +Z -Z). `SONA_TEX_BC1_SRGB` and `SONA_TEX_BC3_SRGB` are reserved for 1.1.

A `sona_prop_palette` holds `item`, `playing` and `palette` (864 floats). While `playing` is 0 the prop's meshes are not drawn.

### sona_pose

```c
sona_result sona_pose(sona_avatar *a, const sona_pose_data **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `out` | `const sona_pose_data **` | Receives a pointer to the `sona_pose_data`, which the library keeps | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Drawing avatars with your own renderer](guides/own-renderer.md)):

```c
static float positions[65536 * 3], normals[65536 * 3];
const sona_pose_data *pose = NULL;
if (sona_pose(avatar, &pose) == SONA_OK && pose->mesh_count > 0) {
  const sona_mesh *m = &pose->meshes[0];
  if (m->vertex_count <= 65536 &&
      sona_pose_vertices(avatar, 0, SONA_SPACE_WORLD, positions, normals, 3) == SONA_OK)
    my_draw_positions(positions, normals, m->vertex_count, m->indices, m->index_count);
}
```

The avatar's pose data, valid until the next `sona_update`. `SONA_E_NOT_READY` before `READY`.

### sona_pose_vertices

```c
sona_result sona_pose_vertices(sona_avatar *a, uint32_t mesh, uint32_t space,
                               float *positions, float *normals, size_t stride_floats);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `mesh` | `uint32_t` | A mesh index of the pose data | - |
| `space` | `uint32_t` | `SONA_SPACE_*`: the space the vertices come back in | - |
| `positions` | `float *` | Receives the positions | required |
| `normals` | `float *` | Receives the normals, or NULL | `NULL`: not written |
| `stride_floats` | `size_t` | Floats from one vertex to the next in the output | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Drawing avatars with your own renderer](guides/own-renderer.md)):

```c
static float positions[65536 * 3], normals[65536 * 3];
const sona_pose_data *pose = NULL;
if (sona_pose(avatar, &pose) == SONA_OK && pose->mesh_count > 0) {
  const sona_mesh *m = &pose->meshes[0];
  if (m->vertex_count <= 65536 &&
      sona_pose_vertices(avatar, 0, SONA_SPACE_WORLD, positions, normals, 3) == SONA_OK)
    my_draw_positions(positions, normals, m->vertex_count, m->indices, m->index_count);
}
```

CPU skinning, for hosts that cannot skin on the GPU. Writes `vertex_count` positions (and normals, when `normals` is not NULL) for one mesh, `stride_floats` apart (at least 3). `space` is `SONA_SPACE_AVATAR` or `SONA_SPACE_WORLD`. Uses SIMD where the CPU has it.

### sona_shading_get

```c
sona_result sona_shading_get(sona_ctx *ctx, sona_shading *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `out` | `sona_shading *` | Receives the [`sona_shading`](reference/fields.md#sona_shading) | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Drawing avatars with your own renderer](guides/own-renderer.md)):

```c
size_t len = 0;
const void *vs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 0, &len);
const void *fs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 1, &len);
sona_shading shading;
if (vs && fs && sona_shading_get(ctx, &shading) == SONA_OK) {
  /* shading.irradiance (a cube, 16 x 16 per face), shading.rim[4], shading.shadow_rows[12]:
     the constants those shaders read */
}
```

The fixed shading inputs, for hosts that rebuild the look in their own shaders: `irradiance` (16x16 per face, RGBA16F), `irradiance_gain` (1.0), `ao_gain` (0 in the SDK), `bloom_gain` (0.1875), `shadow_rows[12]` (the 3x4 light lookup), `rim[4]` (0.549, 0.502, 0.4039, 1.6). `SONA_PENDING` until the data files have loaded.

### sona_shader_source

```c
const void *sona_shader_source(sona_shader_lang lang, sona_program prog, int stage, size_t *len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `lang` | `sona_shader_lang` | The shading language | - |
| `prog` | `sona_program` | Which program of the frame | - |
| `stage` | `int` | 0 vertex, 1 fragment | - |
| `len` | `size_t *` | Receives how many bytes were written | required |

**Returns** `const void *`.

**Example** (also in [Drawing avatars with your own renderer](guides/own-renderer.md)):

```c
size_t len = 0;
const void *vs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 0, &len);
const void *fs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 1, &len);
sona_shading shading;
if (vs && fs && sona_shading_get(ctx, &shading) == SONA_OK) {
  /* shading.irradiance (a cube, 16 x 16 per face), shading.rim[4], shading.shadow_rows[12]:
     the constants those shaders read */
}
```

The SDK's own shaders, for hosts that draw themselves. `lang` is `SONA_LANG_GLSL_ES300`, `SONA_LANG_GLSL_330`, `SONA_LANG_SPIRV`, `SONA_LANG_HLSL` or `SONA_LANG_MSL`; `prog` is one of `SONA_PROG_SHADOW`, `GBUFFER`, `SSAO`, `BRIGHT`, `BLUR`, `PRESENT`, `CLOTH`, `SKIN`, `REFL`, `REFL_SKIN`, `CREDIT`; `stage` is 0 for vertex, 1 for fragment. Returns text, or SPIR-V bytes, with its length in `*len`; NULL when that language is not in this build.

## Drawing with the SDK's backends

The host owns the device and hands it over in a `sona_device_desc {backend, u, frames_in_flight}`. Pointers are the API's own handles cast to `void *`. `frames_in_flight` 0 means 2.

| Backend | `u.` | What to pass |
|---|---|---|
| `SONA_BACKEND_GL`, `SONA_BACKEND_GLES` | `gl` | `get_proc(name)`; the context current |
| `SONA_BACKEND_VULKAN` | `vk` | `instance`, `physical_device`, `device`, `queue`, `queue_family`, `api_version`, `get_instance_proc` |
| `SONA_BACKEND_D3D11` | `d3d11` | `ID3D11Device *`, `ID3D11DeviceContext *` |
| `SONA_BACKEND_D3D12` | `d3d12` | `ID3D12Device *`, `ID3D12CommandQueue *` |
| `SONA_BACKEND_METAL` | `metal` | `id<MTLDevice>` |
| `SONA_BACKEND_XENOS` | `xenos` | `struct XenosDevice *` |

A `sona_target` says where one draw lands: `width`, `height`, and per API a GL framebuffer (0: the default), a Vulkan image, view, format, layouts and command buffer (recorded into, not submitted), a D3D11 render target view, a D3D12 resource, RTV handle, states and command list (recorded into, not executed), a Metal texture and command buffer, or a Xenos surface. Row 0 is the top of the picture on every API except GL and GLES, where it is the bottom. The colour target must be UNORM RGBA8 or BGRA8, not sRGB: the present pass encodes sRGB itself, as on the web.

`sona_draw_options` holds `clear[4]` (premultiplied RGBA, default 0, 0, 0, 0), `flags` and `credit_corner`. Flags:

- `SONA_DRAW_SHADOW`: the key light shadow (the web's `shadow: true`). The shader is the web's, with no depth bias beyond the shadow pass's front-face culling, so on a bare figure it self-shadows in fine diagonal stripes with a hard edge across the chest. 360sona.com's editor and `sona_editor` draw without it.
- `SONA_DRAW_NO_BLOOM`.
- `SONA_DRAW_EDITOR_AO`: the editor's look, G-buffer and SSAO, aoGain 1.
- `SONA_DRAW_NO_CREDIT`: the app shows the credit itself; the licence still requires it.

There is no "do not clear" flag (bit 2 is reserved): present overwrites the target, colour and alpha, as the web does. To put avatars over the host's own pixels, draw into a texture and composite it. `credit_corner` is `SONA_CORNER_BOTTOM_RIGHT` (0), `BOTTOM_LEFT`, `TOP_RIGHT` or `TOP_LEFT`.

### sona_renderer_create

```c
sona_result sona_renderer_create(sona_ctx *ctx, const sona_device_desc *dev, sona_renderer **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `dev` | `const sona_device_desc *` | The options, a [`sona_device_desc`](reference/fields.md#sona_device_desc) | required |
| `out` | `sona_renderer **` | Receives the new renderer | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Getting started](getting-started.md)):

```c
sona_device_desc dev;
sona_renderer *renderer = NULL;
memset(&dev, 0, sizeof dev);
dev.backend = SONA_BACKEND_GL;
dev.u.gl.get_proc = my_gl_get_proc;          /* SDL_GL_GetProcAddress, glfwGetProcAddress, ... */
while (sona_renderer_create(ctx, &dev, &renderer) == SONA_PENDING)
  sona_update(ctx, 0, NULL, NULL);           /* the shading data is still arriving */
```

Makes a renderer on the host's device. `SONA_E_UNSUPPORTED` for a backend not compiled into this library.

### sona_renderer_destroy

```c
void sona_renderer_destroy(sona_renderer *r);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |

**Returns** Nothing.

**Example** (also in [Getting started](getting-started.md)):

```c
sona_avatar_remove(avatar);       /* frees what only it used */
sona_renderer_destroy(renderer);  /* before your device goes */
sona_close(ctx);
```

Frees the renderer and its GPU objects.

### sona_draw

```c
sona_result sona_draw(sona_renderer *r, const sona_view *view, const sona_target *target,
                      const sona_draw_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](reference/fields.md#sona_target) | required |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Device loss: getting a renderer back](guides/device-loss.md)):

```c
/* the device is gone: the draw said so */
if (sona_draw(r, &view, &target, NULL) == SONA_E_CONTEXT) {
  sona_renderer_lost(r);            /* every GPU object of the renderer forgotten */
  /* make the new device (see below for when the old one may go) */
  sona_device_desc dev = my_new_device();
  if (sona_renderer_reset(r, &dev) != SONA_OK) { /* try again later, or another device */ }
}
```

Draws every visible ready avatar, as posed by the last `sona_update`, folding each palette with this view. Each `sona_draw` and `sona_snapshot` is one frame; frames count from 1.

It changes API state and does not restore it:

- GL and GLES: framebuffer bindings, viewport, program, vertex array, array and uniform buffer bindings, texture units 0..5 with their samplers, active texture, blend, depth, cull, front face, colour mask. `GL_FRAMEBUFFER_SRGB` is left off.
- D3D11: every stage's shaders, constant buffers, SRVs and samplers, input layout, topology, rasteriser, blend, depth-stencil, render targets, viewports.
- D3D12: root signature, pipeline state, descriptor heaps, viewports, scissors, render targets, primitive topology.
- Vulkan and Metal: only what is recorded; nothing is submitted. With sprites on (1.1, `sona_lod_set`) a draw that bakes new looks records the bake ahead of its frame and uses two frame indices.
- With multisampling (1.1, on by default), GL and GLES also change the renderbuffer binding.

On Vulkan, D3D12 and Metal it returns `SONA_PENDING` once `frames_in_flight` frames are outstanding without `sona_renderer_frame_done`.

### sona_renderer_frame_index

```c
uint64_t sona_renderer_frame_index(const sona_renderer *r);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_renderer *` | The renderer | required |

**Returns** `uint64_t`.

**Example**:

```c
uint64_t x_got = sona_renderer_frame_index(r);
printf("sona_renderer_frame_index: %lld\n", (long long)x_got);
```

The index of the last frame recorded (0 before the first).

### sona_renderer_frame_done

```c
void sona_renderer_frame_done(sona_renderer *r, uint64_t completed_frame);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `completed_frame` | `uint64_t` | The index of the last frame the host's GPU has finished | - |

**Returns** Nothing.

**Example**:

```c
sona_renderer_frame_done(r, 0);
```

Vulkan, D3D12 and Metal: every frame up to and including `completed_frame` has finished on the GPU. The per-frame rings and the GPU cache's releases wait for it. GL and D3D11 ignore it.

### sona_renderer_lost

```c
void sona_renderer_lost(sona_renderer *r);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |

**Returns** Nothing.

**Example** (also in [Device loss: getting a renderer back](guides/device-loss.md)):

```c
/* the device is gone: the draw said so */
if (sona_draw(r, &view, &target, NULL) == SONA_E_CONTEXT) {
  sona_renderer_lost(r);            /* every GPU object of the renderer forgotten */
  /* make the new device (see below for when the old one may go) */
  sona_device_desc dev = my_new_device();
  if (sona_renderer_reset(r, &dev) != SONA_OK) { /* try again later, or another device */ }
}
```

After a device loss: forget every GPU object. The next `sona_draw` uploads again.

### sona_renderer_reset

```c
sona_result sona_renderer_reset(sona_renderer *r, const sona_device_desc *dev);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `dev` | `const sona_device_desc *` | The options, a [`sona_device_desc`](reference/fields.md#sona_device_desc) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Device loss: getting a renderer back](guides/device-loss.md)):

```c
/* the device is gone: the draw said so */
if (sona_draw(r, &view, &target, NULL) == SONA_E_CONTEXT) {
  sona_renderer_lost(r);            /* every GPU object of the renderer forgotten */
  /* make the new device (see below for when the old one may go) */
  sona_device_desc dev = my_new_device();
  if (sona_renderer_reset(r, &dev) != SONA_OK) { /* try again later, or another device */ }
}
```

Starts the renderer again on a new device of the same backend, after `sona_renderer_lost`. Another backend is `SONA_E_ARGUMENT`.

### sona_snapshot

```c
sona_result sona_snapshot(sona_renderer *r, const sona_view *view, uint32_t width, uint32_t height,
                          const sona_draw_options *opts, uint8_t *rgba_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |
| `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The same picture natively and on the web](guides/parity.md)):

```c
sona_quality q;
sona_draw_options o;
sona_quality_defaults(&q);
q.msaa = 1;                      /* one sample */
q.flags = 0;                     /* no mips */
sona_renderer_set_quality(renderer, &q);
memset(&o, 0, sizeof o);
o.flags = SONA_DRAW_NO_CREDIT;   /* no shadow, no badge; bloom stays on */
sona_camera_preset(avatar, SONA_PRESET_FULL, &view);
sona_snapshot(renderer, &view, 512, 512, &o, rgba);
```

Draws into an internal target, folding palettes with this view, and reads it back as straight RGBA8, row 0 at the top. Blocks until the GPU finishes this one frame. On Vulkan it submits on the device's `VkQueue`, so no other thread may use that queue during the call. The credit is drawn unless `SONA_DRAW_NO_CREDIT`. `rgba_out` holds `width * height * 4` bytes.

### sona_png_encode

```c
sona_result sona_png_encode(sona_ctx *ctx, const uint8_t *rgba, uint32_t width, uint32_t height,
                            uint8_t **out, size_t *out_len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `rgba` | `const uint8_t *` | Straight RGBA8, row 0 at the top, `width * height * 4` bytes | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

PNG bytes of an RGBA8 picture, with the web's three tEXt chunks after IHDR: Software "360sona", Source "https://360sona.com", Comment "Powered by 360sona". Free `*out` with `sona_free`.

### sona_free

```c
void sona_free(sona_ctx *ctx, void *p);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `p` | `void *` | Memory the library handed out | required |

**Returns** Nothing.

**Example** (also in [FBX, Roblox and clips in the export](guides/export-fbx.md)):

```c
sona_export_options o;
uint8_t *fbx = NULL;
size_t fbx_len = 0;
sona_export_defaults(&o);
o.format = SONA_EXPORT_FBX;
o.flags = SONA_EXPORT_CLIPS;          /* the clip it plays, as an animation on the skeleton */
if (sona_export_avatar(avatar, &o, &fbx, &fbx_len, NULL) == SONA_OK) {
  FILE *f = fopen("avatar.fbx", "wb");
  if (f) { fwrite(fbx, 1, fbx_len, f); fclose(f); }
  sona_free(ctx, fbx);
}
```

Frees memory the library handed out (`sona_png_encode`), through the ctx's allocator.

## Item previews

One item worn alone on a grey stand-in body, framed by its slot, for wardrobes and item pickers. The guide, with the framing rules and the measured cost, is [Item previews](guides/item-preview.md).

A preview is an avatar of the ctx with a made-up manifest. It builds through the same queue, shares decoded items and GPU buffers with every other avatar, counts toward `max_avatars` and is freed by `sona_avatar_remove`. `sona_draw` and `sona_snapshot` never draw it, `sona_avatar_set_visible` does nothing to it and `sona_camera_fit_crowd` ignores it. It is a still picture: `sona_avatar_play`, `_crossfade` and `_queue` return `SONA_E_ARGUMENT` for it. Leave pose overrides off a preview; they are not part of the measured frame.

`sona_preview_options`, 40 bytes:

| Field | Meaning | Default |
|---|---|---|
| `gender` | 1 male, 2 female; 0: the body the item was made for (male when either) | 0 |
| `slot` | The category mask to frame by (`0x40` hat, `0x38` costume, ...); 0: from the item | 0 |
| `flags` | `SONA_PREVIEW_PLAY` (1): a prop plays its clip, framed for all of it. `SONA_PREVIEW_COLOURS` (2): wear the item in `colours` | 0 |
| `skin` | 0xAARRGGBB; 0: the stand-in grey `0xff9a9a9a` | 0 |
| `colours[3]` | 0xAARRGGBB primary, secondary, tertiary, with `SONA_PREVIEW_COLOURS` | 0 |
| `priority` | Build order, as `sona_add_options.priority` | 0 |
| `time` | Props: seconds into the clip to hold (or start at); negative: its fullest frame | -1 |
| `margin` | Room around the item: 1 touches the edges; 0 means 1.36, as the web's item renders | 1.36 |

### sona_preview_defaults

```c
void sona_preview_defaults(sona_preview_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_preview_options *` | The [`sona_preview_options`](reference/fields.md#sona_preview_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_preview_options x_preview_options;
memset(&x_preview_options, 0, sizeof x_preview_options);
sona_preview_defaults(&x_preview_options);
```

Fills the defaults above. NULL does nothing.

### sona_item_preview_add

```c
sona_result sona_item_preview_add(sona_ctx *ctx, const char *item_id, const sona_preview_options *opts,
                                  sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `item_id` | `const char *` | An item id as text | required |
| `opts` | `const sona_preview_options *` | The options, a [`sona_preview_options`](reference/fields.md#sona_preview_options) | `NULL`: the defaults |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Queues a preview of one item id (lowercase or uppercase) and returns at once. NULL `opts` takes the defaults. It reaches READY or FAILED through `sona_update` with the usual events. A missing item file does not fail it: it reaches READY without the item, and `sona_item_preview_bounds` says `SONA_E_NOT_FOUND`.

- `SONA_E_ARGUMENT`: NULL `ctx` or `out`, an id that does not parse, an item that is not a worn item, a face item or a head shape (a clip, for example), `gender` above 2, a negative or non-finite `margin`, a non-finite `time`.
- `SONA_E_LIMIT`: the ctx already holds `max_avatars` avatars.
- `SONA_E_MEMORY`.

`*out` is NULL on any error.

### sona_item_preview_bounds

```c
sona_result sona_item_preview_bounds(sona_avatar *a, float lo[3], float hi[3]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `lo` | `float [3]` | Receives the box's lower corner | required |
| `hi` | `float [3]` | Receives the box's upper corner | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
float x_lo[3];
memset(x_lo, 0, sizeof x_lo);
float x_hi2[3];
memset(x_hi2, 0, sizeof x_hi2);
sona_result result = sona_item_preview_bounds(avatar, x_lo, x_hi2);
if (result != SONA_OK) printf("sona_item_preview_bounds: %s\n", sona_result_name(result));
```

The item's box in world metres, over the whole clip for a playing prop. Face and head-shape items give the head; a pair framed from one side (earrings, wristbands) gives the near one; a held prop leaves out a stray part set apart from the rest. Measured once, on the first call to any of `_bounds`, `_view`, `_draw` or `_snapshot` after READY.

`SONA_E_NOT_READY` before READY. `SONA_E_ARGUMENT` for NULL arguments or an avatar that is not a preview. `SONA_E_NOT_FOUND` when no triangle of the item was drawn (its file is missing).

### sona_item_preview_view

```c
sona_result sona_item_preview_view(sona_avatar *a, uint32_t width, uint32_t height, sona_view *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `out` | `sona_view *` | Receives the [`sona_view`](reference/fields.md#sona_view) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
sona_result result = sona_item_preview_view(avatar, 16, 16, &x_view);
if (result != SONA_OK) printf("sona_item_preview_view: %s\n", sona_result_name(result));
```

The framed camera for a `width` x `height` picture: the slot's view preset gives the angle, the item's box the target and the distance. Every field of `*out` is set. Errors as `sona_item_preview_bounds`, except that an item that drew nothing still gets its slot's preset camera and `SONA_OK`.

### sona_item_preview_draw

```c
sona_result sona_item_preview_draw(sona_renderer *r, sona_avatar *a, const sona_view *view,
                                   const sona_target *target, const sona_draw_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `a` | `sona_avatar *` | The avatar | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](reference/fields.md#sona_target) | required |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

`sona_draw` with only this preview in the frame. NULL `view`: `sona_item_preview_view` for the target's size. One frame, with the frames-in-flight and host-state rules of `sona_draw`. The renderer must belong to the preview's ctx (`SONA_E_ARGUMENT` otherwise). It also returns what `sona_draw` returns.

### sona_item_preview_snapshot

```c
sona_result sona_item_preview_snapshot(sona_renderer *r, sona_avatar *a, uint32_t width, uint32_t height,
                                       const sona_draw_options *opts, uint8_t *rgba_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `a` | `sona_avatar *` | The avatar | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |
| `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

`sona_snapshot` of this preview alone, framed for `width` x `height`. Blocks until the GPU finishes and writes `width * height * 4` bytes of straight RGBA8, row 0 at the top. The credit is drawn unless `SONA_DRAW_NO_CREDIT`; a picker usually passes the flag and shows the credit once elsewhere, as the licence still requires.

## Rendering quality

What the web SDK does against white specks on small avatars: multisampling in the main pass (with centroid sampling and a coverage-aware present), mip chains for item textures, and coverage-preserving mips for cut-out colour textures. The guide, with the speck counts, is [Rendering quality](guides/quality.md).

`sona_quality` holds `msaa` and `flags`, 8 bytes. `msaa` is `SONA_MSAA_AUTO` (0: 4 samples on a hardware GPU, 1 on a software rasteriser), or 1 (off), 2, 4 or 8. `flags` are `SONA_QUALITY_MIPS` (1: item textures carry mip chains and are filtered between levels) and `SONA_QUALITY_CUTOUT_MIPS` (2: cut-out colour textures get edge bleed and coverage-preserving mips; only with `SONA_QUALITY_MIPS`).

A renderer starts with `sona_quality_defaults`. A frame over 4096 x 4096 / samples halves its samples until it fits, as the web does.

### sona_quality_defaults

```c
void sona_quality_defaults(sona_quality *q);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `q` | `sona_quality *` | The [`sona_quality`](reference/fields.md#sona_quality) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Rendering quality](guides/quality.md)):

```c
void sona_quality_defaults(sona_quality *q);
```

The web SDK's defaults: `msaa = SONA_MSAA_AUTO`, `flags = SONA_QUALITY_MIPS | SONA_QUALITY_CUTOUT_MIPS`. NULL does nothing.

### sona_renderer_set_quality

```c
sona_result sona_renderer_set_quality(sona_renderer *r, const sona_quality *q);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `q` | `const sona_quality *` | A [`sona_quality`](reference/fields.md#sona_quality) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Rendering quality](guides/quality.md)):

```c
sona_result sona_renderer_set_quality(sona_renderer *r, const sona_quality *q);
```

Sets the quality from the next `sona_draw` or `sona_snapshot`. NULL `q` means the defaults. More samples than the device has are clamped to the most it has. A change of mip flags uploads each avatar's textures again at its next draw. `SONA_E_ARGUMENT` for a NULL renderer, another `msaa` value, or an unknown flag; the renderer keeps its old quality then. `sona_renderer_reset` keeps the quality and works out the sample count again for the new device.

### sona_renderer_quality

```c
sona_result sona_renderer_quality(const sona_renderer *r, sona_quality *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_renderer *` | The renderer | required |
| `out` | `sona_quality *` | Receives the [`sona_quality`](reference/fields.md#sona_quality) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Rendering quality](guides/quality.md)):

```c
sona_result sona_renderer_quality(const sona_renderer *r, sona_quality *out);
```

What the renderer draws with. `out->msaa` is the sample count the backend really uses, asked of it at each call: never `SONA_MSAA_AUTO`, and 1 when the device cannot multisample. When a backend cannot make its multisampled target it logs once and draws one sample from then on, and `out->msaa` is 1 after that. After a frame over the 4096 x 4096 budget it is the halved count that frame used. `out->flags` are the flags as set, with `SONA_QUALITY_CUTOUT_MIPS` cleared when `SONA_QUALITY_MIPS` is not set. `SONA_E_ARGUMENT` when `r` or `out` is NULL.

### sona_renderer_vk_features

```c
sona_result sona_renderer_vk_features(sona_renderer *r, uint32_t features);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `features` | `uint32_t` | `SONA_VK_FEATURE_*` bits the host's device has enabled | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_renderer_vk_features(r, 0);
if (result != SONA_OK) printf("sona_renderer_vk_features: %s\n", sona_result_name(result));
```

Vulkan only: the optional `VkPhysicalDeviceFeatures` the host enabled when it created `sona_device_desc.u.vk.device`, which the backend cannot ask the device for. `SONA_VK_FEATURE_BINDLESS` (1, `shaderSampledImageArrayDynamicIndexing`) puts every texture in one descriptor set, so a pass binds one set and the draws only draw; `SONA_VK_FEATURE_MULTI_DRAW` (2, `multiDrawIndirect` and `drawIndirectFirstInstance`, only with BINDLESS) makes each run of draws one `vkCmdDrawIndexedIndirect`. The picture is the same byte for byte; the CPU time to record a frame drops (the guide has the numbers). From the next frame; 0 goes back to a set per draw. A renderer starts with 0, and again after `sona_renderer_reset`. `SONA_E_UNSUPPORTED` on any other backend or when the physical device lacks a feature (nothing changes), `SONA_E_ARGUMENT` for a NULL renderer, an unknown bit, or MULTI_DRAW without BINDLESS. The guide: [Vulkan](guides/vulkan-features.md).

### sona_tier_defaults

```c
void sona_tier_defaults(sona_tier_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_tier_options *` | The [`sona_tier_options`](reference/fields.md#sona_tier_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Quality tiers](guides/tiers.md)):

```c
void sona_tier_defaults(sona_tier_options *o);
```

`size` set; `target_fps` 60, `avatars` 20.

### sona_tier_apply

```c
sona_result sona_tier_apply(sona_ctx *ctx, sona_renderer *r, const sona_tier_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `r` | `sona_renderer *` | The renderer | required |
| `o` | `const sona_tier_options *` | The options, a [`sona_tier_options`](reference/fields.md#sona_tier_options) | `NULL`: the defaults |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Quality tiers](guides/tiers.md)):

```c
sona_result sona_tier_apply(sona_ctx *ctx, sona_renderer *r, const sona_tier_options *o);
```

`r` NULL: the ctx's side only. o NULL: the defaults.

### sona_tier_detect

```c
sona_result sona_tier_detect(const sona_renderer *r, uint32_t *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_renderer *` | The renderer | required |
| `out` | `uint32_t *` | Receives the values | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Quality tiers](guides/tiers.md)):

```c
sona_result sona_tier_detect(const sona_renderer *r, uint32_t *out);
```

The tier the device behind r suits: `SONA_TIER_LOW` .. `SONA_TIER_HIGH`.

## 2D outputs

Sprite sheets of a clip at N frames in M directions with Aseprite and TexturePacker atlases, outlined stickers, and crisp pixel art with a small palette. Sheets and stickers draw through `sona_snapshot` with the avatar staged alone at the origin, and put it back as it was (placement, clip and its time, pose, events, visibility, crowd step). A clip named in their options is read from the ctx's sources without touching the avatar's clip: `SONA_PENDING` until its file arrives (run `sona_update`, call again). The guide, with every field and the numbers: [2D outputs](guides/sprites2d.md).

Every options struct starts with `size`, set by its `_defaults` call; a struct without it is refused with `SONA_E_ARGUMENT`. `sona_picture` holds `rgba`, `width` and `height`: straight RGBA8, row 0 at the top.

### sona_pixel_defaults

```c
void sona_pixel_defaults(sona_pixel_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_pixel_options *` | The [`sona_pixel_options`](reference/fields.md#sona_pixel_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_pixel_options x_pixel_options;
memset(&x_pixel_options, 0, sizeof x_pixel_options);
x_pixel_options.size = sizeof x_pixel_options;
sona_pixel_defaults(&x_pixel_options);
```

`size` set, `height` 32, `colours` 16, `flags` `SONA_PIXEL_OUTLINE`, `outline` 0 (from the palette), `alpha_cut` 0.5, no palette. NULL does nothing.

### sona_pixel_art

```c
sona_result sona_pixel_art(sona_ctx *ctx, const sona_picture *in, const sona_pixel_options *o, sona_picture *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `in` | `const sona_picture *` | A [`sona_picture`](reference/fields.md#sona_picture) | required |
| `o` | `const sona_pixel_options *` | The options, a [`sona_pixel_options`](reference/fields.md#sona_pixel_options) | required |
| `out` | `sona_picture *` | Receives the [`sona_picture`](reference/fields.md#sona_picture) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_picture x_picture;
memset(&x_picture, 0, sizeof x_picture);
sona_pixel_options x_pixel_options2;
memset(&x_pixel_options2, 0, sizeof x_pixel_options2);
x_pixel_options2.size = sizeof x_pixel_options2;
sona_picture x_picture3;
memset(&x_picture3, 0, sizeof x_picture3);
sona_result result = sona_pixel_art(ctx, &x_picture, &x_pixel_options2, &x_picture3);
if (result != SONA_OK) printf("sona_pixel_art: %s\n", sona_result_name(result));
```

The figure's box of `in` (alpha 8 and up; the whole picture with `SONA_PIXEL_KEEP_FRAME`) scaled with an area filter to exactly `o->height` pixels including the outline, every pixel opaque or clear at `alpha_cut`, colours mapped to `o->palette` or to `o->colours` colours made from the picture, optionally dithered (`SONA_PIXEL_DITHER`) and outlined (`SONA_PIXEL_OUTLINE`, `_OUTLINE_THIN`). `out->rgba` is freed with `sona_free`. `SONA_E_NOT_FOUND` when no pixel reaches alpha 8 or none is opaque enough at that size; `SONA_E_ARGUMENT` for a value out of range or a picture too wide for the height (over 4096 pixels).

### sona_pixel_palette

```c
sona_result sona_pixel_palette(sona_ctx *ctx, const sona_picture *images, uint32_t image_count, uint32_t colours,
                               uint32_t palette[256], uint32_t *count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `images` | `const sona_picture *` | A [`sona_picture`](reference/fields.md#sona_picture) | required |
| `image_count` | `uint32_t` | How many pictures `images` holds | - |
| `colours` | `uint32_t` | How many colours the palette may hold | - |
| `palette` | `uint32_t [256]` | Receives up to 256 colours | required |
| `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

One palette of up to `colours` (2..256) entries over every pixel of alpha 128 and up in the pictures: median cut, then k-means, integer maths. Entries are `0xFFRRGGBB`, darkest first; `*count` may be below `colours` when the pictures hold fewer colours. Pass it as `sona_pixel_options.palette` so frames share colours. `SONA_E_NOT_FOUND` when no pixel counts.

### sona_sticker_defaults

```c
void sona_sticker_defaults(sona_sticker_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_sticker_options *` | The [`sona_sticker_options`](reference/fields.md#sona_sticker_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_sticker_options x_sticker_options;
memset(&x_sticker_options, 0, sizeof x_sticker_options);
x_sticker_options.size = sizeof x_sticker_options;
sona_sticker_defaults(&x_sticker_options);
```

`size` set, `pixels` 512, `time` -1, `framing` `SONA_PRESET_FULL`, `outline_px` 10, `outline` `0xffffffff`, `shadow` `0x59000000` (off while `shadow_px` is 0), `padding` 8. NULL does nothing.

### sona_sticker

```c
sona_result sona_sticker(sona_renderer *r, sona_avatar *a, const sona_sticker_options *o, sona_picture *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_sticker_options *` | The options, a [`sona_sticker_options`](reference/fields.md#sona_sticker_options) | required |
| `out` | `sona_picture *` | Receives the [`sona_picture`](reference/fields.md#sona_picture) | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_sticker_options x_sticker_options;
memset(&x_sticker_options, 0, sizeof x_sticker_options);
x_sticker_options.size = sizeof x_sticker_options;
sona_picture x_picture2;
memset(&x_picture2, 0, sizeof x_picture2);
sona_result result = sona_sticker(r, avatar, &x_sticker_options, &x_picture2);
if (result != SONA_OK) printf("sona_sticker: %s\n", sona_result_name(result));
```

A transparent cut-out of the avatar turned `turn_deg` from facing the camera, at `time` seconds into `clip` (negative: its middle; NULL clip: the pose it has now), framed whole (`SONA_PRESET_FULL`) or by the console's `UPPER`, `BUST` and `FACE` framings, drawn at twice the size and brought down so its longer side is `pixels`, outline included; then the outline, the drop shadow, `padding`, and with `SONA_STICKER_SQUARE` a square canvas. The credit badge is stamped bottom right unless `draw_flags` has `SONA_DRAW_NO_CREDIT`. `out->rgba` is freed with `sona_free`. `SONA_E_NOT_READY` before READY, `SONA_E_ARGUMENT` for an item preview, a renderer of another ctx or an option out of range, `SONA_E_NOT_FOUND` when the avatar drew nothing or the clip's file cannot be read, `SONA_PENDING` while the clip loads.

### sona_sheet_defaults

```c
void sona_sheet_defaults(sona_sheet_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_sheet_options *` | The [`sona_sheet_options`](reference/fields.md#sona_sheet_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_sheet_options x_sheet_options;
memset(&x_sheet_options, 0, sizeof x_sheet_options);
x_sheet_options.size = sizeof x_sheet_options;
sona_sheet_defaults(&x_sheet_options);
```

`size` set, 8 frames, 8 directions, `px_per_metre` 64, `padding` 2, `max_page` 4096, `draw_flags` `SONA_DRAW_NO_BLOOM`; every other field 0 (the whole clip, facing the camera first, side on, orthographic, packed and trimmed). NULL does nothing.

### sona_sheet_render

```c
sona_result sona_sheet_render(sona_renderer *r, sona_avatar *a, const sona_sheet_options *o, sona_sheet **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_sheet_options *` | The options, a [`sona_sheet_options`](reference/fields.md#sona_sheet_options) | required |
| `out` | `sona_sheet **` | Receives the new sprite sheet | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

Renders `frames` x `directions` pictures of the clip under one fixed camera (looking down by `pitch_deg`, orthographic unless `fov_deg`) at `px_per_metre`, the hips held in place unless `SONA_SHEET_ROOT_MOTION`. Frames are trimmed (`SONA_SHEET_NO_TRIM`: whole cells), identical ones share a rectangle (`SONA_SHEET_NO_DEDUP`), and they are packed on pages of at most `max_page` (`SONA_SHEET_POW2`: power-of-two sides), or with `SONA_SHEET_GRID` laid out a row per direction. With `o->pixel` the frames are pixel art with one palette. The sheet is the caller's until `sona_sheet_free`, which must come before `sona_close`. Errors as `sona_sticker`, plus `SONA_E_LIMIT` when a frame does not fit `max_page`, a cell needs a render over 8192 pixels, or the cells would pass the 1 GB limit. `*out` is NULL on any error.

### sona_sheet_free

```c
void sona_sheet_free(sona_sheet *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_sheet *` | The sprite sheet | required |

**Returns** Nothing.

Frees the sheet, its pages and frames. NULL does nothing.

### sona_sheet_page_count

```c
uint32_t sona_sheet_page_count(const sona_sheet *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_sheet *` | The sprite sheet | required |

**Returns** `uint32_t`.

The number of pages; 0 for NULL.

### sona_sheet_page

```c
sona_result sona_sheet_page(const sona_sheet *s, uint32_t page, sona_picture *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_sheet *` | The sprite sheet | required |
| `page` | `uint32_t` | An atlas page, from 0 | - |
| `out` | `sona_picture *` | Receives the [`sona_picture`](reference/fields.md#sona_picture) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

One page's pixels, owned by the sheet: do not free them; valid until `sona_sheet_free`. `SONA_E_ARGUMENT` past the last page.

### sona_sheet_frame_count

```c
uint32_t sona_sheet_frame_count(const sona_sheet *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_sheet *` | The sprite sheet | required |

**Returns** `uint32_t`.

`frames * directions`; 0 for NULL.

### sona_sheet_frame_get

```c
sona_result sona_sheet_frame_get(const sona_sheet *s, uint32_t index, sona_sheet_frame *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_sheet *` | The sprite sheet | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_sheet_frame *` | Receives the [`sona_sheet_frame`](reference/fields.md#sona_sheet_frame) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

One frame (index = direction * frames + frame): its page and rectangle, where the rectangle sits in the full cell (`trim_x`, `trim_y`), the cell's size, the pivot (the avatar's feet) in the cell, its direction, facing, time, duration and `alias` (the first frame with the same rectangle). `SONA_E_ARGUMENT` past the last frame.

### sona_sheet_atlas

```c
sona_result sona_sheet_atlas(const sona_sheet *s, uint32_t format, uint32_t page, const char *image, char **json,
                             size_t *len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_sheet *` | The sprite sheet | required |
| `format` | `uint32_t` | The file format to write | - |
| `page` | `uint32_t` | An atlas page, from 0 | - |
| `image` | `const char *` | The picture's file name, as the atlas names it | required |
| `json` | `char **` | Receives the atlas as JSON text; free it with `sona_free` | required |
| `len` | `size_t *` | Receives how many bytes were written | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

The atlas of one page as NUL-terminated JSON, freed with `sona_free` on the sheet's ctx. `SONA_ATLAS_ASEPRITE`: Aseprite's array form, a frame tag per direction and a `pivot` slice. `SONA_ATLAS_TEXTUREPACKER`: TexturePacker's hash form with a pivot per frame and an animation per direction; with `page` `SONA_ATLAS_ALL_PAGES`, every page in one multi-atlas file. Frames are named `<name>_<direction>_<nnn>`. `image` is the page file's name for `meta.image` (`{n}` becomes the page number; NULL: `sheet-<n>.png`). `SONA_E_ARGUMENT` for an unknown format, a page past the last, or ALL_PAGES with Aseprite.

## Camera helpers

Pure maths, as the web SDK's camera. Presets: `SONA_PRESET_FULL`, `UPPER`, `BUST`, `FACE`.

### sona_camera_preset

```c
sona_result sona_camera_preset(const sona_avatar *a, sona_preset p, sona_view *view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `p` | `sona_preset` | The framing: full, upper, bust or face | - |
| `view` | `sona_view *` | Receives the camera, a [`sona_view`](reference/fields.md#sona_view) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The same picture natively and on the web](guides/parity.md)):

```c
sona_quality q;
sona_draw_options o;
sona_quality_defaults(&q);
q.msaa = 1;                      /* one sample */
q.flags = 0;                     /* no mips */
sona_renderer_set_quality(renderer, &q);
memset(&o, 0, sizeof o);
o.flags = SONA_DRAW_NO_CREDIT;   /* no shadow, no badge; bloom stays on */
sona_camera_preset(avatar, SONA_PRESET_FULL, &view);
sona_snapshot(renderer, &view, 512, 512, &o, rgba);
```

Sets `view->eye` and `view->target` to one of the console's framings on one ready avatar.

### sona_camera_fit_crowd

```c
void sona_camera_fit_crowd(const sona_ctx *ctx, sona_view *view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `view` | `sona_view *` | Receives the camera, a [`sona_view`](reference/fields.md#sona_view) | required |

**Returns** Nothing.

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
sona_camera_fit_crowd(ctx, &x_view);
```

Fits every ready avatar in view (the web's preset `"crowd"`). Keeps fov, near, far, width and height.

### sona_camera_orbit

```c
void sona_camera_orbit(sona_view *view, const double target[3], double yaw_deg, double pitch_deg, double distance);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `view` | `sona_view *` | Receives the camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `target` | `const double [3]` | The point the eye looks at | required |
| `yaw_deg` | `double` | Yaw in degrees | - |
| `pitch_deg` | `double` | Pitch in degrees, up positive | - |
| `distance` | `double` | How far the eye is from the target, metres | - |

**Returns** Nothing.

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
double x_target2[3];
memset(x_target2, 0, sizeof x_target2);
sona_camera_orbit(&x_view, x_target2, 30.0f, 30.0f, 0);
```

Places the eye on an orbit around `target`. Hosts wire their own input to it.

### sona_view_matrices

```c
void sona_view_matrices(const sona_view *view, float view_m[16], float proj_m[16]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `view_m` | `float [16]` | Receives the view matrix, row-major | required |
| `proj_m` | `float [16]` | Receives the projection matrix, row-major | required |

**Returns** Nothing.

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
float x_view_m2[16];
memset(x_view_m2, 0, sizeof x_view_m2);
float x_proj_m3[16];
memset(x_proj_m3, 0, sizeof x_proj_m3);
sona_view_matrices(&x_view, x_view_m2, x_proj_m3);
```

Row-vector view and projection matrices (D3D depth 0..1), for hosts that draw themselves. Double maths, one float store per element, as the web.

## Manifests

Pure functions; no ctx needed. A manifest is the 1000-byte AvatarDescription. `sona_guid` is 16 bytes in wire (big-endian) order.

`sona_manifest` is the parsed form: `version` (0), `weight` and `height` (raw, not clamped), `chin`, `nose`, `ears`, `face[6]` (mouth, eyes, eyebrows, facial hair, eye shadow, facial feature; each a GUID and four words), `colours[9]` (skin, hair, mouth, eyes, eyebrows, eye shadow, facial hair, facial feature, facial feature 2), `figure_a` (the body, and the gender source), `figure_b` (the head), `worn[13]` (all 13 slots; zero GUIDs are empty), `required[4]` (the last-worn cache: shoes, trousers, shirt, hair), `blob5[5]`, `xuid`, `padding[91]`, and the derived `gender` (1 male, 2 female, 0 unknown) and `valid`.

A `sona_asset_ref` holds `id`, `mask` (the u16 type mask after the GUID), `pad` (kept verbatim) and `colours[3]` (primary, secondary, tertiary, 0xAARRGGBB).

`sona_route` says where an item goes: `SONA_ROUTE_REJECTED`, `WORN`, `BARE` or `FACE`.

The edit verbs follow the editor's rules. Each changes `*m` in place, or returns `SONA_E_ARGUMENT` with `m` unchanged where the editor refuses. Edit flags: `SONA_EDIT_NO_REQUIRED`, `SONA_EDIT_STACK_PROPS`, `SONA_EDIT_NO_DRESS`.

### sona_manifest_parse

```c
sona_result sona_manifest_parse(const uint8_t bytes[SONA_MANIFEST_BYTES], sona_manifest *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `bytes` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required |
| `out` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Untrusted files, long sessions and speed](guides/hardening.md)):

```c
sona_manifest m;
if (sona_manifest_parse(manifest, &m) != SONA_OK)   /* any 1,000 bytes from a player */
  puts("not an avatar");                            /* SONA_E_MANIFEST */
else
  sona_avatar_add(ctx, manifest, NULL, &avatar);    /* its items load through your sources */
```

Reads 1000 bytes into a `sona_manifest`.

### sona_manifest_write

```c
sona_result sona_manifest_write(const sona_manifest *m, uint8_t out[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const sona_manifest *` | A [`sona_manifest`](reference/fields.md#sona_manifest) | required |
| `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Manifests](concepts/manifests.md)):

```c
sona_manifest m;
sona_guid tee;
const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff };   /* 0xAARRGGBB */
if (sona_manifest_parse(manifest, &m) == SONA_OK &&
    sona_guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0", &tee) == SONA_OK &&
    sona_manifest_wear(&m, &tee, colours, 0) == SONA_OK &&
    sona_manifest_write(&m, manifest) == SONA_OK)
  sona_avatar_add(ctx, manifest, NULL, &avatar);
```

Writes it back. Byte-exact: `write(parse(x)) == x` for every manifest.

### sona_slot_of

```c
sona_route sona_slot_of(const sona_guid *id, uint32_t *mask_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `id` | `const sona_guid *` | An item id | required |
| `mask_out` | `uint32_t *` | Receives the item's slot mask; may be NULL | `NULL`: not written |

**Returns** `sona_route`.

Where an item id goes, and its slot mask in `*mask_out`.

### sona_guid_parse

```c
sona_result sona_guid_parse(const char *text, sona_guid *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `text` | `const char *` | An id as text | required |
| `out` | `sona_guid *` | Receives the [`sona_guid`](reference/fields.md#sona_guid) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Manifests](concepts/manifests.md)):

```c
sona_manifest m;
sona_guid tee;
const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff };   /* 0xAARRGGBB */
if (sona_manifest_parse(manifest, &m) == SONA_OK &&
    sona_guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0", &tee) == SONA_OK &&
    sona_manifest_wear(&m, &tee, colours, 0) == SONA_OK &&
    sona_manifest_write(&m, manifest) == SONA_OK)
  sona_avatar_add(ctx, manifest, NULL, &avatar);
```

Parses the 36-character text form.

### sona_guid_format

```c
void sona_guid_format(const sona_guid *id, char out[SONA_ID_CHARS]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `id` | `const sona_guid *` | An item id | required |
| `out` | `char [SONA_ID_CHARS]` | Receives the id as text with its NUL | required |

**Returns** Nothing.

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
char x_out2[SONA_ID_CHARS];
memset(x_out2, 0, sizeof x_out2);
sona_guid_format(&x_guid, x_out2);
```

Writes the lowercase 36-character form and a NUL.

### sona_base64_decode

```c
sona_result sona_base64_decode(const char *text, uint8_t *out, size_t cap, size_t *len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `text` | `const char *` | base64 text | required |
| `out` | `uint8_t *` | Receives the bytes | required |
| `cap` | `size_t` | How many bytes `out` holds | - |
| `len` | `size_t *` | Receives how many bytes were written | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Decodes base64 into at most `cap` bytes, and the length in `*len`.

### sona_manifest_wear

```c
sona_result sona_manifest_wear(sona_manifest *m, const sona_guid *item, const uint32_t colours[3], uint32_t flags);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |
| `item` | `const sona_guid *` | A [`sona_guid`](reference/fields.md#sona_guid) | required |
| `colours` | `const uint32_t [3]` | The item's three colours, 0xAARRGGBB; NULL: its own | `NULL`: its own |
| `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Manifests](concepts/manifests.md)):

```c
sona_manifest m;
sona_guid tee;
const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff };   /* 0xAARRGGBB */
if (sona_manifest_parse(manifest, &m) == SONA_OK &&
    sona_guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0", &tee) == SONA_OK &&
    sona_manifest_wear(&m, &tee, colours, 0) == SONA_OK &&
    sona_manifest_write(&m, manifest) == SONA_OK)
  sona_avatar_add(ctx, manifest, NULL, &avatar);
```

Puts an item on, with its three colours.

### sona_manifest_unwear

```c
sona_result sona_manifest_unwear(sona_manifest *m, uint32_t slot_mask, uint32_t flags);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |
| `slot_mask` | `uint32_t` | The slots to take off | - |
| `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_manifest x_manifest;
memset(&x_manifest, 0, sizeof x_manifest);
sona_result result = sona_manifest_unwear(&x_manifest, 0, 0);
if (result != SONA_OK) printf("sona_manifest_unwear: %s\n", sona_result_name(result));
```

Takes off what is in the slots of `slot_mask`.

### sona_manifest_undress_all

```c
sona_result sona_manifest_undress_all(sona_manifest *m);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_manifest x_manifest;
memset(&x_manifest, 0, sizeof x_manifest);
sona_result result = sona_manifest_undress_all(&x_manifest);
if (result != SONA_OK) printf("sona_manifest_undress_all: %s\n", sona_result_name(result));
```

Takes everything off.

### sona_manifest_set_colour

```c
sona_result sona_manifest_set_colour(sona_manifest *m, uint32_t colour_slot, uint32_t argb);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |
| `colour_slot` | `uint32_t` | Which of the manifest's colours to set | - |
| `argb` | `uint32_t` | The colour, 0xAARRGGBB | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_manifest x_manifest;
memset(&x_manifest, 0, sizeof x_manifest);
sona_result result = sona_manifest_set_colour(&x_manifest, 0, 0);
if (result != SONA_OK) printf("sona_manifest_set_colour: %s\n", sona_result_name(result));
```

Sets one of the nine body colours, by its index in `colours`.

### sona_manifest_set_gender

```c
sona_result sona_manifest_set_gender(sona_manifest *m, uint32_t gender, uint32_t flags);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |
| `gender` | `uint32_t` | 1 male, 2 female | - |
| `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_manifest x_manifest;
memset(&x_manifest, 0, sizeof x_manifest);
sona_result result = sona_manifest_set_gender(&x_manifest, 0, 0);
if (result != SONA_OK) printf("sona_manifest_set_gender: %s\n", sona_result_name(result));
```

Sets the gender: 1 male, 2 female.

### sona_manifest_set_shape

```c
sona_result sona_manifest_set_shape(sona_manifest *m, float weight, float height);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |
| `weight` | `float` | The body's weight, as the manifest stores it | - |
| `height` | `float` | The body's height, as the manifest stores it | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_manifest x_manifest;
memset(&x_manifest, 0, sizeof x_manifest);
sona_result result = sona_manifest_set_shape(&x_manifest, 0.5f, 16);
if (result != SONA_OK) printf("sona_manifest_set_shape: %s\n", sona_result_name(result));
```

Sets the weight and height.

### sona_manifest_ready_for_xbox

```c
int sona_manifest_ready_for_xbox(const sona_manifest *m);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const sona_manifest *` | A [`sona_manifest`](reference/fields.md#sona_manifest) | required |

**Returns** `int`.

**Example**:

```c
sona_manifest x_manifest;
memset(&x_manifest, 0, sizeof x_manifest);
int x_got = sona_manifest_ready_for_xbox(&x_manifest);
printf("sona_manifest_ready_for_xbox: %lld\n", (long long)x_got);
```

1 when the body (and so the gender) is known and the editor's Xbox clean-up would change nothing: the manifest can be saved to Xbox as it is. 0 otherwise.

## Credit

`sona_draw` and `sona_snapshot` draw a small "Powered by 360sona" badge, its opacity set to 75%, unless `SONA_DRAW_NO_CREDIT`; an app that turns it off credits 360sona itself, in its credits, about page, footer or store page.

`sona_credit` is `{text ("Powered by 360sona"), url ("https://360sona.com"), rgba (the badge in the SDK's pixel font at the given scale, at full strength: engines show it at 75%, as `sona_draw` does), width, height}`.

### sona_credit_get

```c
sona_result sona_credit_get(sona_ctx *ctx, uint32_t scale, sona_credit *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `scale` | `uint32_t` | The badge's scale: 1, 2 or 3 | - |
| `out` | `sona_credit *` | Receives the [`sona_credit`](reference/fields.md#sona_credit) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The credit](concepts/credit.md)):

```c
sona_credit credit;
if (sona_credit_get(ctx, 2, &credit) == SONA_OK) {
  /* credit.rgba is credit.width x credit.height RGBA pixels: show them at 75%, linked to credit.url */
}
```

The credit text, link and badge. `scale` is 1 for the badge; `max(1, round(min(w, h) / 400))` for snapshots, as the web. Engine plugins draw this badge in a corner.

## The offline catalogue

The full contracts, the structs, the flags and the file format are in [The offline catalogue](guides/catalogue.md). The catalogue is a handle of its own: it needs no ctx after loading and any thread may read it.

### sona_catalogue_load

```c
sona_result sona_catalogue_load(sona_ctx *ctx, const char *path, sona_catalogue **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `path` | `const char *` | A file path | required |
| `out` | `sona_catalogue **` | Receives the new catalogue | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
sona_result sona_catalogue_load(sona_ctx *ctx, const char *path, sona_catalogue **out);
```

Loads `sona-catalogue.bin` from a UTF-8 path and checks every byte. `ctx` may be `NULL`. `SONA_E_IO`, `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED`.

### sona_catalogue_load_memory

```c
sona_result sona_catalogue_load_memory(sona_ctx *ctx, const void *bytes, size_t len, sona_catalogue **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `bytes` | `const void *` | The file's bytes | required |
| `len` | `size_t` | How many bytes there are | - |
| `out` | `sona_catalogue **` | Receives the new catalogue | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
sona_result sona_catalogue_load_memory(sona_ctx *ctx, const void *bytes, size_t len, sona_catalogue **out);
```

The same from bytes in memory. The catalogue keeps its own copy.

### sona_catalogue_free

```c
void sona_catalogue_free(sona_catalogue *cat);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `sona_catalogue *` | The catalogue | required |

**Returns** Nothing.

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
void sona_catalogue_free(sona_catalogue *cat);
```

Frees it and every string it handed out. `NULL` is fine.

### sona_catalogue_count

```c
uint32_t sona_catalogue_count(const sona_catalogue *cat);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |

**Returns** `uint32_t`.

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
uint32_t sona_catalogue_count(const sona_catalogue *cat);
```

Items, sorted by id. 0 for `NULL`.

### sona_catalogue_get

```c
sona_result sona_catalogue_get(const sona_catalogue *cat, uint32_t index, sona_item_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_item_info *` | Receives the [`sona_item_info`](reference/fields.md#sona_item_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
sona_result sona_catalogue_get(const sona_catalogue *cat, uint32_t index, sona_item_info *out);
```

One item. Its strings live as long as the catalogue.

### sona_catalogue_find

```c
int32_t sona_catalogue_find(const sona_catalogue *cat, const char *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `id` | `const char *` | An item id: 32 hex digits, with or without dashes, braces or spaces | required |

**Returns** `int32_t`.

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
int32_t sona_catalogue_find(const sona_catalogue *cat, const char *id);
```

The index of an id in any spelling, or -1. A binary search.

### sona_catalogue_find_guid

```c
int32_t sona_catalogue_find_guid(const sona_catalogue *cat, const sona_guid *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `id` | `const sona_guid *` | An item id | required |

**Returns** `int32_t`.

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
int32_t sona_catalogue_find_guid(const sona_catalogue *cat, const sona_guid *id);
```

The same from a parsed GUID.

### sona_catalogue_search

```c
sona_result sona_catalogue_search(const sona_catalogue *cat, const sona_catalogue_query *q, uint32_t *out_indexes, uint32_t max, uint32_t *total);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `q` | `const sona_catalogue_query *` | A [`sona_catalogue_query`](reference/fields.md#sona_catalogue_query) | required |
| `out_indexes` | `uint32_t *` | Receives catalogue indexes, up to `max` | required |
| `max` | `uint32_t` | How many entries `out` holds | - |
| `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
sona_result sona_catalogue_search(const sona_catalogue *cat, const sona_catalogue_query *q,
                                  uint32_t *out_indexes, uint32_t max, uint32_t *total);
```

Indexes matching a query (words, game, slots, section, body, flags, paging), in id order.

### sona_catalogue_game_count

```c
uint32_t sona_catalogue_game_count(const sona_catalogue *cat);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |

**Returns** `uint32_t`.

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
uint32_t sona_catalogue_game_count(const sona_catalogue *cat);
sona_result sona_catalogue_game(const sona_catalogue *cat, uint32_t index, const char **name, uint32_t *items);
```

How many distinct games items come from.

### sona_catalogue_game

```c
sona_result sona_catalogue_game(const sona_catalogue *cat, uint32_t index, const char **name, uint32_t *items);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `name` | `const char **` | Receives the name; lives as long as the catalogue | required |
| `items` | `uint32_t *` | Receives how many items the game has; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
uint32_t sona_catalogue_game_count(const sona_catalogue *cat);
sona_result sona_catalogue_game(const sona_catalogue *cat, uint32_t index, const char **name, uint32_t *items);
```

One game, sorted by name, and its item count.

### sona_catalogue_generated

```c
const char *sona_catalogue_generated(const sona_catalogue *cat);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |

**Returns** `const char *`.

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
const char *sona_catalogue_generated(const sona_catalogue *cat);
```

When its data was made, ISO 8601.

### sona_catalogue_section_name

```c
const char *sona_catalogue_section_name(uint32_t section);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `section` | `uint32_t` | A `SONA_SECTION_*` | - |

**Returns** `const char *`.

**Example** (also in [The offline catalogue](guides/catalogue.md)):

```c
const char *sona_catalogue_section_name(uint32_t section);
```

A `sona_section` as the editor spells it; `NULL` past the last.

### sona_catalogue_language_count

```c
uint32_t sona_catalogue_language_count(const sona_catalogue *cat);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |

**Returns** `uint32_t`.

**Example** (also in [Item names in other languages](guides/catalogue-languages.md)):

```c
uint32_t n = sona_catalogue_language_count(cat);          /* "en" among them */
const char *tag = sona_catalogue_language(cat, i);        /* "cs", "da", "de", "el", "en", "en-GB", "es", ... */
const char *name;
if (sona_catalogue_item_name(cat, index, "pt-PT", &name) == SONA_OK) show(name);
else show(info.name);                                     /* SONA_E_NOT_FOUND: that market used the English name */
```

How many languages the catalogue carries item names in. Each is a BCP 47 tag ("de", "ja", "pt-BR"), sorted; "en" is always one.

### sona_catalogue_language

```c
const char * sona_catalogue_language(const sona_catalogue *cat, uint32_t index);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `index` | `uint32_t` | Which one, from 0 | - |

**Returns** `const char *`.

**Example** (also in [Item names in other languages](guides/catalogue-languages.md)):

```c
uint32_t n = sona_catalogue_language_count(cat);          /* "en" among them */
const char *tag = sona_catalogue_language(cat, i);        /* "cs", "da", "de", "el", "en", "en-GB", "es", ... */
const char *name;
if (sona_catalogue_item_name(cat, index, "pt-PT", &name) == SONA_OK) show(name);
else show(info.name);                                     /* SONA_E_NOT_FOUND: that market used the English name */
```

The language tag at `index` (see `sona_catalogue_language_count`); NULL past the last.

### sona_catalogue_item_name

```c
sona_result sona_catalogue_item_name(const sona_catalogue *cat, uint32_t index, const char *lang, const char **name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `lang` | `const char *` | A language tag, such as `"fr"` or `"pt-BR"` | required |
| `name` | `const char **` | Receives the name; lives as long as the catalogue | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Item names in other languages](guides/catalogue-languages.md)):

```c
uint32_t n = sona_catalogue_language_count(cat);          /* "en" among them */
const char *tag = sona_catalogue_language(cat, i);        /* "cs", "da", "de", "el", "en", "en-GB", "es", ... */
const char *name;
if (sona_catalogue_item_name(cat, index, "pt-PT", &name) == SONA_OK) show(name);
else show(info.name);                                     /* SONA_E_NOT_FOUND: that market used the English name */
```

An item's name in lang (an exact tag first, then the market the Xbox 360 marketplace served it from, then its language: [catalogue languages guide](guides/catalogue-languages.md)); it lives as long as the catalogue. `SONA_E_NOT_FOUND` when the item has no name in that language: show `sona_item_info`.name.

### sona_item_colourways

```c
sona_result sona_item_colourways(sona_ctx *ctx, const char *item_id, uint32_t (*out)[3], uint32_t cap, uint32_t *count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `item_id` | `const char *` | An item id as text | required |
| `out` | `uint32_t (*out)[3]` | Receives three colours per colourway | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |
| `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

An item's own colourways (its colour table): up to cap sets of primary, secondary and tertiary colours (0xFFRRGGBB) into out, and how many it has in *count (0 for an item without a table). Wearing the item with one set's three colours in its `sona_asset_ref`.colours (`sona_manifest_wear`) wears that colourway; colours that match no set wear the first. The item is read through the ctx's sources: `SONA_PENDING` until it has loaded (call again after `sona_update`), `SONA_E_NOT_FOUND` when no source has it, `SONA_E_ARGUMENT` for a bad id.

## The stock clip library and the procedural idle

Section 3.22 of the header. The guide, with the full clip table, the tags and how every clip was named, is
[Clips](guides/clips.md). The library calls are pure (no ctx) and safe from any thread. Structs
carry a `size` the caller sets to `sizeof`; a call fills at most that many bytes.

### sona_stock_clip_count

```c
uint32_t sona_stock_clip_count(void);
```

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_stock_clip_count();
printf("sona_stock_clip_count: %lld\n", (long long)x_got);
```

The clips in the library: 100 (`SONA_STOCK_CLIP_COUNT`).

### sona_stock_clip_at

```c
sona_result sona_stock_clip_at(uint32_t index, sona_stock_clip *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_stock_clip *` | Receives the [`sona_stock_clip`](reference/fields.md#sona_stock_clip) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_stock_clip x_stock_clip;
memset(&x_stock_clip, 0, sizeof x_stock_clip);
x_stock_clip.size = sizeof x_stock_clip;
sona_result result = sona_stock_clip_at(0, &x_stock_clip);
if (result != SONA_OK) printf("sona_stock_clip_at: %s\n", sona_result_name(result));
```

The clip at index, in id order. `SONA_E_NOT_FOUND` past the end, `SONA_E_ARGUMENT` for a `NULL` out or a size below 8.

### sona_stock_clip_get

```c
sona_result sona_stock_clip_get(uint32_t id, sona_stock_clip *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `id` | `uint32_t` | A stock clip id, from 1 | - |
| `out` | `sona_stock_clip *` | Receives the [`sona_stock_clip`](reference/fields.md#sona_stock_clip) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_stock_clip x_stock_clip;
memset(&x_stock_clip, 0, sizeof x_stock_clip);
x_stock_clip.size = sizeof x_stock_clip;
sona_result result = sona_stock_clip_get(0, &x_stock_clip);
if (result != SONA_OK) printf("sona_stock_clip_get: %s\n", sona_result_name(result));
```

The clip with this id (`SONA_STOCK_*`: bytes 4 to 7 of its asset id). `SONA_E_NOT_FOUND` for an unknown id.

### sona_stock_clip_find

```c
uint32_t sona_stock_clip_find(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | The name to look up | required |

**Returns** `uint32_t`.

**Example** (also in [Clips: the stock clip library and the procedural idle](guides/clips.md)):

```c
/* every idle this body can play, the procedural idle on top */
uint32_t ids[64], n = sona_stock_clips_tagged(SONA_CLIP_TAG_IDLE, SONA_CLIP_TAG_COPY, body, ids, 64);
sona_idle_options idle;
sona_idle_defaults(&idle);                  /* blinks, glances, weight shifts and breathing, seed from the ctx */
sona_avatar_idle(avatar, &idle);

sona_avatar_play_stock(avatar, SONA_STOCK_WAVE, NULL, 0.3f);           /* crossfade into a wave */
sona_avatar_play_stock(avatar, sona_stock_clip_find("laugh"), NULL, 0); /* NULL opts: loops when the clip loops */
```

A library name (`"wave"`), an asset id in either case or a `sona_clip_get` key (`"GenericWave"`); 0 when none.

### sona_stock_clip_for_body

```c
uint32_t sona_stock_clip_for_body(uint32_t id, uint32_t body);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `id` | `uint32_t` | A stock clip id | - |
| `body` | `uint32_t` | The body a clip or item is for: 1 male, 2 female | - |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_stock_clip_for_body(0, 0);
printf("sona_stock_clip_for_body: %lld\n", (long long)x_got);
```

The clip of id's family made for body (1 male, 2 female): its own variant, else one for both, else id itself.

### sona_stock_clips_tagged

```c
uint32_t sona_stock_clips_tagged(uint32_t all, uint32_t none, uint32_t body, uint32_t *ids, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `all` | `uint32_t` | Tag bits a clip must all have | - |
| `none` | `uint32_t` | Tag bits a clip must not have | - |
| `body` | `uint32_t` | The body the clips must suit: 1 male, 2 female; 0: any | `0`: any |
| `ids` | `uint32_t *` | Receives the ids; may be NULL to count | `NULL`: not written |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example** (also in [Clips: the stock clip library and the procedural idle](guides/clips.md)):

```c
/* every idle this body can play, the procedural idle on top */
uint32_t ids[64], n = sona_stock_clips_tagged(SONA_CLIP_TAG_IDLE, SONA_CLIP_TAG_COPY, body, ids, 64);
sona_idle_options idle;
sona_idle_defaults(&idle);                  /* blinks, glances, weight shifts and breathing, seed from the ctx */
sona_avatar_idle(avatar, &idle);

sona_avatar_play_stock(avatar, SONA_STOCK_WAVE, NULL, 0.3f);           /* crossfade into a wave */
sona_avatar_play_stock(avatar, sona_stock_clip_find("laugh"), NULL, 0); /* NULL opts: loops when the clip loops */
```

Clips with every `SONA_CLIP_TAG_*` bit of all and none of none that suit body (0 any; 1 or 2: that body's clips and
the clips for both), in id order. Returns how many match and writes up to cap ids; ids may be `NULL` with cap 0.

### sona_clip_tag_name

```c
const char *sona_clip_tag_name(uint32_t tag);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `tag` | `uint32_t` | A tag's bit | - |

**Returns** `const char *`.

**Example**:

```c
const char * x_got = sona_clip_tag_name(0);
printf("sona_clip_tag_name: %s\n", x_got ? "a value" : "none");
```

The name of one tag bit (`"idle"`, `"travel"`, ...); `NULL` for 0, several bits or an unknown bit.

### sona_clip_tag_find

```c
uint32_t sona_clip_tag_find(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | The name to look up | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_clip_tag_find("speed");
printf("sona_clip_tag_find: %lld\n", (long long)x_got);
```

The bit for a tag name; 0 when none.

### sona_avatar_play_stock

```c
sona_result sona_avatar_play_stock(sona_avatar *a, uint32_t id, const sona_play_options *opts, float fade_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `id` | `uint32_t` | A stock clip id | - |
| `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](reference/fields.md#sona_play_options) | required |
| `fade_seconds` | `float` | Seconds to blend over | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_placement to = { { 2.0f, 0.0f, -3.0f }, 90.0f, 1.0f };   /* position, turn, scale */
sona_avatar_play_stock(avatar, SONA_STOCK_WALK_FORWARD, NULL, 0.25f);
sona_avatar_move(avatar, &to, 2.5f);
/* 2.5 s later, when it has arrived: */
sona_avatar_crossfade(avatar, "idle", NULL, 0.3f);
```

Plays id's variant for the avatar's body (`sona_stock_clip_for_body` with the manifest's gender) through
`sona_avatar_play`, or `sona_avatar_crossfade` when fade_seconds is above 0. `NULL` opts: loop when the clip has
`SONA_CLIP_TAG_LOOP`, speed 1, from 0. `SONA_E_NOT_FOUND` for an unknown id; otherwise what the play call returns.

### sona_idle_defaults

```c
void sona_idle_defaults(sona_idle_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_idle_options *` | The [`sona_idle_options`](reference/fields.md#sona_idle_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Clips: the stock clip library and the procedural idle](guides/clips.md)):

```c
sona_idle_options o;
sona_idle_defaults(&o);        /* parts SONA_IDLE_ALL, seed 0, amount 1, face_px 240 */
o.seed = 42;                   /* 0: from the ctx seed and the avatar id */
sona_avatar_idle(avatar, &o);  /* NULL turns it off */
```

`size` set, `parts` `SONA_IDLE_ALL`, `seed` 0, `amount` 1, `face_px` 240.

### sona_avatar_idle

```c
sona_result sona_avatar_idle(sona_avatar *a, const sona_idle_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_idle_options *` | The options, a [`sona_idle_options`](reference/fields.md#sona_idle_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Clips: the stock clip library and the procedural idle](guides/clips.md)):

```c
sona_idle_options o;
sona_idle_defaults(&o);        /* parts SONA_IDLE_ALL, seed 0, amount 1, face_px 240 */
o.seed = 42;                   /* 0: from the ctx seed and the avatar id */
sona_avatar_idle(avatar, &o);  /* NULL turns it off */
```

Turns the procedural idle on with these options, or off for `NULL`. A seed of 0 is resolved from the ctx seed and
the avatar id. `SONA_E_ARGUMENT` for a size below 20, unknown parts, amount outside 0..2 or a negative or infinite
face_px; `SONA_E_DESTROYED` for a removed avatar. Off, the avatar poses exactly as without it.

### sona_avatar_idle_get

```c
sona_result sona_avatar_idle_get(const sona_avatar *a, sona_idle_options *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_idle_options *` | Receives the [`sona_idle_options`](reference/fields.md#sona_idle_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_idle_options x_idle_options;
memset(&x_idle_options, 0, sizeof x_idle_options);
x_idle_options.size = sizeof x_idle_options;
sona_result result = sona_avatar_idle_get(avatar, &x_idle_options);
if (result != SONA_OK) printf("sona_avatar_idle_get: %s\n", sona_result_name(result));
```

The options in use, seed resolved; parts 0 when off.

### sona_avatar_idle_state

```c
sona_result sona_avatar_idle_state(const sona_avatar *a, sona_idle_state *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_idle_state *` | Receives the [`sona_idle_state`](reference/fields.md#sona_idle_state) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_idle_state x_idle_state;
memset(&x_idle_state, 0, sizeof x_idle_state);
x_idle_state.size = sizeof x_idle_state;
sona_result result = sona_avatar_idle_state(avatar, &x_idle_state);
if (result != SONA_OK) printf("sona_avatar_idle_state: %s\n", sona_result_name(result));
```

The channels the idle gave the avatar's last pose (before amount); all 0 before one or when off.

### sona_idle_sample

```c
sona_result sona_idle_sample(const sona_idle_options *o, double seconds, sona_idle_state *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_idle_options *` | The options, a [`sona_idle_options`](reference/fields.md#sona_idle_options) | required |
| `seconds` | `double` | The time to sample, seconds | - |
| `out` | `sona_idle_state *` | Receives the [`sona_idle_state`](reference/fields.md#sona_idle_state) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_idle_options x_idle_options;
memset(&x_idle_options, 0, sizeof x_idle_options);
x_idle_options.size = sizeof x_idle_options;
sona_idle_state x_idle_state2;
memset(&x_idle_state2, 0, sizeof x_idle_state2);
x_idle_state2.size = sizeof x_idle_state2;
sona_result result = sona_idle_sample(&x_idle_options, 0.5f, &x_idle_state2);
if (result != SONA_OK) printf("sona_idle_sample: %s\n", sona_result_name(result));
```

Pure: the channels at seconds on the ctx clock for `o->seed` (0 is a seed here) and `o->parts`, before amount.
`sona_avatar_idle_state` equals it at the clock of the last pose. `SONA_E_ARGUMENT` for a negative or infinite
time.

## Inverse kinematics

Two-bone IK for the arms and legs, feet planted on the host's ground, look-at for the head and the eyes, and hand
targets. It runs in every pose after the clip, the fades, the overrides and any layers, before skinning. Each struct
starts with `size = sizeof(struct)` and is refused (`SONA_E_ARGUMENT`) when `size` is smaller; the `_defaults`
functions set it. Avatar calls belong to the owner thread and give `SONA_E_ARGUMENT` for a NULL avatar and
`SONA_E_DESTROYED` for one being removed. Every setter re-poses the avatar at the next `sona_update`. The guide,
with the limits, the ground modes and the cost, is [Inverse kinematics](guides/ik.md).

| Struct | Bytes (8-byte pointers) | Fields |
|---|---|---|
| `sona_ik_target` | 92 | `size`, `flags`, `position[3]`, `rotation[4]`, `pole[3]`, `joint`, `weight`, `fade_seconds`, `reserved[8]` |
| `sona_ik_feet` | 88 (80 with 4-byte pointers) | `size`, `ground`, `plane[4]`, `query`, `user`, `weight`, `max_hips_offset`, `max_tilt_deg`, `smoothing`, `reserved[8]` |
| `sona_ik_look` | 80 | `size`, `flags`, `target[3]`, `weight`, `max_yaw_deg`, `max_up_deg`, `max_down_deg`, `smoothing`, `max_speed_deg`, `eye_threshold_deg`, `reserved[8]` |
| `sona_ik_limits` | 72 | `size`, `flags`, `elbow_max_deg`, `knee_max_deg`, `wrist_swing_deg`, `wrist_twist_deg`, `ankle_swing_deg`, `ankle_twist_deg`, `soft_reach`, `body_margin`, `hip_forward_deg`, `hip_back_deg`, `hip_out_deg`, `hip_in_deg`, `shoulder_back_deg`, `shoulder_across_deg`, `reserved[2]` |
| `sona_ik_status` | 88 | `size`, `active`, `error[4]`, `hit[4]`, `hips_offset`, `look_yaw_deg`, `look_pitch_deg`, `eyes[2]`, `pad[2]`, `reserved[8]` |

Limbs: `SONA_IK_LEFT_HAND` (0), `SONA_IK_RIGHT_HAND` (1), `SONA_IK_LEFT_FOOT` (2), `SONA_IK_RIGHT_FOOT` (3).

### sona_ik_target_defaults

```c
void sona_ik_target_defaults(sona_ik_target *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_ik_target *` | The [`sona_ik_target`](reference/fields.md#sona_ik_target) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ik_target x_ik_target;
sona_ik_target_defaults(&x_ik_target);
sona_ik_target_defaults(&x_ik_target);
```

`size` set, no flags, position 0, rotation (0, 0, 0, 1), joint -1, weight 1, and the fade a default of 0.2 s. NULL is ignored.

### sona_avatar_ik_target

```c
sona_result sona_avatar_ik_target(sona_avatar *a, uint32_t limb, const sona_ik_target *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `limb` | `uint32_t` | A `SONA_IK_*` limb | - |
| `t` | `const sona_ik_target *` | A [`sona_ik_target`](reference/fields.md#sona_ik_target) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_target x_ik_target;
sona_ik_target_defaults(&x_ik_target);
sona_result result = sona_avatar_ik_target(avatar, 0, &x_ik_target);
if (result != SONA_OK) printf("sona_avatar_ik_target: %s\n", sona_result_name(result));
```

A hand puts its palm (with `SONA_IK_WRIST` its wrist) at `position`; a foot its ankle. Flags: `SONA_IK_ROTATION`
(`rotation` is the hand's or foot's world orientation from the rest pose), `SONA_IK_POLE` (`pole` is a point the
elbow or knee bends towards), `SONA_IK_RELATIVE` (position, rotation and pole are in the frame of `joint` of this
avatar), `SONA_IK_AVATAR_SPACE` (in avatar space, before the placement). `weight` 0..1 eases over `fade_seconds`.
NULL `t`: off at once. A foot target replaces planting for that foot. `SONA_E_ARGUMENT` for a limb past 3, a small
`size`, an unknown flag, a non-finite position or pole, a weight outside 0..1, a negative fade, a zero quaternion,
`SONA_IK_RELATIVE` without a joint (or with `SONA_IK_AVATAR_SPACE`), or `SONA_IK_WRIST` on a foot.

### sona_ik_feet_defaults

```c
void sona_ik_feet_defaults(sona_ik_feet *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ik_feet *` | The [`sona_ik_feet`](reference/fields.md#sona_ik_feet) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ik_feet x_ik_feet;
sona_ik_feet_defaults(&x_ik_feet);
sona_ik_feet_defaults(&x_ik_feet);
```

`SONA_IK_GROUND_PLANE` with the plane y = 0, weight 1, hips offset at most 0.45 m, tilt at most 35 degrees,
and the smoothing a default of 0.1 s.

### sona_avatar_ik_feet

```c
sona_result sona_avatar_ik_feet(sona_avatar *a, const sona_ik_feet *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_ik_feet *` | A [`sona_ik_feet`](reference/fields.md#sona_ik_feet) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_feet x_ik_feet;
sona_ik_feet_defaults(&x_ik_feet);
sona_result result = sona_avatar_ik_feet(avatar, &x_ik_feet);
if (result != SONA_OK) printf("sona_avatar_ik_feet: %s\n", sona_result_name(result));
```

Plants the feet on the ground given by `ground`: `SONA_IK_GROUND_PLANE` (`plane`: n.x, n.y, n.z, d, world),
`SONA_IK_GROUND_POINTS` (`sona_avatar_ik_ground` per foot) or `SONA_IK_GROUND_CALLBACK` (`query`, a downward ray
the core asks for each foot's heel and toes; it runs on the posing threads, at the same time for different
avatars, must be safe from any thread and must not call into sona). The hips move by up to `max_hips_offset`.
NULL: off at once. `SONA_E_ARGUMENT` for a small `size`, another mode, a plane with no up component, a callback
mode without `query`, or a weight, offset, tilt or smoothing out of range.

### sona_avatar_ik_ground

```c
sona_result sona_avatar_ik_ground(sona_avatar *a, uint32_t foot, const float point[3], const float normal[3]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `foot` | `uint32_t` | `SONA_IK_LEFT_FOOT` or `SONA_IK_RIGHT_FOOT` | - |
| `point` | `const float [3]` | A point on the ground under the foot, world space | required |
| `normal` | `const float [3]` | The ground's normal under the foot | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
float x_point[3];
memset(x_point, 0, sizeof x_point);
float x_normal2[3];
memset(x_normal2, 0, sizeof x_normal2);
sona_result result = sona_avatar_ik_ground(avatar, 0, x_point, x_normal2);
if (result != SONA_OK) printf("sona_avatar_ik_ground: %s\n", sona_result_name(result));
```

`SONA_IK_GROUND_POINTS`: the world point and normal of the ground under `SONA_IK_LEFT_FOOT` or
`SONA_IK_RIGHT_FOOT`, used from the next pose until changed. NULL `point`: no ground under that foot.
`SONA_E_ARGUMENT` for another limb, a NULL or zero normal, or a non-finite value.

### sona_ik_look_defaults

```c
void sona_ik_look_defaults(sona_ik_look *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ik_look *` | The [`sona_ik_look`](reference/fields.md#sona_ik_look) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_ik_look look;
sona_ik_look_defaults(&look);
look.target[0] = player_head[0];
look.target[1] = player_head[1];
look.target[2] = player_head[2];
sona_avatar_ik_look(avatar, &look);
```

Its defaults are head and eyes, weight 1, yaw 70, up 35, down 45 degrees, smoothing by default 0.15 s, a turn rate of 360 degrees a second, eyes past 10.

### sona_avatar_ik_look

```c
sona_result sona_avatar_ik_look(sona_avatar *a, const sona_ik_look *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_ik_look *` | A [`sona_ik_look`](reference/fields.md#sona_ik_look) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_ik_look look;
sona_ik_look_defaults(&look);
look.target[0] = player_head[0];
look.target[1] = player_head[1];
look.target[2] = player_head[2];
sona_avatar_ik_look(avatar, &look);
```

Turns the chest, neck and head towards the world point `target` inside the limits, eased; the eyes take the rest
through the face's look shapes when it has them. `SONA_IK_LOOK_HEAD` and `SONA_IK_LOOK_EYES` choose which. NULL:
off, easing back. `SONA_E_ARGUMENT` for a small `size`, an unknown flag, a non-finite target, or a limit out of
range (yaw 0..135, up and down 0..89, eyes 0..90, speed above 0).

### sona_ik_limits_defaults

```c
void sona_ik_limits_defaults(sona_ik_limits *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ik_limits *` | The [`sona_ik_limits`](reference/fields.md#sona_ik_limits) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ik_limits x_ik_limits;
sona_ik_limits_defaults(&x_ik_limits);
sona_ik_limits_defaults(&x_ik_limits);
```

Elbows 145, knees 150, wrists 75 swing and 80 twist, ankles 45 and 30 degrees, hips 120 forward, 25 behind, 45
out and 25 in, shoulders 45 behind (held level) and 50 across, reach easing from 0.97, a 0.02 m body margin, the body checks
on.

### sona_avatar_ik_limits

```c
sona_result sona_avatar_ik_limits(sona_avatar *a, const sona_ik_limits *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_ik_limits *` | A [`sona_ik_limits`](reference/fields.md#sona_ik_limits) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_limits x_ik_limits;
sona_ik_limits_defaults(&x_ik_limits);
sona_result result = sona_avatar_ik_limits(avatar, &x_ik_limits);
if (result != SONA_OK) printf("sona_avatar_ik_limits: %s\n", sona_result_name(result));
```

The joint limits for this avatar's solves. `SONA_IK_NO_BODY` turns off the checks that keep the limbs clear of the
torso, head and legs. Every limit is hard: a target past one is reached short, and a clip already past one is
kept, never taken further. NULL: the defaults. `SONA_E_ARGUMENT` for a small `size`, an unknown flag or a value out
of range (hips forward 0..150, behind 0..90 and the two together at most 180; out, in and the shoulders 0..90).

### sona_avatar_ik_clear

```c
void sona_avatar_ik_clear(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example**:

```c
sona_avatar_ik_clear(avatar);
```

Every target, the planting and the look-at off at once. The next pose is the clip's, bit for bit. NULL is ignored.

### sona_avatar_ik_status

```c
sona_result sona_avatar_ik_status(const sona_avatar *a, sona_ik_status *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_ik_status *` | Receives the [`sona_ik_status`](reference/fields.md#sona_ik_status) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_status x_ik_status;
memset(&x_ik_status, 0, sizeof x_ik_status);
x_ik_status.size = sizeof x_ik_status;
sona_result result = sona_avatar_ik_status(avatar, &x_ik_status);
if (result != SONA_OK) printf("sona_avatar_ik_status: %s\n", sona_result_name(result));
```

What the last pose did: `active` (`1 << limb`, `SONA_IK_ACTIVE_FEET`, `SONA_IK_ACTIVE_LOOK`), each limb's
distance from its target in metres, what held it back (`SONA_IK_HIT_REACH`, `_BEND`, `_POLE`, `_BODY`,
`_ROTATION`, `_GROUND`, `_SWING`), the hips' move, the head's turn from the clip and the eye shapes shown (255: the clip's).
Set `out->size` first. `SONA_E_NOT_READY` before the avatar was posed with IK on; `SONA_E_ARGUMENT` for a small
`size`.

### sona_ik_foot_lock_defaults

```c
void sona_ik_foot_lock_defaults(sona_ik_foot_lock *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ik_foot_lock *` | The [`sona_ik_foot_lock`](reference/fields.md#sona_ik_foot_lock) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ik_foot_lock x_ik_foot_lock;
sona_ik_foot_lock_defaults(&x_ik_foot_lock);
sona_ik_foot_lock_defaults(&x_ik_foot_lock);
```

`size` set; `weight` 1, `max_slide` 0.25, `release_seconds` 0.15.

### sona_avatar_ik_foot_lock

```c
sona_result sona_avatar_ik_foot_lock(sona_avatar *a, const sona_ik_foot_lock *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_ik_foot_lock *` | A [`sona_ik_foot_lock`](reference/fields.md#sona_ik_foot_lock) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_foot_lock x_ik_foot_lock;
sona_ik_foot_lock_defaults(&x_ik_foot_lock);
sona_result result = sona_avatar_ik_foot_lock(avatar, &x_ik_foot_lock);
if (result != SONA_OK) printf("sona_avatar_ik_foot_lock: %s\n", sona_result_name(result));
```

Foot locking: a foot the clip plants stays where it landed until the clip lifts the heel, so walk and run clips do not slide while the host moves the avatar no faster than the clip's feet travel. Pulled past `max_slide` it lets go. A foot target replaces it for that foot. NULL: off.

### sona_ik_spine_defaults

```c
void sona_ik_spine_defaults(sona_ik_spine *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ik_spine *` | The [`sona_ik_spine`](reference/fields.md#sona_ik_spine) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ik_spine x_ik_spine;
sona_ik_spine_defaults(&x_ik_spine);
sona_ik_spine_defaults(&x_ik_spine);
```

`size` set; `weight` 1, `max_bend_deg` 35, `max_twist_deg` 40, `hips_share` 0.2.

### sona_avatar_ik_spine

```c
sona_result sona_avatar_ik_spine(sona_avatar *a, const sona_ik_spine *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_ik_spine *` | A [`sona_ik_spine`](reference/fields.md#sona_ik_spine) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_spine x_ik_spine;
sona_ik_spine_defaults(&x_ik_spine);
sona_result result = sona_avatar_ik_spine(avatar, &x_ik_spine);
if (result != SONA_OK) printf("sona_avatar_ik_spine: %s\n", sona_result_name(result));
```

Spine assist: a hand target past the arm's reach bends and turns the spine, and the hips a little, towards it. NULL: off.

### sona_ik_fingers_defaults

```c
void sona_ik_fingers_defaults(sona_ik_fingers *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ik_fingers *` | The [`sona_ik_fingers`](reference/fields.md#sona_ik_fingers) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ik_fingers x_ik_fingers;
sona_ik_fingers_defaults(&x_ik_fingers);
sona_ik_fingers_defaults(&x_ik_fingers);
```

`size` set; `spread` 0, `weight` 1, `fade_seconds` 0.15.

### sona_avatar_ik_fingers

```c
sona_result sona_avatar_ik_fingers(sona_avatar *a, uint32_t hand, const sona_ik_fingers *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `hand` | `uint32_t` | `SONA_IK_LEFT_HAND` or `SONA_IK_RIGHT_HAND` | - |
| `o` | `const sona_ik_fingers *` | A [`sona_ik_fingers`](reference/fields.md#sona_ik_fingers) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_fingers x_ik_fingers;
sona_ik_fingers_defaults(&x_ik_fingers);
sona_result result = sona_avatar_ik_fingers(avatar, 0, &x_ik_fingers);
if (result != SONA_OK) printf("sona_avatar_ik_fingers: %s\n", sona_result_name(result));
```

`hand` `SONA_IK_LEFT_HAND` or `SONA_IK_RIGHT_HAND`. NULL: back to the clip over fade_seconds.

### sona_ik_eyes_defaults

```c
void sona_ik_eyes_defaults(sona_ik_eyes *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ik_eyes *` | The [`sona_ik_eyes`](reference/fields.md#sona_ik_eyes) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ik_eyes x_ik_eyes;
sona_ik_eyes_defaults(&x_ik_eyes);
sona_ik_eyes_defaults(&x_ik_eyes);
```

`size` set; `max_speed_deg` 400, `smoothing` 0.05, `lead_seconds` 0.08.

### sona_avatar_ik_eyes

```c
sona_result sona_avatar_ik_eyes(sona_avatar *a, const sona_ik_eyes *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_ik_eyes *` | A [`sona_ik_eyes`](reference/fields.md#sona_ik_eyes) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ik_eyes x_ik_eyes;
sona_ik_eyes_defaults(&x_ik_eyes);
sona_result result = sona_avatar_ik_eyes(avatar, &x_ik_eyes);
if (result != SONA_OK) printf("sona_avatar_ik_eyes: %s\n", sona_result_name(result));
```

Smooth eye turns: the eyes move towards the look-at target at up to `max_speed_deg` a second and lead the head by `lead_seconds`. NULL: back to the plain look-at.

## Imported clips

Your own glTF, FBX and BVH clips, retargeted onto the avatar rig and played by key like stock clips. The guide, with
the naming table and the retarget, is [Bring your own animation](guides/import.md). Structs:
`sona_import_options`, `sona_import_info`, `sona_bone_map`, and the opaque `sona_anim_file`.

### sona_import_defaults

```c
void sona_import_defaults(sona_import_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_import_options *` | The [`sona_import_options`](reference/fields.md#sona_import_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Bring your own animation](guides/import.md)):

```c
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];

sona_import_defaults(&o);
o.key = "wave_big";                                  /* NULL: the take's own name */
if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; }
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)   /* waits for the rig data, read through the sources */
  sona_update(ctx, 1.0 / 60, &view, NULL);
sona_anim_file_free(f);                              /* the clip is kept; the file is not needed any more */

sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f);
```

Zeroes the options and sets `size`.

### sona_import_formats

```c
uint32_t sona_import_formats(void);
```

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_import_formats();
printf("sona_import_formats: %lld\n", (long long)x_got);
```

`1 << SONA_ANIM_GLTF`, `_FBX` and `_BVH` for each format this build reads.

### sona_anim_file_load

```c
sona_result sona_anim_file_load(const void *bytes, size_t len, const sona_import_options *opts, sona_anim_file **out,
                                char *why, size_t why_cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `bytes` | `const void *` | The file's bytes | required |
| `len` | `size_t` | How many bytes there are | - |
| `opts` | `const sona_import_options *` | The options, a [`sona_import_options`](reference/fields.md#sona_import_options) | `NULL` allowed (below) |
| `out` | `sona_anim_file **` | Receives the new animation file | required |
| `why` | `char *` | Receives what was refused, NUL-terminated; may be NULL | `NULL`: not written |
| `why_cap` | `size_t` | How many bytes `why` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

Parses a clip file in memory, no ctx needed. `opts` may be NULL; its `format`, `map` and `flags` are used (the
mapping `sona_anim_file_bone` reports). `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED` or `SONA_E_LIMIT` with the reason in
`why`. A `.gltf` whose buffers are other files needs `sona_anim_file_open`.

### sona_anim_file_open

```c
sona_result sona_anim_file_open(const char *path, const sona_import_options *opts, sona_anim_file **out,
                                char *why, size_t why_cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `path` | `const char *` | A file path | required |
| `opts` | `const sona_import_options *` | The options, a [`sona_import_options`](reference/fields.md#sona_import_options) | required |
| `out` | `sona_anim_file **` | Receives the new animation file | required |
| `why` | `char *` | Receives what was refused, NUL-terminated; may be NULL | `NULL`: not written |
| `why_cap` | `size_t` | How many bytes `why` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Bring your own animation](guides/import.md)):

```c
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];

sona_import_defaults(&o);
o.key = "wave_big";                                  /* NULL: the take's own name */
if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; }
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)   /* waits for the rig data, read through the sources */
  sona_update(ctx, 1.0 / 60, &view, NULL);
sona_anim_file_free(f);                              /* the clip is kept; the file is not needed any more */

sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f);
```

The same from a path (`SONA_E_IO` when it cannot be read). A BVH take is named after the file.

### sona_anim_file_free

```c
void sona_anim_file_free(sona_anim_file *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_anim_file *` | The animation file | required |

**Returns** Nothing.

**Example** (also in [Bring your own animation](guides/import.md)):

```c
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];

sona_import_defaults(&o);
o.key = "wave_big";                                  /* NULL: the take's own name */
if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; }
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)   /* waits for the rig data, read through the sources */
  sona_update(ctx, 1.0 / 60, &view, NULL);
sona_anim_file_free(f);                              /* the clip is kept; the file is not needed any more */

sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f);
```

Imported clips do not need the file once `sona_clip_import` returned.

### sona_anim_file_takes

```c
uint32_t sona_anim_file_takes(const sona_anim_file *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_anim_file *` | The animation file | required |

**Returns** `uint32_t`.

How many takes (animations) the file holds.

### sona_anim_file_take

```c
const char *sona_anim_file_take(const sona_anim_file *f, uint32_t index, float *seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_anim_file *` | The animation file | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `seconds` | `float *` | Receives the take's length, seconds | required |

**Returns** `const char *`.

A take's name and length; `NULL` past the last.

### sona_anim_file_bones

```c
uint32_t sona_anim_file_bones(const sona_anim_file *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_anim_file *` | The animation file | required |

**Returns** `uint32_t`.

How many bones the file's skeleton has.

### sona_anim_file_bone

```c
const char *sona_anim_file_bone(const sona_anim_file *f, uint32_t index, int32_t *parent, int32_t *joint);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_anim_file *` | The animation file | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `parent` | `int32_t *` | Receives the parent bone's index, -1 for a root | required |
| `joint` | `int32_t *` | Receives the rig joint the bone drives, -1 for none | required |

**Returns** `const char *`.

A bone's name, its parent (a lower index, or -1) and the avatar joint it drives (-1 none). `NULL` past the last.

### sona_clip_import

```c
sona_result sona_clip_import(sona_ctx *ctx, const sona_anim_file *f, const sona_import_options *opts,
                             sona_import_info *info);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `f` | `const sona_anim_file *` | The animation file | required |
| `opts` | `const sona_import_options *` | The options, a [`sona_import_options`](reference/fields.md#sona_import_options) | required |
| `info` | `sona_import_info *` | Receives what the file holds; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_GATE` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Bring your own animation](guides/import.md)):

```c
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];

sona_import_defaults(&o);
o.key = "wave_big";                                  /* NULL: the take's own name */
if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; }
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)   /* waits for the rig data, read through the sources */
  sona_update(ctx, 1.0 / 60, &view, NULL);
sona_anim_file_free(f);                              /* the clip is kept; the file is not needed any more */

sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f);
```

Retargets one take and keeps it under its key (replacing an imported clip of that key). `SONA_PENDING` until the
rig data has been read: call again after `sona_update`. `SONA_E_ARGUMENT` for a stock key, an id, an unknown take or
a map entry naming no joint; `SONA_E_NOT_FOUND` when no bone matches a joint or the file has no animation;
`SONA_E_LIMIT` past 1024 clips. `sona_last_error` has the reason.

### sona_clip_imported_count

```c
uint32_t sona_clip_imported_count(const sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_clip_imported_count(ctx);
printf("sona_clip_imported_count: %lld\n", (long long)x_got);
```

How many clips have been imported into the ctx.

### sona_clip_imported_get

```c
sona_result sona_clip_imported_get(const sona_ctx *ctx, uint32_t index, sona_import_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_import_info *` | Receives the [`sona_import_info`](reference/fields.md#sona_import_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_import_info x_import_info;
memset(&x_import_info, 0, sizeof x_import_info);
x_import_info.size = sizeof x_import_info;
sona_result result = sona_clip_imported_get(ctx, 0, &x_import_info);
if (result != SONA_OK) printf("sona_clip_imported_get: %s\n", sona_result_name(result));
```

`SONA_E_NOT_FOUND` past the last.

### sona_clip_imported_find

```c
sona_result sona_clip_imported_find(const sona_ctx *ctx, const char *key, sona_import_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `key` | `const char *` | The key, as it was given when made | required |
| `out` | `sona_import_info *` | Receives the [`sona_import_info`](reference/fields.md#sona_import_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_import_info x_import_info;
memset(&x_import_info, 0, sizeof x_import_info);
x_import_info.size = sizeof x_import_info;
sona_result result = sona_clip_imported_find(ctx, "GenericWave", &x_import_info);
if (result != SONA_OK) printf("sona_clip_imported_find: %s\n", sona_result_name(result));
```

The imported clip with this key; `SONA_E_NOT_FOUND` when there is none.

### sona_clip_imported_remove

```c
sona_result sona_clip_imported_remove(sona_ctx *ctx, const char *key);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `key` | `const char *` | The key, as it was given when made | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_clip_imported_remove(ctx, "GenericWave");
if (result != SONA_OK) printf("sona_clip_imported_remove: %s\n", sona_result_name(result));
```

Avatars playing it finish with their own reference; new plays of the key fail with `SONA_E_ARGUMENT`.

## Headless rendering and video out

A device of the library's own, with no window and no display: the best GPU, or a software rasteriser (lavapipe,
llvmpipe) where there is none. Pictures are straight RGBA8, row 0 at the top. Every call runs on the ctx's owner thread
and blocks until its pictures are read back. The guide, with the device order, the formats, the sample and the
measured gamerpics a second, is [Headless rendering and video](guides/headless.md).

Structs, each with `size` first (set by its `_defaults`; a smaller `size` is `SONA_E_ARGUMENT`): `sona_headless_options`
(64 bytes: `device` `SONA_DEVICE_AUTO`/`GPU`/`SOFTWARE`, `backend` 0/`VULKAN`/`GL`, `adapter` -1, `flags`
`SONA_HEADLESS_VALIDATION`, `batch_in_flight` 8 (at most 32), `wait_seconds` 60), `sona_headless_info` (440 bytes:
`backend`, `software`, `type`, `vendor_id`, `device_id`, `name[256]`, `driver[128]`), `sona_render_options` (104
bytes, 100 with 4-byte pointers: `width` and `height` 256, `preset` FULL, `yaw_deg`, `pitch_deg`, `zoom` 1,
`turn_deg`, `time`, `draw`, `flags` 0, `clip` NULL), `sona_sequence_options` (52 bytes: `frames` 0, `fps` 30,
`turn_deg`, `flags` `SONA_SEQUENCE_ORBIT`) and `sona_video_options` (80 bytes, 76: `format`, `width`, `height`, `fps`
30, `loops` 0, `quality` 0, `background` 0xff000000, `flags` `SONA_VIDEO_OPAQUE` / `SONA_VIDEO_NO_DITHER`, `colours`
0, `ffmpeg` NULL). The handles `sona_headless` and `sona_video` are opaque.

### sona_headless_defaults

```c
void sona_headless_defaults(sona_headless_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_headless_options *` | The [`sona_headless_options`](reference/fields.md#sona_headless_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_headless_options x_headless_options;
memset(&x_headless_options, 0, sizeof x_headless_options);
x_headless_options.size = sizeof x_headless_options;
sona_headless_defaults(&x_headless_options);
```

Fills the defaults above. NULL does nothing.

### sona_headless_devices

```c
uint32_t sona_headless_devices(const sona_headless_options *o, sona_headless_info *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_headless_options *` | The options, a [`sona_headless_options`](reference/fields.md#sona_headless_options) | `NULL`: the defaults |
| `out` | `sona_headless_info *` | Receives the [`sona_headless_info`](reference/fields.md#sona_headless_info) | `NULL` allowed (below) |
| `cap` | `uint32_t` | How many entries `out` holds | `NULL` allowed (below) |

**Returns** `uint32_t`.

**Example**:

```c
sona_headless_options x_headless_options;
memset(&x_headless_options, 0, sizeof x_headless_options);
x_headless_options.size = sizeof x_headless_options;
sona_headless_info x_headless_info2;
memset(&x_headless_info2, 0, sizeof x_headless_info2);
x_headless_info2.size = sizeof x_headless_info2;
uint32_t x_got = sona_headless_devices(&x_headless_options, &x_headless_info2, 1);
printf("sona_headless_devices: %lld\n", (long long)x_got);
```

The devices a headless renderer can open with `o`'s backend: Vulkan devices in the loader's order, then EGL devices.
Writes up to `cap` (`out` may be NULL) and returns how many there are. NULL `o`: the defaults; bad options: 0.

### sona_headless_open

```c
sona_result sona_headless_open(sona_ctx *ctx, const sona_headless_options *o, sona_headless **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_headless_options *` | The options, a [`sona_headless_options`](reference/fields.md#sona_headless_options) | `NULL`: the defaults |
| `out` | `sona_headless **` | Receives the new headless renderer | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_headless *h;
sona_headless_open(ctx, NULL, &h);                 /* best GPU, else lavapipe or llvmpipe */
sona_render_options ro;
sona_render_defaults(&ro);                         /* 256 x 256, full body, transparent */
ro.preset = SONA_PRESET_BUST;
uint8_t *rgba = malloc(256 * 256 * 4);
sona_headless_render_manifest(h, manifest, &ro, rgba);   /* waits for the avatar, draws it, removes it */
```

Makes the device and a renderer on it, waiting up to `wait_seconds` for the ctx's shading data. NULL `o`: the defaults.
`SONA_E_UNSUPPORTED` when no device fits (the message says what was tried), `SONA_E_ARGUMENT` for bad options,
`SONA_E_NOT_READY` when the shading data did not load in time.

### sona_headless_close

```c
void sona_headless_close(sona_headless *h);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `sona_headless *` | The headless renderer | required |

**Returns** Nothing.

Frees the renderer and the device. NULL is fine. Close it before the ctx.

### sona_headless_info_get

```c
sona_result sona_headless_info_get(const sona_headless *h, sona_headless_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `const sona_headless *` | The headless renderer | required |
| `out` | `sona_headless_info *` | Receives the [`sona_headless_info`](reference/fields.md#sona_headless_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The device it drew on. `SONA_E_ARGUMENT` for NULL arguments.

### sona_headless_renderer

```c
sona_renderer *sona_headless_renderer(const sona_headless *h);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `const sona_headless *` | The headless renderer | required |

**Returns** `sona_renderer *`.

Its renderer, for `sona_renderer_set_quality` and the like. Owned by `h`; do not destroy it.

### sona_render_defaults

```c
void sona_render_defaults(sona_render_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_render_options *` | The [`sona_render_options`](reference/fields.md#sona_render_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_headless *h;
sona_headless_open(ctx, NULL, &h);                 /* best GPU, else lavapipe or llvmpipe */
sona_render_options ro;
sona_render_defaults(&ro);                         /* 256 x 256, full body, transparent */
ro.preset = SONA_PRESET_BUST;
uint8_t *rgba = malloc(256 * 256 * 4);
sona_headless_render_manifest(h, manifest, &ro, rgba);   /* waits for the avatar, draws it, removes it */
```

256 x 256, `SONA_PRESET_FULL`, zoom 1, transparent, no clip. NULL does nothing.

### sona_headless_render

```c
sona_result sona_headless_render(sona_headless *h, sona_avatar *a, const sona_render_options *o, uint8_t *rgba_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `sona_headless *` | The headless renderer | required |
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_render_options *` | The options, a [`sona_render_options`](reference/fields.md#sona_render_options) | required |
| `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

One picture of an avatar of the ctx, alone, after waiting for it to be READY. With `clip` set it plays that clip from
`time` (as `sona_avatar_play`, from then on) and is drawn at `time`; without, it is drawn as its clock stands. Its
placement, clock and pose are as before when the call returns. `rgba_out` holds `width * height * 4` bytes.
`SONA_E_ARGUMENT` for bad options, an item preview, an avatar of another ctx or a clip it does not have;
`SONA_E_NOT_READY` after `wait_seconds`; its own failure code when it FAILED.

### sona_headless_render_manifest

```c
sona_result sona_headless_render_manifest(sona_headless *h, const uint8_t manifest[SONA_MANIFEST_BYTES],
                                          const sona_render_options *o, uint8_t *rgba_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `sona_headless *` | The headless renderer | required |
| `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required |
| `o` | `const sona_render_options *` | The options, a [`sona_render_options`](reference/fields.md#sona_render_options) | required |
| `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_headless *h;
sona_headless_open(ctx, NULL, &h);                 /* best GPU, else lavapipe or llvmpipe */
sona_render_options ro;
sona_render_defaults(&ro);                         /* 256 x 256, full body, transparent */
ro.preset = SONA_PRESET_BUST;
uint8_t *rgba = malloc(256 * 256 * 4);
sona_headless_render_manifest(h, manifest, &ro, rgba);   /* waits for the avatar, draws it, removes it */
```

Adds the avatar (hidden, standing still or playing `clip` from `time`), draws it and removes it. Errors as above;
`SONA_E_MANIFEST` for a manifest that cannot be built, `SONA_E_LIMIT` when the ctx is full.

### sona_headless_batch

```c
sona_result sona_headless_batch(sona_headless *h, const uint8_t *manifests, uint32_t count,
                                const sona_render_options *o, sona_picture_fn fn, void *user);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `sona_headless *` | The headless renderer | required |
| `manifests` | `const uint8_t *` | The manifests, 1,000 bytes each, one after the other | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `o` | `const sona_render_options *` | The options, a [`sona_render_options`](reference/fields.md#sona_render_options) | required |
| `fn` | `sona_picture_fn` | Called with each picture as it is made | - |
| `user` | `void *` | Passed to the callback as it is | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

`count` manifests, one after another, to pictures. `fn(user, index, result, rgba, width, height)` runs once for each,
in index order; `rgba` is NULL unless `result` is `SONA_OK` and lives until `fn` returns. `batch_in_flight` avatars
build ahead; each is removed once drawn. A failing manifest gives its code and the batch goes on. Returns `SONA_OK`, or
the error that stopped it (`SONA_E_CONTEXT`, `SONA_E_MEMORY`, a ctx-wide error). `SONA_E_ARGUMENT` for NULL `fn`.

### sona_sequence_defaults

```c
void sona_sequence_defaults(sona_sequence_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_sequence_options *` | The [`sona_sequence_options`](reference/fields.md#sona_sequence_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_sequence_options so;
sona_sequence_defaults(&so);
so.turn_deg = 360;
so.frames = 36;
sona_video_options vo;
sona_video_defaults(&vo);
vo.width = ro.width; vo.height = ro.height; vo.fps = 18;
sona_video *v;
sona_video_open(ctx, "turntable.gif", &vo, &v);
sona_headless_record(h, avatar, &ro, &so, v);
sona_video_finish(v, NULL, NULL);
```

`frames` 0, `fps` 30, no turn. NULL does nothing.

### sona_headless_sequence

```c
sona_result sona_headless_sequence(sona_headless *h, sona_avatar *a, const sona_render_options *r,
                                   const sona_sequence_options *s, sona_picture_fn fn, void *user);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `sona_headless *` | The headless renderer | required |
| `a` | `sona_avatar *` | The avatar | required |
| `r` | `const sona_render_options *` | The options, a [`sona_render_options`](reference/fields.md#sona_render_options) | required |
| `s` | `const sona_sequence_options *` | The options, a [`sona_sequence_options`](reference/fields.md#sona_sequence_options) | required |
| `fn` | `sona_picture_fn` | Called with each picture as it is made | - |
| `user` | `void *` | Passed to the callback as it is | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Frame `i` is the clip at its start + `i / fps` (the render options' `time` with a clip, else the avatar's clock) and the
turn `turn_deg * i / frames` (of the avatar, or of the camera with `SONA_SEQUENCE_ORBIT`). `frames` 0: the clip's
length at `fps`, rounded; 36 when nothing plays and `turn_deg` is set; else 1. `fn` gets every frame in order. The same
inputs give the same pixels every run. The avatar's clock and placement are put back after.

### sona_headless_record

```c
sona_result sona_headless_record(sona_headless *h, sona_avatar *a, const sona_render_options *r,
                                 const sona_sequence_options *s, sona_video *v);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `h` | `sona_headless *` | The headless renderer | required |
| `a` | `sona_avatar *` | The avatar | required |
| `r` | `const sona_render_options *` | The options, a [`sona_render_options`](reference/fields.md#sona_render_options) | required |
| `s` | `const sona_sequence_options *` | The options, a [`sona_sequence_options`](reference/fields.md#sona_sequence_options) | required |
| `v` | `sona_video *` | The video writer | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_sequence_options so;
sona_sequence_defaults(&so);
so.turn_deg = 360;
so.frames = 36;
sona_video_options vo;
sona_video_defaults(&vo);
vo.width = ro.width; vo.height = ro.height; vo.fps = 18;
sona_video *v;
sona_video_open(ctx, "turntable.gif", &vo, &v);
sona_headless_record(h, avatar, &ro, &so, v);
sona_video_finish(v, NULL, NULL);
```

`sona_headless_sequence` into a video. `SONA_E_ARGUMENT` when the video's size is not the render size; a video
error stops it.

### sona_video_defaults

```c
void sona_video_defaults(sona_video_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_video_options *` | The [`sona_video_options`](reference/fields.md#sona_video_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_sequence_options so;
sona_sequence_defaults(&so);
so.turn_deg = 360;
so.frames = 36;
sona_video_options vo;
sona_video_defaults(&vo);
vo.width = ro.width; vo.height = ro.height; vo.fps = 18;
sona_video *v;
sona_video_open(ctx, "turntable.gif", &vo, &v);
sona_headless_record(h, avatar, &ro, &so, v);
sona_video_finish(v, NULL, NULL);
```

The defaults are `format` from the path, a frame rate of 30 fps, opaque black background, every other field 0. Set `width` and `height`.

### sona_video_open

```c
sona_result sona_video_open(sona_ctx *ctx, const char *path, const sona_video_options *o, sona_video **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `path` | `const char *` | A file path | required |
| `o` | `const sona_video_options *` | The options, a [`sona_video_options`](reference/fields.md#sona_video_options) | required |
| `out` | `sona_video **` | Receives the new video writer | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_sequence_options so;
sona_sequence_defaults(&so);
so.turn_deg = 360;
so.frames = 36;
sona_video_options vo;
sona_video_defaults(&vo);
vo.width = ro.width; vo.height = ro.height; vo.fps = 18;
sona_video *v;
sona_video_open(ctx, "turntable.gif", &vo, &v);
sona_headless_record(h, avatar, &ro, &so, v);
sona_video_finish(v, NULL, NULL);
```

Starts a PNG sequence (the path holds one `%d`, `%u` or `%0Nd`), a GIF, or an MP4 or WebM through ffmpeg (started here).
NULL `path` keeps a GIF, MP4 or WebM in memory. `SONA_E_ARGUMENT` for bad options, a PNG path without one number,
or a NULL path with no format; `SONA_E_UNSUPPORTED` when ffmpeg cannot be run or has no fitting encoder (the message
says which); `SONA_E_IO` when the file cannot be made.

### sona_video_frame

```c
sona_result sona_video_frame(sona_video *v, const uint8_t *rgba);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `v` | `sona_video *` | The video writer | required |
| `rgba` | `const uint8_t *` | Straight RGBA8, row 0 at the top, `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](troubleshooting.md#error-codes)).

One frame of `width * height` straight RGBA8, row 0 at the top. `SONA_E_IO` when the file or ffmpeg failed; a GIF or ffmpeg
error sticks.

### sona_video_finish

```c
sona_result sona_video_finish(sona_video *v, uint8_t **out, size_t *out_len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `v` | `sona_video *` | The video writer | required |
| `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Headless rendering and video out](guides/headless.md)):

```c
sona_sequence_options so;
sona_sequence_defaults(&so);
so.turn_deg = 360;
so.frames = 36;
sona_video_options vo;
sona_video_defaults(&vo);
vo.width = ro.width; vo.height = ro.height; vo.fps = 18;
sona_video *v;
sona_video_open(ctx, "turntable.gif", &vo, &v);
sona_headless_record(h, avatar, &ro, &so, v);
sona_video_finish(v, NULL, NULL);
```

Ends the file and frees `v`, also on error. For an in-memory video `*out` and `*out_len` (may be NULL) get the bytes,
freed with `sona_free`. `SONA_E_ARGUMENT` for a video with no frames; `SONA_E_IO` with ffmpeg's last line when it
failed.

### sona_video_formats

```c
uint32_t sona_video_formats(const char *ffmpeg);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ffmpeg` | `const char *` | The ffmpeg program; NULL: `ffmpeg` on the path | `NULL`: `ffmpeg` on the path |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_video_formats("example");
printf("sona_video_formats: %lld\n", (long long)x_got);
```

Bit `1u << format` for each format this machine can write: PNG and GIF always, MP4 and WebM when that ffmpeg (NULL:
`$SONA_FFMPEG`, else `ffmpeg` on the PATH) runs and has an encoder for them.

## Skeleton maps and VRM export

The guides are [VRM and glTF export](guides/vrm.md) (the file, the flattening, the expressions, what was checked)
and [Skeleton maps](guides/skeleton-maps.md) (the five tables). New structs: `sona_vrm_face`,
`sona_export_options` and `sona_export_report`; the last two start with a `size` field, so a later version can grow
them. `sona_struct_size` and `sona_struct_offset` know all three.

### sona_skeleton_bone

```c
const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `skeleton` | `uint32_t` | A `sona_skeleton_kind` | - |
| `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - |

**Returns** `const char *`.

**Example** (also in [Skeleton maps: Unity Humanoid, VRM and the Unreal mannequins](guides/skeleton-maps.md)):

```c
const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint);   /* NULL: that skeleton has no such bone */
int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone);    /* -1: none; names match exactly */
```

The bone a joint is in a `sona_skeleton_kind` (`SONA_SKELETON_UNITY`, `_VRM`, `_VRM0`, `_UE4`, `_UE5`). `NULL` for a joint
that skeleton has no bone for (the shape, prop and special joints), past the last joint or for an unknown
skeleton. A static string; any thread.

### sona_skeleton_joint

```c
int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `skeleton` | `uint32_t` | A `sona_skeleton_kind` | - |
| `bone` | `const char *` | A bone name of that skeleton | required |

**Returns** `int32_t`.

**Example** (also in [Skeleton maps: Unity Humanoid, VRM and the Unreal mannequins](guides/skeleton-maps.md)):

```c
const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint);   /* NULL: that skeleton has no such bone */
int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone);    /* -1: none; names match exactly */
```

The joint a bone of that skeleton is, matched exactly; -1 when none.

### sona_vrm_expression_name

```c
const char *sona_vrm_expression_name(uint32_t expression);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `expression` | `uint32_t` | A VRM expression index | - |

**Returns** `const char *`.

**Example**:

```c
const char * x_got = sona_vrm_expression_name(1);
printf("sona_vrm_expression_name: %s\n", x_got ? "a value" : "none");
```

The VRM 1.0 preset name of a `sona_vrm_expression` (`"aa"` ... `"lookRight"`); `NULL` past the last.

### sona_vrm_face_default

```c
sona_result sona_vrm_face_default(uint32_t expression, sona_vrm_face *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `expression` | `uint32_t` | A VRM expression index | - |
| `out` | `sona_vrm_face *` | Receives the [`sona_vrm_face`](reference/fields.md#sona_vrm_face) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_vrm_face x_vrm_face;
memset(&x_vrm_face, 0, sizeof x_vrm_face);
sona_result result = sona_vrm_face_default(1, &x_vrm_face);
if (result != SONA_OK) printf("sona_vrm_face_default: %s\n", sona_result_name(result));
```

The face an expression shows by default: a shape index per face part, in `sona_avatar_expression`'s order with
left meaning the avatar's own left, 255 for a part it leaves alone. `SONA_E_ARGUMENT` past the last expression.

### sona_export_defaults

```c
void sona_export_defaults(sona_export_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_export_options *` | The [`sona_export_options`](reference/fields.md#sona_export_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [FBX, Roblox and clips in the export](guides/export-fbx.md)):

```c
sona_export_options o;
uint8_t *fbx = NULL;
size_t fbx_len = 0;
sona_export_defaults(&o);
o.format = SONA_EXPORT_FBX;
o.flags = SONA_EXPORT_CLIPS;          /* the clip it plays, as an animation on the skeleton */
if (sona_export_avatar(avatar, &o, &fbx, &fbx_len, NULL) == SONA_OK) {
  FILE *f = fopen("avatar.fbx", "wb");
  if (f) { fwrite(fbx, 1, fbx_len, f); fclose(f); }
  sona_free(ctx, fbx);
}
```

Sets `size`, VRM 1.0, Unity bone names, MToon, no flags, every string `NULL` and the most restrictive licence.

### sona_export_avatar

```c
sona_result sona_export_avatar(sona_avatar *a, const sona_export_options *o, uint8_t **out, size_t *out_len,
                               sona_export_report *report);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_export_options *` | The options, a [`sona_export_options`](reference/fields.md#sona_export_options) | `NULL`: the defaults |
| `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |
| `report` | `sona_export_report *` | Receives what the call did; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [FBX, Roblox and clips in the export](guides/export-fbx.md)):

```c
sona_export_options o;
uint8_t *fbx = NULL;
size_t fbx_len = 0;
sona_export_defaults(&o);
o.format = SONA_EXPORT_FBX;
o.flags = SONA_EXPORT_CLIPS;          /* the clip it plays, as an animation on the skeleton */
if (sona_export_avatar(avatar, &o, &fbx, &fbx_len, NULL) == SONA_OK) {
  FILE *f = fopen("avatar.fbx", "wb");
  if (f) { fwrite(fbx, 1, fbx_len, f); fclose(f); }
  sona_free(ctx, fbx);
}
```

The avatar as one binary glTF, VRM 1.0 or VRM 0.x file in `*out` (free with `sona_free`). `o` `NULL`: the defaults;
fields past `o->size` take their defaults. `report` may be `NULL`; when given, its `size` must be set, and only that
much is written. Runs its slow parts on the ctx's workers; call it from the thread that calls `sona_update`.
`SONA_E_NOT_READY` before READY, `SONA_E_DESTROYED`, `SONA_E_ARGUMENT` for a bad format, bone names, face table or
a `size` of 0, `SONA_E_MEMORY`.

## 3D print export

Posed avatars as one watertight, manifold solid for a 3D printer: every part drawn is skinned as the last `sona_update` posed it and rebuilt from a distance field, so overlapping shells unite, inner faces and holes go, every part is at least `min_wall_mm` thick, and an optional base joins the feet. Millimetres, Z up, right-handed; an avatar at turn 0 faces -Y. CPU only, in the calling thread. The guide, with the pipeline, the options table and the independent checks, is [3D print export](guides/print3d.md).

`sona_print_options` (64 bytes): `{size, flags, height_mm, mm_per_metre, min_wall_mm, voxel_mm, close_mm, base_height_mm, base_margin_mm, base_colour, max_voxels, reserved[5]}`. Flags: `SONA_PRINT_BASE`, `SONA_PRINT_BASE_SQUARE`, `SONA_PRINT_NO_COLOUR`, `SONA_PRINT_LARGEST_ONLY`, `SONA_PRINT_NO_PROPS`. Formats: `SONA_PRINT_STL` (0), `SONA_PRINT_3MF` (1). `sona_print_mesh` (96 bytes, 84 with 4-byte pointers) and `sona_print_report` (112 bytes) carry a `size` the caller sets. `sona_print` is opaque.

### sona_print_defaults

```c
void sona_print_defaults(sona_print_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_print_options *` | The [`sona_print_options`](reference/fields.md#sona_print_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_print_options x_print_options;
memset(&x_print_options, 0, sizeof x_print_options);
x_print_options.size = sizeof x_print_options;
sona_print_defaults(&x_print_options);
```

`size` set, 120 mm tall, 1.2 mm walls, voxel from the wall, `close_mm` 0.6, a 3 mm base 4 mm round the feet in `0xff3c3c3c` (when `SONA_PRINT_BASE` is set), at most 24,000,000 grid points. NULL does nothing.

### sona_print_avatars

```c
sona_result sona_print_avatars(sona_avatar *const *avatars, uint32_t count, const sona_print_options *o, sona_print **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `avatars` | `sona_avatar *const *` | The avatars, `count` of them | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `o` | `const sona_print_options *` | The options, a [`sona_print_options`](reference/fields.md#sona_print_options) | `NULL`: the defaults |
| `out` | `sona_print **` | Receives the new solid | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [3D print export](guides/print3d.md)):

```c
sona_play_options pl = { 0, 1.0f, 1.25f };          /* no loop, speed 1, from 1.25 s */
sona_avatar_play(a, "GenericWave", &pl);
sona_update(ctx, 0, NULL, NULL);
sona_avatar_stop(a);
sona_update(ctx, 0, NULL, NULL);
sona_print_avatars(&a, 1, &opts, &print);
```

One solid from `count` READY avatars of one ctx, as posed by the last `sona_update`, in their placements. To print a clip frame: `sona_avatar_play` with `from` at the time, `sona_update`, `sona_avatar_stop`, `sona_update`. NULL `o`: the defaults. `SONA_E_NOT_READY`, `SONA_E_ARGUMENT` (NULL arguments, bad options, two ctxs), `SONA_E_NOT_FOUND` (nothing with area), `SONA_E_LIMIT` (no grid fits `max_voxels`), `SONA_E_MEMORY`.

### sona_print_triangles

```c
sona_result sona_print_triangles(sona_ctx *ctx, const float *positions, uint32_t vertex_count, const uint32_t *indices,
                                 uint32_t triangle_count, const uint32_t *colours, const sona_print_options *o,
                                 sona_print **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | `NULL` allowed (below) |
| `positions` | `const float *` | Three floats a vertex | required |
| `vertex_count` | `uint32_t` | How many vertices `positions` holds | - |
| `indices` | `const uint32_t *` | Three vertex indexes a triangle | required |
| `triangle_count` | `uint32_t` | How many triangles `indices` holds | - |
| `colours` | `const uint32_t *` | A colour per vertex, 0xAARRGGBB; NULL: none | `NULL`: none |
| `o` | `const sona_print_options *` | The options, a [`sona_print_options`](reference/fields.md#sona_print_options) | required |
| `out` | `sona_print **` | Receives the new solid | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

The same from any triangles, in metres in the SDK's frame, any winding, colours 0xAARRGGBB per vertex or NULL. `ctx` may be NULL (malloc).

### sona_print_get

```c
sona_result sona_print_get(const sona_print *p, sona_print_mesh *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `const sona_print *` | The solid | required |
| `out` | `sona_print_mesh *` | Receives the [`sona_print_mesh`](reference/fields.md#sona_print_mesh) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The solid: counts, shells, volume, area, positions, sRGB colours per vertex, indices (counter-clockwise from outside), bounds (`lo[2]` is 0, centred on x = y = 0) and the scale, wall and grid used. Pointers live as long as `p`. `SONA_E_ARGUMENT` when `out->size` is too small.

### sona_print_encode

```c
sona_result sona_print_encode(sona_print *p, uint32_t format, const uint8_t **out, size_t *out_len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_print *` | The solid | required |
| `format` | `uint32_t` | The file format to write | - |
| `out` | `const uint8_t **` | Receives the bytes; they belong to the solid | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Binary STL, or 3MF with a colour per vertex (the materials extension's colour group). The bytes live in `p` until the next encode or `sona_print_free`. Deterministic.

### sona_print_free

```c
void sona_print_free(sona_print *p);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_print *` | The solid | required |

**Returns** Nothing.

NULL does nothing.

### sona_print_check

```c
sona_result sona_print_check(const float *positions, uint32_t vertex_count, const uint32_t *indices,
                             uint32_t triangle_count, sona_print_report *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `positions` | `const float *` | Three floats a vertex | required |
| `vertex_count` | `uint32_t` | How many vertices `positions` holds | - |
| `indices` | `const uint32_t *` | Three vertex indexes a triangle | required |
| `triangle_count` | `uint32_t` | How many triangles `indices` holds | - |
| `out` | `sona_print_report *` | Receives the [`sona_print_report`](reference/fields.md#sona_print_report) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Checks any mesh: edges with one or more than two triangles, inconsistent winding, pinched vertices, degenerate and crossing triangles, shells, Euler characteristic, volume, area and bounds; `ok` is 1 when it would print as one closed solid per shell. Pure, no ctx.

## Other players' avatars by id

Friends, lobby members and leaderboard rows by id: a gamertag (`Your Gamertag`, `gt:Your Gamertag`, `Name#1234`), a public slot (`a:<account id>/<slot>`) or a display case (`w:<case key>`), looked up through the accounts server's routes (`/sona/v1/gamertag/<gt>?client=<app>`, `/sona/a/<account>/<slot>`, `/sona/w/<key>` with `/sona/wv/<key>` for its version). Kept in memory and in `<cache_dir>/players.cache`, asked again after `refresh_s`, at most `per_hour` requests in any hour and `in_flight` at once, backed off on 429, 5xx and no network; the last known look, else the placeholder, when they fail. No ctx; owner thread only. The guide: [Other players' avatars by id](guides/players.md).

`sona_players_config` (136 bytes, 96 with 4-byte pointers): `{size, max_players, refresh_s, per_hour, in_flight, timeout_ms, host, client, http, cache_dir, placeholder, clock, clock_user, allocator, reserved[8]}`. `sona_player_look` (1200 bytes): `{size, state, error, placeholder, fetched_at, checked_at, next_check, manifest[1000], version[33], name[95], reserved[8]}`. `sona_player_event` (112 bytes): `{size, type, code, reserved, id[96]}`. `sona_players_stats` (96 bytes). States: `SONA_PLAYER_WAITING`, `_FRESH`, `_STALE`, `_PRIVATE`, `_NONE`. Events: `SONA_PLAYER_EVENT_LOOK`, `_GONE`, `_FAILED`. `sona_players` is opaque.

### sona_players_defaults

```c
void sona_players_defaults(sona_players_config *c);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `c` | `sona_players_config *` | The [`sona_players_config`](reference/fields.md#sona_players_config) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_players_config x_players_config;
memset(&x_players_config, 0, sizeof x_players_config);
x_players_config.size = sizeof x_players_config;
sona_players_defaults(&x_players_config);
```

Zeroes the config and sets `size`; zero fields take the defaults (2048 looks, an interval of 600 s, 60 an hour, 4 at once, a timeout of 15 s). NULL does nothing.

### sona_players_open

```c
sona_result sona_players_open(const sona_players_config *c, sona_players **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `c` | `const sona_players_config *` | The options, a [`sona_players_config`](reference/fields.md#sona_players_config) | required |
| `out` | `sona_players **` | Receives the new players lookup | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

Reads the cache file when `cache_dir` is set (a file that does not decode is ignored). `SONA_E_ARGUMENT` for a config with a small `size`, a host that is not `http(s)://` (release builds: `https://` or loopback `http://`), `in_flight` over 16, or a placeholder that is not a manifest; `SONA_E_IO` when `cache_dir` cannot be made; `SONA_E_UNSUPPORTED` with no HTTP layer.

### sona_players_close

```c
void sona_players_close(sona_players *p);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |

**Returns** Nothing.

Writes the cache file when it changed; answers still in flight are dropped. NULL does nothing.

### sona_players_watch

```c
sona_result sona_players_watch(sona_players *p, const char *const *ids, uint32_t count, int32_t priority);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |
| `ids` | `const char *const *` | Player ids, `count` of them | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `priority` | `int32_t` | Higher is looked up sooner | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_APP` ([what each means](troubleshooting.md#error-codes)).

Watches ids and returns at once; known looks are there now, the rest are asked by priority (higher first), then in the order first watched, one request per distinct id. `SONA_E_ARGUMENT` when an id is not an id (it becomes `SONA_PLAYER_NONE`; the others are watched), `SONA_E_LIMIT` past `max_players`.

### sona_players_unwatch

```c
void sona_players_unwatch(sona_players *p, const char *const *ids, uint32_t count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |
| `ids` | `const char *const *` | Player ids, `count` of them | required |
| `count` | `uint32_t` | How many entries the array holds | - |

**Returns** Nothing.

Stops asking; looks stay cached. `ids` NULL: every id.

### sona_players_refresh

```c
sona_result sona_players_refresh(sona_players *p, const char *const *ids, uint32_t count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |
| `ids` | `const char *const *` | Player ids, `count` of them | required |
| `count` | `uint32_t` | How many entries the array holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

Asks again now, inside the limits. `ids` NULL: every watched id. `SONA_E_NOT_FOUND` for an id not watched.

### sona_players_update

```c
uint32_t sona_players_update(sona_players *p);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |

**Returns** `uint32_t`.

Each frame: takes answers, sends due requests, writes the cache file (at most every 2 s). Returns the events queued.

### sona_players_poll

```c
int sona_players_poll(sona_players *p, sona_player_event *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |
| `out` | `sona_player_event *` | Receives the [`sona_player_event`](reference/fields.md#sona_player_event) | required |

**Returns** `int`.

1 when an event was written, 0 when there are none. `LOOK` when a look arrives or changes, `GONE` when it turns private or goes, `FAILED` once when checks start failing (`code`: `SONA_E_IO`, `SONA_E_LIMIT`, `SONA_E_GATE`, `SONA_E_CORRUPT`, `SONA_E_APP`).

### sona_players_look

```c
sona_result sona_players_look(sona_players *p, const char *id, sona_player_look *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |
| `id` | `const char *` | An id as text | required |
| `out` | `sona_player_look *` | Receives the [`sona_player_look`](reference/fields.md#sona_player_look) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

Always fills `out` with a look to draw (the placeholder when nothing is known). `SONA_E_NOT_FOUND` for an id never watched nor cached, `SONA_E_ARGUMENT` for one that is not an id.

### sona_players_forget

```c
sona_result sona_players_forget(sona_players *p, const char *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_players *` | The players lookup | required |
| `id` | `const char *` | An id as text | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

Drops the id's look from memory and, at the next write, from the cache file, and stops watching it. `SONA_E_NOT_FOUND` when there was none.

### sona_players_stats_get

```c
sona_result sona_players_stats_get(const sona_players *p, sona_players_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `const sona_players *` | The players lookup | required |
| `out` | `sona_players_stats *` | Receives the [`sona_players_stats`](reference/fields.md#sona_players_stats) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Looks kept, ids watched, requests in flight and due, and counts since open: requests, changed, the same, 304s, gone, failed, read from disk, disk writes, waits for `per_hour`; `paused_until`.

### sona_players_placeholder

```c
void sona_players_placeholder(uint8_t out[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required |

**Returns** Nothing.

**Example**:

```c
uint8_t x_out[SONA_MANIFEST_BYTES];
memset(x_out, 0, sizeof x_out);
sona_players_placeholder(x_out);
```

The built-in placeholder: the site's faceless grey mannequin, nothing worn.

## Avatar state, network sync and replays

An avatar's whole state as a blob put back exactly; a stream that carries one avatar to a receiver in a few bytes a tick, shown on a puppet with the same pose bits on every receiver fed the same packets; and recordings played at any time, forwards or back. The guide, with what a state holds, the formats and the measured sizes, is [State, network sync, replays](guides/netstate.md). All of it runs on the owner thread.

Structs (no pointers: one layout for 4- and 8-byte pointers): `sona_state_info` (56 bytes) `{size, version, has_look, parts, clock, reserved[8]}`; `sona_state_status` (40) `{size, mode, pending, missing, applied, reserved[5]}`; `sona_net_options` (48) `{size, tick_hz, history, full_after, reserved[8]}`; `sona_net_look` (1092) `{size, version, kind, manifest[1000], id[64], reserved[4]}`; `sona_net_stats` (64) `{size, packets, bytes, full, newest, oldest, last_bytes, acked, reserved[8]}`; `sona_record_options` (48) `{size, tick_hz, keyframe_ticks, keep_seconds, reserved[8]}`; `sona_replay_info` (60) `{size, tracks, tick_hz, first_tick, last_tick, frames, seconds, reserved[8]}`. `sona_net_sender`, `sona_net_receiver`, `sona_recorder` and `sona_replay` are opaque. Flags and codes: `SONA_STATE_NO_LOOK`; `SONA_STATE_PART_FADE`, `_LAYERS`, `_OVERRIDES`, `_IK`, `_IDLE`, `_QUEUE`; `SONA_STATE_MISSING_CLIP`, `_BLEND`, `_MACHINE`, `_GROUND`, `_POSE`, `_LOOK`; `SONA_STATE_LIVE`, `_WAITING`, `_PUPPET`; `SONA_NET_LOOK_NONE`, `_MANIFEST`, `_ID`.

### sona_avatar_save_state

```c
sona_result sona_avatar_save_state(sona_avatar *a, uint32_t flags, uint8_t **out, size_t *out_len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none |
| `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Avatar state, network sync and replays](guides/netstate.md)):

```c
uint8_t *blob; size_t n;
sona_avatar_save_state(a, 0, &blob, &n);           /* 0.4 to 2 KB with the manifest; sona_free */

sona_avatar *b;
sona_avatar_add_state(other_ctx, blob, n, NULL, &b);   /* a new avatar with the blob's look and state */
/* or, into an avatar that already has the look: sona_avatar_load_state(b, blob, n); */
```

The blob of a READY avatar's state, freed with `sona_free`; `SONA_STATE_NO_LOOK` leaves the manifest out. `SONA_E_NOT_READY` before READY, `SONA_E_ARGUMENT` for an unknown flag.

### sona_avatar_load_state

```c
sona_result sona_avatar_load_state(sona_avatar *a, const void *blob, size_t len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `blob` | `const void *` | The bytes of a saved state | required |
| `len` | `size_t` | How many bytes there are | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Avatar state, network sync and replays](guides/netstate.md)):

```c
uint8_t *blob; size_t n;
sona_avatar_save_state(a, 0, &blob, &n);           /* 0.4 to 2 KB with the manifest; sona_free */

sona_avatar *b;
sona_avatar_add_state(other_ctx, blob, n, NULL, &b);   /* a new avatar with the blob's look and state */
/* or, into an avatar that already has the look: sona_avatar_load_state(b, blob, n); */
```

Puts a saved state on `a` at the next `sona_update` once it is READY and the clips the state needs are loaded; until then the avatar holds still (`SONA_STATE_WAITING`). Afterwards the same updates give the same pose bits as the saved avatar would have. A look that differs is reported (`SONA_STATE_MISSING_LOOK`), not refused. `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED` for a newer format. Ends puppet mode.

### sona_avatar_add_state

```c
sona_result sona_avatar_add_state(sona_ctx *ctx, const void *blob, size_t len, const sona_add_options *opts,
                                  sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `blob` | `const void *` | The bytes of a saved state | required |
| `len` | `size_t` | How many bytes there are | - |
| `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](reference/fields.md#sona_add_options) | required |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Avatar state, network sync and replays](guides/netstate.md)):

```c
uint8_t *blob; size_t n;
sona_avatar_save_state(a, 0, &blob, &n);           /* 0.4 to 2 KB with the manifest; sona_free */

sona_avatar *b;
sona_avatar_add_state(other_ctx, blob, n, NULL, &b);   /* a new avatar with the blob's look and state */
/* or, into an avatar that already has the look: sona_avatar_load_state(b, blob, n); */
```

A new avatar with the blob's look, then `sona_avatar_load_state`. `opts` gives the visibility and priority (its clip is ignored). `SONA_E_ARGUMENT` for a blob without a look.

### sona_state_info_get

```c
sona_result sona_state_info_get(const void *blob, size_t len, sona_state_info *out, uint8_t manifest[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `blob` | `const void *` | The bytes of a saved state | required |
| `len` | `size_t` | How many bytes there are | - |
| `out` | `sona_state_info *` | Receives the [`sona_state_info`](reference/fields.md#sona_state_info) | required |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | `NULL` allowed (below) |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

What a blob holds, without a ctx; `manifest` (may be NULL) gets the look when there is one.

### sona_avatar_state_status

```c
sona_result sona_avatar_state_status(const sona_avatar *a, sona_state_status *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_state_status *` | Receives the [`sona_state_status`](reference/fields.md#sona_state_status) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_state_status x_state_status;
memset(&x_state_status, 0, sizeof x_state_status);
x_state_status.size = sizeof x_state_status;
sona_result result = sona_avatar_state_status(avatar, &x_state_status);
if (result != SONA_OK) printf("sona_avatar_state_status: %s\n", sona_result_name(result));
```

`mode` (`SONA_STATE_LIVE`, `_WAITING`, `_PUPPET`), `pending` (a clip of the last state is still loading), `missing` (`SONA_STATE_MISSING_*` of the last state put on) and how many states were put on. All zero for an avatar the module never touched.

### sona_avatar_puppet

```c
sona_result sona_avatar_puppet(sona_avatar *a, int on);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `on` | `int` | 1 on, 0 off | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_puppet(avatar, 1);
if (result != SONA_OK) printf("sona_avatar_puppet: %s\n", sona_result_name(result));
```

A puppet's clocks stand still: its clip, layers, fades, moves, IK smoothing and idle change only when a state is put on it. `sona_net_drive` and `sona_replay_drive` make an avatar a puppet; off, it plays on from the last state.

### sona_net_defaults

```c
void sona_net_defaults(sona_net_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_net_options *` | The [`sona_net_options`](reference/fields.md#sona_net_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_net_options x_net_options;
memset(&x_net_options, 0, sizeof x_net_options);
x_net_options.size = sizeof x_net_options;
sona_net_defaults(&x_net_options);
```

A rate of 30 ticks a second, 64 ticks of history, a full state after 30 ticks without an acknowledgement.

### sona_net_sender_create

```c
sona_result sona_net_sender_create(sona_ctx *ctx, const sona_net_options *o, sona_net_sender **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_net_options *` | The options, a [`sona_net_options`](reference/fields.md#sona_net_options) | `NULL` allowed (below) |
| `out` | `sona_net_sender **` | Receives the new sender | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

One stream's sending end. `o` may be NULL. `SONA_E_ARGUMENT` for a `tick_hz` of 0 or over 1000, or a `history` outside 8..1024.

### sona_net_sender_destroy

```c
void sona_net_sender_destroy(sona_net_sender *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_net_sender *` | The sender | required |

**Returns** Nothing.

Frees the sender.

### sona_net_sender_look

```c
sona_result sona_net_sender_look(sona_net_sender *s, const char *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_net_sender *` | The sender | required |
| `id` | `const char *` | An id as text | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

NULL (the default): the stream sends the avatar's manifest, and again whenever it changes. An id of 1 to 63 bytes sends that instead. Either goes along until a packet carrying it is acknowledged.

### sona_net_write

```c
sona_result sona_net_write(sona_net_sender *s, sona_avatar *a, uint32_t tick, uint8_t *out, size_t cap, size_t *len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_net_sender *` | The sender | required |
| `a` | `sona_avatar *` | The avatar | required |
| `tick` | `uint32_t` | The tick's number | - |
| `out` | `uint8_t *` | Receives the bytes | required |
| `cap` | `size_t` | How many bytes `out` holds | - |
| `len` | `size_t *` | Receives how many bytes were written | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

One packet of `a`'s state at `tick`, coded against the newest acknowledged tick (or full). Ticks rise (`SONA_E_ARGUMENT` otherwise). `SONA_E_LIMIT` when `cap` is too small, with `*len` the size needed; `SONA_E_NOT_READY` before READY.

### sona_net_ack

```c
void sona_net_ack(sona_net_sender *s, uint32_t tick);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_net_sender *` | The sender | required |
| `tick` | `uint32_t` | The tick's number | - |

**Returns** Nothing.

The receiver holds `tick`. Ticks the sender no longer keeps are ignored.

### sona_net_receiver_create

```c
sona_result sona_net_receiver_create(sona_ctx *ctx, const sona_net_options *o, sona_net_receiver **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_net_options *` | The options, a [`sona_net_options`](reference/fields.md#sona_net_options) | `NULL` allowed (below) |
| `out` | `sona_net_receiver **` | Receives the new receiver | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

One stream's receiving end. `o` may be NULL (the defaults).

### sona_net_receiver_destroy

```c
void sona_net_receiver_destroy(sona_net_receiver *r);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_net_receiver *` | The receiver | required |

**Returns** Nothing.

Frees the receiver.

### sona_net_read

```c
sona_result sona_net_read(sona_net_receiver *r, const void *packet, size_t len, uint32_t *ack);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_net_receiver *` | The receiver | required |
| `packet` | `const void *` | One packet as it arrived | required |
| `len` | `size_t` | How many bytes there are | - |
| `ack` | `uint32_t *` | Receives the newest tick the sender has seen acknowledged | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

Decodes and keeps one packet; `*ack` is the tick to send back. Late and repeated packets are fine. `SONA_E_NOT_FOUND` when its baseline is no longer held, `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED`.

### sona_net_receiver_look

```c
sona_result sona_net_receiver_look(const sona_net_receiver *r, sona_net_look *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_net_receiver *` | The receiver | required |
| `out` | `sona_net_look *` | Receives the [`sona_net_look`](reference/fields.md#sona_net_look) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The newest look the stream carried: `kind` `SONA_NET_LOOK_MANIFEST` with `manifest`, `SONA_NET_LOOK_ID` with `id`, or `SONA_NET_LOOK_NONE` before one arrives; `version` rises with each change.

### sona_net_drive

```c
sona_result sona_net_drive(sona_net_receiver *r, sona_avatar *a, double tick);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_net_receiver *` | The receiver | required |
| `a` | `sona_avatar *` | The avatar | required |
| `tick` | `double` | The tick to show, fractions between two | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

Shows `tick` on `a`, which becomes a puppet: a held tick as it is, a fraction between two held ticks as their blend, before the oldest the oldest, past the newest the newest. `SONA_E_NOT_READY` before any state arrived.

### sona_net_sender_stats

```c
sona_result sona_net_sender_stats(const sona_net_sender *s, sona_net_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_net_sender *` | The sender | required |
| `out` | `sona_net_stats *` | Receives the [`sona_net_stats`](reference/fields.md#sona_net_stats) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Packets and bytes written, those without a baseline (`full`), the last packet's size and the newest acknowledged tick.

### sona_net_receiver_stats

```c
sona_result sona_net_receiver_stats(const sona_net_receiver *r, sona_net_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_net_receiver *` | The receiver | required |
| `out` | `sona_net_stats *` | Receives the [`sona_net_stats`](reference/fields.md#sona_net_stats) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Packets and bytes read, packets refused for want of a baseline (`full`), the newest and oldest ticks held.

### sona_record_defaults

```c
void sona_record_defaults(sona_record_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_record_options *` | The [`sona_record_options`](reference/fields.md#sona_record_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_record_options x_record_options;
memset(&x_record_options, 0, sizeof x_record_options);
x_record_options.size = sizeof x_record_options;
sona_record_defaults(&x_record_options);
```

A rate of 30 ticks a second, a keyframe every 30 ticks, everything kept.

### sona_recorder_create

```c
sona_result sona_recorder_create(sona_ctx *ctx, const sona_record_options *o, sona_recorder **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_record_options *` | The options, a [`sona_record_options`](reference/fields.md#sona_record_options) | required |
| `out` | `sona_recorder **` | Receives the new recorder | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

`keep_seconds` above 0 keeps only about the last that many seconds (whole keyframe spans), for kill-cams.

### sona_recorder_destroy

```c
void sona_recorder_destroy(sona_recorder *r);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_recorder *` | The recorder | required |

**Returns** Nothing.

Frees the recorder and what it captured.

### sona_recorder_track

```c
sona_result sona_recorder_track(sona_recorder *r, sona_avatar *a, const char *name, uint32_t *track);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_recorder *` | The recorder | required |
| `a` | `sona_avatar *` | The avatar | required |
| `name` | `const char *` | The track's name, at most 63 bytes; may be NULL | `NULL`: none |
| `track` | `uint32_t *` | Receives the track's index | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Records `a` from the next capture on, as track `*track`. At most 256 tracks; `name` at most 63 bytes.

### sona_recorder_capture

```c
sona_result sona_recorder_capture(sona_recorder *r, uint32_t tick);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_recorder *` | The recorder | required |
| `tick` | `uint32_t` | The tick's number | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Every track's state at `tick` (rising). A track whose avatar is not READY or was removed is left out of that capture.

### sona_recorder_save

```c
sona_result sona_recorder_save(sona_recorder *r, uint8_t **out, size_t *out_len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_recorder *` | The recorder | required |
| `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

The file's bytes, freed with `sona_free`. Recording can go on after.

### sona_replay_open

```c
sona_result sona_replay_open(sona_ctx *ctx, const void *bytes, size_t len, sona_replay **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `bytes` | `const void *` | The file's bytes | required |
| `len` | `size_t` | How many bytes there are | - |
| `out` | `sona_replay **` | Receives the new replay | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

Keeps a copy of the bytes. `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED` for a newer format.

### sona_replay_close

```c
void sona_replay_close(sona_replay *p);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_replay *` | The replay | required |

**Returns** Nothing.

Frees the replay.

### sona_replay_info_get

```c
sona_result sona_replay_info_get(const sona_replay *p, sona_replay_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `const sona_replay *` | The replay | required |
| `out` | `sona_replay_info *` | Receives the [`sona_replay_info`](reference/fields.md#sona_replay_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The replay's tracks, tick rate, first and last tick, the captures it holds and its length in seconds.

### sona_replay_track

```c
sona_result sona_replay_track(const sona_replay *p, uint32_t track, uint8_t manifest[SONA_MANIFEST_BYTES], char name[64],
                              float *from, float *to);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `const sona_replay *` | The replay | required |
| `track` | `uint32_t` | A track's index | - |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required |
| `name` | `char [64]` | Receives the track's name | required |
| `from` | `float *` | Receives the track's first time, seconds | required |
| `to` | `float *` | Receives the track's last time, seconds | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

A track's look, name and span in seconds from the replay's start; each output may be NULL.

### sona_replay_drive

```c
sona_result sona_replay_drive(sona_replay *p, uint32_t track, sona_avatar *a, double seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_replay *` | The replay | required |
| `track` | `uint32_t` | A track's index | - |
| `a` | `sona_avatar *` | The avatar | required |
| `seconds` | `double` | The time to sample, seconds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

Shows the track at `seconds` from the replay's start on `a`, which becomes a puppet, blending the two frames around it. Any order: the same time always shows the same pose bits.

## Art styles

Toon (cel bands of the key light and a hard highlight), flat (the colours, unlit) and silhouette (one colour), each with an optional inverted-hull outline, per avatar or for every avatar a renderer draws. With no style set every picture is the original, byte for byte. Drawn on Vulkan and GL; other backends answer `SONA_E_UNSUPPORTED` and draw the original. The guide: [Art styles](guides/styles.md).

`sona_style` (48 bytes): `{size, kind, flags, bands, shade, highlight, outline_px, outline, colour, reserved[3]}`. Kinds: `SONA_STYLE_ORIGINAL` (0), `SONA_STYLE_TOON`, `SONA_STYLE_FLAT`, `SONA_STYLE_SILHOUETTE`. Flags: `SONA_STYLE_OUTLINE`, `SONA_STYLE_OVERRIDE` (a renderer's style only).

### sona_style_defaults

```c
void sona_style_defaults(sona_style *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_style *` | The [`sona_style`](reference/fields.md#sona_style) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Art styles](guides/styles.md)):

```c
void sona_style_defaults(sona_style *s);
sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s);
sona_result sona_avatar_style(const sona_avatar *a, sona_style *out);
sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s);
sona_result sona_renderer_style(const sona_renderer *r, sona_style *out);
```

`size` set, the original look, no flags, 3 bands, shade 0.55, highlight 0.35, a 2 px outline in `0xff141414`, silhouette colour `0xff1e2430`. NULL does nothing.

### sona_avatar_set_style

```c
sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `s` | `const sona_style *` | A [`sona_style`](reference/fields.md#sona_style) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Art styles](guides/styles.md)):

```c
void sona_style_defaults(sona_style *s);
sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s);
sona_result sona_avatar_style(const sona_avatar *a, sona_style *out);
sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s);
sona_result sona_renderer_style(const sona_renderer *r, sona_style *out);
```

The avatar's own style from the next frame; NULL, or the original look without an outline, clears it. `SONA_E_ARGUMENT` for a parameter out of range, an unknown kind or flag, `SONA_STYLE_OVERRIDE`, a non-zero reserved word or a `size` below `sizeof(sona_style)`; nothing changes then.

### sona_avatar_style

```c
sona_result sona_avatar_style(const sona_avatar *a, sona_style *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_style *` | Receives the [`sona_style`](reference/fields.md#sona_style) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Art styles](guides/styles.md)):

```c
void sona_style_defaults(sona_style *s);
sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s);
sona_result sona_avatar_style(const sona_avatar *a, sona_style *out);
sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s);
sona_result sona_renderer_style(const sona_renderer *r, sona_style *out);
```

The avatar's own style, or `sona_style_defaults` when it has none.

### sona_renderer_set_style

```c
sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `s` | `const sona_style *` | A [`sona_style`](reference/fields.md#sona_style) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Art styles](guides/styles.md)):

```c
void sona_style_defaults(sona_style *s);
sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s);
sona_result sona_avatar_style(const sona_avatar *a, sona_style *out);
sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s);
sona_result sona_renderer_style(const sona_renderer *r, sona_style *out);
```

The style of every avatar this renderer draws that has none of its own (with `SONA_STYLE_OVERRIDE`, of every avatar), from the next `sona_draw` or `sona_snapshot`. NULL, or the original look with no flags, clears it. `SONA_E_UNSUPPORTED` (nothing changes) on a backend without styles; `SONA_E_ARGUMENT` as `sona_avatar_set_style`.

### sona_renderer_style

```c
sona_result sona_renderer_style(const sona_renderer *r, sona_style *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_renderer *` | The renderer | required |
| `out` | `sona_style *` | Receives the [`sona_style`](reference/fields.md#sona_style) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Art styles](guides/styles.md)):

```c
void sona_style_defaults(sona_style *s);
sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s);
sona_result sona_avatar_style(const sona_avatar *a, sona_style *out);
sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s);
sona_result sona_renderer_style(const sona_renderer *r, sona_style *out);
```

The renderer's style, or the defaults when none. `SONA_E_UNSUPPORTED`, with `out` the defaults, when its backend draws no styles.

## Player screens: the quick creator and the wardrobe picker

Two ready-made screens a game opens and gets an avatar back from: the quick creator (eight generated looks, pick one, change one thing, done) and the wardrobe picker (an outfit for this match from the player's own wardrobe, or the catalogue under the host's filter, with a live try-on). The host draws a screen from its node list; input arrives as actions from any device. The guide, with the flow, the controls, the drawing contract and the numbers, is [Quick creator and wardrobe](guides/quick-creator.md).

Structs: `sona_screen_event` (48 bytes), `sona_screen_theme` (96, 88 with 4-byte pointers), `sona_screen_node` (112, 92), `sona_quick_options` (96, 72), `sona_wardrobe_options` (128, 84), `sona_screen_stats` (108). `sona_screen` is opaque. A screen is used from the ctx's owner thread and destroyed before its ctx.

### sona_screen_theme_defaults

```c
void sona_screen_theme_defaults(sona_screen_theme *t, uint32_t preset);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_screen_theme *` | The [`sona_screen_theme`](reference/fields.md#sona_screen_theme) to fill with the defaults | required |
| `preset` | `uint32_t` | Which preset, one of the header's constants for it | - |

**Returns** Nothing.

**Example**:

```c
sona_screen_theme x_screen_theme;
memset(&x_screen_theme, 0, sizeof x_screen_theme);
x_screen_theme.size = sizeof x_screen_theme;
sona_screen_theme_defaults(&x_screen_theme, 0);
```

`SONA_THEME_DARK`, `SONA_THEME_LIGHT` (the editor module's own palettes) or `SONA_THEME_CONTRAST` (black, white and yellow, with `SONA_THEME_HIGH_CONTRAST` set). `size` set, scale 1, corner 10.

### sona_quick_defaults

```c
void sona_quick_defaults(sona_quick_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_quick_options *` | The [`sona_quick_options`](reference/fields.md#sona_quick_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_quick_options x_quick_options;
memset(&x_quick_options, 0, sizeof x_quick_options);
x_quick_options.size = sizeof x_quick_options;
sona_quick_defaults(&x_quick_options);
```

`size` set, seed 1, 8 looks, both bodies, no flags. Set `catalogue` before opening.

### sona_quick_open

```c
sona_result sona_quick_open(sona_ctx *ctx, const sona_quick_options *o, sona_screen **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_quick_options *` | The options, a [`sona_quick_options`](reference/fields.md#sona_quick_options) | required |
| `out` | `sona_screen **` | Receives the new screen | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

The quick creator; its eight looks start building at once, hidden from `sona_draw`. `SONA_E_ARGUMENT` without a catalogue, for `looks` outside 2..8 or `body` over 2; `SONA_E_NOT_FOUND` when the catalogue after the filter has no hair, clothes or shoes for a body it needs.

### sona_quick_look

```c
sona_result sona_quick_look(const sona_quick_options *o, uint32_t shuffle, uint32_t index, uint8_t manifest[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_quick_options *` | The options, a [`sona_quick_options`](reference/fields.md#sona_quick_options) | required |
| `shuffle` | `uint32_t` | How many times the player asked for new looks | - |
| `index` | `uint32_t` | Which one, from 0 | - |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The quick creator and the wardrobe picker](guides/quick-creator.md)):

```c
/* catalogue, filter, seed set */
typedef struct quick_hook {
  sona_quick_options o;
  uint64_t first;
} quick_hook;
static int quick_looks(void *user, uint64_t seed, uint32_t index, uint8_t manifest[SONA_MANIFEST_BYTES]) {
  quick_hook *h = (quick_hook *)user;
  return sona_quick_look(&h->o, (uint32_t)(seed - h->first), index, manifest) == SONA_OK;
}
/* sona_editor_options: .seed = h.first = h.o.seed, .look = quick_looks, .look_user = &h, the same .filter */
```

Look `index` of the set the seed and `shuffle` (X presses so far) make, without a screen or a ctx: the same bytes the screen shows. A screen re-rolls a look whose items are missing from the sources; that one then differs. The editor module's `look` hook takes it in one line (the guide shows it).

### sona_wardrobe_defaults

```c
void sona_wardrobe_defaults(sona_wardrobe_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_wardrobe_options *` | The [`sona_wardrobe_options`](reference/fields.md#sona_wardrobe_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [The quick creator and the wardrobe picker](guides/quick-creator.md)):

```c
sona_wardrobe_options wo;
sona_wardrobe_defaults(&wo);
wo.manifest = my_avatar;            /* the player's own, SONA_MANIFEST_BYTES; only clothes change */
wo.catalogue = cat;
wo.owned = owned; wo.owned_count = n;   /* the player's wardrobe; NULL: the catalogue's items for this body */
wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names;   /* saved outfits, first tab */
wo.filter = my_content_filter;
wo.title = "Dress for the match";
sona_wardrobe_open(ctx, &wo, &s);
```

`size` set, `flags` `SONA_WARDROBE_STOCK`. Set `manifest` and `catalogue` before opening.

### sona_wardrobe_open

```c
sona_result sona_wardrobe_open(sona_ctx *ctx, const sona_wardrobe_options *o, sona_screen **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_wardrobe_options *` | The options, a [`sona_wardrobe_options`](reference/fields.md#sona_wardrobe_options) | required |
| `out` | `sona_screen **` | Receives the new screen | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The quick creator and the wardrobe picker](guides/quick-creator.md)):

```c
sona_wardrobe_options wo;
sona_wardrobe_defaults(&wo);
wo.manifest = my_avatar;            /* the player's own, SONA_MANIFEST_BYTES; only clothes change */
wo.catalogue = cat;
wo.owned = owned; wo.owned_count = n;   /* the player's wardrobe; NULL: the catalogue's items for this body */
wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names;   /* saved outfits, first tab */
wo.filter = my_content_filter;
wo.title = "Dress for the match";
sona_wardrobe_open(ctx, &wo, &s);
```

The wardrobe picker on the player's manifest. Its lists, outfits and names are copied. Only clothes change. `SONA_E_ARGUMENT` without a manifest or catalogue (or a count without its array), `SONA_E_MANIFEST` for a manifest that does not parse.

### sona_screen_destroy

```c
void sona_screen_destroy(sona_screen *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |

**Returns** Nothing.

Removes the screen's avatars from the ctx and frees it. NULL does nothing.

### sona_screen_kind

```c
uint32_t sona_screen_kind(const sona_screen *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |

**Returns** `uint32_t`.

`SONA_SCREEN_KIND_QUICK` or `SONA_SCREEN_KIND_WARDROBE`; 0 for NULL.

### sona_screen_layout

```c
sona_result sona_screen_layout(sona_screen *s, uint32_t width, uint32_t height);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The host's size in pixels, 64 to 16384 a side: a wide layout when `width >= height`, a tall one otherwise. Default 1280 x 720. May change at any time.

### sona_screen_set_theme

```c
sona_result sona_screen_set_theme(sona_screen *s, const sona_screen_theme *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `t` | `const sona_screen_theme *` | A [`sona_screen_theme`](reference/fields.md#sona_screen_theme) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Copies the theme; the next nodes use it.

### sona_screen_input

```c
sona_result sona_screen_input(sona_screen *s, const sona_screen_event *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `in` | `const sona_screen_event *` | A [`sona_screen_event`](reference/fields.md#sona_screen_event) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

One event: `SONA_INPUT_PRESS` and `_RELEASE` of a `sona_screen_action`, pointer moves, presses and releases, scrolls, and the turn axis. Held directions and tabs repeat by themselves (after a set 0.36 s, then every 0.085 s) until released. `SONA_E_ARGUMENT` for a bad event; a finished screen ignores input.

### sona_screen_update

```c
sona_screen_status sona_screen_update(sona_screen *s, double dt_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `dt_seconds` | `double` | Seconds since the last update | - |

**Returns** `sona_screen_status`.

Repeats, turning, the screen's avatars (a rebuilt one replaces the shown one when READY) and the screen's own timers. Call it after `sona_update`. Returns `SONA_SCREEN_RUNNING`, `_DONE`, `_CANCELLED` or `_FINE_TUNE`, and keeps returning a finished status. NULL: `_CANCELLED`.

### sona_screen_nodes

```c
uint32_t sona_screen_nodes(sona_screen *s, sona_screen_node *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `out` | `sona_screen_node *` | Receives the [`sona_screen_node`](reference/fields.md#sona_screen_node) | `NULL` allowed (below) |
| `cap` | `uint32_t` | How many entries `out` holds | `NULL` allowed (below) |

**Returns** `uint32_t`.

What to draw, in paint order, with roles, states, boxes in pixels, text and spoken labels; writes up to `cap` (`out` may be NULL) and returns how many there are. Strings live until the next call on the screen.

### sona_screen_announcement

```c
int sona_screen_announcement(sona_screen *s, char *out, size_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `out` | `char *` | Receives the text, NUL-terminated | required |
| `cap` | `size_t` | How many bytes `out` holds | - |

**Returns** `int`.

The oldest thing a screen reader should say (eight are kept): 1 when one was written (cut at `cap`), 0 when none.

### sona_screen_result

```c
sona_result sona_screen_result(const sona_screen *s, uint8_t manifest[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

The avatar the player has now. The quick creator answers `SONA_E_NOT_READY` before a pick; a cancelled wardrobe answers the manifest it opened with.

### sona_screen_stats_get

```c
void sona_screen_stats_get(const sona_screen *s, sona_screen_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `out` | `sona_screen_stats *` | Receives the [`sona_screen_stats`](reference/fields.md#sona_screen_stats) | required |

**Returns** Nothing.

Presses (repeats not counted), taps, changes, shuffles, focus moves, the seconds from open to finish and the presses of each action.

### sona_screen_owns

```c
int sona_screen_owns(const sona_screen *s, const sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `a` | `const sona_avatar *` | The avatar | required |

**Returns** `int`.

1 when `a` is one of the screen's avatars, for hosts that read `sona_poll_event`.

### sona_screen_view_avatar

```c
sona_avatar *sona_screen_view_avatar(const sona_screen *s, int32_t view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |

**Returns** `sona_avatar *`.

The avatar a node's `view` shows now, or NULL. It may change between frames.

### sona_screen_view_camera

```c
sona_result sona_screen_view_camera(sona_screen *s, int32_t view, uint32_t width, uint32_t height, sona_view *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `out` | `sona_view *` | Receives the [`sona_view`](reference/fields.md#sona_view) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

The view's camera for a `width` x `height` picture (the figure fills the height, turned by the player), for hosts that draw through the data API. `SONA_E_NOT_READY` before READY.

### sona_screen_view_draw

```c
sona_result sona_screen_view_draw(sona_renderer *r, sona_screen *s, int32_t view, const sona_target *target,
                                  const sona_draw_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `s` | `sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |
| `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](reference/fields.md#sona_target) | required |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

`sona_draw` of that view alone into `target`. `SONA_E_NOT_READY` while it has nothing to draw.

### sona_screen_view_snapshot

```c
sona_result sona_screen_view_snapshot(sona_renderer *r, sona_screen *s, int32_t view, uint32_t width, uint32_t height,
                                      const sona_draw_options *opts, uint8_t *rgba_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `s` | `sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |
| `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

`sona_snapshot` of that view alone, straight RGBA8.

## Picking

Which avatar, which body part or item, and which held prop is under a screen point or along a ray. On the CPU: each avatar's bounding sphere, then boxes per mesh and per run of 64 triangles made from the posed joints, then the triangles, skinned as `sona_pose_vertices` skins them (the scalar maths, so the same bits on every machine), back faces culled and the colour texture's alpha test applied as the draw does. A sprite avatar is met on its quad and the point on the picture goes on into the mesh at the baked turn. On the GPU (Vulkan, GL, GLES): an id buffer of the avatars the ray meets, one pixel, then the hit finished on the CPU on the mesh found. Call between `sona_update` calls, one thread at a time per ctx. The guide, with the cost measured over 1,000 avatars: [Picking](guides/picking.md).

`sona_pick_options` (56 bytes, 52 with 4-byte pointers): `{size, flags, max_distance, ignore_count, ignore, reserved[8]}`. Flags: `SONA_PICK_HIDDEN`, `SONA_PICK_CULLED`, `SONA_PICK_BACK_FACES`, `SONA_PICK_NO_ALPHA`, `SONA_PICK_NO_PROPS`, `SONA_PICK_BOUNDS`, `SONA_PICK_SPRITES_AS_MESH`. `sona_pick_hit` (176 bytes, 172): `{size, source, flags, avatar_id, avatar, part, section, mask, item[37], mesh, prop, triangle, joint, region, lod, distance, point[3], normal[3], bary[2], uv[2], reserved[8]}`; `source` is `SONA_PICK_SOURCE_MESH`, `_SPRITE` or `_BOUNDS`, `part` is `SONA_PICK_BODY`, `_ITEM` or `_PROP`, `flags` holds `SONA_PICK_HIT_BACK`, `_FACE` and `_GPU`, `region` is a `sona_body_region` (`SONA_REGION_HEAD` .. `SONA_REGION_RIGHT_FOOT`).

### sona_pick_defaults

```c
void sona_pick_defaults(sona_pick_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_pick_options *` | The [`sona_pick_options`](reference/fields.md#sona_pick_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_pick_options x_pick_options;
memset(&x_pick_options, 0, sizeof x_pick_options);
x_pick_options.size = sizeof x_pick_options;
sona_pick_defaults(&x_pick_options);
```

`size` set, everything else 0: visible avatars in view, front faces, the alpha test, props, no distance limit. NULL does nothing.

### sona_view_ray

```c
sona_result sona_view_ray(const sona_view *v, double x, double y, float origin[3], float dir[3]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `v` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `x` | `double` | A pixel from the picture's left | - |
| `y` | `double` | A pixel from the picture's top | - |
| `origin` | `float [3]` | Receives the ray's origin | required |
| `dir` | `float [3]` | Receives the ray's direction | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
float x_origin2[3];
memset(x_origin2, 0, sizeof x_origin2);
float x_dir3[3];
memset(x_dir3, 0, sizeof x_dir3);
sona_result result = sona_view_ray(&x_view, 128.0, 128.0, x_origin2, x_dir3);
if (result != SONA_OK) printf("sona_view_ray: %s\n", sona_result_name(result));
```

The ray through the point (x, y) of the view's picture, in pixels from its top left (a pixel's centre is + 0.5): `origin` on the near plane, `dir` of length 1. Pure. `SONA_E_ARGUMENT` for a view with no size or a NULL pointer.

### sona_pick_ray

```c
sona_result sona_pick_ray(sona_ctx *ctx, const float origin[3], const float dir[3], const sona_pick_options *o,
                          sona_pick_hit *hit);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `origin` | `const float [3]` | The ray's origin, world space | required |
| `dir` | `const float [3]` | The ray's direction, world space | required |
| `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](reference/fields.md#sona_pick_options) | `NULL` allowed (below) |
| `hit` | `sona_pick_hit *` | Receives what was hit | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
float x_origin[3];
memset(x_origin, 0, sizeof x_origin);
float x_dir2[3];
memset(x_dir2, 0, sizeof x_dir2);
sona_pick_options x_pick_options3;
memset(&x_pick_options3, 0, sizeof x_pick_options3);
x_pick_options3.size = sizeof x_pick_options3;
sona_pick_hit x_pick_hit4;
memset(&x_pick_hit4, 0, sizeof x_pick_hit4);
x_pick_hit4.size = sizeof x_pick_hit4;
sona_result result = sona_pick_ray(ctx, x_origin, x_dir2, &x_pick_options3, &x_pick_hit4);
if (result != SONA_OK) printf("sona_pick_ray: %s\n", sona_result_name(result));
```

The nearest hit. `SONA_OK` with `*hit` set, `SONA_E_NOT_FOUND` when nothing is hit (`*hit` then has `size` set and `mesh`, `prop` and `joint` at -1). `o` may be NULL. `dir` need not be unit length; `distance` is in metres along it. Sprites are met as the last `sona_update`'s view faces them. `SONA_E_ARGUMENT` for a zero or non-finite ray, a `size` too small, a negative `max_distance` or `ignore_count` without `ignore`.

### sona_pick_screen

```c
sona_result sona_pick_screen(sona_ctx *ctx, const sona_view *v, double x, double y, const sona_pick_options *o,
                             sona_pick_hit *hit);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `v` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `x` | `double` | A pixel from the picture's left | - |
| `y` | `double` | A pixel from the picture's top | - |
| `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](reference/fields.md#sona_pick_options) | required |
| `hit` | `sona_pick_hit *` | Receives what was hit | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
sona_pick_options x_pick_options2;
memset(&x_pick_options2, 0, sizeof x_pick_options2);
x_pick_options2.size = sizeof x_pick_options2;
sona_pick_hit x_pick_hit3;
memset(&x_pick_hit3, 0, sizeof x_pick_hit3);
x_pick_hit3.size = sizeof x_pick_hit3;
sona_result result = sona_pick_screen(ctx, &x_view, 128.0, 128.0, &x_pick_options2, &x_pick_hit3);
if (result != SONA_OK) printf("sona_pick_screen: %s\n", sona_result_name(result));
```

`sona_view_ray` then `sona_pick_ray`, with the sprites facing this view.

### sona_pick_ray_all

```c
uint32_t sona_pick_ray_all(sona_ctx *ctx, const float origin[3], const float dir[3], const sona_pick_options *o,
                           sona_pick_hit *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `origin` | `const float [3]` | The ray's origin, world space | required |
| `dir` | `const float [3]` | The ray's direction, world space | required |
| `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](reference/fields.md#sona_pick_options) | required |
| `out` | `sona_pick_hit *` | Receives the [`sona_pick_hit`](reference/fields.md#sona_pick_hit) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example**:

```c
float x_origin[3];
memset(x_origin, 0, sizeof x_origin);
float x_dir2[3];
memset(x_dir2, 0, sizeof x_dir2);
sona_pick_options x_pick_options3;
memset(&x_pick_options3, 0, sizeof x_pick_options3);
x_pick_options3.size = sizeof x_pick_options3;
sona_pick_hit x_pick_hit4;
memset(&x_pick_hit4, 0, sizeof x_pick_hit4);
x_pick_hit4.size = sizeof x_pick_hit4;
uint32_t x_got = sona_pick_ray_all(ctx, x_origin, x_dir2, &x_pick_options3, &x_pick_hit4, 1);
printf("sona_pick_ray_all: %lld\n", (long long)x_got);
```

Every avatar the ray hits, each at its nearest hit, nearest first. Returns how many avatars it hits and writes up to `cap` of them (`cap` 0 and `out` NULL only count). 0 on a bad argument.

### sona_avatar_pick

```c
sona_result sona_avatar_pick(sona_avatar *a, const float origin[3], const float dir[3], const sona_pick_options *o,
                             sona_pick_hit *hit);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `origin` | `const float [3]` | The ray's origin, world space | required |
| `dir` | `const float [3]` | The ray's direction, world space | required |
| `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](reference/fields.md#sona_pick_options) | required |
| `hit` | `sona_pick_hit *` | Receives what was hit | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
float x_origin[3];
memset(x_origin, 0, sizeof x_origin);
float x_dir2[3];
memset(x_dir2, 0, sizeof x_dir2);
sona_pick_options x_pick_options3;
memset(&x_pick_options3, 0, sizeof x_pick_options3);
x_pick_options3.size = sizeof x_pick_options3;
sona_pick_hit x_pick_hit4;
memset(&x_pick_hit4, 0, sizeof x_pick_hit4);
x_pick_hit4.size = sizeof x_pick_hit4;
sona_result result = sona_avatar_pick(avatar, x_origin, x_dir2, &x_pick_options3, &x_pick_hit4);
if (result != SONA_OK) printf("sona_avatar_pick: %s\n", sona_result_name(result));
```

The ray against one avatar; its hidden and culled flags and `o->ignore` do not apply. `SONA_E_NOT_READY` before it is READY and posed, `SONA_E_DESTROYED` once removed.

### sona_region_name

```c
const char *sona_region_name(uint32_t region);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `region` | `uint32_t` | A body region index | - |

**Returns** `const char *`.

**Example**:

```c
const char * x_got = sona_region_name(1);
printf("sona_region_name: %s\n", x_got ? "a value" : "none");
```

`"none"`, `"head"`, `"neck"`, `"torso"`, `"hips"`, `"leftArm"`, `"rightArm"`, `"leftHand"`, `"rightHand"`, `"leftLeg"`, `"rightLeg"`, `"leftFoot"`, `"rightFoot"`; NULL past the last.

### sona_pick_gpu

```c
sona_result sona_pick_gpu(sona_renderer *r, const sona_view *v, double x, double y, const sona_pick_options *o,
                          sona_pick_hit *hit);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `v` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `x` | `double` | A pixel from the picture's left | - |
| `y` | `double` | A pixel from the picture's top | - |
| `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](reference/fields.md#sona_pick_options) | required |
| `hit` | `sona_pick_hit *` | Receives what was hit | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_view x_view;
sona_view_defaults(&x_view);
sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view);
sona_pick_options x_pick_options2;
memset(&x_pick_options2, 0, sizeof x_pick_options2);
x_pick_options2.size = sizeof x_pick_options2;
sona_pick_hit x_pick_hit3;
memset(&x_pick_hit3, 0, sizeof x_pick_hit3);
x_pick_hit3.size = sizeof x_pick_hit3;
sona_result result = sona_pick_gpu(r, &x_view, 128.0, 128.0, &x_pick_options2, &x_pick_hit3);
if (result != SONA_OK) printf("sona_pick_gpu: %s\n", sona_result_name(result));
```

The pick through the id buffer: the avatars whose sphere the ray meets are drawn once more, each draw writing its index, into a one-pixel target of the pass's own under a projection of that pixel; the backend reads it back (on Vulkan this submits on the device's queue and waits, as `sona_snapshot` does) and the hit is finished on the CPU on the one mesh found (`SONA_PICK_HIT_GPU` set). Sprite avatars are picked on the CPU and the nearer hit wins. `SONA_E_UNSUPPORTED` on D3D11, D3D12, Metal and Xenos. With `SONA_PICK_BOUNDS` it is the CPU pick.

### sona_pick_gpu_ids

```c
sona_result sona_pick_gpu_ids(sona_renderer *r, const sona_view *v, uint32_t x, uint32_t y, uint32_t w, uint32_t h,
                              const sona_pick_options *o, uint32_t *avatar_ids, uint16_t *meshes);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `v` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `x` | `uint32_t` | The region's left edge in pixels | - |
| `y` | `uint32_t` | The region's top edge in pixels | - |
| `w` | `uint32_t` | The region's width in pixels | - |
| `h` | `uint32_t` | The region's height in pixels | - |
| `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](reference/fields.md#sona_pick_options) | required |
| `avatar_ids` | `uint32_t *` | Receives the avatar id per pixel, `w * h` of them | required |
| `meshes` | `uint16_t *` | Receives the mesh index + 1 per pixel; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

The id buffer of the region (x, y, w, h) of the view's picture, at most 4096 x 4096 and inside the view: per pixel, row 0 at the top, the avatar id drawn there (0: none) and, when `meshes` is not NULL, its mesh index + 1. Every drawable avatar in the region is drawn, sprite avatars as their meshes in their held pose. For selection outlines and editors.

## Hair and cloth sway

Long hair, skirts, dresses, robes, coat tails and earrings swing as the avatar moves, under the ctx's gravity and
wind, off the body's capsules. Off by default, per avatar. What sways is read from each worn mesh; those vertices are
re-skinned in a shared copy through palette joints the mesh never reads, and the copy draws with its own palette,
listed after the props in `sona_pose`. Each struct starts with `size = sizeof(struct)` and is refused
(`SONA_E_ARGUMENT`) when `size` is smaller; the `_defaults` functions set it. Avatar calls belong to the owner
thread. The guide, with what counts as hanging, the solver and the cost, is
[Hair and cloth sway](guides/sway.md).

| Struct | Bytes | Fields |
|---|---|---|
| `sona_sway` | 60 | `size`, `parts`, `quality`, `stiffness`, `damping`, `wind_scale`, `min_pixels`, `reserved[8]` |
| `sona_sway_world` | 68 | `size`, `gravity[3]`, `wind[3]`, `gust`, `gust_seconds`, `reserved[8]` |
| `sona_sway_info` | 68 | `size`, `parts`, `meshes`, `chains`, `nodes`, `vertices`, `steps`, `resting`, `max_offset`, `reserved[8]` |

Parts: `SONA_SWAY_HAIR` (1), `SONA_SWAY_CLOTH` (2), `SONA_SWAY_ACCESSORIES` (4, earrings), `SONA_SWAY_HEADWEAR` (8,
costume and hat pieces below the head), `SONA_SWAY_DEFAULT` (7), `SONA_SWAY_ALL` (15). Quality: `SONA_SWAY_LOW` (0,
30 steps a second), `SONA_SWAY_MEDIUM` (1, 60), `SONA_SWAY_HIGH` (2, 120).

### sona_sway_defaults

```c
void sona_sway_defaults(sona_sway *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_sway *` | The [`sona_sway`](reference/fields.md#sona_sway) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Hair and cloth sway](guides/sway.md)):

```c
sona_sway o;
sona_sway_defaults(&o);                  /* hair, cloth and earrings; medium quality */
sona_avatar_sway(avatar, &o);            /* before or after READY */

sona_sway_world w;
sona_sway_world_defaults(&w);            /* gravity 0 -9.81 0, no wind */
w.wind[0] = 4;                           /* a 4 m/s breeze along +X, gusting */
sona_sway_world_set(ctx, &w);

sona_update(ctx, dt, &view, NULL);       /* the chains step inside the poses of this update */
```

Parts `SONA_SWAY_DEFAULT`, medium quality, stiffness and damping 0.5, wind scale 1, 48 minimum pixels.

### sona_avatar_sway

```c
sona_result sona_avatar_sway(sona_avatar *a, const sona_sway *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_sway *` | A [`sona_sway`](reference/fields.md#sona_sway) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Hair and cloth sway](guides/sway.md)):

```c
sona_sway o;
sona_sway_defaults(&o);                  /* hair, cloth and earrings; medium quality */
sona_avatar_sway(avatar, &o);            /* before or after READY */

sona_sway_world w;
sona_sway_world_defaults(&w);            /* gravity 0 -9.81 0, no wind */
w.wind[0] = 4;                           /* a 4 m/s breeze along +X, gusting */
sona_sway_world_set(ctx, &w);

sona_update(ctx, dt, &view, NULL);       /* the chains step inside the poses of this update */
```

Turns sway on with these options, before or after READY (it applies to every later build too). A change of parts
re-skins at once and bumps `build_version`. NULL turns it off: the items' own meshes again. `SONA_E_ARGUMENT` for a
small `size`, no part or an unknown one, a quality past `SONA_SWAY_HIGH`, stiffness or damping outside 0..1, a wind
scale outside 0..100 or negative minimum pixels; `SONA_E_DESTROYED` for an avatar being removed.

### sona_avatar_sway_reset

```c
void sona_avatar_sway_reset(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example**:

```c
sona_avatar_sway_reset(avatar);
```

Back to the modelled shape, at rest, at the next pose. NULL is ignored.

### sona_sway_world_defaults

```c
void sona_sway_world_defaults(sona_sway_world *w);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `w` | `sona_sway_world *` | The [`sona_sway_world`](reference/fields.md#sona_sway_world) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Hair and cloth sway](guides/sway.md)):

```c
sona_sway o;
sona_sway_defaults(&o);                  /* hair, cloth and earrings; medium quality */
sona_avatar_sway(avatar, &o);            /* before or after READY */

sona_sway_world w;
sona_sway_world_defaults(&w);            /* gravity 0 -9.81 0, no wind */
w.wind[0] = 4;                           /* a 4 m/s breeze along +X, gusting */
sona_sway_world_set(ctx, &w);

sona_update(ctx, dt, &view, NULL);       /* the chains step inside the poses of this update */
```

Gravity 0 -9.81 0, no wind, gust 0.35 with a period of 1.5 s.

### sona_sway_world_set

```c
sona_result sona_sway_world_set(sona_ctx *ctx, const sona_sway_world *w);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `w` | `const sona_sway_world *` | A [`sona_sway_world`](reference/fields.md#sona_sway_world) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Hair and cloth sway](guides/sway.md)):

```c
sona_sway o;
sona_sway_defaults(&o);                  /* hair, cloth and earrings; medium quality */
sona_avatar_sway(avatar, &o);            /* before or after READY */

sona_sway_world w;
sona_sway_world_defaults(&w);            /* gravity 0 -9.81 0, no wind */
w.wind[0] = 4;                           /* a 4 m/s breeze along +X, gusting */
sona_sway_world_set(ctx, &w);

sona_update(ctx, dt, &view, NULL);       /* the chains step inside the poses of this update */
```

The gravity and wind every swaying avatar of the ctx feels from its next pose; resting avatars are posed again. NULL:
the defaults. `SONA_E_ARGUMENT` for a small `size`, a gust outside 0..1, gust seconds outside 0.05..600, gravity over
1000 or wind over 100 on an axis, or a value that is not finite.

### sona_avatar_sway_info

```c
sona_result sona_avatar_sway_info(sona_avatar *a, sona_sway_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `out` | `sona_sway_info *` | Receives the [`sona_sway_info`](reference/fields.md#sona_sway_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_sway_info x_sway_info;
memset(&x_sway_info, 0, sizeof x_sway_info);
x_sway_info.size = sizeof x_sway_info;
sona_result result = sona_avatar_sway_info(avatar, &x_sway_info);
if (result != SONA_OK) printf("sona_avatar_sway_info: %s\n", sona_result_name(result));
```

What sways (`parts`, `meshes`, `chains`, `nodes`, `vertices`) and what the last pose did (`steps`, `resting`,
`max_offset` in metres). With sway off: `parts` as found in what it wears, the rest 0. `SONA_E_NOT_READY` before
READY.

### sona_avatar_sway_mesh_parts

```c
uint32_t sona_avatar_sway_mesh_parts(const sona_avatar *a, uint32_t mesh);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `mesh` | `uint32_t` | A mesh index of the pose data | - |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_avatar_sway_mesh_parts(avatar, 0);
printf("sona_avatar_sway_mesh_parts: %lld\n", (long long)x_got);
```

The `SONA_SWAY_*` kinds one of `sona_pose`'s meshes sways with; 0 for one that does not, a bad index, or an avatar
with sway off or not READY.

## Custom items

Your own items: paint a stock item's template, or bring your own skinned mesh, and wear it like any other item. The format, the rules and the tools: [Custom items](guides/custom-items.md).

### sona_custom_item_check

```c
sona_result sona_custom_item_check(const void *bytes, size_t len, sona_custom_item_info *info, char *why, size_t why_cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `bytes` | `const void *` | The file's bytes | required |
| `len` | `size_t` | How many bytes there are | - |
| `info` | `sona_custom_item_info *` | Receives what the file holds; may be NULL | `NULL`: not written |
| `why` | `char *` | Receives what was refused, NUL-terminated; may be NULL | `NULL`: not written |
| `why_cap` | `size_t` | How many bytes `why` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

Pure, no ctx, no network: rules 1 to 11. `SONA_OK` with *info set, or `SONA_E_CORRUPT`, `SONA_E_LIMIT` or `SONA_E_UNSUPPORTED` (a newer format) with the rule in why ("rule 6: ..."), always NUL-terminated. info and why may be NULL.

### sona_custom_item_add

```c
sona_result sona_custom_item_add(sona_ctx *ctx, const void *bytes, size_t len, sona_guid *out_id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `bytes` | `const void *` | The file's bytes | required |
| `len` | `size_t` | How many bytes there are | - |
| `out_id` | `sona_guid *` | Receives the item's id | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Custom items](guides/custom-items.md)):

```c
sona_guid id;
sona_manifest m;
uint8_t worn[SONA_MANIFEST_BYTES];
if (sona_custom_item_add(ctx, file, file_len, &id) == SONA_OK &&     /* the bytes of night-sky.sonaitem */
    sona_manifest_parse(manifest, &m) == SONA_OK &&                  /* an avatar's 1,000 bytes */
    sona_manifest_wear(&m, &id, NULL, 0) == SONA_OK &&
    sona_manifest_write(&m, worn) == SONA_OK)
  sona_avatar_add(ctx, worn, NULL, &avatar);                         /* an avatar wearing it */
```

Checks, copies and keeps the file in ctx. Avatars wearing the id rebuild (READY again). Same id: a higher version replaces, a lower one is kept out (`SONA_OK`, nothing changes); the same version with another hash is `SONA_E_ARGUMENT`. out_id may be NULL.

### sona_custom_item_remove

```c
sona_result sona_custom_item_remove(sona_ctx *ctx, const sona_guid *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `id` | `const sona_guid *` | An item id | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
sona_result result = sona_custom_item_remove(ctx, &x_guid);
if (result != SONA_OK) printf("sona_custom_item_remove: %s\n", sona_result_name(result));
```

Forgets a custom item; avatars wearing it rebuild without it. `SONA_E_NOT_FOUND` for an id the ctx does not hold.

### sona_custom_item_count

```c
uint32_t sona_custom_item_count(const sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_custom_item_count(ctx);
printf("sona_custom_item_count: %lld\n", (long long)x_got);
```

How many custom items the ctx holds.

### sona_custom_item_get

```c
sona_result sona_custom_item_get(const sona_ctx *ctx, uint32_t index, sona_custom_item_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_custom_item_info *` | Receives the [`sona_custom_item_info`](reference/fields.md#sona_custom_item_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_custom_item_info x_custom_item_info;
memset(&x_custom_item_info, 0, sizeof x_custom_item_info);
sona_result result = sona_custom_item_get(ctx, 0, &x_custom_item_info);
if (result != SONA_OK) printf("sona_custom_item_get: %s\n", sona_result_name(result));
```

The custom item at `index`, in the order `sona_custom_item_count` counts them.

### sona_custom_item_find

```c
sona_result sona_custom_item_find(const sona_ctx *ctx, const sona_guid *id, sona_custom_item_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `id` | `const sona_guid *` | An item id | required |
| `out` | `sona_custom_item_info *` | Receives the [`sona_custom_item_info`](reference/fields.md#sona_custom_item_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
sona_custom_item_info x_custom_item_info2;
memset(&x_custom_item_info2, 0, sizeof x_custom_item_info2);
sona_result result = sona_custom_item_find(ctx, &x_guid, &x_custom_item_info2);
if (result != SONA_OK) printf("sona_custom_item_find: %s\n", sona_result_name(result));
```

The custom item with this id; `SONA_E_NOT_FOUND` when the ctx holds none.

### sona_guid_is_custom

```c
int sona_guid_is_custom(const sona_guid *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `id` | `const sona_guid *` | An item id | required |

**Returns** `int`.

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
int x_got = sona_guid_is_custom(&x_guid);
printf("sona_guid_is_custom: %lld\n", (long long)x_got);
```

1 when the id is a custom item's id, 0 for a stock item's.

### sona_guid_pair

```c
sona_result sona_guid_pair(const sona_guid *id, sona_guid *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `id` | `const sona_guid *` | An item id | required |
| `out` | `sona_guid *` | Receives the [`sona_guid`](reference/fields.md#sona_guid) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
sona_guid x_guid2;
memset(&x_guid2, 0, sizeof x_guid2);
sona_result result = sona_guid_pair(&x_guid, &x_guid2);
if (result != SONA_OK) printf("sona_guid_pair: %s\n", sona_result_name(result));
```

The same custom item's id for the other body. `SONA_E_ARGUMENT` for a body 3 item or a stock id.

### sona_custom_item_new_id

```c
sona_result sona_custom_item_new_id(sona_ctx *ctx, const sona_guid *template_id, sona_guid *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `template_id` | `const sona_guid *` | A [`sona_guid`](reference/fields.md#sona_guid) | required |
| `out` | `sona_guid *` | Receives the [`sona_guid`](reference/fields.md#sona_guid) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
sona_guid x_guid2;
memset(&x_guid2, 0, sizeof x_guid2);
sona_result result = sona_custom_item_new_id(ctx, &x_guid, &x_guid2);
if (result != SONA_OK) printf("sona_custom_item_new_id: %s\n", sona_result_name(result));
```

A fresh id for a template (a real worn id of a 1.0 slot, body 1, 2 or 3). ctx may be NULL.

### sona_custom_item_pack

```c
sona_result sona_custom_item_pack(sona_ctx *ctx, const sona_paint_spec *spec, uint8_t **out, size_t *out_len);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `spec` | `const sona_paint_spec *` | The options, a [`sona_paint_spec`](reference/fields.md#sona_paint_spec) | required |
| `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](troubleshooting.md#error-codes)).

Pixels in, a `.sonaitem` out (free with `sona_free`): the same bytes as `scene.items.pack` gives for the same input. The template must be readable through the ctx's sources (surfaces and hash are checked): `SONA_PENDING` until it has been fetched, then call again after `sona_update`. Each surface takes the template's default layout. The file is not signed. [Custom items](guides/custom-items.md) has the format.

### sona_avatar_missing_items

```c
uint32_t sona_avatar_missing_items(const sona_avatar *a, sona_guid *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_guid *` | Receives the [`sona_guid`](reference/fields.md#sona_guid) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
uint32_t x_got = sona_avatar_missing_items(avatar, &x_guid, 1);
printf("sona_avatar_missing_items: %lld\n", (long long)x_got);
```

Custom ids this avatar wears that no registration supplied, as last built. Returns the count; writes up to cap.

### sona_mesh_item_spec_defaults

```c
void sona_mesh_item_spec_defaults(sona_mesh_item_spec *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_mesh_item_spec *` | The [`sona_mesh_item_spec`](reference/fields.md#sona_mesh_item_spec) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_mesh_item_spec x_mesh_item_spec;
sona_mesh_item_spec_defaults(&x_mesh_item_spec);
sona_mesh_item_spec_defaults(&x_mesh_item_spec);
```

`size` set and every pointer NULL.

### sona_custom_item_pack_mesh

```c
sona_result sona_custom_item_pack_mesh(sona_ctx *ctx, const sona_mesh_item_spec *spec, uint8_t **out, size_t *out_len, char *why, size_t why_cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `spec` | `const sona_mesh_item_spec *` | The options, a [`sona_mesh_item_spec`](reference/fields.md#sona_mesh_item_spec) | required |
| `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required |
| `out_len` | `size_t *` | Receives how many bytes `*out` holds | required |
| `why` | `char *` | Receives what was refused, NUL-terminated; may be NULL | `NULL`: not written |
| `why_cap` | `size_t` | How many bytes `why` holds | - |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](troubleshooting.md#error-codes)).

Free *out with `sona_free`. why (may be NULL) says what the import refused, always NUL-terminated. Not signed. Reads the template, the rig and the coverage check's assets through the ctx's sources: `SONA_PENDING` until they arrive. `SONA_E_ARGUMENT` when the glb is refused ([custom items](guides/custom-items.md), sections 5.2 and 5.3).

## Lip sync and voice mouths

Mouth shapes from audio, from timed phonemes or from text, and cheap mouths that move with a voice's loudness: [Lip sync](guides/lipsync.md).

### sona_lipsync_defaults

```c
void sona_lipsync_defaults(sona_lipsync_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_lipsync_options *` | The [`sona_lipsync_options`](reference/fields.md#sona_lipsync_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_lipsync_options x_lipsync_options;
memset(&x_lipsync_options, 0, sizeof x_lipsync_options);
x_lipsync_options.size = sizeof x_lipsync_options;
sona_lipsync_defaults(&x_lipsync_options);
```

`size` set; `sample_rate` 48000, `channels` 1, `hold_seconds` 0.07, `attack_seconds` 0.02, `release_seconds` 0.07, `gate_db` -55, `lead_seconds` 0.04.

### sona_lipsync_create

```c
sona_result sona_lipsync_create(const sona_lipsync_options *o, const sona_allocator *al, sona_lipsync **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_lipsync_options *` | The options, a [`sona_lipsync_options`](reference/fields.md#sona_lipsync_options) | `NULL`: the defaults |
| `al` | `const sona_allocator *` | A [`sona_allocator`](reference/fields.md#sona_allocator) | required |
| `out` | `sona_lipsync **` | Receives the new lip sync analyser | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

NULL options: the defaults. al NULL: malloc. `SONA_E_ARGUMENT` for a size, rate, channel count, format or time out of range.

### sona_lipsync_destroy

```c
void sona_lipsync_destroy(sona_lipsync *ls);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ls` | `sona_lipsync *` | The lip sync analyser | required |

**Returns** Nothing.

**Example**:

```c
sona_lipsync_destroy(ls);
```

Frees the analyser.

### sona_lipsync_reset

```c
void sona_lipsync_reset(sona_lipsync *ls);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ls` | `sona_lipsync *` | The lip sync analyser | required |

**Returns** Nothing.

**Example**:

```c
sona_lipsync_reset(ls);
```

Back to time 0: hints and frames waiting to be read are dropped.

### sona_lipsync_feed

```c
sona_result sona_lipsync_feed(sona_lipsync *ls, const void *pcm, size_t frames);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ls` | `sona_lipsync *` | The lip sync analyser | required |
| `pcm` | `const void *` | Audio samples, interleaved, in the format the options name | required |
| `frames` | `size_t` | How many sample frames `pcm` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

`frames`: samples per channel. Analyses every 10 ms that is complete.

### sona_lipsync_read

```c
uint32_t sona_lipsync_read(sona_lipsync *ls, sona_lipsync_frame *out, uint32_t max);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ls` | `sona_lipsync *` | The lip sync analyser | required |
| `out` | `sona_lipsync_frame *` | Receives the [`sona_lipsync_frame`](reference/fields.md#sona_lipsync_frame) | required |
| `max` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example**:

```c
sona_lipsync_frame x_lipsync_frame;
memset(&x_lipsync_frame, 0, sizeof x_lipsync_frame);
uint32_t x_got = sona_lipsync_read(ls, &x_lipsync_frame, 1);
printf("sona_lipsync_read: %lld\n", (long long)x_got);
```

Moves up to max frames made since the last read into out, oldest first; returns how many.

### sona_lipsync_current

```c
sona_result sona_lipsync_current(const sona_lipsync *ls, sona_lipsync_frame *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ls` | `const sona_lipsync *` | The lip sync analyser | required |
| `out` | `sona_lipsync_frame *` | Receives the [`sona_lipsync_frame`](reference/fields.md#sona_lipsync_frame) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_lipsync_frame x_lipsync_frame;
memset(&x_lipsync_frame, 0, sizeof x_lipsync_frame);
sona_result result = sona_lipsync_current(ls, &x_lipsync_frame);
if (result != SONA_OK) printf("sona_lipsync_current: %s\n", sona_result_name(result));
```

The newest frame (a shut mouth before the first).

### sona_lipsync_latency

```c
double sona_lipsync_latency(const sona_lipsync *ls);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ls` | `const sona_lipsync *` | The lip sync analyser | required |

**Returns** `double`.

**Example**:

```c
double x_got = sona_lipsync_latency(ls);
printf("sona_lipsync_latency: %g\n", (double)x_got);
```

Seconds from a sample being fed to the first frame that hears it.

### sona_lipsync_hint

```c
sona_result sona_lipsync_hint(sona_lipsync *ls, const sona_phoneme *ph, uint32_t count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ls` | `sona_lipsync *` | The lip sync analyser | required |
| `ph` | `const sona_phoneme *` | A [`sona_phoneme`](reference/fields.md#sona_phoneme) | required |
| `count` | `uint32_t` | How many entries the array holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_phoneme x_phoneme;
memset(&x_phoneme, 0, sizeof x_phoneme);
sona_result result = sona_lipsync_hint(ls, &x_phoneme, 1);
if (result != SONA_OK) printf("sona_lipsync_hint: %s\n", sona_result_name(result));
```

Phonemes the host's TTS reported, on the fed audio's clock: their shapes win while the audio is sounding, and lips close for M, B and P. Up to 256 held; ones that ended a second ago go.

### sona_phoneme_mouth

```c
uint32_t sona_phoneme_mouth(const char *symbol);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `symbol` | `const char *` | A phoneme symbol | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_phoneme_mouth("example");
printf("sona_phoneme_mouth: %lld\n", (long long)x_got);
```

The mouth for a phoneme symbol; `SONA_MOUTH_UNKNOWN` when it is none of the sets.

### sona_lipsync_phonemes

```c
sona_result sona_lipsync_phonemes(const sona_phoneme *ph, uint32_t count, const sona_lipsync_options *o, sona_mouth_key *out, uint32_t cap, uint32_t *total);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ph` | `const sona_phoneme *` | A [`sona_phoneme`](reference/fields.md#sona_phoneme) | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `o` | `const sona_lipsync_options *` | The options, a [`sona_lipsync_options`](reference/fields.md#sona_lipsync_options) | required |
| `out` | `sona_mouth_key *` | Receives the [`sona_mouth_key`](reference/fields.md#sona_mouth_key) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |
| `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Timed phonemes to keys (lead, closures kept, short shapes merged). *total is the count; writes up to cap. o may be NULL.

### sona_lipsync_text

```c
sona_result sona_lipsync_text(const char *text, const void *pcm, size_t frames, const sona_lipsync_options *o, sona_mouth_key *out, uint32_t cap, uint32_t *total);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `text` | `const char *` | The text to read | required |
| `pcm` | `const void *` | Audio samples, interleaved, in the format the options name | required |
| `frames` | `size_t` | How many sample frames `pcm` holds | - |
| `o` | `const sona_lipsync_options *` | The options, a [`sona_lipsync_options`](reference/fields.md#sona_lipsync_options) | required |
| `out` | `sona_mouth_key *` | Receives the [`sona_mouth_key`](reference/fields.md#sona_mouth_key) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |
| `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Text to keys. With audio (frames > 0, in o's format) the text is aligned to it; without, an even pace. `SONA_E_LIMIT` past 4096 letters or the 10 minutes limit of audio.

### sona_mouth_keys_sample

```c
sona_result sona_mouth_keys_sample(const sona_mouth_key *keys, uint32_t count, double t, sona_lipsync_frame *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `keys` | `const sona_mouth_key *` | A [`sona_mouth_key`](reference/fields.md#sona_mouth_key) | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `t` | `double` | The time to sample, seconds | - |
| `out` | `sona_lipsync_frame *` | Receives the [`sona_lipsync_frame`](reference/fields.md#sona_lipsync_frame) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_mouth_key x_mouth_key;
memset(&x_mouth_key, 0, sizeof x_mouth_key);
sona_lipsync_frame x_lipsync_frame2;
memset(&x_lipsync_frame2, 0, sizeof x_lipsync_frame2);
sona_result result = sona_mouth_keys_sample(&x_mouth_key, 1, 0.5f, &x_lipsync_frame2);
if (result != SONA_OK) printf("sona_mouth_keys_sample: %s\n", sona_result_name(result));
```

The mouth at time t of a key list, eased between keys.

### sona_avatar_mouth

```c
sona_result sona_avatar_mouth(sona_avatar *a, uint32_t shape);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `shape` | `uint32_t` | A `SONA_MOUTH_*` shape | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_mouth(avatar, 0);
if (result != SONA_OK) printf("sona_avatar_mouth: %s\n", sona_result_name(result));
```

Only the mouth of the expression: a `SONA_MOUTH_`* or another shape index, or 255 to hand it back to the clip. The rest of the face keeps what `sona_avatar_expression` or the clip gave it. The same shape again does nothing.

### sona_voice_mouth_init

```c
void sona_voice_mouth_init(sona_voice_mouth *v, uint32_t seed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `v` | `sona_voice_mouth *` | Receives the [`sona_voice_mouth`](reference/fields.md#sona_voice_mouth) | required |
| `seed` | `uint32_t` | The seed: the same seed gives the same result | - |

**Returns** Nothing.

**Example** (also in [Lip sync: a microphone or any audio drives the mouth](guides/lipsync.md)):

```c
sona_voice_mouth v[64];
for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i], sona_avatar_id(avatars[i]));
/* each frame: */
uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt);
```

Sets `size` and starts the state from `seed`. Avatars with different seeds move their mouths differently to the same voice.

### sona_voice_mouth_step

```c
uint32_t sona_voice_mouth_step(sona_voice_mouth *v, float level, float dt, float *open);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `v` | `sona_voice_mouth *` | Receives the [`sona_voice_mouth`](reference/fields.md#sona_voice_mouth) | required |
| `level` | `float` | The audio level, linear RMS | - |
| `dt` | `float` | Seconds since the last call | - |
| `open` | `float *` | Receives how open the mouth is, 0 to 1 | required |

**Returns** `uint32_t`.

Advances by dt seconds; returns the `SONA_MOUTH_`* to show. open may be NULL.

### sona_avatar_voice

```c
sona_result sona_avatar_voice(sona_avatar *a, sona_voice_mouth *v, float level, float dt);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `v` | `sona_voice_mouth *` | Receives the [`sona_voice_mouth`](reference/fields.md#sona_voice_mouth) | required |
| `level` | `float` | The audio level, linear RMS | - |
| `dt` | `float` | Seconds since the last call | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_voice_mouth x_voice_mouth;
memset(&x_voice_mouth, 0, sizeof x_voice_mouth);
x_voice_mouth.size = sizeof x_voice_mouth;
sona_result result = sona_avatar_voice(avatar, &x_voice_mouth, 0, 1.0f / 60);
if (result != SONA_OK) printf("sona_avatar_voice: %s\n", sona_result_name(result));
```

`sona_voice_mouth_step` with the voice's level, put on the avatar's mouth with `sona_avatar_mouth`.

### sona_voice_mouths

```c
uint32_t sona_voice_mouths(sona_avatar *const *avatars, sona_voice_mouth *states, const float *levels, uint32_t count, float dt);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `avatars` | `sona_avatar *const *` | The avatars, `count` of them | required |
| `states` | `sona_voice_mouth *` | A mouth state per avatar | required |
| `levels` | `const float *` | An audio level per avatar, linear RMS | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `dt` | `float` | Seconds since the last call | - |

**Returns** `uint32_t`.

**Example** (also in [Lip sync: a microphone or any audio drives the mouth](guides/lipsync.md)):

```c
sona_voice_mouth v[64];
for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i], sona_avatar_id(avatars[i]));
/* each frame: */
uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt);
```

`sona_avatar_voice` for count avatars (NULL entries skipped); returns how many mouths changed.

## Making avatars in code

Seeded random avatars, dressing one avatar like another, and the outfit rules the editor follows: [Making avatars in code](guides/makers.md).

### sona_maker_create

```c
sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat, sona_maker **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | `NULL` allowed (below) |
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `out` | `sona_maker **` | Receives the new maker | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat, sona_maker **out);
void sona_maker_free(sona_maker *mk);
```

Indexes a catalogue's outfit rules once: candidate items per body and section, gender variants and matched sets ([Making avatars in code](guides/makers.md)). The maker never changes after this, so every call on it is safe from any number of threads at once. It reads the catalogue: free it before the catalogue. `ctx` may be NULL (malloc, codes only).

### sona_maker_free

```c
void sona_maker_free(sona_maker *mk);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `sona_maker *` | The maker | required |

**Returns** Nothing.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat, sona_maker **out);
void sona_maker_free(sona_maker *mk);
```

Frees the maker.

### sona_random_defaults

```c
void sona_random_defaults(sona_random_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_random_options *` | The [`sona_random_options`](reference/fields.md#sona_random_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
void sona_random_defaults(sona_random_options *o);
sona_result sona_make_random(const sona_maker *mk, uint32_t seed, const sona_random_options *o,
                             uint8_t out[SONA_MANIFEST_BYTES], sona_random_report *report);
```

`size` set and everything else zero: the seed picks the body, any game, a new avatar, the palette's colours and every item available.

### sona_make_random

```c
sona_result sona_make_random(const sona_maker *mk, uint32_t seed, const sona_random_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_random_report *report);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `seed` | `uint32_t` | The seed: the same seed gives the same result | - |
| `o` | `const sona_random_options *` | The options, a [`sona_random_options`](reference/fields.md#sona_random_options) | required |
| `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required |
| `report` | `sona_random_report *` | Receives what the call did; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
void sona_random_defaults(sona_random_options *o);
sona_result sona_make_random(const sona_maker *mk, uint32_t seed, const sona_random_options *o,
                             uint8_t out[SONA_MANIFEST_BYTES], sona_random_report *report);
```

A new avatar from a seed: body, shape, colours, face, hair and an outfit with no clashes. The same seed, options and library give the same bytes. Picks are rendezvous hashes of (seed, section, item id): a newer catalogue moves a pick only where that item is gone or a new item outscores it, so most avatars survive a catalogue update. o may be NULL; report may be NULL. `SONA_E_ARGUMENT`: a body over 2, a style or palette out of range, or a base that does not parse or has no body while body is 0.

### sona_like_defaults

```c
void sona_like_defaults(sona_like_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_like_options *` | The [`sona_like_options`](reference/fields.md#sona_like_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
void sona_like_defaults(sona_like_options *o);
sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES],
                                 const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o,
                                 uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report);
uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match,
                           sona_guid *out);
```

`size` set; `parts` clothes and props, `match` SIMILAR.

### sona_make_dress_like

```c
sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES], const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `body` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest whose body is kept | required |
| `like` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest whose look is copied | required |
| `o` | `const sona_like_options *` | The options, a [`sona_like_options`](reference/fields.md#sona_like_options) | required |
| `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required |
| `report` | `sona_like_report *` | Receives what the call did; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MANIFEST` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
void sona_like_defaults(sona_like_options *o);
sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES],
                                 const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o,
                                 uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report);
uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match,
                           sona_guid *out);
```

`out` = body wearing like's parts, each item resolved for body's gender (`sona_make_variant`). out may be body. mk may be NULL: then only items both bodies wear, and custom items' pairs, come across. `SONA_E_ARGUMENT` when body has no known body; `SONA_E_MANIFEST` when either does not parse.

### sona_make_variant

```c
uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match, sona_guid *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `item` | `const sona_guid *` | A [`sona_guid`](reference/fields.md#sona_guid) | required |
| `body` | `uint32_t` | The body a clip or item is for: 1 male, 2 female | - |
| `match` | `uint32_t` | What the variant must match | - |
| `out` | `sona_guid *` | Receives the [`sona_guid`](reference/fields.md#sona_guid) | required |

**Returns** `uint32_t`.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
void sona_like_defaults(sona_like_options *o);
sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES],
                                 const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o,
                                 uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report);
uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match,
                           sona_guid *out);
```

The item body (1 or 2) wears for item: itself when it fits (KEPT), else its variant within match. Returns `SONA_RESOLVED_`*; DROPPED (out zeroed) when nothing fits.

### sona_outfit_clash

```c
uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a, const sona_guid *b, uint32_t *slots);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `a` | `const sona_guid *` | One item id | required |
| `b` | `const sona_guid *` | The other item id | required |
| `slots` | `uint32_t *` | Receives the slots the two items share | required |

**Returns** `uint32_t`.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a, const sona_guid *b, uint32_t *slots);
uint32_t sona_outfit_conflicts(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES],
                               const sona_guid *item, sona_guid *out, uint32_t cap);
```

`SONA_CLASH_`* bits (0: they go together); slots (may be NULL) gets the slots they share. mk may be NULL (ids only). Two props share the prop slot: they stack only with `SONA_EDIT_STACK_PROPS`, up to four.

### sona_outfit_conflicts

```c
uint32_t sona_outfit_conflicts(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], const sona_guid *item, sona_guid *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required |
| `item` | `const sona_guid *` | A [`sona_guid`](reference/fields.md#sona_guid) | required |
| `out` | `sona_guid *` | Receives the [`sona_guid`](reference/fields.md#sona_guid) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a, const sona_guid *b, uint32_t *slots);
uint32_t sona_outfit_conflicts(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES],
                               const sona_guid *item, sona_guid *out, uint32_t cap);
```

What wearing item would take off manifest: up to cap ids into out; returns how many.

### sona_outfit_set_count

```c
uint32_t sona_outfit_set_count(const sona_maker *mk);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |

**Returns** `uint32_t`.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap);
```

How many matched sets (outfits sold as one) the maker knows.

### sona_outfit_set_get

```c
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `set` | `uint32_t` | A matched set's index | - |
| `out` | `sona_outfit_set *` | Receives the [`sona_outfit_set`](reference/fields.md#sona_outfit_set) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap);
```

Set `set`: its item count, which bodies wear it, the sections it has items in and the slots it covers.

### sona_outfit_set_of

```c
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `item` | `const sona_guid *` | A [`sona_guid`](reference/fields.md#sona_guid) | required |

**Returns** `int32_t`.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap);
```

The matched set an item belongs to, or -1 when it is in none.

### sona_outfit_set_items

```c
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `set` | `uint32_t` | A matched set's index | - |
| `body` | `uint32_t` | The body whose items to list: 1 male, 2 female; 0: every item | `0`: every item |
| `indexes` | `uint32_t *` | Receives catalogue indexes | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap);
```

The set's items a body wears (0: every item), catalogue indexes in id order: up to cap; returns how many.

### sona_outfit_check

```c
sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required |
| `report` | `sona_outfit_report *` | Receives what the call did; may be NULL | `NULL`: not written |
| `issues` | `sona_outfit_issue *` | Receives the issues found, up to `max` | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES],
                              sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap);
sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after);
const char *sona_outfit_issue_name(uint32_t kind);
```

Every issue of a manifest, up to cap into issues (may be NULL with cap 0), errors first. mk may be NULL: the catalogue's checks (UNKNOWN, NOT_OFFERED, bodies by the catalogue) are left out. `SONA_E_MANIFEST`: it does not parse.

### sona_outfit_fix

```c
sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `mk` | `const sona_maker *` | The maker | required |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required |
| `after` | `sona_outfit_report *` | Receives the report of the manifest as fixed | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES],
                              sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap);
sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after);
const char *sona_outfit_issue_name(uint32_t kind);
```

Fixes every error but NO_BODY in place: clashes go to the item worn last (as the editor), other-body items to their variants, duplicates and misplaced items out (a misplaced item that routes is worn where it belongs), missing slots to the body's defaults, a stale cache to the body's own; after (may be NULL) is the check after. `SONA_E_ARGUMENT` when the body is not known.

### sona_outfit_issue_name

```c
const char * sona_outfit_issue_name(uint32_t kind);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `kind` | `uint32_t` | Which kind, one of the header's constants for it | - |

**Returns** `const char *`.

**Example** (also in [Making avatars in code](guides/makers.md)):

```c
sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES],
                              sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap);
sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after);
const char *sona_outfit_issue_name(uint32_t kind);
```

The name of a `SONA_OUTFIT_*` issue kind ("clash", ...); NULL past the last.

## Content filters

Which items a game allows, by section, slot, source, game, tag or id, with presets and JSON rules: [Content filters](guides/filters.md).

### sona_filter_create

```c
sona_result sona_filter_create(sona_ctx *ctx, const sona_catalogue *cat, sona_filter **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | `NULL` allowed (below) |
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `out` | `sona_filter **` | Receives the new filter | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

`ctx` may be NULL (malloc; errors only as codes); with one, its allocator and `sona_last_error`. cat may be NULL: then only id, slot, section (from the id) and source rules can match. The filter may outlive both.

### sona_filter_free

```c
void sona_filter_free(sona_filter *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |

**Returns** Nothing.

Frees the filter.

### sona_filter_reset

```c
sona_result sona_filter_reset(sona_filter *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Every rule goes; tags stay.

### sona_filter_sections

```c
sona_result sona_filter_sections(sona_filter *f, uint32_t mode, uint32_t sections);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - |
| `sections` | `uint32_t` | `SONA_SECTION_*` bits | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Adds a rule on sections: bits (1u << `sona_section`). `mode` is `SONA_CONTENT_ALLOW` or `_DENY`; each call adds to the rules.

### sona_filter_slots

```c
sona_result sona_filter_slots(sona_filter *f, uint32_t mode, uint32_t slots);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - |
| `slots` | `uint32_t` | Slot mask bits | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Adds a rule on slots (AssetMask bits): an item matches when it covers any of them. `mode` is `SONA_CONTENT_ALLOW` or `_DENY`.

### sona_filter_sources

```c
sona_result sona_filter_sources(sona_filter *f, uint32_t mode, uint32_t sources);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - |
| `sources` | `uint32_t` | `SONA_ITEM_*` source bits | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Content filters](guides/filters.md)):

```c
sona_filter_game(f, SONA_CONTENT_ALLOW, "Racer X");
sona_filter_sources(f, SONA_CONTENT_ALLOW, SONA_CONTENT_STOCK);
```

Adds a rule on where items come from (`SONA_CONTENT_STOCK` and the other source bits). `mode` is `SONA_CONTENT_ALLOW` or `_DENY`.

### sona_filter_game

```c
sona_result sona_filter_game(sona_filter *f, uint32_t mode, const char *game);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - |
| `game` | `const char *` | A game's name, as the catalogue spells it | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Content filters](guides/filters.md)):

```c
sona_filter_game(f, SONA_CONTENT_ALLOW, "Racer X");
sona_filter_sources(f, SONA_CONTENT_ALLOW, SONA_CONTENT_STOCK);
```

A game as `sona_catalogue_game` names it (ASCII case folded). `SONA_E_NOT_FOUND` when no item has that game.

### sona_filter_tag

```c
sona_result sona_filter_tag(sona_filter *f, uint32_t mode, const char *tag);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - |
| `tag` | `const char *` | A tag's name | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

A tag by name ("weapon", "logo", or one the host defined). `SONA_E_NOT_FOUND` for an unknown name.

### sona_filter_item

```c
sona_result sona_filter_item(sona_filter *f, uint32_t mode, const sona_guid *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - |
| `id` | `const sona_guid *` | An item id | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Adds a rule on one item by id. `mode` is `SONA_CONTENT_ALLOW` or `_DENY`.

### sona_filter_preset

```c
sona_result sona_filter_preset(sona_filter *f, uint32_t preset);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `preset` | `uint32_t` | Which preset, one of the header's constants for it | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Adds a preset's rules (`SONA_FILTER_PRESET_*`, listed in [Content filters](guides/filters.md)).

### sona_filter_load

```c
sona_result sona_filter_load(sona_filter *f, const char *json, size_t len, char *why, size_t why_cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `json` | `const char *` | Filter rules as JSON text | required |
| `len` | `size_t` | How many bytes there are | - |
| `why` | `char *` | Receives what was refused, NUL-terminated; may be NULL | `NULL`: not written |
| `why_cap` | `size_t` | How many bytes `why` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Rules from JSON ([Content filters](guides/filters.md)): {"preset": [...], "allow": {...}, "deny": {...}, "tags": {...}, "untag": {...}}. All or nothing: on an error the filter is unchanged and why (may be NULL) says what was wrong.

### sona_filter_tag_count

```c
uint32_t sona_filter_tag_count(const sona_filter *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |

**Returns** `uint32_t`.

How many tags the filter knows, built-in and host-defined.

### sona_filter_tag_name

```c
const char * sona_filter_tag_name(const sona_filter *f, uint32_t tag);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `tag` | `uint32_t` | A tag's bit | - |

**Returns** `const char *`.

NULL past the last.

### sona_filter_tag_find

```c
int32_t sona_filter_tag_find(const sona_filter *f, const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `name` | `const char *` | The name to look up | required |

**Returns** `int32_t`.

-1 when unknown.

### sona_filter_tag_define

```c
sona_result sona_filter_tag_define(sona_filter *f, const char *name, uint32_t *out_tag);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `name` | `const char *` | The new tag's name | required |
| `out_tag` | `uint32_t *` | Receives the new tag's bit | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT` ([what each means](troubleshooting.md#error-codes)).

A new tag (a name of 1 to 31 bytes of a-z, 0-9 and '-'), or the index of the one of that name. `SONA_E_LIMIT` past 64 tags.

### sona_filter_tag_set

```c
sona_result sona_filter_tag_set(sona_filter *f, const sona_guid *id, uint32_t tag, int on);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `sona_filter *` | The filter | required |
| `id` | `const sona_guid *` | An item id | required |
| `tag` | `uint32_t` | A tag's bit | - |
| `on` | `int` | 1 on, 0 off | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Puts a tag on an item (`on` 1) or takes it off (0), for ids in the catalogue or not.

### sona_filter_item_tags

```c
uint64_t sona_filter_item_tags(const sona_filter *f, const sona_guid *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `id` | `const sona_guid *` | An item id | required |

**Returns** `uint64_t`.

The bits of an item's tags (bit n is tag n).

### sona_filter_tag_items

```c
uint32_t sona_filter_tag_items(const sona_filter *f, uint32_t tag);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `tag` | `uint32_t` | A tag's bit | - |

**Returns** `uint32_t`.

How many catalogue items carry a tag.

### sona_filter_allows

```c
int sona_filter_allows(const sona_filter *f, const sona_guid *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `id` | `const sona_guid *` | An item id | required |

**Returns** `int`.

1 when the item is allowed; a NULL filter allows everything.

### sona_filter_check

```c
sona_result sona_filter_check(const sona_filter *f, const sona_guid *id, sona_filter_verdict *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `id` | `const sona_guid *` | An item id | required |
| `out` | `sona_filter_verdict *` | Receives the [`sona_filter_verdict`](reference/fields.md#sona_filter_verdict) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Whether the item is allowed, and if not, which rule denied it (`SONA_CONTENT_BY_*`) and the item's tags.

### sona_filter_search

```c
sona_result sona_filter_search(const sona_filter *f, const sona_catalogue *cat, const sona_catalogue_query *q, uint32_t *out_indexes, uint32_t max, uint32_t *total);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `cat` | `const sona_catalogue *` | The catalogue | required |
| `q` | `const sona_catalogue_query *` | A [`sona_catalogue_query`](reference/fields.md#sona_catalogue_query) | required |
| `out_indexes` | `uint32_t *` | Receives catalogue indexes, up to `max` | required |
| `max` | `uint32_t` | How many entries `out` holds | - |
| `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

`sona_catalogue_search` over cat, allowed items only (offset and total count allowed ones). Any catalogue works; items are matched by id.

### sona_filter_allowed_count

```c
uint32_t sona_filter_allowed_count(const sona_filter *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |

**Returns** `uint32_t`.

Catalogue items allowed.

### sona_filter_manifest

```c
sona_result sona_filter_manifest(const sona_filter *f, sona_manifest *m, sona_filter_report *report);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `m` | `sona_manifest *` | Receives the [`sona_manifest`](reference/fields.md#sona_manifest) | required |
| `report` | `sona_filter_report *` | Receives what the call did; may be NULL | `NULL` allowed (below) |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Takes every denied item off a manifest: worn items go back to the body's defaults, props are hidden. `report` (may be NULL) lists what changed.

### sona_filter_manifest_bytes

```c
sona_result sona_filter_manifest_bytes(const sona_filter *f, uint8_t manifest[SONA_MANIFEST_BYTES], sona_filter_report *report);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `f` | `const sona_filter *` | The filter | required |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required |
| `report` | `sona_filter_report *` | Receives what the call did; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MANIFEST` ([what each means](troubleshooting.md#error-codes)).

The same on the 1000 bytes, in place; unchanged bytes when nothing is denied. `SONA_E_MANIFEST` for bad bytes.

### sona_ctx_set_filter

```c
sona_result sona_ctx_set_filter(sona_ctx *ctx, const sona_filter *f);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `f` | `const sona_filter *` | The filter | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

The ctx's filter: a copy of f (NULL takes it away), applied to an avatar when its manifest is read, whoever's it is (`sona_avatar_add`, headless renders); an avatar read before the change keeps what it wore until it is removed and added again. A preview of a denied item fails with `SONA_E_NOT_FOUND`. Pickers read it back with `sona_ctx_filter`: NULL when none; owned by the ctx and gone at the next `sona_ctx_set_filter` or `sona_close`.

### sona_ctx_filter

```c
const sona_filter * sona_ctx_filter(const sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |

**Returns** `const sona_filter *`.

**Example**:

```c
const sona_filter * x_got = sona_ctx_filter(ctx);
printf("sona_ctx_filter: %s\n", x_got ? "a value" : "none");
```

The ctx's filter as `sona_ctx_set_filter` left it: NULL when none; owned by the ctx and gone at the next `sona_ctx_set_filter` or `sona_close`.

### sona_avatar_filter_report

```c
sona_result sona_avatar_filter_report(const sona_avatar *a, sona_filter_report *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_filter_report *` | Receives the [`sona_filter_report`](reference/fields.md#sona_filter_report) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_filter_report x_filter_report;
memset(&x_filter_report, 0, sizeof x_filter_report);
x_filter_report.size = sizeof x_filter_report;
sona_result result = sona_avatar_filter_report(avatar, &x_filter_report);
if (result != SONA_OK) printf("sona_avatar_filter_report: %s\n", sona_result_name(result));
```

What the ctx's filter changed on this avatar. `SONA_E_NOT_READY` before its manifest is read, `SONA_E_NOT_FOUND` when no filter was set then.

## Lighting and shadows

A key light, ambient and environment light, shadows on the avatars and the ground, and the host's own shadow map: [Lighting and shadows](guides/lighting.md).

### sona_lighting_defaults

```c
void sona_lighting_defaults(sona_lighting *l);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `l` | `sona_lighting *` | The [`sona_lighting`](reference/fields.md#sona_lighting) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Lighting and shadows](guides/lighting.md)):

```c
sona_lighting_defaults(&l);
l.key.direction[0] = 0.4f; l.key.direction[1] = -1.0f; l.key.direction[2] = 0.6f;
l.key.intensity = 0.9f;
l.flags = SONA_LIGHTING_GROUND | SONA_LIGHTING_PROXY_CASTERS;   /* a crowd's ground shadows for almost nothing */
sona_renderer_set_lighting(r, &l);
```

`size` set; `ambient` 0, `environment` 1, `specular` 1, `rim` 1, `shadow` FIT, `shadow_size` 2048, `shadow_strength` 1, `shadow_ambient` 0.5, `shadow_bias` 0.03, `ground_y` 0, `ground_opacity` 0.6.

### sona_renderer_set_lighting

```c
sona_result sona_renderer_set_lighting(sona_renderer *r, const sona_lighting *l);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `l` | `const sona_lighting *` | A [`sona_lighting`](reference/fields.md#sona_lighting) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Lighting and shadows](guides/lighting.md)):

```c
sona_lighting_defaults(&l);
l.key.direction[0] = 0.4f; l.key.direction[1] = -1.0f; l.key.direction[2] = 0.6f;
l.key.intensity = 0.9f;
l.flags = SONA_LIGHTING_GROUND | SONA_LIGHTING_PROXY_CASTERS;   /* a crowd's ground shadows for almost nothing */
sona_renderer_set_lighting(r, &l);
```

From the next draw. NULL: no lighting, the original look again. `SONA_E_ARGUMENT` for a size that is not sizeof(`sona_lighting`), a value out of range, an unknown flag or mode, a zero key direction with shadows on, or a matrix that is not orthographic.

### sona_renderer_lighting

```c
sona_result sona_renderer_lighting(const sona_renderer *r, sona_lighting *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_renderer *` | The renderer | required |
| `out` | `sona_lighting *` | Receives the [`sona_lighting`](reference/fields.md#sona_lighting) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_lighting x_lighting;
sona_lighting_defaults(&x_lighting);
sona_result result = sona_renderer_lighting(r, &x_lighting);
if (result != SONA_OK) printf("sona_renderer_lighting: %s\n", sona_result_name(result));
```

What is set; `SONA_E_NOT_FOUND` when none is.

### sona_draw_lit

```c
sona_result sona_draw_lit(sona_renderer *r, const sona_view *view, const sona_target *target, const sona_draw_options *opts, const sona_lighting *l);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](reference/fields.md#sona_target) | required |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |
| `l` | `const sona_lighting *` | A [`sona_lighting`](reference/fields.md#sona_lighting) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

`sona_draw` and `sona_snapshot` with l in place of the renderer's lighting for this one frame (one per view of a split screen); l NULL: the renderer's own. The checks of `sona_renderer_set_lighting`.

### sona_snapshot_lit

```c
sona_result sona_snapshot_lit(sona_renderer *r, const sona_view *view, uint32_t width, uint32_t height, const sona_draw_options *opts, const sona_lighting *l, uint8_t *rgba_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |
| `l` | `const sona_lighting *` | A [`sona_lighting`](reference/fields.md#sona_lighting) | required |
| `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

`sona_snapshot` with `l` in place of the renderer's lighting for this one picture; `l` NULL: the renderer's own. The checks of `sona_renderer_set_lighting`.

### sona_environment_defaults

```c
void sona_environment_defaults(sona_environment *e);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `e` | `sona_environment *` | The [`sona_environment`](reference/fields.md#sona_environment) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [Lighting and shadows](guides/lighting.md)):

```c
sona_environment e;
sona_environment_defaults(&e);
e.kind = SONA_ENV_SH9;                       /* or SONA_ENV_CUBE with cube_size and cube */
memcpy(e.sh, my_sh, sizeof e.sh);            /* 9 x RGB, radiance */
sona_renderer_set_environment(r, &e);        /* NULL: the built-in cube */
```

`size` set; `kind` BUILTIN, `skin_red` 1.2 (the built-in's).

### sona_renderer_set_environment

```c
sona_result sona_renderer_set_environment(sona_renderer *r, const sona_environment *e);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `e` | `const sona_environment *` | A [`sona_environment`](reference/fields.md#sona_environment) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Lighting and shadows](guides/lighting.md)):

```c
sona_environment e;
sona_environment_defaults(&e);
e.kind = SONA_ENV_SH9;                       /* or SONA_ENV_CUBE with cube_size and cube */
memcpy(e.sh, my_sh, sizeof e.sh);            /* 9 x RGB, radiance */
sona_renderer_set_environment(r, &e);        /* NULL: the built-in cube */
```

From the next lit draw. NULL: the built-in cube. `SONA_E_ARGUMENT` for a bad size, kind or cube.

### sona_environment_irradiance

```c
sona_result sona_environment_irradiance(const sona_environment *e, float out_sh[27]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `e` | `const sona_environment *` | A [`sona_environment`](reference/fields.md#sona_environment) | required |
| `out_sh` | `float [27]` | Receives nine RGB spherical-harmonic coefficients | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_environment x_environment;
sona_environment_defaults(&x_environment);
float x_out_sh2[27];
memset(x_out_sh2, 0, sizeof x_out_sh2);
sona_result result = sona_environment_irradiance(&x_environment, x_out_sh2);
if (result != SONA_OK) printf("sona_environment_irradiance: %s\n", sona_result_name(result));
```

The irradiance the shader evaluates for e (cube projected, convolved with the cosine lobe, divided by pi), in the basis above: a host lights its own scene the same way with it. `SONA_E_ARGUMENT` as above and for BUILTIN.

### sona_renderer_set_host_shadow

```c
sona_result sona_renderer_set_host_shadow(sona_renderer *r, const sona_host_shadow *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `s` | `const sona_host_shadow *` | A [`sona_host_shadow`](reference/fields.md#sona_host_shadow) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Lighting and shadows](guides/lighting.md)):

```c
sona_host_shadow h;
memset(&h, 0, sizeof h);
h.size = sizeof h;
memcpy(h.matrix, my_light_view_proj_to_uv, sizeof h.matrix);   /* world point to (u, v, depth, w) */
h.bias = 0.0015f;
h.width = h.height = 4096;
h.u.vk.view = my_depth_view;                 /* .gl.texture, .d3d11.srv, .d3d12.resource + .srv_format */
h.u.vk.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
sona_renderer_set_host_shadow(r, &h);
```

NULL: none. `SONA_E_UNSUPPORTED` on a backend without it (Metal), `SONA_E_ARGUMENT` for a bad size or handle.

### sona_renderer_shadow_map

```c
sona_result sona_renderer_shadow_map(const sona_renderer *r, sona_shadow_map *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `const sona_renderer *` | The renderer | required |
| `out` | `sona_shadow_map *` | Receives the [`sona_shadow_map`](reference/fields.md#sona_shadow_map) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_UNSUPPORTED` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Lighting and shadows](guides/lighting.md)):

```c
sona_shadow_map m;
m.size = sizeof m;
if (sona_renderer_shadow_map(r, &m) == SONA_OK) {
  /* m.matrix: world point (row vector) to (u, v, depth, 1); m.u.vk.view etc: the depth texture to sample */
}
```

`SONA_E_NOT_FOUND` before a lit frame with shadows; `SONA_E_UNSUPPORTED` on a backend without it.

## Loading placeholders

A neutral figure in the avatar's place while it loads, and avatars added before their manifest is known: [Loading placeholders](guides/placeholder.md).

### sona_placeholder_defaults

```c
void sona_placeholder_defaults(sona_placeholder_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_placeholder_options *` | The [`sona_placeholder_options`](reference/fields.md#sona_placeholder_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_placeholder_options x_placeholder_options;
memset(&x_placeholder_options, 0, sizeof x_placeholder_options);
x_placeholder_options.size = sizeof x_placeholder_options;
sona_placeholder_defaults(&x_placeholder_options);
```

`size` set; `delay_seconds` 0 (never a hole), `appear_seconds` 0.2, `reveal_seconds` 0.4, `failed_seconds` 2, `tint` 0.16, 0.19, 0.25 (a cool grey), `failed_tint` 0.25, 0.15, 0.15 (a muted red), `glow` 0.5.

### sona_placeholder_set

```c
sona_result sona_placeholder_set(sona_ctx *ctx, const sona_placeholder_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_placeholder_options *` | The options, a [`sona_placeholder_options`](reference/fields.md#sona_placeholder_options) | `NULL`: the defaults |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Loading placeholders](guides/placeholder.md)):

```c
sona_open(&cfg, &ctx);
sona_placeholder_set(ctx, NULL);         /* on, with the defaults */
sona_lod_set(ctx, NULL);                 /* optional: far figures become sprites too */

/* ... add avatars as usual; they show figures until READY ... */

while (game_running()) {               /* your game's loop */
  sona_update(ctx, dt, &view, NULL);     /* phases, timers, posing */
  sona_draw(renderer, &view, &target, NULL);
}
```

NULL: the defaults. `SONA_E_ARGUMENT` for a size that is not the struct's, a negative or non-finite time (each has a limit of 60 s), a colour outside 0..1 or reserved words that are not zero. Takes effect at the next `sona_update`.

### sona_placeholder_get

```c
sona_result sona_placeholder_get(const sona_ctx *ctx, sona_placeholder_options *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `out` | `sona_placeholder_options *` | Receives the [`sona_placeholder_options`](reference/fields.md#sona_placeholder_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_placeholder_options x_placeholder_options;
memset(&x_placeholder_options, 0, sizeof x_placeholder_options);
x_placeholder_options.size = sizeof x_placeholder_options;
sona_result result = sona_placeholder_get(ctx, &x_placeholder_options);
if (result != SONA_OK) printf("sona_placeholder_get: %s\n", sona_result_name(result));
```

`SONA_E_NOT_FOUND` while placeholders are off (out still gets the options last set, or the defaults).

### sona_placeholder_off

```c
sona_result sona_placeholder_off(sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_placeholder_off(ctx);
if (result != SONA_OK) printf("sona_placeholder_off: %s\n", sona_result_name(result));
```

Figures shown now fade out over appear_seconds.

### sona_avatar_placeholder

```c
sona_result sona_avatar_placeholder(sona_avatar *a, int32_t mode);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `mode` | `int32_t` | A `SONA_PLACEHOLDER_*` mode for this avatar | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_placeholder(avatar, 0);
if (result != SONA_OK) printf("sona_avatar_placeholder: %s\n", sona_result_name(result));
```

Per avatar: -1 follows the ctx (the default), 0 never, 1 always (with the ctx's options, or the defaults).

### sona_avatar_placeholder_info

```c
sona_result sona_avatar_placeholder_info(const sona_avatar *a, sona_placeholder_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_placeholder_info *` | Receives the [`sona_placeholder_info`](reference/fields.md#sona_placeholder_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_placeholder_info x_placeholder_info;
memset(&x_placeholder_info, 0, sizeof x_placeholder_info);
x_placeholder_info.size = sizeof x_placeholder_info;
sona_result result = sona_avatar_placeholder_info(avatar, &x_placeholder_info);
if (result != SONA_OK) printf("sona_avatar_placeholder_info: %s\n", sona_result_name(result));
```

The avatar's figure at the last `sona_update`: its phase, opacity, height, which figure (male, female or neutral), whether it plays the avatar's clip, the seconds since the avatar was added and whether it is drawn as a sprite.

### sona_placeholder_stats_get

```c
void sona_placeholder_stats_get(const sona_ctx *ctx, sona_placeholder_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `out` | `sona_placeholder_stats *` | Receives the [`sona_placeholder_stats`](reference/fields.md#sona_placeholder_stats) | required |

**Returns** Nothing.

**Example**:

```c
sona_placeholder_stats x_placeholder_stats;
memset(&x_placeholder_stats, 0, sizeof x_placeholder_stats);
x_placeholder_stats.size = sizeof x_placeholder_stats;
sona_placeholder_stats_get(ctx, &x_placeholder_stats);
```

Figures in view at the last `sona_update` (by phase, and how many as sprites), how many were posed and the time that took, and the figure draws of the last `sona_draw` or `sona_snapshot`.

### sona_avatar_add_waiting

```c
sona_result sona_avatar_add_waiting(sona_ctx *ctx, const sona_add_options *opts, sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](reference/fields.md#sona_add_options) | required |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Loading placeholders](guides/placeholder.md)):

```c
sona_avatar *seat;
sona_avatar_add_waiting(ctx, &opts, &seat);         /* QUEUED, the neutral figure */
/* ... later, when the network brings the manifest ... */
sona_avatar_set_manifest_base64(seat, b64);         /* now it loads like any avatar */
```

An avatar whose manifest is not known, as for a player joining before their profile arrives. It stays QUEUED and shows the neutral figure (with placeholders on) until `sona_avatar_set_manifest` gives it its manifest, once; then it loads as if it had been added with it. Placement, play, layers and the rest work on it as on any avatar. `sona_avatar_set_manifest`: `SONA_E_ARGUMENT` for an avatar not added waiting or already given one. A bad manifest fails the avatar later with `SONA_E_MANIFEST`, as `sona_avatar_add`.

### sona_avatar_set_manifest

```c
sona_result sona_avatar_set_manifest(sona_avatar *a, const uint8_t manifest[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_set_manifest(avatar, manifest);
if (result != SONA_OK) printf("sona_avatar_set_manifest: %s\n", sona_result_name(result));
```

Gives an avatar added with `sona_avatar_add_waiting` its manifest, once; it then loads as if it had been added with it. `SONA_E_ARGUMENT` for an avatar not added waiting or already given one.

### sona_avatar_set_manifest_base64

```c
sona_result sona_avatar_set_manifest_base64(sona_avatar *a, const char *b64);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `b64` | `const char *` | The manifest as base64 text, at most 4096 characters | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Loading placeholders](guides/placeholder.md)):

```c
sona_avatar *seat;
sona_avatar_add_waiting(ctx, &opts, &seat);         /* QUEUED, the neutral figure */
/* ... later, when the network brings the manifest ... */
sona_avatar_set_manifest_base64(seat, b64);         /* now it loads like any avatar */
```

`sona_avatar_set_manifest` with the manifest as base64 text.

## Overlays

A picture the host draws on the CPU, blended over the frame by the renderer: [Overlays](guides/overlay.md).

### sona_renderer_overlay

```c
sona_result sona_renderer_overlay(sona_renderer *r, const sona_overlay *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `o` | `const sona_overlay *` | A [`sona_overlay`](reference/fields.md#sona_overlay) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Overlays: a picture over the frame](guides/overlay.md)):

```c
sona_overlay o;
memset(&o, 0, sizeof o);
o.size = sizeof o;
o.width = hud_w;
o.height = hud_h;
o.rgba = hud_pixels;          /* straight RGBA8, row 0 at the top; read during the call only */
o.revision = hud_revision;    /* the same as the last call's: nothing is uploaded */
o.dirty[0] = x; o.dirty[1] = y; o.dirty[2] = w; o.dirty[3] = h;   /* what changed; w 0: all of it */
/* o.rect: where it lands in the target, pixels from the top left; w 0: the whole target */
sona_renderer_overlay(renderer, &o);
sona_draw(renderer, &view, &target, &opts);   /* the avatars, the credit, then the overlay */
sona_renderer_overlay(renderer, NULL);        /* the next draws have none (the texture is kept) */
```

Sets r's overlay for every `sona_draw` that follows, until the next call. o NULL takes it away (its texture is kept for the next one of the same size). After `sona_renderer_reset` or a lost device, set it again. `SONA_E_ARGUMENT` for a bad size or stride, a dirty rectangle outside the picture, or no rgba; `SONA_E_LIMIT` past the largest texture.

### sona_renderer_underlay

```c
sona_result sona_renderer_underlay(sona_renderer *r, const sona_overlay *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `o` | `const sona_overlay *` | A [`sona_overlay`](reference/fields.md#sona_overlay) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_overlay x_overlay;
memset(&x_overlay, 0, sizeof x_overlay);
x_overlay.size = sizeof x_overlay;
sona_result result = sona_renderer_underlay(r, &x_overlay);
if (result != SONA_OK) printf("sona_renderer_underlay: %s\n", sona_result_name(result));
```

A picture behind the avatars, as a page's backdrop behind a clear canvas: drawn first in the main pass at o->rect (w or h 0: the whole target), for every `sona_draw` and `sona_snapshot` until the next call; NULL takes it away. The frame's bloom runs over it as over the avatars. The editor draws 360sona.com's stage gradient this way. GL and Vulkan have it; on the other backends it returns `SONA_E_UNSUPPORTED` and the frame's clear shows.

## Props: held and worn objects

Your own meshes and glTF files, and the catalogue's stock props and pets, in an avatar's hands or on any joint: [Props](guides/props.md).

### sona_prop_part_defaults

```c
void sona_prop_part_defaults(sona_prop_part *p);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `p` | `sona_prop_part *` | The [`sona_prop_part`](reference/fields.md#sona_prop_part) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_prop_part x_prop_part;
sona_prop_part_defaults(&x_prop_part);
sona_prop_part_defaults(&x_prop_part);
```

`size` set; `colour` 0xffffffff.

### sona_prop_load_defaults

```c
void sona_prop_load_defaults(sona_prop_load_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_prop_load_options *` | The [`sona_prop_load_options`](reference/fields.md#sona_prop_load_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_prop_load_options x_prop_load_options;
memset(&x_prop_load_options, 0, sizeof x_prop_load_options);
x_prop_load_options.size = sizeof x_prop_load_options;
sona_prop_load_defaults(&x_prop_load_options);
```

`size` set; `scale` 1.

### sona_prop_mesh_create

```c
sona_result sona_prop_mesh_create(sona_ctx *ctx, const sona_prop_part *parts, uint32_t count, sona_prop_mesh **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `parts` | `const sona_prop_part *` | A [`sona_prop_part`](reference/fields.md#sona_prop_part) | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `out` | `sona_prop_mesh **` | Receives the new prop mesh | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

A mesh from the host's triangles; the data is copied. `SONA_E_ARGUMENT` for a bad part, `SONA_E_LIMIT` past 64 parts.

### sona_prop_mesh_load

```c
sona_result sona_prop_mesh_load(sona_ctx *ctx, const void *bytes, size_t len, const sona_prop_load_options *o, sona_prop_mesh **out, char *why, size_t why_cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `bytes` | `const void *` | The file's bytes | required |
| `len` | `size_t` | How many bytes there are | - |
| `o` | `const sona_prop_load_options *` | The options, a [`sona_prop_load_options`](reference/fields.md#sona_prop_load_options) | required |
| `out` | `sona_prop_mesh **` | Receives the new prop mesh | required |
| `why` | `char *` | Receives what was refused, NUL-terminated; may be NULL | `NULL`: not written |
| `why_cap` | `size_t` | How many bytes `why` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

A glTF 2.0 file (.glb, or .gltf with its buffers embedded) as a prop: every triangle primitive of the scene's nodes, their transforms applied, one part per primitive with its base colour (factor, texture, vertex colours), alpha mode BLEND as transparent, +Y up, z negated into the avatar's left-handed space (the same mirror as the glTF export and the clip importer). Skins and morph targets are ignored (the bind pose is drawn). Images are PNG or JPEG. why (may be NULL) gets the reason for a refusal: `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED` (this build reads no glTF), `SONA_E_LIMIT` (a primitive over 65536 vertices or 64 parts), `SONA_E_NOT_FOUND` (no triangles). o may be NULL.

### sona_prop_mesh_open

```c
sona_result sona_prop_mesh_open(sona_ctx *ctx, const char *path, const sona_prop_load_options *o, sona_prop_mesh **out, char *why, size_t why_cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `path` | `const char *` | A file path | required |
| `o` | `const sona_prop_load_options *` | The options, a [`sona_prop_load_options`](reference/fields.md#sona_prop_load_options) | required |
| `out` | `sona_prop_mesh **` | Receives the new prop mesh | required |
| `why` | `char *` | Receives what was refused, NUL-terminated; may be NULL | `NULL`: not written |
| `why_cap` | `size_t` | How many bytes `why` holds | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_IO` ([what each means](troubleshooting.md#error-codes)).

The same from a path (UTF-8): a .gltf's buffers and images next to it are read too. `SONA_E_IO` when it cannot be read.

### sona_prop_mesh_stock

```c
sona_result sona_prop_mesh_stock(sona_ctx *ctx, const char *item_id, sona_prop_mesh **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `item_id` | `const char *` | An item id as text | required |
| `out` | `sona_prop_mesh **` | Receives the new prop mesh | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

A stock prop item (a carryable: mask 0x1000, such as the pets of `sona_prop_pet`) with its own skeleton and clip, read through the ctx's sources like a worn item. Returns at once; `sona_prop_mesh_state` is `SONA_PENDING` until it has loaded. It can be attached meanwhile and is drawn once it is ready. Attached with `SONA_PROP_JOINT_AUTO` it sits as the site's held props do: in the hand its clip grips it in at its grip frame, or, for one no hand holds (most pets), where its clip puts it beside the avatar. `SONA_E_ARGUMENT` for an id that is not a prop item.

### sona_prop_mesh_state

```c
sona_result sona_prop_mesh_state(const sona_prop_mesh *m);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const sona_prop_mesh *` | The prop mesh | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

`SONA_OK`, `SONA_PENDING`, or why it failed (`SONA_E_NOT_FOUND`: no source has it).

### sona_prop_mesh_release

```c
void sona_prop_mesh_release(sona_prop_mesh *m);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `sona_prop_mesh *` | The prop mesh | required |

**Returns** Nothing.

The host's reference goes; avatars it is attached to keep it until they detach it.

### sona_prop_mesh_info_get

```c
sona_result sona_prop_mesh_info_get(const sona_prop_mesh *m, sona_prop_mesh_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const sona_prop_mesh *` | The prop mesh | required |
| `out` | `sona_prop_mesh_info *` | Receives the [`sona_prop_mesh_info`](reference/fields.md#sona_prop_mesh_info) | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

`SONA_PENDING` (only kind and item set) until the mesh is ready.

### sona_prop_mesh_data

```c
sona_result sona_prop_mesh_data(const sona_prop_mesh *m, sona_prop_data *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const sona_prop_mesh *` | The prop mesh | required |
| `out` | `sona_prop_data *` | Receives the [`sona_prop_data`](reference/fields.md#sona_prop_data) | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

`SONA_PENDING` until ready.

### sona_prop_attach_defaults

```c
void sona_prop_attach_defaults(sona_prop_attach *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_prop_attach *` | The [`sona_prop_attach`](reference/fields.md#sona_prop_attach) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_prop_attach x_prop_attach;
sona_prop_attach_defaults(&x_prop_attach);
sona_prop_attach_defaults(&x_prop_attach);
```

`size` set; `position` 0, `rotation` 0 0 0 1, `scale` 1, `hand_weight` 1, `fade_seconds` 0.2, `speed` 1.

### sona_avatar_prop_attach

```c
sona_result sona_avatar_prop_attach(sona_avatar *a, sona_prop_mesh *m, const sona_prop_attach *o, uint32_t *id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `m` | `sona_prop_mesh *` | The prop mesh | required |
| `o` | `const sona_prop_attach *` | A [`sona_prop_attach`](reference/fields.md#sona_prop_attach) | required |
| `id` | `uint32_t *` | Receives the new prop's id | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Attaches m to the avatar (READY or not; a prop on an avatar that is not READY waits for it). *id (may be NULL) names it on this avatar from then on. The hand, when set, takes that hand's IK target (`sona_avatar_ik_target`) while the prop has it. NULL o: defaults. `SONA_E_LIMIT` past `SONA_PROP_MAX`; `SONA_E_ARGUMENT` for a bad size, flag, joint, hand, quaternion or scale, or a mesh of another ctx.

### sona_avatar_prop_set

```c
sona_result sona_avatar_prop_set(sona_avatar *a, uint32_t id, const sona_prop_attach *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `id` | `uint32_t` | The id, as the call that made it gave it | - |
| `o` | `const sona_prop_attach *` | A [`sona_prop_attach`](reference/fields.md#sona_prop_attach) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_prop_attach x_prop_attach;
sona_prop_attach_defaults(&x_prop_attach);
sona_result result = sona_avatar_prop_set(avatar, 0, &x_prop_attach);
if (result != SONA_OK) printf("sona_avatar_prop_set: %s\n", sona_result_name(result));
```

New placement, flags or hand for an attached prop (each frame for one that moves on the joint).

### sona_avatar_prop_swap

```c
sona_result sona_avatar_prop_swap(sona_avatar *a, uint32_t id, sona_prop_mesh *m);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `id` | `uint32_t` | The id, as the call that made it gave it | - |
| `m` | `sona_prop_mesh *` | The prop mesh | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

Another mesh in the same place: a sword for a stick, an item for a placeholder. The prop clock starts again.

### sona_avatar_prop_get

```c
sona_result sona_avatar_prop_get(const sona_avatar *a, uint32_t id, sona_prop_attach *out, sona_prop_mesh **mesh);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `id` | `uint32_t` | The id, as the call that made it gave it | - |
| `out` | `sona_prop_attach *` | Receives the [`sona_prop_attach`](reference/fields.md#sona_prop_attach) | required |
| `mesh` | `sona_prop_mesh **` | Receives the new prop mesh | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

What the prop was attached with, and its mesh (either may be NULL). `SONA_E_NOT_FOUND` for an id it does not have.

### sona_avatar_prop_detach

```c
sona_result sona_avatar_prop_detach(sona_avatar *a, uint32_t id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `id` | `uint32_t` | The id, as the call that made it gave it | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_prop_detach(avatar, 0);
if (result != SONA_OK) printf("sona_avatar_prop_detach: %s\n", sona_result_name(result));
```

Takes the prop off at once (its hand's IK target eases off). `SONA_E_NOT_FOUND` for an id it does not have.

### sona_avatar_prop_detach_all

```c
void sona_avatar_prop_detach_all(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example**:

```c
sona_avatar_prop_detach_all(avatar);
```

Takes every prop off the avatar at once.

### sona_avatar_prop_list

```c
uint32_t sona_avatar_prop_list(const sona_avatar *a, uint32_t *ids, uint32_t max);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `ids` | `uint32_t *` | Receives the ids; may be NULL to count | `NULL`: not written |
| `max` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

The ids of the avatar's props in attach order: writes up to max (ids may be NULL), returns how many it has.

### sona_avatar_prop_frame

```c
sona_result sona_avatar_prop_frame(const sona_avatar *a, uint32_t id, sona_prop_frame *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `id` | `uint32_t` | The id, as the call that made it gave it | - |
| `out` | `sona_prop_frame *` | Receives the [`sona_prop_frame`](reference/fields.md#sona_prop_frame) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_prop_frame x_prop_frame;
memset(&x_prop_frame, 0, sizeof x_prop_frame);
x_prop_frame.size = sizeof x_prop_frame;
sona_result result = sona_avatar_prop_frame(avatar, 0, &x_prop_frame);
if (result != SONA_OK) printf("sona_avatar_prop_frame: %s\n", sona_result_name(result));
```

Where an attached prop is this frame: the joint it is on, the time into its own clip, its frame in the world and in avatar space, how far the second hand is from its point on the prop (metres), and the palette of a skinned prop, valid until the next `sona_update`.

### sona_avatar_prop_vertices

```c
sona_result sona_avatar_prop_vertices(sona_avatar *a, uint32_t id, uint32_t mesh, uint32_t space, float *positions, float *normals, size_t stride_floats);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `id` | `uint32_t` | The id, as the call that made it gave it | - |
| `mesh` | `uint32_t` | A mesh index of the pose data | - |
| `space` | `uint32_t` | `SONA_SPACE_*`: the space the vertices come back in | - |
| `positions` | `float *` | Receives the positions | required |
| `normals` | `float *` | Receives the normals, or NULL | `NULL`: not written |
| `stride_floats` | `size_t` | Floats from one vertex to the next in the output | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

`sona_pose_vertices` for one of the prop's meshes (`sona_prop_data`.meshes): CPU skinning, `SONA_SPACE_AVATAR` or _WORLD. `SONA_E_NOT_READY` before it has been posed with a ready mesh.

### sona_prop_pet_count

```c
uint32_t sona_prop_pet_count(void);
```

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_prop_pet_count();
printf("sona_prop_pet_count: %lld\n", (long long)x_got);
```

How many of the catalogue's pets there are: stock prop items that are animals or creature companions, as the site's pet mode lists them, for `sona_prop_mesh_stock`.

### sona_prop_pet

```c
sona_result sona_prop_pet(uint32_t index, sona_guid *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_guid *` | Receives the [`sona_guid`](reference/fields.md#sona_guid) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_guid x_guid;
memset(&x_guid, 0, sizeof x_guid);
sona_result result = sona_prop_pet(0, &x_guid);
if (result != SONA_OK) printf("sona_prop_pet: %s\n", sona_result_name(result));
```

`SONA_E_ARGUMENT` past the last.

### sona_prop_is_pet

```c
int sona_prop_is_pet(const char *item_id);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `item_id` | `const char *` | An item id as text | required |

**Returns** `int`.

**Example**:

```c
int x_got = sona_prop_is_pet("00400000-0003-0003-c1c8-f109a19cb2e0");
printf("sona_prop_is_pet: %lld\n", (long long)x_got);
```

1 when the item id is one of the pets.

## Ragdolls

Bodies fitted to the avatar for the host's physics engine, and the handoff to a ragdoll and back: [Physics-ready avatars](guides/physics.md).

### sona_ragdoll_defaults

```c
void sona_ragdoll_defaults(sona_ragdoll_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_ragdoll_options *` | The [`sona_ragdoll_options`](reference/fields.md#sona_ragdoll_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_ragdoll_options x_ragdoll_options;
memset(&x_ragdoll_options, 0, sizeof x_ragdoll_options);
x_ragdoll_options.size = sizeof x_ragdoll_options;
sona_ragdoll_defaults(&x_ragdoll_options);
```

`size` set; `coverage` 0.9.

### sona_avatar_ragdoll

```c
sona_result sona_avatar_ragdoll(sona_avatar *a, const sona_ragdoll_options *o, sona_ragdoll_body *out, uint32_t cap, uint32_t *count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_ragdoll_options *` | The options, a [`sona_ragdoll_options`](reference/fields.md#sona_ragdoll_options) | required |
| `out` | `sona_ragdoll_body *` | Receives the [`sona_ragdoll_body`](reference/fields.md#sona_ragdoll_body) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |
| `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Fits the bodies to the avatar as it is now (its rig, body shape and outfit) and writes up to cap of them; count (may be NULL) gets `SONA_RAGDOLL_BODIES`. The same avatar and options give the same bits. From this call on, each pose keeps the bodies' last two transforms for `sona_avatar_ragdoll_state`. `SONA_E_NOT_READY` before the avatar is READY and posed; `SONA_E_ARGUMENT` for a bad size, flag, mass or coverage.

### sona_avatar_ragdoll_state

```c
sona_result sona_avatar_ragdoll_state(const sona_avatar *a, sona_ragdoll_state *out, uint32_t cap, uint32_t *count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_ragdoll_state *` | Receives the [`sona_ragdoll_state`](reference/fields.md#sona_ragdoll_state) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |
| `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

The bodies at the last pose, with velocities from the last two poses (on the scene clock; zero until there have been two). For the host's bodies when it takes over. `SONA_E_NOT_READY` before `sona_avatar_ragdoll`.

### sona_avatar_ragdoll_drive

```c
sona_result sona_avatar_ragdoll_drive(sona_avatar *a, const sona_ragdoll_state *bodies, uint32_t count, float weight, uint32_t flags);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `bodies` | `const sona_ragdoll_state *` | A [`sona_ragdoll_state`](reference/fields.md#sona_ragdoll_state) | required |
| `count` | `uint32_t` | How many entries the array holds | - |
| `weight` | `float` | How much of the host's bodies to show over the clip, 0 to 1 | - |
| `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ragdoll_state x_ragdoll_state;
memset(&x_ragdoll_state, 0, sizeof x_ragdoll_state);
sona_result result = sona_avatar_ragdoll_drive(avatar, &x_ragdoll_state, 1, 0.5f, 0);
if (result != SONA_OK) printf("sona_avatar_ragdoll_drive: %s\n", sona_result_name(result));
```

The host's simulated bodies onto the avatar: from the next pose it draws them, until released. `count` is `SONA_RAGDOLL_BODIES`; velocities are not read. `weight` 0..1 blends from the clip's pose (0.3: a hit reaction); every joint between bodies (fingers, toes, the neck, the face) keeps its clip pose relative to its body. Call it after each physics step. `SONA_RAGDOLL_KEEP_LENGTHS`: only the bodies' turns and the hips' position are taken, so the bones keep their lengths. `SONA_E_ARGUMENT` for a bad count, weight or flag, or a body that is not finite.

### sona_avatar_ragdoll_release

```c
sona_result sona_avatar_ragdoll_release(sona_avatar *a, float blend_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `blend_seconds` | `float` | Seconds over which the ragdoll blends back to the clip | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_ragdoll_release(avatar, 0.5f);
if (result != SONA_OK) printf("sona_avatar_ragdoll_release: %s\n", sona_result_name(result));
```

Back to the animation: the last drawn ragdoll pose stays where it is in the world and blends into the clip's pose over blend_seconds (smoothstep; 0: at once), turn by turn down the body, so limbs stay joined. Play the get-up clip and move the placement to `sona_ragdoll_info`'s getup_position and getup_turn_deg first.

### sona_avatar_ragdoll_info

```c
sona_result sona_avatar_ragdoll_info(const sona_avatar *a, sona_ragdoll_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_ragdoll_info *` | Receives the [`sona_ragdoll_info`](reference/fields.md#sona_ragdoll_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_ragdoll_info x_ragdoll_info;
memset(&x_ragdoll_info, 0, sizeof x_ragdoll_info);
x_ragdoll_info.size = sizeof x_ragdoll_info;
sona_result result = sona_avatar_ragdoll_info(avatar, &x_ragdoll_info);
if (result != SONA_OK) printf("sona_avatar_ragdoll_info: %s\n", sona_result_name(result));
```

`SONA_E_NOT_READY` before the avatar has been posed since `sona_avatar_ragdoll`.

### sona_avatar_ragdoll_clear

```c
void sona_avatar_ragdoll_clear(sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

**Example**:

```c
sona_avatar_ragdoll_clear(avatar);
```

Off at once: no tracking, no drive, no blend.

### sona_avatar_ragdoll_motors

```c
sona_result sona_avatar_ragdoll_motors(const sona_avatar *a, sona_ragdoll_motor *out, uint32_t cap, uint32_t *count);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_ragdoll_motor *` | Receives the [`sona_ragdoll_motor`](reference/fields.md#sona_ragdoll_motor) | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |
| `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

The targets of the last pose, velocities from the last two (zero until there have been two). count (may be NULL) gets `SONA_RAGDOLL_BODIES`. `SONA_E_NOT_READY` before `sona_avatar_ragdoll`. The stock get-up clips are "getup_back" and "getup_front" ([physics guide](guides/physics.md), "Getting up").

## Two-avatar interactions and seats

High fives, handshakes, hugs, holding hands and sitting, with the avatars placed and their hands and hips meeting: [Two-avatar interactions](guides/interactions.md).

### sona_seat_defaults

```c
void sona_seat_defaults(sona_seat *s, uint32_t kind);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_seat *` | The [`sona_seat`](reference/fields.md#sona_seat) to fill with the defaults | required |
| `kind` | `uint32_t` | Which kind, one of the header's constants for it | - |

**Returns** Nothing.

**Example** (also in [Two-avatar interactions and seats](guides/interactions.md)):

```c
sona_interaction_defaults(&d, SONA_INTERACT_SIT);
d.a = adult; d.b = child;          /* b NULL: one sitter */
d.flags = SONA_INTERACT_HANDS;     /* two sitters: the near hands hold */
sona_seat_defaults(&d.seat, SONA_SEAT_BENCH);
d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f;   /* the front edge's middle, on top */
d.seat.turn_deg = 0;               /* the way they face */
sona_interaction_start(ctx, &d, &it);
```

`size` set and a seat of that kind: `height` 0.45 (0 for GROUND), `depth` 0.45 (unlimited for GROUND), `width` 0.5 for a chair, 1.4 for a bench and unlimited on the ground.

### sona_interaction_defaults

```c
void sona_interaction_defaults(sona_interaction_desc *d, uint32_t kind);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `d` | `sona_interaction_desc *` | The [`sona_interaction_desc`](reference/fields.md#sona_interaction_desc) to fill with the defaults | required |
| `kind` | `uint32_t` | Which kind, one of the header's constants for it | - |

**Returns** Nothing.

**Example** (also in [Two-avatar interactions and seats](guides/interactions.md)):

```c
sona_interaction_defaults(&d, SONA_INTERACT_SIT);
d.a = adult; d.b = child;          /* b NULL: one sitter */
d.flags = SONA_INTERACT_HANDS;     /* two sitters: the near hands hold */
sona_seat_defaults(&d.seat, SONA_SEAT_BENCH);
d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f;   /* the front edge's middle, on top */
d.seat.turn_deg = 0;               /* the way they face */
sona_interaction_start(ctx, &d, &it);
```

Sets size, kind, the kind's default timings in seconds (high five 0.8, 0.15, 0.7; handshake 0.9, 1.6, 0.8; hug 1.1, 2.5, 1.0; hold hands 0.8, 0, 0.6; sit 1.3, 0, 1.4) and a default seat.

### sona_interaction_layout

```c
sona_result sona_interaction_layout(const sona_interaction_desc *d, sona_interaction_plan *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `d` | `const sona_interaction_desc *` | The options, a [`sona_interaction_desc`](reference/fields.md#sona_interaction_desc) | required |
| `out` | `sona_interaction_plan *` | Receives the [`sona_interaction_plan`](reference/fields.md#sona_interaction_plan) | required |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_interaction_desc x_interaction_desc;
memset(&x_interaction_desc, 0, sizeof x_interaction_desc);
x_interaction_desc.size = sizeof x_interaction_desc;
sona_interaction_plan x_interaction_plan2;
memset(&x_interaction_plan2, 0, sizeof x_interaction_plan2);
x_interaction_plan2.size = sizeof x_interaction_plan2;
sona_result result = sona_interaction_layout(&x_interaction_desc, &x_interaction_plan2);
if (result != SONA_OK) printf("sona_interaction_layout: %s\n", sona_result_name(result));
```

`SONA_E_ARGUMENT` for a bad desc (sizes, kind, flags, timings, a missing or repeated avatar, a seat too narrow for two), `SONA_E_NOT_READY` until both avatars are READY, and for SIT `SONA_PENDING` until the stock sit clip has been read (the call asks the sources for it; call again). Owner thread only, like `sona_interaction_start`: it measures both bodies (a few milliseconds) and may read the clip into the ctx.

### sona_interaction_start

```c
sona_result sona_interaction_start(sona_ctx *ctx, const sona_interaction_desc *d, sona_interaction **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `d` | `const sona_interaction_desc *` | The options, a [`sona_interaction_desc`](reference/fields.md#sona_interaction_desc) | required |
| `out` | `sona_interaction **` | Receives the new interaction | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Two-avatar interactions and seats](guides/interactions.md)):

```c
sona_interaction_defaults(&d, SONA_INTERACT_SIT);
d.a = adult; d.b = child;          /* b NULL: one sitter */
d.flags = SONA_INTERACT_HANDS;     /* two sitters: the near hands hold */
sona_seat_defaults(&d.seat, SONA_SEAT_BENCH);
d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f;   /* the front edge's middle, on top */
d.seat.turn_deg = 0;               /* the way they face */
sona_interaction_start(ctx, &d, &it);
```

Starts it: the avatars are placed (eased over the first part of the start phase when they are near), their clips started together and their IK targets driven from now on. An avatar in another running interaction is refused (`SONA_E_ARGUMENT`); `SONA_E_LIMIT` when the ctx holds 64, finished ones included: an interaction is freed only by `sona_interaction_remove` (or `sona_close`), so a handle stays valid until the host removes it.

### sona_interaction_end

```c
sona_result sona_interaction_end(sona_interaction *it);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

Begins the end phase now (a hold of 0 waits for this). No effect once ending.

### sona_interaction_move

```c
sona_result sona_interaction_move(sona_interaction *it, const float position[3], float turn_deg);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |
| `position` | `const float [3]` | Where to move it, world space | required |
| `turn_deg` | `float` | Which way it faces, degrees | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](troubleshooting.md#error-codes)).

Moves the place (and the seat with it) while it runs, for a pair walking hand in hand; contacts follow.

### sona_interaction_remove

```c
void sona_interaction_remove(sona_interaction *it);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |

**Returns** Nothing.

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_interaction_desc d;
sona_interaction *it;
sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE);
d.a = avatar;
d.b = other;
if (sona_interaction_start(ctx, &d, &it) == SONA_OK) {
  /* each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) */
}
```

Stops at once and frees it: its IK targets go, the avatars stay where they are and keep their clip.

### sona_interaction_status_get

```c
sona_result sona_interaction_status_get(const sona_interaction *it, sona_interaction_status *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `const sona_interaction *` | The interaction | required |
| `out` | `sona_interaction_status *` | Receives the [`sona_interaction_status`](reference/fields.md#sona_interaction_status) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Where an interaction is: its kind and phase, the time in the phase and how far through it, whether the contacts are together, the widest gap at a contact, the clearance between the two bodies (negative: into each other), the contact points now and the IK hit bits of both avatars' limbs.

### sona_interaction_events

```c
uint32_t sona_interaction_events(sona_interaction *it, sona_interaction_event *out, uint32_t max);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `it` | `sona_interaction *` | The interaction | required |
| `out` | `sona_interaction_event *` | Receives the [`sona_interaction_event`](reference/fields.md#sona_interaction_event) | required |
| `max` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_interaction_desc d;
sona_interaction *it;
sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE);
d.a = avatar;
d.b = other;
if (sona_interaction_start(ctx, &d, &it) == SONA_OK) {
  /* each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) */
}
```

Moves up to `max` events since the last call into `out` (`SONA_INTERACT_EV_*`: contact, a handshake pump, release, end, cancel) and returns how many.

## Text to emote

A sentence to stock clips and a face: [Text to emote](guides/emote.md).

### sona_emote_from_text

```c
sona_result sona_emote_from_text(const char *text, sona_emote *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `text` | `const char *` | A sentence, such as `"wave excitedly"` | required |
| `out` | `sona_emote *` | Receives the [`sona_emote`](reference/fields.md#sona_emote) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_emote e = { sizeof e };
if (sona_emote_from_text("jump for joy", &e) == SONA_OK && e.count > 0)
  sona_avatar_emote(avatar, &e, 0.25f);
```

A sentence in ("wave excitedly", "shrug, not sure"), stock clips and a face out: up to four clips with weights to blend, a speed and an expression. Pure, no ctx: the same text gives the same answer. `count` 0 with a face is a mood with no action ("smile"). Set `out->size` first. [Text to emote](guides/emote.md) has the table.

### sona_avatar_emote

```c
sona_result sona_avatar_emote(sona_avatar *a, const sona_emote *e, float fade_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `e` | `const sona_emote *` | A [`sona_emote`](reference/fields.md#sona_emote) | required |
| `fade_seconds` | `float` | Seconds to blend over | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [Cookbook: recipes for game moments](cookbook.md)):

```c
sona_emote e = { sizeof e };
if (sona_emote_from_text("jump for joy", &e) == SONA_OK && e.count > 0)
  sona_avatar_emote(avatar, &e, 0.25f);
```

Plays it on a: the clips blended on the emote layers (`SONA_LAYER_MAX` - count to `SONA_LAYER_MAX` - 1, each over the ones below by its share of the weight), faded in over fade_seconds; the face set when it has one. An emote plays once and hands back to the clip, but a dance, sleep, hover or run loops until the next emote. count 0 with no face stops the emote's layers and hands the face back. It never stops a layer the app played (a layer it played is the app's once the app plays anything on it): `SONA_E_LIMIT`, with nothing changed, when one is on a layer the emote needs. `SONA_E_MEMORY` also changes nothing.

## Award items

Items a game defines and unlocks for its signed-in players, who then wear them in their 360sona wardrobe: [custom items: award items](guides/custom-items.md#award-items-from-your-own-game).

### sona_award_def_defaults

```c
void sona_award_def_defaults(sona_award_def *d);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `d` | `sona_award_def *` | The [`sona_award_def`](reference/fields.md#sona_award_def) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_award_def x_award_def;
sona_award_def_defaults(&x_award_def);
sona_award_def_defaults(&x_award_def);
```

`size` set and everything else zero.

### sona_award_define

```c
sona_result sona_award_define(sona_ctx *ctx, const sona_award_def *d, uint32_t *ticket);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `d` | `const sona_award_def *` | The options, a [`sona_award_def`](reference/fields.md#sona_award_def) | required |
| `ticket` | `uint32_t *` | Receives a ticket for `sona_award_poll` | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_APP` ([what each means](troubleshooting.md#error-codes)).

Defines an award item for an app with the app's developer key (a tool's call, never a shipped game's). It goes to `config.check_host` through the ctx's HTTP layer and gives a ticket: `sona_award_poll` after `sona_update` says how it went.

### sona_award_unlock

```c
sona_result sona_award_unlock(sona_ctx *ctx, const char *player_token, const char *key, uint32_t *ticket);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `player_token` | `const char *` | The signed-in player's access token | required |
| `key` | `const char *` | The award's key | required |
| `ticket` | `uint32_t *` | Receives a ticket for `sona_award_poll` | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_APP` ([what each means](troubleshooting.md#error-codes)).

`player_token`: the signed-in player's access token (Sign in with 360sona).

### sona_award_poll

```c
sona_result sona_award_poll(sona_ctx *ctx, uint32_t ticket);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `ticket` | `uint32_t` | The ticket the request gave | - |

**Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_IO`, `SONA_E_GATE`, `SONA_E_APP` ([what each means](troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_award_poll(ctx, 0);
if (result != SONA_OK) printf("sona_award_poll: %s\n", sona_result_name(result));
```

`SONA_PENDING` while it runs, then its result once: `SONA_OK`, `SONA_E_NOT_FOUND` (no such award), `SONA_E_APP` (a wrong key or token, or no awards scope), `SONA_E_ARGUMENT` (refused; see `sona_last_error`), `SONA_E_LIMIT`, `SONA_E_GATE` or `SONA_E_IO`.

## Body tracking module (sona_body.h)

An optional library, `sona_body`, beside the core: webcam full-body pose to the avatar. Include `sona_body.h` and link `sona_body`. The guide: [Body tracking (sona_body)](guides/body-tracking.md).

### sona_body_defaults

```c
void sona_body_defaults(sona_body_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_body_options *` | The [`sona_body_options`](reference/fields.md#sona_body_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_body_options x_body_options;
memset(&x_body_options, 0, sizeof x_body_options);
x_body_options.size = sizeof x_body_options;
sona_body_defaults(&x_body_options);
```

`size` set; `min_cutoff` 1.5, `beta` 0.8, `min_visibility` 0.5, `lost_seconds` 0.5, `return_seconds` 0.4.

### sona_body_create

```c
sona_result sona_body_create(const sona_body_options *o, sona_body_tracker **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_body_options *` | The options, a [`sona_body_options`](reference/fields.md#sona_body_options) | `NULL`: the defaults |
| `out` | `sona_body_tracker **` | Receives the new body tracker | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

NULL options: the defaults. `SONA_E_ARGUMENT` for a wrong size or a value out of range.

### sona_body_destroy

```c
void sona_body_destroy(sona_body_tracker *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |

**Returns** Nothing.

Frees the tracker.

### sona_body_reset

```c
void sona_body_reset(sona_body_tracker *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |

**Returns** Nothing.

Forgets the filters and the tracking state; keeps the options.

### sona_body_input_defaults

```c
void sona_body_input_defaults(sona_body_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `in` | `sona_body_input *` | The [`sona_body_input`](reference/fields.md#sona_body_input) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_body_input x_body_input;
sona_body_input_defaults(&x_body_input);
sona_body_input_defaults(&x_body_input);
```

`size` set, the MediaPipe layout and no points.

### sona_body_feed

```c
sona_result sona_body_feed(sona_body_tracker *t, const sona_body_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |
| `in` | `const sona_body_input *` | A [`sona_body_input`](reference/fields.md#sona_body_input) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

One frame of what the body tracker saw (`sona_body_input`). `SONA_E_ARGUMENT` for a wrong size, a time that is not finite, or a found body without 33 points in the MediaPipe layout.

### sona_body_apply

```c
sona_result sona_body_apply(sona_body_tracker *t, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |
| `a` | `sona_avatar *` | The avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

Puts the pose on an avatar through overrides below the neck, after the clip and before the IK. One tracker drives one avatar at a time. `SONA_E_NOT_READY` until the avatar is READY and posed.

### sona_body_release

```c
void sona_body_release(sona_body_tracker *t, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_body_tracker *` | The body tracker | required |
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

Hands the joints back to the clip; nothing when a is not the avatar it drives.

### sona_body_struct_size

```c
uint32_t sona_body_struct_size(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A public struct's name | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_body_struct_size("sona_config");
printf("sona_body_struct_size: %lld\n", (long long)x_got);
```

sizeof a public struct of this header by name ("sona_body_options"), for the bindings' layout checks; 0 when unknown.

### sona_body_struct_offset

```c
uint32_t sona_body_struct_offset(const char *struct_dot_field);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `struct_dot_field` | `const char *` | `"struct.field"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_body_struct_offset("example");
printf("sona_body_struct_offset: %lld\n", (long long)x_got);
```

offsetof a field by "struct.field" ("sona_body_input.points"); `UINT32_MAX` when unknown.

## Player editor module (sona_editor.h)

An optional library, `sona_editor`: the player-facing editor, the same screens as 360sona.com's, drawn by the SDK for keyboard, gamepad, mouse and touch. Include `sona_editor.h` and link `sona_editor`. The guide: [Player editor](guides/editor.md).

### sona_editor_defaults

```c
void sona_editor_defaults(sona_editor_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_editor_options *` | The [`sona_editor_options`](reference/fields.md#sona_editor_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_editor_options x_editor_options;
memset(&x_editor_options, 0, sizeof x_editor_options);
x_editor_options.size = sizeof x_editor_options;
sona_editor_defaults(&x_editor_options);
```

`size` set, 1280 x 720 (`sona_editor_resize` changes it), seed 1, everything else zero.

### sona_editor_theme_defaults

```c
void sona_editor_theme_defaults(sona_editor_theme *t, uint32_t which);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_editor_theme *` | The [`sona_editor_theme`](reference/fields.md#sona_editor_theme) to fill with the defaults | required |
| `which` | `uint32_t` | Which built-in theme | - |

**Returns** Nothing.

**Example**:

```c
sona_editor_theme x_editor_theme;
memset(&x_editor_theme, 0, sizeof x_editor_theme);
x_editor_theme.size = sizeof x_editor_theme;
sona_editor_theme_defaults(&x_editor_theme, 0);
```

`which`: `SONA_EDITOR_THEME_LIGHT` (360sona.com's editor) or _DARK (the console slate).

### sona_editor_open

```c
sona_result sona_editor_open(sona_ctx *ctx, const sona_editor_options *o, const sona_editor_theme *theme, sona_editor **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_editor_options *` | The options, a [`sona_editor_options`](reference/fields.md#sona_editor_options) | required |
| `theme` | `const sona_editor_theme *` | A [`sona_editor_theme`](reference/fields.md#sona_editor_theme) | required |
| `out` | `sona_editor **` | Receives the new editor | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](troubleshooting.md#error-codes)).

`theme` NULL: the light (site) theme. `SONA_E_ARGUMENT` without a catalogue, for MODE_WARDROBE without a start manifest, or a start manifest that does not parse; `SONA_E_CORRUPT` for font bytes that do not load.

### sona_editor_close

```c
void sona_editor_close(sona_editor *ed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |

**Returns** Nothing.

Removes its avatars from the ctx.

### sona_editor_set_theme

```c
sona_result sona_editor_set_theme(sona_editor *ed, const sona_editor_theme *theme);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `theme` | `const sona_editor_theme *` | A [`sona_editor_theme`](reference/fields.md#sona_editor_theme) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Changes the colours and sizes from the next frame. NULL: the light (site) theme.

### sona_editor_resize

```c
sona_result sona_editor_resize(sona_editor *ed, uint32_t width, uint32_t height);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

The editor's size in pixels, the size of the target it is drawn into.

### sona_editor_feed

```c
sona_result sona_editor_feed(sona_editor *ed, const sona_editor_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `in` | `const sona_editor_input *` | A [`sona_editor_input`](reference/fields.md#sona_editor_input) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

One input event (`SONA_EDITOR_IN_*`): a gamepad button or axis, a key, a typed character for the search box, a pointer or touch, or the wheel.

### sona_editor_update

```c
uint32_t sona_editor_update(sona_editor *ed, double dt);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `dt` | `double` | Seconds since the last call | - |

**Returns** `uint32_t`.

Advances dt seconds: stick repeat, animations, avatar builds and (unless HOST_UPDATES) `sona_update` on the ctx. Returns `SONA_EDITOR_RUNNING`, _DONE or _CANCELLED (and keeps returning it).

### sona_editor_status

```c
uint32_t sona_editor_status(const sona_editor *ed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |

**Returns** `uint32_t`.

`SONA_EDITOR_RUNNING`, `_DONE` or `_CANCELLED`, as the last `sona_editor_update` returned.

### sona_editor_result

```c
sona_result sona_editor_result(const sona_editor *ed, uint8_t out[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |
| `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The avatar as it stands (at any time): `SONA_MANIFEST_BYTES`. After CANCELLED it is the start manifest.

### sona_editor_set_search

```c
sona_result sona_editor_set_search(sona_editor *ed, const char *text);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `text` | `const char *` | The search text, UTF-8; NULL clears it | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The search box of the wardrobe and the item screens, for hosts with an on-screen keyboard (UTF-8; NULL clears).

### sona_editor_set_screen

```c
sona_result sona_editor_set_screen(sona_editor *ed, uint32_t screen);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `screen` | `uint32_t` | A `SONA_EDITOR_SCREEN_*` | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Moves to a screen of the mode (a deprecated id to the screen that took its place). `SONA_E_ARGUMENT` for one the mode does not have, `SONA_EDITOR_SCREEN_LOOKS` in `SONA_EDITOR_MODE_FULL` among them.

### sona_editor_screen_get

```c
uint32_t sona_editor_screen_get(const sona_editor *ed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |

**Returns** `uint32_t`.

The screen shown now.

### sona_editor_screens

```c
uint32_t sona_editor_screens(const sona_editor *ed, uint32_t *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |
| `out` | `uint32_t *` | Receives the values | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

The mode's screens in tab order: writes up to cap of them (out may be NULL) and returns how many there are.

### sona_editor_busy

```c
int sona_editor_busy(const sona_editor *ed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |

**Returns** `int`.

1 while an avatar is still building (the shown one or a change on its way); thumbnails do not count. A change that fails to build leaves the last avatar that did on screen; when the first one fails, nothing shows and busy is 0.

### sona_editor_build_failures

```c
uint32_t sona_editor_build_failures(const sona_editor *ed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |

**Returns** `uint32_t`.

How many avatar builds failed since open (the screen reader is told each time).

### sona_editor_avatar

```c
sona_avatar *sona_editor_avatar(const sona_editor *ed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |

**Returns** `sona_avatar *`.

The avatar on the editor's stage now, or NULL while the first one builds. It is the editor's: read it or hide it,
never remove it. Each choice in the editor makes a new one, so ask again each frame. A host that draws the avatar
layer itself uses it to fade the stage's avatar in and out.

### sona_editor_undo

```c
int sona_editor_undo(sona_editor *ed, int redo);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `redo` | `int` | 1 for redo, 0 for undo | - |

**Returns** `int`.

Undoes the last change (`redo` 0) or redoes the last undone one (`redo` 1), for a host that draws the stage's own
undo and redo buttons. Returns 1 when it stepped, 0 when there was nothing to step to. The editor keeps 32 steps.

### sona_editor_can_undo

```c
int sona_editor_can_undo(const sona_editor *ed, int redo);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |
| `redo` | `int` | 1 for redo, 0 for undo | - |

**Returns** `int`.

1 when `sona_editor_undo` with the same `redo` would step: use it to grey out the buttons.

### sona_editor_zoom

```c
double sona_editor_zoom(sona_editor *ed, double set);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `set` | `double` | A matched set's index | - |

**Returns** `double`.

The stage's zoom: 1 is the editor's own framing, from 0.6 to 3. A `set` above 0 sets it (clamped to that range);
0 only reads it. Returns the zoom now.

### sona_editor_turn

```c
void sona_editor_turn(sona_editor *ed, double degrees);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `degrees` | `double` | How far to turn the avatar, degrees | - |

**Returns** Nothing.

Turns the avatar on the stage by `degrees`, as a drag across the stage does.

### sona_editor_view

```c
sona_result sona_editor_view(const sona_editor *ed, sona_view *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |
| `out` | `sona_view *` | Receives the [`sona_view`](reference/fields.md#sona_view) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The camera the avatar layer is drawn with (framed into avatar_rect of the full target).

### sona_editor_draw

```c
sona_result sona_editor_draw(sona_editor *ed, sona_renderer *r, const sona_target *t, const sona_draw_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `r` | `sona_renderer *` | The renderer | required |
| `t` | `const sona_target *` | Where the frame lands, a [`sona_target`](reference/fields.md#sona_target) | required |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | `NULL`: the defaults |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

The editor into t: `sona_draw` with the editor's view and the theme's background, without the credit (the UI draws it), and the UI layer over it as r's overlay (rasterised on the CPU where it changed, uploaded where it changed, blended by the renderer; r has no overlay again afterwards); then up to two pending thumbnails (`sona_item_preview_snapshot` and `sona_snapshot` on r). opts NULL: defaults; its clear and the NO_CREDIT flag are the editor's. The UI is drawn at the editor's size over the whole target: resize the editor to the target.

### sona_editor_draw_avatar

```c
sona_result sona_editor_draw_avatar(sona_editor *ed, sona_renderer *r, const sona_target *t, const sona_draw_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `r` | `sona_renderer *` | The renderer | required |
| `t` | `const sona_target *` | Where the frame lands, a [`sona_target`](reference/fields.md#sona_target) | required |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](reference/fields.md#sona_draw_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](troubleshooting.md#error-codes)).

The avatar layer alone (and the thumbnails), for a host that draws the UI layer with its own 2D pass.

### sona_editor_thumbnails

```c
uint32_t sona_editor_thumbnails(sona_editor *ed, sona_renderer *r, uint32_t budget);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `r` | `sona_renderer *` | The renderer | required |
| `budget` | `uint32_t` | How many pictures to draw this call | - |

**Returns** `uint32_t`.

Renders up to budget pending thumbnails on r, for hosts that draw the avatar layer with their own `sona_draw`.

### sona_editor_draw_data_get

```c
sona_result sona_editor_draw_data_get(sona_editor *ed, sona_editor_draw_data *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `out` | `sona_editor_draw_data *` | Receives the [`sona_editor_draw_data`](reference/fields.md#sona_editor_draw_data) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

The UI layer as of the last `sona_editor_update`. Pointers stay valid until the next update, resize or close.

### sona_editor_texture_get

```c
sona_result sona_editor_texture_get(sona_editor *ed, uint32_t id, sona_editor_texture *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `id` | `uint32_t` | The id, as the call that made it gave it | - |
| `out` | `sona_editor_texture *` | Receives the [`sona_editor_texture`](reference/fields.md#sona_editor_texture) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

A texture the draw data names by id, with its pixels (straight RGBA8, owned by the editor) and the rectangle that changed since an older revision, for a host that draws the UI layer itself.

### sona_editor_render_ui

```c
sona_result sona_editor_render_ui(sona_editor *ed, uint8_t *rgba, uint32_t width, uint32_t height, uint32_t stride, int over);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `rgba` | `uint8_t *` | Receives straight RGBA8, row 0 at the top | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `stride` | `uint32_t` | Bytes from one row to the next | - |
| `over` | `int` | 1 to blend over what `rgba` holds, 0 to replace it | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

The UI layer rasterised on the CPU into width x height straight RGBA8 (stride in bytes, 0: width * 4). over 1: blended over what rgba holds (a snapshot of the avatar layer); 0: cleared to transparent first.

### sona_editor_snapshot

```c
sona_result sona_editor_snapshot(sona_editor *ed, sona_renderer *r, uint8_t *rgba);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `r` | `sona_renderer *` | The renderer | required |
| `rgba` | `uint8_t *` | Receives straight RGBA8, row 0 at the top | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](troubleshooting.md#error-codes)).

The whole picture into rgba (width * height * 4 of the editor's size): `sona_snapshot` of the avatar layer, then render_ui over it. For screenshots, tests and servers.

### sona_editor_control_count

```c
uint32_t sona_editor_control_count(const sona_editor *ed);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |

**Returns** `uint32_t`.

Every control on screen, in reading order, and the focused one.

### sona_editor_control_get

```c
sona_result sona_editor_control_get(const sona_editor *ed, uint32_t index, sona_editor_control *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |
| `index` | `uint32_t` | Which one, from 0 | - |
| `out` | `sona_editor_control *` | Receives the [`sona_editor_control`](reference/fields.md#sona_editor_control) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

Control `index` in reading order: its id, role, flags, rectangle, value, place in its group, label, value text and hint ("Wear it"), for a screen reader or a test.

### sona_editor_focus_get

```c
sona_result sona_editor_focus_get(const sona_editor *ed, sona_editor_control *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `const sona_editor *` | The editor | required |
| `out` | `sona_editor_control *` | Receives the [`sona_editor_control`](reference/fields.md#sona_editor_control) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

`SONA_E_NOT_FOUND` when nothing has focus (pointer-only use).

### sona_editor_announcement

```c
uint32_t sona_editor_announcement(sona_editor *ed, char *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ed` | `sona_editor *` | The editor | required |
| `out` | `char *` | Receives the text, NUL-terminated | required |
| `cap` | `uint32_t` | How many entries `out` holds | - |

**Returns** `uint32_t`.

What a screen reader should say since the last call ("Wardrobe, tab, 6 of 6", "Blue Hoodie, 3 of 120, worn"): copies it (UTF-8, NUL-terminated, cut at cap) and returns its length; 0 when nothing changed.

### sona_editor_struct_size

```c
uint32_t sona_editor_struct_size(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A public struct's name | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_editor_struct_size("sona_config");
printf("sona_editor_struct_size: %lld\n", (long long)x_got);
```

sizeof a public struct of this header by name, for the bindings' layout checks; 0 when unknown.

### sona_editor_struct_offset

```c
uint32_t sona_editor_struct_offset(const char *struct_dot_field);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `struct_dot_field` | `const char *` | `"struct.field"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_editor_struct_offset("example");
printf("sona_editor_struct_offset: %lld\n", (long long)x_got);
```

offsetof a field by "struct.field"; `UINT32_MAX` when unknown.

## NPC kit module (sona_npc.h)

An optional library, `sona_npc`: an avatar that says its lines with lip sync, emotes and looks at the player. Include `sona_npc.h` and link `sona_npc`. The guide: [The NPC kit (sona_npc)](guides/npc.md).

### sona_npc_defaults

```c
void sona_npc_defaults(sona_npc_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_npc_options *` | The [`sona_npc_options`](reference/fields.md#sona_npc_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_npc_options x_npc_options;
memset(&x_npc_options, 0, sizeof x_npc_options);
x_npc_options.size = sizeof x_npc_options;
sona_npc_defaults(&x_npc_options);
```

`size` set; `look_seconds` 2, `idle_emote_seconds` 8 (0: never).

### sona_npc_create

```c
sona_result sona_npc_create(sona_ctx *ctx, sona_avatar *a, const sona_npc_options *o, sona_npc **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `a` | `sona_avatar *` | The avatar | required |
| `o` | `const sona_npc_options *` | The options, a [`sona_npc_options`](reference/fields.md#sona_npc_options) | `NULL`: the defaults |
| `out` | `sona_npc **` | Receives the new NPC | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

Drives a, which must stay in ctx while the NPC lives. NULL options: the defaults.

### sona_npc_destroy

```c
void sona_npc_destroy(sona_npc *npc);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `npc` | `sona_npc *` | The NPC | required |

**Returns** Nothing.

Stops the NPC; the avatar stays in the ctx.

### sona_npc_say

```c
sona_result sona_npc_say(sona_npc *npc, const char *text, uint32_t *line);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `npc` | `sona_npc *` | The NPC | required |
| `text` | `const char *` | The line to say, UTF-8 | required |
| `line` | `uint32_t *` | Receives the line's number; may be NULL | `NULL`: not written |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The NPC kit (sona_npc)](guides/npc.md)):

```c
uint32_t id;
sona_npc_say(npc, "Hello there! Welcome to my shop.", &id);   /* queued; said in order */
sona_npc_emote(npc, "laugh");                                  /* at once, without a word */
float head[3] = { px, py, pz };                                /* the player's head, world space */
sona_npc_look_at(npc, head);                                   /* NULL: no one to look at */
```

Queues a line (UTF-8). *line (may be NULL) is its number, for the line callback.

### sona_npc_emote

```c
sona_result sona_npc_emote(sona_npc *npc, const char *text);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `npc` | `sona_npc *` | The NPC | required |
| `text` | `const char *` | What to do, such as `"wave"` | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The NPC kit (sona_npc)](guides/npc.md)):

```c
uint32_t id;
sona_npc_say(npc, "Hello there! Welcome to my shop.", &id);   /* queued; said in order */
sona_npc_emote(npc, "laugh");                                  /* at once, without a word */
float head[3] = { px, py, pz };                                /* the player's head, world space */
sona_npc_look_at(npc, head);                                   /* NULL: no one to look at */
```

Emotes from text at once, without speaking ("wave", "laugh").

### sona_npc_look_at

```c
sona_result sona_npc_look_at(sona_npc *npc, const float target[3]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `npc` | `sona_npc *` | The NPC | required |
| `target` | `const float [3]` | The point to look at, world space; NULL: stop looking | `NULL`: stop looking |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The NPC kit (sona_npc)](guides/npc.md)):

```c
uint32_t id;
sona_npc_say(npc, "Hello there! Welcome to my shop.", &id);   /* queued; said in order */
sona_npc_emote(npc, "laugh");                                  /* at once, without a word */
float head[3] = { px, py, pz };                                /* the player's head, world space */
sona_npc_look_at(npc, head);                                   /* NULL: no one to look at */
```

The player's head, world space; NULL: no player to look at.

### sona_npc_update

```c
sona_result sona_npc_update(sona_npc *npc, double dt);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `npc` | `sona_npc *` | The NPC | required |
| `dt` | `double` | Seconds since the last call | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The NPC kit (sona_npc)](guides/npc.md)):

```c
sona_npc_update(npc, dt);
sona_update(ctx, dt, NULL, NULL);

sona_npc_state st;
st.size = sizeof st;
sona_npc_state_get(npc, &st);   /* SONA_NPC_IDLE, _SPEAKING (st.line), _EMOTING; st.queued */
```

Advances the NPC by `dt` seconds: the line being said and its lip sync, emotes, the look at the player and the idle. Call it each frame before `sona_update`.

### sona_npc_state_get

```c
sona_result sona_npc_state_get(const sona_npc *npc, sona_npc_state *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `npc` | `const sona_npc *` | The NPC | required |
| `out` | `sona_npc_state *` | Receives the [`sona_npc_state`](reference/fields.md#sona_npc_state) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [The NPC kit (sona_npc)](guides/npc.md)):

```c
sona_npc_update(npc, dt);
sona_update(ctx, dt, NULL, NULL);

sona_npc_state st;
st.size = sizeof st;
sona_npc_state_get(npc, &st);   /* SONA_NPC_IDLE, _SPEAKING (st.line), _EMOTING; st.queued */
```

What the NPC is doing: idle, speaking or emoting, the line being said (0 when none) and how many lines wait.

### sona_npc_struct_size

```c
uint32_t sona_npc_struct_size(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A public struct's name | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_npc_struct_size("sona_config");
printf("sona_npc_struct_size: %lld\n", (long long)x_got);
```

sizeof a public struct of this header by name, for the bindings' layout checks; 0 when unknown.

### sona_npc_struct_offset

```c
uint32_t sona_npc_struct_offset(const char *struct_dot_field);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `struct_dot_field` | `const char *` | `"struct.field"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_npc_struct_offset("example");
printf("sona_npc_struct_offset: %lld\n", (long long)x_got);
```

offsetof a field by "struct.field"; `UINT32_MAX` when unknown.

## Face tracking module (sona_track.h)

An optional library, `sona_track`: a face tracker's blendshapes and head pose to the avatar. Include `sona_track.h` and link `sona_track`. The guide: [Face tracking (sona_track)](guides/face-tracking.md).

### sona_track_blendshape_name

```c
const char * sona_track_blendshape_name(uint32_t index);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `index` | `uint32_t` | Which one, from 0 | - |

**Returns** `const char *`.

**Example**:

```c
const char * x_got = sona_track_blendshape_name(0);
printf("sona_track_blendshape_name: %s\n", x_got ? "a value" : "none");
```

The name of blendshape `index` ("eyeBlinkLeft", ...) as both trackers spell them; NULL past the last.

### sona_track_blendshape_find

```c
int32_t sona_track_blendshape_find(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | The name to look up | required |

**Returns** `int32_t`.

**Example**:

```c
int32_t x_got = sona_track_blendshape_find("speed");
printf("sona_track_blendshape_find: %lld\n", (long long)x_got);
```

The index of a blendshape by name; -1 when unknown.

### sona_track_defaults

```c
void sona_track_defaults(sona_track_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_track_options *` | The [`sona_track_options`](reference/fields.md#sona_track_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_track_options x_track_options;
memset(&x_track_options, 0, sizeof x_track_options);
x_track_options.size = sizeof x_track_options;
sona_track_defaults(&x_track_options);
```

`size` set and the filter and head settings the [face tracking](guides/face-tracking.md) guide lists.

### sona_track_create

```c
sona_result sona_track_create(const sona_track_options *o, sona_tracker **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_track_options *` | The options, a [`sona_track_options`](reference/fields.md#sona_track_options) | `NULL`: the defaults |
| `out` | `sona_tracker **` | Receives the new face tracker | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

NULL options: the defaults. `SONA_E_ARGUMENT` for a wrong size or a value out of range.

### sona_track_destroy

```c
void sona_track_destroy(sona_tracker *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |

**Returns** Nothing.

Frees the tracker.

### sona_track_set_options

```c
sona_result sona_track_set_options(sona_tracker *t, const sona_track_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |
| `o` | `const sona_track_options *` | The options, a [`sona_track_options`](reference/fields.md#sona_track_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

New options from the next frame; the filters keep their state. `SONA_E_ARGUMENT` for a wrong size or a value out of range.

### sona_track_reset

```c
void sona_track_reset(sona_tracker *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |

**Returns** Nothing.

Forgets the filters, the shapes held and the tracking state; keeps the options and the calibration.

### sona_track_face_input_defaults

```c
void sona_track_face_input_defaults(sona_track_face_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `in` | `sona_track_face_input *` | The [`sona_track_face_input`](reference/fields.md#sona_track_face_input) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_track_face_input x_track_face_input;
sona_track_face_input_defaults(&x_track_face_input);
sona_track_face_input_defaults(&x_track_face_input);
```

`size` set, the ARKit layout, nothing found.

### sona_track_face_feed

```c
sona_result sona_track_face_feed(sona_tracker *t, const sona_track_face_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |
| `in` | `const sona_track_face_input *` | A [`sona_track_face_input`](reference/fields.md#sona_track_face_input) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

`SONA_E_ARGUMENT` for a wrong size, layout or count, a missing weights pointer with FOUND, or a time that is not finite. A time more than a second away from the last one (or earlier than it) starts the filters again.

### sona_track_face_get

```c
sona_result sona_track_face_get(const sona_tracker *t, sona_track_face_state *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `const sona_tracker *` | The face tracker | required |
| `out` | `sona_track_face_state *` | Receives the [`sona_track_face_state`](reference/fields.md#sona_track_face_state) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

What the tracker makes of the frames so far: the filtered, calibrated weights in ARKit order (sides swapped under `SONA_TRACK_MIRROR`, so Left is the avatar's left) and the head.

### sona_track_calibrate_begin

```c
sona_result sona_track_calibrate_begin(sona_tracker *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

Starts collecting a neutral face: every frame with a face from now on counts.

### sona_track_calibrate_end

```c
sona_result sona_track_calibrate_end(sona_tracker *t, sona_track_calibration *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |
| `out` | `sona_track_calibration *` | Receives the [`sona_track_calibration`](reference/fields.md#sona_track_calibration) | `NULL` allowed (below) |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

Stops and makes each weight's 30th percentile over the frames (the first 300) and their mean head rotation the neutral, and writes it to `out` (may be NULL). `SONA_E_NOT_READY` when no face came in between. Each weight's neutral value is taken off it and the rest rescaled to 0..1; the neutral head rotation becomes identity.

### sona_track_calibration_set

```c
sona_result sona_track_calibration_set(sona_tracker *t, const sona_track_calibration *c);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |
| `c` | `const sona_track_calibration *` | A [`sona_track_calibration`](reference/fields.md#sona_track_calibration) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

A saved calibration, for the next session; NULL clears it.

### sona_track_calibration_get

```c
sona_result sona_track_calibration_get(const sona_tracker *t, sona_track_calibration *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `const sona_tracker *` | The face tracker | required |
| `out` | `sona_track_calibration *` | Receives the [`sona_track_calibration`](reference/fields.md#sona_track_calibration) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The calibration in use, as `sona_track_calibrate_end` or `sona_track_calibration_set` left it.

### sona_track_apply

```c
sona_result sona_track_apply(sona_tracker *t, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |
| `a` | `sona_avatar *` | The avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

Puts the state on an avatar: the face shapes through `sona_avatar_expression` (only when they change) and the head through ADD overrides on Neck and Head, aimed in the avatar's body space from its posed joints, so it holds for any turn, lean or clip (overrides need a clip playing: the default idle does). Call it after the feed and before `sona_update`. One tracker drives one avatar at a time: moving it to another leaves the first as it is, so release that one first. `SONA_E_NOT_READY` until the avatar is READY and posed.

### sona_track_release

```c
void sona_track_release(sona_tracker *t, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_tracker *` | The face tracker | required |
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

Hands the face and the tracker's joints back to the clip; nothing when a is not the avatar it drives.

### sona_track_quat_from_matrix

```c
sona_result sona_track_quat_from_matrix(const float *m, uint32_t stride, int transpose, float q[4]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `m` | `const float *` | A 3x3 or 4x4 rotation matrix | required |
| `stride` | `uint32_t` | Bytes from one row to the next | - |
| `transpose` | `int` | 1 when the matrix is column-major | - |
| `q` | `float [4]` | Receives a unit quaternion (x, y, z, w) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

A rotation matrix to the quaternion head_rotation takes. m holds the 3x3 rotation row by row (m[0..2] the first row); stride is the distance between rows in floats, 3 for a 3x3 and 4 for the upper left of a row-major 4x4 (MediaPipe's facial transformation matrix as numpy holds it). A column-major 4x4 (ARKit's simd_float4x4, glTF) is the transpose: pass transpose 1. Scale is removed.

### sona_track_quat_from_euler

```c
void sona_track_quat_from_euler(float pitch_deg, float yaw_deg, float roll_deg, float q[4]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `pitch_deg` | `float` | Pitch in degrees, up positive | - |
| `yaw_deg` | `float` | Yaw in degrees | - |
| `roll_deg` | `float` | Roll in degrees | - |
| `q` | `float [4]` | Receives a unit quaternion (x, y, z, w) | required |

**Returns** Nothing.

**Example**:

```c
float x_q[4];
memset(x_q, 0, sizeof x_q);
sona_track_quat_from_euler(30.0f, 30.0f, 30.0f, x_q);
```

Degrees, right-handed about the camera axes: pitch about +X (nodding down is positive), yaw about +Y (turning towards the image's right, the subject's own left, is positive), roll about +Z; applied roll, then pitch, then yaw (q = yaw * pitch * roll). Many trackers (OpenSeeFace, head-pose solvers) give these.

### sona_track_struct_size

```c
uint32_t sona_track_struct_size(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A public struct's name | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_track_struct_size("sona_config");
printf("sona_track_struct_size: %lld\n", (long long)x_got);
```

sizeof a public struct of this header by name ("sona_track_options"), for the bindings' layout checks; 0 when unknown.

### sona_track_struct_offset

```c
uint32_t sona_track_struct_offset(const char *struct_dot_field);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `struct_dot_field` | `const char *` | `"struct.field"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_track_struct_offset("example");
printf("sona_track_struct_offset: %lld\n", (long long)x_got);
```

offsetof a field by "struct.field" ("sona_track_face_state.weights"); `UINT32_MAX` when unknown.

## XR body module (sona_xr.h)

An optional library, `sona_xr`: a first-person body driven by a headset and two controllers, for OpenXR games. Include `sona_xr.h` and link `sona_xr`.

### sona_xr_defaults

```c
void sona_xr_defaults(sona_xr_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_xr_options *` | The [`sona_xr_options`](reference/fields.md#sona_xr_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_xr_options x_xr_options;
memset(&x_xr_options, 0, sizeof x_xr_options);
x_xr_options.size = sizeof x_xr_options;
sona_xr_defaults(&x_xr_options);
```

`size` set; `step_distance` 0.25.

### sona_xr_create

```c
sona_result sona_xr_create(const sona_xr_options *o, sona_xr_body **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_xr_options *` | The options, a [`sona_xr_options`](reference/fields.md#sona_xr_options) | `NULL`: the defaults |
| `out` | `sona_xr_body **` | Receives the new XR body | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

A first-person body for a headset and two controllers. NULL options: the defaults.

### sona_xr_destroy

```c
void sona_xr_destroy(sona_xr_body *xr);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `xr` | `sona_xr_body *` | The XR body | required |

**Returns** Nothing.

Frees it.

### sona_xr_input_defaults

```c
void sona_xr_input_defaults(sona_xr_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `in` | `sona_xr_input *` | The [`sona_xr_input`](reference/fields.md#sona_xr_input) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [VR and XR bodies (sona_xr)](guides/xr.md)):

```c
sona_xr_input in;
sona_xr_input_defaults(&in);
in.time = now;                                  /* seconds, rising */
in.flags = SONA_XR_HAS_HEAD;                    /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */
in.head.position[0] = head_pos[0];
in.head.position[1] = head_pos[1];
in.head.position[2] = head_pos[2];
sona_xr_feed(xr, &in);
if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar);
sona_update(ctx, dt, &view, NULL);
```

`size` set, the three poses at the origin with no turn, the floor at 0.

### sona_xr_feed

```c
sona_result sona_xr_feed(sona_xr_body *xr, const sona_xr_input *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `xr` | `sona_xr_body *` | The XR body | required |
| `in` | `const sona_xr_input *` | A [`sona_xr_input`](reference/fields.md#sona_xr_input) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [VR and XR bodies (sona_xr)](guides/xr.md)):

```c
sona_xr_input in;
sona_xr_input_defaults(&in);
in.time = now;                                  /* seconds, rising */
in.flags = SONA_XR_HAS_HEAD;                    /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */
in.head.position[0] = head_pos[0];
in.head.position[1] = head_pos[1];
in.head.position[2] = head_pos[2];
sona_xr_feed(xr, &in);
if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar);
sona_update(ctx, dt, &view, NULL);
```

One frame of the head and the two grip poses (world metres, as `XrPosef`), with its time in seconds and the floor's height.

### sona_xr_calibrate

```c
sona_result sona_xr_calibrate(sona_xr_body *xr);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `xr` | `sona_xr_body *` | The XR body | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

Takes the wearer's height and arm span from the poses fed while they stand straight.

### sona_xr_apply

```c
sona_result sona_xr_apply(sona_xr_body *xr, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `xr` | `sona_xr_body *` | The XR body | required |
| `a` | `sona_avatar *` | The avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](troubleshooting.md#error-codes)).

**Example** (also in [VR and XR bodies (sona_xr)](guides/xr.md)):

```c
sona_xr_input in;
sona_xr_input_defaults(&in);
in.time = now;                                  /* seconds, rising */
in.flags = SONA_XR_HAS_HEAD;                    /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */
in.head.position[0] = head_pos[0];
in.head.position[1] = head_pos[1];
in.head.position[2] = head_pos[2];
sona_xr_feed(xr, &in);
if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar);
sona_update(ctx, dt, &view, NULL);
```

Puts the body on an avatar, scaled to the wearer. `SONA_E_NOT_READY` until the avatar is READY and posed.

### sona_xr_release

```c
void sona_xr_release(sona_xr_body *xr, sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `xr` | `sona_xr_body *` | The XR body | required |
| `a` | `sona_avatar *` | The avatar | required |

**Returns** Nothing.

Hands the avatar's joints back to its clip; nothing when `a` is not the avatar it drives.

### sona_xr_status_get

```c
sona_result sona_xr_status_get(const sona_xr_body *xr, sona_xr_status *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `xr` | `const sona_xr_body *` | The XR body | required |
| `out` | `sona_xr_status *` | Receives the [`sona_xr_status`](reference/fields.md#sona_xr_status) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](troubleshooting.md#error-codes)).

Fills `out` (a `sona_xr_status`) with what the last `sona_xr_apply` did: the poses tracked, the eye height and scale
in use, the body's turn, placement and crouch, the steps taken and where the avatar's eyes were put. `out->size` is set
by the call. `SONA_E_NOT_READY`, with `out` zeroed, before the body has been applied; `SONA_E_ARGUMENT` for NULL.

### sona_xr_openxr_to_world

```c
void sona_xr_openxr_to_world(const sona_xr_pose *in, sona_xr_pose *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `in` | `const sona_xr_pose *` | A [`sona_xr_pose`](reference/fields.md#sona_xr_pose) | required |
| `out` | `sona_xr_pose *` | Receives the [`sona_xr_pose`](reference/fields.md#sona_xr_pose) | required |

**Returns** Nothing.

**Example**:

```c
sona_xr_pose x_xr_pose;
memset(&x_xr_pose, 0, sizeof x_xr_pose);
sona_xr_pose x_xr_pose2;
memset(&x_xr_pose2, 0, sizeof x_xr_pose2);
sona_xr_openxr_to_world(&x_xr_pose, &x_xr_pose2);
```

Turns an OpenXR pose (a view, a hand, an object; right-handed) into sona's world: z mirrored, then half a turn about
Y, so OpenXR's identity faces -Z as an avatar at turn 0 does. `in` and `out` may be the same. The module does this
itself for poses fed with `SONA_XR_OPENXR_SPACE`; call it to place your own things beside the body. Nothing for NULL.

### sona_xr_struct_size

```c
uint32_t sona_xr_struct_size(const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `name` | `const char *` | A public struct's name | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_xr_struct_size("sona_config");
printf("sona_xr_struct_size: %lld\n", (long long)x_got);
```

sizeof a public struct of this header by name, for the bindings' layout checks; 0 when unknown.

### sona_xr_struct_offset

```c
uint32_t sona_xr_struct_offset(const char *struct_dot_field);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `struct_dot_field` | `const char *` | `"struct.field"` | required |

**Returns** `uint32_t`.

**Example**:

```c
uint32_t x_got = sona_xr_struct_offset("example");
printf("sona_xr_struct_offset: %lld\n", (long long)x_got);
```

offsetof a field by "struct.field"; `UINT32_MAX` when unknown.

## Xbox 360 homebrew module (sona_xsdk.h)

In the `xbox360` download only, inside `libsona.a` for xsdk: the calls a title needs to put avatars on the TV. Include `sona_xsdk.h`. The guide: [Xbox 360 homebrew](guides/xbox360.md).

### sona_xsdk_defaults

```c
void sona_xsdk_defaults(sona_xsdk_config *c);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `c` | `sona_xsdk_config *` | The [`sona_xsdk_config`](reference/fields.md#sona_xsdk_config) to fill with the defaults | required |

**Returns** Nothing.

`size` set; `folder` `"game:/"`, `tv` 1, `max_avatars` 64, `memory_mb` 160, `workers` 5, `log_level` `SONA_LOG_WARN`, a dark blue `clear`.

### sona_xsdk_open

```c
sona_result sona_xsdk_open(const sona_xsdk_config *c, sona_xsdk **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `c` | `const sona_xsdk_config *` | The options, a [`sona_xsdk_config`](reference/fields.md#sona_xsdk_config) | required |
| `out` | `sona_xsdk **` | Receives the new Xbox 360 title | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_NOT_FOUND` ([what each means](troubleshooting.md#error-codes)).

Takes the licence built into the title (`samples/x360/embed-licence.cmake`), else `sona-licence.json` from `folder`, and opens the core with two sources: `folder`'s `360sona/` when there is one, then the gate. Starts the workers on hardware threads 1 to 5, opens xsdk's present at 720p when `tv` is 1 and a display opens, and blocks until the Xenos renderer is ready, at most 60 s. Each failure is written to the title's log. `SONA_E_NOT_FOUND` when the title has no licence built in and there is no `sona-licence.json` in `folder`.

### sona_xsdk_add_player

```c
sona_result sona_xsdk_add_player(sona_xsdk *sx, uint32_t user_index, const sona_add_options *opts,
                                   sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |
| `user_index` | `uint32_t` | The signed-in user, 0 to 3, one per controller | - |
| `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](reference/fields.md#sona_add_options) | `NULL`: the defaults |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](troubleshooting.md#error-codes)).

The signed-in player in their own avatar, in the middle of the stage facing the camera. It tries the profile on this console first, then 360sona's lookup by the profile's gamertag, then the gamertag in `sona-player.txt` in `folder`. The neutral figure stands there until one answers, and `*out` keeps the same handle when it does. `opts` NULL: the defaults, idling. `SONA_E_ARGUMENT` for a fifth player or a `user_index` past 3.

### sona_xsdk_view

```c
void sona_xsdk_view(const sona_xsdk *sx, sona_view *view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |
| `view` | `sona_view *` | Receives the camera, a [`sona_view`](reference/fields.md#sona_view) | required |

**Returns** Nothing.

The stage at 1280 by 720: 40 degrees, from 1.35 m up and 5.2 m back. `sona_camera_preset` frames one avatar instead.

### sona_xsdk_frame

```c
int sona_xsdk_frame(sona_xsdk *sx, const sona_view *view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |

**Returns** `int`.

Returns 1 while the title should go on, and 0 for BACK on the first controller or when the display is gone. Reads the first controller (nothing while the Guide is open) and takes the players' lookups. Calls `sona_update` with the time since the last frame, draws `view` and presents it on vblank. Off screen it draws into a target of its own. It never takes the context's events: `sona_poll_event` on `sona_xsdk_ctx(sx)` still gives them.

### sona_xsdk_dt

```c
double sona_xsdk_dt(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `double`.

The seconds between the last two frames, for moving things.

### sona_xsdk_time

```c
double sona_xsdk_time(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `double`.

The seconds since `sona_xsdk_open`.

### sona_xsdk_held

```c
uint16_t sona_xsdk_held(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `uint16_t`.

The first controller's buttons held at the last frame, as `INPUT_GAMEPAD_*` bits.

### sona_xsdk_pressed

```c
uint16_t sona_xsdk_pressed(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `uint16_t`.

The buttons pressed since the frame before, as `INPUT_GAMEPAD_*` bits.

### sona_xsdk_stick

```c
void sona_xsdk_stick(const sona_xsdk *sx, float *x, float *y);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |
| `x` | `float *` | Receives the stick across, -1 left to 1 right; may be NULL | `NULL` allowed (below) |
| `y` | `float *` | Receives the stick up and down, -1 down to 1 up; may be NULL | `NULL` allowed (below) |

**Returns** Nothing.

The first controller's left stick at the last frame, each axis -1 to 1 with up as +y, and 0 inside the usual dead
zone (7,849 of 32,767). `x` and `y` may be NULL.

### sona_xsdk_on_tv

```c
int sona_xsdk_on_tv(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `int`.

1 when frames go to the TV; 0 when they are drawn off screen (no display, as in Xenia, or `tv` 0).

### sona_xsdk_settled

```c
int sona_xsdk_settled(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `int`.

1 when every player's avatar is known and nothing is still loading.

### sona_xsdk_snapshot

```c
sona_result sona_xsdk_snapshot(sona_xsdk *sx, const sona_view *view, const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](reference/fields.md#sona_view) | required |
| `name` | `const char *` | The file's name, ending `.png` or `.ppm` | required |

**Returns** `SONA_OK`.

Draws `view` once more, reads it back and writes it to `folder`, or to `cache:\` where `folder` is read-only (Xenia).

### sona_xsdk_ctx

```c
sona_ctx *sona_xsdk_ctx(sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |

**Returns** `sona_ctx *`.

The context, for every other call of `sona.h`.

### sona_xsdk_renderer

```c
sona_renderer *sona_xsdk_renderer(sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |

**Returns** `sona_renderer *`.

The Xenos renderer, for `sona_draw` and `sona_snapshot` of your own.

### sona_xsdk_close

```c
void sona_xsdk_close(sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |

**Returns** Nothing.

Closes the lookups, the renderer, the context and the display. The worker threads stay for a later `sona_xsdk_open`.

## Types

Every public type of the headers, by name: what it is, its fields or values, and the calls that take it. The header's
comment beside each field or value is its full description.

| Type | What it is |
|---|---|
| `sona_result` | An enum: `SONA_OK`, `SONA_PENDING`, `SONA_E_UNSUPPORTED`, `SONA_E_ORIGIN`, `SONA_E_LICENCE`, `SONA_E_APP` and more; taken by `sona_result_name`, `sona_complete`, `sona_open`, `sona_abi_query` and more |
| `sona_error_info` | The last error on a ctx: code, message and what to do about it. A struct with `code`, `message`, `fix`; taken by `sona_last_error` |
| `sona_allocator` | A struct with `alloc`, `free`, `user`; taken by `sona_lipsync_create` |
| `sona_budget` | Memory budget in bytes. A struct with `total`, `assets`, `clips`, `faces`, `source_cache`, `gpu_idle`; a field of `sona_config` |
| `sona_jobs` | A host job system. A struct with `user`, `workers`, `run`; a field of `sona_config` |
| `sona_http_request` | A struct with `method`, `url`, `headers`, `body`, `body_len`, `timeout_ms`; a field of `sona_http` |
| `sona_http` | A struct with `user`, `send`; taken by `sona_http_platform` |
| `sona_read_kind` | An enum: `SONA_READ_ASSET`, `SONA_READ_DATA`; a field of `sona_source` |
| `sona_source` | A host-written source. A struct with `user`, `read`, `cancel`, `destroy`; a field of `sona_source_desc` |
| `sona_source_desc` | A struct with `kind`, `location`, `custom`; a field of `sona_config` |
| `sona_config` | A struct with `abi`, `app_id`, `licence`, `licence_len`, `sources`, `source_count`, `http`, `allocator` and more; taken by `sona_config_defaults`, `sona_open` |
| `sona_xsdk` | An Xbox 360 title's avatars, renderer and display (`sona_xsdk.h`); made by `sona_xsdk_open` |
| `sona_xsdk_config` | A struct with `size`, `folder`, `tv`, `max_avatars`, `memory_mb`, `workers`, `clear`, `log_level` and more; taken by `sona_xsdk_defaults`, `sona_xsdk_open` |
| `sona_abi_info` | The ABI of the library that is loaded, for hosts and bindings that load it at run time: abi is its SONA_ABI, oldest_abi the oldest SONA_ABI a caller may be built against and still load it (nothing breaks for two minor versions), and its version as numbers. A struct with `abi`, `oldest_abi`, `major`, `minor`, `patch`; taken by `sona_abi_query` |
| `sona_event` | A struct with `type`, `avatar`, `code`, `message`, `fix`; taken by `sona_poll_event` |
| `sona_avatar_state` | An enum: `SONA_AVATAR_QUEUED`, `SONA_AVATAR_LOADING`, `SONA_AVATAR_READY`, `SONA_AVATAR_FAILED`, `SONA_AVATAR_REMOVED`; taken by `sona_avatar_state_of` |
| `sona_placement` | A struct with `position`, `turn_deg`, `scale`; taken by `sona_avatar_move` |
| `sona_add_options` | A struct with `place`, `clip`, `loop`, `speed`, `start_at`, `visible`, `priority`; taken by `sona_add_defaults`, `sona_avatar_add`, `sona_avatar_add_base64`, `sona_avatar_add_state` and more |
| `sona_play_options` | A struct with `loop`, `speed`, `from`; taken by `sona_avatar_play`, `sona_avatar_crossfade`, `sona_avatar_queue`, `sona_avatar_play_stock` |
| `sona_layer_options` | A struct with `mode`, `flags`, `loop`, `weight`, `fade_seconds`, `speed`, `from`, `additive_ref` and more; taken by `sona_layer_defaults`, `sona_avatar_layer_play`, `sona_avatar_layer_blend`, `sona_avatar_layer_machine` |
| `sona_layer_info` | A struct with `kind`, `mode`, `state`, `clip`, `weight`, `time`, `normalized`, `ready` and more; taken by `sona_avatar_layer_info` |
| `sona_blend_sample` | A struct with `clip`, `x`, `y`, `speed`; a field of `sona_blend_space_desc` |
| `sona_blend_space_desc` | A struct with `dims`, `param_x`, `param_y`, `samples`, `sample_count`, `flags`, `smooth_seconds`; taken by `sona_blend_space_defaults`, `sona_blend_space_create` |
| `sona_state_desc` | A struct with `name`, `clip`, `blend`, `loop`, `speed`; a field of `sona_state_machine_desc` |
| `sona_transition_desc` | A struct with `from`, `to`, `fade_seconds`, `exit_time`, `condition_count`, `conditions`; a field of `sona_state_machine_desc` |
| `sona_state_machine_desc` | A struct with `state_count`, `states`, `transitions`, `transition_count`, `initial`; taken by `sona_state_machine_defaults`, `sona_state_machine_create` |
| `sona_clip_info` | A struct with `key`, `id`, `seconds`, `prop`, `caption`; taken by `sona_clip_get` |
| `sona_view` | The camera, in doubles: the maths runs in double and stores float matrices only at the end, as the web SDK does. A struct with `eye`, `target`, `fov_deg`, `near_z`, `far_z`, `width`, `height`; taken by `sona_view_defaults`, `sona_update`, `sona_draw`, `sona_snapshot` and more |
| `sona_frame_stats` | A struct with `ms`, `cpu_ms`, `drawn`, `culled`, `draw_calls`, `built`; taken by `sona_update` |
| `sona_scene_stats` | A struct with `fps`, `ms_per_frame`, `p95_ms`, `cpu_ms_per_frame`, `avatars`, `ready`, `queued`, `drawn` and more; taken by `sona_stats` |
| `sona_lod_options` | Each sona_update gives every avatar in view a step by its height on screen in pixels: FULL (posed every frame), SAMPLED (posed when the clip reaches a new frame), QUARTER (also at most every 4th frame) and SPRITE (a picture of the avatar baked once per look and turn, drawn as one textured quad; not posed). A struct with `full_px`, `quarter_px`, `sprite_px`, `fade_seconds`, `sprite_angles`, `sprite_height`, `max_looks`, `bake_ms`; taken by `sona_lod_defaults`, `sona_lod_set`, `sona_lod_get` |
| `sona_lod_stats` | A struct with `full`, `sampled`, `quarter`, `sprite`, `fading`, `looks`, `bakes`, `bake_ms`; taken by `sona_lod_stats_get` |
| `sona_texture` | A struct with `key`, `version`, `format`, `width`, `height`, `data`, `bytes`; a field of `sona_pose_data`, `sona_shading`, `sona_prop_data` |
| `sona_material` | Address modes: bit 0 set = U wraps, bit 1 set = V wraps; clear = clamp. A struct with `shader_id`, `flags`, `params`, `transparency`, `color_tex`, `intensity_tex`, `decal_tex`, `color_addr` and more; a field of `sona_pose_data`, `sona_prop_data` |
| `sona_mesh` | The runtime vertex, its size set to 76 bytes, in host byte order: +0 float3 position (bind pose, avatar space) +12 uint8 x4 joint index * 3 (the palette's float4 row) +16 uint8 x4 weight (sum 255) +20 uint8 x4 normal, (n * 0.5 + 0.5) * 255; byte 23 is 0 +24 uint8 x4 vertex colour (baked occlusion and alpha) +28 float4 uv0.xy, uv1.xy +44 float4 uv2.xy, uv3.xy (the HQ shaders read uv2 only) +60 float4 uv4.xy, uv5.xy. A struct with `item`, `mask`, `batch`, `material`, `pass`, `palette`, `vertex_count`, `index_count` and more; a field of `sona_pose_data`, `sona_prop_data` |
| `sona_prop_palette` | A struct with `item`, `playing`, `palette`; a field of `sona_pose_data` |
| `sona_pose_data` | A struct with `build_version`, `world`, `palette`, `view_joints`, `mesh_count`, `meshes`, `material_count`, `materials` and more; taken by `sona_pose` |
| `sona_shading` | The fixed shading inputs, for hosts that rebuild our look in their own shaders. A struct with `irradiance`, `irradiance_gain`, `ao_gain`, `bloom_gain`, `shadow_rows`, `rim`; taken by `sona_shading_get` |
| `sona_program` | An enum: `SONA_PROG_SHADOW`, `SONA_PROG_GBUFFER`, `SONA_PROG_SSAO`, `SONA_PROG_BRIGHT`, `SONA_PROG_BLUR`, `SONA_PROG_PRESENT` and more; taken by `sona_shader_source` |
| `sona_device_desc` | The host owns the device. A struct with `backend`, `u`, `instance`, `physical_device`, `device`, `queue`, `queue_family`, `api_version` and more; taken by `sona_renderer_create`, `sona_renderer_reset` |
| `sona_target` | Where one sona_draw lands. A struct with `width`, `height`, `u`, `image`, `view`, `format`, `layout_before`, `layout_after` and more; taken by `sona_draw`, `sona_item_preview_draw`, `sona_draw_lit`, `sona_screen_view_draw` and more |
| `sona_draw_options` | A struct with `clear`, `flags`, `credit_corner`; taken by `sona_draw`, `sona_snapshot`, `sona_item_preview_draw`, `sona_item_preview_snapshot` and more |
| `sona_preview_options` | A struct with `gender`, `slot`, `flags`, `skin`, `colours`, `priority`, `time`, `margin`; taken by `sona_preview_defaults`, `sona_item_preview_add` |
| `sona_quality` | A struct with `msaa`, `flags`; taken by `sona_quality_defaults`, `sona_renderer_set_quality`, `sona_renderer_quality` |
| `sona_tier_options` | A struct with `tier`, `target_fps`, `avatars`; taken by `sona_tier_defaults`, `sona_tier_apply` |
| `sona_picture` | Pictures for 2D games and chat ([sprites2d guide](guides/sprites2d.md)). A struct with `rgba`, `width`, `height`; taken by `sona_pixel_art`, `sona_pixel_palette`, `sona_sticker`, `sona_sheet_page` |
| `sona_pixel_options` | A struct with `height`, `colours`, `flags`, `outline`, `alpha_cut`, `palette`, `palette_count`; taken by `sona_pixel_defaults`, `sona_pixel_art` |
| `sona_sticker_options` | A struct with `pixels`, `clip`, `time`, `turn_deg`, `framing`, `outline_px`, `outline`, `shadow_px` and more; taken by `sona_sticker_defaults`, `sona_sticker` |
| `sona_sheet_options` | A struct with `frames`, `clip`, `name`, `from`, `to`, `directions`, `first_deg`, `pitch_deg` and more; taken by `sona_sheet_defaults`, `sona_sheet_render` |
| `sona_sheet_frame` | One frame of a sheet. A struct with `page`, `x`, `y`, `w`, `h`, `trim_x`, `trim_y`, `cell_w` and more; taken by `sona_sheet_frame_get` |
| `sona_asset_ref` | A struct with `id`, `mask`, `colours`; a field of `sona_manifest` |
| `sona_manifest` | A struct with `version`, `weight`, `height`, `chin`, `nose`, `ears`, `face`, `colours` and more; taken by `sona_manifest_parse`, `sona_manifest_write`, `sona_manifest_wear`, `sona_manifest_unwear` and more |
| `sona_credit` | A struct with `text`, `url`, `rgba`, `width`, `height`; taken by `sona_credit_get` |
| `sona_section` | The editor's wardrobe and appearance sections. An enum: `SONA_SECTION_ANY`, `SONA_SECTION_COSTUME`, `SONA_SECTION_SHIRT`, `SONA_SECTION_TROUSERS`, `SONA_SECTION_SHOES`, `SONA_SECTION_HEADWEAR` and more; a field of `sona_item_info`, `sona_catalogue_query`, `sona_random_options` and more |
| `sona_item_info` | One item. A struct with `guid`, `id`, `kind`, `gender`, `section`, `mask`, `flags`, `route` and more; taken by `sona_catalogue_get` |
| `sona_catalogue_query` | A struct with `text`, `game`, `slots`, `section`, `gender`, `require`, `exclude`, `offset`; taken by `sona_catalogue_search`, `sona_filter_search` |
| `sona_custom_item_info` | A struct with `id`, `mask`, `body`, `version`, `flags`, `template_id`, `sha256`, `template_sha256` and more; taken by `sona_custom_item_check`, `sona_custom_item_get`, `sona_custom_item_find` |
| `sona_paint_spec` | A struct with `id`, `template_id`, `version`, `name`, `description`, `creator`, `created`, `licence` and more; taken by `sona_custom_item_pack` |
| `sona_mesh_item_spec` | A struct with `flags`, `id`, `template_id`, `version`, `glb`, `glb_len`, `name`, `description` and more; taken by `sona_mesh_item_spec_defaults`, `sona_custom_item_pack_mesh` |
| `sona_lipsync_options` | A struct with `sample_rate`, `channels`, `format`, `hold_seconds`, `attack_seconds`, `release_seconds`, `gate_db`, `lead_seconds` and more; taken by `sona_lipsync_defaults`, `sona_lipsync_create`, `sona_lipsync_phonemes`, `sona_lipsync_text` |
| `sona_lipsync_frame` | A struct with `time`, `mouth`, `flags`, `open`, `level_db`, `weights`, `f1`, `f2`; taken by `sona_lipsync_read`, `sona_lipsync_current`, `sona_mouth_keys_sample` |
| `sona_voice_mouth` | Voice chat: a mouth from an audio level alone (linear RMS, 0..1; scale does not matter), for every remote player. A struct with `seed`, `word`, `value`; taken by `sona_voice_mouth_init`, `sona_voice_mouth_step`, `sona_avatar_voice`, `sona_voice_mouths` |
| `sona_headless_options` | A struct with `device`, `backend`, `adapter`, `flags`, `batch_in_flight`, `wait_seconds`; taken by `sona_headless_defaults`, `sona_headless_devices`, `sona_headless_open` |
| `sona_headless_info` | A struct with `backend`, `software`, `type`, `vendor_id`, `device_id`, `name`, `driver`; taken by `sona_headless_devices`, `sona_headless_info_get` |
| `sona_render_options` | A struct with `width`, `height`, `preset`, `yaw_deg`, `pitch_deg`, `zoom`, `turn_deg`, `time` and more; taken by `sona_render_defaults`, `sona_headless_render`, `sona_headless_render_manifest`, `sona_headless_batch` and more |
| `sona_sequence_options` | A struct with `frames`, `fps`, `turn_deg`, `flags`; taken by `sona_sequence_defaults`, `sona_headless_sequence`, `sona_headless_record` |
| `sona_video_options` | A struct with `format`, `width`, `height`, `fps`, `loops`, `quality`, `background`, `flags` and more; taken by `sona_video_defaults`, `sona_video_open` |
| `sona_skeleton_kind` | The rig's joints under other skeletons' bone names, for retargeting ([skeleton maps guide](guides/skeleton-maps.md)). An enum: `SONA_SKELETON_UNITY`, `SONA_SKELETON_VRM`, `SONA_SKELETON_VRM0`, `SONA_SKELETON_UE4`, `SONA_SKELETON_UE5`, `SONA_SKELETON_COUNT`; a field of `sona_export_options` |
| `sona_vrm_expression` | VRM expressions, the presets of VRM 1.0 (VRM 0.x: a i u e o, joy angry sorrow fun, surprised as a custom group, blink, blink_l, blink_r, lookup lookdown lookleft lookright). An enum: `SONA_VRM_AA`, `SONA_VRM_IH`, `SONA_VRM_OU`, `SONA_VRM_EE`, `SONA_VRM_OH`, `SONA_VRM_HAPPY` and more |
| `sona_export_options` | A struct with `format`, `flags`, `bone_names`, `name`, `version`, `authors`, `copyright`, `contact` and more; taken by `sona_export_defaults`, `sona_export_avatar` |
| `sona_export_report` | A struct with `meshes`, `primitives`, `vertices`, `triangles`, `degenerate`, `textures`, `expressions`, `atlas_cells` and more; taken by `sona_export_avatar` |
| `sona_print_options` | A struct with `flags`, `height_mm`, `mm_per_metre`, `min_wall_mm`, `voxel_mm`, `close_mm`, `base_height_mm`, `base_margin_mm` and more; taken by `sona_print_defaults`, `sona_print_avatars`, `sona_print_triangles` |
| `sona_print_mesh` | The solid. A struct with `vertex_count`, `triangle_count`, `shells`, `volume_mm3`, `area_mm2`, `positions`, `colours`, `indices` and more; taken by `sona_print_get` |
| `sona_print_report` | What sona_print_check found. A struct with `vertices`, `triangles`, `edges`, `boundary_edges`, `nonmanifold_edges`, `flipped_edges`, `nonmanifold_vertices`, `degenerate` and more; taken by `sona_print_check` |
| `sona_stock_clip` | A struct with `id`, `name`, `family`, `asset_id`, `caption`, `tags`, `body`, `frames` and more; taken by `sona_stock_clip_at`, `sona_stock_clip_get` |
| `sona_idle_options` | A struct with `parts`, `seed`, `amount`, `face_px`; taken by `sona_idle_defaults`, `sona_avatar_idle`, `sona_avatar_idle_get`, `sona_idle_sample` |
| `sona_idle_state` | A struct with `blink`, `gaze`, `shift`, `breath`; taken by `sona_avatar_idle_state`, `sona_idle_sample` |
| `sona_ik_foot_lock` | Foot locking: a foot the clip plants (down, its ankle at the flat foot's height, and no longer swinging) stays where it landed until the clip lifts the heel, so walk and run clips do not slide while the host moves the avatar no faster than the clip's feet travel; faster, the held foot is dragged after the body just enough for the leg to reach it and slides less than without locking. A struct with `flags`, `weight`, `max_slide`, `release_seconds`; taken by `sona_ik_foot_lock_defaults`, `sona_avatar_ik_foot_lock` |
| `sona_ik_spine` | Spine assist: a hand target past the arm's reach bends and turns the spine, and the hips a little, towards it. A struct with `flags`, `weight`, `max_bend_deg`, `max_twist_deg`, `hips_share`; taken by `sona_ik_spine_defaults`, `sona_avatar_ik_spine` |
| `sona_ik_fingers` | Finger curl per hand, over the clip's: 0 open to 1 closed, per finger, and spread. A struct with `flags`, `curl`, `spread`, `weight`, `fade_seconds`; taken by `sona_ik_fingers_defaults`, `sona_avatar_ik_fingers` |
| `sona_ik_eyes` | A struct with `flags`, `max_speed_deg`, `smoothing`, `lead_seconds`; taken by `sona_ik_eyes_defaults`, `sona_avatar_ik_eyes` |
| `sona_import_options` | A struct with `format`, `key`, `take`, `take_index`, `flags`, `map`, `map_count`, `fps` and more; taken by `sona_import_defaults`, `sona_anim_file_load`, `sona_anim_file_open`, `sona_clip_import` |
| `sona_import_info` | A struct with `format`, `naming`, `bones`, `takes`, `mapped`, `frames`, `fps`, `seconds` and more; taken by `sona_clip_import`, `sona_clip_imported_get`, `sona_clip_imported_find` |
| `sona_players_config` | A struct with `max_players`, `refresh_s`, `per_hour`, `in_flight`, `timeout_ms`, `host`, `client`, `http` and more; taken by `sona_players_defaults`, `sona_players_open` |
| `sona_player_look` | A struct with `state`, `error`, `placeholder`, `fetched_at`, `checked_at`, `next_check`, `manifest`, `version` and more; taken by `sona_players_look` |
| `sona_player_event` | A struct with `type`, `code`, `id`; taken by `sona_players_poll` |
| `sona_players_stats` | A struct with `players`, `watched`, `in_flight`, `due`, `requests`, `changed`, `same`, `not_modified` and more; taken by `sona_players_stats_get` |
| `sona_random_options` | A struct with `body`, `style`, `palette`, `flags`, `require`, `exclude`, `skip_sections`, `skin_count` and more; taken by `sona_random_defaults`, `sona_make_random` |
| `sona_random_report` | A struct with `body`, `seed`, `set`, `picked`, `candidates`; taken by `sona_make_random` |
| `sona_like_options` | A struct with `parts`, `match`, `flags`, `available`, `available_user`; taken by `sona_like_defaults`, `sona_make_dress_like` |
| `sona_like_report` | A struct with `count`, `kept`, `variants`, `similar`, `substitutes`, `dropped`, `covered`, `items`; taken by `sona_make_dress_like` |
| `sona_outfit_set` | A struct with `title`, `game`, `name`, `count`, `bodies`, `sections`, `slots`; taken by `sona_outfit_set_get` |
| `sona_outfit_issue` | A struct with `kind`, `severity`, `slots`, `field`, `item`, `other`; taken by `sona_outfit_check` |
| `sona_outfit_report` | A struct with `issues`, `errors`, `warnings`, `body`, `slots`, `set`, `set_items`, `valid`; taken by `sona_outfit_check`, `sona_outfit_fix` |
| `sona_filter_verdict` | A struct with `allowed`, `reason`, `tag`, `index`, `section`, `source`, `tags`; taken by `sona_filter_check` |
| `sona_filter_report` | A struct with `count`, `replaced`, `hidden`, `cache`, `change`; taken by `sona_filter_manifest`, `sona_filter_manifest_bytes`, `sona_avatar_filter_report` |
| `sona_state_info` | A struct with `version`, `has_look`, `parts`, `clock`; taken by `sona_state_info_get` |
| `sona_state_status` | A struct with `mode`, `pending`, `missing`, `applied`; taken by `sona_avatar_state_status` |
| `sona_net_options` | A struct with `tick_hz`, `history`, `full_after`; taken by `sona_net_defaults`, `sona_net_sender_create`, `sona_net_receiver_create` |
| `sona_net_look` | A struct with `version`, `kind`, `manifest`, `id`; taken by `sona_net_receiver_look` |
| `sona_net_stats` | A struct with `packets`, `bytes`, `full`, `newest`, `oldest`, `last_bytes`, `acked`; taken by `sona_net_sender_stats`, `sona_net_receiver_stats` |
| `sona_record_options` | A struct with `tick_hz`, `keyframe_ticks`, `keep_seconds`; taken by `sona_record_defaults`, `sona_recorder_create` |
| `sona_replay_info` | A struct with `tracks`, `tick_hz`, `first_tick`, `last_tick`, `frames`, `seconds`; taken by `sona_replay_info_get` |
| `sona_lighting` | A struct with `flags`, `key`, `fill`, `ambient`, `environment`, `specular`, `rim`, `shadow` and more; taken by `sona_lighting_defaults`, `sona_renderer_set_lighting`, `sona_renderer_lighting`, `sona_draw_lit` and more |
| `sona_environment` | A struct with `kind`, `sh`, `cube_size`, `cube`, `skin_red`; taken by `sona_environment_defaults`, `sona_renderer_set_environment`, `sona_environment_irradiance` |
| `sona_host_shadow` | The host's shadow map, sampled by the lit avatars (they receive the host scene's shadows), together with their own map. A struct with `flags`, `matrix`, `bias`, `width`, `height`, `u`, `view`, `layout` and more; taken by `sona_renderer_set_host_shadow` |
| `sona_shadow_map` | The renderer's own shadow map as its last lit frame with shadows drew it (the avatars only), for the host to shadow its scene with: sample it at the matrix's (u, v) and compare depth as above. A struct with `width`, `height`, `format`, `matrix`, `texel_metres`, `frame`, `u`, `image` and more; taken by `sona_renderer_shadow_map` |
| `sona_style` | A struct with `kind`, `flags`, `bands`, `shade`, `highlight`, `outline_px`, `outline`, `colour`; taken by `sona_style_defaults`, `sona_avatar_set_style`, `sona_avatar_style`, `sona_renderer_set_style` and more |
| `sona_placeholder_options` | A struct with `flags`, `delay_seconds`, `appear_seconds`, `reveal_seconds`, `failed_seconds`, `tint`, `failed_tint`, `glow`; taken by `sona_placeholder_defaults`, `sona_placeholder_set`, `sona_placeholder_get` |
| `sona_placeholder_info` | A struct with `phase`, `opacity`, `height`, `gender`, `clip`, `seconds`, `sprite`; taken by `sona_avatar_placeholder_info` |
| `sona_placeholder_stats` | A struct with `shown`, `waiting`, `loading`, `revealing`, `failed`, `sprites`, `posed`, `pose_ms` and more; taken by `sona_placeholder_stats_get` |
| `sona_overlay` | A straight-alpha RGBA8 picture that every sona_draw on the renderer blends over its target after the credit, on every backend: SRC_ALPHA, ONE_MINUS_SRC_ALPHA (alpha ONE, ONE_MINUS_SRC_ALPHA), nearest sampling, no depth. A struct with `width`, `height`, `stride`, `rgba`, `revision`, `dirty`, `rect`; taken by `sona_renderer_overlay` |
| `sona_screen_action` | An enum: `SONA_ACT_NONE`, `SONA_ACT_UP`, `SONA_ACT_DOWN`, `SONA_ACT_LEFT`, `SONA_ACT_RIGHT`, `SONA_ACT_ACCEPT` and more; a field of `sona_screen_event`, `sona_screen_node` |
| `sona_screen_event` | One input event. A struct with `type`, `action`, `from`, `x`, `y`, `pointer`; taken by `sona_screen_input` |
| `sona_screen_theme` | Colours are 0xAARRGGBB. A struct with `flags`, `background`, `panel`, `panel_raised`, `text`, `text_dim`, `accent`, `accent_text` and more; taken by `sona_screen_theme_defaults`, `sona_screen_set_theme` |
| `sona_screen_node` | One thing to draw, in paint order. A struct with `id`, `parent`, `role`, `state`, `x`, `y`, `w`, `h` and more; taken by `sona_screen_nodes` |
| `sona_screen_status` | An enum: `SONA_SCREEN_RUNNING`, `SONA_SCREEN_DONE`, `SONA_SCREEN_CANCELLED`, `SONA_SCREEN_FINE_TUNE`; taken by `sona_screen_update` |
| `sona_quick_options` | A struct with `seed`, `looks`, `body`, `flags`, `catalogue`, `filter`, `filter_user`, `theme` and more; taken by `sona_quick_defaults`, `sona_quick_open`, `sona_quick_look` |
| `sona_wardrobe_options` | A struct with `flags`, `manifest`, `catalogue`, `owned`, `owned_count`, `outfits`, `outfit_count`, `outfit_names` and more; taken by `sona_wardrobe_defaults`, `sona_wardrobe_open` |
| `sona_screen_stats` | A struct with `presses`, `taps`, `changes`, `shuffles`, `focus_moves`, `seconds`, `action_presses`; taken by `sona_screen_stats_get` |
| `sona_pick_options` | A struct with `flags`, `max_distance`, `ignore_count`, `ignore`; taken by `sona_pick_defaults`, `sona_pick_ray`, `sona_pick_screen`, `sona_pick_ray_all` and more |
| `sona_body_region` | An enum: `SONA_REGION_NONE`, `SONA_REGION_HEAD`, `SONA_REGION_NECK`, `SONA_REGION_TORSO`, `SONA_REGION_HIPS`, `SONA_REGION_LEFT_ARM` and more; a field of `sona_pick_hit` |
| `sona_pick_hit` | A struct with `source`, `flags`, `avatar_id`, `avatar`, `part`, `section`, `mask`, `item` and more; taken by `sona_pick_ray`, `sona_pick_screen`, `sona_pick_ray_all`, `sona_avatar_pick` and more |
| `sona_prop_part` | A struct with `flags`, `vertex_count`, `index_count`, `positions`, `normals`, `uvs`, `colours`, `indices` and more; taken by `sona_prop_part_defaults`, `sona_prop_mesh_create` |
| `sona_prop_load_options` | A struct with `flags`, `scale`, `scene`; taken by `sona_prop_load_defaults`, `sona_prop_mesh_load`, `sona_prop_mesh_open` |
| `sona_prop_mesh_info` | A struct with `kind`, `flags`, `parts`, `vertices`, `triangles`, `textures`, `joints`, `hand` and more; taken by `sona_prop_mesh_info_get` |
| `sona_prop_data` | The meshes in the data API's own form (3.11), for hosts that draw props themselves: 76-byte vertices whose joint bytes index sona_prop_frame.palette (a host mesh uses joint 0 only), materials and textures. A struct with `mesh_count`, `meshes`, `material_count`, `materials`, `texture_count`, `textures`, `joints`; taken by `sona_prop_mesh_data` |
| `sona_prop_attach` | A struct with `flags`, `joint`, `position`, `rotation`, `scale`, `hand`, `hand_flags`, `hand_position` and more; taken by `sona_prop_attach_defaults`, `sona_avatar_prop_attach`, `sona_avatar_prop_set`, `sona_avatar_prop_get` |
| `sona_prop_frame` | A struct with `flags`, `joint`, `time`, `world`, `avatar`, `hand_error`, `joints`, `palette`; taken by `sona_avatar_prop_frame` |
| `sona_ragdoll_options` | A struct with `flags`, `total_mass`, `coverage`, `limits`; taken by `sona_ragdoll_defaults`, `sona_avatar_ragdoll` |
| `sona_ragdoll_body` | One body. A struct with `joint`, `parent`, `shape`, `no_collide`, `position`, `rotation`, `shape_position`, `shape_rotation` and more; taken by `sona_avatar_ragdoll` |
| `sona_ragdoll_state` | A body's world transform and velocities, in sona_avatar_ragdoll's order. A struct with `position`, `rotation`, `velocity`, `angular_velocity`; taken by `sona_avatar_ragdoll_state`, `sona_avatar_ragdoll_drive` |
| `sona_ragdoll_info` | A struct with `mode`, `weight`, `blend_left`, `face_up`, `hips`, `lowest`, `getup_position`, `getup_turn_deg`; taken by `sona_avatar_ragdoll_info` |
| `sona_ragdoll_motor` | Powered ragdolls. A struct with `rotation`, `joint_rotation`, `angular_velocity`, `world_position`, `world_rotation`, `velocity`, `world_angular_velocity`; taken by `sona_avatar_ragdoll_motors` |
| `sona_seat` | A struct with `kind`, `position`, `turn_deg`, `height`, `depth`, `width`; taken by `sona_seat_defaults` |
| `sona_interaction_desc` | A struct with `kind`, `a`, `b`, `position`, `turn_deg`, `flags`, `start_seconds`, `hold_seconds` and more; taken by `sona_interaction_defaults`, `sona_interaction_layout`, `sona_interaction_start` |
| `sona_interaction_plan` | Where the interaction stands its avatars and where the contacts meet, before it starts (walk them there). A struct with `contacts`, `place`, `contact`, `spacing`, `clearance`; taken by `sona_interaction_layout` |
| `sona_interaction_status` | A struct with `kind`, `phase`, `phase_seconds`, `progress`, `touching`, `contact_error`, `clearance`, `contact` and more; taken by `sona_interaction_status_get` |
| `sona_emote` | A struct with `count`, `clips`, `weights`, `speed`, `confidence`, `expression`; taken by `sona_emote_from_text`, `sona_avatar_emote` |
| `sona_award_def` | A developer defines award items for an app (on the devs site, or with sona_award_define and the app's developer key); the game unlocks one for a signed-in player and it joins their 360sona wardrobe. A struct with `flags`, `key`, `title`, `description`, `item`, `developer_key`; taken by `sona_award_def_defaults`, `sona_award_define` |
| `sona_capsule` | A vertical capsule around the posed body, in world space, for collisions: the segment a..b and its radius. A struct with `a`, `b`, `radius`; taken by `sona_avatar_capsule` |
| `sona_clip_event` | A struct with `kind`, `mark`, `clip`, `time`; taken by `sona_avatar_clip_events` |
| `sona_layer_event` | A struct with `kind`, `layer`, `state`, `from_state`, `time`; taken by `sona_avatar_layer_events` |
| `sona_condition` | A struct with `param`, `op`, `value`; a field of `sona_transition_desc` |
| `sona_shader_lang` | An enum: `SONA_LANG_GLSL_ES300`, `SONA_LANG_GLSL_330`, `SONA_LANG_SPIRV`, `SONA_LANG_HLSL`, `SONA_LANG_MSL`; taken by `sona_shader_source` |
| `sona_preset` | An enum: `SONA_PRESET_FULL`, `SONA_PRESET_UPPER`, `SONA_PRESET_BUST`, `SONA_PRESET_FACE`; taken by `sona_camera_preset` |
| `sona_guid` | A struct with `b`; taken by `sona_slot_of`, `sona_guid_parse`, `sona_guid_format`, `sona_manifest_wear` and more |
| `sona_route` | An enum: `SONA_ROUTE_REJECTED`, `SONA_ROUTE_WORN`, `SONA_ROUTE_BARE`, `SONA_ROUTE_FACE`; taken by `sona_slot_of` |
| `sona_body` | An enum: `SONA_BODY_MAN`, `SONA_BODY_WOMAN`, `SONA_BODY_BOTH`; a field of `sona_custom_item_info` |
| `sona_phoneme` | A phoneme with its time in seconds: ARPAbet ("AH0"), IPA ("ʃ"), the 15 viseme names ("PP", "aa"), the 22 viseme ids as digits ("21"), or a mouth name ("AI"). A struct with `symbol`, `start`, `end`; taken by `sona_lipsync_hint`, `sona_lipsync_phonemes` |
| `sona_mouth_key` | A mouth from time on. A struct with `time`, `mouth`, `open`, `flags`; taken by `sona_lipsync_phonemes`, `sona_lipsync_text`, `sona_mouth_keys_sample` |
| `sona_vrm_face` | The face an expression shows: a shape index per face part, in sona_avatar_expression's order (mouth, left eyebrow, right eyebrow, left eye, right eye; left is the avatar's own left), or 255 for a part it leaves to the others. A struct with `expression`, `parts`; taken by `sona_vrm_face_default` |
| `sona_bone_map` | One override: the source bone (its full name, or as matched: lower case, no prefix) drives joint (a sona_joint_find name). A struct with `source`, `joint`; a field of `sona_import_options` |
| `sona_interaction_event` | A struct with `kind`, `phase`, `time`, `value`; taken by `sona_interaction_events` |
| `sona_ctx` | An opaque handle, made by `sona_open` and freed by `sona_close`, `sona_free`; taken by `sona_open`, `sona_close`, `sona_last_error`, `sona_app_id` and more |
| `sona_avatar` | An opaque handle, made by `sona_avatar_add`, `sona_avatar_add_base64`, `sona_item_preview_add` and more; taken by `sona_avatar_add`, `sona_avatar_add_base64`, `sona_avatar_state_of`, `sona_avatar_id` and more |
| `sona_renderer` | An opaque handle, made by `sona_renderer_create`, `sona_headless_renderer` and freed by `sona_renderer_destroy`; taken by `sona_renderer_create`, `sona_renderer_destroy`, `sona_draw`, `sona_renderer_frame_index` and more |
| `sona_request` | one read in flight from a source. An opaque handle; taken by `sona_complete` |
| `sona_http_reply` | An opaque handle; taken by `sona_http_done` |
| `sona_blend_space` | An opaque handle, made by `sona_blend_space_create` and freed by `sona_blend_space_destroy`; taken by `sona_avatar_layer_blend`, `sona_blend_space_create`, `sona_blend_space_destroy`, `sona_blend_space_weights` |
| `sona_state_machine` | An opaque handle, made by `sona_state_machine_create` and freed by `sona_state_machine_destroy`; taken by `sona_avatar_layer_machine`, `sona_state_machine_create`, `sona_state_machine_destroy`, `sona_state_machine_find` and more |
| `sona_sheet` | An opaque handle, made by `sona_sheet_render` and freed by `sona_sheet_free`; taken by `sona_sheet_render`, `sona_sheet_free`, `sona_sheet_page_count`, `sona_sheet_page` and more |
| `sona_catalogue` | Every item id with its name, slots, game and source, from sona-catalogue.bin, so pickers need no web call. An opaque handle, made by `sona_catalogue_load`, `sona_catalogue_load_memory` and freed by `sona_catalogue_free`; taken by `sona_catalogue_load`, `sona_catalogue_load_memory`, `sona_catalogue_free`, `sona_catalogue_count` and more |
| `sona_lipsync` | An opaque handle, made by `sona_lipsync_create` and freed by `sona_lipsync_destroy`; taken by `sona_lipsync_create`, `sona_lipsync_destroy`, `sona_lipsync_reset`, `sona_lipsync_feed` and more |
| `sona_headless` | A device of the library's own, with no window and no display, for servers, bots and tools: the best GPU, or a software device (lavapipe, llvmpipe) where there is none, so it runs in a container. An opaque handle, made by `sona_headless_open` and freed by `sona_headless_close`; taken by `sona_headless_open`, `sona_headless_close`, `sona_headless_info_get`, `sona_headless_renderer` and more |
| `sona_video` | An opaque handle, made by `sona_video_open`; taken by `sona_headless_record`, `sona_video_open`, `sona_video_frame`, `sona_video_finish` |
| `sona_print` | An opaque handle, made by `sona_print_avatars`, `sona_print_triangles` and freed by `sona_print_free`; taken by `sona_print_avatars`, `sona_print_triangles`, `sona_print_get`, `sona_print_encode` and more |
| `sona_anim_file` | A parsed file: no ctx, nothing retargeted. An opaque handle, made by `sona_anim_file_load`, `sona_anim_file_open` and freed by `sona_anim_file_free`; taken by `sona_anim_file_load`, `sona_anim_file_open`, `sona_anim_file_free`, `sona_anim_file_takes` and more |
| `sona_players` | An opaque handle, made by `sona_players_open` and freed by `sona_players_close`; taken by `sona_players_open`, `sona_players_close`, `sona_players_watch`, `sona_players_unwatch` and more |
| `sona_maker` | A maker indexes a catalogue's outfit rules once: candidate items per body and section, gender variants and matched sets ([makers guide](guides/makers.md)). An opaque handle, made by `sona_maker_create` and freed by `sona_maker_free`; taken by `sona_maker_create`, `sona_maker_free`, `sona_make_random`, `sona_make_dress_like` and more |
| `sona_filter` | Which items a game allows ([filters guide](guides/filters.md)): by section, slot, game (the franchise, brand or collection an item comes from), tag, source or id. An opaque handle, made by `sona_filter_create`, `sona_ctx_filter` and freed by `sona_filter_free`; taken by `sona_filter_create`, `sona_filter_free`, `sona_filter_reset`, `sona_filter_sections` and more |
| `sona_net_sender` | Network sync: a stream carries one avatar from a sender to one receiver. An opaque handle, made by `sona_net_sender_create` and freed by `sona_net_sender_destroy`; taken by `sona_net_sender_create`, `sona_net_sender_destroy`, `sona_net_sender_look`, `sona_net_write` and more |
| `sona_net_receiver` | An opaque handle, made by `sona_net_receiver_create` and freed by `sona_net_receiver_destroy`; taken by `sona_net_receiver_create`, `sona_net_receiver_destroy`, `sona_net_read`, `sona_net_receiver_look` and more |
| `sona_recorder` | Replays (replays, kill-cams, bug reports): a recorder takes avatars' states at each tick into one compact file (the network coding, with a full state every keyframe_ticks so any moment is a short decode away); a replay shows any track at any time on a puppet, so seeking, slow motion, fast forward and reverse are where the host moves the time. An opaque handle, made by `sona_recorder_create` and freed by `sona_recorder_destroy`; taken by `sona_recorder_create`, `sona_recorder_destroy`, `sona_recorder_track`, `sona_recorder_capture` and more |
| `sona_replay` | An opaque handle, made by `sona_replay_open` and freed by `sona_replay_close`; taken by `sona_replay_open`, `sona_replay_close`, `sona_replay_info_get`, `sona_replay_track` and more |
| `sona_screen` | Two ready-made screens a game opens and gets an avatar back from ([quick creator guide](guides/quick-creator.md)). An opaque handle, made by `sona_quick_open`, `sona_wardrobe_open` and freed by `sona_screen_destroy`; taken by `sona_quick_open`, `sona_wardrobe_open`, `sona_screen_destroy`, `sona_screen_kind` and more |
| `sona_prop_mesh` | An opaque handle, made by `sona_prop_mesh_create`, `sona_prop_mesh_load`, `sona_prop_mesh_open` and more; taken by `sona_prop_mesh_create`, `sona_prop_mesh_load`, `sona_prop_mesh_open`, `sona_prop_mesh_stock` and more |
| `sona_interaction` | Two avatars of any heights and shapes doing one thing together, or one avatar on a seat. An opaque handle, made by `sona_interaction_start`; taken by `sona_interaction_start`, `sona_interaction_end`, `sona_interaction_move`, `sona_interaction_remove` and more |
| `sona_picture_fn` | One picture of a batch or a sequence. A callback the host supplies: `void (*sona_picture_fn)(void *user, uint32_t index, sona_result result, const uint8_t *rgba, uint32_t width, uint32_t height)`; taken by `sona_headless_batch`, `sona_headless_sequence` |
| `sona_body_options` | A struct with `flags`, `min_cutoff`, `beta`, `min_visibility`, `lost_seconds`, `return_seconds`; taken by `sona_body_defaults`, `sona_body_create` |
| `sona_body_input` | One frame of a body tracker. A struct with `flags`, `time`, `layout`, `count`, `points`, `visibility`, `image`; taken by `sona_body_input_defaults`, `sona_body_feed` |
| `sona_body_tracker` | An opaque handle, made by `sona_body_create` and freed by `sona_body_destroy`; taken by `sona_body_create`, `sona_body_destroy`, `sona_body_reset`, `sona_body_feed` and more |
| `sona_editor_options` | A struct with `mode`, `width`, `height`, `flags`, `start`, `catalogue`, `seed`, `title` and more; taken by `sona_editor_defaults`, `sona_editor_open` |
| `sona_editor_theme` | Colours are 0xAARRGGBB, straight alpha. A struct with `background`, `panel`, `raised`, `text`, `text_dim`, `accent`, `accent_text`, `focus` and more; taken by `sona_editor_theme_defaults`, `sona_editor_open`, `sona_editor_set_theme` |
| `sona_editor_input` | A struct with `kind`, `code`, `down`, `mods`, `pointer`, `x`, `y`, `value`; taken by `sona_editor_feed` |
| `sona_editor_control` | A struct with `id`, `role`, `flags`, `rect`, `value`, `min`, `max`, `index` and more; taken by `sona_editor_control_get`, `sona_editor_focus_get` |
| `sona_editor_draw_data` | A struct with `width`, `height`, `revision`, `vertices`, `vertex_count`, `indices`, `index_count`, `commands` and more; taken by `sona_editor_draw_data_get` |
| `sona_editor_texture` | A struct with `id`, `width`, `height`, `revision`, `dirty`, `dirty_since`, `rgba`; taken by `sona_editor_texture_get` |
| `sona_editor` | An opaque handle, made by `sona_editor_open` and freed by `sona_editor_close`; taken by `sona_editor_open`, `sona_editor_close`, `sona_editor_set_theme`, `sona_editor_resize` and more |
| `sona_npc_options` | A struct with `flags`, `speak`, `speak_user`, `line`, `line_user`, `look_seconds`, `idle_emote_seconds`; taken by `sona_npc_defaults`, `sona_npc_create` |
| `sona_npc_state` | A struct with `state`, `line`, `queued`; taken by `sona_npc_state_get` |
| `sona_npc` | An opaque handle, made by `sona_npc_create` and freed by `sona_npc_destroy`; taken by `sona_npc_create`, `sona_npc_destroy`, `sona_npc_say`, `sona_npc_emote` and more |
| `sona_track_options` | A struct with `flags`, `face_min_cutoff`, `face_beta`, `head_min_cutoff`, `head_beta`, `head_gain`, `head_limit_deg`, `neck_share` and more; taken by `sona_track_defaults`, `sona_track_create`, `sona_track_set_options` |
| `sona_track_face_input` | One frame of a face tracker. A struct with `flags`, `time`, `layout`, `count`, `weights`, `head_rotation`; taken by `sona_track_face_input_defaults`, `sona_track_face_feed` |
| `sona_track_face_state` | What the tracker makes of the frames so far. A struct with `tracking`, `time`, `weight`, `expression`, `mood`, `head`, `weights`; taken by `sona_track_face_get` |
| `sona_track_calibration` | Neutral face. A struct with `frames`, `neutral`, `head`; taken by `sona_track_calibrate_end`, `sona_track_calibration_set`, `sona_track_calibration_get` |
| `sona_tracker` | An opaque handle, made by `sona_track_create` and freed by `sona_track_destroy`; taken by `sona_track_create`, `sona_track_destroy`, `sona_track_set_options`, `sona_track_reset` and more |
| `sona_xr_options` | A struct with `flags`, `user_height`, `step_distance`; taken by `sona_xr_defaults`, `sona_xr_create` |
| `sona_xr_input` | A struct with `flags`, `time`, `head`, `left_hand`, `right_hand`, `floor_y`; taken by `sona_xr_input_defaults`, `sona_xr_feed` |
| `sona_xr_body` | An opaque handle, made by `sona_xr_create` and freed by `sona_xr_destroy`; taken by `sona_xr_create`, `sona_xr_destroy`, `sona_xr_feed`, `sona_xr_calibrate` and more |
| `sona_source_kind` | The kind of a source in `sona_source_desc`: `SONA_SOURCE_CUSTOM`, `_GATE`, `_DIR`, `_CONSOLE` |
| `sona_event_type` | The kind of a `sona_event`: `SONA_EVENT_READY`, `_FAILED`, `_ERROR` and the rest |
| `sona_clip_event_kind` | The kind of a `sona_clip_event`: a clip starting, looping or ending, a footfall, a mark |
| `sona_layer_event_kind` | The kind of a `sona_layer_event` on an animation layer |
| `sona_tex_format` | The pixel format of a `sona_texture` in the data API |
| `sona_pass` | Which pass a mesh draws in: `SONA_PASS_OPAQUE` or `SONA_PASS_TRANSPARENT` |
| `sona_backend` | A graphics API: Vulkan, Direct3D 11, Direct3D 12, OpenGL, OpenGL ES, Metal or Xenos |
| `sona_corner` | A corner of the target, for the credit badge: `SONA_CORNER_BOTTOM_RIGHT` (0), `_BOTTOM_LEFT`, `_TOP_RIGHT`, `_TOP_LEFT` |
| `sona_face_record` | One face record of a manifest: an item id and four words |
| `sona_paint_image` | An RGBA8 picture for `sona_paint_spec`: pixels, width and height |
| `sona_paint_surface` | One surface of a painted item: its colour, regions and decal pictures (NULL `rgba`: none) |
| `sona_device_kind` | What a headless renderer may open: `SONA_DEVICE_AUTO`, `_GPU` or `_SOFTWARE` |
| `sona_video_format` | What a `sona_video` writes: a PNG sequence, GIF, MP4 or WebM |
| `sona_anim_format` | The format of an animation file: `SONA_ANIM_AUTO`, `_GLTF`, `_FBX` or `_BVH` |
| `sona_rig_naming` | How an imported file names its bones, for retargeting onto the avatar rig |
| `sona_player_state` | What is known of another player's avatar: waiting, fresh, stale, private or none |
| `sona_player_event_type` | The kind of a `sona_player_event` |
| `sona_like_item` | One item `sona_make_dress_like` carried across: from, to, the outcome and the section |
| `sona_filter_change` | One change a content filter made to a manifest: an item replaced (`SONA_CONTENT_REPLACED`) or hidden (`SONA_CONTENT_HIDDEN`) |
| `sona_light` | One of the host's lights in `sona_lighting` |
| `sona_style_kind` | An art style: `SONA_STYLE_ORIGINAL`, `_TOON`, `_FLAT`, `_SILHOUETTE` or `_PROMO` |
| `sona_placeholder_phase` | Where a placeholder figure is: none, waiting, loading, revealing or failed |
| `sona_screen_role` | The role of a `sona_screen_node`, for drawing it and for screen readers |
| `sona_ik_ground_fn` | The host's ground query for foot planting: a ray straight down from a point, returning the first hit and its normal |
| `sona_item_filter_fn` | A filter on catalogue items for the player screens: 1 to offer an item, 0 to leave it out |
| `sona_editor_vertex` | One vertex of the player editor's UI layer, for a host that draws it itself |
| `sona_editor_command` | One draw of the editor's UI layer: a texture, a range of indices and a scissor, blended with straight alpha |
| `sona_editor_filter_fn` | The editor's content filter hook: 0 leaves an item out of every list and every generated look |
| `sona_editor_look_fn` | The editor's seeded look hook: write look `index` of `seed` into the manifest and return 1, or 0 for the editor's own |
| `sona_editor_sound_fn` | Told when the editor would play one of its sounds |
| `sona_npc_speak_fn` | The host's text to speech for the NPC kit: mono 16-bit PCM for a line, or 0 to show it without a voice |
| `sona_npc_line_fn` | Told when the NPC starts and stops saying a line |
| `sona_blendshape` | The face blendshapes in ARKit's order (`SONA_TRACK_BLENDSHAPES` of them), the face tracker's input |
| `sona_track_mood` | The face's moods, the first seven shapes of every part of the avatar's face |
| `sona_xr_pose` | A pose in world metres, as OpenXR's `XrPosef`: a position, then a unit quaternion |
| `sona_xr_status` | What the last `sona_xr_apply` did, from `sona_xr_status_get`: tracked poses, eye height, scale, turn, placement, crouch, steps, the eyes' position |

## Threading and memory

- The owner thread calls everything. Inside `sona_update` the core drains completed reads, commits finished jobs, runs build steps inside `build_budget_ms`, advances clocks and poses due avatars. `sona_draw` and `sona_snapshot` fold the palettes with their own view.
- The device's queue. On Vulkan, `sona_snapshot` and `sona_item_preview_snapshot` submit on the `VkQueue` the host passed and wait for it. Vulkan requires the host to keep every other thread off that queue during those calls.
- A loaded catalogue never changes, so any thread may read it at once, with no ctx.
- Jobs are: decode an asset, decode a clip, bake a face sheet, build an avatar, CPU-skin a mesh slice. With workers (the core's threads or the host's `sona_jobs`) they run there and are committed on the owner thread in the next `sona_update`. With `worker_threads = 0` (WASM, a single-threaded Xbox 360 host) they run inside the build budget.
- Decoded shared data (assets, clips, textures) is immutable once committed and reference counted. Per-avatar data belongs to the avatar.
- The idle chooser's randomness comes from `config.seed`. A fixed seed makes every run repeatable.
- Every allocation goes through the config's allocator. `sona_stats` reports bytes in `cpu_mb` and `gpu_mb`. Eviction is idle first, oldest first. An Xbox 360 host sets `budget.total` (for example a budget of 96 MiB) and the caps; nothing in the core assumes a heap bigger than the budget.

## Left out on purpose

- No glTF export, for size only. The data API hands out every mesh, material and texture.
- No pointer controls, badge element, or resize and visibility observers: those are the web's DOM pieces. Wire input to `sona_camera_orbit`.
- No origin check: native apps have no origin. The licence file and the native check replace it. The WASM build keeps the web's origin check through the bridge.
- No offline gate use. Local sources are the offline path.
- No "do not clear" draw flag.
- The web's `samples()` and `benchmark()` live in sona-bench.

## Index of functions

| Function | Section |
|---|---|
| `sona_result_name` | [Results and errors](#sona_result_name) |
| `sona_last_error` | [Results and errors](#sona_last_error) |
| `sona_http_done` | [HTTP](#sona_http_done) |
| `sona_http_platform` | [HTTP](#sona_http_platform) |
| `sona_complete` | [Asset sources](#sona_complete) |
| `sona_config_defaults` | [The context](#sona_config_defaults) |
| `sona_open` | [The context](#sona_open) |
| `sona_close` | [The context](#sona_close) |
| `sona_app_id` | [The context](#sona_app_id) |
| `sona_version` | [The context](#sona_version) |
| `sona_platform` | [The context](#sona_platform) |
| `sona_struct_size` | [The context](#sona_struct_size) |
| `sona_struct_offset` | [The context](#sona_struct_offset) |
| `sona_abi_query` | [The context](#sona_abi_query) |
| `sona_poll_event` | [Events](#sona_poll_event) |
| `sona_add_defaults` | [Avatars](#sona_add_defaults) |
| `sona_avatar_add` | [Avatars](#sona_avatar_add) |
| `sona_avatar_add_base64` | [Avatars](#sona_avatar_add_base64) |
| `sona_avatar_state_of` | [Avatars](#sona_avatar_state_of) |
| `sona_avatar_id` | [Avatars](#sona_avatar_id) |
| `sona_avatar_play` | [Avatars](#sona_avatar_play) |
| `sona_avatar_stop` | [Avatars](#sona_avatar_stop) |
| `sona_avatar_move` | [Avatars](#sona_avatar_move) |
| `sona_avatar_set_visible` | [Avatars](#sona_avatar_set_visible) |
| `sona_avatar_bounds` | [Avatars](#sona_avatar_bounds) |
| `sona_avatar_remove` | [Avatars](#sona_avatar_remove) |
| `sona_joint_find` | [Game features](#sona_joint_find) |
| `sona_joint_name` | [Game features](#sona_joint_name) |
| `sona_joint_world` | [Game features](#sona_joint_world) |
| `sona_avatar_override` | [Game features](#sona_avatar_override) |
| `sona_avatar_clear_overrides` | [Game features](#sona_avatar_clear_overrides) |
| `sona_avatar_crossfade` | [Game features](#sona_avatar_crossfade) |
| `sona_avatar_queue` | [Game features](#sona_avatar_queue) |
| `sona_avatar_queued` | [Game features](#sona_avatar_queued) |
| `sona_avatar_capsule` | [Game features](#sona_avatar_capsule) |
| `sona_avatar_expression` | [Game features](#sona_avatar_expression) |
| `sona_avatar_expression_counts` | [Game features](#sona_avatar_expression_counts) |
| `sona_avatar_clip_events` | [Game features](#sona_avatar_clip_events) |
| `sona_avatar_mark` | [Game features](#sona_avatar_mark) |
| `sona_avatar_clear_marks` | [Game features](#sona_avatar_clear_marks) |
| `sona_avatar_root_motion` | [Game features](#sona_avatar_root_motion) |
| `sona_avatar_take_root_motion` | [Game features](#sona_avatar_take_root_motion) |
| `sona_layer_defaults` | [Animation layers](#sona_layer_defaults) |
| `sona_avatar_layer_play` | [Animation layers](#sona_avatar_layer_play) |
| `sona_avatar_layer_blend` | [Animation layers](#sona_avatar_layer_blend) |
| `sona_avatar_layer_machine` | [Animation layers](#sona_avatar_layer_machine) |
| `sona_avatar_layer_goto` | [Animation layers](#sona_avatar_layer_goto) |
| `sona_avatar_layer_weight` | [Animation layers](#sona_avatar_layer_weight) |
| `sona_avatar_layer_mask` | [Animation layers](#sona_avatar_layer_mask) |
| `sona_avatar_layer_stop` | [Animation layers](#sona_avatar_layer_stop) |
| `sona_avatar_layer_info` | [Animation layers](#sona_avatar_layer_info) |
| `sona_avatar_layer_events` | [Animation layers](#sona_avatar_layer_events) |
| `sona_mask_preset` | [Animation layers](#sona_mask_preset) |
| `sona_mask_branch` | [Animation layers](#sona_mask_branch) |
| `sona_param_id` | [Animation layers](#sona_param_id) |
| `sona_avatar_set_param` | [Animation layers](#sona_avatar_set_param) |
| `sona_avatar_set_params` | [Animation layers](#sona_avatar_set_params) |
| `sona_avatar_param` | [Animation layers](#sona_avatar_param) |
| `sona_blend_space_defaults` | [Animation layers](#sona_blend_space_defaults) |
| `sona_blend_space_create` | [Animation layers](#sona_blend_space_create) |
| `sona_blend_space_destroy` | [Animation layers](#sona_blend_space_destroy) |
| `sona_blend_space_weights` | [Animation layers](#sona_blend_space_weights) |
| `sona_state_machine_defaults` | [Animation layers](#sona_state_machine_defaults) |
| `sona_state_machine_create` | [Animation layers](#sona_state_machine_create) |
| `sona_state_machine_destroy` | [Animation layers](#sona_state_machine_destroy) |
| `sona_state_machine_find` | [Animation layers](#sona_state_machine_find) |
| `sona_state_machine_state_name` | [Animation layers](#sona_state_machine_state_name) |
| `sona_clip_count` | [Clips](#sona_clip_count) |
| `sona_clip_get` | [Clips](#sona_clip_get) |
| `sona_view_defaults` | [The frame](#sona_view_defaults) |
| `sona_update` | [The frame](#sona_update) |
| `sona_stats` | [The frame](#sona_stats) |
| `sona_lod_defaults` | [Crowds: level of detail and sprites](#sona_lod_defaults) |
| `sona_lod_set` | [Crowds: level of detail and sprites](#sona_lod_set) |
| `sona_lod_get` | [Crowds: level of detail and sprites](#sona_lod_get) |
| `sona_avatar_lod` | [Crowds: level of detail and sprites](#sona_avatar_lod) |
| `sona_lod_stats_get` | [Crowds: level of detail and sprites](#sona_lod_stats_get) |
| `sona_pose` | [The data API](#sona_pose) |
| `sona_pose_vertices` | [The data API](#sona_pose_vertices) |
| `sona_shading_get` | [The data API](#sona_shading_get) |
| `sona_shader_source` | [The data API](#sona_shader_source) |
| `sona_renderer_create` | [Drawing with the SDK's backends](#sona_renderer_create) |
| `sona_renderer_destroy` | [Drawing with the SDK's backends](#sona_renderer_destroy) |
| `sona_draw` | [Drawing with the SDK's backends](#sona_draw) |
| `sona_renderer_frame_index` | [Drawing with the SDK's backends](#sona_renderer_frame_index) |
| `sona_renderer_frame_done` | [Drawing with the SDK's backends](#sona_renderer_frame_done) |
| `sona_renderer_lost` | [Drawing with the SDK's backends](#sona_renderer_lost) |
| `sona_renderer_reset` | [Drawing with the SDK's backends](#sona_renderer_reset) |
| `sona_snapshot` | [Drawing with the SDK's backends](#sona_snapshot) |
| `sona_png_encode` | [Drawing with the SDK's backends](#sona_png_encode) |
| `sona_free` | [Drawing with the SDK's backends](#sona_free) |
| `sona_preview_defaults` | [Item previews](#sona_preview_defaults) |
| `sona_item_preview_add` | [Item previews](#sona_item_preview_add) |
| `sona_item_preview_bounds` | [Item previews](#sona_item_preview_bounds) |
| `sona_item_preview_view` | [Item previews](#sona_item_preview_view) |
| `sona_item_preview_draw` | [Item previews](#sona_item_preview_draw) |
| `sona_item_preview_snapshot` | [Item previews](#sona_item_preview_snapshot) |
| `sona_quality_defaults` | [Rendering quality](#sona_quality_defaults) |
| `sona_renderer_set_quality` | [Rendering quality](#sona_renderer_set_quality) |
| `sona_renderer_quality` | [Rendering quality](#sona_renderer_quality) |
| `sona_renderer_vk_features` | [Rendering quality](#sona_renderer_vk_features) |
| `sona_tier_defaults` | [Rendering quality](#sona_tier_defaults) |
| `sona_tier_apply` | [Rendering quality](#sona_tier_apply) |
| `sona_tier_detect` | [Rendering quality](#sona_tier_detect) |
| `sona_pixel_defaults` | [2D outputs](#sona_pixel_defaults) |
| `sona_pixel_art` | [2D outputs](#sona_pixel_art) |
| `sona_pixel_palette` | [2D outputs](#sona_pixel_palette) |
| `sona_sticker_defaults` | [2D outputs](#sona_sticker_defaults) |
| `sona_sticker` | [2D outputs](#sona_sticker) |
| `sona_sheet_defaults` | [2D outputs](#sona_sheet_defaults) |
| `sona_sheet_render` | [2D outputs](#sona_sheet_render) |
| `sona_sheet_free` | [2D outputs](#sona_sheet_free) |
| `sona_sheet_page_count` | [2D outputs](#sona_sheet_page_count) |
| `sona_sheet_page` | [2D outputs](#sona_sheet_page) |
| `sona_sheet_frame_count` | [2D outputs](#sona_sheet_frame_count) |
| `sona_sheet_frame_get` | [2D outputs](#sona_sheet_frame_get) |
| `sona_sheet_atlas` | [2D outputs](#sona_sheet_atlas) |
| `sona_camera_preset` | [Camera helpers](#sona_camera_preset) |
| `sona_camera_fit_crowd` | [Camera helpers](#sona_camera_fit_crowd) |
| `sona_camera_orbit` | [Camera helpers](#sona_camera_orbit) |
| `sona_view_matrices` | [Camera helpers](#sona_view_matrices) |
| `sona_manifest_parse` | [Manifests](#sona_manifest_parse) |
| `sona_manifest_write` | [Manifests](#sona_manifest_write) |
| `sona_slot_of` | [Manifests](#sona_slot_of) |
| `sona_guid_parse` | [Manifests](#sona_guid_parse) |
| `sona_guid_format` | [Manifests](#sona_guid_format) |
| `sona_base64_decode` | [Manifests](#sona_base64_decode) |
| `sona_manifest_wear` | [Manifests](#sona_manifest_wear) |
| `sona_manifest_unwear` | [Manifests](#sona_manifest_unwear) |
| `sona_manifest_undress_all` | [Manifests](#sona_manifest_undress_all) |
| `sona_manifest_set_colour` | [Manifests](#sona_manifest_set_colour) |
| `sona_manifest_set_gender` | [Manifests](#sona_manifest_set_gender) |
| `sona_manifest_set_shape` | [Manifests](#sona_manifest_set_shape) |
| `sona_manifest_ready_for_xbox` | [Manifests](#sona_manifest_ready_for_xbox) |
| `sona_credit_get` | [Credit](#sona_credit_get) |
| `sona_catalogue_load` | [The offline catalogue](#sona_catalogue_load) |
| `sona_catalogue_load_memory` | [The offline catalogue](#sona_catalogue_load_memory) |
| `sona_catalogue_free` | [The offline catalogue](#sona_catalogue_free) |
| `sona_catalogue_count` | [The offline catalogue](#sona_catalogue_count) |
| `sona_catalogue_get` | [The offline catalogue](#sona_catalogue_get) |
| `sona_catalogue_find` | [The offline catalogue](#sona_catalogue_find) |
| `sona_catalogue_find_guid` | [The offline catalogue](#sona_catalogue_find_guid) |
| `sona_catalogue_search` | [The offline catalogue](#sona_catalogue_search) |
| `sona_catalogue_game_count` | [The offline catalogue](#sona_catalogue_game_count) |
| `sona_catalogue_game` | [The offline catalogue](#sona_catalogue_game) |
| `sona_catalogue_generated` | [The offline catalogue](#sona_catalogue_generated) |
| `sona_catalogue_section_name` | [The offline catalogue](#sona_catalogue_section_name) |
| `sona_catalogue_language_count` | [The offline catalogue](#sona_catalogue_language_count) |
| `sona_catalogue_language` | [The offline catalogue](#sona_catalogue_language) |
| `sona_catalogue_item_name` | [The offline catalogue](#sona_catalogue_item_name) |
| `sona_item_colourways` | [The offline catalogue](#sona_item_colourways) |
| `sona_stock_clip_count` | [The stock clip library and the procedural idle](#sona_stock_clip_count) |
| `sona_stock_clip_at` | [The stock clip library and the procedural idle](#sona_stock_clip_at) |
| `sona_stock_clip_get` | [The stock clip library and the procedural idle](#sona_stock_clip_get) |
| `sona_stock_clip_find` | [The stock clip library and the procedural idle](#sona_stock_clip_find) |
| `sona_stock_clip_for_body` | [The stock clip library and the procedural idle](#sona_stock_clip_for_body) |
| `sona_stock_clips_tagged` | [The stock clip library and the procedural idle](#sona_stock_clips_tagged) |
| `sona_clip_tag_name` | [The stock clip library and the procedural idle](#sona_clip_tag_name) |
| `sona_clip_tag_find` | [The stock clip library and the procedural idle](#sona_clip_tag_find) |
| `sona_avatar_play_stock` | [The stock clip library and the procedural idle](#sona_avatar_play_stock) |
| `sona_idle_defaults` | [The stock clip library and the procedural idle](#sona_idle_defaults) |
| `sona_avatar_idle` | [The stock clip library and the procedural idle](#sona_avatar_idle) |
| `sona_avatar_idle_get` | [The stock clip library and the procedural idle](#sona_avatar_idle_get) |
| `sona_avatar_idle_state` | [The stock clip library and the procedural idle](#sona_avatar_idle_state) |
| `sona_idle_sample` | [The stock clip library and the procedural idle](#sona_idle_sample) |
| `sona_ik_target_defaults` | [Inverse kinematics](#sona_ik_target_defaults) |
| `sona_avatar_ik_target` | [Inverse kinematics](#sona_avatar_ik_target) |
| `sona_ik_feet_defaults` | [Inverse kinematics](#sona_ik_feet_defaults) |
| `sona_avatar_ik_feet` | [Inverse kinematics](#sona_avatar_ik_feet) |
| `sona_avatar_ik_ground` | [Inverse kinematics](#sona_avatar_ik_ground) |
| `sona_ik_look_defaults` | [Inverse kinematics](#sona_ik_look_defaults) |
| `sona_avatar_ik_look` | [Inverse kinematics](#sona_avatar_ik_look) |
| `sona_ik_limits_defaults` | [Inverse kinematics](#sona_ik_limits_defaults) |
| `sona_avatar_ik_limits` | [Inverse kinematics](#sona_avatar_ik_limits) |
| `sona_avatar_ik_clear` | [Inverse kinematics](#sona_avatar_ik_clear) |
| `sona_avatar_ik_status` | [Inverse kinematics](#sona_avatar_ik_status) |
| `sona_ik_foot_lock_defaults` | [Inverse kinematics](#sona_ik_foot_lock_defaults) |
| `sona_avatar_ik_foot_lock` | [Inverse kinematics](#sona_avatar_ik_foot_lock) |
| `sona_ik_spine_defaults` | [Inverse kinematics](#sona_ik_spine_defaults) |
| `sona_avatar_ik_spine` | [Inverse kinematics](#sona_avatar_ik_spine) |
| `sona_ik_fingers_defaults` | [Inverse kinematics](#sona_ik_fingers_defaults) |
| `sona_avatar_ik_fingers` | [Inverse kinematics](#sona_avatar_ik_fingers) |
| `sona_ik_eyes_defaults` | [Inverse kinematics](#sona_ik_eyes_defaults) |
| `sona_avatar_ik_eyes` | [Inverse kinematics](#sona_avatar_ik_eyes) |
| `sona_import_defaults` | [Imported clips](#sona_import_defaults) |
| `sona_import_formats` | [Imported clips](#sona_import_formats) |
| `sona_anim_file_load` | [Imported clips](#sona_anim_file_load) |
| `sona_anim_file_open` | [Imported clips](#sona_anim_file_open) |
| `sona_anim_file_free` | [Imported clips](#sona_anim_file_free) |
| `sona_anim_file_takes` | [Imported clips](#sona_anim_file_takes) |
| `sona_anim_file_take` | [Imported clips](#sona_anim_file_take) |
| `sona_anim_file_bones` | [Imported clips](#sona_anim_file_bones) |
| `sona_anim_file_bone` | [Imported clips](#sona_anim_file_bone) |
| `sona_clip_import` | [Imported clips](#sona_clip_import) |
| `sona_clip_imported_count` | [Imported clips](#sona_clip_imported_count) |
| `sona_clip_imported_get` | [Imported clips](#sona_clip_imported_get) |
| `sona_clip_imported_find` | [Imported clips](#sona_clip_imported_find) |
| `sona_clip_imported_remove` | [Imported clips](#sona_clip_imported_remove) |
| `sona_headless_defaults` | [Headless rendering and video out](#sona_headless_defaults) |
| `sona_headless_devices` | [Headless rendering and video out](#sona_headless_devices) |
| `sona_headless_open` | [Headless rendering and video out](#sona_headless_open) |
| `sona_headless_close` | [Headless rendering and video out](#sona_headless_close) |
| `sona_headless_info_get` | [Headless rendering and video out](#sona_headless_info_get) |
| `sona_headless_renderer` | [Headless rendering and video out](#sona_headless_renderer) |
| `sona_render_defaults` | [Headless rendering and video out](#sona_render_defaults) |
| `sona_headless_render` | [Headless rendering and video out](#sona_headless_render) |
| `sona_headless_render_manifest` | [Headless rendering and video out](#sona_headless_render_manifest) |
| `sona_headless_batch` | [Headless rendering and video out](#sona_headless_batch) |
| `sona_sequence_defaults` | [Headless rendering and video out](#sona_sequence_defaults) |
| `sona_headless_sequence` | [Headless rendering and video out](#sona_headless_sequence) |
| `sona_headless_record` | [Headless rendering and video out](#sona_headless_record) |
| `sona_video_defaults` | [Headless rendering and video out](#sona_video_defaults) |
| `sona_video_open` | [Headless rendering and video out](#sona_video_open) |
| `sona_video_frame` | [Headless rendering and video out](#sona_video_frame) |
| `sona_video_finish` | [Headless rendering and video out](#sona_video_finish) |
| `sona_video_formats` | [Headless rendering and video out](#sona_video_formats) |
| `sona_skeleton_bone` | [Skeleton maps and VRM export](#sona_skeleton_bone) |
| `sona_skeleton_joint` | [Skeleton maps and VRM export](#sona_skeleton_joint) |
| `sona_vrm_expression_name` | [Skeleton maps and VRM export](#sona_vrm_expression_name) |
| `sona_vrm_face_default` | [Skeleton maps and VRM export](#sona_vrm_face_default) |
| `sona_export_defaults` | [Skeleton maps and VRM export](#sona_export_defaults) |
| `sona_export_avatar` | [Skeleton maps and VRM export](#sona_export_avatar) |
| `sona_print_defaults` | [3D print export](#sona_print_defaults) |
| `sona_print_avatars` | [3D print export](#sona_print_avatars) |
| `sona_print_triangles` | [3D print export](#sona_print_triangles) |
| `sona_print_get` | [3D print export](#sona_print_get) |
| `sona_print_encode` | [3D print export](#sona_print_encode) |
| `sona_print_free` | [3D print export](#sona_print_free) |
| `sona_print_check` | [3D print export](#sona_print_check) |
| `sona_players_defaults` | [Other players' avatars by id](#sona_players_defaults) |
| `sona_players_open` | [Other players' avatars by id](#sona_players_open) |
| `sona_players_close` | [Other players' avatars by id](#sona_players_close) |
| `sona_players_watch` | [Other players' avatars by id](#sona_players_watch) |
| `sona_players_unwatch` | [Other players' avatars by id](#sona_players_unwatch) |
| `sona_players_refresh` | [Other players' avatars by id](#sona_players_refresh) |
| `sona_players_update` | [Other players' avatars by id](#sona_players_update) |
| `sona_players_poll` | [Other players' avatars by id](#sona_players_poll) |
| `sona_players_look` | [Other players' avatars by id](#sona_players_look) |
| `sona_players_forget` | [Other players' avatars by id](#sona_players_forget) |
| `sona_players_stats_get` | [Other players' avatars by id](#sona_players_stats_get) |
| `sona_players_placeholder` | [Other players' avatars by id](#sona_players_placeholder) |
| `sona_avatar_save_state` | [Avatar state, network sync and replays](#sona_avatar_save_state) |
| `sona_avatar_load_state` | [Avatar state, network sync and replays](#sona_avatar_load_state) |
| `sona_avatar_add_state` | [Avatar state, network sync and replays](#sona_avatar_add_state) |
| `sona_state_info_get` | [Avatar state, network sync and replays](#sona_state_info_get) |
| `sona_avatar_state_status` | [Avatar state, network sync and replays](#sona_avatar_state_status) |
| `sona_avatar_puppet` | [Avatar state, network sync and replays](#sona_avatar_puppet) |
| `sona_net_defaults` | [Avatar state, network sync and replays](#sona_net_defaults) |
| `sona_net_sender_create` | [Avatar state, network sync and replays](#sona_net_sender_create) |
| `sona_net_sender_destroy` | [Avatar state, network sync and replays](#sona_net_sender_destroy) |
| `sona_net_sender_look` | [Avatar state, network sync and replays](#sona_net_sender_look) |
| `sona_net_write` | [Avatar state, network sync and replays](#sona_net_write) |
| `sona_net_ack` | [Avatar state, network sync and replays](#sona_net_ack) |
| `sona_net_receiver_create` | [Avatar state, network sync and replays](#sona_net_receiver_create) |
| `sona_net_receiver_destroy` | [Avatar state, network sync and replays](#sona_net_receiver_destroy) |
| `sona_net_read` | [Avatar state, network sync and replays](#sona_net_read) |
| `sona_net_receiver_look` | [Avatar state, network sync and replays](#sona_net_receiver_look) |
| `sona_net_drive` | [Avatar state, network sync and replays](#sona_net_drive) |
| `sona_net_sender_stats` | [Avatar state, network sync and replays](#sona_net_sender_stats) |
| `sona_net_receiver_stats` | [Avatar state, network sync and replays](#sona_net_receiver_stats) |
| `sona_record_defaults` | [Avatar state, network sync and replays](#sona_record_defaults) |
| `sona_recorder_create` | [Avatar state, network sync and replays](#sona_recorder_create) |
| `sona_recorder_destroy` | [Avatar state, network sync and replays](#sona_recorder_destroy) |
| `sona_recorder_track` | [Avatar state, network sync and replays](#sona_recorder_track) |
| `sona_recorder_capture` | [Avatar state, network sync and replays](#sona_recorder_capture) |
| `sona_recorder_save` | [Avatar state, network sync and replays](#sona_recorder_save) |
| `sona_replay_open` | [Avatar state, network sync and replays](#sona_replay_open) |
| `sona_replay_close` | [Avatar state, network sync and replays](#sona_replay_close) |
| `sona_replay_info_get` | [Avatar state, network sync and replays](#sona_replay_info_get) |
| `sona_replay_track` | [Avatar state, network sync and replays](#sona_replay_track) |
| `sona_replay_drive` | [Avatar state, network sync and replays](#sona_replay_drive) |
| `sona_style_defaults` | [Art styles](#sona_style_defaults) |
| `sona_avatar_set_style` | [Art styles](#sona_avatar_set_style) |
| `sona_avatar_style` | [Art styles](#sona_avatar_style) |
| `sona_renderer_set_style` | [Art styles](#sona_renderer_set_style) |
| `sona_renderer_style` | [Art styles](#sona_renderer_style) |
| `sona_screen_theme_defaults` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_theme_defaults) |
| `sona_quick_defaults` | [Player screens: the quick creator and the wardrobe picker](#sona_quick_defaults) |
| `sona_quick_open` | [Player screens: the quick creator and the wardrobe picker](#sona_quick_open) |
| `sona_quick_look` | [Player screens: the quick creator and the wardrobe picker](#sona_quick_look) |
| `sona_wardrobe_defaults` | [Player screens: the quick creator and the wardrobe picker](#sona_wardrobe_defaults) |
| `sona_wardrobe_open` | [Player screens: the quick creator and the wardrobe picker](#sona_wardrobe_open) |
| `sona_screen_destroy` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_destroy) |
| `sona_screen_kind` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_kind) |
| `sona_screen_layout` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_layout) |
| `sona_screen_set_theme` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_set_theme) |
| `sona_screen_input` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_input) |
| `sona_screen_update` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_update) |
| `sona_screen_nodes` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_nodes) |
| `sona_screen_announcement` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_announcement) |
| `sona_screen_result` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_result) |
| `sona_screen_stats_get` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_stats_get) |
| `sona_screen_owns` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_owns) |
| `sona_screen_view_avatar` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_view_avatar) |
| `sona_screen_view_camera` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_view_camera) |
| `sona_screen_view_draw` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_view_draw) |
| `sona_screen_view_snapshot` | [Player screens: the quick creator and the wardrobe picker](#sona_screen_view_snapshot) |
| `sona_pick_defaults` | [Picking](#sona_pick_defaults) |
| `sona_view_ray` | [Picking](#sona_view_ray) |
| `sona_pick_ray` | [Picking](#sona_pick_ray) |
| `sona_pick_screen` | [Picking](#sona_pick_screen) |
| `sona_pick_ray_all` | [Picking](#sona_pick_ray_all) |
| `sona_avatar_pick` | [Picking](#sona_avatar_pick) |
| `sona_region_name` | [Picking](#sona_region_name) |
| `sona_pick_gpu` | [Picking](#sona_pick_gpu) |
| `sona_pick_gpu_ids` | [Picking](#sona_pick_gpu_ids) |
| `sona_sway_defaults` | [Hair and cloth sway](#sona_sway_defaults) |
| `sona_avatar_sway` | [Hair and cloth sway](#sona_avatar_sway) |
| `sona_avatar_sway_reset` | [Hair and cloth sway](#sona_avatar_sway_reset) |
| `sona_sway_world_defaults` | [Hair and cloth sway](#sona_sway_world_defaults) |
| `sona_sway_world_set` | [Hair and cloth sway](#sona_sway_world_set) |
| `sona_avatar_sway_info` | [Hair and cloth sway](#sona_avatar_sway_info) |
| `sona_avatar_sway_mesh_parts` | [Hair and cloth sway](#sona_avatar_sway_mesh_parts) |
| `sona_custom_item_check` | [Custom items](#sona_custom_item_check) |
| `sona_custom_item_add` | [Custom items](#sona_custom_item_add) |
| `sona_custom_item_remove` | [Custom items](#sona_custom_item_remove) |
| `sona_custom_item_count` | [Custom items](#sona_custom_item_count) |
| `sona_custom_item_get` | [Custom items](#sona_custom_item_get) |
| `sona_custom_item_find` | [Custom items](#sona_custom_item_find) |
| `sona_guid_is_custom` | [Custom items](#sona_guid_is_custom) |
| `sona_guid_pair` | [Custom items](#sona_guid_pair) |
| `sona_custom_item_new_id` | [Custom items](#sona_custom_item_new_id) |
| `sona_custom_item_pack` | [Custom items](#sona_custom_item_pack) |
| `sona_avatar_missing_items` | [Custom items](#sona_avatar_missing_items) |
| `sona_mesh_item_spec_defaults` | [Custom items](#sona_mesh_item_spec_defaults) |
| `sona_custom_item_pack_mesh` | [Custom items](#sona_custom_item_pack_mesh) |
| `sona_lipsync_defaults` | [Lip sync and voice mouths](#sona_lipsync_defaults) |
| `sona_lipsync_create` | [Lip sync and voice mouths](#sona_lipsync_create) |
| `sona_lipsync_destroy` | [Lip sync and voice mouths](#sona_lipsync_destroy) |
| `sona_lipsync_reset` | [Lip sync and voice mouths](#sona_lipsync_reset) |
| `sona_lipsync_feed` | [Lip sync and voice mouths](#sona_lipsync_feed) |
| `sona_lipsync_read` | [Lip sync and voice mouths](#sona_lipsync_read) |
| `sona_lipsync_current` | [Lip sync and voice mouths](#sona_lipsync_current) |
| `sona_lipsync_latency` | [Lip sync and voice mouths](#sona_lipsync_latency) |
| `sona_lipsync_hint` | [Lip sync and voice mouths](#sona_lipsync_hint) |
| `sona_phoneme_mouth` | [Lip sync and voice mouths](#sona_phoneme_mouth) |
| `sona_lipsync_phonemes` | [Lip sync and voice mouths](#sona_lipsync_phonemes) |
| `sona_lipsync_text` | [Lip sync and voice mouths](#sona_lipsync_text) |
| `sona_mouth_keys_sample` | [Lip sync and voice mouths](#sona_mouth_keys_sample) |
| `sona_avatar_mouth` | [Lip sync and voice mouths](#sona_avatar_mouth) |
| `sona_voice_mouth_init` | [Lip sync and voice mouths](#sona_voice_mouth_init) |
| `sona_voice_mouth_step` | [Lip sync and voice mouths](#sona_voice_mouth_step) |
| `sona_avatar_voice` | [Lip sync and voice mouths](#sona_avatar_voice) |
| `sona_voice_mouths` | [Lip sync and voice mouths](#sona_voice_mouths) |
| `sona_maker_create` | [Making avatars in code](#sona_maker_create) |
| `sona_maker_free` | [Making avatars in code](#sona_maker_free) |
| `sona_random_defaults` | [Making avatars in code](#sona_random_defaults) |
| `sona_make_random` | [Making avatars in code](#sona_make_random) |
| `sona_like_defaults` | [Making avatars in code](#sona_like_defaults) |
| `sona_make_dress_like` | [Making avatars in code](#sona_make_dress_like) |
| `sona_make_variant` | [Making avatars in code](#sona_make_variant) |
| `sona_outfit_clash` | [Making avatars in code](#sona_outfit_clash) |
| `sona_outfit_conflicts` | [Making avatars in code](#sona_outfit_conflicts) |
| `sona_outfit_set_count` | [Making avatars in code](#sona_outfit_set_count) |
| `sona_outfit_set_get` | [Making avatars in code](#sona_outfit_set_get) |
| `sona_outfit_set_of` | [Making avatars in code](#sona_outfit_set_of) |
| `sona_outfit_set_items` | [Making avatars in code](#sona_outfit_set_items) |
| `sona_outfit_check` | [Making avatars in code](#sona_outfit_check) |
| `sona_outfit_fix` | [Making avatars in code](#sona_outfit_fix) |
| `sona_outfit_issue_name` | [Making avatars in code](#sona_outfit_issue_name) |
| `sona_filter_create` | [Content filters](#sona_filter_create) |
| `sona_filter_free` | [Content filters](#sona_filter_free) |
| `sona_filter_reset` | [Content filters](#sona_filter_reset) |
| `sona_filter_sections` | [Content filters](#sona_filter_sections) |
| `sona_filter_slots` | [Content filters](#sona_filter_slots) |
| `sona_filter_sources` | [Content filters](#sona_filter_sources) |
| `sona_filter_game` | [Content filters](#sona_filter_game) |
| `sona_filter_tag` | [Content filters](#sona_filter_tag) |
| `sona_filter_item` | [Content filters](#sona_filter_item) |
| `sona_filter_preset` | [Content filters](#sona_filter_preset) |
| `sona_filter_load` | [Content filters](#sona_filter_load) |
| `sona_filter_tag_count` | [Content filters](#sona_filter_tag_count) |
| `sona_filter_tag_name` | [Content filters](#sona_filter_tag_name) |
| `sona_filter_tag_find` | [Content filters](#sona_filter_tag_find) |
| `sona_filter_tag_define` | [Content filters](#sona_filter_tag_define) |
| `sona_filter_tag_set` | [Content filters](#sona_filter_tag_set) |
| `sona_filter_item_tags` | [Content filters](#sona_filter_item_tags) |
| `sona_filter_tag_items` | [Content filters](#sona_filter_tag_items) |
| `sona_filter_allows` | [Content filters](#sona_filter_allows) |
| `sona_filter_check` | [Content filters](#sona_filter_check) |
| `sona_filter_search` | [Content filters](#sona_filter_search) |
| `sona_filter_allowed_count` | [Content filters](#sona_filter_allowed_count) |
| `sona_filter_manifest` | [Content filters](#sona_filter_manifest) |
| `sona_filter_manifest_bytes` | [Content filters](#sona_filter_manifest_bytes) |
| `sona_ctx_set_filter` | [Content filters](#sona_ctx_set_filter) |
| `sona_ctx_filter` | [Content filters](#sona_ctx_filter) |
| `sona_avatar_filter_report` | [Content filters](#sona_avatar_filter_report) |
| `sona_lighting_defaults` | [Lighting and shadows](#sona_lighting_defaults) |
| `sona_renderer_set_lighting` | [Lighting and shadows](#sona_renderer_set_lighting) |
| `sona_renderer_lighting` | [Lighting and shadows](#sona_renderer_lighting) |
| `sona_draw_lit` | [Lighting and shadows](#sona_draw_lit) |
| `sona_snapshot_lit` | [Lighting and shadows](#sona_snapshot_lit) |
| `sona_environment_defaults` | [Lighting and shadows](#sona_environment_defaults) |
| `sona_renderer_set_environment` | [Lighting and shadows](#sona_renderer_set_environment) |
| `sona_environment_irradiance` | [Lighting and shadows](#sona_environment_irradiance) |
| `sona_renderer_set_host_shadow` | [Lighting and shadows](#sona_renderer_set_host_shadow) |
| `sona_renderer_shadow_map` | [Lighting and shadows](#sona_renderer_shadow_map) |
| `sona_placeholder_defaults` | [Loading placeholders](#sona_placeholder_defaults) |
| `sona_placeholder_set` | [Loading placeholders](#sona_placeholder_set) |
| `sona_placeholder_get` | [Loading placeholders](#sona_placeholder_get) |
| `sona_placeholder_off` | [Loading placeholders](#sona_placeholder_off) |
| `sona_avatar_placeholder` | [Loading placeholders](#sona_avatar_placeholder) |
| `sona_avatar_placeholder_info` | [Loading placeholders](#sona_avatar_placeholder_info) |
| `sona_placeholder_stats_get` | [Loading placeholders](#sona_placeholder_stats_get) |
| `sona_avatar_add_waiting` | [Loading placeholders](#sona_avatar_add_waiting) |
| `sona_avatar_set_manifest` | [Loading placeholders](#sona_avatar_set_manifest) |
| `sona_avatar_set_manifest_base64` | [Loading placeholders](#sona_avatar_set_manifest_base64) |
| `sona_renderer_overlay` | [Overlays](#sona_renderer_overlay) |
| `sona_prop_part_defaults` | [Props: held and worn objects](#sona_prop_part_defaults) |
| `sona_prop_load_defaults` | [Props: held and worn objects](#sona_prop_load_defaults) |
| `sona_prop_mesh_create` | [Props: held and worn objects](#sona_prop_mesh_create) |
| `sona_prop_mesh_load` | [Props: held and worn objects](#sona_prop_mesh_load) |
| `sona_prop_mesh_open` | [Props: held and worn objects](#sona_prop_mesh_open) |
| `sona_prop_mesh_stock` | [Props: held and worn objects](#sona_prop_mesh_stock) |
| `sona_prop_mesh_state` | [Props: held and worn objects](#sona_prop_mesh_state) |
| `sona_prop_mesh_release` | [Props: held and worn objects](#sona_prop_mesh_release) |
| `sona_prop_mesh_info_get` | [Props: held and worn objects](#sona_prop_mesh_info_get) |
| `sona_prop_mesh_data` | [Props: held and worn objects](#sona_prop_mesh_data) |
| `sona_prop_attach_defaults` | [Props: held and worn objects](#sona_prop_attach_defaults) |
| `sona_avatar_prop_attach` | [Props: held and worn objects](#sona_avatar_prop_attach) |
| `sona_avatar_prop_set` | [Props: held and worn objects](#sona_avatar_prop_set) |
| `sona_avatar_prop_swap` | [Props: held and worn objects](#sona_avatar_prop_swap) |
| `sona_avatar_prop_get` | [Props: held and worn objects](#sona_avatar_prop_get) |
| `sona_avatar_prop_detach` | [Props: held and worn objects](#sona_avatar_prop_detach) |
| `sona_avatar_prop_detach_all` | [Props: held and worn objects](#sona_avatar_prop_detach_all) |
| `sona_avatar_prop_list` | [Props: held and worn objects](#sona_avatar_prop_list) |
| `sona_avatar_prop_frame` | [Props: held and worn objects](#sona_avatar_prop_frame) |
| `sona_avatar_prop_vertices` | [Props: held and worn objects](#sona_avatar_prop_vertices) |
| `sona_prop_pet_count` | [Props: held and worn objects](#sona_prop_pet_count) |
| `sona_prop_pet` | [Props: held and worn objects](#sona_prop_pet) |
| `sona_prop_is_pet` | [Props: held and worn objects](#sona_prop_is_pet) |
| `sona_ragdoll_defaults` | [Ragdolls](#sona_ragdoll_defaults) |
| `sona_avatar_ragdoll` | [Ragdolls](#sona_avatar_ragdoll) |
| `sona_avatar_ragdoll_state` | [Ragdolls](#sona_avatar_ragdoll_state) |
| `sona_avatar_ragdoll_drive` | [Ragdolls](#sona_avatar_ragdoll_drive) |
| `sona_avatar_ragdoll_release` | [Ragdolls](#sona_avatar_ragdoll_release) |
| `sona_avatar_ragdoll_info` | [Ragdolls](#sona_avatar_ragdoll_info) |
| `sona_avatar_ragdoll_clear` | [Ragdolls](#sona_avatar_ragdoll_clear) |
| `sona_avatar_ragdoll_motors` | [Ragdolls](#sona_avatar_ragdoll_motors) |
| `sona_seat_defaults` | [Two-avatar interactions and seats](#sona_seat_defaults) |
| `sona_interaction_defaults` | [Two-avatar interactions and seats](#sona_interaction_defaults) |
| `sona_interaction_layout` | [Two-avatar interactions and seats](#sona_interaction_layout) |
| `sona_interaction_start` | [Two-avatar interactions and seats](#sona_interaction_start) |
| `sona_interaction_end` | [Two-avatar interactions and seats](#sona_interaction_end) |
| `sona_interaction_move` | [Two-avatar interactions and seats](#sona_interaction_move) |
| `sona_interaction_remove` | [Two-avatar interactions and seats](#sona_interaction_remove) |
| `sona_interaction_status_get` | [Two-avatar interactions and seats](#sona_interaction_status_get) |
| `sona_interaction_events` | [Two-avatar interactions and seats](#sona_interaction_events) |
| `sona_emote_from_text` | [Text to emote](#sona_emote_from_text) |
| `sona_avatar_emote` | [Text to emote](#sona_avatar_emote) |
| `sona_award_def_defaults` | [Award items](#sona_award_def_defaults) |
| `sona_award_define` | [Award items](#sona_award_define) |
| `sona_award_unlock` | [Award items](#sona_award_unlock) |
| `sona_award_poll` | [Award items](#sona_award_poll) |
| `sona_body_defaults` | [Body tracking module (sona_body.h)](#sona_body_defaults) |
| `sona_body_create` | [Body tracking module (sona_body.h)](#sona_body_create) |
| `sona_body_destroy` | [Body tracking module (sona_body.h)](#sona_body_destroy) |
| `sona_body_reset` | [Body tracking module (sona_body.h)](#sona_body_reset) |
| `sona_body_input_defaults` | [Body tracking module (sona_body.h)](#sona_body_input_defaults) |
| `sona_body_feed` | [Body tracking module (sona_body.h)](#sona_body_feed) |
| `sona_body_apply` | [Body tracking module (sona_body.h)](#sona_body_apply) |
| `sona_body_release` | [Body tracking module (sona_body.h)](#sona_body_release) |
| `sona_body_struct_size` | [Body tracking module (sona_body.h)](#sona_body_struct_size) |
| `sona_body_struct_offset` | [Body tracking module (sona_body.h)](#sona_body_struct_offset) |
| `sona_editor_defaults` | [Player editor module (sona_editor.h)](#sona_editor_defaults) |
| `sona_editor_theme_defaults` | [Player editor module (sona_editor.h)](#sona_editor_theme_defaults) |
| `sona_editor_open` | [Player editor module (sona_editor.h)](#sona_editor_open) |
| `sona_editor_close` | [Player editor module (sona_editor.h)](#sona_editor_close) |
| `sona_editor_set_theme` | [Player editor module (sona_editor.h)](#sona_editor_set_theme) |
| `sona_editor_resize` | [Player editor module (sona_editor.h)](#sona_editor_resize) |
| `sona_editor_feed` | [Player editor module (sona_editor.h)](#sona_editor_feed) |
| `sona_editor_update` | [Player editor module (sona_editor.h)](#sona_editor_update) |
| `sona_editor_status` | [Player editor module (sona_editor.h)](#sona_editor_status) |
| `sona_editor_result` | [Player editor module (sona_editor.h)](#sona_editor_result) |
| `sona_editor_set_search` | [Player editor module (sona_editor.h)](#sona_editor_set_search) |
| `sona_editor_set_screen` | [Player editor module (sona_editor.h)](#sona_editor_set_screen) |
| `sona_editor_screen_get` | [Player editor module (sona_editor.h)](#sona_editor_screen_get) |
| `sona_editor_screens` | [Player editor module (sona_editor.h)](#sona_editor_screens) |
| `sona_editor_busy` | [Player editor module (sona_editor.h)](#sona_editor_busy) |
| `sona_editor_build_failures` | [Player editor module (sona_editor.h)](#sona_editor_build_failures) |
| `sona_editor_view` | [Player editor module (sona_editor.h)](#sona_editor_view) |
| `sona_editor_draw` | [Player editor module (sona_editor.h)](#sona_editor_draw) |
| `sona_editor_draw_avatar` | [Player editor module (sona_editor.h)](#sona_editor_draw_avatar) |
| `sona_editor_thumbnails` | [Player editor module (sona_editor.h)](#sona_editor_thumbnails) |
| `sona_editor_draw_data_get` | [Player editor module (sona_editor.h)](#sona_editor_draw_data_get) |
| `sona_editor_texture_get` | [Player editor module (sona_editor.h)](#sona_editor_texture_get) |
| `sona_editor_render_ui` | [Player editor module (sona_editor.h)](#sona_editor_render_ui) |
| `sona_editor_snapshot` | [Player editor module (sona_editor.h)](#sona_editor_snapshot) |
| `sona_editor_control_count` | [Player editor module (sona_editor.h)](#sona_editor_control_count) |
| `sona_editor_control_get` | [Player editor module (sona_editor.h)](#sona_editor_control_get) |
| `sona_editor_focus_get` | [Player editor module (sona_editor.h)](#sona_editor_focus_get) |
| `sona_editor_announcement` | [Player editor module (sona_editor.h)](#sona_editor_announcement) |
| `sona_editor_struct_size` | [Player editor module (sona_editor.h)](#sona_editor_struct_size) |
| `sona_editor_struct_offset` | [Player editor module (sona_editor.h)](#sona_editor_struct_offset) |
| `sona_npc_defaults` | [NPC kit module (sona_npc.h)](#sona_npc_defaults) |
| `sona_npc_create` | [NPC kit module (sona_npc.h)](#sona_npc_create) |
| `sona_npc_destroy` | [NPC kit module (sona_npc.h)](#sona_npc_destroy) |
| `sona_npc_say` | [NPC kit module (sona_npc.h)](#sona_npc_say) |
| `sona_npc_emote` | [NPC kit module (sona_npc.h)](#sona_npc_emote) |
| `sona_npc_look_at` | [NPC kit module (sona_npc.h)](#sona_npc_look_at) |
| `sona_npc_update` | [NPC kit module (sona_npc.h)](#sona_npc_update) |
| `sona_npc_state_get` | [NPC kit module (sona_npc.h)](#sona_npc_state_get) |
| `sona_npc_struct_size` | [NPC kit module (sona_npc.h)](#sona_npc_struct_size) |
| `sona_npc_struct_offset` | [NPC kit module (sona_npc.h)](#sona_npc_struct_offset) |
| `sona_track_blendshape_name` | [Face tracking module (sona_track.h)](#sona_track_blendshape_name) |
| `sona_track_blendshape_find` | [Face tracking module (sona_track.h)](#sona_track_blendshape_find) |
| `sona_track_defaults` | [Face tracking module (sona_track.h)](#sona_track_defaults) |
| `sona_track_create` | [Face tracking module (sona_track.h)](#sona_track_create) |
| `sona_track_destroy` | [Face tracking module (sona_track.h)](#sona_track_destroy) |
| `sona_track_set_options` | [Face tracking module (sona_track.h)](#sona_track_set_options) |
| `sona_track_reset` | [Face tracking module (sona_track.h)](#sona_track_reset) |
| `sona_track_face_input_defaults` | [Face tracking module (sona_track.h)](#sona_track_face_input_defaults) |
| `sona_track_face_feed` | [Face tracking module (sona_track.h)](#sona_track_face_feed) |
| `sona_track_face_get` | [Face tracking module (sona_track.h)](#sona_track_face_get) |
| `sona_track_calibrate_begin` | [Face tracking module (sona_track.h)](#sona_track_calibrate_begin) |
| `sona_track_calibrate_end` | [Face tracking module (sona_track.h)](#sona_track_calibrate_end) |
| `sona_track_calibration_set` | [Face tracking module (sona_track.h)](#sona_track_calibration_set) |
| `sona_track_calibration_get` | [Face tracking module (sona_track.h)](#sona_track_calibration_get) |
| `sona_track_apply` | [Face tracking module (sona_track.h)](#sona_track_apply) |
| `sona_track_release` | [Face tracking module (sona_track.h)](#sona_track_release) |
| `sona_track_quat_from_matrix` | [Face tracking module (sona_track.h)](#sona_track_quat_from_matrix) |
| `sona_track_quat_from_euler` | [Face tracking module (sona_track.h)](#sona_track_quat_from_euler) |
| `sona_track_struct_size` | [Face tracking module (sona_track.h)](#sona_track_struct_size) |
| `sona_track_struct_offset` | [Face tracking module (sona_track.h)](#sona_track_struct_offset) |
| `sona_xr_defaults` | [XR body module (sona_xr.h)](#sona_xr_defaults) |
| `sona_xr_create` | [XR body module (sona_xr.h)](#sona_xr_create) |
| `sona_xr_destroy` | [XR body module (sona_xr.h)](#sona_xr_destroy) |
| `sona_xr_input_defaults` | [XR body module (sona_xr.h)](#sona_xr_input_defaults) |
| `sona_xr_feed` | [XR body module (sona_xr.h)](#sona_xr_feed) |
| `sona_xr_calibrate` | [XR body module (sona_xr.h)](#sona_xr_calibrate) |
| `sona_xr_apply` | [XR body module (sona_xr.h)](#sona_xr_apply) |
| `sona_xr_release` | [XR body module (sona_xr.h)](#sona_xr_release) |
| `sona_xr_status_get` | [XR body module (sona_xr.h)](#sona_xr_status_get) |
| `sona_xr_openxr_to_world` | [XR body module (sona_xr.h)](#sona_xr_openxr_to_world) |
| `sona_xr_struct_size` | [XR body module (sona_xr.h)](#sona_xr_struct_size) |
| `sona_xr_struct_offset` | [XR body module (sona_xr.h)](#sona_xr_struct_offset) |
