locar 0.0.6 → 0.0.8

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 CHANGED
@@ -42,7 +42,7 @@ import * as LocAR from 'locar';
42
42
  as long as you include `locar` as a dependency, e.g. in your `package.json`:
43
43
  ```
44
44
  "dependencies": {
45
- "locar" : "^0.0.3",
45
+ "locar" : "^0.0.7",
46
46
  "three" : "^0.169.0"
47
47
  }
48
48
  ```
package/dist/locar.es.js CHANGED
@@ -1,24 +1,25 @@
1
- var W = (a) => {
2
- throw TypeError(a);
1
+ var j = (r) => {
2
+ throw TypeError(r);
3
3
  };
4
- var L = (a, t, e) => t.has(a) || W("Cannot " + e);
5
- var i = (a, t, e) => (L(a, t, "read from private field"), e ? e.call(a) : t.get(a)), d = (a, t, e) => t.has(a) ? W("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(a) : t.set(a, e), r = (a, t, e, s) => (L(a, t, "write to private field"), s ? s.call(a, e) : t.set(a, e), e), u = (a, t, e) => (L(a, t, "access private method"), e);
6
- var j = (a, t, e, s) => ({
7
- set _(n) {
8
- r(a, t, n, e);
4
+ var F = (r, t, e) => t.has(r) || j("Cannot " + e);
5
+ var n = (r, t, e) => (F(r, t, "read from private field"), e ? e.call(r) : t.get(r)), m = (r, t, e) => t.has(r) ? j("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), d = (r, t, e, i) => (F(r, t, "write to private field"), i ? i.call(r, e) : t.set(r, e), e), v = (r, t, e) => (F(r, t, "access private method"), e);
6
+ var q = (r, t, e, i) => ({
7
+ set _(o) {
8
+ d(r, t, o, e);
9
9
  },
10
10
  get _() {
11
- return i(a, t, s);
11
+ return n(r, t, i);
12
12
  }
13
13
  });
14
- import * as o from "three";
15
- var v, _, q, I, F;
16
- class N {
14
+ import * as f from "three";
15
+ import { Vector3 as Z, Euler as N, Quaternion as _, EventDispatcher as B, MathUtils as D } from "three";
16
+ var P, U, G, X, Q;
17
+ class K {
17
18
  /**
18
19
  * Create a SphMercProjection.
19
20
  */
20
21
  constructor() {
21
- d(this, v);
22
+ m(this, P);
22
23
  this.EARTH = 4007501668e-2, this.HALF_EARTH = 2003750834e-2;
23
24
  }
24
25
  /**
@@ -28,7 +29,7 @@ class N {
28
29
  * @return {Array} Two-member array containing easting and northing.
29
30
  */
30
31
  project(t, e) {
31
- return [u(this, v, _).call(this, t), u(this, v, q).call(this, e)];
32
+ return [v(this, P, U).call(this, t), v(this, P, G).call(this, e)];
32
33
  }
33
34
  /**
34
35
  * Unproject a Spherical Mercator easting and northing.
@@ -36,7 +37,7 @@ class N {
36
37
  * @return {Array} Two-member array containing longitude and latitude
37
38
  */
38
39
  unproject(t) {
39
- return [u(this, v, I).call(this, t[0]), u(this, v, F).call(this, t[1])];
40
+ return [v(this, P, X).call(this, t[0]), v(this, P, Q).call(this, t[1])];
40
41
  }
41
42
  /**
42
43
  * Return the projection's ID.
@@ -46,19 +47,19 @@ class N {
46
47
  return "epsg:3857";
47
48
  }
48
49
  }
49
- v = new WeakSet(), _ = function(t) {
50
+ P = new WeakSet(), U = function(t) {
50
51
  return t / 180 * this.HALF_EARTH;
51
- }, q = function(t) {
52
+ }, G = function(t) {
52
53
  var e = Math.log(Math.tan((90 + t) * Math.PI / 360)) / (Math.PI / 180);
53
54
  return e * this.HALF_EARTH / 180;
54
- }, I = function(t) {
55
+ }, X = function(t) {
55
56
  return t / this.HALF_EARTH * 180;
56
- }, F = function(t) {
57
+ }, Q = function(t) {
57
58
  var e = t / this.HALF_EARTH * 180;
58
59
  return e = 180 / Math.PI * (2 * Math.atan(Math.exp(e * Math.PI / 180)) - Math.PI / 2), e;
59
60
  };
60
- var O, M, f, b, P, w, m, y, E, p, l, H, S, x, G;
61
- class Y {
61
+ var R, A, T, x, L, C, E, I, b, O, p, S, V, W, Y;
62
+ class st {
62
63
  /**
63
64
  * @param {THREE.Scene} scene - The Three.js scene to use.
64
65
  * @param {THREE.Camera} camera - The Three.js camera to use. Should usually
@@ -67,19 +68,19 @@ class Y {
67
68
  * setGpsOptions() below.
68
69
  * @param {Object} serverLogger - an object which can optionally log GPS position to a server for debugging. null by default, so no logging will be done. This object should implement a sendData() method to send data (2nd arg) to a given endpoint (1st arg). Please see source code for details. Ensure you comply with privacy laws (GDPR or equivalent) if implementing this.
69
70
  */
70
- constructor(t, e, s = {}, n = null) {
71
- d(this, l);
72
- d(this, O);
73
- d(this, M);
74
- d(this, f);
75
- d(this, b);
76
- d(this, P);
77
- d(this, w);
78
- d(this, m);
79
- d(this, y);
80
- d(this, E);
81
- d(this, p);
82
- this.scene = t, this.camera = e, r(this, O, new N()), r(this, M, {}), r(this, f, null), r(this, b, 0), r(this, P, 100), r(this, w, null), this.setGpsOptions(s), r(this, m, null), r(this, y, 0), r(this, E, 0), r(this, p, n);
71
+ constructor(t, e, i = {}, o = null) {
72
+ m(this, p);
73
+ m(this, R);
74
+ m(this, A);
75
+ m(this, T);
76
+ m(this, x);
77
+ m(this, L);
78
+ m(this, C);
79
+ m(this, E);
80
+ m(this, I);
81
+ m(this, b);
82
+ m(this, O);
83
+ this.scene = t, this.camera = e, d(this, R, new K()), d(this, A, {}), d(this, T, null), d(this, x, 0), d(this, L, 100), d(this, C, null), this.setGpsOptions(i), d(this, E, null), d(this, I, 0), d(this, b, 0), d(this, O, o);
83
84
  }
84
85
  /**
85
86
  * Set the projection to use.
@@ -88,7 +89,7 @@ class Y {
88
89
  * containing easting and northing.
89
90
  */
90
91
  setProjection(t) {
91
- r(this, O, t);
92
+ d(this, R, t);
92
93
  }
93
94
  /**
94
95
  * Set the GPS options.
@@ -98,7 +99,7 @@ class Y {
98
99
  * minimum accuracy, in metres, for a GPS reading to be counted.
99
100
  */
100
101
  setGpsOptions(t = {}) {
101
- t.gpsMinDistance !== void 0 && r(this, b, t.gpsMinDistance), t.gpsMinAccuracy !== void 0 && r(this, P, t.gpsMinAccuracy);
102
+ t.gpsMinDistance !== void 0 && d(this, x, t.gpsMinDistance), t.gpsMinAccuracy !== void 0 && d(this, L, t.gpsMinAccuracy);
102
103
  }
103
104
  /**
104
105
  * Start the GPS on a real device
@@ -106,19 +107,19 @@ class Y {
106
107
  * GPS errors can be handled by handling the gpserror event.
107
108
  */
108
109
  async startGps() {
109
- if (i(this, p)) {
110
- const e = await (await i(this, p).sendData("/gps/start", {
111
- gpsMinDistance: i(this, b),
112
- gpsMinAccuracy: i(this, P)
110
+ if (n(this, O)) {
111
+ const e = await (await n(this, O).sendData("/gps/start", {
112
+ gpsMinDistance: n(this, x),
113
+ gpsMinAccuracy: n(this, L)
113
114
  })).json();
114
- r(this, E, e.session);
115
+ d(this, b, e.session);
115
116
  }
116
- return i(this, w) === null ? (r(this, w, navigator.geolocation.watchPosition(
117
+ return n(this, C) === null ? (d(this, C, navigator.geolocation.watchPosition(
117
118
  (t) => {
118
- u(this, l, x).call(this, t);
119
+ v(this, p, W).call(this, t);
119
120
  },
120
121
  (t) => {
121
- i(this, M).gpserror ? i(this, M).gpserror(t.code) : alert(`GPS error: code ${t.code}`);
122
+ n(this, A).gpserror ? n(this, A).gpserror(t.code) : alert(`GPS error: code ${t.code}`);
122
123
  },
123
124
  {
124
125
  enableHighAccuracy: !0
@@ -131,7 +132,7 @@ class Y {
131
132
  * stopped (i.e. it was never started).
132
133
  */
133
134
  stopGps() {
134
- return i(this, w) !== null ? (navigator.geolocation.clearWatch(i(this, w)), r(this, w, null), !0) : !1;
135
+ return n(this, C) !== null ? (navigator.geolocation.clearWatch(n(this, C)), d(this, C, null), !0) : !1;
135
136
  }
136
137
  /**
137
138
  * Send a fake GPS signal. Useful for testing on a desktop or laptop.
@@ -142,12 +143,12 @@ class Y {
142
143
  * @param {number} acc - The accuracy of the GPS reading in metres. May be
143
144
  * ignored if lower than the specified minimum accuracy.
144
145
  */
145
- fakeGps(t, e, s = null, n = 0) {
146
- s !== null && this.setElevation(s), u(this, l, x).call(this, {
146
+ fakeGps(t, e, i = null, o = 0) {
147
+ i !== null && this.setElevation(i), v(this, p, W).call(this, {
147
148
  coords: {
148
149
  longitude: t,
149
150
  latitude: e,
150
- accuracy: n
151
+ accuracy: o
151
152
  }
152
153
  });
153
154
  }
@@ -162,12 +163,12 @@ class Y {
162
163
  * @return {Array} a two member array containing the WebGL x and z coordinates
163
164
  */
164
165
  lonLatToWorldCoords(t, e) {
165
- const s = i(this, O).project(t, e);
166
- if (i(this, m))
167
- s[0] -= i(this, m)[0], s[1] -= i(this, m)[1];
166
+ const i = n(this, R).project(t, e);
167
+ if (n(this, E))
168
+ i[0] -= n(this, E)[0], i[1] -= n(this, E)[1];
168
169
  else
169
170
  throw "No initial position determined";
170
- return [s[0], -s[1]];
171
+ return [i[0], -i[1]];
171
172
  }
172
173
  /**
173
174
  * Add a new AR object at a given latitude, longitude and elevation.
@@ -179,14 +180,14 @@ class Y {
179
180
  * @param {Object} properties - properties describing the object (for example,
180
181
  * the contents of the GeoJSON properties field).
181
182
  */
182
- add(t, e, s, n, h = {}) {
183
+ add(t, e, i, o, u = {}) {
183
184
  var g;
184
- t.properties = h, u(this, l, H).call(this, t, e, s, n), this.scene.add(t), (g = i(this, p)) == null || g.sendData("/object/new", {
185
+ t.properties = u, v(this, p, S).call(this, t, e, i, o), this.scene.add(t), (g = n(this, O)) == null || g.sendData("/object/new", {
185
186
  position: t.position,
186
187
  x: t.position.x,
187
188
  z: t.position.z,
188
- session: i(this, E),
189
- properties: h
189
+ session: n(this, b),
190
+ properties: u
190
191
  });
191
192
  }
192
193
  /**
@@ -210,49 +211,49 @@ class Y {
210
211
  * @listens LocationBased#gpserror
211
212
  */
212
213
  on(t, e) {
213
- i(this, M)[t] = e;
214
+ n(this, A)[t] = e;
214
215
  }
215
216
  }
216
- O = new WeakMap(), M = new WeakMap(), f = new WeakMap(), b = new WeakMap(), P = new WeakMap(), w = new WeakMap(), m = new WeakMap(), y = new WeakMap(), E = new WeakMap(), p = new WeakMap(), l = new WeakSet(), H = function(t, e, s, n) {
217
- const h = this.lonLatToWorldCoords(e, s);
218
- n !== void 0 && (t.position.y = n), [t.position.x, t.position.z] = h;
219
- }, S = function(t, e) {
220
- r(this, m, i(this, O).project(t, e));
221
- }, x = function(t) {
222
- var s, n, h;
217
+ R = new WeakMap(), A = new WeakMap(), T = new WeakMap(), x = new WeakMap(), L = new WeakMap(), C = new WeakMap(), E = new WeakMap(), I = new WeakMap(), b = new WeakMap(), O = new WeakMap(), p = new WeakSet(), S = function(t, e, i, o) {
218
+ const u = this.lonLatToWorldCoords(e, i);
219
+ o !== void 0 && (t.position.y = o), [t.position.x, t.position.z] = u;
220
+ }, V = function(t, e) {
221
+ d(this, E, n(this, R).project(t, e));
222
+ }, W = function(t) {
223
+ var i, o, u;
223
224
  let e = Number.MAX_VALUE;
224
- j(this, y)._++, (s = i(this, p)) == null || s.sendData("/gps/new", {
225
- gpsCount: i(this, y),
225
+ q(this, I)._++, (i = n(this, O)) == null || i.sendData("/gps/new", {
226
+ gpsCount: n(this, I),
226
227
  lat: t.coords.latitude,
227
228
  lon: t.coords.longitude,
228
229
  acc: t.coords.accuracy,
229
- session: i(this, E)
230
- }), t.coords.accuracy <= i(this, P) && (i(this, f) === null ? r(this, f, {
230
+ session: n(this, b)
231
+ }), t.coords.accuracy <= n(this, L) && (n(this, T) === null ? d(this, T, {
231
232
  latitude: t.coords.latitude,
232
233
  longitude: t.coords.longitude
233
- }) : e = u(this, l, G).call(this, i(this, f), t.coords), e >= i(this, b) && (i(this, f).longitude = t.coords.longitude, i(this, f).latitude = t.coords.latitude, i(this, m) || (u(this, l, S).call(this, t.coords.longitude, t.coords.latitude), (n = i(this, p)) == null || n.sendData("/worldorigin/new", {
234
- gpsCount: i(this, y),
234
+ }) : e = v(this, p, Y).call(this, n(this, T), t.coords), e >= n(this, x) && (n(this, T).longitude = t.coords.longitude, n(this, T).latitude = t.coords.latitude, n(this, E) || (v(this, p, V).call(this, t.coords.longitude, t.coords.latitude), (o = n(this, O)) == null || o.sendData("/worldorigin/new", {
235
+ gpsCount: n(this, I),
235
236
  lat: t.coords.latitude,
236
237
  lon: t.coords.longitude,
237
- session: i(this, E),
238
- initialPosition: i(this, m)
239
- })), u(this, l, H).call(this, this.camera, t.coords.longitude, t.coords.latitude), (h = i(this, p)) == null || h.sendData("/gps/accepted", {
240
- gpsCount: i(this, y),
238
+ session: n(this, b),
239
+ initialPosition: n(this, E)
240
+ })), v(this, p, S).call(this, this.camera, t.coords.longitude, t.coords.latitude), (u = n(this, O)) == null || u.sendData("/gps/accepted", {
241
+ gpsCount: n(this, I),
241
242
  cameraX: this.camera.position.x,
242
243
  cameraZ: this.camera.position.z,
243
- session: i(this, E),
244
+ session: n(this, b),
244
245
  distMoved: e
245
- }), i(this, M).gpsupdate && i(this, M).gpsupdate(t, e)));
246
+ }), n(this, A).gpsupdate && n(this, A).gpsupdate(t, e)));
246
247
  }, /**
247
248
  * Calculate haversine distance between two lat/lon pairs.
248
249
  *
249
250
  * Taken from original A-Frame AR.js location-based components
250
251
  */
251
- G = function(t, e) {
252
- const s = o.MathUtils.degToRad(e.longitude - t.longitude), n = o.MathUtils.degToRad(e.latitude - t.latitude), h = Math.sin(n / 2) * Math.sin(n / 2) + Math.cos(o.MathUtils.degToRad(t.latitude)) * Math.cos(o.MathUtils.degToRad(e.latitude)) * (Math.sin(s / 2) * Math.sin(s / 2));
253
- return 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)) * 6371e3;
252
+ Y = function(t, e) {
253
+ const i = f.MathUtils.degToRad(e.longitude - t.longitude), o = f.MathUtils.degToRad(e.latitude - t.latitude), u = Math.sin(o / 2) * Math.sin(o / 2) + Math.cos(f.MathUtils.degToRad(t.latitude)) * Math.cos(f.MathUtils.degToRad(e.latitude)) * (Math.sin(i / 2) * Math.sin(i / 2));
254
+ return 2 * Math.atan2(Math.sqrt(u), Math.sqrt(1 - u)) * 6371e3;
254
255
  };
255
- class Z {
256
+ class ot {
256
257
  /**
257
258
  * Create a WebcamRenderer.
258
259
  * @param {THREE.WebGLRenderer} renderer - the Three.js renderer.
@@ -262,12 +263,12 @@ class Z {
262
263
  * @options {Object} - options to use for initialising the camera. Currently
263
264
  * width and height properties are understood.
264
265
  */
265
- constructor(t, e, s) {
266
- this.renderer = t, this.renderer.autoClear = !1, this.sceneWebcam = new o.Scene();
267
- let n;
268
- e ? n = document.querySelector(e) : (n = document.createElement("video"), n.setAttribute("autoplay", !0), n.setAttribute("playsinline", !0), n.style.display = "none", document.body.appendChild(n)), this.geom = new o.PlaneGeometry(), this.texture = new o.VideoTexture(n), this.material = new o.MeshBasicMaterial({ map: this.texture });
269
- const h = new o.Mesh(this.geom, this.material);
270
- if (this.sceneWebcam.add(h), this.cameraWebcam = new o.OrthographicCamera(
266
+ constructor(t, e, i) {
267
+ this.renderer = t, this.renderer.autoClear = !1, this.sceneWebcam = new f.Scene();
268
+ let o;
269
+ e ? o = document.querySelector(e) : (o = document.createElement("video"), o.setAttribute("autoplay", !0), o.setAttribute("playsinline", !0), o.style.display = "none", document.body.appendChild(o)), this.geom = new f.PlaneGeometry(), this.texture = new f.VideoTexture(o), this.material = new f.MeshBasicMaterial({ map: this.texture });
270
+ const u = new f.Mesh(this.geom, this.material);
271
+ if (this.sceneWebcam.add(u), this.cameraWebcam = new f.OrthographicCamera(
271
272
  -0.5,
272
273
  0.5,
273
274
  0.5,
@@ -277,19 +278,19 @@ class Z {
277
278
  ), navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
278
279
  const g = {
279
280
  video: {
280
- width: (s == null ? void 0 : s.width) || 1280,
281
- height: (s == null ? void 0 : s.height) || 720,
281
+ width: (i == null ? void 0 : i.width) || 1280,
282
+ height: (i == null ? void 0 : i.height) || 720,
282
283
  facingMode: "environment"
283
284
  }
284
285
  };
285
- navigator.mediaDevices.getUserMedia(g).then((T) => {
286
- console.log("using the webcam successfully..."), n.srcObject = T, n.play();
287
- }).catch((T) => {
286
+ navigator.mediaDevices.getUserMedia(g).then((w) => {
287
+ console.log("using the webcam successfully..."), o.srcObject = w, o.play();
288
+ }).catch((w) => {
288
289
  setTimeout(() => {
289
290
  alert(
290
291
  `Webcam Error
291
- Name: ` + T.name + `
292
- Message: ` + T.message
292
+ Name: ` + w.name + `
293
+ Message: ` + w.message
293
294
  );
294
295
  }, 1e3);
295
296
  });
@@ -313,52 +314,199 @@ Message: ` + T.message
313
314
  this.material.dispose(), this.texture.dispose(), this.geom.dispose();
314
315
  }
315
316
  }
316
- const z = new o.Vector3(0, 0, 1), U = new o.Euler(), Q = new o.Quaternion(), X = new o.Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)), V = { type: "change" };
317
- class B extends o.EventDispatcher {
317
+ const k = navigator.userAgent.match(/iPhone|iPad|iPod/i) || /Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints != null && navigator.maxTouchPoints > 1, $ = new Z(0, 0, 1), z = new N(), J = new _(), tt = new _(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)), et = { type: "change" };
318
+ class at extends B {
318
319
  /**
319
320
  * Create an instance of DeviceOrientationControls.
320
321
  * @param {Object} object - the object to attach the controls to
321
322
  * (usually your Three.js camera)
322
323
  */
323
324
  constructor(t) {
324
- super(), window.isSecureContext === !1 && console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");
325
- const e = this, s = 1e-6, n = new o.Quaternion();
326
- this.object = t, this.object.rotation.reorder("YXZ"), this.enabled = !0, this.deviceOrientation = {}, this.screenOrientation = 0, this.alphaOffset = 0, this.deviceOrientationEventName = "ondeviceorientationabsolute" in window ? "deviceorientationabsolute" : "deviceorientation";
327
- const h = function(c) {
328
- e.deviceOrientation = c;
325
+ super(), window.isSecureContext === !1 && console.error(
326
+ "THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)"
327
+ );
328
+ const e = this, i = 1e-6, o = new _();
329
+ this.object = t, this.object.rotation.reorder("YXZ"), this.enabled = !0, this.deviceOrientation = null, this.screenOrientation = 0, this.alphaOffset = 0, this.initialOffset = null, this.TWO_PI = 2 * Math.PI, this.HALF_PI = 0.5 * Math.PI, this.orientationChangeEventName = "ondeviceorientationabsolute" in window ? "deviceorientationabsolute" : "deviceorientation", this.smoothingFactor = 1;
330
+ const u = function({
331
+ alpha: s,
332
+ beta: c,
333
+ gamma: h,
334
+ webkitCompassHeading: a
335
+ }) {
336
+ if (k) {
337
+ const l = 360 - a;
338
+ e.alphaOffset = D.degToRad(l - s), e.deviceOrientation = { alpha: s, beta: c, gamma: h, webkitCompassHeading: a };
339
+ } else
340
+ s < 0 && (s += 360), e.deviceOrientation = { alpha: s, beta: c, gamma: h };
341
+ window.dispatchEvent(
342
+ new CustomEvent("camera-rotation-change", {
343
+ detail: { cameraRotation: t.rotation }
344
+ })
345
+ );
329
346
  }, g = function() {
330
347
  e.screenOrientation = window.orientation || 0;
331
- }, T = function(c, D, A, R, C) {
332
- U.set(A, D, -R, "YXZ"), c.setFromEuler(U), c.multiply(X), c.multiply(Q.setFromAxisAngle(z, -C));
348
+ }, w = function(s, c, h, a, l) {
349
+ z.set(h, c, -a, "YXZ"), s.setFromEuler(z), s.multiply(tt), s.multiply(J.setFromAxisAngle($, -l));
333
350
  };
334
351
  this.connect = function() {
335
- g(), window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? window.DeviceOrientationEvent.requestPermission().then(function(c) {
336
- c == "granted" && (window.addEventListener("orientationchange", g), window.addEventListener(e.deviceOrientationEventName, h));
337
- }).catch(function(c) {
338
- console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:", c);
339
- }) : (window.addEventListener("orientationchange", g), window.addEventListener(e.deviceOrientationEventName, h)), e.enabled = !0;
352
+ g(), window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? window.DeviceOrientationEvent.requestPermission().then((s) => {
353
+ s === "granted" && (window.addEventListener(
354
+ "orientationchange",
355
+ g
356
+ ), window.addEventListener(
357
+ e.orientationChangeEventName,
358
+ u
359
+ ));
360
+ }).catch(function(s) {
361
+ console.error(
362
+ "THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",
363
+ s
364
+ );
365
+ }) : (window.addEventListener(
366
+ "orientationchange",
367
+ g
368
+ ), window.addEventListener(
369
+ e.orientationChangeEventName,
370
+ u
371
+ )), e.enabled = !0;
340
372
  }, this.disconnect = function() {
341
- window.removeEventListener("orientationchange", g), window.removeEventListener(e.deviceOrientationEventName, h), e.enabled = !1;
342
- }, this.update = function() {
373
+ window.removeEventListener(
374
+ "orientationchange",
375
+ g
376
+ ), window.removeEventListener(
377
+ e.orientationChangeEventName,
378
+ u
379
+ ), e.enabled = !1, e.initialOffset = !1, e.deviceOrientation = null;
380
+ }, this.update = function({ theta: s = 0 } = { theta: 0 }) {
343
381
  if (e.enabled === !1) return;
344
382
  const c = e.deviceOrientation;
345
383
  if (c) {
346
- const D = c.alpha ? o.MathUtils.degToRad(c.alpha) + e.alphaOffset : 0, A = c.beta ? o.MathUtils.degToRad(c.beta) : 0, R = c.gamma ? o.MathUtils.degToRad(c.gamma) : 0, C = e.screenOrientation ? o.MathUtils.degToRad(e.screenOrientation) : 0;
347
- T(e.object.quaternion, D, A, R, C), 8 * (1 - n.dot(e.object.quaternion)) > s && (n.copy(e.object.quaternion), e.dispatchEvent(V));
384
+ let h = c.alpha ? D.degToRad(c.alpha) + e.alphaOffset : 0, a = c.beta ? D.degToRad(c.beta) : 0, l = c.gamma ? D.degToRad(c.gamma) : 0;
385
+ const H = e.screenOrientation ? D.degToRad(e.screenOrientation) : 0;
386
+ if (k) {
387
+ const y = new _();
388
+ w(y, h, a, l, H);
389
+ const M = new N().setFromQuaternion(
390
+ y,
391
+ "YXZ"
392
+ );
393
+ console.log(M.x, M.y, M.z), M.y = D.degToRad(
394
+ 360 - c.webkitCompassHeading
395
+ ), y.setFromEuler(M), e.object.quaternion.copy(y);
396
+ } else {
397
+ if (this.smoothingFactor < 1) {
398
+ if (this.lastOrientation) {
399
+ const y = this.smoothingFactor;
400
+ h = this._getSmoothedAngle(
401
+ h,
402
+ this.lastOrientation.alpha,
403
+ y
404
+ ), a = this._getSmoothedAngle(
405
+ a + Math.PI,
406
+ this.lastOrientation.beta,
407
+ y
408
+ ), l = this._getSmoothedAngle(
409
+ l + this.HALF_PI,
410
+ this.lastOrientation.gamma,
411
+ y,
412
+ Math.PI
413
+ );
414
+ } else
415
+ a += Math.PI, l += this.HALF_PI;
416
+ this.lastOrientation = {
417
+ alpha: h,
418
+ beta: a,
419
+ gamma: l
420
+ };
421
+ }
422
+ w(
423
+ e.object.quaternion,
424
+ h + s,
425
+ this.smoothingFactor < 1 ? a - Math.PI : a,
426
+ this.smoothingFactor < 1 ? l - this.HALF_PI : l,
427
+ H
428
+ );
429
+ }
430
+ 8 * (1 - o.dot(e.object.quaternion)) > i && (o.copy(e.object.quaternion), e.dispatchEvent(et));
348
431
  }
432
+ }, this._orderAngle = function(s, c, h = this.TWO_PI) {
433
+ return c > s && Math.abs(c - s) < h / 2 || s > c && Math.abs(c - s) > h / 2 ? { left: s, right: c } : { left: c, right: s };
434
+ }, this._getSmoothedAngle = function(s, c, h, a = this.TWO_PI) {
435
+ const l = this._orderAngle(s, c, a), H = l.left, y = l.right;
436
+ l.left = 0, l.right -= H, l.right < 0 && (l.right += a);
437
+ let M = y == c ? (1 - h) * l.right + h * l.left : h * l.right + (1 - h) * l.left;
438
+ return M += H, M >= a && (M -= a), M;
439
+ }, this.updateAlphaOffset = function() {
440
+ e.initialOffset = !1;
349
441
  }, this.dispose = function() {
350
442
  e.disconnect();
351
- }, this.connect();
443
+ }, this.getAlpha = function() {
444
+ const { deviceOrientation: s } = e;
445
+ return s && s.alpha ? D.degToRad(s.alpha) + e.alphaOffset : 0;
446
+ }, this.getBeta = function() {
447
+ const { deviceOrientation: s } = e;
448
+ return s && s.beta ? D.degToRad(s.beta) : 0;
449
+ }, window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? this.initPermissionDialog() : this.connect();
450
+ }
451
+ // Provide gesture before initialising device orientation controls
452
+ // From PR #659 on the main AR.js repo
453
+ // Thanks to @ma2yama
454
+ initPermissionDialog() {
455
+ const t = document.createElement("div"), e = document.createElement("div"), i = document.createElement("div"), o = document.createElement("div");
456
+ document.body.appendChild(t);
457
+ const u = {
458
+ display: "flex",
459
+ position: "fixed",
460
+ top: 0,
461
+ left: 0,
462
+ width: "100%",
463
+ height: "100%",
464
+ zIndex: 1,
465
+ backgroundColor: "rgba(0,0,0,0.6)",
466
+ justifyContent: "center",
467
+ alignItems: "center"
468
+ }, g = {
469
+ backgroundColor: "white",
470
+ padding: "6px",
471
+ borderRadius: "3px",
472
+ width: "36rem",
473
+ height: "24rem"
474
+ }, w = {
475
+ width: "100%",
476
+ height: "70%",
477
+ display: "flex",
478
+ justifyContent: "center",
479
+ alignItems: "center"
480
+ }, s = {
481
+ display: "inline-flex",
482
+ width: "100%",
483
+ height: "30%",
484
+ justifyContent: "center",
485
+ alignItems: "center"
486
+ };
487
+ for (let a in u)
488
+ t.style[a] = u[a];
489
+ for (let a in g)
490
+ e.style[a] = g[a];
491
+ for (let a in w)
492
+ i.style[a] = w[a];
493
+ for (let a in s)
494
+ o.style[a] = s[a];
495
+ t.appendChild(e), e.appendChild(i), e.appendChild(o), i.innerHTML = '<div style="font-size: 24pt; margin: 1rem;">This immersive website requires access to your device motion sensors.</div>';
496
+ const c = () => {
497
+ this.connect(), t.style.display = "none";
498
+ }, h = document.createElement("button");
499
+ h.addEventListener("click", c), h.style.width = "50%", h.style.height = "80%", h.style.fontSize = "20pt", h.appendChild(document.createTextNode("OK")), o.appendChild(h), document.body.appendChild(t);
352
500
  }
353
501
  }
354
- class $ {
502
+ class rt {
355
503
  /**
356
504
  * Create a ClickHandler.
357
505
  * @param {THREE.WebGLRenderer} - The Three.js renderer on which the click
358
506
  * events will be handled.
359
507
  */
360
508
  constructor(t) {
361
- this.raycaster = new o.Raycaster(), this.normalisedMousePosition = new o.Vector2(null, null), t.domElement.addEventListener("click", (e) => {
509
+ this.raycaster = new f.Raycaster(), this.normalisedMousePosition = new f.Vector2(null, null), t.domElement.addEventListener("click", (e) => {
362
510
  this.normalisedMousePosition.set(
363
511
  e.clientX / t.domElement.clientWidth * 2 - 1,
364
512
  -(e.clientY / t.domElement.clientHeight * 2) + 1
@@ -376,16 +524,16 @@ class $ {
376
524
  raycast(t, e) {
377
525
  if (this.normalisedMousePosition.x !== null && this.normalisedMousePosition.y !== null) {
378
526
  this.raycaster.setFromCamera(this.normalisedMousePosition, t);
379
- const s = this.raycaster.intersectObjects(e.children, !1);
380
- return this.normalisedMousePosition.set(null, null), s;
527
+ const i = this.raycaster.intersectObjects(e.children, !1);
528
+ return this.normalisedMousePosition.set(null, null), i;
381
529
  }
382
530
  return [];
383
531
  }
384
532
  }
385
533
  export {
386
- $ as ClickHandler,
387
- B as DeviceOrientationControls,
388
- Y as LocationBased,
389
- N as SphMercProjection,
390
- Z as WebcamRenderer
534
+ rt as ClickHandler,
535
+ at as DeviceOrientationControls,
536
+ st as LocationBased,
537
+ K as SphMercProjection,
538
+ ot as WebcamRenderer
391
539
  };
package/dist/locar.umd.js CHANGED
@@ -1,3 +1,3 @@
1
- (function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.locar={},s.THREE))})(this,function(s,r){"use strict";var q=s=>{throw TypeError(s)};var _=(s,r,h)=>r.has(s)||q("Cannot "+h);var i=(s,r,h)=>(_(s,r,"read from private field"),h?h.call(s):r.get(s)),u=(s,r,h)=>r.has(s)?q("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(s):r.set(s,h),c=(s,r,h,o)=>(_(s,r,"write to private field"),o?o.call(s,h):r.set(s,h),h),m=(s,r,h)=>(_(s,r,"access private method"),h);var I=(s,r,h,o)=>({set _(C){c(s,r,C,h)},get _(){return i(s,r,o)}});var f,F,N,G,z,P,E,y,D,A,O,p,T,b,v,g,S,k,x,Q;function h(M){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(M){for(const t in M)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(M,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>M[t]})}}return e.default=M,Object.freeze(e)}const o=h(r);class C{constructor(){u(this,f);this.EARTH=4007501668e-2,this.HALF_EARTH=2003750834e-2}project(e,t){return[m(this,f,F).call(this,e),m(this,f,N).call(this,t)]}unproject(e){return[m(this,f,G).call(this,e[0]),m(this,f,z).call(this,e[1])]}getID(){return"epsg:3857"}}f=new WeakSet,F=function(e){return e/180*this.HALF_EARTH},N=function(e){var t=Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180);return t*this.HALF_EARTH/180},G=function(e){return e/this.HALF_EARTH*180},z=function(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};class X{constructor(e,t,n={},a=null){u(this,g);u(this,P);u(this,E);u(this,y);u(this,D);u(this,A);u(this,O);u(this,p);u(this,T);u(this,b);u(this,v);this.scene=e,this.camera=t,c(this,P,new C),c(this,E,{}),c(this,y,null),c(this,D,0),c(this,A,100),c(this,O,null),this.setGpsOptions(n),c(this,p,null),c(this,T,0),c(this,b,0),c(this,v,a)}setProjection(e){c(this,P,e)}setGpsOptions(e={}){e.gpsMinDistance!==void 0&&c(this,D,e.gpsMinDistance),e.gpsMinAccuracy!==void 0&&c(this,A,e.gpsMinAccuracy)}async startGps(){if(i(this,v)){const t=await(await i(this,v).sendData("/gps/start",{gpsMinDistance:i(this,D),gpsMinAccuracy:i(this,A)})).json();c(this,b,t.session)}return i(this,O)===null?(c(this,O,navigator.geolocation.watchPosition(e=>{m(this,g,x).call(this,e)},e=>{i(this,E).gpserror?i(this,E).gpserror(e.code):alert(`GPS error: code ${e.code}`)},{enableHighAccuracy:!0})),!0):!1}stopGps(){return i(this,O)!==null?(navigator.geolocation.clearWatch(i(this,O)),c(this,O,null),!0):!1}fakeGps(e,t,n=null,a=0){n!==null&&this.setElevation(n),m(this,g,x).call(this,{coords:{longitude:e,latitude:t,accuracy:a}})}lonLatToWorldCoords(e,t){const n=i(this,P).project(e,t);if(i(this,p))n[0]-=i(this,p)[0],n[1]-=i(this,p)[1];else throw"No initial position determined";return[n[0],-n[1]]}add(e,t,n,a,l={}){var w;e.properties=l,m(this,g,S).call(this,e,t,n,a),this.scene.add(e),(w=i(this,v))==null||w.sendData("/object/new",{position:e.position,x:e.position.x,z:e.position.z,session:i(this,b),properties:l})}setElevation(e){this.camera.position.y=e}on(e,t){i(this,E)[e]=t}}P=new WeakMap,E=new WeakMap,y=new WeakMap,D=new WeakMap,A=new WeakMap,O=new WeakMap,p=new WeakMap,T=new WeakMap,b=new WeakMap,v=new WeakMap,g=new WeakSet,S=function(e,t,n,a){const l=this.lonLatToWorldCoords(t,n);a!==void 0&&(e.position.y=a),[e.position.x,e.position.z]=l},k=function(e,t){c(this,p,i(this,P).project(e,t))},x=function(e){var n,a,l;let t=Number.MAX_VALUE;I(this,T)._++,(n=i(this,v))==null||n.sendData("/gps/new",{gpsCount:i(this,T),lat:e.coords.latitude,lon:e.coords.longitude,acc:e.coords.accuracy,session:i(this,b)}),e.coords.accuracy<=i(this,A)&&(i(this,y)===null?c(this,y,{latitude:e.coords.latitude,longitude:e.coords.longitude}):t=m(this,g,Q).call(this,i(this,y),e.coords),t>=i(this,D)&&(i(this,y).longitude=e.coords.longitude,i(this,y).latitude=e.coords.latitude,i(this,p)||(m(this,g,k).call(this,e.coords.longitude,e.coords.latitude),(a=i(this,v))==null||a.sendData("/worldorigin/new",{gpsCount:i(this,T),lat:e.coords.latitude,lon:e.coords.longitude,session:i(this,b),initialPosition:i(this,p)})),m(this,g,S).call(this,this.camera,e.coords.longitude,e.coords.latitude),(l=i(this,v))==null||l.sendData("/gps/accepted",{gpsCount:i(this,T),cameraX:this.camera.position.x,cameraZ:this.camera.position.z,session:i(this,b),distMoved:t}),i(this,E).gpsupdate&&i(this,E).gpsupdate(e,t)))},Q=function(e,t){const n=o.MathUtils.degToRad(t.longitude-e.longitude),a=o.MathUtils.degToRad(t.latitude-e.latitude),l=Math.sin(a/2)*Math.sin(a/2)+Math.cos(o.MathUtils.degToRad(e.latitude))*Math.cos(o.MathUtils.degToRad(t.latitude))*(Math.sin(n/2)*Math.sin(n/2));return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3};class V{constructor(e,t,n){this.renderer=e,this.renderer.autoClear=!1,this.sceneWebcam=new o.Scene;let a;t?a=document.querySelector(t):(a=document.createElement("video"),a.setAttribute("autoplay",!0),a.setAttribute("playsinline",!0),a.style.display="none",document.body.appendChild(a)),this.geom=new o.PlaneGeometry,this.texture=new o.VideoTexture(a),this.material=new o.MeshBasicMaterial({map:this.texture});const l=new o.Mesh(this.geom,this.material);if(this.sceneWebcam.add(l),this.cameraWebcam=new o.OrthographicCamera(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const w={video:{width:(n==null?void 0:n.width)||1280,height:(n==null?void 0:n.height)||720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(w).then(R=>{console.log("using the webcam successfully..."),a.srcObject=R,a.play()}).catch(R=>{setTimeout(()=>{alert(`Webcam Error
2
- Name: `+R.name+`
3
- Message: `+R.message)},1e3)})}else setTimeout(()=>{alert("sorry - media devices API not supported")},1e3)}update(){this.renderer.clear(),this.renderer.render(this.sceneWebcam,this.cameraWebcam),this.renderer.clearDepth()}dispose(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}}const B=new o.Vector3(0,0,1),U=new o.Euler,Y=new o.Quaternion,Z=new o.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),$={type:"change"};class J extends o.EventDispatcher{constructor(e){super(),window.isSecureContext===!1&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const t=this,n=1e-6,a=new o.Quaternion;this.object=e,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation={},this.screenOrientation=0,this.alphaOffset=0,this.deviceOrientationEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation";const l=function(d){t.deviceOrientation=d},w=function(){t.screenOrientation=window.orientation||0},R=function(d,H,L,j,W){U.set(L,H,-j,"YXZ"),d.setFromEuler(U),d.multiply(Z),d.multiply(Y.setFromAxisAngle(B,-W))};this.connect=function(){w(),window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission=="function"?window.DeviceOrientationEvent.requestPermission().then(function(d){d=="granted"&&(window.addEventListener("orientationchange",w),window.addEventListener(t.deviceOrientationEventName,l))}).catch(function(d){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",d)}):(window.addEventListener("orientationchange",w),window.addEventListener(t.deviceOrientationEventName,l)),t.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",w),window.removeEventListener(t.deviceOrientationEventName,l),t.enabled=!1},this.update=function(){if(t.enabled===!1)return;const d=t.deviceOrientation;if(d){const H=d.alpha?o.MathUtils.degToRad(d.alpha)+t.alphaOffset:0,L=d.beta?o.MathUtils.degToRad(d.beta):0,j=d.gamma?o.MathUtils.degToRad(d.gamma):0,W=t.screenOrientation?o.MathUtils.degToRad(t.screenOrientation):0;R(t.object.quaternion,H,L,j,W),8*(1-a.dot(t.object.quaternion))>n&&(a.copy(t.object.quaternion),t.dispatchEvent($))}},this.dispose=function(){t.disconnect()},this.connect()}}class K{constructor(e){this.raycaster=new o.Raycaster,this.normalisedMousePosition=new o.Vector2(null,null),e.domElement.addEventListener("click",t=>{this.normalisedMousePosition.set(t.clientX/e.domElement.clientWidth*2-1,-(t.clientY/e.domElement.clientHeight*2)+1)})}raycast(e,t){if(this.normalisedMousePosition.x!==null&&this.normalisedMousePosition.y!==null){this.raycaster.setFromCamera(this.normalisedMousePosition,e);const n=this.raycaster.intersectObjects(t.children,!1);return this.normalisedMousePosition.set(null,null),n}return[]}}s.ClickHandler=K,s.DeviceOrientationControls=J,s.LocationBased=X,s.SphMercProjection=C,s.WebcamRenderer=V,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],i):(a=typeof globalThis<"u"?globalThis:a||self,i(a.locar={},a.THREE))})(this,function(a,i){"use strict";var H=a=>{throw TypeError(a)};var U=(a,i,f)=>i.has(a)||H("Cannot "+f);var n=(a,i,f)=>(U(a,i,"read from private field"),f?f.call(a):i.get(a)),v=(a,i,f)=>i.has(a)?H("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(a):i.set(a,f),u=(a,i,f,m)=>(U(a,i,"write to private field"),m?m.call(a,f):i.set(a,f),f),y=(a,i,f)=>(U(a,i,"access private method"),f);var N=(a,i,f,m)=>({set _(W){u(a,i,W,f)},get _(){return n(a,i,m)}});var w,Q,G,X,B,S,I,T,x,j,_,O,E,L,P,M,q,V,R,Y;function f(b){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const e in b)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>b[e]})}}return t.default=b,Object.freeze(t)}const m=f(i);class W{constructor(){v(this,w);this.EARTH=4007501668e-2,this.HALF_EARTH=2003750834e-2}project(t,e){return[y(this,w,Q).call(this,t),y(this,w,G).call(this,e)]}unproject(t){return[y(this,w,X).call(this,t[0]),y(this,w,B).call(this,t[1])]}getID(){return"epsg:3857"}}w=new WeakSet,Q=function(t){return t/180*this.HALF_EARTH},G=function(t){var e=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return e*this.HALF_EARTH/180},X=function(t){return t/this.HALF_EARTH*180},B=function(t){var e=t/this.HALF_EARTH*180;return e=180/Math.PI*(2*Math.atan(Math.exp(e*Math.PI/180))-Math.PI/2),e};class Z{constructor(t,e,s={},r=null){v(this,M);v(this,S);v(this,I);v(this,T);v(this,x);v(this,j);v(this,_);v(this,O);v(this,E);v(this,L);v(this,P);this.scene=t,this.camera=e,u(this,S,new W),u(this,I,{}),u(this,T,null),u(this,x,0),u(this,j,100),u(this,_,null),this.setGpsOptions(s),u(this,O,null),u(this,E,0),u(this,L,0),u(this,P,r)}setProjection(t){u(this,S,t)}setGpsOptions(t={}){t.gpsMinDistance!==void 0&&u(this,x,t.gpsMinDistance),t.gpsMinAccuracy!==void 0&&u(this,j,t.gpsMinAccuracy)}async startGps(){if(n(this,P)){const e=await(await n(this,P).sendData("/gps/start",{gpsMinDistance:n(this,x),gpsMinAccuracy:n(this,j)})).json();u(this,L,e.session)}return n(this,_)===null?(u(this,_,navigator.geolocation.watchPosition(t=>{y(this,M,R).call(this,t)},t=>{n(this,I).gpserror?n(this,I).gpserror(t.code):alert(`GPS error: code ${t.code}`)},{enableHighAccuracy:!0})),!0):!1}stopGps(){return n(this,_)!==null?(navigator.geolocation.clearWatch(n(this,_)),u(this,_,null),!0):!1}fakeGps(t,e,s=null,r=0){s!==null&&this.setElevation(s),y(this,M,R).call(this,{coords:{longitude:t,latitude:e,accuracy:r}})}lonLatToWorldCoords(t,e){const s=n(this,S).project(t,e);if(n(this,O))s[0]-=n(this,O)[0],s[1]-=n(this,O)[1];else throw"No initial position determined";return[s[0],-s[1]]}add(t,e,s,r,g={}){var p;t.properties=g,y(this,M,q).call(this,t,e,s,r),this.scene.add(t),(p=n(this,P))==null||p.sendData("/object/new",{position:t.position,x:t.position.x,z:t.position.z,session:n(this,L),properties:g})}setElevation(t){this.camera.position.y=t}on(t,e){n(this,I)[t]=e}}S=new WeakMap,I=new WeakMap,T=new WeakMap,x=new WeakMap,j=new WeakMap,_=new WeakMap,O=new WeakMap,E=new WeakMap,L=new WeakMap,P=new WeakMap,M=new WeakSet,q=function(t,e,s,r){const g=this.lonLatToWorldCoords(e,s);r!==void 0&&(t.position.y=r),[t.position.x,t.position.z]=g},V=function(t,e){u(this,O,n(this,S).project(t,e))},R=function(t){var s,r,g;let e=Number.MAX_VALUE;N(this,E)._++,(s=n(this,P))==null||s.sendData("/gps/new",{gpsCount:n(this,E),lat:t.coords.latitude,lon:t.coords.longitude,acc:t.coords.accuracy,session:n(this,L)}),t.coords.accuracy<=n(this,j)&&(n(this,T)===null?u(this,T,{latitude:t.coords.latitude,longitude:t.coords.longitude}):e=y(this,M,Y).call(this,n(this,T),t.coords),e>=n(this,x)&&(n(this,T).longitude=t.coords.longitude,n(this,T).latitude=t.coords.latitude,n(this,O)||(y(this,M,V).call(this,t.coords.longitude,t.coords.latitude),(r=n(this,P))==null||r.sendData("/worldorigin/new",{gpsCount:n(this,E),lat:t.coords.latitude,lon:t.coords.longitude,session:n(this,L),initialPosition:n(this,O)})),y(this,M,q).call(this,this.camera,t.coords.longitude,t.coords.latitude),(g=n(this,P))==null||g.sendData("/gps/accepted",{gpsCount:n(this,E),cameraX:this.camera.position.x,cameraZ:this.camera.position.z,session:n(this,L),distMoved:e}),n(this,I).gpsupdate&&n(this,I).gpsupdate(t,e)))},Y=function(t,e){const s=m.MathUtils.degToRad(e.longitude-t.longitude),r=m.MathUtils.degToRad(e.latitude-t.latitude),g=Math.sin(r/2)*Math.sin(r/2)+Math.cos(m.MathUtils.degToRad(t.latitude))*Math.cos(m.MathUtils.degToRad(e.latitude))*(Math.sin(s/2)*Math.sin(s/2));return 2*Math.atan2(Math.sqrt(g),Math.sqrt(1-g))*6371e3};class K{constructor(t,e,s){this.renderer=t,this.renderer.autoClear=!1,this.sceneWebcam=new m.Scene;let r;e?r=document.querySelector(e):(r=document.createElement("video"),r.setAttribute("autoplay",!0),r.setAttribute("playsinline",!0),r.style.display="none",document.body.appendChild(r)),this.geom=new m.PlaneGeometry,this.texture=new m.VideoTexture(r),this.material=new m.MeshBasicMaterial({map:this.texture});const g=new m.Mesh(this.geom,this.material);if(this.sceneWebcam.add(g),this.cameraWebcam=new m.OrthographicCamera(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const p={video:{width:(s==null?void 0:s.width)||1280,height:(s==null?void 0:s.height)||720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(p).then(A=>{console.log("using the webcam successfully..."),r.srcObject=A,r.play()}).catch(A=>{setTimeout(()=>{alert(`Webcam Error
2
+ Name: `+A.name+`
3
+ Message: `+A.message)},1e3)})}else setTimeout(()=>{alert("sorry - media devices API not supported")},1e3)}update(){this.renderer.clear(),this.renderer.render(this.sceneWebcam,this.cameraWebcam),this.renderer.clearDepth()}dispose(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}}const k=navigator.userAgent.match(/iPhone|iPad|iPod/i)||/Macintosh/i.test(navigator.userAgent)&&navigator.maxTouchPoints!=null&&navigator.maxTouchPoints>1,$=new i.Vector3(0,0,1),z=new i.Euler,J=new i.Quaternion,tt=new i.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),et={type:"change"};class it extends i.EventDispatcher{constructor(t){super(),window.isSecureContext===!1&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const e=this,s=1e-6,r=new i.Quaternion;this.object=t,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation=null,this.screenOrientation=0,this.alphaOffset=0,this.initialOffset=null,this.TWO_PI=2*Math.PI,this.HALF_PI=.5*Math.PI,this.orientationChangeEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation",this.smoothingFactor=1;const g=function({alpha:o,beta:h,gamma:l,webkitCompassHeading:c}){if(k){const d=360-c;e.alphaOffset=i.MathUtils.degToRad(d-o),e.deviceOrientation={alpha:o,beta:h,gamma:l,webkitCompassHeading:c}}else o<0&&(o+=360),e.deviceOrientation={alpha:o,beta:h,gamma:l};window.dispatchEvent(new CustomEvent("camera-rotation-change",{detail:{cameraRotation:t.rotation}}))},p=function(){e.screenOrientation=window.orientation||0},A=function(o,h,l,c,d){z.set(l,h,-c,"YXZ"),o.setFromEuler(z),o.multiply(tt),o.multiply(J.setFromAxisAngle($,-d))};this.connect=function(){p(),window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission=="function"?window.DeviceOrientationEvent.requestPermission().then(o=>{o==="granted"&&(window.addEventListener("orientationchange",p),window.addEventListener(e.orientationChangeEventName,g))}).catch(function(o){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",o)}):(window.addEventListener("orientationchange",p),window.addEventListener(e.orientationChangeEventName,g)),e.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",p),window.removeEventListener(e.orientationChangeEventName,g),e.enabled=!1,e.initialOffset=!1,e.deviceOrientation=null},this.update=function({theta:o=0}={theta:0}){if(e.enabled===!1)return;const h=e.deviceOrientation;if(h){let l=h.alpha?i.MathUtils.degToRad(h.alpha)+e.alphaOffset:0,c=h.beta?i.MathUtils.degToRad(h.beta):0,d=h.gamma?i.MathUtils.degToRad(h.gamma):0;const F=e.screenOrientation?i.MathUtils.degToRad(e.screenOrientation):0;if(k){const C=new i.Quaternion;A(C,l,c,d,F);const D=new i.Euler().setFromQuaternion(C,"YXZ");console.log(D.x,D.y,D.z),D.y=i.MathUtils.degToRad(360-h.webkitCompassHeading),C.setFromEuler(D),e.object.quaternion.copy(C)}else{if(this.smoothingFactor<1){if(this.lastOrientation){const C=this.smoothingFactor;l=this._getSmoothedAngle(l,this.lastOrientation.alpha,C),c=this._getSmoothedAngle(c+Math.PI,this.lastOrientation.beta,C),d=this._getSmoothedAngle(d+this.HALF_PI,this.lastOrientation.gamma,C,Math.PI)}else c+=Math.PI,d+=this.HALF_PI;this.lastOrientation={alpha:l,beta:c,gamma:d}}A(e.object.quaternion,l+o,this.smoothingFactor<1?c-Math.PI:c,this.smoothingFactor<1?d-this.HALF_PI:d,F)}8*(1-r.dot(e.object.quaternion))>s&&(r.copy(e.object.quaternion),e.dispatchEvent(et))}},this._orderAngle=function(o,h,l=this.TWO_PI){return h>o&&Math.abs(h-o)<l/2||o>h&&Math.abs(h-o)>l/2?{left:o,right:h}:{left:h,right:o}},this._getSmoothedAngle=function(o,h,l,c=this.TWO_PI){const d=this._orderAngle(o,h,c),F=d.left,C=d.right;d.left=0,d.right-=F,d.right<0&&(d.right+=c);let D=C==h?(1-l)*d.right+l*d.left:l*d.right+(1-l)*d.left;return D+=F,D>=c&&(D-=c),D},this.updateAlphaOffset=function(){e.initialOffset=!1},this.dispose=function(){e.disconnect()},this.getAlpha=function(){const{deviceOrientation:o}=e;return o&&o.alpha?i.MathUtils.degToRad(o.alpha)+e.alphaOffset:0},this.getBeta=function(){const{deviceOrientation:o}=e;return o&&o.beta?i.MathUtils.degToRad(o.beta):0},window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission=="function"?this.initPermissionDialog():this.connect()}initPermissionDialog(){const t=document.createElement("div"),e=document.createElement("div"),s=document.createElement("div"),r=document.createElement("div");document.body.appendChild(t);const g={display:"flex",position:"fixed",top:0,left:0,width:"100%",height:"100%",zIndex:1,backgroundColor:"rgba(0,0,0,0.6)",justifyContent:"center",alignItems:"center"},p={backgroundColor:"white",padding:"6px",borderRadius:"3px",width:"36rem",height:"24rem"},A={width:"100%",height:"70%",display:"flex",justifyContent:"center",alignItems:"center"},o={display:"inline-flex",width:"100%",height:"30%",justifyContent:"center",alignItems:"center"};for(let c in g)t.style[c]=g[c];for(let c in p)e.style[c]=p[c];for(let c in A)s.style[c]=A[c];for(let c in o)r.style[c]=o[c];t.appendChild(e),e.appendChild(s),e.appendChild(r),s.innerHTML='<div style="font-size: 24pt; margin: 1rem;">This immersive website requires access to your device motion sensors.</div>';const h=()=>{this.connect(),t.style.display="none"},l=document.createElement("button");l.addEventListener("click",h),l.style.width="50%",l.style.height="80%",l.style.fontSize="20pt",l.appendChild(document.createTextNode("OK")),r.appendChild(l),document.body.appendChild(t)}}class nt{constructor(t){this.raycaster=new m.Raycaster,this.normalisedMousePosition=new m.Vector2(null,null),t.domElement.addEventListener("click",e=>{this.normalisedMousePosition.set(e.clientX/t.domElement.clientWidth*2-1,-(e.clientY/t.domElement.clientHeight*2)+1)})}raycast(t,e){if(this.normalisedMousePosition.x!==null&&this.normalisedMousePosition.y!==null){this.raycaster.setFromCamera(this.normalisedMousePosition,t);const s=this.raycaster.intersectObjects(e.children,!1);return this.normalisedMousePosition.set(null,null),s}return[]}}a.ClickHandler=nt,a.DeviceOrientationControls=it,a.LocationBased=Z,a.SphMercProjection=W,a.WebcamRenderer=K,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locar",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Location-based AR from AR.js.",
5
5
  "files": [
6
6
  "dist"