# 360sona

![Sixteen avatars in costumes in three rows in front of a big green 360sona logo on a plinth, like a class photo: most clap, two wave](img/home-class.webp){ .sona-hero }

360sona is a free toolkit for using Xbox 360 avatars in your own games, apps and web pages. The SDK loads an avatar
from its manifest (the 1,000 bytes an Xbox 360 stores for one), dresses it from the stock items, and draws it
animated in your own frame. The downloads are for the web, Windows, Linux, macOS, iOS, Android and Xbox 360 homebrew, used
from JavaScript, C, C++, C#, Rust and Python, and as packages for Unity, Godot, Unreal and Blender
([platforms](platforms.md)). It is free: the one condition is the small
"Powered by 360sona" badge, which the SDK draws for you.

## Overview

| To | Use | Needs |
|---|---|---|
| Show one live avatar on a web page | [The live avatar](web-api.md#runtime), one script tag | Nothing |
| Draw many avatars in your own canvas | [The web Renderer SDK](tutorials/web.md) | An app id |
| Use avatars in Unity, Godot or Unreal | [Unity](tutorials/unity.md), [Godot](tutorials/godot.md), [Unreal](tutorials/unreal.md) | The SDK download |
| Draw avatars from C, C++, C#, Rust or Python | [C](tutorials/c.md), [C++](tutorials/cpp.md), [C#](tutorials/csharp.md), [Rust](tutorials/rust.md), [Python](tutorials/python.md) | The SDK download |
| Start from a scene that already runs | [The plaza starter](tutorials/starter-plaza.md), on eleven platforms | The SDK download |
| See the whole SDK in one app | [The plaza demo](tutorials/plaza-demo.md) | The SDK download |
| Let players make and dress their avatar in your game | [The player editor](guides/editor.md), [the quick creator](guides/quick-creator.md) | The SDK download |
| Draw a crowd: 1,000 or 10,000 different avatars | [Crowds](guides/crowd.md) | The SDK download |
| Draw avatars in your own renderer or engine | [Your own renderer](guides/own-renderer.md): posed meshes, materials, skinning | The SDK download |
| Make pictures on a server: gamerpics, cards, video | [Headless rendering](guides/headless.md), [the bot template](tutorials/template-bot.md) | The SDK download |
| Get an avatar as a model: GLB, VRM, FBX, a 3D print | [VRM and glTF](guides/vrm.md), [FBX](guides/export-fbx.md), [3D print](guides/print3d.md) | The SDK download |
| Show the avatar on someone's Xbox account | [Gamertag lookup](web-api.md#lookup) | An app id |
| Let players bring their saved 360sona avatar | [Sign in with 360sona](web-api.md#sign-in) | An app id |
| Let an AI agent build and render avatars | [MCP](guides/mcp.md), [with no person present](guides/unattended.md) | Nothing |

App ids are free, and read-only ones are approved at once: [ask for one](web-api.md#access). The SDK download is made
for your app id and holds your `sona-licence.json`: [installing](install.md).

## Quick start

One avatar from its manifest, waving, in each language and engine. In a game the last step is `sona_update` and
`sona_draw` once a frame, into your own target: [getting started](getting-started.md) has the loop.

### C

Open a context with your licence, add an avatar from its manifest, draw it. This is the middle of
[hello.c](tutorials/code/hello.c), which saves one picture and needs no window ([the C tutorial](tutorials/c.md)):

```c
/* A context: the licence and where the avatar files come from. */
sona_config_defaults(&cfg);
cfg.app_id = getenv("SONA_APP_ID");   /* NULL: the app id your download is made for */
cfg.licence = licence;
cfg.licence_len = licence_len;
cfg.sources[0].kind = dir ? SONA_SOURCE_DIR : SONA_SOURCE_GATE;   /* the gate: item files from 360sona */
cfg.sources[0].location = dir;
cfg.source_count = 1;
r = sona_open(&cfg, &ctx);
free(licence);
if (r != SONA_OK) return fail("sona_open", NULL, r);

/* An avatar from its manifest. It loads over the next updates. */
r = sona_avatar_add_base64(ctx, argv[2], NULL, &avatar);
if (r != SONA_OK) return fail("sona_avatar_add_base64", ctx, r);

/* No window: one picture, 1.5 s into the wave. */
r = sona_headless_open(ctx, NULL, &h);
if (r != SONA_OK) return fail("sona_headless_open", ctx, r);
sona_render_defaults(&ro);
ro.width = 480;
ro.height = 600;
ro.clip = "GenericWave";
ro.time = 1.5f;
rgba = malloc((size_t)ro.width * ro.height * 4);
r = rgba ? sona_headless_render(h, avatar, &ro, rgba) : SONA_E_MEMORY;
if (r != SONA_OK) return fail("sona_headless_render", ctx, r);
```

```bash
cc -std=c99 -I sdk/include hello.c -L sdk/lib -lsona \
  -Wl,-rpath,sdk/lib -o hello
```

```bash
./hello sona-licence.json "$(cat manifest.txt)"
```

`manifest.txt` is an avatar as base64, from 360sona.com's share box; the item files stream from 360sona. The
program writes `avatar.png`:

![hello.c's run, and the avatar.png it writes: an avatar mid-wave](img/one-quickstart.webp)

### C++

The same through `sona.hpp`, the header-only wrapper. This is the middle of [hello.cpp](tutorials/code/hello.cpp)
([the C++ tutorial](tutorials/cpp.md)):

```cpp
sona::Config cfg;
if (!cfg.licence_file(argv[1])) { std::fprintf(stderr, "cannot read %s\n", argv[1]); return 1; }
if (const char *app = std::getenv("SONA_APP_ID")) cfg.app_id(app);   // unset: the app id your download is made for
if (dir) cfg.dir(dir); else cfg.gate();   // the gate: item files from 360sona
sona::Context ctx(cfg);
sona::Avatar avatar = ctx.add_base64(argv[2]);

// The headless renderer is plain C: sona.hpp hands over the raw handles.
sona_headless *h = 0;
if (sona_headless_open(ctx.raw(), 0, &h) != SONA_OK) { std::fprintf(stderr, "no device to draw with\n"); return 1; }
sona_render_options ro;
sona_render_defaults(&ro);
ro.width = 480;
ro.height = 600;
ro.clip = "GenericWave";
ro.time = 1.5f;
std::vector<uint8_t> rgba(ro.width * ro.height * 4);
sona_result r = sona_headless_render(h, avatar.raw(), &ro, rgba.data());
```

### C#

The C# binding runs on .NET 8 and inside Unity. This is the middle of
[Hello.cs](tutorials/code/csharp/Hello.cs) ([the C# tutorial](tutorials/csharp.md)):

```csharp
var options = new SonaOptions
{
    Licence = File.ReadAllBytes(args[0]),
    AppId = Environment.GetEnvironmentVariable("SONA_APP_ID"),
};
options.Sources.Add(dir != null ? SonaSourceSpec.Dir(dir) : SonaSourceSpec.Gate());   // the gate: item files from 360sona
using var ctx = new SonaContext(options);

var avatar = ctx.AddBase64(args[1]);
while (avatar.State != SonaAvatarState.Ready && avatar.State != SonaAvatarState.Failed) ctx.Update(1.0 / 60);
if (avatar.State != SonaAvatarState.Ready) { Console.Error.WriteLine("the avatar did not load"); return 1; }

avatar.Play("GenericWave");
for (var i = 0; i < 60; i++) ctx.Update(1.0 / 60);

var head = new float[16];
avatar.TryGetJointWorld(SonaJoints.Find("Head"), head);
Console.WriteLine($"head at {head[12]:F3} {head[13]:F3} {head[14]:F3}");

using var headless = new SonaHeadless(ctx);
var rgba = headless.Render(avatar, new SonaRenderOptions { Width = 480, Height = 600, Clip = "GenericWave", Time = 1.5f });
File.WriteAllBytes("avatar.png", ctx.EncodePng(rgba, 480, 600));
```

### Rust

The `sona` crate wraps the C library safely. This is the middle of [main.rs](tutorials/code/rust/src/main.rs)
([the Rust tutorial](tutorials/rust.md)):

```rust
let mut cfg = sona::Config::new().licence(licence);
if let Ok(app) = std::env::var("SONA_APP_ID") {
    cfg = cfg.app_id(&app); // unset: the app id your download is made for
}
cfg = match &dir {
    Some(d) => cfg.dir(d),
    None => cfg.gate(None),
};
let ctx = sona::Context::open(cfg).map_err(|e| e.to_string())?;

// An avatar from its manifest. It loads over the next updates.
let avatar = ctx.add_base64(&args[1], &sona::AddOptions::default()).map_err(|e| e.to_string())?;

// No window: one picture, 1.5 s into the wave.
let h = sona::Headless::open(&ctx, &sona::HeadlessOptions::default()).map_err(|e| e.to_string())?;
let mut ro = sona::RenderOptions::default();
ro.width = 480;
ro.height = 600;
ro.clip = Some("GenericWave".into());
ro.time = 1.5;
let rgba = h.render(&avatar, &ro).map_err(|e| e.to_string())?;
```

### Python

The `sona` package reads posed avatars as plain data. This is the middle of [hello.py](tutorials/code/hello.py)
([the Python tutorial](tutorials/python.md)):

```python
with sona.Context(app_id=os.environ.get("SONA_APP_ID"), licence=licence,
                  sources=[source]) as ctx:
    avatar = ctx.add_base64(manifest)
    while not avatar.settled:
        ctx.update(1 / 60)
    if not avatar.ready:
        sys.exit("the avatar did not load")

    avatar.play("GenericWave")
    for _ in range(60):
        ctx.update(1 / 60)

    pose = avatar.pose()
    head = avatar.joint_world("Head")
    print(len(pose.meshes), "meshes;", "head at", tuple(round(v, 3) for v in head[12:15]))

    with sona.Headless(ctx) as h:
        rgba = h.render(avatar, width=480, height=600, clip="GenericWave", time=1.5)
    with open("avatar.png", "wb") as f:
        f.write(ctx.png_encode(rgba, 480, 600))
```

### JavaScript

With the Renderer SDK in your own canvas. `manifestBase64` is the avatar as base64, from 360sona.com's share box
([the web tutorial](tutorials/web.md)):

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

const canvas = document.querySelector('canvas');
const sona = await SonaRenderer.create({ canvas });
const avatar = sona.add(manifestBase64, { clip: 'GenericWave' });
await avatar.ready;
```

It is the avatar drawn at the top of this page. With no SDK download and no key, the live avatar does the same in an iframe: `rt.avatar(manifestBase64)`, then
`rt.play('GenericWave')` ([the live avatar](web-api.md#runtime)).

### Unity

Add the 360sona Renderer package and put a `SonaContext` in the scene with your licence. This script, on any
GameObject, adds the avatar; `manifest` is a text asset holding it as base64 (the package's Components sample,
[the Unity tutorial](tutorials/unity.md)):

```csharp
using UnityEngine;

namespace Sona.Unity.Samples
{
    public sealed class HelloAvatar : MonoBehaviour
    {
        public TextAsset manifest;

        void Start()
        {
            var avatar = new GameObject("Avatar").AddComponent<SonaAvatar>();
            avatar.manifestAsset = manifest;
            avatar.clip = "GenericWave";
        }
    }
}
```

### Godot

Copy the addon into the project and put `sona-licence.json` at `res://`. This is the root script of the demo's hello
scene, a `Node3D` with a `Camera3D` child; `SonaServer` opens the context when the avatar enters the tree
([the Godot tutorial](tutorials/godot.md)):

```gdscript
func _ready() -> void:
	var avatar = ClassDB.instantiate("SonaAvatar3D")
	var text = FileAccess.get_file_as_string("res://hello/manifest.txt")
	avatar.manifest = text.strip_edges()
	avatar.clip = "GenericWave"
	add_child(avatar)
	avatar.avatar_ready.connect(func(): avatar.frame_camera($Camera3D))
```

### Unreal

Enable the `Sona360` plugin. This actor holds a `USonaAvatarComponent` and gives it the manifest from
`Content/manifest.txt`; place it in a level (the SonaStarter project, [the Unreal tutorial](tutorials/unreal.md)):

```cpp
AHelloAvatar::AHelloAvatar()
{
	Avatar = CreateDefaultSubobject<USonaAvatarComponent>(TEXT("Avatar"));
	RootComponent = Avatar;
	Avatar->Clip = TEXT("GenericWave");
}

void AHelloAvatar::BeginPlay()
{
	Super::BeginPlay();
	FString Manifest;
	if (FFileHelper::LoadFileToString(Manifest, *FPaths::Combine(FPaths::ProjectContentDir(), TEXT("manifest.txt"))))
		Avatar->SetManifest(Manifest.TrimStartAndEnd());
}
```

`AHelloAvatar` is declared in `HelloAvatar.h` beside it, with `Avatar` as a `UPROPERTY`. In a Blueprint, the node
Load 360sona Avatar does the same.

## Start

| Page | What it covers |
|---|---|
| [Installing](install.md) | The download for each platform, what is in it, where the library goes, the packages |
| [Getting started](getting-started.md) | A context, an avatar and the frame loop in a window of your own |
| [Playground](playground.md) | Pick a costume, a clip, a prop, a framing and the light, see it live, copy the code in JavaScript and C |
| [Concepts](concepts.md) | The context, avatars, renderers, the frame, units, threading, memory |
| [Manifests](concepts/manifests.md) | The 1,000 bytes of one avatar: what is in them, where they come from, editing them |
| [Items and slots](concepts/items.md) | Item ids, the slots they fill, bodies, props, custom items |
| [Clips and animation](concepts/clips.md) | Playing, crossfading and queueing clips, layers, events, root motion |
| [Item files, the gate and the licence](concepts/sources.md) | Where the item files come from, the gate, the licence file |
| [The credit](concepts/credit.md) | Where "Powered by 360sona" shows, and how to move it |
| [Cookbook](cookbook.md) | Short recipes for game moments |
| [Examples](examples.md) | Every example program with its picture and code |
| [Platforms](platforms.md) | Each platform's backends, library file, build and limits |
| [Performance](performance.md) | Frame times, load times and memory as the bench measures them, and what sets them |
| [Limits and quotas](limits.md) | Every fixed limit of the library and every quota of the servers |
| [Licence and credit](licence.md) | What is free, the badge, what you may ship |
| [Troubleshooting](troubleshooting.md) | Symptoms, causes, and every error code |
| [FAQ](faq.md) | Short answers to common questions |
| [Glossary](glossary.md) | The words these docs use |
| [Versions and migration](versions.md) | What a release may change, checking the version, moving from 1.0 to 1.1 |
| [Changelog](changelog.md) | What changed in each version |

## Tutorials

A tutorial is numbered steps that end with something running.

| You use | Tutorial | It builds |
|---|---|---|
| A web page | [Web](tutorials/web.md) | One avatar with a script tag, then several in your canvas |
| Unity | [Unity](tutorials/unity.md) | The package, a `SonaAvatar`, the Plaza sample |
| Godot 4.7 or later | [Godot](tutorials/godot.md) | The addon, a `SonaAvatar3D`, the plaza scene |
| Unreal Engine | [Unreal](tutorials/unreal.md) | The `Sona360` plugin and the `SonaPlaza` project |
| C | [C](tutorials/c.md) | One avatar to a PNG, no window |
| C++ | [C++](tutorials/cpp.md) | The same through `sona.hpp` |
| C# | [C#](tutorials/csharp.md) | One avatar, where its head is, and a PNG, in a console program |
| Rust | [Rust](tutorials/rust.md) | One avatar to a PNG through the `sona` crate |
| Python | [Python](tutorials/python.md) | One avatar's pose as plain data, and a PNG |
| Blender | [Blender](tutorials/blender.md) | An avatar imported with its clips, and exported back |

Starters and templates, each a program to copy:

| Template | Tutorial | What it is |
|---|---|---|
| Plaza starter | [The plaza starter](tutorials/starter-plaza.md) | Twelve avatars walking about a plaza, the same bare scene on eleven platforms |
| Plaza demo | [The plaza demo](tutorials/plaza-demo.md) | A park of avatars: pick, edit, create and save them, native and web |
| C++ starter | [The C++ starter](tutorials/template-cpp-starter.md) | The project `sona project new` makes |
| Lobby | [The lobby](tutorials/template-lobby.md) | Sign in with 360sona or a gamertag, players synced over UDP |
| Bot and server | [The bot](tutorials/template-bot.md) | Gamerpics and outfit cards over HTTP, no window |
| VTuber kit | [The VTuber kit](tutorials/template-vtuber.md) | Webcam and microphone drive the face, transparent window |
| VR | [The VR template](tutorials/template-vr.md) | OpenXR, a whole body from a headset and two controllers |
| Web crowd | [The web crowd](tutorials/template-web-crowd.md) | 1,000 different avatars in one canvas |

All of them on one page: [templates and starters](guides/templates.md).

## Guides

One page per feature: what it is, the smallest example, then every call.

| Area | Guides |
|---|---|
| Animation | [Clips](guides/clips.md), [layers](guides/layers.md), [IK](guides/ik.md), [imported clips](guides/import.md), [text to emote](guides/emote.md), [lip sync](guides/lipsync.md), [sway](guides/sway.md), [interactions](guides/interactions.md), [physics](guides/physics.md) |
| Looks | [Art styles](guides/styles.md), [lighting](guides/lighting.md), [quality](guides/quality.md), [tiers](guides/tiers.md), [crowds](guides/crowd.md), [placeholders](guides/placeholder.md), [parity with the web](guides/parity.md), [device loss](guides/device-loss.md), [Vulkan features](guides/vulkan-features.md) |
| Avatars and items | [The offline catalogue](guides/catalogue.md), [item names in other languages](guides/catalogue-languages.md), [item previews](guides/item-preview.md), [making avatars in code](guides/makers.md), [content filters](guides/filters.md), [custom items](guides/custom-items.md), [props](guides/props.md), [other players' avatars](guides/players.md), [network sync and replays](guides/netstate.md) |
| Outputs | [Your own renderer](guides/own-renderer.md), [headless rendering](guides/headless.md), [2D outputs](guides/sprites2d.md), [VRM and glTF](guides/vrm.md), [FBX](guides/export-fbx.md), [skeleton maps](guides/skeleton-maps.md), [3D print](guides/print3d.md), [overlays](guides/overlay.md), [picking](guides/picking.md) |
| Players | [The player editor](guides/editor.md), [the quick creator](guides/quick-creator.md), [face tracking](guides/face-tracking.md), [body tracking](guides/body-tracking.md), [VR and XR bodies](guides/xr.md), [the NPC kit](guides/npc.md) |
| Platforms and tools | [Android](guides/android.md), [Unreal](guides/unreal.md), [Blender](guides/blender.md), [the CLI](guides/cli.md), [the CLI for every Studio pane](guides/cli-studio.md), [the Studio](guides/studio.md), [the Studio's agents and apps](guides/studio-agents-apps.md), [MCP](guides/mcp.md), [installing the tools](guides/installer.md), [360sona SDK Setup](guides/setup.md), [agents with no person present](guides/unattended.md), [Xbox 360 homebrew](guides/xbox360.md) |
| Shipping | [Packages](guides/packages.md), [the stable ABI and deprecations](guides/abi.md), [signed releases and revocation](guides/release.md), [hardening and speed gates](guides/hardening.md) |
| Web | [three.js, Babylon.js and React](guides/web-wrappers.md), [the editor element](guides/web-editor.md), [WebGPU](guides/web-webgpu.md), [headless pictures](guides/web-headless.md) |

## Reference

| Page | What is in it |
|---|---|
| [The C reference](reference.md) | Every function of `sona.h` and the optional modules: signature, rules, errors |
| [Struct fields](reference/fields.md) | Every field of every public struct, with its unit and its default |
| [Every package, name by name](reference/bindings.md) | Each public name of the C++, C#, Python, Rust and WebAssembly packages, with the C function it calls |
| [Engine reference](reference/engines.md) | Every component, node and class of the Unity package, the Godot extension and the Unreal plugin: fields, methods, signals and Blueprint functions |
| [CLI reference](reference/cli.md) | Every `sona` command: its synopsis, what it does, its options and the exit codes |
| [The web API](web-api.md) | The live avatar, the web Renderer SDK, the HTTP API, sign-in, MCP |
| [The web SDK reference](reference/web.md) | Every class and method of `sona-renderer.js` and its packages, with live examples |
| [Error codes](troubleshooting.md#error-codes) | Every `SONA_E_*`, its cause and its fix |

For tools and agents: [api.json](api.json) (and beside it `api/bindings.json`, `api/fields.json`, `api/units.json`,
`api/defaults.json` and `api/binding-notes.json`), [llms.txt](llms.txt) and [llms-full.txt](llms-full.txt). Every page is
also plain Markdown: put `.md` in place of `.html`.

## Common questions

[What is 360sona?](answers/what-is-360sona.md) · [Xbox 360 avatars in Unity](answers/xbox-360-avatars-in-unity.md) ·
[in Unreal](answers/xbox-360-avatars-in-unreal.md) · [in Godot](answers/xbox-360-avatars-in-godot.md) ·
[on the web](answers/xbox-360-avatars-on-the-web.md) · [in C and C++](answers/xbox-360-avatars-in-cpp.md) ·
[an avatar from a gamertag](answers/avatar-from-a-gamertag.md) · [GLB and VRM export](answers/export-glb-and-vrm.md) ·
[what a game may ship](answers/what-may-i-ship.md)

360sona is not affiliated with or endorsed by Microsoft.
