@vincentt-xr/sdk 2.0.0-alpha.4 → 2.0.0-alpha.6
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/GROUNDING.md +11 -4
- package/README.md +85 -52
- package/dist/{DebuggerUI-DhKTXTY2.js → DebuggerUI-C_rbLdkh.js} +1 -1
- package/dist/{DebuggerUI-bnGHSSOb.cjs → DebuggerUI-DYT_dk1E.cjs} +1 -1
- package/dist/FaceMeshRenderer-D1WsrTLA.cjs +155 -0
- package/dist/FaceMeshRenderer-DSCd1H55.js +1264 -0
- package/dist/{FaceRetouch-Bg-OBU4n.js → FaceRetouch-CMJbGThL.js} +30 -30
- package/dist/{FaceRetouch-TZeBGIqW.cjs → FaceRetouch-DsE0Dbw-.cjs} +1 -1
- package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +11 -1
- package/dist/components/FaceMesh/canonical/geometryGroups.d.ts +1 -1
- package/dist/components/FaceMesh/canonical/parseCanonicalFaceModel.d.ts +1 -0
- package/dist/components/LipEffect/LipEffect.d.ts +2 -0
- package/dist/components/LipEffect/LipEffectMaterial.d.ts +10 -0
- package/dist/components/LipEffect/defaults.d.ts +9 -0
- package/dist/components/LipEffect/index.d.ts +4 -0
- package/dist/components/LipEffect/types.d.ts +22 -0
- package/dist/{contexts-B2_NsTnk.js → contexts-DvQI4PqI.js} +6 -3
- package/dist/contexts-h-9TRH0r.cjs +1 -0
- package/dist/debug-ui/media-source.cjs +1 -1
- package/dist/debug-ui/media-source.js +1 -1
- package/dist/debug-ui.cjs +1 -1
- package/dist/debug-ui.js +10 -10
- package/dist/entries/face-effects.d.ts +2 -0
- package/dist/face-effects.cjs +1 -1
- package/dist/face-effects.js +621 -508
- package/dist/{getFaceInfo-4DhcPZDJ.js → getFaceInfo-B43Cwq4n.js} +1 -1
- package/dist/{getFaceInfo-QOQ_dc-W.cjs → getFaceInfo-DEzcL_Ub.cjs} +1 -1
- package/dist/{index-D1kj6uc-.js → index-B-s4YbWu.js} +1 -1
- package/dist/index-C0-fg1Hk.cjs +1 -0
- package/dist/{index-C9yQVzAh.cjs → index-CY7Z8cHV.cjs} +1 -1
- package/dist/{index-ZaDEzDtR.cjs → index-CxMEeCRP.cjs} +1 -1
- package/dist/{index-WPPnlFO1.cjs → index-D67hHm44.cjs} +1 -1
- package/dist/{index-CNGzE49z.cjs → index-DPPpU5By.cjs} +1 -1
- package/dist/{index-g250Tqme.js → index-DYfY9ljy.js} +1 -1
- package/dist/{index-Cj3fGDtZ.js → index-G_5h_FJQ.js} +8 -8
- package/dist/{index-BMeBJ0dV.js → index-I4eF5TKT.js} +227 -191
- package/dist/{index-72Wb15Ca.js → index-uE3sKczj.js} +1 -1
- package/dist/{internal-Dtvo4WYo.cjs → internal-MvKrz0Nt.cjs} +1 -1
- package/dist/{internal-34pb7djs.js → internal-ldPYiUF0.js} +3 -3
- package/dist/internal.cjs +1 -1
- package/dist/internal.js +1 -1
- package/dist/low-level.cjs +1 -1
- package/dist/low-level.js +11 -11
- package/dist/main.cjs +1 -1
- package/dist/main.js +12 -12
- package/dist/{renderGroups-jSUOY1Oq.cjs → renderGroups-BJsx32q5.cjs} +1 -1
- package/dist/{renderGroups-CPWUX6z9.js → renderGroups-CFt1yYLB.js} +1 -1
- package/dist/{renderPasses-CLlYRdMk.js → renderPasses-C72MbZ-a.js} +4 -4
- package/dist/{renderPasses-KUJUSevp.cjs → renderPasses-D-Krl6D0.cjs} +1 -1
- package/dist/scene-object.cjs +1 -1
- package/dist/scene-object.js +2 -2
- package/dist/{selectors-DLxL8Q66.js → selectors-ByKNTXeA.js} +1 -1
- package/dist/{selectors-S8g25ke9.cjs → selectors-CAwmL9VW.cjs} +1 -1
- package/dist/{session-DP8AF7Rg.cjs → session-CANvoLD6.cjs} +1 -1
- package/dist/{session-CbtvwiaD.js → session-Dhi0OqZo.js} +1 -1
- package/dist/tracking.cjs +1 -1
- package/dist/tracking.js +9 -9
- package/dist/{useFaceInfo-BvZeUBsL.cjs → useFaceInfo-BSZq7AO1.cjs} +1 -1
- package/dist/{useFaceInfo-C06EyScd.js → useFaceInfo-FVQBBNdY.js} +3 -3
- package/dist/{useFaceResults-CCNiH7VZ.cjs → useFaceResults-C3oZkn2Z.cjs} +1 -1
- package/dist/{useFaceResults-C1Ppc8rS.js → useFaceResults-D62STzT1.js} +1 -1
- package/dist/utils/visionWasm.d.ts +18 -0
- package/package.json +2 -2
- package/dist/FaceMeshRenderer-B2i2NW71.js +0 -1195
- package/dist/FaceMeshRenderer-BSOq1OnG.cjs +0 -155
- package/dist/contexts-BgWfyxre.cjs +0 -1
- package/dist/index-Da7uycur.cjs +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (n, s, e) =>
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { useRef as
|
|
6
|
-
import { FilesetResolver as V, PoseLandmarker as
|
|
1
|
+
var Ee = Object.defineProperty;
|
|
2
|
+
var Ie = (n, s, e) => s in n ? Ee(n, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[s] = e;
|
|
3
|
+
var h = (n, s, e) => Ie(n, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import { jsx as re } from "react/jsx-runtime";
|
|
5
|
+
import { useRef as he, useMemo as J, useEffect as Pe, useContext as de, useCallback as oe, createElement as De, createContext as ue } from "react";
|
|
6
|
+
import { FilesetResolver as V, PoseLandmarker as _e, FaceLandmarker as Oe, GestureRecognizer as Ue, HandLandmarker as ze, ImageSegmenter as Le, DrawingUtils as Be } from "@mediapipe/tasks-vision";
|
|
7
7
|
import * as E from "three";
|
|
8
|
-
import { RGBAFormat as
|
|
8
|
+
import { RGBAFormat as le, LinearFilter as G, CanvasTexture as ge, SRGBColorSpace as Ve } from "three";
|
|
9
9
|
var F = /* @__PURE__ */ ((n) => (n.WEBCAM = "webcam", n.STREAM = "stream", n.CANVAS = "canvas", n))(F || {}), z = /* @__PURE__ */ ((n) => (n.HAND_TRACKER = "vincentt.xr.hand-tracker", n.GESTURE_TRACKER = "vincentt.xr.gesture-tracker", n.FACE_TRACKER = "vincentt.xr.face-tracker", n.BODY_TRACKER = "vincentt.xr.body-tracker", n.BACKGROUND_SEGMENTATION = "vincentt.xr.background-segmentation", n))(z || {});
|
|
10
10
|
class b extends Error {
|
|
11
11
|
constructor(s) {
|
|
12
12
|
super(s), this.name = "VincenttXRError";
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
apiBaseUrl:
|
|
15
|
+
const Ke = (n, s) => s, I = {
|
|
16
|
+
apiBaseUrl: Ke(void 0, "https://api.vincentt.studio"),
|
|
17
17
|
// Pinned to the CDN, NOT build-env-driven: a stale VITE_ASSET_STORAGE_ENDPOINT
|
|
18
18
|
// baked a now-deleted CloudFront domain into every published bundle, breaking
|
|
19
19
|
// WASM/model loads at runtime. The host must never come from a mutable env value.
|
|
@@ -23,7 +23,7 @@ const Be = (n, s) => s, I = {
|
|
|
23
23
|
loggerPrefix: "[vincentt-xr]:",
|
|
24
24
|
sessionCheckInterval: 3e4
|
|
25
25
|
};
|
|
26
|
-
class
|
|
26
|
+
class Ne {
|
|
27
27
|
constructor(s) {
|
|
28
28
|
h(this, "options");
|
|
29
29
|
const e = {
|
|
@@ -41,12 +41,12 @@ class Ve {
|
|
|
41
41
|
e && console.error(t, ...s);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
const O = (n) => n * 2 - 1,
|
|
45
|
-
|
|
46
|
-
const r = -t.position.z /
|
|
47
|
-
return i.copy(t.position).addScaledVector(
|
|
48
|
-
},
|
|
49
|
-
class
|
|
44
|
+
const O = (n) => n * 2 - 1, Y = new E.Vector3(), Q = new E.Vector3(), q = ({ x: n, y: s, z: e }, t, i) => {
|
|
45
|
+
Y.set((n - 0.5) * 2, (0.5 - s) * 2, -e), Y.unproject(t), Q.copy(Y).sub(t.position).normalize();
|
|
46
|
+
const r = -t.position.z / Q.z;
|
|
47
|
+
return i.copy(t.position).addScaledVector(Q, r), i;
|
|
48
|
+
}, Ut = (n, s) => q(n, s, new E.Vector3()), He = (n, s, e = 0.2) => e * s + (1 - e) * n;
|
|
49
|
+
class ee {
|
|
50
50
|
constructor(s) {
|
|
51
51
|
h(this, "canvas");
|
|
52
52
|
this.maxDimension = s;
|
|
@@ -68,7 +68,7 @@ class Z {
|
|
|
68
68
|
this.canvas = void 0;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
const
|
|
71
|
+
const qe = {
|
|
72
72
|
"/assets/xr/models/face_tracking.task": "sha384-tYQh+yJE8llY+zO4RviZmWaSKs5W9tsB0ix5rjQVpF5/CLTqmwtP7bYtkUi2w65P",
|
|
73
73
|
"/assets/xr/models/hand_tracking.task": "sha384-uWvruVKd887ov8k43S+DBHCsi7UXXS+CKvvdM1PX00rjPzx/B0QrAPfJ1U9yKcze",
|
|
74
74
|
"/assets/xr/models/gesture_tracking.task": "sha384-2zuseP9JKKWAYlWQGKA2N+ooabB8V/yIxu23Mv8mtY7SowcySB+xKiOmqBhVvlUC",
|
|
@@ -78,24 +78,24 @@ const Ne = {
|
|
|
78
78
|
"/assets/sdk/face/v1/canonical_face_model.obj": "sha384-xP8YM/72TXKvbMptXB9a8JUlUf3MZQ8uLurExrsZc05v6/P5RrsaNGMUYS/BZx8A",
|
|
79
79
|
"/opencv/facial_expression_recognition/resolve/main/facial_expression_recognition_mobilefacenet_2022july_int8.onnx": "sha384-g8mtFubiIc/yhqi591RsxD76AJLw2CfYgKhKbVkIiFlwBmIyG7ZAIVyGPXafrDGB"
|
|
80
80
|
};
|
|
81
|
-
async function
|
|
81
|
+
async function Ge(n) {
|
|
82
82
|
const s = await fetch(n);
|
|
83
83
|
if (!s.ok)
|
|
84
84
|
throw new Error(`fetchAndVerify: ${s.status} ${n}`);
|
|
85
|
-
const e = await s.arrayBuffer(), t =
|
|
85
|
+
const e = await s.arrayBuffer(), t = Xe(n);
|
|
86
86
|
if (!t) {
|
|
87
|
-
if (
|
|
87
|
+
if (We(n))
|
|
88
88
|
throw new Error(`[xr-sdk integrity] no SRI hash for SDK asset ${n}`);
|
|
89
89
|
return console.warn(`[xr-sdk integrity] no SRI hash for ${n} — passing through`), e;
|
|
90
90
|
}
|
|
91
|
-
const i = await
|
|
91
|
+
const i = await je(e);
|
|
92
92
|
if (i !== t)
|
|
93
93
|
throw new Error(
|
|
94
94
|
`[xr-sdk integrity] SRI mismatch for ${n}: expected ${t}, got ${i}`
|
|
95
95
|
);
|
|
96
96
|
return e;
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function We(n) {
|
|
99
99
|
try {
|
|
100
100
|
return new URL(n).origin === new URL(I.assetStorageEndpoint).origin;
|
|
101
101
|
} catch {
|
|
@@ -103,25 +103,43 @@ function qe(n) {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
async function K(n) {
|
|
106
|
-
const s = await
|
|
106
|
+
const s = await Ge(n);
|
|
107
107
|
return new Uint8Array(s);
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function Xe(n) {
|
|
110
110
|
try {
|
|
111
111
|
const s = new URL(n);
|
|
112
|
-
return
|
|
112
|
+
return qe[s.pathname];
|
|
113
113
|
} catch {
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
async function
|
|
117
|
+
async function je(n) {
|
|
118
118
|
const s = await crypto.subtle.digest("SHA-384", n), e = new Uint8Array(s);
|
|
119
119
|
let t = "";
|
|
120
120
|
for (let i = 0; i < e.byteLength; i++)
|
|
121
121
|
t += String.fromCharCode(e[i]);
|
|
122
122
|
return `sha384-${btoa(t)}`;
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
const $ = /* @__PURE__ */ new Map();
|
|
125
|
+
function N(n) {
|
|
126
|
+
const s = n.wasmBinaryPath;
|
|
127
|
+
let e = $.get(s);
|
|
128
|
+
return e || (e = Ye(s).catch(() => {
|
|
129
|
+
$.delete(s);
|
|
130
|
+
}), $.set(s, e)), e;
|
|
131
|
+
}
|
|
132
|
+
async function Ye(n) {
|
|
133
|
+
const s = await fetch(n, { credentials: "same-origin" });
|
|
134
|
+
if (!s.ok || !s.body)
|
|
135
|
+
throw new Error(`warmVisionWasm: ${s.status} ${n}`);
|
|
136
|
+
const e = s.body.getReader();
|
|
137
|
+
for (; ; ) {
|
|
138
|
+
const { done: t } = await e.read();
|
|
139
|
+
if (t) return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
class H {
|
|
125
143
|
constructor() {
|
|
126
144
|
h(this, "disposed", !1);
|
|
127
145
|
h(this, "paused", !1);
|
|
@@ -183,15 +201,15 @@ class N {
|
|
|
183
201
|
this.disposed = !0, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
|
|
184
202
|
}
|
|
185
203
|
}
|
|
186
|
-
const
|
|
187
|
-
class
|
|
204
|
+
const Qe = 768;
|
|
205
|
+
class $e extends H {
|
|
188
206
|
constructor() {
|
|
189
207
|
super();
|
|
190
208
|
h(this, "landmarker", null);
|
|
191
209
|
h(this, "processingTime", null);
|
|
192
210
|
h(this, "coordinates");
|
|
193
211
|
h(this, "sourceCanvas");
|
|
194
|
-
h(this, "downscaler", new
|
|
212
|
+
h(this, "downscaler", new ee(Qe));
|
|
195
213
|
}
|
|
196
214
|
async getBodyData() {
|
|
197
215
|
if (!this.landmarker || !this.sourceCanvas)
|
|
@@ -238,10 +256,13 @@ class je extends N {
|
|
|
238
256
|
async initialize(e) {
|
|
239
257
|
const t = await V.forVisionTasks(
|
|
240
258
|
new URL("/assets/xr/wasm", I.assetStorageEndpoint).toString()
|
|
241
|
-
), i = await
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
259
|
+
), [i] = await Promise.all([
|
|
260
|
+
K(
|
|
261
|
+
new URL("/assets/xr/models/body_tracking.task", I.assetStorageEndpoint).toString()
|
|
262
|
+
),
|
|
263
|
+
N(t)
|
|
264
|
+
]);
|
|
265
|
+
this.landmarker = await _e.createFromOptions(t, {
|
|
245
266
|
baseOptions: {
|
|
246
267
|
modelAssetBuffer: i,
|
|
247
268
|
delegate: "GPU"
|
|
@@ -265,8 +286,8 @@ class je extends N {
|
|
|
265
286
|
};
|
|
266
287
|
}
|
|
267
288
|
}
|
|
268
|
-
const
|
|
269
|
-
class
|
|
289
|
+
const Ze = 0.11, Je = 4e-3, et = (n, s) => s.set(n.x, -n.y, n.z);
|
|
290
|
+
class tt extends H {
|
|
270
291
|
constructor() {
|
|
271
292
|
super();
|
|
272
293
|
h(this, "landmarker", null);
|
|
@@ -327,20 +348,20 @@ class Ze extends N {
|
|
|
327
348
|
this.rotQuatScratch.y,
|
|
328
349
|
this.rotQuatScratch.z,
|
|
329
350
|
this.rotQuatScratch.w
|
|
330
|
-
), this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch, "XYZ"),
|
|
351
|
+
), this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch, "XYZ"), et(this.rotEulerScratch, o.transform.rotation), q(
|
|
331
352
|
this.landmarkForSource(d[4], m),
|
|
332
353
|
this.cameras[r],
|
|
333
354
|
o.transform.position
|
|
334
|
-
),
|
|
355
|
+
), q(
|
|
335
356
|
this.landmarkForSource(d[50], m),
|
|
336
357
|
this.cameras[r],
|
|
337
358
|
this.leftCheekScratch[r]
|
|
338
|
-
),
|
|
359
|
+
), q(
|
|
339
360
|
this.landmarkForSource(d[280], m),
|
|
340
361
|
this.cameras[r],
|
|
341
362
|
this.rightCheekScratch[r]
|
|
342
363
|
);
|
|
343
|
-
const M = this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r]) *
|
|
364
|
+
const M = this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r]) * Ze, x = Math.abs(E.MathUtils.radToDeg(this.rotEulerScratch.y)), l = M + x * Je, f = o.transform.scale.x, v = He(
|
|
344
365
|
isNaN(f) ? 0 : f,
|
|
345
366
|
l
|
|
346
367
|
);
|
|
@@ -357,7 +378,7 @@ class Ze extends N {
|
|
|
357
378
|
this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this));
|
|
358
379
|
return;
|
|
359
380
|
}
|
|
360
|
-
const e =
|
|
381
|
+
const e = st(this.numFaces), t = this.sourceCanvas.width, i = this.sourceCanvas.height, r = Math.min(1, e / Math.max(t, i)), o = Math.max(1, Math.round(t * r)), u = Math.max(1, Math.round(i * r));
|
|
361
382
|
(!this.analysisCanvas || this.analysisCanvas.width !== o || this.analysisCanvas.height !== u) && (this.analysisCanvas = new OffscreenCanvas(o, u));
|
|
362
383
|
const m = this.analysisCanvas.getContext("2d");
|
|
363
384
|
if (!m) {
|
|
@@ -400,9 +421,12 @@ class Ze extends N {
|
|
|
400
421
|
this.numFaces = (e == null ? void 0 : e.numFaces) || 1;
|
|
401
422
|
const t = await V.forVisionTasks(
|
|
402
423
|
new URL("/assets/xr/wasm", I.assetStorageEndpoint).toString()
|
|
403
|
-
), i = await
|
|
404
|
-
|
|
405
|
-
|
|
424
|
+
), [i] = await Promise.all([
|
|
425
|
+
K(
|
|
426
|
+
new URL("/assets/xr/models/face_tracking.task", I.assetStorageEndpoint).toString()
|
|
427
|
+
),
|
|
428
|
+
N(t)
|
|
429
|
+
]), r = await Oe.createFromOptions(t, {
|
|
406
430
|
baseOptions: {
|
|
407
431
|
modelAssetBuffer: i,
|
|
408
432
|
delegate: "GPU"
|
|
@@ -446,19 +470,19 @@ class Ze extends N {
|
|
|
446
470
|
};
|
|
447
471
|
}
|
|
448
472
|
}
|
|
449
|
-
const
|
|
450
|
-
var
|
|
451
|
-
const
|
|
452
|
-
Closed_Fist:
|
|
453
|
-
Open_Palm:
|
|
454
|
-
Pointing_Up:
|
|
455
|
-
Thumb_Down:
|
|
456
|
-
Thumb_Up:
|
|
457
|
-
Victory:
|
|
458
|
-
ILoveYou:
|
|
459
|
-
None:
|
|
460
|
-
},
|
|
461
|
-
class
|
|
473
|
+
const st = (n) => n > 1 ? 1024 : 512;
|
|
474
|
+
var P = /* @__PURE__ */ ((n) => (n.ClosedFist = "closed_fist", n.OpenPalm = "open_palm", n.PointingUp = "pointing_up", n.ThumbDown = "thumb_down", n.ThumbUp = "thumb_up", n.Victory = "victory", n.ILoveYou = "i_love_you", n.None = "none", n))(P || {});
|
|
475
|
+
const nt = 512, at = {
|
|
476
|
+
Closed_Fist: P.ClosedFist,
|
|
477
|
+
Open_Palm: P.OpenPalm,
|
|
478
|
+
Pointing_Up: P.PointingUp,
|
|
479
|
+
Thumb_Down: P.ThumbDown,
|
|
480
|
+
Thumb_Up: P.ThumbUp,
|
|
481
|
+
Victory: P.Victory,
|
|
482
|
+
ILoveYou: P.ILoveYou,
|
|
483
|
+
None: P.None
|
|
484
|
+
}, it = 15;
|
|
485
|
+
class rt extends H {
|
|
462
486
|
constructor() {
|
|
463
487
|
super();
|
|
464
488
|
h(this, "landmarker", null);
|
|
@@ -466,7 +490,7 @@ class nt extends N {
|
|
|
466
490
|
h(this, "coordinates");
|
|
467
491
|
h(this, "gesture");
|
|
468
492
|
h(this, "sourceCanvas");
|
|
469
|
-
h(this, "downscaler", new
|
|
493
|
+
h(this, "downscaler", new ee(nt));
|
|
470
494
|
}
|
|
471
495
|
async getGestureData() {
|
|
472
496
|
if (!this.landmarker || !this.sourceCanvas)
|
|
@@ -484,7 +508,7 @@ class nt extends N {
|
|
|
484
508
|
});
|
|
485
509
|
}), {
|
|
486
510
|
coordinates: u,
|
|
487
|
-
gesture:
|
|
511
|
+
gesture: at[m]
|
|
488
512
|
};
|
|
489
513
|
}
|
|
490
514
|
return { coordinates: void 0, gesture: void 0 };
|
|
@@ -514,9 +538,15 @@ class nt extends N {
|
|
|
514
538
|
async initialize() {
|
|
515
539
|
const e = await V.forVisionTasks(
|
|
516
540
|
new URL("/assets/xr/wasm", I.assetStorageEndpoint).toString()
|
|
517
|
-
), t = await
|
|
518
|
-
|
|
519
|
-
|
|
541
|
+
), [t] = await Promise.all([
|
|
542
|
+
K(
|
|
543
|
+
new URL(
|
|
544
|
+
"/assets/xr/models/gesture_tracking.task",
|
|
545
|
+
I.assetStorageEndpoint
|
|
546
|
+
).toString()
|
|
547
|
+
),
|
|
548
|
+
N(e)
|
|
549
|
+
]), i = await Ue.createFromOptions(e, {
|
|
520
550
|
baseOptions: {
|
|
521
551
|
modelAssetBuffer: t,
|
|
522
552
|
delegate: "GPU"
|
|
@@ -527,7 +557,7 @@ class nt extends N {
|
|
|
527
557
|
this.landmarker = i;
|
|
528
558
|
}
|
|
529
559
|
async run({ sourceCanvas: e, targetFps: t }) {
|
|
530
|
-
this.sourceCanvas = e, this.setTargetFps(t ??
|
|
560
|
+
this.sourceCanvas = e, this.setTargetFps(t ?? it), this.rafId === null && await this.processGestureTracking();
|
|
531
561
|
}
|
|
532
562
|
getModelNode() {
|
|
533
563
|
const e = this;
|
|
@@ -547,8 +577,8 @@ class nt extends N {
|
|
|
547
577
|
};
|
|
548
578
|
}
|
|
549
579
|
}
|
|
550
|
-
const
|
|
551
|
-
class
|
|
580
|
+
const ot = 512;
|
|
581
|
+
class ct extends H {
|
|
552
582
|
constructor() {
|
|
553
583
|
super();
|
|
554
584
|
h(this, "landmarker", null);
|
|
@@ -558,7 +588,7 @@ class it extends N {
|
|
|
558
588
|
h(this, "gesture");
|
|
559
589
|
h(this, "handedness");
|
|
560
590
|
h(this, "sourceCanvas");
|
|
561
|
-
h(this, "downscaler", new
|
|
591
|
+
h(this, "downscaler", new ee(ot));
|
|
562
592
|
}
|
|
563
593
|
async getHandData() {
|
|
564
594
|
if (!this.landmarker || !this.sourceCanvas)
|
|
@@ -616,9 +646,12 @@ class it extends N {
|
|
|
616
646
|
async initialize() {
|
|
617
647
|
const e = await V.forVisionTasks(
|
|
618
648
|
new URL("/assets/xr/wasm", I.assetStorageEndpoint).toString()
|
|
619
|
-
), t = await
|
|
620
|
-
|
|
621
|
-
|
|
649
|
+
), [t] = await Promise.all([
|
|
650
|
+
K(
|
|
651
|
+
new URL("/assets/xr/models/hand_tracking.task", I.assetStorageEndpoint).toString()
|
|
652
|
+
),
|
|
653
|
+
N(e)
|
|
654
|
+
]), i = await ze.createFromOptions(e, {
|
|
622
655
|
baseOptions: {
|
|
623
656
|
modelAssetBuffer: t,
|
|
624
657
|
delegate: "GPU"
|
|
@@ -655,13 +688,13 @@ class it extends N {
|
|
|
655
688
|
};
|
|
656
689
|
}
|
|
657
690
|
}
|
|
658
|
-
const
|
|
691
|
+
const ht = 24, dt = 720, ut = [
|
|
659
692
|
[255, 255, 255, 255],
|
|
660
693
|
// 0: background → green 255, kept
|
|
661
694
|
[0, 0, 0, 0]
|
|
662
695
|
// 1: person → green 0, discarded
|
|
663
696
|
];
|
|
664
|
-
class
|
|
697
|
+
class lt extends H {
|
|
665
698
|
constructor() {
|
|
666
699
|
super();
|
|
667
700
|
h(this, "segmenter", null);
|
|
@@ -747,7 +780,7 @@ class ht extends N {
|
|
|
747
780
|
const e = this.readIntrinsicSize(this.inputSource);
|
|
748
781
|
if (!e) return;
|
|
749
782
|
this.inputSourceSize = e;
|
|
750
|
-
const t = Math.min(1,
|
|
783
|
+
const t = Math.min(1, dt / Math.max(e.width, e.height)), i = Math.max(1, Math.round(e.width * t)), r = Math.max(1, Math.round(e.height * t));
|
|
751
784
|
this.processCanvas.width === i && this.processCanvas.height === r || (this.processCanvas.width = i, this.processCanvas.height = r, this.glCanvas && (this.glCanvas.width = i, this.glCanvas.height = r), this.maskImageData = void 0);
|
|
752
785
|
}
|
|
753
786
|
async processSegmentation() {
|
|
@@ -785,13 +818,13 @@ class ht extends N {
|
|
|
785
818
|
return;
|
|
786
819
|
}
|
|
787
820
|
if (this.rawCache = null, this.latestMask && (this.latestMask.close(), this.latestMask = null), this.useGpuMaskPath && this.drawingUtils && this.glCanvas)
|
|
788
|
-
this.drawingUtils.drawCategoryMask(o,
|
|
821
|
+
this.drawingUtils.drawCategoryMask(o, ut), this.latestMask = o.clone(), o.close(), this.blitGlToMask();
|
|
789
822
|
else {
|
|
790
823
|
this.latestMask = o.clone();
|
|
791
824
|
const u = this.readMaskToImageData(o);
|
|
792
825
|
o.close(), u && this.blitImageDataToMask(u);
|
|
793
826
|
}
|
|
794
|
-
this.segmentationMaskTexture && (this.isMaskSetup || (this.segmentationMaskTexture.format =
|
|
827
|
+
this.segmentationMaskTexture && (this.isMaskSetup || (this.segmentationMaskTexture.format = le, this.segmentationMaskTexture.minFilter = G, this.segmentationMaskTexture.magFilter = G, this.segmentationMaskTexture.generateMipmaps = !1, this.isMaskSetup = !0), this.segmentationMaskTexture.needsUpdate = !0), this.processingTime = performance.now() - t, !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.processSegmentation.bind(this)));
|
|
795
828
|
}
|
|
796
829
|
/**
|
|
797
830
|
* Blit the GPU-rendered mask (already RGBA-inverted by drawCategoryMask)
|
|
@@ -860,14 +893,17 @@ class ht extends N {
|
|
|
860
893
|
this.quality = (e == null ? void 0 : e.quality) ?? "low";
|
|
861
894
|
const t = await V.forVisionTasks(
|
|
862
895
|
new URL("/assets/xr/wasm", I.assetStorageEndpoint).toString()
|
|
863
|
-
), i = await
|
|
864
|
-
|
|
865
|
-
|
|
896
|
+
), [i] = await Promise.all([
|
|
897
|
+
K(
|
|
898
|
+
new URL("/assets/xr/models/segmentation.tflite", I.assetStorageEndpoint).toString()
|
|
899
|
+
),
|
|
900
|
+
N(t)
|
|
901
|
+
]);
|
|
866
902
|
this.glCanvas = new OffscreenCanvas(1, 1);
|
|
867
903
|
const r = this.glCanvas.getContext("webgl2", {
|
|
868
904
|
preserveDrawingBuffer: !0
|
|
869
905
|
});
|
|
870
|
-
this.segmenter = await
|
|
906
|
+
this.segmenter = await Le.createFromOptions(t, {
|
|
871
907
|
baseOptions: {
|
|
872
908
|
modelAssetBuffer: i,
|
|
873
909
|
delegate: "GPU"
|
|
@@ -876,7 +912,7 @@ class ht extends N {
|
|
|
876
912
|
outputCategoryMask: !0,
|
|
877
913
|
outputConfidenceMasks: !1,
|
|
878
914
|
runningMode: "VIDEO"
|
|
879
|
-
}), r ? (this.drawingUtils = new
|
|
915
|
+
}), r ? (this.drawingUtils = new Be(r), this.useGpuMaskPath = !0) : this.useGpuMaskPath = !1;
|
|
880
916
|
}
|
|
881
917
|
async run({
|
|
882
918
|
sourceCanvas: e,
|
|
@@ -887,9 +923,9 @@ class ht extends N {
|
|
|
887
923
|
var u;
|
|
888
924
|
if (!e)
|
|
889
925
|
return;
|
|
890
|
-
this.setTargetFps(r ??
|
|
926
|
+
this.setTargetFps(r ?? ht), this.isProcessing = !1, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
|
|
891
927
|
const o = this.getQualityScaleFactor();
|
|
892
|
-
this.sourceCanvas = e, this.processCanvas = document.createElement("canvas"), this.processCanvas.width = e.width * o, this.processCanvas.height = e.height * o, this.glCanvas && (this.glCanvas.width = this.processCanvas.width, this.glCanvas.height = this.processCanvas.height), this.maskImageData = void 0, this.maskCanvas = document.createElement("canvas"), this.maskCanvas.width = t, this.maskCanvas.height = i, this.filterCanvas = document.createElement("canvas"), this.filterCanvas.width = t, this.filterCanvas.height = i, (u = this.segmentationMaskTexture) == null || u.dispose(), this.segmentationMaskTexture = new
|
|
928
|
+
this.sourceCanvas = e, this.processCanvas = document.createElement("canvas"), this.processCanvas.width = e.width * o, this.processCanvas.height = e.height * o, this.glCanvas && (this.glCanvas.width = this.processCanvas.width, this.glCanvas.height = this.processCanvas.height), this.maskImageData = void 0, this.maskCanvas = document.createElement("canvas"), this.maskCanvas.width = t, this.maskCanvas.height = i, this.filterCanvas = document.createElement("canvas"), this.filterCanvas.width = t, this.filterCanvas.height = i, (u = this.segmentationMaskTexture) == null || u.dispose(), this.segmentationMaskTexture = new ge(this.maskCanvas), this.isMaskSetup = !1, this.rawCache = null, this.isProcessing = !0, this.lastInferenceMs = 0, this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
|
|
893
929
|
}
|
|
894
930
|
/**
|
|
895
931
|
* Lazily read the single-channel mask back to a Uint8Array. Only invoked when
|
|
@@ -924,13 +960,13 @@ class ht extends N {
|
|
|
924
960
|
};
|
|
925
961
|
}
|
|
926
962
|
}
|
|
927
|
-
const
|
|
928
|
-
[z.BACKGROUND_SEGMENTATION]:
|
|
929
|
-
[z.HAND_TRACKER]:
|
|
930
|
-
[z.GESTURE_TRACKER]:
|
|
931
|
-
[z.FACE_TRACKER]:
|
|
932
|
-
[z.BODY_TRACKER]:
|
|
933
|
-
},
|
|
963
|
+
const ce = {
|
|
964
|
+
[z.BACKGROUND_SEGMENTATION]: lt,
|
|
965
|
+
[z.HAND_TRACKER]: ct,
|
|
966
|
+
[z.GESTURE_TRACKER]: rt,
|
|
967
|
+
[z.FACE_TRACKER]: tt,
|
|
968
|
+
[z.BODY_TRACKER]: $e
|
|
969
|
+
}, gt = async (n) => {
|
|
934
970
|
const s = document.createElement("video");
|
|
935
971
|
s.srcObject = n, s.muted = !0, s.playsInline = !0, s.autoplay = !0, await new Promise((t) => {
|
|
936
972
|
s.onloadedmetadata = () => {
|
|
@@ -944,17 +980,17 @@ const re = {
|
|
|
944
980
|
};
|
|
945
981
|
typeof e.requestVideoFrameCallback == "function" ? e.requestVideoFrameCallback(r) : requestAnimationFrame(() => requestAnimationFrame(() => r()));
|
|
946
982
|
}), s;
|
|
947
|
-
},
|
|
948
|
-
const s = new
|
|
949
|
-
return s.colorSpace =
|
|
950
|
-
},
|
|
983
|
+
}, mt = (n) => {
|
|
984
|
+
const s = new ge(n);
|
|
985
|
+
return s.colorSpace = Ve, s.format = le, s.minFilter = G, s.magFilter = G, s.generateMipmaps = !1, s.needsUpdate = !0, s;
|
|
986
|
+
}, ft = (n, s) => {
|
|
951
987
|
const e = n.videoWidth, t = n.videoHeight;
|
|
952
988
|
e > 0 && t > 0 && (s.width !== e && (s.width = e), s.height !== t && (s.height = t));
|
|
953
989
|
const i = s.getContext("2d", {
|
|
954
990
|
colorSpace: "srgb"
|
|
955
991
|
});
|
|
956
992
|
i.save(), i.scale(-1, 1), i.drawImage(n, -s.width, 0, s.width, s.height), i.restore();
|
|
957
|
-
},
|
|
993
|
+
}, pt = (n, s, e = 1) => {
|
|
958
994
|
const t = s.getContext("2d", {
|
|
959
995
|
colorSpace: "srgb"
|
|
960
996
|
}), i = s.width / s.height, r = n.width / n.height;
|
|
@@ -974,7 +1010,7 @@ const re = {
|
|
|
974
1010
|
o,
|
|
975
1011
|
u
|
|
976
1012
|
);
|
|
977
|
-
},
|
|
1013
|
+
}, wt = (n) => {
|
|
978
1014
|
switch (n instanceof DOMException ? n.name : "") {
|
|
979
1015
|
case "NotAllowedError":
|
|
980
1016
|
case "PermissionDeniedError":
|
|
@@ -991,13 +1027,13 @@ const re = {
|
|
|
991
1027
|
default:
|
|
992
1028
|
return n instanceof TypeError ? "unsupported" : "unknown";
|
|
993
1029
|
}
|
|
994
|
-
},
|
|
1030
|
+
}, vt = {
|
|
995
1031
|
"permission-denied": "Camera access was blocked. Allow camera permissions in your browser, then refresh.",
|
|
996
1032
|
"camera-in-use": "Camera is already in use by another app or browser tab. Close it and refresh.",
|
|
997
1033
|
"no-camera": "No camera was found on this device.",
|
|
998
1034
|
unsupported: "Unable to access camera. Allow camera permissions in your browser, then refresh.",
|
|
999
1035
|
unknown: "Unable to access camera. Allow camera permissions in your browser, then refresh."
|
|
1000
|
-
},
|
|
1036
|
+
}, Ct = (n, s, e) => {
|
|
1001
1037
|
const t = /* @__PURE__ */ new Map();
|
|
1002
1038
|
let i = !1;
|
|
1003
1039
|
const r = (l, f) => {
|
|
@@ -1015,18 +1051,18 @@ const re = {
|
|
|
1015
1051
|
const k = s[l];
|
|
1016
1052
|
if (!k)
|
|
1017
1053
|
throw new Error(`Invalid model: ${l}`);
|
|
1018
|
-
const C = new k(), L = /* @__PURE__ */ new Set([f]), U = /* @__PURE__ */ new Set([f]),
|
|
1054
|
+
const C = new k(), L = /* @__PURE__ */ new Set([f]), U = /* @__PURE__ */ new Set([f]), D = (async () => {
|
|
1019
1055
|
await C.initialize(v);
|
|
1020
1056
|
const B = t.get(l);
|
|
1021
1057
|
if (!B || B.model !== C || B.refs.size === 0)
|
|
1022
1058
|
return r(l, C), C;
|
|
1023
1059
|
e && await e(l, C);
|
|
1024
1060
|
const T = t.get(l);
|
|
1025
|
-
return T && T.refs.size > 0 && n.setPipeline((
|
|
1061
|
+
return T && T.refs.size > 0 && n.setPipeline((_) => _.set(l, C)), C;
|
|
1026
1062
|
})();
|
|
1027
|
-
return p = { model: C, refs: L, activeRefs: U, initPromise:
|
|
1063
|
+
return p = { model: C, refs: L, activeRefs: U, initPromise: D, options: v }, t.set(l, p), D.catch(() => {
|
|
1028
1064
|
t.get(l) === p && (t.delete(l), n.setPipeline((T) => T.delete(l))), r(l, C);
|
|
1029
|
-
}),
|
|
1065
|
+
}), D;
|
|
1030
1066
|
}, release: (l, f) => {
|
|
1031
1067
|
const v = t.get(l);
|
|
1032
1068
|
v && (v.refs.delete(f), v.activeRefs.delete(f) && v.refs.size > 0 && v.activeRefs.size === 0 && v.model.pause(), !(v.refs.size > 0) && (t.delete(l), r(l, v.model), n.setPipeline((p) => p.delete(l))));
|
|
@@ -1058,7 +1094,7 @@ const re = {
|
|
|
1058
1094
|
}
|
|
1059
1095
|
n.setPipeline((l) => l.clear());
|
|
1060
1096
|
} };
|
|
1061
|
-
},
|
|
1097
|
+
}, St = {
|
|
1062
1098
|
lifecycle: "idle",
|
|
1063
1099
|
ready: !1,
|
|
1064
1100
|
error: void 0,
|
|
@@ -1068,8 +1104,8 @@ const re = {
|
|
|
1068
1104
|
source: void 0,
|
|
1069
1105
|
sourceKind: void 0,
|
|
1070
1106
|
pipeline: /* @__PURE__ */ new Map()
|
|
1071
|
-
},
|
|
1072
|
-
let n = { ...
|
|
1107
|
+
}, kt = () => {
|
|
1108
|
+
let n = { ...St, pipeline: /* @__PURE__ */ new Map() };
|
|
1073
1109
|
const s = /* @__PURE__ */ new Set(), e = () => {
|
|
1074
1110
|
s.forEach((t) => t());
|
|
1075
1111
|
};
|
|
@@ -1092,7 +1128,7 @@ const re = {
|
|
|
1092
1128
|
s.delete(t);
|
|
1093
1129
|
})
|
|
1094
1130
|
};
|
|
1095
|
-
},
|
|
1131
|
+
}, yt = ({
|
|
1096
1132
|
renderHeight: n,
|
|
1097
1133
|
renderWidth: s,
|
|
1098
1134
|
videoHeight: e,
|
|
@@ -1100,8 +1136,8 @@ const re = {
|
|
|
1100
1136
|
}) => ({
|
|
1101
1137
|
height: n || e,
|
|
1102
1138
|
width: s || t
|
|
1103
|
-
}),
|
|
1104
|
-
const s = new
|
|
1139
|
+
}), Mt = (n) => {
|
|
1140
|
+
const s = new Ne({ verbose: !0 }), e = kt();
|
|
1105
1141
|
let t = n;
|
|
1106
1142
|
const i = (a) => {
|
|
1107
1143
|
var g;
|
|
@@ -1112,9 +1148,9 @@ const re = {
|
|
|
1112
1148
|
const C = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set(), U = (a) => {
|
|
1113
1149
|
const c = e.getSnapshot().cameraTexture;
|
|
1114
1150
|
c && c.dispose();
|
|
1115
|
-
const g =
|
|
1151
|
+
const g = mt(a);
|
|
1116
1152
|
return e.set({ cameraTexture: g }), g;
|
|
1117
|
-
},
|
|
1153
|
+
}, D = async (a, c) => {
|
|
1118
1154
|
if (C.has(a) || e.getSnapshot().lifecycle !== "running" || !d) return;
|
|
1119
1155
|
C.add(a);
|
|
1120
1156
|
const g = k;
|
|
@@ -1129,14 +1165,14 @@ const re = {
|
|
|
1129
1165
|
} catch (w) {
|
|
1130
1166
|
throw C.delete(a), w;
|
|
1131
1167
|
}
|
|
1132
|
-
}, T =
|
|
1168
|
+
}, T = Ct(e, ce, (a, c) => D(a, c));
|
|
1133
1169
|
e.subscribe(() => {
|
|
1134
1170
|
if (e.getSnapshot().lifecycle !== "running") return;
|
|
1135
1171
|
const a = e.getSnapshot().pipeline;
|
|
1136
1172
|
for (const [c, g] of a.entries())
|
|
1137
|
-
C.has(c) ||
|
|
1173
|
+
C.has(c) || D(c, g);
|
|
1138
1174
|
});
|
|
1139
|
-
const
|
|
1175
|
+
const _ = () => {
|
|
1140
1176
|
if (f !== void 0 && (cancelAnimationFrame(f), f = void 0), o) {
|
|
1141
1177
|
try {
|
|
1142
1178
|
o.pause();
|
|
@@ -1155,31 +1191,31 @@ const re = {
|
|
|
1155
1191
|
}
|
|
1156
1192
|
u = void 0;
|
|
1157
1193
|
}
|
|
1158
|
-
},
|
|
1194
|
+
}, W = () => {
|
|
1159
1195
|
if (v || !o || !m || !d) return;
|
|
1160
1196
|
const a = window.__xr_debugger_metrics;
|
|
1161
1197
|
if (a != null && a.trackCameraFrame && a.trackCameraFrame(), (e.getSnapshot().sourceKind ?? "webcam") === "webcam")
|
|
1162
|
-
|
|
1198
|
+
ft(o, m);
|
|
1163
1199
|
else {
|
|
1164
1200
|
const w = m.getContext("2d");
|
|
1165
1201
|
if (!w) return;
|
|
1166
1202
|
const y = o.videoWidth, A = o.videoHeight;
|
|
1167
1203
|
m.width !== y && (m.width = y), m.height !== A && (m.height = A), w.setTransform(1, 0, 0, 1, 0, 0), w.clearRect(0, 0, y, A), w.drawImage(o, 0, 0, y, A);
|
|
1168
1204
|
}
|
|
1169
|
-
|
|
1205
|
+
pt(m, d, (t == null ? void 0 : t.cameraZoom) ?? 1.2);
|
|
1170
1206
|
const g = e.getSnapshot().cameraTexture;
|
|
1171
1207
|
g && (g.needsUpdate = !0);
|
|
1172
|
-
},
|
|
1208
|
+
}, te = () => {
|
|
1173
1209
|
if (!o || !m || !d) return;
|
|
1174
1210
|
if (p) {
|
|
1175
|
-
|
|
1211
|
+
W();
|
|
1176
1212
|
return;
|
|
1177
1213
|
}
|
|
1178
1214
|
const a = () => {
|
|
1179
|
-
f = requestAnimationFrame(a),
|
|
1215
|
+
f = requestAnimationFrame(a), W();
|
|
1180
1216
|
};
|
|
1181
1217
|
f = requestAnimationFrame(a);
|
|
1182
|
-
},
|
|
1218
|
+
}, ve = async (a) => {
|
|
1183
1219
|
if (a.source === F.WEBCAM)
|
|
1184
1220
|
try {
|
|
1185
1221
|
const c = t != null && t.camRes && t.camRes > 0 ? t.camRes : 960;
|
|
@@ -1191,34 +1227,34 @@ const re = {
|
|
|
1191
1227
|
}
|
|
1192
1228
|
});
|
|
1193
1229
|
} catch (c) {
|
|
1194
|
-
const g =
|
|
1230
|
+
const g = wt(c), w = vt[g];
|
|
1195
1231
|
throw e.set({ error: { error: "PermissionError", message: w, reason: g } }), new b(c instanceof Error ? c.message : "getUserMedia failed");
|
|
1196
1232
|
}
|
|
1197
1233
|
return a.stream;
|
|
1198
|
-
},
|
|
1199
|
-
const c = await
|
|
1234
|
+
}, X = async (a) => {
|
|
1235
|
+
const c = await ve(a);
|
|
1200
1236
|
u = c;
|
|
1201
|
-
const g = await
|
|
1237
|
+
const g = await gt(c);
|
|
1202
1238
|
o = g, m = new OffscreenCanvas(g.videoWidth, g.videoHeight);
|
|
1203
|
-
const { renderWidth: w, renderHeight: y } = e.getSnapshot(), A =
|
|
1239
|
+
const { renderWidth: w, renderHeight: y } = e.getSnapshot(), A = yt({
|
|
1204
1240
|
renderWidth: w,
|
|
1205
1241
|
renderHeight: y,
|
|
1206
1242
|
videoWidth: g.videoWidth,
|
|
1207
1243
|
videoHeight: g.videoHeight
|
|
1208
1244
|
});
|
|
1209
1245
|
d ? (d.width !== A.width || d.height !== A.height) && (d.width = A.width, d.height = A.height, U(d)) : (d = new OffscreenCanvas(A.width, A.height), U(d));
|
|
1210
|
-
const
|
|
1211
|
-
p =
|
|
1246
|
+
const ie = a.source === F.STREAM ? a.static === !0 : !1;
|
|
1247
|
+
p = ie, r = a.source === F.WEBCAM ? { source: F.WEBCAM, sourceKind: "webcam" } : {
|
|
1212
1248
|
source: F.STREAM,
|
|
1213
1249
|
stream: a.stream,
|
|
1214
|
-
static:
|
|
1250
|
+
static: ie,
|
|
1215
1251
|
sourceKind: a.sourceKind ?? "webcam"
|
|
1216
1252
|
}, e.set({
|
|
1217
1253
|
source: a.source,
|
|
1218
1254
|
sourceKind: r.sourceKind,
|
|
1219
1255
|
error: void 0
|
|
1220
1256
|
});
|
|
1221
|
-
},
|
|
1257
|
+
}, j = async (a) => {
|
|
1222
1258
|
const c = a.sourceKind ?? "webcam";
|
|
1223
1259
|
d = a.canvas;
|
|
1224
1260
|
const g = U(d);
|
|
@@ -1234,48 +1270,48 @@ const re = {
|
|
|
1234
1270
|
canvas: a.canvas,
|
|
1235
1271
|
sourceKind: c
|
|
1236
1272
|
};
|
|
1237
|
-
},
|
|
1273
|
+
}, Ce = (a, c) => !c || a.source !== c.source ? !1 : a.source === F.STREAM && c.source === F.STREAM ? a.stream === c.stream && (a.sourceKind ?? "webcam") === c.sourceKind : !0, Se = async () => {
|
|
1238
1274
|
if (!d) return;
|
|
1239
1275
|
const a = k, c = e.getSnapshot().pipeline;
|
|
1240
1276
|
for (const [, g] of c.entries())
|
|
1241
1277
|
g.resume();
|
|
1242
1278
|
await new Promise((g) => requestAnimationFrame(() => g())), await new Promise((g) => requestAnimationFrame(() => g())), p && k === a && T.suspendAll();
|
|
1243
|
-
},
|
|
1279
|
+
}, ke = (a, c) => !c || c.source !== F.CANVAS ? !1 : a.canvas === c.canvas && (a.sourceKind ?? "webcam") === c.sourceKind, ye = async (a) => {
|
|
1244
1280
|
const c = a.source;
|
|
1245
1281
|
if (c !== F.WEBCAM && c !== F.STREAM)
|
|
1246
1282
|
throw new b(`Invalid media source: ${String(c)}`);
|
|
1247
|
-
if (
|
|
1283
|
+
if (Ce(a, r)) {
|
|
1248
1284
|
s.log("Media source unchanged, skipping rebind.");
|
|
1249
1285
|
return;
|
|
1250
1286
|
}
|
|
1251
1287
|
k += 1;
|
|
1252
1288
|
const { lifecycle: g } = e.getSnapshot();
|
|
1253
1289
|
if (g === "idle" || g === "stopped") {
|
|
1254
|
-
await
|
|
1290
|
+
await X(a), e.set({ lifecycle: "media-bound" }), s.log("Media source set to:", a.source);
|
|
1255
1291
|
return;
|
|
1256
1292
|
}
|
|
1257
1293
|
if (g === "media-bound") {
|
|
1258
|
-
|
|
1294
|
+
_(), await X(a), s.log("Media source rebound to:", a.source);
|
|
1259
1295
|
return;
|
|
1260
1296
|
}
|
|
1261
|
-
v = !0, await new Promise((w) => requestAnimationFrame(() => w())),
|
|
1262
|
-
},
|
|
1263
|
-
if (
|
|
1297
|
+
v = !0, await new Promise((w) => requestAnimationFrame(() => w())), _(), await X(a), v = !1, te(), p ? await Se() : T.resumeActive(), s.log("Media source swapped to:", a.source);
|
|
1298
|
+
}, Me = async (a) => {
|
|
1299
|
+
if (ke(a, r)) {
|
|
1264
1300
|
s.log("Frame source unchanged, skipping rebind.");
|
|
1265
1301
|
return;
|
|
1266
1302
|
}
|
|
1267
1303
|
k += 1;
|
|
1268
1304
|
const { lifecycle: c } = e.getSnapshot();
|
|
1269
1305
|
if (c === "idle" || c === "stopped") {
|
|
1270
|
-
await
|
|
1306
|
+
await j(a), e.set({ lifecycle: "media-bound" }), s.log("Frame source set to canvas.");
|
|
1271
1307
|
return;
|
|
1272
1308
|
}
|
|
1273
1309
|
if (c === "media-bound") {
|
|
1274
|
-
|
|
1310
|
+
_(), await j(a), s.log("Frame source rebound to canvas.");
|
|
1275
1311
|
return;
|
|
1276
1312
|
}
|
|
1277
|
-
v = !0, await new Promise((g) => requestAnimationFrame(() => g())),
|
|
1278
|
-
},
|
|
1313
|
+
v = !0, await new Promise((g) => requestAnimationFrame(() => g())), _(), await j(a), v = !1, s.log("Frame source swapped to canvas.");
|
|
1314
|
+
}, Re = async () => {
|
|
1279
1315
|
const { lifecycle: a } = e.getSnapshot();
|
|
1280
1316
|
if (a === "running") return;
|
|
1281
1317
|
if (a === "idle")
|
|
@@ -1287,49 +1323,49 @@ const re = {
|
|
|
1287
1323
|
throw a === "stopped" ? new b(
|
|
1288
1324
|
"session.start() called from stopped state without a media source — call setMediaSource first"
|
|
1289
1325
|
) : new b("session.start(): media source not bound");
|
|
1290
|
-
c ||
|
|
1326
|
+
c || te(), T.resumeActive(), e.set({ lifecycle: "running" }), await new Promise((w) => requestAnimationFrame(() => w()));
|
|
1291
1327
|
const g = e.getSnapshot().pipeline;
|
|
1292
1328
|
for (const [w, y] of g.entries())
|
|
1293
|
-
await
|
|
1329
|
+
await D(w, y);
|
|
1294
1330
|
e.set({ ready: !0 }), s.log("XR session started.");
|
|
1295
|
-
},
|
|
1331
|
+
}, se = async () => {
|
|
1296
1332
|
const { lifecycle: a } = e.getSnapshot();
|
|
1297
|
-
a === "stopped" || a === "idle" || (
|
|
1298
|
-
},
|
|
1299
|
-
await
|
|
1333
|
+
a === "stopped" || a === "idle" || (_(), T.suspendAll(), e.set({ lifecycle: "stopped", ready: !1 }), s.log("XR session stopped."));
|
|
1334
|
+
}, Te = async () => {
|
|
1335
|
+
await se(), T.releaseAll(), L.clear();
|
|
1300
1336
|
const a = e.getSnapshot().cameraTexture;
|
|
1301
1337
|
a && a.dispose(), C.clear(), r = void 0, k += 1, d = void 0, m = void 0, p = !1, e.set({
|
|
1302
1338
|
lifecycle: "idle",
|
|
1303
1339
|
cameraTexture: void 0,
|
|
1304
1340
|
source: void 0
|
|
1305
1341
|
}), s.log("XR session reset.");
|
|
1306
|
-
},
|
|
1342
|
+
}, xe = async (a) => {
|
|
1307
1343
|
const c = "legacy:registerXRPipeline", g = [];
|
|
1308
1344
|
await Promise.all(
|
|
1309
1345
|
a.map(async (w) => {
|
|
1310
1346
|
const { model: y } = w;
|
|
1311
|
-
if (!
|
|
1347
|
+
if (!ce[y])
|
|
1312
1348
|
throw new b(`Invalid model: ${y}`);
|
|
1313
1349
|
L.has(y) || g.push(y);
|
|
1314
1350
|
const A = "options" in w ? w.options : void 0;
|
|
1315
1351
|
await T.acquire(y, c, A);
|
|
1316
1352
|
})
|
|
1317
1353
|
), g.length > 0 && (g.forEach((w) => L.add(w)), s.log("XR pipeline registered."));
|
|
1318
|
-
},
|
|
1354
|
+
}, Fe = (a) => {
|
|
1319
1355
|
const c = T.get(a);
|
|
1320
1356
|
if (!c)
|
|
1321
1357
|
throw new b(`Model ${a} is not registered in the pipeline`);
|
|
1322
1358
|
return c.getModelNode();
|
|
1323
|
-
},
|
|
1324
|
-
a <= 0 || c <= 0 || (e.set({ renderWidth: a, renderHeight: c }), d && (d.width !== a || d.height !== c) && (d.width = a, d.height = c, U(d), p &&
|
|
1325
|
-
},
|
|
1359
|
+
}, ne = async (a, c) => {
|
|
1360
|
+
a <= 0 || c <= 0 || (e.set({ renderWidth: a, renderHeight: c }), d && (d.width !== a || d.height !== c) && (d.width = a, d.height = c, U(d), p && W()), s.log(`Source canvas set. Render size: ${a}x${c}`));
|
|
1361
|
+
}, Ae = async (a) => {
|
|
1326
1362
|
var y;
|
|
1327
1363
|
S = a;
|
|
1328
1364
|
const c = (y = a.getBoundingClientRect) == null ? void 0 : y.call(a), g = c && c.width > 0 ? Math.round(c.width) : a.clientWidth, w = c && c.height > 0 ? Math.round(c.height) : a.clientHeight;
|
|
1329
|
-
await
|
|
1330
|
-
},
|
|
1365
|
+
await ne(g, w);
|
|
1366
|
+
}, be = (a) => {
|
|
1331
1367
|
R = a.renderer, M = a.scene, x = a.camera, l = a.renderFrame;
|
|
1332
|
-
},
|
|
1368
|
+
}, ae = () => {
|
|
1333
1369
|
if (!R || !M || !x)
|
|
1334
1370
|
throw new b(
|
|
1335
1371
|
"XR frame render requested before the R3F state was bound — make sure <XRScene> is mounted"
|
|
@@ -1339,13 +1375,13 @@ const re = {
|
|
|
1339
1375
|
return {
|
|
1340
1376
|
store: e,
|
|
1341
1377
|
registry: T,
|
|
1342
|
-
setMediaSource:
|
|
1343
|
-
start:
|
|
1344
|
-
stop:
|
|
1345
|
-
reset:
|
|
1346
|
-
setFrameSource:
|
|
1347
|
-
registerXRPipeline:
|
|
1348
|
-
getModelNode:
|
|
1378
|
+
setMediaSource: ye,
|
|
1379
|
+
start: Re,
|
|
1380
|
+
stop: se,
|
|
1381
|
+
reset: Te,
|
|
1382
|
+
setFrameSource: Me,
|
|
1383
|
+
registerXRPipeline: xe,
|
|
1384
|
+
getModelNode: Fe,
|
|
1349
1385
|
captureFrame: () => {
|
|
1350
1386
|
if (!S)
|
|
1351
1387
|
throw new b(
|
|
@@ -1355,13 +1391,13 @@ const re = {
|
|
|
1355
1391
|
throw new b(
|
|
1356
1392
|
"session.captureFrame() called before the R3F state was bound — make sure <XRScene> is mounted"
|
|
1357
1393
|
);
|
|
1358
|
-
return
|
|
1394
|
+
return ae(), S.toDataURL("image/png");
|
|
1359
1395
|
},
|
|
1360
1396
|
getInputFrame: () => d ?? null,
|
|
1361
|
-
_setRenderTarget:
|
|
1362
|
-
_setRenderSize:
|
|
1363
|
-
_setR3FState:
|
|
1364
|
-
_renderFrame:
|
|
1397
|
+
_setRenderTarget: Ae,
|
|
1398
|
+
_setRenderSize: ne,
|
|
1399
|
+
_setR3FState: be,
|
|
1400
|
+
_renderFrame: ae,
|
|
1365
1401
|
_getVideoElement: () => o,
|
|
1366
1402
|
_setPerf: (a) => {
|
|
1367
1403
|
if (t = a, e.getSnapshot().lifecycle !== "running" || !d) return;
|
|
@@ -1376,46 +1412,46 @@ const re = {
|
|
|
1376
1412
|
});
|
|
1377
1413
|
}
|
|
1378
1414
|
};
|
|
1379
|
-
},
|
|
1380
|
-
const s =
|
|
1381
|
-
return
|
|
1415
|
+
}, Rt = (n) => {
|
|
1416
|
+
const s = he(n), e = J(() => Mt(s.current), []), t = JSON.stringify(n ?? {});
|
|
1417
|
+
return Pe(() => {
|
|
1382
1418
|
e._setPerf(n);
|
|
1383
1419
|
}, [e, t]), e;
|
|
1384
|
-
},
|
|
1420
|
+
}, Z = /* @__PURE__ */ new Map(), Tt = () => ({
|
|
1385
1421
|
register: (n, s) => {
|
|
1386
|
-
s ?
|
|
1422
|
+
s ? Z.set(n, s) : Z.delete(n);
|
|
1387
1423
|
},
|
|
1388
|
-
resolve: (n) => n ?
|
|
1389
|
-
}),
|
|
1390
|
-
const s =
|
|
1424
|
+
resolve: (n) => n ? Z.get(n) ?? null : null
|
|
1425
|
+
}), me = Tt(), fe = ue(null), xt = ({ children: n }) => {
|
|
1426
|
+
const s = he(/* @__PURE__ */ new Map()), e = oe((r, o) => {
|
|
1391
1427
|
o ? s.current.set(r, o) : s.current.delete(r);
|
|
1392
|
-
}, []), t =
|
|
1428
|
+
}, []), t = oe(
|
|
1393
1429
|
(r) => r ? s.current.get(r) ?? null : null,
|
|
1394
1430
|
[]
|
|
1395
|
-
), i =
|
|
1396
|
-
return
|
|
1397
|
-
},
|
|
1398
|
-
|
|
1399
|
-
const
|
|
1400
|
-
const n =
|
|
1431
|
+
), i = J(() => ({ register: e, resolve: t }), [e, t]);
|
|
1432
|
+
return De(fe.Provider, { value: i }, n);
|
|
1433
|
+
}, pe = () => de(fe) ?? me, zt = () => pe().register, Lt = () => pe().resolve;
|
|
1434
|
+
me.register;
|
|
1435
|
+
const we = ue(void 0), Bt = () => {
|
|
1436
|
+
const n = de(we);
|
|
1401
1437
|
if (!n)
|
|
1402
1438
|
throw new b(
|
|
1403
1439
|
"XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?"
|
|
1404
1440
|
);
|
|
1405
1441
|
return n;
|
|
1406
|
-
},
|
|
1407
|
-
const e =
|
|
1408
|
-
return /* @__PURE__ */
|
|
1442
|
+
}, Vt = ({ children: n, perf: s }) => {
|
|
1443
|
+
const e = Rt(s), t = J(() => ({ session: e }), [e]);
|
|
1444
|
+
return /* @__PURE__ */ re(we.Provider, { value: t, children: /* @__PURE__ */ re(xt, { children: n }) });
|
|
1409
1445
|
};
|
|
1410
1446
|
export {
|
|
1411
1447
|
z as X,
|
|
1412
|
-
|
|
1413
|
-
|
|
1448
|
+
q as a,
|
|
1449
|
+
Ut as b,
|
|
1414
1450
|
F as c,
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1451
|
+
Vt as d,
|
|
1452
|
+
Lt as e,
|
|
1453
|
+
Ge as f,
|
|
1454
|
+
zt as g,
|
|
1419
1455
|
I as l,
|
|
1420
|
-
|
|
1456
|
+
Bt as u
|
|
1421
1457
|
};
|