@vincentt-xr/sdk 2.0.0-alpha.2 → 2.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GROUNDING.md +67 -9
- package/dist/{DebuggerUI-Cq28c18s.js → DebuggerUI-DhKTXTY2.js} +1 -1
- package/dist/{DebuggerUI-B45_Gb9d.cjs → DebuggerUI-bnGHSSOb.cjs} +1 -1
- package/dist/{FaceMeshRenderer-6t8OsQhK.js → FaceMeshRenderer-B2i2NW71.js} +3 -3
- package/dist/{FaceMeshRenderer-lQLhYIW-.cjs → FaceMeshRenderer-BSOq1OnG.cjs} +1 -1
- package/dist/{FaceRetouch-CDrL0pXg.js → FaceRetouch-Bg-OBU4n.js} +30 -30
- package/dist/{FaceRetouch-DtNl8-4e.cjs → FaceRetouch-TZeBGIqW.cjs} +1 -1
- package/dist/components/MeshRenderer/index.d.ts +1 -0
- package/dist/components/ScreenImage/source.d.ts +3 -0
- package/dist/contexts-B2_NsTnk.js +660 -0
- package/dist/contexts-BgWfyxre.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 +3 -3
- package/dist/debug-ui.js +1246 -1205
- package/dist/entries/low-level.d.ts +5 -0
- package/dist/face-effects.cjs +1 -1
- package/dist/face-effects.js +4 -4
- package/dist/{getFaceInfo-hUKMLFcr.js → getFaceInfo-4DhcPZDJ.js} +1 -1
- package/dist/{getFaceInfo-CyPAKh3h.cjs → getFaceInfo-QOQ_dc-W.cjs} +1 -1
- package/dist/hooks/selectors.d.ts +2 -4
- package/dist/hooks/useXRModel.d.ts +5 -0
- package/dist/hooks/useXRSession/reason.d.ts +19 -0
- package/dist/hooks/useXRSession/store.d.ts +12 -4
- package/dist/index-72Wb15Ca.js +214 -0
- package/dist/{index-JygePOwo.js → index-BMeBJ0dV.js} +322 -299
- package/dist/index-C9yQVzAh.cjs +1 -0
- package/dist/index-CNGzE49z.cjs +17 -0
- package/dist/{index-Di70KWuY.js → index-Cj3fGDtZ.js} +844 -825
- package/dist/{index-BgQAX8rs.js → index-D1kj6uc-.js} +123 -120
- package/dist/{index-D4bLzBr6.cjs → index-Da7uycur.cjs} +1 -1
- package/dist/{index-DSpzjuqd.cjs → index-WPPnlFO1.cjs} +1 -1
- package/dist/index-ZaDEzDtR.cjs +1 -0
- package/dist/{index-UC0Ux38E.js → index-g250Tqme.js} +1 -1
- package/dist/{internal-DuMPpcbp.js → internal-34pb7djs.js} +3 -3
- package/dist/{internal-i2JkM85N.cjs → internal-Dtvo4WYo.cjs} +1 -1
- package/dist/internal.cjs +1 -1
- package/dist/internal.js +1 -1
- package/dist/low-level.cjs +1 -1
- package/dist/low-level.js +399 -490
- package/dist/main.cjs +1 -1
- package/dist/main.js +28 -28
- package/dist/{renderGroups-C9QJrAXu.js → renderGroups-CPWUX6z9.js} +1 -1
- package/dist/{renderGroups-Dvm1J4lW.cjs → renderGroups-jSUOY1Oq.cjs} +1 -1
- package/dist/{renderPasses-CjgG_6kQ.js → renderPasses-CLlYRdMk.js} +5 -5
- package/dist/{renderPasses-CT5iBwtg.cjs → renderPasses-KUJUSevp.cjs} +2 -2
- package/dist/scene-object.cjs +1 -1
- package/dist/scene-object.js +2 -2
- package/dist/{selectors-Dw3C-gSk.js → selectors-DLxL8Q66.js} +4 -4
- package/dist/{selectors-2QvO5RYY.cjs → selectors-S8g25ke9.cjs} +1 -1
- package/dist/{session-C1StwN0f.js → session-CbtvwiaD.js} +1 -1
- package/dist/{session-BChR4TgK.cjs → session-DP8AF7Rg.cjs} +1 -1
- package/dist/texture/animatedTexture.d.ts +2 -0
- package/dist/texture/gifReader.d.ts +17 -0
- package/dist/texture/gifTextureSource.d.ts +16 -0
- package/dist/tracking.cjs +1 -1
- package/dist/tracking.js +9 -9
- package/dist/{useFaceInfo-C-WfMlYp.cjs → useFaceInfo-BvZeUBsL.cjs} +1 -1
- package/dist/{useFaceInfo-CwsHZedC.js → useFaceInfo-C06EyScd.js} +3 -3
- package/dist/{useFaceResults-CkFc1egZ.js → useFaceResults-C1Ppc8rS.js} +1 -1
- package/dist/{useFaceResults-VcFdOUFV.cjs → useFaceResults-CCNiH7VZ.cjs} +1 -1
- package/docs/api/screen-image.mdx +27 -3
- package/docs/api/texture-sources.mdx +25 -6
- package/docs/texture-api-consumer.md +26 -0
- package/package.json +4 -3
- package/dist/contexts-BKvTIayr.cjs +0 -1
- package/dist/contexts-Bk5zz_VR.js +0 -214
- package/dist/index-82aENaRq.cjs +0 -1
- package/dist/index-CEc1CAmB.cjs +0 -1
- package/dist/index-CTHeBQOs.js +0 -178
- package/dist/index-DzEzkBIH.cjs +0 -17
|
@@ -1,58 +1,61 @@
|
|
|
1
1
|
import { jsx as _, jsxs as w } from "react/jsx-runtime";
|
|
2
2
|
import { useThree as k, useFrame as U } from "@react-three/fiber";
|
|
3
|
-
import
|
|
4
|
-
import { u as $, a as e0, X as P, b as t0 } from "./index-
|
|
5
|
-
import { R as
|
|
3
|
+
import z, { useId as B, useState as W, useRef as A, useEffect as F, useSyncExternalStore as q, useMemo as v, useContext as G, createContext as J, useCallback as Q } from "react";
|
|
4
|
+
import { u as $, a as e0, X as P, b as t0 } from "./index-BMeBJ0dV.js";
|
|
5
|
+
import { R as n0 } from "./renderLayers-zrK2pv5O.js";
|
|
6
6
|
import * as T from "three";
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
function r0(e) {
|
|
8
|
+
return JSON.stringify(e ?? {});
|
|
9
|
+
}
|
|
10
|
+
function j(e, t, r = !0) {
|
|
11
|
+
const { session: n } = $(), s = B(), [i, f] = W(null), u = r0(t), o = A(t);
|
|
12
|
+
o.current = t, F(() => {
|
|
13
|
+
let c = !1;
|
|
14
|
+
return f(null), n.registry.acquire(e, s, o.current).catch((l) => {
|
|
15
|
+
c || f(l instanceof Error ? l : new Error(String(l)));
|
|
13
16
|
}), () => {
|
|
14
|
-
|
|
17
|
+
c = !0, n.registry.release(e, s);
|
|
15
18
|
};
|
|
16
|
-
}, [
|
|
17
|
-
|
|
18
|
-
}, [
|
|
19
|
-
const
|
|
20
|
-
(
|
|
21
|
-
() =>
|
|
19
|
+
}, [n, e, s, u]), F(() => {
|
|
20
|
+
n.registry.setActive(e, s, r);
|
|
21
|
+
}, [n, e, s, r]);
|
|
22
|
+
const d = n.store, h = q(
|
|
23
|
+
(c) => d.subscribe(c),
|
|
24
|
+
() => d.getSnapshot().pipeline.get(e) ?? null,
|
|
22
25
|
() => null
|
|
23
|
-
),
|
|
26
|
+
), p = v(() => h ? h.getModelNode() : null, [h]);
|
|
24
27
|
return {
|
|
25
|
-
ready:
|
|
26
|
-
node:
|
|
28
|
+
ready: h !== null && i === null,
|
|
29
|
+
node: p,
|
|
27
30
|
error: i
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
|
-
const
|
|
33
|
+
const s0 = ({ materialProps: e, settings: t }) => t.type === "basic" ? /* @__PURE__ */ _("meshBasicMaterial", { ...e }) : /* @__PURE__ */ _(
|
|
31
34
|
"meshStandardMaterial",
|
|
32
35
|
{
|
|
33
36
|
...e,
|
|
34
37
|
roughness: t.roughness,
|
|
35
38
|
metalness: t.metalness
|
|
36
39
|
}
|
|
37
|
-
), g = 1e-6,
|
|
38
|
-
const { x: t, y:
|
|
39
|
-
return Math.abs(t -
|
|
40
|
-
},
|
|
41
|
-
if (!
|
|
42
|
-
const s =
|
|
43
|
-
return
|
|
44
|
-
},
|
|
45
|
-
const
|
|
46
|
-
return
|
|
47
|
-
},
|
|
40
|
+
), g = 1e-6, o0 = (e) => {
|
|
41
|
+
const { x: t, y: r, z: n } = e.scale;
|
|
42
|
+
return Math.abs(t - r) <= g && Math.abs(t - n) <= g ? t : 1;
|
|
43
|
+
}, R0 = (e, t, r, n) => {
|
|
44
|
+
if (!r.enabled) return e;
|
|
45
|
+
const s = o0(r);
|
|
46
|
+
return n.x = t.x + (e.x - t.x) * s + r.position.x, n.y = t.y + (e.y - t.y) * s - r.position.y, n.z = t.z + (e.z - t.z) * s + r.position.z, n;
|
|
47
|
+
}, c0 = (e, t, r) => e0(e, t, r), b0 = (e, t, r) => {
|
|
48
|
+
const n = (e.x - 0.5) * 2, s = (0.5 - e.y) * 2, i = T.MathUtils.clamp(e.z * 2, -1, 1);
|
|
49
|
+
return r.set(n, s, i).unproject(t);
|
|
50
|
+
}, i0 = (e, t, r, n, s, i) => {
|
|
48
51
|
const f = Math.min(t, e.length);
|
|
49
52
|
for (let u = 0; u < f; u++) {
|
|
50
|
-
s(e[u],
|
|
53
|
+
s(e[u], n, i);
|
|
51
54
|
const o = u * 3;
|
|
52
|
-
|
|
55
|
+
r[o] = i.x, r[o + 1] = i.y, r[o + 2] = i.z;
|
|
53
56
|
}
|
|
54
57
|
return f;
|
|
55
|
-
},
|
|
58
|
+
}, a0 = [
|
|
56
59
|
[127, 34, 139],
|
|
57
60
|
[11, 0, 37],
|
|
58
61
|
[232, 231, 120],
|
|
@@ -906,7 +909,7 @@ const n0 = ({ materialProps: e, settings: t }) => t.type === "basic" ? /* @__PUR
|
|
|
906
909
|
[390, 339, 249],
|
|
907
910
|
[339, 448, 255],
|
|
908
911
|
[255, 339, 448]
|
|
909
|
-
].flat(),
|
|
912
|
+
].flat(), u0 = [
|
|
910
913
|
0.5104879319667817,
|
|
911
914
|
0.33515610277652746,
|
|
912
915
|
0.5174233198165894,
|
|
@@ -1863,7 +1866,7 @@ const n0 = ({ materialProps: e, settings: t }) => t.type === "basic" ? /* @__PUR
|
|
|
1863
1866
|
0.618020570576191,
|
|
1864
1867
|
0.33353258967399596,
|
|
1865
1868
|
0.5936576622724534
|
|
1866
|
-
], H = 468,
|
|
1869
|
+
], H = 468, l0 = H * 3, f0 = {
|
|
1867
1870
|
type: "standard",
|
|
1868
1871
|
color: "#ffffff",
|
|
1869
1872
|
opacity: 1,
|
|
@@ -1873,51 +1876,51 @@ const n0 = ({ materialProps: e, settings: t }) => t.type === "basic" ? /* @__PUR
|
|
|
1873
1876
|
}, K = ({
|
|
1874
1877
|
material: e,
|
|
1875
1878
|
faceIndex: t = 0,
|
|
1876
|
-
numFaces:
|
|
1877
|
-
visible:
|
|
1879
|
+
numFaces: r,
|
|
1880
|
+
visible: n = !0,
|
|
1878
1881
|
children: s
|
|
1879
1882
|
}) => {
|
|
1880
1883
|
const { ready: i, node: f } = j(
|
|
1881
1884
|
P.FACE_TRACKER,
|
|
1882
|
-
|
|
1883
|
-
), { camera: u } = k(), o =
|
|
1884
|
-
const
|
|
1885
|
-
return a.setUsage(T.DynamicDrawUsage), { indexAttr:
|
|
1885
|
+
r === void 0 ? void 0 : { numFaces: r }
|
|
1886
|
+
), { camera: u } = k(), o = A(null), d = A(null), h = A(null), p = A(null), c = A(null), l = A(new T.Vector3()), E = v(() => {
|
|
1887
|
+
const m = new Uint16Array(a0), x = new T.BufferAttribute(m, 1), y = new T.Float32BufferAttribute(u0, 2), R = new Float32Array(l0), a = new T.Float32BufferAttribute(R, 3);
|
|
1888
|
+
return a.setUsage(T.DynamicDrawUsage), { indexAttr: x, uvAttr: y, positionAttr: a, positions: R };
|
|
1886
1889
|
}, []);
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
const
|
|
1890
|
-
if (
|
|
1891
|
-
const
|
|
1892
|
-
|
|
1890
|
+
F(() => {
|
|
1891
|
+
p.current = E.indexAttr, c.current = E.uvAttr, h.current = E.positionAttr, d.current = E.positions;
|
|
1892
|
+
const m = o.current;
|
|
1893
|
+
if (m) {
|
|
1894
|
+
const x = m.geometry;
|
|
1895
|
+
x.setAttribute("position", E.positionAttr), x.setAttribute("uv", E.uvAttr), x.setIndex(E.indexAttr);
|
|
1893
1896
|
}
|
|
1894
1897
|
return () => {
|
|
1895
|
-
|
|
1898
|
+
p.current = null, c.current = null, h.current = null, d.current = null;
|
|
1896
1899
|
};
|
|
1897
|
-
}, [
|
|
1898
|
-
var
|
|
1900
|
+
}, [E]), U(() => {
|
|
1901
|
+
var M;
|
|
1899
1902
|
if (!i || !f || !o.current) return;
|
|
1900
|
-
const { detectionResults:
|
|
1901
|
-
if (!
|
|
1902
|
-
|
|
1903
|
+
const { detectionResults: m } = f, x = (M = m == null ? void 0 : m.faceLandmarks) == null ? void 0 : M[t], y = o.current.geometry, R = d.current, a = h.current;
|
|
1904
|
+
if (!x || x.length === 0 || !R || !a) {
|
|
1905
|
+
y.drawRange.count !== 0 && y.setDrawRange(0, 0);
|
|
1903
1906
|
return;
|
|
1904
1907
|
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1908
|
+
y.getAttribute("position") !== a && (y.setAttribute("position", a), y.setAttribute("uv", c.current), y.setIndex(p.current)), y.drawRange.count === 0 && y.setDrawRange(0, 1 / 0), i0(
|
|
1909
|
+
x,
|
|
1907
1910
|
H,
|
|
1908
1911
|
R,
|
|
1909
1912
|
u,
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
), a.needsUpdate = !0,
|
|
1913
|
+
c0,
|
|
1914
|
+
l.current
|
|
1915
|
+
), a.needsUpdate = !0, y.computeVertexNormals();
|
|
1913
1916
|
});
|
|
1914
|
-
const
|
|
1915
|
-
return /* @__PURE__ */ w("mesh", { material: e, ref: o, visible:
|
|
1917
|
+
const S = s != null && s !== !1;
|
|
1918
|
+
return /* @__PURE__ */ w("mesh", { material: e, ref: o, visible: n, children: [
|
|
1916
1919
|
/* @__PURE__ */ _("bufferGeometry", {}),
|
|
1917
|
-
!e && !
|
|
1918
|
-
|
|
1920
|
+
!e && !S && /* @__PURE__ */ _(
|
|
1921
|
+
s0,
|
|
1919
1922
|
{
|
|
1920
|
-
settings:
|
|
1923
|
+
settings: f0,
|
|
1921
1924
|
materialProps: {
|
|
1922
1925
|
attach: "material",
|
|
1923
1926
|
transparent: !0,
|
|
@@ -1927,7 +1930,7 @@ const n0 = ({ materialProps: e, settings: t }) => t.type === "basic" ? /* @__PUR
|
|
|
1927
1930
|
}
|
|
1928
1931
|
}
|
|
1929
1932
|
),
|
|
1930
|
-
!e &&
|
|
1933
|
+
!e && S ? s : null
|
|
1931
1934
|
] });
|
|
1932
1935
|
};
|
|
1933
1936
|
K.displayName = "FaceMesh";
|
|
@@ -1942,114 +1945,114 @@ const L = {
|
|
|
1942
1945
|
"face.mouthCenter": 13,
|
|
1943
1946
|
"face.leftEarlobe": 454,
|
|
1944
1947
|
"face.rightEarlobe": 234
|
|
1945
|
-
},
|
|
1948
|
+
}, y0 = {
|
|
1946
1949
|
"face.center": [10, 152, 234, 454],
|
|
1947
1950
|
"face.leftEye": [263, 362, 387, 373],
|
|
1948
1951
|
"face.rightEye": [33, 133, 158, 145]
|
|
1949
|
-
}, V = (e, t = 0) => Number.isFinite(e) ? e : t, D = (e) => Math.max(-1, Math.min(1, V(e))),
|
|
1952
|
+
}, V = (e, t = 0) => Number.isFinite(e) ? e : t, D = (e) => Math.max(-1, Math.min(1, V(e))), d0 = { x: 0, y: 0, z: 0 }, h0 = (e, t, r = d0, n = { x: 0, y: 0, z: 0, visibility: 0 }) => {
|
|
1950
1953
|
const s = L[e];
|
|
1951
1954
|
if (s !== void 0) {
|
|
1952
1955
|
const c = t[s];
|
|
1953
|
-
return c ? Object.assign(
|
|
1956
|
+
return c ? Object.assign(n, c) : null;
|
|
1954
1957
|
}
|
|
1955
|
-
const i =
|
|
1958
|
+
const i = y0[e];
|
|
1956
1959
|
if (i) {
|
|
1957
|
-
|
|
1960
|
+
n.x = 0, n.y = 0, n.z = 0;
|
|
1958
1961
|
for (const c of i) {
|
|
1959
|
-
const
|
|
1960
|
-
if (!
|
|
1961
|
-
|
|
1962
|
+
const l = t[c];
|
|
1963
|
+
if (!l) return null;
|
|
1964
|
+
n.x += l.x, n.y += l.y, n.z += l.z;
|
|
1962
1965
|
}
|
|
1963
|
-
return
|
|
1966
|
+
return n.x /= i.length, n.y /= i.length, n.z /= i.length, n.visibility = 1, n;
|
|
1964
1967
|
}
|
|
1965
1968
|
if (e !== "face.custom" || t.length === 0) return null;
|
|
1966
|
-
let f = 1 / 0, u = 1 / 0, o = -1 / 0,
|
|
1969
|
+
let f = 1 / 0, u = 1 / 0, o = -1 / 0, d = -1 / 0, h = 0;
|
|
1967
1970
|
for (const c of t)
|
|
1968
|
-
f = Math.min(f, c.x), u = Math.min(u, c.y), o = Math.max(o, c.x),
|
|
1969
|
-
const
|
|
1970
|
-
return
|
|
1971
|
-
},
|
|
1971
|
+
f = Math.min(f, c.x), u = Math.min(u, c.y), o = Math.max(o, c.x), d = Math.max(d, c.y), h += c.z;
|
|
1972
|
+
const p = o - f;
|
|
1973
|
+
return n.x = (f + o) * 0.5 - D(r.x) * p * 0.5, n.y = (u + d) * 0.5 - D(r.y) * (d - u) * 0.5, n.z = h / t.length - V(r.z) * p, n.visibility = 1, n;
|
|
1974
|
+
}, T0 = {
|
|
1972
1975
|
left: L["face.leftEyeOuter"],
|
|
1973
1976
|
right: L["face.rightEyeOuter"]
|
|
1974
|
-
}, X = J(null),
|
|
1977
|
+
}, X = J(null), _0 = () => G(X), p0 = ({
|
|
1975
1978
|
faceIndex: e = 0,
|
|
1976
1979
|
numFaces: t,
|
|
1977
|
-
scaleWithFace:
|
|
1978
|
-
followFaceRoll:
|
|
1980
|
+
scaleWithFace: r = !1,
|
|
1981
|
+
followFaceRoll: n = !0,
|
|
1979
1982
|
targetFps: s,
|
|
1980
1983
|
active: i = !0,
|
|
1981
1984
|
children: f
|
|
1982
1985
|
}) => {
|
|
1983
|
-
const u =
|
|
1986
|
+
const u = A(!1), o = A(null), d = v(() => {
|
|
1984
1987
|
if (!(t === void 0 && s === void 0))
|
|
1985
1988
|
return {
|
|
1986
1989
|
...t === void 0 ? {} : { numFaces: t },
|
|
1987
1990
|
...s === void 0 ? {} : { targetFps: s }
|
|
1988
1991
|
};
|
|
1989
|
-
}, [t, s]), { ready:
|
|
1992
|
+
}, [t, s]), { ready: h, node: p } = j(
|
|
1990
1993
|
P.FACE_TRACKER,
|
|
1991
|
-
|
|
1994
|
+
d,
|
|
1992
1995
|
i
|
|
1993
|
-
), { camera: c } = k(),
|
|
1994
|
-
|
|
1995
|
-
const
|
|
1996
|
+
), { camera: c } = k(), l = A(c);
|
|
1997
|
+
l.current !== c && (l.current = c, u.current = !1);
|
|
1998
|
+
const E = A(null), S = A({ x: 0, y: 0, z: 0, visibility: 0 });
|
|
1996
1999
|
U(() => {
|
|
1997
|
-
if (!
|
|
1998
|
-
|
|
1999
|
-
const a =
|
|
2000
|
+
if (!h || !p || !o.current) return;
|
|
2001
|
+
E.current = p, !u.current && l.current && (p.setCamera(l.current, e), u.current = !0);
|
|
2002
|
+
const a = p.getFace(e);
|
|
2000
2003
|
if (!a) {
|
|
2001
2004
|
o.current.visible = !1;
|
|
2002
2005
|
return;
|
|
2003
2006
|
}
|
|
2004
2007
|
o.current.visible = !0;
|
|
2005
|
-
const { position:
|
|
2006
|
-
o.current.position.set(
|
|
2008
|
+
const { position: M, rotation: C, scale: b } = a.transform;
|
|
2009
|
+
o.current.position.set(M.x, M.y, M.z), o.current.rotation.set(C.x, C.y, n ? C.z : 0), r ? o.current.scale.set(b.x, b.y, b.z) : o.current.scale.set(1, 1, 1);
|
|
2007
2010
|
});
|
|
2008
|
-
const
|
|
2009
|
-
(a,
|
|
2010
|
-
var
|
|
2011
|
-
const C =
|
|
2011
|
+
const m = Q(
|
|
2012
|
+
(a, M) => {
|
|
2013
|
+
var O, I;
|
|
2014
|
+
const C = E.current, b = (I = (O = C == null ? void 0 : C.detectionResults) == null ? void 0 : O.faceLandmarks) == null ? void 0 : I[e];
|
|
2012
2015
|
if (!b || b.length === 0) return null;
|
|
2013
2016
|
const N = h0(
|
|
2014
2017
|
a,
|
|
2015
2018
|
b,
|
|
2016
|
-
|
|
2017
|
-
|
|
2019
|
+
M,
|
|
2020
|
+
S.current
|
|
2018
2021
|
);
|
|
2019
|
-
return N ? { position: t0(N,
|
|
2022
|
+
return N ? { position: t0(N, l.current) } : null;
|
|
2020
2023
|
},
|
|
2021
2024
|
[e]
|
|
2022
|
-
),
|
|
2023
|
-
() => ({ type: "face", resolveLandmark:
|
|
2024
|
-
[
|
|
2025
|
+
), x = v(
|
|
2026
|
+
() => ({ type: "face", resolveLandmark: m }),
|
|
2027
|
+
[m]
|
|
2025
2028
|
);
|
|
2026
|
-
let
|
|
2029
|
+
let y;
|
|
2027
2030
|
const R = [];
|
|
2028
|
-
return
|
|
2029
|
-
var
|
|
2030
|
-
|
|
2031
|
-
(((
|
|
2032
|
-
((C = a.type) == null ? void 0 : C.displayName) === "FaceMesh") ?
|
|
2033
|
-
}), /* @__PURE__ */ w(X.Provider, { value:
|
|
2034
|
-
/* @__PURE__ */ _("group", { ref: o, renderOrder:
|
|
2035
|
-
|
|
2031
|
+
return z.Children.forEach(f, (a) => {
|
|
2032
|
+
var M, C;
|
|
2033
|
+
z.isValidElement(a) && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2034
|
+
(((M = a.type) == null ? void 0 : M.displayName) === "FaceTracker.Mesh" || // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2035
|
+
((C = a.type) == null ? void 0 : C.displayName) === "FaceMesh") ? y = z.cloneElement(a, { faceIndex: e, numFaces: t }) : R.push(a);
|
|
2036
|
+
}), /* @__PURE__ */ w(X.Provider, { value: x, children: [
|
|
2037
|
+
/* @__PURE__ */ _("group", { ref: o, renderOrder: n0.TRACKED, children: R }),
|
|
2038
|
+
y
|
|
2036
2039
|
] });
|
|
2037
2040
|
}, Z = (e) => /* @__PURE__ */ _(K, { ...e });
|
|
2038
2041
|
Z.displayName = "FaceTracker.Mesh";
|
|
2039
|
-
const Y =
|
|
2042
|
+
const Y = p0;
|
|
2040
2043
|
Y.Mesh = Z;
|
|
2041
|
-
const
|
|
2044
|
+
const S0 = Y;
|
|
2042
2045
|
export {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
+
T0 as F,
|
|
2047
|
+
S0 as H,
|
|
2048
|
+
s0 as M,
|
|
2046
2049
|
X as T,
|
|
2047
|
-
|
|
2050
|
+
_0 as a,
|
|
2048
2051
|
Y as b,
|
|
2049
2052
|
K as c,
|
|
2050
2053
|
L as d,
|
|
2051
|
-
|
|
2054
|
+
b0 as p,
|
|
2052
2055
|
h0 as r,
|
|
2053
|
-
|
|
2056
|
+
R0 as t,
|
|
2054
2057
|
j as u
|
|
2055
2058
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Re=Object.defineProperty;var Me=(n,s,e)=>s in n?Re(n,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[s]=e;var h=(n,s,e)=>Me(n,typeof s!="symbol"?s+"":s,e);const ie=require("react/jsx-runtime"),b=require("react"),_=require("@mediapipe/tasks-vision"),P=require("three");function Te(n){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(s,e,t.get?t:{enumerable:!0,get:()=>n[e]})}}return s.default=n,Object.freeze(s)}const D=Te(P);var x=(n=>(n.WEBCAM="webcam",n.STREAM="stream",n.CANVAS="canvas",n))(x||{}),L=(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))(L||{});class I extends Error{constructor(s){super(s),this.name="VincenttXRError"}}const xe=(n,s)=>s,E={apiBaseUrl:xe(void 0,"https://api.vincentt.studio"),assetStorageEndpoint:"https://cdn.vincentt.studio",sdkAssetsBaseUrl:"https://cdn.vincentt.studio/assets/sdk/face/v1",loggerPrefix:"[vincentt-xr]:",sessionCheckInterval:3e4};class Fe{constructor(s){h(this,"options");const e={verbose:!1,prefix:E.loggerPrefix};this.options={...e,...s}}log(...s){const{verbose:e,prefix:t}=this.options;e&&console.info(t,...s)}error(...s){const{verbose:e,prefix:t}=this.options;e&&console.error(t,...s)}}const B=n=>n*2-1,Y=new D.Vector3,Q=new D.Vector3,q=({x:n,y:s,z:e},t,a)=>{Y.set((n-.5)*2,(.5-s)*2,-e),Y.unproject(t),Q.copy(Y).sub(t.position).normalize();const r=-t.position.z/Q.z;return a.copy(t.position).addScaledVector(Q,r),a},Ae=(n,s)=>q(n,s,new D.Vector3),be=(n,s,e=.2)=>e*s+(1-e)*n;class ${constructor(s){h(this,"canvas");this.maxDimension=s}draw(s){const e=s.width,t=s.height,a=Math.min(1,this.maxDimension/Math.max(e,t));if(a>=1)return s;const r=Math.max(1,Math.round(e*a)),o=Math.max(1,Math.round(t*a));(!this.canvas||this.canvas.width!==r||this.canvas.height!==o)&&(this.canvas=new OffscreenCanvas(r,o));const u=this.canvas.getContext("2d");return u?(u.setTransform(1,0,0,1,0,0),u.clearRect(0,0,r,o),u.drawImage(s,0,0,r,o),this.canvas):s}dispose(){this.canvas=void 0}}const Ee={"/assets/xr/models/face_tracking.task":"sha384-tYQh+yJE8llY+zO4RviZmWaSKs5W9tsB0ix5rjQVpF5/CLTqmwtP7bYtkUi2w65P","/assets/xr/models/hand_tracking.task":"sha384-uWvruVKd887ov8k43S+DBHCsi7UXXS+CKvvdM1PX00rjPzx/B0QrAPfJ1U9yKcze","/assets/xr/models/gesture_tracking.task":"sha384-2zuseP9JKKWAYlWQGKA2N+ooabB8V/yIxu23Mv8mtY7SowcySB+xKiOmqBhVvlUC","/assets/xr/models/body_tracking.task":"sha384-3Wk9dvRYo36b3Nc9xVjKamb4wCKt9FwiPjcHKfrvyJL/jXoGs+uRLnii6yjWLKul","/assets/xr/models/segmentation.tflite":"sha384-A2bQ8+iZyQM3KIGVBUf0FyetqxuynyKpjsjCE8uzoJEnj1ghCu6ge2daiRffAiS5","/assets/xr/3d-models/head-occluder-v2.glb":"sha384-+0G60Q6EBVE6hpITxGzQgofAeKexPltpsfPq5T5et9GGBjRhFP5HOdsKAhe73OaI","/assets/sdk/face/v1/canonical_face_model.obj":"sha384-xP8YM/72TXKvbMptXB9a8JUlUf3MZQ8uLurExrsZc05v6/P5RrsaNGMUYS/BZx8A","/opencv/facial_expression_recognition/resolve/main/facial_expression_recognition_mobilefacenet_2022july_int8.onnx":"sha384-g8mtFubiIc/yhqi591RsxD76AJLw2CfYgKhKbVkIiFlwBmIyG7ZAIVyGPXafrDGB"};async function re(n){const s=await fetch(n);if(!s.ok)throw new Error(`fetchAndVerify: ${s.status} ${n}`);const e=await s.arrayBuffer(),t=De(n);if(!t){if(Ie(n))throw new Error(`[xr-sdk integrity] no SRI hash for SDK asset ${n}`);return console.warn(`[xr-sdk integrity] no SRI hash for ${n} — passing through`),e}const a=await _e(e);if(a!==t)throw new Error(`[xr-sdk integrity] SRI mismatch for ${n}: expected ${t}, got ${a}`);return e}function Ie(n){try{return new URL(n).origin===new URL(E.assetStorageEndpoint).origin}catch{return!1}}async function H(n){const s=await re(n);return new Uint8Array(s)}function De(n){try{const s=new URL(n);return Ee[s.pathname]}catch{return}}async function _e(n){const s=await crypto.subtle.digest("SHA-384",n),e=new Uint8Array(s);let t="";for(let a=0;a<e.byteLength;a++)t+=String.fromCharCode(e[a]);return`sha384-${btoa(t)}`}class G{constructor(){h(this,"disposed",!1);h(this,"paused",!1);h(this,"rafId",null);h(this,"targetFrameIntervalMs",0);h(this,"lastInferenceMs",0)}setTargetFps(s){this.targetFrameIntervalMs=s&&s>0?1e3/s:0}shouldRunInference(){if(this.targetFrameIntervalMs<=0)return!0;const s=performance.now();return s-this.lastInferenceMs<this.targetFrameIntervalMs?!1:(this.lastInferenceMs=s,!0)}async initialize(s){}async run(s){}getModelNode(){return{}}async getPerformanceData(){return{name:this.constructor.name,processingTime:null}}pause(){this.paused=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}resume(){this.paused=!1}dispose(){this.disposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}}const Pe=768;class Oe extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"sourceCanvas");h(this,"downscaler",new $(Pe))}async getBodyData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=a.landmarks,u=[];if(o)return o.forEach((m,d)=>{u[d]||(u[d]=[]),m.forEach(S=>{const M=B(S.x),R=B(1-S.y),F=B(S.z);u[d].push({x:M,y:R,z:F})})}),{coordinatesList:u}}async processBodyTracking(){if(!(this.disposed||this.paused||!this.landmarker)){if(this.shouldRunInference()){const e=await this.getBodyData();e&&(this.coordinates=e.coordinatesList)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processBodyTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processBodyTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0}getLandmarks2D(e=0){if(this.coordinates)return this.coordinates[e]}async initialize(e){const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/body_tracking.task",E.assetStorageEndpoint).toString());this.landmarker=await _.PoseLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},runningMode:"VIDEO",numPoses:(e==null?void 0:e.numPoses)||1})}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t),this.rafId===null&&await this.processBodyTracking()}getModelNode(){return{getLandmarks2D:this.getLandmarks2D.bind(this)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ue=.11,ze=.004,Le=(n,s)=>s.set(n.x,-n.y,n.z);class Be extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"analysisCanvas");h(this,"getSource");h(this,"detectionResults");h(this,"numFaces",1);h(this,"cameras",[]);h(this,"faces",[]);h(this,"leftCheekScratch",[]);h(this,"rightCheekScratch",[]);h(this,"landmarkScratch",{x:0,y:0,z:0,visibility:0});h(this,"rotMatrixScratch",new D.Matrix4);h(this,"rotQuatScratch",new D.Quaternion);h(this,"rotEulerScratch",new D.Euler)}landmarkForSource(e,t){return t?(this.landmarkScratch.x=1-e.x,this.landmarkScratch.y=e.y,this.landmarkScratch.z=e.z,this.landmarkScratch.visibility=e.visibility,this.landmarkScratch):e}extractAndUpdateFaceData(e){var a;if(!e.faceLandmarks.length){this.faces=[];return}const t=e.faceLandmarks.length;for(this.faces.length>t&&(this.faces.length=t,this.leftCheekScratch.length=t,this.rightCheekScratch.length=t);this.faces.length<t;)this.faces.push({transform:{position:new D.Vector3,rotation:new D.Vector3,scale:new D.Vector3},gestures:{}}),this.leftCheekScratch.push(new D.Vector3),this.rightCheekScratch.push(new D.Vector3);for(let r=0;r<t;r+=1){if(!this.cameras[r])continue;const o=this.faces[r],u=(a=this.getSource)==null?void 0:a.call(this),m=!(u==="webcam"||!u),d=e.faceLandmarks[r],S=e.facialTransformationMatrixes[r];this.rotMatrixScratch.fromArray(S.data),this.rotQuatScratch.setFromRotationMatrix(this.rotMatrixScratch),this.rotQuatScratch.set(-this.rotQuatScratch.x,this.rotQuatScratch.y,this.rotQuatScratch.z,this.rotQuatScratch.w),this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch,"XYZ"),Le(this.rotEulerScratch,o.transform.rotation),q(this.landmarkForSource(d[4],m),this.cameras[r],o.transform.position),q(this.landmarkForSource(d[50],m),this.cameras[r],this.leftCheekScratch[r]),q(this.landmarkForSource(d[280],m),this.cameras[r],this.rightCheekScratch[r]);const R=this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r])*Ue,F=Math.abs(D.MathUtils.radToDeg(this.rotEulerScratch.y)),g=R+F*ze,f=o.transform.scale.x,w=be(isNaN(f)?0:f,g);o.transform.scale.set(w,w,w);const p=o.gestures,k=e.faceBlendshapes[r].categories;for(const C of k)p[C.categoryName]=C.score}}async processFaceTracking(){if(this.disposed||this.paused||!this.landmarker||!this.sourceCanvas)return null;if(!this.shouldRunInference()){this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this));return}const e=Ve(this.numFaces),t=this.sourceCanvas.width,a=this.sourceCanvas.height,r=Math.min(1,e/Math.max(t,a)),o=Math.max(1,Math.round(t*r)),u=Math.max(1,Math.round(a*r));(!this.analysisCanvas||this.analysisCanvas.width!==o||this.analysisCanvas.height!==u)&&(this.analysisCanvas=new OffscreenCanvas(o,u));const m=this.analysisCanvas.getContext("2d");if(!m){this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this));return}m.setTransform(1,0,0,1,0,0),m.clearRect(0,0,o,u),m.drawImage(this.sourceCanvas,0,0,o,u);const d=performance.now(),S=this.landmarker.detectForVideo(this.analysisCanvas,d),M=performance.now();this.processingTime=M-d,this.detectionResults=S,this.extractAndUpdateFaceData(S),!(this.disposed||this.paused)&&(this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this)))}resume(){this.paused&&(super.resume(),this.processFaceTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.analysisCanvas=void 0,this.getSource=void 0,this.detectionResults=void 0,this.processingTime=null,this.cameras=[],this.faces=[],this.leftCheekScratch=[],this.rightCheekScratch=[]}getFace(e=0){return this.faces[e]}getDetectionResults(){return this.detectionResults}getRawFaceTrackingData(e=0){var t,a,r,o;if(this.detectionResults)return{landmarks:(t=this.detectionResults.faceLandmarks)==null?void 0:t[e],blendshapes:(r=(a=this.detectionResults.faceBlendshapes)==null?void 0:a[e])==null?void 0:r.categories,transformationMatrix:(o=this.detectionResults.facialTransformationMatrixes)==null?void 0:o[e]}}async initialize(e){this.numFaces=(e==null?void 0:e.numFaces)||1;const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/face_tracking.task",E.assetStorageEndpoint).toString()),r=await _.FaceLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},minFaceDetectionConfidence:.3,minFacePresenceConfidence:.3,minTrackingConfidence:.3,outputFaceBlendshapes:!0,outputFacialTransformationMatrixes:!0,runningMode:"VIDEO",numFaces:this.numFaces});if(this.disposed){r.close();return}this.landmarker=r}async run({sourceCanvas:e,getSource:t,targetFps:a}){this.sourceCanvas=e,this.getSource=t,this.setTargetFps(a),this.analysisCanvas=void 0,this.rafId===null&&this.processFaceTracking()}getModelNode(){const e=this;return{get detectionResults(){return e.detectionResults},getDetectionResults:this.getDetectionResults.bind(this),getFace:this.getFace.bind(this),getRawFaceTrackingData:this.getRawFaceTrackingData.bind(this),setCamera:(a,r=0)=>{this.cameras[r]=a}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ve=n=>n>1?1024:512;var O=(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))(O||{});const Ke=512,Ne={Closed_Fist:O.ClosedFist,Open_Palm:O.OpenPalm,Pointing_Up:O.PointingUp,Thumb_Down:O.ThumbDown,Thumb_Up:O.ThumbUp,Victory:O.Victory,ILoveYou:O.ILoveYou,None:O.None},qe=15;class He extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"gesture");h(this,"sourceCanvas");h(this,"downscaler",new $(Ke))}async getGestureData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.recognizeForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=a.landmarks[0],u=[];if(o){const m=a.gestures[0][0].categoryName;return o.forEach(d=>{u.push({x:B(d.x),y:B(1-d.y),z:-d.z})}),{coordinates:u,gesture:Ne[m]}}return{coordinates:void 0,gesture:void 0}}async processGestureTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getGestureData();e&&(this.coordinates=e.coordinates,this.gesture=e.gesture)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processGestureTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processGestureTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0}async initialize(){const e=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),t=await H(new URL("/assets/xr/models/gesture_tracking.task",E.assetStorageEndpoint).toString()),a=await _.GestureRecognizer.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:1});this.landmarker=a}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t??qe),this.rafId===null&&await this.processGestureTracking()}getModelNode(){const e=this;return{get coordinates(){return e.coordinates},get gesture(){return e.gesture}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ge=512;class je extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"hands");h(this,"coordinates");h(this,"gesture");h(this,"handedness");h(this,"sourceCanvas");h(this,"downscaler",new $(Ge))}async getHandData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=[],u=a.handedness??a.handednesses??[];if(a.landmarks.forEach((d,S)=>{var f,w,p;if(!d||d.length===0)return;const M=d.map(k=>({x:B(k.x),y:B(1-k.y),z:-k.z})),R=(p=(w=(f=u[S])==null?void 0:f[0])==null?void 0:w.categoryName)==null?void 0:p.toLowerCase(),F=R==="left"||R==="right"?R:void 0,g=d[0].z<0?"closed_fist":"open_palm";o.push({coordinates:M,gesture:g,handedness:F})}),!o.length)return{hands:void 0,coordinates:void 0,gesture:void 0,handedness:void 0};const m=o[0];return{hands:o,coordinates:m.coordinates,gesture:m.gesture,handedness:m.handedness}}async processHandTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getHandData();e&&(this.hands=e.hands,this.coordinates=e.coordinates,this.gesture=e.gesture,this.handedness=e.handedness)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processHandTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processHandTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.hands=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0,this.handedness=void 0}async initialize(){const e=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),t=await H(new URL("/assets/xr/models/hand_tracking.task",E.assetStorageEndpoint).toString()),a=await _.HandLandmarker.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:2});this.landmarker=a}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t),this.rafId===null&&await this.processHandTracking()}getModelNode(){const e=this;return{get hands(){return e.hands},get coordinates(){return e.coordinates},get gesture(){return e.gesture},get handedness(){return e.handedness}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const We=24,Xe=720,Ye=[[255,255,255,255],[0,0,0,0]];class Qe extends G{constructor(){super();h(this,"segmenter",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"processCanvas");h(this,"filterCanvas");h(this,"inputSource");h(this,"inputSourceSize");h(this,"glCanvas");h(this,"drawingUtils");h(this,"useGpuMaskPath",!1);h(this,"maskImageData");h(this,"maskCanvas",null);h(this,"segmentationMaskTexture");h(this,"isMaskSetup",!1);h(this,"isProcessing",!1);h(this,"latestMask",null);h(this,"rawCache",null);h(this,"quality","medium");h(this,"stagingCanvas")}getQualityScaleFactor(){switch(this.quality){case"low":return .5;case"medium":return .75;case"high":return 1;default:return .5}}setInputSource(e){this.inputSource=e,this.inputSourceSize=e?this.readIntrinsicSize(e):void 0}readIntrinsicSize(e){if(e instanceof HTMLVideoElement)return e.videoWidth>0?{width:e.videoWidth,height:e.videoHeight}:void 0;if(e instanceof HTMLImageElement)return e.naturalWidth>0?{width:e.naturalWidth,height:e.naturalHeight}:void 0;const t=e.width,a=e.height;return typeof t=="number"&&t>0&&typeof a=="number"&&a>0?{width:t,height:a}:void 0}ensureProcessCanvasForInput(){if(!this.processCanvas||!this.inputSource)return;const e=this.readIntrinsicSize(this.inputSource);if(!e)return;this.inputSourceSize=e;const t=Math.min(1,Xe/Math.max(e.width,e.height)),a=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));this.processCanvas.width===a&&this.processCanvas.height===r||(this.processCanvas.width=a,this.processCanvas.height=r,this.glCanvas&&(this.glCanvas.width=a,this.glCanvas.height=r),this.maskImageData=void 0)}async processSegmentation(){if(this.disposed||!this.isProcessing||!this.maskCanvas||!this.processCanvas)return;if(!this.shouldRunInference()){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const e=this.inputSource??this.sourceCanvas;if(!this.segmenter||!e){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const t=performance.now();this.ensureProcessCanvasForInput();const a=this.processCanvas.getContext("2d");if(a){const u=this.processCanvas.width,m=this.processCanvas.height;if(a.clearRect(0,0,u,m),this.inputSource&&this.inputSourceSize){const{width:d,height:S}=this.inputSourceSize,M=Math.min(u/d,m/S),R=d*M,F=S*M;a.drawImage(this.inputSource,(u-R)/2,(m-F)/2,R,F)}else a.drawImage(e,0,0,u,m)}const o=this.segmenter.segmentForVideo(this.processCanvas,performance.now()).categoryMask;if(!o){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}if(this.rawCache=null,this.latestMask&&(this.latestMask.close(),this.latestMask=null),this.useGpuMaskPath&&this.drawingUtils&&this.glCanvas)this.drawingUtils.drawCategoryMask(o,Ye),this.latestMask=o.clone(),o.close(),this.blitGlToMask();else{this.latestMask=o.clone();const u=this.readMaskToImageData(o);o.close(),u&&this.blitImageDataToMask(u)}this.segmentationMaskTexture&&(this.isMaskSetup||(this.segmentationMaskTexture.format=P.RGBAFormat,this.segmentationMaskTexture.minFilter=P.LinearFilter,this.segmentationMaskTexture.magFilter=P.LinearFilter,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)))}blitGlToMask(){if(!this.maskCanvas||!this.filterCanvas||!this.glCanvas)return;const e=this.maskCanvas.getContext("2d"),t=this.filterCanvas.getContext("2d");!e||!t||(t.filter="blur(0.5px)",t.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),t.drawImage(this.glCanvas,0,0,this.filterCanvas.width,this.filterCanvas.height),e.clearRect(0,0,this.maskCanvas.width,this.maskCanvas.height),e.drawImage(this.filterCanvas,0,0,this.maskCanvas.width,this.maskCanvas.height))}readMaskToImageData(e){const t=e.getAsUint8Array(),{width:a,height:r}=e;if(!t||a<=0||r<=0)return null;(!this.maskImageData||this.maskImageData.width!==a||this.maskImageData.height!==r)&&(this.maskImageData=new ImageData(a,r));const o=this.maskImageData.data;for(let u=0;u<t.length;u+=1){const m=t[u]===255?0:255;o[u*4]=255,o[u*4+1]=m,o[u*4+2]=255,o[u*4+3]=m}return this.maskImageData}blitImageDataToMask(e){if(!this.maskCanvas||!this.filterCanvas)return;const t=this.maskCanvas.getContext("2d"),a=this.filterCanvas.getContext("2d");if(!t||!a)return;const r=this.getStagingCanvas(e.width,e.height),o=r.getContext("2d");o&&(o.putImageData(e,0,0),a.filter="blur(0.5px)",a.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),a.drawImage(r,0,0,this.filterCanvas.width,this.filterCanvas.height),t.clearRect(0,0,this.maskCanvas.width,this.maskCanvas.height),t.drawImage(this.filterCanvas,0,0,this.maskCanvas.width,this.maskCanvas.height))}getStagingCanvas(e,t){return this.stagingCanvas||(this.stagingCanvas=document.createElement("canvas")),this.stagingCanvas.width!==e&&(this.stagingCanvas.width=e),this.stagingCanvas.height!==t&&(this.stagingCanvas.height=t),this.stagingCanvas}resume(){this.paused&&(super.resume(),this.processSegmentation())}dispose(){if(super.dispose(),this.isProcessing=!1,this.latestMask){try{this.latestMask.close()}catch{}this.latestMask=null}if(this.rawCache=null,this.segmenter){try{this.segmenter.close()}catch{}this.segmenter=null}this.drawingUtils=void 0,this.glCanvas=void 0,this.maskImageData=void 0,this.segmentationMaskTexture&&(this.segmentationMaskTexture.dispose(),this.segmentationMaskTexture=void 0),this.sourceCanvas=void 0,this.inputSource=void 0,this.inputSourceSize=void 0,this.processCanvas=void 0,this.filterCanvas=void 0,this.stagingCanvas=void 0,this.maskCanvas=null}async initialize(e){this.quality=(e==null?void 0:e.quality)??"low";const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/segmentation.tflite",E.assetStorageEndpoint).toString());this.glCanvas=new OffscreenCanvas(1,1);const r=this.glCanvas.getContext("webgl2",{preserveDrawingBuffer:!0});this.segmenter=await _.ImageSegmenter.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},...r?{canvas:this.glCanvas}:{},outputCategoryMask:!0,outputConfidenceMasks:!1,runningMode:"VIDEO"}),r?(this.drawingUtils=new _.DrawingUtils(r),this.useGpuMaskPath=!0):this.useGpuMaskPath=!1}async run({sourceCanvas:e,renderWidth:t,renderHeight:a,targetFps:r}){var u;if(!e)return;this.setTargetFps(r??We),this.isProcessing=!1,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null);const o=this.getQualityScaleFactor();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=a,this.filterCanvas=document.createElement("canvas"),this.filterCanvas.width=t,this.filterCanvas.height=a,(u=this.segmentationMaskTexture)==null||u.dispose(),this.segmentationMaskTexture=new P.CanvasTexture(this.maskCanvas),this.isMaskSetup=!1,this.rawCache=null,this.isProcessing=!0,this.lastInferenceMs=0,this.rafId=requestAnimationFrame(this.processSegmentation.bind(this))}getRawSegmentationData(){if(this.rawCache)return this.rawCache;if(!this.latestMask)return null;const e=this.latestMask.getAsUint8Array();return this.rawCache={maskData:e,width:this.latestMask.width,height:this.latestMask.height},this.rawCache}getModelNode(){const e=this;return{get backgroundSegmentationMask(){return e.segmentationMaskTexture},getMaskCanvas:()=>e.maskCanvas,getRawSegmentationData:()=>e.getRawSegmentationData(),setInputSource:t=>e.setInputSource(t??void 0)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const ae={[L.BACKGROUND_SEGMENTATION]:Qe,[L.HAND_TRACKER]:je,[L.GESTURE_TRACKER]:He,[L.FACE_TRACKER]:Be,[L.BODY_TRACKER]:Oe},Ze=async n=>{const s=document.createElement("video");s.srcObject=n,s.muted=!0,s.playsInline=!0,s.autoplay=!0,await new Promise(t=>{s.onloadedmetadata=()=>{s.play(),t()}});const e=s;return await new Promise(t=>{const a=setTimeout(t,150),r=()=>{clearTimeout(a),t()};typeof e.requestVideoFrameCallback=="function"?e.requestVideoFrameCallback(r):requestAnimationFrame(()=>requestAnimationFrame(()=>r()))}),s},$e=n=>{const s=new P.CanvasTexture(n);return s.colorSpace=P.SRGBColorSpace,s.format=P.RGBAFormat,s.minFilter=P.LinearFilter,s.magFilter=P.LinearFilter,s.generateMipmaps=!1,s.needsUpdate=!0,s},Je=(n,s)=>{const e=n.videoWidth,t=n.videoHeight;e>0&&t>0&&(s.width!==e&&(s.width=e),s.height!==t&&(s.height=t));const a=s.getContext("2d",{colorSpace:"srgb"});a.save(),a.scale(-1,1),a.drawImage(n,-s.width,0,s.width,s.height),a.restore()},et=(n,s,e=1)=>{const t=s.getContext("2d",{colorSpace:"srgb"}),a=s.width/s.height,r=n.width/n.height;let o,u;r>a?(u=s.height,o=n.width*(s.height/n.height)):(o=s.width,u=n.height*(s.width/n.width));const m=Number.isFinite(e)&&e>0?e:1;o*=m,u*=m;const d=(s.width-o)/2,S=(s.height-u)/2;t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,s.width,s.height),t.drawImage(n,0,0,n.width,n.height,d,S,o,u)},tt=(n,s,e)=>{const t=new Map;let a=!1;const r=(g,f)=>{var w;try{(w=f.dispose)==null||w.call(f)}catch(p){console.warn(`[xr-sdk registry] dispose threw for ${g}`,p)}};return{acquire:async(g,f,w)=>{let p=t.get(g);if(p)return p.refs.add(f),p.activeRefs.add(f),p.initPromise;const k=s[g];if(!k)throw new Error(`Invalid model: ${g}`);const C=new k,K=new Set([f]),V=new Set([f]),U=(async()=>{await C.initialize(w);const N=t.get(g);if(!N||N.model!==C||N.refs.size===0)return r(g,C),C;e&&await e(g,C);const T=t.get(g);return T&&T.refs.size>0&&n.setPipeline(z=>z.set(g,C)),C})();return p={model:C,refs:K,activeRefs:V,initPromise:U,options:w},t.set(g,p),U.catch(()=>{t.get(g)===p&&(t.delete(g),n.setPipeline(T=>T.delete(g))),r(g,C)}),U},release:(g,f)=>{const w=t.get(g);w&&(w.refs.delete(f),w.activeRefs.delete(f)&&w.refs.size>0&&w.activeRefs.size===0&&w.model.pause(),!(w.refs.size>0)&&(t.delete(g),r(g,w.model),n.setPipeline(p=>p.delete(g))))},setActive:(g,f,w)=>{const p=t.get(g);if(!p||!p.refs.has(f))return;const k=p.activeRefs.size>0;w?p.activeRefs.add(f):p.activeRefs.delete(f);const C=p.activeRefs.size>0;k!==C&&(C&&!a?p.model.resume():p.model.pause())},suspendAll:()=>{a=!0;for(const g of t.values())g.model.pause()},resumeActive:()=>{a=!1;for(const g of t.values())g.activeRefs.size>0&&g.model.resume()},get:g=>{var f;return(f=t.get(g))==null?void 0:f.model},getOptions:g=>{var f;return(f=t.get(g))==null?void 0:f.options},releaseAll:()=>{for(const g of Array.from(t.keys())){const f=t.get(g);f&&(f.refs.clear(),t.delete(g),r(g,f.model))}n.setPipeline(g=>g.clear())}}},st={lifecycle:"idle",ready:!1,error:void 0,cameraTexture:void 0,renderWidth:0,renderHeight:0,source:void 0,sourceKind:void 0,pipeline:new Map},nt=()=>{let n={...st,pipeline:new Map};const s=new Set,e=()=>{s.forEach(t=>t())};return{getSnapshot:()=>n,set:t=>{let a=!1;for(const r of Object.keys(t))if(t[r]!==n[r]){a=!0;break}a&&(n={...n,...t},e())},setPipeline:t=>{const a=new Map(n.pipeline);return t(a),n={...n,pipeline:a},e(),a},subscribe:t=>(s.add(t),()=>{s.delete(t)})}},it=({renderHeight:n,renderWidth:s,videoHeight:e,videoWidth:t})=>({height:n||e,width:s||t}),at=n=>{const s=new Fe({verbose:!0}),e=nt();let t=n;const a=i=>{var l;const c=(l=T.getOptions(i))==null?void 0:l.targetFps;return typeof c=="number"?c:t==null?void 0:t.targetFps};let r,o,u,m,d,S,M,R,F,g,f,w=!1,p=!1,k=0;const C=new Set,K=new Set,V=i=>{const c=e.getSnapshot().cameraTexture;c&&c.dispose();const l=$e(i);return e.set({cameraTexture:l}),l},U=async(i,c)=>{if(C.has(i)||e.getSnapshot().lifecycle!=="running"||!d)return;C.add(i);const l=k;try{await c.run({sourceCanvas:d,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:a(i)}),p&&(await new Promise(v=>requestAnimationFrame(()=>v())),await new Promise(v=>requestAnimationFrame(()=>v())),p&&k===l&&T.suspendAll())}catch(v){throw C.delete(i),v}},T=tt(e,ae,(i,c)=>U(i,c));e.subscribe(()=>{if(e.getSnapshot().lifecycle!=="running")return;const i=e.getSnapshot().pipeline;for(const[c,l]of i.entries())C.has(c)||U(c,l)});const z=()=>{if(f!==void 0&&(cancelAnimationFrame(f),f=void 0),o){try{o.pause()}catch{}try{o.srcObject=null}catch{}o=void 0}if(u){try{u.getTracks().forEach(i=>i.stop())}catch{}u=void 0}},j=()=>{if(w||!o||!m||!d)return;const i=window.__xr_debugger_metrics;if(i!=null&&i.trackCameraFrame&&i.trackCameraFrame(),(e.getSnapshot().sourceKind??"webcam")==="webcam")Je(o,m);else{const v=m.getContext("2d");if(!v)return;const y=o.videoWidth,A=o.videoHeight;m.width!==y&&(m.width=y),m.height!==A&&(m.height=A),v.setTransform(1,0,0,1,0,0),v.clearRect(0,0,y,A),v.drawImage(o,0,0,y,A)}et(m,d,(t==null?void 0:t.cameraZoom)??1.2);const l=e.getSnapshot().cameraTexture;l&&(l.needsUpdate=!0)},J=()=>{if(!o||!m||!d)return;if(p){j();return}const i=()=>{f=requestAnimationFrame(i),j()};f=requestAnimationFrame(i)},ue=async i=>{if(i.source===x.WEBCAM)try{const c=t!=null&&t.camRes&&t.camRes>0?t.camRes:960;return await navigator.mediaDevices.getUserMedia({video:{facingMode:"user",frameRate:{min:24,ideal:30,max:60},width:{ideal:c}}})}catch(c){const l=c instanceof DOMException?c.name:"",v=l==="NotReadableError"||l==="TrackStartError"?"Camera is already in use by another app or browser tab. Close it and refresh.":l==="NotFoundError"||l==="DevicesNotFoundError"?"No camera was found on this device.":l==="NotAllowedError"||l==="PermissionDeniedError"?"Camera access was blocked. Allow camera permissions in your browser, then refresh.":"Unable to access camera. Allow camera permissions in your browser, then refresh.";throw e.set({error:{error:"PermissionError",message:v}}),new I(c instanceof Error?c.message:"getUserMedia failed")}return i.stream},W=async i=>{const c=await ue(i);u=c;const l=await Ze(c);o=l,m=new OffscreenCanvas(l.videoWidth,l.videoHeight);const{renderWidth:v,renderHeight:y}=e.getSnapshot(),A=it({renderWidth:v,renderHeight:y,videoWidth:l.videoWidth,videoHeight:l.videoHeight});d?(d.width!==A.width||d.height!==A.height)&&(d.width=A.width,d.height=A.height,V(d)):(d=new OffscreenCanvas(A.width,A.height),V(d));const ne=i.source===x.STREAM?i.static===!0:!1;p=ne,r=i.source===x.WEBCAM?{source:x.WEBCAM,sourceKind:"webcam"}:{source:x.STREAM,stream:i.stream,static:ne,sourceKind:i.sourceKind??"webcam"},e.set({source:i.source,sourceKind:r.sourceKind,error:void 0})},X=async i=>{const c=i.sourceKind??"webcam";d=i.canvas;const l=V(d);e.set({cameraTexture:l,source:x.CANVAS,sourceKind:c,renderWidth:d.width,renderHeight:d.height,error:void 0}),r={source:x.CANVAS,canvas:i.canvas,sourceKind:c}},le=(i,c)=>!c||i.source!==c.source?!1:i.source===x.STREAM&&c.source===x.STREAM?i.stream===c.stream&&(i.sourceKind??"webcam")===c.sourceKind:!0,ge=async()=>{if(!d)return;const i=k,c=e.getSnapshot().pipeline;for(const[,l]of c.entries())l.resume();await new Promise(l=>requestAnimationFrame(()=>l())),await new Promise(l=>requestAnimationFrame(()=>l())),p&&k===i&&T.suspendAll()},me=(i,c)=>!c||c.source!==x.CANVAS?!1:i.canvas===c.canvas&&(i.sourceKind??"webcam")===c.sourceKind,fe=async i=>{const c=i.source;if(c!==x.WEBCAM&&c!==x.STREAM)throw new I(`Invalid media source: ${String(c)}`);if(le(i,r)){s.log("Media source unchanged, skipping rebind.");return}k+=1;const{lifecycle:l}=e.getSnapshot();if(l==="idle"||l==="stopped"){await W(i),e.set({lifecycle:"media-bound"}),s.log("Media source set to:",i.source);return}if(l==="media-bound"){z(),await W(i),s.log("Media source rebound to:",i.source);return}w=!0,await new Promise(v=>requestAnimationFrame(()=>v())),z(),await W(i),w=!1,J(),p?await ge():T.resumeActive(),s.log("Media source swapped to:",i.source)},pe=async i=>{if(me(i,r)){s.log("Frame source unchanged, skipping rebind.");return}k+=1;const{lifecycle:c}=e.getSnapshot();if(c==="idle"||c==="stopped"){await X(i),e.set({lifecycle:"media-bound"}),s.log("Frame source set to canvas.");return}if(c==="media-bound"){z(),await X(i),s.log("Frame source rebound to canvas.");return}w=!0,await new Promise(l=>requestAnimationFrame(()=>l())),z(),await X(i),w=!1,s.log("Frame source swapped to canvas.")},ve=async()=>{const{lifecycle:i}=e.getSnapshot();if(i==="running")return;if(i==="idle")throw new I("session.start() called before setMediaSource — call setMediaSource first");if(!d)throw new I("session.start(): media source not bound");const c=(r==null?void 0:r.source)===x.CANVAS;if(!c&&(!o||!m))throw i==="stopped"?new I("session.start() called from stopped state without a media source — call setMediaSource first"):new I("session.start(): media source not bound");c||J(),T.resumeActive(),e.set({lifecycle:"running"}),await new Promise(v=>requestAnimationFrame(()=>v()));const l=e.getSnapshot().pipeline;for(const[v,y]of l.entries())await U(v,y);e.set({ready:!0}),s.log("XR session started.")},ee=async()=>{const{lifecycle:i}=e.getSnapshot();i==="stopped"||i==="idle"||(z(),T.suspendAll(),e.set({lifecycle:"stopped",ready:!1}),s.log("XR session stopped."))},we=async()=>{await ee(),T.releaseAll(),K.clear();const i=e.getSnapshot().cameraTexture;i&&i.dispose(),C.clear(),r=void 0,k+=1,d=void 0,m=void 0,p=!1,e.set({lifecycle:"idle",cameraTexture:void 0,source:void 0}),s.log("XR session reset.")},Ce=async i=>{const c="legacy:registerXRPipeline",l=[];await Promise.all(i.map(async v=>{const{model:y}=v;if(!ae[y])throw new I(`Invalid model: ${y}`);K.has(y)||l.push(y);const A="options"in v?v.options:void 0;await T.acquire(y,c,A)})),l.length>0&&(l.forEach(v=>K.add(v)),s.log("XR pipeline registered."))},Se=i=>{const c=T.get(i);if(!c)throw new I(`Model ${i} is not registered in the pipeline`);return c.getModelNode()},te=async(i,c)=>{i<=0||c<=0||(e.set({renderWidth:i,renderHeight:c}),d&&(d.width!==i||d.height!==c)&&(d.width=i,d.height=c,V(d),p&&j()),s.log(`Source canvas set. Render size: ${i}x${c}`))},ke=async i=>{var y;S=i;const c=(y=i.getBoundingClientRect)==null?void 0:y.call(i),l=c&&c.width>0?Math.round(c.width):i.clientWidth,v=c&&c.height>0?Math.round(c.height):i.clientHeight;await te(l,v)},ye=i=>{M=i.renderer,R=i.scene,F=i.camera,g=i.renderFrame},se=()=>{if(!M||!R||!F)throw new I("XR frame render requested before the R3F state was bound — make sure <XRScene> is mounted");g?g():M.render(R,F)};return{store:e,registry:T,setMediaSource:fe,start:ve,stop:ee,reset:we,setFrameSource:pe,registerXRPipeline:Ce,getModelNode:Se,captureFrame:()=>{if(!S)throw new I("session.captureFrame() called before the XRScene render target was bound — make sure <XRScene> is mounted");if(!M||!R||!F)throw new I("session.captureFrame() called before the R3F state was bound — make sure <XRScene> is mounted");return se(),S.toDataURL("image/png")},getInputFrame:()=>d??null,_setRenderTarget:ke,_setRenderSize:te,_setR3FState:ye,_renderFrame:se,_getVideoElement:()=>o,_setPerf:i=>{if(t=i,e.getSnapshot().lifecycle!=="running"||!d)return;const c=e.getSnapshot().pipeline;for(const[l,v]of c.entries())v.run({sourceCanvas:d,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:a(l)})}}},rt=n=>{const s=b.useRef(n),e=b.useMemo(()=>at(s.current),[]),t=JSON.stringify(n??{});return b.useEffect(()=>{e._setPerf(n)},[e,t]),e},Z=new Map,ot=()=>({register:(n,s)=>{s?Z.set(n,s):Z.delete(n)},resolve:n=>n?Z.get(n)??null:null}),oe=ot(),ce=b.createContext(null),ct=({children:n})=>{const s=b.useRef(new Map),e=b.useCallback((r,o)=>{o?s.current.set(r,o):s.current.delete(r)},[]),t=b.useCallback(r=>r?s.current.get(r)??null:null,[]),a=b.useMemo(()=>({register:e,resolve:t}),[e,t]);return b.createElement(ce.Provider,{value:a},n)},he=()=>b.useContext(ce)??oe,ht=()=>he().register,dt=()=>he().resolve;oe.register;const de=b.createContext(void 0),ut=()=>{const n=b.useContext(de);if(!n)throw new I("XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?");return n},lt=({children:n,perf:s})=>{const e=rt(s),t=b.useMemo(()=>({session:e}),[e]);return ie.jsx(de.Provider,{value:t,children:ie.jsx(ct,{children:n})})};exports.XRMediaSource=x;exports.XRModel=L;exports.XRProvider=lt;exports.fetchAndVerify=re;exports.libConfig=E;exports.unprojectToZZero=Ae;exports.unprojectToZZeroInto=q;exports.useRegisterRuntimeObject=ht;exports.useResolveRuntimeObject=dt;exports.useXRContext=ut;
|
|
1
|
+
"use strict";var Re=Object.defineProperty;var Me=(n,s,e)=>s in n?Re(n,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[s]=e;var h=(n,s,e)=>Me(n,typeof s!="symbol"?s+"":s,e);const ie=require("react/jsx-runtime"),b=require("react"),_=require("@mediapipe/tasks-vision"),P=require("three");function Te(n){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(s,e,t.get?t:{enumerable:!0,get:()=>n[e]})}}return s.default=n,Object.freeze(s)}const D=Te(P);var x=(n=>(n.WEBCAM="webcam",n.STREAM="stream",n.CANVAS="canvas",n))(x||{}),L=(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))(L||{});class I extends Error{constructor(s){super(s),this.name="VincenttXRError"}}const xe=(n,s)=>s,E={apiBaseUrl:xe(void 0,"https://api.vincentt.studio"),assetStorageEndpoint:"https://cdn.vincentt.studio",sdkAssetsBaseUrl:"https://cdn.vincentt.studio/assets/sdk/face/v1",loggerPrefix:"[vincentt-xr]:",sessionCheckInterval:3e4};class Fe{constructor(s){h(this,"options");const e={verbose:!1,prefix:E.loggerPrefix};this.options={...e,...s}}log(...s){const{verbose:e,prefix:t}=this.options;e&&console.info(t,...s)}error(...s){const{verbose:e,prefix:t}=this.options;e&&console.error(t,...s)}}const B=n=>n*2-1,Y=new D.Vector3,Q=new D.Vector3,q=({x:n,y:s,z:e},t,a)=>{Y.set((n-.5)*2,(.5-s)*2,-e),Y.unproject(t),Q.copy(Y).sub(t.position).normalize();const r=-t.position.z/Q.z;return a.copy(t.position).addScaledVector(Q,r),a},Ae=(n,s)=>q(n,s,new D.Vector3),be=(n,s,e=.2)=>e*s+(1-e)*n;class ${constructor(s){h(this,"canvas");this.maxDimension=s}draw(s){const e=s.width,t=s.height,a=Math.min(1,this.maxDimension/Math.max(e,t));if(a>=1)return s;const r=Math.max(1,Math.round(e*a)),o=Math.max(1,Math.round(t*a));(!this.canvas||this.canvas.width!==r||this.canvas.height!==o)&&(this.canvas=new OffscreenCanvas(r,o));const d=this.canvas.getContext("2d");return d?(d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,r,o),d.drawImage(s,0,0,r,o),this.canvas):s}dispose(){this.canvas=void 0}}const Ee={"/assets/xr/models/face_tracking.task":"sha384-tYQh+yJE8llY+zO4RviZmWaSKs5W9tsB0ix5rjQVpF5/CLTqmwtP7bYtkUi2w65P","/assets/xr/models/hand_tracking.task":"sha384-uWvruVKd887ov8k43S+DBHCsi7UXXS+CKvvdM1PX00rjPzx/B0QrAPfJ1U9yKcze","/assets/xr/models/gesture_tracking.task":"sha384-2zuseP9JKKWAYlWQGKA2N+ooabB8V/yIxu23Mv8mtY7SowcySB+xKiOmqBhVvlUC","/assets/xr/models/body_tracking.task":"sha384-3Wk9dvRYo36b3Nc9xVjKamb4wCKt9FwiPjcHKfrvyJL/jXoGs+uRLnii6yjWLKul","/assets/xr/models/segmentation.tflite":"sha384-A2bQ8+iZyQM3KIGVBUf0FyetqxuynyKpjsjCE8uzoJEnj1ghCu6ge2daiRffAiS5","/assets/xr/3d-models/head-occluder-v2.glb":"sha384-+0G60Q6EBVE6hpITxGzQgofAeKexPltpsfPq5T5et9GGBjRhFP5HOdsKAhe73OaI","/assets/sdk/face/v1/canonical_face_model.obj":"sha384-xP8YM/72TXKvbMptXB9a8JUlUf3MZQ8uLurExrsZc05v6/P5RrsaNGMUYS/BZx8A","/opencv/facial_expression_recognition/resolve/main/facial_expression_recognition_mobilefacenet_2022july_int8.onnx":"sha384-g8mtFubiIc/yhqi591RsxD76AJLw2CfYgKhKbVkIiFlwBmIyG7ZAIVyGPXafrDGB"};async function re(n){const s=await fetch(n);if(!s.ok)throw new Error(`fetchAndVerify: ${s.status} ${n}`);const e=await s.arrayBuffer(),t=De(n);if(!t){if(Ie(n))throw new Error(`[xr-sdk integrity] no SRI hash for SDK asset ${n}`);return console.warn(`[xr-sdk integrity] no SRI hash for ${n} — passing through`),e}const a=await _e(e);if(a!==t)throw new Error(`[xr-sdk integrity] SRI mismatch for ${n}: expected ${t}, got ${a}`);return e}function Ie(n){try{return new URL(n).origin===new URL(E.assetStorageEndpoint).origin}catch{return!1}}async function H(n){const s=await re(n);return new Uint8Array(s)}function De(n){try{const s=new URL(n);return Ee[s.pathname]}catch{return}}async function _e(n){const s=await crypto.subtle.digest("SHA-384",n),e=new Uint8Array(s);let t="";for(let a=0;a<e.byteLength;a++)t+=String.fromCharCode(e[a]);return`sha384-${btoa(t)}`}class G{constructor(){h(this,"disposed",!1);h(this,"paused",!1);h(this,"rafId",null);h(this,"targetFrameIntervalMs",0);h(this,"lastInferenceMs",0)}setTargetFps(s){this.targetFrameIntervalMs=s&&s>0?1e3/s:0}shouldRunInference(){if(this.targetFrameIntervalMs<=0)return!0;const s=performance.now();return s-this.lastInferenceMs<this.targetFrameIntervalMs?!1:(this.lastInferenceMs=s,!0)}async initialize(s){}async run(s){}getModelNode(){return{}}async getPerformanceData(){return{name:this.constructor.name,processingTime:null}}pause(){this.paused=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}resume(){this.paused=!1}dispose(){this.disposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}}const Pe=768;class Oe extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"sourceCanvas");h(this,"downscaler",new $(Pe))}async getBodyData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=a.landmarks,d=[];if(o)return o.forEach((m,u)=>{d[u]||(d[u]=[]),m.forEach(S=>{const M=B(S.x),R=B(1-S.y),F=B(S.z);d[u].push({x:M,y:R,z:F})})}),{coordinatesList:d}}async processBodyTracking(){if(!(this.disposed||this.paused||!this.landmarker)){if(this.shouldRunInference()){const e=await this.getBodyData();e&&(this.coordinates=e.coordinatesList)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processBodyTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processBodyTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0}getLandmarks2D(e=0){if(this.coordinates)return this.coordinates[e]}async initialize(e){const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/body_tracking.task",E.assetStorageEndpoint).toString());this.landmarker=await _.PoseLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},runningMode:"VIDEO",numPoses:(e==null?void 0:e.numPoses)||1})}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t),this.rafId===null&&await this.processBodyTracking()}getModelNode(){return{getLandmarks2D:this.getLandmarks2D.bind(this)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ue=.11,ze=.004,Le=(n,s)=>s.set(n.x,-n.y,n.z);class Be extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"analysisCanvas");h(this,"getSource");h(this,"detectionResults");h(this,"numFaces",1);h(this,"cameras",[]);h(this,"faces",[]);h(this,"leftCheekScratch",[]);h(this,"rightCheekScratch",[]);h(this,"landmarkScratch",{x:0,y:0,z:0,visibility:0});h(this,"rotMatrixScratch",new D.Matrix4);h(this,"rotQuatScratch",new D.Quaternion);h(this,"rotEulerScratch",new D.Euler)}landmarkForSource(e,t){return t?(this.landmarkScratch.x=1-e.x,this.landmarkScratch.y=e.y,this.landmarkScratch.z=e.z,this.landmarkScratch.visibility=e.visibility,this.landmarkScratch):e}extractAndUpdateFaceData(e){var a;if(!e.faceLandmarks.length){this.faces=[];return}const t=e.faceLandmarks.length;for(this.faces.length>t&&(this.faces.length=t,this.leftCheekScratch.length=t,this.rightCheekScratch.length=t);this.faces.length<t;)this.faces.push({transform:{position:new D.Vector3,rotation:new D.Vector3,scale:new D.Vector3},gestures:{}}),this.leftCheekScratch.push(new D.Vector3),this.rightCheekScratch.push(new D.Vector3);for(let r=0;r<t;r+=1){if(!this.cameras[r])continue;const o=this.faces[r],d=(a=this.getSource)==null?void 0:a.call(this),m=!(d==="webcam"||!d),u=e.faceLandmarks[r],S=e.facialTransformationMatrixes[r];this.rotMatrixScratch.fromArray(S.data),this.rotQuatScratch.setFromRotationMatrix(this.rotMatrixScratch),this.rotQuatScratch.set(-this.rotQuatScratch.x,this.rotQuatScratch.y,this.rotQuatScratch.z,this.rotQuatScratch.w),this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch,"XYZ"),Le(this.rotEulerScratch,o.transform.rotation),q(this.landmarkForSource(u[4],m),this.cameras[r],o.transform.position),q(this.landmarkForSource(u[50],m),this.cameras[r],this.leftCheekScratch[r]),q(this.landmarkForSource(u[280],m),this.cameras[r],this.rightCheekScratch[r]);const R=this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r])*Ue,F=Math.abs(D.MathUtils.radToDeg(this.rotEulerScratch.y)),l=R+F*ze,f=o.transform.scale.x,w=be(isNaN(f)?0:f,l);o.transform.scale.set(w,w,w);const p=o.gestures,k=e.faceBlendshapes[r].categories;for(const C of k)p[C.categoryName]=C.score}}async processFaceTracking(){if(this.disposed||this.paused||!this.landmarker||!this.sourceCanvas)return null;if(!this.shouldRunInference()){this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this));return}const e=Ve(this.numFaces),t=this.sourceCanvas.width,a=this.sourceCanvas.height,r=Math.min(1,e/Math.max(t,a)),o=Math.max(1,Math.round(t*r)),d=Math.max(1,Math.round(a*r));(!this.analysisCanvas||this.analysisCanvas.width!==o||this.analysisCanvas.height!==d)&&(this.analysisCanvas=new OffscreenCanvas(o,d));const m=this.analysisCanvas.getContext("2d");if(!m){this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this));return}m.setTransform(1,0,0,1,0,0),m.clearRect(0,0,o,d),m.drawImage(this.sourceCanvas,0,0,o,d);const u=performance.now(),S=this.landmarker.detectForVideo(this.analysisCanvas,u),M=performance.now();this.processingTime=M-u,this.detectionResults=S,this.extractAndUpdateFaceData(S),!(this.disposed||this.paused)&&(this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this)))}resume(){this.paused&&(super.resume(),this.processFaceTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.analysisCanvas=void 0,this.getSource=void 0,this.detectionResults=void 0,this.processingTime=null,this.cameras=[],this.faces=[],this.leftCheekScratch=[],this.rightCheekScratch=[]}getFace(e=0){return this.faces[e]}getDetectionResults(){return this.detectionResults}getRawFaceTrackingData(e=0){var t,a,r,o;if(this.detectionResults)return{landmarks:(t=this.detectionResults.faceLandmarks)==null?void 0:t[e],blendshapes:(r=(a=this.detectionResults.faceBlendshapes)==null?void 0:a[e])==null?void 0:r.categories,transformationMatrix:(o=this.detectionResults.facialTransformationMatrixes)==null?void 0:o[e]}}async initialize(e){this.numFaces=(e==null?void 0:e.numFaces)||1;const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/face_tracking.task",E.assetStorageEndpoint).toString()),r=await _.FaceLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},minFaceDetectionConfidence:.3,minFacePresenceConfidence:.3,minTrackingConfidence:.3,outputFaceBlendshapes:!0,outputFacialTransformationMatrixes:!0,runningMode:"VIDEO",numFaces:this.numFaces});if(this.disposed){r.close();return}this.landmarker=r}async run({sourceCanvas:e,getSource:t,targetFps:a}){this.sourceCanvas=e,this.getSource=t,this.setTargetFps(a),this.analysisCanvas=void 0,this.rafId===null&&this.processFaceTracking()}getModelNode(){const e=this;return{get detectionResults(){return e.detectionResults},getDetectionResults:this.getDetectionResults.bind(this),getFace:this.getFace.bind(this),getRawFaceTrackingData:this.getRawFaceTrackingData.bind(this),setCamera:(a,r=0)=>{this.cameras[r]=a}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ve=n=>n>1?1024:512;var O=(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))(O||{});const Ke=512,Ne={Closed_Fist:O.ClosedFist,Open_Palm:O.OpenPalm,Pointing_Up:O.PointingUp,Thumb_Down:O.ThumbDown,Thumb_Up:O.ThumbUp,Victory:O.Victory,ILoveYou:O.ILoveYou,None:O.None},qe=15;class He extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"gesture");h(this,"sourceCanvas");h(this,"downscaler",new $(Ke))}async getGestureData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.recognizeForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=a.landmarks[0],d=[];if(o){const m=a.gestures[0][0].categoryName;return o.forEach(u=>{d.push({x:B(u.x),y:B(1-u.y),z:-u.z})}),{coordinates:d,gesture:Ne[m]}}return{coordinates:void 0,gesture:void 0}}async processGestureTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getGestureData();e&&(this.coordinates=e.coordinates,this.gesture=e.gesture)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processGestureTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processGestureTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0}async initialize(){const e=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),t=await H(new URL("/assets/xr/models/gesture_tracking.task",E.assetStorageEndpoint).toString()),a=await _.GestureRecognizer.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:1});this.landmarker=a}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t??qe),this.rafId===null&&await this.processGestureTracking()}getModelNode(){const e=this;return{get coordinates(){return e.coordinates},get gesture(){return e.gesture}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ge=512;class je extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"hands");h(this,"coordinates");h(this,"gesture");h(this,"handedness");h(this,"sourceCanvas");h(this,"downscaler",new $(Ge))}async getHandData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=[],d=a.handedness??a.handednesses??[];if(a.landmarks.forEach((u,S)=>{var f,w,p;if(!u||u.length===0)return;const M=u.map(k=>({x:B(k.x),y:B(1-k.y),z:-k.z})),R=(p=(w=(f=d[S])==null?void 0:f[0])==null?void 0:w.categoryName)==null?void 0:p.toLowerCase(),F=R==="left"||R==="right"?R:void 0,l=u[0].z<0?"closed_fist":"open_palm";o.push({coordinates:M,gesture:l,handedness:F})}),!o.length)return{hands:void 0,coordinates:void 0,gesture:void 0,handedness:void 0};const m=o[0];return{hands:o,coordinates:m.coordinates,gesture:m.gesture,handedness:m.handedness}}async processHandTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getHandData();e&&(this.hands=e.hands,this.coordinates=e.coordinates,this.gesture=e.gesture,this.handedness=e.handedness)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processHandTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processHandTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.hands=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0,this.handedness=void 0}async initialize(){const e=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),t=await H(new URL("/assets/xr/models/hand_tracking.task",E.assetStorageEndpoint).toString()),a=await _.HandLandmarker.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:2});this.landmarker=a}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t),this.rafId===null&&await this.processHandTracking()}getModelNode(){const e=this;return{get hands(){return e.hands},get coordinates(){return e.coordinates},get gesture(){return e.gesture},get handedness(){return e.handedness}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const We=24,Xe=720,Ye=[[255,255,255,255],[0,0,0,0]];class Qe extends G{constructor(){super();h(this,"segmenter",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"processCanvas");h(this,"filterCanvas");h(this,"inputSource");h(this,"inputSourceSize");h(this,"glCanvas");h(this,"drawingUtils");h(this,"useGpuMaskPath",!1);h(this,"maskImageData");h(this,"maskCanvas",null);h(this,"segmentationMaskTexture");h(this,"isMaskSetup",!1);h(this,"isProcessing",!1);h(this,"latestMask",null);h(this,"rawCache",null);h(this,"quality","medium");h(this,"stagingCanvas")}getQualityScaleFactor(){switch(this.quality){case"low":return .5;case"medium":return .75;case"high":return 1;default:return .5}}setInputSource(e){this.inputSource=e,this.inputSourceSize=e?this.readIntrinsicSize(e):void 0}readIntrinsicSize(e){if(e instanceof HTMLVideoElement)return e.videoWidth>0?{width:e.videoWidth,height:e.videoHeight}:void 0;if(e instanceof HTMLImageElement)return e.naturalWidth>0?{width:e.naturalWidth,height:e.naturalHeight}:void 0;const t=e.width,a=e.height;return typeof t=="number"&&t>0&&typeof a=="number"&&a>0?{width:t,height:a}:void 0}ensureProcessCanvasForInput(){if(!this.processCanvas||!this.inputSource)return;const e=this.readIntrinsicSize(this.inputSource);if(!e)return;this.inputSourceSize=e;const t=Math.min(1,Xe/Math.max(e.width,e.height)),a=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));this.processCanvas.width===a&&this.processCanvas.height===r||(this.processCanvas.width=a,this.processCanvas.height=r,this.glCanvas&&(this.glCanvas.width=a,this.glCanvas.height=r),this.maskImageData=void 0)}async processSegmentation(){if(this.disposed||!this.isProcessing||!this.maskCanvas||!this.processCanvas)return;if(!this.shouldRunInference()){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const e=this.inputSource??this.sourceCanvas;if(!this.segmenter||!e){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const t=performance.now();this.ensureProcessCanvasForInput();const a=this.processCanvas.getContext("2d");if(a){const d=this.processCanvas.width,m=this.processCanvas.height;if(a.clearRect(0,0,d,m),this.inputSource&&this.inputSourceSize){const{width:u,height:S}=this.inputSourceSize,M=Math.min(d/u,m/S),R=u*M,F=S*M;a.drawImage(this.inputSource,(d-R)/2,(m-F)/2,R,F)}else a.drawImage(e,0,0,d,m)}const o=this.segmenter.segmentForVideo(this.processCanvas,performance.now()).categoryMask;if(!o){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}if(this.rawCache=null,this.latestMask&&(this.latestMask.close(),this.latestMask=null),this.useGpuMaskPath&&this.drawingUtils&&this.glCanvas)this.drawingUtils.drawCategoryMask(o,Ye),this.latestMask=o.clone(),o.close(),this.blitGlToMask();else{this.latestMask=o.clone();const d=this.readMaskToImageData(o);o.close(),d&&this.blitImageDataToMask(d)}this.segmentationMaskTexture&&(this.isMaskSetup||(this.segmentationMaskTexture.format=P.RGBAFormat,this.segmentationMaskTexture.minFilter=P.LinearFilter,this.segmentationMaskTexture.magFilter=P.LinearFilter,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)))}blitGlToMask(){if(!this.maskCanvas||!this.filterCanvas||!this.glCanvas)return;const e=this.maskCanvas.getContext("2d"),t=this.filterCanvas.getContext("2d");!e||!t||(t.filter="blur(0.5px)",t.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),t.drawImage(this.glCanvas,0,0,this.filterCanvas.width,this.filterCanvas.height),e.clearRect(0,0,this.maskCanvas.width,this.maskCanvas.height),e.drawImage(this.filterCanvas,0,0,this.maskCanvas.width,this.maskCanvas.height))}readMaskToImageData(e){const t=e.getAsUint8Array(),{width:a,height:r}=e;if(!t||a<=0||r<=0)return null;(!this.maskImageData||this.maskImageData.width!==a||this.maskImageData.height!==r)&&(this.maskImageData=new ImageData(a,r));const o=this.maskImageData.data;for(let d=0;d<t.length;d+=1){const m=t[d]===255?0:255;o[d*4]=255,o[d*4+1]=m,o[d*4+2]=255,o[d*4+3]=m}return this.maskImageData}blitImageDataToMask(e){if(!this.maskCanvas||!this.filterCanvas)return;const t=this.maskCanvas.getContext("2d"),a=this.filterCanvas.getContext("2d");if(!t||!a)return;const r=this.getStagingCanvas(e.width,e.height),o=r.getContext("2d");o&&(o.putImageData(e,0,0),a.filter="blur(0.5px)",a.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),a.drawImage(r,0,0,this.filterCanvas.width,this.filterCanvas.height),t.clearRect(0,0,this.maskCanvas.width,this.maskCanvas.height),t.drawImage(this.filterCanvas,0,0,this.maskCanvas.width,this.maskCanvas.height))}getStagingCanvas(e,t){return this.stagingCanvas||(this.stagingCanvas=document.createElement("canvas")),this.stagingCanvas.width!==e&&(this.stagingCanvas.width=e),this.stagingCanvas.height!==t&&(this.stagingCanvas.height=t),this.stagingCanvas}resume(){this.paused&&(super.resume(),this.processSegmentation())}dispose(){if(super.dispose(),this.isProcessing=!1,this.latestMask){try{this.latestMask.close()}catch{}this.latestMask=null}if(this.rawCache=null,this.segmenter){try{this.segmenter.close()}catch{}this.segmenter=null}this.drawingUtils=void 0,this.glCanvas=void 0,this.maskImageData=void 0,this.segmentationMaskTexture&&(this.segmentationMaskTexture.dispose(),this.segmentationMaskTexture=void 0),this.sourceCanvas=void 0,this.inputSource=void 0,this.inputSourceSize=void 0,this.processCanvas=void 0,this.filterCanvas=void 0,this.stagingCanvas=void 0,this.maskCanvas=null}async initialize(e){this.quality=(e==null?void 0:e.quality)??"low";const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/segmentation.tflite",E.assetStorageEndpoint).toString());this.glCanvas=new OffscreenCanvas(1,1);const r=this.glCanvas.getContext("webgl2",{preserveDrawingBuffer:!0});this.segmenter=await _.ImageSegmenter.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},...r?{canvas:this.glCanvas}:{},outputCategoryMask:!0,outputConfidenceMasks:!1,runningMode:"VIDEO"}),r?(this.drawingUtils=new _.DrawingUtils(r),this.useGpuMaskPath=!0):this.useGpuMaskPath=!1}async run({sourceCanvas:e,renderWidth:t,renderHeight:a,targetFps:r}){var d;if(!e)return;this.setTargetFps(r??We),this.isProcessing=!1,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null);const o=this.getQualityScaleFactor();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=a,this.filterCanvas=document.createElement("canvas"),this.filterCanvas.width=t,this.filterCanvas.height=a,(d=this.segmentationMaskTexture)==null||d.dispose(),this.segmentationMaskTexture=new P.CanvasTexture(this.maskCanvas),this.isMaskSetup=!1,this.rawCache=null,this.isProcessing=!0,this.lastInferenceMs=0,this.rafId=requestAnimationFrame(this.processSegmentation.bind(this))}getRawSegmentationData(){if(this.rawCache)return this.rawCache;if(!this.latestMask)return null;const e=this.latestMask.getAsUint8Array();return this.rawCache={maskData:e,width:this.latestMask.width,height:this.latestMask.height},this.rawCache}getModelNode(){const e=this;return{get backgroundSegmentationMask(){return e.segmentationMaskTexture},getMaskCanvas:()=>e.maskCanvas,getRawSegmentationData:()=>e.getRawSegmentationData(),setInputSource:t=>e.setInputSource(t??void 0)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const ae={[L.BACKGROUND_SEGMENTATION]:Qe,[L.HAND_TRACKER]:je,[L.GESTURE_TRACKER]:He,[L.FACE_TRACKER]:Be,[L.BODY_TRACKER]:Oe},Ze=async n=>{const s=document.createElement("video");s.srcObject=n,s.muted=!0,s.playsInline=!0,s.autoplay=!0,await new Promise(t=>{s.onloadedmetadata=()=>{s.play(),t()}});const e=s;return await new Promise(t=>{const a=setTimeout(t,150),r=()=>{clearTimeout(a),t()};typeof e.requestVideoFrameCallback=="function"?e.requestVideoFrameCallback(r):requestAnimationFrame(()=>requestAnimationFrame(()=>r()))}),s},$e=n=>{const s=new P.CanvasTexture(n);return s.colorSpace=P.SRGBColorSpace,s.format=P.RGBAFormat,s.minFilter=P.LinearFilter,s.magFilter=P.LinearFilter,s.generateMipmaps=!1,s.needsUpdate=!0,s},Je=(n,s)=>{const e=n.videoWidth,t=n.videoHeight;e>0&&t>0&&(s.width!==e&&(s.width=e),s.height!==t&&(s.height=t));const a=s.getContext("2d",{colorSpace:"srgb"});a.save(),a.scale(-1,1),a.drawImage(n,-s.width,0,s.width,s.height),a.restore()},et=(n,s,e=1)=>{const t=s.getContext("2d",{colorSpace:"srgb"}),a=s.width/s.height,r=n.width/n.height;let o,d;r>a?(d=s.height,o=n.width*(s.height/n.height)):(o=s.width,d=n.height*(s.width/n.width));const m=Number.isFinite(e)&&e>0?e:1;o*=m,d*=m;const u=(s.width-o)/2,S=(s.height-d)/2;t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,s.width,s.height),t.drawImage(n,0,0,n.width,n.height,u,S,o,d)},tt=n=>{switch(n instanceof DOMException?n.name:""){case"NotAllowedError":case"PermissionDeniedError":return"permission-denied";case"NotReadableError":case"TrackStartError":return"camera-in-use";case"NotFoundError":case"DevicesNotFoundError":return"no-camera";case"NotSupportedError":case"SecurityError":return"unsupported";default:return n instanceof TypeError?"unsupported":"unknown"}},st={"permission-denied":"Camera access was blocked. Allow camera permissions in your browser, then refresh.","camera-in-use":"Camera is already in use by another app or browser tab. Close it and refresh.","no-camera":"No camera was found on this device.",unsupported:"Unable to access camera. Allow camera permissions in your browser, then refresh.",unknown:"Unable to access camera. Allow camera permissions in your browser, then refresh."},nt=(n,s,e)=>{const t=new Map;let a=!1;const r=(l,f)=>{var w;try{(w=f.dispose)==null||w.call(f)}catch(p){console.warn(`[xr-sdk registry] dispose threw for ${l}`,p)}};return{acquire:async(l,f,w)=>{let p=t.get(l);if(p)return p.refs.add(f),p.activeRefs.add(f),p.initPromise;const k=s[l];if(!k)throw new Error(`Invalid model: ${l}`);const C=new k,K=new Set([f]),V=new Set([f]),U=(async()=>{await C.initialize(w);const N=t.get(l);if(!N||N.model!==C||N.refs.size===0)return r(l,C),C;e&&await e(l,C);const T=t.get(l);return T&&T.refs.size>0&&n.setPipeline(z=>z.set(l,C)),C})();return p={model:C,refs:K,activeRefs:V,initPromise:U,options:w},t.set(l,p),U.catch(()=>{t.get(l)===p&&(t.delete(l),n.setPipeline(T=>T.delete(l))),r(l,C)}),U},release:(l,f)=>{const w=t.get(l);w&&(w.refs.delete(f),w.activeRefs.delete(f)&&w.refs.size>0&&w.activeRefs.size===0&&w.model.pause(),!(w.refs.size>0)&&(t.delete(l),r(l,w.model),n.setPipeline(p=>p.delete(l))))},setActive:(l,f,w)=>{const p=t.get(l);if(!p||!p.refs.has(f))return;const k=p.activeRefs.size>0;w?p.activeRefs.add(f):p.activeRefs.delete(f);const C=p.activeRefs.size>0;k!==C&&(C&&!a?p.model.resume():p.model.pause())},suspendAll:()=>{a=!0;for(const l of t.values())l.model.pause()},resumeActive:()=>{a=!1;for(const l of t.values())l.activeRefs.size>0&&l.model.resume()},get:l=>{var f;return(f=t.get(l))==null?void 0:f.model},getOptions:l=>{var f;return(f=t.get(l))==null?void 0:f.options},releaseAll:()=>{for(const l of Array.from(t.keys())){const f=t.get(l);f&&(f.refs.clear(),t.delete(l),r(l,f.model))}n.setPipeline(l=>l.clear())}}},it={lifecycle:"idle",ready:!1,error:void 0,cameraTexture:void 0,renderWidth:0,renderHeight:0,source:void 0,sourceKind:void 0,pipeline:new Map},at=()=>{let n={...it,pipeline:new Map};const s=new Set,e=()=>{s.forEach(t=>t())};return{getSnapshot:()=>n,set:t=>{let a=!1;for(const r of Object.keys(t))if(t[r]!==n[r]){a=!0;break}a&&(n={...n,...t},e())},setPipeline:t=>{const a=new Map(n.pipeline);return t(a),n={...n,pipeline:a},e(),a},subscribe:t=>(s.add(t),()=>{s.delete(t)})}},rt=({renderHeight:n,renderWidth:s,videoHeight:e,videoWidth:t})=>({height:n||e,width:s||t}),ot=n=>{const s=new Fe({verbose:!0}),e=at();let t=n;const a=i=>{var g;const c=(g=T.getOptions(i))==null?void 0:g.targetFps;return typeof c=="number"?c:t==null?void 0:t.targetFps};let r,o,d,m,u,S,M,R,F,l,f,w=!1,p=!1,k=0;const C=new Set,K=new Set,V=i=>{const c=e.getSnapshot().cameraTexture;c&&c.dispose();const g=$e(i);return e.set({cameraTexture:g}),g},U=async(i,c)=>{if(C.has(i)||e.getSnapshot().lifecycle!=="running"||!u)return;C.add(i);const g=k;try{await c.run({sourceCanvas:u,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:a(i)}),p&&(await new Promise(v=>requestAnimationFrame(()=>v())),await new Promise(v=>requestAnimationFrame(()=>v())),p&&k===g&&T.suspendAll())}catch(v){throw C.delete(i),v}},T=nt(e,ae,(i,c)=>U(i,c));e.subscribe(()=>{if(e.getSnapshot().lifecycle!=="running")return;const i=e.getSnapshot().pipeline;for(const[c,g]of i.entries())C.has(c)||U(c,g)});const z=()=>{if(f!==void 0&&(cancelAnimationFrame(f),f=void 0),o){try{o.pause()}catch{}try{o.srcObject=null}catch{}o=void 0}if(d){try{d.getTracks().forEach(i=>i.stop())}catch{}d=void 0}},j=()=>{if(w||!o||!m||!u)return;const i=window.__xr_debugger_metrics;if(i!=null&&i.trackCameraFrame&&i.trackCameraFrame(),(e.getSnapshot().sourceKind??"webcam")==="webcam")Je(o,m);else{const v=m.getContext("2d");if(!v)return;const y=o.videoWidth,A=o.videoHeight;m.width!==y&&(m.width=y),m.height!==A&&(m.height=A),v.setTransform(1,0,0,1,0,0),v.clearRect(0,0,y,A),v.drawImage(o,0,0,y,A)}et(m,u,(t==null?void 0:t.cameraZoom)??1.2);const g=e.getSnapshot().cameraTexture;g&&(g.needsUpdate=!0)},J=()=>{if(!o||!m||!u)return;if(p){j();return}const i=()=>{f=requestAnimationFrame(i),j()};f=requestAnimationFrame(i)},de=async i=>{if(i.source===x.WEBCAM)try{const c=t!=null&&t.camRes&&t.camRes>0?t.camRes:960;return await navigator.mediaDevices.getUserMedia({video:{facingMode:"user",frameRate:{min:24,ideal:30,max:60},width:{ideal:c}}})}catch(c){const g=tt(c),v=st[g];throw e.set({error:{error:"PermissionError",message:v,reason:g}}),new I(c instanceof Error?c.message:"getUserMedia failed")}return i.stream},W=async i=>{const c=await de(i);d=c;const g=await Ze(c);o=g,m=new OffscreenCanvas(g.videoWidth,g.videoHeight);const{renderWidth:v,renderHeight:y}=e.getSnapshot(),A=rt({renderWidth:v,renderHeight:y,videoWidth:g.videoWidth,videoHeight:g.videoHeight});u?(u.width!==A.width||u.height!==A.height)&&(u.width=A.width,u.height=A.height,V(u)):(u=new OffscreenCanvas(A.width,A.height),V(u));const ne=i.source===x.STREAM?i.static===!0:!1;p=ne,r=i.source===x.WEBCAM?{source:x.WEBCAM,sourceKind:"webcam"}:{source:x.STREAM,stream:i.stream,static:ne,sourceKind:i.sourceKind??"webcam"},e.set({source:i.source,sourceKind:r.sourceKind,error:void 0})},X=async i=>{const c=i.sourceKind??"webcam";u=i.canvas;const g=V(u);e.set({cameraTexture:g,source:x.CANVAS,sourceKind:c,renderWidth:u.width,renderHeight:u.height,error:void 0}),r={source:x.CANVAS,canvas:i.canvas,sourceKind:c}},le=(i,c)=>!c||i.source!==c.source?!1:i.source===x.STREAM&&c.source===x.STREAM?i.stream===c.stream&&(i.sourceKind??"webcam")===c.sourceKind:!0,ge=async()=>{if(!u)return;const i=k,c=e.getSnapshot().pipeline;for(const[,g]of c.entries())g.resume();await new Promise(g=>requestAnimationFrame(()=>g())),await new Promise(g=>requestAnimationFrame(()=>g())),p&&k===i&&T.suspendAll()},me=(i,c)=>!c||c.source!==x.CANVAS?!1:i.canvas===c.canvas&&(i.sourceKind??"webcam")===c.sourceKind,fe=async i=>{const c=i.source;if(c!==x.WEBCAM&&c!==x.STREAM)throw new I(`Invalid media source: ${String(c)}`);if(le(i,r)){s.log("Media source unchanged, skipping rebind.");return}k+=1;const{lifecycle:g}=e.getSnapshot();if(g==="idle"||g==="stopped"){await W(i),e.set({lifecycle:"media-bound"}),s.log("Media source set to:",i.source);return}if(g==="media-bound"){z(),await W(i),s.log("Media source rebound to:",i.source);return}w=!0,await new Promise(v=>requestAnimationFrame(()=>v())),z(),await W(i),w=!1,J(),p?await ge():T.resumeActive(),s.log("Media source swapped to:",i.source)},pe=async i=>{if(me(i,r)){s.log("Frame source unchanged, skipping rebind.");return}k+=1;const{lifecycle:c}=e.getSnapshot();if(c==="idle"||c==="stopped"){await X(i),e.set({lifecycle:"media-bound"}),s.log("Frame source set to canvas.");return}if(c==="media-bound"){z(),await X(i),s.log("Frame source rebound to canvas.");return}w=!0,await new Promise(g=>requestAnimationFrame(()=>g())),z(),await X(i),w=!1,s.log("Frame source swapped to canvas.")},ve=async()=>{const{lifecycle:i}=e.getSnapshot();if(i==="running")return;if(i==="idle")throw new I("session.start() called before setMediaSource — call setMediaSource first");if(!u)throw new I("session.start(): media source not bound");const c=(r==null?void 0:r.source)===x.CANVAS;if(!c&&(!o||!m))throw i==="stopped"?new I("session.start() called from stopped state without a media source — call setMediaSource first"):new I("session.start(): media source not bound");c||J(),T.resumeActive(),e.set({lifecycle:"running"}),await new Promise(v=>requestAnimationFrame(()=>v()));const g=e.getSnapshot().pipeline;for(const[v,y]of g.entries())await U(v,y);e.set({ready:!0}),s.log("XR session started.")},ee=async()=>{const{lifecycle:i}=e.getSnapshot();i==="stopped"||i==="idle"||(z(),T.suspendAll(),e.set({lifecycle:"stopped",ready:!1}),s.log("XR session stopped."))},we=async()=>{await ee(),T.releaseAll(),K.clear();const i=e.getSnapshot().cameraTexture;i&&i.dispose(),C.clear(),r=void 0,k+=1,u=void 0,m=void 0,p=!1,e.set({lifecycle:"idle",cameraTexture:void 0,source:void 0}),s.log("XR session reset.")},Ce=async i=>{const c="legacy:registerXRPipeline",g=[];await Promise.all(i.map(async v=>{const{model:y}=v;if(!ae[y])throw new I(`Invalid model: ${y}`);K.has(y)||g.push(y);const A="options"in v?v.options:void 0;await T.acquire(y,c,A)})),g.length>0&&(g.forEach(v=>K.add(v)),s.log("XR pipeline registered."))},Se=i=>{const c=T.get(i);if(!c)throw new I(`Model ${i} is not registered in the pipeline`);return c.getModelNode()},te=async(i,c)=>{i<=0||c<=0||(e.set({renderWidth:i,renderHeight:c}),u&&(u.width!==i||u.height!==c)&&(u.width=i,u.height=c,V(u),p&&j()),s.log(`Source canvas set. Render size: ${i}x${c}`))},ke=async i=>{var y;S=i;const c=(y=i.getBoundingClientRect)==null?void 0:y.call(i),g=c&&c.width>0?Math.round(c.width):i.clientWidth,v=c&&c.height>0?Math.round(c.height):i.clientHeight;await te(g,v)},ye=i=>{M=i.renderer,R=i.scene,F=i.camera,l=i.renderFrame},se=()=>{if(!M||!R||!F)throw new I("XR frame render requested before the R3F state was bound — make sure <XRScene> is mounted");l?l():M.render(R,F)};return{store:e,registry:T,setMediaSource:fe,start:ve,stop:ee,reset:we,setFrameSource:pe,registerXRPipeline:Ce,getModelNode:Se,captureFrame:()=>{if(!S)throw new I("session.captureFrame() called before the XRScene render target was bound — make sure <XRScene> is mounted");if(!M||!R||!F)throw new I("session.captureFrame() called before the R3F state was bound — make sure <XRScene> is mounted");return se(),S.toDataURL("image/png")},getInputFrame:()=>u??null,_setRenderTarget:ke,_setRenderSize:te,_setR3FState:ye,_renderFrame:se,_getVideoElement:()=>o,_setPerf:i=>{if(t=i,e.getSnapshot().lifecycle!=="running"||!u)return;const c=e.getSnapshot().pipeline;for(const[g,v]of c.entries())v.run({sourceCanvas:u,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:a(g)})}}},ct=n=>{const s=b.useRef(n),e=b.useMemo(()=>ot(s.current),[]),t=JSON.stringify(n??{});return b.useEffect(()=>{e._setPerf(n)},[e,t]),e},Z=new Map,ht=()=>({register:(n,s)=>{s?Z.set(n,s):Z.delete(n)},resolve:n=>n?Z.get(n)??null:null}),oe=ht(),ce=b.createContext(null),ut=({children:n})=>{const s=b.useRef(new Map),e=b.useCallback((r,o)=>{o?s.current.set(r,o):s.current.delete(r)},[]),t=b.useCallback(r=>r?s.current.get(r)??null:null,[]),a=b.useMemo(()=>({register:e,resolve:t}),[e,t]);return b.createElement(ce.Provider,{value:a},n)},he=()=>b.useContext(ce)??oe,dt=()=>he().register,lt=()=>he().resolve;oe.register;const ue=b.createContext(void 0),gt=()=>{const n=b.useContext(ue);if(!n)throw new I("XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?");return n},mt=({children:n,perf:s})=>{const e=ct(s),t=b.useMemo(()=>({session:e}),[e]);return ie.jsx(ue.Provider,{value:t,children:ie.jsx(ut,{children:n})})};exports.XRMediaSource=x;exports.XRModel=L;exports.XRProvider=mt;exports.fetchAndVerify=re;exports.libConfig=E;exports.unprojectToZZero=Ae;exports.unprojectToZZeroInto=q;exports.useRegisterRuntimeObject=dt;exports.useResolveRuntimeObject=lt;exports.useXRContext=gt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const w=require("react/jsx-runtime"),_=require("@react-three/fiber"),p=require("react"),H=require("three"),O=require("./renderLayers-lDtL0_43.cjs"),S=require("./index-
|
|
1
|
+
"use strict";const w=require("react/jsx-runtime"),_=require("@react-three/fiber"),p=require("react"),H=require("three"),O=require("./renderLayers-lDtL0_43.cjs"),S=require("./index-ZaDEzDtR.cjs");function D(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const h=D(H),q=["face.center","face.forehead","face.noseTip","face.chin","face.leftEyeOuter","face.rightEyeOuter","face.leftCheek","face.rightCheek","face.mouthCenter","face.leftEye","face.rightEye","face.leftEarlobe","face.rightEarlobe","face.custom"],v=["hand.wrist","hand.thumbTip","hand.indexTip","hand.middleTip","hand.ringTip","hand.pinkyTip","hand.indexBase","hand.middleBase","hand.ringBase","hand.pinkyBase"],z=["body.head","body.neck","body.leftShoulder","body.rightShoulder","body.leftElbow","body.rightElbow","body.leftWrist","body.rightWrist","body.leftHip","body.rightHip","body.leftKnee","body.rightKnee","body.leftAnkle","body.rightAnkle"],A=e=>e.startsWith("face.")?"face":e.startsWith("hand.")?"hand":e.startsWith("body.")?"body":null,N={target:"face.center",customAnchorPoint:{x:0,y:0,z:0},offset:{x:0,y:0,z:0},smoothing:0,followFaceRoll:!1},R=(e,r,n)=>r+n*(e-r),E=(e,r)=>1/(1+1/(2*Math.PI*e)/r),C=(e,r,n,a,T,t)=>{if(!e.initialized||n<=0)return e.pos.copy(r),e.prevRaw.copy(r),e.dxHat.set(0,0,0),e.initialized=!0,e;const c=E(t,n),u=["x","y","z"];for(const o of u){const l=(r[o]-e.prevRaw[o])/n,i=R(l,e.dxHat[o],c);e.dxHat[o]=i;const f=a+T*Math.abs(i),d=E(f,n);e.pos[o]=R(r[o],e.pos[o],d),e.prevRaw[o]=r[o]}return e},m=(e,r,n,a)=>C(e,r,n,a*.1,.5,1),F=({target:e,customAnchorPoint:r,offset:n,smoothing:a=0,children:T})=>{const t=S.useTrackerContext(),c=p.useRef(null),u=p.useRef(!1),o=p.useRef(new h.Vector3),l=p.useRef({pos:new h.Vector3,prevRaw:new h.Vector3,dxHat:new h.Vector3,initialized:!1}),i=A(e),f=t!==null&&i!==null&&t.type!==i,d=t===null,b=d||f||i===null;return p.useEffect(()=>{d?console.warn(`[TrackingAnchor] target "${e}" requires a FaceTracker / HandTracker / BodyTracker ancestor; rendering null.`):f?console.warn(`[TrackingAnchor] target "${e}" namespace does not match parent tracker type "${t==null?void 0:t.type}"; rendering null.`):i===null&&console.warn(`[TrackingAnchor] target "${e}" is not a recognized face/hand/body landmark; rendering null.`)},[e,i,d,f,t==null?void 0:t.type]),_.useFrame((G,k)=>{if(b||!c.current||!t)return;const y=t.resolveLandmark(e,r);if(!y){c.current.visible=!1,u.current=!1,l.current.initialized=!1;return}c.current.visible=!0;const s=o.current.copy(y.position),g=c.current.parent;if(g){g.updateMatrixWorld();const x=new h.Matrix4().copy(g.matrixWorld).invert();s.applyMatrix4(x)}n&&(s.x+=n[0],s.y+=n[1],s.z+=n[2]),a>0?(m(l.current,s,u.current?k:0,a),c.current.position.copy(l.current.pos)):c.current.position.copy(s),u.current=!0,y.quaternion&&c.current.quaternion.copy(y.quaternion)}),b?null:w.jsx("group",{ref:c,renderOrder:O.RENDER_LAYERS.TRACKED,children:T})};exports.BODY_TARGETS=z;exports.DEFAULT_TRACKING_ANCHOR=N;exports.FACE_TARGETS=q;exports.HAND_TARGETS=v;exports.TrackingAnchor=F;exports.getTargetNamespace=A;exports.stepTrackingSmoothing=m;
|