mesh-avatar 0.3.0 → 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/engine/sprites.d.ts +5 -1
- package/dist/index.js +1561 -1480
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -21,157 +21,157 @@ 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
|
-
},
|
|
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
|
-
},
|
|
41
|
-
|
|
42
|
-
},
|
|
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
|
+
ye(n, e, t), Array.isArray(n) && n.length === 2 && n[0] >= n[1] && t.push(`${e}: start must be less than end`);
|
|
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:
|
|
57
|
-
head:
|
|
58
|
-
...
|
|
59
|
-
shiftX:
|
|
60
|
-
shiftY:
|
|
61
|
-
pivotX:
|
|
62
|
-
pivotY:
|
|
63
|
-
maxRoll:
|
|
64
|
-
weightBand:
|
|
65
|
-
turnBand:
|
|
56
|
+
image: oe({ width: we, height: we }),
|
|
57
|
+
head: oe({
|
|
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
|
-
body:
|
|
68
|
-
pivotX:
|
|
69
|
-
pivotY:
|
|
70
|
-
maxRoll:
|
|
71
|
-
breathBand:
|
|
72
|
-
rollBand:
|
|
73
|
-
chest:
|
|
74
|
-
shoulders:
|
|
67
|
+
body: oe({
|
|
68
|
+
pivotX: ne,
|
|
69
|
+
pivotY: ne,
|
|
70
|
+
maxRoll: ne,
|
|
71
|
+
breathBand: ue,
|
|
72
|
+
rollBand: ue,
|
|
73
|
+
chest: ve,
|
|
74
|
+
shoulders: ge(ve)
|
|
75
75
|
}),
|
|
76
|
-
face:
|
|
77
|
-
nose:
|
|
78
|
-
mouth:
|
|
79
|
-
eyeA:
|
|
80
|
-
eyeB:
|
|
81
|
-
earL:
|
|
82
|
-
earR:
|
|
83
|
-
brow:
|
|
84
|
-
jaw:
|
|
76
|
+
face: oe({
|
|
77
|
+
nose: ve,
|
|
78
|
+
mouth: ve,
|
|
79
|
+
eyeA: ve,
|
|
80
|
+
eyeB: ve,
|
|
81
|
+
earL: ve,
|
|
82
|
+
earR: ve,
|
|
83
|
+
brow: oe({ ...Ce, band: ue }),
|
|
84
|
+
jaw: oe({ ...Ce, band: ue })
|
|
85
85
|
}),
|
|
86
|
-
buns:
|
|
87
|
-
eyes:
|
|
88
|
-
opening:
|
|
89
|
-
roi:
|
|
90
|
-
x0:
|
|
91
|
-
x1:
|
|
92
|
-
top:
|
|
93
|
-
bot:
|
|
86
|
+
buns: oe({ bunL: ve, bunR: ve }, ["bunL", "bunR"]),
|
|
87
|
+
eyes: ge(oe({
|
|
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
|
-
mouth:
|
|
96
|
-
cx:
|
|
97
|
-
cy:
|
|
98
|
-
angle:
|
|
99
|
-
halfLen:
|
|
100
|
-
bow:
|
|
101
|
-
area:
|
|
95
|
+
mouth: 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
|
-
cheeks:
|
|
104
|
-
strands:
|
|
105
|
-
accessories:
|
|
106
|
-
name:
|
|
107
|
-
pivot:
|
|
108
|
-
tip:
|
|
109
|
-
split:
|
|
110
|
-
box:
|
|
111
|
-
color:
|
|
103
|
+
cheeks: ge(ye, 2, 2),
|
|
104
|
+
strands: ge(oe({ name: jt, nodes: It, sigma: Le, k: Le, max: Le })),
|
|
105
|
+
accessories: ge(oe({
|
|
106
|
+
name: jt,
|
|
107
|
+
pivot: ye,
|
|
108
|
+
tip: ye,
|
|
109
|
+
split: nt,
|
|
110
|
+
box: ge(Ie, 4, 4),
|
|
111
|
+
color: oe({ redness: nt, minRed: ne })
|
|
112
112
|
})),
|
|
113
|
-
hand:
|
|
114
|
-
outline:
|
|
115
|
-
jaw:
|
|
116
|
-
jawRange:
|
|
117
|
-
background:
|
|
118
|
-
elbow:
|
|
119
|
-
wrist:
|
|
120
|
-
knuckle:
|
|
121
|
-
contact:
|
|
122
|
-
forearmShare:
|
|
123
|
-
armBand:
|
|
124
|
-
wristBand:
|
|
125
|
-
handBand:
|
|
126
|
-
fingerXBand:
|
|
127
|
-
fingerYBand:
|
|
128
|
-
pinBand:
|
|
113
|
+
hand: oe({
|
|
114
|
+
outline: We,
|
|
115
|
+
jaw: It,
|
|
116
|
+
jawRange: ue,
|
|
117
|
+
background: We,
|
|
118
|
+
elbow: ye,
|
|
119
|
+
wrist: ye,
|
|
120
|
+
knuckle: ye,
|
|
121
|
+
contact: ye,
|
|
122
|
+
forearmShare: nt,
|
|
123
|
+
armBand: ue,
|
|
124
|
+
wristBand: ue,
|
|
125
|
+
handBand: ue,
|
|
126
|
+
fingerXBand: ue,
|
|
127
|
+
fingerYBand: ue,
|
|
128
|
+
pinBand: ue
|
|
129
129
|
}),
|
|
130
|
-
mesh:
|
|
131
|
-
baseCell:
|
|
132
|
-
fine:
|
|
133
|
-
x0:
|
|
134
|
-
x1:
|
|
135
|
-
y0:
|
|
136
|
-
y1:
|
|
137
|
-
cell:
|
|
130
|
+
mesh: oe({
|
|
131
|
+
baseCell: we,
|
|
132
|
+
fine: oe({
|
|
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:
|
|
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 Ze = [
|
|
|
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
|
|
200
|
-
}
|
|
201
|
-
function
|
|
202
|
-
|
|
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 F = Math.min(1, Math.max(0, (
|
|
214
|
-
return { top:
|
|
215
|
-
}
|
|
216
|
-
function
|
|
217
|
-
const F =
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
function
|
|
221
|
-
const
|
|
222
|
-
return
|
|
223
|
-
}
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
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
|
+
}
|
|
201
|
+
function l(x, M, T, _) {
|
|
202
|
+
M = Math.min(1, Math.max(0, M));
|
|
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
|
|
238
|
-
for (let F = 0; F <
|
|
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
|
|
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
|
|
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
279
|
if (F <= 0) return [0, 0];
|
|
280
|
-
const
|
|
281
|
-
return [
|
|
282
|
-
}
|
|
283
|
-
function
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
function
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
function
|
|
292
|
-
const F =
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
function U(
|
|
296
|
-
const F =
|
|
297
|
-
F[0] =
|
|
298
|
-
const
|
|
299
|
-
for (const [
|
|
300
|
-
const ee =
|
|
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
301
|
if (!ee) continue;
|
|
302
|
-
const
|
|
303
|
-
F[0] += (ee[
|
|
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
304
|
}
|
|
305
|
-
if (F[0] += (
|
|
306
|
-
const
|
|
307
|
-
F[1] += (
|
|
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
308
|
}
|
|
309
|
-
F[1] +=
|
|
310
|
-
const
|
|
311
|
-
return F[0] +=
|
|
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
312
|
}
|
|
313
|
-
const O = n.hand,
|
|
314
|
-
function H(
|
|
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 [
|
|
326
|
-
},
|
|
327
|
-
function
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
const ee =
|
|
334
|
-
return [ee[0] +
|
|
335
|
-
},
|
|
336
|
-
return { tr:
|
|
337
|
-
}
|
|
338
|
-
function
|
|
339
|
-
let F = [
|
|
340
|
-
F =
|
|
341
|
-
const
|
|
342
|
-
F =
|
|
343
|
-
const
|
|
344
|
-
return F =
|
|
345
|
-
}
|
|
346
|
-
const
|
|
347
|
-
function
|
|
348
|
-
const
|
|
349
|
-
return U(
|
|
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 Le = 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 Le = 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
|
|
488
|
+
const Ve = -0.1, Rn = 0.9, Ln = 1, _n = 1.06;
|
|
489
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(
|
|
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
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 /
|
|
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,352 +695,398 @@ 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
|
-
|
|
731
|
-
}
|
|
732
|
-
const
|
|
733
|
-
for (let
|
|
734
|
-
const
|
|
735
|
-
let
|
|
736
|
-
for (let F = Math.max(0,
|
|
737
|
-
for (let
|
|
738
|
-
if (
|
|
739
|
-
|
|
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
|
+
let M = !1;
|
|
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
|
+
M = !0;
|
|
740
740
|
break;
|
|
741
741
|
}
|
|
742
|
-
if (!
|
|
743
|
-
const
|
|
744
|
-
|
|
742
|
+
if (!M) continue;
|
|
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
|
|
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 U =
|
|
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[U],
|
|
887
|
-
O.p || (O.p =
|
|
888
|
-
const
|
|
889
|
-
for (let
|
|
890
|
-
const
|
|
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
891
|
for (let H = 1; H < 4; H++) {
|
|
892
|
-
const
|
|
893
|
-
|
|
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
|
-
O.p[0] = [
|
|
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
|
|
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 U =
|
|
922
|
-
|
|
923
|
-
const O =
|
|
924
|
-
O.acc = [O.acc[0] + (
|
|
925
|
-
const
|
|
926
|
-
for (let
|
|
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 V = [0, 0];
|
|
988
|
-
let
|
|
989
|
-
const
|
|
990
|
-
function
|
|
991
|
-
const
|
|
992
|
-
for (let
|
|
993
|
-
let
|
|
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(
|
|
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 {
|
|
1003
1003
|
/**
|
|
1004
1004
|
* Show / hide and deform the sprites for this frame.
|
|
1005
|
-
* Returns which eyes are covered by a sprite, so the layered eye parts can be hidden
|
|
1005
|
+
* Returns which eyes are covered by a sprite, so the layered eye parts can be hidden, and
|
|
1006
|
+
* whether a drawing shows the mouth, so the shader mouth can be left out.
|
|
1006
1007
|
* `mood` (angry / sad / surprise) picks drawn expression eyes (sad, surprise) and closed
|
|
1007
1008
|
* mouths (angry, sad) when the avatar has them.
|
|
1008
1009
|
*/
|
|
1009
|
-
update(
|
|
1010
|
-
for (const
|
|
1011
|
-
const
|
|
1010
|
+
update(I, V, K = 1 / 60, x = null) {
|
|
1011
|
+
for (const C of Object.values(k)) C.layer.visible = !1;
|
|
1012
|
+
const M = [!1, !1];
|
|
1012
1013
|
[
|
|
1013
|
-
[
|
|
1014
|
-
[
|
|
1015
|
-
].forEach(([
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
const
|
|
1019
|
-
if (
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
},
|
|
1023
|
-
|
|
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;
|
|
1024
1025
|
});
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
const
|
|
1028
|
-
if (
|
|
1029
|
-
|
|
1030
|
-
const
|
|
1031
|
-
|
|
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);
|
|
1032
1033
|
}
|
|
1033
|
-
return { eyes:
|
|
1034
|
-
}
|
|
1034
|
+
return { eyes: M, mouth: _, mouthDrawn: N && (!Y || !!X) };
|
|
1035
|
+
},
|
|
1036
|
+
/** Whether each eye has the closed and half-closed drawings, so the layered eye stays open. */
|
|
1037
|
+
eyesDrawn: q
|
|
1035
1038
|
};
|
|
1036
1039
|
}
|
|
1037
|
-
return { createSprites:
|
|
1040
|
+
return { createSprites: S, mouthShape: u, eyeSprite: h };
|
|
1038
1041
|
}
|
|
1039
|
-
const
|
|
1042
|
+
const $t = { angry: "angry", angryTalk: "angry", sad: "sad", sadTalk: "sad", surprise: "surprise", surprisedTalk: "surprise" };
|
|
1040
1043
|
function In(n, e) {
|
|
1041
|
-
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];
|
|
1042
1056
|
}
|
|
1043
|
-
function
|
|
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
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
function St(n) {
|
|
1044
1090
|
if (!n || typeof n != "object" || Array.isArray(n)) throw new TypeError("lipSync: expected an object");
|
|
1045
1091
|
const e = n, t = {};
|
|
1046
1092
|
for (const r of ["granularity", "openness", "closeSpeed"]) {
|
|
@@ -1058,32 +1104,32 @@ function wt(n) {
|
|
|
1058
1104
|
}
|
|
1059
1105
|
return t;
|
|
1060
1106
|
}
|
|
1061
|
-
function
|
|
1107
|
+
function zt(n = {}, e = {
|
|
1062
1108
|
granularity: 0.5,
|
|
1063
1109
|
openness: 0.5,
|
|
1064
1110
|
closeSpeed: 0.5
|
|
1065
1111
|
}) {
|
|
1066
|
-
const t =
|
|
1112
|
+
const t = St(n);
|
|
1067
1113
|
return {
|
|
1068
1114
|
granularity: t.granularity ?? e.granularity,
|
|
1069
1115
|
openness: t.openness ?? e.openness,
|
|
1070
1116
|
closeSpeed: t.closeSpeed ?? e.closeSpeed
|
|
1071
1117
|
};
|
|
1072
1118
|
}
|
|
1073
|
-
const
|
|
1074
|
-
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) {
|
|
1075
1121
|
return {
|
|
1076
|
-
arm:
|
|
1077
|
-
trigger:
|
|
1078
|
-
relax:
|
|
1079
|
-
range:
|
|
1080
|
-
risePower:
|
|
1081
|
-
openness:
|
|
1082
|
-
audioRelease:
|
|
1083
|
-
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)
|
|
1084
1130
|
};
|
|
1085
1131
|
}
|
|
1086
|
-
const
|
|
1132
|
+
const $n = /* @__PURE__ */ new Set([
|
|
1087
1133
|
"angleX",
|
|
1088
1134
|
"angleY",
|
|
1089
1135
|
"angleZ",
|
|
@@ -1093,7 +1139,7 @@ const Nn = /* @__PURE__ */ new Set([
|
|
|
1093
1139
|
"handAngle",
|
|
1094
1140
|
"gazeX",
|
|
1095
1141
|
"gazeY"
|
|
1096
|
-
]),
|
|
1142
|
+
]), Tt = {
|
|
1097
1143
|
nod: {
|
|
1098
1144
|
label: "Nod",
|
|
1099
1145
|
dur: 1.7,
|
|
@@ -1241,7 +1287,7 @@ const Nn = /* @__PURE__ */ new Set([
|
|
|
1241
1287
|
blush: [[0, 0], [1.6, 0.3], [2.6, 0]]
|
|
1242
1288
|
}
|
|
1243
1289
|
}
|
|
1244
|
-
},
|
|
1290
|
+
}, Ot = {
|
|
1245
1291
|
lookAround: {
|
|
1246
1292
|
label: "Look around",
|
|
1247
1293
|
dur: 5.2,
|
|
@@ -1481,16 +1527,16 @@ const Nn = /* @__PURE__ */ new Set([
|
|
|
1481
1527
|
}
|
|
1482
1528
|
}
|
|
1483
1529
|
};
|
|
1484
|
-
function
|
|
1530
|
+
function zn(n, e) {
|
|
1485
1531
|
if (e <= n[0][0]) return n[0][1];
|
|
1486
1532
|
const t = n.length - 1;
|
|
1487
1533
|
if (e >= n[t][0]) return n[t][1];
|
|
1488
1534
|
let r = 0;
|
|
1489
1535
|
for (; e > n[r + 1][0]; ) r++;
|
|
1490
|
-
const [a,
|
|
1491
|
-
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;
|
|
1492
1538
|
}
|
|
1493
|
-
const
|
|
1539
|
+
const Pe = {
|
|
1494
1540
|
a: { open: 0.9, form: 0, label: "あ" },
|
|
1495
1541
|
i: { open: 0.5, form: -0.85, label: "い" },
|
|
1496
1542
|
u: { open: 0.4, form: 0.9, label: "う" },
|
|
@@ -1498,21 +1544,21 @@ const Ce = {
|
|
|
1498
1544
|
o: { open: 0.75, form: 0.6, label: "お" },
|
|
1499
1545
|
n: { open: 0, form: null, label: "ん" }
|
|
1500
1546
|
// closes with the previous shape
|
|
1501
|
-
},
|
|
1547
|
+
}, Cn = {
|
|
1502
1548
|
a: "あかさたなはまやらわがざだばぱぁ",
|
|
1503
1549
|
i: "いきしちにひみりぎじぢびぴぃ",
|
|
1504
1550
|
u: "うくすつぬふむゆるぐずづぶぷぅゔ",
|
|
1505
1551
|
e: "えけせてねへめれげぜでべぺぇ",
|
|
1506
1552
|
o: "おこそとのほもよろをごぞどぼぽぉ"
|
|
1507
|
-
},
|
|
1508
|
-
for (const [n, e] of Object.entries(
|
|
1509
|
-
const
|
|
1510
|
-
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) {
|
|
1511
1557
|
const t = [];
|
|
1512
|
-
for (const r of
|
|
1558
|
+
for (const r of Zn(n)) {
|
|
1513
1559
|
const a = t[t.length - 1];
|
|
1514
|
-
if (
|
|
1515
|
-
a.vowel =
|
|
1560
|
+
if (Pt[r] && a) {
|
|
1561
|
+
a.vowel = Pt[r];
|
|
1516
1562
|
continue;
|
|
1517
1563
|
}
|
|
1518
1564
|
if (r === "ー" && a) {
|
|
@@ -1527,41 +1573,41 @@ function Dn(n, e = 0.14) {
|
|
|
1527
1573
|
t.push({ vowel: "n", dur: e, onset: null });
|
|
1528
1574
|
continue;
|
|
1529
1575
|
}
|
|
1530
|
-
if (
|
|
1576
|
+
if (Hn.has(r)) {
|
|
1531
1577
|
t.push({ vowel: "n", dur: e * 2.2, onset: null });
|
|
1532
1578
|
continue;
|
|
1533
1579
|
}
|
|
1534
|
-
const
|
|
1535
|
-
|
|
1580
|
+
const s = tn[r];
|
|
1581
|
+
s && t.push({ vowel: s, dur: e, onset: Pn.has(r) ? "lips" : Dn.has(r) ? null : "consonant" });
|
|
1536
1582
|
}
|
|
1537
1583
|
return t;
|
|
1538
1584
|
}
|
|
1539
|
-
function
|
|
1540
|
-
if (t !== 0.5) return
|
|
1585
|
+
function Gn(n, e, t = 0.5) {
|
|
1586
|
+
if (t !== 0.5) return Vn(n, e, t);
|
|
1541
1587
|
let r = 0;
|
|
1542
1588
|
for (const a of n) {
|
|
1543
1589
|
if (e < r + a.dur) {
|
|
1544
|
-
const
|
|
1545
|
-
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 };
|
|
1546
1592
|
}
|
|
1547
1593
|
r += a.dur;
|
|
1548
1594
|
}
|
|
1549
1595
|
return null;
|
|
1550
1596
|
}
|
|
1551
|
-
function
|
|
1597
|
+
function Vn(n, e, t) {
|
|
1552
1598
|
const r = t < 0.5 ? (0.5 - t) * 0.72 : 0;
|
|
1553
|
-
let a = 0,
|
|
1599
|
+
let a = 0, s = 0, l = null;
|
|
1554
1600
|
for (const f of n) {
|
|
1555
|
-
let
|
|
1556
|
-
if (f.vowel === "n" ? r && f.dur <= 0.2 &&
|
|
1557
|
-
const
|
|
1558
|
-
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 };
|
|
1559
1605
|
}
|
|
1560
1606
|
a += f.dur;
|
|
1561
1607
|
}
|
|
1562
1608
|
return null;
|
|
1563
1609
|
}
|
|
1564
|
-
const
|
|
1610
|
+
const at = { ...Tt, ...Ot }, Dt = { amp: 1, stiff: 1.8 }, qn = /^(angle|bodyAngle|armAngle|handAngle)/, Jn = /* @__PURE__ */ new Set([
|
|
1565
1611
|
"eyeOpen",
|
|
1566
1612
|
"eyeOpenL",
|
|
1567
1613
|
"eyeSmileL",
|
|
@@ -1571,18 +1617,18 @@ const tt = { ...At, ...Mt }, Ct = { amp: 1, stiff: 1.8 }, Wn = /^(angle|bodyAngl
|
|
|
1571
1617
|
"blush",
|
|
1572
1618
|
"browY",
|
|
1573
1619
|
"browAngle"
|
|
1574
|
-
]),
|
|
1620
|
+
]), qe = (n, e, t) => {
|
|
1575
1621
|
const r = Math.min(1, Math.max(0, (t - n) / (e - n)));
|
|
1576
1622
|
return r * r * (3 - 2 * r);
|
|
1577
1623
|
};
|
|
1578
|
-
function
|
|
1579
|
-
const t = Math.floor(n), r = n - t, a = (
|
|
1580
|
-
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;
|
|
1581
1627
|
return f - Math.floor(f);
|
|
1582
|
-
},
|
|
1583
|
-
return (a(t) * (1 -
|
|
1628
|
+
}, s = r * r * (3 - 2 * r);
|
|
1629
|
+
return (a(t) * (1 - s) + a(t + 1) * s) * 2 - 1;
|
|
1584
1630
|
}
|
|
1585
|
-
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 = {
|
|
1586
1632
|
normal: { label: "Neutral", p: {} },
|
|
1587
1633
|
smile: { label: "Smile", p: { eyeOpen: 0, eyeSmile: 1, blush: 0.35, browY: 0.2 } },
|
|
1588
1634
|
shy: { label: "Blush", p: { eyeOpen: 0.78, eyeSmile: 0.5, blush: 1, browAngle: -0.5, browY: -0.1, glance: [0.7, 0.35] } },
|
|
@@ -1596,14 +1642,14 @@ const we = (n, e) => zt(n, e) * 0.7 + zt(n * 2.3, e + 9) * 0.3, me = (n, e, t) =
|
|
|
1596
1642
|
angryTalk: { label: "angry", p: { eyeOpen: 0.72, browAngle: 0.85, browY: -0.55, mouthForm: 0.2 } },
|
|
1597
1643
|
surprisedTalk: { label: "surprised", p: { eyeOpen: 1.18, browY: 0.9, mouthForm: 0.9 } },
|
|
1598
1644
|
relaxedTalk: { label: "relaxed", p: { eyeOpen: 0.82, eyeSmile: 0.35, blush: 0.15, browY: 0.1 } }
|
|
1599
|
-
},
|
|
1645
|
+
}, Zt = {
|
|
1600
1646
|
happy: ["happyTalk", "nod"],
|
|
1601
1647
|
sad: ["sadTalk", "sigh"],
|
|
1602
1648
|
angry: ["angryTalk", "no"],
|
|
1603
1649
|
surprised: ["surprisedTalk", "surprise"],
|
|
1604
1650
|
relaxed: ["relaxedTalk", "sway"],
|
|
1605
1651
|
neutral: ["normal", null]
|
|
1606
|
-
},
|
|
1652
|
+
}, Kn = {
|
|
1607
1653
|
gazeX: [260, 0.9],
|
|
1608
1654
|
gazeY: [260, 0.9],
|
|
1609
1655
|
angleX: [55, 0.72],
|
|
@@ -1614,41 +1660,41 @@ const we = (n, e) => zt(n, e) * 0.7 + zt(n * 2.3, e + 9) * 0.3, me = (n, e, t) =
|
|
|
1614
1660
|
armAngle: [20, 0.85],
|
|
1615
1661
|
handAngle: [30, 0.8]
|
|
1616
1662
|
};
|
|
1617
|
-
class
|
|
1663
|
+
class Qn {
|
|
1618
1664
|
/** @param {number[]} gazeCenter */
|
|
1619
1665
|
constructor(e) {
|
|
1620
|
-
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;
|
|
1621
1667
|
}
|
|
1622
1668
|
setExpression(e) {
|
|
1623
1669
|
this.expr = e;
|
|
1624
1670
|
}
|
|
1625
1671
|
hasMotion(e) {
|
|
1626
|
-
return e in
|
|
1672
|
+
return e in at;
|
|
1627
1673
|
}
|
|
1628
1674
|
// ---- speech (driven from outside, e.g. by the TTS audio analyser) ----
|
|
1629
1675
|
setVoiceLevel(e) {
|
|
1630
1676
|
this.voice = Math.min(1, Math.max(0, Number(e) || 0));
|
|
1631
1677
|
}
|
|
1632
1678
|
setLipSync(e) {
|
|
1633
|
-
this.lipSync =
|
|
1679
|
+
this.lipSync = zt(e, this.lipSync), this.lipMotion = Ct(this.lipSync);
|
|
1634
1680
|
}
|
|
1635
1681
|
setSpeaking(e) {
|
|
1636
1682
|
e !== this.speaking && (this.speaking = !!e, e || (this.emotionUntil = this.t + 1.2, this.voice = 0));
|
|
1637
1683
|
}
|
|
1638
1684
|
/** `playMotion: false` changes only the face (a caller that picks motions itself). */
|
|
1639
1685
|
setEmotion(e, { playMotion: t = !0 } = {}) {
|
|
1640
|
-
const r =
|
|
1686
|
+
const r = Zt[e] ?? Zt.neutral;
|
|
1641
1687
|
this.expr = r[0], this.emotionUntil = 1 / 0, r[1] && t && this.playMotion(r[1]);
|
|
1642
1688
|
}
|
|
1643
1689
|
/** Mouth shapes from kana text, without audio (preview / tuning). */
|
|
1644
1690
|
/** @param {string} text @param {{ speed?: number, loop?: boolean }} [options] */
|
|
1645
1691
|
speakKana(e, { speed: t, loop: r = !1 } = {}) {
|
|
1646
1692
|
this.lipHold = null;
|
|
1647
|
-
const a =
|
|
1648
|
-
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;
|
|
1649
1695
|
}
|
|
1650
1696
|
holdMouth(e) {
|
|
1651
|
-
this.kana = null, this.lipHold = Object.hasOwn(
|
|
1697
|
+
this.kana = null, this.lipHold = Object.hasOwn(Pe, e) ? e : null;
|
|
1652
1698
|
}
|
|
1653
1699
|
stopLipSync() {
|
|
1654
1700
|
this.kana = null, this.lipHold = null, this.lipOpen = null, this.mouth = 0;
|
|
@@ -1664,11 +1710,11 @@ class qn {
|
|
|
1664
1710
|
// the dip before each mora even when a loud voice never gets quiet.
|
|
1665
1711
|
speechMouth(e) {
|
|
1666
1712
|
if (this.kana || this.lipHold) {
|
|
1667
|
-
let
|
|
1668
|
-
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)
|
|
1669
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;
|
|
1670
|
-
const
|
|
1671
|
-
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];
|
|
1672
1718
|
}
|
|
1673
1719
|
const t = this.speaking ? this.voice : 0, r = 1 - Math.exp(-e * this.lipMotion.relax);
|
|
1674
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;
|
|
@@ -1676,18 +1722,18 @@ class qn {
|
|
|
1676
1722
|
if (t < a * this.lipMotion.arm) this.syllableArmed = !0;
|
|
1677
1723
|
else if (this.syllableArmed && t > a * this.lipMotion.trigger && t > 0.1) {
|
|
1678
1724
|
this.syllableArmed = !1;
|
|
1679
|
-
const
|
|
1680
|
-
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";
|
|
1681
1727
|
}
|
|
1682
|
-
const
|
|
1683
|
-
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;
|
|
1684
1730
|
}
|
|
1685
1731
|
// Breathing: inhale ~40% of the cycle, a slower exhale, a short pause at the bottom,
|
|
1686
1732
|
// and a period that drifts between ~3.2 and 4.6 s so it never looks metronomic.
|
|
1687
1733
|
breathValue(e) {
|
|
1688
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);
|
|
1689
1735
|
const t = this.breathPhase;
|
|
1690
|
-
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;
|
|
1691
1737
|
}
|
|
1692
1738
|
// pick one at random, never the one that just played
|
|
1693
1739
|
playRandom(e) {
|
|
@@ -1706,81 +1752,81 @@ class qn {
|
|
|
1706
1752
|
update(e) {
|
|
1707
1753
|
this.t += e;
|
|
1708
1754
|
const t = this.t, r = {};
|
|
1709
|
-
for (const
|
|
1755
|
+
for (const v of Ge) r[v.id] = v.def;
|
|
1710
1756
|
if (this.mode === "manual")
|
|
1711
1757
|
Object.assign(r, this.manual);
|
|
1712
1758
|
else if (this.mode === "auto") {
|
|
1713
|
-
if (r.angleX =
|
|
1714
|
-
const
|
|
1715
|
-
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;
|
|
1716
1762
|
}
|
|
1717
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) {
|
|
1718
1764
|
this.nextIdle = Math.max(this.nextIdle, t + 2.5), this.nextAuto = Math.max(this.nextAuto, t + 6);
|
|
1719
|
-
const
|
|
1720
|
-
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;
|
|
1721
1767
|
}
|
|
1722
|
-
!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));
|
|
1723
1769
|
} else if (this.mode === "mouse" && this.pointer) {
|
|
1724
|
-
const
|
|
1725
|
-
r.angleX =
|
|
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);
|
|
1726
1772
|
}
|
|
1727
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));
|
|
1728
|
-
let a = null,
|
|
1774
|
+
let a = null, s = 0;
|
|
1729
1775
|
if (this.play) {
|
|
1730
|
-
const
|
|
1731
|
-
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)
|
|
1732
1778
|
this.play = null, this.onMotion?.(null);
|
|
1733
1779
|
else {
|
|
1734
1780
|
a = {};
|
|
1735
|
-
for (const [
|
|
1736
|
-
a[
|
|
1737
|
-
|
|
1738
|
-
for (const [
|
|
1739
|
-
|
|
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)));
|
|
1740
1786
|
}
|
|
1741
1787
|
}
|
|
1742
1788
|
this.mode !== "manual" && (r.angleY += r.breath * 1.6);
|
|
1743
|
-
const
|
|
1744
|
-
eyeOpen:
|
|
1745
|
-
eyeOpenL:
|
|
1746
|
-
eyeSmileL:
|
|
1747
|
-
eyeSmile:
|
|
1748
|
-
mouthOpen:
|
|
1749
|
-
mouthForm:
|
|
1750
|
-
blush:
|
|
1751
|
-
browY:
|
|
1752
|
-
browAngle:
|
|
1753
|
-
gx:
|
|
1754
|
-
gy:
|
|
1755
|
-
},
|
|
1756
|
-
for (const
|
|
1757
|
-
this.exprMix[
|
|
1758
|
-
const
|
|
1759
|
-
for (const
|
|
1760
|
-
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;
|
|
1761
1807
|
if (this.mode === "manual" && !a) {
|
|
1762
|
-
|
|
1808
|
+
c[h] = r[h], this.cur[h] = r[h], this.vel[h] = 0;
|
|
1763
1809
|
continue;
|
|
1764
1810
|
}
|
|
1765
|
-
let [
|
|
1766
|
-
a && /^angle|^body/.test(
|
|
1767
|
-
const
|
|
1768
|
-
this.vel[
|
|
1769
|
-
}
|
|
1770
|
-
let
|
|
1771
|
-
if (this.mode !== "manual" ? (
|
|
1772
|
-
const
|
|
1773
|
-
|
|
1774
|
-
},
|
|
1775
|
-
"eyeOpen" in a && (
|
|
1776
|
-
for (const
|
|
1777
|
-
|
|
1778
|
-
}
|
|
1779
|
-
const
|
|
1780
|
-
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;
|
|
1781
1827
|
}
|
|
1782
1828
|
}
|
|
1783
|
-
const
|
|
1829
|
+
const Rt = {
|
|
1784
1830
|
neutral: "normal",
|
|
1785
1831
|
smile: "smile",
|
|
1786
1832
|
shy: "shy",
|
|
@@ -1789,9 +1835,9 @@ const Et = {
|
|
|
1789
1835
|
angry: "angryTalk",
|
|
1790
1836
|
sad: "sadTalk",
|
|
1791
1837
|
wink: "wink"
|
|
1792
|
-
},
|
|
1793
|
-
function
|
|
1794
|
-
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] ?? {};
|
|
1795
1841
|
return {
|
|
1796
1842
|
eyeOpen: e.eyeOpen ?? 1,
|
|
1797
1843
|
eyeOpenL: e.eyeOpenL ?? e.eyeOpen ?? 1,
|
|
@@ -1806,277 +1852,293 @@ function Kn(n) {
|
|
|
1806
1852
|
pitch: t.pitch ?? 0
|
|
1807
1853
|
};
|
|
1808
1854
|
}
|
|
1809
|
-
function
|
|
1855
|
+
function nr(n, e) {
|
|
1810
1856
|
const t = { ...n };
|
|
1811
|
-
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;
|
|
1812
1858
|
}
|
|
1813
|
-
class
|
|
1859
|
+
class rr {
|
|
1814
1860
|
/** @type {keyof typeof OVERLAY_EXPRESSIONS} */
|
|
1815
1861
|
name = "neutral";
|
|
1816
|
-
mix = { ...
|
|
1862
|
+
mix = { ...Xe };
|
|
1817
1863
|
/** @param {string} name */
|
|
1818
1864
|
set(e) {
|
|
1819
|
-
this.name = Object.hasOwn(
|
|
1865
|
+
this.name = Object.hasOwn(Rt, e) ? (
|
|
1820
1866
|
/** @type {keyof typeof OVERLAY_EXPRESSIONS} */
|
|
1821
1867
|
e
|
|
1822
1868
|
) : "neutral";
|
|
1823
1869
|
}
|
|
1824
1870
|
/** True while an expression is shown or still fading out. */
|
|
1825
1871
|
get active() {
|
|
1826
|
-
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);
|
|
1827
1873
|
}
|
|
1828
1874
|
apply(e, t) {
|
|
1829
1875
|
if (!this.active)
|
|
1830
|
-
return this.mix = { ...
|
|
1831
|
-
const r =
|
|
1832
|
-
for (const
|
|
1833
|
-
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);
|
|
1834
1880
|
}
|
|
1835
1881
|
}
|
|
1836
|
-
const
|
|
1837
|
-
async function
|
|
1838
|
-
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) => {
|
|
1839
1885
|
if (!e.ok) throw new Error(`failed to load ${n}`);
|
|
1840
1886
|
return e.json();
|
|
1841
|
-
})),
|
|
1887
|
+
})), st.get(n);
|
|
1842
1888
|
}
|
|
1843
|
-
function
|
|
1844
|
-
if (
|
|
1889
|
+
function lt(n) {
|
|
1890
|
+
if (ot.has(n)) return ot.get(n);
|
|
1845
1891
|
const e = new Promise((t, r) => {
|
|
1846
1892
|
const a = new Image();
|
|
1847
1893
|
a.onload = () => t(a), a.onerror = () => r(new Error(`failed to load ${n}`)), a.src = n;
|
|
1848
1894
|
});
|
|
1849
|
-
return
|
|
1895
|
+
return ot.set(n, e), e;
|
|
1850
1896
|
}
|
|
1851
|
-
function
|
|
1897
|
+
function rn(n, e) {
|
|
1852
1898
|
const t = document.createElement("canvas");
|
|
1853
1899
|
t.width = n.width, t.height = n.height;
|
|
1854
1900
|
const r = t.getContext("2d");
|
|
1855
1901
|
r.drawImage(n, 0, 0);
|
|
1856
|
-
const a = r.getImageData(0, 0, t.width, t.height).data,
|
|
1857
|
-
for (let
|
|
1858
|
-
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;
|
|
1859
1905
|
}
|
|
1860
|
-
const
|
|
1861
|
-
function
|
|
1862
|
-
const
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
const
|
|
1868
|
-
|
|
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;
|
|
1910
|
+
}
|
|
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;
|
|
1869
1919
|
}
|
|
1870
1920
|
}
|
|
1871
|
-
async function
|
|
1921
|
+
async function sr(n, e) {
|
|
1872
1922
|
if (!e.assets && e.assetsBase === void 0)
|
|
1873
1923
|
throw new Error("createMeshAvatar requires assets or assetsBase.");
|
|
1874
|
-
const t = e.rig, r =
|
|
1924
|
+
const t = e.rig, r = xn(t), {
|
|
1875
1925
|
IMG: a,
|
|
1876
|
-
EYES:
|
|
1877
|
-
baseWeights:
|
|
1926
|
+
EYES: s,
|
|
1927
|
+
baseWeights: l,
|
|
1878
1928
|
deformBase: f,
|
|
1879
|
-
eyePartY:
|
|
1880
|
-
eyePartAlpha:
|
|
1881
|
-
handWeights:
|
|
1882
|
-
handFrame:
|
|
1883
|
-
deformHand:
|
|
1884
|
-
TASSELS:
|
|
1885
|
-
} = 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) => {
|
|
1886
1936
|
if (e.assets) {
|
|
1887
|
-
if (!e.assets[
|
|
1888
|
-
return e.assets[
|
|
1889
|
-
}
|
|
1890
|
-
return `${
|
|
1891
|
-
},
|
|
1892
|
-
for (let
|
|
1893
|
-
const
|
|
1894
|
-
O.push(
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1899
|
-
for (const
|
|
1900
|
-
const
|
|
1901
|
-
for (let
|
|
1902
|
-
const
|
|
1903
|
-
|
|
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 });
|
|
1904
1954
|
}
|
|
1905
1955
|
});
|
|
1906
|
-
let
|
|
1956
|
+
let D = null;
|
|
1907
1957
|
try {
|
|
1908
1958
|
{
|
|
1909
|
-
const
|
|
1910
|
-
|
|
1911
|
-
}
|
|
1912
|
-
} catch (
|
|
1913
|
-
console.warn("eye / mouth sprites not loaded:",
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
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);
|
|
1926
1983
|
};
|
|
1927
|
-
let
|
|
1928
|
-
const
|
|
1929
|
-
function
|
|
1930
|
-
const
|
|
1931
|
-
for (const [
|
|
1932
|
-
|
|
1933
|
-
const
|
|
1934
|
-
return
|
|
1935
|
-
}
|
|
1936
|
-
function E
|
|
1937
|
-
const
|
|
1938
|
-
for (let
|
|
1939
|
-
f(
|
|
1940
|
-
const
|
|
1941
|
-
for (const
|
|
1942
|
-
const
|
|
1943
|
-
|
|
1944
|
-
const
|
|
1945
|
-
for (let
|
|
1946
|
-
const
|
|
1947
|
-
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];
|
|
1948
2005
|
}
|
|
1949
2006
|
}
|
|
1950
|
-
const
|
|
1951
|
-
if (
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
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({
|
|
2016
|
+
angleX: R.angleX,
|
|
2017
|
+
angleY: R.angleY,
|
|
2018
|
+
angleZ: R.angleZ,
|
|
1961
2019
|
eyes: [
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
-
|
|
2020
|
+
se(R.eyeROpen, 0),
|
|
2021
|
+
R.eyeSmile,
|
|
2022
|
+
R.gazeX * Ze,
|
|
2023
|
+
-R.gazeY * Ze * 0.6,
|
|
2024
|
+
se(R.eyeLOpen, 1),
|
|
2025
|
+
R.eyeSmileL ?? R.eyeSmile,
|
|
2026
|
+
R.gazeX * Ze * 0.85,
|
|
2027
|
+
-R.gazeY * Ze * 0.6
|
|
1970
2028
|
],
|
|
1971
2029
|
// with sprites the drawn mouths replace the shader-painted one
|
|
1972
|
-
mouthOpen:
|
|
1973
|
-
mouthForm:
|
|
1974
|
-
cheek:
|
|
2030
|
+
mouthOpen: le?.mouthDrawn ? 0 : R.mouthOpen,
|
|
2031
|
+
mouthForm: R.mouthForm,
|
|
2032
|
+
cheek: R.blush,
|
|
1975
2033
|
showMesh: !1,
|
|
1976
2034
|
originalAlpha: 0,
|
|
1977
2035
|
joints: []
|
|
1978
2036
|
});
|
|
1979
2037
|
}
|
|
1980
|
-
let
|
|
1981
|
-
const
|
|
1982
|
-
const
|
|
1983
|
-
|
|
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);
|
|
1984
2042
|
};
|
|
1985
|
-
return e.manual || (
|
|
2043
|
+
return e.manual || (Y = requestAnimationFrame(C)), {
|
|
1986
2044
|
motions: [
|
|
1987
|
-
...Object.entries(
|
|
1988
|
-
...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 }))
|
|
1989
2047
|
],
|
|
1990
|
-
setParameters(
|
|
1991
|
-
|
|
2048
|
+
setParameters(E, R = 1) {
|
|
2049
|
+
I = { ...E }, V = Math.min(1, Math.max(0, Number(R) || 0));
|
|
1992
2050
|
},
|
|
1993
2051
|
getParameters() {
|
|
1994
|
-
return { ...
|
|
2052
|
+
return { ...K };
|
|
1995
2053
|
},
|
|
1996
2054
|
/** 0..1 loudness of the voice being played (e.g. normalised RMS). */
|
|
1997
|
-
setVoiceLevel(
|
|
1998
|
-
|
|
2055
|
+
setVoiceLevel(E) {
|
|
2056
|
+
z.setVoiceLevel(E);
|
|
1999
2057
|
},
|
|
2000
2058
|
/** Partial mouth-movement settings; omitted fields retain their current values. */
|
|
2001
|
-
setLipSync(
|
|
2002
|
-
|
|
2059
|
+
setLipSync(E) {
|
|
2060
|
+
z.setLipSync(E);
|
|
2003
2061
|
},
|
|
2004
2062
|
/** true while TTS audio is playing: idle motions pause and the head nods along. */
|
|
2005
|
-
setSpeaking(
|
|
2006
|
-
|
|
2063
|
+
setSpeaking(E) {
|
|
2064
|
+
z.setSpeaking(E);
|
|
2007
2065
|
},
|
|
2008
2066
|
/** AITuber OnAir emotion tag: happy / sad / angry / surprised / relaxed / neutral (or null). */
|
|
2009
|
-
setEmotion(
|
|
2010
|
-
|
|
2067
|
+
setEmotion(E, R) {
|
|
2068
|
+
z.setEmotion(E, R);
|
|
2011
2069
|
},
|
|
2012
2070
|
/** Live expression layered over tracking (see OVERLAY_EXPRESSIONS); 'neutral' clears it. */
|
|
2013
|
-
setExpression(
|
|
2014
|
-
|
|
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);
|
|
2015
2077
|
},
|
|
2016
2078
|
getExpression() {
|
|
2017
|
-
return { name:
|
|
2079
|
+
return { name: x.name, active: x.active };
|
|
2018
2080
|
},
|
|
2019
2081
|
/** How much the head moves with the voice while speaking (1 = default, calmer below). */
|
|
2020
|
-
setTalkGain(
|
|
2021
|
-
|
|
2082
|
+
setTalkGain(E) {
|
|
2083
|
+
z.talkGain = Math.max(0, Number(E) || 0);
|
|
2022
2084
|
},
|
|
2023
2085
|
/** Play a motion or idle motion by id (see `motions`). */
|
|
2024
|
-
play(
|
|
2025
|
-
|
|
2086
|
+
play(E) {
|
|
2087
|
+
z.hasMotion(E) && z.playMotion(E);
|
|
2026
2088
|
},
|
|
2027
2089
|
/** Move the mouth through the vowels of kana text (no audio; for previews). */
|
|
2028
|
-
speakKana(
|
|
2029
|
-
|
|
2090
|
+
speakKana(E, R) {
|
|
2091
|
+
z.speakKana(String(E ?? ""), R);
|
|
2030
2092
|
},
|
|
2031
|
-
holdMouth(
|
|
2032
|
-
|
|
2093
|
+
holdMouth(E) {
|
|
2094
|
+
z.holdMouth(E);
|
|
2033
2095
|
},
|
|
2034
2096
|
stopLipSync() {
|
|
2035
|
-
|
|
2097
|
+
z.stopLipSync();
|
|
2036
2098
|
},
|
|
2037
2099
|
getLipSyncState() {
|
|
2038
|
-
return
|
|
2100
|
+
return z.getLipSyncState();
|
|
2039
2101
|
},
|
|
2040
|
-
setAutoIdle(
|
|
2041
|
-
|
|
2102
|
+
setAutoIdle(E) {
|
|
2103
|
+
z.autoIdle = !!E;
|
|
2042
2104
|
},
|
|
2043
|
-
setLighting(
|
|
2044
|
-
|
|
2105
|
+
setLighting(E) {
|
|
2106
|
+
j.setLighting(E);
|
|
2045
2107
|
},
|
|
2046
2108
|
getLightingStats() {
|
|
2047
|
-
return { ...
|
|
2109
|
+
return { ...j.lightingStats };
|
|
2048
2110
|
},
|
|
2049
|
-
setAutoMotion(
|
|
2050
|
-
|
|
2111
|
+
setAutoMotion(E) {
|
|
2112
|
+
z.autoMotion = !!E;
|
|
2051
2113
|
},
|
|
2052
2114
|
/** Hair / tassel sway multiplier (1 = default). */
|
|
2053
|
-
setSwayGain(
|
|
2054
|
-
|
|
2115
|
+
setSwayGain(E) {
|
|
2116
|
+
G.gain = E;
|
|
2055
2117
|
},
|
|
2056
2118
|
/** Called with the motion id when a motion starts and with null when it ends. */
|
|
2057
|
-
onMotion(
|
|
2058
|
-
return
|
|
2119
|
+
onMotion(E) {
|
|
2120
|
+
return W.add(E), () => W.delete(E);
|
|
2059
2121
|
},
|
|
2060
2122
|
/** Advance the simulation by `sec` and draw (for tests / hidden tabs). */
|
|
2061
|
-
advance(
|
|
2062
|
-
if (!
|
|
2063
|
-
if (
|
|
2064
|
-
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);
|
|
2065
2127
|
},
|
|
2066
2128
|
/** Update motion and lip sync without drawing a hidden preview. */
|
|
2067
|
-
advanceParameters(
|
|
2068
|
-
|
|
2129
|
+
advanceParameters(E) {
|
|
2130
|
+
F || T(E);
|
|
2069
2131
|
},
|
|
2070
2132
|
destroy() {
|
|
2071
|
-
|
|
2133
|
+
F || (F = !0, cancelAnimationFrame(Y), W.clear(), j.destroy());
|
|
2072
2134
|
}
|
|
2073
2135
|
};
|
|
2074
2136
|
}
|
|
2075
|
-
const
|
|
2076
|
-
async function
|
|
2077
|
-
return
|
|
2137
|
+
const Yr = Object.keys(Rt);
|
|
2138
|
+
async function ir(n, e) {
|
|
2139
|
+
return sr(n, { ...e, rig: Et(e.rig) });
|
|
2078
2140
|
}
|
|
2079
|
-
function
|
|
2141
|
+
function Ye(n) {
|
|
2080
2142
|
if (!n || typeof n != "object" || Array.isArray(n))
|
|
2081
2143
|
throw new Error("avatar.json: expected an object");
|
|
2082
2144
|
const e = n, t = [];
|
|
@@ -2090,7 +2152,7 @@ function ke(n) {
|
|
|
2090
2152
|
}
|
|
2091
2153
|
if (e.lipSync !== void 0)
|
|
2092
2154
|
try {
|
|
2093
|
-
r.lipSync =
|
|
2155
|
+
r.lipSync = St(e.lipSync);
|
|
2094
2156
|
} catch (a) {
|
|
2095
2157
|
t.push(`avatar.json.lipSync: ${a instanceof Error ? a.message : String(a)}`);
|
|
2096
2158
|
}
|
|
@@ -2098,111 +2160,126 @@ function ke(n) {
|
|
|
2098
2160
|
`));
|
|
2099
2161
|
return r;
|
|
2100
2162
|
}
|
|
2101
|
-
function
|
|
2102
|
-
return
|
|
2163
|
+
function an(n) {
|
|
2164
|
+
return Ye({ format: "mesh-avatar", version: 1, name: n });
|
|
2103
2165
|
}
|
|
2104
|
-
const
|
|
2105
|
-
function
|
|
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) {
|
|
2106
2168
|
const e = [];
|
|
2107
|
-
function t(
|
|
2108
|
-
if (!
|
|
2109
|
-
|
|
2169
|
+
function t(b, v = !0) {
|
|
2170
|
+
if (!ct(n, b)) {
|
|
2171
|
+
v && e.push(`${b}: missing file`);
|
|
2110
2172
|
return;
|
|
2111
2173
|
}
|
|
2112
|
-
const
|
|
2113
|
-
if (!(
|
|
2114
|
-
e.push(`${
|
|
2174
|
+
const h = n[b];
|
|
2175
|
+
if (!(h instanceof Uint8Array)) {
|
|
2176
|
+
e.push(`${b}: JSON bytes are required`);
|
|
2115
2177
|
return;
|
|
2116
2178
|
}
|
|
2117
2179
|
let u;
|
|
2118
2180
|
try {
|
|
2119
|
-
u = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(
|
|
2181
|
+
u = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(h));
|
|
2120
2182
|
} catch {
|
|
2121
|
-
e.push(`${
|
|
2183
|
+
e.push(`${b}: invalid UTF-8 JSON`);
|
|
2122
2184
|
return;
|
|
2123
2185
|
}
|
|
2124
|
-
if (!
|
|
2125
|
-
e.push(`${
|
|
2186
|
+
if (!Je(u)) {
|
|
2187
|
+
e.push(`${b}: expected an object`);
|
|
2126
2188
|
return;
|
|
2127
2189
|
}
|
|
2128
2190
|
return u;
|
|
2129
2191
|
}
|
|
2130
|
-
function r(
|
|
2131
|
-
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);
|
|
2132
2194
|
}
|
|
2133
|
-
function a(
|
|
2134
|
-
if (!
|
|
2135
|
-
e.push(`${
|
|
2195
|
+
function a(b) {
|
|
2196
|
+
if (!ct(n, b)) {
|
|
2197
|
+
e.push(`${b}: missing file`);
|
|
2136
2198
|
return;
|
|
2137
2199
|
}
|
|
2138
|
-
const
|
|
2139
|
-
(!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`);
|
|
2140
2202
|
}
|
|
2141
|
-
function
|
|
2142
|
-
if (!
|
|
2143
|
-
e.push(`${
|
|
2203
|
+
function s(b, v, h, u) {
|
|
2204
|
+
if (!Je(b)) {
|
|
2205
|
+
e.push(`${v}.layers: expected a layer rectangle map`);
|
|
2144
2206
|
return;
|
|
2145
2207
|
}
|
|
2146
|
-
for (const [
|
|
2147
|
-
const
|
|
2148
|
-
if (!/^[A-Za-z0-9_-]+$/.test(
|
|
2149
|
-
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)`);
|
|
2150
2212
|
continue;
|
|
2151
2213
|
}
|
|
2152
|
-
!
|
|
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`);
|
|
2153
2215
|
}
|
|
2154
|
-
return
|
|
2216
|
+
return b;
|
|
2155
2217
|
}
|
|
2156
|
-
function
|
|
2157
|
-
(typeof
|
|
2218
|
+
function l(b, v) {
|
|
2219
|
+
(typeof b.build != "string" || !b.build.trim()) && e.push(`${v}.build: expected a non-empty string`);
|
|
2158
2220
|
}
|
|
2159
2221
|
const f = t("avatar.json", !1);
|
|
2160
2222
|
if (f)
|
|
2161
2223
|
try {
|
|
2162
|
-
|
|
2163
|
-
} catch (
|
|
2164
|
-
e.push(
|
|
2224
|
+
Ye(f);
|
|
2225
|
+
} catch (b) {
|
|
2226
|
+
e.push(b.message);
|
|
2165
2227
|
}
|
|
2166
|
-
const
|
|
2167
|
-
let
|
|
2168
|
-
if (
|
|
2169
|
-
const
|
|
2170
|
-
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);
|
|
2171
2233
|
}
|
|
2172
2234
|
a("built/base.png"), a("built/hairmask.png");
|
|
2173
|
-
const
|
|
2174
|
-
if (
|
|
2175
|
-
|
|
2176
|
-
let
|
|
2177
|
-
!
|
|
2178
|
-
const
|
|
2179
|
-
if (
|
|
2180
|
-
const
|
|
2181
|
-
...
|
|
2182
|
-
...
|
|
2183
|
-
...(
|
|
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)
|
|
2184
2246
|
];
|
|
2185
|
-
for (const u of
|
|
2247
|
+
for (const u of h) ct(v, u) || e.push(`built/layers.json.layers.${u}: missing required layer`);
|
|
2186
2248
|
}
|
|
2187
|
-
!Array.isArray(
|
|
2188
|
-
const
|
|
2189
|
-
if (!
|
|
2190
|
-
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`);
|
|
2191
2253
|
return;
|
|
2192
2254
|
}
|
|
2193
|
-
|
|
2194
|
-
for (const
|
|
2195
|
-
|
|
2196
|
-
if (
|
|
2197
|
-
const
|
|
2198
|
-
(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}`);
|
|
2199
2261
|
}
|
|
2200
2262
|
});
|
|
2201
2263
|
}
|
|
2202
|
-
const
|
|
2203
|
-
|
|
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;
|
|
2204
2281
|
}
|
|
2205
|
-
var ae = Uint8Array,
|
|
2282
|
+
var ae = Uint8Array, fe = Uint16Array, Lt = Int32Array, et = new ae([
|
|
2206
2283
|
0,
|
|
2207
2284
|
0,
|
|
2208
2285
|
0,
|
|
@@ -2237,7 +2314,7 @@ var ae = Uint8Array, ue = Uint16Array, St = Int32Array, Je = new ae([
|
|
|
2237
2314
|
0,
|
|
2238
2315
|
/* impossible */
|
|
2239
2316
|
0
|
|
2240
|
-
]),
|
|
2317
|
+
]), tt = new ae([
|
|
2241
2318
|
0,
|
|
2242
2319
|
0,
|
|
2243
2320
|
0,
|
|
@@ -2271,65 +2348,65 @@ var ae = Uint8Array, ue = Uint16Array, St = Int32Array, Je = new ae([
|
|
|
2271
2348
|
/* unused */
|
|
2272
2349
|
0,
|
|
2273
2350
|
0
|
|
2274
|
-
]),
|
|
2275
|
-
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)
|
|
2276
2353
|
t[r] = e += 1 << n[r - 1];
|
|
2277
|
-
for (var a = new
|
|
2278
|
-
for (var
|
|
2279
|
-
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;
|
|
2280
2357
|
return { b: t, r: a };
|
|
2281
|
-
},
|
|
2282
|
-
|
|
2283
|
-
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);
|
|
2284
2361
|
for (var re = 0; re < 32768; ++re) {
|
|
2285
|
-
var
|
|
2286
|
-
|
|
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;
|
|
2287
2364
|
}
|
|
2288
|
-
var
|
|
2289
|
-
for (var r = n.length, a = 0,
|
|
2290
|
-
n[a] && ++
|
|
2291
|
-
var
|
|
2365
|
+
var xe = (function(n, e, t) {
|
|
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);
|
|
2292
2369
|
for (a = 1; a < e; ++a)
|
|
2293
|
-
|
|
2370
|
+
l[a] = l[a - 1] + s[a - 1] << 1;
|
|
2294
2371
|
var f;
|
|
2295
2372
|
if (t) {
|
|
2296
|
-
f = new
|
|
2297
|
-
var
|
|
2373
|
+
f = new fe(1 << e);
|
|
2374
|
+
var y = 15 - e;
|
|
2298
2375
|
for (a = 0; a < r; ++a)
|
|
2299
2376
|
if (n[a])
|
|
2300
|
-
for (var
|
|
2301
|
-
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;
|
|
2302
2379
|
} else
|
|
2303
|
-
for (f = new
|
|
2304
|
-
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]);
|
|
2305
2382
|
return f;
|
|
2306
|
-
}),
|
|
2383
|
+
}), Te = new ae(288);
|
|
2307
2384
|
for (var re = 0; re < 144; ++re)
|
|
2308
|
-
|
|
2385
|
+
Te[re] = 8;
|
|
2309
2386
|
for (var re = 144; re < 256; ++re)
|
|
2310
|
-
|
|
2387
|
+
Te[re] = 9;
|
|
2311
2388
|
for (var re = 256; re < 280; ++re)
|
|
2312
|
-
|
|
2389
|
+
Te[re] = 7;
|
|
2313
2390
|
for (var re = 280; re < 288; ++re)
|
|
2314
|
-
|
|
2315
|
-
var
|
|
2391
|
+
Te[re] = 8;
|
|
2392
|
+
var De = new ae(32);
|
|
2316
2393
|
for (var re = 0; re < 32; ++re)
|
|
2317
|
-
|
|
2318
|
-
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) {
|
|
2319
2396
|
for (var e = n[0], t = 1; t < n.length; ++t)
|
|
2320
2397
|
n[t] > e && (e = n[t]);
|
|
2321
2398
|
return e;
|
|
2322
|
-
},
|
|
2399
|
+
}, de = function(n, e, t) {
|
|
2323
2400
|
var r = e / 8 | 0;
|
|
2324
2401
|
return (n[r] | n[r + 1] << 8) >> (e & 7) & t;
|
|
2325
|
-
},
|
|
2402
|
+
}, ut = function(n, e) {
|
|
2326
2403
|
var t = e / 8 | 0;
|
|
2327
2404
|
return (n[t] | n[t + 1] << 8 | n[t + 2] << 16) >> (e & 7);
|
|
2328
|
-
},
|
|
2405
|
+
}, _t = function(n) {
|
|
2329
2406
|
return (n + 7) / 8 | 0;
|
|
2330
|
-
},
|
|
2407
|
+
}, He = function(n, e, t) {
|
|
2331
2408
|
return (e == null || e < 0) && (e = 0), (t == null || t > n.length) && (t = n.length), new ae(n.subarray(e, t));
|
|
2332
|
-
},
|
|
2409
|
+
}, mr = [
|
|
2333
2410
|
"unexpected EOF",
|
|
2334
2411
|
"invalid block type",
|
|
2335
2412
|
"invalid length/literal",
|
|
@@ -2346,649 +2423,653 @@ var or = /* @__PURE__ */ be(Se, 9, 0), sr = /* @__PURE__ */ be(Se, 9, 1), ir = /
|
|
|
2346
2423
|
"stream finishing",
|
|
2347
2424
|
"invalid zip data"
|
|
2348
2425
|
// determined by unknown compression method
|
|
2349
|
-
],
|
|
2350
|
-
var r = new Error(e ||
|
|
2351
|
-
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)
|
|
2352
2429
|
throw r;
|
|
2353
2430
|
return r;
|
|
2354
|
-
},
|
|
2355
|
-
var a = n.length,
|
|
2431
|
+
}, pr = function(n, e, t, r) {
|
|
2432
|
+
var a = n.length, s = r ? r.length : 0;
|
|
2356
2433
|
if (!a || e.f && !e.l)
|
|
2357
2434
|
return t || new ae(0);
|
|
2358
|
-
var
|
|
2359
|
-
|
|
2360
|
-
var
|
|
2361
|
-
var
|
|
2362
|
-
if (F >
|
|
2363
|
-
var
|
|
2364
|
-
|
|
2365
|
-
}
|
|
2366
|
-
},
|
|
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;
|
|
2367
2444
|
do {
|
|
2368
|
-
if (!
|
|
2369
|
-
|
|
2370
|
-
var
|
|
2371
|
-
if (
|
|
2372
|
-
if (
|
|
2373
|
-
|
|
2374
|
-
else if (
|
|
2375
|
-
var
|
|
2376
|
-
|
|
2377
|
-
for (var
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
for (var O =
|
|
2381
|
-
var
|
|
2382
|
-
|
|
2383
|
-
var
|
|
2384
|
-
if (
|
|
2385
|
-
|
|
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;
|
|
2386
2463
|
else {
|
|
2387
|
-
var
|
|
2388
|
-
for (
|
|
2389
|
-
|
|
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;
|
|
2390
2467
|
}
|
|
2391
2468
|
}
|
|
2392
|
-
var H =
|
|
2393
|
-
|
|
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);
|
|
2394
2471
|
} else
|
|
2395
|
-
|
|
2472
|
+
he(1);
|
|
2396
2473
|
else {
|
|
2397
|
-
var
|
|
2398
|
-
if (
|
|
2399
|
-
|
|
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);
|
|
2400
2477
|
break;
|
|
2401
2478
|
}
|
|
2402
|
-
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;
|
|
2403
2480
|
continue;
|
|
2404
2481
|
}
|
|
2405
|
-
if (
|
|
2406
|
-
|
|
2482
|
+
if (c > w) {
|
|
2483
|
+
y && he(0);
|
|
2407
2484
|
break;
|
|
2408
2485
|
}
|
|
2409
2486
|
}
|
|
2410
|
-
f &&
|
|
2411
|
-
for (var
|
|
2412
|
-
var
|
|
2413
|
-
if (
|
|
2414
|
-
|
|
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);
|
|
2415
2492
|
break;
|
|
2416
2493
|
}
|
|
2417
|
-
if (
|
|
2418
|
-
t[
|
|
2419
|
-
else if (
|
|
2420
|
-
|
|
2494
|
+
if (N || he(2), V < 256)
|
|
2495
|
+
t[p++] = V;
|
|
2496
|
+
else if (V == 256) {
|
|
2497
|
+
I = c, b = null;
|
|
2421
2498
|
break;
|
|
2422
2499
|
} else {
|
|
2423
|
-
var
|
|
2424
|
-
if (
|
|
2425
|
-
var U =
|
|
2426
|
-
|
|
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;
|
|
2427
2504
|
}
|
|
2428
|
-
var
|
|
2429
|
-
|
|
2430
|
-
var
|
|
2431
|
-
if (
|
|
2432
|
-
var
|
|
2433
|
-
|
|
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;
|
|
2434
2511
|
}
|
|
2435
|
-
if (
|
|
2436
|
-
|
|
2512
|
+
if (c > w) {
|
|
2513
|
+
y && he(0);
|
|
2437
2514
|
break;
|
|
2438
2515
|
}
|
|
2439
|
-
f &&
|
|
2440
|
-
var
|
|
2441
|
-
if (
|
|
2442
|
-
var
|
|
2443
|
-
for (
|
|
2444
|
-
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];
|
|
2445
2522
|
}
|
|
2446
|
-
for (;
|
|
2447
|
-
t[
|
|
2523
|
+
for (; p < _; ++p)
|
|
2524
|
+
t[p] = t[p - G];
|
|
2448
2525
|
}
|
|
2449
2526
|
}
|
|
2450
|
-
e.l =
|
|
2451
|
-
} while (!
|
|
2452
|
-
return
|
|
2453
|
-
},
|
|
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) {
|
|
2454
2531
|
t <<= e & 7;
|
|
2455
2532
|
var r = e / 8 | 0;
|
|
2456
2533
|
n[r] |= t, n[r + 1] |= t >> 8;
|
|
2457
|
-
},
|
|
2534
|
+
}, $e = function(n, e, t) {
|
|
2458
2535
|
t <<= e & 7;
|
|
2459
2536
|
var r = e / 8 | 0;
|
|
2460
2537
|
n[r] |= t, n[r + 1] |= t >> 8, n[r + 2] |= t >> 16;
|
|
2461
|
-
},
|
|
2538
|
+
}, ft = function(n, e) {
|
|
2462
2539
|
for (var t = [], r = 0; r < n.length; ++r)
|
|
2463
2540
|
n[r] && t.push({ s: r, f: n[r] });
|
|
2464
|
-
var a = t.length,
|
|
2541
|
+
var a = t.length, s = t.slice();
|
|
2465
2542
|
if (!a)
|
|
2466
|
-
return { t:
|
|
2543
|
+
return { t: fn, l: 0 };
|
|
2467
2544
|
if (a == 1) {
|
|
2468
|
-
var
|
|
2469
|
-
return
|
|
2545
|
+
var l = new ae(t[0].s + 1);
|
|
2546
|
+
return l[t[0].s] = 1, { t: l, l: 1 };
|
|
2470
2547
|
}
|
|
2471
|
-
t.sort(function(
|
|
2472
|
-
return
|
|
2548
|
+
t.sort(function(g, A) {
|
|
2549
|
+
return g.f - A.f;
|
|
2473
2550
|
}), t.push({ s: -1, f: 25001 });
|
|
2474
|
-
var f = t[0],
|
|
2475
|
-
for (t[0] = { s: -1, f: f.f +
|
|
2476
|
-
f = t[t[
|
|
2477
|
-
for (var
|
|
2478
|
-
|
|
2479
|
-
var
|
|
2480
|
-
if (
|
|
2481
|
-
var r = 0,
|
|
2482
|
-
for (
|
|
2483
|
-
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;
|
|
2484
2561
|
}); r < a; ++r) {
|
|
2485
|
-
var
|
|
2486
|
-
if (
|
|
2487
|
-
|
|
2562
|
+
var o = s[r].s;
|
|
2563
|
+
if (b[o] > e)
|
|
2564
|
+
h += w - (1 << v - b[o]), b[o] = e;
|
|
2488
2565
|
else
|
|
2489
2566
|
break;
|
|
2490
2567
|
}
|
|
2491
|
-
for (
|
|
2492
|
-
var
|
|
2493
|
-
|
|
2568
|
+
for (h >>= u; h > 0; ) {
|
|
2569
|
+
var i = s[r].s;
|
|
2570
|
+
b[i] < e ? h -= 1 << e - b[i]++ - 1 : ++r;
|
|
2494
2571
|
}
|
|
2495
|
-
for (; r >= 0 &&
|
|
2496
|
-
var
|
|
2497
|
-
S
|
|
2572
|
+
for (; r >= 0 && h; --r) {
|
|
2573
|
+
var S = s[r].s;
|
|
2574
|
+
b[S] == e && (--b[S], ++h);
|
|
2498
2575
|
}
|
|
2499
|
-
|
|
2576
|
+
v = e;
|
|
2500
2577
|
}
|
|
2501
|
-
return { t: new ae(
|
|
2502
|
-
},
|
|
2503
|
-
return n.s == -1 ? Math.max(
|
|
2504
|
-
},
|
|
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) {
|
|
2505
2582
|
for (var e = n.length; e && !n[--e]; )
|
|
2506
2583
|
;
|
|
2507
|
-
for (var t = new
|
|
2508
|
-
t[r++] =
|
|
2584
|
+
for (var t = new fe(++e), r = 0, a = n[0], s = 1, l = function(y) {
|
|
2585
|
+
t[r++] = y;
|
|
2509
2586
|
}, f = 1; f <= e; ++f)
|
|
2510
2587
|
if (n[f] == a && f != e)
|
|
2511
|
-
++
|
|
2588
|
+
++s;
|
|
2512
2589
|
else {
|
|
2513
|
-
if (!a &&
|
|
2514
|
-
for (;
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
} else if (
|
|
2518
|
-
for (
|
|
2519
|
-
|
|
2520
|
-
|
|
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);
|
|
2521
2598
|
}
|
|
2522
|
-
for (;
|
|
2523
|
-
|
|
2524
|
-
|
|
2599
|
+
for (; s--; )
|
|
2600
|
+
l(a);
|
|
2601
|
+
s = 1, a = n[f];
|
|
2525
2602
|
}
|
|
2526
2603
|
return { c: t.subarray(0, r), n: e };
|
|
2527
|
-
},
|
|
2604
|
+
}, ze = function(n, e) {
|
|
2528
2605
|
for (var t = 0, r = 0; r < e.length; ++r)
|
|
2529
2606
|
t += n[r] * e[r];
|
|
2530
2607
|
return t;
|
|
2531
|
-
},
|
|
2532
|
-
var r = t.length, a =
|
|
2608
|
+
}, un = function(n, e, t) {
|
|
2609
|
+
var r = t.length, a = _t(e + 2);
|
|
2533
2610
|
n[a] = r & 255, n[a + 1] = r >> 8, n[a + 2] = n[a] ^ 255, n[a + 3] = n[a + 1] ^ 255;
|
|
2534
|
-
for (var
|
|
2535
|
-
n[a +
|
|
2611
|
+
for (var s = 0; s < r; ++s)
|
|
2612
|
+
n[a + s + 4] = t[s];
|
|
2536
2613
|
return (a + 4 + r) * 8;
|
|
2537
|
-
},
|
|
2538
|
-
|
|
2539
|
-
for (var
|
|
2540
|
-
++
|
|
2541
|
-
for (var
|
|
2542
|
-
++
|
|
2543
|
-
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)
|
|
2544
2621
|
;
|
|
2545
|
-
var
|
|
2546
|
-
if (
|
|
2547
|
-
return
|
|
2548
|
-
var
|
|
2549
|
-
if (
|
|
2550
|
-
|
|
2551
|
-
var
|
|
2552
|
-
|
|
2553
|
-
for (var
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
for (var
|
|
2557
|
-
for (var
|
|
2558
|
-
var
|
|
2559
|
-
|
|
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);
|
|
2560
2637
|
}
|
|
2561
2638
|
} else
|
|
2562
|
-
|
|
2563
|
-
for (var
|
|
2564
|
-
var
|
|
2565
|
-
if (
|
|
2566
|
-
var
|
|
2567
|
-
|
|
2568
|
-
var
|
|
2569
|
-
|
|
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]);
|
|
2570
2647
|
} else
|
|
2571
|
-
|
|
2648
|
+
$e(e, m, N[x]), m += P[x];
|
|
2572
2649
|
}
|
|
2573
|
-
return
|
|
2574
|
-
},
|
|
2575
|
-
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;
|
|
2576
2653
|
if (e) {
|
|
2577
|
-
|
|
2578
|
-
for (var
|
|
2579
|
-
return (n[
|
|
2580
|
-
},
|
|
2581
|
-
var
|
|
2582
|
-
if (
|
|
2583
|
-
var
|
|
2584
|
-
if ((
|
|
2585
|
-
|
|
2586
|
-
for (var
|
|
2587
|
-
|
|
2588
|
-
for (var
|
|
2589
|
-
|
|
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;
|
|
2590
2667
|
}
|
|
2591
|
-
var H = 2,
|
|
2592
|
-
if (
|
|
2593
|
-
for (var
|
|
2594
|
-
if (n[
|
|
2595
|
-
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)
|
|
2596
2673
|
;
|
|
2597
|
-
if (
|
|
2598
|
-
if (H =
|
|
2674
|
+
if (x > H) {
|
|
2675
|
+
if (H = x, G = W, x > I)
|
|
2599
2676
|
break;
|
|
2600
|
-
for (var
|
|
2601
|
-
var
|
|
2602
|
-
|
|
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 = _);
|
|
2603
2680
|
}
|
|
2604
2681
|
}
|
|
2605
2682
|
}
|
|
2606
|
-
|
|
2683
|
+
D = q, q = h[D], W += D - q & 32767;
|
|
2607
2684
|
}
|
|
2608
|
-
if (
|
|
2609
|
-
|
|
2610
|
-
var F =
|
|
2611
|
-
|
|
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;
|
|
2612
2689
|
} else
|
|
2613
|
-
|
|
2690
|
+
S[k++] = n[j], ++g[n[j]];
|
|
2614
2691
|
}
|
|
2615
2692
|
}
|
|
2616
|
-
for (
|
|
2617
|
-
|
|
2618
|
-
|
|
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);
|
|
2619
2696
|
} else {
|
|
2620
|
-
for (var
|
|
2621
|
-
var
|
|
2622
|
-
|
|
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));
|
|
2623
2700
|
}
|
|
2624
|
-
|
|
2701
|
+
s.i = l;
|
|
2625
2702
|
}
|
|
2626
|
-
return
|
|
2627
|
-
},
|
|
2703
|
+
return He(f, 0, r + _t(m) + a);
|
|
2704
|
+
}, yr = /* @__PURE__ */ (function() {
|
|
2628
2705
|
for (var n = new Int32Array(256), e = 0; e < 256; ++e) {
|
|
2629
2706
|
for (var t = e, r = 9; --r; )
|
|
2630
2707
|
t = (t & 1 && -306674912) ^ t >>> 1;
|
|
2631
2708
|
n[e] = t;
|
|
2632
2709
|
}
|
|
2633
2710
|
return n;
|
|
2634
|
-
})(),
|
|
2711
|
+
})(), vr = function() {
|
|
2635
2712
|
var n = -1;
|
|
2636
2713
|
return {
|
|
2637
2714
|
p: function(e) {
|
|
2638
2715
|
for (var t = n, r = 0; r < e.length; ++r)
|
|
2639
|
-
t =
|
|
2716
|
+
t = yr[t & 255 ^ e[r]] ^ t >>> 8;
|
|
2640
2717
|
n = t;
|
|
2641
2718
|
},
|
|
2642
2719
|
d: function() {
|
|
2643
2720
|
return ~n;
|
|
2644
2721
|
}
|
|
2645
2722
|
};
|
|
2646
|
-
},
|
|
2723
|
+
}, br = function(n, e, t, r, a) {
|
|
2647
2724
|
if (!a && (a = { l: 1 }, e.dictionary)) {
|
|
2648
|
-
var
|
|
2649
|
-
|
|
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;
|
|
2650
2727
|
}
|
|
2651
|
-
return
|
|
2652
|
-
},
|
|
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) {
|
|
2653
2730
|
var t = {};
|
|
2654
2731
|
for (var r in n)
|
|
2655
2732
|
t[r] = n[r];
|
|
2656
2733
|
for (var r in e)
|
|
2657
2734
|
t[r] = e[r];
|
|
2658
2735
|
return t;
|
|
2659
|
-
},
|
|
2736
|
+
}, be = function(n, e) {
|
|
2660
2737
|
return n[e] | n[e + 1] << 8;
|
|
2661
|
-
},
|
|
2738
|
+
}, me = function(n, e) {
|
|
2662
2739
|
return (n[e] | n[e + 1] << 8 | n[e + 2] << 16 | n[e + 3] << 24) >>> 0;
|
|
2663
|
-
},
|
|
2664
|
-
return
|
|
2740
|
+
}, mt = function(n, e) {
|
|
2741
|
+
return me(n, e) + me(n, e + 4) * 4294967296;
|
|
2665
2742
|
}, ie = function(n, e, t) {
|
|
2666
2743
|
for (; t; ++e)
|
|
2667
2744
|
n[e] = t, t >>>= 8;
|
|
2668
2745
|
};
|
|
2669
|
-
function
|
|
2670
|
-
return
|
|
2746
|
+
function xr(n, e) {
|
|
2747
|
+
return br(n, e || {}, 0, 0);
|
|
2671
2748
|
}
|
|
2672
|
-
function
|
|
2673
|
-
return
|
|
2749
|
+
function wr(n, e) {
|
|
2750
|
+
return pr(n, { i: 2 }, e && e.out, e && e.dictionary);
|
|
2674
2751
|
}
|
|
2675
|
-
var
|
|
2752
|
+
var pn = function(n, e, t, r) {
|
|
2676
2753
|
for (var a in n) {
|
|
2677
|
-
var
|
|
2678
|
-
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));
|
|
2679
2756
|
}
|
|
2680
|
-
},
|
|
2757
|
+
}, Jt = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), bt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), Ar = 0;
|
|
2681
2758
|
try {
|
|
2682
|
-
|
|
2759
|
+
bt.decode(fn, { stream: !0 }), Ar = 1;
|
|
2683
2760
|
} catch {
|
|
2684
2761
|
}
|
|
2685
|
-
var
|
|
2762
|
+
var Mr = function(n) {
|
|
2686
2763
|
for (var e = "", t = 0; ; ) {
|
|
2687
2764
|
var r = n[t++], a = (r > 127) + (r > 223) + (r > 239);
|
|
2688
2765
|
if (t + a > n.length)
|
|
2689
|
-
return { s: e, r:
|
|
2766
|
+
return { s: e, r: He(n, t - 1) };
|
|
2690
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);
|
|
2691
2768
|
}
|
|
2692
2769
|
};
|
|
2693
|
-
function
|
|
2770
|
+
function Kt(n, e) {
|
|
2694
2771
|
var t;
|
|
2695
|
-
if (
|
|
2696
|
-
return
|
|
2697
|
-
for (var r = n.length, a = new ae(n.length + (n.length >> 1)),
|
|
2698
|
-
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;
|
|
2699
2776
|
}, t = 0; t < r; ++t) {
|
|
2700
|
-
if (
|
|
2701
|
-
var f = new ae(
|
|
2777
|
+
if (s + 5 > a.length) {
|
|
2778
|
+
var f = new ae(s + 8 + (r - t << 1));
|
|
2702
2779
|
f.set(a), a = f;
|
|
2703
2780
|
}
|
|
2704
|
-
var
|
|
2705
|
-
|
|
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));
|
|
2706
2783
|
}
|
|
2707
|
-
return
|
|
2784
|
+
return He(a, 0, s);
|
|
2708
2785
|
}
|
|
2709
|
-
function
|
|
2786
|
+
function Er(n, e) {
|
|
2710
2787
|
if (e) {
|
|
2711
2788
|
for (var t = "", r = 0; r < n.length; r += 16384)
|
|
2712
2789
|
t += String.fromCharCode.apply(null, n.subarray(r, r + 16384));
|
|
2713
2790
|
return t;
|
|
2714
2791
|
} else {
|
|
2715
|
-
if (
|
|
2716
|
-
return
|
|
2717
|
-
var a =
|
|
2718
|
-
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;
|
|
2719
2796
|
}
|
|
2720
2797
|
}
|
|
2721
|
-
var
|
|
2722
|
-
return e + 30 +
|
|
2723
|
-
},
|
|
2724
|
-
var r =
|
|
2725
|
-
return [
|
|
2726
|
-
},
|
|
2727
|
-
var f = a == 4294967295,
|
|
2728
|
-
if (r &&
|
|
2729
|
-
for (; e + 4 <
|
|
2730
|
-
if (
|
|
2798
|
+
var Sr = function(n, e) {
|
|
2799
|
+
return e + 30 + be(n, e + 26) + be(n, e + 28);
|
|
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))
|
|
2807
|
+
if (be(n, e) == 1)
|
|
2731
2808
|
return [
|
|
2732
|
-
f ?
|
|
2733
|
-
|
|
2734
|
-
|
|
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,
|
|
2735
2812
|
1
|
|
2736
2813
|
];
|
|
2737
|
-
r < 2 &&
|
|
2814
|
+
r < 2 && he(13);
|
|
2738
2815
|
}
|
|
2739
|
-
return [a,
|
|
2740
|
-
},
|
|
2816
|
+
return [a, s, l, 0];
|
|
2817
|
+
}, xt = function(n) {
|
|
2741
2818
|
var e = 0;
|
|
2742
2819
|
if (n)
|
|
2743
2820
|
for (var t in n) {
|
|
2744
2821
|
var r = n[t].length;
|
|
2745
|
-
r > 65535 &&
|
|
2822
|
+
r > 65535 && he(9), e += r + 4;
|
|
2746
2823
|
}
|
|
2747
2824
|
return e;
|
|
2748
|
-
},
|
|
2749
|
-
var
|
|
2750
|
-
ie(n, e,
|
|
2751
|
-
var
|
|
2752
|
-
if ((
|
|
2753
|
-
for (var
|
|
2754
|
-
var
|
|
2755
|
-
ie(n, e, +
|
|
2756
|
-
}
|
|
2757
|
-
return
|
|
2758
|
-
},
|
|
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) {
|
|
2759
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);
|
|
2760
2837
|
};
|
|
2761
|
-
function
|
|
2838
|
+
function Lr(n, e) {
|
|
2762
2839
|
e || (e = {});
|
|
2763
2840
|
var t = {}, r = [];
|
|
2764
|
-
|
|
2765
|
-
var a = 0,
|
|
2766
|
-
for (var
|
|
2767
|
-
var f = t[
|
|
2768
|
-
|
|
2769
|
-
var
|
|
2770
|
-
|
|
2771
|
-
size:
|
|
2772
|
-
crc:
|
|
2773
|
-
c:
|
|
2774
|
-
f:
|
|
2775
|
-
m:
|
|
2776
|
-
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,
|
|
2777
2854
|
o: a,
|
|
2778
|
-
compression:
|
|
2779
|
-
})), a += 30 +
|
|
2855
|
+
compression: m
|
|
2856
|
+
})), a += 30 + p + u + o, s += 76 + 2 * (p + u) + (h || 0) + o;
|
|
2780
2857
|
}
|
|
2781
|
-
for (var
|
|
2782
|
-
var
|
|
2783
|
-
|
|
2784
|
-
var
|
|
2785
|
-
|
|
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);
|
|
2786
2863
|
}
|
|
2787
|
-
return
|
|
2864
|
+
return Rr(S, a, r.length, A, g), S;
|
|
2788
2865
|
}
|
|
2789
|
-
function
|
|
2790
|
-
for (var t = {}, r = n.length - 22;
|
|
2791
|
-
(!r || n.length - r > 65558) &&
|
|
2792
|
-
var a =
|
|
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);
|
|
2869
|
+
var a = be(n, r + 8);
|
|
2793
2870
|
if (!a)
|
|
2794
2871
|
return {};
|
|
2795
|
-
var
|
|
2796
|
-
if (
|
|
2797
|
-
var f =
|
|
2798
|
-
|
|
2799
|
-
}
|
|
2800
|
-
for (var
|
|
2801
|
-
var
|
|
2802
|
-
|
|
2803
|
-
name:
|
|
2804
|
-
size:
|
|
2805
|
-
originalSize:
|
|
2806
|
-
compression:
|
|
2807
|
-
})) && (
|
|
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));
|
|
2808
2885
|
}
|
|
2809
2886
|
return t;
|
|
2810
2887
|
}
|
|
2811
|
-
const
|
|
2812
|
-
function
|
|
2888
|
+
const Qe = 200, wt = 64 * 1024 * 1024, At = new TextDecoder("utf-8", { fatal: !0 });
|
|
2889
|
+
function kt(n) {
|
|
2813
2890
|
if (!n || n.startsWith("/") || /^[A-Za-z]:/.test(n) || n.includes("\\") || n.includes("\0") || n.split("/").includes(".."))
|
|
2814
2891
|
throw new Error(`ZIP entry ${JSON.stringify(n)}: path must be relative, without .. or backslashes`);
|
|
2815
2892
|
}
|
|
2816
|
-
function
|
|
2817
|
-
const e = new DataView(n.buffer, n.byteOffset, n.byteLength), t = (
|
|
2818
|
-
throw new Error(`ZIP entry ${JSON.stringify(
|
|
2819
|
-
}, r = (
|
|
2820
|
-
let
|
|
2821
|
-
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--)
|
|
2822
2899
|
;
|
|
2823
|
-
(
|
|
2824
|
-
const
|
|
2825
|
-
|
|
2826
|
-
const
|
|
2827
|
-
let
|
|
2828
|
-
for (let
|
|
2829
|
-
(
|
|
2830
|
-
const
|
|
2831
|
-
|
|
2832
|
-
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;
|
|
2833
2910
|
try {
|
|
2834
|
-
|
|
2911
|
+
h = At.decode(n.subarray(c + 46, c + 46 + b));
|
|
2835
2912
|
} catch {
|
|
2836
2913
|
throw new Error("ZIP entry (invalid UTF-8 name): invalid filename");
|
|
2837
2914
|
}
|
|
2838
|
-
if (
|
|
2839
|
-
if (
|
|
2840
|
-
|
|
2841
|
-
const
|
|
2842
|
-
if (
|
|
2843
|
-
if (r(
|
|
2844
|
-
if (r(
|
|
2845
|
-
(
|
|
2846
|
-
const
|
|
2847
|
-
(
|
|
2848
|
-
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;
|
|
2849
2926
|
try {
|
|
2850
|
-
|
|
2927
|
+
S = At.decode(n.subarray(o + 30, o + 30 + r(o + 26)));
|
|
2851
2928
|
} catch {
|
|
2852
|
-
t(
|
|
2929
|
+
t(h);
|
|
2853
2930
|
}
|
|
2854
|
-
|
|
2931
|
+
S !== h && t(h), d.push({ name: h, offset: o, start: i, size: u, central: c }), c = v;
|
|
2855
2932
|
}
|
|
2856
|
-
return
|
|
2933
|
+
return c !== y && t(), { files: d };
|
|
2857
2934
|
}
|
|
2858
|
-
function
|
|
2859
|
-
const e = n instanceof Uint8Array ? n : new Uint8Array(n), t =
|
|
2860
|
-
for (const
|
|
2861
|
-
const
|
|
2862
|
-
if (!(
|
|
2863
|
-
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;
|
|
2864
2941
|
}
|
|
2865
2942
|
return a;
|
|
2866
2943
|
}
|
|
2867
|
-
function
|
|
2868
|
-
const t = Object.hasOwn(n, "avatar.json") ? n["avatar.json"] : void 0, r = t ?
|
|
2869
|
-
`),
|
|
2870
|
-
|
|
2871
|
-
for (const [
|
|
2872
|
-
for (const [
|
|
2873
|
-
if (
|
|
2874
|
-
if (
|
|
2875
|
-
}
|
|
2876
|
-
const
|
|
2877
|
-
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(`
|
|
2878
2955
|
`));
|
|
2879
2956
|
let f = "proto0000";
|
|
2880
|
-
for (let
|
|
2881
|
-
const
|
|
2882
|
-
if (Object.hasOwn(
|
|
2883
|
-
const
|
|
2884
|
-
|
|
2885
|
-
}
|
|
2886
|
-
const
|
|
2887
|
-
if (
|
|
2888
|
-
const
|
|
2889
|
-
|
|
2890
|
-
const
|
|
2891
|
-
for (const
|
|
2892
|
-
return
|
|
2893
|
-
}
|
|
2894
|
-
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;
|
|
2895
2972
|
}
|
|
2896
|
-
const
|
|
2897
|
-
function
|
|
2973
|
+
const Fr = (n) => JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(n));
|
|
2974
|
+
function Be(n, e) {
|
|
2898
2975
|
try {
|
|
2899
|
-
return
|
|
2976
|
+
return Fr(n);
|
|
2900
2977
|
} catch {
|
|
2901
2978
|
throw new Error(`${e}: invalid UTF-8 JSON`);
|
|
2902
2979
|
}
|
|
2903
2980
|
}
|
|
2904
|
-
function
|
|
2981
|
+
function dn(n, e, t) {
|
|
2905
2982
|
return [
|
|
2906
2983
|
"layers.json",
|
|
2907
2984
|
"base.png",
|
|
2908
2985
|
"hairmask.png",
|
|
2909
|
-
...Object.keys(n?.layers ?? {}).map((
|
|
2910
|
-
...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}`] : [])] : []
|
|
2911
2990
|
];
|
|
2912
2991
|
}
|
|
2913
|
-
function
|
|
2914
|
-
const e =
|
|
2992
|
+
function gn(n) {
|
|
2993
|
+
const e = on(n);
|
|
2915
2994
|
if (e.length) throw new Error(e.join(`
|
|
2916
2995
|
`));
|
|
2917
2996
|
}
|
|
2918
|
-
function
|
|
2997
|
+
function yn(n) {
|
|
2919
2998
|
return !!n && typeof n == "object" && "manifest" in n && "rig" in n && "assets" in n && "release" in n;
|
|
2920
2999
|
}
|
|
2921
|
-
function
|
|
2922
|
-
const e =
|
|
3000
|
+
function pt(n) {
|
|
3001
|
+
const e = kr(n);
|
|
2923
3002
|
if (!Object.hasOwn(e, "avatar.json")) throw new Error("avatar.json: missing file in .mavatar archive");
|
|
2924
|
-
|
|
2925
|
-
const t =
|
|
2926
|
-
|
|
2927
|
-
e["built/sprites/sprites.json"] ?
|
|
2928
|
-
|
|
2929
|
-
|
|
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));
|
|
2930
3010
|
};
|
|
2931
3011
|
try {
|
|
2932
|
-
for (const
|
|
2933
|
-
const
|
|
2934
|
-
|
|
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;
|
|
2935
3015
|
}
|
|
2936
|
-
} catch (
|
|
2937
|
-
throw
|
|
3016
|
+
} catch (d) {
|
|
3017
|
+
throw y(), d;
|
|
2938
3018
|
}
|
|
2939
|
-
return { manifest: t, rig: r, assets:
|
|
3019
|
+
return { manifest: t, rig: r, assets: l, release: y };
|
|
2940
3020
|
}
|
|
2941
|
-
async function
|
|
2942
|
-
if (
|
|
2943
|
-
if (n instanceof Blob) return
|
|
2944
|
-
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);
|
|
2945
3025
|
const t = new URL(n, typeof location > "u" ? void 0 : location.href);
|
|
2946
3026
|
if (/\.mavatar$/i.test(t.pathname)) {
|
|
2947
3027
|
const u = await fetch(t);
|
|
2948
3028
|
if (!u.ok) throw new Error(`.mavatar: could not load (${u.status})`);
|
|
2949
|
-
return
|
|
3029
|
+
return pt(await u.arrayBuffer());
|
|
2950
3030
|
}
|
|
2951
3031
|
t.pathname.endsWith("/") || (t.pathname += "/");
|
|
2952
3032
|
const r = (u) => {
|
|
2953
|
-
const
|
|
2954
|
-
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;
|
|
2955
3035
|
}, a = {};
|
|
2956
|
-
async function
|
|
2957
|
-
const
|
|
2958
|
-
if (
|
|
2959
|
-
if (!
|
|
2960
|
-
const
|
|
2961
|
-
return a[u] =
|
|
2962
|
-
}
|
|
2963
|
-
const
|
|
2964
|
-
|
|
2965
|
-
const [f,
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
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)
|
|
2970
3051
|
]);
|
|
2971
|
-
Array.isArray(f?.eyes) && Array.isArray(
|
|
3052
|
+
Array.isArray(f?.eyes) && Array.isArray(y?.eyes) && (f.eyes = f.eyes.map((u, w) => {
|
|
2972
3053
|
if (!u || typeof u != "object") return u;
|
|
2973
|
-
const
|
|
2974
|
-
for (const
|
|
2975
|
-
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;
|
|
2976
3057
|
})), a["rig.json"] = new TextEncoder().encode(JSON.stringify(f));
|
|
2977
|
-
const
|
|
2978
|
-
for (const u of
|
|
2979
|
-
|
|
2980
|
-
const
|
|
2981
|
-
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() {
|
|
2982
3063
|
} };
|
|
2983
3064
|
}
|
|
2984
|
-
async function
|
|
2985
|
-
const r = !
|
|
3065
|
+
async function Ir(n, e, t = {}) {
|
|
3066
|
+
const r = !yn(e), a = await Br(e);
|
|
2986
3067
|
try {
|
|
2987
|
-
const
|
|
2988
|
-
let
|
|
2989
|
-
return Object.assign(
|
|
2990
|
-
if (!
|
|
2991
|
-
|
|
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;
|
|
2992
3073
|
try {
|
|
2993
3074
|
f();
|
|
2994
3075
|
} finally {
|
|
@@ -2996,23 +3077,23 @@ async function Br(n, e, t = {}) {
|
|
|
2996
3077
|
}
|
|
2997
3078
|
}
|
|
2998
3079
|
} });
|
|
2999
|
-
} catch (
|
|
3000
|
-
throw r && a.release(),
|
|
3080
|
+
} catch (s) {
|
|
3081
|
+
throw r && a.release(), s;
|
|
3001
3082
|
}
|
|
3002
3083
|
}
|
|
3003
3084
|
export {
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
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
|
|
3018
3099
|
};
|