locar 0.0.7 → 0.0.9

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