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