@anime-studio/cli 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -2
  3. package/dist/bin.d.ts +3 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +238 -0
  6. package/dist/bin.js.map +1 -0
  7. package/dist/describe.d.ts +7 -0
  8. package/dist/describe.d.ts.map +1 -0
  9. package/dist/describe.js +48 -0
  10. package/dist/describe.js.map +1 -0
  11. package/dist/doctor.d.ts +44 -0
  12. package/dist/doctor.d.ts.map +1 -0
  13. package/dist/doctor.js +121 -0
  14. package/dist/doctor.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +11 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/load.d.ts +13 -0
  20. package/dist/load.d.ts.map +1 -0
  21. package/dist/load.js +41 -0
  22. package/dist/load.js.map +1 -0
  23. package/dist/skills.d.ts +28 -0
  24. package/dist/skills.d.ts.map +1 -0
  25. package/dist/skills.js +56 -0
  26. package/dist/skills.js.map +1 -0
  27. package/package.json +55 -3
  28. package/skills/animestudio/SKILL.md +165 -0
  29. package/skills/animestudio/examples/first-frame.ts +54 -0
  30. package/skills/animestudio/examples/hello.scene.json +50 -0
  31. package/skills/animestudio/examples/hello.sequence.json +13 -0
  32. package/skills/animestudio/examples/remotion/Root.tsx +25 -0
  33. package/skills/animestudio/examples/remotion/index.ts +5 -0
  34. package/skills/animestudio/examples/render-video.ts +110 -0
  35. package/skills/animestudio/references/packages.md +54 -0
  36. package/skills/animestudio/references/rendering.md +127 -0
  37. package/skills/animestudio/references/scene-format.md +101 -0
  38. package/skills/animestudio/references/validation-and-debugging.md +67 -0
  39. package/skills/animestudio-animation/SKILL.md +176 -0
  40. package/skills/animestudio-animation/examples/gestures.ts +55 -0
  41. package/skills/animestudio-animation/examples/hold.ts +82 -0
  42. package/skills/animestudio-animation/examples/knockdown.ts +68 -0
  43. package/skills/animestudio-animation/examples/sheet.ts +80 -0
  44. package/skills/animestudio-animation/examples/walk-wave-run.ts +59 -0
  45. package/skills/animestudio-animation/references/clips.md +103 -0
  46. package/skills/animestudio-animation/references/director-beats.md +48 -0
  47. package/skills/animestudio-animation/references/holding.md +106 -0
  48. package/skills/animestudio-animation/references/locomotion.md +86 -0
  49. package/skills/animestudio-animation/references/timing.md +89 -0
  50. package/skills/animestudio-characters/SKILL.md +211 -0
  51. package/skills/animestudio-characters/examples/cast.ts +63 -0
  52. package/skills/animestudio-characters/examples/human.ts +52 -0
  53. package/skills/animestudio-characters/examples/import-svg.ts +68 -0
  54. package/skills/animestudio-characters/examples/lumo.svg +36 -0
  55. package/skills/animestudio-characters/examples/sprout.toon.json +116 -0
  56. package/skills/animestudio-characters/examples/sprout.ts +48 -0
  57. package/skills/animestudio-characters/examples/turnaround.ts +91 -0
  58. package/skills/animestudio-characters/references/custom-rig.md +139 -0
  59. package/skills/animestudio-characters/references/import-svg.md +59 -0
  60. package/skills/animestudio-characters/references/look-options.md +143 -0
  61. package/skills/animestudio-characters/references/rig-surface.md +62 -0
  62. package/skills/animestudio-script/SKILL.md +164 -0
  63. package/skills/animestudio-script/examples/director.ts +143 -0
  64. package/skills/animestudio-script/examples/sheet.ts +58 -0
  65. package/skills/animestudio-script/examples/short.ts +193 -0
  66. package/skills/animestudio-script/references/actions.md +84 -0
  67. package/skills/animestudio-script/references/dialogue-lipsync.md +87 -0
  68. package/skills/animestudio-script/references/director.md +110 -0
  69. package/skills/animestudio-script/references/shots-and-editing.md +79 -0
  70. package/skills/animestudio-script/references/writing-for-animation.md +84 -0
  71. package/skills/animestudio-sets/SKILL.md +232 -0
  72. package/skills/animestudio-sets/examples/hillside.scene.json +93 -0
  73. package/skills/animestudio-sets/examples/render-scene.ts +35 -0
  74. package/skills/animestudio-sets/examples/sets.ts +257 -0
  75. package/skills/animestudio-sets/references/drawing-sets.md +119 -0
  76. package/skills/animestudio-sets/references/fx.md +92 -0
  77. package/skills/animestudio-sets/references/lighting-camera.md +93 -0
  78. package/skills/animestudio-sets/references/scene-fields.md +132 -0
