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