three-mediapipe-rig 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +1,113 @@
1
- var nt = Object.defineProperty;
2
- var rt = (l, o, t) => o in l ? nt(l, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[o] = t;
3
- var y = (l, o, t) => rt(l, typeof o != "symbol" ? o + "" : o, t);
4
- import { PoseLandmarker as tt, HandLandmarker as S, FaceLandmarker as C, FilesetResolver as at, DrawingUtils as dt } from "@mediapipe/tasks-vision";
5
- import * as h from "three/webgpu";
6
- import { Vector3 as L, Quaternion as et } from "three/webgpu";
7
- import { Bone as lt } from "three";
8
- const N = new L(), D = new L(), ht = new L(1, 0, 0), ct = new L(-1, 0, 0), pt = new L(0, 1, 0), mt = new L(0, -1, 0), T = new L(0, 0, 1);
9
- new L(0, 0, -1);
10
- const g = new L(), ut = new L(), ft = new L(), B = new et(), O = new et();
11
- function A(l, o, t, e = "+x") {
12
- l.lookAt(o);
13
- const s = e == "+x" ? ht : e == "-x" ? ct : e == "+y" ? pt : mt;
14
- l.getWorldPosition(D), l.getWorldQuaternion(O), N.subVectors(t, D).normalize(), g.copy(s).applyQuaternion(O);
15
- const i = g, r = ut.copy(T).applyQuaternion(O), n = N.clone().addScaledVector(r, -N.dot(r)).normalize(), a = ft.crossVectors(i, n), c = Math.atan2(a.dot(r), i.dot(n));
16
- B.setFromAxisAngle(T, c), l.quaternion.multiply(B);
1
+ var he = Object.defineProperty;
2
+ var ce = (h, s, e) => s in h ? he(h, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[s] = e;
3
+ var k = (h, s, e) => ce(h, typeof s != "symbol" ? s + "" : s, e);
4
+ import { PoseLandmarker as se, HandLandmarker as D, FaceLandmarker as C, FilesetResolver as le, DrawingUtils as pe } from "@mediapipe/tasks-vision";
5
+ import * as l from "three/webgpu";
6
+ import { Vector3 as P, Quaternion as ie } from "three/webgpu";
7
+ import * as S from "three";
8
+ import { Bone as me } from "three";
9
+ import { GLTFExporter as ue } from "three/examples/jsm/Addons.js";
10
+ const V = new P(), z = new P(), fe = new P(1, 0, 0), ye = new P(-1, 0, 0), we = new P(0, 1, 0), Le = new P(0, -1, 0), B = new P(0, 0, 1);
11
+ new P(0, 0, -1);
12
+ const I = new P(), ke = new P(), be = new P(), U = new ie(), O = new ie();
13
+ function A(h, s, e, t = "+x") {
14
+ h.lookAt(s);
15
+ const o = t == "+x" ? fe : t == "-x" ? ye : t == "+y" ? we : Le;
16
+ h.getWorldPosition(z), h.getWorldQuaternion(O), V.subVectors(e, z).normalize(), I.copy(o).applyQuaternion(O);
17
+ const i = I, r = ke.copy(B).applyQuaternion(O), n = V.clone().addScaledVector(r, -V.dot(r)).normalize(), a = be.crossVectors(i, n), c = Math.atan2(a.dot(r), i.dot(n));
18
+ U.setFromAxisAngle(B, c), h.quaternion.multiply(U);
17
19
  }
18
- const V = new h.Vector3(), F = new h.Vector3(), _ = new h.Vector3();
19
- new h.Vector3();
20
- class z {
21
- constructor(o, t) {
22
- y(this, "objectGhost");
23
- y(this, "root");
20
+ const N = new l.Vector3(), M = new l.Vector3(), T = new l.Vector3();
21
+ new l.Vector3();
22
+ class _ {
23
+ constructor(s, e) {
24
+ k(this, "objectGhost");
25
+ k(this, "root");
24
26
  /**
25
27
  * per landmark index, it points to it's object3D equivalent.
26
28
  */
27
- y(this, "marks", {});
28
- this.points = o, this.debugConnections = t, this.root = new h.Object3D(), this.objectGhost = /* @__PURE__ */ new Map();
29
- for (let e in this.points)
30
- this.marks[e] = new yt(), this.root.add(this.marks[e]);
31
- }
32
- updateLandmarks(o, t, e) {
33
- for (let s in this.points) {
34
- const i = this.points[s], r = this.marks[s];
35
- r && (i instanceof Array ? (V.copy(o[i[0]]), r.position.copy(o[i[1]]).sub(V).divideScalar(2).add(o[i[0]]), i.length == 4 && (V.subVectors(
36
- o[i[3]],
37
- o[i[2]]
38
- ).divideScalar(2).add(o[i[2]]).sub(r.position).divideScalar(2), r.position.add(V))) : r.position.copy(o[i]));
29
+ k(this, "marks", {});
30
+ this.points = s, this.debugConnections = e, this.root = new l.Object3D(), this.objectGhost = /* @__PURE__ */ new Map();
31
+ for (let t in this.points)
32
+ this.marks[t] = new xe(), this.root.add(this.marks[t]);
33
+ }
34
+ updateLandmarks(s, e, t) {
35
+ for (let o in this.points) {
36
+ const i = this.points[o], r = this.marks[o];
37
+ r && (i instanceof Array ? (N.copy(s[i[0]]), r.position.copy(s[i[1]]).sub(N).divideScalar(2).add(s[i[0]]), i.length == 4 && (N.subVectors(
38
+ s[i[3]],
39
+ s[i[2]]
40
+ ).divideScalar(2).add(s[i[2]]).sub(r.position).divideScalar(2), r.position.add(N))) : r.position.copy(s[i]));
39
41
  }
40
- e && t && e.drawConnectors(
41
- t,
42
+ t && e && t.drawConnectors(
43
+ e,
42
44
  this.debugConnections,
43
45
  {
44
46
  lineWidth: 1
45
47
  }
46
48
  );
47
49
  }
48
- getGhost(o) {
49
- var t;
50
- if (!this.objectGhost.has(o)) {
51
- const e = new wt();
52
- e.position.copy(o.position), e.quaternion.copy(o.quaternion), (t = o.parent) == null || t.add(e), this.objectGhost.set(o, e);
50
+ getGhost(s) {
51
+ var e;
52
+ if (!this.objectGhost.has(s)) {
53
+ const t = new Re();
54
+ t.position.copy(s.position), t.quaternion.copy(s.quaternion), (e = s.parent) == null || e.add(t), this.objectGhost.set(s, t);
53
55
  }
54
- return this.objectGhost.get(o);
56
+ return this.objectGhost.get(s);
55
57
  }
56
- predict(o, t) {
58
+ predict(s, e) {
57
59
  throw new Error("Method 'predict' must be implemented.");
58
60
  }
59
- sync(o, t) {
61
+ sync(s, e) {
60
62
  throw new Error("Method 'sync' must be implemented.");
61
63
  }
62
- test(o) {
63
- this.marks[o].position.set(1, 2, 3);
64
+ test(s) {
65
+ this.marks[s].position.set(1, 2, 3);
64
66
  }
65
- syncObjects(o, t, e) {
66
- for (const [s, i, r, n] of o) {
67
- this.marks[r].getWorldPosition(_), this.marks[i].getWorldPosition(F);
68
- const a = _.sub(F);
69
- s.getWorldPosition(F), F.add(a);
70
- const c = F, m = s.getWorldPosition(_).sub(e), f = this.getGhost(s);
71
- A(f, c, m, n), f.rotateX(Math.PI / 2), s.position.lerp(f.position, t * 4), s.quaternion.slerp(f.quaternion, t * 4);
67
+ syncObjects(s, e, t) {
68
+ for (const [o, i, r, n] of s) {
69
+ this.marks[r].getWorldPosition(T), this.marks[i].getWorldPosition(M);
70
+ const a = T.sub(M);
71
+ o.getWorldPosition(M), M.add(a);
72
+ const c = M, p = o.getWorldPosition(T).sub(t), f = this.getGhost(o);
73
+ A(f, c, p, n), f.rotateX(Math.PI / 2), o.position.lerp(f.position, e * 4), o.quaternion.slerp(f.quaternion, e * 4);
72
74
  }
73
75
  }
74
- getBone(o, t) {
75
- return o.getObjectByName(t.replace(/[\.\:]/g, ""));
76
+ getBone(s, e) {
77
+ return s.getObjectByName(e.replace(/[\.\:]/g, ""));
76
78
  }
77
79
  }
78
- class yt extends h.Mesh {
80
+ class xe extends l.Mesh {
79
81
  constructor() {
80
- super(new h.SphereGeometry(0.01, 3, 3), new h.MeshStandardMaterial({ color: 16711680, wireframe: !0 }));
81
- y(this, "_worldPosition", new h.Vector3());
82
- this.add(new h.AxesHelper(1e-3));
82
+ super(new l.SphereGeometry(0.01, 3, 3), new l.MeshStandardMaterial({ color: 16711680, wireframe: !0 }));
83
+ k(this, "_worldPosition", new l.Vector3());
84
+ this.add(new l.AxesHelper(1e-3));
83
85
  }
84
86
  get worldPosition() {
85
87
  return this.getWorldPosition(this._worldPosition), this._worldPosition;
86
88
  }
87
89
  }
88
- class wt extends h.Object3D {
89
- lerp(o, t, e = 8) {
90
- o.position.lerp(this.position, t * e), o.quaternion.slerp(this.quaternion, t * e);
90
+ class Re extends l.Object3D {
91
+ lerp(s, e, t = 8) {
92
+ s.position.lerp(this.position, e * t), s.quaternion.slerp(this.quaternion, e * t);
91
93
  }
92
94
  }
93
- function E(l, o, t) {
94
- return t.worldToLocal(o.getWorldPosition(l)), l;
95
+ function F(h, s, e) {
96
+ return e.worldToLocal(s.getWorldPosition(h)), h;
95
97
  }
96
- function Lt(l) {
97
- return l.replace(/[\.\:]/g, "");
98
+ function Pe(h) {
99
+ return h.replace(/[\.\:]/g, "");
98
100
  }
99
- function w(l, o) {
100
- let t;
101
- return o = Lt(o), l.traverse((e) => {
102
- e.name.indexOf(o) === 0 && e instanceof lt && (t = e);
103
- }), t || console.log("Bone not found: ", o, l.name), t;
101
+ function x(h, s) {
102
+ let e;
103
+ return s = Pe(s), h.traverse((t) => {
104
+ t.name.indexOf(s) === 0 && t instanceof me && (e = t);
105
+ }), e || console.log("Bone not found: ", s, h.name), e;
104
106
  }
105
- async function kt(l, o) {
106
- const t = await tt.createFromOptions(l, {
107
+ async function We(h, s) {
108
+ const e = await se.createFromOptions(h, {
107
109
  baseOptions: {
108
- modelAssetPath: (o == null ? void 0 : o.modelPath) ?? "pose_landmarker_lite.task",
110
+ modelAssetPath: (s == null ? void 0 : s.modelPath) ?? "pose_landmarker_lite.task",
109
111
  //modelAssetPath: `https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task`,
110
112
  //modelAssetPath: "https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_heavy/float16/latest/pose_landmarker_heavy.task",
111
113
  delegate: "GPU"
@@ -113,9 +115,9 @@ async function kt(l, o) {
113
115
  runningMode: "VIDEO",
114
116
  numPoses: 1
115
117
  });
116
- return new Et(t, o);
118
+ return new ge(e, s);
117
119
  }
118
- const xt = {
120
+ const Ee = {
119
121
  hips: [24, 23],
120
122
  neck: [12, 11],
121
123
  leftLeg: 23,
@@ -137,13 +139,13 @@ const xt = {
137
139
  torso: [24, 23, 12, 11],
138
140
  leftEar: 7,
139
141
  rightEar: 8
140
- }, bt = new h.Vector3(), G = new h.Vector3(), Pt = new h.Vector3(), Rt = new h.Vector3(), Wt = new h.Vector3(), I = new h.Vector3(), H = new h.Vector3();
141
- class Et extends z {
142
- constructor(t, e) {
143
- super(xt, tt.POSE_CONNECTIONS);
144
- y(this, "_leftWristNormalizedPosition");
145
- y(this, "_rightWristNormalizedPosition");
146
- this.poseLandmarker = t, this.config = e, this.root.scale.y *= -2, this.root.scale.z *= -2, this.root.scale.x *= 2;
142
+ }, Fe = new l.Vector3(), G = new l.Vector3(), Ae = new l.Vector3(), Me = new l.Vector3(), ve = new l.Vector3(), H = new l.Vector3(), $ = new l.Vector3();
143
+ class ge extends _ {
144
+ constructor(e, t) {
145
+ super(Ee, se.POSE_CONNECTIONS);
146
+ k(this, "_leftWristNormalizedPosition");
147
+ k(this, "_rightWristNormalizedPosition");
148
+ this.poseLandmarker = e, this.config = t, this.root.scale.y *= -2, this.root.scale.z *= -2, this.root.scale.x *= 2;
147
149
  }
148
150
  /**
149
151
  * Position of the left wrist in normalized coordinates (0..1)
@@ -157,9 +159,9 @@ class Et extends z {
157
159
  get rightWristNormalizedPosition() {
158
160
  return this._rightWristNormalizedPosition;
159
161
  }
160
- predict(t, e) {
161
- this.poseLandmarker.detectForVideo(t, performance.now(), (s) => {
162
- s.landmarks.length != 0 && (this.updateLandmarks(s.worldLandmarks[0], s.landmarks[0], e), this._leftWristNormalizedPosition = s.landmarks[0][this.points.leftWrist], this._rightWristNormalizedPosition = s.landmarks[0][this.points.rightWrist]);
162
+ predict(e, t) {
163
+ this.poseLandmarker.detectForVideo(e, performance.now(), (o) => {
164
+ o.landmarks.length != 0 && (this.updateLandmarks(o.worldLandmarks[0], o.landmarks[0], t), this._leftWristNormalizedPosition = o.landmarks[0][this.points.leftWrist], this._rightWristNormalizedPosition = o.landmarks[0][this.points.rightWrist]);
163
165
  });
164
166
  }
165
167
  // override sync ( delta:number, objects: BoneBinding[] ) {
@@ -169,59 +171,66 @@ class Et extends z {
169
171
  // const torsoNormal = C.crossVectors(A,B);
170
172
  // this.syncObjects(objects, delta, torsoNormal);
171
173
  // }
172
- bind(t, e) {
174
+ bind(e, t) {
173
175
  var a;
174
- const s = {
175
- hips: w(t, e.hips),
176
- neck: w(t, e.neck),
177
- leftArm: w(t, e.armL),
178
- leftElbow: w(t, e.forearmL),
179
- leftWrist: w(t, e.handL),
180
- rightArm: w(t, e.armR),
181
- rightElbow: w(t, e.forearmR),
182
- rightWrist: w(t, e.handR),
183
- head: w(t, e.head),
184
- torso: w(t, e.torso),
185
- leftLeg: w(t, e.thighL),
186
- leftKnee: w(t, e.shinL),
187
- leftFoot: w(t, e.footL),
188
- rightLeg: w(t, e.thighR),
189
- rightKnee: w(t, e.shinR),
190
- rightFoot: w(t, e.footR)
176
+ const o = {
177
+ hips: x(e, t.hips),
178
+ neck: x(e, t.neck),
179
+ leftArm: x(e, t.armL),
180
+ leftElbow: x(e, t.forearmL),
181
+ leftWrist: x(e, t.handL),
182
+ rightArm: x(e, t.armR),
183
+ rightElbow: x(e, t.forearmR),
184
+ rightWrist: x(e, t.handR),
185
+ head: x(e, t.head),
186
+ torso: x(e, t.torso),
187
+ leftLeg: x(e, t.thighL),
188
+ leftKnee: x(e, t.shinL),
189
+ leftFoot: x(e, t.footL),
190
+ rightLeg: x(e, t.thighR),
191
+ rightKnee: x(e, t.shinR),
192
+ rightFoot: x(e, t.footR)
191
193
  };
192
- (a = this.config) != null && a.ignoreLegs && (delete s.leftLeg, delete s.leftKnee, delete s.leftFoot, delete s.leftToes, delete s.rightLeg, delete s.rightKnee, delete s.rightFoot, delete s.rightToes);
193
- const i = new h.Vector3(), r = new h.Vector3(), n = (c, m, f, k, d, p) => {
194
- if (!m) return;
195
- const P = this.marks[k].getWorldPosition(i).sub(this.marks[f].getWorldPosition(r)).normalize();
196
- E(I, m, t).add(P).applyMatrix4(t.matrixWorld), E(H, m, t).add(d).applyMatrix4(t.matrixWorld);
197
- const x = this.getGhost(m);
198
- A(x, I, H, p), x.rotateX(Math.PI / 2), x.lerp(m, c);
194
+ (a = this.config) != null && a.ignoreLegs && (delete o.leftLeg, delete o.leftKnee, delete o.leftFoot, delete o.leftToes, delete o.rightLeg, delete o.rightKnee, delete o.rightFoot, delete o.rightToes);
195
+ const i = new l.Vector3(), r = new l.Vector3(), n = (c, p, f, R, d, m) => {
196
+ if (!p) return;
197
+ const L = this.marks[R].getWorldPosition(i).sub(this.marks[f].getWorldPosition(r)).normalize();
198
+ F(H, p, e).add(L).applyMatrix4(e.matrixWorld), F($, p, e).add(d).applyMatrix4(e.matrixWorld);
199
+ const u = this.getGhost(p);
200
+ A(u, H, $, m), u.rotateX(Math.PI / 2), u.lerp(p, c);
199
201
  };
200
202
  return {
201
203
  update: (c) => {
202
- const m = this.marks.leftLeg.getWorldPosition(bt).sub(this.marks.rightLeg.getWorldPosition(G)).normalize(), f = this.marks.leftArm.getWorldPosition(G).sub(this.marks.rightArm.getWorldPosition(Pt)).normalize(), k = this.marks.leftEar.getWorldPosition(Rt).sub(this.marks.rightEar.getWorldPosition(Wt)).normalize();
203
- n(c, s.hips, "hips", "torso", m, "+x"), n(c, s.torso, "torso", "neck", f, "+x"), n(c, s.neck, "neck", "head", k, "+x"), n(c, s.head, "neck", "head", k, "+x"), n(c, s.leftArm, "leftArm", "leftElbow", f, "-x"), n(c, s.leftElbow, "leftElbow", "leftWrist", f, "-x"), n(c, s.leftLeg, "leftLeg", "leftKnee", m, "+x"), n(c, s.leftKnee, "leftKnee", "leftFoot", m, "+x"), n(c, s.leftFoot, "leftFoot", "leftToes", m, "+x"), n(c, s.rightArm, "rightArm", "rightElbow", f, "-x"), n(c, s.rightElbow, "rightElbow", "rightWrist", f, "-x"), n(c, s.rightLeg, "rightLeg", "rightKnee", m, "+x"), n(c, s.rightKnee, "rightKnee", "rightFoot", m, "+x"), n(c, s.rightFoot, "rightFoot", "rightToes", m, "+x");
204
+ const p = this.marks.leftLeg.getWorldPosition(Fe).sub(this.marks.rightLeg.getWorldPosition(G)).normalize(), f = this.marks.leftArm.getWorldPosition(G).sub(this.marks.rightArm.getWorldPosition(Ae)).normalize(), R = this.marks.leftEar.getWorldPosition(Me).sub(this.marks.rightEar.getWorldPosition(ve)).normalize();
205
+ n(c, o.hips, "hips", "torso", p, "+x"), n(c, o.torso, "torso", "neck", f, "+x"), n(c, o.neck, "neck", "head", R, "+x"), n(c, o.head, "neck", "head", R, "+x"), n(c, o.leftArm, "leftArm", "leftElbow", f, "-x"), n(c, o.leftElbow, "leftElbow", "leftWrist", f, "-x"), n(c, o.leftLeg, "leftLeg", "leftKnee", p, "+x"), n(c, o.leftKnee, "leftKnee", "leftFoot", p, "+x"), n(c, o.leftFoot, "leftFoot", "leftToes", p, "+x"), n(c, o.rightArm, "rightArm", "rightElbow", f, "-x"), n(c, o.rightElbow, "rightElbow", "rightWrist", f, "-x"), n(c, o.rightLeg, "rightLeg", "rightKnee", p, "+x"), n(c, o.rightKnee, "rightKnee", "rightFoot", p, "+x"), n(c, o.rightFoot, "rightFoot", "rightToes", p, "+x");
204
206
  }
205
207
  };
206
208
  }
207
209
  }
208
- const $ = new h.Vector2(), U = new h.Vector2();
209
- async function At(l, o) {
210
- const t = await S.createFromOptions(l, {
210
+ const j = new l.Vector2(), q = new l.Vector2();
211
+ async function Se(h, s) {
212
+ const e = await D.createFromOptions(h, {
211
213
  baseOptions: {
212
- modelAssetPath: o.modelPath ?? "hand_landmarker.task",
214
+ modelAssetPath: s.modelPath ?? "hand_landmarker.task",
213
215
  //modelAssetPath: `https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,
214
216
  delegate: "GPU"
215
217
  },
216
218
  runningMode: "VIDEO",
217
219
  numHands: 2
218
- }), e = (s, i, r) => ($.copy(s()), U.copy(i()), $.distanceTo(r) < U.distanceTo(r));
220
+ }), t = (o, i, r) => {
221
+ try {
222
+ j.copy(o()), q.copy(i());
223
+ } catch (n) {
224
+ return console.warn("No pose data... will just be optimitic and say yes to everything.", n), !0;
225
+ }
226
+ return j.distanceTo(r) < q.distanceTo(r);
227
+ };
219
228
  return {
220
- left: new Z(t, "Left", e.bind(null, o.leftWrist, o.rightWrist)),
221
- right: new Z(t, "Right", e.bind(null, o.rightWrist, o.leftWrist))
229
+ left: new te(e, "Left", t.bind(null, s.leftWrist, s.rightWrist)),
230
+ right: new te(e, "Right", t.bind(null, s.rightWrist, s.leftWrist))
222
231
  };
223
232
  }
224
- const Mt = {
233
+ const Ne = {
225
234
  wrist: 0,
226
235
  palm: [9, 13],
227
236
  thumb1: 1,
@@ -250,36 +259,37 @@ const Mt = {
250
259
  middle: ["middle1", "middle2", "middle3", "middle4"],
251
260
  ring: ["ring1", "ring2", "ring3", "ring4"],
252
261
  pinky: ["pinky1", "pinky2", "pinky3", "pinky4"]
253
- }, Ft = new h.Vector3(), K = new h.Vector3(), j = new h.Vector3(), q = new h.Vector3(), X = new h.Vector3(), vt = new h.Vector3();
254
- new h.Vector3();
255
- new h.Vector3();
256
- const Q = new h.Vector3(), Y = Math.PI / 2, Vt = new h.Vector3(0, -1, 0);
257
- class Z extends z {
258
- constructor(t, e, s) {
259
- super(Mt, S.HAND_CONNECTIONS);
260
- y(this, "sign");
261
- y(this, "isLeft");
262
+ }, Ve = new l.Vector3(), K = new l.Vector3(), X = new l.Vector3(), Q = new l.Vector3(), Y = new l.Vector3(), Z = new l.Vector3();
263
+ new l.Vector3();
264
+ new l.Vector3();
265
+ new l.Vector3();
266
+ const J = new l.Vector3(), ee = Math.PI / 2, Oe = new l.Vector3(0, -1, 0);
267
+ class te extends _ {
268
+ constructor(e, t, o) {
269
+ super(Ne, D.HAND_CONNECTIONS);
270
+ k(this, "sign");
271
+ k(this, "isLeft");
262
272
  /**
263
273
  * the axis used to look at the pole
264
274
  */
265
- y(this, "lookAtPoleAxis");
266
- this.handLandmarker = t, this.side = e, this.isMyWrist = s, this.sign = this.side == "Left" ? -1 : 1, this.isLeft = this.side == "Left", this.lookAtPoleAxis = this.sign < 0 ? "+x" : "-x", this.root.scale.setScalar(2), this.root.scale.y *= -1, this.root.scale.z *= -1;
267
- }
268
- predict(t, e) {
269
- const s = this.handLandmarker.detectForVideo(t, performance.now());
270
- if (s.landmarks.length)
271
- for (let i = 0; i < s.landmarks.length; i++) {
272
- const r = s.landmarks[i], n = r[this.points.wrist];
275
+ k(this, "lookAtPoleAxis");
276
+ this.handLandmarker = e, this.side = t, this.isMyWrist = o, this.sign = this.side == "Left" ? -1 : 1, this.isLeft = this.side == "Left", this.lookAtPoleAxis = this.sign < 0 ? "+x" : "-x", this.root.scale.setScalar(7), this.root.scale.y *= -1, this.root.scale.z *= -1;
277
+ }
278
+ predict(e, t) {
279
+ const o = this.handLandmarker.detectForVideo(e, performance.now());
280
+ if (o.landmarks.length)
281
+ for (let i = 0; i < o.landmarks.length; i++) {
282
+ const r = o.landmarks[i], n = r[this.points.wrist];
273
283
  if (this.isMyWrist(n)) {
274
- this.updateLandmarks(s.worldLandmarks[i]), e.drawConnectors(r, S.HAND_CONNECTIONS, {
284
+ this.updateLandmarks(o.worldLandmarks[i]), t.drawConnectors(r, D.HAND_CONNECTIONS, {
275
285
  color: this.side == "Left" ? "#00FF00" : "#0000FF",
276
286
  lineWidth: 4
277
- }), e.drawLandmarks(r, { color: this.side == "Left" ? "#00FF00" : "#0000FF", lineWidth: 3, radius: 1 });
287
+ }), t.drawLandmarks(r, { color: this.side == "Left" ? "#00FF00" : "#0000FF", lineWidth: 3, radius: 1 });
278
288
  break;
279
289
  }
280
290
  }
281
291
  }
282
- sync(t, e) {
292
+ sync(e, t) {
283
293
  throw new Error("Not used. Use syncHandBones instead");
284
294
  }
285
295
  /**
@@ -288,64 +298,68 @@ class Z extends z {
288
298
  * @param landmark2bones Array the same size as the umber of hand landmarks, and on each positionthe bone that belongs to that point.
289
299
  * @see https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker
290
300
  */
291
- syncHandBones(t, e, s) {
292
- const i = Ft.crossVectors(
301
+ syncHandBones(e, t, o) {
302
+ const i = Ve.crossVectors(
293
303
  K.copy(this.marks.index1.worldPosition).sub(this.marks.wrist.worldPosition),
294
- j.copy(this.marks.pinky1.worldPosition).sub(this.marks.wrist.worldPosition)
295
- ).normalize(), r = K.copy(this.marks.palm.worldPosition).sub(this.marks.wrist.worldPosition).normalize(), n = j.copy(this.marks.pinky1.worldPosition).sub(this.marks.index1.worldPosition).normalize();
296
- if (!(r.dot(Vt) > 0.8)) {
297
- if (e.wrist) {
298
- const a = E(q, e.wrist, s).add(r).applyMatrix4(s.matrixWorld), c = E(X, e.wrist, s).sub(n).applyMatrix4(s.matrixWorld), m = this.getGhost(e.wrist);
299
- A(m, a, c, "-y"), m.rotateX(Y), m.lerp(e.wrist, t);
304
+ X.copy(this.marks.pinky1.worldPosition).sub(this.marks.wrist.worldPosition)
305
+ ).normalize(), r = K.copy(this.marks.palm.worldPosition).sub(this.marks.wrist.worldPosition).normalize(), n = X.copy(this.marks.pinky1.worldPosition).sub(this.marks.index1.worldPosition).normalize();
306
+ if (!(r.dot(Oe) > 0.8)) {
307
+ if (t.wrist) {
308
+ const a = F(Q, t.wrist, o).add(r).applyMatrix4(o.matrixWorld), c = F(Y, t.wrist, o).sub(n).applyMatrix4(o.matrixWorld), p = this.getGhost(t.wrist);
309
+ A(p, a, c, "-y"), p.rotateX(ee), p.lerp(t.wrist, e);
300
310
  }
301
- this.syncFinger(t, s, i, r, n, e, v.index, "middle1"), this.syncFinger(t, s, i, r, n, e, v.middle, "ring1"), this.syncFinger(t, s, i, r, n, e, v.ring, "pinky1"), this.syncFinger(t, s, i, r, n, e, v.pinky, "ring1", !0), this.syncFinger(t, s, i, r, n, e, v.thumb, "index1");
311
+ this.syncFinger(e, o, i, r, n, t, v.index, "middle1"), this.syncFinger(e, o, i, r, n, t, v.middle, "ring1"), this.syncFinger(e, o, i, r, n, t, v.ring, "pinky1"), this.syncFinger(e, o, i, r, n, t, v.pinky, "ring1", !0), this.syncFinger(e, o, i, r, n, t, v.thumb, "index1");
302
312
  }
303
313
  }
304
- syncFinger(t, e, s, i, r, n, a, c, m = !1) {
314
+ syncFinger(e, t, o, i, r, n, a, c, p = !1) {
305
315
  for (let f = 0; f < a.length - 1; f++) {
306
- const k = n[a[f]];
307
- if (!k) continue;
308
- const d = q.copy(this.marks[a[f + 1]].worldPosition).sub(this.marks[a[f]].worldPosition).normalize(), p = E(X, k, e), P = vt.copy(p).add(r);
309
- m && P.negate();
310
- const x = this.getGhost(k);
311
- f == 0 ? (Q.copy(P), A(
312
- x,
313
- d.add(p).applyMatrix4(e.matrixWorld),
314
- P.add(p).applyMatrix4(e.matrixWorld),
315
- this.lookAtPoleAxis
316
- )) : (P.copy(Q), A(
317
- x,
318
- d.add(p).applyMatrix4(e.matrixWorld),
319
- P.add(p).applyMatrix4(e.matrixWorld),
320
- this.lookAtPoleAxis
321
- )), x.rotateX(Y), x.lerp(k, t);
316
+ const R = n[a[f]];
317
+ if (!R) continue;
318
+ const d = this.getGhost(R), m = Q.copy(this.marks[a[f + 1]].worldPosition).sub(this.marks[a[f]].worldPosition).normalize(), L = F(Y, R, t);
319
+ if (f == 0) {
320
+ const u = Z.copy(this.marks[c].worldPosition).sub(this.marks[a[0]].worldPosition).normalize();
321
+ p && u.negate(), J.copy(u), A(
322
+ d,
323
+ m.add(L).applyMatrix4(t.matrixWorld),
324
+ u.add(L).applyMatrix4(t.matrixWorld),
325
+ this.lookAtPoleAxis
326
+ );
327
+ } else
328
+ A(
329
+ d,
330
+ m.add(L).applyMatrix4(t.matrixWorld),
331
+ Z.copy(J).add(L).applyMatrix4(t.matrixWorld),
332
+ this.lookAtPoleAxis
333
+ );
334
+ d.rotateX(ee), d.lerp(R, e);
322
335
  }
323
336
  }
324
- bind(t, e) {
325
- const s = {}, i = (r, n) => {
326
- const a = w(t, r);
327
- a && (s[n] = a);
337
+ bind(e, t) {
338
+ const o = {}, i = (r, n) => {
339
+ const a = x(e, r);
340
+ if (a)
341
+ return o[n] = a, n;
328
342
  };
329
- return i(this.isLeft ? e.handL : e.handR, "wrist"), i(this.isLeft ? e.index1L : e.index1R, "index1"), i(this.isLeft ? e.index2L : e.index2R, "index2"), i(this.isLeft ? e.index3L : e.index3R, "index3"), i(this.isLeft ? e.middle1L : e.middle1R, "middle1"), i(this.isLeft ? e.middle2L : e.middle2R, "middle2"), i(this.isLeft ? e.middle3L : e.middle3R, "middle3"), i(this.isLeft ? e.ring1L : e.ring1R, "ring1"), i(this.isLeft ? e.ring2L : e.ring2R, "ring2"), i(this.isLeft ? e.ring3L : e.ring3R, "ring3"), i(this.isLeft ? e.pinky1L : e.pinky1R, "pinky1"), i(this.isLeft ? e.pinky2L : e.pinky2R, "pinky2"), i(this.isLeft ? e.pinky3L : e.pinky3R, "pinky3"), i(this.isLeft ? e.thumb1L : e.thumb1R, "thumb1"), i(this.isLeft ? e.thumb2L : e.thumb2R, "thumb2"), i(this.isLeft ? e.thumb3L : e.thumb3R, "thumb3"), {
343
+ return i(this.isLeft ? t.handL : t.handR, "wrist"), i(this.isLeft ? t.index1L : t.index1R, "index1"), i(this.isLeft ? t.index2L : t.index2R, "index2"), i(this.isLeft ? t.index3L : t.index3R, "index3"), i(this.isLeft ? t.middle1L : t.middle1R, "middle1"), i(this.isLeft ? t.middle2L : t.middle2R, "middle2"), i(this.isLeft ? t.middle3L : t.middle3R, "middle3"), i(this.isLeft ? t.ring1L : t.ring1R, "ring1"), i(this.isLeft ? t.ring2L : t.ring2R, "ring2"), i(this.isLeft ? t.ring3L : t.ring3R, "ring3"), i(this.isLeft ? t.pinky1L : t.pinky1R, "pinky1"), i(this.isLeft ? t.pinky2L : t.pinky2R, "pinky2"), i(this.isLeft ? t.pinky3L : t.pinky3R, "pinky3"), i(this.isLeft ? t.thumb1L : t.thumb1R, "thumb1"), i(this.isLeft ? t.thumb2L : t.thumb2R, "thumb2"), i(this.isLeft ? t.thumb3L : t.thumb3R, "thumb3"), {
330
344
  update: (r) => {
331
- this.syncHandBones(r, s, t);
345
+ this.syncHandBones(r, o, e);
332
346
  }
333
347
  };
334
348
  }
335
349
  }
336
- async function Nt(l, o) {
337
- const t = await C.createFromOptions(l, {
350
+ async function Te(h, s) {
351
+ const e = await C.createFromOptions(h, {
338
352
  baseOptions: {
339
- modelAssetPath: (o == null ? void 0 : o.modelPath) ?? "face_landmarker.task",
353
+ modelAssetPath: (s == null ? void 0 : s.modelPath) ?? "face_landmarker.task",
340
354
  delegate: "GPU"
341
355
  },
342
356
  outputFaceBlendshapes: !0,
343
357
  runningMode: "VIDEO",
344
358
  numFaces: 1
345
359
  });
346
- return new Dt(t);
360
+ return new Ie(e);
347
361
  }
348
- const Ot = {
362
+ const De = {
349
363
  eyeL: 473,
350
364
  eyeR: 468,
351
365
  eyeStartL: 463,
@@ -358,71 +372,71 @@ const Ot = {
358
372
  noseBone: 6,
359
373
  chin: 152,
360
374
  forehead: 10
361
- }, _t = new L(), St = new L(), ot = new L(), Ct = new L(), zt = new L();
362
- new L();
363
- class Dt extends z {
375
+ }, Ce = new P(), _e = new P(), ne = new P(), ze = new P(), Be = new P();
376
+ new P();
377
+ class Ie extends _ {
364
378
  // lower = smoother but more lag, higher = more responsive
365
- constructor(t) {
366
- super(Ot, C.FACE_LANDMARKS_TESSELATION);
367
- y(this, "blendshapeCategories");
368
- y(this, "blendshapeMap", /* @__PURE__ */ new Map());
369
- y(this, "smoothed", {});
370
- y(this, "smoothing", 3e-4);
371
- this.faceLandmarker = t, this.root.scale.y *= -1, this.root.scale.z *= -1, this.root.scale.multiplyScalar(3);
372
- }
373
- predict(t, e) {
379
+ constructor(e) {
380
+ super(De, C.FACE_LANDMARKS_TESSELATION);
381
+ k(this, "blendshapeCategories");
382
+ k(this, "blendshapeMap", /* @__PURE__ */ new Map());
383
+ k(this, "smoothed", {});
384
+ k(this, "smoothing", 3e-4);
385
+ this.faceLandmarker = e, this.root.scale.y *= -1, this.root.scale.z *= -1, this.root.scale.multiplyScalar(3);
386
+ }
387
+ predict(e, t) {
374
388
  var i, r, n;
375
- const s = this.faceLandmarker.detectForVideo(t, performance.now());
376
- s.faceLandmarks[0] && (e.drawConnectors(s.faceLandmarks[0], C.FACE_LANDMARKS_TESSELATION, { color: "#00fff2ff", lineWidth: 0.1 }), e.drawLandmarks(s.faceLandmarks[0], { color: "#00ff00", lineWidth: 0.1, radius: 0.4 }), this.updateLandmarks(s.faceLandmarks[0], s.faceLandmarks[0])), this.blendshapeCategories = (r = (i = s.faceBlendshapes) == null ? void 0 : i[0]) == null ? void 0 : r.categories, (n = this.blendshapeCategories) == null || n.forEach((a) => {
389
+ const o = this.faceLandmarker.detectForVideo(e, performance.now());
390
+ o.faceLandmarks[0] && (t.drawConnectors(o.faceLandmarks[0], C.FACE_LANDMARKS_TESSELATION, { color: "#00fff2ff", lineWidth: 0.1 }), t.drawLandmarks(o.faceLandmarks[0], { color: "#00ff00", lineWidth: 0.1, radius: 0.4 }), this.updateLandmarks(o.faceLandmarks[0], o.faceLandmarks[0])), this.blendshapeCategories = (r = (i = o.faceBlendshapes) == null ? void 0 : i[0]) == null ? void 0 : r.categories, (n = this.blendshapeCategories) == null || n.forEach((a) => {
377
391
  this.blendshapeMap.set(a.categoryName, a.score);
378
392
  });
379
393
  }
380
- bindShapeKeys(t) {
381
- const e = t.morphTargetDictionary;
394
+ bindShapeKeys(e) {
395
+ const t = e.morphTargetDictionary;
382
396
  return {
383
- update: (s) => {
397
+ update: (o) => {
384
398
  var i;
385
399
  (i = this.blendshapeCategories) == null || i.forEach((r) => {
386
400
  const { categoryName: n, score: a } = r;
387
- if (!(e != null && e.hasOwnProperty(n))) return;
401
+ if (!(t != null && t.hasOwnProperty(n))) return;
388
402
  this.smoothed[n] === void 0 && (this.smoothed[n] = a);
389
- const c = 1 - Math.pow(this.smoothing, s);
390
- this.smoothed[n] += (a - this.smoothed[n]) * c, t.morphTargetInfluences[e[n]] = this.smoothed[n];
403
+ const c = 1 - Math.pow(this.smoothing, o);
404
+ this.smoothed[n] += (a - this.smoothed[n]) * c, e.morphTargetInfluences[t[n]] = this.smoothed[n];
391
405
  });
392
406
  }
393
407
  };
394
408
  }
395
- bind(t) {
396
- const e = new J(t, "L"), s = new J(t, "R"), i = w(t, "head");
409
+ bind(e) {
410
+ const t = new oe(e, "L"), o = new oe(e, "R"), i = x(e, "head");
397
411
  return {
398
412
  update: (r) => {
399
- if (e.update(r, this.blendshapeMap), s.update(r, this.blendshapeMap), !i) return;
400
- const n = _t.copy(this.marks.earL.worldPosition), a = St.copy(this.marks.earR.worldPosition), c = ot.subVectors(n, a).multiplyScalar(0.5).add(a), m = Ct.subVectors(this.marks.noseTip.worldPosition, c), f = n.sub(a), k = E(zt, i, t), d = f.add(k).applyMatrix4(t.matrixWorld), p = m.add(k).applyMatrix4(t.matrixWorld);
401
- A(i, p, d, "+x");
413
+ if (t.update(r, this.blendshapeMap), o.update(r, this.blendshapeMap), !i) return;
414
+ const n = Ce.copy(this.marks.earL.worldPosition), a = _e.copy(this.marks.earR.worldPosition), c = ne.subVectors(n, a).multiplyScalar(0.5).add(a), p = ze.subVectors(this.marks.noseTip.worldPosition, c), f = n.sub(a), R = F(Be, i, e), d = f.add(R).applyMatrix4(e.matrixWorld), m = p.add(R).applyMatrix4(e.matrixWorld);
415
+ A(i, m, d, "+x");
402
416
  }
403
417
  };
404
418
  }
405
419
  }
406
- class J {
407
- constructor(o, t) {
408
- y(this, "eyeBone");
409
- y(this, "eyeLookOut");
410
- y(this, "eyeLookIn");
411
- y(this, "eyeLookUp");
412
- y(this, "eyeLookDown");
413
- y(this, "sign", 1);
414
- this.rig = o, this.side = t, this.eyeBone = o.getObjectByName(`eye${t}`);
415
- const e = t == "L" ? "Left" : "Right";
416
- this.eyeLookOut = `eyeLookOut${e}`, this.eyeLookIn = `eyeLookIn${e}`, this.eyeLookUp = `eyeLookUp${e}`, this.eyeLookDown = `eyeLookDown${e}`, this.sign = t == "L" ? -1 : 1;
417
- }
418
- update(o, t) {
420
+ class oe {
421
+ constructor(s, e) {
422
+ k(this, "eyeBone");
423
+ k(this, "eyeLookOut");
424
+ k(this, "eyeLookIn");
425
+ k(this, "eyeLookUp");
426
+ k(this, "eyeLookDown");
427
+ k(this, "sign", 1);
428
+ this.rig = s, this.side = e, this.eyeBone = s.getObjectByName(`eye${e}`);
429
+ const t = e == "L" ? "Left" : "Right";
430
+ this.eyeLookOut = `eyeLookOut${t}`, this.eyeLookIn = `eyeLookIn${t}`, this.eyeLookUp = `eyeLookUp${t}`, this.eyeLookDown = `eyeLookDown${t}`, this.sign = e == "L" ? -1 : 1;
431
+ }
432
+ update(s, e) {
419
433
  if (!this.eyeBone) return;
420
- E(ot, this.eyeBone, this.rig);
421
- const e = t.get(this.eyeLookOut) ?? 0, s = t.get(this.eyeLookIn) ?? 0, i = t.get(this.eyeLookUp) ?? 0, r = t.get(this.eyeLookDown) ?? 0, n = s - e, a = r - i;
422
- console.log("EYE: ", n, a), this.eyeBone.rotation.y = n * this.sign / 2, this.eyeBone.rotation.x = a / 2;
434
+ F(ne, this.eyeBone, this.rig);
435
+ const t = e.get(this.eyeLookOut) ?? 0, o = e.get(this.eyeLookIn) ?? 0, i = e.get(this.eyeLookUp) ?? 0, r = e.get(this.eyeLookDown) ?? 0, n = o - t, a = r - i;
436
+ this.eyeBone.rotation.y = n * this.sign / 2, this.eyeBone.rotation.x = a / 2;
423
437
  }
424
438
  }
425
- const Tt = {
439
+ const re = {
426
440
  faceMesh: "face",
427
441
  head: "head",
428
442
  hips: "hips",
@@ -470,12 +484,148 @@ const Tt = {
470
484
  thumb1R: "thumb1R",
471
485
  thumb2R: "thumb2R",
472
486
  thumb3R: "thumb3R"
473
- }, gt = () => {
474
- var l;
475
- return !!((l = navigator.mediaDevices) != null && l.getUserMedia);
487
+ }, Ue = [
488
+ "eyeBlinkLeft",
489
+ "eyeBlinkRight",
490
+ "eyeLookDownLeft",
491
+ "eyeLookDownRight",
492
+ "eyeLookInLeft",
493
+ "eyeLookInRight",
494
+ "eyeLookOutLeft",
495
+ "eyeLookOutRight",
496
+ "eyeLookUpLeft",
497
+ "eyeLookUpRight",
498
+ "eyeSquintLeft",
499
+ "eyeSquintRight",
500
+ "eyeWideLeft",
501
+ "eyeWideRight",
502
+ "browDownLeft",
503
+ "browDownRight",
504
+ "browInnerUp",
505
+ "browOuterUpLeft",
506
+ "browOuterUpRight",
507
+ "noseSneerLeft",
508
+ "noseSneerRight",
509
+ "cheekPuff",
510
+ "cheekSquintLeft",
511
+ "cheekSquintRight",
512
+ "jawForward",
513
+ "jawLeft",
514
+ "jawOpen",
515
+ "jawRight",
516
+ "mouthClose",
517
+ "mouthDimpleLeft",
518
+ "mouthDimpleRight",
519
+ "mouthFrownLeft",
520
+ "mouthFrownRight",
521
+ "mouthFunnel",
522
+ "mouthLeft",
523
+ "mouthLowerDownLeft",
524
+ "mouthLowerDownRight",
525
+ "mouthPressLeft",
526
+ "mouthPressRight",
527
+ "mouthPucker",
528
+ "mouthRight",
529
+ "mouthRollLower",
530
+ "mouthRollUpper",
531
+ "mouthShrugLower",
532
+ "mouthShrugUpper",
533
+ "mouthSmileLeft",
534
+ "mouthSmileRight",
535
+ "mouthStretchLeft",
536
+ "mouthStretchRight",
537
+ "mouthUpperUpLeft",
538
+ "mouthUpperUpRight",
539
+ "tongueOut"
540
+ ];
541
+ function Ge(h, s, e = 30) {
542
+ const t = [], o = h.getObjectByName(
543
+ s.faceMesh
544
+ ), i = /* @__PURE__ */ new Set();
545
+ if (o != null && o.morphTargetDictionary)
546
+ for (const L in o.morphTargetDictionary)
547
+ Ue.includes(L) && i.add(L);
548
+ const r = Object.keys(s);
549
+ h.traverse((L) => {
550
+ if (L instanceof S.Bone) {
551
+ const u = r.find((W) => L.name.indexOf(s[W]) === 0);
552
+ u && t.push({
553
+ ref: L,
554
+ name: L.name,
555
+ normalizedName: u
556
+ });
557
+ }
558
+ });
559
+ const n = [], a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
560
+ let p = !1, f = 0;
561
+ function R() {
562
+ a.clear(), c.clear(), n.length = 0, f = performance.now() / 1e3, p = !0;
563
+ }
564
+ function d() {
565
+ if (!p) return;
566
+ const L = performance.now() / 1e3 - f;
567
+ n.push(L);
568
+ for (const u of t) {
569
+ a.has(u.name) || a.set(u.name, []);
570
+ const W = a.get(u.name), b = u.ref.quaternion;
571
+ W.push(b.x, b.y, b.z, b.w);
572
+ }
573
+ for (const u of i) {
574
+ c.has(u) || c.set(u, []);
575
+ const W = c.get(u), b = o.morphTargetDictionary[u], E = o.morphTargetInfluences[b];
576
+ W.push(E);
577
+ }
578
+ }
579
+ function m(L = "RecordedClip") {
580
+ p = !1;
581
+ const u = [];
582
+ for (const [b, E] of a)
583
+ u.push(
584
+ new S.QuaternionKeyframeTrack(
585
+ `${b}.quaternion`,
586
+ n,
587
+ E
588
+ )
589
+ );
590
+ for (const [b, E] of c)
591
+ u.push(
592
+ new S.NumberKeyframeTrack(
593
+ `${re.faceMesh}.morphTargetInfluences[${b}]`,
594
+ n,
595
+ E
596
+ )
597
+ );
598
+ const W = new S.AnimationClip(L, -1, u);
599
+ return {
600
+ clip: W,
601
+ saveToFile: () => {
602
+ new ue().parse(
603
+ h,
604
+ (E) => {
605
+ const w = new Blob([E], {
606
+ type: "model/gltf-binary"
607
+ }), y = URL.createObjectURL(w), g = document.createElement("a");
608
+ g.href = y, g.download = L + ".glb", g.click();
609
+ },
610
+ (E) => {
611
+ console.error(E);
612
+ },
613
+ {
614
+ binary: !0,
615
+ animations: [W]
616
+ }
617
+ );
618
+ }
619
+ };
620
+ }
621
+ return { start: R, captureFrame: d, stop: m, isRecording: () => p };
622
+ }
623
+ const He = () => {
624
+ var h;
625
+ return !!((h = navigator.mediaDevices) != null && h.getUserMedia);
476
626
  };
477
- async function Ut(l) {
478
- const o = {
627
+ async function Qe(h) {
628
+ const s = {
479
629
  debugFrame: void 0,
480
630
  displayScale: 1,
481
631
  ignoreLegs: !1,
@@ -487,50 +637,50 @@ async function Ut(l) {
487
637
  hand: "https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task",
488
638
  face: "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task"
489
639
  },
490
- ...l
640
+ ...h
491
641
  };
492
- let t;
493
- const e = await at.forVisionTasks(o.modelPaths.vision ?? "/wasm"), s = await kt(e, {
494
- ignoreLegs: o.ignoreLegs,
495
- modelPath: o.modelPaths.pose
496
- }), i = await At(e, {
497
- leftWrist: () => s.leftWristNormalizedPosition,
498
- rightWrist: () => s.rightWristNormalizedPosition,
499
- modelPath: o.modelPaths.hand,
500
- ...l == null ? void 0 : l.handsTrackerOptions
501
- }), r = o.ignoreFace ? void 0 : await Nt(e, { modelPath: o.modelPaths.face }), n = document.createElement("div");
642
+ let e;
643
+ const t = await le.forVisionTasks(s.modelPaths.vision ?? "/wasm"), o = await We(t, {
644
+ ignoreLegs: s.ignoreLegs,
645
+ modelPath: s.modelPaths.pose
646
+ }), i = await Se(t, {
647
+ leftWrist: () => o.leftWristNormalizedPosition,
648
+ rightWrist: () => o.rightWristNormalizedPosition,
649
+ modelPath: s.modelPaths.hand,
650
+ ...h == null ? void 0 : h.handsTrackerOptions
651
+ }), r = s.ignoreFace ? void 0 : await Te(t, { modelPath: s.modelPaths.face }), n = document.createElement("div");
502
652
  n.style.position = "absolute", n.style.top = "0px", n.style.left = "0px", n.style.zIndex = "21", n.classList.add("three-mediapipe-rig"), document.body.appendChild(n);
503
- const a = document.createElement("canvas"), c = a.getContext("2d"), m = new dt(c);
653
+ const a = document.createElement("canvas"), c = a.getContext("2d"), p = new pe(c);
504
654
  a.style.zIndex = "22", a.style.position = "absolute", a.style.top = "0px", a.style.left = "0px", a.style.pointerEvents = "none", n.appendChild(a);
505
655
  function f(d) {
506
- c.save(), c.clearRect(0, 0, a.width, a.height), s == null || s.predict(d, m), i == null || i.left.predict(d, m), i == null || i.right.predict(d, m), r == null || r.predict(d, m), c.restore();
656
+ c.save(), c.clearRect(0, 0, a.width, a.height), o == null || o.predict(d, p), i == null || i.left.predict(d, p), i == null || i.right.predict(d, p), r == null || r.predict(d, p), c.restore();
507
657
  }
508
- function k() {
509
- t = document.createElement("video"), n.appendChild(t);
658
+ function R() {
659
+ e = document.createElement("video"), n.appendChild(e);
510
660
  let d = -1;
511
- t.style.zIndex = "21", t.style.position = "absolute", t.style.top = "0px", t.style.left = "0px", o.debugVideo && (t.src = o.debugVideo, t.controls = !0, t.loop = !0, t.muted = !0, t.controls = !0, t.play());
512
- function p() {
513
- d !== t.currentTime && (f(t), d = t.currentTime), window.requestAnimationFrame(p);
661
+ e.style.zIndex = "21", e.style.position = "absolute", e.style.top = "0px", e.style.left = "0px", s.debugVideo && (e.src = s.debugVideo, e.controls = !0, e.loop = !0, e.muted = !0, e.controls = !0, e.play());
662
+ function m() {
663
+ d !== e.currentTime && (f(e), d = e.currentTime), window.requestAnimationFrame(m);
514
664
  }
515
- t.addEventListener("loadeddata", () => {
516
- t.width = t.videoWidth * o.displayScale, t.height = t.videoHeight * o.displayScale, a.width = t.videoWidth, a.height = t.videoHeight, a.style.height = t.height + "px", a.style.width = t.width + "px", window.requestAnimationFrame(p);
665
+ e.addEventListener("loadeddata", () => {
666
+ e.width = e.videoWidth * s.displayScale, e.height = e.videoHeight * s.displayScale, a.width = e.videoWidth, a.height = e.videoHeight, a.style.height = e.height + "px", a.style.width = e.width + "px", window.requestAnimationFrame(m);
517
667
  });
518
668
  }
519
- if (o.debugFrame) {
669
+ if (s.debugFrame) {
520
670
  const d = document.createElement("img");
521
- d.src = o.debugFrame, d.style.zIndex = "21", d.style.position = "absolute", d.style.top = "0px", d.style.left = "0px", document.body.appendChild(d), d.addEventListener("load", () => {
522
- d.width = d.naturalWidth * o.displayScale, d.height = d.naturalHeight * o.displayScale, a.width = d.naturalWidth, a.height = d.naturalWidth, a.style.width = d.width + "px", a.style.height = d.height + "px";
523
- function p() {
671
+ d.src = s.debugFrame, d.style.zIndex = "21", d.style.position = "absolute", d.style.top = "0px", d.style.left = "0px", n.appendChild(d), d.addEventListener("load", () => {
672
+ d.width = d.naturalWidth * s.displayScale, d.height = d.naturalHeight * s.displayScale, a.width = d.naturalWidth, a.height = d.naturalWidth, a.style.width = d.width + "px", a.style.height = d.height + "px";
673
+ function m() {
524
674
  f(d);
525
675
  }
526
- window.requestAnimationFrame(p);
676
+ window.requestAnimationFrame(m);
527
677
  });
528
- } else o.debugVideo && k();
678
+ } else s.debugVideo && R();
529
679
  return {
530
- poseTracker: s,
680
+ poseTracker: o,
531
681
  handsTracker: i,
532
682
  faceTracker: r,
533
- video: t,
683
+ video: e,
534
684
  /**
535
685
  * A div that contains the video and canvas used to display the landmarks stacked on top of each other.
536
686
  */
@@ -540,54 +690,54 @@ async function Ut(l) {
540
690
  */
541
691
  start: async () => {
542
692
  let d = !1;
543
- if (!gt())
693
+ if (!He())
544
694
  throw new Error("Webcam not supported");
545
- t || k();
546
- let p;
547
- function P(u) {
548
- console.warn("Camera track ended, attempting recovery..."), x(u), R(u);
695
+ e || R();
696
+ let m;
697
+ function L(w) {
698
+ console.warn("Camera track ended, attempting recovery..."), u(w), W(w);
549
699
  }
550
- function x(u) {
551
- p == null || p.getTracks().forEach((b) => b.stop()), p = void 0, u.srcObject = null;
700
+ function u(w) {
701
+ m == null || m.getTracks().forEach((y) => y.stop()), m = void 0, w.srcObject = null;
552
702
  }
553
- async function R(u, b = 0) {
554
- const st = Math.min(1e3 * 2 ** b, 16e3);
555
- if (b >= 5)
703
+ async function W(w, y = 0) {
704
+ const ae = Math.min(1e3 * 2 ** y, 16e3);
705
+ if (y >= 5)
556
706
  throw new Error("Camera recovery failed after max attempts");
557
- if (await new Promise((it) => setTimeout(it, st)), !d)
707
+ if (await new Promise((de) => setTimeout(de, ae)), !d)
558
708
  try {
559
- await W(u), console.log("Camera recovered successfully");
709
+ await b(w), console.log("Camera recovered successfully");
560
710
  } catch {
561
- R(u, b + 1);
711
+ W(w, y + 1);
562
712
  }
563
713
  }
564
- async function W(u) {
714
+ async function b(w) {
565
715
  try {
566
- p = await navigator.mediaDevices.getUserMedia({ video: !0 }), u.srcObject = p, await u.play(), p.getVideoTracks().forEach((b) => {
567
- b.addEventListener("ended", () => P(u));
716
+ m = await navigator.mediaDevices.getUserMedia({ video: !0 }), w.srcObject = m, await w.play(), m.getVideoTracks().forEach((y) => {
717
+ y.addEventListener("ended", () => L(w));
568
718
  });
569
- } catch (b) {
570
- M(b, u);
719
+ } catch (y) {
720
+ E(y, w);
571
721
  }
572
722
  }
573
- function M(u, b) {
574
- if (u instanceof DOMException)
575
- switch (u.name) {
723
+ function E(w, y) {
724
+ if (w instanceof DOMException)
725
+ switch (w.name) {
576
726
  case "NotAllowedError":
577
727
  throw new Error("Permission denied — prompt user to allow camera");
578
728
  case "NotFoundError":
579
- console.error("No camera found — retry when device is connected"), R(b);
729
+ console.error("No camera found — retry when device is connected"), W(y);
580
730
  break;
581
731
  case "NotReadableError":
582
- console.error("Camera in use by another app"), R(b);
732
+ console.error("Camera in use by another app"), W(y);
583
733
  break;
584
734
  default:
585
- console.error("Camera error:", u.message), R(b);
735
+ console.error("Camera error:", w.message), W(y);
586
736
  }
587
737
  }
588
- return await W(t), {
738
+ return await b(e), {
589
739
  stop: () => {
590
- d = !0, x(t);
740
+ d = !0, u(e);
591
741
  }
592
742
  };
593
743
  },
@@ -596,22 +746,31 @@ async function Ut(l) {
596
746
  * @param rig The rig that contains all the bones and skinned meshes of your character.
597
747
  * @param magging The bone mapping to use for the rig.
598
748
  */
599
- bind: (d, p) => {
600
- p = p || Tt;
601
- const P = s.bind(d, p), x = i.left.bind(d, p), R = i.right.bind(d, p);
602
- let W;
603
- const M = r == null ? void 0 : r.bind(d);
604
- return d.traverse((u) => {
605
- u instanceof h.Mesh && u.name.indexOf(p.faceMesh) === 0 && (u.frustumCulled = !1, W = r == null ? void 0 : r.bindShapeKeys(u));
606
- }), {
607
- update: (u) => {
608
- P.update(u), x.update(u), R.update(u), W == null || W.update(u), M == null || M.update(u);
749
+ bind: (d, m) => {
750
+ m = m || re;
751
+ const L = o.bind(d, m), u = i.left.bind(d, m), W = i.right.bind(d, m);
752
+ let b;
753
+ const E = r == null ? void 0 : r.bind(d);
754
+ d.traverse((y) => {
755
+ y instanceof l.Mesh && y.name.indexOf(m.faceMesh) === 0 && (y.frustumCulled = !1, b = r == null ? void 0 : r.bindShapeKeys(y));
756
+ });
757
+ const w = Ge(d, m);
758
+ return {
759
+ /**
760
+ * Will save the tracked movement of the rig to an animation clip.
761
+ * Only the bones moved by the bone mapping will be recorded.
762
+ */
763
+ startRecording: w.start,
764
+ stopRecording: w.stop,
765
+ isRecording: () => w.isRecording(),
766
+ update: (y) => {
767
+ L.update(y), u.update(y), W.update(y), b == null || b.update(y), E == null || E.update(y), w.isRecording() && w.captureFrame();
609
768
  }
610
769
  };
611
770
  }
612
771
  };
613
772
  }
614
773
  export {
615
- Ut as setupTracker
774
+ Qe as setupTracker
616
775
  };
617
776
  //# sourceMappingURL=three-mediapipe-rig.js.map