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.
@@ -8,7 +8,7 @@ const d = 478, g = (r) => {
8
8
  const u = n.get(o);
9
9
  i.push(u < d ? u : 65535);
10
10
  }
11
- s.setAttribute("landmarkIndex", new c(new Uint16Array(i), 1));
11
+ s.setAttribute("landmarkIndex", new c(new Float32Array(i), 1));
12
12
  };
13
13
  export {
14
14
  d as F,
@@ -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,EAAE,OAAO,EAA4B,YAAY,EAAW,MAAM,cAAc,CAAC;AAOxF,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,CAmUnK"}
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;AAgVD,wBAAsB,cAAc,CAAE,KAAK,EAAC,YAAY,qBAIvD"}
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 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) {
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 Xt(o, s) {
17
- const a = new AudioContext(), i = await Dt(o), n = await a.decodeAudioData(i);
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 g = Math.floor(t.audioSprite.start * n.sampleRate), m = Math.floor(t.duration * n.sampleRate), l = a.createBuffer(
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(g, g + m);
28
- l.getChannelData(r).set(e);
27
+ const e = n.getChannelData(r).subarray(w, w + m);
28
+ f.getChannelData(r).set(e);
29
29
  }
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");
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 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);
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 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;
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 ht = /* @__PURE__ */ new WeakMap();
50
- function Yt(o, s) {
51
- const a = ht.get(o) || new AudioContext();
52
- ht.set(o, a);
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 g = s[t];
70
- if (!g.audioSprite) return;
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, g.audioSprite.start, g.duration), n = m, m;
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 qt(o, s, a, i, n) {
76
+ function ee(o, s, a, i, n) {
77
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);
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 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 = {
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: () => 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)));
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(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);
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(y, v) {
128
- this.goto(y, !0, v);
156
+ gotoAndLoop(g, p) {
157
+ this.goto(g, !0, p);
129
158
  },
130
- gotoAndPlay(y, v) {
131
- this.goto(y, !1, v);
159
+ gotoAndPlay(g, p) {
160
+ this.goto(g, !1, p);
132
161
  },
133
- gotoAndStop(y, v = 0) {
134
- this.goto(y, !1, void 0, !1), U.value = v, st = !1;
162
+ gotoAndStop(g, p = 0) {
163
+ this.goto(g, !1, void 0, !1), A.value = p, it = !1;
135
164
  }
136
165
  };
137
- return V;
166
+ return S;
138
167
  }
139
- function Zt(o, s, a) {
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 _t(o, s = !0) {
145
- const a = await Ut(o, s);
173
+ async function oe(o, s = !0) {
174
+ const a = await Rt(o, s);
146
175
  return new Promise((i, n) => {
147
- St(new Uint8Array(a), { level: 9 }, (t, g) => {
176
+ Nt(new Uint8Array(a), { level: 9 }, (t, w) => {
148
177
  if (t) return n(t);
149
- const m = new Blob([g], { type: "application/octet-stream" });
178
+ const m = new Blob([w], { type: "application/octet-stream" });
150
179
  i(m);
151
180
  });
152
181
  });
153
182
  }
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);
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, 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);
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, C), e += 2, r.setUint16(e, k), e += 2, r.setInt16(e, P), e += 2;
203
+ r.setUint16(e, A), e += 2, r.setUint16(e, B), e += 2, r.setInt16(e, j), e += 2;
175
204
  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;
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, C), e += 2, r.setUint16(e, k), e += 2, r.setInt16(e, P), e += 2;
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 c = 0; c < i; c++) {
185
- const d = o.clips[c];
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 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;
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 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;
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 f;
231
+ return u;
203
232
  }
