OrbitControls.js 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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. /*global THREE, console */
  9. ( function () {
  10. function OrbitConstraint ( object ) {
  11. this.object = object;
  12. // "target" sets the location of focus, where the object orbits around
  13. // and where it pans with respect to.
  14. this.target = new THREE.Vector3();
  15. // Limits to how far you can dolly in and out ( PerspectiveCamera only )
  16. this.minDistance = 0;
  17. this.maxDistance = Infinity;
  18. // Limits to how far you can zoom in and out ( OrthographicCamera only )
  19. this.minZoom = 0;
  20. this.maxZoom = Infinity;
  21. // How far you can orbit vertically, upper and lower limits.
  22. // Range is 0 to Math.PI radians.
  23. this.minPolarAngle = 0; // radians
  24. this.maxPolarAngle = Math.PI; // radians
  25. // How far you can orbit horizontally, upper and lower limits.
  26. // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
  27. this.minAzimuthAngle = - Infinity; // radians
  28. this.maxAzimuthAngle = Infinity; // radians
  29. // Set to true to enable damping (inertia)
  30. // If damping is enabled, you must call controls.update() in your animation loop
  31. this.enableDamping = false;
  32. this.dampingFactor = 0.25;
  33. ////////////
  34. // internals
  35. var scope = this;
  36. var EPS = 0.000001;
  37. // Current position in spherical coordinate system.
  38. var theta;
  39. var phi;
  40. // Pending changes
  41. var phiDelta = 0;
  42. var thetaDelta = 0;
  43. var scale = 1;
  44. var panOffset = new THREE.Vector3();
  45. var zoomChanged = false;
  46. // API
  47. this.getPolarAngle = function () {
  48. return phi;
  49. };
  50. this.getAzimuthalAngle = function () {
  51. return theta;
  52. };
  53. this.rotateLeft = function ( angle ) {
  54. thetaDelta -= angle;
  55. };
  56. this.rotateUp = function ( angle ) {
  57. phiDelta -= angle;
  58. };
  59. // pass in distance in world space to move left
  60. this.panLeft = function() {
  61. var v = new THREE.Vector3();
  62. return function panLeft ( distance ) {
  63. var te = this.object.matrix.elements;
  64. // get X column of matrix
  65. v.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  66. v.multiplyScalar( - distance );
  67. panOffset.add( v );
  68. };
  69. }();
  70. // pass in distance in world space to move up
  71. this.panUp = function() {
  72. var v = new THREE.Vector3();
  73. return function panUp ( distance ) {
  74. var te = this.object.matrix.elements;
  75. // get Y column of matrix
  76. v.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  77. v.multiplyScalar( distance );
  78. panOffset.add( v );
  79. };
  80. }();
  81. // pass in x,y of change desired in pixel space,
  82. // right and down are positive
  83. this.pan = function ( deltaX, deltaY, screenWidth, screenHeight ) {
  84. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  85. // perspective
  86. var position = scope.object.position;
  87. var offset = position.clone().sub( scope.target );
  88. var targetDistance = offset.length();
  89. // half of the fov is center to top of screen
  90. targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
  91. // we actually don't use screenWidth, since perspective camera is fixed to screen height
  92. scope.panLeft( 2 * deltaX * targetDistance / screenHeight );
  93. scope.panUp( 2 * deltaY * targetDistance / screenHeight );
  94. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  95. // orthographic
  96. scope.panLeft( deltaX * ( scope.object.right - scope.object.left ) / screenWidth );
  97. scope.panUp( deltaY * ( scope.object.top - scope.object.bottom ) / screenHeight );
  98. } else {
  99. // camera neither orthographic or perspective
  100. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
  101. }
  102. };
  103. this.dollyIn = function ( dollyScale ) {
  104. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  105. scale /= dollyScale;
  106. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  107. scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
  108. scope.object.updateProjectionMatrix();
  109. zoomChanged = true;
  110. } else {
  111. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
  112. }
  113. };
  114. this.dollyOut = function ( dollyScale ) {
  115. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  116. scale *= dollyScale;
  117. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  118. scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
  119. scope.object.updateProjectionMatrix();
  120. zoomChanged = true;
  121. } else {
  122. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
  123. }
  124. };
  125. this.update = function() {
  126. var offset = new THREE.Vector3();
  127. // so camera.up is the orbit axis
  128. var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
  129. var quatInverse = quat.clone().inverse();
  130. var lastPosition = new THREE.Vector3();
  131. var lastQuaternion = new THREE.Quaternion();
  132. return function () {
  133. var position = this.object.position;
  134. offset.copy( position ).sub( this.target );
  135. // rotate offset to "y-axis-is-up" space
  136. offset.applyQuaternion( quat );
  137. // angle from z-axis around y-axis
  138. theta = Math.atan2( offset.x, offset.z );
  139. // angle from y-axis
  140. phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
  141. theta += thetaDelta;
  142. phi += phiDelta;
  143. // restrict theta to be between desired limits
  144. theta = Math.max( this.minAzimuthAngle, Math.min( this.maxAzimuthAngle, theta ) );
  145. // restrict phi to be between desired limits
  146. phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
  147. // restrict phi to be betwee EPS and PI-EPS
  148. phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
  149. var radius = offset.length() * scale;
  150. // restrict radius to be between desired limits
  151. radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
  152. // move target to panned location
  153. this.target.add( panOffset );
  154. offset.x = radius * Math.sin( phi ) * Math.sin( theta );
  155. offset.y = radius * Math.cos( phi );
  156. offset.z = radius * Math.sin( phi ) * Math.cos( theta );
  157. // rotate offset back to "camera-up-vector-is-up" space
  158. offset.applyQuaternion( quatInverse );
  159. position.copy( this.target ).add( offset );
  160. this.object.lookAt( this.target );
  161. if ( this.enableDamping === true ) {
  162. thetaDelta *= ( 1 - this.dampingFactor );
  163. phiDelta *= ( 1 - this.dampingFactor );
  164. } else {
  165. thetaDelta = 0;
  166. phiDelta = 0;
  167. }
  168. scale = 1;
  169. panOffset.set( 0, 0, 0 );
  170. // update condition is:
  171. // min(camera displacement, camera rotation in radians)^2 > EPS
  172. // using small-angle approximation cos(x/2) = 1 - x^2 / 8
  173. if ( zoomChanged ||
  174. lastPosition.distanceToSquared( this.object.position ) > EPS ||
  175. 8 * ( 1 - lastQuaternion.dot( this.object.quaternion ) ) > EPS ) {
  176. lastPosition.copy( this.object.position );
  177. lastQuaternion.copy( this.object.quaternion );
  178. zoomChanged = false;
  179. return true;
  180. }
  181. return false;
  182. };
  183. }();
  184. };
  185. // This set of controls performs orbiting, dollying (zooming), and panning. It maintains
  186. // the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is
  187. // supported.
  188. //
  189. // Orbit - left mouse / touch: one finger move
  190. // Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
  191. // Pan - right mouse, or arrow keys / touch: three finter swipe
  192. THREE.OrbitControls = function ( object, domElement ) {
  193. var constraint = new OrbitConstraint( object );
  194. this.domElement = ( domElement !== undefined ) ? domElement : document;
  195. // API
  196. Object.defineProperty( this, 'constraint', {
  197. get: function() {
  198. return constraint;
  199. }
  200. } );
  201. this.getPolarAngle = function () {
  202. return constraint.getPolarAngle();
  203. };
  204. this.getAzimuthalAngle = function () {
  205. return constraint.getAzimuthalAngle();
  206. };
  207. // Set to false to disable this control
  208. this.enabled = true;
  209. // center is old, deprecated; use "target" instead
  210. this.center = this.target;
  211. // This option actually enables dollying in and out; left as "zoom" for
  212. // backwards compatibility.
  213. // Set to false to disable zooming
  214. this.enableZoom = true;
  215. this.zoomSpeed = 1.0;
  216. // Set to false to disable rotating
  217. this.enableRotate = true;
  218. this.rotateSpeed = 1.0;
  219. // Set to false to disable panning
  220. this.enablePan = true;
  221. this.keyPanSpeed = 7.0; // pixels moved per arrow key push
  222. // Set to true to automatically rotate around the target
  223. // If auto-rotate is enabled, you must call controls.update() in your animation loop
  224. this.autoRotate = false;
  225. this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
  226. // Set to false to disable use of the keys
  227. this.enableKeys = true;
  228. // The four arrow keys
  229. this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
  230. // Mouse buttons
  231. this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
  232. ////////////
  233. // internals
  234. var scope = this;
  235. var rotateStart = new THREE.Vector2();
  236. var rotateEnd = new THREE.Vector2();
  237. var rotateDelta = new THREE.Vector2();
  238. var panStart = new THREE.Vector2();
  239. var panEnd = new THREE.Vector2();
  240. var panDelta = new THREE.Vector2();
  241. var dollyStart = new THREE.Vector2();
  242. var dollyEnd = new THREE.Vector2();
  243. var dollyDelta = new THREE.Vector2();
  244. var STATE = { NONE : - 1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
  245. var state = STATE.NONE;
  246. // for reset
  247. this.target0 = this.target.clone();
  248. this.position0 = this.object.position.clone();
  249. this.zoom0 = this.object.zoom;
  250. // events
  251. var changeEvent = { type: 'change' };
  252. var startEvent = { type: 'start' };
  253. var endEvent = { type: 'end' };
  254. // pass in x,y of change desired in pixel space,
  255. // right and down are positive
  256. function pan( deltaX, deltaY ) {
  257. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  258. constraint.pan( deltaX, deltaY, element.clientWidth, element.clientHeight );
  259. }
  260. this.update = function () {
  261. if ( this.autoRotate && state === STATE.NONE ) {
  262. constraint.rotateLeft( getAutoRotationAngle() );
  263. }
  264. if ( constraint.update() === true ) {
  265. this.dispatchEvent( changeEvent );
  266. }
  267. };
  268. this.reset = function () {
  269. state = STATE.NONE;
  270. this.target.copy( this.target0 );
  271. this.object.position.copy( this.position0 );
  272. this.object.zoom = this.zoom0;
  273. this.object.updateProjectionMatrix();
  274. this.dispatchEvent( changeEvent );
  275. this.update();
  276. };
  277. function getAutoRotationAngle() {
  278. return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
  279. }
  280. function getZoomScale() {
  281. return Math.pow( 0.95, scope.zoomSpeed );
  282. }
  283. function onMouseDown( event ) {
  284. if ( scope.enabled === false ) return;
  285. event.preventDefault();
  286. if ( event.button === scope.mouseButtons.ORBIT ) {
  287. if ( scope.enableRotate === false ) return;
  288. state = STATE.ROTATE;
  289. rotateStart.set( event.clientX, event.clientY );
  290. } else if ( event.button === scope.mouseButtons.ZOOM ) {
  291. if ( scope.enableZoom === false ) return;
  292. state = STATE.DOLLY;
  293. dollyStart.set( event.clientX, event.clientY );
  294. } else if ( event.button === scope.mouseButtons.PAN ) {
  295. if ( scope.enablePan === false ) return;
  296. state = STATE.PAN;
  297. panStart.set( event.clientX, event.clientY );
  298. }
  299. if ( state !== STATE.NONE ) {
  300. document.addEventListener( 'mousemove', onMouseMove, false );
  301. document.addEventListener( 'mouseup', onMouseUp, false );
  302. document.addEventListener( 'mouseout', onMouseUp, false );
  303. scope.dispatchEvent( startEvent );
  304. }
  305. }
  306. function onMouseMove( event ) {
  307. if ( scope.enabled === false ) return;
  308. event.preventDefault();
  309. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  310. if ( state === STATE.ROTATE ) {
  311. if ( scope.enableRotate === false ) return;
  312. rotateEnd.set( event.clientX, event.clientY );
  313. rotateDelta.subVectors( rotateEnd, rotateStart );
  314. // rotating across whole screen goes 360 degrees around
  315. constraint.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
  316. // rotating up and down along whole screen attempts to go 360, but limited to 180
  317. constraint.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
  318. rotateStart.copy( rotateEnd );
  319. } else if ( state === STATE.DOLLY ) {
  320. if ( scope.enableZoom === false ) return;
  321. dollyEnd.set( event.clientX, event.clientY );
  322. dollyDelta.subVectors( dollyEnd, dollyStart );
  323. if ( dollyDelta.y > 0 ) {
  324. constraint.dollyIn( getZoomScale() );
  325. } else if ( dollyDelta.y < 0 ) {
  326. constraint.dollyOut( getZoomScale() );
  327. }
  328. dollyStart.copy( dollyEnd );
  329. } else if ( state === STATE.PAN ) {
  330. if ( scope.enablePan === false ) return;
  331. panEnd.set( event.clientX, event.clientY );
  332. panDelta.subVectors( panEnd, panStart );
  333. pan( panDelta.x, panDelta.y );
  334. panStart.copy( panEnd );
  335. }
  336. if ( state !== STATE.NONE ) scope.update();
  337. }
  338. function onMouseUp( /* event */ ) {
  339. if ( scope.enabled === false ) return;
  340. document.removeEventListener( 'mousemove', onMouseMove, false );
  341. document.removeEventListener( 'mouseup', onMouseUp, false );
  342. document.removeEventListener( 'mouseout', onMouseUp, false );
  343. scope.dispatchEvent( endEvent );
  344. state = STATE.NONE;
  345. }
  346. function onMouseWheel( event ) {
  347. if ( scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE ) return;
  348. event.preventDefault();
  349. event.stopPropagation();
  350. var delta = 0;
  351. if ( event.wheelDelta !== undefined ) {
  352. // WebKit / Opera / Explorer 9
  353. delta = event.wheelDelta;
  354. } else if ( event.detail !== undefined ) {
  355. // Firefox
  356. delta = - event.detail;
  357. }
  358. if ( delta > 0 ) {
  359. constraint.dollyOut( getZoomScale() );
  360. } else if ( delta < 0 ) {
  361. constraint.dollyIn( getZoomScale() );
  362. }
  363. scope.update();
  364. scope.dispatchEvent( startEvent );
  365. scope.dispatchEvent( endEvent );
  366. }
  367. function onKeyDown( event ) {
  368. if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return;
  369. switch ( event.keyCode ) {
  370. case scope.keys.UP:
  371. pan( 0, scope.keyPanSpeed );
  372. scope.update();
  373. break;
  374. case scope.keys.BOTTOM:
  375. pan( 0, - scope.keyPanSpeed );
  376. scope.update();
  377. break;
  378. case scope.keys.LEFT:
  379. pan( scope.keyPanSpeed, 0 );
  380. scope.update();
  381. break;
  382. case scope.keys.RIGHT:
  383. pan( - scope.keyPanSpeed, 0 );
  384. scope.update();
  385. break;
  386. }
  387. }
  388. function touchstart( event ) {
  389. if ( scope.enabled === false ) return;
  390. switch ( event.touches.length ) {
  391. case 1: // one-fingered touch: rotate
  392. if ( scope.enableRotate === false ) return;
  393. state = STATE.TOUCH_ROTATE;
  394. rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  395. break;
  396. case 2: // two-fingered touch: dolly
  397. if ( scope.enableZoom === false ) return;
  398. state = STATE.TOUCH_DOLLY;
  399. var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  400. var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  401. var distance = Math.sqrt( dx * dx + dy * dy );
  402. dollyStart.set( 0, distance );
  403. break;
  404. case 3: // three-fingered touch: pan
  405. if ( scope.enablePan === false ) return;
  406. state = STATE.TOUCH_PAN;
  407. panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  408. break;
  409. default:
  410. state = STATE.NONE;
  411. }
  412. if ( state !== STATE.NONE ) scope.dispatchEvent( startEvent );
  413. }
  414. function touchmove( event ) {
  415. if ( scope.enabled === false ) return;
  416. event.preventDefault();
  417. event.stopPropagation();
  418. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  419. switch ( event.touches.length ) {
  420. case 1: // one-fingered touch: rotate
  421. if ( scope.enableRotate === false ) return;
  422. if ( state !== STATE.TOUCH_ROTATE ) return;
  423. rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  424. rotateDelta.subVectors( rotateEnd, rotateStart );
  425. // rotating across whole screen goes 360 degrees around
  426. constraint.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
  427. // rotating up and down along whole screen attempts to go 360, but limited to 180
  428. constraint.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
  429. rotateStart.copy( rotateEnd );
  430. scope.update();
  431. break;
  432. case 2: // two-fingered touch: dolly
  433. if ( scope.enableZoom === false ) return;
  434. if ( state !== STATE.TOUCH_DOLLY ) return;
  435. var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  436. var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  437. var distance = Math.sqrt( dx * dx + dy * dy );
  438. dollyEnd.set( 0, distance );
  439. dollyDelta.subVectors( dollyEnd, dollyStart );
  440. if ( dollyDelta.y > 0 ) {
  441. constraint.dollyOut( getZoomScale() );
  442. } else if ( dollyDelta.y < 0 ) {
  443. constraint.dollyIn( getZoomScale() );
  444. }
  445. dollyStart.copy( dollyEnd );
  446. scope.update();
  447. break;
  448. case 3: // three-fingered touch: pan
  449. if ( scope.enablePan === false ) return;
  450. if ( state !== STATE.TOUCH_PAN ) return;
  451. panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  452. panDelta.subVectors( panEnd, panStart );
  453. pan( panDelta.x, panDelta.y );
  454. panStart.copy( panEnd );
  455. scope.update();
  456. break;
  457. default:
  458. state = STATE.NONE;
  459. }
  460. }
  461. function touchend( /* event */ ) {
  462. if ( scope.enabled === false ) return;
  463. scope.dispatchEvent( endEvent );
  464. state = STATE.NONE;
  465. }
  466. function contextmenu( event ) {
  467. event.preventDefault();
  468. }
  469. this.dispose = function() {
  470. this.domElement.removeEventListener( 'contextmenu', contextmenu, false );
  471. this.domElement.removeEventListener( 'mousedown', onMouseDown, false );
  472. this.domElement.removeEventListener( 'mousewheel', onMouseWheel, false );
  473. this.domElement.removeEventListener( 'MozMousePixelScroll', onMouseWheel, false ); // firefox
  474. this.domElement.removeEventListener( 'touchstart', touchstart, false );
  475. this.domElement.removeEventListener( 'touchend', touchend, false );
  476. this.domElement.removeEventListener( 'touchmove', touchmove, false );
  477. document.removeEventListener( 'mousemove', onMouseMove, false );
  478. document.removeEventListener( 'mouseup', onMouseUp, false );
  479. document.removeEventListener( 'mouseout', onMouseUp, false );
  480. window.removeEventListener( 'keydown', onKeyDown, false );
  481. }
  482. this.domElement.addEventListener( 'contextmenu', contextmenu, false );
  483. this.domElement.addEventListener( 'mousedown', onMouseDown, false );
  484. this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
  485. this.domElement.addEventListener( 'MozMousePixelScroll', onMouseWheel, false ); // firefox
  486. this.domElement.addEventListener( 'touchstart', touchstart, false );
  487. this.domElement.addEventListener( 'touchend', touchend, false );
  488. this.domElement.addEventListener( 'touchmove', touchmove, false );
  489. window.addEventListener( 'keydown', onKeyDown, false );
  490. // force an update at start
  491. this.update();
  492. };
  493. THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
  494. THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
  495. Object.defineProperties( THREE.OrbitControls.prototype, {
  496. object: {
  497. get: function () {
  498. return this.constraint.object;
  499. }
  500. },
  501. target: {
  502. get: function () {
  503. return this.constraint.target;
  504. },
  505. set: function ( value ) {
  506. console.warn( 'THREE.OrbitControls: target is now immutable. Use target.set() instead.' );
  507. this.constraint.target.copy( value );
  508. }
  509. },
  510. minDistance : {
  511. get: function () {
  512. return this.constraint.minDistance;
  513. },
  514. set: function ( value ) {
  515. this.constraint.minDistance = value;
  516. }
  517. },
  518. maxDistance : {
  519. get: function () {
  520. return this.constraint.maxDistance;
  521. },
  522. set: function ( value ) {
  523. this.constraint.maxDistance = value;
  524. }
  525. },
  526. minZoom : {
  527. get: function () {
  528. return this.constraint.minZoom;
  529. },
  530. set: function ( value ) {
  531. this.constraint.minZoom = value;
  532. }
  533. },
  534. maxZoom : {
  535. get: function () {
  536. return this.constraint.maxZoom;
  537. },
  538. set: function ( value ) {
  539. this.constraint.maxZoom = value;
  540. }
  541. },
  542. minPolarAngle : {
  543. get: function () {
  544. return this.constraint.minPolarAngle;
  545. },
  546. set: function ( value ) {
  547. this.constraint.minPolarAngle = value;
  548. }
  549. },
  550. maxPolarAngle : {
  551. get: function () {
  552. return this.constraint.maxPolarAngle;
  553. },
  554. set: function ( value ) {
  555. this.constraint.maxPolarAngle = value;
  556. }
  557. },
  558. minAzimuthAngle : {
  559. get: function () {
  560. return this.constraint.minAzimuthAngle;
  561. },
  562. set: function ( value ) {
  563. this.constraint.minAzimuthAngle = value;
  564. }
  565. },
  566. maxAzimuthAngle : {
  567. get: function () {
  568. return this.constraint.maxAzimuthAngle;
  569. },
  570. set: function ( value ) {
  571. this.constraint.maxAzimuthAngle = value;
  572. }
  573. },
  574. enableDamping : {
  575. get: function () {
  576. return this.constraint.enableDamping;
  577. },
  578. set: function ( value ) {
  579. this.constraint.enableDamping = value;
  580. }
  581. },
  582. dampingFactor : {
  583. get: function () {
  584. return this.constraint.dampingFactor;
  585. },
  586. set: function ( value ) {
  587. this.constraint.dampingFactor = value;
  588. }
  589. },
  590. // backward compatibility
  591. noZoom: {
  592. get: function () {
  593. console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
  594. return ! this.enableZoom;
  595. },
  596. set: function ( value ) {
  597. console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
  598. this.enableZoom = ! value;
  599. }
  600. },
  601. noRotate: {
  602. get: function () {
  603. console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
  604. return ! this.enableRotate;
  605. },
  606. set: function ( value ) {
  607. console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
  608. this.enableRotate = ! value;
  609. }
  610. },
  611. noPan: {
  612. get: function () {
  613. console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
  614. return ! this.enablePan;
  615. },
  616. set: function ( value ) {
  617. console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
  618. this.enablePan = ! value;
  619. }
  620. },
  621. noKeys: {
  622. get: function () {
  623. console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
  624. return ! this.enableKeys;
  625. },
  626. set: function ( value ) {
  627. console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
  628. this.enableKeys = ! value;
  629. }
  630. },
  631. staticMoving : {
  632. get: function () {
  633. console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
  634. return ! this.constraint.enableDamping;
  635. },
  636. set: function ( value ) {
  637. console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
  638. this.constraint.enableDamping = ! value;
  639. }
  640. },
  641. dynamicDampingFactor : {
  642. get: function () {
  643. console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
  644. return this.constraint.dampingFactor;
  645. },
  646. set: function ( value ) {
  647. console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
  648. this.constraint.dampingFactor = value;
  649. }
  650. }
  651. } );
  652. }() );