mesh-avatar 0.6.1 → 0.7.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 +5 -0
- package/dist/engine/expression-overlay.d.ts +14 -1
- package/dist/engine/expression-settings.d.ts +11 -0
- package/dist/engine/index.d.ts +3 -0
- package/dist/format/manifest.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1173 -1134
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,87 +21,87 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
21
21
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
function qe(
|
|
24
|
+
function qe(e, t) {
|
|
25
25
|
const n = [0];
|
|
26
|
-
for (let i = 1; i <
|
|
27
|
-
const r = Math.max(0, Math.min(1,
|
|
26
|
+
for (let i = 1; i < e.length; i++) n.push(n.at(-1) + Math.hypot(e[i][0] - e[i - 1][0], e[i][1] - e[i - 1][1]));
|
|
27
|
+
const r = Math.max(0, Math.min(1, t)) * n.at(-1);
|
|
28
28
|
let o = 1;
|
|
29
|
-
for (; o <
|
|
30
|
-
const
|
|
31
|
-
return
|
|
29
|
+
for (; o < e.length - 1 && n[o] < r; ) o++;
|
|
30
|
+
const s = (r - n[o - 1]) / Math.max(1e-9, n[o] - n[o - 1]);
|
|
31
|
+
return e[o - 1].map((i, u) => i + (e[o][u] - i) * s);
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
function
|
|
33
|
+
const Pt = (e) => e.slice(1).reduce((t, n, r) => t + Math.hypot(n[0] - e[r][0], n[1] - e[r][1]), 0);
|
|
34
|
+
function qn(e, t) {
|
|
35
35
|
let n = 0;
|
|
36
|
-
const r =
|
|
37
|
-
for (let i = 1; i <
|
|
38
|
-
const u =
|
|
39
|
-
for (let c = 1; c <
|
|
40
|
-
const f =
|
|
36
|
+
const r = Pt(e), o = [];
|
|
37
|
+
for (let i = 1; i < e.length; i++) {
|
|
38
|
+
const u = e[i - 1], y = e[i], v = y[0] - u[0], m = y[1] - u[1], l = Math.hypot(v, m);
|
|
39
|
+
for (let c = 1; c < t.length; c++) {
|
|
40
|
+
const f = t[c - 1], h = t[c], p = h[0] - f[0], g = h[1] - f[1], b = v * g - m * p;
|
|
41
41
|
if (Math.abs(b) < 1e-9) continue;
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const a = ((f[0] - u[0]) * g - (f[1] - u[1]) * p) / b, d = ((f[0] - u[0]) * m - (f[1] - u[1]) * v) / b;
|
|
43
|
+
a >= -1e-8 && a <= 1 + 1e-8 && d >= -1e-8 && d <= 1 + 1e-8 && o.push((n + a * l) / r);
|
|
44
44
|
}
|
|
45
45
|
n += l;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
return
|
|
47
|
+
const s = o.filter((i, u) => o.findIndex((y) => Math.abs(i - y) < 1e-7) === u);
|
|
48
|
+
if (s.length !== 1) throw new RangeError("Each tier must cross every column exactly once");
|
|
49
|
+
return s[0];
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
const o = r.map((m) => [0, ...
|
|
51
|
+
function kn(e) {
|
|
52
|
+
const t = !!(e.seams?.length || e.tiers?.length), n = e.seams?.length || (e.columns ?? 8), r = e.seams?.length ? e.seams : Array.from({ length: n }, (m, l) => [qe(e.waist, l / (n - 1)), qe(e.hem, l / (n - 1))]);
|
|
53
|
+
if (t && r.some((m) => Pt(m) < 1)) throw new RangeError("Columns must have nonzero source length");
|
|
54
|
+
const o = r.map((m) => [0, ...e.tiers?.length ? e.tiers.map((l) => qn(m, l)) : [0.5], 1]);
|
|
55
55
|
for (const m of o) if (m.some((l, c) => c > 0 && l - m[c - 1] < 1e-3)) throw new RangeError("Tier intersections must be ordered from waist to hem, with nonzero links");
|
|
56
|
-
const
|
|
56
|
+
const s = o[0].length - 1, i = t ? Math.max(2, Math.ceil(((e.rows ?? 5) - 1) / s)) : 0, u = t ? s * i + 1 : e.rows ?? 5, y = new Float64Array(u * n * 2), v = [];
|
|
57
57
|
for (let m = 0; m < n; m++) {
|
|
58
58
|
v[m] = [];
|
|
59
59
|
for (let l = 0; l < u; l++) {
|
|
60
|
-
const c =
|
|
60
|
+
const c = t ? Math.min(s - 1, Math.floor(l / i)) : 0, f = t ? (l - c * i) / i : l / (u - 1), h = t ? o[m][c] + (o[m][c + 1] - o[m][c]) * f : f;
|
|
61
61
|
v[m].push(h), y.set(qe(r[m], h), (l * n + m) * 2);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
if (
|
|
65
|
-
const c = (m * n + l) * 2, f = c + 2, h = c + n * 2, p = h + 2, g = (b,
|
|
64
|
+
if (t) for (let m = 0; m < u - 1; m++) for (let l = 0; l < n - 1; l++) {
|
|
65
|
+
const c = (m * n + l) * 2, f = c + 2, h = c + n * 2, p = h + 2, g = (b, a, d) => (y[a] - y[b]) * (y[d + 1] - y[b + 1]) - (y[a + 1] - y[b + 1]) * (y[d] - y[b]);
|
|
66
66
|
if (g(c, f, p) <= 1e-6 || g(c, p, h) <= 1e-6) throw new RangeError("Columns must be ordered left to right without crossing");
|
|
67
67
|
}
|
|
68
|
-
return { custom:
|
|
69
|
-
}
|
|
70
|
-
const le = (
|
|
71
|
-
(typeof
|
|
72
|
-
}, we = (
|
|
73
|
-
le(
|
|
74
|
-
}, De = (
|
|
75
|
-
le(
|
|
76
|
-
},
|
|
77
|
-
De(
|
|
78
|
-
}, _e = (
|
|
79
|
-
we(
|
|
80
|
-
}, ot = (
|
|
81
|
-
le(
|
|
82
|
-
}, yt = (
|
|
83
|
-
(typeof
|
|
84
|
-
}, Oe = (
|
|
68
|
+
return { custom: t, cols: n, rows: u, rest: y, seams: r, joints: o, fractions: v, lengths: r.map(Pt), top: r.map((m) => m[0]) };
|
|
69
|
+
}
|
|
70
|
+
const le = (e, t, n) => {
|
|
71
|
+
(typeof e != "number" || !Number.isFinite(e)) && n.push(`${t}: expected a finite number`);
|
|
72
|
+
}, we = (e, t, n) => {
|
|
73
|
+
le(e, t, n), typeof e == "number" && e <= 0 && n.push(`${t}: must be positive`);
|
|
74
|
+
}, De = (e, t, n) => {
|
|
75
|
+
le(e, t, n), typeof e == "number" && e < 0 && n.push(`${t}: must be nonnegative`);
|
|
76
|
+
}, Jn = (e, t, n) => {
|
|
77
|
+
De(e, t, n), typeof e == "number" && (!Number.isInteger(e) || e > 8) && n.push(`${t}: expected an integer from 0 to 8`);
|
|
78
|
+
}, _e = (e, t, n) => {
|
|
79
|
+
we(e, t, n), typeof e == "number" && !Number.isInteger(e) && n.push(`${t}: expected an integer`);
|
|
80
|
+
}, ot = (e, t, n) => {
|
|
81
|
+
le(e, t, n), typeof e == "number" && !Number.isInteger(e) && n.push(`${t}: expected an integer`);
|
|
82
|
+
}, yt = (e, t, n) => {
|
|
83
|
+
(typeof e != "string" || !e.trim()) && n.push(`${t}: expected a non-empty string`);
|
|
84
|
+
}, Oe = (e, t = 0, n = 1 / 0) => (r, o, s) => {
|
|
85
85
|
if (!Array.isArray(r)) {
|
|
86
|
-
|
|
86
|
+
s.push(`${o}: expected an array`);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
|
-
(r.length <
|
|
90
|
-
}, me = Oe(le, 2, 2), Ae = (
|
|
91
|
-
me(
|
|
92
|
-
}, he = (
|
|
89
|
+
(r.length < t || r.length > n) && s.push(`${o}: expected ${t}..${n} items`), r.forEach((i, u) => e(i, `${o}[${u}]`, s));
|
|
90
|
+
}, me = Oe(le, 2, 2), Ae = (e, t, n) => {
|
|
91
|
+
me(e, t, n), Array.isArray(e) && e.length === 2 && e[0] >= e[1] && n.push(`${t}: start must be less than end`);
|
|
92
|
+
}, he = (e, t = []) => (n, r, o) => {
|
|
93
93
|
if (!n || typeof n != "object" || Array.isArray(n)) {
|
|
94
94
|
o.push(`${r}: expected an object`);
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
const
|
|
98
|
-
for (const [i, u] of Object.entries(
|
|
99
|
-
|
|
100
|
-
}, ft = { cx: le, cy: le, rx: we, ry: we }, Ue = he(ft),
|
|
101
|
-
le(
|
|
102
|
-
},
|
|
103
|
-
version: (
|
|
104
|
-
|
|
97
|
+
const s = n;
|
|
98
|
+
for (const [i, u] of Object.entries(e))
|
|
99
|
+
s[i] === void 0 && t.includes(i) || u(s[i], `${r}.${i}`, o);
|
|
100
|
+
}, ft = { cx: le, cy: le, rx: we, ry: we }, Ue = he(ft), st = Oe(me, 3), Xe = Oe(me, 2), Je = (e, t, n) => {
|
|
101
|
+
le(e, t, n), typeof e == "number" && (e < 0 || e > 1) && n.push(`${t}: must be between 0 and 1`);
|
|
102
|
+
}, Kn = (e) => he({
|
|
103
|
+
version: (t, n, r) => {
|
|
104
|
+
t !== 1 && r.push(`${n}: only version 1 is supported`);
|
|
105
105
|
},
|
|
106
106
|
image: he({ width: _e, height: _e }),
|
|
107
107
|
head: he({
|
|
@@ -136,13 +136,13 @@ const le = (t, e, n) => {
|
|
|
136
136
|
}),
|
|
137
137
|
buns: he({ bunL: Ue, bunR: Ue }, ["bunL", "bunR"]),
|
|
138
138
|
eyes: Oe(he({
|
|
139
|
-
opening:
|
|
140
|
-
roi:
|
|
139
|
+
opening: st,
|
|
140
|
+
roi: st,
|
|
141
141
|
x0: le,
|
|
142
142
|
x1: le,
|
|
143
143
|
top: Oe(le, 24, 24),
|
|
144
144
|
bot: Oe(le, 24, 24)
|
|
145
|
-
},
|
|
145
|
+
}, e ? ["x0", "x1", "top", "bot"] : []), 2, 2),
|
|
146
146
|
mouth: he({
|
|
147
147
|
cx: le,
|
|
148
148
|
cy: le,
|
|
@@ -162,10 +162,10 @@ const le = (t, e, n) => {
|
|
|
162
162
|
color: he({ redness: Je, minRed: le })
|
|
163
163
|
})),
|
|
164
164
|
hand: he({
|
|
165
|
-
outline:
|
|
165
|
+
outline: st,
|
|
166
166
|
jaw: Xe,
|
|
167
167
|
jawRange: Ae,
|
|
168
|
-
background:
|
|
168
|
+
background: st,
|
|
169
169
|
elbow: me,
|
|
170
170
|
wrist: me,
|
|
171
171
|
knuckle: me,
|
|
@@ -180,7 +180,7 @@ const le = (t, e, n) => {
|
|
|
180
180
|
}),
|
|
181
181
|
cloth: Oe(he({
|
|
182
182
|
name: yt,
|
|
183
|
-
outline:
|
|
183
|
+
outline: st,
|
|
184
184
|
waist: Xe,
|
|
185
185
|
hem: Xe,
|
|
186
186
|
columns: _e,
|
|
@@ -193,10 +193,10 @@ const le = (t, e, n) => {
|
|
|
193
193
|
responseGain: we,
|
|
194
194
|
swing: we,
|
|
195
195
|
follow: Je,
|
|
196
|
-
cohesion:
|
|
196
|
+
cohesion: Jn,
|
|
197
197
|
wind: De,
|
|
198
|
-
behind: (
|
|
199
|
-
typeof
|
|
198
|
+
behind: (t, n, r) => {
|
|
199
|
+
typeof t != "boolean" && r.push(`${n}: expected a boolean`);
|
|
200
200
|
},
|
|
201
201
|
parent: yt,
|
|
202
202
|
scale: we,
|
|
@@ -241,38 +241,38 @@ const le = (t, e, n) => {
|
|
|
241
241
|
}, ["clothCell"]),
|
|
242
242
|
view: he({ padTop: le, padSide: le, gazeCenter: me, irisTravel: we }, ["gazeCenter", "irisTravel"])
|
|
243
243
|
}, ["buns", "strands", "accessories", "hand", "cloth", "legs", "arms"]);
|
|
244
|
-
function
|
|
244
|
+
function Ln(e, t = {}) {
|
|
245
245
|
const n = [];
|
|
246
|
-
if (
|
|
247
|
-
const r =
|
|
248
|
-
r.eyes.forEach((
|
|
246
|
+
if (Kn(t.draft ?? !1)(e, "rig", n), n.length) return n;
|
|
247
|
+
const r = e;
|
|
248
|
+
r.eyes.forEach((s, i) => {
|
|
249
249
|
const u = ["x0", "x1", "top", "bot"];
|
|
250
|
-
if (!(
|
|
251
|
-
if (u.some((y) =>
|
|
250
|
+
if (!(t.draft && u.every((y) => s[y] === void 0))) {
|
|
251
|
+
if (u.some((y) => s[y] === void 0)) {
|
|
252
252
|
n.push(`rig.eyes[${i}]: supply all x0/x1/top/bot fields or omit all in a draft`);
|
|
253
253
|
return;
|
|
254
254
|
}
|
|
255
|
-
|
|
255
|
+
s.x0 >= s.x1 && n.push(`rig.eyes[${i}].x1: must exceed x0`), s.top.some((y, v) => y > s.bot[v]) && n.push(`rig.eyes[${i}].top: must not exceed bottom curve`);
|
|
256
256
|
}
|
|
257
257
|
}), (r.mesh.fine.x0 >= r.mesh.fine.x1 || r.mesh.fine.y0 >= r.mesh.fine.y1) && n.push("rig.mesh.fine: rectangle must have positive area"), (r.view.padTop <= -1 || r.view.padTop >= 1 || r.view.padSide <= -0.5) && n.push("rig.view: margins must leave a positive viewport");
|
|
258
|
-
for (const [
|
|
259
|
-
i.nodes.some((u, y) => y > 0 && u[0] === i.nodes[y - 1][0] && u[1] === i.nodes[y - 1][1]) && n.push(`rig.strands[${
|
|
260
|
-
for (const [
|
|
261
|
-
(i.box[0] < 0 || i.box[1] < 0 || i.box[2] > r.image.width || i.box[3] > r.image.height) && n.push(`rig.accessories[${
|
|
258
|
+
for (const [s, i] of (r.strands ?? []).entries())
|
|
259
|
+
i.nodes.some((u, y) => y > 0 && u[0] === i.nodes[y - 1][0] && u[1] === i.nodes[y - 1][1]) && n.push(`rig.strands[${s}].nodes: consecutive nodes must differ`);
|
|
260
|
+
for (const [s, i] of (r.accessories ?? []).entries())
|
|
261
|
+
(i.box[0] < 0 || i.box[1] < 0 || i.box[2] > r.image.width || i.box[3] > r.image.height) && n.push(`rig.accessories[${s}].box: rectangle must stay inside the image`), (i.split <= 0 || i.split >= 1) && n.push(`rig.accessories[${s}].split: must be strictly between 0 and 1`), i.pivot.every((u, y) => u === i.tip[y]) && n.push(`rig.accessories[${s}].tip: must differ from pivot`), (i.box[0] >= i.box[2] || i.box[1] >= i.box[3]) && n.push(`rig.accessories[${s}].box: rectangle must have positive area`);
|
|
262
262
|
const o = /* @__PURE__ */ new Set();
|
|
263
263
|
if (r.legs) {
|
|
264
264
|
(r.legs.twist ?? 0) > 15 && n.push("rig.legs.twist: must be between 0 and 15 degrees");
|
|
265
|
-
const
|
|
265
|
+
const s = r.legs;
|
|
266
266
|
for (const i of ["left", "right"]) {
|
|
267
|
-
const u =
|
|
268
|
-
|
|
267
|
+
const u = s[i];
|
|
268
|
+
s.band[0] < u.hip[1] && u.hip[1] < u.knee[1] && u.knee[1] < u.ankle[1] || n.push(`rig.legs.${i}: require band start < hip y < knee y < ankle y`);
|
|
269
269
|
}
|
|
270
|
-
|
|
270
|
+
s.split.some((i, u) => u > 0 && i[1] <= s.split[u - 1][1]) && n.push("rig.legs.split: y coordinates must increase");
|
|
271
271
|
}
|
|
272
272
|
if (r.arms) {
|
|
273
273
|
(r.arms.swing ?? 4) > 10 && n.push("rig.arms.swing: must be between 0 and 10 degrees"), (r.arms.bend ?? 6) > 12 && n.push("rig.arms.bend: must be between 0 and 12 degrees");
|
|
274
|
-
for (const
|
|
275
|
-
const i = r.arms[
|
|
274
|
+
for (const s of ["left", "right"]) {
|
|
275
|
+
const i = r.arms[s], u = `rig.arms.${s}`;
|
|
276
276
|
i.shoulder[1] < i.elbow[1] && i.elbow[1] < i.wrist[1] || n.push(`${u}: require shoulder y < elbow y < wrist y`);
|
|
277
277
|
for (const [y, v] of Object.entries({ shoulder: [i.shoulder], elbow: [i.elbow], wrist: [i.wrist], split: i.split }))
|
|
278
278
|
v.some(([m, l]) => m < 0 || l < 0 || m >= r.image.width || l >= r.image.height) && n.push(`${u}.${y}: points must stay inside the image`);
|
|
@@ -285,65 +285,65 @@ function Rn(t, e = {}) {
|
|
|
285
285
|
const l = i.split[m], c = i.split[m + 1], f = Math.max(0, Math.min(1, (v - l[1]) / (c[1] - l[1])));
|
|
286
286
|
return l[0] + (c[0] - l[0]) * f;
|
|
287
287
|
};
|
|
288
|
-
[i.elbow, i.wrist].some(([v, m]) =>
|
|
288
|
+
[i.elbow, i.wrist].some(([v, m]) => s === "left" ? y(m) <= v : y(m) >= v) && n.push(`${u}.split: must lie on the body side of elbow and wrist`);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
for (const [
|
|
293
|
-
if ((!/^[A-Za-z0-9_-]+$/.test(i.name) || o.has(i.name)) && n.push(`rig.cloth[${
|
|
294
|
-
i.seams?.some((u) => u.some((y, v) => v > 0 && y[1] <= u[v - 1][1])) && n.push(`rig.cloth[${
|
|
292
|
+
for (const [s, i] of (r.cloth ?? []).entries()) {
|
|
293
|
+
if ((!/^[A-Za-z0-9_-]+$/.test(i.name) || o.has(i.name)) && n.push(`rig.cloth[${s}].name: must be a unique layer-safe name`), i.parent !== void 0 && !o.has(i.parent) && n.push(`rig.cloth[${s}].parent: must name an earlier cloth entry`), ((i.columns ?? 2) < 2 || (i.rows ?? 2) < 2) && n.push(`rig.cloth[${s}]: columns and rows must be at least 2`), i.seams?.length === 1 && n.push(`rig.cloth[${s}].seams: at least two columns required`), i.seams?.length || i.tiers?.length) {
|
|
294
|
+
i.seams?.some((u) => u.some((y, v) => v > 0 && y[1] <= u[v - 1][1])) && n.push(`rig.cloth[${s}].seams: y must increase from waist to hem`);
|
|
295
295
|
try {
|
|
296
|
-
|
|
296
|
+
kn(i);
|
|
297
297
|
} catch (u) {
|
|
298
|
-
n.push(`rig.cloth[${
|
|
298
|
+
n.push(`rig.cloth[${s}]: ${u instanceof Error ? u.message : String(u)}`);
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
o.add(i.name);
|
|
302
302
|
}
|
|
303
303
|
return n;
|
|
304
304
|
}
|
|
305
|
-
function
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
-
${
|
|
305
|
+
function en(e) {
|
|
306
|
+
const t = Ln(e);
|
|
307
|
+
if (t.length) throw new Error(`Invalid rig:
|
|
308
|
+
${t.join(`
|
|
309
309
|
`)}`);
|
|
310
|
-
return structuredClone(
|
|
310
|
+
return structuredClone(e);
|
|
311
311
|
}
|
|
312
|
-
const Ke = (
|
|
313
|
-
const r = Ke((n -
|
|
312
|
+
const Ke = (e, t, n) => Math.max(t, Math.min(n, e)), Ye = (e, t, n) => {
|
|
313
|
+
const r = Ke((n - e) / (t - e), 0, 1);
|
|
314
314
|
return r * r * (3 - 2 * r);
|
|
315
|
-
}, At = (
|
|
316
|
-
const r =
|
|
317
|
-
return [
|
|
315
|
+
}, At = (e, t) => Math.hypot(e[0] - t[0], e[1] - t[1]), vt = (e, t, n) => {
|
|
316
|
+
const r = e[0] - t[0], o = e[1] - t[1], s = Math.cos(n), i = Math.sin(n);
|
|
317
|
+
return [t[0] + r * s - o * i, t[1] + r * i + o * s];
|
|
318
318
|
};
|
|
319
|
-
function
|
|
320
|
-
const o = At(
|
|
319
|
+
function cn(e, t, n, r) {
|
|
320
|
+
const o = At(e, t), s = At(n, r), i = (t[0] - e[0]) / o, u = (t[1] - e[1]) / o, y = (r[0] - n[0]) / s, v = (r[1] - n[1]) / s, m = s / o, l = [
|
|
321
321
|
y * m * i + v * u,
|
|
322
322
|
y * m * u - v * i,
|
|
323
323
|
v * m * i - y * u,
|
|
324
324
|
v * m * u + y * i
|
|
325
325
|
];
|
|
326
|
-
return [...l, n[0] - l[0] *
|
|
326
|
+
return [...l, n[0] - l[0] * e[0] - l[1] * e[1], n[1] - l[2] * e[0] - l[3] * e[1]];
|
|
327
327
|
}
|
|
328
|
-
const
|
|
329
|
-
function
|
|
330
|
-
if (!
|
|
331
|
-
const r = [
|
|
328
|
+
const hn = (e, t) => [t[0] * e[0] + t[1] * e[1] + t[4], t[2] * e[0] + t[3] * e[1] + t[5]], kt = Object.freeze({ spine: 0.7, bob: 2, twist: 0 });
|
|
329
|
+
function Qn(e, t, n = null) {
|
|
330
|
+
if (!e) return null;
|
|
331
|
+
const r = [e.left, e.right].map((F, j) => {
|
|
332
332
|
const C = At(F.hip, F.knee), B = At(F.knee, F.ankle), H = Math.min(C, B) * 0.05, N = Math.hypot(C, H), ne = Math.hypot(B, H), Q = F.ankle[0] - F.hip[0], J = F.ankle[1] - F.hip[1], X = Q * (F.knee[1] - F.hip[1]) - J * (F.knee[0] - F.hip[0]);
|
|
333
333
|
return { ...F, u: N, v: ne, depth: H, lateral: X / Math.hypot(Q, J), side: Math.sign(X) || (j ? 1 : -1) };
|
|
334
|
-
}), o = (
|
|
334
|
+
}), o = (e.twist ?? 0) > 0, s = (e.twist ?? 0) * Math.PI / 180, i = Math.max(1, ...r.map((F) => Math.abs(F.hip[0] - e.pelvis[0]) * 1.35)), u = Math.max(t.chest.rx, ...t.shoulders.map((F) => Math.abs(F.cx - t.chest.cx) + F.rx)), y = [0, 0], v = [0, 0];
|
|
335
335
|
let m = 0;
|
|
336
336
|
const l = (F, j, C, B) => {
|
|
337
337
|
const H = F - j, N = Math.max(0, 1 - (H / C) ** 2);
|
|
338
338
|
return H * (Math.cos(B) - 1) + C * 0.75 * N * N * Math.sin(B);
|
|
339
339
|
}, c = [0, 0, 0], f = [0, 0, 0];
|
|
340
|
-
let h = 0, p = 0, g = 0, b = 0,
|
|
340
|
+
let h = 0, p = 0, g = 0, b = 0, a;
|
|
341
341
|
function d(F, j) {
|
|
342
|
-
const C = Ke(F.weightShift ?? 0, -1, 1), B = Math.min(Math.max(j, 0), 0.05), H = v[0], N = o ?
|
|
342
|
+
const C = Ke(F.weightShift ?? 0, -1, 1), B = Math.min(Math.max(j, 0), 0.05), H = v[0], N = o ? s * Ke(0.4 * C + (B ? 0.6 * Math.tanh((C - g) / B) : 0), -1, 1) : 0;
|
|
343
343
|
if (!B)
|
|
344
344
|
o && (y.fill(N), v.fill(0), m = 0), c.fill(C), f.fill(0), h = 0, p = 0;
|
|
345
345
|
else {
|
|
346
|
-
const ne = (
|
|
346
|
+
const ne = (e.bob ?? kt.bob) * Math.min(1, Math.abs(C - g) / B / 1.5), Q = Math.ceil(B * 240), J = B / Q;
|
|
347
347
|
for (let X = 0; X < Q; X++) {
|
|
348
348
|
for (let G = 0; G < 3; G++) {
|
|
349
349
|
const re = G ? c[G - 1] : C;
|
|
@@ -362,18 +362,18 @@ function Jn(t, e, n = null) {
|
|
|
362
362
|
let w, A, L;
|
|
363
363
|
function z(F) {
|
|
364
364
|
const j = Ke(F.weightShift ?? 0, -1, 1), C = Ke(F.bodyAngleX ?? 0, -10, 10);
|
|
365
|
-
if (j === w && C === A && b ===
|
|
366
|
-
w = j, A = C,
|
|
367
|
-
const B = -
|
|
368
|
-
const M = vt(V,
|
|
369
|
-
return o && (M[0] += l(V[0],
|
|
370
|
-
}, J = r.map((V) => Q(V.hip)), X = r.map((V, M) => V.lateral + V.side *
|
|
371
|
-
let te = h +
|
|
365
|
+
if (j === w && C === A && b === a) return L;
|
|
366
|
+
w = j, A = C, a = b;
|
|
367
|
+
const B = -e.tilt * j, H = e.shift * j + C / 10 * (t.hip?.shift ?? e.shift), N = o ? b ? y[0] : s * 0.4 * j : 0, ne = o ? -(1 - (e.spine ?? kt.spine)) * (b ? y[1] : N) : 0, Q = (V) => {
|
|
368
|
+
const M = vt(V, e.pelvis, B);
|
|
369
|
+
return o && (M[0] += l(V[0], e.pelvis[0], i, N)), M[0] += H, M;
|
|
370
|
+
}, J = r.map((V) => Q(V.hip)), X = r.map((V, M) => V.lateral + V.side * e.bend * Math.max(0, M ? -j : j) ** 2), G = j * j + (C / 10) ** 2, re = e.bend ** 2 / Math.min(...r.map((V) => V.u + V.v)) * G, W = (V) => (V + Math.hypot(V, re)) / 2;
|
|
371
|
+
let te = h + e.bend ** 2 / Math.min(...r.map((V) => V.u + V.v)) * j * j;
|
|
372
372
|
for (let V = 0; V < r.length; V++) {
|
|
373
373
|
const M = r[V], E = J[V], O = E[0] - M.ankle[0], k = Math.sqrt(Math.max(0, M.u * M.u - X[V] ** 2)) + Math.sqrt(Math.max(0, M.v * M.v - X[V] ** 2)), $ = M.ankle[1] - Math.sqrt(Math.max(0, k * k - O * O)) - E[1];
|
|
374
374
|
te += W($ - te);
|
|
375
375
|
}
|
|
376
|
-
const
|
|
376
|
+
const ae = r.map((V, M) => {
|
|
377
377
|
const E = [J[M][0], J[M][1] + te], O = V.ankle;
|
|
378
378
|
if (!j && !C && !h && !N) return {
|
|
379
379
|
hip: V.hip,
|
|
@@ -396,8 +396,8 @@ function Jn(t, e, n = null) {
|
|
|
396
396
|
hip3: [...E, 0],
|
|
397
397
|
knee3: [...q, ee],
|
|
398
398
|
ankle3: [...O, 0],
|
|
399
|
-
upper:
|
|
400
|
-
lower:
|
|
399
|
+
upper: cn(V.hip, V.knee, E, q),
|
|
400
|
+
lower: cn(V.knee, V.ankle, q, O)
|
|
401
401
|
};
|
|
402
402
|
});
|
|
403
403
|
return L = {
|
|
@@ -406,21 +406,21 @@ function Jn(t, e, n = null) {
|
|
|
406
406
|
angle: B,
|
|
407
407
|
shift: H,
|
|
408
408
|
drop: te,
|
|
409
|
-
bones:
|
|
409
|
+
bones: ae,
|
|
410
410
|
...o && { twist: { pelvis: N, shoulder: ne, head: 0, acceleration: m } },
|
|
411
411
|
trunk: { spine: c[0], chest: c[1], head: c[2], bob: h }
|
|
412
412
|
}, L;
|
|
413
413
|
}
|
|
414
414
|
function Y(F) {
|
|
415
|
-
const j =
|
|
415
|
+
const j = e.split;
|
|
416
416
|
let C = 0;
|
|
417
417
|
for (; C < j.length - 2 && F > j[C + 1][1]; ) C++;
|
|
418
418
|
const B = j[C], H = j[C + 1], N = Ke((F - B[1]) / (H[1] - B[1]), 0, 1);
|
|
419
419
|
return B[0] + (H[0] - B[0]) * N;
|
|
420
420
|
}
|
|
421
421
|
function I(F, j) {
|
|
422
|
-
const C = j >=
|
|
423
|
-
leg: Ye(
|
|
422
|
+
const C = j >= e.split[0][1] ? +(F >= Y(j)) : Ye(Y(j) - 4, Y(j) + 4, F), B = r.map((H) => ({
|
|
423
|
+
leg: Ye(e.band[0], H.hip[1], j),
|
|
424
424
|
shin: Ye(H.knee[1] - 45, H.knee[1] + 45, j),
|
|
425
425
|
pin: 1 - Ye(H.ankle[1] - 55, H.ankle[1], j)
|
|
426
426
|
}));
|
|
@@ -429,41 +429,41 @@ function Jn(t, e, n = null) {
|
|
|
429
429
|
function U(F, j, C, B, H) {
|
|
430
430
|
const N = z(H);
|
|
431
431
|
if (!N.ws && !N.bx && !N.trunk.chest && !N.trunk.head && !h && !N.twist?.pelvis && !N.twist?.shoulder) return;
|
|
432
|
-
const ne = [
|
|
433
|
-
const E = vt(M,
|
|
432
|
+
const ne = [e.pelvis[0] + N.shift, e.pelvis[1] + N.drop], Q = 1 - Ye(Math.min(t.chest.cy, e.pelvis[1] - 1), e.pelvis[1], C), J = 1 - Ye(...e.band, C), X = e.spine ?? kt.spine, G = e.tilt * (1 - X) * N.trunk.chest, re = e.shift * (1.12 * N.trunk.chest - N.ws) + Math.sin(G) * Math.max(0, e.pelvis[1] - t.chest.cy), W = (M) => {
|
|
433
|
+
const E = vt(M, e.pelvis, N.angle);
|
|
434
434
|
E[0] += N.shift, E[1] += N.drop;
|
|
435
435
|
const O = vt(E, ne, (G - N.angle) * J);
|
|
436
436
|
return O[0] += re * Q, O;
|
|
437
437
|
}, te = W(F);
|
|
438
438
|
if (n) {
|
|
439
|
-
const M = 1 - Ye(...n.weightBand, C), E = W([n.pivotX, n.pivotY]), O = -
|
|
440
|
-
te[0] = k[0] +
|
|
439
|
+
const M = 1 - Ye(...n.weightBand, C), E = W([n.pivotX, n.pivotY]), O = -e.tilt * (1 - X) * N.trunk.head * M, k = vt(te, E, O);
|
|
440
|
+
te[0] = k[0] + e.shift * 1.12 * (N.trunk.head - N.trunk.chest) * M, te[1] = k[1];
|
|
441
441
|
}
|
|
442
442
|
if (o) {
|
|
443
|
-
const M =
|
|
443
|
+
const M = t.chest.cy + Math.max(40, (e.pelvis[1] - t.chest.cy) * 0.5), E = Ye(t.chest.cy, M, C), O = N.twist.shoulder + (N.twist.pelvis - N.twist.shoulder) * E, k = t.chest.cx + (e.pelvis[0] - t.chest.cx) * E, $ = u + (i - u) * E, Z = n ? Ye(...n.weightBand, C) : 1;
|
|
444
444
|
te[0] += l(j, k, $, O) * Z;
|
|
445
445
|
}
|
|
446
|
-
let
|
|
446
|
+
let ae = 0, V = 0;
|
|
447
447
|
r.forEach((M, E) => {
|
|
448
|
-
const O = N.bones[E], k = B.perBone[E], $ =
|
|
449
|
-
|
|
450
|
-
}), F[0] +=
|
|
448
|
+
const O = N.bones[E], k = B.perBone[E], $ = hn(F, O.upper), Z = hn(F, O.lower), _ = $[0] + (Z[0] - $[0]) * k.shin, D = $[1] + (Z[1] - $[1]) * k.shin, q = E ? B.right : 1 - B.right;
|
|
449
|
+
ae += ((te[0] - F[0]) * (1 - k.leg) + (_ - F[0]) * k.leg) * k.pin * q, V += ((te[1] - F[1]) * (1 - k.leg) + (D - F[1]) * k.leg) * k.pin * q;
|
|
450
|
+
}), F[0] += ae, F[1] += V;
|
|
451
451
|
}
|
|
452
452
|
function T(F) {
|
|
453
453
|
return 1 - Ye(x - 55, x, F);
|
|
454
454
|
}
|
|
455
455
|
return { frame: z, weights: I, apply: U, pin: T, step: d };
|
|
456
456
|
}
|
|
457
|
-
const Ge = (
|
|
458
|
-
const r = Ge((n -
|
|
457
|
+
const Ge = (e, t, n) => Math.max(t, Math.min(n, e)), at = (e, t = 0) => Number.isFinite(e) ? e : t, it = (e, t, n) => {
|
|
458
|
+
const r = Ge((n - e) / Math.max(1e-6, t - e), 0, 1);
|
|
459
459
|
return r * r * (3 - 2 * r);
|
|
460
|
-
},
|
|
461
|
-
const r =
|
|
462
|
-
return [
|
|
460
|
+
}, Lt = (e, t, n) => {
|
|
461
|
+
const r = e[0] - t[0], o = e[1] - t[1], s = Math.cos(n), i = Math.sin(n);
|
|
462
|
+
return [t[0] + r * s - o * i, t[1] + r * i + o * s];
|
|
463
463
|
}, mt = Object.freeze({ swing: 4, bend: 6, inward: 0.4 });
|
|
464
|
-
function
|
|
465
|
-
if (!
|
|
466
|
-
const r = Ge(
|
|
464
|
+
function er(e, t, n = null) {
|
|
465
|
+
if (!e) return null;
|
|
466
|
+
const r = Ge(at(e.swing, mt.swing), 0, 10) * Math.PI / 180, o = Ge(at(e.bend, mt.bend), 0, 12) * Math.PI / 180, s = Ge(at(e.inward, mt.inward), 0, 1), i = [e.left, e.right];
|
|
467
467
|
function u(l, c) {
|
|
468
468
|
let f = 0;
|
|
469
469
|
for (; f < l.length - 2 && c > l[f + 1][1]; ) f++;
|
|
@@ -472,7 +472,7 @@ function Kn(t, e, n = null) {
|
|
|
472
472
|
}
|
|
473
473
|
function y(l, c) {
|
|
474
474
|
return i.map((f, h) => {
|
|
475
|
-
const p = Math.max(1, f.elbow[1] - f.shoulder[1]), g = Math.max(1, f.wrist[1] - f.elbow[1]), b = Math.max(1, Math.min(p, g,
|
|
475
|
+
const p = Math.max(1, f.elbow[1] - f.shoulder[1]), g = Math.max(1, f.wrist[1] - f.elbow[1]), b = Math.max(1, Math.min(p, g, t.chest.ry) * 0.2), a = u(f.split, c), d = h ? l - a : a - l, x = +(d >= 0), w = it(-b, b, d), A = it(f.split[0][1] - b, f.split[0][1], c);
|
|
476
476
|
return {
|
|
477
477
|
arm: (w + (x - w) * A) * it(f.shoulder[1], f.shoulder[1] + p * 0.55, c) * (1 - it(f.split.at(-1)[1], f.split.at(-1)[1] + b, c)),
|
|
478
478
|
forearm: it(f.elbow[1] - b, f.elbow[1] + b, c)
|
|
@@ -481,21 +481,21 @@ function Kn(t, e, n = null) {
|
|
|
481
481
|
}
|
|
482
482
|
function v(l, c = (f) => [...f]) {
|
|
483
483
|
return i.map((f, h) => {
|
|
484
|
-
const p = h ? "R" : "L", g = h ? -1 : 1, b = Ge(
|
|
484
|
+
const p = h ? "R" : "L", g = h ? -1 : 1, b = Ge(at(l[`armSwing${p}`]), -1, 1);
|
|
485
485
|
return {
|
|
486
486
|
shoulder: c(f.shoulder),
|
|
487
487
|
elbow: c(f.elbow),
|
|
488
|
-
swing: g * r * b * (b < 0 ?
|
|
488
|
+
swing: g * r * b * (b < 0 ? s : 1),
|
|
489
489
|
// Flex inward; negative values never hyper-extend the elbow.
|
|
490
|
-
bend: -g * o * Ge(
|
|
490
|
+
bend: -g * o * Ge(at(l[`elbowBend${p}`]), 0, 1)
|
|
491
491
|
};
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
494
|
function m(l, c, f, h, p, g = v(p)) {
|
|
495
495
|
const b = [...l];
|
|
496
|
-
g.forEach((
|
|
497
|
-
if (!h[d].arm || !
|
|
498
|
-
const x =
|
|
496
|
+
g.forEach((a, d) => {
|
|
497
|
+
if (!h[d].arm || !a.swing && !a.bend) return;
|
|
498
|
+
const x = a.swing ? Lt(b, a.shoulder, a.swing) : b, w = a.swing ? Lt(a.elbow, a.shoulder, a.swing) : a.elbow, A = a.bend ? Lt(x, w, a.bend) : x;
|
|
499
499
|
l[0] += (x[0] - b[0] + (A[0] - x[0]) * h[d].forearm) * h[d].arm, l[1] += (x[1] - b[1] + (A[1] - x[1]) * h[d].forearm) * h[d].arm;
|
|
500
500
|
});
|
|
501
501
|
}
|
|
@@ -522,20 +522,20 @@ const bt = [
|
|
|
522
522
|
{ id: "handAngle", label: "Wrist angle", min: -10, max: 10, def: 0, group: "Hand" },
|
|
523
523
|
{ id: "fingerTap", label: "Finger tap", min: 0, max: 1, def: 0, group: "Hand" },
|
|
524
524
|
{ id: "weightShift", label: "Weight shift", min: -1, max: 1, def: 0, group: "Legs" },
|
|
525
|
-
...["L", "R"].flatMap((
|
|
526
|
-
{ id: `armSwing${
|
|
527
|
-
{ id: `elbowBend${
|
|
525
|
+
...["L", "R"].flatMap((e) => [
|
|
526
|
+
{ id: `armSwing${e}`, label: `Arm swing ${e}`, min: -1, max: 1, def: 0, group: "Arms" },
|
|
527
|
+
{ id: `elbowBend${e}`, label: `Elbow bend ${e}`, min: 0, max: 1, def: 0, group: "Arms" }
|
|
528
528
|
])
|
|
529
529
|
];
|
|
530
|
-
function
|
|
531
|
-
const
|
|
532
|
-
function
|
|
530
|
+
function tr(e) {
|
|
531
|
+
const t = { w: e.image.width, h: e.image.height }, n = (M, E, O) => O ? Math.exp(-(((M - O.cx) / O.rx) ** 2 + ((E - O.cy) / O.ry) ** 2)) : 0, r = 24, o = e.eyes;
|
|
532
|
+
function s(M, E) {
|
|
533
533
|
const O = Math.min(1, Math.max(0, E)) * (r - 1), k = Math.min(Math.floor(O), r - 2), $ = O - k;
|
|
534
534
|
return M[k] + (M[k + 1] - M[k]) * $;
|
|
535
535
|
}
|
|
536
536
|
function i(M, E, O, k) {
|
|
537
537
|
E = Math.min(1, Math.max(0, E));
|
|
538
|
-
const $ =
|
|
538
|
+
const $ = s(M.top, E), Z = s(M.bot, E), _ = 1 - O, D = 4 * E * (1 - E), q = s(M.bot, 0.5) - s(M.top, 0.5), ee = M.top[0] + (M.top[r - 1] - M.top[0]) * E - 0.3 * q * D, oe = Math.max($, Z + 1 + (ee - Z - 1) * k);
|
|
539
539
|
return [(oe - $) * Math.max(_, -0.07), _ > 0 ? (oe - Z) * _ * k : 0];
|
|
540
540
|
}
|
|
541
541
|
const u = [[-2, 1], [-1, 2], [0, 3], [1, 2], [2, 1]], y = 5;
|
|
@@ -545,7 +545,7 @@ function Qn(t) {
|
|
|
545
545
|
const [S, R] = i(M, (E + ee * y - M.x0) / (M.x1 - M.x0), O, k);
|
|
546
546
|
$ += S * oe / 9, Z += R * oe / 9;
|
|
547
547
|
}
|
|
548
|
-
const _ = Math.min(1, Math.max(0, (E - M.x0) / (M.x1 - M.x0))), D =
|
|
548
|
+
const _ = Math.min(1, Math.max(0, (E - M.x0) / (M.x1 - M.x0))), D = s(M.top, _), q = s(M.bot, _);
|
|
549
549
|
return { top: D, bot: q, b: 1 - O, lid: D + $, bc: q + Z };
|
|
550
550
|
}
|
|
551
551
|
function m(M, E, O, k, $, Z) {
|
|
@@ -556,23 +556,23 @@ function Qn(t) {
|
|
|
556
556
|
const k = Math.min(1, Math.max(0, 1 - E));
|
|
557
557
|
return M === "low" ? 1 - Math.min(1, k * O * 1.2) : M === "crease" ? 1 - 0.45 * k : 1;
|
|
558
558
|
}
|
|
559
|
-
const c =
|
|
559
|
+
const c = e.mouth, f = e.cheeks, h = e.head, p = e.body, g = Qn(e.legs, p, h), b = er(e.arms, p, e.legs), a = (M, E, O) => {
|
|
560
560
|
const k = Math.min(1, Math.max(0, (O - M) / (E - M)));
|
|
561
561
|
return k * k * (3 - 2 * k);
|
|
562
562
|
};
|
|
563
563
|
function d(M, E) {
|
|
564
|
-
return 1 -
|
|
564
|
+
return 1 - a(...h.weightBand, E);
|
|
565
565
|
}
|
|
566
566
|
function x(M, E) {
|
|
567
|
-
return 1 -
|
|
567
|
+
return 1 - a(...h.turnBand, E);
|
|
568
568
|
}
|
|
569
|
-
const w =
|
|
569
|
+
const w = e.strands ?? [];
|
|
570
570
|
function A(M, E, O) {
|
|
571
571
|
let k = 1 / 0, $ = 0;
|
|
572
572
|
const Z = O.length - 1;
|
|
573
573
|
for (let _ = 0; _ < Z; _++) {
|
|
574
|
-
const [D, q] = O[_], [ee, oe] = O[_ + 1], S = ee - D, R = oe - q, P = Math.min(1, Math.max(0, ((M - D) * S + (E - q) * R) / (S * S + R * R))),
|
|
575
|
-
|
|
574
|
+
const [D, q] = O[_], [ee, oe] = O[_ + 1], S = ee - D, R = oe - q, P = Math.min(1, Math.max(0, ((M - D) * S + (E - q) * R) / (S * S + R * R))), se = Math.hypot(M - D - S * P, E - q - R * P);
|
|
575
|
+
se < k && (k = se, $ = (_ + P) / Z);
|
|
576
576
|
}
|
|
577
577
|
return [k, $];
|
|
578
578
|
}
|
|
@@ -585,27 +585,27 @@ function Qn(t) {
|
|
|
585
585
|
oe < 0.02 || (k.push([D, oe, ee]), $ += oe);
|
|
586
586
|
});
|
|
587
587
|
const Z = Math.max(1, $);
|
|
588
|
-
return k.map(([_, D, q]) => [_, O * D / Z *
|
|
588
|
+
return k.map(([_, D, q]) => [_, O * D / Z * a(0.04, 0.55, q), q]);
|
|
589
589
|
}
|
|
590
590
|
function z(M, E, O = 1) {
|
|
591
591
|
return {
|
|
592
592
|
head: d(M, E),
|
|
593
593
|
turn: x(M, E),
|
|
594
594
|
strands: L(M, E, O),
|
|
595
|
-
bunL: n(M, E,
|
|
596
|
-
bunR: n(M, E,
|
|
597
|
-
brow: n(M, E,
|
|
595
|
+
bunL: n(M, E, e.buns?.bunL),
|
|
596
|
+
bunR: n(M, E, e.buns?.bunR),
|
|
597
|
+
brow: n(M, E, e.face.brow) * (1 - a(...e.face.brow.band, E)),
|
|
598
598
|
// chin below the mouth line drops a little when the mouth opens
|
|
599
|
-
jaw: n(M, E,
|
|
599
|
+
jaw: n(M, E, e.face.jaw) * a(...e.face.jaw.band, E),
|
|
600
600
|
// per-feature depth for head turns (nose sticks out most, ears sit at the back)
|
|
601
|
-
nose: n(M, E,
|
|
602
|
-
mouth: n(M, E,
|
|
603
|
-
eyeA: n(M, E,
|
|
604
|
-
eyeB: n(M, E,
|
|
605
|
-
earR: n(M, E,
|
|
606
|
-
earL: n(M, E,
|
|
601
|
+
nose: n(M, E, e.face.nose),
|
|
602
|
+
mouth: n(M, E, e.face.mouth),
|
|
603
|
+
eyeA: n(M, E, e.face.eyeA),
|
|
604
|
+
eyeB: n(M, E, e.face.eyeB),
|
|
605
|
+
earR: n(M, E, e.face.earR),
|
|
606
|
+
earL: n(M, E, e.face.earL),
|
|
607
607
|
chest: n(M, E, p.chest),
|
|
608
|
-
breath: 1 -
|
|
608
|
+
breath: 1 - a(...p.breathBand, E),
|
|
609
609
|
shoulder: p.shoulders.reduce((k, $) => k + n(M, E, $), 0),
|
|
610
610
|
...g && { legs: g.weights(M, E) },
|
|
611
611
|
...b && { arms: b.weights(M, E) }
|
|
@@ -614,7 +614,7 @@ function Qn(t) {
|
|
|
614
614
|
function Y(M, E, O, k) {
|
|
615
615
|
const $ = (M - h.cx) / h.rx, Z = (E - h.cy) / h.ry, _ = 1 - $ * $ - Z * Z;
|
|
616
616
|
if (_ <= 0) return [0, 0];
|
|
617
|
-
const D =
|
|
617
|
+
const D = a(0, 0.84, _);
|
|
618
618
|
return [O * h.shiftX * D, -k * h.shiftY * D];
|
|
619
619
|
}
|
|
620
620
|
function I(M, E, O, k) {
|
|
@@ -630,7 +630,7 @@ function Qn(t) {
|
|
|
630
630
|
const D = M[0], q = M[1], ee = O.breath;
|
|
631
631
|
M[1] -= ee * (5 * $ + 4 * Z), M[0] += (M[0] - p.chest.cx) * 0.012 * ee * k;
|
|
632
632
|
const oe = p.hip;
|
|
633
|
-
if (g || (M[0] += O.bodyAngleX / 10 * (oe ? oe.shift * (1 -
|
|
633
|
+
if (g || (M[0] += O.bodyAngleX / 10 * (oe ? oe.shift * (1 - a(...oe.band, E)) : 7 + 9 * k)), I(M, p.pivotX, p.pivotY, -O.bodyAngleZ / 10 * p.maxRoll * (1 - a(...p.rollBand, E))), g) {
|
|
634
634
|
const S = g.pin(E);
|
|
635
635
|
M[0] = D + (M[0] - D) * S, M[1] = q + (M[1] - q) * S;
|
|
636
636
|
}
|
|
@@ -643,16 +643,16 @@ function Qn(t) {
|
|
|
643
643
|
for (const [oe, S, R] of O.strands) {
|
|
644
644
|
const P = $.strands?.[oe];
|
|
645
645
|
if (!P) continue;
|
|
646
|
-
const
|
|
646
|
+
const se = R * 3, ie = Math.min(2, Math.floor(se)), pe = se - ie;
|
|
647
647
|
_[0] += (P[ie][0] + (P[ie + 1][0] - P[ie][0]) * pe) * S * D, _[1] += (P[ie][1] + (P[ie + 1][1] - P[ie][1]) * pe) * S * D;
|
|
648
648
|
}
|
|
649
649
|
if (_[0] += ($.bunL[0] * O.bunL + $.bunR[0] * O.bunR) * D, _[1] += ($.bunL[1] * O.bunL + $.bunR[1] * O.bunR) * D, _[1] -= k.browY * 7 * O.brow, O.brow > 0.01) {
|
|
650
650
|
const oe = k.browAngle * 0.12 * O.brow;
|
|
651
|
-
_[1] += (M -
|
|
651
|
+
_[1] += (M - e.face.brow.cx) * Math.sin(oe);
|
|
652
652
|
}
|
|
653
653
|
_[1] += k.mouthOpen * 3.5 * O.jaw;
|
|
654
654
|
const q = k.angleX / 30, ee = k.angleY / 30;
|
|
655
|
-
if (_[0] += q * (8 * O.nose + 5 * O.mouth) + (M -
|
|
655
|
+
if (_[0] += q * (8 * O.nose + 5 * O.mouth) + (M - e.face.eyeA.cx) * 0.12 * q * O.eyeA - (M - e.face.eyeB.cx) * 0.12 * q * O.eyeB - q * 9 * O.earR + q * 4 * O.earL - q * 10 * (O.bunL + O.bunR), _[1] -= ee * (6 * O.nose + 3 * O.mouth), _[1] += (E - e.face.eyeA.cy) * -0.06 * Math.abs(ee) * O.eyeA + (E - e.face.eyeB.cy) * -0.06 * Math.abs(ee) * O.eyeB, U(_, O.head, k, O.turn), T(_, E, k, O.chest, O.breath, O.shoulder, O.legs), b && O.arms.some((oe) => oe.arm > 0)) {
|
|
656
656
|
const oe = [
|
|
657
657
|
k.angleX,
|
|
658
658
|
k.angleY,
|
|
@@ -673,14 +673,14 @@ function Qn(t) {
|
|
|
673
673
|
}
|
|
674
674
|
return _;
|
|
675
675
|
}
|
|
676
|
-
const B =
|
|
676
|
+
const B = e.hand, H = B?.elbow ?? [0, 0], N = B?.wrist ?? [0, 0], ne = B?.knuckle ?? [0, 0], Q = B?.contact ?? [0, 0], J = B?.forearmShare ?? 0;
|
|
677
677
|
function X(M, E) {
|
|
678
678
|
return B ? {
|
|
679
|
-
arm: 1 -
|
|
680
|
-
wrist: 1 -
|
|
681
|
-
hand: 1 -
|
|
682
|
-
finger:
|
|
683
|
-
pinBottom:
|
|
679
|
+
arm: 1 - a(...B.armBand, E),
|
|
680
|
+
wrist: 1 - a(...B.wristBand, E),
|
|
681
|
+
hand: 1 - a(...B.handBand, E),
|
|
682
|
+
finger: a(...B.fingerXBand, M) * (1 - a(...B.fingerYBand, E)),
|
|
683
|
+
pinBottom: a(...B.pinBand, E)
|
|
684
684
|
} : { arm: 0, wrist: 0, hand: 0, finger: 0, pinBottom: 0 };
|
|
685
685
|
}
|
|
686
686
|
const G = (M, E, O, k) => {
|
|
@@ -706,48 +706,48 @@ function Qn(t) {
|
|
|
706
706
|
const ee = $.b * O.hand, oe = 1 + ($.k - 1) * O.hand;
|
|
707
707
|
return _ = G(_, $.w, Math.cos(ee) * oe, Math.sin(ee) * oe), _[1] += (E - _[1]) * O.pinBottom, Z[0] = _[0], Z[1] = _[1], Z;
|
|
708
708
|
}
|
|
709
|
-
const
|
|
709
|
+
const ae = e.accessories ?? [];
|
|
710
710
|
function V(M, E, O, k) {
|
|
711
711
|
const $ = z(M.pivot[0], M.pivot[1]);
|
|
712
712
|
return C(M.pivot[0], M.pivot[1], $, E, O, k);
|
|
713
713
|
}
|
|
714
|
-
return { legs: g, stepBody: (M, E) => g?.step(M, E), IMG:
|
|
715
|
-
}
|
|
716
|
-
function
|
|
717
|
-
const o = r ? Math.max(
|
|
718
|
-
for (let u = 0; u < n; u++) for (let y = 0; y <
|
|
719
|
-
const v = u *
|
|
720
|
-
|
|
721
|
-
y ?
|
|
722
|
-
u ?
|
|
723
|
-
y && u ?
|
|
724
|
-
u && y + 1 <
|
|
714
|
+
return { legs: g, stepBody: (M, E) => g?.step(M, E), IMG: t, EYES: o, MOUTH: c, CHEEKS: f, STRANDS: w, TASSELS: ae, headWeight: d, turnWeight: x, baseWeights: z, deformBase: C, applyHead: U, applyBody: T, handWeights: X, handFrame: W, deformHand: te, eyePartY: m, eyePartAlpha: l, tasselAnchor: V };
|
|
715
|
+
}
|
|
716
|
+
function nr(e, t, n, r = !1) {
|
|
717
|
+
const o = r ? Math.max(t, n) * 2 : 1, s = new Float32Array(e.length), i = Math.SQRT2;
|
|
718
|
+
for (let u = 0; u < n; u++) for (let y = 0; y < t; y++) {
|
|
719
|
+
const v = u * t + y;
|
|
720
|
+
e[v] <= 3 || (s[v] = Math.min(
|
|
721
|
+
y ? s[v - 1] + 1 : o,
|
|
722
|
+
u ? s[v - t] + 1 : o,
|
|
723
|
+
y && u ? s[v - t - 1] + i : o,
|
|
724
|
+
u && y + 1 < t ? s[v - t + 1] + i : o
|
|
725
725
|
));
|
|
726
726
|
}
|
|
727
|
-
for (let u = n - 1; u >= 0; u--) for (let y =
|
|
728
|
-
const v = u *
|
|
729
|
-
!
|
|
730
|
-
|
|
731
|
-
y + 1 <
|
|
732
|
-
u + 1 < n ?
|
|
733
|
-
y && u + 1 < n ?
|
|
734
|
-
y + 1 <
|
|
727
|
+
for (let u = n - 1; u >= 0; u--) for (let y = t - 1; y >= 0; y--) {
|
|
728
|
+
const v = u * t + y;
|
|
729
|
+
!e[v] || e[v] <= 3 || (s[v] = Math.min(
|
|
730
|
+
s[v],
|
|
731
|
+
y + 1 < t ? s[v + 1] + 1 : o,
|
|
732
|
+
u + 1 < n ? s[v + t] + 1 : o,
|
|
733
|
+
y && u + 1 < n ? s[v + t - 1] + i : o,
|
|
734
|
+
y + 1 < t && u + 1 < n ? s[v + t + 1] + i : o
|
|
735
735
|
));
|
|
736
736
|
}
|
|
737
|
-
return
|
|
737
|
+
return s;
|
|
738
738
|
}
|
|
739
|
-
function
|
|
740
|
-
return Math.exp(-(((
|
|
739
|
+
function _t(e, t, n) {
|
|
740
|
+
return Math.exp(-(((e - n.cx) / n.rx) ** 2 + ((t - n.cy) / n.ry) ** 2));
|
|
741
741
|
}
|
|
742
|
-
function
|
|
743
|
-
const r = ((
|
|
744
|
-
let o = n.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + n.body.chest.rx * 0.23 *
|
|
745
|
-
o += n.face.nose.rx * 0.2 *
|
|
746
|
-
for (const [
|
|
742
|
+
function rr(e, t, n) {
|
|
743
|
+
const r = ((e - n.head.cx) / n.head.rx) ** 2 + ((t - n.head.cy) / n.head.ry) ** 2;
|
|
744
|
+
let o = n.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + n.body.chest.rx * 0.23 * _t(e, t, n.body.chest);
|
|
745
|
+
o += n.face.nose.rx * 0.2 * _t(e, t, n.face.nose);
|
|
746
|
+
for (const [s, i] of n.cheeks) o += n.head.rx * 0.012 * _t(e, t, { cx: s, cy: i, rx: n.head.rx * 0.3, ry: n.head.ry * 0.16 });
|
|
747
747
|
return o;
|
|
748
748
|
}
|
|
749
|
-
function Et(
|
|
750
|
-
const o = new Float32Array(
|
|
749
|
+
function Et(e, t, n, r) {
|
|
750
|
+
const o = new Float32Array(e.length), s = new Float32Array(e.length), i = (u, y, v, m, l, c) => {
|
|
751
751
|
for (let f = 0; f < m; f++) {
|
|
752
752
|
const h = f * c;
|
|
753
753
|
let p = 0, g = 0;
|
|
@@ -755,51 +755,51 @@ function Et(t, e, n, r) {
|
|
|
755
755
|
p += u[h + b * l], g++;
|
|
756
756
|
for (let b = 0; b < v; b++) {
|
|
757
757
|
y[h + b * l] = p / g;
|
|
758
|
-
const
|
|
759
|
-
|
|
758
|
+
const a = b + r + 1, d = b - r;
|
|
759
|
+
a < v && (p += u[h + a * l], g++), d >= 0 && (p -= u[h + d * l], g--);
|
|
760
760
|
}
|
|
761
761
|
}
|
|
762
762
|
};
|
|
763
|
-
return i(
|
|
763
|
+
return i(e, o, t, n, 1, t), i(o, s, n, t, t, 1), s;
|
|
764
764
|
}
|
|
765
|
-
function
|
|
766
|
-
const o = Et(
|
|
767
|
-
for (let v = 0; v < i.length; v++) i[v] =
|
|
768
|
-
const u = new Float32Array(
|
|
765
|
+
function or(e, t, n, r) {
|
|
766
|
+
const o = Et(e, n, r, 1), s = Et(e, n, r, 6), i = new Float32Array(e.length);
|
|
767
|
+
for (let v = 0; v < i.length; v++) i[v] = t[v] > 128 ? o[v] - s[v] : 0;
|
|
768
|
+
const u = new Float32Array(e.length * 2), y = (v, m) => i[Math.max(0, Math.min(r - 1, m)) * n + Math.max(0, Math.min(n - 1, v))];
|
|
769
769
|
for (let v = 0; v < r; v++) for (let m = 0; m < n; m++) {
|
|
770
770
|
const l = v * n + m;
|
|
771
|
-
|
|
771
|
+
t[l] <= 128 || (u[2 * l] = Math.max(-1, Math.min(1, -(y(m + 1, v) - y(m - 1, v)) * 4)), u[2 * l + 1] = Math.max(-1, Math.min(1, -(y(m, v + 1) - y(m, v - 1)) * 4)));
|
|
772
772
|
}
|
|
773
773
|
return u;
|
|
774
774
|
}
|
|
775
|
-
function
|
|
776
|
-
const u = !!o && r[0] === 0 && r[1] === 0 && r[2] === o.image.width && r[3] === o.image.height, y =
|
|
777
|
-
for (let
|
|
778
|
-
const x =
|
|
779
|
-
v[x] = (
|
|
780
|
-
}
|
|
781
|
-
const h = Math.max(1, Math.round(Math.min(
|
|
782
|
-
v.set(Et(Et(v,
|
|
783
|
-
const p = i ?
|
|
784
|
-
for (let
|
|
785
|
-
const x = -(b(d + 2,
|
|
775
|
+
function sr(e, t, n, r, o, s = !0, i) {
|
|
776
|
+
const u = !!o && r[0] === 0 && r[1] === 0 && r[2] === o.image.width && r[3] === o.image.height, y = nr(e, t, n, u), v = new Float32Array(e.length), m = r[2] / t, l = r[3] / n, c = Math.min(m, l), f = Math.min(r[2], r[3]) * 0.08;
|
|
777
|
+
for (let a = 0; a < n; a++) for (let d = 0; d < t; d++) {
|
|
778
|
+
const x = a * t + d;
|
|
779
|
+
v[x] = (s ? Math.sqrt(y[x] * c * f) * 0.55 : 0) + (o ? rr(r[0] + (d + 0.5) * m, r[1] + (a + 0.5) * l, o) : 0);
|
|
780
|
+
}
|
|
781
|
+
const h = Math.max(1, Math.round(Math.min(t, n) * 0.02));
|
|
782
|
+
v.set(Et(Et(v, t, n, h), t, n, h));
|
|
783
|
+
const p = i ? or(i, e, t, n) : null, g = new Uint8Array(t * n * 4), b = (a, d) => v[Math.max(0, Math.min(n - 1, d)) * t + Math.max(0, Math.min(t - 1, a))];
|
|
784
|
+
for (let a = 0; a < n; a++) for (let d = 0; d < t; d++) {
|
|
785
|
+
const x = -(b(d + 2, a) - b(d - 2, a)) / (4 * m), w = -(b(d, a + 2) - b(d, a - 2)) / (4 * l), A = Math.hypot(x, w, 1), L = (a * t + d) * 4, z = a * t + d;
|
|
786
786
|
g[L] = Math.round((x / A * 0.5 + 0.5) * 255), g[L + 1] = Math.round((w / A * 0.5 + 0.5) * 255), g[L + 2] = Math.round(((p?.[2 * z] ?? 0) * 0.5 + 0.5) * 255), g[L + 3] = Math.round(((p?.[2 * z + 1] ?? 0) * 0.5 + 0.5) * 255);
|
|
787
787
|
}
|
|
788
788
|
return g;
|
|
789
789
|
}
|
|
790
|
-
const
|
|
791
|
-
function
|
|
792
|
-
const o = JSON.stringify([
|
|
793
|
-
if (
|
|
794
|
-
const i = performance.now(), u = Math.min(1, 512 / Math.max(
|
|
790
|
+
const un = /* @__PURE__ */ new WeakMap();
|
|
791
|
+
function ar(e, t, n, r) {
|
|
792
|
+
const o = JSON.stringify([t, n.head, n.body.chest, n.face.nose, n.cheeks, r]), s = un.get(e);
|
|
793
|
+
if (s?.key === o) return { ...s, computed: !1, ms: 0 };
|
|
794
|
+
const i = performance.now(), u = Math.min(1, 512 / Math.max(e.width, e.height)), y = Math.max(1, Math.round(e.width * u)), v = Math.max(1, Math.round(e.height * u)), m = document.createElement("canvas");
|
|
795
795
|
m.width = y, m.height = v;
|
|
796
796
|
const l = m.getContext("2d", { willReadFrequently: !0 });
|
|
797
|
-
l.drawImage(
|
|
797
|
+
l.drawImage(e, 0, 0, y, v);
|
|
798
798
|
const c = l.getImageData(0, 0, y, v).data, f = new Uint8Array(y * v), h = new Float32Array(y * v);
|
|
799
799
|
for (let g = 0; g < f.length; g++)
|
|
800
800
|
f[g] = c[4 * g + 3], h[g] = (0.2126 * c[4 * g] + 0.7152 * c[4 * g + 1] + 0.0722 * c[4 * g + 2]) / 255;
|
|
801
|
-
const p = { key: o, data:
|
|
802
|
-
return
|
|
801
|
+
const p = { key: o, data: sr(f, y, v, t, n, r, r ? h : void 0), width: y, height: v };
|
|
802
|
+
return un.set(e, p), { ...p, computed: !0, ms: performance.now() - i };
|
|
803
803
|
}
|
|
804
804
|
const et = Object.freeze({
|
|
805
805
|
enabled: !1,
|
|
@@ -818,7 +818,7 @@ const et = Object.freeze({
|
|
|
818
818
|
specular: 0.12,
|
|
819
819
|
rim: 0.3,
|
|
820
820
|
detail: 0.4
|
|
821
|
-
}),
|
|
821
|
+
}), fn = {
|
|
822
822
|
x: [0, 1],
|
|
823
823
|
y: [0, 1],
|
|
824
824
|
z: [0.1, 2],
|
|
@@ -832,28 +832,28 @@ const et = Object.freeze({
|
|
|
832
832
|
specular: [0, 1],
|
|
833
833
|
rim: [0, 1],
|
|
834
834
|
detail: [0, 1]
|
|
835
|
-
},
|
|
836
|
-
function
|
|
837
|
-
if (!
|
|
838
|
-
const
|
|
839
|
-
if (Object.keys(
|
|
840
|
-
const n = { ...et, enabled:
|
|
841
|
-
for (const r of Object.keys(
|
|
842
|
-
const o =
|
|
843
|
-
if (typeof o != "number" || !Number.isFinite(o) ||
|
|
844
|
-
n[r] = Math.max(
|
|
835
|
+
}, ir = /* @__PURE__ */ new Set(["color", "ambientColor"]);
|
|
836
|
+
function lr(e) {
|
|
837
|
+
if (!e || typeof e != "object" || Array.isArray(e)) return null;
|
|
838
|
+
const t = e;
|
|
839
|
+
if (Object.keys(t).length !== Object.keys(et).length || Object.keys(t).some((r) => !(r in et)) || ![!0, !1].includes(t.enabled) || ![!0, !1].includes(t.shadow) || !["soft", "cel"].includes(t.mode)) return null;
|
|
840
|
+
const n = { ...et, enabled: t.enabled, shadow: t.shadow, mode: t.mode };
|
|
841
|
+
for (const r of Object.keys(fn)) {
|
|
842
|
+
const o = t[r], [s, i] = fn[r];
|
|
843
|
+
if (typeof o != "number" || !Number.isFinite(o) || ir.has(r) && !Number.isInteger(o)) return null;
|
|
844
|
+
n[r] = Math.max(s, Math.min(i, o));
|
|
845
845
|
}
|
|
846
846
|
return n;
|
|
847
847
|
}
|
|
848
|
-
function
|
|
849
|
-
return `#${
|
|
848
|
+
function Eo(e) {
|
|
849
|
+
return `#${e.toString(16).padStart(6, "0")}`;
|
|
850
850
|
}
|
|
851
|
-
const wt = -0.1,
|
|
852
|
-
function
|
|
853
|
-
return [(0.5 -
|
|
851
|
+
const wt = -0.1, cr = 0.9, hr = 1, ur = 1.06;
|
|
852
|
+
function fr(e, t) {
|
|
853
|
+
return [(0.5 - e) * 0.12, (0.5 - t) * 0.12];
|
|
854
854
|
}
|
|
855
|
-
function
|
|
856
|
-
const o =
|
|
855
|
+
function mr(e, t, n, r) {
|
|
856
|
+
const o = e * Math.PI / 180, s = t * Math.PI / 180, i = -n / 30 * r, u = Math.cos(o), y = Math.sin(o), v = Math.cos(s), m = Math.sin(s), l = Math.cos(i), c = Math.sin(i);
|
|
857
857
|
return [
|
|
858
858
|
l * u,
|
|
859
859
|
c * u,
|
|
@@ -866,9 +866,9 @@ function ur(t, e, n, r) {
|
|
|
866
866
|
u * v
|
|
867
867
|
];
|
|
868
868
|
}
|
|
869
|
-
class
|
|
870
|
-
constructor(
|
|
871
|
-
this.gl =
|
|
869
|
+
class pr {
|
|
870
|
+
constructor(t, n) {
|
|
871
|
+
this.gl = t, this.program = n(t, `#version 300 es
|
|
872
872
|
out vec2 vUv;
|
|
873
873
|
void main() { vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)); vUv = p; gl_Position = vec4(p * 2.0 - 1.0, 0, 1); }`, `#version 300 es
|
|
874
874
|
precision highp float; in vec2 vUv; out vec4 o;
|
|
@@ -881,34 +881,34 @@ class fr {
|
|
|
881
881
|
a += (alphaAt(p + uStep * 1.384615) + alphaAt(p - uStep * 1.384615)) * 0.316216;
|
|
882
882
|
a += (alphaAt(p + uStep * 3.230769) + alphaAt(p - uStep * 3.230769)) * 0.070270;
|
|
883
883
|
o = uPass == 0 ? vec4(0, 0, 0, a) : vec4(vec3(0.035, 0.045, 0.065) * a * 0.28, a * 0.28);
|
|
884
|
-
}`), this.vao =
|
|
884
|
+
}`), this.vao = t.createVertexArray(), this.targets = [];
|
|
885
885
|
}
|
|
886
|
-
target(
|
|
887
|
-
const r = this.gl, o = r.createTexture(),
|
|
888
|
-
if (r.bindTexture(r.TEXTURE_2D, o), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA,
|
|
889
|
-
return { texture: o, framebuffer:
|
|
886
|
+
target(t, n) {
|
|
887
|
+
const r = this.gl, o = r.createTexture(), s = r.createFramebuffer();
|
|
888
|
+
if (r.bindTexture(r.TEXTURE_2D, o), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, t, n, 0, r.RGBA, r.UNSIGNED_BYTE, null), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.bindFramebuffer(r.FRAMEBUFFER, s), r.framebufferTexture2D(r.FRAMEBUFFER, r.COLOR_ATTACHMENT0, r.TEXTURE_2D, o, 0), r.checkFramebufferStatus(r.FRAMEBUFFER) !== r.FRAMEBUFFER_COMPLETE) throw new Error("Shadow framebuffer unavailable");
|
|
889
|
+
return { texture: o, framebuffer: s };
|
|
890
890
|
}
|
|
891
|
-
begin(
|
|
891
|
+
begin(t, n) {
|
|
892
892
|
const r = this.gl;
|
|
893
|
-
(this.width !==
|
|
893
|
+
(this.width !== t || this.height !== n) && (this.clearTargets(), this.width = t, this.height = n, this.targets = [this.target(t, n), this.target(Math.ceil(t / 2), Math.ceil(n / 2))]), r.bindFramebuffer(r.FRAMEBUFFER, this.targets[0].framebuffer), r.viewport(0, 0, t, n), r.clearColor(0, 0, 0, 0), r.clear(r.COLOR_BUFFER_BIT);
|
|
894
894
|
}
|
|
895
|
-
composite(
|
|
896
|
-
const n = this.gl, { prog: r, u: o } = this.program,
|
|
897
|
-
n.useProgram(r), n.bindVertexArray(this.vao), n.activeTexture(n.TEXTURE0), n.uniform1i(o.uTex, 0), n.disable(n.BLEND), n.bindFramebuffer(n.FRAMEBUFFER, this.targets[1].framebuffer), n.viewport(0, 0, Math.ceil(
|
|
898
|
-
const u =
|
|
895
|
+
composite(t) {
|
|
896
|
+
const n = this.gl, { prog: r, u: o } = this.program, s = this.width, i = this.height;
|
|
897
|
+
n.useProgram(r), n.bindVertexArray(this.vao), n.activeTexture(n.TEXTURE0), n.uniform1i(o.uTex, 0), n.disable(n.BLEND), n.bindFramebuffer(n.FRAMEBUFFER, this.targets[1].framebuffer), n.viewport(0, 0, Math.ceil(s / 2), Math.ceil(i / 2)), n.bindTexture(n.TEXTURE_2D, this.targets[0].texture), n.uniform1i(o.uPass, 0), n.uniform2f(o.uShift, 0, 0), n.uniform2f(o.uStep, 3 / s, 0), n.drawArrays(n.TRIANGLES, 0, 3), n.bindFramebuffer(n.FRAMEBUFFER, null), n.viewport(0, 0, s, i), n.clearColor(0, 0, 0, 0), n.clear(n.COLOR_BUFFER_BIT), n.enable(n.BLEND), n.bindTexture(n.TEXTURE_2D, this.targets[1].texture);
|
|
898
|
+
const u = fr(t.x, t.y);
|
|
899
899
|
n.uniform1i(o.uPass, 1), n.uniform2f(o.uShift, u[0], -u[1]), n.uniform2f(o.uStep, 0, 3 / i), n.drawArrays(n.TRIANGLES, 0, 3), n.bindTexture(n.TEXTURE_2D, this.targets[0].texture), n.uniform1i(o.uPass, 2), n.drawArrays(n.TRIANGLES, 0, 3), n.bindVertexArray(null);
|
|
900
900
|
}
|
|
901
901
|
clearTargets() {
|
|
902
|
-
for (const
|
|
903
|
-
this.gl.deleteTexture(
|
|
902
|
+
for (const t of this.targets)
|
|
903
|
+
this.gl.deleteTexture(t.texture), this.gl.deleteFramebuffer(t.framebuffer);
|
|
904
904
|
this.targets = [];
|
|
905
905
|
}
|
|
906
906
|
destroy() {
|
|
907
907
|
this.clearTargets(), this.gl.deleteProgram(this.program.prog), this.gl.deleteVertexArray(this.vao);
|
|
908
908
|
}
|
|
909
909
|
}
|
|
910
|
-
function
|
|
911
|
-
const { IMG: n, EYES: r, MOUTH: o, CHEEKS:
|
|
910
|
+
function dr(e, t) {
|
|
911
|
+
const { IMG: n, EYES: r, MOUTH: o, CHEEKS: s } = e, i = `#version 300 es
|
|
912
912
|
in vec2 aPos; in vec2 aUv;
|
|
913
913
|
uniform vec2 uScale; uniform vec2 uOffset;
|
|
914
914
|
out vec2 vUv;
|
|
@@ -1028,7 +1028,7 @@ function mr(t, e) {
|
|
|
1028
1028
|
vec4 encoded = texture(uNormal, vUv);
|
|
1029
1029
|
vec2 base = encoded.rg * 2.0 - 1.0;
|
|
1030
1030
|
vec3 n = vec3(base, sqrt(max(0.0, 1.0 - dot(base, base))));
|
|
1031
|
-
n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${
|
|
1031
|
+
n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${cr.toFixed(3)}, 0.0));
|
|
1032
1032
|
n = normalize(mix(n, uHeadRotation * n, vHeadWeight));
|
|
1033
1033
|
vec2 toLight = (uLight.xy - vScreen) * vec2(uAspect, 1.0);
|
|
1034
1034
|
vec3 light = normalize(vec3(toLight, uLight.z));
|
|
@@ -1045,12 +1045,12 @@ function mr(t, e) {
|
|
|
1045
1045
|
float attenuation = 1.0 / (1.0 + reach);
|
|
1046
1046
|
vec3 radiance = uLightColor * uLighting.y * attenuation;
|
|
1047
1047
|
// A light close to the surface may brighten a little, but must not bleach painted colours.
|
|
1048
|
-
vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${
|
|
1048
|
+
vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${ur.toFixed(3)}));
|
|
1049
1049
|
// Painted shadows are deeper versions of the base colour, not grey: multiply by the colour
|
|
1050
1050
|
// itself as the surface turns away from the light.
|
|
1051
1051
|
vec3 albedo = c.rgb / max(c.a, 1e-4);
|
|
1052
1052
|
float dark = 1.0 - clamp(dot(irradiance, vec3(0.3333)), 0.0, 1.0);
|
|
1053
|
-
vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${
|
|
1053
|
+
vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${hr.toFixed(3)}) * irradiance;
|
|
1054
1054
|
float specular = pow(max(dot(n, normalize(light + vec3(0.0, 0.0, 1.0))), 0.0), 60.0) * uSurface.y;
|
|
1055
1055
|
if (uCel == 1) specular = smoothstep(0.3, 0.35, specular) * uSurface.y;
|
|
1056
1056
|
vec2 side = length(n.xy) > 0.001 ? normalize(n.xy) : vec2(0.0);
|
|
@@ -1062,9 +1062,9 @@ function mr(t, e) {
|
|
|
1062
1062
|
in vec2 aPos; uniform vec2 uScale; uniform vec2 uOffset;
|
|
1063
1063
|
void main() { gl_Position = vec4(aPos * uScale + uOffset, 0.0, 1.0); gl_PointSize = 7.0; }`, l = `#version 300 es
|
|
1064
1064
|
precision mediump float; uniform vec4 uColor; out vec4 o; void main() { o = uColor; }`;
|
|
1065
|
-
function c(g, b,
|
|
1065
|
+
function c(g, b, a) {
|
|
1066
1066
|
const d = g.createProgram();
|
|
1067
|
-
for (const [A, L] of [[g.VERTEX_SHADER, b], [g.FRAGMENT_SHADER,
|
|
1067
|
+
for (const [A, L] of [[g.VERTEX_SHADER, b], [g.FRAGMENT_SHADER, a]]) {
|
|
1068
1068
|
const z = g.createShader(A);
|
|
1069
1069
|
if (g.shaderSource(z, L), g.compileShader(z), !g.getShaderParameter(z, g.COMPILE_STATUS)) throw new Error(g.getShaderInfoLog(z));
|
|
1070
1070
|
g.attachShader(d, z), g.deleteShader(z);
|
|
@@ -1077,51 +1077,51 @@ function mr(t, e) {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
return { prog: d, u: x };
|
|
1079
1079
|
}
|
|
1080
|
-
function f(g, b,
|
|
1080
|
+
function f(g, b, a, d) {
|
|
1081
1081
|
const x = [g];
|
|
1082
1082
|
let w = g;
|
|
1083
1083
|
for (; w < g + b - 0.5; ) {
|
|
1084
|
-
const A = d && w >= d.from && w < d.to ? d.cell :
|
|
1084
|
+
const A = d && w >= d.from && w < d.to ? d.cell : a;
|
|
1085
1085
|
w = Math.min(g + b, w + A), x.push(w);
|
|
1086
1086
|
}
|
|
1087
1087
|
return x;
|
|
1088
1088
|
}
|
|
1089
|
-
function h(g, b,
|
|
1089
|
+
function h(g, b, a, d, x = null) {
|
|
1090
1090
|
const [w, A, L, z] = g, Y = f(w, L, b, x && { from: x.x0, to: x.x1, cell: x.cell }), I = f(A, z, b, x && { from: x.y0, to: x.y1, cell: x.cell }), U = Y.length - 1, T = I.length - 1, F = (U + 1) * (T + 1), j = new Float32Array(F * 2), C = new Float32Array(F * 2);
|
|
1091
1091
|
for (let Q = 0; Q <= T; Q++) for (let J = 0; J <= U; J++) {
|
|
1092
1092
|
const X = Q * (U + 1) + J;
|
|
1093
1093
|
j[X * 2] = Y[J], j[X * 2 + 1] = I[Q], C[X * 2] = (Y[J] - w) / L, C[X * 2 + 1] = (I[Q] - A) / z;
|
|
1094
1094
|
}
|
|
1095
|
-
const B = [], H = [], N =
|
|
1095
|
+
const B = [], H = [], N = a.length / d, ne = d === 1 ? 0 : 1;
|
|
1096
1096
|
for (let Q = 0; Q < T; Q++) for (let J = 0; J < U; J++) {
|
|
1097
1097
|
const X = Math.floor(Y[J] - w) * ne - 2, G = Math.ceil(Y[J + 1] - w) * ne + 2, re = Math.floor(I[Q] - A) * ne - 2, W = Math.ceil(I[Q + 1] - A) * ne + 2;
|
|
1098
1098
|
let te = !1;
|
|
1099
1099
|
for (let O = Math.max(0, re); O < Math.min(N, W) && !te; O += 1)
|
|
1100
1100
|
for (let k = Math.max(0, X); k < Math.min(d, G); k += 1)
|
|
1101
|
-
if (
|
|
1101
|
+
if (a[O * d + k] > 3) {
|
|
1102
1102
|
te = !0;
|
|
1103
1103
|
break;
|
|
1104
1104
|
}
|
|
1105
1105
|
if (!te) continue;
|
|
1106
|
-
const
|
|
1107
|
-
B.push(
|
|
1106
|
+
const ae = Q * (U + 1) + J, V = ae + 1, M = ae + U + 1, E = M + 1;
|
|
1107
|
+
B.push(ae, V, M, V, E, M), H.push(ae, V, ae, M, V, M), J === U - 1 && H.push(V, E), Q === T - 1 && H.push(M, E);
|
|
1108
1108
|
}
|
|
1109
1109
|
return { rect: g, cols: U, rows: T, rest: j, uv: C, pos: new Float32Array(j), tris: new Uint32Array(B), lines: new Uint32Array(H) };
|
|
1110
1110
|
}
|
|
1111
1111
|
class p {
|
|
1112
1112
|
// padTop / padSide: margin around the image, as a share of its height / width. A negative
|
|
1113
1113
|
// padTop pushes the top of the image above the canvas (hides a cut-off top edge).
|
|
1114
|
-
constructor(b, { padTop:
|
|
1115
|
-
this.pad = { top:
|
|
1114
|
+
constructor(b, { padTop: a = 0, padSide: d = 0, fit: x = "contain" } = {}) {
|
|
1115
|
+
this.pad = { top: a, side: d }, this.fit = x;
|
|
1116
1116
|
const w = b.getContext("webgl2", { premultipliedAlpha: !0, antialias: !0, alpha: !0, preserveDrawingBuffer: !0 });
|
|
1117
1117
|
if (!w) throw new Error("WebGL2 is not available");
|
|
1118
1118
|
this.gl = w, this.canvas = b, this.main = c(w, i, u), this.line = c(w, m, l), this.layers = [], this.lighting = et, this.lightingStats = { normalMs: 0, computedLayers: 0, cachedLayers: 0 }, w.enable(w.BLEND), w.blendFunc(w.ONE, w.ONE_MINUS_SRC_ALPHA);
|
|
1119
1119
|
}
|
|
1120
1120
|
texture(b) {
|
|
1121
|
-
const
|
|
1122
|
-
return
|
|
1121
|
+
const a = this.gl, d = a.createTexture();
|
|
1122
|
+
return a.bindTexture(a.TEXTURE_2D, d), a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), a.texImage2D(a.TEXTURE_2D, 0, a.RGBA, a.RGBA, a.UNSIGNED_BYTE, b), a.generateMipmap(a.TEXTURE_2D), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.LINEAR_MIPMAP_LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE), d;
|
|
1123
1123
|
}
|
|
1124
|
-
addLayer(b,
|
|
1124
|
+
addLayer(b, a, d, x = {}) {
|
|
1125
1125
|
const w = this.gl, A = w.createVertexArray();
|
|
1126
1126
|
w.bindVertexArray(A);
|
|
1127
1127
|
const L = w.createBuffer();
|
|
@@ -1138,96 +1138,96 @@ function mr(t, e) {
|
|
|
1138
1138
|
w.bindBuffer(w.ELEMENT_ARRAY_BUFFER, I), w.bufferData(w.ELEMENT_ARRAY_BUFFER, d.tris, w.STATIC_DRAW), w.bindVertexArray(null);
|
|
1139
1139
|
const U = w.createBuffer();
|
|
1140
1140
|
w.bindBuffer(w.ELEMENT_ARRAY_BUFFER, U), w.bufferData(w.ELEMENT_ARRAY_BUFFER, d.lines, w.STATIC_DRAW);
|
|
1141
|
-
const T = { name: b, image:
|
|
1141
|
+
const T = { name: b, image: a, mesh: d, tex: this.texture(a), vao: A, posBuf: L, uvBuf: z, triBuf: I, lineBuf: U, visible: !0, face: !!x.face, eyeBall: x.eyeBall, color: x.color || [1, 1, 1, 1] };
|
|
1142
1142
|
return this.layers.push(T), T;
|
|
1143
1143
|
}
|
|
1144
1144
|
destroy() {
|
|
1145
1145
|
const b = this.gl;
|
|
1146
|
-
for (const
|
|
1147
|
-
b.deleteTexture(
|
|
1148
|
-
for (const d of [
|
|
1146
|
+
for (const a of this.layers) {
|
|
1147
|
+
b.deleteTexture(a.tex), a.normal && b.deleteTexture(a.normal), a.headBuf && b.deleteBuffer(a.headBuf), b.deleteVertexArray(a.vao);
|
|
1148
|
+
for (const d of [a.posBuf, a.uvBuf, a.triBuf, a.lineBuf]) b.deleteBuffer(d);
|
|
1149
1149
|
}
|
|
1150
1150
|
b.deleteProgram(this.main.prog), b.deleteProgram(this.line.prog), this.lit && b.deleteProgram(this.lit.prog), this.shadow?.destroy(), this.layers.length = 0;
|
|
1151
1151
|
}
|
|
1152
1152
|
setLighting(b) {
|
|
1153
|
-
if (this.lighting =
|
|
1154
|
-
const
|
|
1155
|
-
this.lit || (this.lit = c(
|
|
1153
|
+
if (this.lighting = lr({ ...et, ...b }) ?? et, !this.lighting.enabled) return;
|
|
1154
|
+
const a = this.gl;
|
|
1155
|
+
this.lit || (this.lit = c(a, y, v));
|
|
1156
1156
|
for (const d of this.layers) {
|
|
1157
1157
|
if (d.normal || d.overlay) continue;
|
|
1158
|
-
const x =
|
|
1159
|
-
this.lightingStats.normalMs += x.ms, this.lightingStats[x.computed ? "computedLayers" : "cachedLayers"]++, d.normal =
|
|
1158
|
+
const x = ar(d.image, d.mesh.rect, t, !/^(eye|mouth)/.test(d.name));
|
|
1159
|
+
this.lightingStats.normalMs += x.ms, this.lightingStats[x.computed ? "computedLayers" : "cachedLayers"]++, d.normal = a.createTexture(), a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, d.normal), a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), a.texImage2D(a.TEXTURE_2D, 0, a.RGBA, x.width, x.height, 0, a.RGBA, a.UNSIGNED_BYTE, x.data), a.generateMipmap(a.TEXTURE_2D), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.LINEAR_MIPMAP_LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE);
|
|
1160
1160
|
const w = new Float32Array(d.mesh.rest.length / 2);
|
|
1161
|
-
for (let A = 0; A < w.length; A++) w[A] =
|
|
1162
|
-
d.headBuf =
|
|
1161
|
+
for (let A = 0; A < w.length; A++) w[A] = e.headWeight(d.mesh.rest[A * 2], d.mesh.rest[A * 2 + 1]);
|
|
1162
|
+
d.headBuf = a.createBuffer(), a.bindVertexArray(d.vao), a.bindBuffer(a.ARRAY_BUFFER, d.headBuf), a.bufferData(a.ARRAY_BUFFER, w, a.STATIC_DRAW), a.enableVertexAttribArray(2), a.vertexAttribPointer(2, 1, a.FLOAT, !1, 0, 0);
|
|
1163
1163
|
}
|
|
1164
|
-
|
|
1164
|
+
a.bindVertexArray(null), this.lighting.shadow && !this.shadow && (this.shadow = new pr(a, c));
|
|
1165
1165
|
}
|
|
1166
1166
|
resize() {
|
|
1167
|
-
const b = this.canvas,
|
|
1167
|
+
const b = this.canvas, a = Math.min(window.devicePixelRatio || 1, 2), d = Math.round(b.clientWidth * a), x = Math.round(b.clientHeight * a);
|
|
1168
1168
|
(b.width !== d || b.height !== x) && (b.width = d, b.height = x);
|
|
1169
1169
|
const w = (this.fit === "cover" ? Math.max : Math.min)(d / (n.w * (1 + 2 * this.pad.side)), x / (n.h * (1 + this.pad.top))), A = (d - n.w * w) / 2, L = (x - n.h * w) / (this.fit === "cover" ? 2 : 1);
|
|
1170
1170
|
this.scale = [2 * w / d, -2 * w / x], this.offset = [-1 + 2 * A / d, 1 - 2 * L / x], this.pxScale = w, this.pxOff = [A, L];
|
|
1171
1171
|
}
|
|
1172
1172
|
draw(b) {
|
|
1173
|
-
const
|
|
1174
|
-
this.resize(),
|
|
1173
|
+
const a = this.gl;
|
|
1174
|
+
this.resize(), a.viewport(0, 0, this.canvas.width, this.canvas.height), a.clearColor(0, 0, 0, 0), a.clear(a.COLOR_BUFFER_BIT);
|
|
1175
1175
|
const d = this.lighting.enabled, x = d && this.lighting.shadow;
|
|
1176
1176
|
x && this.shadow.begin(this.canvas.width, this.canvas.height);
|
|
1177
1177
|
const w = d ? this.lit : this.main;
|
|
1178
|
-
if (this.current = w,
|
|
1178
|
+
if (this.current = w, a.useProgram(w.prog), d) {
|
|
1179
1179
|
const A = this.lighting;
|
|
1180
|
-
|
|
1180
|
+
a.uniform1i(w.u.uNormal, 1), a.uniform3f(w.u.uLight, A.x, A.y, A.z), a.uniform3f(w.u.uLightColor, (A.color >> 16 & 255) / 255, (A.color >> 8 & 255) / 255, (A.color & 255) / 255), a.uniform3f(w.u.uAmbientColor, (A.ambientColor >> 16 & 255) / 255, (A.ambientColor >> 8 & 255) / 255, (A.ambientColor & 255) / 255), a.uniform4f(w.u.uLighting, A.strength, A.intensity, A.ambient, A.reach), a.uniform4f(w.u.uSurface, A.softness, A.specular, A.rim, A.detail), a.uniform1f(w.u.uAspect, this.canvas.width / this.canvas.height), a.uniform1i(w.u.uCel, A.mode === "cel" ? 1 : 0), a.uniformMatrix3fv(w.u.uHeadRotation, !1, mr(b.angleX ?? 0, b.angleY ?? 0, b.angleZ ?? 0, t.head.maxRoll));
|
|
1181
1181
|
}
|
|
1182
|
-
|
|
1182
|
+
a.uniform2fv(w.u.uScale, this.scale), a.uniform2fv(w.u.uOffset, this.offset), a.uniform1i(w.u.uTex, 0), a.uniform4fv(w.u.uEyeBox, r.flatMap((A) => [A.x0, A.x1, 0, 0])), a.uniform1fv(w.u.uEyeTop, r.flatMap((A) => A.top)), a.uniform1fv(w.u.uEyeBot, r.flatMap((A) => A.bot)), a.uniform4fv(w.u.uEyeState, b.eyes), a.uniform4f(w.u.uMouth, o.cx, o.cy, o.angle, o.halfLen), a.uniform4f(w.u.uMouthState, b.mouthOpen, b.mouthForm, o.bow, 0), a.uniform4f(w.u.uCheeks, s[0][0], s[0][1], s[1][0], s[1][1]), a.uniform1f(w.u.uCheek, b.cheek), a.activeTexture(a.TEXTURE0);
|
|
1183
1183
|
for (const A of this.layers)
|
|
1184
1184
|
!A.visible || A.overlay || this.drawLayer(A, A.alpha ?? 1);
|
|
1185
1185
|
if (this.original && b.originalAlpha > 0 && this.drawLayer(this.original, b.originalAlpha), x && this.shadow.composite(this.lighting), b.showMesh) {
|
|
1186
1186
|
const A = this.line;
|
|
1187
|
-
|
|
1187
|
+
a.useProgram(A.prog), a.uniform2fv(A.u.uScale, this.scale), a.uniform2fv(A.u.uOffset, this.offset);
|
|
1188
1188
|
for (const L of this.layers)
|
|
1189
|
-
!L.visible || L.overlay || (
|
|
1190
|
-
b.joints?.length && this.drawPoints(b.joints),
|
|
1189
|
+
!L.visible || L.overlay || (a.bindVertexArray(L.vao), a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, L.lineBuf), a.uniform4fv(A.u.uColor, L.color), a.drawElements(a.LINES, L.mesh.lines.length, a.UNSIGNED_INT, 0), a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, L.triBuf));
|
|
1190
|
+
b.joints?.length && this.drawPoints(b.joints), a.bindVertexArray(null);
|
|
1191
1191
|
}
|
|
1192
1192
|
}
|
|
1193
|
-
drawLayer(b,
|
|
1193
|
+
drawLayer(b, a) {
|
|
1194
1194
|
const d = this.gl, x = this.current;
|
|
1195
|
-
d.useProgram(x.prog), d.bindVertexArray(b.vao), d.bindBuffer(d.ARRAY_BUFFER, b.posBuf), d.bufferSubData(d.ARRAY_BUFFER, 0, b.mesh.pos), this.lighting.enabled && (d.activeTexture(d.TEXTURE1), d.bindTexture(d.TEXTURE_2D, b.normal), d.activeTexture(d.TEXTURE0)), d.bindTexture(d.TEXTURE_2D, b.tex), d.uniform4fv(x.u.uRect, b.mesh.rect), d.uniform1i(x.u.uFace, b.eyeBall !== void 0 ? 2 + b.eyeBall : b.face ? 1 : 0), d.uniform1f(x.u.uAlpha,
|
|
1195
|
+
d.useProgram(x.prog), d.bindVertexArray(b.vao), d.bindBuffer(d.ARRAY_BUFFER, b.posBuf), d.bufferSubData(d.ARRAY_BUFFER, 0, b.mesh.pos), this.lighting.enabled && (d.activeTexture(d.TEXTURE1), d.bindTexture(d.TEXTURE_2D, b.normal), d.activeTexture(d.TEXTURE0)), d.bindTexture(d.TEXTURE_2D, b.tex), d.uniform4fv(x.u.uRect, b.mesh.rect), d.uniform1i(x.u.uFace, b.eyeBall !== void 0 ? 2 + b.eyeBall : b.face ? 1 : 0), d.uniform1f(x.u.uAlpha, a), d.drawElements(d.TRIANGLES, b.mesh.tris.length, d.UNSIGNED_INT, 0);
|
|
1196
1196
|
}
|
|
1197
1197
|
drawPoints(b) {
|
|
1198
|
-
const
|
|
1198
|
+
const a = this.gl, d = this.line;
|
|
1199
1199
|
if (!this.pointBuf) {
|
|
1200
|
-
this.pointBuf =
|
|
1201
|
-
const x =
|
|
1202
|
-
|
|
1200
|
+
this.pointBuf = a.createBuffer(), this.pointVao = a.createVertexArray(), a.bindVertexArray(this.pointVao), a.bindBuffer(a.ARRAY_BUFFER, this.pointBuf);
|
|
1201
|
+
const x = a.getAttribLocation(d.prog, "aPos");
|
|
1202
|
+
a.enableVertexAttribArray(x), a.vertexAttribPointer(x, 2, a.FLOAT, !1, 0, 0);
|
|
1203
1203
|
}
|
|
1204
|
-
|
|
1204
|
+
a.bindVertexArray(this.pointVao), a.bindBuffer(a.ARRAY_BUFFER, this.pointBuf), a.bufferData(a.ARRAY_BUFFER, new Float32Array(b.flat()), a.DYNAMIC_DRAW), a.uniform4f(d.u.uColor, 1, 0.85, 0.2, 1), a.drawArrays(a.POINTS, 0, b.length);
|
|
1205
1205
|
}
|
|
1206
1206
|
// canvas CSS px -> source image px
|
|
1207
|
-
toImage(b,
|
|
1207
|
+
toImage(b, a) {
|
|
1208
1208
|
if (!this.pxOff) return null;
|
|
1209
1209
|
const d = this.canvas.width / this.canvas.clientWidth;
|
|
1210
|
-
return [(b * d - this.pxOff[0]) / this.pxScale, (
|
|
1210
|
+
return [(b * d - this.pxOff[0]) / this.pxScale, (a * d - this.pxOff[1]) / this.pxScale];
|
|
1211
1211
|
}
|
|
1212
1212
|
}
|
|
1213
1213
|
return { Renderer: p, buildGrid: h };
|
|
1214
1214
|
}
|
|
1215
|
-
function
|
|
1216
|
-
const { applyHead: n, applyBody: r, TASSELS: o, tasselAnchor:
|
|
1217
|
-
if (
|
|
1215
|
+
function gr(e, t) {
|
|
1216
|
+
const { applyHead: n, applyBody: r, TASSELS: o, tasselAnchor: s } = e, i = (t.strands ?? []).map((a) => {
|
|
1217
|
+
if (a.nodes.length === 4) return a;
|
|
1218
1218
|
const d = Array.from({ length: 4 }, (x, w) => {
|
|
1219
|
-
const A = w / 3 * (
|
|
1220
|
-
return [0, 1].map((Y) =>
|
|
1219
|
+
const A = w / 3 * (a.nodes.length - 1), L = Math.min(a.nodes.length - 2, Math.floor(A)), z = A - L;
|
|
1220
|
+
return [0, 1].map((Y) => a.nodes[L][Y] + (a.nodes[L + 1][Y] - a.nodes[L][Y]) * z);
|
|
1221
1221
|
});
|
|
1222
|
-
return { ...
|
|
1223
|
-
}), u = [0, 300, 200, 140], y = 0.9, v = 7, m = { stiff: 1.7, damp: 1.6, couple: 0.85, reach: 0.9, bind: 4 }, l = Math.min(6, i.filter((
|
|
1224
|
-
const x = Math.hypot(
|
|
1225
|
-
if (x < 1e-6) return
|
|
1222
|
+
return { ...a, nodes: d };
|
|
1223
|
+
}), u = [0, 300, 200, 140], y = 0.9, v = 7, m = { stiff: 1.7, damp: 1.6, couple: 0.85, reach: 0.9, bind: 4 }, l = Math.min(6, i.filter((a) => a.name.startsWith("bang")).length), c = { freq: 0.7, zeta: 0.22, hang: 0.85, inertia: 0.32, wind: 0.03, max: 0.55, smooth: 6 }, f = (a, d) => [a[0] * Math.cos(d) - a[1] * Math.sin(d), a[0] * Math.sin(d) + a[1] * Math.cos(d)], h = (a, d) => {
|
|
1224
|
+
const x = Math.hypot(a[0], a[1]);
|
|
1225
|
+
if (x < 1e-6) return a;
|
|
1226
1226
|
const w = d * Math.tanh(x / d) / x;
|
|
1227
|
-
return [
|
|
1228
|
-
}, p = Object.fromEntries(Object.entries(
|
|
1229
|
-
const x = Math.hypot(
|
|
1230
|
-
x > d && (
|
|
1227
|
+
return [a[0] * w, a[1] * w];
|
|
1228
|
+
}, p = Object.fromEntries(Object.entries(t.buns ?? {}).map(([a, d]) => [a, { at: [d.cx, d.cy], k: 260, c: 11, hang: 3, max: 4 }])), g = (a, d) => {
|
|
1229
|
+
const x = Math.hypot(a[0], a[1]);
|
|
1230
|
+
x > d && (a[0] *= d / x, a[1] *= d / x);
|
|
1231
1231
|
};
|
|
1232
1232
|
class b {
|
|
1233
1233
|
constructor() {
|
|
@@ -1244,8 +1244,8 @@ function pr(t, e) {
|
|
|
1244
1244
|
return n(w, 1, x), r(w, d[1], x), w;
|
|
1245
1245
|
}
|
|
1246
1246
|
step(d, x) {
|
|
1247
|
-
|
|
1248
|
-
const w = Math.max(1, Math.ceil(x / (1 / 240))), A = Math.min(x, 0.05) / w, L = -d.angleZ / 30 *
|
|
1247
|
+
e.stepBody?.(d, x);
|
|
1248
|
+
const w = Math.max(1, Math.ceil(x / (1 / 240))), A = Math.min(x, 0.05) / w, L = -d.angleZ / 30 * t.head.maxRoll - d.bodyAngleZ / 10 * t.body.maxRoll, z = this.gain;
|
|
1249
1249
|
i.forEach((I, U) => {
|
|
1250
1250
|
const T = this.strands[U], F = this.out.strands[U], j = I.nodes.map((B) => this.hairAnchor(B, d));
|
|
1251
1251
|
T.p || (T.p = j.map((B) => [...B]));
|
|
@@ -1253,8 +1253,8 @@ function pr(t, e) {
|
|
|
1253
1253
|
for (let B = 0; B < w; B++) {
|
|
1254
1254
|
const H = this.time + B * A;
|
|
1255
1255
|
for (let N = 1; N < 4; N++) {
|
|
1256
|
-
const ne = Math.hypot(I.nodes[N][0] - I.nodes[0][0], I.nodes[N][1] - I.nodes[0][1]), Q = (Math.sin(H * 1.3) * 0.5 + Math.sin(H * 3.1) * 0.3 + Math.sin(H * 4.7 + C) * 0.2) * I.max * 0.1 * N / 3, J = [T.p[N - 1][0] - j[N - 1][0], T.p[N - 1][1] - j[N - 1][1]], X = j[N][0] + J[0] * y * m.couple - Math.sin(L) * ne * 0.12 + Q, G = j[N][1] + J[1] * y * m.couple, re = u[N] * I.k * m.stiff / Math.max(0.35, z), W = v * m.damp * Math.sqrt(m.stiff) / Math.max(0.5, Math.sqrt(z)), te = T.v[N],
|
|
1257
|
-
te[0] += (re * (X -
|
|
1256
|
+
const ne = Math.hypot(I.nodes[N][0] - I.nodes[0][0], I.nodes[N][1] - I.nodes[0][1]), Q = (Math.sin(H * 1.3) * 0.5 + Math.sin(H * 3.1) * 0.3 + Math.sin(H * 4.7 + C) * 0.2) * I.max * 0.1 * N / 3, J = [T.p[N - 1][0] - j[N - 1][0], T.p[N - 1][1] - j[N - 1][1]], X = j[N][0] + J[0] * y * m.couple - Math.sin(L) * ne * 0.12 + Q, G = j[N][1] + J[1] * y * m.couple, re = u[N] * I.k * m.stiff / Math.max(0.35, z), W = v * m.damp * Math.sqrt(m.stiff) / Math.max(0.5, Math.sqrt(z)), te = T.v[N], ae = T.p[N];
|
|
1257
|
+
te[0] += (re * (X - ae[0]) - W * te[0]) * A, te[1] += (re * (G - ae[1]) - W * te[1]) * A, ae[0] += te[0] * A, ae[1] += te[1] * A;
|
|
1258
1258
|
}
|
|
1259
1259
|
T.p[0] = [...j[0]];
|
|
1260
1260
|
}
|
|
@@ -1282,15 +1282,15 @@ function pr(t, e) {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
}
|
|
1284
1284
|
for (const I of this.chains) {
|
|
1285
|
-
const U =
|
|
1285
|
+
const U = s(I.t, d, this.out, [0, 0]);
|
|
1286
1286
|
I.st || (I.st = { th: [0, 0], w: [0, 0], pos: [...U], vel: [0, 0], acc: [0, 0] });
|
|
1287
1287
|
const T = I.st, F = c, j = [(U[0] - T.pos[0]) / Math.max(x, 1e-3), (U[1] - T.pos[1]) / Math.max(x, 1e-3)], C = 1 - Math.exp(-x * F.smooth), B = [(j[0] - T.vel[0]) / Math.max(x, 1e-3), (j[1] - T.vel[1]) / Math.max(x, 1e-3)];
|
|
1288
1288
|
T.acc = [T.acc[0] + (B[0] - T.acc[0]) * C, T.acc[1] + (B[1] - T.acc[1]) * C], T.vel = [T.vel[0] + (j[0] - T.vel[0]) * C, T.vel[1] + (j[1] - T.vel[1]) * C], T.pos = [...U];
|
|
1289
1289
|
const H = [-I.dir[1], I.dir[0]], N = -(T.acc[0] * H[0] + T.acc[1] * H[1]) / (I.L1 + I.L2) * F.inertia, ne = (Math.sin(this.time * 0.9 + I.t.pivot[0]) * 0.6 + Math.sin(this.time * 0.37 + I.t.pivot[1]) * 0.4) * F.wind, Q = -L * F.hang + ne, J = 2 * Math.PI * F.freq / Math.sqrt(Math.max(0.4, z)), X = J * 1.35;
|
|
1290
1290
|
for (let te = 0; te < w; te++) {
|
|
1291
|
-
const
|
|
1292
|
-
T.w[0] +=
|
|
1293
|
-
const V = -X * X * (T.th[1] - T.th[0]) - 2 * F.zeta * X * T.w[1] + N * 0.4 +
|
|
1291
|
+
const ae = -J * J * (T.th[0] - Q) - 2 * F.zeta * J * T.w[0] + N;
|
|
1292
|
+
T.w[0] += ae * A, T.th[0] += T.w[0] * A;
|
|
1293
|
+
const V = -X * X * (T.th[1] - T.th[0]) - 2 * F.zeta * X * T.w[1] + N * 0.4 + ae * 0.5;
|
|
1294
1294
|
T.w[1] += V * A, T.th[1] += T.w[1] * A;
|
|
1295
1295
|
}
|
|
1296
1296
|
T.th[0] = Math.max(-0.55, Math.min(F.max, T.th[0])), T.th[1] = Math.max(-0.55 * 1.4, Math.min(F.max * 1.4, T.th[1])), I.phi = [T.th[0], T.th[1]];
|
|
@@ -1302,67 +1302,67 @@ function pr(t, e) {
|
|
|
1302
1302
|
}
|
|
1303
1303
|
return { Physics: b };
|
|
1304
1304
|
}
|
|
1305
|
-
const
|
|
1306
|
-
function
|
|
1307
|
-
const n =
|
|
1305
|
+
const _n = (e, t) => e.reduce((n, r, o) => n + r * t[o], 0);
|
|
1306
|
+
function yr(e, t) {
|
|
1307
|
+
const n = t.length, r = Array.from({ length: n }, () => Array(n).fill(0));
|
|
1308
1308
|
for (let i = 0; i < n; i++) for (let u = 0; u <= i; u++) {
|
|
1309
|
-
let y =
|
|
1309
|
+
let y = e[i][u];
|
|
1310
1310
|
for (let v = 0; v < u; v++) y -= r[i][v] * r[u][v];
|
|
1311
1311
|
r[i][u] = i === u ? Math.sqrt(Math.max(1e-18, y)) : y / r[u][u];
|
|
1312
1312
|
}
|
|
1313
|
-
const o = [],
|
|
1314
|
-
for (let i = 0; i < n; i++) o[i] = (
|
|
1313
|
+
const o = [], s = [];
|
|
1314
|
+
for (let i = 0; i < n; i++) o[i] = (t[i] - _n(r[i].slice(0, i), o)) / r[i][i];
|
|
1315
1315
|
for (let i = n - 1; i >= 0; i--) {
|
|
1316
1316
|
let u = o[i];
|
|
1317
|
-
for (let y = i + 1; y < n; y++) u -= r[y][i] *
|
|
1318
|
-
|
|
1317
|
+
for (let y = i + 1; y < n; y++) u -= r[y][i] * s[y];
|
|
1318
|
+
s[i] = u / r[i][i];
|
|
1319
1319
|
}
|
|
1320
|
-
return
|
|
1320
|
+
return s;
|
|
1321
1321
|
}
|
|
1322
|
-
function
|
|
1323
|
-
const
|
|
1322
|
+
function vr(e) {
|
|
1323
|
+
const t = e.map((o) => [...o]), n = t.length, r = t.map((o, s) => t.map((i, u) => +(s === u)));
|
|
1324
1324
|
for (let o = 0; o < 100 * n * n; o++) {
|
|
1325
|
-
let
|
|
1326
|
-
for (let h = 0; h < n; h++) for (let p = h + 1; p < n; p++) Math.abs(
|
|
1325
|
+
let s = 0, i = 1, u = 0;
|
|
1326
|
+
for (let h = 0; h < n; h++) for (let p = h + 1; p < n; p++) Math.abs(t[h][p]) > u && (u = Math.abs(t[h][p]), s = h, i = p);
|
|
1327
1327
|
if (u < 1e-12) break;
|
|
1328
|
-
const y = 0.5 * Math.atan2(2 *
|
|
1329
|
-
for (let h = 0; h < n; h++) if (h !==
|
|
1330
|
-
const p =
|
|
1331
|
-
|
|
1328
|
+
const y = 0.5 * Math.atan2(2 * t[s][i], t[i][i] - t[s][s]), v = Math.cos(y), m = Math.sin(y), l = t[s][s], c = t[i][i], f = t[s][i];
|
|
1329
|
+
for (let h = 0; h < n; h++) if (h !== s && h !== i) {
|
|
1330
|
+
const p = t[h][s], g = t[h][i];
|
|
1331
|
+
t[h][s] = t[s][h] = v * p - m * g, t[h][i] = t[i][h] = m * p + v * g;
|
|
1332
1332
|
}
|
|
1333
|
-
|
|
1333
|
+
t[s][s] = v * v * l - 2 * m * v * f + m * m * c, t[i][i] = m * m * l + 2 * m * v * f + v * v * c, t[s][i] = t[i][s] = 0;
|
|
1334
1334
|
for (let h = 0; h < n; h++) {
|
|
1335
|
-
const p = r[h][
|
|
1336
|
-
r[h][
|
|
1335
|
+
const p = r[h][s], g = r[h][i];
|
|
1336
|
+
r[h][s] = v * p - m * g, r[h][i] = m * p + v * g;
|
|
1337
1337
|
}
|
|
1338
1338
|
}
|
|
1339
|
-
return { values:
|
|
1339
|
+
return { values: t.map((o, s) => o[s]), vectors: r };
|
|
1340
1340
|
}
|
|
1341
|
-
function
|
|
1342
|
-
const o =
|
|
1343
|
-
return { lengths:
|
|
1341
|
+
function br(e, t, n, r = 1) {
|
|
1342
|
+
const o = e.map((l, c) => e.slice(c).reduce((f, h) => f + h, 0)), s = e.map((l, c) => e.map((f, h) => o[Math.max(c, h)] * l * f)), i = e.map((l, c) => t * o[c] * l), u = i.map(Math.sqrt), y = vr(s.map((l, c) => l.map((f, h) => f / u[c] / u[h]))), v = y.values.indexOf(Math.max(...y.values)), m = e.map((l, c) => e.map((f, h) => u[c] * u[h] * y.values.reduce((p, g, b) => p + y.vectors[c][b] * y.vectors[h][b] * 2 * n * Math.sqrt(g) * (b === v ? 1 : r), 0)));
|
|
1343
|
+
return { lengths: e, mass: o, coefficient: s, stiffness: i, damping: m, frequencies: y.values.map((l) => 1 / Math.sqrt(l) / (2 * Math.PI)).sort((l, c) => l - c), angles: e.map(() => 0), velocities: e.map(() => 0) };
|
|
1344
1344
|
}
|
|
1345
|
-
function
|
|
1346
|
-
let r =
|
|
1347
|
-
for (let o = 0; o <
|
|
1345
|
+
function Ft(e, t = e.angles, n = e.velocities) {
|
|
1346
|
+
let r = e.stiffness.reduce((o, s, i) => o + s * (1 - Math.cos(t[i])), 0);
|
|
1347
|
+
for (let o = 0; o < t.length; o++) for (let s = 0; s < t.length; s++) r += 0.5 * e.coefficient[o][s] * Math.cos(t[o] - t[s]) * n[o] * n[s];
|
|
1348
1348
|
return r;
|
|
1349
1349
|
}
|
|
1350
|
-
function
|
|
1351
|
-
const o =
|
|
1352
|
-
let y =
|
|
1350
|
+
function wr(e, t, n = 0, r = 1) {
|
|
1351
|
+
const o = e.angles, s = e.velocities, i = e.coefficient.map((m, l) => m.map((c, f) => c * Math.cos(o[l] - o[f]))), u = o.map((m, l) => _n(i[l], s) + t * (-e.stiffness[l] * r * Math.sin(m) - n * e.mass[l] * e.lengths[l] * Math.cos(m) - e.coefficient[l].reduce((c, f, h) => c + f * Math.sin(m - o[h]) * s[h] * s[h], 0)));
|
|
1352
|
+
let y = yr(i.map((m, l) => m.map((c, f) => c + t * e.damping[l][f])), u), v = o.map((m, l) => m + t * y[l]);
|
|
1353
1353
|
if (n === 0 && r === 1) {
|
|
1354
|
-
const m =
|
|
1354
|
+
const m = Ft(e), l = Ft(e, v, y.map(() => 0)), c = Ft(e, v, y);
|
|
1355
1355
|
if (c > m)
|
|
1356
1356
|
if (l > m)
|
|
1357
|
-
v = [...o], y =
|
|
1357
|
+
v = [...o], y = s.map((f) => f * 0.999);
|
|
1358
1358
|
else {
|
|
1359
1359
|
const f = Math.sqrt(Math.max(0, (m - l) / Math.max(1e-30, c - l)));
|
|
1360
1360
|
y = y.map((h) => h * f);
|
|
1361
1361
|
}
|
|
1362
1362
|
}
|
|
1363
|
-
|
|
1363
|
+
e.angles = v, e.velocities = y;
|
|
1364
1364
|
}
|
|
1365
|
-
const
|
|
1365
|
+
const Fn = Object.freeze({
|
|
1366
1366
|
responseGain: 1,
|
|
1367
1367
|
swing: 1,
|
|
1368
1368
|
stiffness: 1,
|
|
@@ -1371,38 +1371,38 @@ const Ln = Object.freeze({
|
|
|
1371
1371
|
cohesion: 3,
|
|
1372
1372
|
wind: 0.05,
|
|
1373
1373
|
max: 20
|
|
1374
|
-
}),
|
|
1375
|
-
function
|
|
1376
|
-
if (!
|
|
1377
|
-
for (const [
|
|
1378
|
-
if (!Object.hasOwn(
|
|
1379
|
-
if (typeof n != "number" || !Number.isFinite(n)) throw new RangeError(`${
|
|
1380
|
-
if (["tierGain", "highModeDamping", "responseGain", "swing", "stiffness", "damping", "max"].includes(
|
|
1381
|
-
if (["follow", "wind"].includes(
|
|
1382
|
-
if (
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
function
|
|
1374
|
+
}), jn = Object.freeze({ tierGain: 1, highModeDamping: 1 });
|
|
1375
|
+
function xr(e) {
|
|
1376
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError("Expected cloth tuning");
|
|
1377
|
+
for (const [t, n] of Object.entries(e)) {
|
|
1378
|
+
if (!Object.hasOwn(Fn, t) && !Object.hasOwn(jn, t)) throw new RangeError(`Unknown cloth tuning: ${t}`);
|
|
1379
|
+
if (typeof n != "number" || !Number.isFinite(n)) throw new RangeError(`${t}: expected a finite number`);
|
|
1380
|
+
if (["tierGain", "highModeDamping", "responseGain", "swing", "stiffness", "damping", "max"].includes(t) && n <= 0) throw new RangeError(`${t}: must be positive`);
|
|
1381
|
+
if (["follow", "wind"].includes(t) && (n < 0 || t === "follow" && n > 1)) throw new RangeError(`${t}: out of range`);
|
|
1382
|
+
if (t === "cohesion" && (!Number.isInteger(n) || n < 0 || n > 8)) throw new RangeError("cohesion: expected an integer from 0 to 8");
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
function mn(e, t) {
|
|
1386
1386
|
const n = [0];
|
|
1387
|
-
for (let o = 1; o <
|
|
1388
|
-
n.push(n[o - 1] + Math.hypot(
|
|
1387
|
+
for (let o = 1; o < e.length; o++)
|
|
1388
|
+
n.push(n[o - 1] + Math.hypot(e[o][0] - e[o - 1][0], e[o][1] - e[o - 1][1]));
|
|
1389
1389
|
const r = n.at(-1);
|
|
1390
|
-
return Array.from({ length:
|
|
1391
|
-
const i = r *
|
|
1390
|
+
return Array.from({ length: t }, (o, s) => {
|
|
1391
|
+
const i = r * s / (t - 1);
|
|
1392
1392
|
let u = 1;
|
|
1393
|
-
for (; u <
|
|
1393
|
+
for (; u < e.length - 1 && n[u] < i; ) u++;
|
|
1394
1394
|
const y = (i - n[u - 1]) / Math.max(1e-9, n[u] - n[u - 1]);
|
|
1395
|
-
return [0, 1].map((v) =>
|
|
1395
|
+
return [0, 1].map((v) => e[u - 1][v] + (e[u][v] - e[u - 1][v]) * y);
|
|
1396
1396
|
});
|
|
1397
1397
|
}
|
|
1398
|
-
function
|
|
1399
|
-
const { baseWeights: n, deformBase: r } =
|
|
1400
|
-
const f =
|
|
1398
|
+
function Mr(e, t) {
|
|
1399
|
+
const { baseWeights: n, deformBase: r } = e, o = { bounceHz: 2.6, zeta: 0.25 }, s = t.legs ? 0.8 / ((Math.hypot(...t.legs.left.ankle.map((c, f) => c - t.legs.left.hip[f])) + Math.hypot(...t.legs.right.ankle.map((c, f) => c - t.legs.right.hip[f]))) / 2) : 1.6 / t.image.height, i = 0.8, u = (t.cloth ?? []).map((c) => {
|
|
1400
|
+
const f = kn(c), h = f.custom ? f.cols : c.columns ?? 8, p = f.custom ? f.rows : c.rows ?? 5, g = mn(c.waist, h), b = mn(c.hem, h), a = new Float64Array(p * h * 2);
|
|
1401
1401
|
for (let d = 0; d < p; d++) for (let x = 0; x < h; x++) {
|
|
1402
1402
|
const w = d / (p - 1), A = (d * h + x) * 2;
|
|
1403
|
-
|
|
1403
|
+
a[A] = g[x][0] + (b[x][0] - g[x][0]) * w, a[A + 1] = g[x][1] + (b[x][1] - g[x][1]) * w;
|
|
1404
1404
|
}
|
|
1405
|
-
return f.custom &&
|
|
1405
|
+
return f.custom && a.set(f.rest), {
|
|
1406
1406
|
grid: f,
|
|
1407
1407
|
pendulums: (
|
|
1408
1408
|
/** @type {ReturnType<typeof pendulumSystem>[]} */
|
|
@@ -1410,14 +1410,14 @@ function wr(t, e) {
|
|
|
1410
1410
|
),
|
|
1411
1411
|
systemKey: null,
|
|
1412
1412
|
c,
|
|
1413
|
-
gravity: 9.80665 / (c.scale === void 0 ?
|
|
1414
|
-
tuning: Object.fromEntries(Object.entries({ ...
|
|
1413
|
+
gravity: 9.80665 / (c.scale === void 0 ? s : c.scale / 1e3),
|
|
1414
|
+
tuning: Object.fromEntries(Object.entries({ ...Fn, ...jn }).map(([d, x]) => [d, c[d] ?? x])),
|
|
1415
1415
|
cols: h,
|
|
1416
1416
|
rows: p,
|
|
1417
|
-
rest:
|
|
1417
|
+
rest: a,
|
|
1418
1418
|
top: f.custom ? f.top : g,
|
|
1419
1419
|
weights: (f.custom ? f.top : g).map(([d, x]) => n(d, x, 0)),
|
|
1420
|
-
target: new Float64Array(
|
|
1420
|
+
target: new Float64Array(a.length),
|
|
1421
1421
|
previous: null,
|
|
1422
1422
|
pivotVelocity: new Float64Array(h * 2),
|
|
1423
1423
|
angle: new Float64Array(h),
|
|
@@ -1426,8 +1426,8 @@ function wr(t, e) {
|
|
|
1426
1426
|
lowerAngularVelocity: new Float64Array(h),
|
|
1427
1427
|
bounce: new Float64Array(h),
|
|
1428
1428
|
bounceVelocity: new Float64Array(h),
|
|
1429
|
-
out: Float64Array.from(
|
|
1430
|
-
physicalOut: Float64Array.from(
|
|
1429
|
+
out: Float64Array.from(a),
|
|
1430
|
+
physicalOut: Float64Array.from(a),
|
|
1431
1431
|
parent: null,
|
|
1432
1432
|
parentLoc: null,
|
|
1433
1433
|
meshes: []
|
|
@@ -1436,7 +1436,7 @@ function wr(t, e) {
|
|
|
1436
1436
|
function v(c, f, h) {
|
|
1437
1437
|
let p = null;
|
|
1438
1438
|
for (let g = 0; g < c.rows - 1; g++) for (let b = 0; b < c.cols - 1; b++) {
|
|
1439
|
-
const
|
|
1439
|
+
const a = [(g * c.cols + b) * 2, (g * c.cols + b + 1) * 2, ((g + 1) * c.cols + b + 1) * 2, ((g + 1) * c.cols + b) * 2], [d, x, w, A, L, z, Y, I] = a.flatMap((j) => [c.rest[j], c.rest[j + 1]]);
|
|
1440
1440
|
let U = 0.5, T = 0.5;
|
|
1441
1441
|
for (let j = 0; j < 10; j++) {
|
|
1442
1442
|
const C = d * (1 - U) * (1 - T) + w * U * (1 - T) + L * U * T + Y * (1 - U) * T - f, B = x * (1 - U) * (1 - T) + A * U * (1 - T) + z * U * T + I * (1 - U) * T - h, H = (w - d) * (1 - T) + (L - Y) * T, N = (A - x) * (1 - T) + (z - I) * T, ne = (Y - d) * (1 - U) + (L - w) * U, Q = (I - x) * (1 - U) + (z - A) * U, J = H * Q - N * ne;
|
|
@@ -1448,7 +1448,7 @@ function wr(t, e) {
|
|
|
1448
1448
|
const j = Math.max(0, Math.min(1, U)), C = Math.max(0, Math.min(1, T)), B = d * (1 - j) * (1 - C) + w * j * (1 - C) + L * j * C + Y * (1 - j) * C, H = x * (1 - j) * (1 - C) + A * j * (1 - C) + z * j * C + I * (1 - j) * C;
|
|
1449
1449
|
F = Math.hypot(B - f, H - h);
|
|
1450
1450
|
}
|
|
1451
|
-
(!p || F < p.miss) && (p = { q:
|
|
1451
|
+
(!p || F < p.miss) && (p = { q: a, s: U, t: T, miss: F });
|
|
1452
1452
|
}
|
|
1453
1453
|
if (p.s = Math.min(c.grid.custom ? 1 : 4, Math.max(c.grid.custom ? 0 : -3, p.s)), p.t = Math.min(c.grid.custom ? 1 : 4, Math.max(c.grid.custom ? 0 : -3, p.t)), c.grid.custom) {
|
|
1454
1454
|
const g = [0, 0];
|
|
@@ -1457,10 +1457,10 @@ function wr(t, e) {
|
|
|
1457
1457
|
return p;
|
|
1458
1458
|
}
|
|
1459
1459
|
function m(c, f, h) {
|
|
1460
|
-
const { q: p, s: g, t: b } = f,
|
|
1460
|
+
const { q: p, s: g, t: b } = f, a = [(1 - g) * (1 - b), g * (1 - b), g * b, (1 - g) * b];
|
|
1461
1461
|
h[0] = f.offset?.[0] ?? 0, h[1] = f.offset?.[1] ?? 0;
|
|
1462
1462
|
for (let d = 0; d < 4; d++)
|
|
1463
|
-
h[0] += c[p[d]] *
|
|
1463
|
+
h[0] += c[p[d]] * a[d], h[1] += c[p[d] + 1] * a[d];
|
|
1464
1464
|
return h;
|
|
1465
1465
|
}
|
|
1466
1466
|
for (const c of u) c.c.parent && (c.parent = y[c.c.parent], c.parentLoc = c.top.map(([f, h]) => v(c.parent, f, h)));
|
|
@@ -1469,7 +1469,7 @@ function wr(t, e) {
|
|
|
1469
1469
|
this.gain = 1, this.time = 0;
|
|
1470
1470
|
}
|
|
1471
1471
|
setTuning(f, h) {
|
|
1472
|
-
if (
|
|
1472
|
+
if (xr(h), f !== null && !Object.hasOwn(y, f)) throw new RangeError(`Unknown cloth: ${f}`);
|
|
1473
1473
|
for (const p of u) (f === null || p.c.name === f) && Object.assign(p.tuning, h);
|
|
1474
1474
|
}
|
|
1475
1475
|
/** Skin a layer mesh (rest/pos arrays in source px) to the named garment. */
|
|
@@ -1480,13 +1480,13 @@ function wr(t, e) {
|
|
|
1480
1480
|
}
|
|
1481
1481
|
step(f, h, p) {
|
|
1482
1482
|
if (h < 0) return;
|
|
1483
|
-
const g = Math.min(h, 0.05), b = Math.max(1, Math.ceil(g * 240)),
|
|
1483
|
+
const g = Math.min(h, 0.05), b = Math.max(1, Math.ceil(g * 240)), a = g / b, d = [0, 0];
|
|
1484
1484
|
for (const x of u) {
|
|
1485
|
-
const { cols: w, rows: A, rest: L, target: z, out: Y, angle: I, angularVelocity: U, lowerAngle: T, lowerAngularVelocity: F, bounce: j, bounceVelocity: C } = x, { stiffness: B, damping: H, max: N, swing: ne, follow: Q, cohesion: J, wind: X, responseGain: G, tierGain: re, highModeDamping: W } = x.tuning, te = this.gain * (G ?? 1),
|
|
1485
|
+
const { cols: w, rows: A, rest: L, target: z, out: Y, angle: I, angularVelocity: U, lowerAngle: T, lowerAngularVelocity: F, bounce: j, bounceVelocity: C } = x, { stiffness: B, damping: H, max: N, swing: ne, follow: Q, cohesion: J, wind: X, responseGain: G, tierGain: re, highModeDamping: W } = x.tuning, te = this.gain * (G ?? 1), ae = new Float64Array(w * 2), V = new Float64Array(w * 2), M = new Float64Array(w * 2);
|
|
1486
1486
|
for (let $ = 0; $ < w; $++) {
|
|
1487
|
-
x.parent ? m(x.parent.physicalOut, x.parentLoc[$], d) : r(x.top[$][0], x.top[$][1], x.weights[$], f, p, d),
|
|
1487
|
+
x.parent ? m(x.parent.physicalOut, x.parentLoc[$], d) : r(x.top[$][0], x.top[$][1], x.weights[$], f, p, d), ae[$ * 2] = d[0], ae[$ * 2 + 1] = d[1], x.parent && m(x.parent.out, x.parentLoc[$], d), V[$ * 2] = d[0], V[$ * 2 + 1] = d[1];
|
|
1488
1488
|
for (let Z = 0; Z < 2; Z++) {
|
|
1489
|
-
const _ = $ * 2 + Z, D = x.previous && g > 0 ? (
|
|
1489
|
+
const _ = $ * 2 + Z, D = x.previous && g > 0 ? (ae[_] - x.previous[_]) / g : 0;
|
|
1490
1490
|
M[_] = g > 0 ? (D - x.pivotVelocity[_]) / g : 0, x.pivotVelocity[_] = D;
|
|
1491
1491
|
}
|
|
1492
1492
|
for (let Z = 0; Z < A; Z++) {
|
|
@@ -1494,14 +1494,14 @@ function wr(t, e) {
|
|
|
1494
1494
|
z[_] = L[_] + d[0] - x.top[$][0], z[_ + 1] = L[_ + 1] + d[1] - x.top[$][1];
|
|
1495
1495
|
}
|
|
1496
1496
|
}
|
|
1497
|
-
x.previous =
|
|
1497
|
+
x.previous = ae;
|
|
1498
1498
|
const E = ne * Math.sqrt(B), O = 2 * Math.PI * o.bounceHz;
|
|
1499
1499
|
if (x.grid.custom) {
|
|
1500
1500
|
const $ = `${E}:${H}:${W}`;
|
|
1501
1501
|
if (x.systemKey !== $) {
|
|
1502
1502
|
const ee = x.pendulums;
|
|
1503
1503
|
x.pendulums = x.grid.lengths.map((oe, S) => {
|
|
1504
|
-
const R = x.grid.joints[S], P =
|
|
1504
|
+
const R = x.grid.joints[S], P = br(R.slice(1).map((se, ie) => (se - R[ie]) * oe * i), x.gravity * E ** 2, o.zeta * H, W);
|
|
1505
1505
|
return ee[S] && (P.angles = ee[S].angles, P.velocities = ee[S].velocities), P;
|
|
1506
1506
|
}), x.systemKey = $;
|
|
1507
1507
|
}
|
|
@@ -1509,43 +1509,43 @@ function wr(t, e) {
|
|
|
1509
1509
|
for (let ee = 0; ee < _; ee++) {
|
|
1510
1510
|
const oe = this.time + (ee + 1) * D, S = (Math.sin(oe * 1.1) * 0.6 + Math.sin(oe * 2.3) * 0.4) * N * X;
|
|
1511
1511
|
for (let R = 0; R < w; R++) {
|
|
1512
|
-
const P = M[R * 2 + 1],
|
|
1513
|
-
|
|
1512
|
+
const P = M[R * 2 + 1], se = Math.max(x.gravity * 0.1, x.gravity - P), ie = Math.max(-8 * x.gravity, Math.min(8 * x.gravity, M[R * 2])) - se * S / x.grid.lengths[R];
|
|
1513
|
+
wr(x.pendulums[R], D, ie, se / x.gravity), C[R] += (-(O ** 2) * j[R] - 2 * O * C[R] - P * 0.15) * D, j[R] += C[R] * D;
|
|
1514
1514
|
}
|
|
1515
1515
|
}
|
|
1516
1516
|
for (let ee = 0; g > 0 && ee < J; ee++) for (const oe of ["angles", "velocities"]) {
|
|
1517
1517
|
const S = x.pendulums.map((R) => [...R[oe]]);
|
|
1518
1518
|
x.pendulums.forEach((R, P) => {
|
|
1519
|
-
R[oe] = S[P].map((
|
|
1519
|
+
R[oe] = S[P].map((se, ie) => 0.5 * se + 0.25 * (S[Math.max(0, P - 1)][ie] + S[Math.min(w - 1, P + 1)][ie]));
|
|
1520
1520
|
});
|
|
1521
1521
|
}
|
|
1522
1522
|
const q = (ee, oe, S, R = 1) => {
|
|
1523
1523
|
for (let P = 0; P < w; P++) {
|
|
1524
|
-
const
|
|
1524
|
+
const se = x.grid.joints[P], ie = x.grid.seams[P], pe = x.grid.lengths[P], be = N * 0.1 * Math.tanh(j[P] * S / (N * 0.1)), Me = 2 * Math.asin(Math.min(0.95, (N - Math.abs(be)) / (2 * pe))), Be = x.pendulums[P].angles[0], Ee = x.pendulums[P].angles.map((K) => {
|
|
1525
1525
|
const ce = R === 1 ? K : Be + (K - Be) * R;
|
|
1526
1526
|
return Me * Math.tanh(ce * S / Me);
|
|
1527
1527
|
}), de = [Array.from(oe.slice(P * 2, P * 2 + 2))];
|
|
1528
1528
|
for (let K = 0; K < Ee.length; K++) {
|
|
1529
|
-
const ce = qe(ie,
|
|
1529
|
+
const ce = qe(ie, se[K]), ue = qe(ie, se[K + 1]), ke = ue[0] - ce[0], Se = ue[1] - ce[1], ye = Ee[K];
|
|
1530
1530
|
de.push([de[K][0] + ke * Math.cos(ye) + Se * Math.sin(ye), de[K][1] - ke * Math.sin(ye) + Se * Math.cos(ye)]);
|
|
1531
1531
|
}
|
|
1532
1532
|
for (let K = 0; K < A; K++) {
|
|
1533
1533
|
const ce = x.grid.fractions[P][K];
|
|
1534
1534
|
let ue = 0;
|
|
1535
|
-
for (; ue < Ee.length - 1 && ce >
|
|
1536
|
-
const ke = qe(ie,
|
|
1535
|
+
for (; ue < Ee.length - 1 && ce > se[ue + 1] + 1e-9; ) ue++;
|
|
1536
|
+
const ke = qe(ie, se[ue]), Se = qe(ie, ce), ye = (ce - se[ue]) / (se[ue + 1] - se[ue]), Le = Ee[ue] * (1 - 0.1 * (1 - Q) * (1 - ye)), $e = Se[0] - ke[0], nt = Se[1] - ke[1], rt = (K * w + P) * 2;
|
|
1537
1537
|
ee[rt] = de[ue][0] + $e * Math.cos(Le) + nt * Math.sin(Le), ee[rt + 1] = de[ue][1] - $e * Math.sin(Le) + nt * Math.cos(Le) + be * ce;
|
|
1538
1538
|
}
|
|
1539
1539
|
}
|
|
1540
1540
|
};
|
|
1541
|
-
q(x.physicalOut,
|
|
1541
|
+
q(x.physicalOut, ae, 1), q(Y, V, te, re);
|
|
1542
1542
|
continue;
|
|
1543
1543
|
}
|
|
1544
1544
|
for (let $ = 0; $ < b; $++) {
|
|
1545
|
-
const Z = this.time + ($ + 1) *
|
|
1545
|
+
const Z = this.time + ($ + 1) * a, _ = (Math.sin(Z * 1.1) * 0.6 + Math.sin(Z * 2.3) * 0.4) * N * X;
|
|
1546
1546
|
for (let D = 0; D < w; D++) {
|
|
1547
|
-
const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = Math.max(x.gravity * 0.1, x.gravity - M[q + 1]), R = i * oe / 2, P = S / R * E * E,
|
|
1548
|
-
U[D] += ($e - de * nt) / rt *
|
|
1547
|
+
const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = Math.max(x.gravity * 0.1, x.gravity - M[q + 1]), R = i * oe / 2, P = S / R * E * E, se = Math.sqrt(P), ie = o.zeta * H, pe = se * Math.sqrt(2 - Math.SQRT2), be = se * Math.sqrt(2 + Math.SQRT2), Me = 2 * ie * pe * be / (pe + be), Be = 2 * ie / (pe + be), Ee = I[D] - T[D], de = Math.cos(Ee), K = Math.sin(Ee), ce = U[D], ue = F[D], Se = (Math.max(-8 * x.gravity, Math.min(8 * x.gravity, M[q])) - S * _ / oe) / R, ye = Me * (2 * ce + de * ue) + Be * 2 * P * ce, Le = Me * (de * ce + ue) + Be * P * ue, $e = -2 * P * Math.sin(I[D]) - K * ue * ue - 2 * Se * Math.cos(I[D]) - ye, nt = -P * Math.sin(T[D]) + K * ce * ce - Se * Math.cos(T[D]) - Le, rt = 2 - de * de;
|
|
1548
|
+
U[D] += ($e - de * nt) / rt * a, F[D] += (2 * nt - de * $e) / rt * a, I[D] += U[D] * a, T[D] += F[D] * a, C[D] += (-O * O * j[D] - 2 * O * C[D] - M[q + 1] * 0.15) * a, j[D] += C[D] * a;
|
|
1549
1549
|
}
|
|
1550
1550
|
}
|
|
1551
1551
|
for (let $ = 0; g > 0 && $ < J; $++) for (const Z of [I, U, T, F]) {
|
|
@@ -1554,14 +1554,14 @@ function wr(t, e) {
|
|
|
1554
1554
|
}
|
|
1555
1555
|
const k = ($, Z, _) => {
|
|
1556
1556
|
for (let D = 0; D < w; D++) {
|
|
1557
|
-
const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = N * 0.1 * Math.tanh(j[D] * _ / (N * 0.1)), R = 2 * Math.asin(Math.min(0.95, (N - Math.abs(S)) / (2 * oe))), P = R * Math.tanh(I[D] * _ / R),
|
|
1557
|
+
const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = N * 0.1 * Math.tanh(j[D] * _ / (N * 0.1)), R = 2 * Math.asin(Math.min(0.95, (N - Math.abs(S)) / (2 * oe))), P = R * Math.tanh(I[D] * _ / R), se = R * Math.tanh(T[D] * _ / R), ie = 0.1 * (1 - Q), pe = (L[ee] - L[q]) / 2, be = (L[ee + 1] - L[q + 1]) / 2, Me = Z[q] + pe * Math.cos(P) + be * Math.sin(P), Be = Z[q + 1] - pe * Math.sin(P) + be * Math.cos(P);
|
|
1558
1558
|
for (let Ee = 0; Ee < A; Ee++) {
|
|
1559
|
-
const de = Ee / (A - 1), K = (Ee * w + D) * 2, ce = de <= 0.5, ue = ce ? de * 2 : (de - 0.5) * 2, ke = (ce ? P :
|
|
1559
|
+
const de = Ee / (A - 1), K = (Ee * w + D) * 2, ce = de <= 0.5, ue = ce ? de * 2 : (de - 0.5) * 2, ke = (ce ? P : se) * (1 - ie + ie * ue), Se = Math.cos(ke), ye = Math.sin(ke), Le = pe * ue, $e = be * ue;
|
|
1560
1560
|
$[K] = (ce ? Z[q] : Me) + Le * Se + $e * ye, $[K + 1] = (ce ? Z[q + 1] : Be) - Le * ye + $e * Se + S * de;
|
|
1561
1561
|
}
|
|
1562
1562
|
}
|
|
1563
1563
|
};
|
|
1564
|
-
k(x.physicalOut,
|
|
1564
|
+
k(x.physicalOut, ae, 1), k(Y, V, te);
|
|
1565
1565
|
}
|
|
1566
1566
|
this.time += g;
|
|
1567
1567
|
}
|
|
@@ -1578,11 +1578,11 @@ function wr(t, e) {
|
|
|
1578
1578
|
}
|
|
1579
1579
|
return { Cloth: l, garments: u };
|
|
1580
1580
|
}
|
|
1581
|
-
function
|
|
1582
|
-
const { baseWeights: n, deformBase: r, MOUTH: o } =
|
|
1581
|
+
function Ar(e, t) {
|
|
1582
|
+
const { baseWeights: n, deformBase: r, MOUTH: o } = e, s = (w, A, L) => {
|
|
1583
1583
|
const z = Math.min(1, Math.max(0, (L - w) / (A - w)));
|
|
1584
1584
|
return z * z * (3 - 2 * z);
|
|
1585
|
-
}, i =
|
|
1585
|
+
}, i = t.mouth.area, u = {
|
|
1586
1586
|
a: { sprite: "mouth_a", ref: 0.9, width: 1 },
|
|
1587
1587
|
aHalf: { sprite: "mouth_a_half", ref: 0.55, width: 1 },
|
|
1588
1588
|
i: { sprite: "mouth_i", ref: 0.55, width: 1 },
|
|
@@ -1606,35 +1606,35 @@ function xr(t, e) {
|
|
|
1606
1606
|
function b(w) {
|
|
1607
1607
|
return o.cy + (w - o.cx) * Math.tan(o.angle);
|
|
1608
1608
|
}
|
|
1609
|
-
function
|
|
1609
|
+
function a() {
|
|
1610
1610
|
return i.cx;
|
|
1611
1611
|
}
|
|
1612
1612
|
function d(w, A) {
|
|
1613
1613
|
const L = Math.cos(-i.angle), z = Math.sin(-i.angle), Y = w - i.cx, I = A - i.cy, U = (Y * L - I * z) / i.rx, T = (Y * z + I * L) / i.ry;
|
|
1614
|
-
return 1 -
|
|
1614
|
+
return 1 - s(0.55, 0.95, Math.hypot(U, T));
|
|
1615
1615
|
}
|
|
1616
1616
|
function x(w, A, L, z, Y) {
|
|
1617
1617
|
const I = {}, U = (X) => X.startsWith("eyes_closed") || X.startsWith("eyes_smile"), T = (X) => v.some((G) => X === `mouth_${G}`), F = (X) => U(X) ? 1 : X.startsWith("eyes_") ? 0 : T(X) ? 2 : 3, j = Object.entries(A.layers).sort((X, G) => F(X[0]) - F(G[0]));
|
|
1618
1618
|
for (const [X, G] of j) {
|
|
1619
|
-
const re = z(G,
|
|
1619
|
+
const re = z(G, t.mesh.spriteCell, Y(L[X]), L[X].width), W = [], te = [];
|
|
1620
1620
|
for (let V = 0; V < re.rest.length / 2; V++) {
|
|
1621
1621
|
const M = re.rest[V * 2], E = re.rest[V * 2 + 1];
|
|
1622
1622
|
W.push(n(M, E, 0)), te.push(X.startsWith("mouth") ? d(M, E) : 0);
|
|
1623
1623
|
}
|
|
1624
|
-
const
|
|
1625
|
-
|
|
1624
|
+
const ae = w.addLayer(X, L[X], re, { color: [0.4, 1, 0.8, 0.6] });
|
|
1625
|
+
ae.visible = !1, I[X] = { mesh: re, W, inner: te, layer: ae };
|
|
1626
1626
|
}
|
|
1627
1627
|
const C = [0, 1].map((X) => !!(I[`eyes_closed_${X}`] && I[`eyes_half_${X}`])), B = Object.values(u).some((X) => I[X.sprite]), H = (X, G) => (X === "eyes_smile" && !I[`eyes_smile_${G}`] && (X = "eyes_closed"), X === "open" || I[`${X}_${G}`] ? X : "open"), N = [0, 0];
|
|
1628
1628
|
let ne = null;
|
|
1629
1629
|
const Q = [0, 1].map(() => ({ cur: "open", prev: "open", t: 1 }));
|
|
1630
1630
|
function J(X, G, re, W, te = 1) {
|
|
1631
|
-
const
|
|
1631
|
+
const ae = X.mesh.rest, V = X.mesh.pos;
|
|
1632
1632
|
for (let M = 0; M < X.W.length; M++) {
|
|
1633
|
-
let E =
|
|
1633
|
+
let E = ae[M * 2], O = ae[M * 2 + 1];
|
|
1634
1634
|
const k = X.inner[M];
|
|
1635
1635
|
if (k > 0) {
|
|
1636
1636
|
const $ = b(E);
|
|
1637
|
-
O = $ + (O - $) * (1 + (W - 1) * k), E =
|
|
1637
|
+
O = $ + (O - $) * (1 + (W - 1) * k), E = a() + (E - a()) * (1 + (te - 1) * k);
|
|
1638
1638
|
}
|
|
1639
1639
|
r(E, O, X.W[M], G, re, N), V[M * 2] = N[0], V[M * 2 + 1] = N[1];
|
|
1640
1640
|
}
|
|
@@ -1656,10 +1656,10 @@ function xr(t, e) {
|
|
|
1656
1656
|
].forEach(([k, $], Z) => {
|
|
1657
1657
|
const _ = Q[Z], D = h.includes(W) && I[`eyes_${W}_${Z}`] ? `eyes_${W}` : null, q = H(p(k, $, D) ?? "open", Z);
|
|
1658
1658
|
q !== _.cur && (_.prev = _.cur, _.cur = q, _.t = 0), _.t = re > 0 ? Math.min(1, _.t + re / f) : 1;
|
|
1659
|
-
const ee =
|
|
1659
|
+
const ee = s(0, 1, _.t), oe = (R, P) => {
|
|
1660
1660
|
if (R === "open" || P <= 1e-3) return;
|
|
1661
|
-
const
|
|
1662
|
-
|
|
1661
|
+
const se = I[`${R}_${Z}`];
|
|
1662
|
+
se && (se.layer.visible = !0, se.layer.alpha = P, J(se, X, G, 1));
|
|
1663
1663
|
}, S = (R) => R === "open" ? -1 : U(R) ? 1 : 0;
|
|
1664
1664
|
_.t >= 1 ? oe(_.cur, 1) : S(_.cur) > S(_.prev) ? (oe(_.prev, 1), oe(_.cur, ee)) : (oe(_.cur, 1), oe(_.prev, 1 - ee)), te[Z] = _.cur !== "open" && ee >= 0.999;
|
|
1665
1665
|
});
|
|
@@ -1667,7 +1667,7 @@ function xr(t, e) {
|
|
|
1667
1667
|
ne = V;
|
|
1668
1668
|
const M = V && u[V], E = M && I[M.sprite], O = v.includes(W) && I[`mouth_${W}`];
|
|
1669
1669
|
if (O && (!E || X.mouthOpen < y + 0.04) && (O.layer.visible = !0, O.layer.alpha = 1, J(O, X, G, 1)), E) {
|
|
1670
|
-
E.layer.visible = !0, E.layer.alpha =
|
|
1670
|
+
E.layer.visible = !0, E.layer.alpha = s(y, y + 0.04, X.mouthOpen);
|
|
1671
1671
|
const k = Math.min(1.1, Math.max(0.5, X.mouthOpen / M.ref));
|
|
1672
1672
|
J(E, X, G, k, M.width);
|
|
1673
1673
|
}
|
|
@@ -1679,37 +1679,37 @@ function xr(t, e) {
|
|
|
1679
1679
|
}
|
|
1680
1680
|
return { createSprites: x, mouthShape: g, eyeSprite: p };
|
|
1681
1681
|
}
|
|
1682
|
-
const
|
|
1683
|
-
function
|
|
1684
|
-
return
|
|
1682
|
+
const pn = { angry: "angry", angryTalk: "angry", sad: "sad", sadTalk: "sad", surprise: "surprise", surprisedTalk: "surprise" };
|
|
1683
|
+
function Er(e, t) {
|
|
1684
|
+
return e && e !== "neutral" ? pn[e] ?? null : (t && pn[t]) ?? null;
|
|
1685
1685
|
}
|
|
1686
|
-
function
|
|
1687
|
-
let o =
|
|
1686
|
+
function Sr(e, t, n, r = 6) {
|
|
1687
|
+
let o = t, s = n, i = -1, u = -1;
|
|
1688
1688
|
for (let m = 0; m < n; m++) {
|
|
1689
|
-
const l = m *
|
|
1690
|
-
for (let c = 0; c <
|
|
1691
|
-
|
|
1689
|
+
const l = m * t;
|
|
1690
|
+
for (let c = 0; c < t; c++)
|
|
1691
|
+
e[l + c] > 3 && (c < o && (o = c), c > i && (i = c), m < s && (s = m), m > u && (u = m));
|
|
1692
1692
|
}
|
|
1693
1693
|
if (i < 0) return null;
|
|
1694
|
-
const y = Math.max(0, o - r), v = Math.max(0,
|
|
1695
|
-
return [y, v, Math.min(
|
|
1694
|
+
const y = Math.max(0, o - r), v = Math.max(0, s - r);
|
|
1695
|
+
return [y, v, Math.min(t, i + 1 + r) - y, Math.min(n, u + 1 + r) - v];
|
|
1696
1696
|
}
|
|
1697
|
-
function
|
|
1697
|
+
function Or(e, t, n, r, o, s, i = 16, u, y, v) {
|
|
1698
1698
|
const m = /* @__PURE__ */ new Map();
|
|
1699
|
-
for (const l of
|
|
1699
|
+
for (const l of t.overlays) {
|
|
1700
1700
|
const c = n[l.name];
|
|
1701
1701
|
if (u !== void 0 && c.width !== u || y !== void 0 && c.height !== y)
|
|
1702
1702
|
throw new Error(`overlay ${l.name}: image size does not match base.png`);
|
|
1703
|
-
const f = o(c), h =
|
|
1703
|
+
const f = o(c), h = Sr(f, c.width, c.height);
|
|
1704
1704
|
if (!h) continue;
|
|
1705
|
-
const [p, g, b,
|
|
1706
|
-
for (let L = 0; L <
|
|
1705
|
+
const [p, g, b, a] = h, d = new Uint8Array(b * a);
|
|
1706
|
+
for (let L = 0; L < a; L++) d.set(f.subarray((g + L) * c.width + p, (g + L) * c.width + p + b), L * b);
|
|
1707
1707
|
const x = r(h, i, d, b), w = [];
|
|
1708
1708
|
for (let L = 0; L < x.rest.length; L += 2) {
|
|
1709
|
-
const z =
|
|
1709
|
+
const z = s(x.rest[L], x.rest[L + 1], 0);
|
|
1710
1710
|
w.push({ ...z, brow: 0, jaw: 0 });
|
|
1711
1711
|
}
|
|
1712
|
-
const A =
|
|
1712
|
+
const A = e.addLayer(`overlay_${l.name}`, v(c, h), x);
|
|
1713
1713
|
A.visible = !1, m.set(l.name, { mesh: x, weights: w, layer: A });
|
|
1714
1714
|
}
|
|
1715
1715
|
return {
|
|
@@ -1721,55 +1721,55 @@ function Er(t, e, n, r, o, a, i = 16, u, y, v) {
|
|
|
1721
1721
|
update(l, c, f, h) {
|
|
1722
1722
|
for (const { mesh: p, weights: g, layer: b } of m.values())
|
|
1723
1723
|
if (b.visible)
|
|
1724
|
-
for (let
|
|
1725
|
-
f(p.rest[
|
|
1724
|
+
for (let a = 0; a < g.length; a++)
|
|
1725
|
+
f(p.rest[a * 2], p.rest[a * 2 + 1], g[a], l, c, h), p.pos[a * 2] = h[0], p.pos[a * 2 + 1] = h[1];
|
|
1726
1726
|
}
|
|
1727
1727
|
};
|
|
1728
1728
|
}
|
|
1729
|
-
function
|
|
1730
|
-
if (!
|
|
1731
|
-
const
|
|
1729
|
+
function tn(e) {
|
|
1730
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError("lipSync: expected an object");
|
|
1731
|
+
const t = e, n = {};
|
|
1732
1732
|
for (const r of ["granularity", "openness", "closeSpeed"]) {
|
|
1733
|
-
const o =
|
|
1733
|
+
const o = t[r];
|
|
1734
1734
|
if (o !== void 0) {
|
|
1735
1735
|
if (typeof o != "number" || !Number.isFinite(o) || o < 0 || o > 1)
|
|
1736
1736
|
throw new RangeError(`lipSync.${r}: expected 0–1`);
|
|
1737
1737
|
n[r] = o;
|
|
1738
1738
|
}
|
|
1739
1739
|
}
|
|
1740
|
-
if (
|
|
1741
|
-
if (!["calm", "default", "lively", "subtle", "big", "custom"].includes(
|
|
1740
|
+
if (t.preset !== void 0) {
|
|
1741
|
+
if (!["calm", "default", "lively", "subtle", "big", "custom"].includes(t.preset))
|
|
1742
1742
|
throw new RangeError("lipSync.preset: expected calm, default, lively, subtle, big or custom");
|
|
1743
|
-
n.preset =
|
|
1743
|
+
n.preset = t.preset;
|
|
1744
1744
|
}
|
|
1745
1745
|
return n;
|
|
1746
1746
|
}
|
|
1747
|
-
function
|
|
1747
|
+
function dn(e = {}, t = {
|
|
1748
1748
|
granularity: 0.5,
|
|
1749
1749
|
openness: 0.5,
|
|
1750
1750
|
closeSpeed: 0.5
|
|
1751
1751
|
}) {
|
|
1752
|
-
const n =
|
|
1752
|
+
const n = tn(e);
|
|
1753
1753
|
return {
|
|
1754
|
-
granularity: n.granularity ??
|
|
1755
|
-
openness: n.openness ??
|
|
1756
|
-
closeSpeed: n.closeSpeed ??
|
|
1754
|
+
granularity: n.granularity ?? t.granularity,
|
|
1755
|
+
openness: n.openness ?? t.openness,
|
|
1756
|
+
closeSpeed: n.closeSpeed ?? t.closeSpeed
|
|
1757
1757
|
};
|
|
1758
1758
|
}
|
|
1759
|
-
const Pe = (
|
|
1760
|
-
function
|
|
1759
|
+
const Pe = (e, t, n, r) => e === 0.5 ? n : e < 0.5 ? t + (n - t) * e * 2 : n + (r - n) * (e - 0.5) * 2;
|
|
1760
|
+
function gn(e) {
|
|
1761
1761
|
return {
|
|
1762
|
-
arm: Pe(
|
|
1763
|
-
trigger: Pe(
|
|
1764
|
-
relax: Pe(
|
|
1765
|
-
range: Pe(
|
|
1766
|
-
risePower: Pe(
|
|
1767
|
-
openness: Pe(
|
|
1768
|
-
audioRelease: Pe(
|
|
1769
|
-
kanaRelease: Pe(
|
|
1762
|
+
arm: Pe(e.granularity, 0.2, 0.6, 0.9),
|
|
1763
|
+
trigger: Pe(e.granularity, 0.65, 0.8, 0.95),
|
|
1764
|
+
relax: Pe(e.granularity, 1.5, 5, 12),
|
|
1765
|
+
range: Pe(e.granularity, 0.7, 0.3, 0.05),
|
|
1766
|
+
risePower: Pe(e.granularity, 0.05, 0.3, 0.8),
|
|
1767
|
+
openness: Pe(e.openness, 0.55, 1, 1.25),
|
|
1768
|
+
audioRelease: Pe(e.closeSpeed, 6, 32, 45),
|
|
1769
|
+
kanaRelease: Pe(e.closeSpeed, 6, 22, 45)
|
|
1770
1770
|
};
|
|
1771
1771
|
}
|
|
1772
|
-
const
|
|
1772
|
+
const Tr = /* @__PURE__ */ new Set([
|
|
1773
1773
|
"angleX",
|
|
1774
1774
|
"angleY",
|
|
1775
1775
|
"angleZ",
|
|
@@ -1779,7 +1779,7 @@ const Sr = /* @__PURE__ */ new Set([
|
|
|
1779
1779
|
"handAngle",
|
|
1780
1780
|
"gazeX",
|
|
1781
1781
|
"gazeY"
|
|
1782
|
-
]),
|
|
1782
|
+
]), nn = {
|
|
1783
1783
|
nod: {
|
|
1784
1784
|
label: "Nod",
|
|
1785
1785
|
dur: 1.7,
|
|
@@ -1927,7 +1927,7 @@ const Sr = /* @__PURE__ */ new Set([
|
|
|
1927
1927
|
blush: [[0, 0], [1.6, 0.3], [2.6, 0]]
|
|
1928
1928
|
}
|
|
1929
1929
|
}
|
|
1930
|
-
},
|
|
1930
|
+
}, rn = {
|
|
1931
1931
|
lookAround: {
|
|
1932
1932
|
label: "Look around",
|
|
1933
1933
|
dur: 5.2,
|
|
@@ -2167,14 +2167,14 @@ const Sr = /* @__PURE__ */ new Set([
|
|
|
2167
2167
|
}
|
|
2168
2168
|
}
|
|
2169
2169
|
};
|
|
2170
|
-
function
|
|
2171
|
-
if (
|
|
2172
|
-
const n =
|
|
2173
|
-
if (
|
|
2170
|
+
function Rr(e, t) {
|
|
2171
|
+
if (t <= e[0][0]) return e[0][1];
|
|
2172
|
+
const n = e.length - 1;
|
|
2173
|
+
if (t >= e[n][0]) return e[n][1];
|
|
2174
2174
|
let r = 0;
|
|
2175
|
-
for (;
|
|
2176
|
-
const [o,
|
|
2177
|
-
return (2 * h - 3 * f + 1) *
|
|
2175
|
+
for (; t > e[r + 1][0]; ) r++;
|
|
2176
|
+
const [o, s] = e[r], [i, u] = e[r + 1], y = (p) => p <= 0 || p >= n ? 0 : (e[p + 1][1] - e[p - 1][1]) / (e[p + 1][0] - e[p - 1][0]), v = i - o, m = (t - o) / v, l = y(r) * v, c = y(r + 1) * v, f = m * m, h = f * m;
|
|
2177
|
+
return (2 * h - 3 * f + 1) * s + (h - 2 * f + m) * l + (-2 * h + 3 * f) * u + (h - f) * c;
|
|
2178
2178
|
}
|
|
2179
2179
|
const pt = {
|
|
2180
2180
|
a: { open: 0.9, form: 0, label: "あ" },
|
|
@@ -2184,70 +2184,70 @@ const pt = {
|
|
|
2184
2184
|
o: { open: 0.75, form: 0.6, label: "お" },
|
|
2185
2185
|
n: { open: 0, form: null, label: "ん" }
|
|
2186
2186
|
// closes with the previous shape
|
|
2187
|
-
},
|
|
2187
|
+
}, kr = {
|
|
2188
2188
|
a: "あかさたなはまやらわがざだばぱぁ",
|
|
2189
2189
|
i: "いきしちにひみりぎじぢびぴぃ",
|
|
2190
2190
|
u: "うくすつぬふむゆるぐずづぶぷぅゔ",
|
|
2191
2191
|
e: "えけせてねへめれげぜでべぺぇ",
|
|
2192
2192
|
o: "おこそとのほもよろをごぞどぼぽぉ"
|
|
2193
|
-
},
|
|
2194
|
-
for (const [
|
|
2195
|
-
const
|
|
2196
|
-
function
|
|
2193
|
+
}, Bn = {};
|
|
2194
|
+
for (const [e, t] of Object.entries(kr)) for (const n of t) Bn[n] = e;
|
|
2195
|
+
const Lr = /* @__PURE__ */ new Set([..."まみむめもばびぶべぼぱぴぷぺぽ"]), _r = /* @__PURE__ */ new Set([..."あいうえおぁぃぅぇぉ"]), yn = { ゃ: "a", ゅ: "u", ょ: "o" }, Fr = /* @__PURE__ */ new Set([..."、。,.,.!?!? …"]), jr = (e) => e.replace(/[ァ-ヶ]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 96));
|
|
2196
|
+
function Br(e, t = 0.14) {
|
|
2197
2197
|
const n = [];
|
|
2198
|
-
for (const r of
|
|
2198
|
+
for (const r of jr(e)) {
|
|
2199
2199
|
const o = n[n.length - 1];
|
|
2200
|
-
if (
|
|
2201
|
-
o.vowel =
|
|
2200
|
+
if (yn[r] && o) {
|
|
2201
|
+
o.vowel = yn[r];
|
|
2202
2202
|
continue;
|
|
2203
2203
|
}
|
|
2204
2204
|
if (r === "ー" && o) {
|
|
2205
|
-
o.dur +=
|
|
2205
|
+
o.dur += t;
|
|
2206
2206
|
continue;
|
|
2207
2207
|
}
|
|
2208
2208
|
if (r === "っ") {
|
|
2209
|
-
n.push({ vowel: "n", dur:
|
|
2209
|
+
n.push({ vowel: "n", dur: t * 0.8, onset: null });
|
|
2210
2210
|
continue;
|
|
2211
2211
|
}
|
|
2212
2212
|
if (r === "ん") {
|
|
2213
|
-
n.push({ vowel: "n", dur:
|
|
2213
|
+
n.push({ vowel: "n", dur: t, onset: null });
|
|
2214
2214
|
continue;
|
|
2215
2215
|
}
|
|
2216
|
-
if (
|
|
2217
|
-
n.push({ vowel: "n", dur:
|
|
2216
|
+
if (Fr.has(r)) {
|
|
2217
|
+
n.push({ vowel: "n", dur: t * 2.2, onset: null });
|
|
2218
2218
|
continue;
|
|
2219
2219
|
}
|
|
2220
|
-
const
|
|
2221
|
-
|
|
2220
|
+
const s = Bn[r];
|
|
2221
|
+
s && n.push({ vowel: s, dur: t, onset: Lr.has(r) ? "lips" : _r.has(r) ? null : "consonant" });
|
|
2222
2222
|
}
|
|
2223
2223
|
return n;
|
|
2224
2224
|
}
|
|
2225
|
-
function
|
|
2226
|
-
if (n !== 0.5) return
|
|
2225
|
+
function $r(e, t, n = 0.5) {
|
|
2226
|
+
if (n !== 0.5) return Ur(e, t, n);
|
|
2227
2227
|
let r = 0;
|
|
2228
|
-
for (const o of
|
|
2229
|
-
if (
|
|
2230
|
-
const
|
|
2228
|
+
for (const o of e) {
|
|
2229
|
+
if (t < r + o.dur) {
|
|
2230
|
+
const s = (t - r) / o.dur, i = pt[o.vowel], u = o.onset === "lips" ? 0.05 : o.onset === "consonant" ? 0.45 : 1, y = s < 0.35 ? u + (1 - u) * (s / 0.35) : 1;
|
|
2231
2231
|
return { open: i.open * y, form: i.form, vowel: o.vowel };
|
|
2232
2232
|
}
|
|
2233
2233
|
r += o.dur;
|
|
2234
2234
|
}
|
|
2235
2235
|
return null;
|
|
2236
2236
|
}
|
|
2237
|
-
function
|
|
2237
|
+
function Ur(e, t, n) {
|
|
2238
2238
|
const r = n < 0.5 ? (0.5 - n) * 0.72 : 0;
|
|
2239
|
-
let o = 0,
|
|
2240
|
-
for (const u of
|
|
2239
|
+
let o = 0, s = 0, i = null;
|
|
2240
|
+
for (const u of e) {
|
|
2241
2241
|
let y = u.vowel;
|
|
2242
|
-
if (u.vowel === "n" ? r && u.dur <= 0.2 && i ? y = i : (
|
|
2243
|
-
const v = pt[y], m = u.onset === "lips" ? 0.05 : u.onset === "consonant" ? 0.45 : 1, l = n < 0.5 ? 1 - (1 - m) * n * 2 : m * (2 - n * 2), c = Math.min(u.dur * 0.35, 0.05), f = (
|
|
2242
|
+
if (u.vowel === "n" ? r && u.dur <= 0.2 && i ? y = i : (s = 0, i = null) : ((!i || s >= r) && (i = u.vowel, s = 0), s += u.dur, r && (y = i)), t < o + u.dur) {
|
|
2243
|
+
const v = pt[y], m = u.onset === "lips" ? 0.05 : u.onset === "consonant" ? 0.45 : 1, l = n < 0.5 ? 1 - (1 - m) * n * 2 : m * (2 - n * 2), c = Math.min(u.dur * 0.35, 0.05), f = (t - o) / c;
|
|
2244
2244
|
return { open: v.open * (f < 1 ? l + (1 - l) * f : 1), form: v.form, vowel: y };
|
|
2245
2245
|
}
|
|
2246
2246
|
o += u.dur;
|
|
2247
2247
|
}
|
|
2248
2248
|
return null;
|
|
2249
2249
|
}
|
|
2250
|
-
const
|
|
2250
|
+
const jt = { ...nn, ...rn }, vn = { amp: 1, stiff: 1.8 }, Yr = /^(angle|bodyAngle|armAngle|handAngle)/, Ir = /* @__PURE__ */ new Set([
|
|
2251
2251
|
"eyeOpen",
|
|
2252
2252
|
"eyeOpenL",
|
|
2253
2253
|
"eyeSmileL",
|
|
@@ -2257,18 +2257,18 @@ const Ft = { ...tn, ...nn }, yn = { amp: 1, stiff: 1.8 }, $r = /^(angle|bodyAngl
|
|
|
2257
2257
|
"blush",
|
|
2258
2258
|
"browY",
|
|
2259
2259
|
"browAngle"
|
|
2260
|
-
]), xt = (
|
|
2261
|
-
const r = Math.min(1, Math.max(0, (n -
|
|
2260
|
+
]), xt = (e, t, n) => {
|
|
2261
|
+
const r = Math.min(1, Math.max(0, (n - e) / (t - e)));
|
|
2262
2262
|
return r * r * (3 - 2 * r);
|
|
2263
2263
|
};
|
|
2264
|
-
function
|
|
2265
|
-
const n = Math.floor(
|
|
2266
|
-
const u = Math.sin((i +
|
|
2264
|
+
function bn(e, t) {
|
|
2265
|
+
const n = Math.floor(e), r = e - n, o = (i) => {
|
|
2266
|
+
const u = Math.sin((i + t * 57.3) * 127.1) * 43758.5453;
|
|
2267
2267
|
return u - Math.floor(u);
|
|
2268
|
-
},
|
|
2269
|
-
return (o(n) * (1 -
|
|
2268
|
+
}, s = r * r * (3 - 2 * r);
|
|
2269
|
+
return (o(n) * (1 - s) + o(n + 1) * s) * 2 - 1;
|
|
2270
2270
|
}
|
|
2271
|
-
const ze = (
|
|
2271
|
+
const ze = (e, t) => bn(e, t) * 0.7 + bn(e * 2.3, t + 9) * 0.3, Te = (e, t, n) => Math.max(t, Math.min(n, e)), $n = {
|
|
2272
2272
|
normal: { label: "Neutral", p: {} },
|
|
2273
2273
|
smile: { label: "Smile", p: { eyeOpen: 0, eyeSmile: 1, blush: 0.35, browY: 0.2 } },
|
|
2274
2274
|
shy: { label: "Blush", p: { eyeOpen: 0.78, eyeSmile: 0.5, blush: 1, browAngle: -0.5, browY: -0.1, glance: [0.7, 0.35] } },
|
|
@@ -2282,14 +2282,14 @@ const ze = (t, e) => vn(t, e) * 0.7 + vn(t * 2.3, e + 9) * 0.3, Te = (t, e, n) =
|
|
|
2282
2282
|
angryTalk: { label: "angry", p: { eyeOpen: 0.72, browAngle: 0.85, browY: -0.55, mouthForm: 0.2 } },
|
|
2283
2283
|
surprisedTalk: { label: "surprised", p: { eyeOpen: 1.18, browY: 0.9, mouthForm: 0.9 } },
|
|
2284
2284
|
relaxedTalk: { label: "relaxed", p: { eyeOpen: 0.82, eyeSmile: 0.35, blush: 0.15, browY: 0.1 } }
|
|
2285
|
-
},
|
|
2285
|
+
}, wn = {
|
|
2286
2286
|
happy: ["happyTalk", "nod"],
|
|
2287
2287
|
sad: ["sadTalk", "sigh"],
|
|
2288
2288
|
angry: ["angryTalk", "no"],
|
|
2289
2289
|
surprised: ["surprisedTalk", "surprise"],
|
|
2290
2290
|
relaxed: ["relaxedTalk", "sway"],
|
|
2291
2291
|
neutral: ["normal", null]
|
|
2292
|
-
},
|
|
2292
|
+
}, Nr = {
|
|
2293
2293
|
gazeX: [260, 0.9],
|
|
2294
2294
|
gazeY: [260, 0.9],
|
|
2295
2295
|
angleX: [55, 0.72],
|
|
@@ -2301,47 +2301,47 @@ const ze = (t, e) => vn(t, e) * 0.7 + vn(t * 2.3, e + 9) * 0.3, Te = (t, e, n) =
|
|
|
2301
2301
|
armAngle: [20, 0.85],
|
|
2302
2302
|
handAngle: [30, 0.8]
|
|
2303
2303
|
};
|
|
2304
|
-
function
|
|
2305
|
-
const n = (
|
|
2306
|
-
if (
|
|
2307
|
-
const i =
|
|
2304
|
+
function Xr(e) {
|
|
2305
|
+
const n = (e + 0.45) % 5, r = n < 2.5 ? -0.7 : 0.7, o = -r, s = n % 2.5;
|
|
2306
|
+
if (s >= 0.9) return o;
|
|
2307
|
+
const i = s / 0.9, u = i * i * i * (10 + i * (-15 + 6 * i));
|
|
2308
2308
|
return r + (o - r) * u;
|
|
2309
2309
|
}
|
|
2310
|
-
class
|
|
2310
|
+
class zr {
|
|
2311
2311
|
/** @param {number[]} gazeCenter @param {boolean} [planted] @param {import('../rig/types').Rig|null} [armRig] */
|
|
2312
|
-
constructor(
|
|
2313
|
-
this.armRig = r, this.armFollow = 0, this.armVelocity = 0, this.planted = n, this.mode = "auto", this.P = Object.fromEntries(bt.map((o) => [o.id, o.def])), this.manual = { ...this.P }, this.cur = { ...this.P }, this.vel = Object.fromEntries(bt.map((o) => [o.id, 0])), this.expr = "normal", this.exprMix = {}, this.t = 0, this.blink = { t: 0, start: 1.5, double: !1 }, this.gaze = { x: 0, y: 0, next: 0 }, this.tap = { next: 4, until: -1 }, this.pointer = null, this.faceCenter = [...
|
|
2312
|
+
constructor(t, n = !1, r = null) {
|
|
2313
|
+
this.armRig = r, this.armFollow = 0, this.armVelocity = 0, this.planted = n, this.mode = "auto", this.P = Object.fromEntries(bt.map((o) => [o.id, o.def])), this.manual = { ...this.P }, this.cur = { ...this.P }, this.vel = Object.fromEntries(bt.map((o) => [o.id, 0])), this.expr = "normal", this.exprMix = {}, this.t = 0, this.blink = { t: 0, start: 1.5, double: !1 }, this.gaze = { x: 0, y: 0, next: 0 }, this.tap = { next: 4, until: -1 }, this.pointer = null, this.faceCenter = [...t], this.lipOpen = null, this.lipForm = 0, this.speaking = !1, this.voice = 0, this.mouth = 0, this.vowel = "a", this.vowelForm = 0, this.lipSync = dn(), this.lipMotion = gn(this.lipSync), this.syllableArmed = !0, this.voicePeak = 0, this.voiceTrough = 0, this.kana = null, this.lipHold = null, this.emotionUntil = 0, this.talkGain = 1, this.play = null, this.autoMotion = !0, this.nextAuto = 14, this.autoIdle = !0, this.nextIdle = 3, this.lastAuto = null, this.onMotion = null;
|
|
2314
2314
|
}
|
|
2315
|
-
setExpression(
|
|
2316
|
-
this.expr =
|
|
2315
|
+
setExpression(t) {
|
|
2316
|
+
this.expr = t;
|
|
2317
2317
|
}
|
|
2318
|
-
hasMotion(
|
|
2319
|
-
return
|
|
2318
|
+
hasMotion(t) {
|
|
2319
|
+
return t in jt;
|
|
2320
2320
|
}
|
|
2321
2321
|
// ---- speech (driven from outside, e.g. by the TTS audio analyser) ----
|
|
2322
|
-
setVoiceLevel(
|
|
2323
|
-
this.voice = Math.min(1, Math.max(0, Number(
|
|
2322
|
+
setVoiceLevel(t) {
|
|
2323
|
+
this.voice = Math.min(1, Math.max(0, Number(t) || 0));
|
|
2324
2324
|
}
|
|
2325
|
-
setLipSync(
|
|
2326
|
-
this.lipSync =
|
|
2325
|
+
setLipSync(t) {
|
|
2326
|
+
this.lipSync = dn(t, this.lipSync), this.lipMotion = gn(this.lipSync);
|
|
2327
2327
|
}
|
|
2328
|
-
setSpeaking(
|
|
2329
|
-
|
|
2328
|
+
setSpeaking(t) {
|
|
2329
|
+
t !== this.speaking && (this.speaking = !!t, t || (this.emotionUntil = this.t + 1.2, this.voice = 0));
|
|
2330
2330
|
}
|
|
2331
2331
|
/** `playMotion: false` changes only the face (a caller that picks motions itself). */
|
|
2332
|
-
setEmotion(
|
|
2333
|
-
const r =
|
|
2332
|
+
setEmotion(t, { playMotion: n = !0 } = {}) {
|
|
2333
|
+
const r = wn[t] ?? wn.neutral;
|
|
2334
2334
|
this.expr = r[0], this.emotionUntil = 1 / 0, r[1] && n && this.playMotion(r[1]);
|
|
2335
2335
|
}
|
|
2336
2336
|
/** Mouth shapes from kana text, without audio (preview / tuning). */
|
|
2337
2337
|
/** @param {string} text @param {{ speed?: number, loop?: boolean }} [options] */
|
|
2338
|
-
speakKana(
|
|
2338
|
+
speakKana(t, { speed: n, loop: r = !1 } = {}) {
|
|
2339
2339
|
this.lipHold = null;
|
|
2340
|
-
const o =
|
|
2341
|
-
this.kana = o.length ? { moras: o, t: 0, loop: r, duration: o.reduce((
|
|
2340
|
+
const o = Br(t, n === void 0 ? 0.14 : 1 / Te(Number(n) || 7, 4, 12));
|
|
2341
|
+
this.kana = o.length ? { moras: o, t: 0, loop: r, duration: o.reduce((s, i) => s + i.dur, 0) } : null;
|
|
2342
2342
|
}
|
|
2343
|
-
holdMouth(
|
|
2344
|
-
this.kana = null, this.lipHold = Object.hasOwn(pt,
|
|
2343
|
+
holdMouth(t) {
|
|
2344
|
+
this.kana = null, this.lipHold = Object.hasOwn(pt, t) ? t : null;
|
|
2345
2345
|
}
|
|
2346
2346
|
stopLipSync() {
|
|
2347
2347
|
this.kana = null, this.lipHold = null, this.lipOpen = null, this.mouth = 0;
|
|
@@ -2355,15 +2355,15 @@ class Nr {
|
|
|
2355
2355
|
// Syllables are found relative to the recent peak (not an absolute level), and the mouth
|
|
2356
2356
|
// is scaled by where the voice sits between the recent trough and peak, so it closes in
|
|
2357
2357
|
// the dip before each mora even when a loud voice never gets quiet.
|
|
2358
|
-
speechMouth(
|
|
2358
|
+
speechMouth(t) {
|
|
2359
2359
|
if (this.kana || this.lipHold) {
|
|
2360
2360
|
let c;
|
|
2361
|
-
if (this.lipHold ? c = pt[this.lipHold] : (this.kana.t +=
|
|
2362
|
-
return this.kana = null, this.mouth > 0.01 ? [this.mouth *= this.lipSync.closeSpeed === 0.5 ? 0.6 : Math.exp(-
|
|
2363
|
-
const f = this.lipMotion.openness === 1 ? c.open : Math.min(1, c.open * this.lipMotion.openness), h = f > this.mouth ? 1 - Math.exp(-
|
|
2361
|
+
if (this.lipHold ? c = pt[this.lipHold] : (this.kana.t += t, this.kana.loop && (this.kana.t %= this.kana.duration), c = $r(this.kana.moras, this.kana.t, this.lipSync.granularity)), !c)
|
|
2362
|
+
return this.kana = null, this.mouth > 0.01 ? [this.mouth *= this.lipSync.closeSpeed === 0.5 ? 0.6 : Math.exp(-t * this.lipMotion.kanaRelease), this.vowelForm] : null;
|
|
2363
|
+
const f = this.lipMotion.openness === 1 ? c.open : Math.min(1, c.open * this.lipMotion.openness), h = f > this.mouth ? 1 - Math.exp(-t * 30) : 1 - Math.exp(-t * this.lipMotion.kanaRelease);
|
|
2364
2364
|
return this.mouth += (f - this.mouth) * h, c.form !== null && (this.vowelForm = c.form), [this.mouth, this.vowelForm];
|
|
2365
2365
|
}
|
|
2366
|
-
const n = this.speaking ? this.voice : 0, r = 1 - Math.exp(-
|
|
2366
|
+
const n = this.speaking ? this.voice : 0, r = 1 - Math.exp(-t * this.lipMotion.relax);
|
|
2367
2367
|
this.voicePeak = n > this.voicePeak ? n : this.voicePeak + (n - this.voicePeak) * r, this.voiceTrough = n < this.voiceTrough ? n : this.voiceTrough + (n - this.voiceTrough) * r;
|
|
2368
2368
|
const o = Math.max(this.voicePeak, 0.05);
|
|
2369
2369
|
if (n < o * this.lipMotion.arm) this.syllableArmed = !0;
|
|
@@ -2372,70 +2372,70 @@ class Nr {
|
|
|
2372
2372
|
const c = Math.random();
|
|
2373
2373
|
this.vowel = c < 0.4 ? "a" : c < 0.58 ? "o" : c < 0.74 ? "e" : c < 0.88 ? "i" : "u";
|
|
2374
2374
|
}
|
|
2375
|
-
const
|
|
2375
|
+
const s = this.voicePeak - this.voiceTrough, i = s < o * this.lipMotion.range ? 1 : Math.max(0, (n - this.voiceTrough) / s), u = pt[this.vowel ?? "a"], y = Math.min(1, Math.pow(n, 0.7) * 1.15) * Math.pow(i, this.lipMotion.risePower), v = this.speaking ? Math.min(0.95, y) * (0.45 + 0.55 * u.open / 0.9) : 0, m = this.lipMotion.openness === 1 ? v : Math.min(1, v * this.lipMotion.openness), l = m > this.mouth ? 1 - Math.exp(-t * 40) : 1 - Math.exp(-t * this.lipMotion.audioRelease);
|
|
2376
2376
|
return this.mouth += (m - this.mouth) * l, this.speaking && (this.vowelForm = u.form), this.speaking || this.mouth > 0.01 ? [this.mouth, this.vowelForm] : null;
|
|
2377
2377
|
}
|
|
2378
2378
|
// Breathing: inhale ~40% of the cycle, a slower exhale, a short pause at the bottom,
|
|
2379
2379
|
// and a period that drifts between ~3.2 and 4.6 s so it never looks metronomic.
|
|
2380
|
-
breathValue(
|
|
2381
|
-
this.breathPhase = (this.breathPhase ?? 0) +
|
|
2380
|
+
breathValue(t) {
|
|
2381
|
+
this.breathPhase = (this.breathPhase ?? 0) + t / (this.breathPeriod ?? 3.8), this.breathPhase >= 1 && (this.breathPhase -= 1, this.breathPeriod = 3.2 + Math.random() * 1.4);
|
|
2382
2382
|
const n = this.breathPhase;
|
|
2383
2383
|
return n < 0.4 ? xt(0, 0.4, n) : n < 0.88 ? 1 - xt(0.4, 0.88, n) : 0;
|
|
2384
2384
|
}
|
|
2385
2385
|
// pick one at random, never the one that just played
|
|
2386
|
-
playRandom(
|
|
2387
|
-
const n =
|
|
2386
|
+
playRandom(t) {
|
|
2387
|
+
const n = t.filter((r) => r !== this.lastAuto);
|
|
2388
2388
|
this.playMotion(n[Math.floor(Math.random() * n.length)]);
|
|
2389
2389
|
}
|
|
2390
|
-
playMotion(
|
|
2391
|
-
this.lastAuto =
|
|
2390
|
+
playMotion(t) {
|
|
2391
|
+
this.lastAuto = t, this.play = { id: t, t: 0 }, this.onMotion?.(t);
|
|
2392
2392
|
}
|
|
2393
|
-
blinkValue(
|
|
2393
|
+
blinkValue(t) {
|
|
2394
2394
|
const n = this.blink;
|
|
2395
|
-
if (n.t +=
|
|
2395
|
+
if (n.t += t, n.t < n.start) return 1;
|
|
2396
2396
|
const r = (n.t - n.start) / 0.17;
|
|
2397
2397
|
return r >= 1 ? (n.double ? (n.double = !1, n.start = n.t + 0.07) : (n.start = n.t + 1.8 + Math.random() * 4.2, n.double = Math.random() < 0.18), 1) : r < 0.45 ? 1 - r / 0.45 : (r - 0.45) / 0.55;
|
|
2398
2398
|
}
|
|
2399
|
-
update(
|
|
2400
|
-
this.t +=
|
|
2399
|
+
update(t) {
|
|
2400
|
+
this.t += t;
|
|
2401
2401
|
const n = this.t, r = {};
|
|
2402
2402
|
for (const h of bt) r[h.id] = h.def;
|
|
2403
2403
|
if (this.mode === "manual")
|
|
2404
2404
|
Object.assign(r, this.manual);
|
|
2405
2405
|
else if (this.mode === "auto") {
|
|
2406
|
-
if (r.angleX = ze(n * 0.18, 1) * 10 + this.gaze.x * 11, r.angleY = ze(n * 0.15, 2) * 6 - 1 + this.gaze.y * 7, r.angleZ = ze(n * 0.12, 3) * 10, r.bodyAngleX = ze(n * 0.1, 4) * 5 * (this.planted ? 0.35 : 1), r.bodyAngleZ = ze(n * 0.09, 5) * 4 * (this.planted ? 0.35 : 1), r.weightShift = this.planted ?
|
|
2406
|
+
if (r.angleX = ze(n * 0.18, 1) * 10 + this.gaze.x * 11, r.angleY = ze(n * 0.15, 2) * 6 - 1 + this.gaze.y * 7, r.angleZ = ze(n * 0.12, 3) * 10, r.bodyAngleX = ze(n * 0.1, 4) * 5 * (this.planted ? 0.35 : 1), r.bodyAngleZ = ze(n * 0.09, 5) * 4 * (this.planted ? 0.35 : 1), r.weightShift = this.planted ? Xr(n) : 0.7 * Math.sin(n * Math.PI * 2 / 5), r.armAngle = ze(n * 0.14, 6) * 5, r.handAngle = ze(n * 0.21, 7) * 5, n > this.gaze.next) {
|
|
2407
2407
|
const h = Math.random();
|
|
2408
2408
|
this.gaze.x = h < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.8, this.gaze.y = h < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.5, this.gaze.next = n + 0.8 + Math.random() * 2.5;
|
|
2409
2409
|
}
|
|
2410
2410
|
if (r.gazeX = this.gaze.x + r.angleX / 60, r.gazeY = this.gaze.y + r.angleY / 60, n > this.tap.next && (this.tap.until = n + 1.1, this.tap.next = n + 5 + Math.random() * 6), this.speaking) {
|
|
2411
2411
|
this.nextIdle = Math.max(this.nextIdle, n + 2.5), this.nextAuto = Math.max(this.nextAuto, n + 6);
|
|
2412
2412
|
const h = this.talkGain;
|
|
2413
|
-
this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 * h - (this.talkNod ?? 0)) * Math.min(1,
|
|
2413
|
+
this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 * h - (this.talkNod ?? 0)) * Math.min(1, t * 6), r.angleY -= this.talkNod, r.angleX += ze(n * 0.6, 11) * 5 * h, r.angleZ += ze(n * 0.5, 12) * 4 * h;
|
|
2414
2414
|
}
|
|
2415
|
-
!this.speaking && n > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && n > this.nextAuto ? (this.playRandom(Object.keys(
|
|
2415
|
+
!this.speaking && n > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && n > this.nextAuto ? (this.playRandom(Object.keys(nn).filter((h) => h !== "surprise")), this.nextAuto = n + 15 + Math.random() * 10, this.nextIdle = Math.max(this.nextIdle, n + 5)) : !this.play && this.autoIdle && n > this.nextIdle && (this.playRandom(Object.keys(rn)), this.nextIdle = n + 5 + Math.random() * 5));
|
|
2416
2416
|
} else if (this.mode === "mouse" && this.pointer) {
|
|
2417
2417
|
const h = (this.pointer[0] - this.faceCenter[0]) / 500, p = (this.pointer[1] - this.faceCenter[1]) / 500;
|
|
2418
2418
|
r.angleX = Te(h * 30, -30, 30), r.angleY = Te(-p * 30, -30, 30), r.angleZ = Te(-h * p * 25, -12, 12), r.bodyAngleX = Te(h * 10, -10, 10) * 0.6, r.gazeX = Te(h * 1.4, -1, 1), r.gazeY = Te(-p * 1.4, -1, 1), r.handAngle = Te(h * 4, -5, 5);
|
|
2419
2419
|
}
|
|
2420
|
-
this.mode !== "manual" && (r.breath = this.breathValue(
|
|
2421
|
-
let o = null,
|
|
2420
|
+
this.mode !== "manual" && (r.breath = this.breathValue(t), n < this.tap.until && (r.fingerTap = Math.max(0, Math.sin((this.tap.until - n) * Math.PI * 3.6)) ** 2));
|
|
2421
|
+
let o = null, s = 0;
|
|
2422
2422
|
if (this.play) {
|
|
2423
|
-
const h =
|
|
2424
|
-
if (this.play.t +=
|
|
2423
|
+
const h = jt[this.play.id];
|
|
2424
|
+
if (this.play.t += t, this.play.t >= h.dur)
|
|
2425
2425
|
this.play = null, this.onMotion?.(null);
|
|
2426
2426
|
else {
|
|
2427
2427
|
o = {};
|
|
2428
2428
|
for (const [p, g] of Object.entries(h.tracks))
|
|
2429
|
-
o[p] =
|
|
2430
|
-
|
|
2429
|
+
o[p] = Rr(g, this.play.t) * (h.idle && Yr.test(p) ? vn.amp : 1);
|
|
2430
|
+
s = xt(0, 0.15, this.play.t) * (1 - xt(h.dur - 0.25, h.dur, this.play.t));
|
|
2431
2431
|
for (const [p, g] of Object.entries(o))
|
|
2432
|
-
|
|
2432
|
+
Tr.has(p) ? r[p] += g : p === "breath" ? r[p] += (g - r[p]) * s : Ir.has(p) || (r[p] = Math.max(r[p], Math.max(0, g)));
|
|
2433
2433
|
}
|
|
2434
2434
|
}
|
|
2435
2435
|
if (this.mode !== "manual" && (r.angleY += r.breath * 1.6), this.armRig?.arms && this.mode !== "manual") {
|
|
2436
|
-
const { arms: h, body: p, legs: g } = this.armRig, b = -r.bodyAngleZ / 10 * p.maxRoll + (g ? g.tilt * (1 - (g.spine ?? 0.7)) * r.weightShift : 0),
|
|
2436
|
+
const { arms: h, body: p, legs: g } = this.armRig, b = -r.bodyAngleZ / 10 * p.maxRoll + (g ? g.tilt * (1 - (g.spine ?? 0.7)) * r.weightShift : 0), a = Te(t, 0, 0.05), d = Math.ceil(a * 240);
|
|
2437
2437
|
for (let A = 0; A < d; A++) {
|
|
2438
|
-
const L =
|
|
2438
|
+
const L = a / d;
|
|
2439
2439
|
this.armVelocity += (100 * (-b * 0.65 - this.armFollow) - 18 * this.armVelocity) * L, this.armFollow += this.armVelocity * L;
|
|
2440
2440
|
}
|
|
2441
2441
|
const x = (h.swing ?? mt.swing) * Math.PI / 180, w = h.inward ?? mt.inward;
|
|
@@ -2444,7 +2444,7 @@ class Nr {
|
|
|
2444
2444
|
r[`armSwing${A}`] = Te((Y > 0 ? z / Y : 0) + (r.breath - 0.5) * 0.06, -1, 1), r[`elbowBend${A}`] = r.breath * 0.025;
|
|
2445
2445
|
}
|
|
2446
2446
|
}
|
|
2447
|
-
const i =
|
|
2447
|
+
const i = $n[this.expr].p, u = ["eyeOpen", "eyeOpenL", "eyeSmileL", "eyeSmile", "mouthOpen", "mouthForm", "blush", "browY", "browAngle", "gx", "gy"], y = {
|
|
2448
2448
|
eyeOpen: i.eyeOpen ?? 1,
|
|
2449
2449
|
eyeOpenL: i.eyeOpenL ?? i.eyeOpen ?? 1,
|
|
2450
2450
|
eyeSmileL: i.eyeSmileL ?? i.eyeSmile ?? 0,
|
|
@@ -2456,7 +2456,7 @@ class Nr {
|
|
|
2456
2456
|
browAngle: i.browAngle ?? 0,
|
|
2457
2457
|
gx: i.glance?.[0] ?? 0,
|
|
2458
2458
|
gy: i.glance?.[1] ?? 0
|
|
2459
|
-
}, v = 1 - Math.exp(-
|
|
2459
|
+
}, v = 1 - Math.exp(-t * 9);
|
|
2460
2460
|
for (const h of u)
|
|
2461
2461
|
this.exprMix[h] === void 0 && (this.exprMix[h] = y[h]), this.exprMix[h] += (y[h] - this.exprMix[h]) * v;
|
|
2462
2462
|
const m = this.exprMix, l = {};
|
|
@@ -2466,25 +2466,25 @@ class Nr {
|
|
|
2466
2466
|
l[p] = r[p], this.cur[p] = r[p], this.vel[p] = 0;
|
|
2467
2467
|
continue;
|
|
2468
2468
|
}
|
|
2469
|
-
let [g, b] =
|
|
2470
|
-
o && /^angle|^body/.test(p) && (
|
|
2471
|
-
const
|
|
2472
|
-
this.vel[p] += (g * (r[p] - this.cur[p]) -
|
|
2469
|
+
let [g, b] = Nr[p] ?? [120, 0.95];
|
|
2470
|
+
o && /^angle|^body/.test(p) && (jt[this.play?.id ?? ""]?.idle ? (g *= vn.stiff, b = 0.8) : /^angle/.test(p) && (g *= 4.5, b = 0.75));
|
|
2471
|
+
const a = 2 * Math.sqrt(g) * b;
|
|
2472
|
+
this.vel[p] += (g * (r[p] - this.cur[p]) - a * this.vel[p]) * t, this.cur[p] += this.vel[p] * t, l[p] = this.cur[p];
|
|
2473
2473
|
}
|
|
2474
2474
|
let c = 1;
|
|
2475
|
-
if (this.mode !== "manual" ? (c = this.blinkValue(
|
|
2475
|
+
if (this.mode !== "manual" ? (c = this.blinkValue(t), l.eyeROpen = m.eyeOpen * c, l.eyeLOpen = m.eyeOpenL * c, l.eyeSmile = m.eyeSmile, l.eyeSmileL = m.eyeSmileL, l.mouthOpen = m.mouthOpen, l.mouthForm = m.mouthForm, l.blush = m.blush, l.browY = m.browY + (l.angleY > 0 ? l.angleY / 60 : 0) - (1 - c) * 0.18, l.browAngle = m.browAngle, l.gazeX = Te(l.gazeX + m.gx, -1, 1), l.gazeY = Te(l.gazeY + m.gy, -1, 1)) : l.eyeSmileL = l.eyeSmile, o) {
|
|
2476
2476
|
const h = (g, b) => {
|
|
2477
|
-
l[g] += (b - l[g]) *
|
|
2477
|
+
l[g] += (b - l[g]) * s;
|
|
2478
2478
|
}, p = (g) => Math.min(1.3, Math.max(0, g));
|
|
2479
2479
|
"eyeOpen" in o && (h("eyeROpen", p(o.eyeOpen) * c), "eyeOpenL" in o || h("eyeLOpen", p(o.eyeOpen) * c)), "eyeOpenL" in o && h("eyeLOpen", p(o.eyeOpenL) * c), "eyeSmile" in o && (h("eyeSmile", o.eyeSmile), "eyeSmileL" in o || h("eyeSmileL", o.eyeSmile)), "eyeSmileL" in o && h("eyeSmileL", o.eyeSmileL);
|
|
2480
2480
|
for (const g of ["mouthOpen", "mouthForm", "blush", "browY", "browAngle"])
|
|
2481
2481
|
g in o && h(g, g === "mouthOpen" || g === "blush" ? Math.max(0, o[g]) : o[g]);
|
|
2482
2482
|
}
|
|
2483
|
-
const f = this.speechMouth(
|
|
2483
|
+
const f = this.speechMouth(t);
|
|
2484
2484
|
return f ? (this.lipOpen = f[0], this.lipForm = f[1]) : this.lipOpen !== null && !this.speaking && !this.kana && (this.lipOpen = null), this.lipOpen !== null && (l.mouthOpen = Math.max(l.mouthOpen * 0.3, this.lipOpen), l.mouthForm = Te(this.lipForm, -1, 1)), this.P = l, l;
|
|
2485
2485
|
}
|
|
2486
2486
|
}
|
|
2487
|
-
const
|
|
2487
|
+
const Ot = {
|
|
2488
2488
|
neutral: "normal",
|
|
2489
2489
|
smile: "smile",
|
|
2490
2490
|
shy: "shy",
|
|
@@ -2493,96 +2493,123 @@ const rn = {
|
|
|
2493
2493
|
angry: "angryTalk",
|
|
2494
2494
|
sad: "sadTalk",
|
|
2495
2495
|
wink: "wink"
|
|
2496
|
-
},
|
|
2497
|
-
function
|
|
2498
|
-
const
|
|
2496
|
+
}, Cr = { sad: { pitch: -6, gy: -0.45 } }, lt = (e, t, n) => Math.max(t, Math.min(n, e)), ct = Object.freeze({ eyeOpen: 1, eyeOpenL: 1, eyeSmile: 0, eyeSmileL: 0, blush: 0, browY: 0, browAngle: 0, mouthOpen: 0, mouthForm: 0, gx: 0, gy: 0, pitch: 0 });
|
|
2497
|
+
function Dr(e, t = {}) {
|
|
2498
|
+
const n = $n[Ot[e]]?.p ?? {}, r = Cr[e] ?? {}, o = e === "neutral" ? void 0 : t[e]?.mouthOpen;
|
|
2499
2499
|
return {
|
|
2500
|
-
eyeOpen:
|
|
2501
|
-
eyeOpenL:
|
|
2502
|
-
eyeSmile:
|
|
2503
|
-
eyeSmileL:
|
|
2504
|
-
blush:
|
|
2505
|
-
browY:
|
|
2506
|
-
browAngle:
|
|
2507
|
-
mouthOpen:
|
|
2508
|
-
mouthForm:
|
|
2509
|
-
gx:
|
|
2510
|
-
gy:
|
|
2511
|
-
pitch:
|
|
2500
|
+
eyeOpen: n.eyeOpen ?? 1,
|
|
2501
|
+
eyeOpenL: n.eyeOpenL ?? n.eyeOpen ?? 1,
|
|
2502
|
+
eyeSmile: n.eyeSmile ?? 0,
|
|
2503
|
+
eyeSmileL: n.eyeSmileL ?? n.eyeSmile ?? 0,
|
|
2504
|
+
blush: n.blush ?? 0,
|
|
2505
|
+
browY: n.browY ?? 0,
|
|
2506
|
+
browAngle: n.browAngle ?? 0,
|
|
2507
|
+
mouthOpen: o ?? n.mouthOpen ?? 0,
|
|
2508
|
+
mouthForm: n.mouthForm ?? 0,
|
|
2509
|
+
gx: n.glance?.[0] ?? 0,
|
|
2510
|
+
gy: r.gy ?? n.glance?.[1] ?? 0,
|
|
2511
|
+
pitch: r.pitch ?? 0
|
|
2512
2512
|
};
|
|
2513
2513
|
}
|
|
2514
|
-
function
|
|
2515
|
-
const n = { ...
|
|
2516
|
-
return n.eyeROpen = (
|
|
2514
|
+
function Pr(e, t) {
|
|
2515
|
+
const n = { ...e };
|
|
2516
|
+
return n.eyeROpen = (e.eyeROpen ?? 1) * t.eyeOpen, n.eyeLOpen = (e.eyeLOpen ?? 1) * t.eyeOpenL, n.eyeSmile = Math.max(e.eyeSmile ?? 0, t.eyeSmile), n.eyeSmileL = Math.max(e.eyeSmileL ?? e.eyeSmile ?? 0, t.eyeSmileL), n.blush = Math.max(e.blush ?? 0, t.blush), n.browY = lt((e.browY ?? 0) + t.browY, -1, 1), n.browAngle = lt((e.browAngle ?? 0) + t.browAngle, -1, 1), n.mouthOpen = Math.max(e.mouthOpen ?? 0, t.mouthOpen), t.mouthOpen > (e.mouthOpen ?? 0) && (n.mouthForm = t.mouthForm), n.gazeX = lt((e.gazeX ?? 0) + t.gx, -1, 1), n.gazeY = lt((e.gazeY ?? 0) + t.gy, -1, 1), n.angleY = lt((e.angleY ?? 0) + t.pitch, -30, 30), n;
|
|
2517
2517
|
}
|
|
2518
|
-
class
|
|
2518
|
+
class Hr {
|
|
2519
2519
|
/** @type {keyof typeof OVERLAY_EXPRESSIONS} */
|
|
2520
2520
|
name = "neutral";
|
|
2521
2521
|
mix = { ...ct };
|
|
2522
|
+
/** @param {Record<string, { mouthOpen?: number }>} [settings] parsed per-expression settings */
|
|
2523
|
+
constructor(t = {}) {
|
|
2524
|
+
this.settings = t;
|
|
2525
|
+
}
|
|
2522
2526
|
/** @param {string} name */
|
|
2523
|
-
set(
|
|
2524
|
-
this.name = Object.hasOwn(
|
|
2527
|
+
set(t) {
|
|
2528
|
+
this.name = Object.hasOwn(Ot, t) ? (
|
|
2525
2529
|
/** @type {keyof typeof OVERLAY_EXPRESSIONS} */
|
|
2526
|
-
|
|
2530
|
+
t
|
|
2527
2531
|
) : "neutral";
|
|
2528
2532
|
}
|
|
2529
2533
|
/** True while an expression is shown or still fading out. */
|
|
2530
2534
|
get active() {
|
|
2531
|
-
return this.name !== "neutral" || Object.keys(ct).some((
|
|
2535
|
+
return this.name !== "neutral" || Object.keys(ct).some((t) => Math.abs(this.mix[t] - ct[t]) > 1e-3);
|
|
2532
2536
|
}
|
|
2533
|
-
apply(
|
|
2537
|
+
apply(t, n) {
|
|
2534
2538
|
if (!this.active)
|
|
2535
|
-
return this.mix = { ...ct },
|
|
2536
|
-
const r =
|
|
2537
|
-
for (const
|
|
2538
|
-
return
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
const
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2539
|
+
return this.mix = { ...ct }, t;
|
|
2540
|
+
const r = Dr(this.name, this.settings), o = 1 - Math.exp(-Math.max(0, n) * 12);
|
|
2541
|
+
for (const s of Object.keys(ct)) this.mix[s] += (r[s] - this.mix[s]) * o;
|
|
2542
|
+
return Pr(t, this.mix);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
const xn = (e) => !!e && typeof e == "object" && !Array.isArray(e);
|
|
2546
|
+
function on(e) {
|
|
2547
|
+
if (!xn(e)) throw new TypeError("expressions: expected an object");
|
|
2548
|
+
const t = {};
|
|
2549
|
+
for (const [n, r] of Object.entries(e)) {
|
|
2550
|
+
if (n === "neutral" || !Object.hasOwn(Ot, n)) continue;
|
|
2551
|
+
if (!xn(r)) throw new TypeError(`expressions.${n}: expected an object`);
|
|
2552
|
+
const o = {}, s = r.mouthOpen;
|
|
2553
|
+
if (s !== void 0) {
|
|
2554
|
+
if (typeof s != "number" || !Number.isFinite(s) || s < 0 || s > 1)
|
|
2555
|
+
throw new RangeError(`expressions.${n}.mouthOpen: expected 0–1`);
|
|
2556
|
+
o.mouthOpen = s;
|
|
2557
|
+
}
|
|
2558
|
+
t[n] = o;
|
|
2559
|
+
}
|
|
2560
|
+
return t;
|
|
2561
|
+
}
|
|
2562
|
+
function Vr(e = {}, t = {}) {
|
|
2563
|
+
const n = {};
|
|
2564
|
+
for (const r of /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(t)]))
|
|
2565
|
+
n[r] = { ...e[r], ...t[r] };
|
|
2566
|
+
return n;
|
|
2567
|
+
}
|
|
2568
|
+
const Mn = ["ball", "low", "crease", "lash"], Bt = /* @__PURE__ */ new Map(), $t = /* @__PURE__ */ new Map();
|
|
2569
|
+
async function Ut(e) {
|
|
2570
|
+
return $t.has(e) || $t.set(e, fetch(e).then((t) => {
|
|
2571
|
+
if (!t.ok) throw new Error(`failed to load ${e}`);
|
|
2572
|
+
return t.json();
|
|
2573
|
+
})), $t.get(e);
|
|
2574
|
+
}
|
|
2575
|
+
function Yt(e) {
|
|
2576
|
+
if (Bt.has(e)) return Bt.get(e);
|
|
2577
|
+
const t = new Promise((n, r) => {
|
|
2551
2578
|
const o = new Image();
|
|
2552
|
-
o.onload = () => n(o), o.onerror = () => r(new Error(`failed to load ${
|
|
2579
|
+
o.onload = () => n(o), o.onerror = () => r(new Error(`failed to load ${e}`)), o.src = e;
|
|
2553
2580
|
});
|
|
2554
|
-
return
|
|
2581
|
+
return Bt.set(e, t), t;
|
|
2555
2582
|
}
|
|
2556
|
-
function
|
|
2583
|
+
function Un(e, t) {
|
|
2557
2584
|
const n = document.createElement("canvas");
|
|
2558
|
-
n.width =
|
|
2585
|
+
n.width = e.width, n.height = e.height;
|
|
2559
2586
|
const r = n.getContext("2d");
|
|
2560
|
-
r.drawImage(
|
|
2561
|
-
const o = r.getImageData(0, 0, n.width, n.height).data,
|
|
2562
|
-
for (let i = 0; i <
|
|
2563
|
-
return
|
|
2564
|
-
}
|
|
2565
|
-
const Ze = (
|
|
2566
|
-
function
|
|
2567
|
-
const
|
|
2568
|
-
return
|
|
2569
|
-
}
|
|
2570
|
-
function
|
|
2571
|
-
const [n, r] =
|
|
2587
|
+
r.drawImage(e, 0, 0);
|
|
2588
|
+
const o = r.getImageData(0, 0, n.width, n.height).data, s = new Uint8Array(n.width * n.height);
|
|
2589
|
+
for (let i = 0; i < s.length; i++) s[i] = o[i * 4 + t];
|
|
2590
|
+
return s;
|
|
2591
|
+
}
|
|
2592
|
+
const Ze = (e) => Un(e, 3);
|
|
2593
|
+
function Zr(e, [t, n, r, o]) {
|
|
2594
|
+
const s = document.createElement("canvas");
|
|
2595
|
+
return s.width = r, s.height = o, s.getContext("2d").drawImage(e, t, n, r, o, 0, 0, r, o), s;
|
|
2596
|
+
}
|
|
2597
|
+
function Wr(e, t) {
|
|
2598
|
+
const [n, r] = e.t.pivot, o = e.dir, s = e.pts, i = (f, h, p) => {
|
|
2572
2599
|
const g = Math.min(1, Math.max(0, (p - f) / (h - f)));
|
|
2573
2600
|
return g * g * (3 - 2 * g);
|
|
2574
|
-
}, u = Math.cos(
|
|
2601
|
+
}, u = Math.cos(e.phi[0]), y = Math.sin(e.phi[0]), v = Math.cos(e.phi[1]), m = Math.sin(e.phi[1]), l = t.rest, c = t.pos;
|
|
2575
2602
|
for (let f = 0; f < l.length; f += 2) {
|
|
2576
|
-
const h = l[f] - n, p = l[f + 1] - r, g = h * o[0] + p * o[1], b =
|
|
2577
|
-
c[f] = b + (w - b) * L, c[f + 1] =
|
|
2603
|
+
const h = l[f] - n, p = l[f + 1] - r, g = h * o[0] + p * o[1], b = s[0][0] + h * u - p * y, a = s[0][1] + h * y + p * u, d = h - o[0] * e.L1, x = p - o[1] * e.L1, w = s[1][0] + d * v - x * m, A = s[1][1] + d * m + x * v, L = i(e.L1 * 0.55, e.L1 * 1.35, g);
|
|
2604
|
+
c[f] = b + (w - b) * L, c[f + 1] = a + (A - a) * L;
|
|
2578
2605
|
}
|
|
2579
2606
|
}
|
|
2580
|
-
async function
|
|
2581
|
-
if (!
|
|
2607
|
+
async function Gr(e, t) {
|
|
2608
|
+
if (!t.assets && t.assetsBase === void 0)
|
|
2582
2609
|
throw new Error("createMeshAvatar requires assets or assetsBase.");
|
|
2583
|
-
const n =
|
|
2610
|
+
const n = t.rig, r = tr(n), {
|
|
2584
2611
|
IMG: o,
|
|
2585
|
-
EYES:
|
|
2612
|
+
EYES: s,
|
|
2586
2613
|
baseWeights: i,
|
|
2587
2614
|
deformBase: u,
|
|
2588
2615
|
eyePartY: y,
|
|
@@ -2591,19 +2618,19 @@ async function Vr(t, e) {
|
|
|
2591
2618
|
handFrame: l,
|
|
2592
2619
|
deformHand: c,
|
|
2593
2620
|
TASSELS: f
|
|
2594
|
-
} = r, { Renderer: h, buildGrid: p } =
|
|
2595
|
-
if (
|
|
2596
|
-
if (!
|
|
2597
|
-
return
|
|
2621
|
+
} = r, { Renderer: h, buildGrid: p } = dr(r, n), { Physics: g } = gr(r, n), { Cloth: b } = Mr(r, n), a = n.cloth ?? [], { createSprites: d } = Ar(r, n), x = (t.assetsBase ?? "").replace(/\/?$/, "/"), w = (S, R) => {
|
|
2622
|
+
if (t.assets) {
|
|
2623
|
+
if (!t.assets[S]) throw new Error(`Missing project asset: ${S}`);
|
|
2624
|
+
return t.assets[S];
|
|
2598
2625
|
}
|
|
2599
2626
|
return `${x}${S}${R === void 0 ? "" : `?b=${R}`}`;
|
|
2600
|
-
}, A = await
|
|
2601
|
-
|
|
2602
|
-
const I =
|
|
2627
|
+
}, A = await Ut(w("layers.json")), z = [a.length ? "base_cloth" : "base", ...n.hand ? ["hand"] : [], ...f.map((S) => S.name), ...a.map((S) => `cloth_${S.name}`), ...[0, 1].flatMap((S) => Mn.map((R) => `eye${S}_${R}`)), "hairmask"], Y = Object.fromEntries(await Promise.all(z.map(async (S) => [S, await Yt(w(`${S}.png`, A.build))])));
|
|
2628
|
+
a.length && (Y.base = Y.base_cloth);
|
|
2629
|
+
const I = Un(Y.hairmask, 0), U = (S, R) => I[Math.min(o.h - 1, Math.max(0, Math.round(R))) * o.w + Math.min(o.w - 1, Math.max(0, Math.round(S)))] / 255, T = new h(e, { padTop: t.padTop ?? n.view.padTop, padSide: t.padSide ?? n.view.padSide, fit: t.fit }), F = { base: [0, 0, o.w, o.h], ...A.layers }, j = new b(), C = (S) => {
|
|
2603
2630
|
const R = `cloth_${S.name}`, P = p(F[R], n.mesh.clothCell ?? 8, Ze(Y[R]), Y[R].width);
|
|
2604
2631
|
j.attach(S.name, P), T.addLayer(R, Y[R], P);
|
|
2605
2632
|
};
|
|
2606
|
-
|
|
2633
|
+
a.filter((S) => S.behind).forEach(C);
|
|
2607
2634
|
const B = p(F.base, n.mesh.baseCell, Ze(Y.base), Y.base.width, n.mesh.fine), H = [];
|
|
2608
2635
|
for (let S = 0; S < B.rest.length / 2; S++) {
|
|
2609
2636
|
const R = B.rest[S * 2], P = B.rest[S * 2 + 1];
|
|
@@ -2611,30 +2638,30 @@ async function Vr(t, e) {
|
|
|
2611
2638
|
}
|
|
2612
2639
|
T.addLayer("base", Y.base, B, { face: !0 });
|
|
2613
2640
|
const N = [];
|
|
2614
|
-
|
|
2615
|
-
for (const P of
|
|
2616
|
-
const
|
|
2641
|
+
s.forEach((S, R) => {
|
|
2642
|
+
for (const P of Mn) {
|
|
2643
|
+
const se = `eye${R}_${P}`, ie = p(F[se], P === "ball" ? n.mesh.eyeBallCell : n.mesh.eyeCell, Ze(Y[se]), Y[se].width), pe = [];
|
|
2617
2644
|
for (let Me = 0; Me < ie.rest.length / 2; Me++) pe.push(i(ie.rest[Me * 2], ie.rest[Me * 2 + 1], 0));
|
|
2618
|
-
const be = T.addLayer(
|
|
2645
|
+
const be = T.addLayer(se, Y[se], ie, { eyeBall: P === "ball" ? R : void 0 });
|
|
2619
2646
|
N.push({ e: S, eye: R, part: P, mesh: ie, W: pe, layer: be });
|
|
2620
2647
|
}
|
|
2621
2648
|
});
|
|
2622
2649
|
let ne = null;
|
|
2623
2650
|
try {
|
|
2624
2651
|
{
|
|
2625
|
-
const S = await
|
|
2652
|
+
const S = await Ut(w("sprites/sprites.json")), R = Object.fromEntries(await Promise.all(Object.keys(S.layers).map(async (P) => [P, await Yt(w(`sprites/${P}.png`, S.build))])));
|
|
2626
2653
|
ne = d(T, S, R, p, Ze);
|
|
2627
2654
|
}
|
|
2628
2655
|
} catch (S) {
|
|
2629
2656
|
console.warn("eye / mouth sprites not loaded:", S);
|
|
2630
2657
|
}
|
|
2631
|
-
|
|
2658
|
+
a.filter((S) => !S.behind).forEach(C);
|
|
2632
2659
|
let Q = null;
|
|
2633
2660
|
try {
|
|
2634
|
-
const S = await
|
|
2635
|
-
Q =
|
|
2661
|
+
const S = await Ut(w("overlays/overlays.json")), R = Object.fromEntries(await Promise.all(S.overlays.map(async (P) => [P.name, await Yt(w(`overlays/${P.file}`))])));
|
|
2662
|
+
Q = Or(T, S, R, p, Ze, i, n.mesh.spriteCell, o.w, o.h, Zr);
|
|
2636
2663
|
} catch (S) {
|
|
2637
|
-
|
|
2664
|
+
t.assets?.["overlays/overlays.json"] && console.warn("overlay layers not loaded:", S);
|
|
2638
2665
|
}
|
|
2639
2666
|
const J = f.map((S) => {
|
|
2640
2667
|
const R = p(F[S.name], n.mesh.tasselCell, Ze(Y[S.name]), Y[S.name].width);
|
|
@@ -2642,28 +2669,28 @@ async function Vr(t, e) {
|
|
|
2642
2669
|
}), X = n.hand ? p(F.hand, n.mesh.handCell, Ze(Y.hand), Y.hand.width) : { rest: [], pos: [] }, G = [];
|
|
2643
2670
|
for (let S = 0; S < X.rest.length / 2; S++) G.push(m(X.rest[S * 2], X.rest[S * 2 + 1]));
|
|
2644
2671
|
n.hand && T.addLayer("hand", Y.hand, X);
|
|
2645
|
-
const re = new g(), W = new
|
|
2646
|
-
|
|
2672
|
+
const re = new g(), W = new zr(n.view.gazeCenter ?? [n.head.cx, n.head.cy], !!n.legs, n.arms ? n : null);
|
|
2673
|
+
t.lipSync !== void 0 && W.setLipSync(t.lipSync);
|
|
2647
2674
|
const te = /* @__PURE__ */ new Set();
|
|
2648
2675
|
W.onMotion = (S) => {
|
|
2649
2676
|
for (const R of te) R(S);
|
|
2650
2677
|
};
|
|
2651
|
-
let
|
|
2652
|
-
const O = new
|
|
2678
|
+
let ae = {}, V = 1, M = {}, E = {};
|
|
2679
|
+
const O = new Hr(t.expressions === void 0 ? void 0 : on(t.expressions)), k = [0, 0];
|
|
2653
2680
|
function $(S) {
|
|
2654
2681
|
const R = { ...W.update(S) };
|
|
2655
|
-
for (const [
|
|
2656
|
-
const pe = V * (M[
|
|
2657
|
-
R[
|
|
2682
|
+
for (const [se, ie] of Object.entries(ae)) {
|
|
2683
|
+
const pe = V * (M[se] ?? 1);
|
|
2684
|
+
R[se] = pe === 1 ? ie : (R[se] ?? 0) + (ie - (R[se] ?? 0)) * pe;
|
|
2658
2685
|
}
|
|
2659
|
-
W.lipOpen !== null && (R.mouthOpen = W.P.mouthOpen, (!
|
|
2686
|
+
W.lipOpen !== null && (R.mouthOpen = W.P.mouthOpen, (!t.preserveMouthForm || ae.mouthForm === void 0) && (R.mouthForm = W.P.mouthForm));
|
|
2660
2687
|
const P = O.apply(R, S);
|
|
2661
2688
|
return E = P, P;
|
|
2662
2689
|
}
|
|
2663
2690
|
function Z(S) {
|
|
2664
|
-
const R = $(S), P = re.step(R, S),
|
|
2691
|
+
const R = $(S), P = re.step(R, S), se = B.pos, ie = B.rest;
|
|
2665
2692
|
for (let K = 0; K < H.length; K++)
|
|
2666
|
-
u(ie[K * 2], ie[K * 2 + 1], H[K], R, P, k),
|
|
2693
|
+
u(ie[K * 2], ie[K * 2 + 1], H[K], R, P, k), se[K * 2] = k[0], se[K * 2 + 1] = k[1];
|
|
2667
2694
|
const pe = (K, ce) => ne?.eyesDrawn[ce] ? 1 : K;
|
|
2668
2695
|
for (const K of N) {
|
|
2669
2696
|
const ce = pe(K.eye === 0 ? R.eyeROpen : R.eyeLOpen, K.eye), ue = K.eye === 0 ? R.eyeSmile : R.eyeSmileL ?? R.eyeSmile;
|
|
@@ -2674,13 +2701,13 @@ async function Vr(t, e) {
|
|
|
2674
2701
|
u(Le, y(K.e, K.part, Le, $e, ce, ue), K.W[ye], R, P, k), Se[ye * 2] = k[0], Se[ye * 2 + 1] = k[1];
|
|
2675
2702
|
}
|
|
2676
2703
|
}
|
|
2677
|
-
const be = ne?.update(R, P, S,
|
|
2704
|
+
const be = ne?.update(R, P, S, Er(O.name, W.mode === "manual" ? null : W.expr));
|
|
2678
2705
|
if (be) for (const K of N) be.eyes[K.eye] && (K.layer.alpha = 0);
|
|
2679
2706
|
Q?.update(R, P, u, k);
|
|
2680
2707
|
const Me = X.pos, Be = X.rest, Ee = l(R);
|
|
2681
2708
|
for (let K = 0; K < G.length; K++)
|
|
2682
2709
|
c(Be[K * 2], Be[K * 2 + 1], G[K], R, Ee, k), Me[K * 2] = k[0], Me[K * 2 + 1] = k[1];
|
|
2683
|
-
re.chains.forEach((K, ce) =>
|
|
2710
|
+
re.chains.forEach((K, ce) => Wr(K, J[ce].mesh)), a.length && (j.step(R, S, P), j.deform());
|
|
2684
2711
|
const de = n.view.irisTravel ?? 7;
|
|
2685
2712
|
T.draw({
|
|
2686
2713
|
angleX: R.angleX,
|
|
@@ -2710,13 +2737,13 @@ async function Vr(t, e) {
|
|
|
2710
2737
|
const R = Math.min(0.05, (S - D) / 1e3);
|
|
2711
2738
|
D = S, Z(R), _ = requestAnimationFrame(ee);
|
|
2712
2739
|
};
|
|
2713
|
-
return
|
|
2740
|
+
return t.manual || (_ = requestAnimationFrame(ee)), {
|
|
2714
2741
|
motions: [
|
|
2715
|
-
...Object.entries(
|
|
2716
|
-
...Object.entries(
|
|
2742
|
+
...Object.entries(nn).map(([S, R]) => ({ id: S, label: R.label, idle: !1 })),
|
|
2743
|
+
...Object.entries(rn).map(([S, R]) => ({ id: S, label: R.label, idle: !0 }))
|
|
2717
2744
|
],
|
|
2718
2745
|
setParameters(S, R = 1, P = {}) {
|
|
2719
|
-
|
|
2746
|
+
ae = { ...S }, V = Math.min(1, Math.max(0, Number(R) || 0)), M = Object.fromEntries(Object.entries(P ?? {}).map(([se, ie]) => [se, Math.min(1, Math.max(0, Number(ie) || 0))]));
|
|
2720
2747
|
},
|
|
2721
2748
|
getParameters() {
|
|
2722
2749
|
return { ...E };
|
|
@@ -2807,153 +2834,159 @@ async function Vr(t, e) {
|
|
|
2807
2834
|
}
|
|
2808
2835
|
};
|
|
2809
2836
|
}
|
|
2810
|
-
const
|
|
2811
|
-
async function
|
|
2812
|
-
return
|
|
2837
|
+
const So = Object.keys(Ot);
|
|
2838
|
+
async function qr(e, t) {
|
|
2839
|
+
return Gr(e, { ...t, rig: en(t.rig) });
|
|
2813
2840
|
}
|
|
2814
|
-
function tt(
|
|
2815
|
-
if (!
|
|
2841
|
+
function tt(e) {
|
|
2842
|
+
if (!e || typeof e != "object" || Array.isArray(e))
|
|
2816
2843
|
throw new Error("avatar.json: expected an object");
|
|
2817
|
-
const
|
|
2818
|
-
|
|
2819
|
-
const r = { format: "mesh-avatar", version: 1, name:
|
|
2844
|
+
const t = e, n = [];
|
|
2845
|
+
t.format !== "mesh-avatar" && n.push('avatar.json.format: expected "mesh-avatar"'), t.version !== 1 && n.push(`avatar.json.version: unsupported version ${JSON.stringify(t.version) ?? "missing"} (expected 1)`), (typeof t.name != "string" || !t.name.trim()) && n.push("avatar.json.name: expected a non-empty string");
|
|
2846
|
+
const r = { format: "mesh-avatar", version: 1, name: t.name };
|
|
2820
2847
|
for (const o of ["author", "license", "thumbnail", "source"])
|
|
2821
|
-
|
|
2822
|
-
if (
|
|
2823
|
-
const o =
|
|
2848
|
+
t[o] !== void 0 && (typeof t[o] != "string" ? n.push(`avatar.json.${o}: expected a string`) : r[o] = t[o]);
|
|
2849
|
+
if (t.studio !== void 0) {
|
|
2850
|
+
const o = t.studio;
|
|
2824
2851
|
!o || typeof o != "object" || Array.isArray(o) || !("version" in o) || typeof o.version != "string" || !o.version.trim() ? n.push("avatar.json.studio.version: expected a non-empty string") : r.studio = { version: o.version };
|
|
2825
2852
|
}
|
|
2826
|
-
if (
|
|
2853
|
+
if (t.lipSync !== void 0)
|
|
2827
2854
|
try {
|
|
2828
|
-
r.lipSync =
|
|
2855
|
+
r.lipSync = tn(t.lipSync);
|
|
2829
2856
|
} catch (o) {
|
|
2830
2857
|
n.push(`avatar.json.lipSync: ${o instanceof Error ? o.message : String(o)}`);
|
|
2831
2858
|
}
|
|
2859
|
+
if (t.expressions !== void 0)
|
|
2860
|
+
try {
|
|
2861
|
+
r.expressions = on(t.expressions);
|
|
2862
|
+
} catch (o) {
|
|
2863
|
+
n.push(`avatar.json.expressions: ${o instanceof Error ? o.message : String(o)}`);
|
|
2864
|
+
}
|
|
2832
2865
|
if (n.length) throw new Error(n.join(`
|
|
2833
2866
|
`));
|
|
2834
2867
|
return r;
|
|
2835
2868
|
}
|
|
2836
|
-
function
|
|
2837
|
-
return tt({ format: "mesh-avatar", version: 1, name:
|
|
2869
|
+
function Yn(e) {
|
|
2870
|
+
return tt({ format: "mesh-avatar", version: 1, name: e });
|
|
2838
2871
|
}
|
|
2839
|
-
const Mt = (
|
|
2840
|
-
function
|
|
2841
|
-
const
|
|
2872
|
+
const Mt = (e) => !!e && typeof e == "object" && !Array.isArray(e), We = (e, t) => Array.isArray(e) && e.length === t && e.every((n) => typeof n == "number" && Number.isFinite(n)), It = (e, t) => Object.hasOwn(e, t);
|
|
2873
|
+
function In(e) {
|
|
2874
|
+
const t = [];
|
|
2842
2875
|
function n(f, h = !0) {
|
|
2843
|
-
if (!
|
|
2844
|
-
h &&
|
|
2876
|
+
if (!It(e, f)) {
|
|
2877
|
+
h && t.push(`${f}: missing file`);
|
|
2845
2878
|
return;
|
|
2846
2879
|
}
|
|
2847
|
-
const p =
|
|
2880
|
+
const p = e[f];
|
|
2848
2881
|
if (!(p instanceof Uint8Array)) {
|
|
2849
|
-
|
|
2882
|
+
t.push(`${f}: JSON bytes are required`);
|
|
2850
2883
|
return;
|
|
2851
2884
|
}
|
|
2852
2885
|
let g;
|
|
2853
2886
|
try {
|
|
2854
2887
|
g = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(p));
|
|
2855
2888
|
} catch {
|
|
2856
|
-
|
|
2889
|
+
t.push(`${f}: invalid UTF-8 JSON`);
|
|
2857
2890
|
return;
|
|
2858
2891
|
}
|
|
2859
2892
|
if (!Mt(g)) {
|
|
2860
|
-
|
|
2893
|
+
t.push(`${f}: expected an object`);
|
|
2861
2894
|
return;
|
|
2862
2895
|
}
|
|
2863
2896
|
return g;
|
|
2864
2897
|
}
|
|
2865
2898
|
function r(f, h, p = !0) {
|
|
2866
|
-
return f.version === 1 || p && f.version === void 0 ? !0 : (
|
|
2899
|
+
return f.version === 1 || p && f.version === void 0 ? !0 : (t.push(`${h}.version: unsupported version ${JSON.stringify(f.version) ?? "missing"} (expected 1)`), !1);
|
|
2867
2900
|
}
|
|
2868
2901
|
function o(f) {
|
|
2869
|
-
if (!
|
|
2870
|
-
|
|
2902
|
+
if (!It(e, f)) {
|
|
2903
|
+
t.push(`${f}: missing file`);
|
|
2871
2904
|
return;
|
|
2872
2905
|
}
|
|
2873
|
-
const h =
|
|
2874
|
-
(!Number.isSafeInteger(p) || p <= 0) &&
|
|
2906
|
+
const h = e[f], p = h instanceof Uint8Array ? h.byteLength : h?.size;
|
|
2907
|
+
(!Number.isSafeInteger(p) || p <= 0) && t.push(`${f}: expected a non-empty file`);
|
|
2875
2908
|
}
|
|
2876
|
-
function
|
|
2909
|
+
function s(f, h, p, g) {
|
|
2877
2910
|
if (!Mt(f)) {
|
|
2878
|
-
|
|
2911
|
+
t.push(`${h}.layers: expected a layer rectangle map`);
|
|
2879
2912
|
return;
|
|
2880
2913
|
}
|
|
2881
|
-
for (const [b,
|
|
2914
|
+
for (const [b, a] of Object.entries(f)) {
|
|
2882
2915
|
const d = `${h}.layers.${b}`;
|
|
2883
2916
|
if (!/^[A-Za-z0-9_-]+$/.test(b)) {
|
|
2884
|
-
|
|
2917
|
+
t.push(`${d}: expected a safe layer name (letters, digits, hyphens or underscores)`);
|
|
2885
2918
|
continue;
|
|
2886
2919
|
}
|
|
2887
|
-
!We(
|
|
2920
|
+
!We(a, 4) || !a.every(Number.isInteger) || a[0] < 0 || a[1] < 0 || a[2] <= 0 || a[3] <= 0 ? t.push(`${d}: expected [x, y, width, height] with non-negative integer origins and positive integer dimensions`) : g && (a[0] + a[2] > g[0] || a[1] + a[3] > g[1]) && t.push(`${d}: rectangle must stay inside the image`), o(`${p}/${b}.png`);
|
|
2888
2921
|
}
|
|
2889
2922
|
return f;
|
|
2890
2923
|
}
|
|
2891
2924
|
function i(f, h) {
|
|
2892
|
-
(typeof f.build != "string" || !f.build.trim()) &&
|
|
2925
|
+
(typeof f.build != "string" || !f.build.trim()) && t.push(`${h}.build: expected a non-empty string`);
|
|
2893
2926
|
}
|
|
2894
2927
|
const u = n("avatar.json", !1);
|
|
2895
2928
|
if (u)
|
|
2896
2929
|
try {
|
|
2897
2930
|
tt(u);
|
|
2898
2931
|
} catch (f) {
|
|
2899
|
-
|
|
2932
|
+
t.push(f.message);
|
|
2900
2933
|
}
|
|
2901
2934
|
const y = n("rig.json");
|
|
2902
2935
|
let v;
|
|
2903
2936
|
if (y && r(y, "rig.json", !1)) {
|
|
2904
|
-
const f =
|
|
2905
|
-
|
|
2937
|
+
const f = Ln(y);
|
|
2938
|
+
t.push(...f.map((h) => `rig.json: ${h}`)), f.length || (v = y);
|
|
2906
2939
|
}
|
|
2907
2940
|
o("built/base.png"), o("built/hairmask.png"), v?.cloth?.length && o("built/base_cloth.png");
|
|
2908
2941
|
const m = n("built/layers.json");
|
|
2909
2942
|
if (m && r(m, "built/layers.json")) {
|
|
2910
2943
|
i(m, "built/layers.json");
|
|
2911
2944
|
let f;
|
|
2912
|
-
!We(m.size, 2) || !m.size.every((p) => Number.isInteger(p) && p > 0) ?
|
|
2913
|
-
const h =
|
|
2945
|
+
!We(m.size, 2) || !m.size.every((p) => Number.isInteger(p) && p > 0) ? t.push("built/layers.json.size: expected [width, height] with positive integer dimensions") : (f = m.size, v && (f[0] !== v.image.width || f[1] !== v.image.height) && t.push("built/layers.json.size: must match rig.json.image"));
|
|
2946
|
+
const h = s(m.layers, "built/layers.json", "built", f);
|
|
2914
2947
|
if (v && h) {
|
|
2915
2948
|
const p = [
|
|
2916
|
-
...v.eyes.flatMap((g, b) => ["ball", "low", "crease", "lash"].map((
|
|
2949
|
+
...v.eyes.flatMap((g, b) => ["ball", "low", "crease", "lash"].map((a) => `eye${b}_${a}`)),
|
|
2917
2950
|
...v.hand ? ["hand"] : [],
|
|
2918
2951
|
...(v.accessories ?? []).map((g) => g.name),
|
|
2919
2952
|
...(v.cloth ?? []).map((g) => `cloth_${g.name}`)
|
|
2920
2953
|
];
|
|
2921
|
-
for (const g of p)
|
|
2954
|
+
for (const g of p) It(h, g) || t.push(`built/layers.json.layers.${g}: missing required layer`);
|
|
2922
2955
|
}
|
|
2923
|
-
!Array.isArray(m.eyes) || m.eyes.length !== 2 ?
|
|
2956
|
+
!Array.isArray(m.eyes) || m.eyes.length !== 2 ? t.push("built/layers.json.eyes: expected two eye curves") : m.eyes.forEach((p, g) => {
|
|
2924
2957
|
const b = `built/layers.json.eyes[${g}]`;
|
|
2925
2958
|
if (!Mt(p)) {
|
|
2926
|
-
|
|
2959
|
+
t.push(`${b}: expected an object`);
|
|
2927
2960
|
return;
|
|
2928
2961
|
}
|
|
2929
|
-
We([p.x0, p.x1], 2) && p.x0 < p.x1 ||
|
|
2962
|
+
We([p.x0, p.x1], 2) && p.x0 < p.x1 || t.push(`${b}: expected finite x0 < x1`);
|
|
2930
2963
|
for (const d of ["top", "bot"])
|
|
2931
|
-
We(p[d], 24) ||
|
|
2932
|
-
if (We(p.top, 24) && We(p.bot, 24) && p.top.some((d, x) => d > p.bot[x]) &&
|
|
2964
|
+
We(p[d], 24) || t.push(`${b}.${d}: expected 24 finite numbers`);
|
|
2965
|
+
if (We(p.top, 24) && We(p.bot, 24) && p.top.some((d, x) => d > p.bot[x]) && t.push(`${b}.top: must not exceed bottom curve`), v) for (const d of ["x0", "x1", "top", "bot"]) {
|
|
2933
2966
|
const x = p[d], w = v.eyes[g][d];
|
|
2934
|
-
(Array.isArray(w) ? We(x, w.length) && x.every((L, z) => L === w[z]) : x === w) ||
|
|
2967
|
+
(Array.isArray(w) ? We(x, w.length) && x.every((L, z) => L === w[z]) : x === w) || t.push(`${b}.${d}: must match rig.json.eyes[${g}].${d}`);
|
|
2935
2968
|
}
|
|
2936
2969
|
});
|
|
2937
2970
|
}
|
|
2938
2971
|
const l = n("built/sprites/sprites.json", !1);
|
|
2939
|
-
l && r(l, "built/sprites/sprites.json") && (i(l, "built/sprites/sprites.json"),
|
|
2972
|
+
l && r(l, "built/sprites/sprites.json") && (i(l, "built/sprites/sprites.json"), s(l.layers, "built/sprites/sprites.json", "built/sprites", v ? [v.image.width, v.image.height] : void 0));
|
|
2940
2973
|
const c = n("built/overlays/overlays.json", !1);
|
|
2941
2974
|
if (c && r(c, "built/overlays/overlays.json"))
|
|
2942
|
-
if (!Array.isArray(c.overlays))
|
|
2975
|
+
if (!Array.isArray(c.overlays)) t.push("built/overlays/overlays.json.overlays: expected an array");
|
|
2943
2976
|
else {
|
|
2944
2977
|
const f = /* @__PURE__ */ new Set();
|
|
2945
2978
|
for (const [h, p] of c.overlays.entries()) {
|
|
2946
2979
|
const g = `built/overlays/overlays.json.overlays[${h}]`;
|
|
2947
2980
|
if (!Mt(p) || typeof p.name != "string" || !/^[A-Za-z0-9_-]+$/.test(p.name) || typeof p.file != "string" || !/^[A-Za-z0-9_-]+\.png$/.test(p.file)) {
|
|
2948
|
-
|
|
2981
|
+
t.push(`${g}: expected { name, file } with safe names`);
|
|
2949
2982
|
continue;
|
|
2950
2983
|
}
|
|
2951
|
-
f.has(p.name) &&
|
|
2984
|
+
f.has(p.name) && t.push(`${g}.name: duplicate overlay name`), f.add(p.name), o(`built/overlays/${p.file}`);
|
|
2952
2985
|
}
|
|
2953
2986
|
}
|
|
2954
|
-
return
|
|
2987
|
+
return t;
|
|
2955
2988
|
}
|
|
2956
|
-
var ge = Uint8Array, Re = Uint16Array,
|
|
2989
|
+
var ge = Uint8Array, Re = Uint16Array, sn = Int32Array, Tt = new ge([
|
|
2957
2990
|
0,
|
|
2958
2991
|
0,
|
|
2959
2992
|
0,
|
|
@@ -2988,7 +3021,7 @@ var ge = Uint8Array, Re = Uint16Array, on = Int32Array, Ot = new ge([
|
|
|
2988
3021
|
0,
|
|
2989
3022
|
/* impossible */
|
|
2990
3023
|
0
|
|
2991
|
-
]),
|
|
3024
|
+
]), Rt = new ge([
|
|
2992
3025
|
0,
|
|
2993
3026
|
0,
|
|
2994
3027
|
0,
|
|
@@ -3022,37 +3055,37 @@ var ge = Uint8Array, Re = Uint16Array, on = Int32Array, Ot = new ge([
|
|
|
3022
3055
|
/* unused */
|
|
3023
3056
|
0,
|
|
3024
3057
|
0
|
|
3025
|
-
]),
|
|
3058
|
+
]), Ht = new ge([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), Nn = function(e, t) {
|
|
3026
3059
|
for (var n = new Re(31), r = 0; r < 31; ++r)
|
|
3027
|
-
n[r] =
|
|
3028
|
-
for (var o = new
|
|
3029
|
-
for (var
|
|
3030
|
-
o[
|
|
3060
|
+
n[r] = t += 1 << e[r - 1];
|
|
3061
|
+
for (var o = new sn(n[30]), r = 1; r < 30; ++r)
|
|
3062
|
+
for (var s = n[r]; s < n[r + 1]; ++s)
|
|
3063
|
+
o[s] = s - n[r] << 5 | r;
|
|
3031
3064
|
return { b: n, r: o };
|
|
3032
|
-
},
|
|
3033
|
-
|
|
3034
|
-
var
|
|
3065
|
+
}, Xn = Nn(Tt, 2), zn = Xn.b, Vt = Xn.r;
|
|
3066
|
+
zn[28] = 258, Vt[258] = 28;
|
|
3067
|
+
var Cn = Nn(Rt, 0), Jr = Cn.b, An = Cn.r, Zt = new Re(32768);
|
|
3035
3068
|
for (var fe = 0; fe < 32768; ++fe) {
|
|
3036
3069
|
var He = (fe & 43690) >> 1 | (fe & 21845) << 1;
|
|
3037
|
-
He = (He & 52428) >> 2 | (He & 13107) << 2, He = (He & 61680) >> 4 | (He & 3855) << 4,
|
|
3038
|
-
}
|
|
3039
|
-
var Ne = (function(
|
|
3040
|
-
for (var r =
|
|
3041
|
-
|
|
3042
|
-
var i = new Re(
|
|
3043
|
-
for (o = 1; o <
|
|
3044
|
-
i[o] = i[o - 1] +
|
|
3070
|
+
He = (He & 52428) >> 2 | (He & 13107) << 2, He = (He & 61680) >> 4 | (He & 3855) << 4, Zt[fe] = ((He & 65280) >> 8 | (He & 255) << 8) >> 1;
|
|
3071
|
+
}
|
|
3072
|
+
var Ne = (function(e, t, n) {
|
|
3073
|
+
for (var r = e.length, o = 0, s = new Re(t); o < r; ++o)
|
|
3074
|
+
e[o] && ++s[e[o] - 1];
|
|
3075
|
+
var i = new Re(t);
|
|
3076
|
+
for (o = 1; o < t; ++o)
|
|
3077
|
+
i[o] = i[o - 1] + s[o - 1] << 1;
|
|
3045
3078
|
var u;
|
|
3046
3079
|
if (n) {
|
|
3047
|
-
u = new Re(1 <<
|
|
3048
|
-
var y = 15 -
|
|
3080
|
+
u = new Re(1 << t);
|
|
3081
|
+
var y = 15 - t;
|
|
3049
3082
|
for (o = 0; o < r; ++o)
|
|
3050
|
-
if (
|
|
3051
|
-
for (var v = o << 4 |
|
|
3052
|
-
u[
|
|
3083
|
+
if (e[o])
|
|
3084
|
+
for (var v = o << 4 | e[o], m = t - e[o], l = i[e[o] - 1]++ << m, c = l | (1 << m) - 1; l <= c; ++l)
|
|
3085
|
+
u[Zt[l] >> y] = v;
|
|
3053
3086
|
} else
|
|
3054
3087
|
for (u = new Re(r), o = 0; o < r; ++o)
|
|
3055
|
-
|
|
3088
|
+
e[o] && (u[o] = Zt[i[e[o] - 1]++] >> 15 - e[o]);
|
|
3056
3089
|
return u;
|
|
3057
3090
|
}), Ve = new ge(288);
|
|
3058
3091
|
for (var fe = 0; fe < 144; ++fe)
|
|
@@ -3066,21 +3099,21 @@ for (var fe = 280; fe < 288; ++fe)
|
|
|
3066
3099
|
var dt = new ge(32);
|
|
3067
3100
|
for (var fe = 0; fe < 32; ++fe)
|
|
3068
3101
|
dt[fe] = 5;
|
|
3069
|
-
var
|
|
3070
|
-
for (var
|
|
3071
|
-
|
|
3072
|
-
return
|
|
3073
|
-
}, je = function(
|
|
3074
|
-
var r =
|
|
3075
|
-
return (
|
|
3076
|
-
},
|
|
3077
|
-
var n =
|
|
3078
|
-
return (
|
|
3079
|
-
}, an = function(
|
|
3080
|
-
return (
|
|
3081
|
-
}, gt = function(
|
|
3082
|
-
return (
|
|
3083
|
-
},
|
|
3102
|
+
var Kr = /* @__PURE__ */ Ne(Ve, 9, 0), Qr = /* @__PURE__ */ Ne(Ve, 9, 1), eo = /* @__PURE__ */ Ne(dt, 5, 0), to = /* @__PURE__ */ Ne(dt, 5, 1), Nt = function(e) {
|
|
3103
|
+
for (var t = e[0], n = 1; n < e.length; ++n)
|
|
3104
|
+
e[n] > t && (t = e[n]);
|
|
3105
|
+
return t;
|
|
3106
|
+
}, je = function(e, t, n) {
|
|
3107
|
+
var r = t / 8 | 0;
|
|
3108
|
+
return (e[r] | e[r + 1] << 8) >> (t & 7) & n;
|
|
3109
|
+
}, Xt = function(e, t) {
|
|
3110
|
+
var n = t / 8 | 0;
|
|
3111
|
+
return (e[n] | e[n + 1] << 8 | e[n + 2] << 16) >> (t & 7);
|
|
3112
|
+
}, an = function(e) {
|
|
3113
|
+
return (e + 7) / 8 | 0;
|
|
3114
|
+
}, gt = function(e, t, n) {
|
|
3115
|
+
return (t == null || t < 0) && (t = 0), (n == null || n > e.length) && (n = e.length), new ge(e.subarray(t, n));
|
|
3116
|
+
}, no = [
|
|
3084
3117
|
"unexpected EOF",
|
|
3085
3118
|
"invalid block type",
|
|
3086
3119
|
"invalid length/literal",
|
|
@@ -3097,16 +3130,16 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3097
3130
|
"stream finishing",
|
|
3098
3131
|
"invalid zip data"
|
|
3099
3132
|
// determined by unknown compression method
|
|
3100
|
-
], xe = function(
|
|
3101
|
-
var r = new Error(
|
|
3102
|
-
if (r.code =
|
|
3133
|
+
], xe = function(e, t, n) {
|
|
3134
|
+
var r = new Error(t || no[e]);
|
|
3135
|
+
if (r.code = e, Error.captureStackTrace && Error.captureStackTrace(r, xe), !n)
|
|
3103
3136
|
throw r;
|
|
3104
3137
|
return r;
|
|
3105
|
-
},
|
|
3106
|
-
var o =
|
|
3107
|
-
if (!o ||
|
|
3138
|
+
}, ro = function(e, t, n, r) {
|
|
3139
|
+
var o = e.length, s = r ? r.length : 0;
|
|
3140
|
+
if (!o || t.f && !t.l)
|
|
3108
3141
|
return n || new ge(0);
|
|
3109
|
-
var i = !n, u = i ||
|
|
3142
|
+
var i = !n, u = i || t.i != 2, y = t.i;
|
|
3110
3143
|
i && (n = new ge(o * 3));
|
|
3111
3144
|
var v = function(O) {
|
|
3112
3145
|
var k = n.length;
|
|
@@ -3114,43 +3147,43 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3114
3147
|
var $ = new ge(Math.max(k * 2, O));
|
|
3115
3148
|
$.set(n), n = $;
|
|
3116
3149
|
}
|
|
3117
|
-
}, m =
|
|
3150
|
+
}, m = t.f || 0, l = t.p || 0, c = t.b || 0, f = t.l, h = t.d, p = t.m, g = t.n, b = o * 8;
|
|
3118
3151
|
do {
|
|
3119
3152
|
if (!f) {
|
|
3120
|
-
m = je(
|
|
3121
|
-
var
|
|
3122
|
-
if (l += 3,
|
|
3123
|
-
if (
|
|
3124
|
-
f =
|
|
3125
|
-
else if (
|
|
3126
|
-
var A = je(
|
|
3153
|
+
m = je(e, l, 1);
|
|
3154
|
+
var a = je(e, l + 1, 3);
|
|
3155
|
+
if (l += 3, a)
|
|
3156
|
+
if (a == 1)
|
|
3157
|
+
f = Qr, h = to, p = 9, g = 5;
|
|
3158
|
+
else if (a == 2) {
|
|
3159
|
+
var A = je(e, l, 31) + 257, L = je(e, l + 10, 15) + 4, z = A + je(e, l + 5, 31) + 1;
|
|
3127
3160
|
l += 14;
|
|
3128
3161
|
for (var Y = new ge(z), I = new ge(19), U = 0; U < L; ++U)
|
|
3129
|
-
I[
|
|
3162
|
+
I[Ht[U]] = je(e, l + U * 3, 7);
|
|
3130
3163
|
l += L * 3;
|
|
3131
|
-
for (var T =
|
|
3132
|
-
var C = j[je(
|
|
3164
|
+
for (var T = Nt(I), F = (1 << T) - 1, j = Ne(I, T, 1), U = 0; U < z; ) {
|
|
3165
|
+
var C = j[je(e, l, F)];
|
|
3133
3166
|
l += C & 15;
|
|
3134
3167
|
var d = C >> 4;
|
|
3135
3168
|
if (d < 16)
|
|
3136
3169
|
Y[U++] = d;
|
|
3137
3170
|
else {
|
|
3138
3171
|
var B = 0, H = 0;
|
|
3139
|
-
for (d == 16 ? (H = 3 + je(
|
|
3172
|
+
for (d == 16 ? (H = 3 + je(e, l, 3), l += 2, B = Y[U - 1]) : d == 17 ? (H = 3 + je(e, l, 7), l += 3) : d == 18 && (H = 11 + je(e, l, 127), l += 7); H--; )
|
|
3140
3173
|
Y[U++] = B;
|
|
3141
3174
|
}
|
|
3142
3175
|
}
|
|
3143
3176
|
var N = Y.subarray(0, A), ne = Y.subarray(A);
|
|
3144
|
-
p =
|
|
3177
|
+
p = Nt(N), g = Nt(ne), f = Ne(N, p, 1), h = Ne(ne, g, 1);
|
|
3145
3178
|
} else
|
|
3146
3179
|
xe(1);
|
|
3147
3180
|
else {
|
|
3148
|
-
var d = an(l) + 4, x =
|
|
3181
|
+
var d = an(l) + 4, x = e[d - 4] | e[d - 3] << 8, w = d + x;
|
|
3149
3182
|
if (w > o) {
|
|
3150
3183
|
y && xe(0);
|
|
3151
3184
|
break;
|
|
3152
3185
|
}
|
|
3153
|
-
u && v(c + x), n.set(
|
|
3186
|
+
u && v(c + x), n.set(e.subarray(d, w), c), t.b = c += x, t.p = l = w * 8, t.f = m;
|
|
3154
3187
|
continue;
|
|
3155
3188
|
}
|
|
3156
3189
|
if (l > b) {
|
|
@@ -3160,7 +3193,7 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3160
3193
|
}
|
|
3161
3194
|
u && v(c + 131072);
|
|
3162
3195
|
for (var Q = (1 << p) - 1, J = (1 << g) - 1, X = l; ; X = l) {
|
|
3163
|
-
var B = f[
|
|
3196
|
+
var B = f[Xt(e, l) & Q], G = B >> 4;
|
|
3164
3197
|
if (l += B & 15, l > b) {
|
|
3165
3198
|
y && xe(0);
|
|
3166
3199
|
break;
|
|
@@ -3173,15 +3206,15 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3173
3206
|
} else {
|
|
3174
3207
|
var re = G - 254;
|
|
3175
3208
|
if (G > 264) {
|
|
3176
|
-
var U = G - 257, W =
|
|
3177
|
-
re = je(
|
|
3209
|
+
var U = G - 257, W = Tt[U];
|
|
3210
|
+
re = je(e, l, (1 << W) - 1) + zn[U], l += W;
|
|
3178
3211
|
}
|
|
3179
|
-
var te = h[
|
|
3212
|
+
var te = h[Xt(e, l) & J], ae = te >> 4;
|
|
3180
3213
|
te || xe(3), l += te & 15;
|
|
3181
|
-
var ne =
|
|
3182
|
-
if (
|
|
3183
|
-
var W =
|
|
3184
|
-
ne +=
|
|
3214
|
+
var ne = Jr[ae];
|
|
3215
|
+
if (ae > 3) {
|
|
3216
|
+
var W = Rt[ae];
|
|
3217
|
+
ne += Xt(e, l) & (1 << W) - 1, l += W;
|
|
3185
3218
|
}
|
|
3186
3219
|
if (l > b) {
|
|
3187
3220
|
y && xe(0);
|
|
@@ -3190,7 +3223,7 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3190
3223
|
u && v(c + 131072);
|
|
3191
3224
|
var V = c + re;
|
|
3192
3225
|
if (c < ne) {
|
|
3193
|
-
var M =
|
|
3226
|
+
var M = s - ne, E = Math.min(ne, V);
|
|
3194
3227
|
for (M + c < 0 && xe(3); c < E; ++c)
|
|
3195
3228
|
n[c] = r[M + c];
|
|
3196
3229
|
}
|
|
@@ -3198,23 +3231,23 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3198
3231
|
n[c] = n[c - ne];
|
|
3199
3232
|
}
|
|
3200
3233
|
}
|
|
3201
|
-
|
|
3234
|
+
t.l = f, t.p = X, t.b = c, t.f = m, f && (m = 1, t.m = p, t.d = h, t.n = g);
|
|
3202
3235
|
} while (!m);
|
|
3203
3236
|
return c != n.length && i ? gt(n, 0, c) : n.subarray(0, c);
|
|
3204
|
-
}, Ce = function(
|
|
3205
|
-
n <<=
|
|
3206
|
-
var r =
|
|
3207
|
-
|
|
3208
|
-
}, ht = function(
|
|
3209
|
-
n <<=
|
|
3210
|
-
var r =
|
|
3211
|
-
|
|
3212
|
-
},
|
|
3213
|
-
for (var n = [], r = 0; r <
|
|
3214
|
-
|
|
3215
|
-
var o = n.length,
|
|
3237
|
+
}, Ce = function(e, t, n) {
|
|
3238
|
+
n <<= t & 7;
|
|
3239
|
+
var r = t / 8 | 0;
|
|
3240
|
+
e[r] |= n, e[r + 1] |= n >> 8;
|
|
3241
|
+
}, ht = function(e, t, n) {
|
|
3242
|
+
n <<= t & 7;
|
|
3243
|
+
var r = t / 8 | 0;
|
|
3244
|
+
e[r] |= n, e[r + 1] |= n >> 8, e[r + 2] |= n >> 16;
|
|
3245
|
+
}, zt = function(e, t) {
|
|
3246
|
+
for (var n = [], r = 0; r < e.length; ++r)
|
|
3247
|
+
e[r] && n.push({ s: r, f: e[r] });
|
|
3248
|
+
var o = n.length, s = n.slice();
|
|
3216
3249
|
if (!o)
|
|
3217
|
-
return { t:
|
|
3250
|
+
return { t: Pn, l: 0 };
|
|
3218
3251
|
if (o == 1) {
|
|
3219
3252
|
var i = new ge(n[0].s + 1);
|
|
3220
3253
|
return i[n[0].s] = 1, { t: i, l: 1 };
|
|
@@ -3225,115 +3258,115 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3225
3258
|
var u = n[0], y = n[1], v = 0, m = 1, l = 2;
|
|
3226
3259
|
for (n[0] = { s: -1, f: u.f + y.f, l: u, r: y }; m != o - 1; )
|
|
3227
3260
|
u = n[n[v].f < n[l].f ? v++ : l++], y = n[v != m && n[v].f < n[l].f ? v++ : l++], n[m++] = { s: -1, f: u.f + y.f, l: u, r: y };
|
|
3228
|
-
for (var c =
|
|
3229
|
-
|
|
3230
|
-
var f = new Re(c + 1), h =
|
|
3231
|
-
if (h >
|
|
3232
|
-
var r = 0, p = 0, g = h -
|
|
3233
|
-
for (
|
|
3261
|
+
for (var c = s[0].s, r = 1; r < o; ++r)
|
|
3262
|
+
s[r].s > c && (c = s[r].s);
|
|
3263
|
+
var f = new Re(c + 1), h = Wt(n[m - 1], f, 0);
|
|
3264
|
+
if (h > t) {
|
|
3265
|
+
var r = 0, p = 0, g = h - t, b = 1 << g;
|
|
3266
|
+
for (s.sort(function(A, L) {
|
|
3234
3267
|
return f[L.s] - f[A.s] || A.f - L.f;
|
|
3235
3268
|
}); r < o; ++r) {
|
|
3236
|
-
var
|
|
3237
|
-
if (f[
|
|
3238
|
-
p += b - (1 << h - f[
|
|
3269
|
+
var a = s[r].s;
|
|
3270
|
+
if (f[a] > t)
|
|
3271
|
+
p += b - (1 << h - f[a]), f[a] = t;
|
|
3239
3272
|
else
|
|
3240
3273
|
break;
|
|
3241
3274
|
}
|
|
3242
3275
|
for (p >>= g; p > 0; ) {
|
|
3243
|
-
var d =
|
|
3244
|
-
f[d] <
|
|
3276
|
+
var d = s[r].s;
|
|
3277
|
+
f[d] < t ? p -= 1 << t - f[d]++ - 1 : ++r;
|
|
3245
3278
|
}
|
|
3246
3279
|
for (; r >= 0 && p; --r) {
|
|
3247
|
-
var x =
|
|
3248
|
-
f[x] ==
|
|
3280
|
+
var x = s[r].s;
|
|
3281
|
+
f[x] == t && (--f[x], ++p);
|
|
3249
3282
|
}
|
|
3250
|
-
h =
|
|
3283
|
+
h = t;
|
|
3251
3284
|
}
|
|
3252
3285
|
return { t: new ge(f), l: h };
|
|
3253
|
-
},
|
|
3254
|
-
return
|
|
3255
|
-
},
|
|
3256
|
-
for (var
|
|
3286
|
+
}, Wt = function(e, t, n) {
|
|
3287
|
+
return e.s == -1 ? Math.max(Wt(e.l, t, n + 1), Wt(e.r, t, n + 1)) : t[e.s] = n;
|
|
3288
|
+
}, En = function(e) {
|
|
3289
|
+
for (var t = e.length; t && !e[--t]; )
|
|
3257
3290
|
;
|
|
3258
|
-
for (var n = new Re(++
|
|
3291
|
+
for (var n = new Re(++t), r = 0, o = e[0], s = 1, i = function(y) {
|
|
3259
3292
|
n[r++] = y;
|
|
3260
|
-
}, u = 1; u <=
|
|
3261
|
-
if (
|
|
3262
|
-
++
|
|
3293
|
+
}, u = 1; u <= t; ++u)
|
|
3294
|
+
if (e[u] == o && u != t)
|
|
3295
|
+
++s;
|
|
3263
3296
|
else {
|
|
3264
|
-
if (!o &&
|
|
3265
|
-
for (;
|
|
3297
|
+
if (!o && s > 2) {
|
|
3298
|
+
for (; s > 138; s -= 138)
|
|
3266
3299
|
i(32754);
|
|
3267
|
-
|
|
3268
|
-
} else if (
|
|
3269
|
-
for (i(o), --
|
|
3300
|
+
s > 2 && (i(s > 10 ? s - 11 << 5 | 28690 : s - 3 << 5 | 12305), s = 0);
|
|
3301
|
+
} else if (s > 3) {
|
|
3302
|
+
for (i(o), --s; s > 6; s -= 6)
|
|
3270
3303
|
i(8304);
|
|
3271
|
-
|
|
3304
|
+
s > 2 && (i(s - 3 << 5 | 8208), s = 0);
|
|
3272
3305
|
}
|
|
3273
|
-
for (;
|
|
3306
|
+
for (; s--; )
|
|
3274
3307
|
i(o);
|
|
3275
|
-
|
|
3308
|
+
s = 1, o = e[u];
|
|
3276
3309
|
}
|
|
3277
|
-
return { c: n.subarray(0, r), n:
|
|
3278
|
-
}, ut = function(
|
|
3279
|
-
for (var n = 0, r = 0; r <
|
|
3280
|
-
n +=
|
|
3310
|
+
return { c: n.subarray(0, r), n: t };
|
|
3311
|
+
}, ut = function(e, t) {
|
|
3312
|
+
for (var n = 0, r = 0; r < t.length; ++r)
|
|
3313
|
+
n += e[r] * t[r];
|
|
3281
3314
|
return n;
|
|
3282
|
-
},
|
|
3283
|
-
var r = n.length, o = an(
|
|
3284
|
-
|
|
3285
|
-
for (var
|
|
3286
|
-
|
|
3315
|
+
}, Dn = function(e, t, n) {
|
|
3316
|
+
var r = n.length, o = an(t + 2);
|
|
3317
|
+
e[o] = r & 255, e[o + 1] = r >> 8, e[o + 2] = e[o] ^ 255, e[o + 3] = e[o + 1] ^ 255;
|
|
3318
|
+
for (var s = 0; s < r; ++s)
|
|
3319
|
+
e[o + s + 4] = n[s];
|
|
3287
3320
|
return (o + 4 + r) * 8;
|
|
3288
|
-
},
|
|
3289
|
-
Ce(
|
|
3290
|
-
for (var l =
|
|
3291
|
-
++L[
|
|
3321
|
+
}, Sn = function(e, t, n, r, o, s, i, u, y, v, m) {
|
|
3322
|
+
Ce(t, m++, n), ++o[256];
|
|
3323
|
+
for (var l = zt(o, 15), c = l.t, f = l.l, h = zt(s, 15), p = h.t, g = h.l, b = En(c), a = b.c, d = b.n, x = En(p), w = x.c, A = x.n, L = new Re(19), z = 0; z < a.length; ++z)
|
|
3324
|
+
++L[a[z] & 31];
|
|
3292
3325
|
for (var z = 0; z < w.length; ++z)
|
|
3293
3326
|
++L[w[z] & 31];
|
|
3294
|
-
for (var Y =
|
|
3327
|
+
for (var Y = zt(L, 7), I = Y.t, U = Y.l, T = 19; T > 4 && !I[Ht[T - 1]]; --T)
|
|
3295
3328
|
;
|
|
3296
|
-
var F = v + 5 << 3, j = ut(o, Ve) + ut(
|
|
3329
|
+
var F = v + 5 << 3, j = ut(o, Ve) + ut(s, dt) + i, C = ut(o, c) + ut(s, p) + i + 14 + 3 * T + ut(L, I) + 2 * L[16] + 3 * L[17] + 7 * L[18];
|
|
3297
3330
|
if (y >= 0 && F <= j && F <= C)
|
|
3298
|
-
return
|
|
3331
|
+
return Dn(t, m, e.subarray(y, y + v));
|
|
3299
3332
|
var B, H, N, ne;
|
|
3300
|
-
if (Ce(
|
|
3333
|
+
if (Ce(t, m, 1 + (C < j)), m += 2, C < j) {
|
|
3301
3334
|
B = Ne(c, f, 0), H = c, N = Ne(p, g, 0), ne = p;
|
|
3302
3335
|
var Q = Ne(I, U, 0);
|
|
3303
|
-
Ce(
|
|
3336
|
+
Ce(t, m, d - 257), Ce(t, m + 5, A - 1), Ce(t, m + 10, T - 4), m += 14;
|
|
3304
3337
|
for (var z = 0; z < T; ++z)
|
|
3305
|
-
Ce(
|
|
3338
|
+
Ce(t, m + 3 * z, I[Ht[z]]);
|
|
3306
3339
|
m += 3 * T;
|
|
3307
|
-
for (var J = [
|
|
3340
|
+
for (var J = [a, w], X = 0; X < 2; ++X)
|
|
3308
3341
|
for (var G = J[X], z = 0; z < G.length; ++z) {
|
|
3309
3342
|
var re = G[z] & 31;
|
|
3310
|
-
Ce(
|
|
3343
|
+
Ce(t, m, Q[re]), m += I[re], re > 15 && (Ce(t, m, G[z] >> 5 & 127), m += G[z] >> 12);
|
|
3311
3344
|
}
|
|
3312
3345
|
} else
|
|
3313
|
-
B =
|
|
3346
|
+
B = Kr, H = Ve, N = eo, ne = dt;
|
|
3314
3347
|
for (var z = 0; z < u; ++z) {
|
|
3315
3348
|
var W = r[z];
|
|
3316
3349
|
if (W > 255) {
|
|
3317
3350
|
var re = W >> 18 & 31;
|
|
3318
|
-
ht(
|
|
3351
|
+
ht(t, m, B[re + 257]), m += H[re + 257], re > 7 && (Ce(t, m, W >> 23 & 31), m += Tt[re]);
|
|
3319
3352
|
var te = W & 31;
|
|
3320
|
-
ht(
|
|
3353
|
+
ht(t, m, N[te]), m += ne[te], te > 3 && (ht(t, m, W >> 5 & 8191), m += Rt[te]);
|
|
3321
3354
|
} else
|
|
3322
|
-
ht(
|
|
3323
|
-
}
|
|
3324
|
-
return ht(
|
|
3325
|
-
},
|
|
3326
|
-
var i =
|
|
3327
|
-
if (
|
|
3328
|
-
m && (y[0] =
|
|
3329
|
-
for (var l =
|
|
3330
|
-
return (
|
|
3331
|
-
}, x = new
|
|
3355
|
+
ht(t, m, B[W]), m += H[W];
|
|
3356
|
+
}
|
|
3357
|
+
return ht(t, m, B[256]), m + H[256];
|
|
3358
|
+
}, oo = /* @__PURE__ */ new sn([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]), Pn = /* @__PURE__ */ new ge(0), so = function(e, t, n, r, o, s) {
|
|
3359
|
+
var i = s.z || e.length, u = new ge(r + i + 5 * (1 + Math.ceil(i / 7e3)) + o), y = u.subarray(r, u.length - o), v = s.l, m = (s.r || 0) & 7;
|
|
3360
|
+
if (t) {
|
|
3361
|
+
m && (y[0] = s.r >> 3);
|
|
3362
|
+
for (var l = oo[t - 1], c = l >> 13, f = l & 8191, h = (1 << n) - 1, p = s.p || new Re(32768), g = s.h || new Re(h + 1), b = Math.ceil(n / 3), a = 2 * b, d = function(Z) {
|
|
3363
|
+
return (e[Z] ^ e[Z + 1] << b ^ e[Z + 2] << a) & h;
|
|
3364
|
+
}, x = new sn(25e3), w = new Re(288), A = new Re(32), L = 0, z = 0, Y = s.i || 0, I = 0, U = s.w || 0, T = 0; Y + 2 < i; ++Y) {
|
|
3332
3365
|
var F = d(Y), j = Y & 32767, C = g[F];
|
|
3333
3366
|
if (p[j] = C, g[F] = j, U <= Y) {
|
|
3334
3367
|
var B = i - Y;
|
|
3335
3368
|
if ((L > 7e3 || I > 24576) && (B > 423 || !v)) {
|
|
3336
|
-
m =
|
|
3369
|
+
m = Sn(e, y, 0, x, w, A, z, I, T, Y - T, m), I = L = z = 0, T = Y;
|
|
3337
3370
|
for (var H = 0; H < 286; ++H)
|
|
3338
3371
|
w[H] = 0;
|
|
3339
3372
|
for (var H = 0; H < 30; ++H)
|
|
@@ -3342,183 +3375,183 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
|
|
|
3342
3375
|
var N = 2, ne = 0, Q = f, J = j - C & 32767;
|
|
3343
3376
|
if (B > 2 && F == d(Y - J))
|
|
3344
3377
|
for (var X = Math.min(c, B) - 1, G = Math.min(32767, Y), re = Math.min(258, B); J <= G && --Q && j != C; ) {
|
|
3345
|
-
if (
|
|
3346
|
-
for (var W = 0; W < re &&
|
|
3378
|
+
if (e[Y + N] == e[Y + N - J]) {
|
|
3379
|
+
for (var W = 0; W < re && e[Y + W] == e[Y + W - J]; ++W)
|
|
3347
3380
|
;
|
|
3348
3381
|
if (W > N) {
|
|
3349
3382
|
if (N = W, ne = J, W > X)
|
|
3350
3383
|
break;
|
|
3351
|
-
for (var te = Math.min(J, W - 2),
|
|
3384
|
+
for (var te = Math.min(J, W - 2), ae = 0, H = 0; H < te; ++H) {
|
|
3352
3385
|
var V = Y - J + H & 32767, M = p[V], E = V - M & 32767;
|
|
3353
|
-
E >
|
|
3386
|
+
E > ae && (ae = E, C = V);
|
|
3354
3387
|
}
|
|
3355
3388
|
}
|
|
3356
3389
|
}
|
|
3357
3390
|
j = C, C = p[j], J += j - C & 32767;
|
|
3358
3391
|
}
|
|
3359
3392
|
if (ne) {
|
|
3360
|
-
x[I++] = 268435456 |
|
|
3361
|
-
var O =
|
|
3362
|
-
z +=
|
|
3393
|
+
x[I++] = 268435456 | Vt[N] << 18 | An[ne];
|
|
3394
|
+
var O = Vt[N] & 31, k = An[ne] & 31;
|
|
3395
|
+
z += Tt[O] + Rt[k], ++w[257 + O], ++A[k], U = Y + N, ++L;
|
|
3363
3396
|
} else
|
|
3364
|
-
x[I++] =
|
|
3397
|
+
x[I++] = e[Y], ++w[e[Y]];
|
|
3365
3398
|
}
|
|
3366
3399
|
}
|
|
3367
3400
|
for (Y = Math.max(Y, U); Y < i; ++Y)
|
|
3368
|
-
x[I++] =
|
|
3369
|
-
m =
|
|
3401
|
+
x[I++] = e[Y], ++w[e[Y]];
|
|
3402
|
+
m = Sn(e, y, v, x, w, A, z, I, T, Y - T, m), v || (s.r = m & 7 | y[m / 8 | 0] << 3, m -= 7, s.h = g, s.p = p, s.i = Y, s.w = U);
|
|
3370
3403
|
} else {
|
|
3371
|
-
for (var Y =
|
|
3404
|
+
for (var Y = s.w || 0; Y < i + v; Y += 65535) {
|
|
3372
3405
|
var $ = Y + 65535;
|
|
3373
|
-
$ >= i && (y[m / 8 | 0] = v, $ = i), m =
|
|
3406
|
+
$ >= i && (y[m / 8 | 0] = v, $ = i), m = Dn(y, m + 1, e.subarray(Y, $));
|
|
3374
3407
|
}
|
|
3375
|
-
|
|
3408
|
+
s.i = i;
|
|
3376
3409
|
}
|
|
3377
3410
|
return gt(u, 0, r + an(m) + o);
|
|
3378
|
-
},
|
|
3379
|
-
for (var
|
|
3380
|
-
for (var n =
|
|
3411
|
+
}, ao = /* @__PURE__ */ (function() {
|
|
3412
|
+
for (var e = new Int32Array(256), t = 0; t < 256; ++t) {
|
|
3413
|
+
for (var n = t, r = 9; --r; )
|
|
3381
3414
|
n = (n & 1 && -306674912) ^ n >>> 1;
|
|
3382
|
-
t
|
|
3415
|
+
e[t] = n;
|
|
3383
3416
|
}
|
|
3384
|
-
return
|
|
3385
|
-
})(),
|
|
3386
|
-
var
|
|
3417
|
+
return e;
|
|
3418
|
+
})(), io = function() {
|
|
3419
|
+
var e = -1;
|
|
3387
3420
|
return {
|
|
3388
|
-
p: function(
|
|
3389
|
-
for (var n =
|
|
3390
|
-
n =
|
|
3391
|
-
|
|
3421
|
+
p: function(t) {
|
|
3422
|
+
for (var n = e, r = 0; r < t.length; ++r)
|
|
3423
|
+
n = ao[n & 255 ^ t[r]] ^ n >>> 8;
|
|
3424
|
+
e = n;
|
|
3392
3425
|
},
|
|
3393
3426
|
d: function() {
|
|
3394
|
-
return ~
|
|
3427
|
+
return ~e;
|
|
3395
3428
|
}
|
|
3396
3429
|
};
|
|
3397
|
-
},
|
|
3398
|
-
if (!o && (o = { l: 1 },
|
|
3399
|
-
var
|
|
3400
|
-
i.set(
|
|
3430
|
+
}, lo = function(e, t, n, r, o) {
|
|
3431
|
+
if (!o && (o = { l: 1 }, t.dictionary)) {
|
|
3432
|
+
var s = t.dictionary.subarray(-32768), i = new ge(s.length + e.length);
|
|
3433
|
+
i.set(s), i.set(e, s.length), e = i, o.w = s.length;
|
|
3401
3434
|
}
|
|
3402
|
-
return
|
|
3403
|
-
},
|
|
3435
|
+
return so(e, t.level == null ? 6 : t.level, t.mem == null ? o.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(e.length))) * 1.5) : 20 : 12 + t.mem, n, r, o);
|
|
3436
|
+
}, Hn = function(e, t) {
|
|
3404
3437
|
var n = {};
|
|
3405
|
-
for (var r in t)
|
|
3406
|
-
n[r] = t[r];
|
|
3407
3438
|
for (var r in e)
|
|
3408
3439
|
n[r] = e[r];
|
|
3440
|
+
for (var r in t)
|
|
3441
|
+
n[r] = t[r];
|
|
3409
3442
|
return n;
|
|
3410
|
-
}, Ie = function(
|
|
3411
|
-
return t
|
|
3412
|
-
}, Fe = function(
|
|
3413
|
-
return (t
|
|
3414
|
-
},
|
|
3415
|
-
return Fe(
|
|
3416
|
-
}, ve = function(
|
|
3417
|
-
for (; n; ++
|
|
3418
|
-
t
|
|
3443
|
+
}, Ie = function(e, t) {
|
|
3444
|
+
return e[t] | e[t + 1] << 8;
|
|
3445
|
+
}, Fe = function(e, t) {
|
|
3446
|
+
return (e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24) >>> 0;
|
|
3447
|
+
}, Ct = function(e, t) {
|
|
3448
|
+
return Fe(e, t) + Fe(e, t + 4) * 4294967296;
|
|
3449
|
+
}, ve = function(e, t, n) {
|
|
3450
|
+
for (; n; ++t)
|
|
3451
|
+
e[t] = n, n >>>= 8;
|
|
3419
3452
|
};
|
|
3420
|
-
function
|
|
3421
|
-
return
|
|
3453
|
+
function co(e, t) {
|
|
3454
|
+
return lo(e, t || {}, 0, 0);
|
|
3422
3455
|
}
|
|
3423
|
-
function
|
|
3424
|
-
return
|
|
3456
|
+
function ho(e, t) {
|
|
3457
|
+
return ro(e, { i: 2 }, t && t.out, t && t.dictionary);
|
|
3425
3458
|
}
|
|
3426
|
-
var
|
|
3427
|
-
for (var o in
|
|
3428
|
-
var
|
|
3429
|
-
Array.isArray(
|
|
3459
|
+
var Vn = function(e, t, n, r) {
|
|
3460
|
+
for (var o in e) {
|
|
3461
|
+
var s = e[o], i = t + o, u = r;
|
|
3462
|
+
Array.isArray(s) && (u = Hn(r, s[1]), s = s[0]), ArrayBuffer.isView(s) ? n[i] = [s, u] : (n[i += "/"] = [new ge(0), u], Vn(s, i, n, r));
|
|
3430
3463
|
}
|
|
3431
|
-
},
|
|
3464
|
+
}, On = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), Gt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), uo = 0;
|
|
3432
3465
|
try {
|
|
3433
|
-
|
|
3466
|
+
Gt.decode(Pn, { stream: !0 }), uo = 1;
|
|
3434
3467
|
} catch {
|
|
3435
3468
|
}
|
|
3436
|
-
var
|
|
3437
|
-
for (var
|
|
3438
|
-
var r =
|
|
3439
|
-
if (n + o >
|
|
3440
|
-
return { s:
|
|
3441
|
-
o ? o == 3 ? (r = ((r & 15) << 18 | (
|
|
3469
|
+
var fo = function(e) {
|
|
3470
|
+
for (var t = "", n = 0; ; ) {
|
|
3471
|
+
var r = e[n++], o = (r > 127) + (r > 223) + (r > 239);
|
|
3472
|
+
if (n + o > e.length)
|
|
3473
|
+
return { s: t, r: gt(e, n - 1) };
|
|
3474
|
+
o ? o == 3 ? (r = ((r & 15) << 18 | (e[n++] & 63) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) - 65536, t += String.fromCharCode(55296 | r >> 10, 56320 | r & 1023)) : o & 1 ? t += String.fromCharCode((r & 31) << 6 | e[n++] & 63) : t += String.fromCharCode((r & 15) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) : t += String.fromCharCode(r);
|
|
3442
3475
|
}
|
|
3443
3476
|
};
|
|
3444
|
-
function
|
|
3477
|
+
function Tn(e, t) {
|
|
3445
3478
|
var n;
|
|
3446
|
-
if (
|
|
3447
|
-
return
|
|
3448
|
-
for (var r =
|
|
3449
|
-
o[
|
|
3479
|
+
if (On)
|
|
3480
|
+
return On.encode(e);
|
|
3481
|
+
for (var r = e.length, o = new ge(e.length + (e.length >> 1)), s = 0, i = function(v) {
|
|
3482
|
+
o[s++] = v;
|
|
3450
3483
|
}, n = 0; n < r; ++n) {
|
|
3451
|
-
if (
|
|
3452
|
-
var u = new ge(
|
|
3484
|
+
if (s + 5 > o.length) {
|
|
3485
|
+
var u = new ge(s + 8 + (r - n << 1));
|
|
3453
3486
|
u.set(o), o = u;
|
|
3454
3487
|
}
|
|
3455
|
-
var y =
|
|
3456
|
-
y < 128 ||
|
|
3488
|
+
var y = e.charCodeAt(n);
|
|
3489
|
+
y < 128 || t ? i(y) : y < 2048 ? (i(192 | y >> 6), i(128 | y & 63)) : y > 55295 && y < 57344 ? (y = 65536 + (y & 1047552) | e.charCodeAt(++n) & 1023, i(240 | y >> 18), i(128 | y >> 12 & 63), i(128 | y >> 6 & 63), i(128 | y & 63)) : (i(224 | y >> 12), i(128 | y >> 6 & 63), i(128 | y & 63));
|
|
3457
3490
|
}
|
|
3458
|
-
return gt(o, 0,
|
|
3491
|
+
return gt(o, 0, s);
|
|
3459
3492
|
}
|
|
3460
|
-
function
|
|
3461
|
-
if (
|
|
3462
|
-
for (var n = "", r = 0; r <
|
|
3463
|
-
n += String.fromCharCode.apply(null,
|
|
3493
|
+
function mo(e, t) {
|
|
3494
|
+
if (t) {
|
|
3495
|
+
for (var n = "", r = 0; r < e.length; r += 16384)
|
|
3496
|
+
n += String.fromCharCode.apply(null, e.subarray(r, r + 16384));
|
|
3464
3497
|
return n;
|
|
3465
3498
|
} else {
|
|
3466
|
-
if (
|
|
3467
|
-
return
|
|
3468
|
-
var o =
|
|
3469
|
-
return n.length && xe(8),
|
|
3470
|
-
}
|
|
3471
|
-
}
|
|
3472
|
-
var
|
|
3473
|
-
return
|
|
3474
|
-
},
|
|
3475
|
-
var r = Ie(
|
|
3476
|
-
return [Ie(
|
|
3477
|
-
},
|
|
3478
|
-
var u = o == 4294967295, y =
|
|
3499
|
+
if (Gt)
|
|
3500
|
+
return Gt.decode(e);
|
|
3501
|
+
var o = fo(e), s = o.s, n = o.r;
|
|
3502
|
+
return n.length && xe(8), s;
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
var po = function(e, t) {
|
|
3506
|
+
return t + 30 + Ie(e, t + 26) + Ie(e, t + 28);
|
|
3507
|
+
}, go = function(e, t, n) {
|
|
3508
|
+
var r = Ie(e, t + 28), o = Ie(e, t + 30), s = mo(e.subarray(t + 46, t + 46 + r), !(Ie(e, t + 8) & 2048)), i = t + 46 + r, u = yo(e, i, o, n, Fe(e, t + 20), Fe(e, t + 24), Fe(e, t + 42)), y = u[0], v = u[1], m = u[2];
|
|
3509
|
+
return [Ie(e, t + 10), y, v, s, i + o + Ie(e, t + 32), m];
|
|
3510
|
+
}, yo = function(e, t, n, r, o, s, i) {
|
|
3511
|
+
var u = o == 4294967295, y = s == 4294967295, v = i == 4294967295, m = t + n, l = u + y + v;
|
|
3479
3512
|
if (r && l) {
|
|
3480
|
-
for (;
|
|
3481
|
-
if (Ie(
|
|
3513
|
+
for (; t + 4 < m; t += 4 + Ie(e, t + 2))
|
|
3514
|
+
if (Ie(e, t) == 1)
|
|
3482
3515
|
return [
|
|
3483
|
-
u ?
|
|
3484
|
-
y ?
|
|
3485
|
-
v ?
|
|
3516
|
+
u ? Ct(e, t + 4 + 8 * y) : o,
|
|
3517
|
+
y ? Ct(e, t + 4) : s,
|
|
3518
|
+
v ? Ct(e, t + 4 + 8 * (y + u)) : i,
|
|
3486
3519
|
1
|
|
3487
3520
|
];
|
|
3488
3521
|
r < 2 && xe(13);
|
|
3489
3522
|
}
|
|
3490
|
-
return [o,
|
|
3491
|
-
},
|
|
3492
|
-
var
|
|
3493
|
-
if (
|
|
3494
|
-
for (var n in
|
|
3495
|
-
var r =
|
|
3496
|
-
r > 65535 && xe(9),
|
|
3523
|
+
return [o, s, i, 0];
|
|
3524
|
+
}, qt = function(e) {
|
|
3525
|
+
var t = 0;
|
|
3526
|
+
if (e)
|
|
3527
|
+
for (var n in e) {
|
|
3528
|
+
var r = e[n].length;
|
|
3529
|
+
r > 65535 && xe(9), t += r + 4;
|
|
3497
3530
|
}
|
|
3498
|
-
return
|
|
3499
|
-
},
|
|
3500
|
-
var y = r.length, v = n.extra, m = u && u.length, l =
|
|
3501
|
-
ve(
|
|
3531
|
+
return t;
|
|
3532
|
+
}, Rn = function(e, t, n, r, o, s, i, u) {
|
|
3533
|
+
var y = r.length, v = n.extra, m = u && u.length, l = qt(v);
|
|
3534
|
+
ve(e, t, i != null ? 33639248 : 67324752), t += 4, i != null && (e[t++] = 20, e[t++] = n.os), e[t] = 20, t += 2, e[t++] = n.flag << 1 | (s < 0 && 8), e[t++] = o && 8, e[t++] = n.compression & 255, e[t++] = n.compression >> 8;
|
|
3502
3535
|
var c = new Date(n.mtime == null ? Date.now() : n.mtime), f = c.getFullYear() - 1980;
|
|
3503
|
-
if ((f < 0 || f > 119) && xe(10), ve(
|
|
3536
|
+
if ((f < 0 || f > 119) && xe(10), ve(e, t, f << 25 | c.getMonth() + 1 << 21 | c.getDate() << 16 | c.getHours() << 11 | c.getMinutes() << 5 | c.getSeconds() >> 1), t += 4, s != -1 && (ve(e, t, n.crc), ve(e, t + 4, s < 0 ? -s - 2 : s), ve(e, t + 8, n.size)), ve(e, t + 12, y), ve(e, t + 14, l), t += 16, i != null && (ve(e, t, m), ve(e, t + 6, n.attrs), ve(e, t + 10, i), t += 14), e.set(r, t), t += y, l)
|
|
3504
3537
|
for (var h in v) {
|
|
3505
3538
|
var p = v[h], g = p.length;
|
|
3506
|
-
ve(
|
|
3539
|
+
ve(e, t, +h), ve(e, t + 2, g), e.set(p, t + 4), t += 4 + g;
|
|
3507
3540
|
}
|
|
3508
|
-
return m && (
|
|
3509
|
-
},
|
|
3510
|
-
ve(
|
|
3541
|
+
return m && (e.set(u, t), t += m), t;
|
|
3542
|
+
}, vo = function(e, t, n, r, o) {
|
|
3543
|
+
ve(e, t, 101010256), ve(e, t + 8, n), ve(e, t + 10, n), ve(e, t + 12, r), ve(e, t + 16, o);
|
|
3511
3544
|
};
|
|
3512
|
-
function
|
|
3513
|
-
|
|
3545
|
+
function bo(e, t) {
|
|
3546
|
+
t || (t = {});
|
|
3514
3547
|
var n = {}, r = [];
|
|
3515
|
-
|
|
3516
|
-
var o = 0,
|
|
3548
|
+
Vn(e, "", n, t);
|
|
3549
|
+
var o = 0, s = 0;
|
|
3517
3550
|
for (var i in n) {
|
|
3518
|
-
var u = n[i], y = u[0], v = u[1], m = v.level == 0 ? 0 : 8, l =
|
|
3551
|
+
var u = n[i], y = u[0], v = u[1], m = v.level == 0 ? 0 : 8, l = Tn(i), c = l.length, f = v.comment, h = f && Tn(f), p = h && h.length, g = qt(v.extra);
|
|
3519
3552
|
c > 65535 && xe(11);
|
|
3520
|
-
var b = m ?
|
|
3521
|
-
d.p(y), r.push(
|
|
3553
|
+
var b = m ? co(y, v) : y, a = b.length, d = io();
|
|
3554
|
+
d.p(y), r.push(Hn(v, {
|
|
3522
3555
|
size: y.length,
|
|
3523
3556
|
crc: d.d(),
|
|
3524
3557
|
c: b,
|
|
@@ -3527,53 +3560,53 @@ function go(t, e) {
|
|
|
3527
3560
|
u: c != i.length || h && f.length != p,
|
|
3528
3561
|
o,
|
|
3529
3562
|
compression: m
|
|
3530
|
-
})), o += 30 + c + g +
|
|
3563
|
+
})), o += 30 + c + g + a, s += 76 + 2 * (c + g) + (p || 0) + a;
|
|
3531
3564
|
}
|
|
3532
|
-
for (var x = new ge(
|
|
3565
|
+
for (var x = new ge(s + 22), w = o, A = s - o, L = 0; L < r.length; ++L) {
|
|
3533
3566
|
var l = r[L];
|
|
3534
|
-
|
|
3535
|
-
var z = 30 + l.f.length +
|
|
3536
|
-
x.set(l.c, l.o + z),
|
|
3567
|
+
Rn(x, l.o, l, l.f, l.u, l.c.length);
|
|
3568
|
+
var z = 30 + l.f.length + qt(l.extra);
|
|
3569
|
+
x.set(l.c, l.o + z), Rn(x, o, l, l.f, l.u, l.c.length, l.o, l.m), o += 16 + z + (l.m ? l.m.length : 0);
|
|
3537
3570
|
}
|
|
3538
|
-
return
|
|
3571
|
+
return vo(x, o, r.length, A, w), x;
|
|
3539
3572
|
}
|
|
3540
|
-
function
|
|
3541
|
-
for (var n = {}, r =
|
|
3542
|
-
(!r ||
|
|
3543
|
-
var o = Ie(
|
|
3573
|
+
function wo(e, t) {
|
|
3574
|
+
for (var n = {}, r = e.length - 22; Fe(e, r) != 101010256; --r)
|
|
3575
|
+
(!r || e.length - r > 65558) && xe(13);
|
|
3576
|
+
var o = Ie(e, r + 8);
|
|
3544
3577
|
if (!o)
|
|
3545
3578
|
return {};
|
|
3546
|
-
var
|
|
3579
|
+
var s = Fe(e, r + 16), i = Fe(e, r - 20) == 117853008;
|
|
3547
3580
|
if (i) {
|
|
3548
|
-
var u = Fe(
|
|
3549
|
-
i = Fe(
|
|
3581
|
+
var u = Fe(e, r - 12);
|
|
3582
|
+
i = Fe(e, u) == 101075792, i && (o = Fe(e, u + 32), s = Fe(e, u + 48));
|
|
3550
3583
|
}
|
|
3551
|
-
for (var y =
|
|
3552
|
-
var m =
|
|
3553
|
-
|
|
3584
|
+
for (var y = t && t.filter, v = 0; v < o; ++v) {
|
|
3585
|
+
var m = go(e, s, i), l = m[0], c = m[1], f = m[2], h = m[3], p = m[4], g = m[5], b = po(e, g);
|
|
3586
|
+
s = p, (!y || y({
|
|
3554
3587
|
name: h,
|
|
3555
3588
|
size: c,
|
|
3556
3589
|
originalSize: f,
|
|
3557
3590
|
compression: l
|
|
3558
|
-
})) && (l ? l == 8 ? n[h] =
|
|
3591
|
+
})) && (l ? l == 8 ? n[h] = ho(e.subarray(b, b + c), { out: new ge(f) }) : xe(14, "unknown compression type " + l) : n[h] = gt(e, b, b + c));
|
|
3559
3592
|
}
|
|
3560
3593
|
return n;
|
|
3561
3594
|
}
|
|
3562
|
-
const St = 200,
|
|
3563
|
-
function
|
|
3564
|
-
if (!
|
|
3565
|
-
throw new Error(`ZIP entry ${JSON.stringify(
|
|
3595
|
+
const St = 200, Jt = 64 * 1024 * 1024, Kt = new TextDecoder("utf-8", { fatal: !0 });
|
|
3596
|
+
function ln(e) {
|
|
3597
|
+
if (!e || e.startsWith("/") || /^[A-Za-z]:/.test(e) || e.includes("\\") || e.includes("\0") || e.split("/").includes(".."))
|
|
3598
|
+
throw new Error(`ZIP entry ${JSON.stringify(e)}: path must be relative, without .. or backslashes`);
|
|
3566
3599
|
}
|
|
3567
|
-
function
|
|
3568
|
-
const
|
|
3600
|
+
function Qt(e) {
|
|
3601
|
+
const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (c = "(archive)") => {
|
|
3569
3602
|
throw new Error(`ZIP entry ${JSON.stringify(c)}: invalid or truncated ZIP`);
|
|
3570
|
-
}, r = (c) => c >= 0 && c + 2 <=
|
|
3571
|
-
let
|
|
3572
|
-
for (;
|
|
3603
|
+
}, r = (c) => c >= 0 && c + 2 <= e.length ? t.getUint16(c, !0) : n(), o = (c) => c >= 0 && c + 4 <= e.length ? t.getUint32(c, !0) : n();
|
|
3604
|
+
let s = e.length - 22;
|
|
3605
|
+
for (; s >= Math.max(0, e.length - 65557) && !(o(s) === 101010256 && s + 22 + r(s + 20) === e.length); s--)
|
|
3573
3606
|
;
|
|
3574
|
-
(
|
|
3575
|
-
const i = r(
|
|
3576
|
-
y !==
|
|
3607
|
+
(s < 0 || s < e.length - 65557) && n(), (r(s + 4) || r(s + 6) || r(s + 8) !== r(s + 10)) && n();
|
|
3608
|
+
const i = r(s + 10), u = o(s + 16), y = u + o(s + 12);
|
|
3609
|
+
y !== s && n();
|
|
3577
3610
|
const v = [], m = /* @__PURE__ */ new Set();
|
|
3578
3611
|
let l = u;
|
|
3579
3612
|
for (let c = 0; c < i; c++) {
|
|
@@ -3582,59 +3615,59 @@ function Kt(t) {
|
|
|
3582
3615
|
h > y && n();
|
|
3583
3616
|
let p;
|
|
3584
3617
|
try {
|
|
3585
|
-
p =
|
|
3618
|
+
p = Kt.decode(e.subarray(l + 46, l + 46 + f));
|
|
3586
3619
|
} catch {
|
|
3587
3620
|
throw new Error("ZIP entry (invalid UTF-8 name): invalid filename");
|
|
3588
3621
|
}
|
|
3589
|
-
if (
|
|
3622
|
+
if (ln(p), c >= St) throw new Error(`ZIP entry ${JSON.stringify(p)}: more than ${St} entries`);
|
|
3590
3623
|
if (m.has(p)) throw new Error(`ZIP entry ${JSON.stringify(p)}: duplicate entry`);
|
|
3591
3624
|
m.add(p);
|
|
3592
|
-
const g = o(l + 24), b = o(l + 20),
|
|
3593
|
-
if (g >
|
|
3625
|
+
const g = o(l + 24), b = o(l + 20), a = o(l + 42);
|
|
3626
|
+
if (g > Jt || b > Jt) throw new Error(`ZIP entry ${JSON.stringify(p)}: exceeds 64 MB`);
|
|
3594
3627
|
if (r(l + 10) !== 0) throw new Error(`ZIP entry ${JSON.stringify(p)}: expected stored compression (method 0)`);
|
|
3595
3628
|
if (r(l + 8) & 1) throw new Error(`ZIP entry ${JSON.stringify(p)}: encrypted entries are not supported`);
|
|
3596
|
-
(b !== g ||
|
|
3597
|
-
const d =
|
|
3598
|
-
(d + g > u || r(
|
|
3629
|
+
(b !== g || a + 30 > u || o(a) !== 67324752) && n(p);
|
|
3630
|
+
const d = a + 30 + r(a + 26) + r(a + 28);
|
|
3631
|
+
(d + g > u || r(a + 8) !== 0 || r(a + 6) !== r(l + 8)) && n(p);
|
|
3599
3632
|
let x;
|
|
3600
3633
|
try {
|
|
3601
|
-
x =
|
|
3634
|
+
x = Kt.decode(e.subarray(a + 30, a + 30 + r(a + 26)));
|
|
3602
3635
|
} catch {
|
|
3603
3636
|
n(p);
|
|
3604
3637
|
}
|
|
3605
|
-
x !== p && n(p), v.push({ name: p, offset:
|
|
3638
|
+
x !== p && n(p), v.push({ name: p, offset: a, start: d, size: g, central: l }), l = h;
|
|
3606
3639
|
}
|
|
3607
3640
|
return l !== y && n(), { files: v };
|
|
3608
3641
|
}
|
|
3609
|
-
function
|
|
3610
|
-
const
|
|
3611
|
-
for (const
|
|
3612
|
-
const i =
|
|
3613
|
-
if (!(i instanceof Uint8Array) || i.length !==
|
|
3614
|
-
o[
|
|
3642
|
+
function xo(e) {
|
|
3643
|
+
const t = e instanceof Uint8Array ? e : new Uint8Array(e), n = Qt(t), r = wo(t, { filter: (s) => s.name !== "__proto__" }), o = /* @__PURE__ */ Object.create(null);
|
|
3644
|
+
for (const s of n.files) {
|
|
3645
|
+
const i = s.name === "__proto__" ? t.slice(s.start, s.start + s.size) : r[s.name];
|
|
3646
|
+
if (!(i instanceof Uint8Array) || i.length !== s.size) throw new Error(`ZIP entry ${JSON.stringify(s.name)}: invalid size`);
|
|
3647
|
+
o[s.name] = i;
|
|
3615
3648
|
}
|
|
3616
3649
|
return o;
|
|
3617
3650
|
}
|
|
3618
|
-
function
|
|
3619
|
-
const n = Object.hasOwn(
|
|
3620
|
-
`),
|
|
3621
|
-
|
|
3622
|
-
for (const [c, f] of Object.entries(
|
|
3623
|
-
for (const [c, [f, h]] of Object.entries(
|
|
3624
|
-
if (
|
|
3625
|
-
if (h.byteLength >
|
|
3651
|
+
function Oo(e, t = {}) {
|
|
3652
|
+
const n = Object.hasOwn(e, "avatar.json") ? e["avatar.json"] : void 0, r = n ? tt(JSON.parse(Kt.decode(n))) : Yn("Avatar"), o = n && !t.manifest ? n : new TextEncoder().encode(JSON.stringify(tt({ ...r, ...t.manifest }), null, 2) + `
|
|
3653
|
+
`), s = /* @__PURE__ */ Object.create(null);
|
|
3654
|
+
s["avatar.json"] = o;
|
|
3655
|
+
for (const [c, f] of Object.entries(e)) c !== "avatar.json" && (s[c] = f);
|
|
3656
|
+
for (const [c, [f, h]] of Object.entries(s).entries()) {
|
|
3657
|
+
if (ln(f), c >= St) throw new Error(`ZIP entry ${JSON.stringify(f)}: more than ${St} entries`);
|
|
3658
|
+
if (h.byteLength > Jt) throw new Error(`ZIP entry ${JSON.stringify(f)}: exceeds 64 MB`);
|
|
3626
3659
|
}
|
|
3627
|
-
const i =
|
|
3660
|
+
const i = In(s);
|
|
3628
3661
|
if (i.length) throw new Error(i.join(`
|
|
3629
3662
|
`));
|
|
3630
3663
|
let u = "proto0000";
|
|
3631
|
-
for (let c = 0; Object.hasOwn(
|
|
3632
|
-
const y = Object.fromEntries(Object.entries(
|
|
3633
|
-
if (Object.hasOwn(
|
|
3634
|
-
const c =
|
|
3664
|
+
for (let c = 0; Object.hasOwn(s, u); c++) u = `proto${String(c + 1).padStart(4, "0")}`;
|
|
3665
|
+
const y = Object.fromEntries(Object.entries(s).map(([c, f]) => [c === "__proto__" ? u : c, f])), v = bo(y, { level: 0 });
|
|
3666
|
+
if (Object.hasOwn(s, "__proto__")) {
|
|
3667
|
+
const c = Qt(v).files.find((h) => h.name === u), f = new TextEncoder().encode("__proto__");
|
|
3635
3668
|
v.set(f, c.offset + 30), v.set(f, c.central + 46);
|
|
3636
3669
|
}
|
|
3637
|
-
const m =
|
|
3670
|
+
const m = Qt(v), l = m.files.find((c) => c.name === "avatar.json");
|
|
3638
3671
|
if (l.offset !== 0) {
|
|
3639
3672
|
const c = l.start + l.size - l.offset, f = new Uint8Array(v.length);
|
|
3640
3673
|
f.set(v.subarray(l.offset, l.offset + c)), f.set(v.subarray(0, l.offset), c), f.set(v.subarray(l.offset + c), l.offset + c);
|
|
@@ -3644,49 +3677,49 @@ function Ao(t, e = {}) {
|
|
|
3644
3677
|
}
|
|
3645
3678
|
return v;
|
|
3646
3679
|
}
|
|
3647
|
-
const
|
|
3648
|
-
function Qe(
|
|
3680
|
+
const Mo = (e) => JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(e));
|
|
3681
|
+
function Qe(e, t) {
|
|
3649
3682
|
try {
|
|
3650
|
-
return
|
|
3683
|
+
return Mo(e);
|
|
3651
3684
|
} catch {
|
|
3652
|
-
throw new Error(`${
|
|
3685
|
+
throw new Error(`${t}: invalid UTF-8 JSON`);
|
|
3653
3686
|
}
|
|
3654
3687
|
}
|
|
3655
|
-
function
|
|
3688
|
+
function Zn(e, t, n, r) {
|
|
3656
3689
|
return [
|
|
3657
3690
|
"layers.json",
|
|
3658
3691
|
"base.png",
|
|
3659
3692
|
"hairmask.png",
|
|
3660
3693
|
...r?.cloth?.length ? ["base_cloth.png"] : [],
|
|
3661
|
-
...Object.keys(
|
|
3662
|
-
...
|
|
3694
|
+
...Object.keys(e?.layers ?? {}).map((o) => `${o}.png`),
|
|
3695
|
+
...t ? ["sprites/sprites.json", ...Object.keys(t.layers ?? {}).map((o) => `sprites/${o}.png`)] : [],
|
|
3663
3696
|
// malformed entries are left to validateAvatarFiles, which reports them
|
|
3664
3697
|
...n ? ["overlays/overlays.json", ...(Array.isArray(n.overlays) ? n.overlays : []).flatMap((o) => typeof o?.file == "string" ? [`overlays/${o.file}`] : [])] : []
|
|
3665
3698
|
];
|
|
3666
3699
|
}
|
|
3667
|
-
function
|
|
3668
|
-
const
|
|
3669
|
-
if (
|
|
3700
|
+
function Wn(e) {
|
|
3701
|
+
const t = In(e);
|
|
3702
|
+
if (t.length) throw new Error(t.join(`
|
|
3670
3703
|
`));
|
|
3671
3704
|
}
|
|
3672
|
-
function
|
|
3673
|
-
return !!
|
|
3705
|
+
function Gn(e) {
|
|
3706
|
+
return !!e && typeof e == "object" && "manifest" in e && "rig" in e && "assets" in e && "release" in e;
|
|
3674
3707
|
}
|
|
3675
|
-
function
|
|
3676
|
-
const
|
|
3677
|
-
if (!Object.hasOwn(
|
|
3678
|
-
|
|
3679
|
-
const n = tt(Qe(
|
|
3680
|
-
Qe(
|
|
3681
|
-
|
|
3708
|
+
function Dt(e) {
|
|
3709
|
+
const t = xo(e);
|
|
3710
|
+
if (!Object.hasOwn(t, "avatar.json")) throw new Error("avatar.json: missing file in .mavatar archive");
|
|
3711
|
+
Wn(t);
|
|
3712
|
+
const n = tt(Qe(t["avatar.json"], "avatar.json")), r = en(Qe(t["rig.json"], "rig.json")), o = t["built/overlays/overlays.json"] ? Qe(t["built/overlays/overlays.json"], "built/overlays/overlays.json") : void 0, s = Zn(
|
|
3713
|
+
Qe(t["built/layers.json"], "built/layers.json"),
|
|
3714
|
+
t["built/sprites/sprites.json"] ? Qe(t["built/sprites/sprites.json"], "built/sprites/sprites.json") : void 0,
|
|
3682
3715
|
o,
|
|
3683
3716
|
r
|
|
3684
3717
|
), i = {}, u = [], y = () => {
|
|
3685
3718
|
u.splice(0).forEach((v) => URL.revokeObjectURL(v));
|
|
3686
3719
|
};
|
|
3687
3720
|
try {
|
|
3688
|
-
for (const v of new Set(
|
|
3689
|
-
const m = URL.createObjectURL(new Blob([new Uint8Array(
|
|
3721
|
+
for (const v of new Set(s)) {
|
|
3722
|
+
const m = URL.createObjectURL(new Blob([new Uint8Array(t[`built/${v}`])], { type: v.endsWith(".json") ? "application/json" : "image/png" }));
|
|
3690
3723
|
u.push(m), i[v] = m;
|
|
3691
3724
|
}
|
|
3692
3725
|
} catch (v) {
|
|
@@ -3694,83 +3727,89 @@ function Ct(t) {
|
|
|
3694
3727
|
}
|
|
3695
3728
|
return { manifest: n, rig: r, assets: i, release: y };
|
|
3696
3729
|
}
|
|
3697
|
-
async function
|
|
3698
|
-
if (
|
|
3699
|
-
if (
|
|
3700
|
-
if (
|
|
3701
|
-
const n = new URL(
|
|
3730
|
+
async function Ao(e, t = {}) {
|
|
3731
|
+
if (Gn(e)) return e;
|
|
3732
|
+
if (e instanceof Blob) return Dt(await e.arrayBuffer());
|
|
3733
|
+
if (e instanceof ArrayBuffer || e instanceof Uint8Array) return Dt(e);
|
|
3734
|
+
const n = new URL(e, typeof location > "u" ? void 0 : location.href);
|
|
3702
3735
|
if (/\.mavatar$/i.test(n.pathname)) {
|
|
3703
3736
|
const g = await fetch(n);
|
|
3704
3737
|
if (!g.ok) throw new Error(`.mavatar: could not load (${g.status})`);
|
|
3705
|
-
return
|
|
3738
|
+
return Dt(await g.arrayBuffer());
|
|
3706
3739
|
}
|
|
3707
3740
|
n.pathname.endsWith("/") || (n.pathname += "/");
|
|
3708
3741
|
const r = (g) => {
|
|
3709
3742
|
const b = new URL(n);
|
|
3710
|
-
return b.pathname += g.split("/").map(encodeURIComponent).join("/"),
|
|
3743
|
+
return b.pathname += g.split("/").map(encodeURIComponent).join("/"), t.version !== void 0 && b.searchParams.set("v", String(t.version)), b.href;
|
|
3711
3744
|
}, o = {};
|
|
3712
|
-
async function
|
|
3713
|
-
const
|
|
3714
|
-
if (b && (
|
|
3715
|
-
if (!
|
|
3716
|
-
const d = new Uint8Array(await
|
|
3745
|
+
async function s(g, b = !1) {
|
|
3746
|
+
const a = await fetch(r(g));
|
|
3747
|
+
if (b && (a.status === 404 || a.ok && a.headers.get("content-type")?.includes("text/html"))) return;
|
|
3748
|
+
if (!a.ok) throw new Error(`${g}: could not load (${a.status})`);
|
|
3749
|
+
const d = new Uint8Array(await a.arrayBuffer());
|
|
3717
3750
|
return o[g] = d, Qe(d, g);
|
|
3718
3751
|
}
|
|
3719
|
-
const i =
|
|
3720
|
-
|
|
3752
|
+
const i = t.rigFile ?? "rig.json";
|
|
3753
|
+
ln(i);
|
|
3721
3754
|
const [u, y, v, m, l] = await Promise.all([
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3755
|
+
s(i),
|
|
3756
|
+
s("built/layers.json"),
|
|
3757
|
+
s("avatar.json", !0),
|
|
3758
|
+
s("built/sprites/sprites.json", !0),
|
|
3759
|
+
s("built/overlays/overlays.json", !0)
|
|
3727
3760
|
]);
|
|
3728
3761
|
Array.isArray(u?.eyes) && Array.isArray(y?.eyes) && (u.eyes = u.eyes.map((g, b) => {
|
|
3729
3762
|
if (!g || typeof g != "object") return g;
|
|
3730
|
-
const
|
|
3731
|
-
for (const d of ["x0", "x1", "top", "bot"])
|
|
3732
|
-
return
|
|
3763
|
+
const a = { ...g };
|
|
3764
|
+
for (const d of ["x0", "x1", "top", "bot"]) a[d] === void 0 && (a[d] = y.eyes[b]?.[d]);
|
|
3765
|
+
return a;
|
|
3733
3766
|
})), o["rig.json"] = new TextEncoder().encode(JSON.stringify(u));
|
|
3734
|
-
const c =
|
|
3767
|
+
const c = Zn(y, m, l, u);
|
|
3735
3768
|
for (const g of c) g.endsWith(".png") && (o[`built/${g}`] = { size: 1 });
|
|
3736
|
-
|
|
3737
|
-
const f =
|
|
3738
|
-
return { manifest: v === void 0 ?
|
|
3769
|
+
Wn(o);
|
|
3770
|
+
const f = en(u), h = Object.fromEntries(c.map((g) => [g, r(`built/${g}`)])), p = decodeURIComponent(n.pathname.split("/").filter(Boolean).at(-1) ?? "Avatar");
|
|
3771
|
+
return { manifest: v === void 0 ? Yn(p) : tt(v), rig: f, assets: h, release() {
|
|
3739
3772
|
} };
|
|
3740
3773
|
}
|
|
3741
|
-
async function
|
|
3742
|
-
const r = !
|
|
3774
|
+
async function To(e, t, n = {}) {
|
|
3775
|
+
const r = !Gn(t), o = await Ao(t);
|
|
3743
3776
|
try {
|
|
3744
|
-
const
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3777
|
+
const s = n.lipSync === void 0 ? o.manifest.lipSync : { ...o.manifest.lipSync, ...tn(n.lipSync) }, i = n.expressions === void 0 ? o.manifest.expressions : Vr(o.manifest.expressions, on(n.expressions)), u = await qr(e, {
|
|
3778
|
+
...n,
|
|
3779
|
+
...s === void 0 ? {} : { lipSync: s },
|
|
3780
|
+
...i === void 0 ? {} : { expressions: i },
|
|
3781
|
+
rig: o.rig,
|
|
3782
|
+
assets: o.assets
|
|
3783
|
+
}), y = u.destroy.bind(u);
|
|
3784
|
+
let v = !1;
|
|
3785
|
+
return Object.assign(u, { package: o, destroy() {
|
|
3786
|
+
if (!v) {
|
|
3787
|
+
v = !0;
|
|
3749
3788
|
try {
|
|
3750
|
-
|
|
3789
|
+
y();
|
|
3751
3790
|
} finally {
|
|
3752
3791
|
r && o.release();
|
|
3753
3792
|
}
|
|
3754
3793
|
}
|
|
3755
3794
|
} });
|
|
3756
|
-
} catch (
|
|
3757
|
-
throw r && o.release(),
|
|
3795
|
+
} catch (s) {
|
|
3796
|
+
throw r && o.release(), s;
|
|
3758
3797
|
}
|
|
3759
3798
|
}
|
|
3760
3799
|
export {
|
|
3761
3800
|
mt as ARM_DEFAULTS,
|
|
3762
3801
|
et as DEFAULT_LIGHTING,
|
|
3763
|
-
|
|
3802
|
+
So as LIVE_EXPRESSIONS,
|
|
3764
3803
|
bt as PARAMS,
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3804
|
+
Eo as colorHex,
|
|
3805
|
+
qr as createMeshAvatar,
|
|
3806
|
+
To as loadMeshAvatar,
|
|
3807
|
+
Ao as openAvatar,
|
|
3808
|
+
Oo as packAvatar,
|
|
3809
|
+
lr as parseLighting,
|
|
3771
3810
|
tt as parseManifest,
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3811
|
+
en as parseRig,
|
|
3812
|
+
xo as unpackAvatar,
|
|
3813
|
+
In as validateAvatarFiles,
|
|
3814
|
+
Ln as validateRig
|
|
3776
3815
|
};
|