# 📦 Format Specification

The SDK uses two binary formats, both **FlatBuffers**-based, plus a runtime FFI interface. This page summarizes them; the **canonical, field-level specs live in the SDK**:

- [**SSAB / SSQB Schema**](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssab/SCHEMA.md>) - the asset binary.
- [**FrameData Schema**](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssruntime/SCHEMA.md>) - the runtime exchange interface.

Terms below - animation pack, cellmap, part types, name hash - are defined in the [Glossary](<https://cri-middleware.github.io/SpriteStudio-Docs/sdk/glossary/index.md>).

## 🗄️ SSAB / SSQB - the asset binary

`.ssab` (**S**prite**S**tudio **A**nime **B**inary) and `.ssqb` (Sequence Binary) are the converted, play-ready assets produced by `libssconverter` from the XML-based `ss*e` sources (`ssae` / `ssce` / `ssee` / `ssse` / `fnt` / `ssqe`).

|  | `ss*e` (XML) | `.ssab` / `.ssqb` (binary) |
| --- | --- | --- |
| Format | XML / BMFont text | FlatBuffers |
| String lookup | Name comparison | Hash-based (`uint32`) |
| Access | Deserialize to owned structs | Zero-copy read |
| `no_std` | No | Yes |

**Conversion unit - one `.ssab` per `.ssae` (animation pack).** Each `.ssab` is self-contained: it embeds only the `ss*e` resource *data* (cellmaps, effects, fonts) that the pack actually references - except sound settings: a pack with an Audio part carries every `.ssse` of the project. The `.sspj` project itself is *not* stored in `.ssab` - it is used only to resolve resource references during conversion. The texture and sound **binaries** are a separate matter: they sit alongside the `.ssab` unless you convert in *embedded mode*, which packs them in as well - see [Shared Limitations](<https://cri-middleware.github.io/SpriteStudio-Docs/sdk/limitations/index.md>).

### Key design decisions

- **Hash-based lookups** - every named entity carries `name_hash: uint32`, so a lookup compares integers, never strings, at runtime.
- **Columnar keyframes** - instead of `ss*e`'s per-part tagged attribute lists, every key of the pack sits in one set of columns (frame, interpolation, curve, value), and each part names, per attribute, the run of keys that animates it (`position_x_keys`, `rotation_z_keys`, ...). A key search walks contiguous memory, and runs, curves and compound values that repeat are stored once.
- **Event separation** - event attributes (user data, signal, audio, instance, effect) are stored **per frame** (`EventsPerFrame`) rather than per part, optimizing frame dispatch.
- **Union-based part types** - a FlatBuffers union replaces `ss*e`'s tag-string dispatch.
- **Zero-copy / `no_std`** - the default runtime mode reads without allocation; a `converter` feature enables the Object API for writing.
- **Editor-only fields stripped** - UI state, bone-editing, IK, and mesh-weight-editing fields are dropped; mesh weights are pre-resolved to per-vertex influences indexed by part.

`.ssqb` (Sequence) mirrors `.ssqe` almost 1:1 - a list of sequences referencing animation packs by name/hash.

## 🔗 FrameData - the runtime interface

Where `.ssab` holds the *whole timeline* (generated offline), **`FrameData` is generated dynamically at runtime for a single frame**. `libssruntime` takes an animation's keyframe arrays, evaluates them at the current frame, and outputs a `PartState` per part - the primary **data-exchange interface between the runtime core and your renderer over FFI**.

```text
.ssab AnimationData (sparse keyframes)  +  current frame N
        |  libssruntime: interpolate + coordinate-convert
        v
FrameData (dense, one frame)  --FFI-->  your renderer
   +- parts: [PartState]  (position_x, rotation_z, alpha, cell, ...)
```

Each `PartState` field maps directly from the keys of the corresponding `.ssab` `PartAnimationData` field (e.g. `position_x` \<- the run `position_x_keys` names, interpolated and converted to your coordinate system). The full field-by-field mapping is in the [FrameData Schema](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssruntime/SCHEMA.md>). The vertices to draw are not in `FrameData`: the renderer reads them from the runtime's SoA buffers ([Render Loop](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssruntime/docs/30_core/40_render_loop.md>)).

## 🔧 Regenerating bindings

The schemas are defined as FlatBuffers `.fbs` files in the SDK ([`ssab.fbs`](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssab/fbs/ssab.fbs>) / [`ssqb.fbs`](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssab/fbs/ssqb.fbs>), and [`framedata.fbs`](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssruntime/fbs/framedata.fbs>)). See [`libssab`](<https://github.com/cri-middleware/SpriteStudio-SDK/tree/HEAD/libs/ssab>) for its features (`default`, `converter`, and `no_std` by turning the default features off) and codegen.

> [!NOTE]
>
> **Schema versioning**
>
> `.ssab` carries a binary `version` field, and tooling such as `ssconverter-web` is published [per schema version](<https://cri-middleware.github.io/SpriteStudio-Docs/overview/convert-with-a-standalone-tool/index.md>). Match the converter's schema to your player's runtime version - a file the runtime cannot read at its own version [does not load](<https://cri-middleware.github.io/SpriteStudio-Docs/sdk/limitations/index.md>).
