locar 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/locar.es.js +375 -544
- package/dist/locar.umd.js +2 -2
- package/dist/three/app.d.ts +32 -0
- package/dist/three/click-handler.d.ts +25 -0
- package/dist/three/device-orientation-controls.d.ts +55 -0
- package/dist/three/event-emitter.d.ts +24 -0
- package/dist/three/locar.d.ts +112 -0
- package/dist/three/main.d.ts +9 -0
- package/dist/three/sphmerc-projection.d.ts +29 -0
- package/dist/three/webcam.d.ts +27 -0
- package/dist/types/locar.d.ts +89 -0
- package/package.json +11 -17
- package/dist/locar.d.ts +0 -375
package/dist/locar.es.js
CHANGED
|
@@ -1,545 +1,376 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
class
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
t.orientationChangeEventName,
|
|
375
|
-
o
|
|
376
|
-
), t.enabled = !1, t.initialOffset = !1, t.deviceOrientation = null, t.lastQuaternion = null;
|
|
377
|
-
}, this.requestOrientationPermissions = () => {
|
|
378
|
-
window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? window.DeviceOrientationEvent.requestPermission().then((n) => {
|
|
379
|
-
n === "granted" ? this.eventEmitter.emit("deviceorientationgranted", {
|
|
380
|
-
target: this
|
|
381
|
-
}) : this.eventEmitter.emit("deviceorientationerror", {
|
|
382
|
-
code: "LOCAR_DEVICE_ORIENTATION_PERMISSION_DENIED",
|
|
383
|
-
message: "Permission for device orientation denied - AR will not work correctly"
|
|
384
|
-
});
|
|
385
|
-
}).catch((n) => {
|
|
386
|
-
this.eventEmitter.emit("deviceorientationerror", {
|
|
387
|
-
code: "LOCAR_DEVICE_ORIENTATION_PERMISSION_FAILED",
|
|
388
|
-
message: "Permission request for device orientation failed - AR will not work correctly",
|
|
389
|
-
error: JSON.stringify(n, null, 2)
|
|
390
|
-
});
|
|
391
|
-
}) : this.eventEmitter.emit("deviceorientationerror", {
|
|
392
|
-
code: "LOCAR_DEVICE_ORIENTATION_INTERNAL_ERROR",
|
|
393
|
-
message: "Internal error: no requestPermission() found although requestOrientationPermissions() was called - please raise an issue on GitHub"
|
|
394
|
-
});
|
|
395
|
-
}, this.update = () => {
|
|
396
|
-
if (t.enabled === !1) return;
|
|
397
|
-
const n = t.deviceOrientation;
|
|
398
|
-
if (n) {
|
|
399
|
-
let s = n.alpha ? p.degToRad(n.alpha) + t.alphaOffset : 0, d = n.beta ? p.degToRad(n.beta) : 0, c = n.gamma ? p.degToRad(n.gamma) : 0;
|
|
400
|
-
const a = t.screenOrientation ? p.degToRad(t.screenOrientation) : 0, h = new O();
|
|
401
|
-
if (E) {
|
|
402
|
-
m(h, s, d, c, a);
|
|
403
|
-
const g = new T().setFromQuaternion(
|
|
404
|
-
h,
|
|
405
|
-
"YXZ"
|
|
406
|
-
), f = p.degToRad(
|
|
407
|
-
360 - (n.webkitCompassHeading ?? 0)
|
|
408
|
-
);
|
|
409
|
-
g.y = f + (t.orientationOffset || 0), h.setFromEuler(g);
|
|
410
|
-
} else
|
|
411
|
-
m(h, s, d, c, a);
|
|
412
|
-
if (t.lastQuaternion && t.orientationChangeThreshold > 0 && h.angleTo(t.lastQuaternion) < t.orientationChangeThreshold)
|
|
413
|
-
return;
|
|
414
|
-
if (t.smoothingFactor < 1 && t.lastQuaternion) {
|
|
415
|
-
const g = 1 - t.smoothingFactor;
|
|
416
|
-
t.object.quaternion.slerp(h, g);
|
|
417
|
-
} else
|
|
418
|
-
t.object.quaternion.copy(h);
|
|
419
|
-
t.lastQuaternion = t.object.quaternion.clone(), window.dispatchEvent(
|
|
420
|
-
new CustomEvent("camera-rotation-change", {
|
|
421
|
-
detail: { cameraRotation: t.object.rotation }
|
|
422
|
-
})
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
}, this.getCorrectedHeading = () => {
|
|
426
|
-
const { deviceOrientation: n } = t;
|
|
427
|
-
if (!n) return 0;
|
|
428
|
-
let s = 0;
|
|
429
|
-
return E ? (s = 360 - (n.webkitCompassHeading ?? 0), t.orientationOffset && (s += t.orientationOffset * (180 / Math.PI), s = (s + 360) % 360)) : (n.absolute === !0 || t.orientationChangeEventName, s = n.alpha ? n.alpha : 0, s = (360 - s) % 360, s < 0 && (s += 360)), s;
|
|
430
|
-
}, this.updateAlphaOffset = () => {
|
|
431
|
-
t.initialOffset = !1;
|
|
432
|
-
}, this.dispose = () => {
|
|
433
|
-
t.disconnect();
|
|
434
|
-
}, this.getAlpha = () => {
|
|
435
|
-
const { deviceOrientation: n } = t;
|
|
436
|
-
return n && n.alpha ? p.degToRad(n.alpha) + t.alphaOffset : 0;
|
|
437
|
-
}, this.getBeta = () => {
|
|
438
|
-
const { deviceOrientation: n } = t;
|
|
439
|
-
return n && n.beta ? p.degToRad(n.beta) : 0;
|
|
440
|
-
}, this.getGamma = () => {
|
|
441
|
-
const { deviceOrientation: n } = t;
|
|
442
|
-
return n && n.gamma ? p.degToRad(n.gamma) : 0;
|
|
443
|
-
}, this.createObtainPermissionGestureDialog = () => {
|
|
444
|
-
const n = document.createElement("div");
|
|
445
|
-
n.classList.add(_);
|
|
446
|
-
const s = document.createElement("div");
|
|
447
|
-
s.classList.add(N);
|
|
448
|
-
const d = document.createElement("div");
|
|
449
|
-
d.classList.add(L);
|
|
450
|
-
const c = document.createElement("div");
|
|
451
|
-
c.classList.add(S);
|
|
452
|
-
const a = document.createElement("button");
|
|
453
|
-
a.classList.add(H), document.body.appendChild(n), this.enableInlineStyling === !0 && (n.style.fontFamily = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'", n.style.display = "flex", n.style.position = "fixed", n.style.zIndex = "100000", n.style.justifyContent = "center", n.style.alignItems = "center", n.style.backgroundColor = "rgba(0,0,0,0.2)", n.style.inset = "0", n.style.padding = "20px", s.style.backgroundColor = "rgba(220, 220, 220, 0.85)", s.style.padding = "6px 0", s.style.borderRadius = "10px", s.style.width = "100%", s.style.maxWidth = "400px", d.style.padding = "10px 12px", d.style.textAlign = "center", d.style.fontWeight = "400", d.style.fontSize = "13px", d.style.display = "flex", d.style.justifyContent = "center", d.style.alignItems = "center", c.style.display = "block", c.style.textAlign = "center", c.style.textDecoration = "none", c.style.borderTop = "rgb(180,180,180) solid 1px", a.style.display = "block", a.style.width = "100%", a.style.textAlign = "center", a.style.appearance = "none", a.style.background = "none", a.style.border = "none", a.style.outline = "none", a.style.padding = "10px", a.style.fontWeight = "400", a.style.fontSize = "16px", a.style.color = "#2e7cf1", a.style.cursor = "pointer"), n.appendChild(s), s.appendChild(d), s.appendChild(c), d.appendChild(
|
|
454
|
-
document.createTextNode(b)
|
|
455
|
-
);
|
|
456
|
-
const h = () => {
|
|
457
|
-
this.requestOrientationPermissions(), n.style.display = "none";
|
|
458
|
-
};
|
|
459
|
-
a.addEventListener("click", h), a.appendChild(document.createTextNode("OK")), c.appendChild(a), document.body.appendChild(n);
|
|
460
|
-
}, this.obtainPermissionGesture = () => {
|
|
461
|
-
this.preferConfirmDialog === !0 ? window.confirm(b) && this.requestOrientationPermissions() : this.createObtainPermissionGestureDialog();
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
on(e, i) {
|
|
465
|
-
this.eventEmitter.on(e, i);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
class G {
|
|
469
|
-
/**
|
|
470
|
-
* Create a ClickHandler.
|
|
471
|
-
* @param {THREE.WebGLRenderer} - The Three.js renderer on which the click
|
|
472
|
-
* events will be handled.
|
|
473
|
-
*/
|
|
474
|
-
constructor(e) {
|
|
475
|
-
this.raycaster = new u.Raycaster(), this.normalisedMousePosition = null, e.domElement.addEventListener("click", (i) => {
|
|
476
|
-
this.normalisedMousePosition = new u.Vector2(
|
|
477
|
-
i.clientX / e.domElement.clientWidth * 2 - 1,
|
|
478
|
-
-(i.clientY / e.domElement.clientHeight * 2) + 1
|
|
479
|
-
);
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Cast a ray into the scene to detect objects.
|
|
484
|
-
* @param {THREE.Camera} - The active Three.js camera, from which the ray
|
|
485
|
-
* will be cast.
|
|
486
|
-
* @param {THREE.Scene} - The active Three.js scene, which the ray will be
|
|
487
|
-
* cast into.
|
|
488
|
-
* @return {Array} - array of all intersected objects.
|
|
489
|
-
*/
|
|
490
|
-
raycast(e, i) {
|
|
491
|
-
if (this.normalisedMousePosition !== null) {
|
|
492
|
-
this.raycaster.setFromCamera(this.normalisedMousePosition, e);
|
|
493
|
-
const t = this.raycaster.intersectObjects(i.children, !1);
|
|
494
|
-
return this.normalisedMousePosition = null, t;
|
|
495
|
-
}
|
|
496
|
-
return [];
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
class q extends w {
|
|
500
|
-
#e;
|
|
501
|
-
/**
|
|
502
|
-
* Create a Webcam.
|
|
503
|
-
* @param constraints {Object} - options to use for initialising the camera.
|
|
504
|
-
* This is the same constraints object as used by standard MediaDevices API.
|
|
505
|
-
* @param {string} videoElementSelector - selector to obtain the HTML video
|
|
506
|
-
* element to render the webcam feed. If a falsy value (e.g. null or
|
|
507
|
-
* undefined), a video element will be created.
|
|
508
|
-
*/
|
|
509
|
-
constructor(e = { video: { facingMode: "environment" } }, i) {
|
|
510
|
-
super(), this.sceneWebcam = new u.Scene(), i ? this.#e = document.querySelector(i) : (this.#e = document.createElement("video"), this.#e.setAttribute("autoplay", "true"), this.#e.setAttribute("playsinline", "true"), this.#e.style.cssText += `
|
|
511
|
-
width: 100%;
|
|
512
|
-
height: 100%;
|
|
513
|
-
object-fit: cover;
|
|
514
|
-
background: black;
|
|
515
|
-
position: absolute;
|
|
516
|
-
top: 0px;
|
|
517
|
-
left: 0px;
|
|
518
|
-
z-index: -100;
|
|
519
|
-
`, document.body.appendChild(this.#e)), navigator.mediaDevices && navigator.mediaDevices.getUserMedia ? navigator.mediaDevices.getUserMedia(e).then((t) => {
|
|
520
|
-
this.#e?.addEventListener("loadedmetadata", () => {
|
|
521
|
-
this.#e.play(), this.emit("webcamstarted", { videoWidth: this.#e.videoWidth, videoHeight: this.#e.videoHeight });
|
|
522
|
-
}), this.#e && (this.#e.srcObject = t);
|
|
523
|
-
}).catch((t) => {
|
|
524
|
-
this.emit("webcamerror", {
|
|
525
|
-
code: t.name,
|
|
526
|
-
message: t.message
|
|
527
|
-
});
|
|
528
|
-
}) : this.emit("webcamerror", {
|
|
529
|
-
code: "LOCAR_NO_MEDIA_DEVICES_API",
|
|
530
|
-
message: "Media devices API not supported"
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
getVideoDimensions() {
|
|
534
|
-
return `w ${this.#e.videoWidth}, h ${this.#e.videoHeight}`;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
export {
|
|
538
|
-
j as App,
|
|
539
|
-
G as ClickHandler,
|
|
540
|
-
z as DeviceOrientationControls,
|
|
541
|
-
w as EventEmitter,
|
|
542
|
-
y as LocAR,
|
|
543
|
-
x as SphMercProjection,
|
|
544
|
-
q as Webcam
|
|
1
|
+
import * as e from "three";
|
|
2
|
+
import { Euler as t, EventDispatcher as n, MathUtils as r, Quaternion as i, Vector3 as a } from "three";
|
|
3
|
+
//#region lib/three/event-emitter.ts
|
|
4
|
+
var o = class {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.on = (e, t) => {
|
|
7
|
+
this.eventHandlers[e] === void 0 && (this.eventHandlers[e] = []), this.eventHandlers[e].push(t);
|
|
8
|
+
}, this.emit = (e, ...t) => {
|
|
9
|
+
this.eventHandlers[e]?.forEach((e) => {
|
|
10
|
+
e(...t);
|
|
11
|
+
});
|
|
12
|
+
}, this.off = (e, t) => {
|
|
13
|
+
if (this.eventHandlers[e]) {
|
|
14
|
+
let n = this.eventHandlers[e].indexOf(t);
|
|
15
|
+
n > -1 && this.eventHandlers[e].splice(n, 1);
|
|
16
|
+
}
|
|
17
|
+
}, this.eventHandlers = {};
|
|
18
|
+
}
|
|
19
|
+
}, s = class extends o {
|
|
20
|
+
constructor({ cameraOptions: t, canvas: n, gpsOptions: r, videoConstraints: i, deviceOrientationOptions: a, serverLogger: o, projection: s }) {
|
|
21
|
+
super(), this.origHfov = t?.hFov || 80, this.cameraFeedDimensions = null;
|
|
22
|
+
let c = window.innerWidth / window.innerHeight;
|
|
23
|
+
this.camera = new e.PerspectiveCamera(this.origHfov / c, c, t?.near || .001, t?.far || 1e3), n ? (this.renderer = new e.WebGLRenderer({
|
|
24
|
+
canvas: n,
|
|
25
|
+
alpha: !0
|
|
26
|
+
}), this.renderer.setClearColor(65280, 0)) : (this.renderer = new e.WebGLRenderer({ alpha: !0 }), this.renderer.setClearColor(65280, 0), document.body.appendChild(this.renderer.domElement)), this.renderer.setSize(window.innerWidth, window.innerHeight), this.scene = new e.Scene();
|
|
27
|
+
let u = a || { enabled: !0 };
|
|
28
|
+
window.addEventListener("resize", () => {
|
|
29
|
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
|
30
|
+
let e = window.innerWidth / window.innerHeight;
|
|
31
|
+
if (this.camera.aspect = e, this.cameraFeedDimensions !== null) {
|
|
32
|
+
let t = e > 1 ? this.cameraFeedDimensions.landWidth : this.cameraFeedDimensions.landHeight, n = e > 1 ? this.cameraFeedDimensions.landHeight : this.cameraFeedDimensions.landWidth;
|
|
33
|
+
this.#e(t, n, e);
|
|
34
|
+
}
|
|
35
|
+
this.camera.updateProjectionMatrix();
|
|
36
|
+
}), this.locar = new l(this.scene, this.camera, r, o, s), this.webcam = new w(i), this.deviceOrientationControls = u.enabled === !0 ? new S(this.camera, u) : null, this.renderer.setAnimationLoop(() => {
|
|
37
|
+
this.deviceOrientationControls?.update(), this.renderer.render(this.scene, this.camera);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
start() {
|
|
41
|
+
return new Promise((e, t) => {
|
|
42
|
+
this.webcam.on("webcamstarted", (e) => {
|
|
43
|
+
let t = e.videoWidth > e.videoHeight;
|
|
44
|
+
this.cameraFeedDimensions = {
|
|
45
|
+
landWidth: t ? e.videoWidth : e.videoHeight,
|
|
46
|
+
landHeight: t ? e.videoHeight : e.videoWidth
|
|
47
|
+
}, this.#e(e.videoWidth, e.videoHeight, window.innerWidth / window.innerHeight), this.camera.updateProjectionMatrix();
|
|
48
|
+
}), this.webcam.on("webcamerror", (e) => {
|
|
49
|
+
t({
|
|
50
|
+
code: e.code,
|
|
51
|
+
message: e.message
|
|
52
|
+
});
|
|
53
|
+
}), this.deviceOrientationControls === null ? e(this.locar) : (this.deviceOrientationControls?.on("deviceorientationgranted", (t) => {
|
|
54
|
+
t.target.connect(), e(this.locar);
|
|
55
|
+
}), this.deviceOrientationControls.on("deviceorientationerror", (e) => {
|
|
56
|
+
t({
|
|
57
|
+
code: e.code,
|
|
58
|
+
message: e.message
|
|
59
|
+
});
|
|
60
|
+
}), this.deviceOrientationControls.init());
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
#e(e, t, n) {
|
|
64
|
+
if (n < e / t) {
|
|
65
|
+
let r = e * (window.innerHeight / t), i = this.origHfov * (window.innerWidth / r);
|
|
66
|
+
this.camera.fov = i / n;
|
|
67
|
+
} else this.camera.fov = this.origHfov / n;
|
|
68
|
+
}
|
|
69
|
+
}, c = class {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.project = (e, t) => [this.#e(e), this.#t(t)], this.unproject = (e) => [this.#n(e[0]), this.#r(e[1])], this.#e = (e) => e / 180 * this.HALF_EARTH, this.#t = (e) => Math.log(Math.tan((90 + e) * Math.PI / 360)) / (Math.PI / 180) * this.HALF_EARTH / 180, this.#n = (e) => e / this.HALF_EARTH * 180, this.#r = (e) => {
|
|
72
|
+
var t = e / this.HALF_EARTH * 180;
|
|
73
|
+
return t = 180 / Math.PI * (2 * Math.atan(Math.exp(t * Math.PI / 180)) - Math.PI / 2), t;
|
|
74
|
+
}, this.getID = () => "epsg:3857", this.EARTH = 40075016.68, this.HALF_EARTH = 20037508.34;
|
|
75
|
+
}
|
|
76
|
+
#e;
|
|
77
|
+
#t;
|
|
78
|
+
#n;
|
|
79
|
+
#r;
|
|
80
|
+
}, l = class t extends o {
|
|
81
|
+
#e;
|
|
82
|
+
#t;
|
|
83
|
+
#n;
|
|
84
|
+
#r;
|
|
85
|
+
#i;
|
|
86
|
+
#a;
|
|
87
|
+
#o;
|
|
88
|
+
#s;
|
|
89
|
+
#c;
|
|
90
|
+
constructor(e, t, n = {}, r = null, i = new c()) {
|
|
91
|
+
super(), this.scene = e, this.camera = t, this.#e = i, this.#t = null, this.#n = 0, this.#r = 100, this.#i = null, this.setGpsOptions(n), this.#a = null, this.#o = 0, this.#s = 0, this.#c = r;
|
|
92
|
+
}
|
|
93
|
+
setProjection(e) {
|
|
94
|
+
this.#e = e;
|
|
95
|
+
}
|
|
96
|
+
setGpsOptions(e = {}) {
|
|
97
|
+
e.gpsMinDistance !== void 0 && (this.#n = e.gpsMinDistance), e.gpsMinAccuracy !== void 0 && (this.#r = e.gpsMinAccuracy);
|
|
98
|
+
}
|
|
99
|
+
async startGps() {
|
|
100
|
+
if (this.#c) {
|
|
101
|
+
let e = await (await this.#c.sendData("/gps/start", {
|
|
102
|
+
gpsMinDistance: this.#n,
|
|
103
|
+
gpsMinAccuracy: this.#r
|
|
104
|
+
})).json();
|
|
105
|
+
this.#s = e.session;
|
|
106
|
+
}
|
|
107
|
+
return this.#i === null ? (this.#i = navigator.geolocation.watchPosition((e) => {
|
|
108
|
+
this.#f(e);
|
|
109
|
+
}, (e) => {
|
|
110
|
+
this.emit("gpserror", e);
|
|
111
|
+
}, { enableHighAccuracy: !0 }), !0) : !1;
|
|
112
|
+
}
|
|
113
|
+
stopGps() {
|
|
114
|
+
return this.#i === null ? !1 : (navigator.geolocation.clearWatch(this.#i), this.#i = null, !0);
|
|
115
|
+
}
|
|
116
|
+
fakeGps(e, t, n = null, r = 0) {
|
|
117
|
+
n !== null && this.setElevation(n), this.#f({ coords: {
|
|
118
|
+
longitude: e,
|
|
119
|
+
latitude: t,
|
|
120
|
+
accuracy: r
|
|
121
|
+
} });
|
|
122
|
+
}
|
|
123
|
+
lonLatToWorldCoords(e, t) {
|
|
124
|
+
let n = this.#e.project(e, t);
|
|
125
|
+
return this.eastNorthToWorldCoords(n);
|
|
126
|
+
}
|
|
127
|
+
eastNorthToWorldCoords(e) {
|
|
128
|
+
if (this.#a) e[0] -= this.#a[0], e[1] -= this.#a[1];
|
|
129
|
+
else throw "No initial position determined";
|
|
130
|
+
return [e[0], -e[1]];
|
|
131
|
+
}
|
|
132
|
+
add(e, t, n, r, i = {}) {
|
|
133
|
+
e.properties = i, this.#u(e, t, n, r || 0), this.scene.add(e), this.#c?.sendData("/object/new", {
|
|
134
|
+
position: e.position,
|
|
135
|
+
x: e.position.x,
|
|
136
|
+
z: e.position.z,
|
|
137
|
+
session: this.#s,
|
|
138
|
+
properties: i
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
addGeoLine(t, n, r = 1) {
|
|
142
|
+
let i = t.map(((t) => {
|
|
143
|
+
let [n, r] = this.lonLatToWorldCoords(t[0], t[1]);
|
|
144
|
+
return new e.Vector3(n, t[2] || 0, r);
|
|
145
|
+
})), a = this.#l(i, r);
|
|
146
|
+
n.setValues({ side: e.DoubleSide });
|
|
147
|
+
let o = new e.Mesh(a, n);
|
|
148
|
+
return this.scene.add(o), o;
|
|
149
|
+
}
|
|
150
|
+
#l(t, n) {
|
|
151
|
+
let r, i, a, o, s = 0, c = 0, l = [], u, d = t.length - 1, f = [];
|
|
152
|
+
for (let e = 0; e < d; e++) r = t[e + 1].x - t[e].x, i = t[e + 1].z - t[e].z, a = t[e + 1].y - t[e].y, o = Math.sqrt(r * r + a * a + i * i), s = -(n / 2 * i) / o, c = n / 2 * r / o, u = [
|
|
153
|
+
t[e].x - s,
|
|
154
|
+
t[e].y,
|
|
155
|
+
t[e].z - c,
|
|
156
|
+
t[e].x + s,
|
|
157
|
+
t[e].y,
|
|
158
|
+
t[e].z + c
|
|
159
|
+
], e > 0 && u.forEach((e, t) => {
|
|
160
|
+
e = (e + l[t]) / 2;
|
|
161
|
+
}), f.push(...u), l = [
|
|
162
|
+
t[e + 1].x - s,
|
|
163
|
+
t[e + 1].y,
|
|
164
|
+
t[e + 1].z - c,
|
|
165
|
+
t[e + 1].x + s,
|
|
166
|
+
t[e + 1].y,
|
|
167
|
+
t[e + 1].z + c
|
|
168
|
+
];
|
|
169
|
+
f.push(t[d].x - s), f.push(t[d].y), f.push(t[d].z - c), f.push(t[d].x + s), f.push(t[d].y), f.push(t[d].z + c);
|
|
170
|
+
let p = [];
|
|
171
|
+
for (let e = 0; e < d; e++) p.push(e * 2, e * 2 + 1, e * 2 + 2), p.push(e * 2 + 1, e * 2 + 3, e * 2 + 2);
|
|
172
|
+
let m = new e.BufferGeometry(), h = new Float32Array(f);
|
|
173
|
+
return m.setIndex(p), m.setAttribute("position", new e.BufferAttribute(h, 3)), m.computeBoundingBox(), m;
|
|
174
|
+
}
|
|
175
|
+
#u(e, t, n, r) {
|
|
176
|
+
let i = this.lonLatToWorldCoords(t, n);
|
|
177
|
+
r !== void 0 && (e.position.y = r), [e.position.x, e.position.z] = i;
|
|
178
|
+
}
|
|
179
|
+
setElevation(e) {
|
|
180
|
+
this.camera.position.y = e;
|
|
181
|
+
}
|
|
182
|
+
#d(e, t) {
|
|
183
|
+
this.#a = this.#e.project(e, t);
|
|
184
|
+
}
|
|
185
|
+
#f(e) {
|
|
186
|
+
let n = Number.MAX_VALUE;
|
|
187
|
+
this.#o++, this.#c?.sendData("/gps/new", {
|
|
188
|
+
gpsCount: this.#o,
|
|
189
|
+
lat: e.coords.latitude,
|
|
190
|
+
lon: e.coords.longitude,
|
|
191
|
+
acc: e.coords.accuracy,
|
|
192
|
+
session: this.#s
|
|
193
|
+
}), e.coords.accuracy <= this.#r && (this.#t === null ? this.#t = {
|
|
194
|
+
latitude: e.coords.latitude,
|
|
195
|
+
longitude: e.coords.longitude
|
|
196
|
+
} : n = t.haversineDist(this.#t, e.coords), n >= this.#n && (this.#t.longitude = e.coords.longitude, this.#t.latitude = e.coords.latitude, this.#a || (this.#d(e.coords.longitude, e.coords.latitude), this.#c?.sendData("/worldorigin/new", {
|
|
197
|
+
gpsCount: this.#o,
|
|
198
|
+
lat: e.coords.latitude,
|
|
199
|
+
lon: e.coords.longitude,
|
|
200
|
+
session: this.#s,
|
|
201
|
+
initialPosition: this.#a
|
|
202
|
+
})), this.#u(this.camera, e.coords.longitude, e.coords.latitude), this.#c?.sendData("/gps/accepted", {
|
|
203
|
+
gpsCount: this.#o,
|
|
204
|
+
cameraX: this.camera.position.x,
|
|
205
|
+
cameraZ: this.camera.position.z,
|
|
206
|
+
session: this.#s,
|
|
207
|
+
distMoved: n
|
|
208
|
+
}), this.emit("gpsupdate", {
|
|
209
|
+
position: e,
|
|
210
|
+
distMoved: n
|
|
211
|
+
})));
|
|
212
|
+
}
|
|
213
|
+
static haversineDist(t, n) {
|
|
214
|
+
let r = e.MathUtils.degToRad(n.longitude - t.longitude), i = e.MathUtils.degToRad(n.latitude - t.latitude), a = Math.sin(i / 2) * Math.sin(i / 2) + Math.cos(e.MathUtils.degToRad(t.latitude)) * Math.cos(e.MathUtils.degToRad(n.latitude)) * (Math.sin(r / 2) * Math.sin(r / 2));
|
|
215
|
+
return 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) * 6371e3;
|
|
216
|
+
}
|
|
217
|
+
getLastKnownLocation() {
|
|
218
|
+
return this.#t;
|
|
219
|
+
}
|
|
220
|
+
}, u = "locar-device-orientation-permission-modal", d = "locar-device-orientation-permission-button", f = "locar-device-orientation-permission-message", p = "locar-device-orientation-permission-inner", m = "locar-device-orientation-permission-button-inner", h = "This immersive website requires access to your device motion sensors.", g = navigator.userAgent.match(/iPhone|iPad|iPod/i) || /Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints != null && navigator.maxTouchPoints > 1, _ = new a(0, 0, 1), v = new t(), y = new i(), b = new i(-Math.sqrt(.5), 0, 0, Math.sqrt(.5));
|
|
221
|
+
2 * Math.PI;
|
|
222
|
+
var x = .5 * Math.PI, S = class extends n {
|
|
223
|
+
constructor(e, n = {}) {
|
|
224
|
+
super(), this.init = () => {
|
|
225
|
+
window.DeviceOrientationEvent === void 0 ? this.eventEmitter.emit("deviceorientationerror", {
|
|
226
|
+
code: "LOCAR_DEVICE_ORIENTATION_NOT_SUPPORTED",
|
|
227
|
+
message: "Device orientation API not supported"
|
|
228
|
+
}) : window.isSecureContext === !1 ? this.eventEmitter.emit("deviceorientationerror", {
|
|
229
|
+
code: "LOCAR_DEVICE_ORIENTATION_NO_HTTPS",
|
|
230
|
+
message: "DeviceOrientationEvent is only available in secure contexts (https)"
|
|
231
|
+
}) : typeof window.DeviceOrientationEvent.requestPermission == "function" && this.enablePermissionDialog ? this.obtainPermissionGesture() : this.eventEmitter.emit("deviceorientationgranted", { target: this });
|
|
232
|
+
}, this.eventEmitter = new o();
|
|
233
|
+
let a = this;
|
|
234
|
+
this.object = e, this.object.rotation.reorder("YXZ"), this.enabled = !0, this.deviceOrientation = null, this.screenOrientation = 0, this.alphaOffset = 0, this.orientationOffset = 0, this.initialOffset = null, this.lastQuaternion = null, this.orientationChangeEventName = "ondeviceorientationabsolute" in window ? "deviceorientationabsolute" : "deviceorientation", this.smoothingFactor = n.smoothingFactor || .2, this.enablePermissionDialog = n.enablePermissionDialog ?? !0, this.enableInlineStyling = n.enableStyling ?? !0, this.preferConfirmDialog = n.preferConfirmDialog ?? !1, this.orientationChangeThreshold = n.orientationChangeThreshold ?? 0;
|
|
235
|
+
let s = (t) => {
|
|
236
|
+
let { alpha: n, beta: i, gamma: o, webkitCompassHeading: s } = t;
|
|
237
|
+
if (n ??= 0, i ??= 0, o ??= 0, s ??= 0, g) {
|
|
238
|
+
let e = 360 - s;
|
|
239
|
+
a.alphaOffset = r.degToRad(e - n), a.deviceOrientation = {
|
|
240
|
+
alpha: n,
|
|
241
|
+
beta: i,
|
|
242
|
+
gamma: o,
|
|
243
|
+
webkitCompassHeading: s
|
|
244
|
+
};
|
|
245
|
+
} else n < 0 && (n += 360), a.deviceOrientation = {
|
|
246
|
+
alpha: n,
|
|
247
|
+
beta: i,
|
|
248
|
+
gamma: o
|
|
249
|
+
};
|
|
250
|
+
window.dispatchEvent(new CustomEvent("camera-rotation-change", { detail: { cameraRotation: e.rotation } }));
|
|
251
|
+
}, c = () => {
|
|
252
|
+
a.screenOrientation = window.screen.orientation?.angle ?? 0, g && (a.screenOrientation === 90 ? a.orientationOffset = -x : a.screenOrientation === -90 ? a.orientationOffset = x : a.orientationOffset = 0);
|
|
253
|
+
}, l = (e, t, n, r, i) => {
|
|
254
|
+
v.set(n, t, -r, "YXZ"), e.setFromEuler(v), e.multiply(b), e.multiply(y.setFromAxisAngle(_, -i));
|
|
255
|
+
};
|
|
256
|
+
this.connect = () => {
|
|
257
|
+
c(), window.addEventListener("orientationchange", c), window.addEventListener(a.orientationChangeEventName, s), a.enabled = !0;
|
|
258
|
+
}, this.disconnect = () => {
|
|
259
|
+
window.removeEventListener("orientationchange", c), window.removeEventListener(a.orientationChangeEventName, s), a.enabled = !1, a.initialOffset = !1, a.deviceOrientation = null, a.lastQuaternion = null;
|
|
260
|
+
}, this.requestOrientationPermissions = () => {
|
|
261
|
+
window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? window.DeviceOrientationEvent.requestPermission().then((e) => {
|
|
262
|
+
e === "granted" ? this.eventEmitter.emit("deviceorientationgranted", { target: this }) : this.eventEmitter.emit("deviceorientationerror", {
|
|
263
|
+
code: "LOCAR_DEVICE_ORIENTATION_PERMISSION_DENIED",
|
|
264
|
+
message: "Permission for device orientation denied - AR will not work correctly"
|
|
265
|
+
});
|
|
266
|
+
}).catch((e) => {
|
|
267
|
+
this.eventEmitter.emit("deviceorientationerror", {
|
|
268
|
+
code: "LOCAR_DEVICE_ORIENTATION_PERMISSION_FAILED",
|
|
269
|
+
message: "Permission request for device orientation failed - AR will not work correctly",
|
|
270
|
+
error: JSON.stringify(e, null, 2)
|
|
271
|
+
});
|
|
272
|
+
}) : this.eventEmitter.emit("deviceorientationerror", {
|
|
273
|
+
code: "LOCAR_DEVICE_ORIENTATION_INTERNAL_ERROR",
|
|
274
|
+
message: "Internal error: no requestPermission() found although requestOrientationPermissions() was called - please raise an issue on GitHub"
|
|
275
|
+
});
|
|
276
|
+
}, this.update = () => {
|
|
277
|
+
if (a.enabled === !1) return;
|
|
278
|
+
let e = a.deviceOrientation;
|
|
279
|
+
if (e) {
|
|
280
|
+
let n = e.alpha ? r.degToRad(e.alpha) + a.alphaOffset : 0, o = e.beta ? r.degToRad(e.beta) : 0, s = e.gamma ? r.degToRad(e.gamma) : 0, c = a.screenOrientation ? r.degToRad(a.screenOrientation) : 0, u = new i();
|
|
281
|
+
if (g) {
|
|
282
|
+
l(u, n, o, s, c);
|
|
283
|
+
let i = new t().setFromQuaternion(u, "YXZ");
|
|
284
|
+
i.y = r.degToRad(360 - (e.webkitCompassHeading ?? 0)) + (a.orientationOffset || 0), u.setFromEuler(i);
|
|
285
|
+
} else l(u, n, o, s, c);
|
|
286
|
+
if (a.lastQuaternion && a.orientationChangeThreshold > 0 && u.angleTo(a.lastQuaternion) < a.orientationChangeThreshold) return;
|
|
287
|
+
if (a.smoothingFactor < 1 && a.lastQuaternion) {
|
|
288
|
+
let e = 1 - a.smoothingFactor;
|
|
289
|
+
a.object.quaternion.slerp(u, e);
|
|
290
|
+
} else a.object.quaternion.copy(u);
|
|
291
|
+
a.lastQuaternion = a.object.quaternion.clone(), window.dispatchEvent(new CustomEvent("camera-rotation-change", { detail: { cameraRotation: a.object.rotation } }));
|
|
292
|
+
}
|
|
293
|
+
}, this.getCorrectedHeading = () => {
|
|
294
|
+
let { deviceOrientation: e } = a;
|
|
295
|
+
if (!e) return 0;
|
|
296
|
+
let t = 0;
|
|
297
|
+
return g ? (t = 360 - (e.webkitCompassHeading ?? 0), a.orientationOffset && (t += a.orientationOffset * (180 / Math.PI), t = (t + 360) % 360)) : (e.absolute === !0 || a.orientationChangeEventName, t = e.alpha ? e.alpha : 0, t = (360 - t) % 360, t < 0 && (t += 360)), t;
|
|
298
|
+
}, this.updateAlphaOffset = () => {
|
|
299
|
+
a.initialOffset = !1;
|
|
300
|
+
}, this.dispose = () => {
|
|
301
|
+
a.disconnect();
|
|
302
|
+
}, this.getAlpha = () => {
|
|
303
|
+
let { deviceOrientation: e } = a;
|
|
304
|
+
return e && e.alpha ? r.degToRad(e.alpha) + a.alphaOffset : 0;
|
|
305
|
+
}, this.getBeta = () => {
|
|
306
|
+
let { deviceOrientation: e } = a;
|
|
307
|
+
return e && e.beta ? r.degToRad(e.beta) : 0;
|
|
308
|
+
}, this.getGamma = () => {
|
|
309
|
+
let { deviceOrientation: e } = a;
|
|
310
|
+
return e && e.gamma ? r.degToRad(e.gamma) : 0;
|
|
311
|
+
}, this.createObtainPermissionGestureDialog = () => {
|
|
312
|
+
let e = document.createElement("div");
|
|
313
|
+
e.classList.add(u);
|
|
314
|
+
let t = document.createElement("div");
|
|
315
|
+
t.classList.add(p);
|
|
316
|
+
let n = document.createElement("div");
|
|
317
|
+
n.classList.add(f);
|
|
318
|
+
let r = document.createElement("div");
|
|
319
|
+
r.classList.add(m);
|
|
320
|
+
let i = document.createElement("button");
|
|
321
|
+
i.classList.add(d), document.body.appendChild(e), this.enableInlineStyling === !0 && (e.style.fontFamily = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'", e.style.display = "flex", e.style.position = "fixed", e.style.zIndex = "100000", e.style.justifyContent = "center", e.style.alignItems = "center", e.style.backgroundColor = "rgba(0,0,0,0.2)", e.style.inset = "0", e.style.padding = "20px", t.style.backgroundColor = "rgba(220, 220, 220, 0.85)", t.style.padding = "6px 0", t.style.borderRadius = "10px", t.style.width = "100%", t.style.maxWidth = "400px", n.style.padding = "10px 12px", n.style.textAlign = "center", n.style.fontWeight = "400", n.style.fontSize = "13px", n.style.display = "flex", n.style.justifyContent = "center", n.style.alignItems = "center", r.style.display = "block", r.style.textAlign = "center", r.style.textDecoration = "none", r.style.borderTop = "rgb(180,180,180) solid 1px", i.style.display = "block", i.style.width = "100%", i.style.textAlign = "center", i.style.appearance = "none", i.style.background = "none", i.style.border = "none", i.style.outline = "none", i.style.padding = "10px", i.style.fontWeight = "400", i.style.fontSize = "16px", i.style.color = "#2e7cf1", i.style.cursor = "pointer"), e.appendChild(t), t.appendChild(n), t.appendChild(r), n.appendChild(document.createTextNode(h)), i.addEventListener("click", () => {
|
|
322
|
+
this.requestOrientationPermissions(), e.style.display = "none";
|
|
323
|
+
}), i.appendChild(document.createTextNode("OK")), r.appendChild(i), document.body.appendChild(e);
|
|
324
|
+
}, this.obtainPermissionGesture = () => {
|
|
325
|
+
this.preferConfirmDialog === !0 ? window.confirm(h) && this.requestOrientationPermissions() : this.createObtainPermissionGestureDialog();
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
on(e, t) {
|
|
329
|
+
this.eventEmitter.on(e, t);
|
|
330
|
+
}
|
|
331
|
+
}, C = class {
|
|
332
|
+
constructor(t) {
|
|
333
|
+
this.raycaster = new e.Raycaster(), this.normalisedMousePosition = null, t.domElement.addEventListener("click", (n) => {
|
|
334
|
+
this.normalisedMousePosition = new e.Vector2(n.clientX / t.domElement.clientWidth * 2 - 1, -(n.clientY / t.domElement.clientHeight * 2) + 1);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
raycast(e, t) {
|
|
338
|
+
if (this.normalisedMousePosition !== null) {
|
|
339
|
+
this.raycaster.setFromCamera(this.normalisedMousePosition, e);
|
|
340
|
+
let n = this.raycaster.intersectObjects(t.children, !1);
|
|
341
|
+
return this.normalisedMousePosition = null, n;
|
|
342
|
+
}
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
}, w = class extends o {
|
|
346
|
+
#e;
|
|
347
|
+
#t;
|
|
348
|
+
constructor(t = { video: { facingMode: "environment" } }, n) {
|
|
349
|
+
super(), this.sceneWebcam = new e.Scene(), n ? this.#e = document.querySelector(n) : (this.#e = document.createElement("video"), this.#e.setAttribute("autoplay", "true"), this.#e.setAttribute("playsinline", "true"), this.#e.style.cssText += "\n width: 100%;\n height: 100%;\n object-fit: cover;\n background: black;\n position: absolute;\n top: 0px;\n left: 0px;\n z-index: -100; \n ", document.body.appendChild(this.#e)), this.#t = null, navigator.mediaDevices && navigator.mediaDevices.getUserMedia ? navigator.mediaDevices.getUserMedia(t).then((e) => {
|
|
350
|
+
this.#t = e, this.#e?.addEventListener("loadedmetadata", () => {
|
|
351
|
+
this.#e.play(), this.emit("webcamstarted", {
|
|
352
|
+
videoWidth: this.#e.videoWidth,
|
|
353
|
+
videoHeight: this.#e.videoHeight
|
|
354
|
+
});
|
|
355
|
+
}), this.#e && (this.#e.srcObject = e);
|
|
356
|
+
}).catch((e) => {
|
|
357
|
+
this.emit("webcamerror", {
|
|
358
|
+
code: e.name,
|
|
359
|
+
message: e.message
|
|
360
|
+
});
|
|
361
|
+
}) : this.emit("webcamerror", {
|
|
362
|
+
code: "LOCAR_NO_MEDIA_DEVICES_API",
|
|
363
|
+
message: "Media devices API not supported"
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
getVideoDimensions() {
|
|
367
|
+
return `w ${this.#e.videoWidth}, h ${this.#e.videoHeight}`;
|
|
368
|
+
}
|
|
369
|
+
dispose() {
|
|
370
|
+
(this.#t?.getTracks() ?? []).forEach((e) => {
|
|
371
|
+
e.stop();
|
|
372
|
+
}), this.#t = null, this.#e?.remove(), this.#e = null;
|
|
373
|
+
}
|
|
545
374
|
};
|
|
375
|
+
//#endregion
|
|
376
|
+
export { s as App, C as ClickHandler, S as DeviceOrientationControls, o as EventEmitter, l as LocAR, c as SphMercProjection, w as Webcam };
|