aframe-babia-components 1.2.8 → 1.3.0

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.
Files changed (53) hide show
  1. package/components/filters/babia-selector.js +33 -21
  2. package/components/filters/babia-treebuilder.js +14 -13
  3. package/components/others/babia-navigator.js +94 -37
  4. package/components/others/babia-poster.js +369 -368
  5. package/components/others/babia-slider.js +63 -25
  6. package/components/others/common.js +60 -80
  7. package/components/visualizers/babia-doughnut.js +2 -1
  8. package/components/visualizers/babia-html.js +95 -118
  9. package/components/visualizers/babia-map.js +796 -0
  10. package/components/visualizers/babia-pie.js +2 -1
  11. package/dist/aframe-babia-components.js +7247 -6488
  12. package/dist/aframe-babia-components.min.js +1 -1
  13. package/dist/aframe-babia-components.min.js.LICENSE.txt +1 -1
  14. package/dist/aframe-babia-components.min.js.map +1 -1
  15. package/docs/APIs/OTHERS.md +4 -4
  16. package/docs/CONTRIBUTING.md +34 -25
  17. package/docs/RELEASE_NOTES.md +13 -2
  18. package/docs/Tutorials/HOW_TO_USE_BABIA_MAP.md +554 -0
  19. package/docs/Tutorials/ejemplo1.png +0 -0
  20. package/docs/Tutorials/ejemplo2.png +0 -0
  21. package/docs/Tutorials/ejemplo3.png +0 -0
  22. package/docs/Tutorials/pyramids.png +0 -0
  23. package/docs/Tutorials/singular.png +0 -0
  24. package/docs/Tutorials/terrain-vr-scenario.png +0 -0
  25. package/docs/Tutorials/terrain.png +0 -0
  26. package/examples/boats/boats2/data.json +206 -13
  27. package/examples/demos/map-terrain/assets/360-panorama.jpg +0 -0
  28. package/examples/demos/map-terrain/assets/floor-texture.jpg +0 -0
  29. package/examples/demos/map-terrain/assets/mapTextures/512sample.webp +0 -0
  30. package/examples/demos/map-terrain/assets/mapTextures/defaultTexture.webp +0 -0
  31. package/examples/demos/map-terrain/assets/maps/defaultMap.png +0 -0
  32. package/examples/demos/map-terrain/assets/maps/example.png +0 -0
  33. package/examples/demos/map-terrain/assets/metalic-texture.jpg +0 -0
  34. package/examples/demos/map-terrain/dist/aframe-lounge-component.min.js +1 -0
  35. package/examples/demos/map-terrain/index.html +82 -0
  36. package/examples/demos/map-terrain/index_gallery.html +188 -0
  37. package/examples/demos/map-terrain/main_data.json +1 -0
  38. package/examples/demos/map-terrain/pyramids.html +130 -0
  39. package/examples/js/aframe-orbit-controls-component.js +1060 -0
  40. package/examples/ui/pie/index.html +0 -1
  41. package/index.html +15 -0
  42. package/index.js +1 -0
  43. package/package.json +5 -5
  44. package/tests/screenshots/other_snapshots.js/pyramids.png +0 -0
  45. package/tests/screenshots/other_snapshots.js/singular.png +0 -0
  46. package/tests/screenshots/other_snapshots.js/terrain-vr-scenario.png +0 -0
  47. package/tests/screenshots/other_snapshots.js/terrain.png +0 -0
  48. package/webpack.common.js +1 -1
  49. package/webpack.dev.js +17 -0
  50. package/examples/demos/citations/babiaxr.json +0 -1
  51. package/examples/demos/citations/citations.html +0 -72
  52. package/examples/demos/citations/music.mp3 +0 -0
  53. package/examples/demos/citations/stl.js +0 -28
