@omnidotdev/rdk 0.9.1 → 0.10.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.
@@ -1,3 +1,4 @@
1
+ import { ColorRepresentation } from 'three';
1
2
  export interface GeoLineProps {
2
3
  /** Array of coordinates forming the line. GeoJSON-style: [lon, lat, elevation?] */
3
4
  coordinates: Array<[number, number, number?]>;
@@ -5,9 +6,9 @@ export interface GeoLineProps {
5
6
  * Line color.
6
7
  * @default "#ff0000"
7
8
  */
8
- color?: string;
9
+ color?: ColorRepresentation;
9
10
  /**
10
- * Whether line is dashed.
11
+ * Whether line is dashed. When enabled, falls back to Line2 rendering.
11
12
  * @default false
12
13
  */
13
14
  isDashed?: boolean;
@@ -29,6 +30,7 @@ export interface GeoLineProps {
29
30
  }
30
31
  /**
31
32
  * Geolocation line component for rendering lines in AR space. Useful for e.g. roads, paths, and routes.
33
+ * Uses triangle-strip meshes for smooth rendering. Falls back to Line2 when dashing is enabled.
32
34
  * Accepts an array of lon/lat coordinates in GeoJSON-style format.
33
35
  */
34
36
  declare const GeoLine: ({ coordinates, color, isDashed, dashSize, gapSize, lineWidth, }: GeoLineProps) => import("react").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"GeoLine.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeoLine.tsx"],"names":[],"mappings":"AAWA,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,WAAW,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9C;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,QAAA,MAAM,OAAO,GAAI,iEAOd,YAAY,gCAmFd,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"GeoLine.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeoLine.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,WAAW,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9C;;;OAGG;IACH,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA+DD;;;;GAIG;AACH,QAAA,MAAM,OAAO,GAAI,iEAOd,YAAY,gCAwFd,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +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,f=null,p=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)}},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:m,renderer:h,scene:g}=e;if(!g)throw Error(`[geolocationBackend] A THREE.Scene is required for location-based AR`);s=m,l=h,u=g,n=new c.LocationBased(g,m),r=new c.Webcam(t?.webcamConstraints??{video:{facingMode:`environment`}}),o=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)},n.on(`gpsupdate`,o),r.on(`webcamstarted`,e=>{g.background=e.texture}),r.on(`webcamerror`,e=>{console.error(`[geolocationBackend] webcam error:`,e)}),i=new c.DeviceOrientationControls(m),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 _=n.getLastKnownLocation();_!==null&&(f={coords:{longitude:_.longitude,latitude:_.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>_},timestamp:Date.now(),toJSON:()=>_});let v=()=>{if(!l||!s)return;let e=window.innerWidth,t=window.innerHeight;l.setSize(e,t,!1),s.aspect=e/t,s.updateProjectionMatrix?.()};v(),window.addEventListener(`resize`,v),a=v},update(){i?.update?.()},dispose(){n&&o&&n.off(`gpsupdate`,o),n?.stopGps?.(),r?.stop?.(),i?.dispose?.(),a&&=(window.removeEventListener(`resize`,a),void 0);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,i=null,s=null,l=null,u=null,o=null,f=null},getInternal:()=>({locar:n,webcam:r,deviceOrientation:i,scene:u,camera:s,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 _}});
@@ -2,13 +2,13 @@ import { i as e, r as t } from "./useXRStore-B3-MaaCu.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";
5
- import { BackSide as d, DoubleSide as f, FrontSide as p, Group as m, Path as h, Shape as g, ShapeGeometry as _, Vector3 as v } from "three";
6
- import { Line2 as y } from "three/addons/lines/Line2.js";
7
- import { LineGeometry as b } from "three/addons/lines/LineGeometry.js";
8
- import { LineMaterial as x } from "three/addons/lines/LineMaterial.js";
9
- import { DeviceOrientationControls as S, LocationBased as C, Webcam as w } from "locar";
5
+ import { BackSide as d, BufferAttribute as f, BufferGeometry as p, DoubleSide as m, FrontSide as h, Group as g, Mesh as _, MeshBasicMaterial as v, Path as y, Shape as b, ShapeGeometry as x, Vector3 as S } from "three";
6
+ import { Line2 as C } from "three/addons/lines/Line2.js";
7
+ import { LineGeometry as w } from "three/addons/lines/LineGeometry.js";
8
+ import { LineMaterial as T } from "three/addons/lines/LineMaterial.js";
9
+ import { DeviceOrientationControls as E, LocationBased as D, Webcam as O } from "locar";
10
10
  //#region src/geolocation/useGeolocationBackend.ts
