C API: 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.
sona_custom_item_check¶
sona_result sona_custom_item_check(const void *bytes, size_t len,
sona_custom_item_info *info, char *why,
size_t why_cap);
| Parameter and type | Meaning |
|---|---|
bytesconst void * |
The file's bytes (required) |
lensize_t |
How many bytes there are |
infosona_custom_item_info * |
Receives what the file holds; may be NULL (NULL: not written) |
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_UNSUPPORTED, SONA_E_LIMIT, SONA_E_CORRUPT (what each means).
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¶
sona_result sona_custom_item_add(sona_ctx *ctx, const void *bytes,
size_t len, sona_guid *out_id);
| Parameter and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
bytesconst void * |
The file's bytes (required) |
lensize_t |
How many bytes there are |
out_idsona_guid * |
Receives the item's id (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_LIMIT, SONA_E_MEMORY (what each means).
Example (also in Custom items):
sona_guid id;
sona_manifest m;
uint8_t worn[SONA_MANIFEST_BYTES];
/* the bytes of night-sky.sonaitem */
if (sona_custom_item_add(ctx, file, file_len, &id) == SONA_OK &&
/* an avatar's 1,000 bytes */
sona_manifest_parse(manifest, &m) == SONA_OK &&
sona_manifest_wear(&m, &id, NULL, 0) == SONA_OK &&
sona_manifest_write(&m, worn) == SONA_OK)
/* an avatar wearing it */
sona_avatar_add(ctx, worn, NULL, &avatar);
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¶
sona_result sona_custom_item_remove(sona_ctx *ctx, const sona_guid *id);
| Parameter and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
idconst sona_guid * |
An item id (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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¶
uint32_t sona_custom_item_count(const sona_ctx *ctx);
| Parameter and type | Meaning |
|---|---|
ctxconst sona_ctx * |
The context (required) |
Returns uint32_t.
Example:
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¶
sona_result sona_custom_item_get(const sona_ctx *ctx, uint32_t index,
sona_custom_item_info *out);
| Parameter and type | Meaning |
|---|---|
ctxconst sona_ctx * |
The context (required) |
indexuint32_t |
Which one, from 0 |
outsona_custom_item_info * |
Receives the sona_custom_item_info (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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¶
sona_result sona_custom_item_find(const sona_ctx *ctx, const sona_guid *id,
sona_custom_item_info *out);
| Parameter and type | Meaning |
|---|---|
ctxconst sona_ctx * |
The context (required) |
idconst sona_guid * |
An item id (required) |
outsona_custom_item_info * |
Receives the sona_custom_item_info (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Example:
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¶
int sona_guid_is_custom(const sona_guid *id);
| Parameter and type | Meaning |
|---|---|
idconst sona_guid * |
An item id (required) |
Returns int.
Example:
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¶
sona_result sona_guid_pair(const sona_guid *id, sona_guid *out);
| Parameter and type | Meaning |
|---|---|
idconst sona_guid * |
An item id (required) |
outsona_guid * |
Receives the sona_guid (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
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¶
sona_result sona_custom_item_new_id(sona_ctx *ctx,
const sona_guid *template_id,
sona_guid *out);
| Parameter and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
template_idconst sona_guid * |
A sona_guid (required) |
outsona_guid * |
Receives the sona_guid (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
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¶
sona_result sona_custom_item_pack(sona_ctx *ctx,
const sona_paint_spec *spec,
uint8_t **out, size_t *out_len);
| Parameter and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
specconst sona_paint_spec * |
The options, a sona_paint_spec (required) |
outuint8_t ** |
Receives the bytes; free them with sona_free (required) |
out_lensize_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).
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 has the format.
sona_avatar_missing_items¶
uint32_t sona_avatar_missing_items(const sona_avatar *a, sona_guid *out,
uint32_t cap);
| Parameter and type | Meaning |
|---|---|
aconst sona_avatar * |
The avatar (required) |
outsona_guid * |
Receives the sona_guid (required) |
capuint32_t |
How many entries out holds |
Returns uint32_t.
Example:
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¶
void sona_mesh_item_spec_defaults(sona_mesh_item_spec *s);
| Parameter and type | Meaning |
|---|---|
ssona_mesh_item_spec * |
The sona_mesh_item_spec to fill with the defaults (required) |
Returns Nothing.
Example:
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¶
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 and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
specconst sona_mesh_item_spec * |
The options, a sona_mesh_item_spec (required) |
outuint8_t ** |
Receives the bytes; free them with sona_free (required) |
out_lensize_t * |
Receives how many bytes *out holds (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, SONA_PENDING while it is still working. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND, SONA_E_MEMORY, SONA_E_IO (what each means).
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, sections 5.2 and 5.3).
This page as Markdown · All the docs as one file (llms-full.txt)