Web SDK: Connection and headless¶
SonaRenderer.connect() gives avatars as .glb files with their clips, for engines that draw them themselves; SonaRenderer.headless() makes pictures with no canvas on the page.
SonaConnection properties¶
| Field | Type | Meaning |
|---|---|---|
appId |
string |
The app id the connection was opened for. Read only. |
connection.glb()¶
interface SonaConnection {
glb(
manifestBase64: string,
opts?: { clips?: ClipKey[] | null; textures?: boolean },
): Promise<ArrayBuffer>;
}
An avatar as a .glb with the clips asked for (all by default), the renderer's light baked into unlit materials.
| Parameter | Type | Meaning |
|---|---|---|
manifestBase64 |
string |
The avatar's 1,000-byte manifest, base64. |
opts.clips (optional) |
ClipKey[] | null |
The clips to include. Default null: every clip but "prop". |
opts.textures (optional) |
boolean |
Embed the textures. Default true. |
Returns Promise<ArrayBuffer>.
connection.clips()¶
interface SonaConnection {
clips(): ClipInfo[];
}
Every clip a glb() can take.
Returns ClipInfo[].
connection.samples()¶
interface SonaConnection {
samples(): Promise<{ title: string; manifest: string }[]>;
}
The sample avatars: a title and a base64 manifest each.
Returns Promise<{ title: string; manifest: string }[]>.
connection.wardrobe()¶
interface SonaConnection {
wardrobe(): Promise<readonly WardrobeItem[]>;
}
Every item an avatar can wear, as the editor offers them.
Returns Promise<readonly WardrobeItem[]>.
connection.colours()¶
interface SonaConnection {
colours(): Record<string, string[]>;
}
The colour choices of each colourable part (skin, hair, eyes and the rest), each "#rrggbb".
Returns Record<string, string[]>.
connection.credit()¶
interface SonaConnection {
credit(
canvas: HTMLCanvasElement,
corner?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left',
): { dispose(): void };
}
"Powered by 360sona" on a canvas you draw avatars into.
| Parameter | Type | Meaning |
|---|---|---|
canvas |
HTMLCanvasElement |
The canvas you draw avatars into. |
corner (optional) |
'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' |
Where the badge sits. Default "bottom-right". |
Returns { dispose(): void }.
connection.release()¶
interface SonaConnection {
release(): void;
}
Close the connection's bridge.
SonaHeadless properties¶
| Field | Type | Meaning |
|---|---|---|
renderer |
'webgpu' | 'webgl2' |
The backend it draws with. Read only. |
headless.render()¶
interface SonaHeadless {
render(
manifestBase64: string,
opts?: HeadlessOptions,
): Promise<HeadlessPicture>;
}
One picture as RGBA pixels.
| Parameter | Type | Meaning |
|---|---|---|
manifestBase64 |
string |
The avatar's 1,000-byte manifest, base64. |
opts (optional) |
HeadlessOptions |
The picture's size, framing, clip and colour. |
Returns Promise<HeadlessPicture>.
headless.picture()¶
interface SonaHeadless {
picture(manifestBase64: string, opts?: HeadlessOptions): Promise<Blob>;
}
One picture as an image file.
| Parameter | Type | Meaning |
|---|---|---|
manifestBase64 |
string |
The avatar's 1,000-byte manifest, base64. |
opts (optional) |
HeadlessOptions |
The picture's size, framing, clip, colour and format. |
Returns Promise<Blob>.
headless.batch()¶
interface SonaHeadless {
batch(
manifests: string[],
opts: HeadlessOptions,
fn: (
index: number,
result: HeadlessPicture | { error: SonaError },
) => void,
flight?: { inFlight?: number },
): Promise<void>;
}
A picture of each avatar, built a few at a time.
| Parameter | Type | Meaning |
|---|---|---|
manifests |
string[] |
The avatars, each base64. |
opts |
HeadlessOptions |
One set of options for every picture. |
fn |
(index: number, result: HeadlessPicture | { error: SonaError }) => void |
Called once a manifest, in order, with its index and its picture or its error. |
flight.inFlight (optional) |
number |
Avatars built ahead while one is drawn. Default 4. |
Returns Promise<void>.
headless.sequence()¶
interface SonaHeadless {
sequence(
manifestBase64: string,
opts: HeadlessOptions,
seq: { frames?: number; fps?: number; sweep?: number },
fn: (index: number, frame: HeadlessPicture) => void,
): Promise<number>;
}
Frame i holds the clip at time + i / fps and turns the avatar by turn + sweep * i / frames. Resolves with the frame count.
| Parameter | Type | Meaning |
|---|---|---|
manifestBase64 |
string |
The avatar's 1,000-byte manifest, base64. |
opts |
HeadlessOptions |
The pictures' size, framing, clip and colour; time is where the first frame holds the clip. |
seq.frames (optional) |
number |
How many frames. Default: the clip's length at fps, or 36 for a sweep with no clip, else 1. |
seq.fps (optional) |
number |
Frames a second of clip time. Default 30. |
seq.sweep (optional) |
number |
Degrees the avatar turns over the frames. Default 0. |
fn |
(index: number, frame: HeadlessPicture) => void |
Called with each frame's index and pixels. |
Returns Promise<number>.
headless.close()¶
interface SonaHeadless {
close(): void;
}
Frees its scene and its GPU context.
HeadlessOptions¶
The options of one headless picture, as sona_render_options.
| Field | Type | Meaning |
|---|---|---|
width (optional) |
number |
Pixels wide, 1 to 8192. Default 256. |
height (optional) |
number |
Pixels high, 1 to 8192. Default 256. |
preset (optional) |
'full' | 'upper' | 'bust' | 'face' |
The framing. Default "full". |
yaw (optional) |
number |
Degrees the camera moves round the preset's target. Default 0. |
pitch (optional) |
number |
Degrees the camera moves up round the preset's target. Default 0. |
zoom (optional) |
number |
The preset's distance is divided by this: 2 is twice as close. 0.05 or more. Default 1. |
turn (optional) |
number |
Degrees the avatar turns about its feet. |
clip (optional) |
ClipKey | null |
A clip key, held at time seconds. Default: standing still. |
time (optional) |
number |
Seconds into the clip to hold. Default 0. |
clear (optional) |
[number, number, number, number] |
Premultiplied RGBA 0 to 1. Default transparent. |
credit (optional) |
boolean |
"Powered by 360sona" in the corner. Default true; the licence still asks for the line somewhere when it is off. |
type (optional) |
'image/png' | 'image/webp' | 'image/jpeg' |
The file's format, picture() only. Default "image/png". |
quality (optional) |
number |
0 to 1, for WebP and JPEG, picture() only. Default: the browser's own. |
waitSeconds (optional) |
number |
How long to wait for the avatar. Default 120. |
HeadlessPicture¶
| Field | Type | Meaning |
|---|---|---|
width |
number |
Pixels wide. |
height |
number |
Pixels high. |
rgba |
Uint8Array |
The pixels, four bytes each (red, green, blue, alpha, not premultiplied), rows from the top. |
This page as Markdown · All the docs as one file (llms-full.txt)