@algorisys/tinyfly 0.99.0 → 0.101.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.
- package/README.md +9 -9
- package/bin/tinyfly.mjs +7 -3
- package/docs/acting.md +10 -6
- package/docs/character-appearance.md +71 -7
- package/docs/editor-guide.md +38 -3
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +34 -9
- package/docs/maps.md +2 -2
- package/docs/props.md +61 -1
- package/docs/scene-3d.md +23 -4
- package/docs/teaching.md +1 -1
- package/docs/video-rendering.md +154 -0
- package/lib/addons/adapters.js +387 -333
- package/lib/addons/characters.js +4795 -3752
- package/lib/addons/load-scene-oWNsYYC1.js +372 -0
- package/lib/addons/scene-3d-webgl.js +1 -1
- package/lib/addons/scene-3d.js +323 -277
- package/lib/addons/shading-0lPgnXmD.js +96 -0
- package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
- package/lib/browser/tinyfly.iife.js +14 -14
- package/lib/browser/tinyfly.js +7294 -5893
- package/lib/browser/tinyfly.umd.js +14 -14
- package/lib/engine/tinyfly-engine.js +1389 -1031
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +39 -0
- package/lib/types/adapters/canvas/impossible.d.ts +15 -0
- package/lib/types/adapters/canvas/index.d.ts +3 -0
- package/lib/types/adapters/canvas/nested-zoom.d.ts +40 -0
- package/lib/types/adapters/canvas/zoom-blur.d.ts +49 -0
- package/lib/types/characters/acting/character-script.d.ts +14 -2
- package/lib/types/characters/acting/script.d.ts +9 -0
- package/lib/types/characters/capabilities.d.ts +2 -0
- package/lib/types/characters/character.d.ts +28 -1
- package/lib/types/characters/hair-follow.d.ts +12 -6
- package/lib/types/characters/hands/held-items.d.ts +6 -2
- package/lib/types/characters/head/face.d.ts +23 -1
- package/lib/types/characters/index.d.ts +3 -2
- package/lib/types/characters/interactions.d.ts +60 -0
- package/lib/types/characters/props/families/animals.d.ts +6 -0
- package/lib/types/characters/props/families/birds.d.ts +16 -0
- package/lib/types/characters/props/families/furniture.d.ts +102 -0
- package/lib/types/characters/props/index.d.ts +1 -0
- package/lib/types/characters/props/presets.d.ts +15 -2
- package/lib/types/characters/props/ride-3d.d.ts +4 -1
- package/lib/types/characters/scenery.d.ts +126 -0
- package/lib/types/characters/species/human-motion.d.ts +17 -0
- package/lib/types/characters/species/human.d.ts +6 -0
- package/lib/types/characters/wardrobe/basic-outfit.d.ts +16 -5
- package/lib/types/engine/authoring/beat-loop.d.ts +46 -0
- package/lib/types/engine/authoring/curve.d.ts +26 -0
- package/lib/types/engine/authoring/index.d.ts +3 -0
- package/lib/types/engine/authoring/periodic.d.ts +89 -0
- package/lib/types/engine/path/goo.d.ts +103 -0
- package/lib/types/engine/path/impossible.d.ts +92 -0
- package/lib/types/engine/path/index.d.ts +6 -0
- package/lib/types/engine/path/similarity.d.ts +48 -0
- package/lib/types/headless/index.d.ts +1 -0
- package/lib/types/headless/loop-audio.d.ts +21 -0
- package/lib/types/headless/node-audio.d.ts +20 -0
- package/lib/types/headless/video-scene.d.ts +9 -0
- package/lib/types/scene-3d/camera.d.ts +11 -2
- package/lib/types/scene-3d/geometry/mesh.d.ts +2 -0
- package/lib/types/scene-3d/geometry/primitives.d.ts +7 -0
- package/lib/types/scene-3d/impossible-3d.d.ts +29 -0
- package/lib/types/scene-3d/index.d.ts +4 -3
- package/lib/types/scene-3d/resolve-scene.d.ts +13 -1
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +2 -0
- package/lib/types/scene-3d/scene-types.d.ts +29 -4
- package/lib/types/scene-3d/shading.d.ts +2 -0
- package/llms-full.txt +423 -47
- package/llms.txt +29 -29
- package/package.json +2 -2
- package/skills/tinyfly/SKILL.md +20 -6
- package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
- package/lib/addons/shading-o5T_v9DT.js +0 -89
package/llms.txt
CHANGED
|
@@ -13,47 +13,47 @@ Key facts:
|
|
|
13
13
|
- For language models: read the capability catalog first (`npx @algorisys/tinyfly capabilities`, or the end of llms-full.txt). It is generated from the library, so every name in it (poses, expressions, gags, gaits, beat actions, canvas properties, code-panel edits) is accepted, and names not in it are rejected with the name probably meant. Check beat scripts with `npx @algorisys/tinyfly check beats.json`, tracks with `checkTracks(tracks, targets)`, and ask any target what it animates with `describeTarget(target)`. The npm package ships `docs/`, `llms.txt`, `llms-full.txt` and an agent skill (`skills/tinyfly/SKILL.md`); `docs/llm-guide.md` describes the workflow.
|
|
14
14
|
- Source: https://github.com/algorisys-oss/tinyfly. License: MIT.
|
|
15
15
|
|
|
16
|
-
All documentation and the interactive course in a single file: [llms-full.txt](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
16
|
+
All documentation and the interactive course in a single file: [llms-full.txt](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/llms-full.txt)
|
|
17
17
|
|
|
18
18
|
## Start here
|
|
19
19
|
|
|
20
|
-
- [Getting Started](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
21
|
-
- [GSAP Compatibility](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
22
|
-
- [Code Examples](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
23
|
-
- [Building Animations with an LLM](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
20
|
+
- [Getting Started](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/getting-started.md): What tinyfly is, making a first animation in the editor, and using it from code, a script tag or the CDN.
|
|
21
|
+
- [GSAP Compatibility](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/gsap-compat.md): The GSAP-style API (`live.to`, `tf.timeline`): supported vars, motion paths, morphSVG, text, inertia, Draggable, Flip, and where it differs from GSAP.
|
|
22
|
+
- [Code Examples](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/examples.md): Recipes with the engine API: fades, loops, colour and bezier easing, loading JSON, canvas and SVG rendering, multi-scene sequences, motion paths and script-tag embeds.
|
|
23
|
+
- [Building Animations with an LLM](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/llm-guide.md): For assistants and the people setting them up: read the capability catalog (`tinyfly capabilities`), ask targets what they animate (`describeTarget`), check beats and tracks with did-you-mean errors (`tinyfly check`, `checkTracks`), render stills to look at, and the agent skill shipped in the package.
|
|
24
24
|
|
|
25
25
|
## Reference
|
|
26
26
|
|
|
27
|
-
- [API Reference](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
28
|
-
- [File Format](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
27
|
+
- [API Reference](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/api-reference.md): Every public engine, player and adapter API: Timeline, tracks, keyframes, easing, drivers, serialization and exports.
|
|
28
|
+
- [File Format](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/file-format.md): The JSON animation format: timelines, every track kind, keyframes, easing and the project file — for generating or consuming animations.
|
|
29
29
|
|
|
30
30
|
## Editor features
|
|
31
31
|
|
|
32
|
-
- [Editor Guide](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
33
|
-
- [Shape Morphing](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
34
|
-
- [Pen Tool](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
35
|
-
- [Polygons & Stars](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
36
|
-
- [Grid & Snapping](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
37
|
-
- [Onion Skinning](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
38
|
-
- [Sprite-sheet Export](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
32
|
+
- [Editor Guide](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/editor-guide.md): Every panel and feature of the visual editor, from elements and keyframes to text and inertia tracks, preview and export.
|
|
33
|
+
- [Shape Morphing](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/shape-morph.md): Tweening one path into another, including shapes with different point counts and several subpaths.
|
|
34
|
+
- [Pen Tool](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/pen-tool.md): Drawing custom paths point by point with straight segments and bezier curves.
|
|
35
|
+
- [Polygons & Stars](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/polygon-star.md): Parametric polygon and star shapes that stay editable while animating like any path.
|
|
36
|
+
- [Grid & Snapping](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/grid-and-snapping.md): The grid overlay, snapping to grid, elements and artboard centre, and alignment guides.
|
|
37
|
+
- [Onion Skinning](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/onion-skinning.md): Ghost frames before and after the playhead for judging arcs and easing.
|
|
38
|
+
- [Sprite-sheet Export](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/sprite-sheet-export.md): Exporting frames as a PNG grid plus JSON metadata for game engines and canvas players.
|
|
39
39
|
|
|
40
40
|
## Guides
|
|
41
41
|
|
|
42
|
-
- [Scroll Animation](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
43
|
-
- [Props: Everyday Objects with Behaviours](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
44
|
-
- [Teaching Animations](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
45
|
-
- [Rendering Video from Code](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
46
|
-
- [Animated Maps](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
47
|
-
- [Cartoon Hands](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
48
|
-
- [Character Appearance](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
49
|
-
- [Cartoon Acting](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
50
|
-
- [Dance and Flips](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
51
|
-
- [3D Scenes](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
52
|
-
- [3D Transforms and Rotations](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
53
|
-
- [Extending tinyfly](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
54
|
-
- [Deployment](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
42
|
+
- [Scroll Animation](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/scroll-animation.md): Scroll-driven and play-when-visible animation with ScrollDriver and VisibilityDriver.
|
|
43
|
+
- [Props: Everyday Objects with Behaviours](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/props.md): Cars, trucks, buses, tractors, carts, train carriages, bikes, motorbikes, trees, houses, a helicopter and a plane: 3D rigs drawn with the characters’ pens (clean, pencil) that turn toward the camera, with beats acted through the 12 principles (anticipation, squash and stretch, follow-through, an exaggeration dial), wheels that roll exactly, effects, and figures riding them.
|
|
44
|
+
- [Teaching Animations](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/teaching.md): Step-through explanatory figures: markers, captions in several languages, the teaching player, step controls, one-script declarative embeds, tinyfly/teach diagram primitives, and validate / render for build pipelines.
|
|
45
|
+
- [Rendering Video from Code](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/video-rendering.md): Rendering a scene to MP4 without a browser: `tinyfly video`, custom canvas targets drawn by code, timing from narration and recorded voice-over, the stick-figure character, SRT/WebVTT captions, stills, porting Cairo scripts, and a benchmark against pycairo.
|
|
46
|
+
- [Animated Maps](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/maps.md): Maps that animate: a camera that flies in to a city, pins that drop in, routes that draw themselves while a marker travels them, on OpenStreetMap tiles or an offline world outline (also in pencil), in the browser and in headless video.
|
|
47
|
+
- [Cartoon Hands](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/cartoon-hands.md): A hand you can pose: a palm and five fingers in 3D, posed by numbers (curls, thumb, spread, wrist turn), ready-made shapes from a fist to a pencil grip, left and right, four or five fingers, in clean, pencil and silhouette looks; the animator's hand and character gloves are built on it.
|
|
48
|
+
- [Character Appearance](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/character-appearance.md): Hair (34 styles), facial hair (20), glasses, hats and ears for the v2 character as plain data on the head, so they turn with it through all eight views; builds (child, tall, short…), a recurring cast (castMember), expressions with blush, tears and sweat, everyday poses, held items (mug, phone, bags, umbrella, parcel) and two characters’ hands meeting (meetHands: handshake, high five, hand-over).
|
|
49
|
+
- [Cartoon Acting](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/acting.md): actTracks(): the same key poses, acted: anticipation, overshoot and settle, overlapping joints, eyes that lead and blink, moving holds and jump squash, in full, snappy or limited styles; gags as data (take, double take, wind-up); a line of action (bend); gaits with personality; lip-sync from text (Latin and Devanagari); beat scripts compiled to acted tracks; your own actions (defineAction), gaits (defineGait) and personas (persona()); acting on code (codePanel lines and words as anchors: leap onto a line, point at it, swipe it away wiped, knocked off or blurred; grab, throw, kick, carry and drop words, push them along their line, write new text in by hand; ride a line as gaps close); camera shots (push in, cut, shake, follow); the cartoon zip; speed lines, dust puffs and impact stars; drawing on twos (a timeline setting); acting, gags, walks and lines in the editor.
|
|
50
|
+
- [Dance and Flips](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/dance.md): The stick figure dances disco, hip hop, breaking, jazz, K-pop, Bollywood, Bhangra, Bharatanatyam (with mudras), the Charleston, tap (with tap sounds) and popping (side glide, moonwalk), and does front, back, layout and scissor flips, cartwheels, handsprings, split leaps and full splits: wrists, ankles, turn-out, spin and rise as pose fields; moves keyed in beats; styles, grooves and routines as plain data.
|
|
51
|
+
- [3D Scenes](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/scene-3d.md): @algorisys/tinyfly/scene-3d: cameras, lights and meshes as JSON, in metres, animated by tracks at <scene>/<object> (cuts with activeCamera), drawn on a 2D canvas with flat, smooth or toon shading, ink outlines and fog, in browsers, Workers and Node (MP4 with tinyfly video); v2 characters in scenes, dancing, in their pen looks or as solid figures, seen by any camera.
|
|
52
|
+
- [3D Transforms and Rotations](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/3d-rotations.md): CSS-style 3D for flat elements in every renderer (rotateX, rotateY, z, perspective, backface visibility; true perspective on Canvas and WebGL, matching CSS within a pixel), one documented transform order, the editor's 3D fields; smooth quaternion rotations with interpolation: "slerp"; the vec3, quat and mat4 helpers; format version 2.
|
|
53
|
+
- [Extending tinyfly](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/extending.md): Writing a render adapter, animating any object with live and the ticker, custom and parametric eases, stagger offsets, adding a track kind, and contributing gallery examples.
|
|
54
|
+
- [Deployment](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/docs/DEPLOYMENT.md): Building and hosting the editor, and serving the player bundles.
|
|
55
55
|
|
|
56
56
|
## Optional
|
|
57
57
|
|
|
58
|
-
- [README](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
59
|
-
- [Release notes](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.
|
|
58
|
+
- [README](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/README.md): Feature overview, project layout and development setup.
|
|
59
|
+
- [Release notes](https://raw.githubusercontent.com/algorisys-oss/tinyfly/v0.101.0/release-notes/README.md): What changed in each version.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algorisys/tinyfly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight, API-driven animation engine and editor. The engine is framework-agnostic and runs in browsers, Web Workers, and Node.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"unpkg": "./lib/browser/tinyfly.iife.js",
|
|
36
36
|
"jsdelivr": "./lib/browser/tinyfly.iife.js",
|
|
37
37
|
"bin": {
|
|
38
|
-
"tinyfly": "
|
|
38
|
+
"tinyfly": "bin/tinyfly.mjs"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
package/skills/tinyfly/SKILL.md
CHANGED
|
@@ -61,9 +61,13 @@ names.
|
|
|
61
61
|
or `part:ID`). Walk figures on a prop's front line (a house's
|
|
62
62
|
`anchor:doorstep` y), not on the prop's own `y`, or they pass through its
|
|
63
63
|
walls.
|
|
64
|
-
- For objects in the scene (vehicles, trees, houses,
|
|
65
|
-
birds) use the prop presets with `propScript()`; seat figures with
|
|
66
|
-
`propRide()`, tow with `propTow()`.
|
|
64
|
+
- For objects in the scene (vehicles, trees, houses, furniture, aircraft,
|
|
65
|
+
animals, birds) use the prop presets with `propScript()`; seat figures with
|
|
66
|
+
`propRide()`, tow with `propTow()`. Furniture's anchors are where a figure
|
|
67
|
+
uses it (`seat`, `top`, `mattress`, `handle`, `doorway`); a `wheelchair()`
|
|
68
|
+
is ridden on its `seat` in `RIDING_POSES.wheeling`. A sky or a room is
|
|
69
|
+
`scenery()` / `scenePreset('park')` with `hour`, `wind`, `rain`, `snow` as
|
|
70
|
+
tracks. Aim figure beats at prop anchors
|
|
67
71
|
(`propAt(...).anchor('door')`), and perch birds at them (`branch`, `ridge`).
|
|
68
72
|
`style: 'stick'` draws props as line art. In a 3D scene, place props with
|
|
69
73
|
`rotation: [0, deg, 0]` (`rotateY` is a track) and script them with
|
|
@@ -71,15 +75,18 @@ names.
|
|
|
71
75
|
characters there with `characterScript3D`, riders with `propRide3D`.
|
|
72
76
|
- Give a v2 `character()` its look as options, not drawing code: `build`,
|
|
73
77
|
`hair` (`'bob'` or `{ style, color, length }`), `facialHair`, `glasses`,
|
|
74
|
-
`hat`, `ears: true`, `
|
|
75
|
-
|
|
78
|
+
`hat`, `ears: true`, `face: { teeth, tongue }`, `feet: 'flat' | 'pointed' |
|
|
79
|
+
'big'`, `outfit: { shirt, trousers, over, shoes }`; or start from
|
|
80
|
+
`castMember('grandma', height)`. A `cane` in a hand or a wheelchair is an
|
|
81
|
+
accessory, not an age. Hair and hats turn with the head, so one
|
|
76
82
|
description serves every view; hanging hair swings after a turn or a run when
|
|
77
83
|
you add `hairFollowTracks(target, tracks, who)` after the character's tracks
|
|
78
84
|
(per-frame code: `hairFollow` once, `hairMotionAt(keys, t)` each frame).
|
|
79
85
|
Faces are `HUMAN_EXPRESSIONS` plus the pose
|
|
80
86
|
fields `blush`, `tears`, `sweat` (0–1). Items in hands: `holding`
|
|
81
87
|
(`held.<side>` lets go); hands that meet: `meetHands(kind, a, b)` at
|
|
82
|
-
`meetingSpacing
|
|
88
|
+
`meetingSpacing`; a hug: `embrace(a, b)` at `embraceSpacing`; a help-up:
|
|
89
|
+
`helpUp(helper, sitter, progress)` at `helpUpSpacing`. See `docs/character-appearance.md`.
|
|
83
90
|
- For recurring characters, make a `persona()` (look, acting, gait, mood,
|
|
84
91
|
stance) and use `persona.script()`; for a move the catalog lacks, write it
|
|
85
92
|
with `defineAction()` rather than hand-keying joints in many places.
|
|
@@ -107,3 +114,10 @@ npx @algorisys/tinyfly video scene.mjs --stills frames --times 0,800,1600
|
|
|
107
114
|
Check that hands meet what they touch, figures face and point the right
|
|
108
115
|
way, stand on their floors (and ride bars as they grow), text lands where it
|
|
109
116
|
should and nothing leaves the frame. Fix and render again.
|
|
117
|
+
|
|
118
|
+
For a video that loops, set `loop: true` on the scene and drive every motion
|
|
119
|
+
from `frame.time / frame.period` with helpers that repeat exactly (`wobble`,
|
|
120
|
+
`loopEase`, `loopNoise`, `nestedZoom`, `beatPulse` on `loopBeats`,
|
|
121
|
+
`bubblePath` with `period`; sound via `cutAudioToLoop`), whole turns and
|
|
122
|
+
cycles only; then `npx @algorisys/tinyfly video scene.mjs --loop-check` must
|
|
123
|
+
say "closes".
|
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { parsePath as B } from "@algorisys/tinyfly";
|
|
2
|
-
class j {
|
|
3
|
-
positions = [];
|
|
4
|
-
normals = [];
|
|
5
|
-
indices = [];
|
|
6
|
-
/** Add a vertex; returns its index. */
|
|
7
|
-
vertex(c, a, n, s, i, t) {
|
|
8
|
-
const o = Math.hypot(s, i, t) || 1;
|
|
9
|
-
return this.positions.push(c, a, n), this.normals.push(s / o, i / o, t / o), this.positions.length / 3 - 1;
|
|
10
|
-
}
|
|
11
|
-
/** Add a triangle, counter-clockwise seen from its front. */
|
|
12
|
-
triangle(c, a, n) {
|
|
13
|
-
this.indices.push(c, a, n);
|
|
14
|
-
}
|
|
15
|
-
/** Add a quad a-b-c-d (counter-clockwise) as two triangles. */
|
|
16
|
-
quad(c, a, n, s) {
|
|
17
|
-
this.indices.push(c, a, n, c, n, s);
|
|
18
|
-
}
|
|
19
|
-
build() {
|
|
20
|
-
return { positions: this.positions, normals: this.normals, indices: this.indices };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function C(e) {
|
|
24
|
-
const c = /* @__PURE__ */ new Map(), a = [];
|
|
25
|
-
for (let s = 0; s < e.positions.length / 3; s++) {
|
|
26
|
-
const i = [0, 1, 2].map((t) => Math.round(e.positions[s * 3 + t] * 1e6)).join(",");
|
|
27
|
-
c.has(i) || c.set(i, s), a.push(c.get(i));
|
|
28
|
-
}
|
|
29
|
-
const n = /* @__PURE__ */ new Map();
|
|
30
|
-
for (let s = 0; s < e.indices.length / 3; s++)
|
|
31
|
-
for (let i = 0; i < 3; i++) {
|
|
32
|
-
const t = a[e.indices[s * 3 + i]], o = a[e.indices[s * 3 + (i + 1) % 3]];
|
|
33
|
-
if (t === o) continue;
|
|
34
|
-
const r = t < o ? `${t}-${o}` : `${o}-${t}`, l = n.get(r);
|
|
35
|
-
l ? l.faces.push(s) : n.set(r, { a: Math.min(t, o), b: Math.max(t, o), faces: [s] });
|
|
36
|
-
}
|
|
37
|
-
return [...n.values()];
|
|
38
|
-
}
|
|
39
|
-
function z(e) {
|
|
40
|
-
let c = 0;
|
|
41
|
-
for (let a = 0; a < e.length; a++) {
|
|
42
|
-
const n = e[a], s = e[(a + 1) % e.length];
|
|
43
|
-
c += n.x * s.y - s.x * n.y;
|
|
44
|
-
}
|
|
45
|
-
return c;
|
|
46
|
-
}
|
|
47
|
-
function _(e, c) {
|
|
48
|
-
let a = !1;
|
|
49
|
-
for (let n = 0, s = c.length - 1; n < c.length; s = n++) {
|
|
50
|
-
const i = c[n], t = c[s];
|
|
51
|
-
i.y > e.y != t.y > e.y && e.x < (t.x - i.x) * (e.y - i.y) / (t.y - i.y) + i.x && (a = !a);
|
|
52
|
-
}
|
|
53
|
-
return a;
|
|
54
|
-
}
|
|
55
|
-
const X = (e, c, a) => (c.x - e.x) * (a.y - e.y) - (c.y - e.y) * (a.x - e.x), Y = (e, c) => e.x === c.x && e.y === c.y;
|
|
56
|
-
function N(e, c, a, n) {
|
|
57
|
-
return X(c, a, e) >= 0 && X(a, n, e) >= 0 && X(n, c, e) >= 0;
|
|
58
|
-
}
|
|
59
|
-
function F(e, c) {
|
|
60
|
-
let a = 0;
|
|
61
|
-
for (let h = 1; h < c.length; h++) c[h].x > c[a].x && (a = h);
|
|
62
|
-
const n = c[a];
|
|
63
|
-
let s = -1, i = 1 / 0;
|
|
64
|
-
for (let h = 0; h < e.length; h++) {
|
|
65
|
-
const f = e[h], m = e[(h + 1) % e.length];
|
|
66
|
-
if (f.y > n.y == m.y > n.y) continue;
|
|
67
|
-
const g = f.x + (n.y - f.y) * (m.x - f.x) / (m.y - f.y);
|
|
68
|
-
g >= n.x && g < i && (i = g, s = h);
|
|
69
|
-
}
|
|
70
|
-
if (s < 0) return e;
|
|
71
|
-
const t = e[s], o = e[(s + 1) % e.length];
|
|
72
|
-
let r = t.x > o.x ? s : (s + 1) % e.length;
|
|
73
|
-
const l = { x: i, y: n.y };
|
|
74
|
-
let u = 1 / 0;
|
|
75
|
-
for (let h = 0; h < e.length; h++) {
|
|
76
|
-
const f = e[h];
|
|
77
|
-
if (h === r || f.x < n.x) continue;
|
|
78
|
-
const m = e[r];
|
|
79
|
-
if (!(N(f, n, l, m) || N(f, n, m, l))) continue;
|
|
80
|
-
const p = Math.abs(Math.atan2(f.y - n.y, f.x - n.x));
|
|
81
|
-
p < u && (u = p, r = h);
|
|
82
|
-
}
|
|
83
|
-
const d = c.slice(a).concat(c.slice(0, a));
|
|
84
|
-
return [...e.slice(0, r + 1), ...d, n, e[r], ...e.slice(r + 1)];
|
|
85
|
-
}
|
|
86
|
-
function H(e, c = []) {
|
|
87
|
-
const a = z(e) >= 0 ? e : [...e].reverse(), n = c.map((d) => z(d) <= 0 ? d : [...d].reverse()), s = [...a, ...n.flat()], i = /* @__PURE__ */ new Map();
|
|
88
|
-
s.forEach((d, h) => i.set(d, h));
|
|
89
|
-
const t = [...n].sort((d, h) => Math.max(...h.map((f) => f.x)) - Math.max(...d.map((f) => f.x)));
|
|
90
|
-
let o = a;
|
|
91
|
-
for (const d of t) o = F(o, d);
|
|
92
|
-
const r = o.map((d) => i.get(d)), l = [];
|
|
93
|
-
let u = r.length * r.length;
|
|
94
|
-
for (; r.length > 3 && u-- > 0; ) {
|
|
95
|
-
let d = !1;
|
|
96
|
-
for (let h = 0; h < r.length; h++) {
|
|
97
|
-
const f = r[(h + r.length - 1) % r.length], m = r[h], g = r[(h + 1) % r.length], [p, M, b] = [s[f], s[m], s[g]];
|
|
98
|
-
if (X(p, M, b) <= 0) continue;
|
|
99
|
-
let $ = !1;
|
|
100
|
-
for (const y of r) {
|
|
101
|
-
const w = s[y];
|
|
102
|
-
if (!(y === f || y === m || y === g || Y(w, p) || Y(w, M) || Y(w, b)) && N(w, p, M, b)) {
|
|
103
|
-
$ = !0;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (!$) {
|
|
108
|
-
l.push(f, m, g), r.splice(h, 1), d = !0;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
d || (l.push(r[r.length - 1], r[0], r[1]), r.splice(0, 1));
|
|
113
|
-
}
|
|
114
|
-
return r.length === 3 && l.push(r[0], r[1], r[2]), { points: s, triangles: l };
|
|
115
|
-
}
|
|
116
|
-
function U(e, c) {
|
|
117
|
-
const a = /* @__PURE__ */ new Map();
|
|
118
|
-
for (const n of B(e).segments) {
|
|
119
|
-
a.has(n.subpath) || a.set(n.subpath, [{ x: n.startX, y: -n.startY }]);
|
|
120
|
-
const s = a.get(n.subpath);
|
|
121
|
-
if (n.type === "L")
|
|
122
|
-
s.push({ x: n.endX, y: -n.endY });
|
|
123
|
-
else {
|
|
124
|
-
const [i, t, o, r, l, u] = n.points;
|
|
125
|
-
for (let d = 1; d <= c; d++) {
|
|
126
|
-
const h = d / c, f = 1 - h, m = f * f * f * n.startX + 3 * f * f * h * i + 3 * f * h * h * o + h * h * h * l, g = f * f * f * n.startY + 3 * f * f * h * t + 3 * f * h * h * r + h * h * h * u;
|
|
127
|
-
s.push({ x: m, y: -g });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return [...a.values()].map((n) => n.filter((s, i) => i === 0 || s.x !== n[i - 1].x || s.y !== n[i - 1].y)).map((n) => n.length > 1 && n[0].x === n[n.length - 1].x && n[0].y === n[n.length - 1].y ? n.slice(0, -1) : n).filter((n) => n.length >= 3 && Math.abs(z(n)) > 1e-12);
|
|
132
|
-
}
|
|
133
|
-
function W(e, c) {
|
|
134
|
-
const a = U(e, Math.max(1, Math.round(c.curveSegments ?? 12))), n = new j();
|
|
135
|
-
if (a.length === 0) return n.build();
|
|
136
|
-
const s = a.flat(), i = Math.min(...s.map((p) => p.x)), t = Math.max(...s.map((p) => p.x)), o = Math.min(...s.map((p) => p.y)), r = Math.max(...s.map((p) => p.y)), l = (c.width ?? 1) / Math.max(t - i, 1e-9), u = (i + t) / 2, d = (o + r) / 2, h = a.map((p) => p.map((M) => ({ x: (M.x - u) * l, y: (M.y - d) * l }))), f = h.map((p, M) => h.filter((b, $) => $ !== M && _(p[0], b)).length), m = c.depth / 2, g = -c.depth / 2;
|
|
137
|
-
return h.forEach((p, M) => {
|
|
138
|
-
if (f[M] % 2 === 1) return;
|
|
139
|
-
const b = h.filter((x, v) => f[v] === f[M] + 1 && _(x[0], p)), { points: $, triangles: y } = H(p, b), w = $.map((x) => n.vertex(x.x, x.y, m, 0, 0, 1)), E = $.map((x) => n.vertex(x.x, x.y, g, 0, 0, -1));
|
|
140
|
-
for (let x = 0; x < y.length; x += 3)
|
|
141
|
-
n.triangle(w[y[x]], w[y[x + 1]], w[y[x + 2]]), n.triangle(E[y[x]], E[y[x + 2]], E[y[x + 1]]);
|
|
142
|
-
for (const x of [z(p) >= 0 ? p : [...p].reverse(), ...b.map((v) => z(v) <= 0 ? v : [...v].reverse())])
|
|
143
|
-
for (let v = 0; v < x.length; v++) {
|
|
144
|
-
const q = x[v], A = x[(v + 1) % x.length], I = A.y - q.y, S = -(A.x - q.x), D = n.vertex(q.x, q.y, g, I, S, 0), L = n.vertex(A.x, A.y, g, I, S, 0), O = n.vertex(A.x, A.y, m, I, S, 0), T = n.vertex(q.x, q.y, m, I, S, 0);
|
|
145
|
-
n.quad(D, L, O, T);
|
|
146
|
-
}
|
|
147
|
-
}), n.build();
|
|
148
|
-
}
|
|
149
|
-
const k = Math.PI * 2;
|
|
150
|
-
function Z([e, c, a]) {
|
|
151
|
-
const n = new j(), s = e / 2, i = c / 2, t = a / 2, o = [
|
|
152
|
-
[[0, 0, 1], [[-s, -i, t], [s, -i, t], [s, i, t], [-s, i, t]]],
|
|
153
|
-
[[0, 0, -1], [[s, -i, -t], [-s, -i, -t], [-s, i, -t], [s, i, -t]]],
|
|
154
|
-
[[1, 0, 0], [[s, -i, t], [s, -i, -t], [s, i, -t], [s, i, t]]],
|
|
155
|
-
[[-1, 0, 0], [[-s, -i, -t], [-s, -i, t], [-s, i, t], [-s, i, -t]]],
|
|
156
|
-
[[0, 1, 0], [[-s, i, t], [s, i, t], [s, i, -t], [-s, i, -t]]],
|
|
157
|
-
[[0, -1, 0], [[-s, -i, -t], [s, -i, -t], [s, -i, t], [-s, -i, t]]]
|
|
158
|
-
];
|
|
159
|
-
for (const [[r, l, u], d] of o) {
|
|
160
|
-
const [h, f, m, g] = d.map(([p, M, b]) => n.vertex(p, M, b, r, l, u));
|
|
161
|
-
n.quad(h, f, m, g);
|
|
162
|
-
}
|
|
163
|
-
return n.build();
|
|
164
|
-
}
|
|
165
|
-
function G([e, c], a = 1) {
|
|
166
|
-
const n = new j(), s = Math.max(1, Math.round(a)), i = [];
|
|
167
|
-
for (let t = 0; t <= s; t++) {
|
|
168
|
-
const o = c / 2 - c * t / s;
|
|
169
|
-
i.push(Array.from({ length: s + 1 }, (r, l) => n.vertex(-e / 2 + e * l / s, 0, o, 0, 1, 0)));
|
|
170
|
-
}
|
|
171
|
-
for (let t = 0; t < s; t++)
|
|
172
|
-
for (let o = 0; o < s; o++) n.quad(i[t][o], i[t][o + 1], i[t + 1][o + 1], i[t + 1][o]);
|
|
173
|
-
return n.build();
|
|
174
|
-
}
|
|
175
|
-
function J(e, c = 16) {
|
|
176
|
-
const a = new j(), n = Math.max(6, Math.round(c)), s = Math.max(3, Math.round(n / 2)), i = [];
|
|
177
|
-
for (let t = 0; t <= s; t++) {
|
|
178
|
-
const o = t / s * Math.PI, r = [];
|
|
179
|
-
for (let l = 0; l <= n; l++) {
|
|
180
|
-
const u = l / n * k, d = Math.sin(o) * Math.sin(u), h = Math.cos(o), f = Math.sin(o) * Math.cos(u);
|
|
181
|
-
r.push(a.vertex(d * e, h * e, f * e, d, h, f));
|
|
182
|
-
}
|
|
183
|
-
i.push(r);
|
|
184
|
-
}
|
|
185
|
-
for (let t = 0; t < s; t++)
|
|
186
|
-
for (let o = 0; o < n; o++) {
|
|
187
|
-
const r = i[t][o], l = i[t + 1][o], u = i[t + 1][o + 1], d = i[t][o + 1];
|
|
188
|
-
t > 0 && a.triangle(r, l, d), t < s - 1 && a.triangle(l, u, d);
|
|
189
|
-
}
|
|
190
|
-
return a.build();
|
|
191
|
-
}
|
|
192
|
-
function P(e, c, a, n, s) {
|
|
193
|
-
const i = e.vertex(0, a, 0, 0, n, 0), t = Array.from({ length: s }, (o, r) => {
|
|
194
|
-
const l = r / s * k;
|
|
195
|
-
return e.vertex(Math.sin(l) * c, a, Math.cos(l) * c, 0, n, 0);
|
|
196
|
-
});
|
|
197
|
-
for (let o = 0; o < s; o++) {
|
|
198
|
-
const r = t[o], l = t[(o + 1) % s];
|
|
199
|
-
n === 1 ? e.triangle(i, r, l) : e.triangle(i, l, r);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
function K(e, c, a = 24) {
|
|
203
|
-
const n = new j(), s = Math.max(6, Math.round(a)), i = c / 2, t = -c / 2, o = (u) => Array.from({ length: s + 1 }, (d, h) => {
|
|
204
|
-
const f = h / s * k;
|
|
205
|
-
return n.vertex(Math.sin(f) * e, u, Math.cos(f) * e, Math.sin(f), 0, Math.cos(f));
|
|
206
|
-
}), r = o(t), l = o(i);
|
|
207
|
-
for (let u = 0; u < s; u++) n.quad(r[u], r[u + 1], l[u + 1], l[u]);
|
|
208
|
-
return P(n, e, i, 1, s), P(n, e, t, -1, s), n.build();
|
|
209
|
-
}
|
|
210
|
-
function Q(e, c, a = 24) {
|
|
211
|
-
const n = new j(), s = Math.max(6, Math.round(a)), i = c / 2, t = -c / 2, o = e / c;
|
|
212
|
-
for (let r = 0; r < s; r++) {
|
|
213
|
-
const l = r / s * k, u = (r + 1) / s * k, d = (l + u) / 2, h = n.vertex(Math.sin(l) * e, t, Math.cos(l) * e, Math.sin(l), o, Math.cos(l)), f = n.vertex(Math.sin(u) * e, t, Math.cos(u) * e, Math.sin(u), o, Math.cos(u)), m = n.vertex(0, i, 0, Math.sin(d), o, Math.cos(d));
|
|
214
|
-
n.triangle(h, f, m);
|
|
215
|
-
}
|
|
216
|
-
return P(n, e, t, -1, s), n.build();
|
|
217
|
-
}
|
|
218
|
-
function R(e, c, a = 24) {
|
|
219
|
-
const n = new j(), s = Math.max(6, Math.round(a)), i = Math.max(4, Math.round(s / 2)), t = [];
|
|
220
|
-
for (let o = 0; o <= s; o++) {
|
|
221
|
-
const r = o / s * k, l = [];
|
|
222
|
-
for (let u = 0; u <= i; u++) {
|
|
223
|
-
const d = u / i * k, h = Math.cos(d) * Math.sin(r), f = Math.sin(d), m = Math.cos(d) * Math.cos(r), g = e + c * Math.cos(d);
|
|
224
|
-
l.push(n.vertex(g * Math.sin(r), c * Math.sin(d), g * Math.cos(r), h, f, m));
|
|
225
|
-
}
|
|
226
|
-
t.push(l);
|
|
227
|
-
}
|
|
228
|
-
for (let o = 0; o < s; o++)
|
|
229
|
-
for (let r = 0; r < i; r++) n.quad(t[o][r], t[o + 1][r], t[o + 1][r + 1], t[o][r + 1]);
|
|
230
|
-
return n.build();
|
|
231
|
-
}
|
|
232
|
-
function V(e) {
|
|
233
|
-
switch (e.type) {
|
|
234
|
-
case "box":
|
|
235
|
-
return Z(e.size);
|
|
236
|
-
case "plane":
|
|
237
|
-
return G(e.size, e.segments);
|
|
238
|
-
case "sphere":
|
|
239
|
-
return J(e.radius, e.segments);
|
|
240
|
-
case "cylinder":
|
|
241
|
-
return K(e.radius, e.height, e.segments);
|
|
242
|
-
case "cone":
|
|
243
|
-
return Q(e.radius, e.height, e.segments);
|
|
244
|
-
case "torus":
|
|
245
|
-
return R(e.radius, e.tube, e.segments);
|
|
246
|
-
case "extrude":
|
|
247
|
-
return W(e.path, { depth: e.depth, width: e.width, curveSegments: e.curveSegments });
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
const tt = [
|
|
251
|
-
{ name: "position", vector: "position", components: ["x", "y", "z"] },
|
|
252
|
-
{ name: "rotation", vector: "quaternion", components: ["rotateX", "rotateY", "rotateZ"] }
|
|
253
|
-
];
|
|
254
|
-
function nt(e, c = []) {
|
|
255
|
-
const a = [], n = /* @__PURE__ */ new Map();
|
|
256
|
-
for (const t of e.objects) {
|
|
257
|
-
if (t.id ? n.has(t.id) && a.push(`two objects share the id "${t.id}"`) : a.push("an object has no id"), t.parent !== void 0 && !n.has(t.parent) && a.push(`"${t.id}" has parent "${t.parent}", which must be an earlier object`), t.quaternion && t.quaternion.length !== 4 && a.push(`"${t.id}": a quaternion has four numbers`), t.kind === "mesh") {
|
|
258
|
-
e.materials?.[t.material] || a.push(`"${t.id}" uses material "${t.material}", which is not in materials`);
|
|
259
|
-
const o = t.geometry, r = o.type === "box" || o.type === "plane" ? o.size : o.type === "torus" ? [o.radius, o.tube] : o.type === "sphere" ? [o.radius] : o.type === "extrude" ? [o.depth, o.width ?? 1] : [o.radius, o.height];
|
|
260
|
-
o.type === "extrude" && !(typeof o.path == "string" && /^\s*[Mm]/.test(o.path)) && a.push(`"${t.id}": an extrude needs a path that starts with M`), r.every((l) => Number.isFinite(l) && l > 0) || a.push(`"${t.id}": a ${o.type}'s sizes must be positive`);
|
|
261
|
-
}
|
|
262
|
-
if (t.kind === "line" || t.kind === "trail") {
|
|
263
|
-
t.width !== void 0 && !(t.width > 0) && a.push(`"${t.id}": width must be positive`);
|
|
264
|
-
for (const o of ["taper", "fade", "opacity"]) {
|
|
265
|
-
const r = t[o];
|
|
266
|
-
r !== void 0 && !(r >= 0 && r <= 1) && a.push(`"${t.id}": ${o} is between 0 and 1`);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
t.kind === "line" && (Array.isArray(t.points) && t.points.length >= 2 && t.points.every((r) => Array.isArray(r) && r.length === 3 && r.every(Number.isFinite)) || a.push(`"${t.id}": a line needs two or more points of three numbers`)), t.kind === "trail" && (t.length > 0 || a.push(`"${t.id}": a trail's length (ms) must be positive`), (t.follow === t.id || !e.objects.some((o) => o.id === t.follow)) && a.push(`"${t.id}" follows "${t.follow}", which is not another object in the scene`), t.samples !== void 0 && !(t.samples >= 2) && a.push(`"${t.id}": a trail needs at least 2 samples`)), t.kind === "camera" && (t.near > 0 && t.far > t.near || a.push(`camera "${t.id}": near must be above 0 and far beyond it`), t.projection === "perspective" && !(t.fov > 0 && t.fov < 180) && a.push(`camera "${t.id}": fov is between 0 and 180 degrees`), t.projection === "orthographic" && !(t.height > 0) && a.push(`camera "${t.id}": height must be positive`)), t.id && n.set(t.id, t);
|
|
270
|
-
}
|
|
271
|
-
const s = n.get(e.camera);
|
|
272
|
-
s ? s.kind !== "camera" && a.push(`the scene's camera "${e.camera}" is a ${s.kind}, not a camera`) : a.push(`the scene's camera "${e.camera}" is not one of its objects`), e.fog && !(e.fog.far > e.fog.near) && a.push("fog: far must be beyond near");
|
|
273
|
-
const i = /* @__PURE__ */ new Map();
|
|
274
|
-
for (const t of c) {
|
|
275
|
-
if (!t.target.startsWith(`${e.id}/`)) continue;
|
|
276
|
-
const o = t.target.slice(e.id.length + 1);
|
|
277
|
-
i.has(o) || i.set(o, /* @__PURE__ */ new Set()), i.get(o).add(t.property);
|
|
278
|
-
}
|
|
279
|
-
for (const [t, o] of i) {
|
|
280
|
-
n.has(t) || a.push(`a track animates "${e.id}/${t}", which is not in the scene`);
|
|
281
|
-
for (const r of tt)
|
|
282
|
-
o.has(r.vector) && r.components.some((l) => o.has(l)) && a.push(`"${t}": its ${r.name} is animated both by ${r.vector} and by ${r.components.join(" / ")}; use one`);
|
|
283
|
-
}
|
|
284
|
-
return a;
|
|
285
|
-
}
|
|
286
|
-
function et(e) {
|
|
287
|
-
const c = Array.from({ length: e.indices.length / 3 }, () => []);
|
|
288
|
-
for (const a of C(e))
|
|
289
|
-
for (const n of a.faces) {
|
|
290
|
-
const s = a.faces.find((i) => i !== n) ?? -1;
|
|
291
|
-
c[n].push({ a: a.a, b: a.b, across: s });
|
|
292
|
-
}
|
|
293
|
-
return { ...e, faceEdges: c };
|
|
294
|
-
}
|
|
295
|
-
function at(e, c = {}) {
|
|
296
|
-
const a = new Map((c.kinds ?? []).map((t) => [t.kind, t])), n = nt(e);
|
|
297
|
-
for (const t of e.objects) {
|
|
298
|
-
if (st.has(t.kind)) continue;
|
|
299
|
-
const o = a.get(t.kind);
|
|
300
|
-
o ? n.push(...(o.validate?.(t) ?? []).map((r) => `"${t.id}": ${r}`)) : n.push(`"${t.id}" is a ${t.kind}: load the scene with that kind (for characters: loadScene3D(scene, { kinds: [characterObjects] }), from @algorisys/tinyfly/characters)`);
|
|
301
|
-
}
|
|
302
|
-
if (n.length > 0) throw new Error(`scene-3d: "${e.id}" is not valid:
|
|
303
|
-
- ${n.join(`
|
|
304
|
-
- `)}`);
|
|
305
|
-
const s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
306
|
-
for (const t of e.objects) {
|
|
307
|
-
t.kind === "mesh" && s.set(t.id, et(V(t.geometry)));
|
|
308
|
-
const o = a.get(t.kind);
|
|
309
|
-
o?.prepare && i.set(t.id, o.prepare(t));
|
|
310
|
-
}
|
|
311
|
-
return { scene: e, meshes: s, kinds: a, prepared: i };
|
|
312
|
-
}
|
|
313
|
-
const st = /* @__PURE__ */ new Set(["group", "mesh", "camera", "light", "line", "trail"]);
|
|
314
|
-
export {
|
|
315
|
-
j as M,
|
|
316
|
-
K as a,
|
|
317
|
-
Z as b,
|
|
318
|
-
Q as c,
|
|
319
|
-
_ as d,
|
|
320
|
-
W as e,
|
|
321
|
-
et as f,
|
|
322
|
-
V as g,
|
|
323
|
-
J as h,
|
|
324
|
-
H as i,
|
|
325
|
-
at as l,
|
|
326
|
-
C as m,
|
|
327
|
-
G as p,
|
|
328
|
-
z as s,
|
|
329
|
-
R as t,
|
|
330
|
-
nt as v
|
|
331
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { vec3 as f } from "@algorisys/tinyfly";
|
|
2
|
-
const b = /* @__PURE__ */ new Map();
|
|
3
|
-
function M(n) {
|
|
4
|
-
const i = b.get(n);
|
|
5
|
-
if (i) return i;
|
|
6
|
-
let r = [1, 1, 1];
|
|
7
|
-
const o = n.trim().replace("#", "");
|
|
8
|
-
if (n.trim().startsWith("#") && (o.length === 3 || o.length === 6)) {
|
|
9
|
-
const t = o.length === 3 ? o.split("").map((s) => s + s).join("") : o;
|
|
10
|
-
r = [0, 2, 4].map((s) => Number.parseInt(t.slice(s, s + 2), 16) / 255);
|
|
11
|
-
} else {
|
|
12
|
-
const t = n.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);
|
|
13
|
-
t && (r = [Number(t[1]) / 255, Number(t[2]) / 255, Number(t[3]) / 255]);
|
|
14
|
-
}
|
|
15
|
-
return b.size < 512 && b.set(n, r), r;
|
|
16
|
-
}
|
|
17
|
-
const x = [
|
|
18
|
-
{ id: "default-ambient", light: "ambient", color: "#ffffff", intensity: 0.35, position: [0, 0, 0], direction: [0, -1, 0], angle: 30 },
|
|
19
|
-
{ id: "default-key", light: "directional", color: "#ffffff", intensity: 0.8, position: [3, 5, 4], direction: f.normalize([-3, -5, -4]), angle: 30 }
|
|
20
|
-
], y = (n, i, r) => {
|
|
21
|
-
const o = Math.min(1, Math.max(0, (r - n) / (i - n)));
|
|
22
|
-
return o * o * (3 - 2 * o);
|
|
23
|
-
};
|
|
24
|
-
function g(n, i, r) {
|
|
25
|
-
const o = [0, 0, 0];
|
|
26
|
-
for (const t of r) {
|
|
27
|
-
const s = M(t.color);
|
|
28
|
-
let l;
|
|
29
|
-
if (t.light === "ambient")
|
|
30
|
-
l = t.intensity;
|
|
31
|
-
else if (t.light === "directional")
|
|
32
|
-
l = t.intensity * Math.max(0, -f.dot(i, t.direction));
|
|
33
|
-
else {
|
|
34
|
-
const e = f.subtract(t.position, n), m = f.length(e), d = m > 0 ? f.scale(e, 1 / m) : i, a = t.range ? Math.max(0, 1 - m / t.range) ** 2 : 1;
|
|
35
|
-
if (l = t.intensity * Math.max(0, f.dot(i, d)) * a, t.light === "spot") {
|
|
36
|
-
const c = Math.cos(t.angle * Math.PI / 180), h = Math.cos(t.angle * 0.8 * Math.PI / 180);
|
|
37
|
-
l *= y(c, h, -f.dot(d, t.direction));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
o[0] += s[0] * l, o[1] += s[1] * l, o[2] += s[2] * l;
|
|
41
|
-
}
|
|
42
|
-
return o;
|
|
43
|
-
}
|
|
44
|
-
function v(n, i) {
|
|
45
|
-
const r = Math.max(2, Math.round(i));
|
|
46
|
-
return Math.min(1.2, Math.ceil(Math.min(1, n) * r - 1e-9) / r);
|
|
47
|
-
}
|
|
48
|
-
function N(n, i) {
|
|
49
|
-
return n ? Math.min(1, Math.max(0, (i - n.near) / (n.far - n.near))) : 0;
|
|
50
|
-
}
|
|
51
|
-
function C(n, i, r, o) {
|
|
52
|
-
const t = n.material, s = M(n.color ?? t.color), l = t.shading ?? "lambert";
|
|
53
|
-
let e;
|
|
54
|
-
if (l === "unlit")
|
|
55
|
-
e = [...s];
|
|
56
|
-
else {
|
|
57
|
-
const a = i.length > 0 ? i : x;
|
|
58
|
-
let c;
|
|
59
|
-
if (l === "lambert") {
|
|
60
|
-
const h = [0, 0, 0];
|
|
61
|
-
for (const u of n.vertexNormals) {
|
|
62
|
-
const p = g(n.centroid, u, a);
|
|
63
|
-
h[0] += p[0] / 3, h[1] += p[1] / 3, h[2] += p[2] / 3;
|
|
64
|
-
}
|
|
65
|
-
c = h;
|
|
66
|
-
} else if (c = g(n.centroid, n.normal, a), l === "toon") {
|
|
67
|
-
const h = Math.max(c[0], c[1], c[2]), u = h > 0 ? v(h, t.bands ?? 3) / h : 0;
|
|
68
|
-
c = [c[0] * u, c[1] * u, c[2] * u];
|
|
69
|
-
}
|
|
70
|
-
e = [s[0] * c[0], s[1] * c[1], s[2] * c[2]];
|
|
71
|
-
}
|
|
72
|
-
if (t.emissive) {
|
|
73
|
-
const a = M(t.emissive);
|
|
74
|
-
e = [e[0] + a[0], e[1] + a[1], e[2] + a[2]];
|
|
75
|
-
}
|
|
76
|
-
const m = N(o, f.distance(n.centroid, r.position));
|
|
77
|
-
if (o && m > 0) {
|
|
78
|
-
const a = M(o.color);
|
|
79
|
-
e = [e[0] + (a[0] - e[0]) * m, e[1] + (a[1] - e[1]) * m, e[2] + (a[2] - e[2]) * m];
|
|
80
|
-
}
|
|
81
|
-
const d = (a) => Math.round(Math.min(1, Math.max(0, a)) * 255);
|
|
82
|
-
return { color: `rgb(${d(e[0])}, ${d(e[1])}, ${d(e[2])})`, alpha: n.opacity };
|
|
83
|
-
}
|
|
84
|
-
export {
|
|
85
|
-
N as f,
|
|
86
|
-
g as l,
|
|
87
|
-
M as p,
|
|
88
|
-
C as s
|
|
89
|
-
};
|