# Live2D and Spine sprites

Show Live2D Cubism models and Spine skeletons as sprites. The official plugins `live2d` and `spine` (`plugins/live2d` and `plugins/spine` in this repository) draw them.
Neither includes the runtime that animates the models (Cubism Core for Live2D, spine-webgl for Spine). Because those come with terms of use, authors agree to the terms themselves, get the runtimes and put them in the project folder.

You write scripts the same way as for ordinary sprites (`@chara Yui smile at=left`). Showing, hiding, standing positions, `frame`, flipping, speaker emphasis, color tone (`@tone`), depth of field, saving and loading, skipping,
save thumbnails and `lim shot` work the same as for the engine's sprites.

## Setting up

1. In "Official plugins" on the "Plugins" tab of Studio, install "Live2D" or "Spine" and restart (it's copied into `plugins/live2d` or `plugins/spine` and added to `plugins` in `liminalia.json`).
   When running from the repository, you can also write a folder such as `plugins/live2d` in `plugins` in `liminalia.json`.
2. Put the runtime in `assets/others/` ("Live2D" and "Spine" below). Until you do, the variant's `image` (a still image) is shown, and `lim check` tells you how to place it.
3. Put the model files in `assets/fgimage/`, and choose the type and the file in "Sprite motion" on the "Characters" tab of Studio (this becomes the character's `model` in cast.json).

The variant's `image` is needed as a still image that decides position and size (it's used for arranging sprites, the list of expressions, what's shown until the model loads, and what's shown when there's no runtime).
The model is fitted into the variant's frame (`frame`; without one, the size of `image`), centered and keeping its aspect ratio. If you export the still image with the same aspect ratio as the model's canvas (Live2D) or the skeleton's bounds (Spine), the positions line up.
So that hair or arms that stick out aren't cut off, it draws 15% beyond each edge of the frame (top, bottom, left and right).

```json
"Yui": {
  "model": { "type": "live2d", "src": "yui/yui.model3.json" },
  "appearances": {
    "default": {
      "variants": {
        "normal": { "image": "yui/normal.png" },
        "smile": { "image": "yui/smile.png" },
        "angry": { "image": "yui/angry.png", "model": { "type": "live2d", "expression": "f03", "motion": "Angry:1" } }
      }
    }
  }
}
```

The character's `model` applies to all variants. If you write a `model` of the same `type` in a variant, its fields are laid over the character's `model` (`angry` above uses the same model and sets only the expression and motion).
If you write a `model` of a different `type` in a variant, only that variant is drawn a different way.
The expression, motion, animation, skin and loop of a variant can be chosen from the names read from the model file, in the "Sprite motion" panel that appears when you select the variant on the "Characters" tab of Studio (Spine `.skel` names can't be read, so you type them).

## Live2D

### Files to place

| What to place | Where | Where to get it |
|---|---|---|
| Cubism Core (`Core/live2dcubismcore.min.js`) | `assets/others/live2d/live2dcubismcore.min.js` | Cubism SDK for Web on Live2D's official site (https://www.live2d.com/sdk/download/web/) |
| The model (`.model3.json`, `.moc3`, textures, `.motion3.json`, `.exp3.json`, `.physics3.json`, `.pose3.json`) | `assets/fgimage/<character>/` (the exported folder as is) | "Export For Runtime" in Cubism Editor |

The Framework of the Cubism SDK for Web (CubismWebFramework on GitHub) isn't used. This plugin reads values from Core and does the animating and drawing itself.

### Terms of use (for authors to check and agree to)

The terms can change. Before using it, always read the current terms on Live2D's official site. What was checked in November 2026 is as follows.

- **When downloading**: You agree to two agreements, the Live2D Proprietary Software License Agreement (Core) and the Live2D Open Software License Agreement (Framework) (https://www.live2d.com/eula/live2d-proprietary-software-license-agreement_jp.html, https://www.live2d.com/eula/live2d-open-software-license-agreement_jp.html).
- **When distributing Core**: Core can be distributed only in a form built into a work (a game) whose main features use Core. Don't modify it, distribute it in the form you received from Live2D, and don't release it under a license other than Live2D's.
  Players also need to agree to provisions that protect Core, so put them in the game's terms of use (5.2 of the Proprietary Software License Agreement).
- **Publication license agreement (SDK Release License)**: Businesses whose sales in the most recent fiscal year are 10 million yen or more sign a contract with Live2D before releasing the game (no later than one month before release).
  Individuals, and businesses with sales under 10 million yen, don't need one (https://www.live2d.com/sdk/license/).
- **Expandable applications**: Games in which players can add and use models, and games that combine several works into one, need a review by Live2D and a separate contract regardless of size (https://www.live2d.com/sdk/license/expandable/).
  Make the game show only models the author put in, and if you can't tell whether your design falls under this, ask Live2D.
- **Sample models**: The official samples (Hiyori Momose and others) are subject to the Free Material License Agreement and the terms of use for sample data. Individuals and small businesses can build them into a game and distribute it, but
  there are conditions such as a copyright notice, and the materials themselves can't be redistributed (putting them in a public repository, for example).
- **Combining with other middleware**: Live2D's agreements have a provision about using it in combination with middleware that competes with Live2D. If one game uses both Live2D and Spine, ask Live2D first (https://www.live2d.jp/contact/).

Liminalia and this plugin don't include Core. Authors who make and distribute games that use Live2D sprites get Core themselves and agree to the terms above.

### model fields

| Field | Default | Contents |
|---|---|---|
| `type` | | `"live2d"` |
| `src` | | The `.model3.json` (a path from `fgimage`). Required |
| `expression` | The expression with the same name as the variant | This variant's expression (`Name` in `Expressions` of the `.model3.json`). `""` for no expression |
| `motion` | The group with the same name as the variant | The motion played for this variant (a group in `Motions`. `"group:number"` picks one; if you don't write the number, one from the group). `""` plays none |
| `idle` | `Idle` | The group of idle motions. `""` for no idle movement |
| `breath` | `true` | Breathing and slight swaying of the body |
| `blink` | `true` | Blinking |
| `lipSync`, `eyeBlink` | `Groups` in the `.model3.json` | The IDs of the lip sync and blink parameters. If they aren't in `Groups`, `ParamMouthOpenY`, and `ParamEyeLOpen` and `ParamEyeROpen` |
| `lipGain` | `1` | How much the mouth opening is multiplied by |
| `scale`, `x`, `y` | `1`, `0`, `0` | The size within the frame, and how far to shift it (as a fraction of the frame's width and height; right and down are positive) |
| `core` | `live2d/live2dcubismcore.min.js` | The Core file (a path from `others`) |

- When the variant changes, the expression crossfades (`FadeInTime` and `FadeOutTime` in the `.exp3.json`; 1 second if they aren't there), the previous variant's motion fades out, and the new variant's motion plays.
  If the motion's `Loop` is true, it repeats until the next variant change. While skipping and when loading, it switches at once without blending.
- Lip sync adds the voice's loudness (without a voice, opening and closing while the text appears) to the mouth parameter. It uses the same value as the engine's lip sync (the variant's `lip`).
- Physics (`.physics3.json`) and pose (`.pose3.json`) are used if the files exist. `PartOpacity` in motions and the `EyeBlink`, `LipSync` and `Opacity` curves of `Model` are read too.
- Drawing uses WebGL (one context shared by all Live2D sprites). It supports the drawing order of drawables, textures, multiply and screen colors, normal, additive and multiplicative blending, and clipping (including inverted masks).
  It doesn't support the blend modes and offscreen rendering added in Cubism 5.3, motion sounds and user data, or hit detection (drawn with normal blending).

## Spine

### Files to place

| What to place | Where | Where to get it |
|---|---|---|
| The IIFE build of spine-webgl (`dist/iife/spine-webgl.min.js`) | `assets/others/spine/spine-webgl.min.js` | `@esotericsoftware/spine-webgl` on npm (`node_modules/@esotericsoftware/spine-webgl/dist/iife/` after `npm install`), or EsotericSoftware/spine-runtimes on GitHub |
| The skeleton (`.skel` or `.json`), `.atlas` and textures | `assets/fgimage/<character>/` | Exporting from the Spine editor |

Match the version of Spine the skeleton was exported with and the version of the runtime (the first two numbers, such as `4.2`). If the versions differ, it can't be read.
The game loads the runtime from inside the game (exported games don't load scripts from outside pages), so place the file rather than using a CDN URL.

### Terms of use (for authors to check and agree to)

The terms can change. Before using it, always read the current terms on Esoteric Software's official site. What was checked in November 2026 is as follows.

- Each person who makes software with a Spine runtime built in needs their own Spine editor license (the Spine Runtimes License Agreement, and Section 2 of the Spine Editor License Agreement; https://esotericsoftware.com/spine-runtimes-license, https://esotericsoftware.com/spine-editor-license).
  If the engine bundled the runtime, everyone who uses the engine, including authors who don't use Spine, would need a license, so Liminalia doesn't bundle it.
- When you distribute a game that includes the runtime, distribute the text of the Spine Runtimes License and the copyright notice with it (put them in the game's license screen or in documents included in the distribution).
- The terms read as not requiring players of the game to have a license (someone with a license can distribute games that include the runtime; 2.2 of the Spine Editor License Agreement).
- The sample skeletons in spine-runtimes (spineboy and others) follow their own `license.txt` (the images can't be used commercially). You can use them to try things out on your own computer, but don't put them in games you distribute.

### model fields

| Field | Default | Contents |
|---|---|---|
| `type` | | `"spine"` |
| `src` | | The skeleton (`.skel` or `.json`; a path from `fgimage`). Required |
| `atlas` | `src` with its extension changed to `.atlas` | The `.atlas` (a path from `fgimage`). Textures are read from the same folder as the `.atlas` |
| `animation` | The animation with the same name as the variant | The animation played for this variant. `""` plays none |
| `loop` | `true` | Whether the variant's animation repeats (with `false`, it plays once and stops in its last pose) |
| `skin` | The skin with the same name as the variant | The skin. Without one, the skeleton's default skin |
| `idle` | `idle` | The idle animation (always playing). `""` for none |
| `mouth` | `mouth` | The lip sync animation. The mouth opening (0 to 1) is mapped onto the poses from the start to the end of that animation (make the start a closed mouth and the end a wide-open mouth) |
| `blink` | `blink` | The blink animation. Played once every so often. `""` for none |
| `mix` | `0.2` | Seconds of blending when switching animations |
| `scale`, `x`, `y` | `1`, `0`, `0` | The size within the frame, and how far to shift it |
| `runtime` | `spine/spine-webgl.min.js` | The runtime file (a path from `others`) |

- The animation tracks are 0 for idle, 1 for the variant's animation, 2 for blinking and 3 for lip sync. When the variant changes, the animation on track 1 and the skin change. While skipping, they change without blending.
- The skeleton's bounds are `x`, `y`, `width` and `height` of the exported skeleton (without them, the bounds of the setup pose).
- Textures exported with premultiplied alpha (`pma: true` in the `.atlas`) are drawn that way.
- It uses the API of spine-webgl in Spine 4.x (`SkeletonRenderer`, `PolygonBatcher`, `Shader`, `Matrix4` and so on). It also updates the physics constraints added in 4.2.

## Exporting

- Exporting the browser, desktop and mobile versions also puts the `.moc3`, `.json`, `.skel` and `.atlas` files (sprite models) and `.js` files (runtimes placed in others) in `assets/` into the game.
  They can be read even with asset encryption (`build.encrypt`, `build.browser.encrypt`).
- When images are scaled down for the mobile version and so on (`images` in `build.mobile` and the like), textures are scaled down too. Live2D and Spine read positions within textures as ratios, so the shapes don't break when scaled down (they do get coarser).
- The CSP of exported games (`build.csp`) allows scripts from the same place as the game, so runtimes placed in `others` work as is.
  If the developer tools show that the CSP blocked something (WebAssembly and so on) and the runtime doesn't work, add it to `script-src` in `build.csp` (`{ "script-src": ["'wasm-unsafe-eval'"] }`).

## Checking

`lim check` and Studio's check report the following (the `check` in `./commands`).

| Diagnostic | Contents |
|---|---|
| `live2d-no-src`, `spine-no-src` | `model` has no `src` |
| `live2d-missing-model`, `spine-missing-file` | `src` (and Spine's `.atlas`) isn't in `fgimage` |
| `live2d-src-kind` | Live2D's `src` isn't a `.model3.json` |
| `live2d-no-core`, `spine-no-runtime` | The runtime isn't placed in `others` (until it is, the still image is shown) |

When the plugin isn't installed, the engine's check reports `model-plugin-missing` (a warning): there is a `model` whose `type` is `live2d` or `spine`,
but that plugin isn't loaded and isn't in `plugins` in `liminalia.json` (the game shows the image sprite). It's reported once per character and type, on that character's line.
Mistakes in `src` are reported by the diagnostics above once the plugin is installed. A `type` with a close spelling (`Live2D`) is reported by the same diagnostic.

In the game, when something can't be loaded (no runtime, a missing file, mismatched versions), the reason is shown in the developer tools and play continues with the still image.

The plugins' tests (`plugins/*/test`) and the browser test (`packages/web/test/e2e/model-plugins.test.ts`) use fakes with the same API (`test/fixtures`) instead of the real runtimes.
If you have the real runtimes and models on hand, running the same browser test with the following environment variables confirms that the real ones can also be loaded, drawn and switched between variants (without them, it's skipped).

```
LIMINALIA_E2E_BROWSER=1 \
LIMINALIA_LIVE2D_CORE=…/live2dcubismcore.min.js LIMINALIA_LIVE2D_MODEL=…/hiyori/hiyori.model3.json \
LIMINALIA_SPINE_RUNTIME=…/spine-webgl.min.js LIMINALIA_SPINE_SKELETON=…/spineboy-pro.skel \
npx vitest run packages/web/test/e2e/model-plugins.test.ts
```

For `LIMINALIA_LIVE2D_MODEL` and `LIMINALIA_SPINE_SKELETON`, the whole folder containing the file is copied (for Spine, the `.atlas` is the one with the same name as the skeleton). You can set just one of the two.