204
- async function ie(o) {
233
+ async function pe(o) {
205
234
  if (typeof o == "string") {
206
235
  const a = await (await fetch(o)).arrayBuffer();
207
- return it(a);
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(it(t));
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 it(o, s = !0) {
248
+ async function ft(o, s = !0) {
220
249
  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);
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 g = n.getUint32(t);
228
- if (t += 4, g !== wt) throw new Error("Invalid file: not a MCAP file");
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 l = n.getUint8(t);
260
+ const f = n.getUint8(t);
232
261
  t += 1;
233
- const A = n.getUint16(t);
262
+ const M = n.getUint16(t);
234
263
  t += 2;
235
- const M = n.getUint8(t);
264
+ const C = n.getUint8(t);
236
265
  t += 1;
237
- const x = [];
238
- for (let f = 0; f < l; f++) {
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), c = new TextDecoder().decode(e);
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 u = n.getUint8(t);
274
+ const c = n.getUint8(t);
246
275
  t += 1;
247
- const w = n.getUint8(t) / 100;
276
+ const v = n.getUint8(t) / 100;
248
277
  t += 1;
249
- const p = n.getUint8(t) / 100;
278
+ const h = n.getUint8(t) / 100;
250
279
  t += 1;
251
- const h = [], U = [], I = [];
280
+ const U = [], x = [], I = [];
252
281
  for (let b = 0; b < d; b++) {
253
- const C = m < 3 ? 1e3 : 1e4, k = n.getUint16(t) / C;
282
+ const A = m < 3 ? 1e3 : 1e4, B = n.getUint16(t) / A;
254
283
  t += 2;
255
- const P = n.getUint16(t) / C;
284
+ const j = n.getUint16(t) / A;
256
285
  t += 2;
257
- const N = n.getUint16(t) / C;
286
+ const K = n.getUint16(t) / A;
258
287
  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;
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 G = n.getUint16(t) / C;
292
+ const W = n.getUint16(t) / A;
264
293
  t += 2;
265
- const D = n.getUint16(t) / C;
294
+ const X = n.getUint16(t) / A;
266
295
  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;
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 T = n.getInt16(t) / 1e3;
277
- t += 2, Q.push({ x: F, y: E, z: T });
305
+ const O = n.getInt16(t) / 1e3;
306
+ t += 2, R.push({ x: P, y: E, z: O });
278
307
  } else {
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
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
- U.push(Q);
319
+ x.push(R);
291
320
  }
292
- x.push({
293
- name: c,
294
- fps: u,
295
- scale: w,
296
- aspectRatio: p,
297
- frames: I.map((b, C) => ({
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: h[C],
300
- startTime: C / u
328
+ frameUV: U[A],
329
+ startTime: A / c
301
330
  //<-- default for versions sub 2...
302
331
  })),
303
- landmarks: U,
304
- duration: d / u
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 f = 0; f < x.length; f++) {
338
+ for (let u = 0; u < y.length; u++) {
310
339
  let r = n.getUint16(t);
311
- t += 2, x[f].duration = r / 1e3;
340
+ t += 2, y[u].duration = r / 1e3;
312
341
  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));
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 f = 0; f < x.length; f++) {
316
- const r = x[f];
344
+ for (let u = 0; u < y.length; u++) {
345
+ const r = y[u];
317
346
  let e = 0;
318
- for (let c = 0; c < r.frames.length; c++) {
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 u = e + d / 1e3;
322
- r.frames[c].startTime = u, e = u;
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 f = 0; f < x.length; f++) {
328
- const r = x[f];
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 c = new Float32Array(n.buffer, t, 16);
331
- t += 64, r.frames[e].transformMatrix = new Bt().fromArray(c);
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: x,
366
+ clips: y,
338
367
  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");
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 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;
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 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);
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 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(
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
- h.frameUV.u * e.width,
368
- h.frameUV.v * e.height,
369
- h.frameUV.w * e.width,
370
- h.frameUV.h * e.height,
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
- U.width,
374
- U.height
402
+ x.width,
403
+ x.height
375
404
  ), {
376
- canvas: U,
377
- cropUV: h.cropUV,
378
- startTime: h.startTime
405
+ canvas: x,
406
+ cropUV: U.cropUV,
407
+ startTime: U.startTime,
408
+ transformMatrix: U.transformMatrix
379
409
  };
380
410
  })
381
411
  }));
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,
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(f, r, e, c) {
388
- return qt(r, x, f, e, c);
417
+ createMaterialHandlerOnMesh(u, r, e, l) {
418
+ return ee(r, y, u, e, l);
389
419
  }
390
420
  };
391
421
  }
392
- async function ce(o) {
393
- const s = await Ut(o);
394
- return it(s, !1);
422
+ async function ge(o) {
423
+ const s = await Rt(o);
424
+ return ft(s, !1);
395
425
  }
396
- function Kt(o) {
397
- const s = $t(o), a = [], i = [];
426
+ function ae(o) {
427
+ const s = re(o), a = [], i = [];
398
428
  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) {
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
- ...l,
406
- x: M.currentX,
407
- y: M.y
408
- }), M.currentX += l.width, A = !0;
435
+ ...f,
436
+ x: C.currentX,
437
+ y: C.y
438
+ }), C.currentX += f.width, M = !0;
409
439
  break;
410
440
  }
