locar 0.0.9 → 0.0.11
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 +3 -5
- package/dist/locar.es.js +74 -73
- package/dist/locar.umd.js +2 -2
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Location-based AR from AR.js.
|
|
|
4
4
|
|
|
5
5
|
## What is this?
|
|
6
6
|
|
|
7
|
-
LocAR.js is an AR.js project to develop a library focused specifically on location-based augmented reality in the browser. Currently it consists of the location-based three.js code from [the main AR.js repository](https://github.com/AR-js-org/AR.js), with some minor changes to make it compatible with latest versions (0.
|
|
7
|
+
LocAR.js is an AR.js project to develop a library focused specifically on location-based augmented reality in the browser. Currently it consists of the location-based three.js code from [the main AR.js repository](https://github.com/AR-js-org/AR.js), with some minor changes to make it compatible with latest versions (0.175.0 at time of writing) of three.js.
|
|
8
8
|
|
|
9
9
|
## Why?
|
|
10
10
|
|
|
@@ -20,8 +20,6 @@ For a while there have been some bugs and issues with location-based AR.js which
|
|
|
20
20
|
|
|
21
21
|
Some of these issues, such as incorrect North on some devices, may well be to do with incorrect or mis-calibrated sensors but the hope is that the standalone library will help to verify this and, if certain devices have North wrong by a consistent bearing, to develop a calibration tool.
|
|
22
22
|
|
|
23
|
-
For this reason, the focus at present will be on developing a **pure three.js version only**. When we believe that the key bugs and issues have been resolved, the plan is to then provide an A-Frame wrapper.
|
|
24
|
-
|
|
25
23
|
## Cross-platform Compatibility
|
|
26
24
|
|
|
27
25
|
Chrome on Android is recommended. It may also work on Chrome in iOS; please file an issue if not. It will not work on Safari on iOS, due to permissions issues - **though pull requests are welcome to fix this**. Firefox unfortunately does not appear to fully implement the Device Orientation API so is unlikely to work
|
|
@@ -42,8 +40,8 @@ import * as LocAR from 'locar';
|
|
|
42
40
|
as long as you include `locar` as a dependency, e.g. in your `package.json`:
|
|
43
41
|
```
|
|
44
42
|
"dependencies": {
|
|
45
|
-
"locar" : "^0.0.
|
|
46
|
-
"three" : "^0.
|
|
43
|
+
"locar" : "^0.0.11",
|
|
44
|
+
"three" : "^0.175.0"
|
|
47
45
|
}
|
|
48
46
|
```
|
|
49
47
|
|
package/dist/locar.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var W = (a) => {
|
|
2
2
|
throw TypeError(a);
|
|
3
3
|
};
|
|
4
|
-
var S = (a, t, e) => t.has(a) ||
|
|
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) ?
|
|
6
|
-
var
|
|
4
|
+
var S = (a, t, e) => t.has(a) || W("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) ? W("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 q = (a, t, e, i) => ({
|
|
7
7
|
set _(r) {
|
|
8
8
|
u(a, t, r, e);
|
|
9
9
|
},
|
|
@@ -11,7 +11,7 @@ var W = (a, t, e, i) => ({
|
|
|
11
11
|
return n(a, t, i);
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
import * as
|
|
14
|
+
import * as b from "three";
|
|
15
15
|
import { Vector3 as Z, Euler as N, Quaternion as _, EventDispatcher as B, MathUtils as C } from "three";
|
|
16
16
|
var E, U, G, X, Q;
|
|
17
17
|
class K {
|
|
@@ -58,7 +58,7 @@ E = 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 I, O, P, x,
|
|
61
|
+
var I, O, P, x, H, A, y, D, 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.
|
|
@@ -74,13 +74,13 @@ class st {
|
|
|
74
74
|
m(this, O);
|
|
75
75
|
m(this, P);
|
|
76
76
|
m(this, x);
|
|
77
|
-
m(this,
|
|
77
|
+
m(this, H);
|
|
78
78
|
m(this, A);
|
|
79
79
|
m(this, y);
|
|
80
|
-
m(this,
|
|
80
|
+
m(this, D);
|
|
81
81
|
m(this, T);
|
|
82
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,
|
|
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, H, 100), u(this, A, null), this.setGpsOptions(i), u(this, y, null), u(this, D, 0), u(this, T, 0), u(this, M, r);
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Set the projection to use.
|
|
@@ -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 && u(this, x, t.gpsMinDistance), t.gpsMinAccuracy !== void 0 && u(this,
|
|
102
|
+
t.gpsMinDistance !== void 0 && u(this, x, t.gpsMinDistance), t.gpsMinAccuracy !== void 0 && u(this, H, t.gpsMinAccuracy);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Start the GPS on a real device
|
|
@@ -110,7 +110,7 @@ class st {
|
|
|
110
110
|
if (n(this, M)) {
|
|
111
111
|
const e = await (await n(this, M).sendData("/gps/start", {
|
|
112
112
|
gpsMinDistance: n(this, x),
|
|
113
|
-
gpsMinAccuracy: n(this,
|
|
113
|
+
gpsMinAccuracy: n(this, H)
|
|
114
114
|
})).json();
|
|
115
115
|
u(this, T, e.session);
|
|
116
116
|
}
|
|
@@ -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, r,
|
|
183
|
+
add(t, e, i, r, h = {}) {
|
|
184
184
|
var g;
|
|
185
|
-
t.properties =
|
|
185
|
+
t.properties = h, 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:
|
|
190
|
+
properties: h
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
@@ -214,31 +214,31 @@ class st {
|
|
|
214
214
|
n(this, O)[t] = e;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
I = new WeakMap(), O = new WeakMap(), P = new WeakMap(), x = new WeakMap(),
|
|
218
|
-
const
|
|
219
|
-
r !== void 0 && (t.position.y = r), [t.position.x, t.position.z] =
|
|
217
|
+
I = new WeakMap(), O = new WeakMap(), P = new WeakMap(), x = new WeakMap(), H = new WeakMap(), A = new WeakMap(), y = new WeakMap(), D = new WeakMap(), T = new WeakMap(), M = new WeakMap(), f = new WeakSet(), F = function(t, e, i, r) {
|
|
218
|
+
const h = this.lonLatToWorldCoords(e, i);
|
|
219
|
+
r !== void 0 && (t.position.y = r), [t.position.x, t.position.z] = h;
|
|
220
220
|
}, V = function(t, e) {
|
|
221
221
|
u(this, y, n(this, I).project(t, e));
|
|
222
222
|
}, j = function(t) {
|
|
223
|
-
var i, r,
|
|
223
|
+
var i, r, h;
|
|
224
224
|
let e = Number.MAX_VALUE;
|
|
225
|
-
|
|
226
|
-
gpsCount: n(this,
|
|
225
|
+
q(this, D)._++, (i = n(this, M)) == null || i.sendData("/gps/new", {
|
|
226
|
+
gpsCount: n(this, D),
|
|
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,
|
|
231
|
+
}), t.coords.accuracy <= n(this, H) && (n(this, P) === null ? u(this, P, {
|
|
232
232
|
latitude: t.coords.latitude,
|
|
233
233
|
longitude: t.coords.longitude
|
|
234
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,
|
|
235
|
+
gpsCount: n(this, D),
|
|
236
236
|
lat: t.coords.latitude,
|
|
237
237
|
lon: t.coords.longitude,
|
|
238
238
|
session: n(this, T),
|
|
239
239
|
initialPosition: n(this, y)
|
|
240
|
-
})), p(this, f, F).call(this, this.camera, t.coords.longitude, t.coords.latitude), (
|
|
241
|
-
gpsCount: n(this,
|
|
240
|
+
})), p(this, f, F).call(this, this.camera, t.coords.longitude, t.coords.latitude), (h = n(this, M)) == null || h.sendData("/gps/accepted", {
|
|
241
|
+
gpsCount: n(this, D),
|
|
242
242
|
cameraX: this.camera.position.x,
|
|
243
243
|
cameraZ: this.camera.position.z,
|
|
244
244
|
session: n(this, T),
|
|
@@ -250,15 +250,16 @@ I = new WeakMap(), O = new WeakMap(), P = new WeakMap(), x = new WeakMap(), L =
|
|
|
250
250
|
* Taken from original A-Frame AR.js location-based components
|
|
251
251
|
*/
|
|
252
252
|
Y = function(t, e) {
|
|
253
|
-
const i =
|
|
254
|
-
return 2 * Math.atan2(Math.sqrt(
|
|
253
|
+
const i = b.MathUtils.degToRad(e.longitude - t.longitude), r = b.MathUtils.degToRad(e.latitude - t.latitude), h = Math.sin(r / 2) * Math.sin(r / 2) + Math.cos(b.MathUtils.degToRad(t.latitude)) * Math.cos(b.MathUtils.degToRad(e.latitude)) * (Math.sin(i / 2) * Math.sin(i / 2));
|
|
254
|
+
return 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)) * 6371e3;
|
|
255
255
|
};
|
|
256
256
|
class ot {
|
|
257
257
|
/**
|
|
258
258
|
* Create a Webcam.
|
|
259
|
-
* @options {Object} - options to use for initialising the camera.
|
|
260
|
-
*
|
|
261
|
-
* a *required* callback which runs when the camera has
|
|
259
|
+
* @param options {Object} - options to use for initialising the camera.
|
|
260
|
+
* Currently idealWidth and idealHeight properties are understood as well as
|
|
261
|
+
* onVideoStarted(), a *required* callback which runs when the camera has
|
|
262
|
+
* been initialised.
|
|
262
263
|
* This takes a THREE.VideoTexture as an argument which can be used to set
|
|
263
264
|
* the background of your three.js scene within a callback.
|
|
264
265
|
* @param {string} videoElementSelector - selector to obtain the HTML video
|
|
@@ -266,27 +267,27 @@ class ot {
|
|
|
266
267
|
* undefined), a video element will be created.
|
|
267
268
|
*/
|
|
268
269
|
constructor(t = {}, e) {
|
|
269
|
-
this.sceneWebcam = new
|
|
270
|
+
this.sceneWebcam = new b.Scene();
|
|
270
271
|
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
|
|
272
|
+
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 b.VideoTexture(i), navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
|
272
273
|
const r = {
|
|
273
274
|
video: {
|
|
274
|
-
width: { ideal: t.
|
|
275
|
-
height: { ideal: t.
|
|
275
|
+
width: { ideal: t.idealWidth || 1280 },
|
|
276
|
+
height: { ideal: t.idealHeight || 720 },
|
|
276
277
|
facingMode: "environment"
|
|
277
278
|
}
|
|
278
279
|
};
|
|
279
|
-
navigator.mediaDevices.getUserMedia(r).then((
|
|
280
|
+
navigator.mediaDevices.getUserMedia(r).then((h) => {
|
|
280
281
|
i.addEventListener("loadedmetadata", () => {
|
|
281
282
|
var g;
|
|
282
283
|
i.setAttribute("width", i.videoWidth), i.setAttribute("height", i.videoHeight), i.play(), (g = t.onVideoStarted) == null || g.call(this, this.texture);
|
|
283
|
-
}), i.srcObject =
|
|
284
|
-
}).catch((
|
|
284
|
+
}), i.srcObject = h;
|
|
285
|
+
}).catch((h) => {
|
|
285
286
|
setTimeout(() => {
|
|
286
287
|
alert(
|
|
287
288
|
`Webcam Error
|
|
288
|
-
Name: ` +
|
|
289
|
-
Message: ` +
|
|
289
|
+
Name: ` + h.name + `
|
|
290
|
+
Message: ` + h.message
|
|
290
291
|
);
|
|
291
292
|
}, 1e3);
|
|
292
293
|
});
|
|
@@ -316,17 +317,17 @@ class at extends B {
|
|
|
316
317
|
);
|
|
317
318
|
const e = this, i = 1e-6, r = new _();
|
|
318
319
|
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;
|
|
319
|
-
const
|
|
320
|
+
const h = function({
|
|
320
321
|
alpha: s,
|
|
321
322
|
beta: c,
|
|
322
|
-
gamma:
|
|
323
|
+
gamma: d,
|
|
323
324
|
webkitCompassHeading: o
|
|
324
325
|
}) {
|
|
325
326
|
if (k) {
|
|
326
327
|
const l = 360 - o;
|
|
327
|
-
e.alphaOffset = C.degToRad(l - s), e.deviceOrientation = { alpha: s, beta: c, gamma:
|
|
328
|
+
e.alphaOffset = C.degToRad(l - s), e.deviceOrientation = { alpha: s, beta: c, gamma: d, webkitCompassHeading: o };
|
|
328
329
|
} else
|
|
329
|
-
s < 0 && (s += 360), e.deviceOrientation = { alpha: s, beta: c, gamma:
|
|
330
|
+
s < 0 && (s += 360), e.deviceOrientation = { alpha: s, beta: c, gamma: d };
|
|
330
331
|
window.dispatchEvent(
|
|
331
332
|
new CustomEvent("camera-rotation-change", {
|
|
332
333
|
detail: { cameraRotation: t.rotation }
|
|
@@ -334,8 +335,8 @@ class at extends B {
|
|
|
334
335
|
);
|
|
335
336
|
}, g = function() {
|
|
336
337
|
e.screenOrientation = window.orientation || 0;
|
|
337
|
-
},
|
|
338
|
-
z.set(
|
|
338
|
+
}, L = function(s, c, d, o, l) {
|
|
339
|
+
z.set(d, c, -o, "YXZ"), s.setFromEuler(z), s.multiply(tt), s.multiply(J.setFromAxisAngle($, -l));
|
|
339
340
|
};
|
|
340
341
|
this.connect = function() {
|
|
341
342
|
g(), window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? window.DeviceOrientationEvent.requestPermission().then((s) => {
|
|
@@ -344,7 +345,7 @@ class at extends B {
|
|
|
344
345
|
g
|
|
345
346
|
), window.addEventListener(
|
|
346
347
|
e.orientationChangeEventName,
|
|
347
|
-
|
|
348
|
+
h
|
|
348
349
|
));
|
|
349
350
|
}).catch(function(s) {
|
|
350
351
|
console.error(
|
|
@@ -356,7 +357,7 @@ class at extends B {
|
|
|
356
357
|
g
|
|
357
358
|
), window.addEventListener(
|
|
358
359
|
e.orientationChangeEventName,
|
|
359
|
-
|
|
360
|
+
h
|
|
360
361
|
)), e.enabled = !0;
|
|
361
362
|
}, this.disconnect = function() {
|
|
362
363
|
window.removeEventListener(
|
|
@@ -364,17 +365,17 @@ class at extends B {
|
|
|
364
365
|
g
|
|
365
366
|
), window.removeEventListener(
|
|
366
367
|
e.orientationChangeEventName,
|
|
367
|
-
|
|
368
|
+
h
|
|
368
369
|
), e.enabled = !1, e.initialOffset = !1, e.deviceOrientation = null;
|
|
369
370
|
}, this.update = function({ theta: s = 0 } = { theta: 0 }) {
|
|
370
371
|
if (e.enabled === !1) return;
|
|
371
372
|
const c = e.deviceOrientation;
|
|
372
373
|
if (c) {
|
|
373
|
-
let
|
|
374
|
-
const
|
|
374
|
+
let d = 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;
|
|
375
|
+
const R = e.screenOrientation ? C.degToRad(e.screenOrientation) : 0;
|
|
375
376
|
if (k) {
|
|
376
377
|
const v = new _();
|
|
377
|
-
|
|
378
|
+
L(v, d, o, l, R);
|
|
378
379
|
const w = new N().setFromQuaternion(
|
|
379
380
|
v,
|
|
380
381
|
"YXZ"
|
|
@@ -386,8 +387,8 @@ class at extends B {
|
|
|
386
387
|
if (this.smoothingFactor < 1) {
|
|
387
388
|
if (this.lastOrientation) {
|
|
388
389
|
const v = this.smoothingFactor;
|
|
389
|
-
|
|
390
|
-
|
|
390
|
+
d = this._getSmoothedAngle(
|
|
391
|
+
d,
|
|
391
392
|
this.lastOrientation.alpha,
|
|
392
393
|
v
|
|
393
394
|
), o = this._getSmoothedAngle(
|
|
@@ -403,28 +404,28 @@ class at extends B {
|
|
|
403
404
|
} else
|
|
404
405
|
o += Math.PI, l += this.HALF_PI;
|
|
405
406
|
this.lastOrientation = {
|
|
406
|
-
alpha:
|
|
407
|
+
alpha: d,
|
|
407
408
|
beta: o,
|
|
408
409
|
gamma: l
|
|
409
410
|
};
|
|
410
411
|
}
|
|
411
|
-
|
|
412
|
+
L(
|
|
412
413
|
e.object.quaternion,
|
|
413
|
-
|
|
414
|
+
d + s,
|
|
414
415
|
this.smoothingFactor < 1 ? o - Math.PI : o,
|
|
415
416
|
this.smoothingFactor < 1 ? l - this.HALF_PI : l,
|
|
416
|
-
|
|
417
|
+
R
|
|
417
418
|
);
|
|
418
419
|
}
|
|
419
420
|
8 * (1 - r.dot(e.object.quaternion)) > i && (r.copy(e.object.quaternion), e.dispatchEvent(et));
|
|
420
421
|
}
|
|
421
|
-
}, this._orderAngle = function(s, c,
|
|
422
|
-
return c > s && Math.abs(c - s) <
|
|
423
|
-
}, this._getSmoothedAngle = function(s, c,
|
|
424
|
-
const l = this._orderAngle(s, c, o),
|
|
425
|
-
l.left = 0, l.right -=
|
|
426
|
-
let w = v == c ? (1 -
|
|
427
|
-
return w +=
|
|
422
|
+
}, this._orderAngle = function(s, c, d = this.TWO_PI) {
|
|
423
|
+
return c > s && Math.abs(c - s) < d / 2 || s > c && Math.abs(c - s) > d / 2 ? { left: s, right: c } : { left: c, right: s };
|
|
424
|
+
}, this._getSmoothedAngle = function(s, c, d, o = this.TWO_PI) {
|
|
425
|
+
const l = this._orderAngle(s, c, o), R = l.left, v = l.right;
|
|
426
|
+
l.left = 0, l.right -= R, l.right < 0 && (l.right += o);
|
|
427
|
+
let w = v == c ? (1 - d) * l.right + d * l.left : d * l.right + (1 - d) * l.left;
|
|
428
|
+
return w += R, w >= o && (w -= o), w;
|
|
428
429
|
}, this.updateAlphaOffset = function() {
|
|
429
430
|
e.initialOffset = !1;
|
|
430
431
|
}, this.dispose = function() {
|
|
@@ -443,7 +444,7 @@ class at extends B {
|
|
|
443
444
|
initPermissionDialog() {
|
|
444
445
|
const t = document.createElement("div"), e = document.createElement("div"), i = document.createElement("div"), r = document.createElement("div");
|
|
445
446
|
document.body.appendChild(t);
|
|
446
|
-
const
|
|
447
|
+
const h = {
|
|
447
448
|
display: "flex",
|
|
448
449
|
position: "fixed",
|
|
449
450
|
top: 0,
|
|
@@ -460,7 +461,7 @@ class at extends B {
|
|
|
460
461
|
borderRadius: "3px",
|
|
461
462
|
width: "36rem",
|
|
462
463
|
height: "24rem"
|
|
463
|
-
},
|
|
464
|
+
}, L = {
|
|
464
465
|
width: "100%",
|
|
465
466
|
height: "70%",
|
|
466
467
|
display: "flex",
|
|
@@ -473,19 +474,19 @@ class at extends B {
|
|
|
473
474
|
justifyContent: "center",
|
|
474
475
|
alignItems: "center"
|
|
475
476
|
};
|
|
476
|
-
for (let o in
|
|
477
|
-
t.style[o] =
|
|
477
|
+
for (let o in h)
|
|
478
|
+
t.style[o] = h[o];
|
|
478
479
|
for (let o in g)
|
|
479
480
|
e.style[o] = g[o];
|
|
480
|
-
for (let o in
|
|
481
|
-
i.style[o] =
|
|
481
|
+
for (let o in L)
|
|
482
|
+
i.style[o] = L[o];
|
|
482
483
|
for (let o in s)
|
|
483
484
|
r.style[o] = s[o];
|
|
484
485
|
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>';
|
|
485
486
|
const c = () => {
|
|
486
487
|
this.connect(), t.style.display = "none";
|
|
487
|
-
},
|
|
488
|
-
|
|
488
|
+
}, d = document.createElement("button");
|
|
489
|
+
d.addEventListener("click", c), d.style.width = "50%", d.style.height = "80%", d.style.fontSize = "20pt", d.appendChild(document.createTextNode("OK")), r.appendChild(d), document.body.appendChild(t);
|
|
489
490
|
}
|
|
490
491
|
}
|
|
491
492
|
class rt {
|
|
@@ -495,7 +496,7 @@ class rt {
|
|
|
495
496
|
* events will be handled.
|
|
496
497
|
*/
|
|
497
498
|
constructor(t) {
|
|
498
|
-
this.raycaster = new
|
|
499
|
+
this.raycaster = new b.Raycaster(), this.normalisedMousePosition = new b.Vector2(null, null), t.domElement.addEventListener("click", (e) => {
|
|
499
500
|
this.normalisedMousePosition.set(
|
|
500
501
|
e.clientX / t.domElement.clientWidth * 2 - 1,
|
|
501
502
|
-(e.clientY / t.domElement.clientHeight * 2) + 1
|
|
@@ -519,7 +520,7 @@ class rt {
|
|
|
519
520
|
return [];
|
|
520
521
|
}
|
|
521
522
|
}
|
|
522
|
-
const ct = "0.0.
|
|
523
|
+
const ct = "0.0.10-noaframe-1";
|
|
523
524
|
export {
|
|
524
525
|
rt as ClickHandler,
|
|
525
526
|
at as DeviceOrientationControls,
|
package/dist/locar.umd.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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
|
|
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 W=(a,n,f)=>n.has(a)||z("Cannot "+f);var s=(a,n,f)=>(W(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)=>(W(a,n,"write to private field"),p?p.call(a,f):n.set(a,f),f),y=(a,n,f)=>(W(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,q,Y,H,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,H).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,H).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,q).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,q=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))},H=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,q).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.idealWidth||1280},height:{ideal:t.idealHeight||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
2
|
Name: `+h.name+`
|
|
3
|
-
Message: `+h.message)},1e3)})}else setTimeout(()=>{alert("sorry - media devices API not supported")},1e3)}dispose(){this.texture.dispose()}}const
|
|
3
|
+
Message: `+h.message)},1e3)})}else setTimeout(()=>{alert("sorry - media devices API not supported")},1e3)}dispose(){this.texture.dispose()}}const k=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(k){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(k){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.10-noaframe-1";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.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Location-based AR from AR.js.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -20,5 +20,8 @@
|
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"jsdoc": "^4.0.4",
|
|
22
22
|
"vite": "^5.4.8"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"three": "^0.175.0"
|
|
23
26
|
}
|
|
24
27
|
}
|