@algorisys/tinyfly 0.86.2 → 0.88.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 (38) hide show
  1. package/README.md +7 -4
  2. package/bin/tinyfly.mjs +44 -6
  3. package/lib/addons/adapters.js +389 -281
  4. package/lib/addons/characters.js +3 -3
  5. package/lib/addons/load-scene-CQvcFWGJ.js +331 -0
  6. package/lib/addons/maps.js +1 -1
  7. package/lib/addons/scene-3d-webgl.js +52 -49
  8. package/lib/addons/scene-3d.js +299 -215
  9. package/lib/addons/shading-o5T_v9DT.js +89 -0
  10. package/lib/addons/{sketch-CA8ZXhxI.js → sketch-CYPUbk3Q.js} +2 -2
  11. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +4 -2
  12. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  13. package/lib/browser/tinyfly.iife.js +4 -4
  14. package/lib/browser/tinyfly.js +2204 -2043
  15. package/lib/browser/tinyfly.umd.js +4 -4
  16. package/lib/engine/tinyfly-engine.js +149 -106
  17. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  18. package/lib/headless/headless.js +165 -18
  19. package/lib/types/adapters/canvas/bloom.d.ts +33 -0
  20. package/lib/types/adapters/canvas/index.d.ts +3 -0
  21. package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
  22. package/lib/types/adapters/canvas/trail.d.ts +57 -0
  23. package/lib/types/browser/index.d.ts +4 -0
  24. package/lib/types/engine/path/index.d.ts +2 -0
  25. package/lib/types/engine/path/trail.d.ts +79 -0
  26. package/lib/types/headless/index.d.ts +1 -0
  27. package/lib/types/headless/loop-check.d.ts +41 -0
  28. package/lib/types/headless/node-video.d.ts +8 -0
  29. package/lib/types/headless/video-scene.d.ts +9 -1
  30. package/lib/types/scene-3d/resolve-scene.d.ts +6 -0
  31. package/lib/types/scene-3d/scene-3d-adapter.d.ts +9 -1
  32. package/lib/types/scene-3d/scene-types.d.ts +42 -2
  33. package/lib/types/scene-3d/strokes.d.ts +30 -0
  34. package/lib/types/scene-3d/webgl/gl-data.d.ts +1 -0
  35. package/lib/types/scene-3d/webgl/shaders.d.ts +1 -1
  36. package/package.json +1 -1
  37. package/lib/addons/load-scene-vp14_Jj-.js +0 -324
  38. package/lib/addons/shading-ByG9UXd0.js +0 -85
@@ -1,255 +1,338 @@
1
- import { M as at, b as ct, c as lt, a as dt, e as ht, g as gt, l as pt, m as ft, p as ut, d as yt, f as wt, s as mt, h as vt, t as Mt, i as bt, v as kt } from "./load-scene-vp14_Jj-.js";
2
- import { vec3 as h, mat4 as b, quat as T } from "@algorisys/tinyfly";
3
- import { s as B } from "./shading-ByG9UXd0.js";
4
- import { f as Pt, l as St, p as At } from "./shading-ByG9UXd0.js";
5
- function F(t, e) {
6
- const i = h.normalize(h.subtract(e, t)), n = Math.abs(i[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0];
7
- return b.lookAt(t, e, n);
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)), o = Math.abs(i[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0];
7
+ return I.lookAt(t, e, o);
8
8
  }
