@omnidotdev/rdk 0.8.0 → 0.9.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/ImmersiveSession-BiX-Du0K.cjs +1 -0
- package/build/ImmersiveSession-CJRYdHjb.js +21 -0
- package/build/WorldAnchor-gszXX9H2.cjs +1 -0
- package/build/WorldAnchor-ur1RjMrN.js +167 -0
- package/build/fiducial.cjs +1 -0
- package/build/fiducial.d.ts +2 -0
- package/build/fiducial.js +7 -0
- package/build/fiducialBackend-Cr8mdwro.cjs +1 -0
- package/build/fiducialBackend-Vj5N1epW.js +180 -0
- package/build/geolocation.cjs +1 -0
- package/build/geolocation.d.ts +2 -0
- package/build/geolocation.js +9 -0
- package/build/geolocationBackend-BkS2-zqx.cjs +1 -0
- package/build/geolocationBackend-BxwE8Vcl.js +338 -0
- package/build/immersive.cjs +1 -0
- package/build/immersive.d.ts +2 -0
- package/build/immersive.js +4 -0
- package/build/index.cjs +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +31 -672
- package/build/lib/types/engine/backend/Backend.interface.d.ts +1 -0
- package/build/lib/types/engine/backend/Backend.interface.d.ts.map +1 -1
- package/build/magic/MagicSession.d.ts +14 -0
- package/build/magic/MagicSession.d.ts.map +1 -0
- package/build/magic/WorldAnchor.d.ts +21 -0
- package/build/magic/WorldAnchor.d.ts.map +1 -0
- package/build/magic/index.d.ts +7 -0
- package/build/magic/index.d.ts.map +1 -0
- package/build/magic/magicBackend.d.ts +57 -0
- package/build/magic/magicBackend.d.ts.map +1 -0
- package/build/magic.cjs +1 -0
- package/build/magic.d.ts +2 -0
- package/build/magic.js +6 -0
- package/build/useXRStore-eThHhTNv.js +149 -0
- package/build/useXRStore-emhiLtDT.cjs +1 -0
- package/package.json +24 -4
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./fiducialBackend-Cr8mdwro.cjs");exports.FiducialAnchor=i.FiducialAnchor;exports.FiducialSession=i.FiducialSession;exports.createFiducialBackend=i.createFiducialBackend;exports.useFiducialBackend=i.useFiducialBackend;
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { jsx as S } from "react/jsx-runtime";
|
|
2
|
+
import { ArMarkerControls as w, ArToolkitSource as v, ArToolkitContext as h } from "@ar-js-org/ar.js/three.js/build/ar-threex";
|
|
3
|
+
import { useFrame as z, useThree as R } from "@react-three/fiber";
|
|
4
|
+
import { useRef as m, useEffect as y } from "react";
|
|
5
|
+
import { u as C, B as E } from "./useXRStore-eThHhTNv.js";
|
|
6
|
+
const T = {
|
|
7
|
+
isPending: !0,
|
|
8
|
+
isSuccess: !1,
|
|
9
|
+
arSource: null,
|
|
10
|
+
arContext: null
|
|
11
|
+
}, b = () => {
|
|
12
|
+
const e = C((t) => t.backends).get(E.FIDUCIAL);
|
|
13
|
+
return e ? {
|
|
14
|
+
...e.getInternal(),
|
|
15
|
+
isPending: !1,
|
|
16
|
+
isSuccess: !0
|
|
17
|
+
} : T;
|
|
18
|
+
}, j = ({
|
|
19
|
+
patternUrl: o,
|
|
20
|
+
barcodeValue: e,
|
|
21
|
+
params: t,
|
|
22
|
+
onMarkerFound: u,
|
|
23
|
+
onMarkerLost: d,
|
|
24
|
+
children: i
|
|
25
|
+
}) => {
|
|
26
|
+
const c = m(null), A = b(), a = m(!1), s = m(!1), l = m(null);
|
|
27
|
+
return y(() => {
|
|
28
|
+
if (!A.isSuccess) return;
|
|
29
|
+
let n = !1;
|
|
30
|
+
return (() => {
|
|
31
|
+
try {
|
|
32
|
+
const { arContext: f } = A, p = c.current;
|
|
33
|
+
if (!f || !p || n) return;
|
|
34
|
+
if (p.visible = !1, s.current = !1, !f.arController) {
|
|
35
|
+
requestAnimationFrame(() => {
|
|
36
|
+
if (!c.current || n || !A.arContext?.arController)
|
|
37
|
+
return;
|
|
38
|
+
const x = new w(
|
|
39
|
+
A.arContext,
|
|
40
|
+
c.current,
|
|
41
|
+
{
|
|
42
|
+
type: o ? "pattern" : e ? "barcode" : "unknown",
|
|
43
|
+
patternUrl: o,
|
|
44
|
+
barcodeValue: e,
|
|
45
|
+
...t
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
l.current = x, s.current = !0;
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const g = new w(f, p, {
|
|
53
|
+
type: o ? "pattern" : e ? "barcode" : "unknown",
|
|
54
|
+
patternUrl: o,
|
|
55
|
+
barcodeValue: e,
|
|
56
|
+
...t
|
|
57
|
+
});
|
|
58
|
+
l.current = g, s.current = !0;
|
|
59
|
+
} catch (f) {
|
|
60
|
+
console.error("Failed to initialize fiducial anchor:", f);
|
|
61
|
+
}
|
|
62
|
+
})(), () => {
|
|
63
|
+
n = !0;
|
|
64
|
+
const f = l.current;
|
|
65
|
+
typeof f?.dispose == "function" && f.dispose(), s.current = !1;
|
|
66
|
+
};
|
|
67
|
+
}, [
|
|
68
|
+
A.isSuccess,
|
|
69
|
+
A.arContext,
|
|
70
|
+
o,
|
|
71
|
+
e,
|
|
72
|
+
t,
|
|
73
|
+
A
|
|
74
|
+
]), z(() => {
|
|
75
|
+
const n = c.current;
|
|
76
|
+
if (!n || !s.current) {
|
|
77
|
+
n && (n.visible = !1);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const r = n.visible;
|
|
81
|
+
r && !a.current ? (a.current = !0, u?.()) : !r && a.current && (a.current = !1, d?.());
|
|
82
|
+
}), /* @__PURE__ */ S(
|
|
83
|
+
"group",
|
|
84
|
+
{
|
|
85
|
+
ref: c,
|
|
86
|
+
visible: !1,
|
|
87
|
+
children: i
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}, B = ({ options: o = {}, children: e }) => {
|
|
91
|
+
const { scene: t, camera: u, gl: d } = R(), { registerBackend: i, unregisterBackend: c } = C(), A = m(null), a = m(o);
|
|
92
|
+
return a.current = o, y(() => {
|
|
93
|
+
if (A.current) return;
|
|
94
|
+
let s = !1;
|
|
95
|
+
return (async () => {
|
|
96
|
+
try {
|
|
97
|
+
const n = k(a.current);
|
|
98
|
+
if (s) return;
|
|
99
|
+
await i(n, { scene: t, camera: u, renderer: d }), A.current = n;
|
|
100
|
+
} catch (n) {
|
|
101
|
+
console.error("[FiducialSession] Failed to initialize:", n);
|
|
102
|
+
}
|
|
103
|
+
})(), () => {
|
|
104
|
+
s = !0, A.current && (c(A.current), A.current = null);
|
|
105
|
+
};
|
|
106
|
+
}, [t, u, d, i, c]), e;
|
|
107
|
+
}, k = (o) => {
|
|
108
|
+
let e = null, t = null, u = null, d;
|
|
109
|
+
return {
|
|
110
|
+
type: E.FIDUCIAL,
|
|
111
|
+
async init({ camera: i, renderer: c }) {
|
|
112
|
+
e = new v({
|
|
113
|
+
sourceType: o?.sourceType ?? "webcam"
|
|
114
|
+
}), await new Promise((s, l) => {
|
|
115
|
+
const n = setTimeout(() => {
|
|
116
|
+
l(new Error("AR source initialization timeout"));
|
|
117
|
+
}, 1e4);
|
|
118
|
+
e?.init(() => {
|
|
119
|
+
clearTimeout(n);
|
|
120
|
+
const r = e?.domElement;
|
|
121
|
+
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();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
const A = {
|
|
125
|
+
cameraParametersUrl: o?.cameraParametersUrl ?? // default to internal camera parameters
|
|
126
|
+
new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
|
|
127
|
+
detectionMode: o?.detectionMode ?? "mono",
|
|
128
|
+
patternRatio: o?.patternRatio ?? 0.5,
|
|
129
|
+
matrixCodeType: o?.matrixCodeType ?? "3x3"
|
|
130
|
+
};
|
|
131
|
+
t = new h(A), u = i;
|
|
132
|
+
const a = () => {
|
|
133
|
+
e?.onResizeElement();
|
|
134
|
+
const s = window.innerWidth, l = window.innerHeight;
|
|
135
|
+
c.setSize(s, l, !1), e?.copyElementSizeTo(c.domElement), t?.arController && e?.copyElementSizeTo(t.arController.canvas);
|
|
136
|
+
};
|
|
137
|
+
await new Promise((s, l) => {
|
|
138
|
+
const n = setTimeout(() => {
|
|
139
|
+
l(new Error("AR context initialization timeout"));
|
|
140
|
+
}, 1e4);
|
|
141
|
+
t?.init(() => {
|
|
142
|
+
clearTimeout(n);
|
|
143
|
+
try {
|
|
144
|
+
const r = t?.getProjectionMatrix();
|
|
145
|
+
r && i.projectionMatrix.copy(r), a(), s();
|
|
146
|
+
} catch (r) {
|
|
147
|
+
l(r);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}), window.addEventListener("resize", a), d = a;
|
|
151
|
+
},
|
|
152
|
+
update() {
|
|
153
|
+
if (!(!e || !t) && !(!e.ready || !e.domElement))
|
|
154
|
+
try {
|
|
155
|
+
t.update(e.domElement);
|
|
156
|
+
const i = t.getProjectionMatrix?.();
|
|
157
|
+
u && i && u.projectionMatrix.copy(i);
|
|
158
|
+
} catch (i) {
|
|
159
|
+
console.warn("AR.js update error:", i);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
dispose() {
|
|
163
|
+
if (d && (window.removeEventListener("resize", d), d = void 0), t && typeof t.dispose == "function" && t.dispose(), e?.domElement) {
|
|
164
|
+
const i = e.domElement.parentNode;
|
|
165
|
+
i && i.removeChild(e.domElement);
|
|
166
|
+
}
|
|
167
|
+
e = null, t = null, u = null;
|
|
168
|
+
},
|
|
169
|
+
getInternal: () => ({
|
|
170
|
+
arSource: e,
|
|
171
|
+
arContext: t
|
|
172
|
+
})
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
export {
|
|
176
|
+
j as F,
|
|
177
|
+
B as a,
|
|
178
|
+
k as c,
|
|
179
|
+
b as u
|
|
180
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./geolocationBackend-BkS2-zqx.cjs");exports.GeoLine=o.GeoLine;exports.GeoPolygon=o.GeoPolygon;exports.GeolocationAnchor=o.GeolocationAnchor;exports.GeolocationSession=o.GeolocationSession;exports.createGeolocationBackend=o.createGeolocationBackend;exports.useGeolocationBackend=o.useGeolocationBackend;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { G as e, c as n, a as c, b as s, d as G, u as i } from "./geolocationBackend-BxwE8Vcl.js";
|
|
2
|
+
export {
|
|
3
|
+
e as GeoLine,
|
|
4
|
+
n as GeoPolygon,
|
|
5
|
+
c as GeolocationAnchor,
|
|
6
|
+
s as GeolocationSession,
|
|
7
|
+
G as createGeolocationBackend,
|
|
8
|
+
i as useGeolocationBackend
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const P=require("react/jsx-runtime"),T=require("@react-three/fiber"),h=require("react"),L=require("three"),_=require("three/addons/lines/Line2.js"),H=require("three/addons/lines/LineGeometry.js"),K=require("three/addons/lines/LineMaterial.js"),B=require("./useXRStore-emhiLtDT.cjs"),z=require("locar"),Z={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>{}},C=()=>{const e=B.useXRStore(a=>a.backends).get(B.BACKEND_TYPES.GEOLOCATION);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:Z},J=({coordinates:o,color:e="#ff0000",isDashed:a=!1,dashSize:l=3,gapSize:f=1,lineWidth:d=1})=>{const r=C(),[t]=h.useState(()=>new L.Group),u=h.useMemo(()=>Math.random().toString(36).slice(2,11),[]),[s,g]=h.useState(null);return h.useEffect(()=>{if(!r.isSuccess||o.length<2)return;const[p,n,c=0]=o[0],G=A=>{const[E,k,i=0]=o[0],[w,y]=A.lonLatToWorldCoords(E,k),S=o.map(([j,m,v=0])=>{const[R,x]=A.lonLatToWorldCoords(j,m);return new L.Vector3(R-w,v-i,x-y)}),b=new H.LineGeometry().setFromPoints(S),M=new K.LineMaterial({color:e,dashSize:l,gapSize:f,dashed:a,worldUnits:!0,linewidth:d}),O=new _.Line2(b,M);a&&O.computeLineDistances(),g(O)};return r.registerAnchor(u,{anchor:t,isAttached:!1,latitude:n,longitude:p,altitude:c,onAttach:G}),()=>{r.unregisterAnchor(u)}},[r.isSuccess,r.registerAnchor,r.unregisterAnchor,u,t,o,e,a,l,f,d]),T.createPortal(P.jsx("group",{children:s&&P.jsx("primitive",{object:s})}),t)},Y=({latitude:o,longitude:e,altitude:a=0,isBillboard:l=!0,onAttach:f,onGpsUpdate:d,children:r})=>{const t=C(),{camera:u}=T.useThree(),[s]=h.useState(()=>new L.Group),g=h.useMemo(()=>Math.random().toString(36).slice(2,11),[]),p=h.useCallback(()=>{f?.()},[f]),n=h.useCallback((c,G)=>{d?.(c,G)},[d]);return h.useEffect(()=>{if(t.isSuccess)return t.registerAnchor(g,{anchor:s,isAttached:!1,latitude:o,longitude:e,altitude:a,onAttach:p,onGpsUpdate:n}),()=>{t.unregisterAnchor(g)}},[t.isSuccess,t.registerAnchor,t.unregisterAnchor,s,g,o,e,a,p,n]),T.useFrame(()=>{!l||!u||!t.isSuccess||!t.getAnchor(g)?.isAttached||s.lookAt(u.position)}),T.createPortal(P.jsx("group",{children:r}),s)},$=({options:o={},children:e})=>{const{scene:a,camera:l,gl:f}=T.useThree(),{registerBackend:d,unregisterBackend:r}=B.useXRStore(),t=h.useRef(null),u=h.useRef(o);return u.current=o,h.useEffect(()=>{if(t.current)return;let s=!1;return(async()=>{try{const p=D(u.current);if(s)return;await d(p,{scene:a,camera:l,renderer:f}),t.current=p}catch(p){console.error("[GeolocationSession] Failed to initialize:",p)}})(),()=>{s=!0,t.current&&(r(t.current),t.current=null)}},[a,l,f,d,r]),e},V={front:L.FrontSide,back:L.BackSide,double:L.DoubleSide},Q=({coordinates:o,holes:e,color:a="#ff0000",opacity:l=1,isWireframe:f=!1,side:d="double"})=>{const r=C(),[t]=h.useState(()=>new L.Group),u=h.useMemo(()=>Math.random().toString(36).slice(2,11),[]),[s,g]=h.useState(null);return h.useEffect(()=>{if(!r.isSuccess||o.length<3)return;const[p,n,c=0]=o[0],G=A=>{const[E,k,i=0]=o[0],[w,y]=A.lonLatToWorldCoords(E,k),S=[];for(const[m,v,R=0]of o){const[x,I]=A.lonLatToWorldCoords(m,v);S.push({x:x-w,z:I-y,elev:R-i})}const b=new L.Shape;b.moveTo(S[0].x,S[0].z);for(let m=1;m<S.length;m++)b.lineTo(S[m].x,S[m].z);if(b.closePath(),e&&e.length>0)for(const m of e){if(m.length<3)continue;const v=new L.Path,[R,x]=m[0],[I,N]=A.lonLatToWorldCoords(R,x);v.moveTo(I-w,N-y);for(let q=1;q<m.length;q++){const[F,W]=m[q],[X,U]=A.lonLatToWorldCoords(F,W);v.lineTo(X-w,U-y)}v.closePath(),b.holes.push(v)}const M=new L.ShapeGeometry(b),j=S.reduce((m,v)=>m+v.elev,0)/S.length;M.rotateX(-Math.PI/2),g({geometry:M,avgElevation:j})};return r.registerAnchor(u,{anchor:t,isAttached:!1,latitude:n,longitude:p,altitude:c,onAttach:G}),()=>{r.unregisterAnchor(u)}},[r.isSuccess,r.registerAnchor,r.unregisterAnchor,u,t,o,e]),T.createPortal(P.jsx("group",{children:s&&P.jsx("group",{position:[0,s.avgElevation,0],children:P.jsx("mesh",{geometry:s.geometry,children:P.jsx("meshBasicMaterial",{color:a,opacity:l,transparent:l<1,wireframe:f,side:V[d]})})})}),t)},D=o=>{let e=null,a=null,l=null,f,d=null,r=null,t=null,u=null;const s=new Map;let g=null;const p=n=>{if(!(!e||n.isAttached))try{e.add(n.anchor,n.longitude,n.latitude,n.altitude),n.isAttached=!0,n.onAttach?.(e)}catch(c){console.error("❌ Failed to attach anchor:",c)}};return{type:B.BACKEND_TYPES.GEOLOCATION,async init(n){const{camera:c,renderer:G,scene:A}=n;if(!A)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");r=c,t=G,u=A,e=new z.LocationBased(A,c),a=new z.Webcam(o?.webcamConstraints??{video:{facingMode:"environment"}}),d=i=>{g=i.position;for(const w of s.values())w.isAttached||p(w),w.onGpsUpdate?.(i.position,i.distMoved);o?.onGpsUpdate?.(i.position,i.distMoved)},e.on("gpsupdate",d),a.on("webcamstarted",i=>{A.background=i.texture}),a.on("webcamerror",i=>{console.error("[geolocationBackend] webcam error:",i)}),l=new z.DeviceOrientationControls(c),l.on("deviceorientationgranted",i=>{i.target?.connect?.()}),l.on("deviceorientationerror",i=>{console.error("[geolocationBackend] Device orientation error:",i)}),l.init?.(),e.on("gpserror",i=>{console.error("[geolocationBackend] gps error:",i)}),e.startGps(),typeof o?.fakeLat=="number"&&typeof o?.fakeLon=="number"&&e.fakeGps(o.fakeLon,o.fakeLat);const E=e.getLastKnownLocation();E!==null&&(g={coords:{longitude:E.longitude,latitude:E.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>E},timestamp:Date.now(),toJSON:()=>E});const k=()=>{if(!t||!r)return;const i=window.innerWidth,w=window.innerHeight;t.setSize(i,w,!1),r.aspect=i/w,r.updateProjectionMatrix?.()};k(),window.addEventListener("resize",k),f=k},update(){l?.update?.()},dispose(){e&&d&&e.off("gpsupdate",d),e?.stopGps?.(),a?.stop?.(),l?.dispose?.(),f&&(window.removeEventListener("resize",f),f=void 0);for(const n of s.values())if(n.isAttached)try{n.anchor.removeFromParent()}catch(c){console.error("⚠️ Error removing anchor:",c)}s.clear(),e=null,a=null,l=null,r=null,t=null,u=null,d=null,g=null},getInternal:()=>({locar:e,webcam:a,deviceOrientation:l,scene:u,camera:r,lastPosition:g,registerAnchor:(n,c)=>{s.set(n,c),g!==null&&!c.isAttached&&(p(c),c.onGpsUpdate?.(g,0))},unregisterAnchor:n=>{const c=s.get(n);if(c?.isAttached)try{c.anchor.removeFromParent()}catch(G){console.error(`⚠️ Error removing anchor ${n}:`,G)}s.delete(n)},getAnchor:n=>s.get(n)})}};exports.GeoLine=J;exports.GeoPolygon=Q;exports.GeolocationAnchor=Y;exports.GeolocationSession=$;exports.createGeolocationBackend=D;exports.useGeolocationBackend=C;
|