@anime-studio/cli 0.2.0 → 0.3.0

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 (82) hide show
  1. package/dist/bin.js +74 -2
  2. package/dist/bin.js.map +1 -1
  3. package/dist/doctor.d.ts +8 -1
  4. package/dist/doctor.d.ts.map +1 -1
  5. package/dist/doctor.js +30 -5
  6. package/dist/doctor.js.map +1 -1
  7. package/dist/index.d.ts +6 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +6 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/mix.d.ts +21 -0
  12. package/dist/mix.d.ts.map +1 -0
  13. package/dist/mix.js +95 -0
  14. package/dist/mix.js.map +1 -0
  15. package/dist/raster.d.ts +63 -0
  16. package/dist/raster.d.ts.map +1 -0
  17. package/dist/raster.js +145 -0
  18. package/dist/raster.js.map +1 -0
  19. package/dist/render-worker.d.ts +27 -0
  20. package/dist/render-worker.d.ts.map +1 -0
  21. package/dist/render-worker.js +33 -0
  22. package/dist/render-worker.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/dist/video.d.ts +64 -0
  28. package/dist/video.d.ts.map +1 -0
  29. package/dist/video.js +221 -0
  30. package/dist/video.js.map +1 -0
  31. package/package.json +7 -5
  32. package/skills/animestudio/SKILL.md +168 -0
  33. package/skills/animestudio/examples/first-frame.ts +54 -0
  34. package/skills/animestudio/examples/hello.scene.json +50 -0
  35. package/skills/animestudio/examples/hello.sequence.json +13 -0
  36. package/skills/animestudio/examples/remotion/Root.tsx +25 -0
  37. package/skills/animestudio/examples/remotion/index.ts +5 -0
  38. package/skills/animestudio/examples/render-video.ts +110 -0
  39. package/skills/animestudio/references/packages.md +54 -0
  40. package/skills/animestudio/references/rendering.md +148 -0
  41. package/skills/animestudio/references/scene-format.md +101 -0
  42. package/skills/animestudio/references/validation-and-debugging.md +66 -0
  43. package/skills/animestudio-animation/SKILL.md +177 -0
  44. package/skills/animestudio-animation/examples/gestures.ts +55 -0
  45. package/skills/animestudio-animation/examples/hold.ts +82 -0
  46. package/skills/animestudio-animation/examples/knockdown.ts +68 -0
  47. package/skills/animestudio-animation/examples/sheet.ts +80 -0
  48. package/skills/animestudio-animation/examples/walk-wave-run.ts +59 -0
  49. package/skills/animestudio-animation/references/clips.md +103 -0
  50. package/skills/animestudio-animation/references/director-beats.md +48 -0
  51. package/skills/animestudio-animation/references/holding.md +106 -0
  52. package/skills/animestudio-animation/references/locomotion.md +86 -0
  53. package/skills/animestudio-animation/references/timing.md +89 -0
  54. package/skills/animestudio-characters/SKILL.md +211 -0
  55. package/skills/animestudio-characters/examples/cast.ts +63 -0
  56. package/skills/animestudio-characters/examples/human.ts +52 -0
  57. package/skills/animestudio-characters/examples/import-svg.ts +68 -0
  58. package/skills/animestudio-characters/examples/lumo.svg +36 -0
  59. package/skills/animestudio-characters/examples/sprout.toon.json +116 -0
  60. package/skills/animestudio-characters/examples/sprout.ts +48 -0
  61. package/skills/animestudio-characters/examples/turnaround.ts +91 -0
  62. package/skills/animestudio-characters/references/custom-rig.md +139 -0
  63. package/skills/animestudio-characters/references/import-svg.md +59 -0
  64. package/skills/animestudio-characters/references/look-options.md +143 -0
  65. package/skills/animestudio-characters/references/rig-surface.md +62 -0
  66. package/skills/animestudio-script/SKILL.md +164 -0
  67. package/skills/animestudio-script/examples/director.ts +143 -0
  68. package/skills/animestudio-script/examples/sheet.ts +58 -0
  69. package/skills/animestudio-script/examples/short.ts +193 -0
  70. package/skills/animestudio-script/references/actions.md +84 -0
  71. package/skills/animestudio-script/references/dialogue-lipsync.md +87 -0
  72. package/skills/animestudio-script/references/director.md +110 -0
  73. package/skills/animestudio-script/references/shots-and-editing.md +79 -0
  74. package/skills/animestudio-script/references/writing-for-animation.md +84 -0
  75. package/skills/animestudio-sets/SKILL.md +232 -0
  76. package/skills/animestudio-sets/examples/hillside.scene.json +93 -0
  77. package/skills/animestudio-sets/examples/render-scene.ts +35 -0
  78. package/skills/animestudio-sets/examples/sets.ts +257 -0
  79. package/skills/animestudio-sets/references/drawing-sets.md +119 -0
  80. package/skills/animestudio-sets/references/fx.md +93 -0
  81. package/skills/animestudio-sets/references/lighting-camera.md +93 -0
  82. package/skills/animestudio-sets/references/scene-fields.md +132 -0
