OrbitControls.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>OrbitControls - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Controls.html">Controls</a> → </p>
  13. <h1 translate="no">OrbitControls</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>Orbit controls allow the camera to orbit around a target.</p>
  17. <p>OrbitControls performs orbiting, dollying (zooming), and panning. Unlike <a href="TrackballControls.html">TrackballControls</a>,
  18. it maintains the &quot;up&quot; direction <code>object.up</code> (+Y by default).</p>
  19. <ul>
  20. <li>Orbit: Left mouse / touch: one-finger move.</li>
  21. <li>Zoom: Middle mouse, or mousewheel / touch: two-finger spread or squish.</li>
  22. <li>Pan: Right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move.</li>
  23. </ul></div>
  24. <h2>Code Example</h2>
  25. <div translate="no"><pre><code class="language-js">const controls = new OrbitControls( camera, renderer.domElement );
  26. // controls.update() must be called after any manual changes to the camera's transform
  27. camera.position.set( 0, 20, 100 );
  28. controls.update();
  29. function animate() {
  30. // required if controls.enableDamping or controls.autoRotate are set to true
  31. controls.update();
  32. renderer.render( scene, camera );
  33. }
  34. </code></pre></div>
  35. </header>
  36. <article>
  37. <h2 class="subsection-title">Import</h2>
  38. <p><span translate="no">OrbitControls</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  39. <pre><code class="language-js">import { OrbitControls } from 'three/addons/controls/OrbitControls.js';</code></pre>
  40. <div class="container-overview">
  41. <h2>Constructor</h2>
  42. <h3 class="name name-method" id="OrbitControls" translate="no">new <a href="#OrbitControls">OrbitControls</a><span class="signature">( object : <span class="param-type">Object3D</span>, domElement : <span class="param-type">HTMLElement</span> )</span> </h3>
  43. <div class="method">
  44. <div class="description">
  45. <p>Constructs a new controls instance.</p>
  46. </div>
  47. <table class="params">
  48. <tbody>
  49. <tr>
  50. <td class="name"><code>object</code></td>
  51. <td class="description last"><p>The object that is managed by the controls.</p></td>
  52. </tr>
  53. <tr>
  54. <td class="name"><code>domElement</code></td>
  55. <td class="description last"><p>The HTML element used for event listeners.<br/>Default is <code>null</code>.</p></td>
  56. </tr>
  57. </tbody>
  58. </table>
  59. </div>
  60. </div>
  61. <h2 class="subsection-title">Properties</h2>
  62. <div class="member">
  63. <h3 class="name" id="autoRotate" translate="no">.<a href="#autoRotate">autoRotate</a><span class="type-signature"> : boolean</span> </h3>
  64. <div class="description">
  65. <p>Set to true to automatically rotate around the target</p>
  66. <p>Note that if this is enabled, you must call <code>update()</code> in your animation loop.
  67. If you want the auto-rotate speed to be independent of the frame rate (the refresh
  68. rate of the display), you must pass the time <code>deltaTime</code>, in seconds, to <code>update()</code>.<br/>Default is <code>false</code>.</p>
  69. </div>
  70. </div>
  71. <div class="member">
  72. <h3 class="name" id="autoRotateSpeed" translate="no">.<a href="#autoRotateSpeed">autoRotateSpeed</a><span class="type-signature"> : number</span> </h3>
  73. <div class="description">
  74. <p>How fast to rotate around the target if <code>autoRotate</code> is <code>true</code>. The default equates to 30 seconds
  75. per orbit at 60fps.</p>
  76. <p>Note that if <code>autoRotate</code> is enabled, you must call <code>update()</code> in your animation loop.<br/>Default is <code>2</code>.</p>
  77. </div>
  78. </div>
  79. <div class="member">
  80. <h3 class="name" id="cursor" translate="no">.<a href="#cursor">cursor</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  81. <div class="description">
  82. <p>The focus point of the <code>minTargetRadius</code> and <code>maxTargetRadius</code> limits.
  83. It can be updated manually at any point to change the center of interest
  84. for the <code>target</code>.</p>
  85. </div>
  86. </div>
  87. <div class="member">
  88. <h3 class="name" id="dampingFactor" translate="no">.<a href="#dampingFactor">dampingFactor</a><span class="type-signature"> : number</span> </h3>
  89. <div class="description">
  90. <p>The damping inertia used if <code>enableDamping</code> is set to <code>true</code>.</p>
  91. <p>Note that for this to work, you must call <code>update()</code> in your animation loop.<br/>Default is <code>0.05</code>.</p>
  92. </div>
  93. </div>
  94. <div class="member">
  95. <h3 class="name" id="enableDamping" translate="no">.<a href="#enableDamping">enableDamping</a><span class="type-signature"> : boolean</span> </h3>
  96. <div class="description">
  97. <p>Set to <code>true</code> to enable damping (inertia), which can be used to give a sense of weight
  98. to the controls. Note that if this is enabled, you must call <code>update()</code> in your animation
  99. loop.<br/>Default is <code>false</code>.</p>
  100. </div>
  101. </div>
  102. <div class="member">
  103. <h3 class="name" id="enablePan" translate="no">.<a href="#enablePan">enablePan</a><span class="type-signature"> : boolean</span> </h3>
  104. <div class="description">
  105. <p>Enable or disable camera panning.<br/>Default is <code>true</code>.</p>
  106. </div>
  107. </div>
  108. <div class="member">
  109. <h3 class="name" id="enableRotate" translate="no">.<a href="#enableRotate">enableRotate</a><span class="type-signature"> : boolean</span> </h3>
  110. <div class="description">
  111. <p>Enable or disable horizontal and vertical rotation of the camera.</p>
  112. <p>Note that it is possible to disable a single axis by setting the min and max of the
  113. <code>minPolarAngle</code> or <code>minAzimuthAngle</code> to the same value, which will cause the vertical
  114. or horizontal rotation to be fixed at that value.<br/>Default is <code>true</code>.</p>
  115. </div>
  116. </div>
  117. <div class="member">
  118. <h3 class="name" id="enableZoom" translate="no">.<a href="#enableZoom">enableZoom</a><span class="type-signature"> : boolean</span> </h3>
  119. <div class="description">
  120. <p>Enable or disable zooming (dollying) of the camera.<br/>Default is <code>true</code>.</p>
  121. </div>
  122. </div>
  123. <div class="member">
  124. <h3 class="name" id="keyPanSpeed" translate="no">.<a href="#keyPanSpeed">keyPanSpeed</a><span class="type-signature"> : number</span> </h3>
  125. <div class="description">
  126. <p>How fast to pan the camera when the keyboard is used in
  127. pixels per keypress.<br/>Default is <code>7</code>.</p>
  128. </div>
  129. </div>
  130. <div class="member">
  131. <h3 class="name" id="keyRotateSpeed" translate="no">.<a href="#keyRotateSpeed">keyRotateSpeed</a><span class="type-signature"> : number</span> </h3>
  132. <div class="description">
  133. <p>How fast to rotate the camera when the keyboard is used.<br/>Default is <code>1</code>.</p>
  134. </div>
  135. </div>
  136. <div class="member">
  137. <h3 class="name" id="keys" translate="no">.<a href="#keys">keys</a><span class="type-signature"> : Object</span> </h3>
  138. <div class="description">
  139. <p>This object contains references to the keycodes for controlling camera panning.</p>
  140. <pre><code class="language-js">controls.keys = {
  141. LEFT: 'ArrowLeft', //left arrow
  142. UP: 'ArrowUp', // up arrow
  143. RIGHT: 'ArrowRight', // right arrow
  144. BOTTOM: 'ArrowDown' // down arrow
  145. }
  146. </code></pre>
  147. </div>
  148. <dl class="details">
  149. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Controls.html#keys">Controls#keys</a></dt>
  150. </dl>
  151. </div>
  152. <div class="member">
  153. <h3 class="name" id="maxAzimuthAngle" translate="no">.<a href="#maxAzimuthAngle">maxAzimuthAngle</a><span class="type-signature"> : number</span> </h3>
  154. <div class="description">
  155. <p>How far you can orbit horizontally, upper limit. If set, the interval <code>[ min, max ]</code>
  156. must be a sub-interval of <code>[ - 2 PI, 2 PI ]</code>, with <code>( max - min &lt; 2 PI )</code>.<br/>Default is <code>-Infinity</code>.</p>
  157. </div>
  158. </div>
  159. <div class="member">
  160. <h3 class="name" id="maxDistance" translate="no">.<a href="#maxDistance">maxDistance</a><span class="type-signature"> : number</span> </h3>
  161. <div class="description">
  162. <p>How far you can dolly out (perspective camera only).<br/>Default is <code>Infinity</code>.</p>
  163. </div>
  164. </div>
  165. <div class="member">
  166. <h3 class="name" id="maxPolarAngle" translate="no">.<a href="#maxPolarAngle">maxPolarAngle</a><span class="type-signature"> : number</span> </h3>
  167. <div class="description">
  168. <p>How far you can orbit vertically, upper limit. Range is <code>[0, Math.PI]</code> radians.<br/>Default is <code>Math.PI</code>.</p>
  169. </div>
  170. </div>
  171. <div class="member">
  172. <h3 class="name" id="maxTargetRadius" translate="no">.<a href="#maxTargetRadius">maxTargetRadius</a><span class="type-signature"> : number</span> </h3>
  173. <div class="description">
  174. <p>How far you can move the target from the 3D <code>cursor</code>.<br/>Default is <code>Infinity</code>.</p>
  175. </div>
  176. </div>
  177. <div class="member">
  178. <h3 class="name" id="maxZoom" translate="no">.<a href="#maxZoom">maxZoom</a><span class="type-signature"> : number</span> </h3>
  179. <div class="description">
  180. <p>How far you can zoom out (orthographic camera only).<br/>Default is <code>Infinity</code>.</p>
  181. </div>
  182. </div>
  183. <div class="member">
  184. <h3 class="name" id="minAzimuthAngle" translate="no">.<a href="#minAzimuthAngle">minAzimuthAngle</a><span class="type-signature"> : number</span> </h3>
  185. <div class="description">
  186. <p>How far you can orbit horizontally, lower limit. If set, the interval <code>[ min, max ]</code>
  187. must be a sub-interval of <code>[ - 2 PI, 2 PI ]</code>, with <code>( max - min &lt; 2 PI )</code>.<br/>Default is <code>-Infinity</code>.</p>
  188. </div>
  189. </div>
  190. <div class="member">
  191. <h3 class="name" id="minDistance" translate="no">.<a href="#minDistance">minDistance</a><span class="type-signature"> : number</span> </h3>
  192. <div class="description">
  193. <p>How far you can dolly in (perspective camera only).<br/>Default is <code>0</code>.</p>
  194. </div>
  195. </div>
  196. <div class="member">
  197. <h3 class="name" id="minPolarAngle" translate="no">.<a href="#minPolarAngle">minPolarAngle</a><span class="type-signature"> : number</span> </h3>
  198. <div class="description">
  199. <p>How far you can orbit vertically, lower limit. Range is <code>[0, Math.PI]</code> radians.<br/>Default is <code>0</code>.</p>
  200. </div>
  201. </div>
  202. <div class="member">
  203. <h3 class="name" id="minTargetRadius" translate="no">.<a href="#minTargetRadius">minTargetRadius</a><span class="type-signature"> : number</span> </h3>
  204. <div class="description">
  205. <p>How close you can get the target to the 3D <code>cursor</code>.<br/>Default is <code>0</code>.</p>
  206. </div>
  207. </div>
  208. <div class="member">
  209. <h3 class="name" id="minZoom" translate="no">.<a href="#minZoom">minZoom</a><span class="type-signature"> : number</span> </h3>
  210. <div class="description">
  211. <p>How far you can zoom in (orthographic camera only).<br/>Default is <code>0</code>.</p>
  212. </div>
  213. </div>
  214. <div class="member">
  215. <h3 class="name" id="mouseButtons" translate="no">.<a href="#mouseButtons">mouseButtons</a><span class="type-signature"> : Object</span> </h3>
  216. <div class="description">
  217. <p>This object contains references to the mouse actions used by the controls.</p>
  218. <pre><code class="language-js">controls.mouseButtons = {
  219. LEFT: THREE.MOUSE.ROTATE,
  220. MIDDLE: THREE.MOUSE.DOLLY,
  221. RIGHT: THREE.MOUSE.PAN
  222. }
  223. </code></pre>
  224. </div>
  225. <dl class="details">
  226. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Controls.html#mouseButtons">Controls#mouseButtons</a></dt>
  227. </dl>
  228. </div>
  229. <div class="member">
  230. <h3 class="name" id="panSpeed" translate="no">.<a href="#panSpeed">panSpeed</a><span class="type-signature"> : number</span> </h3>
  231. <div class="description">
  232. <p>Speed of panning.<br/>Default is <code>1</code>.</p>
  233. </div>
  234. </div>
  235. <div class="member">
  236. <h3 class="name" id="position0" translate="no">.<a href="#position0">position0</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  237. <div class="description">
  238. <p>Used internally by <code>saveState()</code> and <code>reset()</code>.</p>
  239. </div>
  240. </div>
  241. <div class="member">
  242. <h3 class="name" id="rotateSpeed" translate="no">.<a href="#rotateSpeed">rotateSpeed</a><span class="type-signature"> : number</span> </h3>
  243. <div class="description">
  244. <p>Speed of rotation.<br/>Default is <code>1</code>.</p>
  245. </div>
  246. </div>
  247. <div class="member">
  248. <h3 class="name" id="screenSpacePanning" translate="no">.<a href="#screenSpacePanning">screenSpacePanning</a><span class="type-signature"> : boolean</span> </h3>
  249. <div class="description">
  250. <p>Defines how the camera's position is translated when panning. If <code>true</code>, the camera pans
  251. in screen space. Otherwise, the camera pans in the plane orthogonal to the camera's up
  252. direction.<br/>Default is <code>true</code>.</p>
  253. </div>
  254. </div>
  255. <div class="member">
  256. <h3 class="name" id="target" translate="no">.<a href="#target">target</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  257. <div class="description">
  258. <p>The focus point of the controls, the <code>object</code> orbits around this.
  259. It can be updated manually at any point to change the focus of the controls.</p>
  260. </div>
  261. </div>
  262. <div class="member">
  263. <h3 class="name" id="target0" translate="no">.<a href="#target0">target0</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  264. <div class="description">
  265. <p>Used internally by <code>saveState()</code> and <code>reset()</code>.</p>
  266. </div>
  267. </div>
  268. <div class="member">
  269. <h3 class="name" id="touches" translate="no">.<a href="#touches">touches</a><span class="type-signature"> : Object</span> </h3>
  270. <div class="description">
  271. <p>This object contains references to the touch actions used by the controls.</p>
  272. <pre><code class="language-js">controls.mouseButtons = {
  273. ONE: THREE.TOUCH.ROTATE,
  274. TWO: THREE.TOUCH.DOLLY_PAN
  275. }
  276. </code></pre>
  277. </div>
  278. <dl class="details">
  279. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Controls.html#touches">Controls#touches</a></dt>
  280. </dl>
  281. </div>
  282. <div class="member">
  283. <h3 class="name" id="zoom0" translate="no">.<a href="#zoom0">zoom0</a><span class="type-signature"> : number</span> </h3>
  284. <div class="description">
  285. <p>Used internally by <code>saveState()</code> and <code>reset()</code>.</p>
  286. </div>
  287. </div>
  288. <div class="member">
  289. <h3 class="name" id="zoomSpeed" translate="no">.<a href="#zoomSpeed">zoomSpeed</a><span class="type-signature"> : number</span> </h3>
  290. <div class="description">
  291. <p>Speed of zooming / dollying.<br/>Default is <code>1</code>.</p>
  292. </div>
  293. </div>
  294. <div class="member">
  295. <h3 class="name" id="zoomToCursor" translate="no">.<a href="#zoomToCursor">zoomToCursor</a><span class="type-signature"> : boolean</span> </h3>
  296. <div class="description">
  297. <p>Setting this property to <code>true</code> allows to zoom to the cursor's position.<br/>Default is <code>false</code>.</p>
  298. </div>
  299. </div>
  300. <h2 class="subsection-title">Methods</h2>
  301. <h3 class="name name-method" id="getAzimuthalAngle" translate="no">.<a href="#getAzimuthalAngle">getAzimuthalAngle</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  302. <div class="method">
  303. <div class="description">
  304. <p>Get the current horizontal rotation, in radians.</p>
  305. </div>
  306. <dl class="details">
  307. <dt class="tag-returns"><strong>Returns:</strong> The current horizontal rotation, in radians.</dt>
  308. </dl>
  309. </div>
  310. <h3 class="name name-method" id="getDistance" translate="no">.<a href="#getDistance">getDistance</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  311. <div class="method">
  312. <div class="description">
  313. <p>Returns the distance from the camera to the target.</p>
  314. </div>
  315. <dl class="details">
  316. <dt class="tag-returns"><strong>Returns:</strong> The distance from the camera to the target.</dt>
  317. </dl>
  318. </div>
  319. <h3 class="name name-method" id="getPolarAngle" translate="no">.<a href="#getPolarAngle">getPolarAngle</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  320. <div class="method">
  321. <div class="description">
  322. <p>Get the current vertical rotation, in radians.</p>
  323. </div>
  324. <dl class="details">
  325. <dt class="tag-returns"><strong>Returns:</strong> The current vertical rotation, in radians.</dt>
  326. </dl>
  327. </div>
  328. <h3 class="name name-method" id="listenToKeyEvents" translate="no">.<a href="#listenToKeyEvents">listenToKeyEvents</a><span class="signature">( domElement : <span class="param-type">HTMLElement</span> )</span> </h3>
  329. <div class="method">
  330. <div class="description">
  331. <p>Adds key event listeners to the given DOM element.
  332. <code>window</code> is a recommended argument for using this method.</p>
  333. </div>
  334. <table class="params">
  335. <tbody>
  336. <tr>
  337. <td class="name"><code>domElement</code></td>
  338. <td class="description last"><p>The DOM element</p></td>
  339. </tr>
  340. </tbody>
  341. </table>
  342. </div>
  343. <h3 class="name name-method" id="reset" translate="no">.<a href="#reset">reset</a><span class="signature">()</span> </h3>
  344. <div class="method">
  345. <div class="description">
  346. <p>Reset the controls to their state from either the last time the <code>saveState()</code>
  347. was called, or the initial state.</p>
  348. </div>
  349. </div>
  350. <h3 class="name name-method" id="saveState" translate="no">.<a href="#saveState">saveState</a><span class="signature">()</span> </h3>
  351. <div class="method">
  352. <div class="description">
  353. <p>Save the current state of the controls. This can later be recovered with <code>reset()</code>.</p>
  354. </div>
  355. </div>
  356. <h3 class="name name-method" id="stopListenToKeyEvents" translate="no">.<a href="#stopListenToKeyEvents">stopListenToKeyEvents</a><span class="signature">()</span> </h3>
  357. <div class="method">
  358. <div class="description">
  359. <p>Removes the key event listener previously defined with <code>listenToKeyEvents()</code>.</p>
  360. </div>
  361. </div>
  362. <h2 class="subsection-title">Events</h2>
  363. <h3 class="name name-method" id="event:change" translate="no">.<a href="#event:change">change</a> </h3>
  364. <div class="method">
  365. <div class="description">
  366. <p>Fires when the camera has been transformed by the controls.</p>
  367. </div>
  368. <h5>Type:</h5>
  369. <ul>
  370. <li>
  371. <span class="param-type">Object</span>
  372. </li>
  373. </ul>
  374. </div>
  375. <h3 class="name name-method" id="event:end" translate="no">.<a href="#event:end">end</a> </h3>
  376. <div class="method">
  377. <div class="description">
  378. <p>Fires when an interaction has finished.</p>
  379. </div>
  380. <h5>Type:</h5>
  381. <ul>
  382. <li>
  383. <span class="param-type">Object</span>
  384. </li>
  385. </ul>
  386. </div>
  387. <h3 class="name name-method" id="event:start" translate="no">.<a href="#event:start">start</a> </h3>
  388. <div class="method">
  389. <div class="description">
  390. <p>Fires when an interaction was initiated.</p>
  391. </div>
  392. <h5>Type:</h5>
  393. <ul>
  394. <li>
  395. <span class="param-type">Object</span>
  396. </li>
  397. </ul>
  398. </div>
  399. <h2 class="subsection-title">Source</h2>
  400. <p>
  401. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/OrbitControls.js" target="_blank" rel="noopener" translate="no">examples/jsm/controls/OrbitControls.js</a>
  402. </p>
  403. </article>
  404. </section>
  405. <script src="../scripts/linenumber.js"></script>
  406. <script src="../scripts/page.js"></script>
  407. </body>
  408. </html>
粤ICP备19079148号