@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
@@ -1,331 +1,484 @@
1
- import { M as mt, b as vt, c as Mt, a as bt, e as kt, g as At, l as It, m as Pt, p as St, d as Tt, f as Et, s as Ct, h as Dt, t as Ot, i as $t, v as Nt } from "./load-scene-CQvcFWGJ.js";
2
- import { vec3 as u, mat4 as I, ribbon as K, ribbonHeadCap as Q, quat as N, trailSamples as U } from "@algorisys/tinyfly";
3
- import { p as z, f as G, s as q } from "./shading-o5T_v9DT.js";
4
- import { l as Wt } from "./shading-o5T_v9DT.js";
5
- function x(t, e) {
6
- const i = u.normalize(u.subtract(e, t)), n = Math.abs(i[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0];
7
- return I.lookAt(t, e, n);
8
- }
9
- function dt(t, e, i, n) {
10
- const s = e * Math.PI / 180, a = i * Math.PI / 180;
11
- return [t[0] + n * Math.cos(a) * Math.sin(s), t[1] + n * Math.sin(a), t[2] + n * Math.cos(a) * Math.cos(s)];
12
- }
13
- function pt(t, e, i) {
14
- const n = u.subtract(t, e), s = u.length(n);
15
- if (s === 0) return t;
16
- const a = Math.max(1e-3, s - i);
17
- return u.add(e, u.scale(n, a / s));
18
- }
19
- function Y(t, e) {
20
- if (t.projection === "perspective") return I.perspective(t.fov, e, t.near, t.far);
21
- const i = t.height / 2;
22
- return I.orthographic(-i * e, i * e, -i, i, t.near, t.far);
23
- }
24
- function j(t, e, i, n) {
25
- const { camera: s } = n, a = s.near, r = t.map((d) => I.transformPoint(s.view, d)), p = s.projection[5] * n.height / 2, f = (d, h) => i.width * (1 - i.taper * d) * p / (s.orthographic ? 1 : Math.max(h, a)), k = z(i.color), y = [];
26
- let M = [];
27
- const E = (d) => -d[2] >= a;
28
- for (let d = 0; d < r.length; d++) {
29
- const h = r[d];
30
- E(h) ? (M.length === 0 && d > 0 && !E(r[d - 1]) && M.push(_(r[d - 1], h, e[d - 1], e[d], a)), M.push({ view: h, age: e[d] })) : M.length > 0 && (M.push(_(r[d - 1], h, e[d - 1], e[d], a)), y.push(M), M = []);
31
- }
32
- M.length > 0 && y.push(M);
33
- const C = [];
34
- for (const d of y) {
35
- if (d.length < 2) continue;
36
- const h = d.map((l) => -l.view[2]), o = d.map((l) => n.toScreen(l.view)).map((l, w) => ({ x: l.x, y: l.y, width: f(d[w].age, h[w]) })), c = K(o), b = d[d.length - 1].age === 0 ? Q(o) : null;
37
- for (let l = 0; l + 1 < d.length; l++) {
38
- const w = (h[l] + h[l + 1]) / 2;
39
- if (w > s.far) continue;
40
- let m = i.opacity * (1 - i.fade * ((d[l].age + d[l + 1].age) / 2));
41
- const O = u.lerp(d[l].view, d[l + 1].view, 0.5), S = G(n.fog, u.length(O));
42
- let D = k;
43
- if (n.fog && S > 0)
44
- if (i.additive) m *= 1 - S;
1
+ import { M as sn, b as rn, c as an, a as cn, e as ln, g as dn, l as hn, m as fn, p as un, d as gn, f as pn, r as yn, s as mn, h as kn, t as wn, i as Mn, v as vn } from "./load-scene-oWNsYYC1.js";
2
+ import { vec3 as A, mat4 as P, quat as F, ribbon as dt, ribbonHeadCap as ht, trailSamples as ft, getEasingFunction as ut, loopNoise as gt } from "@algorisys/tinyfly";
3
+ import { p as N, f as pt, s as q, i as j } from "./shading-0lPgnXmD.js";
4
+ import { l as xn } from "./shading-0lPgnXmD.js";
5
+ function yt(t, n, o = {}) {
6
+ const e = A.normalize(A.subtract(n, t)), i = o.up ?? (Math.abs(e[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0]);
7
+ return tt(P.lookAt(t, n, i), o.roll ?? 0);
8
+ }
9
+ function tt(t, n) {
10
+ return n ? P.multiply(P.fromQuat(F.fromAxisAngle([0, 0, 1], -n)), t) : t;
11
+ }
12
+ function L(t, n, o, e) {
13
+ const i = n * Math.PI / 180, a = o * Math.PI / 180;
14
+ return [t[0] + e * Math.cos(a) * Math.sin(i), t[1] + e * Math.sin(a), t[2] + e * Math.cos(a) * Math.cos(i)];
15
+ }
16
+ function Rt(t, n, o) {
17
+ const e = A.subtract(t, n), i = A.length(e);
18
+ if (i === 0) return t;
19
+ const a = Math.max(1e-3, i - o);
20
+ return A.add(n, A.scale(e, a / i));
21
+ }
22
+ function J(t, n) {
23
+ if (t.projection === "perspective") return P.perspective(t.fov, n, t.near, t.far);
24
+ const o = t.height / 2;
25
+ return P.orthographic(-o * n, o * n, -o, o, t.near, t.far);
26
+ }
27
+ function mt(t, n, o, e) {
28
+ const { camera: i } = e, a = i.near, r = t.map((p) => P.transformPoint(i.view, p)), l = i.projection[5] * e.height / 2, c = (p, h) => o.width * (1 - o.taper * p) * l / (i.orthographic ? 1 : Math.max(h, a)), u = N(o.color), g = [];
29
+ let m = [];
30
+ const v = (p) => -p[2] >= a;
31
+ for (let p = 0; p < r.length; p++) {
32
+ const h = r[p];
33
+ v(h) ? (m.length === 0 && p > 0 && !v(r[p - 1]) && m.push(K(r[p - 1], h, n[p - 1], n[p], a)), m.push({ view: h, age: n[p] })) : m.length > 0 && (m.push(K(r[p - 1], h, n[p - 1], n[p], a)), g.push(m), m = []);
34
+ }
35
+ m.length > 0 && g.push(m);
36
+ const $ = [];
37
+ for (const p of g) {
38
+ if (p.length < 2) continue;
39
+ const h = p.map((f) => -f.view[2]), b = p.map((f) => e.toScreen(f.view)).map((f, w) => ({ x: f.x, y: f.y, width: c(p[w].age, h[w]) })), s = dt(b), d = p[p.length - 1].age === 0 ? ht(b) : null;
40
+ for (let f = 0; f + 1 < p.length; f++) {
41
+ const w = (h[f] + h[f + 1]) / 2;
42
+ if (w > i.far) continue;
43
+ let x = o.opacity * (1 - o.fade * ((p[f].age + p[f + 1].age) / 2));
44
+ const k = A.lerp(p[f].view, p[f + 1].view, 0.5), I = pt(e.fog, A.length(k));
45
+ let T = u;
46
+ if (e.fog && I > 0)
47
+ if (o.additive) x *= 1 - I;
45
48
  else {
46
- const v = z(n.fog.color);
47
- D = [k[0] + (v[0] - k[0]) * S, k[1] + (v[1] - k[1]) * S, k[2] + (v[2] - k[2]) * S];
49
+ const y = N(e.fog.color);
50
+ T = [u[0] + (y[0] - u[0]) * I, u[1] + (y[1] - u[1]) * I, u[2] + (y[2] - u[2]) * I];
48
51
  }
49
- if (m <= 0) continue;
50
- const $ = `rgb(${D.map((v) => Math.round(Math.min(1, Math.max(0, v)) * 255)).join(", ")})`, g = [c.left[l], c.left[l + 1], c.right[l + 1], c.right[l]], T = l + 2 === d.length ? b : null;
51
- C.push({
52
+ if (x <= 0) continue;
53
+ const D = `rgb(${T.map((y) => Math.round(Math.min(1, Math.max(0, y)) * 255)).join(", ")})`, S = [s.left[f], s.left[f + 1], s.right[f + 1], s.right[f]], E = f + 2 === p.length ? d : null;
54
+ $.push({
52
55
  depth: w,
53
- draw(v) {
54
- i.additive && (v.globalCompositeOperation = "lighter"), v.globalAlpha = Math.min(1, m), v.fillStyle = $, v.beginPath(), v.moveTo(g[0].x, g[0].y), v.lineTo(g[1].x, g[1].y), T && v.arc(T.x, T.y, T.radius, T.start, T.start - Math.PI, !0), v.lineTo(g[2].x, g[2].y), v.lineTo(g[3].x, g[3].y), v.closePath(), v.fill(), !i.additive && m >= 1 && (v.strokeStyle = $, v.lineWidth = 0.75, v.stroke());
56
+ draw(y) {
57
+ o.additive && (y.globalCompositeOperation = "lighter"), y.globalAlpha = Math.min(1, x), y.fillStyle = D, y.beginPath(), y.moveTo(S[0].x, S[0].y), y.lineTo(S[1].x, S[1].y), E && y.arc(E.x, E.y, E.radius, E.start, E.start - Math.PI, !0), y.lineTo(S[2].x, S[2].y), y.lineTo(S[3].x, S[3].y), y.closePath(), y.fill(), !o.additive && x >= 1 && (y.strokeStyle = D, y.lineWidth = 0.75, y.stroke());
55
58
  }
56
59
  });
57
60
  }
58
61
  }
59
- return C;
62
+ return $;
60
63
  }
61
- function _(t, e, i, n, s) {
62
- const a = (-s - t[2]) / (e[2] - t[2]);
63
- return { view: u.lerp(t, e, a), age: i + (n - i) * a };
64
+ function K(t, n, o, e, i) {
65
+ const a = (-i - t[2]) / (n[2] - t[2]);
66
+ return { view: A.lerp(t, n, a), age: o + (e - o) * a };
64
67
  }
65
- const tt = Math.cos(30 * Math.PI / 180), L = /* @__PURE__ */ new Map(), A = (t) => typeof t == "number" ? t : void 0, R = (t, e) => Array.isArray(t) && t.length === e ? t : void 0;
66
- function V(t, e) {
67
- const i = t.position ?? [0, 0, 0], n = R(e.get("position"), 3) ?? [
68
- A(e.get("x")) ?? i[0],
69
- A(e.get("y")) ?? i[1],
70
- A(e.get("z")) ?? i[2]
68
+ const kt = Math.cos(30 * Math.PI / 180), nt = /* @__PURE__ */ new Map(), C = (t) => typeof t == "number" ? t : void 0, W = (t, n) => Array.isArray(t) && t.length === n ? t : void 0;
69
+ function ot(t, n) {
70
+ const o = t.position ?? [0, 0, 0], e = W(n.get("position"), 3) ?? [
71
+ C(n.get("x")) ?? o[0],
72
+ C(n.get("y")) ?? o[1],
73
+ C(n.get("z")) ?? o[2]
71
74
  ];
72
- let s;
73
- const a = R(e.get("quaternion"), 4), r = ["rotateX", "rotateY", "rotateZ"].map((y) => A(e.get(y)));
74
- if (a) s = N.normalize(a);
75
- else if (r.some((y) => y !== void 0)) {
76
- const y = t.rotation ?? [0, 0, 0];
77
- s = N.fromEuler(r[0] ?? y[0], r[1] ?? y[1], r[2] ?? y[2]);
78
- } else t.quaternion ? s = N.normalize(t.quaternion) : s = t.rotation ? N.fromEuler(...t.rotation) : N.identity();
79
- const p = typeof t.scale == "number" ? [t.scale, t.scale, t.scale] : t.scale ?? [1, 1, 1], f = A(e.get("scale")), k = [
80
- A(e.get("scaleX")) ?? f ?? p[0],
81
- A(e.get("scaleY")) ?? f ?? p[1],
82
- A(e.get("scaleZ")) ?? f ?? p[2]
75
+ let i;
76
+ const a = W(n.get("quaternion"), 4), r = ["rotateX", "rotateY", "rotateZ"].map((g) => C(n.get(g)));
77
+ if (a) i = F.normalize(a);
78
+ else if (r.some((g) => g !== void 0)) {
79
+ const g = t.rotation ?? [0, 0, 0];
80
+ i = F.fromEuler(r[0] ?? g[0], r[1] ?? g[1], r[2] ?? g[2]);
81
+ } else t.quaternion ? i = F.normalize(t.quaternion) : i = t.rotation ? F.fromEuler(...t.rotation) : F.identity();
82
+ const l = typeof t.scale == "number" ? [t.scale, t.scale, t.scale] : t.scale ?? [1, 1, 1], c = C(n.get("scale")), u = [
83
+ C(n.get("scaleX")) ?? c ?? l[0],
84
+ C(n.get("scaleY")) ?? c ?? l[1],
85
+ C(n.get("scaleZ")) ?? c ?? l[2]
83
86
  ];
84
- return I.compose(n, s, k);
87
+ return P.compose(e, i, u);
85
88
  }
86
- const W = (t) => [t[12], t[13], t[14]];
87
- function et(t, e, i, n) {
88
- const s = W(e), a = R(i.get("lookAt"), 3) ?? t.lookAt, r = a ? x(s, a) : I.invert(e) ?? I.identity(), p = t.projection === "perspective" ? Y({ ...t, fov: A(i.get("fov")) ?? t.fov }, n) : Y({ ...t, height: A(i.get("height")) ?? t.height }, n);
89
+ const Z = (t) => [t[12], t[13], t[14]];
90
+ function wt(t, n, o, e) {
91
+ const i = Z(n), a = W(o.get("lookAt"), 3) ?? t.lookAt, r = C(o.get("roll")) ?? t.roll ?? 0, l = a ? yt(i, a, { up: t.up, roll: r }) : tt(P.invert(n) ?? P.identity(), r), c = t.projection === "perspective" ? J({ ...t, fov: C(o.get("fov")) ?? t.fov }, e) : J({ ...t, height: C(o.get("height")) ?? t.height }, e);
89
92
  return {
90
93
  id: t.id,
91
- view: r,
92
- projection: p,
93
- position: s,
94
- forward: u.normalize([-r[2], -r[6], -r[10]]),
94
+ view: l,
95
+ projection: c,
96
+ position: i,
97
+ forward: A.normalize([-l[2], -l[6], -l[10]]),
95
98
  orthographic: t.projection === "orthographic",
96
99
  near: t.near,
97
100
  far: t.far
98
101
  };
99
102
  }
100
- function F(t) {
101
- return I.transpose(I.invert(t) ?? I.identity());
103
+ function Q(t) {
104
+ return P.transpose(P.invert(t) ?? P.identity());
102
105
  }
103
- function nt(t, e, i, n) {
104
- return u.normalize([t[0] * e + t[4] * i + t[8] * n, t[1] * e + t[5] * i + t[9] * n, t[2] * e + t[6] * i + t[10] * n]);
106
+ function Mt(t, n, o, e) {
107
+ return A.normalize([t[0] * n + t[4] * o + t[8] * e, t[1] * n + t[5] * o + t[9] * e, t[2] * n + t[6] * o + t[10] * e]);
105
108
  }
106
- function ot(t, e) {
107
- const i = (s) => -s[2] >= e, n = [];
108
- for (let s = 0; s < t.length; s++) {
109
- const a = t[s], r = t[(s + 1) % t.length];
110
- if (i(a) && n.push(a), i(a) !== i(r)) {
111
- const p = (-e - a[2]) / (r[2] - a[2]);
112
- n.push(u.lerp(a, r, p));
109
+ function vt(t, n) {
110
+ const o = (i) => -i[2] >= n, e = [];
111
+ for (let i = 0; i < t.length; i++) {
112
+ const a = t[i], r = t[(i + 1) % t.length];
113
+ if (o(a) && e.push(a), o(a) !== o(r)) {
114
+ const l = (-n - a[2]) / (r[2] - a[2]);
115
+ e.push(A.lerp(a, r, l));
113
116
  }
114
117
  }
115
- return n;
116
- }
117
- function X(t, e = /* @__PURE__ */ new Map(), i) {
118
- const { scene: n } = t, s = (o) => e.get(`${n.id}/${o}`) ?? L, a = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
119
- for (const o of n.objects) {
120
- const c = s(o.id), b = V(o, c), l = o.parent ? a.get(o.parent) : void 0;
121
- a.set(o.id, l ? I.multiply(l, b) : b);
122
- const w = A(c.get("visible")) !== void 0 ? A(c.get("visible")) > 0.5 : o.visible !== !1;
123
- r.set(o.id, w && (o.parent ? r.get(o.parent) !== !1 : !0));
124
- }
125
- const p = e.get(n.id)?.get("activeCamera"), f = typeof p == "string" && n.objects.some((o) => o.id === p && o.kind === "camera") ? p : n.camera, k = n.objects.find((o) => o.id === f), y = et(k, a.get(f), s(f), i.width / i.height), M = (o) => {
126
- const c = I.transformPoint(y.projection, o);
127
- return { x: (c[0] + 1) / 2 * i.width, y: (1 - c[1]) / 2 * i.height };
128
- }, E = [];
129
- for (const o of n.objects) {
130
- if (o.kind !== "light" || !r.get(o.id)) continue;
131
- const c = s(o.id), b = W(a.get(o.id)), l = R(c.get("target"), 3) ?? o.target ?? [0, 0, 0], w = c.get("color");
132
- E.push({
133
- id: o.id,
134
- light: o.light,
135
- color: typeof w == "string" ? w : o.color,
136
- intensity: A(c.get("intensity")) ?? o.intensity,
137
- position: b,
138
- direction: u.normalize(u.subtract(l, b)),
139
- range: o.range,
140
- angle: o.angle ?? 30
118
+ return e;
119
+ }
120
+ function bt(t, n, o, e = 16) {
121
+ const i = [t[0], t[1], t[2]], a = [0, 1, 0], r = [];
122
+ for (let c = 0; c < e; c++) {
123
+ const u = c / e * Math.PI * 2;
124
+ i.push(t[0] + Math.cos(u) * n, t[1], t[2] + Math.sin(u) * o), a.push(0, 1, 0);
125
+ }
126
+ for (let c = 0; c < e; c++) r.push(0, 1 + (c + 1) % e, 1 + c);
127
+ const l = Array.from({ length: e }, () => []);
128
+ return { positions: i, normals: a, indices: r, faceEdges: l };
129
+ }
130
+ function xt(t, n) {
131
+ const o = C(n.get("outlineWidth")) ?? t.outline?.width, e = n.get("outlineColor"), i = (typeof e == "string" ? e : void 0) ?? t.outline?.color ?? "#000000";
132
+ return o !== void 0 && o > 0 ? { width: o, color: i } : void 0;
133
+ }
134
+ function At(t, n) {
135
+ return !t || t.to <= t.from ? 1 : Math.min(1, Math.max(0, (n - t.from) / (t.to - t.from)));
136
+ }
137
+ function et(t, n = /* @__PURE__ */ new Map(), o) {
138
+ const { scene: e } = t, i = (s) => n.get(`${e.id}/${s}`) ?? nt, a = o.nearFade ?? e.nearFade, r = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
139
+ for (const s of e.objects) {
140
+ const d = i(s.id), f = ot(s, d), w = s.parent ? r.get(s.parent) : void 0;
141
+ r.set(s.id, w ? P.multiply(w, f) : f);
142
+ const x = C(d.get("visible")) !== void 0 ? C(d.get("visible")) > 0.5 : s.visible !== !1;
143
+ l.set(s.id, x && (s.parent ? l.get(s.parent) !== !1 : !0));
144
+ }
145
+ const c = n.get(e.id)?.get("activeCamera"), u = typeof c == "string" && e.objects.some((s) => s.id === c && s.kind === "camera") ? c : e.camera, g = e.objects.find((s) => s.id === u), m = wt(g, r.get(u), i(u), o.width / o.height), v = (s) => {
146
+ const d = P.transformPoint(m.projection, s);
147
+ return { x: (d[0] + 1) / 2 * o.width, y: (1 - d[1]) / 2 * o.height };
148
+ }, $ = [];
149
+ for (const s of e.objects) {
150
+ if (s.kind !== "light" || !l.get(s.id)) continue;
151
+ const d = i(s.id), f = Z(r.get(s.id)), w = W(d.get("target"), 3) ?? s.target ?? [0, 0, 0], x = d.get("color");
152
+ $.push({
153
+ id: s.id,
154
+ light: s.light,
155
+ color: typeof x == "string" ? x : s.color,
156
+ intensity: C(d.get("intensity")) ?? s.intensity,
157
+ position: f,
158
+ direction: A.normalize(A.subtract(w, f)),
159
+ range: s.range,
160
+ angle: s.angle ?? 30
141
161
  });
142
162
  }
143
- const C = [], d = [];
144
- n.objects.forEach((o, c) => {
145
- if (o.kind !== "mesh" || !r.get(o.id)) return;
146
- const b = t.meshes.get(o.id), l = n.materials?.[o.material];
147
- if (!b || !l) return;
148
- const w = s(o.id), m = a.get(o.id), O = F(m), S = w.get("color"), D = (A(w.get("opacity")) ?? 1) * (l.opacity ?? 1);
149
- D <= 0 || (d.push({ objectId: o.id, objectIndex: c, mesh: b, world: m, material: l, color: typeof S == "string" ? S : void 0, opacity: D }), C.push(...H(b, m, O, y, M, l, {
150
- objectId: o.id,
151
- objectIndex: c,
152
- layer: o.layer ?? 0,
153
- color: typeof S == "string" ? S : void 0,
154
- opacity: D
155
- })));
163
+ const p = [], h = [];
164
+ e.objects.forEach((s, d) => {
165
+ if (s.kind !== "mesh" || !l.get(s.id)) return;
166
+ const f = t.meshes.get(s.id), w = e.materials?.[s.material];
167
+ if (!f || !w) return;
168
+ const x = i(s.id), k = r.get(s.id), I = Q(k), T = x.get("color"), D = (C(x.get("opacity")) ?? 1) * (w.opacity ?? 1);
169
+ if (D <= 0) return;
170
+ const S = xt(w, x), E = S === w.outline || S && w.outline && S.width === w.outline.width && S.color === w.outline.color ? w : { ...w, outline: S };
171
+ h.push({ objectId: s.id, objectIndex: d, mesh: f, world: k, material: E, color: typeof T == "string" ? T : void 0, opacity: D }), p.push(..._(f, k, I, m, v, E, {
172
+ objectId: s.id,
173
+ objectIndex: d,
174
+ layer: s.layer ?? 0,
175
+ color: typeof T == "string" ? T : void 0,
176
+ opacity: D,
177
+ ink: S,
178
+ nearFade: a
179
+ }));
180
+ }), e.objects.forEach((s, d) => {
181
+ if (s.kind !== "mesh" || !s.shadow || !l.get(s.id)) return;
182
+ const f = t.meshes.get(s.id);
183
+ if (!f) return;
184
+ const w = i(s.id);
185
+ if ((C(w.get("opacity")) ?? 1) <= 0) return;
186
+ const x = r.get(s.id), k = s.shadow === !0 ? {} : s.shadow, I = k.ground ?? e.ground ?? 0;
187
+ let T = 1 / 0, D = -1 / 0, S = 1 / 0, E = 1 / 0, y = -1 / 0;
188
+ for (let O = 0; O < f.positions.length; O += 3) {
189
+ const R = P.transformPoint(x, [f.positions[O], f.positions[O + 1], f.positions[O + 2]]);
190
+ T = Math.min(T, R[0]), D = Math.max(D, R[0]), S = Math.min(S, R[1]), E = Math.min(E, R[2]), y = Math.max(y, R[2]);
191
+ }
192
+ const z = Math.max(D - T, y - E);
193
+ if (!(z > 0)) return;
194
+ const X = Math.max(0, S - I), Y = Math.min(1, X / (2 * z)), H = (k.opacity ?? 0.22) * (1 - Y * 0.8);
195
+ if (H <= 0.01) return;
196
+ const G = 1.1 + Y * 0.4, ct = bt([(T + D) / 2, I + 2e-3, (E + y) / 2], (D - T) / 2 * G, (y - E) / 2 * G), lt = { color: "#000000", shading: "unlit", opacity: H };
197
+ p.push(..._(ct, P.identity(), P.identity(), m, v, lt, {
198
+ objectId: `${s.id}:shadow`,
199
+ objectIndex: d - 0.5,
200
+ layer: s.layer ?? 0,
201
+ opacity: H,
202
+ nearFade: a
203
+ }));
156
204
  });
157
- const h = [];
158
- n.objects.forEach((o, c) => {
159
- const b = t.kinds.get(o.kind);
160
- if (!b || !r.get(o.id)) return;
161
- const l = b.resolve({
162
- object: o,
163
- prepared: t.prepared.get(o.id),
164
- values: s(o.id),
165
- world: a.get(o.id),
166
- camera: y,
167
- lights: E,
168
- fog: n.fog,
169
- width: i.width,
170
- height: i.height,
171
- toScreen: M
205
+ const M = [];
206
+ e.objects.forEach((s, d) => {
207
+ const f = t.kinds.get(s.kind);
208
+ if (!f || !l.get(s.id)) return;
209
+ const w = f.resolve({
210
+ object: s,
211
+ prepared: t.prepared.get(s.id),
212
+ values: i(s.id),
213
+ world: r.get(s.id),
214
+ camera: m,
215
+ lights: $,
216
+ fog: e.fog,
217
+ width: o.width,
218
+ height: o.height,
219
+ toScreen: v
172
220
  });
173
- if (!l) return;
174
- const w = o.layer ?? 0;
175
- for (const m of l.drawables ?? []) h.push({ ...m, objectId: o.id, objectIndex: c, layer: w });
176
- for (const m of l.meshes ?? [])
177
- d.push({ objectId: o.id, objectIndex: c, mesh: m.mesh, world: m.world, material: m.material, opacity: m.material.opacity ?? 1 }), C.push(...H(m.mesh, m.world, F(m.world), y, M, m.material, {
178
- objectId: o.id,
179
- objectIndex: c,
180
- layer: w,
181
- opacity: m.material.opacity ?? 1
221
+ if (!w) return;
222
+ const x = s.layer ?? 0;
223
+ for (const k of w.drawables ?? []) M.push({ ...k, objectId: s.id, objectIndex: d, layer: x });
224
+ for (const k of w.meshes ?? [])
225
+ h.push({ objectId: s.id, objectIndex: d, mesh: k.mesh, world: k.world, material: k.material, opacity: k.material.opacity ?? 1 }), p.push(..._(k.mesh, k.world, Q(k.world), m, v, k.material, {
226
+ objectId: s.id,
227
+ objectIndex: d,
228
+ layer: x,
229
+ opacity: k.material.opacity ?? 1,
230
+ ink: k.material.outline,
231
+ nearFade: a
182
232
  }));
183
233
  });
184
- const P = { camera: y, height: i.height, fog: n.fog, toScreen: M };
185
- return n.objects.forEach((o, c) => {
186
- if (o.kind !== "line" && o.kind !== "trail" || !r.get(o.id)) return;
187
- const b = s(o.id), l = o.kind === "line" ? st(o, a.get(o.id)) : rt(o, n, e, i);
188
- if (!l) return;
189
- const w = it(o, b);
190
- if (w.opacity <= 0 || w.width <= 0) return;
191
- const m = o.layer ?? 0;
192
- for (const O of j(l.points, l.ages, w, P)) h.push({ ...O, objectId: o.id, objectIndex: c, layer: m });
193
- }), h.sort((o, c) => o.layer - c.layer || c.depth - o.depth || o.objectIndex - c.objectIndex), C.sort((o, c) => o.layer - c.layer || c.depth - o.depth || o.objectIndex - c.objectIndex || o.face - c.face || o.part - c.part), {
194
- id: n.id,
195
- width: i.width,
196
- height: i.height,
197
- background: n.background,
198
- fog: n.fog,
199
- camera: y,
200
- lights: E,
201
- worlds: a,
202
- triangles: C,
203
- drawables: h,
204
- meshes: d,
205
- time: i.time ?? 0
234
+ const b = { camera: m, height: o.height, fog: e.fog, toScreen: v };
235
+ return e.objects.forEach((s, d) => {
236
+ if (s.kind !== "line" && s.kind !== "trail" || !l.get(s.id)) return;
237
+ const f = i(s.id), w = s.kind === "line" ? It(s, r.get(s.id)) : St(s, e, n, o);
238
+ if (!w) return;
239
+ const x = $t(s, f);
240
+ if (x.opacity <= 0 || x.width <= 0) return;
241
+ const k = s.layer ?? 0;
242
+ for (const I of mt(w.points, w.ages, x, b)) M.push({ ...I, objectId: s.id, objectIndex: d, layer: k });
243
+ }), M.sort((s, d) => s.layer - d.layer || d.depth - s.depth || s.objectIndex - d.objectIndex), p.sort((s, d) => s.layer - d.layer || d.depth - s.depth || s.objectIndex - d.objectIndex || s.face - d.face || s.part - d.part), {
244
+ id: e.id,
245
+ width: o.width,
246
+ height: o.height,
247
+ background: e.background,
248
+ fog: e.fog,
249
+ camera: m,
250
+ lights: $,
251
+ worlds: r,
252
+ triangles: p,
253
+ drawables: M,
254
+ meshes: h,
255
+ time: o.time ?? 0
206
256
  };
207
257
  }
208
- function it(t, e) {
209
- const i = e.get("color"), n = t.kind === "trail";
258
+ function $t(t, n) {
259
+ const o = n.get("color"), e = t.kind === "trail";
210
260
  return {
211
- color: typeof i == "string" ? i : t.color,
212
- width: A(e.get("width")) ?? t.width ?? 0.05,
213
- taper: t.taper ?? (n ? 1 : 0),
214
- fade: t.fade ?? (n ? 1 : 0),
215
- opacity: (A(e.get("opacity")) ?? 1) * (t.opacity ?? 1),
261
+ color: typeof o == "string" ? o : t.color,
262
+ width: C(n.get("width")) ?? t.width ?? 0.05,
263
+ taper: t.taper ?? (e ? 1 : 0),
264
+ fade: t.fade ?? (e ? 1 : 0),
265
+ opacity: (C(n.get("opacity")) ?? 1) * (t.opacity ?? 1),
216
266
  additive: t.blend === "add"
217
267
  };
218
268
  }
219
- function st(t, e) {
220
- const n = (t.closed ? [...t.points, t.points[0]] : t.points).map((s) => I.transformPoint(e, s));
221
- return { points: n, ages: n.map((s, a) => 1 - a / (n.length - 1)) };
269
+ function It(t, n) {
270
+ const e = (t.closed ? [...t.points, t.points[0]] : t.points).map((i) => P.transformPoint(n, i));
271
+ return { points: e, ages: e.map((i, a) => 1 - a / (e.length - 1)) };
222
272
  }
223
- function rt(t, e, i, n) {
224
- if (!n.valuesAt) return null;
225
- const s = n.time ?? 0, a = A(i.get(`${e.id}/${t.id}`)?.get("length")) ?? t.length, r = U(
226
- (p) => W(Z(e, t.follow, p === s ? i : n.valuesAt(p))),
227
- s,
228
- { length: a, samples: t.samples ?? 32, period: t.period }
273
+ function St(t, n, o, e) {
274
+ if (!e.valuesAt) return null;
275
+ const i = e.time ?? 0, a = C(o.get(`${n.id}/${t.id}`)?.get("length")) ?? t.length, r = ft(
276
+ (l) => Z(it(n, t.follow, l === i ? o : e.valuesAt(l))),
277
+ i,
278
+ { length: a, samples: t.samples ?? 32, period: t.period ?? e.period }
229
279
  );
230
- return r.length >= 2 ? { points: r.map((p) => p.at), ages: r.map((p) => p.age) } : null;
231
- }
232
- function Z(t, e, i) {
233
- const n = t.objects.find((a) => a.id === e);
234
- if (!n) return I.identity();
235
- const s = V(n, i.get(`${t.id}/${e}`) ?? L);
236
- return n.parent ? I.multiply(Z(t, n.parent, i), s) : s;
237
- }
238
- function H(t, e, i, n, s, a, r) {
239
- const p = t.positions.length / 3, f = [], k = [];
240
- for (let h = 0; h < p; h++) {
241
- const P = I.transformPoint(e, [t.positions[h * 3], t.positions[h * 3 + 1], t.positions[h * 3 + 2]]);
242
- f.push(P), k.push(I.transformPoint(n.view, P));
243
- }
244
- const y = t.indices.length / 3, M = [], E = [];
245
- for (let h = 0; h < y; h++) {
246
- const [P, o, c] = [0, 1, 2].map((w) => f[t.indices[h * 3 + w]]), b = u.normalize(u.cross(u.subtract(o, P), u.subtract(c, P)));
247
- M.push(b);
248
- const l = n.orthographic ? u.scale(n.forward, -1) : u.subtract(n.position, P);
249
- E.push(u.dot(b, l) > 0);
250
- }
251
- const C = (h) => -k[h][2] >= n.near, d = [];
252
- for (let h = 0; h < y; h++) {
253
- const P = E[h];
254
- if (!P && !a.doubleSided) continue;
255
- const o = [t.indices[h * 3], t.indices[h * 3 + 1], t.indices[h * 3 + 2]], c = o.map((g) => k[g]);
256
- if (c.every((g) => -g[2] > n.far)) continue;
257
- const b = ot(c, n.near);
258
- if (b.length < 3) continue;
259
- const l = P ? 1 : -1, w = u.scale(M[h], l), m = o.map((g) => u.scale(nt(i, t.normals[g * 3], t.normals[g * 3 + 1], t.normals[g * 3 + 2]), l)), O = u.scale(u.add(u.add(f[o[0]], f[o[1]]), f[o[2]]), 1 / 3), S = -(c[0][2] + c[1][2] + c[2][2]) / 3, D = [];
260
- if (a.outline && P)
261
- for (const g of t.faceEdges[h]) {
262
- const T = g.across, v = T === -1 || !E[T], J = a.creases !== !1 && !v && h < T && u.dot(M[h], M[T]) < tt;
263
- (v || J) && C(g.a) && C(g.b) && D.push([s(k[g.a]), s(k[g.b])]);
280
+ return r.length >= 2 ? { points: r.map((l) => l.at), ages: r.map((l) => l.age) } : null;
281
+ }
282
+ function it(t, n, o) {
283
+ const e = t.objects.find((a) => a.id === n);
284
+ if (!e) return P.identity();
285
+ const i = ot(e, o.get(`${t.id}/${n}`) ?? nt);
286
+ return e.parent ? P.multiply(it(t, e.parent, o), i) : i;
287
+ }
288
+ function _(t, n, o, e, i, a, r) {
289
+ const l = t.positions.length / 3, c = [], u = [];
290
+ for (let h = 0; h < l; h++) {
291
+ const M = P.transformPoint(n, [t.positions[h * 3], t.positions[h * 3 + 1], t.positions[h * 3 + 2]]);
292
+ c.push(M), u.push(P.transformPoint(e.view, M));
293
+ }
294
+ const g = t.indices.length / 3, m = [], v = [];
295
+ for (let h = 0; h < g; h++) {
296
+ const [M, b, s] = [0, 1, 2].map((w) => c[t.indices[h * 3 + w]]), d = A.normalize(A.cross(A.subtract(b, M), A.subtract(s, M)));
297
+ m.push(d);
298
+ const f = e.orthographic ? A.scale(e.forward, -1) : A.subtract(e.position, M);
299
+ v.push(A.dot(d, f) > 0);
300
+ }
301
+ const $ = (h) => -u[h][2] >= e.near, p = [];
302
+ for (let h = 0; h < g; h++) {
303
+ const M = v[h];
304
+ if (!M && !a.doubleSided) continue;
305
+ const b = [t.indices[h * 3], t.indices[h * 3 + 1], t.indices[h * 3 + 2]], s = b.map((y) => u[y]);
306
+ if (s.every((y) => -y[2] > e.far)) continue;
307
+ const d = vt(s, e.near);
308
+ if (d.length < 3) continue;
309
+ const f = M ? 1 : -1, w = A.scale(m[h], f), x = b.map((y) => A.scale(Mt(o, t.normals[y * 3], t.normals[y * 3 + 1], t.normals[y * 3 + 2]), f)), k = A.scale(A.add(A.add(c[b[0]], c[b[1]]), c[b[2]]), 1 / 3), I = -(s[0][2] + s[1][2] + s[2][2]) / 3, T = [], D = [];
310
+ if (r.ink && M)
311
+ for (const y of t.faceEdges[h]) {
312
+ const z = y.across, X = z === -1 || !v[z], Y = a.creases !== !1 && !X && h < z && A.dot(m[h], m[z]) < kt;
313
+ (X || Y) && $(y.a) && $(y.b) && (T.push([i(u[y.a]), i(u[y.b])]), D.push([-u[y.a][2], -u[y.b][2]]));
264
314
  }
265
- const $ = b.map(s);
266
- for (let g = 1; g + 1 < $.length; g++)
267
- d.push({
315
+ const S = r.opacity * At(r.nearFade, I);
316
+ if (S <= 0) continue;
317
+ const E = d.map(i);
318
+ for (let y = 1; y + 1 < E.length; y++)
319
+ p.push({
268
320
  objectId: r.objectId,
269
321
  objectIndex: r.objectIndex,
270
322
  layer: r.layer,
271
323
  face: h,
272
- part: g - 1,
273
- screen: [$[0], $[g], $[g + 1]],
274
- depth: S,
275
- centroid: O,
324
+ part: y - 1,
325
+ screen: [E[0], E[y], E[y + 1]],
326
+ depth: I,
327
+ depths: [-d[0][2], -d[y][2], -d[y + 1][2]],
328
+ centroid: k,
276
329
  normal: w,
277
- vertexNormals: m,
330
+ vertexNormals: x,
278
331
  material: a,
279
- color: r.color,
280
- opacity: r.opacity,
281
- outline: g === 1 ? D : []
332
+ color: r.color ?? t.faceColors?.[h],
333
+ opacity: S,
334
+ outline: y === 1 ? T : [],
335
+ outlineDepths: y === 1 ? D : [],
336
+ ink: r.ink
282
337
  });
283
338
  }
284
- return d;
339
+ return p;
285
340
  }
286
- class ft {
341
+ class Xt {
287
342
  ctx;
288
- constructor(e) {
289
- this.ctx = e;
343
+ constructor(n) {
344
+ this.ctx = n;
290
345
  }
291
- render(e) {
292
- B(this.ctx, e);
346
+ render(n) {
347
+ st(this.ctx, n);
293
348
  }
294
349
  }
295
- function B(t, e) {
296
- t.save(), e.background && e.background !== "transparent" && (t.fillStyle = e.background, t.fillRect(0, 0, e.width, e.height)), t.lineJoin = "round", t.lineCap = "round";
297
- let i = 0;
298
- const n = (r, p) => {
299
- for (; i < e.drawables.length; ) {
300
- const f = e.drawables[i];
301
- if (f.layer > r || f.layer === r && f.depth <= p) break;
302
- t.save(), f.draw(t, e), t.restore(), i++;
350
+ function st(t, n) {
351
+ if (t.save(), n.background && n.background !== "transparent") {
352
+ if (typeof n.background == "string") t.fillStyle = n.background;
353
+ else {
354
+ const r = t.createLinearGradient(0, 0, 0, n.height);
355
+ r.addColorStop(0, n.background.top), r.addColorStop(1, n.background.bottom), t.fillStyle = r;
356
+ }
357
+ t.fillRect(0, 0, n.width, n.height);
358
+ }
359
+ t.lineJoin = "round", t.lineCap = "round";
360
+ let o = 0;
361
+ const e = (r, l) => {
362
+ for (; o < n.drawables.length; ) {
363
+ const c = n.drawables[o];
364
+ if (c.layer > r || c.layer === r && c.depth <= l) break;
365
+ t.save(), c.draw(t, n), t.restore(), o++;
303
366
  }
304
367
  };
305
- let s = [];
368
+ let i = [];
306
369
  const a = (r) => {
307
- if (s.length === 0) return;
308
- const p = [];
309
- for (const f of s)
310
- r && r.objectId === f.objectId && r.layer === f.layer && f.depth - r.depth <= at * f.depth ? p.push(f) : lt(t, f.triangle);
311
- s = p;
370
+ if (i.length === 0) return;
371
+ const l = [];
372
+ for (const c of i)
373
+ r && r.objectId === c.objectId && r.layer === c.layer && c.depth - r.depth <= Pt * c.depth ? l.push(c) : Tt(t, c.triangle, n);
374
+ i = l;
312
375
  };
313
- for (const r of e.triangles) {
314
- a(r), n(r.layer, r.depth);
315
- const { color: p, alpha: f } = q(r, e.lights, e.camera, e.fog), [k, y, M] = r.screen;
316
- t.globalAlpha = f, t.beginPath(), t.moveTo(k.x, k.y), t.lineTo(y.x, y.y), t.lineTo(M.x, M.y), t.closePath(), t.fillStyle = p, t.fill(), f >= 1 && (t.strokeStyle = p, t.lineWidth = 0.75, t.stroke()), r.material.outline && r.outline.length > 0 && s.push({ objectId: r.objectId, layer: r.layer, depth: r.depth, triangle: r });
317
- }
318
- a(), n(1 / 0, -1 / 0), t.restore();
319
- }
320
- const at = 0.04;
321
- function lt(t, e) {
322
- const i = e.material.outline;
323
- t.globalAlpha = e.opacity, t.strokeStyle = i.color, t.lineWidth = i.width, t.beginPath();
324
- for (const [n, s] of e.outline)
325
- t.moveTo(n.x, n.y), t.lineTo(s.x, s.y);
376
+ for (const r of n.triangles) {
377
+ a(r), e(r.layer, r.depth);
378
+ const { color: l, alpha: c } = q(r, n.lights, n.camera, n.fog), [u, g, m] = r.screen;
379
+ t.globalAlpha = c, t.beginPath(), t.moveTo(u.x, u.y), t.lineTo(g.x, g.y), t.lineTo(m.x, m.y), t.closePath(), t.fillStyle = l, t.fill(), c >= 1 && (t.strokeStyle = l, t.lineWidth = 0.75, t.stroke()), r.ink && r.outline.length > 0 && i.push({ objectId: r.objectId, layer: r.layer, depth: r.depth, triangle: r });
380
+ }
381
+ a(), e(1 / 0, -1 / 0), t.restore();
382
+ }
383
+ const Pt = 0.04;
384
+ function Tt(t, n, o) {
385
+ const e = n.ink;
386
+ t.globalAlpha = n.opacity, t.strokeStyle = j(e.color, o.fog, A.distance(n.centroid, o.camera.position)), t.lineWidth = e.width, t.beginPath();
387
+ for (const [i, a] of n.outline)
388
+ t.moveTo(i.x, i.y), t.lineTo(a.x, a.y);
326
389
  t.stroke();
327
390
  }
328
- class gt {
391
+ function Et(t, n = {}) {
392
+ const o = t.width, e = t.height, i = new Uint8ClampedArray(o * e * 4), a = new Float32Array(o * e).fill(1 / 0);
393
+ if (n.under && n.under.length === i.length) i.set(n.under);
394
+ else if (t.background && t.background !== "transparent") {
395
+ const g = N(typeof t.background == "string" ? t.background : t.background.top), m = N(typeof t.background == "string" ? t.background : t.background.bottom);
396
+ for (let v = 0; v < e; v++) {
397
+ const $ = e > 1 ? v / (e - 1) : 0, p = Math.round((g[0] + (m[0] - g[0]) * $) * 255), h = Math.round((g[1] + (m[1] - g[1]) * $) * 255), M = Math.round((g[2] + (m[2] - g[2]) * $) * 255);
398
+ for (let b = 0; b < o; b++) {
399
+ const s = v * o + b;
400
+ i[s * 4] = p, i[s * 4 + 1] = h, i[s * 4 + 2] = M, i[s * 4 + 3] = 255;
401
+ }
402
+ }
403
+ }
404
+ const r = { width: o, height: e, data: i, depth: a };
405
+ let l = -1 / 0;
406
+ const c = [], u = () => {
407
+ for (const g of c) U(r, t, g, !1);
408
+ c.length = 0;
409
+ };
410
+ for (const g of t.triangles)
411
+ g.layer !== l && (u(), l = g.layer, a.fill(1 / 0)), g.opacity < 1 ? c.push(g) : U(r, t, g, !0);
412
+ return u(), r;
413
+ }
414
+ function U(t, n, o, e) {
415
+ const { color: i, alpha: a } = q(o, n.lights, n.camera, n.fog), r = N(i).map((l) => Math.round(l * 255));
416
+ if (Dt(t, o.screen, o.depths, r, a, e), o.ink && o.outline.length > 0) {
417
+ const l = N(j(o.ink.color, n.fog, A.distance(o.centroid, n.camera.position))).map((c) => Math.round(c * 255));
418
+ o.outline.forEach((c, u) => {
419
+ const g = o.outlineDepths[u] ?? [o.depth, o.depth];
420
+ zt(t, c[0], c[1], g, o.ink.width, l, a);
421
+ });
422
+ }
423
+ }
424
+ function rt(t, n, o, e) {
425
+ const i = n * 4;
426
+ if (e >= 1) {
427
+ t[i] = o[0], t[i + 1] = o[1], t[i + 2] = o[2], t[i + 3] = 255;
428
+ return;
429
+ }
430
+ const a = t[i + 3] / 255, r = e + a * (1 - e);
431
+ if (!(r <= 0)) {
432
+ for (let l = 0; l < 3; l++) t[i + l] = Math.round((o[l] * e + t[i + l] * a * (1 - e)) / r);
433
+ t[i + 3] = Math.round(r * 255);
434
+ }
435
+ }
436
+ const Ct = 4e-3;
437
+ function Dt(t, n, o, e, i, a) {
438
+ const [r, l, c] = n, u = (l.x - r.x) * (c.y - r.y) - (l.y - r.y) * (c.x - r.x);
439
+ if (u === 0) return;
440
+ const g = Math.max(0, Math.floor(Math.min(r.x, l.x, c.x))), m = Math.min(t.width - 1, Math.ceil(Math.max(r.x, l.x, c.x))), v = Math.max(0, Math.floor(Math.min(r.y, l.y, c.y))), $ = Math.min(t.height - 1, Math.ceil(Math.max(r.y, l.y, c.y)));
441
+ if (g > m || v > $) return;
442
+ const p = [1 / Math.max(1e-9, o[0]), 1 / Math.max(1e-9, o[1]), 1 / Math.max(1e-9, o[2])], h = u > 0 ? 1 : -1;
443
+ for (let M = v; M <= $; M++) {
444
+ const b = M + 0.5;
445
+ for (let s = g; s <= m; s++) {
446
+ const d = s + 0.5, f = ((l.x - d) * (c.y - b) - (l.y - b) * (c.x - d)) * h, w = ((c.x - d) * (r.y - b) - (c.y - b) * (r.x - d)) * h, x = ((r.x - d) * (l.y - b) - (r.y - b) * (l.x - d)) * h;
447
+ if (f < 0 || w < 0 || x < 0) continue;
448
+ const I = (f + w + x) / (f * p[0] + w * p[1] + x * p[2]), T = M * t.width + s;
449
+ I >= t.depth[T] || (rt(t.data, T, e, i), a && (t.depth[T] = I));
450
+ }
451
+ }
452
+ }
453
+ function zt(t, n, o, e, i, a, r) {
454
+ const l = Math.max(0.5, i / 2), c = Math.max(0, Math.floor(Math.min(n.x, o.x) - l)), u = Math.min(t.width - 1, Math.ceil(Math.max(n.x, o.x) + l)), g = Math.max(0, Math.floor(Math.min(n.y, o.y) - l)), m = Math.min(t.height - 1, Math.ceil(Math.max(n.y, o.y) + l)), v = o.x - n.x, $ = o.y - n.y, p = v * v + $ * $, h = l * l;
455
+ for (let M = g; M <= m; M++) {
456
+ const b = M + 0.5;
457
+ for (let s = c; s <= u; s++) {
458
+ const d = s + 0.5, f = p > 0 ? Math.min(1, Math.max(0, ((d - n.x) * v + (b - n.y) * $) / p)) : 0, w = n.x + v * f, x = n.y + $ * f;
459
+ if ((d - w) ** 2 + (b - x) ** 2 > h) continue;
460
+ const k = (e[0] + (e[1] - e[0]) * f) * (1 - Ct), I = M * t.width + s;
461
+ k > t.depth[I] || rt(t.data, I, a, r);
462
+ }
463
+ }
464
+ }
465
+ function at(t, n) {
466
+ const e = !n.background || n.background === "transparent" ? t.getImageData(0, 0, n.width, n.height).data : void 0, i = Et(n, { under: e }), a = t.createImageData(n.width, n.height);
467
+ a.data.set(i.data), t.putImageData(a, 0, 0), t.save(), t.lineJoin = "round", t.lineCap = "round";
468
+ for (const r of n.drawables)
469
+ t.save(), r.draw(t, n), t.restore();
470
+ t.restore();
471
+ }
472
+ class Yt {
473
+ ctx;
474
+ constructor(n) {
475
+ this.ctx = n;
476
+ }
477
+ render(n) {
478
+ at(this.ctx, n);
479
+ }
480
+ }
481
+ class Wt {
329
482
  renderer;
330
483
  width;
331
484
  height;
@@ -333,60 +486,262 @@ class gt {
333
486
  values = /* @__PURE__ */ new Map();
334
487
  valuesAt;
335
488
  /** `valuesAt`: the values at another time (`(t) => timeline.getStateAtTime(t).values`), for trails */
336
- constructor(e, i) {
337
- this.renderer = e, this.width = i.width, this.height = i.height, this.valuesAt = i.valuesAt;
489
+ constructor(n, o) {
490
+ this.renderer = n, this.width = o.width, this.height = o.height, this.valuesAt = o.valuesAt;
338
491
  }
339
492
  /** Add a scene; its tracks address `<scene.id>/<objectId>`. */
340
- registerScene(e) {
341
- this.scenes.set(e.scene.id, e);
493
+ registerScene(n) {
494
+ this.scenes.set(n.scene.id, n);
342
495
  }
343
- unregisterScene(e) {
344
- this.scenes.delete(e);
496
+ unregisterScene(n) {
497
+ this.scenes.delete(n);
345
498
  }
346
- resize(e, i) {
347
- this.width = e, this.height = i;
499
+ resize(n, o) {
500
+ this.width = n, this.height = o;
348
501
  }
349
- applyState(e) {
350
- this.values = e.values, this.time = e.currentTime ?? this.time;
502
+ applyState(n) {
503
+ this.values = n.values, this.time = n.currentTime ?? this.time;
351
504
  }
352
505
  time = 0;
353
506
  render() {
354
- for (const e of this.scenes.values())
355
- this.renderer.render(X(e, this.values, { width: this.width, height: this.height, time: this.time, valuesAt: this.valuesAt }));
507
+ for (const n of this.scenes.values())
508
+ this.renderer.render(et(n, this.values, { width: this.width, height: this.height, time: this.time, valuesAt: this.valuesAt }));
509
+ }
510
+ }
511
+ function Ht(t, n, o, e) {
512
+ const i = e.stateAt, a = e.valuesAt ?? (i && ((l) => i(l).values)), r = et(n, o ?? /* @__PURE__ */ new Map(), { width: e.width, height: e.height, time: e.time, period: e.period, valuesAt: a });
513
+ e.depthBuffer ? at(t, r) : st(t, r);
514
+ }
515
+ function Lt(t = {}) {
516
+ const n = t.id ?? "penrose", o = t.length ?? 4, e = t.thickness ?? 0.8, i = t.material ?? "penrose", [a, r, l] = t.position ?? [0, 0, 0], c = e / 2, u = (p, h, M) => ({
517
+ id: `${n}-${p}`,
518
+ kind: "mesh",
519
+ geometry: { type: "box", size: [M[0] - h[0], M[1] - h[1], M[2] - h[2]] },
520
+ material: i,
521
+ position: [a + (h[0] + M[0]) / 2, r + (h[1] + M[1]) / 2, l + (h[2] + M[2]) / 2]
522
+ }), g = [
523
+ u("x", [-c, -c, -c], [o - c, c, c]),
524
+ u("y", [o - c, -c, -c], [o + c, o - c, c]),
525
+ u("z", [o - c, o - c, -c], [o + c, o + c, o])
526
+ ], m = [a + 2 * o / 3, r + o / 3, l + o / 3], v = (t.distance ?? 20) / Math.sqrt(3), $ = {
527
+ id: `${n}-camera`,
528
+ kind: "camera",
529
+ projection: "orthographic",
530
+ height: o * 1.6,
531
+ near: 0.1,
532
+ far: (t.distance ?? 20) * 3,
533
+ position: [m[0] + v, m[1] + v, m[2] + v],
534
+ lookAt: m
535
+ };
536
+ return { objects: g, camera: $ };
537
+ }
538
+ function _t(t, n) {
539
+ let o;
540
+ for (const e of [...t].sort((i, a) => i.start - a.start)) e.start <= n && (o = e);
541
+ return o;
542
+ }
543
+ function Bt(t) {
544
+ const n = [], o = [...t].sort((i, a) => i.start - a.start), e = /* @__PURE__ */ new Set();
545
+ return o.forEach((i, a) => {
546
+ e.has(i.id) && n.push(`two shots share the id "${i.id}"`), e.add(i.id), i.end > i.start || n.push(`shot "${i.id}" ends before it starts`), a > 0 && i.start < o[a - 1].end && n.push(`shot "${i.id}" starts before "${o[a - 1].id}" ends`), i.transition && a === 0 && n.push(`shot "${i.id}" is first: nothing to transition from`), i.transition && i.transition.duration > i.end - i.start && n.push(`shot "${i.id}": its transition is longer than the shot`);
547
+ }), n;
548
+ }
549
+ function Vt(t, n) {
550
+ const o = [...t].sort((i, a) => i.start - a.start);
551
+ if (o.length === 0) return [];
552
+ const e = o.map((i) => ({ time: i.start, value: i.camera }));
553
+ return [{ id: `${n}-shots`, target: n, property: "activeCamera", keyframes: e }];
554
+ }
555
+ function Zt(t) {
556
+ return [...t].sort((n, o) => n.start - o.start).map((n) => ({ id: n.id, time: n.start, label: n.label ?? n.id }));
557
+ }
558
+ function Gt(t, n) {
559
+ const o = [...t].sort((e, i) => e.start - i.start);
560
+ for (let e = 1; e < o.length; e++) {
561
+ const i = o[e], a = i.transition;
562
+ if (!(!a || a.kind === "cut" || !(a.duration > 0)) && n >= i.start && n < i.start + a.duration)
563
+ return { kind: a.kind, progress: (n - i.start) / a.duration, from: o[e - 1], to: i, direction: a.direction ?? "left", color: a.color ?? "#000000" };
564
+ }
565
+ }
566
+ function Jt(t, n) {
567
+ const o = 6e4 / n.bpm, e = (a) => n.offset + Math.round((a - n.offset) / o) * o, i = [...t].sort((a, r) => a.start - r.start).map((a) => ({ ...a }));
568
+ for (let a = 1; a < i.length; a++) {
569
+ const r = Math.max(i[a - 1].start + 1, e(i[a].start));
570
+ i[a - 1].end = r, i[a].start = r;
571
+ }
572
+ return i;
573
+ }
574
+ function Kt(t, n, o) {
575
+ const e = new Map(t ?? []), i = new Map(e.get(n) ?? []);
576
+ return i.set("activeCamera", o), e.set(n, i), e;
577
+ }
578
+ const B = (t, n, o) => [t[0] + (n[0] - t[0]) * o, t[1] + (n[1] - t[1]) * o, t[2] + (n[2] - t[2]) * o];
579
+ function Ft(t, n, o) {
580
+ const e = { target: [0, 0, 0], yaw: 0, pitch: 15, distance: 8, ...t }, i = { ...e, ...n }, a = B(e.target, i.target, o), r = e.position || i.position ? B(e.position ?? L(e.target, e.yaw, e.pitch, e.distance), i.position ?? L(i.target, i.yaw, i.pitch, i.distance), o) : L(a, e.yaw + (i.yaw - e.yaw) * o, e.pitch + (i.pitch - e.pitch) * o, e.distance + (i.distance - e.distance) * o), l = B(e.lookAt ?? e.target, i.lookAt ?? i.target, o), c = e.fov !== void 0 || i.fov !== void 0 ? (e.fov ?? i.fov) + ((i.fov ?? e.fov) - (e.fov ?? i.fov)) * o : void 0;
581
+ return { position: r, lookAt: l, fov: c };
582
+ }
583
+ function Qt(t) {
584
+ const n = Math.max(1, t.every ?? 33), o = ut(t.easing ?? "ease-in-out"), e = `${t.scene}/${t.camera}`, i = [], a = [], r = [];
585
+ for (let c = t.start; ; c = Math.min(t.end, c + n)) {
586
+ const u = t.end > t.start ? o((c - t.start) / (t.end - t.start)) : 1, g = Ft(t.from, t.to, u);
587
+ if (i.push({ time: c, value: g.position }), a.push({ time: c, value: g.lookAt }), g.fov !== void 0 && r.push({ time: c, value: g.fov }), c >= t.end) break;
588
+ }
589
+ const l = [
590
+ { id: `${e}-move-position`, target: e, property: "position", keyframes: i },
591
+ { id: `${e}-move-lookAt`, target: e, property: "lookAt", keyframes: a }
592
+ ];
593
+ return r.length > 0 && l.push({ id: `${e}-move-fov`, target: e, property: "fov", keyframes: r }), l;
594
+ }
595
+ function Ut(t) {
596
+ const n = Math.max(1, t.every ?? 33), o = t.offset ?? [0, 2, 6], e = t.lag ?? 0, i = `${t.scene}/${t.camera}`, a = [], r = [];
597
+ for (let l = t.start; ; l = Math.min(t.end, l + n)) {
598
+ const c = t.subjectAt(l), u = t.subjectAt(Math.max(t.start, l - e));
599
+ if (a.push({ time: l, value: [u[0] + o[0], u[1] + o[1], u[2] + o[2]] }), r.push({ time: l, value: c }), l >= t.end) break;
600
+ }
601
+ return [
602
+ { id: `${i}-follow-position`, target: i, property: "position", keyframes: a },
603
+ { id: `${i}-follow-lookAt`, target: i, property: "lookAt", keyframes: r }
604
+ ];
605
+ }
606
+ function qt(t, n) {
607
+ const o = `${n.scene}/${n.camera}`, e = n.amount ?? 0.04, i = n.aim ?? 0.08, a = n.rate ?? 1.2, r = Math.max(1, n.every ?? 33), l = n.end - n.start, c = Math.max(1, l), u = Math.max(1, Math.round(c / 1e3 * a)), g = typeof n.seed == "string" ? n.seed : `handheld-${n.seed ?? 0}`, m = (s, d) => gt(s - n.start, { period: c, seed: `${g}-${d}`, cycles: u, octaves: 2 }), v = t.filter((s) => s.target === o), $ = t.filter((s) => s.target !== o), p = (s, d, f) => {
608
+ const w = v.find((k) => k.property === s), x = [];
609
+ if (w)
610
+ for (const k of w.keyframes) {
611
+ const I = k.value;
612
+ x.push({ time: k.time, value: [I[0] + m(k.time, `${s}x`) * d, I[1] + m(k.time, `${s}y`) * d, I[2] + m(k.time, `${s}z`) * d * 0.5], easing: k.easing });
613
+ }
614
+ else if (f)
615
+ for (let k = n.start; x.push({ time: k, value: [f[0] + m(k, `${s}x`) * d, f[1] + m(k, `${s}y`) * d, f[2] + m(k, `${s}z`) * d * 0.5] }), !(k >= n.end); k = Math.min(n.end, k + r))
616
+ ;
617
+ else return;
618
+ return { id: w?.id ?? `${o}-handheld-${s}`, target: o, property: s, keyframes: x };
619
+ }, h = [...$, ...v.filter((s) => s.property !== "position" && s.property !== "lookAt")], M = p("position", e, n.base?.position), b = p("lookAt", i, n.base?.lookAt);
620
+ return M && h.push(M), b && h.push(b), h;
621
+ }
622
+ const V = {
623
+ day: {
624
+ lights: [
625
+ { id: "key", kind: "light", light: "directional", color: "#fff6e0", intensity: 0.95, position: [4, 8, 3] },
626
+ { id: "fill", kind: "light", light: "directional", color: "#cfe3ff", intensity: 0.3, position: [-5, 3, -2] },
627
+ { id: "sky", kind: "light", light: "ambient", color: "#bcd4ea", intensity: 0.4 }
628
+ ],
629
+ background: { top: "#5aa9e6", bottom: "#dff1ff" },
630
+ fog: { color: "#dff1ff", near: 14, far: 40 }
631
+ },
632
+ dusk: {
633
+ lights: [
634
+ { id: "key", kind: "light", light: "directional", color: "#ffb067", intensity: 0.8, position: [6, 2.5, 2] },
635
+ { id: "fill", kind: "light", light: "directional", color: "#7b6bd6", intensity: 0.25, position: [-4, 3, -3] },
636
+ { id: "sky", kind: "light", light: "ambient", color: "#b58ab3", intensity: 0.3 }
637
+ ],
638
+ background: { top: "#4a3a7a", bottom: "#ff9a62" },
639
+ fog: { color: "#d9826f", near: 10, far: 30 }
640
+ },
641
+ night: {
642
+ lights: [
643
+ { id: "key", kind: "light", light: "directional", color: "#9db7ff", intensity: 0.35, position: [-3, 7, 2] },
644
+ { id: "fill", kind: "light", light: "directional", color: "#3b4a7a", intensity: 0.12, position: [4, 2, -3] },
645
+ { id: "sky", kind: "light", light: "ambient", color: "#243357", intensity: 0.25 }
646
+ ],
647
+ background: { top: "#060a1c", bottom: "#1b2650" },
648
+ fog: { color: "#101a3a", near: 6, far: 22 }
649
+ },
650
+ stage: {
651
+ lights: [
652
+ { id: "key", kind: "light", light: "directional", color: "#ffffff", intensity: 0.15, position: [2, 6, 4] },
653
+ { id: "fill", kind: "light", light: "directional", color: "#402040", intensity: 0.08, position: [-4, 3, -2] },
654
+ { id: "sky", kind: "light", light: "ambient", color: "#1a1020", intensity: 0.2 },
655
+ { id: "spot", kind: "light", light: "spot", color: "#ffe9b0", intensity: 1.1, position: [0, 7, 2], target: [0, 0, 0], angle: 22, range: 16 }
656
+ ],
657
+ background: { top: "#05030a", bottom: "#120a1c" },
658
+ fog: { color: "#0a0612", near: 8, far: 24 }
356
659
  }
660
+ };
661
+ function jt(t, n = {}) {
662
+ const o = V[t];
663
+ if (!o) throw new Error(`lightingPreset: unknown mood "${t}" (day, dusk, night, stage)`);
664
+ const e = n.prefix ? `${n.prefix}-` : "";
665
+ return {
666
+ objects: o.lights.map((i) => ({ ...i, id: `${e}${i.id}`, position: i.position ? [...i.position] : void 0, target: i.target ? [...i.target] : void 0 })),
667
+ background: { ...o.background },
668
+ fog: { ...o.fog }
669
+ };
357
670
  }
358
- function ut(t, e, i, n) {
359
- const s = n.stateAt, a = n.valuesAt ?? (s && ((r) => s(r).values));
360
- B(t, X(e, i ?? /* @__PURE__ */ new Map(), { width: n.width, height: n.height, time: n.time, valuesAt: a }));
671
+ function tn(t, n, o) {
672
+ const e = V[t], i = V[n];
673
+ if (!e || !i) throw new Error(`lightingTracks: unknown mood "${e ? n : t}" (day, dusk, night, stage)`);
674
+ const a = o.prefix ? `${o.prefix}-` : "", r = /* @__PURE__ */ new Set([...e.lights.map((c) => c.id), ...i.lights.map((c) => c.id)]), l = [];
675
+ for (const c of r) {
676
+ const u = e.lights.find((b) => b.id === c), g = i.lights.find((b) => b.id === c), m = `${o.scene}/${a}${c}`, v = (b, s, d) => {
677
+ const f = [{ time: o.start, value: s }, { time: o.end, value: d, easing: o.easing ?? "ease-in-out" }];
678
+ l.push({ id: `${m}-${b}`, target: m, property: b, keyframes: f });
679
+ };
680
+ v("intensity", u?.intensity ?? 0, g?.intensity ?? 0), v("color", u?.color ?? g.color, g?.color ?? u.color);
681
+ const $ = u?.position ?? g?.position, p = g?.position ?? u?.position;
682
+ $ && p && v("position", [...$], [...p]);
683
+ const h = u?.target ?? g?.target, M = g?.target ?? u?.target;
684
+ h && M && v("target", [...h], [...M]);
685
+ }
686
+ return l;
687
+ }
688
+ function nn(t = {}) {
689
+ const n = t.id ?? "ground", o = t.size ?? 24;
690
+ return {
691
+ objects: [{ id: n, kind: "mesh", layer: -1, geometry: { type: "plane", size: [o, o], segments: t.segments ?? 24 }, material: n, position: [0, t.y ?? 0, 0] }],
692
+ materials: { [n]: { color: t.color ?? "#3b4252", shading: "flat" } }
693
+ };
361
694
  }
362
695
  export {
363
- ft as Canvas2DRenderer,
364
- mt as MeshBuilder,
365
- gt as Scene3DAdapter,
366
- vt as boxMesh,
367
- Mt as coneMesh,
368
- bt as cylinderMesh,
369
- pt as dollyPosition,
370
- B as drawResolvedScene,
371
- ut as drawScene3D,
372
- kt as extrudeMesh,
373
- G as fogAmount,
374
- At as geometryMesh,
375
- Wt as lightAt,
376
- It as loadScene3D,
377
- x as lookAtView,
378
- Pt as meshEdges,
379
- dt as orbitPosition,
380
- z as parseColor,
381
- St as planeMesh,
382
- Tt as pointInPolygon,
383
- Et as prepareMesh,
384
- Y as projectionMatrix,
385
- X as resolveScene3D,
696
+ Xt as Canvas2DRenderer,
697
+ V as LIGHTING_PRESETS,
698
+ sn as MeshBuilder,
699
+ Wt as Scene3DAdapter,
700
+ Yt as SoftwareRenderer,
701
+ rn as boxMesh,
702
+ Ut as cameraFollowTracks,
703
+ qt as cameraHandheldTracks,
704
+ Qt as cameraMoveTracks,
705
+ Ft as cameraPoseAt,
706
+ Bt as checkShots,
707
+ an as coneMesh,
708
+ cn as cylinderMesh,
709
+ Rt as dollyPosition,
710
+ st as drawResolvedScene,
711
+ at as drawResolvedSceneWithDepth,
712
+ Ht as drawScene3D,
713
+ ln as extrudeMesh,
714
+ pt as fogAmount,
715
+ dn as geometryMesh,
716
+ nn as ground,
717
+ j as inkColor,
718
+ xn as lightAt,
719
+ jt as lightingPreset,
720
+ tn as lightingTracks,
721
+ hn as loadScene3D,
722
+ yt as lookAtView,
723
+ fn as meshEdges,
724
+ L as orbitPosition,
725
+ N as parseColor,
726
+ Lt as penroseTriangle3D,
727
+ un as planeMesh,
728
+ gn as pointInPolygon,
729
+ pn as prepareMesh,
730
+ J as projectionMatrix,
731
+ Et as rasterizeResolvedScene,
732
+ yn as rawMesh,
733
+ et as resolveScene3D,
734
+ tt as rollView,
386
735
  q as shadeTriangle,
387
- Ct as signedArea,
388
- Dt as sphereMesh,
389
- Ot as torusMesh,
390
- $t as triangulate,
391
- Nt as validateScene3D
736
+ _t as shotAt,
737
+ Zt as shotMarkers,
738
+ Vt as shotTracks,
739
+ mn as signedArea,
740
+ Jt as snapShotsToBeats,
741
+ kn as sphereMesh,
742
+ wn as torusMesh,
743
+ Gt as transitionAt,
744
+ Mn as triangulate,
745
+ vn as validateScene3D,
746
+ Kt as withActiveCamera
392
747
  };