three-mediapipe-rig 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rigger.js CHANGED
@@ -1,27 +1,27 @@
1
1
  var Pe = Object.defineProperty;
2
- var Ee = (l, o, e) => o in l ? Pe(l, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[o] = e;
3
- var R = (l, o, e) => Ee(l, typeof o != "symbol" ? o + "" : o, e);
4
- import { PoseLandmarker as we, HandLandmarker as I, FaceLandmarker as G, FilesetResolver as ge, DrawingUtils as We } from "@mediapipe/tasks-vision";
5
- import * as u from "three/webgpu";
6
- import { Vector3 as b, Quaternion as ye, VideoTexture as Q, SRGBColorSpace as Y, MeshPhysicalNodeMaterial as Fe } from "three/webgpu";
7
- import * as _ from "three";
2
+ var Ee = (h, o, e) => o in h ? Pe(h, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[o] = e;
3
+ var R = (h, o, e) => Ee(h, typeof o != "symbol" ? o + "" : o, e);
4
+ import { PoseLandmarker as Le, HandLandmarker as G, FaceLandmarker as j, FilesetResolver as We, DrawingUtils as ge } from "@mediapipe/tasks-vision";
5
+ import * as p from "three/webgpu";
6
+ import { Vector3 as b, Quaternion as ke, VideoTexture as Z, SRGBColorSpace as J, MeshPhysicalNodeMaterial as Fe } from "three/webgpu";
7
+ import * as C from "three";
8
8
  import { Bone as Ae } from "three";
9
- import { uniform as C, attribute as Se, instancedArray as Me, varying as Ve, vec3 as Ne, float as Oe, texture as Te, vec2 as _e } from "three/tsl";
9
+ import { uniform as D, attribute as Se, instancedArray as Me, varying as Ve, vec3 as Ne, float as Oe, texture as Te, vec2 as _e } from "three/tsl";
10
10
  import { c as Ce, F as De } from "./face-tracker-utils-xt9__vBF.js";
11
11
  import { GLTFExporter as ze } from "three/examples/jsm/Addons.js";
12
- const z = new b(), Z = new b(), Be = new b(1, 0, 0), Ue = new b(-1, 0, 0), Ie = new b(0, 1, 0), Ge = new b(0, -1, 0), J = new b(0, 0, 1);
12
+ const U = new b(), ee = new b(), Be = new b(1, 0, 0), Ue = new b(-1, 0, 0), Ie = new b(0, 1, 0), He = new b(0, -1, 0), te = new b(0, 0, 1);
13
13
  new b(0, 0, -1);
14
- const ee = new b(), He = new b(), qe = new b(), te = new ye(), B = new ye();
15
- function F(l, o, e, t = "+x") {
16
- l.lookAt(o);
17
- const n = t == "+x" ? Be : t == "-x" ? Ue : t == "+y" ? Ie : Ge;
18
- l.getWorldPosition(Z), l.getWorldQuaternion(B), z.subVectors(e, Z).normalize(), ee.copy(n).applyQuaternion(B);
19
- const s = ee, a = He.copy(J).applyQuaternion(B), i = z.clone().addScaledVector(a, -z.dot(a)).normalize(), r = qe.crossVectors(s, i), m = Math.atan2(r.dot(a), s.dot(i));
20
- te.setFromAxisAngle(J, m), l.quaternion.multiply(te);
14
+ const oe = new b(), Ge = new b(), je = new b(), se = new ke(), I = new ke();
15
+ function S(h, o, e, t = "+x") {
16
+ h.lookAt(o);
17
+ const s = t == "+x" ? Be : t == "-x" ? Ue : t == "+y" ? Ie : He;
18
+ h.getWorldPosition(ee), h.getWorldQuaternion(I), U.subVectors(e, ee).normalize(), oe.copy(s).applyQuaternion(I);
19
+ const n = oe, d = Ge.copy(te).applyQuaternion(I), i = U.clone().addScaledVector(d, -U.dot(d)).normalize(), r = je.crossVectors(n, i), m = Math.atan2(r.dot(d), n.dot(i));
20
+ se.setFromAxisAngle(te, m), h.quaternion.multiply(se);
21
21
  }
22
- const D = new u.Vector3(), N = new u.Vector3(), U = new u.Vector3();
23
- new u.Vector3();
24
- class H {
22
+ const z = new p.Vector3(), O = new p.Vector3(), H = new p.Vector3();
23
+ new p.Vector3();
24
+ class q {
25
25
  constructor(o, e) {
26
26
  R(this, "objectGhost");
27
27
  R(this, "root");
@@ -29,17 +29,17 @@ class H {
29
29
  * per landmark index, it points to it's object3D equivalent.
30
30
  */
31
31
  R(this, "marks", {});
32
- this.points = o, this.debugConnections = e, this.root = new u.Object3D(), this.objectGhost = /* @__PURE__ */ new Map();
32
+ this.points = o, this.debugConnections = e, this.root = new p.Object3D(), this.objectGhost = /* @__PURE__ */ new Map();
33
33
  for (let t in this.points)
34
- this.marks[t] = new $e(), this.root.add(this.marks[t]);
34
+ this.marks[t] = new qe(), this.root.add(this.marks[t]);
35
35
  }
36
36
  updateLandmarks(o, e, t) {
37
- for (let n in this.points) {
38
- const s = this.points[n], a = this.marks[n];
39
- a && (s instanceof Array ? (D.copy(o[s[0]]), a.position.copy(o[s[1]]).sub(D).divideScalar(2).add(o[s[0]]), s.length == 4 && (D.subVectors(
40
- o[s[3]],
41
- o[s[2]]
42
- ).divideScalar(2).add(o[s[2]]).sub(a.position).divideScalar(2), a.position.add(D))) : a.position.copy(o[s]));
37
+ for (let s in this.points) {
38
+ const n = this.points[s], d = this.marks[s];
39
+ d && (n instanceof Array ? (z.copy(o[n[0]]), d.position.copy(o[n[1]]).sub(z).divideScalar(2).add(o[n[0]]), n.length == 4 && (z.subVectors(
40
+ o[n[3]],
41
+ o[n[2]]
42
+ ).divideScalar(2).add(o[n[2]]).sub(d.position).divideScalar(2), d.position.add(z))) : d.position.copy(o[n]));
43
43
  }
44
44
  t && e && t.drawConnectors(
45
45
  e,
@@ -52,7 +52,7 @@ class H {
52
52
  getGhost(o) {
53
53
  var e;
54
54
  if (!this.objectGhost.has(o)) {
55
- const t = new je();
55
+ const t = new $e();
56
56
  t.position.copy(o.position), t.quaternion.copy(o.quaternion), (e = o.parent) == null || e.add(t), this.objectGhost.set(o, t);
57
57
  }
58
58
  return this.objectGhost.get(o);
@@ -67,47 +67,47 @@ class H {
67
67
  this.marks[o].position.set(1, 2, 3);
68
68
  }
69
69
  syncObjects(o, e, t) {
70
- for (const [n, s, a, i] of o) {
71
- this.marks[a].getWorldPosition(U), this.marks[s].getWorldPosition(N);
72
- const r = U.sub(N);
73
- n.getWorldPosition(N), N.add(r);
74
- const m = N, c = n.getWorldPosition(U).sub(t), f = this.getGhost(n);
75
- F(f, m, c, i), f.rotateX(Math.PI / 2), n.position.lerp(f.position, e * 4), n.quaternion.slerp(f.quaternion, e * 4);
70
+ for (const [s, n, d, i] of o) {
71
+ this.marks[d].getWorldPosition(H), this.marks[n].getWorldPosition(O);
72
+ const r = H.sub(O);
73
+ s.getWorldPosition(O), O.add(r);
74
+ const m = O, l = s.getWorldPosition(H).sub(t), u = this.getGhost(s);
75
+ S(u, m, l, i), u.rotateX(Math.PI / 2), s.position.lerp(u.position, e * 4), s.quaternion.slerp(u.quaternion, e * 4);
76
76
  }
77
77
  }
78
78
  getBone(o, e) {
79
79
  return o.getObjectByName(e.replace(/[\.\:]/g, ""));
80
80
  }
81
81
  }
82
- class $e extends u.Mesh {
82
+ class qe extends p.Mesh {
83
83
  constructor() {
84
- super(new u.SphereGeometry(0.01, 3, 3), new u.MeshStandardMaterial({ color: 16711680, wireframe: !0 }));
85
- R(this, "_worldPosition", new u.Vector3());
86
- this.add(new u.AxesHelper(1e-3));
84
+ super(new p.SphereGeometry(0.01, 3, 3), new p.MeshStandardMaterial({ color: 16711680, wireframe: !0 }));
85
+ R(this, "_worldPosition", new p.Vector3());
86
+ this.add(new p.AxesHelper(1e-3));
87
87
  }
88
88
  get worldPosition() {
89
89
  return this.getWorldPosition(this._worldPosition), this._worldPosition;
90
90
  }
91
91
  }
92
- class je extends u.Object3D {
92
+ class $e extends p.Object3D {
93
93
  lerp(o, e, t = 8) {
94
94
  o.position.lerp(this.position, e * t), o.quaternion.slerp(this.quaternion, e * t);
95
95
  }
96
96
  }
97
- function W(l, o, e) {
98
- return e.worldToLocal(o.getWorldPosition(l)), l;
97
+ function A(h, o, e) {
98
+ return e.worldToLocal(o.getWorldPosition(h)), h;
99
99
  }
100
- function Ke(l) {
101
- return l.replace(/[\.\:]/g, "");
100
+ function Ke(h) {
101
+ return h.replace(/[\.\:]/g, "");
102
102
  }
103
- function P(l, o) {
103
+ function P(h, o) {
104
104
  let e;
105
- return o = Ke(o), l.traverse((t) => {
105
+ return o = Ke(o), h.traverse((t) => {
106
106
  t.name.indexOf(o) === 0 && t instanceof Ae && (e = t);
107
- }), e || console.log("Bone not found: ", o, l.name), e;
107
+ }), e || console.log("Bone not found: ", o, h.name), e;
108
108
  }
109
- async function Xe(l, o) {
110
- const e = await we.createFromOptions(l, {
109
+ async function Xe(h, o) {
110
+ const e = await Le.createFromOptions(h, {
111
111
  baseOptions: {
112
112
  modelAssetPath: (o == null ? void 0 : o.modelPath) ?? "pose_landmarker_lite.task",
113
113
  //modelAssetPath: `https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task`,
@@ -141,10 +141,10 @@ const Qe = {
141
141
  torso: [24, 23, 12, 11],
142
142
  leftEar: 7,
143
143
  rightEar: 8
144
- }, Ye = new u.Vector3(), oe = new u.Vector3(), Ze = new u.Vector3(), Je = new u.Vector3(), et = new u.Vector3(), ne = new u.Vector3(), se = new u.Vector3();
145
- class tt extends H {
144
+ }, Ye = new p.Vector3(), ne = new p.Vector3(), Ze = new p.Vector3(), Je = new p.Vector3(), et = new p.Vector3(), ie = new p.Vector3(), re = new p.Vector3();
145
+ class tt extends q {
146
146
  constructor(e, t) {
147
- super(Qe, we.POSE_CONNECTIONS);
147
+ super(Qe, Le.POSE_CONNECTIONS);
148
148
  R(this, "_leftWristNormalizedPosition");
149
149
  R(this, "_rightWristNormalizedPosition");
150
150
  this.poseLandmarker = e, this.config = t, this.root.scale.y *= -2, this.root.scale.z *= -2, this.root.scale.x *= 2;
@@ -162,9 +162,9 @@ class tt extends H {
162
162
  return this._rightWristNormalizedPosition;
163
163
  }
164
164
  predict(e, t) {
165
- this.poseLandmarker.detectForVideo(e, performance.now(), (n) => {
166
- var s;
167
- n.landmarks.length != 0 && (this.updateLandmarks(n.worldLandmarks[0], ((s = this.config) == null ? void 0 : s.drawLandmarks) === !1 ? void 0 : n.landmarks[0], t), this._leftWristNormalizedPosition = n.landmarks[0][this.points.leftWrist], this._rightWristNormalizedPosition = n.landmarks[0][this.points.rightWrist]);
165
+ this.poseLandmarker.detectForVideo(e, performance.now(), (s) => {
166
+ var n;
167
+ s.landmarks.length != 0 && (this.updateLandmarks(s.worldLandmarks[0], ((n = this.config) == null ? void 0 : n.drawLandmarks) === !1 ? void 0 : s.landmarks[0], t), this._leftWristNormalizedPosition = s.landmarks[0][this.points.leftWrist], this._rightWristNormalizedPosition = s.landmarks[0][this.points.rightWrist]);
168
168
  });
169
169
  }
170
170
  // override sync ( delta:number, objects: BoneBinding[] ) {
@@ -176,7 +176,7 @@ class tt extends H {
176
176
  // }
177
177
  bind(e, t) {
178
178
  var r;
179
- const n = {
179
+ const s = {
180
180
  hips: P(e, t.hips),
181
181
  neck: P(e, t.neck),
182
182
  leftArm: P(e, t.armL),
@@ -194,25 +194,25 @@ class tt extends H {
194
194
  rightKnee: P(e, t.shinR),
195
195
  rightFoot: P(e, t.footR)
196
196
  };
197
- (r = this.config) != null && r.ignoreLegs && (delete n.leftLeg, delete n.leftKnee, delete n.leftFoot, delete n.leftToes, delete n.rightLeg, delete n.rightKnee, delete n.rightFoot, delete n.rightToes);
198
- const s = new u.Vector3(), a = new u.Vector3(), i = (m, c, f, k, x, d) => {
199
- if (!c) return;
200
- const h = this.marks[k].getWorldPosition(s).sub(this.marks[f].getWorldPosition(a)).normalize();
201
- W(ne, c, e).add(h).applyMatrix4(e.matrixWorld), W(se, c, e).add(x).applyMatrix4(e.matrixWorld);
202
- const w = this.getGhost(c);
203
- F(w, ne, se, d), w.rotateX(Math.PI / 2), w.lerp(c, m);
197
+ (r = this.config) != null && r.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);
198
+ const n = new p.Vector3(), d = new p.Vector3(), i = (m, l, u, y, x, W) => {
199
+ if (!l) return;
200
+ const a = this.marks[y].getWorldPosition(n).sub(this.marks[u].getWorldPosition(d)).normalize();
201
+ A(ie, l, e).add(a).applyMatrix4(e.matrixWorld), A(re, l, e).add(x).applyMatrix4(e.matrixWorld);
202
+ const c = this.getGhost(l);
203
+ S(c, ie, re, W), c.rotateX(Math.PI / 2), c.lerp(l, m);
204
204
  };
205
205
  return {
206
206
  update: (m) => {
207
- const c = this.marks.leftLeg.getWorldPosition(Ye).sub(this.marks.rightLeg.getWorldPosition(oe)).normalize(), f = this.marks.leftArm.getWorldPosition(oe).sub(this.marks.rightArm.getWorldPosition(Ze)).normalize(), k = this.marks.leftEar.getWorldPosition(Je).sub(this.marks.rightEar.getWorldPosition(et)).normalize();
208
- i(m, n.hips, "hips", "torso", c, "+x"), i(m, n.torso, "torso", "neck", f, "+x"), i(m, n.neck, "neck", "head", k, "+x"), i(m, n.head, "neck", "head", k, "+x"), i(m, n.leftArm, "leftArm", "leftElbow", f, "-x"), i(m, n.leftElbow, "leftElbow", "leftWrist", f, "-x"), i(m, n.leftLeg, "leftLeg", "leftKnee", c, "+x"), i(m, n.leftKnee, "leftKnee", "leftFoot", c, "+x"), i(m, n.leftFoot, "leftFoot", "leftToes", c, "+x"), i(m, n.rightArm, "rightArm", "rightElbow", f, "-x"), i(m, n.rightElbow, "rightElbow", "rightWrist", f, "-x"), i(m, n.rightLeg, "rightLeg", "rightKnee", c, "+x"), i(m, n.rightKnee, "rightKnee", "rightFoot", c, "+x"), i(m, n.rightFoot, "rightFoot", "rightToes", c, "+x");
207
+ const l = this.marks.leftLeg.getWorldPosition(Ye).sub(this.marks.rightLeg.getWorldPosition(ne)).normalize(), u = this.marks.leftArm.getWorldPosition(ne).sub(this.marks.rightArm.getWorldPosition(Ze)).normalize(), y = this.marks.leftEar.getWorldPosition(Je).sub(this.marks.rightEar.getWorldPosition(et)).normalize();
208
+ i(m, s.hips, "hips", "torso", l, "+x"), i(m, s.torso, "torso", "neck", u, "+x"), i(m, s.neck, "neck", "head", y, "+x"), i(m, s.head, "neck", "head", y, "+x"), i(m, s.leftArm, "leftArm", "leftElbow", u, "-x"), i(m, s.leftElbow, "leftElbow", "leftWrist", u, "-x"), i(m, s.leftLeg, "leftLeg", "leftKnee", l, "+x"), i(m, s.leftKnee, "leftKnee", "leftFoot", l, "+x"), i(m, s.leftFoot, "leftFoot", "leftToes", l, "+x"), i(m, s.rightArm, "rightArm", "rightElbow", u, "-x"), i(m, s.rightElbow, "rightElbow", "rightWrist", u, "-x"), i(m, s.rightLeg, "rightLeg", "rightKnee", l, "+x"), i(m, s.rightKnee, "rightKnee", "rightFoot", l, "+x"), i(m, s.rightFoot, "rightFoot", "rightToes", l, "+x");
209
209
  }
210
210
  };
211
211
  }
212
212
  }
213
- const ie = new u.Vector2(), re = new u.Vector2();
214
- async function ot(l, o) {
215
- const e = await I.createFromOptions(l, {
213
+ const ae = new p.Vector2(), de = new p.Vector2();
214
+ async function ot(h, o) {
215
+ const e = await G.createFromOptions(h, {
216
216
  baseOptions: {
217
217
  modelAssetPath: o.modelPath ?? "hand_landmarker.task",
218
218
  //modelAssetPath: `https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,
@@ -220,20 +220,20 @@ async function ot(l, o) {
220
220
  },
221
221
  runningMode: "VIDEO",
222
222
  numHands: 2
223
- }), t = (n, s, a) => {
223
+ }), t = (s, n, d) => {
224
224
  try {
225
- ie.copy(n()), re.copy(s());
225
+ ae.copy(s()), de.copy(n());
226
226
  } catch (i) {
227
227
  return console.warn("No pose data... will just be optimitic and say yes to everything.", i), !0;
228
228
  }
229
- return ie.distanceTo(a) < re.distanceTo(a);
229
+ return ae.distanceTo(d) < de.distanceTo(d);
230
230
  };
231
231
  return {
232
- left: new ue(e, "Left", t.bind(null, o.leftWrist, o.rightWrist), o.drawLandmarks),
233
- right: new ue(e, "Right", t.bind(null, o.rightWrist, o.leftWrist), o.drawLandmarks)
232
+ left: new we(e, "Left", t.bind(null, o.leftWrist, o.rightWrist), o.drawLandmarks),
233
+ right: new we(e, "Right", t.bind(null, o.rightWrist, o.leftWrist), o.drawLandmarks)
234
234
  };
235
235
  }
236
- const nt = {
236
+ const st = {
237
237
  wrist: 0,
238
238
  palm: [9, 13],
239
239
  thumb1: 1,
@@ -256,38 +256,38 @@ const nt = {
256
256
  pinky2: 18,
257
257
  pinky3: 19,
258
258
  pinky4: 20
259
- }, O = {
259
+ }, T = {
260
260
  thumb: ["thumb1", "thumb2", "thumb3", "thumb4"],
261
261
  index: ["index1", "index2", "index3", "index4"],
262
262
  middle: ["middle1", "middle2", "middle3", "middle4"],
263
263
  ring: ["ring1", "ring2", "ring3", "ring4"],
264
264
  pinky: ["pinky1", "pinky2", "pinky3", "pinky4"]
265
- }, st = new u.Vector3(), ae = new u.Vector3(), de = new u.Vector3(), ce = new u.Vector3(), le = new u.Vector3(), he = new u.Vector3();
266
- new u.Vector3();
267
- new u.Vector3();
268
- new u.Vector3();
269
- const me = new u.Vector3(), pe = Math.PI / 2, it = new u.Vector3(0, -1, 0);
270
- class ue extends H {
271
- constructor(e, t, n, s = !0) {
272
- super(nt, I.HAND_CONNECTIONS);
265
+ }, nt = new p.Vector3(), ce = new p.Vector3(), le = new p.Vector3(), he = new p.Vector3(), me = new p.Vector3(), pe = new p.Vector3();
266
+ new p.Vector3();
267
+ new p.Vector3();
268
+ new p.Vector3();
269
+ const ue = new p.Vector3(), fe = Math.PI / 2, it = new p.Vector3(0, -1, 0);
270
+ class we extends q {
271
+ constructor(e, t, s, n = !0) {
272
+ super(st, G.HAND_CONNECTIONS);
273
273
  R(this, "sign");
274
274
  R(this, "isLeft");
275
275
  /**
276
276
  * the axis used to look at the pole
277
277
  */
278
278
  R(this, "lookAtPoleAxis");
279
- this.handLandmarker = e, this.side = t, this.isMyWrist = n, this.drawLandmarks = s, 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;
279
+ this.handLandmarker = e, this.side = t, this.isMyWrist = s, this.drawLandmarks = n, 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;
280
280
  }
281
281
  predict(e, t) {
282
- const n = this.handLandmarker.detectForVideo(e, performance.now());
283
- if (n.landmarks.length)
284
- for (let s = 0; s < n.landmarks.length; s++) {
285
- const a = n.landmarks[s], i = a[this.points.wrist];
282
+ const s = this.handLandmarker.detectForVideo(e, performance.now());
283
+ if (s.landmarks.length)
284
+ for (let n = 0; n < s.landmarks.length; n++) {
285
+ const d = s.landmarks[n], i = d[this.points.wrist];
286
286
  if (this.isMyWrist(i)) {
287
- this.updateLandmarks(n.worldLandmarks[s]), this.drawLandmarks && (t.drawConnectors(a, I.HAND_CONNECTIONS, {
287
+ this.updateLandmarks(s.worldLandmarks[n]), this.drawLandmarks && (t.drawConnectors(d, G.HAND_CONNECTIONS, {
288
288
  color: this.side == "Left" ? "#00FF00" : "#0000FF",
289
289
  lineWidth: 4
290
- }), t.drawLandmarks(a, { color: this.side == "Left" ? "#00FF00" : "#0000FF", lineWidth: 3, radius: 1 }));
290
+ }), t.drawLandmarks(d, { color: this.side == "Left" ? "#00FF00" : "#0000FF", lineWidth: 3, radius: 1 }));
291
291
  break;
292
292
  }
293
293
  }
@@ -301,57 +301,57 @@ class ue extends H {
301
301
  * @param landmark2bones Array the same size as the umber of hand landmarks, and on each positionthe bone that belongs to that point.
302
302
  * @see https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker
303
303
  */
304
- syncHandBones(e, t, n) {
305
- const s = st.crossVectors(
306
- ae.copy(this.marks.index1.worldPosition).sub(this.marks.wrist.worldPosition),
307
- de.copy(this.marks.pinky1.worldPosition).sub(this.marks.wrist.worldPosition)
308
- ).normalize(), a = ae.copy(this.marks.palm.worldPosition).sub(this.marks.wrist.worldPosition).normalize(), i = de.copy(this.marks.pinky1.worldPosition).sub(this.marks.index1.worldPosition).normalize();
309
- if (!(a.dot(it) > 0.8)) {
304
+ syncHandBones(e, t, s) {
305
+ const n = nt.crossVectors(
306
+ ce.copy(this.marks.index1.worldPosition).sub(this.marks.wrist.worldPosition),
307
+ le.copy(this.marks.pinky1.worldPosition).sub(this.marks.wrist.worldPosition)
308
+ ).normalize(), d = ce.copy(this.marks.palm.worldPosition).sub(this.marks.wrist.worldPosition).normalize(), i = le.copy(this.marks.pinky1.worldPosition).sub(this.marks.index1.worldPosition).normalize();
309
+ if (!(d.dot(it) > 0.8)) {
310
310
  if (t.wrist) {
311
- const r = W(ce, t.wrist, n).add(a).applyMatrix4(n.matrixWorld), m = W(le, t.wrist, n).sub(i).applyMatrix4(n.matrixWorld), c = this.getGhost(t.wrist);
312
- F(c, r, m, "-y"), c.rotateX(pe), c.lerp(t.wrist, e);
311
+ const r = A(he, t.wrist, s).add(d).applyMatrix4(s.matrixWorld), m = A(me, t.wrist, s).sub(i).applyMatrix4(s.matrixWorld), l = this.getGhost(t.wrist);
312
+ S(l, r, m, "-y"), l.rotateX(fe), l.lerp(t.wrist, e);
313
313
  }
314
- this.syncFinger(e, n, s, a, i, t, O.index, "middle1"), this.syncFinger(e, n, s, a, i, t, O.middle, "ring1"), this.syncFinger(e, n, s, a, i, t, O.ring, "pinky1"), this.syncFinger(e, n, s, a, i, t, O.pinky, "ring1", !0), this.syncFinger(e, n, s, a, i, t, O.thumb, "index1");
314
+ this.syncFinger(e, s, n, d, i, t, T.index, "middle1"), this.syncFinger(e, s, n, d, i, t, T.middle, "ring1"), this.syncFinger(e, s, n, d, i, t, T.ring, "pinky1"), this.syncFinger(e, s, n, d, i, t, T.pinky, "ring1", !0), this.syncFinger(e, s, n, d, i, t, T.thumb, "index1");
315
315
  }
316
316
  }
317
- syncFinger(e, t, n, s, a, i, r, m, c = !1) {
318
- for (let f = 0; f < r.length - 1; f++) {
319
- const k = i[r[f]];
320
- if (!k) continue;
321
- const x = this.getGhost(k), d = ce.copy(this.marks[r[f + 1]].worldPosition).sub(this.marks[r[f]].worldPosition).normalize(), h = W(le, k, t);
322
- if (f == 0) {
323
- const w = he.copy(this.marks[m].worldPosition).sub(this.marks[r[0]].worldPosition).normalize();
324
- c && w.negate(), me.copy(w), F(
317
+ syncFinger(e, t, s, n, d, i, r, m, l = !1) {
318
+ for (let u = 0; u < r.length - 1; u++) {
319
+ const y = i[r[u]];
320
+ if (!y) continue;
321
+ const x = this.getGhost(y), W = he.copy(this.marks[r[u + 1]].worldPosition).sub(this.marks[r[u]].worldPosition).normalize(), a = A(me, y, t);
322
+ if (u == 0) {
323
+ const c = pe.copy(this.marks[m].worldPosition).sub(this.marks[r[0]].worldPosition).normalize();
324
+ l && c.negate(), ue.copy(c), S(
325
325
  x,
326
- d.add(h).applyMatrix4(t.matrixWorld),
327
- w.add(h).applyMatrix4(t.matrixWorld),
326
+ W.add(a).applyMatrix4(t.matrixWorld),
327
+ c.add(a).applyMatrix4(t.matrixWorld),
328
328
  this.lookAtPoleAxis
329
329
  );
330
330
  } else
331
- F(
331
+ S(
332
332
  x,
333
- d.add(h).applyMatrix4(t.matrixWorld),
334
- he.copy(me).add(h).applyMatrix4(t.matrixWorld),
333
+ W.add(a).applyMatrix4(t.matrixWorld),
334
+ pe.copy(ue).add(a).applyMatrix4(t.matrixWorld),
335
335
  this.lookAtPoleAxis
336
336
  );
337
- x.rotateX(pe), x.lerp(k, e);
337
+ x.rotateX(fe), x.lerp(y, e);
338
338
  }
339
339
  }
340
340
  bind(e, t) {
341
- const n = {}, s = (a, i) => {
342
- const r = P(e, a);
341
+ const s = {}, n = (d, i) => {
342
+ const r = P(e, d);
343
343
  if (r)
344
- return n[i] = r, i;
344
+ return s[i] = r, i;
345
345
  };
346
- return s(this.isLeft ? t.handL : t.handR, "wrist"), s(this.isLeft ? t.index1L : t.index1R, "index1"), s(this.isLeft ? t.index2L : t.index2R, "index2"), s(this.isLeft ? t.index3L : t.index3R, "index3"), s(this.isLeft ? t.middle1L : t.middle1R, "middle1"), s(this.isLeft ? t.middle2L : t.middle2R, "middle2"), s(this.isLeft ? t.middle3L : t.middle3R, "middle3"), s(this.isLeft ? t.ring1L : t.ring1R, "ring1"), s(this.isLeft ? t.ring2L : t.ring2R, "ring2"), s(this.isLeft ? t.ring3L : t.ring3R, "ring3"), s(this.isLeft ? t.pinky1L : t.pinky1R, "pinky1"), s(this.isLeft ? t.pinky2L : t.pinky2R, "pinky2"), s(this.isLeft ? t.pinky3L : t.pinky3R, "pinky3"), s(this.isLeft ? t.thumb1L : t.thumb1R, "thumb1"), s(this.isLeft ? t.thumb2L : t.thumb2R, "thumb2"), s(this.isLeft ? t.thumb3L : t.thumb3R, "thumb3"), {
347
- update: (a) => {
348
- this.syncHandBones(a, n, e);
346
+ return n(this.isLeft ? t.handL : t.handR, "wrist"), n(this.isLeft ? t.index1L : t.index1R, "index1"), n(this.isLeft ? t.index2L : t.index2R, "index2"), n(this.isLeft ? t.index3L : t.index3R, "index3"), n(this.isLeft ? t.middle1L : t.middle1R, "middle1"), n(this.isLeft ? t.middle2L : t.middle2R, "middle2"), n(this.isLeft ? t.middle3L : t.middle3R, "middle3"), n(this.isLeft ? t.ring1L : t.ring1R, "ring1"), n(this.isLeft ? t.ring2L : t.ring2R, "ring2"), n(this.isLeft ? t.ring3L : t.ring3R, "ring3"), n(this.isLeft ? t.pinky1L : t.pinky1R, "pinky1"), n(this.isLeft ? t.pinky2L : t.pinky2R, "pinky2"), n(this.isLeft ? t.pinky3L : t.pinky3R, "pinky3"), n(this.isLeft ? t.thumb1L : t.thumb1R, "thumb1"), n(this.isLeft ? t.thumb2L : t.thumb2R, "thumb2"), n(this.isLeft ? t.thumb3L : t.thumb3R, "thumb3"), {
347
+ update: (d) => {
348
+ this.syncHandBones(d, s, e);
349
349
  }
350
350
  };
351
351
  }
352
352
  }
353
- async function rt(l, o) {
354
- const e = await G.createFromOptions(l, {
353
+ async function rt(h, o) {
354
+ const e = await j.createFromOptions(h, {
355
355
  baseOptions: {
356
356
  modelAssetPath: (o == null ? void 0 : o.modelPath) ?? "face_landmarker.task",
357
357
  delegate: "GPU"
@@ -375,11 +375,11 @@ const at = {
375
375
  noseBone: 6,
376
376
  chin: 152,
377
377
  forehead: 10
378
- }, dt = new b(), ct = new b(), Le = new b(), lt = new b(), ht = new b();
378
+ }, dt = new b(), ct = new b(), be = new b(), lt = new b(), ht = new b();
379
379
  new b();
380
- class mt extends H {
380
+ class mt extends q {
381
381
  constructor(e, t) {
382
- super(at, G.FACE_LANDMARKS_TESSELATION);
382
+ super(at, j.FACE_LANDMARKS_TESSELATION);
383
383
  R(this, "blendshapeCategories");
384
384
  R(this, "blendshapeMap", /* @__PURE__ */ new Map());
385
385
  R(this, "smoothed", {});
@@ -389,9 +389,9 @@ class mt extends H {
389
389
  this.faceLandmarker = e, this.cfg = t, this.root.scale.y *= -1, this.root.scale.z *= -1, this.root.scale.multiplyScalar(3);
390
390
  }
391
391
  predict(e, t) {
392
- var s, a, i;
393
- const n = this.faceLandmarker.detectForVideo(e, performance.now());
394
- n.faceLandmarks[0] && (this.cfg.drawLandmarks && (t.drawConnectors(n.faceLandmarks[0], G.FACE_LANDMARKS_TESSELATION, { color: "#00fff2ff", lineWidth: 0.1 }), t.drawLandmarks(n.faceLandmarks[0], { color: "#00ff00", lineWidth: 0.1, radius: 0.4 })), this.updateLandmarks(n.faceLandmarks[0], n.faceLandmarks[0])), this._faceLandmarks = n.faceLandmarks[0], this.blendshapeCategories = (a = (s = n.faceBlendshapes) == null ? void 0 : s[0]) == null ? void 0 : a.categories, (i = this.blendshapeCategories) == null || i.forEach((r) => {
392
+ var n, d, i;
393
+ const s = this.faceLandmarker.detectForVideo(e, performance.now());
394
+ s.faceLandmarks[0] && (this.cfg.drawLandmarks && (t.drawConnectors(s.faceLandmarks[0], j.FACE_LANDMARKS_TESSELATION, { color: "#00fff2ff", lineWidth: 0.1 }), t.drawLandmarks(s.faceLandmarks[0], { color: "#00ff00", lineWidth: 0.1, radius: 0.4 })), this.updateLandmarks(s.faceLandmarks[0], s.faceLandmarks[0])), this._faceLandmarks = s.faceLandmarks[0], this.blendshapeCategories = (d = (n = s.faceBlendshapes) == null ? void 0 : n[0]) == null ? void 0 : d.categories, (i = this.blendshapeCategories) == null || i.forEach((r) => {
395
395
  this.blendshapeMap.set(r.categoryName, r.score);
396
396
  });
397
397
  }
@@ -401,25 +401,25 @@ class mt extends H {
401
401
  bindShapeKeys(e) {
402
402
  const t = e.morphTargetDictionary;
403
403
  return {
404
- update: (n) => {
405
- var s;
406
- (s = this.blendshapeCategories) == null || s.forEach((a) => {
407
- const { categoryName: i, score: r } = a;
404
+ update: (s) => {
405
+ var n;
406
+ (n = this.blendshapeCategories) == null || n.forEach((d) => {
407
+ const { categoryName: i, score: r } = d;
408
408
  if (!(t != null && t.hasOwnProperty(i))) return;
409
409
  this.smoothed[i] === void 0 && (this.smoothed[i] = r);
410
- const m = 1 - Math.pow(this.smoothing, n);
410
+ const m = 1 - Math.pow(this.smoothing, s);
411
411
  this.smoothed[i] += (r - this.smoothed[i]) * m, e.morphTargetInfluences[t[i]] = this.smoothed[i];
412
412
  });
413
413
  }
414
414
  };
415
415
  }
416
416
  bind(e) {
417
- const t = new fe(e, "L"), n = new fe(e, "R"), s = P(e, "head");
417
+ const t = new ye(e, "L"), s = new ye(e, "R"), n = P(e, "head");
418
418
  return {
419
- update: (a) => {
420
- if (t.update(a, this.blendshapeMap), n.update(a, this.blendshapeMap), !s) return;
421
- const i = dt.copy(this.marks.earL.worldPosition), r = ct.copy(this.marks.earR.worldPosition), m = Le.subVectors(i, r).multiplyScalar(0.5).add(r), c = lt.subVectors(this.marks.noseTip.worldPosition, m), f = i.sub(r), k = W(ht, s, e), x = f.add(k).applyMatrix4(e.matrixWorld), d = c.add(k).applyMatrix4(e.matrixWorld);
422
- F(s, d, x, "+x");
419
+ update: (d) => {
420
+ if (t.update(d, this.blendshapeMap), s.update(d, this.blendshapeMap), !n) return;
421
+ const i = dt.copy(this.marks.earL.worldPosition), r = ct.copy(this.marks.earR.worldPosition), m = be.subVectors(i, r).multiplyScalar(0.5).add(r), l = lt.subVectors(this.marks.noseTip.worldPosition, m), u = i.sub(r), y = A(ht, n, e), x = u.add(y).applyMatrix4(e.matrixWorld), W = l.add(y).applyMatrix4(e.matrixWorld);
422
+ S(n, W, x, "+x");
423
423
  }
424
424
  };
425
425
  }
@@ -432,64 +432,64 @@ class mt extends H {
432
432
  */
433
433
  bindGeometry(e, t) {
434
434
  new b(), new b();
435
- const n = new b();
435
+ const s = new b();
436
436
  new b();
437
- const a = e.geometry.attributes.position;
438
- C(new b(0.5, 0.5, 0.5)), Ce(e);
437
+ const d = e.geometry.attributes.position;
438
+ D(new b(0.5, 0.5, 0.5)), Ce(e);
439
439
  const i = Se("landmarkIndex", "uint"), r = Me(De, "vec3"), m = Ve(r.element(i)).xy;
440
- let c;
441
- const f = 116, k = 346, x = n.subVectors(
442
- new b(a.getX(f), a.getY(f), a.getZ(f)),
443
- new b(a.getX(k), a.getY(k), a.getZ(k))
440
+ let l;
441
+ const u = 116, y = 346, x = s.subVectors(
442
+ new b(d.getX(u), d.getY(u), d.getZ(u)),
443
+ new b(d.getX(y), d.getY(y), d.getZ(y))
444
444
  ).lengthSq();
445
445
  console.log("# mesh face reference (live): ", x);
446
- const d = C(x), h = C(1);
447
- let w;
446
+ const W = D(x), a = D(1);
447
+ let c;
448
448
  return {
449
449
  /**
450
450
  * Disposes of the material and removes events listeners on the video element.
451
451
  */
452
452
  disposeMaterial: () => {
453
- w == null || w();
453
+ c == null || c();
454
454
  },
455
455
  /**
456
456
  * asas
457
457
  * @param delta asas
458
458
  * @returns
459
459
  */
460
- update: (E) => {
461
- var g, L;
462
- if (!c) {
463
- const p = (L = (g = this.cfg) == null ? void 0 : g.videoElementRef) == null ? void 0 : L.call(g);
464
- if (!p || !p.videoWidth || !p.videoHeight) return;
465
- c = p;
466
- const A = new Q(c);
467
- A.colorSpace = Y;
468
- const T = C(c.videoWidth / c.videoHeight), S = r.element(k).sub(r.element(f)).lengthSq(), be = d.div(S).sqrt().mul(2), xe = r.element(234).xy, q = r.element(93).xy, Re = r.element(454).xy, $ = r.element(323).xy, j = xe.sub(q).div(2).add(q), ve = Re.sub($).div(2).add($).sub(j).div(2).add(j), K = r.element(i).sub(ve).xzy.mul(Ne(1, -1, Oe(1).div(T))).mul(be), M = Te(A, _e(m.x, m.y.oneMinus())), X = () => {
469
- const V = new Q(c);
470
- V.colorSpace = Y, M.value = V, M.needsUpdate = !0, T.value = c.videoWidth / c.videoHeight;
460
+ update: (L) => {
461
+ var E, g;
462
+ if (!l) {
463
+ const k = (g = (E = this.cfg) == null ? void 0 : E.videoElementRef) == null ? void 0 : g.call(E);
464
+ if (!k || !k.videoWidth || !k.videoHeight) return;
465
+ l = k;
466
+ const f = new Z(l);
467
+ f.colorSpace = J;
468
+ const F = D(l.videoWidth / l.videoHeight), _ = r.element(y).sub(r.element(u)).lengthSq(), B = W.div(_).sqrt().mul(2), M = r.element(234).xy, $ = r.element(93).xy, Re = r.element(454).xy, K = r.element(323).xy, X = M.sub($).div(2).add($), ve = Re.sub(K).div(2).add(K).sub(X).div(2).add(X), Q = r.element(i).sub(ve).xzy.mul(Ne(1, -1, Oe(1).div(F))).mul(B), V = Te(f, _e(m.x, m.y.oneMinus())), Y = () => {
469
+ const N = new Z(l);
470
+ N.colorSpace = J, V.value = N, V.needsUpdate = !0, F.value = l.videoWidth / l.videoHeight;
471
471
  };
472
- c.addEventListener("loadeddata", X), t ? t(K, M) : e.material = new Fe({
473
- positionNode: K,
474
- colorNode: M,
472
+ l.addEventListener("loadeddata", Y), t ? t(Q, V) : e.material = new Fe({
473
+ positionNode: Q,
474
+ colorNode: V,
475
475
  roughness: 0.93
476
- }), w = () => {
477
- var V;
478
- M.value.dispose(), c == null || c.removeEventListener("loadeddata", X), (V = e.material) == null || V.dispose();
476
+ }), c = () => {
477
+ var N;
478
+ V.value.dispose(), l == null || l.removeEventListener("loadeddata", Y), (N = e.material) == null || N.dispose();
479
479
  };
480
480
  }
481
- const y = this.lastKnownLandmarks;
482
- if (!(y != null && y.length)) return;
483
- h.value = n.subVectors(y[k], y[f]).lengthSq(), h.needsUpdate = !0;
481
+ const w = this.lastKnownLandmarks;
482
+ if (!(w != null && w.length)) return;
483
+ a.value = s.subVectors(w[y], w[u]).lengthSq(), a.needsUpdate = !0;
484
484
  const v = r.value.array;
485
- for (let p = 0; p < y.length; p++)
486
- v[p * 3] = y[p].x, v[p * 3 + 1] = y[p].y, v[p * 3 + 2] = y[p].z;
485
+ for (let k = 0; k < w.length; k++)
486
+ v[k * 3] = w[k].x, v[k * 3 + 1] = w[k].y, v[k * 3 + 2] = w[k].z;
487
487
  r.value.needsUpdate = !0;
488
488
  }
489
489
  };
490
490
  }
491
491
  }
492
- class fe {
492
+ class ye {
493
493
  constructor(o, e) {
494
494
  R(this, "eyeBone");
495
495
  R(this, "eyeLookOut");
@@ -503,12 +503,12 @@ class fe {
503
503
  }
504
504
  update(o, e) {
505
505
  if (!this.eyeBone) return;
506
- W(Le, this.eyeBone, this.rig);
507
- const t = e.get(this.eyeLookOut) ?? 0, n = e.get(this.eyeLookIn) ?? 0, s = e.get(this.eyeLookUp) ?? 0, a = e.get(this.eyeLookDown) ?? 0, i = n - t, r = a - s;
506
+ A(be, this.eyeBone, this.rig);
507
+ const t = e.get(this.eyeLookOut) ?? 0, s = e.get(this.eyeLookIn) ?? 0, n = e.get(this.eyeLookUp) ?? 0, d = e.get(this.eyeLookDown) ?? 0, i = s - t, r = d - n;
508
508
  this.eyeBone.rotation.y = i * this.sign / 2, this.eyeBone.rotation.x = r / 2;
509
509
  }
510
510
  }
511
- const ke = {
511
+ const xe = {
512
512
  faceMesh: "face",
513
513
  head: "head",
514
514
  hips: "hips",
@@ -612,93 +612,93 @@ const ke = {
612
612
  "mouthUpperUpRight",
613
613
  "tongueOut"
614
614
  ];
615
- function ut(l, o, e = 30) {
616
- const t = [], n = l.getObjectByName(
615
+ function ut(h, o, e = 30) {
616
+ const t = [], s = h.getObjectByName(
617
617
  o.faceMesh
618
- ), s = /* @__PURE__ */ new Set();
619
- if (n != null && n.morphTargetDictionary)
620
- for (const h in n.morphTargetDictionary)
621
- pt.includes(h) && s.add(h);
622
- const a = Object.keys(o);
623
- l.traverse((h) => {
624
- if (h instanceof _.Bone) {
625
- const w = a.find((E) => h.name.indexOf(o[E]) === 0);
626
- w && t.push({
627
- ref: h,
628
- name: h.name,
629
- normalizedName: w
618
+ ), n = /* @__PURE__ */ new Set();
619
+ if (s != null && s.morphTargetDictionary)
620
+ for (const a in s.morphTargetDictionary)
621
+ pt.includes(a) && n.add(a);
622
+ const d = Object.keys(o);
623
+ h.traverse((a) => {
624
+ if (a instanceof C.Bone) {
625
+ const c = d.find((L) => a.name.indexOf(o[L]) === 0);
626
+ c && t.push({
627
+ ref: a,
628
+ name: a.name,
629
+ normalizedName: c
630
630
  });
631
631
  }
632
632
  });
633
633
  const i = [], r = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
634
- let c = !1, f = 0;
635
- function k() {
636
- r.clear(), m.clear(), i.length = 0, f = performance.now() / 1e3, c = !0;
634
+ let l = !1, u = 0;
635
+ function y() {
636
+ r.clear(), m.clear(), i.length = 0, u = performance.now() / 1e3, l = !0;
637
637
  }
638
638
  function x() {
639
- if (!c) return;
640
- const h = performance.now() / 1e3 - f;
641
- i.push(h);
642
- for (const w of t) {
643
- r.has(w.name) || r.set(w.name, []);
644
- const E = r.get(w.name), y = w.ref.quaternion;
645
- E.push(y.x, y.y, y.z, y.w);
639
+ if (!l) return;
640
+ const a = performance.now() / 1e3 - u;
641
+ i.push(a);
642
+ for (const c of t) {
643
+ r.has(c.name) || r.set(c.name, []);
644
+ const L = r.get(c.name), w = c.ref.quaternion;
645
+ L.push(w.x, w.y, w.z, w.w);
646
646
  }
647
- for (const w of s) {
648
- m.has(w) || m.set(w, []);
649
- const E = m.get(w), y = n.morphTargetDictionary[w], v = n.morphTargetInfluences[y];
650
- E.push(v);
647
+ for (const c of n) {
648
+ m.has(c) || m.set(c, []);
649
+ const L = m.get(c), w = s.morphTargetDictionary[c], v = s.morphTargetInfluences[w];
650
+ L.push(v);
651
651
  }
652
652
  }
653
- function d(h = "RecordedClip") {
654
- c = !1;
655
- const w = [];
656
- for (const [y, v] of r)
657
- w.push(
658
- new _.QuaternionKeyframeTrack(
659
- `${y}.quaternion`,
653
+ function W(a = "RecordedClip") {
654
+ l = !1;
655
+ const c = [];
656
+ for (const [w, v] of r)
657
+ c.push(
658
+ new C.QuaternionKeyframeTrack(
659
+ `${w}.quaternion`,
660
660
  i,
661
661
  v
662
662
  )
663
663
  );
664
- for (const [y, v] of m)
665
- w.push(
666
- new _.NumberKeyframeTrack(
667
- `${ke.faceMesh}.morphTargetInfluences[${y}]`,
664
+ for (const [w, v] of m)
665
+ c.push(
666
+ new C.NumberKeyframeTrack(
667
+ `${xe.faceMesh}.morphTargetInfluences[${w}]`,
668
668
  i,
669
669
  v
670
670
  )
671
671
  );
672
- const E = new _.AnimationClip(h, -1, w);
672
+ const L = new C.AnimationClip(a, -1, c);
673
673
  return {
674
- clip: E,
674
+ clip: L,
675
675
  saveToFile: () => {
676
676
  new ze().parse(
677
- l,
677
+ h,
678
678
  (v) => {
679
- const g = new Blob([v], {
679
+ const E = new Blob([v], {
680
680
  type: "model/gltf-binary"
681
- }), L = URL.createObjectURL(g), p = document.createElement("a");
682
- p.href = L, p.download = h + ".glb", p.click();
681
+ }), g = URL.createObjectURL(E), k = document.createElement("a");
682
+ k.href = g, k.download = a + ".glb", k.click();
683
683
  },
684
684
  (v) => {
685
685
  console.error(v);
686
686
  },
687
687
  {
688
688
  binary: !0,
689
- animations: [E]
689
+ animations: [L]
690
690
  }
691
691
  );
692
692
  }
693
693
  };
694
694
  }
695
- return { start: k, captureFrame: x, stop: d, isRecording: () => c };
695
+ return { start: y, captureFrame: x, stop: W, isRecording: () => l };
696
696
  }
697
697
  const ft = () => {
698
- var l;
699
- return !!((l = navigator.mediaDevices) != null && l.getUserMedia);
698
+ var h;
699
+ return !!((h = navigator.mediaDevices) != null && h.getUserMedia);
700
700
  };
701
- async function Pt(l) {
701
+ async function Pt(h) {
702
702
  const o = {
703
703
  debugFrame: void 0,
704
704
  displayScale: 1,
@@ -713,136 +713,147 @@ async function Pt(l) {
713
713
  hand: "https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task",
714
714
  face: "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task"
715
715
  },
716
- ...l
716
+ ...h
717
717
  };
718
718
  let e;
719
- const t = await ge.forVisionTasks(o.modelPaths.vision ?? "/wasm"), n = o.onlyFace ? void 0 : await Xe(t, {
719
+ const t = await We.forVisionTasks(o.modelPaths.vision ?? "/wasm"), s = o.onlyFace ? void 0 : await Xe(t, {
720
720
  ignoreLegs: o.ignoreLegs,
721
721
  modelPath: o.modelPaths.pose,
722
722
  drawLandmarks: o.drawLandmarksOverlay
723
- }), s = o.onlyFace ? void 0 : await ot(t, {
724
- leftWrist: () => n.leftWristNormalizedPosition,
725
- rightWrist: () => n.rightWristNormalizedPosition,
723
+ }), n = o.onlyFace ? void 0 : await ot(t, {
724
+ leftWrist: () => s.leftWristNormalizedPosition,
725
+ rightWrist: () => s.rightWristNormalizedPosition,
726
726
  modelPath: o.modelPaths.hand,
727
727
  drawLandmarks: o.drawLandmarksOverlay,
728
- ...l == null ? void 0 : l.handsTrackerOptions
729
- }), a = o.ignoreFace ? void 0 : await rt(t, { modelPath: o.modelPaths.face, videoElementRef: () => e, drawLandmarks: o.drawLandmarksOverlay }), i = document.createElement("div");
728
+ ...h == null ? void 0 : h.handsTrackerOptions
729
+ }), d = o.ignoreFace ? void 0 : await rt(t, { modelPath: o.modelPaths.face, videoElementRef: () => e, drawLandmarks: o.drawLandmarksOverlay }), i = document.createElement("div");
730
730
  i.style.position = "absolute", i.style.top = "0px", i.style.left = "0px", i.style.zIndex = "21", i.style.maxWidth = "600px", i.style.width = "100%", i.classList.add("three-mediapipe-rig"), document.body.appendChild(i);
731
- const r = document.createElement("canvas"), m = r.getContext("2d"), c = new We(m);
731
+ const r = document.createElement("canvas"), m = r.getContext("2d"), l = new ge(m);
732
732
  r.style.zIndex = "22", r.style.position = "absolute", r.style.top = "0px", r.style.left = "0px", r.style.pointerEvents = "none", r.style.maxWidth = "100%", i.appendChild(r);
733
- function f(d) {
734
- m.save(), m.clearRect(0, 0, r.width, r.height), n == null || n.predict(d, c), s == null || s.left.predict(d, c), s == null || s.right.predict(d, c), a == null || a.predict(d, c), m.restore();
733
+ function u(a) {
734
+ m.save(), m.clearRect(0, 0, r.width, r.height), s == null || s.predict(a, l), n == null || n.left.predict(a, l), n == null || n.right.predict(a, l), d == null || d.predict(a, l), m.restore();
735
735
  }
736
- function k() {
736
+ function y() {
737
737
  e = document.createElement("video"), i.appendChild(e);
738
- let d = -1;
739
- e.style.zIndex = "21", e.style.position = "absolute", e.style.top = "0px", e.style.left = "0px", e.style.height = "auto", e.style.maxWidth = "100%", e.style.display = "block", o.debugVideo && (e.src = o.debugVideo, e.controls = !0, e.loop = !0, e.muted = !0, e.controls = !0, e.play());
740
- function h() {
741
- d !== e.currentTime && e.readyState >= 2 && (f(e), d = e.currentTime), window.requestAnimationFrame(h);
738
+ let a = -1;
739
+ e.style.zIndex = "21", e.style.position = "absolute", e.style.top = "0px", e.style.left = "0px", e.style.height = "auto", e.style.maxWidth = "100%", e.style.display = "block", e.muted = !1, o.debugVideo && (e.src = o.debugVideo, e.controls = !0, e.loop = !0, e.muted = !0, e.controls = !0, e.play());
740
+ function c() {
741
+ a !== e.currentTime && e.readyState >= 2 && (u(e), a = e.currentTime), window.requestAnimationFrame(c);
742
742
  }
743
743
  e.addEventListener("loadeddata", () => {
744
- e.width = e.videoWidth * o.displayScale, e.height = e.videoHeight * o.displayScale, r.width = e.videoWidth, r.height = e.videoHeight, r.style.height = e.height + "px", r.style.width = e.width + "px", window.requestAnimationFrame(h);
744
+ const L = e.videoWidth, w = e.videoHeight, g = Math.min(600 / L, 600 / w, 1);
745
+ e.width = L * g * (o.displayScale ?? 1), e.height = w * g * (o.displayScale ?? 1), r.width = e.width, r.height = e.height, r.style.height = "auto", r.style.width = e.width + "px", r.style.maxWidth = "100%", window.requestAnimationFrame(c);
745
746
  });
746
747
  }
747
748
  if (o.debugFrame) {
748
- const d = document.createElement("img");
749
- d.src = o.debugFrame, d.style.zIndex = "21", d.style.position = "absolute", d.style.top = "0px", d.style.left = "0px", i.appendChild(d), d.addEventListener("load", () => {
750
- d.width = d.naturalWidth * o.displayScale, d.height = d.naturalHeight * o.displayScale, r.width = d.naturalWidth, r.height = d.naturalWidth, r.style.width = d.width + "px", r.style.height = d.height + "px";
751
- function h() {
752
- f(d);
749
+ const a = document.createElement("img");
750
+ a.src = o.debugFrame, a.style.zIndex = "21", a.style.position = "absolute", a.style.top = "0px", a.style.left = "0px", i.appendChild(a), a.addEventListener("load", () => {
751
+ a.width = a.naturalWidth * o.displayScale, a.height = a.naturalHeight * o.displayScale, r.width = a.naturalWidth, r.height = a.naturalWidth, r.style.width = a.width + "px", r.style.height = a.height + "px";
752
+ function c() {
753
+ u(a);
753
754
  }
754
- window.requestAnimationFrame(h);
755
+ window.requestAnimationFrame(c);
755
756
  });
756
- } else o.debugVideo && k();
757
+ } else o.debugVideo && y();
757
758
  let x;
759
+ function W(a) {
760
+ e && (e.srcObject ? e.srcObject.getTracks().forEach((L) => L.enabled = a) : a ? e.play() : e.pause());
761
+ }
758
762
  return {
759
- poseTracker: n,
760
- handsTracker: s,
761
- faceTracker: a,
763
+ poseTracker: s,
764
+ handsTracker: n,
765
+ faceTracker: d,
762
766
  video: e,
763
767
  canvas: r,
764
768
  domElement: i,
765
- start: async () => {
766
- let d = !1;
769
+ start: async (a = !1) => {
770
+ let c = !1;
767
771
  if (!ft())
768
772
  throw new Error("Webcam not supported");
769
- e || k();
770
- let h;
771
- function w(L) {
772
- d || (console.warn("Camera track ended, attempting recovery..."), E(L), y(L));
773
+ e || y();
774
+ let L;
775
+ function w(f) {
776
+ c || (console.warn("Camera track ended, attempting recovery..."), v(f), E(f));
773
777
  }
774
- function E(L) {
775
- h == null || h.getVideoTracks().forEach((p) => p.stop()), h = void 0, L.srcObject = null;
778
+ function v(f) {
779
+ L == null || L.getVideoTracks().forEach((F) => F.stop()), L = void 0, f.srcObject = null;
776
780
  }
777
- async function y(L, p = 0) {
778
- const T = Math.min(1e3 * 2 ** p, 16e3);
779
- if (p >= 3)
781
+ async function E(f, F = 0) {
782
+ const B = Math.min(1e3 * 2 ** F, 16e3);
783
+ if (F >= 3)
780
784
  throw new Error("Camera recovery failed after max attempts");
781
- if (await new Promise((S) => setTimeout(S, T)), !d)
785
+ if (await new Promise((M) => setTimeout(M, B)), !c)
782
786
  try {
783
- await v(L);
784
- } catch (S) {
785
- await g(S, L, p + 1);
787
+ await g(f);
788
+ } catch (M) {
789
+ await k(M, f, F + 1);
786
790
  }
787
791
  }
788
- async function v(L) {
789
- h = await navigator.mediaDevices.getUserMedia({ video: !0 }), L.srcObject = h, await L.play(), h.getVideoTracks().forEach((p) => {
790
- p.addEventListener("ended", () => w(L));
792
+ async function g(f) {
793
+ L = await navigator.mediaDevices.getUserMedia({ video: !0, audio: a }), f.srcObject = L, await f.play(), L.getVideoTracks().forEach((F) => {
794
+ F.addEventListener("ended", () => w(f));
791
795
  });
792
796
  }
793
- async function g(L, p, A = 0) {
794
- if (L instanceof DOMException)
795
- switch (L.name) {
797
+ async function k(f, F, _ = 0) {
798
+ if (f instanceof DOMException)
799
+ switch (f.name) {
796
800
  case "NotAllowedError":
797
801
  throw new Error("Permission denied — prompt user to allow camera");
798
802
  case "NotFoundError":
799
- console.error("No camera found — retry when device is connected"), await y(p, A + 1);
803
+ console.error("No camera found — retry when device is connected"), await E(F, _ + 1);
800
804
  break;
801
805
  case "NotReadableError":
802
806
  throw new Error("Camera in use by another app");
803
807
  default:
804
- throw new Error("Camera error: " + L.message);
808
+ throw new Error("Camera error: " + f.message);
805
809
  }
806
810
  else
807
- throw new Error("Unknown camera error: " + L);
811
+ throw new Error("Unknown camera error: " + f);
808
812
  }
809
- return await y(e), x = () => {
810
- d = !0, E(e), x = void 0;
813
+ return await E(e), x = () => {
814
+ c = !0, v(e), x = void 0;
811
815
  }, {
816
+ getStream: () => L,
812
817
  stop: x
813
818
  };
814
819
  },
815
- bind: (d, h) => {
816
- if (h = h || ke, !n) throw new Error("Pose tracker not initialized");
817
- if (!s) throw new Error("Hands tracker not initialized");
818
- if (!a) throw new Error("Face tracker not initialized");
819
- const w = n.bind(d, h), E = s.left.bind(d, h), y = s.right.bind(d, h);
820
- let v;
821
- const g = a == null ? void 0 : a.bind(d);
822
- d.traverse((p) => {
823
- p instanceof u.Mesh && p.name.indexOf(h.faceMesh) === 0 && (p.frustumCulled = !1, v = a == null ? void 0 : a.bindShapeKeys(p));
820
+ pause: () => {
821
+ W(!1);
822
+ },
823
+ resume: () => {
824
+ W(!0);
825
+ },
826
+ bind: (a, c) => {
827
+ if (c = c || xe, !s) throw new Error("Pose tracker not initialized");
828
+ if (!n) throw new Error("Hands tracker not initialized");
829
+ if (!d) throw new Error("Face tracker not initialized");
830
+ const L = s.bind(a, c), w = n.left.bind(a, c), v = n.right.bind(a, c);
831
+ let E;
832
+ const g = d == null ? void 0 : d.bind(a);
833
+ a.traverse((f) => {
834
+ f instanceof p.Mesh && f.name.indexOf(c.faceMesh) === 0 && (f.frustumCulled = !1, E = d == null ? void 0 : d.bindShapeKeys(f));
824
835
  });
825
- const L = ut(d, h);
836
+ const k = ut(a, c);
826
837
  return {
827
838
  /**
828
839
  * Will save the tracked movement of the rig to an animation clip.
829
840
  * Only the bones moved by the bone mapping will be recorded.
830
841
  */
831
- startRecording: L.start,
832
- stopRecording: L.stop,
833
- isRecording: () => L.isRecording(),
834
- update: (p) => {
835
- w.update(p), E.update(p), y.update(p), v == null || v.update(p), g == null || g.update(p), L.isRecording() && L.captureFrame();
842
+ startRecording: k.start,
843
+ stopRecording: k.stop,
844
+ isRecording: () => k.isRecording(),
845
+ update: (f) => {
846
+ L.update(f), w.update(f), v.update(f), E == null || E.update(f), g == null || g.update(f), k.isRecording() && k.captureFrame();
836
847
  }
837
848
  };
838
849
  },
839
- setVideoFromSource: (d) => {
840
- x == null || x(), e || k(), e.src = d instanceof File ? URL.createObjectURL(d) : d, e.controls = !0, e.loop = !0, e.muted = !0, e.controls = !0, e.play();
850
+ setVideoFromSource: (a) => {
851
+ x == null || x(), e || y(), e.src = a instanceof File ? URL.createObjectURL(a) : a, e.controls = !0, e.loop = !0, e.muted = !0, e.controls = !0, e.play();
841
852
  },
842
- async setVideoFromWebcam() {
843
- if (e || k(), x)
853
+ async setVideoFromWebcam(a = !1) {
854
+ if (e || y(), x)
844
855
  throw new Error("Webcam already started");
845
- return await this.start();
856
+ return await this.start(a);
846
857
  }
847
858
  };
848
859
  }