# 360sona: the full docs > 360sona is a free toolkit for using Xbox 360 avatars in your own games, apps and web pages. 360sona is not affiliated with or endorsed by Microsoft. Xbox and Xbox 360 are Microsoft's trademarks, and the avatar items are the work of Microsoft and its partners. Credit: "Powered by 360sona", linking to https://360sona.com. --- Source: https://360sona.com/devs/docs/index.md # 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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/web-api.md#runtime), one script tag | Nothing | | Draw many avatars in your own canvas | [The web Renderer SDK](https://360sona.com/devs/docs/tutorials/web.md) | An app id | | Use avatars in Unity, Godot or Unreal | [Unity](https://360sona.com/devs/docs/tutorials/unity.md), [Godot](https://360sona.com/devs/docs/tutorials/godot.md), [Unreal](https://360sona.com/devs/docs/tutorials/unreal.md) | The SDK download | | Draw avatars from C, C++, C#, Rust or Python | [C](https://360sona.com/devs/docs/tutorials/c.md), [C++](https://360sona.com/devs/docs/tutorials/cpp.md), [C#](https://360sona.com/devs/docs/tutorials/csharp.md), [Rust](https://360sona.com/devs/docs/tutorials/rust.md), [Python](https://360sona.com/devs/docs/tutorials/python.md) | The SDK download | | Start from a scene that already runs | [The plaza starter](https://360sona.com/devs/docs/tutorials/starter-plaza.md), on eleven platforms | The SDK download | | See the whole SDK in one app | [The plaza demo](https://360sona.com/devs/docs/tutorials/plaza-demo.md) | The SDK download | | Let players make and dress their avatar in your game | [The player editor](https://360sona.com/devs/docs/guides/editor.md), [the quick creator](https://360sona.com/devs/docs/guides/quick-creator.md) | The SDK download | | Draw a crowd: 1,000 or 10,000 different avatars | [Crowds](https://360sona.com/devs/docs/guides/crowd.md) | The SDK download | | Draw avatars in your own renderer or engine | [Your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md): posed meshes, materials, skinning | The SDK download | | Make pictures on a server: gamerpics, cards, video | [Headless rendering](https://360sona.com/devs/docs/guides/headless.md), [the bot template](https://360sona.com/devs/docs/tutorials/template-bot.md) | The SDK download | | Get an avatar as a model: GLB, VRM, FBX, a 3D print | [VRM and glTF](https://360sona.com/devs/docs/guides/vrm.md), [FBX](https://360sona.com/devs/docs/guides/export-fbx.md), [3D print](https://360sona.com/devs/docs/guides/print3d.md) | The SDK download | | Show the avatar on someone's Xbox account | [Gamertag lookup](https://360sona.com/devs/docs/web-api.md#lookup) | An app id | | Let players bring their saved 360sona avatar | [Sign in with 360sona](https://360sona.com/devs/docs/web-api.md#sign-in) | An app id | | Let an AI agent build and render avatars | [MCP](https://360sona.com/devs/docs/guides/mcp.md), [with no person present](https://360sona.com/devs/docs/guides/unattended.md) | Nothing | App ids are free, and read-only ones are approved at once: [ask for one](https://360sona.com/devs/docs/web-api.md#access). The SDK download is made for your app id and holds your `sona-licence.json`: [installing](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/tutorials/code/hello.c), which saves one picture and needs no window ([the C tutorial](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/img/one-quickstart.webp) ### C++ The same through `sona.hpp`, the header-only wrapper. This is the middle of [hello.cpp](https://360sona.com/devs/docs/tutorials/code/hello.cpp) ([the C++ tutorial](https://360sona.com/devs/docs/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 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](https://360sona.com/devs/docs/tutorials/code/csharp/Hello.cs) ([the C# tutorial](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/tutorials/code/rust/src/main.rs) ([the Rust tutorial](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/tutorials/code/hello.py) ([the Python tutorial](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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(); 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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/tutorials/unreal.md)): ```cpp AHelloAvatar::AHelloAvatar() { Avatar = CreateDefaultSubobject(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](https://360sona.com/devs/docs/install.md) | The download for each platform, what is in it, where the library goes, the packages | | [Getting started](https://360sona.com/devs/docs/getting-started.md) | A context, an avatar and the frame loop in a window of your own | | [Playground](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/concepts.md) | The context, avatars, renderers, the frame, units, threading, memory | | [Manifests](https://360sona.com/devs/docs/concepts/manifests.md) | The 1,000 bytes of one avatar: what is in them, where they come from, editing them | | [Items and slots](https://360sona.com/devs/docs/concepts/items.md) | Item ids, the slots they fill, bodies, props, custom items | | [Clips and animation](https://360sona.com/devs/docs/concepts/clips.md) | Playing, crossfading and queueing clips, layers, events, root motion | | [Item files, the gate and the licence](https://360sona.com/devs/docs/concepts/sources.md) | Where the item files come from, the gate, the licence file | | [The credit](https://360sona.com/devs/docs/concepts/credit.md) | Where "Powered by 360sona" shows, and how to move it | | [Cookbook](https://360sona.com/devs/docs/cookbook.md) | Short recipes for game moments | | [Examples](https://360sona.com/devs/docs/examples.md) | Every example program with its picture and code | | [Platforms](https://360sona.com/devs/docs/platforms.md) | Each platform's backends, library file, build and limits | | [Performance](https://360sona.com/devs/docs/performance.md) | Frame times, load times and memory as the bench measures them, and what sets them | | [Limits and quotas](https://360sona.com/devs/docs/limits.md) | Every fixed limit of the library and every quota of the servers | | [Licence and credit](https://360sona.com/devs/docs/licence.md) | What is free, the badge, what you may ship | | [Troubleshooting](https://360sona.com/devs/docs/troubleshooting.md) | Symptoms, causes, and every error code | | [FAQ](https://360sona.com/devs/docs/faq.md) | Short answers to common questions | | [Glossary](https://360sona.com/devs/docs/glossary.md) | The words these docs use | | [Versions and migration](https://360sona.com/devs/docs/versions.md) | What a release may change, checking the version, moving from 1.0 to 1.1 | | [Changelog](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/tutorials/web.md) | One avatar with a script tag, then several in your canvas | | Unity | [Unity](https://360sona.com/devs/docs/tutorials/unity.md) | The package, a `SonaAvatar`, the Plaza sample | | Godot 4.7 or later | [Godot](https://360sona.com/devs/docs/tutorials/godot.md) | The addon, a `SonaAvatar3D`, the plaza scene | | Unreal Engine | [Unreal](https://360sona.com/devs/docs/tutorials/unreal.md) | The `Sona360` plugin and the `SonaPlaza` project | | C | [C](https://360sona.com/devs/docs/tutorials/c.md) | One avatar to a PNG, no window | | C++ | [C++](https://360sona.com/devs/docs/tutorials/cpp.md) | The same through `sona.hpp` | | C# | [C#](https://360sona.com/devs/docs/tutorials/csharp.md) | One avatar, where its head is, and a PNG, in a console program | | Rust | [Rust](https://360sona.com/devs/docs/tutorials/rust.md) | One avatar to a PNG through the `sona` crate | | Python | [Python](https://360sona.com/devs/docs/tutorials/python.md) | One avatar's pose as plain data, and a PNG | | Blender | [Blender](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/tutorials/starter-plaza.md) | Twelve avatars walking about a plaza, the same bare scene on eleven platforms | | Plaza demo | [The plaza demo](https://360sona.com/devs/docs/tutorials/plaza-demo.md) | A park of avatars: pick, edit, create and save them, native and web | | C++ starter | [The C++ starter](https://360sona.com/devs/docs/tutorials/template-cpp-starter.md) | The project `sona project new` makes | | Lobby | [The lobby](https://360sona.com/devs/docs/tutorials/template-lobby.md) | Sign in with 360sona or a gamertag, players synced over UDP | | Bot and server | [The bot](https://360sona.com/devs/docs/tutorials/template-bot.md) | Gamerpics and outfit cards over HTTP, no window | | VTuber kit | [The VTuber kit](https://360sona.com/devs/docs/tutorials/template-vtuber.md) | Webcam and microphone drive the face, transparent window | | VR | [The VR template](https://360sona.com/devs/docs/tutorials/template-vr.md) | OpenXR, a whole body from a headset and two controllers | | Web crowd | [The web crowd](https://360sona.com/devs/docs/tutorials/template-web-crowd.md) | 1,000 different avatars in one canvas | All of them on one page: [templates and starters](https://360sona.com/devs/docs/guides/templates.md). ## Guides One page per feature: what it is, the smallest example, then every call. | Area | Guides | |---|---| | Animation | [Clips](https://360sona.com/devs/docs/guides/clips.md), [layers](https://360sona.com/devs/docs/guides/layers.md), [IK](https://360sona.com/devs/docs/guides/ik.md), [imported clips](https://360sona.com/devs/docs/guides/import.md), [text to emote](https://360sona.com/devs/docs/guides/emote.md), [lip sync](https://360sona.com/devs/docs/guides/lipsync.md), [sway](https://360sona.com/devs/docs/guides/sway.md), [interactions](https://360sona.com/devs/docs/guides/interactions.md), [physics](https://360sona.com/devs/docs/guides/physics.md) | | Looks | [Art styles](https://360sona.com/devs/docs/guides/styles.md), [lighting](https://360sona.com/devs/docs/guides/lighting.md), [quality](https://360sona.com/devs/docs/guides/quality.md), [tiers](https://360sona.com/devs/docs/guides/tiers.md), [crowds](https://360sona.com/devs/docs/guides/crowd.md), [placeholders](https://360sona.com/devs/docs/guides/placeholder.md), [parity with the web](https://360sona.com/devs/docs/guides/parity.md), [device loss](https://360sona.com/devs/docs/guides/device-loss.md), [Vulkan features](https://360sona.com/devs/docs/guides/vulkan-features.md) | | Avatars and items | [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md), [item names in other languages](https://360sona.com/devs/docs/guides/catalogue-languages.md), [item previews](https://360sona.com/devs/docs/guides/item-preview.md), [making avatars in code](https://360sona.com/devs/docs/guides/makers.md), [content filters](https://360sona.com/devs/docs/guides/filters.md), [custom items](https://360sona.com/devs/docs/guides/custom-items.md), [props](https://360sona.com/devs/docs/guides/props.md), [other players' avatars](https://360sona.com/devs/docs/guides/players.md), [network sync and replays](https://360sona.com/devs/docs/guides/netstate.md) | | Outputs | [Your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md), [headless rendering](https://360sona.com/devs/docs/guides/headless.md), [2D outputs](https://360sona.com/devs/docs/guides/sprites2d.md), [VRM and glTF](https://360sona.com/devs/docs/guides/vrm.md), [FBX](https://360sona.com/devs/docs/guides/export-fbx.md), [skeleton maps](https://360sona.com/devs/docs/guides/skeleton-maps.md), [3D print](https://360sona.com/devs/docs/guides/print3d.md), [overlays](https://360sona.com/devs/docs/guides/overlay.md), [picking](https://360sona.com/devs/docs/guides/picking.md) | | Players | [The player editor](https://360sona.com/devs/docs/guides/editor.md), [the quick creator](https://360sona.com/devs/docs/guides/quick-creator.md), [face tracking](https://360sona.com/devs/docs/guides/face-tracking.md), [body tracking](https://360sona.com/devs/docs/guides/body-tracking.md), [VR and XR bodies](https://360sona.com/devs/docs/guides/xr.md), [the NPC kit](https://360sona.com/devs/docs/guides/npc.md) | | Platforms and tools | [Android](https://360sona.com/devs/docs/guides/android.md), [Unreal](https://360sona.com/devs/docs/guides/unreal.md), [Blender](https://360sona.com/devs/docs/guides/blender.md), [the CLI](https://360sona.com/devs/docs/guides/cli.md), [the CLI for every Studio pane](https://360sona.com/devs/docs/guides/cli-studio.md), [the Studio](https://360sona.com/devs/docs/guides/studio.md), [the Studio's agents and apps](https://360sona.com/devs/docs/guides/studio-agents-apps.md), [MCP](https://360sona.com/devs/docs/guides/mcp.md), [installing the tools](https://360sona.com/devs/docs/guides/installer.md), [360sona SDK Setup](https://360sona.com/devs/docs/guides/setup.md), [agents with no person present](https://360sona.com/devs/docs/guides/unattended.md), [Xbox 360 homebrew](https://360sona.com/devs/docs/guides/xbox360.md) | | Shipping | [Packages](https://360sona.com/devs/docs/guides/packages.md), [the stable ABI and deprecations](https://360sona.com/devs/docs/guides/abi.md), [signed releases and revocation](https://360sona.com/devs/docs/guides/release.md), [hardening and speed gates](https://360sona.com/devs/docs/guides/hardening.md) | | Web | [three.js, Babylon.js and React](https://360sona.com/devs/docs/guides/web-wrappers.md), [the editor element](https://360sona.com/devs/docs/guides/web-editor.md), [WebGPU](https://360sona.com/devs/docs/guides/web-webgpu.md), [headless pictures](https://360sona.com/devs/docs/guides/web-headless.md) | ## Reference | Page | What is in it | |---|---| | [The C reference](https://360sona.com/devs/docs/reference.md) | Every function of `sona.h` and the optional modules: signature, rules, errors | | [Struct fields](https://360sona.com/devs/docs/reference/fields.md) | Every field of every public struct, with its unit and its default | | [Every package, name by name](https://360sona.com/devs/docs/reference/bindings.md) | Each public name of the C++, C#, Python, Rust and WebAssembly packages, with the C function it calls | | [Engine reference](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/reference/cli.md) | Every `sona` command: its synopsis, what it does, its options and the exit codes | | [The web API](https://360sona.com/devs/docs/web-api.md) | The live avatar, the web Renderer SDK, the HTTP API, sign-in, MCP | | [The web SDK reference](https://360sona.com/devs/docs/reference/web.md) | Every class and method of `sona-renderer.js` and its packages, with live examples | | [Error codes](https://360sona.com/devs/docs/troubleshooting.md#error-codes) | Every `SONA_E_*`, its cause and its fix | For tools and agents: [api.json](https://360sona.com/devs/docs/api.json) (and beside it `api/bindings.json`, `api/fields.json`, `api/units.json`, `api/defaults.json` and `api/binding-notes.json`), [llms.txt](https://360sona.com/devs/docs/llms.txt) and [llms-full.txt](https://360sona.com/devs/docs/llms-full.txt). Every page is also plain Markdown: put `.md` in place of `.html`. ## Common questions [What is 360sona?](https://360sona.com/devs/docs/answers/what-is-360sona.md) · [Xbox 360 avatars in Unity](https://360sona.com/devs/docs/answers/xbox-360-avatars-in-unity.md) · [in Unreal](https://360sona.com/devs/docs/answers/xbox-360-avatars-in-unreal.md) · [in Godot](https://360sona.com/devs/docs/answers/xbox-360-avatars-in-godot.md) · [on the web](https://360sona.com/devs/docs/answers/xbox-360-avatars-on-the-web.md) · [in C and C++](https://360sona.com/devs/docs/answers/xbox-360-avatars-in-cpp.md) · [an avatar from a gamertag](https://360sona.com/devs/docs/answers/avatar-from-a-gamertag.md) · [GLB and VRM export](https://360sona.com/devs/docs/answers/export-glb-and-vrm.md) · [what a game may ship](https://360sona.com/devs/docs/answers/what-may-i-ship.md) 360sona is not affiliated with or endorsed by Microsoft. --- Source: https://360sona.com/devs/docs/install.md # Installing The SDK comes as one download per platform or engine, made for your app id. Each holds the library, its headers or package, and your `sona-licence.json`. ## The download 1. Ask for an app id, with the request form or `POST /sona/v1/requests` ([requests](https://360sona.com/devs/docs/web-api.md#access)). The request gives a contact address and accepts the Developer Terms. An app that only reads is approved at once, and the answer carries the app id and its key (`sak_...`), shown once. 2. Accept the SDK Licence once for the app, on [your app's page](https://360sona.com/devapp.html#sdk) or with the API. 3. Download with `?platform=`: ```bash curl -X POST https://360sona.com/sona/v1/apps/YOUR_APP_ID/sdk-licence \ -H "Authorization: Bearer sak_..." \ -H "Content-Type: application/json" -d '{ "agree": "I have read and understand the SDK Licence" }' curl -OJ -H "Authorization: Bearer sak_..." \ "https://360sona.com/sona/v1/apps/YOUR_APP_ID/sdk?platform=linux-x64" ``` | `platform` | For | Library | |---|---|---| | `web` (the default) | Pages and web apps | `sona-renderer.js` | | `windows-x64` | C, C++, C#, Rust, Python on Windows | `bin/sona.dll`, `lib/sona.lib` | | `linux-x64` | The same on Linux and Steam Deck | `lib/libsona.so`, `lib/libsona.a` | | `linux-arm64` | C, C++, Rust, Python on 64-bit ARM Linux | `lib/libsona.so` | | `macos` | C, C++, C#, Rust, Python on macOS 11 or later, Apple silicon and Intel | `lib/libsona.dylib` (universal) | | `ios` | C and C++ on iOS 13 or later | `lib/sona.xcframework` | | `android` | C and C++ on Android | `lib/arm64-v8a/libsona.so`, `lib/x86_64/libsona.so` | | `unity` | Unity 2021.3 or later | the package `com.360sona.renderer`, its Plugins for Windows, Linux, macOS, Android and iOS | | `godot` | Godot 4.7 or later | `addons/sona` with `sona.gdextension`, for Windows, Linux (x64, arm64), macOS and Android | | `unreal` | Unreal Engine 5.8 or later | the plugin `Sona360`, for Win64, Linux, Mac, Android and iOS | | `wasm` | The core in WebAssembly, data only | `sona-core.wasm`, `sona-core.mjs` | | `xbox360` | Xbox 360 homebrew: `.xex` titles on xsdk, and libxenon | `lib/libsona.a` (xsdk, with HTTPS), the starter and other titles in `samples/x360`, `lib/xenon/libsona-xenon.a` ([Xbox 360 homebrew](https://360sona.com/devs/docs/guides/xbox360.md)) | Each library is stamped for your app and build, so use your own download and do not pass it on. On macOS and iOS the stamped library is signed again for your app as it downloads; until the SDK is signed with an Apple Developer ID, macOS asks once, in Privacy & Security, before it loads ([platforms](https://360sona.com/devs/docs/platforms.md#macos-and-ios)). ## What is in a native download | Path | What it is | |---|---| | `include/` | `sona.h` and the optional modules' headers | | `lib/`, `bin/` | The library for that platform; on Windows and Linux, the optional modules' libraries beside it | | `bindings/` | The C++ header (`sona.hpp`) and the C#, Rust and Python packages' sources, where the platform has them | | `samples/c/` | Small programs, one per feature | | `data/sona-catalogue.bin` | The [offline catalogue](https://360sona.com/devs/docs/install.md#the-offline-catalogue), only when the download is asked for with `&catalogue=1` | | `bench/` | `sona-bench`, the program every number in these docs comes from | | `sona-licence.json` | Your licence: pass its bytes to `sona_open` | | `README.md`, `LICENSE.txt`, `THIRD-PARTY.txt` | The licence text and the notices to keep with what you ship | ## The offline catalogue Item names, search, random avatars and the player editor read the offline catalogue, one data file. Tick **Offline catalogue** on your app's page when you download, or add `&catalogue=1`: ```bash curl -OJ "https://360sona.com/sona/v1/apps/YOUR_APP_ID/sdk?platform=linux-x64&catalogue=1" -H "Authorization: Bearer sak_..." ``` It is `data/sona-catalogue.bin` in the download. The tutorials' commands name it `sona-catalogue.bin` beside the program, so copy it there or give its path (`--catalogue sdk/data/sona-catalogue.bin`); the `sona` tool finds it by itself with `--sdk sdk`. Use the catalogue from the same download as the library ([the catalogue](https://360sona.com/devs/docs/guides/catalogue.md)). ## Optional modules The player editor, face tracking, body tracking, the NPC kit and XR are libraries of their own beside the core: `sona_editor`, `sona_track`, `sona_body`, `sona_npc` and `sona_xr`, each with its header in `include/` (`sona_editor.h` and so on). The Linux x64 download has them in `lib/` (`libsona_editor.so` and so on), the Windows download in `bin/` with their import libraries in `lib/`. Link the ones you use together with the core: ```text cc -std=c99 -I sdk/include my_vtuber.c -L sdk/lib -lsona_track -lsona \ -Wl,-rpath,sdk/lib -o my_vtuber ``` The other platforms' downloads hold the core alone, except that the Godot and Unreal downloads carry the editor module their plugin uses. ## Starters and templates The plaza starter for every platform but C++ (the `sona` tool makes that project), the plaza demo, the lobby, VTuber, bot and VR templates and the NPC kit's program are one archive of source files, [360sona-templates.tar.gz](https://360sona.com/devs/docs/360sona-templates.tar.gz). It is the same for every app and platform. Where its link reads "ask for it", it is sent on request: send a request of kind `other` that names your app id ([requests](https://360sona.com/devs/docs/web-api.md#access)). Unpack it into the folder of your download: ```sh tar xzf 360sona-templates.tar.gz -C sdk ``` `starters/` and `templates/` then sit beside `include/`, `lib/` and `bindings/`, which is where their build commands expect them. [The plaza starter](https://360sona.com/devs/docs/tutorials/starter-plaza.md) is the one to begin with; [templates](https://360sona.com/devs/docs/guides/templates.md) lists the rest. ### The sample avatars The archive holds three lists of avatars, each a JSON array of `{ "title", "b64" }` (a name and a base64 manifest): | File | Avatars | Read by | |---|---|---| | `devs-cast.json` | 60 sample avatars | The guides' commands: `--cast devs-cast.json --member ` picks one | | `starters/showcase-cast.json` | 55 costumes | The C, C#, Rust and Python starters, which walk twelve of them by index (`--cast`) | | `starters/web/plaza-cast.json` | The same twelve costumes alone | The web, Android and iOS starters, and the Unreal starter as `Content/Sona360/plaza-cast.json` | Any list in that form works: put your own avatars in one to see them instead. `devs-cast.json` is also a file of these docs, [devs-cast.json](https://360sona.com/devs/docs/devs-cast.json), for a folder without the archive: ```sh curl -O https://360sona.com/devs/docs/devs-cast.json ``` ### Other files the templates use The templates link nothing that is not in the download or the system, except these, which you fetch once: | File | Used by | Where it comes from | |---|---|---| | `stb_truetype.h` | The plaza demo, the bot template | One header of the stb libraries (public domain): [github.com/nothings/stb](https://github.com/nothings/stb) | | `DejaVuSans.ttf`, `DejaVuSansMono.ttf` | The plaza demo (Linux), the bot template | The DejaVu fonts (free licence): `fonts-dejavu-core` on Debian and Ubuntu, `ttf-dejavu` on Arch, or [dejavu-fonts.github.io](https://dejavu-fonts.github.io) | | SDL3 | The plaza demo; the windows of the lobby and the VTuber kit | [libsdl.org](https://libsdl.org), or the system's package (`libsdl3-dev`, `sdl3`) | | `face_landmarker.task` | The VTuber kit, face tracking | MediaPipe's face landmarker model, below | | The OpenXR loader, Vulkan | The VR template | The [OpenXR SDK](https://github.com/KhronosGroup/OpenXR-SDK) and the [Vulkan SDK](https://vulkan.lunarg.com) | ```sh curl -LO https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task pip install mediapipe numpy ``` ## Your language The code goes in your project; the library is always the one from your download. [Packages](https://360sona.com/devs/docs/guides/packages.md) has every channel. ### C Add `include/` to the include path and link the library. Keep the shared library where the loader finds it. ```bash cc -std=c99 -I sdk/include hello.c -L sdk/lib -lsona \ -Wl,-rpath,sdk/lib -o hello ``` On Windows, in a Developer PowerShell for Visual Studio, link the import library and keep `sona.dll` next to the program: ```powershell cl /I sdk\include hello.c sdk\lib\sona.lib copy sdk\bin\sona.dll . ``` The [C tutorial](https://360sona.com/devs/docs/tutorials/c.md) builds this program. ### C++ `bindings/cpp/sona.hpp` is a header-only wrapper over the C library: add its folder to the include path too. ```bash c++ -std=c++11 -I sdk/include -I sdk/bindings/cpp hello.cpp \ -L sdk/lib -lsona -Wl,-rpath,sdk/lib -o hello_cpp ``` The [C++ tutorial](https://360sona.com/devs/docs/tutorials/cpp.md) builds this program. ### C# ```bash dotnet add package Sona360 ``` Keep the library beside the program, or on the loader path. The same package is in the download as source: with no network, or before the package is on NuGet, reference it instead: ```sh dotnet add reference sdk/bindings/csharp/Sona.csproj ``` The [C# tutorial](https://360sona.com/devs/docs/tutorials/csharp.md) builds a program against it. ### Rust ```bash cargo add sona360 ``` In code it is `use sona;`. Set `SONA_LIB_DIR` to the folder that holds the library when you build (`sdk/lib`; on Windows, the folder of `sona.lib`); at run time the loader finds it on its path (`sona.dll` on the `PATH` on Windows). The crate is in the download as source too, for use with no network or before it is on crates.io: ```sh cargo add --path sdk/bindings/rust/sona ``` The [Rust tutorial](https://360sona.com/devs/docs/tutorials/rust.md) builds a program against it. ### Python ```bash pip install sona360 ``` The package loads the library from `SONA_LIB_DIR`, or from beside the package. It is in the download as source too: with no network, or before it is on PyPI, put its folder on the module path instead (on Windows, `$env:PYTHONPATH = "$PWD\sdk\bindings\python"`): ```sh export PYTHONPATH="$PWD/sdk/bindings/python" ``` The [Python tutorial](https://360sona.com/devs/docs/tutorials/python.md) runs a program against it. ### JavaScript The web download is a zip with `sona-renderer.js`, its types and examples. Register the origins your pages run on first ([getting it](https://360sona.com/devs/docs/web-api.md#sdk-download)). For three.js, Babylon.js and React: ```bash npm install @360sona/three ``` The [web tutorial](https://360sona.com/devs/docs/tutorials/web.md) draws a first avatar. ### Unity In the Package Manager, Add package from disk, and pick the package's `package.json` (or add the git URL). Put `sona-licence.json` on a `SonaContext` and add a `SonaAvatar`. The [Unity tutorial](https://360sona.com/devs/docs/tutorials/unity.md) goes on from here. ### Godot Copy `addons/sona` into the project and enable the plugin (Godot 4.7 or later). Put `sona-licence.json` at `res://sona-licence.json` and add a `SonaAvatar3D`. The [Godot tutorial](https://360sona.com/devs/docs/tutorials/godot.md) goes on from here. ### Unreal Copy `Sona360` into the project's `Plugins` folder and build. Put `sona-licence.json` at `Content/Sona360/sona-licence.json`, then add a `USonaAvatarComponent` or the Load 360sona Avatar node. The [Unreal tutorial](https://360sona.com/devs/docs/tutorials/unreal.md) goes on from here. ## Avatar files The library draws avatars from item files it reads at run time. Give `sona_open` one or more sources, asked in order: | Source | `kind` | Use it when | |---|---|---| | The 360sona gate | `SONA_SOURCE_GATE` | You want items streamed over https for your app id, with nothing to install | | A folder | `SONA_SOURCE_DIR` | You keep the item files yourself, in a folder laid out as the gate serves them | | A console's storage | `SONA_SOURCE_CONSOLE` | The program runs on an Xbox 360, or reads a console's Content tree | | Your own reader | `SONA_SOURCE_CUSTOM` | The files are in your own archive or network layer | ## The tools The command line (`sona`), the MCP server (`sona-mcp`) and SDK Studio install apart from the SDK, with one installer per system: [installing the tools](https://360sona.com/devs/docs/guides/installer.md). ## Check it ```c printf("sona %s on %s\n", sona_version(), sona_platform()); ``` ```cpp std::printf("sona %s on %s\n", sona::version(), sona::platform()); ``` ```csharp Console.WriteLine($"sona {SonaLibrary.Version} on {SonaLibrary.Platform}"); ``` ```rust println!("sona {} on {}", version(), platform()); ``` ```python print("sona", sona.version(), "on", sona.platform()) ``` If `sona_open` fails, `sona_last_error` gives the message and the fix; [troubleshooting](https://360sona.com/devs/docs/troubleshooting.md) lists every code. --- Source: https://360sona.com/devs/docs/getting-started.md # Getting started One avatar in a window of your own: a context, an avatar, a renderer on your device, and two calls a frame. Every step is shown in C, C++, C#, Rust, Python, JavaScript, Unity, Godot and Unreal: pick yours in the step's tabs. In an engine the plugin makes the renderer and draws each frame, so its tabs say what is left to you. You need a download ([installing](https://360sona.com/devs/docs/install.md)) and a manifest: the avatar as base64, from 360sona.com's share box or `GET /sona/v1/avatar/random`. ## 1. Open a context The context holds the licence, where avatar files come from, and every avatar. A game has one. ### C ```c sona_config cfg; sona_ctx *ctx = NULL; sona_config_defaults(&cfg); cfg.licence = licence; /* the bytes of sona-licence.json */ cfg.licence_len = licence_len; cfg.sources[0].kind = SONA_SOURCE_GATE; /* stream item files from 360sona */ cfg.source_count = 1; if (sona_open(&cfg, &ctx) != SONA_OK) { sona_error_info e = sona_last_error(NULL); fprintf(stderr, "%s\n%s\n", e.message, e.fix); } ``` `SONA_SOURCE_DIR` with `location` set reads a folder you own in place of the gate. Every call returns a `sona_result`; `sona_last_error` gives the message and a fix. ### C++ ```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); ``` ### C# ```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); ``` ### Rust ```rust let licence = std::fs::read(&args[0]) .map_err(|e| format!("cannot read {}: {}", args[0], e))?; 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())?; ``` ### Python ```python with sona.Context(app_id=os.environ.get("SONA_APP_ID"), licence=licence, sources=[source]) as ctx: avatar = ctx.add_base64(manifest) ``` ### JavaScript The Renderer SDK opens the context and the renderer together, on your canvas: ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); ``` `create()` rejects with a `SonaError` whose `code` says what and `fix` what to do. ### Unity Put a `SonaContext` component on one GameObject of the scene and set its `licence` to your `sona-licence.json`. It opens the context when the scene starts; leave `useGate` on to stream avatar files from 360sona. ### Godot Copy `addons/sona` into the project and put `sona-licence.json` at `res://sona-licence.json`. `SonaServer` opens the context when the first avatar enters the tree. ### Unreal Copy the `Sona360` plugin into the project's `Plugins` folder and put `sona-licence.json` at `Content/Sona360/sona-licence.json`. The plugin's subsystem opens the context when the game starts. ## 2. Add an avatar The avatar loads on worker threads over the next updates and is drawn once it is ready. ### C ```c sona_avatar *avatar = NULL; sona_avatar_add_base64(ctx, b64, NULL, &avatar); /* b64: the manifest; returns at once */ sona_avatar_play(avatar, "GenericWave", NULL); /* remembered until it is ready */ ``` Its state is `SONA_AVATAR_READY` when it can be drawn; `sona_poll_event` tells you when (`SONA_EVENT_READY`), or turn on [placeholders](https://360sona.com/devs/docs/guides/placeholder.md) to show a neutral figure meanwhile. ### C++ ```cpp sona::Avatar avatar = ctx.add_base64(argv[2]); ``` ### C# ```csharp 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); ``` ### Rust ```rust let avatar = ctx.add_base64(&args[1], &sona::AddOptions::default()).map_err(|e| e.to_string())?; ``` ### Python ```python 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") ``` ### JavaScript `add()` returns at once; `ready` resolves when the avatar is drawn: ```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; ``` ### Unity A `SonaAvatar` component holds the manifest. This script, on any GameObject, adds one waving; `manifest` is a text asset holding the avatar as base64 (the package's Components sample): ```csharp void Start() { var avatar = new GameObject("Avatar").AddComponent(); avatar.manifestAsset = manifest; avatar.clip = "GenericWave"; } ``` ### Godot A `SonaAvatar3D` node holds the manifest. The root script of the demo's hello scene: ```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 A `USonaAvatarComponent` holds the manifest. This actor of the SonaStarter project reads it from `Content/manifest.txt`: ```cpp AHelloAvatar::AHelloAvatar() { Avatar = CreateDefaultSubobject(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()); } ``` ## 3. Make a renderer on your device The device stays yours. Hand it over in a `sona_device_desc`; the union member is per backend. | Backend | `backend` | Fill | |---|---|---| | OpenGL 3.3, OpenGL ES 3.0 | `SONA_BACKEND_GL`, `SONA_BACKEND_GLES` | `u.gl.get_proc`, with the context current | | Vulkan 1.1 | `SONA_BACKEND_VULKAN` | `u.vk`: instance, physical device, device, queue, queue family | | Direct3D 11 | `SONA_BACKEND_D3D11` | `u.d3d11`: the device and its context | | Direct3D 12 | `SONA_BACKEND_D3D12` | `u.d3d12`: the device and a command queue | | Metal | `SONA_BACKEND_METAL` | `u.metal`: the `MTLDevice` | No window at all? `sona_headless_open` makes a device of the library's own: [headless rendering](https://360sona.com/devs/docs/guides/headless.md). ### C ```c sona_device_desc dev; sona_renderer *renderer = NULL; memset(&dev, 0, sizeof dev); dev.backend = SONA_BACKEND_GL; dev.u.gl.get_proc = my_gl_get_proc; /* SDL_GL_GetProcAddress, glfwGetProcAddress, ... */ while (sona_renderer_create(ctx, &dev, &renderer) == SONA_PENDING) sona_update(ctx, 0, NULL, NULL); /* the shading data is still arriving */ ``` ### C++ ```cpp sona_device_desc dev; std::memset(&dev, 0, sizeof dev); dev.backend = SONA_BACKEND_GL; dev.u.gl.get_proc = my_gl_get_proc; sona::Renderer renderer; while (sona::Renderer::create(ctx, dev, renderer) == SONA_PENDING) ctx.update(0); // the shading data is still arriving ``` ### C# ```csharp var dev = new Native.sona_device_desc { backend = SonaBackend.GL }; dev.u.gl.get_proc = getProc; // SDL_GL_GetProcAddress, glfwGetProcAddress, ... SonaRenderer renderer; while ((renderer = ctx.CreateRenderer(dev)) == null) ctx.Update(0); // the shading data is still arriving ``` ### Rust ```rust let mut dev: sys::sona_device_desc = unsafe { std::mem::zeroed() }; dev.backend = sys::SONA_BACKEND_GL; dev.u.gl.get_proc = Some(get_proc); // SDL_GL_GetProcAddress, glfwGetProcAddress, ... let mut frame = ctx.frame()?; let mut renderer = loop { if let Some(r) = unsafe { sona::Renderer::new(ctx, &dev)? } { break r; } frame.update(0.0, None)?; // the shading data is still arriving }; ``` ### Python The Python binding draws on no device of yours. It reads the posed avatar each frame for your own pass (step 4), or draws with a device of the library's own: ```python with sona.Headless(ctx) as h: rgba = h.render(avatar, width=1280, height=720, clip="GenericWave") ``` ### JavaScript The canvas given to `create()` is the device: the SDK draws with WebGPU where the browser has it and WebGL2 where it does not ([WebGPU and WebGL2](https://360sona.com/devs/docs/guides/web-webgpu.md)). There is nothing more to make. ### Unity Unity draws the avatars with its own renderer, as it draws any mesh. There is no renderer to make. ### Godot Godot draws `SonaAvatar3D` nodes with its own renderer, as it draws any mesh. There is no renderer to make. ### Unreal Unreal draws `USonaAvatarComponent`s with its own renderer, as it draws any mesh. There is no renderer to make. ## 4. The frame Each frame, update the context (it moves every avatar on) and draw. `view` is your camera: set `eye`, `target` and `fov_deg` yourself, or let the library frame the avatar with `sona_camera_preset`. `target` names where the draw lands: a GL framebuffer, a Vulkan image and command buffer, a D3D render target. The avatars are drawn over a clear of your choice; to lay them over your own scene, draw into a texture and composite it, or read posed meshes with the data API and draw them in your own pass ([your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md)). ### C ```c sona_view view; sona_target target; sona_view_defaults(&view); /* a full-body framing of an avatar at the origin */ view.width = 1280; view.height = 720; memset(&target, 0, sizeof target); target.width = 1280; target.height = 720; target.u.gl.framebuffer = 0; /* the window; per backend, as the device */ while (game_running()) { sona_frame_stats stats; sona_update(ctx, dt, &view, &stats); /* dt: seconds since the last frame */ sona_draw(renderer, &view, &target, NULL); /* into your target, the badge in a corner */ present_frame(); } ``` ### C++ ```cpp sona_view view; sona_view_defaults(&view); view.width = 1280; view.height = 720; sona_target target; std::memset(&target, 0, sizeof target); target.width = 1280; target.height = 720; target.u.gl.framebuffer = 0; // the window while (game_running()) { ctx.update(dt, &view); renderer.draw(view, target); present_frame(); } ``` ### C# ```csharp var view = SonaView.Defaults(); view.Width = 1280; view.Height = 720; var target = new Native.sona_target { width = 1280, height = 720 }; target.u.gl.framebuffer = 0; // the window while (gameRunning()) { ctx.Update(dt, view); renderer.Draw(view, target); presentFrame(); } ``` ### Rust ```rust let mut view = sona::view_defaults(); view.width = 1280; view.height = 720; let mut target: sys::sona_target = unsafe { std::mem::zeroed() }; target.width = 1280; target.height = 720; target.u.gl.framebuffer = 0; // the window while game_running() { frame.update(dt, Some(&view))?; unsafe { renderer.draw(&view, &target, None)? }; present_frame(); } ``` ### Python ```python view = sona.view_defaults() while game_running(): ctx.update(dt, view) pose = avatar.pose() # this frame's posed meshes, for your own pass draw_meshes(pose.meshes) ``` ### JavaScript The SDK draws every frame on its own. To draw from your own loop, create it with `loop: 'manual'` and call `frame()`: ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas, loop: 'manual' }); sona.add(manifestBase64, { clip: 'GenericWave' }); function tick(t) { sona.frame(t).then(() => requestAnimationFrame(tick)); } requestAnimationFrame(tick); ``` ### Unity Unity's frame updates the context and draws the avatars. Move the camera as you would for any scene. ### Godot Godot's frame updates the context and draws the avatars; `frame_camera` frames one in a `Camera3D`. ### Unreal Unreal's frame updates the context and draws the avatars. Move the camera as you would for any level. ## 5. Move it, dress it, change it Place the avatar and change what it plays; the rest of what an avatar does, with its C calls: | To | Call | |---|---| | Place the avatar | `sona_avatar_move(avatar, &placement, 0)` | | Play, blend, queue clips | `sona_avatar_play`, `sona_avatar_crossfade`, `sona_avatar_queue` ([clips](https://360sona.com/devs/docs/guides/clips.md)) | | Change the face | `sona_avatar_expression`; from audio, [lip sync](https://360sona.com/devs/docs/guides/lipsync.md) | | Look at something, plant the feet | [IK](https://360sona.com/devs/docs/guides/ik.md) | | Change what it wears | Edit the manifest with `sona_manifest_wear`, add it as a new avatar, and remove the old one when the new one is READY ([how](https://360sona.com/devs/docs/concepts/manifests.md#changing-one)) | | Let the player do all of it | [The player editor](https://360sona.com/devs/docs/guides/editor.md) | Each binding's name for each call is in the [bindings reference](https://360sona.com/devs/docs/reference/bindings.md). ### C ```c sona_placement to = { { 1.0f, 0.0f, -2.0f }, 90.0f, 1.0f }; sona_avatar_move(avatar, &to, 0.5f); /* over half a second */ sona_avatar_crossfade(avatar, "GenericWave", NULL, 0.2f); ``` ### C++ ```cpp sona_placement to = {{1.0f, 0.0f, -2.0f}, 90.0f, 1.0f}; sona_avatar_move(avatar.raw(), &to, 0.5f); // over half a second; sona.hpp hands over the raw handle avatar.crossfade("GenericWave", 0.2f); ``` ### C# ```csharp avatar.Move(new SonaPlacement(1, 0, -2, 90), 0.5f); // over half a second avatar.Crossfade("GenericWave", 0.2f); ``` ### Rust ```rust let to = sona::Placement { position: [1.0, 0.0, -2.0], turn_deg: 90.0, scale: 1.0 }; avatar.move_to(&to, 0.5); // over half a second avatar.crossfade("GenericWave", &sona::PlayOptions::default(), 0.2)?; ``` ### Python ```python avatar.move(position=(1, 0, -2), turn_deg=90, over_seconds=0.5) avatar.crossfade("GenericWave", 0.2) ``` ### JavaScript ```js avatar.move({ position: [1, 0, -2], turn: 90 }, { over: 0.5 }); avatar.play('GenericWave'); ``` ### Unity Move the avatar's Transform; `Crossfade` changes what it plays. From the Components sample: ```csharp if (moving != Walking && _waving <= 0 && player.State == global::Sona.SonaAvatarState.Ready) { Walking = moving; player.Crossfade(moving ? Walk : "idle", 0.25f); } ``` ### Godot Move the node; `crossfade` changes what it plays. From the components demo: ```gdscript var loaded: bool = player.get_state() == SonaAvatar3D.STATE_READY if moving != walking and loaded and waving <= 0.0: walking = moving player.crossfade(WALK if moving else "idle", 0.25, true, 1.0, 0.0) ``` ### Unreal Move the actor or the component as any other; `Avatar->Crossfade(TEXT("GenericWave"), 0.2f, false)` changes what it plays, and the 360sona Control Rig drives its IK ([the Unreal tutorial](https://360sona.com/devs/docs/tutorials/unreal.md)). ## 6. Shut down ### C ```c sona_avatar_remove(avatar); /* frees what only it used */ sona_renderer_destroy(renderer); /* before your device goes */ sona_close(ctx); ``` ### C++ ```cpp avatar.remove(); renderer.destroy(); // before your device goes ctx.close(); ``` ### C# ```csharp avatar.Remove(); renderer.Dispose(); // before your device goes ctx.Dispose(); ``` ### Rust ```rust avatar.remove(); drop(renderer); // before your device goes; the context closes when it is dropped ``` ### Python ```python avatar.remove() ctx.close() # or leave the "with sona.Context(...)" block ``` ### JavaScript ```js avatar.remove(); sona.destroy(); ``` ### Unity Destroying a `SonaAvatar`'s GameObject removes the avatar; the `SonaContext` closes when it is destroyed. ### Godot Freeing the node (`queue_free()`) removes the avatar. ### Unreal When the actor ends play, its `USonaAvatarComponent` removes the avatar. ## Next - The same in your language: [C++](https://360sona.com/devs/docs/tutorials/cpp.md), [C#](https://360sona.com/devs/docs/tutorials/csharp.md), [Rust](https://360sona.com/devs/docs/tutorials/rust.md), [Python](https://360sona.com/devs/docs/tutorials/python.md), [the web](https://360sona.com/devs/docs/tutorials/web.md); in an engine: [Unity](https://360sona.com/devs/docs/tutorials/unity.md), [Godot](https://360sona.com/devs/docs/tutorials/godot.md), [Unreal](https://360sona.com/devs/docs/tutorials/unreal.md). - A whole program to start from: [the plaza starter](https://360sona.com/devs/docs/tutorials/starter-plaza.md). - How the pieces fit: [concepts](https://360sona.com/devs/docs/concepts.md). Every call: [the C reference](https://360sona.com/devs/docs/reference.md). --- Source: https://360sona.com/devs/docs/playground.md # Playground Pick a costume, a clip, a prop, the camera, the shadow and the background. The avatar changes as you pick, drawn by the web SDK, and the code under it changes to match: C for the native SDK and JavaScript for the web SDK, the same settings in each. The copy button in the corner of the code copies it as it stands. ## The code The code holds the picked costume's manifest (its 1,000 bytes as base64) as `manifestBase64` (`manifest_b64` in C), so it runs as copied; for your player's own, take theirs from 360sona.com's share box or `GET /sona/v1/avatar/random`. In C the lines go where [getting started](https://360sona.com/devs/docs/getting-started.md) puts them, with its names (`ctx`, `avatar`, `renderer`, `view`, `target`): the avatar after the context is open, the framing once it is ready, the draw in the frame loop. ### C ```c /* The "Harry Potter's Robe and Scarf" costume's manifest, as base64 */ static const char manifest_b64[] = "AAAAAL8o9cM9TMzNABAAAAMgAAPByPEJoZyy4AAIAAADMwADwcjxCaGcsuAAIAAA" "AzoAA8HI8QmhnLLgAACAAALwAAPByPEJoZyy4D+AAAAAAAAAAAAAAAAAAAAAACAA" "AroAA8HI8QmhnLLgP4AAAAAAAAAAAAAAAAAAAAAAQAACdwADwcjxCaGcsuA/gAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAA///gvf+nhWr/sFdP/2uOm/+nhWr/i2tc/6eFav/JoKD/yaCg" "AAAAAgABAALByPEJoZyy4AACAAAAAAAAAAAAAAAAAAAAAAABAAIAA8HI8QmhnLLg" "AAEAAAAAAAAAAAAAAAAAAAAAAAQB+AADwcjxCaGcsuAABAAAAAAAAAAAAAAAAAAA" "AAACOEF50rLPEJpLV0IH5wI4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAIB5DUoLNF8eRRE0H7AAgAAAAAAAAAAAAAAAAAAAAAAAQFV2yUsLLkZBNMQfR" "ABAAAAAAAAAAAAAAAAAAAAAAAAhOd4IywK89nTc5B9EACAAAAAAAAAAAAAAAAAAA" "AAAABAH4AAPByPEJoZyy4AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="; sona_add_options add; sona_add_defaults(&add); add.clip = "GenericWave"; sona_avatar_add_base64(ctx, manifest_b64, &add, &avatar); /* once it is READY */ sona_camera_preset(avatar, SONA_PRESET_FULL, &view); sona_draw_options draw = { { 0, 0, 0, 0 }, 0, SONA_CORNER_BOTTOM_RIGHT }; /* each frame, after sona_update */ sona_draw(renderer, &view, &target, &draw); ``` ### JavaScript ```js import { SonaRenderer } from './sona-renderer.js'; // The "Harry Potter's Robe and Scarf" costume's manifest, as base64 const manifestBase64 = 'AAAAAL8o9cM9TMzNABAAAAMgAAPByPEJoZyy4AAIAAADMwADwcjxCaGcsuAAIAAA' + 'AzoAA8HI8QmhnLLgAACAAALwAAPByPEJoZyy4D+AAAAAAAAAAAAAAAAAAAAAACAA' + 'AroAA8HI8QmhnLLgP4AAAAAAAAAAAAAAAAAAAAAAQAACdwADwcjxCaGcsuA/gAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAA///gvf+nhWr/sFdP/2uOm/+nhWr/i2tc/6eFav/JoKD/yaCg' + 'AAAAAgABAALByPEJoZyy4AACAAAAAAAAAAAAAAAAAAAAAAABAAIAA8HI8QmhnLLg' + 'AAEAAAAAAAAAAAAAAAAAAAAAAAQB+AADwcjxCaGcsuAABAAAAAAAAAAAAAAAAAAA' + 'AAACOEF50rLPEJpLV0IH5wI4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAIB5DUoLNF8eRRE0H7AAgAAAAAAAAAAAAAAAAAAAAAAAQFV2yUsLLkZBNMQfR' + 'ABAAAAAAAAAAAAAAAAAAAAAAAAhOd4IywK89nTc5B9EACAAAAAAAAAAAAAAAAAAA' + 'AAAABAH4AAPByPEJoZyy4AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const avatar = sona.add(manifestBase64, { clip: 'GenericWave' }); await avatar.ready; sona.camera.preset('full', avatar); ``` ## What each picker sets In C: | Picker | What it sets | |---|---| | Costume | The manifest given to `sona_avatar_add_base64()` | | Clip | `add.clip`, or `sona_avatar_play()` later | | Prop | `sona_prop_mesh_stock()`, then `sona_avatar_prop_attach()` with `SONA_PROP_PERFORM` | | Camera | `sona_camera_preset()` into your `sona_view`; with a prop, `sona_camera_orbit()` | | Shadow | `SONA_DRAW_SHADOW` in `sona_draw_options.flags` | | Background | `sona_draw_options.clear`, premultiplied RGBA | In JavaScript: | Picker | What it sets | |---|---| | Costume | The manifest given to `sona.add()` | | Clip | `clip` of `add()`, or `avatar.play()` later | | Prop | `avatar.wear(id)`, then `avatar.play('prop')` | | Camera | `sona.camera.preset()`; with a prop, `sona.camera.orbit()` | | Shadow | `shadow: true` when made, or `sona.shadow` | | Background | `background`, premultiplied RGBA | The clips are keys of `sona.clips()` (`sona_stock_clip_count` and the [clip table](https://360sona.com/devs/docs/guides/clips.md#the-clip-table) in C), the props are stock items, and the framings are the console's own. Every call is in the [web SDK reference](https://360sona.com/devs/docs/reference/web.md) and the [C API reference](https://360sona.com/devs/docs/reference.md). --- Source: https://360sona.com/devs/docs/concepts.md # Concepts The model every language and engine follows: the context, avatars, renderers, the frame, where files come from, units, threads, memory and errors. The [C reference](https://360sona.com/devs/docs/reference.md) states each rule exactly. Each idea has a page of its own: - [Manifests](https://360sona.com/devs/docs/concepts/manifests.md): the 1,000 bytes of one avatar. - [Items and slots](https://360sona.com/devs/docs/concepts/items.md): what an avatar wears and holds. - [Clips and animation](https://360sona.com/devs/docs/concepts/clips.md): how an avatar moves. - [Item files, the gate and the licence](https://360sona.com/devs/docs/concepts/sources.md): where the items' files come from. - [The credit](https://360sona.com/devs/docs/concepts/credit.md): "Powered by 360sona". - [Glossary](https://360sona.com/devs/docs/glossary.md): the words, one line each. ## The pieces - **The context** (`sona_ctx`) holds the licence, the sources avatar files come from, and every avatar. A game usually has one. Every call on it and its avatars belongs to the thread that opened it (the owner thread). - **An avatar** (`sona_avatar`) is one person, made from a manifest. It loads in the background and becomes `READY`; until then it is drawn as nothing, or as a neutral figure with [placeholders](https://360sona.com/devs/docs/guides/placeholder.md) on. - **A renderer** (`sona_renderer`) draws the context's avatars on one graphics device: Vulkan, Direct3D 11, Direct3D 12, OpenGL, OpenGL ES, Metal, or Xenos on an Xbox 360. A game can instead read posed meshes and draw them itself: that is how the Unity, Godot and Unreal packages work. ## The manifest An avatar is 1,000 bytes, the same description an Xbox 360 stores: the body, its height and weight, nine colours, the face, and the items worn in each slot. Text APIs carry it as base64. 360sona.com makes one, the gamertag lookup returns the one on an Xbox account, and `sona_make_random` makes one from a seed. ## The frame Each frame: 1. `sona_update(ctx, dt, view, stats)` moves every clock, loads what arrived, and poses the avatars in view. 2. `sona_draw(renderer, view, target, options)` draws them into your target, with the credit badge in a corner. 3. Your own code presents the frame. Clips play on each avatar's clock: `sona_avatar_play`, `_crossfade` and `_queue`, with layers, masks, blend spaces and state machines above them ([layers](https://360sona.com/devs/docs/guides/layers.md)). ## Where avatar files come from Sources are asked in the order you list them, and the first that has a file wins: - the 360sona gate, which streams files over https for your app id (the usual source; your download's licence opens it); - an asset folder: a folder of item files you own, laid out as the gate serves them; - a console's Content tree. What is read is kept in a memory cache. The licence file from your download is checked when the context opens. A new machine has no avatar files. A program, or an agent, then needs a folder the person owns (`--dir` in the tools and samples), or the gate (`--gate` in the tools; the samples use it when given no `--dir`), which needs the network and your app's licence. With no network the tools and samples fail at once and say so rather than wait for files that cannot come. ## Units and axes Metres, Y up, left-handed. Avatars stand about 1.8 m tall and face -Z at turn 0. Matrices are row-major and row-vector (`v' = v * M`), so a matrix's position is its last row. Times are seconds. ## Placement: position, turn and scale Each avatar stands where its placement puts it: `position` in metres, `turn` in degrees about Y (0 faces -Z) and `scale`, a size factor (1 is the avatar's own size, about 1.8 m tall; 2 is twice that). In C it is [`sona_placement`](https://360sona.com/devs/docs/reference/fields.md#sona_placement), given in `sona_add_options.place` when the avatar is added and to `sona_avatar_move` after; the web SDK's `add()` and `move()` take the same three ([Placement](https://360sona.com/devs/docs/reference/web.md#placement)). ## Threads One thread owns a context: the thread that opened it makes every call on it and on its avatars. Reads, decodes and avatar builds run on worker threads (`config.worker_threads`, or your own job system through `config.jobs`), and their results are committed on the owner thread inside `sona_update`, within `config.build_budget_ms` a frame. With no workers the same work runs inside that budget. Two contexts are independent and may live on two threads. ## Memory Every allocation goes through the config's allocator (yours, if you set one) and counts against `config.budget`. `sona_stats` reports what is held in `cpu_mb` and `gpu_mb`. Items no avatar wears any more are kept for reuse and evicted oldest first; an item an avatar needs is never refused for being over a cache's cap, and `budget.total` is the hard limit: past it an allocation fails with `SONA_E_MEMORY`. What the library hands you (`sona_png_encode`'s bytes, an exported file) you free with `sona_free`. ## Results and errors Every call returns a `sona_result`. `SONA_OK` is success, `SONA_PENDING` means still working (keep updating), and the `SONA_E_*` codes are errors. `sona_last_error(ctx)` gives the code, a message and a fix in words; a failed avatar raises `SONA_EVENT_FAILED` with its reason. [Troubleshooting](https://360sona.com/devs/docs/troubleshooting.md) lists every code. ## Credit Every SDK draws a small "Powered by 360sona" badge where avatars appear, and writes the credit into the files it exports. You may turn the badge off if you put the line in your credits, about page or store page. --- Source: https://360sona.com/devs/docs/concepts/manifests.md # Manifests A manifest is one avatar: 1,000 bytes that hold its body, its shape, its nine colours, its face and the item worn in each slot. It is the same description an Xbox 360 keeps for a profile, so a manifest from a console, from the gamertag lookup or from 360sona.com's editor draws the same avatar in every SDK. Text APIs carry it as base64 (1,336 characters). ```c sona_manifest m; sona_guid tee; const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff }; /* 0xAARRGGBB */ if (sona_manifest_parse(manifest, &m) == SONA_OK && sona_guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0", &tee) == SONA_OK && sona_manifest_wear(&m, &tee, colours, 0) == SONA_OK && sona_manifest_write(&m, manifest) == SONA_OK) sona_avatar_add(ctx, manifest, NULL, &avatar); ``` ```cpp sona::Manifest m; sona_guid tee; const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff }; // 0xAARRGGBB sona::Manifest::parse(manifest, m); sona::parse_guid("00000008-006e-0001-c1c8-f109a19cb2e0", tee); m.wear(tee, colours); sona::Avatar dressed = ctx.add(m); ``` ```csharp var m = SonaManifests.Parse(manifest); var tee = SonaManifests.ParseGuid("00000008-006e-0001-c1c8-f109a19cb2e0"); SonaManifests.Wear(ref m, tee, 0xff2a5caa, 0xffffffff, 0xffffffff); var dressed = ctx.Add(SonaManifests.Write(m)); ``` ```rust let mut m = Manifest::parse(manifest)?; m.wear(&guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0")?, [0xff2a5caa, 0xffffffff, 0xffffffff], 0)?; let dressed = ctx.add(&m.to_bytes()?, &AddOptions::default())?; ``` ```python m = sona.Manifest(manifest) m.wear("00000008-006e-0001-c1c8-f109a19cb2e0", colours=(0xff2a5caa, 0xffffffff, 0xffffffff)) dressed = ctx.add(m.to_bytes()) ``` The parse and write are exact: `sona_manifest_write(sona_manifest_parse(x))` gives back `x` byte for byte, so a manifest you edit and save loses nothing you did not change. None of these calls needs a context, a licence or the network. ## Where a manifest comes from | Source | How | Page | |---|---|---| | A player's Xbox profile | the gamertag lookup, `GET /sona/v1/gamertag/{gamertag}` | [An avatar from a gamertag](https://360sona.com/devs/docs/answers/avatar-from-a-gamertag.md) | | A player who signs in | Sign in with 360sona, then `GET /slots` with the `avatar:read` scope | [Saved avatars](https://360sona.com/devs/docs/web-api.md#slots) | | A player, while playing | the player editor | [Player editor](https://360sona.com/devs/docs/guides/editor.md) | | Code | `sona_make_random`, `sona_make_variant`, `sona_make_dress_like` | [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md) | | The command line | `sona avatar random`, `sona avatar new` | [CLI reference](https://360sona.com/devs/docs/reference/cli.md) | | 360sona.com | the editor's share box | [Avatar manifests](https://360sona.com/devs/docs/web-api.md#manifest) | A manifest you keep is a value like a name: store it, send it over the network and compare it byte for byte. It does not change unless the player changes it. ## What is in it `sona_manifest_parse` reads the bytes into a `sona_manifest`: | Field | What it holds | |---|---| | `weight`, `height` | The two body sliders, -1 to 1 (stored as given; beyond 1 saturates when drawn) | | `figure_a` | The body. Its id says the gender: `gender` is 1 for the man's body, 2 for the woman's | | `figure_b` | The head | | `chin`, `nose`, `ears` | The face's shapes, as item ids | | `face[6]` | Mouth, eyes, eyebrows, facial hair, eye shadow and a facial feature, each a part and its placement | | `colours[9]` | Skin, hair, mouth, eyes, eyebrows, eye shadow, facial hair, facial feature, facial feature 2 (0xAARRGGBB) | | `worn[13]` | The item in each of the 13 slots, with its three colours; an empty slot has a zero id | | `required[4]` | The last shoes, trousers, shirt and hair worn, so taking an item off puts them back | | `valid` | Whether the manifest passes the console's own check | The [struct fields](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) page has every field's type; [items and slots](https://360sona.com/devs/docs/concepts/items.md) says what an item id is and which slot it fills. ## Changing one The edit calls follow 360sona.com's editor, so an avatar edited in your game is one the editor and a console take: - `sona_manifest_wear` puts an item on and takes off what shares its slots, then refills the required clothes (a shirt, trousers and shoes) from the last ones worn. `SONA_EDIT_NO_REQUIRED` leaves them empty; `SONA_EDIT_STACK_PROPS` keeps the props already held. - `sona_manifest_unwear` takes off what a slot mask holds; `sona_manifest_undress_all` takes everything off. - `sona_manifest_set_colour`, `sona_manifest_set_shape` and `sona_manifest_set_gender` set a colour, the two sliders and the body. A new body swaps the clothes made for the other one, as the editor does. - `sona_manifest_ready_for_xbox` says whether a console would take it as it is: one prop, the required clothes, no custom item. An avatar's look is fixed when it is added. To change what an avatar on screen wears, add the edited manifest as a new avatar and swap the two when the new one is READY, so the old look stays on screen while the new one loads: ```c sona_manifest m; uint8_t edited[SONA_MANIFEST_BYTES]; sona_avatar *next = NULL; sona_placement here = { { 0.0f, 0.0f, 0.0f }, 0.0f, 1.0f }; /* where the old one stands */ sona_manifest_parse(manifest, &m); if (sona_manifest_wear(&m, &item, NULL, 0) == SONA_OK && sona_manifest_write(&m, edited) == SONA_OK) sona_avatar_add(ctx, edited, NULL, &next); /* each frame, after sona_update */ if (next && sona_avatar_state_of(next) == SONA_AVATAR_READY) { sona_avatar_move(next, &here, 0); sona_avatar_remove(avatar); avatar = next; next = NULL; } ``` `sona_avatar_set_manifest` is for one case only: an avatar added with `sona_avatar_add_waiting` before its manifest was known takes it once ([loading placeholders](https://360sona.com/devs/docs/guides/placeholder.md)). On the web, the avatar changes an item in place ([`avatar.wear()`](https://360sona.com/devs/docs/reference/web.md#avatar-wear)). ## Base64 Base64 is the form for text: JSON, URLs, the web SDK, a save file. `sona_avatar_add_base64` takes it directly (at most 4,096 characters, so whitespace and line breaks are allowed); `sona_base64_decode` gives you the bytes. ```sh sona avatar random --seed 42 --catalogue sona-catalogue.bin -o me.txt sona manifest unpack me.txt -o me.json ``` `sona manifest unpack` writes every field as JSON to read or edit, and `sona manifest pack` turns it back into the same 1,000 bytes. ## Related - [Items and slots](https://360sona.com/devs/docs/concepts/items.md): what goes in `worn[13]`. - [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md): random avatars and outfits. - [Struct fields](https://360sona.com/devs/docs/reference/fields.md#sona_manifest): `sona_manifest` field by field. --- Source: https://360sona.com/devs/docs/concepts/items.md # Items and slots Everything an avatar wears or holds is an item: a shirt, a hat, a pair of glasses, a guitar, a costume. Each item has a 128-bit id and fills one or more of the avatar's slots; putting an item on takes off whatever shares a slot with it. The [offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md) names every item, and the item's files (its meshes, textures and clips) are read at run time from your [sources](https://360sona.com/devs/docs/concepts/sources.md). ```sh sona catalogue search hoodie --body man --limit 5 --catalogue sona-catalogue.bin sona avatar dress seed:atlas "Blue full-zip hoodie" --catalogue sona-catalogue.bin -o me.txt sona avatar show me.txt --catalogue sona-catalogue.bin ``` These run the `sona` tool ([the tool and `seed:` avatars](https://360sona.com/devs/docs/concepts/sources.md)) with the offline catalogue, which comes with a download asked for with `&catalogue=1` ([installing](https://360sona.com/devs/docs/install.md#the-offline-catalogue)). ## Item ids An id is 32 hex digits, written as a GUID: `00000008-006e-0001-c1c8-f109a19cb2e0`. The first eight digits are the slots it fills, as a mask (below): `00000008` is a shirt, `00000208` a long-sleeved top (shirt and wristwear), `00800018` a costume (shirt, trousers and the costume bit). `sona_slot_of` reads the mask from an id and says how the item is worn, and `sona_guid_parse` and `sona_guid_format` turn the text into the 16 bytes a manifest holds and back. The catalogue's lookups take an id in any case, with or without dashes or braces. ## Slots | Slot | Mask | Holds | |---|---|---| | hair | `0x4` | the hair | | shirt | `0x8` | tops | | trousers | `0x10` | trousers, skirts, shorts | | shoes | `0x20` | shoes and boots | | headwear | `0x40` | hats, helmets, hoods | | gloves | `0x80` | gloves | | glasses | `0x100` | glasses and masks | | wristwear | `0x200` | watches and bands | | earrings | `0x400` | earrings | | ring | `0x800` | rings | | prop | `0x1000` | a held or worn object | | costume | `0x800000` | a costume, with the slots it covers | The face's parts are slots too (eyes `0x2000`, eyebrows `0x4000`, mouth `0x8000`, facial hair `0x10000`, facial features `0x20000`, eye shadow `0x40000`, nose `0x80000`, chin `0x100000`, ears `0x200000`), as are the body's shape (`0x1000000`) and its animation (`0x400000`). The command line takes a slot by its name or its mask (`sona avatar undress me.txt hat`, `--slots 0x40`). A manifest holds 13 worn slots. Three are required: an avatar always wears a shirt, trousers and shoes, so taking one off puts back the last one worn (the manifest keeps them), or the body's default. ## Bodies Most clothes are made for one body, the man's or the woman's; props and many hats fit both. The catalogue says which (`sona_item_info.gender`: 1 the man's, 2 the woman's, 3 both), and its `gender` query lists what the editor offers each body. Changing an avatar's body swaps each item for its variant on the new body, as 360sona.com's editor does, and `sona outfit check` reports an item worn on the wrong body. ## What the catalogue says about an item `sona_catalogue_get` fills a `sona_item_info`: its id, name, game and type (`"Shirt/Hoodie"`), the body it is made for, its section (the editor's grouping: `"shirt"`, `"carryable"`), its slot mask, where wearing puts it, its colours and its flags. | Flag | Means | |---|---| | `SONA_ITEM_OFFERED` | The editor lists it | | `SONA_ITEM_NAMED` | It has a name a person can read | | `SONA_ITEM_STOCK` | Built in: every avatar has it | | `SONA_ITEM_AWARD` | Earned in a game | The catalogue holds names and facts only: no models, textures or pictures. Names come in 26 languages ([catalogue languages](https://360sona.com/devs/docs/guides/catalogue-languages.md)). ## Props A prop is an item on a joint: in a hand, on the back, at the feet. A console avatar holds one prop; `SONA_EDIT_STACK_PROPS` keeps more than one in a manifest, and a game can attach up to `SONA_PROP_MAX` (8) meshes of its own to each avatar the same way ([props](https://360sona.com/devs/docs/guides/props.md)). Many stock props come with a clip of their own that the avatar performs. ## Custom items Your own clothes and props are items too: a `.sonaitem` file with its own id, made from a stock template you paint or from your own skinned mesh, signed with your creator key. They wear and draw like any other item, in your game only; a console does not take an avatar that wears one. [Custom items](https://360sona.com/devs/docs/guides/custom-items.md). ## Filters A content filter leaves out what a game does not want shown (licensed brands, logos, items for an older audience) from searches, random avatars and the editor, and swaps it on avatars that arrive wearing it ([content filters](https://360sona.com/devs/docs/guides/filters.md)). ## Related - [Manifests](https://360sona.com/devs/docs/concepts/manifests.md): the 1,000 bytes that hold the worn items. - [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md): searching and listing items. - [Item previews](https://360sona.com/devs/docs/guides/item-preview.md): a picture of one item on its own. --- Source: https://360sona.com/devs/docs/concepts/clips.md # Clips and animation An avatar moves by playing clips on its own clock. A clip is a named animation of the avatar's skeleton and its face: the clips 360sona.com's editor plays, by key (`GenericWave`, `Stand0`: `sona clips` lists them), the 100 clips of the stock clip library by name (`wave`, `laugh_female`), the clips that come with a prop, and clips you import from glTF, FBX or BVH. Every frame `sona_update` moves each avatar's clock by `dt` and poses it from what it plays. ```sh sona clips sona render seed:vega -o wave.png --clip GenericWave --time 1.5 --size 512x640 --gate ``` `sona` is the SDK's command-line tool ([what it needs](https://360sona.com/devs/docs/concepts/sources.md)). ## Play, crossfade and queue Play a clip and it starts at once; crossfade to it and the avatar blends from the pose it has into the new clip over the seconds you give; queue it and it starts when the current clip ends. | Call | What it does | |---|---| | `sona_avatar_play(a, clip, opts)` | Plays a clip now, and empties the queue | | `sona_avatar_crossfade(a, clip, opts, seconds)` | Blends from what plays into the clip over `seconds` | | `sona_avatar_queue(a, clip, opts, fade)` | Plays the clip when the current one ends, up to `SONA_QUEUE_MAX` (8) waiting | | `sona_avatar_play_stock(a, id, opts, fade)` | A stock clip by its id, in the variant made for the avatar's body | `sona_play_options` gives `loop` (default 1), `speed` (default 1) and `from`, seconds into the clip; `NULL` takes those defaults. A clip asked for before the avatar is `READY` is remembered and starts when it appears. The names a call takes are a clip key, a raw clip id, `"idle"`, `"still"` (no clip) or `"prop"` (the held prop's own clip). ## The stock clips The stock clip library's 100 clips have a name, a constant (`SONA_STOCK_WAVE`), a family and tags: idle, emote, reaction, look, travel and more ([the clip table](https://360sona.com/devs/docs/guides/clips.md#the-clip-table)). Some come in a man's and a woman's variant (`laugh_male`, `laugh_female`); `sona_avatar_play_stock` takes either and plays the one made for the body. `sona_stock_clips_tagged` lists every clip with a tag, for a random emote or an idle picker. The procedural idle lays blinks, glances, small weight shifts and breathing over whatever plays (`sona_avatar_idle`), so a standing avatar never looks frozen. ## Layers, masks and state machines Above the clip on its clock, an avatar can run layers: up to `SONA_LAYER_MAX` (8), each playing a clip or a blend space on a mask of the body (`SONA_MASK_UPPER_BODY`, `SONA_MASK_LEFT_ARM`, ...), with a weight. A state machine of up to `SONA_STATE_MAX` (32) states and `SONA_TRANSITION_MAX` (64) transitions picks a layer's clip from parameters your game sets each frame, as an engine's animator does ([layers and states](https://360sona.com/devs/docs/guides/layers.md)). ## After the clip What the clip and its crossfades give is then changed by joint overrides your game sets (`sona_avatar_override`), by the layers, and by inverse kinematics: look-at, hands on a target, feet on the ground ([IK](https://360sona.com/devs/docs/guides/ik.md)). Hair and loose clothes sway ([sway](https://360sona.com/devs/docs/guides/sway.md)), and props are posed last, from the solved joints, so a prop moves exactly with the hand that holds it ([props](https://360sona.com/devs/docs/guides/props.md)). The face is posed apart from the body: expressions, lip sync and face tracking each set its parts ([lip sync](https://360sona.com/devs/docs/guides/lipsync.md), [face tracking](https://360sona.com/devs/docs/guides/face-tracking.md)). ## Clip events and root motion `sona_avatar_clip_events` lists what happened on an avatar's clip since the last call: started, looped, ended, a left or right footfall, or a mark you set at a time in the clip (up to `SONA_CLIP_EVENT_MAX`, 32, are held). Clips that travel (`walk_forward`, `run_forward`) move the root: `sona_avatar_root_motion` with `SONA_ROOT_MOTION_EXTRACT` keeps the avatar in place and collects the travel for `sona_avatar_take_root_motion`, so your game moves it, and `SONA_ROOT_MOTION_APPLY` moves it for you. ## Your own clips glTF, FBX and BVH animations are retargeted onto the avatar's skeleton at import, by bone name, with maps for Unity Humanoid, VRM, the Unreal mannequins and Mixamo ([imported clips](https://360sona.com/devs/docs/guides/import.md), [skeleton maps](https://360sona.com/devs/docs/guides/skeleton-maps.md)). ## Related - [Clips: the stock clip library](https://360sona.com/devs/docs/guides/clips.md): every stock clip and the procedural idle. - [Animation layers and states](https://360sona.com/devs/docs/guides/layers.md). - [Two-avatar interactions](https://360sona.com/devs/docs/guides/interactions.md): handshakes, hugs, high fives, sitting. --- Source: https://360sona.com/devs/docs/concepts/sources.md # Item files, the gate and the licence A manifest names items; drawing them needs the items' files: meshes, textures, clips. The SDK never ships them. It reads them at run time from the sources you give the context, in order, and the first that has a file wins. The licence file from your download opens the context and, with the gate as a source, lets it stream items for your app. ```sh sona render seed:vega -o vega.png --gate ``` The commands on the concept pages are the `sona` tool's, which installs apart from the SDK ([installing the tools](https://360sona.com/devs/docs/guides/installer.md)). `seed:vega` is one of its four sample avatars (`atlas`, `vega`, `juno` and `cutout`); a manifest file or base64 text works in its place. `--dir ~/dump` reads the item files from a folder of your own; `--gate` streams them from 360sona instead, with the licence of your download (`--sdk sdk` finds it there). ## The sources `sona_config.sources` holds up to `SONA_MAX_SOURCES` (4), asked in order: | Source | `kind` | `location` | Use it when | |---|---|---|---| | The 360sona gate | `SONA_SOURCE_GATE` | `NULL`: https://360sona.com/g | Items should stream over https for your app id, with nothing to install | | An asset folder | `SONA_SOURCE_DIR` | the folder | You keep the item files yourself, laid out as the gate serves them | | A console's storage | `SONA_SOURCE_CONSOLE` | a Content root (`uda0:/Content`) or a PC path to one | The program runs on an Xbox 360, or reads a console's Content tree | | Your own reader | `SONA_SOURCE_CUSTOM` | `custom` | The files are in your own archive, package or network layer | What is read is decoded on worker threads and kept in a memory cache that counts against the context's budget ([memory](https://360sona.com/devs/docs/concepts.md#memory)); an item no avatar uses any more is kept for reuse and dropped oldest first. A folder or a console source works offline. With the gate, an item read once stays in the cache for the run. On the command line `--gate` is the gate and `--dir ` an asset folder (up to four, or `$SONA_DIR`) ([CLI reference](https://360sona.com/devs/docs/reference/cli.md#global-options)). The sample programs of the download (`samples/`) and the templates stream from the gate with the licence of your download, so their commands in these pages give no folder; `--dir ""` reads one instead. With no network they stop at once and say so. Their `--cast devs-cast.json` is the [sample avatars](https://360sona.com/devs/docs/install.md#sample-avatars). ## The gate The gate is 360sona's item server. It answers only a program with a licence for an app, and it streams the files of the items asked for by id, so a game reads what its avatars wear and nothing more. Each app has a daily allowance per address: 10,000 items and 100,000 answers ([limits](https://360sona.com/devs/docs/limits.md)). A web page reaches the gate through the bridge, an iframe the web SDK opens on 360sona.com, so its items never sit in your page's own files. When the gate cannot be reached the code is `SONA_E_GATE` ([troubleshooting](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). ## The licence Each download carries `sona-licence.json`: your app id, the build id, the platforms it is for and its version, signed with 360sona's release key. The context checks it when it opens: | Result of `sona_open` | Means | |---|---| | `SONA_E_LICENCE` | The file is missing, damaged or another app's, or the app has not accepted the SDK Licence | | `SONA_E_PLATFORM` | The download was made for other platforms | | `SONA_E_APP` | The app was turned off | | `SONA_E_BUILD` | This build was revoked | With the gate as a source, the context also checks its build with 360sona in the background. A revoked build or an app that was turned off closes the gate source and raises `SONA_EVENT_ERROR`; folder and console sources need only the licence file and keep working offline ([signed releases and revocation](https://360sona.com/devs/docs/guides/release.md)). Each library in a download is stamped with your app and its build. Use your own download, and ship it only inside your game ([licence and credit](https://360sona.com/devs/docs/licence.md#your-download)). ## A source of your own `SONA_SOURCE_CUSTOM` hands every read to your code: a `sona_source` with a `read` callback that gets a request and completes it, from any thread, with the bytes or an error. It is how a game reads items from its own pack file, or proxies the gate through its own server. The reference has the callback's rules ([asset sources](https://360sona.com/devs/docs/reference.md#asset-sources)). ## Related - [Installing](https://360sona.com/devs/docs/install.md#avatar-files): the sources in a first program. - [Untrusted files, long sessions](https://360sona.com/devs/docs/guides/hardening.md): what the readers check. - [Licence and credit](https://360sona.com/devs/docs/licence.md): what the licence allows. --- Source: https://360sona.com/devs/docs/concepts/credit.md # The credit The SDK is free on one condition: where your users see the avatars, they see "Powered by 360sona", linking to https://360sona.com. The SDK shows it for you, as a small badge in a corner of the frame and as text inside every file it writes. You may move the badge, or turn it off and put the line in your credits, about page or store page instead. The wording is always "Powered by 360sona". ```sh sona render seed:vega -o vega.png --gate sona render seed:vega -o vega-plain.png --no-credit --gate ``` The first picture has the badge in its corner; the second has none, for a page that shows the credit itself. Both commands are the `sona` tool's ([seed avatars and item files](https://360sona.com/devs/docs/concepts/sources.md)). ## Where the SDK shows it | Where | What the SDK does | To move it or turn it off | |---|---|---| | `sona_draw` and `sona_snapshot` | Draws the badge in a corner once an avatar is on screen | `sona_draw_options.credit_corner`; `SONA_DRAW_NO_CREDIT` | | The web SDK | The same badge over the canvas | `credit: false` | | Unity, Godot, Unreal | The `SonaCredit` component, the addon's and the plugin's badge | Unity: `SonaCredit.corner`, `showBadge`. Godot: `SonaCredit.corner`, `SonaServer.credit_enabled`. Unreal: `CreditCorner`, `bShowCredit` in the project settings | | `sona_png_encode`, headless renders | The PNG's `Software`, `Source` and `Comment` text: "360sona", the address, "Powered by 360sona" | Leave it there | | GLB, VRM and FBX exports | The credit in the file's metadata | Leave it there | | Sprite sheets | No badge on a frame | Show the credit in the game | | `sona render` on the command line | The badge, and the text chunks | `--no-credit` | The corners are `SONA_CORNER_BOTTOM_RIGHT` (the default), `_BOTTOM_LEFT`, `_TOP_RIGHT` and `_TOP_LEFT`. The badge is the same art everywhere, shown at a fixed 75% strength; a snapshot scales it with the picture, one size for every 400 pixels of its shorter side. ## In your own UI To draw the badge yourself (a corner of your HUD, an about screen), take its pixels and link it to the address: ```c sona_credit credit; if (sona_credit_get(ctx, 2, &credit) == SONA_OK) { /* credit.rgba is credit.width x credit.height RGBA pixels: show them at 75%, linked to credit.url */ } ``` ```cpp sona_credit credit; if (ctx.credit(2, credit) == SONA_OK) { // credit.rgba is credit.width x credit.height RGBA pixels: show them at 75%, linked to credit.url } ``` ```csharp var credit = ctx.GetCredit(2); // credit.Rgba is credit.Width x credit.Height RGBA pixels: show them at 75%, linked to credit.Url ``` ```rust let credit = ctx.credit(2)?; // credit.rgba is credit.width x credit.height RGBA pixels: show them at 75%, linked to credit.url ``` ```python credit = ctx.credit(2) # credit["rgba"] is credit["width"] x credit["height"] RGBA pixels: show them at 75%, linked to credit["url"] ``` The second argument is the scale: 1, 2 or 3 are the art's own sizes, and larger scales are the 3x art resampled. `credit.text` is "Powered by 360sona" and `credit.url` is https://360sona.com. ## When the badge is off `SONA_DRAW_NO_CREDIT` and the other switches turn the badge off; they do not turn the condition off. A game that draws no badge shows "Powered by 360sona", linking to https://360sona.com, in at least one of: its credits, its about page, its store page. A site shows it in its footer or on its about page. ## What it is not - Not an endorsement line. The credit says what draws the avatars; your game must not say 360sona or Microsoft endorses it ([licence and credit](https://360sona.com/devs/docs/licence.md#trademarks)). - Not a line to reword. It is always "Powered by 360sona". - Not a fee. There is no paid tier that removes it. ## Related - [Licence and credit](https://360sona.com/devs/docs/licence.md): what the licence allows and asks. - [What may a game ship?](https://360sona.com/devs/docs/answers/what-may-i-ship.md) --- Source: https://360sona.com/devs/docs/platforms.md # Platforms The same C API runs on every platform below; what differs is the graphics backends, the library file and how far each is tested. [Installing](https://360sona.com/devs/docs/install.md) has the downloads. ## At a glance | Platform | Graphics backends | Library | |---|---|---| | Windows x64 | Direct3D 11, Direct3D 12, Vulkan 1.1, OpenGL 3.3 | `sona.dll`, `sona.lib` | | Linux x64 (and Steam Deck) | Vulkan 1.1, OpenGL 3.3, OpenGL ES 3.0 | `libsona.so`, `libsona.a` | | Linux arm64 | Vulkan, OpenGL ES 3.0 | `libsona.so` | | Android (arm64-v8a, x86_64) | Vulkan, OpenGL ES 3.0 | `libsona.so` per ABI | | The web | WebGPU, WebGL2 | `sona-renderer.js` | | macOS (arm64, x86_64) | Metal | `libsona.dylib` | | iOS | Metal | `sona.xcframework` | | Xbox 360 homebrew (xsdk, libxenon) | Xenos | `libsona.a` for xsdk, `libsona-xenon.a` | | WebAssembly core | none: data only | `sona-core.wasm` | The languages and engines each platform has, and how far each is tested: | Platform | Languages and engines | How far it is tested | |---|---|---| | Windows x64 | C, C++, C#, Rust, Python; Unity, Unreal, Godot | Tested on hardware GPUs and on WARP | | Linux x64 (and Steam Deck) | C, C++, C#, Rust, Python; Godot, Unreal | Tested on a GPU and on lavapipe and llvmpipe | | Linux arm64 | C, C++, Rust, Python; Godot | Core tested under emulation; backends built | | Android (arm64-v8a, x86_64) | C, C++; Unity, Unreal, Godot | Drawn on the emulator's GPU; see [Android](https://360sona.com/devs/docs/guides/android.md) | | The web | JavaScript, TypeScript; three.js, Babylon.js, React | Tested in headless Chromium on both | | macOS (arm64, x86_64) | C, C++, C#, Rust, Python; Unity, Unreal, Godot | Metal's tests on Apple silicon; the download loads on Apple silicon and Intel | | iOS | C, C++; Unity, Unreal | Built for devices and the simulator; the tests run in the simulator | | Xbox 360 homebrew (libxenon) | C | Drawn on a software model of the GPU; see below | | WebAssembly core | JavaScript | The data API, for a renderer of your own | ## Windows - Compilers: MSVC 2022 for the release library; mingw-w64 builds too. - Keep `sona.dll` beside your program. The import library is `lib/sona.lib`. - [Headless rendering](https://360sona.com/devs/docs/guides/headless.md) uses Vulkan, Direct3D 11 on any adapter, or WARP when there is no GPU. - A lost device (a driver update, a GPU reset) is recovered with `sona_renderer_lost` and `sona_renderer_reset`: [device loss](https://360sona.com/devs/docs/guides/device-loss.md). ## Linux - The release library is built against glibc 2.31, so it loads on Ubuntu 22.04 and later, SteamOS 3 and the engine hosts built on them. - Only `sona_*` symbols are exported. - With no GPU, the headless device falls back to lavapipe or llvmpipe, so servers and containers draw the same pictures. - OpenGL ES 3.0 runs over EGL, GBM or surfaceless. ## Android - Both ABIs have their page alignment set to 16 KB, as Google Play requires for apps that target Android 15 and later. - Vulkan is the default; OpenGL ES 3.0 is the fallback for older devices. - The low [quality tier](https://360sona.com/devs/docs/guides/tiers.md) is made for low-end phones. - An app paused with its EGL context gone recovers as on a desktop: [device loss](https://360sona.com/devs/docs/guides/device-loss.md). - The plaza starter builds an APK with no Java: [the plaza starter](https://360sona.com/devs/docs/tutorials/starter-plaza.md#android). ## The web - The Renderer SDK draws with WebGPU and falls back to WebGL2 by itself: [WebGPU](https://360sona.com/devs/docs/guides/web-webgpu.md). - Pages must be served over https, or `http://localhost` while you develop, from an origin registered for your app. - The live avatar (`sona-runtime.js`) needs no key and no registration: [the web API](https://360sona.com/devs/docs/web-api.md#runtime). ## macOS and iOS The library draws with Metal on macOS and iOS, from the same source as the other platforms. `?platform=macos` is one universal `libsona.dylib` (Apple silicon and Intel, macOS 11 or later) with the tools; `?platform=ios` is `sona.xcframework` (devices and the simulator, iOS 13 or later). The Unity, Godot and Unreal downloads carry their macOS parts, and Unity and Unreal their iOS ones. Each copy is stamped for your app and signed again as it downloads. Until the SDK is signed with an Apple Developer ID, macOS asks once before it loads the library: allow it in System Settings, Privacy & Security. The plaza demo's macOS build draws with OpenGL. ## Xbox 360 homebrew `libsona.a` builds `.xex` titles with xsdk, for a modded console's own dashboard and for Xenia. It streams items from 360sona over HTTPS and shows the signed-in player's own avatar; the starter `sona-plaza` does both ([Xbox 360 homebrew](https://360sona.com/devs/docs/guides/xbox360.md)). `libsona-xenon.a` is the same core for libxenon under XeLL, with a sample (`samples/xell`): avatars on the TV, the gamepad changing clips and styles. The core is big-endian clean, and the Xenos backend draws the same pictures as the desktop backends. Set `budget.total` in the config to the memory you can spare; nothing in the core allocates past it. ![sona-plaza on Xbox 360 homebrew, in Xenia](https://360sona.com/devs/docs/img/xbox360-plaza.webp) ## Engines | Engine | Version built against | How avatars are drawn | |---|---|---| | Unity | 2021.3 or later | Unity's renderer, from posed meshes the package reads each frame | | Godot | 4.7 (GDExtension) | Godot's renderer; the extension skins on the GPU | | Unreal Engine | 5.8 | Unreal's renderer; the plugin's material and a Control Rig for IK | | Blender | 4.5 | Import as a rigged mesh with actions; export back as GLB | The engines draw with their own renderers, so an avatar takes the engine's lights, shadows and post-processing. The SDK's own backends are for programs that draw with Vulkan, Direct3D, OpenGL or Metal themselves. ## What every platform shares - The API and its behaviour: the same manifest gives the same avatar and the same pose bits. - [Parity](https://360sona.com/devs/docs/guides/parity.md): each backend's pictures are held to the web renderer's, scene by scene. - A [stable ABI](https://360sona.com/devs/docs/guides/abi.md): nothing breaks for two minor versions. --- Source: https://360sona.com/devs/docs/performance.md # Performance What a frame, a load and an avatar cost, as `sona-bench` measures them, and the settings that move each number. Every figure on this page is `sona-bench`'s own output, as it printed it. The scene is the hard case: every avatar in its own random outfit and body from the full catalogue (`--outfits random`), at 1920 x 1080, the median of three runs. ## Frame time | Scene, machine | ms a frame (CPU, GPU) | Draws a frame | |---|---|---| | 1,000 different avatars: Intel Arc iGPU (Core Ultra 9 185H), Vulkan | 14.05 (3.38, 13.98) | 9,470 | | 1,000 different avatars: RTX 4000 Ada machine, Vulkan | 1.79 (1.77, 1.59) | 9,470 | | 10,000 different avatars, stadium, LOD on: Intel Arc iGPU (Core Ultra 9 185H), Vulkan | 11.46 (7.84, 11.37) | 5,831 | | 10,000 different avatars, stadium, LOD on: RTX 4000 Ada machine, Vulkan | 7.56 (7.5, 2.87) | 5,831 | With LOD on, far avatars are drawn as sprites from atlas pages, which is why the stadium takes fewer draws than the grid of 1,000. ## Load time | What | Machine | Value | |---|---|---| | 1,000 different avatars, all ready after (ms) | Intel Arc iGPU | 2,422 | | 10,000 different avatars, all ready after (ms) | Intel Arc iGPU | 14,939 | | One avatar ready, items already in memory, median (ms) | Intel Arc iGPU | 25.77 | | One avatar ready, items read from disk, median (ms) | Intel Arc iGPU | 26.11 | Avatars load on worker threads and are committed inside `sona_update`, a few per frame, so a load does not stall the frame. From the gate the first load also waits on the network; what is read is cached in memory. ## Memory | Scene | CPU MB | GPU MB | |---|---|---| | 1,000 different avatars | 1,249.9 | 956.1 | | 10,000 different avatars, stadium, LOD on | 6,876.7 | 1,524.6 | `sona_stats` reports both figures at run time (`cpu_mb`, `gpu_mb`). Every avatar holds its own build, so memory grows with the count of avatars, not of looks. ## What sets the numbers | Setting | Where | Effect | |---|---|---| | Level of detail | `sona_lod_set` ([crowds](https://360sona.com/devs/docs/guides/crowd.md)) | Far avatars become sprites: fewer draws, less GPU time | | Quality tier | `sona_tier_apply` ([tiers](https://360sona.com/devs/docs/guides/tiers.md)) | The low tier draws one sample, smaller faces, and poses small avatars at their clip's own rate | | Anti-aliasing | `sona_renderer_set_quality` ([quality](https://360sona.com/devs/docs/guides/quality.md)) | MSAA samples cost GPU time on every avatar | | Shadows and lighting | `sona_renderer_set_lighting` ([lighting](https://360sona.com/devs/docs/guides/lighting.md)) | A shadow pass per frame; proxy casters make it cheap for crowds | | Build budget | `config.build_budget_ms` | How much of a frame the owner thread may spend committing loads | | Worker threads | `config.worker_threads` | Decodes and builds run there; 0 runs them inside the build budget | | Memory budget | `config.budget` | Caps the caches; `budget.total` is the hard limit | | Vulkan features | `sona_renderer_vk_features` ([Vulkan features](https://360sona.com/devs/docs/guides/vulkan-features.md)) | Bindless textures and multi-draw cut CPU time per draw | ## Measure it yourself `sona-bench` is in every native download (`bench/`) and prints the same JSON these tables are filled from. It reads the avatar files from a folder (`--source dir:`), and random outfits need the catalogue: ```text sona-bench --scene crowd --backend vk --source dir: --outfits random \ --catalogue sona-catalogue.bin --counts 1000 --seconds 4 --out crowd.json sona-bench --scene crowd --backend vk --source dir: --layout stadium --lod on \ --counts 10000 --out stadium.json sona-bench --scene cold --backend vk --source dir: --out cold.json ``` It reads the frame times from `sona_stats`, so your own game can log the same numbers. The speed gates each release must pass are in [hardening](https://360sona.com/devs/docs/guides/hardening.md). --- Source: https://360sona.com/devs/docs/limits.md # Limits and quotas Every fixed limit of the SDK and every quota of 360sona's servers, with the number. A limit in the library is reported as `SONA_E_LIMIT` or `SONA_E_ARGUMENT` with a message and a fix (`sona_last_error`); a server quota answers `429` with `Retry-After`, or `403` for a daily allowance. ## The library | What | Limit | Where it is set | |---|---|---| | Avatars in one context | 256 by default, 16,384 at most | `sona_config.max_avatars` | | Sources a context reads from | 4 | `SONA_MAX_SOURCES` | | A manifest | 1,000 bytes; as base64, at most 4,096 characters with whitespace | `SONA_MANIFEST_BYTES` | | Clips waiting in an avatar's queue | 8 | `SONA_QUEUE_MAX` | | Animation layers on an avatar | 8, with 32 parameters | `SONA_LAYER_MAX`, `SONA_PARAM_MAX` | | A state machine | 32 states, 64 transitions, 4 conditions a transition | `SONA_STATE_MAX`, `SONA_TRANSITION_MAX`, `SONA_CONDITION_MAX` | | A blend space | 16 samples | `SONA_BLEND_SAMPLES_MAX` | | Clip events held per avatar | 32, the oldest dropped past that | `SONA_CLIP_EVENT_MAX` | | Marks on an avatar's clip | 16 | `SONA_MARK_MAX` | | Props on one avatar | 8 | `SONA_PROP_MAX` | | A custom item file | 4 MiB | `SONA_CUSTOM_ITEM_MAX_BYTES` | | Baked looks per renderer (crowd sprites) | 16,384 by default | `sona_lod_options.max_looks` | | A headless picture | 1 to 8,192 pixels a side | `sona_render_options.width`, `height` | | Face sheets kept | 64 MiB and 512 sheets by default | `sona_budget.faces` | | The offline catalogue file | 256 MB | `sona_catalogue_load` | | A catalogue search | 1,024 bytes of text, 16 words | `sona_catalogue_query.text` | The memory caps are `sona_budget`'s defaults, every one yours to change: decoded items no avatar uses default to 256 MiB, clips default to 32 MiB, face sheets default to 64 MiB, fetched files default to 64 MiB and idle GPU objects default to 64 MiB. An item an avatar needs is never refused for being over a cache's cap; `budget.total`, when you set it, is the hard limit ([memory](https://360sona.com/devs/docs/concepts.md#memory)). ## The command line | What | Limit | |---|---| | `--dir` folders | 4 (or `$SONA_DIR`) | | `sona render --size` | 8,192 pixels a side; 512 x 512 by default | | `sona catalogue search --limit` | 5,000; 20 by default | | `--timeout`, how long an avatar may take to build | 120 seconds by default | | `sona scene --count` | 1 to 10,000 avatars | ## The web SDK | What | Limit | |---|---| | Avatars in one scene | 256 by default, 1,024 at most | | Origins per app | 10 | | Different items per page load | 3,000 | ## The SDK's daily allowance The SDK reports what it read from the gate; each app has an allowance per address and day. | What | Limit | |---|---| | Items a day, per app and address | 10,000 different items | | Answers a day, per app and address | 100,000 | | Native build checks | 600 an hour per address | Over it the answer is `403` until the next day (UTC). Caching avatars and reusing scenes keeps a game well under it: an item read once stays in the context's cache for the run. ## The web API | What | Limit | |---|---| | API calls per sign-in | 120 a minute | | Token swaps per address | 30 a minute | | Gamertag lookups | 60 an hour per address, and a shared hourly budget per app | | Xbox saves | 6 an hour per account | | Wardrobe, avatar tools and MCP | 600 an hour per address | | SDK downloads | 10 an hour per app | | Requests to us | 5 an hour per address | A `429` carries `Retry-After`; wait that long, or a minute. A manifest does not change unless its player changes it, so cache lookups ([the web API's limits](https://360sona.com/devs/docs/web-api.md#limits)). ## Asking for more A limit of the library that is a default (`max_avatars`, the budget, `max_looks`) is yours to raise. For a server quota, ask with `POST /sona/v1/requests` and say what your game needs ([requests](https://360sona.com/devs/docs/web-api.md#access)). --- Source: https://360sona.com/devs/docs/licence.md # Licence and credit The SDK is free, for free and paid games alike. The condition is the credit "Powered by 360sona", and the avatar items stay Microsoft's and its partners'. The [Developer Terms](https://360sona.com/devterms.html) and the SDK Licence in your download (`LICENSE.txt`) are the rules; this page is how they apply in code. ## What it costs Nothing. There are no paid tiers, no trial limits and no revenue share. App ids are free. ## The credit Show "Powered by 360sona", linking to https://360sona.com, where your users see the avatars. The SDK does it for you: | Where | What the SDK does | To move or replace it | |---|---|---| | `sona_draw`, `sona_snapshot` | Draws the badge in a corner of the frame | `sona_draw_options.credit_corner`; `SONA_DRAW_NO_CREDIT` turns it off | | The web Renderer SDK | Draws the same badge over the canvas | `credit: false` | | Unity, Godot, Unreal | `SonaCredit`, the addon's and the plugin's badge | Each component's own switch | | Exported files (PNG, GLB, VRM, FBX) | Writes the credit into the file's metadata | Leave it there | | Sprite sheet frames | No badge on a frame | Show the credit in the game | If you turn the badge off, put the line in your credits, about page or store page. To draw the badge yourself, in your own UI: ```c sona_credit credit; if (sona_credit_get(ctx, 1, &credit) == SONA_OK) { /* credit.rgba is credit.width x credit.height pixels; link it to credit.url */ } ``` ```cpp sona_credit credit; if (ctx.credit(1, credit) == SONA_OK) { // credit.rgba is credit.width x credit.height pixels; link it to credit.url } ``` ```csharp var credit = ctx.GetCredit(1); // credit.Rgba is credit.Width x credit.Height pixels; link it to credit.Url ``` ```rust let credit = ctx.credit(1)?; // credit.rgba is credit.width x credit.height pixels; link it to credit.url ``` ```python credit = ctx.credit(1) # credit["rgba"] is credit["width"] x credit["height"] pixels; link it to credit["url"] ``` The second argument is the scale: one, two or three times the badge's size. The wording is always "Powered by 360sona". ## What you may do | You may | You may not | |---|---| | Ship the SDK in a free or paid game or app | Sell avatar items, or put them in paid content | | Show Xbox 360 avatars, and say that your game uses them | Call your game an Xbox game, or say Microsoft or 360sona endorses it | | Let a player export their own avatar, with the credit in the file | Use the exporter to collect items or animations | | Draw avatars on your own servers (cards, gamerpics) | Scrape the catalogue or the asset server, or gather avatars in bulk | | Dress your own characters from the catalogue | Put licensed brands on what you sell or promote: use plain clothes (`style=plain`, `plain=1`, the `no-licensed` [filter](https://360sona.com/devs/docs/guides/filters.md)) | | Read the SDK's open sources (headers, bindings, samples) | Reverse engineer the library, or keep items, textures, models or animations in a usable form outside it | ## Your download > **Warning:** Each download is made for one app id and stamped for it. Use your own, do not pass it on, and ship > the library only inside your game. `sona-licence.json` is checked when the context opens; an app or a build that has been turned off answers `SONA_E_APP` or `SONA_E_BUILD` ([signed releases and revocation](https://360sona.com/devs/docs/guides/release.md)). ## Players' data Sign in with 360sona and the gamertag lookup give you data that belongs to the player. Use it only for what your sign-in page said, have a privacy policy, and delete it when the player asks or removes your app. > **Warning:** Never ask for a 360sona password, and never put tokens or keys in a web page. ## Trademarks 360sona is not affiliated with or endorsed by Microsoft. Xbox and Xbox 360 are Microsoft's trademarks, and the avatar items are the work of Microsoft and its partners. "Xbox 360 avatars" describes what the SDK draws; use it that way, and use no Microsoft logo or art. The short answers: [what may a game ship?](https://360sona.com/devs/docs/answers/what-may-i-ship.md) --- Source: https://360sona.com/devs/docs/troubleshooting.md # Troubleshooting and error codes Every failing call returns a negative `sona_result`, and `sona_last_error(ctx)` gives a message and a `fix` line written for that case. Print both; the fix usually says exactly what to change. The web API's errors carry the same `fix` and a `docs` link ([web errors](https://360sona.com/devs/docs/web-api.md#errors)). ## Symptoms ### The avatar does not appear - The avatar is still loading. `sona_avatar_add` returns at once and the avatar shows up once it is `READY`: an avatar that never shows up after `sona_avatar_add` is usually one whose context is not being updated. Check `sona_avatar_state_of`, and keep calling `sona_update` every frame. - The avatar failed. Read the events (`sona_poll_event`): a `SONA_EVENT_FAILED` carries the code and message. - The camera does not see it. Avatars stand about 1.8 m tall at the origin and face -Z at turn 0; start from a preset framing (`sona_camera_preset`) before moving the camera yourself. ### Avatars are black or too dark - In an engine (Unity, Godot, Unreal) the avatar draws with the package's own material. A material of your own loses the baked lighting: use the shipped one. - With the SDK's lighting on, a key light pointing up or a zero ambient leaves faces dark; start from `sona_lighting_defaults` ([lighting](https://360sona.com/devs/docs/guides/lighting.md)). ### It worked on my machine and fails on another - `SONA_E_PLATFORM`: the download was made for other platforms. Download again with this platform ticked. - `SONA_E_LICENCE`: the `sona-licence.json` next to the program is missing, or is another app's. ### Frame spikes when adding avatars Building an avatar takes work on the owner thread. `build_budget_ms` in `sona_config` caps that work per update, and worker threads take the rest; lower the budget, or add avatars a few at a time ([crowds](https://360sona.com/devs/docs/guides/crowd.md)). ### "403 origin" on a web page The page's origin is not on the app's list. Add it on your app's page, with `http://localhost` (any port) while you develop ([getting the SDK](https://360sona.com/devs/docs/web-api.md#sdk-download)). A `file://` page has no origin and never works. ## Error codes Every error is a negative `sona_result`; `sona_result_name(r)` gives its name for a log line. `SONA_OK` is 0 and `SONA_PENDING` is 1 (not finished: call again after `sona_update`). | Code | Value | Cause and fix | |---|---|---| | `SONA_E_UNSUPPORTED` | -1 | No usable backend, API version or feature: the device lacks what the backend needs (Vulkan 1.1, OpenGL 3.3), or the call is for a module this build does not have. **Fix:** Pick another backend, or update the graphics driver. | | `SONA_E_ORIGIN` | -2 | Web only: the page's origin is not one of the app's origins. Native builds never return it. **Fix:** Register the origin on your app's page. | | `SONA_E_LICENCE` | -3 | The app has not accepted the SDK Licence, or the licence file is missing or bad. **Fix:** Accept the licence on your app's page, download again and pass that download's `sona-licence.json` unchanged. | | `SONA_E_APP` | -4 | No such app, or it was turned off. **Fix:** Check the app id in your config and on your app's page. | | `SONA_E_GATE` | -5 | 360sona could not be reached; the gate source streams the item files over https. **Fix:** Check the network; add a folder source so the game works offline. | | `SONA_E_MANIFEST` | -6 | The avatar could not be read or built: the 1,000 bytes are not a manifest, or its items cannot be put together. **Fix:** Check the bytes with `sona_manifest_parse`, and that base64 text was not cut or changed. | | `SONA_E_CONTEXT` | -7 | The graphics device failed or was lost. **Fix:** Recreate the renderer ([device loss](https://360sona.com/devs/docs/guides/device-loss.md)); the avatars stay in the context. | | `SONA_E_READBACK` | -8 | A picture could not be read back from the GPU. **Fix:** Retry the snapshot; if it keeps failing, the device is lost. | | `SONA_E_LIMIT` | -9 | Too many avatars or requests, over the daily use, or over the memory budget. **Fix:** Remove avatars you no longer show, raise `max_avatars` or the budget in `sona_config`, or wait for the daily use to reset. | | `SONA_E_DESTROYED` | -10 | The context, avatar or renderer is gone. **Fix:** Do not use a handle after `sona_close`, `sona_avatar_remove` or `sona_renderer_destroy`. | | `SONA_E_PLATFORM` | -11 | This build is not licensed for this platform. **Fix:** Download again with this platform ticked. | | `SONA_E_BUILD` | -12 | This build was revoked. **Fix:** Download a new one from your app's page. | | `SONA_E_ARGUMENT` | -13 | A bad argument: NULL where a pointer is needed, a struct whose `size` is not set, or a value out of range; the message names it. **Fix:** Fill structs with their `_defaults` call before setting fields. | | `SONA_E_MEMORY` | -14 | The allocator returned NULL. **Fix:** Free memory, or give the context a larger budget or allocator. | | `SONA_E_NOT_FOUND` | -15 | No source has that asset. **Fix:** For a folder source, check that it holds the item; else add the gate source. | | `SONA_E_IO` | -16 | A source failed to read; a retry may work. **Fix:** Check the folder's permissions or the network, then try again. | | `SONA_E_CORRUPT` | -17 | Bytes did not decode: a damaged file in a folder source, or a file that is not what its name says. **Fix:** Replace the file. | | `SONA_E_NOT_READY` | -18 | The avatar is not ready. **Fix:** Wait for `READY` (call `sona_update` each frame) before reading its pose or joints. | | `SONA_E_UNIMPLEMENTED` | -19 | The call is not in this build. **Fix:** Download a build with the module, or check which modules your platform has ([installing](https://360sona.com/devs/docs/install.md#optional-modules)). | In a log: ```c sona_config_defaults(&cfg); /* then the licence and the sources */ sona_result r = sona_open(&cfg, &ctx); if (r != SONA_OK) { sona_error_info e = sona_last_error(NULL); fprintf(stderr, "%s (%d): %s\n %s\n", sona_result_name(r), (int)r, e.message, e.fix ? e.fix : ""); } ``` ```cpp try { sona::Config cfg; // then the licence and the sources sona::Context opened(cfg); } catch (const sona::Error &e) { std::fprintf(stderr, "%s (%d): %s\n %s\n", sona_result_name(e.code), (int)e.code, e.message.c_str(), e.fix.c_str()); } ``` ```csharp try { using var opened = new SonaContext(new SonaOptions()); // then the licence and the sources } catch (SonaException e) { Console.Error.WriteLine($"{e.Code} ({(int)e.Code}): {e.Message}\n {e.Fix}"); } ``` ```rust match Context::open(Config::new()) { // then the licence and the sources Ok(opened) => { /* ... */ } Err(e) => eprintln!("{:?}: {}\n {}", e.code, e.message, e.fix), } ``` ```python try: opened = sona.Context() # then the licence and the sources except sona.SonaError as e: print("%s (%d): %s\n %s" % (e.name, e.code, e.message, e.fix)) ``` --- Source: https://360sona.com/devs/docs/faq.md # FAQ ## The SDK **Does it cost anything?** No. It is free for free and paid games, with no paid tiers. The condition is the "Powered by 360sona" credit, which the SDK draws. [Licence and credit](https://360sona.com/devs/docs/licence.md). **Is it made by Microsoft?** No. 360sona is not affiliated with or endorsed by Microsoft, and your game must not say it is. **Which platforms?** The web, Windows, Linux (x64 and arm64), macOS, iOS, Android and Xbox 360 homebrew, each with a download. [Platforms](https://360sona.com/devs/docs/platforms.md). **Which languages and engines?** JavaScript, C, C++, C#, Rust and Python; Unity, Godot, Unreal and Blender. [Installing](https://360sona.com/devs/docs/install.md). **Do I need an app id?** Not for the live avatar on a web page, the wardrobe search, random avatars or MCP. You need one, free, for the SDK downloads, the gamertag lookup and sign-in. Make one on [Your apps](https://360sona.com/devapp.html). **How do I get the SDK?** Sign in to [Your apps](https://360sona.com/devapp.html), make an app and download Setup from its **Set up** tab, for Windows, Linux or macOS. Setup installs the tools, SDK Studio and the SDK for what you are making, then draws an avatar to show it works. [SDK Setup](https://360sona.com/devs/docs/guides/setup.md). **Can my team use my copy of Setup?** One copy runs on up to three computers. Download a copy for each person; the **Set up** tab lists every copy and turns any of them off. **Can I see it run before I install anything?** Yes. The [web tutorial](https://360sona.com/devs/docs/tutorials/web.md) has a See it in action button that runs its code in the page, and the [playground](https://360sona.com/devs/docs/playground.md) changes the costume, clip and camera and gives you the code. **What is SDK Studio?** The SDK's desktop app. Browse and try on items, build avatars, put a crowd in a scene, start a project from a template and read these docs with no network. [SDK Studio](https://360sona.com/devs/docs/guides/studio.md). **Where do I start a project?** From a template: a plaza, a lobby, a VTuber kit, VR, a bot and server, and plaza starters, each ready to run. [Templates and starters](https://360sona.com/devs/docs/guides/templates.md). **How do I know a new version is out?** SDK Studio checks once a day and shows a bar when there is one. On the command line, `sona update` says whether one is out and what changed. [Versions and migration](https://360sona.com/devs/docs/versions.md). **How does my app get write access?** Reading (`profile:read`, `avatar:read`, `awards`) is granted when the app is made. To change what players have (`profile:write`, `avatar:write`, `xbox`), ask on the **Sign-in** tab of Your apps, or with `POST /sona/v1/apps/{id}/ask`, with a line on what it is for. The app keeps working while it waits, and the tab shows the answer. [Write access](https://360sona.com/devs/docs/web-api.md#access). **Does the SDK call home?** Only through the gate. With the gate as a source, the context checks its build with 360sona and reports how many items it read, for the daily allowance; a folder or console source makes no network call at all. [Item files, the gate and the licence](https://360sona.com/devs/docs/concepts/sources.md). **Is there an offline copy of these docs?** Yes: `sona docs search ` and `sona docs show ` read the SDK's pages with no network, and SDK Studio has them in its Docs pane. [CLI reference](https://360sona.com/devs/docs/reference/cli.md#docs). ## Avatars **What is a manifest?** The 1,000 bytes that describe one avatar: body, colours, face and the item worn in each slot. Text APIs carry it as base64. [Concepts](https://360sona.com/devs/docs/concepts.md#the-manifest). **Where do I get one?** From 360sona.com's editor (the share box), from a gamertag, from a player who signs in, or made in code with `sona_make_random`. [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md). **Can I show the avatar on someone's Xbox account?** Yes, from the gamertag: `GET /sona/v1/gamertag/{gamertag}?client=YOUR_APP_ID`. [An avatar from a gamertag](https://360sona.com/devs/docs/answers/avatar-from-a-gamertag.md). **Can players edit their avatar inside my game?** Yes. The player editor is a component you open and get a manifest back from. [The player editor](https://360sona.com/devs/docs/guides/editor.md), [the editor element](https://360sona.com/devs/docs/guides/web-editor.md). **Can I add my own clothes?** Yes: paint on a stock shape, or bring your own skinned mesh. [Custom items](https://360sona.com/devs/docs/guides/custom-items.md). **How do I find an item's id?** Search the offline catalogue: `sona catalogue search `, or `sona_catalogue_search` in code. [Items and slots](https://360sona.com/devs/docs/concepts/items.md). **Why does an item go on one body and not the other?** Most clothes are made for the man's body or the woman's. The catalogue says which, and changing an avatar's body swaps each item for its variant. [Items and slots](https://360sona.com/devs/docs/concepts/items.md#bodies). **Can a desktop app use Sign in with 360sona?** Yes, with a loopback redirect: listen on a free port and send `http://127.0.0.1:{port}/callback`, with PKCE. [Sign in with 360sona](https://360sona.com/devs/docs/web-api.md#sign-in). ## Drawing **Where do the item files come from?** From the 360sona gate over https, or from a folder you own. They are read at run time and never shipped in your game. [Installing](https://360sona.com/devs/docs/install.md#avatar-files). **Does it work offline?** With a folder source, yes. With the gate, what has been read stays in the memory cache for the run. **The avatar does not appear.** It is still loading, a source has none of its items, or the licence was refused. [Troubleshooting](https://360sona.com/devs/docs/troubleshooting.md#the-avatar-does-not-appear). **How many avatars can I draw?** The bench draws 1,000 different avatars at once, and 10,000 with level of detail on. [Performance](https://360sona.com/devs/docs/performance.md) has the frame times, load times and memory for both. **Can I draw them with my own renderer?** Yes. `sona_pose` gives posed meshes, materials and a joint palette each frame; the Unity, Godot and Unreal packages are built on it. [Your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md) shows the frame loop and the skinning in five languages. **Can I draw without a window?** Yes, on a GPU or a software device. [Headless rendering](https://360sona.com/devs/docs/guides/headless.md). **An item draws broken or with the wrong picture.** A few items' own files are damaged where they come from. Ask for a look at it with its id: `POST /sona/v1/requests` with `"kind": "bug"` ([requests](https://360sona.com/devs/docs/web-api.md#access)). **It is slow on a machine with no graphics card.** A software renderer (Microsoft Basic Render Driver, llvmpipe, SwiftShader) draws on the CPU. Use the low quality tier there; `sona_tier_detect` picks it. [Quality tiers](https://360sona.com/devs/docs/guides/tiers.md). ## Animation **Which animations are there?** The stock clips (idles, emotes, reactions), each with a name and an enum. [Clips](https://360sona.com/devs/docs/guides/clips.md). **Can I use my own animations?** Yes, from glTF, FBX or BVH, retargeted to the avatar. [Imported clips](https://360sona.com/devs/docs/guides/import.md). **Can the avatar talk?** Yes: lip sync from audio, and a face you set shape by shape. [Lip sync](https://360sona.com/devs/docs/guides/lipsync.md). ## Shipping **What must my game show?** "Powered by 360sona", linking to https://360sona.com. The badge does it. [Licence and credit](https://360sona.com/devs/docs/licence.md#the-credit). **Can I sell the items?** No. They are Microsoft's and its partners' work. [What may a game ship?](https://360sona.com/devs/docs/answers/what-may-i-ship.md) **Will an update break my build?** Not within two minor versions. [The stable ABI](https://360sona.com/devs/docs/guides/abi.md). **How do I export an avatar as a model?** GLB, VRM and FBX, rigged, with clips. [VRM and glTF](https://360sona.com/devs/docs/guides/vrm.md), [FBX](https://360sona.com/devs/docs/guides/export-fbx.md). **How do I move to a new version?** Download again for your app; within 1.x nothing breaks for two minor versions. [Versions and migration](https://360sona.com/devs/docs/versions.md). **What are the limits?** The library's fixed limits and the servers' quotas are on one page. [Limits and quotas](https://360sona.com/devs/docs/limits.md). ## Something else Ask for it: `POST /sona/v1/requests` with what you need ([requests](https://360sona.com/devs/docs/web-api.md#access)). --- Source: https://360sona.com/devs/docs/glossary.md # Glossary The words these docs use, each with the page that has the rest. **App id.** The name 360sona gives your app, free, with a key (`sak_...`) for its API calls. Downloads, the gamertag lookup, sign-in and the gate all go by it. [Requests](https://360sona.com/devs/docs/web-api.md#access). **Asset folder.** A folder of item files you own, laid out as the gate serves them; a source with `--dir` or `SONA_SOURCE_DIR`. The samples and templates read one; the CLI and your own programs can read the gate instead. [Item files, the gate and the licence](https://360sona.com/devs/docs/concepts/sources.md). **Award.** An item a player earns in a game. Your own game can define awards and unlock them for its players. [Items and slots](https://360sona.com/devs/docs/concepts/items.md). **Backend.** The graphics API a renderer draws with: Vulkan, Direct3D 11 or 12, OpenGL, OpenGL ES, Metal, WebGPU, WebGL2, or Xenos on an Xbox 360. [Platforms](https://360sona.com/devs/docs/platforms.md). **Badge.** The small "Powered by 360sona" picture the SDK draws in a corner of the frame. [The credit](https://360sona.com/devs/docs/concepts/credit.md). **Binding.** The SDK's API in another language: C++ (`sona.hpp`), C#, Rust and Python. Each wraps the C API and can reach every C call through its raw layer. [Bindings reference](https://360sona.com/devs/docs/reference/bindings.md). **Body.** The man's or the woman's figure an avatar is built on, with its two sliders, weight and height. [Manifests](https://360sona.com/devs/docs/concepts/manifests.md). **Bridge.** The iframe the web SDK opens on 360sona.com to read items from the gate for a page. [The web API](https://360sona.com/devs/docs/web-api.md#sdk-bridge). **Build id.** The id stamped into the libraries of one download. A build can be revoked on its own. [Signed releases](https://360sona.com/devs/docs/guides/release.md). **Catalogue.** `sona-catalogue.bin`: every item id with its name, slots, game and body, read with no web call. [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md). **Clip.** A named animation an avatar plays on its clock: a stock clip, a prop's clip, or one you import. [Clips and animation](https://360sona.com/devs/docs/concepts/clips.md). **Console-ready.** A manifest a real Xbox 360 takes as it is: one prop, the required clothes, no custom item. `sona_manifest_ready_for_xbox`. [Manifests](https://360sona.com/devs/docs/concepts/manifests.md). **Context.** `sona_ctx`: the licence, the sources and every avatar. A game usually has one, owned by one thread. [Concepts](https://360sona.com/devs/docs/concepts.md). **Costume.** An item that fills several slots at once, such as a dress or a suit of armour. [Items and slots](https://360sona.com/devs/docs/concepts/items.md). **Credit.** "Powered by 360sona", linking to https://360sona.com, shown where your users see avatars. [The credit](https://360sona.com/devs/docs/concepts/credit.md). **Crowd.** Many avatars drawn at once, with level of detail. [Crowds](https://360sona.com/devs/docs/guides/crowd.md). **Custom item.** An item you make: a `.sonaitem` file painted on a stock template or built from your own skinned mesh. [Custom items](https://360sona.com/devs/docs/guides/custom-items.md). **Filter.** A content filter: rules that leave out items a game does not want shown. [Content filters](https://360sona.com/devs/docs/guides/filters.md). **Gamertag.** A player's Xbox name. The gamertag lookup returns the avatar on that account. [An avatar from a gamertag](https://360sona.com/devs/docs/answers/avatar-from-a-gamertag.md). **Gate.** 360sona's item server, which streams item files to a program with a licence for an app. [Item files, the gate and the licence](https://360sona.com/devs/docs/concepts/sources.md). **Headless.** Rendering with no window, to pictures or video. [Headless rendering](https://360sona.com/devs/docs/guides/headless.md). **IK.** Inverse kinematics: look-at, hands on a target, feet on the ground. [Inverse kinematics](https://360sona.com/devs/docs/guides/ik.md). **Item.** Anything an avatar wears or holds, by a 128-bit id. [Items and slots](https://360sona.com/devs/docs/concepts/items.md). **Layer.** A clip or blend space played over part of the body, on top of the clip on the avatar's clock. [Animation layers and states](https://360sona.com/devs/docs/guides/layers.md). **Licence file.** `sona-licence.json` in your download, signed for your app; the context checks it when it opens. [Item files, the gate and the licence](https://360sona.com/devs/docs/concepts/sources.md). **LOD.** Level of detail: far avatars posed less often or drawn as sprites. [Crowds](https://360sona.com/devs/docs/guides/crowd.md). **Manifest.** The 1,000 bytes that describe one avatar; as text, base64. [Manifests](https://360sona.com/devs/docs/concepts/manifests.md). **MCP server.** `sona-mcp`, the SDK's tools for AI agents over the Model Context Protocol. [MCP](https://360sona.com/devs/docs/guides/mcp.md). **Owner thread.** The thread that opened a context, which makes every call on it. [Concepts](https://360sona.com/devs/docs/concepts.md#threads). **Placeholder.** A neutral figure drawn while an avatar loads. [Placeholders](https://360sona.com/devs/docs/guides/placeholder.md). **Prop.** An item or mesh on a joint: held in a hand, worn on the back, at the feet. [Props](https://360sona.com/devs/docs/guides/props.md). **Renderer.** `sona_renderer`: draws a context's avatars on one graphics device. [Concepts](https://360sona.com/devs/docs/concepts.md). **Slot.** A place an item fills (shirt, trousers, headwear, ...), as a bit of a mask. [Items and slots](https://360sona.com/devs/docs/concepts/items.md). **Source.** Where the context reads item files from: the gate, a folder, a console, or your own reader. [Item files, the gate and the licence](https://360sona.com/devs/docs/concepts/sources.md). **Sprite.** A baked picture of an avatar, drawn in place of its meshes far away. [Crowds](https://360sona.com/devs/docs/guides/crowd.md). **Stock clip.** One of the 100 clips of the stock clip library, by name and id. [Clips](https://360sona.com/devs/docs/guides/clips.md). **Tier.** A quality preset (low to high) that sets many options at once. [Quality tiers](https://360sona.com/devs/docs/guides/tiers.md). **View.** `sona_view`: the camera a frame is posed and drawn for. [The C reference](https://360sona.com/devs/docs/reference.md). --- Source: https://360sona.com/devs/docs/versions.md # Versions and migration The SDK's version is `major.minor.patch`. The web SDK, the native library, the bindings and the engine packages are released together, and the [changelog](https://360sona.com/devs/docs/changelog.md) lists each release's changes to all of them. Within a major version nothing you build against breaks for two minor versions. This page says how to read the version, what each kind of release may change, and how to move from 1.0 to 1.1. ```c printf("built against %d.%d.%d (ABI %d), running %s\n", SONA_VERSION_MAJOR, SONA_VERSION_MINOR, SONA_VERSION_PATCH, SONA_ABI, sona_version()); ``` ```cpp std::printf("built against %d.%d.%d (ABI %d), running %s\n", SONA_VERSION_MAJOR, SONA_VERSION_MINOR, SONA_VERSION_PATCH, SONA_ABI, sona::version()); ``` ```csharp Console.WriteLine($"running {SonaLibrary.Version}"); ``` ```rust println!("running {}", version()); ``` ```python print("running", sona.version()) ``` ```sh sona version ``` ## What a release may change | Release | May add | May change or remove | |---|---|---| | Patch (1.1.0 to 1.1.1) | Fixes | Nothing you call | | Minor (1.1 to 1.2) | Functions, structs, enum values, fields in a struct's `reserved` words, bindings' methods | Marks things deprecated; removes only what was deprecated two minor versions before | | Major (1.x to 2.0) | Anything | Anything, said in its release notes | Within 1.x every struct keeps its size and every field its offset; a number (`SONA_*`, an enum value, a result code) keeps its meaning; every exported function stays. Something deprecated in 1.x still works in 1.x and 1.(x+1) and goes, at the earliest, in 1.(x+2) ([the stable ABI](https://360sona.com/devs/docs/guides/abi.md)). ## Checking at run time A program that loads the library at run time, or a binding, asks which ABI it has before it opens a context: | Call | Gives | |---|---| | `sona_version()` | The library's version as text, `"1.1.0"` | | `sona_abi_query` | Its `SONA_ABI`, the oldest `SONA_ABI` a caller may be built against, and its version as numbers | | `sona_struct_size`, `sona_struct_offset` | A struct's size and a field's offset as the library has them | The bindings make these checks themselves and refuse a library that does not match, with a message, instead of misreading it. The [stable ABI](https://360sona.com/devs/docs/guides/abi.md) page has the check in each language. ## From 1.0 to 1.1 1.0 was the web SDK alone. 1.1 adds the native SDK (C and the bindings), the engine packages, the templates and the tools, and keeps every 1.0 web call working as it was. On the web: - `SonaRenderer.create()`, `add`, `play`, `snapshot()`, `glb()` and the camera calls are unchanged. - The renderer now draws with WebGPU where the browser has it and WebGL2 elsewhere; the pictures are the same. To keep WebGL2, ask for it ([WebGPU and WebGL2](https://360sona.com/devs/docs/guides/web-webgpu.md)). - New: the avatar editor element, `avatar.update(manifest)`, the wardrobe and colour lists, headless pictures, the three.js, Babylon.js and React packages ([the changelog](https://360sona.com/devs/docs/changelog.md)). From the web to native: the ideas carry over one for one. A web `scene` is a context (`sona_ctx`), `scene.add` is `sona_avatar_add_base64`, `avatar.play` is `sona_avatar_play`, and the page's animation frame is your loop's `sona_update` and `sona_draw`. Items come from the gate through your licence file instead of the bridge ([getting started](https://360sona.com/devs/docs/getting-started.md)). ## Downloads and versions A download is one version, stamped for your app. To move to a new version, download again: the new build has its own build id and licence file, and the old one keeps working until you revoke it ([signed releases](https://360sona.com/devs/docs/guides/release.md)). ## When a new version is out The tools tell you. `sona update` asks 360sona and says whether a newer SDK is out, what changed (the [changelog](https://360sona.com/devs/docs/changelog.md)) and how to update; with `--json` it gives `current`, `latest` and `newer` for scripts. Every other `sona` command reminds you once a day, in one line on stderr after its own output, when one is out. SDK Studio shows the same as a bar under its address bar, and Help > Check for updates asks again. Updating is two steps: 1. The tools, which bring SDK Studio with them: Setup, or the tools for your system, from your app's page (https://360sona.com/devapp.html), or `sona app tools ` with your app key. 2. Your SDK, which is made for your app: download it again from the same page, or `sona app download --force`. The check needs no key and sends no key, app id or account: it reads the server's list of downloads at most once a day and keeps the answer in your user's cache folder. The reminder never shows in scripts, pipes, `--json`, `--quiet`, `sona mcp` or when `CI` is set; `SONA_NO_UPDATE_CHECK=1` turns it off everywhere, the Studio's bar included. ## Related - [The stable ABI and deprecation](https://360sona.com/devs/docs/guides/abi.md) - [Changelog](https://360sona.com/devs/docs/changelog.md) - [Signed releases](https://360sona.com/devs/docs/guides/release.md) --- Source: https://360sona.com/devs/docs/changelog.md # Changelog ## 1.1.0 (2026-11-16) ### Native - `sona_item_thumbnail`: the gate's own picture of an item for grids and pickers, 120 to a request and metered apart from items, so a wardrobe no longer spends the budget avatars need ([Item previews](https://360sona.com/devs/docs/guides/item-preview.md)). - A licensed app presents its `sona-licence.json` when a gate session opens. The gate then meters that app on its own budget per network, larger than a browser's, instead of sharing one bucket with every browser on the network; restarting the app many times a day is no longer slowed. ### SDK Studio - The Wardrobe shows the gate's thumbnails (asked two screens ahead, kept on disk across SDK versions); previews are drawn only for items without one. - The Scene frames the crowd once as it is placed and holds still while it loads (it used to turn every frame until the last avatar was ready). Random outfits come from a fixed pool of about 140 items per body. - The Scene leads with the potential frame rate: what the SDK's CPU and GPU time allow, not the display's refresh rate, from GPU timer queries around the draw (GL and D3D11). Every frame time shows its frames a second too. ## 1.1.0 (2026-11-16) ### Web - The first avatar is on screen about three times sooner: about 350 ms from page open on a repeat visit at a 40 ms round trip, from about 1,150. The GPU starts while the network is busy, the bridge arrives with its check done and its boot files already fetched, items decode in a small worker pool with a faster LZX reader, and the first avatar shows on its build's face while the sharp one bakes (`snapshot()`, `settle()` and the headless pictures still wait for the sharp face). `performance` marks named `sona:*` time each stage. - `` (`defineAvatarEditor()`): the player-facing avatar editor as a web element, in the 360sona.com editor's layout and look: Body (body type, the build triangle, height and weight, skin), an Appearance door (the face rail: hair and the face parts with their colours) and a Wardrobe door (a tile per category under "Search every item", each garment's own colours). The full creator, the quick creator (eight generated looks, then the same three screens) and the wardrobe picker (the Wardrobe alone); gamepad (LB and RB go between Body, Appearance and Wardrobe), touch, mouse and keyboard; screen-reader labels; themed with `--sona-editor-*` custom properties in a shadow root; `startScreen` and `itemFilter`. It lists what the site's editor lists, by the site's rule and in its order, and "Search every item" finds what the site's search finds, a worn garment's body shape (to take it off) and the animations included. Putting an item on or picking a colourway never refills an empty required slot, as on the site (bald stays bald), the required cache changes only as the site's wear and unwear change it, and a body type change on a figure with nothing on leaves it bare. `examples/editor.html`. - `scene.wardrobe()`, `scene.colours()` and `scene.thumbnails(ids)`: the catalogue for pickers. Wardrobe rows carry `sub` (the subcategory) and `slots`, and a garment's body-shape record (mask 0x1000000) is a row in section `shape`, offered only while worn; animations are rows in section `animation`. - `avatar.update(manifest)`: change an avatar's manifest, drawing the old look until the new one is built. - A WebGPU renderer with the WebGL2 fallback, held to the same reference pictures as the native backends. - three.js, Babylon.js and React packages (`@360sona/three`, `@360sona/babylon`, `@360sona/react`). - `SonaRenderer.connect` (avatars as .glb with clips, for other engines) and `SonaRenderer.headless` (pictures with no canvas on the page). - Per-garment colours in the editor; `scene.colourways(id)`. - `SonaTrack`: webcam face tracking onto an avatar's face and head (MediaPipe's face landmarker). - Award items: `SonaRenderer.defineAward`, `unlockAward`, `playerAwards` and `awardFile`. ### Native SDK - Custom items v2: your own skinned meshes as items (format 1.1), packed by `sona_custom_item_pack_mesh`, the web packer and `sona-item mesh` to the same bytes. - Award items from your own game: `sona_award_define`, `sona_award_unlock`, `sona_award_poll`, and the accounts server's routes. Once a player unlocks an award its item stays as it was, and a retired award stays retired. - Body tracking (`sona_body`, an optional module), text to emote (`sona_emote_from_text`, `sona_avatar_emote`, and the MCP `emote_from_text` tool), the NPC kit (`sona_npc`), and face tracking on Windows and Android. - Art styles on D3D11, D3D12 and Xenos; crowd sprites baked in the avatar's style, now on D3D11 and D3D12 too. - GPU picking on D3D11, D3D12 and Xenos; lighting on Xenos; `SONA_LIGHTING_MESH_CASTERS`. Metal builds from the source; there is no macOS or iOS download. - Device loss recovery on GL, Vulkan, D3D11 and D3D12 (the device loss guide). - Props in 3D print and crowd sprites; glTF props on big-endian hosts. - IK foot locking, spine assist, finger curl and smooth eye turns; powered ragdolls (`sona_avatar_ragdoll_motors`) and the stock get-up clips `getup_back` and `getup_front`; props in a saved avatar state (`SONA_STATE_PART_PROPS`, `SONA_STATE_MISSING_PROP`). - FBX and Roblox export with clips, a rigged GLB from the CLI; item names in 26 catalogue languages. - `sona_item_colourways` and per-garment colours in the native editor (`SONA_EDITOR_GARMENT_COLOURS`). - The native editor's Wardrobe doors (`SONA_EDITOR_DOORS`) have the same "Search every item" box as the web element. - The native editor has 360sona.com's layout: Body (body type, height, build, skin), Appearance (the site's face board, each part with its colour over its grid) and Wardrobe (in the site's order, a worn garment's colourways over its category). The looks are the quick creator's entry. `SONA_EDITOR_SCREEN_APPEARANCE` is new; `SONA_EDITOR_SCREEN_FACE`, `_HAIR` and `_COLOURS` are deprecated and open the screen that took their place. C#, Python, Rust, Unity, Godot and Unreal have the new screen. - The native editor lists what the site's editor lists: every named item, a mesh or not, the body checked on models only, and anything the avatar wears, hidden duplicates and the other body's models included. Its counts match the web element's for the same avatar (`editor_item_counts`). An item worn twice in one section is listed with the other. - The native editor's Body is the site's body card: the two figures, the build triangle, Height and Weight, the skin, and the Appearance and Wardrobe doors under it. Its colour strips are the site's: `Data/ColorSets.json`'s sets, then the spectrum row and Any colour. Face paint has its colour strip. Brows and facial hair take their own colours, not the hair's (the quick creator's hair colour still carries to them). A tap on a figure picks that body, and the one in use does nothing, as on the site. - With no start manifest the native editor opens on the site's blank man (`blankAvatar`): the site's default figure (seed 0 of `docs/seed-avatars.json`) with every garment, the hair and the face parts off, its own chin, nose, ears, height, build and colours, and grey skin. Before, it wore the stock tee, jeans and shoes, with height and weight 0. A body switch from a figure with nothing on keeps it bare, as on the site; it used to put on the four default garments and hair. - The native editor's lists are in the site's order (the catalogue's, garments by how many slots they cover), not stock first and then by name. Its camera frames each part and category with the original's view presets, as the site's does (the head on Appearance, tops a little turned). Face parts are pictured on a tan face with brows, three across; the Male and Female tiles are renders of the two bare figures; an item whose file is missing has no picture. The stage is the site's grey gradient, drawn without the key light shadow, which striped the figure. A touch scroll of a grid stays where it is let go. - A pick in the native editor wears that item and nothing else, as the site's editor does: a hat on the blank man is one worn record, where it used to add shoes, trousers, a top and hair. Taking off an outfit puts back what it took off. Done hands back the figure as picked, which may lack a required garment (`sona_manifest_ready_for_xbox` says whether a console takes it). - The native editor's door pictures are the site's: one item from each category's representative set (the fullest outfits, else the items that are only that thing), picked with the editor's seed, on the grey stand-in; an item with no file gives way to the next. - `sona_renderer_underlay`: a picture behind the avatars, drawn first in the main pass (GL and Vulkan; `SONA_E_UNSUPPORTED` elsewhere, where the clear shows). The editor draws the site's stage gradient with it. - `SONA_EDITOR_SCREEN_FACE`, `_HAIR` and `_COLOURS` stay until 2.0. C# marks them `[Obsolete]`, Python warns, Unreal hides them in Blueprints. - Headless rendering on Windows (Direct3D 11 on each adapter, and WARP) and on the Xbox 360. Metal builds from the source; there is no macOS or iOS download. - Quality tiers (`sona_tier_apply`, `sona_tier_detect`); the low tier poses most avatars at their clips' own rate. - sona-mcp builds with MSVC and runs on Windows. - Downloads for Linux x64, Linux arm64, Windows x64, Android, wasm and the Xbox 360 (with a XeLL sample), each signed with the release key, and for Unity, Godot and Unreal without their macOS and iOS libraries. The Windows download's import libraries are written from the `.def` files with llvm-lib. - The samples run with no `--dir`: they read items from 360sona with your download's licence, and say so plainly when 360sona cannot be reached. `--dir` still reads a folder of your own. - Rust: the `sona-editor` crate, a safe wrapper for the native editor. C#: `SonaRenderer.SetHostShadow` and `ClearHostShadow`, and `SonaHeadless.Renderer`. - Studio opens on a face: the Avatar builder starts from the April O'Neil Costume, and the home line-up is seven avatars with their faces showing. - Native 1.1.0: `sona_version()` reports 1.1.0; `sona_abi_query` and a stable ABI within 1.x (nothing breaks for two minor versions). Signed releases: every release's files in a signed SHA256SUMS, downloads stamped for your app and build, builds and apps revocable. - Packages: NuGet `Sona360`, PyPI `sona360`, crates.io `sona360-sys` and `sona360`, npm `@360sona/three`, `@360sona/babylon` and `@360sona/react`, the Unity package and .unitypackage, the Godot Asset Library zip and the Fab zip. Rust and Python cover every call; the C++ header wraps every call added in 1.1. - Fuzzers on the container, model, clip, texture, manifest and item decoders; a 30-minute soak of 1,000 different avatars; bench gates per tier. Faster crowds: meshes in vertex-cache order, small avatars drawn with simplified meshes under `sona_lod_set`, faces baked on the build's workers; `sona_library_cache_bytes`. - The credit badge is the real "Powered by 360sona" art (1x, 2x and 3x) in the core and every engine. ### Studio and CLI - SDK Studio opens on a home screen: the 360sona SDK wordmark, a live line-up of seven costumed avatars standing on a reflective floor, and a tile for every folder. A Samples folder lists the SDK's sample programs with their source. The Wardrobe lists what your sources hold first, each item once. A new install says what it needs and File > Sources takes effect without a restart. Icons are kept to the tree, toolbars, menus, headings and dialogs. `sona-studio --pane ` opens on a pane; Alt+Up goes up one level. An exported PNG's badge no longer lies on the avatar. Fixed: on Windows a headless Studio could end without printing its lines; the Log pane timed lines from before the app started from the wrong origin; a hair with nothing to draw had no preview. - Agents with no person present: the native download carries `bin/sona` and `bin/sona-mcp` made for your app (`SONA_SDK` or `--sdk` points the installed tools at them), `--server` for the licence check, the tools installer from `GET /sona/v1/apps/{id}/tools`, `sona app request` and `sona app licence`, MCP grants written ahead of time (`SONA_MCP_ALLOW_WRITE`, `SONA_MCP_ALLOW_EXEC`, `--config`), `export_avatar` over MCP, and `scene.settle()` on the web. Nothing waits on a prompt. - SDK Studio hosts the MCP server (HTTP and stdio, asks before writes outside Projects) and runs on macOS; Consoles and Apps works with your app on 360sona; the Projects pane makes the toolkit's templates. - The `sona` CLI gains `app`, `console`, `project`, `scene`, `docs`, `mcp` and `item mesh`, and reads v2 items. - Installers for the SDK tools on Windows, Linux and macOS. - sona-mcp takes its HTTP token from `--token-file` only (`--token` is gone). ### Templates - The plaza starter on every platform: C, C++, C#, Rust, Python, the web, Unity, Godot, Unreal and Android. - The plaza demo is the editor with a park, at the site's own size: one camera move for a pick and for Done, the site's stage bar, undo and redo in the native editor. Native (SDL3 and OpenGL) and web from one design. - The web crowd: a thousand avatars in one canvas, each a person of their own in one of 506 costumes. - The lobby sample: sign in with 360sona over a loopback redirect with PKCE, gamertag lookup, network sync, emotes with root motion, gamepad. The VR template (OpenXR: a first-person body with IK, a mirror, other players), the VTuber kit, the bot and server template (gamerpics and outfit cards) and the web crowd. - `devs-cast.json`, `starters/showcase-cast.json` and the web crowd wear some different costumes; row numbers are unchanged. ### Docs - A standard documentation site (Material for MkDocs) with search, light and dark, language tabs and a phone layout; every page opens with its own subject. Live previews drawn by the web SDK on the pages, a playground and the web SDK reference. ### Engines - Unity and Godot: full components, the drop-in editor with look and item pictures, the quick creator and the wardrobe picker, per-garment colours, starter scenes. - Unreal: IK on the component, the Load 360sona Avatar node, Control Rig IK (module Sona360ControlRig, the stock rig or your own rig graph), the drop-in editor widget (Full, Quick, Wardrobe) with its controls for screen readers, the M_SonaAvatar materials, `GetDrawnItems`, an AppId setting and a starter project; built and run against Unreal Engine 5.8.4. - Blender add-on: import an avatar rigged with its clips, export it back. ## 1.0.0 (2026-11-06) The first release of the 360sona Renderer SDK, for the web. - `SonaRenderer.create()` draws into your own canvas. No iframe draws anything. - Many avatars in one WebGL2 context. Each item is decoded and uploaded once and shared by every avatar that wears it. - Item and clip files are decoded in a worker. The rest of a build runs on the page's thread in short steps spread over frames to a time budget (`buildBudgetMs`, 6 ms by default). A step can still run longer than the budget, so adding an avatar can cost a few long frames, not one long freeze. - The idle playlist's clips are decoded in the background after the first idle avatar appears, so a new gesture does not wait or stall when it comes up. - Faces bake in a worker, at 512, 256 or 128 pixels depending on the crowd size. - Clips: the console's stands, the photo booth animations, the held prop's own clip, an idle playlist, and raw clip ids. - Camera: the console's four framings, a crowd fit, an orbit, a free camera, eased moves, and drag and zoom controls. - A small "Powered by 360sona" badge, shown once the first avatar is on screen. `credit: false` hides it. - `snapshot()` with the credit written into the file (`credit: true` also draws it in the corner), and `glb()`. - `benchmark()` and `stats()`: fps, ms per frame, p95, CPU ms, draw calls, GPU memory, build step times. - Assets stream from 360sona through the asset bridge, only to origins registered for your app. Not in 1.0: instancing, impostors, the whole build in a worker, the native C core, engine plugins and Xbox 360 homebrew. --- Source: https://360sona.com/devs/docs/cookbook.md # Cookbook: recipes for game moments Each recipe is a few lines for one game moment: make an avatar wave, cheer, look at the player, walk somewhere, hold something, smile or high-five another. Each is in C, C++ (`sona.hpp`), C#, Rust and Python. They use the variables a game already has: `ctx` (the context), `avatar` and `other` (two `READY` avatars), `player_head` (a point in metres). Where a binding has no wrapper for a call, its recipe makes the C call through the binding's own raw layer (C++ `raw()`, C# `Native`). Unity, Godot and Unreal have the same features on their avatar components. ## Wave when a goal is scored Crossfade to the wave once, then back to the idle when it ends. ```c /* once: loop 0, speed 1, from the start */ sona_play_options once = { 0, 1.0f, 0.0f }; sona_avatar_crossfade(avatar, "GenericWave", &once, 0.2f); sona_avatar_queue(avatar, "idle", NULL, 0.3f); ``` ```cpp // once: loop 0, speed 1, from the start sona_play_options once = sona::play_defaults(); once.loop = 0; avatar.crossfade("GenericWave", 0.2f, &once); avatar.queue("idle", 0.3f); ``` ```csharp // once, at speed 1, from the start avatar.Crossfade("GenericWave", 0.2f, loop: false); avatar.Queue("idle", 0.3f); ``` ```rust // once, at speed 1, from the start let once = PlayOptions { looped: false, ..Default::default() }; avatar.crossfade("GenericWave", &once, 0.2)?; avatar.queue("idle", &PlayOptions::default(), 0.3)?; ``` ```python # once, at speed 1, from the start avatar.crossfade("GenericWave", 0.2, loop=False) avatar.queue("idle", fade=0.3) ``` ## Cheer from a line of text The text-to-emote table picks stock clips and a face for a sentence ([guide](https://360sona.com/devs/docs/guides/emote.md)). ```c sona_emote e = { sizeof e }; if (sona_emote_from_text("jump for joy", &e) == SONA_OK && e.count > 0) sona_avatar_emote(avatar, &e, 0.25f); ``` ```cpp sona_emote e; if (sona::emote_from_text("jump for joy", e) == SONA_OK && e.count > 0) avatar.emote(e, 0.25f); ``` ```csharp var e = new Native.sona_emote { size = (uint)sizeof(Native.sona_emote) }; fixed (byte* text = System.Text.Encoding.UTF8.GetBytes("jump for joy\0")) if (Native.sona_emote_from_text(text, &e) == SonaResult.Ok && e.count > 0) Native.sona_avatar_emote(avatar.Handle, &e, 0.25f); // the binding's raw call ``` ```rust let e = emote_from_text("jump for joy")?; if e.count > 0 { avatar.emote(&e, 0.25)?; } ``` ```python e = sona.emote_from_text("jump for joy") if e["count"] > 0: avatar.emote(e, 0.25) ``` ## Look at the player The head turns and the eyes follow, inside the neck's limits. Call it each frame while the player moves. ```c sona_ik_look look; sona_ik_look_defaults(&look); look.target[0] = player_head[0]; look.target[1] = player_head[1]; look.target[2] = player_head[2]; sona_avatar_ik_look(avatar, &look); ``` ```cpp sona_ik_look look; sona_ik_look_defaults(&look); look.target[0] = player_head[0]; look.target[1] = player_head[1]; look.target[2] = player_head[2]; sona_avatar_ik_look(avatar.raw(), &look); // sona.hpp has no wrapper: the C call on the handle ``` ```csharp var look = SonaAvatar.IkLookDefaults(); look.target[0] = playerHead[0]; look.target[1] = playerHead[1]; look.target[2] = playerHead[2]; avatar.SetIkLook(look); ``` ```rust let mut look = ik_look_defaults(); look.target = player_head; avatar.set_ik_look(Some(&look))?; ``` ```python avatar.ik_look(target=player_head) ``` ## Walk to a spot `sona_avatar_move` eases the placement over the time given; the stock walk plays while it moves ([clips](https://360sona.com/devs/docs/guides/clips.md)). ```c sona_placement to = { { 2.0f, 0.0f, -3.0f }, 90.0f, 1.0f }; /* position, turn, scale */ sona_avatar_play_stock(avatar, SONA_STOCK_WALK_FORWARD, NULL, 0.25f); sona_avatar_move(avatar, &to, 2.5f); /* 2.5 s later, when it has arrived: */ sona_avatar_crossfade(avatar, "idle", NULL, 0.3f); ``` ```cpp const sona_placement to = { { 2.0f, 0.0f, -3.0f }, 90.0f, 1.0f }; // position, turn, scale sona_avatar_play_stock(avatar.raw(), SONA_STOCK_WALK_FORWARD, nullptr, 0.25f); avatar.move(to, 2.5f); // 2.5 s later, when it has arrived: avatar.crossfade("idle", 0.3f); ``` ```csharp avatar.PlayStock("walk_forward", 0.25f); avatar.Move(new SonaPlacement(2, 0, -3, turnDeg: 90), 2.5f); // position, turn, scale // 2.5 s later, when it has arrived: avatar.Crossfade("idle", 0.3f); ``` ```rust let walk = stock_clip_find("walk_forward").unwrap_or(0); avatar.play_stock(walk, None, 0.25)?; avatar.move_to(&Placement { position: [2.0, 0.0, -3.0], turn_deg: 90.0, scale: 1.0 }, 2.5); // 2.5 s later, when it has arrived: avatar.crossfade("idle", &PlayOptions::default(), 0.3)?; ``` ```python avatar.play_stock("walk_forward", fade=0.25) avatar.move((2, 0, -3), turn_deg=90, over_seconds=2.5) # 2.5 s later, when it has arrived: avatar.crossfade("idle", 0.3) ``` The walk loops, so it never ends by itself; switch back when the move is done, not with a queue. ## Hold something where the hand is Read a joint's world matrix each frame and put your object there; the matrix is row-vector, so the position is the last row. ```c float hand[16]; if (sona_joint_world(avatar, (uint32_t)sona_joint_find("RightHand"), hand) == SONA_OK) { float x = hand[12], y = hand[13], z = hand[14]; (void)x; (void)y; (void)z; /* your object's position */ } ``` ```cpp float hand[16]; int32_t joint = sona::joint_find("RightHand"); if (joint >= 0 && avatar.joint_world((uint32_t)joint, hand) == SONA_OK) { float x = hand[12], y = hand[13], z = hand[14]; // your object's position (void)x; (void)y; (void)z; } ``` ```csharp var hand = new float[16]; if (avatar.TryGetJointWorld(SonaJoints.Find("RightHand"), hand)) { float x = hand[12], y = hand[13], z = hand[14]; // your object's position } ``` ```rust if let Some(joint) = joint_find("RightHand") { let hand = avatar.joint_world(joint)?; let (x, y, z) = (hand[12], hand[13], hand[14]); // your object's position } ``` ```python hand = avatar.joint_world("RightHand") x, y, z = hand[12:15] # your object's position ``` For a real held item, the props API attaches a mesh to the hand and grips it ([props](https://360sona.com/devs/docs/guides/props.md)). ## A smile that holds Set the mouth and leave the rest of the face to the clip (255 means "the clip's"). ```c uint8_t face[5] = { 6, 255, 255, 255, 255 }; /* mouth 6 is happy; brows and eyes from the clip */ sona_avatar_expression(avatar, face); ``` ```cpp const uint8_t face[5] = { 6, 255, 255, 255, 255 }; // mouth 6 is happy; brows and eyes from the clip avatar.expression(face); ``` ```csharp avatar.SetExpression(6); // mouth 6 is happy; brows and eyes from the clip ``` ```rust avatar.set_expression(Some([6, 255, 255, 255, 255]))?; // mouth 6 is happy; brows and eyes from the clip ``` ```python avatar.expression([6, 255, 255, 255, 255]) # mouth 6 is happy; brows and eyes from the clip ``` ## High five Two avatars meet, their hands touch on the beat, and both go back to their idle ([guide](https://360sona.com/devs/docs/guides/interactions.md)). ```c sona_interaction_desc d; sona_interaction *it; sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE); d.a = avatar; d.b = other; if (sona_interaction_start(ctx, &d, &it) == SONA_OK) { /* each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) */ } ``` ```cpp sona_interaction_desc d; sona_interaction *it = nullptr; sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE); d.a = avatar.raw(); d.b = other.raw(); if (sona_interaction_start(ctx.raw(), &d, &it) == SONA_OK) { // each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) } ``` ```csharp var d = SonaContext.InteractionDefaults(Native.SONA_INTERACT_HIGH_FIVE); d.a = avatar.Handle; d.b = other.Handle; var it = ctx.StartInteraction(d); // each frame: it.Events(); when it ends, it.Dispose() ``` ```rust let mut d = interaction_defaults(sona_sys::SONA_INTERACT_HIGH_FIVE); d.a = avatar.raw(); d.b = other.raw(); let mut it = ctx.start_interaction(&d)?; // each frame: it.events(); dropping it removes it ``` ```python it = ctx.interaction("high_five", avatar, other) # each frame: it.events(); when it ends, it.remove() ``` ## A random extra Seeded, so the same seed always gives the same person; here in everyday clothes, never a costume ([guide](https://360sona.com/devs/docs/guides/makers.md)). ```c sona_catalogue *cat; sona_maker *mk; sona_random_options o; uint8_t manifest[SONA_MANIFEST_BYTES]; sona_avatar *extra; if (sona_catalogue_load(ctx, "sona-catalogue.bin", &cat) == SONA_OK && sona_maker_create(ctx, cat, &mk) == SONA_OK) { sona_random_defaults(&o); o.flags = SONA_RANDOM_NO_COSTUME; if (sona_make_random(mk, 42, &o, manifest, NULL) == SONA_OK) sona_avatar_add(ctx, manifest, NULL, &extra); sona_maker_free(mk); } ``` ```cpp sona::Catalogue cat("sona-catalogue.bin", &ctx); sona_maker *mk = nullptr; if (sona_maker_create(ctx.raw(), cat.raw(), &mk) == SONA_OK) { sona_random_options o; sona_random_defaults(&o); o.flags = SONA_RANDOM_NO_COSTUME; uint8_t made[SONA_MANIFEST_BYTES]; if (sona_make_random(mk, 42, &o, made, nullptr) == SONA_OK) { sona::Avatar extra = ctx.add(made); } sona_maker_free(mk); } ``` ```csharp using var cat = SonaCatalogue.Load("sona-catalogue.bin", ctx); using var mk = new SonaMaker(cat, ctx); var made = mk.Random(42, new SonaRandomOptions { Flags = Native.SONA_RANDOM_NO_COSTUME }); var extra = ctx.Add(made.Manifest); ``` ```rust let bytes = std::fs::read("sona-catalogue.bin").unwrap_or_default(); let cat = Catalogue::from_bytes(&bytes)?; let mk = Maker::new(&cat)?; let made = mk.random(42, &RandomOptions { flags: sona_sys::SONA_RANDOM_NO_COSTUME, ..Default::default() })?; let extra = ctx.add(&made.manifest, &AddOptions::default())?; ``` ```python cat = sona.Catalogue("sona-catalogue.bin", ctx) mk = sona.Maker(cat, ctx) made, info = mk.random(42, flags=1) # 1: SONA_RANDOM_NO_COSTUME extra = ctx.add(made) mk.close() ``` ## Remove an avatar when its player leaves ```c sona_avatar_remove(avatar); ``` ```cpp avatar.remove(); ``` ```csharp avatar.Remove(); ``` ```rust let extra = ctx.add(manifest, &AddOptions::default())?; extra.remove(); // or let it go out of scope: an avatar dropped is removed ``` ```python avatar.remove() ``` `sona_avatar_remove` frees what only that avatar used; do not use its handle again. --- Source: https://360sona.com/devs/docs/examples.md # Examples Every example here is a whole program in the SDK: its picture is what it draws, its code is cut from its source, and the page after it says how to build and run it. The programs are in your download (`samples/`, `starters/`, `templates/`) or beside the tutorials. ## One avatar, waving One avatar from its manifest, drawn with no window 1.5 seconds into a wave and saved as a PNG with the credit in it. The same program in each language. ### C ![hello.c's run, and the avatar.png it saved: an avatar mid-wave](https://360sona.com/devs/docs/img/one-tutorial-c.webp) ```c /* 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); ``` The whole program, `hello.c`, and how to build it: [your first avatar in C](https://360sona.com/devs/docs/tutorials/c.md). ### C++ ![hello.cpp's run, and the avatar.png it saved: an avatar mid-wave](https://360sona.com/devs/docs/img/one-tutorial-cpp.webp) ```cpp 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; ``` The whole program and its build: [your first avatar in C++](https://360sona.com/devs/docs/tutorials/cpp.md). ### C# ![Hello.cs's run, and the avatar.png it saved: an avatar mid-wave](https://360sona.com/devs/docs/img/one-tutorial-csharp.webp) ```csharp 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); ``` The whole program and its project: [your first avatar in C#](https://360sona.com/devs/docs/tutorials/csharp.md). ### Rust ![main.rs's run, and the avatar.png it saved: an avatar mid-wave](https://360sona.com/devs/docs/img/one-tutorial-rust.webp) ```rust // 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())?; ``` The whole program and its `Cargo.toml`: [your first avatar in Rust](https://360sona.com/devs/docs/tutorials/rust.md). ### Python ![hello.py's run, and the avatar.png it saved: an avatar mid-wave](https://360sona.com/devs/docs/img/one-tutorial-python.webp) ```python 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) ``` The whole program: [avatars as data in Python](https://360sona.com/devs/docs/tutorials/python.md). ## In an engine One avatar from a manifest file, waving, in each engine's own terms: a component on an object. ### Unity ```csharp void Start() { var avatar = new GameObject("Avatar").AddComponent(); avatar.manifestAsset = manifest; avatar.clip = "GenericWave"; } ``` `HelloAvatar.cs` is in the package's Components sample: [your first avatar in Unity](https://360sona.com/devs/docs/tutorials/unity.md). ### Godot ![The Godot demo's hello scene](https://360sona.com/devs/docs/img/godot-hello.webp) ```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)) ``` The addon's demo project, scene `hello`: [your first avatar in Godot](https://360sona.com/devs/docs/tutorials/godot.md). ### Unreal ```cpp AHelloAvatar::AHelloAvatar() { Avatar = CreateDefaultSubobject(TEXT("Avatar")); RootComponent = Avatar; Avatar->Clip = TEXT("GenericWave"); } ``` `AHelloAvatar` is in the starter project's module: [your first avatar in Unreal](https://360sona.com/devs/docs/tutorials/unreal.md). ## The plaza ![The plaza starter in C: costumed avatars walking about a plaza](https://360sona.com/devs/docs/img/starter-plaza.webp) Twelve avatars, every one a different costume, walking loops about a plaza. The same scene is a starter on every platform (C, C++, C#, Rust, Python, the web, Unity, Godot, Unreal and Android), the bare start of a game. ```c for (i = 0; i < (int)count; i++) { /* all start at once, each a little further into the walk */ sona_play_options po = { 1, 1, (float)i * 0.13f }; sona_avatar_play_stock(walkers[i].a, sona_stock_clip_find("walk_forward"), &po, 0); } ``` Each platform's starter and how to run it: [the plaza starter](https://360sona.com/devs/docs/tutorials/starter-plaza.md). ## A crowd on a web page ![The web crowd: a thousand different avatars on one canvas](https://360sona.com/devs/docs/img/web-crowd.webp) A thousand avatars in one canvas, each in one of 506 costumes on a face, hair and build of its own, standing out of step. ```js for (const f of crowd) f.avatar = sona.add(f.manifest, { position: f.at, turn: f.turn, clip: f.clip, startAt: 'random' }); ``` `examples/crowd.html` in the web download: [the web crowd template](https://360sona.com/devs/docs/tutorials/template-web-crowd.md). ## Templates Each template is a small game or tool to start from, built with CMake and run as it comes. ### Bot and server ![A gamerpic the bot template drew](https://360sona.com/devs/docs/img/template-bot-gamerpic.webp) Gamerpics and outfit cards over HTTP, for chat bots and sites: [the bot and server template](https://360sona.com/devs/docs/tutorials/template-bot.md). ### Lobby ![Two players in the lobby template](https://360sona.com/devs/docs/img/template-lobby.webp) Sign in with 360sona, the gamertag lookup, network sync and emotes with root motion: [the lobby template](https://360sona.com/devs/docs/tutorials/template-lobby.md). ### VTuber kit ![The VTuber kit's window](https://360sona.com/devs/docs/img/template-vtuber.webp) A webcam and a microphone drive the avatar's face, in a transparent window for OBS: [the VTuber kit](https://360sona.com/devs/docs/tutorials/template-vtuber.md). ### VR ![The VR template's mirror](https://360sona.com/devs/docs/img/template-vr-mirror.webp) OpenXR, a first-person body, a mirror and other players: [the VR template](https://360sona.com/devs/docs/tutorials/template-vr.md). ### C++ starter ![The C++ starter project](https://360sona.com/devs/docs/img/template-cpp-starter.webp) A project made by `sona project new`: your avatar and eleven others walking about a plaza, in C++: [the C++ starter project](https://360sona.com/devs/docs/tutorials/template-cpp-starter.md). ### NPC kit ![An NPC from the kit](https://360sona.com/devs/docs/img/npc-kit.webp) An avatar your game's agent drives: it says a line with lip sync, emotes what the words say and looks at the player: [the NPC kit](https://360sona.com/devs/docs/guides/npc.md). ## Looks and outputs ### Art styles ![Toon with an outline](https://360sona.com/devs/docs/img/styles-toon.webp) Toon, flat, silhouette and promo looks, each with or without an outline: [art styles](https://360sona.com/devs/docs/guides/styles.md). ### Lights and shadows ![Avatars under the SDK's lighting](https://360sona.com/devs/docs/img/lighting.webp) Lights, an environment and shadows, or your engine's own shadow map: [lighting](https://360sona.com/devs/docs/guides/lighting.md). ### Two avatars, one moment ![A high five](https://360sona.com/devs/docs/img/interact-five.webp) Hand holds, high fives, handshakes, hugs and seats, fitted to both bodies: [two-avatar interactions](https://360sona.com/devs/docs/guides/interactions.md). ### A sprite sheet ![A sprite sheet for a 2D game](https://360sona.com/devs/docs/img/sprite-sheet.webp) An avatar's clips as frames for a 2D game, with stickers and pixel art: [2D outputs](https://360sona.com/devs/docs/guides/sprites2d.md). ### A 3D print ![A print-ready avatar](https://360sona.com/devs/docs/img/print3d.webp) A posed avatar as one watertight solid, STL or 3MF with colour, on the CPU: [3D print](https://360sona.com/devs/docs/guides/print3d.md). ### An avatar in Blender ![An avatar imported into Blender](https://360sona.com/devs/docs/img/blender-import.webp) Rigged, with its clips, and exported back: [Blender](https://360sona.com/devs/docs/tutorials/blender.md). ### Ten thousand avatars ![A stadium of 10,000 different avatars](https://360sona.com/devs/docs/img/crowd-10000.webp) Every one different, with level of detail: [crowds](https://360sona.com/devs/docs/guides/crowd.md). More, one recipe a game moment: [the cookbook](https://360sona.com/devs/docs/cookbook.md). --- Source: https://360sona.com/devs/docs/reference.md # C API reference The reference for `include/sona.h` and the optional modules' headers (`sona_body.h`, `sona_track.h`, `sona_npc.h`, `sona_xr.h`, `sona_editor.h`, `sona_xsdk.h`), version 1.1 (`SONA_VERSION_MAJOR` 1, `SONA_VERSION_MINOR` 1), `SONA_ABI` 1. Every public function is listed once, under the part of the header that declares it, with its signature, its parameters, what it returns and its rules. Where this page and the header differ, the header wins. The same entries, with every struct and constant, are in [api/api.json](https://360sona.com/devs/docs/api/api.json) for tools. Conventions are the web SDK's: metres, Y up, left-handed, avatars face -Z at turn 0 and stand about 1.8 m tall. Matrices are row-major and row-vector (`v' = v * M`). ## Version This page is version 1.1.0 of the library: `sona_version()` returns `"1.1.0"`, and `SONA_ABI` is 1. 1.1 keeps every 1.0 call, struct and layout: a 1.0 host builds against the 1.1 header unchanged and draws the same, but for these: - **Pictures.** A new renderer starts with the web's quality defaults: 4 samples on a hardware GPU (1 on a software rasteriser), mip chains and coverage-preserving mips. `sona_renderer_set_quality` with `msaa` 1 and `flags` 0 draws without them. - **GL state.** With multisampling, GL and GLES also change the renderbuffer binding in `sona_draw` and `sona_snapshot`. Within 1.x nothing breaks for two minor versions ([the stable ABI](https://360sona.com/devs/docs/guides/abi.md)). [The changelog](https://360sona.com/devs/docs/changelog.md) lists every addition. --- ## Rules every function follows - **One owner thread.** All calls on one `sona_ctx`, and on its avatars and renderers, come from one thread at a time. The only exceptions are `sona_complete` and `sona_http_done`, which a source or an HTTP layer may call from any thread. - **Completed exactly once.** Every `sona_request` and every `sona_http_reply` is completed exactly once, and stays valid until then: after `cancel` (which only asks), and after `sona_close`. A source must complete every read it accepted, also after `cancel`, and the host must not unload a source's code until its reads are complete. - **Callbacks run on the owner thread.** The core calls a source's `read` and an HTTP layer's `send` only on the owner thread, inside `sona_open` or `sona_update`, so engines can start their own main-thread requests from them. - **No blocking I/O.** Work that needs bytes returns `SONA_PENDING` or moves an avatar through its states. Results arrive through `sona_update` and `sona_poll_event`. - **No allocation per frame.** After the first frames, `sona_update`, `sona_pose` and `sona_draw` do not allocate. Memory comes from the config's allocator and is counted against the budget. - **Pointer lifetime.** Pointers handed out (`sona_pose_data`, event strings, clip info) stay valid until the next `sona_update` on that ctx, unless a function says otherwise. - **Explicit padding.** Every public struct has explicit padding, so each field sits at its natural alignment on every ABI. `sona_struct_size` and `sona_struct_offset` let a binding check its mirror of every struct when it loads. ## Constants | Name | Value | Meaning | |---|---|---| | `SONA_VERSION_MAJOR`, `_MINOR`, `_PATCH` | 1, 1, 0 | The header's version | | `SONA_ABI` | 1 | Bumped when a public struct changes shape. Pass it in `sona_config.abi` | | `SONA_MANIFEST_BYTES` | 1000 | An AvatarDescription | | `SONA_JOINTS` | 72 | Palette slots; the avatar rig animates 71 | | `SONA_PALETTE_FLOATS` | 864 | 72 joints x 3 float4 | | `SONA_CB_FLOATS` | 896 | The HQ constant buffer: projection 0..15, shadow 16..31, palette from 32 | | `SONA_VERTEX_STRIDE` | 76 | The runtime vertex (see `sona_mesh`) | | `SONA_MAX_SOURCES` | 4 | Sources in one config | | `SONA_ID_CHARS` | 37 | An item id, `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`, plus NUL | | `SONA_JOINT_COUNT` | 72 | joint slots; joints 0..70 have names and matrices | | `SONA_QUEUE_MAX` | 8 | clips one avatar can have queued | | `SONA_CLIP_EVENT_MAX` | 32 | clip events held per avatar | | `SONA_MARK_MAX` | 16 | clip marks per avatar | | `SONA_MSAA_AUTO` | 0 | 4 samples on a hardware GPU, 1 on a software rasteriser | On Windows the library is a DLL: `SONA_API` is `dllimport` unless `SONA_STATIC` is defined. Elsewhere it marks default visibility. ## Results and errors `sona_result` is the return code of almost every call. `SONA_OK` is 0, `SONA_PENDING` is 1 (not finished; call again after `sona_update`), and every error is negative: | Code | Value | When | |---|---|---| | `SONA_E_UNSUPPORTED` | -1 | No usable backend, API version or feature | | `SONA_E_ORIGIN` | -2 | Web only; kept so codes line up with the web SDK | | `SONA_E_LICENCE` | -3 | The app has not accepted the SDK Licence, or the licence file is missing or bad | | `SONA_E_APP` | -4 | No such app, or it was turned off | | `SONA_E_GATE` | -5 | 360sona could not be reached | | `SONA_E_MANIFEST` | -6 | That avatar could not be read or built | | `SONA_E_CONTEXT` | -7 | The graphics device failed or was lost | | `SONA_E_READBACK` | -8 | A picture could not be read back | | `SONA_E_LIMIT` | -9 | Too many avatars or requests, over the daily use, or over the memory budget | | `SONA_E_DESTROYED` | -10 | The ctx, avatar or renderer is gone | | `SONA_E_PLATFORM` | -11 | This build is not licensed for this platform | | `SONA_E_BUILD` | -12 | This build was revoked; download a new one | | `SONA_E_ARGUMENT` | -13 | A bad argument | | `SONA_E_MEMORY` | -14 | The allocator returned NULL | | `SONA_E_NOT_FOUND` | -15 | No source has that asset | | `SONA_E_IO` | -16 | A source failed; a retry may work | | `SONA_E_CORRUPT` | -17 | Bytes did not decode | | `SONA_E_NOT_READY` | -18 | The avatar is not ready | | `SONA_E_UNIMPLEMENTED` | -19 | Not in this build | `sona_error_info` holds `code`, `message` and `fix`: what went wrong and what to do about it. ### sona_result_name ```c const char *sona_result_name(sona_result r); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_result` | A result code | - | **Returns** `const char *`. **Example** (also in [Troubleshooting and error codes](https://360sona.com/devs/docs/troubleshooting.md)): ```c sona_config_defaults(&cfg); /* then the licence and the sources */ sona_result r = sona_open(&cfg, &ctx); if (r != SONA_OK) { sona_error_info e = sona_last_error(NULL); fprintf(stderr, "%s (%d): %s\n %s\n", sona_result_name(r), (int)r, e.message, e.fix ? e.fix : ""); } ``` The name of a code (`"licence"`, `"gate"`, ...): the same words as the web SDK's `SonaError.code`. ### sona_last_error ```c sona_error_info sona_last_error(const sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | **Returns** `sona_error_info`. **Example** (also in [Troubleshooting and error codes](https://360sona.com/devs/docs/troubleshooting.md)): ```c sona_config_defaults(&cfg); /* then the licence and the sources */ sona_result r = sona_open(&cfg, &ctx); if (r != SONA_OK) { sona_error_info e = sona_last_error(NULL); fprintf(stderr, "%s (%d): %s\n %s\n", sona_result_name(r), (int)r, e.message, e.fix ? e.fix : ""); } ``` The last error on a ctx. Its strings live until the next error. ## Handles Every handle is an opaque pointer: its struct is not in the header, so a program holds it and passes it back, never reads into it or copies it. The library makes each one in the call that gives it out (through an out-parameter, the `**out` last argument) and frees it in the one call named below; nothing else frees it, and a handle is not used after that call. Calls on a `sona_ctx` and on everything made from it come from one thread at a time ([Rules every function follows](https://360sona.com/devs/docs/reference.md#rules-every-function-follows)). | Handle | What it is | Made by | Freed by | |---|---|---|---| | `sona_ctx` | The library's state: sources, caches, the clock, the job system | `sona_open` | `sona_close`, after the avatars and renderers made from it are freed | | `sona_avatar` | One avatar in a ctx | `sona_avatar_add`, `sona_avatar_add_base64`, `sona_avatar_add_state`, `sona_avatar_add_waiting`, `sona_item_preview_add` | `sona_avatar_remove` | | `sona_renderer` | A renderer on the host's device, or a headless one | `sona_renderer_create`, `sona_headless_renderer` | `sona_renderer_destroy` | | `sona_request` | One read in flight from a host-written source | the core, when it calls the source's `read` | the core, once the source calls `sona_complete` on it (exactly once) | | `sona_http_reply` | One request in flight on a host's HTTP layer | the core, when it calls the layer's `send` | the core, once the layer calls `sona_http_done` on it (exactly once; valid until then, even after `sona_close`) | | `sona_catalogue` | The offline catalogue, loaded | `sona_catalogue_load`, `sona_catalogue_load_memory` | `sona_catalogue_free` | | `sona_maker` | A catalogue's outfit rules, indexed for making avatars | `sona_maker_create` | `sona_maker_free` | | `sona_filter` | A content filter's rules | `sona_filter_create` | `sona_filter_free` | | `sona_blend_space` | A blend of clips by one or two values | `sona_blend_space_create` | `sona_blend_space_destroy` | | `sona_state_machine` | Clip states and the moves between them | `sona_state_machine_create` | `sona_state_machine_destroy` | | `sona_interaction` | Two avatars acting together | `sona_interaction_start` | `sona_interaction_remove` | | `sona_prop_mesh` | A stock prop's mesh, read for a host's own drawing | `sona_prop_mesh_stock` | `sona_prop_mesh_release` | | `sona_sheet` | A sprite sheet of a clip | `sona_sheet_render` | `sona_sheet_free` | | `sona_lipsync` | Mouth shapes from sound | `sona_lipsync_create` | `sona_lipsync_destroy` | | `sona_headless` | A renderer with no window, for pictures and video | `sona_headless_open` | `sona_headless_close` | | `sona_video` | A video or picture sequence being written | `sona_video_open` | `sona_video_finish` (also on an error) | | `sona_print` | A mesh for 3D printing | `sona_print_avatars`, `sona_print_triangles` | `sona_print_free` | | `sona_anim_file` | An animation file read for import | `sona_anim_file_open` | `sona_anim_file_free` | | `sona_players` | Players looked up by gamertag or id | `sona_players_open` | `sona_players_close` | | `sona_net_sender`, `sona_net_receiver` | One avatar's state sent over a network, and received | `sona_net_sender_create`, `sona_net_receiver_create` | `sona_net_sender_destroy`, `sona_net_receiver_destroy` | | `sona_recorder`, `sona_replay` | A recording of avatars' states, and its playback | `sona_recorder_create`, `sona_replay_open` | `sona_recorder_destroy`, `sona_replay_close` | | `sona_screen` | A ready-made screen: the quick creator or the wardrobe picker | `sona_quick_open`, `sona_wardrobe_open` | `sona_screen_destroy` (the avatars it shows, from `sona_screen_view_avatar`, are its own) | ## Host services: memory, jobs, logging `sona_allocator` holds `alloc(user, size, align)`, `free(user, ptr, size)` and `user`. `alloc` returns NULL on failure. All zero means `malloc` and `free`. `sona_budget` is the memory budget in bytes. Zero fields take the defaults. Caches evict idle entries, oldest first, to stay inside their share; if what is live does not fit, the avatar that needed more fails with `SONA_E_LIMIT`. | Field | Default | |---|---| | `total` | 0: no overall cap. Xbox 360 hosts should set it | | `assets` | 256 MiB of decoded items | | `clips` | 32 MiB of retained clip blocks | | `faces` | 64 MiB of baked face sheets, at most 512 sheets, as the web | | `source_cache` | 64 MiB of fetched container bytes, in memory only | | `gpu_idle` | 64 MiB of GPU objects no avatar uses any more, as the web | `sona_jobs` is a host job system: `{user, workers, run(user, fn, arg)}`. `run` runs `fn(arg)` once, on any thread; `workers` says how many run at once. The core hands it independent jobs (decode, face bake, build, skinning slices) and never waits on one inside a call that must not block. Log levels are `SONA_LOG_ERROR` (0), `SONA_LOG_WARN`, `SONA_LOG_INFO` and `SONA_LOG_DEBUG` (3), passed to `sona_config.log`. ## HTTP The core's network traffic (the gate source and the native check) goes through a `sona_http`, which holds `user` and `send(user, request, reply)`. `send` starts the request and returns; the layer finishes it later, from any thread, with `sona_http_done`. A `sona_http_request` holds `method` ("GET" or "POST"), `url`, `headers` (NULL-terminated "Name: value" strings, may be NULL), `body`, `body_len` and `timeout_ms`. A layer the host supplies sees every URL, header and answer in clear, the gate's session key included. ### sona_http_done ```c void sona_http_done(sona_http_reply *reply, int status, const void *body, size_t len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `reply` | `sona_http_reply *` | The reply the layer was handed | required | | `status` | `int` | The HTTP status; 0 or less when the request failed | - | | `body` | `const void *` | The reply's body | required | | `len` | `size_t` | How many bytes there are | - | **Returns** Nothing. Finishes one HTTP request. `status` is the HTTP status, or 0 when the request could not be made. The body is copied. Call it exactly once per reply; the reply stays valid until then, even after `sona_close`. May be called from any thread. ### sona_http_platform ```c const sona_http *sona_http_platform(void); ``` **Returns** `const sona_http *`. **Example**: ```c const sona_http * x_got = sona_http_platform(); printf("sona_http_platform: %s\n", x_got ? "a value" : "none"); ``` The platform's own layer: WinHTTP on Windows, libcurl loaded at run time on Linux, NSURLSession on Apple platforms. NULL where there is none (Xbox 360, WASM, Linux without libcurl): the host must then pass its own in `sona_config.http`. ## Asset sources A read asks for one of two kinds (`sona_read_kind`): - `SONA_READ_ASSET`: `name` is a lowercase item id in the 36-character form above. - `SONA_READ_DATA`: `name` is a data file: `"avatar-rig.json"`, `"ColorSets.json"`, `"irradiance-cube.csv"`, `"ssao/poisson_512x32_r8g8snorm.bin"` or `"bin/tocassetdependencies.bin"`. Container bytes are the file as stored: YTGR-wrapped, raw STRB, or an STFS package holding `asset_v2.bin`. A source is described by a `sona_source_desc {kind, location, custom}`: | Kind | `location` | |---|---| | `SONA_SOURCE_CUSTOM` | Unused; `custom` points at a host-written `sona_source` | | `SONA_SOURCE_GATE` | The gate base; NULL for 360sona's own. Not in the WASM build | | `SONA_SOURCE_DIR` | A folder of item files the user owns, laid out as the gate serves them. The core reads it and never writes to it | | `SONA_SOURCE_CONSOLE` | A Content root, such as `"uda0:/Content"` on an Xbox 360, or a PC path to a copied one | A host-written `sona_source` holds `user`, `read(user, kind, name, req)`, `cancel(user, req)` and `destroy(user)`. `read` starts a read and returns at once; the source finishes it, now or later, from any thread, with `sona_complete`. `cancel` is optional and only asks. `destroy` is optional and is called by `sona_close`. Sources are asked in order; the first that has an asset wins. Fetched bytes are cached in memory only, against `budget.source_cache`. ### sona_complete ```c void sona_complete(sona_request *req, sona_result status, const void *bytes, size_t len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `req` | `sona_request *` | The read request | required | | `status` | `sona_result` | `SONA_OK`, or why the read failed | - | | `bytes` | `const void *` | The file's bytes | required | | `len` | `size_t` | How many bytes there are | - | **Returns** Nothing. Finishes one read, exactly once, also after `cancel`; the request stays valid until then. `status` is one of: - `SONA_OK` with the bytes, which the core copies; - `SONA_E_NOT_FOUND` when the source has no such asset: the next source in the chain is asked; - `SONA_E_IO` when it failed: the read is retried later, as the web retries. May be called from any thread. ## The context `sona_config` holds everything `sona_open` needs: | Field | Meaning | |---|---| | `abi` | `SONA_ABI` | | `app_id` | NULL: the app id stamped into this build. Release builds refuse an id that differs from the stamp | | `licence`, `licence_len` | `sona-licence.json` from the download, as bytes. The WASM build has none | | `sources[SONA_MAX_SOURCES]`, `source_count` | Asked in order; the first that has an asset wins | | `http` | NULL: `sona_http_platform()` | | `allocator` | All zero: `malloc` and `free` | | `budget` | See `sona_budget` | | `worker_threads` | -1: cores - 1 (the default); 0: none, work runs inside `sona_update` | | `jobs` | When `.run` is set it replaces `worker_threads` | | `seed` | Idle and start-time randomness; 0: from the clock. A fixed seed makes runs repeatable | | `max_avatars` | Default 256, at most 16384 | | `build_budget_ms` | Building allowed per `sona_update`; default 6 | | `face_size` | 0: auto (512 up to 4 avatars, 256 up to 32, else 128); or 128, 256, 512 | | `flags` | `SONA_CFG_*`, below | | `log`, `log_user` | `log(user, level, msg)` | | `check_host` | NULL: `https://test.360sona.com`, the developer site, where the native check answers. Release builds accept only an `https://` host, and only a signed answer from 360sona opens the gate, so a proxy works but cannot stand in for the server | Flags: - `SONA_CFG_STILL_FACES`: one face per avatar (the web's `faces: "still"`). - `SONA_CFG_APP_BEHAVIOUR`: the app-faithful idle player with crossfades, instead of the web SDK's idle chooser. - `SONA_CFG_NO_CPU_SKIN`: never allocate CPU-skinned vertex buffers. ### sona_config_defaults ```c void sona_config_defaults(sona_config *cfg); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cfg` | `sona_config *` | The [`sona_config`](https://360sona.com/devs/docs/reference/fields.md#sona_config) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Signed releases, stamped downloads and revocation](https://360sona.com/devs/docs/guides/release.md)): ```c sona_config_defaults(&cfg); cfg.licence = licence; /* the bytes of sona-licence.json */ cfg.licence_len = licence_len; sona_result r = sona_open(&cfg, &ctx); ``` Sets `abi` and leaves everything else at its default. ### sona_open ```c sona_result sona_open(const sona_config *cfg, sona_ctx **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cfg` | `const sona_config *` | The configuration, a [`sona_config`](https://360sona.com/devs/docs/reference/fields.md#sona_config) | required | | `out` | `sona_ctx **` | Receives the new context | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_GATE`, `SONA_E_LICENCE`, `SONA_E_PLATFORM` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Signed releases, stamped downloads and revocation](https://360sona.com/devs/docs/guides/release.md)): ```c sona_config_defaults(&cfg); cfg.licence = licence; /* the bytes of sona-licence.json */ cfg.licence_len = licence_len; sona_result r = sona_open(&cfg, &ctx); ``` Opens a context. The licence file is checked at once: its signature, its app and build against the ones stamped into this library, and this library's platform in its list. A failure is `SONA_E_LICENCE` or `SONA_E_PLATFORM`, and no source opens. The native check with 360sona runs in the background, and gate reads wait for it. A failed check arrives as a `SONA_EVENT_ERROR` and turns the gate source off; a passed one as `SONA_EVENT_LICENCE_OK`. Over the daily use (`SONA_E_LIMIT`), the gate source stays off until the next UTC day. Local sources (dir and console) need only the licence file, work offline and are never counted: only reads that reach the gate count toward its caps (3,000 distinct items and 20,000 answers per ctx). If no source can give the avatar rig (`avatar-rig.json`), the ctx raises one `SONA_EVENT_ERROR` with `SONA_E_GATE` and its avatars fail with the same code. ### sona_close ```c void sona_close(sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | **Returns** Nothing. **Example** (also in [Getting started](https://360sona.com/devs/docs/getting-started.md)): ```c sona_avatar_remove(avatar); /* frees what only it used */ sona_renderer_destroy(renderer); /* before your device goes */ sona_close(ctx); ``` Closes a context. It calls `cancel` on every read in flight, then each source's `destroy`, and frees everything else. Reads still open are freed by their own completion, whose result is dropped. ### sona_app_id ```c const char *sona_app_id(const sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | **Returns** `const char *`. **Example**: ```c const char * x_got = sona_app_id(ctx); printf("sona_app_id: %s\n", x_got ? "a value" : "none"); ``` The app id this context runs as. ### sona_version ```c const char *sona_version(void); ``` **Returns** `const char *`. **Example** (also in [Installing](https://360sona.com/devs/docs/install.md)): ```c printf("sona %s on %s\n", sona_version(), sona_platform()); ``` The library's version, `"1.1.0"`. ### sona_platform ```c const char *sona_platform(void); ``` **Returns** `const char *`. **Example** (also in [Installing](https://360sona.com/devs/docs/install.md)): ```c printf("sona %s on %s\n", sona_version(), sona_platform()); ``` The binary platform id compiled into this library: `"windows-x64"`, `"linux-x64"`, `"linux-arm64"`, `"macos-arm64"`, `"macos-x64"`, `"ios-arm64"`, `"android-arm64"`, `"android-x64"`, `"xbox360"` or `"wasm"`. The licence file lists these ids. They are not the download names (`macos`, `unity`, ...): one download can hold several. ### sona_struct_size ```c uint32_t sona_struct_size(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | A public struct's name, such as `"sona_config"` | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_struct_size("sona_config"); printf("sona_struct_size: %lld\n", (long long)x_got); ``` `sizeof` a public struct by its name (`"sona_config"`, `"sona_pose_data"`, ...); 0 if unknown. ### sona_struct_offset ```c uint32_t sona_struct_offset(const char *struct_dot_field); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `struct_dot_field` | `const char *` | `"struct.field"` | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_struct_offset("example"); printf("sona_struct_offset: %lld\n", (long long)x_got); ``` `offsetof` a field, by `"struct.field"`: `"sona_manifest.xuid"`, `"sona_device_desc.u.vk.queue_family"`; `UINT32_MAX` if unknown. Bindings check the size of every struct and the offset of every field they mirror when they load, and refuse to run on a mismatch. ### sona_abi_query ```c sona_result sona_abi_query(sona_abi_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `out` | `sona_abi_info *` | Receives the [`sona_abi_info`](https://360sona.com/devs/docs/reference/fields.md#sona_abi_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The stable ABI and the deprecation policy](https://360sona.com/devs/docs/guides/abi.md)): ```c sona_abi_info i = { 0 }; i.size = sizeof i; if (sona_abi_query(&i) == SONA_OK && SONA_ABI >= i.oldest_abi && SONA_ABI <= i.abi) { /* this program, built against SONA_ABI, can use the library */ } ``` The ABI of the library that is loaded, for hosts and bindings that load it at run time: `abi` is its `SONA_ABI`, `oldest_abi` the oldest `SONA_ABI` a caller may be built against and still load it (nothing breaks for two minor versions), and its version as numbers. Set `out->size` first. ## Events A `sona_event` holds `type`, `avatar`, `code`, `message` and `fix`. `message` and `fix` are valid until the next `sona_poll_event`. | Type | Meaning | |---|---| | `SONA_EVENT_NONE` | Nothing | | `SONA_EVENT_READY` | An avatar is built and drawable (`avatar` is set) | | `SONA_EVENT_FAILED` | An avatar could not be built; `code` says why (`avatar` is set) | | `SONA_EVENT_ERROR` | Context-wide: licence, app, platform, build, limit, gate or context | | `SONA_EVENT_LICENCE_OK` | The native check passed | ### sona_poll_event ```c int sona_poll_event(sona_ctx *ctx, sona_event *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `out` | `sona_event *` | Receives the [`sona_event`](https://360sona.com/devs/docs/reference/fields.md#sona_event) | required | **Returns** `int`. **Example**: ```c sona_event x_event; memset(&x_event, 0, sizeof x_event); int x_got = sona_poll_event(ctx, &x_event); printf("sona_poll_event: %lld\n", (long long)x_got); ``` 1 when an event was written to `*out`, 0 when there are none. Call it in a loop after `sona_update`. ## Avatars An avatar moves through `SONA_AVATAR_QUEUED`, `LOADING`, `READY`, and ends in `FAILED` or `REMOVED`. `sona_placement` holds `position[3]` (metres, default 0, 0, 0), `turn_deg` (degrees about Y; 0 faces -Z) and `scale` (default 1). `sona_add_options`: | Field | Meaning | |---|---| | `place` | Where it stands | | `clip` | A clip key, a raw clip id, `"prop"`, `"idle"` or `"still"`; NULL: `"idle"` | | `loop` | Default 1 | | `speed` | Default 1 | | `start_at` | Seconds; negative means random, to desynchronise a crowd | | `visible` | Default 1 | | `priority` | Higher builds sooner; default 0 | `sona_play_options` holds `loop` (default 1), `speed` (default 1) and `from` (seconds into the clip, default 0). ### sona_add_defaults ```c void sona_add_defaults(sona_add_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_add_options *` | The [`sona_add_options`](https://360sona.com/devs/docs/reference/fields.md#sona_add_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Crowds: level of detail and sprites](https://360sona.com/devs/docs/guides/crowd.md)): ```c /* 10,000 avatars in rows round a pitch, facing in */ sona_lod_set(ctx, NULL); for (i = 0; i < 10000; i++) { sona_add_options o; sona_add_defaults(&o); seat(i, o.place.position, &o.place.turn_deg); /* your layout */ o.start_at = -1; /* random start: a crowd out of step */ sona_avatar_add_base64(ctx, looks[i % 12], &o, &av[i]); } ``` Fills `*o` with the defaults above. ### sona_avatar_add ```c sona_result sona_avatar_add(sona_ctx *ctx, const uint8_t manifest[SONA_MANIFEST_BYTES], const sona_add_options *opts, sona_avatar **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required | | `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](https://360sona.com/devs/docs/reference/fields.md#sona_add_options) | required | | `out` | `sona_avatar **` | Receives the new avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Untrusted files, long sessions and speed](https://360sona.com/devs/docs/guides/hardening.md)): ```c sona_manifest m; if (sona_manifest_parse(manifest, &m) != SONA_OK) /* any 1,000 bytes from a player */ puts("not an avatar"); /* SONA_E_MANIFEST */ else sona_avatar_add(ctx, manifest, NULL, &avatar); /* its items load through your sources */ ``` Queues an avatar and returns at once. A bad manifest does not fail here: the avatar moves to `FAILED` with `SONA_E_MANIFEST`, as the web's `add()` never throws for one. It fails at once only with `SONA_E_LIMIT` (over `max_avatars`) or `SONA_E_ARGUMENT`. ### sona_avatar_add_base64 ```c sona_result sona_avatar_add_base64(sona_ctx *ctx, const char *b64, const sona_add_options *opts, sona_avatar **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `b64` | `const char *` | The manifest as base64 text, at most 4096 characters | required | | `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](https://360sona.com/devs/docs/reference/fields.md#sona_add_options) | required | | `out` | `sona_avatar **` | Receives the new avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Getting started](https://360sona.com/devs/docs/getting-started.md)): ```c sona_avatar *avatar = NULL; sona_avatar_add_base64(ctx, b64, NULL, &avatar); /* b64: the manifest; returns at once */ sona_avatar_play(avatar, "GenericWave", NULL); /* remembered until it is ready */ ``` The same, from base64 text of at most 4096 characters, as the web. ### sona_avatar_state_of ```c sona_avatar_state sona_avatar_state_of(const sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | **Returns** `sona_avatar_state`. **Example** (also in [VR and XR bodies (sona_xr)](https://360sona.com/devs/docs/guides/xr.md)): ```c sona_xr_input in; sona_xr_input_defaults(&in); in.time = now; /* seconds, rising */ in.flags = SONA_XR_HAS_HEAD; /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */ in.head.position[0] = head_pos[0]; in.head.position[1] = head_pos[1]; in.head.position[2] = head_pos[2]; sona_xr_feed(xr, &in); if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar); sona_update(ctx, dt, &view, NULL); ``` The avatar's state. ### sona_avatar_id ```c uint32_t sona_avatar_id(const sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | **Returns** `uint32_t`. **Example** (also in [Lip sync: a microphone or any audio drives the mouth](https://360sona.com/devs/docs/guides/lipsync.md)): ```c sona_voice_mouth v[64]; for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i], sona_avatar_id(avatars[i])); /* each frame: */ uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt); ``` A number unique within the ctx. ### sona_avatar_play ```c sona_result sona_avatar_play(sona_avatar *a, const char *clip, const sona_play_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `clip` | `const char *` | A clip key or id | required | | `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](https://360sona.com/devs/docs/reference/fields.md#sona_play_options) | `NULL`: the defaults | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Getting started](https://360sona.com/devs/docs/getting-started.md)): ```c sona_avatar *avatar = NULL; sona_avatar_add_base64(ctx, b64, NULL, &avatar); /* b64: the manifest; returns at once */ sona_avatar_play(avatar, "GenericWave", NULL); /* remembered until it is ready */ ``` Plays a clip. Called before `READY`, it is remembered and applied when the avatar appears. NULL `opts` takes the defaults. Since 1.1 it also clears the clip queue, and returns `SONA_E_ARGUMENT` for an item preview. ### sona_avatar_stop ```c void sona_avatar_stop(sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. **Example** (also in [3D print export](https://360sona.com/devs/docs/guides/print3d.md)): ```c sona_play_options pl = { 0, 1.0f, 1.25f }; /* no loop, speed 1, from 1.25 s */ sona_avatar_play(a, "GenericWave", &pl); sona_update(ctx, 0, NULL, NULL); sona_avatar_stop(a); sona_update(ctx, 0, NULL, NULL); sona_print_avatars(&a, 1, &opts, &print); ``` Holds the current pose. ### sona_avatar_move ```c void sona_avatar_move(sona_avatar *a, const sona_placement *to, float over_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `to` | `const sona_placement *` | Where to stand, a [`sona_placement`](https://360sona.com/devs/docs/reference/fields.md#sona_placement) | required | | `over_seconds` | `float` | Seconds to ease over; 0: at once | `0`: at once | **Returns** Nothing. **Example** (also in [Getting started](https://360sona.com/devs/docs/getting-started.md)): ```c sona_placement to = { { 1.0f, 0.0f, -2.0f }, 90.0f, 1.0f }; sona_avatar_move(avatar, &to, 0.5f); /* over half a second */ sona_avatar_crossfade(avatar, "GenericWave", NULL, 0.2f); ``` Moves the avatar to a new placement over `over_seconds`. ### sona_avatar_set_visible ```c void sona_avatar_set_visible(sona_avatar *a, int visible); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `visible` | `int` | 1 drawn, 0 hidden | - | **Returns** Nothing. **Example**: ```c sona_avatar_set_visible(avatar, 1); ``` Shows or hides it. A hidden avatar is not drawn. It does nothing to an item preview, which `sona_draw` never draws. ### sona_avatar_bounds ```c void sona_avatar_bounds(const sona_avatar *a, float center[3], float *radius); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `center` | `float [3]` | Receives the centre of the bounding sphere, world space | required | | `radius` | `float *` | Receives the sphere's radius | required | **Returns** Nothing. A bounding sphere, in metres. ### sona_avatar_remove ```c void sona_avatar_remove(sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_avatar_remove(avatar); ``` Removes the avatar and frees what only it used. The handle must not be used afterwards. ## Game features Joints by name, pose overrides, clip crossfades and queues, a collision capsule, expressions, clip events and root motion. Like every avatar call they belong to the ctx's owner thread. Calls that return a `sona_result` give `SONA_E_ARGUMENT` for a NULL avatar or pointer. `sona_joint_world`, `sona_avatar_override`, `_queue`, `_capsule`, `_expression` and `_expression_counts` also give `SONA_E_DESTROYED` for an avatar that is being removed. `sona_capsule` holds `a[3]`, `b[3]` and `radius`: 28 bytes of floats, world metres. `sona_clip_event` holds `kind`, `mark`, `clip` and `time`, 16 bytes: | Field | Meaning | |---|---| | `kind` | `SONA_CLIP_STARTED` (1), `SONA_CLIP_LOOPED` (2), `SONA_CLIP_ENDED` (3), `SONA_CLIP_FOOT_LEFT` (4), `SONA_CLIP_FOOT_RIGHT` (5), `SONA_CLIP_MARK` (6) | | `mark` | The id given to `sona_avatar_mark`, for MARK events; else 0 | | `clip` | The `sona_clip_get` index of the clip; -1 for a prop's clip or a raw clip id | | `time` | Seconds into the clip | ### sona_joint_find ```c int32_t sona_joint_find(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | A joint's name | required | **Returns** `int32_t`. **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c sona_mask_preset(SONA_MASK_UPPER_BODY, m); sona_mask_branch(m, sona_joint_find("Spine"), 0.5f); /* half the wave in the spine ... */ sona_mask_branch(m, sona_joint_find("Chest"), 1.0f); /* ... all of it from the chest up */ ``` A joint's number from its name: a humanoid name (`Hips`, `Spine`, `Chest`, `Neck`, `Head`, `LeftUpperArm`, ... `PropLeft`, `PropRight`), `shape_NN` for a body-shape joint, or `joint_NN` for any joint by number. -1 when the name is unknown or NULL. ### sona_joint_name ```c const char *sona_joint_name(uint32_t joint); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - | **Returns** `const char *`. **Example**: ```c const char * x_got = sona_joint_name(0); printf("sona_joint_name: %s\n", x_got ? "a value" : "none"); ``` The name of joints 0 to 70: the humanoid name, or `shape_NN`. NULL past the last joint. The string is static. ### sona_joint_world ```c sona_result sona_joint_world(const sona_avatar *a, uint32_t joint, float out[16]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - | | `out` | `float [16]` | Receives a row-major 4x4 matrix | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c float hand[16]; if (sona_joint_world(avatar, (uint32_t)sona_joint_find("RightHand"), hand) == SONA_OK) { float x = hand[12], y = hand[13], z = hand[14]; (void)x; (void)y; (void)z; /* your object's position */ } ``` The joint's world matrix at the last `sona_update`: row-vector, metres, with the avatar's placement applied. `SONA_E_ARGUMENT` for a joint past 70. `SONA_E_NOT_READY` before the avatar is READY and posed. A sprite (see crowds) keeps the last pose computed before it became one. ### sona_avatar_override ```c sona_result sona_avatar_override(sona_avatar *a, uint32_t joint, const float rotation[4], float weight, uint32_t mode); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - | | `rotation` | `const float [4]` | A unit quaternion (x, y, z, w); NULL clears the joint | required | | `weight` | `float` | A weight from 0 to 1 | - | | `mode` | `uint32_t` | `SONA_OVERRIDE_REPLACE` or `SONA_OVERRIDE_ADD` | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c float x_rotation[4]; memset(x_rotation, 0, sizeof x_rotation); sona_result result = sona_avatar_override(avatar, 0, x_rotation, 0.5f, 0); if (result != SONA_OK) printf("sona_avatar_override: %s\n", sona_result_name(result)); ``` A rotation applied after the clip each frame, for look-at and aiming. `rotation` is a quaternion (x, y, z, w); it is normalised, and a zero or non-finite one is `SONA_E_ARGUMENT`. `mode` `SONA_OVERRIDE_REPLACE` (0) sets the joint's rotation from its rest orientation; `SONA_OVERRIDE_ADD` (1) rotates on top of the clip's. `weight` blends from the clip, 0 to 1 (above 1 counts as 1). A weight of 0 or a NULL `rotation` clears that joint. Joints the clip does not move are not affected while no clip plays. `SONA_E_ARGUMENT` for a joint past 70 or another mode. ### sona_avatar_clear_overrides ```c void sona_avatar_clear_overrides(sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. **Example**: ```c sona_avatar_clear_overrides(avatar); ``` Clears every override of the avatar. NULL is ignored. ### sona_avatar_crossfade ```c sona_result sona_avatar_crossfade(sona_avatar *a, const char *clip, const sona_play_options *opts, float seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `clip` | `const char *` | A clip key or id | required | | `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](https://360sona.com/devs/docs/reference/fields.md#sona_play_options) | required | | `seconds` | `float` | Seconds to blend from the current pose; 0: a cut | `0`: a cut | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Getting started](https://360sona.com/devs/docs/getting-started.md)): ```c sona_placement to = { { 1.0f, 0.0f, -2.0f }, 90.0f, 1.0f }; sona_avatar_move(avatar, &to, 0.5f); /* over half a second */ sona_avatar_crossfade(avatar, "GenericWave", NULL, 0.2f); ``` `sona_avatar_play`, blending from the current pose over `seconds`. 0, a negative or a non-finite value is a cut. It clears the queue. It returns what `sona_avatar_play` returns, so `SONA_E_ARGUMENT` for an item preview. ### sona_avatar_queue ```c sona_result sona_avatar_queue(sona_avatar *a, const char *clip, const sona_play_options *opts, float fade_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `clip` | `const char *` | A clip key or id | required | | `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](https://360sona.com/devs/docs/reference/fields.md#sona_play_options) | `NULL`: the defaults | | `fade_seconds` | `float` | Seconds to blend over | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_LIMIT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c /* once: loop 0, speed 1, from the start */ sona_play_options once = { 0, 1.0f, 0.0f }; sona_avatar_crossfade(avatar, "GenericWave", &once, 0.2f); sona_avatar_queue(avatar, "idle", NULL, 0.3f); ``` Plays `clip` when the current one ends, blending over `fade_seconds` (0: a cut). A looping clip never ends, so queue after a non-looping one. NULL `opts` takes the defaults. Up to `SONA_QUEUE_MAX` clips wait; `SONA_E_LIMIT` past that. `SONA_E_ARGUMENT` for a NULL or over-long clip name, or an item preview. `sona_avatar_play` and `sona_avatar_crossfade` clear the queue. ### sona_avatar_queued ```c uint32_t sona_avatar_queued(const sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_avatar_queued(avatar); printf("sona_avatar_queued: %lld\n", (long long)x_got); ``` How many clips are waiting in the queue. 0 for NULL. ### sona_avatar_capsule ```c sona_result sona_avatar_capsule(const sona_avatar *a, sona_capsule *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_capsule *` | Receives the [`sona_capsule`](https://360sona.com/devs/docs/reference/fields.md#sona_capsule) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_capsule x_capsule; memset(&x_capsule, 0, sizeof x_capsule); sona_result result = sona_avatar_capsule(avatar, &x_capsule); if (result != SONA_OK) printf("sona_avatar_capsule: %s\n", sona_result_name(result)); ``` A vertical capsule around the posed body, in world space, for collisions: the segment `a`..`b` and its `radius`, scaled with the avatar. `SONA_E_NOT_READY` before the avatar is READY and posed. ### sona_avatar_expression ```c sona_result sona_avatar_expression(sona_avatar *a, const uint8_t values[5]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `values` | `const uint8_t [5]` | The shape of the mouth, both eyebrows and both eyes; 255 leaves one as it is | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c uint8_t face[5] = { 6, 255, 255, 255, 255 }; /* mouth 6 is happy; brows and eyes from the clip */ sona_avatar_expression(avatar, face); ``` Sets the face. `values` are mouth, left eyebrow, right eyebrow, left eye, right eye, each a shape index (0 is the face's neutral shape) or 255 to leave that part as the clip has it. NULL hands the whole face back to the clip. The face texture is baked again when the shapes change; each combination is baked once and cached. `sona_pose_data.expression` reports what is shown. Mouth shapes 0 to 6 are moods: neutral, sad, angry, confused, laughing, shocked, happy. 7 to 13 are speech shapes for lip sync: `SONA_MOUTH_O` (7), `SONA_MOUTH_AI`, `SONA_MOUTH_EE`, `SONA_MOUTH_FV`, `SONA_MOUTH_W`, `SONA_MOUTH_L`, `SONA_MOUTH_DTH` (13). `SONA_MOUTH_NEUTRAL` is 0. A sprite does not show expressions. ### sona_avatar_expression_counts ```c sona_result sona_avatar_expression_counts(const sona_avatar *a, uint32_t counts[3]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `counts` | `uint32_t [3]` | Receives how many mouth, eyebrow and eye shapes the avatar has | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c uint32_t x_counts[3]; memset(x_counts, 0, sizeof x_counts); sona_result result = sona_avatar_expression_counts(avatar, x_counts); if (result != SONA_OK) printf("sona_avatar_expression_counts: %s\n", sona_result_name(result)); ``` How many shapes this face has: `counts[0]` mouth, `counts[1]` eyebrows, `counts[2]` eyes. 0 for a part the face lacks. `SONA_E_NOT_READY` before READY. ### sona_avatar_clip_events ```c uint32_t sona_avatar_clip_events(sona_avatar *a, sona_clip_event *out, uint32_t max); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `out` | `sona_clip_event *` | Receives the [`sona_clip_event`](https://360sona.com/devs/docs/reference/fields.md#sona_clip_event) | required | | `max` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example**: ```c sona_clip_event x_clip_event; memset(&x_clip_event, 0, sizeof x_clip_event); uint32_t x_got = sona_avatar_clip_events(avatar, &x_clip_event, 1); printf("sona_avatar_clip_events: %lld\n", (long long)x_got); ``` Moves up to `max` events into `out`, oldest first, and returns how many. They are what happened on the avatar's clip since the last call. 0 for NULL arguments or `max` 0. Footfalls come from the evaluated pose, so an avatar that is not posed (culled, a sprite, or not READY) has none. Up to `SONA_CLIP_EVENT_MAX` are held; past that the oldest go. ### sona_avatar_mark ```c sona_result sona_avatar_mark(sona_avatar *a, float seconds, uint32_t id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `seconds` | `float` | The clip time the mark sits at, seconds | - | | `id` | `uint32_t` | An id of your own, given back with the event | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_mark(avatar, 0.5f, 0); if (result != SONA_OK) printf("sona_avatar_mark: %s\n", sona_result_name(result)); ``` A MARK event with this `id` each time the current clip passes `seconds`. Marks go when another clip starts. `SONA_E_ARGUMENT` for a negative or NaN time; `SONA_E_LIMIT` past `SONA_MARK_MAX` marks. ### sona_avatar_clear_marks ```c void sona_avatar_clear_marks(sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. **Example**: ```c sona_avatar_clear_marks(avatar); ``` Removes the avatar's marks. NULL is ignored. ### sona_avatar_root_motion ```c sona_result sona_avatar_root_motion(sona_avatar *a, uint32_t mode); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `mode` | `uint32_t` | `SONA_ROOT_MOTION_OFF`, `_EXTRACT` or `_APPLY` | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c float upper[SONA_JOINT_COUNT]; sona_layer_options lo; sona_avatar_play(a, "00400000-0064-0003-c1c8-f109a19cb2e0", NULL); /* the stock walk */ sona_avatar_root_motion(a, SONA_ROOT_MOTION_EXTRACT); /* walk in place, the game moves the avatar */ sona_mask_preset(SONA_MASK_UPPER_BODY, upper); sona_layer_defaults(&lo); lo.mask = upper; sona_avatar_layer_play(a, 1, "GenericWave", &lo); /* layer 1: the wave, on Spine and above */ ``` What happens to the clip's sideways travel of the hips. `SONA_ROOT_MOTION_OFF` (0) leaves it in the pose. `SONA_ROOT_MOTION_EXTRACT` (1) holds the hips where the clip starts and collects the travel for `sona_avatar_take_root_motion`. `SONA_ROOT_MOTION_APPLY` (2) moves the avatar's placement by it each update. Setting a mode drops what was collected. `SONA_E_ARGUMENT` for another mode. ### sona_avatar_take_root_motion ```c sona_result sona_avatar_take_root_motion(sona_avatar *a, float delta[3]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `delta` | `float [3]` | Receives the root motion since the last call, world space | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c float x_delta[3]; memset(x_delta, 0, sizeof x_delta); sona_result result = sona_avatar_take_root_motion(avatar, x_delta); if (result != SONA_OK) printf("sona_avatar_take_root_motion: %s\n", sona_result_name(result)); ``` The travel collected since the last call, in world metres (the avatar's turn and scale applied), and clears it. ## Animation layers Section 3.8c of the header. The guide, with examples, the rules for root motion, threads and crowds, and the measured cost, is [Animation layers and states](https://360sona.com/devs/docs/guides/layers.md). New structs: `sona_layer_options` (48 bytes, 44 with 4-byte pointers), `sona_layer_info` (40), `sona_layer_event` (20), `sona_blend_sample` (24 / 16), `sona_blend_space_desc` (48 / 36), `sona_state_desc` (32 / 20), `sona_condition` (16 / 12), `sona_transition_desc` (96 / 72), `sona_state_machine_desc` (40 / 28), and the opaque `sona_blend_space` and `sona_state_machine`. Structs with a `size` field are filled from their `_defaults` call (or `size` set to `sizeof`); a smaller `size` is `SONA_E_ARGUMENT`. Every layer call returns `SONA_E_ARGUMENT` for a NULL avatar, a layer past `SONA_LAYER_MAX - 1` or an item preview, and `SONA_E_DESTROYED` for a removed one. ### sona_layer_defaults ```c void sona_layer_defaults(sona_layer_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_layer_options *` | The [`sona_layer_options`](https://360sona.com/devs/docs/reference/fields.md#sona_layer_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c float upper[SONA_JOINT_COUNT]; sona_layer_options lo; sona_avatar_play(a, "00400000-0064-0003-c1c8-f109a19cb2e0", NULL); /* the stock walk */ sona_avatar_root_motion(a, SONA_ROOT_MOTION_EXTRACT); /* walk in place, the game moves the avatar */ sona_mask_preset(SONA_MASK_UPPER_BODY, upper); sona_layer_defaults(&lo); lo.mask = upper; sona_avatar_layer_play(a, 1, "GenericWave", &lo); /* layer 1: the wave, on Spine and above */ ``` `size` set, `SONA_LAYER_OVERRIDE`, no flags, `loop` 1, `weight` 1, `fade_seconds` 0.2, `speed` 1, `from` 0, `additive_ref` 0, `mask` NULL. NULL is ignored. ### sona_avatar_layer_play ```c sona_result sona_avatar_layer_play(sona_avatar *a, uint32_t layer, const char *clip, const sona_layer_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `clip` | `const char *` | A clip key or id | required | | `opts` | `const sona_layer_options *` | The options, a [`sona_layer_options`](https://360sona.com/devs/docs/reference/fields.md#sona_layer_options) | `NULL`: the defaults | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c float upper[SONA_JOINT_COUNT]; sona_layer_options lo; sona_avatar_play(a, "00400000-0064-0003-c1c8-f109a19cb2e0", NULL); /* the stock walk */ sona_avatar_root_motion(a, SONA_ROOT_MOTION_EXTRACT); /* walk in place, the game moves the avatar */ sona_mask_preset(SONA_MASK_UPPER_BODY, upper); sona_layer_defaults(&lo); lo.mask = upper; sona_avatar_layer_play(a, 1, "GenericWave", &lo); /* layer 1: the wave, on Spine and above */ ``` Plays a clip key or raw clip id on the layer, crossfading from what it showed over `fade_seconds`. NULL `opts`: the defaults. `SONA_E_ARGUMENT` also for `"idle"`, `"still"`, `"prop"`, an unknown key and an option out of range (`weight` outside 0..1, a negative or NaN time or speed, a mask weight outside 0..1). Changing between OVERRIDE and ADDITIVE cuts instead of crossfading. ### sona_avatar_layer_blend ```c sona_result sona_avatar_layer_blend(sona_avatar *a, uint32_t layer, sona_blend_space *b, const sona_layer_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `b` | `sona_blend_space *` | The blend space | required | | `opts` | `const sona_layer_options *` | The options, a [`sona_layer_options`](https://360sona.com/devs/docs/reference/fields.md#sona_layer_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c sona_blend_sample s[3] = { { "Stand0", 0.0f, 0, 1 }, /* clip, x, y, playback rate */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 }, /* walk */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */ }; sona_blend_space_desc d; sona_blend_space *move; sona_blend_space_defaults(&d); d.param_x = "speed"; d.samples = s; d.sample_count = 3; sona_blend_space_create(ctx, &d, &move); sona_avatar_layer_blend(a, 0, move, NULL); sona_blend_space_destroy(move); /* the avatar keeps it while it plays */ ``` Plays a blend space of the same ctx on the layer. `from` is the fraction 0..1 of its shared cycle (seconds with `SONA_BLEND_UNSYNCED`). ### sona_avatar_layer_machine ```c sona_result sona_avatar_layer_machine(sona_avatar *a, uint32_t layer, sona_state_machine *m, const sona_layer_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `m` | `sona_state_machine *` | The state machine | required | | `opts` | `const sona_layer_options *` | The options, a [`sona_layer_options`](https://360sona.com/devs/docs/reference/fields.md#sona_layer_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Runs a state machine of the same ctx on the layer from its initial state (a `STATE` event with `from_state` -1). `speed` scales every state's speed; each state says whether it loops. ### sona_avatar_layer_goto ```c sona_result sona_avatar_layer_goto(sona_avatar *a, uint32_t layer, uint32_t state, float fade_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `state` | `uint32_t` | A state's index | - | | `fade_seconds` | `float` | Seconds to blend over | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_layer_goto(avatar, 0, 0, 0.5f); if (result != SONA_OK) printf("sona_avatar_layer_goto: %s\n", sona_result_name(result)); ``` Sends a machine layer to `state` now, crossfading over `fade_seconds`. `SONA_E_ARGUMENT` when the layer runs no machine or the state is past its last. ### sona_avatar_layer_weight ```c sona_result sona_avatar_layer_weight(sona_avatar *a, uint32_t layer, float weight, float over_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `weight` | `float` | A weight from 0 to 1 | - | | `over_seconds` | `float` | Seconds to ease over; 0: at once | `0`: at once | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_layer_weight(avatar, 0, 0.5f, 0.5f); if (result != SONA_OK) printf("sona_avatar_layer_weight: %s\n", sona_result_name(result)); ``` Moves the layer's weight linearly to `weight` (0..1) over `over_seconds`; 0 or less sets it at once. ### sona_avatar_layer_mask ```c sona_result sona_avatar_layer_mask(sona_avatar *a, uint32_t layer, const float *mask); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `mask` | `const float *` | A weight per joint, `SONA_JOINT_COUNT` of them; NULL: the whole body | `NULL`: the whole body | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Copies `SONA_JOINT_COUNT` weights (each 0..1); NULL is every joint. Takes effect at the next pose. ### sona_avatar_layer_stop ```c sona_result sona_avatar_layer_stop(sona_avatar *a, uint32_t layer, float fade_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `fade_seconds` | `float` | Seconds to blend over | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_layer_stop(avatar, 0, 0.5f); if (result != SONA_OK) printf("sona_avatar_layer_stop: %s\n", sona_result_name(result)); ``` Fades the layer out over `fade_seconds` and then empties it (a `STOPPED` event); 0 empties it now. An empty layer is `SONA_OK`. ### sona_avatar_layer_info ```c sona_result sona_avatar_layer_info(const sona_avatar *a, uint32_t layer, sona_layer_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `layer` | `uint32_t` | A layer index, from 1 (0 is the base clip) | - | | `out` | `sona_layer_info *` | Receives the [`sona_layer_info`](https://360sona.com/devs/docs/reference/fields.md#sona_layer_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_layer_info x_layer_info; memset(&x_layer_info, 0, sizeof x_layer_info); x_layer_info.size = sizeof x_layer_info; sona_result result = sona_avatar_layer_info(avatar, 0, &x_layer_info); if (result != SONA_OK) printf("sona_avatar_layer_info: %s\n", sona_result_name(result)); ``` The layer now: `kind`, `mode`, `state` (machines, else -1), `clip` (the `sona_clip_get` index, -1 for a raw id), `weight` with fades, `time` and `normalized` through the clip or cycle, `ready` (its clips have loaded) and `fading`. The caller sets `out->size`. ### sona_avatar_layer_events ```c uint32_t sona_avatar_layer_events(sona_avatar *a, sona_layer_event *out, uint32_t max); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `out` | `sona_layer_event *` | Receives the [`sona_layer_event`](https://360sona.com/devs/docs/reference/fields.md#sona_layer_event) | required | | `max` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example**: ```c sona_layer_event x_layer_event; memset(&x_layer_event, 0, sizeof x_layer_event); uint32_t x_got = sona_avatar_layer_events(avatar, &x_layer_event, 1); printf("sona_avatar_layer_events: %lld\n", (long long)x_got); ``` Moves up to `max` events, oldest first, into `out` and returns how many: `STARTED`, `LOOPED`, `ENDED`, `STATE`, `STOPPED`, each with its `layer`, `state` and `from_state` (machines; else -1) and `time` (seconds into the clip). Up to `SONA_LAYER_EVENT_MAX` are held; past that the oldest go. ### sona_mask_preset ```c sona_result sona_mask_preset(uint32_t preset, float mask[SONA_JOINT_COUNT]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `preset` | `uint32_t` | Which preset, one of the header's constants for it | - | | `mask` | `float [SONA_JOINT_COUNT]` | Receives a weight per joint | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c sona_mask_preset(SONA_MASK_UPPER_BODY, m); sona_mask_branch(m, sona_joint_find("Spine"), 0.5f); /* half the wave in the spine ... */ sona_mask_branch(m, sona_joint_find("Chest"), 1.0f); /* ... all of it from the chest up */ ``` Fills a mask: `SONA_MASK_NONE`, `_FULL`, `_UPPER_BODY` (Spine and below it), `_LOWER_BODY` (the hips and legs), `_HEAD` (from the Neck), `_LEFT_ARM`, `_RIGHT_ARM`, `_ARMS` (from the shoulders). Joint 71 is always 0. ### sona_mask_branch ```c sona_result sona_mask_branch(float mask[SONA_JOINT_COUNT], uint32_t joint, float weight); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mask` | `float [SONA_JOINT_COUNT]` | Receives a weight per joint | required | | `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - | | `weight` | `float` | A weight from 0 to 1 | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c sona_mask_preset(SONA_MASK_UPPER_BODY, m); sona_mask_branch(m, sona_joint_find("Spine"), 0.5f); /* half the wave in the spine ... */ sona_mask_branch(m, sona_joint_find("Chest"), 1.0f); /* ... all of it from the chest up */ ``` Sets `joint` and every joint below it in the rig to `weight` (0..1); the rest is kept. ### sona_param_id ```c int32_t sona_param_id(sona_ctx *ctx, const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `name` | `const char *` | A parameter's name, 1 to 31 bytes | required | **Returns** `int32_t`. **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c int32_t speed = sona_param_id(ctx, "speed"); /* 0 */ int32_t turn = sona_param_id(ctx, "turn"); /* 1 */ /* ... */ float p[2] = { player_speed, player_turn }; sona_avatar_set_params(a, 0, p, 2); /* each frame, before sona_update */ ``` The id of a parameter name (1 to 31 bytes), made on first use and numbered from 0 in that order; -1 for a bad name or past `SONA_PARAM_MAX` (32) names. ### sona_avatar_set_param ```c sona_result sona_avatar_set_param(sona_avatar *a, int32_t param, float value); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `param` | `int32_t` | A parameter id, from `sona_param_id` | - | | `value` | `float` | The value to set | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_set_param(avatar, 0, 0.5f); if (result != SONA_OK) printf("sona_avatar_set_param: %s\n", sona_result_name(result)); ``` Sets one parameter on the avatar; read at the next `sona_update`. `SONA_E_ARGUMENT` for an id outside 0..31 or a value that is not finite. ### sona_avatar_set_params ```c sona_result sona_avatar_set_params(sona_avatar *a, uint32_t first, const float *values, uint32_t count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `first` | `uint32_t` | The id of the first parameter to set | - | | `values` | `const float *` | The values, `count` of them | required | | `count` | `uint32_t` | How many entries the array holds | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c int32_t speed = sona_param_id(ctx, "speed"); /* 0 */ int32_t turn = sona_param_id(ctx, "turn"); /* 1 */ /* ... */ float p[2] = { player_speed, player_turn }; sona_avatar_set_params(a, 0, p, 2); /* each frame, before sona_update */ ``` Sets parameters `first .. first + count - 1`: a game's one call a frame. Nothing is set when any value is not finite or the range passes `SONA_PARAM_MAX`. ### sona_avatar_param ```c float sona_avatar_param(const sona_avatar *a, int32_t param); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `param` | `int32_t` | A parameter id, from `sona_param_id` | - | **Returns** `float`. **Example**: ```c float x_got = sona_avatar_param(avatar, 0); printf("sona_avatar_param: %g\n", (double)x_got); ``` A parameter's value; 0 when unset or unknown. Triggers read 0 once their transition fired. ### sona_blend_space_defaults ```c void sona_blend_space_defaults(sona_blend_space_desc *d); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `d` | `sona_blend_space_desc *` | The [`sona_blend_space_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_blend_space_desc) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c sona_blend_sample s[3] = { { "Stand0", 0.0f, 0, 1 }, /* clip, x, y, playback rate */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 }, /* walk */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */ }; sona_blend_space_desc d; sona_blend_space *move; sona_blend_space_defaults(&d); d.param_x = "speed"; d.samples = s; d.sample_count = 3; sona_blend_space_create(ctx, &d, &move); sona_avatar_layer_blend(a, 0, move, NULL); sona_blend_space_destroy(move); /* the avatar keeps it while it plays */ ``` `size` set, `dims` 1, no samples, `smooth_seconds` 0.1. ### sona_blend_space_create ```c sona_result sona_blend_space_create(sona_ctx *ctx, const sona_blend_space_desc *d, sona_blend_space **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `d` | `const sona_blend_space_desc *` | The options, a [`sona_blend_space_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_blend_space_desc) | required | | `out` | `sona_blend_space **` | Receives the new blend space | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c sona_blend_sample s[3] = { { "Stand0", 0.0f, 0, 1 }, /* clip, x, y, playback rate */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 }, /* walk */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */ }; sona_blend_space_desc d; sona_blend_space *move; sona_blend_space_defaults(&d); d.param_x = "speed"; d.samples = s; d.sample_count = 3; sona_blend_space_create(ctx, &d, &move); sona_avatar_layer_blend(a, 0, move, NULL); sona_blend_space_destroy(move); /* the avatar keeps it while it plays */ ``` Checks and copies the desc and starts loading its clips. `SONA_E_ARGUMENT`, with the bad sample named in `sona_last_error`: `dims` not 1 or 2, 0 or over 16 samples, a missing parameter name, a clip that is not a key or id, two samples at one point, a negative or NaN value. 2D samples are triangulated here. ### sona_blend_space_destroy ```c void sona_blend_space_destroy(sona_blend_space *b); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `b` | `sona_blend_space *` | The blend space | required | **Returns** Nothing. **Example** (also in [Animation layers, masks, blend spaces and state machines](https://360sona.com/devs/docs/guides/layers.md)): ```c sona_blend_sample s[3] = { { "Stand0", 0.0f, 0, 1 }, /* clip, x, y, playback rate */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 1.2f, 0, 1 }, /* walk */ { "00400000-0064-0003-c1c8-f109a19cb2e0", 2.4f, 0, 1.9f }, /* the walk played fast as a run */ }; sona_blend_space_desc d; sona_blend_space *move; sona_blend_space_defaults(&d); d.param_x = "speed"; d.samples = s; d.sample_count = 3; sona_blend_space_create(ctx, &d, &move); sona_avatar_layer_blend(a, 0, move, NULL); sona_blend_space_destroy(move); /* the avatar keeps it while it plays */ ``` Lets go of the host's handle. Avatars and states that play it keep it until they stop; `sona_close` frees the rest. ### sona_blend_space_weights ```c uint32_t sona_blend_space_weights(const sona_blend_space *b, float x, float y, float *weights); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `b` | `const sona_blend_space *` | The blend space | required | | `x` | `float` | The blend space's first input | - | | `y` | `float` | The blend space's second input | - | | `weights` | `float *` | Receives a weight per sample | required | **Returns** `uint32_t`. Writes each sample's weight at `(x, y)` (they sum to 1; `y` is ignored in 1D) and returns how many are above 0 (1 to 3). 0 for a NULL argument or a NaN point. ### sona_state_machine_defaults ```c void sona_state_machine_defaults(sona_state_machine_desc *d); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `d` | `sona_state_machine_desc *` | The [`sona_state_machine_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_state_machine_desc) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_state_machine_desc x_state_machine_desc; memset(&x_state_machine_desc, 0, sizeof x_state_machine_desc); x_state_machine_desc.size = sizeof x_state_machine_desc; sona_state_machine_defaults(&x_state_machine_desc); ``` `size` set, everything else zero. ### sona_state_machine_create ```c sona_result sona_state_machine_create(sona_ctx *ctx, const sona_state_machine_desc *d, sona_state_machine **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `d` | `const sona_state_machine_desc *` | The options, a [`sona_state_machine_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_state_machine_desc) | required | | `out` | `sona_state_machine **` | Receives the new state machine | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Resolves every name to an index once. `SONA_E_ARGUMENT`, naming the state, transition or condition in `sona_last_error`: 0 or over 32 states, over 64 transitions, a state name that is empty, over 31 bytes or used twice, a state with both or neither of a clip and a blend space, a transition naming an unknown state, a negative fade, more than 4 conditions, an unknown op, a bad parameter name, a value that is not finite, an unknown initial state. ### sona_state_machine_destroy ```c void sona_state_machine_destroy(sona_state_machine *m); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `sona_state_machine *` | The state machine | required | **Returns** Nothing. As `sona_blend_space_destroy`. ### sona_state_machine_find ```c int32_t sona_state_machine_find(const sona_state_machine *m, const char *state); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `const sona_state_machine *` | The state machine | required | | `state` | `const char *` | A state's name | required | **Returns** `int32_t`. A state's index by name, -1 if unknown. ### sona_state_machine_state_name ```c const char *sona_state_machine_state_name(const sona_state_machine *m, uint32_t state); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `const sona_state_machine *` | The state machine | required | | `state` | `uint32_t` | A state's index | - | **Returns** `const char *`. A state's name, NULL past the last. Valid while the machine lives. ## Clips `sona_clip_info` holds `key` ("GenericWave", "Stand0", ...), `id` (the clip's item id, or NULL for "idle", "still" and "prop"), `seconds` (negative when not known until decoded), `prop` (1 for the held prop's own clip) and `caption` (may be NULL). ### sona_clip_count ```c uint32_t sona_clip_count(const sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_clip_count(ctx); printf("sona_clip_count: %lld\n", (long long)x_got); ``` How many clips the context knows. ### sona_clip_get ```c sona_result sona_clip_get(const sona_ctx *ctx, uint32_t index, sona_clip_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `index` | `uint32_t` | Which one, from 0 | - | | `out` | `sona_clip_info *` | Receives the [`sona_clip_info`](https://360sona.com/devs/docs/reference/fields.md#sona_clip_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_clip_info x_clip_info; memset(&x_clip_info, 0, sizeof x_clip_info); sona_result result = sona_clip_get(ctx, 0, &x_clip_info); if (result != SONA_OK) printf("sona_clip_get: %s\n", sona_result_name(result)); ``` One clip by index, `0 .. sona_clip_count() - 1`. ## The frame `sona_view` holds doubles, as the JavaScript keeps plain numbers: the camera maths runs in double and stores float matrices only at the end. | Field | Meaning | |---|---| | `eye[3]`, `target[3]` | Up is always +Y (look-at, left-handed), as the web camera | | `fov_deg` | Vertical field of view in degrees; default 28.65, as the web | | `near_z` | Default 0.05 | | `far_z` | Default 200 (the web SDK's; the editor uses 20) | | `width`, `height` | The target size in pixels, for LOD and culling | `sona_frame_stats` reports one update: `ms` (the dt passed in), `cpu_ms` (time inside `sona_update`), `drawn`, `culled`, `draw_calls` (main-pass draws of the last `sona_draw`) and `built` (build steps run). `sona_scene_stats` is the running picture, as the web's `stats()`: `fps`, `ms_per_frame`, `p95_ms`, `cpu_ms_per_frame`, `avatars`, `ready`, `queued`, `drawn`, `draw_calls`, `geometries`, `textures`, `gpu_mb`, `cpu_mb`, `build_ms_avg`, `build_ms_max`, and `long_frames` (frames over the 33.4 ms threshold, counted over a window set to 2 s). ### sona_view_defaults ```c void sona_view_defaults(sona_view *v); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `v` | `sona_view *` | The [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); sona_view_defaults(&x_view); ``` The web's full-body framing. ### sona_update ```c sona_result sona_update(sona_ctx *ctx, double dt_seconds, const sona_view *view, sona_frame_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `dt_seconds` | `double` | Seconds since the last update | - | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | `NULL` allowed (below) | | `out` | `sona_frame_stats *` | Receives the [`sona_frame_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_frame_stats) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_IO`, `SONA_E_GATE` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The NPC kit (sona_npc)](https://360sona.com/devs/docs/guides/npc.md)): ```c sona_npc_update(npc, dt); sona_update(ctx, dt, NULL, NULL); sona_npc_state st; st.size = sizeof st; sona_npc_state_get(npc, &st); /* SONA_NPC_IDLE, _SPEAKING (st.line), _EMOTING; st.queued */ ``` Advances every avatar by `dt_seconds` (clamped to 0..0.1 s, as the web), runs build steps inside the build budget, culls against the view and poses what is due (the web's LOD rules). It also drains finished reads and jobs. `view` may be NULL: then nothing is culled and every avatar poses every frame. The view is used only for culling and LOD; palettes are folded with each draw's own view in `sona_draw` and `sona_snapshot`. ### sona_stats ```c void sona_stats(const sona_ctx *ctx, sona_scene_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `out` | `sona_scene_stats *` | Receives the [`sona_scene_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_scene_stats) | required | **Returns** Nothing. **Example**: ```c sona_scene_stats x_scene_stats; memset(&x_scene_stats, 0, sizeof x_scene_stats); sona_stats(ctx, &x_scene_stats); ``` Fills `*out` with the scene statistics. ## Crowds: level of detail and sprites The guide, with the measured stadium numbers, is [Crowds](https://360sona.com/devs/docs/guides/crowd.md). Each `sona_update` with a view gives every avatar in view a step from its height on screen in pixels: | Step | When | Posed | Drawn as | |---|---|---|---| | `SONA_LOD_FULL` (0) | at or above `full_px` | every frame | its meshes | | `SONA_LOD_SAMPLED` (1) | from `quarter_px` up to `full_px` | when the clip reaches a new frame | its meshes | | `SONA_LOD_QUARTER` (2) | below `quarter_px` | as SAMPLED, and at most every 4th frame | its meshes | | `SONA_LOD_SPRITE` (3) | below `sprite_px`, its look baked | never | one textured quad | A sprite is a picture of the avatar, baked once per look (the manifest's bytes) and turn. Avatars cross between mesh and sprite over `fade_seconds`. A ctx opens with sprites off (`sprite_px` 0) and thresholds 120 and 40 until `sona_lod_set`. `sona_lod_options`, 32 bytes: | Field | Range | Default | Meaning | |---|---|---|---| | `full_px` | `>= quarter_px` | 120 | At or above: FULL | | `quarter_px` | `0 .. full_px` | 40 | Below: QUARTER | | `sprite_px` | `>= 0` | 48 | Below: SPRITE. 0: never | | `fade_seconds` | `0 .. 10` | 0.25 | The mesh-to-sprite crossfade; 0 is a cut | | `sprite_angles` | `4 .. 32` | 8 | Turns baked per look | | `sprite_height` | `32 .. 512`, even | 64 | Pixels per baked picture; half as wide | | `max_looks` | `1 .. 65536` | 16384 | Baked looks kept per renderer; avatars past it stay meshes | | `bake_ms` | `>= 0` | 4 | Baking time per `sona_draw`; at least one batch of looks is baked when one is needed | `sprite_angles * sprite_height / 2` must be 4096 or less. `sona_lod_stats`, 32 bytes: `full`, `sampled`, `quarter`, `sprite` (avatars in view per step at the last `sona_update`), `fading` (of those, crossing between a mesh and a sprite), `looks` (baked looks over every renderer), `bakes` (looks baked by the last `sona_draw` or `sona_snapshot`), `bake_ms` (the time those took). Rules for sprites: - **Bakes happen inside `sona_draw` and `sona_snapshot`,** straight into the renderer's atlas pages. `sona_draw` records the bake into the host's frame, ahead of the picture (on Vulkan into the target's command buffer: nothing is submitted and nothing waits); a draw that bakes uses two frame indices. `sona_snapshot` bakes through the backend's readback, as it draws. - **Sheets belong to a renderer.** An avatar becomes a sprite only when every renderer that drew it since the last `sona_update` has its look baked. While a renderer without sprites draws the ctx, far avatars stay meshes on every renderer, and no renderer ever loses an avatar. - **Backends.** Vulkan, GL and GLES draw sprites. D3D11, D3D12, Metal and Xenos do not; far avatars stay meshes at the QUARTER rate there. - **The bake must fit the device.** One look's sheet is `sprite_angles * (h / 2 + 2 * (h / 16))` pixels wide and `h + 2 * (h / 16)` tall (`h` = `sprite_height`), and a bake pass holds up to 32 sheets in a column. A device whose largest texture is smaller bakes fewer looks a pass; one that cannot fit a sheet draws no sprites. ### sona_lod_defaults ```c void sona_lod_defaults(sona_lod_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_lod_options *` | The [`sona_lod_options`](https://360sona.com/devs/docs/reference/fields.md#sona_lod_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_lod_options x_lod_options; memset(&x_lod_options, 0, sizeof x_lod_options); sona_lod_defaults(&x_lod_options); ``` Writes the defaults in the table above, with sprites on at 48 px. NULL is ignored. ### sona_lod_set ```c sona_result sona_lod_set(sona_ctx *ctx, const sona_lod_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_lod_options *` | The options, a [`sona_lod_options`](https://360sona.com/devs/docs/reference/fields.md#sona_lod_options) | `NULL`: the defaults | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Crowds: level of detail and sprites](https://360sona.com/devs/docs/guides/crowd.md)): ```c /* 10,000 avatars in rows round a pitch, facing in */ sona_lod_set(ctx, NULL); for (i = 0; i < 10000; i++) { sona_add_options o; sona_add_defaults(&o); seat(i, o.place.position, &o.place.turn_deg); /* your layout */ o.start_at = -1; /* random start: a crowd out of step */ sona_avatar_add_base64(ctx, looks[i % 12], &o, &av[i]); } ``` Sets the options; NULL sets the defaults. Takes effect at the next `sona_update`. Changing `sprite_angles` or `sprite_height` drops every baked sheet; they are baked again as needed. - `SONA_E_ARGUMENT`: `ctx` is NULL, a value is out of range or NaN, or `sprite_px` is above 0 and a renderer already on the ctx has a device too small for one sheet of the bake. Nothing changes then. - `SONA_E_MEMORY`: the allocator failed (first call only). - A renderer made later on a device too small for the options draws no sprites. It logs a warning once. ### sona_lod_get ```c sona_result sona_lod_get(const sona_ctx *ctx, sona_lod_options *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `out` | `sona_lod_options *` | Receives the [`sona_lod_options`](https://360sona.com/devs/docs/reference/fields.md#sona_lod_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_lod_options x_lod_options; memset(&x_lod_options, 0, sizeof x_lod_options); sona_result result = sona_lod_get(ctx, &x_lod_options); if (result != SONA_OK) printf("sona_lod_get: %s\n", sona_result_name(result)); ``` Copies the current options: before any `sona_lod_set`, thresholds 120 and 40 and no sprites (`sprite_px` 0). `SONA_E_ARGUMENT` for a NULL argument. ### sona_avatar_lod ```c uint32_t sona_avatar_lod(const sona_avatar *a, float *fade); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `fade` | `float *` | Receives the crossfade between two levels, 0 to 1; may be NULL | `NULL` allowed (below) | **Returns** `uint32_t`. The avatar's step at the last `sona_update`, and in `*fade` how far it is from its mesh (0) to its sprite (1). `SONA_LOD_FULL` and 0 for NULL, an avatar that is not READY, and one that was not in view at that update (culled or hidden). Back in view it has its step again. `fade` may be NULL. ### sona_lod_stats_get ```c void sona_lod_stats_get(const sona_ctx *ctx, sona_lod_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `out` | `sona_lod_stats *` | Receives the [`sona_lod_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_lod_stats) | required | **Returns** Nothing. **Example**: ```c sona_lod_stats x_lod_stats; memset(&x_lod_stats, 0, sizeof x_lod_stats); sona_lod_stats_get(ctx, &x_lod_stats); ``` Fills `*out`. All zero before the first `sona_lod_set`. NULL arguments are ignored. ## The data API For hosts and engines that draw with their own renderer. A posed avatar is a `sona_pose_data`: | Field | Meaning | |---|---| | `build_version` | Bumps when meshes, materials or textures change | | `world[16]` | `W = scale * rotateY(turn) * translate(position)`, row-vector | | `palette` | 864 floats: per joint 3 float4, columns 0..2 of the row-vector skin matrix, in avatar space | | `view_joints` | 72 x 3 floats: each joint's translation before `W` | | `meshes`, `mesh_count` | In draw order | | `materials`, `material_count` | The materials the meshes draw with: each a `sona_material` (shader family, `SONA_MAT_*` flags, parameters, textures); a mesh names one by index | | `textures`, `texture_count` | The face sheet is one of them (its material has `SONA_MAT_FACE`) | | `props`, `prop_count` | Palettes for held props (up to 4), then, with sway on, one for each swaying mesh ([sway](https://360sona.com/devs/docs/guides/sway.md)), so `prop_count` can pass 4; size arrays by it | | `expression[5]` | Mouth, left eyebrow, right eyebrow, left eye, right eye | A `sona_mesh` holds `item` (the item it came from), `mask` (its AssetMask), `batch`, `material` (index into materials), `pass` (SONA_PASS_OPAQUE or SONA_PASS_TRANSPARENT), `palette` (-1: the body; else an index into props), `vertex_count`, `index_count`, `vertices`, `indices` (uint16 triangle list) and `key`. `key` is stable while the geometry lives and is shared by avatars wearing the same item, so a host can cache uploads by it. The runtime vertex is 76 bytes, in host byte order: | Offset | Type | What | |---|---|---| | +0 | float3 | Position (bind pose, avatar space) | | +12 | uint8 x4 | Joint index x 3 (the palette's float4 row) | | +16 | uint8 x4 | Weight (sum 255) | | +20 | uint8 x4 | Normal, `(n * 0.5 + 0.5) * 255`; byte 23 is 0 | | +24 | uint8 x4 | Vertex colour (baked occlusion and alpha) | | +28 | float4 | uv0.xy, uv1.xy | | +44 | float4 | uv2.xy, uv3.xy (the HQ shaders read uv2 only) | | +60 | float4 | uv4.xy, uv5.xy | A `sona_material` holds `shader_id` (0..4, the app's material family), `flags` (SONA_MAT_*), `params[40]` (AvatarShaderParams, 10 float4; the baked shaders read only 36..39), `transparency`, `color_tex`, `intensity_tex`, `decal_tex`, `color_addr`, `intensity_addr` and `decal_addr`. A texture index of -1 means neutral: white for colour, (0,0,0,255) for intensity and decal. The decal slot holds the matcap for reflective materials. Address modes: bit 0 set means U wraps, bit 1 set means V wraps; clear means clamp. Material flags: `SONA_MAT_SKIN` (the skin program), `SONA_MAT_REFLECTIVE` (the decal slot holds the matcap), `SONA_MAT_FACE` (the colour texture is the face sheet), `SONA_MAT_TRANSPARENT`, `SONA_MAT_CARRYABLE` (drawn with a prop palette, or not drawn when it has none). A `sona_texture` holds `key` (stable while it lives), `version` (bumps when the pixels change, as the face sheet does), `format`, `width`, `height`, `data` and `bytes`. Formats: `SONA_TEX_RGBA8_SRGB` (decoded and preprocessed, as the web uploads it; `width * height * 4` bytes), `SONA_TEX_RGBA16F_CUBE` (the irradiance cube: 6 faces, +X -X +Y -Y +Z -Z). `SONA_TEX_BC1_SRGB` and `SONA_TEX_BC3_SRGB` are reserved for 1.1. A `sona_prop_palette` holds `item`, `playing` and `palette` (864 floats). While `playing` is 0 the prop's meshes are not drawn. ### sona_pose ```c sona_result sona_pose(sona_avatar *a, const sona_pose_data **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `out` | `const sona_pose_data **` | Receives a pointer to the `sona_pose_data`, which the library keeps | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Drawing avatars with your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md)): ```c static float positions[65536 * 3], normals[65536 * 3]; const sona_pose_data *pose = NULL; if (sona_pose(avatar, &pose) == SONA_OK && pose->mesh_count > 0) { const sona_mesh *m = &pose->meshes[0]; if (m->vertex_count <= 65536 && sona_pose_vertices(avatar, 0, SONA_SPACE_WORLD, positions, normals, 3) == SONA_OK) my_draw_positions(positions, normals, m->vertex_count, m->indices, m->index_count); } ``` The avatar's pose data, valid until the next `sona_update`. `SONA_E_NOT_READY` before `READY`. ### sona_pose_vertices ```c sona_result sona_pose_vertices(sona_avatar *a, uint32_t mesh, uint32_t space, float *positions, float *normals, size_t stride_floats); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `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` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Drawing avatars with your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md)): ```c static float positions[65536 * 3], normals[65536 * 3]; const sona_pose_data *pose = NULL; if (sona_pose(avatar, &pose) == SONA_OK && pose->mesh_count > 0) { const sona_mesh *m = &pose->meshes[0]; if (m->vertex_count <= 65536 && sona_pose_vertices(avatar, 0, SONA_SPACE_WORLD, positions, normals, 3) == SONA_OK) my_draw_positions(positions, normals, m->vertex_count, m->indices, m->index_count); } ``` CPU skinning, for hosts that cannot skin on the GPU. Writes `vertex_count` positions (and normals, when `normals` is not NULL) for one mesh, `stride_floats` apart (at least 3). `space` is `SONA_SPACE_AVATAR` or `SONA_SPACE_WORLD`. Uses SIMD where the CPU has it. ### sona_shading_get ```c sona_result sona_shading_get(sona_ctx *ctx, sona_shading *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `out` | `sona_shading *` | Receives the [`sona_shading`](https://360sona.com/devs/docs/reference/fields.md#sona_shading) | required | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Drawing avatars with your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md)): ```c size_t len = 0; const void *vs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 0, &len); const void *fs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 1, &len); sona_shading shading; if (vs && fs && sona_shading_get(ctx, &shading) == SONA_OK) { /* shading.irradiance (a cube, 16 x 16 per face), shading.rim[4], shading.shadow_rows[12]: the constants those shaders read */ } ``` The fixed shading inputs, for hosts that rebuild the look in their own shaders: `irradiance` (16x16 per face, RGBA16F), `irradiance_gain` (1.0), `ao_gain` (0 in the SDK), `bloom_gain` (0.1875), `shadow_rows[12]` (the 3x4 light lookup), `rim[4]` (0.549, 0.502, 0.4039, 1.6). `SONA_PENDING` until the data files have loaded. ### sona_shader_source ```c const void *sona_shader_source(sona_shader_lang lang, sona_program prog, int stage, size_t *len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `lang` | `sona_shader_lang` | The shading language | - | | `prog` | `sona_program` | Which program of the frame | - | | `stage` | `int` | 0 vertex, 1 fragment | - | | `len` | `size_t *` | Receives how many bytes were written | required | **Returns** `const void *`. **Example** (also in [Drawing avatars with your own renderer](https://360sona.com/devs/docs/guides/own-renderer.md)): ```c size_t len = 0; const void *vs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 0, &len); const void *fs = sona_shader_source(SONA_LANG_GLSL_330, SONA_PROG_CLOTH, 1, &len); sona_shading shading; if (vs && fs && sona_shading_get(ctx, &shading) == SONA_OK) { /* shading.irradiance (a cube, 16 x 16 per face), shading.rim[4], shading.shadow_rows[12]: the constants those shaders read */ } ``` The SDK's own shaders, for hosts that draw themselves. `lang` is `SONA_LANG_GLSL_ES300`, `SONA_LANG_GLSL_330`, `SONA_LANG_SPIRV`, `SONA_LANG_HLSL` or `SONA_LANG_MSL`; `prog` is one of `SONA_PROG_SHADOW`, `GBUFFER`, `SSAO`, `BRIGHT`, `BLUR`, `PRESENT`, `CLOTH`, `SKIN`, `REFL`, `REFL_SKIN`, `CREDIT`; `stage` is 0 for vertex, 1 for fragment. Returns text, or SPIR-V bytes, with its length in `*len`; NULL when that language is not in this build. ## Drawing with the SDK's backends The host owns the device and hands it over in a `sona_device_desc {backend, u, frames_in_flight}`. Pointers are the API's own handles cast to `void *`. `frames_in_flight` 0 means 2. | Backend | `u.` | What to pass | |---|---|---| | `SONA_BACKEND_GL`, `SONA_BACKEND_GLES` | `gl` | `get_proc(name)`; the context current | | `SONA_BACKEND_VULKAN` | `vk` | `instance`, `physical_device`, `device`, `queue`, `queue_family`, `api_version`, `get_instance_proc` | | `SONA_BACKEND_D3D11` | `d3d11` | `ID3D11Device *`, `ID3D11DeviceContext *` | | `SONA_BACKEND_D3D12` | `d3d12` | `ID3D12Device *`, `ID3D12CommandQueue *` | | `SONA_BACKEND_METAL` | `metal` | `id` | | `SONA_BACKEND_XENOS` | `xenos` | `struct XenosDevice *` | A `sona_target` says where one draw lands: `width`, `height`, and per API a GL framebuffer (0: the default), a Vulkan image, view, format, layouts and command buffer (recorded into, not submitted), a D3D11 render target view, a D3D12 resource, RTV handle, states and command list (recorded into, not executed), a Metal texture and command buffer, or a Xenos surface. Row 0 is the top of the picture on every API except GL and GLES, where it is the bottom. The colour target must be UNORM RGBA8 or BGRA8, not sRGB: the present pass encodes sRGB itself, as on the web. `sona_draw_options` holds `clear[4]` (premultiplied RGBA, default 0, 0, 0, 0), `flags` and `credit_corner`. Flags: - `SONA_DRAW_SHADOW`: the key light shadow (the web's `shadow: true`). The shader is the web's, with no depth bias beyond the shadow pass's front-face culling, so on a bare figure it self-shadows in fine diagonal stripes with a hard edge across the chest. 360sona.com's editor and `sona_editor` draw without it. - `SONA_DRAW_NO_BLOOM`. - `SONA_DRAW_EDITOR_AO`: the editor's look, G-buffer and SSAO, aoGain 1. - `SONA_DRAW_NO_CREDIT`: the app shows the credit itself; the licence still requires it. There is no "do not clear" flag (bit 2 is reserved): present overwrites the target, colour and alpha, as the web does. To put avatars over the host's own pixels, draw into a texture and composite it. `credit_corner` is `SONA_CORNER_BOTTOM_RIGHT` (0), `BOTTOM_LEFT`, `TOP_RIGHT` or `TOP_LEFT`. ### sona_renderer_create ```c sona_result sona_renderer_create(sona_ctx *ctx, const sona_device_desc *dev, sona_renderer **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `dev` | `const sona_device_desc *` | The options, a [`sona_device_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_device_desc) | required | | `out` | `sona_renderer **` | Receives the new renderer | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Getting started](https://360sona.com/devs/docs/getting-started.md)): ```c sona_device_desc dev; sona_renderer *renderer = NULL; memset(&dev, 0, sizeof dev); dev.backend = SONA_BACKEND_GL; dev.u.gl.get_proc = my_gl_get_proc; /* SDL_GL_GetProcAddress, glfwGetProcAddress, ... */ while (sona_renderer_create(ctx, &dev, &renderer) == SONA_PENDING) sona_update(ctx, 0, NULL, NULL); /* the shading data is still arriving */ ``` Makes a renderer on the host's device. `SONA_E_UNSUPPORTED` for a backend not compiled into this library. ### sona_renderer_destroy ```c void sona_renderer_destroy(sona_renderer *r); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | **Returns** Nothing. **Example** (also in [Getting started](https://360sona.com/devs/docs/getting-started.md)): ```c sona_avatar_remove(avatar); /* frees what only it used */ sona_renderer_destroy(renderer); /* before your device goes */ sona_close(ctx); ``` Frees the renderer and its GPU objects. ### sona_draw ```c sona_result sona_draw(sona_renderer *r, const sona_view *view, const sona_target *target, const sona_draw_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](https://360sona.com/devs/docs/reference/fields.md#sona_target) | required | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Device loss: getting a renderer back](https://360sona.com/devs/docs/guides/device-loss.md)): ```c /* the device is gone: the draw said so */ if (sona_draw(r, &view, &target, NULL) == SONA_E_CONTEXT) { sona_renderer_lost(r); /* every GPU object of the renderer forgotten */ /* make the new device (see below for when the old one may go) */ sona_device_desc dev = my_new_device(); if (sona_renderer_reset(r, &dev) != SONA_OK) { /* try again later, or another device */ } } ``` Draws every visible ready avatar, as posed by the last `sona_update`, folding each palette with this view. Each `sona_draw` and `sona_snapshot` is one frame; frames count from 1. It changes API state and does not restore it: - GL and GLES: framebuffer bindings, viewport, program, vertex array, array and uniform buffer bindings, texture units 0..5 with their samplers, active texture, blend, depth, cull, front face, colour mask. `GL_FRAMEBUFFER_SRGB` is left off. - D3D11: every stage's shaders, constant buffers, SRVs and samplers, input layout, topology, rasteriser, blend, depth-stencil, render targets, viewports. - D3D12: root signature, pipeline state, descriptor heaps, viewports, scissors, render targets, primitive topology. - Vulkan and Metal: only what is recorded; nothing is submitted. With sprites on (1.1, `sona_lod_set`) a draw that bakes new looks records the bake ahead of its frame and uses two frame indices. - With multisampling (1.1, on by default), GL and GLES also change the renderbuffer binding. On Vulkan, D3D12 and Metal it returns `SONA_PENDING` once `frames_in_flight` frames are outstanding without `sona_renderer_frame_done`. ### sona_renderer_frame_index ```c uint64_t sona_renderer_frame_index(const sona_renderer *r); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_renderer *` | The renderer | required | **Returns** `uint64_t`. **Example**: ```c uint64_t x_got = sona_renderer_frame_index(r); printf("sona_renderer_frame_index: %lld\n", (long long)x_got); ``` The index of the last frame recorded (0 before the first). ### sona_renderer_frame_done ```c void sona_renderer_frame_done(sona_renderer *r, uint64_t completed_frame); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `completed_frame` | `uint64_t` | The index of the last frame the host's GPU has finished | - | **Returns** Nothing. **Example**: ```c sona_renderer_frame_done(r, 0); ``` Vulkan, D3D12 and Metal: every frame up to and including `completed_frame` has finished on the GPU. The per-frame rings and the GPU cache's releases wait for it. GL and D3D11 ignore it. ### sona_renderer_lost ```c void sona_renderer_lost(sona_renderer *r); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | **Returns** Nothing. **Example** (also in [Device loss: getting a renderer back](https://360sona.com/devs/docs/guides/device-loss.md)): ```c /* the device is gone: the draw said so */ if (sona_draw(r, &view, &target, NULL) == SONA_E_CONTEXT) { sona_renderer_lost(r); /* every GPU object of the renderer forgotten */ /* make the new device (see below for when the old one may go) */ sona_device_desc dev = my_new_device(); if (sona_renderer_reset(r, &dev) != SONA_OK) { /* try again later, or another device */ } } ``` After a device loss: forget every GPU object. The next `sona_draw` uploads again. ### sona_renderer_reset ```c sona_result sona_renderer_reset(sona_renderer *r, const sona_device_desc *dev); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `dev` | `const sona_device_desc *` | The options, a [`sona_device_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_device_desc) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Device loss: getting a renderer back](https://360sona.com/devs/docs/guides/device-loss.md)): ```c /* the device is gone: the draw said so */ if (sona_draw(r, &view, &target, NULL) == SONA_E_CONTEXT) { sona_renderer_lost(r); /* every GPU object of the renderer forgotten */ /* make the new device (see below for when the old one may go) */ sona_device_desc dev = my_new_device(); if (sona_renderer_reset(r, &dev) != SONA_OK) { /* try again later, or another device */ } } ``` Starts the renderer again on a new device of the same backend, after `sona_renderer_lost`. Another backend is `SONA_E_ARGUMENT`. ### sona_snapshot ```c sona_result sona_snapshot(sona_renderer *r, const sona_view *view, uint32_t width, uint32_t height, const sona_draw_options *opts, uint8_t *rgba_out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | | `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The same picture natively and on the web](https://360sona.com/devs/docs/guides/parity.md)): ```c sona_quality q; sona_draw_options o; sona_quality_defaults(&q); q.msaa = 1; /* one sample */ q.flags = 0; /* no mips */ sona_renderer_set_quality(renderer, &q); memset(&o, 0, sizeof o); o.flags = SONA_DRAW_NO_CREDIT; /* no shadow, no badge; bloom stays on */ sona_camera_preset(avatar, SONA_PRESET_FULL, &view); sona_snapshot(renderer, &view, 512, 512, &o, rgba); ``` Draws into an internal target, folding palettes with this view, and reads it back as straight RGBA8, row 0 at the top. Blocks until the GPU finishes this one frame. On Vulkan it submits on the device's `VkQueue`, so no other thread may use that queue during the call. The credit is drawn unless `SONA_DRAW_NO_CREDIT`. `rgba_out` holds `width * height * 4` bytes. ### sona_png_encode ```c sona_result sona_png_encode(sona_ctx *ctx, const uint8_t *rgba, uint32_t width, uint32_t height, uint8_t **out, size_t *out_len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `rgba` | `const uint8_t *` | Straight RGBA8, row 0 at the top, `width * height * 4` bytes | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required | | `out_len` | `size_t *` | Receives how many bytes `*out` holds | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). PNG bytes of an RGBA8 picture, with the web's three tEXt chunks after IHDR: Software "360sona", Source "https://360sona.com", Comment "Powered by 360sona". Free `*out` with `sona_free`. ### sona_free ```c void sona_free(sona_ctx *ctx, void *p); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `p` | `void *` | Memory the library handed out | required | **Returns** Nothing. **Example** (also in [FBX, Roblox and clips in the export](https://360sona.com/devs/docs/guides/export-fbx.md)): ```c sona_export_options o; uint8_t *fbx = NULL; size_t fbx_len = 0; sona_export_defaults(&o); o.format = SONA_EXPORT_FBX; o.flags = SONA_EXPORT_CLIPS; /* the clip it plays, as an animation on the skeleton */ if (sona_export_avatar(avatar, &o, &fbx, &fbx_len, NULL) == SONA_OK) { FILE *f = fopen("avatar.fbx", "wb"); if (f) { fwrite(fbx, 1, fbx_len, f); fclose(f); } sona_free(ctx, fbx); } ``` Frees memory the library handed out (`sona_png_encode`), through the ctx's allocator. ## Item previews One item worn alone on a grey stand-in body, framed by its slot, for wardrobes and item pickers. The guide, with the framing rules and the measured cost, is [Item previews](https://360sona.com/devs/docs/guides/item-preview.md). A preview is an avatar of the ctx with a made-up manifest. It builds through the same queue, shares decoded items and GPU buffers with every other avatar, counts toward `max_avatars` and is freed by `sona_avatar_remove`. `sona_draw` and `sona_snapshot` never draw it, `sona_avatar_set_visible` does nothing to it and `sona_camera_fit_crowd` ignores it. It is a still picture: `sona_avatar_play`, `_crossfade` and `_queue` return `SONA_E_ARGUMENT` for it. Leave pose overrides off a preview; they are not part of the measured frame. `sona_preview_options`, 40 bytes: | Field | Meaning | Default | |---|---|---| | `gender` | 1 male, 2 female; 0: the body the item was made for (male when either) | 0 | | `slot` | The category mask to frame by (`0x40` hat, `0x38` costume, ...); 0: from the item | 0 | | `flags` | `SONA_PREVIEW_PLAY` (1): a prop plays its clip, framed for all of it. `SONA_PREVIEW_COLOURS` (2): wear the item in `colours` | 0 | | `skin` | 0xAARRGGBB; 0: the stand-in grey `0xff9a9a9a` | 0 | | `colours[3]` | 0xAARRGGBB primary, secondary, tertiary, with `SONA_PREVIEW_COLOURS` | 0 | | `priority` | Build order, as `sona_add_options.priority` | 0 | | `time` | Props: seconds into the clip to hold (or start at); negative: its fullest frame | -1 | | `margin` | Room around the item: 1 touches the edges; 0 means 1.36, as the web's item renders | 1.36 | ### sona_preview_defaults ```c void sona_preview_defaults(sona_preview_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_preview_options *` | The [`sona_preview_options`](https://360sona.com/devs/docs/reference/fields.md#sona_preview_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_preview_options x_preview_options; memset(&x_preview_options, 0, sizeof x_preview_options); sona_preview_defaults(&x_preview_options); ``` Fills the defaults above. NULL does nothing. ### sona_item_preview_add ```c sona_result sona_item_preview_add(sona_ctx *ctx, const char *item_id, const sona_preview_options *opts, sona_avatar **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `item_id` | `const char *` | An item id as text | required | | `opts` | `const sona_preview_options *` | The options, a [`sona_preview_options`](https://360sona.com/devs/docs/reference/fields.md#sona_preview_options) | `NULL`: the defaults | | `out` | `sona_avatar **` | Receives the new avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Queues a preview of one item id (lowercase or uppercase) and returns at once. NULL `opts` takes the defaults. It reaches READY or FAILED through `sona_update` with the usual events. A missing item file does not fail it: it reaches READY without the item, and `sona_item_preview_bounds` says `SONA_E_NOT_FOUND`. - `SONA_E_ARGUMENT`: NULL `ctx` or `out`, an id that does not parse, an item that is not a worn item, a face item or a head shape (a clip, for example), `gender` above 2, a negative or non-finite `margin`, a non-finite `time`. - `SONA_E_LIMIT`: the ctx already holds `max_avatars` avatars. - `SONA_E_MEMORY`. `*out` is NULL on any error. ### sona_item_preview_bounds ```c sona_result sona_item_preview_bounds(sona_avatar *a, float lo[3], float hi[3]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `lo` | `float [3]` | Receives the box's lower corner | required | | `hi` | `float [3]` | Receives the box's upper corner | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c float x_lo[3]; memset(x_lo, 0, sizeof x_lo); float x_hi2[3]; memset(x_hi2, 0, sizeof x_hi2); sona_result result = sona_item_preview_bounds(avatar, x_lo, x_hi2); if (result != SONA_OK) printf("sona_item_preview_bounds: %s\n", sona_result_name(result)); ``` The item's box in world metres, over the whole clip for a playing prop. Face and head-shape items give the head; a pair framed from one side (earrings, wristbands) gives the near one; a held prop leaves out a stray part set apart from the rest. Measured once, on the first call to any of `_bounds`, `_view`, `_draw` or `_snapshot` after READY. `SONA_E_NOT_READY` before READY. `SONA_E_ARGUMENT` for NULL arguments or an avatar that is not a preview. `SONA_E_NOT_FOUND` when no triangle of the item was drawn (its file is missing). ### sona_item_preview_view ```c sona_result sona_item_preview_view(sona_avatar *a, uint32_t width, uint32_t height, sona_view *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `out` | `sona_view *` | Receives the [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); sona_result result = sona_item_preview_view(avatar, 16, 16, &x_view); if (result != SONA_OK) printf("sona_item_preview_view: %s\n", sona_result_name(result)); ``` The framed camera for a `width` x `height` picture: the slot's view preset gives the angle, the item's box the target and the distance. Every field of `*out` is set. Errors as `sona_item_preview_bounds`, except that an item that drew nothing still gets its slot's preset camera and `SONA_OK`. ### sona_item_preview_draw ```c sona_result sona_item_preview_draw(sona_renderer *r, sona_avatar *a, const sona_view *view, const sona_target *target, const sona_draw_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `a` | `sona_avatar *` | The avatar | required | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](https://360sona.com/devs/docs/reference/fields.md#sona_target) | required | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `sona_draw` with only this preview in the frame. NULL `view`: `sona_item_preview_view` for the target's size. One frame, with the frames-in-flight and host-state rules of `sona_draw`. The renderer must belong to the preview's ctx (`SONA_E_ARGUMENT` otherwise). It also returns what `sona_draw` returns. ### sona_item_preview_snapshot ```c sona_result sona_item_preview_snapshot(sona_renderer *r, sona_avatar *a, uint32_t width, uint32_t height, const sona_draw_options *opts, uint8_t *rgba_out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `a` | `sona_avatar *` | The avatar | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | | `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `sona_snapshot` of this preview alone, framed for `width` x `height`. Blocks until the GPU finishes and writes `width * height * 4` bytes of straight RGBA8, row 0 at the top. The credit is drawn unless `SONA_DRAW_NO_CREDIT`; a picker usually passes the flag and shows the credit once elsewhere, as the licence still requires. ## Rendering quality What the web SDK does against white specks on small avatars: multisampling in the main pass (with centroid sampling and a coverage-aware present), mip chains for item textures, and coverage-preserving mips for cut-out colour textures. The guide, with the speck counts, is [Rendering quality](https://360sona.com/devs/docs/guides/quality.md). `sona_quality` holds `msaa` and `flags`, 8 bytes. `msaa` is `SONA_MSAA_AUTO` (0: 4 samples on a hardware GPU, 1 on a software rasteriser), or 1 (off), 2, 4 or 8. `flags` are `SONA_QUALITY_MIPS` (1: item textures carry mip chains and are filtered between levels) and `SONA_QUALITY_CUTOUT_MIPS` (2: cut-out colour textures get edge bleed and coverage-preserving mips; only with `SONA_QUALITY_MIPS`). A renderer starts with `sona_quality_defaults`. A frame over 4096 x 4096 / samples halves its samples until it fits, as the web does. ### sona_quality_defaults ```c void sona_quality_defaults(sona_quality *q); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `q` | `sona_quality *` | The [`sona_quality`](https://360sona.com/devs/docs/reference/fields.md#sona_quality) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Rendering quality](https://360sona.com/devs/docs/guides/quality.md)): ```c void sona_quality_defaults(sona_quality *q); ``` The web SDK's defaults: `msaa = SONA_MSAA_AUTO`, `flags = SONA_QUALITY_MIPS | SONA_QUALITY_CUTOUT_MIPS`. NULL does nothing. ### sona_renderer_set_quality ```c sona_result sona_renderer_set_quality(sona_renderer *r, const sona_quality *q); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `q` | `const sona_quality *` | A [`sona_quality`](https://360sona.com/devs/docs/reference/fields.md#sona_quality) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Rendering quality](https://360sona.com/devs/docs/guides/quality.md)): ```c sona_result sona_renderer_set_quality(sona_renderer *r, const sona_quality *q); ``` Sets the quality from the next `sona_draw` or `sona_snapshot`. NULL `q` means the defaults. More samples than the device has are clamped to the most it has. A change of mip flags uploads each avatar's textures again at its next draw. `SONA_E_ARGUMENT` for a NULL renderer, another `msaa` value, or an unknown flag; the renderer keeps its old quality then. `sona_renderer_reset` keeps the quality and works out the sample count again for the new device. ### sona_renderer_quality ```c sona_result sona_renderer_quality(const sona_renderer *r, sona_quality *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_renderer *` | The renderer | required | | `out` | `sona_quality *` | Receives the [`sona_quality`](https://360sona.com/devs/docs/reference/fields.md#sona_quality) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Rendering quality](https://360sona.com/devs/docs/guides/quality.md)): ```c sona_result sona_renderer_quality(const sona_renderer *r, sona_quality *out); ``` What the renderer draws with. `out->msaa` is the sample count the backend really uses, asked of it at each call: never `SONA_MSAA_AUTO`, and 1 when the device cannot multisample. When a backend cannot make its multisampled target it logs once and draws one sample from then on, and `out->msaa` is 1 after that. After a frame over the 4096 x 4096 budget it is the halved count that frame used. `out->flags` are the flags as set, with `SONA_QUALITY_CUTOUT_MIPS` cleared when `SONA_QUALITY_MIPS` is not set. `SONA_E_ARGUMENT` when `r` or `out` is NULL. ### sona_renderer_vk_features ```c sona_result sona_renderer_vk_features(sona_renderer *r, uint32_t features); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `features` | `uint32_t` | `SONA_VK_FEATURE_*` bits the host's device has enabled | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_renderer_vk_features(r, 0); if (result != SONA_OK) printf("sona_renderer_vk_features: %s\n", sona_result_name(result)); ``` Vulkan only: the optional `VkPhysicalDeviceFeatures` the host enabled when it created `sona_device_desc.u.vk.device`, which the backend cannot ask the device for. `SONA_VK_FEATURE_BINDLESS` (1, `shaderSampledImageArrayDynamicIndexing`) puts every texture in one descriptor set, so a pass binds one set and the draws only draw; `SONA_VK_FEATURE_MULTI_DRAW` (2, `multiDrawIndirect` and `drawIndirectFirstInstance`, only with BINDLESS) makes each run of draws one `vkCmdDrawIndexedIndirect`. The picture is the same byte for byte; the CPU time to record a frame drops (the guide has the numbers). From the next frame; 0 goes back to a set per draw. A renderer starts with 0, and again after `sona_renderer_reset`. `SONA_E_UNSUPPORTED` on any other backend or when the physical device lacks a feature (nothing changes), `SONA_E_ARGUMENT` for a NULL renderer, an unknown bit, or MULTI_DRAW without BINDLESS. The guide: [Vulkan](https://360sona.com/devs/docs/guides/vulkan-features.md). ### sona_tier_defaults ```c void sona_tier_defaults(sona_tier_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_tier_options *` | The [`sona_tier_options`](https://360sona.com/devs/docs/reference/fields.md#sona_tier_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Quality tiers](https://360sona.com/devs/docs/guides/tiers.md)): ```c void sona_tier_defaults(sona_tier_options *o); ``` `size` set; `target_fps` 60, `avatars` 20. ### sona_tier_apply ```c sona_result sona_tier_apply(sona_ctx *ctx, sona_renderer *r, const sona_tier_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `r` | `sona_renderer *` | The renderer | required | | `o` | `const sona_tier_options *` | The options, a [`sona_tier_options`](https://360sona.com/devs/docs/reference/fields.md#sona_tier_options) | `NULL`: the defaults | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Quality tiers](https://360sona.com/devs/docs/guides/tiers.md)): ```c sona_result sona_tier_apply(sona_ctx *ctx, sona_renderer *r, const sona_tier_options *o); ``` `r` NULL: the ctx's side only. o NULL: the defaults. ### sona_tier_detect ```c sona_result sona_tier_detect(const sona_renderer *r, uint32_t *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_renderer *` | The renderer | required | | `out` | `uint32_t *` | Receives the values | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Quality tiers](https://360sona.com/devs/docs/guides/tiers.md)): ```c sona_result sona_tier_detect(const sona_renderer *r, uint32_t *out); ``` The tier the device behind r suits: `SONA_TIER_LOW` .. `SONA_TIER_HIGH`. ## 2D outputs Sprite sheets of a clip at N frames in M directions with Aseprite and TexturePacker atlases, outlined stickers, and crisp pixel art with a small palette. Sheets and stickers draw through `sona_snapshot` with the avatar staged alone at the origin, and put it back as it was (placement, clip and its time, pose, events, visibility, crowd step). A clip named in their options is read from the ctx's sources without touching the avatar's clip: `SONA_PENDING` until its file arrives (run `sona_update`, call again). The guide, with every field and the numbers: [2D outputs](https://360sona.com/devs/docs/guides/sprites2d.md). Every options struct starts with `size`, set by its `_defaults` call; a struct without it is refused with `SONA_E_ARGUMENT`. `sona_picture` holds `rgba`, `width` and `height`: straight RGBA8, row 0 at the top. ### sona_pixel_defaults ```c void sona_pixel_defaults(sona_pixel_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_pixel_options *` | The [`sona_pixel_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pixel_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_pixel_options x_pixel_options; memset(&x_pixel_options, 0, sizeof x_pixel_options); x_pixel_options.size = sizeof x_pixel_options; sona_pixel_defaults(&x_pixel_options); ``` `size` set, `height` 32, `colours` 16, `flags` `SONA_PIXEL_OUTLINE`, `outline` 0 (from the palette), `alpha_cut` 0.5, no palette. NULL does nothing. ### sona_pixel_art ```c sona_result sona_pixel_art(sona_ctx *ctx, const sona_picture *in, const sona_pixel_options *o, sona_picture *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `in` | `const sona_picture *` | A [`sona_picture`](https://360sona.com/devs/docs/reference/fields.md#sona_picture) | required | | `o` | `const sona_pixel_options *` | The options, a [`sona_pixel_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pixel_options) | required | | `out` | `sona_picture *` | Receives the [`sona_picture`](https://360sona.com/devs/docs/reference/fields.md#sona_picture) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_picture x_picture; memset(&x_picture, 0, sizeof x_picture); sona_pixel_options x_pixel_options2; memset(&x_pixel_options2, 0, sizeof x_pixel_options2); x_pixel_options2.size = sizeof x_pixel_options2; sona_picture x_picture3; memset(&x_picture3, 0, sizeof x_picture3); sona_result result = sona_pixel_art(ctx, &x_picture, &x_pixel_options2, &x_picture3); if (result != SONA_OK) printf("sona_pixel_art: %s\n", sona_result_name(result)); ``` The figure's box of `in` (alpha 8 and up; the whole picture with `SONA_PIXEL_KEEP_FRAME`) scaled with an area filter to exactly `o->height` pixels including the outline, every pixel opaque or clear at `alpha_cut`, colours mapped to `o->palette` or to `o->colours` colours made from the picture, optionally dithered (`SONA_PIXEL_DITHER`) and outlined (`SONA_PIXEL_OUTLINE`, `_OUTLINE_THIN`). `out->rgba` is freed with `sona_free`. `SONA_E_NOT_FOUND` when no pixel reaches alpha 8 or none is opaque enough at that size; `SONA_E_ARGUMENT` for a value out of range or a picture too wide for the height (over 4096 pixels). ### sona_pixel_palette ```c sona_result sona_pixel_palette(sona_ctx *ctx, const sona_picture *images, uint32_t image_count, uint32_t colours, uint32_t palette[256], uint32_t *count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `images` | `const sona_picture *` | A [`sona_picture`](https://360sona.com/devs/docs/reference/fields.md#sona_picture) | required | | `image_count` | `uint32_t` | How many pictures `images` holds | - | | `colours` | `uint32_t` | How many colours the palette may hold | - | | `palette` | `uint32_t [256]` | Receives up to 256 colours | required | | `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One palette of up to `colours` (2..256) entries over every pixel of alpha 128 and up in the pictures: median cut, then k-means, integer maths. Entries are `0xFFRRGGBB`, darkest first; `*count` may be below `colours` when the pictures hold fewer colours. Pass it as `sona_pixel_options.palette` so frames share colours. `SONA_E_NOT_FOUND` when no pixel counts. ### sona_sticker_defaults ```c void sona_sticker_defaults(sona_sticker_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_sticker_options *` | The [`sona_sticker_options`](https://360sona.com/devs/docs/reference/fields.md#sona_sticker_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_sticker_options x_sticker_options; memset(&x_sticker_options, 0, sizeof x_sticker_options); x_sticker_options.size = sizeof x_sticker_options; sona_sticker_defaults(&x_sticker_options); ``` `size` set, `pixels` 512, `time` -1, `framing` `SONA_PRESET_FULL`, `outline_px` 10, `outline` `0xffffffff`, `shadow` `0x59000000` (off while `shadow_px` is 0), `padding` 8. NULL does nothing. ### sona_sticker ```c sona_result sona_sticker(sona_renderer *r, sona_avatar *a, const sona_sticker_options *o, sona_picture *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_sticker_options *` | The options, a [`sona_sticker_options`](https://360sona.com/devs/docs/reference/fields.md#sona_sticker_options) | required | | `out` | `sona_picture *` | Receives the [`sona_picture`](https://360sona.com/devs/docs/reference/fields.md#sona_picture) | required | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_sticker_options x_sticker_options; memset(&x_sticker_options, 0, sizeof x_sticker_options); x_sticker_options.size = sizeof x_sticker_options; sona_picture x_picture2; memset(&x_picture2, 0, sizeof x_picture2); sona_result result = sona_sticker(r, avatar, &x_sticker_options, &x_picture2); if (result != SONA_OK) printf("sona_sticker: %s\n", sona_result_name(result)); ``` A transparent cut-out of the avatar turned `turn_deg` from facing the camera, at `time` seconds into `clip` (negative: its middle; NULL clip: the pose it has now), framed whole (`SONA_PRESET_FULL`) or by the console's `UPPER`, `BUST` and `FACE` framings, drawn at twice the size and brought down so its longer side is `pixels`, outline included; then the outline, the drop shadow, `padding`, and with `SONA_STICKER_SQUARE` a square canvas. The credit badge is stamped bottom right unless `draw_flags` has `SONA_DRAW_NO_CREDIT`. `out->rgba` is freed with `sona_free`. `SONA_E_NOT_READY` before READY, `SONA_E_ARGUMENT` for an item preview, a renderer of another ctx or an option out of range, `SONA_E_NOT_FOUND` when the avatar drew nothing or the clip's file cannot be read, `SONA_PENDING` while the clip loads. ### sona_sheet_defaults ```c void sona_sheet_defaults(sona_sheet_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_sheet_options *` | The [`sona_sheet_options`](https://360sona.com/devs/docs/reference/fields.md#sona_sheet_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_sheet_options x_sheet_options; memset(&x_sheet_options, 0, sizeof x_sheet_options); x_sheet_options.size = sizeof x_sheet_options; sona_sheet_defaults(&x_sheet_options); ``` `size` set, 8 frames, 8 directions, `px_per_metre` 64, `padding` 2, `max_page` 4096, `draw_flags` `SONA_DRAW_NO_BLOOM`; every other field 0 (the whole clip, facing the camera first, side on, orthographic, packed and trimmed). NULL does nothing. ### sona_sheet_render ```c sona_result sona_sheet_render(sona_renderer *r, sona_avatar *a, const sona_sheet_options *o, sona_sheet **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_sheet_options *` | The options, a [`sona_sheet_options`](https://360sona.com/devs/docs/reference/fields.md#sona_sheet_options) | required | | `out` | `sona_sheet **` | Receives the new sprite sheet | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Renders `frames` x `directions` pictures of the clip under one fixed camera (looking down by `pitch_deg`, orthographic unless `fov_deg`) at `px_per_metre`, the hips held in place unless `SONA_SHEET_ROOT_MOTION`. Frames are trimmed (`SONA_SHEET_NO_TRIM`: whole cells), identical ones share a rectangle (`SONA_SHEET_NO_DEDUP`), and they are packed on pages of at most `max_page` (`SONA_SHEET_POW2`: power-of-two sides), or with `SONA_SHEET_GRID` laid out a row per direction. With `o->pixel` the frames are pixel art with one palette. The sheet is the caller's until `sona_sheet_free`, which must come before `sona_close`. Errors as `sona_sticker`, plus `SONA_E_LIMIT` when a frame does not fit `max_page`, a cell needs a render over 8192 pixels, or the cells would pass the 1 GB limit. `*out` is NULL on any error. ### sona_sheet_free ```c void sona_sheet_free(sona_sheet *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_sheet *` | The sprite sheet | required | **Returns** Nothing. Frees the sheet, its pages and frames. NULL does nothing. ### sona_sheet_page_count ```c uint32_t sona_sheet_page_count(const sona_sheet *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_sheet *` | The sprite sheet | required | **Returns** `uint32_t`. The number of pages; 0 for NULL. ### sona_sheet_page ```c sona_result sona_sheet_page(const sona_sheet *s, uint32_t page, sona_picture *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_sheet *` | The sprite sheet | required | | `page` | `uint32_t` | An atlas page, from 0 | - | | `out` | `sona_picture *` | Receives the [`sona_picture`](https://360sona.com/devs/docs/reference/fields.md#sona_picture) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One page's pixels, owned by the sheet: do not free them; valid until `sona_sheet_free`. `SONA_E_ARGUMENT` past the last page. ### sona_sheet_frame_count ```c uint32_t sona_sheet_frame_count(const sona_sheet *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_sheet *` | The sprite sheet | required | **Returns** `uint32_t`. `frames * directions`; 0 for NULL. ### sona_sheet_frame_get ```c sona_result sona_sheet_frame_get(const sona_sheet *s, uint32_t index, sona_sheet_frame *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_sheet *` | The sprite sheet | required | | `index` | `uint32_t` | Which one, from 0 | - | | `out` | `sona_sheet_frame *` | Receives the [`sona_sheet_frame`](https://360sona.com/devs/docs/reference/fields.md#sona_sheet_frame) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One frame (index = direction * frames + frame): its page and rectangle, where the rectangle sits in the full cell (`trim_x`, `trim_y`), the cell's size, the pivot (the avatar's feet) in the cell, its direction, facing, time, duration and `alias` (the first frame with the same rectangle). `SONA_E_ARGUMENT` past the last frame. ### sona_sheet_atlas ```c sona_result sona_sheet_atlas(const sona_sheet *s, uint32_t format, uint32_t page, const char *image, char **json, size_t *len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_sheet *` | The sprite sheet | required | | `format` | `uint32_t` | The file format to write | - | | `page` | `uint32_t` | An atlas page, from 0 | - | | `image` | `const char *` | The picture's file name, as the atlas names it | required | | `json` | `char **` | Receives the atlas as JSON text; free it with `sona_free` | required | | `len` | `size_t *` | Receives how many bytes were written | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The atlas of one page as NUL-terminated JSON, freed with `sona_free` on the sheet's ctx. `SONA_ATLAS_ASEPRITE`: Aseprite's array form, a frame tag per direction and a `pivot` slice. `SONA_ATLAS_TEXTUREPACKER`: TexturePacker's hash form with a pivot per frame and an animation per direction; with `page` `SONA_ATLAS_ALL_PAGES`, every page in one multi-atlas file. Frames are named `__`. `image` is the page file's name for `meta.image` (`{n}` becomes the page number; NULL: `sheet-.png`). `SONA_E_ARGUMENT` for an unknown format, a page past the last, or ALL_PAGES with Aseprite. ## Camera helpers Pure maths, as the web SDK's camera. Presets: `SONA_PRESET_FULL`, `UPPER`, `BUST`, `FACE`. ### sona_camera_preset ```c sona_result sona_camera_preset(const sona_avatar *a, sona_preset p, sona_view *view); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `p` | `sona_preset` | The framing: full, upper, bust or face | - | | `view` | `sona_view *` | Receives the camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The same picture natively and on the web](https://360sona.com/devs/docs/guides/parity.md)): ```c sona_quality q; sona_draw_options o; sona_quality_defaults(&q); q.msaa = 1; /* one sample */ q.flags = 0; /* no mips */ sona_renderer_set_quality(renderer, &q); memset(&o, 0, sizeof o); o.flags = SONA_DRAW_NO_CREDIT; /* no shadow, no badge; bloom stays on */ sona_camera_preset(avatar, SONA_PRESET_FULL, &view); sona_snapshot(renderer, &view, 512, 512, &o, rgba); ``` Sets `view->eye` and `view->target` to one of the console's framings on one ready avatar. ### sona_camera_fit_crowd ```c void sona_camera_fit_crowd(const sona_ctx *ctx, sona_view *view); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `view` | `sona_view *` | Receives the camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | **Returns** Nothing. **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); sona_camera_fit_crowd(ctx, &x_view); ``` Fits every ready avatar in view (the web's preset `"crowd"`). Keeps fov, near, far, width and height. ### sona_camera_orbit ```c void sona_camera_orbit(sona_view *view, const double target[3], double yaw_deg, double pitch_deg, double distance); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `view` | `sona_view *` | Receives the camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `target` | `const double [3]` | The point the eye looks at | required | | `yaw_deg` | `double` | Yaw in degrees | - | | `pitch_deg` | `double` | Pitch in degrees, up positive | - | | `distance` | `double` | How far the eye is from the target, metres | - | **Returns** Nothing. **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); double x_target2[3]; memset(x_target2, 0, sizeof x_target2); sona_camera_orbit(&x_view, x_target2, 30.0f, 30.0f, 0); ``` Places the eye on an orbit around `target`. Hosts wire their own input to it. ### sona_view_matrices ```c void sona_view_matrices(const sona_view *view, float view_m[16], float proj_m[16]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `view_m` | `float [16]` | Receives the view matrix, row-major | required | | `proj_m` | `float [16]` | Receives the projection matrix, row-major | required | **Returns** Nothing. **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); float x_view_m2[16]; memset(x_view_m2, 0, sizeof x_view_m2); float x_proj_m3[16]; memset(x_proj_m3, 0, sizeof x_proj_m3); sona_view_matrices(&x_view, x_view_m2, x_proj_m3); ``` Row-vector view and projection matrices (D3D depth 0..1), for hosts that draw themselves. Double maths, one float store per element, as the web. ## Manifests Pure functions; no ctx needed. A manifest is the 1000-byte AvatarDescription. `sona_guid` is 16 bytes in wire (big-endian) order. `sona_manifest` is the parsed form: `version` (0), `weight` and `height` (raw, not clamped), `chin`, `nose`, `ears`, `face[6]` (mouth, eyes, eyebrows, facial hair, eye shadow, facial feature; each a GUID and four words), `colours[9]` (skin, hair, mouth, eyes, eyebrows, eye shadow, facial hair, facial feature, facial feature 2), `figure_a` (the body, and the gender source), `figure_b` (the head), `worn[13]` (all 13 slots; zero GUIDs are empty), `required[4]` (the last-worn cache: shoes, trousers, shirt, hair), `blob5[5]`, `xuid`, `padding[91]`, and the derived `gender` (1 male, 2 female, 0 unknown) and `valid`. A `sona_asset_ref` holds `id`, `mask` (the u16 type mask after the GUID), `pad` (kept verbatim) and `colours[3]` (primary, secondary, tertiary, 0xAARRGGBB). `sona_route` says where an item goes: `SONA_ROUTE_REJECTED`, `WORN`, `BARE` or `FACE`. The edit verbs follow the editor's rules. Each changes `*m` in place, or returns `SONA_E_ARGUMENT` with `m` unchanged where the editor refuses. Edit flags: `SONA_EDIT_NO_REQUIRED`, `SONA_EDIT_STACK_PROPS`, `SONA_EDIT_NO_DRESS`. ### sona_manifest_parse ```c sona_result sona_manifest_parse(const uint8_t bytes[SONA_MANIFEST_BYTES], sona_manifest *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `bytes` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required | | `out` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Untrusted files, long sessions and speed](https://360sona.com/devs/docs/guides/hardening.md)): ```c sona_manifest m; if (sona_manifest_parse(manifest, &m) != SONA_OK) /* any 1,000 bytes from a player */ puts("not an avatar"); /* SONA_E_MANIFEST */ else sona_avatar_add(ctx, manifest, NULL, &avatar); /* its items load through your sources */ ``` Reads 1000 bytes into a `sona_manifest`. ### sona_manifest_write ```c sona_result sona_manifest_write(const sona_manifest *m, uint8_t out[SONA_MANIFEST_BYTES]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `const sona_manifest *` | A [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | | `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Manifests](https://360sona.com/devs/docs/concepts/manifests.md)): ```c sona_manifest m; sona_guid tee; const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff }; /* 0xAARRGGBB */ if (sona_manifest_parse(manifest, &m) == SONA_OK && sona_guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0", &tee) == SONA_OK && sona_manifest_wear(&m, &tee, colours, 0) == SONA_OK && sona_manifest_write(&m, manifest) == SONA_OK) sona_avatar_add(ctx, manifest, NULL, &avatar); ``` Writes it back. Byte-exact: `write(parse(x)) == x` for every manifest. ### sona_slot_of ```c sona_route sona_slot_of(const sona_guid *id, uint32_t *mask_out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `id` | `const sona_guid *` | An item id | required | | `mask_out` | `uint32_t *` | Receives the item's slot mask; may be NULL | `NULL`: not written | **Returns** `sona_route`. Where an item id goes, and its slot mask in `*mask_out`. ### sona_guid_parse ```c sona_result sona_guid_parse(const char *text, sona_guid *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `text` | `const char *` | An id as text | required | | `out` | `sona_guid *` | Receives the [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Manifests](https://360sona.com/devs/docs/concepts/manifests.md)): ```c sona_manifest m; sona_guid tee; const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff }; /* 0xAARRGGBB */ if (sona_manifest_parse(manifest, &m) == SONA_OK && sona_guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0", &tee) == SONA_OK && sona_manifest_wear(&m, &tee, colours, 0) == SONA_OK && sona_manifest_write(&m, manifest) == SONA_OK) sona_avatar_add(ctx, manifest, NULL, &avatar); ``` Parses the 36-character text form. ### sona_guid_format ```c void sona_guid_format(const sona_guid *id, char out[SONA_ID_CHARS]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `id` | `const sona_guid *` | An item id | required | | `out` | `char [SONA_ID_CHARS]` | Receives the id as text with its NUL | required | **Returns** Nothing. **Example**: ```c sona_guid x_guid; memset(&x_guid, 0, sizeof x_guid); char x_out2[SONA_ID_CHARS]; memset(x_out2, 0, sizeof x_out2); sona_guid_format(&x_guid, x_out2); ``` Writes the lowercase 36-character form and a NUL. ### sona_base64_decode ```c sona_result sona_base64_decode(const char *text, uint8_t *out, size_t cap, size_t *len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `text` | `const char *` | base64 text | required | | `out` | `uint8_t *` | Receives the bytes | required | | `cap` | `size_t` | How many bytes `out` holds | - | | `len` | `size_t *` | Receives how many bytes were written | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Decodes base64 into at most `cap` bytes, and the length in `*len`. ### sona_manifest_wear ```c sona_result sona_manifest_wear(sona_manifest *m, const sona_guid *item, const uint32_t colours[3], uint32_t flags); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | | `item` | `const sona_guid *` | A [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | | `colours` | `const uint32_t [3]` | The item's three colours, 0xAARRGGBB; NULL: its own | `NULL`: its own | | `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Manifests](https://360sona.com/devs/docs/concepts/manifests.md)): ```c sona_manifest m; sona_guid tee; const uint32_t colours[3] = { 0xff2a5caa, 0xffffffff, 0xffffffff }; /* 0xAARRGGBB */ if (sona_manifest_parse(manifest, &m) == SONA_OK && sona_guid_parse("00000008-006e-0001-c1c8-f109a19cb2e0", &tee) == SONA_OK && sona_manifest_wear(&m, &tee, colours, 0) == SONA_OK && sona_manifest_write(&m, manifest) == SONA_OK) sona_avatar_add(ctx, manifest, NULL, &avatar); ``` Puts an item on, with its three colours. ### sona_manifest_unwear ```c sona_result sona_manifest_unwear(sona_manifest *m, uint32_t slot_mask, uint32_t flags); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | | `slot_mask` | `uint32_t` | The slots to take off | - | | `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_manifest x_manifest; memset(&x_manifest, 0, sizeof x_manifest); sona_result result = sona_manifest_unwear(&x_manifest, 0, 0); if (result != SONA_OK) printf("sona_manifest_unwear: %s\n", sona_result_name(result)); ``` Takes off what is in the slots of `slot_mask`. ### sona_manifest_undress_all ```c sona_result sona_manifest_undress_all(sona_manifest *m); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_manifest x_manifest; memset(&x_manifest, 0, sizeof x_manifest); sona_result result = sona_manifest_undress_all(&x_manifest); if (result != SONA_OK) printf("sona_manifest_undress_all: %s\n", sona_result_name(result)); ``` Takes everything off. ### sona_manifest_set_colour ```c sona_result sona_manifest_set_colour(sona_manifest *m, uint32_t colour_slot, uint32_t argb); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | | `colour_slot` | `uint32_t` | Which of the manifest's colours to set | - | | `argb` | `uint32_t` | The colour, 0xAARRGGBB | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_manifest x_manifest; memset(&x_manifest, 0, sizeof x_manifest); sona_result result = sona_manifest_set_colour(&x_manifest, 0, 0); if (result != SONA_OK) printf("sona_manifest_set_colour: %s\n", sona_result_name(result)); ``` Sets one of the nine body colours, by its index in `colours`. ### sona_manifest_set_gender ```c sona_result sona_manifest_set_gender(sona_manifest *m, uint32_t gender, uint32_t flags); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | | `gender` | `uint32_t` | 1 male, 2 female | - | | `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_manifest x_manifest; memset(&x_manifest, 0, sizeof x_manifest); sona_result result = sona_manifest_set_gender(&x_manifest, 0, 0); if (result != SONA_OK) printf("sona_manifest_set_gender: %s\n", sona_result_name(result)); ``` Sets the gender: 1 male, 2 female. ### sona_manifest_set_shape ```c sona_result sona_manifest_set_shape(sona_manifest *m, float weight, float height); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | | `weight` | `float` | The body's weight, as the manifest stores it | - | | `height` | `float` | The body's height, as the manifest stores it | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_manifest x_manifest; memset(&x_manifest, 0, sizeof x_manifest); sona_result result = sona_manifest_set_shape(&x_manifest, 0.5f, 16); if (result != SONA_OK) printf("sona_manifest_set_shape: %s\n", sona_result_name(result)); ``` Sets the weight and height. ### sona_manifest_ready_for_xbox ```c int sona_manifest_ready_for_xbox(const sona_manifest *m); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `const sona_manifest *` | A [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | **Returns** `int`. **Example**: ```c sona_manifest x_manifest; memset(&x_manifest, 0, sizeof x_manifest); int x_got = sona_manifest_ready_for_xbox(&x_manifest); printf("sona_manifest_ready_for_xbox: %lld\n", (long long)x_got); ``` 1 when the body (and so the gender) is known and the editor's Xbox clean-up would change nothing: the manifest can be saved to Xbox as it is. 0 otherwise. ## Credit `sona_draw` and `sona_snapshot` draw a small "Powered by 360sona" badge, its opacity set to 75%, unless `SONA_DRAW_NO_CREDIT`; an app that turns it off credits 360sona itself, in its credits, about page, footer or store page. `sona_credit` is `{text ("Powered by 360sona"), url ("https://360sona.com"), rgba (the badge in the SDK's pixel font at the given scale, at full strength: engines show it at 75%, as `sona_draw` does), width, height}`. ### sona_credit_get ```c sona_result sona_credit_get(sona_ctx *ctx, uint32_t scale, sona_credit *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `scale` | `uint32_t` | The badge's scale: 1, 2 or 3 | - | | `out` | `sona_credit *` | Receives the [`sona_credit`](https://360sona.com/devs/docs/reference/fields.md#sona_credit) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The credit](https://360sona.com/devs/docs/concepts/credit.md)): ```c sona_credit credit; if (sona_credit_get(ctx, 2, &credit) == SONA_OK) { /* credit.rgba is credit.width x credit.height RGBA pixels: show them at 75%, linked to credit.url */ } ``` The credit text, link and badge. `scale` is 1 for the badge; `max(1, round(min(w, h) / 400))` for snapshots, as the web. Engine plugins draw this badge in a corner. ## The offline catalogue The full contracts, the structs, the flags and the file format are in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md). The catalogue is a handle of its own: it needs no ctx after loading and any thread may read it. ### sona_catalogue_load ```c sona_result sona_catalogue_load(sona_ctx *ctx, const char *path, sona_catalogue **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `path` | `const char *` | A file path | required | | `out` | `sona_catalogue **` | Receives the new catalogue | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c sona_result sona_catalogue_load(sona_ctx *ctx, const char *path, sona_catalogue **out); ``` Loads `sona-catalogue.bin` from a UTF-8 path and checks every byte. `ctx` may be `NULL`. `SONA_E_IO`, `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED`. ### sona_catalogue_load_memory ```c sona_result sona_catalogue_load_memory(sona_ctx *ctx, const void *bytes, size_t len, sona_catalogue **out); ``` | 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 | - | | `out` | `sona_catalogue **` | Receives the new catalogue | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c sona_result sona_catalogue_load_memory(sona_ctx *ctx, const void *bytes, size_t len, sona_catalogue **out); ``` The same from bytes in memory. The catalogue keeps its own copy. ### sona_catalogue_free ```c void sona_catalogue_free(sona_catalogue *cat); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `sona_catalogue *` | The catalogue | required | **Returns** Nothing. **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c void sona_catalogue_free(sona_catalogue *cat); ``` Frees it and every string it handed out. `NULL` is fine. ### sona_catalogue_count ```c uint32_t sona_catalogue_count(const sona_catalogue *cat); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | **Returns** `uint32_t`. **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c uint32_t sona_catalogue_count(const sona_catalogue *cat); ``` Items, sorted by id. 0 for `NULL`. ### sona_catalogue_get ```c sona_result sona_catalogue_get(const sona_catalogue *cat, uint32_t index, sona_item_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | | `index` | `uint32_t` | Which one, from 0 | - | | `out` | `sona_item_info *` | Receives the [`sona_item_info`](https://360sona.com/devs/docs/reference/fields.md#sona_item_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c sona_result sona_catalogue_get(const sona_catalogue *cat, uint32_t index, sona_item_info *out); ``` One item. Its strings live as long as the catalogue. ### sona_catalogue_find ```c int32_t sona_catalogue_find(const sona_catalogue *cat, const char *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | | `id` | `const char *` | An item id: 32 hex digits, with or without dashes, braces or spaces | required | **Returns** `int32_t`. **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c int32_t sona_catalogue_find(const sona_catalogue *cat, const char *id); ``` The index of an id in any spelling, or -1. A binary search. ### sona_catalogue_find_guid ```c int32_t sona_catalogue_find_guid(const sona_catalogue *cat, const sona_guid *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | | `id` | `const sona_guid *` | An item id | required | **Returns** `int32_t`. **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c int32_t sona_catalogue_find_guid(const sona_catalogue *cat, const sona_guid *id); ``` The same from a parsed GUID. ### sona_catalogue_search ```c sona_result sona_catalogue_search(const sona_catalogue *cat, const sona_catalogue_query *q, uint32_t *out_indexes, uint32_t max, uint32_t *total); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | | `q` | `const sona_catalogue_query *` | A [`sona_catalogue_query`](https://360sona.com/devs/docs/reference/fields.md#sona_catalogue_query) | required | | `out_indexes` | `uint32_t *` | Receives catalogue indexes, up to `max` | required | | `max` | `uint32_t` | How many entries `out` holds | - | | `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c sona_result sona_catalogue_search(const sona_catalogue *cat, const sona_catalogue_query *q, uint32_t *out_indexes, uint32_t max, uint32_t *total); ``` Indexes matching a query (words, game, slots, section, body, flags, paging), in id order. ### sona_catalogue_game_count ```c uint32_t sona_catalogue_game_count(const sona_catalogue *cat); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | **Returns** `uint32_t`. **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c uint32_t sona_catalogue_game_count(const sona_catalogue *cat); sona_result sona_catalogue_game(const sona_catalogue *cat, uint32_t index, const char **name, uint32_t *items); ``` How many distinct games items come from. ### sona_catalogue_game ```c sona_result sona_catalogue_game(const sona_catalogue *cat, uint32_t index, const char **name, uint32_t *items); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | | `index` | `uint32_t` | Which one, from 0 | - | | `name` | `const char **` | Receives the name; lives as long as the catalogue | required | | `items` | `uint32_t *` | Receives how many items the game has; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c uint32_t sona_catalogue_game_count(const sona_catalogue *cat); sona_result sona_catalogue_game(const sona_catalogue *cat, uint32_t index, const char **name, uint32_t *items); ``` One game, sorted by name, and its item count. ### sona_catalogue_generated ```c const char *sona_catalogue_generated(const sona_catalogue *cat); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | **Returns** `const char *`. **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c const char *sona_catalogue_generated(const sona_catalogue *cat); ``` When its data was made, ISO 8601. ### sona_catalogue_section_name ```c const char *sona_catalogue_section_name(uint32_t section); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `section` | `uint32_t` | A `SONA_SECTION_*` | - | **Returns** `const char *`. **Example** (also in [The offline catalogue](https://360sona.com/devs/docs/guides/catalogue.md)): ```c const char *sona_catalogue_section_name(uint32_t section); ``` A `sona_section` as the editor spells it; `NULL` past the last. ### sona_catalogue_language_count ```c uint32_t sona_catalogue_language_count(const sona_catalogue *cat); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | **Returns** `uint32_t`. **Example** (also in [Item names in other languages](https://360sona.com/devs/docs/guides/catalogue-languages.md)): ```c uint32_t n = sona_catalogue_language_count(cat); /* "en" among them */ const char *tag = sona_catalogue_language(cat, i); /* "cs", "da", "de", "el", "en", "en-GB", "es", ... */ const char *name; if (sona_catalogue_item_name(cat, index, "pt-PT", &name) == SONA_OK) show(name); else show(info.name); /* SONA_E_NOT_FOUND: that market used the English name */ ``` How many languages the catalogue carries item names in. Each is a BCP 47 tag ("de", "ja", "pt-BR"), sorted; "en" is always one. ### sona_catalogue_language ```c const char * sona_catalogue_language(const sona_catalogue *cat, uint32_t index); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | | `index` | `uint32_t` | Which one, from 0 | - | **Returns** `const char *`. **Example** (also in [Item names in other languages](https://360sona.com/devs/docs/guides/catalogue-languages.md)): ```c uint32_t n = sona_catalogue_language_count(cat); /* "en" among them */ const char *tag = sona_catalogue_language(cat, i); /* "cs", "da", "de", "el", "en", "en-GB", "es", ... */ const char *name; if (sona_catalogue_item_name(cat, index, "pt-PT", &name) == SONA_OK) show(name); else show(info.name); /* SONA_E_NOT_FOUND: that market used the English name */ ``` The language tag at `index` (see `sona_catalogue_language_count`); NULL past the last. ### sona_catalogue_item_name ```c sona_result sona_catalogue_item_name(const sona_catalogue *cat, uint32_t index, const char *lang, const char **name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `cat` | `const sona_catalogue *` | The catalogue | required | | `index` | `uint32_t` | Which one, from 0 | - | | `lang` | `const char *` | A language tag, such as `"fr"` or `"pt-BR"` | required | | `name` | `const char **` | Receives the name; lives as long as the catalogue | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Item names in other languages](https://360sona.com/devs/docs/guides/catalogue-languages.md)): ```c uint32_t n = sona_catalogue_language_count(cat); /* "en" among them */ const char *tag = sona_catalogue_language(cat, i); /* "cs", "da", "de", "el", "en", "en-GB", "es", ... */ const char *name; if (sona_catalogue_item_name(cat, index, "pt-PT", &name) == SONA_OK) show(name); else show(info.name); /* SONA_E_NOT_FOUND: that market used the English name */ ``` An item's name in lang (an exact tag first, then the market the Xbox 360 marketplace served it from, then its language: [catalogue languages guide](https://360sona.com/devs/docs/guides/catalogue-languages.md)); it lives as long as the catalogue. `SONA_E_NOT_FOUND` when the item has no name in that language: show `sona_item_info`.name. ### sona_item_colourways ```c sona_result sona_item_colourways(sona_ctx *ctx, const char *item_id, uint32_t (*out)[3], uint32_t cap, uint32_t *count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `item_id` | `const char *` | An item id as text | required | | `out` | `uint32_t (*out)[3]` | Receives three colours per colourway | required | | `cap` | `uint32_t` | How many entries `out` holds | - | | `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). An item's own colourways (its colour table): up to cap sets of primary, secondary and tertiary colours (0xFFRRGGBB) into out, and how many it has in *count (0 for an item without a table). Wearing the item with one set's three colours in its `sona_asset_ref`.colours (`sona_manifest_wear`) wears that colourway; colours that match no set wear the first. The item is read through the ctx's sources: `SONA_PENDING` until it has loaded (call again after `sona_update`), `SONA_E_NOT_FOUND` when no source has it, `SONA_E_ARGUMENT` for a bad id. ## The stock clip library and the procedural idle Section 3.22 of the header. The guide, with the full clip table, the tags and how every clip was named, is [Clips](https://360sona.com/devs/docs/guides/clips.md). The library calls are pure (no ctx) and safe from any thread. Structs carry a `size` the caller sets to `sizeof`; a call fills at most that many bytes. ### sona_stock_clip_count ```c uint32_t sona_stock_clip_count(void); ``` **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_stock_clip_count(); printf("sona_stock_clip_count: %lld\n", (long long)x_got); ``` The clips in the library: 100 (`SONA_STOCK_CLIP_COUNT`). ### sona_stock_clip_at ```c sona_result sona_stock_clip_at(uint32_t index, sona_stock_clip *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `index` | `uint32_t` | Which one, from 0 | - | | `out` | `sona_stock_clip *` | Receives the [`sona_stock_clip`](https://360sona.com/devs/docs/reference/fields.md#sona_stock_clip) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_stock_clip x_stock_clip; memset(&x_stock_clip, 0, sizeof x_stock_clip); x_stock_clip.size = sizeof x_stock_clip; sona_result result = sona_stock_clip_at(0, &x_stock_clip); if (result != SONA_OK) printf("sona_stock_clip_at: %s\n", sona_result_name(result)); ``` The clip at index, in id order. `SONA_E_NOT_FOUND` past the end, `SONA_E_ARGUMENT` for a `NULL` out or a size below 8. ### sona_stock_clip_get ```c sona_result sona_stock_clip_get(uint32_t id, sona_stock_clip *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `id` | `uint32_t` | A stock clip id, from 1 | - | | `out` | `sona_stock_clip *` | Receives the [`sona_stock_clip`](https://360sona.com/devs/docs/reference/fields.md#sona_stock_clip) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_stock_clip x_stock_clip; memset(&x_stock_clip, 0, sizeof x_stock_clip); x_stock_clip.size = sizeof x_stock_clip; sona_result result = sona_stock_clip_get(0, &x_stock_clip); if (result != SONA_OK) printf("sona_stock_clip_get: %s\n", sona_result_name(result)); ``` The clip with this id (`SONA_STOCK_*`: bytes 4 to 7 of its asset id). `SONA_E_NOT_FOUND` for an unknown id. ### sona_stock_clip_find ```c uint32_t sona_stock_clip_find(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | The name to look up | required | **Returns** `uint32_t`. **Example** (also in [Clips: the stock clip library and the procedural idle](https://360sona.com/devs/docs/guides/clips.md)): ```c /* every idle this body can play, the procedural idle on top */ uint32_t ids[64], n = sona_stock_clips_tagged(SONA_CLIP_TAG_IDLE, SONA_CLIP_TAG_COPY, body, ids, 64); sona_idle_options idle; sona_idle_defaults(&idle); /* blinks, glances, weight shifts and breathing, seed from the ctx */ sona_avatar_idle(avatar, &idle); sona_avatar_play_stock(avatar, SONA_STOCK_WAVE, NULL, 0.3f); /* crossfade into a wave */ sona_avatar_play_stock(avatar, sona_stock_clip_find("laugh"), NULL, 0); /* NULL opts: loops when the clip loops */ ``` A library name (`"wave"`), an asset id in either case or a `sona_clip_get` key (`"GenericWave"`); 0 when none. ### sona_stock_clip_for_body ```c uint32_t sona_stock_clip_for_body(uint32_t id, uint32_t body); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `id` | `uint32_t` | A stock clip id | - | | `body` | `uint32_t` | The body a clip or item is for: 1 male, 2 female | - | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_stock_clip_for_body(0, 0); printf("sona_stock_clip_for_body: %lld\n", (long long)x_got); ``` The clip of id's family made for body (1 male, 2 female): its own variant, else one for both, else id itself. ### sona_stock_clips_tagged ```c uint32_t sona_stock_clips_tagged(uint32_t all, uint32_t none, uint32_t body, uint32_t *ids, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `all` | `uint32_t` | Tag bits a clip must all have | - | | `none` | `uint32_t` | Tag bits a clip must not have | - | | `body` | `uint32_t` | The body the clips must suit: 1 male, 2 female; 0: any | `0`: any | | `ids` | `uint32_t *` | Receives the ids; may be NULL to count | `NULL`: not written | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example** (also in [Clips: the stock clip library and the procedural idle](https://360sona.com/devs/docs/guides/clips.md)): ```c /* every idle this body can play, the procedural idle on top */ uint32_t ids[64], n = sona_stock_clips_tagged(SONA_CLIP_TAG_IDLE, SONA_CLIP_TAG_COPY, body, ids, 64); sona_idle_options idle; sona_idle_defaults(&idle); /* blinks, glances, weight shifts and breathing, seed from the ctx */ sona_avatar_idle(avatar, &idle); sona_avatar_play_stock(avatar, SONA_STOCK_WAVE, NULL, 0.3f); /* crossfade into a wave */ sona_avatar_play_stock(avatar, sona_stock_clip_find("laugh"), NULL, 0); /* NULL opts: loops when the clip loops */ ``` Clips with every `SONA_CLIP_TAG_*` bit of all and none of none that suit body (0 any; 1 or 2: that body's clips and the clips for both), in id order. Returns how many match and writes up to cap ids; ids may be `NULL` with cap 0. ### sona_clip_tag_name ```c const char *sona_clip_tag_name(uint32_t tag); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `tag` | `uint32_t` | A tag's bit | - | **Returns** `const char *`. **Example**: ```c const char * x_got = sona_clip_tag_name(0); printf("sona_clip_tag_name: %s\n", x_got ? "a value" : "none"); ``` The name of one tag bit (`"idle"`, `"travel"`, ...); `NULL` for 0, several bits or an unknown bit. ### sona_clip_tag_find ```c uint32_t sona_clip_tag_find(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | The name to look up | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_clip_tag_find("speed"); printf("sona_clip_tag_find: %lld\n", (long long)x_got); ``` The bit for a tag name; 0 when none. ### sona_avatar_play_stock ```c sona_result sona_avatar_play_stock(sona_avatar *a, uint32_t id, const sona_play_options *opts, float fade_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `id` | `uint32_t` | A stock clip id | - | | `opts` | `const sona_play_options *` | The options, a [`sona_play_options`](https://360sona.com/devs/docs/reference/fields.md#sona_play_options) | required | | `fade_seconds` | `float` | Seconds to blend over | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_placement to = { { 2.0f, 0.0f, -3.0f }, 90.0f, 1.0f }; /* position, turn, scale */ sona_avatar_play_stock(avatar, SONA_STOCK_WALK_FORWARD, NULL, 0.25f); sona_avatar_move(avatar, &to, 2.5f); /* 2.5 s later, when it has arrived: */ sona_avatar_crossfade(avatar, "idle", NULL, 0.3f); ``` Plays id's variant for the avatar's body (`sona_stock_clip_for_body` with the manifest's gender) through `sona_avatar_play`, or `sona_avatar_crossfade` when fade_seconds is above 0. `NULL` opts: loop when the clip has `SONA_CLIP_TAG_LOOP`, speed 1, from 0. `SONA_E_NOT_FOUND` for an unknown id; otherwise what the play call returns. ### sona_idle_defaults ```c void sona_idle_defaults(sona_idle_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_idle_options *` | The [`sona_idle_options`](https://360sona.com/devs/docs/reference/fields.md#sona_idle_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Clips: the stock clip library and the procedural idle](https://360sona.com/devs/docs/guides/clips.md)): ```c sona_idle_options o; sona_idle_defaults(&o); /* parts SONA_IDLE_ALL, seed 0, amount 1, face_px 240 */ o.seed = 42; /* 0: from the ctx seed and the avatar id */ sona_avatar_idle(avatar, &o); /* NULL turns it off */ ``` `size` set, `parts` `SONA_IDLE_ALL`, `seed` 0, `amount` 1, `face_px` 240. ### sona_avatar_idle ```c sona_result sona_avatar_idle(sona_avatar *a, const sona_idle_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_idle_options *` | The options, a [`sona_idle_options`](https://360sona.com/devs/docs/reference/fields.md#sona_idle_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Clips: the stock clip library and the procedural idle](https://360sona.com/devs/docs/guides/clips.md)): ```c sona_idle_options o; sona_idle_defaults(&o); /* parts SONA_IDLE_ALL, seed 0, amount 1, face_px 240 */ o.seed = 42; /* 0: from the ctx seed and the avatar id */ sona_avatar_idle(avatar, &o); /* NULL turns it off */ ``` Turns the procedural idle on with these options, or off for `NULL`. A seed of 0 is resolved from the ctx seed and the avatar id. `SONA_E_ARGUMENT` for a size below 20, unknown parts, amount outside 0..2 or a negative or infinite face_px; `SONA_E_DESTROYED` for a removed avatar. Off, the avatar poses exactly as without it. ### sona_avatar_idle_get ```c sona_result sona_avatar_idle_get(const sona_avatar *a, sona_idle_options *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_idle_options *` | Receives the [`sona_idle_options`](https://360sona.com/devs/docs/reference/fields.md#sona_idle_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_idle_options x_idle_options; memset(&x_idle_options, 0, sizeof x_idle_options); x_idle_options.size = sizeof x_idle_options; sona_result result = sona_avatar_idle_get(avatar, &x_idle_options); if (result != SONA_OK) printf("sona_avatar_idle_get: %s\n", sona_result_name(result)); ``` The options in use, seed resolved; parts 0 when off. ### sona_avatar_idle_state ```c sona_result sona_avatar_idle_state(const sona_avatar *a, sona_idle_state *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_idle_state *` | Receives the [`sona_idle_state`](https://360sona.com/devs/docs/reference/fields.md#sona_idle_state) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_idle_state x_idle_state; memset(&x_idle_state, 0, sizeof x_idle_state); x_idle_state.size = sizeof x_idle_state; sona_result result = sona_avatar_idle_state(avatar, &x_idle_state); if (result != SONA_OK) printf("sona_avatar_idle_state: %s\n", sona_result_name(result)); ``` The channels the idle gave the avatar's last pose (before amount); all 0 before one or when off. ### sona_idle_sample ```c sona_result sona_idle_sample(const sona_idle_options *o, double seconds, sona_idle_state *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `const sona_idle_options *` | The options, a [`sona_idle_options`](https://360sona.com/devs/docs/reference/fields.md#sona_idle_options) | required | | `seconds` | `double` | The time to sample, seconds | - | | `out` | `sona_idle_state *` | Receives the [`sona_idle_state`](https://360sona.com/devs/docs/reference/fields.md#sona_idle_state) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_idle_options x_idle_options; memset(&x_idle_options, 0, sizeof x_idle_options); x_idle_options.size = sizeof x_idle_options; sona_idle_state x_idle_state2; memset(&x_idle_state2, 0, sizeof x_idle_state2); x_idle_state2.size = sizeof x_idle_state2; sona_result result = sona_idle_sample(&x_idle_options, 0.5f, &x_idle_state2); if (result != SONA_OK) printf("sona_idle_sample: %s\n", sona_result_name(result)); ``` Pure: the channels at seconds on the ctx clock for `o->seed` (0 is a seed here) and `o->parts`, before amount. `sona_avatar_idle_state` equals it at the clock of the last pose. `SONA_E_ARGUMENT` for a negative or infinite time. ## Inverse kinematics Two-bone IK for the arms and legs, feet planted on the host's ground, look-at for the head and the eyes, and hand targets. It runs in every pose after the clip, the fades, the overrides and any layers, before skinning. Each struct starts with `size = sizeof(struct)` and is refused (`SONA_E_ARGUMENT`) when `size` is smaller; the `_defaults` functions set it. Avatar calls belong to the owner thread and give `SONA_E_ARGUMENT` for a NULL avatar and `SONA_E_DESTROYED` for one being removed. Every setter re-poses the avatar at the next `sona_update`. The guide, with the limits, the ground modes and the cost, is [Inverse kinematics](https://360sona.com/devs/docs/guides/ik.md). | Struct | Bytes (8-byte pointers) | Fields | |---|---|---| | `sona_ik_target` | 92 | `size`, `flags`, `position[3]`, `rotation[4]`, `pole[3]`, `joint`, `weight`, `fade_seconds`, `reserved[8]` | | `sona_ik_feet` | 88 (80 with 4-byte pointers) | `size`, `ground`, `plane[4]`, `query`, `user`, `weight`, `max_hips_offset`, `max_tilt_deg`, `smoothing`, `reserved[8]` | | `sona_ik_look` | 80 | `size`, `flags`, `target[3]`, `weight`, `max_yaw_deg`, `max_up_deg`, `max_down_deg`, `smoothing`, `max_speed_deg`, `eye_threshold_deg`, `reserved[8]` | | `sona_ik_limits` | 72 | `size`, `flags`, `elbow_max_deg`, `knee_max_deg`, `wrist_swing_deg`, `wrist_twist_deg`, `ankle_swing_deg`, `ankle_twist_deg`, `soft_reach`, `body_margin`, `hip_forward_deg`, `hip_back_deg`, `hip_out_deg`, `hip_in_deg`, `shoulder_back_deg`, `shoulder_across_deg`, `reserved[2]` | | `sona_ik_status` | 88 | `size`, `active`, `error[4]`, `hit[4]`, `hips_offset`, `look_yaw_deg`, `look_pitch_deg`, `eyes[2]`, `pad[2]`, `reserved[8]` | Limbs: `SONA_IK_LEFT_HAND` (0), `SONA_IK_RIGHT_HAND` (1), `SONA_IK_LEFT_FOOT` (2), `SONA_IK_RIGHT_FOOT` (3). ### sona_ik_target_defaults ```c void sona_ik_target_defaults(sona_ik_target *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_ik_target *` | The [`sona_ik_target`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_target) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ik_target x_ik_target; sona_ik_target_defaults(&x_ik_target); sona_ik_target_defaults(&x_ik_target); ``` `size` set, no flags, position 0, rotation (0, 0, 0, 1), joint -1, weight 1, and the fade a default of 0.2 s. NULL is ignored. ### sona_avatar_ik_target ```c sona_result sona_avatar_ik_target(sona_avatar *a, uint32_t limb, const sona_ik_target *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `limb` | `uint32_t` | A `SONA_IK_*` limb | - | | `t` | `const sona_ik_target *` | A [`sona_ik_target`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_target) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_target x_ik_target; sona_ik_target_defaults(&x_ik_target); sona_result result = sona_avatar_ik_target(avatar, 0, &x_ik_target); if (result != SONA_OK) printf("sona_avatar_ik_target: %s\n", sona_result_name(result)); ``` A hand puts its palm (with `SONA_IK_WRIST` its wrist) at `position`; a foot its ankle. Flags: `SONA_IK_ROTATION` (`rotation` is the hand's or foot's world orientation from the rest pose), `SONA_IK_POLE` (`pole` is a point the elbow or knee bends towards), `SONA_IK_RELATIVE` (position, rotation and pole are in the frame of `joint` of this avatar), `SONA_IK_AVATAR_SPACE` (in avatar space, before the placement). `weight` 0..1 eases over `fade_seconds`. NULL `t`: off at once. A foot target replaces planting for that foot. `SONA_E_ARGUMENT` for a limb past 3, a small `size`, an unknown flag, a non-finite position or pole, a weight outside 0..1, a negative fade, a zero quaternion, `SONA_IK_RELATIVE` without a joint (or with `SONA_IK_AVATAR_SPACE`), or `SONA_IK_WRIST` on a foot. ### sona_ik_feet_defaults ```c void sona_ik_feet_defaults(sona_ik_feet *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ik_feet *` | The [`sona_ik_feet`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_feet) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ik_feet x_ik_feet; sona_ik_feet_defaults(&x_ik_feet); sona_ik_feet_defaults(&x_ik_feet); ``` `SONA_IK_GROUND_PLANE` with the plane y = 0, weight 1, hips offset at most 0.45 m, tilt at most 35 degrees, and the smoothing a default of 0.1 s. ### sona_avatar_ik_feet ```c sona_result sona_avatar_ik_feet(sona_avatar *a, const sona_ik_feet *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_ik_feet *` | A [`sona_ik_feet`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_feet) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_feet x_ik_feet; sona_ik_feet_defaults(&x_ik_feet); sona_result result = sona_avatar_ik_feet(avatar, &x_ik_feet); if (result != SONA_OK) printf("sona_avatar_ik_feet: %s\n", sona_result_name(result)); ``` Plants the feet on the ground given by `ground`: `SONA_IK_GROUND_PLANE` (`plane`: n.x, n.y, n.z, d, world), `SONA_IK_GROUND_POINTS` (`sona_avatar_ik_ground` per foot) or `SONA_IK_GROUND_CALLBACK` (`query`, a downward ray the core asks for each foot's heel and toes; it runs on the posing threads, at the same time for different avatars, must be safe from any thread and must not call into sona). The hips move by up to `max_hips_offset`. NULL: off at once. `SONA_E_ARGUMENT` for a small `size`, another mode, a plane with no up component, a callback mode without `query`, or a weight, offset, tilt or smoothing out of range. ### sona_avatar_ik_ground ```c sona_result sona_avatar_ik_ground(sona_avatar *a, uint32_t foot, const float point[3], const float normal[3]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `foot` | `uint32_t` | `SONA_IK_LEFT_FOOT` or `SONA_IK_RIGHT_FOOT` | - | | `point` | `const float [3]` | A point on the ground under the foot, world space | required | | `normal` | `const float [3]` | The ground's normal under the foot | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c float x_point[3]; memset(x_point, 0, sizeof x_point); float x_normal2[3]; memset(x_normal2, 0, sizeof x_normal2); sona_result result = sona_avatar_ik_ground(avatar, 0, x_point, x_normal2); if (result != SONA_OK) printf("sona_avatar_ik_ground: %s\n", sona_result_name(result)); ``` `SONA_IK_GROUND_POINTS`: the world point and normal of the ground under `SONA_IK_LEFT_FOOT` or `SONA_IK_RIGHT_FOOT`, used from the next pose until changed. NULL `point`: no ground under that foot. `SONA_E_ARGUMENT` for another limb, a NULL or zero normal, or a non-finite value. ### sona_ik_look_defaults ```c void sona_ik_look_defaults(sona_ik_look *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ik_look *` | The [`sona_ik_look`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_look) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_ik_look look; sona_ik_look_defaults(&look); look.target[0] = player_head[0]; look.target[1] = player_head[1]; look.target[2] = player_head[2]; sona_avatar_ik_look(avatar, &look); ``` Its defaults are head and eyes, weight 1, yaw 70, up 35, down 45 degrees, smoothing by default 0.15 s, a turn rate of 360 degrees a second, eyes past 10. ### sona_avatar_ik_look ```c sona_result sona_avatar_ik_look(sona_avatar *a, const sona_ik_look *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_ik_look *` | A [`sona_ik_look`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_look) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_ik_look look; sona_ik_look_defaults(&look); look.target[0] = player_head[0]; look.target[1] = player_head[1]; look.target[2] = player_head[2]; sona_avatar_ik_look(avatar, &look); ``` Turns the chest, neck and head towards the world point `target` inside the limits, eased; the eyes take the rest through the face's look shapes when it has them. `SONA_IK_LOOK_HEAD` and `SONA_IK_LOOK_EYES` choose which. NULL: off, easing back. `SONA_E_ARGUMENT` for a small `size`, an unknown flag, a non-finite target, or a limit out of range (yaw 0..135, up and down 0..89, eyes 0..90, speed above 0). ### sona_ik_limits_defaults ```c void sona_ik_limits_defaults(sona_ik_limits *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ik_limits *` | The [`sona_ik_limits`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_limits) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ik_limits x_ik_limits; sona_ik_limits_defaults(&x_ik_limits); sona_ik_limits_defaults(&x_ik_limits); ``` Elbows 145, knees 150, wrists 75 swing and 80 twist, ankles 45 and 30 degrees, hips 120 forward, 25 behind, 45 out and 25 in, shoulders 45 behind (held level) and 50 across, reach easing from 0.97, a 0.02 m body margin, the body checks on. ### sona_avatar_ik_limits ```c sona_result sona_avatar_ik_limits(sona_avatar *a, const sona_ik_limits *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_ik_limits *` | A [`sona_ik_limits`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_limits) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_limits x_ik_limits; sona_ik_limits_defaults(&x_ik_limits); sona_result result = sona_avatar_ik_limits(avatar, &x_ik_limits); if (result != SONA_OK) printf("sona_avatar_ik_limits: %s\n", sona_result_name(result)); ``` The joint limits for this avatar's solves. `SONA_IK_NO_BODY` turns off the checks that keep the limbs clear of the torso, head and legs. Every limit is hard: a target past one is reached short, and a clip already past one is kept, never taken further. NULL: the defaults. `SONA_E_ARGUMENT` for a small `size`, an unknown flag or a value out of range (hips forward 0..150, behind 0..90 and the two together at most 180; out, in and the shoulders 0..90). ### sona_avatar_ik_clear ```c void sona_avatar_ik_clear(sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. **Example**: ```c sona_avatar_ik_clear(avatar); ``` Every target, the planting and the look-at off at once. The next pose is the clip's, bit for bit. NULL is ignored. ### sona_avatar_ik_status ```c sona_result sona_avatar_ik_status(const sona_avatar *a, sona_ik_status *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_ik_status *` | Receives the [`sona_ik_status`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_status) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_status x_ik_status; memset(&x_ik_status, 0, sizeof x_ik_status); x_ik_status.size = sizeof x_ik_status; sona_result result = sona_avatar_ik_status(avatar, &x_ik_status); if (result != SONA_OK) printf("sona_avatar_ik_status: %s\n", sona_result_name(result)); ``` What the last pose did: `active` (`1 << limb`, `SONA_IK_ACTIVE_FEET`, `SONA_IK_ACTIVE_LOOK`), each limb's distance from its target in metres, what held it back (`SONA_IK_HIT_REACH`, `_BEND`, `_POLE`, `_BODY`, `_ROTATION`, `_GROUND`, `_SWING`), the hips' move, the head's turn from the clip and the eye shapes shown (255: the clip's). Set `out->size` first. `SONA_E_NOT_READY` before the avatar was posed with IK on; `SONA_E_ARGUMENT` for a small `size`. ### sona_ik_foot_lock_defaults ```c void sona_ik_foot_lock_defaults(sona_ik_foot_lock *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ik_foot_lock *` | The [`sona_ik_foot_lock`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_foot_lock) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ik_foot_lock x_ik_foot_lock; sona_ik_foot_lock_defaults(&x_ik_foot_lock); sona_ik_foot_lock_defaults(&x_ik_foot_lock); ``` `size` set; `weight` 1, `max_slide` 0.25, `release_seconds` 0.15. ### sona_avatar_ik_foot_lock ```c sona_result sona_avatar_ik_foot_lock(sona_avatar *a, const sona_ik_foot_lock *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_ik_foot_lock *` | A [`sona_ik_foot_lock`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_foot_lock) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_foot_lock x_ik_foot_lock; sona_ik_foot_lock_defaults(&x_ik_foot_lock); sona_result result = sona_avatar_ik_foot_lock(avatar, &x_ik_foot_lock); if (result != SONA_OK) printf("sona_avatar_ik_foot_lock: %s\n", sona_result_name(result)); ``` Foot locking: a foot the clip plants stays where it landed until the clip lifts the heel, so walk and run clips do not slide while the host moves the avatar no faster than the clip's feet travel. Pulled past `max_slide` it lets go. A foot target replaces it for that foot. NULL: off. ### sona_ik_spine_defaults ```c void sona_ik_spine_defaults(sona_ik_spine *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ik_spine *` | The [`sona_ik_spine`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_spine) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ik_spine x_ik_spine; sona_ik_spine_defaults(&x_ik_spine); sona_ik_spine_defaults(&x_ik_spine); ``` `size` set; `weight` 1, `max_bend_deg` 35, `max_twist_deg` 40, `hips_share` 0.2. ### sona_avatar_ik_spine ```c sona_result sona_avatar_ik_spine(sona_avatar *a, const sona_ik_spine *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_ik_spine *` | A [`sona_ik_spine`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_spine) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_spine x_ik_spine; sona_ik_spine_defaults(&x_ik_spine); sona_result result = sona_avatar_ik_spine(avatar, &x_ik_spine); if (result != SONA_OK) printf("sona_avatar_ik_spine: %s\n", sona_result_name(result)); ``` Spine assist: a hand target past the arm's reach bends and turns the spine, and the hips a little, towards it. NULL: off. ### sona_ik_fingers_defaults ```c void sona_ik_fingers_defaults(sona_ik_fingers *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ik_fingers *` | The [`sona_ik_fingers`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_fingers) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ik_fingers x_ik_fingers; sona_ik_fingers_defaults(&x_ik_fingers); sona_ik_fingers_defaults(&x_ik_fingers); ``` `size` set; `spread` 0, `weight` 1, `fade_seconds` 0.15. ### sona_avatar_ik_fingers ```c sona_result sona_avatar_ik_fingers(sona_avatar *a, uint32_t hand, const sona_ik_fingers *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `hand` | `uint32_t` | `SONA_IK_LEFT_HAND` or `SONA_IK_RIGHT_HAND` | - | | `o` | `const sona_ik_fingers *` | A [`sona_ik_fingers`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_fingers) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_fingers x_ik_fingers; sona_ik_fingers_defaults(&x_ik_fingers); sona_result result = sona_avatar_ik_fingers(avatar, 0, &x_ik_fingers); if (result != SONA_OK) printf("sona_avatar_ik_fingers: %s\n", sona_result_name(result)); ``` `hand` `SONA_IK_LEFT_HAND` or `SONA_IK_RIGHT_HAND`. NULL: back to the clip over fade_seconds. ### sona_ik_eyes_defaults ```c void sona_ik_eyes_defaults(sona_ik_eyes *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ik_eyes *` | The [`sona_ik_eyes`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_eyes) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ik_eyes x_ik_eyes; sona_ik_eyes_defaults(&x_ik_eyes); sona_ik_eyes_defaults(&x_ik_eyes); ``` `size` set; `max_speed_deg` 400, `smoothing` 0.05, `lead_seconds` 0.08. ### sona_avatar_ik_eyes ```c sona_result sona_avatar_ik_eyes(sona_avatar *a, const sona_ik_eyes *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_ik_eyes *` | A [`sona_ik_eyes`](https://360sona.com/devs/docs/reference/fields.md#sona_ik_eyes) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ik_eyes x_ik_eyes; sona_ik_eyes_defaults(&x_ik_eyes); sona_result result = sona_avatar_ik_eyes(avatar, &x_ik_eyes); if (result != SONA_OK) printf("sona_avatar_ik_eyes: %s\n", sona_result_name(result)); ``` Smooth eye turns: the eyes move towards the look-at target at up to `max_speed_deg` a second and lead the head by `lead_seconds`. NULL: back to the plain look-at. ## Imported clips Your own glTF, FBX and BVH clips, retargeted onto the avatar rig and played by key like stock clips. The guide, with the naming table and the retarget, is [Bring your own animation](https://360sona.com/devs/docs/guides/import.md). Structs: `sona_import_options`, `sona_import_info`, `sona_bone_map`, and the opaque `sona_anim_file`. ### sona_import_defaults ```c void sona_import_defaults(sona_import_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_import_options *` | The [`sona_import_options`](https://360sona.com/devs/docs/reference/fields.md#sona_import_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Bring your own animation](https://360sona.com/devs/docs/guides/import.md)): ```c sona_import_options o; sona_import_info info; sona_anim_file *f; char why[256]; sona_import_defaults(&o); o.key = "wave_big"; /* NULL: the take's own name */ if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; } while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING) /* waits for the rig data, read through the sources */ sona_update(ctx, 1.0 / 60, &view, NULL); sona_anim_file_free(f); /* the clip is kept; the file is not needed any more */ sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f); ``` Zeroes the options and sets `size`. ### sona_import_formats ```c uint32_t sona_import_formats(void); ``` **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_import_formats(); printf("sona_import_formats: %lld\n", (long long)x_got); ``` `1 << SONA_ANIM_GLTF`, `_FBX` and `_BVH` for each format this build reads. ### sona_anim_file_load ```c sona_result sona_anim_file_load(const void *bytes, size_t len, const sona_import_options *opts, sona_anim_file **out, char *why, size_t why_cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `bytes` | `const void *` | The file's bytes | required | | `len` | `size_t` | How many bytes there are | - | | `opts` | `const sona_import_options *` | The options, a [`sona_import_options`](https://360sona.com/devs/docs/reference/fields.md#sona_import_options) | `NULL` allowed (below) | | `out` | `sona_anim_file **` | Receives the new animation file | 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_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Parses a clip file in memory, no ctx needed. `opts` may be NULL; its `format`, `map` and `flags` are used (the mapping `sona_anim_file_bone` reports). `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED` or `SONA_E_LIMIT` with the reason in `why`. A `.gltf` whose buffers are other files needs `sona_anim_file_open`. ### sona_anim_file_open ```c sona_result sona_anim_file_open(const char *path, const sona_import_options *opts, sona_anim_file **out, char *why, size_t why_cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `path` | `const char *` | A file path | required | | `opts` | `const sona_import_options *` | The options, a [`sona_import_options`](https://360sona.com/devs/docs/reference/fields.md#sona_import_options) | required | | `out` | `sona_anim_file **` | Receives the new animation file | 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_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Bring your own animation](https://360sona.com/devs/docs/guides/import.md)): ```c sona_import_options o; sona_import_info info; sona_anim_file *f; char why[256]; sona_import_defaults(&o); o.key = "wave_big"; /* NULL: the take's own name */ if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; } while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING) /* waits for the rig data, read through the sources */ sona_update(ctx, 1.0 / 60, &view, NULL); sona_anim_file_free(f); /* the clip is kept; the file is not needed any more */ sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f); ``` The same from a path (`SONA_E_IO` when it cannot be read). A BVH take is named after the file. ### sona_anim_file_free ```c void sona_anim_file_free(sona_anim_file *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_anim_file *` | The animation file | required | **Returns** Nothing. **Example** (also in [Bring your own animation](https://360sona.com/devs/docs/guides/import.md)): ```c sona_import_options o; sona_import_info info; sona_anim_file *f; char why[256]; sona_import_defaults(&o); o.key = "wave_big"; /* NULL: the take's own name */ if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; } while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING) /* waits for the rig data, read through the sources */ sona_update(ctx, 1.0 / 60, &view, NULL); sona_anim_file_free(f); /* the clip is kept; the file is not needed any more */ sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f); ``` Imported clips do not need the file once `sona_clip_import` returned. ### sona_anim_file_takes ```c uint32_t sona_anim_file_takes(const sona_anim_file *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_anim_file *` | The animation file | required | **Returns** `uint32_t`. How many takes (animations) the file holds. ### sona_anim_file_take ```c const char *sona_anim_file_take(const sona_anim_file *f, uint32_t index, float *seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_anim_file *` | The animation file | required | | `index` | `uint32_t` | Which one, from 0 | - | | `seconds` | `float *` | Receives the take's length, seconds | required | **Returns** `const char *`. A take's name and length; `NULL` past the last. ### sona_anim_file_bones ```c uint32_t sona_anim_file_bones(const sona_anim_file *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_anim_file *` | The animation file | required | **Returns** `uint32_t`. How many bones the file's skeleton has. ### sona_anim_file_bone ```c const char *sona_anim_file_bone(const sona_anim_file *f, uint32_t index, int32_t *parent, int32_t *joint); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_anim_file *` | The animation file | required | | `index` | `uint32_t` | Which one, from 0 | - | | `parent` | `int32_t *` | Receives the parent bone's index, -1 for a root | required | | `joint` | `int32_t *` | Receives the rig joint the bone drives, -1 for none | required | **Returns** `const char *`. A bone's name, its parent (a lower index, or -1) and the avatar joint it drives (-1 none). `NULL` past the last. ### sona_clip_import ```c sona_result sona_clip_import(sona_ctx *ctx, const sona_anim_file *f, const sona_import_options *opts, sona_import_info *info); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `f` | `const sona_anim_file *` | The animation file | required | | `opts` | `const sona_import_options *` | The options, a [`sona_import_options`](https://360sona.com/devs/docs/reference/fields.md#sona_import_options) | required | | `info` | `sona_import_info *` | Receives what the file holds; may be NULL | `NULL`: not written | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_GATE` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Bring your own animation](https://360sona.com/devs/docs/guides/import.md)): ```c sona_import_options o; sona_import_info info; sona_anim_file *f; char why[256]; sona_import_defaults(&o); o.key = "wave_big"; /* NULL: the take's own name */ if (sona_anim_file_open("wave.fbx", &o, &f, why, sizeof why) != SONA_OK) { puts(why); return; } while (sona_clip_import(ctx, f, &o, &info) == SONA_PENDING) /* waits for the rig data, read through the sources */ sona_update(ctx, 1.0 / 60, &view, NULL); sona_anim_file_free(f); /* the clip is kept; the file is not needed any more */ sona_avatar_crossfade(avatar, "wave_big", NULL, 0.25f); ``` Retargets one take and keeps it under its key (replacing an imported clip of that key). `SONA_PENDING` until the rig data has been read: call again after `sona_update`. `SONA_E_ARGUMENT` for a stock key, an id, an unknown take or a map entry naming no joint; `SONA_E_NOT_FOUND` when no bone matches a joint or the file has no animation; `SONA_E_LIMIT` past 1024 clips. `sona_last_error` has the reason. ### sona_clip_imported_count ```c uint32_t sona_clip_imported_count(const sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_clip_imported_count(ctx); printf("sona_clip_imported_count: %lld\n", (long long)x_got); ``` How many clips have been imported into the ctx. ### sona_clip_imported_get ```c sona_result sona_clip_imported_get(const sona_ctx *ctx, uint32_t index, sona_import_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `index` | `uint32_t` | Which one, from 0 | - | | `out` | `sona_import_info *` | Receives the [`sona_import_info`](https://360sona.com/devs/docs/reference/fields.md#sona_import_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_import_info x_import_info; memset(&x_import_info, 0, sizeof x_import_info); x_import_info.size = sizeof x_import_info; sona_result result = sona_clip_imported_get(ctx, 0, &x_import_info); if (result != SONA_OK) printf("sona_clip_imported_get: %s\n", sona_result_name(result)); ``` `SONA_E_NOT_FOUND` past the last. ### sona_clip_imported_find ```c sona_result sona_clip_imported_find(const sona_ctx *ctx, const char *key, sona_import_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `key` | `const char *` | The key, as it was given when made | required | | `out` | `sona_import_info *` | Receives the [`sona_import_info`](https://360sona.com/devs/docs/reference/fields.md#sona_import_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_import_info x_import_info; memset(&x_import_info, 0, sizeof x_import_info); x_import_info.size = sizeof x_import_info; sona_result result = sona_clip_imported_find(ctx, "GenericWave", &x_import_info); if (result != SONA_OK) printf("sona_clip_imported_find: %s\n", sona_result_name(result)); ``` The imported clip with this key; `SONA_E_NOT_FOUND` when there is none. ### sona_clip_imported_remove ```c sona_result sona_clip_imported_remove(sona_ctx *ctx, const char *key); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `key` | `const char *` | The key, as it was given when made | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_clip_imported_remove(ctx, "GenericWave"); if (result != SONA_OK) printf("sona_clip_imported_remove: %s\n", sona_result_name(result)); ``` Avatars playing it finish with their own reference; new plays of the key fail with `SONA_E_ARGUMENT`. ## Headless rendering and video out A device of the library's own, with no window and no display: the best GPU, or a software rasteriser (lavapipe, llvmpipe) where there is none. Pictures are straight RGBA8, row 0 at the top. Every call runs on the ctx's owner thread and blocks until its pictures are read back. The guide, with the device order, the formats, the sample and the measured gamerpics a second, is [Headless rendering and video](https://360sona.com/devs/docs/guides/headless.md). Structs, each with `size` first (set by its `_defaults`; a smaller `size` is `SONA_E_ARGUMENT`): `sona_headless_options` (64 bytes: `device` `SONA_DEVICE_AUTO`/`GPU`/`SOFTWARE`, `backend` 0/`VULKAN`/`GL`, `adapter` -1, `flags` `SONA_HEADLESS_VALIDATION`, `batch_in_flight` 8 (at most 32), `wait_seconds` 60), `sona_headless_info` (440 bytes: `backend`, `software`, `type`, `vendor_id`, `device_id`, `name[256]`, `driver[128]`), `sona_render_options` (104 bytes, 100 with 4-byte pointers: `width` and `height` 256, `preset` FULL, `yaw_deg`, `pitch_deg`, `zoom` 1, `turn_deg`, `time`, `draw`, `flags` 0, `clip` NULL), `sona_sequence_options` (52 bytes: `frames` 0, `fps` 30, `turn_deg`, `flags` `SONA_SEQUENCE_ORBIT`) and `sona_video_options` (80 bytes, 76: `format`, `width`, `height`, `fps` 30, `loops` 0, `quality` 0, `background` 0xff000000, `flags` `SONA_VIDEO_OPAQUE` / `SONA_VIDEO_NO_DITHER`, `colours` 0, `ffmpeg` NULL). The handles `sona_headless` and `sona_video` are opaque. ### sona_headless_defaults ```c void sona_headless_defaults(sona_headless_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_headless_options *` | The [`sona_headless_options`](https://360sona.com/devs/docs/reference/fields.md#sona_headless_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_headless_options x_headless_options; memset(&x_headless_options, 0, sizeof x_headless_options); x_headless_options.size = sizeof x_headless_options; sona_headless_defaults(&x_headless_options); ``` Fills the defaults above. NULL does nothing. ### sona_headless_devices ```c uint32_t sona_headless_devices(const sona_headless_options *o, sona_headless_info *out, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `const sona_headless_options *` | The options, a [`sona_headless_options`](https://360sona.com/devs/docs/reference/fields.md#sona_headless_options) | `NULL`: the defaults | | `out` | `sona_headless_info *` | Receives the [`sona_headless_info`](https://360sona.com/devs/docs/reference/fields.md#sona_headless_info) | `NULL` allowed (below) | | `cap` | `uint32_t` | How many entries `out` holds | `NULL` allowed (below) | **Returns** `uint32_t`. **Example**: ```c sona_headless_options x_headless_options; memset(&x_headless_options, 0, sizeof x_headless_options); x_headless_options.size = sizeof x_headless_options; sona_headless_info x_headless_info2; memset(&x_headless_info2, 0, sizeof x_headless_info2); x_headless_info2.size = sizeof x_headless_info2; uint32_t x_got = sona_headless_devices(&x_headless_options, &x_headless_info2, 1); printf("sona_headless_devices: %lld\n", (long long)x_got); ``` The devices a headless renderer can open with `o`'s backend: Vulkan devices in the loader's order, then EGL devices. Writes up to `cap` (`out` may be NULL) and returns how many there are. NULL `o`: the defaults; bad options: 0. ### sona_headless_open ```c sona_result sona_headless_open(sona_ctx *ctx, const sona_headless_options *o, sona_headless **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_headless_options *` | The options, a [`sona_headless_options`](https://360sona.com/devs/docs/reference/fields.md#sona_headless_options) | `NULL`: the defaults | | `out` | `sona_headless **` | Receives the new headless renderer | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_headless *h; sona_headless_open(ctx, NULL, &h); /* best GPU, else lavapipe or llvmpipe */ sona_render_options ro; sona_render_defaults(&ro); /* 256 x 256, full body, transparent */ ro.preset = SONA_PRESET_BUST; uint8_t *rgba = malloc(256 * 256 * 4); sona_headless_render_manifest(h, manifest, &ro, rgba); /* waits for the avatar, draws it, removes it */ ``` Makes the device and a renderer on it, waiting up to `wait_seconds` for the ctx's shading data. NULL `o`: the defaults. `SONA_E_UNSUPPORTED` when no device fits (the message says what was tried), `SONA_E_ARGUMENT` for bad options, `SONA_E_NOT_READY` when the shading data did not load in time. ### sona_headless_close ```c void sona_headless_close(sona_headless *h); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `sona_headless *` | The headless renderer | required | **Returns** Nothing. Frees the renderer and the device. NULL is fine. Close it before the ctx. ### sona_headless_info_get ```c sona_result sona_headless_info_get(const sona_headless *h, sona_headless_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `const sona_headless *` | The headless renderer | required | | `out` | `sona_headless_info *` | Receives the [`sona_headless_info`](https://360sona.com/devs/docs/reference/fields.md#sona_headless_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The device it drew on. `SONA_E_ARGUMENT` for NULL arguments. ### sona_headless_renderer ```c sona_renderer *sona_headless_renderer(const sona_headless *h); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `const sona_headless *` | The headless renderer | required | **Returns** `sona_renderer *`. Its renderer, for `sona_renderer_set_quality` and the like. Owned by `h`; do not destroy it. ### sona_render_defaults ```c void sona_render_defaults(sona_render_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_render_options *` | The [`sona_render_options`](https://360sona.com/devs/docs/reference/fields.md#sona_render_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_headless *h; sona_headless_open(ctx, NULL, &h); /* best GPU, else lavapipe or llvmpipe */ sona_render_options ro; sona_render_defaults(&ro); /* 256 x 256, full body, transparent */ ro.preset = SONA_PRESET_BUST; uint8_t *rgba = malloc(256 * 256 * 4); sona_headless_render_manifest(h, manifest, &ro, rgba); /* waits for the avatar, draws it, removes it */ ``` 256 x 256, `SONA_PRESET_FULL`, zoom 1, transparent, no clip. NULL does nothing. ### sona_headless_render ```c sona_result sona_headless_render(sona_headless *h, sona_avatar *a, const sona_render_options *o, uint8_t *rgba_out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `sona_headless *` | The headless renderer | required | | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_render_options *` | The options, a [`sona_render_options`](https://360sona.com/devs/docs/reference/fields.md#sona_render_options) | required | | `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One picture of an avatar of the ctx, alone, after waiting for it to be READY. With `clip` set it plays that clip from `time` (as `sona_avatar_play`, from then on) and is drawn at `time`; without, it is drawn as its clock stands. Its placement, clock and pose are as before when the call returns. `rgba_out` holds `width * height * 4` bytes. `SONA_E_ARGUMENT` for bad options, an item preview, an avatar of another ctx or a clip it does not have; `SONA_E_NOT_READY` after `wait_seconds`; its own failure code when it FAILED. ### sona_headless_render_manifest ```c sona_result sona_headless_render_manifest(sona_headless *h, const uint8_t manifest[SONA_MANIFEST_BYTES], const sona_render_options *o, uint8_t *rgba_out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `sona_headless *` | The headless renderer | required | | `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required | | `o` | `const sona_render_options *` | The options, a [`sona_render_options`](https://360sona.com/devs/docs/reference/fields.md#sona_render_options) | required | | `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_headless *h; sona_headless_open(ctx, NULL, &h); /* best GPU, else lavapipe or llvmpipe */ sona_render_options ro; sona_render_defaults(&ro); /* 256 x 256, full body, transparent */ ro.preset = SONA_PRESET_BUST; uint8_t *rgba = malloc(256 * 256 * 4); sona_headless_render_manifest(h, manifest, &ro, rgba); /* waits for the avatar, draws it, removes it */ ``` Adds the avatar (hidden, standing still or playing `clip` from `time`), draws it and removes it. Errors as above; `SONA_E_MANIFEST` for a manifest that cannot be built, `SONA_E_LIMIT` when the ctx is full. ### sona_headless_batch ```c sona_result sona_headless_batch(sona_headless *h, const uint8_t *manifests, uint32_t count, const sona_render_options *o, sona_picture_fn fn, void *user); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `sona_headless *` | The headless renderer | required | | `manifests` | `const uint8_t *` | The manifests, 1,000 bytes each, one after the other | required | | `count` | `uint32_t` | How many entries the array holds | - | | `o` | `const sona_render_options *` | The options, a [`sona_render_options`](https://360sona.com/devs/docs/reference/fields.md#sona_render_options) | required | | `fn` | `sona_picture_fn` | Called with each picture as it is made | - | | `user` | `void *` | Passed to the callback as it is | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `count` manifests, one after another, to pictures. `fn(user, index, result, rgba, width, height)` runs once for each, in index order; `rgba` is NULL unless `result` is `SONA_OK` and lives until `fn` returns. `batch_in_flight` avatars build ahead; each is removed once drawn. A failing manifest gives its code and the batch goes on. Returns `SONA_OK`, or the error that stopped it (`SONA_E_CONTEXT`, `SONA_E_MEMORY`, a ctx-wide error). `SONA_E_ARGUMENT` for NULL `fn`. ### sona_sequence_defaults ```c void sona_sequence_defaults(sona_sequence_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_sequence_options *` | The [`sona_sequence_options`](https://360sona.com/devs/docs/reference/fields.md#sona_sequence_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_sequence_options so; sona_sequence_defaults(&so); so.turn_deg = 360; so.frames = 36; sona_video_options vo; sona_video_defaults(&vo); vo.width = ro.width; vo.height = ro.height; vo.fps = 18; sona_video *v; sona_video_open(ctx, "turntable.gif", &vo, &v); sona_headless_record(h, avatar, &ro, &so, v); sona_video_finish(v, NULL, NULL); ``` `frames` 0, `fps` 30, no turn. NULL does nothing. ### sona_headless_sequence ```c sona_result sona_headless_sequence(sona_headless *h, sona_avatar *a, const sona_render_options *r, const sona_sequence_options *s, sona_picture_fn fn, void *user); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `sona_headless *` | The headless renderer | required | | `a` | `sona_avatar *` | The avatar | required | | `r` | `const sona_render_options *` | The options, a [`sona_render_options`](https://360sona.com/devs/docs/reference/fields.md#sona_render_options) | required | | `s` | `const sona_sequence_options *` | The options, a [`sona_sequence_options`](https://360sona.com/devs/docs/reference/fields.md#sona_sequence_options) | required | | `fn` | `sona_picture_fn` | Called with each picture as it is made | - | | `user` | `void *` | Passed to the callback as it is | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Frame `i` is the clip at its start + `i / fps` (the render options' `time` with a clip, else the avatar's clock) and the turn `turn_deg * i / frames` (of the avatar, or of the camera with `SONA_SEQUENCE_ORBIT`). `frames` 0: the clip's length at `fps`, rounded; 36 when nothing plays and `turn_deg` is set; else 1. `fn` gets every frame in order. The same inputs give the same pixels every run. The avatar's clock and placement are put back after. ### sona_headless_record ```c sona_result sona_headless_record(sona_headless *h, sona_avatar *a, const sona_render_options *r, const sona_sequence_options *s, sona_video *v); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `h` | `sona_headless *` | The headless renderer | required | | `a` | `sona_avatar *` | The avatar | required | | `r` | `const sona_render_options *` | The options, a [`sona_render_options`](https://360sona.com/devs/docs/reference/fields.md#sona_render_options) | required | | `s` | `const sona_sequence_options *` | The options, a [`sona_sequence_options`](https://360sona.com/devs/docs/reference/fields.md#sona_sequence_options) | required | | `v` | `sona_video *` | The video writer | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_sequence_options so; sona_sequence_defaults(&so); so.turn_deg = 360; so.frames = 36; sona_video_options vo; sona_video_defaults(&vo); vo.width = ro.width; vo.height = ro.height; vo.fps = 18; sona_video *v; sona_video_open(ctx, "turntable.gif", &vo, &v); sona_headless_record(h, avatar, &ro, &so, v); sona_video_finish(v, NULL, NULL); ``` `sona_headless_sequence` into a video. `SONA_E_ARGUMENT` when the video's size is not the render size; a video error stops it. ### sona_video_defaults ```c void sona_video_defaults(sona_video_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_video_options *` | The [`sona_video_options`](https://360sona.com/devs/docs/reference/fields.md#sona_video_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_sequence_options so; sona_sequence_defaults(&so); so.turn_deg = 360; so.frames = 36; sona_video_options vo; sona_video_defaults(&vo); vo.width = ro.width; vo.height = ro.height; vo.fps = 18; sona_video *v; sona_video_open(ctx, "turntable.gif", &vo, &v); sona_headless_record(h, avatar, &ro, &so, v); sona_video_finish(v, NULL, NULL); ``` The defaults are `format` from the path, a frame rate of 30 fps, opaque black background, every other field 0. Set `width` and `height`. ### sona_video_open ```c sona_result sona_video_open(sona_ctx *ctx, const char *path, const sona_video_options *o, sona_video **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `path` | `const char *` | A file path | required | | `o` | `const sona_video_options *` | The options, a [`sona_video_options`](https://360sona.com/devs/docs/reference/fields.md#sona_video_options) | required | | `out` | `sona_video **` | Receives the new video writer | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_sequence_options so; sona_sequence_defaults(&so); so.turn_deg = 360; so.frames = 36; sona_video_options vo; sona_video_defaults(&vo); vo.width = ro.width; vo.height = ro.height; vo.fps = 18; sona_video *v; sona_video_open(ctx, "turntable.gif", &vo, &v); sona_headless_record(h, avatar, &ro, &so, v); sona_video_finish(v, NULL, NULL); ``` Starts a PNG sequence (the path holds one `%d`, `%u` or `%0Nd`), a GIF, or an MP4 or WebM through ffmpeg (started here). NULL `path` keeps a GIF, MP4 or WebM in memory. `SONA_E_ARGUMENT` for bad options, a PNG path without one number, or a NULL path with no format; `SONA_E_UNSUPPORTED` when ffmpeg cannot be run or has no fitting encoder (the message says which); `SONA_E_IO` when the file cannot be made. ### sona_video_frame ```c sona_result sona_video_frame(sona_video *v, const uint8_t *rgba); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `v` | `sona_video *` | The video writer | required | | `rgba` | `const uint8_t *` | Straight RGBA8, row 0 at the top, `width * height * 4` bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One frame of `width * height` straight RGBA8, row 0 at the top. `SONA_E_IO` when the file or ffmpeg failed; a GIF or ffmpeg error sticks. ### sona_video_finish ```c sona_result sona_video_finish(sona_video *v, uint8_t **out, size_t *out_len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `v` | `sona_video *` | The video writer | required | | `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required | | `out_len` | `size_t *` | Receives how many bytes `*out` holds | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Headless rendering and video out](https://360sona.com/devs/docs/guides/headless.md)): ```c sona_sequence_options so; sona_sequence_defaults(&so); so.turn_deg = 360; so.frames = 36; sona_video_options vo; sona_video_defaults(&vo); vo.width = ro.width; vo.height = ro.height; vo.fps = 18; sona_video *v; sona_video_open(ctx, "turntable.gif", &vo, &v); sona_headless_record(h, avatar, &ro, &so, v); sona_video_finish(v, NULL, NULL); ``` Ends the file and frees `v`, also on error. For an in-memory video `*out` and `*out_len` (may be NULL) get the bytes, freed with `sona_free`. `SONA_E_ARGUMENT` for a video with no frames; `SONA_E_IO` with ffmpeg's last line when it failed. ### sona_video_formats ```c uint32_t sona_video_formats(const char *ffmpeg); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ffmpeg` | `const char *` | The ffmpeg program; NULL: `ffmpeg` on the path | `NULL`: `ffmpeg` on the path | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_video_formats("example"); printf("sona_video_formats: %lld\n", (long long)x_got); ``` Bit `1u << format` for each format this machine can write: PNG and GIF always, MP4 and WebM when that ffmpeg (NULL: `$SONA_FFMPEG`, else `ffmpeg` on the PATH) runs and has an encoder for them. ## Skeleton maps and VRM export The guides are [VRM and glTF export](https://360sona.com/devs/docs/guides/vrm.md) (the file, the flattening, the expressions, what was checked) and [Skeleton maps](https://360sona.com/devs/docs/guides/skeleton-maps.md) (the five tables). New structs: `sona_vrm_face`, `sona_export_options` and `sona_export_report`; the last two start with a `size` field, so a later version can grow them. `sona_struct_size` and `sona_struct_offset` know all three. ### sona_skeleton_bone ```c const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `skeleton` | `uint32_t` | A `sona_skeleton_kind` | - | | `joint` | `uint32_t` | A joint index, from `sona_joint_find` | - | **Returns** `const char *`. **Example** (also in [Skeleton maps: Unity Humanoid, VRM and the Unreal mannequins](https://360sona.com/devs/docs/guides/skeleton-maps.md)): ```c const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint); /* NULL: that skeleton has no such bone */ int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone); /* -1: none; names match exactly */ ``` The bone a joint is in a `sona_skeleton_kind` (`SONA_SKELETON_UNITY`, `_VRM`, `_VRM0`, `_UE4`, `_UE5`). `NULL` for a joint that skeleton has no bone for (the shape, prop and special joints), past the last joint or for an unknown skeleton. A static string; any thread. ### sona_skeleton_joint ```c int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `skeleton` | `uint32_t` | A `sona_skeleton_kind` | - | | `bone` | `const char *` | A bone name of that skeleton | required | **Returns** `int32_t`. **Example** (also in [Skeleton maps: Unity Humanoid, VRM and the Unreal mannequins](https://360sona.com/devs/docs/guides/skeleton-maps.md)): ```c const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint); /* NULL: that skeleton has no such bone */ int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone); /* -1: none; names match exactly */ ``` The joint a bone of that skeleton is, matched exactly; -1 when none. ### sona_vrm_expression_name ```c const char *sona_vrm_expression_name(uint32_t expression); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `expression` | `uint32_t` | A VRM expression index | - | **Returns** `const char *`. **Example**: ```c const char * x_got = sona_vrm_expression_name(1); printf("sona_vrm_expression_name: %s\n", x_got ? "a value" : "none"); ``` The VRM 1.0 preset name of a `sona_vrm_expression` (`"aa"` ... `"lookRight"`); `NULL` past the last. ### sona_vrm_face_default ```c sona_result sona_vrm_face_default(uint32_t expression, sona_vrm_face *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `expression` | `uint32_t` | A VRM expression index | - | | `out` | `sona_vrm_face *` | Receives the [`sona_vrm_face`](https://360sona.com/devs/docs/reference/fields.md#sona_vrm_face) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_vrm_face x_vrm_face; memset(&x_vrm_face, 0, sizeof x_vrm_face); sona_result result = sona_vrm_face_default(1, &x_vrm_face); if (result != SONA_OK) printf("sona_vrm_face_default: %s\n", sona_result_name(result)); ``` The face an expression shows by default: a shape index per face part, in `sona_avatar_expression`'s order with left meaning the avatar's own left, 255 for a part it leaves alone. `SONA_E_ARGUMENT` past the last expression. ### sona_export_defaults ```c void sona_export_defaults(sona_export_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_export_options *` | The [`sona_export_options`](https://360sona.com/devs/docs/reference/fields.md#sona_export_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [FBX, Roblox and clips in the export](https://360sona.com/devs/docs/guides/export-fbx.md)): ```c sona_export_options o; uint8_t *fbx = NULL; size_t fbx_len = 0; sona_export_defaults(&o); o.format = SONA_EXPORT_FBX; o.flags = SONA_EXPORT_CLIPS; /* the clip it plays, as an animation on the skeleton */ if (sona_export_avatar(avatar, &o, &fbx, &fbx_len, NULL) == SONA_OK) { FILE *f = fopen("avatar.fbx", "wb"); if (f) { fwrite(fbx, 1, fbx_len, f); fclose(f); } sona_free(ctx, fbx); } ``` Sets `size`, VRM 1.0, Unity bone names, MToon, no flags, every string `NULL` and the most restrictive licence. ### sona_export_avatar ```c sona_result sona_export_avatar(sona_avatar *a, const sona_export_options *o, uint8_t **out, size_t *out_len, sona_export_report *report); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_export_options *` | The options, a [`sona_export_options`](https://360sona.com/devs/docs/reference/fields.md#sona_export_options) | `NULL`: the defaults | | `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required | | `out_len` | `size_t *` | Receives how many bytes `*out` holds | required | | `report` | `sona_export_report *` | Receives what the call did; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [FBX, Roblox and clips in the export](https://360sona.com/devs/docs/guides/export-fbx.md)): ```c sona_export_options o; uint8_t *fbx = NULL; size_t fbx_len = 0; sona_export_defaults(&o); o.format = SONA_EXPORT_FBX; o.flags = SONA_EXPORT_CLIPS; /* the clip it plays, as an animation on the skeleton */ if (sona_export_avatar(avatar, &o, &fbx, &fbx_len, NULL) == SONA_OK) { FILE *f = fopen("avatar.fbx", "wb"); if (f) { fwrite(fbx, 1, fbx_len, f); fclose(f); } sona_free(ctx, fbx); } ``` The avatar as one binary glTF, VRM 1.0 or VRM 0.x file in `*out` (free with `sona_free`). `o` `NULL`: the defaults; fields past `o->size` take their defaults. `report` may be `NULL`; when given, its `size` must be set, and only that much is written. Runs its slow parts on the ctx's workers; call it from the thread that calls `sona_update`. `SONA_E_NOT_READY` before READY, `SONA_E_DESTROYED`, `SONA_E_ARGUMENT` for a bad format, bone names, face table or a `size` of 0, `SONA_E_MEMORY`. ## 3D print export Posed avatars as one watertight, manifold solid for a 3D printer: every part drawn is skinned as the last `sona_update` posed it and rebuilt from a distance field, so overlapping shells unite, inner faces and holes go, every part is at least `min_wall_mm` thick, and an optional base joins the feet. Millimetres, Z up, right-handed; an avatar at turn 0 faces -Y. CPU only, in the calling thread. The guide, with the pipeline, the options table and the independent checks, is [3D print export](https://360sona.com/devs/docs/guides/print3d.md). `sona_print_options` (64 bytes): `{size, flags, height_mm, mm_per_metre, min_wall_mm, voxel_mm, close_mm, base_height_mm, base_margin_mm, base_colour, max_voxels, reserved[5]}`. Flags: `SONA_PRINT_BASE`, `SONA_PRINT_BASE_SQUARE`, `SONA_PRINT_NO_COLOUR`, `SONA_PRINT_LARGEST_ONLY`, `SONA_PRINT_NO_PROPS`. Formats: `SONA_PRINT_STL` (0), `SONA_PRINT_3MF` (1). `sona_print_mesh` (96 bytes, 84 with 4-byte pointers) and `sona_print_report` (112 bytes) carry a `size` the caller sets. `sona_print` is opaque. ### sona_print_defaults ```c void sona_print_defaults(sona_print_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_print_options *` | The [`sona_print_options`](https://360sona.com/devs/docs/reference/fields.md#sona_print_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_print_options x_print_options; memset(&x_print_options, 0, sizeof x_print_options); x_print_options.size = sizeof x_print_options; sona_print_defaults(&x_print_options); ``` `size` set, 120 mm tall, 1.2 mm walls, voxel from the wall, `close_mm` 0.6, a 3 mm base 4 mm round the feet in `0xff3c3c3c` (when `SONA_PRINT_BASE` is set), at most 24,000,000 grid points. NULL does nothing. ### sona_print_avatars ```c sona_result sona_print_avatars(sona_avatar *const *avatars, uint32_t count, const sona_print_options *o, sona_print **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `avatars` | `sona_avatar *const *` | The avatars, `count` of them | required | | `count` | `uint32_t` | How many entries the array holds | - | | `o` | `const sona_print_options *` | The options, a [`sona_print_options`](https://360sona.com/devs/docs/reference/fields.md#sona_print_options) | `NULL`: the defaults | | `out` | `sona_print **` | Receives the new solid | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [3D print export](https://360sona.com/devs/docs/guides/print3d.md)): ```c sona_play_options pl = { 0, 1.0f, 1.25f }; /* no loop, speed 1, from 1.25 s */ sona_avatar_play(a, "GenericWave", &pl); sona_update(ctx, 0, NULL, NULL); sona_avatar_stop(a); sona_update(ctx, 0, NULL, NULL); sona_print_avatars(&a, 1, &opts, &print); ``` One solid from `count` READY avatars of one ctx, as posed by the last `sona_update`, in their placements. To print a clip frame: `sona_avatar_play` with `from` at the time, `sona_update`, `sona_avatar_stop`, `sona_update`. NULL `o`: the defaults. `SONA_E_NOT_READY`, `SONA_E_ARGUMENT` (NULL arguments, bad options, two ctxs), `SONA_E_NOT_FOUND` (nothing with area), `SONA_E_LIMIT` (no grid fits `max_voxels`), `SONA_E_MEMORY`. ### sona_print_triangles ```c sona_result sona_print_triangles(sona_ctx *ctx, const float *positions, uint32_t vertex_count, const uint32_t *indices, uint32_t triangle_count, const uint32_t *colours, const sona_print_options *o, sona_print **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | `NULL` allowed (below) | | `positions` | `const float *` | Three floats a vertex | required | | `vertex_count` | `uint32_t` | How many vertices `positions` holds | - | | `indices` | `const uint32_t *` | Three vertex indexes a triangle | required | | `triangle_count` | `uint32_t` | How many triangles `indices` holds | - | | `colours` | `const uint32_t *` | A colour per vertex, 0xAARRGGBB; NULL: none | `NULL`: none | | `o` | `const sona_print_options *` | The options, a [`sona_print_options`](https://360sona.com/devs/docs/reference/fields.md#sona_print_options) | required | | `out` | `sona_print **` | Receives the new solid | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The same from any triangles, in metres in the SDK's frame, any winding, colours 0xAARRGGBB per vertex or NULL. `ctx` may be NULL (malloc). ### sona_print_get ```c sona_result sona_print_get(const sona_print *p, sona_print_mesh *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `const sona_print *` | The solid | required | | `out` | `sona_print_mesh *` | Receives the [`sona_print_mesh`](https://360sona.com/devs/docs/reference/fields.md#sona_print_mesh) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The solid: counts, shells, volume, area, positions, sRGB colours per vertex, indices (counter-clockwise from outside), bounds (`lo[2]` is 0, centred on x = y = 0) and the scale, wall and grid used. Pointers live as long as `p`. `SONA_E_ARGUMENT` when `out->size` is too small. ### sona_print_encode ```c sona_result sona_print_encode(sona_print *p, uint32_t format, const uint8_t **out, size_t *out_len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_print *` | The solid | required | | `format` | `uint32_t` | The file format to write | - | | `out` | `const uint8_t **` | Receives the bytes; they belong to the solid | required | | `out_len` | `size_t *` | Receives how many bytes `*out` holds | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Binary STL, or 3MF with a colour per vertex (the materials extension's colour group). The bytes live in `p` until the next encode or `sona_print_free`. Deterministic. ### sona_print_free ```c void sona_print_free(sona_print *p); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_print *` | The solid | required | **Returns** Nothing. NULL does nothing. ### sona_print_check ```c sona_result sona_print_check(const float *positions, uint32_t vertex_count, const uint32_t *indices, uint32_t triangle_count, sona_print_report *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `positions` | `const float *` | Three floats a vertex | required | | `vertex_count` | `uint32_t` | How many vertices `positions` holds | - | | `indices` | `const uint32_t *` | Three vertex indexes a triangle | required | | `triangle_count` | `uint32_t` | How many triangles `indices` holds | - | | `out` | `sona_print_report *` | Receives the [`sona_print_report`](https://360sona.com/devs/docs/reference/fields.md#sona_print_report) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Checks any mesh: edges with one or more than two triangles, inconsistent winding, pinched vertices, degenerate and crossing triangles, shells, Euler characteristic, volume, area and bounds; `ok` is 1 when it would print as one closed solid per shell. Pure, no ctx. ## Other players' avatars by id Friends, lobby members and leaderboard rows by id: a gamertag (`Your Gamertag`, `gt:Your Gamertag`, `Name#1234`), a public slot (`a:/`) or a display case (`w:`), looked up through the accounts server's routes (`/sona/v1/gamertag/?client=`, `/sona/a//`, `/sona/w/` with `/sona/wv/` for its version). Kept in memory and in `/players.cache`, asked again after `refresh_s`, at most `per_hour` requests in any hour and `in_flight` at once, backed off on 429, 5xx and no network; the last known look, else the placeholder, when they fail. No ctx; owner thread only. The guide: [Other players' avatars by id](https://360sona.com/devs/docs/guides/players.md). `sona_players_config` (136 bytes, 96 with 4-byte pointers): `{size, max_players, refresh_s, per_hour, in_flight, timeout_ms, host, client, http, cache_dir, placeholder, clock, clock_user, allocator, reserved[8]}`. `sona_player_look` (1200 bytes): `{size, state, error, placeholder, fetched_at, checked_at, next_check, manifest[1000], version[33], name[95], reserved[8]}`. `sona_player_event` (112 bytes): `{size, type, code, reserved, id[96]}`. `sona_players_stats` (96 bytes). States: `SONA_PLAYER_WAITING`, `_FRESH`, `_STALE`, `_PRIVATE`, `_NONE`. Events: `SONA_PLAYER_EVENT_LOOK`, `_GONE`, `_FAILED`. `sona_players` is opaque. ### sona_players_defaults ```c void sona_players_defaults(sona_players_config *c); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `c` | `sona_players_config *` | The [`sona_players_config`](https://360sona.com/devs/docs/reference/fields.md#sona_players_config) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_players_config x_players_config; memset(&x_players_config, 0, sizeof x_players_config); x_players_config.size = sizeof x_players_config; sona_players_defaults(&x_players_config); ``` Zeroes the config and sets `size`; zero fields take the defaults (2048 looks, an interval of 600 s, 60 an hour, 4 at once, a timeout of 15 s). NULL does nothing. ### sona_players_open ```c sona_result sona_players_open(const sona_players_config *c, sona_players **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `c` | `const sona_players_config *` | The options, a [`sona_players_config`](https://360sona.com/devs/docs/reference/fields.md#sona_players_config) | required | | `out` | `sona_players **` | Receives the new players lookup | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Reads the cache file when `cache_dir` is set (a file that does not decode is ignored). `SONA_E_ARGUMENT` for a config with a small `size`, a host that is not `http(s)://` (release builds: `https://` or loopback `http://`), `in_flight` over 16, or a placeholder that is not a manifest; `SONA_E_IO` when `cache_dir` cannot be made; `SONA_E_UNSUPPORTED` with no HTTP layer. ### sona_players_close ```c void sona_players_close(sona_players *p); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | **Returns** Nothing. Writes the cache file when it changed; answers still in flight are dropped. NULL does nothing. ### sona_players_watch ```c sona_result sona_players_watch(sona_players *p, const char *const *ids, uint32_t count, int32_t priority); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | | `ids` | `const char *const *` | Player ids, `count` of them | required | | `count` | `uint32_t` | How many entries the array holds | - | | `priority` | `int32_t` | Higher is looked up sooner | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_APP` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Watches ids and returns at once; known looks are there now, the rest are asked by priority (higher first), then in the order first watched, one request per distinct id. `SONA_E_ARGUMENT` when an id is not an id (it becomes `SONA_PLAYER_NONE`; the others are watched), `SONA_E_LIMIT` past `max_players`. ### sona_players_unwatch ```c void sona_players_unwatch(sona_players *p, const char *const *ids, uint32_t count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | | `ids` | `const char *const *` | Player ids, `count` of them | required | | `count` | `uint32_t` | How many entries the array holds | - | **Returns** Nothing. Stops asking; looks stay cached. `ids` NULL: every id. ### sona_players_refresh ```c sona_result sona_players_refresh(sona_players *p, const char *const *ids, uint32_t count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | | `ids` | `const char *const *` | Player ids, `count` of them | required | | `count` | `uint32_t` | How many entries the array holds | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Asks again now, inside the limits. `ids` NULL: every watched id. `SONA_E_NOT_FOUND` for an id not watched. ### sona_players_update ```c uint32_t sona_players_update(sona_players *p); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | **Returns** `uint32_t`. Each frame: takes answers, sends due requests, writes the cache file (at most every 2 s). Returns the events queued. ### sona_players_poll ```c int sona_players_poll(sona_players *p, sona_player_event *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | | `out` | `sona_player_event *` | Receives the [`sona_player_event`](https://360sona.com/devs/docs/reference/fields.md#sona_player_event) | required | **Returns** `int`. 1 when an event was written, 0 when there are none. `LOOK` when a look arrives or changes, `GONE` when it turns private or goes, `FAILED` once when checks start failing (`code`: `SONA_E_IO`, `SONA_E_LIMIT`, `SONA_E_GATE`, `SONA_E_CORRUPT`, `SONA_E_APP`). ### sona_players_look ```c sona_result sona_players_look(sona_players *p, const char *id, sona_player_look *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | | `id` | `const char *` | An id as text | required | | `out` | `sona_player_look *` | Receives the [`sona_player_look`](https://360sona.com/devs/docs/reference/fields.md#sona_player_look) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Always fills `out` with a look to draw (the placeholder when nothing is known). `SONA_E_NOT_FOUND` for an id never watched nor cached, `SONA_E_ARGUMENT` for one that is not an id. ### sona_players_forget ```c sona_result sona_players_forget(sona_players *p, const char *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_players *` | The players lookup | required | | `id` | `const char *` | An id as text | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Drops the id's look from memory and, at the next write, from the cache file, and stops watching it. `SONA_E_NOT_FOUND` when there was none. ### sona_players_stats_get ```c sona_result sona_players_stats_get(const sona_players *p, sona_players_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `const sona_players *` | The players lookup | required | | `out` | `sona_players_stats *` | Receives the [`sona_players_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_players_stats) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Looks kept, ids watched, requests in flight and due, and counts since open: requests, changed, the same, 304s, gone, failed, read from disk, disk writes, waits for `per_hour`; `paused_until`. ### sona_players_placeholder ```c void sona_players_placeholder(uint8_t out[SONA_MANIFEST_BYTES]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required | **Returns** Nothing. **Example**: ```c uint8_t x_out[SONA_MANIFEST_BYTES]; memset(x_out, 0, sizeof x_out); sona_players_placeholder(x_out); ``` The built-in placeholder: the site's faceless grey mannequin, nothing worn. ## Avatar state, network sync and replays An avatar's whole state as a blob put back exactly; a stream that carries one avatar to a receiver in a few bytes a tick, shown on a puppet with the same pose bits on every receiver fed the same packets; and recordings played at any time, forwards or back. The guide, with what a state holds, the formats and the measured sizes, is [State, network sync, replays](https://360sona.com/devs/docs/guides/netstate.md). All of it runs on the owner thread. Structs (no pointers: one layout for 4- and 8-byte pointers): `sona_state_info` (56 bytes) `{size, version, has_look, parts, clock, reserved[8]}`; `sona_state_status` (40) `{size, mode, pending, missing, applied, reserved[5]}`; `sona_net_options` (48) `{size, tick_hz, history, full_after, reserved[8]}`; `sona_net_look` (1092) `{size, version, kind, manifest[1000], id[64], reserved[4]}`; `sona_net_stats` (64) `{size, packets, bytes, full, newest, oldest, last_bytes, acked, reserved[8]}`; `sona_record_options` (48) `{size, tick_hz, keyframe_ticks, keep_seconds, reserved[8]}`; `sona_replay_info` (60) `{size, tracks, tick_hz, first_tick, last_tick, frames, seconds, reserved[8]}`. `sona_net_sender`, `sona_net_receiver`, `sona_recorder` and `sona_replay` are opaque. Flags and codes: `SONA_STATE_NO_LOOK`; `SONA_STATE_PART_FADE`, `_LAYERS`, `_OVERRIDES`, `_IK`, `_IDLE`, `_QUEUE`; `SONA_STATE_MISSING_CLIP`, `_BLEND`, `_MACHINE`, `_GROUND`, `_POSE`, `_LOOK`; `SONA_STATE_LIVE`, `_WAITING`, `_PUPPET`; `SONA_NET_LOOK_NONE`, `_MANIFEST`, `_ID`. ### sona_avatar_save_state ```c sona_result sona_avatar_save_state(sona_avatar *a, uint32_t flags, uint8_t **out, size_t *out_len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none | | `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required | | `out_len` | `size_t *` | Receives how many bytes `*out` holds | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Avatar state, network sync and replays](https://360sona.com/devs/docs/guides/netstate.md)): ```c uint8_t *blob; size_t n; sona_avatar_save_state(a, 0, &blob, &n); /* 0.4 to 2 KB with the manifest; sona_free */ sona_avatar *b; sona_avatar_add_state(other_ctx, blob, n, NULL, &b); /* a new avatar with the blob's look and state */ /* or, into an avatar that already has the look: sona_avatar_load_state(b, blob, n); */ ``` The blob of a READY avatar's state, freed with `sona_free`; `SONA_STATE_NO_LOOK` leaves the manifest out. `SONA_E_NOT_READY` before READY, `SONA_E_ARGUMENT` for an unknown flag. ### sona_avatar_load_state ```c sona_result sona_avatar_load_state(sona_avatar *a, const void *blob, size_t len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `blob` | `const void *` | The bytes of a saved state | required | | `len` | `size_t` | How many bytes there are | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Avatar state, network sync and replays](https://360sona.com/devs/docs/guides/netstate.md)): ```c uint8_t *blob; size_t n; sona_avatar_save_state(a, 0, &blob, &n); /* 0.4 to 2 KB with the manifest; sona_free */ sona_avatar *b; sona_avatar_add_state(other_ctx, blob, n, NULL, &b); /* a new avatar with the blob's look and state */ /* or, into an avatar that already has the look: sona_avatar_load_state(b, blob, n); */ ``` Puts a saved state on `a` at the next `sona_update` once it is READY and the clips the state needs are loaded; until then the avatar holds still (`SONA_STATE_WAITING`). Afterwards the same updates give the same pose bits as the saved avatar would have. A look that differs is reported (`SONA_STATE_MISSING_LOOK`), not refused. `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED` for a newer format. Ends puppet mode. ### sona_avatar_add_state ```c sona_result sona_avatar_add_state(sona_ctx *ctx, const void *blob, size_t len, const sona_add_options *opts, sona_avatar **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `blob` | `const void *` | The bytes of a saved state | required | | `len` | `size_t` | How many bytes there are | - | | `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](https://360sona.com/devs/docs/reference/fields.md#sona_add_options) | required | | `out` | `sona_avatar **` | Receives the new avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Avatar state, network sync and replays](https://360sona.com/devs/docs/guides/netstate.md)): ```c uint8_t *blob; size_t n; sona_avatar_save_state(a, 0, &blob, &n); /* 0.4 to 2 KB with the manifest; sona_free */ sona_avatar *b; sona_avatar_add_state(other_ctx, blob, n, NULL, &b); /* a new avatar with the blob's look and state */ /* or, into an avatar that already has the look: sona_avatar_load_state(b, blob, n); */ ``` A new avatar with the blob's look, then `sona_avatar_load_state`. `opts` gives the visibility and priority (its clip is ignored). `SONA_E_ARGUMENT` for a blob without a look. ### sona_state_info_get ```c sona_result sona_state_info_get(const void *blob, size_t len, sona_state_info *out, uint8_t manifest[SONA_MANIFEST_BYTES]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `blob` | `const void *` | The bytes of a saved state | required | | `len` | `size_t` | How many bytes there are | - | | `out` | `sona_state_info *` | Receives the [`sona_state_info`](https://360sona.com/devs/docs/reference/fields.md#sona_state_info) | required | | `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | `NULL` allowed (below) | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). What a blob holds, without a ctx; `manifest` (may be NULL) gets the look when there is one. ### sona_avatar_state_status ```c sona_result sona_avatar_state_status(const sona_avatar *a, sona_state_status *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_state_status *` | Receives the [`sona_state_status`](https://360sona.com/devs/docs/reference/fields.md#sona_state_status) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_state_status x_state_status; memset(&x_state_status, 0, sizeof x_state_status); x_state_status.size = sizeof x_state_status; sona_result result = sona_avatar_state_status(avatar, &x_state_status); if (result != SONA_OK) printf("sona_avatar_state_status: %s\n", sona_result_name(result)); ``` `mode` (`SONA_STATE_LIVE`, `_WAITING`, `_PUPPET`), `pending` (a clip of the last state is still loading), `missing` (`SONA_STATE_MISSING_*` of the last state put on) and how many states were put on. All zero for an avatar the module never touched. ### sona_avatar_puppet ```c sona_result sona_avatar_puppet(sona_avatar *a, int on); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `on` | `int` | 1 on, 0 off | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_puppet(avatar, 1); if (result != SONA_OK) printf("sona_avatar_puppet: %s\n", sona_result_name(result)); ``` A puppet's clocks stand still: its clip, layers, fades, moves, IK smoothing and idle change only when a state is put on it. `sona_net_drive` and `sona_replay_drive` make an avatar a puppet; off, it plays on from the last state. ### sona_net_defaults ```c void sona_net_defaults(sona_net_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_net_options *` | The [`sona_net_options`](https://360sona.com/devs/docs/reference/fields.md#sona_net_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_net_options x_net_options; memset(&x_net_options, 0, sizeof x_net_options); x_net_options.size = sizeof x_net_options; sona_net_defaults(&x_net_options); ``` A rate of 30 ticks a second, 64 ticks of history, a full state after 30 ticks without an acknowledgement. ### sona_net_sender_create ```c sona_result sona_net_sender_create(sona_ctx *ctx, const sona_net_options *o, sona_net_sender **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_net_options *` | The options, a [`sona_net_options`](https://360sona.com/devs/docs/reference/fields.md#sona_net_options) | `NULL` allowed (below) | | `out` | `sona_net_sender **` | Receives the new sender | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One stream's sending end. `o` may be NULL. `SONA_E_ARGUMENT` for a `tick_hz` of 0 or over 1000, or a `history` outside 8..1024. ### sona_net_sender_destroy ```c void sona_net_sender_destroy(sona_net_sender *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_net_sender *` | The sender | required | **Returns** Nothing. Frees the sender. ### sona_net_sender_look ```c sona_result sona_net_sender_look(sona_net_sender *s, const char *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_net_sender *` | The sender | required | | `id` | `const char *` | An id as text | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). NULL (the default): the stream sends the avatar's manifest, and again whenever it changes. An id of 1 to 63 bytes sends that instead. Either goes along until a packet carrying it is acknowledged. ### sona_net_write ```c sona_result sona_net_write(sona_net_sender *s, sona_avatar *a, uint32_t tick, uint8_t *out, size_t cap, size_t *len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_net_sender *` | The sender | required | | `a` | `sona_avatar *` | The avatar | required | | `tick` | `uint32_t` | The tick's number | - | | `out` | `uint8_t *` | Receives the bytes | required | | `cap` | `size_t` | How many bytes `out` holds | - | | `len` | `size_t *` | Receives how many bytes were written | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One packet of `a`'s state at `tick`, coded against the newest acknowledged tick (or full). Ticks rise (`SONA_E_ARGUMENT` otherwise). `SONA_E_LIMIT` when `cap` is too small, with `*len` the size needed; `SONA_E_NOT_READY` before READY. ### sona_net_ack ```c void sona_net_ack(sona_net_sender *s, uint32_t tick); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_net_sender *` | The sender | required | | `tick` | `uint32_t` | The tick's number | - | **Returns** Nothing. The receiver holds `tick`. Ticks the sender no longer keeps are ignored. ### sona_net_receiver_create ```c sona_result sona_net_receiver_create(sona_ctx *ctx, const sona_net_options *o, sona_net_receiver **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_net_options *` | The options, a [`sona_net_options`](https://360sona.com/devs/docs/reference/fields.md#sona_net_options) | `NULL` allowed (below) | | `out` | `sona_net_receiver **` | Receives the new receiver | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One stream's receiving end. `o` may be NULL (the defaults). ### sona_net_receiver_destroy ```c void sona_net_receiver_destroy(sona_net_receiver *r); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_net_receiver *` | The receiver | required | **Returns** Nothing. Frees the receiver. ### sona_net_read ```c sona_result sona_net_read(sona_net_receiver *r, const void *packet, size_t len, uint32_t *ack); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_net_receiver *` | The receiver | required | | `packet` | `const void *` | One packet as it arrived | required | | `len` | `size_t` | How many bytes there are | - | | `ack` | `uint32_t *` | Receives the newest tick the sender has seen acknowledged | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Decodes and keeps one packet; `*ack` is the tick to send back. Late and repeated packets are fine. `SONA_E_NOT_FOUND` when its baseline is no longer held, `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED`. ### sona_net_receiver_look ```c sona_result sona_net_receiver_look(const sona_net_receiver *r, sona_net_look *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_net_receiver *` | The receiver | required | | `out` | `sona_net_look *` | Receives the [`sona_net_look`](https://360sona.com/devs/docs/reference/fields.md#sona_net_look) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The newest look the stream carried: `kind` `SONA_NET_LOOK_MANIFEST` with `manifest`, `SONA_NET_LOOK_ID` with `id`, or `SONA_NET_LOOK_NONE` before one arrives; `version` rises with each change. ### sona_net_drive ```c sona_result sona_net_drive(sona_net_receiver *r, sona_avatar *a, double tick); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_net_receiver *` | The receiver | required | | `a` | `sona_avatar *` | The avatar | required | | `tick` | `double` | The tick to show, fractions between two | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Shows `tick` on `a`, which becomes a puppet: a held tick as it is, a fraction between two held ticks as their blend, before the oldest the oldest, past the newest the newest. `SONA_E_NOT_READY` before any state arrived. ### sona_net_sender_stats ```c sona_result sona_net_sender_stats(const sona_net_sender *s, sona_net_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_net_sender *` | The sender | required | | `out` | `sona_net_stats *` | Receives the [`sona_net_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_net_stats) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Packets and bytes written, those without a baseline (`full`), the last packet's size and the newest acknowledged tick. ### sona_net_receiver_stats ```c sona_result sona_net_receiver_stats(const sona_net_receiver *r, sona_net_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_net_receiver *` | The receiver | required | | `out` | `sona_net_stats *` | Receives the [`sona_net_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_net_stats) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Packets and bytes read, packets refused for want of a baseline (`full`), the newest and oldest ticks held. ### sona_record_defaults ```c void sona_record_defaults(sona_record_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_record_options *` | The [`sona_record_options`](https://360sona.com/devs/docs/reference/fields.md#sona_record_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_record_options x_record_options; memset(&x_record_options, 0, sizeof x_record_options); x_record_options.size = sizeof x_record_options; sona_record_defaults(&x_record_options); ``` A rate of 30 ticks a second, a keyframe every 30 ticks, everything kept. ### sona_recorder_create ```c sona_result sona_recorder_create(sona_ctx *ctx, const sona_record_options *o, sona_recorder **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_record_options *` | The options, a [`sona_record_options`](https://360sona.com/devs/docs/reference/fields.md#sona_record_options) | required | | `out` | `sona_recorder **` | Receives the new recorder | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `keep_seconds` above 0 keeps only about the last that many seconds (whole keyframe spans), for kill-cams. ### sona_recorder_destroy ```c void sona_recorder_destroy(sona_recorder *r); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_recorder *` | The recorder | required | **Returns** Nothing. Frees the recorder and what it captured. ### sona_recorder_track ```c sona_result sona_recorder_track(sona_recorder *r, sona_avatar *a, const char *name, uint32_t *track); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_recorder *` | The recorder | required | | `a` | `sona_avatar *` | The avatar | required | | `name` | `const char *` | The track's name, at most 63 bytes; may be NULL | `NULL`: none | | `track` | `uint32_t *` | Receives the track's index | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Records `a` from the next capture on, as track `*track`. At most 256 tracks; `name` at most 63 bytes. ### sona_recorder_capture ```c sona_result sona_recorder_capture(sona_recorder *r, uint32_t tick); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_recorder *` | The recorder | required | | `tick` | `uint32_t` | The tick's number | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Every track's state at `tick` (rising). A track whose avatar is not READY or was removed is left out of that capture. ### sona_recorder_save ```c sona_result sona_recorder_save(sona_recorder *r, uint8_t **out, size_t *out_len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_recorder *` | The recorder | required | | `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required | | `out_len` | `size_t *` | Receives how many bytes `*out` holds | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The file's bytes, freed with `sona_free`. Recording can go on after. ### sona_replay_open ```c sona_result sona_replay_open(sona_ctx *ctx, const void *bytes, size_t len, sona_replay **out); ``` | 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 | - | | `out` | `sona_replay **` | Receives the new replay | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Keeps a copy of the bytes. `SONA_E_CORRUPT`, `SONA_E_UNSUPPORTED` for a newer format. ### sona_replay_close ```c void sona_replay_close(sona_replay *p); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_replay *` | The replay | required | **Returns** Nothing. Frees the replay. ### sona_replay_info_get ```c sona_result sona_replay_info_get(const sona_replay *p, sona_replay_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `const sona_replay *` | The replay | required | | `out` | `sona_replay_info *` | Receives the [`sona_replay_info`](https://360sona.com/devs/docs/reference/fields.md#sona_replay_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The replay's tracks, tick rate, first and last tick, the captures it holds and its length in seconds. ### sona_replay_track ```c sona_result sona_replay_track(const sona_replay *p, uint32_t track, uint8_t manifest[SONA_MANIFEST_BYTES], char name[64], float *from, float *to); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `const sona_replay *` | The replay | required | | `track` | `uint32_t` | A track's index | - | | `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required | | `name` | `char [64]` | Receives the track's name | required | | `from` | `float *` | Receives the track's first time, seconds | required | | `to` | `float *` | Receives the track's last time, seconds | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). A track's look, name and span in seconds from the replay's start; each output may be NULL. ### sona_replay_drive ```c sona_result sona_replay_drive(sona_replay *p, uint32_t track, sona_avatar *a, double seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `p` | `sona_replay *` | The replay | required | | `track` | `uint32_t` | A track's index | - | | `a` | `sona_avatar *` | The avatar | required | | `seconds` | `double` | The time to sample, seconds | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Shows the track at `seconds` from the replay's start on `a`, which becomes a puppet, blending the two frames around it. Any order: the same time always shows the same pose bits. ## Art styles Toon (cel bands of the key light and a hard highlight), flat (the colours, unlit) and silhouette (one colour), each with an optional inverted-hull outline, per avatar or for every avatar a renderer draws. With no style set every picture is the original, byte for byte. Drawn on Vulkan and GL; other backends answer `SONA_E_UNSUPPORTED` and draw the original. The guide: [Art styles](https://360sona.com/devs/docs/guides/styles.md). `sona_style` (48 bytes): `{size, kind, flags, bands, shade, highlight, outline_px, outline, colour, reserved[3]}`. Kinds: `SONA_STYLE_ORIGINAL` (0), `SONA_STYLE_TOON`, `SONA_STYLE_FLAT`, `SONA_STYLE_SILHOUETTE`. Flags: `SONA_STYLE_OUTLINE`, `SONA_STYLE_OVERRIDE` (a renderer's style only). ### sona_style_defaults ```c void sona_style_defaults(sona_style *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_style *` | The [`sona_style`](https://360sona.com/devs/docs/reference/fields.md#sona_style) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Art styles](https://360sona.com/devs/docs/guides/styles.md)): ```c void sona_style_defaults(sona_style *s); sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s); sona_result sona_avatar_style(const sona_avatar *a, sona_style *out); sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s); sona_result sona_renderer_style(const sona_renderer *r, sona_style *out); ``` `size` set, the original look, no flags, 3 bands, shade 0.55, highlight 0.35, a 2 px outline in `0xff141414`, silhouette colour `0xff1e2430`. NULL does nothing. ### sona_avatar_set_style ```c sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `s` | `const sona_style *` | A [`sona_style`](https://360sona.com/devs/docs/reference/fields.md#sona_style) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Art styles](https://360sona.com/devs/docs/guides/styles.md)): ```c void sona_style_defaults(sona_style *s); sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s); sona_result sona_avatar_style(const sona_avatar *a, sona_style *out); sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s); sona_result sona_renderer_style(const sona_renderer *r, sona_style *out); ``` The avatar's own style from the next frame; NULL, or the original look without an outline, clears it. `SONA_E_ARGUMENT` for a parameter out of range, an unknown kind or flag, `SONA_STYLE_OVERRIDE`, a non-zero reserved word or a `size` below `sizeof(sona_style)`; nothing changes then. ### sona_avatar_style ```c sona_result sona_avatar_style(const sona_avatar *a, sona_style *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_style *` | Receives the [`sona_style`](https://360sona.com/devs/docs/reference/fields.md#sona_style) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Art styles](https://360sona.com/devs/docs/guides/styles.md)): ```c void sona_style_defaults(sona_style *s); sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s); sona_result sona_avatar_style(const sona_avatar *a, sona_style *out); sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s); sona_result sona_renderer_style(const sona_renderer *r, sona_style *out); ``` The avatar's own style, or `sona_style_defaults` when it has none. ### sona_renderer_set_style ```c sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `s` | `const sona_style *` | A [`sona_style`](https://360sona.com/devs/docs/reference/fields.md#sona_style) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Art styles](https://360sona.com/devs/docs/guides/styles.md)): ```c void sona_style_defaults(sona_style *s); sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s); sona_result sona_avatar_style(const sona_avatar *a, sona_style *out); sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s); sona_result sona_renderer_style(const sona_renderer *r, sona_style *out); ``` The style of every avatar this renderer draws that has none of its own (with `SONA_STYLE_OVERRIDE`, of every avatar), from the next `sona_draw` or `sona_snapshot`. NULL, or the original look with no flags, clears it. `SONA_E_UNSUPPORTED` (nothing changes) on a backend without styles; `SONA_E_ARGUMENT` as `sona_avatar_set_style`. ### sona_renderer_style ```c sona_result sona_renderer_style(const sona_renderer *r, sona_style *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_renderer *` | The renderer | required | | `out` | `sona_style *` | Receives the [`sona_style`](https://360sona.com/devs/docs/reference/fields.md#sona_style) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Art styles](https://360sona.com/devs/docs/guides/styles.md)): ```c void sona_style_defaults(sona_style *s); sona_result sona_avatar_set_style(sona_avatar *a, const sona_style *s); sona_result sona_avatar_style(const sona_avatar *a, sona_style *out); sona_result sona_renderer_set_style(sona_renderer *r, const sona_style *s); sona_result sona_renderer_style(const sona_renderer *r, sona_style *out); ``` The renderer's style, or the defaults when none. `SONA_E_UNSUPPORTED`, with `out` the defaults, when its backend draws no styles. ## Player screens: the quick creator and the wardrobe picker Two ready-made screens a game opens and gets an avatar back from: the quick creator (eight generated looks, pick one, change one thing, done) and the wardrobe picker (an outfit for this match from the player's own wardrobe, or the catalogue under the host's filter, with a live try-on). The host draws a screen from its node list; input arrives as actions from any device. The guide, with the flow, the controls, the drawing contract and the numbers, is [Quick creator and wardrobe](https://360sona.com/devs/docs/guides/quick-creator.md). Structs: `sona_screen_event` (48 bytes), `sona_screen_theme` (96, 88 with 4-byte pointers), `sona_screen_node` (112, 92), `sona_quick_options` (96, 72), `sona_wardrobe_options` (128, 84), `sona_screen_stats` (108). `sona_screen` is opaque. A screen is used from the ctx's owner thread and destroyed before its ctx. ### sona_screen_theme_defaults ```c void sona_screen_theme_defaults(sona_screen_theme *t, uint32_t preset); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_screen_theme *` | The [`sona_screen_theme`](https://360sona.com/devs/docs/reference/fields.md#sona_screen_theme) to fill with the defaults | required | | `preset` | `uint32_t` | Which preset, one of the header's constants for it | - | **Returns** Nothing. **Example**: ```c sona_screen_theme x_screen_theme; memset(&x_screen_theme, 0, sizeof x_screen_theme); x_screen_theme.size = sizeof x_screen_theme; sona_screen_theme_defaults(&x_screen_theme, 0); ``` `SONA_THEME_DARK`, `SONA_THEME_LIGHT` (the editor module's own palettes) or `SONA_THEME_CONTRAST` (black, white and yellow, with `SONA_THEME_HIGH_CONTRAST` set). `size` set, scale 1, corner 10. ### sona_quick_defaults ```c void sona_quick_defaults(sona_quick_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_quick_options *` | The [`sona_quick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_quick_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_quick_options x_quick_options; memset(&x_quick_options, 0, sizeof x_quick_options); x_quick_options.size = sizeof x_quick_options; sona_quick_defaults(&x_quick_options); ``` `size` set, seed 1, 8 looks, both bodies, no flags. Set `catalogue` before opening. ### sona_quick_open ```c sona_result sona_quick_open(sona_ctx *ctx, const sona_quick_options *o, sona_screen **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_quick_options *` | The options, a [`sona_quick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_quick_options) | required | | `out` | `sona_screen **` | Receives the new screen | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The quick creator; its eight looks start building at once, hidden from `sona_draw`. `SONA_E_ARGUMENT` without a catalogue, for `looks` outside 2..8 or `body` over 2; `SONA_E_NOT_FOUND` when the catalogue after the filter has no hair, clothes or shoes for a body it needs. ### sona_quick_look ```c sona_result sona_quick_look(const sona_quick_options *o, uint32_t shuffle, uint32_t index, uint8_t manifest[SONA_MANIFEST_BYTES]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `const sona_quick_options *` | The options, a [`sona_quick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_quick_options) | required | | `shuffle` | `uint32_t` | How many times the player asked for new looks | - | | `index` | `uint32_t` | Which one, from 0 | - | | `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The quick creator and the wardrobe picker](https://360sona.com/devs/docs/guides/quick-creator.md)): ```c /* catalogue, filter, seed set */ typedef struct quick_hook { sona_quick_options o; uint64_t first; } quick_hook; static int quick_looks(void *user, uint64_t seed, uint32_t index, uint8_t manifest[SONA_MANIFEST_BYTES]) { quick_hook *h = (quick_hook *)user; return sona_quick_look(&h->o, (uint32_t)(seed - h->first), index, manifest) == SONA_OK; } /* sona_editor_options: .seed = h.first = h.o.seed, .look = quick_looks, .look_user = &h, the same .filter */ ``` Look `index` of the set the seed and `shuffle` (X presses so far) make, without a screen or a ctx: the same bytes the screen shows. A screen re-rolls a look whose items are missing from the sources; that one then differs. The editor module's `look` hook takes it in one line (the guide shows it). ### sona_wardrobe_defaults ```c void sona_wardrobe_defaults(sona_wardrobe_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_wardrobe_options *` | The [`sona_wardrobe_options`](https://360sona.com/devs/docs/reference/fields.md#sona_wardrobe_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [The quick creator and the wardrobe picker](https://360sona.com/devs/docs/guides/quick-creator.md)): ```c sona_wardrobe_options wo; sona_wardrobe_defaults(&wo); wo.manifest = my_avatar; /* the player's own, SONA_MANIFEST_BYTES; only clothes change */ wo.catalogue = cat; wo.owned = owned; wo.owned_count = n; /* the player's wardrobe; NULL: the catalogue's items for this body */ wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names; /* saved outfits, first tab */ wo.filter = my_content_filter; wo.title = "Dress for the match"; sona_wardrobe_open(ctx, &wo, &s); ``` `size` set, `flags` `SONA_WARDROBE_STOCK`. Set `manifest` and `catalogue` before opening. ### sona_wardrobe_open ```c sona_result sona_wardrobe_open(sona_ctx *ctx, const sona_wardrobe_options *o, sona_screen **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_wardrobe_options *` | The options, a [`sona_wardrobe_options`](https://360sona.com/devs/docs/reference/fields.md#sona_wardrobe_options) | required | | `out` | `sona_screen **` | Receives the new screen | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The quick creator and the wardrobe picker](https://360sona.com/devs/docs/guides/quick-creator.md)): ```c sona_wardrobe_options wo; sona_wardrobe_defaults(&wo); wo.manifest = my_avatar; /* the player's own, SONA_MANIFEST_BYTES; only clothes change */ wo.catalogue = cat; wo.owned = owned; wo.owned_count = n; /* the player's wardrobe; NULL: the catalogue's items for this body */ wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names; /* saved outfits, first tab */ wo.filter = my_content_filter; wo.title = "Dress for the match"; sona_wardrobe_open(ctx, &wo, &s); ``` The wardrobe picker on the player's manifest. Its lists, outfits and names are copied. Only clothes change. `SONA_E_ARGUMENT` without a manifest or catalogue (or a count without its array), `SONA_E_MANIFEST` for a manifest that does not parse. ### sona_screen_destroy ```c void sona_screen_destroy(sona_screen *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | **Returns** Nothing. Removes the screen's avatars from the ctx and frees it. NULL does nothing. ### sona_screen_kind ```c uint32_t sona_screen_kind(const sona_screen *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_screen *` | The screen | required | **Returns** `uint32_t`. `SONA_SCREEN_KIND_QUICK` or `SONA_SCREEN_KIND_WARDROBE`; 0 for NULL. ### sona_screen_layout ```c sona_result sona_screen_layout(sona_screen *s, uint32_t width, uint32_t height); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The host's size in pixels, 64 to 16384 a side: a wide layout when `width >= height`, a tall one otherwise. Default 1280 x 720. May change at any time. ### sona_screen_set_theme ```c sona_result sona_screen_set_theme(sona_screen *s, const sona_screen_theme *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | | `t` | `const sona_screen_theme *` | A [`sona_screen_theme`](https://360sona.com/devs/docs/reference/fields.md#sona_screen_theme) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Copies the theme; the next nodes use it. ### sona_screen_input ```c sona_result sona_screen_input(sona_screen *s, const sona_screen_event *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | | `in` | `const sona_screen_event *` | A [`sona_screen_event`](https://360sona.com/devs/docs/reference/fields.md#sona_screen_event) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One event: `SONA_INPUT_PRESS` and `_RELEASE` of a `sona_screen_action`, pointer moves, presses and releases, scrolls, and the turn axis. Held directions and tabs repeat by themselves (after a set 0.36 s, then every 0.085 s) until released. `SONA_E_ARGUMENT` for a bad event; a finished screen ignores input. ### sona_screen_update ```c sona_screen_status sona_screen_update(sona_screen *s, double dt_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | | `dt_seconds` | `double` | Seconds since the last update | - | **Returns** `sona_screen_status`. Repeats, turning, the screen's avatars (a rebuilt one replaces the shown one when READY) and the screen's own timers. Call it after `sona_update`. Returns `SONA_SCREEN_RUNNING`, `_DONE`, `_CANCELLED` or `_FINE_TUNE`, and keeps returning a finished status. NULL: `_CANCELLED`. ### sona_screen_nodes ```c uint32_t sona_screen_nodes(sona_screen *s, sona_screen_node *out, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | | `out` | `sona_screen_node *` | Receives the [`sona_screen_node`](https://360sona.com/devs/docs/reference/fields.md#sona_screen_node) | `NULL` allowed (below) | | `cap` | `uint32_t` | How many entries `out` holds | `NULL` allowed (below) | **Returns** `uint32_t`. What to draw, in paint order, with roles, states, boxes in pixels, text and spoken labels; writes up to `cap` (`out` may be NULL) and returns how many there are. Strings live until the next call on the screen. ### sona_screen_announcement ```c int sona_screen_announcement(sona_screen *s, char *out, size_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | | `out` | `char *` | Receives the text, NUL-terminated | required | | `cap` | `size_t` | How many bytes `out` holds | - | **Returns** `int`. The oldest thing a screen reader should say (eight are kept): 1 when one was written (cut at `cap`), 0 when none. ### sona_screen_result ```c sona_result sona_screen_result(const sona_screen *s, uint8_t manifest[SONA_MANIFEST_BYTES]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_screen *` | The screen | required | | `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The avatar the player has now. The quick creator answers `SONA_E_NOT_READY` before a pick; a cancelled wardrobe answers the manifest it opened with. ### sona_screen_stats_get ```c void sona_screen_stats_get(const sona_screen *s, sona_screen_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_screen *` | The screen | required | | `out` | `sona_screen_stats *` | Receives the [`sona_screen_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_screen_stats) | required | **Returns** Nothing. Presses (repeats not counted), taps, changes, shuffles, focus moves, the seconds from open to finish and the presses of each action. ### sona_screen_owns ```c int sona_screen_owns(const sona_screen *s, const sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_screen *` | The screen | required | | `a` | `const sona_avatar *` | The avatar | required | **Returns** `int`. 1 when `a` is one of the screen's avatars, for hosts that read `sona_poll_event`. ### sona_screen_view_avatar ```c sona_avatar *sona_screen_view_avatar(const sona_screen *s, int32_t view); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `const sona_screen *` | The screen | required | | `view` | `int32_t` | Which of the screen's avatar views | - | **Returns** `sona_avatar *`. The avatar a node's `view` shows now, or NULL. It may change between frames. ### sona_screen_view_camera ```c sona_result sona_screen_view_camera(sona_screen *s, int32_t view, uint32_t width, uint32_t height, sona_view *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_screen *` | The screen | required | | `view` | `int32_t` | Which of the screen's avatar views | - | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `out` | `sona_view *` | Receives the [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The view's camera for a `width` x `height` picture (the figure fills the height, turned by the player), for hosts that draw through the data API. `SONA_E_NOT_READY` before READY. ### sona_screen_view_draw ```c sona_result sona_screen_view_draw(sona_renderer *r, sona_screen *s, int32_t view, const sona_target *target, const sona_draw_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `s` | `sona_screen *` | The screen | required | | `view` | `int32_t` | Which of the screen's avatar views | - | | `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](https://360sona.com/devs/docs/reference/fields.md#sona_target) | required | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `sona_draw` of that view alone into `target`. `SONA_E_NOT_READY` while it has nothing to draw. ### sona_screen_view_snapshot ```c sona_result sona_screen_view_snapshot(sona_renderer *r, sona_screen *s, int32_t view, uint32_t width, uint32_t height, const sona_draw_options *opts, uint8_t *rgba_out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `s` | `sona_screen *` | The screen | required | | `view` | `int32_t` | Which of the screen's avatar views | - | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | | `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `sona_snapshot` of that view alone, straight RGBA8. ## Picking Which avatar, which body part or item, and which held prop is under a screen point or along a ray. On the CPU: each avatar's bounding sphere, then boxes per mesh and per run of 64 triangles made from the posed joints, then the triangles, skinned as `sona_pose_vertices` skins them (the scalar maths, so the same bits on every machine), back faces culled and the colour texture's alpha test applied as the draw does. A sprite avatar is met on its quad and the point on the picture goes on into the mesh at the baked turn. On the GPU (Vulkan, GL, GLES): an id buffer of the avatars the ray meets, one pixel, then the hit finished on the CPU on the mesh found. Call between `sona_update` calls, one thread at a time per ctx. The guide, with the cost measured over 1,000 avatars: [Picking](https://360sona.com/devs/docs/guides/picking.md). `sona_pick_options` (56 bytes, 52 with 4-byte pointers): `{size, flags, max_distance, ignore_count, ignore, reserved[8]}`. Flags: `SONA_PICK_HIDDEN`, `SONA_PICK_CULLED`, `SONA_PICK_BACK_FACES`, `SONA_PICK_NO_ALPHA`, `SONA_PICK_NO_PROPS`, `SONA_PICK_BOUNDS`, `SONA_PICK_SPRITES_AS_MESH`. `sona_pick_hit` (176 bytes, 172): `{size, source, flags, avatar_id, avatar, part, section, mask, item[37], mesh, prop, triangle, joint, region, lod, distance, point[3], normal[3], bary[2], uv[2], reserved[8]}`; `source` is `SONA_PICK_SOURCE_MESH`, `_SPRITE` or `_BOUNDS`, `part` is `SONA_PICK_BODY`, `_ITEM` or `_PROP`, `flags` holds `SONA_PICK_HIT_BACK`, `_FACE` and `_GPU`, `region` is a `sona_body_region` (`SONA_REGION_HEAD` .. `SONA_REGION_RIGHT_FOOT`). ### sona_pick_defaults ```c void sona_pick_defaults(sona_pick_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_pick_options *` | The [`sona_pick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_pick_options x_pick_options; memset(&x_pick_options, 0, sizeof x_pick_options); x_pick_options.size = sizeof x_pick_options; sona_pick_defaults(&x_pick_options); ``` `size` set, everything else 0: visible avatars in view, front faces, the alpha test, props, no distance limit. NULL does nothing. ### sona_view_ray ```c sona_result sona_view_ray(const sona_view *v, double x, double y, float origin[3], float dir[3]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `v` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `x` | `double` | A pixel from the picture's left | - | | `y` | `double` | A pixel from the picture's top | - | | `origin` | `float [3]` | Receives the ray's origin | required | | `dir` | `float [3]` | Receives the ray's direction | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); float x_origin2[3]; memset(x_origin2, 0, sizeof x_origin2); float x_dir3[3]; memset(x_dir3, 0, sizeof x_dir3); sona_result result = sona_view_ray(&x_view, 128.0, 128.0, x_origin2, x_dir3); if (result != SONA_OK) printf("sona_view_ray: %s\n", sona_result_name(result)); ``` The ray through the point (x, y) of the view's picture, in pixels from its top left (a pixel's centre is + 0.5): `origin` on the near plane, `dir` of length 1. Pure. `SONA_E_ARGUMENT` for a view with no size or a NULL pointer. ### sona_pick_ray ```c sona_result sona_pick_ray(sona_ctx *ctx, const float origin[3], const float dir[3], const sona_pick_options *o, sona_pick_hit *hit); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `origin` | `const float [3]` | The ray's origin, world space | required | | `dir` | `const float [3]` | The ray's direction, world space | required | | `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_options) | `NULL` allowed (below) | | `hit` | `sona_pick_hit *` | Receives what was hit | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c float x_origin[3]; memset(x_origin, 0, sizeof x_origin); float x_dir2[3]; memset(x_dir2, 0, sizeof x_dir2); sona_pick_options x_pick_options3; memset(&x_pick_options3, 0, sizeof x_pick_options3); x_pick_options3.size = sizeof x_pick_options3; sona_pick_hit x_pick_hit4; memset(&x_pick_hit4, 0, sizeof x_pick_hit4); x_pick_hit4.size = sizeof x_pick_hit4; sona_result result = sona_pick_ray(ctx, x_origin, x_dir2, &x_pick_options3, &x_pick_hit4); if (result != SONA_OK) printf("sona_pick_ray: %s\n", sona_result_name(result)); ``` The nearest hit. `SONA_OK` with `*hit` set, `SONA_E_NOT_FOUND` when nothing is hit (`*hit` then has `size` set and `mesh`, `prop` and `joint` at -1). `o` may be NULL. `dir` need not be unit length; `distance` is in metres along it. Sprites are met as the last `sona_update`'s view faces them. `SONA_E_ARGUMENT` for a zero or non-finite ray, a `size` too small, a negative `max_distance` or `ignore_count` without `ignore`. ### sona_pick_screen ```c sona_result sona_pick_screen(sona_ctx *ctx, const sona_view *v, double x, double y, const sona_pick_options *o, sona_pick_hit *hit); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `v` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `x` | `double` | A pixel from the picture's left | - | | `y` | `double` | A pixel from the picture's top | - | | `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_options) | required | | `hit` | `sona_pick_hit *` | Receives what was hit | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); sona_pick_options x_pick_options2; memset(&x_pick_options2, 0, sizeof x_pick_options2); x_pick_options2.size = sizeof x_pick_options2; sona_pick_hit x_pick_hit3; memset(&x_pick_hit3, 0, sizeof x_pick_hit3); x_pick_hit3.size = sizeof x_pick_hit3; sona_result result = sona_pick_screen(ctx, &x_view, 128.0, 128.0, &x_pick_options2, &x_pick_hit3); if (result != SONA_OK) printf("sona_pick_screen: %s\n", sona_result_name(result)); ``` `sona_view_ray` then `sona_pick_ray`, with the sprites facing this view. ### sona_pick_ray_all ```c uint32_t sona_pick_ray_all(sona_ctx *ctx, const float origin[3], const float dir[3], const sona_pick_options *o, sona_pick_hit *out, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `origin` | `const float [3]` | The ray's origin, world space | required | | `dir` | `const float [3]` | The ray's direction, world space | required | | `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_options) | required | | `out` | `sona_pick_hit *` | Receives the [`sona_pick_hit`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_hit) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example**: ```c float x_origin[3]; memset(x_origin, 0, sizeof x_origin); float x_dir2[3]; memset(x_dir2, 0, sizeof x_dir2); sona_pick_options x_pick_options3; memset(&x_pick_options3, 0, sizeof x_pick_options3); x_pick_options3.size = sizeof x_pick_options3; sona_pick_hit x_pick_hit4; memset(&x_pick_hit4, 0, sizeof x_pick_hit4); x_pick_hit4.size = sizeof x_pick_hit4; uint32_t x_got = sona_pick_ray_all(ctx, x_origin, x_dir2, &x_pick_options3, &x_pick_hit4, 1); printf("sona_pick_ray_all: %lld\n", (long long)x_got); ``` Every avatar the ray hits, each at its nearest hit, nearest first. Returns how many avatars it hits and writes up to `cap` of them (`cap` 0 and `out` NULL only count). 0 on a bad argument. ### sona_avatar_pick ```c sona_result sona_avatar_pick(sona_avatar *a, const float origin[3], const float dir[3], const sona_pick_options *o, sona_pick_hit *hit); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `origin` | `const float [3]` | The ray's origin, world space | required | | `dir` | `const float [3]` | The ray's direction, world space | required | | `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_options) | required | | `hit` | `sona_pick_hit *` | Receives what was hit | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c float x_origin[3]; memset(x_origin, 0, sizeof x_origin); float x_dir2[3]; memset(x_dir2, 0, sizeof x_dir2); sona_pick_options x_pick_options3; memset(&x_pick_options3, 0, sizeof x_pick_options3); x_pick_options3.size = sizeof x_pick_options3; sona_pick_hit x_pick_hit4; memset(&x_pick_hit4, 0, sizeof x_pick_hit4); x_pick_hit4.size = sizeof x_pick_hit4; sona_result result = sona_avatar_pick(avatar, x_origin, x_dir2, &x_pick_options3, &x_pick_hit4); if (result != SONA_OK) printf("sona_avatar_pick: %s\n", sona_result_name(result)); ``` The ray against one avatar; its hidden and culled flags and `o->ignore` do not apply. `SONA_E_NOT_READY` before it is READY and posed, `SONA_E_DESTROYED` once removed. ### sona_region_name ```c const char *sona_region_name(uint32_t region); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `region` | `uint32_t` | A body region index | - | **Returns** `const char *`. **Example**: ```c const char * x_got = sona_region_name(1); printf("sona_region_name: %s\n", x_got ? "a value" : "none"); ``` `"none"`, `"head"`, `"neck"`, `"torso"`, `"hips"`, `"leftArm"`, `"rightArm"`, `"leftHand"`, `"rightHand"`, `"leftLeg"`, `"rightLeg"`, `"leftFoot"`, `"rightFoot"`; NULL past the last. ### sona_pick_gpu ```c sona_result sona_pick_gpu(sona_renderer *r, const sona_view *v, double x, double y, const sona_pick_options *o, sona_pick_hit *hit); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `v` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `x` | `double` | A pixel from the picture's left | - | | `y` | `double` | A pixel from the picture's top | - | | `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_options) | required | | `hit` | `sona_pick_hit *` | Receives what was hit | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_view x_view; sona_view_defaults(&x_view); sona_camera_preset(avatar, SONA_PRESET_FULL, &x_view); sona_pick_options x_pick_options2; memset(&x_pick_options2, 0, sizeof x_pick_options2); x_pick_options2.size = sizeof x_pick_options2; sona_pick_hit x_pick_hit3; memset(&x_pick_hit3, 0, sizeof x_pick_hit3); x_pick_hit3.size = sizeof x_pick_hit3; sona_result result = sona_pick_gpu(r, &x_view, 128.0, 128.0, &x_pick_options2, &x_pick_hit3); if (result != SONA_OK) printf("sona_pick_gpu: %s\n", sona_result_name(result)); ``` The pick through the id buffer: the avatars whose sphere the ray meets are drawn once more, each draw writing its index, into a one-pixel target of the pass's own under a projection of that pixel; the backend reads it back (on Vulkan this submits on the device's queue and waits, as `sona_snapshot` does) and the hit is finished on the CPU on the one mesh found (`SONA_PICK_HIT_GPU` set). Sprite avatars are picked on the CPU and the nearer hit wins. `SONA_E_UNSUPPORTED` on D3D11, D3D12, Metal and Xenos. With `SONA_PICK_BOUNDS` it is the CPU pick. ### sona_pick_gpu_ids ```c sona_result sona_pick_gpu_ids(sona_renderer *r, const sona_view *v, uint32_t x, uint32_t y, uint32_t w, uint32_t h, const sona_pick_options *o, uint32_t *avatar_ids, uint16_t *meshes); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `v` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `x` | `uint32_t` | The region's left edge in pixels | - | | `y` | `uint32_t` | The region's top edge in pixels | - | | `w` | `uint32_t` | The region's width in pixels | - | | `h` | `uint32_t` | The region's height in pixels | - | | `o` | `const sona_pick_options *` | The options, a [`sona_pick_options`](https://360sona.com/devs/docs/reference/fields.md#sona_pick_options) | required | | `avatar_ids` | `uint32_t *` | Receives the avatar id per pixel, `w * h` of them | required | | `meshes` | `uint16_t *` | Receives the mesh index + 1 per pixel; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The id buffer of the region (x, y, w, h) of the view's picture, at most 4096 x 4096 and inside the view: per pixel, row 0 at the top, the avatar id drawn there (0: none) and, when `meshes` is not NULL, its mesh index + 1. Every drawable avatar in the region is drawn, sprite avatars as their meshes in their held pose. For selection outlines and editors. ## Hair and cloth sway Long hair, skirts, dresses, robes, coat tails and earrings swing as the avatar moves, under the ctx's gravity and wind, off the body's capsules. Off by default, per avatar. What sways is read from each worn mesh; those vertices are re-skinned in a shared copy through palette joints the mesh never reads, and the copy draws with its own palette, listed after the props in `sona_pose`. Each struct starts with `size = sizeof(struct)` and is refused (`SONA_E_ARGUMENT`) when `size` is smaller; the `_defaults` functions set it. Avatar calls belong to the owner thread. The guide, with what counts as hanging, the solver and the cost, is [Hair and cloth sway](https://360sona.com/devs/docs/guides/sway.md). | Struct | Bytes | Fields | |---|---|---| | `sona_sway` | 60 | `size`, `parts`, `quality`, `stiffness`, `damping`, `wind_scale`, `min_pixels`, `reserved[8]` | | `sona_sway_world` | 68 | `size`, `gravity[3]`, `wind[3]`, `gust`, `gust_seconds`, `reserved[8]` | | `sona_sway_info` | 68 | `size`, `parts`, `meshes`, `chains`, `nodes`, `vertices`, `steps`, `resting`, `max_offset`, `reserved[8]` | Parts: `SONA_SWAY_HAIR` (1), `SONA_SWAY_CLOTH` (2), `SONA_SWAY_ACCESSORIES` (4, earrings), `SONA_SWAY_HEADWEAR` (8, costume and hat pieces below the head), `SONA_SWAY_DEFAULT` (7), `SONA_SWAY_ALL` (15). Quality: `SONA_SWAY_LOW` (0, 30 steps a second), `SONA_SWAY_MEDIUM` (1, 60), `SONA_SWAY_HIGH` (2, 120). ### sona_sway_defaults ```c void sona_sway_defaults(sona_sway *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_sway *` | The [`sona_sway`](https://360sona.com/devs/docs/reference/fields.md#sona_sway) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Hair and cloth sway](https://360sona.com/devs/docs/guides/sway.md)): ```c sona_sway o; sona_sway_defaults(&o); /* hair, cloth and earrings; medium quality */ sona_avatar_sway(avatar, &o); /* before or after READY */ sona_sway_world w; sona_sway_world_defaults(&w); /* gravity 0 -9.81 0, no wind */ w.wind[0] = 4; /* a 4 m/s breeze along +X, gusting */ sona_sway_world_set(ctx, &w); sona_update(ctx, dt, &view, NULL); /* the chains step inside the poses of this update */ ``` Parts `SONA_SWAY_DEFAULT`, medium quality, stiffness and damping 0.5, wind scale 1, 48 minimum pixels. ### sona_avatar_sway ```c sona_result sona_avatar_sway(sona_avatar *a, const sona_sway *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_sway *` | A [`sona_sway`](https://360sona.com/devs/docs/reference/fields.md#sona_sway) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Hair and cloth sway](https://360sona.com/devs/docs/guides/sway.md)): ```c sona_sway o; sona_sway_defaults(&o); /* hair, cloth and earrings; medium quality */ sona_avatar_sway(avatar, &o); /* before or after READY */ sona_sway_world w; sona_sway_world_defaults(&w); /* gravity 0 -9.81 0, no wind */ w.wind[0] = 4; /* a 4 m/s breeze along +X, gusting */ sona_sway_world_set(ctx, &w); sona_update(ctx, dt, &view, NULL); /* the chains step inside the poses of this update */ ``` Turns sway on with these options, before or after READY (it applies to every later build too). A change of parts re-skins at once and bumps `build_version`. NULL turns it off: the items' own meshes again. `SONA_E_ARGUMENT` for a small `size`, no part or an unknown one, a quality past `SONA_SWAY_HIGH`, stiffness or damping outside 0..1, a wind scale outside 0..100 or negative minimum pixels; `SONA_E_DESTROYED` for an avatar being removed. ### sona_avatar_sway_reset ```c void sona_avatar_sway_reset(sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. **Example**: ```c sona_avatar_sway_reset(avatar); ``` Back to the modelled shape, at rest, at the next pose. NULL is ignored. ### sona_sway_world_defaults ```c void sona_sway_world_defaults(sona_sway_world *w); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `w` | `sona_sway_world *` | The [`sona_sway_world`](https://360sona.com/devs/docs/reference/fields.md#sona_sway_world) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Hair and cloth sway](https://360sona.com/devs/docs/guides/sway.md)): ```c sona_sway o; sona_sway_defaults(&o); /* hair, cloth and earrings; medium quality */ sona_avatar_sway(avatar, &o); /* before or after READY */ sona_sway_world w; sona_sway_world_defaults(&w); /* gravity 0 -9.81 0, no wind */ w.wind[0] = 4; /* a 4 m/s breeze along +X, gusting */ sona_sway_world_set(ctx, &w); sona_update(ctx, dt, &view, NULL); /* the chains step inside the poses of this update */ ``` Gravity 0 -9.81 0, no wind, gust 0.35 with a period of 1.5 s. ### sona_sway_world_set ```c sona_result sona_sway_world_set(sona_ctx *ctx, const sona_sway_world *w); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `w` | `const sona_sway_world *` | A [`sona_sway_world`](https://360sona.com/devs/docs/reference/fields.md#sona_sway_world) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Hair and cloth sway](https://360sona.com/devs/docs/guides/sway.md)): ```c sona_sway o; sona_sway_defaults(&o); /* hair, cloth and earrings; medium quality */ sona_avatar_sway(avatar, &o); /* before or after READY */ sona_sway_world w; sona_sway_world_defaults(&w); /* gravity 0 -9.81 0, no wind */ w.wind[0] = 4; /* a 4 m/s breeze along +X, gusting */ sona_sway_world_set(ctx, &w); sona_update(ctx, dt, &view, NULL); /* the chains step inside the poses of this update */ ``` The gravity and wind every swaying avatar of the ctx feels from its next pose; resting avatars are posed again. NULL: the defaults. `SONA_E_ARGUMENT` for a small `size`, a gust outside 0..1, gust seconds outside 0.05..600, gravity over 1000 or wind over 100 on an axis, or a value that is not finite. ### sona_avatar_sway_info ```c sona_result sona_avatar_sway_info(sona_avatar *a, sona_sway_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `out` | `sona_sway_info *` | Receives the [`sona_sway_info`](https://360sona.com/devs/docs/reference/fields.md#sona_sway_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_sway_info x_sway_info; memset(&x_sway_info, 0, sizeof x_sway_info); x_sway_info.size = sizeof x_sway_info; sona_result result = sona_avatar_sway_info(avatar, &x_sway_info); if (result != SONA_OK) printf("sona_avatar_sway_info: %s\n", sona_result_name(result)); ``` What sways (`parts`, `meshes`, `chains`, `nodes`, `vertices`) and what the last pose did (`steps`, `resting`, `max_offset` in metres). With sway off: `parts` as found in what it wears, the rest 0. `SONA_E_NOT_READY` before READY. ### sona_avatar_sway_mesh_parts ```c uint32_t sona_avatar_sway_mesh_parts(const sona_avatar *a, uint32_t mesh); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `mesh` | `uint32_t` | A mesh index of the pose data | - | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_avatar_sway_mesh_parts(avatar, 0); printf("sona_avatar_sway_mesh_parts: %lld\n", (long long)x_got); ``` The `SONA_SWAY_*` kinds one of `sona_pose`'s meshes sways with; 0 for one that does not, a bad index, or an avatar with sway off or not READY. ## 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](https://360sona.com/devs/docs/guides/custom-items.md). ### sona_custom_item_check ```c sona_result sona_custom_item_check(const void *bytes, size_t len, sona_custom_item_info *info, char *why, size_t why_cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `bytes` | `const void *` | The file's bytes | required | | `len` | `size_t` | How many bytes there are | - | | `info` | `sona_custom_item_info *` | Receives what the file holds; may be NULL | `NULL`: not written | | `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_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). 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 ```c sona_result sona_custom_item_add(sona_ctx *ctx, const void *bytes, size_t len, sona_guid *out_id); ``` | 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 | - | | `out_id` | `sona_guid *` | Receives the item's id | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Custom items](https://360sona.com/devs/docs/guides/custom-items.md)): ```c sona_guid id; sona_manifest m; uint8_t worn[SONA_MANIFEST_BYTES]; if (sona_custom_item_add(ctx, file, file_len, &id) == SONA_OK && /* the bytes of night-sky.sonaitem */ sona_manifest_parse(manifest, &m) == SONA_OK && /* an avatar's 1,000 bytes */ sona_manifest_wear(&m, &id, NULL, 0) == SONA_OK && sona_manifest_write(&m, worn) == SONA_OK) sona_avatar_add(ctx, worn, NULL, &avatar); /* an avatar wearing it */ ``` 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 ```c sona_result sona_custom_item_remove(sona_ctx *ctx, const sona_guid *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `id` | `const sona_guid *` | An item id | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c 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 ```c uint32_t sona_custom_item_count(const sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | **Returns** `uint32_t`. **Example**: ```c 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 ```c sona_result sona_custom_item_get(const sona_ctx *ctx, uint32_t index, sona_custom_item_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `index` | `uint32_t` | Which one, from 0 | - | | `out` | `sona_custom_item_info *` | Receives the [`sona_custom_item_info`](https://360sona.com/devs/docs/reference/fields.md#sona_custom_item_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c 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 ```c sona_result sona_custom_item_find(const sona_ctx *ctx, const sona_guid *id, sona_custom_item_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `id` | `const sona_guid *` | An item id | required | | `out` | `sona_custom_item_info *` | Receives the [`sona_custom_item_info`](https://360sona.com/devs/docs/reference/fields.md#sona_custom_item_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c 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 ```c int sona_guid_is_custom(const sona_guid *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `id` | `const sona_guid *` | An item id | required | **Returns** `int`. **Example**: ```c 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 ```c sona_result sona_guid_pair(const sona_guid *id, sona_guid *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `id` | `const sona_guid *` | An item id | required | | `out` | `sona_guid *` | Receives the [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c 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 ```c sona_result sona_custom_item_new_id(sona_ctx *ctx, const sona_guid *template_id, sona_guid *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `template_id` | `const sona_guid *` | A [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | | `out` | `sona_guid *` | Receives the [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c 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 ```c sona_result sona_custom_item_pack(sona_ctx *ctx, const sona_paint_spec *spec, uint8_t **out, size_t *out_len); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `spec` | `const sona_paint_spec *` | The options, a [`sona_paint_spec`](https://360sona.com/devs/docs/reference/fields.md#sona_paint_spec) | required | | `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required | | `out_len` | `size_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](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). 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](https://360sona.com/devs/docs/guides/custom-items.md) has the format. ### sona_avatar_missing_items ```c uint32_t sona_avatar_missing_items(const sona_avatar *a, sona_guid *out, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_guid *` | Receives the [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example**: ```c 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 ```c void sona_mesh_item_spec_defaults(sona_mesh_item_spec *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_mesh_item_spec *` | The [`sona_mesh_item_spec`](https://360sona.com/devs/docs/reference/fields.md#sona_mesh_item_spec) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c 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 ```c 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 | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `spec` | `const sona_mesh_item_spec *` | The options, a [`sona_mesh_item_spec`](https://360sona.com/devs/docs/reference/fields.md#sona_mesh_item_spec) | required | | `out` | `uint8_t **` | Receives the bytes; free them with `sona_free` | required | | `out_len` | `size_t *` | Receives how many bytes `*out` holds | 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`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_IO` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). 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](https://360sona.com/devs/docs/guides/custom-items.md), sections 5.2 and 5.3). ## Lip sync and voice mouths Mouth shapes from audio, from timed phonemes or from text, and cheap mouths that move with a voice's loudness: [Lip sync](https://360sona.com/devs/docs/guides/lipsync.md). ### sona_lipsync_defaults ```c void sona_lipsync_defaults(sona_lipsync_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_lipsync_options *` | The [`sona_lipsync_options`](https://360sona.com/devs/docs/reference/fields.md#sona_lipsync_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_lipsync_options x_lipsync_options; memset(&x_lipsync_options, 0, sizeof x_lipsync_options); x_lipsync_options.size = sizeof x_lipsync_options; sona_lipsync_defaults(&x_lipsync_options); ``` `size` set; `sample_rate` 48000, `channels` 1, `hold_seconds` 0.07, `attack_seconds` 0.02, `release_seconds` 0.07, `gate_db` -55, `lead_seconds` 0.04. ### sona_lipsync_create ```c sona_result sona_lipsync_create(const sona_lipsync_options *o, const sona_allocator *al, sona_lipsync **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `const sona_lipsync_options *` | The options, a [`sona_lipsync_options`](https://360sona.com/devs/docs/reference/fields.md#sona_lipsync_options) | `NULL`: the defaults | | `al` | `const sona_allocator *` | A [`sona_allocator`](https://360sona.com/devs/docs/reference/fields.md#sona_allocator) | required | | `out` | `sona_lipsync **` | Receives the new lip sync analyser | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). NULL options: the defaults. al NULL: malloc. `SONA_E_ARGUMENT` for a size, rate, channel count, format or time out of range. ### sona_lipsync_destroy ```c void sona_lipsync_destroy(sona_lipsync *ls); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ls` | `sona_lipsync *` | The lip sync analyser | required | **Returns** Nothing. **Example**: ```c sona_lipsync_destroy(ls); ``` Frees the analyser. ### sona_lipsync_reset ```c void sona_lipsync_reset(sona_lipsync *ls); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ls` | `sona_lipsync *` | The lip sync analyser | required | **Returns** Nothing. **Example**: ```c sona_lipsync_reset(ls); ``` Back to time 0: hints and frames waiting to be read are dropped. ### sona_lipsync_feed ```c sona_result sona_lipsync_feed(sona_lipsync *ls, const void *pcm, size_t frames); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ls` | `sona_lipsync *` | The lip sync analyser | required | | `pcm` | `const void *` | Audio samples, interleaved, in the format the options name | required | | `frames` | `size_t` | How many sample frames `pcm` holds | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `frames`: samples per channel. Analyses every 10 ms that is complete. ### sona_lipsync_read ```c uint32_t sona_lipsync_read(sona_lipsync *ls, sona_lipsync_frame *out, uint32_t max); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ls` | `sona_lipsync *` | The lip sync analyser | required | | `out` | `sona_lipsync_frame *` | Receives the [`sona_lipsync_frame`](https://360sona.com/devs/docs/reference/fields.md#sona_lipsync_frame) | required | | `max` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example**: ```c sona_lipsync_frame x_lipsync_frame; memset(&x_lipsync_frame, 0, sizeof x_lipsync_frame); uint32_t x_got = sona_lipsync_read(ls, &x_lipsync_frame, 1); printf("sona_lipsync_read: %lld\n", (long long)x_got); ``` Moves up to max frames made since the last read into out, oldest first; returns how many. ### sona_lipsync_current ```c sona_result sona_lipsync_current(const sona_lipsync *ls, sona_lipsync_frame *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ls` | `const sona_lipsync *` | The lip sync analyser | required | | `out` | `sona_lipsync_frame *` | Receives the [`sona_lipsync_frame`](https://360sona.com/devs/docs/reference/fields.md#sona_lipsync_frame) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_lipsync_frame x_lipsync_frame; memset(&x_lipsync_frame, 0, sizeof x_lipsync_frame); sona_result result = sona_lipsync_current(ls, &x_lipsync_frame); if (result != SONA_OK) printf("sona_lipsync_current: %s\n", sona_result_name(result)); ``` The newest frame (a shut mouth before the first). ### sona_lipsync_latency ```c double sona_lipsync_latency(const sona_lipsync *ls); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ls` | `const sona_lipsync *` | The lip sync analyser | required | **Returns** `double`. **Example**: ```c double x_got = sona_lipsync_latency(ls); printf("sona_lipsync_latency: %g\n", (double)x_got); ``` Seconds from a sample being fed to the first frame that hears it. ### sona_lipsync_hint ```c sona_result sona_lipsync_hint(sona_lipsync *ls, const sona_phoneme *ph, uint32_t count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ls` | `sona_lipsync *` | The lip sync analyser | required | | `ph` | `const sona_phoneme *` | A [`sona_phoneme`](https://360sona.com/devs/docs/reference/fields.md#sona_phoneme) | required | | `count` | `uint32_t` | How many entries the array holds | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_phoneme x_phoneme; memset(&x_phoneme, 0, sizeof x_phoneme); sona_result result = sona_lipsync_hint(ls, &x_phoneme, 1); if (result != SONA_OK) printf("sona_lipsync_hint: %s\n", sona_result_name(result)); ``` Phonemes the host's TTS reported, on the fed audio's clock: their shapes win while the audio is sounding, and lips close for M, B and P. Up to 256 held; ones that ended a second ago go. ### sona_phoneme_mouth ```c uint32_t sona_phoneme_mouth(const char *symbol); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `symbol` | `const char *` | A phoneme symbol | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_phoneme_mouth("example"); printf("sona_phoneme_mouth: %lld\n", (long long)x_got); ``` The mouth for a phoneme symbol; `SONA_MOUTH_UNKNOWN` when it is none of the sets. ### sona_lipsync_phonemes ```c sona_result sona_lipsync_phonemes(const sona_phoneme *ph, uint32_t count, const sona_lipsync_options *o, sona_mouth_key *out, uint32_t cap, uint32_t *total); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ph` | `const sona_phoneme *` | A [`sona_phoneme`](https://360sona.com/devs/docs/reference/fields.md#sona_phoneme) | required | | `count` | `uint32_t` | How many entries the array holds | - | | `o` | `const sona_lipsync_options *` | The options, a [`sona_lipsync_options`](https://360sona.com/devs/docs/reference/fields.md#sona_lipsync_options) | required | | `out` | `sona_mouth_key *` | Receives the [`sona_mouth_key`](https://360sona.com/devs/docs/reference/fields.md#sona_mouth_key) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | | `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Timed phonemes to keys (lead, closures kept, short shapes merged). *total is the count; writes up to cap. o may be NULL. ### sona_lipsync_text ```c sona_result sona_lipsync_text(const char *text, const void *pcm, size_t frames, const sona_lipsync_options *o, sona_mouth_key *out, uint32_t cap, uint32_t *total); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `text` | `const char *` | The text to read | required | | `pcm` | `const void *` | Audio samples, interleaved, in the format the options name | required | | `frames` | `size_t` | How many sample frames `pcm` holds | - | | `o` | `const sona_lipsync_options *` | The options, a [`sona_lipsync_options`](https://360sona.com/devs/docs/reference/fields.md#sona_lipsync_options) | required | | `out` | `sona_mouth_key *` | Receives the [`sona_mouth_key`](https://360sona.com/devs/docs/reference/fields.md#sona_mouth_key) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | | `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Text to keys. With audio (frames > 0, in o's format) the text is aligned to it; without, an even pace. `SONA_E_LIMIT` past 4096 letters or the 10 minutes limit of audio. ### sona_mouth_keys_sample ```c sona_result sona_mouth_keys_sample(const sona_mouth_key *keys, uint32_t count, double t, sona_lipsync_frame *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `keys` | `const sona_mouth_key *` | A [`sona_mouth_key`](https://360sona.com/devs/docs/reference/fields.md#sona_mouth_key) | required | | `count` | `uint32_t` | How many entries the array holds | - | | `t` | `double` | The time to sample, seconds | - | | `out` | `sona_lipsync_frame *` | Receives the [`sona_lipsync_frame`](https://360sona.com/devs/docs/reference/fields.md#sona_lipsync_frame) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_mouth_key x_mouth_key; memset(&x_mouth_key, 0, sizeof x_mouth_key); sona_lipsync_frame x_lipsync_frame2; memset(&x_lipsync_frame2, 0, sizeof x_lipsync_frame2); sona_result result = sona_mouth_keys_sample(&x_mouth_key, 1, 0.5f, &x_lipsync_frame2); if (result != SONA_OK) printf("sona_mouth_keys_sample: %s\n", sona_result_name(result)); ``` The mouth at time t of a key list, eased between keys. ### sona_avatar_mouth ```c sona_result sona_avatar_mouth(sona_avatar *a, uint32_t shape); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `shape` | `uint32_t` | A `SONA_MOUTH_*` shape | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_mouth(avatar, 0); if (result != SONA_OK) printf("sona_avatar_mouth: %s\n", sona_result_name(result)); ``` Only the mouth of the expression: a `SONA_MOUTH_`* or another shape index, or 255 to hand it back to the clip. The rest of the face keeps what `sona_avatar_expression` or the clip gave it. The same shape again does nothing. ### sona_voice_mouth_init ```c void sona_voice_mouth_init(sona_voice_mouth *v, uint32_t seed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `v` | `sona_voice_mouth *` | Receives the [`sona_voice_mouth`](https://360sona.com/devs/docs/reference/fields.md#sona_voice_mouth) | required | | `seed` | `uint32_t` | The seed: the same seed gives the same result | - | **Returns** Nothing. **Example** (also in [Lip sync: a microphone or any audio drives the mouth](https://360sona.com/devs/docs/guides/lipsync.md)): ```c sona_voice_mouth v[64]; for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i], sona_avatar_id(avatars[i])); /* each frame: */ uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt); ``` Sets `size` and starts the state from `seed`. Avatars with different seeds move their mouths differently to the same voice. ### sona_voice_mouth_step ```c uint32_t sona_voice_mouth_step(sona_voice_mouth *v, float level, float dt, float *open); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `v` | `sona_voice_mouth *` | Receives the [`sona_voice_mouth`](https://360sona.com/devs/docs/reference/fields.md#sona_voice_mouth) | required | | `level` | `float` | The audio level, linear RMS | - | | `dt` | `float` | Seconds since the last call | - | | `open` | `float *` | Receives how open the mouth is, 0 to 1 | required | **Returns** `uint32_t`. Advances by dt seconds; returns the `SONA_MOUTH_`* to show. open may be NULL. ### sona_avatar_voice ```c sona_result sona_avatar_voice(sona_avatar *a, sona_voice_mouth *v, float level, float dt); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `v` | `sona_voice_mouth *` | Receives the [`sona_voice_mouth`](https://360sona.com/devs/docs/reference/fields.md#sona_voice_mouth) | required | | `level` | `float` | The audio level, linear RMS | - | | `dt` | `float` | Seconds since the last call | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_voice_mouth x_voice_mouth; memset(&x_voice_mouth, 0, sizeof x_voice_mouth); x_voice_mouth.size = sizeof x_voice_mouth; sona_result result = sona_avatar_voice(avatar, &x_voice_mouth, 0, 1.0f / 60); if (result != SONA_OK) printf("sona_avatar_voice: %s\n", sona_result_name(result)); ``` `sona_voice_mouth_step` with the voice's level, put on the avatar's mouth with `sona_avatar_mouth`. ### sona_voice_mouths ```c uint32_t sona_voice_mouths(sona_avatar *const *avatars, sona_voice_mouth *states, const float *levels, uint32_t count, float dt); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `avatars` | `sona_avatar *const *` | The avatars, `count` of them | required | | `states` | `sona_voice_mouth *` | A mouth state per avatar | required | | `levels` | `const float *` | An audio level per avatar, linear RMS | required | | `count` | `uint32_t` | How many entries the array holds | - | | `dt` | `float` | Seconds since the last call | - | **Returns** `uint32_t`. **Example** (also in [Lip sync: a microphone or any audio drives the mouth](https://360sona.com/devs/docs/guides/lipsync.md)): ```c sona_voice_mouth v[64]; for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i], sona_avatar_id(avatars[i])); /* each frame: */ uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt); ``` `sona_avatar_voice` for count avatars (NULL entries skipped); returns how many mouths changed. ## Making avatars in code Seeded random avatars, dressing one avatar like another, and the outfit rules the editor follows: [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md). ### sona_maker_create ```c sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat, sona_maker **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | `NULL` allowed (below) | | `cat` | `const sona_catalogue *` | The catalogue | required | | `out` | `sona_maker **` | Receives the new maker | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat, sona_maker **out); void sona_maker_free(sona_maker *mk); ``` Indexes a catalogue's outfit rules once: candidate items per body and section, gender variants and matched sets ([Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)). The maker never changes after this, so every call on it is safe from any number of threads at once. It reads the catalogue: free it before the catalogue. `ctx` may be NULL (malloc, codes only). ### sona_maker_free ```c void sona_maker_free(sona_maker *mk); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `sona_maker *` | The maker | required | **Returns** Nothing. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat, sona_maker **out); void sona_maker_free(sona_maker *mk); ``` Frees the maker. ### sona_random_defaults ```c void sona_random_defaults(sona_random_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_random_options *` | The [`sona_random_options`](https://360sona.com/devs/docs/reference/fields.md#sona_random_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c void sona_random_defaults(sona_random_options *o); sona_result sona_make_random(const sona_maker *mk, uint32_t seed, const sona_random_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_random_report *report); ``` `size` set and everything else zero: the seed picks the body, any game, a new avatar, the palette's colours and every item available. ### sona_make_random ```c sona_result sona_make_random(const sona_maker *mk, uint32_t seed, const sona_random_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_random_report *report); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `seed` | `uint32_t` | The seed: the same seed gives the same result | - | | `o` | `const sona_random_options *` | The options, a [`sona_random_options`](https://360sona.com/devs/docs/reference/fields.md#sona_random_options) | required | | `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required | | `report` | `sona_random_report *` | Receives what the call did; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c void sona_random_defaults(sona_random_options *o); sona_result sona_make_random(const sona_maker *mk, uint32_t seed, const sona_random_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_random_report *report); ``` A new avatar from a seed: body, shape, colours, face, hair and an outfit with no clashes. The same seed, options and library give the same bytes. Picks are rendezvous hashes of (seed, section, item id): a newer catalogue moves a pick only where that item is gone or a new item outscores it, so most avatars survive a catalogue update. o may be NULL; report may be NULL. `SONA_E_ARGUMENT`: a body over 2, a style or palette out of range, or a base that does not parse or has no body while body is 0. ### sona_like_defaults ```c void sona_like_defaults(sona_like_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_like_options *` | The [`sona_like_options`](https://360sona.com/devs/docs/reference/fields.md#sona_like_options) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c void sona_like_defaults(sona_like_options *o); sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES], const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report); uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match, sona_guid *out); ``` `size` set; `parts` clothes and props, `match` SIMILAR. ### sona_make_dress_like ```c sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES], const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `body` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest whose body is kept | required | | `like` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest whose look is copied | required | | `o` | `const sona_like_options *` | The options, a [`sona_like_options`](https://360sona.com/devs/docs/reference/fields.md#sona_like_options) | required | | `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required | | `report` | `sona_like_report *` | Receives what the call did; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MANIFEST` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c void sona_like_defaults(sona_like_options *o); sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES], const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report); uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match, sona_guid *out); ``` `out` = body wearing like's parts, each item resolved for body's gender (`sona_make_variant`). out may be body. mk may be NULL: then only items both bodies wear, and custom items' pairs, come across. `SONA_E_ARGUMENT` when body has no known body; `SONA_E_MANIFEST` when either does not parse. ### sona_make_variant ```c uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match, sona_guid *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `item` | `const sona_guid *` | A [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | | `body` | `uint32_t` | The body a clip or item is for: 1 male, 2 female | - | | `match` | `uint32_t` | What the variant must match | - | | `out` | `sona_guid *` | Receives the [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | **Returns** `uint32_t`. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c void sona_like_defaults(sona_like_options *o); sona_result sona_make_dress_like(const sona_maker *mk, const uint8_t body[SONA_MANIFEST_BYTES], const uint8_t like[SONA_MANIFEST_BYTES], const sona_like_options *o, uint8_t out[SONA_MANIFEST_BYTES], sona_like_report *report); uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item, uint32_t body, uint32_t match, sona_guid *out); ``` The item body (1 or 2) wears for item: itself when it fits (KEPT), else its variant within match. Returns `SONA_RESOLVED_`*; DROPPED (out zeroed) when nothing fits. ### sona_outfit_clash ```c uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a, const sona_guid *b, uint32_t *slots); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `a` | `const sona_guid *` | One item id | required | | `b` | `const sona_guid *` | The other item id | required | | `slots` | `uint32_t *` | Receives the slots the two items share | required | **Returns** `uint32_t`. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a, const sona_guid *b, uint32_t *slots); uint32_t sona_outfit_conflicts(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], const sona_guid *item, sona_guid *out, uint32_t cap); ``` `SONA_CLASH_`* bits (0: they go together); slots (may be NULL) gets the slots they share. mk may be NULL (ids only). Two props share the prop slot: they stack only with `SONA_EDIT_STACK_PROPS`, up to four. ### sona_outfit_conflicts ```c uint32_t sona_outfit_conflicts(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], const sona_guid *item, sona_guid *out, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required | | `item` | `const sona_guid *` | A [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | | `out` | `sona_guid *` | Receives the [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a, const sona_guid *b, uint32_t *slots); uint32_t sona_outfit_conflicts(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], const sona_guid *item, sona_guid *out, uint32_t cap); ``` What wearing item would take off manifest: up to cap ids into out; returns how many. ### sona_outfit_set_count ```c uint32_t sona_outfit_set_count(const sona_maker *mk); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | **Returns** `uint32_t`. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c uint32_t sona_outfit_set_count(const sona_maker *mk); sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out); int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item); uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap); ``` How many matched sets (outfits sold as one) the maker knows. ### sona_outfit_set_get ```c sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `set` | `uint32_t` | A matched set's index | - | | `out` | `sona_outfit_set *` | Receives the [`sona_outfit_set`](https://360sona.com/devs/docs/reference/fields.md#sona_outfit_set) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c uint32_t sona_outfit_set_count(const sona_maker *mk); sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out); int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item); uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap); ``` Set `set`: its item count, which bodies wear it, the sections it has items in and the slots it covers. ### sona_outfit_set_of ```c int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `item` | `const sona_guid *` | A [`sona_guid`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | **Returns** `int32_t`. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c uint32_t sona_outfit_set_count(const sona_maker *mk); sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out); int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item); uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap); ``` The matched set an item belongs to, or -1 when it is in none. ### sona_outfit_set_items ```c uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `set` | `uint32_t` | A matched set's index | - | | `body` | `uint32_t` | The body whose items to list: 1 male, 2 female; 0: every item | `0`: every item | | `indexes` | `uint32_t *` | Receives catalogue indexes | required | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c uint32_t sona_outfit_set_count(const sona_maker *mk); sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set, sona_outfit_set *out); int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item); uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set, uint32_t body, uint32_t *indexes, uint32_t cap); ``` The set's items a body wears (0: every item), catalogue indexes in id order: up to cap; returns how many. ### sona_outfit_check ```c sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required | | `report` | `sona_outfit_report *` | Receives what the call did; may be NULL | `NULL`: not written | | `issues` | `sona_outfit_issue *` | Receives the issues found, up to `max` | required | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap); sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after); const char *sona_outfit_issue_name(uint32_t kind); ``` Every issue of a manifest, up to cap into issues (may be NULL with cap 0), errors first. mk may be NULL: the catalogue's checks (UNKNOWN, NOT_OFFERED, bodies by the catalogue) are left out. `SONA_E_MANIFEST`: it does not parse. ### sona_outfit_fix ```c sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `mk` | `const sona_maker *` | The maker | required | | `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required | | `after` | `sona_outfit_report *` | Receives the report of the manifest as fixed | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap); sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after); const char *sona_outfit_issue_name(uint32_t kind); ``` Fixes every error but NO_BODY in place: clashes go to the item worn last (as the editor), other-body items to their variants, duplicates and misplaced items out (a misplaced item that routes is worn where it belongs), missing slots to the body's defaults, a stale cache to the body's own; after (may be NULL) is the check after. `SONA_E_ARGUMENT` when the body is not known. ### sona_outfit_issue_name ```c const char * sona_outfit_issue_name(uint32_t kind); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `kind` | `uint32_t` | Which kind, one of the header's constants for it | - | **Returns** `const char *`. **Example** (also in [Making avatars in code](https://360sona.com/devs/docs/guides/makers.md)): ```c sona_result sona_outfit_check(const sona_maker *mk, const uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *report, sona_outfit_issue *issues, uint32_t cap); sona_result sona_outfit_fix(const sona_maker *mk, uint8_t manifest[SONA_MANIFEST_BYTES], sona_outfit_report *after); const char *sona_outfit_issue_name(uint32_t kind); ``` The name of a `SONA_OUTFIT_*` issue kind ("clash", ...); NULL past the last. ## Content filters Which items a game allows, by section, slot, source, game, tag or id, with presets and JSON rules: [Content filters](https://360sona.com/devs/docs/guides/filters.md). ### sona_filter_create ```c sona_result sona_filter_create(sona_ctx *ctx, const sona_catalogue *cat, sona_filter **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | `NULL` allowed (below) | | `cat` | `const sona_catalogue *` | The catalogue | required | | `out` | `sona_filter **` | Receives the new filter | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `ctx` may be NULL (malloc; errors only as codes); with one, its allocator and `sona_last_error`. cat may be NULL: then only id, slot, section (from the id) and source rules can match. The filter may outlive both. ### sona_filter_free ```c void sona_filter_free(sona_filter *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | **Returns** Nothing. Frees the filter. ### sona_filter_reset ```c sona_result sona_filter_reset(sona_filter *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Every rule goes; tags stay. ### sona_filter_sections ```c sona_result sona_filter_sections(sona_filter *f, uint32_t mode, uint32_t sections); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - | | `sections` | `uint32_t` | `SONA_SECTION_*` bits | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Adds a rule on sections: bits (1u << `sona_section`). `mode` is `SONA_CONTENT_ALLOW` or `_DENY`; each call adds to the rules. ### sona_filter_slots ```c sona_result sona_filter_slots(sona_filter *f, uint32_t mode, uint32_t slots); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - | | `slots` | `uint32_t` | Slot mask bits | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Adds a rule on slots (AssetMask bits): an item matches when it covers any of them. `mode` is `SONA_CONTENT_ALLOW` or `_DENY`. ### sona_filter_sources ```c sona_result sona_filter_sources(sona_filter *f, uint32_t mode, uint32_t sources); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - | | `sources` | `uint32_t` | `SONA_ITEM_*` source bits | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Content filters](https://360sona.com/devs/docs/guides/filters.md)): ```c sona_filter_game(f, SONA_CONTENT_ALLOW, "Racer X"); sona_filter_sources(f, SONA_CONTENT_ALLOW, SONA_CONTENT_STOCK); ``` Adds a rule on where items come from (`SONA_CONTENT_STOCK` and the other source bits). `mode` is `SONA_CONTENT_ALLOW` or `_DENY`. ### sona_filter_game ```c sona_result sona_filter_game(sona_filter *f, uint32_t mode, const char *game); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - | | `game` | `const char *` | A game's name, as the catalogue spells it | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Content filters](https://360sona.com/devs/docs/guides/filters.md)): ```c sona_filter_game(f, SONA_CONTENT_ALLOW, "Racer X"); sona_filter_sources(f, SONA_CONTENT_ALLOW, SONA_CONTENT_STOCK); ``` A game as `sona_catalogue_game` names it (ASCII case folded). `SONA_E_NOT_FOUND` when no item has that game. ### sona_filter_tag ```c sona_result sona_filter_tag(sona_filter *f, uint32_t mode, const char *tag); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - | | `tag` | `const char *` | A tag's name | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). A tag by name ("weapon", "logo", or one the host defined). `SONA_E_NOT_FOUND` for an unknown name. ### sona_filter_item ```c sona_result sona_filter_item(sona_filter *f, uint32_t mode, const sona_guid *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `mode` | `uint32_t` | `SONA_CONTENT_ALLOW` or `SONA_CONTENT_DENY` | - | | `id` | `const sona_guid *` | An item id | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Adds a rule on one item by id. `mode` is `SONA_CONTENT_ALLOW` or `_DENY`. ### sona_filter_preset ```c sona_result sona_filter_preset(sona_filter *f, uint32_t preset); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `preset` | `uint32_t` | Which preset, one of the header's constants for it | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Adds a preset's rules (`SONA_FILTER_PRESET_*`, listed in [Content filters](https://360sona.com/devs/docs/guides/filters.md)). ### sona_filter_load ```c sona_result sona_filter_load(sona_filter *f, const char *json, size_t len, char *why, size_t why_cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `json` | `const char *` | Filter rules as JSON text | required | | `len` | `size_t` | How many bytes there are | - | | `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_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Rules from JSON ([Content filters](https://360sona.com/devs/docs/guides/filters.md)): {"preset": [...], "allow": {...}, "deny": {...}, "tags": {...}, "untag": {...}}. All or nothing: on an error the filter is unchanged and why (may be NULL) says what was wrong. ### sona_filter_tag_count ```c uint32_t sona_filter_tag_count(const sona_filter *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | **Returns** `uint32_t`. How many tags the filter knows, built-in and host-defined. ### sona_filter_tag_name ```c const char * sona_filter_tag_name(const sona_filter *f, uint32_t tag); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `tag` | `uint32_t` | A tag's bit | - | **Returns** `const char *`. NULL past the last. ### sona_filter_tag_find ```c int32_t sona_filter_tag_find(const sona_filter *f, const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `name` | `const char *` | The name to look up | required | **Returns** `int32_t`. -1 when unknown. ### sona_filter_tag_define ```c sona_result sona_filter_tag_define(sona_filter *f, const char *name, uint32_t *out_tag); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `name` | `const char *` | The new tag's name | required | | `out_tag` | `uint32_t *` | Receives the new tag's bit | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). A new tag (a name of 1 to 31 bytes of a-z, 0-9 and '-'), or the index of the one of that name. `SONA_E_LIMIT` past 64 tags. ### sona_filter_tag_set ```c sona_result sona_filter_tag_set(sona_filter *f, const sona_guid *id, uint32_t tag, int on); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `sona_filter *` | The filter | required | | `id` | `const sona_guid *` | An item id | required | | `tag` | `uint32_t` | A tag's bit | - | | `on` | `int` | 1 on, 0 off | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Puts a tag on an item (`on` 1) or takes it off (0), for ids in the catalogue or not. ### sona_filter_item_tags ```c uint64_t sona_filter_item_tags(const sona_filter *f, const sona_guid *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `id` | `const sona_guid *` | An item id | required | **Returns** `uint64_t`. The bits of an item's tags (bit n is tag n). ### sona_filter_tag_items ```c uint32_t sona_filter_tag_items(const sona_filter *f, uint32_t tag); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `tag` | `uint32_t` | A tag's bit | - | **Returns** `uint32_t`. How many catalogue items carry a tag. ### sona_filter_allows ```c int sona_filter_allows(const sona_filter *f, const sona_guid *id); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `id` | `const sona_guid *` | An item id | required | **Returns** `int`. 1 when the item is allowed; a NULL filter allows everything. ### sona_filter_check ```c sona_result sona_filter_check(const sona_filter *f, const sona_guid *id, sona_filter_verdict *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `id` | `const sona_guid *` | An item id | required | | `out` | `sona_filter_verdict *` | Receives the [`sona_filter_verdict`](https://360sona.com/devs/docs/reference/fields.md#sona_filter_verdict) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Whether the item is allowed, and if not, which rule denied it (`SONA_CONTENT_BY_*`) and the item's tags. ### sona_filter_search ```c sona_result sona_filter_search(const sona_filter *f, const sona_catalogue *cat, const sona_catalogue_query *q, uint32_t *out_indexes, uint32_t max, uint32_t *total); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `cat` | `const sona_catalogue *` | The catalogue | required | | `q` | `const sona_catalogue_query *` | A [`sona_catalogue_query`](https://360sona.com/devs/docs/reference/fields.md#sona_catalogue_query) | required | | `out_indexes` | `uint32_t *` | Receives catalogue indexes, up to `max` | required | | `max` | `uint32_t` | How many entries `out` holds | - | | `total` | `uint32_t *` | Receives how many there are in all; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `sona_catalogue_search` over cat, allowed items only (offset and total count allowed ones). Any catalogue works; items are matched by id. ### sona_filter_allowed_count ```c uint32_t sona_filter_allowed_count(const sona_filter *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | **Returns** `uint32_t`. Catalogue items allowed. ### sona_filter_manifest ```c sona_result sona_filter_manifest(const sona_filter *f, sona_manifest *m, sona_filter_report *report); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `m` | `sona_manifest *` | Receives the [`sona_manifest`](https://360sona.com/devs/docs/reference/fields.md#sona_manifest) | required | | `report` | `sona_filter_report *` | Receives what the call did; may be NULL | `NULL` allowed (below) | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Takes every denied item off a manifest: worn items go back to the body's defaults, props are hidden. `report` (may be NULL) lists what changed. ### sona_filter_manifest_bytes ```c sona_result sona_filter_manifest_bytes(const sona_filter *f, uint8_t manifest[SONA_MANIFEST_BYTES], sona_filter_report *report); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `f` | `const sona_filter *` | The filter | required | | `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required | | `report` | `sona_filter_report *` | Receives what the call did; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MANIFEST` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The same on the 1000 bytes, in place; unchanged bytes when nothing is denied. `SONA_E_MANIFEST` for bad bytes. ### sona_ctx_set_filter ```c sona_result sona_ctx_set_filter(sona_ctx *ctx, const sona_filter *f); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `f` | `const sona_filter *` | The filter | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The ctx's filter: a copy of f (NULL takes it away), applied to an avatar when its manifest is read, whoever's it is (`sona_avatar_add`, headless renders); an avatar read before the change keeps what it wore until it is removed and added again. A preview of a denied item fails with `SONA_E_NOT_FOUND`. Pickers read it back with `sona_ctx_filter`: NULL when none; owned by the ctx and gone at the next `sona_ctx_set_filter` or `sona_close`. ### sona_ctx_filter ```c const sona_filter * sona_ctx_filter(const sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | **Returns** `const sona_filter *`. **Example**: ```c const sona_filter * x_got = sona_ctx_filter(ctx); printf("sona_ctx_filter: %s\n", x_got ? "a value" : "none"); ``` The ctx's filter as `sona_ctx_set_filter` left it: NULL when none; owned by the ctx and gone at the next `sona_ctx_set_filter` or `sona_close`. ### sona_avatar_filter_report ```c sona_result sona_avatar_filter_report(const sona_avatar *a, sona_filter_report *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_filter_report *` | Receives the [`sona_filter_report`](https://360sona.com/devs/docs/reference/fields.md#sona_filter_report) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_filter_report x_filter_report; memset(&x_filter_report, 0, sizeof x_filter_report); x_filter_report.size = sizeof x_filter_report; sona_result result = sona_avatar_filter_report(avatar, &x_filter_report); if (result != SONA_OK) printf("sona_avatar_filter_report: %s\n", sona_result_name(result)); ``` What the ctx's filter changed on this avatar. `SONA_E_NOT_READY` before its manifest is read, `SONA_E_NOT_FOUND` when no filter was set then. ## Lighting and shadows A key light, ambient and environment light, shadows on the avatars and the ground, and the host's own shadow map: [Lighting and shadows](https://360sona.com/devs/docs/guides/lighting.md). ### sona_lighting_defaults ```c void sona_lighting_defaults(sona_lighting *l); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `l` | `sona_lighting *` | The [`sona_lighting`](https://360sona.com/devs/docs/reference/fields.md#sona_lighting) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Lighting and shadows](https://360sona.com/devs/docs/guides/lighting.md)): ```c sona_lighting_defaults(&l); l.key.direction[0] = 0.4f; l.key.direction[1] = -1.0f; l.key.direction[2] = 0.6f; l.key.intensity = 0.9f; l.flags = SONA_LIGHTING_GROUND | SONA_LIGHTING_PROXY_CASTERS; /* a crowd's ground shadows for almost nothing */ sona_renderer_set_lighting(r, &l); ``` `size` set; `ambient` 0, `environment` 1, `specular` 1, `rim` 1, `shadow` FIT, `shadow_size` 2048, `shadow_strength` 1, `shadow_ambient` 0.5, `shadow_bias` 0.03, `ground_y` 0, `ground_opacity` 0.6. ### sona_renderer_set_lighting ```c sona_result sona_renderer_set_lighting(sona_renderer *r, const sona_lighting *l); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `l` | `const sona_lighting *` | A [`sona_lighting`](https://360sona.com/devs/docs/reference/fields.md#sona_lighting) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Lighting and shadows](https://360sona.com/devs/docs/guides/lighting.md)): ```c sona_lighting_defaults(&l); l.key.direction[0] = 0.4f; l.key.direction[1] = -1.0f; l.key.direction[2] = 0.6f; l.key.intensity = 0.9f; l.flags = SONA_LIGHTING_GROUND | SONA_LIGHTING_PROXY_CASTERS; /* a crowd's ground shadows for almost nothing */ sona_renderer_set_lighting(r, &l); ``` From the next draw. NULL: no lighting, the original look again. `SONA_E_ARGUMENT` for a size that is not sizeof(`sona_lighting`), a value out of range, an unknown flag or mode, a zero key direction with shadows on, or a matrix that is not orthographic. ### sona_renderer_lighting ```c sona_result sona_renderer_lighting(const sona_renderer *r, sona_lighting *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_renderer *` | The renderer | required | | `out` | `sona_lighting *` | Receives the [`sona_lighting`](https://360sona.com/devs/docs/reference/fields.md#sona_lighting) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_lighting x_lighting; sona_lighting_defaults(&x_lighting); sona_result result = sona_renderer_lighting(r, &x_lighting); if (result != SONA_OK) printf("sona_renderer_lighting: %s\n", sona_result_name(result)); ``` What is set; `SONA_E_NOT_FOUND` when none is. ### sona_draw_lit ```c sona_result sona_draw_lit(sona_renderer *r, const sona_view *view, const sona_target *target, const sona_draw_options *opts, const sona_lighting *l); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](https://360sona.com/devs/docs/reference/fields.md#sona_target) | required | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | | `l` | `const sona_lighting *` | A [`sona_lighting`](https://360sona.com/devs/docs/reference/fields.md#sona_lighting) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `sona_draw` and `sona_snapshot` with l in place of the renderer's lighting for this one frame (one per view of a split screen); l NULL: the renderer's own. The checks of `sona_renderer_set_lighting`. ### sona_snapshot_lit ```c sona_result sona_snapshot_lit(sona_renderer *r, const sona_view *view, uint32_t width, uint32_t height, const sona_draw_options *opts, const sona_lighting *l, uint8_t *rgba_out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | | `l` | `const sona_lighting *` | A [`sona_lighting`](https://360sona.com/devs/docs/reference/fields.md#sona_lighting) | required | | `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `sona_snapshot` with `l` in place of the renderer's lighting for this one picture; `l` NULL: the renderer's own. The checks of `sona_renderer_set_lighting`. ### sona_environment_defaults ```c void sona_environment_defaults(sona_environment *e); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `e` | `sona_environment *` | The [`sona_environment`](https://360sona.com/devs/docs/reference/fields.md#sona_environment) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [Lighting and shadows](https://360sona.com/devs/docs/guides/lighting.md)): ```c sona_environment e; sona_environment_defaults(&e); e.kind = SONA_ENV_SH9; /* or SONA_ENV_CUBE with cube_size and cube */ memcpy(e.sh, my_sh, sizeof e.sh); /* 9 x RGB, radiance */ sona_renderer_set_environment(r, &e); /* NULL: the built-in cube */ ``` `size` set; `kind` BUILTIN, `skin_red` 1.2 (the built-in's). ### sona_renderer_set_environment ```c sona_result sona_renderer_set_environment(sona_renderer *r, const sona_environment *e); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `e` | `const sona_environment *` | A [`sona_environment`](https://360sona.com/devs/docs/reference/fields.md#sona_environment) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Lighting and shadows](https://360sona.com/devs/docs/guides/lighting.md)): ```c sona_environment e; sona_environment_defaults(&e); e.kind = SONA_ENV_SH9; /* or SONA_ENV_CUBE with cube_size and cube */ memcpy(e.sh, my_sh, sizeof e.sh); /* 9 x RGB, radiance */ sona_renderer_set_environment(r, &e); /* NULL: the built-in cube */ ``` From the next lit draw. NULL: the built-in cube. `SONA_E_ARGUMENT` for a bad size, kind or cube. ### sona_environment_irradiance ```c sona_result sona_environment_irradiance(const sona_environment *e, float out_sh[27]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `e` | `const sona_environment *` | A [`sona_environment`](https://360sona.com/devs/docs/reference/fields.md#sona_environment) | required | | `out_sh` | `float [27]` | Receives nine RGB spherical-harmonic coefficients | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_environment x_environment; sona_environment_defaults(&x_environment); float x_out_sh2[27]; memset(x_out_sh2, 0, sizeof x_out_sh2); sona_result result = sona_environment_irradiance(&x_environment, x_out_sh2); if (result != SONA_OK) printf("sona_environment_irradiance: %s\n", sona_result_name(result)); ``` The irradiance the shader evaluates for e (cube projected, convolved with the cosine lobe, divided by pi), in the basis above: a host lights its own scene the same way with it. `SONA_E_ARGUMENT` as above and for BUILTIN. ### sona_renderer_set_host_shadow ```c sona_result sona_renderer_set_host_shadow(sona_renderer *r, const sona_host_shadow *s); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `s` | `const sona_host_shadow *` | A [`sona_host_shadow`](https://360sona.com/devs/docs/reference/fields.md#sona_host_shadow) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Lighting and shadows](https://360sona.com/devs/docs/guides/lighting.md)): ```c sona_host_shadow h; memset(&h, 0, sizeof h); h.size = sizeof h; memcpy(h.matrix, my_light_view_proj_to_uv, sizeof h.matrix); /* world point to (u, v, depth, w) */ h.bias = 0.0015f; h.width = h.height = 4096; h.u.vk.view = my_depth_view; /* .gl.texture, .d3d11.srv, .d3d12.resource + .srv_format */ h.u.vk.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; sona_renderer_set_host_shadow(r, &h); ``` NULL: none. `SONA_E_UNSUPPORTED` on a backend without it (Metal), `SONA_E_ARGUMENT` for a bad size or handle. ### sona_renderer_shadow_map ```c sona_result sona_renderer_shadow_map(const sona_renderer *r, sona_shadow_map *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `const sona_renderer *` | The renderer | required | | `out` | `sona_shadow_map *` | Receives the [`sona_shadow_map`](https://360sona.com/devs/docs/reference/fields.md#sona_shadow_map) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_UNSUPPORTED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Lighting and shadows](https://360sona.com/devs/docs/guides/lighting.md)): ```c sona_shadow_map m; m.size = sizeof m; if (sona_renderer_shadow_map(r, &m) == SONA_OK) { /* m.matrix: world point (row vector) to (u, v, depth, 1); m.u.vk.view etc: the depth texture to sample */ } ``` `SONA_E_NOT_FOUND` before a lit frame with shadows; `SONA_E_UNSUPPORTED` on a backend without it. ## Loading placeholders A neutral figure in the avatar's place while it loads, and avatars added before their manifest is known: [Loading placeholders](https://360sona.com/devs/docs/guides/placeholder.md). ### sona_placeholder_defaults ```c void sona_placeholder_defaults(sona_placeholder_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_placeholder_options *` | The [`sona_placeholder_options`](https://360sona.com/devs/docs/reference/fields.md#sona_placeholder_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_placeholder_options x_placeholder_options; memset(&x_placeholder_options, 0, sizeof x_placeholder_options); x_placeholder_options.size = sizeof x_placeholder_options; sona_placeholder_defaults(&x_placeholder_options); ``` `size` set; `delay_seconds` 0 (never a hole), `appear_seconds` 0.2, `reveal_seconds` 0.4, `failed_seconds` 2, `tint` 0.16, 0.19, 0.25 (a cool grey), `failed_tint` 0.25, 0.15, 0.15 (a muted red), `glow` 0.5. ### sona_placeholder_set ```c sona_result sona_placeholder_set(sona_ctx *ctx, const sona_placeholder_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_placeholder_options *` | The options, a [`sona_placeholder_options`](https://360sona.com/devs/docs/reference/fields.md#sona_placeholder_options) | `NULL`: the defaults | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Loading placeholders](https://360sona.com/devs/docs/guides/placeholder.md)): ```c sona_open(&cfg, &ctx); sona_placeholder_set(ctx, NULL); /* on, with the defaults */ sona_lod_set(ctx, NULL); /* optional: far figures become sprites too */ /* ... add avatars as usual; they show figures until READY ... */ while (game_running()) { /* your game's loop */ sona_update(ctx, dt, &view, NULL); /* phases, timers, posing */ sona_draw(renderer, &view, &target, NULL); } ``` NULL: the defaults. `SONA_E_ARGUMENT` for a size that is not the struct's, a negative or non-finite time (each has a limit of 60 s), a colour outside 0..1 or reserved words that are not zero. Takes effect at the next `sona_update`. ### sona_placeholder_get ```c sona_result sona_placeholder_get(const sona_ctx *ctx, sona_placeholder_options *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `out` | `sona_placeholder_options *` | Receives the [`sona_placeholder_options`](https://360sona.com/devs/docs/reference/fields.md#sona_placeholder_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_placeholder_options x_placeholder_options; memset(&x_placeholder_options, 0, sizeof x_placeholder_options); x_placeholder_options.size = sizeof x_placeholder_options; sona_result result = sona_placeholder_get(ctx, &x_placeholder_options); if (result != SONA_OK) printf("sona_placeholder_get: %s\n", sona_result_name(result)); ``` `SONA_E_NOT_FOUND` while placeholders are off (out still gets the options last set, or the defaults). ### sona_placeholder_off ```c sona_result sona_placeholder_off(sona_ctx *ctx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_placeholder_off(ctx); if (result != SONA_OK) printf("sona_placeholder_off: %s\n", sona_result_name(result)); ``` Figures shown now fade out over appear_seconds. ### sona_avatar_placeholder ```c sona_result sona_avatar_placeholder(sona_avatar *a, int32_t mode); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `mode` | `int32_t` | A `SONA_PLACEHOLDER_*` mode for this avatar | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_placeholder(avatar, 0); if (result != SONA_OK) printf("sona_avatar_placeholder: %s\n", sona_result_name(result)); ``` Per avatar: -1 follows the ctx (the default), 0 never, 1 always (with the ctx's options, or the defaults). ### sona_avatar_placeholder_info ```c sona_result sona_avatar_placeholder_info(const sona_avatar *a, sona_placeholder_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_placeholder_info *` | Receives the [`sona_placeholder_info`](https://360sona.com/devs/docs/reference/fields.md#sona_placeholder_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_placeholder_info x_placeholder_info; memset(&x_placeholder_info, 0, sizeof x_placeholder_info); x_placeholder_info.size = sizeof x_placeholder_info; sona_result result = sona_avatar_placeholder_info(avatar, &x_placeholder_info); if (result != SONA_OK) printf("sona_avatar_placeholder_info: %s\n", sona_result_name(result)); ``` The avatar's figure at the last `sona_update`: its phase, opacity, height, which figure (male, female or neutral), whether it plays the avatar's clip, the seconds since the avatar was added and whether it is drawn as a sprite. ### sona_placeholder_stats_get ```c void sona_placeholder_stats_get(const sona_ctx *ctx, sona_placeholder_stats *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `const sona_ctx *` | The context | required | | `out` | `sona_placeholder_stats *` | Receives the [`sona_placeholder_stats`](https://360sona.com/devs/docs/reference/fields.md#sona_placeholder_stats) | required | **Returns** Nothing. **Example**: ```c sona_placeholder_stats x_placeholder_stats; memset(&x_placeholder_stats, 0, sizeof x_placeholder_stats); x_placeholder_stats.size = sizeof x_placeholder_stats; sona_placeholder_stats_get(ctx, &x_placeholder_stats); ``` Figures in view at the last `sona_update` (by phase, and how many as sprites), how many were posed and the time that took, and the figure draws of the last `sona_draw` or `sona_snapshot`. ### sona_avatar_add_waiting ```c sona_result sona_avatar_add_waiting(sona_ctx *ctx, const sona_add_options *opts, sona_avatar **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](https://360sona.com/devs/docs/reference/fields.md#sona_add_options) | required | | `out` | `sona_avatar **` | Receives the new avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Loading placeholders](https://360sona.com/devs/docs/guides/placeholder.md)): ```c sona_avatar *seat; sona_avatar_add_waiting(ctx, &opts, &seat); /* QUEUED, the neutral figure */ /* ... later, when the network brings the manifest ... */ sona_avatar_set_manifest_base64(seat, b64); /* now it loads like any avatar */ ``` An avatar whose manifest is not known, as for a player joining before their profile arrives. It stays QUEUED and shows the neutral figure (with placeholders on) until `sona_avatar_set_manifest` gives it its manifest, once; then it loads as if it had been added with it. Placement, play, layers and the rest work on it as on any avatar. `sona_avatar_set_manifest`: `SONA_E_ARGUMENT` for an avatar not added waiting or already given one. A bad manifest fails the avatar later with `SONA_E_MANIFEST`, as `sona_avatar_add`. ### sona_avatar_set_manifest ```c sona_result sona_avatar_set_manifest(sona_avatar *a, const uint8_t manifest[SONA_MANIFEST_BYTES]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_set_manifest(avatar, manifest); if (result != SONA_OK) printf("sona_avatar_set_manifest: %s\n", sona_result_name(result)); ``` Gives an avatar added with `sona_avatar_add_waiting` its manifest, once; it then loads as if it had been added with it. `SONA_E_ARGUMENT` for an avatar not added waiting or already given one. ### sona_avatar_set_manifest_base64 ```c sona_result sona_avatar_set_manifest_base64(sona_avatar *a, const char *b64); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `b64` | `const char *` | The manifest as base64 text, at most 4096 characters | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Loading placeholders](https://360sona.com/devs/docs/guides/placeholder.md)): ```c sona_avatar *seat; sona_avatar_add_waiting(ctx, &opts, &seat); /* QUEUED, the neutral figure */ /* ... later, when the network brings the manifest ... */ sona_avatar_set_manifest_base64(seat, b64); /* now it loads like any avatar */ ``` `sona_avatar_set_manifest` with the manifest as base64 text. ## Overlays A picture the host draws on the CPU, blended over the frame by the renderer: [Overlays](https://360sona.com/devs/docs/guides/overlay.md). ### sona_renderer_overlay ```c sona_result sona_renderer_overlay(sona_renderer *r, const sona_overlay *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `o` | `const sona_overlay *` | A [`sona_overlay`](https://360sona.com/devs/docs/reference/fields.md#sona_overlay) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Overlays: a picture over the frame](https://360sona.com/devs/docs/guides/overlay.md)): ```c sona_overlay o; memset(&o, 0, sizeof o); o.size = sizeof o; o.width = hud_w; o.height = hud_h; o.rgba = hud_pixels; /* straight RGBA8, row 0 at the top; read during the call only */ o.revision = hud_revision; /* the same as the last call's: nothing is uploaded */ o.dirty[0] = x; o.dirty[1] = y; o.dirty[2] = w; o.dirty[3] = h; /* what changed; w 0: all of it */ /* o.rect: where it lands in the target, pixels from the top left; w 0: the whole target */ sona_renderer_overlay(renderer, &o); sona_draw(renderer, &view, &target, &opts); /* the avatars, the credit, then the overlay */ sona_renderer_overlay(renderer, NULL); /* the next draws have none (the texture is kept) */ ``` Sets r's overlay for every `sona_draw` that follows, until the next call. o NULL takes it away (its texture is kept for the next one of the same size). After `sona_renderer_reset` or a lost device, set it again. `SONA_E_ARGUMENT` for a bad size or stride, a dirty rectangle outside the picture, or no rgba; `SONA_E_LIMIT` past the largest texture. ### sona_renderer_underlay ```c sona_result sona_renderer_underlay(sona_renderer *r, const sona_overlay *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `r` | `sona_renderer *` | The renderer | required | | `o` | `const sona_overlay *` | A [`sona_overlay`](https://360sona.com/devs/docs/reference/fields.md#sona_overlay) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_overlay x_overlay; memset(&x_overlay, 0, sizeof x_overlay); x_overlay.size = sizeof x_overlay; sona_result result = sona_renderer_underlay(r, &x_overlay); if (result != SONA_OK) printf("sona_renderer_underlay: %s\n", sona_result_name(result)); ``` A picture behind the avatars, as a page's backdrop behind a clear canvas: drawn first in the main pass at o->rect (w or h 0: the whole target), for every `sona_draw` and `sona_snapshot` until the next call; NULL takes it away. The frame's bloom runs over it as over the avatars. The editor draws 360sona.com's stage gradient this way. GL and Vulkan have it; on the other backends it returns `SONA_E_UNSUPPORTED` and the frame's clear shows. ## 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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/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`](https://360sona.com/devs/docs/reference/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`](https://360sona.com/devs/docs/reference/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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/fields.md#sona_prop_mesh_info) | required | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/fields.md#sona_prop_data) | required | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/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`](https://360sona.com/devs/docs/reference/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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/fields.md#sona_prop_attach) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/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](https://360sona.com/devs/docs/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](https://360sona.com/devs/docs/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`](https://360sona.com/devs/docs/reference/fields.md#sona_guid) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/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. ## Ragdolls Bodies fitted to the avatar for the host's physics engine, and the handoff to a ragdoll and back: [Physics-ready avatars](https://360sona.com/devs/docs/guides/physics.md). ### sona_ragdoll_defaults ```c void sona_ragdoll_defaults(sona_ragdoll_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_ragdoll_options *` | The [`sona_ragdoll_options`](https://360sona.com/devs/docs/reference/fields.md#sona_ragdoll_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_ragdoll_options x_ragdoll_options; memset(&x_ragdoll_options, 0, sizeof x_ragdoll_options); x_ragdoll_options.size = sizeof x_ragdoll_options; sona_ragdoll_defaults(&x_ragdoll_options); ``` `size` set; `coverage` 0.9. ### sona_avatar_ragdoll ```c sona_result sona_avatar_ragdoll(sona_avatar *a, const sona_ragdoll_options *o, sona_ragdoll_body *out, uint32_t cap, uint32_t *count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_ragdoll_options *` | The options, a [`sona_ragdoll_options`](https://360sona.com/devs/docs/reference/fields.md#sona_ragdoll_options) | required | | `out` | `sona_ragdoll_body *` | Receives the [`sona_ragdoll_body`](https://360sona.com/devs/docs/reference/fields.md#sona_ragdoll_body) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | | `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Fits the bodies to the avatar as it is now (its rig, body shape and outfit) and writes up to cap of them; count (may be NULL) gets `SONA_RAGDOLL_BODIES`. The same avatar and options give the same bits. From this call on, each pose keeps the bodies' last two transforms for `sona_avatar_ragdoll_state`. `SONA_E_NOT_READY` before the avatar is READY and posed; `SONA_E_ARGUMENT` for a bad size, flag, mass or coverage. ### sona_avatar_ragdoll_state ```c sona_result sona_avatar_ragdoll_state(const sona_avatar *a, sona_ragdoll_state *out, uint32_t cap, uint32_t *count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_ragdoll_state *` | Receives the [`sona_ragdoll_state`](https://360sona.com/devs/docs/reference/fields.md#sona_ragdoll_state) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | | `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The bodies at the last pose, with velocities from the last two poses (on the scene clock; zero until there have been two). For the host's bodies when it takes over. `SONA_E_NOT_READY` before `sona_avatar_ragdoll`. ### sona_avatar_ragdoll_drive ```c sona_result sona_avatar_ragdoll_drive(sona_avatar *a, const sona_ragdoll_state *bodies, uint32_t count, float weight, uint32_t flags); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `bodies` | `const sona_ragdoll_state *` | A [`sona_ragdoll_state`](https://360sona.com/devs/docs/reference/fields.md#sona_ragdoll_state) | required | | `count` | `uint32_t` | How many entries the array holds | - | | `weight` | `float` | How much of the host's bodies to show over the clip, 0 to 1 | - | | `flags` | `uint32_t` | Option bits for the call; 0: none | `0`: none | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ragdoll_state x_ragdoll_state; memset(&x_ragdoll_state, 0, sizeof x_ragdoll_state); sona_result result = sona_avatar_ragdoll_drive(avatar, &x_ragdoll_state, 1, 0.5f, 0); if (result != SONA_OK) printf("sona_avatar_ragdoll_drive: %s\n", sona_result_name(result)); ``` The host's simulated bodies onto the avatar: from the next pose it draws them, until released. `count` is `SONA_RAGDOLL_BODIES`; velocities are not read. `weight` 0..1 blends from the clip's pose (0.3: a hit reaction); every joint between bodies (fingers, toes, the neck, the face) keeps its clip pose relative to its body. Call it after each physics step. `SONA_RAGDOLL_KEEP_LENGTHS`: only the bodies' turns and the hips' position are taken, so the bones keep their lengths. `SONA_E_ARGUMENT` for a bad count, weight or flag, or a body that is not finite. ### sona_avatar_ragdoll_release ```c sona_result sona_avatar_ragdoll_release(sona_avatar *a, float blend_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `blend_seconds` | `float` | Seconds over which the ragdoll blends back to the clip | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_avatar_ragdoll_release(avatar, 0.5f); if (result != SONA_OK) printf("sona_avatar_ragdoll_release: %s\n", sona_result_name(result)); ``` Back to the animation: the last drawn ragdoll pose stays where it is in the world and blends into the clip's pose over blend_seconds (smoothstep; 0: at once), turn by turn down the body, so limbs stay joined. Play the get-up clip and move the placement to `sona_ragdoll_info`'s getup_position and getup_turn_deg first. ### sona_avatar_ragdoll_info ```c sona_result sona_avatar_ragdoll_info(const sona_avatar *a, sona_ragdoll_info *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_ragdoll_info *` | Receives the [`sona_ragdoll_info`](https://360sona.com/devs/docs/reference/fields.md#sona_ragdoll_info) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_ragdoll_info x_ragdoll_info; memset(&x_ragdoll_info, 0, sizeof x_ragdoll_info); x_ragdoll_info.size = sizeof x_ragdoll_info; sona_result result = sona_avatar_ragdoll_info(avatar, &x_ragdoll_info); if (result != SONA_OK) printf("sona_avatar_ragdoll_info: %s\n", sona_result_name(result)); ``` `SONA_E_NOT_READY` before the avatar has been posed since `sona_avatar_ragdoll`. ### sona_avatar_ragdoll_clear ```c void sona_avatar_ragdoll_clear(sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. **Example**: ```c sona_avatar_ragdoll_clear(avatar); ``` Off at once: no tracking, no drive, no blend. ### sona_avatar_ragdoll_motors ```c sona_result sona_avatar_ragdoll_motors(const sona_avatar *a, sona_ragdoll_motor *out, uint32_t cap, uint32_t *count); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `const sona_avatar *` | The avatar | required | | `out` | `sona_ragdoll_motor *` | Receives the [`sona_ragdoll_motor`](https://360sona.com/devs/docs/reference/fields.md#sona_ragdoll_motor) | required | | `cap` | `uint32_t` | How many entries `out` holds | - | | `count` | `uint32_t *` | Receives how many entries there are; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The targets of the last pose, velocities from the last two (zero until there have been two). count (may be NULL) gets `SONA_RAGDOLL_BODIES`. `SONA_E_NOT_READY` before `sona_avatar_ragdoll`. The stock get-up clips are "getup_back" and "getup_front" ([physics guide](https://360sona.com/devs/docs/guides/physics.md), "Getting up"). ## Two-avatar interactions and seats High fives, handshakes, hugs, holding hands and sitting, with the avatars placed and their hands and hips meeting: [Two-avatar interactions](https://360sona.com/devs/docs/guides/interactions.md). ### sona_seat_defaults ```c void sona_seat_defaults(sona_seat *s, uint32_t kind); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `s` | `sona_seat *` | The [`sona_seat`](https://360sona.com/devs/docs/reference/fields.md#sona_seat) to fill with the defaults | required | | `kind` | `uint32_t` | Which kind, one of the header's constants for it | - | **Returns** Nothing. **Example** (also in [Two-avatar interactions and seats](https://360sona.com/devs/docs/guides/interactions.md)): ```c sona_interaction_defaults(&d, SONA_INTERACT_SIT); d.a = adult; d.b = child; /* b NULL: one sitter */ d.flags = SONA_INTERACT_HANDS; /* two sitters: the near hands hold */ sona_seat_defaults(&d.seat, SONA_SEAT_BENCH); d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f; /* the front edge's middle, on top */ d.seat.turn_deg = 0; /* the way they face */ sona_interaction_start(ctx, &d, &it); ``` `size` set and a seat of that kind: `height` 0.45 (0 for GROUND), `depth` 0.45 (unlimited for GROUND), `width` 0.5 for a chair, 1.4 for a bench and unlimited on the ground. ### sona_interaction_defaults ```c void sona_interaction_defaults(sona_interaction_desc *d, uint32_t kind); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `d` | `sona_interaction_desc *` | The [`sona_interaction_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_interaction_desc) to fill with the defaults | required | | `kind` | `uint32_t` | Which kind, one of the header's constants for it | - | **Returns** Nothing. **Example** (also in [Two-avatar interactions and seats](https://360sona.com/devs/docs/guides/interactions.md)): ```c sona_interaction_defaults(&d, SONA_INTERACT_SIT); d.a = adult; d.b = child; /* b NULL: one sitter */ d.flags = SONA_INTERACT_HANDS; /* two sitters: the near hands hold */ sona_seat_defaults(&d.seat, SONA_SEAT_BENCH); d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f; /* the front edge's middle, on top */ d.seat.turn_deg = 0; /* the way they face */ sona_interaction_start(ctx, &d, &it); ``` Sets size, kind, the kind's default timings in seconds (high five 0.8, 0.15, 0.7; handshake 0.9, 1.6, 0.8; hug 1.1, 2.5, 1.0; hold hands 0.8, 0, 0.6; sit 1.3, 0, 1.4) and a default seat. ### sona_interaction_layout ```c sona_result sona_interaction_layout(const sona_interaction_desc *d, sona_interaction_plan *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `d` | `const sona_interaction_desc *` | The options, a [`sona_interaction_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_interaction_desc) | required | | `out` | `sona_interaction_plan *` | Receives the [`sona_interaction_plan`](https://360sona.com/devs/docs/reference/fields.md#sona_interaction_plan) | required | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_interaction_desc x_interaction_desc; memset(&x_interaction_desc, 0, sizeof x_interaction_desc); x_interaction_desc.size = sizeof x_interaction_desc; sona_interaction_plan x_interaction_plan2; memset(&x_interaction_plan2, 0, sizeof x_interaction_plan2); x_interaction_plan2.size = sizeof x_interaction_plan2; sona_result result = sona_interaction_layout(&x_interaction_desc, &x_interaction_plan2); if (result != SONA_OK) printf("sona_interaction_layout: %s\n", sona_result_name(result)); ``` `SONA_E_ARGUMENT` for a bad desc (sizes, kind, flags, timings, a missing or repeated avatar, a seat too narrow for two), `SONA_E_NOT_READY` until both avatars are READY, and for SIT `SONA_PENDING` until the stock sit clip has been read (the call asks the sources for it; call again). Owner thread only, like `sona_interaction_start`: it measures both bodies (a few milliseconds) and may read the clip into the ctx. ### sona_interaction_start ```c sona_result sona_interaction_start(sona_ctx *ctx, const sona_interaction_desc *d, sona_interaction **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `d` | `const sona_interaction_desc *` | The options, a [`sona_interaction_desc`](https://360sona.com/devs/docs/reference/fields.md#sona_interaction_desc) | required | | `out` | `sona_interaction **` | Receives the new interaction | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Two-avatar interactions and seats](https://360sona.com/devs/docs/guides/interactions.md)): ```c sona_interaction_defaults(&d, SONA_INTERACT_SIT); d.a = adult; d.b = child; /* b NULL: one sitter */ d.flags = SONA_INTERACT_HANDS; /* two sitters: the near hands hold */ sona_seat_defaults(&d.seat, SONA_SEAT_BENCH); d.seat.position[0] = 4; d.seat.position[1] = 0.45f; d.seat.position[2] = 0.3f; /* the front edge's middle, on top */ d.seat.turn_deg = 0; /* the way they face */ sona_interaction_start(ctx, &d, &it); ``` Starts it: the avatars are placed (eased over the first part of the start phase when they are near), their clips started together and their IK targets driven from now on. An avatar in another running interaction is refused (`SONA_E_ARGUMENT`); `SONA_E_LIMIT` when the ctx holds 64, finished ones included: an interaction is freed only by `sona_interaction_remove` (or `sona_close`), so a handle stays valid until the host removes it. ### sona_interaction_end ```c sona_result sona_interaction_end(sona_interaction *it); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `it` | `sona_interaction *` | The interaction | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Begins the end phase now (a hold of 0 waits for this). No effect once ending. ### sona_interaction_move ```c sona_result sona_interaction_move(sona_interaction *it, const float position[3], float turn_deg); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `it` | `sona_interaction *` | The interaction | required | | `position` | `const float [3]` | Where to move it, world space | required | | `turn_deg` | `float` | Which way it faces, degrees | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Moves the place (and the seat with it) while it runs, for a pair walking hand in hand; contacts follow. ### sona_interaction_remove ```c void sona_interaction_remove(sona_interaction *it); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `it` | `sona_interaction *` | The interaction | required | **Returns** Nothing. **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_interaction_desc d; sona_interaction *it; sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE); d.a = avatar; d.b = other; if (sona_interaction_start(ctx, &d, &it) == SONA_OK) { /* each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) */ } ``` Stops at once and frees it: its IK targets go, the avatars stay where they are and keep their clip. ### sona_interaction_status_get ```c sona_result sona_interaction_status_get(const sona_interaction *it, sona_interaction_status *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `it` | `const sona_interaction *` | The interaction | required | | `out` | `sona_interaction_status *` | Receives the [`sona_interaction_status`](https://360sona.com/devs/docs/reference/fields.md#sona_interaction_status) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Where an interaction is: its kind and phase, the time in the phase and how far through it, whether the contacts are together, the widest gap at a contact, the clearance between the two bodies (negative: into each other), the contact points now and the IK hit bits of both avatars' limbs. ### sona_interaction_events ```c uint32_t sona_interaction_events(sona_interaction *it, sona_interaction_event *out, uint32_t max); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `it` | `sona_interaction *` | The interaction | required | | `out` | `sona_interaction_event *` | Receives the [`sona_interaction_event`](https://360sona.com/devs/docs/reference/fields.md#sona_interaction_event) | required | | `max` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_interaction_desc d; sona_interaction *it; sona_interaction_defaults(&d, SONA_INTERACT_HIGH_FIVE); d.a = avatar; d.b = other; if (sona_interaction_start(ctx, &d, &it) == SONA_OK) { /* each frame: sona_interaction_events(it, ...); when it ends, sona_interaction_remove(it) */ } ``` Moves up to `max` events since the last call into `out` (`SONA_INTERACT_EV_*`: contact, a handshake pump, release, end, cancel) and returns how many. ## Text to emote A sentence to stock clips and a face: [Text to emote](https://360sona.com/devs/docs/guides/emote.md). ### sona_emote_from_text ```c sona_result sona_emote_from_text(const char *text, sona_emote *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `text` | `const char *` | A sentence, such as `"wave excitedly"` | required | | `out` | `sona_emote *` | Receives the [`sona_emote`](https://360sona.com/devs/docs/reference/fields.md#sona_emote) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_emote e = { sizeof e }; if (sona_emote_from_text("jump for joy", &e) == SONA_OK && e.count > 0) sona_avatar_emote(avatar, &e, 0.25f); ``` A sentence in ("wave excitedly", "shrug, not sure"), stock clips and a face out: up to four clips with weights to blend, a speed and an expression. Pure, no ctx: the same text gives the same answer. `count` 0 with a face is a mood with no action ("smile"). Set `out->size` first. [Text to emote](https://360sona.com/devs/docs/guides/emote.md) has the table. ### sona_avatar_emote ```c sona_result sona_avatar_emote(sona_avatar *a, const sona_emote *e, float fade_seconds); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `a` | `sona_avatar *` | The avatar | required | | `e` | `const sona_emote *` | A [`sona_emote`](https://360sona.com/devs/docs/reference/fields.md#sona_emote) | required | | `fade_seconds` | `float` | Seconds to blend over | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [Cookbook: recipes for game moments](https://360sona.com/devs/docs/cookbook.md)): ```c sona_emote e = { sizeof e }; if (sona_emote_from_text("jump for joy", &e) == SONA_OK && e.count > 0) sona_avatar_emote(avatar, &e, 0.25f); ``` Plays it on a: the clips blended on the emote layers (`SONA_LAYER_MAX` - count to `SONA_LAYER_MAX` - 1, each over the ones below by its share of the weight), faded in over fade_seconds; the face set when it has one. An emote plays once and hands back to the clip, but a dance, sleep, hover or run loops until the next emote. count 0 with no face stops the emote's layers and hands the face back. It never stops a layer the app played (a layer it played is the app's once the app plays anything on it): `SONA_E_LIMIT`, with nothing changed, when one is on a layer the emote needs. `SONA_E_MEMORY` also changes nothing. ## Award items Items a game defines and unlocks for its signed-in players, who then wear them in their 360sona wardrobe: [custom items: award items](https://360sona.com/devs/docs/guides/custom-items.md#award-items-from-your-own-game). ### sona_award_def_defaults ```c void sona_award_def_defaults(sona_award_def *d); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `d` | `sona_award_def *` | The [`sona_award_def`](https://360sona.com/devs/docs/reference/fields.md#sona_award_def) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_award_def x_award_def; sona_award_def_defaults(&x_award_def); sona_award_def_defaults(&x_award_def); ``` `size` set and everything else zero. ### sona_award_define ```c sona_result sona_award_define(sona_ctx *ctx, const sona_award_def *d, uint32_t *ticket); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `d` | `const sona_award_def *` | The options, a [`sona_award_def`](https://360sona.com/devs/docs/reference/fields.md#sona_award_def) | required | | `ticket` | `uint32_t *` | Receives a ticket for `sona_award_poll` | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_APP` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Defines an award item for an app with the app's developer key (a tool's call, never a shipped game's). It goes to `config.check_host` through the ctx's HTTP layer and gives a ticket: `sona_award_poll` after `sona_update` says how it went. ### sona_award_unlock ```c sona_result sona_award_unlock(sona_ctx *ctx, const char *player_token, const char *key, uint32_t *ticket); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `player_token` | `const char *` | The signed-in player's access token | required | | `key` | `const char *` | The award's key | required | | `ticket` | `uint32_t *` | Receives a ticket for `sona_award_poll` | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_IO`, `SONA_E_APP` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `player_token`: the signed-in player's access token (Sign in with 360sona). ### sona_award_poll ```c sona_result sona_award_poll(sona_ctx *ctx, uint32_t ticket); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `ticket` | `uint32_t` | The ticket the request gave | - | **Returns** `SONA_OK`, `SONA_PENDING` while it is still working. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_IO`, `SONA_E_GATE`, `SONA_E_APP` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example**: ```c sona_result result = sona_award_poll(ctx, 0); if (result != SONA_OK) printf("sona_award_poll: %s\n", sona_result_name(result)); ``` `SONA_PENDING` while it runs, then its result once: `SONA_OK`, `SONA_E_NOT_FOUND` (no such award), `SONA_E_APP` (a wrong key or token, or no awards scope), `SONA_E_ARGUMENT` (refused; see `sona_last_error`), `SONA_E_LIMIT`, `SONA_E_GATE` or `SONA_E_IO`. ## Body tracking module (sona_body.h) An optional library, `sona_body`, beside the core: webcam full-body pose to the avatar. Include `sona_body.h` and link `sona_body`. The guide: [Body tracking (sona_body)](https://360sona.com/devs/docs/guides/body-tracking.md). ### sona_body_defaults ```c void sona_body_defaults(sona_body_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_body_options *` | The [`sona_body_options`](https://360sona.com/devs/docs/reference/fields.md#sona_body_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_body_options x_body_options; memset(&x_body_options, 0, sizeof x_body_options); x_body_options.size = sizeof x_body_options; sona_body_defaults(&x_body_options); ``` `size` set; `min_cutoff` 1.5, `beta` 0.8, `min_visibility` 0.5, `lost_seconds` 0.5, `return_seconds` 0.4. ### sona_body_create ```c sona_result sona_body_create(const sona_body_options *o, sona_body_tracker **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `const sona_body_options *` | The options, a [`sona_body_options`](https://360sona.com/devs/docs/reference/fields.md#sona_body_options) | `NULL`: the defaults | | `out` | `sona_body_tracker **` | Receives the new body tracker | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). NULL options: the defaults. `SONA_E_ARGUMENT` for a wrong size or a value out of range. ### sona_body_destroy ```c void sona_body_destroy(sona_body_tracker *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_body_tracker *` | The body tracker | required | **Returns** Nothing. Frees the tracker. ### sona_body_reset ```c void sona_body_reset(sona_body_tracker *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_body_tracker *` | The body tracker | required | **Returns** Nothing. Forgets the filters and the tracking state; keeps the options. ### sona_body_input_defaults ```c void sona_body_input_defaults(sona_body_input *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `in` | `sona_body_input *` | The [`sona_body_input`](https://360sona.com/devs/docs/reference/fields.md#sona_body_input) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_body_input x_body_input; sona_body_input_defaults(&x_body_input); sona_body_input_defaults(&x_body_input); ``` `size` set, the MediaPipe layout and no points. ### sona_body_feed ```c sona_result sona_body_feed(sona_body_tracker *t, const sona_body_input *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_body_tracker *` | The body tracker | required | | `in` | `const sona_body_input *` | A [`sona_body_input`](https://360sona.com/devs/docs/reference/fields.md#sona_body_input) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One frame of what the body tracker saw (`sona_body_input`). `SONA_E_ARGUMENT` for a wrong size, a time that is not finite, or a found body without 33 points in the MediaPipe layout. ### sona_body_apply ```c sona_result sona_body_apply(sona_body_tracker *t, sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_body_tracker *` | The body tracker | required | | `a` | `sona_avatar *` | The avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Puts the pose on an avatar through overrides below the neck, after the clip and before the IK. One tracker drives one avatar at a time. `SONA_E_NOT_READY` until the avatar is READY and posed. ### sona_body_release ```c void sona_body_release(sona_body_tracker *t, sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_body_tracker *` | The body tracker | required | | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. Hands the joints back to the clip; nothing when a is not the avatar it drives. ### sona_body_struct_size ```c uint32_t sona_body_struct_size(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | A public struct's name | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_body_struct_size("sona_config"); printf("sona_body_struct_size: %lld\n", (long long)x_got); ``` sizeof a public struct of this header by name ("sona_body_options"), for the bindings' layout checks; 0 when unknown. ### sona_body_struct_offset ```c uint32_t sona_body_struct_offset(const char *struct_dot_field); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `struct_dot_field` | `const char *` | `"struct.field"` | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_body_struct_offset("example"); printf("sona_body_struct_offset: %lld\n", (long long)x_got); ``` offsetof a field by "struct.field" ("sona_body_input.points"); `UINT32_MAX` when unknown. ## Player editor module (sona_editor.h) An optional library, `sona_editor`: the player-facing editor, the same screens as 360sona.com's, drawn by the SDK for keyboard, gamepad, mouse and touch. Include `sona_editor.h` and link `sona_editor`. The guide: [Player editor](https://360sona.com/devs/docs/guides/editor.md). ### sona_editor_defaults ```c void sona_editor_defaults(sona_editor_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_editor_options *` | The [`sona_editor_options`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_editor_options x_editor_options; memset(&x_editor_options, 0, sizeof x_editor_options); x_editor_options.size = sizeof x_editor_options; sona_editor_defaults(&x_editor_options); ``` `size` set, 1280 x 720 (`sona_editor_resize` changes it), seed 1, everything else zero. ### sona_editor_theme_defaults ```c void sona_editor_theme_defaults(sona_editor_theme *t, uint32_t which); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_editor_theme *` | The [`sona_editor_theme`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_theme) to fill with the defaults | required | | `which` | `uint32_t` | Which built-in theme | - | **Returns** Nothing. **Example**: ```c sona_editor_theme x_editor_theme; memset(&x_editor_theme, 0, sizeof x_editor_theme); x_editor_theme.size = sizeof x_editor_theme; sona_editor_theme_defaults(&x_editor_theme, 0); ``` `which`: `SONA_EDITOR_THEME_LIGHT` (360sona.com's editor) or _DARK (the console slate). ### sona_editor_open ```c sona_result sona_editor_open(sona_ctx *ctx, const sona_editor_options *o, const sona_editor_theme *theme, sona_editor **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `o` | `const sona_editor_options *` | The options, a [`sona_editor_options`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_options) | required | | `theme` | `const sona_editor_theme *` | A [`sona_editor_theme`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_theme) | required | | `out` | `sona_editor **` | Receives the new editor | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_CORRUPT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `theme` NULL: the light (site) theme. `SONA_E_ARGUMENT` without a catalogue, for MODE_WARDROBE without a start manifest, or a start manifest that does not parse; `SONA_E_CORRUPT` for font bytes that do not load. ### sona_editor_close ```c void sona_editor_close(sona_editor *ed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | **Returns** Nothing. Removes its avatars from the ctx. ### sona_editor_set_theme ```c sona_result sona_editor_set_theme(sona_editor *ed, const sona_editor_theme *theme); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `theme` | `const sona_editor_theme *` | A [`sona_editor_theme`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_theme) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Changes the colours and sizes from the next frame. NULL: the light (site) theme. ### sona_editor_resize ```c sona_result sona_editor_resize(sona_editor *ed, uint32_t width, uint32_t height); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The editor's size in pixels, the size of the target it is drawn into. ### sona_editor_feed ```c sona_result sona_editor_feed(sona_editor *ed, const sona_editor_input *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `in` | `const sona_editor_input *` | A [`sona_editor_input`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_input) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). One input event (`SONA_EDITOR_IN_*`): a gamepad button or axis, a key, a typed character for the search box, a pointer or touch, or the wheel. ### sona_editor_update ```c uint32_t sona_editor_update(sona_editor *ed, double dt); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `dt` | `double` | Seconds since the last call | - | **Returns** `uint32_t`. Advances dt seconds: stick repeat, animations, avatar builds and (unless HOST_UPDATES) `sona_update` on the ctx. Returns `SONA_EDITOR_RUNNING`, _DONE or _CANCELLED (and keeps returning it). ### sona_editor_status ```c uint32_t sona_editor_status(const sona_editor *ed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | **Returns** `uint32_t`. `SONA_EDITOR_RUNNING`, `_DONE` or `_CANCELLED`, as the last `sona_editor_update` returned. ### sona_editor_result ```c sona_result sona_editor_result(const sona_editor *ed, uint8_t out[SONA_MANIFEST_BYTES]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | | `out` | `uint8_t [SONA_MANIFEST_BYTES]` | Receives the manifest's 1,000 bytes | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The avatar as it stands (at any time): `SONA_MANIFEST_BYTES`. After CANCELLED it is the start manifest. ### sona_editor_set_search ```c sona_result sona_editor_set_search(sona_editor *ed, const char *text); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `text` | `const char *` | The search text, UTF-8; NULL clears it | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The search box of the wardrobe and the item screens, for hosts with an on-screen keyboard (UTF-8; NULL clears). ### sona_editor_set_screen ```c sona_result sona_editor_set_screen(sona_editor *ed, uint32_t screen); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `screen` | `uint32_t` | A `SONA_EDITOR_SCREEN_*` | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Moves to a screen of the mode (a deprecated id to the screen that took its place). `SONA_E_ARGUMENT` for one the mode does not have, `SONA_EDITOR_SCREEN_LOOKS` in `SONA_EDITOR_MODE_FULL` among them. ### sona_editor_screen_get ```c uint32_t sona_editor_screen_get(const sona_editor *ed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | **Returns** `uint32_t`. The screen shown now. ### sona_editor_screens ```c uint32_t sona_editor_screens(const sona_editor *ed, uint32_t *out, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | | `out` | `uint32_t *` | Receives the values | required | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. The mode's screens in tab order: writes up to cap of them (out may be NULL) and returns how many there are. ### sona_editor_busy ```c int sona_editor_busy(const sona_editor *ed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | **Returns** `int`. 1 while an avatar is still building (the shown one or a change on its way); thumbnails do not count. A change that fails to build leaves the last avatar that did on screen; when the first one fails, nothing shows and busy is 0. ### sona_editor_build_failures ```c uint32_t sona_editor_build_failures(const sona_editor *ed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | **Returns** `uint32_t`. How many avatar builds failed since open (the screen reader is told each time). ### sona_editor_avatar ```c sona_avatar *sona_editor_avatar(const sona_editor *ed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | **Returns** `sona_avatar *`. The avatar on the editor's stage now, or NULL while the first one builds. It is the editor's: read it or hide it, never remove it. Each choice in the editor makes a new one, so ask again each frame. A host that draws the avatar layer itself uses it to fade the stage's avatar in and out. ### sona_editor_undo ```c int sona_editor_undo(sona_editor *ed, int redo); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `redo` | `int` | 1 for redo, 0 for undo | - | **Returns** `int`. Undoes the last change (`redo` 0) or redoes the last undone one (`redo` 1), for a host that draws the stage's own undo and redo buttons. Returns 1 when it stepped, 0 when there was nothing to step to. The editor keeps 32 steps. ### sona_editor_can_undo ```c int sona_editor_can_undo(const sona_editor *ed, int redo); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | | `redo` | `int` | 1 for redo, 0 for undo | - | **Returns** `int`. 1 when `sona_editor_undo` with the same `redo` would step: use it to grey out the buttons. ### sona_editor_zoom ```c double sona_editor_zoom(sona_editor *ed, double set); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `set` | `double` | A matched set's index | - | **Returns** `double`. The stage's zoom: 1 is the editor's own framing, from 0.6 to 3. A `set` above 0 sets it (clamped to that range); 0 only reads it. Returns the zoom now. ### sona_editor_turn ```c void sona_editor_turn(sona_editor *ed, double degrees); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `degrees` | `double` | How far to turn the avatar, degrees | - | **Returns** Nothing. Turns the avatar on the stage by `degrees`, as a drag across the stage does. ### sona_editor_view ```c sona_result sona_editor_view(const sona_editor *ed, sona_view *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | | `out` | `sona_view *` | Receives the [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The camera the avatar layer is drawn with (framed into avatar_rect of the full target). ### sona_editor_draw ```c sona_result sona_editor_draw(sona_editor *ed, sona_renderer *r, const sona_target *t, const sona_draw_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `r` | `sona_renderer *` | The renderer | required | | `t` | `const sona_target *` | Where the frame lands, a [`sona_target`](https://360sona.com/devs/docs/reference/fields.md#sona_target) | required | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | `NULL`: the defaults | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The editor into t: `sona_draw` with the editor's view and the theme's background, without the credit (the UI draws it), and the UI layer over it as r's overlay (rasterised on the CPU where it changed, uploaded where it changed, blended by the renderer; r has no overlay again afterwards); then up to two pending thumbnails (`sona_item_preview_snapshot` and `sona_snapshot` on r). opts NULL: defaults; its clear and the NO_CREDIT flag are the editor's. The UI is drawn at the editor's size over the whole target: resize the editor to the target. ### sona_editor_draw_avatar ```c sona_result sona_editor_draw_avatar(sona_editor *ed, sona_renderer *r, const sona_target *t, const sona_draw_options *opts); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `r` | `sona_renderer *` | The renderer | required | | `t` | `const sona_target *` | Where the frame lands, a [`sona_target`](https://360sona.com/devs/docs/reference/fields.md#sona_target) | required | | `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](https://360sona.com/devs/docs/reference/fields.md#sona_draw_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The avatar layer alone (and the thumbnails), for a host that draws the UI layer with its own 2D pass. ### sona_editor_thumbnails ```c uint32_t sona_editor_thumbnails(sona_editor *ed, sona_renderer *r, uint32_t budget); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `r` | `sona_renderer *` | The renderer | required | | `budget` | `uint32_t` | How many pictures to draw this call | - | **Returns** `uint32_t`. Renders up to budget pending thumbnails on r, for hosts that draw the avatar layer with their own `sona_draw`. ### sona_editor_draw_data_get ```c sona_result sona_editor_draw_data_get(sona_editor *ed, sona_editor_draw_data *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `out` | `sona_editor_draw_data *` | Receives the [`sona_editor_draw_data`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_draw_data) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The UI layer as of the last `sona_editor_update`. Pointers stay valid until the next update, resize or close. ### sona_editor_texture_get ```c sona_result sona_editor_texture_get(sona_editor *ed, uint32_t id, sona_editor_texture *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `id` | `uint32_t` | The id, as the call that made it gave it | - | | `out` | `sona_editor_texture *` | Receives the [`sona_editor_texture`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_texture) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). A texture the draw data names by id, with its pixels (straight RGBA8, owned by the editor) and the rectangle that changed since an older revision, for a host that draws the UI layer itself. ### sona_editor_render_ui ```c sona_result sona_editor_render_ui(sona_editor *ed, uint8_t *rgba, uint32_t width, uint32_t height, uint32_t stride, int over); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `rgba` | `uint8_t *` | Receives straight RGBA8, row 0 at the top | required | | `width` | `uint32_t` | The picture's width in pixels | - | | `height` | `uint32_t` | The picture's height in pixels | - | | `stride` | `uint32_t` | Bytes from one row to the next | - | | `over` | `int` | 1 to blend over what `rgba` holds, 0 to replace it | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The UI layer rasterised on the CPU into width x height straight RGBA8 (stride in bytes, 0: width * 4). over 1: blended over what rgba holds (a snapshot of the avatar layer); 0: cleared to transparent first. ### sona_editor_snapshot ```c sona_result sona_editor_snapshot(sona_editor *ed, sona_renderer *r, uint8_t *rgba); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `r` | `sona_renderer *` | The renderer | required | | `rgba` | `uint8_t *` | Receives straight RGBA8, row 0 at the top | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The whole picture into rgba (width * height * 4 of the editor's size): `sona_snapshot` of the avatar layer, then render_ui over it. For screenshots, tests and servers. ### sona_editor_control_count ```c uint32_t sona_editor_control_count(const sona_editor *ed); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | **Returns** `uint32_t`. Every control on screen, in reading order, and the focused one. ### sona_editor_control_get ```c sona_result sona_editor_control_get(const sona_editor *ed, uint32_t index, sona_editor_control *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | | `index` | `uint32_t` | Which one, from 0 | - | | `out` | `sona_editor_control *` | Receives the [`sona_editor_control`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_control) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Control `index` in reading order: its id, role, flags, rectangle, value, place in its group, label, value text and hint ("Wear it"), for a screen reader or a test. ### sona_editor_focus_get ```c sona_result sona_editor_focus_get(const sona_editor *ed, sona_editor_control *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `const sona_editor *` | The editor | required | | `out` | `sona_editor_control *` | Receives the [`sona_editor_control`](https://360sona.com/devs/docs/reference/fields.md#sona_editor_control) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `SONA_E_NOT_FOUND` when nothing has focus (pointer-only use). ### sona_editor_announcement ```c uint32_t sona_editor_announcement(sona_editor *ed, char *out, uint32_t cap); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ed` | `sona_editor *` | The editor | required | | `out` | `char *` | Receives the text, NUL-terminated | required | | `cap` | `uint32_t` | How many entries `out` holds | - | **Returns** `uint32_t`. What a screen reader should say since the last call ("Wardrobe, tab, 6 of 6", "Blue Hoodie, 3 of 120, worn"): copies it (UTF-8, NUL-terminated, cut at cap) and returns its length; 0 when nothing changed. ### sona_editor_struct_size ```c uint32_t sona_editor_struct_size(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | A public struct's name | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_editor_struct_size("sona_config"); printf("sona_editor_struct_size: %lld\n", (long long)x_got); ``` sizeof a public struct of this header by name, for the bindings' layout checks; 0 when unknown. ### sona_editor_struct_offset ```c uint32_t sona_editor_struct_offset(const char *struct_dot_field); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `struct_dot_field` | `const char *` | `"struct.field"` | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_editor_struct_offset("example"); printf("sona_editor_struct_offset: %lld\n", (long long)x_got); ``` offsetof a field by "struct.field"; `UINT32_MAX` when unknown. ## NPC kit module (sona_npc.h) An optional library, `sona_npc`: an avatar that says its lines with lip sync, emotes and looks at the player. Include `sona_npc.h` and link `sona_npc`. The guide: [The NPC kit (sona_npc)](https://360sona.com/devs/docs/guides/npc.md). ### sona_npc_defaults ```c void sona_npc_defaults(sona_npc_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_npc_options *` | The [`sona_npc_options`](https://360sona.com/devs/docs/reference/fields.md#sona_npc_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_npc_options x_npc_options; memset(&x_npc_options, 0, sizeof x_npc_options); x_npc_options.size = sizeof x_npc_options; sona_npc_defaults(&x_npc_options); ``` `size` set; `look_seconds` 2, `idle_emote_seconds` 8 (0: never). ### sona_npc_create ```c sona_result sona_npc_create(sona_ctx *ctx, sona_avatar *a, const sona_npc_options *o, sona_npc **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `ctx` | `sona_ctx *` | The context | required | | `a` | `sona_avatar *` | The avatar | required | | `o` | `const sona_npc_options *` | The options, a [`sona_npc_options`](https://360sona.com/devs/docs/reference/fields.md#sona_npc_options) | `NULL`: the defaults | | `out` | `sona_npc **` | Receives the new NPC | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Drives a, which must stay in ctx while the NPC lives. NULL options: the defaults. ### sona_npc_destroy ```c void sona_npc_destroy(sona_npc *npc); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `npc` | `sona_npc *` | The NPC | required | **Returns** Nothing. Stops the NPC; the avatar stays in the ctx. ### sona_npc_say ```c sona_result sona_npc_say(sona_npc *npc, const char *text, uint32_t *line); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `npc` | `sona_npc *` | The NPC | required | | `text` | `const char *` | The line to say, UTF-8 | required | | `line` | `uint32_t *` | Receives the line's number; may be NULL | `NULL`: not written | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The NPC kit (sona_npc)](https://360sona.com/devs/docs/guides/npc.md)): ```c uint32_t id; sona_npc_say(npc, "Hello there! Welcome to my shop.", &id); /* queued; said in order */ sona_npc_emote(npc, "laugh"); /* at once, without a word */ float head[3] = { px, py, pz }; /* the player's head, world space */ sona_npc_look_at(npc, head); /* NULL: no one to look at */ ``` Queues a line (UTF-8). *line (may be NULL) is its number, for the line callback. ### sona_npc_emote ```c sona_result sona_npc_emote(sona_npc *npc, const char *text); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `npc` | `sona_npc *` | The NPC | required | | `text` | `const char *` | What to do, such as `"wave"` | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The NPC kit (sona_npc)](https://360sona.com/devs/docs/guides/npc.md)): ```c uint32_t id; sona_npc_say(npc, "Hello there! Welcome to my shop.", &id); /* queued; said in order */ sona_npc_emote(npc, "laugh"); /* at once, without a word */ float head[3] = { px, py, pz }; /* the player's head, world space */ sona_npc_look_at(npc, head); /* NULL: no one to look at */ ``` Emotes from text at once, without speaking ("wave", "laugh"). ### sona_npc_look_at ```c sona_result sona_npc_look_at(sona_npc *npc, const float target[3]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `npc` | `sona_npc *` | The NPC | required | | `target` | `const float [3]` | The point to look at, world space; NULL: stop looking | `NULL`: stop looking | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The NPC kit (sona_npc)](https://360sona.com/devs/docs/guides/npc.md)): ```c uint32_t id; sona_npc_say(npc, "Hello there! Welcome to my shop.", &id); /* queued; said in order */ sona_npc_emote(npc, "laugh"); /* at once, without a word */ float head[3] = { px, py, pz }; /* the player's head, world space */ sona_npc_look_at(npc, head); /* NULL: no one to look at */ ``` The player's head, world space; NULL: no player to look at. ### sona_npc_update ```c sona_result sona_npc_update(sona_npc *npc, double dt); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `npc` | `sona_npc *` | The NPC | required | | `dt` | `double` | Seconds since the last call | - | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_FOUND`, `SONA_E_LIMIT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The NPC kit (sona_npc)](https://360sona.com/devs/docs/guides/npc.md)): ```c sona_npc_update(npc, dt); sona_update(ctx, dt, NULL, NULL); sona_npc_state st; st.size = sizeof st; sona_npc_state_get(npc, &st); /* SONA_NPC_IDLE, _SPEAKING (st.line), _EMOTING; st.queued */ ``` Advances the NPC by `dt` seconds: the line being said and its lip sync, emotes, the look at the player and the idle. Call it each frame before `sona_update`. ### sona_npc_state_get ```c sona_result sona_npc_state_get(const sona_npc *npc, sona_npc_state *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `npc` | `const sona_npc *` | The NPC | required | | `out` | `sona_npc_state *` | Receives the [`sona_npc_state`](https://360sona.com/devs/docs/reference/fields.md#sona_npc_state) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [The NPC kit (sona_npc)](https://360sona.com/devs/docs/guides/npc.md)): ```c sona_npc_update(npc, dt); sona_update(ctx, dt, NULL, NULL); sona_npc_state st; st.size = sizeof st; sona_npc_state_get(npc, &st); /* SONA_NPC_IDLE, _SPEAKING (st.line), _EMOTING; st.queued */ ``` What the NPC is doing: idle, speaking or emoting, the line being said (0 when none) and how many lines wait. ### sona_npc_struct_size ```c uint32_t sona_npc_struct_size(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | A public struct's name | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_npc_struct_size("sona_config"); printf("sona_npc_struct_size: %lld\n", (long long)x_got); ``` sizeof a public struct of this header by name, for the bindings' layout checks; 0 when unknown. ### sona_npc_struct_offset ```c uint32_t sona_npc_struct_offset(const char *struct_dot_field); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `struct_dot_field` | `const char *` | `"struct.field"` | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_npc_struct_offset("example"); printf("sona_npc_struct_offset: %lld\n", (long long)x_got); ``` offsetof a field by "struct.field"; `UINT32_MAX` when unknown. ## Face tracking module (sona_track.h) An optional library, `sona_track`: a face tracker's blendshapes and head pose to the avatar. Include `sona_track.h` and link `sona_track`. The guide: [Face tracking (sona_track)](https://360sona.com/devs/docs/guides/face-tracking.md). ### sona_track_blendshape_name ```c const char * sona_track_blendshape_name(uint32_t index); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `index` | `uint32_t` | Which one, from 0 | - | **Returns** `const char *`. **Example**: ```c const char * x_got = sona_track_blendshape_name(0); printf("sona_track_blendshape_name: %s\n", x_got ? "a value" : "none"); ``` The name of blendshape `index` ("eyeBlinkLeft", ...) as both trackers spell them; NULL past the last. ### sona_track_blendshape_find ```c int32_t sona_track_blendshape_find(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | The name to look up | required | **Returns** `int32_t`. **Example**: ```c int32_t x_got = sona_track_blendshape_find("speed"); printf("sona_track_blendshape_find: %lld\n", (long long)x_got); ``` The index of a blendshape by name; -1 when unknown. ### sona_track_defaults ```c void sona_track_defaults(sona_track_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_track_options *` | The [`sona_track_options`](https://360sona.com/devs/docs/reference/fields.md#sona_track_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_track_options x_track_options; memset(&x_track_options, 0, sizeof x_track_options); x_track_options.size = sizeof x_track_options; sona_track_defaults(&x_track_options); ``` `size` set and the filter and head settings the [face tracking](https://360sona.com/devs/docs/guides/face-tracking.md) guide lists. ### sona_track_create ```c sona_result sona_track_create(const sona_track_options *o, sona_tracker **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `const sona_track_options *` | The options, a [`sona_track_options`](https://360sona.com/devs/docs/reference/fields.md#sona_track_options) | `NULL`: the defaults | | `out` | `sona_tracker **` | Receives the new face tracker | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). NULL options: the defaults. `SONA_E_ARGUMENT` for a wrong size or a value out of range. ### sona_track_destroy ```c void sona_track_destroy(sona_tracker *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | **Returns** Nothing. Frees the tracker. ### sona_track_set_options ```c sona_result sona_track_set_options(sona_tracker *t, const sona_track_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | | `o` | `const sona_track_options *` | The options, a [`sona_track_options`](https://360sona.com/devs/docs/reference/fields.md#sona_track_options) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). New options from the next frame; the filters keep their state. `SONA_E_ARGUMENT` for a wrong size or a value out of range. ### sona_track_reset ```c void sona_track_reset(sona_tracker *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | **Returns** Nothing. Forgets the filters, the shapes held and the tracking state; keeps the options and the calibration. ### sona_track_face_input_defaults ```c void sona_track_face_input_defaults(sona_track_face_input *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `in` | `sona_track_face_input *` | The [`sona_track_face_input`](https://360sona.com/devs/docs/reference/fields.md#sona_track_face_input) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_track_face_input x_track_face_input; sona_track_face_input_defaults(&x_track_face_input); sona_track_face_input_defaults(&x_track_face_input); ``` `size` set, the ARKit layout, nothing found. ### sona_track_face_feed ```c sona_result sona_track_face_feed(sona_tracker *t, const sona_track_face_input *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | | `in` | `const sona_track_face_input *` | A [`sona_track_face_input`](https://360sona.com/devs/docs/reference/fields.md#sona_track_face_input) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). `SONA_E_ARGUMENT` for a wrong size, layout or count, a missing weights pointer with FOUND, or a time that is not finite. A time more than a second away from the last one (or earlier than it) starts the filters again. ### sona_track_face_get ```c sona_result sona_track_face_get(const sona_tracker *t, sona_track_face_state *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `const sona_tracker *` | The face tracker | required | | `out` | `sona_track_face_state *` | Receives the [`sona_track_face_state`](https://360sona.com/devs/docs/reference/fields.md#sona_track_face_state) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). What the tracker makes of the frames so far: the filtered, calibrated weights in ARKit order (sides swapped under `SONA_TRACK_MIRROR`, so Left is the avatar's left) and the head. ### sona_track_calibrate_begin ```c sona_result sona_track_calibrate_begin(sona_tracker *t); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Starts collecting a neutral face: every frame with a face from now on counts. ### sona_track_calibrate_end ```c sona_result sona_track_calibrate_end(sona_tracker *t, sona_track_calibration *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | | `out` | `sona_track_calibration *` | Receives the [`sona_track_calibration`](https://360sona.com/devs/docs/reference/fields.md#sona_track_calibration) | `NULL` allowed (below) | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Stops and makes each weight's 30th percentile over the frames (the first 300) and their mean head rotation the neutral, and writes it to `out` (may be NULL). `SONA_E_NOT_READY` when no face came in between. Each weight's neutral value is taken off it and the rest rescaled to 0..1; the neutral head rotation becomes identity. ### sona_track_calibration_set ```c sona_result sona_track_calibration_set(sona_tracker *t, const sona_track_calibration *c); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | | `c` | `const sona_track_calibration *` | A [`sona_track_calibration`](https://360sona.com/devs/docs/reference/fields.md#sona_track_calibration) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). A saved calibration, for the next session; NULL clears it. ### sona_track_calibration_get ```c sona_result sona_track_calibration_get(const sona_tracker *t, sona_track_calibration *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `const sona_tracker *` | The face tracker | required | | `out` | `sona_track_calibration *` | Receives the [`sona_track_calibration`](https://360sona.com/devs/docs/reference/fields.md#sona_track_calibration) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The calibration in use, as `sona_track_calibrate_end` or `sona_track_calibration_set` left it. ### sona_track_apply ```c sona_result sona_track_apply(sona_tracker *t, sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | | `a` | `sona_avatar *` | The avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Puts the state on an avatar: the face shapes through `sona_avatar_expression` (only when they change) and the head through ADD overrides on Neck and Head, aimed in the avatar's body space from its posed joints, so it holds for any turn, lean or clip (overrides need a clip playing: the default idle does). Call it after the feed and before `sona_update`. One tracker drives one avatar at a time: moving it to another leaves the first as it is, so release that one first. `SONA_E_NOT_READY` until the avatar is READY and posed. ### sona_track_release ```c void sona_track_release(sona_tracker *t, sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `t` | `sona_tracker *` | The face tracker | required | | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. Hands the face and the tracker's joints back to the clip; nothing when a is not the avatar it drives. ### sona_track_quat_from_matrix ```c sona_result sona_track_quat_from_matrix(const float *m, uint32_t stride, int transpose, float q[4]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `m` | `const float *` | A 3x3 or 4x4 rotation matrix | required | | `stride` | `uint32_t` | Bytes from one row to the next | - | | `transpose` | `int` | 1 when the matrix is column-major | - | | `q` | `float [4]` | Receives a unit quaternion (x, y, z, w) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). A rotation matrix to the quaternion head_rotation takes. m holds the 3x3 rotation row by row (m[0..2] the first row); stride is the distance between rows in floats, 3 for a 3x3 and 4 for the upper left of a row-major 4x4 (MediaPipe's facial transformation matrix as numpy holds it). A column-major 4x4 (ARKit's simd_float4x4, glTF) is the transpose: pass transpose 1. Scale is removed. ### sona_track_quat_from_euler ```c void sona_track_quat_from_euler(float pitch_deg, float yaw_deg, float roll_deg, float q[4]); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `pitch_deg` | `float` | Pitch in degrees, up positive | - | | `yaw_deg` | `float` | Yaw in degrees | - | | `roll_deg` | `float` | Roll in degrees | - | | `q` | `float [4]` | Receives a unit quaternion (x, y, z, w) | required | **Returns** Nothing. **Example**: ```c float x_q[4]; memset(x_q, 0, sizeof x_q); sona_track_quat_from_euler(30.0f, 30.0f, 30.0f, x_q); ``` Degrees, right-handed about the camera axes: pitch about +X (nodding down is positive), yaw about +Y (turning towards the image's right, the subject's own left, is positive), roll about +Z; applied roll, then pitch, then yaw (q = yaw * pitch * roll). Many trackers (OpenSeeFace, head-pose solvers) give these. ### sona_track_struct_size ```c uint32_t sona_track_struct_size(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | A public struct's name | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_track_struct_size("sona_config"); printf("sona_track_struct_size: %lld\n", (long long)x_got); ``` sizeof a public struct of this header by name ("sona_track_options"), for the bindings' layout checks; 0 when unknown. ### sona_track_struct_offset ```c uint32_t sona_track_struct_offset(const char *struct_dot_field); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `struct_dot_field` | `const char *` | `"struct.field"` | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_track_struct_offset("example"); printf("sona_track_struct_offset: %lld\n", (long long)x_got); ``` offsetof a field by "struct.field" ("sona_track_face_state.weights"); `UINT32_MAX` when unknown. ## XR body module (sona_xr.h) An optional library, `sona_xr`: a first-person body driven by a headset and two controllers, for OpenXR games. Include `sona_xr.h` and link `sona_xr`. ### sona_xr_defaults ```c void sona_xr_defaults(sona_xr_options *o); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `sona_xr_options *` | The [`sona_xr_options`](https://360sona.com/devs/docs/reference/fields.md#sona_xr_options) to fill with the defaults | required | **Returns** Nothing. **Example**: ```c sona_xr_options x_xr_options; memset(&x_xr_options, 0, sizeof x_xr_options); x_xr_options.size = sizeof x_xr_options; sona_xr_defaults(&x_xr_options); ``` `size` set; `step_distance` 0.25. ### sona_xr_create ```c sona_result sona_xr_create(const sona_xr_options *o, sona_xr_body **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `o` | `const sona_xr_options *` | The options, a [`sona_xr_options`](https://360sona.com/devs/docs/reference/fields.md#sona_xr_options) | `NULL`: the defaults | | `out` | `sona_xr_body **` | Receives the new XR body | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). A first-person body for a headset and two controllers. NULL options: the defaults. ### sona_xr_destroy ```c void sona_xr_destroy(sona_xr_body *xr); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `xr` | `sona_xr_body *` | The XR body | required | **Returns** Nothing. Frees it. ### sona_xr_input_defaults ```c void sona_xr_input_defaults(sona_xr_input *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `in` | `sona_xr_input *` | The [`sona_xr_input`](https://360sona.com/devs/docs/reference/fields.md#sona_xr_input) to fill with the defaults | required | **Returns** Nothing. **Example** (also in [VR and XR bodies (sona_xr)](https://360sona.com/devs/docs/guides/xr.md)): ```c sona_xr_input in; sona_xr_input_defaults(&in); in.time = now; /* seconds, rising */ in.flags = SONA_XR_HAS_HEAD; /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */ in.head.position[0] = head_pos[0]; in.head.position[1] = head_pos[1]; in.head.position[2] = head_pos[2]; sona_xr_feed(xr, &in); if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar); sona_update(ctx, dt, &view, NULL); ``` `size` set, the three poses at the origin with no turn, the floor at 0. ### sona_xr_feed ```c sona_result sona_xr_feed(sona_xr_body *xr, const sona_xr_input *in); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `xr` | `sona_xr_body *` | The XR body | required | | `in` | `const sona_xr_input *` | A [`sona_xr_input`](https://360sona.com/devs/docs/reference/fields.md#sona_xr_input) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [VR and XR bodies (sona_xr)](https://360sona.com/devs/docs/guides/xr.md)): ```c sona_xr_input in; sona_xr_input_defaults(&in); in.time = now; /* seconds, rising */ in.flags = SONA_XR_HAS_HEAD; /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */ in.head.position[0] = head_pos[0]; in.head.position[1] = head_pos[1]; in.head.position[2] = head_pos[2]; sona_xr_feed(xr, &in); if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar); sona_update(ctx, dt, &view, NULL); ``` One frame of the head and the two grip poses (world metres, as `XrPosef`), with its time in seconds and the floor's height. ### sona_xr_calibrate ```c sona_result sona_xr_calibrate(sona_xr_body *xr); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `xr` | `sona_xr_body *` | The XR body | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Takes the wearer's height and arm span from the poses fed while they stand straight. ### sona_xr_apply ```c sona_result sona_xr_apply(sona_xr_body *xr, sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `xr` | `sona_xr_body *` | The XR body | required | | `a` | `sona_avatar *` | The avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_NOT_READY`, `SONA_E_UNSUPPORTED`, `SONA_E_MEMORY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). **Example** (also in [VR and XR bodies (sona_xr)](https://360sona.com/devs/docs/guides/xr.md)): ```c sona_xr_input in; sona_xr_input_defaults(&in); in.time = now; /* seconds, rising */ in.flags = SONA_XR_HAS_HEAD; /* and _HAS_LEFT, _HAS_RIGHT for the grips the runtime tracked */ in.head.position[0] = head_pos[0]; in.head.position[1] = head_pos[1]; in.head.position[2] = head_pos[2]; sona_xr_feed(xr, &in); if (sona_avatar_state_of(avatar) == SONA_AVATAR_READY) sona_xr_apply(xr, avatar); sona_update(ctx, dt, &view, NULL); ``` Puts the body on an avatar, scaled to the wearer. `SONA_E_NOT_READY` until the avatar is READY and posed. ### sona_xr_release ```c void sona_xr_release(sona_xr_body *xr, sona_avatar *a); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `xr` | `sona_xr_body *` | The XR body | required | | `a` | `sona_avatar *` | The avatar | required | **Returns** Nothing. Hands the avatar's joints back to its clip; nothing when `a` is not the avatar it drives. ### sona_xr_status_get ```c sona_result sona_xr_status_get(const sona_xr_body *xr, sona_xr_status *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `xr` | `const sona_xr_body *` | The XR body | required | | `out` | `sona_xr_status *` | Receives the [`sona_xr_status`](https://360sona.com/devs/docs/reference/fields.md#sona_xr_status) | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Fills `out` (a `sona_xr_status`) with what the last `sona_xr_apply` did: the poses tracked, the eye height and scale in use, the body's turn, placement and crouch, the steps taken and where the avatar's eyes were put. `out->size` is set by the call. `SONA_E_NOT_READY`, with `out` zeroed, before the body has been applied; `SONA_E_ARGUMENT` for NULL. ### sona_xr_openxr_to_world ```c void sona_xr_openxr_to_world(const sona_xr_pose *in, sona_xr_pose *out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `in` | `const sona_xr_pose *` | A [`sona_xr_pose`](https://360sona.com/devs/docs/reference/fields.md#sona_xr_pose) | required | | `out` | `sona_xr_pose *` | Receives the [`sona_xr_pose`](https://360sona.com/devs/docs/reference/fields.md#sona_xr_pose) | required | **Returns** Nothing. **Example**: ```c sona_xr_pose x_xr_pose; memset(&x_xr_pose, 0, sizeof x_xr_pose); sona_xr_pose x_xr_pose2; memset(&x_xr_pose2, 0, sizeof x_xr_pose2); sona_xr_openxr_to_world(&x_xr_pose, &x_xr_pose2); ``` Turns an OpenXR pose (a view, a hand, an object; right-handed) into sona's world: z mirrored, then half a turn about Y, so OpenXR's identity faces -Z as an avatar at turn 0 does. `in` and `out` may be the same. The module does this itself for poses fed with `SONA_XR_OPENXR_SPACE`; call it to place your own things beside the body. Nothing for NULL. ### sona_xr_struct_size ```c uint32_t sona_xr_struct_size(const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `name` | `const char *` | A public struct's name | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_xr_struct_size("sona_config"); printf("sona_xr_struct_size: %lld\n", (long long)x_got); ``` sizeof a public struct of this header by name, for the bindings' layout checks; 0 when unknown. ### sona_xr_struct_offset ```c uint32_t sona_xr_struct_offset(const char *struct_dot_field); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `struct_dot_field` | `const char *` | `"struct.field"` | required | **Returns** `uint32_t`. **Example**: ```c uint32_t x_got = sona_xr_struct_offset("example"); printf("sona_xr_struct_offset: %lld\n", (long long)x_got); ``` offsetof a field by "struct.field"; `UINT32_MAX` when unknown. ## Xbox 360 homebrew module (sona_xsdk.h) In the `xbox360` download only, inside `libsona.a` for xsdk: the calls a title needs to put avatars on the TV. Include `sona_xsdk.h`. The guide: [Xbox 360 homebrew](https://360sona.com/devs/docs/guides/xbox360.md). ### sona_xsdk_defaults ```c void sona_xsdk_defaults(sona_xsdk_config *c); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `c` | `sona_xsdk_config *` | The [`sona_xsdk_config`](https://360sona.com/devs/docs/reference/fields.md#sona_xsdk_config) to fill with the defaults | required | **Returns** Nothing. `size` set; `folder` `"game:/"`, `tv` 1, `max_avatars` 64, `memory_mb` 160, `workers` 5, `log_level` `SONA_LOG_WARN`, a dark blue `clear`. ### sona_xsdk_open ```c sona_result sona_xsdk_open(const sona_xsdk_config *c, sona_xsdk **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `c` | `const sona_xsdk_config *` | The options, a [`sona_xsdk_config`](https://360sona.com/devs/docs/reference/fields.md#sona_xsdk_config) | required | | `out` | `sona_xsdk **` | Receives the new Xbox 360 title | required | **Returns** `SONA_OK`. **Errors** `SONA_E_NOT_FOUND` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). Takes the licence built into the title (`samples/x360/embed-licence.cmake`), else `sona-licence.json` from `folder`, and opens the core with two sources: `folder`'s `360sona/` when there is one, then the gate. Starts the workers on hardware threads 1 to 5, opens xsdk's present at 720p when `tv` is 1 and a display opens, and blocks until the Xenos renderer is ready, at most 60 s. Each failure is written to the title's log. `SONA_E_NOT_FOUND` when the title has no licence built in and there is no `sona-licence.json` in `folder`. ### sona_xsdk_add_player ```c sona_result sona_xsdk_add_player(sona_xsdk *sx, uint32_t user_index, const sona_add_options *opts, sona_avatar **out); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `sona_xsdk *` | The Xbox 360 title | required | | `user_index` | `uint32_t` | The signed-in user, 0 to 3, one per controller | - | | `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](https://360sona.com/devs/docs/reference/fields.md#sona_add_options) | `NULL`: the defaults | | `out` | `sona_avatar **` | Receives the new avatar | required | **Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](https://360sona.com/devs/docs/troubleshooting.md#error-codes)). The signed-in player in their own avatar, in the middle of the stage facing the camera. It tries the profile on this console first, then 360sona's lookup by the profile's gamertag, then the gamertag in `sona-player.txt` in `folder`. The neutral figure stands there until one answers, and `*out` keeps the same handle when it does. `opts` NULL: the defaults, idling. `SONA_E_ARGUMENT` for a fifth player or a `user_index` past 3. ### sona_xsdk_view ```c void sona_xsdk_view(const sona_xsdk *sx, sona_view *view); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | | `view` | `sona_view *` | Receives the camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | **Returns** Nothing. The stage at 1280 by 720: 40 degrees, from 1.35 m up and 5.2 m back. `sona_camera_preset` frames one avatar instead. ### sona_xsdk_frame ```c int sona_xsdk_frame(sona_xsdk *sx, const sona_view *view); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `sona_xsdk *` | The Xbox 360 title | required | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | **Returns** `int`. Returns 1 while the title should go on, and 0 for BACK on the first controller or when the display is gone. Reads the first controller (nothing while the Guide is open) and takes the players' lookups. Calls `sona_update` with the time since the last frame, draws `view` and presents it on vblank. Off screen it draws into a target of its own. It never takes the context's events: `sona_poll_event` on `sona_xsdk_ctx(sx)` still gives them. ### sona_xsdk_dt ```c double sona_xsdk_dt(const sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | **Returns** `double`. The seconds between the last two frames, for moving things. ### sona_xsdk_time ```c double sona_xsdk_time(const sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | **Returns** `double`. The seconds since `sona_xsdk_open`. ### sona_xsdk_held ```c uint16_t sona_xsdk_held(const sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | **Returns** `uint16_t`. The first controller's buttons held at the last frame, as `INPUT_GAMEPAD_*` bits. ### sona_xsdk_pressed ```c uint16_t sona_xsdk_pressed(const sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | **Returns** `uint16_t`. The buttons pressed since the frame before, as `INPUT_GAMEPAD_*` bits. ### sona_xsdk_stick ```c void sona_xsdk_stick(const sona_xsdk *sx, float *x, float *y); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | | `x` | `float *` | Receives the stick across, -1 left to 1 right; may be NULL | `NULL` allowed (below) | | `y` | `float *` | Receives the stick up and down, -1 down to 1 up; may be NULL | `NULL` allowed (below) | **Returns** Nothing. The first controller's left stick at the last frame, each axis -1 to 1 with up as +y, and 0 inside the usual dead zone (7,849 of 32,767). `x` and `y` may be NULL. ### sona_xsdk_on_tv ```c int sona_xsdk_on_tv(const sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | **Returns** `int`. 1 when frames go to the TV; 0 when they are drawn off screen (no display, as in Xenia, or `tv` 0). ### sona_xsdk_settled ```c int sona_xsdk_settled(const sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `const sona_xsdk *` | The Xbox 360 title | required | **Returns** `int`. 1 when every player's avatar is known and nothing is still loading. ### sona_xsdk_snapshot ```c sona_result sona_xsdk_snapshot(sona_xsdk *sx, const sona_view *view, const char *name); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `sona_xsdk *` | The Xbox 360 title | required | | `view` | `const sona_view *` | The camera, a [`sona_view`](https://360sona.com/devs/docs/reference/fields.md#sona_view) | required | | `name` | `const char *` | The file's name, ending `.png` or `.ppm` | required | **Returns** `SONA_OK`. Draws `view` once more, reads it back and writes it to `folder`, or to `cache:\` where `folder` is read-only (Xenia). ### sona_xsdk_ctx ```c sona_ctx *sona_xsdk_ctx(sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `sona_xsdk *` | The Xbox 360 title | required | **Returns** `sona_ctx *`. The context, for every other call of `sona.h`. ### sona_xsdk_renderer ```c sona_renderer *sona_xsdk_renderer(sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `sona_xsdk *` | The Xbox 360 title | required | **Returns** `sona_renderer *`. The Xenos renderer, for `sona_draw` and `sona_snapshot` of your own. ### sona_xsdk_close ```c void sona_xsdk_close(sona_xsdk *sx); ``` | Parameter | Type | Meaning | Default | |---|---|---|---| | `sx` | `sona_xsdk *` | The Xbox 360 title | required | **Returns** Nothing. Closes the lookups, the renderer, the context and the display. The worker threads stay for a later `sona_xsdk_open`. ## Types Every public type of the headers, by name: what it is, its fields or values, and the calls that take it. The header's comment beside each field or value is its full description. | Type | What it is | |---|---| | `sona_result` | An enum: `SONA_OK`, `SONA_PENDING`, `SONA_E_UNSUPPORTED`, `SONA_E_ORIGIN`, `SONA_E_LICENCE`, `SONA_E_APP` and more; taken by `sona_result_name`, `sona_complete`, `sona_open`, `sona_abi_query` and more | | `sona_error_info` | The last error on a ctx: code, message and what to do about it. A struct with `code`, `message`, `fix`; taken by `sona_last_error` | | `sona_allocator` | A struct with `alloc`, `free`, `user`; taken by `sona_lipsync_create` | | `sona_budget` | Memory budget in bytes. A struct with `total`, `assets`, `clips`, `faces`, `source_cache`, `gpu_idle`; a field of `sona_config` | | `sona_jobs` | A host job system. A struct with `user`, `workers`, `run`; a field of `sona_config` | | `sona_http_request` | A struct with `method`, `url`, `headers`, `body`, `body_len`, `timeout_ms`; a field of `sona_http` | | `sona_http` | A struct with `user`, `send`; taken by `sona_http_platform` | | `sona_read_kind` | An enum: `SONA_READ_ASSET`, `SONA_READ_DATA`; a field of `sona_source` | | `sona_source` | A host-written source. A struct with `user`, `read`, `cancel`, `destroy`; a field of `sona_source_desc` | | `sona_source_desc` | A struct with `kind`, `location`, `custom`; a field of `sona_config` | | `sona_config` | A struct with `abi`, `app_id`, `licence`, `licence_len`, `sources`, `source_count`, `http`, `allocator` and more; taken by `sona_config_defaults`, `sona_open` | | `sona_xsdk` | An Xbox 360 title's avatars, renderer and display (`sona_xsdk.h`); made by `sona_xsdk_open` | | `sona_xsdk_config` | A struct with `size`, `folder`, `tv`, `max_avatars`, `memory_mb`, `workers`, `clear`, `log_level` and more; taken by `sona_xsdk_defaults`, `sona_xsdk_open` | | `sona_abi_info` | The ABI of the library that is loaded, for hosts and bindings that load it at run time: abi is its SONA_ABI, oldest_abi the oldest SONA_ABI a caller may be built against and still load it (nothing breaks for two minor versions), and its version as numbers. A struct with `abi`, `oldest_abi`, `major`, `minor`, `patch`; taken by `sona_abi_query` | | `sona_event` | A struct with `type`, `avatar`, `code`, `message`, `fix`; taken by `sona_poll_event` | | `sona_avatar_state` | An enum: `SONA_AVATAR_QUEUED`, `SONA_AVATAR_LOADING`, `SONA_AVATAR_READY`, `SONA_AVATAR_FAILED`, `SONA_AVATAR_REMOVED`; taken by `sona_avatar_state_of` | | `sona_placement` | A struct with `position`, `turn_deg`, `scale`; taken by `sona_avatar_move` | | `sona_add_options` | A struct with `place`, `clip`, `loop`, `speed`, `start_at`, `visible`, `priority`; taken by `sona_add_defaults`, `sona_avatar_add`, `sona_avatar_add_base64`, `sona_avatar_add_state` and more | | `sona_play_options` | A struct with `loop`, `speed`, `from`; taken by `sona_avatar_play`, `sona_avatar_crossfade`, `sona_avatar_queue`, `sona_avatar_play_stock` | | `sona_layer_options` | A struct with `mode`, `flags`, `loop`, `weight`, `fade_seconds`, `speed`, `from`, `additive_ref` and more; taken by `sona_layer_defaults`, `sona_avatar_layer_play`, `sona_avatar_layer_blend`, `sona_avatar_layer_machine` | | `sona_layer_info` | A struct with `kind`, `mode`, `state`, `clip`, `weight`, `time`, `normalized`, `ready` and more; taken by `sona_avatar_layer_info` | | `sona_blend_sample` | A struct with `clip`, `x`, `y`, `speed`; a field of `sona_blend_space_desc` | | `sona_blend_space_desc` | A struct with `dims`, `param_x`, `param_y`, `samples`, `sample_count`, `flags`, `smooth_seconds`; taken by `sona_blend_space_defaults`, `sona_blend_space_create` | | `sona_state_desc` | A struct with `name`, `clip`, `blend`, `loop`, `speed`; a field of `sona_state_machine_desc` | | `sona_transition_desc` | A struct with `from`, `to`, `fade_seconds`, `exit_time`, `condition_count`, `conditions`; a field of `sona_state_machine_desc` | | `sona_state_machine_desc` | A struct with `state_count`, `states`, `transitions`, `transition_count`, `initial`; taken by `sona_state_machine_defaults`, `sona_state_machine_create` | | `sona_clip_info` | A struct with `key`, `id`, `seconds`, `prop`, `caption`; taken by `sona_clip_get` | | `sona_view` | The camera, in doubles: the maths runs in double and stores float matrices only at the end, as the web SDK does. A struct with `eye`, `target`, `fov_deg`, `near_z`, `far_z`, `width`, `height`; taken by `sona_view_defaults`, `sona_update`, `sona_draw`, `sona_snapshot` and more | | `sona_frame_stats` | A struct with `ms`, `cpu_ms`, `drawn`, `culled`, `draw_calls`, `built`; taken by `sona_update` | | `sona_scene_stats` | A struct with `fps`, `ms_per_frame`, `p95_ms`, `cpu_ms_per_frame`, `avatars`, `ready`, `queued`, `drawn` and more; taken by `sona_stats` | | `sona_lod_options` | Each sona_update gives every avatar in view a step by its height on screen in pixels: FULL (posed every frame), SAMPLED (posed when the clip reaches a new frame), QUARTER (also at most every 4th frame) and SPRITE (a picture of the avatar baked once per look and turn, drawn as one textured quad; not posed). A struct with `full_px`, `quarter_px`, `sprite_px`, `fade_seconds`, `sprite_angles`, `sprite_height`, `max_looks`, `bake_ms`; taken by `sona_lod_defaults`, `sona_lod_set`, `sona_lod_get` | | `sona_lod_stats` | A struct with `full`, `sampled`, `quarter`, `sprite`, `fading`, `looks`, `bakes`, `bake_ms`; taken by `sona_lod_stats_get` | | `sona_texture` | A struct with `key`, `version`, `format`, `width`, `height`, `data`, `bytes`; a field of `sona_pose_data`, `sona_shading`, `sona_prop_data` | | `sona_material` | Address modes: bit 0 set = U wraps, bit 1 set = V wraps; clear = clamp. A struct with `shader_id`, `flags`, `params`, `transparency`, `color_tex`, `intensity_tex`, `decal_tex`, `color_addr` and more; a field of `sona_pose_data`, `sona_prop_data` | | `sona_mesh` | The runtime vertex, its size set to 76 bytes, in host byte order: +0 float3 position (bind pose, avatar space) +12 uint8 x4 joint index * 3 (the palette's float4 row) +16 uint8 x4 weight (sum 255) +20 uint8 x4 normal, (n * 0.5 + 0.5) * 255; byte 23 is 0 +24 uint8 x4 vertex colour (baked occlusion and alpha) +28 float4 uv0.xy, uv1.xy +44 float4 uv2.xy, uv3.xy (the HQ shaders read uv2 only) +60 float4 uv4.xy, uv5.xy. A struct with `item`, `mask`, `batch`, `material`, `pass`, `palette`, `vertex_count`, `index_count` and more; a field of `sona_pose_data`, `sona_prop_data` | | `sona_prop_palette` | A struct with `item`, `playing`, `palette`; a field of `sona_pose_data` | | `sona_pose_data` | A struct with `build_version`, `world`, `palette`, `view_joints`, `mesh_count`, `meshes`, `material_count`, `materials` and more; taken by `sona_pose` | | `sona_shading` | The fixed shading inputs, for hosts that rebuild our look in their own shaders. A struct with `irradiance`, `irradiance_gain`, `ao_gain`, `bloom_gain`, `shadow_rows`, `rim`; taken by `sona_shading_get` | | `sona_program` | An enum: `SONA_PROG_SHADOW`, `SONA_PROG_GBUFFER`, `SONA_PROG_SSAO`, `SONA_PROG_BRIGHT`, `SONA_PROG_BLUR`, `SONA_PROG_PRESENT` and more; taken by `sona_shader_source` | | `sona_device_desc` | The host owns the device. A struct with `backend`, `u`, `instance`, `physical_device`, `device`, `queue`, `queue_family`, `api_version` and more; taken by `sona_renderer_create`, `sona_renderer_reset` | | `sona_target` | Where one sona_draw lands. A struct with `width`, `height`, `u`, `image`, `view`, `format`, `layout_before`, `layout_after` and more; taken by `sona_draw`, `sona_item_preview_draw`, `sona_draw_lit`, `sona_screen_view_draw` and more | | `sona_draw_options` | A struct with `clear`, `flags`, `credit_corner`; taken by `sona_draw`, `sona_snapshot`, `sona_item_preview_draw`, `sona_item_preview_snapshot` and more | | `sona_preview_options` | A struct with `gender`, `slot`, `flags`, `skin`, `colours`, `priority`, `time`, `margin`; taken by `sona_preview_defaults`, `sona_item_preview_add` | | `sona_quality` | A struct with `msaa`, `flags`; taken by `sona_quality_defaults`, `sona_renderer_set_quality`, `sona_renderer_quality` | | `sona_tier_options` | A struct with `tier`, `target_fps`, `avatars`; taken by `sona_tier_defaults`, `sona_tier_apply` | | `sona_picture` | Pictures for 2D games and chat ([sprites2d guide](https://360sona.com/devs/docs/guides/sprites2d.md)). A struct with `rgba`, `width`, `height`; taken by `sona_pixel_art`, `sona_pixel_palette`, `sona_sticker`, `sona_sheet_page` | | `sona_pixel_options` | A struct with `height`, `colours`, `flags`, `outline`, `alpha_cut`, `palette`, `palette_count`; taken by `sona_pixel_defaults`, `sona_pixel_art` | | `sona_sticker_options` | A struct with `pixels`, `clip`, `time`, `turn_deg`, `framing`, `outline_px`, `outline`, `shadow_px` and more; taken by `sona_sticker_defaults`, `sona_sticker` | | `sona_sheet_options` | A struct with `frames`, `clip`, `name`, `from`, `to`, `directions`, `first_deg`, `pitch_deg` and more; taken by `sona_sheet_defaults`, `sona_sheet_render` | | `sona_sheet_frame` | One frame of a sheet. A struct with `page`, `x`, `y`, `w`, `h`, `trim_x`, `trim_y`, `cell_w` and more; taken by `sona_sheet_frame_get` | | `sona_asset_ref` | A struct with `id`, `mask`, `colours`; a field of `sona_manifest` | | `sona_manifest` | A struct with `version`, `weight`, `height`, `chin`, `nose`, `ears`, `face`, `colours` and more; taken by `sona_manifest_parse`, `sona_manifest_write`, `sona_manifest_wear`, `sona_manifest_unwear` and more | | `sona_credit` | A struct with `text`, `url`, `rgba`, `width`, `height`; taken by `sona_credit_get` | | `sona_section` | The editor's wardrobe and appearance sections. An enum: `SONA_SECTION_ANY`, `SONA_SECTION_COSTUME`, `SONA_SECTION_SHIRT`, `SONA_SECTION_TROUSERS`, `SONA_SECTION_SHOES`, `SONA_SECTION_HEADWEAR` and more; a field of `sona_item_info`, `sona_catalogue_query`, `sona_random_options` and more | | `sona_item_info` | One item. A struct with `guid`, `id`, `kind`, `gender`, `section`, `mask`, `flags`, `route` and more; taken by `sona_catalogue_get` | | `sona_catalogue_query` | A struct with `text`, `game`, `slots`, `section`, `gender`, `require`, `exclude`, `offset`; taken by `sona_catalogue_search`, `sona_filter_search` | | `sona_custom_item_info` | A struct with `id`, `mask`, `body`, `version`, `flags`, `template_id`, `sha256`, `template_sha256` and more; taken by `sona_custom_item_check`, `sona_custom_item_get`, `sona_custom_item_find` | | `sona_paint_spec` | A struct with `id`, `template_id`, `version`, `name`, `description`, `creator`, `created`, `licence` and more; taken by `sona_custom_item_pack` | | `sona_mesh_item_spec` | A struct with `flags`, `id`, `template_id`, `version`, `glb`, `glb_len`, `name`, `description` and more; taken by `sona_mesh_item_spec_defaults`, `sona_custom_item_pack_mesh` | | `sona_lipsync_options` | A struct with `sample_rate`, `channels`, `format`, `hold_seconds`, `attack_seconds`, `release_seconds`, `gate_db`, `lead_seconds` and more; taken by `sona_lipsync_defaults`, `sona_lipsync_create`, `sona_lipsync_phonemes`, `sona_lipsync_text` | | `sona_lipsync_frame` | A struct with `time`, `mouth`, `flags`, `open`, `level_db`, `weights`, `f1`, `f2`; taken by `sona_lipsync_read`, `sona_lipsync_current`, `sona_mouth_keys_sample` | | `sona_voice_mouth` | Voice chat: a mouth from an audio level alone (linear RMS, 0..1; scale does not matter), for every remote player. A struct with `seed`, `word`, `value`; taken by `sona_voice_mouth_init`, `sona_voice_mouth_step`, `sona_avatar_voice`, `sona_voice_mouths` | | `sona_headless_options` | A struct with `device`, `backend`, `adapter`, `flags`, `batch_in_flight`, `wait_seconds`; taken by `sona_headless_defaults`, `sona_headless_devices`, `sona_headless_open` | | `sona_headless_info` | A struct with `backend`, `software`, `type`, `vendor_id`, `device_id`, `name`, `driver`; taken by `sona_headless_devices`, `sona_headless_info_get` | | `sona_render_options` | A struct with `width`, `height`, `preset`, `yaw_deg`, `pitch_deg`, `zoom`, `turn_deg`, `time` and more; taken by `sona_render_defaults`, `sona_headless_render`, `sona_headless_render_manifest`, `sona_headless_batch` and more | | `sona_sequence_options` | A struct with `frames`, `fps`, `turn_deg`, `flags`; taken by `sona_sequence_defaults`, `sona_headless_sequence`, `sona_headless_record` | | `sona_video_options` | A struct with `format`, `width`, `height`, `fps`, `loops`, `quality`, `background`, `flags` and more; taken by `sona_video_defaults`, `sona_video_open` | | `sona_skeleton_kind` | The rig's joints under other skeletons' bone names, for retargeting ([skeleton maps guide](https://360sona.com/devs/docs/guides/skeleton-maps.md)). An enum: `SONA_SKELETON_UNITY`, `SONA_SKELETON_VRM`, `SONA_SKELETON_VRM0`, `SONA_SKELETON_UE4`, `SONA_SKELETON_UE5`, `SONA_SKELETON_COUNT`; a field of `sona_export_options` | | `sona_vrm_expression` | VRM expressions, the presets of VRM 1.0 (VRM 0.x: a i u e o, joy angry sorrow fun, surprised as a custom group, blink, blink_l, blink_r, lookup lookdown lookleft lookright). An enum: `SONA_VRM_AA`, `SONA_VRM_IH`, `SONA_VRM_OU`, `SONA_VRM_EE`, `SONA_VRM_OH`, `SONA_VRM_HAPPY` and more | | `sona_export_options` | A struct with `format`, `flags`, `bone_names`, `name`, `version`, `authors`, `copyright`, `contact` and more; taken by `sona_export_defaults`, `sona_export_avatar` | | `sona_export_report` | A struct with `meshes`, `primitives`, `vertices`, `triangles`, `degenerate`, `textures`, `expressions`, `atlas_cells` and more; taken by `sona_export_avatar` | | `sona_print_options` | A struct with `flags`, `height_mm`, `mm_per_metre`, `min_wall_mm`, `voxel_mm`, `close_mm`, `base_height_mm`, `base_margin_mm` and more; taken by `sona_print_defaults`, `sona_print_avatars`, `sona_print_triangles` | | `sona_print_mesh` | The solid. A struct with `vertex_count`, `triangle_count`, `shells`, `volume_mm3`, `area_mm2`, `positions`, `colours`, `indices` and more; taken by `sona_print_get` | | `sona_print_report` | What sona_print_check found. A struct with `vertices`, `triangles`, `edges`, `boundary_edges`, `nonmanifold_edges`, `flipped_edges`, `nonmanifold_vertices`, `degenerate` and more; taken by `sona_print_check` | | `sona_stock_clip` | A struct with `id`, `name`, `family`, `asset_id`, `caption`, `tags`, `body`, `frames` and more; taken by `sona_stock_clip_at`, `sona_stock_clip_get` | | `sona_idle_options` | A struct with `parts`, `seed`, `amount`, `face_px`; taken by `sona_idle_defaults`, `sona_avatar_idle`, `sona_avatar_idle_get`, `sona_idle_sample` | | `sona_idle_state` | A struct with `blink`, `gaze`, `shift`, `breath`; taken by `sona_avatar_idle_state`, `sona_idle_sample` | | `sona_ik_foot_lock` | Foot locking: a foot the clip plants (down, its ankle at the flat foot's height, and no longer swinging) stays where it landed until the clip lifts the heel, so walk and run clips do not slide while the host moves the avatar no faster than the clip's feet travel; faster, the held foot is dragged after the body just enough for the leg to reach it and slides less than without locking. A struct with `flags`, `weight`, `max_slide`, `release_seconds`; taken by `sona_ik_foot_lock_defaults`, `sona_avatar_ik_foot_lock` | | `sona_ik_spine` | Spine assist: a hand target past the arm's reach bends and turns the spine, and the hips a little, towards it. A struct with `flags`, `weight`, `max_bend_deg`, `max_twist_deg`, `hips_share`; taken by `sona_ik_spine_defaults`, `sona_avatar_ik_spine` | | `sona_ik_fingers` | Finger curl per hand, over the clip's: 0 open to 1 closed, per finger, and spread. A struct with `flags`, `curl`, `spread`, `weight`, `fade_seconds`; taken by `sona_ik_fingers_defaults`, `sona_avatar_ik_fingers` | | `sona_ik_eyes` | A struct with `flags`, `max_speed_deg`, `smoothing`, `lead_seconds`; taken by `sona_ik_eyes_defaults`, `sona_avatar_ik_eyes` | | `sona_import_options` | A struct with `format`, `key`, `take`, `take_index`, `flags`, `map`, `map_count`, `fps` and more; taken by `sona_import_defaults`, `sona_anim_file_load`, `sona_anim_file_open`, `sona_clip_import` | | `sona_import_info` | A struct with `format`, `naming`, `bones`, `takes`, `mapped`, `frames`, `fps`, `seconds` and more; taken by `sona_clip_import`, `sona_clip_imported_get`, `sona_clip_imported_find` | | `sona_players_config` | A struct with `max_players`, `refresh_s`, `per_hour`, `in_flight`, `timeout_ms`, `host`, `client`, `http` and more; taken by `sona_players_defaults`, `sona_players_open` | | `sona_player_look` | A struct with `state`, `error`, `placeholder`, `fetched_at`, `checked_at`, `next_check`, `manifest`, `version` and more; taken by `sona_players_look` | | `sona_player_event` | A struct with `type`, `code`, `id`; taken by `sona_players_poll` | | `sona_players_stats` | A struct with `players`, `watched`, `in_flight`, `due`, `requests`, `changed`, `same`, `not_modified` and more; taken by `sona_players_stats_get` | | `sona_random_options` | A struct with `body`, `style`, `palette`, `flags`, `require`, `exclude`, `skip_sections`, `skin_count` and more; taken by `sona_random_defaults`, `sona_make_random` | | `sona_random_report` | A struct with `body`, `seed`, `set`, `picked`, `candidates`; taken by `sona_make_random` | | `sona_like_options` | A struct with `parts`, `match`, `flags`, `available`, `available_user`; taken by `sona_like_defaults`, `sona_make_dress_like` | | `sona_like_report` | A struct with `count`, `kept`, `variants`, `similar`, `substitutes`, `dropped`, `covered`, `items`; taken by `sona_make_dress_like` | | `sona_outfit_set` | A struct with `title`, `game`, `name`, `count`, `bodies`, `sections`, `slots`; taken by `sona_outfit_set_get` | | `sona_outfit_issue` | A struct with `kind`, `severity`, `slots`, `field`, `item`, `other`; taken by `sona_outfit_check` | | `sona_outfit_report` | A struct with `issues`, `errors`, `warnings`, `body`, `slots`, `set`, `set_items`, `valid`; taken by `sona_outfit_check`, `sona_outfit_fix` | | `sona_filter_verdict` | A struct with `allowed`, `reason`, `tag`, `index`, `section`, `source`, `tags`; taken by `sona_filter_check` | | `sona_filter_report` | A struct with `count`, `replaced`, `hidden`, `cache`, `change`; taken by `sona_filter_manifest`, `sona_filter_manifest_bytes`, `sona_avatar_filter_report` | | `sona_state_info` | A struct with `version`, `has_look`, `parts`, `clock`; taken by `sona_state_info_get` | | `sona_state_status` | A struct with `mode`, `pending`, `missing`, `applied`; taken by `sona_avatar_state_status` | | `sona_net_options` | A struct with `tick_hz`, `history`, `full_after`; taken by `sona_net_defaults`, `sona_net_sender_create`, `sona_net_receiver_create` | | `sona_net_look` | A struct with `version`, `kind`, `manifest`, `id`; taken by `sona_net_receiver_look` | | `sona_net_stats` | A struct with `packets`, `bytes`, `full`, `newest`, `oldest`, `last_bytes`, `acked`; taken by `sona_net_sender_stats`, `sona_net_receiver_stats` | | `sona_record_options` | A struct with `tick_hz`, `keyframe_ticks`, `keep_seconds`; taken by `sona_record_defaults`, `sona_recorder_create` | | `sona_replay_info` | A struct with `tracks`, `tick_hz`, `first_tick`, `last_tick`, `frames`, `seconds`; taken by `sona_replay_info_get` | | `sona_lighting` | A struct with `flags`, `key`, `fill`, `ambient`, `environment`, `specular`, `rim`, `shadow` and more; taken by `sona_lighting_defaults`, `sona_renderer_set_lighting`, `sona_renderer_lighting`, `sona_draw_lit` and more | | `sona_environment` | A struct with `kind`, `sh`, `cube_size`, `cube`, `skin_red`; taken by `sona_environment_defaults`, `sona_renderer_set_environment`, `sona_environment_irradiance` | | `sona_host_shadow` | The host's shadow map, sampled by the lit avatars (they receive the host scene's shadows), together with their own map. A struct with `flags`, `matrix`, `bias`, `width`, `height`, `u`, `view`, `layout` and more; taken by `sona_renderer_set_host_shadow` | | `sona_shadow_map` | The renderer's own shadow map as its last lit frame with shadows drew it (the avatars only), for the host to shadow its scene with: sample it at the matrix's (u, v) and compare depth as above. A struct with `width`, `height`, `format`, `matrix`, `texel_metres`, `frame`, `u`, `image` and more; taken by `sona_renderer_shadow_map` | | `sona_style` | A struct with `kind`, `flags`, `bands`, `shade`, `highlight`, `outline_px`, `outline`, `colour`; taken by `sona_style_defaults`, `sona_avatar_set_style`, `sona_avatar_style`, `sona_renderer_set_style` and more | | `sona_placeholder_options` | A struct with `flags`, `delay_seconds`, `appear_seconds`, `reveal_seconds`, `failed_seconds`, `tint`, `failed_tint`, `glow`; taken by `sona_placeholder_defaults`, `sona_placeholder_set`, `sona_placeholder_get` | | `sona_placeholder_info` | A struct with `phase`, `opacity`, `height`, `gender`, `clip`, `seconds`, `sprite`; taken by `sona_avatar_placeholder_info` | | `sona_placeholder_stats` | A struct with `shown`, `waiting`, `loading`, `revealing`, `failed`, `sprites`, `posed`, `pose_ms` and more; taken by `sona_placeholder_stats_get` | | `sona_overlay` | A straight-alpha RGBA8 picture that every sona_draw on the renderer blends over its target after the credit, on every backend: SRC_ALPHA, ONE_MINUS_SRC_ALPHA (alpha ONE, ONE_MINUS_SRC_ALPHA), nearest sampling, no depth. A struct with `width`, `height`, `stride`, `rgba`, `revision`, `dirty`, `rect`; taken by `sona_renderer_overlay` | | `sona_screen_action` | An enum: `SONA_ACT_NONE`, `SONA_ACT_UP`, `SONA_ACT_DOWN`, `SONA_ACT_LEFT`, `SONA_ACT_RIGHT`, `SONA_ACT_ACCEPT` and more; a field of `sona_screen_event`, `sona_screen_node` | | `sona_screen_event` | One input event. A struct with `type`, `action`, `from`, `x`, `y`, `pointer`; taken by `sona_screen_input` | | `sona_screen_theme` | Colours are 0xAARRGGBB. A struct with `flags`, `background`, `panel`, `panel_raised`, `text`, `text_dim`, `accent`, `accent_text` and more; taken by `sona_screen_theme_defaults`, `sona_screen_set_theme` | | `sona_screen_node` | One thing to draw, in paint order. A struct with `id`, `parent`, `role`, `state`, `x`, `y`, `w`, `h` and more; taken by `sona_screen_nodes` | | `sona_screen_status` | An enum: `SONA_SCREEN_RUNNING`, `SONA_SCREEN_DONE`, `SONA_SCREEN_CANCELLED`, `SONA_SCREEN_FINE_TUNE`; taken by `sona_screen_update` | | `sona_quick_options` | A struct with `seed`, `looks`, `body`, `flags`, `catalogue`, `filter`, `filter_user`, `theme` and more; taken by `sona_quick_defaults`, `sona_quick_open`, `sona_quick_look` | | `sona_wardrobe_options` | A struct with `flags`, `manifest`, `catalogue`, `owned`, `owned_count`, `outfits`, `outfit_count`, `outfit_names` and more; taken by `sona_wardrobe_defaults`, `sona_wardrobe_open` | | `sona_screen_stats` | A struct with `presses`, `taps`, `changes`, `shuffles`, `focus_moves`, `seconds`, `action_presses`; taken by `sona_screen_stats_get` | | `sona_pick_options` | A struct with `flags`, `max_distance`, `ignore_count`, `ignore`; taken by `sona_pick_defaults`, `sona_pick_ray`, `sona_pick_screen`, `sona_pick_ray_all` and more | | `sona_body_region` | An enum: `SONA_REGION_NONE`, `SONA_REGION_HEAD`, `SONA_REGION_NECK`, `SONA_REGION_TORSO`, `SONA_REGION_HIPS`, `SONA_REGION_LEFT_ARM` and more; a field of `sona_pick_hit` | | `sona_pick_hit` | A struct with `source`, `flags`, `avatar_id`, `avatar`, `part`, `section`, `mask`, `item` and more; taken by `sona_pick_ray`, `sona_pick_screen`, `sona_pick_ray_all`, `sona_avatar_pick` and more | | `sona_prop_part` | A struct with `flags`, `vertex_count`, `index_count`, `positions`, `normals`, `uvs`, `colours`, `indices` and more; taken by `sona_prop_part_defaults`, `sona_prop_mesh_create` | | `sona_prop_load_options` | A struct with `flags`, `scale`, `scene`; taken by `sona_prop_load_defaults`, `sona_prop_mesh_load`, `sona_prop_mesh_open` | | `sona_prop_mesh_info` | A struct with `kind`, `flags`, `parts`, `vertices`, `triangles`, `textures`, `joints`, `hand` and more; taken by `sona_prop_mesh_info_get` | | `sona_prop_data` | The meshes in the data API's own form (3.11), for hosts that draw props themselves: 76-byte vertices whose joint bytes index sona_prop_frame.palette (a host mesh uses joint 0 only), materials and textures. A struct with `mesh_count`, `meshes`, `material_count`, `materials`, `texture_count`, `textures`, `joints`; taken by `sona_prop_mesh_data` | | `sona_prop_attach` | A struct with `flags`, `joint`, `position`, `rotation`, `scale`, `hand`, `hand_flags`, `hand_position` and more; taken by `sona_prop_attach_defaults`, `sona_avatar_prop_attach`, `sona_avatar_prop_set`, `sona_avatar_prop_get` | | `sona_prop_frame` | A struct with `flags`, `joint`, `time`, `world`, `avatar`, `hand_error`, `joints`, `palette`; taken by `sona_avatar_prop_frame` | | `sona_ragdoll_options` | A struct with `flags`, `total_mass`, `coverage`, `limits`; taken by `sona_ragdoll_defaults`, `sona_avatar_ragdoll` | | `sona_ragdoll_body` | One body. A struct with `joint`, `parent`, `shape`, `no_collide`, `position`, `rotation`, `shape_position`, `shape_rotation` and more; taken by `sona_avatar_ragdoll` | | `sona_ragdoll_state` | A body's world transform and velocities, in sona_avatar_ragdoll's order. A struct with `position`, `rotation`, `velocity`, `angular_velocity`; taken by `sona_avatar_ragdoll_state`, `sona_avatar_ragdoll_drive` | | `sona_ragdoll_info` | A struct with `mode`, `weight`, `blend_left`, `face_up`, `hips`, `lowest`, `getup_position`, `getup_turn_deg`; taken by `sona_avatar_ragdoll_info` | | `sona_ragdoll_motor` | Powered ragdolls. A struct with `rotation`, `joint_rotation`, `angular_velocity`, `world_position`, `world_rotation`, `velocity`, `world_angular_velocity`; taken by `sona_avatar_ragdoll_motors` | | `sona_seat` | A struct with `kind`, `position`, `turn_deg`, `height`, `depth`, `width`; taken by `sona_seat_defaults` | | `sona_interaction_desc` | A struct with `kind`, `a`, `b`, `position`, `turn_deg`, `flags`, `start_seconds`, `hold_seconds` and more; taken by `sona_interaction_defaults`, `sona_interaction_layout`, `sona_interaction_start` | | `sona_interaction_plan` | Where the interaction stands its avatars and where the contacts meet, before it starts (walk them there). A struct with `contacts`, `place`, `contact`, `spacing`, `clearance`; taken by `sona_interaction_layout` | | `sona_interaction_status` | A struct with `kind`, `phase`, `phase_seconds`, `progress`, `touching`, `contact_error`, `clearance`, `contact` and more; taken by `sona_interaction_status_get` | | `sona_emote` | A struct with `count`, `clips`, `weights`, `speed`, `confidence`, `expression`; taken by `sona_emote_from_text`, `sona_avatar_emote` | | `sona_award_def` | A developer defines award items for an app (on the devs site, or with sona_award_define and the app's developer key); the game unlocks one for a signed-in player and it joins their 360sona wardrobe. A struct with `flags`, `key`, `title`, `description`, `item`, `developer_key`; taken by `sona_award_def_defaults`, `sona_award_define` | | `sona_capsule` | A vertical capsule around the posed body, in world space, for collisions: the segment a..b and its radius. A struct with `a`, `b`, `radius`; taken by `sona_avatar_capsule` | | `sona_clip_event` | A struct with `kind`, `mark`, `clip`, `time`; taken by `sona_avatar_clip_events` | | `sona_layer_event` | A struct with `kind`, `layer`, `state`, `from_state`, `time`; taken by `sona_avatar_layer_events` | | `sona_condition` | A struct with `param`, `op`, `value`; a field of `sona_transition_desc` | | `sona_shader_lang` | An enum: `SONA_LANG_GLSL_ES300`, `SONA_LANG_GLSL_330`, `SONA_LANG_SPIRV`, `SONA_LANG_HLSL`, `SONA_LANG_MSL`; taken by `sona_shader_source` | | `sona_preset` | An enum: `SONA_PRESET_FULL`, `SONA_PRESET_UPPER`, `SONA_PRESET_BUST`, `SONA_PRESET_FACE`; taken by `sona_camera_preset` | | `sona_guid` | A struct with `b`; taken by `sona_slot_of`, `sona_guid_parse`, `sona_guid_format`, `sona_manifest_wear` and more | | `sona_route` | An enum: `SONA_ROUTE_REJECTED`, `SONA_ROUTE_WORN`, `SONA_ROUTE_BARE`, `SONA_ROUTE_FACE`; taken by `sona_slot_of` | | `sona_body` | An enum: `SONA_BODY_MAN`, `SONA_BODY_WOMAN`, `SONA_BODY_BOTH`; a field of `sona_custom_item_info` | | `sona_phoneme` | A phoneme with its time in seconds: ARPAbet ("AH0"), IPA ("ʃ"), the 15 viseme names ("PP", "aa"), the 22 viseme ids as digits ("21"), or a mouth name ("AI"). A struct with `symbol`, `start`, `end`; taken by `sona_lipsync_hint`, `sona_lipsync_phonemes` | | `sona_mouth_key` | A mouth from time on. A struct with `time`, `mouth`, `open`, `flags`; taken by `sona_lipsync_phonemes`, `sona_lipsync_text`, `sona_mouth_keys_sample` | | `sona_vrm_face` | The face an expression shows: a shape index per face part, in sona_avatar_expression's order (mouth, left eyebrow, right eyebrow, left eye, right eye; left is the avatar's own left), or 255 for a part it leaves to the others. A struct with `expression`, `parts`; taken by `sona_vrm_face_default` | | `sona_bone_map` | One override: the source bone (its full name, or as matched: lower case, no prefix) drives joint (a sona_joint_find name). A struct with `source`, `joint`; a field of `sona_import_options` | | `sona_interaction_event` | A struct with `kind`, `phase`, `time`, `value`; taken by `sona_interaction_events` | | `sona_ctx` | An opaque handle, made by `sona_open` and freed by `sona_close`, `sona_free`; taken by `sona_open`, `sona_close`, `sona_last_error`, `sona_app_id` and more | | `sona_avatar` | An opaque handle, made by `sona_avatar_add`, `sona_avatar_add_base64`, `sona_item_preview_add` and more; taken by `sona_avatar_add`, `sona_avatar_add_base64`, `sona_avatar_state_of`, `sona_avatar_id` and more | | `sona_renderer` | An opaque handle, made by `sona_renderer_create`, `sona_headless_renderer` and freed by `sona_renderer_destroy`; taken by `sona_renderer_create`, `sona_renderer_destroy`, `sona_draw`, `sona_renderer_frame_index` and more | | `sona_request` | one read in flight from a source. An opaque handle; taken by `sona_complete` | | `sona_http_reply` | An opaque handle; taken by `sona_http_done` | | `sona_blend_space` | An opaque handle, made by `sona_blend_space_create` and freed by `sona_blend_space_destroy`; taken by `sona_avatar_layer_blend`, `sona_blend_space_create`, `sona_blend_space_destroy`, `sona_blend_space_weights` | | `sona_state_machine` | An opaque handle, made by `sona_state_machine_create` and freed by `sona_state_machine_destroy`; taken by `sona_avatar_layer_machine`, `sona_state_machine_create`, `sona_state_machine_destroy`, `sona_state_machine_find` and more | | `sona_sheet` | An opaque handle, made by `sona_sheet_render` and freed by `sona_sheet_free`; taken by `sona_sheet_render`, `sona_sheet_free`, `sona_sheet_page_count`, `sona_sheet_page` and more | | `sona_catalogue` | Every item id with its name, slots, game and source, from sona-catalogue.bin, so pickers need no web call. An opaque handle, made by `sona_catalogue_load`, `sona_catalogue_load_memory` and freed by `sona_catalogue_free`; taken by `sona_catalogue_load`, `sona_catalogue_load_memory`, `sona_catalogue_free`, `sona_catalogue_count` and more | | `sona_lipsync` | An opaque handle, made by `sona_lipsync_create` and freed by `sona_lipsync_destroy`; taken by `sona_lipsync_create`, `sona_lipsync_destroy`, `sona_lipsync_reset`, `sona_lipsync_feed` and more | | `sona_headless` | A device of the library's own, with no window and no display, for servers, bots and tools: the best GPU, or a software device (lavapipe, llvmpipe) where there is none, so it runs in a container. An opaque handle, made by `sona_headless_open` and freed by `sona_headless_close`; taken by `sona_headless_open`, `sona_headless_close`, `sona_headless_info_get`, `sona_headless_renderer` and more | | `sona_video` | An opaque handle, made by `sona_video_open`; taken by `sona_headless_record`, `sona_video_open`, `sona_video_frame`, `sona_video_finish` | | `sona_print` | An opaque handle, made by `sona_print_avatars`, `sona_print_triangles` and freed by `sona_print_free`; taken by `sona_print_avatars`, `sona_print_triangles`, `sona_print_get`, `sona_print_encode` and more | | `sona_anim_file` | A parsed file: no ctx, nothing retargeted. An opaque handle, made by `sona_anim_file_load`, `sona_anim_file_open` and freed by `sona_anim_file_free`; taken by `sona_anim_file_load`, `sona_anim_file_open`, `sona_anim_file_free`, `sona_anim_file_takes` and more | | `sona_players` | An opaque handle, made by `sona_players_open` and freed by `sona_players_close`; taken by `sona_players_open`, `sona_players_close`, `sona_players_watch`, `sona_players_unwatch` and more | | `sona_maker` | A maker indexes a catalogue's outfit rules once: candidate items per body and section, gender variants and matched sets ([makers guide](https://360sona.com/devs/docs/guides/makers.md)). An opaque handle, made by `sona_maker_create` and freed by `sona_maker_free`; taken by `sona_maker_create`, `sona_maker_free`, `sona_make_random`, `sona_make_dress_like` and more | | `sona_filter` | Which items a game allows ([filters guide](https://360sona.com/devs/docs/guides/filters.md)): by section, slot, game (the franchise, brand or collection an item comes from), tag, source or id. An opaque handle, made by `sona_filter_create`, `sona_ctx_filter` and freed by `sona_filter_free`; taken by `sona_filter_create`, `sona_filter_free`, `sona_filter_reset`, `sona_filter_sections` and more | | `sona_net_sender` | Network sync: a stream carries one avatar from a sender to one receiver. An opaque handle, made by `sona_net_sender_create` and freed by `sona_net_sender_destroy`; taken by `sona_net_sender_create`, `sona_net_sender_destroy`, `sona_net_sender_look`, `sona_net_write` and more | | `sona_net_receiver` | An opaque handle, made by `sona_net_receiver_create` and freed by `sona_net_receiver_destroy`; taken by `sona_net_receiver_create`, `sona_net_receiver_destroy`, `sona_net_read`, `sona_net_receiver_look` and more | | `sona_recorder` | Replays (replays, kill-cams, bug reports): a recorder takes avatars' states at each tick into one compact file (the network coding, with a full state every keyframe_ticks so any moment is a short decode away); a replay shows any track at any time on a puppet, so seeking, slow motion, fast forward and reverse are where the host moves the time. An opaque handle, made by `sona_recorder_create` and freed by `sona_recorder_destroy`; taken by `sona_recorder_create`, `sona_recorder_destroy`, `sona_recorder_track`, `sona_recorder_capture` and more | | `sona_replay` | An opaque handle, made by `sona_replay_open` and freed by `sona_replay_close`; taken by `sona_replay_open`, `sona_replay_close`, `sona_replay_info_get`, `sona_replay_track` and more | | `sona_screen` | Two ready-made screens a game opens and gets an avatar back from ([quick creator guide](https://360sona.com/devs/docs/guides/quick-creator.md)). An opaque handle, made by `sona_quick_open`, `sona_wardrobe_open` and freed by `sona_screen_destroy`; taken by `sona_quick_open`, `sona_wardrobe_open`, `sona_screen_destroy`, `sona_screen_kind` and more | | `sona_prop_mesh` | An opaque handle, made by `sona_prop_mesh_create`, `sona_prop_mesh_load`, `sona_prop_mesh_open` and more; taken by `sona_prop_mesh_create`, `sona_prop_mesh_load`, `sona_prop_mesh_open`, `sona_prop_mesh_stock` and more | | `sona_interaction` | Two avatars of any heights and shapes doing one thing together, or one avatar on a seat. An opaque handle, made by `sona_interaction_start`; taken by `sona_interaction_start`, `sona_interaction_end`, `sona_interaction_move`, `sona_interaction_remove` and more | | `sona_picture_fn` | One picture of a batch or a sequence. A callback the host supplies: `void (*sona_picture_fn)(void *user, uint32_t index, sona_result result, const uint8_t *rgba, uint32_t width, uint32_t height)`; taken by `sona_headless_batch`, `sona_headless_sequence` | | `sona_body_options` | A struct with `flags`, `min_cutoff`, `beta`, `min_visibility`, `lost_seconds`, `return_seconds`; taken by `sona_body_defaults`, `sona_body_create` | | `sona_body_input` | One frame of a body tracker. A struct with `flags`, `time`, `layout`, `count`, `points`, `visibility`, `image`; taken by `sona_body_input_defaults`, `sona_body_feed` | | `sona_body_tracker` | An opaque handle, made by `sona_body_create` and freed by `sona_body_destroy`; taken by `sona_body_create`, `sona_body_destroy`, `sona_body_reset`, `sona_body_feed` and more | | `sona_editor_options` | A struct with `mode`, `width`, `height`, `flags`, `start`, `catalogue`, `seed`, `title` and more; taken by `sona_editor_defaults`, `sona_editor_open` | | `sona_editor_theme` | Colours are 0xAARRGGBB, straight alpha. A struct with `background`, `panel`, `raised`, `text`, `text_dim`, `accent`, `accent_text`, `focus` and more; taken by `sona_editor_theme_defaults`, `sona_editor_open`, `sona_editor_set_theme` | | `sona_editor_input` | A struct with `kind`, `code`, `down`, `mods`, `pointer`, `x`, `y`, `value`; taken by `sona_editor_feed` | | `sona_editor_control` | A struct with `id`, `role`, `flags`, `rect`, `value`, `min`, `max`, `index` and more; taken by `sona_editor_control_get`, `sona_editor_focus_get` | | `sona_editor_draw_data` | A struct with `width`, `height`, `revision`, `vertices`, `vertex_count`, `indices`, `index_count`, `commands` and more; taken by `sona_editor_draw_data_get` | | `sona_editor_texture` | A struct with `id`, `width`, `height`, `revision`, `dirty`, `dirty_since`, `rgba`; taken by `sona_editor_texture_get` | | `sona_editor` | An opaque handle, made by `sona_editor_open` and freed by `sona_editor_close`; taken by `sona_editor_open`, `sona_editor_close`, `sona_editor_set_theme`, `sona_editor_resize` and more | | `sona_npc_options` | A struct with `flags`, `speak`, `speak_user`, `line`, `line_user`, `look_seconds`, `idle_emote_seconds`; taken by `sona_npc_defaults`, `sona_npc_create` | | `sona_npc_state` | A struct with `state`, `line`, `queued`; taken by `sona_npc_state_get` | | `sona_npc` | An opaque handle, made by `sona_npc_create` and freed by `sona_npc_destroy`; taken by `sona_npc_create`, `sona_npc_destroy`, `sona_npc_say`, `sona_npc_emote` and more | | `sona_track_options` | A struct with `flags`, `face_min_cutoff`, `face_beta`, `head_min_cutoff`, `head_beta`, `head_gain`, `head_limit_deg`, `neck_share` and more; taken by `sona_track_defaults`, `sona_track_create`, `sona_track_set_options` | | `sona_track_face_input` | One frame of a face tracker. A struct with `flags`, `time`, `layout`, `count`, `weights`, `head_rotation`; taken by `sona_track_face_input_defaults`, `sona_track_face_feed` | | `sona_track_face_state` | What the tracker makes of the frames so far. A struct with `tracking`, `time`, `weight`, `expression`, `mood`, `head`, `weights`; taken by `sona_track_face_get` | | `sona_track_calibration` | Neutral face. A struct with `frames`, `neutral`, `head`; taken by `sona_track_calibrate_end`, `sona_track_calibration_set`, `sona_track_calibration_get` | | `sona_tracker` | An opaque handle, made by `sona_track_create` and freed by `sona_track_destroy`; taken by `sona_track_create`, `sona_track_destroy`, `sona_track_set_options`, `sona_track_reset` and more | | `sona_xr_options` | A struct with `flags`, `user_height`, `step_distance`; taken by `sona_xr_defaults`, `sona_xr_create` | | `sona_xr_input` | A struct with `flags`, `time`, `head`, `left_hand`, `right_hand`, `floor_y`; taken by `sona_xr_input_defaults`, `sona_xr_feed` | | `sona_xr_body` | An opaque handle, made by `sona_xr_create` and freed by `sona_xr_destroy`; taken by `sona_xr_create`, `sona_xr_destroy`, `sona_xr_feed`, `sona_xr_calibrate` and more | | `sona_source_kind` | The kind of a source in `sona_source_desc`: `SONA_SOURCE_CUSTOM`, `_GATE`, `_DIR`, `_CONSOLE` | | `sona_event_type` | The kind of a `sona_event`: `SONA_EVENT_READY`, `_FAILED`, `_ERROR` and the rest | | `sona_clip_event_kind` | The kind of a `sona_clip_event`: a clip starting, looping or ending, a footfall, a mark | | `sona_layer_event_kind` | The kind of a `sona_layer_event` on an animation layer | | `sona_tex_format` | The pixel format of a `sona_texture` in the data API | | `sona_pass` | Which pass a mesh draws in: `SONA_PASS_OPAQUE` or `SONA_PASS_TRANSPARENT` | | `sona_backend` | A graphics API: Vulkan, Direct3D 11, Direct3D 12, OpenGL, OpenGL ES, Metal or Xenos | | `sona_corner` | A corner of the target, for the credit badge: `SONA_CORNER_BOTTOM_RIGHT` (0), `_BOTTOM_LEFT`, `_TOP_RIGHT`, `_TOP_LEFT` | | `sona_face_record` | One face record of a manifest: an item id and four words | | `sona_paint_image` | An RGBA8 picture for `sona_paint_spec`: pixels, width and height | | `sona_paint_surface` | One surface of a painted item: its colour, regions and decal pictures (NULL `rgba`: none) | | `sona_device_kind` | What a headless renderer may open: `SONA_DEVICE_AUTO`, `_GPU` or `_SOFTWARE` | | `sona_video_format` | What a `sona_video` writes: a PNG sequence, GIF, MP4 or WebM | | `sona_anim_format` | The format of an animation file: `SONA_ANIM_AUTO`, `_GLTF`, `_FBX` or `_BVH` | | `sona_rig_naming` | How an imported file names its bones, for retargeting onto the avatar rig | | `sona_player_state` | What is known of another player's avatar: waiting, fresh, stale, private or none | | `sona_player_event_type` | The kind of a `sona_player_event` | | `sona_like_item` | One item `sona_make_dress_like` carried across: from, to, the outcome and the section | | `sona_filter_change` | One change a content filter made to a manifest: an item replaced (`SONA_CONTENT_REPLACED`) or hidden (`SONA_CONTENT_HIDDEN`) | | `sona_light` | One of the host's lights in `sona_lighting` | | `sona_style_kind` | An art style: `SONA_STYLE_ORIGINAL`, `_TOON`, `_FLAT`, `_SILHOUETTE` or `_PROMO` | | `sona_placeholder_phase` | Where a placeholder figure is: none, waiting, loading, revealing or failed | | `sona_screen_role` | The role of a `sona_screen_node`, for drawing it and for screen readers | | `sona_ik_ground_fn` | The host's ground query for foot planting: a ray straight down from a point, returning the first hit and its normal | | `sona_item_filter_fn` | A filter on catalogue items for the player screens: 1 to offer an item, 0 to leave it out | | `sona_editor_vertex` | One vertex of the player editor's UI layer, for a host that draws it itself | | `sona_editor_command` | One draw of the editor's UI layer: a texture, a range of indices and a scissor, blended with straight alpha | | `sona_editor_filter_fn` | The editor's content filter hook: 0 leaves an item out of every list and every generated look | | `sona_editor_look_fn` | The editor's seeded look hook: write look `index` of `seed` into the manifest and return 1, or 0 for the editor's own | | `sona_editor_sound_fn` | Told when the editor would play one of its sounds | | `sona_npc_speak_fn` | The host's text to speech for the NPC kit: mono 16-bit PCM for a line, or 0 to show it without a voice | | `sona_npc_line_fn` | Told when the NPC starts and stops saying a line | | `sona_blendshape` | The face blendshapes in ARKit's order (`SONA_TRACK_BLENDSHAPES` of them), the face tracker's input | | `sona_track_mood` | The face's moods, the first seven shapes of every part of the avatar's face | | `sona_xr_pose` | A pose in world metres, as OpenXR's `XrPosef`: a position, then a unit quaternion | | `sona_xr_status` | What the last `sona_xr_apply` did, from `sona_xr_status_get`: tracked poses, eye height, scale, turn, placement, crouch, steps, the eyes' position | ## Threading and memory - The owner thread calls everything. Inside `sona_update` the core drains completed reads, commits finished jobs, runs build steps inside `build_budget_ms`, advances clocks and poses due avatars. `sona_draw` and `sona_snapshot` fold the palettes with their own view. - The device's queue. On Vulkan, `sona_snapshot` and `sona_item_preview_snapshot` submit on the `VkQueue` the host passed and wait for it. Vulkan requires the host to keep every other thread off that queue during those calls. - A loaded catalogue never changes, so any thread may read it at once, with no ctx. - Jobs are: decode an asset, decode a clip, bake a face sheet, build an avatar, CPU-skin a mesh slice. With workers (the core's threads or the host's `sona_jobs`) they run there and are committed on the owner thread in the next `sona_update`. With `worker_threads = 0` (WASM, a single-threaded Xbox 360 host) they run inside the build budget. - Decoded shared data (assets, clips, textures) is immutable once committed and reference counted. Per-avatar data belongs to the avatar. - The idle chooser's randomness comes from `config.seed`. A fixed seed makes every run repeatable. - Every allocation goes through the config's allocator. `sona_stats` reports bytes in `cpu_mb` and `gpu_mb`. Eviction is idle first, oldest first. An Xbox 360 host sets `budget.total` (for example a budget of 96 MiB) and the caps; nothing in the core assumes a heap bigger than the budget. ## Left out on purpose - No glTF export, for size only. The data API hands out every mesh, material and texture. - No pointer controls, badge element, or resize and visibility observers: those are the web's DOM pieces. Wire input to `sona_camera_orbit`. - No origin check: native apps have no origin. The licence file and the native check replace it. The WASM build keeps the web's origin check through the bridge. - No offline gate use. Local sources are the offline path. - No "do not clear" draw flag. - The web's `samples()` and `benchmark()` live in sona-bench. ## Index of functions | Function | Section | |---|---| | `sona_result_name` | [Results and errors](https://360sona.com/devs/docs/reference.md#sona_result_name) | | `sona_last_error` | [Results and errors](https://360sona.com/devs/docs/reference.md#sona_last_error) | | `sona_http_done` | [HTTP](https://360sona.com/devs/docs/reference.md#sona_http_done) | | `sona_http_platform` | [HTTP](https://360sona.com/devs/docs/reference.md#sona_http_platform) | | `sona_complete` | [Asset sources](https://360sona.com/devs/docs/reference.md#sona_complete) | | `sona_config_defaults` | [The context](https://360sona.com/devs/docs/reference.md#sona_config_defaults) | | `sona_open` | [The context](https://360sona.com/devs/docs/reference.md#sona_open) | | `sona_close` | [The context](https://360sona.com/devs/docs/reference.md#sona_close) | | `sona_app_id` | [The context](https://360sona.com/devs/docs/reference.md#sona_app_id) | | `sona_version` | [The context](https://360sona.com/devs/docs/reference.md#sona_version) | | `sona_platform` | [The context](https://360sona.com/devs/docs/reference.md#sona_platform) | | `sona_struct_size` | [The context](https://360sona.com/devs/docs/reference.md#sona_struct_size) | | `sona_struct_offset` | [The context](https://360sona.com/devs/docs/reference.md#sona_struct_offset) | | `sona_abi_query` | [The context](https://360sona.com/devs/docs/reference.md#sona_abi_query) | | `sona_poll_event` | [Events](https://360sona.com/devs/docs/reference.md#sona_poll_event) | | `sona_add_defaults` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_add_defaults) | | `sona_avatar_add` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_add) | | `sona_avatar_add_base64` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_add_base64) | | `sona_avatar_state_of` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_state_of) | | `sona_avatar_id` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_id) | | `sona_avatar_play` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_play) | | `sona_avatar_stop` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_stop) | | `sona_avatar_move` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_move) | | `sona_avatar_set_visible` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_set_visible) | | `sona_avatar_bounds` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_bounds) | | `sona_avatar_remove` | [Avatars](https://360sona.com/devs/docs/reference.md#sona_avatar_remove) | | `sona_joint_find` | [Game features](https://360sona.com/devs/docs/reference.md#sona_joint_find) | | `sona_joint_name` | [Game features](https://360sona.com/devs/docs/reference.md#sona_joint_name) | | `sona_joint_world` | [Game features](https://360sona.com/devs/docs/reference.md#sona_joint_world) | | `sona_avatar_override` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_override) | | `sona_avatar_clear_overrides` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_clear_overrides) | | `sona_avatar_crossfade` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_crossfade) | | `sona_avatar_queue` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_queue) | | `sona_avatar_queued` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_queued) | | `sona_avatar_capsule` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_capsule) | | `sona_avatar_expression` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_expression) | | `sona_avatar_expression_counts` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_expression_counts) | | `sona_avatar_clip_events` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_clip_events) | | `sona_avatar_mark` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_mark) | | `sona_avatar_clear_marks` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_clear_marks) | | `sona_avatar_root_motion` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_root_motion) | | `sona_avatar_take_root_motion` | [Game features](https://360sona.com/devs/docs/reference.md#sona_avatar_take_root_motion) | | `sona_layer_defaults` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_layer_defaults) | | `sona_avatar_layer_play` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_play) | | `sona_avatar_layer_blend` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_blend) | | `sona_avatar_layer_machine` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_machine) | | `sona_avatar_layer_goto` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_goto) | | `sona_avatar_layer_weight` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_weight) | | `sona_avatar_layer_mask` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_mask) | | `sona_avatar_layer_stop` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_stop) | | `sona_avatar_layer_info` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_info) | | `sona_avatar_layer_events` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_layer_events) | | `sona_mask_preset` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_mask_preset) | | `sona_mask_branch` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_mask_branch) | | `sona_param_id` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_param_id) | | `sona_avatar_set_param` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_set_param) | | `sona_avatar_set_params` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_set_params) | | `sona_avatar_param` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_avatar_param) | | `sona_blend_space_defaults` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_blend_space_defaults) | | `sona_blend_space_create` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_blend_space_create) | | `sona_blend_space_destroy` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_blend_space_destroy) | | `sona_blend_space_weights` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_blend_space_weights) | | `sona_state_machine_defaults` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_state_machine_defaults) | | `sona_state_machine_create` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_state_machine_create) | | `sona_state_machine_destroy` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_state_machine_destroy) | | `sona_state_machine_find` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_state_machine_find) | | `sona_state_machine_state_name` | [Animation layers](https://360sona.com/devs/docs/reference.md#sona_state_machine_state_name) | | `sona_clip_count` | [Clips](https://360sona.com/devs/docs/reference.md#sona_clip_count) | | `sona_clip_get` | [Clips](https://360sona.com/devs/docs/reference.md#sona_clip_get) | | `sona_view_defaults` | [The frame](https://360sona.com/devs/docs/reference.md#sona_view_defaults) | | `sona_update` | [The frame](https://360sona.com/devs/docs/reference.md#sona_update) | | `sona_stats` | [The frame](https://360sona.com/devs/docs/reference.md#sona_stats) | | `sona_lod_defaults` | [Crowds: level of detail and sprites](https://360sona.com/devs/docs/reference.md#sona_lod_defaults) | | `sona_lod_set` | [Crowds: level of detail and sprites](https://360sona.com/devs/docs/reference.md#sona_lod_set) | | `sona_lod_get` | [Crowds: level of detail and sprites](https://360sona.com/devs/docs/reference.md#sona_lod_get) | | `sona_avatar_lod` | [Crowds: level of detail and sprites](https://360sona.com/devs/docs/reference.md#sona_avatar_lod) | | `sona_lod_stats_get` | [Crowds: level of detail and sprites](https://360sona.com/devs/docs/reference.md#sona_lod_stats_get) | | `sona_pose` | [The data API](https://360sona.com/devs/docs/reference.md#sona_pose) | | `sona_pose_vertices` | [The data API](https://360sona.com/devs/docs/reference.md#sona_pose_vertices) | | `sona_shading_get` | [The data API](https://360sona.com/devs/docs/reference.md#sona_shading_get) | | `sona_shader_source` | [The data API](https://360sona.com/devs/docs/reference.md#sona_shader_source) | | `sona_renderer_create` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_renderer_create) | | `sona_renderer_destroy` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_renderer_destroy) | | `sona_draw` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_draw) | | `sona_renderer_frame_index` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_renderer_frame_index) | | `sona_renderer_frame_done` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_renderer_frame_done) | | `sona_renderer_lost` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_renderer_lost) | | `sona_renderer_reset` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_renderer_reset) | | `sona_snapshot` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_snapshot) | | `sona_png_encode` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_png_encode) | | `sona_free` | [Drawing with the SDK's backends](https://360sona.com/devs/docs/reference.md#sona_free) | | `sona_preview_defaults` | [Item previews](https://360sona.com/devs/docs/reference.md#sona_preview_defaults) | | `sona_item_preview_add` | [Item previews](https://360sona.com/devs/docs/reference.md#sona_item_preview_add) | | `sona_item_preview_bounds` | [Item previews](https://360sona.com/devs/docs/reference.md#sona_item_preview_bounds) | | `sona_item_preview_view` | [Item previews](https://360sona.com/devs/docs/reference.md#sona_item_preview_view) | | `sona_item_preview_draw` | [Item previews](https://360sona.com/devs/docs/reference.md#sona_item_preview_draw) | | `sona_item_preview_snapshot` | [Item previews](https://360sona.com/devs/docs/reference.md#sona_item_preview_snapshot) | | `sona_quality_defaults` | [Rendering quality](https://360sona.com/devs/docs/reference.md#sona_quality_defaults) | | `sona_renderer_set_quality` | [Rendering quality](https://360sona.com/devs/docs/reference.md#sona_renderer_set_quality) | | `sona_renderer_quality` | [Rendering quality](https://360sona.com/devs/docs/reference.md#sona_renderer_quality) | | `sona_renderer_vk_features` | [Rendering quality](https://360sona.com/devs/docs/reference.md#sona_renderer_vk_features) | | `sona_tier_defaults` | [Rendering quality](https://360sona.com/devs/docs/reference.md#sona_tier_defaults) | | `sona_tier_apply` | [Rendering quality](https://360sona.com/devs/docs/reference.md#sona_tier_apply) | | `sona_tier_detect` | [Rendering quality](https://360sona.com/devs/docs/reference.md#sona_tier_detect) | | `sona_pixel_defaults` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_pixel_defaults) | | `sona_pixel_art` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_pixel_art) | | `sona_pixel_palette` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_pixel_palette) | | `sona_sticker_defaults` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sticker_defaults) | | `sona_sticker` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sticker) | | `sona_sheet_defaults` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_defaults) | | `sona_sheet_render` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_render) | | `sona_sheet_free` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_free) | | `sona_sheet_page_count` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_page_count) | | `sona_sheet_page` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_page) | | `sona_sheet_frame_count` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_frame_count) | | `sona_sheet_frame_get` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_frame_get) | | `sona_sheet_atlas` | [2D outputs](https://360sona.com/devs/docs/reference.md#sona_sheet_atlas) | | `sona_camera_preset` | [Camera helpers](https://360sona.com/devs/docs/reference.md#sona_camera_preset) | | `sona_camera_fit_crowd` | [Camera helpers](https://360sona.com/devs/docs/reference.md#sona_camera_fit_crowd) | | `sona_camera_orbit` | [Camera helpers](https://360sona.com/devs/docs/reference.md#sona_camera_orbit) | | `sona_view_matrices` | [Camera helpers](https://360sona.com/devs/docs/reference.md#sona_view_matrices) | | `sona_manifest_parse` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_parse) | | `sona_manifest_write` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_write) | | `sona_slot_of` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_slot_of) | | `sona_guid_parse` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_guid_parse) | | `sona_guid_format` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_guid_format) | | `sona_base64_decode` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_base64_decode) | | `sona_manifest_wear` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_wear) | | `sona_manifest_unwear` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_unwear) | | `sona_manifest_undress_all` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_undress_all) | | `sona_manifest_set_colour` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_set_colour) | | `sona_manifest_set_gender` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_set_gender) | | `sona_manifest_set_shape` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_set_shape) | | `sona_manifest_ready_for_xbox` | [Manifests](https://360sona.com/devs/docs/reference.md#sona_manifest_ready_for_xbox) | | `sona_credit_get` | [Credit](https://360sona.com/devs/docs/reference.md#sona_credit_get) | | `sona_catalogue_load` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_load) | | `sona_catalogue_load_memory` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_load_memory) | | `sona_catalogue_free` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_free) | | `sona_catalogue_count` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_count) | | `sona_catalogue_get` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_get) | | `sona_catalogue_find` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_find) | | `sona_catalogue_find_guid` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_find_guid) | | `sona_catalogue_search` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_search) | | `sona_catalogue_game_count` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_game_count) | | `sona_catalogue_game` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_game) | | `sona_catalogue_generated` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_generated) | | `sona_catalogue_section_name` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_section_name) | | `sona_catalogue_language_count` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_language_count) | | `sona_catalogue_language` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_language) | | `sona_catalogue_item_name` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_catalogue_item_name) | | `sona_item_colourways` | [The offline catalogue](https://360sona.com/devs/docs/reference.md#sona_item_colourways) | | `sona_stock_clip_count` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_stock_clip_count) | | `sona_stock_clip_at` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_stock_clip_at) | | `sona_stock_clip_get` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_stock_clip_get) | | `sona_stock_clip_find` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_stock_clip_find) | | `sona_stock_clip_for_body` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_stock_clip_for_body) | | `sona_stock_clips_tagged` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_stock_clips_tagged) | | `sona_clip_tag_name` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_clip_tag_name) | | `sona_clip_tag_find` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_clip_tag_find) | | `sona_avatar_play_stock` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_avatar_play_stock) | | `sona_idle_defaults` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_idle_defaults) | | `sona_avatar_idle` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_avatar_idle) | | `sona_avatar_idle_get` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_avatar_idle_get) | | `sona_avatar_idle_state` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_avatar_idle_state) | | `sona_idle_sample` | [The stock clip library and the procedural idle](https://360sona.com/devs/docs/reference.md#sona_idle_sample) | | `sona_ik_target_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_target_defaults) | | `sona_avatar_ik_target` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_target) | | `sona_ik_feet_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_feet_defaults) | | `sona_avatar_ik_feet` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_feet) | | `sona_avatar_ik_ground` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_ground) | | `sona_ik_look_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_look_defaults) | | `sona_avatar_ik_look` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_look) | | `sona_ik_limits_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_limits_defaults) | | `sona_avatar_ik_limits` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_limits) | | `sona_avatar_ik_clear` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_clear) | | `sona_avatar_ik_status` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_status) | | `sona_ik_foot_lock_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_foot_lock_defaults) | | `sona_avatar_ik_foot_lock` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_foot_lock) | | `sona_ik_spine_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_spine_defaults) | | `sona_avatar_ik_spine` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_spine) | | `sona_ik_fingers_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_fingers_defaults) | | `sona_avatar_ik_fingers` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_fingers) | | `sona_ik_eyes_defaults` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_ik_eyes_defaults) | | `sona_avatar_ik_eyes` | [Inverse kinematics](https://360sona.com/devs/docs/reference.md#sona_avatar_ik_eyes) | | `sona_import_defaults` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_import_defaults) | | `sona_import_formats` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_import_formats) | | `sona_anim_file_load` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_anim_file_load) | | `sona_anim_file_open` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_anim_file_open) | | `sona_anim_file_free` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_anim_file_free) | | `sona_anim_file_takes` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_anim_file_takes) | | `sona_anim_file_take` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_anim_file_take) | | `sona_anim_file_bones` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_anim_file_bones) | | `sona_anim_file_bone` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_anim_file_bone) | | `sona_clip_import` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_clip_import) | | `sona_clip_imported_count` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_clip_imported_count) | | `sona_clip_imported_get` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_clip_imported_get) | | `sona_clip_imported_find` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_clip_imported_find) | | `sona_clip_imported_remove` | [Imported clips](https://360sona.com/devs/docs/reference.md#sona_clip_imported_remove) | | `sona_headless_defaults` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_defaults) | | `sona_headless_devices` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_devices) | | `sona_headless_open` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_open) | | `sona_headless_close` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_close) | | `sona_headless_info_get` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_info_get) | | `sona_headless_renderer` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_renderer) | | `sona_render_defaults` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_render_defaults) | | `sona_headless_render` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_render) | | `sona_headless_render_manifest` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_render_manifest) | | `sona_headless_batch` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_batch) | | `sona_sequence_defaults` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_sequence_defaults) | | `sona_headless_sequence` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_sequence) | | `sona_headless_record` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_headless_record) | | `sona_video_defaults` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_video_defaults) | | `sona_video_open` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_video_open) | | `sona_video_frame` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_video_frame) | | `sona_video_finish` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_video_finish) | | `sona_video_formats` | [Headless rendering and video out](https://360sona.com/devs/docs/reference.md#sona_video_formats) | | `sona_skeleton_bone` | [Skeleton maps and VRM export](https://360sona.com/devs/docs/reference.md#sona_skeleton_bone) | | `sona_skeleton_joint` | [Skeleton maps and VRM export](https://360sona.com/devs/docs/reference.md#sona_skeleton_joint) | | `sona_vrm_expression_name` | [Skeleton maps and VRM export](https://360sona.com/devs/docs/reference.md#sona_vrm_expression_name) | | `sona_vrm_face_default` | [Skeleton maps and VRM export](https://360sona.com/devs/docs/reference.md#sona_vrm_face_default) | | `sona_export_defaults` | [Skeleton maps and VRM export](https://360sona.com/devs/docs/reference.md#sona_export_defaults) | | `sona_export_avatar` | [Skeleton maps and VRM export](https://360sona.com/devs/docs/reference.md#sona_export_avatar) | | `sona_print_defaults` | [3D print export](https://360sona.com/devs/docs/reference.md#sona_print_defaults) | | `sona_print_avatars` | [3D print export](https://360sona.com/devs/docs/reference.md#sona_print_avatars) | | `sona_print_triangles` | [3D print export](https://360sona.com/devs/docs/reference.md#sona_print_triangles) | | `sona_print_get` | [3D print export](https://360sona.com/devs/docs/reference.md#sona_print_get) | | `sona_print_encode` | [3D print export](https://360sona.com/devs/docs/reference.md#sona_print_encode) | | `sona_print_free` | [3D print export](https://360sona.com/devs/docs/reference.md#sona_print_free) | | `sona_print_check` | [3D print export](https://360sona.com/devs/docs/reference.md#sona_print_check) | | `sona_players_defaults` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_defaults) | | `sona_players_open` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_open) | | `sona_players_close` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_close) | | `sona_players_watch` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_watch) | | `sona_players_unwatch` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_unwatch) | | `sona_players_refresh` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_refresh) | | `sona_players_update` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_update) | | `sona_players_poll` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_poll) | | `sona_players_look` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_look) | | `sona_players_forget` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_forget) | | `sona_players_stats_get` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_stats_get) | | `sona_players_placeholder` | [Other players' avatars by id](https://360sona.com/devs/docs/reference.md#sona_players_placeholder) | | `sona_avatar_save_state` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_avatar_save_state) | | `sona_avatar_load_state` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_avatar_load_state) | | `sona_avatar_add_state` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_avatar_add_state) | | `sona_state_info_get` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_state_info_get) | | `sona_avatar_state_status` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_avatar_state_status) | | `sona_avatar_puppet` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_avatar_puppet) | | `sona_net_defaults` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_defaults) | | `sona_net_sender_create` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_sender_create) | | `sona_net_sender_destroy` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_sender_destroy) | | `sona_net_sender_look` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_sender_look) | | `sona_net_write` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_write) | | `sona_net_ack` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_ack) | | `sona_net_receiver_create` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_receiver_create) | | `sona_net_receiver_destroy` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_receiver_destroy) | | `sona_net_read` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_read) | | `sona_net_receiver_look` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_receiver_look) | | `sona_net_drive` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_drive) | | `sona_net_sender_stats` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_sender_stats) | | `sona_net_receiver_stats` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_net_receiver_stats) | | `sona_record_defaults` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_record_defaults) | | `sona_recorder_create` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_recorder_create) | | `sona_recorder_destroy` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_recorder_destroy) | | `sona_recorder_track` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_recorder_track) | | `sona_recorder_capture` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_recorder_capture) | | `sona_recorder_save` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_recorder_save) | | `sona_replay_open` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_replay_open) | | `sona_replay_close` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_replay_close) | | `sona_replay_info_get` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_replay_info_get) | | `sona_replay_track` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_replay_track) | | `sona_replay_drive` | [Avatar state, network sync and replays](https://360sona.com/devs/docs/reference.md#sona_replay_drive) | | `sona_style_defaults` | [Art styles](https://360sona.com/devs/docs/reference.md#sona_style_defaults) | | `sona_avatar_set_style` | [Art styles](https://360sona.com/devs/docs/reference.md#sona_avatar_set_style) | | `sona_avatar_style` | [Art styles](https://360sona.com/devs/docs/reference.md#sona_avatar_style) | | `sona_renderer_set_style` | [Art styles](https://360sona.com/devs/docs/reference.md#sona_renderer_set_style) | | `sona_renderer_style` | [Art styles](https://360sona.com/devs/docs/reference.md#sona_renderer_style) | | `sona_screen_theme_defaults` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_theme_defaults) | | `sona_quick_defaults` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_quick_defaults) | | `sona_quick_open` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_quick_open) | | `sona_quick_look` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_quick_look) | | `sona_wardrobe_defaults` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_wardrobe_defaults) | | `sona_wardrobe_open` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_wardrobe_open) | | `sona_screen_destroy` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_destroy) | | `sona_screen_kind` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_kind) | | `sona_screen_layout` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_layout) | | `sona_screen_set_theme` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_set_theme) | | `sona_screen_input` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_input) | | `sona_screen_update` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_update) | | `sona_screen_nodes` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_nodes) | | `sona_screen_announcement` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_announcement) | | `sona_screen_result` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_result) | | `sona_screen_stats_get` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_stats_get) | | `sona_screen_owns` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_owns) | | `sona_screen_view_avatar` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_view_avatar) | | `sona_screen_view_camera` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_view_camera) | | `sona_screen_view_draw` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_view_draw) | | `sona_screen_view_snapshot` | [Player screens: the quick creator and the wardrobe picker](https://360sona.com/devs/docs/reference.md#sona_screen_view_snapshot) | | `sona_pick_defaults` | [Picking](https://360sona.com/devs/docs/reference.md#sona_pick_defaults) | | `sona_view_ray` | [Picking](https://360sona.com/devs/docs/reference.md#sona_view_ray) | | `sona_pick_ray` | [Picking](https://360sona.com/devs/docs/reference.md#sona_pick_ray) | | `sona_pick_screen` | [Picking](https://360sona.com/devs/docs/reference.md#sona_pick_screen) | | `sona_pick_ray_all` | [Picking](https://360sona.com/devs/docs/reference.md#sona_pick_ray_all) | | `sona_avatar_pick` | [Picking](https://360sona.com/devs/docs/reference.md#sona_avatar_pick) | | `sona_region_name` | [Picking](https://360sona.com/devs/docs/reference.md#sona_region_name) | | `sona_pick_gpu` | [Picking](https://360sona.com/devs/docs/reference.md#sona_pick_gpu) | | `sona_pick_gpu_ids` | [Picking](https://360sona.com/devs/docs/reference.md#sona_pick_gpu_ids) | | `sona_sway_defaults` | [Hair and cloth sway](https://360sona.com/devs/docs/reference.md#sona_sway_defaults) | | `sona_avatar_sway` | [Hair and cloth sway](https://360sona.com/devs/docs/reference.md#sona_avatar_sway) | | `sona_avatar_sway_reset` | [Hair and cloth sway](https://360sona.com/devs/docs/reference.md#sona_avatar_sway_reset) | | `sona_sway_world_defaults` | [Hair and cloth sway](https://360sona.com/devs/docs/reference.md#sona_sway_world_defaults) | | `sona_sway_world_set` | [Hair and cloth sway](https://360sona.com/devs/docs/reference.md#sona_sway_world_set) | | `sona_avatar_sway_info` | [Hair and cloth sway](https://360sona.com/devs/docs/reference.md#sona_avatar_sway_info) | | `sona_avatar_sway_mesh_parts` | [Hair and cloth sway](https://360sona.com/devs/docs/reference.md#sona_avatar_sway_mesh_parts) | | `sona_custom_item_check` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_check) | | `sona_custom_item_add` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_add) | | `sona_custom_item_remove` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_remove) | | `sona_custom_item_count` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_count) | | `sona_custom_item_get` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_get) | | `sona_custom_item_find` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_find) | | `sona_guid_is_custom` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_guid_is_custom) | | `sona_guid_pair` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_guid_pair) | | `sona_custom_item_new_id` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_new_id) | | `sona_custom_item_pack` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_pack) | | `sona_avatar_missing_items` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_avatar_missing_items) | | `sona_mesh_item_spec_defaults` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_mesh_item_spec_defaults) | | `sona_custom_item_pack_mesh` | [Custom items](https://360sona.com/devs/docs/reference.md#sona_custom_item_pack_mesh) | | `sona_lipsync_defaults` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_defaults) | | `sona_lipsync_create` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_create) | | `sona_lipsync_destroy` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_destroy) | | `sona_lipsync_reset` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_reset) | | `sona_lipsync_feed` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_feed) | | `sona_lipsync_read` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_read) | | `sona_lipsync_current` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_current) | | `sona_lipsync_latency` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_latency) | | `sona_lipsync_hint` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_hint) | | `sona_phoneme_mouth` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_phoneme_mouth) | | `sona_lipsync_phonemes` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_phonemes) | | `sona_lipsync_text` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_lipsync_text) | | `sona_mouth_keys_sample` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_mouth_keys_sample) | | `sona_avatar_mouth` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_avatar_mouth) | | `sona_voice_mouth_init` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_voice_mouth_init) | | `sona_voice_mouth_step` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_voice_mouth_step) | | `sona_avatar_voice` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_avatar_voice) | | `sona_voice_mouths` | [Lip sync and voice mouths](https://360sona.com/devs/docs/reference.md#sona_voice_mouths) | | `sona_maker_create` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_maker_create) | | `sona_maker_free` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_maker_free) | | `sona_random_defaults` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_random_defaults) | | `sona_make_random` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_make_random) | | `sona_like_defaults` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_like_defaults) | | `sona_make_dress_like` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_make_dress_like) | | `sona_make_variant` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_make_variant) | | `sona_outfit_clash` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_clash) | | `sona_outfit_conflicts` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_conflicts) | | `sona_outfit_set_count` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_set_count) | | `sona_outfit_set_get` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_set_get) | | `sona_outfit_set_of` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_set_of) | | `sona_outfit_set_items` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_set_items) | | `sona_outfit_check` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_check) | | `sona_outfit_fix` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_fix) | | `sona_outfit_issue_name` | [Making avatars in code](https://360sona.com/devs/docs/reference.md#sona_outfit_issue_name) | | `sona_filter_create` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_create) | | `sona_filter_free` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_free) | | `sona_filter_reset` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_reset) | | `sona_filter_sections` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_sections) | | `sona_filter_slots` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_slots) | | `sona_filter_sources` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_sources) | | `sona_filter_game` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_game) | | `sona_filter_tag` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_tag) | | `sona_filter_item` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_item) | | `sona_filter_preset` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_preset) | | `sona_filter_load` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_load) | | `sona_filter_tag_count` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_tag_count) | | `sona_filter_tag_name` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_tag_name) | | `sona_filter_tag_find` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_tag_find) | | `sona_filter_tag_define` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_tag_define) | | `sona_filter_tag_set` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_tag_set) | | `sona_filter_item_tags` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_item_tags) | | `sona_filter_tag_items` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_tag_items) | | `sona_filter_allows` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_allows) | | `sona_filter_check` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_check) | | `sona_filter_search` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_search) | | `sona_filter_allowed_count` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_allowed_count) | | `sona_filter_manifest` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_manifest) | | `sona_filter_manifest_bytes` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_filter_manifest_bytes) | | `sona_ctx_set_filter` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_ctx_set_filter) | | `sona_ctx_filter` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_ctx_filter) | | `sona_avatar_filter_report` | [Content filters](https://360sona.com/devs/docs/reference.md#sona_avatar_filter_report) | | `sona_lighting_defaults` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_lighting_defaults) | | `sona_renderer_set_lighting` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_renderer_set_lighting) | | `sona_renderer_lighting` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_renderer_lighting) | | `sona_draw_lit` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_draw_lit) | | `sona_snapshot_lit` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_snapshot_lit) | | `sona_environment_defaults` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_environment_defaults) | | `sona_renderer_set_environment` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_renderer_set_environment) | | `sona_environment_irradiance` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_environment_irradiance) | | `sona_renderer_set_host_shadow` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_renderer_set_host_shadow) | | `sona_renderer_shadow_map` | [Lighting and shadows](https://360sona.com/devs/docs/reference.md#sona_renderer_shadow_map) | | `sona_placeholder_defaults` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_placeholder_defaults) | | `sona_placeholder_set` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_placeholder_set) | | `sona_placeholder_get` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_placeholder_get) | | `sona_placeholder_off` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_placeholder_off) | | `sona_avatar_placeholder` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_avatar_placeholder) | | `sona_avatar_placeholder_info` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_avatar_placeholder_info) | | `sona_placeholder_stats_get` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_placeholder_stats_get) | | `sona_avatar_add_waiting` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_avatar_add_waiting) | | `sona_avatar_set_manifest` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_avatar_set_manifest) | | `sona_avatar_set_manifest_base64` | [Loading placeholders](https://360sona.com/devs/docs/reference.md#sona_avatar_set_manifest_base64) | | `sona_renderer_overlay` | [Overlays](https://360sona.com/devs/docs/reference.md#sona_renderer_overlay) | | `sona_prop_part_defaults` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_part_defaults) | | `sona_prop_load_defaults` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_load_defaults) | | `sona_prop_mesh_create` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_create) | | `sona_prop_mesh_load` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_load) | | `sona_prop_mesh_open` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_open) | | `sona_prop_mesh_stock` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_stock) | | `sona_prop_mesh_state` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_state) | | `sona_prop_mesh_release` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_release) | | `sona_prop_mesh_info_get` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_info_get) | | `sona_prop_mesh_data` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_mesh_data) | | `sona_prop_attach_defaults` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_attach_defaults) | | `sona_avatar_prop_attach` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_attach) | | `sona_avatar_prop_set` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_set) | | `sona_avatar_prop_swap` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_swap) | | `sona_avatar_prop_get` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_get) | | `sona_avatar_prop_detach` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_detach) | | `sona_avatar_prop_detach_all` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_detach_all) | | `sona_avatar_prop_list` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_list) | | `sona_avatar_prop_frame` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_frame) | | `sona_avatar_prop_vertices` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_avatar_prop_vertices) | | `sona_prop_pet_count` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_pet_count) | | `sona_prop_pet` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_pet) | | `sona_prop_is_pet` | [Props: held and worn objects](https://360sona.com/devs/docs/reference.md#sona_prop_is_pet) | | `sona_ragdoll_defaults` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_ragdoll_defaults) | | `sona_avatar_ragdoll` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_avatar_ragdoll) | | `sona_avatar_ragdoll_state` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_avatar_ragdoll_state) | | `sona_avatar_ragdoll_drive` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_avatar_ragdoll_drive) | | `sona_avatar_ragdoll_release` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_avatar_ragdoll_release) | | `sona_avatar_ragdoll_info` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_avatar_ragdoll_info) | | `sona_avatar_ragdoll_clear` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_avatar_ragdoll_clear) | | `sona_avatar_ragdoll_motors` | [Ragdolls](https://360sona.com/devs/docs/reference.md#sona_avatar_ragdoll_motors) | | `sona_seat_defaults` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_seat_defaults) | | `sona_interaction_defaults` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_defaults) | | `sona_interaction_layout` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_layout) | | `sona_interaction_start` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_start) | | `sona_interaction_end` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_end) | | `sona_interaction_move` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_move) | | `sona_interaction_remove` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_remove) | | `sona_interaction_status_get` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_status_get) | | `sona_interaction_events` | [Two-avatar interactions and seats](https://360sona.com/devs/docs/reference.md#sona_interaction_events) | | `sona_emote_from_text` | [Text to emote](https://360sona.com/devs/docs/reference.md#sona_emote_from_text) | | `sona_avatar_emote` | [Text to emote](https://360sona.com/devs/docs/reference.md#sona_avatar_emote) | | `sona_award_def_defaults` | [Award items](https://360sona.com/devs/docs/reference.md#sona_award_def_defaults) | | `sona_award_define` | [Award items](https://360sona.com/devs/docs/reference.md#sona_award_define) | | `sona_award_unlock` | [Award items](https://360sona.com/devs/docs/reference.md#sona_award_unlock) | | `sona_award_poll` | [Award items](https://360sona.com/devs/docs/reference.md#sona_award_poll) | | `sona_body_defaults` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_defaults) | | `sona_body_create` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_create) | | `sona_body_destroy` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_destroy) | | `sona_body_reset` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_reset) | | `sona_body_input_defaults` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_input_defaults) | | `sona_body_feed` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_feed) | | `sona_body_apply` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_apply) | | `sona_body_release` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_release) | | `sona_body_struct_size` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_struct_size) | | `sona_body_struct_offset` | [Body tracking module (sona_body.h)](https://360sona.com/devs/docs/reference.md#sona_body_struct_offset) | | `sona_editor_defaults` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_defaults) | | `sona_editor_theme_defaults` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_theme_defaults) | | `sona_editor_open` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_open) | | `sona_editor_close` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_close) | | `sona_editor_set_theme` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_set_theme) | | `sona_editor_resize` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_resize) | | `sona_editor_feed` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_feed) | | `sona_editor_update` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_update) | | `sona_editor_status` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_status) | | `sona_editor_result` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_result) | | `sona_editor_set_search` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_set_search) | | `sona_editor_set_screen` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_set_screen) | | `sona_editor_screen_get` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_screen_get) | | `sona_editor_screens` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_screens) | | `sona_editor_busy` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_busy) | | `sona_editor_build_failures` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_build_failures) | | `sona_editor_view` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_view) | | `sona_editor_draw` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_draw) | | `sona_editor_draw_avatar` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_draw_avatar) | | `sona_editor_thumbnails` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_thumbnails) | | `sona_editor_draw_data_get` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_draw_data_get) | | `sona_editor_texture_get` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_texture_get) | | `sona_editor_render_ui` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_render_ui) | | `sona_editor_snapshot` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_snapshot) | | `sona_editor_control_count` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_control_count) | | `sona_editor_control_get` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_control_get) | | `sona_editor_focus_get` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_focus_get) | | `sona_editor_announcement` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_announcement) | | `sona_editor_struct_size` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_struct_size) | | `sona_editor_struct_offset` | [Player editor module (sona_editor.h)](https://360sona.com/devs/docs/reference.md#sona_editor_struct_offset) | | `sona_npc_defaults` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_defaults) | | `sona_npc_create` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_create) | | `sona_npc_destroy` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_destroy) | | `sona_npc_say` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_say) | | `sona_npc_emote` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_emote) | | `sona_npc_look_at` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_look_at) | | `sona_npc_update` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_update) | | `sona_npc_state_get` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_state_get) | | `sona_npc_struct_size` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_struct_size) | | `sona_npc_struct_offset` | [NPC kit module (sona_npc.h)](https://360sona.com/devs/docs/reference.md#sona_npc_struct_offset) | | `sona_track_blendshape_name` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_blendshape_name) | | `sona_track_blendshape_find` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_blendshape_find) | | `sona_track_defaults` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_defaults) | | `sona_track_create` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_create) | | `sona_track_destroy` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_destroy) | | `sona_track_set_options` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_set_options) | | `sona_track_reset` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_reset) | | `sona_track_face_input_defaults` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_face_input_defaults) | | `sona_track_face_feed` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_face_feed) | | `sona_track_face_get` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_face_get) | | `sona_track_calibrate_begin` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_calibrate_begin) | | `sona_track_calibrate_end` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_calibrate_end) | | `sona_track_calibration_set` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_calibration_set) | | `sona_track_calibration_get` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_calibration_get) | | `sona_track_apply` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_apply) | | `sona_track_release` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_release) | | `sona_track_quat_from_matrix` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_quat_from_matrix) | | `sona_track_quat_from_euler` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_quat_from_euler) | | `sona_track_struct_size` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_struct_size) | | `sona_track_struct_offset` | [Face tracking module (sona_track.h)](https://360sona.com/devs/docs/reference.md#sona_track_struct_offset) | | `sona_xr_defaults` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_defaults) | | `sona_xr_create` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_create) | | `sona_xr_destroy` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_destroy) | | `sona_xr_input_defaults` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_input_defaults) | | `sona_xr_feed` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_feed) | | `sona_xr_calibrate` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_calibrate) | | `sona_xr_apply` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_apply) | | `sona_xr_release` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_release) | | `sona_xr_status_get` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_status_get) | | `sona_xr_openxr_to_world` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_openxr_to_world) | | `sona_xr_struct_size` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_struct_size) | | `sona_xr_struct_offset` | [XR body module (sona_xr.h)](https://360sona.com/devs/docs/reference.md#sona_xr_struct_offset) | --- Source: https://360sona.com/devs/docs/reference/web.md # Web SDK reference The web SDK, `sona-renderer.js` 1.1.0, is one ES module: `SonaRenderer` draws live avatars in your own canvas with WebGPU, or WebGL2 where WebGPU is missing. This reference is generated from the declarations that ship with it, `sona-renderer.d.ts`, and the packages' `index.d.ts`. Where an example draws something, the web SDK draws it on the page beside the code, with the same values. | Part | What it covers | |---|---| | [SonaRenderer](https://360sona.com/devs/docs/reference/web.md#sonarenderer) | `SonaRenderer` is what the module exports: it makes scenes on your canvas, connections for engines that draw for themselves, and headless renderers, and holds the custom-item helpers. | | [SonaScene](https://360sona.com/devs/docs/reference/web.md#sonascene) | A scene is many avatars in one canvas and one WebGPU or WebGL2 context, from `SonaRenderer.create()`. | | [SonaAvatar](https://360sona.com/devs/docs/reference/web.md#sonaavatar) | One avatar in a scene, from `scene.add()`. | | [SonaCamera](https://360sona.com/devs/docs/reference/web.md#sonacamera) | The scene's camera, `scene.camera`: the console's framings, an orbit, a free camera, eased moves and pointer controls. | | [Options and results](https://360sona.com/devs/docs/reference/web.md#options-and-results) | The options `create()` and `add()` take, and what the scene reports. | | [Errors](https://360sona.com/devs/docs/reference/web.md#errors) | Every error the SDK raises is a `SonaError`: `code` says what went wrong, `fix` what to do. | | [Custom items](https://360sona.com/devs/docs/reference/web.md#custom-items) | Items of your own (`.sonaitem` files, [custom items](https://360sona.com/devs/docs/guides/custom-items.md)), per scene as `scene.items`, worn by id with `avatar.wear()`. | | [Connection and headless](https://360sona.com/devs/docs/reference/web.md#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. | | [The avatar editor element](https://360sona.com/devs/docs/reference/web.md#the-avatar-editor-element) | ``, the player-facing avatar creator as one element. | | [Face tracking](https://360sona.com/devs/docs/reference/web.md#face-tracking) | `SonaTrack`: webcam face tracking, MediaPipe's face landmarker in, an avatar's face and head out. | | [Packages](https://360sona.com/devs/docs/reference/web.md#packages) | `@360sona/three`, `@360sona/babylon` and `@360sona/react`, on the same connection and scenes. | ## SonaRenderer `SonaRenderer` is what the module exports: it makes scenes on your canvas, connections for engines that draw for themselves, and headless renderers, and holds the custom-item helpers. `defineAvatarEditor` and `SonaTrack` are exported beside it. ### SonaRendererStatic properties | Field | Type | Meaning | |---|---|---| | `VERSION` | `string` | The SDK's version. Read only. | ### SonaRenderer.create() ```ts interface SonaRendererStatic { create(opts: CreateOptions): Promise; } ``` Check the page's origin, open the asset bridge and start a scene on your canvas. | Parameter | Type | Meaning | |---|---|---| | `opts` | [`CreateOptions`](https://360sona.com/devs/docs/reference/web.md#createoptions) | Your canvas and the scene's settings. | Returns `Promise`. ```js import { SonaRenderer } from './sona-renderer.js'; const sona = await SonaRenderer.create({ canvas: document.querySelector('canvas'), credit: 'bottom-left', }); const avatar = sona.add(manifestBase64, { clip: 'GenericWave' }); await avatar.ready; ``` ### SonaRenderer.supported() ```ts interface SonaRendererStatic { supported(): boolean; } ``` True when this browser has WebGPU or WebGL2. Returns `boolean`. ```js import { SonaRenderer } from './sona-renderer.js'; if (!SonaRenderer.supported()) { document.body.append('This browser has neither WebGPU nor WebGL2.'); } ``` ### SonaRenderer.connect() ```ts interface SonaRendererStatic { connect( opts?: { appId?: string; host?: string }, ): Promise; } ``` A connection with no canvas, for engines that draw avatars themselves (the packages for three.js and Babylon.js). | Parameter | Type | Meaning | |---|---|---| | `opts.appId` (optional) | `string` | The app id. Default: the one this copy was built for. | | `opts.host` (optional) | `string` | Where assets come from. Default: the 360sona developer site. | Returns `Promise`. ```js import { SonaRenderer } from './sona-renderer.js'; const connection = await SonaRenderer.connect(); const glb = await connection.glb(manifestBase64, { clips: ['GenericWave'], }); ``` ### SonaRenderer.headless() ```ts interface SonaRendererStatic { headless( opts?: { appId?: string; host?: string; renderer?: 'auto' | 'webgpu' | 'webgl2'; antialias?: boolean | 'auto'; faceSize?: 128 | 256 | 512; }, ): Promise; } ``` Pictures with no canvas on the page: gamerpics, cards and frames at any size (the web half of sona_headless_*). | Parameter | Type | Meaning | |---|---|---| | `opts.appId` (optional) | `string` | The app id. Default: the one this copy was built for. | | `opts.host` (optional) | `string` | Where assets come from. Default: the 360sona developer site. | | `opts.renderer` (optional) | `'auto' \| 'webgpu' \| 'webgl2'` | As create(): "auto", "webgpu" or "webgl2". Default "auto". | | `opts.antialias` (optional) | `boolean \| 'auto'` | As create(). Default "auto". | | `opts.faceSize` (optional) | `128 \| 256 \| 512` | The face sheet of each picture's avatar, in pixels. Default 512. | Returns `Promise`. ```js import { SonaRenderer } from './sona-renderer.js'; const headless = await SonaRenderer.headless(); const png = await headless.picture(manifestBase64, { width: 256, height: 256, preset: 'face', }); headless.close(); save(png); // your own: a download, an upload, an ``` ### SonaRenderer.checkItem() ```ts interface SonaRendererStatic { checkItem( file: ArrayBuffer | Uint8Array, ): { ok: boolean; rule: number | null; why: string | null; info: CustomItemInfo | null; }; } ``` The shallow check of a .sonaitem (format rules 1 to 11), no network. | Parameter | Type | Meaning | |---|---|---| | `file` | `ArrayBuffer \| Uint8Array` | The .sonaitem file's bytes. | Returns `{ ok: boolean; rule: number | null; why: string | null; info: CustomItemInfo | null }`. ### SonaRenderer.newItemId() ```ts interface SonaRendererStatic { newItemId(templateId: string): string; } ``` A fresh custom id for a template: its slot and body, a custom marker, 90 random bits. | Parameter | Type | Meaning | |---|---|---| | `templateId` | `string` | The stock item id of the template the custom item is drawn on. | Returns `string`. ### SonaRenderer.isCustomId() ```ts interface SonaRendererStatic { isCustomId(id: string): boolean; } ``` True for a custom item id (the marker 8, 9, a or b at the start of the fourth group). | Parameter | Type | Meaning | |---|---|---| | `id` | `string` | An item id. | Returns `boolean`. ### SonaRenderer.pairOf() ```ts interface SonaRendererStatic { pairOf(id: string): string | null; } ``` The other body's id (man and woman swapped), or null for body 3 and for real ids. | Parameter | Type | Meaning | |---|---|---| | `id` | `string` | A custom item id. | Returns `string | null`. ### SonaRenderer.wear() ```ts interface SonaRendererStatic { wear( manifestBase64: string, itemId: string, opts?: { colourway?: number }, ): string; } ``` The manifest with an item worn, by the editor's rules (a long-sleeved top takes off the watch). colourway needs the item loaded in a scene on this page. Returns a new manifest (base64). | Parameter | Type | Meaning | |---|---|---| | `manifestBase64` | `string` | The avatar's 1,000-byte manifest, base64. | | `itemId` | `string` | A stock or custom item id. | | `opts.colourway` (optional) | `number` | An index into the item's colourways (scene.colourways()). Default: the item's own colours. | Returns `string`. ### SonaRenderer.unwear() ```ts interface SonaRendererStatic { unwear(manifestBase64: string, slot: string): string; } ``` The manifest with a slot ("shirt", "headwear", ...) emptied. Returns a new manifest (base64). | Parameter | Type | Meaning | |---|---|---| | `manifestBase64` | `string` | The avatar's 1,000-byte manifest, base64. | | `slot` | `string` | A wardrobe slot, as scene.wardrobe() names its sections: "shirt", "trousers", "shoes", "costume", "headwear", "glasses", "gloves", "wristwear", "ring", "earrings" or "carryable". | Returns `string`. ### SonaRenderer.defineAward() ```ts interface SonaRendererStatic { defineAward( opts: { app: string; key: string; title: string; description?: string; item: string; file?: ArrayBuffer | Uint8Array | Blob; developerKey: string; host?: string; }, ): Promise; } ``` Defines an award item for your app, or changes one, with the app's developer key: for your own tools, never a shipped game. Rejects with SonaError "item" (a refused field or file), "app" (a wrong key), "limit" or "gate". | Parameter | Type | Meaning | |---|---|---| | `opts.app` | `string` | Your app id. | | `opts.key` | `string` | The award's key, 1 to 64 of a-z, 0-9, _ and -. | | `opts.title` | `string` | The award's name, as players see it. | | `opts.description` (optional) | `string` | A line under the title. | | `opts.item` | `string` | A stock avatar award's item id, or your custom item's id. | | `opts.file` (optional) | `ArrayBuffer \| Uint8Array \| Blob` | The custom item's .sonaitem, when item is a custom id. | | `opts.developerKey` | `string` | Your app's developer key. | | `opts.host` (optional) | `string` | The accounts server. Default: the 360sona developer site. | Returns `Promise`. ### SonaRenderer.unlockAward() ```ts interface SonaRendererStatic { unlockAward( opts: { key: string; playerToken: string; host?: string }, ): Promise<{ unlocked: boolean; award: Award }>; } ``` Gives the signed-in player an award item, which joins their 360sona wardrobe. Unlocking it twice is fine. Rejects with SonaError "not_found" (no such award), "app" (the token lacks the awards scope), "limit" or "gate". | Parameter | Type | Meaning | |---|---|---| | `opts.key` | `string` | The award's key. | | `opts.playerToken` | `string` | The player's token, with the awards scope. | | `opts.host` (optional) | `string` | The accounts server. Default: the 360sona developer site. | Returns `Promise<{ unlocked: boolean; award: Award }>`. ### SonaRenderer.playerAwards() ```ts interface SonaRendererStatic { playerAwards( opts: { playerToken: string; host?: string }, ): Promise; } ``` The award items the signed-in player has earned in your app. | Parameter | Type | Meaning | |---|---|---| | `opts.playerToken` | `string` | The player's token, with the awards scope. | | `opts.host` (optional) | `string` | The accounts server. Default: the 360sona developer site. | Returns `Promise`. ### SonaRenderer.awardFile() ```ts interface SonaRendererStatic { awardFile( opts: { award: Award; playerToken: string; host?: string }, ): Promise; } ``` A custom award's .sonaitem, for the player who earned it; give it to scene.items.add() to wear it. Rejects with SonaError "not_found" when the player has not earned it. | Parameter | Type | Meaning | |---|---|---| | `opts.award` | [`Award`](https://360sona.com/devs/docs/reference/web.md#award) | An award from playerAwards() that has a file. | | `opts.playerToken` | `string` | The player's token, or your app's developer key. | | `opts.host` (optional) | `string` | The accounts server. Default: the 360sona developer site. | Returns `Promise`. ### SonaRenderer.defineAvatarEditor() ```ts interface SonaRendererStatic { defineAvatarEditor(name?: string): SonaAvatarEditorConstructor; } ``` Registers the avatar editor element, by default as ``. The same as the defineAvatarEditor export. | Parameter | Type | Meaning | |---|---|---| | `name` (optional) | `string` | The element's tag name. Default "sona-avatar-editor". | Returns `SonaAvatarEditorConstructor`. ### VERSION ```ts declare const VERSION: string; ``` The SDK's version, for example "1.1.0". ## SonaScene A scene is many avatars in one canvas and one WebGPU or WebGL2 context, from `SonaRenderer.create()`. The examples call it `sona`. ### SonaScene properties | Field | Type | Meaning | |---|---|---| | `canvas` | `HTMLCanvasElement` | The canvas the scene draws into. Read only. | | `appId` | `string` | The app id the scene runs under. Read only. | | `camera` | `SonaCamera` | The camera. Read only. | | `avatars` | `readonly SonaAvatar[]` | Every avatar in the scene, in the order they were added. Read only. | | `running` | `boolean` | True while the auto loop runs. Read only. | | `items` | `SonaItems` | Custom items loaded into this scene. Read only. | | `renderer` | `'webgpu' \| 'webgl2'` | "webgpu" or "webgl2": what this scene draws with. Read only. | | `background` | `[number, number, number, number]` | The clear colour, premultiplied RGBA 0 to 1. | ### scene.add() ```ts interface SonaScene { add(manifestBase64: string, opts?: AddOptions): SonaAvatar; } ``` Queue an avatar. Returns at once; it builds over the next frames and appears when ready. Throws SonaError("limit") past maxAvatars. | Parameter | Type | Meaning | |---|---|---| | `manifestBase64` | `string` | The avatar's 1,000-byte manifest, base64. | | `opts` (optional) | [`AddOptions`](https://360sona.com/devs/docs/reference/web.md#addoptions) | Where it stands and what it plays. | Returns `SonaAvatar`. ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const a = sona.add(manifestBase64, { position: [-0.5, 0, 0], turn: 15, clip: 'GenericClap', }); const b = sona.add(otherManifest, { position: [0.5, 0, 0], turn: -15, clip: 'GenericWave', }); sona.camera.preset('crowd'); ``` ### scene.remove() ```ts interface SonaScene { remove(avatar: SonaAvatar): void; } ``` Take an avatar out and free what only it used. | Parameter | Type | Meaning | |---|---|---| | `avatar` | [`SonaAvatar`](https://360sona.com/devs/docs/reference/web.md#sonaavatar) | An avatar of this scene. | ### scene.clear() ```ts interface SonaScene { clear(): void; } ``` Remove every avatar. ### scene.frame() ```ts interface SonaScene { frame(timeMs?: number): Promise; } ``` Draw one frame at timeMs (performance.now() if omitted). For loop: "manual". | Parameter | Type | Meaning | |---|---|---| | `timeMs` (optional) | `number` | The frame's time in milliseconds, which clips and eases follow. Default performance.now(). | Returns `Promise`. ### scene.settle() ```ts interface SonaScene { settle( avatars?: SonaAvatar | SonaAvatar[], opts?: { seconds?: number }, ): Promise; } ``` Resolves when the avatars (default all) are ready or failed. Avatars build only while frames are drawn: with loop "manual" this draws frames while it waits, where awaiting `avatar.ready` alone would wait for ever. Rejects with code "not_ready" after `seconds` (default 120). | Parameter | Type | Meaning | |---|---|---| | `avatars` (optional) | `SonaAvatar \| SonaAvatar[]` | The avatars to wait for. Default: every avatar in the scene. | | `opts.seconds` (optional) | `number` | How long to wait before rejecting. Default 120. | Returns `Promise`. ### scene.start() ```ts interface SonaScene { start(): void; } ``` Turn the auto loop on. ### scene.stop() ```ts interface SonaScene { stop(): void; } ``` Turn the auto loop off. ### scene.resize() ```ts interface SonaScene { resize(): void; } ``` Re-measure the canvas. Also automatic through a ResizeObserver. ### scene.snapshot() ```ts interface SonaScene { snapshot( opts?: { type?: 'image/png' | 'image/webp' | 'image/jpeg'; quality?: number; credit?: boolean; }, ): Promise; } ``` A picture of the next frame, drawn and read back in one task. The credit is written into the file's metadata; credit: true also draws it in the corner. | Parameter | Type | Meaning | |---|---|---| | `opts.type` (optional) | `'image/png' \| 'image/webp' \| 'image/jpeg'` | The picture's format. Default "image/png". | | `opts.quality` (optional) | `number` | 0 to 1, for WebP and JPEG. Default: the browser's own. | | `opts.credit` (optional) | `boolean` | Draw the badge in the picture's corner too. Default false. | Returns `Promise`. ```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; const png = await sona.snapshot({ credit: true }); const img = new Image(); img.src = URL.createObjectURL(png); ``` ### scene.glb() ```ts interface SonaScene { glb( manifestBase64: string, opts?: { clips?: ClipKey[]; textures?: boolean }, ): Promise; } ``` The avatar as a .glb, the same file the 360sona runtime exports, with the same credit inside. Runs a full build at face size 512 on the calling thread. Custom items it draws are named, with their creators, in the file's copyright. The SDK Licence (S5) allows this file only for the person whose avatar it is, with the credit left in; it is not a way to collect items or animations. | Parameter | Type | Meaning | |---|---|---| | `manifestBase64` | `string` | The avatar's 1,000-byte manifest, base64. | | `opts.clips` (optional) | `ClipKey[]` | The clips to put in the file. Default: every clip but "prop". | | `opts.textures` (optional) | `boolean` | Embed the textures. Default true. | Returns `Promise`. ### scene.clips() ```ts interface SonaScene { clips(): ClipInfo[]; } ``` Every clip this SDK can play. Returns `ClipInfo[]`. ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); for (const c of sona.clips()) console.log(c.key, c.caption); ``` ### scene.samples() ```ts interface SonaScene { samples(): Promise<{ title: string; manifest: string }[]>; } ``` Sample avatars from 360sona, for demos and benchmarks. Returns `Promise<{ title: string; manifest: string }[]>`. ### scene.wardrobe() ```ts interface SonaScene { wardrobe(): Promise; } ``` The wardrobe for pickers: every item that may be offered, named, with its editor section. Loaded once per scene, through the bridge. Returns `Promise`. ### scene.colours() ```ts interface SonaScene { colours(): Record; } ``` The swatches of each palette slot (skin, hair, mouth, eyes, eyebrows, eyeShadow, facialHair, facialFeature), as #rrggbb. Returns `Record`. ### scene.colourways() ```ts interface SonaScene { colourways(itemId: string): string[][] | null; } ``` An item's own colourways, each three #rrggbb, once the item is loaded (worn by an avatar here, or added with items); null before, or when it has none. Pass the index to avatar.wear(id, { colourway }). | Parameter | Type | Meaning | |---|---|---| | `itemId` | `string` | A stock or custom item id. | Returns `string[][] | null`. ### scene.thumbnails() ```ts interface SonaScene { thumbnails(ids: string[]): Promise<(Uint8Array | null)[]>; } ``` Item pictures: PNG, JPEG or WebP bytes in the order asked, null where an item has none. At most 6000 different ids per page. | Parameter | Type | Meaning | |---|---|---| | `ids` | `string[]` | Item ids, at most 6000 different ones a page. | Returns `Promise<(Uint8Array | null)[]>`. ### scene.benchmark() ```ts interface SonaScene { benchmark( opts?: { counts?: number[]; seconds?: number; distinct?: number; onStep?: (r: BenchStep) => void; }, ): Promise; } ``` Run the benchmark: adds sample avatars at each count (replicating `distinct` samples, default 12), waits until they are ready, measures, removes them. | Parameter | Type | Meaning | |---|---|---| | `opts.counts` (optional) | `number[]` | The avatar counts to measure, in order; a count over maxAvatars is skipped. Default [10, 25, 50, 100, 200]. | | `opts.seconds` (optional) | `number` | Seconds measured at each count. Default 4. | | `opts.distinct` (optional) | `number` | Different sample avatars, repeated to make up each count. Default 12. | | `opts.onStep` (optional) | `(r: BenchStep) => void` | Called with each row as it is measured. | Returns `Promise`. ### scene.stats() ```ts interface SonaScene { stats(): SceneStats; } ``` Rolling numbers over the last two seconds. Returns `SceneStats`. ### scene.on() ```ts interface SonaScene { on(event: 'ready', fn: (a: SonaAvatar) => void): () => void; on( event: 'error', fn: (e: SonaError, a?: SonaAvatar) => void, ): () => void; on(event: 'frame', fn: (s: FrameStats) => void): () => void; } ``` - `'ready'`: An avatar appeared. Returns a function that removes the listener. - `'error'`: Something failed. Returns a function that removes the listener. - `'frame'`: A frame was drawn. Returns a function that removes the listener. ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); sona.on('ready', (a) => console.log('drawn', a.id)); sona.on('error', (e) => console.log(e.code, e.fix)); sona.add(manifestBase64); ``` ### scene.destroy() ```ts interface SonaScene { destroy(): void; } ``` Free everything: GPU objects, the bridge frame, the badge, listeners. ## SonaAvatar One avatar in a scene, from `scene.add()`. It is built over the next frames and shows when `ready` resolves. ### SonaAvatar properties | Field | Type | Meaning | |---|---|---| | `id` | `number` | A number unique on this page. Read only. | | `manifest` | `string` | The manifest it wears (base64): the one it was added with, as changed by wear and unwear. Read only. | | `state` | `'queued' \| 'loading' \| 'ready' \| 'failed' \| 'removed'` | Where it is in its life. Read only. | | `ready` | `Promise` | Resolves when it is on screen; rejects with a SonaError if it cannot be built. Read only. | | `position` | `Vec3` | Its position. Read only. | | `turn` | `number` | Its turn in degrees. Read only. | | `scale` | `number` | Its scale. Read only. | | `clip` | `ClipKey \| null` | What it was last asked to play. Read only. | | `missingItems` | `readonly string[]` | Custom ids this avatar wears that are not loaded (or cannot be built), as last built. Required slots show the body's default garment meanwhile. Read only. | ### avatar.play() ```ts interface SonaAvatar { play( clip: ClipKey, opts?: { loop?: boolean; speed?: number; from?: number }, ): Promise; } ``` Play a clip. Called before ready, it is remembered and applied when the avatar appears. | Parameter | Type | Meaning | |---|---|---| | `clip` | `ClipKey` | A key from scene.clips(), a raw clip id, "prop", "idle" or "still". | | `opts.loop` (optional) | `boolean` | Loop the clip. Default true ("idle" always loops). | | `opts.speed` (optional) | `number` | Playback speed, 0 or more; 1 is the clip's own. Default 1. | | `opts.from` (optional) | `number` | Seconds into the clip to start from, up to its length. Default 0. | Returns `Promise`. ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const avatar = sona.add(manifestBase64, { clip: 'GenericStand5' }); await avatar.ready; await avatar.play('GenericCelebration', { loop: false }); ``` ### avatar.stop() ```ts interface SonaAvatar { stop(): void; } ``` Hold the current pose. ### avatar.move() ```ts interface SonaAvatar { move(to: Placement, opts?: { over?: number }): void; } ``` Move, turn or scale. | Parameter | Type | Meaning | |---|---|---| | `to` | [`Placement`](https://360sona.com/devs/docs/reference/web.md#placement) | Where to go: position (metres), turn (degrees about Y) and scale. What it leaves out stays as it is. | | `opts.over` (optional) | `number` | Seconds to ease there. Default 0 (at once). | ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const avatar = sona.add(manifestBase64); await avatar.ready; avatar.move({ turn: 60 }, { over: 1 }); ``` ### avatar.setVisible() ```ts interface SonaAvatar { setVisible(visible: boolean): void; } ``` Show or hide it. | Parameter | Type | Meaning | |---|---|---| | `visible` | `boolean` | false hides it; it keeps its place and its clip. | ### avatar.bounds() ```ts interface SonaAvatar { bounds(): { center: Vec3; radius: number }; } ``` Its bounding sphere in world space. Returns `{ center: Vec3; radius: number }`. ### avatar.remove() ```ts interface SonaAvatar { remove(): void; } ``` Take it out of its scene. ### avatar.wear() ```ts interface SonaAvatar { wear(itemId: string, opts?: { colourway?: number }): Promise; } ``` Wears an item (stock or custom) and rebuilds. The old look stays on screen until the new one is ready. colourway: an index into the item's colourways. | Parameter | Type | Meaning | |---|---|---| | `itemId` | `string` | A stock or custom item id; a custom one is loaded first with scene.items.add(). | | `opts.colourway` (optional) | `number` | An index into the item's colourways (scene.colourways()). Default: the item's own colours. | Returns `Promise`. ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const avatar = sona.add(manifestBase64); await avatar.ready; await avatar.wear('00001000-c6f4-2253-caa5-9f694d5309cf'); avatar.play('prop'); // room for the prop: its clip swings it above the head sona.camera.orbit({ yaw: 0, pitch: 5, distance: 4.5, target: [0, 0.95, 0], }); ``` ### avatar.unwear() ```ts interface SonaAvatar { unwear(slot: string): Promise; } ``` Empties a slot ("shirt", "headwear", ...) and rebuilds. | Parameter | Type | Meaning | |---|---|---| | `slot` | `string` | A wardrobe slot, as scene.wardrobe() names its sections: "shirt", "trousers", "shoes", "costume", "headwear", "glasses", "gloves", "wristwear", "ring", "earrings" or "carryable". | Returns `Promise`. ### avatar.update() ```ts interface SonaAvatar { update(manifestBase64: string): Promise; } ``` Changes to another manifest and rebuilds. The old look stays on screen until the new one is ready. | Parameter | Type | Meaning | |---|---|---| | `manifestBase64` | `string` | The new manifest, base64. | Returns `Promise`. ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const avatar = sona.add(manifestBase64, { clip: 'GenericStand5' }); await avatar.ready; await avatar.update(otherManifest); ``` ## SonaCamera The scene's camera, `scene.camera`: the console's framings, an orbit, a free camera, eased moves and pointer controls. ### SonaCamera properties | Field | Type | Meaning | |---|---|---| | `fov` | `number` | Vertical field of view in degrees. Default 28.65 (0.5 rad, the console's). | | `near` | `number` | Near plane in metres. Default 0.05. | | `far` | `number` | Far plane in metres. Default 200. | | `eye` | `Vec3` | Where the camera is. Read only. | | `target` | `Vec3` | What it looks at. Read only. | ### camera.preset() ```ts interface SonaCamera { preset(name: PresetName, on?: SonaAvatar, opts?: { over?: number }): void; } ``` One of the console's framings on one avatar, or "crowd" to fit every avatar. | Parameter | Type | Meaning | |---|---|---| | `name` | `PresetName` | A framing: "full", "upper", "bust" or "face", or "crowd" to fit every avatar. | | `on` (optional) | [`SonaAvatar`](https://360sona.com/devs/docs/reference/web.md#sonaavatar) | The avatar to frame. Default: the first ready one. "crowd" frames them all. | | `opts.over` (optional) | `number` | Seconds to ease there. Default 0 (at once). | ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const avatar = sona.add(manifestBase64, { clip: 'GenericStand5' }); await avatar.ready; // 'full', 'upper', 'bust' or 'face' sona.camera.preset('bust', avatar, { over: 0.5 }); ``` ### camera.orbit() ```ts interface SonaCamera { orbit( o: { yaw?: number; pitch?: number; distance?: number; target?: Vec3 }, opts?: { over?: number }, ): void; } ``` Orbit around a target. yaw and pitch in degrees, distance in metres. | Parameter | Type | Meaning | |---|---|---| | `o.yaw` (optional) | `number` | Degrees round the target. Default: as now. | | `o.pitch` (optional) | `number` | Degrees up, -89 to 89. Default: as now. | | `o.distance` (optional) | `number` | Metres from the target. Default: as now. | | `o.target` (optional) | `Vec3` | The point to orbit, in metres. Default: as now. | | `opts.over` (optional) | `number` | Seconds to ease there. Default 0 (at once). | ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); const avatar = sona.add(manifestBase64, { clip: 'GenericStand5' }); await avatar.ready; sona.camera.orbit({ yaw: 35, pitch: 10, distance: 4.4, target: [0, 0.9, 0], }); ``` ### camera.lookAt() ```ts interface SonaCamera { lookAt(eye: Vec3, target: Vec3, opts?: { over?: number }): void; } ``` A free camera. | Parameter | Type | Meaning | |---|---|---| | `eye` | `Vec3` | Where the camera goes, in metres. | | `target` | `Vec3` | The point it looks at, in metres. | | `opts.over` (optional) | `number` | Seconds to ease there. Default 0 (at once). | ### camera.controls() ```ts interface SonaCamera { controls( on: boolean | { drag?: boolean; zoom?: boolean; pitch?: boolean }, ): void; } ``` Pointer controls on the canvas. | Parameter | Type | Meaning | |---|---|---| | `on` | `boolean \| { drag?: boolean; zoom?: boolean; pitch?: boolean }` | true: drag turns and the wheel zooms. false: none. Or each one: drag turns, zoom scrolls, pitch tilts with an up and down drag. | ```js import { SonaRenderer } from './sona-renderer.js'; const canvas = document.querySelector('canvas'); const sona = await SonaRenderer.create({ canvas }); sona.add(manifestBase64); sona.camera.controls({ drag: true, zoom: true }); ``` ### PresetName ```ts type PresetName = 'full' | 'upper' | 'bust' | 'face' | 'crowd'; ``` The console's framings, and "crowd" to fit every avatar. ## Options and results The options `create()` and `add()` take, and what the scene reports. ### CreateOptions Options for SonaRenderer.create(). | Field | Type | Meaning | |---|---|---| | `canvas` | `HTMLCanvasElement` | Your canvas. The SDK owns its WebGPU or WebGL2 context. | | `renderer` (optional) | `'auto' \| 'webgpu' \| 'webgl2'` | "auto": WebGPU on a hardware adapter, else WebGL2. "webgpu" or "webgl2" asks for one (SonaError "unsupported" when WebGPU is missing). The two draw the same pixels. Default "auto". | | `appId` (optional) | `string` | Defaults to the app id this copy was built for. | | `host` (optional) | `string` | Where assets come from. Default: the 360sona developer site (https://360sona.com). | | `loop` (optional) | `'auto' \| 'manual'` | "auto": the SDK runs requestAnimationFrame. "manual": you call frame() from your loop; avatars build only inside frame(), so await scene.settle() (it draws frames) rather than avatar.ready alone. Default "auto". | | `pixelRatio` (optional) | `number` | Device pixels per CSS pixel. Default min(2, devicePixelRatio). | | `supersample` (optional) | `number` | Supersampling, 1 to 2. Default 1. Capped at 5.2 million pixels. | | `antialias` (optional) | `boolean \| 'auto'` | 4x multisampled edges. "auto" turns it off on software rasterisers (SwiftShader, llvmpipe), where each sample costs a full shade. Default "auto". | | `faceSize` (optional) | `128 \| 256 \| 512 \| 'auto'` | Face sheet size per avatar. "auto": 512 for 1 to 4 avatars, 256 up to 32, 128 beyond. Default "auto". | | `faces` (optional) | `'animated' \| 'still'` | "animated": faces follow each clip's expression track. "still": one face per avatar. Default "animated". | | `shadow` (optional) | `boolean` | The key light shadow. Tuned for one figure near the origin. Default false. | | `background` (optional) | `[number, number, number, number]` | Clear colour, premultiplied RGBA 0 to 1. Default [0, 0, 0, 0] (transparent). | | `credit` (optional) | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left' \| false` | Where the credit badge sits. A small "Powered by 360sona" link, shown once an avatar is on screen. false hides it: then put the line in your credits, about page, footer or store page (Licence S2). Default "bottom-right". | | `buildBudgetMs` (optional) | `number` | Milliseconds of avatar building allowed per frame. Default 6. | | `maxAvatars` (optional) | `number` | Most avatars at once. Default 256, at most 1024. | | `pauseWhenHidden` (optional) | `boolean` | Stop drawing while the canvas is off screen or the tab is hidden (auto loop only). Default true. | | `controls` (optional) | `boolean \| { drag?: boolean; zoom?: boolean; pitch?: boolean }` | Drag to turn the camera, and optionally scroll to zoom and drag up and down to tilt. Default false. | ### Placement Where an avatar stands. | Field | Type | Meaning | |---|---|---| | `position` (optional) | `Vec3` | World position in metres. Y is up. Default [0, 0, 0]. | | `turn` (optional) | `number` | Degrees about Y. 0 faces the default camera (towards -Z). Default 0. | | `scale` (optional) | `number` | Uniform scale. Default 1. | ### AddOptions Options for scene.add(). | Field | Type | Meaning | |---|---|---| | `clip` (optional) | `ClipKey \| null` | What to play once ready. Default "idle". | | `loop` (optional) | `boolean` | Loop the clip. Default true. | | `speed` (optional) | `number` | Playback speed. Default 1. | | `startAt` (optional) | `number \| 'random'` | Seconds into the clip, or "random" to desynchronise a crowd. Default 0. | | `visible` (optional) | `boolean` | Draw it. Default true. | | `priority` (optional) | `number` | Higher builds sooner. Default 0. | ### Vec3 ```ts type Vec3 = [number, number, number]; ``` A point or direction in metres. Y is up; an avatar is about 1.8 tall. ### ClipKey ```ts type ClipKey = string; ``` A clip key from scene.clips() (for example "GenericWave" or "Stand0"), a raw clip id, "prop" (the held prop's own clip), "idle" (a quiet playlist) or "still" (hold the pose). ### ClipInfo One playable clip. | Field | Type | Meaning | |---|---|---| | `key` | `string` | The name to play it by, for example "GenericWave". | | `id` | `string \| null` | Its clip id, or null for "prop" (each prop has its own). | | `seconds` | `number \| null` | Its length in seconds where known; null in this release, which reads a clip's length only when it decodes it. | | `prop` | `boolean` | True for "prop", the held prop's own clip. | | `caption` | `string \| null` | Its name in plain words where the clip table has one, else null. | ### FrameStats What one frame did. | Field | Type | Meaning | |---|---|---| | `ms` | `number` | Wall time since the previous frame. | | `cpuMs` | `number` | Time spent inside frame(). | | `drawn` | `number` | Avatars drawn. | | `culled` | `number` | Avatars outside the view. | | `drawCalls` | `number` | Draw calls in the main pass. | | `built` | `number` | Build steps run this frame. | ### SceneStats Rolling scene numbers. | Field | Type | Meaning | |---|---|---| | `fps` | `number` | Frames a second over the last two seconds. | | `msPerFrame` | `number` | Milliseconds between frames, the mean over the last two seconds. | | `p95Ms` | `number` | Milliseconds between frames that 95 of 100 frames beat, over the last two seconds. | | `cpuMsPerFrame` | `number` | Milliseconds a frame spends inside frame(), the mean over the last two seconds. | | `avatars` | `number` | Avatars in the scene, ready or not. | | `ready` | `number` | Avatars built and shown. | | `queued` | `number` | Avatars waiting to be built or loading. | | `drawn` | `number` | Avatars drawn in the last frame. | | `drawCalls` | `number` | Draw calls in the last frame's main pass. | | `geometries` | `number` | Meshes held on the GPU. | | `textures` | `number` | Textures held on the GPU. | | `gpuMB` | `number` | MiB of GPU memory the scene's meshes and textures hold. | | `cpuMB` | `number` | MiB of item files and decoded assets held in memory. | | `buildMsAvg` | `number` | Milliseconds of a build step, the mean over the last 200. | | `buildMsMax` | `number` | Milliseconds of the longest build step since the scene was made. | | `longFrames` | `number` | Frames over the threshold of 33 ms in the last two seconds. | ### BenchStep One row of the benchmark. | Field | Type | Meaning | |---|---|---| | `avatars` | `number` | Avatars in this step. | | `fps` | `number` | Frames a second while they all played. | | `msPerFrame` | `number` | Milliseconds between frames, the mean. | | `p95Ms` | `number` | Milliseconds between frames that 95 of 100 frames beat. | | `cpuMsPerFrame` | `number` | Milliseconds a frame spent inside frame(), the mean. | | `drawCalls` | `number` | Draw calls in the last frame's main pass. | | `gpuMB` | `number` | MiB of GPU memory the scene held. | | `ready` | `number` | How many of the step's avatars were ready. | | `readyMs` | `number` | Milliseconds from adding the step's avatars to the last one ready (at most 180,000). | | `buildMsMax` | `number` | Milliseconds of the longest build step so far. | ### WardrobeItem One wardrobe item, as scene.wardrobe() and the editor offer it. | Field | Type | Meaning | |---|---|---| | `id` | `string` | The item id. | | `name` | `string` | Its name. | | `section` | `string` | The editor section: shirt, trousers, shoes, costume (outfits), headwear, glasses, gloves, wristwear, ring, earrings, carryable (props), hair, eyes, eyebrows, mouth, facialHair, eyeShadow, facialFeature (face paint), chin, nose, ears, shape (a garment's body shape, listed only while worn, so it can be taken off) or animation. The editor's search of every item finds all of them; shape and animation items cannot be put on. | | `mask` | `number` | The item type bits. 0x1000000 alone is a garment's body shape, offered only while worn. | | `kind` | `number` | 1 a garment (body-specific), 2 a face texture, 3 a shape. | | `gender` | `number \| null` | For garments: 1 male body, 2 female body, 3 either, null not body-specific. | | `hidden` | `boolean` | A duplicate of another item; offered only while worn. | | `stock` | `boolean` | Part of the built-in wardrobe. | | `awarded` | `boolean` | An award item. | | `game` | `string \| null` | The game an award or item came with, where known. | | `colours` | `number` | How many colourways the item carries (scene.colourways gives them once it is loaded); 0 or 1 when it has no choice. | | `sub` | `string \| null` | The catalogue's subcategory name, where it has one; searched with the name. | | `slots` | `readonly string[]` | The slots the item fills ("shirt", "trousers", ...). | ## Errors Every error the SDK raises is a `SonaError`: `code` says what went wrong, `fix` what to do. `create()` and `ready` reject with one; `add()` throws one only past `maxAvatars`. ### SonaError The error class. Its `message` and `fix` are plain words for a person; `code` is one of the values below. | Field | Type | Meaning | |---|---|---| | `code` | `'unsupported' \| 'not_ready' \| 'origin' \| 'licence' \| 'app' \| 'gate' \| 'manifest' \| 'context' \| 'readback' \| 'limit' \| 'destroyed' \| 'item' \| 'not_found'` | unsupported: no WebGPU or WebGL2 (or no WebGPU when renderer "webgpu" was asked for). not_ready: a headless picture's avatar was not ready in time. origin: this page's origin is not registered for the app. licence: the app has not accepted the SDK Licence. app: no such app, or it was turned off. gate: 360sona could not be reached. manifest: that avatar could not be read or built. context: the graphics context failed. readback: a picture could not be read. limit: too many avatars or requests. destroyed: the scene or avatar is gone. item: a custom item file was refused (the message names the rule). not_found: no such award, or none this player has earned (the award calls). Read only. | | `fix` (optional) | `string` | What to do about it, in plain words. Read only. | ## Custom items Items of your own (`.sonaitem` files, [custom items](https://360sona.com/devs/docs/guides/custom-items.md)), per scene as `scene.items`, worn by id with `avatar.wear()`. ### scene.items.add() ```ts interface SonaItems { add(file: ArrayBuffer | Uint8Array | Blob): Promise; } ``` 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`. ```js 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() ```ts 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() ```ts 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() ```ts interface SonaItems { list(): CustomItemInfo[]; } ``` Every loaded item. Returns `CustomItemInfo[]`. ### scene.items.pack() ```ts interface SonaItems { pack(spec: PackSpec): Promise; } ``` Makes a .sonaitem from pixels. Reads the template through 360sona to check its surfaces and take its hash. Unsigned. | Parameter | Type | Meaning | |---|---|---| | `spec` | [`PackSpec`](https://360sona.com/devs/docs/reference/web.md#packspec) | The template, the pictures and the item's details. | Returns `Promise`. ### 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). | ## 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() ```ts interface SonaConnection { glb( manifestBase64: string, opts?: { clips?: ClipKey[] | null; textures?: boolean }, ): Promise; } ``` 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`. ### connection.clips() ```ts interface SonaConnection { clips(): ClipInfo[]; } ``` Every clip a glb() can take. Returns `ClipInfo[]`. ### connection.samples() ```ts 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() ```ts interface SonaConnection { wardrobe(): Promise; } ``` Every item an avatar can wear, as the editor offers them. Returns `Promise`. ### connection.colours() ```ts interface SonaConnection { colours(): Record; } ``` The colour choices of each colourable part (skin, hair, eyes and the rest), each "#rrggbb". Returns `Record`. ### connection.credit() ```ts 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() ```ts 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() ```ts interface SonaHeadless { render( manifestBase64: string, opts?: HeadlessOptions, ): Promise; } ``` One picture as RGBA pixels. | Parameter | Type | Meaning | |---|---|---| | `manifestBase64` | `string` | The avatar's 1,000-byte manifest, base64. | | `opts` (optional) | [`HeadlessOptions`](https://360sona.com/devs/docs/reference/web.md#headlessoptions) | The picture's size, framing, clip and colour. | Returns `Promise`. ### headless.picture() ```ts interface SonaHeadless { picture(manifestBase64: string, opts?: HeadlessOptions): Promise; } ``` One picture as an image file. | Parameter | Type | Meaning | |---|---|---| | `manifestBase64` | `string` | The avatar's 1,000-byte manifest, base64. | | `opts` (optional) | [`HeadlessOptions`](https://360sona.com/devs/docs/reference/web.md#headlessoptions) | The picture's size, framing, clip, colour and format. | Returns `Promise`. ### headless.batch() ```ts interface SonaHeadless { batch( manifests: string[], opts: HeadlessOptions, fn: ( index: number, result: HeadlessPicture | { error: SonaError }, ) => void, flight?: { inFlight?: number }, ): Promise; } ``` A picture of each avatar, built a few at a time. | Parameter | Type | Meaning | |---|---|---| | `manifests` | `string[]` | The avatars, each base64. | | `opts` | [`HeadlessOptions`](https://360sona.com/devs/docs/reference/web.md#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`. ### headless.sequence() ```ts interface SonaHeadless { sequence( manifestBase64: string, opts: HeadlessOptions, seq: { frames?: number; fps?: number; sweep?: number }, fn: (index: number, frame: HeadlessPicture) => void, ): Promise; } ``` 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`](https://360sona.com/devs/docs/reference/web.md#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`. ### headless.close() ```ts 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. | ## The avatar editor element ``, the player-facing avatar creator as one element ([guide](https://360sona.com/devs/docs/guides/web-editor.md)). `defineAvatarEditor()` registers it; the page opens it, the player makes or changes an avatar, and `open()` resolves with the manifest. ```js import { defineAvatarEditor } from './sona-renderer.js'; defineAvatarEditor(); // registers const editor = document.createElement('sona-avatar-editor'); document.body.append(editor); editor.sceneOptions = { appId: 'your-app' }; const manifest = await editor.open({ mode: 'quick' }); if (manifest) save(manifest); // null when the player cancelled ``` ### SonaAvatarEditor properties | Field | Type | Meaning | |---|---|---| | `mode` | `AvatarEditorMode` | The screen. | | `manifest` | `string \| null` | The manifest being edited (base64), or the attribute while closed. | | `isOpen` | `boolean` | True while open. Read only. | | `changed` | `boolean` | True when the avatar differs from the one it opened on. Read only. | | `scene` | `SonaScene \| null` | The editor's scene while open (the SDK scene it draws in), or null. Read only. | | `sceneOptions` | `Partial` | Options passed to SonaRenderer.create for the editor's scene (appId, host, pixelRatio, ...). Set before open. | | `gamepad` | `boolean` | Read the standard gamepad while open. Default true. | | `startScreen` | `'body' \| 'appearance' \| 'wardrobe'` | The full creator's first screen: "body" (default), "appearance" or "wardrobe". Set before open. | | `itemFilter` | `((row: WardrobeItem) => boolean) \| null` | (row) => false leaves an item out of every list and every generated look. Set before open. | ### editor.open() ```ts interface SonaAvatarEditor { open( opts?: { mode?: AvatarEditorMode; manifest?: string }, ): Promise; } ``` Opens the editor. Resolves with the finished manifest on Done, or null on Cancel. | Parameter | Type | Meaning | |---|---|---| | `opts.mode` (optional) | `AvatarEditorMode` | The screen. Default: the mode attribute, else "full". | | `opts.manifest` (optional) | `string` | The manifest to start from. Default: the manifest attribute; none starts a new avatar. | Returns `Promise`. ### editor.done() ```ts interface SonaAvatarEditor { done(): void; } ``` Done: fires done with the manifest and closes. ### editor.cancel() ```ts interface SonaAvatarEditor { cancel(): void; } ``` Cancel: fires cancel and closes. ### editor.close() ```ts interface SonaAvatarEditor { close(): void; } ``` Closes without an event (the open promise gives null). ### editor.undo() ```ts interface SonaAvatarEditor { undo(): void; } ``` Undo the last edit. ### editor.redo() ```ts interface SonaAvatarEditor { redo(): void; } ``` Redo. ### editor.addEventListener() ```ts interface SonaAvatarEditor { addEventListener( type: K, fn: (e: AvatarEditorEventMap[K]) => void, opts?: boolean | AddEventListenerOptions, ): void; addEventListener( type: string, fn: EventListenerOrEventListenerObject, opts?: boolean | AddEventListenerOptions, ): void; } ``` - `K`: Listens for one of the editor's events, its detail typed by AvatarEditorEventMap. - `string`: Any other event, as on any element. ### defineAvatarEditor ```ts declare const defineAvatarEditor: ( name?: string, ) => SonaAvatarEditorConstructor; ``` Registers the avatar editor element, by default as ``, and returns its class. Call once per page; a second call returns the same class. ### AvatarEditorMode ```ts type AvatarEditorMode = 'full' | 'quick' | 'wardrobe'; ``` The three screens: the whole creator, the quick creator (eight generated looks, then one tweak) and the wardrobe picker. ### AvatarEditorEventMap The detail of the editor's events. | Field | Type | Meaning | |---|---|---| | `open` | `CustomEvent<{ mode: AvatarEditorMode }>` | The editor opened (it then loads). | | `change` | `CustomEvent<{ manifest: string; change: { op: string; [k: string]: unknown } }>` | An edit, an undo, a redo or a chosen look. `manifest` is the avatar now (base64). | | `done` | `CustomEvent<{ manifest: string }>` | Done: the finished manifest. The editor closes. | | `cancel` | `CustomEvent>` | Cancelled. The editor closes. | | `error` | `CustomEvent<{ error: unknown; code: string \| null; message: string }>` | The scene or the catalogue could not be loaded, or the preview failed. | ## Face tracking `SonaTrack`: webcam face tracking, MediaPipe's face landmarker in, an avatar's face and head out ([guide](https://360sona.com/devs/docs/guides/face-tracking.md)). ### FaceTracker properties | Field | Type | Meaning | |---|---|---| | `options` | `Record` | The settings in use: the defaults with the ones createFaceTracker() was given. A copy. Read only. | ### tracker.feed() ```ts interface FaceTracker { feed(frame: FaceFrame): void; } ``` Takes one frame. | Parameter | Type | Meaning | |---|---|---| | `frame` | [`FaceFrame`](https://360sona.com/devs/docs/reference/web.md#faceframe) | One frame of blendshape weights and head rotation; frameFromLandmarker() makes one. | ### tracker.state() ```ts interface FaceTracker { state(): FaceTrackerState; } ``` What the tracker makes of the frames so far. Returns `FaceTrackerState`. ### tracker.reset() ```ts interface FaceTracker { reset(): void; } ``` Forgets every frame and hands the face back to the clip; a calibration is kept. ### tracker.calibrateBegin() ```ts interface FaceTracker { calibrateBegin(): void; } ``` The frames from calibrateBegin to calibrateEnd are the neutral face. ### tracker.calibrateEnd() ```ts interface FaceTracker { calibrateEnd(): { frames: number; neutral: number[]; head: number[]; } | null; } ``` Ends the calibration and uses it: the neutral face's 52 weights and the head's rest rotation [x, y, z, w]. Returns null when no frame came in. Returns `{ frames: number; neutral: number[]; head: number[] } | null`. ### tracker.setCalibration() ```ts interface FaceTracker { setCalibration( c: { frames: number; neutral: number[]; head: number[] } | null, ): void; } ``` Uses a calibration saved earlier. | Parameter | Type | Meaning | |---|---|---| | `c` | `{ frames: number; neutral: number[]; head: number[] } \| null` | A calibration calibrateEnd() returned, or null to drop it. | ### SonaTrack Webcam face tracking: the page brings MediaPipe's face landmarker and a `