@omnidotdev/rdk 0.5.2 → 0.7.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 +4 -12
- package/build/engine/useXRStore.d.ts.map +1 -1
- package/build/fiducial/FiducialAnchor.d.ts.map +1 -1
- package/build/fiducial/FiducialSession.d.ts +1 -4
- package/build/fiducial/FiducialSession.d.ts.map +1 -1
- package/build/fiducial/fiducialBackend.d.ts +18 -1
- package/build/fiducial/fiducialBackend.d.ts.map +1 -1
- package/build/fiducial/index.d.ts +2 -1
- package/build/fiducial/index.d.ts.map +1 -1
- package/build/fiducial/useFiducialBackend.d.ts +17 -0
- package/build/fiducial/useFiducialBackend.d.ts.map +1 -0
- package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
- package/build/geolocation/GeolocationSession.d.ts +1 -4
- package/build/geolocation/GeolocationSession.d.ts.map +1 -1
- package/build/geolocation/geolocationBackend.d.ts +37 -8
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/geolocation/index.d.ts +2 -1
- package/build/geolocation/index.d.ts.map +1 -1
- package/build/geolocation/useGeolocationBackend.d.ts +17 -0
- package/build/geolocation/useGeolocationBackend.d.ts.map +1 -0
- package/build/immersive/ImmersiveSession.d.ts.map +1 -1
- package/build/index.cjs +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +403 -370
- package/build/lib/types/engine/backend/Backend.interface.d.ts +20 -4
- package/build/lib/types/engine/backend/Backend.interface.d.ts.map +1 -1
- package/build/lib/types/engine/backend/index.d.ts +2 -1
- package/build/lib/types/engine/backend/index.d.ts.map +1 -1
- package/build/lib/types/engine/index.d.ts +2 -2
- package/build/lib/types/engine/index.d.ts.map +1 -1
- package/package.json +15 -17
- package/build/lib/types/engine/context/ContextValue.interface.d.ts +0 -16
- package/build/lib/types/engine/context/ContextValue.interface.d.ts.map +0 -1
- package/build/lib/types/engine/context/index.d.ts +0 -2
- package/build/lib/types/engine/context/index.d.ts.map +0 -1
- package/build/lib/types/index.d.ts +0 -3
- package/build/lib/types/index.d.ts.map +0 -1
- package/build/lib/util/immersive/fromWebXRSessionMode.d.ts +0 -7
- package/build/lib/util/immersive/fromWebXRSessionMode.d.ts.map +0 -1
- package/build/lib/util/immersive/index.d.ts +0 -4
- package/build/lib/util/immersive/index.d.ts.map +0 -1
- package/build/lib/util/immersive/isImmersiveModeSupported.d.ts +0 -7
- package/build/lib/util/immersive/isImmersiveModeSupported.d.ts.map +0 -1
- package/build/lib/util/immersive/toWebXRSessionMode.d.ts +0 -7
- package/build/lib/util/immersive/toWebXRSessionMode.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -1,503 +1,536 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFrame as
|
|
3
|
-
import { jsx as
|
|
4
|
-
import { ArMarkerControls as
|
|
5
|
-
import { Group as
|
|
6
|
-
import { LocationBased as
|
|
7
|
-
import { createXRStore as
|
|
8
|
-
const
|
|
1
|
+
import y, { useRef as b, useEffect as k, useState as P, useMemo as F, useCallback as M } from "react";
|
|
2
|
+
import { useFrame as R, useThree as v, createPortal as G } from "@react-three/fiber";
|
|
3
|
+
import { jsx as C } from "react/jsx-runtime";
|
|
4
|
+
import { ArMarkerControls as x, ArToolkitSource as B, ArToolkitContext as N } from "@ar-js-org/ar.js/three.js/build/ar-threex";
|
|
5
|
+
import { Group as D } from "three";
|
|
6
|
+
import { LocationBased as U, Webcam as X, DeviceOrientationControls as H } from "locar";
|
|
7
|
+
import { createXRStore as W, XR as q } from "@react-three/xr";
|
|
8
|
+
const p = {
|
|
9
|
+
FIDUCIAL: "fiducial",
|
|
10
|
+
GEOLOCATION: "geolocation",
|
|
11
|
+
IMMERSIVE: "immersive"
|
|
12
|
+
}, L = (n) => {
|
|
9
13
|
let e;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
if (!Object.is(
|
|
13
|
-
const
|
|
14
|
-
e =
|
|
14
|
+
const t = /* @__PURE__ */ new Set(), r = (a, f) => {
|
|
15
|
+
const l = typeof a == "function" ? a(e) : a;
|
|
16
|
+
if (!Object.is(l, e)) {
|
|
17
|
+
const o = e;
|
|
18
|
+
e = f ?? (typeof l != "object" || l === null) ? l : Object.assign({}, e, l), t.forEach((d) => d(e, o));
|
|
15
19
|
}
|
|
16
|
-
},
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
}, c = () => e, s = { setState: r, getState: c, getInitialState: () => u, subscribe: (a) => (t.add(a), () => t.delete(a)) }, u = e = n(r, c, s);
|
|
21
|
+
return s;
|
|
22
|
+
}, K = ((n) => n ? L(n) : L), V = (n) => n;
|
|
23
|
+
function Q(n, e = V) {
|
|
24
|
+
const t = y.useSyncExternalStore(
|
|
25
|
+
n.subscribe,
|
|
26
|
+
y.useCallback(() => e(n.getState()), [n, e]),
|
|
27
|
+
y.useCallback(() => e(n.getInitialState()), [n, e])
|
|
24
28
|
);
|
|
25
|
-
return
|
|
29
|
+
return y.useDebugValue(t), t;
|
|
26
30
|
}
|
|
27
|
-
const
|
|
28
|
-
const e =
|
|
29
|
-
return Object.assign(
|
|
30
|
-
},
|
|
31
|
-
const
|
|
32
|
-
return r.subscribe = ((
|
|
33
|
-
let a =
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
a = (
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
const
|
|
41
|
-
|
|
31
|
+
const Y = (n) => {
|
|
32
|
+
const e = K(n), t = (r) => Q(e, r);
|
|
33
|
+
return Object.assign(t, e), t;
|
|
34
|
+
}, _ = ((n) => Y), J = (n) => (e, t, r) => {
|
|
35
|
+
const c = r.subscribe;
|
|
36
|
+
return r.subscribe = ((A, s, u) => {
|
|
37
|
+
let a = A;
|
|
38
|
+
if (s) {
|
|
39
|
+
const f = u?.equalityFn || Object.is;
|
|
40
|
+
let l = A(r.getState());
|
|
41
|
+
a = (o) => {
|
|
42
|
+
const d = A(o);
|
|
43
|
+
if (!f(l, d)) {
|
|
44
|
+
const S = l;
|
|
45
|
+
s(l = d, S);
|
|
42
46
|
}
|
|
43
|
-
}, u?.fireImmediately &&
|
|
47
|
+
}, u?.fireImmediately && s(l, l);
|
|
44
48
|
}
|
|
45
|
-
return
|
|
46
|
-
}),
|
|
47
|
-
},
|
|
49
|
+
return c(a);
|
|
50
|
+
}), n(e, t, r);
|
|
51
|
+
}, $ = J, T = (n) => Symbol.iterator in n, j = (n) => (
|
|
48
52
|
// HACK: avoid checking entries type
|
|
49
|
-
"entries" in
|
|
50
|
-
),
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
+
"entries" in n
|
|
54
|
+
), z = (n, e) => {
|
|
55
|
+
const t = n instanceof Map ? n : new Map(n.entries()), r = e instanceof Map ? e : new Map(e.entries());
|
|
56
|
+
if (t.size !== r.size)
|
|
53
57
|
return !1;
|
|
54
|
-
for (const [
|
|
55
|
-
if (!r.has(
|
|
58
|
+
for (const [c, i] of t)
|
|
59
|
+
if (!r.has(c) || !Object.is(i, r.get(c)))
|
|
56
60
|
return !1;
|
|
57
61
|
return !0;
|
|
58
|
-
},
|
|
59
|
-
const
|
|
60
|
-
let
|
|
61
|
-
for (; !
|
|
62
|
-
if (!Object.is(
|
|
62
|
+
}, Z = (n, e) => {
|
|
63
|
+
const t = n[Symbol.iterator](), r = e[Symbol.iterator]();
|
|
64
|
+
let c = t.next(), i = r.next();
|
|
65
|
+
for (; !c.done && !i.done; ) {
|
|
66
|
+
if (!Object.is(c.value, i.value))
|
|
63
67
|
return !1;
|
|
64
|
-
|
|
68
|
+
c = t.next(), i = r.next();
|
|
65
69
|
}
|
|
66
|
-
return !!
|
|
70
|
+
return !!c.done && !!i.done;
|
|
67
71
|
};
|
|
68
|
-
function
|
|
69
|
-
return Object.is(
|
|
70
|
-
{ entries: () => Object.entries(
|
|
72
|
+
function ee(n, e) {
|
|
73
|
+
return Object.is(n, e) ? !0 : typeof n != "object" || n === null || typeof e != "object" || e === null || Object.getPrototypeOf(n) !== Object.getPrototypeOf(e) ? !1 : T(n) && T(e) ? j(n) && j(e) ? z(n, e) : Z(n, e) : z(
|
|
74
|
+
{ entries: () => Object.entries(n) },
|
|
71
75
|
{ entries: () => Object.entries(e) }
|
|
72
76
|
);
|
|
73
77
|
}
|
|
74
|
-
function
|
|
75
|
-
const e =
|
|
76
|
-
return (
|
|
77
|
-
const r = t
|
|
78
|
-
return
|
|
78
|
+
function te(n) {
|
|
79
|
+
const e = y.useRef(void 0);
|
|
80
|
+
return (t) => {
|
|
81
|
+
const r = n(t);
|
|
82
|
+
return ee(e.current, r) ? e.current : e.current = r;
|
|
79
83
|
};
|
|
80
84
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
GEOLOCATION: "GeolocationSession",
|
|
84
|
-
IMMERSIVE: "ImmersiveSession"
|
|
85
|
-
}, G = ie()(
|
|
86
|
-
ce((t, e) => ({
|
|
85
|
+
const O = _()(
|
|
86
|
+
$((n, e) => ({
|
|
87
87
|
// initial state
|
|
88
88
|
video: null,
|
|
89
|
-
backends:
|
|
90
|
-
sessionTypes: /* @__PURE__ */ new Set(),
|
|
89
|
+
backends: /* @__PURE__ */ new Map(),
|
|
91
90
|
immersiveStore: null,
|
|
92
91
|
// actions
|
|
93
|
-
registerBackend: async (
|
|
92
|
+
registerBackend: async (t, r) => {
|
|
94
93
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
throw console.error(a), new Error(a);
|
|
100
|
-
}
|
|
101
|
-
t(() => ({
|
|
102
|
-
sessionTypes: l
|
|
103
|
-
}));
|
|
94
|
+
const c = e(), i = new Set(c.backends.keys()), A = i.has(p.FIDUCIAL) || t.type === p.FIDUCIAL, s = i.has(p.GEOLOCATION) || t.type === p.GEOLOCATION;
|
|
95
|
+
if (A && s) {
|
|
96
|
+
const u = "❌ [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.";
|
|
97
|
+
throw console.error(u), new Error(u);
|
|
104
98
|
}
|
|
105
|
-
await
|
|
99
|
+
await t.init({
|
|
106
100
|
scene: r.scene,
|
|
107
101
|
camera: r.camera,
|
|
108
102
|
renderer: r.renderer
|
|
109
|
-
}),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
}), n((u) => {
|
|
104
|
+
const a = new Map(u.backends);
|
|
105
|
+
return a.set(t.type, t), { backends: a };
|
|
106
|
+
});
|
|
107
|
+
} catch (c) {
|
|
108
|
+
throw console.error("[XRStore] Failed to register backend:", c), c;
|
|
114
109
|
}
|
|
115
110
|
},
|
|
116
|
-
unregisterBackend: (
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const l = i.backends.filter((c) => c !== n);
|
|
111
|
+
unregisterBackend: (t) => {
|
|
112
|
+
n((r) => {
|
|
113
|
+
const c = new Map(r.backends);
|
|
114
|
+
c.delete(t.type);
|
|
121
115
|
try {
|
|
122
|
-
|
|
123
|
-
} catch (
|
|
124
|
-
console.error("[XRStore] Error disposing backend:",
|
|
116
|
+
t.dispose?.();
|
|
117
|
+
} catch (i) {
|
|
118
|
+
console.error("[XRStore] Error disposing backend:", i);
|
|
125
119
|
}
|
|
126
|
-
return {
|
|
127
|
-
backends: l,
|
|
128
|
-
sessionTypes: o
|
|
129
|
-
};
|
|
120
|
+
return { backends: c };
|
|
130
121
|
});
|
|
131
122
|
},
|
|
132
|
-
setVideo: (
|
|
133
|
-
|
|
123
|
+
setVideo: (t) => {
|
|
124
|
+
n({ video: t });
|
|
134
125
|
},
|
|
135
|
-
updateBackends: (
|
|
126
|
+
updateBackends: (t) => {
|
|
136
127
|
const { backends: r } = e();
|
|
137
|
-
r.
|
|
128
|
+
for (const c of r.values())
|
|
138
129
|
try {
|
|
139
|
-
|
|
140
|
-
} catch (
|
|
141
|
-
console.error("[XRStore] Backend update error:",
|
|
130
|
+
c.update?.(t);
|
|
131
|
+
} catch (i) {
|
|
132
|
+
console.error("[XRStore] Backend update error:", i);
|
|
142
133
|
}
|
|
143
|
-
});
|
|
144
134
|
},
|
|
145
|
-
setImmersiveStore: (
|
|
146
|
-
|
|
135
|
+
setImmersiveStore: (t) => {
|
|
136
|
+
n({ immersiveStore: t });
|
|
147
137
|
}
|
|
148
138
|
}))
|
|
149
|
-
),
|
|
150
|
-
|
|
139
|
+
), ne = () => O.getState(), be = O.subscribe, I = (n) => O(
|
|
140
|
+
te((t) => {
|
|
151
141
|
const r = {
|
|
152
|
-
...
|
|
153
|
-
isImmersive:
|
|
154
|
-
immersive:
|
|
142
|
+
...t,
|
|
143
|
+
isImmersive: t.backends.has(p.IMMERSIVE),
|
|
144
|
+
immersive: t.immersiveStore || null
|
|
155
145
|
};
|
|
156
|
-
return
|
|
146
|
+
return n ? n(r) : r;
|
|
157
147
|
})
|
|
158
|
-
),
|
|
159
|
-
const { updateBackends: e } =
|
|
160
|
-
return
|
|
148
|
+
), ge = ({ children: n }) => {
|
|
149
|
+
const { updateBackends: e } = I();
|
|
150
|
+
return R((t, r) => {
|
|
161
151
|
e(r);
|
|
162
|
-
}),
|
|
163
|
-
},
|
|
164
|
-
|
|
152
|
+
}), n;
|
|
153
|
+
}, re = {
|
|
154
|
+
isPending: !0,
|
|
155
|
+
isSuccess: !1,
|
|
156
|
+
arSource: null,
|
|
157
|
+
arContext: null
|
|
158
|
+
}, oe = () => {
|
|
159
|
+
const e = I((t) => t.backends).get(p.FIDUCIAL);
|
|
160
|
+
return e ? {
|
|
161
|
+
...e.getInternal(),
|
|
162
|
+
isPending: !1,
|
|
163
|
+
isSuccess: !0
|
|
164
|
+
} : re;
|
|
165
|
+
}, he = ({
|
|
166
|
+
patternUrl: n,
|
|
165
167
|
barcodeValue: e,
|
|
166
|
-
params:
|
|
168
|
+
params: t,
|
|
167
169
|
onMarkerFound: r,
|
|
168
|
-
onMarkerLost:
|
|
169
|
-
children:
|
|
170
|
+
onMarkerLost: c,
|
|
171
|
+
children: i
|
|
170
172
|
}) => {
|
|
171
|
-
const
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
const A = b(null), s = oe(), u = b(!1), a = b(!1), f = b(null);
|
|
174
|
+
return k(() => {
|
|
175
|
+
if (!s.isSuccess) return;
|
|
176
|
+
let l = !1;
|
|
177
|
+
return (() => {
|
|
175
178
|
try {
|
|
176
|
-
const
|
|
177
|
-
if (!
|
|
178
|
-
|
|
179
|
-
if (!g || !y) return;
|
|
180
|
-
if (y.visible = !1, a.current = !1, !g.arController) {
|
|
179
|
+
const { arContext: d } = s, S = A.current;
|
|
180
|
+
if (!d || !S || l) return;
|
|
181
|
+
if (S.visible = !1, a.current = !1, !d.arController) {
|
|
181
182
|
requestAnimationFrame(() => {
|
|
182
|
-
if (!
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
183
|
+
if (!A.current || l || !s.arContext?.arController)
|
|
184
|
+
return;
|
|
185
|
+
const g = new x(
|
|
186
|
+
s.arContext,
|
|
187
|
+
A.current,
|
|
188
|
+
{
|
|
189
|
+
type: n ? "pattern" : e ? "barcode" : "unknown",
|
|
190
|
+
patternUrl: n,
|
|
191
|
+
barcodeValue: e,
|
|
192
|
+
...t
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
f.current = g, a.current = !0;
|
|
192
196
|
});
|
|
193
197
|
return;
|
|
194
198
|
}
|
|
195
|
-
const
|
|
196
|
-
type:
|
|
197
|
-
patternUrl:
|
|
199
|
+
const h = new x(d, S, {
|
|
200
|
+
type: n ? "pattern" : e ? "barcode" : "unknown",
|
|
201
|
+
patternUrl: n,
|
|
198
202
|
barcodeValue: e,
|
|
199
|
-
...
|
|
203
|
+
...t
|
|
200
204
|
});
|
|
201
|
-
|
|
202
|
-
} catch (
|
|
203
|
-
console.error("Failed to initialize fiducial
|
|
205
|
+
f.current = h, a.current = !0;
|
|
206
|
+
} catch (d) {
|
|
207
|
+
console.error("Failed to initialize fiducial anchor:", d);
|
|
204
208
|
}
|
|
205
209
|
})(), () => {
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
typeof
|
|
210
|
+
l = !0;
|
|
211
|
+
const d = f.current;
|
|
212
|
+
typeof d?.dispose == "function" && d.dispose(), a.current = !1;
|
|
209
213
|
};
|
|
210
|
-
}, [
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
}, [
|
|
215
|
+
s.isSuccess,
|
|
216
|
+
s.arContext,
|
|
217
|
+
n,
|
|
218
|
+
e,
|
|
219
|
+
t,
|
|
220
|
+
s
|
|
221
|
+
]), R(() => {
|
|
222
|
+
const l = A.current;
|
|
223
|
+
if (!l || !a.current) {
|
|
224
|
+
l && (l.visible = !1);
|
|
214
225
|
return;
|
|
215
226
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
}), /* @__PURE__ */
|
|
227
|
+
const o = l.visible;
|
|
228
|
+
o && !u.current ? (u.current = !0, r?.()) : !o && u.current && (u.current = !1, c?.());
|
|
229
|
+
}), /* @__PURE__ */ C(
|
|
219
230
|
"group",
|
|
220
231
|
{
|
|
221
|
-
ref:
|
|
232
|
+
ref: A,
|
|
222
233
|
visible: !1,
|
|
223
|
-
children:
|
|
234
|
+
children: i
|
|
224
235
|
}
|
|
225
236
|
);
|
|
226
|
-
},
|
|
227
|
-
const { scene:
|
|
228
|
-
return u.current =
|
|
229
|
-
if (
|
|
237
|
+
}, we = ({ options: n = {}, children: e }) => {
|
|
238
|
+
const { scene: t, camera: r, gl: c } = v(), { registerBackend: i, unregisterBackend: A } = I(), s = b(null), u = b(n);
|
|
239
|
+
return u.current = n, k(() => {
|
|
240
|
+
if (s.current) return;
|
|
230
241
|
let a = !1;
|
|
231
242
|
return (async () => {
|
|
232
243
|
try {
|
|
233
|
-
const
|
|
244
|
+
const l = se(u.current);
|
|
234
245
|
if (a) return;
|
|
235
|
-
await
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
S.FIDUCIAL
|
|
239
|
-
), c.current = s;
|
|
240
|
-
} catch (s) {
|
|
241
|
-
console.error("[FiducialSession] Failed to initialize:", s);
|
|
246
|
+
await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
|
|
247
|
+
} catch (l) {
|
|
248
|
+
console.error("[FiducialSession] Failed to initialize:", l);
|
|
242
249
|
}
|
|
243
250
|
})(), () => {
|
|
244
|
-
a = !0,
|
|
251
|
+
a = !0, s.current && (A(s.current), s.current = null);
|
|
245
252
|
};
|
|
246
|
-
}, [
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const fe = (t) => {
|
|
250
|
-
let e = null, n = null, r = null, i;
|
|
253
|
+
}, [t, r, c, i, A]), e;
|
|
254
|
+
}, se = (n) => {
|
|
255
|
+
let e = null, t = null, r = null, c;
|
|
251
256
|
return {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
257
|
+
type: p.FIDUCIAL,
|
|
258
|
+
async init({ camera: i, renderer: A }) {
|
|
259
|
+
e = new B({
|
|
260
|
+
sourceType: n?.sourceType ?? "webcam"
|
|
261
|
+
}), await new Promise((a, f) => {
|
|
262
|
+
const l = setTimeout(() => {
|
|
263
|
+
f(new Error("AR source initialization timeout"));
|
|
258
264
|
}, 1e4);
|
|
259
|
-
e
|
|
260
|
-
clearTimeout(
|
|
261
|
-
const
|
|
262
|
-
|
|
265
|
+
e?.init(() => {
|
|
266
|
+
clearTimeout(l);
|
|
267
|
+
const o = e?.domElement;
|
|
268
|
+
o && (o.style.position = "fixed", o.style.top = "0", o.style.left = "0", o.style.width = "100vw", o.style.height = "100vh", o.style.objectFit = "cover", o.style.zIndex = "-1", o.style.pointerEvents = "none"), a();
|
|
263
269
|
});
|
|
264
270
|
});
|
|
265
|
-
const
|
|
266
|
-
cameraParametersUrl:
|
|
271
|
+
const s = {
|
|
272
|
+
cameraParametersUrl: n?.cameraParametersUrl ?? // default to internal camera parameters
|
|
267
273
|
new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
|
|
268
|
-
detectionMode:
|
|
269
|
-
patternRatio:
|
|
270
|
-
matrixCodeType:
|
|
274
|
+
detectionMode: n?.detectionMode ?? "mono",
|
|
275
|
+
patternRatio: n?.patternRatio ?? 0.5,
|
|
276
|
+
matrixCodeType: n?.matrixCodeType ?? "3x3"
|
|
271
277
|
};
|
|
272
|
-
|
|
278
|
+
t = new N(s), r = i;
|
|
273
279
|
const u = () => {
|
|
274
|
-
e
|
|
275
|
-
const a = window.innerWidth,
|
|
276
|
-
|
|
280
|
+
e?.onResizeElement();
|
|
281
|
+
const a = window.innerWidth, f = window.innerHeight;
|
|
282
|
+
A.setSize(a, f, !1), e?.copyElementSizeTo(A.domElement), t?.arController && e?.copyElementSizeTo(t.arController.canvas);
|
|
277
283
|
};
|
|
278
|
-
await new Promise((a,
|
|
279
|
-
const
|
|
280
|
-
|
|
284
|
+
await new Promise((a, f) => {
|
|
285
|
+
const l = setTimeout(() => {
|
|
286
|
+
f(new Error("AR context initialization timeout"));
|
|
281
287
|
}, 1e4);
|
|
282
|
-
|
|
283
|
-
clearTimeout(
|
|
288
|
+
t?.init(() => {
|
|
289
|
+
clearTimeout(l);
|
|
284
290
|
try {
|
|
285
|
-
o
|
|
286
|
-
|
|
287
|
-
|
|
291
|
+
const o = t?.getProjectionMatrix();
|
|
292
|
+
o && i.projectionMatrix.copy(o), u(), a();
|
|
293
|
+
} catch (o) {
|
|
294
|
+
f(o);
|
|
288
295
|
}
|
|
289
296
|
});
|
|
290
|
-
}), window.addEventListener("resize", u),
|
|
297
|
+
}), window.addEventListener("resize", u), c = u;
|
|
291
298
|
},
|
|
292
299
|
update() {
|
|
293
|
-
if (!(!e || !
|
|
300
|
+
if (!(!e || !t) && !(!e.ready || !e.domElement))
|
|
294
301
|
try {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
302
|
+
t.update(e.domElement);
|
|
303
|
+
const i = t.getProjectionMatrix?.();
|
|
304
|
+
r && i && r.projectionMatrix.copy(i);
|
|
305
|
+
} catch (i) {
|
|
306
|
+
console.warn("AR.js update error:", i);
|
|
298
307
|
}
|
|
299
308
|
},
|
|
300
309
|
dispose() {
|
|
301
|
-
if (
|
|
302
|
-
const
|
|
303
|
-
|
|
310
|
+
if (c && (window.removeEventListener("resize", c), c = void 0), t && typeof t.dispose == "function" && t.dispose(), e?.domElement) {
|
|
311
|
+
const i = e.domElement.parentNode;
|
|
312
|
+
i && i.removeChild(e.domElement);
|
|
304
313
|
}
|
|
305
|
-
e = null,
|
|
314
|
+
e = null, t = null, r = null;
|
|
306
315
|
},
|
|
307
|
-
getInternal() {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
};
|
|
312
|
-
}
|
|
316
|
+
getInternal: () => ({
|
|
317
|
+
arSource: e,
|
|
318
|
+
arContext: t
|
|
319
|
+
})
|
|
313
320
|
};
|
|
314
|
-
},
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
321
|
+
}, ce = {
|
|
322
|
+
isPending: !0,
|
|
323
|
+
isSuccess: !1,
|
|
324
|
+
locar: null,
|
|
325
|
+
webcam: null,
|
|
326
|
+
deviceOrientation: null,
|
|
327
|
+
scene: null,
|
|
328
|
+
camera: null,
|
|
329
|
+
lastPosition: null,
|
|
330
|
+
registerAnchor: () => {
|
|
331
|
+
},
|
|
332
|
+
unregisterAnchor: () => {
|
|
333
|
+
},
|
|
334
|
+
getAnchor: () => {
|
|
335
|
+
}
|
|
336
|
+
}, ie = () => {
|
|
337
|
+
const e = I((t) => t.backends).get(p.GEOLOCATION);
|
|
338
|
+
return e ? {
|
|
339
|
+
...e.getInternal(),
|
|
340
|
+
isPending: !1,
|
|
341
|
+
isSuccess: !0
|
|
342
|
+
} : ce;
|
|
343
|
+
}, ye = ({
|
|
344
|
+
latitude: n,
|
|
318
345
|
longitude: e,
|
|
319
|
-
altitude:
|
|
346
|
+
altitude: t = 0,
|
|
320
347
|
isBillboard: r = !0,
|
|
321
|
-
onAttach:
|
|
322
|
-
onGpsUpdate:
|
|
323
|
-
children:
|
|
348
|
+
onAttach: c,
|
|
349
|
+
onGpsUpdate: i,
|
|
350
|
+
children: A
|
|
324
351
|
}) => {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
}, [
|
|
328
|
-
(
|
|
329
|
-
|
|
352
|
+
const s = ie(), { camera: u } = v(), [a] = P(() => new D()), f = F(() => Math.random().toString(36).slice(2, 11), []), l = M(() => {
|
|
353
|
+
c?.();
|
|
354
|
+
}, [c]), o = M(
|
|
355
|
+
(d, S) => {
|
|
356
|
+
i?.(d, S);
|
|
330
357
|
},
|
|
331
|
-
[
|
|
358
|
+
[i]
|
|
332
359
|
);
|
|
333
|
-
return
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
p.latitude,
|
|
347
|
-
p.altitude
|
|
348
|
-
), p.isAttached = !0, p.onAttach?.();
|
|
349
|
-
} catch (R) {
|
|
350
|
-
console.error("❌ Failed to attach anchor:", R);
|
|
351
|
-
}
|
|
352
|
-
}, b = {
|
|
353
|
-
anchor: a,
|
|
354
|
-
isAttached: !1,
|
|
355
|
-
latitude: t,
|
|
356
|
-
longitude: e,
|
|
357
|
-
altitude: n || 0,
|
|
358
|
-
onAttach: A,
|
|
359
|
-
onGpsUpdate: m
|
|
360
|
-
};
|
|
361
|
-
if (k.set(d, b), !M) {
|
|
362
|
-
C = ({ position: R, distMoved: W }) => {
|
|
363
|
-
O = R, k.forEach((z) => {
|
|
364
|
-
z.isAttached || I(z), z.onGpsUpdate?.(R, W);
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
const p = h.getLastKnownLocation();
|
|
368
|
-
p !== null && (O = {
|
|
369
|
-
coords: {
|
|
370
|
-
longitude: p.longitude,
|
|
371
|
-
latitude: p.latitude,
|
|
372
|
-
accuracy: 0,
|
|
373
|
-
altitude: null,
|
|
374
|
-
altitudeAccuracy: null,
|
|
375
|
-
heading: null,
|
|
376
|
-
speed: null,
|
|
377
|
-
toJSON: () => p
|
|
378
|
-
},
|
|
379
|
-
timestamp: Date.now(),
|
|
380
|
-
toJSON: () => p
|
|
381
|
-
}), O !== null && !b.isAttached && I(b), h.on?.("gpsupdate", C), M = !0;
|
|
382
|
-
}
|
|
383
|
-
O !== null && (b.isAttached || I(b), b.onGpsUpdate?.(O, 0)), s.current = !1;
|
|
384
|
-
} catch (y) {
|
|
385
|
-
console.error("Failed to initialize geolocation backend:", y);
|
|
386
|
-
}
|
|
387
|
-
})(), () => {
|
|
388
|
-
if (f = !0, k.get(d)?.isAttached)
|
|
389
|
-
try {
|
|
390
|
-
a.removeFromParent();
|
|
391
|
-
} catch (E) {
|
|
392
|
-
console.error(`⚠️ Error removing anchor ${d}:`, E);
|
|
393
|
-
}
|
|
394
|
-
k.delete(d), k.size === 0 && C && (c.find((b) => b.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate", C), C = null, M = !1);
|
|
395
|
-
};
|
|
360
|
+
return k(() => {
|
|
361
|
+
if (s.isSuccess)
|
|
362
|
+
return s.registerAnchor(f, {
|
|
363
|
+
anchor: a,
|
|
364
|
+
isAttached: !1,
|
|
365
|
+
latitude: n,
|
|
366
|
+
longitude: e,
|
|
367
|
+
altitude: t,
|
|
368
|
+
onAttach: l,
|
|
369
|
+
onGpsUpdate: o
|
|
370
|
+
}), () => {
|
|
371
|
+
s.unregisterAnchor(f);
|
|
372
|
+
};
|
|
396
373
|
}, [
|
|
397
|
-
|
|
374
|
+
s.isSuccess,
|
|
375
|
+
s.registerAnchor,
|
|
376
|
+
s.unregisterAnchor,
|
|
398
377
|
a,
|
|
399
|
-
|
|
400
|
-
t,
|
|
401
|
-
e,
|
|
378
|
+
f,
|
|
402
379
|
n,
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
380
|
+
e,
|
|
381
|
+
t,
|
|
382
|
+
l,
|
|
383
|
+
o
|
|
384
|
+
]), R(() => {
|
|
385
|
+
!r || !u || !s.isSuccess || !s.getAnchor(f)?.isAttached || a.lookAt(u.position);
|
|
386
|
+
}), G(/* @__PURE__ */ C("group", { children: A }), a);
|
|
387
|
+
}, ke = ({
|
|
388
|
+
options: n = {},
|
|
410
389
|
children: e
|
|
411
390
|
}) => {
|
|
412
|
-
const { scene:
|
|
413
|
-
return u.current =
|
|
414
|
-
if (
|
|
391
|
+
const { scene: t, camera: r, gl: c } = v(), { registerBackend: i, unregisterBackend: A } = I(), s = b(null), u = b(n);
|
|
392
|
+
return u.current = n, k(() => {
|
|
393
|
+
if (s.current) return;
|
|
415
394
|
let a = !1;
|
|
416
395
|
return (async () => {
|
|
417
396
|
try {
|
|
418
|
-
const
|
|
397
|
+
const l = ae(u.current);
|
|
419
398
|
if (a) return;
|
|
420
|
-
await
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
S.GEOLOCATION
|
|
424
|
-
), c.current = s;
|
|
425
|
-
} catch (s) {
|
|
426
|
-
console.error("[GeolocationSession] Failed to initialize:", s);
|
|
399
|
+
await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
|
|
400
|
+
} catch (l) {
|
|
401
|
+
console.error("[GeolocationSession] Failed to initialize:", l);
|
|
427
402
|
}
|
|
428
403
|
})(), () => {
|
|
429
|
-
a = !0,
|
|
404
|
+
a = !0, s.current && (A(s.current), s.current = null);
|
|
430
405
|
};
|
|
431
|
-
}, [
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
let
|
|
406
|
+
}, [t, r, c, i, A]), e;
|
|
407
|
+
}, ae = (n) => {
|
|
408
|
+
let e = null, t = null, r = null, c, i = null, A = null, s = null, u = null;
|
|
409
|
+
const a = /* @__PURE__ */ new Map();
|
|
410
|
+
let f = null;
|
|
411
|
+
const l = (o) => {
|
|
412
|
+
if (!(!e || o.isAttached))
|
|
413
|
+
try {
|
|
414
|
+
e.add(o.anchor, o.longitude, o.latitude, o.altitude), o.isAttached = !0, o.onAttach?.();
|
|
415
|
+
} catch (d) {
|
|
416
|
+
console.error("❌ Failed to attach anchor:", d);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
436
419
|
return {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
420
|
+
type: p.GEOLOCATION,
|
|
421
|
+
async init(o) {
|
|
422
|
+
const { camera: d, renderer: S, scene: h } = o;
|
|
423
|
+
if (!h)
|
|
440
424
|
throw new Error(
|
|
441
425
|
"[geolocationBackend] A THREE.Scene is required for location-based AR"
|
|
442
426
|
);
|
|
443
|
-
|
|
444
|
-
|
|
427
|
+
A = d, s = S, u = h, e = new U(h, d), t = new X(
|
|
428
|
+
n?.webcamConstraints ?? {
|
|
445
429
|
video: { facingMode: "environment" }
|
|
446
430
|
// TODO remove `as any` once fixed upstream (LocAR.js)
|
|
447
431
|
}
|
|
448
|
-
),
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
432
|
+
), i = (m) => {
|
|
433
|
+
f = m.position;
|
|
434
|
+
for (const w of a.values())
|
|
435
|
+
w.isAttached || l(w), w.onGpsUpdate?.(m.position, m.distMoved);
|
|
436
|
+
n?.onGpsUpdate?.(m.position, m.distMoved);
|
|
437
|
+
}, e.on("gpsupdate", i), t.on("webcamstarted", (m) => {
|
|
438
|
+
h.background = m.texture;
|
|
439
|
+
}), t.on("webcamerror", (m) => {
|
|
440
|
+
console.error("[geolocationBackend] webcam error:", m);
|
|
441
|
+
}), r = new H(d), r.on("deviceorientationgranted", (m) => {
|
|
442
|
+
m.target?.connect?.();
|
|
443
|
+
}), r.on("deviceorientationerror", (m) => {
|
|
444
|
+
console.error("[geolocationBackend] Device orientation error:", m);
|
|
445
|
+
}), r.init?.(), e.on("gpserror", (m) => {
|
|
446
|
+
console.error("[geolocationBackend] gps error:", m);
|
|
447
|
+
}), e.startGps(), typeof n?.fakeLat == "number" && typeof n?.fakeLon == "number" && e.fakeGps(n.fakeLon, n.fakeLat);
|
|
448
|
+
const g = e.getLastKnownLocation();
|
|
449
|
+
g !== null && (f = {
|
|
450
|
+
coords: {
|
|
451
|
+
longitude: g.longitude,
|
|
452
|
+
latitude: g.latitude,
|
|
453
|
+
accuracy: 0,
|
|
454
|
+
altitude: null,
|
|
455
|
+
altitudeAccuracy: null,
|
|
456
|
+
heading: null,
|
|
457
|
+
speed: null,
|
|
458
|
+
toJSON: () => g
|
|
459
|
+
},
|
|
460
|
+
timestamp: Date.now(),
|
|
461
|
+
toJSON: () => g
|
|
462
|
+
});
|
|
463
|
+
const E = () => {
|
|
464
|
+
if (!s || !A) return;
|
|
465
|
+
const m = window.innerWidth, w = window.innerHeight;
|
|
466
|
+
s.setSize(m, w, !1), A.aspect = m / w, A.updateProjectionMatrix?.();
|
|
465
467
|
};
|
|
466
|
-
|
|
468
|
+
E(), window.addEventListener("resize", E), c = E;
|
|
467
469
|
},
|
|
468
470
|
update() {
|
|
469
471
|
r?.update?.();
|
|
470
472
|
},
|
|
471
473
|
dispose() {
|
|
472
|
-
e &&
|
|
474
|
+
e && i && e.off("gpsupdate", i), e?.stopGps?.(), t?.stop?.(), r?.dispose?.(), c && (window.removeEventListener("resize", c), c = void 0);
|
|
475
|
+
for (const o of a.values())
|
|
476
|
+
if (o.isAttached)
|
|
477
|
+
try {
|
|
478
|
+
o.anchor.removeFromParent();
|
|
479
|
+
} catch (d) {
|
|
480
|
+
console.error("⚠️ Error removing anchor:", d);
|
|
481
|
+
}
|
|
482
|
+
a.clear(), e = null, t = null, r = null, A = null, s = null, u = null, i = null, f = null;
|
|
473
483
|
},
|
|
474
484
|
getInternal: () => ({
|
|
475
485
|
locar: e,
|
|
476
|
-
webcam:
|
|
486
|
+
webcam: t,
|
|
477
487
|
deviceOrientation: r,
|
|
478
488
|
scene: u,
|
|
479
|
-
camera:
|
|
489
|
+
camera: A,
|
|
490
|
+
lastPosition: f,
|
|
491
|
+
registerAnchor: (o, d) => {
|
|
492
|
+
a.set(o, d), f !== null && !d.isAttached && (l(d), d.onGpsUpdate?.(f, 0));
|
|
493
|
+
},
|
|
494
|
+
unregisterAnchor: (o) => {
|
|
495
|
+
const d = a.get(o);
|
|
496
|
+
if (d?.isAttached)
|
|
497
|
+
try {
|
|
498
|
+
d.anchor.removeFromParent();
|
|
499
|
+
} catch (S) {
|
|
500
|
+
console.error(`⚠️ Error removing anchor ${o}:`, S);
|
|
501
|
+
}
|
|
502
|
+
a.delete(o);
|
|
503
|
+
},
|
|
504
|
+
getAnchor: (o) => a.get(o)
|
|
480
505
|
})
|
|
481
506
|
};
|
|
482
|
-
},
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
507
|
+
}, le = () => ({
|
|
508
|
+
type: p.IMMERSIVE,
|
|
509
|
+
init: () => {
|
|
510
|
+
},
|
|
511
|
+
getInternal: () => null
|
|
512
|
+
}), Ie = ({ children: n }) => {
|
|
513
|
+
const e = F(() => W(), []);
|
|
514
|
+
return k(() => {
|
|
515
|
+
const t = ne(), r = le();
|
|
516
|
+
return t.backends.set(p.IMMERSIVE, r), t.setImmersiveStore(e), () => {
|
|
517
|
+
t.backends.delete(p.IMMERSIVE), t.setImmersiveStore(null);
|
|
488
518
|
};
|
|
489
|
-
}, [e]), /* @__PURE__ */
|
|
519
|
+
}, [e]), /* @__PURE__ */ C(q, { store: e, children: n });
|
|
490
520
|
};
|
|
491
521
|
export {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
522
|
+
p as BACKEND_TYPES,
|
|
523
|
+
he as FiducialAnchor,
|
|
524
|
+
we as FiducialSession,
|
|
525
|
+
ye as GeolocationAnchor,
|
|
526
|
+
ke as GeolocationSession,
|
|
527
|
+
Ie as ImmersiveSession,
|
|
528
|
+
ge as XR,
|
|
529
|
+
se as createFiducialBackend,
|
|
530
|
+
ae as createGeolocationBackend,
|
|
531
|
+
ne as getXRStore,
|
|
532
|
+
be as subscribeToXRStore,
|
|
533
|
+
oe as useFiducialBackend,
|
|
534
|
+
ie as useGeolocationBackend,
|
|
535
|
+
I as useXRStore
|
|
503
536
|
};
|