Skip to content

Web SDK: Custom items

Items of your own (.sonaitem files, custom items), per scene as scene.items, worn by id with avatar.wear().

scene.items.add()

interface SonaItems {
  add(file: ArrayBuffer | Uint8Array | Blob): Promise<CustomItemInfo>;
}

Checks the file and keeps it. Avatars wearing its id rebuild. Rejects with SonaError("item"), whose message names the rule and whose fix says what to do. A higher version of a loaded id replaces it; the same version with other bytes is refused.

Parameter Type Meaning
file ArrayBuffer | Uint8Array | Blob The .sonaitem file: its bytes or a Blob.

Returns Promise<CustomItemInfo>.

import { SonaRenderer } from './sona-renderer.js';

const canvas = document.querySelector('canvas');
const sona = await SonaRenderer.create({ canvas });
const bytes = await (await fetch('night-sky.sonaitem')).arrayBuffer();
const info = await sona.items.add(bytes);
const avatar = sona.add(SonaRenderer.wear(manifestBase64, info.id));

scene.items.remove()

interface SonaItems {
  remove(id: string): boolean;
}

Forgets it. Avatars wearing it rebuild with the slot's fallback (see SonaAvatar.missingItems).

Parameter Type Meaning
id string A custom item id.

Returns boolean.

scene.items.get()

interface SonaItems {
  get(id: string): CustomItemInfo | null;
}

A loaded item, or null.

Parameter Type Meaning
id string A custom item id.

Returns CustomItemInfo | null.

scene.items.list()

interface SonaItems {
  list(): CustomItemInfo[];
}

Every loaded item.

Returns CustomItemInfo[].

scene.items.pack()

interface SonaItems {
  pack(spec: PackSpec): Promise<Uint8Array>;
}

Makes a .sonaitem from pixels. Reads the template through 360sona to check its surfaces and take its hash. Unsigned.

Parameter Type Meaning
spec PackSpec The template, the pictures and the item's details.

Returns Promise<Uint8Array>.

CustomItemInfo

What a custom item file holds, as checked.

Field Type Meaning
id string The item's id, which avatars wear it by.
slot string The wardrobe slot its id names: "shirt", "headwear", "carryable" and the rest.
mask number The item type bits its id carries.
body 'man' | 'woman' | 'both' The body it fits, read from its id.
name string Its name, 1 to 48 characters.
creator string | null The creator's display name, or null when the file names none. Not an account.
version number Its version, 1 or more; a higher version of a loaded id replaces it.
sha256 string SHA-256 of the file's hashed part, 64 lowercase hex digits.
template { id: string; sha256: string } The stock template it was painted on: its item id and the SHA-256 of the template's bytes.
surfaces { color: [number, number]; regions: [number, number] | null; decal: [number, number] | null }[] Each surface's texture sizes, [width, height].
colourways [string, string, string][] Its colourways, each three "#rrggbb" colours; empty when it has none.
signed { creator: boolean; site: boolean } Whether the file carries the creator's signature and 360sona's.
bytes number The file's size in bytes.
warnings string[] What the check let through but noted, in plain words (an ignored lower version, an unknown key).

PackSpec

The input to scene.items.pack. Images are RGBA; colour sides 64 to 512, regions and decal 32 to 512, powers of two.

Field Type Meaning
id (optional) string Default: a fresh id for the template.
template string The stock template's item id, whose surfaces the pictures paint.
name string The item's name, 1 to 48 characters.
version (optional) number 1 or more, up by one each time you change the item. Default 1.
description (optional) string Up to 280 characters. Default: none.
creator (optional) string Your display name, up to 48 characters. Default: none.
created (optional) string The day it was made, "YYYY-MM-DD". Default: none.
licence (optional) string Up to 64 characters. Default "wear": anyone may wear, show and share it; nobody may sell it.
surfaces { color: ImageData; regions?: ImageData; decal?: ImageData; layout?: 'split' | 'template' }[] One per template surface. layout defaults to "template" (the template's own colour layout).
colourways (optional) [string, string, string][] Up to 32 triples of "#rrggbb". Needed when any surface has regions.

Award

An award item of your app, as the award calls give it.

Field Type Meaning
key string Its key, unique in your app.
title string Its name, as players see it.
description string | null The line under its title, or null.
item string The item id it gives: a stock avatar award or your custom item.
file string | null Where its .sonaitem is (awardFile() reads it), or null for a stock item.
made number When it was defined (Unix milliseconds).
at number When it last changed (Unix milliseconds).
retired (optional) number When it was retired (Unix milliseconds); absent while it is offered.
unlocked (optional) number In playerAwards(): when the player unlocked it (Unix milliseconds).

This page as Markdown · All the docs as one file (llms-full.txt)