9
- function tt(t, e, i, n) {
10
- const r = e * Math.PI / 180, c = i * Math.PI / 180;
11
- return [t[0] + n * Math.cos(c) * Math.sin(r), t[1] + n * Math.sin(c), t[2] + n * Math.cos(c) * Math.cos(r)];
9
+ function dt(t, e, i, o) {
10
+ const s = e * Math.PI / 180, a = i * Math.PI / 180;
11
+ return [t[0] + o * Math.cos(a) * Math.sin(s), t[1] + o * Math.sin(a), t[2] + o * Math.cos(a) * Math.cos(s)];
12
12
  }
13
- function et(t, e, i) {
14
- const n = h.subtract(t, e), r = h.length(n);
15
- if (r === 0) return t;
16
- const c = Math.max(1e-3, r - i);
17
- return h.add(e, h.scale(n, c / r));
13
+ function pt(t, e, i) {
14
+ const o = u.subtract(t, e), s = u.length(o);
15
+ if (s === 0) return t;
16
+ const a = Math.max(1e-3, s - i);
17
+ return u.add(e, u.scale(o, a / s));
18
18
  }
19
19
  function Y(t, e) {
20
- if (t.projection === "perspective") return b.perspective(t.fov, e, t.near, t.far);
20
+ if (t.projection === "perspective") return I.perspective(t.fov, e, t.near, t.far);
21
21
  const i = t.height / 2;
22
- return b.orthographic(-i * e, i * e, -i, i, t.near, t.far);
22
+ return I.orthographic(-i * e, i * e, -i, i, t.near, t.far);
23
23
  }
24
- const H = Math.cos(30 * Math.PI / 180), J = /* @__PURE__ */ new Map(), v = (t) => typeof t == "number" ? t : void 0, z = (t, e) => Array.isArray(t) && t.length === e ? t : void 0;
25
- function K(t, e) {
26
- const i = t.position ?? [0, 0, 0], n = z(e.get("position"), 3) ?? [
27
- v(e.get("x")) ?? i[0],
28
- v(e.get("y")) ?? i[1],
29
- v(e.get("z")) ?? i[2]
24
+ function j(t, e, i, o) {
25
+ const { camera: s } = o, a = s.near, r = t.map((d) => I.transformPoint(s.view, d)), p = s.projection[5] * o.height / 2, g = (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 C = (d) => -d[2] >= a;
28
+ for (let d = 0; d < r.length; d++) {
29
+ const h = r[d];
30
+ C(h) ? (M.length === 0 && d > 0 && !C(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 E = [];
34
+ for (const d of y) {
35
+ if (d.length < 2) continue;
36
+ const h = d.map((l) => -l.view[2]), n = d.map((l) => o.toScreen(l.view)).map((l, w) => ({ x: l.x, y: l.y, width: g(d[w].age, h[w]) })), c = K(n), b = d[d.length - 1].age === 0 ? Q(n) : 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(o.fog, u.length(O));
42
+ let D = k;
43
+ if (o.fog && S > 0)
44
+ if (i.additive) m *= 1 - S;
45
+ else {
46
+ const v = z(o.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];
48
+ }
49
+ if (m <= 0) continue;
50
+ const $ = `rgb(${D.map((v) => Math.round(Math.min(1, Math.max(0, v)) * 255)).join(", ")})`, f = [c.left[l], c.left[l + 1], c.right[l + 1], c.right[l]], T = l + 2 === d.length ? b : null;
51
+ E.push({
52
+ depth: w,
53
+ draw(v) {
54
+ i.additive && (v.globalCompositeOperation = "lighter"), v.globalAlpha = Math.min(1, m), v.fillStyle = $, v.beginPath(), v.moveTo(f[0].x, f[0].y), v.lineTo(f[1].x, f[1].y), T && v.arc(T.x, T.y, T.radius, T.start, T.start - Math.PI, !0), v.lineTo(f[2].x, f[2].y), v.lineTo(f[3].x, f[3].y), v.closePath(), v.fill(), !i.additive && m >= 1 && (v.strokeStyle = $, v.lineWidth = 0.75, v.stroke());
55
+ }
56
+ });
57
+ }
58
+ }
59
+ return E;
60
+ }
61
+ function _(t, e, i, o, s) {
62
+ const a = (-s - t[2]) / (e[2] - t[2]);
63
+ return { view: u.lerp(t, e, a), age: i + (o - i) * a };
64
+ }
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], o = 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]
30
71
  ];
31
- let r;
32
- const c = z(e.get("quaternion"), 4), s = ["rotateX", "rotateY", "rotateZ"].map((u) => v(e.get(u)));
33
- if (c) r = T.normalize(c);
34
- else if (s.some((u) => u !== void 0)) {
35
- const u = t.rotation ?? [0, 0, 0];
36
- r = T.fromEuler(s[0] ?? u[0], s[1] ?? u[1], s[2] ?? u[2]);
37
- } else t.quaternion ? r = T.normalize(t.quaternion) : r = t.rotation ? T.fromEuler(...t.rotation) : T.identity();
38
- const g = typeof t.scale == "number" ? [t.scale, t.scale, t.scale] : t.scale ?? [1, 1, 1], l = v(e.get("scale")), M = [
39
- v(e.get("scaleX")) ?? l ?? g[0],
40
- v(e.get("scaleY")) ?? l ?? g[1],
41
- v(e.get("scaleZ")) ?? l ?? g[2]
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], g = A(e.get("scale")), k = [
80
+ A(e.get("scaleX")) ?? g ?? p[0],
81
+ A(e.get("scaleY")) ?? g ?? p[1],
82
+ A(e.get("scaleZ")) ?? g ?? p[2]
42
83
  ];
43
- return b.compose(n, r, M);
84
+ return I.compose(o, s, k);
44
85
  }
45
- const X = (t) => [t[12], t[13], t[14]];
46
- function L(t, e, i, n) {
47
- const r = X(e), c = z(i.get("lookAt"), 3) ?? t.lookAt, s = c ? F(r, c) : b.invert(e) ?? b.identity(), g = t.projection === "perspective" ? Y({ ...t, fov: v(i.get("fov")) ?? t.fov }, n) : Y({ ...t, height: v(i.get("height")) ?? t.height }, n);
86
+ const W = (t) => [t[12], t[13], t[14]];
87
+ function et(t, e, i, o) {
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 }, o) : Y({ ...t, height: A(i.get("height")) ?? t.height }, o);
48
89
  return {
49
90
  id: t.id,
50
- view: s,
51
- projection: g,
52
- position: r,
53
- forward: h.normalize([-s[2], -s[6], -s[10]]),
91
+ view: r,
92
+ projection: p,
93
+ position: s,
94
+ forward: u.normalize([-r[2], -r[6], -r[10]]),
54
95
  orthographic: t.projection === "orthographic",
55
96
  near: t.near,
56
97
  far: t.far
57
98
  };
58
99
  }
59
- function j(t) {
60
- return b.transpose(b.invert(t) ?? b.identity());
100
+ function F(t) {
101
+ return I.transpose(I.invert(t) ?? I.identity());
61
102
  }
62
- function Q(t, e, i, n) {
63
- return h.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]);
103
+ function nt(t, e, i, o) {
104
+ return u.normalize([t[0] * e + t[4] * i + t[8] * o, t[1] * e + t[5] * i + t[9] * o, t[2] * e + t[6] * i + t[10] * o]);
64
105
  }
65
- function U(t, e) {
66
- const i = (r) => -r[2] >= e, n = [];
67
- for (let r = 0; r < t.length; r++) {
68
- const c = t[r], s = t[(r + 1) % t.length];
69
- if (i(c) && n.push(c), i(c) !== i(s)) {
70
- const g = (-e - c[2]) / (s[2] - c[2]);
71
- n.push(h.lerp(c, s, g));
106
+ function ot(t, e) {
107
+ const i = (s) => -s[2] >= e, o = [];
108
+ for (let s = 0; s < t.length; s++) {
109
+ const a = t[s], r = t[(s + 1) % t.length];
110
+ if (i(a) && o.push(a), i(a) !== i(r)) {
111
+ const p = (-e - a[2]) / (r[2] - a[2]);
112
+ o.push(u.lerp(a, r, p));
72
113
  }
73
114
  }
74
- return n;
115
+ return o;
75
116
  }
76
- function Z(t, e = /* @__PURE__ */ new Map(), i) {
77
- const { scene: n } = t, r = (o) => e.get(`${n.id}/${o}`) ?? J, c = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
78
- for (const o of n.objects) {
79
- const a = r(o.id), p = K(o, a), y = o.parent ? c.get(o.parent) : void 0;
80
- c.set(o.id, y ? b.multiply(y, p) : p);
81
- const m = v(a.get("visible")) !== void 0 ? v(a.get("visible")) > 0.5 : o.visible !== !1;
82
- s.set(o.id, m && (o.parent ? s.get(o.parent) !== !1 : !0));
117
+ function X(t, e = /* @__PURE__ */ new Map(), i) {
118
+ const { scene: o } = t, s = (n) => e.get(`${o.id}/${n}`) ?? L, a = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
119
+ for (const n of o.objects) {
120
+ const c = s(n.id), b = V(n, c), l = n.parent ? a.get(n.parent) : void 0;
121
+ a.set(n.id, l ? I.multiply(l, b) : b);
122
+ const w = A(c.get("visible")) !== void 0 ? A(c.get("visible")) > 0.5 : n.visible !== !1;
123
+ r.set(n.id, w && (n.parent ? r.get(n.parent) !== !1 : !0));
83
124
  }
84
- const g = e.get(n.id)?.get("activeCamera"), l = typeof g == "string" && n.objects.some((o) => o.id === g && o.kind === "camera") ? g : n.camera, M = n.objects.find((o) => o.id === l), u = L(M, c.get(l), r(l), i.width / i.height), k = (o) => {
85
- const a = b.transformPoint(u.projection, o);
86
- return { x: (a[0] + 1) / 2 * i.width, y: (1 - a[1]) / 2 * i.height };
87
- }, P = [];
88
- for (const o of n.objects) {
89
- if (o.kind !== "light" || !s.get(o.id)) continue;
90
- const a = r(o.id), p = X(c.get(o.id)), y = z(a.get("target"), 3) ?? o.target ?? [0, 0, 0], m = a.get("color");
91
- P.push({
92
- id: o.id,
93
- light: o.light,
94
- color: typeof m == "string" ? m : o.color,
95
- intensity: v(a.get("intensity")) ?? o.intensity,
96
- position: p,
97
- direction: h.normalize(h.subtract(y, p)),
98
- range: o.range,
99
- angle: o.angle ?? 30
125
+ const p = e.get(o.id)?.get("activeCamera"), g = typeof p == "string" && o.objects.some((n) => n.id === p && n.kind === "camera") ? p : o.camera, k = o.objects.find((n) => n.id === g), y = et(k, a.get(g), s(g), i.width / i.height), M = (n) => {
126
+ const c = I.transformPoint(y.projection, n);
127
+ return { x: (c[0] + 1) / 2 * i.width, y: (1 - c[1]) / 2 * i.height };
128
+ }, C = [];
129
+ for (const n of o.objects) {
130
+ if (n.kind !== "light" || !r.get(n.id)) continue;
131
+ const c = s(n.id), b = W(a.get(n.id)), l = R(c.get("target"), 3) ?? n.target ?? [0, 0, 0], w = c.get("color");
132
+ C.push({
133
+ id: n.id,
134
+ light: n.light,
135
+ color: typeof w == "string" ? w : n.color,
136
+ intensity: A(c.get("intensity")) ?? n.intensity,
137
+ position: b,
138
+ direction: u.normalize(u.subtract(l, b)),
139
+ range: n.range,
140
+ angle: n.angle ?? 30
100
141
  });
101
142
  }
102
- const I = [], S = [];
103
- n.objects.forEach((o, a) => {
104
- if (o.kind !== "mesh" || !s.get(o.id)) return;
105
- const p = t.meshes.get(o.id), y = n.materials?.[o.material];
106
- if (!p || !y) return;
107
- const m = r(o.id), w = c.get(o.id), N = j(w), A = m.get("color"), E = (v(m.get("opacity")) ?? 1) * (y.opacity ?? 1);
108
- E <= 0 || (S.push({ objectId: o.id, objectIndex: a, mesh: p, world: w, material: y, color: typeof A == "string" ? A : void 0, opacity: E }), I.push(...W(p, w, N, u, k, y, {
109
- objectId: o.id,
110
- objectIndex: a,
111
- layer: o.layer ?? 0,
112
- color: typeof A == "string" ? A : void 0,
113
- opacity: E
143
+ const E = [], d = [];
144
+ o.objects.forEach((n, c) => {
145
+ if (n.kind !== "mesh" || !r.get(n.id)) return;
146
+ const b = t.meshes.get(n.id), l = o.materials?.[n.material];
147
+ if (!b || !l) return;
148
+ const w = s(n.id), m = a.get(n.id), O = F(m), S = w.get("color"), D = (A(w.get("opacity")) ?? 1) * (l.opacity ?? 1);
149
+ D <= 0 || (d.push({ objectId: n.id, objectIndex: c, mesh: b, world: m, material: l, color: typeof S == "string" ? S : void 0, opacity: D }), E.push(...H(b, m, O, y, M, l, {
150
+ objectId: n.id,
151
+ objectIndex: c,
152
+ layer: n.layer ?? 0,
153
+ color: typeof S == "string" ? S : void 0,
154
+ opacity: D
114
155
  })));
115
156
  });
116
- const d = [];
117
- return n.objects.forEach((o, a) => {
118
- const p = t.kinds.get(o.kind);
119
- if (!p || !s.get(o.id)) return;
120
- const y = p.resolve({
121
- object: o,
122
- prepared: t.prepared.get(o.id),
123
- values: r(o.id),
124
- world: c.get(o.id),
125
- camera: u,
157
+ const h = [];
158
+ o.objects.forEach((n, c) => {
159
+ const b = t.kinds.get(n.kind);
160
+ if (!b || !r.get(n.id)) return;
161
+ const l = b.resolve({
162
+ object: n,
163
+ prepared: t.prepared.get(n.id),
164
+ values: s(n.id),
165
+ world: a.get(n.id),
166
+ camera: y,
126
167
  width: i.width,
127
168
  height: i.height,
128
- toScreen: k
169
+ toScreen: M
129
170
  });
130
- if (!y) return;
131
- const m = o.layer ?? 0;
132
- for (const w of y.drawables ?? []) d.push({ ...w, objectId: o.id, objectIndex: a, layer: m });
133
- for (const w of y.meshes ?? [])
134
- S.push({ objectId: o.id, objectIndex: a, mesh: w.mesh, world: w.world, material: w.material, opacity: w.material.opacity ?? 1 }), I.push(...W(w.mesh, w.world, j(w.world), u, k, w.material, {
135
- objectId: o.id,
136
- objectIndex: a,
137
- layer: m,
138
- opacity: w.material.opacity ?? 1
171
+ if (!l) return;
172
+ const w = n.layer ?? 0;
173
+ for (const m of l.drawables ?? []) h.push({ ...m, objectId: n.id, objectIndex: c, layer: w });
174
+ for (const m of l.meshes ?? [])
175
+ d.push({ objectId: n.id, objectIndex: c, mesh: m.mesh, world: m.world, material: m.material, opacity: m.material.opacity ?? 1 }), E.push(...H(m.mesh, m.world, F(m.world), y, M, m.material, {
176
+ objectId: n.id,
177
+ objectIndex: c,
178
+ layer: w,
179
+ opacity: m.material.opacity ?? 1
139
180
  }));
140
- }), d.sort((o, a) => o.layer - a.layer || a.depth - o.depth || o.objectIndex - a.objectIndex), I.sort((o, a) => o.layer - a.layer || a.depth - o.depth || o.objectIndex - a.objectIndex || o.face - a.face || o.part - a.part), {
141
- id: n.id,
181
+ });
182
+ const P = { camera: y, height: i.height, fog: o.fog, toScreen: M };
183
+ return o.objects.forEach((n, c) => {
184
+ if (n.kind !== "line" && n.kind !== "trail" || !r.get(n.id)) return;
185
+ const b = s(n.id), l = n.kind === "line" ? st(n, a.get(n.id)) : rt(n, o, e, i);
186
+ if (!l) return;
187
+ const w = it(n, b);
188
+ if (w.opacity <= 0 || w.width <= 0) return;
189
+ const m = n.layer ?? 0;
190
+ for (const O of j(l.points, l.ages, w, P)) h.push({ ...O, objectId: n.id, objectIndex: c, layer: m });
191
+ }), h.sort((n, c) => n.layer - c.layer || c.depth - n.depth || n.objectIndex - c.objectIndex), E.sort((n, c) => n.layer - c.layer || c.depth - n.depth || n.objectIndex - c.objectIndex || n.face - c.face || n.part - c.part), {
192
+ id: o.id,
142
193
  width: i.width,
143
194
  height: i.height,
144
- background: n.background,
145
- fog: n.fog,
146
- camera: u,
147
- lights: P,
148
- worlds: c,
149
- triangles: I,
150
- drawables: d,
151
- meshes: S,
195
+ background: o.background,
196
+ fog: o.fog,
197
+ camera: y,
198
+ lights: C,
199
+ worlds: a,
200
+ triangles: E,
201
+ drawables: h,
202
+ meshes: d,
152
203
  time: i.time ?? 0
153
204
  };
154
205
  }
155
- function W(t, e, i, n, r, c, s) {
156
- const g = t.positions.length / 3, l = [], M = [];
157
- for (let d = 0; d < g; d++) {
158
- const o = b.transformPoint(e, [t.positions[d * 3], t.positions[d * 3 + 1], t.positions[d * 3 + 2]]);
159
- l.push(o), M.push(b.transformPoint(n.view, o));
206
+ function it(t, e) {
207
+ const i = e.get("color"), o = t.kind === "trail";
208
+ return {
209
+ color: typeof i == "string" ? i : t.color,
210
+ width: A(e.get("width")) ?? t.width ?? 0.05,
211
+ taper: t.taper ?? (o ? 1 : 0),
212
+ fade: t.fade ?? (o ? 1 : 0),
213
+ opacity: (A(e.get("opacity")) ?? 1) * (t.opacity ?? 1),
214
+ additive: t.blend === "add"
215
+ };
216
+ }
217
+ function st(t, e) {
218
+ const o = (t.closed ? [...t.points, t.points[0]] : t.points).map((s) => I.transformPoint(e, s));
219
+ return { points: o, ages: o.map((s, a) => 1 - a / (o.length - 1)) };
220
+ }
221
+ function rt(t, e, i, o) {
222
+ if (!o.valuesAt) return null;
223
+ const s = o.time ?? 0, a = A(i.get(`${e.id}/${t.id}`)?.get("length")) ?? t.length, r = U(
224
+ (p) => W(Z(e, t.follow, p === s ? i : o.valuesAt(p))),
225
+ s,
226
+ { length: a, samples: t.samples ?? 32, period: t.period }
227
+ );
228
+ return r.length >= 2 ? { points: r.map((p) => p.at), ages: r.map((p) => p.age) } : null;
229
+ }
230
+ function Z(t, e, i) {
231
+ const o = t.objects.find((a) => a.id === e);
232
+ if (!o) return I.identity();
233
+ const s = V(o, i.get(`${t.id}/${e}`) ?? L);
234
+ return o.parent ? I.multiply(Z(t, o.parent, i), s) : s;
235
+ }
236
+ function H(t, e, i, o, s, a, r) {
237
+ const p = t.positions.length / 3, g = [], k = [];
238
+ for (let h = 0; h < p; h++) {
239
+ const P = I.transformPoint(e, [t.positions[h * 3], t.positions[h * 3 + 1], t.positions[h * 3 + 2]]);
240
+ g.push(P), k.push(I.transformPoint(o.view, P));
160
241
  }
161
- const u = t.indices.length / 3, k = [], P = [];
162
- for (let d = 0; d < u; d++) {
163
- const [o, a, p] = [0, 1, 2].map((w) => l[t.indices[d * 3 + w]]), y = h.normalize(h.cross(h.subtract(a, o), h.subtract(p, o)));
164
- k.push(y);
165
- const m = n.orthographic ? h.scale(n.forward, -1) : h.subtract(n.position, o);
166
- P.push(h.dot(y, m) > 0);
242
+ const y = t.indices.length / 3, M = [], C = [];
243
+ for (let h = 0; h < y; h++) {
244
+ const [P, n, c] = [0, 1, 2].map((w) => g[t.indices[h * 3 + w]]), b = u.normalize(u.cross(u.subtract(n, P), u.subtract(c, P)));
245
+ M.push(b);
246
+ const l = o.orthographic ? u.scale(o.forward, -1) : u.subtract(o.position, P);
247
+ C.push(u.dot(b, l) > 0);
167
248
  }
168
- const I = (d) => -M[d][2] >= n.near, S = [];
169
- for (let d = 0; d < u; d++) {
170
- const o = P[d];
171
- if (!o && !c.doubleSided) continue;
172
- const a = [t.indices[d * 3], t.indices[d * 3 + 1], t.indices[d * 3 + 2]], p = a.map((f) => M[f]);
173
- if (p.every((f) => -f[2] > n.far)) continue;
174
- const y = U(p, n.near);
175
- if (y.length < 3) continue;
176
- const m = o ? 1 : -1, w = h.scale(k[d], m), N = a.map((f) => h.scale(Q(i, t.normals[f * 3], t.normals[f * 3 + 1], t.normals[f * 3 + 2]), m)), A = h.scale(h.add(h.add(l[a[0]], l[a[1]]), l[a[2]]), 1 / 3), E = -(p[0][2] + p[1][2] + p[2][2]) / 3, O = [];
177
- if (c.outline && o)
178
- for (const f of t.faceEdges[d]) {
179
- const D = f.across, R = D === -1 || !P[D], $ = !R && d < D && h.dot(k[d], k[D]) < H;
180
- (R || $) && I(f.a) && I(f.b) && O.push([r(M[f.a]), r(M[f.b])]);
249
+ const E = (h) => -k[h][2] >= o.near, d = [];
250
+ for (let h = 0; h < y; h++) {
251
+ const P = C[h];
252
+ if (!P && !a.doubleSided) continue;
253
+ const n = [t.indices[h * 3], t.indices[h * 3 + 1], t.indices[h * 3 + 2]], c = n.map((f) => k[f]);
254
+ if (c.every((f) => -f[2] > o.far)) continue;
255
+ const b = ot(c, o.near);
256
+ if (b.length < 3) continue;
257
+ const l = P ? 1 : -1, w = u.scale(M[h], l), m = n.map((f) => u.scale(nt(i, t.normals[f * 3], t.normals[f * 3 + 1], t.normals[f * 3 + 2]), l)), O = u.scale(u.add(u.add(g[n[0]], g[n[1]]), g[n[2]]), 1 / 3), S = -(c[0][2] + c[1][2] + c[2][2]) / 3, D = [];
258
+ if (a.outline && P)
259
+ for (const f of t.faceEdges[h]) {
260
+ const T = f.across, v = T === -1 || !C[T], J = !v && h < T && u.dot(M[h], M[T]) < tt;
261
+ (v || J) && E(f.a) && E(f.b) && D.push([s(k[f.a]), s(k[f.b])]);
181
262
  }
182
- const C = y.map(r);
183
- for (let f = 1; f + 1 < C.length; f++)
184
- S.push({
185
- objectId: s.objectId,
186
- objectIndex: s.objectIndex,
187
- layer: s.layer,
188
- face: d,
263
+ const $ = b.map(s);
264
+ for (let f = 1; f + 1 < $.length; f++)
265
+ d.push({
266
+ objectId: r.objectId,
267
+ objectIndex: r.objectIndex,
268
+ layer: r.layer,
269
+ face: h,
189
270
  part: f - 1,
190
- screen: [C[0], C[f], C[f + 1]],
191
- depth: E,
192
- centroid: A,
271
+ screen: [$[0], $[f], $[f + 1]],
272
+ depth: S,
273
+ centroid: O,
193
274
  normal: w,
194
- vertexNormals: N,
195
- material: c,
196
- color: s.color,
197
- opacity: s.opacity,
198
- outline: f === 1 ? O : []
275
+ vertexNormals: m,
276
+ material: a,
277
+ color: r.color,
278
+ opacity: r.opacity,
279
+ outline: f === 1 ? D : []
199
280
  });
200
281
  }
201
- return S;
282
+ return d;
202
283
  }
203
- class ot {
284
+ class gt {
204
285
  ctx;
205
286
  constructor(e) {
206
287
  this.ctx = e;
207
288
  }
208
289
  render(e) {
209
- _(this.ctx, e);
290
+ B(this.ctx, e);
210
291
  }
211
292
  }
212
- function _(t, e) {
293
+ function B(t, e) {
213
294
  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";
214
295
  let i = 0;
215
- const n = (s, g) => {
296
+ const o = (r, p) => {
216
297
  for (; i < e.drawables.length; ) {
217
- const l = e.drawables[i];
218
- if (l.layer > s || l.layer === s && l.depth <= g) break;
219
- t.save(), l.draw(t, e), t.restore(), i++;
298
+ const g = e.drawables[i];
299
+ if (g.layer > r || g.layer === r && g.depth <= p) break;
300
+ t.save(), g.draw(t, e), t.restore(), i++;
220
301
  }
221
302
  };
222
- let r = [];
223
- const c = (s) => {
224
- if (r.length === 0) return;
225
- const g = [];
226
- for (const l of r)
227
- s && s.objectId === l.objectId && s.layer === l.layer && l.depth - s.depth <= V * l.depth ? g.push(l) : G(t, l.triangle);
228
- r = g;
303
+ let s = [];
304
+ const a = (r) => {
305
+ if (s.length === 0) return;
306
+ const p = [];
307
+ for (const g of s)
308
+ r && r.objectId === g.objectId && r.layer === g.layer && g.depth - r.depth <= at * g.depth ? p.push(g) : lt(t, g.triangle);
309
+ s = p;
229
310
  };
230
- for (const s of e.triangles) {
231
- c(s), n(s.layer, s.depth);
232
- const { color: g, alpha: l } = B(s, e.lights, e.camera, e.fog), [M, u, k] = s.screen;
233
- t.globalAlpha = l, t.beginPath(), t.moveTo(M.x, M.y), t.lineTo(u.x, u.y), t.lineTo(k.x, k.y), t.closePath(), t.fillStyle = g, t.fill(), l >= 1 && (t.strokeStyle = g, t.lineWidth = 0.75, t.stroke()), s.material.outline && s.outline.length > 0 && r.push({ objectId: s.objectId, layer: s.layer, depth: s.depth, triangle: s });
311
+ for (const r of e.triangles) {
312
+ a(r), o(r.layer, r.depth);
313
+ const { color: p, alpha: g } = q(r, e.lights, e.camera, e.fog), [k, y, M] = r.screen;
314
+ t.globalAlpha = g, 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(), g >= 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 });
234
315
  }
235
- c(), n(1 / 0, -1 / 0), t.restore();
316
+ a(), o(1 / 0, -1 / 0), t.restore();
236
317
  }
237
- const V = 0.04;
238
- function G(t, e) {
318
+ const at = 0.04;
319
+ function lt(t, e) {
239
320
  const i = e.material.outline;
240
321
  t.globalAlpha = e.opacity, t.strokeStyle = i.color, t.lineWidth = i.width, t.beginPath();
241
- for (const [n, r] of e.outline)
242
- t.moveTo(n.x, n.y), t.lineTo(r.x, r.y);
322
+ for (const [o, s] of e.outline)
323
+ t.moveTo(o.x, o.y), t.lineTo(s.x, s.y);
243
324
  t.stroke();
244
325
  }
245
- class nt {
326
+ class ft {
246
327
  renderer;
247
328
  width;
248
329
  height;
249
330
  scenes = /* @__PURE__ */ new Map();
250
331
  values = /* @__PURE__ */ new Map();
332
+ valuesAt;
333
+ /** `valuesAt`: the values at another time (`(t) => timeline.getStateAtTime(t).values`), for trails */
251
334
  constructor(e, i) {
252
- this.renderer = e, this.width = i.width, this.height = i.height;
335
+ this.renderer = e, this.width = i.width, this.height = i.height, this.valuesAt = i.valuesAt;
253
336
  }
254
337
  /** Add a scene; its tracks address `<scene.id>/<objectId>`. */
255
338
  registerScene(e) {
@@ -267,40 +350,41 @@ class nt {
267
350
  time = 0;
268
351
  render() {
269
352
  for (const e of this.scenes.values())
270
- this.renderer.render(Z(e, this.values, { width: this.width, height: this.height, time: this.time }));
353
+ this.renderer.render(X(e, this.values, { width: this.width, height: this.height, time: this.time, valuesAt: this.valuesAt }));
271
354
  }
272
355
  }
273
- function it(t, e, i, n) {
274
- _(t, Z(e, i ?? /* @__PURE__ */ new Map(), { width: n.width, height: n.height, time: n.time }));
356
+ function ut(t, e, i, o) {
357
+ const s = o.stateAt, a = o.valuesAt ?? (s && ((r) => s(r).values));
358
+ B(t, X(e, i ?? /* @__PURE__ */ new Map(), { width: o.width, height: o.height, time: o.time, valuesAt: a }));
275
359
  }
276
360
  export {
277
- ot as Canvas2DRenderer,
278
- at as MeshBuilder,
279
- nt as Scene3DAdapter,
280
- ct as boxMesh,
281
- lt as coneMesh,
282
- dt as cylinderMesh,
283
- et as dollyPosition,
284
- _ as drawResolvedScene,
285
- it as drawScene3D,
286
- ht as extrudeMesh,
287
- Pt as fogAmount,
288
- gt as geometryMesh,
289
- St as lightAt,
290
- pt as loadScene3D,
291
- F as lookAtView,
292
- ft as meshEdges,
293
- tt as orbitPosition,
294
- At as parseColor,
295
- ut as planeMesh,
296
- yt as pointInPolygon,
297
- wt as prepareMesh,
361
+ gt as Canvas2DRenderer,
362
+ mt as MeshBuilder,
363
+ ft as Scene3DAdapter,
364
+ vt as boxMesh,
365
+ Mt as coneMesh,
366
+ bt as cylinderMesh,
367
+ pt as dollyPosition,
368
+ B as drawResolvedScene,
369
+ ut as drawScene3D,
370
+ kt as extrudeMesh,
371
+ G as fogAmount,
372
+ At as geometryMesh,
373
+ Wt as lightAt,
374
+ It as loadScene3D,
375
+ x as lookAtView,
376
+ Pt as meshEdges,
377
+ dt as orbitPosition,
378
+ z as parseColor,
379
+ St as planeMesh,
380
+ Tt as pointInPolygon,
381
+ Et as prepareMesh,
298
382
  Y as projectionMatrix,
299
- Z as resolveScene3D,
300
- B as shadeTriangle,
301
- mt as signedArea,
302
- vt as sphereMesh,
303
- Mt as torusMesh,
304
- bt as triangulate,
305
- kt as validateScene3D
383
+ X as resolveScene3D,
384
+ q as shadeTriangle,
385
+ Ct as signedArea,
386
+ Dt as sphereMesh,
387
+ Ot as torusMesh,
388
+ $t as triangulate,
389
+ Nt as validateScene3D
306
390
  };