@algorisys/tinyfly 0.100.0 → 0.102.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 (71) hide show
  1. package/README.md +6 -6
  2. package/bin/tinyfly.mjs +16 -6
  3. package/docs/character-appearance.md +26 -0
  4. package/docs/editor-guide.md +1 -1
  5. package/docs/examples.md +1 -1
  6. package/docs/getting-started.md +1 -1
  7. package/docs/gsap-compat.md +1 -1
  8. package/docs/llm-guide.md +22 -4
  9. package/docs/maps.md +2 -2
  10. package/docs/scene-3d.md +140 -9
  11. package/docs/teaching.md +1 -1
  12. package/docs/video-rendering.md +198 -1
  13. package/lib/addons/adapters.js +431 -332
  14. package/lib/addons/characters.js +3889 -3773
  15. package/lib/addons/load-scene-oWNsYYC1.js +372 -0
  16. package/lib/addons/scene-3d-webgl.js +31 -31
  17. package/lib/addons/scene-3d.js +669 -314
  18. package/lib/addons/shading-0lPgnXmD.js +96 -0
  19. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +2 -2
  20. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  21. package/lib/browser/tinyfly.iife.js +15 -15
  22. package/lib/browser/tinyfly.js +6232 -5723
  23. package/lib/browser/tinyfly.umd.js +15 -15
  24. package/lib/engine/tinyfly-engine.js +1563 -1170
  25. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  26. package/lib/headless/headless.js +189 -6
  27. package/lib/types/adapters/canvas/framing.d.ts +27 -0
  28. package/lib/types/adapters/canvas/impossible.d.ts +15 -0
  29. package/lib/types/adapters/canvas/index.d.ts +4 -0
  30. package/lib/types/adapters/canvas/nested-zoom.d.ts +40 -0
  31. package/lib/types/adapters/canvas/zoom-blur.d.ts +49 -0
  32. package/lib/types/characters/character-script-3d.d.ts +21 -1
  33. package/lib/types/characters/character.d.ts +23 -3
  34. package/lib/types/characters/head/face.d.ts +19 -2
  35. package/lib/types/characters/index.d.ts +2 -1
  36. package/lib/types/characters/staging-3d.d.ts +56 -0
  37. package/lib/types/engine/authoring/beat-loop.d.ts +46 -0
  38. package/lib/types/engine/authoring/curve.d.ts +26 -0
  39. package/lib/types/engine/authoring/framing.d.ts +48 -0
  40. package/lib/types/engine/authoring/index.d.ts +4 -0
  41. package/lib/types/engine/authoring/periodic.d.ts +89 -0
  42. package/lib/types/engine/path/goo.d.ts +103 -0
  43. package/lib/types/engine/path/impossible.d.ts +92 -0
  44. package/lib/types/engine/path/index.d.ts +6 -0
  45. package/lib/types/engine/path/similarity.d.ts +48 -0
  46. package/lib/types/headless/audio-mix.d.ts +40 -0
  47. package/lib/types/headless/ffmpeg-args.d.ts +2 -0
  48. package/lib/types/headless/frame-renderer.d.ts +7 -1
  49. package/lib/types/headless/index.d.ts +2 -0
  50. package/lib/types/headless/loop-audio.d.ts +21 -0
  51. package/lib/types/headless/node-audio.d.ts +39 -0
  52. package/lib/types/headless/node-video.d.ts +2 -0
  53. package/lib/types/headless/video-scene.d.ts +21 -0
  54. package/lib/types/scene-3d/camera.d.ts +11 -2
  55. package/lib/types/scene-3d/geometry/mesh.d.ts +2 -0
  56. package/lib/types/scene-3d/geometry/primitives.d.ts +7 -0
  57. package/lib/types/scene-3d/impossible-3d.d.ts +29 -0
  58. package/lib/types/scene-3d/index.d.ts +7 -3
  59. package/lib/types/scene-3d/lighting.d.ts +58 -0
  60. package/lib/types/scene-3d/resolve-scene.d.ts +18 -2
  61. package/lib/types/scene-3d/scene-3d-adapter.d.ts +4 -0
  62. package/lib/types/scene-3d/scene-types.d.ts +43 -6
  63. package/lib/types/scene-3d/shading.d.ts +2 -0
  64. package/lib/types/scene-3d/shots.d.ts +162 -0
  65. package/lib/types/scene-3d/software-renderer.d.ts +40 -0
  66. package/llms-full.txt +395 -23
  67. package/llms.txt +29 -29
  68. package/package.json +1 -1
  69. package/skills/tinyfly/SKILL.md +11 -1
  70. package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
  71. package/lib/addons/shading-o5T_v9DT.js +0 -89
package/README.md CHANGED
@@ -97,10 +97,10 @@ A lightweight, API-driven animation engine and visual editor for creating high-p
97
97
  - **Camera** - Animate a pan/zoom/rotate over the whole stage (a reserved `Camera` layer driven by ordinary tracks). One-click add, a **🎥 Camera inspector** (Pan/Zoom/Rotation keyframed at the playhead), on-stage **✋ Pan** dragging, and a dedicated 🎥 lane at the top of the timeline; applies in every preview, export, and embed. Ready-made Push In / Pan Across / Orbit Reveal samples
98
98
  - **Polygon & star shapes** - ⬡ Polygon and ★ Star elements are parametric paths — edit sides / points / inner ratio in Properties and they regenerate and rescale; they render and export like any path
