C API: Skeleton maps and VRM export¶
The guides are VRM and glTF export (the file, the flattening, the expressions, what was checked)
and Skeleton maps (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¶
const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint);
| Parameter and type | Meaning |
|---|---|
skeletonuint32_t |
A sona_skeleton_kind |
jointuint32_t |
A joint index, from sona_joint_find |
Returns const char *.
Example (also in Skeleton maps: Unity Humanoid, VRM and the Unreal mannequins):
/* NULL: that skeleton has no such bone */
const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint);
/* -1: none; names match exactly */
int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone);
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¶
int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone);
| Parameter and type | Meaning |
|---|---|
skeletonuint32_t |
A sona_skeleton_kind |
boneconst char * |
A bone name of that skeleton (required) |
Returns int32_t.
Example (also in Skeleton maps: Unity Humanoid, VRM and the Unreal mannequins):
/* NULL: that skeleton has no such bone */
const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint);
/* -1: none; names match exactly */
int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone);
The joint a bone of that skeleton is, matched exactly; -1 when none.
sona_vrm_expression_name¶
const char *sona_vrm_expression_name(uint32_t expression);
| Parameter and type | Meaning |
|---|---|
expressionuint32_t |
A VRM expression index |
Returns const char *.
Example:
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¶
sona_result sona_vrm_face_default(uint32_t expression, sona_vrm_face *out);
| Parameter and type | Meaning |
|---|---|
expressionuint32_t |
A VRM expression index |
outsona_vrm_face * |
Receives the sona_vrm_face (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
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¶
void sona_export_defaults(sona_export_options *o);
| Parameter and type | Meaning |
|---|---|
osona_export_options * |
The sona_export_options to fill with the defaults (required) |
Returns Nothing.
Example (also in FBX, Roblox and clips in the export):
sona_export_options o;
uint8_t *fbx = NULL;
size_t fbx_len = 0;
sona_export_defaults(&o);
o.format = SONA_EXPORT_FBX;
/* the clip it plays, as an animation on the skeleton */
o.flags = SONA_EXPORT_CLIPS;
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¶
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 and type | Meaning |
|---|---|
asona_avatar * |
The avatar (required) |
oconst sona_export_options * |
The options, a sona_export_options (NULL: the defaults) |
outuint8_t ** |
Receives the bytes; free them with sona_free (required) |
out_lensize_t * |
Receives how many bytes *out holds (required) |
reportsona_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).
Example (also in FBX, Roblox and clips in the export):
sona_export_options o;
uint8_t *fbx = NULL;
size_t fbx_len = 0;
sona_export_defaults(&o);
o.format = SONA_EXPORT_FBX;
/* the clip it plays, as an animation on the skeleton */
o.flags = SONA_EXPORT_CLIPS;
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.
This page as Markdown · All the docs as one file (llms-full.txt)