├── img
├── H.png
├── R.png
├── T.png
├── U.png
├── white.png
├── planets
│ ├── earthmap.jpg
│ ├── jupitermap.jpg
│ ├── marsmap1k.jpg
│ ├── mercurymap.jpg
│ ├── neptunemap.jpg
│ ├── saturnmap.jpg
│ ├── uranusmap.jpg
│ ├── venusmap.jpg
│ ├── saturnringcolor.jpg
│ └── uranusringcolour.jpg
└── dispair ridge
│ ├── dispair-ridge_up.png
│ ├── dispair-ridge_back.png
│ ├── dispair-ridge_down.png
│ ├── dispair-ridge_front.png
│ ├── dispair-ridge_left.png
│ └── dispair-ridge_right.png
├── README.md
├── index.html
└── js
└── OrbitControls.js
/img/H.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/H.png
--------------------------------------------------------------------------------
/img/R.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/R.png
--------------------------------------------------------------------------------
/img/T.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/T.png
--------------------------------------------------------------------------------
/img/U.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/U.png
--------------------------------------------------------------------------------
/img/white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/white.png
--------------------------------------------------------------------------------
/img/planets/earthmap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/earthmap.jpg
--------------------------------------------------------------------------------
/img/planets/jupitermap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/jupitermap.jpg
--------------------------------------------------------------------------------
/img/planets/marsmap1k.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/marsmap1k.jpg
--------------------------------------------------------------------------------
/img/planets/mercurymap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/mercurymap.jpg
--------------------------------------------------------------------------------
/img/planets/neptunemap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/neptunemap.jpg
--------------------------------------------------------------------------------
/img/planets/saturnmap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/saturnmap.jpg
--------------------------------------------------------------------------------
/img/planets/uranusmap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/uranusmap.jpg
--------------------------------------------------------------------------------
/img/planets/venusmap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/venusmap.jpg
--------------------------------------------------------------------------------
/img/planets/saturnringcolor.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/saturnringcolor.jpg
--------------------------------------------------------------------------------
/img/planets/uranusringcolour.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/planets/uranusringcolour.jpg
--------------------------------------------------------------------------------
/img/dispair ridge/dispair-ridge_up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/dispair ridge/dispair-ridge_up.png
--------------------------------------------------------------------------------
/img/dispair ridge/dispair-ridge_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/dispair ridge/dispair-ridge_back.png
--------------------------------------------------------------------------------
/img/dispair ridge/dispair-ridge_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/dispair ridge/dispair-ridge_down.png
--------------------------------------------------------------------------------
/img/dispair ridge/dispair-ridge_front.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/dispair ridge/dispair-ridge_front.png
--------------------------------------------------------------------------------
/img/dispair ridge/dispair-ridge_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/dispair ridge/dispair-ridge_left.png
--------------------------------------------------------------------------------
/img/dispair ridge/dispair-ridge_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gazijarin/Truth/HEAD/img/dispair ridge/dispair-ridge_right.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Truth
2 |
3 | A remake of the solar system created using Three.js.
4 |
5 | In this simple simulation, the solar system was re-designed using Three.js as an interface to WEBGL. The user is able to interact with the focal object, the monolith, and its surroundings by controlling the cursor. Each of the planets, albeit not to scale or to actual orbital radius, are more or less represented accurately in relative to each other - each having their own texture maps, rings (if necessary) and their unique rotation. The monolith, instead of the Sun, was used as the central object to symbolize the brink of human knowledge and evolution (an inspiration drawn from the film 2001: A Space Odyssey). They are all positioned in a skybox, called the Dispair Ridge, to provide an illusion of space.
6 |
7 | Check out the complete [three.js](https://threejs.org/) documentation for more information.
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The Truth
5 |
6 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
227 |
228 |
229 |
230 |
231 |
--------------------------------------------------------------------------------
/js/OrbitControls.js:
--------------------------------------------------------------------------------
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 left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
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.panSpeed = 1.0;
63 | this.screenSpacePanning = false; // if true, pan in screen-space
64 | this.keyPanSpeed = 7.0; // pixels moved per arrow key push
65 |
66 | // Set to true to automatically rotate around the target
67 | // If auto-rotate is enabled, you must call controls.update() in your animation loop
68 | this.autoRotate = false;
69 | this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
70 |
71 | // Set to false to disable use of the keys
72 | this.enableKeys = true;
73 |
74 | // The four arrow keys
75 | this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
76 |
77 | // Mouse buttons
78 | this.mouseButtons = { LEFT: THREE.MOUSE.LEFT, MIDDLE: THREE.MOUSE.MIDDLE, RIGHT: THREE.MOUSE.RIGHT };
79 |
80 | // for reset
81 | this.target0 = this.target.clone();
82 | this.position0 = this.object.position.clone();
83 | this.zoom0 = this.object.zoom;
84 |
85 | //
86 | // public methods
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 | // this method is exposed, but perhaps it would be better if we can make it private...
125 | this.update = function () {
126 |
127 | var offset = new THREE.Vector3();
128 |
129 | // so camera.up is the orbit axis
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 | // rotate offset to "y-axis-is-up" space
143 | offset.applyQuaternion( quat );
144 |
145 | // angle from z-axis around y-axis
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 | // restrict theta to be between desired limits
158 | spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) );
159 |
160 | // restrict phi to be between desired limits
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 | // restrict radius to be between desired limits
169 | spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
170 |
171 | // move target to panned location
172 | scope.target.add( panOffset );
173 |
174 | offset.setFromSpherical( spherical );
175 |
176 | // rotate offset back to "camera-up-vector-is-up" space
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 | // update condition is:
201 | // min(camera displacement, camera rotation in radians)^2 > EPS
202 | // using small-angle approximation cos(x/2) = 1 - x^2 / 8
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 | //scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
240 |
241 | };
242 |
243 | //
244 | // internals
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 | // current position in spherical coordinates
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 ); // get X column of objectMatrix
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 | // deltaX and deltaY are in pixels; right and down are positive
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 | // perspective
355 | var position = scope.object.position;
356 | offset.copy( position ).sub( scope.target );
357 | var targetDistance = offset.length();
358 |
359 | // half of the fov is center to top of screen
360 | targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
361 |
362 | // we use only clientHeight here so aspect ratio does not distort speed
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 | // orthographic
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 | // camera neither orthographic nor perspective
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 | // event callbacks - update the object state
428 | //
429 |
430 | function handleMouseDownRotate( event ) {
431 |
432 | //console.log( 'handleMouseDownRotate' );
433 |
434 | rotateStart.set( event.clientX, event.clientY );
435 |
436 | }
437 |
438 | function handleMouseDownDolly( event ) {
439 |
440 | //console.log( 'handleMouseDownDolly' );
441 |
442 | dollyStart.set( event.clientX, event.clientY );
443 |
444 | }
445 |
446 | function handleMouseDownPan( event ) {
447 |
448 | //console.log( 'handleMouseDownPan' );
449 |
450 | panStart.set( event.clientX, event.clientY );
451 |
452 | }
453 |
454 | function handleMouseMoveRotate( event ) {
455 |
456 | //console.log( 'handleMouseMoveRotate' );
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 | rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
465 |
466 | rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
467 |
468 | rotateStart.copy( rotateEnd );
469 |
470 | scope.update();
471 |
472 | }
473 |
474 | function handleMouseMoveDolly( event ) {
475 |
476 | //console.log( 'handleMouseMoveDolly' );
477 |
478 | dollyEnd.set( event.clientX, event.clientY );
479 |
480 | dollyDelta.subVectors( dollyEnd, dollyStart );
481 |
482 | if ( dollyDelta.y > 0 ) {
483 |
484 | dollyIn( getZoomScale() );
485 |
486 | } else if ( dollyDelta.y < 0 ) {
487 |
488 | dollyOut( getZoomScale() );
489 |
490 | }
491 |
492 | dollyStart.copy( dollyEnd );
493 |
494 | scope.update();
495 |
496 | }
497 |
498 | function handleMouseMovePan( event ) {
499 |
500 | //console.log( 'handleMouseMovePan' );
501 |
502 | panEnd.set( event.clientX, event.clientY );
503 |
504 | panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
505 |
506 | pan( panDelta.x, panDelta.y );
507 |
508 | panStart.copy( panEnd );
509 |
510 | scope.update();
511 |
512 | }
513 |
514 | function handleMouseUp( event ) {
515 |
516 | // console.log( 'handleMouseUp' );
517 |
518 | }
519 |
520 | function handleMouseWheel( event ) {
521 |
522 | // console.log( 'handleMouseWheel' );
523 |
524 | if ( event.deltaY < 0 ) {
525 |
526 | dollyOut( getZoomScale() );
527 |
528 | } else if ( event.deltaY > 0 ) {
529 |
530 | dollyIn( getZoomScale() );
531 |
532 | }
533 |
534 | scope.update();
535 |
536 | }
537 |
538 | function handleKeyDown( event ) {
539 |
540 | //console.log( 'handleKeyDown' );
541 |
542 | switch ( event.keyCode ) {
543 |
544 | case scope.keys.UP:
545 | pan( 0, scope.keyPanSpeed );
546 | scope.update();
547 | break;
548 |
549 | case scope.keys.BOTTOM:
550 | pan( 0, - scope.keyPanSpeed );
551 | scope.update();
552 | break;
553 |
554 | case scope.keys.LEFT:
555 | pan( scope.keyPanSpeed, 0 );
556 | scope.update();
557 | break;
558 |
559 | case scope.keys.RIGHT:
560 | pan( - scope.keyPanSpeed, 0 );
561 | scope.update();
562 | break;
563 |
564 | }
565 |
566 | }
567 |
568 | function handleTouchStartRotate( event ) {
569 |
570 | //console.log( 'handleTouchStartRotate' );
571 |
572 | rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
573 |
574 | }
575 |
576 | function handleTouchStartDollyPan( event ) {
577 |
578 | //console.log( 'handleTouchStartDollyPan' );
579 |
580 | if ( scope.enableZoom ) {
581 |
582 | var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
583 | var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
584 |
585 | var distance = Math.sqrt( dx * dx + dy * dy );
586 |
587 | dollyStart.set( 0, distance );
588 |
589 | }
590 |
591 | if ( scope.enablePan ) {
592 |
593 | var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
594 | var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
595 |
596 | panStart.set( x, y );
597 |
598 | }
599 |
600 | }
601 |
602 | function handleTouchMoveRotate( event ) {
603 |
604 | //console.log( 'handleTouchMoveRotate' );
605 |
606 | rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
607 |
608 | rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
609 |
610 | var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
611 |
612 | rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
613 |
614 | rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
615 |
616 | rotateStart.copy( rotateEnd );
617 |
618 | scope.update();
619 |
620 | }
621 |
622 | function handleTouchMoveDollyPan( event ) {
623 |
624 | //console.log( 'handleTouchMoveDollyPan' );
625 |
626 | if ( scope.enableZoom ) {
627 |
628 | var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
629 | var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
630 |
631 | var distance = Math.sqrt( dx * dx + dy * dy );
632 |
633 | dollyEnd.set( 0, distance );
634 |
635 | dollyDelta.set( 0, Math.pow( dollyEnd.y / dollyStart.y, scope.zoomSpeed ) );
636 |
637 | dollyIn( dollyDelta.y );
638 |
639 | dollyStart.copy( dollyEnd );
640 |
641 | }
642 |
643 | if ( scope.enablePan ) {
644 |
645 | var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
646 | var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
647 |
648 | panEnd.set( x, y );
649 |
650 | panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
651 |
652 | pan( panDelta.x, panDelta.y );
653 |
654 | panStart.copy( panEnd );
655 |
656 | }
657 |
658 | scope.update();
659 |
660 | }
661 |
662 | function handleTouchEnd( event ) {
663 |
664 | //console.log( 'handleTouchEnd' );
665 |
666 | }
667 |
668 | //
669 | // event handlers - FSM: listen for events and reset state
670 | //
671 |
672 | function onMouseDown( event ) {
673 |
674 | if ( scope.enabled === false ) return;
675 |
676 | event.preventDefault();
677 |
678 | switch ( event.button ) {
679 |
680 | case scope.mouseButtons.LEFT:
681 |
682 | if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
683 |
684 | if ( scope.enablePan === false ) return;
685 |
686 | handleMouseDownPan( event );
687 |
688 | state = STATE.PAN;
689 |
690 | } else {
691 |
692 | if ( scope.enableRotate === false ) return;
693 |
694 | handleMouseDownRotate( event );
695 |
696 | state = STATE.ROTATE;
697 |
698 | }
699 |
700 | break;
701 |
702 | case scope.mouseButtons.MIDDLE:
703 |
704 | if ( scope.enableZoom === false ) return;
705 |
706 | handleMouseDownDolly( event );
707 |
708 | state = STATE.DOLLY;
709 |
710 | break;
711 |
712 | case scope.mouseButtons.RIGHT:
713 |
714 | if ( scope.enablePan === false ) return;
715 |
716 | handleMouseDownPan( event );
717 |
718 | state = STATE.PAN;
719 |
720 | break;
721 |
722 | }
723 |
724 | if ( state !== STATE.NONE ) {
725 |
726 | document.addEventListener( 'mousemove', onMouseMove, false );
727 | document.addEventListener( 'mouseup', onMouseUp, false );
728 |
729 | scope.dispatchEvent( startEvent );
730 |
731 | }
732 |
733 | }
734 |
735 | function onMouseMove( event ) {
736 |
737 | if ( scope.enabled === false ) return;
738 |
739 | event.preventDefault();
740 |
741 | switch ( state ) {
742 |
743 | case STATE.ROTATE:
744 |
745 | if ( scope.enableRotate === false ) return;
746 |
747 | handleMouseMoveRotate( event );
748 |
749 | break;
750 |
751 | case STATE.DOLLY:
752 |
753 | if ( scope.enableZoom === false ) return;
754 |
755 | handleMouseMoveDolly( event );
756 |
757 | break;
758 |
759 | case STATE.PAN:
760 |
761 | if ( scope.enablePan === false ) return;
762 |
763 | handleMouseMovePan( event );
764 |
765 | break;
766 |
767 | }
768 |
769 | }
770 |
771 | function onMouseUp( event ) {
772 |
773 | if ( scope.enabled === false ) return;
774 |
775 | handleMouseUp( event );
776 |
777 | document.removeEventListener( 'mousemove', onMouseMove, false );
778 | document.removeEventListener( 'mouseup', onMouseUp, false );
779 |
780 | scope.dispatchEvent( endEvent );
781 |
782 | state = STATE.NONE;
783 |
784 | }
785 |
786 | function onMouseWheel( event ) {
787 |
788 | if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return;
789 |
790 | event.preventDefault();
791 | event.stopPropagation();
792 |
793 | scope.dispatchEvent( startEvent );
794 |
795 | handleMouseWheel( event );
796 |
797 | scope.dispatchEvent( endEvent );
798 |
799 | }
800 |
801 | function onKeyDown( event ) {
802 |
803 | if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return;
804 |
805 | handleKeyDown( event );
806 |
807 | }
808 |
809 | function onTouchStart( event ) {
810 |
811 | if ( scope.enabled === false ) return;
812 |
813 | event.preventDefault();
814 |
815 | switch ( event.touches.length ) {
816 |
817 | case 1: // one-fingered touch: rotate
818 |
819 | if ( scope.enableRotate === false ) return;
820 |
821 | handleTouchStartRotate( event );
822 |
823 | state = STATE.TOUCH_ROTATE;
824 |
825 | break;
826 |
827 | case 2: // two-fingered touch: dolly-pan
828 |
829 | if ( scope.enableZoom === false && scope.enablePan === false ) return;
830 |
831 | handleTouchStartDollyPan( event );
832 |
833 | state = STATE.TOUCH_DOLLY_PAN;
834 |
835 | break;
836 |
837 | default:
838 |
839 | state = STATE.NONE;
840 |
841 | }
842 |
843 | if ( state !== STATE.NONE ) {
844 |
845 | scope.dispatchEvent( startEvent );
846 |
847 | }
848 |
849 | }
850 |
851 | function onTouchMove( event ) {
852 |
853 | if ( scope.enabled === false ) return;
854 |
855 | event.preventDefault();
856 | event.stopPropagation();
857 |
858 | switch ( event.touches.length ) {
859 |
860 | case 1: // one-fingered touch: rotate
861 |
862 | if ( scope.enableRotate === false ) return;
863 | if ( state !== STATE.TOUCH_ROTATE ) return; // is this needed?
864 |
865 | handleTouchMoveRotate( event );
866 |
867 | break;
868 |
869 | case 2: // two-fingered touch: dolly-pan
870 |
871 | if ( scope.enableZoom === false && scope.enablePan === false ) return;
872 | if ( state !== STATE.TOUCH_DOLLY_PAN ) return; // is this needed?
873 |
874 | handleTouchMoveDollyPan( event );
875 |
876 | break;
877 |
878 | default:
879 |
880 | state = STATE.NONE;
881 |
882 | }
883 |
884 | }
885 |
886 | function onTouchEnd( event ) {
887 |
888 | if ( scope.enabled === false ) return;
889 |
890 | handleTouchEnd( event );
891 |
892 | scope.dispatchEvent( endEvent );
893 |
894 | state = STATE.NONE;
895 |
896 | }
897 |
898 | function onContextMenu( event ) {
899 |
900 | if ( scope.enabled === false ) return;
901 |
902 | event.preventDefault();
903 |
904 | }
905 |
906 | //
907 |
908 | scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );
909 |
910 | scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
911 | scope.domElement.addEventListener( 'wheel', onMouseWheel, false );
912 |
913 | scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
914 | scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
915 | scope.domElement.addEventListener( 'touchmove', onTouchMove, false );
916 |
917 | window.addEventListener( 'keydown', onKeyDown, false );
918 |
919 | // force an update at start
920 |
921 | this.update();
922 |
923 | };
924 |
925 | THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
926 | THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
927 |
928 | Object.defineProperties( THREE.OrbitControls.prototype, {
929 |
930 | center: {
931 |
932 | get: function () {
933 |
934 | console.warn( 'THREE.OrbitControls: .center has been renamed to .target' );
935 | return this.target;
936 |
937 | }
938 |
939 | },
940 |
941 | // backward compatibility
942 |
943 | noZoom: {
944 |
945 | get: function () {
946 |
947 | console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
948 | return ! this.enableZoom;
949 |
950 | },
951 |
952 | set: function ( value ) {
953 |
954 | console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
955 | this.enableZoom = ! value;
956 |
957 | }
958 |
959 | },
960 |
961 | noRotate: {
962 |
963 | get: function () {
964 |
965 | console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
966 | return ! this.enableRotate;
967 |
968 | },
969 |
970 | set: function ( value ) {
971 |
972 | console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
973 | this.enableRotate = ! value;
974 |
975 | }
976 |
977 | },
978 |
979 | noPan: {
980 |
981 | get: function () {
982 |
983 | console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
984 | return ! this.enablePan;
985 |
986 | },
987 |
988 | set: function ( value ) {
989 |
990 | console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
991 | this.enablePan = ! value;
992 |
993 | }
994 |
995 | },
996 |
997 | noKeys: {
998 |
999 | get: function () {
1000 |
1001 | console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1002 | return ! this.enableKeys;
1003 |
1004 | },
1005 |
1006 | set: function ( value ) {
1007 |
1008 | console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1009 | this.enableKeys = ! value;
1010 |
1011 | }
1012 |
1013 | },
1014 |
1015 | staticMoving: {
1016 |
1017 | get: function () {
1018 |
1019 | console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1020 | return ! this.enableDamping;
1021 |
1022 | },
1023 |
1024 | set: function ( value ) {
1025 |
1026 | console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1027 | this.enableDamping = ! value;
1028 |
1029 | }
1030 |
1031 | },
1032 |
1033 | dynamicDampingFactor: {
1034 |
1035 | get: function () {
1036 |
1037 | console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1038 | return this.dampingFactor;
1039 |
1040 | },
1041 |
1042 | set: function ( value ) {
1043 |
1044 | console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1045 | this.dampingFactor = value;
1046 |
1047 | }
1048 |
1049 | }
1050 |
1051 | } );
1052 |
--------------------------------------------------------------------------------