411
- if (!A) {
412
- const M = {
441
+ if (!M) {
442
+ const C = {
413
443
  y: n,
414
- height: l.height,
415
- currentX: l.width
444
+ height: f.height,
445
+ currentX: f.width
416
446
  };
417
- a.push(M), i.push({
418
- ...l,
447
+ a.push(C), i.push({
448
+ ...f,
419
449
  x: 0,
420
450
  y: n
421
- }), n += l.height;
451
+ }), n += f.height;
422
452
  }
423
453
  }
424
- const g = a.length > 0 ? Math.max(...a.map((l) => l.currentX)) : 0, m = n;
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(g, s),
457
+ width: Math.max(w, s),
428
458
  height: m
429
459
  };
430
460
  }
431
- function $t(o) {
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 = Gt(a), a;
466
+ return a = Math.max(a, i), a = Vt(a), a;
437
467
  }
438
- function Gt(o) {
468
+ function Vt(o) {
439
469
  return Math.pow(2, Math.ceil(Math.log2(o)));
440
470
  }
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]) => ({
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: 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);
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 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
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 c = 0;
493
+ let l = 0;
464
494
  for (const d of o) {
465
- const u = {
495
+ const c = {
466
496
  ...d,
467
497
  frames: []
468
498
  };
469
- for (const w of d.frames)
470
- u.frames.push({
471
- frameUV: r[c++],
472
- cropUV: w.cropUV,
473
- startTime: w.startTime,
474
- transformMatrix: w.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(u);
506
+ e.push(c);
477
507
  }
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,
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 u = await _t(this);
514
+ const c = await oe(this);
485
515
  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();
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 u;
519
+ return c;
490
520
  },
491
- async saveImageAtlas(d, u) {
492
- const w = document.createElement("a");
493
- w.download = u ? "atlas.jpg" : "atlas.png";
494
- let p = this.canvas;
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 Jt(p, d, u);
497
- w.href = p.toDataURL(u ? "image/jpeg" : "image/png", u ? 0.8 : 1), w.click();
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 ct(o, s) {
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 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);
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 fe(o, s) {
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 gt(i, s);
548
+ return await Ct(i, s);
519
549
  } else
520
- return new pt().loadAsync(o);
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 = (g) => {
526
- const m = g.target.result;
527
- i(gt(m, s));
528
- }, t.onerror = (g) => {
529
- n(g);
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 pt().load(a, i, void 0, n);
564
+ new Mt().load(a, i, void 0, n);
535
565
  });
536
566
  }
537
567
  }
538
- async function gt(o, s) {
568
+ async function Ct(o, s) {
539
569
  if (!s)
540
570
  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;
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 g = new Nt(t);
546
- return g.needsUpdate = !0, g;
575
+ const w = new Kt(t);
576
+ return w.needsUpdate = !0, w;
547
577
  }
548
- async function de(o, s) {
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((g, m) => {
552
- a.toBlob((l) => {
553
- if (!l) {
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
- g(l.arrayBuffer());
587
+ w(f.arrayBuffer());
558
588
  }, "image/jpeg", 0.75);
559
- }), t = ct(n, s);
589
+ }), t = dt(n, s);
560
590
  return new Blob([t], { type: "application/octet-stream" });
561
591
  }
562
592
  export {
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
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 z, attribute as _e, instancedArray as Ce, varying as De, vec3 as ze, float as Be, select as Ue, positionLocal as Ie, texture as He, vec2 as Ge } from "three/tsl";
10
- import { c as qe, F as ee } from "./face-tracker-utils-xt9__vBF.js";
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 U = 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);
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), U.subVectors(e, te).normalize(), se.copy(o).applyQuaternion(I);
19
- const n = se, a = Ye.copy(oe).applyQuaternion(I), r = U.clone().addScaledVector(a, -U.dot(a)).normalize(), i = Ze.crossVectors(n, r), l = Math.atan2(i.dot(a), n.dot(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 B = new p.Vector3(), _ = new p.Vector3(), H = new p.Vector3();
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 ? (B.copy(s[n[0]]), a.position.copy(s[n[1]]).sub(B).divideScalar(2).add(s[n[0]]), n.length == 4 && (B.subVectors(
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(B))) : a.position.copy(s[n]));
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 = z(new x().addVectors(
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", "uint"), h = Ce(ee, "vec3"), b = De(h.element(m)).xy;
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 = z(y), k = z(1);
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 = z(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(ze(1, -1, Be(1).div(M))).mul(ve).add(l), Q = Ue(m.toUint().lessThanEqual(ee), Fe, Ie), O = He(V, Ge(b.x, b.y.oneMinus())), Y = () => {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-mediapipe-rig",
3
- "version": "0.1.4",
3
+ "version": "0.1.41",
4
4
  "type": "module",
5
5
  "description": "Easy setup of a skeletal rig that responds to the motion tracker provided by google's mediapipe webwam feed.",
6
6
  "repository": {