@omnidotdev/rdk 0.7.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/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/geolocationBackend.d.ts +2 -1
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/geolocation/index.d.ts +4 -0
- package/build/geolocation/index.d.ts.map +1 -1
- 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 -533
- 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,338 @@
|
|
|
1
|
+
import { jsx as G } from "react/jsx-runtime";
|
|
2
|
+
import { createPortal as x, useThree as U, useFrame as q } from "@react-three/fiber";
|
|
3
|
+
import { useState as y, useMemo as z, useEffect as B, useCallback as F, useRef as W } from "react";
|
|
4
|
+
import { Group as D, Vector3 as V, DoubleSide as Y, BackSide as $, FrontSide as Q, Shape as ee, Path as te, ShapeGeometry as ne } from "three";
|
|
5
|
+
import { Line2 as oe } from "three/addons/lines/Line2.js";
|
|
6
|
+
import { LineGeometry as re } from "three/addons/lines/LineGeometry.js";
|
|
7
|
+
import { LineMaterial as se } from "three/addons/lines/LineMaterial.js";
|
|
8
|
+
import { u as X, B as j } from "./useXRStore-eThHhTNv.js";
|
|
9
|
+
import { LocationBased as ce, Webcam as ie, DeviceOrientationControls as ae } from "locar";
|
|
10
|
+
const le = {
|
|
11
|
+
isPending: !0,
|
|
12
|
+
isSuccess: !1,
|
|
13
|
+
locar: null,
|
|
14
|
+
webcam: null,
|
|
15
|
+
deviceOrientation: null,
|
|
16
|
+
scene: null,
|
|
17
|
+
camera: null,
|
|
18
|
+
lastPosition: null,
|
|
19
|
+
registerAnchor: () => {
|
|
20
|
+
},
|
|
21
|
+
unregisterAnchor: () => {
|
|
22
|
+
},
|
|
23
|
+
getAnchor: () => {
|
|
24
|
+
}
|
|
25
|
+
}, N = () => {
|
|
26
|
+
const e = X((a) => a.backends).get(j.GEOLOCATION);
|
|
27
|
+
return e ? {
|
|
28
|
+
...e.getInternal(),
|
|
29
|
+
isPending: !1,
|
|
30
|
+
isSuccess: !0
|
|
31
|
+
} : le;
|
|
32
|
+
}, Se = ({
|
|
33
|
+
coordinates: o,
|
|
34
|
+
color: e = "#ff0000",
|
|
35
|
+
isDashed: a = !1,
|
|
36
|
+
dashSize: l = 3,
|
|
37
|
+
gapSize: h = 1,
|
|
38
|
+
lineWidth: d = 1
|
|
39
|
+
}) => {
|
|
40
|
+
const r = N(), [t] = y(() => new D()), u = z(() => Math.random().toString(36).slice(2, 11), []), [s, g] = y(null);
|
|
41
|
+
return B(() => {
|
|
42
|
+
if (!r.isSuccess || o.length < 2) return;
|
|
43
|
+
const [m, n, c = 0] = o[0], L = (p) => {
|
|
44
|
+
const [S, b, i = 0] = o[0], [A, E] = p.lonLatToWorldCoords(
|
|
45
|
+
S,
|
|
46
|
+
b
|
|
47
|
+
), w = o.map(([M, f, v = 0]) => {
|
|
48
|
+
const [P, T] = p.lonLatToWorldCoords(M, f);
|
|
49
|
+
return new V(P - A, v - i, T - E);
|
|
50
|
+
}), k = new re().setFromPoints(w), O = new se({
|
|
51
|
+
color: e,
|
|
52
|
+
dashSize: l,
|
|
53
|
+
gapSize: h,
|
|
54
|
+
dashed: a,
|
|
55
|
+
worldUnits: !0,
|
|
56
|
+
linewidth: d
|
|
57
|
+
}), C = new oe(k, O);
|
|
58
|
+
a && C.computeLineDistances(), g(C);
|
|
59
|
+
};
|
|
60
|
+
return r.registerAnchor(u, {
|
|
61
|
+
anchor: t,
|
|
62
|
+
isAttached: !1,
|
|
63
|
+
latitude: n,
|
|
64
|
+
longitude: m,
|
|
65
|
+
altitude: c,
|
|
66
|
+
onAttach: L
|
|
67
|
+
}), () => {
|
|
68
|
+
r.unregisterAnchor(u);
|
|
69
|
+
};
|
|
70
|
+
}, [
|
|
71
|
+
r.isSuccess,
|
|
72
|
+
r.registerAnchor,
|
|
73
|
+
r.unregisterAnchor,
|
|
74
|
+
u,
|
|
75
|
+
t,
|
|
76
|
+
o,
|
|
77
|
+
e,
|
|
78
|
+
a,
|
|
79
|
+
l,
|
|
80
|
+
h,
|
|
81
|
+
d
|
|
82
|
+
]), x(
|
|
83
|
+
/* @__PURE__ */ G("group", { children: s && /* @__PURE__ */ G("primitive", { object: s }) }),
|
|
84
|
+
t
|
|
85
|
+
);
|
|
86
|
+
}, be = ({
|
|
87
|
+
latitude: o,
|
|
88
|
+
longitude: e,
|
|
89
|
+
altitude: a = 0,
|
|
90
|
+
isBillboard: l = !0,
|
|
91
|
+
onAttach: h,
|
|
92
|
+
onGpsUpdate: d,
|
|
93
|
+
children: r
|
|
94
|
+
}) => {
|
|
95
|
+
const t = N(), { camera: u } = U(), [s] = y(() => new D()), g = z(() => Math.random().toString(36).slice(2, 11), []), m = F(() => {
|
|
96
|
+
h?.();
|
|
97
|
+
}, [h]), n = F(
|
|
98
|
+
(c, L) => {
|
|
99
|
+
d?.(c, L);
|
|
100
|
+
},
|
|
101
|
+
[d]
|
|
102
|
+
);
|
|
103
|
+
return B(() => {
|
|
104
|
+
if (t.isSuccess)
|
|
105
|
+
return t.registerAnchor(g, {
|
|
106
|
+
anchor: s,
|
|
107
|
+
isAttached: !1,
|
|
108
|
+
latitude: o,
|
|
109
|
+
longitude: e,
|
|
110
|
+
altitude: a,
|
|
111
|
+
onAttach: m,
|
|
112
|
+
onGpsUpdate: n
|
|
113
|
+
}), () => {
|
|
114
|
+
t.unregisterAnchor(g);
|
|
115
|
+
};
|
|
116
|
+
}, [
|
|
117
|
+
t.isSuccess,
|
|
118
|
+
t.registerAnchor,
|
|
119
|
+
t.unregisterAnchor,
|
|
120
|
+
s,
|
|
121
|
+
g,
|
|
122
|
+
o,
|
|
123
|
+
e,
|
|
124
|
+
a,
|
|
125
|
+
m,
|
|
126
|
+
n
|
|
127
|
+
]), q(() => {
|
|
128
|
+
!l || !u || !t.isSuccess || !t.getAnchor(g)?.isAttached || s.lookAt(u.position);
|
|
129
|
+
}), x(/* @__PURE__ */ G("group", { children: r }), s);
|
|
130
|
+
}, ke = ({
|
|
131
|
+
options: o = {},
|
|
132
|
+
children: e
|
|
133
|
+
}) => {
|
|
134
|
+
const { scene: a, camera: l, gl: h } = U(), { registerBackend: d, unregisterBackend: r } = X(), t = W(null), u = W(o);
|
|
135
|
+
return u.current = o, B(() => {
|
|
136
|
+
if (t.current) return;
|
|
137
|
+
let s = !1;
|
|
138
|
+
return (async () => {
|
|
139
|
+
try {
|
|
140
|
+
const m = de(u.current);
|
|
141
|
+
if (s) return;
|
|
142
|
+
await d(m, { scene: a, camera: l, renderer: h }), t.current = m;
|
|
143
|
+
} catch (m) {
|
|
144
|
+
console.error("[GeolocationSession] Failed to initialize:", m);
|
|
145
|
+
}
|
|
146
|
+
})(), () => {
|
|
147
|
+
s = !0, t.current && (r(t.current), t.current = null);
|
|
148
|
+
};
|
|
149
|
+
}, [a, l, h, d, r]), e;
|
|
150
|
+
}, ue = {
|
|
151
|
+
front: Q,
|
|
152
|
+
back: $,
|
|
153
|
+
double: Y
|
|
154
|
+
}, Ge = ({
|
|
155
|
+
coordinates: o,
|
|
156
|
+
holes: e,
|
|
157
|
+
color: a = "#ff0000",
|
|
158
|
+
opacity: l = 1,
|
|
159
|
+
isWireframe: h = !1,
|
|
160
|
+
side: d = "double"
|
|
161
|
+
}) => {
|
|
162
|
+
const r = N(), [t] = y(() => new D()), u = z(() => Math.random().toString(36).slice(2, 11), []), [s, g] = y(null);
|
|
163
|
+
return B(() => {
|
|
164
|
+
if (!r.isSuccess || o.length < 3) return;
|
|
165
|
+
const [m, n, c = 0] = o[0], L = (p) => {
|
|
166
|
+
const [S, b, i = 0] = o[0], [A, E] = p.lonLatToWorldCoords(
|
|
167
|
+
S,
|
|
168
|
+
b
|
|
169
|
+
), w = [];
|
|
170
|
+
for (const [f, v, P = 0] of o) {
|
|
171
|
+
const [T, I] = p.lonLatToWorldCoords(f, v);
|
|
172
|
+
w.push({
|
|
173
|
+
x: T - A,
|
|
174
|
+
z: I - E,
|
|
175
|
+
elev: P - i
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const k = new ee();
|
|
179
|
+
k.moveTo(w[0].x, w[0].z);
|
|
180
|
+
for (let f = 1; f < w.length; f++)
|
|
181
|
+
k.lineTo(w[f].x, w[f].z);
|
|
182
|
+
if (k.closePath(), e && e.length > 0)
|
|
183
|
+
for (const f of e) {
|
|
184
|
+
if (f.length < 3) continue;
|
|
185
|
+
const v = new te(), [P, T] = f[0], [I, H] = p.lonLatToWorldCoords(
|
|
186
|
+
P,
|
|
187
|
+
T
|
|
188
|
+
);
|
|
189
|
+
v.moveTo(I - A, H - E);
|
|
190
|
+
for (let R = 1; R < f.length; R++) {
|
|
191
|
+
const [Z, J] = f[R], [K, _] = p.lonLatToWorldCoords(Z, J);
|
|
192
|
+
v.lineTo(K - A, _ - E);
|
|
193
|
+
}
|
|
194
|
+
v.closePath(), k.holes.push(v);
|
|
195
|
+
}
|
|
196
|
+
const O = new ne(k), M = w.reduce((f, v) => f + v.elev, 0) / w.length;
|
|
197
|
+
O.rotateX(-Math.PI / 2), g({ geometry: O, avgElevation: M });
|
|
198
|
+
};
|
|
199
|
+
return r.registerAnchor(u, {
|
|
200
|
+
anchor: t,
|
|
201
|
+
isAttached: !1,
|
|
202
|
+
latitude: n,
|
|
203
|
+
longitude: m,
|
|
204
|
+
altitude: c,
|
|
205
|
+
onAttach: L
|
|
206
|
+
}), () => {
|
|
207
|
+
r.unregisterAnchor(u);
|
|
208
|
+
};
|
|
209
|
+
}, [
|
|
210
|
+
r.isSuccess,
|
|
211
|
+
r.registerAnchor,
|
|
212
|
+
r.unregisterAnchor,
|
|
213
|
+
u,
|
|
214
|
+
t,
|
|
215
|
+
o,
|
|
216
|
+
e
|
|
217
|
+
]), x(
|
|
218
|
+
/* @__PURE__ */ G("group", { children: s && /* @__PURE__ */ G("group", { position: [0, s.avgElevation, 0], children: /* @__PURE__ */ G("mesh", { geometry: s.geometry, children: /* @__PURE__ */ G(
|
|
219
|
+
"meshBasicMaterial",
|
|
220
|
+
{
|
|
221
|
+
color: a,
|
|
222
|
+
opacity: l,
|
|
223
|
+
transparent: l < 1,
|
|
224
|
+
wireframe: h,
|
|
225
|
+
side: ue[d]
|
|
226
|
+
}
|
|
227
|
+
) }) }) }),
|
|
228
|
+
t
|
|
229
|
+
);
|
|
230
|
+
}, de = (o) => {
|
|
231
|
+
let e = null, a = null, l = null, h, d = null, r = null, t = null, u = null;
|
|
232
|
+
const s = /* @__PURE__ */ new Map();
|
|
233
|
+
let g = null;
|
|
234
|
+
const m = (n) => {
|
|
235
|
+
if (!(!e || n.isAttached))
|
|
236
|
+
try {
|
|
237
|
+
e.add(n.anchor, n.longitude, n.latitude, n.altitude), n.isAttached = !0, n.onAttach?.(e);
|
|
238
|
+
} catch (c) {
|
|
239
|
+
console.error("❌ Failed to attach anchor:", c);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
return {
|
|
243
|
+
type: j.GEOLOCATION,
|
|
244
|
+
async init(n) {
|
|
245
|
+
const { camera: c, renderer: L, scene: p } = n;
|
|
246
|
+
if (!p)
|
|
247
|
+
throw new Error(
|
|
248
|
+
"[geolocationBackend] A THREE.Scene is required for location-based AR"
|
|
249
|
+
);
|
|
250
|
+
r = c, t = L, u = p, e = new ce(p, c), a = new ie(
|
|
251
|
+
o?.webcamConstraints ?? {
|
|
252
|
+
video: { facingMode: "environment" }
|
|
253
|
+
// TODO remove `as any` once fixed upstream (LocAR.js)
|
|
254
|
+
}
|
|
255
|
+
), d = (i) => {
|
|
256
|
+
g = i.position;
|
|
257
|
+
for (const A of s.values())
|
|
258
|
+
A.isAttached || m(A), A.onGpsUpdate?.(i.position, i.distMoved);
|
|
259
|
+
o?.onGpsUpdate?.(i.position, i.distMoved);
|
|
260
|
+
}, e.on("gpsupdate", d), a.on("webcamstarted", (i) => {
|
|
261
|
+
p.background = i.texture;
|
|
262
|
+
}), a.on("webcamerror", (i) => {
|
|
263
|
+
console.error("[geolocationBackend] webcam error:", i);
|
|
264
|
+
}), l = new ae(c), l.on("deviceorientationgranted", (i) => {
|
|
265
|
+
i.target?.connect?.();
|
|
266
|
+
}), l.on("deviceorientationerror", (i) => {
|
|
267
|
+
console.error("[geolocationBackend] Device orientation error:", i);
|
|
268
|
+
}), l.init?.(), e.on("gpserror", (i) => {
|
|
269
|
+
console.error("[geolocationBackend] gps error:", i);
|
|
270
|
+
}), e.startGps(), typeof o?.fakeLat == "number" && typeof o?.fakeLon == "number" && e.fakeGps(o.fakeLon, o.fakeLat);
|
|
271
|
+
const S = e.getLastKnownLocation();
|
|
272
|
+
S !== null && (g = {
|
|
273
|
+
coords: {
|
|
274
|
+
longitude: S.longitude,
|
|
275
|
+
latitude: S.latitude,
|
|
276
|
+
accuracy: 0,
|
|
277
|
+
altitude: null,
|
|
278
|
+
altitudeAccuracy: null,
|
|
279
|
+
heading: null,
|
|
280
|
+
speed: null,
|
|
281
|
+
toJSON: () => S
|
|
282
|
+
},
|
|
283
|
+
timestamp: Date.now(),
|
|
284
|
+
toJSON: () => S
|
|
285
|
+
});
|
|
286
|
+
const b = () => {
|
|
287
|
+
if (!t || !r) return;
|
|
288
|
+
const i = window.innerWidth, A = window.innerHeight;
|
|
289
|
+
t.setSize(i, A, !1), r.aspect = i / A, r.updateProjectionMatrix?.();
|
|
290
|
+
};
|
|
291
|
+
b(), window.addEventListener("resize", b), h = b;
|
|
292
|
+
},
|
|
293
|
+
update() {
|
|
294
|
+
l?.update?.();
|
|
295
|
+
},
|
|
296
|
+
dispose() {
|
|
297
|
+
e && d && e.off("gpsupdate", d), e?.stopGps?.(), a?.stop?.(), l?.dispose?.(), h && (window.removeEventListener("resize", h), h = void 0);
|
|
298
|
+
for (const n of s.values())
|
|
299
|
+
if (n.isAttached)
|
|
300
|
+
try {
|
|
301
|
+
n.anchor.removeFromParent();
|
|
302
|
+
} catch (c) {
|
|
303
|
+
console.error("⚠️ Error removing anchor:", c);
|
|
304
|
+
}
|
|
305
|
+
s.clear(), e = null, a = null, l = null, r = null, t = null, u = null, d = null, g = null;
|
|
306
|
+
},
|
|
307
|
+
getInternal: () => ({
|
|
308
|
+
locar: e,
|
|
309
|
+
webcam: a,
|
|
310
|
+
deviceOrientation: l,
|
|
311
|
+
scene: u,
|
|
312
|
+
camera: r,
|
|
313
|
+
lastPosition: g,
|
|
314
|
+
registerAnchor: (n, c) => {
|
|
315
|
+
s.set(n, c), g !== null && !c.isAttached && (m(c), c.onGpsUpdate?.(g, 0));
|
|
316
|
+
},
|
|
317
|
+
unregisterAnchor: (n) => {
|
|
318
|
+
const c = s.get(n);
|
|
319
|
+
if (c?.isAttached)
|
|
320
|
+
try {
|
|
321
|
+
c.anchor.removeFromParent();
|
|
322
|
+
} catch (L) {
|
|
323
|
+
console.error(`⚠️ Error removing anchor ${n}:`, L);
|
|
324
|
+
}
|
|
325
|
+
s.delete(n);
|
|
326
|
+
},
|
|
327
|
+
getAnchor: (n) => s.get(n)
|
|
328
|
+
})
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
export {
|
|
332
|
+
Se as G,
|
|
333
|
+
be as a,
|
|
334
|
+
ke as b,
|
|
335
|
+
Ge as c,
|
|
336
|
+
de as d,
|
|
337
|
+
N as u
|
|
338
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./ImmersiveSession-BiX-Du0K.cjs");exports.ImmersiveSession=e.ImmersiveSession;
|
package/build/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react"),h=require("@react-three/fiber"),v=require("react/jsx-runtime"),I=require("@ar-js-org/ar.js/three.js/build/ar-threex"),N=require("three"),R=require("locar"),x=require("@react-three/xr");var C=typeof document<"u"?document.currentScript:null;const p={FIDUCIAL:"fiducial",GEOLOCATION:"geolocation",IMMERSIVE:"immersive"},M=n=>{let e;const t=new Set,r=(a,f)=>{const l=typeof a=="function"?a(e):a;if(!Object.is(l,e)){const o=e;e=f??(typeof l!="object"||l===null)?l:Object.assign({},e,l),t.forEach(d=>d(e,o))}},c=()=>e,s={setState:r,getState:c,getInitialState:()=>u,subscribe:a=>(t.add(a),()=>t.delete(a))},u=e=n(r,c,s);return s},D=(n=>n?M(n):M),U=n=>n;function q(n,e=U){const t=m.useSyncExternalStore(n.subscribe,m.useCallback(()=>e(n.getState()),[n,e]),m.useCallback(()=>e(n.getInitialState()),[n,e]));return m.useDebugValue(t),t}const X=n=>{const e=D(n),t=r=>q(e,r);return Object.assign(t,e),t},H=(n=>X),W=n=>(e,t,r)=>{const c=r.subscribe;return r.subscribe=((A,s,u)=>{let a=A;if(s){const f=u?.equalityFn||Object.is;let l=A(r.getState());a=o=>{const d=A(o);if(!f(l,d)){const b=l;s(l=d,b)}},u?.fireImmediately&&s(l,l)}return c(a)}),n(e,t,r)},_=W,T=n=>Symbol.iterator in n,F=n=>"entries"in n,j=(n,e)=>{const t=n instanceof Map?n:new Map(n.entries()),r=e instanceof Map?e:new Map(e.entries());if(t.size!==r.size)return!1;for(const[c,i]of t)if(!r.has(c)||!Object.is(i,r.get(c)))return!1;return!0},K=(n,e)=>{const t=n[Symbol.iterator](),r=e[Symbol.iterator]();let c=t.next(),i=r.next();for(;!c.done&&!i.done;){if(!Object.is(c.value,i.value))return!1;c=t.next(),i=r.next()}return!!c.done&&!!i.done};function V(n,e){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)?F(n)&&F(e)?j(n,e):K(n,e):j({entries:()=>Object.entries(n)},{entries:()=>Object.entries(e)})}function Y(n){const e=m.useRef(void 0);return t=>{const r=n(t);return V(e.current,r)?e.current:e.current=r}}const O=H()(_((n,e)=>({video:null,backends:new Map,immersiveStore:null,registerBackend:async(t,r)=>{try{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;if(A&&s){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.";throw console.error(u),new Error(u)}await t.init({scene:r.scene,camera:r.camera,renderer:r.renderer}),n(u=>{const a=new Map(u.backends);return a.set(t.type,t),{backends:a}})}catch(c){throw console.error("[XRStore] Failed to register backend:",c),c}},unregisterBackend:t=>{n(r=>{const c=new Map(r.backends);c.delete(t.type);try{t.dispose?.()}catch(i){console.error("[XRStore] Error disposing backend:",i)}return{backends:c}})},setVideo:t=>{n({video:t})},updateBackends:t=>{const{backends:r}=e();for(const c of r.values())try{c.update?.(t)}catch(i){console.error("[XRStore] Backend update error:",i)}},setImmersiveStore:t=>{n({immersiveStore:t})}}))),L=()=>O.getState(),Q=O.subscribe,k=n=>O(Y(t=>{const r={...t,isImmersive:t.backends.has(p.IMMERSIVE),immersive:t.immersiveStore||null};return n?n(r):r})),J=({children:n})=>{const{updateBackends:e}=k();return h.useFrame((t,r)=>{e(r)}),n},$={isPending:!0,isSuccess:!1,arSource:null,arContext:null},B=()=>{const e=k(t=>t.backends).get(p.FIDUCIAL);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:$},Z=({patternUrl:n,barcodeValue:e,params:t,onMarkerFound:r,onMarkerLost:c,children:i})=>{const A=m.useRef(null),s=B(),u=m.useRef(!1),a=m.useRef(!1),f=m.useRef(null);return m.useEffect(()=>{if(!s.isSuccess)return;let l=!1;return(()=>{try{const{arContext:d}=s,b=A.current;if(!d||!b||l)return;if(b.visible=!1,a.current=!1,!d.arController){requestAnimationFrame(()=>{if(!A.current||l||!s.arContext?.arController)return;const g=new I.ArMarkerControls(s.arContext,A.current,{type:n?"pattern":e?"barcode":"unknown",patternUrl:n,barcodeValue:e,...t});f.current=g,a.current=!0});return}const w=new I.ArMarkerControls(d,b,{type:n?"pattern":e?"barcode":"unknown",patternUrl:n,barcodeValue:e,...t});f.current=w,a.current=!0}catch(d){console.error("Failed to initialize fiducial anchor:",d)}})(),()=>{l=!0;const d=f.current;typeof d?.dispose=="function"&&d.dispose(),a.current=!1}},[s.isSuccess,s.arContext,n,e,t,s]),h.useFrame(()=>{const l=A.current;if(!l||!a.current){l&&(l.visible=!1);return}const o=l.visible;o&&!u.current?(u.current=!0,r?.()):!o&&u.current&&(u.current=!1,c?.())}),v.jsx("group",{ref:A,visible:!1,children:i})},ee=({options:n={},children:e})=>{const{scene:t,camera:r,gl:c}=h.useThree(),{registerBackend:i,unregisterBackend:A}=k(),s=m.useRef(null),u=m.useRef(n);return u.current=n,m.useEffect(()=>{if(s.current)return;let a=!1;return(async()=>{try{const l=G(u.current);if(a)return;await i(l,{scene:t,camera:r,renderer:c}),s.current=l}catch(l){console.error("[FiducialSession] Failed to initialize:",l)}})(),()=>{a=!0,s.current&&(A(s.current),s.current=null)}},[t,r,c,i,A]),e},G=n=>{let e=null,t=null,r=null,c;return{type:p.FIDUCIAL,async init({camera:i,renderer:A}){e=new I.ArToolkitSource({sourceType:n?.sourceType??"webcam"}),await new Promise((a,f)=>{const l=setTimeout(()=>{f(new Error("AR source initialization timeout"))},1e4);e?.init(()=>{clearTimeout(l);const o=e?.domElement;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()})});const s={cameraParametersUrl:n?.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("index.cjs",document.baseURI).href).toString(),detectionMode:n?.detectionMode??"mono",patternRatio:n?.patternRatio??.5,matrixCodeType:n?.matrixCodeType??"3x3"};t=new I.ArToolkitContext(s),r=i;const u=()=>{e?.onResizeElement();const a=window.innerWidth,f=window.innerHeight;A.setSize(a,f,!1),e?.copyElementSizeTo(A.domElement),t?.arController&&e?.copyElementSizeTo(t.arController.canvas)};await new Promise((a,f)=>{const l=setTimeout(()=>{f(new Error("AR context initialization timeout"))},1e4);t?.init(()=>{clearTimeout(l);try{const o=t?.getProjectionMatrix();o&&i.projectionMatrix.copy(o),u(),a()}catch(o){f(o)}})}),window.addEventListener("resize",u),c=u},update(){if(!(!e||!t)&&!(!e.ready||!e.domElement))try{t.update(e.domElement);const i=t.getProjectionMatrix?.();r&&i&&r.projectionMatrix.copy(i)}catch(i){console.warn("AR.js update error:",i)}},dispose(){if(c&&(window.removeEventListener("resize",c),c=void 0),t&&typeof t.dispose=="function"&&t.dispose(),e?.domElement){const i=e.domElement.parentNode;i&&i.removeChild(e.domElement)}e=null,t=null,r=null},getInternal:()=>({arSource:e,arContext:t})}},te={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>{}},P=()=>{const e=k(t=>t.backends).get(p.GEOLOCATION);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:te},ne=({latitude:n,longitude:e,altitude:t=0,isBillboard:r=!0,onAttach:c,onGpsUpdate:i,children:A})=>{const s=P(),{camera:u}=h.useThree(),[a]=m.useState(()=>new N.Group),f=m.useMemo(()=>Math.random().toString(36).slice(2,11),[]),l=m.useCallback(()=>{c?.()},[c]),o=m.useCallback((d,b)=>{i?.(d,b)},[i]);return m.useEffect(()=>{if(s.isSuccess)return s.registerAnchor(f,{anchor:a,isAttached:!1,latitude:n,longitude:e,altitude:t,onAttach:l,onGpsUpdate:o}),()=>{s.unregisterAnchor(f)}},[s.isSuccess,s.registerAnchor,s.unregisterAnchor,a,f,n,e,t,l,o]),h.useFrame(()=>{!r||!u||!s.isSuccess||!s.getAnchor(f)?.isAttached||a.lookAt(u.position)}),h.createPortal(v.jsx("group",{children:A}),a)},re=({options:n={},children:e})=>{const{scene:t,camera:r,gl:c}=h.useThree(),{registerBackend:i,unregisterBackend:A}=k(),s=m.useRef(null),u=m.useRef(n);return u.current=n,m.useEffect(()=>{if(s.current)return;let a=!1;return(async()=>{try{const l=z(u.current);if(a)return;await i(l,{scene:t,camera:r,renderer:c}),s.current=l}catch(l){console.error("[GeolocationSession] Failed to initialize:",l)}})(),()=>{a=!0,s.current&&(A(s.current),s.current=null)}},[t,r,c,i,A]),e},z=n=>{let e=null,t=null,r=null,c,i=null,A=null,s=null,u=null;const a=new Map;let f=null;const l=o=>{if(!(!e||o.isAttached))try{e.add(o.anchor,o.longitude,o.latitude,o.altitude),o.isAttached=!0,o.onAttach?.()}catch(d){console.error("❌ Failed to attach anchor:",d)}};return{type:p.GEOLOCATION,async init(o){const{camera:d,renderer:b,scene:w}=o;if(!w)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");A=d,s=b,u=w,e=new R.LocationBased(w,d),t=new R.Webcam(n?.webcamConstraints??{video:{facingMode:"environment"}}),i=S=>{f=S.position;for(const y of a.values())y.isAttached||l(y),y.onGpsUpdate?.(S.position,S.distMoved);n?.onGpsUpdate?.(S.position,S.distMoved)},e.on("gpsupdate",i),t.on("webcamstarted",S=>{w.background=S.texture}),t.on("webcamerror",S=>{console.error("[geolocationBackend] webcam error:",S)}),r=new R.DeviceOrientationControls(d),r.on("deviceorientationgranted",S=>{S.target?.connect?.()}),r.on("deviceorientationerror",S=>{console.error("[geolocationBackend] Device orientation error:",S)}),r.init?.(),e.on("gpserror",S=>{console.error("[geolocationBackend] gps error:",S)}),e.startGps(),typeof n?.fakeLat=="number"&&typeof n?.fakeLon=="number"&&e.fakeGps(n.fakeLon,n.fakeLat);const g=e.getLastKnownLocation();g!==null&&(f={coords:{longitude:g.longitude,latitude:g.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>g},timestamp:Date.now(),toJSON:()=>g});const E=()=>{if(!s||!A)return;const S=window.innerWidth,y=window.innerHeight;s.setSize(S,y,!1),A.aspect=S/y,A.updateProjectionMatrix?.()};E(),window.addEventListener("resize",E),c=E},update(){r?.update?.()},dispose(){e&&i&&e.off("gpsupdate",i),e?.stopGps?.(),t?.stop?.(),r?.dispose?.(),c&&(window.removeEventListener("resize",c),c=void 0);for(const o of a.values())if(o.isAttached)try{o.anchor.removeFromParent()}catch(d){console.error("⚠️ Error removing anchor:",d)}a.clear(),e=null,t=null,r=null,A=null,s=null,u=null,i=null,f=null},getInternal:()=>({locar:e,webcam:t,deviceOrientation:r,scene:u,camera:A,lastPosition:f,registerAnchor:(o,d)=>{a.set(o,d),f!==null&&!d.isAttached&&(l(d),d.onGpsUpdate?.(f,0))},unregisterAnchor:o=>{const d=a.get(o);if(d?.isAttached)try{d.anchor.removeFromParent()}catch(b){console.error(`⚠️ Error removing anchor ${o}:`,b)}a.delete(o)},getAnchor:o=>a.get(o)})}},oe=()=>({type:p.IMMERSIVE,init:()=>{},getInternal:()=>null}),se=({children:n})=>{const e=m.useMemo(()=>x.createXRStore(),[]);return m.useEffect(()=>{const t=L(),r=oe();return t.backends.set(p.IMMERSIVE,r),t.setImmersiveStore(e),()=>{t.backends.delete(p.IMMERSIVE),t.setImmersiveStore(null)}},[e]),v.jsx(x.XR,{store:e,children:n})};exports.BACKEND_TYPES=p;exports.FiducialAnchor=Z;exports.FiducialSession=ee;exports.GeolocationAnchor=ne;exports.GeolocationSession=re;exports.ImmersiveSession=se;exports.XR=J;exports.createFiducialBackend=G;exports.createGeolocationBackend=z;exports.getXRStore=L;exports.subscribeToXRStore=Q;exports.useFiducialBackend=B;exports.useGeolocationBackend=P;exports.useXRStore=k;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./useXRStore-emhiLtDT.cjs"),s=require("@react-three/fiber"),c=require("./fiducialBackend-Cr8mdwro.cjs"),e=require("./geolocationBackend-BkS2-zqx.cjs"),t=require("./ImmersiveSession-BiX-Du0K.cjs"),i=require("./WorldAnchor-gszXX9H2.cjs"),u=({children:n})=>{const{updateBackends:r}=o.useXRStore();return s.useFrame((d,a)=>{r(a)}),n};exports.BACKEND_TYPES=o.BACKEND_TYPES;exports.getXRStore=o.getXRStore;exports.subscribeToXRStore=o.subscribeToXRStore;exports.useXRStore=o.useXRStore;exports.FiducialAnchor=c.FiducialAnchor;exports.FiducialSession=c.FiducialSession;exports.createFiducialBackend=c.createFiducialBackend;exports.useFiducialBackend=c.useFiducialBackend;exports.GeoLine=e.GeoLine;exports.GeoPolygon=e.GeoPolygon;exports.GeolocationAnchor=e.GeolocationAnchor;exports.GeolocationSession=e.GeolocationSession;exports.createGeolocationBackend=e.createGeolocationBackend;exports.useGeolocationBackend=e.useGeolocationBackend;exports.ImmersiveSession=t.ImmersiveSession;exports.MagicSession=i.MagicSession;exports.WorldAnchor=i.WorldAnchor;exports.createMagicBackend=i.createMagicBackend;exports.XR=u;
|
package/build/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './fiducial';
|
|
|
4
4
|
export * from './geolocation';
|
|
5
5
|
export * from './immersive';
|
|
6
6
|
export { BACKEND_TYPES } from './lib/types/engine';
|
|
7
|
+
export * from './magic';
|
|
7
8
|
export type { Backend, BackendType, } from './lib/types/engine';
|
|
8
9
|
export type { ImmersiveMode } from './lib/types/immersive';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,UAAU,EACV,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,UAAU,EACV,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,cAAc,SAAS,CAAC;AAExB,YAAY,EACV,OAAO,EACP,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D,OAAO,oBAAoB,CAAC"}
|