@@ -0,0 +1,1060 @@
1
+ /******/ (function(modules) { // webpackBootstrap
2
+ /******/ // The module cache
3
+ /******/ var installedModules = {};
4
+
5
+ /******/ // The require function
6
+ /******/ function __webpack_require__(moduleId) {
7
+
8
+ /******/ // Check if module is in cache
9
+ /******/ if(installedModules[moduleId])
10
+ /******/ return installedModules[moduleId].exports;
11
+
12
+ /******/ // Create a new module (and put it into the cache)
13
+ /******/ var module = installedModules[moduleId] = {
14
+ /******/ exports: {},
15
+ /******/ id: moduleId,
16
+ /******/ loaded: false
17
+ /******/ };
18
+
19
+ /******/ // Execute the module function
20
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
+
22
+ /******/ // Flag the module as loaded
23
+ /******/ module.loaded = true;
24
+
25
+ /******/ // Return the exports of the module
26
+ /******/ return module.exports;
27
+ /******/ }
28
+
29
+
30
+ /******/ // expose the modules object (__webpack_modules__)
31
+ /******/ __webpack_require__.m = modules;
32
+
33
+ /******/ // expose the module cache
34
+ /******/ __webpack_require__.c = installedModules;
35
+
36
+ /******/ // __webpack_public_path__
37
+ /******/ __webpack_require__.p = "";
38
+
39
+ /******/ // Load entry module and return exports
40
+ /******/ return __webpack_require__(0);
41
+ /******/ })
42
+ /************************************************************************/
43
+ /******/ ([
44
+ /* 0 */
45
+ /***/ (function(module, exports) {
46
+
47
+ /* global AFRAME THREE */
48
+
49
+ if (typeof AFRAME === 'undefined') {
50
+ throw new Error('Component attempted to register before AFRAME was available.');
51
+ }
52
+
53
+ var radToDeg = THREE.Math.radToDeg;
54
+
55
+ /**
56
+ * Example component for A-Frame.
57
+ */
58
+ AFRAME.registerComponent('orbit-controls', {
59
+ dependencies: ['position', 'rotation'],
60
+ schema: {
61
+ enabled: {
62
+ default: true
63
+ },
64
+ target: {
65
+ default: ''
66
+ },
67
+ distance: {
68
+ default: 1
69
+ },
70
+ enableRotate: {
71
+ default: true
72
+ },
73
+ rotateSpeed: {
74
+ default: 1.0
75
+ },
76
+ enableZoom: {
77
+ default: true
78
+ },
79
+ zoomSpeed: {
80
+ default: 1.0
81
+ },
82
+ enablePan: {
83
+ default: true
84
+ },
85
+ keyPanSpeed: {
86
+ default: 7.0
87
+ },
88
+ enableDamping: {
89
+ default: false
90
+ },
91
+ dampingFactor: {
92
+ default: 0.25
93
+ },
94
+ autoRotate: {
95
+ default: false
96
+ },
97
+ autoRotateSpeed: {
98
+ default: 2.0
99
+ },
100
+ enableKeys: {
101
+ default: true
102
+ },
103
+ minAzimuthAngle: {
104
+ default: -Infinity
105
+ },
106
+ maxAzimuthAngle: {
107
+ default: Infinity
108
+ },
109
+ minPolarAngle: {
110
+ default: 0
111
+ },
112
+ maxPolarAngle: {
113
+ default: Math.PI
114
+ },
115
+ minZoom: {
116
+ default: 0
117
+ },
118
+ maxZoom: {
119
+ default: Infinity
120
+ },
121
+ invertZoom: {
122
+ default: false
123
+ },
124
+ minDistance: {
125
+ default: 0
126
+ },
127
+ maxDistance: {
128
+ default: Infinity
129
+ },
130
+ rotateTo: {
131
+ type: 'vec3',
132
+ default: {x: 0, y: 0, z: 0}
133
+ },
134
+ rotateToSpeed: {
135
+ type: 'number',
136
+ default: 0.05
137
+ },
138
+ logPosition: {
139
+ type: 'boolean',
140
+ default: false
141
+ },
142
+ autoVRLookCam: {
143
+ type: 'boolean',
144
+ default: true
145
+ },
146
+ enableProportionalVelocity: {
147
+ type: 'boolean',
148
+ default: true
149
+ }
150
+ },
151
+
152
+ /**
153
+ * Set if component needs multiple instancing.
154
+ */
155
+ multiple: false,
156
+
157
+ /**
158
+ * Called once when component is attached. Generally for initial setup.
159
+ */
160
+ init: function () {
161
+ this.sceneEl = this.el.sceneEl;
162
+ this.object = this.el.object3D;
163
+ this.target = this.sceneEl.querySelector(this.data.target).object3D.position;
164
+
165
+ console.log('enabled: ', this.data.enabled);
166
+
167
+ // Find the look-controls component on this camera, or create if it doesn't exist.
168
+ this.isRunning = false;
169
+ this.lookControls = null;
170
+
171
+ if (this.data.autoVRLookCam) {
172
+ if (this.el.components['look-controls']) {
173
+ this.lookControls = this.el.components['look-controls'];
174
+ } else {
175
+ this.el.setAttribute('look-controls', '');
176
+ this.lookControls = this.el.components['look-controls'];
177
+ }
178
+ this.lookControls.pause();
179
+ this.el.sceneEl.addEventListener('enter-vr', this.onEnterVR.bind(this), false);
180
+ this.el.sceneEl.addEventListener('exit-vr', this.onExitVR.bind(this), false);
181
+ }
182
+
183
+ this.dolly = new THREE.Object3D();
184
+ this.dolly.position.copy(this.object.position);
185
+
186
+ this.savedPose = null;
187
+
188
+ this.STATE = {
189
+ NONE: -1,
190
+ ROTATE: 0,
191
+ DOLLY: 1,
192
+ PAN: 2,
193
+ TOUCH_ROTATE: 3,
194
+ TOUCH_DOLLY: 4,
195
+ TOUCH_PAN: 5,
196
+ ROTATE_TO: 6
197
+ };
198
+
199
+ this.state = this.STATE.NONE;
200
+
201
+ this.EPS = 0.000001;
202
+ this.lastPosition = new THREE.Vector3();
203
+ this.lastQuaternion = new THREE.Quaternion();
204
+
205
+ this.spherical = new THREE.Spherical();
206
+ this.sphericalDelta = new THREE.Spherical();
207
+
208
+ this.scale = 1.0;
209
+ this.zoomChanged = false;
210
+
211
+ this.rotateStart = new THREE.Vector2();
212
+ this.rotateEnd = new THREE.Vector2();
213
+ this.rotateDelta = new THREE.Vector2();
214
+
215
+ this.panStart = new THREE.Vector2();
216
+ this.panEnd = new THREE.Vector2();
217
+ this.panDelta = new THREE.Vector2();
218
+ this.panOffset = new THREE.Vector3();
219
+
220
+ this.dollyStart = new THREE.Vector2();
221
+ this.dollyEnd = new THREE.Vector2();
222
+ this.dollyDelta = new THREE.Vector2();
223
+
224
+ this.vector = new THREE.Vector3();
225
+ this.desiredPosition = new THREE.Vector3();
226
+
227
+ this.mouseButtons = {
228
+ ORBIT: THREE.MOUSE.LEFT,
229
+ ZOOM: THREE.MOUSE.MIDDLE,
230
+ PAN: THREE.MOUSE.RIGHT
231
+ };
232
+
233
+ this.keys = {
234
+ LEFT: 37,
235
+ UP: 38,
236
+ RIGHT: 39,
237
+ BOTTOM: 40
238
+ };
239
+
240
+ this.bindMethods();
241
+ },
242
+
243
+ /**
244
+ * Called when component is attached and when component data changes.
245
+ * Generally modifies the entity based on the data.
246
+ */
247
+ update: function (oldData) {
248
+ console.log('component update');
249
+
250
+ if (this.data.rotateTo) {
251
+ var rotateToVec3 = new THREE.Vector3(this.data.rotateTo.x, this.data.rotateTo.y, this.data.rotateTo.z);
252
+ // Check if rotateToVec3 is already desiredPosition
253
+ if (!this.desiredPosition.equals(rotateToVec3)) {
254
+ this.desiredPosition.copy(rotateToVec3);
255
+ this.rotateTo(this.desiredPosition);
256
+ }
257
+ }
258
+
259
+ this.dolly.position.copy(this.object.position);
260
+ this.updateView(true);
261
+ },
262
+
263
+ /**
264
+ * Called when a component is removed (e.g., via removeAttribute).
265
+ * Generally undoes all modifications to the entity.
266
+ */
267
+ remove: function () {
268
+ // console.log("component remove");
269
+ this.isRunning = false;
270
+ this.removeEventListeners();
271
+ this.el.sceneEl.removeEventListener('enter-vr', this.onEnterVR, false);
272
+ this.el.sceneEl.removeEventListener('exit-vr', this.onExitVR, false);
273
+ },
274
+
275
+ /**
276
+ * Called on each scene tick.
277
+ */
278
+ tick: function (t) {
279
+ var render = this.data.enabled && this.isRunning ? this.updateView() : false;
280
+ if (render === true && this.data.logPosition === true) {
281
+ console.log(this.el.object3D.position);
282
+ }
283
+ },
284
+
285
+ /*
286
+ * Called when entering VR mode
287
+ */
288
+ onEnterVR: function (event) {
289
+ // console.log('enter vr', this);
290
+
291
+ this.saveCameraPose();
292
+
293
+ this.el.setAttribute('position', {x: 0, y: 2, z: 5});
294
+ this.el.setAttribute('rotation', {x: 0, y: 0, z: 0});
295
+
296
+ this.pause();
297
+ this.lookControls.play();
298
+ if (this.data.autoRotate) console.warn('orbit-controls: Sorry, autoRotate is not implemented in VR mode');
299
+ },
300
+
301
+ /*
302
+ * Called when exiting VR mode
303
+ */
304
+ onExitVR: function (event) {
305
+ // console.log('exit vr');
306
+
307
+ this.lookControls.pause();
308
+ this.play();
309
+
310
+ this.restoreCameraPose();
311
+ this.updateView(true);
312
+ },
313
+
314
+ /**
315
+ * Called when entity pauses.
316
+ * Use to stop or remove any dynamic or background behavior such as events.
317
+ */
318
+ pause: function () {
319
+ // console.log("component pause");
320
+ this.isRunning = false;
321
+ this.removeEventListeners();
322
+ },
323
+
324
+ /**
325
+ * Called when entity resumes.
326
+ * Use to continue or add any dynamic or background behavior such as events.
327
+ */
328
+ play: function () {
329
+ // console.log("component play");
330
+ this.isRunning = true;
331
+
332
+ var camera, cameraType;
333
+ this.object.traverse(function (child) {
334
+ if (child instanceof THREE.PerspectiveCamera) {
335
+ camera = child;
336
+ cameraType = 'PerspectiveCamera';
337
+ } else if (child instanceof THREE.OrthographicCamera) {
338
+ camera = child;
339
+ cameraType = 'OrthographicCamera';
340
+ }
341
+ });
342
+
343
+ this.camera = camera;
344
+ this.cameraType = cameraType;
345
+
346
+ this.sceneEl.addEventListener('renderstart', this.onRenderTargetLoaded, false);
347
+
348
+ if (this.lookControls) this.lookControls.pause();
349
+ if (this.canvasEl) this.addEventListeners();
350
+ },
351
+
352
+ /*
353
+ * Called when Render Target is completely loaded
354
+ * Then set canvasEl and add event listeners
355
+ */
356
+ onRenderTargetLoaded: function () {
357
+ this.sceneEl.removeEventListener('renderstart', this.onRenderTargetLoaded, false);
358
+ this.canvasEl = this.sceneEl.canvas;
359
+ this.addEventListeners();
360
+ },
361
+
362
+ /*
363
+ * Bind this to all event handlera
364
+ */
365
+ bindMethods: function () {
366
+ this.onRenderTargetLoaded = this.onRenderTargetLoaded.bind(this);
367
+
368
+ this.onContextMenu = this.onContextMenu.bind(this);
369
+ this.onMouseDown = this.onMouseDown.bind(this);
370
+ this.onMouseWheel = this.onMouseWheel.bind(this);
371
+ this.onMouseMove = this.onMouseMove.bind(this);
372
+ this.onMouseUp = this.onMouseUp.bind(this);
373
+ this.onTouchStart = this.onTouchStart.bind(this);
374
+ this.onTouchMove = this.onTouchMove.bind(this);
375
+ this.onTouchEnd = this.onTouchEnd.bind(this);
376
+ this.onKeyDown = this.onKeyDown.bind(this);
377
+ },
378
+
379
+ /*
380
+ * Add event listeners
381
+ */
382
+ addEventListeners: function () {
383
+ this.canvasEl.addEventListener('contextmenu', this.onContextMenu, false);
384
+
385
+ this.canvasEl.addEventListener('mousedown', this.onMouseDown, false);
386
+ this.canvasEl.addEventListener('mousewheel', this.onMouseWheel, false);
387
+ this.canvasEl.addEventListener('MozMousePixelScroll', this.onMouseWheel, false); // firefox
388
+
389
+ this.canvasEl.addEventListener('touchstart', this.onTouchStart, false);
390
+ this.canvasEl.addEventListener('touchend', this.onTouchEnd, false);
391
+ this.canvasEl.addEventListener('touchmove', this.onTouchMove, false);
392
+
393
+ window.addEventListener('keydown', this.onKeyDown, false);
394
+ },
395
+
396
+ /*
397
+ * Remove event listeners
398
+ */
399
+ removeEventListeners: function () {
400
+
401
+ if(this.canvasEl){
402
+ this.canvasEl.removeEventListener('contextmenu', this.onContextMenu, false);
403
+ this.canvasEl.removeEventListener('mousedown', this.onMouseDown, false);
404
+ this.canvasEl.removeEventListener('mousewheel', this.onMouseWheel, false);
405
+ this.canvasEl.removeEventListener('MozMousePixelScroll', this.onMouseWheel, false); // firefox
406
+
407
+ this.canvasEl.removeEventListener('touchstart', this.onTouchStart, false);
408
+ this.canvasEl.removeEventListener('touchend', this.onTouchEnd, false);
409
+ this.canvasEl.removeEventListener('touchmove', this.onTouchMove, false);
410
+
411
+ this.canvasEl.removeEventListener('mousemove', this.onMouseMove, false);
412
+ this.canvasEl.removeEventListener('mouseup', this.onMouseUp, false);
413
+ this.canvasEl.removeEventListener('mouseout', this.onMouseUp, false);
414
+ }
415
+
416
+ window.removeEventListener('keydown', this.onKeyDown, false);
417
+ },
418
+
419
+ /*
420
+ * EVENT LISTENERS
421
+ */
422
+
423
+ /*
424
+ * Called when right clicking the A-Frame component
425
+ */
426
+
427
+ onContextMenu: function (event) {
428
+ event.preventDefault();
429
+ },
430
+
431
+ /*
432
+ * MOUSE CLICK EVENT LISTENERS
433
+ */
434
+
435
+ onMouseDown: function (event) {
436
+ // console.log('onMouseDown');
437
+
438
+ if (!this.data.enabled || !this.isRunning) return;
439
+
440
+ if (event.button === this.mouseButtons.ORBIT && (event.shiftKey || event.ctrlKey)) {
441
+ if (this.data.enablePan === false) return;
442
+ this.handleMouseDownPan(event);
443
+ this.state = this.STATE.PAN;
444
+ } else if (event.button === this.mouseButtons.ORBIT) {
445
+ this.panOffset.set(0, 0, 0);
446
+ if (this.data.enableRotate === false) return;
447
+ this.handleMouseDownRotate(event);
448
+ this.state = this.STATE.ROTATE;
449
+ } else if (event.button === this.mouseButtons.ZOOM) {
450
+ this.panOffset.set(0, 0, 0);
451
+ if (this.data.enableZoom === false) return;
452
+ this.handleMouseDownDolly(event);
453
+ this.state = this.STATE.DOLLY;
454
+ } else if (event.button === this.mouseButtons.PAN) {
455
+ if (this.data.enablePan === false) return;
456
+ this.handleMouseDownPan(event);
457
+ this.state = this.STATE.PAN;
458
+ }
459
+
460
+ if (this.state !== this.STATE.NONE) {
461
+ this.canvasEl.addEventListener('mousemove', this.onMouseMove, false);
462
+ this.canvasEl.addEventListener('mouseup', this.onMouseUp, false);
463
+ this.canvasEl.addEventListener('mouseout', this.onMouseUp, false);
464
+
465
+ this.el.emit('start-drag-orbit-controls', null, false);
466
+ }
467
+ },
468
+
469
+ onMouseMove: function (event) {
470
+ // console.log('onMouseMove');
471
+
472
+ if (!this.data.enabled || !this.isRunning) return;
473
+
474
+ event.preventDefault();
475
+
476
+ if (this.state === this.STATE.ROTATE) {
477
+ if (this.data.enableRotate === false) return;
478
+ this.handleMouseMoveRotate(event);
479
+ } else if (this.state === this.STATE.DOLLY) {
480
+ if (this.data.enableZoom === false) return;
481
+ this.handleMouseMoveDolly(event);
482
+ } else if (this.state === this.STATE.PAN) {
483
+ if (this.data.enablePan === false) return;
484
+ this.handleMouseMovePan(event);
485
+ }
486
+ },
487
+
488
+ onMouseUp: function (event) {
489
+ // console.log('onMouseUp');
490
+
491
+ if (!this.data.enabled || !this.isRunning) return;
492
+
493
+ if (this.state === this.STATE.ROTATE_TO) return;
494
+
495
+ event.preventDefault();
496
+ event.stopPropagation();
497
+
498
+ this.handleMouseUp(event);
499
+
500
+ this.canvasEl.removeEventListener('mousemove', this.onMouseMove, false);
501
+ this.canvasEl.removeEventListener('mouseup', this.onMouseUp, false);
502
+ this.canvasEl.removeEventListener('mouseout', this.onMouseUp, false);
503
+
504
+ this.state = this.STATE.NONE;
505
+
506
+ this.el.emit('end-drag-orbit-controls', null, false);
507
+ },
508
+
509
+ /*
510
+ * MOUSE WHEEL EVENT LISTENERS
511
+ */
512
+
513
+ onMouseWheel: function (event) {
514
+ // console.log('onMouseWheel');
515
+
516
+ if (!this.data.enabled || !this.isRunning || this.data.enableZoom === false || (this.state !== this.STATE.NONE && this.state !== this.STATE.ROTATE)) return;
517
+
518
+ event.preventDefault();
519
+ event.stopPropagation();
520
+ this.handleMouseWheel(event);
521
+ },
522
+
523
+ /*
524
+ * TOUCH EVENT LISTENERS
525
+ */
526
+
527
+ onTouchStart: function (event) {
528
+ // console.log('onTouchStart');
529
+
530
+ if (!this.data.enabled || !this.isRunning) return;
531
+
532
+ switch (event.touches.length) {
533
+ case 1: // one-fingered touch: rotate
534
+ if (this.data.enableRotate === false) return;
535
+ this.handleTouchStartRotate(event);
536
+ this.state = this.STATE.TOUCH_ROTATE;
537
+ break;
538
+ case 2: // two-fingered touch: dolly
539
+ if (this.data.enableZoom === false) return;
540
+ this.handleTouchStartDolly(event);
541
+ this.state = this.STATE.TOUCH_DOLLY;
542
+ break;
543
+ case 3: // three-fingered touch: pan
544
+ if (this.data.enablePan === false) return;
545
+ this.handleTouchStartPan(event);
546
+ this.state = this.STATE.TOUCH_PAN;
547
+ break;
548
+ default:
549
+ this.state = this.STATE.NONE;
550
+ }
551
+
552
+ if (this.state !== this.STATE.NONE) {
553
+ this.el.emit('start-drag-orbit-controls', null, false);
554
+ }
555
+ },
556
+
557
+ onTouchMove: function (event) {
558
+ // console.log('onTouchMove');
559
+
560
+ if (!this.data.enabled || !this.isRunning) return;
561
+
562
+ event.preventDefault();
563
+ event.stopPropagation();
564
+
565
+ switch (event.touches.length) {
566
+ case 1: // one-fingered touch: rotate
567
+ if (this.enableRotate === false) return;
568
+ if (this.state !== this.STATE.TOUCH_ROTATE) return; // is this needed?...
569
+ this.handleTouchMoveRotate(event);
570
+ break;
571
+
572
+ case 2: // two-fingered touch: dolly
573
+ if (this.data.enableZoom === false) return;
574
+ if (this.state !== this.STATE.TOUCH_DOLLY) return; // is this needed?...
575
+ this.handleTouchMoveDolly(event);
576
+ break;
577
+
578
+ case 3: // three-fingered touch: pan
579
+ if (this.data.enablePan === false) return;
580
+ if (this.state !== this.STATE.TOUCH_PAN) return; // is this needed?...
581
+ this.handleTouchMovePan(event);
582
+ break;
583
+
584
+ default:
585
+ this.state = this.STATE.NONE;
586
+ }
587
+ },
588
+
589
+ onTouchEnd: function (event) {
590
+ // console.log('onTouchEnd');
591
+
592
+ if (!this.data.enabled || !this.isRunning) return;
593
+
594
+ this.handleTouchEnd(event);
595
+
596
+ this.el.emit('end-drag-orbit-controls', null, false);
597
+
598
+ this.state = this.STATE.NONE;
599
+ },
600
+
601
+ /*
602
+ * KEYBOARD EVENT LISTENERS
603
+ */
604
+
605
+ onKeyDown: function (event) {
606
+ // console.log('onKeyDown');
607
+
608
+ if (!this.data.enabled || !this.isRunning || this.data.enableKeys === false || this.data.enablePan === false) return;
609
+
610
+ this.handleKeyDown(event);
611
+ },
612
+
613
+ /*
614
+ * EVENT HANDLERS
615
+ */
616
+
617
+ /*
618
+ * MOUSE CLICK EVENT HANDLERS
619
+ */
620
+
621
+ handleMouseDownRotate: function (event) {
622
+ // console.log( 'handleMouseDownRotate' );
623
+ this.rotateStart.set(event.clientX, event.clientY);
624
+ },
625
+
626
+ handleMouseDownDolly: function (event) {
627
+ // console.log( 'handleMouseDownDolly' );
628
+ this.dollyStart.set(event.clientX, event.clientY);
629
+ },
630
+
631
+ handleMouseDownPan: function (event) {
632
+ // console.log( 'handleMouseDownPan' );
633
+ this.panStart.set(event.clientX, event.clientY);
634
+ },
635
+
636
+ handleMouseMoveRotate: function (event) {
637
+ // console.log( 'handleMouseMoveRotate' );
638
+
639
+ this.rotateEnd.set(event.clientX, event.clientY);
640
+ this.rotateDelta.subVectors(this.rotateEnd, this.rotateStart);
641
+
642
+ var canvas = this.canvasEl === document ? this.canvasEl.body : this.canvasEl;
643
+
644
+ // rotate less if closer
645
+ let ratio = 1;
646
+ if(this.data.enableProportionalVelocity) {
647
+ ratio = (this.spherical.radius-this.data.minDistance) / (this.data.maxDistance-this.data.minDistance);
648
+ }
649
+
650
+ // rotating across whole screen goes 360 degrees around
651
+ this.rotateLeft(2 * Math.PI * this.rotateDelta.x / canvas.clientWidth * this.data.rotateSpeed * ratio);
652
+
653
+ // rotating up and down along whole screen attempts to go 360, but limited to 180
654
+ this.rotateUp(2 * Math.PI * this.rotateDelta.y / canvas.clientHeight * this.data.rotateSpeed * ratio);
655
+
656
+ this.rotateStart.copy(this.rotateEnd);
657
+
658
+ this.updateView();
659
+ },
660
+
661
+ handleMouseMoveDolly: function (event) {
662
+ // console.log( 'handleMouseMoveDolly' );
663
+
664
+ this.dollyEnd.set(event.clientX, event.clientY);
665
+ this.dollyDelta.subVectors(this.dollyEnd, this.dollyStart);
666
+
667
+ if (this.dollyDelta.y > 0) {
668
+ !this.data.invertZoom ? this.dollyIn(this.getZoomScale()) : this.dollyOut(this.getZoomScale());
669
+ } else if (this.dollyDelta.y < 0) {
670
+ !this.data.invertZoom ? this.dollyOut(this.getZoomScale()) : this.dollyIn(this.getZoomScale());
671
+ }
672
+
673
+ this.dollyStart.copy(this.dollyEnd);
674
+
675
+ this.updateView();
676
+ },
677
+
678
+ handleMouseMovePan: function (event) {
679
+ // console.log( 'handleMouseMovePan' );
680
+
681
+ this.panEnd.set(event.clientX, event.clientY);
682
+ this.panDelta.subVectors(this.panEnd, this.panStart);
683
+ this.pan(this.panDelta.x, this.panDelta.y);
684
+ this.panStart.copy(this.panEnd);
685
+
686
+ this.updateView();
687
+ },
688
+
689
+ handleMouseUp: function (event) {
690
+ // console.log( 'handleMouseUp' );
691
+ },
692
+
693
+ /*
694
+ * MOUSE WHEEL EVENT HANDLERS
695
+ */
696
+
697
+ handleMouseWheel: function (event) {
698
+ // console.log( 'handleMouseWheel' );
699
+
700
+ var delta = 0;
701
+ if (event.wheelDelta !== undefined) {
702
+ // WebKit / Opera / Explorer 9
703
+ delta = event.wheelDelta;
704
+ } else if (event.detail !== undefined) {
705
+ // Firefox
706
+ delta = -event.detail;
707
+ }
708
+
709
+ if (delta > 0) {
710
+ !this.data.invertZoom ? this.dollyOut(this.getZoomScale()) : this.dollyIn(this.getZoomScale());
711
+ } else if (delta < 0) {
712
+ !this.data.invertZoom ? this.dollyIn(this.getZoomScale()) : this.dollyOut(this.getZoomScale());
713
+ }
714
+
715
+ this.updateView();
716
+ },
717
+
718
+ /*
719
+ * TOUCH EVENT HANDLERS
720
+ */
721
+
722
+ handleTouchStartRotate: function (event) {
723
+ // console.log( 'handleTouchStartRotate' );
724
+
725
+ this.rotateStart.set(event.touches[0].pageX, event.touches[0].pageY);
726
+ },
727
+
728
+ handleTouchStartDolly: function (event) {
729
+ // console.log( 'handleTouchStartDolly' );
730
+
731
+ var dx = event.touches[0].pageX - event.touches[1].pageX;
732
+ var dy = event.touches[0].pageY - event.touches[1].pageY;
733
+ var distance = Math.sqrt(dx * dx + dy * dy);
734
+ this.dollyStart.set(0, distance);
735
+ },
736
+
737
+ handleTouchStartPan: function (event) {
738
+ // console.log( 'handleTouchStartPan' );
739
+
740
+ this.panStart.set(event.touches[0].pageX, event.touches[0].pageY);
741
+ },
742
+
743
+ handleTouchMoveRotate: function (event) {
744
+ // console.log( 'handleTouchMoveRotate' );
745
+
746
+ this.rotateEnd.set(event.touches[0].pageX, event.touches[0].pageY);
747
+ this.rotateDelta.subVectors(this.rotateEnd, this.rotateStart);
748
+
749
+ var canvas = this.canvasEl === document ? this.canvasEl.body : this.canvasEl;
750
+
751
+ // rotate less if closer
752
+ let ratio = 1;
753
+ if(this.data.enableProportionalVelocity) {
754
+ ratio = (this.spherical.radius-this.data.minDistance) / (this.data.maxDistance-this.data.minDistance);
755
+ }
756
+
757
+ // rotating across whole screen goes 360 degrees around
758
+ this.rotateLeft(2 * Math.PI * this.rotateDelta.x / canvas.clientWidth * this.data.rotateSpeed * ratio);
759
+ // rotating up and down along whole screen attempts to go 360, but limited to 180
760
+ this.rotateUp(2 * Math.PI * this.rotateDelta.y / canvas.clientHeight * this.data.rotateSpeed * ratio);
761
+ this.rotateStart.copy(this.rotateEnd);
762
+ this.updateView();
763
+ },
764
+
765
+ handleTouchMoveDolly: function (event) {
766
+ // console.log( 'handleTouchMoveDolly' );
767
+
768
+ var dx = event.touches[0].pageX - event.touches[1].pageX;
769
+ var dy = event.touches[0].pageY - event.touches[1].pageY;
770
+
771
+ var distance = Math.sqrt(dx * dx + dy * dy);
772
+
773
+ this.dollyEnd.set(0, distance);
774
+ this.dollyDelta.subVectors(this.dollyEnd, this.dollyStart);
775
+ if (this.dollyDelta.y > 0) {
776
+ this.dollyIn(this.getZoomScale());
777
+ } else if (this.dollyDelta.y < 0) {
778
+ this.dollyOut(this.getZoomScale());
779
+ }
780
+
781
+ this.dollyStart.copy(this.dollyEnd);
782
+ this.updateView();
783
+ },
784
+
785
+ handleTouchMovePan: function (event) {
786
+ // console.log( 'handleTouchMovePan' );
787
+
788
+ this.panEnd.set(event.touches[0].pageX, event.touches[0].pageY);
789
+ this.panDelta.subVectors(this.panEnd, this.panStart);
790
+ this.pan(this.panDelta.x, this.panDelta.y);
791
+ this.panStart.copy(this.panEnd);
792
+ this.updateView();
793
+ },
794
+
795
+ handleTouchEnd: function (event) {
796
+ // console.log( 'handleTouchEnd' );
797
+ },
798
+
799
+ /*
800
+ * KEYBOARD EVENT HANDLERS
801
+ */
802
+
803
+ handleKeyDown: function (event) {
804
+ // console.log( 'handleKeyDown' );
805
+
806
+ switch (event.keyCode) {
807
+ case this.keys.UP:
808
+ this.pan(0, this.data.keyPanSpeed);
809
+ this.updateView();
810
+ break;
811
+ case this.keys.BOTTOM:
812
+ this.pan(0, -this.data.keyPanSpeed);
813
+ this.updateView();
814
+ break;
815
+ case this.keys.LEFT:
816
+ this.pan(this.data.keyPanSpeed, 0);
817
+ this.updateView();
818
+ break;
819
+ case this.keys.RIGHT:
820
+ this.pan(-this.data.keyPanSpeed, 0);
821
+ this.updateView();
822
+ break;
823
+ }
824
+ },
825
+
826
+ /*
827
+ * HELPER FUNCTIONS
828
+ */
829
+
830
+ getAutoRotationAngle: function () {
831
+ return 2 * Math.PI / 60 / 60 * this.data.autoRotateSpeed;
832
+ },
833
+
834
+ getZoomScale: function () {
835
+
836
+ // deviation from 1 is the degree of zoom - a constant - we need something more flexible.
837
+ if(!this.data.enableProportionalVelocity) {
838
+ let speed = Math.pow(0.95, this.data.zoomSpeed);
839
+ return speed;
840
+ } else {
841
+ // 0.9 = deviation from zoom at far, and 1 = deviation from zoom at near - with a strong bias to be near 1.0 in general
842
+ let speed = (this.data.maxDistance*10-this.spherical.radius) / (this.data.maxDistance*10-this.data.minDistance);
843
+ return speed;
844
+ }
845
+
846
+ },
847
+
848
+ rotateLeft: function (angle) {
849
+ this.sphericalDelta.theta -= angle;
850
+ },
851
+
852
+ rotateUp: function (angle) {
853
+ this.sphericalDelta.phi -= angle;
854
+ },
855
+
856
+ rotateTo: function (vec3) {
857
+ this.state = this.STATE.ROTATE_TO;
858
+ this.desiredPosition.copy(vec3);
859
+ },
860
+
861
+ panHorizontally: function (distance, objectMatrix) {
862
+ // console.log('pan horizontally', distance, objectMatrix);
863
+ var v = new THREE.Vector3();
864
+ v.setFromMatrixColumn(objectMatrix, 0); // get X column of objectMatrix
865
+ v.multiplyScalar(-distance);
866
+ this.panOffset.add(v);
867
+ },
868
+
869
+ panVertically: function (distance, objectMatrix) {
870
+ // console.log('pan vertically', distance, objectMatrix);
871
+ var v = new THREE.Vector3();
872
+ v.setFromMatrixColumn(objectMatrix, 1); // get Y column of objectMatrix
873
+ v.multiplyScalar(distance);
874
+ this.panOffset.add(v);
875
+ },
876
+
877
+ pan: function (deltaX, deltaY) { // deltaX and deltaY are in pixels; right and down are positive
878
+ // console.log('panning', deltaX, deltaY );
879
+ var offset = new THREE.Vector3();
880
+ var canvas = this.canvasEl === document ? this.canvasEl.body : this.canvasEl;
881
+
882
+ if (this.cameraType === 'PerspectiveCamera') {
883
+ // perspective
884
+ var position = this.dolly.position;
885
+ offset.copy(position).sub(this.target);
886
+ var targetDistance = offset.length();
887
+ targetDistance *= Math.tan((this.camera.fov / 2) * Math.PI / 180.0); // half of the fov is center to top of screen
888
+ this.panHorizontally(2 * deltaX * targetDistance / canvas.clientHeight, this.object.matrix); // we actually don't use screenWidth, since perspective camera is fixed to screen height
889
+ this.panVertically(2 * deltaY * targetDistance / canvas.clientHeight, this.object.matrix);
890
+ } else if (this.cameraType === 'OrthographicCamera') {
891
+ // orthographic
892
+ this.panHorizontally(deltaX * (this.dolly.right - this.dolly.left) / this.camera.zoom / canvas.clientWidth, this.object.matrix);
893
+ this.panVertically(deltaY * (this.dolly.top - this.dolly.bottom) / this.camera.zoom / canvas.clientHeight, this.object.matrix);
894
+ } else {
895
+ // camera neither orthographic nor perspective
896
+ console.warn('Trying to pan: WARNING: Orbit Controls encountered an unknown camera type - pan disabled.');
897
+ this.data.enablePan = false;
898
+ }
899
+ },
900
+
901
+ dollyIn: function (dollyScale) {
902
+ // console.log( "dollyIn camera" );
903
+ if (this.cameraType === 'PerspectiveCamera') {
904
+ this.scale *= dollyScale;
905
+ } else if (this.cameraType === 'OrthographicCamera') {
906
+ this.camera.zoom = Math.max(this.data.minZoom, Math.min(this.data.maxZoom, this.camera.zoom * dollyScale));
907
+ this.camera.updateProjectionMatrix();
908
+ this.zoomChanged = true;
909
+ } else {
910
+ console.warn('Trying to dolly in: WARNING: Orbit Controls encountered an unknown camera type - dolly/zoom disabled.');
911
+ this.data.enableZoom = false;
912
+ }
913
+ },
914
+
915
+ dollyOut: function (dollyScale) {
916
+ // console.log( "dollyOut camera" );
917
+ if (this.cameraType === 'PerspectiveCamera') {
918
+ this.scale /= dollyScale;
919
+ } else if (this.cameraType === 'OrthographicCamera') {
920
+ this.camera.zoom = Math.max(this.data.minZoom, Math.min(this.data.maxZoom, this.camera.zoom / dollyScale));
921
+ this.camera.updateProjectionMatrix();
922
+ this.zoomChanged = true;
923
+ } else {
924
+ console.warn('Trying to dolly out: WARNING: Orbit Controls encountered an unknown camera type - dolly/zoom disabled.');
925
+ this.data.enableZoom = false;
926
+ }
927
+ },
928
+
929
+ lookAtTarget: function (object, target) {
930
+ var v = new THREE.Vector3();
931
+ v.subVectors(object.position, target).add(object.position);
932
+ object.lookAt(v);
933
+ },
934
+
935
+ /*
936
+ * SAVES CAMERA POSE (WHEN ENTERING VR)
937
+ */
938
+
939
+ saveCameraPose: function () {
940
+ if (this.savedPose) { return; }
941
+ this.savedPose = {
942
+ position: this.dolly.position,
943
+ rotation: this.dolly.rotation
944
+ };
945
+ },
946
+
947
+ /*
948
+ * RESTORE CAMERA POSE (WHEN EXITING VR)
949
+ */
950
+
951
+ restoreCameraPose: function () {
952
+ if (!this.savedPose) { return; }
953
+ this.dolly.position.copy(this.savedPose.position);
954
+ this.dolly.rotation.copy(this.savedPose.rotation);
955
+ this.savedPose = null;
956
+ },
957
+
958
+ /*
959
+ * VIEW UPDATE
960
+ */
961
+
962
+ updateView: function (forceUpdate) {
963
+ if (this.desiredPosition && this.state === this.STATE.ROTATE_TO) {
964
+ var desiredSpherical = new THREE.Spherical();
965
+ desiredSpherical.setFromVector3(this.desiredPosition);
966
+ var phiDiff = desiredSpherical.phi - this.spherical.phi;
967
+ var thetaDiff = desiredSpherical.theta - this.spherical.theta;
968
+ this.sphericalDelta.set(this.spherical.radius, phiDiff * this.data.rotateToSpeed, thetaDiff * this.data.rotateToSpeed);
969
+ }
970
+
971
+ var offset = new THREE.Vector3();
972
+
973
+ var quat = new THREE.Quaternion().setFromUnitVectors(this.dolly.up, new THREE.Vector3(0, 1, 0)); // so camera.up is the orbit axis
974
+ var quatInverse = quat.clone().inverse();
975
+
976
+ offset.copy(this.dolly.position).sub(this.target);
977
+ offset.applyQuaternion(quat); // rotate offset to "y-axis-is-up" space
978
+ this.spherical.setFromVector3(offset); // angle from z-axis around y-axis
979
+
980
+ if (this.data.autoRotate && this.state === this.STATE.NONE) this.rotateLeft(this.getAutoRotationAngle());
981
+
982
+ this.spherical.theta += this.sphericalDelta.theta;
983
+ this.spherical.phi += this.sphericalDelta.phi;
984
+ this.spherical.theta = Math.max(this.data.minAzimuthAngle, Math.min(this.data.maxAzimuthAngle, this.spherical.theta)); // restrict theta to be inside desired limits
985
+ this.spherical.phi = Math.max(this.data.minPolarAngle, Math.min(this.data.maxPolarAngle, this.spherical.phi)); // restrict phi to be inside desired limits
986
+ this.spherical.makeSafe();
987
+ this.spherical.radius *= this.scale;
988
+ this.spherical.radius = Math.max(this.data.minDistance, Math.min(this.data.maxDistance, this.spherical.radius)); // restrict radius to be inside desired limits
989
+
990
+ this.target.add(this.panOffset); // move target to panned location
991
+
992
+ offset.setFromSpherical(this.spherical);
993
+ offset.applyQuaternion(quatInverse); // rotate offset back to "camera-up-vector-is-up" space
994
+
995
+ this.dolly.position.copy(this.target).add(offset);
996
+
997
+ if (this.target) {
998
+ this.lookAtTarget(this.dolly, this.target);
999
+ }
1000
+
1001
+ if (this.data.enableDamping === true) {
1002
+ this.sphericalDelta.theta *= (1 - this.data.dampingFactor);
1003
+ this.sphericalDelta.phi *= (1 - this.data.dampingFactor);
1004
+ } else {
1005
+ this.sphericalDelta.set(0, 0, 0);
1006
+ }
1007
+
1008
+ this.scale = 1;
1009
+ this.panOffset.set(0, 0, 0);
1010
+
1011
+ // update condition is:
1012
+ // min(camera displacement, camera rotation in radians)^2 > EPS
1013
+ // using small-angle approximation cos(x/2) = 1 - x^2 / 8
1014
+
1015
+ if (forceUpdate === true ||
1016
+ this.zoomChanged ||
1017
+ this.lastPosition.distanceToSquared(this.dolly.position) > this.EPS ||
1018
+ 8 * (1 - this.lastQuaternion.dot(this.dolly.quaternion)) > this.EPS) {
1019
+ // this.el.emit('change-drag-orbit-controls', null, false);
1020
+
1021
+ var hmdQuaternion = this.calculateHMDQuaternion();
1022
+ var hmdEuler = new THREE.Euler();
1023
+ hmdEuler.setFromQuaternion(hmdQuaternion, 'YXZ');
1024
+
1025
+ this.el.setAttribute('position', {
1026
+ x: this.dolly.position.x,
1027
+ y: this.dolly.position.y,
1028
+ z: this.dolly.position.z
1029
+ });
1030
+
1031
+ this.el.setAttribute('rotation', {
1032
+ x: radToDeg(hmdEuler.x),
1033
+ y: radToDeg(hmdEuler.y),
1034
+ z: radToDeg(hmdEuler.z)
1035
+ });
1036
+
1037
+ this.lastPosition.copy(this.dolly.position);
1038
+ this.lastQuaternion.copy(this.dolly.quaternion);
1039
+
1040
+ this.zoomChanged = false;
1041
+
1042
+ return true;
1043
+ }
1044
+
1045
+ return false;
1046
+ },
1047
+
1048
+ calculateHMDQuaternion: (function () {
1049
+ var hmdQuaternion = new THREE.Quaternion();
1050
+ return function () {
1051
+ hmdQuaternion.copy(this.dolly.quaternion);
1052
+ return hmdQuaternion;
1053
+ };
1054
+ })()
1055
+
1056
+ });
1057
+
1058
+
1059
+ /***/ })
1060
+ /******/ ]);