@omnidotdev/rdk 0.10.0 → 0.10.1
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.d.ts +1 -1
- package/build/geolocation/geolocationBackend.d.ts +1 -1
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/{geolocation-DxPzqQPN.js → geolocation-BIUFKLO_.js} +46 -36
- package/build/{geolocation-ClkbtHic.cjs → geolocation-tCLtH8CU.cjs} +1 -1
- package/build/geolocation.cjs +1 -1
- package/build/geolocation.d.ts +1 -1
- package/build/geolocation.js +1 -1
- package/build/immersive.d.ts +1 -1
- package/build/index.cjs +1 -1
- package/build/index.js +1 -1
- package/build/magic.d.ts +1 -1
- package/package.json +8 -8
package/build/fiducial.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './fiducial/index'
|
|
1
|
+
export * from './fiducial/index.js'
|
|
2
2
|
export {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/geolocationBackend.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"geolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/geolocationBackend.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAiB,MAAM,OAAO,CAAC;AAEjE;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1E;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iBAAiB,EAAE,yBAAyB,GAAG,IAAI,CAAC;IACpD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+BAA+B;IAC/B,YAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACzC,2CAA2C;IAC3C,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACzD,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,iCAAiC;IACjC,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,iEAAiE;IACjE,SAAS,EAAE,OAAO,CAAC;IACnB,2DAA2D;IAC3D,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;IAC3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9E;AAED;;GAEG;AACH,QAAA,MAAM,wBAAwB,GAC5B,UAAU,yBAAyB,KAClC,OAAO,CAAC,mBAAmB,CAgQ7B,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
|
@@ -6,7 +6,7 @@ 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 { DeviceOrientationControls as E,
|
|
9
|
+
import { DeviceOrientationControls as E, LocAR as D, Webcam as O } from "locar";
|
|
10
10
|
//#region src/geolocation/useGeolocationBackend.ts
|
|
11
11
|
var k = {
|
|
12
12
|
isPending: !0,
|
|
@@ -217,87 +217,97 @@ var k = {
|
|
|
217
217
|
})
|
|
218
218
|
}) }), m);
|
|
219
219
|
}, L = (t) => {
|
|
220
|
-
let n = null, r = null, i = null, a, o = null, s = null, c = null, l = null, u = /* @__PURE__ */ new Map(),
|
|
220
|
+
let n = null, r = null, i = null, a, o = null, s = null, c = null, l = null, u = null, d = /* @__PURE__ */ new Map(), f = null, p = (e) => {
|
|
221
221
|
if (!(!n || e.isAttached)) try {
|
|
222
222
|
n.add(e.anchor, e.longitude, e.latitude, e.altitude), e.isAttached = !0, e.onAttach?.(n);
|
|
223
223
|
} catch (e) {
|
|
224
224
|
console.error("❌ Failed to attach anchor:", e);
|
|
225
225
|
}
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
},
|
|
229
|
-
let t =
|
|
226
|
+
}, m = (e, t) => {
|
|
227
|
+
d.set(e, t), f !== null && !t.isAttached && (p(t), t.onGpsUpdate?.(f, 0));
|
|
228
|
+
}, h = (e) => {
|
|
229
|
+
let t = d.get(e);
|
|
230
230
|
if (t?.isAttached) try {
|
|
231
231
|
t.anchor.removeFromParent();
|
|
232
232
|
} catch (t) {
|
|
233
233
|
console.error(`⚠️ Error removing anchor ${e}:`, t);
|
|
234
234
|
}
|
|
235
|
-
|
|
236
|
-
},
|
|
235
|
+
d.delete(e);
|
|
236
|
+
}, g = (e) => d.get(e);
|
|
237
237
|
return {
|
|
238
238
|
type: e.GEOLOCATION,
|
|
239
239
|
async init(e) {
|
|
240
|
-
let { camera:
|
|
241
|
-
if (!
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
let { camera: m, renderer: h, scene: g } = e;
|
|
241
|
+
if (!g) throw Error("[geolocationBackend] A THREE.Scene is required for location-based AR");
|
|
242
|
+
c = m, l = h, u = g, n = new D(g, m), h.setClearAlpha?.(0);
|
|
243
|
+
let _ = new Set(document.querySelectorAll("video"));
|
|
244
|
+
r = new O(t?.webcamConstraints ?? { video: { facingMode: "environment" } });
|
|
245
|
+
for (let e of document.querySelectorAll("video")) if (!_.has(e)) {
|
|
246
|
+
o = e;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
s = (e) => {
|
|
250
|
+
f = e.position;
|
|
251
|
+
for (let t of d.values()) t.isAttached || p(t), t.onGpsUpdate?.(e.position, e.distMoved);
|
|
245
252
|
t?.onGpsUpdate?.(e.position, e.distMoved);
|
|
246
|
-
}, n.on("gpsupdate",
|
|
247
|
-
h.background = e.texture;
|
|
248
|
-
}), r.on("webcamerror", (e) => {
|
|
253
|
+
}, n.on("gpsupdate", s), r.on("webcamerror", (e) => {
|
|
249
254
|
console.error("[geolocationBackend] webcam error:", e);
|
|
250
|
-
}), i = new E(
|
|
255
|
+
}), i = new E(m), i.on("deviceorientationgranted", (e) => {
|
|
251
256
|
e.target?.connect?.();
|
|
252
257
|
}), i.on("deviceorientationerror", (e) => {
|
|
253
258
|
console.error("[geolocationBackend] Device orientation error:", e);
|
|
254
259
|
}), i.init?.(), n.on("gpserror", (e) => {
|
|
255
260
|
console.error("[geolocationBackend] gps error:", e);
|
|
256
261
|
}), n.startGps(), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" && n.fakeGps(t.fakeLon, t.fakeLat);
|
|
257
|
-
let
|
|
258
|
-
|
|
262
|
+
let v = n.getLastKnownLocation();
|
|
263
|
+
v !== null && (f = {
|
|
259
264
|
coords: {
|
|
260
|
-
longitude:
|
|
261
|
-
latitude:
|
|
265
|
+
longitude: v.longitude,
|
|
266
|
+
latitude: v.latitude,
|
|
262
267
|
accuracy: 0,
|
|
263
268
|
altitude: null,
|
|
264
269
|
altitudeAccuracy: null,
|
|
265
270
|
heading: null,
|
|
266
271
|
speed: null,
|
|
267
|
-
toJSON: () =>
|
|
272
|
+
toJSON: () => v
|
|
268
273
|
},
|
|
269
274
|
timestamp: Date.now(),
|
|
270
|
-
toJSON: () =>
|
|
275
|
+
toJSON: () => v
|
|
271
276
|
});
|
|
272
|
-
let
|
|
273
|
-
if (!
|
|
277
|
+
let y = () => {
|
|
278
|
+
if (!l || !c) return;
|
|
274
279
|
let e = window.innerWidth, t = window.innerHeight;
|
|
275
|
-
|
|
280
|
+
l.setSize(e, t, !1), c.aspect = e / t, c.updateProjectionMatrix?.();
|
|
276
281
|
};
|
|
277
|
-
|
|
282
|
+
y(), window.addEventListener("resize", y), a = y;
|
|
278
283
|
},
|
|
279
284
|
update() {
|
|
280
285
|
i?.update?.();
|
|
281
286
|
},
|
|
282
287
|
dispose() {
|
|
283
|
-
n &&
|
|
284
|
-
|
|
288
|
+
if (n && s && n.off("gpsupdate", s), n?.stopGps?.(), o) {
|
|
289
|
+
let e = o.srcObject;
|
|
290
|
+
for (let t of e?.getTracks() ?? []) t.stop();
|
|
291
|
+
o.srcObject = null, o.remove(), o = null;
|
|
292
|
+
}
|
|
293
|
+
l?.setClearAlpha?.(1), i?.dispose?.(), a &&= (window.removeEventListener("resize", a), void 0);
|
|
294
|
+
for (let e of d.values()) if (e.isAttached) try {
|
|
285
295
|
e.anchor.removeFromParent();
|
|
286
296
|
} catch (e) {
|
|
287
297
|
console.error("⚠️ Error removing anchor:", e);
|
|
288
298
|
}
|
|
289
|
-
|
|
299
|
+
d.clear(), n = null, r = null, i = null, c = null, l = null, u = null, s = null, f = null;
|
|
290
300
|
},
|
|
291
301
|
getInternal: () => ({
|
|
292
302
|
locar: n,
|
|
293
303
|
webcam: r,
|
|
294
304
|
deviceOrientation: i,
|
|
295
|
-
scene:
|
|
296
|
-
camera:
|
|
297
|
-
lastPosition:
|
|
298
|
-
registerAnchor:
|
|
299
|
-
unregisterAnchor:
|
|
300
|
-
getAnchor:
|
|
305
|
+
scene: u,
|
|
306
|
+
camera: c,
|
|
307
|
+
lastPosition: f,
|
|
308
|
+
registerAnchor: m,
|
|
309
|
+
unregisterAnchor: h,
|
|
310
|
+
getAnchor: g
|
|
301
311
|
})
|
|
302
312
|
};
|
|
303
313
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./useXRStore-7Gy83DEg.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})=>{let h=u(),g=(0,t.useRef)(h);g.current=h;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(!h.isSuccess||e.length<2)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,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}));e.computeLineDistances(),b(e)}else b(new i.Mesh(d(_,m),new i.MeshBasicMaterial({color:c,side:i.DoubleSide})))}}),()=>{g.current.unregisterAnchor(v),b(e=>(e&&(e.geometry.dispose(),e.material.dispose()),null))}},[v,_,e,c,l,f,p,m,h.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:y&&(0,r.jsx)(`primitive`,{object:y})}),_)},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}=(0,n.useThree)(),{registerBackend:c,unregisterBackend:l}=e.r(),u=(0,t.useRef)(null),d=(0,t.useRef)(r);return d.current=r,(0,t.useEffect)(()=>{if(u.current)return;let e=!1;return(async()=>{try{let t=_(d.current);if(e)return;await c(t,{scene:a,camera:o,renderer:s}),u.current=t}catch(e){console.error(`[GeolocationSession] Failed to initialize:`,e)}})(),()=>{e=!0,u.current&&=(l(u.current),null)}},[a,o,s,c,l]),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,side:l=`double`})=>{let d=u(),f=(0,t.useRef)(d);f.current=d;let[p]=(0,t.useState)(()=>new i.Group),m=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[g,_]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!d.isSuccess||e.length<3)return;let[t,n,r=0]=e[0];return f.current.registerAnchor(m,{anchor:p,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),_({geometry:d,avgElevation:f})}}),()=>{f.current.unregisterAnchor(m),_(e=>(e&&e.geometry.dispose(),null))}},[m,p,e,a,d.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:g&&(0,r.jsx)(`group`,{position:[0,g.avgElevation,0],children:(0,r.jsx)(`mesh`,{geometry:g.geometry,children:(0,r.jsx)(`meshBasicMaterial`,{color:o,opacity:s,transparent:s<1,wireframe:c,side:h[l]})})})}),p)},_=t=>{let n=null,r=null,i=null,a,o=null,s=null,l=null,u=null,d=new Map,
|
|
1
|
+
const e=require(`./useXRStore-7Gy83DEg.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})=>{let h=u(),g=(0,t.useRef)(h);g.current=h;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(!h.isSuccess||e.length<2)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,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}));e.computeLineDistances(),b(e)}else b(new i.Mesh(d(_,m),new i.MeshBasicMaterial({color:c,side:i.DoubleSide})))}}),()=>{g.current.unregisterAnchor(v),b(e=>(e&&(e.geometry.dispose(),e.material.dispose()),null))}},[v,_,e,c,l,f,p,m,h.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:y&&(0,r.jsx)(`primitive`,{object:y})}),_)},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}=(0,n.useThree)(),{registerBackend:c,unregisterBackend:l}=e.r(),u=(0,t.useRef)(null),d=(0,t.useRef)(r);return d.current=r,(0,t.useEffect)(()=>{if(u.current)return;let e=!1;return(async()=>{try{let t=_(d.current);if(e)return;await c(t,{scene:a,camera:o,renderer:s}),u.current=t}catch(e){console.error(`[GeolocationSession] Failed to initialize:`,e)}})(),()=>{e=!0,u.current&&=(l(u.current),null)}},[a,o,s,c,l]),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,side:l=`double`})=>{let d=u(),f=(0,t.useRef)(d);f.current=d;let[p]=(0,t.useState)(()=>new i.Group),m=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[g,_]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!d.isSuccess||e.length<3)return;let[t,n,r=0]=e[0];return f.current.registerAnchor(m,{anchor:p,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),_({geometry:d,avgElevation:f})}}),()=>{f.current.unregisterAnchor(m),_(e=>(e&&e.geometry.dispose(),null))}},[m,p,e,a,d.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:g&&(0,r.jsx)(`group`,{position:[0,g.avgElevation,0],children:(0,r.jsx)(`mesh`,{geometry:g.geometry,children:(0,r.jsx)(`meshBasicMaterial`,{color:o,opacity:s,transparent:s<1,wireframe:c,side:h[l]})})})}),p)},_=t=>{let n=null,r=null,i=null,a,o=null,s=null,l=null,u=null,d=null,f=new Map,p=null,m=e=>{if(!(!n||e.isAttached))try{n.add(e.anchor,e.longitude,e.latitude,e.altitude),e.isAttached=!0,e.onAttach?.(n)}catch(e){console.error(`❌ Failed to attach anchor:`,e)}},h=(e,t)=>{f.set(e,t),p!==null&&!t.isAttached&&(m(t),t.onGpsUpdate?.(p,0))},g=e=>{let t=f.get(e);if(t?.isAttached)try{t.anchor.removeFromParent()}catch(t){console.error(`⚠️ Error removing anchor ${e}:`,t)}f.delete(e)},_=e=>f.get(e);return{type:e.i.GEOLOCATION,async init(e){let{camera:h,renderer:g,scene:_}=e;if(!_)throw Error(`[geolocationBackend] A THREE.Scene is required for location-based AR`);l=h,u=g,d=_,n=new c.LocAR(_,h),g.setClearAlpha?.(0);let v=new Set(document.querySelectorAll(`video`));r=new c.Webcam(t?.webcamConstraints??{video:{facingMode:`environment`}});for(let e of document.querySelectorAll(`video`))if(!v.has(e)){o=e;break}s=e=>{p=e.position;for(let t of f.values())t.isAttached||m(t),t.onGpsUpdate?.(e.position,e.distMoved);t?.onGpsUpdate?.(e.position,e.distMoved)},n.on(`gpsupdate`,s),r.on(`webcamerror`,e=>{console.error(`[geolocationBackend] webcam error:`,e)}),i=new c.DeviceOrientationControls(h),i.on(`deviceorientationgranted`,e=>{e.target?.connect?.()}),i.on(`deviceorientationerror`,e=>{console.error(`[geolocationBackend] Device orientation error:`,e)}),i.init?.(),n.on(`gpserror`,e=>{console.error(`[geolocationBackend] gps error:`,e)}),n.startGps(),typeof t?.fakeLat==`number`&&typeof t?.fakeLon==`number`&&n.fakeGps(t.fakeLon,t.fakeLat);let y=n.getLastKnownLocation();y!==null&&(p={coords:{longitude:y.longitude,latitude:y.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>y},timestamp:Date.now(),toJSON:()=>y});let b=()=>{if(!u||!l)return;let e=window.innerWidth,t=window.innerHeight;u.setSize(e,t,!1),l.aspect=e/t,l.updateProjectionMatrix?.()};b(),window.addEventListener(`resize`,b),a=b},update(){i?.update?.()},dispose(){if(n&&s&&n.off(`gpsupdate`,s),n?.stopGps?.(),o){let e=o.srcObject;for(let t of e?.getTracks()??[])t.stop();o.srcObject=null,o.remove(),o=null}u?.setClearAlpha?.(1),i?.dispose?.(),a&&=(window.removeEventListener(`resize`,a),void 0);for(let e of f.values())if(e.isAttached)try{e.anchor.removeFromParent()}catch(e){console.error(`⚠️ Error removing anchor:`,e)}f.clear(),n=null,r=null,i=null,l=null,u=null,d=null,s=null,p=null},getInternal:()=>({locar:n,webcam:r,deviceOrientation:i,scene:d,camera:l,lastPosition:p,registerAnchor:h,unregisterAnchor:g,getAnchor:_})}};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`}),require(`./useXRStore-7Gy83DEg.cjs`);const e=require(`./geolocation-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-7Gy83DEg.cjs`);const e=require(`./geolocation-tCLtH8CU.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.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './geolocation/index'
|
|
1
|
+
export * from './geolocation/index.js'
|
|
2
2
|
export {}
|
package/build/geolocation.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./useXRStore-B3-MaaCu.js";
|
|
2
|
-
import { a as e, i as t, n, o as r, r as i, t as a } from "./geolocation-
|
|
2
|
+
import { a as e, i as t, n, o as r, r as i, t as a } from "./geolocation-BIUFKLO_.js";
|
|
3
3
|
export { e as GeoLine, n as GeoPolygon, t as GeolocationAnchor, i as GeolocationSession, a as createGeolocationBackend, r as useGeolocationBackend };
|
package/build/immersive.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './immersive/index'
|
|
1
|
+
export * from './immersive/index.js'
|
|
2
2
|
export {}
|
package/build/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useXRStore-7Gy83DEg.cjs`),t=require(`./fiducial-dapuWTXg.cjs`),n=require(`./geolocation-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useXRStore-7Gy83DEg.cjs`),t=require(`./fiducial-dapuWTXg.cjs`),n=require(`./geolocation-tCLtH8CU.cjs`),r=require(`./immersive-8m33PLug.cjs`),i=require(`./magic-DznuBYgG.cjs`);let a=require(`@react-three/fiber`);var o=({children:t})=>{let{updateBackends:n}=e.r();return(0,a.useFrame)((e,t)=>{n(t)}),t};exports.BACKEND_TYPES=e.i,exports.FiducialAnchor=t.r,exports.FiducialSession=t.n,exports.GeoLine=n.a,exports.GeoPolygon=n.n,exports.GeolocationAnchor=n.i,exports.GeolocationSession=n.r,exports.ImmersiveSession=r.t,exports.MagicSession=i.n,exports.WorldAnchor=i.t,exports.XR=o,exports.createFiducialBackend=t.t,exports.createGeolocationBackend=n.t,exports.createMagicBackend=i.r,exports.getXRStore=e.t,exports.subscribeToXRStore=e.n,exports.useFiducialBackend=t.i,exports.useGeolocationBackend=n.o,exports.useXRStore=e.r;
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as e, n as t, r as n, t as r } from "./useXRStore-B3-MaaCu.js";
|
|
2
2
|
import { i, n as a, r as o, t as s } from "./fiducial-CqsG94R9.js";
|
|
3
|
-
import { a as c, i as l, n as u, o as d, r as f, t as p } from "./geolocation-
|
|
3
|
+
import { a as c, i as l, n as u, o as d, r as f, t as p } from "./geolocation-BIUFKLO_.js";
|
|
4
4
|
import { t as m } from "./immersive-Dp2-ZCRC.js";
|
|
5
5
|
import { n as h, r as g, t as _ } from "./magic-DAQdGGEO.js";
|
|
6
6
|
import { useFrame as v } from "@react-three/fiber";
|
package/build/magic.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './magic/index'
|
|
1
|
+
export * from './magic/index.js'
|
|
2
2
|
export {}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnidotdev/rdk",
|
|
3
3
|
"description": "Reality Development Kit, a unified React-first XR engine",
|
|
4
|
-
"version": "0.10.
|
|
5
|
-
"license": "
|
|
4
|
+
"version": "0.10.1",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"@ar-js-org/ar.js": "^3.4.7",
|
|
71
71
|
"@react-three/fiber": "^9.5.0",
|
|
72
72
|
"@react-three/xr": "^6.6.29",
|
|
73
|
-
"locar": "^0.
|
|
73
|
+
"locar": "^0.2.3",
|
|
74
74
|
"react": "^19.2.0",
|
|
75
75
|
"react-dom": "^19.2.0",
|
|
76
|
-
"three": "^0.
|
|
76
|
+
"three": "^0.185.0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependenciesMeta": {
|
|
79
79
|
"@ar-js-org/ar.js": {
|
|
@@ -95,15 +95,15 @@
|
|
|
95
95
|
"@types/node": "^25.0.3",
|
|
96
96
|
"@types/react": "^19.2.7",
|
|
97
97
|
"@types/react-dom": "^19.2.3",
|
|
98
|
-
"@types/three": "^0.
|
|
98
|
+
"@types/three": "^0.185.0",
|
|
99
99
|
"jsdom": "^29.0.0",
|
|
100
|
-
"locar": "^0.
|
|
100
|
+
"locar": "^0.2.3",
|
|
101
101
|
"react": "^19.2.3",
|
|
102
102
|
"react-dom": "^19.2.3",
|
|
103
|
-
"three": "^0.
|
|
103
|
+
"three": "^0.185.0",
|
|
104
104
|
"typescript": "^5.9.3",
|
|
105
105
|
"vite": "^8.0.0",
|
|
106
|
-
"vite-plugin-dts": "^
|
|
106
|
+
"vite-plugin-dts": "^5.0.0",
|
|
107
107
|
"vite-tsconfig-paths": "^6.0.3",
|
|
108
108
|
"vitest": "^4.0.16"
|
|
109
109
|
},
|