99
99
  - **Pen tool** - ✒️ Draw custom bezier paths: click for corners, click-drag for curves (Alt for a cusp), drag existing anchors/handles to adjust, snap points to grid/guides, click the first point or Enter to finish
100
- - **Loop check** - `tinyfly video scene.mjs --loop-check` renders five frames and says whether a video loops: whether the frame at the duration matches the first, and whether the last → first seam looks like any other step (exit 1 when it does not). `--frames 0,79,88` renders stills at chosen frames. See [docs/video-rendering.md](docs/video-rendering.md#loops)
100
+ - **Loop check** - `tinyfly video scene.mjs --loop-check` renders five frames and says whether a video loops: whether the frame at the duration matches the first, and whether the last → first seam looks like any other step (exit 1 when it does not). `--frames 0,79,88` renders stills at chosen frames. See [docs/video-rendering.md](docs/video-rendering.md#loops) A scene with `loop: true` is checked before it renders, its frames carry the `period`, and periodic helpers repeat exactly over it: `wobble`, `loopEase`, `loopNoise` (seeded noise round a circle), `torusNoise`; `nestedZoom` draws a Droste picture (a `similarityAbout` step, one level per loop, only the visible levels); `applyZoomBlur` and `drawDiveLines` for dives; the Penrose triangle and stairs as boxes that line up from one viewpoint (`penroseTriangle`, `penroseStairs`, `penroseTriangle3D`); goo as geometry: metaballs that merge and split (`metaballContours`), drips (`dripPath`), bubbles that grow, wobble and pop (`bubblePath`, `bubblePop`) and area-keeping squash and stretch (`squashStretch`)
101
101
  - **Bloom** - `bloom: true` on a video scene adds a deterministic glow around bright things (bright pass, blur, add; no `ctx.filter`), and 3D materials take `emissive` light that shines in the dark and feeds it. `applyBloom(ctx)` works on any 2D canvas. See [docs/video-rendering.md](docs/video-rendering.md#bloom)
102
102
  - **Light trails** - `trailSamples` + `drawTrail` draw comets and light streaks on any 2D canvas: a tapering, fading band with a round head, smooth at any speed, and deterministic (the trail is where the thing was, asked of the timeline, not a frame history). 3D scenes get `line` and `trail` objects whose segments sort by depth among the meshes. See [docs/video-rendering.md](docs/video-rendering.md#light-trails) and [docs/scene-3d.md](docs/scene-3d.md#lines-and-trails)
103
- - **3D scenes** - `@algorisys/tinyfly/scene-3d`: cameras, lights, meshes (box, sphere, cylinder, cone, torus, floor, any SVG path extruded) and props from the catalog (also from the editor's 3D Scene palette) as JSON in metres, animated by ordinary tracks (`stage/box`), cut between cameras with one keyframe, drawn on a plain canvas with flat, smooth or toon shading, ink outlines and fog: in the browser, in Workers, and to MP4 in Node. Characters stand in scenes and dance, seen by any camera, in their pen looks (clean, pencil) or as solid figures (`characterObjects`); props (cars, houses, trees, animals, birds) stand in them by preset name (`propObjects`), sorted a column at a time so figures walk round them rightly, and lit by the scene's lights (a sunset, a night with lit windows). Both are scripted in world metres (`propScript3D`, `characterScript3D`): drive or walk to a point or along a path, wheels and feet keeping pace with the ground. In the editor, a 🧊 3D Scene element builds them without code: add shapes, characters and lights, key them, dance from the playhead, cut between cameras. No WebGL needed (about 7 KB gzipped, its own entry and CDN script); for big or tangled scenes the optional WebGL2 renderer (`@algorisys/tinyfly/scene-3d/webgl`) adds a depth buffer and light per pixel. See [docs/scene-3d.md](docs/scene-3d.md)
103
+ - **3D scenes** - `@algorisys/tinyfly/scene-3d`: cameras, lights, meshes (box, sphere, cylinder, cone, torus, floor, any SVG path extruded) and props from the catalog (also from the editor's 3D Scene palette) as JSON in metres, animated by ordinary tracks (`stage/box`), cut between cameras with one keyframe, drawn on a plain canvas with flat, smooth or toon shading, ink outlines and fog: in the browser, in Workers, and to MP4 in Node. Characters stand in scenes and dance, seen by any camera, in their pen looks (clean, pencil) or as solid figures (`characterObjects`); props (cars, houses, trees, animals, birds) stand in them by preset name (`propObjects`), sorted a column at a time so figures walk round them rightly, and lit by the scene's lights (a sunset, a night with lit windows). Both are scripted in world metres (`propScript3D`, `characterScript3D`): drive or walk to a point or along a path, wheels and feet keeping pace with the ground. In the editor, a 🧊 3D Scene element builds them without code: add shapes, characters and lights, key them, dance from the playhead, cut between cameras. No WebGL needed (about 7 KB gzipped, its own entry and CDN script); for big or tangled scenes the optional WebGL2 renderer (`@algorisys/tinyfly/scene-3d/webgl`) adds a depth buffer and light per pixel. A software depth buffer (`depthBuffer: true`) draws crossing shapes and see-through meshes right in Node too. Films are shot lists as data: `shotTracks` cuts between cameras, `transitionAt` and `drawTransition` crossfade, dip or wipe between shots, `cameraMoveTracks` writes orbits, dollies, cranes, pans and zooms as tracks, `cameraHandheldTracks` adds a seeded shake, and `drawLetterbox` frames it at any aspect. See [docs/scene-3d.md](docs/scene-3d.md)
104
104
  - **3D transforms** - Cards, images, text and shapes turn in 3D (`rotateX`, `rotateY`, `z`, `perspective`, `backfaceVisibility`) and land on the same pixels in DOM, SVG, Canvas (true perspective, also headless) and WebGL, checked against each browser's own CSS. One documented transform order everywhere; Tilt / Turn / Depth / Perspective fields in the editor; 3D Card Flip and Cover Flow samples. Quaternion tracks with `interpolation: "slerp"` turn without gimbal lock; the engine's `vec3`, `quat` and `mat4` helpers are plain arrays. The first steps of [3D support](docs/3d-support-plan.md). See [docs/3d-rotations.md](docs/3d-rotations.md)
105
105
  - **Shape morph** - 🌀 Tween one path into another over the timeline (engine-level path interpolation); plays in every renderer, export, and embed
106
106
  - **Grid, snapping & guides** - ▦ 20px grid, 🧲 snapping of drag/resize to grid/element-edges/artboard with live alignment guides, and 📏 rulers with draggable guides
@@ -237,7 +237,7 @@ GSAP-shaped functions at the top level. Teaching embeds are included: add
237
237
  itself.
238
238
 
239
239
  ```html
240
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly.iife.js"></script>
240
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly.iife.js"></script>
241
241
  <script>
242
242
  tinyfly.to('.box', { x: 200, rotate: 90, duration: 1, ease: 'power2.out' })
243
243
 
@@ -273,7 +273,7 @@ A teaching figure needs no code at all:
273
273
  <script type="application/json" data-tinyfly-timeline>{ …timeline JSON with markers… }</script>
274
274
  <figcaption>Appending to a full slice</figcaption>
275
275
  </figure>
276
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly.iife.js" data-tinyfly-auto></script>
276
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly.iife.js" data-tinyfly-auto></script>
277
277
  ```
278
278
 
279
279
  See [Teaching Animations](docs/teaching.md).
@@ -372,7 +372,7 @@ Without a build step, the player bundle puts the same functions on a `tinyfly` g
372
372
  <div data-tinyfly="box" style="width: 60px; height: 60px; background: #4a9eff;"></div>
373
373
  </div>
374
374
 
375
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly-player.iife.js"></script>
375
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly-player.iife.js"></script>
376
376
  <script>
377
377
  tinyfly.play('#animation', './animation.json', { loop: -1 })
378
378
  </script>
@@ -481,7 +481,7 @@ Or skip the code entirely with declarative embeds (see [Teaching Animations](doc
481
481
  <svg viewBox="0 0 720 200">…</svg>
482
482
  <script type="application/json" data-tinyfly-timeline>{ …timeline JSON… }</script>
483
483
  </figure>
484
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
484
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
485
485
  ```
486
486
 
487
487
  ### Audio / Video Sync
package/bin/tinyfly.mjs CHANGED
@@ -27,7 +27,7 @@
27
27
  * JavaScript (RSS, email, print, previews).
28
28
  *
29
29
  * tinyfly video <scene.mjs> [-o <out.mp4>] [--stills <dir>] [--frames <i,j,…> | --times <ms,ms,…>]
30
- * [--loop-check] [--scale <n>] [--fps <n>] [--crf <n>] [--no-audio] [--srt <file>] [--vtt <file>]
30
+ * [--loop-check] [--scale <n>] [--fps <n>] [--crf <n>] [--codec h264|prores] [--no-audio] [--srt <file>] [--vtt <file>]
31
31
  * Render a scene module to an MP4 without a browser. The module's default
32
32
  * export is a VideoScene (or a function returning one): a timeline and
33
33
  * canvas targets, a draw(ctx, frame) function, or both. --stills writes
@@ -86,7 +86,7 @@ const usage = () => {
86
86
  ' tinyfly validate <timeline.json> [<timeline.json> …] [--markup <file>]\n' +
87
87
  ' tinyfly render <timeline.json> <markup file> [--at start|end|<ms>|<marker id>]\n' +
88
88
  ' tinyfly video <scene.mjs> [-o <out.mp4>] [--stills <dir>] [--frames <i,j,…> | --times <ms,…>] [--loop-check]\n' +
89
- ' [--scale <n>] [--fps <n>] [--crf <n>] [--no-audio] [--srt <file>] [--vtt <file>]'
89
+ ' [--scale <n>] [--fps <n>] [--crf <n>] [--codec h264|prores] [--no-audio] [--srt <file>] [--vtt <file>]'
90
90
  )
91
91
  process.exit(2)
92
92
  }
@@ -162,6 +162,11 @@ async function video() {
162
162
  const scale = numberFlag('--scale')
163
163
  const fps = numberFlag('--fps')
164
164
  const crf = numberFlag('--crf')
165
+ const codec = flag('--codec')
166
+ if (codec && codec !== 'h264' && codec !== 'prores') {
167
+ console.error('tinyfly: --codec is h264 or prores')
168
+ process.exit(2)
169
+ }
165
170
  const silent = has('--no-audio')
166
171
  const loopCheck = has('--loop-check')
167
172
  const framesList = listFlag('--frames')
@@ -190,15 +195,19 @@ async function video() {
190
195
  if (vttFile) writeFileSync(vttFile, headless.toWebVTT(cues))
191
196
  console.error(`captions: ${cues.length} cue(s)`)
192
197
  }
193
- if (loopCheck) {
198
+ if (loopCheck || (scene.loop && !stillsDir)) {
199
+ // A scene that says it loops is checked before any frame is encoded.
194
200
  const report = await headless.checkLoop(scene, { baseDir, scale, fps })
195
201
  const db = (value) => (Number.isFinite(value) ? `${value.toFixed(2)} dB` : 'identical')
196
202
  console.error(`frame at the duration vs the first: ${db(report.closure)}`)
197
203
  console.error(`last → first (the seam): ${db(report.seam)}`)
198
204
  console.error(`ordinary steps: ${db(report.steps[0])}, ${db(report.steps[1])}`)
199
205
  console.error(`${report.loops ? '✓' : '✗'} ${report.verdict}`)
200
- if (!report.loops) process.exit(1)
201
- return
206
+ if (!report.loops) {
207
+ if (!loopCheck) console.error('the scene has `loop: true`; fix the motion (or drop the flag) and render again')
208
+ process.exit(1)
209
+ }
210
+ if (loopCheck) return
202
211
  }
203
212
  if (stillsDir) {
204
213
  // Stills at chosen frames or times, else one per marker step.
@@ -210,7 +219,7 @@ async function video() {
210
219
  console.error(`stills: ${files.length} PNG(s) in ${stillsDir}`)
211
220
  return
212
221
  }
213
- const out = output ?? join(baseDir, `${basename(scenePath, extname(scenePath))}.mp4`)
222
+ const out = output ?? join(baseDir, `${basename(scenePath, extname(scenePath))}.${codec === 'prores' ? 'mov' : 'mp4'}`)
214
223
  let lastPercent = -1
215
224
  const started = Date.now()
216
225
  const result = await headless.renderVideo(scene, {
@@ -219,6 +228,7 @@ async function video() {
219
228
  scale,
220
229
  fps,
221
230
  crf,
231
+ codec,
222
232
  audio: silent ? false : undefined,
223
233
  onProgress: (done, total) => {
224
234
  const percent = Math.floor((done / total) * 20) * 5
@@ -293,6 +293,32 @@ tracks animate them): `blush` (rosy cheeks, with hatch lines past 0.5),
293
293
  `tears` (a drop under each eye, running down past 0.6) and `sweat` (a bead at
294
294
  the temple).
295
295
 
296
+ ## Close-ups
297
+
298
+ For a face filling the frame there are three more pose fields and a bigger
299
+ drawing:
300
+
301
+ - `pupil` (1 the usual size): bigger for excitement or a dive into it,
302
+ smaller for fear. `lid` (0..1) lowers the upper lids over the eye (sleepy,
303
+ suspicious, bored). `bulge` (0..1) pops the eyes out of the head, whites and
304
+ all. `scared`, `afraid`, `sleepy`, `suspicious` and `excited` use them.
305
+ - `face: { nose: true }` adds a small nose; `face: { teeth, tongue }` are
306
+ above.
307
+ - `drawCharacterHead(ctx, who, pose, { x, y, radius, time })` draws just the
308
+ head (hair, hat, glasses, ears, the face), its centre at `x`, `y` and its
309
+ radius `radius` px, in the character's look with the line weight scaled to
310
+ the size. The pose turns and nods it and sets the face.
311
+ - `face: { inPupil(ctx, pupil) }` draws inside each pupil, the context
312
+ clipped to its circle on screen (`{ x, y, r, side }`): another scene, or the
313
+ same head again for a Droste face:
314
+
315
+ ```js
316
+ function head(ctx, x, y, r, depth = 0) {
317
+ const who = character({ hair: 'spiky', face: { nose: true, inPupil: depth < 4 ? (c, p) => head(c, p.x, p.y, p.r, depth + 1) : undefined } })
318
+ drawCharacterHead(ctx, who, humanPose({ bulge: 0.9, pupil: 1.5 }), { x, y, radius: r })
319
+ }
320
+ ```
321
+
296
322
  ## Everyday actions, held items and meeting hands
297
323
 
298
324
  The motion and everyday-life sheets add poses to `HUMAN_POSES`: `sleep`,
@@ -1128,7 +1128,7 @@ The dialog shows the generated HTML/JavaScript code with a **Copy Code** button.
1128
1128
  **Steps to embed:**
1129
1129
  1. Build the player: `npm run build:player`
1130
1130
  2. Copy `lib/player/tinyfly-player.iife.js` to your project (or load
1131
- `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly-player.iife.js`
1131
+ `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly-player.iife.js`
1132
1132
  instead; see [Deployment](DEPLOYMENT.md))
1133
1133
  3. Copy the generated code into your HTML
1134
1134
  4. Adjust the script `src` path if needed
package/docs/examples.md CHANGED
@@ -694,7 +694,7 @@ For simple website embedding without a build system.
694
694
  </html>
695
695
  ```
696
696
 
697
- Build the player with `npm run build:player` to generate `lib/player/tinyfly-player.iife.js`, or load it from the CDN: `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly-player.iife.js`.
697
+ Build the player with `npm run build:player` to generate `lib/player/tinyfly-player.iife.js`, or load it from the CDN: `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly-player.iife.js`.
698
698
 
699
699
  ---
700
700
 
@@ -185,7 +185,7 @@ with a GSAP-style call (durations are in seconds here):
185
185
  ```html
186
186
  <div class="box" style="width:60px;height:60px;background:#4a9eff"></div>
187
187
 
188
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly.iife.js"></script>
188
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly.iife.js"></script>
189
189
  <script>
190
190
  tinyfly.to('.box', { x: 200, duration: 1 })
191
191
  </script>
@@ -74,7 +74,7 @@ Without a build step, the all-in-one bundle exposes the same functions on a
74
74
  global — `tinyfly.to()`, `tinyfly.timeline()` and so on:
75
75
 
76
76
  ```html
77
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly.iife.js"></script>
77
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly.iife.js"></script>
78
78
  <script>
79
79
  tinyfly.to('.box', { x: 200, duration: 1 })
80
80
  </script>
package/docs/llm-guide.md CHANGED
@@ -48,8 +48,14 @@ loaded with `kinds: [characterObjects, propObjects]`; its controls are tracks
48
48
  on the object. Script it in world metres with `propScript3D` (`to: [x, z]`,
49
49
  `through: [[x, z], …]`, `face`), not with `propScript`, whose `to` is screen px.
50
50
  Characters in a 3D scene walk the same way with `characterScript3D`
51
- (`{ do: 'walk', to: [x, z] }`, `pose`, `gag`, `face`, `place`); a rider is
52
- seated with `propRide3D` and spliced into its script with `spliceTracks`. See `docs/props.md`.
51
+ (`{ do: 'walk', to: [x, z] }`, `pose`, `gag`, `face`, `place`, `say` with a
52
+ line, `look` at a point or `'camera'`); a rider is seated with `propRide3D`
53
+ and spliced into its script with `spliceTracks`. A film from a 3D scene is a
54
+ shot list (`shotTracks`, `transitionAt` + `drawTransition`), camera moves as
55
+ tracks (`cameraMoveTracks`, `cameraHandheldTracks`), a mood from
56
+ `lightingPreset('dusk')` with `ground()` and `shadow: true` on meshes, and
57
+ sound from `renderMix`; draw it with `depthBuffer: true` when shapes cross.
58
+ See `docs/props.md` and `docs/scene-3d.md`.
53
59
 
54
60
  ## Characters with a look
55
61
 
@@ -63,8 +69,11 @@ code: `build` (`child`, `tall`, `short`…), `hair` (a style name, or
63
69
  from. Age is hair, glasses and clothes, never a stoop; a `cane` in a hand or
64
70
  a `wheelchair()` to ride (`RIDING_POSES.wheeling`) is an accessory any
65
71
  character can have. Expressions come from `HUMAN_EXPRESSIONS`
66
- and are pose fields, as are the face marks `blush`, `tears` and `sweat` (0–1),
67
- so any face goes with any action or view. Hair and hats turn with the head:
72
+ and are pose fields, as are the face marks `blush`, `tears` and `sweat` (0–1)
73
+ and the close-up fields `pupil`, `lid` and `bulge`, so any face goes with any
74
+ action or view; `drawCharacterHead(ctx, who, pose, { x, y, radius })` draws
75
+ just the head big, and `face: { nose, inPupil }` adds a nose and a drawing in
76
+ the pupils. Hair and hats turn with the head:
68
77
  don't draw a different hairstyle per view. Hanging hair swings on its own:
69
78
  after the character's tracks add `hairFollowTracks(target, tracks, who)` (or,
70
79
  posing per frame, `hairFollow` once and `hairMotionAt(keys, t)` each frame)
@@ -145,12 +154,21 @@ them before calling it done:
145
154
 
146
155
  ```bash
147
156
  npx @algorisys/tinyfly video scene.mjs --stills frames --times 0,800,1600,2400
157
+ npx @algorisys/tinyfly video scene.mjs --loop-check # a looping video: does the frame at the duration match the first?
148
158
  ```
149
159
 
150
160
  A model that can read images should look at the PNGs: is the hand on the
151
161
  word, does the figure stand on the line, does the text land where it should?
152
162
  Fix, render again.
153
163
 
164
+ **A video that loops** (Shorts, Reels): say `loop: true` on the scene and
165
+ make every motion a function of `frame.time / frame.period` that repeats
166
+ exactly: `wobble`, `loopEase`, `loopNoise` for motion, `nestedZoom` for a
167
+ zoom that steps one level per loop, `bubblePath` with `period`, `beatPulse`
168
+ on a tempo from `loopBeats`, and `cutAudioToLoop` for the sound. Whole
169
+ numbers of turns and cycles only; `--loop-check` must say "closes". See the
170
+ Loops chapter of `docs/video-rendering.md`.
171
+
154
172
  ## The rules that trip models up
155
173
 
156
174
  - **Milliseconds in JSON, seconds in the GSAP-style API.** Timeline keyframes
package/docs/maps.md CHANGED
@@ -14,8 +14,8 @@ On a page with no build step, load the maps add-on after the browser bundle; it
14
14
  adds to the same `tinyfly` global:
15
15
 
16
16
  ```html
17
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly.iife.js"></script>
18
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly-maps.iife.js"></script>
17
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly.iife.js"></script>
18
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly-maps.iife.js"></script>
19
19
  ```
20
20
 
21
21
  It is a separate script because the offline world map it carries adds about
package/docs/scene-3d.md CHANGED
@@ -57,7 +57,7 @@ number or three), `parent` (an earlier object it moves with), `visible`, and
57
57
  |---|---|
58
58
  | `group` | (just a transform: move several objects together, or carry a camera) |
59
59
  | `mesh` | `geometry`, `material` (a key of `materials`) |
60
- | `camera` | `projection: 'perspective'` with `fov` (vertical, degrees), or `'orthographic'` with `height` (metres); `near`, `far`; optional `lookAt: [x, y, z]` |
60
+ | `camera` | `projection: 'perspective'` with `fov` (vertical, degrees), or `'orthographic'` with `height` (metres); `near`, `far`; optional `lookAt: [x, y, z]`, `up` (which way is up for it, default +y) and `roll` (degrees about the view axis, clockwise on screen) |
61
61
  | `light` | `light: 'ambient' \| 'directional' \| 'point' \| 'spot'`, `color`, `intensity` (1 is full light); directional and spot shine from their position toward `target` (default the origin); point and spot fade to nothing at `range`; spot's cone is `angle` (half-angle, default 30°) |
62
62
 
63
63
  **Geometry**: `box` (`size: [w, h, d]`), `sphere` (`radius`, `segments`),
@@ -67,7 +67,11 @@ facing up, `segments` per side), and `extrude`: any SVG `path` made solid,
67
67
  `depth` metres thick and scaled to `width` metres wide (default 1), with
68
68
  `curveSegments` points per curve (default 12). Subpaths inside others are
69
69
  holes (an "o", a ring); outlines inside holes are solid again. The path's y
70
- (down) is flipped to 3D's y (up). All centred on the origin.
70
+ (down) is flipped to 3D's y (up). All centred on the origin. A raw `mesh`
71
+ takes `positions` (flat x, y, z runs), `indices` (triples, counter-clockwise
72
+ from outside), optional `normals` per vertex (flat ones are computed) and
73
+ `colors`, one per face or one per vertex (blended per face), over the
74
+ material's colour: warped beams, terrain, anything exported from a tool.
71
75
 
72
76
  ```js
73
77
  { id: 'star', kind: 'mesh', material: 'gold',
@@ -91,9 +95,14 @@ for a neon glow: `{ color: '#000000', emissive: '#ff2bd6', shading: 'unlit' }`.
91
95
  `roughness` and `metalness` are for the realistic look (three.js, a later
92
96
  milestone); the stylized renderers ignore them, so one material serves both.
93
97
 
94
- The scene can have `background` and `fog: { color, near, far }` (metres from
95
- the camera). A scene with no lights gets a soft default (ambient plus a key
96
- light from upper right).
98
+ The scene can have `background` (a colour, or a sky as a vertical gradient
99
+ `{ top, bottom }`), `fog: { color, near, far }` (metres from the camera) and
100
+ `ground` (the height blob shadows lie at, default 0). A mesh with `shadow:
101
+ true` (or `{ opacity, ground }`) gets a soft blob shadow on the ground under
102
+ it, which spreads and fades as the mesh lifts off. A scene with no lights gets a soft default (ambient plus a key
103
+ light from upper right). Outlines fade into the fog too. `nearFade: { from, to }` fades geometry
104
+ nearer the camera than `to` metres, gone at `from`, so a dive passes through
105
+ things as if they were glass (also an option of `resolveScene3D`).
97
106
 
98
107
  ## Animating it
99
108
 
@@ -108,8 +117,9 @@ live in the same timeline as everything else.
108
117
  | `visible` | any object | 0 or 1 (children hide with their parent) |
109
118
  | `opacity` | meshes | 0..1, times the material's |
110
119
  | `color` | meshes, lights | a colour, over the material's or light's |
120
+ | `outlineWidth`, `outlineColor` | meshes | px and a colour, over the material's outline (0 switches it off) |
111
121
  | `intensity`, `target` | lights | |
112
- | `fov` / `height`, `lookAt` | cameras | |
122
+ | `fov` / `height`, `lookAt`, `roll` | cameras | |
113
123
  | `color`, `width`, `opacity` | lines, trails | |
114
124
  | `length` | trails | ms |
115
125
  | `activeCamera` | the scene, target `<sceneId>` | a camera's id: **a cut is one keyframe** |
@@ -122,6 +132,85 @@ so instead of picking a winner.
122
132
  the group. `orbitPosition(target, yaw, pitch, distance)` and
123
133
  `dollyPosition(eye, target, amount)` place cameras for keyframes.
124
134
 
135
+ ## Shots and cameras
136
+
137
+ A film is a shot list, as data, over the same scene and timeline:
138
+
139
+ ```js
140
+ import { shotTracks, shotMarkers, transitionAt, withActiveCamera, cameraMoveTracks, cameraHandheldTracks } from '@algorisys/tinyfly/scene-3d'
141
+ import { drawTransition, drawLetterbox } from '@algorisys/tinyfly/adapters'
142
+
143
+ const shots = [
144
+ { id: 'establish', start: 0, end: 4000, camera: 'wide', label: 'Dolly in' },
145
+ { id: 'orbit', start: 4000, end: 7500, camera: 'orbiter', transition: { kind: 'crossfade', duration: 700 } },
146
+ { id: 'close', start: 7500, end: 10000, camera: 'close', transition: { kind: 'dipToBlack', duration: 600 } },
147
+ ]
148
+ const tracks = [
149
+ ...shotTracks(shots, 'set'), // the activeCamera track: a cut is one keyframe
150
+ ...cameraMoveTracks({ scene: 'set', camera: 'wide', start: 0, end: 4000,
151
+ from: { target: [0, 0.8, 0], yaw: 20, pitch: 18, distance: 11 }, to: { distance: 7 } }), // a dolly
152
+ ...cameraHandheldTracks([], { scene: 'set', camera: 'close', start: 7500, end: 10000,
153
+ base: { position: [1.2, 1.4, 3.6], lookAt: [0, 0.75, 1.3] }, seed: 'close' }),
154
+ ]
155
+ ```
156
+
157
+ - **Shots** are `{ id, start, end, camera, label?, transition? }`;
158
+ `checkShots` names overlaps, bad ends and a transition on the first shot;
159
+ `shotAt(shots, time)` is the shot playing; `shotMarkers` gives the
160
+ timeline's markers (stills and captions step through them).
161
+ - **Transitions** (`cut`, `crossfade`, `dipToBlack`, `wipe` with a
162
+ `direction`) start at the shot's start and last `duration` ms. Any frame can
163
+ ask `transitionAt(shots, time)` which two shots to draw and how far along
164
+ (0..1); `drawTransition(ctx, transition, { width, height, draw(ctx,
165
+ cameraId) })` draws both and blends them (a crossfade mixes, a dip covers
166
+ the cut, a wipe sweeps the new shot in), with `withActiveCamera(values,
167
+ sceneId, cameraId)` to draw the shot going out. Pure and frame-addressable:
168
+ the film renders the same in any order.
169
+ - **Camera moves** are presets that write `position`, `lookAt` (and `fov`)
170
+ tracks on the camera: `cameraMoveTracks({ from, to, easing, every })` with
171
+ poses as an orbit round a target (`yaw`, `pitch`, `distance`), or a fixed
172
+ `position` with a moving `lookAt`, or a `fov`: change `yaw` for an orbit,
173
+ `distance` for a dolly, `pitch` and `distance` for a crane, `lookAt` for a
174
+ pan or tilt, `fov` for a zoom, or any mix. `cameraFollowTracks({ subjectAt,
175
+ offset, lag })` keeps a camera on a moving subject. `cameraHandheldTracks(
176
+ tracks, { amount, aim, rate, seed })` adds a deterministic handheld shake
177
+ onto a move's tracks or a still camera's `base`.
178
+ - **Aspect and safe areas**: `drawLetterbox(ctx, canvas, '2.39:1')` paints
179
+ the bars (in a video's `overlay`), `frameRect`, `frameSize` and `safeAreas`
180
+ are the geometry, `drawSafeAreas` draws the action and title guides for
181
+ stills. `FRAME_ASPECTS` has 16:9, 2.39:1, 4:3, 1:1, 9:16 and 4:5.
182
+
183
+ `examples/headless-video/film-shots.mjs` is a three-shot film with a dolly, a
184
+ crossfade into an orbit, a dip to black into a handheld close-up, letterboxed.
185
+
186
+ ## Sets and light for mood
187
+
188
+ A set is objects like any other; what sets the mood is its light, its sky and
189
+ its fog, and those come as presets:
190
+
191
+ ```js
192
+ import { lightingPreset, lightingTracks, ground } from '@algorisys/tinyfly/scene-3d'
193
+
194
+ const light = lightingPreset('dusk') // or 'day', 'night', 'stage'
195
+ const floor = ground({ size: 20 })
196
+ const scene = {
197
+ id: 'set', camera: 'cam', background: light.background, fog: light.fog,
198
+ materials: { ...floor.materials, red: { color: '#ef4444', shading: 'toon' } },
199
+ objects: [camera, ...light.objects, ...floor.objects, { id: 'box', kind: 'mesh', geometry: { type: 'box', size: [1, 1, 1] }, material: 'red', position: [0, 0.5, 0], shadow: true }],
200
+ }
201
+ // Day turning to night over four seconds: tracks on the same lights.
202
+ const tracks = lightingTracks('day', 'night', { scene: 'set', start: 0, end: 4000 })
203
+ ```
204
+
205
+ Every preset uses the same light ids (`key`, `fill`, `sky`, and `spot` on
206
+ the stage), so `lightingTracks(from, to, { scene, start, end })` keys each
207
+ light's `color`, `intensity`, `position` and `target` from one mood to the
208
+ other (a spot only one mood has fades in or out); the sky and fog are the
209
+ scene's to set per shot. `ground({ size, color, segments, y })` is a floor
210
+ on layer −1 with its material; props from the catalog (trees, houses,
211
+ furniture) are the set pieces, placed by preset name (see Props). Blob
212
+ shadows under meshes are `shadow: true`; projected shadows are planned.
213
+
125
214
  ## Lines and trails
126
215
 
127
216
  Two more kinds of object draw a band that faces the camera, as wide as
@@ -167,7 +256,7 @@ front of the meshes. For trails on a plain 2D canvas, see `drawTrail` in
167
256
  loadScene3D(json): LoadedScene3D // validates and builds meshes once (throws with every problem)
168
257
  validateScene3D(json, tracks?): string[] // problems as sentences, empty when fine
169
258
  resolveScene3D(loaded, values, { width, height, time?, valuesAt? }): ResolvedScene3D // pure: matrices, camera, lights, sorted triangles
170
- drawScene3D(ctx, loaded, values, { width, height, time?, valuesAt? | stateAt? }) // resolve and draw, in one call
259
+ drawScene3D(ctx, loaded, values, { width, height, time?, valuesAt? | stateAt?, depthBuffer? }) // resolve and draw, in one call
171
260
  new Scene3DAdapter(new Canvas2DRenderer(ctx), { width, height, valuesAt? }) // registerScene, applyState(state), render()
172
261
  ```
173
262
 
@@ -265,6 +354,21 @@ phase) with the distance, one stride per cycle, so the feet stay planted, plus
265
354
  the stepping pose as it draws, on the pose it holds: a wave carries on while it
266
355
  walks. Objects take `gait` and `walking` as fields too.
267
356
 
357
+ **Speaking and looking.** `{ do: 'say', say: 'A pot of water!' }` lip-syncs
358
+ the line on the character's mouth (the same `lipSyncOver` the 2D scripts use)
359
+ with a talking head, and lasts as long as the line (`speechLength(text)`, or
360
+ `for`). `{ do: 'look', look: [x, z] }` turns the head and eyes toward a point
361
+ at eye height (`[x, y, z]` for any height, `'camera'` for the viewer with
362
+ `options.camera`); `lookFields(from, at)` is the maths. To keep looking at
363
+ something that moves, `characterLookAtTracks(tracks, { scene, character,
364
+ at: { object: 'didi' } | { camera: 'cam' } | [x, y, z] | (time) => [x, y, z],
365
+ start, end, objects })` keys `head.turn`, `head.nod`, `lookX` and `lookY`
366
+ from where both are at every moment; `objectPositionAt(tracks, target,
367
+ base)` is the sampler it uses. For several figures, `stageSpots({ count,
368
+ shape: 'line' | 'arc' | 'circle' | 'cluster', spacing, centre })` gives
369
+ positions and headings that do not overlap: a line across, an arc facing its
370
+ middle, a circle facing in, or a seeded loose group.
371
+
268
372
  **Riding.** `propRide3D({ prop, propId, propTracks, scene, placement, anchor, riderId, pose, start, end, mount?, dismount? })`
269
373
  keeps a rider's hips on a prop's seat anchor (a horse's `saddle`, a bike's or
270
374
  a cart's `seat`) as the prop moves, turns, bobs with its stride and pitches,
@@ -394,6 +498,18 @@ objects, prepares them once, and each frame returns meshes (shaded and sorted
394
498
  with the scene's) and drawables (drawn whole at their depth). Pass it in
395
499
  `loadScene3D(scene, { kinds })`.
396
500
 
501
+ ## Impossible objects
502
+
503
+ `penroseTriangle3D({ length, thickness, material, id, position, distance })`
504
+ returns three box objects (beams along x, up y and along z, each starting
505
+ where the last ends) and an orthographic camera on the (1, 1, 1) diagonal
506
+ from which the third beam's end meets the first's start on screen. Add the
507
+ objects with a material of that name and the camera, or place your own camera
508
+ along the diagonal; from anywhere else the loop is open. The third corner
509
+ shows the beams' ends as a real sculpture's does. For a clean drawing see the
510
+ 2D `penroseTriangle` and `penroseStairs` in
511
+ [Video from code](video-rendering.md#dives-and-impossible-objects).
512
+
397
513
  ## The WebGL2 renderer
398
514
 
399
515
  `@algorisys/tinyfly/scene-3d/webgl` (`tinyfly-scene-3d-webgl.iife.js` for
@@ -421,8 +537,9 @@ renderer.render(resolveScene3D(scene, values, { width: canvas.width, height: can
421
537
  trails, go on `overlay`, a 2D canvas laid over the GL one (in front of the meshes);
422
538
  solid characters are meshes and sort properly.
423
539
 
424
- It runs on a page or in a Worker (OffscreenCanvas). Node has no WebGL2, so
425
- headless video uses the Canvas 2D renderer. The cross-browser checks
540
+ It runs on a page or in a Worker (OffscreenCanvas). Node has no WebGL2;
541
+ headless video uses the Canvas 2D renderer, or its software depth buffer
542
+ (below) when shapes cut through each other. The cross-browser checks
426
543
  (`npm run e2e -- --check scene-3d-webgl`) compile it in Chromium, Firefox and
427
544
  WebKit, compare its silhouettes with the Canvas 2D renderer's and check the
428
545
  depth buffer.
@@ -438,5 +555,19 @@ modest, or use a layer. Each triangle has one colour, so smooth shading is
438
555
  smoothed per triangle, not per pixel; more segments look rounder. The WebGL2
439
556
  renderer (above) has a depth buffer and per-pixel light.
440
557
 
558
+ **A software depth buffer** draws right where the painter's order cannot:
559
+ `drawScene3D(ctx, scene, values, { …, depthBuffer: true })`, or
560
+ `new Scene3DAdapter(new SoftwareRenderer(ctx), …)`. Every triangle is
561
+ rasterised into a pixel buffer with a depth per pixel (`rasterizeResolvedScene`
562
+ gives the bytes and depths without a canvas), so crossing beams, huge floors
563
+ and long meshes need no `layer` or segments; see-through meshes blend over
564
+ what is behind them, and ink is depth-tested so an outline never shows
565
+ through what is in front. Each triangle keeps its one shaded colour and its
566
+ fog, edges are hard (no anti-aliasing), and objects drawn whole (characters
567
+ in their pen looks, lines, trails) go on top of the meshes, as on the WebGL2
568
+ overlay. It costs about three times the painter's time and works anywhere
569
+ the Canvas 2D renderer does. Layers keep their meaning: a lower layer is
570
+ drawn first and a higher one paints over it whatever the depths.
571
+
441
572
  Rendering speed in Node: a 1280×720 scene of a few thousand triangles renders
442
573
  at a few frames a second; parallel rendering for long films is planned.
package/docs/teaching.md CHANGED
@@ -25,7 +25,7 @@ path for all of that:
25
25
  </figure>
26
26
 
27
27
  <!-- once, anywhere on the page (a site-wide footer is fine) -->
28
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.100.0/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
28
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.102.0/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
29
29
  ```
30
30
 
31
31
  Every `[data-tinyfly-embed]` mounts when the page is ready, with no per-post