@easyv/react-component-builder 0.19.3 → 0.19.5-beta.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.
@@ -1,1051 +1,1051 @@
1
- var THREE = require('three')
2
-
3
- /**
4
- * @author qiao / https://github.com/qiao
5
- * @author mrdoob / http://mrdoob.com
6
- * @author alteredq / http://alteredqualia.com/
7
- * @author WestLangley / http://github.com/WestLangley
8
- * @author erich666 / http://erichaines.com
9
- */
10
-
11
- // This set of controls performs orbiting, dollying (zooming), and panning.
12
- // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
13
- //
14
- // Orbit - left mouse / touch: one-finger move
15
- // Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
16
- // Pan - right mouse, or arrow keys / touch: two-finger move
17
-
18
- THREE.OrbitControls = function ( object, domElement ) {
19
-
20
- this.object = object;
21
-
22
- this.domElement = ( domElement !== undefined ) ? domElement : document;
23
-
24
- // Set to false to disable this control
25
- this.enabled = true;
26
-
27
- // "target" sets the location of focus, where the object orbits around
28
- this.target = new THREE.Vector3();
29
-
30
- // How far you can dolly in and out ( PerspectiveCamera only )
31
- this.minDistance = 0;
32
- this.maxDistance = Infinity;
33
-
34
- // How far you can zoom in and out ( OrthographicCamera only )
35
- this.minZoom = 0;
36
- this.maxZoom = Infinity;
37
-
38
- // How far you can orbit vertically, upper and lower limits.
39
- // Range is 0 to Math.PI radians.
40
- this.minPolarAngle = 0; // radians
41
- this.maxPolarAngle = Math.PI; // radians
42
-
43
- // How far you can orbit horizontally, upper and lower limits.
44
- // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
45
- this.minAzimuthAngle = - Infinity; // radians
46
- this.maxAzimuthAngle = Infinity; // radians
47
-
48
- // Set to true to enable damping (inertia)
49
- // If damping is enabled, you must call controls.update() in your animation loop
50
- this.enableDamping = false;
51
- this.dampingFactor = 0.25;
52
-
53
- // This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
54
- // Set to false to disable zooming
55
- this.enableZoom = true;
56
- this.zoomSpeed = 1.0;
57
-
58
- // Set to false to disable rotating
59
- this.enableRotate = true;
60
- this.rotateSpeed = 1.0;
61
-
62
- // Set to false to disable panning
63
- this.enablePan = true;
64
- this.panSpeed = 1.0;
65
- this.screenSpacePanning = false; // if true, pan in screen-space
66
- this.keyPanSpeed = 7.0; // pixels moved per arrow key push
67
-
68
- // Set to true to automatically rotate around the target
69
- // If auto-rotate is enabled, you must call controls.update() in your animation loop
70
- this.autoRotate = false;
71
- this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
72
-
73
- // Set to false to disable use of the keys
74
- this.enableKeys = true;
75
-
76
- // The four arrow keys
77
- this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
78
-
79
- // Mouse buttons
80
- this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
81
-
82
- // for reset
83
- this.target0 = this.target.clone();
84
- this.position0 = this.object.position.clone();
85
- this.zoom0 = this.object.zoom;
86
-
87
- this.controlChange = false;
88
-
89
- //
90
- // public methods
91
- //
92
-
93
- this.getPolarAngle = function () {
94
-
95
- return spherical.phi;
96
-
97
- };
98
-
99
- this.getAzimuthalAngle = function () {
100
-
101
- return spherical.theta;
102
-
103
- };
104
-
105
- this.saveState = function () {
106
-
107
- scope.target0.copy( scope.target );
108
- scope.position0.copy( scope.object.position );
109
- scope.zoom0 = scope.object.zoom;
110
-
111
- };
112
-
113
- this.reset = function () {
114
-
115
- scope.target.copy( scope.target0 );
116
- scope.object.position.copy( scope.position0 );
117
- scope.object.zoom = scope.zoom0;
118
-
119
- scope.object.updateProjectionMatrix();
120
- scope.dispatchEvent( changeEvent );
121
-
122
- scope.update();
123
-
124
- state = STATE.NONE;
125
-
126
- };
127
-
128
- // this method is exposed, but perhaps it would be better if we can make it private...
129
- this.update = function () {
130
-
131
- var offset = new THREE.Vector3();
132
-
133
- // so camera.up is the orbit axis
134
- var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
135
- var quatInverse = quat.clone().inverse();
136
-
137
- var lastPosition = new THREE.Vector3();
138
- var lastQuaternion = new THREE.Quaternion();
139
-
140
- return function update() {
141
-
142
- var position = scope.object.position;
143
-
144
- offset.copy( position ).sub( scope.target );
145
-
146
- // rotate offset to "y-axis-is-up" space
147
- offset.applyQuaternion( quat );
148
-
149
- // angle from z-axis around y-axis
150
- spherical.setFromVector3( offset );
151
-
152
- if ( scope.autoRotate && state === STATE.NONE ) {
153
-
154
- rotateLeft( getAutoRotationAngle() );
155
-
156
- }
157
-
158
- spherical.theta += sphericalDelta.theta;
159
- spherical.phi += sphericalDelta.phi;
160
-
161
- // restrict theta to be between desired limits
162
- spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) );
163
-
164
- // restrict phi to be between desired limits
165
- spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
166
-
167
- spherical.makeSafe();
168
-
169
-
170
- spherical.radius *= scale;
171
-
172
- // restrict radius to be between desired limits
173
- spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
174
-
175
- // move target to panned location
176
- scope.target.add( panOffset );
177
-
178
- offset.setFromSpherical( spherical );
179
-
180
- // rotate offset back to "camera-up-vector-is-up" space
181
- offset.applyQuaternion( quatInverse );
182
-
183
- position.copy( scope.target ).add( offset );
184
-
185
- scope.object.lookAt( scope.target );
186
-
187
- if ( scope.enableDamping === true ) {
188
-
189
- sphericalDelta.theta *= ( 1 - scope.dampingFactor );
190
- sphericalDelta.phi *= ( 1 - scope.dampingFactor );
191
-
192
- panOffset.multiplyScalar( 1 - scope.dampingFactor );
193
-
194
- } else {
195
-
196
- sphericalDelta.set( 0, 0, 0 );
197
-
198
- panOffset.set( 0, 0, 0 );
199
-
200
- }
201
-
202
- scale = 1;
203
-
204
- // update condition is:
205
- // min(camera displacement, camera rotation in radians)^2 > EPS
206
- // using small-angle approximation cos(x/2) = 1 - x^2 / 8
207
-
208
- if ( zoomChanged ||
209
- lastPosition.distanceToSquared( scope.object.position ) > EPS ||
210
- 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
211
-
212
- scope.dispatchEvent( changeEvent );
213
-
214
- lastPosition.copy( scope.object.position );
215
- lastQuaternion.copy( scope.object.quaternion );
216
- zoomChanged = false;
217
-
218
- return true;
219
-
220
- }
221
-
222
- return false;
223
-
224
- };
225
-
226
- }();
227
-
228
- this.dispose = function () {
229
-
230
- scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false );
231
- scope.domElement.removeEventListener( 'mousedown', onMouseDown, false );
232
- scope.domElement.removeEventListener( 'wheel', onMouseWheel, false );
233
-
234
- scope.domElement.removeEventListener( 'touchstart', onTouchStart, false );
235
- scope.domElement.removeEventListener( 'touchend', onTouchEnd, false );
236
- scope.domElement.removeEventListener( 'touchmove', onTouchMove, false );
237
-
238
- document.removeEventListener( 'mousemove', onMouseMove, false );
239
- document.removeEventListener( 'mouseup', onMouseUp, false );
240
-
241
- window.removeEventListener( 'keydown', onKeyDown, false );
242
-
243
- //scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
244
-
245
- };
246
-
247
- //
248
- // internals
249
- //
250
-
251
- var scope = this;
252
-
253
- var changeEvent = { type: 'change' };
254
- var startEvent = { type: 'start' };
255
- var endEvent = { type: 'end' };
256
-
257
- var STATE = { NONE: - 1, ROTATE: 0, DOLLY: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_DOLLY_PAN: 4 };
258
-
259
- var state = STATE.NONE;
260
-
261
- var EPS = 0.000001;
262
-
263
- // current position in spherical coordinates
264
- var spherical = new THREE.Spherical();
265
- var sphericalDelta = new THREE.Spherical();
266
-
267
- var scale = 1;
268
- var panOffset = new THREE.Vector3();
269
- var zoomChanged = false;
270
-
271
- var rotateStart = new THREE.Vector2();
272
- var rotateEnd = new THREE.Vector2();
273
- var rotateDelta = new THREE.Vector2();
274
-
275
- var panStart = new THREE.Vector2();
276
- var panEnd = new THREE.Vector2();
277
- var panDelta = new THREE.Vector2();
278
-
279
- var dollyStart = new THREE.Vector2();
280
- var dollyEnd = new THREE.Vector2();
281
- var dollyDelta = new THREE.Vector2();
282
-
283
- function getAutoRotationAngle() {
284
-
285
- return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
286
-
287
- }
288
-
289
- function getZoomScale() {
290
-
291
- return Math.pow( 0.95, scope.zoomSpeed );
292
-
293
- }
294
-
295
- function rotateLeft( angle ) {
296
-
297
- sphericalDelta.theta -= angle;
298
-
299
- }
300
-
301
- function rotateUp( angle ) {
302
-
303
- sphericalDelta.phi -= angle;
304
-
305
- }
306
-
307
- var panLeft = function () {
308
-
309
- var v = new THREE.Vector3();
310
-
311
- return function panLeft( distance, objectMatrix ) {
312
-
313
- v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
314
- v.multiplyScalar( - distance );
315
-
316
- panOffset.add( v );
317
-
318
- };
319
-
320
- }();
321
-
322
- var panUp = function () {
323
-
324
- var v = new THREE.Vector3();
325
-
326
- return function panUp( distance, objectMatrix ) {
327
-
328
- if ( scope.screenSpacePanning === true ) {
329
-
330
- v.setFromMatrixColumn( objectMatrix, 1 );
331
-
332
- } else {
333
-
334
- v.setFromMatrixColumn( objectMatrix, 0 );
335
- v.crossVectors( scope.object.up, v );
336
-
337
- }
338
-
339
- v.multiplyScalar( distance );
340
-
341
- panOffset.add( v );
342
-
343
- };
344
-
345
- }();
346
-
347
- // deltaX and deltaY are in pixels; right and down are positive
348
- var pan = function () {
349
-
350
- var offset = new THREE.Vector3();
351
-
352
- return function pan( deltaX, deltaY ) {
353
-
354
- var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
355
-
356
- if ( scope.object.isPerspectiveCamera ) {
357
-
358
- // perspective
359
- var position = scope.object.position;
360
- offset.copy( position ).sub( scope.target );
361
- var targetDistance = offset.length();
362
-
363
- // half of the fov is center to top of screen
364
- targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
365
-
366
- // we use only clientHeight here so aspect ratio does not distort speed
367
- panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
368
- panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
369
-
370
- } else if ( scope.object.isOrthographicCamera ) {
371
-
372
- // orthographic
373
- panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
374
- panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
375
-
376
- } else {
377
-
378
- // camera neither orthographic nor perspective
379
- console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
380
- scope.enablePan = false;
381
-
382
- }
383
-
384
- };
385
-
386
- }();
387
-
388
- function dollyIn( dollyScale ) {
389
-
390
- if ( scope.object.isPerspectiveCamera ) {
391
-
392
- scale /= dollyScale;
393
-
394
- } else if ( scope.object.isOrthographicCamera ) {
395
-
396
- scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) );
397
- scope.object.updateProjectionMatrix();
398
- zoomChanged = true;
399
-
400
- } else {
401
-
402
- console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
403
- scope.enableZoom = false;
404
-
405
- }
406
-
407
- }
408
-
409
- function dollyOut( dollyScale ) {
410
-
411
- if ( scope.object.isPerspectiveCamera ) {
412
-
413
- scale *= dollyScale;
414
-
415
- } else if ( scope.object.isOrthographicCamera ) {
416
-
417
- scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) );
418
- scope.object.updateProjectionMatrix();
419
- zoomChanged = true;
420
-
421
- } else {
422
-
423
- console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
424
- scope.enableZoom = false;
425
-
426
- }
427
-
428
- }
429
-
430
- //
431
- // event callbacks - update the object state
432
- //
433
-
434
- function handleMouseDownRotate( event ) {
435
-
436
- //console.log( 'handleMouseDownRotate' );
437
-
438
- rotateStart.set( event.clientX, event.clientY );
439
-
440
- }
441
-
442
- function handleMouseDownDolly( event ) {
443
-
444
- //console.log( 'handleMouseDownDolly' );
445
-
446
- dollyStart.set( event.clientX, event.clientY );
447
-
448
- }
449
-
450
- function handleMouseDownPan( event ) {
451
-
452
- //console.log( 'handleMouseDownPan' );
453
-
454
- panStart.set( event.clientX, event.clientY );
455
-
456
- }
457
-
458
- function handleMouseMoveRotate( event ) {
459
-
460
- //console.log( 'handleMouseMoveRotate' );
461
-
462
- rotateEnd.set( event.clientX, event.clientY );
463
-
464
- rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
465
-
466
- var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
467
-
468
- // rotating across whole screen goes 360 degrees around
469
- rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth );
470
-
471
- // rotating up and down along whole screen attempts to go 360, but limited to 180
472
- rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
473
-
474
- rotateStart.copy( rotateEnd );
475
-
476
- scope.update();
477
-
478
- }
479
-
480
- function handleMouseMoveDolly( event ) {
481
-
482
- //console.log( 'handleMouseMoveDolly' );
483
-
484
- dollyEnd.set( event.clientX, event.clientY );
485
-
486
- dollyDelta.subVectors( dollyEnd, dollyStart );
487
-
488
- if ( dollyDelta.y > 0 ) {
489
-
490
- dollyIn( getZoomScale() );
491
-
492
- } else if ( dollyDelta.y < 0 ) {
493
-
494
- dollyOut( getZoomScale() );
495
-
496
- }
497
-
498
- dollyStart.copy( dollyEnd );
499
-
500
- scope.update();
501
-
502
- }
503
-
504
- function handleMouseMovePan( event ) {
505
-
506
- //console.log( 'handleMouseMovePan' );
507
-
508
- panEnd.set( event.clientX, event.clientY );
509
-
510
- panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
511
-
512
- pan( panDelta.x, panDelta.y );
513
-
514
- panStart.copy( panEnd );
515
-
516
- scope.update();
517
-
518
- }
519
-
520
- function handleMouseUp( event ) {
521
-
522
- // console.log( 'handleMouseUp' );
523
-
524
- }
525
-
526
- function handleMouseWheel( event ) {
527
-
528
- // console.log( 'handleMouseWheel' );
529
-
530
- if ( event.deltaY < 0 ) {
531
-
532
- dollyOut( getZoomScale() );
533
-
534
- } else if ( event.deltaY > 0 ) {
535
-
536
- dollyIn( getZoomScale() );
537
-
538
- }
539
-
540
- scope.update();
541
-
542
- }
543
-
544
- function handleKeyDown( event ) {
545
-
546
- //console.log( 'handleKeyDown' );
547
-
548
- switch ( event.keyCode ) {
549
-
550
- case scope.keys.UP:
551
- pan( 0, scope.keyPanSpeed );
552
- scope.update();
553
- break;
554
-
555
- case scope.keys.BOTTOM:
556
- pan( 0, - scope.keyPanSpeed );
557
- scope.update();
558
- break;
559
-
560
- case scope.keys.LEFT:
561
- pan( scope.keyPanSpeed, 0 );
562
- scope.update();
563
- break;
564
-
565
- case scope.keys.RIGHT:
566
- pan( - scope.keyPanSpeed, 0 );
567
- scope.update();
568
- break;
569
-
570
- }
571
-
572
- }
573
-
574
- function handleTouchStartRotate( event ) {
575
-
576
- //console.log( 'handleTouchStartRotate' );
577
-
578
- rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
579
-
580
- }
581
-
582
- function handleTouchStartDollyPan( event ) {
583
-
584
- //console.log( 'handleTouchStartDollyPan' );
585
-
586
- if ( scope.enableZoom ) {
587
-
588
- var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
589
- var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
590
-
591
- var distance = Math.sqrt( dx * dx + dy * dy );
592
-
593
- dollyStart.set( 0, distance );
594
-
595
- }
596
-
597
- if ( scope.enablePan ) {
598
-
599
- var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
600
- var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
601
-
602
- panStart.set( x, y );
603
-
604
- }
605
-
606
- }
607
-
608
- function handleTouchMoveRotate( event ) {
609
-
610
- //console.log( 'handleTouchMoveRotate' );
611
-
612
- rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
613
-
614
- rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
615
-
616
- var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
617
-
618
- // rotating across whole screen goes 360 degrees around
619
- rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth );
620
-
621
- // rotating up and down along whole screen attempts to go 360, but limited to 180
622
- rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
623
-
624
- rotateStart.copy( rotateEnd );
625
-
626
- scope.update();
627
-
628
- }
629
-
630
- function handleTouchMoveDollyPan( event ) {
631
-
632
- //console.log( 'handleTouchMoveDollyPan' );
633
-
634
- if ( scope.enableZoom ) {
635
-
636
- var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
637
- var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
638
-
639
- var distance = Math.sqrt( dx * dx + dy * dy );
640
-
641
- dollyEnd.set( 0, distance );
642
-
643
- dollyDelta.set( 0, Math.pow( dollyEnd.y / dollyStart.y, scope.zoomSpeed ) );
644
-
645
- dollyIn( dollyDelta.y );
646
-
647
- dollyStart.copy( dollyEnd );
648
-
649
- }
650
-
651
- if ( scope.enablePan ) {
652
-
653
- var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
654
- var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
655
-
656
- panEnd.set( x, y );
657
-
658
- panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
659
-
660
- pan( panDelta.x, panDelta.y );
661
-
662
- panStart.copy( panEnd );
663
-
664
- }
665
-
666
- scope.update();
667
-
668
- }
669
-
670
- function handleTouchEnd( event ) {
671
-
672
- //console.log( 'handleTouchEnd' );
673
-
674
- }
675
-
676
- //
677
- // event handlers - FSM: listen for events and reset state
678
- //
679
-
680
- function onMouseDown( event ) {
681
-
682
- if ( scope.enabled === false ) return;
683
-
684
- event.preventDefault();
685
-
686
- switch ( event.button ) {
687
-
688
- case scope.mouseButtons.ORBIT:
689
-
690
- if ( scope.enableRotate === false ) return;
691
-
692
- handleMouseDownRotate( event );
693
-
694
- state = STATE.ROTATE;
695
-
696
- break;
697
-
698
- case scope.mouseButtons.ZOOM:
699
-
700
- if ( scope.enableZoom === false ) return;
701
-
702
- handleMouseDownDolly( event );
703
-
704
- state = STATE.DOLLY;
705
-
706
- break;
707
-
708
- case scope.mouseButtons.PAN:
709
-
710
- if ( scope.enablePan === false ) return;
711
-
712
- handleMouseDownPan( event );
713
-
714
- state = STATE.PAN;
715
-
716
- break;
717
-
718
- }
719
-
720
- if ( state !== STATE.NONE ) {
721
-
722
- document.addEventListener( 'mousemove', onMouseMove, false );
723
- document.addEventListener( 'mouseup', onMouseUp, false );
724
-
725
- scope.dispatchEvent( startEvent );
726
-
727
- }
728
-
729
- }
730
-
731
- function onMouseMove( event ) {
732
- if ( scope.enabled === false ) return;
733
- scope.controlChange = true;
734
-
735
- event.preventDefault();
736
-
737
- switch ( state ) {
738
-
739
- case STATE.ROTATE:
740
-
741
- if ( scope.enableRotate === false ) return;
742
-
743
- handleMouseMoveRotate( event );
744
-
745
- break;
746
-
747
- case STATE.DOLLY:
748
-
749
- if ( scope.enableZoom === false ) return;
750
-
751
- handleMouseMoveDolly( event );
752
-
753
- break;
754
-
755
- case STATE.PAN:
756
-
757
- if ( scope.enablePan === false ) return;
758
-
759
- handleMouseMovePan( event );
760
-
761
- break;
762
-
763
- }
764
-
765
- }
766
-
767
- function onMouseUp( event ) {
768
-
769
- // this.controlChange = false;
770
-
771
- if ( scope.enabled === false ) return;
772
-
773
- handleMouseUp( event );
774
-
775
- document.removeEventListener( 'mousemove', onMouseMove, false );
776
- document.removeEventListener( 'mouseup', onMouseUp, false );
777
-
778
- scope.dispatchEvent( endEvent );
779
-
780
- state = STATE.NONE;
781
-
782
- }
783
-
784
- function onMouseWheel( event ) {
785
-
786
- if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return;
787
-
788
- event.preventDefault();
789
- event.stopPropagation();
790
-
791
- scope.dispatchEvent( startEvent );
792
-
793
- handleMouseWheel( event );
794
-
795
- scope.dispatchEvent( endEvent );
796
-
797
- }
798
-
799
- function onKeyDown( event ) {
800
-
801
- if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return;
802
-
803
- handleKeyDown( event );
804
-
805
- }
806
-
807
- function onTouchStart( event ) {
808
-
809
- if ( scope.enabled === false ) return;
810
-
811
- event.preventDefault();
812
-
813
- switch ( event.touches.length ) {
814
-
815
- case 1: // one-fingered touch: rotate
816
-
817
- if ( scope.enableRotate === false ) return;
818
-
819
- handleTouchStartRotate( event );
820
-
821
- state = STATE.TOUCH_ROTATE;
822
-
823
- break;
824
-
825
- case 2: // two-fingered touch: dolly-pan
826
-
827
- if ( scope.enableZoom === false && scope.enablePan === false ) return;
828
-
829
- handleTouchStartDollyPan( event );
830
-
831
- state = STATE.TOUCH_DOLLY_PAN;
832
-
833
- break;
834
-
835
- default:
836
-
837
- state = STATE.NONE;
838
-
839
- }
840
-
841
- if ( state !== STATE.NONE ) {
842
-
843
- scope.dispatchEvent( startEvent );
844
-
845
- }
846
-
847
- }
848
-
849
- function onTouchMove( event ) {
850
-
851
- if ( scope.enabled === false ) return;
852
-
853
- event.preventDefault();
854
- event.stopPropagation();
855
-
856
- switch ( event.touches.length ) {
857
-
858
- case 1: // one-fingered touch: rotate
859
-
860
- if ( scope.enableRotate === false ) return;
861
- if ( state !== STATE.TOUCH_ROTATE ) return; // is this needed?
862
-
863
- handleTouchMoveRotate( event );
864
-
865
- break;
866
-
867
- case 2: // two-fingered touch: dolly-pan
868
-
869
- if ( scope.enableZoom === false && scope.enablePan === false ) return;
870
- if ( state !== STATE.TOUCH_DOLLY_PAN ) return; // is this needed?
871
-
872
- handleTouchMoveDollyPan( event );
873
-
874
- break;
875
-
876
- default:
877
-
878
- state = STATE.NONE;
879
-
880
- }
881
-
882
- }
883
-
884
- function onTouchEnd( event ) {
885
-
886
- if ( scope.enabled === false ) return;
887
-
888
- handleTouchEnd( event );
889
-
890
- scope.dispatchEvent( endEvent );
891
-
892
- state = STATE.NONE;
893
-
894
- }
895
-
896
- function onContextMenu( event ) {
897
-
898
- if ( scope.enabled === false ) return;
899
-
900
- event.preventDefault();
901
-
902
- }
903
-
904
- //
905
-
906
- scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );
907
-
908
- scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
909
- scope.domElement.addEventListener( 'wheel', onMouseWheel, false );
910
-
911
- scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
912
- scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
913
- scope.domElement.addEventListener( 'touchmove', onTouchMove, false );
914
-
915
- window.addEventListener( 'keydown', onKeyDown, false );
916
-
917
- // force an update at start
918
-
919
- this.update();
920
-
921
- };
922
-
923
- THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
924
- THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
925
-
926
- Object.defineProperties( THREE.OrbitControls.prototype, {
927
-
928
- center: {
929
-
930
- get: function () {
931
-
932
- console.warn( 'THREE.OrbitControls: .center has been renamed to .target' );
933
- return this.target;
934
-
935
- }
936
-
937
- },
938
-
939
- // backward compatibility
940
-
941
- noZoom: {
942
-
943
- get: function () {
944
-
945
- console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
946
- return ! this.enableZoom;
947
-
948
- },
949
-
950
- set: function ( value ) {
951
-
952
- console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
953
- this.enableZoom = ! value;
954
-
955
- }
956
-
957
- },
958
-
959
- noRotate: {
960
-
961
- get: function () {
962
-
963
- console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
964
- return ! this.enableRotate;
965
-
966
- },
967
-
968
- set: function ( value ) {
969
-
970
- console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
971
- this.enableRotate = ! value;
972
-
973
- }
974
-
975
- },
976
-
977
- noPan: {
978
-
979
- get: function () {
980
-
981
- console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
982
- return ! this.enablePan;
983
-
984
- },
985
-
986
- set: function ( value ) {
987
-
988
- console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
989
- this.enablePan = ! value;
990
-
991
- }
992
-
993
- },
994
-
995
- noKeys: {
996
-
997
- get: function () {
998
-
999
- console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1000
- return ! this.enableKeys;
1001
-
1002
- },
1003
-
1004
- set: function ( value ) {
1005
-
1006
- console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1007
- this.enableKeys = ! value;
1008
-
1009
- }
1010
-
1011
- },
1012
-
1013
- staticMoving: {
1014
-
1015
- get: function () {
1016
-
1017
- console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1018
- return ! this.enableDamping;
1019
-
1020
- },
1021
-
1022
- set: function ( value ) {
1023
-
1024
- console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1025
- this.enableDamping = ! value;
1026
-
1027
- }
1028
-
1029
- },
1030
-
1031
- dynamicDampingFactor: {
1032
-
1033
- get: function () {
1034
-
1035
- console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1036
- return this.dampingFactor;
1037
-
1038
- },
1039
-
1040
- set: function ( value ) {
1041
-
1042
- console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1043
- this.dampingFactor = value;
1044
-
1045
- }
1046
-
1047
- }
1048
-
1049
- } );
1050
-
1051
- module.exports = exports.default = THREE.OrbitControls
1
+ var THREE = require('three')
2
+
3
+ /**
4
+ * @author qiao / https://github.com/qiao
5
+ * @author mrdoob / http://mrdoob.com
6
+ * @author alteredq / http://alteredqualia.com/
7
+ * @author WestLangley / http://github.com/WestLangley
8
+ * @author erich666 / http://erichaines.com
9
+ */
10
+
11
+ // This set of controls performs orbiting, dollying (zooming), and panning.
12
+ // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
13
+ //
14
+ // Orbit - left mouse / touch: one-finger move
15
+ // Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
16
+ // Pan - right mouse, or arrow keys / touch: two-finger move
17
+
18
+ THREE.OrbitControls = function ( object, domElement ) {
19
+
20
+ this.object = object;
21
+
22
+ this.domElement = ( domElement !== undefined ) ? domElement : document;
23
+
24
+ // Set to false to disable this control
25
+ this.enabled = true;
26
+
27
+ // "target" sets the location of focus, where the object orbits around
28
+ this.target = new THREE.Vector3();
29
+
30
+ // How far you can dolly in and out ( PerspectiveCamera only )
31
+ this.minDistance = 0;
32
+ this.maxDistance = Infinity;
33
+
34
+ // How far you can zoom in and out ( OrthographicCamera only )
35
+ this.minZoom = 0;
36
+ this.maxZoom = Infinity;
37
+
38
+ // How far you can orbit vertically, upper and lower limits.
39
+ // Range is 0 to Math.PI radians.
40
+ this.minPolarAngle = 0; // radians
41
+ this.maxPolarAngle = Math.PI; // radians
42
+
43
+ // How far you can orbit horizontally, upper and lower limits.
44
+ // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
45
+ this.minAzimuthAngle = - Infinity; // radians
46
+ this.maxAzimuthAngle = Infinity; // radians
47
+
48
+ // Set to true to enable damping (inertia)
49
+ // If damping is enabled, you must call controls.update() in your animation loop
50
+ this.enableDamping = false;
51
+ this.dampingFactor = 0.25;
52
+
53
+ // This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
54
+ // Set to false to disable zooming
55
+ this.enableZoom = true;
56
+ this.zoomSpeed = 1.0;
57
+
58
+ // Set to false to disable rotating
59
+ this.enableRotate = true;
60
+ this.rotateSpeed = 1.0;
61
+
62
+ // Set to false to disable panning
63
+ this.enablePan = true;
64
+ this.panSpeed = 1.0;
65
+ this.screenSpacePanning = false; // if true, pan in screen-space
66
+ this.keyPanSpeed = 7.0; // pixels moved per arrow key push
67
+
68
+ // Set to true to automatically rotate around the target
69
+ // If auto-rotate is enabled, you must call controls.update() in your animation loop
70
+ this.autoRotate = false;
71
+ this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
72
+
73
+ // Set to false to disable use of the keys
74
+ this.enableKeys = true;
75
+
76
+ // The four arrow keys
77
+ this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
78
+
79
+ // Mouse buttons
80
+ this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
81
+
82
+ // for reset
83
+ this.target0 = this.target.clone();
84
+ this.position0 = this.object.position.clone();
85
+ this.zoom0 = this.object.zoom;
86
+
87
+ this.controlChange = false;
88
+
89
+ //
90
+ // public methods
91
+ //
92
+
93
+ this.getPolarAngle = function () {
94
+
95
+ return spherical.phi;
96
+
97
+ };
98
+
99
+ this.getAzimuthalAngle = function () {
100
+
101
+ return spherical.theta;
102
+
103
+ };
104
+
105
+ this.saveState = function () {
106
+
107
+ scope.target0.copy( scope.target );
108
+ scope.position0.copy( scope.object.position );
109
+ scope.zoom0 = scope.object.zoom;
110
+
111
+ };
112
+
113
+ this.reset = function () {
114
+
115
+ scope.target.copy( scope.target0 );
116
+ scope.object.position.copy( scope.position0 );
117
+ scope.object.zoom = scope.zoom0;
118
+
119
+ scope.object.updateProjectionMatrix();
120
+ scope.dispatchEvent( changeEvent );
121
+
122
+ scope.update();
123
+
124
+ state = STATE.NONE;
125
+
126
+ };
127
+
128
+ // this method is exposed, but perhaps it would be better if we can make it private...
129
+ this.update = function () {
130
+
131
+ var offset = new THREE.Vector3();
132
+
133
+ // so camera.up is the orbit axis
134
+ var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
135
+ var quatInverse = quat.clone().inverse();
136
+
137
+ var lastPosition = new THREE.Vector3();
138
+ var lastQuaternion = new THREE.Quaternion();
139
+
140
+ return function update() {
141
+
142
+ var position = scope.object.position;
143
+
144
+ offset.copy( position ).sub( scope.target );
145
+
146
+ // rotate offset to "y-axis-is-up" space
147
+ offset.applyQuaternion( quat );
148
+
149
+ // angle from z-axis around y-axis
150
+ spherical.setFromVector3( offset );
151
+
152
+ if ( scope.autoRotate && state === STATE.NONE ) {
153
+
154
+ rotateLeft( getAutoRotationAngle() );
155
+
156
+ }
157
+
158
+ spherical.theta += sphericalDelta.theta;
159
+ spherical.phi += sphericalDelta.phi;
160
+
161
+ // restrict theta to be between desired limits
162
+ spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) );
163
+
164
+ // restrict phi to be between desired limits
165
+ spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
166
+
167
+ spherical.makeSafe();
168
+
169
+
170
+ spherical.radius *= scale;
171
+
172
+ // restrict radius to be between desired limits
173
+ spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
174
+
175
+ // move target to panned location
176
+ scope.target.add( panOffset );
177
+
178
+ offset.setFromSpherical( spherical );
179
+
180
+ // rotate offset back to "camera-up-vector-is-up" space
181
+ offset.applyQuaternion( quatInverse );
182
+
183
+ position.copy( scope.target ).add( offset );
184
+
185
+ scope.object.lookAt( scope.target );
186
+
187
+ if ( scope.enableDamping === true ) {
188
+
189
+ sphericalDelta.theta *= ( 1 - scope.dampingFactor );
190
+ sphericalDelta.phi *= ( 1 - scope.dampingFactor );
191
+
192
+ panOffset.multiplyScalar( 1 - scope.dampingFactor );
193
+
194
+ } else {
195
+
196
+ sphericalDelta.set( 0, 0, 0 );
197
+
198
+ panOffset.set( 0, 0, 0 );
199
+
200
+ }
201
+
202
+ scale = 1;
203
+
204
+ // update condition is:
205
+ // min(camera displacement, camera rotation in radians)^2 > EPS
206
+ // using small-angle approximation cos(x/2) = 1 - x^2 / 8
207
+
208
+ if ( zoomChanged ||
209
+ lastPosition.distanceToSquared( scope.object.position ) > EPS ||
210
+ 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
211
+
212
+ scope.dispatchEvent( changeEvent );
213
+
214
+ lastPosition.copy( scope.object.position );
215
+ lastQuaternion.copy( scope.object.quaternion );
216
+ zoomChanged = false;
217
+
218
+ return true;
219
+
220
+ }
221
+
222
+ return false;
223
+
224
+ };
225
+
226
+ }();
227
+
228
+ this.dispose = function () {
229
+
230
+ scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false );
231
+ scope.domElement.removeEventListener( 'mousedown', onMouseDown, false );
232
+ scope.domElement.removeEventListener( 'wheel', onMouseWheel, false );
233
+
234
+ scope.domElement.removeEventListener( 'touchstart', onTouchStart, false );
235
+ scope.domElement.removeEventListener( 'touchend', onTouchEnd, false );
236
+ scope.domElement.removeEventListener( 'touchmove', onTouchMove, false );
237
+
238
+ document.removeEventListener( 'mousemove', onMouseMove, false );
239
+ document.removeEventListener( 'mouseup', onMouseUp, false );
240
+
241
+ window.removeEventListener( 'keydown', onKeyDown, false );
242
+
243
+ //scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
244
+
245
+ };
246
+
247
+ //
248
+ // internals
249
+ //
250
+
251
+ var scope = this;
252
+
253
+ var changeEvent = { type: 'change' };
254
+ var startEvent = { type: 'start' };
255
+ var endEvent = { type: 'end' };
256
+
257
+ var STATE = { NONE: - 1, ROTATE: 0, DOLLY: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_DOLLY_PAN: 4 };
258
+
259
+ var state = STATE.NONE;
260
+
261
+ var EPS = 0.000001;
262
+
263
+ // current position in spherical coordinates
264
+ var spherical = new THREE.Spherical();
265
+ var sphericalDelta = new THREE.Spherical();
266
+
267
+ var scale = 1;
268
+ var panOffset = new THREE.Vector3();
269
+ var zoomChanged = false;
270
+
271
+ var rotateStart = new THREE.Vector2();
272
+ var rotateEnd = new THREE.Vector2();
273
+ var rotateDelta = new THREE.Vector2();
274
+
275
+ var panStart = new THREE.Vector2();
276
+ var panEnd = new THREE.Vector2();
277
+ var panDelta = new THREE.Vector2();
278
+
279
+ var dollyStart = new THREE.Vector2();
280
+ var dollyEnd = new THREE.Vector2();
281
+ var dollyDelta = new THREE.Vector2();
282
+
283
+ function getAutoRotationAngle() {
284
+
285
+ return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
286
+
287
+ }
288
+
289
+ function getZoomScale() {
290
+
291
+ return Math.pow( 0.95, scope.zoomSpeed );
292
+
293
+ }
294
+
295
+ function rotateLeft( angle ) {
296
+
297
+ sphericalDelta.theta -= angle;
298
+
299
+ }
300
+
301
+ function rotateUp( angle ) {
302
+
303
+ sphericalDelta.phi -= angle;
304
+
305
+ }
306
+
307
+ var panLeft = function () {
308
+
309
+ var v = new THREE.Vector3();
310
+
311
+ return function panLeft( distance, objectMatrix ) {
312
+
313
+ v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
314
+ v.multiplyScalar( - distance );
315
+
316
+ panOffset.add( v );
317
+
318
+ };
319
+
320
+ }();
321
+
322
+ var panUp = function () {
323
+
324
+ var v = new THREE.Vector3();
325
+
326
+ return function panUp( distance, objectMatrix ) {
327
+
328
+ if ( scope.screenSpacePanning === true ) {
329
+
330
+ v.setFromMatrixColumn( objectMatrix, 1 );
331
+
332
+ } else {
333
+
334
+ v.setFromMatrixColumn( objectMatrix, 0 );
335
+ v.crossVectors( scope.object.up, v );
336
+
337
+ }
338
+
339
+ v.multiplyScalar( distance );
340
+
341
+ panOffset.add( v );
342
+
343
+ };
344
+
345
+ }();
346
+
347
+ // deltaX and deltaY are in pixels; right and down are positive
348
+ var pan = function () {
349
+
350
+ var offset = new THREE.Vector3();
351
+
352
+ return function pan( deltaX, deltaY ) {
353
+
354
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
355
+
356
+ if ( scope.object.isPerspectiveCamera ) {
357
+
358
+ // perspective
359
+ var position = scope.object.position;
360
+ offset.copy( position ).sub( scope.target );
361
+ var targetDistance = offset.length();
362
+
363
+ // half of the fov is center to top of screen
364
+ targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
365
+
366
+ // we use only clientHeight here so aspect ratio does not distort speed
367
+ panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
368
+ panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
369
+
370
+ } else if ( scope.object.isOrthographicCamera ) {
371
+
372
+ // orthographic
373
+ panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
374
+ panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
375
+
376
+ } else {
377
+
378
+ // camera neither orthographic nor perspective
379
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
380
+ scope.enablePan = false;
381
+
382
+ }
383
+
384
+ };
385
+
386
+ }();
387
+
388
+ function dollyIn( dollyScale ) {
389
+
390
+ if ( scope.object.isPerspectiveCamera ) {
391
+
392
+ scale /= dollyScale;
393
+
394
+ } else if ( scope.object.isOrthographicCamera ) {
395
+
396
+ scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) );
397
+ scope.object.updateProjectionMatrix();
398
+ zoomChanged = true;
399
+
400
+ } else {
401
+
402
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
403
+ scope.enableZoom = false;
404
+
405
+ }
406
+
407
+ }
408
+
409
+ function dollyOut( dollyScale ) {
410
+
411
+ if ( scope.object.isPerspectiveCamera ) {
412
+
413
+ scale *= dollyScale;
414
+
415
+ } else if ( scope.object.isOrthographicCamera ) {
416
+
417
+ scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) );
418
+ scope.object.updateProjectionMatrix();
419
+ zoomChanged = true;
420
+
421
+ } else {
422
+
423
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
424
+ scope.enableZoom = false;
425
+
426
+ }
427
+
428
+ }
429
+
430
+ //
431
+ // event callbacks - update the object state
432
+ //
433
+
434
+ function handleMouseDownRotate( event ) {
435
+
436
+ //console.log( 'handleMouseDownRotate' );
437
+
438
+ rotateStart.set( event.clientX, event.clientY );
439
+
440
+ }
441
+
442
+ function handleMouseDownDolly( event ) {
443
+
444
+ //console.log( 'handleMouseDownDolly' );
445
+
446
+ dollyStart.set( event.clientX, event.clientY );
447
+
448
+ }
449
+
450
+ function handleMouseDownPan( event ) {
451
+
452
+ //console.log( 'handleMouseDownPan' );
453
+
454
+ panStart.set( event.clientX, event.clientY );
455
+
456
+ }
457
+
458
+ function handleMouseMoveRotate( event ) {
459
+
460
+ //console.log( 'handleMouseMoveRotate' );
461
+
462
+ rotateEnd.set( event.clientX, event.clientY );
463
+
464
+ rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
465
+
466
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
467
+
468
+ // rotating across whole screen goes 360 degrees around
469
+ rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth );
470
+
471
+ // rotating up and down along whole screen attempts to go 360, but limited to 180
472
+ rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
473
+
474
+ rotateStart.copy( rotateEnd );
475
+
476
+ scope.update();
477
+
478
+ }
479
+
480
+ function handleMouseMoveDolly( event ) {
481
+
482
+ //console.log( 'handleMouseMoveDolly' );
483
+
484
+ dollyEnd.set( event.clientX, event.clientY );
485
+
486
+ dollyDelta.subVectors( dollyEnd, dollyStart );
487
+
488
+ if ( dollyDelta.y > 0 ) {
489
+
490
+ dollyIn( getZoomScale() );
491
+
492
+ } else if ( dollyDelta.y < 0 ) {
493
+
494
+ dollyOut( getZoomScale() );
495
+
496
+ }
497
+
498
+ dollyStart.copy( dollyEnd );
499
+
500
+ scope.update();
501
+
502
+ }
503
+
504
+ function handleMouseMovePan( event ) {
505
+
506
+ //console.log( 'handleMouseMovePan' );
507
+
508
+ panEnd.set( event.clientX, event.clientY );
509
+
510
+ panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
511
+
512
+ pan( panDelta.x, panDelta.y );
513
+
514
+ panStart.copy( panEnd );
515
+
516
+ scope.update();
517
+
518
+ }
519
+
520
+ function handleMouseUp( event ) {
521
+
522
+ // console.log( 'handleMouseUp' );
523
+
524
+ }
525
+
526
+ function handleMouseWheel( event ) {
527
+
528
+ // console.log( 'handleMouseWheel' );
529
+
530
+ if ( event.deltaY < 0 ) {
531
+
532
+ dollyOut( getZoomScale() );
533
+
534
+ } else if ( event.deltaY > 0 ) {
535
+
536
+ dollyIn( getZoomScale() );
537
+
538
+ }
539
+
540
+ scope.update();
541
+
542
+ }
543
+
544
+ function handleKeyDown( event ) {
545
+
546
+ //console.log( 'handleKeyDown' );
547
+
548
+ switch ( event.keyCode ) {
549
+
550
+ case scope.keys.UP:
551
+ pan( 0, scope.keyPanSpeed );
552
+ scope.update();
553
+ break;
554
+
555
+ case scope.keys.BOTTOM:
556
+ pan( 0, - scope.keyPanSpeed );
557
+ scope.update();
558
+ break;
559
+
560
+ case scope.keys.LEFT:
561
+ pan( scope.keyPanSpeed, 0 );
562
+ scope.update();
563
+ break;
564
+
565
+ case scope.keys.RIGHT:
566
+ pan( - scope.keyPanSpeed, 0 );
567
+ scope.update();
568
+ break;
569
+
570
+ }
571
+
572
+ }
573
+
574
+ function handleTouchStartRotate( event ) {
575
+
576
+ //console.log( 'handleTouchStartRotate' );
577
+
578
+ rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
579
+
580
+ }
581
+
582
+ function handleTouchStartDollyPan( event ) {
583
+
584
+ //console.log( 'handleTouchStartDollyPan' );
585
+
586
+ if ( scope.enableZoom ) {
587
+
588
+ var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
589
+ var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
590
+
591
+ var distance = Math.sqrt( dx * dx + dy * dy );
592
+
593
+ dollyStart.set( 0, distance );
594
+
595
+ }
596
+
597
+ if ( scope.enablePan ) {
598
+
599
+ var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
600
+ var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
601
+
602
+ panStart.set( x, y );
603
+
604
+ }
605
+
606
+ }
607
+
608
+ function handleTouchMoveRotate( event ) {
609
+
610
+ //console.log( 'handleTouchMoveRotate' );
611
+
612
+ rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
613
+
614
+ rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
615
+
616
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
617
+
618
+ // rotating across whole screen goes 360 degrees around
619
+ rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth );
620
+
621
+ // rotating up and down along whole screen attempts to go 360, but limited to 180
622
+ rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
623
+
624
+ rotateStart.copy( rotateEnd );
625
+
626
+ scope.update();
627
+
628
+ }
629
+
630
+ function handleTouchMoveDollyPan( event ) {
631
+
632
+ //console.log( 'handleTouchMoveDollyPan' );
633
+
634
+ if ( scope.enableZoom ) {
635
+
636
+ var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
637
+ var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
638
+
639
+ var distance = Math.sqrt( dx * dx + dy * dy );
640
+
641
+ dollyEnd.set( 0, distance );
642
+
643
+ dollyDelta.set( 0, Math.pow( dollyEnd.y / dollyStart.y, scope.zoomSpeed ) );
644
+
645
+ dollyIn( dollyDelta.y );
646
+
647
+ dollyStart.copy( dollyEnd );
648
+
649
+ }
650
+
651
+ if ( scope.enablePan ) {
652
+
653
+ var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
654
+ var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
655
+
656
+ panEnd.set( x, y );
657
+
658
+ panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
659
+
660
+ pan( panDelta.x, panDelta.y );
661
+
662
+ panStart.copy( panEnd );
663
+
664
+ }
665
+
666
+ scope.update();
667
+
668
+ }
669
+
670
+ function handleTouchEnd( event ) {
671
+
672
+ //console.log( 'handleTouchEnd' );
673
+
674
+ }
675
+
676
+ //
677
+ // event handlers - FSM: listen for events and reset state
678
+ //
679
+
680
+ function onMouseDown( event ) {
681
+
682
+ if ( scope.enabled === false ) return;
683
+
684
+ event.preventDefault();
685
+
686
+ switch ( event.button ) {
687
+
688
+ case scope.mouseButtons.ORBIT:
689
+
690
+ if ( scope.enableRotate === false ) return;
691
+
692
+ handleMouseDownRotate( event );
693
+
694
+ state = STATE.ROTATE;
695
+
696
+ break;
697
+
698
+ case scope.mouseButtons.ZOOM:
699
+
700
+ if ( scope.enableZoom === false ) return;
701
+
702
+ handleMouseDownDolly( event );
703
+
704
+ state = STATE.DOLLY;
705
+
706
+ break;
707
+
708
+ case scope.mouseButtons.PAN:
709
+
710
+ if ( scope.enablePan === false ) return;
711
+
712
+ handleMouseDownPan( event );
713
+
714
+ state = STATE.PAN;
715
+
716
+ break;
717
+
718
+ }
719
+
720
+ if ( state !== STATE.NONE ) {
721
+
722
+ document.addEventListener( 'mousemove', onMouseMove, false );
723
+ document.addEventListener( 'mouseup', onMouseUp, false );
724
+
725
+ scope.dispatchEvent( startEvent );
726
+
727
+ }
728
+
729
+ }
730
+
731
+ function onMouseMove( event ) {
732
+ if ( scope.enabled === false ) return;
733
+ scope.controlChange = true;
734
+
735
+ event.preventDefault();
736
+
737
+ switch ( state ) {
738
+
739
+ case STATE.ROTATE:
740
+
741
+ if ( scope.enableRotate === false ) return;
742
+
743
+ handleMouseMoveRotate( event );
744
+
745
+ break;
746
+
747
+ case STATE.DOLLY:
748
+
749
+ if ( scope.enableZoom === false ) return;
750
+
751
+ handleMouseMoveDolly( event );
752
+
753
+ break;
754
+
755
+ case STATE.PAN:
756
+
757
+ if ( scope.enablePan === false ) return;
758
+
759
+ handleMouseMovePan( event );
760
+
761
+ break;
762
+
763
+ }
764
+
765
+ }
766
+
767
+ function onMouseUp( event ) {
768
+
769
+ // this.controlChange = false;
770
+
771
+ if ( scope.enabled === false ) return;
772
+
773
+ handleMouseUp( event );
774
+
775
+ document.removeEventListener( 'mousemove', onMouseMove, false );
776
+ document.removeEventListener( 'mouseup', onMouseUp, false );
777
+
778
+ scope.dispatchEvent( endEvent );
779
+
780
+ state = STATE.NONE;
781
+
782
+ }
783
+
784
+ function onMouseWheel( event ) {
785
+
786
+ if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return;
787
+
788
+ event.preventDefault();
789
+ event.stopPropagation();
790
+
791
+ scope.dispatchEvent( startEvent );
792
+
793
+ handleMouseWheel( event );
794
+
795
+ scope.dispatchEvent( endEvent );
796
+
797
+ }
798
+
799
+ function onKeyDown( event ) {
800
+
801
+ if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return;
802
+
803
+ handleKeyDown( event );
804
+
805
+ }
806
+
807
+ function onTouchStart( event ) {
808
+
809
+ if ( scope.enabled === false ) return;
810
+
811
+ event.preventDefault();
812
+
813
+ switch ( event.touches.length ) {
814
+
815
+ case 1: // one-fingered touch: rotate
816
+
817
+ if ( scope.enableRotate === false ) return;
818
+
819
+ handleTouchStartRotate( event );
820
+
821
+ state = STATE.TOUCH_ROTATE;
822
+
823
+ break;
824
+
825
+ case 2: // two-fingered touch: dolly-pan
826
+
827
+ if ( scope.enableZoom === false && scope.enablePan === false ) return;
828
+
829
+ handleTouchStartDollyPan( event );
830
+
831
+ state = STATE.TOUCH_DOLLY_PAN;
832
+
833
+ break;
834
+
835
+ default:
836
+
837
+ state = STATE.NONE;
838
+
839
+ }
840
+
841
+ if ( state !== STATE.NONE ) {
842
+
843
+ scope.dispatchEvent( startEvent );
844
+
845
+ }
846
+
847
+ }
848
+
849
+ function onTouchMove( event ) {
850
+
851
+ if ( scope.enabled === false ) return;
852
+
853
+ event.preventDefault();
854
+ event.stopPropagation();
855
+
856
+ switch ( event.touches.length ) {
857
+
858
+ case 1: // one-fingered touch: rotate
859
+
860
+ if ( scope.enableRotate === false ) return;
861
+ if ( state !== STATE.TOUCH_ROTATE ) return; // is this needed?
862
+
863
+ handleTouchMoveRotate( event );
864
+
865
+ break;
866
+
867
+ case 2: // two-fingered touch: dolly-pan
868
+
869
+ if ( scope.enableZoom === false && scope.enablePan === false ) return;
870
+ if ( state !== STATE.TOUCH_DOLLY_PAN ) return; // is this needed?
871
+
872
+ handleTouchMoveDollyPan( event );
873
+
874
+ break;
875
+
876
+ default:
877
+
878
+ state = STATE.NONE;
879
+
880
+ }
881
+
882
+ }
883
+
884
+ function onTouchEnd( event ) {
885
+
886
+ if ( scope.enabled === false ) return;
887
+
888
+ handleTouchEnd( event );
889
+
890
+ scope.dispatchEvent( endEvent );
891
+
892
+ state = STATE.NONE;
893
+
894
+ }
895
+
896
+ function onContextMenu( event ) {
897
+
898
+ if ( scope.enabled === false ) return;
899
+
900
+ event.preventDefault();
901
+
902
+ }
903
+
904
+ //
905
+
906
+ scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );
907
+
908
+ scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
909
+ scope.domElement.addEventListener( 'wheel', onMouseWheel, false );
910
+
911
+ scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
912
+ scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
913
+ scope.domElement.addEventListener( 'touchmove', onTouchMove, false );
914
+
915
+ window.addEventListener( 'keydown', onKeyDown, false );
916
+
917
+ // force an update at start
918
+
919
+ this.update();
920
+
921
+ };
922
+
923
+ THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
924
+ THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
925
+
926
+ Object.defineProperties( THREE.OrbitControls.prototype, {
927
+
928
+ center: {
929
+
930
+ get: function () {
931
+
932
+ console.warn( 'THREE.OrbitControls: .center has been renamed to .target' );
933
+ return this.target;
934
+
935
+ }
936
+
937
+ },
938
+
939
+ // backward compatibility
940
+
941
+ noZoom: {
942
+
943
+ get: function () {
944
+
945
+ console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
946
+ return ! this.enableZoom;
947
+
948
+ },
949
+
950
+ set: function ( value ) {
951
+
952
+ console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
953
+ this.enableZoom = ! value;
954
+
955
+ }
956
+
957
+ },
958
+
959
+ noRotate: {
960
+
961
+ get: function () {
962
+
963
+ console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
964
+ return ! this.enableRotate;
965
+
966
+ },
967
+
968
+ set: function ( value ) {
969
+
970
+ console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
971
+ this.enableRotate = ! value;
972
+
973
+ }
974
+
975
+ },
976
+
977
+ noPan: {
978
+
979
+ get: function () {
980
+
981
+ console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
982
+ return ! this.enablePan;
983
+
984
+ },
985
+
986
+ set: function ( value ) {
987
+
988
+ console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
989
+ this.enablePan = ! value;
990
+
991
+ }
992
+
993
+ },
994
+
995
+ noKeys: {
996
+
997
+ get: function () {
998
+
999
+ console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1000
+ return ! this.enableKeys;
1001
+
1002
+ },
1003
+
1004
+ set: function ( value ) {
1005
+
1006
+ console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1007
+ this.enableKeys = ! value;
1008
+
1009
+ }
1010
+
1011
+ },
1012
+
1013
+ staticMoving: {
1014
+
1015
+ get: function () {
1016
+
1017
+ console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1018
+ return ! this.enableDamping;
1019
+
1020
+ },
1021
+
1022
+ set: function ( value ) {
1023
+
1024
+ console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1025
+ this.enableDamping = ! value;
1026
+
1027
+ }
1028
+
1029
+ },
1030
+
1031
+ dynamicDampingFactor: {
1032
+
1033
+ get: function () {
1034
+
1035
+ console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1036
+ return this.dampingFactor;
1037
+
1038
+ },
1039
+
1040
+ set: function ( value ) {
1041
+
1042
+ console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1043
+ this.dampingFactor = value;
1044
+
1045
+ }
1046
+
1047
+ }
1048
+
1049
+ } );
1050
+
1051
+ module.exports = exports.default = THREE.OrbitControls