three-mediapipe-rig 0.1.4 → 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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"material.d.ts","sourceRoot":"","sources":["../../src/meshcap/material.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"material.d.ts","sourceRoot":"","sources":["../../src/meshcap/material.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAgC,OAAO,EAA4B,YAAY,EAAsC,MAAM,cAAc,CAAC;AAOjJ,MAAM,MAAM,sBAAsB,GAAG;IAEpC;;;;;;;;;;OAUG;IACH,yBAAyB,EAAC,MAAI,OAAO,GAAC,SAAS,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAC,OAAO,CAAC;IAEd;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAC,CAAC,SAAS,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,KAAG,IAAI,CAAC;IAGvF;;;;;OAKG;IACH,IAAI,EAAC,CAAE,SAAS,EAAC,MAAM,GAAC,MAAM,EAAE,KAAK,CAAC,EAAC,OAAO,EAAE,mBAAmB,CAAC,EAAC,CAAE,UAAU,EAAC,MAAM,KAAI,IAAI,EAAE,SAAS,CAAC,EAAC,OAAO,KAAI,IAAI,CAAA;IAE5H;;;;OAIG;IACH,WAAW,EAAC,CAAE,SAAS,EAAC,MAAM,GAAC,MAAM,EAAE,OAAO,CAAC,EAAC,CAAE,UAAU,EAAC,MAAM,KAAI,IAAI,KAAI,IAAI,CAAA;IAEnF;;;;OAIG;IACH,WAAW,EAAC,CAAE,SAAS,EAAC,MAAM,GAAC,MAAM,EAAE,aAAa,CAAC,EAAC,MAAI,IAAI,KAAI,IAAI,CAAA;IAEtE;;;;OAIG;IACH,WAAW,EAAC,CAAE,SAAS,EAAC,MAAM,GAAC,MAAM,EAAE,KAAK,CAAC,EAAC,MAAM,KAAI,IAAI,CAAA;IAE5D;;;OAGG;IACH,MAAM,EAAC,CAAE,KAAK,EAAC,MAAM,KAAI,IAAI,CAAA;IAE7B;;OAEG;IACH,KAAK,EAAC,QAAQ,EAAE,CAAA;IAEhB;;OAEG;IACH,YAAY,EAAC,OAAO,CAAA;IAEpB;;OAEG;IACH,OAAO,EAAC,YAAY,CAAA;IAEpB;;OAEG;IACH,QAAQ,EAAC,YAAY,CAAA;CACrB,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAE,YAAY,EAAC,OAAO,EAAE,KAAK,EAAC,QAAQ,EAAE,EAAE,UAAU,EAAC,IAAI,EAAE,IAAI,CAAC,EAAC,YAAY,EAAE,UAAU,CAAC,EAAC,WAAW,GAAG,sBAAsB,CAmYnK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-mcap-file.d.ts","sourceRoot":"","sources":["../../src/meshcap/parse-mcap-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,QAAQ,EAAE,YAAY,EAAyB,MAAM,SAAS,CAAC;AAUlF;;;;GAIG;AACH,wBAAsB,eAAe,CAAE,cAAc,EAAC,MAAM,GAAC,IAAI,GAAK,OAAO,CAAC,QAAQ,CAAC,CAmBtF;
|
|
1
|
+
{"version":3,"file":"parse-mcap-file.d.ts","sourceRoot":"","sources":["../../src/meshcap/parse-mcap-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,QAAQ,EAAE,YAAY,EAAyB,MAAM,SAAS,CAAC;AAUlF;;;;GAIG;AACH,wBAAsB,eAAe,CAAE,cAAc,EAAC,MAAM,GAAC,IAAI,GAAK,OAAO,CAAC,QAAQ,CAAC,CAmBtF;AAiVD,wBAAsB,cAAc,CAAE,KAAK,EAAC,YAAY,qBAIvD"}
|
package/dist/meshcap.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MeshPhysicalNodeMaterial as
|
|
2
|
-
import { deflate as
|
|
3
|
-
import { c as
|
|
4
|
-
import { instancedArray as
|
|
5
|
-
import { TextureLoader as
|
|
6
|
-
const
|
|
7
|
-
async function
|
|
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
8
|
if (o instanceof ArrayBuffer)
|
|
9
9
|
return o;
|
|
10
10
|
if (o instanceof File || o instanceof Blob)
|
|
@@ -13,43 +13,43 @@ async function Dt(o) {
|
|
|
13
13
|
return (await fetch(o)).arrayBuffer();
|
|
14
14
|
throw new Error(`Unsupported audio source type: ${typeof o}`);
|
|
15
15
|
}
|
|
16
|
-
async function
|
|
17
|
-
const a = new AudioContext(), i = await
|
|
16
|
+
async function Qt(o, s) {
|
|
17
|
+
const a = new AudioContext(), i = await $t(o), n = await a.decodeAudioData(i);
|
|
18
18
|
for (const t of s) {
|
|
19
19
|
if (!t.audioSprite)
|
|
20
20
|
continue;
|
|
21
|
-
const
|
|
21
|
+
const w = Math.floor(t.audioSprite.start * n.sampleRate), m = Math.floor(t.duration * n.sampleRate), f = a.createBuffer(
|
|
22
22
|
n.numberOfChannels,
|
|
23
23
|
m,
|
|
24
24
|
n.sampleRate
|
|
25
25
|
);
|
|
26
26
|
for (let r = 0; r < n.numberOfChannels; r++) {
|
|
27
|
-
const e = n.getChannelData(r).subarray(
|
|
28
|
-
|
|
27
|
+
const e = n.getChannelData(r).subarray(w, w + m);
|
|
28
|
+
f.getChannelData(r).set(e);
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
t.audioSprite.domElement =
|
|
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");
|
|
32
32
|
}
|
|
33
33
|
return a.close(), {
|
|
34
34
|
blob: new Blob([i], { type: "audio/wav" }),
|
|
35
35
|
sprites: s.map((t) => t.audioSprite ? [t.audioSprite.start, t.duration] : void 0)
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
const s = o.numberOfChannels, a = o.sampleRate, i = o.length * s * 2, n = new ArrayBuffer(44 + i), t = new DataView(n),
|
|
40
|
-
|
|
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
41
|
let m = 44;
|
|
42
|
-
for (let
|
|
43
|
-
for (let
|
|
44
|
-
const
|
|
45
|
-
t.setInt16(m,
|
|
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;
|
|
46
46
|
}
|
|
47
47
|
return n;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
function
|
|
51
|
-
const a =
|
|
52
|
-
|
|
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
53
|
const i = a.createGain();
|
|
54
54
|
i.connect(a.destination), i.gain.value = 1;
|
|
55
55
|
let n;
|
|
@@ -66,439 +66,469 @@ function Yt(o, s) {
|
|
|
66
66
|
*/
|
|
67
67
|
playSprite(t) {
|
|
68
68
|
this.stopCurrent();
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
69
|
+
const w = s[t];
|
|
70
|
+
if (!w.audioSprite) return;
|
|
71
71
|
const m = a.createBufferSource();
|
|
72
|
-
return m.buffer = o, m.connect(i), m.start(0,
|
|
72
|
+
return m.buffer = o, m.connect(i), m.start(0, w.audioSprite.start, w.duration), n = m, m;
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function ee(o, s, a, i, n) {
|
|
77
77
|
const t = !i;
|
|
78
|
-
i ?? (i = new
|
|
79
|
-
const
|
|
80
|
-
let
|
|
81
|
-
for (let
|
|
82
|
-
const
|
|
83
|
-
|
|
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);
|
|
84
84
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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;
|
|
125
|
+
const S = {
|
|
97
126
|
muted: !1,
|
|
98
127
|
clips: s,
|
|
99
128
|
atlasTexture: o,
|
|
100
129
|
material: i,
|
|
101
|
-
getLastKnownFaceTransform: () =>
|
|
102
|
-
goto(
|
|
103
|
-
var
|
|
104
|
-
let
|
|
105
|
-
if (typeof
|
|
106
|
-
|
|
107
|
-
else if (
|
|
108
|
-
throw new Error(`Clip ${
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
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)));
|
|
112
141
|
},
|
|
113
|
-
update(
|
|
114
|
-
var
|
|
115
|
-
if (
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
else if (
|
|
119
|
-
const
|
|
120
|
-
|
|
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);
|
|
121
150
|
}
|
|
122
151
|
}
|
|
123
152
|
},
|
|
124
153
|
dispose() {
|
|
125
154
|
o.dispose(), i.dispose();
|
|
126
155
|
},
|
|
127
|
-
gotoAndLoop(
|
|
128
|
-
this.goto(
|
|
156
|
+
gotoAndLoop(g, p) {
|
|
157
|
+
this.goto(g, !0, p);
|
|
129
158
|
},
|
|
130
|
-
gotoAndPlay(
|
|
131
|
-
this.goto(
|
|
159
|
+
gotoAndPlay(g, p) {
|
|
160
|
+
this.goto(g, !1, p);
|
|
132
161
|
},
|
|
133
|
-
gotoAndStop(
|
|
134
|
-
this.goto(
|
|
162
|
+
gotoAndStop(g, p = 0) {
|
|
163
|
+
this.goto(g, !1, void 0, !1), A.value = p, it = !1;
|
|
135
164
|
}
|
|
136
165
|
};
|
|
137
|
-
return
|
|
166
|
+
return S;
|
|
138
167
|
}
|
|
139
|
-
function
|
|
168
|
+
function ne(o, s, a) {
|
|
140
169
|
for (; a < o.length - 1 && o[a + 1].startTime <= s; )
|
|
141
170
|
a++;
|
|
142
171
|
return a;
|
|
143
172
|
}
|
|
144
|
-
async function
|
|
145
|
-
const a = await
|
|
173
|
+
async function oe(o, s = !0) {
|
|
174
|
+
const a = await Rt(o, s);
|
|
146
175
|
return new Promise((i, n) => {
|
|
147
|
-
|
|
176
|
+
Nt(new Uint8Array(a), { level: 9 }, (t, w) => {
|
|
148
177
|
if (t) return n(t);
|
|
149
|
-
const m = new Blob([
|
|
178
|
+
const m = new Blob([w], { type: "application/octet-stream" });
|
|
150
179
|
i(m);
|
|
151
180
|
});
|
|
152
181
|
});
|
|
153
182
|
}
|
|
154
|
-
async function
|
|
155
|
-
const a = new TextEncoder(), i = o.clips.length, n = o.clips.map((
|
|
156
|
-
const
|
|
157
|
-
let
|
|
158
|
-
return
|
|
159
|
-
}, 0), m = o.clips.reduce((
|
|
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);
|
|
160
189
|
let e = 0;
|
|
161
|
-
r.setUint32(e,
|
|
162
|
-
for (let
|
|
163
|
-
r.setUint8(e, n[
|
|
164
|
-
const d = o.clips[
|
|
165
|
-
for (let
|
|
166
|
-
const
|
|
167
|
-
r.setUint16(e, Math.round(
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
for (let b = 0; b <
|
|
171
|
-
const
|
|
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);
|
|
172
201
|
if (s)
|
|
173
202
|
if (I === null)
|
|
174
|
-
r.setUint16(e,
|
|
203
|
+
r.setUint16(e, A), e += 2, r.setUint16(e, B), e += 2, r.setInt16(e, j), e += 2;
|
|
175
204
|
else {
|
|
176
|
-
const
|
|
177
|
-
r.setInt16(e,
|
|
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;
|
|
178
207
|
}
|
|
179
208
|
else
|
|
180
|
-
r.setUint16(e,
|
|
209
|
+
r.setUint16(e, A), e += 2, r.setUint16(e, B), e += 2, r.setInt16(e, j), e += 2;
|
|
181
210
|
}
|
|
182
211
|
}
|
|
183
212
|
}
|
|
184
|
-
for (let
|
|
185
|
-
const d = o.clips[
|
|
213
|
+
for (let l = 0; l < i; l++) {
|
|
214
|
+
const d = o.clips[l];
|
|
186
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;
|
|
187
216
|
}
|
|
188
|
-
for (let
|
|
189
|
-
const d = o.clips[
|
|
190
|
-
let
|
|
191
|
-
for (const
|
|
192
|
-
const
|
|
193
|
-
r.setUint16(e,
|
|
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;
|
|
194
223
|
}
|
|
195
224
|
}
|
|
196
225
|
e = e + 3 & -4;
|
|
197
|
-
for (let
|
|
198
|
-
const d = o.clips[
|
|
199
|
-
for (const
|
|
200
|
-
|
|
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;
|
|
201
230
|
}
|
|
202
|
-
return
|
|
231
|
+
return u;
|
|
203
232
|
}
|
|
204
|
-
async function
|
|
233
|
+
async function pe(o) {
|
|
205
234
|
if (typeof o == "string") {
|
|
206
235
|
const a = await (await fetch(o)).arrayBuffer();
|
|
207
|
-
return
|
|
236
|
+
return ft(a);
|
|
208
237
|
} else
|
|
209
238
|
return new Promise((s, a) => {
|
|
210
239
|
const i = new FileReader();
|
|
211
240
|
i.onload = (n) => {
|
|
212
241
|
const t = n.target.result;
|
|
213
|
-
s(
|
|
242
|
+
s(ft(t));
|
|
214
243
|
}, i.onerror = (n) => {
|
|
215
244
|
a(n);
|
|
216
245
|
}, i.readAsArrayBuffer(o);
|
|
217
246
|
});
|
|
218
247
|
}
|
|
219
|
-
async function
|
|
248
|
+
async function ft(o, s = !0) {
|
|
220
249
|
let a = !1;
|
|
221
|
-
const i = s ? await new Promise((
|
|
222
|
-
|
|
223
|
-
e ? r(e) :
|
|
250
|
+
const i = s ? await new Promise((u, r) => {
|
|
251
|
+
Wt(new Uint8Array(o), (e, l) => {
|
|
252
|
+
e ? r(e) : u(l);
|
|
224
253
|
});
|
|
225
254
|
}) : new Uint8Array(o), n = new DataView(i.buffer);
|
|
226
255
|
let t = 0;
|
|
227
|
-
const
|
|
228
|
-
if (t += 4,
|
|
256
|
+
const w = n.getUint32(t);
|
|
257
|
+
if (t += 4, w !== It) throw new Error("Invalid file: not a MCAP file");
|
|
229
258
|
const m = n.getUint8(t);
|
|
230
259
|
t += 1;
|
|
231
|
-
const
|
|
260
|
+
const f = n.getUint8(t);
|
|
232
261
|
t += 1;
|
|
233
|
-
const
|
|
262
|
+
const M = n.getUint16(t);
|
|
234
263
|
t += 2;
|
|
235
|
-
const
|
|
264
|
+
const C = n.getUint8(t);
|
|
236
265
|
t += 1;
|
|
237
|
-
const
|
|
238
|
-
for (let
|
|
266
|
+
const y = [];
|
|
267
|
+
for (let u = 0; u < f; u++) {
|
|
239
268
|
const r = n.getUint8(t);
|
|
240
269
|
t += 1;
|
|
241
|
-
const e = new Uint8Array(i.buffer, t, r),
|
|
270
|
+
const e = new Uint8Array(i.buffer, t, r), l = new TextDecoder().decode(e);
|
|
242
271
|
t += r;
|
|
243
272
|
const d = m >= 3 ? n.getUint16(t) : n.getUint8(t);
|
|
244
273
|
t += m >= 3 ? 2 : 1;
|
|
245
|
-
const
|
|
274
|
+
const c = n.getUint8(t);
|
|
246
275
|
t += 1;
|
|
247
|
-
const
|
|
276
|
+
const v = n.getUint8(t) / 100;
|
|
248
277
|
t += 1;
|
|
249
|
-
const
|
|
278
|
+
const h = n.getUint8(t) / 100;
|
|
250
279
|
t += 1;
|
|
251
|
-
const
|
|
280
|
+
const U = [], x = [], I = [];
|
|
252
281
|
for (let b = 0; b < d; b++) {
|
|
253
|
-
const
|
|
282
|
+
const A = m < 3 ? 1e3 : 1e4, B = n.getUint16(t) / A;
|
|
254
283
|
t += 2;
|
|
255
|
-
const
|
|
284
|
+
const j = n.getUint16(t) / A;
|
|
256
285
|
t += 2;
|
|
257
|
-
const
|
|
286
|
+
const K = n.getUint16(t) / A;
|
|
258
287
|
t += 2;
|
|
259
|
-
const
|
|
260
|
-
t += 2,
|
|
261
|
-
const
|
|
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;
|
|
262
291
|
t += 2;
|
|
263
|
-
const
|
|
292
|
+
const W = n.getUint16(t) / A;
|
|
264
293
|
t += 2;
|
|
265
|
-
const
|
|
294
|
+
const X = n.getUint16(t) / A;
|
|
266
295
|
t += 2;
|
|
267
|
-
const
|
|
268
|
-
t += 2, I.push({ u:
|
|
269
|
-
const
|
|
270
|
-
for (let
|
|
271
|
-
if (
|
|
272
|
-
const
|
|
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;
|
|
273
302
|
t += 2;
|
|
274
303
|
const E = n.getUint16(t) / 1e3;
|
|
275
304
|
t += 2;
|
|
276
|
-
const
|
|
277
|
-
t += 2,
|
|
305
|
+
const O = n.getInt16(t) / 1e3;
|
|
306
|
+
t += 2, R.push({ x: P, y: E, z: O });
|
|
278
307
|
} else {
|
|
279
|
-
let
|
|
280
|
-
m < 3 ? (
|
|
281
|
-
x:
|
|
282
|
-
y:
|
|
283
|
-
z:
|
|
284
|
-
})) : (
|
|
285
|
-
x:
|
|
286
|
-
y:
|
|
287
|
-
z:
|
|
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
|
|
288
317
|
}));
|
|
289
318
|
}
|
|
290
|
-
|
|
319
|
+
x.push(R);
|
|
291
320
|
}
|
|
292
|
-
|
|
293
|
-
name:
|
|
294
|
-
fps:
|
|
295
|
-
scale:
|
|
296
|
-
aspectRatio:
|
|
297
|
-
frames: I.map((b,
|
|
321
|
+
y.push({
|
|
322
|
+
name: l,
|
|
323
|
+
fps: c,
|
|
324
|
+
scale: v,
|
|
325
|
+
aspectRatio: h,
|
|
326
|
+
frames: I.map((b, A) => ({
|
|
298
327
|
cropUV: b,
|
|
299
|
-
frameUV:
|
|
300
|
-
startTime:
|
|
328
|
+
frameUV: U[A],
|
|
329
|
+
startTime: A / c
|
|
301
330
|
//<-- default for versions sub 2...
|
|
302
331
|
})),
|
|
303
|
-
landmarks:
|
|
304
|
-
duration: d /
|
|
332
|
+
landmarks: x,
|
|
333
|
+
duration: d / c
|
|
305
334
|
// default for versions sub 2...
|
|
306
335
|
});
|
|
307
336
|
}
|
|
308
337
|
if (m >= 2) {
|
|
309
|
-
for (let
|
|
338
|
+
for (let u = 0; u < y.length; u++) {
|
|
310
339
|
let r = n.getUint16(t);
|
|
311
|
-
t += 2,
|
|
340
|
+
t += 2, y[u].duration = r / 1e3;
|
|
312
341
|
let e = n.getUint16(t);
|
|
313
|
-
t += 2, e === 1 ? console.log("Clip " +
|
|
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));
|
|
314
343
|
}
|
|
315
|
-
for (let
|
|
316
|
-
const r =
|
|
344
|
+
for (let u = 0; u < y.length; u++) {
|
|
345
|
+
const r = y[u];
|
|
317
346
|
let e = 0;
|
|
318
|
-
for (let
|
|
347
|
+
for (let l = 0; l < r.frames.length; l++) {
|
|
319
348
|
const d = m < 3 ? n.getUint8(t) : n.getUint16(t);
|
|
320
349
|
t += m < 3 ? 1 : 2;
|
|
321
|
-
const
|
|
322
|
-
r.frames[
|
|
350
|
+
const c = e + d / 1e3;
|
|
351
|
+
r.frames[l].startTime = c, e = c;
|
|
323
352
|
}
|
|
324
353
|
}
|
|
325
354
|
if (m >= 3) {
|
|
326
355
|
t = t + 3 & -4;
|
|
327
|
-
for (let
|
|
328
|
-
const r =
|
|
356
|
+
for (let u = 0; u < y.length; u++) {
|
|
357
|
+
const r = y[u];
|
|
329
358
|
for (let e = 0; e < r.frames.length; e++) {
|
|
330
|
-
const
|
|
331
|
-
t += 64, r.frames[e].transformMatrix = new
|
|
359
|
+
const l = new Float32Array(n.buffer, t, 16);
|
|
360
|
+
t += 64, r.frames[e].transformMatrix = new Dt().fromArray(l);
|
|
332
361
|
}
|
|
333
362
|
}
|
|
334
363
|
}
|
|
335
364
|
}
|
|
336
365
|
return {
|
|
337
|
-
clips:
|
|
366
|
+
clips: y,
|
|
338
367
|
version: m,
|
|
339
|
-
atlasSize:
|
|
340
|
-
atlasPadding:
|
|
341
|
-
async unpackClips(
|
|
342
|
-
let e,
|
|
343
|
-
if (
|
|
344
|
-
|
|
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");
|
|
345
374
|
else {
|
|
346
|
-
let
|
|
347
|
-
if (typeof
|
|
348
|
-
|
|
349
|
-
else if (
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
URL.revokeObjectURL(
|
|
354
|
-
},
|
|
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;
|
|
355
384
|
});
|
|
356
|
-
} else
|
|
357
|
-
(!
|
|
358
|
-
|
|
359
|
-
}), e = document.createElement("canvas"), e.width =
|
|
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);
|
|
360
389
|
}
|
|
361
|
-
const
|
|
362
|
-
...
|
|
363
|
-
frames:
|
|
364
|
-
const
|
|
365
|
-
return
|
|
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(
|
|
366
395
|
e,
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
396
|
+
U.frameUV.u * e.width,
|
|
397
|
+
U.frameUV.v * e.height,
|
|
398
|
+
U.frameUV.w * e.width,
|
|
399
|
+
U.frameUV.h * e.height,
|
|
371
400
|
0,
|
|
372
401
|
0,
|
|
373
|
-
|
|
374
|
-
|
|
402
|
+
x.width,
|
|
403
|
+
x.height
|
|
375
404
|
), {
|
|
376
|
-
canvas:
|
|
377
|
-
cropUV:
|
|
378
|
-
startTime:
|
|
405
|
+
canvas: x,
|
|
406
|
+
cropUV: U.cropUV,
|
|
407
|
+
startTime: U.startTime,
|
|
408
|
+
transformMatrix: U.transformMatrix
|
|
379
409
|
};
|
|
380
410
|
})
|
|
381
411
|
}));
|
|
382
|
-
return
|
|
383
|
-
clips:
|
|
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,
|
|
384
414
|
audioAtlas: d
|
|
385
415
|
};
|
|
386
416
|
},
|
|
387
|
-
createMaterialHandlerOnMesh(
|
|
388
|
-
return
|
|
417
|
+
createMaterialHandlerOnMesh(u, r, e, l) {
|
|
418
|
+
return ee(r, y, u, e, l);
|
|
389
419
|
}
|
|
390
420
|
};
|
|
391
421
|
}
|
|
392
|
-
async function
|
|
393
|
-
const s = await
|
|
394
|
-
return
|
|
422
|
+
async function ge(o) {
|
|
423
|
+
const s = await Rt(o);
|
|
424
|
+
return ft(s, !1);
|
|
395
425
|
}
|
|
396
|
-
function
|
|
397
|
-
const s =
|
|
426
|
+
function ae(o) {
|
|
427
|
+
const s = re(o), a = [], i = [];
|
|
398
428
|
let n = 0;
|
|
399
|
-
const t = [...o].sort((
|
|
400
|
-
for (const
|
|
401
|
-
let
|
|
402
|
-
for (const
|
|
403
|
-
if (
|
|
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) {
|
|
404
434
|
i.push({
|
|
405
|
-
...
|
|
406
|
-
x:
|
|
407
|
-
y:
|
|
408
|
-
}),
|
|
435
|
+
...f,
|
|
436
|
+
x: C.currentX,
|
|
437
|
+
y: C.y
|
|
438
|
+
}), C.currentX += f.width, M = !0;
|
|
409
439
|
break;
|
|
410
440
|
}
|
|
411
|
-
if (!
|
|
412
|
-
const
|
|
441
|
+
if (!M) {
|
|
442
|
+
const C = {
|
|
413
443
|
y: n,
|
|
414
|
-
height:
|
|
415
|
-
currentX:
|
|
444
|
+
height: f.height,
|
|
445
|
+
currentX: f.width
|
|
416
446
|
};
|
|
417
|
-
a.push(
|
|
418
|
-
...
|
|
447
|
+
a.push(C), i.push({
|
|
448
|
+
...f,
|
|
419
449
|
x: 0,
|
|
420
450
|
y: n
|
|
421
|
-
}), n +=
|
|
451
|
+
}), n += f.height;
|
|
422
452
|
}
|
|
423
453
|
}
|
|
424
|
-
const
|
|
454
|
+
const w = a.length > 0 ? Math.max(...a.map((f) => f.currentX)) : 0, m = n;
|
|
425
455
|
return {
|
|
426
456
|
packed: i,
|
|
427
|
-
width: Math.max(
|
|
457
|
+
width: Math.max(w, s),
|
|
428
458
|
height: m
|
|
429
459
|
};
|
|
430
460
|
}
|
|
431
|
-
function
|
|
461
|
+
function re(o) {
|
|
432
462
|
if (o.length === 0) return 1;
|
|
433
463
|
const s = o.reduce((n, t) => n + t.width * t.height, 0);
|
|
434
464
|
let a = Math.ceil(Math.sqrt(s));
|
|
435
465
|
const i = Math.max(...o.map((n) => n.width));
|
|
436
|
-
return a = Math.max(a, i), a =
|
|
466
|
+
return a = Math.max(a, i), a = Vt(a), a;
|
|
437
467
|
}
|
|
438
|
-
function
|
|
468
|
+
function Vt(o) {
|
|
439
469
|
return Math.pow(2, Math.ceil(Math.log2(o)));
|
|
440
470
|
}
|
|
441
|
-
const
|
|
442
|
-
function
|
|
443
|
-
const i = o.flatMap((d) => d.frames.map((
|
|
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]) => ({
|
|
444
474
|
id: d,
|
|
445
475
|
// index of the frame after all the frames from all the clips have been flattened
|
|
446
|
-
width:
|
|
447
|
-
height:
|
|
448
|
-
})), t =
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
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);
|
|
452
482
|
const r = [];
|
|
453
483
|
for (const d of t.packed) {
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
u:
|
|
457
|
-
v:
|
|
458
|
-
w:
|
|
459
|
-
h:
|
|
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
|
|
460
490
|
};
|
|
461
491
|
}
|
|
462
492
|
const e = [];
|
|
463
|
-
let
|
|
493
|
+
let l = 0;
|
|
464
494
|
for (const d of o) {
|
|
465
|
-
const
|
|
495
|
+
const c = {
|
|
466
496
|
...d,
|
|
467
497
|
frames: []
|
|
468
498
|
};
|
|
469
|
-
for (const
|
|
470
|
-
|
|
471
|
-
frameUV: r[
|
|
472
|
-
cropUV:
|
|
473
|
-
startTime:
|
|
474
|
-
transformMatrix:
|
|
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
|
|
475
505
|
});
|
|
476
|
-
e.push(
|
|
506
|
+
e.push(c);
|
|
477
507
|
}
|
|
478
|
-
return
|
|
479
|
-
canvas:
|
|
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,
|
|
480
510
|
clips: e,
|
|
481
511
|
padding: a,
|
|
482
512
|
atlasSize: s,
|
|
483
513
|
async save(d) {
|
|
484
|
-
const
|
|
514
|
+
const c = await oe(this);
|
|
485
515
|
if (d) {
|
|
486
|
-
const
|
|
487
|
-
|
|
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();
|
|
488
518
|
}
|
|
489
|
-
return
|
|
519
|
+
return c;
|
|
490
520
|
},
|
|
491
|
-
async saveImageAtlas(d,
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
let
|
|
521
|
+
async saveImageAtlas(d, c) {
|
|
522
|
+
const v = document.createElement("a");
|
|
523
|
+
v.download = c ? "atlas.jpg" : "atlas.png";
|
|
524
|
+
let h = this.canvas;
|
|
495
525
|
if (d)
|
|
496
|
-
return await
|
|
497
|
-
|
|
526
|
+
return await ie(h, d, c);
|
|
527
|
+
v.href = h.toDataURL(c ? "image/jpeg" : "image/png", c ? 0.8 : 1), v.click();
|
|
498
528
|
}
|
|
499
529
|
};
|
|
500
530
|
}
|
|
501
|
-
function
|
|
531
|
+
function dt(o, s) {
|
|
502
532
|
const a = new Uint8Array(o);
|
|
503
533
|
let i = 0;
|
|
504
534
|
for (let n = 0; n < s.length; n++)
|
|
@@ -507,66 +537,66 @@ function ct(o, s) {
|
|
|
507
537
|
a[n] ^= i;
|
|
508
538
|
return a;
|
|
509
539
|
}
|
|
510
|
-
async function
|
|
511
|
-
const n = await (await new Promise((
|
|
512
|
-
|
|
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);
|
|
513
543
|
}
|
|
514
|
-
async function
|
|
544
|
+
async function Ue(o, s) {
|
|
515
545
|
if (typeof o == "string")
|
|
516
546
|
if (o.endsWith(".mcatlas")) {
|
|
517
547
|
const i = await (await fetch(o)).arrayBuffer();
|
|
518
|
-
return await
|
|
548
|
+
return await Ct(i, s);
|
|
519
549
|
} else
|
|
520
|
-
return new
|
|
550
|
+
return new Mt().loadAsync(o);
|
|
521
551
|
else {
|
|
522
552
|
if (o.name.endsWith(".mcatlas"))
|
|
523
553
|
return new Promise((i, n) => {
|
|
524
554
|
const t = new FileReader();
|
|
525
|
-
t.onload = (
|
|
526
|
-
const m =
|
|
527
|
-
i(
|
|
528
|
-
}, t.onerror = (
|
|
529
|
-
n(
|
|
555
|
+
t.onload = (w) => {
|
|
556
|
+
const m = w.target.result;
|
|
557
|
+
i(Ct(m, s));
|
|
558
|
+
}, t.onerror = (w) => {
|
|
559
|
+
n(w);
|
|
530
560
|
}, t.readAsArrayBuffer(o);
|
|
531
561
|
});
|
|
532
562
|
const a = URL.createObjectURL(o);
|
|
533
563
|
return await new Promise((i, n) => {
|
|
534
|
-
new
|
|
564
|
+
new Mt().load(a, i, void 0, n);
|
|
535
565
|
});
|
|
536
566
|
}
|
|
537
567
|
}
|
|
538
|
-
async function
|
|
568
|
+
async function Ct(o, s) {
|
|
539
569
|
if (!s)
|
|
540
570
|
throw new Error("No passphrase provided");
|
|
541
|
-
const a =
|
|
542
|
-
await new Promise((m,
|
|
543
|
-
t.onload = () => m(), t.onerror =
|
|
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;
|
|
544
574
|
});
|
|
545
|
-
const
|
|
546
|
-
return
|
|
575
|
+
const w = new Kt(t);
|
|
576
|
+
return w.needsUpdate = !0, w;
|
|
547
577
|
}
|
|
548
|
-
async function
|
|
578
|
+
async function ye(o, s) {
|
|
549
579
|
const a = document.createElement("canvas");
|
|
550
580
|
a.width = o.width, a.height = o.height, a.getContext("2d").drawImage(o, 0, 0);
|
|
551
|
-
const n = await new Promise((
|
|
552
|
-
a.toBlob((
|
|
553
|
-
if (!
|
|
581
|
+
const n = await new Promise((w, m) => {
|
|
582
|
+
a.toBlob((f) => {
|
|
583
|
+
if (!f) {
|
|
554
584
|
m(new Error("Failed to create blob"));
|
|
555
585
|
return;
|
|
556
586
|
}
|
|
557
|
-
|
|
587
|
+
w(f.arrayBuffer());
|
|
558
588
|
}, "image/jpeg", 0.75);
|
|
559
|
-
}), t =
|
|
589
|
+
}), t = dt(n, s);
|
|
560
590
|
return new Blob([t], { type: "application/octet-stream" });
|
|
561
591
|
}
|
|
562
592
|
export {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
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
|
|
572
602
|
};
|
package/dist/rigger.js
CHANGED
|
@@ -6,20 +6,20 @@ import * as p from "three/webgpu";
|
|
|
6
6
|
import { Vector3 as x, Quaternion as xe, Matrix4 as Ne, VideoTexture as Z, SRGBColorSpace as J, MeshPhysicalNodeMaterial as Oe } from "three/webgpu";
|
|
7
7
|
import * as D from "three";
|
|
8
8
|
import { Bone as Te } from "three";
|
|
9
|
-
import { uniform as
|
|
10
|
-
import { c as qe, F as ee } from "./face-tracker-utils-
|
|
9
|
+
import { uniform as U, attribute as _e, instancedArray as Ce, varying as De, vec3 as Ue, float as ze, select as Be, positionLocal as Ie, texture as He, vec2 as Ge } from "three/tsl";
|
|
10
|
+
import { c as qe, F as ee } from "./face-tracker-utils-BYPHYWo9.js";
|
|
11
11
|
import { GLTFExporter as je } from "three/examples/jsm/Addons.js";
|
|
12
|
-
const
|
|
12
|
+
const B = new x(), te = new x(), Ke = new x(1, 0, 0), $e = new x(-1, 0, 0), Xe = new x(0, 1, 0), Qe = new x(0, -1, 0), oe = new x(0, 0, 1);
|
|
13
13
|
new x(0, 0, -1);
|
|
14
14
|
const se = new x(), Ye = new x(), Ze = new x(), ne = new xe(), I = new xe();
|
|
15
15
|
function N(c, s, e, t = "+x") {
|
|
16
16
|
c.lookAt(s);
|
|
17
17
|
const o = t == "+x" ? Ke : t == "-x" ? $e : t == "+y" ? Xe : Qe;
|
|
18
|
-
c.getWorldPosition(te), c.getWorldQuaternion(I),
|
|
19
|
-
const n = se, a = Ye.copy(oe).applyQuaternion(I), r =
|
|
18
|
+
c.getWorldPosition(te), c.getWorldQuaternion(I), B.subVectors(e, te).normalize(), se.copy(o).applyQuaternion(I);
|
|
19
|
+
const n = se, a = Ye.copy(oe).applyQuaternion(I), r = B.clone().addScaledVector(a, -B.dot(a)).normalize(), i = Ze.crossVectors(n, r), l = Math.atan2(i.dot(a), n.dot(r));
|
|
20
20
|
ne.setFromAxisAngle(oe, l), c.quaternion.multiply(ne);
|
|
21
21
|
}
|
|
22
|
-
const
|
|
22
|
+
const z = new p.Vector3(), _ = new p.Vector3(), H = new p.Vector3();
|
|
23
23
|
new p.Vector3();
|
|
24
24
|
class j {
|
|
25
25
|
constructor(s, e) {
|
|
@@ -36,10 +36,10 @@ class j {
|
|
|
36
36
|
updateLandmarks(s, e, t) {
|
|
37
37
|
for (let o in this.points) {
|
|
38
38
|
const n = this.points[o], a = this.marks[o];
|
|
39
|
-
a && (n instanceof Array ? (
|
|
39
|
+
a && (n instanceof Array ? (z.copy(s[n[0]]), a.position.copy(s[n[1]]).sub(z).divideScalar(2).add(s[n[0]]), n.length == 4 && (z.subVectors(
|
|
40
40
|
s[n[3]],
|
|
41
41
|
s[n[2]]
|
|
42
|
-
).divideScalar(2).add(s[n[2]]).sub(a.position).divideScalar(2), a.position.add(
|
|
42
|
+
).divideScalar(2).add(s[n[2]]).sub(a.position).divideScalar(2), a.position.add(z))) : a.position.copy(s[n]));
|
|
43
43
|
}
|
|
44
44
|
t && e && t.drawConnectors(
|
|
45
45
|
e,
|
|
@@ -469,17 +469,17 @@ class kt extends j {
|
|
|
469
469
|
new x(), new x();
|
|
470
470
|
const o = new x();
|
|
471
471
|
new x();
|
|
472
|
-
const a = e.geometry.attributes.position, r = 209, i = 429, l =
|
|
472
|
+
const a = e.geometry.attributes.position, r = 209, i = 429, l = U(new x().addVectors(
|
|
473
473
|
new x(a.getX(r), a.getY(r), a.getZ(r)),
|
|
474
474
|
new x(a.getX(i), a.getY(i), a.getZ(i))
|
|
475
475
|
).multiplyScalar(0.5));
|
|
476
476
|
qe(e);
|
|
477
|
-
const m = _e("landmarkIndex", "
|
|
477
|
+
const m = _e("landmarkIndex", "float").toUint(), h = Ce(ee, "vec3"), b = De(h.element(m)).xy;
|
|
478
478
|
let u;
|
|
479
479
|
const E = 116, d = 346, y = o.subVectors(
|
|
480
480
|
new x(a.getX(E), a.getY(E), a.getZ(E)),
|
|
481
481
|
new x(a.getX(d), a.getY(d), a.getZ(d))
|
|
482
|
-
).lengthSq(), P =
|
|
482
|
+
).lengthSq(), P = U(y), k = U(1);
|
|
483
483
|
let L;
|
|
484
484
|
return {
|
|
485
485
|
/**
|
|
@@ -501,7 +501,7 @@ class kt extends j {
|
|
|
501
501
|
u = W;
|
|
502
502
|
const V = new Z(u);
|
|
503
503
|
V.colorSpace = J;
|
|
504
|
-
const M =
|
|
504
|
+
const M = U(u.videoWidth / u.videoHeight), Pe = h.element(d).sub(h.element(E)).lengthSq(), ve = P.div(Pe).sqrt(), ge = h.element(234).xy, K = h.element(93).xy, Ee = h.element(454).xy, $ = h.element(323).xy, X = ge.sub(K).div(2).add(K), We = Ee.sub($).div(2).add($).sub(X).div(2).add(X), Fe = h.element(m).sub(We).xzy.mul(Ue(1, -1, ze(1).div(M))).mul(ve).add(l), Q = Be(m.toUint().lessThanEqual(ee), Fe, Ie), O = He(V, Ge(b.x, b.y.oneMinus())), Y = () => {
|
|
505
505
|
const T = new Z(u);
|
|
506
506
|
T.colorSpace = J, O.value = T, O.needsUpdate = !0, M.value = u.videoWidth / u.videoHeight;
|
|
507
507
|
};
|
package/package.json
CHANGED