@omnidotdev/rdk 0.12.2 → 0.14.0
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/build/engine/useXRStore.d.ts +2 -0
- package/build/engine/useXRStore.d.ts.map +1 -1
- package/build/engine-EvzyijbY.cjs +1 -0
- package/build/engine-NEJZ-OgD.js +11 -0
- package/build/engine.cjs +1 -0
- package/build/engine.d.ts +2 -0
- package/build/engine.js +3 -0
- package/build/{fiducial-C7jQpZcK.js → fiducial-7pF-ErgE.js} +12 -11
- package/build/fiducial-Tris7XAY.cjs +1 -0
- package/build/fiducial.cjs +1 -1
- package/build/fiducial.js +1 -2
- package/build/geolocation/GeoLine.d.ts +14 -1
- package/build/geolocation/GeoLine.d.ts.map +1 -1
- package/build/geolocation/GeoPolygon.d.ts +14 -1
- package/build/geolocation/GeoPolygon.d.ts.map +1 -1
- package/build/geolocation/GeolocationSession.d.ts.map +1 -1
- package/build/geolocation/geolocationBackend.d.ts +8 -2
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/{geolocation-DbT8iR2H.js → geolocation-C_n3zwq4.js} +134 -102
- package/build/geolocation-D0RxA8Tv.cjs +1 -0
- package/build/geolocation.cjs +1 -1
- package/build/geolocation.js +1 -2
- package/build/{immersive-DZ9J_acN.js → immersive-CoSRZ58s.js} +1 -1
- package/build/{immersive-ikuE6hTP.cjs → immersive-DMYGUy_v.cjs} +1 -1
- package/build/immersive.cjs +1 -1
- package/build/immersive.js +1 -2
- package/build/index.cjs +1 -1
- package/build/index.js +9 -16
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts +3 -0
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts.map +1 -1
- package/build/magic/magicBackend.d.ts.map +1 -1
- package/build/magic-B9pQnRYJ.cjs +1 -0
- package/build/{magic-DAyR255x.js → magic-CjnX9lWp.js} +45 -50
- package/build/magic.cjs +1 -1
- package/build/magic.js +1 -2
- package/build/{useXRStore-CousLTRl.js → useXRStore-BTnI1ZM2.js} +2 -1
- package/build/{useXRStore-XWI97jRe.cjs → useXRStore-Cf_XL0aI.cjs} +1 -1
- package/build/{vision-DmoN9LKO.cjs → vision-BLWMU9Ys.cjs} +1 -1
- package/build/{vision-Dogx4i9B.js → vision-Vp2iuVNJ.js} +16 -15
- package/build/vision.cjs +1 -1
- package/build/vision.js +1 -2
- package/package.json +11 -5
- package/build/fiducial-C4M9sMNn.cjs +0 -1
- package/build/geolocation-BKCHn-Gq.cjs +0 -1
- package/build/magic-Brm3MYTP.cjs +0 -1
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { i as e, r as t } from "./useXRStore-
|
|
1
|
+
import { i as e, r as t } from "./useXRStore-BTnI1ZM2.js";
|
|
2
2
|
import { useEffect as n, useRef as r } from "react";
|
|
3
3
|
import { useFrame as i, useThree as a } from "@react-three/fiber";
|
|
4
4
|
import { jsx as o } from "react/jsx-runtime";
|
|
5
5
|
import * as s from "three";
|
|
6
6
|
//#region src/magic/magicBackend.ts
|
|
7
7
|
var c = .15, l = .5, u = (t) => {
|
|
8
|
-
let n = null, r = null, i = null, a
|
|
8
|
+
let n = null, r = null, i = null, a = t?.enableOrientation ?? !0, o = !1, u = t?.enableWorldAnchoring ?? !0, d = null, f = null, p = t?.smoothingFactor ?? c, m = t?.deadZone ?? l, h = {
|
|
9
9
|
alpha: 0,
|
|
10
10
|
beta: 0,
|
|
11
11
|
gamma: 0
|
|
12
|
-
},
|
|
12
|
+
}, g = {
|
|
13
13
|
alpha: 0,
|
|
14
14
|
beta: 0,
|
|
15
15
|
gamma: 0
|
|
16
|
-
},
|
|
16
|
+
}, _ = {
|
|
17
17
|
alpha: 0,
|
|
18
18
|
beta: 0,
|
|
19
19
|
gamma: 0
|
|
20
|
-
},
|
|
20
|
+
}, v = !1, y = null, b = null, x = new s.Quaternion(), S = new s.Quaternion(), C = new s.Euler(), w = new s.Quaternion(), T = new s.Quaternion(-Math.sqrt(.5), 0, 0, Math.sqrt(.5)), E = new s.Vector3(0, 0, 1), D = new s.Quaternion(), O = new s.Quaternion(), k = (e, t, n, r) => {
|
|
21
21
|
let i = (screen.orientation?.angle ?? 0) * Math.PI / 180;
|
|
22
|
-
|
|
23
|
-
},
|
|
22
|
+
C.set(n, t, -r, "YXZ"), e.setFromEuler(C), e.multiply(T), e.multiply(w.setFromAxisAngle(E, -i));
|
|
23
|
+
}, A = (e, t) => {
|
|
24
24
|
let n = (t - e) % 360 + 360;
|
|
25
25
|
return n = (n + 180) % 360 - 180, n;
|
|
26
|
-
},
|
|
26
|
+
}, j = (e, t, n = !1) => Math.abs(n ? A(e, t) : t - e) < m ? e : t, M = (e, t, n) => e + (t - e) * n, N = (e, t, n) => ((e + A(e, t) * n) % 360 + 360) % 360, P = async () => {
|
|
27
27
|
let e = DeviceOrientationEvent;
|
|
28
28
|
if (typeof e.requestPermission == "function") try {
|
|
29
|
-
return await e.requestPermission() === "granted" ? (
|
|
29
|
+
return await e.requestPermission() === "granted" ? (o = !0, !0) : (console.warn("[MagicBackend] Device orientation permission denied"), !1);
|
|
30
30
|
} catch (e) {
|
|
31
31
|
return console.error("[MagicBackend] Error requesting orientation permission:", e), !1;
|
|
32
32
|
}
|
|
33
|
-
return
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
33
|
+
return o = !0, !0;
|
|
34
|
+
}, F = () => {
|
|
35
|
+
d = (e) => {
|
|
36
|
+
if (h.alpha = e.alpha ?? 0, h.beta = e.beta ?? 0, h.gamma = e.gamma ?? 0, !v && (h.alpha !== 0 || h.beta !== 0 || h.gamma !== 0)) {
|
|
37
|
+
_.alpha = h.alpha, _.beta = h.beta, _.gamma = h.gamma;
|
|
38
38
|
let { degToRad: e } = s.MathUtils;
|
|
39
|
-
|
|
39
|
+
k(D, e(h.alpha), e(h.beta), e(h.gamma)), O.copy(D).invert(), v = !0;
|
|
40
40
|
}
|
|
41
|
-
}, window.addEventListener("deviceorientation",
|
|
42
|
-
},
|
|
41
|
+
}, window.addEventListener("deviceorientation", d, !0);
|
|
42
|
+
}, I = async (e, a) => {
|
|
43
43
|
let o = t?.webcamConstraints ?? { video: { facingMode: "environment" } };
|
|
44
44
|
try {
|
|
45
45
|
i = await navigator.mediaDevices.getUserMedia(o);
|
|
@@ -51,78 +51,73 @@ var c = .15, l = .5, u = (t) => {
|
|
|
51
51
|
return {
|
|
52
52
|
type: e.MAGIC,
|
|
53
53
|
async init({ scene: e, camera: t, renderer: n }) {
|
|
54
|
-
if (
|
|
54
|
+
if (y = t, b = e, await I(e, n), a) if (await P()) F();
|
|
55
55
|
else {
|
|
56
56
|
let e = async () => {
|
|
57
|
-
document.removeEventListener("click", e), document.removeEventListener("touchend", e),
|
|
57
|
+
document.removeEventListener("click", e), document.removeEventListener("touchend", e), f = null, await P() && F();
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
f = e, document.addEventListener("click", e), document.addEventListener("touchend", e);
|
|
60
60
|
}
|
|
61
|
-
let r = () => {
|
|
62
|
-
if (!x || !b) return;
|
|
63
|
-
let e = window.innerWidth, t = window.innerHeight;
|
|
64
|
-
x.setSize(e, t, !1), b.aspect = e / t, b.updateProjectionMatrix?.();
|
|
65
|
-
};
|
|
66
|
-
r(), window.addEventListener("resize", r), a = r;
|
|
67
61
|
},
|
|
68
62
|
update() {
|
|
69
|
-
if (!
|
|
70
|
-
let e =
|
|
71
|
-
if (
|
|
63
|
+
if (!a || !o) return;
|
|
64
|
+
let e = j(g.alpha, h.alpha, !0), t = j(g.beta, h.beta), n = j(g.gamma, h.gamma);
|
|
65
|
+
if (g.alpha = N(g.alpha, e, p), g.beta = M(g.beta, t, p), g.gamma = M(g.gamma, n, p), u && y && v) {
|
|
72
66
|
let { degToRad: e } = s.MathUtils;
|
|
73
|
-
|
|
67
|
+
k(x, e(h.alpha), e(h.beta), e(h.gamma)), S.copy(O).multiply(x), y.quaternion.slerp(S, p);
|
|
74
68
|
}
|
|
75
69
|
r && (r.needsUpdate = !0);
|
|
76
70
|
},
|
|
77
71
|
dispose() {
|
|
78
|
-
if (
|
|
72
|
+
if (d &&= (window.removeEventListener("deviceorientation", d), null), f &&= (document.removeEventListener("click", f), document.removeEventListener("touchend", f), null), i) {
|
|
79
73
|
for (let e of i.getTracks()) e.stop();
|
|
80
74
|
i = null;
|
|
81
75
|
}
|
|
82
|
-
n &&= (n.pause(), n.srcObject = null, n.parentNode?.removeChild(n), null), r &&= (r.dispose(), null),
|
|
76
|
+
n &&= (n.pause(), n.srcObject = null, n.parentNode?.removeChild(n), null), r &&= (r.dispose(), null), b && (b.background = null), y = null, b = null, a = !1, o = !1, u = !1, v = !1, g.alpha = 0, g.beta = 0, g.gamma = 0, h.alpha = 0, h.beta = 0, h.gamma = 0, _.alpha = 0, _.beta = 0, _.gamma = 0, D.identity(), O.identity();
|
|
83
77
|
},
|
|
84
78
|
getInternal: () => ({
|
|
85
79
|
videoElement: n,
|
|
86
80
|
videoTexture: r,
|
|
87
81
|
stream: i,
|
|
88
|
-
orientationEnabled:
|
|
89
|
-
orientationPermissionGranted:
|
|
90
|
-
worldAnchoringEnabled:
|
|
91
|
-
currentOrientation: { ...
|
|
92
|
-
initialOrientation: { ...
|
|
93
|
-
hasInitialOrientation:
|
|
82
|
+
orientationEnabled: a,
|
|
83
|
+
orientationPermissionGranted: o,
|
|
84
|
+
worldAnchoringEnabled: u,
|
|
85
|
+
currentOrientation: { ...g },
|
|
86
|
+
initialOrientation: { ..._ },
|
|
87
|
+
hasInitialOrientation: v,
|
|
94
88
|
requestOrientationPermission: async () => {
|
|
95
|
-
let e = await
|
|
96
|
-
return e && !
|
|
89
|
+
let e = await P();
|
|
90
|
+
return e && !d && F(), e;
|
|
97
91
|
}
|
|
98
92
|
})
|
|
99
93
|
};
|
|
100
94
|
}, d = ({ options: e = {}, children: i }) => {
|
|
101
|
-
let { scene: o, camera: s, gl: c } = a(), { registerBackend:
|
|
102
|
-
return
|
|
103
|
-
if (
|
|
95
|
+
let { scene: o, camera: s, gl: c, size: l } = a(), { registerBackend: d, unregisterBackend: f } = t(), p = r(null), m = r(e);
|
|
96
|
+
return m.current = e, n(() => {
|
|
97
|
+
if (p.current) return;
|
|
104
98
|
let e = !1;
|
|
105
99
|
return (async () => {
|
|
106
100
|
try {
|
|
107
|
-
let t = u(
|
|
101
|
+
let t = u(m.current);
|
|
108
102
|
if (e) return;
|
|
109
|
-
await
|
|
103
|
+
await d(t, {
|
|
110
104
|
scene: o,
|
|
111
105
|
camera: s,
|
|
112
|
-
renderer: c
|
|
113
|
-
|
|
106
|
+
renderer: c,
|
|
107
|
+
size: l
|
|
108
|
+
}), p.current = t;
|
|
114
109
|
} catch (e) {
|
|
115
110
|
console.error("[MagicSession] Failed to initialize:", e);
|
|
116
111
|
}
|
|
117
112
|
})(), () => {
|
|
118
|
-
e = !0,
|
|
113
|
+
e = !0, p.current &&= (f(p.current), null);
|
|
119
114
|
};
|
|
120
115
|
}, [
|
|
121
116
|
o,
|
|
122
117
|
s,
|
|
123
118
|
c,
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
d,
|
|
120
|
+
f
|
|
126
121
|
]), i;
|
|
127
122
|
}, f = ({ position: n = [
|
|
128
123
|
0,
|
package/build/magic.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`})
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./magic-B9pQnRYJ.cjs`);exports.MagicSession=e.n,exports.WorldAnchor=e.t,exports.createMagicBackend=e.r;
|
package/build/magic.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);var l=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},u=(e=>e?l(e):l),d=e=>e;function f(e,t=d){let n=c.default.useSyncExternalStore(e.subscribe,c.default.useCallback(()=>t(e.getState()),[e,t]),c.default.useCallback(()=>t(e.getInitialState()),[e,t]));return c.default.useDebugValue(n),n}var p=e=>{let t=u(e),n=e=>f(t,e);return Object.assign(n,t),n},m=(e=>e?p(e):p),h=e=>(t,n,r)=>{let i=r.subscribe;return r.subscribe=((e,t,n)=>{let a=e;if(t){let i=n?.equalityFn||Object.is,o=e(r.getState());a=n=>{let r=e(n);if(!i(o,r)){let e=o;t(o=r,e)}},n?.fireImmediately&&t(o,o)}return i(a)}),e(t,n,r)},g=e=>Symbol.iterator in e,_=e=>`entries`in e,v=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},y=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function b(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:g(e)&&g(t)?_(e)&&_(t)?v(e,t):y(e,t):v({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function x(e){let t=c.default.useRef(void 0);return n=>{let r=e(n);return b(t.current,r)?t.current:t.current=r}}var S={FIDUCIAL:`fiducial`,GEOLOCATION:`geolocation`,IMMERSIVE:`immersive`,MAGIC:`magic`,VISION:`vision`},C=m()(h((e,t)=>({video:null,backends:new Map,immersiveStore:null,registerBackend:async(n,r)=>{try{let i=t(),a=new Set(i.backends.keys()),o=a.has(S.FIDUCIAL)||n.type===S.FIDUCIAL,s=a.has(S.GEOLOCATION)||n.type===S.GEOLOCATION;if(o&&s){let e=`❌ [RDK] INCOMPATIBLE SESSIONS: fiducial and geolocation backends cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.`;throw console.error(e),Error(e)}await n.init({scene:r.scene,camera:r.camera,renderer:r.renderer}),e(e=>{let t=new Map(e.backends);return t.set(n.type,n),{backends:t}})}catch(e){throw console.error(`[XRStore] Failed to register backend:`,e),e}},unregisterBackend:t=>{e(e=>{let n=new Map(e.backends);n.delete(t.type);try{t.dispose?.()}catch(e){console.error(`[XRStore] Error disposing backend:`,e)}return{backends:n}})},setVideo:t=>{e({video:t})},updateBackends:e=>{let{backends:n}=t();for(let t of n.values())try{t.update?.(e)}catch(e){console.error(`[XRStore] Backend update error:`,e)}},setImmersiveStore:t=>{e({immersiveStore:t})}}))),w=()=>C.getState(),T=C.subscribe,E=e=>C(x(t=>{let n={...t,isImmersive:t.backends.has(S.IMMERSIVE),immersive:t.immersiveStore||null};return e?e(n):n}));Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return w}});
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);var l=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},u=(e=>e?l(e):l),d=e=>e;function f(e,t=d){let n=c.default.useSyncExternalStore(e.subscribe,c.default.useCallback(()=>t(e.getState()),[e,t]),c.default.useCallback(()=>t(e.getInitialState()),[e,t]));return c.default.useDebugValue(n),n}var p=e=>{let t=u(e),n=e=>f(t,e);return Object.assign(n,t),n},m=(e=>e?p(e):p),h=e=>(t,n,r)=>{let i=r.subscribe;return r.subscribe=((e,t,n)=>{let a=e;if(t){let i=n?.equalityFn||Object.is,o=e(r.getState());a=n=>{let r=e(n);if(!i(o,r)){let e=o;t(o=r,e)}},n?.fireImmediately&&t(o,o)}return i(a)}),e(t,n,r)},g=e=>Symbol.iterator in e,_=e=>`entries`in e,v=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},y=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function b(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:g(e)&&g(t)?_(e)&&_(t)?v(e,t):y(e,t):v({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function x(e){let t=c.default.useRef(void 0);return n=>{let r=e(n);return b(t.current,r)?t.current:t.current=r}}var S={FIDUCIAL:`fiducial`,GEOLOCATION:`geolocation`,IMMERSIVE:`immersive`,MAGIC:`magic`,VISION:`vision`},C=m()(h((e,t)=>({video:null,backends:new Map,immersiveStore:null,registerBackend:async(n,r)=>{try{let i=t(),a=new Set(i.backends.keys()),o=a.has(S.FIDUCIAL)||n.type===S.FIDUCIAL,s=a.has(S.GEOLOCATION)||n.type===S.GEOLOCATION;if(o&&s){let e=`❌ [RDK] INCOMPATIBLE SESSIONS: fiducial and geolocation backends cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.`;throw console.error(e),Error(e)}await n.init({scene:r.scene,camera:r.camera,renderer:r.renderer,size:r.size}),e(e=>{let t=new Map(e.backends);return t.set(n.type,n),{backends:t}})}catch(e){throw console.error(`[XRStore] Failed to register backend:`,e),e}},unregisterBackend:t=>{e(e=>{let n=new Map(e.backends);n.delete(t.type);try{t.dispose?.()}catch(e){console.error(`[XRStore] Error disposing backend:`,e)}return{backends:n}})},setVideo:t=>{e({video:t})},updateBackends:e=>{let{backends:n}=t();for(let t of n.values())try{t.update?.(e)}catch(e){console.error(`[XRStore] Backend update error:`,e)}},setImmersiveStore:t=>{e({immersiveStore:t})}}))),w=()=>C.getState(),T=C.subscribe,E=e=>C(x(t=>{let n={...t,isImmersive:t.backends.has(S.IMMERSIVE),immersive:t.immersiveStore||null};return e?e(n):n}));Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return w}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./useXRStore-XWI97jRe.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`);var a=({constraints:e,onReady:n,onError:i,mirrored:a=!0})=>{let o=(0,t.useRef)(null),[s,c]=(0,t.useState)(!1),l=(0,t.useRef)(n);l.current=n;let u=(0,t.useRef)(i);return u.current=i,(0,t.useEffect)(()=>{let t=!1;return(async()=>{try{let n=await navigator.mediaDevices.getUserMedia({video:e||{width:{ideal:1280},height:{ideal:720},facingMode:`user`}});if(t||!o.current){for(let e of n.getTracks())e.stop();return}if(o.current.srcObject=n,await new Promise((e,t)=>{let n=o.current;if(!n){t(Error(`Video ref lost`));return}let r=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),e()},i=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),t(Error(`Video failed to load`))};n.addEventListener(`canplay`,r,{once:!0}),n.addEventListener(`error`,i,{once:!0})}),t)return;await o.current.play(),c(!0),l.current?.(o.current)}catch(e){if(t)return;let n=e instanceof Error?e:Error(`Failed to access camera`);console.error(`Camera error:`,n),u.current?.(n)}})(),()=>{if(t=!0,o.current?.srcObject){let e=o.current.srcObject;for(let t of e.getTracks())t.stop()}}},[e]),(0,r.jsx)(`video`,{ref:o,style:{position:`absolute`,inset:0,width:`100%`,height:`100%`,objectFit:`cover`,transform:a?`scaleX(-1)`:void 0,opacity:s?1:0,transition:`opacity 0.5s ease`},autoPlay:!0,playsInline:!0,muted:!0})},o=(e,t)=>e.y<t.y,s=e=>[Math.abs(e[4].x-e[9].x)>Math.abs(e[3].x-e[9].x),o(e[8],e[6]),o(e[12],e[10]),o(e[16],e[14]),o(e[20],e[18])],c=e=>{if(e.length<21)return null;let t=s(e);return t[0]&&!t[1]&&!t[2]&&!t[3]&&!t[4]?{gesture:`thumbs_up`,confidence:.9}:null},l=e=>{if(e.length<21)return null;let t=s(e);return!t[0]&&t[1]&&t[2]&&!t[3]&&!t[4]?{gesture:`peace`,confidence:.8}:null},u=e=>{if(e.length<21)return null;let t=s(e);return Math.sqrt((e[4].x-e[8].x)**2+(e[4].y-e[8].y)**2)<.05&&t[2]&&t[3]&&t[4]?{gesture:`ok`,confidence:.8}:null},d=e=>e.length<21?null:s(e).filter(Boolean).length===5?{gesture:`open_hand`,confidence:.7}:null,f=e=>e.length<21?null:s(e).filter(Boolean).length<=1?{gesture:`fist`,confidence:.7}:null,p=[c,l,u,d,f],m={gesture:`none`,confidence:0},h=(e,t=p)=>{let n=m;for(let r of t){let t=r(e);t&&t.confidence>n.confidence&&(n=t)}return n},g=(e,t,n,r=!0)=>{let i=t.width/t.height,a=n.width/n.height,o=a>i?a/i:1,s=a>i?1:i/a,c=.5+(e.x-.5)*o,l=.5+(e.y-.5)*s;return[(r?.5-c:c-.5)*t.width,(.5-l)*t.height,0]},_=e=>{let t=e.length||1,n=0,r=0,i=0;for(let t of e)n+=t.x,r+=t.y,i+=t.z??0;return{x:n/t,y:r/t,z:i/t}},v={isPending:!0,isSuccess:!1,provider:null,videoElement:null,onDetection:()=>()=>{}},y=()=>{let t=e.r(e=>e.backends).get(e.i.VISION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:v},b=({onHandMove:e,onGesture:a,landmarkIndex:o=9,mirror:s=!0,children:c})=>{let{onDetection:l,isSuccess:u}=y(),{viewport:d}=(0,n.useThree)(),f=(0,t.useRef)(null),p=(0,t.useRef)(new i.Vector3),m=(0,t.useRef)(``);return(0,t.useEffect)(()=>{if(u)return l(e=>{f.current=e})},[u,l]),(0,n.useFrame)(()=>{let t=f.current;if(!t)return;let n=t.hands[0];if(!n||n.landmarks.length===0)return;let[r,i,c]=g(n.landmarks[o]??n.landmarks[0],d,t.frameSize,s);p.current.set(r,i,c),e?.(p.current);let l=h(n.landmarks);l.gesture!==m.current&&(m.current=l.gesture,a?.(l.gesture,l.confidence))}),(0,r.jsx)(`group`,{children:c})},x=`person.bicycle.car.motorcycle.airplane.bus.train.truck.boat.traffic light.fire hydrant.stop sign.parking meter.bench.bird.cat.dog.horse.sheep.cow.elephant.bear.zebra.giraffe.backpack.umbrella.handbag.tie.suitcase.frisbee.skis.snowboard.sports ball.kite.baseball bat.baseball glove.skateboard.surfboard.tennis racket.bottle.wine glass.cup.fork.knife.spoon.bowl.banana.apple.sandwich.orange.broccoli.carrot.hot dog.pizza.donut.cake.chair.couch.potted plant.bed.dining table.toilet.tv.laptop.mouse.remote.keyboard.cell phone.microwave.oven.toaster.sink.refrigerator.book.clock.vase.scissors.teddy bear.hair drier.toothbrush`.split(`.`),S=(e,t={})=>({name:`yolo`,inputSize:640,labels:[...x],...t,path:e,decoder:`yolo`}),C=(e,t={})=>({name:`rf-detr`,inputSize:560,labels:[...x],...t,path:e,decoder:`rfdetr`}),w=(e,t={})=>({name:`yolo-seg`,inputSize:640,labels:[...x],...t,path:e,decoder:`yoloseg`}),T=e=>{let{isSuccess:n,onDetection:r}=y(),[i,a]=(0,t.useState)(null),o=e?.throttle??16,s=(0,t.useRef)(0);return(0,t.useEffect)(()=>{if(!n){a(null);return}return r(e=>{let t=performance.now();t-s.current<o||(s.current=t,a(e))})},[n,r,o]),i},E=478,D=(e,t)=>t===`faces`?e.faces:t===`poses`?e.poses:e.hands,O=({task:e,index:a=0,debug:o=!1,mirror:s=!0,smoothing:c=.4,children:l})=>{let{onDetection:u,isSuccess:d}=y(),{viewport:f}=(0,n.useThree)(),p=(0,t.useRef)(null),m=(0,t.useRef)(null),h=(0,t.useRef)(null),v=(0,t.useMemo)(()=>new i.Object3D,[]),b=(0,t.useMemo)(()=>new i.Vector3,[]);return(0,t.useEffect)(()=>{m.current&&(m.current.visible=!1),h.current&&(h.current.count=0)},[]),(0,t.useEffect)(()=>{if(d)return u(e=>{p.current=e})},[d,u]),(0,n.useFrame)(()=>{let t=p.current,n=m.current;if(!t||!n)return;let r=D(t,e)[a],i=h.current;if(!r||r.landmarks.length===0){n.visible=!1,i&&(i.count=0);return}let l=n.visible;n.visible=!0;let[u,d,y]=g(_(r.landmarks),f,t.frameSize,s);if(b.set(u,d,y),!l||c>=1?n.position.copy(b):n.position.lerp(b,c),o&&i){let e=n.position,a=Math.min(r.landmarks.length,E);for(let n=0;n<a;n++){let[a,o,c]=g(r.landmarks[n],f,t.frameSize,s);v.position.set(a-e.x,o-e.y,c-e.z),v.updateMatrix(),i.setMatrixAt(n,v.matrix)}i.count=a,i.instanceMatrix.needsUpdate=!0}}),(0,r.jsxs)(`group`,{ref:m,children:[l,o&&(0,r.jsxs)(`instancedMesh`,{ref:h,args:[void 0,void 0,E],children:[(0,r.jsx)(`sphereGeometry`,{args:[.02,6,6]}),(0,r.jsx)(`meshBasicMaterial`,{color:`#00ff88`})]})]})},k=({tasks:e,width:t=320,height:n=240,style:i})=>{let a=T({throttle:50});return(0,r.jsxs)(`div`,{style:{background:`rgba(0, 0, 0, 0.8)`,color:`#00ff88`,padding:`8px`,borderRadius:`8px`,fontFamily:`monospace`,fontSize:`0.75rem`,width:t,height:n,overflow:`auto`,...i},children:[(0,r.jsxs)(`div`,{children:[`Frame: `,a?`active`:`none`]}),a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{children:[`Size: `,a.frameSize.width,`x`,a.frameSize.height]}),e.includes(`hands`)&&(0,r.jsxs)(`div`,{children:[`Hands: `,a.hands.length]}),e.includes(`faces`)&&(0,r.jsxs)(`div`,{children:[`Faces: `,a.faces.length]}),e.includes(`poses`)&&(0,r.jsxs)(`div`,{children:[`Poses: `,a.poses.length]}),e.includes(`objects`)&&(0,r.jsxs)(`div`,{children:[`Objects: `,a.objects.length]})]})]})},A=class{type=`mediapipe`;models={};isInitialized=!1;isProcessing=!1;isDisposed=!1;videoElement=null;animationId=null;lastProcessTime=0;callbacks=[];options;constructor(e){this.options=e}async initialize(e){this.videoElement=e;let{FilesetResolver:t,HandLandmarker:n,FaceLandmarker:r,PoseLandmarker:i}=await import(`@mediapipe/tasks-vision`),a=await t.forVisionTasks(`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10/wasm`),o=this.options.useGpu??!0?`GPU`:`CPU`,s=async e=>{if(o===`CPU`)return e(`CPU`);try{return await e(`GPU`)}catch{return console.warn(`MediaPipe GPU delegate failed, falling back to CPU`),e(`CPU`)}},c=new Set(this.options.tasks??[`hands`,`faces`,`poses`]),l=[`hands`,`faces`,`poses`].filter(e=>c.has(e)),u=0;c.has(`hands`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`hand landmarker`}),this.models.handLandmarker=await s(e=>n.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,delegate:e},runningMode:`VIDEO`,numHands:2,minHandDetectionConfidence:.7,minHandPresenceConfidence:.5,minTrackingConfidence:.5}))),c.has(`faces`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`face landmarker`}),this.models.faceLandmarker=await s(e=>r.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task`,delegate:e},runningMode:`VIDEO`,numFaces:1,minFaceDetectionConfidence:.7,minFacePresenceConfidence:.5,minTrackingConfidence:.5,outputFaceBlendshapes:!1,outputFacialTransformationMatrixes:!1}))),c.has(`poses`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`pose landmarker`}),this.models.poseLandmarker=await s(e=>i.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task`,delegate:e},runningMode:`VIDEO`,numPoses:1,minPoseDetectionConfidence:.7,minPosePresenceConfidence:.5,minTrackingConfidence:.5,outputSegmentationMasks:this.options.segmentation??!1}))),this.isInitialized=!0,this.options.onProgress?.(null)}startDetection(){!this.isInitialized||!this.videoElement||this.isProcessing||(this.isProcessing=!0,this.processFrame())}stopDetection(){this.isProcessing=!1,this.animationId&&=(cancelAnimationFrame(this.animationId),null)}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.models.handLandmarker&&this.models.handLandmarker.close(),this.models.faceLandmarker&&this.models.faceLandmarker.close(),this.models.poseLandmarker&&this.models.poseLandmarker.close(),this.models={},this.videoElement=null,this.callbacks=[],this.isInitialized=!1,this.isProcessing=!1}processFrame=()=>{if(!this.isProcessing||!this.videoElement||this.isDisposed)return;let e=performance.now(),t=this.options.throttle??16;if(e-this.lastProcessTime<t){this.animationId=requestAnimationFrame(this.processFrame);return}let{videoWidth:n,videoHeight:r}=this.videoElement;if(n===0||r===0){this.animationId=requestAnimationFrame(this.processFrame);return}this.lastProcessTime=e;let i=e;try{let e={hands:[],faces:[],poses:[],objects:[],timestamp:i,frameSize:{width:n,height:r}};if(this.models.handLandmarker){let t=this.models.handLandmarker.detectForVideo(this.videoElement,i);e.hands=t.landmarks.map((e,n)=>({landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:t.handednesses?.[n]?.[0]?.score||.5}))}if(this.models.faceLandmarker&&(e.faces=this.models.faceLandmarker.detectForVideo(this.videoElement,i).faceLandmarks.map(e=>{let t=e.map(e=>e.x),n=e.map(e=>e.y),r=(Math.max(...t)-Math.min(...t))*(Math.max(...n)-Math.min(...n)),i=Math.min(.95,Math.max(.6,r*4));return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:i}})),this.models.poseLandmarker){let t=this.models.poseLandmarker.detectForVideo(this.videoElement,i);e.poses=t.landmarks.map(e=>{let t=0,n=0;for(let r of e)typeof r.visibility==`number`&&(t+=r.visibility,n++);let r=n>0?t/n:.5;return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:r}});let n=t.segmentationMasks?.[0];if(n){let t=new OffscreenCanvas(n.width,n.height).getContext(`2d`),r=n.getAsFloat32Array(),i=t.createImageData(n.width,n.height);for(let e=0;e<r.length;e++){let t=r[e]*255;i.data[e*4]=t,i.data[e*4+1]=t,i.data[e*4+2]=t,i.data[e*4+3]=255}e.segmentationMask=i}}this.handleResult(e)}catch(e){console.error(`Vision processing error:`,e)}this.animationId=requestAnimationFrame(this.processFrame)};handleResult(e){let t=this.options.minConfidence??.7,n=this.options.maxResults??2,r={...e,hands:e.hands.filter(e=>e.confidence>=t).slice(0,n),faces:e.faces.filter(e=>e.confidence>=t).slice(0,n),poses:e.poses.filter(e=>e.confidence>=t).slice(0,n),objects:[]};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in vision callback:`,e)}}},j=5e3,M=class{type=`onnx`;worker=null;isInitialized=!1;isDisposed=!1;isProcessing=!1;videoElement=null;animationId=null;loadedModels=new Map;lastProcessTime=0;processingStartTime=0;callbacks=[];options;messageHandler=null;pendingModelCallbacks=new Map;constructor(e){this.options=e}post(e,t){t?this.worker?.postMessage(e,t):this.worker?.postMessage(e)}async initialize(e){this.videoElement=e,this.worker=new Worker(new URL(`/assets/onnxWorker-BNjoneWr.js`,``+{}.url),{type:`module`}),await new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`ONNX worker initialization timeout`))},1e4);this.messageHandler=r=>{let i=r.data;switch(i.type){case`initialized`:clearTimeout(n),this.isInitialized=!0,e();break;case`result`:this.isProcessing=!1,this.handleResult(i.result);break;case`modelLoaded`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.resolve());break}case`modelError`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.reject(Error(i.error)));break}case`error`:this.isProcessing=!1,this.isInitialized?console.error(`ONNX worker error:`,i.error):(clearTimeout(n),t(Error(i.error)));break}},this.worker?.addEventListener(`message`,this.messageHandler),this.post({type:`init`})});let t=this.options.onnx?.models??[];for(let e of t)await this.loadModel(e)}startDetection(){if(!this.isInitialized||!this.videoElement){console.warn(`ONNX provider not initialized`);return}let e=()=>{if(!this.videoElement||!this.isInitialized)return;let t=Date.now(),n=this.options.throttle??100;if(t-this.lastProcessTime<n){this.animationId=requestAnimationFrame(e);return}this.isProcessing&&this.processingStartTime>0&&t-this.processingStartTime>j&&(console.warn(`ONNX processing stall detected, resetting`),this.isProcessing=!1),this.isProcessing||this.processCurrentFrame(),this.animationId=requestAnimationFrame(e)};e()}stopDetection(){this.animationId&&=(cancelAnimationFrame(this.animationId),null),this.isProcessing=!1}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.worker&&=(this.messageHandler&&=(this.worker.removeEventListener(`message`,this.messageHandler),null),this.post({type:`dispose`}),this.worker.terminate(),null),this.videoElement=null,this.callbacks.length=0,this.loadedModels.clear(),this.pendingModelCallbacks.clear(),this.isInitialized=!1}async loadModel(e){if(!this.worker)throw Error(`Worker not initialized`);let t=new Promise((t,n)=>{this.pendingModelCallbacks.set(e.name,{resolve:t,reject:n})});this.post({type:`loadModel`,model:e}),await t,this.loadedModels.set(e.name,e)}processCurrentFrame(){if(!this.videoElement||!this.worker||this.isProcessing)return;let e=Date.now();this.isProcessing=!0,this.lastProcessTime=e,this.processingStartTime=e;let{videoWidth:t,videoHeight:n}=this.videoElement;createImageBitmap(this.videoElement).then(e=>{if(this.isDisposed){e.close();return}this.post({type:`process`,imageBitmap:e,sourceWidth:t,sourceHeight:n,options:{minConfidence:this.options.minConfidence??.5,maxResults:this.options.maxResults??100}},[e])},e=>{this.isProcessing=!1,console.error(`Error creating ImageBitmap:`,e)})}handleResult(e){let t=this.options.minConfidence??.5,n=this.options.maxResults??100,r={hands:[],faces:[],poses:[],objects:e.detections.filter(e=>e.confidence>=t).sort((e,t)=>t.confidence-e.confidence).slice(0,n),masks:e.masks.length>0?e.masks:void 0,timestamp:e.timestamp,frameSize:e.frameSize,processingTime:e.processingTime};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in ONNX detection callback:`,e)}}},N=e=>e.provider===`onnx`?new M(e):new A(e),P=async e=>{let t=document.createElement(`video`);t.style.display=`none`,document.body.appendChild(t);try{return t.srcObject=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280,min:640},height:{ideal:720,min:480},facingMode:e.provider===`onnx`?`environment`:`user`,frameRate:{ideal:30,min:15}}}),t.playsInline=!0,t.muted=!0,await new Promise((e,n)=>{t.onloadedmetadata=()=>{t.play().then(e).catch(n)},t.onerror=n}),t}catch(e){throw document.body.removeChild(t),e}},F=e=>{if(!e)return;let t=e.srcObject;if(t)for(let e of t.getTracks())e.stop();e.parentNode&&e.parentNode.removeChild(e)},I=t=>{let n=null,r=null,i=!1,a=null,o=[],s=e=>(o.push(e),()=>{let t=o.indexOf(e);t>-1&&o.splice(t,1)});return{type:e.i.VISION,async init(e){t.videoElement?(r=t.videoElement,i=!1):(r=await P(t),i=!0),n=N(t),await n.initialize(r),a=n.onDetection(e=>{for(let t of o)try{t(e)}catch(e){console.error(`Error in vision detection callback:`,e)}}),n.startDetection()},update(e){},dispose(){a?.(),a=null,n?.dispose(),i&&F(r),r=null,n=null,o.length=0},getInternal:()=>({provider:n,videoElement:r,onDetection:s})}},L=({options:i,children:a,onError:o})=>{let{scene:s,camera:c,gl:l}=(0,n.useThree)(),{registerBackend:u,unregisterBackend:d}=e.r(),f=(0,t.useRef)(null),p=(0,t.useRef)(i);p.current=i;let m=(0,t.useRef)(o);return m.current=o,(0,t.useEffect)(()=>{if(f.current)return;let e=!1;return(async()=>{try{let t=I(p.current);if(e)return;if(await u(t,{scene:s,camera:c,renderer:l}),e){d(t);return}f.current=t}catch(e){let t=e instanceof Error?e:Error(String(e));console.error(`[VisionSession] Failed to initialize:`,t),m.current?.(t)}})(),()=>{e=!0,f.current&&=(d(f.current),null)}},[s,c,l,u,d]),(0,r.jsx)(r.Fragment,{children:a})},R=({tasks:e,progress:t,showDebug:n,onToggleDebug:i})=>{let a=T({throttle:100}),o=e=>{if(!a)return!1;switch(e){case`hands`:return a.hands.length>0;case`faces`:return a.faces.length>0;case`poses`:return a.poses.length>0;case`objects`:return a.objects.length>0;default:return!1}},s=e.some(o),c=a!==null;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{style:{position:`fixed`,top:`20px`,left:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,padding:`12px`,borderRadius:`8px`,fontFamily:`system-ui, sans-serif`,fontSize:`0.9rem`,zIndex:1e3},children:[(0,r.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,marginBottom:`8px`},children:[(0,r.jsx)(`div`,{style:{width:`8px`,height:`8px`,borderRadius:`50%`,background:c?`#00ff88`:`#ffaa00`}}),(0,r.jsx)(`span`,{children:s?`Active`:c?`Ready`:t?`Loading models (${t.step}/${t.total}) ${t.label}...`:`Starting...`})]}),e.map(e=>(0,r.jsxs)(`div`,{style:{fontSize:`0.8rem`,opacity:.8,display:`flex`,justifyContent:`space-between`,gap:`12px`},children:[(0,r.jsx)(`span`,{children:e}),(0,r.jsx)(`span`,{children:o(e)?`active`:c?`idle`:`...`})]},e))]}),(0,r.jsxs)(`button`,{onClick:i,type:`button`,style:{position:`fixed`,top:`20px`,right:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,border:`1px solid #333`,padding:`8px 12px`,borderRadius:`6px`,cursor:`pointer`,fontFamily:`system-ui, sans-serif`,fontSize:`0.8rem`,zIndex:1e3},children:[n?`Hide`:`Show`,` Debug`]})]})},z={},B=({tasks:e=[`hands`],options:i,children:o,showDebug:s=!1,cameraConstraints:c,canvasStyle:l=z,onReady:u,onError:d})=>{let[f,p]=(0,t.useState)(s),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)(null),v=(0,t.useRef)(u);v.current=u;let y=(0,t.useRef)(_);y.current=_;let b=(0,t.useCallback)(e=>y.current(e),[]),x=(0,t.useCallback)(e=>{h(e),v.current?.()},[]),S=(0,t.useMemo)(()=>({tasks:e,minConfidence:.6,maxResults:2,useGpu:!0,...i,videoElement:m??void 0,onProgress:b}),[e,i,m,b]);return(0,r.jsxs)(`div`,{style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,r.jsx)(a,{constraints:c,onReady:x,onError:d}),m&&(0,r.jsx)(n.Canvas,{style:{position:`absolute`,inset:0,pointerEvents:`none`,...l},camera:{position:[0,0,5],fov:75},gl:{alpha:!0,premultipliedAlpha:!1},children:(0,r.jsx)(V,{options:S,onError:d,children:o})}),(0,r.jsx)(R,{tasks:e,progress:g,showDebug:f,onToggleDebug:()=>p(e=>!e)}),f&&(0,r.jsx)(k,{tasks:e,width:320,height:240,style:{position:`fixed`,bottom:`80px`,right:`20px`,maxWidth:`calc(100vw - 40px)`,overflow:`hidden`}})]})},V=({options:e,onError:t,children:n})=>(0,r.jsxs)(L,{options:e,onError:t,children:[(0,r.jsx)(`ambientLight`,{intensity:.6}),(0,r.jsx)(`directionalLight`,{position:[10,10,10],intensity:.8}),n]});Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return u}});
|
|
1
|
+
const e=require(`./useXRStore-Cf_XL0aI.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`);var a=({constraints:e,onReady:n,onError:i,mirrored:a=!0})=>{let o=(0,t.useRef)(null),[s,c]=(0,t.useState)(!1),l=(0,t.useRef)(n);l.current=n;let u=(0,t.useRef)(i);return u.current=i,(0,t.useEffect)(()=>{let t=!1;return(async()=>{try{let n=await navigator.mediaDevices.getUserMedia({video:e||{width:{ideal:1280},height:{ideal:720},facingMode:`user`}});if(t||!o.current){for(let e of n.getTracks())e.stop();return}if(o.current.srcObject=n,await new Promise((e,t)=>{let n=o.current;if(!n){t(Error(`Video ref lost`));return}let r=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),e()},i=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),t(Error(`Video failed to load`))};n.addEventListener(`canplay`,r,{once:!0}),n.addEventListener(`error`,i,{once:!0})}),t)return;await o.current.play(),c(!0),l.current?.(o.current)}catch(e){if(t)return;let n=e instanceof Error?e:Error(`Failed to access camera`);console.error(`Camera error:`,n),u.current?.(n)}})(),()=>{if(t=!0,o.current?.srcObject){let e=o.current.srcObject;for(let t of e.getTracks())t.stop()}}},[e]),(0,r.jsx)(`video`,{ref:o,style:{position:`absolute`,inset:0,width:`100%`,height:`100%`,objectFit:`cover`,transform:a?`scaleX(-1)`:void 0,opacity:s?1:0,transition:`opacity 0.5s ease`},autoPlay:!0,playsInline:!0,muted:!0})},o=(e,t)=>e.y<t.y,s=e=>[Math.abs(e[4].x-e[9].x)>Math.abs(e[3].x-e[9].x),o(e[8],e[6]),o(e[12],e[10]),o(e[16],e[14]),o(e[20],e[18])],c=e=>{if(e.length<21)return null;let t=s(e);return t[0]&&!t[1]&&!t[2]&&!t[3]&&!t[4]?{gesture:`thumbs_up`,confidence:.9}:null},l=e=>{if(e.length<21)return null;let t=s(e);return!t[0]&&t[1]&&t[2]&&!t[3]&&!t[4]?{gesture:`peace`,confidence:.8}:null},u=e=>{if(e.length<21)return null;let t=s(e);return Math.sqrt((e[4].x-e[8].x)**2+(e[4].y-e[8].y)**2)<.05&&t[2]&&t[3]&&t[4]?{gesture:`ok`,confidence:.8}:null},d=e=>e.length<21?null:s(e).filter(Boolean).length===5?{gesture:`open_hand`,confidence:.7}:null,f=e=>e.length<21?null:s(e).filter(Boolean).length<=1?{gesture:`fist`,confidence:.7}:null,p=[c,l,u,d,f],m={gesture:`none`,confidence:0},h=(e,t=p)=>{let n=m;for(let r of t){let t=r(e);t&&t.confidence>n.confidence&&(n=t)}return n},g=(e,t,n,r=!0)=>{let i=t.width/t.height,a=n.width/n.height,o=a>i?a/i:1,s=a>i?1:i/a,c=.5+(e.x-.5)*o,l=.5+(e.y-.5)*s;return[(r?.5-c:c-.5)*t.width,(.5-l)*t.height,0]},_=e=>{let t=e.length||1,n=0,r=0,i=0;for(let t of e)n+=t.x,r+=t.y,i+=t.z??0;return{x:n/t,y:r/t,z:i/t}},v={isPending:!0,isSuccess:!1,provider:null,videoElement:null,onDetection:()=>()=>{}},y=()=>{let t=e.r(e=>e.backends).get(e.i.VISION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:v},b=({onHandMove:e,onGesture:a,landmarkIndex:o=9,mirror:s=!0,children:c})=>{let{onDetection:l,isSuccess:u}=y(),{viewport:d}=(0,n.useThree)(),f=(0,t.useRef)(null),p=(0,t.useRef)(new i.Vector3),m=(0,t.useRef)(``);return(0,t.useEffect)(()=>{if(u)return l(e=>{f.current=e})},[u,l]),(0,n.useFrame)(()=>{let t=f.current;if(!t)return;let n=t.hands[0];if(!n||n.landmarks.length===0)return;let[r,i,c]=g(n.landmarks[o]??n.landmarks[0],d,t.frameSize,s);p.current.set(r,i,c),e?.(p.current);let l=h(n.landmarks);l.gesture!==m.current&&(m.current=l.gesture,a?.(l.gesture,l.confidence))}),(0,r.jsx)(`group`,{children:c})},x=`person.bicycle.car.motorcycle.airplane.bus.train.truck.boat.traffic light.fire hydrant.stop sign.parking meter.bench.bird.cat.dog.horse.sheep.cow.elephant.bear.zebra.giraffe.backpack.umbrella.handbag.tie.suitcase.frisbee.skis.snowboard.sports ball.kite.baseball bat.baseball glove.skateboard.surfboard.tennis racket.bottle.wine glass.cup.fork.knife.spoon.bowl.banana.apple.sandwich.orange.broccoli.carrot.hot dog.pizza.donut.cake.chair.couch.potted plant.bed.dining table.toilet.tv.laptop.mouse.remote.keyboard.cell phone.microwave.oven.toaster.sink.refrigerator.book.clock.vase.scissors.teddy bear.hair drier.toothbrush`.split(`.`),S=(e,t={})=>({name:`yolo`,inputSize:640,labels:[...x],...t,path:e,decoder:`yolo`}),C=(e,t={})=>({name:`rf-detr`,inputSize:560,labels:[...x],...t,path:e,decoder:`rfdetr`}),w=(e,t={})=>({name:`yolo-seg`,inputSize:640,labels:[...x],...t,path:e,decoder:`yoloseg`}),T=e=>{let{isSuccess:n,onDetection:r}=y(),[i,a]=(0,t.useState)(null),o=e?.throttle??16,s=(0,t.useRef)(0);return(0,t.useEffect)(()=>{if(!n){a(null);return}return r(e=>{let t=performance.now();t-s.current<o||(s.current=t,a(e))})},[n,r,o]),i},E=478,D=(e,t)=>t===`faces`?e.faces:t===`poses`?e.poses:e.hands,O=({task:e,index:a=0,debug:o=!1,mirror:s=!0,smoothing:c=.4,children:l})=>{let{onDetection:u,isSuccess:d}=y(),{viewport:f}=(0,n.useThree)(),p=(0,t.useRef)(null),m=(0,t.useRef)(null),h=(0,t.useRef)(null),v=(0,t.useMemo)(()=>new i.Object3D,[]),b=(0,t.useMemo)(()=>new i.Vector3,[]);return(0,t.useEffect)(()=>{m.current&&(m.current.visible=!1),h.current&&(h.current.count=0)},[]),(0,t.useEffect)(()=>{if(d)return u(e=>{p.current=e})},[d,u]),(0,n.useFrame)(()=>{let t=p.current,n=m.current;if(!t||!n)return;let r=D(t,e)[a],i=h.current;if(!r||r.landmarks.length===0){n.visible=!1,i&&(i.count=0);return}let l=n.visible;n.visible=!0;let[u,d,y]=g(_(r.landmarks),f,t.frameSize,s);if(b.set(u,d,y),!l||c>=1?n.position.copy(b):n.position.lerp(b,c),o&&i){let e=n.position,a=Math.min(r.landmarks.length,E);for(let n=0;n<a;n++){let[a,o,c]=g(r.landmarks[n],f,t.frameSize,s);v.position.set(a-e.x,o-e.y,c-e.z),v.updateMatrix(),i.setMatrixAt(n,v.matrix)}i.count=a,i.instanceMatrix.needsUpdate=!0}}),(0,r.jsxs)(`group`,{ref:m,children:[l,o&&(0,r.jsxs)(`instancedMesh`,{ref:h,args:[void 0,void 0,E],children:[(0,r.jsx)(`sphereGeometry`,{args:[.02,6,6]}),(0,r.jsx)(`meshBasicMaterial`,{color:`#00ff88`})]})]})},k=({tasks:e,width:t=320,height:n=240,style:i})=>{let a=T({throttle:50});return(0,r.jsxs)(`div`,{style:{background:`rgba(0, 0, 0, 0.8)`,color:`#00ff88`,padding:`8px`,borderRadius:`8px`,fontFamily:`monospace`,fontSize:`0.75rem`,width:t,height:n,overflow:`auto`,...i},children:[(0,r.jsxs)(`div`,{children:[`Frame: `,a?`active`:`none`]}),a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{children:[`Size: `,a.frameSize.width,`x`,a.frameSize.height]}),e.includes(`hands`)&&(0,r.jsxs)(`div`,{children:[`Hands: `,a.hands.length]}),e.includes(`faces`)&&(0,r.jsxs)(`div`,{children:[`Faces: `,a.faces.length]}),e.includes(`poses`)&&(0,r.jsxs)(`div`,{children:[`Poses: `,a.poses.length]}),e.includes(`objects`)&&(0,r.jsxs)(`div`,{children:[`Objects: `,a.objects.length]})]})]})},A=class{type=`mediapipe`;models={};isInitialized=!1;isProcessing=!1;isDisposed=!1;videoElement=null;animationId=null;lastProcessTime=0;callbacks=[];options;constructor(e){this.options=e}async initialize(e){this.videoElement=e;let{FilesetResolver:t,HandLandmarker:n,FaceLandmarker:r,PoseLandmarker:i}=await import(`@mediapipe/tasks-vision`),a=await t.forVisionTasks(`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10/wasm`),o=this.options.useGpu??!0?`GPU`:`CPU`,s=async e=>{if(o===`CPU`)return e(`CPU`);try{return await e(`GPU`)}catch{return console.warn(`MediaPipe GPU delegate failed, falling back to CPU`),e(`CPU`)}},c=new Set(this.options.tasks??[`hands`,`faces`,`poses`]),l=[`hands`,`faces`,`poses`].filter(e=>c.has(e)),u=0;c.has(`hands`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`hand landmarker`}),this.models.handLandmarker=await s(e=>n.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,delegate:e},runningMode:`VIDEO`,numHands:2,minHandDetectionConfidence:.7,minHandPresenceConfidence:.5,minTrackingConfidence:.5}))),c.has(`faces`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`face landmarker`}),this.models.faceLandmarker=await s(e=>r.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task`,delegate:e},runningMode:`VIDEO`,numFaces:1,minFaceDetectionConfidence:.7,minFacePresenceConfidence:.5,minTrackingConfidence:.5,outputFaceBlendshapes:!1,outputFacialTransformationMatrixes:!1}))),c.has(`poses`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`pose landmarker`}),this.models.poseLandmarker=await s(e=>i.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task`,delegate:e},runningMode:`VIDEO`,numPoses:1,minPoseDetectionConfidence:.7,minPosePresenceConfidence:.5,minTrackingConfidence:.5,outputSegmentationMasks:this.options.segmentation??!1}))),this.isInitialized=!0,this.options.onProgress?.(null)}startDetection(){!this.isInitialized||!this.videoElement||this.isProcessing||(this.isProcessing=!0,this.processFrame())}stopDetection(){this.isProcessing=!1,this.animationId&&=(cancelAnimationFrame(this.animationId),null)}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.models.handLandmarker&&this.models.handLandmarker.close(),this.models.faceLandmarker&&this.models.faceLandmarker.close(),this.models.poseLandmarker&&this.models.poseLandmarker.close(),this.models={},this.videoElement=null,this.callbacks=[],this.isInitialized=!1,this.isProcessing=!1}processFrame=()=>{if(!this.isProcessing||!this.videoElement||this.isDisposed)return;let e=performance.now(),t=this.options.throttle??16;if(e-this.lastProcessTime<t){this.animationId=requestAnimationFrame(this.processFrame);return}let{videoWidth:n,videoHeight:r}=this.videoElement;if(n===0||r===0){this.animationId=requestAnimationFrame(this.processFrame);return}this.lastProcessTime=e;let i=e;try{let e={hands:[],faces:[],poses:[],objects:[],timestamp:i,frameSize:{width:n,height:r}};if(this.models.handLandmarker){let t=this.models.handLandmarker.detectForVideo(this.videoElement,i);e.hands=t.landmarks.map((e,n)=>({landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:t.handednesses?.[n]?.[0]?.score||.5}))}if(this.models.faceLandmarker&&(e.faces=this.models.faceLandmarker.detectForVideo(this.videoElement,i).faceLandmarks.map(e=>{let t=e.map(e=>e.x),n=e.map(e=>e.y),r=(Math.max(...t)-Math.min(...t))*(Math.max(...n)-Math.min(...n)),i=Math.min(.95,Math.max(.6,r*4));return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:i}})),this.models.poseLandmarker){let t=this.models.poseLandmarker.detectForVideo(this.videoElement,i);e.poses=t.landmarks.map(e=>{let t=0,n=0;for(let r of e)typeof r.visibility==`number`&&(t+=r.visibility,n++);let r=n>0?t/n:.5;return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:r}});let n=t.segmentationMasks?.[0];if(n){let t=new OffscreenCanvas(n.width,n.height).getContext(`2d`),r=n.getAsFloat32Array(),i=t.createImageData(n.width,n.height);for(let e=0;e<r.length;e++){let t=r[e]*255;i.data[e*4]=t,i.data[e*4+1]=t,i.data[e*4+2]=t,i.data[e*4+3]=255}e.segmentationMask=i}}this.handleResult(e)}catch(e){console.error(`Vision processing error:`,e)}this.animationId=requestAnimationFrame(this.processFrame)};handleResult(e){let t=this.options.minConfidence??.7,n=this.options.maxResults??2,r={...e,hands:e.hands.filter(e=>e.confidence>=t).slice(0,n),faces:e.faces.filter(e=>e.confidence>=t).slice(0,n),poses:e.poses.filter(e=>e.confidence>=t).slice(0,n),objects:[]};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in vision callback:`,e)}}},j=5e3,M=class{type=`onnx`;worker=null;isInitialized=!1;isDisposed=!1;isProcessing=!1;videoElement=null;animationId=null;loadedModels=new Map;lastProcessTime=0;processingStartTime=0;callbacks=[];options;messageHandler=null;pendingModelCallbacks=new Map;constructor(e){this.options=e}post(e,t){t?this.worker?.postMessage(e,t):this.worker?.postMessage(e)}async initialize(e){this.videoElement=e,this.worker=new Worker(new URL(`/assets/onnxWorker-BNjoneWr.js`,``+{}.url),{type:`module`}),await new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`ONNX worker initialization timeout`))},1e4);this.messageHandler=r=>{let i=r.data;switch(i.type){case`initialized`:clearTimeout(n),this.isInitialized=!0,e();break;case`result`:this.isProcessing=!1,this.handleResult(i.result);break;case`modelLoaded`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.resolve());break}case`modelError`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.reject(Error(i.error)));break}case`error`:this.isProcessing=!1,this.isInitialized?console.error(`ONNX worker error:`,i.error):(clearTimeout(n),t(Error(i.error)));break}},this.worker?.addEventListener(`message`,this.messageHandler),this.post({type:`init`})});let t=this.options.onnx?.models??[];for(let e of t)await this.loadModel(e)}startDetection(){if(!this.isInitialized||!this.videoElement){console.warn(`ONNX provider not initialized`);return}let e=()=>{if(!this.videoElement||!this.isInitialized)return;let t=Date.now(),n=this.options.throttle??100;if(t-this.lastProcessTime<n){this.animationId=requestAnimationFrame(e);return}this.isProcessing&&this.processingStartTime>0&&t-this.processingStartTime>j&&(console.warn(`ONNX processing stall detected, resetting`),this.isProcessing=!1),this.isProcessing||this.processCurrentFrame(),this.animationId=requestAnimationFrame(e)};e()}stopDetection(){this.animationId&&=(cancelAnimationFrame(this.animationId),null),this.isProcessing=!1}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.worker&&=(this.messageHandler&&=(this.worker.removeEventListener(`message`,this.messageHandler),null),this.post({type:`dispose`}),this.worker.terminate(),null),this.videoElement=null,this.callbacks.length=0,this.loadedModels.clear(),this.pendingModelCallbacks.clear(),this.isInitialized=!1}async loadModel(e){if(!this.worker)throw Error(`Worker not initialized`);let t=new Promise((t,n)=>{this.pendingModelCallbacks.set(e.name,{resolve:t,reject:n})});this.post({type:`loadModel`,model:e}),await t,this.loadedModels.set(e.name,e)}processCurrentFrame(){if(!this.videoElement||!this.worker||this.isProcessing)return;let e=Date.now();this.isProcessing=!0,this.lastProcessTime=e,this.processingStartTime=e;let{videoWidth:t,videoHeight:n}=this.videoElement;createImageBitmap(this.videoElement).then(e=>{if(this.isDisposed){e.close();return}this.post({type:`process`,imageBitmap:e,sourceWidth:t,sourceHeight:n,options:{minConfidence:this.options.minConfidence??.5,maxResults:this.options.maxResults??100}},[e])},e=>{this.isProcessing=!1,console.error(`Error creating ImageBitmap:`,e)})}handleResult(e){let t=this.options.minConfidence??.5,n=this.options.maxResults??100,r={hands:[],faces:[],poses:[],objects:e.detections.filter(e=>e.confidence>=t).sort((e,t)=>t.confidence-e.confidence).slice(0,n),masks:e.masks.length>0?e.masks:void 0,timestamp:e.timestamp,frameSize:e.frameSize,processingTime:e.processingTime};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in ONNX detection callback:`,e)}}},N=e=>e.provider===`onnx`?new M(e):new A(e),P=async e=>{let t=document.createElement(`video`);t.style.display=`none`,document.body.appendChild(t);try{return t.srcObject=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280,min:640},height:{ideal:720,min:480},facingMode:e.provider===`onnx`?`environment`:`user`,frameRate:{ideal:30,min:15}}}),t.playsInline=!0,t.muted=!0,await new Promise((e,n)=>{t.onloadedmetadata=()=>{t.play().then(e).catch(n)},t.onerror=n}),t}catch(e){throw document.body.removeChild(t),e}},F=e=>{if(!e)return;let t=e.srcObject;if(t)for(let e of t.getTracks())e.stop();e.parentNode&&e.parentNode.removeChild(e)},I=t=>{let n=null,r=null,i=!1,a=null,o=[],s=e=>(o.push(e),()=>{let t=o.indexOf(e);t>-1&&o.splice(t,1)});return{type:e.i.VISION,async init(e){t.videoElement?(r=t.videoElement,i=!1):(r=await P(t),i=!0),n=N(t),await n.initialize(r),a=n.onDetection(e=>{for(let t of o)try{t(e)}catch(e){console.error(`Error in vision detection callback:`,e)}}),n.startDetection()},update(e){},dispose(){a?.(),a=null,n?.dispose(),i&&F(r),r=null,n=null,o.length=0},getInternal:()=>({provider:n,videoElement:r,onDetection:s})}},L=({options:i,children:a,onError:o})=>{let{scene:s,camera:c,gl:l,size:u}=(0,n.useThree)(),{registerBackend:d,unregisterBackend:f}=e.r(),p=(0,t.useRef)(null),m=(0,t.useRef)(i);m.current=i;let h=(0,t.useRef)(o);return h.current=o,(0,t.useEffect)(()=>{if(p.current)return;let e=!1;return(async()=>{try{let t=I(m.current);if(e)return;if(await d(t,{scene:s,camera:c,renderer:l,size:u}),e){f(t);return}p.current=t}catch(e){let t=e instanceof Error?e:Error(String(e));console.error(`[VisionSession] Failed to initialize:`,t),h.current?.(t)}})(),()=>{e=!0,p.current&&=(f(p.current),null)}},[s,c,l,d,f]),(0,r.jsx)(r.Fragment,{children:a})},R=({tasks:e,progress:t,showDebug:n,onToggleDebug:i})=>{let a=T({throttle:100}),o=e=>{if(!a)return!1;switch(e){case`hands`:return a.hands.length>0;case`faces`:return a.faces.length>0;case`poses`:return a.poses.length>0;case`objects`:return a.objects.length>0;default:return!1}},s=e.some(o),c=a!==null;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{style:{position:`fixed`,top:`20px`,left:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,padding:`12px`,borderRadius:`8px`,fontFamily:`system-ui, sans-serif`,fontSize:`0.9rem`,zIndex:1e3},children:[(0,r.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,marginBottom:`8px`},children:[(0,r.jsx)(`div`,{style:{width:`8px`,height:`8px`,borderRadius:`50%`,background:c?`#00ff88`:`#ffaa00`}}),(0,r.jsx)(`span`,{children:s?`Active`:c?`Ready`:t?`Loading models (${t.step}/${t.total}) ${t.label}...`:`Starting...`})]}),e.map(e=>(0,r.jsxs)(`div`,{style:{fontSize:`0.8rem`,opacity:.8,display:`flex`,justifyContent:`space-between`,gap:`12px`},children:[(0,r.jsx)(`span`,{children:e}),(0,r.jsx)(`span`,{children:o(e)?`active`:c?`idle`:`...`})]},e))]}),(0,r.jsxs)(`button`,{onClick:i,type:`button`,style:{position:`fixed`,top:`20px`,right:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,border:`1px solid #333`,padding:`8px 12px`,borderRadius:`6px`,cursor:`pointer`,fontFamily:`system-ui, sans-serif`,fontSize:`0.8rem`,zIndex:1e3},children:[n?`Hide`:`Show`,` Debug`]})]})},z={},B=({tasks:e=[`hands`],options:i,children:o,showDebug:s=!1,cameraConstraints:c,canvasStyle:l=z,onReady:u,onError:d})=>{let[f,p]=(0,t.useState)(s),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)(null),v=(0,t.useRef)(u);v.current=u;let y=(0,t.useRef)(_);y.current=_;let b=(0,t.useCallback)(e=>y.current(e),[]),x=(0,t.useCallback)(e=>{h(e),v.current?.()},[]),S=(0,t.useMemo)(()=>({tasks:e,minConfidence:.6,maxResults:2,useGpu:!0,...i,videoElement:m??void 0,onProgress:b}),[e,i,m,b]);return(0,r.jsxs)(`div`,{style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,r.jsx)(a,{constraints:c,onReady:x,onError:d}),m&&(0,r.jsx)(n.Canvas,{style:{position:`absolute`,inset:0,pointerEvents:`none`,...l},camera:{position:[0,0,5],fov:75},gl:{alpha:!0,premultipliedAlpha:!1},children:(0,r.jsx)(V,{options:S,onError:d,children:o})}),(0,r.jsx)(R,{tasks:e,progress:g,showDebug:f,onToggleDebug:()=>p(e=>!e)}),f&&(0,r.jsx)(k,{tasks:e,width:320,height:240,style:{position:`fixed`,bottom:`80px`,right:`20px`,maxWidth:`calc(100vw - 40px)`,overflow:`hidden`}})]})},V=({options:e,onError:t,children:n})=>(0,r.jsxs)(L,{options:e,onError:t,children:[(0,r.jsx)(`ambientLight`,{intensity:.6}),(0,r.jsx)(`directionalLight`,{position:[10,10,10],intensity:.8}),n]});Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return u}});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as e, r as t } from "./useXRStore-
|
|
1
|
+
import { i as e, r as t } from "./useXRStore-BTnI1ZM2.js";
|
|
2
2
|
import { useCallback as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
|
|
3
3
|
import { Canvas as s, useFrame as c, useThree as l } from "@react-three/fiber";
|
|
4
4
|
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
@@ -647,38 +647,39 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
|
|
|
647
647
|
})
|
|
648
648
|
};
|
|
649
649
|
}, q = ({ options: e, children: n, onError: i }) => {
|
|
650
|
-
let { scene: o, camera: s, gl: c } = l(), { registerBackend:
|
|
651
|
-
|
|
652
|
-
let
|
|
653
|
-
return
|
|
654
|
-
if (
|
|
650
|
+
let { scene: o, camera: s, gl: c, size: f } = l(), { registerBackend: p, unregisterBackend: m } = t(), h = a(null), g = a(e);
|
|
651
|
+
g.current = e;
|
|
652
|
+
let _ = a(i);
|
|
653
|
+
return _.current = i, r(() => {
|
|
654
|
+
if (h.current) return;
|
|
655
655
|
let e = !1;
|
|
656
656
|
return (async () => {
|
|
657
657
|
try {
|
|
658
|
-
let t = K(
|
|
658
|
+
let t = K(g.current);
|
|
659
659
|
if (e) return;
|
|
660
|
-
if (await
|
|
660
|
+
if (await p(t, {
|
|
661
661
|
scene: o,
|
|
662
662
|
camera: s,
|
|
663
|
-
renderer: c
|
|
663
|
+
renderer: c,
|
|
664
|
+
size: f
|
|
664
665
|
}), e) {
|
|
665
|
-
|
|
666
|
+
m(t);
|
|
666
667
|
return;
|
|
667
668
|
}
|
|
668
|
-
|
|
669
|
+
h.current = t;
|
|
669
670
|
} catch (e) {
|
|
670
671
|
let t = e instanceof Error ? e : Error(String(e));
|
|
671
|
-
console.error("[VisionSession] Failed to initialize:", t),
|
|
672
|
+
console.error("[VisionSession] Failed to initialize:", t), _.current?.(t);
|
|
672
673
|
}
|
|
673
674
|
})(), () => {
|
|
674
|
-
e = !0,
|
|
675
|
+
e = !0, h.current &&= (m(h.current), null);
|
|
675
676
|
};
|
|
676
677
|
}, [
|
|
677
678
|
o,
|
|
678
679
|
s,
|
|
679
680
|
c,
|
|
680
|
-
|
|
681
|
-
|
|
681
|
+
p,
|
|
682
|
+
m
|
|
682
683
|
]), /* @__PURE__ */ d(u, { children: n });
|
|
683
684
|
}, J = ({ tasks: e, progress: t, showDebug: n, onToggleDebug: r }) => {
|
|
684
685
|
let i = F({ throttle: 100 }), a = (e) => {
|
package/build/vision.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`})
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./vision-BLWMU9Ys.cjs`);exports.COCO_LABELS=e.c,exports.CameraBackground=e.C,exports.DEFAULT_GESTURES=e._,exports.HandTracker=e.f,exports.VisionAnchor=e.o,exports.VisionDebug=e.a,exports.VisionOverlay=e.t,exports.VisionSession=e.r,exports.VisionStatus=e.n,exports.createVisionBackend=e.i,exports.detectGesture=e.g,exports.fist=e.v,exports.landmarkToWorld=e.m,exports.landmarksCentroid=e.h,exports.ok=e.y,exports.openHand=e.b,exports.peace=e.x,exports.rfDetr=e.l,exports.thumbsUp=e.S,exports.useVisionBackend=e.p,exports.useVisionFrame=e.s,exports.yolo=e.u,exports.yoloSeg=e.d;
|
package/build/vision.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { C as e, S as t, _ as n, a as r, b as i, c as a, d as o, f as s, g as c, h as l, i as u, l as d, m as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y, v as b, x, y as S } from "./vision-Dogx4i9B.js";
|
|
1
|
+
import { C as e, S as t, _ as n, a as r, b as i, c as a, d as o, f as s, g as c, h as l, i as u, l as d, m as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y, v as b, x, y as S } from "./vision-Vp2iuVNJ.js";
|
|
3
2
|
export { a as COCO_LABELS, e as CameraBackground, n as DEFAULT_GESTURES, s as HandTracker, m as VisionAnchor, r as VisionDebug, v as VisionOverlay, g as VisionSession, p as VisionStatus, u as createVisionBackend, c as detectGesture, b as fist, f as landmarkToWorld, l as landmarksCentroid, S as ok, i as openHand, x as peace, d as rfDetr, t as thumbsUp, h as useVisionBackend, _ as useVisionFrame, y as yolo, o as yoloSeg };
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnidotdev/rdk",
|
|
3
3
|
"description": "Reality Development Kit, a unified React-first XR engine",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.14.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"main": "build/index.js",
|
|
8
9
|
"module": "build/index.js",
|
|
9
10
|
"types": "build/index.d.ts",
|
|
@@ -35,6 +36,11 @@
|
|
|
35
36
|
"import": "./build/index.js",
|
|
36
37
|
"require": "./build/index.cjs"
|
|
37
38
|
},
|
|
39
|
+
"./engine": {
|
|
40
|
+
"types": "./build/engine.d.ts",
|
|
41
|
+
"import": "./build/engine.js",
|
|
42
|
+
"require": "./build/engine.cjs"
|
|
43
|
+
},
|
|
38
44
|
"./fiducial": {
|
|
39
45
|
"types": "./build/fiducial.d.ts",
|
|
40
46
|
"import": "./build/fiducial.js",
|
|
@@ -76,7 +82,7 @@
|
|
|
76
82
|
"@mediapipe/tasks-vision": "^0.10.0",
|
|
77
83
|
"@react-three/fiber": "^9.5.0",
|
|
78
84
|
"@react-three/xr": "^6.6.29",
|
|
79
|
-
"locar": "^0.2.
|
|
85
|
+
"locar": "^0.2.12",
|
|
80
86
|
"onnxruntime-web": "^1.22.0",
|
|
81
87
|
"react": "^19.2.0",
|
|
82
88
|
"react-dom": "^19.2.0",
|
|
@@ -104,15 +110,15 @@
|
|
|
104
110
|
"@biomejs/biome": "^2.4.8",
|
|
105
111
|
"@mediapipe/tasks-vision": "^0.10.35",
|
|
106
112
|
"@react-three/fiber": "^9.5.0",
|
|
107
|
-
"@testing-library/jest-dom": "^
|
|
113
|
+
"@testing-library/jest-dom": "^7.0.0",
|
|
108
114
|
"@testing-library/react": "^16.3.1",
|
|
109
115
|
"@types/node": "^26.0.0",
|
|
110
116
|
"@types/react": "^19.2.7",
|
|
111
117
|
"@types/react-dom": "^19.2.3",
|
|
112
118
|
"@types/three": "^0.185.0",
|
|
113
119
|
"@typescript/typescript6": "^6.0.2",
|
|
114
|
-
"jsdom": "^
|
|
115
|
-
"locar": "^0.2.
|
|
120
|
+
"jsdom": "^30.0.0",
|
|
121
|
+
"locar": "^0.2.12",
|
|
116
122
|
"onnxruntime-web": "^1.27.0",
|
|
117
123
|
"react": "^19.2.3",
|
|
118
124
|
"react-dom": "^19.2.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require(`./useXRStore-XWI97jRe.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`@ar-js-org/ar.js/three.js/build/ar-threex`),i=require(`react/jsx-runtime`);var a={isPending:!0,isSuccess:!1,arSource:null,arContext:null},o=()=>{let t=e.r(e=>e.backends).get(e.i.FIDUCIAL);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:a},s=({patternUrl:e,barcodeValue:a,params:s,onMarkerFound:c,onMarkerLost:l,children:u})=>{let d=(0,t.useRef)(null),f=o(),p=(0,t.useRef)(!1),m=(0,t.useRef)(!1),h=(0,t.useRef)(null);return(0,t.useEffect)(()=>{if(!f.isSuccess)return;let t=!1;return(()=>{try{let{arContext:n}=f,i=d.current;if(!n||!i||t)return;if(i.visible=!1,m.current=!1,!n.arController){requestAnimationFrame(()=>{!d.current||t||!f.arContext?.arController||(h.current=new r.ArMarkerControls(f.arContext,d.current,{type:e?`pattern`:a?`barcode`:`unknown`,patternUrl:e,barcodeValue:a,...s}),m.current=!0)});return}h.current=new r.ArMarkerControls(n,i,{type:e?`pattern`:a?`barcode`:`unknown`,patternUrl:e,barcodeValue:a,...s}),m.current=!0}catch(e){console.error(`Failed to initialize fiducial anchor:`,e)}})(),()=>{t=!0;let e=h.current;typeof e?.dispose==`function`&&e.dispose(),m.current=!1}},[f.isSuccess,f.arContext,e,a,s,f]),(0,n.useFrame)(()=>{let e=d.current;if(!e||!m.current){e&&(e.visible=!1);return}let t=e.visible;t&&!p.current?(p.current=!0,c?.()):!t&&p.current&&(p.current=!1,l?.())}),(0,i.jsx)(`group`,{ref:d,visible:!1,children:u})},c=({options:r={},children:i})=>{let{scene:a,camera:o,gl:s}=(0,n.useThree)(),{registerBackend:c,unregisterBackend:u}=e.r(),d=(0,t.useRef)(null),f=(0,t.useRef)(r);return f.current=r,(0,t.useEffect)(()=>{if(d.current)return;let e=!1;return(async()=>{try{let t=l(f.current);if(e)return;await c(t,{scene:a,camera:o,renderer:s}),d.current=t}catch(e){console.error(`[FiducialSession] Failed to initialize:`,e)}})(),()=>{e=!0,d.current&&=(u(d.current),null)}},[a,o,s,c,u]),i},l=t=>{let n=null,i=null,a=null,o;return{type:e.i.FIDUCIAL,async init({camera:e,renderer:s}){n=new r.ArToolkitSource({sourceType:t?.sourceType??`webcam`}),await new Promise((e,t)=>{let r=setTimeout(()=>{t(Error(`AR source initialization timeout`))},1e4);n?.init(()=>{clearTimeout(r);let t=n?.domElement;t&&(t.style.position=`fixed`,t.style.top=`0`,t.style.left=`0`,t.style.width=`100vw`,t.style.height=`100vh`,t.style.objectFit=`cover`,t.style.zIndex=`-1`,t.style.pointerEvents=`none`),e()})}),i=new r.ArToolkitContext({cameraParametersUrl:t?.cameraParametersUrl??new URL(`data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=`,``+{}.url).toString(),detectionMode:t?.detectionMode??`mono`,patternRatio:t?.patternRatio??.5,matrixCodeType:t?.matrixCodeType??`3x3`}),a=e;let c=()=>{n?.onResizeElement();let e=window.innerWidth,t=window.innerHeight;s.setSize(e,t,!1),n?.copyElementSizeTo(s.domElement),i?.arController&&n?.copyElementSizeTo(i.arController.canvas)};await new Promise((t,n)=>{let r=setTimeout(()=>{n(Error(`AR context initialization timeout`))},1e4);i?.init(()=>{clearTimeout(r);try{let n=i?.getProjectionMatrix();n&&e.projectionMatrix.copy(n),c(),t()}catch(e){n(e)}})}),window.addEventListener(`resize`,c),o=c},update(){if(!(!n||!i)&&!(!n.ready||!n.domElement))try{i.update(n.domElement);let e=i.getProjectionMatrix?.();a&&e&&a.projectionMatrix.copy(e)}catch(e){console.warn(`AR.js update error:`,e)}},dispose(){if(o&&=(window.removeEventListener(`resize`,o),void 0),i&&typeof i.dispose==`function`&&i.dispose(),n?.domElement){let e=n.domElement.parentNode;e&&e.removeChild(n.domElement)}n=null,i=null,a=null},getInternal:()=>({arSource:n,arContext:i})}};Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require(`./useXRStore-XWI97jRe.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`),a=require(`three/addons/lines/Line2.js`),o=require(`three/addons/lines/LineGeometry.js`),s=require(`three/addons/lines/LineMaterial.js`),c=require(`locar`);var l={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>void 0},u=()=>{let t=e.r(e=>e.backends).get(e.i.GEOLOCATION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:l},d=(e,t)=>{let n=e.length-1,r=[],a=0,o=0;for(let i=0;i<n;i++){let n=e[i+1].x-e[i].x,s=e[i+1].y-e[i].y,c=e[i+1].z-e[i].z,l=Math.sqrt(n*n+s*s+c*c),u=t/2,d=-(c*u)/l,f=n*u/l,p=i>0?(d+a)/2:d,m=i>0?(f+o)/2:f;r.push(e[i].x-p,e[i].y,e[i].z-m,e[i].x+p,e[i].y,e[i].z+m),a=d,o=f}r.push(e[n].x-a,e[n].y,e[n].z-o,e[n].x+a,e[n].y,e[n].z+o);let s=[];for(let e=0;e<n;e++)s.push(e*2,e*2+1,e*2+2),s.push(e*2+1,e*2+3,e*2+2);let c=new i.BufferGeometry;return c.setIndex(s),c.setAttribute(`position`,new i.BufferAttribute(new Float32Array(r),3)),c.computeBoundingBox(),c},f=({coordinates:e,color:c=`#ff0000`,isDashed:l=!1,dashSize:f=3,gapSize:p=1,lineWidth:m=1,opacity:h=1})=>{let g=u(),_=(0,t.useRef)(g);_.current=g;let[v]=(0,t.useState)(()=>new i.Group),y=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[b,x]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!g.isSuccess||e.length<2)return;let[t,n,r=0]=e[0];return _.current.registerAnchor(y,{anchor:v,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,u=0]=e[0],[g,_]=t.lonLatToWorldCoords(n,r),v=e.map(([e,n,r=0])=>{let[a,o]=t.lonLatToWorldCoords(e,n);return new i.Vector3(a-g,r-u,o-_)});if(l){let e=new a.Line2(new o.LineGeometry().setFromPoints(v),new s.LineMaterial({color:c,dashSize:f,gapSize:p,dashed:!0,worldUnits:!0,linewidth:m,transparent:h<1,opacity:h}));e.computeLineDistances(),x(e)}else x(new i.Mesh(d(v,m),new i.MeshBasicMaterial({color:c,transparent:h<1,opacity:h,side:i.DoubleSide})))}}),()=>{_.current.unregisterAnchor(y),x(e=>(e&&(e.geometry.dispose(),e.material.dispose()),null))}},[y,v,e,c,l,f,p,m,h,g.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:b&&(0,r.jsx)(`primitive`,{object:b})}),v)},p=({latitude:e,longitude:a,altitude:o=0,isBillboard:s=!0,onAttach:c,onGpsUpdate:l,children:d})=>{let f=u(),p=(0,t.useRef)(f);p.current=f;let{camera:m}=(0,n.useThree)(),[h]=(0,t.useState)(()=>new i.Group),g=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),_=(0,t.useCallback)(()=>{c?.()},[c]),v=(0,t.useCallback)((e,t)=>{l?.(e,t)},[l]);return(0,t.useEffect)(()=>{if(f.isSuccess)return p.current.registerAnchor(g,{anchor:h,isAttached:!1,latitude:e,longitude:a,altitude:o,onAttach:_,onGpsUpdate:v}),()=>{p.current.unregisterAnchor(g)}},[h,g,e,a,o,_,v,f.isSuccess]),(0,n.useFrame)(()=>{!s||!m||!f.isSuccess||f.getAnchor(g)?.isAttached&&h.lookAt(m.position)}),(0,n.createPortal)((0,r.jsx)(`group`,{children:d}),h)},m=({options:r={},children:i})=>{let{scene:a,camera:o,gl:s}=(0,n.useThree)(),{registerBackend:c,unregisterBackend:l}=e.r(),u=(0,t.useRef)(null),d=(0,t.useRef)(r);return d.current=r,(0,t.useEffect)(()=>{if(u.current)return;let e=!1;return(async()=>{try{let t=_(d.current);if(e)return;await c(t,{scene:a,camera:o,renderer:s}),u.current=t}catch(e){console.error(`[GeolocationSession] Failed to initialize:`,e)}})(),()=>{e=!0,u.current&&=(l(u.current),null)}},[a,o,s,c,l]),i},h={front:i.FrontSide,back:i.BackSide,double:i.DoubleSide},g=({coordinates:e,holes:a,color:o=`#ff0000`,opacity:s=1,isWireframe:c=!1,side:l=`double`})=>{let d=u(),f=(0,t.useRef)(d);f.current=d;let[p]=(0,t.useState)(()=>new i.Group),m=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[g,_]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!d.isSuccess||e.length<3)return;let[t,n,r=0]=e[0];return f.current.registerAnchor(m,{anchor:p,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,o=0]=e[0],[s,c]=t.lonLatToWorldCoords(n,r),l=[];for(let[n,r,i=0]of e){let[e,a]=t.lonLatToWorldCoords(n,r);l.push({x:e-s,z:a-c,elev:i-o})}let u=new i.Shape;u.moveTo(l[0].x,l[0].z);for(let e=1;e<l.length;e++)u.lineTo(l[e].x,l[e].z);if(u.closePath(),a&&a.length>0)for(let e of a){if(e.length<3)continue;let n=new i.Path,[r,a]=e[0],[o,l]=t.lonLatToWorldCoords(r,a);n.moveTo(o-s,l-c);for(let r=1;r<e.length;r++){let[i,a]=e[r],[o,l]=t.lonLatToWorldCoords(i,a);n.lineTo(o-s,l-c)}n.closePath(),u.holes.push(n)}let d=new i.ShapeGeometry(u),f=l.reduce((e,t)=>e+t.elev,0)/l.length;d.rotateX(-Math.PI/2),_({geometry:d,avgElevation:f})}}),()=>{f.current.unregisterAnchor(m),_(e=>(e&&e.geometry.dispose(),null))}},[m,p,e,a,d.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:g&&(0,r.jsx)(`group`,{position:[0,g.avgElevation,0],children:(0,r.jsx)(`mesh`,{geometry:g.geometry,children:(0,r.jsx)(`meshBasicMaterial`,{color:o,opacity:s,transparent:s<1,wireframe:c,side:h[l]})})})}),p)},_=t=>{let n=null,r=null,i,a=null,o=null,s=null,l=null,u=new Map,d=null,f=e=>{if(!(!r||e.isAttached))try{r.add(e.anchor,e.longitude,e.latitude,e.altitude),e.isAttached=!0,e.onAttach?.(r)}catch(e){console.error(`❌ Failed to attach anchor:`,e)}},p=(e,t)=>{u.set(e,t),d!==null&&!t.isAttached&&(f(t),t.onGpsUpdate?.(d,0))},m=e=>{let t=u.get(e);if(t?.isAttached)try{t.anchor.removeFromParent()}catch(t){console.error(`⚠️ Error removing anchor ${e}:`,t)}u.delete(e)},h=e=>u.get(e);return{type:e.i.GEOLOCATION,async init(e){let{camera:p,renderer:m,scene:h}=e;if(!h)throw Error(`[geolocationBackend] A THREE.Scene is required for location-based AR`);o=p,s=m,l=h,n=new c.App({threeObjects:{camera:p,renderer:m,scene:h},videoConstraints:t?.webcamConstraints??{video:{facingMode:`environment`}},deviceOrientationOptions:{enabled:!0}}),m.setClearAlpha?.(0),a=e=>{d=e.position;for(let t of u.values())t.isAttached||f(t),t.onGpsUpdate?.(e.position,e.distMoved);t?.onGpsUpdate?.(e.position,e.distMoved)},r=await n.start();let g=n.deviceOrientationControls;if(g&&g.orientationChangeEventName!==`deviceorientation`)try{g.disconnect(),g.orientationChangeEventName=`deviceorientation`,g.connect()}catch(e){console.error(`[geolocationBackend] failed to rebind device orientation event:`,e)}r.on(`gpsupdate`,a),n.webcam?.on?.(`webcamerror`,e=>{console.error(`[geolocationBackend] webcam error:`,e)}),n.deviceOrientationControls?.on?.(`deviceorientationerror`,e=>{console.error(`[geolocationBackend] Device orientation error:`,e)}),r.on(`gpserror`,e=>{console.error(`[geolocationBackend] gps error:`,e)}),r.startGps(),typeof t?.fakeLat==`number`&&typeof t?.fakeLon==`number`&&r.fakeGps(t.fakeLon,t.fakeLat);let _=r.getLastKnownLocation();_!==null&&(d={coords:{longitude:_.longitude,latitude:_.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>_},timestamp:Date.now(),toJSON:()=>_});let v=()=>{if(!s||!o)return;let e=window.innerWidth,t=window.innerHeight;s.setSize(e,t,!1),o.aspect=e/t,o.updateProjectionMatrix?.()};v(),window.addEventListener(`resize`,v),i=v},update(){n?.deviceOrientationControls?.update?.()},dispose(){r&&a&&r.off(`gpsupdate`,a),r?.stopGps?.(),n?.webcam?.dispose?.(),s?.setClearAlpha?.(1),n?.deviceOrientationControls?.dispose?.(),i&&=(window.removeEventListener(`resize`,i),void 0);for(let e of u.values())if(e.isAttached)try{e.anchor.removeFromParent()}catch(e){console.error(`⚠️ Error removing anchor:`,e)}u.clear(),n=null,r=null,o=null,s=null,l=null,a=null,d=null},getInternal:()=>({locar:r,webcam:n?.webcam??null,deviceOrientation:n?.deviceOrientationControls??null,scene:l,camera:o,lastPosition:d,registerAnchor:p,unregisterAnchor:m,getAnchor:h})}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return _}});
|
package/build/magic-Brm3MYTP.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require(`./useXRStore-XWI97jRe.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`);i=e.a(i);var a=.15,o=.5,s=t=>{let n=null,r=null,s=null,c,l=t?.enableOrientation??!0,u=!1,d=t?.enableWorldAnchoring??!0,f=null,p=null,m=t?.smoothingFactor??a,h=t?.deadZone??o,g={alpha:0,beta:0,gamma:0},_={alpha:0,beta:0,gamma:0},v={alpha:0,beta:0,gamma:0},y=!1,b=null,x=null,S=null,C=new i.Quaternion,w=new i.Quaternion,T=new i.Euler,E=new i.Quaternion,D=new i.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),O=new i.Vector3(0,0,1),k=new i.Quaternion,A=new i.Quaternion,j=(e,t,n,r)=>{let i=(screen.orientation?.angle??0)*Math.PI/180;T.set(n,t,-r,`YXZ`),e.setFromEuler(T),e.multiply(D),e.multiply(E.setFromAxisAngle(O,-i))},M=(e,t)=>{let n=(t-e)%360+360;return n=(n+180)%360-180,n},N=(e,t,n=!1)=>Math.abs(n?M(e,t):t-e)<h?e:t,P=(e,t,n)=>e+(t-e)*n,F=(e,t,n)=>((e+M(e,t)*n)%360+360)%360,I=async()=>{let e=DeviceOrientationEvent;if(typeof e.requestPermission==`function`)try{return await e.requestPermission()===`granted`?(u=!0,!0):(console.warn(`[MagicBackend] Device orientation permission denied`),!1)}catch(e){return console.error(`[MagicBackend] Error requesting orientation permission:`,e),!1}return u=!0,!0},L=()=>{f=e=>{if(g.alpha=e.alpha??0,g.beta=e.beta??0,g.gamma=e.gamma??0,!y&&(g.alpha!==0||g.beta!==0||g.gamma!==0)){v.alpha=g.alpha,v.beta=g.beta,v.gamma=g.gamma;let{degToRad:e}=i.MathUtils;j(k,e(g.alpha),e(g.beta),e(g.gamma)),A.copy(k).invert(),y=!0}},window.addEventListener(`deviceorientation`,f,!0)},R=async(e,a)=>{let o=t?.webcamConstraints??{video:{facingMode:`environment`}};try{s=await navigator.mediaDevices.getUserMedia(o)}catch(e){throw console.error(`[MagicBackend] Failed to access camera:`,e),e}n=document.createElement(`video`),n.srcObject=s,n.setAttribute(`playsinline`,``),n.setAttribute(`autoplay`,``),n.muted=!0,n.style.position=`fixed`,n.style.top=`0`,n.style.left=`0`,n.style.width=`100vw`,n.style.height=`100vh`,n.style.objectFit=`cover`,n.style.zIndex=`-1`,n.style.pointerEvents=`none`,document.body.appendChild(n),await n.play(),r=new i.VideoTexture(n),r.minFilter=i.LinearFilter,r.magFilter=i.LinearFilter,r.colorSpace=i.SRGBColorSpace,e.background=r,a.setClearColor(0,0)};return{type:e.i.MAGIC,async init({scene:e,camera:t,renderer:n}){if(b=t,x=n,S=e,await R(e,n),l)if(await I())L();else{let e=async()=>{document.removeEventListener(`click`,e),document.removeEventListener(`touchend`,e),p=null,await I()&&L()};p=e,document.addEventListener(`click`,e),document.addEventListener(`touchend`,e)}let r=()=>{if(!x||!b)return;let e=window.innerWidth,t=window.innerHeight;x.setSize(e,t,!1),b.aspect=e/t,b.updateProjectionMatrix?.()};r(),window.addEventListener(`resize`,r),c=r},update(){if(!l||!u)return;let e=N(_.alpha,g.alpha,!0),t=N(_.beta,g.beta),n=N(_.gamma,g.gamma);if(_.alpha=F(_.alpha,e,m),_.beta=P(_.beta,t,m),_.gamma=P(_.gamma,n,m),d&&b&&y){let{degToRad:e}=i.MathUtils;j(C,e(g.alpha),e(g.beta),e(g.gamma)),w.copy(A).multiply(C),b.quaternion.slerp(w,m)}r&&(r.needsUpdate=!0)},dispose(){if(f&&=(window.removeEventListener(`deviceorientation`,f),null),p&&=(document.removeEventListener(`click`,p),document.removeEventListener(`touchend`,p),null),c&&=(window.removeEventListener(`resize`,c),void 0),s){for(let e of s.getTracks())e.stop();s=null}n&&=(n.pause(),n.srcObject=null,n.parentNode?.removeChild(n),null),r&&=(r.dispose(),null),S&&(S.background=null),b=null,x=null,S=null,l=!1,u=!1,d=!1,y=!1,_.alpha=0,_.beta=0,_.gamma=0,g.alpha=0,g.beta=0,g.gamma=0,v.alpha=0,v.beta=0,v.gamma=0,k.identity(),A.identity()},getInternal:()=>({videoElement:n,videoTexture:r,stream:s,orientationEnabled:l,orientationPermissionGranted:u,worldAnchoringEnabled:d,currentOrientation:{..._},initialOrientation:{...v},hasInitialOrientation:y,requestOrientationPermission:async()=>{let e=await I();return e&&!f&&L(),e}})}},c=({options:r={},children:i})=>{let{scene:a,camera:o,gl:c}=(0,n.useThree)(),{registerBackend:l,unregisterBackend:u}=e.r(),d=(0,t.useRef)(null),f=(0,t.useRef)(r);return f.current=r,(0,t.useEffect)(()=>{if(d.current)return;let e=!1;return(async()=>{try{let t=s(f.current);if(e)return;await l(t,{scene:a,camera:o,renderer:c}),d.current=t}catch(e){console.error(`[MagicSession] Failed to initialize:`,e)}})(),()=>{e=!0,d.current&&=(u(d.current),null)}},[a,o,c,l,u]),i},l=({position:i=[0,0,-2],rotation:a=[0,0,0],scale:o=1,isBillboard:s=!1,children:c})=>{let l=(0,t.useRef)(null),u=e.r(e=>e.backends);return(0,n.useFrame)(({camera:t})=>{let n=l.current;if(!n)return;let r=u.get(e.i.MAGIC);r&&r.getInternal().hasInitialOrientation&&(n.position.set(i[0],i[1],i[2]),n.rotation.set(a[0],a[1],a[2]),typeof o==`number`?n.scale.setScalar(o):n.scale.set(o[0],o[1],o[2]),s&&n.lookAt(t.position))}),(0,r.jsx)(`group`,{ref:l,children:c})};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
|