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