@omnidotdev/rdk 0.5.0 → 0.5.2
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.map +1 -1
- package/build/fiducial/FiducialSession.d.ts.map +1 -1
- package/build/fiducial/fiducialBackend.d.ts +1 -1
- package/build/fiducial/fiducialBackend.d.ts.map +1 -1
- package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
- package/build/geolocation/GeolocationSession.d.ts.map +1 -1
- package/build/geolocation/geolocationBackend.d.ts +20 -1
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/index.cjs +1 -1
- package/build/index.js +363 -328
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts +4 -4
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts.map +1 -1
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useXRStore.d.ts","sourceRoot":"","sources":["../../src/engine/useXRStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useXRStore.d.ts","sourceRoot":"","sources":["../../src/engine/useXRStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE1D,eAAO,MAAM,aAAa;;;;CAIhB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E,UAAU,gBAAgB;IACxB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,8CAA8C;IAC9C,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,uDAAuD;IACvD,YAAY,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IACjC,6CAA6C;IAC7C,cAAc,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC3C;AAED,UAAU,kBAAkB;IAC1B,+CAA+C;IAC/C,eAAe,EAAE,CACf,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,aAAa,CAAA;KAAE,EACpE,WAAW,CAAC,EAAE,aAAa,KACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,iDAAiD;IACjD,iBAAiB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3E,gCAAgC;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD,yDAAyD;IACzD,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,oCAAoC;IACpC,iBAAiB,EAAE,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;CAC9D;AAED,KAAK,WAAW,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAEzD,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACrC,CAAC;AA+FF,eAAO,MAAM,UAAU,mBAAkC,CAAC;AAC1D,eAAO,MAAM,kBAAkB;;;;;;CAA2B,CAAC;AAE3D;;GAEG;AACH,QAAA,MAAM,UAAU,GAAI,CAAC,GAAG,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,KAc5C,CACpB,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiducialSession.d.ts","sourceRoot":"","sources":["../../src/fiducial/FiducialSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,gCAAgC;IAChC,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe;4BAAgC,oBAAoB;;
|
|
1
|
+
{"version":3,"file":"FiducialSession.d.ts","sourceRoot":"","sources":["../../src/fiducial/FiducialSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,gCAAgC;IAChC,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe;4BAAgC,oBAAoB;;CAgDxE,CAAC;AAKF,eAAe,eAAe,CAAC"}
|
|
@@ -14,6 +14,6 @@ export interface FiducialSessionOptions {
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a fiducial marker-based AR backend.
|
|
16
16
|
*/
|
|
17
|
-
declare const createFiducialBackend: (options
|
|
17
|
+
declare const createFiducialBackend: (options?: FiducialSessionOptions) => Backend;
|
|
18
18
|
export default createFiducialBackend;
|
|
19
19
|
//# sourceMappingURL=fiducialBackend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fiducialBackend.d.ts","sourceRoot":"","sources":["../../src/fiducial/fiducialBackend.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAGjE,MAAM,WAAW,sBAAsB;IACrC,yBAAyB;IACzB,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;IAC1C,6BAA6B;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB;IACtB,aAAa,CAAC,EAAE,OAAO,GAAG,kBAAkB,GAAG,MAAM,GAAG,iBAAiB,CAAC;IAC1E,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,cAAc,CAAC,EACX,KAAK,GACL,eAAe,GACf,cAAc,GACd,KAAK,GACL,gBAAgB,GAChB,gBAAgB,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"fiducialBackend.d.ts","sourceRoot":"","sources":["../../src/fiducial/fiducialBackend.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAGjE,MAAM,WAAW,sBAAsB;IACrC,yBAAyB;IACzB,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;IAC1C,6BAA6B;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB;IACtB,aAAa,CAAC,EAAE,OAAO,GAAG,kBAAkB,GAAG,MAAM,GAAG,iBAAiB,CAAC;IAC1E,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,cAAc,CAAC,EACX,KAAK,GACL,eAAe,GACf,cAAc,GACd,KAAK,GACL,gBAAgB,GAChB,gBAAgB,CAAC;CACtB;AAED;;GAEG;AACH,QAAA,MAAM,qBAAqB,GAAI,UAAU,sBAAsB,KAAG,OAuIjE,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeolocationAnchor.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationAnchor.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"GeolocationAnchor.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationAnchor.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAEV,yBAAyB,EAE1B,MAAM,sBAAsB,CAAC;AAyB9B,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,yBAAyB,EAAE,aAAa,CAAC,EACpD,iBAAiB;IACnB,wFAAwF;IACxF,QAAQ,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,QAAA,MAAM,iBAAiB,GAAI,2GAQxB,sBAAsB,gCAkMxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeolocationSession.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,mCAAmC;IACnC,OAAO,CAAC,EAAE,yBAAyB,CAAC;CACrC;AAED;;;GAGG;AACH,QAAA,MAAM,kBAAkB;6BAGrB,uBAAuB;;
|
|
1
|
+
{"version":3,"file":"GeolocationSession.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,mCAAmC;IACnC,OAAO,CAAC,EAAE,yBAAyB,CAAC;CACrC;AAED;;;GAGG;AACH,QAAA,MAAM,kBAAkB;6BAGrB,uBAAuB;;CAgDzB,CAAC;AAKF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,4 +1,23 @@
|
|
|
1
|
+
import { DeviceOrientationControls, LocationBased as LocAR, Webcam } from 'locar';
|
|
1
2
|
import { Backend } from 'lib/types/engine';
|
|
3
|
+
import { Camera, Scene } from 'three';
|
|
4
|
+
/**
|
|
5
|
+
* Geolocation backend.
|
|
6
|
+
*/
|
|
7
|
+
export interface GeolocationBackend {
|
|
8
|
+
locar: LocAR | null;
|
|
9
|
+
webcam: Webcam | null;
|
|
10
|
+
deviceOrientation: DeviceOrientationControls | null;
|
|
11
|
+
scene: Scene | null;
|
|
12
|
+
camera: Camera | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* GPS update event structure emitted by LocAR.
|
|
16
|
+
*/
|
|
17
|
+
export interface GpsUpdateEvent {
|
|
18
|
+
position: GeolocationPosition;
|
|
19
|
+
distMoved: number;
|
|
20
|
+
}
|
|
2
21
|
/**
|
|
3
22
|
* Options for the geolocation backend.
|
|
4
23
|
*/
|
|
@@ -19,6 +38,6 @@ export interface GeolocationSessionOptions {
|
|
|
19
38
|
/**
|
|
20
39
|
* Create a location-based AR backend.
|
|
21
40
|
*/
|
|
22
|
-
declare const createGeolocationBackend: (options
|
|
41
|
+
declare const createGeolocationBackend: (options?: GeolocationSessionOptions) => Backend;
|
|
23
42
|
export default createGeolocationBackend;
|
|
24
43
|
//# sourceMappingURL=geolocationBackend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/geolocationBackend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/geolocationBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,aAAa,IAAI,KAAK,EACtB,MAAM,EACP,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAiB,MAAM,OAAO,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,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;CACvB;AAED;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;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,OA0IF,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
package/build/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),v=require("@react-three/fiber"),L=require("react/jsx-runtime"),O=require("@ar-js-org/ar.js/three.js/build/ar-threex"),N=require("three"),H=require("locar"),G=require("@react-three/xr");var B=typeof document<"u"?document.currentScript:null;function W(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const F=W(H),j=e=>{let t;const n=new Set,o=(a,l)=>{const d=typeof a=="function"?a(t):a;if(!Object.is(d,t)){const c=t;t=l??(typeof d!="object"||d===null)?d:Object.assign({},t,d),n.forEach(m=>m(t,c))}},A=()=>t,r={setState:o,getState:A,getInitialState:()=>u,subscribe:a=>(n.add(a),()=>n.delete(a))},u=t=e(o,A,r);return r},Q=(e=>e?j(e):j),V=e=>e;function Y(e,t=V){const n=f.useSyncExternalStore(e.subscribe,f.useCallback(()=>t(e.getState()),[e,t]),f.useCallback(()=>t(e.getInitialState()),[e,t]));return f.useDebugValue(n),n}const K=e=>{const t=Q(e),n=o=>Y(t,o);return Object.assign(n,t),n},$=(e=>K),J=e=>(t,n,o)=>{const A=o.subscribe;return o.subscribe=((i,r,u)=>{let a=i;if(r){const l=u?.equalityFn||Object.is;let d=i(o.getState());a=c=>{const m=i(c);if(!l(d,m)){const g=d;r(d=m,g)}},u?.fireImmediately&&r(d,d)}return A(a)}),e(t,n,o)},Z=J,p={FIDUCIAL:"FiducialSession",GEOLOCATION:"GeolocationSession",IMMERSIVE:"ImmersiveSession"},M=$()(Z((e,t)=>({video:null,backends:[],sessionTypes:new Set,immersiveStore:null,registerBackend:async(n,o,A)=>{try{if(A){const s=t(),i=new Set([...s.sessionTypes,A]),r=i.has(p.FIDUCIAL),u=i.has(p.GEOLOCATION);if(r&&u){const a=`❌ [RDK] INCOMPATIBLE SESSIONS: ${p.FIDUCIAL} and ${p.GEOLOCATION} cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.`;throw console.error(a),new Error(a)}e(()=>({sessionTypes:i}))}await n.init({scene:o.scene,camera:o.camera,renderer:o.renderer}),e(s=>({backends:[...s.backends,n]}))}catch(s){throw console.error("[XRStore] Failed to register backend:",s),s}},unregisterBackend:(n,o)=>{e(A=>{const s=new Set(A.sessionTypes);o&&s.delete(o);const i=A.backends.filter(r=>r!==n);try{n.dispose?.()}catch(r){console.error("[XRStore] Error disposing backend:",r)}return{backends:i,sessionTypes:s}})},setVideo:n=>{e({video:n})},updateBackends:n=>{const{backends:o}=t();o.forEach(A=>{try{A.update?.(n)}catch(s){console.error("[XRStore] Backend update error:",s)}})},setImmersiveStore:n=>{e({immersiveStore:n})}}))),P=()=>M.getState(),ee=M.subscribe,E=e=>{const t=M(),n={...t,isImmersive:t.sessionTypes.has(p.IMMERSIVE),immersive:t.immersiveStore||null};return e?e(n):n},te=({children:e})=>{const{updateBackends:t}=E();return v.useFrame((n,o)=>{t(o)}),e},ne=({patternUrl:e,barcodeValue:t,params:n,onMarkerFound:o,onMarkerLost:A,children:s})=>{const i=f.useRef(null),r=E(d=>d.backends),u=f.useRef(!1),a=f.useRef(!1),l=f.useRef(null);return f.useEffect(()=>{let d=!1;return(async()=>{try{const m=r.find(w=>w.getInternal?.()?.arContext);if(!m||d)return;const k=m.getInternal?.()?.arContext,y=i.current;if(!k||!y)return;if(y.visible=!1,a.current=!1,!k.arController){requestAnimationFrame(()=>{if(!i.current||d)return;const b=m.getInternal?.()?.arContext;if(!b?.arController)return;const h=new O.ArMarkerControls(b,i.current,{type:e?"pattern":t?"barcode":"unknown",patternUrl:e,barcodeValue:t,...n});l.current=h,a.current=!0});return}const I=new O.ArMarkerControls(k,y,{type:e?"pattern":t?"barcode":"unknown",patternUrl:e,barcodeValue:t,...n});l.current=I,a.current=!0}catch(m){console.error("Failed to initialize fiducial backend:",m)}})(),()=>{d=!0;const m=l.current;typeof m?.dispose=="function"&&m.dispose(),a.current=!1}},[r,e,t,n]),v.useFrame(()=>{const d=i.current;if(!d||!a.current){d&&(d.visible=!1);return}const c=d.visible;c&&!u.current?(u.current=!0,o?.()):!c&&u.current&&(u.current=!1,A?.())}),L.jsx("group",{ref:i,visible:!1,children:s})},U=({options:e={},children:t})=>{const{scene:n,camera:o,gl:A}=v.useThree(),{registerBackend:s,unregisterBackend:i}=E(),r=f.useRef(null);return f.useEffect(()=>{if(r.current)return;let u=!1;return(async()=>{try{const l=q(e);if(u)return;await s(l,{scene:n,camera:o,renderer:A},p.FIDUCIAL),r.current=l}catch(l){console.error("[FiducialSession] Failed to initialize:",l)}})(),()=>{u=!0,r.current&&(i(r.current,p.FIDUCIAL),r.current=null)}},[n,o,A,s,i,e]),t};U.sessionType="FiducialSession";const q=e=>{let t,n,o;return{async init({camera:s,renderer:i}){t=new O.ArToolkitSource({sourceType:e.sourceType??"webcam"}),await new Promise((a,l)=>{const d=setTimeout(()=>{l(new Error("AR source initialization timeout"))},1e4);t.init(()=>{clearTimeout(d);const c=t.domElement;c&&(c.style.position="fixed",c.style.top="0",c.style.left="0",c.style.width="100vw",c.style.height="100vh",c.style.objectFit="cover",c.style.zIndex="-1",c.style.pointerEvents="none"),a()})});const r={cameraParametersUrl:e.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:B&&B.tagName.toUpperCase()==="SCRIPT"&&B.src||new URL("index.cjs",document.baseURI).href).toString(),detectionMode:e.detectionMode??"mono",patternRatio:e.patternRatio??.5,matrixCodeType:e.matrixCodeType??"3x3"};n=new O.ArToolkitContext(r);const u=()=>{t.onResizeElement();const a=window.innerWidth,l=window.innerHeight;i.setSize(a,l,!1),t.copyElementSizeTo(i.domElement),n?.arController&&t.copyElementSizeTo(n.arController.canvas)};await new Promise((a,l)=>{const d=setTimeout(()=>{l(new Error("AR context initialization timeout"))},1e4);n.init(()=>{clearTimeout(d);try{s.projectionMatrix.copy(n.getProjectionMatrix()),u(),a()}catch(c){l(c)}})}),this._arSource=t,this._arContext=n,this._camera=s,window.addEventListener("resize",u),o=u},update(){const s=this._arSource,i=this._arContext,r=this._camera;if(!(!s||!i)&&s.ready!==!1&&s.domElement)try{i.update(s.domElement),r&&i.getProjectionMatrix&&r.projectionMatrix.copy(i.getProjectionMatrix())}catch(u){console.warn("AR.js update error:",u)}},dispose(){o&&(window.removeEventListener("resize",o),o=void 0);const s=this._arSource,i=this._arContext;if(i&&typeof i.dispose=="function"&&i.dispose(),s?.domElement){const r=s.domElement.parentNode;r&&r.removeChild(s.domElement)}this._arSource=void 0,this._arContext=void 0},getInternal(){return{arSource:this._arSource,arContext:this._arContext}}}},R=new Map;let z=!1,x=null,C=null;const re=({latitude:e,longitude:t,altitude:n=0,isBillboard:o=!0,onAttach:A,onGpsUpdate:s,children:i})=>{const r=E(g=>g.backends),{camera:u}=v.useThree(),[a]=f.useState(()=>new N.Group),[l]=f.useState(()=>Math.random().toString(36).slice(2,11)),d=f.useRef(!1),c=f.useCallback(()=>{A?.()},[A]),m=f.useCallback((g,k)=>{s?.(g,k)},[s]);return f.useEffect(()=>{let g=!1;return(async()=>{try{const y=r.find(S=>S.getInternal?.()?.locar);if(!y||g)return;const w=y.getInternal?.()?.locar;if(!w)return;const b=S=>{try{w.add(S.anchor,S.longitude,S.latitude,S.altitude),S.isAttached=!0,S.onAttach?.()}catch(T){console.error("❌ Failed to attach anchor:",T)}},h={anchor:a,isAttached:!1,latitude:e,longitude:t,altitude:n||0,onAttach:c,onGpsUpdate:m};R.set(l,h),z||(C=({position:S,distMoved:T})=>{x=S,R.forEach(_=>{_.isAttached||b(_),_.onGpsUpdate?.(S,T)})},x!==null&&!h.isAttached&&b(h),w.on?.("gpsupdate",C),z=!0),x!==null&&(h.isAttached||b(h),h.onGpsUpdate?.(x,0)),d.current=!1}catch(y){console.error("Failed to initialize geolocation backend:",y)}})(),()=>{if(g=!0,R.get(l)?.isAttached)try{const b=r.find(h=>h.getInternal?.()?.locar)?.getInternal?.()?.locar;typeof b?.remove=="function"?b.remove(a):a.removeFromParent()}catch(I){console.error(`⚠️ Error removing anchor ${l}:`,I)}R.delete(l),R.size===0&&C&&(r.find(h=>h.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate",C),C=null,z=!1)}},[r,a,l,e,t,n,c,m]),v.useFrame(()=>{!o||!u||!R.get(l)?.isAttached||a.lookAt(u.position)}),v.createPortal(L.jsx("group",{children:i}),a)},X=({options:e={},children:t})=>{const{scene:n,camera:o,gl:A}=v.useThree(),{registerBackend:s,unregisterBackend:i}=E(),r=f.useRef(null);return f.useEffect(()=>{if(r.current)return;let u=!1;return(async()=>{try{const l=D(e);if(u)return;await s(l,{scene:n,camera:o,renderer:A},p.GEOLOCATION),r.current=l}catch(l){console.error("[GeolocationSession] Failed to initialize:",l)}})(),()=>{u=!0,r.current&&(i(r.current,p.GEOLOCATION),r.current=null)}},[n,o,A,s,i,e]),t};X.sessionType="GeolocationSession";const D=e=>{let t,n,o,A,s=null,i=null;return{async init(r){const{camera:u,renderer:a,scene:l}=r;if(!l)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");s=u,i=a,t=new F.LocationBased(l,u),n=new F.Webcam(e.webcamConstraints??{video:{facingMode:"environment"}},null),t.on("gpsupdate",c=>{e.onGpsUpdate?.(c.position,c.distMoved)}),n.on("webcamstarted",c=>{l.background=c.texture}),n.on("webcamerror",c=>{console.error("[geolocationBackend] webcam error:",c)}),o=new F.DeviceOrientationControls(u),o.on("deviceorientationgranted",c=>{c.target?.connect?.()}),o.on("deviceorientationerror",c=>{console.error("[geolocationBackend] Device orientation error:",c)}),o.init?.(),t.on("gpserror",c=>{console.error("[geolocationBackend] gps error:",c)}),t.startGps(),typeof e.fakeLat=="number"&&typeof e.fakeLon=="number"&&t.fakeGps(e.fakeLon,e.fakeLat);const d=()=>{if(!i||!s)return;const c=window.innerWidth,m=window.innerHeight;i.setSize(c,m,!1),s.aspect=c/m,s.updateProjectionMatrix?.()};d(),window.addEventListener("resize",d),A=d,this._locar=t,this._webcam=n,this._deviceOrientation=o,this._scene=l,this._camera=u},update(){this._deviceOrientation?.update?.()},dispose(){const r=this._locar,u=this._webcam,a=this._deviceOrientation;e?.onGpsUpdate&&r?.off("gpsupdate",e.onGpsUpdate),r?.stopGps?.(),u?.stop?.(),a?.dispose?.(),A&&(window.removeEventListener("resize",A),A=void 0),this._locar=null,this._webcam=null,this._deviceOrientation=null,this._scene=null,this._camera=null},getInternal(){return{locar:this._locar,webcam:this._webcam,deviceOrientation:this._deviceOrientation,scene:this._scene,camera:this._camera}}}},oe=({children:e})=>{const t=f.useMemo(()=>G.createXRStore(),[]);return f.useEffect(()=>{const n=P();return n.sessionTypes.add(p.IMMERSIVE),n.setImmersiveStore(t),()=>{n.sessionTypes.delete(p.IMMERSIVE),n.setImmersiveStore(null)}},[t]),L.jsx(G.XR,{store:t,children:e})};exports.FiducialAnchor=ne;exports.FiducialSession=U;exports.GeolocationAnchor=re;exports.GeolocationSession=X;exports.ImmersiveSession=oe;exports.XR=te;exports.createFiducialBackend=q;exports.createGeolocationBackend=D;exports.getXRStore=P;exports.subscribeToXRStore=ee;exports.useXRStore=E;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react"),k=require("@react-three/fiber"),L=require("react/jsx-runtime"),v=require("@ar-js-org/ar.js/three.js/build/ar-threex"),V=require("three"),M=require("locar"),B=require("@react-three/xr");var j=typeof document<"u"?document.currentScript:null;const P=t=>{let e;const n=new Set,r=(a,d)=>{const i=typeof a=="function"?a(e):a;if(!Object.is(i,e)){const A=e;e=d??(typeof i!="object"||i===null)?i:Object.assign({},e,i),n.forEach(S=>S(e,A))}},s=()=>e,c={setState:r,getState:s,getInitialState:()=>u,subscribe:a=>(n.add(a),()=>n.delete(a))},u=e=t(r,s,c);return c},Y=(t=>t?P(t):P),$=t=>t;function J(t,e=$){const n=m.useSyncExternalStore(t.subscribe,m.useCallback(()=>e(t.getState()),[t,e]),m.useCallback(()=>e(t.getInitialState()),[t,e]));return m.useDebugValue(n),n}const _=t=>{const e=Y(t),n=r=>J(e,r);return Object.assign(n,e),n},Z=(t=>_),ee=t=>(e,n,r)=>{const s=r.subscribe;return r.subscribe=((l,c,u)=>{let a=l;if(c){const d=u?.equalityFn||Object.is;let i=l(r.getState());a=A=>{const S=l(A);if(!d(i,S)){const f=i;c(i=S,f)}},u?.fireImmediately&&c(i,i)}return s(a)}),t(e,n,r)},te=ee,q=t=>Symbol.iterator in t,U=t=>"entries"in t,X=(t,e)=>{const n=t instanceof Map?t:new Map(t.entries()),r=e instanceof Map?e:new Map(e.entries());if(n.size!==r.size)return!1;for(const[s,o]of n)if(!r.has(s)||!Object.is(o,r.get(s)))return!1;return!0},ne=(t,e)=>{const n=t[Symbol.iterator](),r=e[Symbol.iterator]();let s=n.next(),o=r.next();for(;!s.done&&!o.done;){if(!Object.is(s.value,o.value))return!1;s=n.next(),o=r.next()}return!!s.done&&!!o.done};function re(t,e){return Object.is(t,e)?!0:typeof t!="object"||t===null||typeof e!="object"||e===null||Object.getPrototypeOf(t)!==Object.getPrototypeOf(e)?!1:q(t)&&q(e)?U(t)&&U(e)?X(t,e):ne(t,e):X({entries:()=>Object.entries(t)},{entries:()=>Object.entries(e)})}function oe(t){const e=m.useRef(void 0);return n=>{const r=t(n);return re(e.current,r)?e.current:e.current=r}}const b={FIDUCIAL:"FiducialSession",GEOLOCATION:"GeolocationSession",IMMERSIVE:"ImmersiveSession"},G=Z()(te((t,e)=>({video:null,backends:[],sessionTypes:new Set,immersiveStore:null,registerBackend:async(n,r,s)=>{try{if(s){const o=e(),l=new Set([...o.sessionTypes,s]),c=l.has(b.FIDUCIAL),u=l.has(b.GEOLOCATION);if(c&&u){const a=`❌ [RDK] INCOMPATIBLE SESSIONS: ${b.FIDUCIAL} and ${b.GEOLOCATION} cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.`;throw console.error(a),new Error(a)}t(()=>({sessionTypes:l}))}await n.init({scene:r.scene,camera:r.camera,renderer:r.renderer}),t(o=>({backends:[...o.backends,n]}))}catch(o){throw console.error("[XRStore] Failed to register backend:",o),o}},unregisterBackend:(n,r)=>{t(s=>{const o=new Set(s.sessionTypes);r&&o.delete(r);const l=s.backends.filter(c=>c!==n);try{n.dispose?.()}catch(c){console.error("[XRStore] Error disposing backend:",c)}return{backends:l,sessionTypes:o}})},setVideo:n=>{t({video:n})},updateBackends:n=>{const{backends:r}=e();r.forEach(s=>{try{s.update?.(n)}catch(o){console.error("[XRStore] Backend update error:",o)}})},setImmersiveStore:n=>{t({immersiveStore:n})}}))),N=()=>G.getState(),se=G.subscribe,E=t=>G(oe(n=>{const r={...n,isImmersive:n.sessionTypes.has(b.IMMERSIVE),immersive:n.immersiveStore||null};return t?t(r):r})),ie=({children:t})=>{const{updateBackends:e}=E();return k.useFrame((n,r)=>{e(r)}),t},ce=({patternUrl:t,barcodeValue:e,params:n,onMarkerFound:r,onMarkerLost:s,children:o})=>{const l=m.useRef(null),c=E(i=>i.backends),u=m.useRef(!1),a=m.useRef(!1),d=m.useRef(null);return m.useEffect(()=>{let i=!1;return(async()=>{try{const S=c.find(h=>h.getInternal?.()?.arContext);if(!S||i)return;const y=S.getInternal?.()?.arContext,w=l.current;if(!y||!w)return;if(w.visible=!1,a.current=!1,!y.arController){requestAnimationFrame(()=>{if(!l.current||i)return;const I=S.getInternal?.()?.arContext;if(!I?.arController)return;const g=new v.ArMarkerControls(I,l.current,{type:t?"pattern":e?"barcode":"unknown",patternUrl:t,barcodeValue:e,...n});d.current=g,a.current=!0});return}const C=new v.ArMarkerControls(y,w,{type:t?"pattern":e?"barcode":"unknown",patternUrl:t,barcodeValue:e,...n});d.current=C,a.current=!0}catch(S){console.error("Failed to initialize fiducial backend:",S)}})(),()=>{i=!0;const S=d.current;typeof S?.dispose=="function"&&S.dispose(),a.current=!1}},[c,t,e,n]),k.useFrame(()=>{const i=l.current;if(!i||!a.current){i&&(i.visible=!1);return}const A=i.visible;A&&!u.current?(u.current=!0,r?.()):!A&&u.current&&(u.current=!1,s?.())}),L.jsx("group",{ref:l,visible:!1,children:o})},D=({options:t={},children:e})=>{const{scene:n,camera:r,gl:s}=k.useThree(),{registerBackend:o,unregisterBackend:l}=E(),c=m.useRef(null),u=m.useRef(t);return u.current=t,m.useEffect(()=>{if(c.current)return;let a=!1;return(async()=>{try{const i=H(u.current);if(a)return;await o(i,{scene:n,camera:r,renderer:s},b.FIDUCIAL),c.current=i}catch(i){console.error("[FiducialSession] Failed to initialize:",i)}})(),()=>{a=!0,c.current&&(l(c.current,b.FIDUCIAL),c.current=null)}},[n,r,s,o,l]),e};D.sessionType="FiducialSession";const H=t=>{let e=null,n=null,r=null,s;return{async init({camera:o,renderer:l}){e=new v.ArToolkitSource({sourceType:t?.sourceType??"webcam"}),await new Promise((a,d)=>{const i=setTimeout(()=>{d(new Error("AR source initialization timeout"))},1e4);e.init(()=>{clearTimeout(i);const A=e.domElement;A&&(A.style.position="fixed",A.style.top="0",A.style.left="0",A.style.width="100vw",A.style.height="100vh",A.style.objectFit="cover",A.style.zIndex="-1",A.style.pointerEvents="none"),a()})});const c={cameraParametersUrl:t?.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:j&&j.tagName.toUpperCase()==="SCRIPT"&&j.src||new URL("index.cjs",document.baseURI).href).toString(),detectionMode:t?.detectionMode??"mono",patternRatio:t?.patternRatio??.5,matrixCodeType:t?.matrixCodeType??"3x3"};n=new v.ArToolkitContext(c),r=o;const u=()=>{e.onResizeElement();const a=window.innerWidth,d=window.innerHeight;l.setSize(a,d,!1),e.copyElementSizeTo(l.domElement),n?.arController&&e.copyElementSizeTo(n.arController.canvas)};await new Promise((a,d)=>{const i=setTimeout(()=>{d(new Error("AR context initialization timeout"))},1e4);n.init(()=>{clearTimeout(i);try{o.projectionMatrix.copy(n.getProjectionMatrix()),u(),a()}catch(A){d(A)}})}),window.addEventListener("resize",u),s=u},update(){if(!(!e||!n)&&!(!e.ready||!e.domElement))try{n.update(e.domElement),r&&n.getProjectionMatrix&&r.projectionMatrix.copy(n.getProjectionMatrix())}catch(o){console.warn("AR.js update error:",o)}},dispose(){if(s&&(window.removeEventListener("resize",s),s=void 0),n&&typeof n.dispose=="function"&&n.dispose(),e?.domElement){const o=e.domElement.parentNode;o&&o.removeChild(e.domElement)}e=null,n=null,r=null},getInternal(){return{arSource:e,arContext:n}}}},R=new Map;let z=!1,x=null,O=null;const ae=({latitude:t,longitude:e,altitude:n=0,isBillboard:r=!0,onAttach:s,onGpsUpdate:o,children:l})=>{const c=E(f=>f.backends),{camera:u}=k.useThree(),[a]=m.useState(()=>new V.Group),[d]=m.useState(()=>Math.random().toString(36).slice(2,11)),i=m.useRef(!1),A=m.useCallback(()=>{s?.()},[s]),S=m.useCallback((f,y)=>{o?.(f,y)},[o]);return m.useEffect(()=>{let f=!1;return(async()=>{try{const w=c.find(p=>p.getInternal?.()?.locar);if(!w||f)return;const h=w.getInternal?.()?.locar;if(!h)return;const I=p=>{try{h.add(p.anchor,p.longitude,p.latitude,p.altitude),p.isAttached=!0,p.onAttach?.()}catch(T){console.error("❌ Failed to attach anchor:",T)}},g={anchor:a,isAttached:!1,latitude:t,longitude:e,altitude:n||0,onAttach:A,onGpsUpdate:S};if(R.set(d,g),!z){O=({position:T,distMoved:Q})=>{x=T,R.forEach(F=>{F.isAttached||I(F),F.onGpsUpdate?.(T,Q)})};const p=h.getLastKnownLocation();p!==null&&(x={coords:{longitude:p.longitude,latitude:p.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>p},timestamp:Date.now(),toJSON:()=>p}),x!==null&&!g.isAttached&&I(g),h.on?.("gpsupdate",O),z=!0}x!==null&&(g.isAttached||I(g),g.onGpsUpdate?.(x,0)),i.current=!1}catch(w){console.error("Failed to initialize geolocation backend:",w)}})(),()=>{if(f=!0,R.get(d)?.isAttached)try{a.removeFromParent()}catch(C){console.error(`⚠️ Error removing anchor ${d}:`,C)}R.delete(d),R.size===0&&O&&(c.find(g=>g.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate",O),O=null,z=!1)}},[c,a,d,t,e,n,A,S]),k.useFrame(()=>{!r||!u||!R.get(d)?.isAttached||a.lookAt(u.position)}),k.createPortal(L.jsx("group",{children:l}),a)},W=({options:t={},children:e})=>{const{scene:n,camera:r,gl:s}=k.useThree(),{registerBackend:o,unregisterBackend:l}=E(),c=m.useRef(null),u=m.useRef(t);return u.current=t,m.useEffect(()=>{if(c.current)return;let a=!1;return(async()=>{try{const i=K(u.current);if(a)return;await o(i,{scene:n,camera:r,renderer:s},b.GEOLOCATION),c.current=i}catch(i){console.error("[GeolocationSession] Failed to initialize:",i)}})(),()=>{a=!0,c.current&&(l(c.current,b.GEOLOCATION),c.current=null)}},[n,r,s,o,l]),e};W.sessionType="GeolocationSession";const K=t=>{let e=null,n=null,r=null,s,o=null,l=null,c=null,u=null;return{async init(a){const{camera:d,renderer:i,scene:A}=a;if(!A)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");l=d,c=i,u=A,e=new M.LocationBased(A,d),n=new M.Webcam(t?.webcamConstraints??{video:{facingMode:"environment"}}),o=f=>{t?.onGpsUpdate?.(f.position,f.distMoved)},e.on("gpsupdate",o),n.on("webcamstarted",f=>{A.background=f.texture}),n.on("webcamerror",f=>{console.error("[geolocationBackend] webcam error:",f)}),r=new M.DeviceOrientationControls(d),r.on("deviceorientationgranted",f=>{f.target?.connect?.()}),r.on("deviceorientationerror",f=>{console.error("[geolocationBackend] Device orientation error:",f)}),r.init?.(),e.on("gpserror",f=>{console.error("[geolocationBackend] gps error:",f)}),e.startGps(),typeof t?.fakeLat=="number"&&typeof t?.fakeLon=="number"&&e.fakeGps(t.fakeLon,t.fakeLat);const S=()=>{if(!c||!l)return;const f=window.innerWidth,y=window.innerHeight;c.setSize(f,y,!1),l.aspect=f/y,l.updateProjectionMatrix?.()};S(),window.addEventListener("resize",S),s=S},update(){r?.update?.()},dispose(){e&&o&&e.off("gpsupdate",o),e?.stopGps?.(),n?.stop?.(),r?.dispose?.(),s&&(window.removeEventListener("resize",s),s=void 0),e=null,n=null,r=null,l=null,c=null,u=null,o=null},getInternal:()=>({locar:e,webcam:n,deviceOrientation:r,scene:u,camera:l})}},le=({children:t})=>{const e=m.useMemo(()=>B.createXRStore(),[]);return m.useEffect(()=>{const n=N();return n.sessionTypes.add(b.IMMERSIVE),n.setImmersiveStore(e),()=>{n.sessionTypes.delete(b.IMMERSIVE),n.setImmersiveStore(null)}},[e]),L.jsx(B.XR,{store:e,children:t})};exports.FiducialAnchor=ce;exports.FiducialSession=D;exports.GeolocationAnchor=ae;exports.GeolocationSession=W;exports.ImmersiveSession=le;exports.XR=ie;exports.createFiducialBackend=H;exports.createGeolocationBackend=K;exports.getXRStore=N;exports.subscribeToXRStore=se;exports.useXRStore=E;
|
package/build/index.js
CHANGED
|
@@ -1,468 +1,503 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFrame as
|
|
3
|
-
import { jsx as
|
|
4
|
-
import { ArMarkerControls as D, ArToolkitSource as
|
|
5
|
-
import { Group as
|
|
6
|
-
import
|
|
7
|
-
import { createXRStore as
|
|
8
|
-
const
|
|
9
|
-
let
|
|
10
|
-
const n = /* @__PURE__ */ new Set(),
|
|
11
|
-
const
|
|
12
|
-
if (!Object.is(
|
|
13
|
-
const
|
|
14
|
-
|
|
1
|
+
import v, { useRef as w, useEffect as x, useState as B, useCallback as P, useMemo as q } from "react";
|
|
2
|
+
import { useFrame as L, useThree as j, createPortal as K } from "@react-three/fiber";
|
|
3
|
+
import { jsx as F } from "react/jsx-runtime";
|
|
4
|
+
import { ArMarkerControls as D, ArToolkitSource as Q, ArToolkitContext as V } from "@ar-js-org/ar.js/three.js/build/ar-threex";
|
|
5
|
+
import { Group as Y } from "three";
|
|
6
|
+
import { LocationBased as $, Webcam as J, DeviceOrientationControls as Z } from "locar";
|
|
7
|
+
import { createXRStore as _, XR as ee } from "@react-three/xr";
|
|
8
|
+
const N = (t) => {
|
|
9
|
+
let e;
|
|
10
|
+
const n = /* @__PURE__ */ new Set(), r = (a, d) => {
|
|
11
|
+
const s = typeof a == "function" ? a(e) : a;
|
|
12
|
+
if (!Object.is(s, e)) {
|
|
13
|
+
const A = e;
|
|
14
|
+
e = d ?? (typeof s != "object" || s === null) ? s : Object.assign({}, e, s), n.forEach((m) => m(e, A));
|
|
15
15
|
}
|
|
16
|
-
},
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
function
|
|
20
|
-
const n =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
}, i = () => e, c = { setState: r, getState: i, getInitialState: () => u, subscribe: (a) => (n.add(a), () => n.delete(a)) }, u = e = t(r, i, c);
|
|
17
|
+
return c;
|
|
18
|
+
}, te = ((t) => t ? N(t) : N), ne = (t) => t;
|
|
19
|
+
function re(t, e = ne) {
|
|
20
|
+
const n = v.useSyncExternalStore(
|
|
21
|
+
t.subscribe,
|
|
22
|
+
v.useCallback(() => e(t.getState()), [t, e]),
|
|
23
|
+
v.useCallback(() => e(t.getInitialState()), [t, e])
|
|
24
24
|
);
|
|
25
|
-
return
|
|
25
|
+
return v.useDebugValue(n), n;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
return Object.assign(n,
|
|
30
|
-
},
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
let a =
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
a = (
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
const
|
|
41
|
-
|
|
27
|
+
const oe = (t) => {
|
|
28
|
+
const e = te(t), n = (r) => re(e, r);
|
|
29
|
+
return Object.assign(n, e), n;
|
|
30
|
+
}, ie = ((t) => oe), se = (t) => (e, n, r) => {
|
|
31
|
+
const i = r.subscribe;
|
|
32
|
+
return r.subscribe = ((l, c, u) => {
|
|
33
|
+
let a = l;
|
|
34
|
+
if (c) {
|
|
35
|
+
const d = u?.equalityFn || Object.is;
|
|
36
|
+
let s = l(r.getState());
|
|
37
|
+
a = (A) => {
|
|
38
|
+
const m = l(A);
|
|
39
|
+
if (!d(s, m)) {
|
|
40
|
+
const f = s;
|
|
41
|
+
c(s = m, f);
|
|
42
42
|
}
|
|
43
|
-
}, u?.fireImmediately &&
|
|
43
|
+
}, u?.fireImmediately && c(s, s);
|
|
44
44
|
}
|
|
45
|
-
return
|
|
46
|
-
}), e
|
|
47
|
-
},
|
|
45
|
+
return i(a);
|
|
46
|
+
}), t(e, n, r);
|
|
47
|
+
}, ce = se, X = (t) => Symbol.iterator in t, U = (t) => (
|
|
48
|
+
// HACK: avoid checking entries type
|
|
49
|
+
"entries" in t
|
|
50
|
+
), H = (t, e) => {
|
|
51
|
+
const n = t instanceof Map ? t : new Map(t.entries()), r = e instanceof Map ? e : new Map(e.entries());
|
|
52
|
+
if (n.size !== r.size)
|
|
53
|
+
return !1;
|
|
54
|
+
for (const [i, o] of n)
|
|
55
|
+
if (!r.has(i) || !Object.is(o, r.get(i)))
|
|
56
|
+
return !1;
|
|
57
|
+
return !0;
|
|
58
|
+
}, ae = (t, e) => {
|
|
59
|
+
const n = t[Symbol.iterator](), r = e[Symbol.iterator]();
|
|
60
|
+
let i = n.next(), o = r.next();
|
|
61
|
+
for (; !i.done && !o.done; ) {
|
|
62
|
+
if (!Object.is(i.value, o.value))
|
|
63
|
+
return !1;
|
|
64
|
+
i = n.next(), o = r.next();
|
|
65
|
+
}
|
|
66
|
+
return !!i.done && !!o.done;
|
|
67
|
+
};
|
|
68
|
+
function le(t, e) {
|
|
69
|
+
return Object.is(t, e) ? !0 : typeof t != "object" || t === null || typeof e != "object" || e === null || Object.getPrototypeOf(t) !== Object.getPrototypeOf(e) ? !1 : X(t) && X(e) ? U(t) && U(e) ? H(t, e) : ae(t, e) : H(
|
|
70
|
+
{ entries: () => Object.entries(t) },
|
|
71
|
+
{ entries: () => Object.entries(e) }
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function ue(t) {
|
|
75
|
+
const e = v.useRef(void 0);
|
|
76
|
+
return (n) => {
|
|
77
|
+
const r = t(n);
|
|
78
|
+
return le(e.current, r) ? e.current : e.current = r;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const S = {
|
|
48
82
|
FIDUCIAL: "FiducialSession",
|
|
49
83
|
GEOLOCATION: "GeolocationSession",
|
|
50
84
|
IMMERSIVE: "ImmersiveSession"
|
|
51
|
-
}, G =
|
|
52
|
-
|
|
85
|
+
}, G = ie()(
|
|
86
|
+
ce((t, e) => ({
|
|
53
87
|
// initial state
|
|
54
88
|
video: null,
|
|
55
89
|
backends: [],
|
|
56
90
|
sessionTypes: /* @__PURE__ */ new Set(),
|
|
57
91
|
immersiveStore: null,
|
|
58
92
|
// actions
|
|
59
|
-
registerBackend: async (n,
|
|
93
|
+
registerBackend: async (n, r, i) => {
|
|
60
94
|
try {
|
|
61
|
-
if (
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
const a = `❌ [RDK] INCOMPATIBLE SESSIONS: ${
|
|
95
|
+
if (i) {
|
|
96
|
+
const o = e(), l = /* @__PURE__ */ new Set([...o.sessionTypes, i]), c = l.has(S.FIDUCIAL), u = l.has(S.GEOLOCATION);
|
|
97
|
+
if (c && u) {
|
|
98
|
+
const a = `❌ [RDK] INCOMPATIBLE SESSIONS: ${S.FIDUCIAL} and ${S.GEOLOCATION} cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.`;
|
|
65
99
|
throw console.error(a), new Error(a);
|
|
66
100
|
}
|
|
67
|
-
|
|
68
|
-
sessionTypes:
|
|
101
|
+
t(() => ({
|
|
102
|
+
sessionTypes: l
|
|
69
103
|
}));
|
|
70
104
|
}
|
|
71
105
|
await n.init({
|
|
72
|
-
scene:
|
|
73
|
-
camera:
|
|
74
|
-
renderer:
|
|
75
|
-
}),
|
|
76
|
-
backends: [...
|
|
106
|
+
scene: r.scene,
|
|
107
|
+
camera: r.camera,
|
|
108
|
+
renderer: r.renderer
|
|
109
|
+
}), t((o) => ({
|
|
110
|
+
backends: [...o.backends, n]
|
|
77
111
|
}));
|
|
78
|
-
} catch (
|
|
79
|
-
throw console.error("[XRStore] Failed to register backend:",
|
|
112
|
+
} catch (o) {
|
|
113
|
+
throw console.error("[XRStore] Failed to register backend:", o), o;
|
|
80
114
|
}
|
|
81
115
|
},
|
|
82
|
-
unregisterBackend: (n,
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const
|
|
116
|
+
unregisterBackend: (n, r) => {
|
|
117
|
+
t((i) => {
|
|
118
|
+
const o = new Set(i.sessionTypes);
|
|
119
|
+
r && o.delete(r);
|
|
120
|
+
const l = i.backends.filter((c) => c !== n);
|
|
87
121
|
try {
|
|
88
122
|
n.dispose?.();
|
|
89
|
-
} catch (
|
|
90
|
-
console.error("[XRStore] Error disposing backend:",
|
|
123
|
+
} catch (c) {
|
|
124
|
+
console.error("[XRStore] Error disposing backend:", c);
|
|
91
125
|
}
|
|
92
126
|
return {
|
|
93
|
-
backends:
|
|
94
|
-
sessionTypes:
|
|
127
|
+
backends: l,
|
|
128
|
+
sessionTypes: o
|
|
95
129
|
};
|
|
96
130
|
});
|
|
97
131
|
},
|
|
98
132
|
setVideo: (n) => {
|
|
99
|
-
|
|
133
|
+
t({ video: n });
|
|
100
134
|
},
|
|
101
135
|
updateBackends: (n) => {
|
|
102
|
-
const { backends:
|
|
103
|
-
|
|
136
|
+
const { backends: r } = e();
|
|
137
|
+
r.forEach((i) => {
|
|
104
138
|
try {
|
|
105
|
-
|
|
106
|
-
} catch (
|
|
107
|
-
console.error("[XRStore] Backend update error:",
|
|
139
|
+
i.update?.(n);
|
|
140
|
+
} catch (o) {
|
|
141
|
+
console.error("[XRStore] Backend update error:", o);
|
|
108
142
|
}
|
|
109
143
|
});
|
|
110
144
|
},
|
|
111
145
|
setImmersiveStore: (n) => {
|
|
112
|
-
|
|
146
|
+
t({ immersiveStore: n });
|
|
113
147
|
}
|
|
114
148
|
}))
|
|
115
|
-
),
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
149
|
+
), de = () => G.getState(), ke = G.subscribe, T = (t) => G(
|
|
150
|
+
ue((n) => {
|
|
151
|
+
const r = {
|
|
152
|
+
...n,
|
|
153
|
+
isImmersive: n.sessionTypes.has(S.IMMERSIVE),
|
|
154
|
+
immersive: n.immersiveStore || null
|
|
155
|
+
};
|
|
156
|
+
return t ? t(r) : r;
|
|
157
|
+
})
|
|
158
|
+
), Ee = ({ children: t }) => {
|
|
159
|
+
const { updateBackends: e } = T();
|
|
160
|
+
return L((n, r) => {
|
|
161
|
+
e(r);
|
|
162
|
+
}), t;
|
|
163
|
+
}, Re = ({
|
|
164
|
+
patternUrl: t,
|
|
165
|
+
barcodeValue: e,
|
|
130
166
|
params: n,
|
|
131
|
-
onMarkerFound:
|
|
132
|
-
onMarkerLost:
|
|
133
|
-
children:
|
|
167
|
+
onMarkerFound: r,
|
|
168
|
+
onMarkerLost: i,
|
|
169
|
+
children: o
|
|
134
170
|
}) => {
|
|
135
|
-
const
|
|
136
|
-
return
|
|
137
|
-
let
|
|
171
|
+
const l = w(null), c = T((s) => s.backends), u = w(!1), a = w(!1), d = w(null);
|
|
172
|
+
return x(() => {
|
|
173
|
+
let s = !1;
|
|
138
174
|
return (async () => {
|
|
139
175
|
try {
|
|
140
|
-
const
|
|
141
|
-
if (!
|
|
142
|
-
const
|
|
143
|
-
if (!
|
|
144
|
-
if (
|
|
176
|
+
const m = c.find((h) => h.getInternal?.()?.arContext);
|
|
177
|
+
if (!m || s) return;
|
|
178
|
+
const g = m.getInternal?.()?.arContext, y = l.current;
|
|
179
|
+
if (!g || !y) return;
|
|
180
|
+
if (y.visible = !1, a.current = !1, !g.arController) {
|
|
145
181
|
requestAnimationFrame(() => {
|
|
146
|
-
if (!
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
149
|
-
const
|
|
150
|
-
type:
|
|
151
|
-
patternUrl:
|
|
152
|
-
barcodeValue:
|
|
182
|
+
if (!l.current || s) return;
|
|
183
|
+
const I = m.getInternal?.()?.arContext;
|
|
184
|
+
if (!I?.arController) return;
|
|
185
|
+
const b = new D(I, l.current, {
|
|
186
|
+
type: t ? "pattern" : e ? "barcode" : "unknown",
|
|
187
|
+
patternUrl: t,
|
|
188
|
+
barcodeValue: e,
|
|
153
189
|
...n
|
|
154
190
|
});
|
|
155
|
-
|
|
191
|
+
d.current = b, a.current = !0;
|
|
156
192
|
});
|
|
157
193
|
return;
|
|
158
194
|
}
|
|
159
|
-
const
|
|
160
|
-
type:
|
|
161
|
-
patternUrl:
|
|
162
|
-
barcodeValue:
|
|
195
|
+
const E = new D(g, y, {
|
|
196
|
+
type: t ? "pattern" : e ? "barcode" : "unknown",
|
|
197
|
+
patternUrl: t,
|
|
198
|
+
barcodeValue: e,
|
|
163
199
|
...n
|
|
164
200
|
});
|
|
165
|
-
|
|
166
|
-
} catch (
|
|
167
|
-
console.error("Failed to initialize fiducial backend:",
|
|
201
|
+
d.current = E, a.current = !0;
|
|
202
|
+
} catch (m) {
|
|
203
|
+
console.error("Failed to initialize fiducial backend:", m);
|
|
168
204
|
}
|
|
169
205
|
})(), () => {
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
typeof
|
|
206
|
+
s = !0;
|
|
207
|
+
const m = d.current;
|
|
208
|
+
typeof m?.dispose == "function" && m.dispose(), a.current = !1;
|
|
173
209
|
};
|
|
174
|
-
}, [
|
|
175
|
-
const
|
|
176
|
-
if (!
|
|
177
|
-
|
|
210
|
+
}, [c, t, e, n]), L(() => {
|
|
211
|
+
const s = l.current;
|
|
212
|
+
if (!s || !a.current) {
|
|
213
|
+
s && (s.visible = !1);
|
|
178
214
|
return;
|
|
179
215
|
}
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
}), /* @__PURE__ */
|
|
216
|
+
const A = s.visible;
|
|
217
|
+
A && !u.current ? (u.current = !0, r?.()) : !A && u.current && (u.current = !1, i?.());
|
|
218
|
+
}), /* @__PURE__ */ F(
|
|
183
219
|
"group",
|
|
184
220
|
{
|
|
185
|
-
ref:
|
|
221
|
+
ref: l,
|
|
186
222
|
visible: !1,
|
|
187
|
-
children:
|
|
223
|
+
children: o
|
|
188
224
|
}
|
|
189
225
|
);
|
|
190
|
-
},
|
|
191
|
-
const { scene: n, camera:
|
|
192
|
-
return
|
|
193
|
-
if (
|
|
194
|
-
let
|
|
226
|
+
}, Ae = ({ options: t = {}, children: e }) => {
|
|
227
|
+
const { scene: n, camera: r, gl: i } = j(), { registerBackend: o, unregisterBackend: l } = T(), c = w(null), u = w(t);
|
|
228
|
+
return u.current = t, x(() => {
|
|
229
|
+
if (c.current) return;
|
|
230
|
+
let a = !1;
|
|
195
231
|
return (async () => {
|
|
196
232
|
try {
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
await
|
|
200
|
-
|
|
201
|
-
{ scene: n, camera:
|
|
202
|
-
|
|
203
|
-
),
|
|
204
|
-
} catch (
|
|
205
|
-
console.error("[FiducialSession] Failed to initialize:",
|
|
233
|
+
const s = fe(u.current);
|
|
234
|
+
if (a) return;
|
|
235
|
+
await o(
|
|
236
|
+
s,
|
|
237
|
+
{ scene: n, camera: r, renderer: i },
|
|
238
|
+
S.FIDUCIAL
|
|
239
|
+
), c.current = s;
|
|
240
|
+
} catch (s) {
|
|
241
|
+
console.error("[FiducialSession] Failed to initialize:", s);
|
|
206
242
|
}
|
|
207
243
|
})(), () => {
|
|
208
|
-
|
|
244
|
+
a = !0, c.current && (l(c.current, S.FIDUCIAL), c.current = null);
|
|
209
245
|
};
|
|
210
|
-
}, [n,
|
|
246
|
+
}, [n, r, i, o, l]), e;
|
|
211
247
|
};
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
let
|
|
248
|
+
Ae.sessionType = "FiducialSession";
|
|
249
|
+
const fe = (t) => {
|
|
250
|
+
let e = null, n = null, r = null, i;
|
|
215
251
|
return {
|
|
216
|
-
async init({ camera:
|
|
217
|
-
|
|
218
|
-
sourceType:
|
|
219
|
-
}), await new Promise((a,
|
|
220
|
-
const
|
|
221
|
-
|
|
252
|
+
async init({ camera: o, renderer: l }) {
|
|
253
|
+
e = new Q({
|
|
254
|
+
sourceType: t?.sourceType ?? "webcam"
|
|
255
|
+
}), await new Promise((a, d) => {
|
|
256
|
+
const s = setTimeout(() => {
|
|
257
|
+
d(new Error("AR source initialization timeout"));
|
|
222
258
|
}, 1e4);
|
|
223
|
-
|
|
224
|
-
clearTimeout(
|
|
225
|
-
const
|
|
226
|
-
|
|
259
|
+
e.init(() => {
|
|
260
|
+
clearTimeout(s);
|
|
261
|
+
const A = e.domElement;
|
|
262
|
+
A && (A.style.position = "fixed", A.style.top = "0", A.style.left = "0", A.style.width = "100vw", A.style.height = "100vh", A.style.objectFit = "cover", A.style.zIndex = "-1", A.style.pointerEvents = "none"), a();
|
|
227
263
|
});
|
|
228
264
|
});
|
|
229
|
-
const
|
|
230
|
-
cameraParametersUrl:
|
|
265
|
+
const c = {
|
|
266
|
+
cameraParametersUrl: t?.cameraParametersUrl ?? // default to internal camera parameters
|
|
231
267
|
new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
|
|
232
|
-
detectionMode:
|
|
233
|
-
patternRatio:
|
|
234
|
-
matrixCodeType:
|
|
268
|
+
detectionMode: t?.detectionMode ?? "mono",
|
|
269
|
+
patternRatio: t?.patternRatio ?? 0.5,
|
|
270
|
+
matrixCodeType: t?.matrixCodeType ?? "3x3"
|
|
235
271
|
};
|
|
236
|
-
n = new
|
|
272
|
+
n = new V(c), r = o;
|
|
237
273
|
const u = () => {
|
|
238
|
-
|
|
239
|
-
const a = window.innerWidth,
|
|
240
|
-
|
|
274
|
+
e.onResizeElement();
|
|
275
|
+
const a = window.innerWidth, d = window.innerHeight;
|
|
276
|
+
l.setSize(a, d, !1), e.copyElementSizeTo(l.domElement), n?.arController && e.copyElementSizeTo(n.arController.canvas);
|
|
241
277
|
};
|
|
242
|
-
await new Promise((a,
|
|
243
|
-
const
|
|
244
|
-
|
|
278
|
+
await new Promise((a, d) => {
|
|
279
|
+
const s = setTimeout(() => {
|
|
280
|
+
d(new Error("AR context initialization timeout"));
|
|
245
281
|
}, 1e4);
|
|
246
282
|
n.init(() => {
|
|
247
|
-
clearTimeout(
|
|
283
|
+
clearTimeout(s);
|
|
248
284
|
try {
|
|
249
|
-
|
|
250
|
-
} catch (
|
|
251
|
-
|
|
285
|
+
o.projectionMatrix.copy(n.getProjectionMatrix()), u(), a();
|
|
286
|
+
} catch (A) {
|
|
287
|
+
d(A);
|
|
252
288
|
}
|
|
253
289
|
});
|
|
254
|
-
}),
|
|
290
|
+
}), window.addEventListener("resize", u), i = u;
|
|
255
291
|
},
|
|
256
292
|
update() {
|
|
257
|
-
|
|
258
|
-
if (!(!i || !s) && i.ready !== !1 && i.domElement)
|
|
293
|
+
if (!(!e || !n) && !(!e.ready || !e.domElement))
|
|
259
294
|
try {
|
|
260
|
-
|
|
261
|
-
} catch (
|
|
262
|
-
console.warn("AR.js update error:",
|
|
295
|
+
n.update(e.domElement), r && n.getProjectionMatrix && r.projectionMatrix.copy(n.getProjectionMatrix());
|
|
296
|
+
} catch (o) {
|
|
297
|
+
console.warn("AR.js update error:", o);
|
|
263
298
|
}
|
|
264
299
|
},
|
|
265
300
|
dispose() {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const r = i.domElement.parentNode;
|
|
270
|
-
r && r.removeChild(i.domElement);
|
|
301
|
+
if (i && (window.removeEventListener("resize", i), i = void 0), n && typeof n.dispose == "function" && n.dispose(), e?.domElement) {
|
|
302
|
+
const o = e.domElement.parentNode;
|
|
303
|
+
o && o.removeChild(e.domElement);
|
|
271
304
|
}
|
|
272
|
-
|
|
305
|
+
e = null, n = null, r = null;
|
|
273
306
|
},
|
|
274
307
|
getInternal() {
|
|
275
308
|
return {
|
|
276
|
-
arSource:
|
|
277
|
-
arContext:
|
|
309
|
+
arSource: e,
|
|
310
|
+
arContext: n
|
|
278
311
|
};
|
|
279
312
|
}
|
|
280
313
|
};
|
|
281
314
|
}, k = /* @__PURE__ */ new Map();
|
|
282
|
-
let
|
|
283
|
-
const
|
|
284
|
-
latitude:
|
|
285
|
-
longitude:
|
|
315
|
+
let M = !1, O = null, C = null;
|
|
316
|
+
const Oe = ({
|
|
317
|
+
latitude: t,
|
|
318
|
+
longitude: e,
|
|
286
319
|
altitude: n = 0,
|
|
287
|
-
isBillboard:
|
|
288
|
-
onAttach:
|
|
289
|
-
onGpsUpdate:
|
|
290
|
-
children:
|
|
320
|
+
isBillboard: r = !0,
|
|
321
|
+
onAttach: i,
|
|
322
|
+
onGpsUpdate: o,
|
|
323
|
+
children: l
|
|
291
324
|
}) => {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
}, [
|
|
295
|
-
(
|
|
296
|
-
|
|
325
|
+
const c = T((f) => f.backends), { camera: u } = j(), [a] = B(() => new Y()), [d] = B(() => Math.random().toString(36).slice(2, 11)), s = w(!1), A = P(() => {
|
|
326
|
+
i?.();
|
|
327
|
+
}, [i]), m = P(
|
|
328
|
+
(f, g) => {
|
|
329
|
+
o?.(f, g);
|
|
297
330
|
},
|
|
298
|
-
[
|
|
331
|
+
[o]
|
|
299
332
|
);
|
|
300
|
-
return
|
|
301
|
-
let
|
|
333
|
+
return x(() => {
|
|
334
|
+
let f = !1;
|
|
302
335
|
return (async () => {
|
|
303
336
|
try {
|
|
304
|
-
const
|
|
305
|
-
if (!
|
|
306
|
-
const
|
|
307
|
-
if (!
|
|
308
|
-
const
|
|
337
|
+
const y = c.find((p) => p.getInternal?.()?.locar);
|
|
338
|
+
if (!y || f) return;
|
|
339
|
+
const h = y.getInternal?.()?.locar;
|
|
340
|
+
if (!h) return;
|
|
341
|
+
const I = (p) => {
|
|
309
342
|
try {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
),
|
|
316
|
-
} catch (
|
|
317
|
-
console.error("❌ Failed to attach anchor:",
|
|
343
|
+
h.add(
|
|
344
|
+
p.anchor,
|
|
345
|
+
p.longitude,
|
|
346
|
+
p.latitude,
|
|
347
|
+
p.altitude
|
|
348
|
+
), p.isAttached = !0, p.onAttach?.();
|
|
349
|
+
} catch (R) {
|
|
350
|
+
console.error("❌ Failed to attach anchor:", R);
|
|
318
351
|
}
|
|
319
|
-
},
|
|
352
|
+
}, b = {
|
|
320
353
|
anchor: a,
|
|
321
354
|
isAttached: !1,
|
|
322
|
-
latitude:
|
|
323
|
-
longitude:
|
|
355
|
+
latitude: t,
|
|
356
|
+
longitude: e,
|
|
324
357
|
altitude: n || 0,
|
|
325
|
-
onAttach:
|
|
326
|
-
onGpsUpdate:
|
|
358
|
+
onAttach: A,
|
|
359
|
+
onGpsUpdate: m
|
|
327
360
|
};
|
|
328
|
-
k.set(
|
|
329
|
-
position:
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
361
|
+
if (k.set(d, b), !M) {
|
|
362
|
+
C = ({ position: R, distMoved: W }) => {
|
|
363
|
+
O = R, k.forEach((z) => {
|
|
364
|
+
z.isAttached || I(z), z.onGpsUpdate?.(R, W);
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
const p = h.getLastKnownLocation();
|
|
368
|
+
p !== null && (O = {
|
|
369
|
+
coords: {
|
|
370
|
+
longitude: p.longitude,
|
|
371
|
+
latitude: p.latitude,
|
|
372
|
+
accuracy: 0,
|
|
373
|
+
altitude: null,
|
|
374
|
+
altitudeAccuracy: null,
|
|
375
|
+
heading: null,
|
|
376
|
+
speed: null,
|
|
377
|
+
toJSON: () => p
|
|
378
|
+
},
|
|
379
|
+
timestamp: Date.now(),
|
|
380
|
+
toJSON: () => p
|
|
381
|
+
}), O !== null && !b.isAttached && I(b), h.on?.("gpsupdate", C), M = !0;
|
|
382
|
+
}
|
|
383
|
+
O !== null && (b.isAttached || I(b), b.onGpsUpdate?.(O, 0)), s.current = !1;
|
|
384
|
+
} catch (y) {
|
|
385
|
+
console.error("Failed to initialize geolocation backend:", y);
|
|
338
386
|
}
|
|
339
387
|
})(), () => {
|
|
340
|
-
if (
|
|
388
|
+
if (f = !0, k.get(d)?.isAttached)
|
|
341
389
|
try {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
console.error(`⚠️ Error removing anchor ${l}:`, I);
|
|
390
|
+
a.removeFromParent();
|
|
391
|
+
} catch (E) {
|
|
392
|
+
console.error(`⚠️ Error removing anchor ${d}:`, E);
|
|
346
393
|
}
|
|
347
|
-
k.delete(
|
|
394
|
+
k.delete(d), k.size === 0 && C && (c.find((b) => b.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate", C), C = null, M = !1);
|
|
348
395
|
};
|
|
349
396
|
}, [
|
|
350
|
-
|
|
397
|
+
c,
|
|
351
398
|
a,
|
|
352
|
-
|
|
353
|
-
e,
|
|
399
|
+
d,
|
|
354
400
|
t,
|
|
401
|
+
e,
|
|
355
402
|
n,
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
]),
|
|
359
|
-
!
|
|
360
|
-
}),
|
|
361
|
-
},
|
|
362
|
-
options:
|
|
363
|
-
children:
|
|
403
|
+
A,
|
|
404
|
+
m
|
|
405
|
+
]), L(() => {
|
|
406
|
+
!r || !u || !k.get(d)?.isAttached || a.lookAt(u.position);
|
|
407
|
+
}), K(/* @__PURE__ */ F("group", { children: l }), a);
|
|
408
|
+
}, me = ({
|
|
409
|
+
options: t = {},
|
|
410
|
+
children: e
|
|
364
411
|
}) => {
|
|
365
|
-
const { scene: n, camera:
|
|
366
|
-
return
|
|
367
|
-
if (
|
|
368
|
-
let
|
|
412
|
+
const { scene: n, camera: r, gl: i } = j(), { registerBackend: o, unregisterBackend: l } = T(), c = w(null), u = w(t);
|
|
413
|
+
return u.current = t, x(() => {
|
|
414
|
+
if (c.current) return;
|
|
415
|
+
let a = !1;
|
|
369
416
|
return (async () => {
|
|
370
417
|
try {
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
await
|
|
374
|
-
|
|
375
|
-
{ scene: n, camera:
|
|
376
|
-
|
|
377
|
-
),
|
|
378
|
-
} catch (
|
|
379
|
-
console.error("[GeolocationSession] Failed to initialize:",
|
|
418
|
+
const s = pe(u.current);
|
|
419
|
+
if (a) return;
|
|
420
|
+
await o(
|
|
421
|
+
s,
|
|
422
|
+
{ scene: n, camera: r, renderer: i },
|
|
423
|
+
S.GEOLOCATION
|
|
424
|
+
), c.current = s;
|
|
425
|
+
} catch (s) {
|
|
426
|
+
console.error("[GeolocationSession] Failed to initialize:", s);
|
|
380
427
|
}
|
|
381
428
|
})(), () => {
|
|
382
|
-
|
|
429
|
+
a = !0, c.current && (l(c.current, S.GEOLOCATION), c.current = null);
|
|
383
430
|
};
|
|
384
|
-
}, [n,
|
|
431
|
+
}, [n, r, i, o, l]), e;
|
|
385
432
|
};
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
let
|
|
433
|
+
me.sessionType = "GeolocationSession";
|
|
434
|
+
const pe = (t) => {
|
|
435
|
+
let e = null, n = null, r = null, i, o = null, l = null, c = null, u = null;
|
|
389
436
|
return {
|
|
390
|
-
async init(
|
|
391
|
-
const { camera:
|
|
392
|
-
if (!
|
|
437
|
+
async init(a) {
|
|
438
|
+
const { camera: d, renderer: s, scene: A } = a;
|
|
439
|
+
if (!A)
|
|
393
440
|
throw new Error(
|
|
394
441
|
"[geolocationBackend] A THREE.Scene is required for location-based AR"
|
|
395
442
|
);
|
|
396
|
-
|
|
397
|
-
|
|
443
|
+
l = d, c = s, u = A, e = new $(A, d), n = new J(
|
|
444
|
+
t?.webcamConstraints ?? {
|
|
398
445
|
video: { facingMode: "environment" }
|
|
399
|
-
|
|
400
|
-
null
|
|
401
|
-
), t.on(
|
|
402
|
-
"gpsupdate",
|
|
403
|
-
// TODO remove explicit type annotation once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
|
|
404
|
-
(c) => {
|
|
405
|
-
e.onGpsUpdate?.(c.position, c.distMoved);
|
|
446
|
+
// TODO remove `as any` once fixed upstream (LocAR.js)
|
|
406
447
|
}
|
|
407
|
-
),
|
|
408
|
-
|
|
409
|
-
}), n.on("
|
|
410
|
-
|
|
411
|
-
}),
|
|
412
|
-
|
|
413
|
-
}),
|
|
414
|
-
|
|
415
|
-
}),
|
|
416
|
-
console.error("[geolocationBackend]
|
|
417
|
-
}),
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
448
|
+
), o = (f) => {
|
|
449
|
+
t?.onGpsUpdate?.(f.position, f.distMoved);
|
|
450
|
+
}, e.on("gpsupdate", o), n.on("webcamstarted", (f) => {
|
|
451
|
+
A.background = f.texture;
|
|
452
|
+
}), n.on("webcamerror", (f) => {
|
|
453
|
+
console.error("[geolocationBackend] webcam error:", f);
|
|
454
|
+
}), r = new Z(d), r.on("deviceorientationgranted", (f) => {
|
|
455
|
+
f.target?.connect?.();
|
|
456
|
+
}), r.on("deviceorientationerror", (f) => {
|
|
457
|
+
console.error("[geolocationBackend] Device orientation error:", f);
|
|
458
|
+
}), r.init?.(), e.on("gpserror", (f) => {
|
|
459
|
+
console.error("[geolocationBackend] gps error:", f);
|
|
460
|
+
}), e.startGps(), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" && e.fakeGps(t.fakeLon, t.fakeLat);
|
|
461
|
+
const m = () => {
|
|
462
|
+
if (!c || !l) return;
|
|
463
|
+
const f = window.innerWidth, g = window.innerHeight;
|
|
464
|
+
c.setSize(f, g, !1), l.aspect = f / g, l.updateProjectionMatrix?.();
|
|
422
465
|
};
|
|
423
|
-
|
|
466
|
+
m(), window.addEventListener("resize", m), i = m;
|
|
424
467
|
},
|
|
425
468
|
update() {
|
|
426
|
-
|
|
469
|
+
r?.update?.();
|
|
427
470
|
},
|
|
428
471
|
dispose() {
|
|
429
|
-
|
|
430
|
-
e?.onGpsUpdate && r?.off("gpsupdate", e.onGpsUpdate), r?.stopGps?.(), u?.stop?.(), a?.dispose?.(), A && (window.removeEventListener("resize", A), A = void 0), this._locar = null, this._webcam = null, this._deviceOrientation = null, this._scene = null, this._camera = null;
|
|
472
|
+
e && o && e.off("gpsupdate", o), e?.stopGps?.(), n?.stop?.(), r?.dispose?.(), i && (window.removeEventListener("resize", i), i = void 0), e = null, n = null, r = null, l = null, c = null, u = null, o = null;
|
|
431
473
|
},
|
|
432
|
-
getInternal() {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
deviceOrientation: this._deviceOrientation,
|
|
440
|
-
// biome-ignore lint/suspicious/noExplicitAny: TODO solve once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
|
|
441
|
-
scene: this._scene,
|
|
442
|
-
// biome-ignore lint/suspicious/noExplicitAny: TODO solve once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
|
|
443
|
-
camera: this._camera
|
|
444
|
-
};
|
|
445
|
-
}
|
|
474
|
+
getInternal: () => ({
|
|
475
|
+
locar: e,
|
|
476
|
+
webcam: n,
|
|
477
|
+
deviceOrientation: r,
|
|
478
|
+
scene: u,
|
|
479
|
+
camera: l
|
|
480
|
+
})
|
|
446
481
|
};
|
|
447
|
-
},
|
|
448
|
-
const
|
|
449
|
-
return
|
|
450
|
-
const n =
|
|
451
|
-
return n.sessionTypes.add(
|
|
452
|
-
n.sessionTypes.delete(
|
|
482
|
+
}, Ce = ({ children: t }) => {
|
|
483
|
+
const e = q(() => _(), []);
|
|
484
|
+
return x(() => {
|
|
485
|
+
const n = de();
|
|
486
|
+
return n.sessionTypes.add(S.IMMERSIVE), n.setImmersiveStore(e), () => {
|
|
487
|
+
n.sessionTypes.delete(S.IMMERSIVE), n.setImmersiveStore(null);
|
|
453
488
|
};
|
|
454
|
-
}, [
|
|
489
|
+
}, [e]), /* @__PURE__ */ F(ee, { store: e, children: t });
|
|
455
490
|
};
|
|
456
491
|
export {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
492
|
+
Re as FiducialAnchor,
|
|
493
|
+
Ae as FiducialSession,
|
|
494
|
+
Oe as GeolocationAnchor,
|
|
495
|
+
me as GeolocationSession,
|
|
496
|
+
Ce as ImmersiveSession,
|
|
497
|
+
Ee as XR,
|
|
498
|
+
fe as createFiducialBackend,
|
|
499
|
+
pe as createGeolocationBackend,
|
|
500
|
+
de as getXRStore,
|
|
501
|
+
ke as subscribeToXRStore,
|
|
502
|
+
T as useXRStore
|
|
468
503
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Camera, Scene, WebGLRenderer } from 'three';
|
|
2
2
|
/**
|
|
3
3
|
* Initialization arguments for backends.
|
|
4
4
|
* Contains the Three.js objects required to initialize any backend.
|
|
5
5
|
*/
|
|
6
6
|
export interface BackendInitArgs {
|
|
7
7
|
/** The Three.js scene to render content into. */
|
|
8
|
-
scene:
|
|
8
|
+
scene: Scene;
|
|
9
9
|
/** The Three.js camera used for rendering. */
|
|
10
|
-
camera:
|
|
10
|
+
camera: Camera;
|
|
11
11
|
/** The WebGL renderer instance. */
|
|
12
|
-
renderer:
|
|
12
|
+
renderer: WebGLRenderer;
|
|
13
13
|
}
|
|
14
14
|
//# 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,
|
|
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;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnidotdev/rdk",
|
|
3
3
|
"description": "AR.js with react-three-fiber",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"locar": "0.1.5",
|
|
51
51
|
"react": "^19.2.0",
|
|
52
52
|
"react-dom": "^19.2.0",
|
|
53
|
-
"three": "^0.
|
|
53
|
+
"three": "^0.182.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
56
|
"@ar-js-org/ar.js": {
|
|
@@ -66,27 +66,27 @@
|
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@ar-js-org/ar.js": "^3.4.7",
|
|
68
68
|
"@biomejs/biome": "^2.3.8",
|
|
69
|
-
"@react-three/fiber": "^9.4.
|
|
69
|
+
"@react-three/fiber": "^9.4.2",
|
|
70
70
|
"@testing-library/jest-dom": "^6.9.1",
|
|
71
71
|
"@testing-library/react": "^16.3.0",
|
|
72
|
-
"@types/node": "^
|
|
72
|
+
"@types/node": "^25.0.0",
|
|
73
73
|
"@types/react": "^19.2.7",
|
|
74
74
|
"@types/react-dom": "^19.2.3",
|
|
75
|
-
"@types/three": "^0.
|
|
75
|
+
"@types/three": "^0.182.0",
|
|
76
76
|
"@types/webxr": "^0.5.24",
|
|
77
|
-
"jsdom": "^27.
|
|
78
|
-
"locar": "^0.1.
|
|
79
|
-
"react": "^19.2.
|
|
80
|
-
"react-dom": "^19.2.
|
|
81
|
-
"three": "^0.
|
|
77
|
+
"jsdom": "^27.3.0",
|
|
78
|
+
"locar": "^0.1.7",
|
|
79
|
+
"react": "^19.2.1",
|
|
80
|
+
"react-dom": "^19.2.1",
|
|
81
|
+
"three": "^0.182.0",
|
|
82
82
|
"typescript": "^5.9.3",
|
|
83
|
-
"vite": "^7.2.
|
|
83
|
+
"vite": "^7.2.7",
|
|
84
84
|
"vite-plugin-dts": "^4.5.4",
|
|
85
85
|
"vite-tsconfig-paths": "^5.1.4",
|
|
86
|
-
"vitest": "^4.0.
|
|
86
|
+
"vitest": "^4.0.15"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"ts-pattern": "^5.9.0",
|
|
90
|
-
"zustand": "^5.0.
|
|
90
|
+
"zustand": "^5.0.9"
|
|
91
91
|
}
|
|
92
92
|
}
|