@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.
- package/README.md +7 -4
- package/bin/tinyfly.mjs +44 -6
- package/lib/addons/adapters.js +389 -281
- package/lib/addons/characters.js +3 -3
- package/lib/addons/load-scene-CQvcFWGJ.js +331 -0
- package/lib/addons/maps.js +1 -1
- package/lib/addons/scene-3d-webgl.js +52 -49
- package/lib/addons/scene-3d.js +299 -215
- package/lib/addons/shading-o5T_v9DT.js +89 -0
- package/lib/addons/{sketch-CA8ZXhxI.js → sketch-CYPUbk3Q.js} +2 -2
- package/lib/browser/tinyfly-scene-3d-webgl.iife.js +4 -2
- package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +2204 -2043
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/engine/tinyfly-engine.js +149 -106
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +165 -18
- package/lib/types/adapters/canvas/bloom.d.ts +33 -0
- package/lib/types/adapters/canvas/index.d.ts +3 -0
- package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
- package/lib/types/adapters/canvas/trail.d.ts +57 -0
- package/lib/types/browser/index.d.ts +4 -0
- package/lib/types/engine/path/index.d.ts +2 -0
- package/lib/types/engine/path/trail.d.ts +79 -0
- package/lib/types/headless/index.d.ts +1 -0
- package/lib/types/headless/loop-check.d.ts +41 -0
- package/lib/types/headless/node-video.d.ts +8 -0
- package/lib/types/headless/video-scene.d.ts +9 -1
- package/lib/types/scene-3d/resolve-scene.d.ts +6 -0
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +9 -1
- package/lib/types/scene-3d/scene-types.d.ts +42 -2
- package/lib/types/scene-3d/strokes.d.ts +30 -0
- package/lib/types/scene-3d/webgl/gl-data.d.ts +1 -0
- package/lib/types/scene-3d/webgl/shaders.d.ts +1 -1
- package/package.json +1 -1
- package/lib/addons/load-scene-vp14_Jj-.js +0 -324
- package/lib/addons/shading-ByG9UXd0.js +0 -85
package/lib/addons/scene-3d.js
CHANGED
|
@@ -1,255 +1,338 @@
|
|
|
1
|
-
import { M as
|
|
2
|
-
import { vec3 as
|
|
3
|
-
import { s as
|
|
4
|
-
import {
|
|
5
|
-
function
|
|
6
|
-
const i =
|
|
7
|
-
return
|
|
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
|
|
10
|
-
const
|
|
11
|
-
return [t[0] +
|
|
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
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
17
|
-
return
|
|
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
|
|
20
|
+
if (t.projection === "perspective") return I.perspective(t.fov, e, t.near, t.far);
|
|
21
21
|
const i = t.height / 2;
|
|
22
|
-
return
|
|
22
|
+
return I.orthographic(-i * e, i * e, -i, i, t.near, t.far);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
else if (
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
} else t.quaternion ?
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
84
|
+
return I.compose(o, s, k);
|
|
44
85
|
}
|
|
45
|
-
const
|
|
46
|
-
function
|
|
47
|
-
const
|
|
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:
|
|
51
|
-
projection:
|
|
52
|
-
position:
|
|
53
|
-
forward:
|
|
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
|
|
60
|
-
return
|
|
100
|
+
function F(t) {
|
|
101
|
+
return I.transpose(I.invert(t) ?? I.identity());
|
|
61
102
|
}
|
|
62
|
-
function
|
|
63
|
-
return
|
|
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
|
|
66
|
-
const i = (
|
|
67
|
-
for (let
|
|
68
|
-
const
|
|
69
|
-
if (i(
|
|
70
|
-
const
|
|
71
|
-
|
|
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
|
|
115
|
+
return o;
|
|
75
116
|
}
|
|
76
|
-
function
|
|
77
|
-
const { scene:
|
|
78
|
-
for (const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
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
|
|
85
|
-
const
|
|
86
|
-
return { x: (
|
|
87
|
-
},
|
|
88
|
-
for (const
|
|
89
|
-
if (
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
id:
|
|
93
|
-
light:
|
|
94
|
-
color: typeof
|
|
95
|
-
intensity:
|
|
96
|
-
position:
|
|
97
|
-
direction:
|
|
98
|
-
range:
|
|
99
|
-
angle:
|
|
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
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
objectId:
|
|
110
|
-
objectIndex:
|
|
111
|
-
layer:
|
|
112
|
-
color: typeof
|
|
113
|
-
opacity:
|
|
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
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
if (!
|
|
120
|
-
const
|
|
121
|
-
object:
|
|
122
|
-
prepared: t.prepared.get(
|
|
123
|
-
values:
|
|
124
|
-
world:
|
|
125
|
-
camera:
|
|
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:
|
|
169
|
+
toScreen: M
|
|
129
170
|
});
|
|
130
|
-
if (!
|
|
131
|
-
const
|
|
132
|
-
for (const
|
|
133
|
-
for (const
|
|
134
|
-
|
|
135
|
-
objectId:
|
|
136
|
-
objectIndex:
|
|
137
|
-
layer:
|
|
138
|
-
opacity:
|
|
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
|
-
})
|
|
141
|
-
|
|
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:
|
|
145
|
-
fog:
|
|
146
|
-
camera:
|
|
147
|
-
lights:
|
|
148
|
-
worlds:
|
|
149
|
-
triangles:
|
|
150
|
-
drawables:
|
|
151
|
-
meshes:
|
|
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
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
|
162
|
-
for (let
|
|
163
|
-
const [
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
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
|
|
169
|
-
for (let
|
|
170
|
-
const
|
|
171
|
-
if (!
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
for (const f of t.faceEdges[
|
|
179
|
-
const
|
|
180
|
-
(
|
|
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
|
|
183
|
-
for (let f = 1; f + 1 <
|
|
184
|
-
|
|
185
|
-
objectId:
|
|
186
|
-
objectIndex:
|
|
187
|
-
layer:
|
|
188
|
-
face:
|
|
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: [
|
|
191
|
-
depth:
|
|
192
|
-
centroid:
|
|
271
|
+
screen: [$[0], $[f], $[f + 1]],
|
|
272
|
+
depth: S,
|
|
273
|
+
centroid: O,
|
|
193
274
|
normal: w,
|
|
194
|
-
vertexNormals:
|
|
195
|
-
material:
|
|
196
|
-
color:
|
|
197
|
-
opacity:
|
|
198
|
-
outline: f === 1 ?
|
|
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
|
|
282
|
+
return d;
|
|
202
283
|
}
|
|
203
|
-
class
|
|
284
|
+
class gt {
|
|
204
285
|
ctx;
|
|
205
286
|
constructor(e) {
|
|
206
287
|
this.ctx = e;
|
|
207
288
|
}
|
|
208
289
|
render(e) {
|
|
209
|
-
|
|
290
|
+
B(this.ctx, e);
|
|
210
291
|
}
|
|
211
292
|
}
|
|
212
|
-
function
|
|
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
|
|
296
|
+
const o = (r, p) => {
|
|
216
297
|
for (; i < e.drawables.length; ) {
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
219
|
-
t.save(),
|
|
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
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
225
|
-
const
|
|
226
|
-
for (const
|
|
227
|
-
|
|
228
|
-
|
|
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
|
|
231
|
-
|
|
232
|
-
const { color:
|
|
233
|
-
t.globalAlpha =
|
|
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
|
-
|
|
316
|
+
a(), o(1 / 0, -1 / 0), t.restore();
|
|
236
317
|
}
|
|
237
|
-
const
|
|
238
|
-
function
|
|
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 [
|
|
242
|
-
t.moveTo(
|
|
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
|
|
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(
|
|
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
|
|
274
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
};
|