three-mediapipe-rig 0.1.3 → 0.1.4

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/meshcap.js CHANGED
@@ -1,468 +1,572 @@
1
- import { inflate as xt, deflate as Mt } from "fflate";
2
- import { c as At, F as X } from "./face-tracker-utils-xt9__vBF.js";
3
- import { MeshPhysicalNodeMaterial as Ct, Vector3 as et } from "three/webgpu";
4
- import { instancedArray as H, texture as it, uniform as K, attribute as bt, varying as St, vec3 as It, float as kt } from "three/tsl";
5
- const dt = 1296253264, Rt = 2;
6
- async function Vt(a) {
7
- if (a instanceof ArrayBuffer)
8
- return a;
9
- if (a instanceof File || a instanceof Blob)
10
- return a.arrayBuffer();
11
- if (typeof a == "string")
12
- return (await fetch(a)).arrayBuffer();
13
- throw new Error(`Unsupported audio source type: ${typeof a}`);
1
+ import { MeshPhysicalNodeMaterial as Lt, Vector3 as _, Matrix4 as Bt } from "three/webgpu";
2
+ import { deflate as St, inflate as Tt } from "fflate";
3
+ import { c as Vt, F as $ } from "./face-tracker-utils-xt9__vBF.js";
4
+ import { instancedArray as K, texture as mt, uniform as tt, attribute as zt, varying as Ft, vec3 as Et, float as Pt, select as Ot, positionLocal as jt } from "three/tsl";
5
+ import { TextureLoader as pt, Texture as Nt } from "three";
6
+ const wt = 1296253264, Wt = 3;
7
+ async function Dt(o) {
8
+ if (o instanceof ArrayBuffer)
9
+ return o;
10
+ if (o instanceof File || o instanceof Blob)
11
+ return o.arrayBuffer();
12
+ if (typeof o == "string")
13
+ return (await fetch(o)).arrayBuffer();
14
+ throw new Error(`Unsupported audio source type: ${typeof o}`);
14
15
  }
15
- async function Lt(a, d) {
16
- const i = new AudioContext(), o = await Vt(a), e = await i.decodeAudioData(o);
17
- for (const l of d) {
18
- if (!l.audioSprite)
16
+ async function Xt(o, s) {
17
+ const a = new AudioContext(), i = await Dt(o), n = await a.decodeAudioData(i);
18
+ for (const t of s) {
19
+ if (!t.audioSprite)
19
20
  continue;
20
- const v = Math.floor(l.audioSprite.start * e.sampleRate), x = Math.floor(l.duration * e.sampleRate), f = i.createBuffer(
21
- e.numberOfChannels,
22
- x,
23
- e.sampleRate
21
+ const g = Math.floor(t.audioSprite.start * n.sampleRate), m = Math.floor(t.duration * n.sampleRate), l = a.createBuffer(
22
+ n.numberOfChannels,
23
+ m,
24
+ n.sampleRate
24
25
  );
25
- for (let r = 0; r < e.numberOfChannels; r++) {
26
- const p = e.getChannelData(r).subarray(v, v + x);
27
- f.getChannelData(r).set(p);
26
+ for (let r = 0; r < n.numberOfChannels; r++) {
27
+ const e = n.getChannelData(r).subarray(g, g + m);
28
+ l.getChannelData(r).set(e);
28
29
  }
29
- const s = Tt(f), t = new Blob([s], { type: "audio/wav" }), n = URL.createObjectURL(t), c = new Audio(n);
30
- l.audioSprite.domElement = c, console.log("Assigned audio to clip: ", l.name, " at ", l.audioSprite.start, " for ", l.duration, " seconds");
30
+ const A = Ht(l), M = new Blob([A], { type: "audio/wav" }), x = URL.createObjectURL(M), f = new Audio(x);
31
+ t.audioSprite.domElement = f, console.log("Assigned audio to clip: ", t.name, " at ", t.audioSprite.start, " for ", t.duration, " seconds");
31
32
  }
32
- return i.close(), {
33
- blob: new Blob([o], { type: "audio/wav" }),
34
- sprites: d.map((l) => l.audioSprite ? [l.audioSprite.start, l.duration] : void 0)
33
+ return a.close(), {
34
+ blob: new Blob([i], { type: "audio/wav" }),
35
+ sprites: s.map((t) => t.audioSprite ? [t.audioSprite.start, t.duration] : void 0)
35
36
  };
36
37
  }
37
- function Tt(a) {
38
- const d = a.numberOfChannels, i = a.sampleRate, o = a.length * d * 2, e = new ArrayBuffer(44 + o), l = new DataView(e), v = (f, s) => [...s].forEach((t, n) => l.setUint8(f + n, t.charCodeAt(0)));
39
- v(0, "RIFF"), l.setUint32(4, 36 + o, !0), v(8, "WAVE"), v(12, "fmt "), l.setUint32(16, 16, !0), l.setUint16(20, 1, !0), l.setUint16(22, d, !0), l.setUint32(24, i, !0), l.setUint32(28, i * d * 2, !0), l.setUint16(32, d * 2, !0), l.setUint16(34, 16, !0), v(36, "data"), l.setUint32(40, o, !0);
40
- let x = 44;
41
- for (let f = 0; f < a.length; f++)
42
- for (let s = 0; s < d; s++) {
43
- const t = Math.max(-1, Math.min(1, a.getChannelData(s)[f]));
44
- l.setInt16(x, t * 32767, !0), x += 2;
38
+ function Ht(o) {
39
+ const s = o.numberOfChannels, a = o.sampleRate, i = o.length * s * 2, n = new ArrayBuffer(44 + i), t = new DataView(n), g = (l, A) => [...A].forEach((M, x) => t.setUint8(l + x, M.charCodeAt(0)));
40
+ g(0, "RIFF"), t.setUint32(4, 36 + i, !0), g(8, "WAVE"), g(12, "fmt "), t.setUint32(16, 16, !0), t.setUint16(20, 1, !0), t.setUint16(22, s, !0), t.setUint32(24, a, !0), t.setUint32(28, a * s * 2, !0), t.setUint16(32, s * 2, !0), t.setUint16(34, 16, !0), g(36, "data"), t.setUint32(40, i, !0);
41
+ let m = 44;
42
+ for (let l = 0; l < o.length; l++)
43
+ for (let A = 0; A < s; A++) {
44
+ const M = Math.max(-1, Math.min(1, o.getChannelData(A)[l]));
45
+ t.setInt16(m, M * 32767, !0), m += 2;
45
46
  }
46
- return e;
47
+ return n;
47
48
  }
48
- const ct = /* @__PURE__ */ new WeakMap();
49
- function zt(a, d) {
50
- const i = ct.get(a) || new AudioContext();
51
- ct.set(a, i);
52
- const o = i.createGain();
53
- o.connect(i.destination), o.gain.value = 1;
54
- let e;
49
+ const ht = /* @__PURE__ */ new WeakMap();
50
+ function Yt(o, s) {
51
+ const a = ht.get(o) || new AudioContext();
52
+ ht.set(o, a);
53
+ const i = a.createGain();
54
+ i.connect(a.destination), i.gain.value = 1;
55
+ let n;
55
56
  return {
56
57
  stopCurrent() {
57
- e && (e.stop(), e = void 0);
58
+ n && (n.stop(), n = void 0);
58
59
  },
59
- setVolume(l) {
60
- o.gain.value = l;
60
+ setVolume(t) {
61
+ i.gain.value = t;
61
62
  },
62
63
  /**
63
64
  * @param clipIndex Index of the clip to play
64
65
  * @returns The audio buffer source node that is playing the audio.
65
66
  */
66
- playSprite(l) {
67
+ playSprite(t) {
67
68
  this.stopCurrent();
68
- const v = d[l];
69
- if (!v.audioSprite) return;
70
- const x = i.createBufferSource();
71
- return x.buffer = a, x.connect(o), x.start(0, v.audioSprite.start, v.duration), e = x, console.log("PLAYING SOUNC", v.name), x;
69
+ const g = s[t];
70
+ if (!g.audioSprite) return;
71
+ const m = a.createBufferSource();
72
+ return m.buffer = o, m.connect(i), m.start(0, g.audioSprite.start, g.duration), n = m, m;
72
73
  }
73
74
  };
74
75
  }
75
- function Bt(a, d, i, o, e) {
76
- const l = !o;
77
- o ?? (o = new Ct()), l && (i.material = o), i.geometry.hasAttribute("landmarkIndex") || At(i);
78
- const v = [], x = [], f = [];
79
- let s = 0, t = 0;
80
- for (let U = 0; U < d.length; U++) {
81
- const w = d[U];
82
- v.push(s, t, w.frames.length, w.fps), s += w.frames.length, t += w.frames.length * X, x.push(w.aspectRatio), f.push(U == 0 ? 0 : f[U - 1] + d[U - 1].frames.length);
76
+ function qt(o, s, a, i, n) {
77
+ const t = !i;
78
+ i ?? (i = new Lt()), t && (a.material = i), a.geometry.hasAttribute("landmarkIndex") || Vt(a);
79
+ const g = [], m = [], l = [];
80
+ let A = 0, M = 0;
81
+ for (let y = 0; y < s.length; y++) {
82
+ const v = s[y];
83
+ g.push(A, M, v.frames.length, v.fps), A += v.frames.length, M += v.frames.length * $, m.push(v.aspectRatio), l.push(y == 0 ? 0 : l[y - 1] + s[y - 1].frames.length);
83
84
  }
84
- const n = H(new Float32Array(x), "float"), c = H(new Uint32Array(v), "uvec4"), r = new Float32Array(d.flatMap((U) => U.frames).reduce((U, w) => (U.push(w.frameUV.u, w.frameUV.v, w.frameUV.w, w.frameUV.h), U), [])), p = H(r, "vec4"), M = new Float32Array(d.flatMap((U) => U.frames.flatMap((w) => [w.cropUV.u, w.cropUV.v, w.cropUV.w, w.cropUV.h]))), m = H(M, "vec4"), u = new Float32Array(d.flatMap((U) => U.landmarks.flatMap((w) => w.flatMap((I) => [I.x, I.y, I.z])))), h = H(u, "vec3"), g = it(a), y = K(0), A = K(0), C = K(!0), k = n.element(y), j = H(new Uint32Array(f), "uint"), R = A, D = j.element(y).add(R), z = p.element(c.element(y).x.add(R)), b = c.element(y).y.add(R.mul(X)), J = bt("landmarkIndex", "uint").toUint(), Q = b.add(J), B = h.element(Q), V = m.element(D), Y = B.xy.sub(V.xy).div(V.zw), q = St(z.xy.add(Y.mul(z.zw))), _ = it(g, q);
85
- o.colorNode = _;
86
- const ft = h.element(b.add(234)).xy, nt = h.element(b.add(93)).xy, ut = h.element(b.add(454)).xy, ot = h.element(b.add(323)).xy, at = ft.sub(nt).div(2).add(nt), ht = ut.sub(ot).div(2).add(ot).sub(at).div(2).add(at), E = i.geometry.attributes.position, Z = 116, $ = 346, pt = new et().subVectors(
87
- new et(E.getX(Z), E.getY(Z), E.getZ(Z)),
88
- new et(E.getX($), E.getY($), E.getZ($))
89
- ).lengthSq(), mt = K(pt), gt = h.element(b.add($)).sub(h.element(b.add(Z))).lengthSq(), Ut = mt.div(gt).sqrt().mul(2), wt = B.sub(ht).xzy.mul(It(1, -1, kt(1).div(k))).mul(Ut);
90
- o.positionNode = wt;
91
- let G = 0, L = 0, N, P, st = d[0].frames, tt = !1, O = e ? zt(e, d) : void 0;
92
- const S = {
85
+ const x = K(new Float32Array(m), "float"), f = K(new Uint32Array(g), "uvec4"), r = new Float32Array(s.flatMap((y) => y.frames).reduce((y, v) => (y.push(v.frameUV.u, v.frameUV.v, v.frameUV.w, v.frameUV.h), y), [])), e = K(r, "vec4"), c = new Float32Array(s.flatMap((y) => y.frames.flatMap((v) => [v.cropUV.u, v.cropUV.v, v.cropUV.w, v.cropUV.h]))), d = K(c, "vec4"), u = new Float32Array(s.flatMap((y) => y.landmarks.flatMap((v) => v.flatMap((z) => [z.x, z.y, z.z])))), w = K(u, "vec3"), p = mt(o), h = tt(0), U = tt(0), I = tt(!0), b = x.element(h), C = K(new Uint32Array(l), "uint"), k = U, P = C.element(h).add(k), N = e.element(f.element(h).x.add(k)), L = f.element(h).y.add(k.mul($)), W = zt("landmarkIndex", "uint").toUint(), G = L.add(W), D = w.element(G), X = d.element(P), S = D.xy.sub(X.xy).div(X.zw), B = Ft(N.xy.add(S.mul(N.zw))), F = mt(p, B);
86
+ i.colorNode = F;
87
+ const E = w.element(L.add(234)).xy, T = w.element(L.add(93)).xy, yt = w.element(L.add(454)).xy, lt = w.element(L.add(323)).xy, ft = E.sub(T).div(2).add(T), vt = yt.sub(lt).div(2).add(lt).sub(ft).div(2).add(ft), R = a.geometry.attributes.position, et = 116, nt = 346, xt = new _().subVectors(
88
+ new _(R.getX(et), R.getY(et), R.getZ(et)),
89
+ new _(R.getX(nt), R.getY(nt), R.getZ(nt))
90
+ ).lengthSq(), ot = 209, at = 429, At = tt(new _().addVectors(
91
+ new _(R.getX(ot), R.getY(ot), R.getZ(ot)),
92
+ new _(R.getX(at), R.getY(at), R.getZ(at))
93
+ ).multiplyScalar(0.5)), Mt = tt(xt), bt = w.element(L.add(nt)).sub(w.element(L.add(et))).lengthSq(), Ct = Mt.div(bt).sqrt(), It = D.sub(vt).xzy.mul(Et(1, -1, Pt(1).div(b))).mul(Ct).add(At);
94
+ i.positionNode = Ot(W.toUint().lessThanEqual($), It, jt);
95
+ let J = 0, O = 0, H, Y, rt = s[0].frames, st = !1, q = n ? Yt(n, s) : void 0, dt;
96
+ const V = {
93
97
  muted: !1,
94
- clips: d,
95
- atlasTexture: a,
96
- material: o,
97
- goto(U, w = !0, I, yt = !0) {
98
- var rt;
99
- let T = -1;
100
- if (typeof U == "number")
101
- T = U;
102
- else if (T = d.findIndex((vt) => vt.name === U), T === -1)
103
- throw new Error(`Clip ${U.toString()} not found`);
104
- C.value = w, A.value = 0, y.value = T;
105
- const W = d[T];
106
- N = W, st = W.frames, G = W.duration, L = 0, P = I, tt = !0, O && (O.stopCurrent(), yt && !S.muted && W.audioSprite && (O.playSprite(T), (rt = S.playClipAudioHook) == null || rt.call(S, T, W.audioSprite.start, W.duration)));
98
+ clips: s,
99
+ atlasTexture: o,
100
+ material: i,
101
+ getLastKnownFaceTransform: () => dt,
102
+ goto(y, v = !0, z, Rt = !0) {
103
+ var ut;
104
+ let j = -1;
105
+ if (typeof y == "number")
106
+ j = y;
107
+ else if (j = s.findIndex((kt) => kt.name === y), j === -1)
108
+ throw new Error(`Clip ${y.toString()} not found`);
109
+ I.value = v, U.value = 0, h.value = j;
110
+ const Z = s[j];
111
+ H = Z, rt = Z.frames, J = Z.duration, O = 0, Y = z, st = !0, q && (q.stopCurrent(), Rt && !V.muted && Z.audioSprite && (q.playSprite(j), (ut = V.playClipAudioHook) == null || ut.call(V, j, Z.audioSprite.start, Z.duration)));
107
112
  },
108
- update(U) {
109
- var w;
110
- if (tt) {
111
- if (L += U, A.value = Ft(st, L, A.value), C.value)
112
- L >= G && (L -= G, A.value = 0, S.muted || (O == null || O.playSprite(y.value), N != null && N.audioSprite && ((w = S.playClipAudioHook) == null || w.call(S, y.value, N.audioSprite.start, N.duration))), P == null || P(L));
113
- else if (L >= G) {
114
- const I = P;
115
- P = void 0, I == null || I(G);
113
+ update(y) {
114
+ var v;
115
+ if (st) {
116
+ if (O += y, U.value = Zt(rt, O, U.value), dt = rt[U.value].transformMatrix, I.value)
117
+ O >= J && (O -= J, U.value = 0, V.muted || (q == null || q.playSprite(h.value), H != null && H.audioSprite && ((v = V.playClipAudioHook) == null || v.call(V, h.value, H.audioSprite.start, H.duration))), Y == null || Y(O));
118
+ else if (O >= J) {
119
+ const z = Y;
120
+ Y = void 0, z == null || z(J);
116
121
  }
117
122
  }
118
123
  },
119
124
  dispose() {
120
- a.dispose(), o.dispose();
125
+ o.dispose(), i.dispose();
121
126
  },
122
- gotoAndLoop(U, w) {
123
- this.goto(U, !0, w);
127
+ gotoAndLoop(y, v) {
128
+ this.goto(y, !0, v);
124
129
  },
125
- gotoAndPlay(U, w) {
126
- this.goto(U, !1, w);
130
+ gotoAndPlay(y, v) {
131
+ this.goto(y, !1, v);
127
132
  },
128
- gotoAndStop(U, w = 0) {
129
- this.goto(U, !1, void 0, !1), A.value = w, tt = !1;
133
+ gotoAndStop(y, v = 0) {
134
+ this.goto(y, !1, void 0, !1), U.value = v, st = !1;
130
135
  }
131
136
  };
132
- return S;
137
+ return V;
133
138
  }
134
- function Ft(a, d, i) {
135
- for (; i < a.length - 1 && a[i + 1].startTime <= d; )
136
- i++;
137
- return i;
139
+ function Zt(o, s, a) {
140
+ for (; a < o.length - 1 && o[a + 1].startTime <= s; )
141
+ a++;
142
+ return a;
138
143
  }
139
- async function _t(a) {
140
- if (typeof a == "string") {
141
- const i = await (await fetch(a)).arrayBuffer();
142
- return lt(i);
144
+ async function _t(o, s = !0) {
145
+ const a = await Ut(o, s);
146
+ return new Promise((i, n) => {
147
+ St(new Uint8Array(a), { level: 9 }, (t, g) => {
148
+ if (t) return n(t);
149
+ const m = new Blob([g], { type: "application/octet-stream" });
150
+ i(m);
151
+ });
152
+ });
153
+ }
154
+ async function Ut(o, s = !0) {
155
+ const a = new TextEncoder(), i = o.clips.length, n = o.clips.map((c) => a.encode(c.name)), t = 9, g = n.reduce((c, d, u) => {
156
+ const w = o.clips[u].frames.length, p = 1 + d.byteLength, h = 2, U = 1, I = 1, b = 1, C = 16;
157
+ let k = $ * 6;
158
+ return c + p + h + U + I + b + (C + k) * w;
159
+ }, 0), m = o.clips.reduce((c, d) => c + 2 + 2, 0), l = o.clips.reduce((c, d) => c + d.frames.length * 2, 0), A = o.clips.reduce((c, d) => c + d.frames.length * 64, 0), x = t + g + m + l + 3 & -4, f = new ArrayBuffer(x + A), r = new DataView(f);
160
+ let e = 0;
161
+ r.setUint32(e, wt), e += 4, r.setUint8(e, Wt), e += 1, r.setUint8(e, o.clips.length), e += 1, r.setUint16(e, o.atlasSize), e += 2, r.setUint8(e, o.padding), e += 1;
162
+ for (let c = 0; c < i; c++) {
163
+ r.setUint8(e, n[c].byteLength), e += 1, new Uint8Array(f, e, n[c].byteLength).set(n[c]), e += n[c].byteLength, r.setUint16(e, o.clips[c].frames.length), e += 2, r.setUint8(e, o.clips[c].fps), e += 1, r.setUint8(e, Math.round(o.clips[c].scale * 100)), e += 1, r.setUint8(e, Math.round(o.clips[c].aspectRatio * 100)), e += 1;
164
+ const d = o.clips[c];
165
+ for (let u = 0; u < d.frames.length; u++) {
166
+ const w = d.frames[u].cropUV, p = d.frames[u].frameUV, h = 1e4;
167
+ r.setUint16(e, Math.round(p.u * h)), e += 2, r.setUint16(e, Math.round(p.v * h)), e += 2, r.setUint16(e, Math.round(p.w * h)), e += 2, r.setUint16(e, Math.round(p.h * h)), e += 2, r.setUint16(e, Math.round(w.u * h)), e += 2, r.setUint16(e, Math.round(w.v * h)), e += 2, r.setUint16(e, Math.round(w.w * h)), e += 2, r.setUint16(e, Math.round(w.h * h)), e += 2;
168
+ const U = d.landmarks[u], I = u > 0 ? d.landmarks[u - 1] : null;
169
+ U.reduce((b, C) => Math.max(b, Math.abs(C.z)), 0);
170
+ for (let b = 0; b < $; b++) {
171
+ const C = Math.round(U[b].x * 1e3), k = Math.round(U[b].y * 1e3), P = Math.round(U[b].z * 1e3);
172
+ if (s)
173
+ if (I === null)
174
+ r.setUint16(e, C), e += 2, r.setUint16(e, k), e += 2, r.setInt16(e, P), e += 2;
175
+ else {
176
+ const N = Math.round(I[b].x * 1e3), L = Math.round(I[b].y * 1e3), W = Math.round(I[b].z * 1e3), G = C - N, D = k - L, X = P - W;
177
+ r.setInt16(e, G), e += 2, r.setInt16(e, D), e += 2, r.setInt16(e, X), e += 2;
178
+ }
179
+ else
180
+ r.setUint16(e, C), e += 2, r.setUint16(e, k), e += 2, r.setInt16(e, P), e += 2;
181
+ }
182
+ }
183
+ }
184
+ for (let c = 0; c < i; c++) {
185
+ const d = o.clips[c];
186
+ r.setUint16(e, Math.round(d.duration * 1e3)), e += 2, d.audioSprite ? r.setUint16(e, Math.round(d.audioSprite.start * 1e3)) : r.setUint16(e, 1), e += 2;
187
+ }
188
+ for (let c = 0; c < i; c++) {
189
+ const d = o.clips[c];
190
+ let u = 0;
191
+ for (const w of d.frames) {
192
+ const p = Math.floor((w.startTime - u) * 1e3);
193
+ r.setUint16(e, p), e += 2, u = w.startTime;
194
+ }
195
+ }
196
+ e = e + 3 & -4;
197
+ for (let c = 0; c < i; c++) {
198
+ const d = o.clips[c];
199
+ for (const u of d.frames)
200
+ u.transformMatrix ? u.transformMatrix.toArray(new Float32Array(f, e, 16)) : new Float32Array(f, e, 16).fill(0), e += 64;
201
+ }
202
+ return f;
203
+ }
204
+ async function ie(o) {
205
+ if (typeof o == "string") {
206
+ const a = await (await fetch(o)).arrayBuffer();
207
+ return it(a);
143
208
  } else
144
- return new Promise((d, i) => {
145
- const o = new FileReader();
146
- o.onload = (e) => {
147
- const l = e.target.result;
148
- d(lt(l));
149
- }, o.onerror = (e) => {
150
- i(e);
151
- }, o.readAsArrayBuffer(a);
209
+ return new Promise((s, a) => {
210
+ const i = new FileReader();
211
+ i.onload = (n) => {
212
+ const t = n.target.result;
213
+ s(it(t));
214
+ }, i.onerror = (n) => {
215
+ a(n);
216
+ }, i.readAsArrayBuffer(o);
152
217
  });
153
218
  }
154
- async function lt(a) {
155
- let d = !1;
156
- const i = await new Promise((n, c) => {
157
- xt(new Uint8Array(a), (r, p) => {
158
- r ? c(r) : n(p);
219
+ async function it(o, s = !0) {
220
+ let a = !1;
221
+ const i = s ? await new Promise((f, r) => {
222
+ Tt(new Uint8Array(o), (e, c) => {
223
+ e ? r(e) : f(c);
159
224
  });
160
- }), o = new DataView(i.buffer);
161
- let e = 0;
162
- const l = o.getUint32(e);
163
- if (e += 4, l !== dt) throw new Error("Invalid file: not a MCAP file");
164
- const v = o.getUint8(e);
165
- e += 1;
166
- const x = o.getUint8(e);
167
- e += 1;
168
- const f = o.getUint16(e);
169
- e += 2;
170
- const s = o.getUint8(e);
171
- e += 1;
172
- const t = [];
173
- for (let n = 0; n < x; n++) {
174
- const c = o.getUint8(e);
175
- e += 1;
176
- const r = new Uint8Array(i.buffer, e, c), p = new TextDecoder().decode(r);
177
- e += c;
178
- const M = o.getUint8(e);
179
- e += 1;
180
- const m = o.getUint8(e);
181
- e += 1;
182
- const u = o.getUint8(e) / 100;
183
- e += 1;
184
- const h = o.getUint8(e) / 100;
185
- e += 1;
186
- const g = [], y = [], A = [];
187
- for (let C = 0; C < M; C++) {
188
- const k = o.getUint16(e) / 1e3;
189
- e += 2;
190
- const j = o.getUint16(e) / 1e3;
191
- e += 2;
192
- const R = o.getUint16(e) / 1e3;
193
- e += 2;
194
- const D = o.getUint16(e) / 1e3;
195
- e += 2, g.push({ u: k, v: j, w: R, h: D });
196
- const z = o.getUint16(e) / 1e3;
197
- e += 2;
198
- const b = o.getUint16(e) / 1e3;
199
- e += 2;
200
- const J = o.getUint16(e) / 1e3;
201
- e += 2;
202
- const Q = o.getUint16(e) / 1e3;
203
- e += 2, A.push({ u: z, v: b, w: J, h: Q });
204
- const B = [], V = C > 0 ? y[C - 1] : null;
205
- for (let F = 0; F < X; F++)
206
- if (V === null) {
207
- const Y = o.getUint16(e) / 1e3;
208
- e += 2;
209
- const q = o.getUint16(e) / 1e3;
210
- e += 2;
211
- const _ = o.getInt16(e) / 1e3;
212
- e += 2, B.push({ x: Y, y: q, z: _ });
225
+ }) : new Uint8Array(o), n = new DataView(i.buffer);
226
+ let t = 0;
227
+ const g = n.getUint32(t);
228
+ if (t += 4, g !== wt) throw new Error("Invalid file: not a MCAP file");
229
+ const m = n.getUint8(t);
230
+ t += 1;
231
+ const l = n.getUint8(t);
232
+ t += 1;
233
+ const A = n.getUint16(t);
234
+ t += 2;
235
+ const M = n.getUint8(t);
236
+ t += 1;
237
+ const x = [];
238
+ for (let f = 0; f < l; f++) {
239
+ const r = n.getUint8(t);
240
+ t += 1;
241
+ const e = new Uint8Array(i.buffer, t, r), c = new TextDecoder().decode(e);
242
+ t += r;
243
+ const d = m >= 3 ? n.getUint16(t) : n.getUint8(t);
244
+ t += m >= 3 ? 2 : 1;
245
+ const u = n.getUint8(t);
246
+ t += 1;
247
+ const w = n.getUint8(t) / 100;
248
+ t += 1;
249
+ const p = n.getUint8(t) / 100;
250
+ t += 1;
251
+ const h = [], U = [], I = [];
252
+ for (let b = 0; b < d; b++) {
253
+ const C = m < 3 ? 1e3 : 1e4, k = n.getUint16(t) / C;
254
+ t += 2;
255
+ const P = n.getUint16(t) / C;
256
+ t += 2;
257
+ const N = n.getUint16(t) / C;
258
+ t += 2;
259
+ const L = n.getUint16(t) / C;
260
+ t += 2, h.push({ u: k, v: P, w: N, h: L });
261
+ const W = n.getUint16(t) / C;
262
+ t += 2;
263
+ const G = n.getUint16(t) / C;
264
+ t += 2;
265
+ const D = n.getUint16(t) / C;
266
+ t += 2;
267
+ const X = n.getUint16(t) / C;
268
+ t += 2, I.push({ u: W, v: G, w: D, h: X });
269
+ const Q = [], S = b > 0 ? U[b - 1] : null;
270
+ for (let B = 0; B < $; B++)
271
+ if (S === null) {
272
+ const F = n.getUint16(t) / 1e3;
273
+ t += 2;
274
+ const E = n.getUint16(t) / 1e3;
275
+ t += 2;
276
+ const T = n.getInt16(t) / 1e3;
277
+ t += 2, Q.push({ x: F, y: E, z: T });
213
278
  } else {
214
- const Y = o.getInt8(e) / 1e3;
215
- e += 1;
216
- const q = o.getInt8(e) / 1e3;
217
- e += 1;
218
- const _ = o.getInt8(e) / 1e3;
219
- e += 1, B.push({
220
- x: V[F].x + Y,
221
- y: V[F].y + q,
222
- z: V[F].z + _
223
- });
279
+ let F, E, T;
280
+ m < 3 ? (F = n.getInt8(t) / 1e3, t += 1, E = n.getInt8(t) / 1e3, t += 1, T = n.getInt8(t) / 1e3, t += 1, Q.push({
281
+ x: S[B].x + F,
282
+ y: S[B].y + E,
283
+ z: S[B].z + T
284
+ })) : (F = n.getInt16(t) / 1e3, t += 2, E = n.getInt16(t) / 1e3, t += 2, T = n.getInt16(t) / 1e3, t += 2, Q.push({
285
+ x: S[B].x + F,
286
+ y: S[B].y + E,
287
+ z: S[B].z + T
288
+ }));
224
289
  }
225
- y.push(B);
290
+ U.push(Q);
226
291
  }
227
- t.push({
228
- name: p,
229
- fps: m,
230
- scale: u,
231
- aspectRatio: h,
232
- frames: A.map((C, k) => ({
233
- cropUV: C,
234
- frameUV: g[k],
235
- startTime: k / m
292
+ x.push({
293
+ name: c,
294
+ fps: u,
295
+ scale: w,
296
+ aspectRatio: p,
297
+ frames: I.map((b, C) => ({
298
+ cropUV: b,
299
+ frameUV: h[C],
300
+ startTime: C / u
236
301
  //<-- default for versions sub 2...
237
302
  })),
238
- landmarks: y,
239
- duration: M / m
303
+ landmarks: U,
304
+ duration: d / u
240
305
  // default for versions sub 2...
241
306
  });
242
307
  }
243
- if (v >= 2) {
244
- for (let n = 0; n < t.length; n++) {
245
- let c = o.getUint16(e);
246
- e += 2, t[n].duration = c / 1e3;
247
- let r = o.getUint16(e);
248
- e += 2, r === 1 ? console.log("Clip " + n + " has no audio") : (r /= 1e3, t[n].audioSprite = { start: r }, d = !0);
308
+ if (m >= 2) {
309
+ for (let f = 0; f < x.length; f++) {
310
+ let r = n.getUint16(t);
311
+ t += 2, x[f].duration = r / 1e3;
312
+ let e = n.getUint16(t);
313
+ t += 2, e === 1 ? console.log("Clip " + f + " has no audio") : (e /= 1e3, x[f].audioSprite = { start: e }, a = !0, console.log("MCAP AUDIO CLIP;", e, "Duration: ", r / 1e3));
249
314
  }
250
- for (let n = 0; n < t.length; n++) {
251
- const c = t[n];
252
- let r = 0;
253
- for (let p = 0; p < c.frames.length; p++) {
254
- const M = o.getUint8(e);
255
- e += 1;
256
- const m = r + M / 1e3;
257
- c.frames[p].startTime = m, r = m;
315
+ for (let f = 0; f < x.length; f++) {
316
+ const r = x[f];
317
+ let e = 0;
318
+ for (let c = 0; c < r.frames.length; c++) {
319
+ const d = m < 3 ? n.getUint8(t) : n.getUint16(t);
320
+ t += m < 3 ? 1 : 2;
321
+ const u = e + d / 1e3;
322
+ r.frames[c].startTime = u, e = u;
323
+ }
324
+ }
325
+ if (m >= 3) {
326
+ t = t + 3 & -4;
327
+ for (let f = 0; f < x.length; f++) {
328
+ const r = x[f];
329
+ for (let e = 0; e < r.frames.length; e++) {
330
+ const c = new Float32Array(n.buffer, t, 16);
331
+ t += 64, r.frames[e].transformMatrix = new Bt().fromArray(c);
332
+ }
258
333
  }
259
334
  }
260
335
  }
261
336
  return {
262
- clips: t,
263
- version: v,
264
- atlasSize: f,
265
- atlasPadding: s,
266
- unpackClips: async (n, c) => {
267
- let r, p = !0, M;
268
- if (n instanceof HTMLCanvasElement)
269
- p = !1, r = n;
337
+ clips: x,
338
+ version: m,
339
+ atlasSize: A,
340
+ atlasPadding: M,
341
+ async unpackClips(f, r) {
342
+ let e, c = !0, d, u;
343
+ if (f instanceof HTMLCanvasElement)
344
+ c = !1, e = f, u = e.getContext("2d");
270
345
  else {
271
- let u = new Image();
272
- if (typeof n == "string")
273
- u.src = n;
274
- else if (n instanceof File || n instanceof Blob) {
275
- const g = URL.createObjectURL(n);
276
- u.src = g, await new Promise((y, A) => {
277
- u.onload = () => {
278
- URL.revokeObjectURL(g), y();
279
- }, u.onerror = A;
346
+ let p = new Image();
347
+ if (typeof f == "string")
348
+ p.src = f;
349
+ else if (f instanceof File || f instanceof Blob) {
350
+ const h = URL.createObjectURL(f);
351
+ p.src = h, await new Promise((U, I) => {
352
+ p.onload = () => {
353
+ URL.revokeObjectURL(h), U();
354
+ }, p.onerror = I;
280
355
  });
281
- } else n instanceof HTMLImageElement && (u = n);
282
- (!u.complete || !u.naturalWidth) && await new Promise((g, y) => {
283
- u.onload = () => g(), u.onerror = y;
284
- }), r = document.createElement("canvas"), r.width = u.width, r.height = u.height, r.getContext("2d").drawImage(u, 0, 0);
356
+ } else f instanceof HTMLImageElement && (p = f);
357
+ (!p.complete || !p.naturalWidth) && await new Promise((h, U) => {
358
+ p.onload = () => h(), p.onerror = U;
359
+ }), e = document.createElement("canvas"), e.width = p.width, e.height = p.height, u = e.getContext("2d"), u.drawImage(p, 0, 0);
285
360
  }
286
- const m = t.map((u) => ({
287
- ...u,
288
- frames: u.frames.map((h) => {
289
- const g = document.createElement("canvas");
290
- return g.width = h.frameUV.w * r.width, g.height = h.frameUV.h * r.height, g.getContext("2d").drawImage(
291
- r,
292
- h.frameUV.u * r.width,
293
- h.frameUV.v * r.height,
294
- h.frameUV.w * r.width,
295
- h.frameUV.h * r.height,
361
+ const w = x.map((p) => ({
362
+ ...p,
363
+ frames: p.frames.map((h) => {
364
+ const U = document.createElement("canvas");
365
+ return U.width = h.frameUV.w * e.width, U.height = h.frameUV.h * e.height, U.getContext("2d").drawImage(
366
+ e,
367
+ h.frameUV.u * e.width,
368
+ h.frameUV.v * e.height,
369
+ h.frameUV.w * e.width,
370
+ h.frameUV.h * e.height,
296
371
  0,
297
372
  0,
298
- g.width,
299
- g.height
373
+ U.width,
374
+ U.height
300
375
  ), {
301
- canvas: g,
376
+ canvas: U,
302
377
  cropUV: h.cropUV,
303
378
  startTime: h.startTime
304
379
  };
305
380
  })
306
381
  }));
307
- return p && r.remove(), d && (c ? M = await Lt(c, m) : console.warn("This mcap file uses an audio atlas, but no audio atlas file was provided.")), {
308
- clips: m,
309
- audioAtlas: M
382
+ return c && e.remove(), a && (r ? d = await Xt(r, w) : console.warn("This mcap file uses an audio atlas, but no audio atlas file was provided.")), {
383
+ clips: w,
384
+ audioAtlas: d
310
385
  };
311
386
  },
312
- createMaterialHandlerOnMesh: (n, c, r, p) => Bt(c, t, n, r, p)
387
+ createMaterialHandlerOnMesh(f, r, e, c) {
388
+ return qt(r, x, f, e, c);
389
+ }
313
390
  };
314
391
  }
315
- async function Et(a, d = !0) {
316
- const i = new TextEncoder(), o = a.clips.map((n) => i.encode(n.name)), e = 9, l = o.reduce((n, c, r) => {
317
- const p = a.clips[r].frames.length, M = 1 + c.byteLength, m = 1, u = 1, h = 1, g = 1, y = 16;
318
- let A = X * 6;
319
- return n + M + m + u + h + g + (d ? y + A + (y + X * 3) * (p - 1) : (y + A) * p);
320
- }, 0), v = a.clips.reduce((n, c) => n + 2 + 2, 0), x = a.clips.reduce((n, c) => n + c.frames.length * 1, 0), f = new ArrayBuffer(e + l + v + x), s = new DataView(f);
321
- let t = 0;
322
- s.setUint32(t, dt), t += 4, s.setUint8(t, Rt), t += 1, s.setUint8(t, a.clips.length), t += 1, s.setUint16(t, a.atlasSize), t += 2, s.setUint8(t, a.padding), t += 1;
323
- for (let n = 0; n < a.clips.length; n++) {
324
- s.setUint8(t, o[n].byteLength), t += 1, new Uint8Array(f, t, o[n].byteLength).set(o[n]), t += o[n].byteLength, s.setUint8(t, a.clips[n].frames.length), t += 1, s.setUint8(t, a.clips[n].fps), t += 1, s.setUint8(t, Math.round(a.clips[n].scale * 100)), t += 1, s.setUint8(t, Math.round(a.clips[n].aspectRatio * 100)), t += 1;
325
- const c = a.clips[n];
326
- for (let r = 0; r < c.frames.length; r++) {
327
- const p = c.frames[r].cropUV, M = c.frames[r].frameUV;
328
- s.setUint16(t, Math.round(M.u * 1e3)), t += 2, s.setUint16(t, Math.round(M.v * 1e3)), t += 2, s.setUint16(t, Math.round(M.w * 1e3)), t += 2, s.setUint16(t, Math.round(M.h * 1e3)), t += 2, s.setUint16(t, Math.round(p.u * 1e3)), t += 2, s.setUint16(t, Math.round(p.v * 1e3)), t += 2, s.setUint16(t, Math.round(p.w * 1e3)), t += 2, s.setUint16(t, Math.round(p.h * 1e3)), t += 2;
329
- const m = c.landmarks[r], u = r > 0 ? c.landmarks[r - 1] : null;
330
- m.reduce((h, g) => Math.max(h, Math.abs(g.z)), 0);
331
- for (let h = 0; h < X; h++) {
332
- const g = Math.round(m[h].x * 1e3), y = Math.round(m[h].y * 1e3), A = Math.round(m[h].z * 1e3);
333
- if (d)
334
- if (u === null)
335
- s.setUint16(t, g), t += 2, s.setUint16(t, y), t += 2, s.setInt16(t, A), t += 2;
336
- else {
337
- const C = Math.round(u[h].x * 1e3), k = Math.round(u[h].y * 1e3), j = Math.round(u[h].z * 1e3), R = g - C, D = y - k, z = A - j;
338
- s.setInt8(t, R), t += 1, s.setInt8(t, D), t += 1, s.setInt8(t, z), t += 1;
339
- }
340
- else
341
- s.setUint16(t, g), t += 2, s.setUint16(t, y), t += 2, s.setInt16(t, A), t += 2;
342
- }
343
- }
344
- }
345
- for (let n = 0; n < a.clips.length; n++) {
346
- const c = a.clips[n];
347
- s.setUint16(t, Math.round(c.duration * 1e3)), t += 2, c.audioSprite ? s.setUint16(t, Math.round(c.audioSprite.start * 1e3)) : s.setUint16(t, 1), t += 2;
348
- }
349
- for (let n = 0; n < a.clips.length; n++) {
350
- const c = a.clips[n];
351
- let r = 0;
352
- for (const p of c.frames) {
353
- const M = Math.floor((p.startTime - r) * 1e3);
354
- s.setUint8(t, M), t += 1, r = p.startTime;
355
- }
356
- }
357
- return new Promise((n, c) => {
358
- Mt(new Uint8Array(f), { level: 9 }, (r, p) => {
359
- if (r) return c(r);
360
- const M = new Blob([p], { type: "application/octet-stream" });
361
- n(M);
362
- });
363
- });
392
+ async function ce(o) {
393
+ const s = await Ut(o);
394
+ return it(s, !1);
364
395
  }
365
- function Nt(a) {
366
- const d = Pt(a), i = [], o = [];
367
- let e = 0;
368
- const l = [...a].sort((f, s) => s.height - f.height);
369
- for (const f of l) {
370
- let s = !1;
371
- for (const t of i)
372
- if (f.width <= d - t.currentX && f.height <= t.height) {
373
- o.push({
374
- ...f,
375
- x: t.currentX,
376
- y: t.y
377
- }), t.currentX += f.width, s = !0;
396
+ function Kt(o) {
397
+ const s = $t(o), a = [], i = [];
398
+ let n = 0;
399
+ const t = [...o].sort((l, A) => A.height - l.height);
400
+ for (const l of t) {
401
+ let A = !1;
402
+ for (const M of a)
403
+ if (l.width <= s - M.currentX && l.height <= M.height) {
404
+ i.push({
405
+ ...l,
406
+ x: M.currentX,
407
+ y: M.y
408
+ }), M.currentX += l.width, A = !0;
378
409
  break;
379
410
  }
380
- if (!s) {
381
- const t = {
382
- y: e,
383
- height: f.height,
384
- currentX: f.width
411
+ if (!A) {
412
+ const M = {
413
+ y: n,
414
+ height: l.height,
415
+ currentX: l.width
385
416
  };
386
- i.push(t), o.push({
387
- ...f,
417
+ a.push(M), i.push({
418
+ ...l,
388
419
  x: 0,
389
- y: e
390
- }), e += f.height;
420
+ y: n
421
+ }), n += l.height;
391
422
  }
392
423
  }
393
- const v = i.length > 0 ? Math.max(...i.map((f) => f.currentX)) : 0, x = e;
424
+ const g = a.length > 0 ? Math.max(...a.map((l) => l.currentX)) : 0, m = n;
394
425
  return {
395
- packed: o,
396
- width: Math.max(v, d),
397
- height: x
426
+ packed: i,
427
+ width: Math.max(g, s),
428
+ height: m
398
429
  };
399
430
  }
400
- function Pt(a) {
401
- if (a.length === 0) return 1;
402
- const d = a.reduce((e, l) => e + l.width * l.height, 0);
403
- let i = Math.ceil(Math.sqrt(d));
404
- const o = Math.max(...a.map((e) => e.width));
405
- return i = Math.max(i, o), i = Ot(i), i;
431
+ function $t(o) {
432
+ if (o.length === 0) return 1;
433
+ const s = o.reduce((n, t) => n + t.width * t.height, 0);
434
+ let a = Math.ceil(Math.sqrt(s));
435
+ const i = Math.max(...o.map((n) => n.width));
436
+ return a = Math.max(a, i), a = Gt(a), a;
406
437
  }
407
- function Ot(a) {
408
- return Math.pow(2, Math.ceil(Math.log2(a)));
438
+ function Gt(o) {
439
+ return Math.pow(2, Math.ceil(Math.log2(o)));
409
440
  }
410
- const Wt = 20;
411
- function Gt(a, d, i = 0) {
412
- const o = a.flatMap((m) => m.frames.map((u) => u.canvas)), e = Array.from(o.entries()).map(([m, u]) => ({
413
- id: m,
441
+ const Qt = 20;
442
+ function le(o, s, a = 0) {
443
+ const i = o.flatMap((d) => d.frames.map((u) => u.canvas)), n = Array.from(i.entries()).map(([d, u]) => ({
444
+ id: d,
414
445
  // index of the frame after all the frames from all the clips have been flattened
415
- width: u.width + i * 2,
416
- height: u.height + i * 2
417
- })), l = Nt(e), v = l.height, x = l.width, f = Math.min(1, d / x, d / v), s = Math.floor(x * f), t = Math.floor(v * f) + Wt, n = document.createElement("canvas");
418
- n.width = s, n.height = t;
419
- const c = n.getContext("2d");
420
- c.fillStyle = "#000000", c.fillRect(0, 0, n.width, n.height);
446
+ width: u.width + a * 2,
447
+ height: u.height + a * 2
448
+ })), t = Kt(n), g = t.height, m = t.width, l = Math.min(1, s / m, s / g), A = Math.floor(m * l), M = Math.floor(g * l) + Qt, x = document.createElement("canvas");
449
+ x.width = A, x.height = M;
450
+ const f = x.getContext("2d");
451
+ f.fillStyle = "#000000", f.fillRect(0, 0, x.width, x.height);
421
452
  const r = [];
422
- for (const m of l.packed) {
423
- const u = o[m.id], h = m.x + i, g = m.y + i, y = u.width, A = u.height;
424
- c.drawImage(u, h * f, g * f, y * f, A * f), r[m.id] = {
425
- u: h * f / s,
426
- v: g * f / t,
427
- w: y * f / s,
428
- h: A * f / t
453
+ for (const d of t.packed) {
454
+ const u = i[d.id], w = d.x + a, p = d.y + a, h = u.width, U = u.height;
455
+ f.drawImage(u, w * l, p * l, h * l, U * l), r[d.id] = {
456
+ u: w * l / A,
457
+ v: p * l / M,
458
+ w: h * l / A,
459
+ h: U * l / M
429
460
  };
430
461
  }
431
- const p = [];
432
- let M = 0;
433
- for (const m of a) {
462
+ const e = [];
463
+ let c = 0;
464
+ for (const d of o) {
434
465
  const u = {
435
- ...m,
466
+ ...d,
436
467
  frames: []
437
468
  };
438
- for (const h of m.frames)
469
+ for (const w of d.frames)
439
470
  u.frames.push({
440
- frameUV: r[M++],
441
- cropUV: h.cropUV,
442
- startTime: h.startTime
471
+ frameUV: r[c++],
472
+ cropUV: w.cropUV,
473
+ startTime: w.startTime,
474
+ transformMatrix: w.transformMatrix
443
475
  });
444
- p.push(u);
476
+ e.push(u);
445
477
  }
446
- return c.font = `${Math.max(6, Math.floor(12))}px monospace`, c.fillStyle = "#ff0000", c.fillText("Created with MeshCap : https://bandinopla.github.io/three-mediapipe-rig/?editor=meshcap", 0, t - 4), {
447
- canvas: n,
448
- clips: p,
449
- padding: i,
450
- atlasSize: d,
451
- async save(m) {
452
- const u = await Et(this);
453
- if (m) {
454
- const h = URL.createObjectURL(u), g = document.createElement("a");
455
- g.href = h, g.download = "atlas.mcap", g.click(), URL.revokeObjectURL(h), g.remove();
478
+ return f.font = `${Math.max(6, Math.floor(12))}px monospace`, f.fillStyle = "#ff0000", f.fillText("Created with MeshCap : https://bandinopla.github.io/three-mediapipe-rig/?editor=meshcap", 0, M - 4), {
479
+ canvas: x,
480
+ clips: e,
481
+ padding: a,
482
+ atlasSize: s,
483
+ async save(d) {
484
+ const u = await _t(this);
485
+ if (d) {
486
+ const w = URL.createObjectURL(u), p = document.createElement("a");
487
+ p.href = w, p.download = "atlas.mcap", p.click(), URL.revokeObjectURL(w), p.remove();
456
488
  }
457
489
  return u;
490
+ },
491
+ async saveImageAtlas(d, u) {
492
+ const w = document.createElement("a");
493
+ w.download = u ? "atlas.jpg" : "atlas.png";
494
+ let p = this.canvas;
495
+ if (d)
496
+ return await Jt(p, d, u);
497
+ w.href = p.toDataURL(u ? "image/jpeg" : "image/png", u ? 0.8 : 1), w.click();
458
498
  }
459
499
  };
460
500
  }
501
+ function ct(o, s) {
502
+ const a = new Uint8Array(o);
503
+ let i = 0;
504
+ for (let n = 0; n < s.length; n++)
505
+ i = i + s.charCodeAt(n) & 255;
506
+ for (let n = 0; n < a.length; n++)
507
+ a[n] ^= i;
508
+ return a;
509
+ }
510
+ async function Jt(o, s, a) {
511
+ const n = await (await new Promise((A) => o.toBlob(A, a ? "image/jpeg" : "image/png", a ? 0.8 : 1))).arrayBuffer(), t = ct(n, s), g = new Blob([t], { type: "application/octet-stream" }), m = URL.createObjectURL(g), l = document.createElement("a");
512
+ l.href = m, l.download = "atlas.mcatlas", l.click(), URL.revokeObjectURL(m);
513
+ }
514
+ async function fe(o, s) {
515
+ if (typeof o == "string")
516
+ if (o.endsWith(".mcatlas")) {
517
+ const i = await (await fetch(o)).arrayBuffer();
518
+ return await gt(i, s);
519
+ } else
520
+ return new pt().loadAsync(o);
521
+ else {
522
+ if (o.name.endsWith(".mcatlas"))
523
+ return new Promise((i, n) => {
524
+ const t = new FileReader();
525
+ t.onload = (g) => {
526
+ const m = g.target.result;
527
+ i(gt(m, s));
528
+ }, t.onerror = (g) => {
529
+ n(g);
530
+ }, t.readAsArrayBuffer(o);
531
+ });
532
+ const a = URL.createObjectURL(o);
533
+ return await new Promise((i, n) => {
534
+ new pt().load(a, i, void 0, n);
535
+ });
536
+ }
537
+ }
538
+ async function gt(o, s) {
539
+ if (!s)
540
+ throw new Error("No passphrase provided");
541
+ const a = ct(o, s), i = new Blob([a], { type: "image/png" }), n = URL.createObjectURL(i), t = document.createElement("img");
542
+ await new Promise((m, l) => {
543
+ t.onload = () => m(), t.onerror = l, t.src = n;
544
+ });
545
+ const g = new Nt(t);
546
+ return g.needsUpdate = !0, g;
547
+ }
548
+ async function de(o, s) {
549
+ const a = document.createElement("canvas");
550
+ a.width = o.width, a.height = o.height, a.getContext("2d").drawImage(o, 0, 0);
551
+ const n = await new Promise((g, m) => {
552
+ a.toBlob((l) => {
553
+ if (!l) {
554
+ m(new Error("Failed to create blob"));
555
+ return;
556
+ }
557
+ g(l.arrayBuffer());
558
+ }, "image/jpeg", 0.75);
559
+ }), t = ct(n, s);
560
+ return new Blob([t], { type: "application/octet-stream" });
561
+ }
461
562
  export {
462
- Tt as audioBufferToWav,
463
- Gt as buildMeshCapAtlas,
464
- zt as createAudioAtlasPlayer,
465
- Bt as createMeshCapMaterial,
466
- Lt as extractAudioSprites,
467
- _t as loadMeshCapFile
563
+ Ht as audioBufferToWav,
564
+ le as buildMeshCapAtlas,
565
+ Yt as createAudioAtlasPlayer,
566
+ qt as createMeshCapMaterial,
567
+ Xt as extractAudioSprites,
568
+ ie as loadMeshCapFile,
569
+ fe as loadMeshcapAtlas,
570
+ de as obfuscateImage,
571
+ ce as readAsMCapFile
468
572
  };