C API: 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. Structs:
sona_import_options, sona_import_info, sona_bone_map, and the opaque sona_anim_file.
sona_import_defaults¶
void sona_import_defaults(sona_import_options *o);
| Parameter and type | Meaning |
|---|---|
osona_import_options * |
The sona_import_options to fill with the defaults (required) |
Returns Nothing.
Example (also in Bring your own animation):
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];
sona_import_defaults(&o);
/* NULL: the take's own name */
o.key = "wave_big";
if (sona_anim_file_open("wave.fbx", &o, &f, why,
sizeof why) != SONA_OK) { puts(why); return; }
/* waits for the rig data, read through the sources */
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)
sona_update(ctx, 1.0 / 60, &view, NULL);
/* the clip is kept; the file is not needed any more */
sona_anim_file_free(f);
sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f);
Zeroes the options and sets size.
sona_import_formats¶
uint32_t sona_import_formats(void);
Returns uint32_t.
Example:
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¶
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 and type | Meaning |
|---|---|
bytesconst void * |
The file's bytes (required) |
lensize_t |
How many bytes there are |
optsconst sona_import_options * |
The options, a sona_import_options (NULL allowed (below)) |
outsona_anim_file ** |
Receives the new animation file (required) |
whychar * |
Receives what was refused, NUL-terminated; may be NULL (NULL: not written) |
why_capsize_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).
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¶
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 and type | Meaning |
|---|---|
pathconst char * |
A file path (required) |
optsconst sona_import_options * |
The options, a sona_import_options (required) |
outsona_anim_file ** |
Receives the new animation file (required) |
whychar * |
Receives what was refused, NUL-terminated; may be NULL (NULL: not written) |
why_capsize_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).
Example (also in Bring your own animation):
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];
sona_import_defaults(&o);
/* NULL: the take's own name */
o.key = "wave_big";
if (sona_anim_file_open("wave.fbx", &o, &f, why,
sizeof why) != SONA_OK) { puts(why); return; }
/* waits for the rig data, read through the sources */
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)
sona_update(ctx, 1.0 / 60, &view, NULL);
/* the clip is kept; the file is not needed any more */
sona_anim_file_free(f);
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¶
void sona_anim_file_free(sona_anim_file *f);
| Parameter and type | Meaning |
|---|---|
fsona_anim_file * |
The animation file (required) |
Returns Nothing.
Example (also in Bring your own animation):
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];
sona_import_defaults(&o);
/* NULL: the take's own name */
o.key = "wave_big";
if (sona_anim_file_open("wave.fbx", &o, &f, why,
sizeof why) != SONA_OK) { puts(why); return; }
/* waits for the rig data, read through the sources */
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)
sona_update(ctx, 1.0 / 60, &view, NULL);
/* the clip is kept; the file is not needed any more */
sona_anim_file_free(f);
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¶
uint32_t sona_anim_file_takes(const sona_anim_file *f);
| Parameter and type | Meaning |
|---|---|
fconst sona_anim_file * |
The animation file (required) |
Returns uint32_t.
How many takes (animations) the file holds.
sona_anim_file_take¶
const char *sona_anim_file_take(const sona_anim_file *f, uint32_t index,
float *seconds);
| Parameter and type | Meaning |
|---|---|
fconst sona_anim_file * |
The animation file (required) |
indexuint32_t |
Which one, from 0 |
secondsfloat * |
Receives the take's length, seconds (required) |
Returns const char *.
A take's name and length; NULL past the last.
sona_anim_file_bones¶
uint32_t sona_anim_file_bones(const sona_anim_file *f);
| Parameter and type | Meaning |
|---|---|
fconst sona_anim_file * |
The animation file (required) |
Returns uint32_t.
How many bones the file's skeleton has.
sona_anim_file_bone¶
const char *sona_anim_file_bone(const sona_anim_file *f, uint32_t index,
int32_t *parent, int32_t *joint);
| Parameter and type | Meaning |
|---|---|
fconst sona_anim_file * |
The animation file (required) |
indexuint32_t |
Which one, from 0 |
parentint32_t * |
Receives the parent bone's index, -1 for a root (required) |
jointint32_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¶
sona_result sona_clip_import(sona_ctx *ctx, const sona_anim_file *f,
const sona_import_options *opts,
sona_import_info *info);
| Parameter and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
fconst sona_anim_file * |
The animation file (required) |
optsconst sona_import_options * |
The options, a sona_import_options (required) |
infosona_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).
Example (also in Bring your own animation):
sona_import_options o;
sona_import_info info;
sona_anim_file *f;
char why[256];
sona_import_defaults(&o);
/* NULL: the take's own name */
o.key = "wave_big";
if (sona_anim_file_open("wave.fbx", &o, &f, why,
sizeof why) != SONA_OK) { puts(why); return; }
/* waits for the rig data, read through the sources */
while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING)
sona_update(ctx, 1.0 / 60, &view, NULL);
/* the clip is kept; the file is not needed any more */
sona_anim_file_free(f);
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¶
uint32_t sona_clip_imported_count(const sona_ctx *ctx);
| Parameter and type | Meaning |
|---|---|
ctxconst sona_ctx * |
The context (required) |
Returns uint32_t.
Example:
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¶
sona_result sona_clip_imported_get(const sona_ctx *ctx, uint32_t index,
sona_import_info *out);
| Parameter and type | Meaning |
|---|---|
ctxconst sona_ctx * |
The context (required) |
indexuint32_t |
Which one, from 0 |
outsona_import_info * |
Receives the sona_import_info (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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¶
sona_result sona_clip_imported_find(const sona_ctx *ctx, const char *key,
sona_import_info *out);
| Parameter and type | Meaning |
|---|---|
ctxconst sona_ctx * |
The context (required) |
keyconst char * |
The key, as it was given when made (required) |
outsona_import_info * |
Receives the sona_import_info (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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¶
sona_result sona_clip_imported_remove(sona_ctx *ctx, const char *key);
| Parameter and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
keyconst char * |
The key, as it was given when made (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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.
This page as Markdown · All the docs as one file (llms-full.txt)