# C API: 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`](../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`](../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`](../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`](../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`](../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`](../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`](../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`](../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`](../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`](../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`](../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`](../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`](../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.
