@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,324 +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(i, c, n, e, a, t) {
8
- const o = Math.hypot(e, a, t) || 1;
9
- return this.positions.push(i, c, n), this.normals.push(e / o, a / o, t / o), this.positions.length / 3 - 1;
10
- }
11
- /** Add a triangle, counter-clockwise seen from its front. */
12
- triangle(i, c, n) {
13
- this.indices.push(i, c, n);
14
- }
15
- /** Add a quad a-b-c-d (counter-clockwise) as two triangles. */
16
- quad(i, c, n, e) {
17
- this.indices.push(i, c, n, i, n, e);
18
- }
19
- build() {
20
- return { positions: this.positions, normals: this.normals, indices: this.indices };
21
- }
22
- }
23
- function C(s) {
24
- const i = /* @__PURE__ */ new Map(), c = [];
25
- for (let e = 0; e < s.positions.length / 3; e++) {
26
- const a = [0, 1, 2].map((t) => Math.round(s.positions[e * 3 + t] * 1e6)).join(",");
27
- i.has(a) || i.set(a, e), c.push(i.get(a));
28
- }
29
- const n = /* @__PURE__ */ new Map();
30
- for (let e = 0; e < s.indices.length / 3; e++)
31
- for (let a = 0; a < 3; a++) {
32
- const t = c[s.indices[e * 3 + a]], o = c[s.indices[e * 3 + (a + 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(e) : n.set(r, { a: Math.min(t, o), b: Math.max(t, o), faces: [e] });
36
- }
37
- return [...n.values()];
38
- }
39
- function I(s) {
40
- let i = 0;
41
- for (let c = 0; c < s.length; c++) {
42
- const n = s[c], e = s[(c + 1) % s.length];
43
- i += n.x * e.y - e.x * n.y;
44
- }
45
- return i;
46
- }
47
- function _(s, i) {
48
- let c = !1;
49
- for (let n = 0, e = i.length - 1; n < i.length; e = n++) {
50
- const a = i[n], t = i[e];
51
- a.y > s.y != t.y > s.y && s.x < (t.x - a.x) * (s.y - a.y) / (t.y - a.y) + a.x && (c = !c);
52
- }
53
- return c;
54
- }
55
- const X = (s, i, c) => (i.x - s.x) * (c.y - s.y) - (i.y - s.y) * (c.x - s.x), Y = (s, i) => s.x === i.x && s.y === i.y;
56
- function P(s, i, c, n) {
57
- return X(i, c, s) >= 0 && X(c, n, s) >= 0 && X(n, i, s) >= 0;
58
- }
59
- function H(s, i) {
60
- let c = 0;
61
- for (let h = 1; h < i.length; h++) i[h].x > i[c].x && (c = h);
62
- const n = i[c];
63
- let e = -1, a = 1 / 0;
64
- for (let h = 0; h < s.length; h++) {
65
- const f = s[h], x = s[(h + 1) % s.length];
66
- if (f.y > n.y == x.y > n.y) continue;
67
- const g = f.x + (n.y - f.y) * (x.x - f.x) / (x.y - f.y);
68
- g >= n.x && g < a && (a = g, e = h);
69
- }
70
- if (e < 0) return s;
71
- const t = s[e], o = s[(e + 1) % s.length];
72
- let r = t.x > o.x ? e : (e + 1) % s.length;
73
- const l = { x: a, y: n.y };
74
- let d = 1 / 0;
75
- for (let h = 0; h < s.length; h++) {
76
- const f = s[h];
77
- if (h === r || f.x < n.x) continue;
78
- const x = s[r];
79
- if (!(P(f, n, l, x) || P(f, n, x, l))) continue;
80
- const p = Math.abs(Math.atan2(f.y - n.y, f.x - n.x));
81
- p < d && (d = p, r = h);
82
- }
83
- const u = i.slice(c).concat(i.slice(0, c));
84
- return [...s.slice(0, r + 1), ...u, n, s[r], ...s.slice(r + 1)];
85
- }
86
- function U(s, i = []) {
87
- const c = I(s) >= 0 ? s : [...s].reverse(), n = i.map((u) => I(u) <= 0 ? u : [...u].reverse()), e = [...c, ...n.flat()], a = /* @__PURE__ */ new Map();
88
- e.forEach((u, h) => a.set(u, h));
89
- const t = [...n].sort((u, h) => Math.max(...h.map((f) => f.x)) - Math.max(...u.map((f) => f.x)));
90
- let o = c;
91
- for (const u of t) o = H(o, u);
92
- const r = o.map((u) => a.get(u)), l = [];
93
- let d = r.length * r.length;
94
- for (; r.length > 3 && d-- > 0; ) {
95
- let u = !1;
96
- for (let h = 0; h < r.length; h++) {
97
- const f = r[(h + r.length - 1) % r.length], x = r[h], g = r[(h + 1) % r.length], [p, M, b] = [e[f], e[x], e[g]];
98
- if (X(p, M, b) <= 0) continue;
99
- let $ = !1;
100
- for (const y of r) {
101
- const w = e[y];
102
- if (!(y === f || y === x || y === g || Y(w, p) || Y(w, M) || Y(w, b)) && P(w, p, M, b)) {
103
- $ = !0;
104
- break;
105
- }
106
- }
107
- if (!$) {
108
- l.push(f, x, g), r.splice(h, 1), u = !0;
109
- break;
110
- }
111
- }
112
- u || (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: e, triangles: l };
115
- }
116
- function F(s, i) {
117
- const c = /* @__PURE__ */ new Map();
118
- for (const n of B(s).segments) {
119
- c.has(n.subpath) || c.set(n.subpath, [{ x: n.startX, y: -n.startY }]);
120
- const e = c.get(n.subpath);
121
- if (n.type === "L")
122
- e.push({ x: n.endX, y: -n.endY });
123
- else {
124
- const [a, t, o, r, l, d] = n.points;
125
- for (let u = 1; u <= i; u++) {
126
- const h = u / i, f = 1 - h, x = f * f * f * n.startX + 3 * f * f * h * a + 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 * d;
127
- e.push({ x, y: -g });
128
- }
129
- }
130
- }
131
- return [...c.values()].map((n) => n.filter((e, a) => a === 0 || e.x !== n[a - 1].x || e.y !== n[a - 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(I(n)) > 1e-12);
132
- }
133
- function W(s, i) {
134
- const c = F(s, Math.max(1, Math.round(i.curveSegments ?? 12))), n = new j();
135
- if (c.length === 0) return n.build();
136
- const e = c.flat(), a = Math.min(...e.map((p) => p.x)), t = Math.max(...e.map((p) => p.x)), o = Math.min(...e.map((p) => p.y)), r = Math.max(...e.map((p) => p.y)), l = (i.width ?? 1) / Math.max(t - a, 1e-9), d = (a + t) / 2, u = (o + r) / 2, h = c.map((p) => p.map((M) => ({ x: (M.x - d) * l, y: (M.y - u) * l }))), f = h.map((p, M) => h.filter((b, $) => $ !== M && _(p[0], b)).length), x = i.depth / 2, g = -i.depth / 2;
137
- return h.forEach((p, M) => {
138
- if (f[M] % 2 === 1) return;
139
- const b = h.filter((m, v) => f[v] === f[M] + 1 && _(m[0], p)), { points: $, triangles: y } = U(p, b), w = $.map((m) => n.vertex(m.x, m.y, x, 0, 0, 1)), E = $.map((m) => n.vertex(m.x, m.y, g, 0, 0, -1));
140
- for (let m = 0; m < y.length; m += 3)
141
- n.triangle(w[y[m]], w[y[m + 1]], w[y[m + 2]]), n.triangle(E[y[m]], E[y[m + 2]], E[y[m + 1]]);
142
- for (const m of [I(p) >= 0 ? p : [...p].reverse(), ...b.map((v) => I(v) <= 0 ? v : [...v].reverse())])
143
- for (let v = 0; v < m.length; v++) {
144
- const q = m[v], z = m[(v + 1) % m.length], A = z.y - q.y, S = -(z.x - q.x), D = n.vertex(q.x, q.y, g, A, S, 0), L = n.vertex(z.x, z.y, g, A, S, 0), O = n.vertex(z.x, z.y, x, A, S, 0), T = n.vertex(q.x, q.y, x, A, S, 0);
145
- n.quad(D, L, O, T);
146
- }
147
- }), n.build();
148
- }
149
- const k = Math.PI * 2;
150
- function Z([s, i, c]) {
151
- const n = new j(), e = s / 2, a = i / 2, t = c / 2, o = [
152
- [[0, 0, 1], [[-e, -a, t], [e, -a, t], [e, a, t], [-e, a, t]]],
153
- [[0, 0, -1], [[e, -a, -t], [-e, -a, -t], [-e, a, -t], [e, a, -t]]],
154
- [[1, 0, 0], [[e, -a, t], [e, -a, -t], [e, a, -t], [e, a, t]]],
155
- [[-1, 0, 0], [[-e, -a, -t], [-e, -a, t], [-e, a, t], [-e, a, -t]]],
156
- [[0, 1, 0], [[-e, a, t], [e, a, t], [e, a, -t], [-e, a, -t]]],
157
- [[0, -1, 0], [[-e, -a, -t], [e, -a, -t], [e, -a, t], [-e, -a, t]]]
158
- ];
159
- for (const [[r, l, d], u] of o) {
160
- const [h, f, x, g] = u.map(([p, M, b]) => n.vertex(p, M, b, r, l, d));
161
- n.quad(h, f, x, g);
162
- }
163
- return n.build();
164
- }
165
- function G([s, i], c = 1) {
166
- const n = new j(), e = Math.max(1, Math.round(c)), a = [];
167
- for (let t = 0; t <= e; t++) {
168
- const o = i / 2 - i * t / e;
169
- a.push(Array.from({ length: e + 1 }, (r, l) => n.vertex(-s / 2 + s * l / e, 0, o, 0, 1, 0)));
170
- }
171
- for (let t = 0; t < e; t++)
172
- for (let o = 0; o < e; o++) n.quad(a[t][o], a[t][o + 1], a[t + 1][o + 1], a[t + 1][o]);
173
- return n.build();
174
- }
175
- function J(s, i = 16) {
176
- const c = new j(), n = Math.max(6, Math.round(i)), e = Math.max(3, Math.round(n / 2)), a = [];
177
- for (let t = 0; t <= e; t++) {
178
- const o = t / e * Math.PI, r = [];
179
- for (let l = 0; l <= n; l++) {
180
- const d = l / n * k, u = Math.sin(o) * Math.sin(d), h = Math.cos(o), f = Math.sin(o) * Math.cos(d);
181
- r.push(c.vertex(u * s, h * s, f * s, u, h, f));
182
- }
183
- a.push(r);
184
- }
185
- for (let t = 0; t < e; t++)
186
- for (let o = 0; o < n; o++) {
187
- const r = a[t][o], l = a[t + 1][o], d = a[t + 1][o + 1], u = a[t][o + 1];
188
- t > 0 && c.triangle(r, l, u), t < e - 1 && c.triangle(l, d, u);
189
- }
190
- return c.build();
191
- }
192
- function N(s, i, c, n, e) {
193
- const a = s.vertex(0, c, 0, 0, n, 0), t = Array.from({ length: e }, (o, r) => {
194
- const l = r / e * k;
195
- return s.vertex(Math.sin(l) * i, c, Math.cos(l) * i, 0, n, 0);
196
- });
197
- for (let o = 0; o < e; o++) {
198
- const r = t[o], l = t[(o + 1) % e];
199
- n === 1 ? s.triangle(a, r, l) : s.triangle(a, l, r);
200
- }
201
- }
202
- function K(s, i, c = 24) {
203
- const n = new j(), e = Math.max(6, Math.round(c)), a = i / 2, t = -i / 2, o = (d) => Array.from({ length: e + 1 }, (u, h) => {
204
- const f = h / e * k;
205
- return n.vertex(Math.sin(f) * s, d, Math.cos(f) * s, Math.sin(f), 0, Math.cos(f));
206
- }), r = o(t), l = o(a);
207
- for (let d = 0; d < e; d++) n.quad(r[d], r[d + 1], l[d + 1], l[d]);
208
- return N(n, s, a, 1, e), N(n, s, t, -1, e), n.build();
209
- }
210
- function Q(s, i, c = 24) {
211
- const n = new j(), e = Math.max(6, Math.round(c)), a = i / 2, t = -i / 2, o = s / i;
212
- for (let r = 0; r < e; r++) {
213
- const l = r / e * k, d = (r + 1) / e * k, u = (l + d) / 2, h = n.vertex(Math.sin(l) * s, t, Math.cos(l) * s, Math.sin(l), o, Math.cos(l)), f = n.vertex(Math.sin(d) * s, t, Math.cos(d) * s, Math.sin(d), o, Math.cos(d)), x = n.vertex(0, a, 0, Math.sin(u), o, Math.cos(u));
214
- n.triangle(h, f, x);
215
- }
216
- return N(n, s, t, -1, e), n.build();
217
- }
218
- function R(s, i, c = 24) {
219
- const n = new j(), e = Math.max(6, Math.round(c)), a = Math.max(4, Math.round(e / 2)), t = [];
220
- for (let o = 0; o <= e; o++) {
221
- const r = o / e * k, l = [];
222
- for (let d = 0; d <= a; d++) {
223
- const u = d / a * k, h = Math.cos(u) * Math.sin(r), f = Math.sin(u), x = Math.cos(u) * Math.cos(r), g = s + i * Math.cos(u);
224
- l.push(n.vertex(g * Math.sin(r), i * Math.sin(u), g * Math.cos(r), h, f, x));
225
- }
226
- t.push(l);
227
- }
228
- for (let o = 0; o < e; o++)
229
- for (let r = 0; r < a; 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(s) {
233
- switch (s.type) {
234
- case "box":
235
- return Z(s.size);
236
- case "plane":
237
- return G(s.size, s.segments);
238
- case "sphere":
239
- return J(s.radius, s.segments);
240
- case "cylinder":
241
- return K(s.radius, s.height, s.segments);
242
- case "cone":
243
- return Q(s.radius, s.height, s.segments);
244
- case "torus":
245
- return R(s.radius, s.tube, s.segments);
246
- case "extrude":
247
- return W(s.path, { depth: s.depth, width: s.width, curveSegments: s.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(s, i = []) {
255
- const c = [], n = /* @__PURE__ */ new Map();
256
- for (const t of s.objects) {
257
- if (t.id ? n.has(t.id) && c.push(`two objects share the id "${t.id}"`) : c.push("an object has no id"), t.parent !== void 0 && !n.has(t.parent) && c.push(`"${t.id}" has parent "${t.parent}", which must be an earlier object`), t.quaternion && t.quaternion.length !== 4 && c.push(`"${t.id}": a quaternion has four numbers`), t.kind === "mesh") {
258
- s.materials?.[t.material] || c.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)) && c.push(`"${t.id}": an extrude needs a path that starts with M`), r.every((l) => Number.isFinite(l) && l > 0) || c.push(`"${t.id}": a ${o.type}'s sizes must be positive`);
261
- }
262
- t.kind === "camera" && (t.near > 0 && t.far > t.near || c.push(`camera "${t.id}": near must be above 0 and far beyond it`), t.projection === "perspective" && !(t.fov > 0 && t.fov < 180) && c.push(`camera "${t.id}": fov is between 0 and 180 degrees`), t.projection === "orthographic" && !(t.height > 0) && c.push(`camera "${t.id}": height must be positive`)), t.id && n.set(t.id, t);
263
- }
264
- const e = n.get(s.camera);
265
- e ? e.kind !== "camera" && c.push(`the scene's camera "${s.camera}" is a ${e.kind}, not a camera`) : c.push(`the scene's camera "${s.camera}" is not one of its objects`), s.fog && !(s.fog.far > s.fog.near) && c.push("fog: far must be beyond near");
266
- const a = /* @__PURE__ */ new Map();
267
- for (const t of i) {
268
- if (!t.target.startsWith(`${s.id}/`)) continue;
269
- const o = t.target.slice(s.id.length + 1);
270
- a.has(o) || a.set(o, /* @__PURE__ */ new Set()), a.get(o).add(t.property);
271
- }
272
- for (const [t, o] of a) {
273
- n.has(t) || c.push(`a track animates "${s.id}/${t}", which is not in the scene`);
274
- for (const r of tt)
275
- o.has(r.vector) && r.components.some((l) => o.has(l)) && c.push(`"${t}": its ${r.name} is animated both by ${r.vector} and by ${r.components.join(" / ")}; use one`);
276
- }
277
- return c;
278
- }
279
- function st(s) {
280
- const i = Array.from({ length: s.indices.length / 3 }, () => []);
281
- for (const c of C(s))
282
- for (const n of c.faces) {
283
- const e = c.faces.find((a) => a !== n) ?? -1;
284
- i[n].push({ a: c.a, b: c.b, across: e });
285
- }
286
- return { ...s, faceEdges: i };
287
- }
288
- function at(s, i = {}) {
289
- const c = new Map((i.kinds ?? []).map((t) => [t.kind, t])), n = nt(s);
290
- for (const t of s.objects) {
291
- if (et.has(t.kind)) continue;
292
- const o = c.get(t.kind);
293
- 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)`);
294
- }
295
- if (n.length > 0) throw new Error(`scene-3d: "${s.id}" is not valid:
296
- - ${n.join(`
297
- - `)}`);
298
- const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
299
- for (const t of s.objects) {
300
- t.kind === "mesh" && e.set(t.id, st(V(t.geometry)));
301
- const o = c.get(t.kind);
302
- o?.prepare && a.set(t.id, o.prepare(t));
303
- }
304
- return { scene: s, meshes: e, kinds: c, prepared: a };
305
- }
306
- const et = /* @__PURE__ */ new Set(["group", "mesh", "camera", "light"]);
307
- export {
308
- j as M,
309
- K as a,
310
- Z as b,
311
- Q as c,
312
- _ as d,
313
- W as e,
314
- st as f,
315
- V as g,
316
- J as h,
317
- U as i,
318
- at as l,
319
- C as m,
320
- G as p,
321
- I as s,
322
- R as t,
323
- nt as v
324
- };
@@ -1,85 +0,0 @@
1
- import { vec3 as f } from "@algorisys/tinyfly";
2
- const p = /* @__PURE__ */ new Map();
3
- function b(t) {
4
- const o = p.get(t);
5
- if (o) return o;
6
- let c = [1, 1, 1];
7
- const e = t.trim().replace("#", "");
8
- if (t.trim().startsWith("#") && (e.length === 3 || e.length === 6)) {
9
- const n = e.length === 3 ? e.split("").map((i) => i + i).join("") : e;
10
- c = [0, 2, 4].map((i) => Number.parseInt(n.slice(i, i + 2), 16) / 255);
11
- } else {
12
- const n = t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);
13
- n && (c = [Number(n[1]) / 255, Number(n[2]) / 255, Number(n[3]) / 255]);
14
- }
15
- return p.size < 512 && p.set(t, c), c;
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 = (t, o, c) => {
21
- const e = Math.min(1, Math.max(0, (c - t) / (o - t)));
22
- return e * e * (3 - 2 * e);
23
- };
24
- function g(t, o, c) {
25
- const e = [0, 0, 0];
26
- for (const n of c) {
27
- const i = b(n.color);
28
- let r;
29
- if (n.light === "ambient")
30
- r = n.intensity;
31
- else if (n.light === "directional")
32
- r = n.intensity * Math.max(0, -f.dot(o, n.direction));
33
- else {
34
- const a = f.subtract(n.position, t), m = f.length(a), d = m > 0 ? f.scale(a, 1 / m) : o, l = n.range ? Math.max(0, 1 - m / n.range) ** 2 : 1;
35
- if (r = n.intensity * Math.max(0, f.dot(o, d)) * l, n.light === "spot") {
36
- const s = Math.cos(n.angle * Math.PI / 180), h = Math.cos(n.angle * 0.8 * Math.PI / 180);
37
- r *= y(s, h, -f.dot(d, n.direction));
38
- }
39
- }
40
- e[0] += i[0] * r, e[1] += i[1] * r, e[2] += i[2] * r;
41
- }
42
- return e;
43
- }
44
- function N(t, o) {
45
- const c = Math.max(2, Math.round(o));
46
- return Math.min(1.2, Math.ceil(Math.min(1, t) * c - 1e-9) / c);
47
- }
48
- function v(t, o) {
49
- return t ? Math.min(1, Math.max(0, (o - t.near) / (t.far - t.near))) : 0;
50
- }
51
- function C(t, o, c, e) {
52
- const n = t.material, i = b(t.color ?? n.color), r = n.shading ?? "lambert";
53
- let a;
54
- if (r === "unlit")
55
- a = [...i];
56
- else {
57
- const l = o.length > 0 ? o : x;
58
- let s;
59
- if (r === "lambert") {
60
- const h = [0, 0, 0];
61
- for (const u of t.vertexNormals) {
62
- const M = g(t.centroid, u, l);
63
- h[0] += M[0] / 3, h[1] += M[1] / 3, h[2] += M[2] / 3;
64
- }
65
- s = h;
66
- } else if (s = g(t.centroid, t.normal, l), r === "toon") {
67
- const h = Math.max(s[0], s[1], s[2]), u = h > 0 ? N(h, n.bands ?? 3) / h : 0;
68
- s = [s[0] * u, s[1] * u, s[2] * u];
69
- }
70
- a = [i[0] * s[0], i[1] * s[1], i[2] * s[2]];
71
- }
72
- const m = v(e, f.distance(t.centroid, c.position));
73
- if (e && m > 0) {
74
- const l = b(e.color);
75
- a = [a[0] + (l[0] - a[0]) * m, a[1] + (l[1] - a[1]) * m, a[2] + (l[2] - a[2]) * m];
76
- }
77
- const d = (l) => Math.round(Math.min(1, Math.max(0, l)) * 255);
78
- return { color: `rgb(${d(a[0])}, ${d(a[1])}, ${d(a[2])})`, alpha: t.opacity };
79
- }
80
- export {
81
- v as f,
82
- g as l,
83
- b as p,
84
- C as s
85
- };