locar 0.2.11 → 0.2.12
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/README.md +1 -1
- package/dist/locar.d.ts +34 -1
- package/dist/locar.es.js +39 -13
- package/dist/locar.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/locar.d.ts
CHANGED
|
@@ -17,13 +17,17 @@ export declare class App extends EventEmitter {
|
|
|
17
17
|
landHeight: number;
|
|
18
18
|
} | null; /** camera feed dimensions in LANDSCAPE */
|
|
19
19
|
origHfov: number;
|
|
20
|
+
dimensionsProvider?: () => {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
20
24
|
/**
|
|
21
25
|
* Create an App object.
|
|
22
26
|
* @param {AppOptions} - Startup options.
|
|
23
27
|
* Note that you can only specify ONE of cameraOptions and threeObjects, as cameraOptions is intended to configure a new three.js camera,
|
|
24
28
|
* while threeObjects allows you to specify an existing camera, renderer and scene.
|
|
25
29
|
*/
|
|
26
|
-
constructor({ cameraOptions, canvas, gpsOptions, videoConstraints, deviceOrientationOptions, serverLogger, projection, threeObjects }: AppOptions);
|
|
30
|
+
constructor({ cameraOptions, canvas, gpsOptions, videoConstraints, deviceOrientationOptions, serverLogger, projection, threeObjects, dimensionsProvider }: AppOptions);
|
|
27
31
|
/**
|
|
28
32
|
* Start the app.
|
|
29
33
|
* Must be called after construction.
|
|
@@ -94,6 +98,11 @@ export declare interface BasicAppOptions {
|
|
|
94
98
|
serverLogger?: ServerLogger;
|
|
95
99
|
/** Existing three.js objects, set up elsewhere - e.g. react-three-fiber */
|
|
96
100
|
threeObjects?: ThreeObjects;
|
|
101
|
+
/** Optional function which provides canvas/screen dimensions in cases where we do not wish to use window width/height */
|
|
102
|
+
dimensionsProvider?: () => {
|
|
103
|
+
width: number;
|
|
104
|
+
height: number;
|
|
105
|
+
};
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
/**
|
|
@@ -359,6 +368,30 @@ export declare class LocAR extends EventEmitter {
|
|
|
359
368
|
* @return {Object} object containing latitude and longitude fields, or null if no previous GPS location.
|
|
360
369
|
*/
|
|
361
370
|
getLastKnownLocation(): LonLat | null;
|
|
371
|
+
/**
|
|
372
|
+
* Accurate hfov -> vfov coversion.
|
|
373
|
+
* @param {number} hfov The horizontal field of view in degrees
|
|
374
|
+
* @param {number} aspect The aspect ratio
|
|
375
|
+
* @returns {number} The vertical field of view in degrees
|
|
376
|
+
* See https://wojtsterna.com/2024/01/09/field-of-view-horizontal-and-vertical-conversion/
|
|
377
|
+
*/
|
|
378
|
+
static htov(hfov: number, aspect: number): number;
|
|
379
|
+
/**
|
|
380
|
+
* Accurate vfov -> hfov coversion.
|
|
381
|
+
* @param {number} vfov The vertical field of view in degrees
|
|
382
|
+
* @param {number} aspect The aspect ratio
|
|
383
|
+
* @returns {number} The horizontal field of view in degrees
|
|
384
|
+
* See https://wojtsterna.com/2024/01/09/field-of-view-horizontal-and-vertical-conversion/
|
|
385
|
+
*/
|
|
386
|
+
static vtoh(vfov: number, aspect: number): number;
|
|
387
|
+
/**
|
|
388
|
+
* Scale a fov angle correctly according to changes in e.g. screen width or height
|
|
389
|
+
* @param {number} origAngleDeg The original angle in degrees
|
|
390
|
+
* @param {number} ratioOfFinalToOriginalDistances ratio of the final screen dimension to the original screen dimension
|
|
391
|
+
* @returns {number} The correctly scaled angle
|
|
392
|
+
* See https://wojtsterna.com/2024/01/09/field-of-view-horizontal-and-vertical-conversion/
|
|
393
|
+
*/
|
|
394
|
+
static fovScale(origAngleDeg: number, ratioOfFinalToOriginalDistances: number): number;
|
|
362
395
|
}
|
|
363
396
|
|
|
364
397
|
/** Longitude and latitude. */
|
package/dist/locar.es.js
CHANGED
|
@@ -19,22 +19,23 @@ var o = class {
|
|
|
19
19
|
}
|
|
20
20
|
}, s = class extends o {
|
|
21
21
|
#e;
|
|
22
|
-
constructor({ cameraOptions: t, canvas: n, gpsOptions: r, videoConstraints: i, deviceOrientationOptions: a, serverLogger: o, projection: s, threeObjects: c }) {
|
|
22
|
+
constructor({ cameraOptions: t, canvas: n, gpsOptions: r, videoConstraints: i, deviceOrientationOptions: a, serverLogger: o, projection: s, threeObjects: c, dimensionsProvider: u }) {
|
|
23
23
|
if (c && t) throw Error("LocAR.App: ERROR: can only specify one of cameraOptions and threeObjects");
|
|
24
|
-
super();
|
|
25
|
-
let
|
|
26
|
-
this.origHfov = c?.camera ? c.camera.fov
|
|
24
|
+
super(), this.dimensionsProvider = u;
|
|
25
|
+
let { width: d, height: f } = this.#t(), p = d / f;
|
|
26
|
+
this.origHfov = c?.camera ? l.vtoh(c.camera.fov, p) : t?.hFov || 80, this.cameraFeedDimensions = null, this.camera = c?.camera || new e.PerspectiveCamera(l.htov(this.origHfov, p), p, t?.near || .001, t?.far || 1e3), this.scene = c?.scene || new e.Scene(), c ? this.renderer = c.renderer : (n ? (this.renderer = new e.WebGLRenderer({
|
|
27
27
|
canvas: n,
|
|
28
28
|
alpha: !0
|
|
29
|
-
}), this.renderer.setClearColor(65280, 0)) : (this.renderer = new e.WebGLRenderer({ alpha: !0 }), this.renderer.setClearColor(65280, 0), this.renderer.domElement.style.position = "relative", this.renderer.domElement.style.zIndex = "999", document.body.appendChild(this.renderer.domElement)), this.renderer.setSize(
|
|
29
|
+
}), this.renderer.setClearColor(65280, 0)) : (this.renderer = new e.WebGLRenderer({ alpha: !0 }), this.renderer.setClearColor(65280, 0), this.renderer.domElement.style.position = "relative", this.renderer.domElement.style.zIndex = "999", document.body.appendChild(this.renderer.domElement)), this.renderer.setSize(d, f), this.renderer.setAnimationLoop(() => {
|
|
30
30
|
this.deviceOrientationControls?.update(), this.renderer.render(this.scene, this.camera);
|
|
31
31
|
let e = this.#e?.raycast(this.camera, this.scene) ?? [];
|
|
32
32
|
e.length > 0 && this.emit("objectsIntersected", { intersections: e });
|
|
33
33
|
}), window.addEventListener("resize", () => {
|
|
34
|
-
|
|
34
|
+
let { width: e, height: t } = this.#t();
|
|
35
|
+
this.renderer.setSize(e, t), this.camera.aspect = e / t, this.syncFovWithWebcam(this.camera.aspect);
|
|
35
36
|
}));
|
|
36
|
-
let
|
|
37
|
-
this.locar = new l(this.scene, this.camera, r, o, s), this.webcam = new w(i), this.deviceOrientationControls =
|
|
37
|
+
let m = a || { enabled: !0 };
|
|
38
|
+
this.locar = new l(this.scene, this.camera, r, o, s), this.webcam = new w(i), this.deviceOrientationControls = m.enabled === !0 ? new S(this.camera, m) : null, this.#e = null;
|
|
38
39
|
}
|
|
39
40
|
start() {
|
|
40
41
|
return new Promise((e, t) => {
|
|
@@ -43,7 +44,13 @@ var o = class {
|
|
|
43
44
|
this.cameraFeedDimensions = {
|
|
44
45
|
landWidth: t ? e.videoWidth : e.videoHeight,
|
|
45
46
|
landHeight: t ? e.videoHeight : e.videoWidth
|
|
46
|
-
}
|
|
47
|
+
};
|
|
48
|
+
let { width: n, height: r } = this.#t();
|
|
49
|
+
this.matchFovToWebcam(e.videoWidth, e.videoHeight, n / r), this.camera.updateProjectionMatrix(), this.emit("webcamstarted", {
|
|
50
|
+
...e,
|
|
51
|
+
landVideoWidth: this.cameraFeedDimensions.landWidth,
|
|
52
|
+
landVideoHeight: this.cameraFeedDimensions.landHeight
|
|
53
|
+
});
|
|
47
54
|
}), this.webcam.on("webcamerror", (e) => {
|
|
48
55
|
t({
|
|
49
56
|
code: e.code,
|
|
@@ -60,7 +67,11 @@ var o = class {
|
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
syncFovWithWebcam(e) {
|
|
63
|
-
if (e === void 0
|
|
70
|
+
if (e === void 0) {
|
|
71
|
+
let { width: t, height: n } = this.#t();
|
|
72
|
+
e = t / n;
|
|
73
|
+
}
|
|
74
|
+
if (this.cameraFeedDimensions !== null) {
|
|
64
75
|
let t = e > 1 ? this.cameraFeedDimensions.landWidth : this.cameraFeedDimensions.landHeight, n = e > 1 ? this.cameraFeedDimensions.landHeight : this.cameraFeedDimensions.landWidth;
|
|
65
76
|
this.matchFovToWebcam(t, n, e);
|
|
66
77
|
}
|
|
@@ -68,13 +79,19 @@ var o = class {
|
|
|
68
79
|
}
|
|
69
80
|
matchFovToWebcam(e, t, n) {
|
|
70
81
|
if (n < e / t) {
|
|
71
|
-
let r
|
|
72
|
-
this.camera.fov =
|
|
73
|
-
} else this.camera.fov = this.origHfov
|
|
82
|
+
let { width: r, height: i } = this.#t(), a = i / t * e, o = l.fovScale(this.origHfov, r / a);
|
|
83
|
+
this.camera.fov = l.htov(o, n);
|
|
84
|
+
} else this.camera.fov = l.htov(this.origHfov, n);
|
|
74
85
|
}
|
|
75
86
|
on(e, t) {
|
|
76
87
|
e == "objectsIntersected" && this.#e === null && (this.#e = new C(this.renderer)), super.on(e, t);
|
|
77
88
|
}
|
|
89
|
+
#t() {
|
|
90
|
+
return this.dimensionsProvider?.() ?? {
|
|
91
|
+
width: window.innerWidth,
|
|
92
|
+
height: window.innerHeight
|
|
93
|
+
};
|
|
94
|
+
}
|
|
78
95
|
}, c = class {
|
|
79
96
|
constructor() {
|
|
80
97
|
this.project = (e, t) => [this.#e(e), this.#t(t)], this.unproject = (e) => [this.#n(e[0]), this.#r(e[1])], this.#e = (e) => e / 180 * this.HALF_EARTH, this.#t = (e) => Math.log(Math.tan((90 + e) * Math.PI / 360)) / (Math.PI / 180) * this.HALF_EARTH / 180, this.#n = (e) => e / this.HALF_EARTH * 180, this.#r = (e) => {
|
|
@@ -230,6 +247,15 @@ var o = class {
|
|
|
230
247
|
getLastKnownLocation() {
|
|
231
248
|
return this.#t;
|
|
232
249
|
}
|
|
250
|
+
static htov(e, t) {
|
|
251
|
+
return this.fovScale(e, 1 / t);
|
|
252
|
+
}
|
|
253
|
+
static vtoh(e, t) {
|
|
254
|
+
return this.fovScale(e, t);
|
|
255
|
+
}
|
|
256
|
+
static fovScale(e, t) {
|
|
257
|
+
return 2 * Math.atan(t * Math.tan(Math.PI / 180 * (e / 2))) * (180 / Math.PI);
|
|
258
|
+
}
|
|
233
259
|
}, u = "locar-device-orientation-permission-modal", d = "locar-device-orientation-permission-button", f = "locar-device-orientation-permission-message", p = "locar-device-orientation-permission-inner", m = "locar-device-orientation-permission-button-inner", h = "This immersive website requires access to your device motion sensors.", g = navigator.userAgent.match(/iPhone|iPad|iPod/i) || /Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints != null && navigator.maxTouchPoints > 1, _ = new a(0, 0, 1), v = new t(), y = new i(), b = new i(-Math.sqrt(.5), 0, 0, Math.sqrt(.5));
|
|
234
260
|
2 * Math.PI;
|
|
235
261
|
var x = .5 * Math.PI, S = class extends n {
|
package/dist/locar.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("three")):typeof define==`function`&&define.amd?define([`exports`,`three`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.locar={},e.THREE))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e};t=((e,t,i)=>(i=e==null?{}:n(o(e)),c(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)))(t);var l=class{constructor(){this.emit=(e,...t)=>{this.eventHandlers[e]?.forEach(e=>{e(...t)})},this.off=(e,t)=>{if(this.eventHandlers[e]){let n=this.eventHandlers[e].indexOf(t);n>-1&&this.eventHandlers[e].splice(n,1)}},this.eventHandlers={}}on(e,t){this.eventHandlers[e]===void 0&&(this.eventHandlers[e]=[]),this.eventHandlers[e].push(t)}},u=class extends l{#e;constructor({cameraOptions:e,canvas:n,gpsOptions:r,videoConstraints:i,deviceOrientationOptions:a,serverLogger:o,projection:s,threeObjects:c}){if(c&&e)throw Error(`LocAR.App: ERROR: can only specify one of cameraOptions and threeObjects`);super();let l=window.innerWidth/window.innerHeight;this.origHfov=c?.camera?c.camera.fov*l:e?.hFov||80,this.cameraFeedDimensions=null,this.camera=c?.camera||new t.PerspectiveCamera(this.origHfov/l,l,e?.near||.001,e?.far||1e3),this.scene=c?.scene||new t.Scene,c?this.renderer=c.renderer:(n?(this.renderer=new t.WebGLRenderer({canvas:n,alpha:!0}),this.renderer.setClearColor(65280,0)):(this.renderer=new t.WebGLRenderer({alpha:!0}),this.renderer.setClearColor(65280,0),this.renderer.domElement.style.position=`relative`,this.renderer.domElement.style.zIndex=`999`,document.body.appendChild(this.renderer.domElement)),this.renderer.setSize(window.innerWidth,window.innerHeight),this.renderer.setAnimationLoop(()=>{this.deviceOrientationControls?.update(),this.renderer.render(this.scene,this.camera);let e=this.#e?.raycast(this.camera,this.scene)??[];e.length>0&&this.emit(`objectsIntersected`,{intersections:e})}),window.addEventListener(`resize`,()=>{this.renderer.setSize(window.innerWidth,window.innerHeight),this.camera.aspect=window.innerWidth/window.innerHeight,this.syncFovWithWebcam(this.camera.aspect)}));let u=a||{enabled:!0};this.locar=new f(this.scene,this.camera,r,o,s),this.webcam=new D(i),this.deviceOrientationControls=u.enabled===!0?new T(this.camera,u):null,this.#e=null}start(){return new Promise((e,t)=>{this.webcam.on(`webcamstarted`,e=>{let t=e.videoWidth>e.videoHeight;this.cameraFeedDimensions={landWidth:t?e.videoWidth:e.videoHeight,landHeight:t?e.videoHeight:e.videoWidth},this.matchFovToWebcam(e.videoWidth,e.videoHeight,window.innerWidth/window.innerHeight),this.camera.updateProjectionMatrix()}),this.webcam.on(`webcamerror`,e=>{t({code:e.code,message:e.message})}),this.deviceOrientationControls===null?e(this.locar):(this.deviceOrientationControls?.on(`deviceorientationgranted`,t=>{t.target.connect(),e(this.locar)}),this.deviceOrientationControls.on(`deviceorientationerror`,e=>{t({code:e.code,message:e.message})}),this.deviceOrientationControls.init())})}syncFovWithWebcam(e){if(e===void 0&&(e=window.innerWidth/window.innerHeight),this.cameraFeedDimensions!==null){let t=e>1?this.cameraFeedDimensions.landWidth:this.cameraFeedDimensions.landHeight,n=e>1?this.cameraFeedDimensions.landHeight:this.cameraFeedDimensions.landWidth;this.matchFovToWebcam(t,n,e)}this.camera.updateProjectionMatrix()}matchFovToWebcam(e,t,n){if(n<e/t){let r=e*(window.innerHeight/t),i=this.origHfov*(window.innerWidth/r);this.camera.fov=i/n}else this.camera.fov=this.origHfov/n}on(e,t){e==`objectsIntersected`&&this.#e===null&&(this.#e=new E(this.renderer)),super.on(e,t)}},d=class{constructor(){this.project=(e,t)=>[this.#e(e),this.#t(t)],this.unproject=e=>[this.#n(e[0]),this.#r(e[1])],this.#e=e=>e/180*this.HALF_EARTH,this.#t=e=>Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180)*this.HALF_EARTH/180,this.#n=e=>e/this.HALF_EARTH*180,this.#r=e=>{var t=e/this.HALF_EARTH*180;return t=180/Math.PI*(2*Math.atan(Math.exp(t*Math.PI/180))-Math.PI/2),t},this.getID=()=>`epsg:3857`,this.EARTH=40075016.68,this.HALF_EARTH=20037508.34}#e;#t;#n;#r},f=class e extends l{#e;#t;#n;#r;#i;#a;#o;#s;#c;constructor(e,t,n={},r=null,i=new d){super(),this.scene=e,this.camera=t,this.#e=i,this.#t=null,this.#n=0,this.#r=100,this.#i=null,this.setGpsOptions(n),this.#a=null,this.#o=0,this.#s=0,this.#c=r}setProjection(e){this.#e=e}setGpsOptions(e={}){e.gpsMinDistance!==void 0&&(this.#n=e.gpsMinDistance),e.gpsMinAccuracy!==void 0&&(this.#r=e.gpsMinAccuracy)}async startGps(){if(this.#c){let e=await(await this.#c.sendData(`/gps/start`,{gpsMinDistance:this.#n,gpsMinAccuracy:this.#r})).json();this.#s=e.session}return this.#i===null?(this.#i=navigator.geolocation.watchPosition(e=>{this.#f(e)},e=>{this.emit(`gpserror`,e)},{enableHighAccuracy:!0}),!0):!1}stopGps(){return this.#i===null?!1:(navigator.geolocation.clearWatch(this.#i),this.#i=null,!0)}fakeGps(e,t,n=null,r=0){n!==null&&this.setElevation(n),this.#f({coords:{longitude:e,latitude:t,accuracy:r}})}lonLatToWorldCoords(e,t){let n=this.#e.project(e,t);return this.eastNorthToWorldCoords(n)}eastNorthToWorldCoords(e){if(this.#a)e[0]-=this.#a[0],e[1]-=this.#a[1];else throw`No initial position determined`;return[e[0],-e[1]]}add(e,t,n,r,i={}){e.properties=i,this.#u(e,t,n,r||0),this.scene.add(e),this.#c?.sendData(`/object/new`,{position:e.position,x:e.position.x,z:e.position.z,session:this.#s,properties:i})}addGeoLine(e,n,r=1){let i=this.createGeoLine(e,r);n.setValues({side:t.DoubleSide});let a=new t.Mesh(i,n);return this.scene.add(a),a}createGeoLine(e,n=1){let r=e.map((e=>{let[n,r]=this.lonLatToWorldCoords(e[0],e[1]);return new t.Vector3(n,e[2]||0,r)}));return this.#l(r,n)}#l(e,n){let r,i,a,o,s=0,c=0,l=[],u,d=e.length-1,f=[];for(let t=0;t<d;t++)r=e[t+1].x-e[t].x,i=e[t+1].z-e[t].z,a=e[t+1].y-e[t].y,o=Math.sqrt(r*r+a*a+i*i),s=-(n/2*i)/o,c=n/2*r/o,u=[e[t].x-s,e[t].y,e[t].z-c,e[t].x+s,e[t].y,e[t].z+c],t>0&&u.forEach((e,t)=>{e=(e+l[t])/2}),f.push(...u),l=[e[t+1].x-s,e[t+1].y,e[t+1].z-c,e[t+1].x+s,e[t+1].y,e[t+1].z+c];f.push(e[d].x-s),f.push(e[d].y),f.push(e[d].z-c),f.push(e[d].x+s),f.push(e[d].y),f.push(e[d].z+c);let p=[];for(let e=0;e<d;e++)p.push(e*2,e*2+1,e*2+2),p.push(e*2+1,e*2+3,e*2+2);let m=new t.BufferGeometry,h=new Float32Array(f);return m.setIndex(p),m.setAttribute(`position`,new t.BufferAttribute(h,3)),m.computeBoundingBox(),m}#u(e,t,n,r){let i=this.lonLatToWorldCoords(t,n);r!==void 0&&(e.position.y=r),[e.position.x,e.position.z]=i}setElevation(e){this.camera.position.y=e}#d(e,t){this.#a=this.#e.project(e,t)}#f(t){let n=Number.MAX_VALUE;this.#o++,this.#c?.sendData(`/gps/new`,{gpsCount:this.#o,lat:t.coords.latitude,lon:t.coords.longitude,acc:t.coords.accuracy,session:this.#s}),t.coords.accuracy<=this.#r&&(this.#t===null?this.#t={latitude:t.coords.latitude,longitude:t.coords.longitude}:n=e.haversineDist(this.#t,t.coords),n>=this.#n&&(this.#t.longitude=t.coords.longitude,this.#t.latitude=t.coords.latitude,this.#a||(this.#d(t.coords.longitude,t.coords.latitude),this.#c?.sendData(`/worldorigin/new`,{gpsCount:this.#o,lat:t.coords.latitude,lon:t.coords.longitude,session:this.#s,initialPosition:this.#a})),this.#u(this.camera,t.coords.longitude,t.coords.latitude),this.#c?.sendData(`/gps/accepted`,{gpsCount:this.#o,cameraX:this.camera.position.x,cameraZ:this.camera.position.z,session:this.#s,distMoved:n}),this.emit(`gpsupdate`,{position:t,distMoved:n})))}static haversineDist(e,n){let r=t.MathUtils.degToRad(n.longitude-e.longitude),i=t.MathUtils.degToRad(n.latitude-e.latitude),a=Math.sin(i/2)*Math.sin(i/2)+Math.cos(t.MathUtils.degToRad(e.latitude))*Math.cos(t.MathUtils.degToRad(n.latitude))*(Math.sin(r/2)*Math.sin(r/2));return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}getLastKnownLocation(){return this.#t}},p=`locar-device-orientation-permission-modal`,m=`locar-device-orientation-permission-button`,h=`locar-device-orientation-permission-message`,g=`locar-device-orientation-permission-inner`,_=`locar-device-orientation-permission-button-inner`,v=`This immersive website requires access to your device motion sensors.`,y=navigator.userAgent.match(/iPhone|iPad|iPod/i)||/Macintosh/i.test(navigator.userAgent)&&navigator.maxTouchPoints!=null&&navigator.maxTouchPoints>1,b=new t.Vector3(0,0,1),x=new t.Euler,S=new t.Quaternion,C=new t.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5));2*Math.PI;var w=.5*Math.PI,T=class extends t.EventDispatcher{constructor(e,n={}){super(),this.init=()=>{window.DeviceOrientationEvent===void 0?this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_NOT_SUPPORTED`,message:`Device orientation API not supported`}):window.isSecureContext===!1?this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_NO_HTTPS`,message:`DeviceOrientationEvent is only available in secure contexts (https)`}):typeof window.DeviceOrientationEvent.requestPermission==`function`&&this.enablePermissionDialog?this.obtainPermissionGesture():this.eventEmitter.emit(`deviceorientationgranted`,{target:this})},this.eventEmitter=new l;let r=this;this.object=e,this.object.rotation.reorder(`YXZ`),this.enabled=!0,this.deviceOrientation=null,this.screenOrientation=0,this.alphaOffset=0,this.orientationOffset=0,this.initialOffset=null,this.lastQuaternion=null,this.orientationChangeEventName=`ondeviceorientationabsolute`in window?`deviceorientationabsolute`:`deviceorientation`,this.smoothingFactor=n.smoothingFactor||.2,this.enablePermissionDialog=n.enablePermissionDialog??!0,this.enableInlineStyling=n.enableStyling??!0,this.preferConfirmDialog=n.preferConfirmDialog??!1,this.orientationChangeThreshold=n.orientationChangeThreshold??0;let i=n=>{let{alpha:i,beta:a,gamma:o,webkitCompassHeading:s}=n;if(i??=0,a??=0,o??=0,s??=0,y){let e=360-s;r.alphaOffset=t.MathUtils.degToRad(e-i),r.deviceOrientation={alpha:i,beta:a,gamma:o,webkitCompassHeading:s}}else i<0&&(i+=360),r.deviceOrientation={alpha:i,beta:a,gamma:o};window.dispatchEvent(new CustomEvent(`camera-rotation-change`,{detail:{cameraRotation:e.rotation}}))},a=()=>{r.screenOrientation=window.screen.orientation?.angle??0,y&&(r.screenOrientation===90?r.orientationOffset=-w:r.screenOrientation===-90?r.orientationOffset=w:r.orientationOffset=0)},o=(e,t,n,r,i)=>{x.set(n,t,-r,`YXZ`),e.setFromEuler(x),e.multiply(C),e.multiply(S.setFromAxisAngle(b,-i))};this.connect=()=>{a(),window.addEventListener(`orientationchange`,a),window.addEventListener(r.orientationChangeEventName,i),r.enabled=!0},this.disconnect=()=>{window.removeEventListener(`orientationchange`,a),window.removeEventListener(r.orientationChangeEventName,i),r.enabled=!1,r.initialOffset=!1,r.deviceOrientation=null,r.lastQuaternion=null},this.requestOrientationPermissions=()=>{window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission==`function`?window.DeviceOrientationEvent.requestPermission().then(e=>{e===`granted`?this.eventEmitter.emit(`deviceorientationgranted`,{target:this}):this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_PERMISSION_DENIED`,message:`Permission for device orientation denied - AR will not work correctly`})}).catch(e=>{this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_PERMISSION_FAILED`,message:`Permission request for device orientation failed - AR will not work correctly`,error:JSON.stringify(e,null,2)})}):this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_INTERNAL_ERROR`,message:`Internal error: no requestPermission() found although requestOrientationPermissions() was called - please raise an issue on GitHub`})},this.update=()=>{if(r.enabled===!1)return;let e=r.deviceOrientation;if(e){let n=e.alpha?t.MathUtils.degToRad(e.alpha)+r.alphaOffset:0,i=e.beta?t.MathUtils.degToRad(e.beta):0,a=e.gamma?t.MathUtils.degToRad(e.gamma):0,s=r.screenOrientation?t.MathUtils.degToRad(r.screenOrientation):0,c=new t.Quaternion;if(y){o(c,n,i,a,s);let l=new t.Euler().setFromQuaternion(c,`YXZ`);l.y=t.MathUtils.degToRad(360-(e.webkitCompassHeading??0))+(r.orientationOffset||0),c.setFromEuler(l)}else o(c,n,i,a,s);if(r.lastQuaternion&&r.orientationChangeThreshold>0&&c.angleTo(r.lastQuaternion)<r.orientationChangeThreshold)return;if(r.smoothingFactor<1&&r.lastQuaternion){let e=1-r.smoothingFactor;r.object.quaternion.slerp(c,e)}else r.object.quaternion.copy(c);r.lastQuaternion=r.object.quaternion.clone(),window.dispatchEvent(new CustomEvent(`camera-rotation-change`,{detail:{cameraRotation:r.object.rotation}}))}},this.getCorrectedHeading=()=>{let{deviceOrientation:e}=r;if(!e)return 0;let t=0;return y?(t=360-(e.webkitCompassHeading??0),r.orientationOffset&&(t+=r.orientationOffset*(180/Math.PI),t=(t+360)%360)):(e.absolute===!0||r.orientationChangeEventName,t=e.alpha?e.alpha:0,t=(360-t)%360,t<0&&(t+=360)),t},this.updateAlphaOffset=()=>{r.initialOffset=!1},this.dispose=()=>{r.disconnect()},this.getAlpha=()=>{let{deviceOrientation:e}=r;return e&&e.alpha?t.MathUtils.degToRad(e.alpha)+r.alphaOffset:0},this.getBeta=()=>{let{deviceOrientation:e}=r;return e&&e.beta?t.MathUtils.degToRad(e.beta):0},this.getGamma=()=>{let{deviceOrientation:e}=r;return e&&e.gamma?t.MathUtils.degToRad(e.gamma):0},this.createObtainPermissionGestureDialog=()=>{let e=document.createElement(`div`);e.classList.add(p);let t=document.createElement(`div`);t.classList.add(g);let n=document.createElement(`div`);n.classList.add(h);let r=document.createElement(`div`);r.classList.add(_);let i=document.createElement(`button`);i.classList.add(m),document.body.appendChild(e),this.enableInlineStyling===!0&&(e.style.fontFamily=`-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'`,e.style.display=`flex`,e.style.position=`fixed`,e.style.zIndex=`100000`,e.style.justifyContent=`center`,e.style.alignItems=`center`,e.style.backgroundColor=`rgba(0,0,0,0.2)`,e.style.inset=`0`,e.style.padding=`20px`,t.style.backgroundColor=`rgba(220, 220, 220, 0.85)`,t.style.padding=`6px 0`,t.style.borderRadius=`10px`,t.style.width=`100%`,t.style.maxWidth=`400px`,n.style.padding=`10px 12px`,n.style.textAlign=`center`,n.style.fontWeight=`400`,n.style.fontSize=`13px`,n.style.display=`flex`,n.style.justifyContent=`center`,n.style.alignItems=`center`,r.style.display=`block`,r.style.textAlign=`center`,r.style.textDecoration=`none`,r.style.borderTop=`rgb(180,180,180) solid 1px`,i.style.display=`block`,i.style.width=`100%`,i.style.textAlign=`center`,i.style.appearance=`none`,i.style.background=`none`,i.style.border=`none`,i.style.outline=`none`,i.style.padding=`10px`,i.style.fontWeight=`400`,i.style.fontSize=`16px`,i.style.color=`#2e7cf1`,i.style.cursor=`pointer`),e.appendChild(t),t.appendChild(n),t.appendChild(r),n.appendChild(document.createTextNode(v)),i.addEventListener(`click`,()=>{this.requestOrientationPermissions(),e.style.display=`none`}),i.appendChild(document.createTextNode(`OK`)),r.appendChild(i),document.body.appendChild(e)},this.obtainPermissionGesture=()=>{this.preferConfirmDialog===!0?window.confirm(v)&&this.requestOrientationPermissions():this.createObtainPermissionGestureDialog()}}on(e,t){this.eventEmitter.on(e,t)}},E=class{constructor(e){this.raycaster=new t.Raycaster,this.normalisedMousePosition=null,e.domElement.addEventListener(`click`,n=>{let r=e.domElement.getBoundingClientRect();this.normalisedMousePosition=new t.Vector2((n.clientX-r.left)/e.domElement.clientWidth*2-1,-((n.clientY-r.top)/e.domElement.clientHeight*2)+1)})}raycast(e,t){if(this.normalisedMousePosition!==null){this.raycaster.setFromCamera(this.normalisedMousePosition,e);let n=this.raycaster.intersectObjects(t.children,!0);return this.normalisedMousePosition=null,n}return[]}},D=class extends l{#e;constructor(e={video:{facingMode:`environment`}},t){super(),t?this.video=document.querySelector(t):(this.video=document.createElement(`video`),this.video.setAttribute(`autoplay`,`true`),this.video.setAttribute(`playsinline`,`true`),this.video.style.cssText+=`
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("three")):typeof define==`function`&&define.amd?define([`exports`,`three`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.locar={},e.THREE))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e};t=((e,t,i)=>(i=e==null?{}:n(o(e)),c(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)))(t);var l=class{constructor(){this.emit=(e,...t)=>{this.eventHandlers[e]?.forEach(e=>{e(...t)})},this.off=(e,t)=>{if(this.eventHandlers[e]){let n=this.eventHandlers[e].indexOf(t);n>-1&&this.eventHandlers[e].splice(n,1)}},this.eventHandlers={}}on(e,t){this.eventHandlers[e]===void 0&&(this.eventHandlers[e]=[]),this.eventHandlers[e].push(t)}},u=class extends l{#e;constructor({cameraOptions:e,canvas:n,gpsOptions:r,videoConstraints:i,deviceOrientationOptions:a,serverLogger:o,projection:s,threeObjects:c,dimensionsProvider:l}){if(c&&e)throw Error(`LocAR.App: ERROR: can only specify one of cameraOptions and threeObjects`);super(),this.dimensionsProvider=l;let{width:u,height:d}=this.#t(),p=u/d;this.origHfov=c?.camera?f.vtoh(c.camera.fov,p):e?.hFov||80,this.cameraFeedDimensions=null,this.camera=c?.camera||new t.PerspectiveCamera(f.htov(this.origHfov,p),p,e?.near||.001,e?.far||1e3),this.scene=c?.scene||new t.Scene,c?this.renderer=c.renderer:(n?(this.renderer=new t.WebGLRenderer({canvas:n,alpha:!0}),this.renderer.setClearColor(65280,0)):(this.renderer=new t.WebGLRenderer({alpha:!0}),this.renderer.setClearColor(65280,0),this.renderer.domElement.style.position=`relative`,this.renderer.domElement.style.zIndex=`999`,document.body.appendChild(this.renderer.domElement)),this.renderer.setSize(u,d),this.renderer.setAnimationLoop(()=>{this.deviceOrientationControls?.update(),this.renderer.render(this.scene,this.camera);let e=this.#e?.raycast(this.camera,this.scene)??[];e.length>0&&this.emit(`objectsIntersected`,{intersections:e})}),window.addEventListener(`resize`,()=>{let{width:e,height:t}=this.#t();this.renderer.setSize(e,t),this.camera.aspect=e/t,this.syncFovWithWebcam(this.camera.aspect)}));let m=a||{enabled:!0};this.locar=new f(this.scene,this.camera,r,o,s),this.webcam=new D(i),this.deviceOrientationControls=m.enabled===!0?new T(this.camera,m):null,this.#e=null}start(){return new Promise((e,t)=>{this.webcam.on(`webcamstarted`,e=>{let t=e.videoWidth>e.videoHeight;this.cameraFeedDimensions={landWidth:t?e.videoWidth:e.videoHeight,landHeight:t?e.videoHeight:e.videoWidth};let{width:n,height:r}=this.#t();this.matchFovToWebcam(e.videoWidth,e.videoHeight,n/r),this.camera.updateProjectionMatrix(),this.emit(`webcamstarted`,{...e,landVideoWidth:this.cameraFeedDimensions.landWidth,landVideoHeight:this.cameraFeedDimensions.landHeight})}),this.webcam.on(`webcamerror`,e=>{t({code:e.code,message:e.message})}),this.deviceOrientationControls===null?e(this.locar):(this.deviceOrientationControls?.on(`deviceorientationgranted`,t=>{t.target.connect(),e(this.locar)}),this.deviceOrientationControls.on(`deviceorientationerror`,e=>{t({code:e.code,message:e.message})}),this.deviceOrientationControls.init())})}syncFovWithWebcam(e){if(e===void 0){let{width:t,height:n}=this.#t();e=t/n}if(this.cameraFeedDimensions!==null){let t=e>1?this.cameraFeedDimensions.landWidth:this.cameraFeedDimensions.landHeight,n=e>1?this.cameraFeedDimensions.landHeight:this.cameraFeedDimensions.landWidth;this.matchFovToWebcam(t,n,e)}this.camera.updateProjectionMatrix()}matchFovToWebcam(e,t,n){if(n<e/t){let{width:r,height:i}=this.#t(),a=i/t*e,o=f.fovScale(this.origHfov,r/a);this.camera.fov=f.htov(o,n)}else this.camera.fov=f.htov(this.origHfov,n)}on(e,t){e==`objectsIntersected`&&this.#e===null&&(this.#e=new E(this.renderer)),super.on(e,t)}#t(){return this.dimensionsProvider?.()??{width:window.innerWidth,height:window.innerHeight}}},d=class{constructor(){this.project=(e,t)=>[this.#e(e),this.#t(t)],this.unproject=e=>[this.#n(e[0]),this.#r(e[1])],this.#e=e=>e/180*this.HALF_EARTH,this.#t=e=>Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180)*this.HALF_EARTH/180,this.#n=e=>e/this.HALF_EARTH*180,this.#r=e=>{var t=e/this.HALF_EARTH*180;return t=180/Math.PI*(2*Math.atan(Math.exp(t*Math.PI/180))-Math.PI/2),t},this.getID=()=>`epsg:3857`,this.EARTH=40075016.68,this.HALF_EARTH=20037508.34}#e;#t;#n;#r},f=class e extends l{#e;#t;#n;#r;#i;#a;#o;#s;#c;constructor(e,t,n={},r=null,i=new d){super(),this.scene=e,this.camera=t,this.#e=i,this.#t=null,this.#n=0,this.#r=100,this.#i=null,this.setGpsOptions(n),this.#a=null,this.#o=0,this.#s=0,this.#c=r}setProjection(e){this.#e=e}setGpsOptions(e={}){e.gpsMinDistance!==void 0&&(this.#n=e.gpsMinDistance),e.gpsMinAccuracy!==void 0&&(this.#r=e.gpsMinAccuracy)}async startGps(){if(this.#c){let e=await(await this.#c.sendData(`/gps/start`,{gpsMinDistance:this.#n,gpsMinAccuracy:this.#r})).json();this.#s=e.session}return this.#i===null?(this.#i=navigator.geolocation.watchPosition(e=>{this.#f(e)},e=>{this.emit(`gpserror`,e)},{enableHighAccuracy:!0}),!0):!1}stopGps(){return this.#i===null?!1:(navigator.geolocation.clearWatch(this.#i),this.#i=null,!0)}fakeGps(e,t,n=null,r=0){n!==null&&this.setElevation(n),this.#f({coords:{longitude:e,latitude:t,accuracy:r}})}lonLatToWorldCoords(e,t){let n=this.#e.project(e,t);return this.eastNorthToWorldCoords(n)}eastNorthToWorldCoords(e){if(this.#a)e[0]-=this.#a[0],e[1]-=this.#a[1];else throw`No initial position determined`;return[e[0],-e[1]]}add(e,t,n,r,i={}){e.properties=i,this.#u(e,t,n,r||0),this.scene.add(e),this.#c?.sendData(`/object/new`,{position:e.position,x:e.position.x,z:e.position.z,session:this.#s,properties:i})}addGeoLine(e,n,r=1){let i=this.createGeoLine(e,r);n.setValues({side:t.DoubleSide});let a=new t.Mesh(i,n);return this.scene.add(a),a}createGeoLine(e,n=1){let r=e.map((e=>{let[n,r]=this.lonLatToWorldCoords(e[0],e[1]);return new t.Vector3(n,e[2]||0,r)}));return this.#l(r,n)}#l(e,n){let r,i,a,o,s=0,c=0,l=[],u,d=e.length-1,f=[];for(let t=0;t<d;t++)r=e[t+1].x-e[t].x,i=e[t+1].z-e[t].z,a=e[t+1].y-e[t].y,o=Math.sqrt(r*r+a*a+i*i),s=-(n/2*i)/o,c=n/2*r/o,u=[e[t].x-s,e[t].y,e[t].z-c,e[t].x+s,e[t].y,e[t].z+c],t>0&&u.forEach((e,t)=>{e=(e+l[t])/2}),f.push(...u),l=[e[t+1].x-s,e[t+1].y,e[t+1].z-c,e[t+1].x+s,e[t+1].y,e[t+1].z+c];f.push(e[d].x-s),f.push(e[d].y),f.push(e[d].z-c),f.push(e[d].x+s),f.push(e[d].y),f.push(e[d].z+c);let p=[];for(let e=0;e<d;e++)p.push(e*2,e*2+1,e*2+2),p.push(e*2+1,e*2+3,e*2+2);let m=new t.BufferGeometry,h=new Float32Array(f);return m.setIndex(p),m.setAttribute(`position`,new t.BufferAttribute(h,3)),m.computeBoundingBox(),m}#u(e,t,n,r){let i=this.lonLatToWorldCoords(t,n);r!==void 0&&(e.position.y=r),[e.position.x,e.position.z]=i}setElevation(e){this.camera.position.y=e}#d(e,t){this.#a=this.#e.project(e,t)}#f(t){let n=Number.MAX_VALUE;this.#o++,this.#c?.sendData(`/gps/new`,{gpsCount:this.#o,lat:t.coords.latitude,lon:t.coords.longitude,acc:t.coords.accuracy,session:this.#s}),t.coords.accuracy<=this.#r&&(this.#t===null?this.#t={latitude:t.coords.latitude,longitude:t.coords.longitude}:n=e.haversineDist(this.#t,t.coords),n>=this.#n&&(this.#t.longitude=t.coords.longitude,this.#t.latitude=t.coords.latitude,this.#a||(this.#d(t.coords.longitude,t.coords.latitude),this.#c?.sendData(`/worldorigin/new`,{gpsCount:this.#o,lat:t.coords.latitude,lon:t.coords.longitude,session:this.#s,initialPosition:this.#a})),this.#u(this.camera,t.coords.longitude,t.coords.latitude),this.#c?.sendData(`/gps/accepted`,{gpsCount:this.#o,cameraX:this.camera.position.x,cameraZ:this.camera.position.z,session:this.#s,distMoved:n}),this.emit(`gpsupdate`,{position:t,distMoved:n})))}static haversineDist(e,n){let r=t.MathUtils.degToRad(n.longitude-e.longitude),i=t.MathUtils.degToRad(n.latitude-e.latitude),a=Math.sin(i/2)*Math.sin(i/2)+Math.cos(t.MathUtils.degToRad(e.latitude))*Math.cos(t.MathUtils.degToRad(n.latitude))*(Math.sin(r/2)*Math.sin(r/2));return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}getLastKnownLocation(){return this.#t}static htov(e,t){return this.fovScale(e,1/t)}static vtoh(e,t){return this.fovScale(e,t)}static fovScale(e,t){return 2*Math.atan(t*Math.tan(Math.PI/180*(e/2)))*(180/Math.PI)}},p=`locar-device-orientation-permission-modal`,m=`locar-device-orientation-permission-button`,h=`locar-device-orientation-permission-message`,g=`locar-device-orientation-permission-inner`,_=`locar-device-orientation-permission-button-inner`,v=`This immersive website requires access to your device motion sensors.`,y=navigator.userAgent.match(/iPhone|iPad|iPod/i)||/Macintosh/i.test(navigator.userAgent)&&navigator.maxTouchPoints!=null&&navigator.maxTouchPoints>1,b=new t.Vector3(0,0,1),x=new t.Euler,S=new t.Quaternion,C=new t.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5));2*Math.PI;var w=.5*Math.PI,T=class extends t.EventDispatcher{constructor(e,n={}){super(),this.init=()=>{window.DeviceOrientationEvent===void 0?this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_NOT_SUPPORTED`,message:`Device orientation API not supported`}):window.isSecureContext===!1?this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_NO_HTTPS`,message:`DeviceOrientationEvent is only available in secure contexts (https)`}):typeof window.DeviceOrientationEvent.requestPermission==`function`&&this.enablePermissionDialog?this.obtainPermissionGesture():this.eventEmitter.emit(`deviceorientationgranted`,{target:this})},this.eventEmitter=new l;let r=this;this.object=e,this.object.rotation.reorder(`YXZ`),this.enabled=!0,this.deviceOrientation=null,this.screenOrientation=0,this.alphaOffset=0,this.orientationOffset=0,this.initialOffset=null,this.lastQuaternion=null,this.orientationChangeEventName=`ondeviceorientationabsolute`in window?`deviceorientationabsolute`:`deviceorientation`,this.smoothingFactor=n.smoothingFactor||.2,this.enablePermissionDialog=n.enablePermissionDialog??!0,this.enableInlineStyling=n.enableStyling??!0,this.preferConfirmDialog=n.preferConfirmDialog??!1,this.orientationChangeThreshold=n.orientationChangeThreshold??0;let i=n=>{let{alpha:i,beta:a,gamma:o,webkitCompassHeading:s}=n;if(i??=0,a??=0,o??=0,s??=0,y){let e=360-s;r.alphaOffset=t.MathUtils.degToRad(e-i),r.deviceOrientation={alpha:i,beta:a,gamma:o,webkitCompassHeading:s}}else i<0&&(i+=360),r.deviceOrientation={alpha:i,beta:a,gamma:o};window.dispatchEvent(new CustomEvent(`camera-rotation-change`,{detail:{cameraRotation:e.rotation}}))},a=()=>{r.screenOrientation=window.screen.orientation?.angle??0,y&&(r.screenOrientation===90?r.orientationOffset=-w:r.screenOrientation===-90?r.orientationOffset=w:r.orientationOffset=0)},o=(e,t,n,r,i)=>{x.set(n,t,-r,`YXZ`),e.setFromEuler(x),e.multiply(C),e.multiply(S.setFromAxisAngle(b,-i))};this.connect=()=>{a(),window.addEventListener(`orientationchange`,a),window.addEventListener(r.orientationChangeEventName,i),r.enabled=!0},this.disconnect=()=>{window.removeEventListener(`orientationchange`,a),window.removeEventListener(r.orientationChangeEventName,i),r.enabled=!1,r.initialOffset=!1,r.deviceOrientation=null,r.lastQuaternion=null},this.requestOrientationPermissions=()=>{window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission==`function`?window.DeviceOrientationEvent.requestPermission().then(e=>{e===`granted`?this.eventEmitter.emit(`deviceorientationgranted`,{target:this}):this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_PERMISSION_DENIED`,message:`Permission for device orientation denied - AR will not work correctly`})}).catch(e=>{this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_PERMISSION_FAILED`,message:`Permission request for device orientation failed - AR will not work correctly`,error:JSON.stringify(e,null,2)})}):this.eventEmitter.emit(`deviceorientationerror`,{code:`LOCAR_DEVICE_ORIENTATION_INTERNAL_ERROR`,message:`Internal error: no requestPermission() found although requestOrientationPermissions() was called - please raise an issue on GitHub`})},this.update=()=>{if(r.enabled===!1)return;let e=r.deviceOrientation;if(e){let n=e.alpha?t.MathUtils.degToRad(e.alpha)+r.alphaOffset:0,i=e.beta?t.MathUtils.degToRad(e.beta):0,a=e.gamma?t.MathUtils.degToRad(e.gamma):0,s=r.screenOrientation?t.MathUtils.degToRad(r.screenOrientation):0,c=new t.Quaternion;if(y){o(c,n,i,a,s);let l=new t.Euler().setFromQuaternion(c,`YXZ`);l.y=t.MathUtils.degToRad(360-(e.webkitCompassHeading??0))+(r.orientationOffset||0),c.setFromEuler(l)}else o(c,n,i,a,s);if(r.lastQuaternion&&r.orientationChangeThreshold>0&&c.angleTo(r.lastQuaternion)<r.orientationChangeThreshold)return;if(r.smoothingFactor<1&&r.lastQuaternion){let e=1-r.smoothingFactor;r.object.quaternion.slerp(c,e)}else r.object.quaternion.copy(c);r.lastQuaternion=r.object.quaternion.clone(),window.dispatchEvent(new CustomEvent(`camera-rotation-change`,{detail:{cameraRotation:r.object.rotation}}))}},this.getCorrectedHeading=()=>{let{deviceOrientation:e}=r;if(!e)return 0;let t=0;return y?(t=360-(e.webkitCompassHeading??0),r.orientationOffset&&(t+=r.orientationOffset*(180/Math.PI),t=(t+360)%360)):(e.absolute===!0||r.orientationChangeEventName,t=e.alpha?e.alpha:0,t=(360-t)%360,t<0&&(t+=360)),t},this.updateAlphaOffset=()=>{r.initialOffset=!1},this.dispose=()=>{r.disconnect()},this.getAlpha=()=>{let{deviceOrientation:e}=r;return e&&e.alpha?t.MathUtils.degToRad(e.alpha)+r.alphaOffset:0},this.getBeta=()=>{let{deviceOrientation:e}=r;return e&&e.beta?t.MathUtils.degToRad(e.beta):0},this.getGamma=()=>{let{deviceOrientation:e}=r;return e&&e.gamma?t.MathUtils.degToRad(e.gamma):0},this.createObtainPermissionGestureDialog=()=>{let e=document.createElement(`div`);e.classList.add(p);let t=document.createElement(`div`);t.classList.add(g);let n=document.createElement(`div`);n.classList.add(h);let r=document.createElement(`div`);r.classList.add(_);let i=document.createElement(`button`);i.classList.add(m),document.body.appendChild(e),this.enableInlineStyling===!0&&(e.style.fontFamily=`-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'`,e.style.display=`flex`,e.style.position=`fixed`,e.style.zIndex=`100000`,e.style.justifyContent=`center`,e.style.alignItems=`center`,e.style.backgroundColor=`rgba(0,0,0,0.2)`,e.style.inset=`0`,e.style.padding=`20px`,t.style.backgroundColor=`rgba(220, 220, 220, 0.85)`,t.style.padding=`6px 0`,t.style.borderRadius=`10px`,t.style.width=`100%`,t.style.maxWidth=`400px`,n.style.padding=`10px 12px`,n.style.textAlign=`center`,n.style.fontWeight=`400`,n.style.fontSize=`13px`,n.style.display=`flex`,n.style.justifyContent=`center`,n.style.alignItems=`center`,r.style.display=`block`,r.style.textAlign=`center`,r.style.textDecoration=`none`,r.style.borderTop=`rgb(180,180,180) solid 1px`,i.style.display=`block`,i.style.width=`100%`,i.style.textAlign=`center`,i.style.appearance=`none`,i.style.background=`none`,i.style.border=`none`,i.style.outline=`none`,i.style.padding=`10px`,i.style.fontWeight=`400`,i.style.fontSize=`16px`,i.style.color=`#2e7cf1`,i.style.cursor=`pointer`),e.appendChild(t),t.appendChild(n),t.appendChild(r),n.appendChild(document.createTextNode(v)),i.addEventListener(`click`,()=>{this.requestOrientationPermissions(),e.style.display=`none`}),i.appendChild(document.createTextNode(`OK`)),r.appendChild(i),document.body.appendChild(e)},this.obtainPermissionGesture=()=>{this.preferConfirmDialog===!0?window.confirm(v)&&this.requestOrientationPermissions():this.createObtainPermissionGestureDialog()}}on(e,t){this.eventEmitter.on(e,t)}},E=class{constructor(e){this.raycaster=new t.Raycaster,this.normalisedMousePosition=null,e.domElement.addEventListener(`click`,n=>{let r=e.domElement.getBoundingClientRect();this.normalisedMousePosition=new t.Vector2((n.clientX-r.left)/e.domElement.clientWidth*2-1,-((n.clientY-r.top)/e.domElement.clientHeight*2)+1)})}raycast(e,t){if(this.normalisedMousePosition!==null){this.raycaster.setFromCamera(this.normalisedMousePosition,e);let n=this.raycaster.intersectObjects(t.children,!0);return this.normalisedMousePosition=null,n}return[]}},D=class extends l{#e;constructor(e={video:{facingMode:`environment`}},t){super(),t?this.video=document.querySelector(t):(this.video=document.createElement(`video`),this.video.setAttribute(`autoplay`,`true`),this.video.setAttribute(`playsinline`,`true`),this.video.style.cssText+=`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
object-fit: cover;
|