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