C API: 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. 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¶
uint32_t sona_stock_clip_count(void);
Returns uint32_t.
Example:
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¶
sona_result sona_stock_clip_at(uint32_t index, sona_stock_clip *out);
| Parameter and type | Meaning |
|---|---|
indexuint32_t |
Which one, from 0 |
outsona_stock_clip * |
Receives the sona_stock_clip (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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¶
sona_result sona_stock_clip_get(uint32_t id, sona_stock_clip *out);
| Parameter and type | Meaning |
|---|---|
iduint32_t |
A stock clip id, from 1 |
outsona_stock_clip * |
Receives the sona_stock_clip (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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¶
uint32_t sona_stock_clip_find(const char *name);
| Parameter and type | Meaning |
|---|---|
nameconst char * |
The name to look up (required) |
Returns uint32_t.
Example (also in Clips: the stock clip library and the procedural idle):
/* 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;
/* blinks, glances, weight shifts and breathing, seed from the ctx */
sona_idle_defaults(&idle);
sona_avatar_idle(avatar, &idle);
/* crossfade into a wave */
sona_avatar_play_stock(avatar, SONA_STOCK_WAVE, NULL, 0.3f);
/* NULL opts: loops when the clip loops */
sona_avatar_play_stock(avatar, sona_stock_clip_find("laugh"), NULL, 0);
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¶
uint32_t sona_stock_clip_for_body(uint32_t id, uint32_t body);
| Parameter and type | Meaning |
|---|---|
iduint32_t |
A stock clip id |
bodyuint32_t |
The body a clip or item is for: 1 male, 2 female |
Returns uint32_t.
Example:
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¶
uint32_t sona_stock_clips_tagged(uint32_t all, uint32_t none, uint32_t body,
uint32_t *ids, uint32_t cap);
| Parameter and type | Meaning |
|---|---|
alluint32_t |
Tag bits a clip must all have |
noneuint32_t |
Tag bits a clip must not have |
bodyuint32_t |
The body the clips must suit: 1 male, 2 female; 0: any (0: any) |
idsuint32_t * |
Receives the ids; may be NULL to count (NULL: not written) |
capuint32_t |
How many entries out holds |
Returns uint32_t.
Example (also in Clips: the stock clip library and the procedural idle):
/* 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;
/* blinks, glances, weight shifts and breathing, seed from the ctx */
sona_idle_defaults(&idle);
sona_avatar_idle(avatar, &idle);
/* crossfade into a wave */
sona_avatar_play_stock(avatar, SONA_STOCK_WAVE, NULL, 0.3f);
/* NULL opts: loops when the clip loops */
sona_avatar_play_stock(avatar, sona_stock_clip_find("laugh"), NULL, 0);
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¶
const char *sona_clip_tag_name(uint32_t tag);
| Parameter and type | Meaning |
|---|---|
taguint32_t |
A tag's bit |
Returns const char *.
Example:
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¶
uint32_t sona_clip_tag_find(const char *name);
| Parameter and type | Meaning |
|---|---|
nameconst char * |
The name to look up (required) |
Returns uint32_t.
Example:
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¶
sona_result sona_avatar_play_stock(sona_avatar *a, uint32_t id,
const sona_play_options *opts,
float fade_seconds);
| Parameter and type | Meaning |
|---|---|
asona_avatar * |
The avatar (required) |
iduint32_t |
A stock clip id |
optsconst sona_play_options * |
The options, a sona_play_options (required) |
fade_secondsfloat |
Seconds to blend over |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_NOT_FOUND (what each means).
Example (also in Cookbook: recipes for game moments):
/* position, turn, scale */
sona_placement to = { { 2.0f, 0.0f, -3.0f }, 90.0f, 1.0f };
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¶
void sona_idle_defaults(sona_idle_options *o);
| Parameter and type | Meaning |
|---|---|
osona_idle_options * |
The sona_idle_options to fill with the defaults (required) |
Returns Nothing.
Example (also in Clips: the stock clip library and the procedural idle):
sona_idle_options o;
/* parts SONA_IDLE_ALL, seed 0, amount 1, face_px 240 */
sona_idle_defaults(&o);
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¶
sona_result sona_avatar_idle(sona_avatar *a, const sona_idle_options *o);
| Parameter and type | Meaning |
|---|---|
asona_avatar * |
The avatar (required) |
oconst sona_idle_options * |
The options, a sona_idle_options (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_MEMORY (what each means).
Example (also in Clips: the stock clip library and the procedural idle):
sona_idle_options o;
/* parts SONA_IDLE_ALL, seed 0, amount 1, face_px 240 */
sona_idle_defaults(&o);
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¶
sona_result sona_avatar_idle_get(const sona_avatar *a,
sona_idle_options *out);
| Parameter and type | Meaning |
|---|---|
aconst sona_avatar * |
The avatar (required) |
outsona_idle_options * |
Receives the sona_idle_options (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
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¶
sona_result sona_avatar_idle_state(const sona_avatar *a,
sona_idle_state *out);
| Parameter and type | Meaning |
|---|---|
aconst sona_avatar * |
The avatar (required) |
outsona_idle_state * |
Receives the sona_idle_state (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
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¶
sona_result sona_idle_sample(const sona_idle_options *o, double seconds,
sona_idle_state *out);
| Parameter and type | Meaning |
|---|---|
oconst sona_idle_options * |
The options, a sona_idle_options (required) |
secondsdouble |
The time to sample, seconds |
outsona_idle_state * |
Receives the sona_idle_state (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
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.
This page as Markdown · All the docs as one file (llms-full.txt)