OrbitControls.js 20 KB

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