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