@omnidotdev/rdk 0.12.2 → 0.14.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 +2 -0
- package/build/engine/useXRStore.d.ts.map +1 -1
- package/build/engine-EvzyijbY.cjs +1 -0
- package/build/engine-NEJZ-OgD.js +11 -0
- package/build/engine.cjs +1 -0
- package/build/engine.d.ts +2 -0
- package/build/engine.js +3 -0
- package/build/{fiducial-C7jQpZcK.js → fiducial-7pF-ErgE.js} +12 -11
- package/build/fiducial-Tris7XAY.cjs +1 -0
- package/build/fiducial.cjs +1 -1
- package/build/fiducial.js +1 -2
- package/build/geolocation/GeoLine.d.ts +14 -1
- package/build/geolocation/GeoLine.d.ts.map +1 -1
- package/build/geolocation/GeoPolygon.d.ts +14 -1
- package/build/geolocation/GeoPolygon.d.ts.map +1 -1
- package/build/geolocation/GeolocationSession.d.ts.map +1 -1
- package/build/geolocation/geolocationBackend.d.ts +8 -2
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/{geolocation-DbT8iR2H.js → geolocation-C_n3zwq4.js} +134 -102
- package/build/geolocation-D0RxA8Tv.cjs +1 -0
- package/build/geolocation.cjs +1 -1
- package/build/geolocation.js +1 -2
- package/build/{immersive-DZ9J_acN.js → immersive-CoSRZ58s.js} +1 -1
- package/build/{immersive-ikuE6hTP.cjs → immersive-DMYGUy_v.cjs} +1 -1
- package/build/immersive.cjs +1 -1
- package/build/immersive.js +1 -2
- package/build/index.cjs +1 -1
- package/build/index.js +9 -16
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts +3 -0
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts.map +1 -1
- package/build/magic/magicBackend.d.ts.map +1 -1
- package/build/magic-B9pQnRYJ.cjs +1 -0
- package/build/{magic-DAyR255x.js → magic-CjnX9lWp.js} +45 -50
- package/build/magic.cjs +1 -1
- package/build/magic.js +1 -2
- package/build/{useXRStore-CousLTRl.js → useXRStore-BTnI1ZM2.js} +2 -1
- package/build/{useXRStore-XWI97jRe.cjs → useXRStore-Cf_XL0aI.cjs} +1 -1
- package/build/{vision-DmoN9LKO.cjs → vision-BLWMU9Ys.cjs} +1 -1
- package/build/{vision-Dogx4i9B.js → vision-Vp2iuVNJ.js} +16 -15
- package/build/vision.cjs +1 -1
- package/build/vision.js +1 -2
- package/package.json +11 -5
- package/build/fiducial-C4M9sMNn.cjs +0 -1
- package/build/geolocation-BKCHn-Gq.cjs +0 -1
- package/build/magic-Brm3MYTP.cjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as e, r as t } from "./useXRStore-
|
|
1
|
+
import { i as e, r as t } from "./useXRStore-BTnI1ZM2.js";
|
|
2
2
|
import { useCallback as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
|
|
3
3
|
import { createPortal as s, useFrame as c, useThree as l } from "@react-three/fiber";
|
|
4
4
|
import { jsx as u } from "react/jsx-runtime";
|
|
@@ -6,9 +6,9 @@ import { BackSide as d, BufferAttribute as f, BufferGeometry as p, DoubleSide as
|
|
|
6
6
|
import { Line2 as C } from "three/addons/lines/Line2.js";
|
|
7
7
|
import { LineGeometry as w } from "three/addons/lines/LineGeometry.js";
|
|
8
8
|
import { LineMaterial as T } from "three/addons/lines/LineMaterial.js";
|
|
9
|
-
import { App as E } from "locar";
|
|
9
|
+
import { App as E, LocAR as D } from "locar";
|
|
10
10
|
//#region src/geolocation/useGeolocationBackend.ts
|
|
11
|
-
var
|
|
11
|
+
var O = {
|
|
12
12
|
isPending: !0,
|
|
13
13
|
isSuccess: !1,
|
|
14
14
|
locar: null,
|
|
@@ -20,14 +20,14 @@ var D = {
|
|
|
20
20
|
registerAnchor: () => {},
|
|
21
21
|
unregisterAnchor: () => {},
|
|
22
22
|
getAnchor: () => void 0
|
|
23
|
-
},
|
|
23
|
+
}, k = () => {
|
|
24
24
|
let n = t((e) => e.backends).get(e.GEOLOCATION);
|
|
25
25
|
return n ? {
|
|
26
26
|
...n.getInternal(),
|
|
27
27
|
isPending: !1,
|
|
28
28
|
isSuccess: !0
|
|
29
|
-
} :
|
|
30
|
-
},
|
|
29
|
+
} : O;
|
|
30
|
+
}, A = (e, t) => {
|
|
31
31
|
let n = e.length - 1, r = [], i = 0, a = 0;
|
|
32
32
|
for (let o = 0; o < n; o++) {
|
|
33
33
|
let n = e[o + 1].x - e[o].x, s = e[o + 1].y - e[o].y, c = e[o + 1].z - e[o].z, l = Math.sqrt(n * n + s * s + c * c), u = t / 2, d = -(c * u) / l, f = n * u / l, p = o > 0 ? (d + i) / 2 : d, m = o > 0 ? (f + a) / 2 : f;
|
|
@@ -38,60 +38,65 @@ var D = {
|
|
|
38
38
|
for (let e = 0; e < n; e++) o.push(e * 2, e * 2 + 1, e * 2 + 2), o.push(e * 2 + 1, e * 2 + 3, e * 2 + 2);
|
|
39
39
|
let s = new p();
|
|
40
40
|
return s.setIndex(o), s.setAttribute("position", new f(new Float32Array(r), 3)), s.computeBoundingBox(), s;
|
|
41
|
-
},
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
let [
|
|
41
|
+
}, j = ({ coordinates: e, color: t = "#ff0000", isDashed: n = !1, dashSize: c = 3, gapSize: l = 1, lineWidth: d = 1, onClick: f, onPointerOut: p, onPointerOver: h, opacity: y = 1 }) => {
|
|
42
|
+
let b = k(), x = a(b);
|
|
43
|
+
x.current = b;
|
|
44
|
+
let [E] = o(() => new g()), D = i(() => Math.random().toString(36).slice(2, 11), []), [O, j] = o(null);
|
|
45
45
|
return r(() => {
|
|
46
|
-
if (!
|
|
46
|
+
if (!b.isSuccess || e.length < 2) return;
|
|
47
47
|
let [r, i, a = 0] = e[0];
|
|
48
|
-
return
|
|
49
|
-
anchor:
|
|
48
|
+
return x.current.registerAnchor(D, {
|
|
49
|
+
anchor: E,
|
|
50
50
|
isAttached: !1,
|
|
51
51
|
latitude: i,
|
|
52
52
|
longitude: r,
|
|
53
53
|
altitude: a,
|
|
54
54
|
onAttach: (r) => {
|
|
55
|
-
let [i, a, o = 0] = e[0], [s, u] = r.lonLatToWorldCoords(i, a),
|
|
55
|
+
let [i, a, o = 0] = e[0], [s, u] = r.lonLatToWorldCoords(i, a), f = e.map(([e, t, n = 0]) => {
|
|
56
56
|
let [i, a] = r.lonLatToWorldCoords(e, t);
|
|
57
57
|
return new S(i - s, n - o, a - u);
|
|
58
58
|
});
|
|
59
59
|
if (n) {
|
|
60
|
-
let e = new C(new w().setFromPoints(
|
|
60
|
+
let e = new C(new w().setFromPoints(f), new T({
|
|
61
61
|
color: t,
|
|
62
62
|
dashSize: c,
|
|
63
63
|
gapSize: l,
|
|
64
64
|
dashed: !0,
|
|
65
65
|
worldUnits: !0,
|
|
66
66
|
linewidth: d,
|
|
67
|
-
transparent:
|
|
68
|
-
opacity:
|
|
67
|
+
transparent: y < 1,
|
|
68
|
+
opacity: y
|
|
69
69
|
}));
|
|
70
|
-
e.computeLineDistances(),
|
|
71
|
-
} else
|
|
70
|
+
e.computeLineDistances(), j(e);
|
|
71
|
+
} else j(new _(A(f, d), new v({
|
|
72
72
|
color: t,
|
|
73
|
-
transparent:
|
|
74
|
-
opacity:
|
|
73
|
+
transparent: y < 1,
|
|
74
|
+
opacity: y,
|
|
75
75
|
side: m
|
|
76
76
|
})));
|
|
77
77
|
}
|
|
78
78
|
}), () => {
|
|
79
|
-
|
|
79
|
+
x.current.unregisterAnchor(D), j((e) => (e && (e.geometry.dispose(), e.material.dispose()), null));
|
|
80
80
|
};
|
|
81
81
|
}, [
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
D,
|
|
83
|
+
E,
|
|
84
84
|
e,
|
|
85
85
|
t,
|
|
86
86
|
n,
|
|
87
87
|
c,
|
|
88
88
|
l,
|
|
89
89
|
d,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
]), s(/* @__PURE__ */ u("group", {
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
y,
|
|
91
|
+
b.isSuccess
|
|
92
|
+
]), s(/* @__PURE__ */ u("group", {
|
|
93
|
+
onClick: f,
|
|
94
|
+
onPointerOut: p,
|
|
95
|
+
onPointerOver: h,
|
|
96
|
+
children: O && /* @__PURE__ */ u("primitive", { object: O })
|
|
97
|
+
}), E);
|
|
98
|
+
}, M = ({ latitude: e, longitude: t, altitude: d = 0, isBillboard: f = !0, onAttach: p, onGpsUpdate: m, children: h }) => {
|
|
99
|
+
let _ = k(), v = a(_);
|
|
95
100
|
v.current = _;
|
|
96
101
|
let { camera: y } = l(), [b] = o(() => new g()), x = i(() => Math.random().toString(36).slice(2, 11), []), S = n(() => {
|
|
97
102
|
p?.();
|
|
@@ -122,46 +127,49 @@ var D = {
|
|
|
122
127
|
]), c(() => {
|
|
123
128
|
!f || !y || !_.isSuccess || _.getAnchor(x)?.isAttached && b.lookAt(y.position);
|
|
124
129
|
}), s(/* @__PURE__ */ u("group", { children: h }), b);
|
|
125
|
-
},
|
|
126
|
-
let { scene: i, camera: o, gl: s } = l(), { registerBackend:
|
|
127
|
-
return
|
|
128
|
-
if (
|
|
130
|
+
}, N = ({ options: e = {}, children: n }) => {
|
|
131
|
+
let { scene: i, camera: o, gl: s, size: c } = l(), { registerBackend: u, unregisterBackend: d } = t(), f = a(null), p = a(e);
|
|
132
|
+
return p.current = e, r(() => {
|
|
133
|
+
if (f.current) return;
|
|
129
134
|
let e = !1;
|
|
130
135
|
return (async () => {
|
|
131
136
|
try {
|
|
132
|
-
let t =
|
|
137
|
+
let t = I(p.current);
|
|
133
138
|
if (e) return;
|
|
134
|
-
await
|
|
139
|
+
await u(t, {
|
|
135
140
|
scene: i,
|
|
136
141
|
camera: o,
|
|
137
|
-
renderer: s
|
|
138
|
-
|
|
142
|
+
renderer: s,
|
|
143
|
+
size: c
|
|
144
|
+
}), f.current = t;
|
|
139
145
|
} catch (e) {
|
|
140
146
|
console.error("[GeolocationSession] Failed to initialize:", e);
|
|
141
147
|
}
|
|
142
148
|
})(), () => {
|
|
143
|
-
e = !0,
|
|
149
|
+
e = !0, f.current &&= (d(f.current), null);
|
|
144
150
|
};
|
|
145
151
|
}, [
|
|
146
152
|
i,
|
|
147
153
|
o,
|
|
148
154
|
s,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
]),
|
|
152
|
-
|
|
155
|
+
u,
|
|
156
|
+
d
|
|
157
|
+
]), r(() => {
|
|
158
|
+
f.current?.setSize(c);
|
|
159
|
+
}, [c]), n;
|
|
160
|
+
}, P = {
|
|
153
161
|
front: h,
|
|
154
162
|
back: d,
|
|
155
163
|
double: m
|
|
156
|
-
},
|
|
157
|
-
let
|
|
158
|
-
|
|
159
|
-
let [
|
|
164
|
+
}, F = ({ coordinates: e, holes: t, color: n = "#ff0000", opacity: c = 1, isWireframe: l = !1, onClick: d, onPointerOut: f, onPointerOver: p, side: m = "double" }) => {
|
|
165
|
+
let h = k(), _ = a(h);
|
|
166
|
+
_.current = h;
|
|
167
|
+
let [v] = o(() => new g()), S = i(() => Math.random().toString(36).slice(2, 11), []), [C, w] = o(null);
|
|
160
168
|
return r(() => {
|
|
161
|
-
if (!
|
|
169
|
+
if (!h.isSuccess || e.length < 3) return;
|
|
162
170
|
let [n, r, i = 0] = e[0];
|
|
163
|
-
return
|
|
164
|
-
anchor:
|
|
171
|
+
return _.current.registerAnchor(S, {
|
|
172
|
+
anchor: v,
|
|
165
173
|
isAttached: !1,
|
|
166
174
|
latitude: r,
|
|
167
175
|
longitude: n,
|
|
@@ -190,132 +198,156 @@ var D = {
|
|
|
190
198
|
t.closePath(), l.holes.push(t);
|
|
191
199
|
}
|
|
192
200
|
let u = new x(l), d = c.reduce((e, t) => e + t.elev, 0) / c.length;
|
|
193
|
-
u.rotateX(-Math.PI / 2),
|
|
201
|
+
u.rotateX(-Math.PI / 2), w({
|
|
194
202
|
geometry: u,
|
|
195
203
|
avgElevation: d
|
|
196
204
|
});
|
|
197
205
|
}
|
|
198
206
|
}), () => {
|
|
199
|
-
|
|
207
|
+
_.current.unregisterAnchor(S), w((e) => (e && e.geometry.dispose(), null));
|
|
200
208
|
};
|
|
201
209
|
}, [
|
|
202
|
-
|
|
203
|
-
|
|
210
|
+
S,
|
|
211
|
+
v,
|
|
204
212
|
e,
|
|
205
213
|
t,
|
|
206
|
-
|
|
207
|
-
]), s(/* @__PURE__ */ u("group", { children:
|
|
214
|
+
h.isSuccess
|
|
215
|
+
]), s(/* @__PURE__ */ u("group", { children: C && /* @__PURE__ */ u("group", {
|
|
208
216
|
position: [
|
|
209
217
|
0,
|
|
210
|
-
|
|
218
|
+
C.avgElevation,
|
|
211
219
|
0
|
|
212
220
|
],
|
|
213
221
|
children: /* @__PURE__ */ u("mesh", {
|
|
214
|
-
geometry:
|
|
222
|
+
geometry: C.geometry,
|
|
223
|
+
onClick: d,
|
|
224
|
+
onPointerOut: f,
|
|
225
|
+
onPointerOver: p,
|
|
215
226
|
children: /* @__PURE__ */ u("meshBasicMaterial", {
|
|
216
227
|
color: n,
|
|
217
228
|
opacity: c,
|
|
218
229
|
transparent: c < 1,
|
|
219
230
|
wireframe: l,
|
|
220
|
-
side:
|
|
231
|
+
side: P[m]
|
|
221
232
|
})
|
|
222
233
|
})
|
|
223
|
-
}) }),
|
|
224
|
-
},
|
|
225
|
-
let n = null, r = null, i, a = null, o = null, s = null, c = null, l =
|
|
234
|
+
}) }), v);
|
|
235
|
+
}, I = (t) => {
|
|
236
|
+
let n = null, r = null, i = null, a = null, o = null, s = null, c = null, l = {
|
|
237
|
+
width: 0,
|
|
238
|
+
height: 0
|
|
239
|
+
}, u = /* @__PURE__ */ new Map(), d = null, f = (e) => {
|
|
226
240
|
if (!(!r || e.isAttached)) try {
|
|
227
241
|
r.add(e.anchor, e.longitude, e.latitude, e.altitude), e.isAttached = !0, e.onAttach?.(r);
|
|
228
242
|
} catch (e) {
|
|
229
243
|
console.error("❌ Failed to attach anchor:", e);
|
|
230
244
|
}
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
},
|
|
234
|
-
let t =
|
|
245
|
+
}, p = (e, t) => {
|
|
246
|
+
u.set(e, t), d !== null && !t.isAttached && (f(t), t.onGpsUpdate?.(d, 0));
|
|
247
|
+
}, m = (e) => {
|
|
248
|
+
let t = u.get(e);
|
|
235
249
|
if (t?.isAttached) try {
|
|
236
250
|
t.anchor.removeFromParent();
|
|
237
251
|
} catch (t) {
|
|
238
252
|
console.error(`⚠️ Error removing anchor ${e}:`, t);
|
|
239
253
|
}
|
|
240
|
-
|
|
241
|
-
},
|
|
254
|
+
u.delete(e);
|
|
255
|
+
}, h = (e) => u.get(e);
|
|
242
256
|
return {
|
|
243
257
|
type: e.GEOLOCATION,
|
|
244
258
|
async init(e) {
|
|
245
|
-
let { camera:
|
|
259
|
+
let { camera: l, renderer: p, scene: m, size: h } = e;
|
|
246
260
|
if (!m) throw Error("[geolocationBackend] A THREE.Scene is required for location-based AR");
|
|
247
|
-
|
|
261
|
+
a = l, o = p, s = m, c = h;
|
|
262
|
+
let g = a, _ = t?.hFov ?? 80;
|
|
263
|
+
g.fov = D.htov(_, h.width / h.height), g.updateProjectionMatrix(), n = new E({
|
|
248
264
|
threeObjects: {
|
|
249
|
-
camera:
|
|
265
|
+
camera: l,
|
|
250
266
|
renderer: p,
|
|
251
267
|
scene: m
|
|
252
268
|
},
|
|
253
269
|
videoConstraints: t?.webcamConstraints ?? { video: { facingMode: "environment" } },
|
|
254
|
-
deviceOrientationOptions: { enabled: !0 }
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
270
|
+
deviceOrientationOptions: { enabled: !0 },
|
|
271
|
+
dimensionsProvider: () => c ? {
|
|
272
|
+
width: c.width,
|
|
273
|
+
height: c.height
|
|
274
|
+
} : {
|
|
275
|
+
width: 0,
|
|
276
|
+
height: 0
|
|
277
|
+
}
|
|
278
|
+
}), p.setClearAlpha?.(0), i = (e) => {
|
|
279
|
+
d = e.position;
|
|
280
|
+
for (let t of u.values()) t.isAttached || f(t), t.onGpsUpdate?.(e.position, e.distMoved);
|
|
258
281
|
t?.onGpsUpdate?.(e.position, e.distMoved);
|
|
259
282
|
}, r = await n.start();
|
|
260
|
-
let
|
|
261
|
-
if (
|
|
262
|
-
|
|
283
|
+
let v = n.deviceOrientationControls;
|
|
284
|
+
if (v && v.orientationChangeEventName !== "deviceorientation") try {
|
|
285
|
+
v.disconnect(), v.orientationChangeEventName = "deviceorientation", v.connect();
|
|
263
286
|
} catch (e) {
|
|
264
287
|
console.error("[geolocationBackend] failed to rebind device orientation event:", e);
|
|
265
288
|
}
|
|
266
|
-
r.on("gpsupdate",
|
|
289
|
+
r.on("gpsupdate", i), n.webcam?.on?.("webcamerror", (e) => {
|
|
267
290
|
console.error("[geolocationBackend] webcam error:", e);
|
|
268
291
|
}), n.deviceOrientationControls?.on?.("deviceorientationerror", (e) => {
|
|
269
292
|
console.error("[geolocationBackend] Device orientation error:", e);
|
|
270
293
|
}), r.on("gpserror", (e) => {
|
|
271
294
|
console.error("[geolocationBackend] gps error:", e);
|
|
272
|
-
}),
|
|
273
|
-
let
|
|
274
|
-
|
|
295
|
+
}), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" ? r.fakeGps(t.fakeLon, t.fakeLat) : r.startGps();
|
|
296
|
+
let y = r.getLastKnownLocation();
|
|
297
|
+
y !== null && (d = {
|
|
275
298
|
coords: {
|
|
276
|
-
longitude:
|
|
277
|
-
latitude:
|
|
299
|
+
longitude: y.longitude,
|
|
300
|
+
latitude: y.latitude,
|
|
278
301
|
accuracy: 0,
|
|
279
302
|
altitude: null,
|
|
280
303
|
altitudeAccuracy: null,
|
|
281
304
|
heading: null,
|
|
282
305
|
speed: null,
|
|
283
|
-
toJSON: () =>
|
|
306
|
+
toJSON: () => y
|
|
284
307
|
},
|
|
285
308
|
timestamp: Date.now(),
|
|
286
|
-
toJSON: () =>
|
|
309
|
+
toJSON: () => y
|
|
287
310
|
});
|
|
288
|
-
let _ = () => {
|
|
289
|
-
if (!s || !o) return;
|
|
290
|
-
let e = window.innerWidth, t = window.innerHeight;
|
|
291
|
-
s.setSize(e, t, !1), o.aspect = e / t, o.updateProjectionMatrix?.();
|
|
292
|
-
};
|
|
293
|
-
_(), window.addEventListener("resize", _), i = _;
|
|
294
311
|
},
|
|
295
312
|
update() {
|
|
296
|
-
n?.deviceOrientationControls?.update?.()
|
|
313
|
+
if (n?.deviceOrientationControls?.update?.(), c !== null && (c.width !== l.width || c.height !== l.height)) {
|
|
314
|
+
l = {
|
|
315
|
+
width: c.width,
|
|
316
|
+
height: c.height
|
|
317
|
+
};
|
|
318
|
+
let e = c.width / c.height, t = a;
|
|
319
|
+
t.aspect = e, t.updateProjectionMatrix(), n?.syncFovWithWebcam(e);
|
|
320
|
+
}
|
|
297
321
|
},
|
|
298
322
|
dispose() {
|
|
299
|
-
r &&
|
|
300
|
-
for (let e of
|
|
323
|
+
r && i && r.off("gpsupdate", i), r?.stopGps?.(), n?.webcam?.dispose?.(), o?.setClearAlpha?.(1), n?.deviceOrientationControls?.dispose?.();
|
|
324
|
+
for (let e of u.values()) if (e.isAttached) try {
|
|
301
325
|
e.anchor.removeFromParent();
|
|
302
326
|
} catch (e) {
|
|
303
327
|
console.error("⚠️ Error removing anchor:", e);
|
|
304
328
|
}
|
|
305
|
-
|
|
329
|
+
u.clear(), n = null, r = null, a = null, o = null, s = null, i = null, d = null;
|
|
330
|
+
},
|
|
331
|
+
setSize(e) {
|
|
332
|
+
c = {
|
|
333
|
+
width: e.width,
|
|
334
|
+
height: e.height,
|
|
335
|
+
top: 0,
|
|
336
|
+
left: 0
|
|
337
|
+
};
|
|
306
338
|
},
|
|
307
339
|
getInternal: () => ({
|
|
308
340
|
locar: r,
|
|
309
341
|
webcam: n?.webcam ?? null,
|
|
310
342
|
deviceOrientation: n?.deviceOrientationControls ?? null,
|
|
311
|
-
scene:
|
|
312
|
-
camera:
|
|
313
|
-
lastPosition:
|
|
314
|
-
registerAnchor:
|
|
315
|
-
unregisterAnchor:
|
|
316
|
-
getAnchor:
|
|
343
|
+
scene: s,
|
|
344
|
+
camera: a,
|
|
345
|
+
lastPosition: d,
|
|
346
|
+
registerAnchor: p,
|
|
347
|
+
unregisterAnchor: m,
|
|
348
|
+
getAnchor: h
|
|
317
349
|
})
|
|
318
350
|
};
|
|
319
351
|
};
|
|
320
352
|
//#endregion
|
|
321
|
-
export {
|
|
353
|
+
export { j as a, M as i, F as n, k as o, N as r, I as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./useXRStore-Cf_XL0aI.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`),a=require(`three/addons/lines/Line2.js`),o=require(`three/addons/lines/LineGeometry.js`),s=require(`three/addons/lines/LineMaterial.js`),c=require(`locar`);var l={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>void 0},u=()=>{let t=e.r(e=>e.backends).get(e.i.GEOLOCATION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:l},d=(e,t)=>{let n=e.length-1,r=[],a=0,o=0;for(let i=0;i<n;i++){let n=e[i+1].x-e[i].x,s=e[i+1].y-e[i].y,c=e[i+1].z-e[i].z,l=Math.sqrt(n*n+s*s+c*c),u=t/2,d=-(c*u)/l,f=n*u/l,p=i>0?(d+a)/2:d,m=i>0?(f+o)/2:f;r.push(e[i].x-p,e[i].y,e[i].z-m,e[i].x+p,e[i].y,e[i].z+m),a=d,o=f}r.push(e[n].x-a,e[n].y,e[n].z-o,e[n].x+a,e[n].y,e[n].z+o);let s=[];for(let e=0;e<n;e++)s.push(e*2,e*2+1,e*2+2),s.push(e*2+1,e*2+3,e*2+2);let c=new i.BufferGeometry;return c.setIndex(s),c.setAttribute(`position`,new i.BufferAttribute(new Float32Array(r),3)),c.computeBoundingBox(),c},f=({coordinates:e,color:c=`#ff0000`,isDashed:l=!1,dashSize:f=3,gapSize:p=1,lineWidth:m=1,onClick:h,onPointerOut:g,onPointerOver:_,opacity:v=1})=>{let y=u(),b=(0,t.useRef)(y);b.current=y;let[x]=(0,t.useState)(()=>new i.Group),S=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[C,w]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!y.isSuccess||e.length<2)return;let[t,n,r=0]=e[0];return b.current.registerAnchor(S,{anchor:x,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,u=0]=e[0],[h,g]=t.lonLatToWorldCoords(n,r),_=e.map(([e,n,r=0])=>{let[a,o]=t.lonLatToWorldCoords(e,n);return new i.Vector3(a-h,r-u,o-g)});if(l){let e=new a.Line2(new o.LineGeometry().setFromPoints(_),new s.LineMaterial({color:c,dashSize:f,gapSize:p,dashed:!0,worldUnits:!0,linewidth:m,transparent:v<1,opacity:v}));e.computeLineDistances(),w(e)}else w(new i.Mesh(d(_,m),new i.MeshBasicMaterial({color:c,transparent:v<1,opacity:v,side:i.DoubleSide})))}}),()=>{b.current.unregisterAnchor(S),w(e=>(e&&(e.geometry.dispose(),e.material.dispose()),null))}},[S,x,e,c,l,f,p,m,v,y.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{onClick:h,onPointerOut:g,onPointerOver:_,children:C&&(0,r.jsx)(`primitive`,{object:C})}),x)},p=({latitude:e,longitude:a,altitude:o=0,isBillboard:s=!0,onAttach:c,onGpsUpdate:l,children:d})=>{let f=u(),p=(0,t.useRef)(f);p.current=f;let{camera:m}=(0,n.useThree)(),[h]=(0,t.useState)(()=>new i.Group),g=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),_=(0,t.useCallback)(()=>{c?.()},[c]),v=(0,t.useCallback)((e,t)=>{l?.(e,t)},[l]);return(0,t.useEffect)(()=>{if(f.isSuccess)return p.current.registerAnchor(g,{anchor:h,isAttached:!1,latitude:e,longitude:a,altitude:o,onAttach:_,onGpsUpdate:v}),()=>{p.current.unregisterAnchor(g)}},[h,g,e,a,o,_,v,f.isSuccess]),(0,n.useFrame)(()=>{!s||!m||!f.isSuccess||f.getAnchor(g)?.isAttached&&h.lookAt(m.position)}),(0,n.createPortal)((0,r.jsx)(`group`,{children:d}),h)},m=({options:r={},children:i})=>{let{scene:a,camera:o,gl:s,size:c}=(0,n.useThree)(),{registerBackend:l,unregisterBackend:u}=e.r(),d=(0,t.useRef)(null),f=(0,t.useRef)(r);return f.current=r,(0,t.useEffect)(()=>{if(d.current)return;let e=!1;return(async()=>{try{let t=_(f.current);if(e)return;await l(t,{scene:a,camera:o,renderer:s,size:c}),d.current=t}catch(e){console.error(`[GeolocationSession] Failed to initialize:`,e)}})(),()=>{e=!0,d.current&&=(u(d.current),null)}},[a,o,s,l,u]),(0,t.useEffect)(()=>{d.current?.setSize(c)},[c]),i},h={front:i.FrontSide,back:i.BackSide,double:i.DoubleSide},g=({coordinates:e,holes:a,color:o=`#ff0000`,opacity:s=1,isWireframe:c=!1,onClick:l,onPointerOut:d,onPointerOver:f,side:p=`double`})=>{let m=u(),g=(0,t.useRef)(m);g.current=m;let[_]=(0,t.useState)(()=>new i.Group),v=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[y,b]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!m.isSuccess||e.length<3)return;let[t,n,r=0]=e[0];return g.current.registerAnchor(v,{anchor:_,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,o=0]=e[0],[s,c]=t.lonLatToWorldCoords(n,r),l=[];for(let[n,r,i=0]of e){let[e,a]=t.lonLatToWorldCoords(n,r);l.push({x:e-s,z:a-c,elev:i-o})}let u=new i.Shape;u.moveTo(l[0].x,l[0].z);for(let e=1;e<l.length;e++)u.lineTo(l[e].x,l[e].z);if(u.closePath(),a&&a.length>0)for(let e of a){if(e.length<3)continue;let n=new i.Path,[r,a]=e[0],[o,l]=t.lonLatToWorldCoords(r,a);n.moveTo(o-s,l-c);for(let r=1;r<e.length;r++){let[i,a]=e[r],[o,l]=t.lonLatToWorldCoords(i,a);n.lineTo(o-s,l-c)}n.closePath(),u.holes.push(n)}let d=new i.ShapeGeometry(u),f=l.reduce((e,t)=>e+t.elev,0)/l.length;d.rotateX(-Math.PI/2),b({geometry:d,avgElevation:f})}}),()=>{g.current.unregisterAnchor(v),b(e=>(e&&e.geometry.dispose(),null))}},[v,_,e,a,m.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:y&&(0,r.jsx)(`group`,{position:[0,y.avgElevation,0],children:(0,r.jsx)(`mesh`,{geometry:y.geometry,onClick:l,onPointerOut:d,onPointerOver:f,children:(0,r.jsx)(`meshBasicMaterial`,{color:o,opacity:s,transparent:s<1,wireframe:c,side:h[p]})})})}),_)},_=t=>{let n=null,r=null,i=null,a=null,o=null,s=null,l=null,u={width:0,height:0},d=new Map,f=null,p=e=>{if(!(!r||e.isAttached))try{r.add(e.anchor,e.longitude,e.latitude,e.altitude),e.isAttached=!0,e.onAttach?.(r)}catch(e){console.error(`❌ Failed to attach anchor:`,e)}},m=(e,t)=>{d.set(e,t),f!==null&&!t.isAttached&&(p(t),t.onGpsUpdate?.(f,0))},h=e=>{let t=d.get(e);if(t?.isAttached)try{t.anchor.removeFromParent()}catch(t){console.error(`⚠️ Error removing anchor ${e}:`,t)}d.delete(e)},g=e=>d.get(e);return{type:e.i.GEOLOCATION,async init(e){let{camera:u,renderer:m,scene:h,size:g}=e;if(!h)throw Error(`[geolocationBackend] A THREE.Scene is required for location-based AR`);a=u,o=m,s=h,l=g;let _=a,v=t?.hFov??80;_.fov=c.LocAR.htov(v,g.width/g.height),_.updateProjectionMatrix(),n=new c.App({threeObjects:{camera:u,renderer:m,scene:h},videoConstraints:t?.webcamConstraints??{video:{facingMode:`environment`}},deviceOrientationOptions:{enabled:!0},dimensionsProvider:()=>l?{width:l.width,height:l.height}:{width:0,height:0}}),m.setClearAlpha?.(0),i=e=>{f=e.position;for(let t of d.values())t.isAttached||p(t),t.onGpsUpdate?.(e.position,e.distMoved);t?.onGpsUpdate?.(e.position,e.distMoved)},r=await n.start();let y=n.deviceOrientationControls;if(y&&y.orientationChangeEventName!==`deviceorientation`)try{y.disconnect(),y.orientationChangeEventName=`deviceorientation`,y.connect()}catch(e){console.error(`[geolocationBackend] failed to rebind device orientation event:`,e)}r.on(`gpsupdate`,i),n.webcam?.on?.(`webcamerror`,e=>{console.error(`[geolocationBackend] webcam error:`,e)}),n.deviceOrientationControls?.on?.(`deviceorientationerror`,e=>{console.error(`[geolocationBackend] Device orientation error:`,e)}),r.on(`gpserror`,e=>{console.error(`[geolocationBackend] gps error:`,e)}),typeof t?.fakeLat==`number`&&typeof t?.fakeLon==`number`?r.fakeGps(t.fakeLon,t.fakeLat):r.startGps();let b=r.getLastKnownLocation();b!==null&&(f={coords:{longitude:b.longitude,latitude:b.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>b},timestamp:Date.now(),toJSON:()=>b})},update(){if(n?.deviceOrientationControls?.update?.(),l!==null&&(l.width!==u.width||l.height!==u.height)){u={width:l.width,height:l.height};let e=l.width/l.height,t=a;t.aspect=e,t.updateProjectionMatrix(),n?.syncFovWithWebcam(e)}},dispose(){r&&i&&r.off(`gpsupdate`,i),r?.stopGps?.(),n?.webcam?.dispose?.(),o?.setClearAlpha?.(1),n?.deviceOrientationControls?.dispose?.();for(let e of d.values())if(e.isAttached)try{e.anchor.removeFromParent()}catch(e){console.error(`⚠️ Error removing anchor:`,e)}d.clear(),n=null,r=null,a=null,o=null,s=null,i=null,f=null},setSize(e){l={width:e.width,height:e.height,top:0,left:0}},getInternal:()=>({locar:r,webcam:n?.webcam??null,deviceOrientation:n?.deviceOrientationControls??null,scene:s,camera:a,lastPosition:f,registerAnchor:m,unregisterAnchor:h,getAnchor:g})}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return _}});
|
package/build/geolocation.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`})
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./geolocation-D0RxA8Tv.cjs`);exports.GeoLine=e.a,exports.GeoPolygon=e.n,exports.GeolocationAnchor=e.i,exports.GeolocationSession=e.r,exports.createGeolocationBackend=e.t,exports.useGeolocationBackend=e.o;
|
package/build/geolocation.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { a as e, i as t, n, o as r, r as i, t as a } from "./geolocation-DbT8iR2H.js";
|
|
1
|
+
import { a as e, i as t, n, o as r, r as i, t as a } from "./geolocation-C_n3zwq4.js";
|
|
3
2
|
export { e as GeoLine, n as GeoPolygon, t as GeolocationAnchor, i as GeolocationSession, a as createGeolocationBackend, r as useGeolocationBackend };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as e, t } from "./useXRStore-
|
|
1
|
+
import { i as e, t } from "./useXRStore-BTnI1ZM2.js";
|
|
2
2
|
import { useEffect as n, useMemo as r } from "react";
|
|
3
3
|
import { jsx as i } from "react/jsx-runtime";
|
|
4
4
|
import { XR as a, createXRStore as o } from "@react-three/xr";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./useXRStore-
|
|
1
|
+
const e=require(`./useXRStore-Cf_XL0aI.cjs`);let t=require(`react`),n=require(`react/jsx-runtime`),r=require(`@react-three/xr`);var i=()=>({type:e.i.IMMERSIVE,init:()=>{},getInternal:()=>null}),a=({children:a})=>{let o=(0,t.useMemo)(()=>(0,r.createXRStore)(),[]);return(0,t.useEffect)(()=>{let t=e.t(),n=i();return t.backends.set(e.i.IMMERSIVE,n),t.setImmersiveStore(o),()=>{t.backends.delete(e.i.IMMERSIVE),t.setImmersiveStore(null)}},[o]),(0,n.jsx)(r.XR,{store:o,children:a})};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
|
package/build/immersive.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`})
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./immersive-DMYGUy_v.cjs`);exports.ImmersiveSession=e.t;
|
package/build/immersive.js
CHANGED
package/build/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useXRStore-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useXRStore-Cf_XL0aI.cjs`),t=require(`./engine-EvzyijbY.cjs`),n=require(`./fiducial-Tris7XAY.cjs`),r=require(`./geolocation-D0RxA8Tv.cjs`),i=require(`./immersive-DMYGUy_v.cjs`),a=require(`./magic-B9pQnRYJ.cjs`),o=require(`./vision-BLWMU9Ys.cjs`);require(`@react-three/fiber`),exports.BACKEND_TYPES=e.i,exports.COCO_LABELS=o.c,exports.CameraBackground=o.C,exports.DEFAULT_GESTURES=o._,exports.FiducialAnchor=n.r,exports.FiducialSession=n.n,exports.GeoLine=r.a,exports.GeoPolygon=r.n,exports.GeolocationAnchor=r.i,exports.GeolocationSession=r.r,exports.HandTracker=o.f,exports.ImmersiveSession=i.t,exports.MagicSession=a.n,exports.VisionAnchor=o.o,exports.VisionDebug=o.a,exports.VisionOverlay=o.t,exports.VisionSession=o.r,exports.VisionStatus=o.n,exports.WorldAnchor=a.t,exports.XR=t.t,exports.createFiducialBackend=n.t,exports.createGeolocationBackend=r.t,exports.createMagicBackend=a.r,exports.createVisionBackend=o.i,exports.detectGesture=o.g,exports.fist=o.v,exports.getXRStore=e.t,exports.landmarkToWorld=o.m,exports.landmarksCentroid=o.h,exports.ok=o.y,exports.openHand=o.b,exports.peace=o.x,exports.rfDetr=o.l,exports.subscribeToXRStore=e.n,exports.thumbsUp=o.S,exports.useFiducialBackend=n.i,exports.useGeolocationBackend=r.o,exports.useVisionBackend=o.p,exports.useVisionFrame=o.s,exports.useXRStore=e.r,exports.yolo=o.u,exports.yoloSeg=o.d;
|
package/build/index.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import { i as e, n as t, r as n, t as r } from "./useXRStore-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as m } from "./
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let { updateBackends: t } = n();
|
|
11
|
-
return V((e, n) => {
|
|
12
|
-
t(n);
|
|
13
|
-
}), e;
|
|
14
|
-
};
|
|
15
|
-
//#endregion
|
|
16
|
-
export { e as BACKEND_TYPES, C as COCO_LABELS, v as CameraBackground, b as DEFAULT_GESTURES, o as FiducialAnchor, a as FiducialSession, c as GeoLine, u as GeoPolygon, l as GeolocationAnchor, f as GeolocationSession, T as HandTracker, m as ImmersiveSession, h as MagicSession, M as VisionAnchor, x as VisionDebug, I as VisionOverlay, P as VisionSession, j as VisionStatus, _ as WorldAnchor, H as XR, s as createFiducialBackend, p as createGeolocationBackend, g as createMagicBackend, O as createVisionBackend, E as detectGesture, R as fist, r as getXRStore, A as landmarkToWorld, D as landmarksCentroid, B as ok, S as openHand, z as peace, k as rfDetr, t as subscribeToXRStore, y as thumbsUp, i as useFiducialBackend, d as useGeolocationBackend, N as useVisionBackend, F as useVisionFrame, n as useXRStore, L as yolo, w as yoloSeg };
|
|
1
|
+
import { i as e, n as t, r as n, t as r } from "./useXRStore-BTnI1ZM2.js";
|
|
2
|
+
import { t as i } from "./engine-NEJZ-OgD.js";
|
|
3
|
+
import { i as a, n as o, r as s, t as c } from "./fiducial-7pF-ErgE.js";
|
|
4
|
+
import { a as l, i as u, n as d, o as f, r as p, t as m } from "./geolocation-C_n3zwq4.js";
|
|
5
|
+
import { t as h } from "./immersive-CoSRZ58s.js";
|
|
6
|
+
import { n as g, r as _, t as v } from "./magic-CjnX9lWp.js";
|
|
7
|
+
import { C as y, S as b, _ as x, a as S, b as C, c as w, d as T, f as E, g as D, h as O, i as k, l as A, m as j, n as M, o as N, p as P, r as F, s as I, t as L, u as R, v as z, x as B, y as V } from "./vision-Vp2iuVNJ.js";
|
|
8
|
+
import "@react-three/fiber";
|
|
9
|
+
export { e as BACKEND_TYPES, w as COCO_LABELS, y as CameraBackground, x as DEFAULT_GESTURES, s as FiducialAnchor, o as FiducialSession, l as GeoLine, d as GeoPolygon, u as GeolocationAnchor, p as GeolocationSession, E as HandTracker, h as ImmersiveSession, g as MagicSession, N as VisionAnchor, S as VisionDebug, L as VisionOverlay, F as VisionSession, M as VisionStatus, v as WorldAnchor, i as XR, c as createFiducialBackend, m as createGeolocationBackend, _ as createMagicBackend, k as createVisionBackend, D as detectGesture, z as fist, r as getXRStore, j as landmarkToWorld, O as landmarksCentroid, V as ok, C as openHand, B as peace, A as rfDetr, t as subscribeToXRStore, b as thumbsUp, a as useFiducialBackend, f as useGeolocationBackend, P as useVisionBackend, I as useVisionFrame, n as useXRStore, R as yolo, T as yoloSeg };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Size } from '@react-three/fiber';
|
|
1
2
|
import { Camera, Scene, WebGLRenderer } from 'three';
|
|
2
3
|
/**
|
|
3
4
|
* Initialization arguments for backends.
|
|
@@ -10,5 +11,7 @@ export interface BackendInitArgs {
|
|
|
10
11
|
camera: Camera;
|
|
11
12
|
/** The WebGL renderer instance. */
|
|
12
13
|
renderer: WebGLRenderer;
|
|
14
|
+
/** The canvas size. */
|
|
15
|
+
size: Size;
|
|
13
16
|
}
|
|
14
17
|
//# sourceMappingURL=BackendInitArgs.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendInitArgs.interface.d.ts","sourceRoot":"","sources":["../../../../../src/lib/types/engine/backend/BackendInitArgs.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,KAAK,EAAE,KAAK,CAAC;IACb,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,QAAQ,EAAE,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"BackendInitArgs.interface.d.ts","sourceRoot":"","sources":["../../../../../src/lib/types/engine/backend/BackendInitArgs.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,KAAK,EAAE,KAAK,CAAC;IACb,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,QAAQ,EAAE,aAAa,CAAC;IACxB,uBAAuB;IACvB,IAAI,EAAE,IAAI,CAAC;CACZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"magicBackend.d.ts","sourceRoot":"","sources":["../../src/magic/magicBackend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,oBAAoB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;IACxC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,4BAA4B,EAAE,OAAO,CAAC;IACtC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,kBAAkB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,kBAAkB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,qBAAqB,EAAE,OAAO,CAAC;IAC/B,sFAAsF;IACtF,4BAA4B,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,yEAAyE;IACzE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;CAC5C;AAMD;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,GACtB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,aAAa,
|
|
1
|
+
{"version":3,"file":"magicBackend.d.ts","sourceRoot":"","sources":["../../src/magic/magicBackend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,oBAAoB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;IACxC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,4BAA4B,EAAE,OAAO,CAAC;IACtC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,kBAAkB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,kBAAkB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,qBAAqB,EAAE,OAAO,CAAC;IAC/B,sFAAsF;IACtF,4BAA4B,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,yEAAyE;IACzE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;CAC5C;AAMD;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,GACtB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,aAAa,CA6YvB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./useXRStore-Cf_XL0aI.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`);i=e.a(i);var a=.15,o=.5,s=t=>{let n=null,r=null,s=null,c=t?.enableOrientation??!0,l=!1,u=t?.enableWorldAnchoring??!0,d=null,f=null,p=t?.smoothingFactor??a,m=t?.deadZone??o,h={alpha:0,beta:0,gamma:0},g={alpha:0,beta:0,gamma:0},_={alpha:0,beta:0,gamma:0},v=!1,y=null,b=null,x=new i.Quaternion,S=new i.Quaternion,C=new i.Euler,w=new i.Quaternion,T=new i.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),E=new i.Vector3(0,0,1),D=new i.Quaternion,O=new i.Quaternion,k=(e,t,n,r)=>{let i=(screen.orientation?.angle??0)*Math.PI/180;C.set(n,t,-r,`YXZ`),e.setFromEuler(C),e.multiply(T),e.multiply(w.setFromAxisAngle(E,-i))},A=(e,t)=>{let n=(t-e)%360+360;return n=(n+180)%360-180,n},j=(e,t,n=!1)=>Math.abs(n?A(e,t):t-e)<m?e:t,M=(e,t,n)=>e+(t-e)*n,N=(e,t,n)=>((e+A(e,t)*n)%360+360)%360,P=async()=>{let e=DeviceOrientationEvent;if(typeof e.requestPermission==`function`)try{return await e.requestPermission()===`granted`?(l=!0,!0):(console.warn(`[MagicBackend] Device orientation permission denied`),!1)}catch(e){return console.error(`[MagicBackend] Error requesting orientation permission:`,e),!1}return l=!0,!0},F=()=>{d=e=>{if(h.alpha=e.alpha??0,h.beta=e.beta??0,h.gamma=e.gamma??0,!v&&(h.alpha!==0||h.beta!==0||h.gamma!==0)){_.alpha=h.alpha,_.beta=h.beta,_.gamma=h.gamma;let{degToRad:e}=i.MathUtils;k(D,e(h.alpha),e(h.beta),e(h.gamma)),O.copy(D).invert(),v=!0}},window.addEventListener(`deviceorientation`,d,!0)},I=async(e,a)=>{let o=t?.webcamConstraints??{video:{facingMode:`environment`}};try{s=await navigator.mediaDevices.getUserMedia(o)}catch(e){throw console.error(`[MagicBackend] Failed to access camera:`,e),e}n=document.createElement(`video`),n.srcObject=s,n.setAttribute(`playsinline`,``),n.setAttribute(`autoplay`,``),n.muted=!0,n.style.position=`fixed`,n.style.top=`0`,n.style.left=`0`,n.style.width=`100vw`,n.style.height=`100vh`,n.style.objectFit=`cover`,n.style.zIndex=`-1`,n.style.pointerEvents=`none`,document.body.appendChild(n),await n.play(),r=new i.VideoTexture(n),r.minFilter=i.LinearFilter,r.magFilter=i.LinearFilter,r.colorSpace=i.SRGBColorSpace,e.background=r,a.setClearColor(0,0)};return{type:e.i.MAGIC,async init({scene:e,camera:t,renderer:n}){if(y=t,b=e,await I(e,n),c)if(await P())F();else{let e=async()=>{document.removeEventListener(`click`,e),document.removeEventListener(`touchend`,e),f=null,await P()&&F()};f=e,document.addEventListener(`click`,e),document.addEventListener(`touchend`,e)}},update(){if(!c||!l)return;let e=j(g.alpha,h.alpha,!0),t=j(g.beta,h.beta),n=j(g.gamma,h.gamma);if(g.alpha=N(g.alpha,e,p),g.beta=M(g.beta,t,p),g.gamma=M(g.gamma,n,p),u&&y&&v){let{degToRad:e}=i.MathUtils;k(x,e(h.alpha),e(h.beta),e(h.gamma)),S.copy(O).multiply(x),y.quaternion.slerp(S,p)}r&&(r.needsUpdate=!0)},dispose(){if(d&&=(window.removeEventListener(`deviceorientation`,d),null),f&&=(document.removeEventListener(`click`,f),document.removeEventListener(`touchend`,f),null),s){for(let e of s.getTracks())e.stop();s=null}n&&=(n.pause(),n.srcObject=null,n.parentNode?.removeChild(n),null),r&&=(r.dispose(),null),b&&(b.background=null),y=null,b=null,c=!1,l=!1,u=!1,v=!1,g.alpha=0,g.beta=0,g.gamma=0,h.alpha=0,h.beta=0,h.gamma=0,_.alpha=0,_.beta=0,_.gamma=0,D.identity(),O.identity()},getInternal:()=>({videoElement:n,videoTexture:r,stream:s,orientationEnabled:c,orientationPermissionGranted:l,worldAnchoringEnabled:u,currentOrientation:{...g},initialOrientation:{..._},hasInitialOrientation:v,requestOrientationPermission:async()=>{let e=await P();return e&&!d&&F(),e}})}},c=({options:r={},children:i})=>{let{scene:a,camera:o,gl:c,size:l}=(0,n.useThree)(),{registerBackend:u,unregisterBackend:d}=e.r(),f=(0,t.useRef)(null),p=(0,t.useRef)(r);return p.current=r,(0,t.useEffect)(()=>{if(f.current)return;let e=!1;return(async()=>{try{let t=s(p.current);if(e)return;await u(t,{scene:a,camera:o,renderer:c,size:l}),f.current=t}catch(e){console.error(`[MagicSession] Failed to initialize:`,e)}})(),()=>{e=!0,f.current&&=(d(f.current),null)}},[a,o,c,u,d]),i},l=({position:i=[0,0,-2],rotation:a=[0,0,0],scale:o=1,isBillboard:s=!1,children:c})=>{let l=(0,t.useRef)(null),u=e.r(e=>e.backends);return(0,n.useFrame)(({camera:t})=>{let n=l.current;if(!n)return;let r=u.get(e.i.MAGIC);r&&r.getInternal().hasInitialOrientation&&(n.position.set(i[0],i[1],i[2]),n.rotation.set(a[0],a[1],a[2]),typeof o==`number`?n.scale.setScalar(o):n.scale.set(o[0],o[1],o[2]),s&&n.lookAt(t.position))}),(0,r.jsx)(`group`,{ref:l,children:c})};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
|