mesh-avatar 0.3.1 → 0.4.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 +4 -1
- package/dist/engine/createMeshAvatar.d.ts +2 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/overlays.d.ts +15 -0
- package/dist/index.js +1519 -1441
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,55 +21,55 @@ 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
|
-
const
|
|
24
|
+
const ne = (n, e, t) => {
|
|
25
25
|
(typeof n != "number" || !Number.isFinite(n)) && t.push(`${e}: expected a finite number`);
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
},
|
|
26
|
+
}, Le = (n, e, t) => {
|
|
27
|
+
ne(n, e, t), typeof n == "number" && n <= 0 && t.push(`${e}: must be positive`);
|
|
28
|
+
}, we = (n, e, t) => {
|
|
29
|
+
Le(n, e, t), typeof n == "number" && !Number.isInteger(n) && t.push(`${e}: expected an integer`);
|
|
30
|
+
}, Ie = (n, e, t) => {
|
|
31
|
+
ne(n, e, t), typeof n == "number" && !Number.isInteger(n) && t.push(`${e}: expected an integer`);
|
|
32
|
+
}, jt = (n, e, t) => {
|
|
33
33
|
(typeof n != "string" || !n.trim()) && t.push(`${e}: expected a non-empty string`);
|
|
34
|
-
}, ge = (n, e = 0, t = 1 / 0) => (r, a,
|
|
34
|
+
}, ge = (n, e = 0, t = 1 / 0) => (r, a, s) => {
|
|
35
35
|
if (!Array.isArray(r)) {
|
|
36
|
-
|
|
36
|
+
s.push(`${a}: expected an array`);
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
(r.length < e || r.length > t) &&
|
|
40
|
-
}, ye = ge(
|
|
39
|
+
(r.length < e || r.length > t) && s.push(`${a}: expected ${e}..${t} items`), r.forEach((l, f) => n(l, `${a}[${f}]`, s));
|
|
40
|
+
}, ye = ge(ne, 2, 2), ue = (n, e, t) => {
|
|
41
41
|
ye(n, e, t), Array.isArray(n) && n.length === 2 && n[0] >= n[1] && t.push(`${e}: start must be less than end`);
|
|
42
42
|
}, oe = (n, e = []) => (t, r, a) => {
|
|
43
43
|
if (!t || typeof t != "object" || Array.isArray(t)) {
|
|
44
44
|
a.push(`${r}: expected an object`);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
for (const [
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
},
|
|
47
|
+
const s = t;
|
|
48
|
+
for (const [l, f] of Object.entries(n))
|
|
49
|
+
s[l] === void 0 && e.includes(l) || f(s[l], `${r}.${l}`, a);
|
|
50
|
+
}, Ce = { cx: ne, cy: ne, rx: Le, ry: Le }, ve = oe(Ce), We = ge(ye, 3), It = ge(ye, 2), nt = (n, e, t) => {
|
|
51
|
+
ne(n, e, t), typeof n == "number" && (n < 0 || n > 1) && t.push(`${e}: must be between 0 and 1`);
|
|
52
|
+
}, bn = (n) => oe({
|
|
53
53
|
version: (e, t, r) => {
|
|
54
54
|
e !== 1 && r.push(`${t}: only version 1 is supported`);
|
|
55
55
|
},
|
|
56
|
-
image: oe({ width:
|
|
56
|
+
image: oe({ width: we, height: we }),
|
|
57
57
|
head: oe({
|
|
58
|
-
|
|
59
|
-
shiftX:
|
|
60
|
-
shiftY:
|
|
61
|
-
pivotX:
|
|
62
|
-
pivotY:
|
|
63
|
-
maxRoll:
|
|
64
|
-
weightBand:
|
|
65
|
-
turnBand:
|
|
58
|
+
...Ce,
|
|
59
|
+
shiftX: ne,
|
|
60
|
+
shiftY: ne,
|
|
61
|
+
pivotX: ne,
|
|
62
|
+
pivotY: ne,
|
|
63
|
+
maxRoll: ne,
|
|
64
|
+
weightBand: ue,
|
|
65
|
+
turnBand: ue
|
|
66
66
|
}),
|
|
67
67
|
body: oe({
|
|
68
|
-
pivotX:
|
|
69
|
-
pivotY:
|
|
70
|
-
maxRoll:
|
|
71
|
-
breathBand:
|
|
72
|
-
rollBand:
|
|
68
|
+
pivotX: ne,
|
|
69
|
+
pivotY: ne,
|
|
70
|
+
maxRoll: ne,
|
|
71
|
+
breathBand: ue,
|
|
72
|
+
rollBand: ue,
|
|
73
73
|
chest: ve,
|
|
74
74
|
shoulders: ge(ve)
|
|
75
75
|
}),
|
|
@@ -80,98 +80,98 @@ const ee = (n, e, t) => {
|
|
|
80
80
|
eyeB: ve,
|
|
81
81
|
earL: ve,
|
|
82
82
|
earR: ve,
|
|
83
|
-
brow: oe({
|
|
84
|
-
jaw: oe({
|
|
83
|
+
brow: oe({ ...Ce, band: ue }),
|
|
84
|
+
jaw: oe({ ...Ce, band: ue })
|
|
85
85
|
}),
|
|
86
86
|
buns: oe({ bunL: ve, bunR: ve }, ["bunL", "bunR"]),
|
|
87
87
|
eyes: ge(oe({
|
|
88
|
-
opening:
|
|
89
|
-
roi:
|
|
90
|
-
x0:
|
|
91
|
-
x1:
|
|
92
|
-
top: ge(
|
|
93
|
-
bot: ge(
|
|
88
|
+
opening: We,
|
|
89
|
+
roi: We,
|
|
90
|
+
x0: ne,
|
|
91
|
+
x1: ne,
|
|
92
|
+
top: ge(ne, 24, 24),
|
|
93
|
+
bot: ge(ne, 24, 24)
|
|
94
94
|
}, n ? ["x0", "x1", "top", "bot"] : []), 2, 2),
|
|
95
95
|
mouth: oe({
|
|
96
|
-
cx:
|
|
97
|
-
cy:
|
|
98
|
-
angle:
|
|
99
|
-
halfLen:
|
|
100
|
-
bow:
|
|
101
|
-
area: oe({
|
|
96
|
+
cx: ne,
|
|
97
|
+
cy: ne,
|
|
98
|
+
angle: ne,
|
|
99
|
+
halfLen: Le,
|
|
100
|
+
bow: ne,
|
|
101
|
+
area: oe({ ...Ce, angle: ne })
|
|
102
102
|
}),
|
|
103
103
|
cheeks: ge(ye, 2, 2),
|
|
104
|
-
strands: ge(oe({ name:
|
|
104
|
+
strands: ge(oe({ name: jt, nodes: It, sigma: Le, k: Le, max: Le })),
|
|
105
105
|
accessories: ge(oe({
|
|
106
|
-
name:
|
|
106
|
+
name: jt,
|
|
107
107
|
pivot: ye,
|
|
108
108
|
tip: ye,
|
|
109
|
-
split:
|
|
110
|
-
box: ge(
|
|
111
|
-
color: oe({ redness:
|
|
109
|
+
split: nt,
|
|
110
|
+
box: ge(Ie, 4, 4),
|
|
111
|
+
color: oe({ redness: nt, minRed: ne })
|
|
112
112
|
})),
|
|
113
113
|
hand: oe({
|
|
114
|
-
outline:
|
|
115
|
-
jaw:
|
|
116
|
-
jawRange:
|
|
117
|
-
background:
|
|
114
|
+
outline: We,
|
|
115
|
+
jaw: It,
|
|
116
|
+
jawRange: ue,
|
|
117
|
+
background: We,
|
|
118
118
|
elbow: ye,
|
|
119
119
|
wrist: ye,
|
|
120
120
|
knuckle: ye,
|
|
121
121
|
contact: ye,
|
|
122
|
-
forearmShare:
|
|
123
|
-
armBand:
|
|
124
|
-
wristBand:
|
|
125
|
-
handBand:
|
|
126
|
-
fingerXBand:
|
|
127
|
-
fingerYBand:
|
|
128
|
-
pinBand:
|
|
122
|
+
forearmShare: nt,
|
|
123
|
+
armBand: ue,
|
|
124
|
+
wristBand: ue,
|
|
125
|
+
handBand: ue,
|
|
126
|
+
fingerXBand: ue,
|
|
127
|
+
fingerYBand: ue,
|
|
128
|
+
pinBand: ue
|
|
129
129
|
}),
|
|
130
130
|
mesh: oe({
|
|
131
|
-
baseCell:
|
|
131
|
+
baseCell: we,
|
|
132
132
|
fine: oe({
|
|
133
|
-
x0:
|
|
134
|
-
x1:
|
|
135
|
-
y0:
|
|
136
|
-
y1:
|
|
137
|
-
cell:
|
|
133
|
+
x0: Ie,
|
|
134
|
+
x1: Ie,
|
|
135
|
+
y0: Ie,
|
|
136
|
+
y1: Ie,
|
|
137
|
+
cell: we
|
|
138
138
|
}),
|
|
139
|
-
handCell:
|
|
140
|
-
tasselCell:
|
|
141
|
-
eyeBallCell:
|
|
142
|
-
eyeCell:
|
|
143
|
-
spriteCell:
|
|
139
|
+
handCell: we,
|
|
140
|
+
tasselCell: we,
|
|
141
|
+
eyeBallCell: we,
|
|
142
|
+
eyeCell: we,
|
|
143
|
+
spriteCell: we
|
|
144
144
|
}),
|
|
145
|
-
view: oe({ padTop:
|
|
145
|
+
view: oe({ padTop: ne, padSide: ne, gazeCenter: ye }, ["gazeCenter"])
|
|
146
146
|
}, ["buns", "strands", "accessories", "hand"]);
|
|
147
|
-
function
|
|
147
|
+
function en(n, e = {}) {
|
|
148
148
|
const t = [];
|
|
149
|
-
if (
|
|
149
|
+
if (bn(e.draft ?? !1)(n, "rig", t), t.length) return t;
|
|
150
150
|
const r = n;
|
|
151
|
-
r.eyes.forEach((a,
|
|
152
|
-
const
|
|
153
|
-
if (!(e.draft &&
|
|
154
|
-
if (
|
|
155
|
-
t.push(`rig.eyes[${
|
|
151
|
+
r.eyes.forEach((a, s) => {
|
|
152
|
+
const l = ["x0", "x1", "top", "bot"];
|
|
153
|
+
if (!(e.draft && l.every((f) => a[f] === void 0))) {
|
|
154
|
+
if (l.some((f) => a[f] === void 0)) {
|
|
155
|
+
t.push(`rig.eyes[${s}]: supply all x0/x1/top/bot fields or omit all in a draft`);
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
|
-
a.x0 >= a.x1 && t.push(`rig.eyes[${
|
|
158
|
+
a.x0 >= a.x1 && t.push(`rig.eyes[${s}].x1: must exceed x0`), a.top.some((f, y) => f > a.bot[y]) && t.push(`rig.eyes[${s}].top: must not exceed bottom curve`);
|
|
159
159
|
}
|
|
160
160
|
}), (r.mesh.fine.x0 >= r.mesh.fine.x1 || r.mesh.fine.y0 >= r.mesh.fine.y1) && t.push("rig.mesh.fine: rectangle must have positive area"), (r.view.padTop <= -1 || r.view.padTop >= 1 || r.view.padSide <= -0.5) && t.push("rig.view: margins must leave a positive viewport");
|
|
161
|
-
for (const [a,
|
|
162
|
-
|
|
163
|
-
for (const [a,
|
|
164
|
-
(
|
|
161
|
+
for (const [a, s] of (r.strands ?? []).entries())
|
|
162
|
+
s.nodes.some((l, f) => f > 0 && l[0] === s.nodes[f - 1][0] && l[1] === s.nodes[f - 1][1]) && t.push(`rig.strands[${a}].nodes: consecutive nodes must differ`);
|
|
163
|
+
for (const [a, s] of (r.accessories ?? []).entries())
|
|
164
|
+
(s.box[0] < 0 || s.box[1] < 0 || s.box[2] > r.image.width || s.box[3] > r.image.height) && t.push(`rig.accessories[${a}].box: rectangle must stay inside the image`), (s.split <= 0 || s.split >= 1) && t.push(`rig.accessories[${a}].split: must be strictly between 0 and 1`), s.pivot.every((l, f) => l === s.tip[f]) && t.push(`rig.accessories[${a}].tip: must differ from pivot`), (s.box[0] >= s.box[2] || s.box[1] >= s.box[3]) && t.push(`rig.accessories[${a}].box: rectangle must have positive area`);
|
|
165
165
|
return t;
|
|
166
166
|
}
|
|
167
|
-
function
|
|
168
|
-
const e =
|
|
167
|
+
function Et(n) {
|
|
168
|
+
const e = en(n);
|
|
169
169
|
if (e.length) throw new Error(`Invalid rig:
|
|
170
170
|
${e.join(`
|
|
171
171
|
`)}`);
|
|
172
172
|
return structuredClone(n);
|
|
173
173
|
}
|
|
174
|
-
const
|
|
174
|
+
const Ge = [
|
|
175
175
|
{ id: "angleX", label: "Face angle X", min: -30, max: 30, def: 0, group: "Head and body" },
|
|
176
176
|
{ id: "angleY", label: "Face angle Y", min: -30, max: 30, def: 0, group: "Head and body" },
|
|
177
177
|
{ id: "angleZ", label: "Face roll", min: -30, max: 30, def: 0, group: "Head and body" },
|
|
@@ -192,253 +192,253 @@ const We = [
|
|
|
192
192
|
{ id: "handAngle", label: "Wrist angle", min: -10, max: 10, def: 0, group: "Hand" },
|
|
193
193
|
{ id: "fingerTap", label: "Finger tap", min: 0, max: 1, def: 0, group: "Hand" }
|
|
194
194
|
];
|
|
195
|
-
function
|
|
196
|
-
const e = { w: n.image.width, h: n.image.height }, t = (
|
|
197
|
-
function
|
|
198
|
-
const
|
|
199
|
-
return
|
|
195
|
+
function xn(n) {
|
|
196
|
+
const e = { w: n.image.width, h: n.image.height }, t = (x, M, T) => T ? Math.exp(-(((x - T.cx) / T.rx) ** 2 + ((M - T.cy) / T.ry) ** 2)) : 0, r = 24, a = n.eyes;
|
|
197
|
+
function s(x, M) {
|
|
198
|
+
const T = Math.min(1, Math.max(0, M)) * (r - 1), _ = Math.min(Math.floor(T), r - 2), Y = T - _;
|
|
199
|
+
return x[_] + (x[_ + 1] - x[_]) * Y;
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function l(x, M, T, _) {
|
|
202
202
|
M = Math.min(1, Math.max(0, M));
|
|
203
|
-
const
|
|
204
|
-
return [(
|
|
205
|
-
}
|
|
206
|
-
const f = [[-2, 1], [-1, 2], [0, 3], [1, 2], [2, 1]],
|
|
207
|
-
function
|
|
208
|
-
let
|
|
209
|
-
for (const [
|
|
210
|
-
const [
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
const
|
|
214
|
-
return { top:
|
|
215
|
-
}
|
|
216
|
-
function
|
|
217
|
-
const
|
|
218
|
-
return M === "lash" ?
|
|
219
|
-
}
|
|
220
|
-
function
|
|
221
|
-
const
|
|
222
|
-
return
|
|
223
|
-
}
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
return
|
|
203
|
+
const Y = s(x.top, M), X = s(x.bot, M), F = 1 - T, C = 4 * M * (1 - M), Z = s(x.bot, 0.5) - s(x.top, 0.5), E = x.top[0] + (x.top[r - 1] - x.top[0]) * M - 0.3 * Z * C, R = Math.max(Y, X + 1 + (E - X - 1) * _);
|
|
204
|
+
return [(R - Y) * Math.max(F, -0.07), F > 0 ? (R - X) * F * _ : 0];
|
|
205
|
+
}
|
|
206
|
+
const f = [[-2, 1], [-1, 2], [0, 3], [1, 2], [2, 1]], y = 5;
|
|
207
|
+
function d(x, M, T, _) {
|
|
208
|
+
let Y = 0, X = 0;
|
|
209
|
+
for (const [E, R] of f) {
|
|
210
|
+
const [J, te] = l(x, (M + E * y - x.x0) / (x.x1 - x.x0), T, _);
|
|
211
|
+
Y += J * R / 9, X += te * R / 9;
|
|
212
|
+
}
|
|
213
|
+
const F = Math.min(1, Math.max(0, (M - x.x0) / (x.x1 - x.x0))), C = s(x.top, F), Z = s(x.bot, F);
|
|
214
|
+
return { top: C, bot: Z, b: 1 - T, lid: C + Y, bc: Z + X };
|
|
215
|
+
}
|
|
216
|
+
function m(x, M, T, _, Y, X) {
|
|
217
|
+
const F = d(x, T, Y, X);
|
|
218
|
+
return M === "lash" ? F.lid - (F.top - _) * (1 - 0.3 * Math.min(1, Math.max(0, F.b))) : M === "low" ? _ + (F.bc - F.bot) : M === "crease" ? _ + (F.lid - F.top) * 0.22 : _;
|
|
219
|
+
}
|
|
220
|
+
function c(x, M, T) {
|
|
221
|
+
const _ = Math.min(1, Math.max(0, 1 - M));
|
|
222
|
+
return x === "low" ? 1 - Math.min(1, _ * T * 1.2) : x === "crease" ? 1 - 0.45 * _ : 1;
|
|
223
|
+
}
|
|
224
|
+
const p = n.mouth, b = n.cheeks, v = n.head, h = n.body, u = (x, M, T) => {
|
|
225
|
+
const _ = Math.min(1, Math.max(0, (T - x) / (M - x)));
|
|
226
|
+
return _ * _ * (3 - 2 * _);
|
|
227
227
|
};
|
|
228
|
-
function x
|
|
229
|
-
return 1 -
|
|
230
|
-
}
|
|
231
|
-
function
|
|
232
|
-
return 1 -
|
|
233
|
-
}
|
|
234
|
-
const
|
|
235
|
-
function
|
|
236
|
-
let
|
|
237
|
-
const X =
|
|
238
|
-
for (let
|
|
239
|
-
const [
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
return [
|
|
243
|
-
}
|
|
244
|
-
function
|
|
245
|
-
if (
|
|
246
|
-
const
|
|
247
|
-
let
|
|
248
|
-
|
|
249
|
-
const [
|
|
250
|
-
|
|
228
|
+
function w(x, M) {
|
|
229
|
+
return 1 - u(...v.weightBand, M);
|
|
230
|
+
}
|
|
231
|
+
function o(x, M) {
|
|
232
|
+
return 1 - u(...v.turnBand, M);
|
|
233
|
+
}
|
|
234
|
+
const i = n.strands ?? [];
|
|
235
|
+
function S(x, M, T) {
|
|
236
|
+
let _ = 1 / 0, Y = 0;
|
|
237
|
+
const X = T.length - 1;
|
|
238
|
+
for (let F = 0; F < X; F++) {
|
|
239
|
+
const [C, Z] = T[F], [E, R] = T[F + 1], J = E - C, te = R - Z, ee = Math.min(1, Math.max(0, ((x - C) * J + (M - Z) * te) / (J * J + te * te))), se = Math.hypot(x - C - J * ee, M - Z - te * ee);
|
|
240
|
+
se < _ && (_ = se, Y = (F + ee) / X);
|
|
241
|
+
}
|
|
242
|
+
return [_, Y];
|
|
243
|
+
}
|
|
244
|
+
function g(x, M, T) {
|
|
245
|
+
if (T < 0.02) return [];
|
|
246
|
+
const _ = [];
|
|
247
|
+
let Y = 0;
|
|
248
|
+
i.forEach((F, C) => {
|
|
249
|
+
const [Z, E] = S(x, M, F.nodes), R = Math.exp(-((Z / F.sigma) ** 2));
|
|
250
|
+
R < 0.02 || (_.push([C, R, E]), Y += R);
|
|
251
251
|
});
|
|
252
|
-
const X = Math.max(1,
|
|
253
|
-
return
|
|
252
|
+
const X = Math.max(1, Y);
|
|
253
|
+
return _.map(([F, C, Z]) => [F, T * C / X * u(0.04, 0.55, Z), Z]);
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function A(x, M, T = 1) {
|
|
256
256
|
return {
|
|
257
|
-
head: x
|
|
258
|
-
turn:
|
|
259
|
-
strands:
|
|
260
|
-
bunL: t(
|
|
261
|
-
bunR: t(
|
|
262
|
-
brow: t(
|
|
257
|
+
head: w(x, M),
|
|
258
|
+
turn: o(x, M),
|
|
259
|
+
strands: g(x, M, T),
|
|
260
|
+
bunL: t(x, M, n.buns?.bunL),
|
|
261
|
+
bunR: t(x, M, n.buns?.bunR),
|
|
262
|
+
brow: t(x, M, n.face.brow) * (1 - u(...n.face.brow.band, M)),
|
|
263
263
|
// chin below the mouth line drops a little when the mouth opens
|
|
264
|
-
jaw: t(
|
|
264
|
+
jaw: t(x, M, n.face.jaw) * u(...n.face.jaw.band, M),
|
|
265
265
|
// per-feature depth for head turns (nose sticks out most, ears sit at the back)
|
|
266
|
-
nose: t(
|
|
267
|
-
mouth: t(
|
|
268
|
-
eyeA: t(
|
|
269
|
-
eyeB: t(
|
|
270
|
-
earR: t(
|
|
271
|
-
earL: t(
|
|
272
|
-
chest: t(
|
|
273
|
-
breath: 1 -
|
|
274
|
-
shoulder:
|
|
266
|
+
nose: t(x, M, n.face.nose),
|
|
267
|
+
mouth: t(x, M, n.face.mouth),
|
|
268
|
+
eyeA: t(x, M, n.face.eyeA),
|
|
269
|
+
eyeB: t(x, M, n.face.eyeB),
|
|
270
|
+
earR: t(x, M, n.face.earR),
|
|
271
|
+
earL: t(x, M, n.face.earL),
|
|
272
|
+
chest: t(x, M, h.chest),
|
|
273
|
+
breath: 1 - u(...h.breathBand, M),
|
|
274
|
+
shoulder: h.shoulders.reduce((_, Y) => _ + t(x, M, Y), 0)
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
|
-
function
|
|
278
|
-
const
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
return [
|
|
282
|
-
}
|
|
283
|
-
function
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
function
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
function
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
function
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
for (const [
|
|
300
|
-
const
|
|
301
|
-
if (!
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
if (
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
return
|
|
312
|
-
}
|
|
313
|
-
const O = n.hand,
|
|
314
|
-
function
|
|
277
|
+
function L(x, M, T, _) {
|
|
278
|
+
const Y = (x - v.cx) / v.rx, X = (M - v.cy) / v.ry, F = 1 - Y * Y - X * X;
|
|
279
|
+
if (F <= 0) return [0, 0];
|
|
280
|
+
const C = u(0, 0.84, F);
|
|
281
|
+
return [T * v.shiftX * C, -_ * v.shiftY * C];
|
|
282
|
+
}
|
|
283
|
+
function B(x, M, T, _) {
|
|
284
|
+
const Y = Math.cos(_), X = Math.sin(_), F = x[0] - M, C = x[1] - T;
|
|
285
|
+
x[0] = M + F * Y - C * X, x[1] = T + F * X + C * Y;
|
|
286
|
+
}
|
|
287
|
+
function j(x, M, T, _ = M) {
|
|
288
|
+
const Y = L(x[0], x[1], T.angleX / 30, T.angleY / 30);
|
|
289
|
+
x[0] += Y[0] * _, x[1] += Y[1] * _, !(M <= 0) && B(x, v.pivotX, v.pivotY, -T.angleZ / 30 * v.maxRoll * M);
|
|
290
|
+
}
|
|
291
|
+
function k(x, M, T, _ = 0, Y = 1, X = 0) {
|
|
292
|
+
const F = T.breath;
|
|
293
|
+
x[1] -= F * (5 * Y + 4 * X), x[0] += (x[0] - h.chest.cx) * 0.012 * F * _, x[0] += T.bodyAngleX / 10 * (7 + 9 * _), B(x, h.pivotX, h.pivotY, -T.bodyAngleZ / 10 * h.maxRoll * (1 - u(...h.rollBand, M)));
|
|
294
|
+
}
|
|
295
|
+
function U(x, M, T, _, Y, X) {
|
|
296
|
+
const F = X;
|
|
297
|
+
F[0] = x, F[1] = M;
|
|
298
|
+
const C = Y.gain;
|
|
299
|
+
for (const [R, J, te] of T.strands) {
|
|
300
|
+
const ee = Y.strands?.[R];
|
|
301
|
+
if (!ee) continue;
|
|
302
|
+
const se = te * 3, le = Math.min(2, Math.floor(se)), ce = se - le;
|
|
303
|
+
F[0] += (ee[le][0] + (ee[le + 1][0] - ee[le][0]) * ce) * J * C, F[1] += (ee[le][1] + (ee[le + 1][1] - ee[le][1]) * ce) * J * C;
|
|
304
|
+
}
|
|
305
|
+
if (F[0] += (Y.bunL[0] * T.bunL + Y.bunR[0] * T.bunR) * C, F[1] += (Y.bunL[1] * T.bunL + Y.bunR[1] * T.bunR) * C, F[1] -= _.browY * 7 * T.brow, T.brow > 0.01) {
|
|
306
|
+
const R = _.browAngle * 0.12 * T.brow;
|
|
307
|
+
F[1] += (x - n.face.brow.cx) * Math.sin(R);
|
|
308
|
+
}
|
|
309
|
+
F[1] += _.mouthOpen * 3.5 * T.jaw;
|
|
310
|
+
const Z = _.angleX / 30, E = _.angleY / 30;
|
|
311
|
+
return F[0] += Z * (8 * T.nose + 5 * T.mouth) + (x - n.face.eyeA.cx) * 0.12 * Z * T.eyeA - (x - n.face.eyeB.cx) * 0.12 * Z * T.eyeB - Z * 9 * T.earR + Z * 4 * T.earL - Z * 10 * (T.bunL + T.bunR), F[1] -= E * (6 * T.nose + 3 * T.mouth), F[1] += (M - n.face.eyeA.cy) * -0.06 * Math.abs(E) * T.eyeA + (M - n.face.eyeB.cy) * -0.06 * Math.abs(E) * T.eyeB, j(F, T.head, _, T.turn), k(F, M, _, T.chest, T.breath, T.shoulder), F;
|
|
312
|
+
}
|
|
313
|
+
const O = n.hand, $ = O?.elbow ?? [0, 0], D = O?.wrist ?? [0, 0], q = O?.knuckle ?? [0, 0], N = O?.contact ?? [0, 0], P = O?.forearmShare ?? 0;
|
|
314
|
+
function H(x, M) {
|
|
315
315
|
return O ? {
|
|
316
|
-
arm: 1 -
|
|
317
|
-
wrist: 1 -
|
|
318
|
-
hand: 1 -
|
|
319
|
-
finger:
|
|
320
|
-
pinBottom:
|
|
316
|
+
arm: 1 - u(...O.armBand, M),
|
|
317
|
+
wrist: 1 - u(...O.wristBand, M),
|
|
318
|
+
hand: 1 - u(...O.handBand, M),
|
|
319
|
+
finger: u(...O.fingerXBand, x) * (1 - u(...O.fingerYBand, M)),
|
|
320
|
+
pinBottom: u(...O.pinBand, M)
|
|
321
321
|
} : { arm: 0, wrist: 0, hand: 0, finger: 0, pinBottom: 0 };
|
|
322
322
|
}
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
return [M[0] +
|
|
326
|
-
},
|
|
327
|
-
function W(
|
|
328
|
-
const M = [...
|
|
329
|
-
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
const
|
|
334
|
-
return [
|
|
335
|
-
},
|
|
336
|
-
return { tr:
|
|
337
|
-
}
|
|
338
|
-
function
|
|
339
|
-
let
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
const
|
|
344
|
-
return
|
|
345
|
-
}
|
|
346
|
-
const
|
|
347
|
-
function
|
|
348
|
-
const
|
|
349
|
-
return
|
|
350
|
-
}
|
|
351
|
-
return { IMG: e, EYES: a, MOUTH:
|
|
323
|
+
const G = (x, M, T, _) => {
|
|
324
|
+
const Y = x[0] - M[0], X = x[1] - M[1];
|
|
325
|
+
return [M[0] + Y * T - X * _, M[1] + Y * _ + X * T];
|
|
326
|
+
}, z = (x) => Math.atan2(x[1], x[0]);
|
|
327
|
+
function W(x) {
|
|
328
|
+
const M = [...N];
|
|
329
|
+
j(M, w(...N), x, o(...N)), k(M, N[1], x, 0, 1, 0);
|
|
330
|
+
const T = [...$];
|
|
331
|
+
k(T, $[1], x, 0, 0, 0);
|
|
332
|
+
const Y = (z([M[0] - T[0], M[1] - T[1]]) - z([N[0] - $[0], N[1] - $[1]])) * P, X = Math.cos(Y), F = Math.sin(Y), C = (te) => {
|
|
333
|
+
const ee = G(te, $, X, F);
|
|
334
|
+
return [ee[0] + T[0] - $[0], ee[1] + T[1] - $[1]];
|
|
335
|
+
}, Z = C(D), E = C(N), R = z([M[0] - Z[0], M[1] - Z[1]]) - z([E[0] - Z[0], E[1] - Z[1]]), J = Math.min(1.03, Math.max(0.97, Math.hypot(M[0] - Z[0], M[1] - Z[1]) / Math.hypot(E[0] - Z[0], E[1] - Z[1])));
|
|
336
|
+
return { tr: C, w: Z, b: R, k: J };
|
|
337
|
+
}
|
|
338
|
+
function I(x, M, T, _, Y, X) {
|
|
339
|
+
let F = [x, M];
|
|
340
|
+
F = G(F, q, Math.cos(_.fingerTap * 0.07 * T.finger), Math.sin(_.fingerTap * 0.07 * T.finger));
|
|
341
|
+
const C = -_.handAngle / 10 * 0.045 * T.wrist, Z = -_.armAngle / 10 * 0.015 * T.arm;
|
|
342
|
+
F = G(F, D, Math.cos(C), Math.sin(C)), F = G(F, $, Math.cos(Z), Math.sin(Z)), F = Y.tr(F);
|
|
343
|
+
const E = Y.b * T.hand, R = 1 + (Y.k - 1) * T.hand;
|
|
344
|
+
return F = G(F, Y.w, Math.cos(E) * R, Math.sin(E) * R), F[1] += (M - F[1]) * T.pinBottom, X[0] = F[0], X[1] = F[1], X;
|
|
345
|
+
}
|
|
346
|
+
const V = n.accessories ?? [];
|
|
347
|
+
function K(x, M, T, _) {
|
|
348
|
+
const Y = A(x.pivot[0], x.pivot[1]);
|
|
349
|
+
return U(x.pivot[0], x.pivot[1], Y, M, T, _);
|
|
350
|
+
}
|
|
351
|
+
return { IMG: e, EYES: a, MOUTH: p, CHEEKS: b, STRANDS: i, TASSELS: V, headWeight: w, turnWeight: o, baseWeights: A, deformBase: U, applyHead: j, applyBody: k, handWeights: H, handFrame: W, deformHand: I, eyePartY: m, eyePartAlpha: c, tasselAnchor: K };
|
|
352
352
|
}
|
|
353
|
-
function
|
|
354
|
-
const a = r ? Math.max(e, t) * 2 : 1,
|
|
355
|
-
for (let f = 0; f < t; f++) for (let
|
|
356
|
-
const
|
|
357
|
-
n[
|
|
358
|
-
|
|
359
|
-
f ?
|
|
360
|
-
|
|
361
|
-
f &&
|
|
353
|
+
function wn(n, e, t, r = !1) {
|
|
354
|
+
const a = r ? Math.max(e, t) * 2 : 1, s = new Float32Array(n.length), l = Math.SQRT2;
|
|
355
|
+
for (let f = 0; f < t; f++) for (let y = 0; y < e; y++) {
|
|
356
|
+
const d = f * e + y;
|
|
357
|
+
n[d] <= 3 || (s[d] = Math.min(
|
|
358
|
+
y ? s[d - 1] + 1 : a,
|
|
359
|
+
f ? s[d - e] + 1 : a,
|
|
360
|
+
y && f ? s[d - e - 1] + l : a,
|
|
361
|
+
f && y + 1 < e ? s[d - e + 1] + l : a
|
|
362
362
|
));
|
|
363
363
|
}
|
|
364
|
-
for (let f = t - 1; f >= 0; f--) for (let
|
|
365
|
-
const
|
|
366
|
-
!n[
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
f + 1 < t ?
|
|
370
|
-
|
|
371
|
-
|
|
364
|
+
for (let f = t - 1; f >= 0; f--) for (let y = e - 1; y >= 0; y--) {
|
|
365
|
+
const d = f * e + y;
|
|
366
|
+
!n[d] || n[d] <= 3 || (s[d] = Math.min(
|
|
367
|
+
s[d],
|
|
368
|
+
y + 1 < e ? s[d + 1] + 1 : a,
|
|
369
|
+
f + 1 < t ? s[d + e] + 1 : a,
|
|
370
|
+
y && f + 1 < t ? s[d + e - 1] + l : a,
|
|
371
|
+
y + 1 < e && f + 1 < t ? s[d + e + 1] + l : a
|
|
372
372
|
));
|
|
373
373
|
}
|
|
374
|
-
return
|
|
374
|
+
return s;
|
|
375
375
|
}
|
|
376
|
-
function
|
|
376
|
+
function rt(n, e, t) {
|
|
377
377
|
return Math.exp(-(((n - t.cx) / t.rx) ** 2 + ((e - t.cy) / t.ry) ** 2));
|
|
378
378
|
}
|
|
379
|
-
function
|
|
379
|
+
function An(n, e, t) {
|
|
380
380
|
const r = ((n - t.head.cx) / t.head.rx) ** 2 + ((e - t.head.cy) / t.head.ry) ** 2;
|
|
381
|
-
let a = t.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + t.body.chest.rx * 0.23 *
|
|
382
|
-
a += t.face.nose.rx * 0.2 *
|
|
383
|
-
for (const [
|
|
381
|
+
let a = t.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + t.body.chest.rx * 0.23 * rt(n, e, t.body.chest);
|
|
382
|
+
a += t.face.nose.rx * 0.2 * rt(n, e, t.face.nose);
|
|
383
|
+
for (const [s, l] of t.cheeks) a += t.head.rx * 0.012 * rt(n, e, { cx: s, cy: l, rx: t.head.rx * 0.3, ry: t.head.ry * 0.16 });
|
|
384
384
|
return a;
|
|
385
385
|
}
|
|
386
|
-
function
|
|
387
|
-
const a = new Float32Array(n.length),
|
|
388
|
-
for (let
|
|
389
|
-
const
|
|
390
|
-
let
|
|
391
|
-
for (let
|
|
392
|
-
|
|
393
|
-
for (let
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
|
|
386
|
+
function Ke(n, e, t, r) {
|
|
387
|
+
const a = new Float32Array(n.length), s = new Float32Array(n.length), l = (f, y, d, m, c, p) => {
|
|
388
|
+
for (let b = 0; b < m; b++) {
|
|
389
|
+
const v = b * p;
|
|
390
|
+
let h = 0, u = 0;
|
|
391
|
+
for (let w = 0; w < Math.min(r, d - 1) + 1; w++)
|
|
392
|
+
h += f[v + w * c], u++;
|
|
393
|
+
for (let w = 0; w < d; w++) {
|
|
394
|
+
y[v + w * c] = h / u;
|
|
395
|
+
const o = w + r + 1, i = w - r;
|
|
396
|
+
o < d && (h += f[v + o * c], u++), i >= 0 && (h -= f[v + i * c], u--);
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
|
-
return
|
|
400
|
+
return l(n, a, e, t, 1, e), l(a, s, t, e, e, 1), s;
|
|
401
401
|
}
|
|
402
|
-
function
|
|
403
|
-
const a =
|
|
404
|
-
for (let
|
|
405
|
-
const f = new Float32Array(n.length * 2),
|
|
406
|
-
for (let
|
|
407
|
-
const
|
|
408
|
-
e[
|
|
402
|
+
function Mn(n, e, t, r) {
|
|
403
|
+
const a = Ke(n, t, r, 1), s = Ke(n, t, r, 6), l = new Float32Array(n.length);
|
|
404
|
+
for (let d = 0; d < l.length; d++) l[d] = e[d] > 128 ? a[d] - s[d] : 0;
|
|
405
|
+
const f = new Float32Array(n.length * 2), y = (d, m) => l[Math.max(0, Math.min(r - 1, m)) * t + Math.max(0, Math.min(t - 1, d))];
|
|
406
|
+
for (let d = 0; d < r; d++) for (let m = 0; m < t; m++) {
|
|
407
|
+
const c = d * t + m;
|
|
408
|
+
e[c] <= 128 || (f[2 * c] = Math.max(-1, Math.min(1, -(y(m + 1, d) - y(m - 1, d)) * 4)), f[2 * c + 1] = Math.max(-1, Math.min(1, -(y(m, d + 1) - y(m, d - 1)) * 4)));
|
|
409
409
|
}
|
|
410
410
|
return f;
|
|
411
411
|
}
|
|
412
|
-
function
|
|
413
|
-
const f = !!a && r[0] === 0 && r[1] === 0 && r[2] === a.image.width && r[3] === a.image.height,
|
|
414
|
-
for (let
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
for (let
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
return
|
|
412
|
+
function En(n, e, t, r, a, s = !0, l) {
|
|
413
|
+
const f = !!a && r[0] === 0 && r[1] === 0 && r[2] === a.image.width && r[3] === a.image.height, y = wn(n, e, t, f), d = new Float32Array(n.length), m = r[2] / e, c = r[3] / t, p = Math.min(m, c), b = Math.min(r[2], r[3]) * 0.08;
|
|
414
|
+
for (let o = 0; o < t; o++) for (let i = 0; i < e; i++) {
|
|
415
|
+
const S = o * e + i;
|
|
416
|
+
d[S] = (s ? Math.sqrt(y[S] * p * b) * 0.55 : 0) + (a ? An(r[0] + (i + 0.5) * m, r[1] + (o + 0.5) * c, a) : 0);
|
|
417
|
+
}
|
|
418
|
+
const v = Math.max(1, Math.round(Math.min(e, t) * 0.02));
|
|
419
|
+
d.set(Ke(Ke(d, e, t, v), e, t, v));
|
|
420
|
+
const h = l ? Mn(l, n, e, t) : null, u = new Uint8Array(e * t * 4), w = (o, i) => d[Math.max(0, Math.min(t - 1, i)) * e + Math.max(0, Math.min(e - 1, o))];
|
|
421
|
+
for (let o = 0; o < t; o++) for (let i = 0; i < e; i++) {
|
|
422
|
+
const S = -(w(i + 2, o) - w(i - 2, o)) / (4 * m), g = -(w(i, o + 2) - w(i, o - 2)) / (4 * c), A = Math.hypot(S, g, 1), L = (o * e + i) * 4, B = o * e + i;
|
|
423
|
+
u[L] = Math.round((S / A * 0.5 + 0.5) * 255), u[L + 1] = Math.round((g / A * 0.5 + 0.5) * 255), u[L + 2] = Math.round(((h?.[2 * B] ?? 0) * 0.5 + 0.5) * 255), u[L + 3] = Math.round(((h?.[2 * B + 1] ?? 0) * 0.5 + 0.5) * 255);
|
|
424
|
+
}
|
|
425
|
+
return u;
|
|
426
426
|
}
|
|
427
|
-
const
|
|
428
|
-
function
|
|
429
|
-
const a = JSON.stringify([e, t.head, t.body.chest, t.face.nose, t.cheeks, r]),
|
|
430
|
-
if (
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
const
|
|
436
|
-
for (let
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
return
|
|
427
|
+
const Nt = /* @__PURE__ */ new WeakMap();
|
|
428
|
+
function Sn(n, e, t, r) {
|
|
429
|
+
const a = JSON.stringify([e, t.head, t.body.chest, t.face.nose, t.cheeks, r]), s = Nt.get(n);
|
|
430
|
+
if (s?.key === a) return { ...s, computed: !1, ms: 0 };
|
|
431
|
+
const l = performance.now(), f = Math.min(1, 512 / Math.max(n.width, n.height)), y = Math.max(1, Math.round(n.width * f)), d = Math.max(1, Math.round(n.height * f)), m = document.createElement("canvas");
|
|
432
|
+
m.width = y, m.height = d;
|
|
433
|
+
const c = m.getContext("2d", { willReadFrequently: !0 });
|
|
434
|
+
c.drawImage(n, 0, 0, y, d);
|
|
435
|
+
const p = c.getImageData(0, 0, y, d).data, b = new Uint8Array(y * d), v = new Float32Array(y * d);
|
|
436
|
+
for (let u = 0; u < b.length; u++)
|
|
437
|
+
b[u] = p[4 * u + 3], v[u] = (0.2126 * p[4 * u] + 0.7152 * p[4 * u + 1] + 0.0722 * p[4 * u + 2]) / 255;
|
|
438
|
+
const h = { key: a, data: En(b, y, d, e, t, r, r ? v : void 0), width: y, height: d };
|
|
439
|
+
return Nt.set(n, h), { ...h, computed: !0, ms: performance.now() - l };
|
|
440
440
|
}
|
|
441
|
-
const
|
|
441
|
+
const Ue = Object.freeze({
|
|
442
442
|
enabled: !1,
|
|
443
443
|
x: 0.2,
|
|
444
444
|
y: 0.2,
|
|
@@ -455,7 +455,7 @@ const Fe = Object.freeze({
|
|
|
455
455
|
specular: 0.12,
|
|
456
456
|
rim: 0.3,
|
|
457
457
|
detail: 0.4
|
|
458
|
-
}),
|
|
458
|
+
}), Xt = {
|
|
459
459
|
x: [0, 1],
|
|
460
460
|
y: [0, 1],
|
|
461
461
|
z: [0.1, 2],
|
|
@@ -469,41 +469,41 @@ const Fe = Object.freeze({
|
|
|
469
469
|
specular: [0, 1],
|
|
470
470
|
rim: [0, 1],
|
|
471
471
|
detail: [0, 1]
|
|
472
|
-
},
|
|
473
|
-
function
|
|
472
|
+
}, Tn = /* @__PURE__ */ new Set(["color", "ambientColor"]);
|
|
473
|
+
function On(n) {
|
|
474
474
|
if (!n || typeof n != "object" || Array.isArray(n)) return null;
|
|
475
475
|
const e = n;
|
|
476
|
-
if (Object.keys(e).length !== Object.keys(
|
|
477
|
-
const t = { ...
|
|
478
|
-
for (const r of Object.keys(
|
|
479
|
-
const a = e[r], [
|
|
480
|
-
if (typeof a != "number" || !Number.isFinite(a) ||
|
|
481
|
-
t[r] = Math.max(
|
|
476
|
+
if (Object.keys(e).length !== Object.keys(Ue).length || Object.keys(e).some((r) => !(r in Ue)) || ![!0, !1].includes(e.enabled) || ![!0, !1].includes(e.shadow) || !["soft", "cel"].includes(e.mode)) return null;
|
|
477
|
+
const t = { ...Ue, enabled: e.enabled, shadow: e.shadow, mode: e.mode };
|
|
478
|
+
for (const r of Object.keys(Xt)) {
|
|
479
|
+
const a = e[r], [s, l] = Xt[r];
|
|
480
|
+
if (typeof a != "number" || !Number.isFinite(a) || Tn.has(r) && !Number.isInteger(a)) return null;
|
|
481
|
+
t[r] = Math.max(s, Math.min(l, a));
|
|
482
482
|
}
|
|
483
483
|
return t;
|
|
484
484
|
}
|
|
485
|
-
function
|
|
485
|
+
function Ur(n) {
|
|
486
486
|
return `#${n.toString(16).padStart(6, "0")}`;
|
|
487
487
|
}
|
|
488
|
-
const
|
|
489
|
-
function
|
|
488
|
+
const Ve = -0.1, Rn = 0.9, Ln = 1, _n = 1.06;
|
|
489
|
+
function kn(n, e) {
|
|
490
490
|
return [(0.5 - n) * 0.12, (0.5 - e) * 0.12];
|
|
491
491
|
}
|
|
492
|
-
function
|
|
493
|
-
const a = n * Math.PI / 180,
|
|
492
|
+
function Fn(n, e, t, r) {
|
|
493
|
+
const a = n * Math.PI / 180, s = e * Math.PI / 180, l = -t / 30 * r, f = Math.cos(a), y = Math.sin(a), d = Math.cos(s), m = Math.sin(s), c = Math.cos(l), p = Math.sin(l);
|
|
494
494
|
return [
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
f *
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
f *
|
|
495
|
+
c * f,
|
|
496
|
+
p * f,
|
|
497
|
+
-y,
|
|
498
|
+
c * y * m - p * d,
|
|
499
|
+
p * y * m + c * d,
|
|
500
|
+
f * m,
|
|
501
|
+
c * y * d + p * m,
|
|
502
|
+
p * y * d - c * m,
|
|
503
|
+
f * d
|
|
504
504
|
];
|
|
505
505
|
}
|
|
506
|
-
class
|
|
506
|
+
class Bn {
|
|
507
507
|
constructor(e, t) {
|
|
508
508
|
this.gl = e, this.program = t(e, `#version 300 es
|
|
509
509
|
out vec2 vUv;
|
|
@@ -521,19 +521,19 @@ class Fn {
|
|
|
521
521
|
}`), this.vao = e.createVertexArray(), this.targets = [];
|
|
522
522
|
}
|
|
523
523
|
target(e, t) {
|
|
524
|
-
const r = this.gl, a = r.createTexture(),
|
|
525
|
-
if (r.bindTexture(r.TEXTURE_2D, a), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, e, t, 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,
|
|
526
|
-
return { texture: a, framebuffer:
|
|
524
|
+
const r = this.gl, a = r.createTexture(), s = r.createFramebuffer();
|
|
525
|
+
if (r.bindTexture(r.TEXTURE_2D, a), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, e, t, 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, a, 0), r.checkFramebufferStatus(r.FRAMEBUFFER) !== r.FRAMEBUFFER_COMPLETE) throw new Error("Shadow framebuffer unavailable");
|
|
526
|
+
return { texture: a, framebuffer: s };
|
|
527
527
|
}
|
|
528
528
|
begin(e, t) {
|
|
529
529
|
const r = this.gl;
|
|
530
530
|
(this.width !== e || this.height !== t) && (this.clearTargets(), this.width = e, this.height = t, this.targets = [this.target(e, t), this.target(Math.ceil(e / 2), Math.ceil(t / 2))]), r.bindFramebuffer(r.FRAMEBUFFER, this.targets[0].framebuffer), r.viewport(0, 0, e, t), r.clearColor(0, 0, 0, 0), r.clear(r.COLOR_BUFFER_BIT);
|
|
531
531
|
}
|
|
532
532
|
composite(e) {
|
|
533
|
-
const t = this.gl, { prog: r, u: a } = this.program,
|
|
534
|
-
t.useProgram(r), t.bindVertexArray(this.vao), t.activeTexture(t.TEXTURE0), t.uniform1i(a.uTex, 0), t.disable(t.BLEND), t.bindFramebuffer(t.FRAMEBUFFER, this.targets[1].framebuffer), t.viewport(0, 0, Math.ceil(
|
|
535
|
-
const f =
|
|
536
|
-
t.uniform1i(a.uPass, 1), t.uniform2f(a.uShift, f[0], -f[1]), t.uniform2f(a.uStep, 0, 3 /
|
|
533
|
+
const t = this.gl, { prog: r, u: a } = this.program, s = this.width, l = this.height;
|
|
534
|
+
t.useProgram(r), t.bindVertexArray(this.vao), t.activeTexture(t.TEXTURE0), t.uniform1i(a.uTex, 0), t.disable(t.BLEND), t.bindFramebuffer(t.FRAMEBUFFER, this.targets[1].framebuffer), t.viewport(0, 0, Math.ceil(s / 2), Math.ceil(l / 2)), t.bindTexture(t.TEXTURE_2D, this.targets[0].texture), t.uniform1i(a.uPass, 0), t.uniform2f(a.uShift, 0, 0), t.uniform2f(a.uStep, 3 / s, 0), t.drawArrays(t.TRIANGLES, 0, 3), t.bindFramebuffer(t.FRAMEBUFFER, null), t.viewport(0, 0, s, l), t.clearColor(0, 0, 0, 0), t.clear(t.COLOR_BUFFER_BIT), t.enable(t.BLEND), t.bindTexture(t.TEXTURE_2D, this.targets[1].texture);
|
|
535
|
+
const f = kn(e.x, e.y);
|
|
536
|
+
t.uniform1i(a.uPass, 1), t.uniform2f(a.uShift, f[0], -f[1]), t.uniform2f(a.uStep, 0, 3 / l), t.drawArrays(t.TRIANGLES, 0, 3), t.bindTexture(t.TEXTURE_2D, this.targets[0].texture), t.uniform1i(a.uPass, 2), t.drawArrays(t.TRIANGLES, 0, 3), t.bindVertexArray(null);
|
|
537
537
|
}
|
|
538
538
|
clearTargets() {
|
|
539
539
|
for (const e of this.targets)
|
|
@@ -544,8 +544,8 @@ class Fn {
|
|
|
544
544
|
this.clearTargets(), this.gl.deleteProgram(this.program.prog), this.gl.deleteVertexArray(this.vao);
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
|
-
function
|
|
548
|
-
const { IMG: t, EYES: r, MOUTH: a, CHEEKS:
|
|
547
|
+
function Un(n, e) {
|
|
548
|
+
const { IMG: t, EYES: r, MOUTH: a, CHEEKS: s } = n, l = `#version 300 es
|
|
549
549
|
in vec2 aPos; in vec2 aUv;
|
|
550
550
|
uniform vec2 uScale; uniform vec2 uOffset;
|
|
551
551
|
out vec2 vUv;
|
|
@@ -657,7 +657,7 @@ function Bn(n, e) {
|
|
|
657
657
|
c = texAt(p);
|
|
658
658
|
}
|
|
659
659
|
outColor = c * uAlpha;
|
|
660
|
-
}`,
|
|
660
|
+
}`, y = l.replace("out vec2 vUv;", "in float aHeadWeight; out float vHeadWeight; out vec2 vScreen; out vec2 vUv;").replace("vUv = aUv;", "vHeadWeight = aHeadWeight; vScreen = vec2((aPos.x * uScale.x + uOffset.x + 1.0) * 0.5, (1.0 - aPos.y * uScale.y - uOffset.y) * 0.5); vUv = aUv;"), d = f.replace("uniform sampler2D uTex;", `uniform sampler2D uTex;
|
|
661
661
|
uniform sampler2D uNormal; in float vHeadWeight; in vec2 vScreen;
|
|
662
662
|
uniform mat3 uHeadRotation; uniform vec3 uLight; uniform vec3 uLightColor; uniform vec3 uAmbientColor;
|
|
663
663
|
uniform vec4 uLighting; uniform vec4 uSurface; uniform float uAspect; uniform int uCel;`).replace("outColor = c * uAlpha;", `
|
|
@@ -665,7 +665,7 @@ function Bn(n, e) {
|
|
|
665
665
|
vec4 encoded = texture(uNormal, vUv);
|
|
666
666
|
vec2 base = encoded.rg * 2.0 - 1.0;
|
|
667
667
|
vec3 n = vec3(base, sqrt(max(0.0, 1.0 - dot(base, base))));
|
|
668
|
-
n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${
|
|
668
|
+
n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${Rn.toFixed(3)}, 0.0));
|
|
669
669
|
n = normalize(mix(n, uHeadRotation * n, vHeadWeight));
|
|
670
670
|
vec2 toLight = (uLight.xy - vScreen) * vec2(uAspect, 1.0);
|
|
671
671
|
vec3 light = normalize(vec3(toLight, uLight.z));
|
|
@@ -673,21 +673,21 @@ function Bn(n, e) {
|
|
|
673
673
|
float diffuse;
|
|
674
674
|
if (uCel == 1) {
|
|
675
675
|
float w = 0.01 + uSurface.x * 0.08;
|
|
676
|
-
diffuse = 0.2 + 0.45 * smoothstep(${
|
|
676
|
+
diffuse = 0.2 + 0.45 * smoothstep(${Ve.toFixed(3)} - w, ${Ve.toFixed(3)} + w, ndl) + 0.35 * smoothstep(0.55 - w, 0.55 + w, ndl);
|
|
677
677
|
} else {
|
|
678
678
|
float s = 0.05 + uSurface.x * 0.5;
|
|
679
|
-
diffuse = smoothstep(${
|
|
679
|
+
diffuse = smoothstep(${Ve.toFixed(3)} - s, ${Ve.toFixed(3)} + s, ndl) * (0.35 + 0.65 * max(0.0, ndl));
|
|
680
680
|
}
|
|
681
681
|
float reach = dot(toLight, toLight) / (uLighting.w * uLighting.w);
|
|
682
682
|
float attenuation = 1.0 / (1.0 + reach);
|
|
683
683
|
vec3 radiance = uLightColor * uLighting.y * attenuation;
|
|
684
684
|
// A light close to the surface may brighten a little, but must not bleach painted colours.
|
|
685
|
-
vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${
|
|
685
|
+
vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${_n.toFixed(3)}));
|
|
686
686
|
// Painted shadows are deeper versions of the base colour, not grey: multiply by the colour
|
|
687
687
|
// itself as the surface turns away from the light.
|
|
688
688
|
vec3 albedo = c.rgb / max(c.a, 1e-4);
|
|
689
689
|
float dark = 1.0 - clamp(dot(irradiance, vec3(0.3333)), 0.0, 1.0);
|
|
690
|
-
vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${
|
|
690
|
+
vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${Ln.toFixed(3)}) * irradiance;
|
|
691
691
|
float specular = pow(max(dot(n, normalize(light + vec3(0.0, 0.0, 1.0))), 0.0), 60.0) * uSurface.y;
|
|
692
692
|
if (uCel == 1) specular = smoothstep(0.3, 0.35, specular) * uSurface.y;
|
|
693
693
|
vec2 side = length(n.xy) > 0.001 ? normalize(n.xy) : vec2(0.0);
|
|
@@ -695,308 +695,308 @@ function Bn(n, e) {
|
|
|
695
695
|
shaded += radiance * (specular * max(0.0, ndl) + rim) * c.a;
|
|
696
696
|
// Strength blends between the original painting and the relit result; alpha is unchanged.
|
|
697
697
|
c.rgb = clamp(mix(c.rgb, shaded, uLighting.x), vec3(0.0), vec3(c.a));
|
|
698
|
-
outColor = c * uAlpha;`),
|
|
698
|
+
outColor = c * uAlpha;`), m = `#version 300 es
|
|
699
699
|
in vec2 aPos; uniform vec2 uScale; uniform vec2 uOffset;
|
|
700
|
-
void main() { gl_Position = vec4(aPos * uScale + uOffset, 0.0, 1.0); gl_PointSize = 7.0; }`,
|
|
700
|
+
void main() { gl_Position = vec4(aPos * uScale + uOffset, 0.0, 1.0); gl_PointSize = 7.0; }`, c = `#version 300 es
|
|
701
701
|
precision mediump float; uniform vec4 uColor; out vec4 o; void main() { o = uColor; }`;
|
|
702
|
-
function
|
|
703
|
-
const
|
|
704
|
-
for (const [
|
|
705
|
-
const
|
|
706
|
-
if (
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
if (
|
|
710
|
-
const
|
|
711
|
-
for (let
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
}
|
|
715
|
-
return { prog:
|
|
716
|
-
}
|
|
717
|
-
function
|
|
718
|
-
const
|
|
719
|
-
let
|
|
720
|
-
for (;
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
}
|
|
724
|
-
return
|
|
725
|
-
}
|
|
726
|
-
function
|
|
727
|
-
const [
|
|
728
|
-
for (let
|
|
729
|
-
const
|
|
730
|
-
D[
|
|
731
|
-
}
|
|
732
|
-
const
|
|
733
|
-
for (let
|
|
734
|
-
const
|
|
702
|
+
function p(u, w, o) {
|
|
703
|
+
const i = u.createProgram();
|
|
704
|
+
for (const [A, L] of [[u.VERTEX_SHADER, w], [u.FRAGMENT_SHADER, o]]) {
|
|
705
|
+
const B = u.createShader(A);
|
|
706
|
+
if (u.shaderSource(B, L), u.compileShader(B), !u.getShaderParameter(B, u.COMPILE_STATUS)) throw new Error(u.getShaderInfoLog(B));
|
|
707
|
+
u.attachShader(i, B), u.deleteShader(B);
|
|
708
|
+
}
|
|
709
|
+
if (u.bindAttribLocation(i, 0, "aPos"), u.bindAttribLocation(i, 1, "aUv"), u.bindAttribLocation(i, 2, "aHeadWeight"), u.linkProgram(i), !u.getProgramParameter(i, u.LINK_STATUS)) throw new Error(u.getProgramInfoLog(i));
|
|
710
|
+
const S = {}, g = u.getProgramParameter(i, u.ACTIVE_UNIFORMS);
|
|
711
|
+
for (let A = 0; A < g; A++) {
|
|
712
|
+
const L = u.getActiveUniform(i, A).name.replace("[0]", "");
|
|
713
|
+
S[L] = u.getUniformLocation(i, L);
|
|
714
|
+
}
|
|
715
|
+
return { prog: i, u: S };
|
|
716
|
+
}
|
|
717
|
+
function b(u, w, o, i) {
|
|
718
|
+
const S = [u];
|
|
719
|
+
let g = u;
|
|
720
|
+
for (; g < u + w - 0.5; ) {
|
|
721
|
+
const A = i && g >= i.from && g < i.to ? i.cell : o;
|
|
722
|
+
g = Math.min(u + w, g + A), S.push(g);
|
|
723
|
+
}
|
|
724
|
+
return S;
|
|
725
|
+
}
|
|
726
|
+
function v(u, w, o, i, S = null) {
|
|
727
|
+
const [g, A, L, B] = u, j = b(g, L, w, S && { from: S.x0, to: S.x1, cell: S.cell }), k = b(A, B, w, S && { from: S.y0, to: S.y1, cell: S.cell }), U = j.length - 1, O = k.length - 1, $ = (U + 1) * (O + 1), D = new Float32Array($ * 2), q = new Float32Array($ * 2);
|
|
728
|
+
for (let z = 0; z <= O; z++) for (let W = 0; W <= U; W++) {
|
|
729
|
+
const I = z * (U + 1) + W;
|
|
730
|
+
D[I * 2] = j[W], D[I * 2 + 1] = k[z], q[I * 2] = (j[W] - g) / L, q[I * 2 + 1] = (k[z] - A) / B;
|
|
731
|
+
}
|
|
732
|
+
const N = [], P = [], H = o.length / i, G = i === 1 ? 0 : 1;
|
|
733
|
+
for (let z = 0; z < O; z++) for (let W = 0; W < U; W++) {
|
|
734
|
+
const I = Math.floor(j[W] - g) * G - 2, V = Math.ceil(j[W + 1] - g) * G + 2, K = Math.floor(k[z] - A) * G - 2, x = Math.ceil(k[z + 1] - A) * G + 2;
|
|
735
735
|
let M = !1;
|
|
736
|
-
for (let
|
|
737
|
-
for (let
|
|
738
|
-
if (
|
|
736
|
+
for (let F = Math.max(0, K); F < Math.min(H, x) && !M; F += 1)
|
|
737
|
+
for (let C = Math.max(0, I); C < Math.min(i, V); C += 1)
|
|
738
|
+
if (o[F * i + C] > 3) {
|
|
739
739
|
M = !0;
|
|
740
740
|
break;
|
|
741
741
|
}
|
|
742
742
|
if (!M) continue;
|
|
743
|
-
const
|
|
744
|
-
|
|
743
|
+
const T = z * (U + 1) + W, _ = T + 1, Y = T + U + 1, X = Y + 1;
|
|
744
|
+
N.push(T, _, Y, _, X, Y), P.push(T, _, T, Y, _, Y), W === U - 1 && P.push(_, X), z === O - 1 && P.push(Y, X);
|
|
745
745
|
}
|
|
746
|
-
return { rect:
|
|
746
|
+
return { rect: u, cols: U, rows: O, rest: D, uv: q, pos: new Float32Array(D), tris: new Uint32Array(N), lines: new Uint32Array(P) };
|
|
747
747
|
}
|
|
748
|
-
class
|
|
748
|
+
class h {
|
|
749
749
|
// padTop / padSide: margin around the image, as a share of its height / width. A negative
|
|
750
750
|
// padTop pushes the top of the image above the canvas (hides a cut-off top edge).
|
|
751
|
-
constructor(
|
|
752
|
-
this.pad = { top:
|
|
753
|
-
const
|
|
754
|
-
if (!
|
|
755
|
-
this.gl =
|
|
756
|
-
}
|
|
757
|
-
texture(
|
|
758
|
-
const
|
|
759
|
-
return
|
|
760
|
-
}
|
|
761
|
-
addLayer(
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
for (const
|
|
767
|
-
const D =
|
|
768
|
-
|
|
751
|
+
constructor(w, { padTop: o = 0, padSide: i = 0, fit: S = "contain" } = {}) {
|
|
752
|
+
this.pad = { top: o, side: i }, this.fit = S;
|
|
753
|
+
const g = w.getContext("webgl2", { premultipliedAlpha: !0, antialias: !0, alpha: !0, preserveDrawingBuffer: !0 });
|
|
754
|
+
if (!g) throw new Error("WebGL2 is not available");
|
|
755
|
+
this.gl = g, this.canvas = w, this.main = p(g, l, f), this.line = p(g, m, c), this.layers = [], this.lighting = Ue, this.lightingStats = { normalMs: 0, computedLayers: 0, cachedLayers: 0 }, g.enable(g.BLEND), g.blendFunc(g.ONE, g.ONE_MINUS_SRC_ALPHA);
|
|
756
|
+
}
|
|
757
|
+
texture(w) {
|
|
758
|
+
const o = this.gl, i = o.createTexture();
|
|
759
|
+
return o.bindTexture(o.TEXTURE_2D, i), o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, o.RGBA, o.UNSIGNED_BYTE, w), o.generateMipmap(o.TEXTURE_2D), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR_MIPMAP_LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), i;
|
|
760
|
+
}
|
|
761
|
+
addLayer(w, o, i, S = {}) {
|
|
762
|
+
const g = this.gl, A = g.createVertexArray();
|
|
763
|
+
g.bindVertexArray(A);
|
|
764
|
+
const L = g.createBuffer();
|
|
765
|
+
g.bindBuffer(g.ARRAY_BUFFER, L), g.bufferData(g.ARRAY_BUFFER, i.pos, g.DYNAMIC_DRAW);
|
|
766
|
+
for (const $ of [this.main, this.line]) {
|
|
767
|
+
const D = g.getAttribLocation($.prog, "aPos");
|
|
768
|
+
g.enableVertexAttribArray(D), g.vertexAttribPointer(D, 2, g.FLOAT, !1, 0, 0);
|
|
769
769
|
}
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
const
|
|
777
|
-
|
|
778
|
-
const O = { name:
|
|
770
|
+
const B = g.createBuffer();
|
|
771
|
+
g.bindBuffer(g.ARRAY_BUFFER, B), g.bufferData(g.ARRAY_BUFFER, i.uv, g.STATIC_DRAW);
|
|
772
|
+
const j = g.getAttribLocation(this.main.prog, "aUv");
|
|
773
|
+
g.enableVertexAttribArray(j), g.vertexAttribPointer(j, 2, g.FLOAT, !1, 0, 0);
|
|
774
|
+
const k = g.createBuffer();
|
|
775
|
+
g.bindBuffer(g.ELEMENT_ARRAY_BUFFER, k), g.bufferData(g.ELEMENT_ARRAY_BUFFER, i.tris, g.STATIC_DRAW), g.bindVertexArray(null);
|
|
776
|
+
const U = g.createBuffer();
|
|
777
|
+
g.bindBuffer(g.ELEMENT_ARRAY_BUFFER, U), g.bufferData(g.ELEMENT_ARRAY_BUFFER, i.lines, g.STATIC_DRAW);
|
|
778
|
+
const O = { name: w, image: o, mesh: i, tex: this.texture(o), vao: A, posBuf: L, uvBuf: B, triBuf: k, lineBuf: U, visible: !0, face: !!S.face, eyeBall: S.eyeBall, color: S.color || [1, 1, 1, 1] };
|
|
779
779
|
return this.layers.push(O), O;
|
|
780
780
|
}
|
|
781
781
|
destroy() {
|
|
782
|
-
const
|
|
783
|
-
for (const
|
|
784
|
-
|
|
785
|
-
for (const
|
|
782
|
+
const w = this.gl;
|
|
783
|
+
for (const o of this.layers) {
|
|
784
|
+
w.deleteTexture(o.tex), o.normal && w.deleteTexture(o.normal), o.headBuf && w.deleteBuffer(o.headBuf), w.deleteVertexArray(o.vao);
|
|
785
|
+
for (const i of [o.posBuf, o.uvBuf, o.triBuf, o.lineBuf]) w.deleteBuffer(i);
|
|
786
786
|
}
|
|
787
|
-
|
|
788
|
-
}
|
|
789
|
-
setLighting(
|
|
790
|
-
if (this.lighting =
|
|
791
|
-
const
|
|
792
|
-
this.lit || (this.lit =
|
|
793
|
-
for (const
|
|
794
|
-
if (
|
|
795
|
-
const
|
|
796
|
-
this.lightingStats.normalMs +=
|
|
797
|
-
const
|
|
798
|
-
for (let
|
|
799
|
-
|
|
787
|
+
w.deleteProgram(this.main.prog), w.deleteProgram(this.line.prog), this.lit && w.deleteProgram(this.lit.prog), this.shadow?.destroy(), this.layers.length = 0;
|
|
788
|
+
}
|
|
789
|
+
setLighting(w) {
|
|
790
|
+
if (this.lighting = On({ ...Ue, ...w }) ?? Ue, !this.lighting.enabled) return;
|
|
791
|
+
const o = this.gl;
|
|
792
|
+
this.lit || (this.lit = p(o, y, d));
|
|
793
|
+
for (const i of this.layers) {
|
|
794
|
+
if (i.normal || i.overlay) continue;
|
|
795
|
+
const S = Sn(i.image, i.mesh.rect, e, !/^(eye|mouth)/.test(i.name));
|
|
796
|
+
this.lightingStats.normalMs += S.ms, this.lightingStats[S.computed ? "computedLayers" : "cachedLayers"]++, i.normal = o.createTexture(), o.activeTexture(o.TEXTURE0), o.bindTexture(o.TEXTURE_2D, i.normal), o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, S.width, S.height, 0, o.RGBA, o.UNSIGNED_BYTE, S.data), o.generateMipmap(o.TEXTURE_2D), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR_MIPMAP_LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE);
|
|
797
|
+
const g = new Float32Array(i.mesh.rest.length / 2);
|
|
798
|
+
for (let A = 0; A < g.length; A++) g[A] = n.headWeight(i.mesh.rest[A * 2], i.mesh.rest[A * 2 + 1]);
|
|
799
|
+
i.headBuf = o.createBuffer(), o.bindVertexArray(i.vao), o.bindBuffer(o.ARRAY_BUFFER, i.headBuf), o.bufferData(o.ARRAY_BUFFER, g, o.STATIC_DRAW), o.enableVertexAttribArray(2), o.vertexAttribPointer(2, 1, o.FLOAT, !1, 0, 0);
|
|
800
800
|
}
|
|
801
|
-
|
|
801
|
+
o.bindVertexArray(null), this.lighting.shadow && !this.shadow && (this.shadow = new Bn(o, p));
|
|
802
802
|
}
|
|
803
803
|
resize() {
|
|
804
|
-
const
|
|
805
|
-
(
|
|
806
|
-
const
|
|
807
|
-
this.scale = [2 *
|
|
808
|
-
}
|
|
809
|
-
draw(
|
|
810
|
-
const
|
|
811
|
-
this.resize(),
|
|
812
|
-
const
|
|
813
|
-
|
|
814
|
-
const
|
|
815
|
-
if (this.current =
|
|
816
|
-
const
|
|
817
|
-
|
|
804
|
+
const w = this.canvas, o = Math.min(window.devicePixelRatio || 1, 2), i = Math.round(w.clientWidth * o), S = Math.round(w.clientHeight * o);
|
|
805
|
+
(w.width !== i || w.height !== S) && (w.width = i, w.height = S);
|
|
806
|
+
const g = (this.fit === "cover" ? Math.max : Math.min)(i / (t.w * (1 + 2 * this.pad.side)), S / (t.h * (1 + this.pad.top))), A = (i - t.w * g) / 2, L = (S - t.h * g) / (this.fit === "cover" ? 2 : 1);
|
|
807
|
+
this.scale = [2 * g / i, -2 * g / S], this.offset = [-1 + 2 * A / i, 1 - 2 * L / S], this.pxScale = g, this.pxOff = [A, L];
|
|
808
|
+
}
|
|
809
|
+
draw(w) {
|
|
810
|
+
const o = this.gl;
|
|
811
|
+
this.resize(), o.viewport(0, 0, this.canvas.width, this.canvas.height), o.clearColor(0, 0, 0, 0), o.clear(o.COLOR_BUFFER_BIT);
|
|
812
|
+
const i = this.lighting.enabled, S = i && this.lighting.shadow;
|
|
813
|
+
S && this.shadow.begin(this.canvas.width, this.canvas.height);
|
|
814
|
+
const g = i ? this.lit : this.main;
|
|
815
|
+
if (this.current = g, o.useProgram(g.prog), i) {
|
|
816
|
+
const A = this.lighting;
|
|
817
|
+
o.uniform1i(g.u.uNormal, 1), o.uniform3f(g.u.uLight, A.x, A.y, A.z), o.uniform3f(g.u.uLightColor, (A.color >> 16 & 255) / 255, (A.color >> 8 & 255) / 255, (A.color & 255) / 255), o.uniform3f(g.u.uAmbientColor, (A.ambientColor >> 16 & 255) / 255, (A.ambientColor >> 8 & 255) / 255, (A.ambientColor & 255) / 255), o.uniform4f(g.u.uLighting, A.strength, A.intensity, A.ambient, A.reach), o.uniform4f(g.u.uSurface, A.softness, A.specular, A.rim, A.detail), o.uniform1f(g.u.uAspect, this.canvas.width / this.canvas.height), o.uniform1i(g.u.uCel, A.mode === "cel" ? 1 : 0), o.uniformMatrix3fv(g.u.uHeadRotation, !1, Fn(w.angleX ?? 0, w.angleY ?? 0, w.angleZ ?? 0, e.head.maxRoll));
|
|
818
818
|
}
|
|
819
|
-
|
|
820
|
-
for (const
|
|
821
|
-
!
|
|
822
|
-
if (this.original &&
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
for (const
|
|
826
|
-
!
|
|
827
|
-
|
|
819
|
+
o.uniform2fv(g.u.uScale, this.scale), o.uniform2fv(g.u.uOffset, this.offset), o.uniform1i(g.u.uTex, 0), o.uniform4fv(g.u.uEyeBox, r.flatMap((A) => [A.x0, A.x1, 0, 0])), o.uniform1fv(g.u.uEyeTop, r.flatMap((A) => A.top)), o.uniform1fv(g.u.uEyeBot, r.flatMap((A) => A.bot)), o.uniform4fv(g.u.uEyeState, w.eyes), o.uniform4f(g.u.uMouth, a.cx, a.cy, a.angle, a.halfLen), o.uniform4f(g.u.uMouthState, w.mouthOpen, w.mouthForm, a.bow, 0), o.uniform4f(g.u.uCheeks, s[0][0], s[0][1], s[1][0], s[1][1]), o.uniform1f(g.u.uCheek, w.cheek), o.activeTexture(o.TEXTURE0);
|
|
820
|
+
for (const A of this.layers)
|
|
821
|
+
!A.visible || A.overlay || this.drawLayer(A, A.alpha ?? 1);
|
|
822
|
+
if (this.original && w.originalAlpha > 0 && this.drawLayer(this.original, w.originalAlpha), S && this.shadow.composite(this.lighting), w.showMesh) {
|
|
823
|
+
const A = this.line;
|
|
824
|
+
o.useProgram(A.prog), o.uniform2fv(A.u.uScale, this.scale), o.uniform2fv(A.u.uOffset, this.offset);
|
|
825
|
+
for (const L of this.layers)
|
|
826
|
+
!L.visible || L.overlay || (o.bindVertexArray(L.vao), o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, L.lineBuf), o.uniform4fv(A.u.uColor, L.color), o.drawElements(o.LINES, L.mesh.lines.length, o.UNSIGNED_INT, 0), o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, L.triBuf));
|
|
827
|
+
w.joints?.length && this.drawPoints(w.joints), o.bindVertexArray(null);
|
|
828
828
|
}
|
|
829
829
|
}
|
|
830
|
-
drawLayer(
|
|
831
|
-
const
|
|
832
|
-
|
|
830
|
+
drawLayer(w, o) {
|
|
831
|
+
const i = this.gl, S = this.current;
|
|
832
|
+
i.useProgram(S.prog), i.bindVertexArray(w.vao), i.bindBuffer(i.ARRAY_BUFFER, w.posBuf), i.bufferSubData(i.ARRAY_BUFFER, 0, w.mesh.pos), this.lighting.enabled && (i.activeTexture(i.TEXTURE1), i.bindTexture(i.TEXTURE_2D, w.normal), i.activeTexture(i.TEXTURE0)), i.bindTexture(i.TEXTURE_2D, w.tex), i.uniform4fv(S.u.uRect, w.mesh.rect), i.uniform1i(S.u.uFace, w.eyeBall !== void 0 ? 2 + w.eyeBall : w.face ? 1 : 0), i.uniform1f(S.u.uAlpha, o), i.drawElements(i.TRIANGLES, w.mesh.tris.length, i.UNSIGNED_INT, 0);
|
|
833
833
|
}
|
|
834
|
-
drawPoints(
|
|
835
|
-
const
|
|
834
|
+
drawPoints(w) {
|
|
835
|
+
const o = this.gl, i = this.line;
|
|
836
836
|
if (!this.pointBuf) {
|
|
837
|
-
this.pointBuf =
|
|
838
|
-
const
|
|
839
|
-
|
|
837
|
+
this.pointBuf = o.createBuffer(), this.pointVao = o.createVertexArray(), o.bindVertexArray(this.pointVao), o.bindBuffer(o.ARRAY_BUFFER, this.pointBuf);
|
|
838
|
+
const S = o.getAttribLocation(i.prog, "aPos");
|
|
839
|
+
o.enableVertexAttribArray(S), o.vertexAttribPointer(S, 2, o.FLOAT, !1, 0, 0);
|
|
840
840
|
}
|
|
841
|
-
|
|
841
|
+
o.bindVertexArray(this.pointVao), o.bindBuffer(o.ARRAY_BUFFER, this.pointBuf), o.bufferData(o.ARRAY_BUFFER, new Float32Array(w.flat()), o.DYNAMIC_DRAW), o.uniform4f(i.u.uColor, 1, 0.85, 0.2, 1), o.drawArrays(o.POINTS, 0, w.length);
|
|
842
842
|
}
|
|
843
843
|
// canvas CSS px -> source image px
|
|
844
|
-
toImage(
|
|
844
|
+
toImage(w, o) {
|
|
845
845
|
if (!this.pxOff) return null;
|
|
846
|
-
const
|
|
847
|
-
return [(
|
|
846
|
+
const i = this.canvas.width / this.canvas.clientWidth;
|
|
847
|
+
return [(w * i - this.pxOff[0]) / this.pxScale, (o * i - this.pxOff[1]) / this.pxScale];
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
|
-
return { Renderer:
|
|
850
|
+
return { Renderer: h, buildGrid: v };
|
|
851
851
|
}
|
|
852
|
-
function
|
|
853
|
-
const { applyHead: t, applyBody: r, TASSELS: a, tasselAnchor:
|
|
854
|
-
if (
|
|
855
|
-
const
|
|
856
|
-
const
|
|
857
|
-
return [0, 1].map((
|
|
852
|
+
function Yn(n, e) {
|
|
853
|
+
const { applyHead: t, applyBody: r, TASSELS: a, tasselAnchor: s } = n, l = (e.strands ?? []).map((o) => {
|
|
854
|
+
if (o.nodes.length === 4) return o;
|
|
855
|
+
const i = Array.from({ length: 4 }, (S, g) => {
|
|
856
|
+
const A = g / 3 * (o.nodes.length - 1), L = Math.min(o.nodes.length - 2, Math.floor(A)), B = A - L;
|
|
857
|
+
return [0, 1].map((j) => o.nodes[L][j] + (o.nodes[L + 1][j] - o.nodes[L][j]) * B);
|
|
858
858
|
});
|
|
859
|
-
return { ...
|
|
860
|
-
}), f = [0, 300, 200, 140],
|
|
861
|
-
const
|
|
862
|
-
if (
|
|
863
|
-
const
|
|
864
|
-
return [
|
|
865
|
-
},
|
|
866
|
-
const
|
|
867
|
-
|
|
859
|
+
return { ...o, nodes: i };
|
|
860
|
+
}), f = [0, 300, 200, 140], y = 0.9, d = 7, m = { stiff: 1.7, damp: 1.6, couple: 0.85, reach: 0.9, bind: 4 }, c = Math.min(6, l.filter((o) => o.name.startsWith("bang")).length), p = { freq: 0.7, zeta: 0.22, hang: 0.85, inertia: 0.32, wind: 0.03, max: 0.55, smooth: 6 }, b = (o, i) => [o[0] * Math.cos(i) - o[1] * Math.sin(i), o[0] * Math.sin(i) + o[1] * Math.cos(i)], v = (o, i) => {
|
|
861
|
+
const S = Math.hypot(o[0], o[1]);
|
|
862
|
+
if (S < 1e-6) return o;
|
|
863
|
+
const g = i * Math.tanh(S / i) / S;
|
|
864
|
+
return [o[0] * g, o[1] * g];
|
|
865
|
+
}, h = Object.fromEntries(Object.entries(e.buns ?? {}).map(([o, i]) => [o, { at: [i.cx, i.cy], k: 260, c: 11, hang: 3, max: 4 }])), u = (o, i) => {
|
|
866
|
+
const S = Math.hypot(o[0], o[1]);
|
|
867
|
+
S > i && (o[0] *= i / S, o[1] *= i / S);
|
|
868
868
|
};
|
|
869
|
-
class
|
|
869
|
+
class w {
|
|
870
870
|
constructor() {
|
|
871
871
|
this.gain = 1, this.out = { gain: 1, bunL: [0, 0], bunR: [0, 0] }, this.hair = {};
|
|
872
|
-
for (const
|
|
873
|
-
this.hair[
|
|
874
|
-
this.strands =
|
|
875
|
-
const
|
|
876
|
-
return { t:
|
|
872
|
+
for (const i of Object.keys(h))
|
|
873
|
+
this.hair[i] = { p: null, v: [0, 0] }, this.out[i] = [0, 0];
|
|
874
|
+
this.strands = l.map(() => ({ p: null, v: [[0, 0], [0, 0], [0, 0], [0, 0]] })), this.out.strands = l.map(() => [[0, 0], [0, 0], [0, 0], [0, 0]]), this.chains = a.map((i) => {
|
|
875
|
+
const S = i.tip[0] - i.pivot[0], g = i.tip[1] - i.pivot[1], A = Math.hypot(S, g), L = [S / A, g / A];
|
|
876
|
+
return { t: i, dir: L, L1: A * i.split, L2: A * (1 - i.split), pts: null, prev: null, phi: [0, 0], anchor: [0, 0] };
|
|
877
877
|
}), this.time = 0;
|
|
878
878
|
}
|
|
879
|
-
hairAnchor(
|
|
880
|
-
const
|
|
881
|
-
return t(
|
|
882
|
-
}
|
|
883
|
-
step(
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
const O = this.strands[
|
|
887
|
-
O.p || (O.p = D.map((
|
|
888
|
-
const
|
|
889
|
-
for (let
|
|
890
|
-
const
|
|
891
|
-
for (let
|
|
892
|
-
const
|
|
893
|
-
M[0] += (
|
|
879
|
+
hairAnchor(i, S) {
|
|
880
|
+
const g = [i[0], i[1]];
|
|
881
|
+
return t(g, 1, S), r(g, i[1], S), g;
|
|
882
|
+
}
|
|
883
|
+
step(i, S) {
|
|
884
|
+
const g = Math.max(1, Math.ceil(S / 0.004166666666666667)), A = Math.min(S, 0.05) / g, L = -i.angleZ / 30 * e.head.maxRoll - i.bodyAngleZ / 10 * e.body.maxRoll, B = this.gain;
|
|
885
|
+
l.forEach((k, U) => {
|
|
886
|
+
const O = this.strands[U], $ = this.out.strands[U], D = k.nodes.map((N) => this.hairAnchor(N, i));
|
|
887
|
+
O.p || (O.p = D.map((N) => [...N]));
|
|
888
|
+
const q = U * 1.7;
|
|
889
|
+
for (let N = 0; N < g; N++) {
|
|
890
|
+
const P = this.time + N * A;
|
|
891
|
+
for (let H = 1; H < 4; H++) {
|
|
892
|
+
const G = Math.hypot(k.nodes[H][0] - k.nodes[0][0], k.nodes[H][1] - k.nodes[0][1]), z = (Math.sin(P * 1.3) * 0.5 + Math.sin(P * 3.1) * 0.3 + Math.sin(P * 4.7 + q) * 0.2) * k.max * 0.1 * H / 3, W = [O.p[H - 1][0] - D[H - 1][0], O.p[H - 1][1] - D[H - 1][1]], I = D[H][0] + W[0] * y * m.couple - Math.sin(L) * G * 0.12 + z, V = D[H][1] + W[1] * y * m.couple, K = f[H] * k.k * m.stiff / Math.max(0.35, B), x = d * m.damp * Math.sqrt(m.stiff) / Math.max(0.5, Math.sqrt(B)), M = O.v[H], T = O.p[H];
|
|
893
|
+
M[0] += (K * (I - T[0]) - x * M[0]) * A, M[1] += (K * (V - T[1]) - x * M[1]) * A, T[0] += M[0] * A, T[1] += M[1] * A;
|
|
894
894
|
}
|
|
895
895
|
O.p[0] = [...D[0]];
|
|
896
896
|
}
|
|
897
|
-
for (let
|
|
898
|
-
const
|
|
899
|
-
|
|
897
|
+
for (let N = 0; N < 4; N++) {
|
|
898
|
+
const P = [O.p[N][0] - D[N][0], O.p[N][1] - D[N][1]];
|
|
899
|
+
$[N] = v(P, Math.max(0.5, k.max * m.reach * Math.max(1, B) * N / 3));
|
|
900
900
|
}
|
|
901
901
|
});
|
|
902
|
-
for (const [
|
|
903
|
-
const O = this.hair[
|
|
904
|
-
O.p || (O.p = [
|
|
905
|
-
const
|
|
906
|
-
for (let
|
|
907
|
-
O.v[0] += (
|
|
908
|
-
const
|
|
909
|
-
|
|
902
|
+
for (const [k, U] of Object.entries(h)) {
|
|
903
|
+
const O = this.hair[k], $ = this.hairAnchor(U.at, i), D = Math.sin(this.time * 1.3 + U.at[0] * 0.01) * 0.6 + Math.sin(this.time * 2.9 + U.at[1] * 0.02) * 0.4, q = $[0] - Math.sin(L) * U.hang + D * U.max * 0.12, N = $[1];
|
|
904
|
+
O.p || (O.p = [q, N]);
|
|
905
|
+
const P = U.k / Math.max(0.35, B), H = U.c / Math.max(0.5, Math.sqrt(B));
|
|
906
|
+
for (let z = 0; z < g; z++)
|
|
907
|
+
O.v[0] += (P * (q - O.p[0]) - H * O.v[0]) * A, O.v[1] += (P * (N - O.p[1]) - H * O.v[1]) * A, O.p[0] += O.v[0] * A, O.p[1] += O.v[1] * A;
|
|
908
|
+
const G = [O.p[0] - $[0], O.p[1] - $[1]];
|
|
909
|
+
u(G, U.max * Math.max(1, B)), this.out[k] = G;
|
|
910
910
|
}
|
|
911
911
|
this.out.gain = 1;
|
|
912
|
-
const
|
|
913
|
-
for (let
|
|
914
|
-
const O =
|
|
915
|
-
for (let
|
|
916
|
-
const D = O[Math.max(0,
|
|
917
|
-
for (const
|
|
912
|
+
const j = this.out.strands;
|
|
913
|
+
for (let k = 0; k < m.bind; k++) for (let U = 1; U < 4; U++) {
|
|
914
|
+
const O = j.slice(0, c).map(($) => [...$[U]]);
|
|
915
|
+
for (let $ = 0; $ < c; $++) {
|
|
916
|
+
const D = O[Math.max(0, $ - 1)], q = O[Math.min(c - 1, $ + 1)];
|
|
917
|
+
for (const N of [0, 1]) j[$][U][N] = O[$][N] * 0.5 + (D[N] + q[N]) * 0.25;
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
|
-
for (const
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
const O =
|
|
924
|
-
O.acc = [O.acc[0] + (
|
|
925
|
-
const
|
|
926
|
-
for (let M = 0; M <
|
|
927
|
-
const
|
|
928
|
-
O.w[0] +=
|
|
929
|
-
const
|
|
930
|
-
O.w[1] +=
|
|
920
|
+
for (const k of this.chains) {
|
|
921
|
+
const U = s(k.t, i, this.out, [0, 0]);
|
|
922
|
+
k.st || (k.st = { th: [0, 0], w: [0, 0], pos: [...U], vel: [0, 0], acc: [0, 0] });
|
|
923
|
+
const O = k.st, $ = p, D = [(U[0] - O.pos[0]) / Math.max(S, 1e-3), (U[1] - O.pos[1]) / Math.max(S, 1e-3)], q = 1 - Math.exp(-S * $.smooth), N = [(D[0] - O.vel[0]) / Math.max(S, 1e-3), (D[1] - O.vel[1]) / Math.max(S, 1e-3)];
|
|
924
|
+
O.acc = [O.acc[0] + (N[0] - O.acc[0]) * q, O.acc[1] + (N[1] - O.acc[1]) * q], O.vel = [O.vel[0] + (D[0] - O.vel[0]) * q, O.vel[1] + (D[1] - O.vel[1]) * q], O.pos = [...U];
|
|
925
|
+
const P = [-k.dir[1], k.dir[0]], H = -(O.acc[0] * P[0] + O.acc[1] * P[1]) / (k.L1 + k.L2) * $.inertia, G = (Math.sin(this.time * 0.9 + k.t.pivot[0]) * 0.6 + Math.sin(this.time * 0.37 + k.t.pivot[1]) * 0.4) * $.wind, z = -L * $.hang + G, W = 2 * Math.PI * $.freq / Math.sqrt(Math.max(0.4, B)), I = W * 1.35;
|
|
926
|
+
for (let M = 0; M < g; M++) {
|
|
927
|
+
const T = -W * W * (O.th[0] - z) - 2 * $.zeta * W * O.w[0] + H;
|
|
928
|
+
O.w[0] += T * A, O.th[0] += O.w[0] * A;
|
|
929
|
+
const _ = -I * I * (O.th[1] - O.th[0]) - 2 * $.zeta * I * O.w[1] + H * 0.4 + T * 0.5;
|
|
930
|
+
O.w[1] += _ * A, O.th[1] += O.w[1] * A;
|
|
931
931
|
}
|
|
932
|
-
O.th[0] = Math.max(-0.55, Math.min(
|
|
933
|
-
const
|
|
934
|
-
|
|
932
|
+
O.th[0] = Math.max(-0.55, Math.min($.max, O.th[0])), O.th[1] = Math.max(-0.55 * 1.4, Math.min($.max * 1.4, O.th[1])), k.phi = [O.th[0], O.th[1]];
|
|
933
|
+
const V = b(k.dir, O.th[0]), K = b(k.dir, O.th[1]), x = [U[0] + V[0] * k.L1, U[1] + V[1] * k.L1];
|
|
934
|
+
k.pts = [[...U], x, [x[0] + K[0] * k.L2, x[1] + K[1] * k.L2]], k.anchor = U;
|
|
935
935
|
}
|
|
936
|
-
return this.time +=
|
|
936
|
+
return this.time += S, this.out;
|
|
937
937
|
}
|
|
938
938
|
}
|
|
939
|
-
return { Physics:
|
|
939
|
+
return { Physics: w };
|
|
940
940
|
}
|
|
941
|
-
function
|
|
942
|
-
const { baseWeights: t, deformBase: r, MOUTH: a } = n,
|
|
943
|
-
const
|
|
944
|
-
return
|
|
945
|
-
},
|
|
941
|
+
function jn(n, e) {
|
|
942
|
+
const { baseWeights: t, deformBase: r, MOUTH: a } = n, s = (g, A, L) => {
|
|
943
|
+
const B = Math.min(1, Math.max(0, (L - g) / (A - g)));
|
|
944
|
+
return B * B * (3 - 2 * B);
|
|
945
|
+
}, l = e.mouth.area, f = {
|
|
946
946
|
a: { sprite: "mouth_a", ref: 0.9, width: 1 },
|
|
947
947
|
aHalf: { sprite: "mouth_a_half", ref: 0.55, width: 1 },
|
|
948
948
|
i: { sprite: "mouth_i", ref: 0.55, width: 1 },
|
|
949
949
|
e: { sprite: "mouth_a_half", ref: 0.65, width: 1.06 },
|
|
950
950
|
o: { sprite: "mouth_o", ref: 0.75, width: 1 },
|
|
951
951
|
u: { sprite: "mouth_o", ref: 0.75, width: 0.78 }
|
|
952
|
-
},
|
|
953
|
-
function
|
|
954
|
-
const
|
|
955
|
-
return
|
|
956
|
-
}
|
|
957
|
-
const
|
|
958
|
-
function
|
|
959
|
-
return
|
|
960
|
-
}
|
|
961
|
-
function
|
|
962
|
-
if (
|
|
963
|
-
const
|
|
964
|
-
return
|
|
965
|
-
}
|
|
966
|
-
function
|
|
967
|
-
return a.cy + (
|
|
968
|
-
}
|
|
969
|
-
function
|
|
970
|
-
return
|
|
971
|
-
}
|
|
972
|
-
function
|
|
973
|
-
const
|
|
974
|
-
return 1 -
|
|
975
|
-
}
|
|
976
|
-
function
|
|
977
|
-
const
|
|
978
|
-
for (const [
|
|
979
|
-
const
|
|
980
|
-
for (let
|
|
981
|
-
const
|
|
982
|
-
|
|
952
|
+
}, y = 0.16, d = ["angry", "sad"];
|
|
953
|
+
function m(g, A) {
|
|
954
|
+
const B = (U, O, $) => U >= O - (A ? 0.07 : 0) && U < $ + (A ? 0.07 : 0), j = [["i", -9, -0.55], ["e", -0.55, -0.2], ["a", -0.2, 0.35], ["o", 0.35, 0.75], ["u", 0.75, 9]], k = A && j.find((U) => U[0] === A || A === "aHalf" && U[0] === "a");
|
|
955
|
+
return k && B(g, k[1], k[2]) ? k[0] : j.find((U) => g >= U[1] && g < U[2])[0];
|
|
956
|
+
}
|
|
957
|
+
const c = 0.75, p = 0.3, b = 0.06, v = ["sad", "surprise"];
|
|
958
|
+
function h(g, A, L = null) {
|
|
959
|
+
return L && g >= p ? L : g >= c ? null : g < p ? A >= 0.5 ? "eyes_smile" : "eyes_closed" : "eyes_half";
|
|
960
|
+
}
|
|
961
|
+
function u(g, A, L = null) {
|
|
962
|
+
if (g < y) return null;
|
|
963
|
+
const B = m(A, L);
|
|
964
|
+
return B === "a" ? g >= 0.6 ? "a" : "aHalf" : B;
|
|
965
|
+
}
|
|
966
|
+
function w(g) {
|
|
967
|
+
return a.cy + (g - a.cx) * Math.tan(a.angle);
|
|
968
|
+
}
|
|
969
|
+
function o() {
|
|
970
|
+
return l.cx;
|
|
971
|
+
}
|
|
972
|
+
function i(g, A) {
|
|
973
|
+
const L = Math.cos(-l.angle), B = Math.sin(-l.angle), j = g - l.cx, k = A - l.cy, U = (j * L - k * B) / l.rx, O = (j * B + k * L) / l.ry;
|
|
974
|
+
return 1 - s(0.55, 0.95, Math.hypot(U, O));
|
|
975
|
+
}
|
|
976
|
+
function S(g, A, L, B, j) {
|
|
977
|
+
const k = {}, U = (I) => I.startsWith("eyes_closed") || I.startsWith("eyes_smile"), O = (I) => d.some((V) => I === `mouth_${V}`), $ = (I) => U(I) ? 1 : I.startsWith("eyes_") ? 0 : O(I) ? 2 : 3, D = Object.entries(A.layers).sort((I, V) => $(I[0]) - $(V[0]));
|
|
978
|
+
for (const [I, V] of D) {
|
|
979
|
+
const K = B(V, e.mesh.spriteCell, j(L[I]), L[I].width), x = [], M = [];
|
|
980
|
+
for (let _ = 0; _ < K.rest.length / 2; _++) {
|
|
981
|
+
const Y = K.rest[_ * 2], X = K.rest[_ * 2 + 1];
|
|
982
|
+
x.push(t(Y, X, 0)), M.push(I.startsWith("mouth") ? i(Y, X) : 0);
|
|
983
983
|
}
|
|
984
|
-
const
|
|
985
|
-
|
|
986
|
-
}
|
|
987
|
-
const
|
|
988
|
-
let
|
|
989
|
-
const
|
|
990
|
-
function W(
|
|
991
|
-
const
|
|
992
|
-
for (let
|
|
993
|
-
let X =
|
|
994
|
-
const
|
|
995
|
-
if (
|
|
996
|
-
const
|
|
997
|
-
|
|
984
|
+
const T = g.addLayer(I, L[I], K, { color: [0.4, 1, 0.8, 0.6] });
|
|
985
|
+
T.visible = !1, k[I] = { mesh: K, W: x, inner: M, layer: T };
|
|
986
|
+
}
|
|
987
|
+
const q = [0, 1].map((I) => !!(k[`eyes_closed_${I}`] && k[`eyes_half_${I}`])), N = Object.values(f).some((I) => k[I.sprite]), P = (I, V) => (I === "eyes_smile" && !k[`eyes_smile_${V}`] && (I = "eyes_closed"), I === "open" || k[`${I}_${V}`] ? I : "open"), H = [0, 0];
|
|
988
|
+
let G = null;
|
|
989
|
+
const z = [0, 1].map(() => ({ cur: "open", prev: "open", t: 1 }));
|
|
990
|
+
function W(I, V, K, x, M = 1) {
|
|
991
|
+
const T = I.mesh.rest, _ = I.mesh.pos;
|
|
992
|
+
for (let Y = 0; Y < I.W.length; Y++) {
|
|
993
|
+
let X = T[Y * 2], F = T[Y * 2 + 1];
|
|
994
|
+
const C = I.inner[Y];
|
|
995
|
+
if (C > 0) {
|
|
996
|
+
const Z = w(X);
|
|
997
|
+
F = Z + (F - Z) * (1 + (x - 1) * C), X = o() + (X - o()) * (1 + (M - 1) * C);
|
|
998
998
|
}
|
|
999
|
-
r(X,
|
|
999
|
+
r(X, F, I.W[Y], V, K, H), _[Y * 2] = H[0], _[Y * 2 + 1] = H[1];
|
|
1000
1000
|
}
|
|
1001
1001
|
}
|
|
1002
1002
|
return {
|
|
@@ -1007,43 +1007,86 @@ function Yn(n, e) {
|
|
|
1007
1007
|
* `mood` (angry / sad / surprise) picks drawn expression eyes (sad, surprise) and closed
|
|
1008
1008
|
* mouths (angry, sad) when the avatar has them.
|
|
1009
1009
|
*/
|
|
1010
|
-
update(
|
|
1011
|
-
for (const
|
|
1010
|
+
update(I, V, K = 1 / 60, x = null) {
|
|
1011
|
+
for (const C of Object.values(k)) C.layer.visible = !1;
|
|
1012
1012
|
const M = [!1, !1];
|
|
1013
1013
|
[
|
|
1014
|
-
[
|
|
1015
|
-
[
|
|
1016
|
-
].forEach(([
|
|
1017
|
-
const
|
|
1018
|
-
te !==
|
|
1019
|
-
const
|
|
1020
|
-
if (
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
},
|
|
1024
|
-
|
|
1014
|
+
[I.eyeROpen, I.eyeSmile],
|
|
1015
|
+
[I.eyeLOpen, I.eyeSmileL ?? I.eyeSmile]
|
|
1016
|
+
].forEach(([C, Z], E) => {
|
|
1017
|
+
const R = z[E], J = v.includes(x) && k[`eyes_${x}_${E}`] ? `eyes_${x}` : null, te = P(h(C, Z, J) ?? "open", E);
|
|
1018
|
+
te !== R.cur && (R.prev = R.cur, R.cur = te, R.t = 0), R.t = K > 0 ? Math.min(1, R.t + K / b) : 1;
|
|
1019
|
+
const ee = s(0, 1, R.t), se = (ce, je) => {
|
|
1020
|
+
if (ce === "open" || je <= 1e-3) return;
|
|
1021
|
+
const _e = k[`${ce}_${E}`];
|
|
1022
|
+
_e && (_e.layer.visible = !0, _e.layer.alpha = je, W(_e, I, V, 1));
|
|
1023
|
+
}, le = (ce) => ce === "open" ? -1 : U(ce) ? 1 : 0;
|
|
1024
|
+
R.t >= 1 ? se(R.cur, 1) : le(R.cur) > le(R.prev) ? (se(R.prev, 1), se(R.cur, ee)) : (se(R.cur, 1), se(R.prev, 1 - ee)), M[E] = R.cur !== "open" && ee >= 0.999;
|
|
1025
1025
|
});
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
const
|
|
1029
|
-
if (
|
|
1030
|
-
X.layer.visible = !0, X.layer.alpha =
|
|
1031
|
-
const
|
|
1032
|
-
W(X,
|
|
1026
|
+
const _ = u(I.mouthOpen, I.mouthForm, G);
|
|
1027
|
+
G = _;
|
|
1028
|
+
const Y = _ && f[_], X = Y && k[Y.sprite], F = d.includes(x) && k[`mouth_${x}`];
|
|
1029
|
+
if (F && (!X || I.mouthOpen < y + 0.04) && (F.layer.visible = !0, F.layer.alpha = 1, W(F, I, V, 1)), X) {
|
|
1030
|
+
X.layer.visible = !0, X.layer.alpha = s(y, y + 0.04, I.mouthOpen);
|
|
1031
|
+
const C = Math.min(1.1, Math.max(0.5, I.mouthOpen / Y.ref));
|
|
1032
|
+
W(X, I, V, C, Y.width);
|
|
1033
1033
|
}
|
|
1034
|
-
return { eyes: M, mouth:
|
|
1034
|
+
return { eyes: M, mouth: _, mouthDrawn: N && (!Y || !!X) };
|
|
1035
1035
|
},
|
|
1036
1036
|
/** Whether each eye has the closed and half-closed drawings, so the layered eye stays open. */
|
|
1037
|
-
eyesDrawn:
|
|
1037
|
+
eyesDrawn: q
|
|
1038
1038
|
};
|
|
1039
1039
|
}
|
|
1040
|
-
return { createSprites:
|
|
1040
|
+
return { createSprites: S, mouthShape: u, eyeSprite: h };
|
|
1041
1041
|
}
|
|
1042
|
-
const
|
|
1042
|
+
const $t = { angry: "angry", angryTalk: "angry", sad: "sad", sadTalk: "sad", surprise: "surprise", surprisedTalk: "surprise" };
|
|
1043
1043
|
function In(n, e) {
|
|
1044
|
-
return n && n !== "neutral" ?
|
|
1044
|
+
return n && n !== "neutral" ? $t[n] ?? null : (e && $t[e]) ?? null;
|
|
1045
|
+
}
|
|
1046
|
+
function Nn(n, e, t, r = 6) {
|
|
1047
|
+
let a = e, s = t, l = -1, f = -1;
|
|
1048
|
+
for (let m = 0; m < t; m++) {
|
|
1049
|
+
const c = m * e;
|
|
1050
|
+
for (let p = 0; p < e; p++)
|
|
1051
|
+
n[c + p] > 3 && (p < a && (a = p), p > l && (l = p), m < s && (s = m), m > f && (f = m));
|
|
1052
|
+
}
|
|
1053
|
+
if (l < 0) return null;
|
|
1054
|
+
const y = Math.max(0, a - r), d = Math.max(0, s - r);
|
|
1055
|
+
return [y, d, Math.min(e, l + 1 + r) - y, Math.min(t, f + 1 + r) - d];
|
|
1056
|
+
}
|
|
1057
|
+
function Xn(n, e, t, r, a, s, l = 16, f, y, d) {
|
|
1058
|
+
const m = /* @__PURE__ */ new Map();
|
|
1059
|
+
for (const c of e.overlays) {
|
|
1060
|
+
const p = t[c.name];
|
|
1061
|
+
if (f !== void 0 && p.width !== f || y !== void 0 && p.height !== y)
|
|
1062
|
+
throw new Error(`overlay ${c.name}: image size does not match base.png`);
|
|
1063
|
+
const b = a(p), v = Nn(b, p.width, p.height);
|
|
1064
|
+
if (!v) continue;
|
|
1065
|
+
const [h, u, w, o] = v, i = new Uint8Array(w * o);
|
|
1066
|
+
for (let L = 0; L < o; L++) i.set(b.subarray((u + L) * p.width + h, (u + L) * p.width + h + w), L * w);
|
|
1067
|
+
const S = r(v, l, i, w), g = [];
|
|
1068
|
+
for (let L = 0; L < S.rest.length; L += 2) {
|
|
1069
|
+
const B = s(S.rest[L], S.rest[L + 1], 0);
|
|
1070
|
+
g.push({ ...B, brow: 0, jaw: 0 });
|
|
1071
|
+
}
|
|
1072
|
+
const A = n.addLayer(`overlay_${c.name}`, d(p, v), S);
|
|
1073
|
+
A.visible = !1, m.set(c.name, { mesh: S, weights: g, layer: A });
|
|
1074
|
+
}
|
|
1075
|
+
return {
|
|
1076
|
+
/** Shows the named overlays and hides the rest. Unknown names are ignored. */
|
|
1077
|
+
set(c) {
|
|
1078
|
+
const p = new Set(c);
|
|
1079
|
+
for (const [b, v] of m) v.layer.visible = p.has(b);
|
|
1080
|
+
},
|
|
1081
|
+
update(c, p, b, v) {
|
|
1082
|
+
for (const { mesh: h, weights: u, layer: w } of m.values())
|
|
1083
|
+
if (w.visible)
|
|
1084
|
+
for (let o = 0; o < u.length; o++)
|
|
1085
|
+
b(h.rest[o * 2], h.rest[o * 2 + 1], u[o], c, p, v), h.pos[o * 2] = v[0], h.pos[o * 2 + 1] = v[1];
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1045
1088
|
}
|
|
1046
|
-
function
|
|
1089
|
+
function St(n) {
|
|
1047
1090
|
if (!n || typeof n != "object" || Array.isArray(n)) throw new TypeError("lipSync: expected an object");
|
|
1048
1091
|
const e = n, t = {};
|
|
1049
1092
|
for (const r of ["granularity", "openness", "closeSpeed"]) {
|
|
@@ -1061,32 +1104,32 @@ function At(n) {
|
|
|
1061
1104
|
}
|
|
1062
1105
|
return t;
|
|
1063
1106
|
}
|
|
1064
|
-
function
|
|
1107
|
+
function zt(n = {}, e = {
|
|
1065
1108
|
granularity: 0.5,
|
|
1066
1109
|
openness: 0.5,
|
|
1067
1110
|
closeSpeed: 0.5
|
|
1068
1111
|
}) {
|
|
1069
|
-
const t =
|
|
1112
|
+
const t = St(n);
|
|
1070
1113
|
return {
|
|
1071
1114
|
granularity: t.granularity ?? e.granularity,
|
|
1072
1115
|
openness: t.openness ?? e.openness,
|
|
1073
1116
|
closeSpeed: t.closeSpeed ?? e.closeSpeed
|
|
1074
1117
|
};
|
|
1075
1118
|
}
|
|
1076
|
-
const
|
|
1077
|
-
function
|
|
1119
|
+
const Ee = (n, e, t, r) => n === 0.5 ? t : n < 0.5 ? e + (t - e) * n * 2 : t + (r - t) * (n - 0.5) * 2;
|
|
1120
|
+
function Ct(n) {
|
|
1078
1121
|
return {
|
|
1079
|
-
arm:
|
|
1080
|
-
trigger:
|
|
1081
|
-
relax:
|
|
1082
|
-
range:
|
|
1083
|
-
risePower:
|
|
1084
|
-
openness:
|
|
1085
|
-
audioRelease:
|
|
1086
|
-
kanaRelease:
|
|
1122
|
+
arm: Ee(n.granularity, 0.2, 0.6, 0.9),
|
|
1123
|
+
trigger: Ee(n.granularity, 0.65, 0.8, 0.95),
|
|
1124
|
+
relax: Ee(n.granularity, 1.5, 5, 12),
|
|
1125
|
+
range: Ee(n.granularity, 0.7, 0.3, 0.05),
|
|
1126
|
+
risePower: Ee(n.granularity, 0.05, 0.3, 0.8),
|
|
1127
|
+
openness: Ee(n.openness, 0.55, 1, 1.25),
|
|
1128
|
+
audioRelease: Ee(n.closeSpeed, 6, 32, 45),
|
|
1129
|
+
kanaRelease: Ee(n.closeSpeed, 6, 22, 45)
|
|
1087
1130
|
};
|
|
1088
1131
|
}
|
|
1089
|
-
const
|
|
1132
|
+
const $n = /* @__PURE__ */ new Set([
|
|
1090
1133
|
"angleX",
|
|
1091
1134
|
"angleY",
|
|
1092
1135
|
"angleZ",
|
|
@@ -1096,7 +1139,7 @@ const Nn = /* @__PURE__ */ new Set([
|
|
|
1096
1139
|
"handAngle",
|
|
1097
1140
|
"gazeX",
|
|
1098
1141
|
"gazeY"
|
|
1099
|
-
]),
|
|
1142
|
+
]), Tt = {
|
|
1100
1143
|
nod: {
|
|
1101
1144
|
label: "Nod",
|
|
1102
1145
|
dur: 1.7,
|
|
@@ -1244,7 +1287,7 @@ const Nn = /* @__PURE__ */ new Set([
|
|
|
1244
1287
|
blush: [[0, 0], [1.6, 0.3], [2.6, 0]]
|
|
1245
1288
|
}
|
|
1246
1289
|
}
|
|
1247
|
-
},
|
|
1290
|
+
}, Ot = {
|
|
1248
1291
|
lookAround: {
|
|
1249
1292
|
label: "Look around",
|
|
1250
1293
|
dur: 5.2,
|
|
@@ -1484,16 +1527,16 @@ const Nn = /* @__PURE__ */ new Set([
|
|
|
1484
1527
|
}
|
|
1485
1528
|
}
|
|
1486
1529
|
};
|
|
1487
|
-
function
|
|
1530
|
+
function zn(n, e) {
|
|
1488
1531
|
if (e <= n[0][0]) return n[0][1];
|
|
1489
1532
|
const t = n.length - 1;
|
|
1490
1533
|
if (e >= n[t][0]) return n[t][1];
|
|
1491
1534
|
let r = 0;
|
|
1492
1535
|
for (; e > n[r + 1][0]; ) r++;
|
|
1493
|
-
const [a,
|
|
1494
|
-
return (2 *
|
|
1536
|
+
const [a, s] = n[r], [l, f] = n[r + 1], y = (h) => h <= 0 || h >= t ? 0 : (n[h + 1][1] - n[h - 1][1]) / (n[h + 1][0] - n[h - 1][0]), d = l - a, m = (e - a) / d, c = y(r) * d, p = y(r + 1) * d, b = m * m, v = b * m;
|
|
1537
|
+
return (2 * v - 3 * b + 1) * s + (v - 2 * b + m) * c + (-2 * v + 3 * b) * f + (v - b) * p;
|
|
1495
1538
|
}
|
|
1496
|
-
const
|
|
1539
|
+
const Pe = {
|
|
1497
1540
|
a: { open: 0.9, form: 0, label: "あ" },
|
|
1498
1541
|
i: { open: 0.5, form: -0.85, label: "い" },
|
|
1499
1542
|
u: { open: 0.4, form: 0.9, label: "う" },
|
|
@@ -1501,21 +1544,21 @@ const ze = {
|
|
|
1501
1544
|
o: { open: 0.75, form: 0.6, label: "お" },
|
|
1502
1545
|
n: { open: 0, form: null, label: "ん" }
|
|
1503
1546
|
// closes with the previous shape
|
|
1504
|
-
},
|
|
1547
|
+
}, Cn = {
|
|
1505
1548
|
a: "あかさたなはまやらわがざだばぱぁ",
|
|
1506
1549
|
i: "いきしちにひみりぎじぢびぴぃ",
|
|
1507
1550
|
u: "うくすつぬふむゆるぐずづぶぷぅゔ",
|
|
1508
1551
|
e: "えけせてねへめれげぜでべぺぇ",
|
|
1509
1552
|
o: "おこそとのほもよろをごぞどぼぽぉ"
|
|
1510
|
-
},
|
|
1511
|
-
for (const [n, e] of Object.entries(
|
|
1512
|
-
const
|
|
1513
|
-
function
|
|
1553
|
+
}, tn = {};
|
|
1554
|
+
for (const [n, e] of Object.entries(Cn)) for (const t of e) tn[t] = n;
|
|
1555
|
+
const Pn = /* @__PURE__ */ new Set([..."まみむめもばびぶべぼぱぴぷぺぽ"]), Dn = /* @__PURE__ */ new Set([..."あいうえおぁぃぅぇぉ"]), Pt = { ゃ: "a", ゅ: "u", ょ: "o" }, Hn = /* @__PURE__ */ new Set([..."、。,.,.!?!? …"]), Zn = (n) => n.replace(/[ァ-ヶ]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 96));
|
|
1556
|
+
function Wn(n, e = 0.14) {
|
|
1514
1557
|
const t = [];
|
|
1515
|
-
for (const r of
|
|
1558
|
+
for (const r of Zn(n)) {
|
|
1516
1559
|
const a = t[t.length - 1];
|
|
1517
|
-
if (
|
|
1518
|
-
a.vowel =
|
|
1560
|
+
if (Pt[r] && a) {
|
|
1561
|
+
a.vowel = Pt[r];
|
|
1519
1562
|
continue;
|
|
1520
1563
|
}
|
|
1521
1564
|
if (r === "ー" && a) {
|
|
@@ -1530,41 +1573,41 @@ function Dn(n, e = 0.14) {
|
|
|
1530
1573
|
t.push({ vowel: "n", dur: e, onset: null });
|
|
1531
1574
|
continue;
|
|
1532
1575
|
}
|
|
1533
|
-
if (
|
|
1576
|
+
if (Hn.has(r)) {
|
|
1534
1577
|
t.push({ vowel: "n", dur: e * 2.2, onset: null });
|
|
1535
1578
|
continue;
|
|
1536
1579
|
}
|
|
1537
|
-
const
|
|
1538
|
-
|
|
1580
|
+
const s = tn[r];
|
|
1581
|
+
s && t.push({ vowel: s, dur: e, onset: Pn.has(r) ? "lips" : Dn.has(r) ? null : "consonant" });
|
|
1539
1582
|
}
|
|
1540
1583
|
return t;
|
|
1541
1584
|
}
|
|
1542
|
-
function
|
|
1543
|
-
if (t !== 0.5) return
|
|
1585
|
+
function Gn(n, e, t = 0.5) {
|
|
1586
|
+
if (t !== 0.5) return Vn(n, e, t);
|
|
1544
1587
|
let r = 0;
|
|
1545
1588
|
for (const a of n) {
|
|
1546
1589
|
if (e < r + a.dur) {
|
|
1547
|
-
const
|
|
1548
|
-
return { open:
|
|
1590
|
+
const s = (e - r) / a.dur, l = Pe[a.vowel], f = a.onset === "lips" ? 0.05 : a.onset === "consonant" ? 0.45 : 1, y = s < 0.35 ? f + (1 - f) * (s / 0.35) : 1;
|
|
1591
|
+
return { open: l.open * y, form: l.form, vowel: a.vowel };
|
|
1549
1592
|
}
|
|
1550
1593
|
r += a.dur;
|
|
1551
1594
|
}
|
|
1552
1595
|
return null;
|
|
1553
1596
|
}
|
|
1554
|
-
function
|
|
1597
|
+
function Vn(n, e, t) {
|
|
1555
1598
|
const r = t < 0.5 ? (0.5 - t) * 0.72 : 0;
|
|
1556
|
-
let a = 0,
|
|
1599
|
+
let a = 0, s = 0, l = null;
|
|
1557
1600
|
for (const f of n) {
|
|
1558
|
-
let
|
|
1559
|
-
if (f.vowel === "n" ? r && f.dur <= 0.2 &&
|
|
1560
|
-
const
|
|
1561
|
-
return { open:
|
|
1601
|
+
let y = f.vowel;
|
|
1602
|
+
if (f.vowel === "n" ? r && f.dur <= 0.2 && l ? y = l : (s = 0, l = null) : ((!l || s >= r) && (l = f.vowel, s = 0), s += f.dur, r && (y = l)), e < a + f.dur) {
|
|
1603
|
+
const d = Pe[y], m = f.onset === "lips" ? 0.05 : f.onset === "consonant" ? 0.45 : 1, c = t < 0.5 ? 1 - (1 - m) * t * 2 : m * (2 - t * 2), p = Math.min(f.dur * 0.35, 0.05), b = (e - a) / p;
|
|
1604
|
+
return { open: d.open * (b < 1 ? c + (1 - c) * b : 1), form: d.form, vowel: y };
|
|
1562
1605
|
}
|
|
1563
1606
|
a += f.dur;
|
|
1564
1607
|
}
|
|
1565
1608
|
return null;
|
|
1566
1609
|
}
|
|
1567
|
-
const
|
|
1610
|
+
const at = { ...Tt, ...Ot }, Dt = { amp: 1, stiff: 1.8 }, qn = /^(angle|bodyAngle|armAngle|handAngle)/, Jn = /* @__PURE__ */ new Set([
|
|
1568
1611
|
"eyeOpen",
|
|
1569
1612
|
"eyeOpenL",
|
|
1570
1613
|
"eyeSmileL",
|
|
@@ -1574,18 +1617,18 @@ const nt = { ...Mt, ...Et }, Ct = { amp: 1, stiff: 1.8 }, Wn = /^(angle|bodyAngl
|
|
|
1574
1617
|
"blush",
|
|
1575
1618
|
"browY",
|
|
1576
1619
|
"browAngle"
|
|
1577
|
-
]),
|
|
1620
|
+
]), qe = (n, e, t) => {
|
|
1578
1621
|
const r = Math.min(1, Math.max(0, (t - n) / (e - n)));
|
|
1579
1622
|
return r * r * (3 - 2 * r);
|
|
1580
1623
|
};
|
|
1581
|
-
function
|
|
1582
|
-
const t = Math.floor(n), r = n - t, a = (
|
|
1583
|
-
const f = Math.sin((
|
|
1624
|
+
function Ht(n, e) {
|
|
1625
|
+
const t = Math.floor(n), r = n - t, a = (l) => {
|
|
1626
|
+
const f = Math.sin((l + e * 57.3) * 127.1) * 43758.5453;
|
|
1584
1627
|
return f - Math.floor(f);
|
|
1585
|
-
},
|
|
1586
|
-
return (a(t) * (1 -
|
|
1628
|
+
}, s = r * r * (3 - 2 * r);
|
|
1629
|
+
return (a(t) * (1 - s) + a(t + 1) * s) * 2 - 1;
|
|
1587
1630
|
}
|
|
1588
|
-
const
|
|
1631
|
+
const Ae = (n, e) => Ht(n, e) * 0.7 + Ht(n * 2.3, e + 9) * 0.3, pe = (n, e, t) => Math.max(e, Math.min(t, n)), nn = {
|
|
1589
1632
|
normal: { label: "Neutral", p: {} },
|
|
1590
1633
|
smile: { label: "Smile", p: { eyeOpen: 0, eyeSmile: 1, blush: 0.35, browY: 0.2 } },
|
|
1591
1634
|
shy: { label: "Blush", p: { eyeOpen: 0.78, eyeSmile: 0.5, blush: 1, browAngle: -0.5, browY: -0.1, glance: [0.7, 0.35] } },
|
|
@@ -1599,14 +1642,14 @@ const Me = (n, e) => zt(n, e) * 0.7 + zt(n * 2.3, e + 9) * 0.3, pe = (n, e, t) =
|
|
|
1599
1642
|
angryTalk: { label: "angry", p: { eyeOpen: 0.72, browAngle: 0.85, browY: -0.55, mouthForm: 0.2 } },
|
|
1600
1643
|
surprisedTalk: { label: "surprised", p: { eyeOpen: 1.18, browY: 0.9, mouthForm: 0.9 } },
|
|
1601
1644
|
relaxedTalk: { label: "relaxed", p: { eyeOpen: 0.82, eyeSmile: 0.35, blush: 0.15, browY: 0.1 } }
|
|
1602
|
-
},
|
|
1645
|
+
}, Zt = {
|
|
1603
1646
|
happy: ["happyTalk", "nod"],
|
|
1604
1647
|
sad: ["sadTalk", "sigh"],
|
|
1605
1648
|
angry: ["angryTalk", "no"],
|
|
1606
1649
|
surprised: ["surprisedTalk", "surprise"],
|
|
1607
1650
|
relaxed: ["relaxedTalk", "sway"],
|
|
1608
1651
|
neutral: ["normal", null]
|
|
1609
|
-
},
|
|
1652
|
+
}, Kn = {
|
|
1610
1653
|
gazeX: [260, 0.9],
|
|
1611
1654
|
gazeY: [260, 0.9],
|
|
1612
1655
|
angleX: [55, 0.72],
|
|
@@ -1617,41 +1660,41 @@ const Me = (n, e) => zt(n, e) * 0.7 + zt(n * 2.3, e + 9) * 0.3, pe = (n, e, t) =
|
|
|
1617
1660
|
armAngle: [20, 0.85],
|
|
1618
1661
|
handAngle: [30, 0.8]
|
|
1619
1662
|
};
|
|
1620
|
-
class
|
|
1663
|
+
class Qn {
|
|
1621
1664
|
/** @param {number[]} gazeCenter */
|
|
1622
1665
|
constructor(e) {
|
|
1623
|
-
this.mode = "auto", this.P = Object.fromEntries(
|
|
1666
|
+
this.mode = "auto", this.P = Object.fromEntries(Ge.map((t) => [t.id, t.def])), this.manual = { ...this.P }, this.cur = { ...this.P }, this.vel = Object.fromEntries(Ge.map((t) => [t.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 = [...e], this.lipOpen = null, this.lipForm = 0, this.speaking = !1, this.voice = 0, this.mouth = 0, this.vowel = "a", this.vowelForm = 0, this.lipSync = zt(), this.lipMotion = Ct(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;
|
|
1624
1667
|
}
|
|
1625
1668
|
setExpression(e) {
|
|
1626
1669
|
this.expr = e;
|
|
1627
1670
|
}
|
|
1628
1671
|
hasMotion(e) {
|
|
1629
|
-
return e in
|
|
1672
|
+
return e in at;
|
|
1630
1673
|
}
|
|
1631
1674
|
// ---- speech (driven from outside, e.g. by the TTS audio analyser) ----
|
|
1632
1675
|
setVoiceLevel(e) {
|
|
1633
1676
|
this.voice = Math.min(1, Math.max(0, Number(e) || 0));
|
|
1634
1677
|
}
|
|
1635
1678
|
setLipSync(e) {
|
|
1636
|
-
this.lipSync =
|
|
1679
|
+
this.lipSync = zt(e, this.lipSync), this.lipMotion = Ct(this.lipSync);
|
|
1637
1680
|
}
|
|
1638
1681
|
setSpeaking(e) {
|
|
1639
1682
|
e !== this.speaking && (this.speaking = !!e, e || (this.emotionUntil = this.t + 1.2, this.voice = 0));
|
|
1640
1683
|
}
|
|
1641
1684
|
/** `playMotion: false` changes only the face (a caller that picks motions itself). */
|
|
1642
1685
|
setEmotion(e, { playMotion: t = !0 } = {}) {
|
|
1643
|
-
const r =
|
|
1686
|
+
const r = Zt[e] ?? Zt.neutral;
|
|
1644
1687
|
this.expr = r[0], this.emotionUntil = 1 / 0, r[1] && t && this.playMotion(r[1]);
|
|
1645
1688
|
}
|
|
1646
1689
|
/** Mouth shapes from kana text, without audio (preview / tuning). */
|
|
1647
1690
|
/** @param {string} text @param {{ speed?: number, loop?: boolean }} [options] */
|
|
1648
1691
|
speakKana(e, { speed: t, loop: r = !1 } = {}) {
|
|
1649
1692
|
this.lipHold = null;
|
|
1650
|
-
const a =
|
|
1651
|
-
this.kana = a.length ? { moras: a, t: 0, loop: r, duration: a.reduce((
|
|
1693
|
+
const a = Wn(e, t === void 0 ? 0.14 : 1 / pe(Number(t) || 7, 4, 12));
|
|
1694
|
+
this.kana = a.length ? { moras: a, t: 0, loop: r, duration: a.reduce((s, l) => s + l.dur, 0) } : null;
|
|
1652
1695
|
}
|
|
1653
1696
|
holdMouth(e) {
|
|
1654
|
-
this.kana = null, this.lipHold = Object.hasOwn(
|
|
1697
|
+
this.kana = null, this.lipHold = Object.hasOwn(Pe, e) ? e : null;
|
|
1655
1698
|
}
|
|
1656
1699
|
stopLipSync() {
|
|
1657
1700
|
this.kana = null, this.lipHold = null, this.lipOpen = null, this.mouth = 0;
|
|
@@ -1667,11 +1710,11 @@ class qn {
|
|
|
1667
1710
|
// the dip before each mora even when a loud voice never gets quiet.
|
|
1668
1711
|
speechMouth(e) {
|
|
1669
1712
|
if (this.kana || this.lipHold) {
|
|
1670
|
-
let
|
|
1671
|
-
if (this.lipHold ?
|
|
1713
|
+
let p;
|
|
1714
|
+
if (this.lipHold ? p = Pe[this.lipHold] : (this.kana.t += e, this.kana.loop && (this.kana.t %= this.kana.duration), p = Gn(this.kana.moras, this.kana.t, this.lipSync.granularity)), !p)
|
|
1672
1715
|
return this.kana = null, this.mouth > 0.01 ? [this.mouth *= this.lipSync.closeSpeed === 0.5 ? 0.6 : Math.exp(-e * this.lipMotion.kanaRelease), this.vowelForm] : null;
|
|
1673
|
-
const
|
|
1674
|
-
return this.mouth += (
|
|
1716
|
+
const b = this.lipMotion.openness === 1 ? p.open : Math.min(1, p.open * this.lipMotion.openness), v = b > this.mouth ? 1 - Math.exp(-e * 30) : 1 - Math.exp(-e * this.lipMotion.kanaRelease);
|
|
1717
|
+
return this.mouth += (b - this.mouth) * v, p.form !== null && (this.vowelForm = p.form), [this.mouth, this.vowelForm];
|
|
1675
1718
|
}
|
|
1676
1719
|
const t = this.speaking ? this.voice : 0, r = 1 - Math.exp(-e * this.lipMotion.relax);
|
|
1677
1720
|
this.voicePeak = t > this.voicePeak ? t : this.voicePeak + (t - this.voicePeak) * r, this.voiceTrough = t < this.voiceTrough ? t : this.voiceTrough + (t - this.voiceTrough) * r;
|
|
@@ -1679,18 +1722,18 @@ class qn {
|
|
|
1679
1722
|
if (t < a * this.lipMotion.arm) this.syllableArmed = !0;
|
|
1680
1723
|
else if (this.syllableArmed && t > a * this.lipMotion.trigger && t > 0.1) {
|
|
1681
1724
|
this.syllableArmed = !1;
|
|
1682
|
-
const
|
|
1683
|
-
this.vowel =
|
|
1725
|
+
const p = Math.random();
|
|
1726
|
+
this.vowel = p < 0.4 ? "a" : p < 0.58 ? "o" : p < 0.74 ? "e" : p < 0.88 ? "i" : "u";
|
|
1684
1727
|
}
|
|
1685
|
-
const
|
|
1686
|
-
return this.mouth += (
|
|
1728
|
+
const s = this.voicePeak - this.voiceTrough, l = s < a * this.lipMotion.range ? 1 : Math.max(0, (t - this.voiceTrough) / s), f = Pe[this.vowel ?? "a"], y = Math.min(1, Math.pow(t, 0.7) * 1.15) * Math.pow(l, this.lipMotion.risePower), d = this.speaking ? Math.min(0.95, y) * (0.45 + 0.55 * f.open / 0.9) : 0, m = this.lipMotion.openness === 1 ? d : Math.min(1, d * this.lipMotion.openness), c = m > this.mouth ? 1 - Math.exp(-e * 40) : 1 - Math.exp(-e * this.lipMotion.audioRelease);
|
|
1729
|
+
return this.mouth += (m - this.mouth) * c, this.speaking && (this.vowelForm = f.form), this.speaking || this.mouth > 0.01 ? [this.mouth, this.vowelForm] : null;
|
|
1687
1730
|
}
|
|
1688
1731
|
// Breathing: inhale ~40% of the cycle, a slower exhale, a short pause at the bottom,
|
|
1689
1732
|
// and a period that drifts between ~3.2 and 4.6 s so it never looks metronomic.
|
|
1690
1733
|
breathValue(e) {
|
|
1691
1734
|
this.breathPhase = (this.breathPhase ?? 0) + e / (this.breathPeriod ?? 3.8), this.breathPhase >= 1 && (this.breathPhase -= 1, this.breathPeriod = 3.2 + Math.random() * 1.4);
|
|
1692
1735
|
const t = this.breathPhase;
|
|
1693
|
-
return t < 0.4 ?
|
|
1736
|
+
return t < 0.4 ? qe(0, 0.4, t) : t < 0.88 ? 1 - qe(0.4, 0.88, t) : 0;
|
|
1694
1737
|
}
|
|
1695
1738
|
// pick one at random, never the one that just played
|
|
1696
1739
|
playRandom(e) {
|
|
@@ -1709,81 +1752,81 @@ class qn {
|
|
|
1709
1752
|
update(e) {
|
|
1710
1753
|
this.t += e;
|
|
1711
1754
|
const t = this.t, r = {};
|
|
1712
|
-
for (const
|
|
1755
|
+
for (const v of Ge) r[v.id] = v.def;
|
|
1713
1756
|
if (this.mode === "manual")
|
|
1714
1757
|
Object.assign(r, this.manual);
|
|
1715
1758
|
else if (this.mode === "auto") {
|
|
1716
|
-
if (r.angleX =
|
|
1717
|
-
const
|
|
1718
|
-
this.gaze.x =
|
|
1759
|
+
if (r.angleX = Ae(t * 0.18, 1) * 10 + this.gaze.x * 11, r.angleY = Ae(t * 0.15, 2) * 6 - 1 + this.gaze.y * 7, r.angleZ = Ae(t * 0.12, 3) * 10, r.bodyAngleX = Ae(t * 0.1, 4) * 5, r.bodyAngleZ = Ae(t * 0.09, 5) * 4, r.armAngle = Ae(t * 0.14, 6) * 5, r.handAngle = Ae(t * 0.21, 7) * 5, t > this.gaze.next) {
|
|
1760
|
+
const v = Math.random();
|
|
1761
|
+
this.gaze.x = v < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.8, this.gaze.y = v < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.5, this.gaze.next = t + 0.8 + Math.random() * 2.5;
|
|
1719
1762
|
}
|
|
1720
1763
|
if (r.gazeX = this.gaze.x + r.angleX / 60, r.gazeY = this.gaze.y + r.angleY / 60, t > this.tap.next && (this.tap.until = t + 1.1, this.tap.next = t + 5 + Math.random() * 6), this.speaking) {
|
|
1721
1764
|
this.nextIdle = Math.max(this.nextIdle, t + 2.5), this.nextAuto = Math.max(this.nextAuto, t + 6);
|
|
1722
|
-
const
|
|
1723
|
-
this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 *
|
|
1765
|
+
const v = this.talkGain;
|
|
1766
|
+
this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 * v - (this.talkNod ?? 0)) * Math.min(1, e * 6), r.angleY -= this.talkNod, r.angleX += Ae(t * 0.6, 11) * 5 * v, r.angleZ += Ae(t * 0.5, 12) * 4 * v;
|
|
1724
1767
|
}
|
|
1725
|
-
!this.speaking && t > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && t > this.nextAuto ? (this.playRandom(Object.keys(
|
|
1768
|
+
!this.speaking && t > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && t > this.nextAuto ? (this.playRandom(Object.keys(Tt).filter((v) => v !== "surprise")), this.nextAuto = t + 15 + Math.random() * 10, this.nextIdle = Math.max(this.nextIdle, t + 5)) : !this.play && this.autoIdle && t > this.nextIdle && (this.playRandom(Object.keys(Ot)), this.nextIdle = t + 5 + Math.random() * 5));
|
|
1726
1769
|
} else if (this.mode === "mouse" && this.pointer) {
|
|
1727
|
-
const
|
|
1728
|
-
r.angleX = pe(
|
|
1770
|
+
const v = (this.pointer[0] - this.faceCenter[0]) / 500, h = (this.pointer[1] - this.faceCenter[1]) / 500;
|
|
1771
|
+
r.angleX = pe(v * 30, -30, 30), r.angleY = pe(-h * 30, -30, 30), r.angleZ = pe(-v * h * 25, -12, 12), r.bodyAngleX = pe(v * 10, -10, 10) * 0.6, r.gazeX = pe(v * 1.4, -1, 1), r.gazeY = pe(-h * 1.4, -1, 1), r.handAngle = pe(v * 4, -5, 5);
|
|
1729
1772
|
}
|
|
1730
1773
|
this.mode !== "manual" && (r.breath = this.breathValue(e), t < this.tap.until && (r.fingerTap = Math.max(0, Math.sin((this.tap.until - t) * Math.PI * 3.6)) ** 2));
|
|
1731
|
-
let a = null,
|
|
1774
|
+
let a = null, s = 0;
|
|
1732
1775
|
if (this.play) {
|
|
1733
|
-
const
|
|
1734
|
-
if (this.play.t += e, this.play.t >=
|
|
1776
|
+
const v = at[this.play.id];
|
|
1777
|
+
if (this.play.t += e, this.play.t >= v.dur)
|
|
1735
1778
|
this.play = null, this.onMotion?.(null);
|
|
1736
1779
|
else {
|
|
1737
1780
|
a = {};
|
|
1738
|
-
for (const [
|
|
1739
|
-
a[
|
|
1740
|
-
|
|
1741
|
-
for (const [
|
|
1742
|
-
|
|
1781
|
+
for (const [h, u] of Object.entries(v.tracks))
|
|
1782
|
+
a[h] = zn(u, this.play.t) * (v.idle && qn.test(h) ? Dt.amp : 1);
|
|
1783
|
+
s = qe(0, 0.15, this.play.t) * (1 - qe(v.dur - 0.25, v.dur, this.play.t));
|
|
1784
|
+
for (const [h, u] of Object.entries(a))
|
|
1785
|
+
$n.has(h) ? r[h] += u : h === "breath" ? r[h] += (u - r[h]) * s : Jn.has(h) || (r[h] = Math.max(r[h], Math.max(0, u)));
|
|
1743
1786
|
}
|
|
1744
1787
|
}
|
|
1745
1788
|
this.mode !== "manual" && (r.angleY += r.breath * 1.6);
|
|
1746
|
-
const
|
|
1747
|
-
eyeOpen:
|
|
1748
|
-
eyeOpenL:
|
|
1749
|
-
eyeSmileL:
|
|
1750
|
-
eyeSmile:
|
|
1751
|
-
mouthOpen:
|
|
1752
|
-
mouthForm:
|
|
1753
|
-
blush:
|
|
1754
|
-
browY:
|
|
1755
|
-
browAngle:
|
|
1756
|
-
gx:
|
|
1757
|
-
gy:
|
|
1758
|
-
},
|
|
1759
|
-
for (const
|
|
1760
|
-
this.exprMix[
|
|
1761
|
-
const
|
|
1762
|
-
for (const
|
|
1763
|
-
const
|
|
1789
|
+
const l = nn[this.expr].p, f = ["eyeOpen", "eyeOpenL", "eyeSmileL", "eyeSmile", "mouthOpen", "mouthForm", "blush", "browY", "browAngle", "gx", "gy"], y = {
|
|
1790
|
+
eyeOpen: l.eyeOpen ?? 1,
|
|
1791
|
+
eyeOpenL: l.eyeOpenL ?? l.eyeOpen ?? 1,
|
|
1792
|
+
eyeSmileL: l.eyeSmileL ?? l.eyeSmile ?? 0,
|
|
1793
|
+
eyeSmile: l.eyeSmile ?? 0,
|
|
1794
|
+
mouthOpen: l.mouthOpen ?? 0,
|
|
1795
|
+
mouthForm: l.mouthForm ?? 0,
|
|
1796
|
+
blush: l.blush ?? 0,
|
|
1797
|
+
browY: l.browY ?? 0,
|
|
1798
|
+
browAngle: l.browAngle ?? 0,
|
|
1799
|
+
gx: l.glance?.[0] ?? 0,
|
|
1800
|
+
gy: l.glance?.[1] ?? 0
|
|
1801
|
+
}, d = 1 - Math.exp(-e * 9);
|
|
1802
|
+
for (const v of f)
|
|
1803
|
+
this.exprMix[v] === void 0 && (this.exprMix[v] = y[v]), this.exprMix[v] += (y[v] - this.exprMix[v]) * d;
|
|
1804
|
+
const m = this.exprMix, c = {};
|
|
1805
|
+
for (const v of Ge) {
|
|
1806
|
+
const h = v.id;
|
|
1764
1807
|
if (this.mode === "manual" && !a) {
|
|
1765
|
-
|
|
1808
|
+
c[h] = r[h], this.cur[h] = r[h], this.vel[h] = 0;
|
|
1766
1809
|
continue;
|
|
1767
1810
|
}
|
|
1768
|
-
let [
|
|
1769
|
-
a && /^angle|^body/.test(
|
|
1770
|
-
const
|
|
1771
|
-
this.vel[
|
|
1772
|
-
}
|
|
1773
|
-
let
|
|
1774
|
-
if (this.mode !== "manual" ? (
|
|
1775
|
-
const
|
|
1776
|
-
|
|
1777
|
-
},
|
|
1778
|
-
"eyeOpen" in a && (
|
|
1779
|
-
for (const
|
|
1780
|
-
|
|
1781
|
-
}
|
|
1782
|
-
const
|
|
1783
|
-
return
|
|
1811
|
+
let [u, w] = Kn[h] ?? [120, 0.95];
|
|
1812
|
+
a && /^angle|^body/.test(h) && (at[this.play?.id ?? ""]?.idle ? (u *= Dt.stiff, w = 0.8) : /^angle/.test(h) && (u *= 4.5, w = 0.75));
|
|
1813
|
+
const o = 2 * Math.sqrt(u) * w;
|
|
1814
|
+
this.vel[h] += (u * (r[h] - this.cur[h]) - o * this.vel[h]) * e, this.cur[h] += this.vel[h] * e, c[h] = this.cur[h];
|
|
1815
|
+
}
|
|
1816
|
+
let p = 1;
|
|
1817
|
+
if (this.mode !== "manual" ? (p = this.blinkValue(e), c.eyeROpen = m.eyeOpen * p, c.eyeLOpen = m.eyeOpenL * p, c.eyeSmile = m.eyeSmile, c.eyeSmileL = m.eyeSmileL, c.mouthOpen = m.mouthOpen, c.mouthForm = m.mouthForm, c.blush = m.blush, c.browY = m.browY + (c.angleY > 0 ? c.angleY / 60 : 0) - (1 - p) * 0.18, c.browAngle = m.browAngle, c.gazeX = pe(c.gazeX + m.gx, -1, 1), c.gazeY = pe(c.gazeY + m.gy, -1, 1)) : c.eyeSmileL = c.eyeSmile, a) {
|
|
1818
|
+
const v = (u, w) => {
|
|
1819
|
+
c[u] += (w - c[u]) * s;
|
|
1820
|
+
}, h = (u) => Math.min(1.3, Math.max(0, u));
|
|
1821
|
+
"eyeOpen" in a && (v("eyeROpen", h(a.eyeOpen) * p), "eyeOpenL" in a || v("eyeLOpen", h(a.eyeOpen) * p)), "eyeOpenL" in a && v("eyeLOpen", h(a.eyeOpenL) * p), "eyeSmile" in a && (v("eyeSmile", a.eyeSmile), "eyeSmileL" in a || v("eyeSmileL", a.eyeSmile)), "eyeSmileL" in a && v("eyeSmileL", a.eyeSmileL);
|
|
1822
|
+
for (const u of ["mouthOpen", "mouthForm", "blush", "browY", "browAngle"])
|
|
1823
|
+
u in a && v(u, u === "mouthOpen" || u === "blush" ? Math.max(0, a[u]) : a[u]);
|
|
1824
|
+
}
|
|
1825
|
+
const b = this.speechMouth(e);
|
|
1826
|
+
return b ? (this.lipOpen = b[0], this.lipForm = b[1]) : this.lipOpen !== null && !this.speaking && !this.kana && (this.lipOpen = null), this.lipOpen !== null && (c.mouthOpen = Math.max(c.mouthOpen * 0.3, this.lipOpen), c.mouthForm = pe(this.lipForm, -1, 1)), this.P = c, c;
|
|
1784
1827
|
}
|
|
1785
1828
|
}
|
|
1786
|
-
const
|
|
1829
|
+
const Rt = {
|
|
1787
1830
|
neutral: "normal",
|
|
1788
1831
|
smile: "smile",
|
|
1789
1832
|
shy: "shy",
|
|
@@ -1792,9 +1835,9 @@ const St = {
|
|
|
1792
1835
|
angry: "angryTalk",
|
|
1793
1836
|
sad: "sadTalk",
|
|
1794
1837
|
wink: "wink"
|
|
1795
|
-
},
|
|
1796
|
-
function
|
|
1797
|
-
const e =
|
|
1838
|
+
}, er = { sad: { pitch: -6, gy: -0.45 } }, Ne = (n, e, t) => Math.max(e, Math.min(t, n)), Xe = Object.freeze({ eyeOpen: 1, eyeOpenL: 1, eyeSmile: 0, eyeSmileL: 0, blush: 0, browY: 0, browAngle: 0, mouthOpen: 0, gx: 0, gy: 0, pitch: 0 });
|
|
1839
|
+
function tr(n) {
|
|
1840
|
+
const e = nn[Rt[n]]?.p ?? {}, t = er[n] ?? {};
|
|
1798
1841
|
return {
|
|
1799
1842
|
eyeOpen: e.eyeOpen ?? 1,
|
|
1800
1843
|
eyeOpenL: e.eyeOpenL ?? e.eyeOpen ?? 1,
|
|
@@ -1809,170 +1852,182 @@ function Kn(n) {
|
|
|
1809
1852
|
pitch: t.pitch ?? 0
|
|
1810
1853
|
};
|
|
1811
1854
|
}
|
|
1812
|
-
function
|
|
1855
|
+
function nr(n, e) {
|
|
1813
1856
|
const t = { ...n };
|
|
1814
|
-
return t.eyeROpen = (n.eyeROpen ?? 1) * e.eyeOpen, t.eyeLOpen = (n.eyeLOpen ?? 1) * e.eyeOpenL, t.eyeSmile = Math.max(n.eyeSmile ?? 0, e.eyeSmile), t.eyeSmileL = Math.max(n.eyeSmileL ?? n.eyeSmile ?? 0, e.eyeSmileL), t.blush = Math.max(n.blush ?? 0, e.blush), t.browY =
|
|
1857
|
+
return t.eyeROpen = (n.eyeROpen ?? 1) * e.eyeOpen, t.eyeLOpen = (n.eyeLOpen ?? 1) * e.eyeOpenL, t.eyeSmile = Math.max(n.eyeSmile ?? 0, e.eyeSmile), t.eyeSmileL = Math.max(n.eyeSmileL ?? n.eyeSmile ?? 0, e.eyeSmileL), t.blush = Math.max(n.blush ?? 0, e.blush), t.browY = Ne((n.browY ?? 0) + e.browY, -1, 1), t.browAngle = Ne((n.browAngle ?? 0) + e.browAngle, -1, 1), t.mouthOpen = Math.max(n.mouthOpen ?? 0, e.mouthOpen), t.gazeX = Ne((n.gazeX ?? 0) + e.gx, -1, 1), t.gazeY = Ne((n.gazeY ?? 0) + e.gy, -1, 1), t.angleY = Ne((n.angleY ?? 0) + e.pitch, -30, 30), t;
|
|
1815
1858
|
}
|
|
1816
|
-
class
|
|
1859
|
+
class rr {
|
|
1817
1860
|
/** @type {keyof typeof OVERLAY_EXPRESSIONS} */
|
|
1818
1861
|
name = "neutral";
|
|
1819
|
-
mix = { ...
|
|
1862
|
+
mix = { ...Xe };
|
|
1820
1863
|
/** @param {string} name */
|
|
1821
1864
|
set(e) {
|
|
1822
|
-
this.name = Object.hasOwn(
|
|
1865
|
+
this.name = Object.hasOwn(Rt, e) ? (
|
|
1823
1866
|
/** @type {keyof typeof OVERLAY_EXPRESSIONS} */
|
|
1824
1867
|
e
|
|
1825
1868
|
) : "neutral";
|
|
1826
1869
|
}
|
|
1827
1870
|
/** True while an expression is shown or still fading out. */
|
|
1828
1871
|
get active() {
|
|
1829
|
-
return this.name !== "neutral" || Object.keys(
|
|
1872
|
+
return this.name !== "neutral" || Object.keys(Xe).some((e) => Math.abs(this.mix[e] - Xe[e]) > 1e-3);
|
|
1830
1873
|
}
|
|
1831
1874
|
apply(e, t) {
|
|
1832
1875
|
if (!this.active)
|
|
1833
|
-
return this.mix = { ...
|
|
1834
|
-
const r =
|
|
1835
|
-
for (const
|
|
1836
|
-
return
|
|
1876
|
+
return this.mix = { ...Xe }, e;
|
|
1877
|
+
const r = tr(this.name), a = 1 - Math.exp(-Math.max(0, t) * 12);
|
|
1878
|
+
for (const s of Object.keys(Xe)) this.mix[s] += (r[s] - this.mix[s]) * a;
|
|
1879
|
+
return nr(e, this.mix);
|
|
1837
1880
|
}
|
|
1838
1881
|
}
|
|
1839
|
-
const
|
|
1840
|
-
async function
|
|
1841
|
-
return
|
|
1882
|
+
const Wt = ["ball", "low", "crease", "lash"], ot = /* @__PURE__ */ new Map(), st = /* @__PURE__ */ new Map();
|
|
1883
|
+
async function it(n) {
|
|
1884
|
+
return st.has(n) || st.set(n, fetch(n).then((e) => {
|
|
1842
1885
|
if (!e.ok) throw new Error(`failed to load ${n}`);
|
|
1843
1886
|
return e.json();
|
|
1844
|
-
})),
|
|
1887
|
+
})), st.get(n);
|
|
1845
1888
|
}
|
|
1846
|
-
function
|
|
1847
|
-
if (
|
|
1889
|
+
function lt(n) {
|
|
1890
|
+
if (ot.has(n)) return ot.get(n);
|
|
1848
1891
|
const e = new Promise((t, r) => {
|
|
1849
1892
|
const a = new Image();
|
|
1850
1893
|
a.onload = () => t(a), a.onerror = () => r(new Error(`failed to load ${n}`)), a.src = n;
|
|
1851
1894
|
});
|
|
1852
|
-
return
|
|
1895
|
+
return ot.set(n, e), e;
|
|
1853
1896
|
}
|
|
1854
|
-
function
|
|
1897
|
+
function rn(n, e) {
|
|
1855
1898
|
const t = document.createElement("canvas");
|
|
1856
1899
|
t.width = n.width, t.height = n.height;
|
|
1857
1900
|
const r = t.getContext("2d");
|
|
1858
1901
|
r.drawImage(n, 0, 0);
|
|
1859
|
-
const a = r.getImageData(0, 0, t.width, t.height).data,
|
|
1860
|
-
for (let
|
|
1861
|
-
return
|
|
1902
|
+
const a = r.getImageData(0, 0, t.width, t.height).data, s = new Uint8Array(t.width * t.height);
|
|
1903
|
+
for (let l = 0; l < s.length; l++) s[l] = a[l * 4 + e];
|
|
1904
|
+
return s;
|
|
1905
|
+
}
|
|
1906
|
+
const Fe = (n) => rn(n, 3);
|
|
1907
|
+
function ar(n, [e, t, r, a]) {
|
|
1908
|
+
const s = document.createElement("canvas");
|
|
1909
|
+
return s.width = r, s.height = a, s.getContext("2d").drawImage(n, e, t, r, a, 0, 0, r, a), s;
|
|
1862
1910
|
}
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
h[E] = x + (d - x) * F, h[E + 1] = s + (w - s) * F;
|
|
1911
|
+
function or(n, e) {
|
|
1912
|
+
const [t, r] = n.t.pivot, a = n.dir, s = n.pts, l = (b, v, h) => {
|
|
1913
|
+
const u = Math.min(1, Math.max(0, (h - b) / (v - b)));
|
|
1914
|
+
return u * u * (3 - 2 * u);
|
|
1915
|
+
}, f = Math.cos(n.phi[0]), y = Math.sin(n.phi[0]), d = Math.cos(n.phi[1]), m = Math.sin(n.phi[1]), c = e.rest, p = e.pos;
|
|
1916
|
+
for (let b = 0; b < c.length; b += 2) {
|
|
1917
|
+
const v = c[b] - t, h = c[b + 1] - r, u = v * a[0] + h * a[1], w = s[0][0] + v * f - h * y, o = s[0][1] + v * y + h * f, i = v - a[0] * n.L1, S = h - a[1] * n.L1, g = s[1][0] + i * d - S * m, A = s[1][1] + i * m + S * d, L = l(n.L1 * 0.55, n.L1 * 1.35, u);
|
|
1918
|
+
p[b] = w + (g - w) * L, p[b + 1] = o + (A - o) * L;
|
|
1872
1919
|
}
|
|
1873
1920
|
}
|
|
1874
|
-
async function
|
|
1921
|
+
async function sr(n, e) {
|
|
1875
1922
|
if (!e.assets && e.assetsBase === void 0)
|
|
1876
1923
|
throw new Error("createMeshAvatar requires assets or assetsBase.");
|
|
1877
|
-
const t = e.rig, r =
|
|
1924
|
+
const t = e.rig, r = xn(t), {
|
|
1878
1925
|
IMG: a,
|
|
1879
|
-
EYES:
|
|
1880
|
-
baseWeights:
|
|
1926
|
+
EYES: s,
|
|
1927
|
+
baseWeights: l,
|
|
1881
1928
|
deformBase: f,
|
|
1882
|
-
eyePartY:
|
|
1883
|
-
eyePartAlpha:
|
|
1884
|
-
handWeights:
|
|
1885
|
-
handFrame:
|
|
1886
|
-
deformHand:
|
|
1887
|
-
TASSELS:
|
|
1888
|
-
} = r, { Renderer:
|
|
1929
|
+
eyePartY: y,
|
|
1930
|
+
eyePartAlpha: d,
|
|
1931
|
+
handWeights: m,
|
|
1932
|
+
handFrame: c,
|
|
1933
|
+
deformHand: p,
|
|
1934
|
+
TASSELS: b
|
|
1935
|
+
} = r, { Renderer: v, buildGrid: h } = Un(r, t), { Physics: u } = Yn(r, t), { createSprites: w } = jn(r, t), o = (e.assetsBase ?? "").replace(/\/?$/, "/"), i = (E, R) => {
|
|
1889
1936
|
if (e.assets) {
|
|
1890
|
-
if (!e.assets[
|
|
1891
|
-
return e.assets[
|
|
1892
|
-
}
|
|
1893
|
-
return `${
|
|
1894
|
-
},
|
|
1895
|
-
for (let
|
|
1896
|
-
const R =
|
|
1897
|
-
O.push(
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
const
|
|
1901
|
-
|
|
1902
|
-
for (const
|
|
1903
|
-
const
|
|
1904
|
-
for (let
|
|
1905
|
-
const
|
|
1906
|
-
|
|
1937
|
+
if (!e.assets[E]) throw new Error(`Missing project asset: ${E}`);
|
|
1938
|
+
return e.assets[E];
|
|
1939
|
+
}
|
|
1940
|
+
return `${o}${E}${R === void 0 ? "" : `?b=${R}`}`;
|
|
1941
|
+
}, S = await it(i("layers.json")), g = ["base", ...t.hand ? ["hand"] : [], ...b.map((E) => E.name), ...[0, 1].flatMap((E) => Wt.map((R) => `eye${E}_${R}`)), "hairmask"], A = Object.fromEntries(await Promise.all(g.map(async (E) => [E, await lt(i(`${E}.png`, S.build))]))), L = rn(A.hairmask, 0), B = (E, R) => L[Math.min(a.h - 1, Math.max(0, Math.round(R))) * a.w + Math.min(a.w - 1, Math.max(0, Math.round(E)))] / 255, j = new v(n, { padTop: e.padTop ?? t.view.padTop, padSide: e.padSide ?? t.view.padSide, fit: e.fit }), k = { base: [0, 0, a.w, a.h], ...S.layers }, U = h(k.base, t.mesh.baseCell, Fe(A.base), A.base.width, t.mesh.fine), O = [];
|
|
1942
|
+
for (let E = 0; E < U.rest.length / 2; E++) {
|
|
1943
|
+
const R = U.rest[E * 2], J = U.rest[E * 2 + 1];
|
|
1944
|
+
O.push(l(R, J, B(R, J)));
|
|
1945
|
+
}
|
|
1946
|
+
j.addLayer("base", A.base, U, { face: !0 });
|
|
1947
|
+
const $ = [];
|
|
1948
|
+
s.forEach((E, R) => {
|
|
1949
|
+
for (const J of Wt) {
|
|
1950
|
+
const te = `eye${R}_${J}`, ee = h(k[te], J === "ball" ? t.mesh.eyeBallCell : t.mesh.eyeCell, Fe(A[te]), A[te].width), se = [];
|
|
1951
|
+
for (let ce = 0; ce < ee.rest.length / 2; ce++) se.push(l(ee.rest[ce * 2], ee.rest[ce * 2 + 1], 0));
|
|
1952
|
+
const le = j.addLayer(te, A[te], ee, { eyeBall: J === "ball" ? R : void 0 });
|
|
1953
|
+
$.push({ e: E, eye: R, part: J, mesh: ee, W: se, layer: le });
|
|
1907
1954
|
}
|
|
1908
1955
|
});
|
|
1909
1956
|
let D = null;
|
|
1910
1957
|
try {
|
|
1911
1958
|
{
|
|
1912
|
-
const
|
|
1913
|
-
D =
|
|
1914
|
-
}
|
|
1915
|
-
} catch (
|
|
1916
|
-
console.warn("eye / mouth sprites not loaded:",
|
|
1917
|
-
}
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1959
|
+
const E = await it(i("sprites/sprites.json")), R = Object.fromEntries(await Promise.all(Object.keys(E.layers).map(async (J) => [J, await lt(i(`sprites/${J}.png`, E.build))])));
|
|
1960
|
+
D = w(j, E, R, h, Fe);
|
|
1961
|
+
}
|
|
1962
|
+
} catch (E) {
|
|
1963
|
+
console.warn("eye / mouth sprites not loaded:", E);
|
|
1964
|
+
}
|
|
1965
|
+
let q = null;
|
|
1966
|
+
try {
|
|
1967
|
+
const E = await it(i("overlays/overlays.json")), R = Object.fromEntries(await Promise.all(E.overlays.map(async (J) => [J.name, await lt(i(`overlays/${J.file}`))])));
|
|
1968
|
+
q = Xn(j, E, R, h, Fe, l, t.mesh.spriteCell, a.w, a.h, ar);
|
|
1969
|
+
} catch (E) {
|
|
1970
|
+
e.assets?.["overlays/overlays.json"] && console.warn("overlay layers not loaded:", E);
|
|
1971
|
+
}
|
|
1972
|
+
const N = b.map((E) => {
|
|
1973
|
+
const R = h(k[E.name], t.mesh.tasselCell, Fe(A[E.name]), A[E.name].width);
|
|
1974
|
+
return j.addLayer(E.name, A[E.name], R);
|
|
1975
|
+
}), P = t.hand ? h(k.hand, t.mesh.handCell, Fe(A.hand), A.hand.width) : { rest: [], pos: [] }, H = [];
|
|
1976
|
+
for (let E = 0; E < P.rest.length / 2; E++) H.push(m(P.rest[E * 2], P.rest[E * 2 + 1]));
|
|
1977
|
+
t.hand && j.addLayer("hand", A.hand, P);
|
|
1978
|
+
const G = new u(), z = new Qn(t.view.gazeCenter ?? [t.head.cx, t.head.cy]);
|
|
1979
|
+
e.lipSync !== void 0 && z.setLipSync(e.lipSync);
|
|
1980
|
+
const W = /* @__PURE__ */ new Set();
|
|
1981
|
+
z.onMotion = (E) => {
|
|
1982
|
+
for (const R of W) R(E);
|
|
1929
1983
|
};
|
|
1930
|
-
let
|
|
1931
|
-
const
|
|
1932
|
-
function
|
|
1933
|
-
const R = {
|
|
1934
|
-
for (const [
|
|
1935
|
-
|
|
1936
|
-
const
|
|
1937
|
-
return
|
|
1938
|
-
}
|
|
1939
|
-
function
|
|
1940
|
-
const R =
|
|
1941
|
-
for (let
|
|
1942
|
-
f(
|
|
1943
|
-
const
|
|
1944
|
-
for (const
|
|
1945
|
-
const ke =
|
|
1946
|
-
|
|
1947
|
-
const
|
|
1948
|
-
for (let
|
|
1949
|
-
const
|
|
1950
|
-
f(
|
|
1984
|
+
let I = {}, V = 1, K = {};
|
|
1985
|
+
const x = new rr(), M = [0, 0];
|
|
1986
|
+
function T(E) {
|
|
1987
|
+
const R = { ...z.update(E) };
|
|
1988
|
+
for (const [te, ee] of Object.entries(I)) R[te] = V === 1 ? ee : (R[te] ?? 0) + (ee - (R[te] ?? 0)) * V;
|
|
1989
|
+
z.lipOpen !== null && (R.mouthOpen = z.P.mouthOpen, (!e.preserveMouthForm || I.mouthForm === void 0) && (R.mouthForm = z.P.mouthForm));
|
|
1990
|
+
const J = x.apply(R, E);
|
|
1991
|
+
return K = J, J;
|
|
1992
|
+
}
|
|
1993
|
+
function _(E) {
|
|
1994
|
+
const R = T(E), J = G.step(R, E), te = U.pos, ee = U.rest;
|
|
1995
|
+
for (let Q = 0; Q < O.length; Q++)
|
|
1996
|
+
f(ee[Q * 2], ee[Q * 2 + 1], O[Q], R, J, M), te[Q * 2] = M[0], te[Q * 2 + 1] = M[1];
|
|
1997
|
+
const se = (Q, ke) => D?.eyesDrawn[ke] ? 1 : Q;
|
|
1998
|
+
for (const Q of $) {
|
|
1999
|
+
const ke = se(Q.eye === 0 ? R.eyeROpen : R.eyeLOpen, Q.eye), Ft = Q.eye === 0 ? R.eyeSmile : R.eyeSmileL ?? R.eyeSmile;
|
|
2000
|
+
Q.layer.alpha = d(Q.part, ke, Ft);
|
|
2001
|
+
const Bt = Q.mesh.rest, Ut = Q.mesh.pos;
|
|
2002
|
+
for (let Oe = 0; Oe < Q.W.length; Oe++) {
|
|
2003
|
+
const Yt = Bt[Oe * 2], vn = Bt[Oe * 2 + 1];
|
|
2004
|
+
f(Yt, y(Q.e, Q.part, Yt, vn, ke, Ft), Q.W[Oe], R, J, M), Ut[Oe * 2] = M[0], Ut[Oe * 2 + 1] = M[1];
|
|
1951
2005
|
}
|
|
1952
2006
|
}
|
|
1953
|
-
const
|
|
1954
|
-
if (
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2007
|
+
const le = D?.update(R, J, E, In(x.name, z.mode === "manual" ? null : z.expr));
|
|
2008
|
+
if (le) for (const Q of $) le.eyes[Q.eye] && (Q.layer.alpha = 0);
|
|
2009
|
+
q?.update(R, J, f, M);
|
|
2010
|
+
const ce = P.pos, je = P.rest, _e = c(R);
|
|
2011
|
+
for (let Q = 0; Q < H.length; Q++)
|
|
2012
|
+
p(je[Q * 2], je[Q * 2 + 1], H[Q], R, _e, M), ce[Q * 2] = M[0], ce[Q * 2 + 1] = M[1];
|
|
2013
|
+
G.chains.forEach((Q, ke) => or(Q, N[ke].mesh));
|
|
2014
|
+
const Ze = 7;
|
|
2015
|
+
j.draw({
|
|
1961
2016
|
angleX: R.angleX,
|
|
1962
2017
|
angleY: R.angleY,
|
|
1963
2018
|
angleZ: R.angleZ,
|
|
1964
2019
|
eyes: [
|
|
1965
|
-
|
|
2020
|
+
se(R.eyeROpen, 0),
|
|
1966
2021
|
R.eyeSmile,
|
|
1967
|
-
R.gazeX *
|
|
1968
|
-
-R.gazeY *
|
|
1969
|
-
|
|
2022
|
+
R.gazeX * Ze,
|
|
2023
|
+
-R.gazeY * Ze * 0.6,
|
|
2024
|
+
se(R.eyeLOpen, 1),
|
|
1970
2025
|
R.eyeSmileL ?? R.eyeSmile,
|
|
1971
|
-
R.gazeX *
|
|
1972
|
-
-R.gazeY *
|
|
2026
|
+
R.gazeX * Ze * 0.85,
|
|
2027
|
+
-R.gazeY * Ze * 0.6
|
|
1973
2028
|
],
|
|
1974
2029
|
// with sprites the drawn mouths replace the shader-painted one
|
|
1975
|
-
mouthOpen:
|
|
2030
|
+
mouthOpen: le?.mouthDrawn ? 0 : R.mouthOpen,
|
|
1976
2031
|
mouthForm: R.mouthForm,
|
|
1977
2032
|
cheek: R.blush,
|
|
1978
2033
|
showMesh: !1,
|
|
@@ -1980,106 +2035,110 @@ async function nr(n, e) {
|
|
|
1980
2035
|
joints: []
|
|
1981
2036
|
});
|
|
1982
2037
|
}
|
|
1983
|
-
let
|
|
1984
|
-
const
|
|
1985
|
-
const R = Math.min(0.05, (
|
|
1986
|
-
|
|
2038
|
+
let Y = 0, X = performance.now(), F = !1;
|
|
2039
|
+
const C = (E) => {
|
|
2040
|
+
const R = Math.min(0.05, (E - X) / 1e3);
|
|
2041
|
+
X = E, _(R), Y = requestAnimationFrame(C);
|
|
1987
2042
|
};
|
|
1988
|
-
return e.manual || (
|
|
2043
|
+
return e.manual || (Y = requestAnimationFrame(C)), {
|
|
1989
2044
|
motions: [
|
|
1990
|
-
...Object.entries(
|
|
1991
|
-
...Object.entries(
|
|
2045
|
+
...Object.entries(Tt).map(([E, R]) => ({ id: E, label: R.label, idle: !1 })),
|
|
2046
|
+
...Object.entries(Ot).map(([E, R]) => ({ id: E, label: R.label, idle: !0 }))
|
|
1992
2047
|
],
|
|
1993
|
-
setParameters(
|
|
1994
|
-
|
|
2048
|
+
setParameters(E, R = 1) {
|
|
2049
|
+
I = { ...E }, V = Math.min(1, Math.max(0, Number(R) || 0));
|
|
1995
2050
|
},
|
|
1996
2051
|
getParameters() {
|
|
1997
|
-
return { ...
|
|
2052
|
+
return { ...K };
|
|
1998
2053
|
},
|
|
1999
2054
|
/** 0..1 loudness of the voice being played (e.g. normalised RMS). */
|
|
2000
|
-
setVoiceLevel(
|
|
2001
|
-
|
|
2055
|
+
setVoiceLevel(E) {
|
|
2056
|
+
z.setVoiceLevel(E);
|
|
2002
2057
|
},
|
|
2003
2058
|
/** Partial mouth-movement settings; omitted fields retain their current values. */
|
|
2004
|
-
setLipSync(
|
|
2005
|
-
|
|
2059
|
+
setLipSync(E) {
|
|
2060
|
+
z.setLipSync(E);
|
|
2006
2061
|
},
|
|
2007
2062
|
/** true while TTS audio is playing: idle motions pause and the head nods along. */
|
|
2008
|
-
setSpeaking(
|
|
2009
|
-
|
|
2063
|
+
setSpeaking(E) {
|
|
2064
|
+
z.setSpeaking(E);
|
|
2010
2065
|
},
|
|
2011
2066
|
/** AITuber OnAir emotion tag: happy / sad / angry / surprised / relaxed / neutral (or null). */
|
|
2012
|
-
setEmotion(
|
|
2013
|
-
|
|
2067
|
+
setEmotion(E, R) {
|
|
2068
|
+
z.setEmotion(E, R);
|
|
2014
2069
|
},
|
|
2015
2070
|
/** Live expression layered over tracking (see OVERLAY_EXPRESSIONS); 'neutral' clears it. */
|
|
2016
|
-
setExpression(
|
|
2017
|
-
|
|
2071
|
+
setExpression(E) {
|
|
2072
|
+
x.set(E);
|
|
2073
|
+
},
|
|
2074
|
+
/** Show the named overlay layers (built/overlays/overlays.json) and hide the others. */
|
|
2075
|
+
setOverlays(E) {
|
|
2076
|
+
q?.set(E);
|
|
2018
2077
|
},
|
|
2019
2078
|
getExpression() {
|
|
2020
|
-
return { name:
|
|
2079
|
+
return { name: x.name, active: x.active };
|
|
2021
2080
|
},
|
|
2022
2081
|
/** How much the head moves with the voice while speaking (1 = default, calmer below). */
|
|
2023
|
-
setTalkGain(
|
|
2024
|
-
|
|
2082
|
+
setTalkGain(E) {
|
|
2083
|
+
z.talkGain = Math.max(0, Number(E) || 0);
|
|
2025
2084
|
},
|
|
2026
2085
|
/** Play a motion or idle motion by id (see `motions`). */
|
|
2027
|
-
play(
|
|
2028
|
-
|
|
2086
|
+
play(E) {
|
|
2087
|
+
z.hasMotion(E) && z.playMotion(E);
|
|
2029
2088
|
},
|
|
2030
2089
|
/** Move the mouth through the vowels of kana text (no audio; for previews). */
|
|
2031
|
-
speakKana(
|
|
2032
|
-
|
|
2090
|
+
speakKana(E, R) {
|
|
2091
|
+
z.speakKana(String(E ?? ""), R);
|
|
2033
2092
|
},
|
|
2034
|
-
holdMouth(
|
|
2035
|
-
|
|
2093
|
+
holdMouth(E) {
|
|
2094
|
+
z.holdMouth(E);
|
|
2036
2095
|
},
|
|
2037
2096
|
stopLipSync() {
|
|
2038
|
-
|
|
2097
|
+
z.stopLipSync();
|
|
2039
2098
|
},
|
|
2040
2099
|
getLipSyncState() {
|
|
2041
|
-
return
|
|
2100
|
+
return z.getLipSyncState();
|
|
2042
2101
|
},
|
|
2043
|
-
setAutoIdle(
|
|
2044
|
-
|
|
2102
|
+
setAutoIdle(E) {
|
|
2103
|
+
z.autoIdle = !!E;
|
|
2045
2104
|
},
|
|
2046
|
-
setLighting(
|
|
2047
|
-
|
|
2105
|
+
setLighting(E) {
|
|
2106
|
+
j.setLighting(E);
|
|
2048
2107
|
},
|
|
2049
2108
|
getLightingStats() {
|
|
2050
|
-
return { ...
|
|
2109
|
+
return { ...j.lightingStats };
|
|
2051
2110
|
},
|
|
2052
|
-
setAutoMotion(
|
|
2053
|
-
|
|
2111
|
+
setAutoMotion(E) {
|
|
2112
|
+
z.autoMotion = !!E;
|
|
2054
2113
|
},
|
|
2055
2114
|
/** Hair / tassel sway multiplier (1 = default). */
|
|
2056
|
-
setSwayGain(
|
|
2057
|
-
|
|
2115
|
+
setSwayGain(E) {
|
|
2116
|
+
G.gain = E;
|
|
2058
2117
|
},
|
|
2059
2118
|
/** Called with the motion id when a motion starts and with null when it ends. */
|
|
2060
|
-
onMotion(
|
|
2061
|
-
return
|
|
2119
|
+
onMotion(E) {
|
|
2120
|
+
return W.add(E), () => W.delete(E);
|
|
2062
2121
|
},
|
|
2063
2122
|
/** Advance the simulation by `sec` and draw (for tests / hidden tabs). */
|
|
2064
|
-
advance(
|
|
2065
|
-
if (!
|
|
2066
|
-
if (
|
|
2067
|
-
else for (let
|
|
2123
|
+
advance(E, R = 60) {
|
|
2124
|
+
if (!F)
|
|
2125
|
+
if (E === 0) _(0);
|
|
2126
|
+
else for (let J = 0; J < Math.round(E * R); J++) _(1 / R);
|
|
2068
2127
|
},
|
|
2069
2128
|
/** Update motion and lip sync without drawing a hidden preview. */
|
|
2070
|
-
advanceParameters(
|
|
2071
|
-
|
|
2129
|
+
advanceParameters(E) {
|
|
2130
|
+
F || T(E);
|
|
2072
2131
|
},
|
|
2073
2132
|
destroy() {
|
|
2074
|
-
|
|
2133
|
+
F || (F = !0, cancelAnimationFrame(Y), W.clear(), j.destroy());
|
|
2075
2134
|
}
|
|
2076
2135
|
};
|
|
2077
2136
|
}
|
|
2078
|
-
const
|
|
2079
|
-
async function
|
|
2080
|
-
return
|
|
2137
|
+
const Yr = Object.keys(Rt);
|
|
2138
|
+
async function ir(n, e) {
|
|
2139
|
+
return sr(n, { ...e, rig: Et(e.rig) });
|
|
2081
2140
|
}
|
|
2082
|
-
function
|
|
2141
|
+
function Ye(n) {
|
|
2083
2142
|
if (!n || typeof n != "object" || Array.isArray(n))
|
|
2084
2143
|
throw new Error("avatar.json: expected an object");
|
|
2085
2144
|
const e = n, t = [];
|
|
@@ -2093,7 +2152,7 @@ function Be(n) {
|
|
|
2093
2152
|
}
|
|
2094
2153
|
if (e.lipSync !== void 0)
|
|
2095
2154
|
try {
|
|
2096
|
-
r.lipSync =
|
|
2155
|
+
r.lipSync = St(e.lipSync);
|
|
2097
2156
|
} catch (a) {
|
|
2098
2157
|
t.push(`avatar.json.lipSync: ${a instanceof Error ? a.message : String(a)}`);
|
|
2099
2158
|
}
|
|
@@ -2101,111 +2160,126 @@ function Be(n) {
|
|
|
2101
2160
|
`));
|
|
2102
2161
|
return r;
|
|
2103
2162
|
}
|
|
2104
|
-
function rn(n) {
|
|
2105
|
-
return Be({ format: "mesh-avatar", version: 1, name: n });
|
|
2106
|
-
}
|
|
2107
|
-
const ot = (n) => !!n && typeof n == "object" && !Array.isArray(n), Le = (n, e) => Array.isArray(n) && n.length === e && n.every((t) => typeof t == "number" && Number.isFinite(t)), st = (n, e) => Object.hasOwn(n, e);
|
|
2108
2163
|
function an(n) {
|
|
2164
|
+
return Ye({ format: "mesh-avatar", version: 1, name: n });
|
|
2165
|
+
}
|
|
2166
|
+
const Je = (n) => !!n && typeof n == "object" && !Array.isArray(n), Re = (n, e) => Array.isArray(n) && n.length === e && n.every((t) => typeof t == "number" && Number.isFinite(t)), ct = (n, e) => Object.hasOwn(n, e);
|
|
2167
|
+
function on(n) {
|
|
2109
2168
|
const e = [];
|
|
2110
|
-
function t(
|
|
2111
|
-
if (!
|
|
2112
|
-
|
|
2169
|
+
function t(b, v = !0) {
|
|
2170
|
+
if (!ct(n, b)) {
|
|
2171
|
+
v && e.push(`${b}: missing file`);
|
|
2113
2172
|
return;
|
|
2114
2173
|
}
|
|
2115
|
-
const
|
|
2116
|
-
if (!(
|
|
2117
|
-
e.push(`${
|
|
2174
|
+
const h = n[b];
|
|
2175
|
+
if (!(h instanceof Uint8Array)) {
|
|
2176
|
+
e.push(`${b}: JSON bytes are required`);
|
|
2118
2177
|
return;
|
|
2119
2178
|
}
|
|
2120
2179
|
let u;
|
|
2121
2180
|
try {
|
|
2122
|
-
u = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(
|
|
2181
|
+
u = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(h));
|
|
2123
2182
|
} catch {
|
|
2124
|
-
e.push(`${
|
|
2183
|
+
e.push(`${b}: invalid UTF-8 JSON`);
|
|
2125
2184
|
return;
|
|
2126
2185
|
}
|
|
2127
|
-
if (!
|
|
2128
|
-
e.push(`${
|
|
2186
|
+
if (!Je(u)) {
|
|
2187
|
+
e.push(`${b}: expected an object`);
|
|
2129
2188
|
return;
|
|
2130
2189
|
}
|
|
2131
2190
|
return u;
|
|
2132
2191
|
}
|
|
2133
|
-
function r(
|
|
2134
|
-
return
|
|
2192
|
+
function r(b, v, h = !0) {
|
|
2193
|
+
return b.version === 1 || h && b.version === void 0 ? !0 : (e.push(`${v}.version: unsupported version ${JSON.stringify(b.version) ?? "missing"} (expected 1)`), !1);
|
|
2135
2194
|
}
|
|
2136
|
-
function a(
|
|
2137
|
-
if (!
|
|
2138
|
-
e.push(`${
|
|
2195
|
+
function a(b) {
|
|
2196
|
+
if (!ct(n, b)) {
|
|
2197
|
+
e.push(`${b}: missing file`);
|
|
2139
2198
|
return;
|
|
2140
2199
|
}
|
|
2141
|
-
const
|
|
2142
|
-
(!Number.isSafeInteger(
|
|
2200
|
+
const v = n[b], h = v instanceof Uint8Array ? v.byteLength : v?.size;
|
|
2201
|
+
(!Number.isSafeInteger(h) || h <= 0) && e.push(`${b}: expected a non-empty file`);
|
|
2143
2202
|
}
|
|
2144
|
-
function
|
|
2145
|
-
if (!
|
|
2146
|
-
e.push(`${
|
|
2203
|
+
function s(b, v, h, u) {
|
|
2204
|
+
if (!Je(b)) {
|
|
2205
|
+
e.push(`${v}.layers: expected a layer rectangle map`);
|
|
2147
2206
|
return;
|
|
2148
2207
|
}
|
|
2149
|
-
for (const [
|
|
2150
|
-
const
|
|
2151
|
-
if (!/^[A-Za-z0-9_-]+$/.test(
|
|
2152
|
-
e.push(`${
|
|
2208
|
+
for (const [w, o] of Object.entries(b)) {
|
|
2209
|
+
const i = `${v}.layers.${w}`;
|
|
2210
|
+
if (!/^[A-Za-z0-9_-]+$/.test(w)) {
|
|
2211
|
+
e.push(`${i}: expected a safe layer name (letters, digits, hyphens or underscores)`);
|
|
2153
2212
|
continue;
|
|
2154
2213
|
}
|
|
2155
|
-
!
|
|
2214
|
+
!Re(o, 4) || !o.every(Number.isInteger) || o[0] < 0 || o[1] < 0 || o[2] <= 0 || o[3] <= 0 ? e.push(`${i}: expected [x, y, width, height] with non-negative integer origins and positive integer dimensions`) : u && (o[0] + o[2] > u[0] || o[1] + o[3] > u[1]) && e.push(`${i}: rectangle must stay inside the image`), a(`${h}/${w}.png`);
|
|
2156
2215
|
}
|
|
2157
|
-
return
|
|
2216
|
+
return b;
|
|
2158
2217
|
}
|
|
2159
|
-
function
|
|
2160
|
-
(typeof
|
|
2218
|
+
function l(b, v) {
|
|
2219
|
+
(typeof b.build != "string" || !b.build.trim()) && e.push(`${v}.build: expected a non-empty string`);
|
|
2161
2220
|
}
|
|
2162
2221
|
const f = t("avatar.json", !1);
|
|
2163
2222
|
if (f)
|
|
2164
2223
|
try {
|
|
2165
|
-
|
|
2166
|
-
} catch (
|
|
2167
|
-
e.push(
|
|
2224
|
+
Ye(f);
|
|
2225
|
+
} catch (b) {
|
|
2226
|
+
e.push(b.message);
|
|
2168
2227
|
}
|
|
2169
|
-
const
|
|
2170
|
-
let
|
|
2171
|
-
if (
|
|
2172
|
-
const
|
|
2173
|
-
e.push(...
|
|
2228
|
+
const y = t("rig.json");
|
|
2229
|
+
let d;
|
|
2230
|
+
if (y && r(y, "rig.json", !1)) {
|
|
2231
|
+
const b = en(y);
|
|
2232
|
+
e.push(...b.map((v) => `rig.json: ${v}`)), b.length || (d = y);
|
|
2174
2233
|
}
|
|
2175
2234
|
a("built/base.png"), a("built/hairmask.png");
|
|
2176
|
-
const
|
|
2177
|
-
if (
|
|
2178
|
-
|
|
2179
|
-
let
|
|
2180
|
-
!
|
|
2181
|
-
const
|
|
2182
|
-
if (
|
|
2183
|
-
const
|
|
2184
|
-
...
|
|
2185
|
-
...
|
|
2186
|
-
...(
|
|
2235
|
+
const m = t("built/layers.json");
|
|
2236
|
+
if (m && r(m, "built/layers.json")) {
|
|
2237
|
+
l(m, "built/layers.json");
|
|
2238
|
+
let b;
|
|
2239
|
+
!Re(m.size, 2) || !m.size.every((h) => Number.isInteger(h) && h > 0) ? e.push("built/layers.json.size: expected [width, height] with positive integer dimensions") : (b = m.size, d && (b[0] !== d.image.width || b[1] !== d.image.height) && e.push("built/layers.json.size: must match rig.json.image"));
|
|
2240
|
+
const v = s(m.layers, "built/layers.json", "built", b);
|
|
2241
|
+
if (d && v) {
|
|
2242
|
+
const h = [
|
|
2243
|
+
...d.eyes.flatMap((u, w) => ["ball", "low", "crease", "lash"].map((o) => `eye${w}_${o}`)),
|
|
2244
|
+
...d.hand ? ["hand"] : [],
|
|
2245
|
+
...(d.accessories ?? []).map((u) => u.name)
|
|
2187
2246
|
];
|
|
2188
|
-
for (const u of
|
|
2247
|
+
for (const u of h) ct(v, u) || e.push(`built/layers.json.layers.${u}: missing required layer`);
|
|
2189
2248
|
}
|
|
2190
|
-
!Array.isArray(
|
|
2191
|
-
const
|
|
2192
|
-
if (!
|
|
2193
|
-
e.push(`${
|
|
2249
|
+
!Array.isArray(m.eyes) || m.eyes.length !== 2 ? e.push("built/layers.json.eyes: expected two eye curves") : m.eyes.forEach((h, u) => {
|
|
2250
|
+
const w = `built/layers.json.eyes[${u}]`;
|
|
2251
|
+
if (!Je(h)) {
|
|
2252
|
+
e.push(`${w}: expected an object`);
|
|
2194
2253
|
return;
|
|
2195
2254
|
}
|
|
2196
|
-
|
|
2197
|
-
for (const
|
|
2198
|
-
|
|
2199
|
-
if (
|
|
2200
|
-
const
|
|
2201
|
-
(Array.isArray(
|
|
2255
|
+
Re([h.x0, h.x1], 2) && h.x0 < h.x1 || e.push(`${w}: expected finite x0 < x1`);
|
|
2256
|
+
for (const i of ["top", "bot"])
|
|
2257
|
+
Re(h[i], 24) || e.push(`${w}.${i}: expected 24 finite numbers`);
|
|
2258
|
+
if (Re(h.top, 24) && Re(h.bot, 24) && h.top.some((i, S) => i > h.bot[S]) && e.push(`${w}.top: must not exceed bottom curve`), d) for (const i of ["x0", "x1", "top", "bot"]) {
|
|
2259
|
+
const S = h[i], g = d.eyes[u][i];
|
|
2260
|
+
(Array.isArray(g) ? Re(S, g.length) && S.every((L, B) => L === g[B]) : S === g) || e.push(`${w}.${i}: must match rig.json.eyes[${u}].${i}`);
|
|
2202
2261
|
}
|
|
2203
2262
|
});
|
|
2204
2263
|
}
|
|
2205
|
-
const
|
|
2206
|
-
|
|
2264
|
+
const c = t("built/sprites/sprites.json", !1);
|
|
2265
|
+
c && r(c, "built/sprites/sprites.json") && (l(c, "built/sprites/sprites.json"), s(c.layers, "built/sprites/sprites.json", "built/sprites", d ? [d.image.width, d.image.height] : void 0));
|
|
2266
|
+
const p = t("built/overlays/overlays.json", !1);
|
|
2267
|
+
if (p && r(p, "built/overlays/overlays.json"))
|
|
2268
|
+
if (!Array.isArray(p.overlays)) e.push("built/overlays/overlays.json.overlays: expected an array");
|
|
2269
|
+
else {
|
|
2270
|
+
const b = /* @__PURE__ */ new Set();
|
|
2271
|
+
for (const [v, h] of p.overlays.entries()) {
|
|
2272
|
+
const u = `built/overlays/overlays.json.overlays[${v}]`;
|
|
2273
|
+
if (!Je(h) || typeof h.name != "string" || !/^[A-Za-z0-9_-]+$/.test(h.name) || typeof h.file != "string" || !/^[A-Za-z0-9_-]+\.png$/.test(h.file)) {
|
|
2274
|
+
e.push(`${u}: expected { name, file } with safe names`);
|
|
2275
|
+
continue;
|
|
2276
|
+
}
|
|
2277
|
+
b.has(h.name) && e.push(`${u}.name: duplicate overlay name`), b.add(h.name), a(`built/overlays/${h.file}`);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
return e;
|
|
2207
2281
|
}
|
|
2208
|
-
var ae = Uint8Array,
|
|
2282
|
+
var ae = Uint8Array, fe = Uint16Array, Lt = Int32Array, et = new ae([
|
|
2209
2283
|
0,
|
|
2210
2284
|
0,
|
|
2211
2285
|
0,
|
|
@@ -2240,7 +2314,7 @@ var ae = Uint8Array, ue = Uint16Array, Tt = Int32Array, Ke = new ae([
|
|
|
2240
2314
|
0,
|
|
2241
2315
|
/* impossible */
|
|
2242
2316
|
0
|
|
2243
|
-
]),
|
|
2317
|
+
]), tt = new ae([
|
|
2244
2318
|
0,
|
|
2245
2319
|
0,
|
|
2246
2320
|
0,
|
|
@@ -2274,65 +2348,65 @@ var ae = Uint8Array, ue = Uint16Array, Tt = Int32Array, Ke = new ae([
|
|
|
2274
2348
|
/* unused */
|
|
2275
2349
|
0,
|
|
2276
2350
|
0
|
|
2277
|
-
]),
|
|
2278
|
-
for (var t = new
|
|
2351
|
+
]), dt = new ae([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), sn = function(n, e) {
|
|
2352
|
+
for (var t = new fe(31), r = 0; r < 31; ++r)
|
|
2279
2353
|
t[r] = e += 1 << n[r - 1];
|
|
2280
|
-
for (var a = new
|
|
2281
|
-
for (var
|
|
2282
|
-
a[
|
|
2354
|
+
for (var a = new Lt(t[30]), r = 1; r < 30; ++r)
|
|
2355
|
+
for (var s = t[r]; s < t[r + 1]; ++s)
|
|
2356
|
+
a[s] = s - t[r] << 5 | r;
|
|
2283
2357
|
return { b: t, r: a };
|
|
2284
|
-
},
|
|
2285
|
-
|
|
2286
|
-
var
|
|
2358
|
+
}, ln = sn(et, 2), cn = ln.b, gt = ln.r;
|
|
2359
|
+
cn[28] = 258, gt[258] = 28;
|
|
2360
|
+
var hn = sn(tt, 0), lr = hn.b, Gt = hn.r, yt = new fe(32768);
|
|
2287
2361
|
for (var re = 0; re < 32768; ++re) {
|
|
2288
|
-
var
|
|
2289
|
-
|
|
2362
|
+
var Se = (re & 43690) >> 1 | (re & 21845) << 1;
|
|
2363
|
+
Se = (Se & 52428) >> 2 | (Se & 13107) << 2, Se = (Se & 61680) >> 4 | (Se & 3855) << 4, yt[re] = ((Se & 65280) >> 8 | (Se & 255) << 8) >> 1;
|
|
2290
2364
|
}
|
|
2291
2365
|
var xe = (function(n, e, t) {
|
|
2292
|
-
for (var r = n.length, a = 0,
|
|
2293
|
-
n[a] && ++
|
|
2294
|
-
var
|
|
2366
|
+
for (var r = n.length, a = 0, s = new fe(e); a < r; ++a)
|
|
2367
|
+
n[a] && ++s[n[a] - 1];
|
|
2368
|
+
var l = new fe(e);
|
|
2295
2369
|
for (a = 1; a < e; ++a)
|
|
2296
|
-
|
|
2370
|
+
l[a] = l[a - 1] + s[a - 1] << 1;
|
|
2297
2371
|
var f;
|
|
2298
2372
|
if (t) {
|
|
2299
|
-
f = new
|
|
2300
|
-
var
|
|
2373
|
+
f = new fe(1 << e);
|
|
2374
|
+
var y = 15 - e;
|
|
2301
2375
|
for (a = 0; a < r; ++a)
|
|
2302
2376
|
if (n[a])
|
|
2303
|
-
for (var
|
|
2304
|
-
f[
|
|
2377
|
+
for (var d = a << 4 | n[a], m = e - n[a], c = l[n[a] - 1]++ << m, p = c | (1 << m) - 1; c <= p; ++c)
|
|
2378
|
+
f[yt[c] >> y] = d;
|
|
2305
2379
|
} else
|
|
2306
|
-
for (f = new
|
|
2307
|
-
n[a] && (f[a] =
|
|
2380
|
+
for (f = new fe(r), a = 0; a < r; ++a)
|
|
2381
|
+
n[a] && (f[a] = yt[l[n[a] - 1]++] >> 15 - n[a]);
|
|
2308
2382
|
return f;
|
|
2309
|
-
}),
|
|
2383
|
+
}), Te = new ae(288);
|
|
2310
2384
|
for (var re = 0; re < 144; ++re)
|
|
2311
|
-
|
|
2385
|
+
Te[re] = 8;
|
|
2312
2386
|
for (var re = 144; re < 256; ++re)
|
|
2313
|
-
|
|
2387
|
+
Te[re] = 9;
|
|
2314
2388
|
for (var re = 256; re < 280; ++re)
|
|
2315
|
-
|
|
2389
|
+
Te[re] = 7;
|
|
2316
2390
|
for (var re = 280; re < 288; ++re)
|
|
2317
|
-
|
|
2318
|
-
var
|
|
2391
|
+
Te[re] = 8;
|
|
2392
|
+
var De = new ae(32);
|
|
2319
2393
|
for (var re = 0; re < 32; ++re)
|
|
2320
|
-
|
|
2321
|
-
var
|
|
2394
|
+
De[re] = 5;
|
|
2395
|
+
var cr = /* @__PURE__ */ xe(Te, 9, 0), hr = /* @__PURE__ */ xe(Te, 9, 1), ur = /* @__PURE__ */ xe(De, 5, 0), fr = /* @__PURE__ */ xe(De, 5, 1), ht = function(n) {
|
|
2322
2396
|
for (var e = n[0], t = 1; t < n.length; ++t)
|
|
2323
2397
|
n[t] > e && (e = n[t]);
|
|
2324
2398
|
return e;
|
|
2325
2399
|
}, de = function(n, e, t) {
|
|
2326
2400
|
var r = e / 8 | 0;
|
|
2327
2401
|
return (n[r] | n[r + 1] << 8) >> (e & 7) & t;
|
|
2328
|
-
},
|
|
2402
|
+
}, ut = function(n, e) {
|
|
2329
2403
|
var t = e / 8 | 0;
|
|
2330
2404
|
return (n[t] | n[t + 1] << 8 | n[t + 2] << 16) >> (e & 7);
|
|
2331
|
-
},
|
|
2405
|
+
}, _t = function(n) {
|
|
2332
2406
|
return (n + 7) / 8 | 0;
|
|
2333
|
-
},
|
|
2407
|
+
}, He = function(n, e, t) {
|
|
2334
2408
|
return (e == null || e < 0) && (e = 0), (t == null || t > n.length) && (t = n.length), new ae(n.subarray(e, t));
|
|
2335
|
-
},
|
|
2409
|
+
}, mr = [
|
|
2336
2410
|
"unexpected EOF",
|
|
2337
2411
|
"invalid block type",
|
|
2338
2412
|
"invalid length/literal",
|
|
@@ -2349,310 +2423,310 @@ var or = /* @__PURE__ */ xe(Oe, 9, 0), sr = /* @__PURE__ */ xe(Oe, 9, 1), ir = /
|
|
|
2349
2423
|
"stream finishing",
|
|
2350
2424
|
"invalid zip data"
|
|
2351
2425
|
// determined by unknown compression method
|
|
2352
|
-
],
|
|
2353
|
-
var r = new Error(e ||
|
|
2354
|
-
if (r.code = n, Error.captureStackTrace && Error.captureStackTrace(r,
|
|
2426
|
+
], he = function(n, e, t) {
|
|
2427
|
+
var r = new Error(e || mr[n]);
|
|
2428
|
+
if (r.code = n, Error.captureStackTrace && Error.captureStackTrace(r, he), !t)
|
|
2355
2429
|
throw r;
|
|
2356
2430
|
return r;
|
|
2357
|
-
},
|
|
2358
|
-
var a = n.length,
|
|
2431
|
+
}, pr = function(n, e, t, r) {
|
|
2432
|
+
var a = n.length, s = r ? r.length : 0;
|
|
2359
2433
|
if (!a || e.f && !e.l)
|
|
2360
2434
|
return t || new ae(0);
|
|
2361
|
-
var
|
|
2362
|
-
|
|
2363
|
-
var
|
|
2364
|
-
var
|
|
2365
|
-
if (
|
|
2366
|
-
var
|
|
2367
|
-
|
|
2368
|
-
}
|
|
2369
|
-
},
|
|
2435
|
+
var l = !t, f = l || e.i != 2, y = e.i;
|
|
2436
|
+
l && (t = new ae(a * 3));
|
|
2437
|
+
var d = function(F) {
|
|
2438
|
+
var C = t.length;
|
|
2439
|
+
if (F > C) {
|
|
2440
|
+
var Z = new ae(Math.max(C * 2, F));
|
|
2441
|
+
Z.set(t), t = Z;
|
|
2442
|
+
}
|
|
2443
|
+
}, m = e.f || 0, c = e.p || 0, p = e.b || 0, b = e.l, v = e.d, h = e.m, u = e.n, w = a * 8;
|
|
2370
2444
|
do {
|
|
2371
|
-
if (!
|
|
2372
|
-
|
|
2373
|
-
var
|
|
2374
|
-
if (
|
|
2375
|
-
if (
|
|
2376
|
-
|
|
2377
|
-
else if (
|
|
2378
|
-
var
|
|
2379
|
-
|
|
2380
|
-
for (var
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
for (var O =
|
|
2384
|
-
var
|
|
2385
|
-
|
|
2386
|
-
var
|
|
2387
|
-
if (
|
|
2388
|
-
|
|
2445
|
+
if (!b) {
|
|
2446
|
+
m = de(n, c, 1);
|
|
2447
|
+
var o = de(n, c + 1, 3);
|
|
2448
|
+
if (c += 3, o)
|
|
2449
|
+
if (o == 1)
|
|
2450
|
+
b = hr, v = fr, h = 9, u = 5;
|
|
2451
|
+
else if (o == 2) {
|
|
2452
|
+
var A = de(n, c, 31) + 257, L = de(n, c + 10, 15) + 4, B = A + de(n, c + 5, 31) + 1;
|
|
2453
|
+
c += 14;
|
|
2454
|
+
for (var j = new ae(B), k = new ae(19), U = 0; U < L; ++U)
|
|
2455
|
+
k[dt[U]] = de(n, c + U * 3, 7);
|
|
2456
|
+
c += L * 3;
|
|
2457
|
+
for (var O = ht(k), $ = (1 << O) - 1, D = xe(k, O, 1), U = 0; U < B; ) {
|
|
2458
|
+
var q = D[de(n, c, $)];
|
|
2459
|
+
c += q & 15;
|
|
2460
|
+
var i = q >> 4;
|
|
2461
|
+
if (i < 16)
|
|
2462
|
+
j[U++] = i;
|
|
2389
2463
|
else {
|
|
2390
|
-
var
|
|
2391
|
-
for (
|
|
2392
|
-
|
|
2464
|
+
var N = 0, P = 0;
|
|
2465
|
+
for (i == 16 ? (P = 3 + de(n, c, 3), c += 2, N = j[U - 1]) : i == 17 ? (P = 3 + de(n, c, 7), c += 3) : i == 18 && (P = 11 + de(n, c, 127), c += 7); P--; )
|
|
2466
|
+
j[U++] = N;
|
|
2393
2467
|
}
|
|
2394
2468
|
}
|
|
2395
|
-
var
|
|
2396
|
-
|
|
2469
|
+
var H = j.subarray(0, A), G = j.subarray(A);
|
|
2470
|
+
h = ht(H), u = ht(G), b = xe(H, h, 1), v = xe(G, u, 1);
|
|
2397
2471
|
} else
|
|
2398
|
-
|
|
2472
|
+
he(1);
|
|
2399
2473
|
else {
|
|
2400
|
-
var
|
|
2401
|
-
if (
|
|
2402
|
-
|
|
2474
|
+
var i = _t(c) + 4, S = n[i - 4] | n[i - 3] << 8, g = i + S;
|
|
2475
|
+
if (g > a) {
|
|
2476
|
+
y && he(0);
|
|
2403
2477
|
break;
|
|
2404
2478
|
}
|
|
2405
|
-
f &&
|
|
2479
|
+
f && d(p + S), t.set(n.subarray(i, g), p), e.b = p += S, e.p = c = g * 8, e.f = m;
|
|
2406
2480
|
continue;
|
|
2407
2481
|
}
|
|
2408
|
-
if (
|
|
2409
|
-
|
|
2482
|
+
if (c > w) {
|
|
2483
|
+
y && he(0);
|
|
2410
2484
|
break;
|
|
2411
2485
|
}
|
|
2412
2486
|
}
|
|
2413
|
-
f &&
|
|
2414
|
-
for (var
|
|
2415
|
-
var
|
|
2416
|
-
if (
|
|
2417
|
-
|
|
2487
|
+
f && d(p + 131072);
|
|
2488
|
+
for (var z = (1 << h) - 1, W = (1 << u) - 1, I = c; ; I = c) {
|
|
2489
|
+
var N = b[ut(n, c) & z], V = N >> 4;
|
|
2490
|
+
if (c += N & 15, c > w) {
|
|
2491
|
+
y && he(0);
|
|
2418
2492
|
break;
|
|
2419
2493
|
}
|
|
2420
|
-
if (
|
|
2421
|
-
t[
|
|
2422
|
-
else if (
|
|
2423
|
-
|
|
2494
|
+
if (N || he(2), V < 256)
|
|
2495
|
+
t[p++] = V;
|
|
2496
|
+
else if (V == 256) {
|
|
2497
|
+
I = c, b = null;
|
|
2424
2498
|
break;
|
|
2425
2499
|
} else {
|
|
2426
|
-
var
|
|
2427
|
-
if (
|
|
2428
|
-
var
|
|
2429
|
-
|
|
2500
|
+
var K = V - 254;
|
|
2501
|
+
if (V > 264) {
|
|
2502
|
+
var U = V - 257, x = et[U];
|
|
2503
|
+
K = de(n, c, (1 << x) - 1) + cn[U], c += x;
|
|
2430
2504
|
}
|
|
2431
|
-
var M =
|
|
2432
|
-
M ||
|
|
2433
|
-
var
|
|
2434
|
-
if (
|
|
2435
|
-
var
|
|
2436
|
-
|
|
2505
|
+
var M = v[ut(n, c) & W], T = M >> 4;
|
|
2506
|
+
M || he(3), c += M & 15;
|
|
2507
|
+
var G = lr[T];
|
|
2508
|
+
if (T > 3) {
|
|
2509
|
+
var x = tt[T];
|
|
2510
|
+
G += ut(n, c) & (1 << x) - 1, c += x;
|
|
2437
2511
|
}
|
|
2438
|
-
if (
|
|
2439
|
-
|
|
2512
|
+
if (c > w) {
|
|
2513
|
+
y && he(0);
|
|
2440
2514
|
break;
|
|
2441
2515
|
}
|
|
2442
|
-
f &&
|
|
2443
|
-
var
|
|
2444
|
-
if (
|
|
2445
|
-
var
|
|
2446
|
-
for (
|
|
2447
|
-
t[
|
|
2516
|
+
f && d(p + 131072);
|
|
2517
|
+
var _ = p + K;
|
|
2518
|
+
if (p < G) {
|
|
2519
|
+
var Y = s - G, X = Math.min(G, _);
|
|
2520
|
+
for (Y + p < 0 && he(3); p < X; ++p)
|
|
2521
|
+
t[p] = r[Y + p];
|
|
2448
2522
|
}
|
|
2449
|
-
for (;
|
|
2450
|
-
t[
|
|
2523
|
+
for (; p < _; ++p)
|
|
2524
|
+
t[p] = t[p - G];
|
|
2451
2525
|
}
|
|
2452
2526
|
}
|
|
2453
|
-
e.l =
|
|
2454
|
-
} while (!
|
|
2455
|
-
return
|
|
2456
|
-
},
|
|
2527
|
+
e.l = b, e.p = I, e.b = p, e.f = m, b && (m = 1, e.m = h, e.d = v, e.n = u);
|
|
2528
|
+
} while (!m);
|
|
2529
|
+
return p != t.length && l ? He(t, 0, p) : t.subarray(0, p);
|
|
2530
|
+
}, Me = function(n, e, t) {
|
|
2457
2531
|
t <<= e & 7;
|
|
2458
2532
|
var r = e / 8 | 0;
|
|
2459
2533
|
n[r] |= t, n[r + 1] |= t >> 8;
|
|
2460
|
-
},
|
|
2534
|
+
}, $e = function(n, e, t) {
|
|
2461
2535
|
t <<= e & 7;
|
|
2462
2536
|
var r = e / 8 | 0;
|
|
2463
2537
|
n[r] |= t, n[r + 1] |= t >> 8, n[r + 2] |= t >> 16;
|
|
2464
|
-
},
|
|
2538
|
+
}, ft = function(n, e) {
|
|
2465
2539
|
for (var t = [], r = 0; r < n.length; ++r)
|
|
2466
2540
|
n[r] && t.push({ s: r, f: n[r] });
|
|
2467
|
-
var a = t.length,
|
|
2541
|
+
var a = t.length, s = t.slice();
|
|
2468
2542
|
if (!a)
|
|
2469
|
-
return { t:
|
|
2543
|
+
return { t: fn, l: 0 };
|
|
2470
2544
|
if (a == 1) {
|
|
2471
|
-
var
|
|
2472
|
-
return
|
|
2545
|
+
var l = new ae(t[0].s + 1);
|
|
2546
|
+
return l[t[0].s] = 1, { t: l, l: 1 };
|
|
2473
2547
|
}
|
|
2474
|
-
t.sort(function(
|
|
2475
|
-
return
|
|
2548
|
+
t.sort(function(g, A) {
|
|
2549
|
+
return g.f - A.f;
|
|
2476
2550
|
}), t.push({ s: -1, f: 25001 });
|
|
2477
|
-
var f = t[0],
|
|
2478
|
-
for (t[0] = { s: -1, f: f.f +
|
|
2479
|
-
f = t[t[
|
|
2480
|
-
for (var
|
|
2481
|
-
|
|
2482
|
-
var
|
|
2483
|
-
if (
|
|
2484
|
-
var r = 0,
|
|
2485
|
-
for (
|
|
2486
|
-
return
|
|
2551
|
+
var f = t[0], y = t[1], d = 0, m = 1, c = 2;
|
|
2552
|
+
for (t[0] = { s: -1, f: f.f + y.f, l: f, r: y }; m != a - 1; )
|
|
2553
|
+
f = t[t[d].f < t[c].f ? d++ : c++], y = t[d != m && t[d].f < t[c].f ? d++ : c++], t[m++] = { s: -1, f: f.f + y.f, l: f, r: y };
|
|
2554
|
+
for (var p = s[0].s, r = 1; r < a; ++r)
|
|
2555
|
+
s[r].s > p && (p = s[r].s);
|
|
2556
|
+
var b = new fe(p + 1), v = vt(t[m - 1], b, 0);
|
|
2557
|
+
if (v > e) {
|
|
2558
|
+
var r = 0, h = 0, u = v - e, w = 1 << u;
|
|
2559
|
+
for (s.sort(function(A, L) {
|
|
2560
|
+
return b[L.s] - b[A.s] || A.f - L.f;
|
|
2487
2561
|
}); r < a; ++r) {
|
|
2488
|
-
var
|
|
2489
|
-
if (
|
|
2490
|
-
|
|
2562
|
+
var o = s[r].s;
|
|
2563
|
+
if (b[o] > e)
|
|
2564
|
+
h += w - (1 << v - b[o]), b[o] = e;
|
|
2491
2565
|
else
|
|
2492
2566
|
break;
|
|
2493
2567
|
}
|
|
2494
|
-
for (
|
|
2495
|
-
var
|
|
2496
|
-
|
|
2568
|
+
for (h >>= u; h > 0; ) {
|
|
2569
|
+
var i = s[r].s;
|
|
2570
|
+
b[i] < e ? h -= 1 << e - b[i]++ - 1 : ++r;
|
|
2497
2571
|
}
|
|
2498
|
-
for (; r >= 0 &&
|
|
2499
|
-
var
|
|
2500
|
-
|
|
2572
|
+
for (; r >= 0 && h; --r) {
|
|
2573
|
+
var S = s[r].s;
|
|
2574
|
+
b[S] == e && (--b[S], ++h);
|
|
2501
2575
|
}
|
|
2502
|
-
|
|
2576
|
+
v = e;
|
|
2503
2577
|
}
|
|
2504
|
-
return { t: new ae(
|
|
2505
|
-
},
|
|
2506
|
-
return n.s == -1 ? Math.max(
|
|
2507
|
-
},
|
|
2578
|
+
return { t: new ae(b), l: v };
|
|
2579
|
+
}, vt = function(n, e, t) {
|
|
2580
|
+
return n.s == -1 ? Math.max(vt(n.l, e, t + 1), vt(n.r, e, t + 1)) : e[n.s] = t;
|
|
2581
|
+
}, Vt = function(n) {
|
|
2508
2582
|
for (var e = n.length; e && !n[--e]; )
|
|
2509
2583
|
;
|
|
2510
|
-
for (var t = new
|
|
2511
|
-
t[r++] =
|
|
2584
|
+
for (var t = new fe(++e), r = 0, a = n[0], s = 1, l = function(y) {
|
|
2585
|
+
t[r++] = y;
|
|
2512
2586
|
}, f = 1; f <= e; ++f)
|
|
2513
2587
|
if (n[f] == a && f != e)
|
|
2514
|
-
++
|
|
2588
|
+
++s;
|
|
2515
2589
|
else {
|
|
2516
|
-
if (!a &&
|
|
2517
|
-
for (;
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
} else if (
|
|
2521
|
-
for (
|
|
2522
|
-
|
|
2523
|
-
|
|
2590
|
+
if (!a && s > 2) {
|
|
2591
|
+
for (; s > 138; s -= 138)
|
|
2592
|
+
l(32754);
|
|
2593
|
+
s > 2 && (l(s > 10 ? s - 11 << 5 | 28690 : s - 3 << 5 | 12305), s = 0);
|
|
2594
|
+
} else if (s > 3) {
|
|
2595
|
+
for (l(a), --s; s > 6; s -= 6)
|
|
2596
|
+
l(8304);
|
|
2597
|
+
s > 2 && (l(s - 3 << 5 | 8208), s = 0);
|
|
2524
2598
|
}
|
|
2525
|
-
for (;
|
|
2526
|
-
|
|
2527
|
-
|
|
2599
|
+
for (; s--; )
|
|
2600
|
+
l(a);
|
|
2601
|
+
s = 1, a = n[f];
|
|
2528
2602
|
}
|
|
2529
2603
|
return { c: t.subarray(0, r), n: e };
|
|
2530
|
-
},
|
|
2604
|
+
}, ze = function(n, e) {
|
|
2531
2605
|
for (var t = 0, r = 0; r < e.length; ++r)
|
|
2532
2606
|
t += n[r] * e[r];
|
|
2533
2607
|
return t;
|
|
2534
|
-
},
|
|
2535
|
-
var r = t.length, a =
|
|
2608
|
+
}, un = function(n, e, t) {
|
|
2609
|
+
var r = t.length, a = _t(e + 2);
|
|
2536
2610
|
n[a] = r & 255, n[a + 1] = r >> 8, n[a + 2] = n[a] ^ 255, n[a + 3] = n[a + 1] ^ 255;
|
|
2537
|
-
for (var
|
|
2538
|
-
n[a +
|
|
2611
|
+
for (var s = 0; s < r; ++s)
|
|
2612
|
+
n[a + s + 4] = t[s];
|
|
2539
2613
|
return (a + 4 + r) * 8;
|
|
2540
|
-
},
|
|
2541
|
-
|
|
2542
|
-
for (var
|
|
2543
|
-
++
|
|
2544
|
-
for (var
|
|
2545
|
-
++
|
|
2546
|
-
for (var
|
|
2614
|
+
}, qt = function(n, e, t, r, a, s, l, f, y, d, m) {
|
|
2615
|
+
Me(e, m++, t), ++a[256];
|
|
2616
|
+
for (var c = ft(a, 15), p = c.t, b = c.l, v = ft(s, 15), h = v.t, u = v.l, w = Vt(p), o = w.c, i = w.n, S = Vt(h), g = S.c, A = S.n, L = new fe(19), B = 0; B < o.length; ++B)
|
|
2617
|
+
++L[o[B] & 31];
|
|
2618
|
+
for (var B = 0; B < g.length; ++B)
|
|
2619
|
+
++L[g[B] & 31];
|
|
2620
|
+
for (var j = ft(L, 7), k = j.t, U = j.l, O = 19; O > 4 && !k[dt[O - 1]]; --O)
|
|
2547
2621
|
;
|
|
2548
|
-
var
|
|
2549
|
-
if (
|
|
2550
|
-
return
|
|
2551
|
-
var
|
|
2552
|
-
if (
|
|
2553
|
-
|
|
2554
|
-
var
|
|
2555
|
-
|
|
2556
|
-
for (var
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
for (var W = [
|
|
2560
|
-
for (var
|
|
2561
|
-
var
|
|
2562
|
-
|
|
2622
|
+
var $ = d + 5 << 3, D = ze(a, Te) + ze(s, De) + l, q = ze(a, p) + ze(s, h) + l + 14 + 3 * O + ze(L, k) + 2 * L[16] + 3 * L[17] + 7 * L[18];
|
|
2623
|
+
if (y >= 0 && $ <= D && $ <= q)
|
|
2624
|
+
return un(e, m, n.subarray(y, y + d));
|
|
2625
|
+
var N, P, H, G;
|
|
2626
|
+
if (Me(e, m, 1 + (q < D)), m += 2, q < D) {
|
|
2627
|
+
N = xe(p, b, 0), P = p, H = xe(h, u, 0), G = h;
|
|
2628
|
+
var z = xe(k, U, 0);
|
|
2629
|
+
Me(e, m, i - 257), Me(e, m + 5, A - 1), Me(e, m + 10, O - 4), m += 14;
|
|
2630
|
+
for (var B = 0; B < O; ++B)
|
|
2631
|
+
Me(e, m + 3 * B, k[dt[B]]);
|
|
2632
|
+
m += 3 * O;
|
|
2633
|
+
for (var W = [o, g], I = 0; I < 2; ++I)
|
|
2634
|
+
for (var V = W[I], B = 0; B < V.length; ++B) {
|
|
2635
|
+
var K = V[B] & 31;
|
|
2636
|
+
Me(e, m, z[K]), m += k[K], K > 15 && (Me(e, m, V[B] >> 5 & 127), m += V[B] >> 12);
|
|
2563
2637
|
}
|
|
2564
2638
|
} else
|
|
2565
|
-
|
|
2566
|
-
for (var
|
|
2567
|
-
var
|
|
2568
|
-
if (
|
|
2569
|
-
var
|
|
2570
|
-
|
|
2571
|
-
var M =
|
|
2572
|
-
|
|
2639
|
+
N = cr, P = Te, H = ur, G = De;
|
|
2640
|
+
for (var B = 0; B < f; ++B) {
|
|
2641
|
+
var x = r[B];
|
|
2642
|
+
if (x > 255) {
|
|
2643
|
+
var K = x >> 18 & 31;
|
|
2644
|
+
$e(e, m, N[K + 257]), m += P[K + 257], K > 7 && (Me(e, m, x >> 23 & 31), m += et[K]);
|
|
2645
|
+
var M = x & 31;
|
|
2646
|
+
$e(e, m, H[M]), m += G[M], M > 3 && ($e(e, m, x >> 5 & 8191), m += tt[M]);
|
|
2573
2647
|
} else
|
|
2574
|
-
|
|
2648
|
+
$e(e, m, N[x]), m += P[x];
|
|
2575
2649
|
}
|
|
2576
|
-
return
|
|
2577
|
-
},
|
|
2578
|
-
var
|
|
2650
|
+
return $e(e, m, N[256]), m + P[256];
|
|
2651
|
+
}, dr = /* @__PURE__ */ new Lt([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]), fn = /* @__PURE__ */ new ae(0), gr = function(n, e, t, r, a, s) {
|
|
2652
|
+
var l = s.z || n.length, f = new ae(r + l + 5 * (1 + Math.ceil(l / 7e3)) + a), y = f.subarray(r, f.length - a), d = s.l, m = (s.r || 0) & 7;
|
|
2579
2653
|
if (e) {
|
|
2580
|
-
|
|
2581
|
-
for (var
|
|
2582
|
-
return (n[
|
|
2583
|
-
},
|
|
2584
|
-
var
|
|
2585
|
-
if (
|
|
2586
|
-
var
|
|
2587
|
-
if ((
|
|
2588
|
-
|
|
2589
|
-
for (var
|
|
2590
|
-
|
|
2591
|
-
for (var
|
|
2592
|
-
|
|
2654
|
+
m && (y[0] = s.r >> 3);
|
|
2655
|
+
for (var c = dr[e - 1], p = c >> 13, b = c & 8191, v = (1 << t) - 1, h = s.p || new fe(32768), u = s.h || new fe(v + 1), w = Math.ceil(t / 3), o = 2 * w, i = function(E) {
|
|
2656
|
+
return (n[E] ^ n[E + 1] << w ^ n[E + 2] << o) & v;
|
|
2657
|
+
}, S = new Lt(25e3), g = new fe(288), A = new fe(32), L = 0, B = 0, j = s.i || 0, k = 0, U = s.w || 0, O = 0; j + 2 < l; ++j) {
|
|
2658
|
+
var $ = i(j), D = j & 32767, q = u[$];
|
|
2659
|
+
if (h[D] = q, u[$] = D, U <= j) {
|
|
2660
|
+
var N = l - j;
|
|
2661
|
+
if ((L > 7e3 || k > 24576) && (N > 423 || !d)) {
|
|
2662
|
+
m = qt(n, y, 0, S, g, A, B, k, O, j - O, m), k = L = B = 0, O = j;
|
|
2663
|
+
for (var P = 0; P < 286; ++P)
|
|
2664
|
+
g[P] = 0;
|
|
2665
|
+
for (var P = 0; P < 30; ++P)
|
|
2666
|
+
A[P] = 0;
|
|
2593
2667
|
}
|
|
2594
|
-
var
|
|
2595
|
-
if (
|
|
2596
|
-
for (var
|
|
2597
|
-
if (n[
|
|
2598
|
-
for (var
|
|
2668
|
+
var H = 2, G = 0, z = b, W = D - q & 32767;
|
|
2669
|
+
if (N > 2 && $ == i(j - W))
|
|
2670
|
+
for (var I = Math.min(p, N) - 1, V = Math.min(32767, j), K = Math.min(258, N); W <= V && --z && D != q; ) {
|
|
2671
|
+
if (n[j + H] == n[j + H - W]) {
|
|
2672
|
+
for (var x = 0; x < K && n[j + x] == n[j + x - W]; ++x)
|
|
2599
2673
|
;
|
|
2600
|
-
if (
|
|
2601
|
-
if (
|
|
2674
|
+
if (x > H) {
|
|
2675
|
+
if (H = x, G = W, x > I)
|
|
2602
2676
|
break;
|
|
2603
|
-
for (var M = Math.min(W,
|
|
2604
|
-
var
|
|
2605
|
-
X >
|
|
2677
|
+
for (var M = Math.min(W, x - 2), T = 0, P = 0; P < M; ++P) {
|
|
2678
|
+
var _ = j - W + P & 32767, Y = h[_], X = _ - Y & 32767;
|
|
2679
|
+
X > T && (T = X, q = _);
|
|
2606
2680
|
}
|
|
2607
2681
|
}
|
|
2608
2682
|
}
|
|
2609
|
-
D =
|
|
2683
|
+
D = q, q = h[D], W += D - q & 32767;
|
|
2610
2684
|
}
|
|
2611
|
-
if (
|
|
2612
|
-
|
|
2613
|
-
var
|
|
2614
|
-
|
|
2685
|
+
if (G) {
|
|
2686
|
+
S[k++] = 268435456 | gt[H] << 18 | Gt[G];
|
|
2687
|
+
var F = gt[H] & 31, C = Gt[G] & 31;
|
|
2688
|
+
B += et[F] + tt[C], ++g[257 + F], ++A[C], U = j + H, ++L;
|
|
2615
2689
|
} else
|
|
2616
|
-
|
|
2690
|
+
S[k++] = n[j], ++g[n[j]];
|
|
2617
2691
|
}
|
|
2618
2692
|
}
|
|
2619
|
-
for (
|
|
2620
|
-
|
|
2621
|
-
|
|
2693
|
+
for (j = Math.max(j, U); j < l; ++j)
|
|
2694
|
+
S[k++] = n[j], ++g[n[j]];
|
|
2695
|
+
m = qt(n, y, d, S, g, A, B, k, O, j - O, m), d || (s.r = m & 7 | y[m / 8 | 0] << 3, m -= 7, s.h = u, s.p = h, s.i = j, s.w = U);
|
|
2622
2696
|
} else {
|
|
2623
|
-
for (var
|
|
2624
|
-
var
|
|
2625
|
-
|
|
2697
|
+
for (var j = s.w || 0; j < l + d; j += 65535) {
|
|
2698
|
+
var Z = j + 65535;
|
|
2699
|
+
Z >= l && (y[m / 8 | 0] = d, Z = l), m = un(y, m + 1, n.subarray(j, Z));
|
|
2626
2700
|
}
|
|
2627
|
-
|
|
2701
|
+
s.i = l;
|
|
2628
2702
|
}
|
|
2629
|
-
return
|
|
2630
|
-
},
|
|
2703
|
+
return He(f, 0, r + _t(m) + a);
|
|
2704
|
+
}, yr = /* @__PURE__ */ (function() {
|
|
2631
2705
|
for (var n = new Int32Array(256), e = 0; e < 256; ++e) {
|
|
2632
2706
|
for (var t = e, r = 9; --r; )
|
|
2633
2707
|
t = (t & 1 && -306674912) ^ t >>> 1;
|
|
2634
2708
|
n[e] = t;
|
|
2635
2709
|
}
|
|
2636
2710
|
return n;
|
|
2637
|
-
})(),
|
|
2711
|
+
})(), vr = function() {
|
|
2638
2712
|
var n = -1;
|
|
2639
2713
|
return {
|
|
2640
2714
|
p: function(e) {
|
|
2641
2715
|
for (var t = n, r = 0; r < e.length; ++r)
|
|
2642
|
-
t =
|
|
2716
|
+
t = yr[t & 255 ^ e[r]] ^ t >>> 8;
|
|
2643
2717
|
n = t;
|
|
2644
2718
|
},
|
|
2645
2719
|
d: function() {
|
|
2646
2720
|
return ~n;
|
|
2647
2721
|
}
|
|
2648
2722
|
};
|
|
2649
|
-
},
|
|
2723
|
+
}, br = function(n, e, t, r, a) {
|
|
2650
2724
|
if (!a && (a = { l: 1 }, e.dictionary)) {
|
|
2651
|
-
var
|
|
2652
|
-
|
|
2725
|
+
var s = e.dictionary.subarray(-32768), l = new ae(s.length + n.length);
|
|
2726
|
+
l.set(s), l.set(n, s.length), n = l, a.w = s.length;
|
|
2653
2727
|
}
|
|
2654
|
-
return
|
|
2655
|
-
},
|
|
2728
|
+
return gr(n, e.level == null ? 6 : e.level, e.mem == null ? a.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(n.length))) * 1.5) : 20 : 12 + e.mem, t, r, a);
|
|
2729
|
+
}, mn = function(n, e) {
|
|
2656
2730
|
var t = {};
|
|
2657
2731
|
for (var r in n)
|
|
2658
2732
|
t[r] = n[r];
|
|
@@ -2661,337 +2735,341 @@ var or = /* @__PURE__ */ xe(Oe, 9, 0), sr = /* @__PURE__ */ xe(Oe, 9, 1), ir = /
|
|
|
2661
2735
|
return t;
|
|
2662
2736
|
}, be = function(n, e) {
|
|
2663
2737
|
return n[e] | n[e + 1] << 8;
|
|
2664
|
-
},
|
|
2738
|
+
}, me = function(n, e) {
|
|
2665
2739
|
return (n[e] | n[e + 1] << 8 | n[e + 2] << 16 | n[e + 3] << 24) >>> 0;
|
|
2666
|
-
},
|
|
2667
|
-
return
|
|
2668
|
-
},
|
|
2740
|
+
}, mt = function(n, e) {
|
|
2741
|
+
return me(n, e) + me(n, e + 4) * 4294967296;
|
|
2742
|
+
}, ie = function(n, e, t) {
|
|
2669
2743
|
for (; t; ++e)
|
|
2670
2744
|
n[e] = t, t >>>= 8;
|
|
2671
2745
|
};
|
|
2672
|
-
function
|
|
2673
|
-
return
|
|
2746
|
+
function xr(n, e) {
|
|
2747
|
+
return br(n, e || {}, 0, 0);
|
|
2674
2748
|
}
|
|
2675
|
-
function
|
|
2676
|
-
return
|
|
2749
|
+
function wr(n, e) {
|
|
2750
|
+
return pr(n, { i: 2 }, e && e.out, e && e.dictionary);
|
|
2677
2751
|
}
|
|
2678
|
-
var
|
|
2752
|
+
var pn = function(n, e, t, r) {
|
|
2679
2753
|
for (var a in n) {
|
|
2680
|
-
var
|
|
2681
|
-
Array.isArray(
|
|
2754
|
+
var s = n[a], l = e + a, f = r;
|
|
2755
|
+
Array.isArray(s) && (f = mn(r, s[1]), s = s[0]), ArrayBuffer.isView(s) ? t[l] = [s, f] : (t[l += "/"] = [new ae(0), f], pn(s, l, t, r));
|
|
2682
2756
|
}
|
|
2683
|
-
},
|
|
2757
|
+
}, Jt = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), bt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), Ar = 0;
|
|
2684
2758
|
try {
|
|
2685
|
-
|
|
2759
|
+
bt.decode(fn, { stream: !0 }), Ar = 1;
|
|
2686
2760
|
} catch {
|
|
2687
2761
|
}
|
|
2688
|
-
var
|
|
2762
|
+
var Mr = function(n) {
|
|
2689
2763
|
for (var e = "", t = 0; ; ) {
|
|
2690
2764
|
var r = n[t++], a = (r > 127) + (r > 223) + (r > 239);
|
|
2691
2765
|
if (t + a > n.length)
|
|
2692
|
-
return { s: e, r:
|
|
2766
|
+
return { s: e, r: He(n, t - 1) };
|
|
2693
2767
|
a ? a == 3 ? (r = ((r & 15) << 18 | (n[t++] & 63) << 12 | (n[t++] & 63) << 6 | n[t++] & 63) - 65536, e += String.fromCharCode(55296 | r >> 10, 56320 | r & 1023)) : a & 1 ? e += String.fromCharCode((r & 31) << 6 | n[t++] & 63) : e += String.fromCharCode((r & 15) << 12 | (n[t++] & 63) << 6 | n[t++] & 63) : e += String.fromCharCode(r);
|
|
2694
2768
|
}
|
|
2695
2769
|
};
|
|
2696
|
-
function
|
|
2770
|
+
function Kt(n, e) {
|
|
2697
2771
|
var t;
|
|
2698
|
-
if (
|
|
2699
|
-
return
|
|
2700
|
-
for (var r = n.length, a = new ae(n.length + (n.length >> 1)),
|
|
2701
|
-
a[
|
|
2772
|
+
if (Jt)
|
|
2773
|
+
return Jt.encode(n);
|
|
2774
|
+
for (var r = n.length, a = new ae(n.length + (n.length >> 1)), s = 0, l = function(d) {
|
|
2775
|
+
a[s++] = d;
|
|
2702
2776
|
}, t = 0; t < r; ++t) {
|
|
2703
|
-
if (
|
|
2704
|
-
var f = new ae(
|
|
2777
|
+
if (s + 5 > a.length) {
|
|
2778
|
+
var f = new ae(s + 8 + (r - t << 1));
|
|
2705
2779
|
f.set(a), a = f;
|
|
2706
2780
|
}
|
|
2707
|
-
var
|
|
2708
|
-
|
|
2781
|
+
var y = n.charCodeAt(t);
|
|
2782
|
+
y < 128 || e ? l(y) : y < 2048 ? (l(192 | y >> 6), l(128 | y & 63)) : y > 55295 && y < 57344 ? (y = 65536 + (y & 1047552) | n.charCodeAt(++t) & 1023, l(240 | y >> 18), l(128 | y >> 12 & 63), l(128 | y >> 6 & 63), l(128 | y & 63)) : (l(224 | y >> 12), l(128 | y >> 6 & 63), l(128 | y & 63));
|
|
2709
2783
|
}
|
|
2710
|
-
return
|
|
2784
|
+
return He(a, 0, s);
|
|
2711
2785
|
}
|
|
2712
|
-
function
|
|
2786
|
+
function Er(n, e) {
|
|
2713
2787
|
if (e) {
|
|
2714
2788
|
for (var t = "", r = 0; r < n.length; r += 16384)
|
|
2715
2789
|
t += String.fromCharCode.apply(null, n.subarray(r, r + 16384));
|
|
2716
2790
|
return t;
|
|
2717
2791
|
} else {
|
|
2718
|
-
if (
|
|
2719
|
-
return
|
|
2720
|
-
var a =
|
|
2721
|
-
return t.length &&
|
|
2792
|
+
if (bt)
|
|
2793
|
+
return bt.decode(n);
|
|
2794
|
+
var a = Mr(n), s = a.s, t = a.r;
|
|
2795
|
+
return t.length && he(8), s;
|
|
2722
2796
|
}
|
|
2723
2797
|
}
|
|
2724
|
-
var
|
|
2798
|
+
var Sr = function(n, e) {
|
|
2725
2799
|
return e + 30 + be(n, e + 26) + be(n, e + 28);
|
|
2726
|
-
},
|
|
2727
|
-
var r = be(n, e + 28), a = be(n, e + 30),
|
|
2728
|
-
return [be(n, e + 10),
|
|
2729
|
-
},
|
|
2730
|
-
var f = a == 4294967295,
|
|
2731
|
-
if (r &&
|
|
2732
|
-
for (; e + 4 <
|
|
2800
|
+
}, Tr = function(n, e, t) {
|
|
2801
|
+
var r = be(n, e + 28), a = be(n, e + 30), s = Er(n.subarray(e + 46, e + 46 + r), !(be(n, e + 8) & 2048)), l = e + 46 + r, f = Or(n, l, a, t, me(n, e + 20), me(n, e + 24), me(n, e + 42)), y = f[0], d = f[1], m = f[2];
|
|
2802
|
+
return [be(n, e + 10), y, d, s, l + a + be(n, e + 32), m];
|
|
2803
|
+
}, Or = function(n, e, t, r, a, s, l) {
|
|
2804
|
+
var f = a == 4294967295, y = s == 4294967295, d = l == 4294967295, m = e + t, c = f + y + d;
|
|
2805
|
+
if (r && c) {
|
|
2806
|
+
for (; e + 4 < m; e += 4 + be(n, e + 2))
|
|
2733
2807
|
if (be(n, e) == 1)
|
|
2734
2808
|
return [
|
|
2735
|
-
f ?
|
|
2736
|
-
|
|
2737
|
-
|
|
2809
|
+
f ? mt(n, e + 4 + 8 * y) : a,
|
|
2810
|
+
y ? mt(n, e + 4) : s,
|
|
2811
|
+
d ? mt(n, e + 4 + 8 * (y + f)) : l,
|
|
2738
2812
|
1
|
|
2739
2813
|
];
|
|
2740
|
-
r < 2 &&
|
|
2814
|
+
r < 2 && he(13);
|
|
2741
2815
|
}
|
|
2742
|
-
return [a,
|
|
2743
|
-
},
|
|
2816
|
+
return [a, s, l, 0];
|
|
2817
|
+
}, xt = function(n) {
|
|
2744
2818
|
var e = 0;
|
|
2745
2819
|
if (n)
|
|
2746
2820
|
for (var t in n) {
|
|
2747
2821
|
var r = n[t].length;
|
|
2748
|
-
r > 65535 &&
|
|
2822
|
+
r > 65535 && he(9), e += r + 4;
|
|
2749
2823
|
}
|
|
2750
2824
|
return e;
|
|
2751
|
-
},
|
|
2752
|
-
var
|
|
2753
|
-
|
|
2754
|
-
var
|
|
2755
|
-
if ((
|
|
2756
|
-
for (var
|
|
2757
|
-
var
|
|
2758
|
-
|
|
2759
|
-
}
|
|
2760
|
-
return
|
|
2761
|
-
},
|
|
2762
|
-
|
|
2825
|
+
}, Qt = function(n, e, t, r, a, s, l, f) {
|
|
2826
|
+
var y = r.length, d = t.extra, m = f && f.length, c = xt(d);
|
|
2827
|
+
ie(n, e, l != null ? 33639248 : 67324752), e += 4, l != null && (n[e++] = 20, n[e++] = t.os), n[e] = 20, e += 2, n[e++] = t.flag << 1 | (s < 0 && 8), n[e++] = a && 8, n[e++] = t.compression & 255, n[e++] = t.compression >> 8;
|
|
2828
|
+
var p = new Date(t.mtime == null ? Date.now() : t.mtime), b = p.getFullYear() - 1980;
|
|
2829
|
+
if ((b < 0 || b > 119) && he(10), ie(n, e, b << 25 | p.getMonth() + 1 << 21 | p.getDate() << 16 | p.getHours() << 11 | p.getMinutes() << 5 | p.getSeconds() >> 1), e += 4, s != -1 && (ie(n, e, t.crc), ie(n, e + 4, s < 0 ? -s - 2 : s), ie(n, e + 8, t.size)), ie(n, e + 12, y), ie(n, e + 14, c), e += 16, l != null && (ie(n, e, m), ie(n, e + 6, t.attrs), ie(n, e + 10, l), e += 14), n.set(r, e), e += y, c)
|
|
2830
|
+
for (var v in d) {
|
|
2831
|
+
var h = d[v], u = h.length;
|
|
2832
|
+
ie(n, e, +v), ie(n, e + 2, u), n.set(h, e + 4), e += 4 + u;
|
|
2833
|
+
}
|
|
2834
|
+
return m && (n.set(f, e), e += m), e;
|
|
2835
|
+
}, Rr = function(n, e, t, r, a) {
|
|
2836
|
+
ie(n, e, 101010256), ie(n, e + 8, t), ie(n, e + 10, t), ie(n, e + 12, r), ie(n, e + 16, a);
|
|
2763
2837
|
};
|
|
2764
|
-
function
|
|
2838
|
+
function Lr(n, e) {
|
|
2765
2839
|
e || (e = {});
|
|
2766
2840
|
var t = {}, r = [];
|
|
2767
|
-
|
|
2768
|
-
var a = 0,
|
|
2769
|
-
for (var
|
|
2770
|
-
var f = t[
|
|
2771
|
-
|
|
2772
|
-
var
|
|
2773
|
-
|
|
2774
|
-
size:
|
|
2775
|
-
crc:
|
|
2776
|
-
c:
|
|
2777
|
-
f:
|
|
2778
|
-
m:
|
|
2779
|
-
u:
|
|
2841
|
+
pn(n, "", t, e);
|
|
2842
|
+
var a = 0, s = 0;
|
|
2843
|
+
for (var l in t) {
|
|
2844
|
+
var f = t[l], y = f[0], d = f[1], m = d.level == 0 ? 0 : 8, c = Kt(l), p = c.length, b = d.comment, v = b && Kt(b), h = v && v.length, u = xt(d.extra);
|
|
2845
|
+
p > 65535 && he(11);
|
|
2846
|
+
var w = m ? xr(y, d) : y, o = w.length, i = vr();
|
|
2847
|
+
i.p(y), r.push(mn(d, {
|
|
2848
|
+
size: y.length,
|
|
2849
|
+
crc: i.d(),
|
|
2850
|
+
c: w,
|
|
2851
|
+
f: c,
|
|
2852
|
+
m: v,
|
|
2853
|
+
u: p != l.length || v && b.length != h,
|
|
2780
2854
|
o: a,
|
|
2781
|
-
compression:
|
|
2782
|
-
})), a += 30 +
|
|
2855
|
+
compression: m
|
|
2856
|
+
})), a += 30 + p + u + o, s += 76 + 2 * (p + u) + (h || 0) + o;
|
|
2783
2857
|
}
|
|
2784
|
-
for (var
|
|
2785
|
-
var
|
|
2786
|
-
|
|
2787
|
-
var
|
|
2788
|
-
|
|
2858
|
+
for (var S = new ae(s + 22), g = a, A = s - a, L = 0; L < r.length; ++L) {
|
|
2859
|
+
var c = r[L];
|
|
2860
|
+
Qt(S, c.o, c, c.f, c.u, c.c.length);
|
|
2861
|
+
var B = 30 + c.f.length + xt(c.extra);
|
|
2862
|
+
S.set(c.c, c.o + B), Qt(S, a, c, c.f, c.u, c.c.length, c.o, c.m), a += 16 + B + (c.m ? c.m.length : 0);
|
|
2789
2863
|
}
|
|
2790
|
-
return
|
|
2864
|
+
return Rr(S, a, r.length, A, g), S;
|
|
2791
2865
|
}
|
|
2792
|
-
function
|
|
2793
|
-
for (var t = {}, r = n.length - 22;
|
|
2794
|
-
(!r || n.length - r > 65558) &&
|
|
2866
|
+
function _r(n, e) {
|
|
2867
|
+
for (var t = {}, r = n.length - 22; me(n, r) != 101010256; --r)
|
|
2868
|
+
(!r || n.length - r > 65558) && he(13);
|
|
2795
2869
|
var a = be(n, r + 8);
|
|
2796
2870
|
if (!a)
|
|
2797
2871
|
return {};
|
|
2798
|
-
var
|
|
2799
|
-
if (
|
|
2800
|
-
var f =
|
|
2801
|
-
|
|
2802
|
-
}
|
|
2803
|
-
for (var
|
|
2804
|
-
var
|
|
2805
|
-
|
|
2806
|
-
name:
|
|
2807
|
-
size:
|
|
2808
|
-
originalSize:
|
|
2809
|
-
compression:
|
|
2810
|
-
})) && (
|
|
2872
|
+
var s = me(n, r + 16), l = me(n, r - 20) == 117853008;
|
|
2873
|
+
if (l) {
|
|
2874
|
+
var f = me(n, r - 12);
|
|
2875
|
+
l = me(n, f) == 101075792, l && (a = me(n, f + 32), s = me(n, f + 48));
|
|
2876
|
+
}
|
|
2877
|
+
for (var y = e && e.filter, d = 0; d < a; ++d) {
|
|
2878
|
+
var m = Tr(n, s, l), c = m[0], p = m[1], b = m[2], v = m[3], h = m[4], u = m[5], w = Sr(n, u);
|
|
2879
|
+
s = h, (!y || y({
|
|
2880
|
+
name: v,
|
|
2881
|
+
size: p,
|
|
2882
|
+
originalSize: b,
|
|
2883
|
+
compression: c
|
|
2884
|
+
})) && (c ? c == 8 ? t[v] = wr(n.subarray(w, w + p), { out: new ae(b) }) : he(14, "unknown compression type " + c) : t[v] = He(n, w, w + p));
|
|
2811
2885
|
}
|
|
2812
2886
|
return t;
|
|
2813
2887
|
}
|
|
2814
|
-
const
|
|
2815
|
-
function
|
|
2888
|
+
const Qe = 200, wt = 64 * 1024 * 1024, At = new TextDecoder("utf-8", { fatal: !0 });
|
|
2889
|
+
function kt(n) {
|
|
2816
2890
|
if (!n || n.startsWith("/") || /^[A-Za-z]:/.test(n) || n.includes("\\") || n.includes("\0") || n.split("/").includes(".."))
|
|
2817
2891
|
throw new Error(`ZIP entry ${JSON.stringify(n)}: path must be relative, without .. or backslashes`);
|
|
2818
2892
|
}
|
|
2819
|
-
function
|
|
2820
|
-
const e = new DataView(n.buffer, n.byteOffset, n.byteLength), t = (
|
|
2821
|
-
throw new Error(`ZIP entry ${JSON.stringify(
|
|
2822
|
-
}, r = (
|
|
2823
|
-
let
|
|
2824
|
-
for (;
|
|
2893
|
+
function Mt(n) {
|
|
2894
|
+
const e = new DataView(n.buffer, n.byteOffset, n.byteLength), t = (p = "(archive)") => {
|
|
2895
|
+
throw new Error(`ZIP entry ${JSON.stringify(p)}: invalid or truncated ZIP`);
|
|
2896
|
+
}, r = (p) => p >= 0 && p + 2 <= n.length ? e.getUint16(p, !0) : t(), a = (p) => p >= 0 && p + 4 <= n.length ? e.getUint32(p, !0) : t();
|
|
2897
|
+
let s = n.length - 22;
|
|
2898
|
+
for (; s >= Math.max(0, n.length - 65557) && !(a(s) === 101010256 && s + 22 + r(s + 20) === n.length); s--)
|
|
2825
2899
|
;
|
|
2826
|
-
(
|
|
2827
|
-
const
|
|
2828
|
-
|
|
2829
|
-
const
|
|
2830
|
-
let
|
|
2831
|
-
for (let
|
|
2832
|
-
(
|
|
2833
|
-
const
|
|
2834
|
-
|
|
2835
|
-
let
|
|
2900
|
+
(s < 0 || s < n.length - 65557) && t(), (r(s + 4) || r(s + 6) || r(s + 8) !== r(s + 10)) && t();
|
|
2901
|
+
const l = r(s + 10), f = a(s + 16), y = f + a(s + 12);
|
|
2902
|
+
y !== s && t();
|
|
2903
|
+
const d = [], m = /* @__PURE__ */ new Set();
|
|
2904
|
+
let c = f;
|
|
2905
|
+
for (let p = 0; p < l; p++) {
|
|
2906
|
+
(c + 46 > y || a(c) !== 33639248) && t();
|
|
2907
|
+
const b = r(c + 28), v = c + 46 + b + r(c + 30) + r(c + 32);
|
|
2908
|
+
v > y && t();
|
|
2909
|
+
let h;
|
|
2836
2910
|
try {
|
|
2837
|
-
|
|
2911
|
+
h = At.decode(n.subarray(c + 46, c + 46 + b));
|
|
2838
2912
|
} catch {
|
|
2839
2913
|
throw new Error("ZIP entry (invalid UTF-8 name): invalid filename");
|
|
2840
2914
|
}
|
|
2841
|
-
if (
|
|
2842
|
-
if (
|
|
2843
|
-
|
|
2844
|
-
const
|
|
2845
|
-
if (
|
|
2846
|
-
if (r(
|
|
2847
|
-
if (r(
|
|
2848
|
-
(
|
|
2849
|
-
const
|
|
2850
|
-
(
|
|
2851
|
-
let
|
|
2915
|
+
if (kt(h), p >= Qe) throw new Error(`ZIP entry ${JSON.stringify(h)}: more than ${Qe} entries`);
|
|
2916
|
+
if (m.has(h)) throw new Error(`ZIP entry ${JSON.stringify(h)}: duplicate entry`);
|
|
2917
|
+
m.add(h);
|
|
2918
|
+
const u = a(c + 24), w = a(c + 20), o = a(c + 42);
|
|
2919
|
+
if (u > wt || w > wt) throw new Error(`ZIP entry ${JSON.stringify(h)}: exceeds 64 MB`);
|
|
2920
|
+
if (r(c + 10) !== 0) throw new Error(`ZIP entry ${JSON.stringify(h)}: expected stored compression (method 0)`);
|
|
2921
|
+
if (r(c + 8) & 1) throw new Error(`ZIP entry ${JSON.stringify(h)}: encrypted entries are not supported`);
|
|
2922
|
+
(w !== u || o + 30 > f || a(o) !== 67324752) && t(h);
|
|
2923
|
+
const i = o + 30 + r(o + 26) + r(o + 28);
|
|
2924
|
+
(i + u > f || r(o + 8) !== 0 || r(o + 6) !== r(c + 8)) && t(h);
|
|
2925
|
+
let S;
|
|
2852
2926
|
try {
|
|
2853
|
-
|
|
2927
|
+
S = At.decode(n.subarray(o + 30, o + 30 + r(o + 26)));
|
|
2854
2928
|
} catch {
|
|
2855
|
-
t(
|
|
2929
|
+
t(h);
|
|
2856
2930
|
}
|
|
2857
|
-
|
|
2931
|
+
S !== h && t(h), d.push({ name: h, offset: o, start: i, size: u, central: c }), c = v;
|
|
2858
2932
|
}
|
|
2859
|
-
return
|
|
2933
|
+
return c !== y && t(), { files: d };
|
|
2860
2934
|
}
|
|
2861
|
-
function
|
|
2862
|
-
const e = n instanceof Uint8Array ? n : new Uint8Array(n), t =
|
|
2863
|
-
for (const
|
|
2864
|
-
const
|
|
2865
|
-
if (!(
|
|
2866
|
-
a[
|
|
2935
|
+
function kr(n) {
|
|
2936
|
+
const e = n instanceof Uint8Array ? n : new Uint8Array(n), t = Mt(e), r = _r(e, { filter: (s) => s.name !== "__proto__" }), a = /* @__PURE__ */ Object.create(null);
|
|
2937
|
+
for (const s of t.files) {
|
|
2938
|
+
const l = s.name === "__proto__" ? e.slice(s.start, s.start + s.size) : r[s.name];
|
|
2939
|
+
if (!(l instanceof Uint8Array) || l.length !== s.size) throw new Error(`ZIP entry ${JSON.stringify(s.name)}: invalid size`);
|
|
2940
|
+
a[s.name] = l;
|
|
2867
2941
|
}
|
|
2868
2942
|
return a;
|
|
2869
2943
|
}
|
|
2870
|
-
function
|
|
2871
|
-
const t = Object.hasOwn(n, "avatar.json") ? n["avatar.json"] : void 0, r = t ?
|
|
2872
|
-
`),
|
|
2873
|
-
|
|
2874
|
-
for (const [
|
|
2875
|
-
for (const [
|
|
2876
|
-
if (
|
|
2877
|
-
if (
|
|
2878
|
-
}
|
|
2879
|
-
const
|
|
2880
|
-
if (
|
|
2944
|
+
function jr(n, e = {}) {
|
|
2945
|
+
const t = Object.hasOwn(n, "avatar.json") ? n["avatar.json"] : void 0, r = t ? Ye(JSON.parse(At.decode(t))) : an("Avatar"), a = t && !e.manifest ? t : new TextEncoder().encode(JSON.stringify(Ye({ ...r, ...e.manifest }), null, 2) + `
|
|
2946
|
+
`), s = /* @__PURE__ */ Object.create(null);
|
|
2947
|
+
s["avatar.json"] = a;
|
|
2948
|
+
for (const [p, b] of Object.entries(n)) p !== "avatar.json" && (s[p] = b);
|
|
2949
|
+
for (const [p, [b, v]] of Object.entries(s).entries()) {
|
|
2950
|
+
if (kt(b), p >= Qe) throw new Error(`ZIP entry ${JSON.stringify(b)}: more than ${Qe} entries`);
|
|
2951
|
+
if (v.byteLength > wt) throw new Error(`ZIP entry ${JSON.stringify(b)}: exceeds 64 MB`);
|
|
2952
|
+
}
|
|
2953
|
+
const l = on(s);
|
|
2954
|
+
if (l.length) throw new Error(l.join(`
|
|
2881
2955
|
`));
|
|
2882
2956
|
let f = "proto0000";
|
|
2883
|
-
for (let
|
|
2884
|
-
const
|
|
2885
|
-
if (Object.hasOwn(
|
|
2886
|
-
const
|
|
2887
|
-
|
|
2888
|
-
}
|
|
2889
|
-
const
|
|
2890
|
-
if (
|
|
2891
|
-
const
|
|
2892
|
-
|
|
2893
|
-
const
|
|
2894
|
-
for (const
|
|
2895
|
-
return
|
|
2896
|
-
}
|
|
2897
|
-
return
|
|
2957
|
+
for (let p = 0; Object.hasOwn(s, f); p++) f = `proto${String(p + 1).padStart(4, "0")}`;
|
|
2958
|
+
const y = Object.fromEntries(Object.entries(s).map(([p, b]) => [p === "__proto__" ? f : p, b])), d = Lr(y, { level: 0 });
|
|
2959
|
+
if (Object.hasOwn(s, "__proto__")) {
|
|
2960
|
+
const p = Mt(d).files.find((v) => v.name === f), b = new TextEncoder().encode("__proto__");
|
|
2961
|
+
d.set(b, p.offset + 30), d.set(b, p.central + 46);
|
|
2962
|
+
}
|
|
2963
|
+
const m = Mt(d), c = m.files.find((p) => p.name === "avatar.json");
|
|
2964
|
+
if (c.offset !== 0) {
|
|
2965
|
+
const p = c.start + c.size - c.offset, b = new Uint8Array(d.length);
|
|
2966
|
+
b.set(d.subarray(c.offset, c.offset + p)), b.set(d.subarray(0, c.offset), p), b.set(d.subarray(c.offset + p), c.offset + p);
|
|
2967
|
+
const v = new DataView(b.buffer);
|
|
2968
|
+
for (const h of m.files) v.setUint32(h.central + 42, h === c ? 0 : h.offset < c.offset ? h.offset + p : h.offset, !0);
|
|
2969
|
+
return b;
|
|
2970
|
+
}
|
|
2971
|
+
return d;
|
|
2898
2972
|
}
|
|
2899
|
-
const
|
|
2900
|
-
function
|
|
2973
|
+
const Fr = (n) => JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(n));
|
|
2974
|
+
function Be(n, e) {
|
|
2901
2975
|
try {
|
|
2902
|
-
return
|
|
2976
|
+
return Fr(n);
|
|
2903
2977
|
} catch {
|
|
2904
2978
|
throw new Error(`${e}: invalid UTF-8 JSON`);
|
|
2905
2979
|
}
|
|
2906
2980
|
}
|
|
2907
|
-
function
|
|
2981
|
+
function dn(n, e, t) {
|
|
2908
2982
|
return [
|
|
2909
2983
|
"layers.json",
|
|
2910
2984
|
"base.png",
|
|
2911
2985
|
"hairmask.png",
|
|
2912
|
-
...Object.keys(n?.layers ?? {}).map((
|
|
2913
|
-
...e ? ["sprites/sprites.json", ...Object.keys(e.layers ?? {}).map((
|
|
2986
|
+
...Object.keys(n?.layers ?? {}).map((r) => `${r}.png`),
|
|
2987
|
+
...e ? ["sprites/sprites.json", ...Object.keys(e.layers ?? {}).map((r) => `sprites/${r}.png`)] : [],
|
|
2988
|
+
// malformed entries are left to validateAvatarFiles, which reports them
|
|
2989
|
+
...t ? ["overlays/overlays.json", ...(Array.isArray(t.overlays) ? t.overlays : []).flatMap((r) => typeof r?.file == "string" ? [`overlays/${r.file}`] : [])] : []
|
|
2914
2990
|
];
|
|
2915
2991
|
}
|
|
2916
|
-
function
|
|
2917
|
-
const e =
|
|
2992
|
+
function gn(n) {
|
|
2993
|
+
const e = on(n);
|
|
2918
2994
|
if (e.length) throw new Error(e.join(`
|
|
2919
2995
|
`));
|
|
2920
2996
|
}
|
|
2921
|
-
function
|
|
2997
|
+
function yn(n) {
|
|
2922
2998
|
return !!n && typeof n == "object" && "manifest" in n && "rig" in n && "assets" in n && "release" in n;
|
|
2923
2999
|
}
|
|
2924
|
-
function
|
|
2925
|
-
const e =
|
|
3000
|
+
function pt(n) {
|
|
3001
|
+
const e = kr(n);
|
|
2926
3002
|
if (!Object.hasOwn(e, "avatar.json")) throw new Error("avatar.json: missing file in .mavatar archive");
|
|
2927
|
-
|
|
2928
|
-
const t = Be(
|
|
2929
|
-
|
|
2930
|
-
e["built/sprites/sprites.json"] ?
|
|
2931
|
-
|
|
2932
|
-
|
|
3003
|
+
gn(e);
|
|
3004
|
+
const t = Ye(Be(e["avatar.json"], "avatar.json")), r = Et(Be(e["rig.json"], "rig.json")), a = e["built/overlays/overlays.json"] ? Be(e["built/overlays/overlays.json"], "built/overlays/overlays.json") : void 0, s = dn(
|
|
3005
|
+
Be(e["built/layers.json"], "built/layers.json"),
|
|
3006
|
+
e["built/sprites/sprites.json"] ? Be(e["built/sprites/sprites.json"], "built/sprites/sprites.json") : void 0,
|
|
3007
|
+
a
|
|
3008
|
+
), l = {}, f = [], y = () => {
|
|
3009
|
+
f.splice(0).forEach((d) => URL.revokeObjectURL(d));
|
|
2933
3010
|
};
|
|
2934
3011
|
try {
|
|
2935
|
-
for (const
|
|
2936
|
-
const
|
|
2937
|
-
|
|
3012
|
+
for (const d of new Set(s)) {
|
|
3013
|
+
const m = URL.createObjectURL(new Blob([new Uint8Array(e[`built/${d}`])], { type: d.endsWith(".json") ? "application/json" : "image/png" }));
|
|
3014
|
+
f.push(m), l[d] = m;
|
|
2938
3015
|
}
|
|
2939
|
-
} catch (
|
|
2940
|
-
throw
|
|
3016
|
+
} catch (d) {
|
|
3017
|
+
throw y(), d;
|
|
2941
3018
|
}
|
|
2942
|
-
return { manifest: t, rig: r, assets:
|
|
3019
|
+
return { manifest: t, rig: r, assets: l, release: y };
|
|
2943
3020
|
}
|
|
2944
|
-
async function
|
|
2945
|
-
if (
|
|
2946
|
-
if (n instanceof Blob) return
|
|
2947
|
-
if (n instanceof ArrayBuffer || n instanceof Uint8Array) return
|
|
3021
|
+
async function Br(n, e = {}) {
|
|
3022
|
+
if (yn(n)) return n;
|
|
3023
|
+
if (n instanceof Blob) return pt(await n.arrayBuffer());
|
|
3024
|
+
if (n instanceof ArrayBuffer || n instanceof Uint8Array) return pt(n);
|
|
2948
3025
|
const t = new URL(n, typeof location > "u" ? void 0 : location.href);
|
|
2949
3026
|
if (/\.mavatar$/i.test(t.pathname)) {
|
|
2950
3027
|
const u = await fetch(t);
|
|
2951
3028
|
if (!u.ok) throw new Error(`.mavatar: could not load (${u.status})`);
|
|
2952
|
-
return
|
|
3029
|
+
return pt(await u.arrayBuffer());
|
|
2953
3030
|
}
|
|
2954
3031
|
t.pathname.endsWith("/") || (t.pathname += "/");
|
|
2955
3032
|
const r = (u) => {
|
|
2956
|
-
const
|
|
2957
|
-
return
|
|
3033
|
+
const w = new URL(t);
|
|
3034
|
+
return w.pathname += u.split("/").map(encodeURIComponent).join("/"), e.version !== void 0 && w.searchParams.set("v", String(e.version)), w.href;
|
|
2958
3035
|
}, a = {};
|
|
2959
|
-
async function
|
|
2960
|
-
const
|
|
2961
|
-
if (
|
|
2962
|
-
if (!
|
|
2963
|
-
const
|
|
2964
|
-
return a[u] =
|
|
2965
|
-
}
|
|
2966
|
-
const
|
|
2967
|
-
|
|
2968
|
-
const [f,
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
3036
|
+
async function s(u, w = !1) {
|
|
3037
|
+
const o = await fetch(r(u));
|
|
3038
|
+
if (w && (o.status === 404 || o.ok && o.headers.get("content-type")?.includes("text/html"))) return;
|
|
3039
|
+
if (!o.ok) throw new Error(`${u}: could not load (${o.status})`);
|
|
3040
|
+
const i = new Uint8Array(await o.arrayBuffer());
|
|
3041
|
+
return a[u] = i, Be(i, u);
|
|
3042
|
+
}
|
|
3043
|
+
const l = e.rigFile ?? "rig.json";
|
|
3044
|
+
kt(l);
|
|
3045
|
+
const [f, y, d, m, c] = await Promise.all([
|
|
3046
|
+
s(l),
|
|
3047
|
+
s("built/layers.json"),
|
|
3048
|
+
s("avatar.json", !0),
|
|
3049
|
+
s("built/sprites/sprites.json", !0),
|
|
3050
|
+
s("built/overlays/overlays.json", !0)
|
|
2973
3051
|
]);
|
|
2974
|
-
Array.isArray(f?.eyes) && Array.isArray(
|
|
3052
|
+
Array.isArray(f?.eyes) && Array.isArray(y?.eyes) && (f.eyes = f.eyes.map((u, w) => {
|
|
2975
3053
|
if (!u || typeof u != "object") return u;
|
|
2976
|
-
const
|
|
2977
|
-
for (const
|
|
2978
|
-
return
|
|
3054
|
+
const o = { ...u };
|
|
3055
|
+
for (const i of ["x0", "x1", "top", "bot"]) o[i] === void 0 && (o[i] = y.eyes[w]?.[i]);
|
|
3056
|
+
return o;
|
|
2979
3057
|
})), a["rig.json"] = new TextEncoder().encode(JSON.stringify(f));
|
|
2980
|
-
const
|
|
2981
|
-
for (const u of
|
|
2982
|
-
|
|
2983
|
-
const
|
|
2984
|
-
return { manifest:
|
|
3058
|
+
const p = dn(y, m, c);
|
|
3059
|
+
for (const u of p) u.endsWith(".png") && (a[`built/${u}`] = { size: 1 });
|
|
3060
|
+
gn(a);
|
|
3061
|
+
const b = Et(f), v = Object.fromEntries(p.map((u) => [u, r(`built/${u}`)])), h = decodeURIComponent(t.pathname.split("/").filter(Boolean).at(-1) ?? "Avatar");
|
|
3062
|
+
return { manifest: d === void 0 ? an(h) : Ye(d), rig: b, assets: v, release() {
|
|
2985
3063
|
} };
|
|
2986
3064
|
}
|
|
2987
|
-
async function
|
|
2988
|
-
const r = !
|
|
3065
|
+
async function Ir(n, e, t = {}) {
|
|
3066
|
+
const r = !yn(e), a = await Br(e);
|
|
2989
3067
|
try {
|
|
2990
|
-
const
|
|
2991
|
-
let
|
|
2992
|
-
return Object.assign(
|
|
2993
|
-
if (!
|
|
2994
|
-
|
|
3068
|
+
const s = t.lipSync === void 0 ? a.manifest.lipSync : { ...a.manifest.lipSync, ...St(t.lipSync) }, l = await ir(n, { ...t, ...s === void 0 ? {} : { lipSync: s }, rig: a.rig, assets: a.assets }), f = l.destroy.bind(l);
|
|
3069
|
+
let y = !1;
|
|
3070
|
+
return Object.assign(l, { package: a, destroy() {
|
|
3071
|
+
if (!y) {
|
|
3072
|
+
y = !0;
|
|
2995
3073
|
try {
|
|
2996
3074
|
f();
|
|
2997
3075
|
} finally {
|
|
@@ -2999,23 +3077,23 @@ async function Br(n, e, t = {}) {
|
|
|
2999
3077
|
}
|
|
3000
3078
|
}
|
|
3001
3079
|
} });
|
|
3002
|
-
} catch (
|
|
3003
|
-
throw r && a.release(),
|
|
3080
|
+
} catch (s) {
|
|
3081
|
+
throw r && a.release(), s;
|
|
3004
3082
|
}
|
|
3005
3083
|
}
|
|
3006
3084
|
export {
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3085
|
+
Ue as DEFAULT_LIGHTING,
|
|
3086
|
+
Yr as LIVE_EXPRESSIONS,
|
|
3087
|
+
Ge as PARAMS,
|
|
3088
|
+
Ur as colorHex,
|
|
3089
|
+
ir as createMeshAvatar,
|
|
3090
|
+
Ir as loadMeshAvatar,
|
|
3091
|
+
Br as openAvatar,
|
|
3092
|
+
jr as packAvatar,
|
|
3093
|
+
On as parseLighting,
|
|
3094
|
+
Ye as parseManifest,
|
|
3095
|
+
Et as parseRig,
|
|
3096
|
+
kr as unpackAvatar,
|
|
3097
|
+
on as validateAvatarFiles,
|
|
3098
|
+
en as validateRig
|
|
3021
3099
|
};
|