@@ -0,0 +1,62 @@
1
+ # What a kit character can do (controls, views, clips, anchors)
2
+
3
+ Read this when you script a character built by `cartoonCharacter` or `humanCharacter`, or when you
4
+ need exact names. The lists below were printed from the built documents (kit 0.2.x); confirm on your
5
+ version with `toon describe <file>.toon.json` — that output is the authority.
6
+
7
+ ## `cartoonCharacter` controls
8
+
9
+ | Control | Type | Values |
10
+ |---|---|---|
11
+ | `view` | pose | `front` `half` `q24` `profile` `q50` `q64` `q77` `side` `q112` `away` `q158` `back` |
12
+ | `head` | pose | any drawn angle, or a mirrored one: `~half` `~q24` `~profile` `~q50` `~q64` `~q77` `~side` `~q112` `~away` `~q158` (looks the other way); `null` follows the body's `view` |
13
+ | `emotion` | pose | `neutral` `sleep` `happy` `joy` `surprised` `sad` `smug` `scared` `angry` `dead` `determined` `calm` `excited` `annoyed` `gape` — or a weight blend `{ "happy": 0.5, "surprised": 0.5 }` |
14
+ | `jaw` | pose | `shut`, `gape`; weighted `{ "gape": 1 }` (big) to `{ "gape": 2 }` (unhinged, `GAPE_FULL`) |
15
+ | `mouth` | viseme | `A` `B` `C` `D` `E` `F` `G` `H` `X`, plus `gape` / `{ "gape": w }` (morphs only) — driven by `say` |
16
+ | `look` | aim | `[x, y]`, an actor or prop id, or `null` — driven by `lookAt` |
17
+ | `side` | pose | `right` / `left`, set by the scene from the actor's facing (only on rigs with asymmetric details) |
18
+
19
+ Views, in turning order. `profile` (36°, a three-quarter view facing right) is the main view; a
20
+ `view` change with a duration steps through the in-betweens, and the director plays the kit's
21
+ `turn` clip (a quick squeeze) on every view change.
22
+
23
+ | `front` | `half` | `q24` | `profile` | `q50` | `q64` | `q77` | `side` | `q112` | `away` | `q158` | `back` |
24
+ |---|---|---|---|---|---|---|---|---|---|---|---|
25
+ | 0° | 12° | 24° | 36° | 50° | 64° | 77° | 90° | 112° | 135° | 158° | 180° |
26
+
27
+ Use `front` for talking to the audience (clear the gaze with `lookAt: null`), `profile` for two
28
+ people talking, `side` / `q64` for runs (`q64` is the rig's `travel` view), `back` / `away` for
29
+ walking off. Facing left is the actor's `flip`, not a view.
30
+
31
+ ## Clips (`cartoonCharacter`)
32
+
33
+ - Locomotion (loop, with `stride`): `walk` `run` `sneak` `strut` `tired` `march` `scaredRun`
34
+ - Base: `idle` (loop it on `layer: -1`), `turn`
35
+ - Talk and gesture: `talk` `wave` `point` `pointUp` `present` `shrug` `think` `facepalm` `laugh`
36
+ `cry` `scared` `clap` `cheer` `dance` `groove` `sing`
37
+ - Props in the hands: `drink` `smoke` `phone` `texting` `textingTwo` `read` `carry` `hold`
38
+ `gamepad` `cue` `dribble` `toss`
39
+ - Body: `jump` `teeter` `flap` `roll` `ride`
40
+ - Fighting and falls: `stance` `power` `punch` `knocked` `down` `rise` (the last three are timed for
41
+ the scene's `fall` / `getUp` — use those actions, not the clips)
42
+
43
+ `humanCharacter` has the same set except `texting`, `carry`, `textingTwo`, `gamepad`, `cue`,
44
+ `groove`; its `view` has only `profile` and `front`; its emotions lack `annoyed` and `gape`.
45
+
46
+ ## Anchors (`cartoonCharacter`)
47
+
48
+ `head`, `face`, `top` (top of the head: hats, halos), `eye`, `ear`, `earB`, `mouth` (move with each
49
+ drawn angle and with the `head` control), `hand`, `handB`, `fist` (the hand anchors have `turn: 1`:
50
+ held props turn with the hand). `hip` defaults to the leg chains' joints.
51
+
52
+ ## Measuring for the director: `cartoonInfo(doc, look, opts?)`
53
+
54
+ Returns `RigInfo`: `height` (as drawn at rest in `profile`, hair and hats included), `extent`
55
+ (`front` / `back` reach from the origin: space neighbours by this, not by their feet), `depth`
56
+ (`front` / `back`, for lying down; `front` grows with `heavy`), `hand`, `shoulder`, `armLength`,
57
+ `backShoulder`, `hip`, `legLength`. Pass the same `style` you built with.
58
+
59
+ ## Gape (swallowing, screaming, yawning big)
60
+
61
+ `{ "action": "pose", "control": "jaw", "value": { "gape": 2 } }`, then `"shut"` (0.1 s closes
62
+ cleanly); or `emotion: "gape"`. Visemes add on top up to gape ≈ 1; keep `say` off while unhinged.
@@ -0,0 +1,164 @@
1
+ ---
2
+ name: animestudio-script
3
+ description: Turns an idea, story or written script (roteiro) into an animeStudio production — logline, beats, scene list, shot list, dialogue with lip sync and emotions — and maps it onto toon-scene scripts, toon-sequence shots, or a director staging for whole episodes. Use when writing or adapting a script, storyboard, shot list, dialogue, lip sync, a short or an episode, a sequence of shots, or a staging for the animeStudio director.
4
+ ---
5
+
6
+ # animeStudio: from a story to scenes, shots and dialogue
7
+
8
+ animeStudio renders cartoons from JSON documents: a **scene** (`*.scene.json`, `format:
9
+ "toon-scene"`) holds actors on a set and a timed `script` of actions; a **sequence**
10
+ (`*.sequence.json`) strings scenes into shots with transitions; the **director**
11
+ (`@anime-studio/director`) writes whole scenes and sequences from a higher-level staging. This skill
12
+ is the writer's room: it decides *what happens when*, then writes it in the vocabulary the engine
13
+ really has.
14
+
15
+ Sibling skills: `animestudio-characters` (building the cast), `animestudio-sets` (backgrounds,
16
+ marks, lighting), `animestudio-animation` (clips, poses, props in hands, motion quality),
17
+ `animestudio` (validate, debug, render, Remotion).
18
+
19
+ ## Workflow
20
+
21
+ 1. **Write the script first, in words** (logline → beats → scene list → shot list → dialogue).
22
+ Read [references/writing-for-animation.md](references/writing-for-animation.md) when starting
23
+ from an idea or when the gag does not read.
24
+ 2. **Pick the path**:
25
+ - a short, a gag, a promo shot, a title card → **hand-written scenes** (below);
26
+ - an episode or any long conversation → **the director**: read
27
+ [references/director.md](references/director.md).
28
+ 3. **Know the cast**: `npx tsx packages/cli/src/bin.ts describe <char>.toon.json` (`toon describe`
29
+ once installed) lists the exact clips, emotions, views and controls. Never invent a name.
30
+ 4. **Write the documents**, keying every time to named constants taken from the shot list and
31
+ the dialogue timings.
32
+ 5. **Validate and debug** every file:
33
+ `npx tsx packages/cli/src/bin.ts validate <files>` then `... debug <scene|sequence>`.
34
+ Fix every error; `info` "jump" findings at your camera cuts are expected.
35
+ 6. **Look at it**: render a contact sheet, one frame per beat (see `examples/sheet.ts`), and read
36
+ it with the sound off. The gag must read from poses, emotions, open mouths on lines. If it does
37
+ not, fix the staging, not the frame.
38
+
39
+ ## Script → documents (hand-written)
40
+
41
+ | Script element | Document |
42
+ |---|---|
43
+ | Location + continuous action | one scene (`layers` = set, `actors`, `props`) |
44
+ | Shot (camera set-up) | a `camera` action inside the scene (`duration: 0` = cut), or a new sequence shot when the place/time changes |
45
+ | Beat | 1–4 script actions at one named time |
46
+ | Line of dialogue | `say` + emotion `pose` + `lookAt` (+ a gesture `play`) |
47
+ | Reaction | emotion `pose`, `fx`, a held pose ≥ 0.8 s |
48
+ | Title, insert, end card | a small scene of its own (`fx caption`, screen-fixed props) |
49
+ | Episode order | `*.sequence.json` `shots` with `transition`s |
50
+
51
+ Exact actions and fields: [references/actions.md](references/actions.md). The scene script has
52
+ `play set pose walkTo face lookAt say fall getUp mount reach grab release` (actor) and
53
+ `camera transition fx shake sound light impulse put` (scene). `sit`, `lie`, `ride`, `wear`, `hug`,
54
+ `hit`, `enter`, `hide`… are **director beats**, not scene actions.
55
+
56
+ ### A beat in JSON
57
+
58
+ ```jsonc
59
+ // 6. REACTION — anticipation (a take) → action (turn) → reaction (the line)
60
+ { "at": 6.70, "action": "fx", "type": "surprise", "actor": "mia" },
61
+ { "at": 6.75, "actor": "mia", "action": "pose", "control": "emotion", "value": "surprised", "duration": 0.1 },
62
+ { "at": 6.75, "actor": "mia", "action": "face", "direction": "left" },
63
+ { "at": 6.75, "actor": "mia", "action": "lookAt", "target": "rex" },
64
+ { "at": 7.05, "actor": "mia", "action": "pose", "control": "emotion", "value": "happy", "duration": 0.3 },
65
+ { "at": 7.10, "actor": "mia", "action": "say", "text": "Oh! Hi, Rex!", "duration": 1.1 },
66
+ { "at": 7.40, "actor": "mia", "action": "play", "clip": "wave", "duration": 1.1, "fadeIn": 0.2, "fadeOut": 0.3 }
67
+ ```
68
+
69
+ ### Rules that make a hand-written scene work
70
+
71
+ - **Every actor gets a looping base clip** at 0: `{ "action": "play", "clip": "idle", "loop":
72
+ true, "layer": -1 }`. Without it they freeze.
73
+ - **Set every changing channel at t = 0** (starting emotion, view, gaze): a key or action at 40 s
74
+ otherwise also applies before it.
75
+ - **One scene per location**, cuts as camera actions inside it: positions stay continuous.
76
+ - **Never overlap two `walkTo`s** of the same actor. `fall` may take over a walk (a trip); no
77
+ `face`/`walkTo` while lying, until `getUp`.
78
+ - **Overlap acting**: a gesture starts slightly before its word; emotions cross-fade 0.2–0.5 s;
79
+ `lookAt` the listener before the line.
80
+ - **Physical gags use the engine**: a hit is the hitter's `punch` clip + the target's `fall` with
81
+ `from` at the moment the fist lands (0.28 s into the kit's `punch`); never fake a fall with
82
+ rotations. Hold a K.O. ≥ 1.5 s before `getUp`.
83
+ - **Camera**: moves ≥ 1 s, `sineInOut`; `frame: [ids]` for two-shots; a cut for the close-up that
84
+ sells the line (mouths must be big enough to read).
85
+ - **Cartoon accents** sparingly: one `fx` per beat, ~0.05 s before the reaction; `shake`/`punch`
86
+ on impacts only.
87
+
88
+ ## Dialogue and lip sync
89
+
90
+ Read [references/dialogue-lipsync.md](references/dialogue-lipsync.md) whenever a scene speaks.
91
+ In short:
92
+
93
+ - `say` needs one cue source: `lipsync` (a cues file id, declared in the scene's `lipsync`), inline
94
+ `cues`, or `text` + `duration` (no audio needed; rough). Add `audio` to play the voice.
95
+ - Best cues: Rhubarb on the WAV (`toon lipsync line.wav --text "…" -o line.cues.json`), then TTS
96
+ timestamps (`cuesFromAlignment`), then `--engine align` (text + audio), then `amplitude`.
97
+ - Time the scene **from the dialogue**: measure each line (`wavDuration`, or ~0.3 s a word), put the
98
+ times in constants, key reactions to words.
99
+ - Per line: emotion 0.05–0.3 s before, gaze on the addressee, listeners looking at the speaker, at
100
+ most one gesture per thought.
101
+
102
+ ## Shots and sequences
103
+
104
+ Read [references/shots-and-editing.md](references/shots-and-editing.md) when turning a shot list
105
+ into a sequence. A sequence's `shots` list `scene`, `from`, `duration`, `transition` (`cut`,
106
+ `crossfade`, `fade`, `iris`, `wipe`, `flash`), `muteSpeech`, `speed`. Keep screen direction (180°
107
+ rule), cut on action or reaction, hold shots ≥ 1 s, end on an iris on whoever has the last beat.
108
+
109
+ ## The director (episodes)
110
+
111
+ `check(staging, lines, kit)` → fix errors → `direct(staging, lines, kit)` →
112
+ `{ sequence, scenes, overlays, music, issues }`. A staging is `blocks` (one continuous scene per
113
+ location stretch, lines `[from, to)`, cast left → right, `beats` with `do`), plus `cuts`,
114
+ `texts`, `music`, `animation` (`anticipation`, `life`) and `camera.style` (`conversation` keeps a
115
+ stable framing of whoever talks). Times are relative to lines (`line`, `word`, `end`, `offset`);
116
+ places are marks or people, never coordinates. Lip sync, listeners turning, talking gestures and
117
+ spacing are automatic. It runs without audio if the lines carry estimated word timings. Details
118
+ and the continuity checklist: [references/director.md](references/director.md).
119
+
120
+ ## Continuity (whole episodes)
121
+
122
+ From docs/AI_GUIDE.md "Continuity" — apply to hand-written and directed work alike:
123
+
124
+ - Stage continuous scenes, not one scene per storyboard shot; cut with the camera.
125
+ - Keep screen direction (180° rule); objects keep their history; vehicles exist only while they
126
+ drive (hide them before they enter and after they leave).
127
+ - Wardrobe follows the place (dress each block; change on screen with a `wear` beat).
128
+ - Time of day is one light change (`light` with a `mood` in the director); never a night scene in a
129
+ day set without it.
130
+ - Hiding is a `hide` beat + `peek`; sitting, lying, riding are staged (`sit`/`lie`/`ride`), never
131
+ drawn per shot; nobody walks while sitting.
132
+ - Listeners face the speaker; front view = talking to the audience (clear the gaze).
133
+ - Around a table, seat everyone behind it facing the camera; leave the camera side open.
134
+ - Captions live in screen space, only while their line plays.
135
+ - Set bounds are the drawn world; time motion to the narration that describes it.
136
+
137
+ ## Examples (run from the repo root)
138
+
139
+ | File | What it shows |
140
+ |---|---|
141
+ | [examples/short.ts](examples/short.ts) | A 10 s original two-character gag: the script in comments (logline, beats with the rule of three, shot list) → a title scene + one continuous street scene with camera cuts → a sequence; one line lip-synced from text only; emotions, gaze, gestures, a trip (`fall`), an iris out |
142
+ | [examples/director.ts](examples/director.ts) | The same cast staged by the director: a kit (cast via `cartoonInfo`, a park set with marks and a bench seat), five lines with estimated word timings (no audio), two blocks (day / evening with a fade), `check` (add `--strict`), `direct`, files rewritten for the CLI |
143
+ | [examples/sheet.ts](examples/sheet.ts) | Helper: writes JSON, renders a labelled contact sheet (frameToSVG → rsvg-convert → magick) |
144
+
145
+ ```bash
146
+ npx tsx skills/animestudio-script/examples/short.ts
147
+ npx tsx packages/cli/src/bin.ts validate skills/animestudio-script/examples/out/short/*.json
148
+ npx tsx packages/cli/src/bin.ts debug skills/animestudio-script/examples/out/short/short.sequence.json
149
+ npx tsx skills/animestudio-script/examples/director.ts
150
+ npx tsx packages/cli/src/bin.ts validate skills/animestudio-script/examples/out/director/*.json
151
+ npx tsx packages/cli/src/bin.ts debug skills/animestudio-script/examples/out/director/episode.sequence.json
152
+ ```
153
+
154
+ Outputs go to `examples/out/` (git-ignored); open `out/*/sheet.png` to check the beats. The contact
155
+ sheet needs `rsvg-convert` and ImageMagick (`magick`).
156
+
157
+ ## Docs
158
+
159
+ [AI_GUIDE.md](https://github.com/denerFernandes/animeStudio/blob/master/docs/AI_GUIDE.md) ·
160
+ [FORMAT.md](https://github.com/denerFernandes/animeStudio/blob/master/docs/FORMAT.md) (§3 scenes,
161
+ §3.7 lip sync, §4 sequences) ·
162
+ [DIRECTOR.md](https://github.com/denerFernandes/animeStudio/blob/master/docs/DIRECTOR.md) ·
163
+ [API.md](https://github.com/denerFernandes/animeStudio/blob/master/docs/API.md) (lipsync,
164
+ director).
@@ -0,0 +1,143 @@
1
+ /**
2
+ * The director path: a staging (blocks + beats) + timed lines + a kit → a whole sequence, with
3
+ * `check()` run first. No audio is needed: the lines carry estimated word timings, and the
4
+ * director lip-syncs every line from them.
5
+ *
6
+ * npx tsx skills/animestudio-script/examples/director.ts (add --strict before a render)
7
+ *
8
+ * Writes out/director/{characters/*.toon.json, <block>.scene.json, episode.sequence.json,
9
+ * sheet.png}. Validate with:
10
+ *
11
+ * npx tsx packages/cli/src/bin.ts validate skills/animestudio-script/examples/out/director/*.json
12
+ * npx tsx packages/cli/src/bin.ts debug skills/animestudio-script/examples/out/director/episode.sequence.json
13
+ *
14
+ * Script: "The Kite" — Mia spots a kite; Rex never manages to see it; at dusk he gives up.
15
+ * Block "park" (lines 0–2, day): Mia points up, Rex looks the wrong way, a double take.
16
+ * Block "bench" (lines 3–4, evening): they sit on the bench; Rex's excuse; Mia's eye-roll line.
17
+ */
18
+ import { join } from "node:path";
19
+ import type { SceneDoc, ToonDoc } from "@anime-studio/core";
20
+ import { type CartoonLook, cartoonCharacter, cartoonInfo } from "@anime-studio/kit";
21
+ import { type Kit, type Line, type Staging, check, describeKit, direct } from "@anime-studio/director";
22
+ import { OUT, contactSheet, writeJson } from "./sheet";
23
+
24
+ const dir = join(OUT, "director");
25
+ const W = 1920, H = 1080, GROUND = 900;
26
+
27
+ // ── Kit: the pieces (cast, sets, props). Built once per series. ───────────────────────────────
28
+ const LOOKS: Record<string, CartoonLook> = {
29
+ rex: { name: "Rex", build: "man", skin: "#e9b48f", hair: "sidePart", hairColor: "#3a2a20", top: "shirt", topColor: "#4f86c6", bottom: "pants", bottomColor: "#333a4a", shoes: "sneakers", shoeColor: "#eeeeee" },
30
+ mia: { name: "Mia", build: "woman", female: true, skin: "#b07850", hair: "ponytail", hairColor: "#20150f", top: "tee", topColor: "#ff7a59", bottom: "skirt", bottomColor: "#2f6f6a", shoes: "sneakers", shoeColor: "#ffffff" },
31
+ };
32
+ const characters: Record<string, ToonDoc> = Object.fromEntries(Object.entries(LOOKS).map(([id, look]) => [id, cartoonCharacter(look)]));
33
+
34
+ const BENCH_X = 960, SEAT = 95;
35
+ const kit: Kit = {
36
+ characters,
37
+ cast: Object.fromEntries(Object.entries(LOOKS).map(([id, look]) => [id, { name: look.name!, scale: 0.9, rig: cartoonInfo(characters[id], look) }])),
38
+ sets: {
39
+ park: {
40
+ ground: { near: GROUND },
41
+ bounds: [-400, 0, W + 400, H],
42
+ layers: [
43
+ { id: "sky", parallax: 0, art: `<rect x="-400" y="-200" width="${W + 800}" height="${H + 400}" fill="#bfe6f7"/>`, moods: ["day", "morning", "afternoon"] },
44
+ { id: "dusk", parallax: 0, art: `<rect x="-400" y="-200" width="${W + 800}" height="${H + 400}" fill="#f4a26b"/>`, moods: ["evening", "night"] },
45
+ { id: "hills", parallax: 0.5, art: `<path d="M-600 820 Q 300 560 1000 760 T 2600 740 L 2600 1300 L -600 1300 Z" fill="#8cc06a" stroke="#2a2a35" stroke-width="3"/>` },
46
+ { id: "lawn", art: `<rect x="-800" y="${GROUND - 30}" width="${W + 1600}" height="500" fill="#6db84f"/>` },
47
+ // The bench is drawn in the set; the mark below says where its seat is.
48
+ { id: "bench", art: `<g stroke="#2a2a35" stroke-width="4"><rect x="${BENCH_X - 230}" y="${GROUND - SEAT - 14}" width="460" height="22" rx="6" fill="#b5713d"/><rect x="${BENCH_X - 230}" y="${GROUND - SEAT - 120}" width="460" height="20" rx="6" fill="#b5713d"/><rect x="${BENCH_X - 210}" y="${GROUND - SEAT + 8}" width="18" height="${SEAT - 8}" fill="#5b4a3a"/><rect x="${BENCH_X + 192}" y="${GROUND - SEAT + 8}" width="18" height="${SEAT - 8}" fill="#5b4a3a"/></g>` },
49
+ ],
50
+ marks: { left: { x: 520 }, right: { x: 1400 }, sky: { x: 1500, y: 250 }, behind: { x: 200, y: 300 }, benchL: { x: BENCH_X - 120, seat: SEAT }, benchR: { x: BENCH_X + 120, seat: SEAT } },
51
+ },
52
+ },
53
+ props: {},
54
+ width: W, height: H, fps: 30,
55
+ };
56
+
57
+ // ── Lines: the soundtrack, timed. Without audio, estimate the timings (~0.3 s a word + pauses). ─
58
+ // With real audio, take `s`, `e` and `words` from a TTS's timestamps or an aligner instead.
59
+ function timed(speaker: string, text: string, s: number, i: number): Line {
60
+ let t = s;
61
+ const words = text.split(/\s+/).map((w) => {
62
+ const d = 0.12 + 0.045 * w.replace(/[^\p{L}]/gu, "").length;
63
+ const word = { w, s: +t.toFixed(2), e: +(t + d).toFixed(2) };
64
+ t += d + (/[,.!?]$/.test(w) ? 0.18 : 0.04);
65
+ return word;
66
+ });
67
+ return { i, speaker, text, s, e: +(t + 0.25).toFixed(2), words };
68
+ }
69
+ const script: [string, string, number][] = [
70
+ ["Mia", "Rex, look! A kite!", 0.6],
71
+ ["Rex", "Where? I don't see it.", 2.6],
72
+ ["Mia", "Up there, behind you!", 4.6],
73
+ ["Rex", "Sunsets are better anyway.", 7.6],
74
+ ["Mia", "Sure they are.", 9.8],
75
+ ];
76
+ const lines: Line[] = script.map(([who, text, s], i) => timed(who, text, s, i));
77
+
78
+ // ── Staging: what happens, relative to the lines. Places are marks or people, never coordinates. ─
79
+ const staging: Staging = {
80
+ animation: { anticipation: 1, life: 1 },
81
+ camera: { style: "conversation" },
82
+ blocks: [
83
+ {
84
+ id: "park", set: "park", from: 0, to: 3,
85
+ cast: [{ id: "rex", at: "left", facing: "right" }, { id: "mia", at: "right", facing: "left", emotion: "excited" }],
86
+ beats: [
87
+ { line: 0, word: "look", do: "gesture", who: "mia", clip: "pointUp" },
88
+ { line: 0, word: "kite", do: "look", who: "mia", target: "sky" },
89
+ { line: 1, do: "look", who: "rex", target: "behind" },
90
+ { line: 1, do: "fx", type: "question", who: "rex" },
91
+ { line: 2, word: "behind", do: "take", who: "rex", target: "sky", double: true },
92
+ ],
93
+ },
94
+ {
95
+ id: "bench", set: "park", from: 3, to: 5, mood: "evening", transition: "fade",
96
+ // Nothing moves before a block starts: start them by the bench so they are seated on the cut.
97
+ cast: [{ id: "rex", at: "benchL", emotion: "annoyed" }, { id: "mia", at: "benchR", emotion: "smug" }],
98
+ beats: [
99
+ { line: 3, do: "sit", who: "rex", on: "benchL" },
100
+ { line: 3, do: "sit", who: "mia", on: "benchR" },
101
+ { line: 4, word: "sure", do: "fx", type: "sweat", who: "rex" },
102
+ ],
103
+ },
104
+ ],
105
+ };
106
+
107
+ // 1. Check before anything else: errors are mistakes in the staging; warnings say what was changed.
108
+ // `--strict` runs the motion checks on every frame (slower: do it before a final render).
109
+ const issues = check(staging, lines, kit, { strict: process.argv.includes("--strict") });
110
+ for (const i of issues) console.log(`[${i.severity}] ${i.where}: ${i.message}`);
111
+ if (issues.some((i) => i.severity === "error")) process.exit(1);
112
+ console.log(`check: ${issues.length} issue(s), no errors. Kit offers: ${describeKit(kit).actions.length} actions`);
113
+
114
+ // 2. Direct: one continuous scene per block + the sequence that cuts between them.
115
+ const { sequence, scenes } = direct(staging, lines, kit);
116
+
117
+ // 3. Write files the CLI can validate: characters as files, scenes and the sequence pointing at them.
118
+ for (const [id, doc] of Object.entries(characters)) writeJson(join(dir, "characters", `${id}.toon.json`), doc);
119
+ const files: Record<string, SceneDoc> = {};
120
+ for (const [id, scene] of Object.entries(scenes)) {
121
+ const doc = { ...scene, characters: Object.fromEntries(Object.keys(scene.characters).map((c) => [c, `./characters/${c}.toon.json`])) };
122
+ writeJson(join(dir, `${id}.scene.json`), doc);
123
+ files[id] = doc;
124
+ }
125
+ writeJson(join(dir, "episode.sequence.json"), { ...sequence, scenes: Object.fromEntries(Object.keys(sequence.scenes).map((id) => [id, `./${id}.scene.json`])) });
126
+
127
+ // 4. Key frames, on each line. Episode time → (shot, scene time): shots play one after the other
128
+ // (a crossfade would overlap them by its duration; this staging has none), each from its `from`.
129
+ const shotAt = (line: number, dt: number): [SceneDoc, number, string] => {
130
+ const t = lines[line].s + dt;
131
+ let start = 0;
132
+ for (const shot of sequence.shots) {
133
+ if (t < start + shot.duration! || shot === sequence.shots.at(-1)) return [files[shot.scene], (shot.from ?? 0) + t - start, `${shot.scene}: line ${line}`];
134
+ start += shot.duration!;
135
+ }
136
+ throw new Error("unreachable");
137
+ };
138
+ console.log("shots:", JSON.stringify(sequence.shots));
139
+ await contactSheet(
140
+ [shotAt(0, 0.5), shotAt(1, 0.5), shotAt(2, 1.0), shotAt(3, 0.4), shotAt(4, 0.3), shotAt(4, 1.0)],
141
+ characters,
142
+ join(dir, "sheet.png"),
143
+ );
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Helpers shared by the examples: write documents, render a contact sheet of key frames.
3
+ * Not an example on its own (imported by short.ts and director.ts).
4
+ *
5
+ * Needs `rsvg-convert` (librsvg) and `magick` (ImageMagick) on PATH for the contact sheet.
6
+ */
7
+ import { execFileSync } from "node:child_process";
8
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+ import { type SceneDoc, type ToonDoc, evaluateScene, frameToSVG } from "@anime-studio/core";
11
+ import { prepareScene } from "@anime-studio/rigid";
12
+
13
+ export const OUT = join(import.meta.dirname, "out");
14
+ const FONTS = ["/System/Library/Fonts/Supplemental/Arial.ttf", "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", "C:/Windows/Fonts/arial.ttf"];
15
+
16
+ export function writeJson(path: string, data: unknown): string {
17
+ mkdirSync(dirname(path), { recursive: true });
18
+ writeFileSync(path, JSON.stringify(data, null, 2) + "\n");
19
+ console.log("wrote", path);
20
+ return path;
21
+ }
22
+
23
+ /**
24
+ * Renders `picks` ([scene, time, label]) to PNGs and tiles them 3 per row into `out`.
25
+ * The scene docs are evaluated in memory with the given character docs.
26
+ */
27
+ export async function contactSheet(
28
+ picks: [SceneDoc, number, string][],
29
+ characters: Record<string, ToonDoc>,
30
+ out: string,
31
+ ): Promise<string> {
32
+ const work = join(dirname(out), "frames");
33
+ mkdirSync(work, { recursive: true });
34
+ const compiled = new Map<SceneDoc, Awaited<ReturnType<typeof prepareScene>>>();
35
+ const files: string[] = [];
36
+ for (const [i, [doc, t, label]] of picks.entries()) {
37
+ if (!compiled.has(doc)) compiled.set(doc, await prepareScene(doc, { characters }));
38
+ const svg = join(work, `k${i}.svg`);
39
+ const png = join(work, `k${i}.png`);
40
+ writeFileSync(svg, frameToSVG(evaluateScene(compiled.get(doc)!, t)));
41
+ execFileSync("rsvg-convert", ["-w", "640", "-o", png, svg]);
42
+ // Label each frame with its time and beat, so the sheet reads like a storyboard (skipped when
43
+ // ImageMagick has no usable font).
44
+ const font = FONTS.find((f) => existsSync(f));
45
+ if (font) execFileSync("magick", [png, "-font", font, "-gravity", "south", "-background", "#222", "-fill", "white", "-pointsize", "18", "-splice", "0x28", "-annotate", "+0+4", `${t.toFixed(2)} s ${label}`, png]);
46
+ files.push(png);
47
+ }
48
+ // Rows of three, then the rows stacked (plain append: no font needed, unlike `montage`).
49
+ const rows: string[] = [];
50
+ for (let i = 0; i < files.length; i += 3) {
51
+ const row = join(work, `row${i}.png`);
52
+ execFileSync("magick", [...files.slice(i, i + 3), "-background", "#111", "+append", row]);
53
+ rows.push(row);
54
+ }
55
+ execFileSync("magick", [...rows, "-background", "#111", "-append", out]);
56
+ console.log("wrote", out);
57
+ return out;
58
+ }
@@ -0,0 +1,193 @@
1
+ /**
2
+ * A ~10 s two-character gag written by hand: script → scenes → sequence, with one spoken line lip
3
+ * synced from its text alone (no audio file needed).
4
+ *
5
+ * npx tsx skills/animestudio-script/examples/short.ts
6
+ *
7
+ * Writes out/short/{characters/*.toon.json, title.scene.json, street.scene.json,
8
+ * short.sequence.json, sheet.png}. Validate with:
9
+ *
10
+ * npx tsx packages/cli/src/bin.ts validate skills/animestudio-script/examples/out/short/*.json
11
+ * npx tsx packages/cli/src/bin.ts debug skills/animestudio-script/examples/out/short/street.scene.json
12
+ * npx tsx packages/cli/src/bin.ts debug skills/animestudio-script/examples/out/short/short.sequence.json
13
+ *
14
+ * ─────────────────────────────────────────────────────────────────────────────────────────────
15
+ * THE SCRIPT (written first, before any JSON)
16
+ *
17
+ * Title: "Hey!"
18
+ * Logline: A guy tries three times to get his friend's attention; the third time he gets it.
19
+ * Format: 16:9 short, ~10.5 s, two characters, one location, one line of dialogue.
20
+ *
21
+ * Beats (anticipation → action → reaction; the rule of three):
22
+ * 1. SET-UP Rex walks in. Mia stands with her back to him, watching birds.
23
+ * 2. TRY 1 Rex waves. Nothing. (establish the pattern)
24
+ * 3. TRY 2 Rex waves BIGGER, both arms. Nothing. (escalate the pattern)
25
+ * 4. RESOLVE Close on Rex: annoyed → determined. (the anticipation of the payoff)
26
+ * 5. TRY 3 He runs at her… and trips flat on his face. (break the pattern: the gag)
27
+ * 6. REACTION Mia turns, surprised, then beams: "Oh! Hi, Rex!" (the reaction sells it)
28
+ * 7. BUTTON Stars over Rex's head. Iris out on him.
29
+ *
30
+ * Shot list (shot = one camera set-up; cuts inside one continuous scene keep positions intact):
31
+ * # scene time camera action
32
+ * 1 title 0.0–1.6 card "HEY!" title
33
+ * 2 street 0.0–4.4 wide beats 1–3
34
+ * 3 street 4.4–5.6 close on Rex beat 4 (a camera cut, same scene)
35
+ * 4 street 5.6–6.95 wide beat 5 and the take
36
+ * 5 street 6.95–10.0 medium two-shot the line, the button, iris out on Rex
37
+ *
38
+ * Staging notes: Rex enters left and moves right all along (screen direction never flips); Mia
39
+ * faces right (away from him) until the fall, then turns left to face him; one action per beat,
40
+ * each held long enough to read (≥ 0.8 s); the line starts ~0.3 s after her surprise take.
41
+ * ─────────────────────────────────────────────────────────────────────────────────────────────
42
+ */
43
+ import { join } from "node:path";
44
+ import type { ActionDef, SceneDoc, SequenceDoc, ToonDoc } from "@anime-studio/core";
45
+ import { type CartoonLook, cartoonCharacter } from "@anime-studio/kit";
46
+ import { OUT, contactSheet, writeJson } from "./sheet";
47
+
48
+ const dir = join(OUT, "short");
49
+ const W = 1920, H = 1080, FPS = 30, GROUND = 900;
50
+
51
+ // Cast: two original characters built by the kit from a short look (see animestudio-characters).
52
+ const LOOKS: Record<string, CartoonLook> = {
53
+ rex: { name: "Rex", build: "man", skin: "#e9b48f", hair: "sidePart", hairColor: "#3a2a20", top: "shirt", topColor: "#4f86c6", bottom: "pants", bottomColor: "#333a4a", shoes: "sneakers", shoeColor: "#eeeeee" },
54
+ mia: { name: "Mia", build: "woman", female: true, skin: "#b07850", hair: "ponytail", hairColor: "#20150f", top: "tee", topColor: "#ff7a59", bottom: "skirt", bottomColor: "#2f6f6a", shoes: "sneakers", shoeColor: "#ffffff" },
55
+ };
56
+ const characters: Record<string, ToonDoc> = Object.fromEntries(Object.entries(LOOKS).map(([id, look]) => [id, cartoonCharacter(look)]));
57
+ for (const [id, doc] of Object.entries(characters)) writeJson(join(dir, "characters", `${id}.toon.json`), doc);
58
+ const charPaths = { rex: "./characters/rex.toon.json", mia: "./characters/mia.toon.json" };
59
+
60
+ // Tiny helpers: every action is still plain JSON (FORMAT §3.3).
61
+ const play = (at: number, actor: string, clip: string, o: object = {}) => ({ at, actor, action: "play", clip, ...o });
62
+ const emo = (at: number, actor: string, value: string, duration = 0.3) => ({ at, actor, action: "pose", control: "emotion", value, duration });
63
+ const fx = (at: number, type: string, o: object = {}) => ({ at, action: "fx", type, ...o });
64
+
65
+ // ── Scene 1: the title card ───────────────────────────────────────────────────────────────────
66
+ const TITLE = 1.6;
67
+ const title: SceneDoc = {
68
+ format: "toon-scene", version: 1, width: W, height: H, fps: FPS, duration: TITLE, background: "#ffd166",
69
+ characters: {},
70
+ script: [
71
+ fx(0.1, "caption", { text: "HEY!", style: "title", duration: 1.4 }),
72
+ fx(0.3, "sparkle", { x: 1250, y: 420 }),
73
+ ] as ActionDef[],
74
+ };
75
+
76
+ // ── Scene 2: the street — one continuous scene for the whole location ─────────────────────────
77
+ // Times are scene seconds. Name the beats so a re-time is one edit.
78
+ const T = {
79
+ try1: 1.8, // first wave
80
+ try2: 3.0, // bigger wave
81
+ close: 4.4, // cut in on Rex
82
+ wide: 5.6, // cut back out
83
+ trip: 6.05, // the fall (while running)
84
+ take: 6.75, // Mia's surprise
85
+ line: 7.1, // "Oh! Hi, Rex!"
86
+ end: 10.0,
87
+ };
88
+ const LINE_TEXT = "Oh! Hi, Rex!";
89
+ const LINE_DUR = 1.1;
90
+
91
+ const street: SceneDoc = {
92
+ format: "toon-scene", version: 1, width: W, height: H, fps: FPS, duration: T.end, background: "#bfe6f7",
93
+ characters: charPaths,
94
+ camera: { x: W / 2, y: H / 2, zoom: 1 },
95
+ layers: [
96
+ { id: "sky", parallax: 0, z: -100, art: `<rect x="-200" y="-200" width="${W + 400}" height="${H + 400}" fill="#bfe6f7"/>` },
97
+ { id: "houses", parallax: 0.6, z: -80, art: `<g stroke="#2a2a35" stroke-width="3"><rect x="-200" y="430" width="520" height="440" fill="#f3d9a4"/><rect x="380" y="380" width="460" height="490" fill="#e8a0a0"/><rect x="900" y="450" width="500" height="420" fill="#a8d0b8"/><rect x="1460" y="400" width="700" height="470" fill="#c9b8e8"/></g>` },
98
+ { id: "street", z: -60, art: `<rect x="-600" y="${GROUND - 20}" width="${W + 1200}" height="420" fill="#9aa0a8"/><rect x="-600" y="${GROUND - 30}" width="${W + 1200}" height="16" fill="#d8d8d8"/>` },
99
+ ],
100
+ actors: [
101
+ { id: "rex", character: "rex", x: -200, y: GROUND, scale: 0.95 },
102
+ { id: "mia", character: "mia", x: 1640, y: GROUND, scale: 0.95 },
103
+ ],
104
+ script: [
105
+ // Never frozen: a looping base clip on layer -1 under everything.
106
+ play(0, "rex", "idle", { loop: true, layer: -1, fadeIn: 0 }),
107
+ play(0, "mia", "idle", { loop: true, layer: -1, fadeIn: 0 }),
108
+ // Every changing channel gets a value at t = 0 (tracks hold their first key before it).
109
+ emo(0, "rex", "happy", 0), emo(0, "mia", "calm", 0),
110
+ // Her back to him: the "away" view (looking off right, the face hidden) reads as "not noticing".
111
+ { at: 0, actor: "mia", action: "pose", control: "view", value: "away", duration: 0 },
112
+ { at: 0, actor: "mia", action: "lookAt", target: [2100, 420] }, // watching birds, off right
113
+ { at: 0, actor: "rex", action: "lookAt", target: "mia" },
114
+ fx(0.2, "birds", { x: 1700, y: 300 }),
115
+
116
+ // 1. SET-UP — Rex walks in from the left.
117
+ { at: 0, actor: "rex", action: "walkTo", x: 620, duration: 1.6 },
118
+
119
+ // 2. TRY 1 — a wave (gesture starts a touch before the beat; fades in/out).
120
+ play(T.try1, "rex", "wave", { duration: 1.0, fadeIn: 0.15, fadeOut: 0.2 }),
121
+
122
+ // 3. TRY 2 — bigger: both arms, plus a cartoon accent.
123
+ emo(T.try2 - 0.1, "rex", "excited", 0.25),
124
+ play(T.try2, "rex", "cheer", { duration: 1.1, fadeIn: 0.12, fadeOut: 0.2 }),
125
+ fx(T.try2 + 0.05, "exclaim", { actor: "rex" }),
126
+ fx(T.try2 + 0.6, "sweat", { actor: "rex" }),
127
+
128
+ // 4. RESOLVE — a camera cut (duration 0) in the same scene: positions stay continuous.
129
+ { at: T.close, action: "camera", x: 640, y: 500, zoom: 2.3, duration: 0 },
130
+ emo(T.close, "rex", "annoyed", 0),
131
+ emo(T.close + 0.55, "rex", "determined", 0.2),
132
+ fx(T.close + 0.6, "anger", { actor: "rex" }),
133
+ { at: T.wide, action: "camera", x: W / 2, y: H / 2, zoom: 1, duration: 0 },
134
+ // Cut to a medium two-shot for the line: the mouth must be big enough to read.
135
+ { at: T.line - 0.15, action: "camera", x: 1400, y: 640, zoom: 1.7, duration: 0 },
136
+
137
+ // 5. TRY 3 — a run, then a trip mid-run (fall takes over the walk; the body carries its speed).
138
+ { at: T.wide, actor: "rex", action: "walkTo", x: 950, clip: "run", duration: 0.7 },
139
+ fx(T.wide + 0.02, "dust", { actor: "rex", anchor: "origin" }),
140
+ { at: T.trip, actor: "rex", action: "fall", side: "front" },
141
+ emo(T.trip, "rex", "scared", 0.08),
142
+ fx(T.trip + 0.4, "impact", { actor: "rex", anchor: "origin" }),
143
+ { at: T.trip + 0.4, action: "shake", duration: 0.3, amount: 8 },
144
+
145
+ // 6. REACTION — anticipation (the take) → action (turn) → reaction (the line).
146
+ fx(T.take - 0.05, "surprise", { actor: "mia" }),
147
+ emo(T.take, "mia", "surprised", 0.1),
148
+ // Turn round to him: back to the three-quarter view, facing left (a view change with a
149
+ // duration steps through the in-between drawings).
150
+ { at: T.take, actor: "mia", action: "face", direction: "left" },
151
+ { at: T.take, actor: "mia", action: "pose", control: "view", value: "profile", duration: 0.2 },
152
+ { at: T.take, actor: "mia", action: "lookAt", target: "rex" },
153
+ // The line: text-only lip sync (visemes spread over `duration`), emotion just before it.
154
+ emo(T.line - 0.05, "mia", "happy", 0.3),
155
+ { at: T.line, actor: "mia", action: "say", text: LINE_TEXT, duration: LINE_DUR },
156
+ play(T.line + 0.3, "mia", "wave", { duration: 1.1, fadeIn: 0.2, fadeOut: 0.3 }),
157
+
158
+ // 7. BUTTON — dizzy stars, hold, iris out on the loser of the gag.
159
+ fx(T.trip + 1.0, "stars", { actor: "rex", duration: 2.4 }),
160
+ { at: T.end - 0.9, action: "transition", type: "iris", mode: "out", duration: 0.8, target: "rex" },
161
+ ] as ActionDef[],
162
+ };
163
+
164
+ // ── The sequence: shots in order, transitions between them (FORMAT §4) ─────────────────────────
165
+ const sequence: SequenceDoc = {
166
+ format: "toon-sequence", version: 1, width: W, height: H, fps: FPS,
167
+ scenes: { title: "./title.scene.json", street: "./street.scene.json" },
168
+ shots: [
169
+ { scene: "title" },
170
+ { scene: "street", transition: { type: "wipe", duration: 0.4, color: "#ffd166", direction: "right" } },
171
+ ],
172
+ };
173
+
174
+ writeJson(join(dir, "title.scene.json"), title);
175
+ writeJson(join(dir, "street.scene.json"), street);
176
+ writeJson(join(dir, "short.sequence.json"), sequence);
177
+
178
+ // A storyboard check: one frame per beat. Look at it — the gag must read without sound.
179
+ await contactSheet(
180
+ [
181
+ [title, 0.8, "title"],
182
+ [street, 1.0, "1 set-up"],
183
+ [street, T.try1 + 0.4, "2 try 1"],
184
+ [street, T.try2 + 0.45, "3 try 2"],
185
+ [street, T.close + 0.9, "4 resolve (close)"],
186
+ [street, T.trip + 0.2, "5 trip"],
187
+ [street, T.take + 0.15, "6 take"],
188
+ [street, T.line + 0.75, "6 line (mouth open on \"Rex\")"],
189
+ [street, T.end - 0.5, "7 iris out"],
190
+ ],
191
+ characters,
192
+ join(dir, "sheet.png"),
193
+ );