11
- var T = {
11
+ var k = {
12
12
  isPending: !0,
13
13
  isSuccess: !1,
14
14
  locar: null,
@@ -20,21 +20,32 @@ var T = {
20
20
  registerAnchor: () => {},
21
21
  unregisterAnchor: () => {},
22
22
  getAnchor: () => void 0
23
- }, E = () => {
23
+ }, A = () => {
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
- } : T;
30
- }, D = ({ coordinates: e, color: t = "#ff0000", isDashed: n = !1, dashSize: c = 3, gapSize: l = 1, lineWidth: d = 1 }) => {
31
- let f = E(), p = a(f);
29
+ } : k;
30
+ }, j = (e, t) => {
31
+ let n = e.length - 1, r = [], i = 0, a = 0;
32
+ for (let o = 0; o < n; o++) {
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;
34
+ r.push(e[o].x - p, e[o].y, e[o].z - m, e[o].x + p, e[o].y, e[o].z + m), i = d, a = f;
35
+ }
36
+ r.push(e[n].x - i, e[n].y, e[n].z - a, e[n].x + i, e[n].y, e[n].z + a);
37
+ let o = [];
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
+ let s = new p();
40
+ return s.setIndex(o), s.setAttribute("position", new f(new Float32Array(r), 3)), s.computeBoundingBox(), s;
41
+ }, M = ({ coordinates: e, color: t = "#ff0000", isDashed: n = !1, dashSize: c = 3, gapSize: l = 1, lineWidth: d = 1 }) => {
42
+ let f = A(), p = a(f);
32
43
  p.current = f;
33
- let [h] = o(() => new m()), g = i(() => Math.random().toString(36).slice(2, 11), []), [_, S] = o(null);
44
+ let [h] = o(() => new g()), y = i(() => Math.random().toString(36).slice(2, 11), []), [b, x] = o(null);
34
45
  return r(() => {
35
46
  if (!f.isSuccess || e.length < 2) return;
36
47
  let [r, i, a = 0] = e[0];
37
- return p.current.registerAnchor(g, {
48
+ return p.current.registerAnchor(y, {
38
49
  anchor: h,
39
50
  isAttached: !1,
40
51
  latitude: i,
@@ -43,22 +54,28 @@ var T = {
43
54
  onAttach: (r) => {
44
55
  let [i, a, o = 0] = e[0], [s, u] = r.lonLatToWorldCoords(i, a), f = e.map(([e, t, n = 0]) => {
45
56
  let [i, a] = r.lonLatToWorldCoords(e, t);
46
- return new v(i - s, n - o, a - u);
47
- }), p = new y(new b().setFromPoints(f), new x({
57
+ return new S(i - s, n - o, a - u);
58
+ });
59
+ if (n) {
60
+ let e = new C(new w().setFromPoints(f), new T({
61
+ color: t,
62
+ dashSize: c,
63
+ gapSize: l,
64
+ dashed: !0,
65
+ worldUnits: !0,
66
+ linewidth: d
67
+ }));
68
+ e.computeLineDistances(), x(e);
69
+ } else x(new _(j(f, d), new v({
48
70
  color: t,
49
- dashSize: c,
50
- gapSize: l,
51
- dashed: n,
52
- worldUnits: !0,
53
- linewidth: d
54
- }));
55
- n && p.computeLineDistances(), S(p);
71
+ side: m
72
+ })));
56
73
  }
57
74
  }), () => {
58
- p.current.unregisterAnchor(g), S((e) => (e && (e.geometry.dispose(), e.material.dispose()), null));
75
+ p.current.unregisterAnchor(y), x((e) => (e && (e.geometry.dispose(), e.material.dispose()), null));
59
76
  };
60
77
  }, [
61
- g,
78
+ y,
62
79
  h,
63
80
  e,
64
81
  t,
@@ -67,15 +84,15 @@ var T = {
67
84
  l,
68
85
  d,
69
86
  f.isSuccess
70
- ]), s(/* @__PURE__ */ u("group", { children: _ && /* @__PURE__ */ u("primitive", { object: _ }) }), h);
71
- }, O = ({ latitude: e, longitude: t, altitude: d = 0, isBillboard: f = !0, onAttach: p, onGpsUpdate: h, children: g }) => {
72
- let _ = E(), v = a(_);
87
+ ]), s(/* @__PURE__ */ u("group", { children: b && /* @__PURE__ */ u("primitive", { object: b }) }), h);
88
+ }, N = ({ latitude: e, longitude: t, altitude: d = 0, isBillboard: f = !0, onAttach: p, onGpsUpdate: m, children: h }) => {
89
+ let _ = A(), v = a(_);
73
90
  v.current = _;
74
- let { camera: y } = l(), [b] = o(() => new m()), x = i(() => Math.random().toString(36).slice(2, 11), []), S = n(() => {
91
+ let { camera: y } = l(), [b] = o(() => new g()), x = i(() => Math.random().toString(36).slice(2, 11), []), S = n(() => {
75
92
  p?.();
76
93
  }, [p]), C = n((e, t) => {
77
- h?.(e, t);
78
- }, [h]);
94
+ m?.(e, t);
95
+ }, [m]);
79
96
  return r(() => {
80
97
  if (_.isSuccess) return v.current.registerAnchor(x, {
81
98
  anchor: b,
@@ -99,15 +116,15 @@ var T = {
99
116
  _.isSuccess
100
117
  ]), c(() => {
101
118
  !f || !y || !_.isSuccess || _.getAnchor(x)?.isAttached && b.lookAt(y.position);
102
- }), s(/* @__PURE__ */ u("group", { children: g }), b);
103
- }, k = ({ options: e = {}, children: n }) => {
119
+ }), s(/* @__PURE__ */ u("group", { children: h }), b);
120
+ }, P = ({ options: e = {}, children: n }) => {
104
121
  let { scene: i, camera: o, gl: s } = l(), { registerBackend: c, unregisterBackend: u } = t(), d = a(null), f = a(e);
105
122
  return f.current = e, r(() => {
106
123
  if (d.current) return;
107
124
  let e = !1;
108
125
  return (async () => {
109
126
  try {
110
- let t = M(f.current);
127
+ let t = L(f.current);
111
128
  if (e) return;
112
129
  await c(t, {
113
130
  scene: i,
@@ -127,19 +144,19 @@ var T = {
127
144
  c,
128
145
  u
129
146
  ]), n;
130
- }, A = {
131
- front: p,
147
+ }, F = {
148
+ front: h,
132
149
  back: d,
133
- double: f
134
- }, j = ({ coordinates: e, holes: t, color: n = "#ff0000", opacity: c = 1, isWireframe: l = !1, side: d = "double" }) => {
135
- let f = E(), p = a(f);
150
+ double: m
151
+ }, I = ({ coordinates: e, holes: t, color: n = "#ff0000", opacity: c = 1, isWireframe: l = !1, side: d = "double" }) => {
152
+ let f = A(), p = a(f);
136
153
  p.current = f;
137
- let [v] = o(() => new m()), y = i(() => Math.random().toString(36).slice(2, 11), []), [b, x] = o(null);
154
+ let [m] = o(() => new g()), h = i(() => Math.random().toString(36).slice(2, 11), []), [_, v] = o(null);
138
155
  return r(() => {
139
156
  if (!f.isSuccess || e.length < 3) return;
140
157
  let [n, r, i = 0] = e[0];
141
- return p.current.registerAnchor(y, {
142
- anchor: v,
158
+ return p.current.registerAnchor(h, {
159
+ anchor: m,
143
160
  isAttached: !1,
144
161
  latitude: r,
145
162
  longitude: n,
@@ -154,12 +171,12 @@ var T = {
154
171
  elev: i - a
155
172
  });
156
173
  }
157
- let l = new g();
174
+ let l = new b();
158
175
  l.moveTo(c[0].x, c[0].z);
159
176
  for (let e = 1; e < c.length; e++) l.lineTo(c[e].x, c[e].z);
160
177
  if (l.closePath(), t && t.length > 0) for (let e of t) {
161
178
  if (e.length < 3) continue;
162
- let t = new h(), [r, i] = e[0], [a, c] = n.lonLatToWorldCoords(r, i);
179
+ let t = new y(), [r, i] = e[0], [a, c] = n.lonLatToWorldCoords(r, i);
163
180
  t.moveTo(a - o, c - s);
164
181
  for (let r = 1; r < e.length; r++) {
165
182
  let [i, a] = e[r], [c, l] = n.lonLatToWorldCoords(i, a);
@@ -167,39 +184,39 @@ var T = {
167
184
  }
168
185
  t.closePath(), l.holes.push(t);
169
186
  }
170
- let u = new _(l), d = c.reduce((e, t) => e + t.elev, 0) / c.length;
171
- u.rotateX(-Math.PI / 2), x({
187
+ let u = new x(l), d = c.reduce((e, t) => e + t.elev, 0) / c.length;
188
+ u.rotateX(-Math.PI / 2), v({
172
189
  geometry: u,
173
190
  avgElevation: d
174
191
  });
175
192
  }
176
193
  }), () => {
177
- p.current.unregisterAnchor(y), x((e) => (e && e.geometry.dispose(), null));
194
+ p.current.unregisterAnchor(h), v((e) => (e && e.geometry.dispose(), null));
178
195
  };
179
196
  }, [
180
- y,
181
- v,
197
+ h,
198
+ m,
182
199
  e,
183
200
  t,
184
201
  f.isSuccess
185
- ]), s(/* @__PURE__ */ u("group", { children: b && /* @__PURE__ */ u("group", {
202
+ ]), s(/* @__PURE__ */ u("group", { children: _ && /* @__PURE__ */ u("group", {
186
203
  position: [
187
204
  0,
188
- b.avgElevation,
205
+ _.avgElevation,
189
206
  0
190
207
  ],
191
208
  children: /* @__PURE__ */ u("mesh", {
192
- geometry: b.geometry,
209
+ geometry: _.geometry,
193
210
  children: /* @__PURE__ */ u("meshBasicMaterial", {
194
211
  color: n,
195
212
  opacity: c,
196
213
  transparent: c < 1,
197
214
  wireframe: l,
198
- side: A[d]
215
+ side: F[d]
199
216
  })
200
217
  })
201
- }) }), v);
202
- }, M = (t) => {
218
+ }) }), m);
219
+ }, L = (t) => {
203
220
  let n = null, r = null, i = null, a, o = null, s = null, c = null, l = null, u = /* @__PURE__ */ new Map(), d = null, f = (e) => {
204
221
  if (!(!n || e.isAttached)) try {
205
222
  n.add(e.anchor, e.longitude, e.latitude, e.altitude), e.isAttached = !0, e.onAttach?.(n);
@@ -222,7 +239,7 @@ var T = {
222
239
  async init(e) {
223
240
  let { camera: p, renderer: m, scene: h } = e;
224
241
  if (!h) throw Error("[geolocationBackend] A THREE.Scene is required for location-based AR");
225
- s = p, c = m, l = h, n = new C(h, p), r = new w(t?.webcamConstraints ?? { video: { facingMode: "environment" } }), o = (e) => {
242
+ s = p, c = m, l = h, n = new D(h, p), r = new O(t?.webcamConstraints ?? { video: { facingMode: "environment" } }), o = (e) => {
226
243
  d = e.position;
227
244
  for (let t of u.values()) t.isAttached || f(t), t.onGpsUpdate?.(e.position, e.distMoved);
228
245
  t?.onGpsUpdate?.(e.position, e.distMoved);
@@ -230,7 +247,7 @@ var T = {
230
247
  h.background = e.texture;
231
248
  }), r.on("webcamerror", (e) => {
232
249
  console.error("[geolocationBackend] webcam error:", e);
233
- }), i = new S(p), i.on("deviceorientationgranted", (e) => {
250
+ }), i = new E(p), i.on("deviceorientationgranted", (e) => {
234
251
  e.target?.connect?.();
235
252
  }), i.on("deviceorientationerror", (e) => {
236
253
  console.error("[geolocationBackend] Device orientation error:", e);
@@ -285,4 +302,4 @@ var T = {
285
302
  };
286
303
  };
287
304
  //#endregion
288
- export { D as a, O as i, j as n, E as o, k as r, M as t };
305
+ export { M as a, N as i, I as n, A as o, P as r, L as t };
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-7Gy83DEg.cjs`);const e=require(`./geolocation-uko8RwgK.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;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-7Gy83DEg.cjs`);const e=require(`./geolocation-ClkbtHic.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;
@@ -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-U_vaIjuk.js";
2
+ import { a as e, i as t, n, o as r, r as i, t as a } from "./geolocation-DxPzqQPN.js";
3
3
  export { e as GeoLine, n as GeoPolygon, t as GeolocationAnchor, i as GeolocationSession, a as createGeolocationBackend, r as useGeolocationBackend };
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-uko8RwgK.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;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useXRStore-7Gy83DEg.cjs`),t=require(`./fiducial-dapuWTXg.cjs`),n=require(`./geolocation-ClkbtHic.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-U_vaIjuk.js";
3
+ import { a as c, i as l, n as u, o as d, r as f, t as p } from "./geolocation-DxPzqQPN.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnidotdev/rdk",
3
3
  "description": "Reality Development Kit, a unified React-first XR engine",
4
- "version": "0.9.1",
4
+ "version": "0.10.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "build/index.js",
@@ -1 +0,0 @@
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=({coordinates:e,color:c=`#ff0000`,isDashed:l=!1,dashSize:d=3,gapSize:f=1,lineWidth:p=1})=>{let m=u(),h=(0,t.useRef)(m);h.current=m;let[g]=(0,t.useState)(()=>new i.Group),_=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[v,y]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!m.isSuccess||e.length<2)return;let[t,n,r=0]=e[0];return h.current.registerAnchor(_,{anchor:g,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,u=0]=e[0],[m,h]=t.lonLatToWorldCoords(n,r),g=e.map(([e,n,r=0])=>{let[a,o]=t.lonLatToWorldCoords(e,n);return new i.Vector3(a-m,r-u,o-h)}),_=new a.Line2(new o.LineGeometry().setFromPoints(g),new s.LineMaterial({color:c,dashSize:d,gapSize:f,dashed:l,worldUnits:!0,linewidth:p}));l&&_.computeLineDistances(),y(_)}}),()=>{h.current.unregisterAnchor(_),y(e=>(e&&(e.geometry.dispose(),e.material.dispose()),null))}},[_,g,e,c,l,d,f,p,m.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:v&&(0,r.jsx)(`primitive`,{object:v})}),g)},f=({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)},p=({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=g(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},m={front:i.FrontSide,back:i.BackSide,double:i.DoubleSide},h=({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),h=(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(h,{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(h),_(e=>(e&&e.geometry.dispose(),null))}},[h,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:m[l]})})})}),p)},g=t=>{let n=null,r=null,i=null,a,o=null,s=null,l=null,u=null,d=new Map,f=null,p=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)}},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:m,renderer:h,scene:g}=e;if(!g)throw Error(`[geolocationBackend] A THREE.Scene is required for location-based AR`);s=m,l=h,u=g,n=new c.LocationBased(g,m),r=new c.Webcam(t?.webcamConstraints??{video:{facingMode:`environment`}}),o=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)},n.on(`gpsupdate`,o),r.on(`webcamstarted`,e=>{g.background=e.texture}),r.on(`webcamerror`,e=>{console.error(`[geolocationBackend] webcam error:`,e)}),i=new c.DeviceOrientationControls(m),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 _=n.getLastKnownLocation();_!==null&&(f={coords:{longitude:_.longitude,latitude:_.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>_},timestamp:Date.now(),toJSON:()=>_});let v=()=>{if(!l||!s)return;let e=window.innerWidth,t=window.innerHeight;l.setSize(e,t,!1),s.aspect=e/t,s.updateProjectionMatrix?.()};v(),window.addEventListener(`resize`,v),a=v},update(){i?.update?.()},dispose(){n&&o&&n.off(`gpsupdate`,o),n?.stopGps?.(),r?.stop?.(),i?.dispose?.(),a&&=(window.removeEventListener(`resize`,a),void 0);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,i=null,s=null,l=null,u=null,o=null,f=null},getInternal:()=>({locar:n,webcam:r,deviceOrientation:i,scene:u,camera:s,lastPosition:f,registerAnchor:m,unregisterAnchor:h,getAnchor:g})}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return g}});