@@ -0,0 +1,211 @@
1
+ ---
2
+ name: animestudio-characters
3
+ description: Design and build characters (personagens) for the animeStudio animation engine — a cast from cartoonCharacter(look) or humanCharacter in @anime-studio/kit, a hand-written *.toon.json rig (skeleton, parts, controls, clips), or an SVG drawing imported with import-svg — and check them with a turnaround line-up sheet across views and emotions. Use it whenever you create, restyle, review or debug a character, cast, look, rig, emotions or turnaround for animeStudio.
4
+ ---
5
+
6
+ # animeStudio characters
7
+
8
+ A character is a `*.toon.json` document (`format: "toon"`): palette, art, skeleton, parts, anchors,
9
+ IK, physics, controls, behaviours and clips. Scenes and the director only talk to it through its
10
+ **controls** (`view`, `emotion`, `mouth`, `look`…), **clips** and **anchors**, so a character is done
11
+ when those exist, validate, and look right from every angle you will film it.
12
+
13
+ Pick the path:
14
+
15
+ | You need | Path | Effort |
16
+ |---|---|---|
17
+ | A human for a TV-cartoon series (sitcom, family, school, office) | `cartoonCharacter(look)` | minutes |
18
+ | An anime-style hero/villain (spiky hair, capes, glowing eyes), profile + front only | `humanCharacter(look)` | minutes |
19
+ | An animal, creature, object, or a style the kit cannot make | hand-written `*.toon.json` | hours |
20
+ | A character someone already drew | SVG → `importSvg` / `toon import-svg`, then add controls | an hour |
21
+
22
+ Never invent field values, hair names, clip or emotion names: they are closed sets (see
23
+ `references/look-options.md`, `references/rig-surface.md`) and `toon describe` lists what a built
24
+ character really has.
25
+
26
+ ## 1. The fast path: `cartoonCharacter`
27
+
28
+ ```ts
29
+ import { cartoonCharacter, cartoonInfo, type CartoonLook } from "@anime-studio/kit";
30
+
31
+ const rosa: CartoonLook = {
32
+ name: "Rosa", build: "woman", female: true, tall: 1.05, skin: "#d9a07a",
33
+ hair: "bob", hairColor: "#1c1a2e",
34
+ top: "blazer", topColor: "#f3efe6", top2: "#2f7f8f", // blazer: top2 = jacket, topColor = shirt
35
+ bottom: "skirt", bottomColor: "#22414a", shoes: "heels", shoeColor: "#c0392b",
36
+ earrings: true, lipstick: "#b8343c",
37
+ };
38
+ const doc = cartoonCharacter(rosa); // style "modern" by default
39
+ const info = cartoonInfo(doc, rosa); // height, extent, depth… for staging
40
+ ```
41
+
42
+ Required: `name`, `build`, `skin`, `hair`, `hairColor`, `top`, `topColor`, `bottom`, `bottomColor`,
43
+ `shoes`. Everything else is optional. The value sets, in short (full tables with notes in
44
+ [references/look-options.md](references/look-options.md) — read it before writing a look):
45
+
46
+ - `build`: baby child kid teen woman man big elder · `heavy` 0..1 · `tall` × · `female` · `limbs` thin|normal|thick
47
+ - `hair`: bowl sidePart afro puffs ponytail long perm mullet buzz bald bun braids rollers tuft receding slick bob curtains spiky
48
+ - `jaw`: round square pointy chubby · `nose`: button round long wide
49
+ - `top`: tee stripes polo shirt tank jersey blouse dress overalls jacket cardigan blazer · `top2` · `pattern`: stripes pinstripes checks polka (+ `stripe`, `stripeWidth`)
50
+ - `bottom`: pants shorts bermuda skirt longSkirt · `shoes`: sneakers studded canvas flipflops dress heels sandals (+ `shoeColor`, `socks`)
51
+ - accessories: `hat` (cap capBack flatCap top bowler cowboy, + `hatColor`), `glasses` (true | "sun"), `tie`, `sweater`, `necklace` {kind: pearls|chain}, `suspenders`, `watch`, `apron`, `pocketItem`, `earItem` (pencil|cigarette), `earrings`, `accent`, `cape`, `veil`, `boutonniere`
52
+ - face: `moustache` `goatee` `freckles` `wrinkles` `stubble` `flushed` `lipstick` `hairLine`
53
+
54
+ Traps the types do not show:
55
+
56
+ - `jacket` / `cardigan` / `blazer`: **`top2` is the jacket and its sleeves**, `topColor` the shirt
57
+ in the opening. `overalls`: the bib is `bottomColor`, `topColor` is the shirt under it.
58
+ - `pattern` prints the torso only: a `dress` with a pattern has a plain skirt. An `apron` ends at
59
+ the waist. Prefer `blouse` + `skirt`/`longSkirt` for a printed outfit.
60
+ - `look.limbs` (thickness) is not `CartoonStyle.limbs` (tapered | tube).
61
+ - Anything that belongs to one series (props, sets, names) stays in the series, never in the kit.
62
+
63
+ ### Styles
64
+
65
+ `cartoonCharacter(look, { style })`:
66
+
67
+ - `"modern"` (default): natural TV-cartoon figure about five heads tall, big round eyes with dot
68
+ pupils, one thin even ink line, flat colours. Emotions here are subtle (brows and mouth): pair
69
+ them with a gesture clip or an `fx` when they must read at a distance.
70
+ - `"painted"`: the look's own proportions, lines in a dark tone of each colour, cel shadows, fists.
71
+ - `"flat"`: one near-black ink, one line weight, no shadows, tube arms, open hands, bigger heads.
72
+ - a `CartoonStyle` object `{ ink, shade, line, limbs, hands, eyes, posture, proportions, blush }`
73
+ refining `painted` (e.g. `{ proportions: "cartoon", eyes: "big", blush: true }`).
74
+
75
+ Use one style for the whole cast. `pitch` (degrees) matches a room camera looking down.
76
+
77
+ ### What the built rig gives you
78
+
79
+ Twelve drawn views on one 2.5D skeleton (`front half q24 profile q50 q64 q77 side q112 away q158
80
+ back`; `profile` = three-quarter facing right is the main one), a `head` control that turns the
81
+ head on its own (`~q50` = mirrored), 15 emotions, a `jaw` gape, a viseme mouth, ~45 clips including
82
+ personality walks (`sneak strut tired march scaredRun`), anchors `head face top eye ear earB mouth
83
+ hand handB fist`, springs on forearms, head, ponytail and big hair. Exact lists:
84
+ [references/rig-surface.md](references/rig-surface.md) (read it when scripting the character).
85
+ Facing left is the actor's `flip`, not a view.
86
+
87
+ ### Tune the anatomy (never hack the drawing code)
88
+
89
+ Body and face proportions live in one editable document. Start from the **styled** anatomy, or the
90
+ style's proportions are lost:
91
+
92
+ ```ts
93
+ import { cartoonAnatomy, styledAnatomy, checkAnatomy, cartoonCharacter } from "@anime-studio/kit";
94
+ const a = structuredClone(styledAnatomy(cartoonAnatomy(look), "modern", look));
95
+ a.body.head *= 1.15; // bigger head
96
+ console.log(checkAnatomy(a)); // [] or { severity, rule, message } per broken rule
97
+ const doc = cartoonCharacter(look, { style: "modern", anatomy: a }); // throws on errors
98
+ ```
99
+
100
+ `body` (hip, torso, neck, head, shoulders, waist, hips, depth, arm), `limbs`, `face` (in head
101
+ radii: eyeY, eyeX, eye, pupil, brow, noseY, nose, mouthY, mouthW…), `physics`. Per-view mouth
102
+ problems that were auto-corrected are listed in `doc.meta.anatomyIssues`.
103
+
104
+ ## 2. `humanCharacter` (anime-style)
105
+
106
+ ```ts
107
+ import { humanCharacter } from "@anime-studio/kit";
108
+ const hiro = humanCharacter({ name: "Hiro", skin: "#f1c7a3", hair: "spiky", hairColor: "#2a2f6b",
109
+ iris: "#3b8fd9", outfit: "hoodie", top: "#e2543a", pants: "#2c2f3a", shoes: "#f2f2f2", scarf: "#f2c14e" });
110
+ ```
111
+
112
+ `hair`: spiky mane messy ponytail cap short curly hood · `outfit`: tee hoodie gi coat armor · plus
113
+ `hairTip`, `topDark`, `accent`, `glasses`, `glow` (villain eyes), `headband`, `scarf`, `cape`,
114
+ `bulk`. Views are `profile` and `front` only (no back). It lacks the cartoon's prop clips
115
+ (`texting`, `carry`, `gamepad`…) and the `annoyed` / `gape` emotions. Run `examples/human.ts`.
116
+
117
+ ## 3. Design a cast that reads
118
+
119
+ Do this before writing looks, then verify on the sheet:
120
+
121
+ 1. **Silhouette first.** Fill every character black in your head: each must be recognisable.
122
+ Vary `build`, `tall`, `heavy` and above all the hair mass (`afro`, `perm`, `puffs`, `bun`,
123
+ `spiky` vs `buzz`, `bob`, `bald`) and hats. No two characters share build + hair outline.
124
+ 2. **One dominant hue per character**, spread round the colour wheel, with a value contrast
125
+ between top and bottom. Avoid neighbours in the same hue and skin-coloured clothes.
126
+ 3. **One signature detail** each (glasses, a cap, pearls, heels, a moustache): it carries the
127
+ identity at thumbnail size and survives the back view.
128
+ 4. **Contrast in pairs.** The characters who share most scenes should differ most (tall/short,
129
+ round/angular, warm/cool).
130
+ 5. **Readable small.** Faces are tiny in wide shots; identity must come from shape and colour.
131
+ 6. Give the face what the personality needs (`jaw`, `nose`, `wrinkles`, `freckles`, `stubble`):
132
+ these show in close-ups, not in the line-up.
133
+
134
+ ## 4. Check it: render the sheet and LOOK
135
+
136
+ ```bash
137
+ npx tsx skills/animestudio-characters/examples/cast.ts # writes out/<id>.toon.json, prints sizes
138
+ npx tsx skills/animestudio-characters/examples/turnaround.ts # [style] [views|all]
139
+ ```
140
+
141
+ Then open with your image viewer (the Read tool for agents) `out/lineup.png`, `out/lineup-small.png`
142
+ (360 px wide), every `out/turn-<id>.png` and `out/emotions.png`. Check:
143
+
144
+ - each character is identifiable in `lineup-small.png`; heights and widths differ;
145
+ - the views agree (hair, hat, glasses, prints hold from `front` to `back`; the back view still says
146
+ who it is);
147
+ - emotions differ in the zoomed rows; colours do not clash with the set you will use;
148
+ - no anatomy issues printed by `cast.ts`; then `toon validate` and `toon describe` each file.
149
+
150
+ How the sheet works: one scene with one actor per cell, each playing `idle` on `layer: -1` and set
151
+ instantly (`duration: 0`) to a `view` and an `emotion`, evaluated at one time with
152
+ `prepareScene` + `evaluateScene`, `frameToSVG`, then `rsvg-convert` and `magick -append`. Zoomed
153
+ rows use a camera `zoom` with the actors spaced by `cellW / zoom`. Copy it for clips (`play` a clip
154
+ and pick the time) or for a new cast.
155
+
156
+ ## 5. The custom path: a hand-written `*.toon.json`
157
+
158
+ Read [references/custom-rig.md](references/custom-rig.md) first, then FORMAT
159
+ [§2](https://github.com/denerFernandes/animeStudio/blob/master/docs/FORMAT.md#2-character-document-toonjson)
160
+ and AI_GUIDE ["Writing characters"](https://github.com/denerFernandes/animeStudio/blob/master/docs/AI_GUIDE.md#writing-characters).
161
+ Start from `examples/sprout.toon.json` (a complete small creature) and check it with
162
+ `examples/sprout.ts`. The essentials:
163
+
164
+ - Setup space: ground at y = 0, facing right, y down, degrees clockwise; bones in setup form
165
+ (`from` / `to`), parents first; slight knee bend at rest.
166
+ - Parts in draw order: `rigid`, `switch` (eyes, hands, views), `morph` (mouth `A`–`H` + `smile` /
167
+ `frown`, every shape the same command structure), `hose` (limbs), `skinned`, `hull`.
168
+ - `palette(name)` for every colour; anchors `head`, `hand`, `handB`.
169
+ - Controls named `mouth` (viseme), `look` (aim; a head drawn pointing up takes `forward: 90`),
170
+ `emotion` (pose); behaviours `blink` + `breathe`; springs on ears, tails, leaves.
171
+ - Clips: `idle` (loop, same first and last values) at least; `stride` on walks.
172
+
173
+ ## 6. Importing an SVG drawing
174
+
175
+ Name the layers (`bone:neck1@root`, `part:head@shade`, `switch:eyes/open@shade`,
176
+ `skin:neck@neck1,neck2`, `anchor:head@shade`, `origin`) and run
177
+ `toon import-svg drawing.svg --name lumo -o lumo.toon.json` or `importSvg(svg, { name })`. You get a
178
+ skeleton, parts and anchors, no controls or clips: add those as in section 5. Details and drawing
179
+ rules: [references/import-svg.md](references/import-svg.md); example: `examples/import-svg.ts`.
180
+
181
+ ## 7. Know what a character can do: `toon describe`
182
+
183
+ ```bash
184
+ npx tsx packages/cli/src/bin.ts describe skills/animestudio-characters/examples/out/rosa.toon.json
185
+ # in a project: npx @anime-studio/cli describe rosa.toon.json
186
+ ```
187
+
188
+ It lists the controls with their values, clips (duration, loop, stride), anchors and every channel.
189
+ Paste it into the prompt of whoever writes the scene; `validate` before every hand-off.
190
+
191
+ ## Hands and props
192
+
193
+ Props in the hands (phones, books, boxes) use the kit's `HOLD` presets, `holdFit`, `holdBoth`,
194
+ `boxFit` and the scene's `grab` — that is scene work: see the `animestudio-animation` skill and
195
+ FORMAT [§2.6](https://github.com/denerFernandes/animeStudio/blob/master/docs/FORMAT.md#26-anchors).
196
+ For a custom rig, give each hand a `switch` with `open`, `fist`, `point`, `grip` variants and a
197
+ `hand` / `handB` anchor so grabs work.
198
+
199
+ ## Examples in this skill
200
+
201
+ All run from the repo root with `npx tsx skills/animestudio-characters/examples/<file>.ts` and write
202
+ only to `skills/animestudio-characters/examples/out/`. `rsvg-convert` is required for PNGs,
203
+ ImageMagick `magick` is optional.
204
+
205
+ | File | Shows |
206
+ |---|---|
207
+ | `cast.ts` | four contrasting original characters (`LOOKS`), written as `.toon.json` with measurements |
208
+ | `turnaround.ts` | the line-up, small line-up, per-character turnaround and zoomed emotion sheets |
209
+ | `human.ts` | `humanCharacter`: views, emotions and clips listed, a strip rendered |
210
+ | `sprout.toon.json` + `sprout.ts` | a complete hand-written rig, validated and rendered (emotions, wave, hop, a viseme) |
211
+ | `lumo.svg` + `import-svg.ts` | a named SVG drawing imported, completed with controls and clips, rendered |
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A small original cast built with the fast path, `cartoonCharacter(look)`.
3
+ *
4
+ * Run from the repo root: npx tsx skills/animestudio-characters/examples/cast.ts [style]
5
+ * (style: modern — the default —, painted or flat). Writes one `<id>.toon.json` per character to
6
+ * skills/animestudio-characters/examples/out/ and prints each one's measurements and anatomy issues.
7
+ *
8
+ * The cast is designed for contrast: four heights and builds, four hair silhouettes, one dominant
9
+ * hue each (teal, green, red, orange), and one signature accessory each (heels, glasses, cap, pearls),
10
+ * so every character reads at thumbnail size and in a crowd.
11
+ */
12
+ import { mkdirSync, writeFileSync } from "node:fs";
13
+ import { dirname, join } from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ import type { ToonDoc } from "@anime-studio/core";
16
+ import { type CartoonLook, type CartoonOptions, cartoonCharacter, cartoonInfo } from "@anime-studio/kit";
17
+
18
+ export const LOOKS: Record<string, CartoonLook> = {
19
+ // Tall, slim, sharp: a bob, a blazer and heels. Teal + a red accent.
20
+ // (jacket / cardigan / blazer: `top2` is the jacket and its sleeves, `topColor` the shirt in the opening.)
21
+ rosa: {
22
+ name: "Rosa", build: "woman", female: true, tall: 1.05, skin: "#d9a07a", hair: "bob", hairColor: "#1c1a2e",
23
+ top: "blazer", topColor: "#f3efe6", top2: "#2f7f8f", bottom: "skirt", bottomColor: "#22414a",
24
+ shoes: "heels", shoeColor: "#c0392b", earrings: true, lipstick: "#b8343c", nose: "button",
25
+ },
26
+ // Small and round-faced: big light hair, glasses, freckles. Green.
27
+ theo: {
28
+ name: "Theo", build: "kid", skin: "#f1c9a5", hair: "curtains", hairColor: "#d08a2e", jaw: "chubby",
29
+ top: "polo", topColor: "#6cbf4f", bottom: "bermuda", bottomColor: "#c8a16a",
30
+ shoes: "canvas", shoeColor: "#e64a3b", socks: "#ffffff", glasses: true, freckles: true,
31
+ },
32
+ // Wide and heavy: square jaw, flat cap, checked shirt, stubble. Red.
33
+ gus: {
34
+ name: "Gus", build: "big", heavy: 0.7, skin: "#c98a62", hair: "buzz", hairColor: "#3a2a20", jaw: "square", nose: "wide",
35
+ top: "shirt", topColor: "#c4473a", top2: "#f1d9a6", pattern: "checks", bottom: "pants", bottomColor: "#3d4a5c",
36
+ shoes: "dress", shoeColor: "#3b2a24", hat: "flatCap", hatColor: "#6a5a48", stubble: true, earItem: "pencil",
37
+ },
38
+ // Short and stooped: a big white perm, a polka-dot blouse, a long skirt, pearls. Orange.
39
+ // (A `pattern` prints the torso only: on a `dress` the skirt stays plain, so prefer a blouse + skirt.)
40
+ ida: {
41
+ name: "Ida", build: "elder", female: true, skin: "#f3d2bd", hair: "perm", hairColor: "#e6e3ee", nose: "round",
42
+ top: "blouse", topColor: "#e8913a", pattern: "polka", stripe: "#fff4dc", bottom: "longSkirt", bottomColor: "#7a4a2a",
43
+ shoes: "sandals", shoeColor: "#5a3a22", wrinkles: true, necklace: { kind: "pearls" },
44
+ },
45
+ };
46
+
47
+ export const cast = (style?: CartoonOptions["style"]): Record<string, ToonDoc> =>
48
+ Object.fromEntries(Object.entries(LOOKS).map(([id, look]) => [id, cartoonCharacter(look, style ? { style } : {})]));
49
+
50
+ // Run as a script: write the documents and print what the director will read.
51
+ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
52
+ const style = process.argv[2] as CartoonOptions["style"] | undefined;
53
+ const out = join(dirname(fileURLToPath(import.meta.url)), "out");
54
+ mkdirSync(out, { recursive: true });
55
+ for (const [id, doc] of Object.entries(cast(style))) {
56
+ const file = join(out, `${id}.toon.json`);
57
+ writeFileSync(file, JSON.stringify(doc));
58
+ const info = cartoonInfo(doc, LOOKS[id], style ? { style } : {});
59
+ const issues = (doc.meta as { anatomyIssues?: unknown[] }).anatomyIssues ?? [];
60
+ console.log(`${id.padEnd(5)} height ${info.height.toFixed(0).padStart(4)} legs ${info.legLength.F.toFixed(0)} ` +
61
+ `extent ${info.extent.front.toFixed(0)}/${info.extent.back.toFixed(0)} anatomy issues ${issues.length} → ${file}`);
62
+ }
63
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The other kit builder: `humanCharacter(look)` — an anime-style human with a profile and a front
3
+ * view (no back drawing), the fighting set and flowing hair/cape physics.
4
+ *
5
+ * Run from the repo root: npx tsx skills/animestudio-characters/examples/human.ts
6
+ * Needs `rsvg-convert`. Writes out/hiro.toon.json and out/hiro.png (profile, front, punch, happy).
7
+ */
8
+ import { execFileSync } from "node:child_process";
9
+ import { mkdirSync, writeFileSync } from "node:fs";
10
+ import { dirname, join } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ import { type SceneDoc, evaluateScene, frameToSVG } from "@anime-studio/core";
13
+ import { prepareScene } from "@anime-studio/rigid";
14
+ import { type HumanLook, humanCharacter } from "@anime-studio/kit";
15
+
16
+ const OUT = join(dirname(fileURLToPath(import.meta.url)), "out");
17
+ mkdirSync(OUT, { recursive: true });
18
+
19
+ const look: HumanLook = {
20
+ name: "Hiro", skin: "#f1c7a3", hair: "spiky", hairColor: "#2a2f6b", hairTip: "#4b5bd1", iris: "#3b8fd9",
21
+ outfit: "hoodie", top: "#e2543a", pants: "#2c2f3a", shoes: "#f2f2f2", scarf: "#f2c14e",
22
+ };
23
+ const hiro = humanCharacter(look);
24
+ writeFileSync(join(OUT, "hiro.toon.json"), JSON.stringify(hiro));
25
+ const d = hiro as unknown as { controls: Record<string, { poses?: object }>; clips: object };
26
+ console.log("views:", Object.keys(d.controls.view?.poses ?? {}).join(" "));
27
+ console.log("emotions:", Object.keys(d.controls.emotion?.poses ?? {}).join(" "));
28
+ console.log("clips:", Object.keys(d.clips).join(" "));
29
+
30
+ const cells = [
31
+ { label: "profile", view: "profile" }, { label: "front", view: "front" },
32
+ { label: "punch", view: "profile", clip: "punch" }, { label: "happy", view: "front", emotion: "happy" },
33
+ ];
34
+ const cellW = 300, W = cellW * cells.length, H = 640, floor = 580;
35
+ const scene = {
36
+ format: "toon-scene", version: 1, width: W, height: H, fps: 30, duration: 2, background: "#f6efe0",
37
+ characters: { hiro: "hiro.toon.json" },
38
+ camera: { x: W / 2, y: H / 2, zoom: 1 },
39
+ layers: [{ id: "floor", art: `<rect x="0" y="${floor}" width="${W}" height="${H - floor}" fill="#e3d4b5"/>` +
40
+ cells.map((c, i) => `<text x="${cellW * i + cellW / 2}" y="${floor + 40}" font-family="sans-serif" font-size="24" text-anchor="middle" fill="#5a4a3a">${c.label}</text>`).join("") }],
41
+ actors: cells.map((_, i) => ({ id: `h${i}`, character: "hiro", x: cellW * i + cellW / 2, y: floor, z: 1 })),
42
+ script: cells.flatMap((c, i) => [
43
+ { at: 0, actor: `h${i}`, action: "play", clip: "idle", loop: true, layer: -1 },
44
+ { at: 0, actor: `h${i}`, action: "pose", control: "view", value: c.view, duration: 0 },
45
+ ...(c.emotion ? [{ at: 0, actor: `h${i}`, action: "pose", control: "emotion", value: c.emotion, duration: 0 }] : []),
46
+ ...(c.clip ? [{ at: 0, actor: `h${i}`, action: "play", clip: c.clip }] : []),
47
+ ]),
48
+ } as unknown as SceneDoc;
49
+ const frame = evaluateScene(await prepareScene(scene, { characters: { hiro } }), 0.28);
50
+ writeFileSync(join(OUT, "hiro.svg"), frameToSVG(frame));
51
+ execFileSync("rsvg-convert", ["-w", String(W), "-o", join(OUT, "hiro.png"), join(OUT, "hiro.svg")]);
52
+ console.log("wrote", join(OUT, "hiro.png"));
@@ -0,0 +1,68 @@
1
+ /**
2
+ * An SVG drawing → a character: import lumo.svg, then add what a drawing cannot carry (behaviours,
3
+ * controls, clips), validate it and render a strip to LOOK at.
4
+ *
5
+ * Run from the repo root: npx tsx skills/animestudio-characters/examples/import-svg.ts
6
+ * Needs `rsvg-convert`. Writes out/lumo.imported.toon.json (raw import), out/lumo.toon.json (finished)
7
+ * and out/lumo.png.
8
+ *
9
+ * The CLI does the same import: `toon import-svg lumo.svg --name lumo -o lumo.toon.json`.
10
+ */
11
+ import { execFileSync } from "node:child_process";
12
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
13
+ import { dirname, join } from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ import { type SceneDoc, type ToonDoc, evaluateScene, frameToSVG, parseToon } from "@anime-studio/core";
16
+ import { importSvg } from "@anime-studio/import-svg";
17
+ import { prepareScene } from "@anime-studio/rigid";
18
+
19
+ const HERE = dirname(fileURLToPath(import.meta.url));
20
+ const OUT = join(HERE, "out");
21
+ mkdirSync(OUT, { recursive: true });
22
+
23
+ // 1. Import: skeleton, parts (rigid / switch / skinned) and anchors come from the drawing's names.
24
+ const imported = importSvg(readFileSync(join(HERE, "lumo.svg"), "utf8"), { name: "lumo" });
25
+ for (const w of imported.warnings) console.warn(`warn ${w}`);
26
+ writeFileSync(join(OUT, "lumo.imported.toon.json"), JSON.stringify(imported.doc, null, 2));
27
+ const doc = imported.doc as ToonDoc;
28
+
29
+ // 2. Add life: a blink, an emotion-ish pose control, a looping idle and a nod.
30
+ doc.meta = { description: "A desk-lamp creature imported from an SVG drawing. Facing right." };
31
+ doc.behaviors = [{ type: "blink", id: "blink", part: "eyes", open: "open", closed: "closed", interval: [2, 4], duration: 0.15 }];
32
+ doc.controls = {
33
+ emotion: { type: "pose", poses: {
34
+ neutral: {},
35
+ curious: { "bones.shade.rotation": -15, "bones.neck2.rotation": -8 },
36
+ sad: { "bones.neck1.rotation": 10, "bones.neck2.rotation": 35, "bones.shade.rotation": 30, "parts.eyes.variant": "closed" },
37
+ } },
38
+ };
39
+ doc.clips = {
40
+ idle: { duration: 2.4, loop: true, tracks: { "bones.neck2.rotation": [[0, 0], [1.2, 3], [2.4, 0]], "bones.shade.rotation": [[0, 0], [1.2, -3], [2.4, 0]] } },
41
+ nod: { duration: 0.8, tracks: { "bones.shade.rotation": [[0, 0], [0.2, 20, "easeOut"], [0.4, -6], [0.6, 10], [0.8, 0]] } },
42
+ };
43
+ // A small spring on the shade for follow-through when the neck moves.
44
+ doc.physics = [{ type: "spring", bones: ["shade"], stiffness: 0.55, damping: 0.35 }];
45
+
46
+ const lumo = parseToon(doc); // throws with every issue listed if something is wrong
47
+ writeFileSync(join(OUT, "lumo.toon.json"), JSON.stringify(lumo, null, 2));
48
+
49
+ // 3. Render: rest, curious, sad, mid-nod.
50
+ const cells = [{ label: "neutral" }, { label: "curious", emotion: "curious" }, { label: "sad", emotion: "sad" }, { label: "nod", clip: "nod" }];
51
+ const cellW = 260, W = cellW * cells.length, H = 340, floor = 290;
52
+ const scene = {
53
+ format: "toon-scene", version: 1, width: W, height: H, fps: 30, duration: 2, background: "#f6efe0",
54
+ characters: { lumo: "lumo.toon.json" },
55
+ camera: { x: W / 2, y: H / 2, zoom: 1 },
56
+ layers: [{ id: "floor", art: `<rect x="0" y="${floor}" width="${W}" height="${H - floor}" fill="#e3d4b5"/>` +
57
+ cells.map((c, i) => `<text x="${cellW * i + cellW / 2}" y="${floor + 34}" font-family="sans-serif" font-size="22" text-anchor="middle" fill="#5a4a3a">${c.label}</text>`).join("") }],
58
+ actors: cells.map((_, i) => ({ id: `l${i}`, character: "lumo", x: cellW * i + cellW / 2, y: floor, z: 1 })),
59
+ script: cells.flatMap((c, i) => [
60
+ { at: 0, actor: `l${i}`, action: "play", clip: "idle", loop: true, layer: -1 },
61
+ ...(c.emotion ? [{ at: 0, actor: `l${i}`, action: "pose", control: "emotion", value: c.emotion, duration: 0 }] : []),
62
+ ...(c.clip ? [{ at: 0, actor: `l${i}`, action: "play", clip: c.clip }] : []),
63
+ ]),
64
+ } as unknown as SceneDoc;
65
+ const frame = evaluateScene(await prepareScene(scene, { characters: { lumo } }), 0.2);
66
+ writeFileSync(join(OUT, "lumo.svg"), frameToSVG(frame));
67
+ execFileSync("rsvg-convert", ["-w", String(W), "-o", join(OUT, "lumo.png"), join(OUT, "lumo.svg")]);
68
+ console.log("wrote", join(OUT, "lumo.toon.json"), "and", join(OUT, "lumo.png"));
@@ -0,0 +1,36 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 260" width="200" height="260">
2
+ <!-- A desk-lamp creature drawn for @anime-studio/import-svg. Names are ids (Inkscape labels and
3
+ data-name work too). Facing right; the origin circle marks the ground point between the feet. -->
4
+ <circle id="origin" cx="100" cy="250" r="2" fill="none"/>
5
+
6
+ <!-- Bones: a <line> from joint to tip; "@parent" links it. Parents may come in any order. -->
7
+ <line id="bone:root" x1="100" y1="250" x2="100" y2="236" stroke="none"/>
8
+ <line id="bone:neck1@root" x1="100" y1="236" x2="92" y2="170" stroke="none"/>
9
+ <line id="bone:neck2@neck1" x1="92" y1="170" x2="112" y2="110" stroke="none"/>
10
+ <line id="bone:shade@neck2" x1="112" y1="110" x2="150" y2="96" stroke="none"/>
11
+
12
+ <!-- A skin: one path bent by two bones (weights by distance to each bone). -->
13
+ <path id="skin:neck@neck1,neck2" d="M96 236 L88 170 L108 110 L116 112 L96 170 L104 236 Z" fill="#9aa3b5" stroke="#2b2633" stroke-width="3" stroke-linejoin="round"/>
14
+
15
+ <!-- Rigid parts: any element or group, attached to one bone. Later = drawn on top. -->
16
+ <g id="part:base@root">
17
+ <ellipse cx="100" cy="244" rx="46" ry="10" fill="#4b5470" stroke="#2b2633" stroke-width="3"/>
18
+ </g>
19
+ <g id="part:head@shade">
20
+ <path d="M104 92 L150 70 L176 112 L124 124 Z" fill="#f2c14e" stroke="#2b2633" stroke-width="3" stroke-linejoin="round"/>
21
+ <circle cx="112" cy="110" r="8" fill="#4b5470" stroke="#2b2633" stroke-width="3"/>
22
+ </g>
23
+
24
+ <!-- A switch: variants of one part ("switch:<part>/<variant>@<bone>", the first is the default). -->
25
+ <g id="switch:eyes/open@shade">
26
+ <circle cx="140" cy="90" r="7" fill="#fff" stroke="#2b2633" stroke-width="2.5"/>
27
+ <circle cx="142" cy="90" r="3" fill="#2b2633"/>
28
+ </g>
29
+ <g id="switch:eyes/closed@shade">
30
+ <path d="M133 91 Q140 95 147 91" fill="none" stroke="#2b2633" stroke-width="3" stroke-linecap="round"/>
31
+ </g>
32
+
33
+ <!-- Anchors: a <circle> marking a named point on a bone. -->
34
+ <circle id="anchor:head@shade" cx="140" cy="96" r="2" fill="none"/>
35
+ <circle id="anchor:light@shade" cx="160" cy="118" r="2" fill="none"/>
36
+ </svg>
@@ -0,0 +1,116 @@
1
+ {
2
+ "format": "toon",
3
+ "version": 1,
4
+ "name": "sprout",
5
+ "meta": { "description": "A small plant creature with a leaf on its head, hand-written to show the format. Facing right, ground at y = 0, about 230 px tall." },
6
+ "palette": {
7
+ "ink": "#2b2633",
8
+ "body": "#8fcf6a",
9
+ "bodyShade": "#6fae4e",
10
+ "leaf": "#3f9a4a",
11
+ "white": "#ffffff",
12
+ "mouth": "#7a2e3b",
13
+ "shoe": "#e0703a"
14
+ },
15
+ "art": {
16
+ "body": "<ellipse cx='0' cy='-95' rx='32' ry='42' fill='palette(body)' stroke='palette(ink)' stroke-width='3'/>",
17
+ "head": "<circle cx='4' cy='-160' r='34' fill='palette(body)' stroke='palette(ink)' stroke-width='3'/>",
18
+ "leafBlade": "<path d='M18 -232 C30 -250 50 -248 56 -240 C46 -230 30 -226 18 -232 Z' fill='palette(leaf)' stroke='palette(ink)' stroke-width='2.5'/>",
19
+ "eyesOpen": "<g fill='palette(white)' stroke='palette(ink)' stroke-width='2.5'><ellipse cx='12' cy='-168' rx='7' ry='9'/><ellipse cx='30' cy='-166' rx='7' ry='9'/></g>",
20
+ "eyesClosed": "<g fill='none' stroke='palette(ink)' stroke-width='3' stroke-linecap='round'><path d='M5 -167 Q12 -163 19 -167'/><path d='M23 -165 Q30 -161 37 -165'/></g>",
21
+ "eyesHappy": "<g fill='none' stroke='palette(ink)' stroke-width='3' stroke-linecap='round'><path d='M5 -166 Q12 -175 19 -166'/><path d='M23 -164 Q30 -173 37 -164'/></g>",
22
+ "pupils": "<g fill='palette(ink)'><circle cx='14' cy='-167' r='3'/><circle cx='32' cy='-165' r='3'/></g>",
23
+ "footF": "<ellipse cx='13' cy='-4' rx='12' ry='5' fill='palette(shoe)' stroke='palette(ink)' stroke-width='2.5'/>",
24
+ "footB": "<ellipse cx='-5' cy='-4' rx='12' ry='5' fill='palette(shoe)' stroke='palette(ink)' stroke-width='2.5'/>"
25
+ },
26
+ "skeleton": [
27
+ { "id": "root" },
28
+ { "id": "hips", "parent": "root", "from": [0, -60], "to": [0, -70], "mass": 2 },
29
+ { "id": "body", "parent": "hips", "from": [0, -60], "to": [0, -130], "mass": 2 },
30
+ { "id": "head", "parent": "body", "from": [0, -130], "to": [0, -194], "limits": { "rotation": [-30, 30] } },
31
+ { "id": "pupils", "parent": "head", "from": [23, -166] },
32
+ { "id": "leaf1", "parent": "head", "from": [2, -193], "to": [8, -215], "mass": 0.3 },
33
+ { "id": "leaf2", "parent": "leaf1", "from": [8, -215], "to": [18, -232], "mass": 0.3 },
34
+ { "id": "armF1", "parent": "body", "from": [10, -112], "to": [20, -88] },
35
+ { "id": "armF2", "parent": "armF1", "from": [20, -88], "to": [26, -64] },
36
+ { "id": "armB1", "parent": "body", "from": [-10, -112], "to": [-20, -88] },
37
+ { "id": "armB2", "parent": "armB1", "from": [-20, -88], "to": [-26, -64] },
38
+ { "id": "legF1", "parent": "hips", "from": [8, -60], "to": [12, -31] },
39
+ { "id": "legF2", "parent": "legF1", "from": [12, -31], "to": [9, -4] },
40
+ { "id": "legB1", "parent": "hips", "from": [-8, -60], "to": [-4, -31] },
41
+ { "id": "legB2", "parent": "legB1", "from": [-4, -31], "to": [-7, -4] }
42
+ ],
43
+ "parts": [
44
+ { "id": "armB", "type": "hose", "bones": ["armB1", "armB2"], "width": [9, 7], "fill": "palette(bodyShade)", "stroke": "palette(ink)", "strokeWidth": 2.5 },
45
+ { "id": "legB", "type": "hose", "bones": ["legB1", "legB2"], "width": [11, 9], "fill": "palette(bodyShade)", "stroke": "palette(ink)", "strokeWidth": 2.5 },
46
+ { "id": "footB", "type": "rigid", "bone": "legB2", "art": "footB" },
47
+ { "id": "legF", "type": "hose", "bones": ["legF1", "legF2"], "width": [11, 9], "fill": "palette(body)", "stroke": "palette(ink)", "strokeWidth": 2.5 },
48
+ { "id": "footF", "type": "rigid", "bone": "legF2", "art": "footF" },
49
+ { "id": "body", "type": "rigid", "bone": "body", "art": "body" },
50
+ { "id": "leaf", "type": "hose", "bones": ["leaf1", "leaf2"], "width": [5, 3], "fill": "palette(leaf)", "stroke": "palette(ink)", "strokeWidth": 2 },
51
+ { "id": "leafBlade", "type": "rigid", "bone": "leaf2", "art": "leafBlade" },
52
+ { "id": "head", "type": "rigid", "bone": "head", "art": "head" },
53
+ { "id": "eyes", "type": "switch", "bone": "head", "variants": { "open": "eyesOpen", "closed": "eyesClosed", "happy": "eyesHappy" }, "default": "open" },
54
+ { "id": "pupils", "type": "rigid", "bone": "pupils", "art": "pupils", "visibleWhen": { "part": "eyes", "variant": ["open"] } },
55
+ {
56
+ "id": "mouth", "type": "morph", "bone": "head", "fill": "palette(mouth)", "stroke": "palette(ink)", "strokeWidth": 2.5,
57
+ "base": "M12 -146 C17 -145 27 -145 32 -146 C27 -145 17 -145 12 -146 Z",
58
+ "shapes": {
59
+ "A": "M12 -146 C17 -145 27 -145 32 -146 C27 -145 17 -145 12 -146 Z",
60
+ "B": "M12 -146 C16 -142 28 -142 32 -146 C27 -148 17 -148 12 -146 Z",
61
+ "C": "M13 -147 C16 -140 28 -140 31 -147 C27 -150 17 -150 13 -147 Z",
62
+ "D": "M11 -148 C14 -134 30 -134 33 -148 C27 -152 17 -152 11 -148 Z",
63
+ "E": "M15 -147 C17 -140 27 -140 29 -147 C26 -151 18 -151 15 -147 Z",
64
+ "F": "M17 -146 C18 -139 26 -139 27 -146 C25 -151 19 -151 17 -146 Z",
65
+ "smile": "M10 -150 C16 -138 28 -138 34 -150 C27 -144 17 -144 10 -150 Z",
66
+ "frown": "M12 -142 C17 -148 27 -148 32 -142 C27 -146 17 -146 12 -142 Z"
67
+ }
68
+ },
69
+ { "id": "armF", "type": "hose", "bones": ["armF1", "armF2"], "width": [9, 7], "fill": "palette(body)", "stroke": "palette(ink)", "strokeWidth": 2.5 }
70
+ ],
71
+ "anchors": {
72
+ "head": { "bone": "head", "at": [10, -160] },
73
+ "hand": { "bone": "armF2", "at": [26, -64] },
74
+ "handB": { "bone": "armB2", "at": [-26, -64] }
75
+ },
76
+ "ik": [
77
+ { "id": "footF", "bones": ["legF1", "legF2"], "bend": 1 },
78
+ { "id": "footB", "bones": ["legB1", "legB2"], "bend": 1 }
79
+ ],
80
+ "physics": [
81
+ { "type": "spring", "bones": ["leaf1", "leaf2"], "stiffness": 0.4, "damping": 0.25, "gravity": [0, 200] },
82
+ { "type": "jiggle", "bone": "body", "stiffness": 0.6, "damping": 0.4, "translate": 0.3, "squash": 0.3 }
83
+ ],
84
+ "controls": {
85
+ "mouth": { "type": "viseme", "part": "mouth" },
86
+ "look": { "type": "aim", "targets": [
87
+ { "bone": "head", "weight": 0.4, "forward": 90, "maxAngle": 15 },
88
+ { "bone": "pupils", "mode": "translate", "radius": 3 }
89
+ ] },
90
+ "emotion": { "type": "pose", "poses": {
91
+ "neutral": {},
92
+ "happy": { "parts.eyes.variant": "happy", "parts.mouth.morph.smile": 1, "bones.head.rotation": -4, "bones.leaf1.rotation": -10 },
93
+ "sad": { "parts.mouth.morph.frown": 1, "bones.head.rotation": 10, "bones.leaf1.rotation": 60, "bones.body.rotation": 3 },
94
+ "surprised": { "parts.mouth.morph.F": 1, "bones.head.rotation": -6, "bones.leaf1.rotation": -20, "bones.pupils.scaleX": 0.7, "bones.pupils.scaleY": 0.7 }
95
+ } }
96
+ },
97
+ "behaviors": [
98
+ { "type": "blink", "id": "blink", "part": "eyes", "open": "open", "closed": "closed", "interval": [2, 5], "duration": 0.14 },
99
+ { "type": "breathe", "id": "breathe", "bone": "body", "amount": 0.015, "period": 3.2 }
100
+ ],
101
+ "clips": {
102
+ "idle": { "duration": 3, "loop": true, "tracks": {
103
+ "bones.armF1.rotation": [[0, 0], [1.5, 4], [3, 0]],
104
+ "bones.armB1.rotation": [[0, 0], [1.5, -3], [3, 0]],
105
+ "bones.head.rotation": [[0, 0], [1.5, 2], [3, 0]]
106
+ } },
107
+ "wave": { "duration": 1.2, "loop": true, "tracks": {
108
+ "bones.armF1.rotation": [[0, 0], [0.25, -100, "backOut"], [0.95, -100], [1.2, 0]],
109
+ "bones.armF2.rotation": [[0, 0], [0.25, -60], [0.45, -20], [0.65, -60], [0.85, -20], [1.2, 0]]
110
+ } },
111
+ "hop": { "duration": 0.8, "tracks": {
112
+ "bones.hips.squash": [[0, 0], [0.12, -0.15, "easeOut"], [0.3, 0.12], [0.6, 0], [0.68, -0.1], [0.8, 0]],
113
+ "bones.root.y": [[0, 0], [0.12, 0], [0.35, -60, "easeOut"], [0.6, 0, "easeIn"], [0.8, 0]]
114
+ } }
115
+ }
116
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Check the hand-written character sprout.toon.json: validate it, then render one strip with its
3
+ * emotions, a blink-free frame of `wave`, the top of `hop` and a `say`-style viseme — and LOOK at it.
4
+ *
5
+ * Run from the repo root: npx tsx skills/animestudio-characters/examples/sprout.ts
6
+ * Needs `rsvg-convert`. Writes skills/animestudio-characters/examples/out/sprout.png.
7
+ * (CLI equivalents: `toon validate`, `toon describe`, `toon render sprout.toon.json --clip wave --time 0.5 -o f.svg`.)
8
+ */
9
+ import { execFileSync } from "node:child_process";
10
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
11
+ import { dirname, join } from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+ import { type SceneDoc, evaluateScene, frameToSVG, parseToon } from "@anime-studio/core";
14
+ import { prepareScene } from "@anime-studio/rigid";
15
+
16
+ const HERE = dirname(fileURLToPath(import.meta.url));
17
+ const OUT = join(HERE, "out");
18
+ mkdirSync(OUT, { recursive: true });
19
+
20
+ // parseToon throws a readable error listing every issue (unknown bone, typo'd field…).
21
+ const sprout = parseToon(JSON.parse(readFileSync(join(HERE, "sprout.toon.json"), "utf8")));
22
+
23
+ const cells: { label: string; emotion?: string; clip?: string; mouth?: string }[] = [
24
+ { label: "neutral" }, { label: "happy", emotion: "happy" }, { label: "sad", emotion: "sad" },
25
+ { label: "surprised", emotion: "surprised" }, { label: "wave", clip: "wave" }, { label: "hop", clip: "hop" },
26
+ { label: "viseme D", mouth: "D" },
27
+ ];
28
+ const cellW = 220, W = cellW * cells.length, H = 360, floor = 300, T = 0.35;
29
+ const scene = {
30
+ format: "toon-scene", version: 1, width: W, height: H, fps: 30, duration: 2, background: "#f6efe0",
31
+ characters: { sprout: "sprout.toon.json" },
32
+ camera: { x: W / 2, y: H / 2, zoom: 1 },
33
+ layers: [{ id: "floor", art: `<rect x="0" y="${floor}" width="${W}" height="${H - floor}" fill="#e3d4b5"/>` +
34
+ cells.map((c, i) => `<text x="${cellW * i + cellW / 2}" y="${floor + 40}" font-family="sans-serif" font-size="22" text-anchor="middle" fill="#5a4a3a">${c.label}</text>`).join("") }],
35
+ actors: cells.map((_, i) => ({ id: `s${i}`, character: "sprout", x: cellW * i + cellW / 2, y: floor, z: 1 })),
36
+ script: cells.flatMap((c, i) => [
37
+ { at: 0, actor: `s${i}`, action: "play", clip: "idle", loop: true, layer: -1 },
38
+ ...(c.emotion ? [{ at: 0, actor: `s${i}`, action: "pose", control: "emotion", value: c.emotion, duration: 0 }] : []),
39
+ ...(c.clip ? [{ at: 0, actor: `s${i}`, action: "play", clip: c.clip }] : []),
40
+ ]),
41
+ // A direct track drives the viseme control, the way `say` does.
42
+ tracks: Object.fromEntries(cells.flatMap((c, i) => (c.mouth ? [[`actors.s${i}.controls.mouth`, [[0, c.mouth]]]] : []))),
43
+ } as unknown as SceneDoc;
44
+
45
+ const frame = evaluateScene(await prepareScene(scene, { characters: { sprout } }), T);
46
+ writeFileSync(join(OUT, "sprout.svg"), frameToSVG(frame));
47
+ execFileSync("rsvg-convert", ["-w", String(W), "-o", join(OUT, "sprout.png"), join(OUT, "sprout.svg")]);
48
+ console.log("wrote", join(OUT, "sprout.png"));