@omnidotdev/rdk 0.9.0 → 0.9.1
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/fiducial-CqsG94R9.js +163 -0
- package/build/fiducial-dapuWTXg.cjs +1 -0
- package/build/fiducial.cjs +1 -1
- package/build/fiducial.js +3 -7
- package/build/geolocation/GeoLine.d.ts.map +1 -1
- package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/geolocation-U_vaIjuk.js +288 -0
- package/build/geolocation-uko8RwgK.cjs +1 -0
- package/build/geolocation.cjs +1 -1
- package/build/geolocation.js +3 -9
- package/build/immersive/ImmersiveSession.d.ts.map +1 -1
- package/build/immersive-8m33PLug.cjs +1 -0
- package/build/immersive-Dp2-ZCRC.js +23 -0
- package/build/immersive.cjs +1 -1
- package/build/immersive.js +3 -4
- package/build/index.cjs +1 -1
- package/build/index.js +14 -33
- package/build/magic-DAQdGGEO.js +148 -0
- package/build/magic-DznuBYgG.cjs +1 -0
- package/build/magic.cjs +1 -1
- package/build/magic.js +3 -6
- package/build/useXRStore-7Gy83DEg.cjs +1 -0
- package/build/useXRStore-B3-MaaCu.js +131 -0
- package/package.json +14 -11
- package/build/ImmersiveSession-BiX-Du0K.cjs +0 -1
- package/build/ImmersiveSession-CJRYdHjb.js +0 -21
- package/build/WorldAnchor-gszXX9H2.cjs +0 -1
- package/build/WorldAnchor-ur1RjMrN.js +0 -167
- package/build/fiducialBackend-Cr8mdwro.cjs +0 -1
- package/build/fiducialBackend-Vj5N1epW.js +0 -180
- package/build/geolocationBackend-BkS2-zqx.cjs +0 -1
- package/build/geolocationBackend-BxwE8Vcl.js +0 -338
- package/build/useXRStore-eThHhTNv.js +0 -149
- package/build/useXRStore-emhiLtDT.cjs +0 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { i as e, r as t } from "./useXRStore-B3-MaaCu.js";
|
|
2
|
+
import { useEffect as n, useRef as r } from "react";
|
|
3
|
+
import { useFrame as i, useThree as a } from "@react-three/fiber";
|
|
4
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
5
|
+
import * as s from "three";
|
|
6
|
+
//#region src/magic/magicBackend.ts
|
|
7
|
+
var c = .15, l = .5, u = (t) => {
|
|
8
|
+
let n = null, r = null, i = null, a, o = t?.enableOrientation ?? !0, u = !1, d = t?.enableWorldAnchoring ?? !0, f = null, p = null, m = t?.smoothingFactor ?? c, h = t?.deadZone ?? l, g = {
|
|
9
|
+
alpha: 0,
|
|
10
|
+
beta: 0,
|
|
11
|
+
gamma: 0
|
|
12
|
+
}, _ = {
|
|
13
|
+
alpha: 0,
|
|
14
|
+
beta: 0,
|
|
15
|
+
gamma: 0
|
|
16
|
+
}, v = {
|
|
17
|
+
alpha: 0,
|
|
18
|
+
beta: 0,
|
|
19
|
+
gamma: 0
|
|
20
|
+
}, y = !1, b = null, x = null, S = null, C = new s.Quaternion(), w = new s.Quaternion(), T = new s.Euler(), E = new s.Quaternion(), D = new s.Quaternion(-Math.sqrt(.5), 0, 0, Math.sqrt(.5)), O = new s.Vector3(0, 0, 1), k = new s.Quaternion(), A = new s.Quaternion(), j = (e, t, n, r) => {
|
|
21
|
+
let i = (screen.orientation?.angle ?? 0) * Math.PI / 180;
|
|
22
|
+
T.set(n, t, -r, "YXZ"), e.setFromEuler(T), e.multiply(D), e.multiply(E.setFromAxisAngle(O, -i));
|
|
23
|
+
}, M = (e, t) => {
|
|
24
|
+
let n = (t - e) % 360 + 360;
|
|
25
|
+
return n = (n + 180) % 360 - 180, n;
|
|
26
|
+
}, 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 () => {
|
|
27
|
+
let e = DeviceOrientationEvent;
|
|
28
|
+
if (typeof e.requestPermission == "function") try {
|
|
29
|
+
return await e.requestPermission() === "granted" ? (u = !0, !0) : (console.warn("[MagicBackend] Device orientation permission denied"), !1);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return console.error("[MagicBackend] Error requesting orientation permission:", e), !1;
|
|
32
|
+
}
|
|
33
|
+
return u = !0, !0;
|
|
34
|
+
}, L = () => {
|
|
35
|
+
f = (e) => {
|
|
36
|
+
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)) {
|
|
37
|
+
v.alpha = g.alpha, v.beta = g.beta, v.gamma = g.gamma;
|
|
38
|
+
let { degToRad: e } = s.MathUtils;
|
|
39
|
+
j(k, e(g.alpha), e(g.beta), e(g.gamma)), A.copy(k).invert(), y = !0;
|
|
40
|
+
}
|
|
41
|
+
}, window.addEventListener("deviceorientation", f, !0);
|
|
42
|
+
}, R = async (e, a) => {
|
|
43
|
+
let o = t?.webcamConstraints ?? { video: { facingMode: "environment" } };
|
|
44
|
+
try {
|
|
45
|
+
i = await navigator.mediaDevices.getUserMedia(o);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
throw console.error("[MagicBackend] Failed to access camera:", e), e;
|
|
48
|
+
}
|
|
49
|
+
n = document.createElement("video"), n.srcObject = i, 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 s.VideoTexture(n), r.minFilter = s.LinearFilter, r.magFilter = s.LinearFilter, r.colorSpace = s.SRGBColorSpace, e.background = r, a.setClearColor(0, 0);
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
type: e.MAGIC,
|
|
53
|
+
async init({ scene: e, camera: t, renderer: n }) {
|
|
54
|
+
if (b = t, x = n, S = e, await R(e, n), o) if (await I()) L();
|
|
55
|
+
else {
|
|
56
|
+
let e = async () => {
|
|
57
|
+
document.removeEventListener("click", e), document.removeEventListener("touchend", e), p = null, await I() && L();
|
|
58
|
+
};
|
|
59
|
+
p = e, document.addEventListener("click", e), document.addEventListener("touchend", e);
|
|
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
|
+
},
|
|
68
|
+
update() {
|
|
69
|
+
if (!o || !u) return;
|
|
70
|
+
let e = N(_.alpha, g.alpha, !0), t = N(_.beta, g.beta), n = N(_.gamma, g.gamma);
|
|
71
|
+
if (_.alpha = F(_.alpha, e, m), _.beta = P(_.beta, t, m), _.gamma = P(_.gamma, n, m), d && b && y) {
|
|
72
|
+
let { degToRad: e } = s.MathUtils;
|
|
73
|
+
j(C, e(g.alpha), e(g.beta), e(g.gamma)), w.copy(A).multiply(C), b.quaternion.slerp(w, m);
|
|
74
|
+
}
|
|
75
|
+
r && (r.needsUpdate = !0);
|
|
76
|
+
},
|
|
77
|
+
dispose() {
|
|
78
|
+
if (f &&= (window.removeEventListener("deviceorientation", f), null), p &&= (document.removeEventListener("click", p), document.removeEventListener("touchend", p), null), a &&= (window.removeEventListener("resize", a), void 0), i) {
|
|
79
|
+
for (let e of i.getTracks()) e.stop();
|
|
80
|
+
i = null;
|
|
81
|
+
}
|
|
82
|
+
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, o = !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();
|
|
83
|
+
},
|
|
84
|
+
getInternal: () => ({
|
|
85
|
+
videoElement: n,
|
|
86
|
+
videoTexture: r,
|
|
87
|
+
stream: i,
|
|
88
|
+
orientationEnabled: o,
|
|
89
|
+
orientationPermissionGranted: u,
|
|
90
|
+
worldAnchoringEnabled: d,
|
|
91
|
+
currentOrientation: { ..._ },
|
|
92
|
+
initialOrientation: { ...v },
|
|
93
|
+
hasInitialOrientation: y,
|
|
94
|
+
requestOrientationPermission: async () => {
|
|
95
|
+
let e = await I();
|
|
96
|
+
return e && !f && L(), e;
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
}, d = ({ options: e = {}, children: i }) => {
|
|
101
|
+
let { scene: o, camera: s, gl: c } = a(), { registerBackend: l, unregisterBackend: d } = t(), f = r(null), p = r(e);
|
|
102
|
+
return p.current = e, n(() => {
|
|
103
|
+
if (f.current) return;
|
|
104
|
+
let e = !1;
|
|
105
|
+
return (async () => {
|
|
106
|
+
try {
|
|
107
|
+
let t = u(p.current);
|
|
108
|
+
if (e) return;
|
|
109
|
+
await l(t, {
|
|
110
|
+
scene: o,
|
|
111
|
+
camera: s,
|
|
112
|
+
renderer: c
|
|
113
|
+
}), f.current = t;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.error("[MagicSession] Failed to initialize:", e);
|
|
116
|
+
}
|
|
117
|
+
})(), () => {
|
|
118
|
+
e = !0, f.current &&= (d(f.current), null);
|
|
119
|
+
};
|
|
120
|
+
}, [
|
|
121
|
+
o,
|
|
122
|
+
s,
|
|
123
|
+
c,
|
|
124
|
+
l,
|
|
125
|
+
d
|
|
126
|
+
]), i;
|
|
127
|
+
}, f = ({ position: n = [
|
|
128
|
+
0,
|
|
129
|
+
0,
|
|
130
|
+
-2
|
|
131
|
+
], rotation: a = [
|
|
132
|
+
0,
|
|
133
|
+
0,
|
|
134
|
+
0
|
|
135
|
+
], scale: s = 1, isBillboard: c = !1, children: l }) => {
|
|
136
|
+
let u = r(null), d = t((e) => e.backends);
|
|
137
|
+
return i(({ camera: t }) => {
|
|
138
|
+
let r = u.current;
|
|
139
|
+
if (!r) return;
|
|
140
|
+
let i = d.get(e.MAGIC);
|
|
141
|
+
i && i.getInternal().hasInitialOrientation && (r.position.set(n[0], n[1], n[2]), r.rotation.set(a[0], a[1], a[2]), typeof s == "number" ? r.scale.setScalar(s) : r.scale.set(s[0], s[1], s[2]), c && r.lookAt(t.position));
|
|
142
|
+
}), /* @__PURE__ */ o("group", {
|
|
143
|
+
ref: u,
|
|
144
|
+
children: l
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
148
|
+
export { d as n, u as r, f as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./useXRStore-7Gy83DEg.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}});
|
package/build/magic.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-7Gy83DEg.cjs`);const e=require(`./magic-DznuBYgG.cjs`);exports.MagicSession=e.n,exports.WorldAnchor=e.t,exports.createMagicBackend=e.r;
|
package/build/magic.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
o as WorldAnchor,
|
|
5
|
-
r as createMagicBackend
|
|
6
|
-
};
|
|
1
|
+
import "./useXRStore-B3-MaaCu.js";
|
|
2
|
+
import { n as e, r as t, t as n } from "./magic-DAQdGGEO.js";
|
|
3
|
+
export { e as MagicSession, n as WorldAnchor, t as createMagicBackend };
|
|
@@ -0,0 +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={FIDUCIAL:`fiducial`,GEOLOCATION:`geolocation`,IMMERSIVE:`immersive`,MAGIC:`magic`},u=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},d=(e=>e?u(e):u),f=e=>e;function p(e,t=f){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 m=e=>{let t=d(e),n=e=>p(t,e);return Object.assign(n,t),n},h=(e=>e?m(e):m),g=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)},_=e=>Symbol.iterator in e,v=e=>`entries`in e,y=(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},b=(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 x(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:_(e)&&_(t)?v(e)&&v(t)?y(e,t):b(e,t):y({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function S(e){let t=c.default.useRef(void 0);return n=>{let r=e(n);return x(t.current,r)?t.current:t.current=r}}var C=h()(g((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(l.FIDUCIAL)||n.type===l.FIDUCIAL,s=a.has(l.GEOLOCATION)||n.type===l.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(S(t=>{let n={...t,isImmersive:t.backends.has(l.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 l}}),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}});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import e from "react";
|
|
2
|
+
//#region src/lib/types/engine/backend/Backend.interface.ts
|
|
3
|
+
var t = {
|
|
4
|
+
FIDUCIAL: "fiducial",
|
|
5
|
+
GEOLOCATION: "geolocation",
|
|
6
|
+
IMMERSIVE: "immersive",
|
|
7
|
+
MAGIC: "magic"
|
|
8
|
+
}, n = (e) => {
|
|
9
|
+
let t, n = /* @__PURE__ */ new Set(), r = (e, r) => {
|
|
10
|
+
let i = typeof e == "function" ? e(t) : e;
|
|
11
|
+
if (!Object.is(i, t)) {
|
|
12
|
+
let e = t;
|
|
13
|
+
t = r ?? (typeof i != "object" || !i) ? i : Object.assign({}, t, i), n.forEach((n) => n(t, e));
|
|
14
|
+
}
|
|
15
|
+
}, i = () => t, a = {
|
|
16
|
+
setState: r,
|
|
17
|
+
getState: i,
|
|
18
|
+
getInitialState: () => o,
|
|
19
|
+
subscribe: (e) => (n.add(e), () => n.delete(e))
|
|
20
|
+
}, o = t = e(r, i, a);
|
|
21
|
+
return a;
|
|
22
|
+
}, r = ((e) => e ? n(e) : n), i = (e) => e;
|
|
23
|
+
function a(t, n = i) {
|
|
24
|
+
let r = e.useSyncExternalStore(t.subscribe, e.useCallback(() => n(t.getState()), [t, n]), e.useCallback(() => n(t.getInitialState()), [t, n]));
|
|
25
|
+
return e.useDebugValue(r), r;
|
|
26
|
+
}
|
|
27
|
+
var o = (e) => {
|
|
28
|
+
let t = r(e), n = (e) => a(t, e);
|
|
29
|
+
return Object.assign(n, t), n;
|
|
30
|
+
}, s = ((e) => e ? o(e) : o), c = (e) => (t, n, r) => {
|
|
31
|
+
let i = r.subscribe;
|
|
32
|
+
return r.subscribe = ((e, t, n) => {
|
|
33
|
+
let a = e;
|
|
34
|
+
if (t) {
|
|
35
|
+
let i = n?.equalityFn || Object.is, o = e(r.getState());
|
|
36
|
+
a = (n) => {
|
|
37
|
+
let r = e(n);
|
|
38
|
+
if (!i(o, r)) {
|
|
39
|
+
let e = o;
|
|
40
|
+
t(o = r, e);
|
|
41
|
+
}
|
|
42
|
+
}, n?.fireImmediately && t(o, o);
|
|
43
|
+
}
|
|
44
|
+
return i(a);
|
|
45
|
+
}), e(t, n, r);
|
|
46
|
+
}, l = (e) => Symbol.iterator in e, u = (e) => "entries" in e, d = (e, t) => {
|
|
47
|
+
let n = e instanceof Map ? e : new Map(e.entries()), r = t instanceof Map ? t : new Map(t.entries());
|
|
48
|
+
if (n.size !== r.size) return !1;
|
|
49
|
+
for (let [e, t] of n) if (!r.has(e) || !Object.is(t, r.get(e))) return !1;
|
|
50
|
+
return !0;
|
|
51
|
+
}, f = (e, t) => {
|
|
52
|
+
let n = e[Symbol.iterator](), r = t[Symbol.iterator](), i = n.next(), a = r.next();
|
|
53
|
+
for (; !i.done && !a.done;) {
|
|
54
|
+
if (!Object.is(i.value, a.value)) return !1;
|
|
55
|
+
i = n.next(), a = r.next();
|
|
56
|
+
}
|
|
57
|
+
return !!i.done && !!a.done;
|
|
58
|
+
};
|
|
59
|
+
function p(e, t) {
|
|
60
|
+
return Object.is(e, t) ? !0 : typeof e != "object" || !e || typeof t != "object" || !t || Object.getPrototypeOf(e) !== Object.getPrototypeOf(t) ? !1 : l(e) && l(t) ? u(e) && u(t) ? d(e, t) : f(e, t) : d({ entries: () => Object.entries(e) }, { entries: () => Object.entries(t) });
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region ../../node_modules/.bun/zustand@5.0.9+3efc971a6f010947/node_modules/zustand/esm/react/shallow.mjs
|
|
64
|
+
function m(t) {
|
|
65
|
+
let n = e.useRef(void 0);
|
|
66
|
+
return (e) => {
|
|
67
|
+
let r = t(e);
|
|
68
|
+
return p(n.current, r) ? n.current : n.current = r;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/engine/useXRStore.ts
|
|
73
|
+
var h = s()(c((e, n) => ({
|
|
74
|
+
video: null,
|
|
75
|
+
backends: /* @__PURE__ */ new Map(),
|
|
76
|
+
immersiveStore: null,
|
|
77
|
+
registerBackend: async (r, i) => {
|
|
78
|
+
try {
|
|
79
|
+
let a = n(), o = new Set(a.backends.keys()), s = o.has(t.FIDUCIAL) || r.type === t.FIDUCIAL, c = o.has(t.GEOLOCATION) || r.type === t.GEOLOCATION;
|
|
80
|
+
if (s && c) {
|
|
81
|
+
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.";
|
|
82
|
+
throw console.error(e), Error(e);
|
|
83
|
+
}
|
|
84
|
+
await r.init({
|
|
85
|
+
scene: i.scene,
|
|
86
|
+
camera: i.camera,
|
|
87
|
+
renderer: i.renderer
|
|
88
|
+
}), e((e) => {
|
|
89
|
+
let t = new Map(e.backends);
|
|
90
|
+
return t.set(r.type, r), { backends: t };
|
|
91
|
+
});
|
|
92
|
+
} catch (e) {
|
|
93
|
+
throw console.error("[XRStore] Failed to register backend:", e), e;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
unregisterBackend: (t) => {
|
|
97
|
+
e((e) => {
|
|
98
|
+
let n = new Map(e.backends);
|
|
99
|
+
n.delete(t.type);
|
|
100
|
+
try {
|
|
101
|
+
t.dispose?.();
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.error("[XRStore] Error disposing backend:", e);
|
|
104
|
+
}
|
|
105
|
+
return { backends: n };
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
setVideo: (t) => {
|
|
109
|
+
e({ video: t });
|
|
110
|
+
},
|
|
111
|
+
updateBackends: (e) => {
|
|
112
|
+
let { backends: t } = n();
|
|
113
|
+
for (let n of t.values()) try {
|
|
114
|
+
n.update?.(e);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
console.error("[XRStore] Backend update error:", e);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
setImmersiveStore: (t) => {
|
|
120
|
+
e({ immersiveStore: t });
|
|
121
|
+
}
|
|
122
|
+
}))), g = () => h.getState(), _ = h.subscribe, v = (e) => h(m((n) => {
|
|
123
|
+
let r = {
|
|
124
|
+
...n,
|
|
125
|
+
isImmersive: n.backends.has(t.IMMERSIVE),
|
|
126
|
+
immersive: n.immersiveStore || null
|
|
127
|
+
};
|
|
128
|
+
return e ? e(r) : r;
|
|
129
|
+
}));
|
|
130
|
+
//#endregion
|
|
131
|
+
export { t as i, _ as n, v as r, g as t };
|
package/package.json
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnidotdev/rdk",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.9.
|
|
3
|
+
"description": "Reality Development Kit, a unified React-first XR engine",
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|
|
9
9
|
"types": "build/index.d.ts",
|
|
10
|
-
"homepage": "https://github.com/omnidotdev/rdk
|
|
10
|
+
"homepage": "https://github.com/omnidotdev/rdk#readme",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/omnidotdev/rdk
|
|
13
|
+
"url": "git+https://github.com/omnidotdev/rdk.git"
|
|
14
14
|
},
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/omnidotdev/rdk
|
|
16
|
+
"url": "https://github.com/omnidotdev/rdk/issues"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
19
22
|
"build/"
|
|
@@ -70,7 +73,7 @@
|
|
|
70
73
|
"locar": "^0.1.8",
|
|
71
74
|
"react": "^19.2.0",
|
|
72
75
|
"react-dom": "^19.2.0",
|
|
73
|
-
"three": "^0.
|
|
76
|
+
"three": "^0.183.0"
|
|
74
77
|
},
|
|
75
78
|
"peerDependenciesMeta": {
|
|
76
79
|
"@ar-js-org/ar.js": {
|
|
@@ -85,21 +88,21 @@
|
|
|
85
88
|
},
|
|
86
89
|
"devDependencies": {
|
|
87
90
|
"@ar-js-org/ar.js": "^3.4.7",
|
|
88
|
-
"@biomejs/biome": "^2.
|
|
91
|
+
"@biomejs/biome": "^2.4.8",
|
|
89
92
|
"@react-three/fiber": "^9.5.0",
|
|
90
93
|
"@testing-library/jest-dom": "^6.9.1",
|
|
91
94
|
"@testing-library/react": "^16.3.1",
|
|
92
95
|
"@types/node": "^25.0.3",
|
|
93
96
|
"@types/react": "^19.2.7",
|
|
94
97
|
"@types/react-dom": "^19.2.3",
|
|
95
|
-
"@types/three": "^0.
|
|
96
|
-
"jsdom": "^
|
|
98
|
+
"@types/three": "^0.183.0",
|
|
99
|
+
"jsdom": "^29.0.0",
|
|
97
100
|
"locar": "^0.1.8",
|
|
98
101
|
"react": "^19.2.3",
|
|
99
102
|
"react-dom": "^19.2.3",
|
|
100
|
-
"three": "^0.
|
|
103
|
+
"three": "^0.183.0",
|
|
101
104
|
"typescript": "^5.9.3",
|
|
102
|
-
"vite": "^
|
|
105
|
+
"vite": "^8.0.0",
|
|
103
106
|
"vite-plugin-dts": "^4.5.4",
|
|
104
107
|
"vite-tsconfig-paths": "^6.0.3",
|
|
105
108
|
"vitest": "^4.0.16"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const i=require("react/jsx-runtime"),s=require("@react-three/xr"),t=require("./useXRStore-emhiLtDT.cjs"),n=require("react"),S=()=>({type:t.BACKEND_TYPES.IMMERSIVE,init:()=>{},getInternal:()=>null}),u=({children:o})=>{const r=n.useMemo(()=>s.createXRStore(),[]);return n.useEffect(()=>{const e=t.getXRStore(),c=S();return e.backends.set(t.BACKEND_TYPES.IMMERSIVE,c),e.setImmersiveStore(r),()=>{e.backends.delete(t.BACKEND_TYPES.IMMERSIVE),e.setImmersiveStore(null)}},[r]),i.jsx(s.XR,{store:r,children:o})};exports.ImmersiveSession=u;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
-
import { createXRStore as n, XR as c } from "@react-three/xr";
|
|
3
|
-
import { g as I, B as r } from "./useXRStore-eThHhTNv.js";
|
|
4
|
-
import { useMemo as i, useEffect as S } from "react";
|
|
5
|
-
const a = () => ({
|
|
6
|
-
type: r.IMMERSIVE,
|
|
7
|
-
init: () => {
|
|
8
|
-
},
|
|
9
|
-
getInternal: () => null
|
|
10
|
-
}), l = ({ children: o }) => {
|
|
11
|
-
const t = i(() => n(), []);
|
|
12
|
-
return S(() => {
|
|
13
|
-
const e = I(), s = a();
|
|
14
|
-
return e.backends.set(r.IMMERSIVE, s), e.setImmersiveStore(t), () => {
|
|
15
|
-
e.backends.delete(r.IMMERSIVE), e.setImmersiveStore(null);
|
|
16
|
-
};
|
|
17
|
-
}, [t]), /* @__PURE__ */ m(c, { store: t, children: o });
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
l as I
|
|
21
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const I=require("@react-three/fiber"),S=require("./useXRStore-emhiLtDT.cjs"),A=require("react"),Z=require("three"),W=require("react/jsx-runtime");function X(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const n in i)if(n!=="default"){const c=Object.getOwnPropertyDescriptor(i,n);Object.defineProperty(t,n,c.get?c:{enumerable:!0,get:()=>i[n]})}}return t.default=i,Object.freeze(t)}const l=X(Z),V=.15,Y=.5,z=i=>{let t=null,n=null,c=null,h,g=i?.enableOrientation??!0,p=!1,u=i?.enableWorldAnchoring??!0,s=null,f=null;const w=i?.smoothingFactor??V,E=i?.deadZone??Y,r={alpha:0,beta:0,gamma:0},d={alpha:0,beta:0,gamma:0},v={alpha:0,beta:0,gamma:0};let O=!1,y=null,R=null,k=null;const _=new l.Quaternion,C=new l.Quaternion,B=new l.Euler,G=new l.Quaternion,x=new l.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),H=new l.Vector3(0,0,1),q=new l.Quaternion,D=new l.Quaternion,P=(e,a,o,m)=>{const M=(screen.orientation?.angle??0)*Math.PI/180;B.set(o,a,-m,"YXZ"),e.setFromEuler(B),e.multiply(x),e.multiply(G.setFromAxisAngle(H,-M))},Q=(e,a)=>{let o=(a-e)%360+360;return o=(o+180)%360-180,o},F=(e,a,o=!1)=>Math.abs(o?Q(e,a):a-e)<E?e:a,j=(e,a,o)=>e+(a-e)*o,N=(e,a,o)=>((e+Q(e,a)*o)%360+360)%360,L=async()=>{const e=DeviceOrientationEvent;if(typeof e.requestPermission=="function")try{return await e.requestPermission()==="granted"?(p=!0,!0):(console.warn("[MagicBackend] Device orientation permission denied"),!1)}catch(a){return console.error("[MagicBackend] Error requesting orientation permission:",a),!1}return p=!0,!0},T=()=>{s=e=>{if(r.alpha=e.alpha??0,r.beta=e.beta??0,r.gamma=e.gamma??0,!O&&(r.alpha!==0||r.beta!==0||r.gamma!==0)){v.alpha=r.alpha,v.beta=r.beta,v.gamma=r.gamma;const{degToRad:a}=l.MathUtils;P(q,a(r.alpha),a(r.beta),a(r.gamma)),D.copy(q).invert(),O=!0}},window.addEventListener("deviceorientation",s,!0)},U=async(e,a)=>{const o=i?.webcamConstraints??{video:{facingMode:"environment"}};try{c=await navigator.mediaDevices.getUserMedia(o)}catch(m){throw console.error("[MagicBackend] Failed to access camera:",m),m}t=document.createElement("video"),t.srcObject=c,t.setAttribute("playsinline",""),t.setAttribute("autoplay",""),t.muted=!0,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",document.body.appendChild(t),await t.play(),n=new l.VideoTexture(t),n.minFilter=l.LinearFilter,n.magFilter=l.LinearFilter,n.colorSpace=l.SRGBColorSpace,e.background=n,a.setClearColor(0,0)};return{type:S.BACKEND_TYPES.MAGIC,async init({scene:e,camera:a,renderer:o}){if(y=a,R=o,k=e,await U(e,o),g)if(await L())T();else{const b=async()=>{document.removeEventListener("click",b),document.removeEventListener("touchend",b),f=null,await L()&&T()};f=b,document.addEventListener("click",b),document.addEventListener("touchend",b)}const m=()=>{if(!R||!y)return;const M=window.innerWidth,b=window.innerHeight;R.setSize(M,b,!1),y.aspect=M/b,y.updateProjectionMatrix?.()};m(),window.addEventListener("resize",m),h=m},update(){if(!g||!p)return;const e=F(d.alpha,r.alpha,!0),a=F(d.beta,r.beta),o=F(d.gamma,r.gamma);if(d.alpha=N(d.alpha,e,w),d.beta=j(d.beta,a,w),d.gamma=j(d.gamma,o,w),u&&y&&O){const{degToRad:m}=l.MathUtils;P(_,m(r.alpha),m(r.beta),m(r.gamma)),C.copy(D).multiply(_),y.quaternion.slerp(C,w)}n&&(n.needsUpdate=!0)},dispose(){if(s&&(window.removeEventListener("deviceorientation",s),s=null),f&&(document.removeEventListener("click",f),document.removeEventListener("touchend",f),f=null),h&&(window.removeEventListener("resize",h),h=void 0),c){for(const e of c.getTracks())e.stop();c=null}t&&(t.pause(),t.srcObject=null,t.parentNode?.removeChild(t),t=null),n&&(n.dispose(),n=null),k&&(k.background=null),y=null,R=null,k=null,g=!1,p=!1,u=!1,O=!1,d.alpha=0,d.beta=0,d.gamma=0,r.alpha=0,r.beta=0,r.gamma=0,v.alpha=0,v.beta=0,v.gamma=0,q.identity(),D.identity()},getInternal:()=>({videoElement:t,videoTexture:n,stream:c,orientationEnabled:g,orientationPermissionGranted:p,worldAnchoringEnabled:u,currentOrientation:{...d},initialOrientation:{...v},hasInitialOrientation:O,requestOrientationPermission:async()=>{const e=await L();return e&&!s&&T(),e}})}},K=({options:i={},children:t})=>{const{scene:n,camera:c,gl:h}=I.useThree(),{registerBackend:g,unregisterBackend:p}=S.useXRStore(),u=A.useRef(null),s=A.useRef(i);return s.current=i,A.useEffect(()=>{if(u.current)return;let f=!1;return(async()=>{try{const E=z(s.current);if(f)return;await g(E,{scene:n,camera:c,renderer:h}),u.current=E}catch(E){console.error("[MagicSession] Failed to initialize:",E)}})(),()=>{f=!0,u.current&&(p(u.current),u.current=null)}},[n,c,h,g,p]),t},J=({position:i=[0,0,-2],rotation:t=[0,0,0],scale:n=1,isBillboard:c=!1,children:h})=>{const g=A.useRef(null),p=S.useXRStore(u=>u.backends);return I.useFrame(({camera:u})=>{const s=g.current;if(!s)return;const f=p.get(S.BACKEND_TYPES.MAGIC);!f||!f.getInternal().hasInitialOrientation||(s.position.set(i[0],i[1],i[2]),s.rotation.set(t[0],t[1],t[2]),typeof n=="number"?s.scale.setScalar(n):s.scale.set(n[0],n[1],n[2]),c&&s.lookAt(u.position))}),W.jsx("group",{ref:g,children:h})};exports.MagicSession=K;exports.WorldAnchor=J;exports.createMagicBackend=z;
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { useThree as Z, useFrame as N } from "@react-three/fiber";
|
|
2
|
-
import { B as G, u as P } from "./useXRStore-eThHhTNv.js";
|
|
3
|
-
import { useRef as S, useEffect as W } from "react";
|
|
4
|
-
import * as s from "three";
|
|
5
|
-
import { jsx as V } from "react/jsx-runtime";
|
|
6
|
-
const X = 0.15, Y = 0.5, K = (d) => {
|
|
7
|
-
let t = null, r = null, p = null, h, f = d?.enableOrientation ?? !0, g = !1, l = d?.enableWorldAnchoring ?? !0, o = null, m = null;
|
|
8
|
-
const y = d?.smoothingFactor ?? X, E = d?.deadZone ?? Y, a = { alpha: 0, beta: 0, gamma: 0 }, c = { alpha: 0, beta: 0, gamma: 0 }, b = { alpha: 0, beta: 0, gamma: 0 };
|
|
9
|
-
let M = !1, w = null, k = null, A = null;
|
|
10
|
-
const T = new s.Quaternion(), B = new s.Quaternion(), Q = new s.Euler(), x = new s.Quaternion(), z = new s.Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)), H = new s.Vector3(0, 0, 1), F = new s.Quaternion(), L = new s.Quaternion(), _ = (e, n, i, u) => {
|
|
11
|
-
const O = (screen.orientation?.angle ?? 0) * Math.PI / 180;
|
|
12
|
-
Q.set(i, n, -u, "YXZ"), e.setFromEuler(Q), e.multiply(z), e.multiply(x.setFromAxisAngle(H, -O));
|
|
13
|
-
}, q = (e, n) => {
|
|
14
|
-
let i = (n - e) % 360 + 360;
|
|
15
|
-
return i = (i + 180) % 360 - 180, i;
|
|
16
|
-
}, R = (e, n, i = !1) => Math.abs(i ? q(e, n) : n - e) < E ? e : n, I = (e, n, i) => e + (n - e) * i, U = (e, n, i) => ((e + q(e, n) * i) % 360 + 360) % 360, C = async () => {
|
|
17
|
-
const e = DeviceOrientationEvent;
|
|
18
|
-
if (typeof e.requestPermission == "function")
|
|
19
|
-
try {
|
|
20
|
-
return await e.requestPermission() === "granted" ? (g = !0, !0) : (console.warn("[MagicBackend] Device orientation permission denied"), !1);
|
|
21
|
-
} catch (n) {
|
|
22
|
-
return console.error(
|
|
23
|
-
"[MagicBackend] Error requesting orientation permission:",
|
|
24
|
-
n
|
|
25
|
-
), !1;
|
|
26
|
-
}
|
|
27
|
-
return g = !0, !0;
|
|
28
|
-
}, D = () => {
|
|
29
|
-
o = (e) => {
|
|
30
|
-
if (a.alpha = e.alpha ?? 0, a.beta = e.beta ?? 0, a.gamma = e.gamma ?? 0, !M && (a.alpha !== 0 || a.beta !== 0 || a.gamma !== 0)) {
|
|
31
|
-
b.alpha = a.alpha, b.beta = a.beta, b.gamma = a.gamma;
|
|
32
|
-
const { degToRad: n } = s.MathUtils;
|
|
33
|
-
_(
|
|
34
|
-
F,
|
|
35
|
-
n(a.alpha),
|
|
36
|
-
n(a.beta),
|
|
37
|
-
n(a.gamma)
|
|
38
|
-
), L.copy(F).invert(), M = !0;
|
|
39
|
-
}
|
|
40
|
-
}, window.addEventListener("deviceorientation", o, !0);
|
|
41
|
-
}, j = async (e, n) => {
|
|
42
|
-
const i = d?.webcamConstraints ?? {
|
|
43
|
-
video: { facingMode: "environment" }
|
|
44
|
-
};
|
|
45
|
-
try {
|
|
46
|
-
p = await navigator.mediaDevices.getUserMedia(i);
|
|
47
|
-
} catch (u) {
|
|
48
|
-
throw console.error("[MagicBackend] Failed to access camera:", u), u;
|
|
49
|
-
}
|
|
50
|
-
t = document.createElement("video"), t.srcObject = p, t.setAttribute("playsinline", ""), t.setAttribute("autoplay", ""), t.muted = !0, 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", document.body.appendChild(t), await t.play(), r = new s.VideoTexture(t), r.minFilter = s.LinearFilter, r.magFilter = s.LinearFilter, r.colorSpace = s.SRGBColorSpace, e.background = r, n.setClearColor(0, 0);
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
type: G.MAGIC,
|
|
54
|
-
async init({ scene: e, camera: n, renderer: i }) {
|
|
55
|
-
if (w = n, k = i, A = e, await j(e, i), f)
|
|
56
|
-
if (await C())
|
|
57
|
-
D();
|
|
58
|
-
else {
|
|
59
|
-
const v = async () => {
|
|
60
|
-
document.removeEventListener("click", v), document.removeEventListener("touchend", v), m = null, await C() && D();
|
|
61
|
-
};
|
|
62
|
-
m = v, document.addEventListener("click", v), document.addEventListener("touchend", v);
|
|
63
|
-
}
|
|
64
|
-
const u = () => {
|
|
65
|
-
if (!k || !w) return;
|
|
66
|
-
const O = window.innerWidth, v = window.innerHeight;
|
|
67
|
-
k.setSize(O, v, !1), w.aspect = O / v, w.updateProjectionMatrix?.();
|
|
68
|
-
};
|
|
69
|
-
u(), window.addEventListener("resize", u), h = u;
|
|
70
|
-
},
|
|
71
|
-
update() {
|
|
72
|
-
if (!f || !g) return;
|
|
73
|
-
const e = R(
|
|
74
|
-
c.alpha,
|
|
75
|
-
a.alpha,
|
|
76
|
-
!0
|
|
77
|
-
), n = R(
|
|
78
|
-
c.beta,
|
|
79
|
-
a.beta
|
|
80
|
-
), i = R(
|
|
81
|
-
c.gamma,
|
|
82
|
-
a.gamma
|
|
83
|
-
);
|
|
84
|
-
if (c.alpha = U(
|
|
85
|
-
c.alpha,
|
|
86
|
-
e,
|
|
87
|
-
y
|
|
88
|
-
), c.beta = I(
|
|
89
|
-
c.beta,
|
|
90
|
-
n,
|
|
91
|
-
y
|
|
92
|
-
), c.gamma = I(
|
|
93
|
-
c.gamma,
|
|
94
|
-
i,
|
|
95
|
-
y
|
|
96
|
-
), l && w && M) {
|
|
97
|
-
const { degToRad: u } = s.MathUtils;
|
|
98
|
-
_(
|
|
99
|
-
T,
|
|
100
|
-
u(a.alpha),
|
|
101
|
-
u(a.beta),
|
|
102
|
-
u(a.gamma)
|
|
103
|
-
), B.copy(L).multiply(T), w.quaternion.slerp(B, y);
|
|
104
|
-
}
|
|
105
|
-
r && (r.needsUpdate = !0);
|
|
106
|
-
},
|
|
107
|
-
dispose() {
|
|
108
|
-
if (o && (window.removeEventListener("deviceorientation", o), o = null), m && (document.removeEventListener("click", m), document.removeEventListener("touchend", m), m = null), h && (window.removeEventListener("resize", h), h = void 0), p) {
|
|
109
|
-
for (const e of p.getTracks())
|
|
110
|
-
e.stop();
|
|
111
|
-
p = null;
|
|
112
|
-
}
|
|
113
|
-
t && (t.pause(), t.srcObject = null, t.parentNode?.removeChild(t), t = null), r && (r.dispose(), r = null), A && (A.background = null), w = null, k = null, A = null, f = !1, g = !1, l = !1, M = !1, c.alpha = 0, c.beta = 0, c.gamma = 0, a.alpha = 0, a.beta = 0, a.gamma = 0, b.alpha = 0, b.beta = 0, b.gamma = 0, F.identity(), L.identity();
|
|
114
|
-
},
|
|
115
|
-
getInternal: () => ({
|
|
116
|
-
videoElement: t,
|
|
117
|
-
videoTexture: r,
|
|
118
|
-
stream: p,
|
|
119
|
-
orientationEnabled: f,
|
|
120
|
-
orientationPermissionGranted: g,
|
|
121
|
-
worldAnchoringEnabled: l,
|
|
122
|
-
currentOrientation: { ...c },
|
|
123
|
-
initialOrientation: { ...b },
|
|
124
|
-
hasInitialOrientation: M,
|
|
125
|
-
requestOrientationPermission: async () => {
|
|
126
|
-
const e = await C();
|
|
127
|
-
return e && !o && D(), e;
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
};
|
|
131
|
-
}, ae = ({ options: d = {}, children: t }) => {
|
|
132
|
-
const { scene: r, camera: p, gl: h } = Z(), { registerBackend: f, unregisterBackend: g } = P(), l = S(null), o = S(d);
|
|
133
|
-
return o.current = d, W(() => {
|
|
134
|
-
if (l.current) return;
|
|
135
|
-
let m = !1;
|
|
136
|
-
return (async () => {
|
|
137
|
-
try {
|
|
138
|
-
const E = K(o.current);
|
|
139
|
-
if (m) return;
|
|
140
|
-
await f(E, { scene: r, camera: p, renderer: h }), l.current = E;
|
|
141
|
-
} catch (E) {
|
|
142
|
-
console.error("[MagicSession] Failed to initialize:", E);
|
|
143
|
-
}
|
|
144
|
-
})(), () => {
|
|
145
|
-
m = !0, l.current && (g(l.current), l.current = null);
|
|
146
|
-
};
|
|
147
|
-
}, [r, p, h, f, g]), t;
|
|
148
|
-
}, re = ({
|
|
149
|
-
position: d = [0, 0, -2],
|
|
150
|
-
rotation: t = [0, 0, 0],
|
|
151
|
-
scale: r = 1,
|
|
152
|
-
isBillboard: p = !1,
|
|
153
|
-
children: h
|
|
154
|
-
}) => {
|
|
155
|
-
const f = S(null), g = P((l) => l.backends);
|
|
156
|
-
return N(({ camera: l }) => {
|
|
157
|
-
const o = f.current;
|
|
158
|
-
if (!o) return;
|
|
159
|
-
const m = g.get(G.MAGIC);
|
|
160
|
-
!m || !m.getInternal().hasInitialOrientation || (o.position.set(d[0], d[1], d[2]), o.rotation.set(t[0], t[1], t[2]), typeof r == "number" ? o.scale.setScalar(r) : o.scale.set(r[0], r[1], r[2]), p && o.lookAt(l.position));
|
|
161
|
-
}), /* @__PURE__ */ V("group", { ref: f, children: h });
|
|
162
|
-
};
|
|
163
|
-
export {
|
|
164
|
-
ae as M,
|
|
165
|
-
re as W,
|
|
166
|
-
K as c
|
|
167
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const x=require("react/jsx-runtime"),p=require("@ar-js-org/ar.js/three.js/build/ar-threex"),R=require("@react-three/fiber"),m=require("react"),y=require("./useXRStore-emhiLtDT.cjs");var C=typeof document<"u"?document.currentScript:null;const T={isPending:!0,isSuccess:!1,arSource:null,arContext:null},S=()=>{const e=y.useXRStore(t=>t.backends).get(y.BACKEND_TYPES.FIDUCIAL);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:T},k=({patternUrl:i,barcodeValue:e,params:t,onMarkerFound:l,onMarkerLost:d,children:o})=>{const A=m.useRef(null),c=S(),u=m.useRef(!1),s=m.useRef(!1),a=m.useRef(null);return m.useEffect(()=>{if(!c.isSuccess)return;let n=!1;return(()=>{try{const{arContext:f}=c,w=A.current;if(!f||!w||n)return;if(w.visible=!1,s.current=!1,!f.arController){requestAnimationFrame(()=>{if(!A.current||n||!c.arContext?.arController)return;const h=new p.ArMarkerControls(c.arContext,A.current,{type:i?"pattern":e?"barcode":"unknown",patternUrl:i,barcodeValue:e,...t});a.current=h,s.current=!0});return}const g=new p.ArMarkerControls(f,w,{type:i?"pattern":e?"barcode":"unknown",patternUrl:i,barcodeValue:e,...t});a.current=g,s.current=!0}catch(f){console.error("Failed to initialize fiducial anchor:",f)}})(),()=>{n=!0;const f=a.current;typeof f?.dispose=="function"&&f.dispose(),s.current=!1}},[c.isSuccess,c.arContext,i,e,t,c]),R.useFrame(()=>{const n=A.current;if(!n||!s.current){n&&(n.visible=!1);return}const r=n.visible;r&&!u.current?(u.current=!0,l?.()):!r&&u.current&&(u.current=!1,d?.())}),x.jsx("group",{ref:A,visible:!1,children:o})},v=({options:i={},children:e})=>{const{scene:t,camera:l,gl:d}=R.useThree(),{registerBackend:o,unregisterBackend:A}=y.useXRStore(),c=m.useRef(null),u=m.useRef(i);return u.current=i,m.useEffect(()=>{if(c.current)return;let s=!1;return(async()=>{try{const n=E(u.current);if(s)return;await o(n,{scene:t,camera:l,renderer:d}),c.current=n}catch(n){console.error("[FiducialSession] Failed to initialize:",n)}})(),()=>{s=!0,c.current&&(A(c.current),c.current=null)}},[t,l,d,o,A]),e},E=i=>{let e=null,t=null,l=null,d;return{type:y.BACKEND_TYPES.FIDUCIAL,async init({camera:o,renderer:A}){e=new p.ArToolkitSource({sourceType:i?.sourceType??"webcam"}),await new Promise((s,a)=>{const n=setTimeout(()=>{a(new Error("AR source initialization timeout"))},1e4);e?.init(()=>{clearTimeout(n);const r=e?.domElement;r&&(r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="100vw",r.style.height="100vh",r.style.objectFit="cover",r.style.zIndex="-1",r.style.pointerEvents="none"),s()})});const c={cameraParametersUrl:i?.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:C&&C.tagName.toUpperCase()==="SCRIPT"&&C.src||new URL("fiducialBackend-Cr8mdwro.cjs",document.baseURI).href).toString(),detectionMode:i?.detectionMode??"mono",patternRatio:i?.patternRatio??.5,matrixCodeType:i?.matrixCodeType??"3x3"};t=new p.ArToolkitContext(c),l=o;const u=()=>{e?.onResizeElement();const s=window.innerWidth,a=window.innerHeight;A.setSize(s,a,!1),e?.copyElementSizeTo(A.domElement),t?.arController&&e?.copyElementSizeTo(t.arController.canvas)};await new Promise((s,a)=>{const n=setTimeout(()=>{a(new Error("AR context initialization timeout"))},1e4);t?.init(()=>{clearTimeout(n);try{const r=t?.getProjectionMatrix();r&&o.projectionMatrix.copy(r),u(),s()}catch(r){a(r)}})}),window.addEventListener("resize",u),d=u},update(){if(!(!e||!t)&&!(!e.ready||!e.domElement))try{t.update(e.domElement);const o=t.getProjectionMatrix?.();l&&o&&l.projectionMatrix.copy(o)}catch(o){console.warn("AR.js update error:",o)}},dispose(){if(d&&(window.removeEventListener("resize",d),d=void 0),t&&typeof t.dispose=="function"&&t.dispose(),e?.domElement){const o=e.domElement.parentNode;o&&o.removeChild(e.domElement)}e=null,t=null,l=null},getInternal:()=>({arSource:e,arContext:t})}};exports.FiducialAnchor=k;exports.FiducialSession=v;exports.createFiducialBackend=E;exports.useFiducialBackend=S;
|