ArcballControls.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:EventDispatcher] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. Arcball controls allow the camera to be controlled by a virtual trackball with full touch support and advanced navigation functionality. <br>
  14. Cursor/finger positions and movements are mapped over a virtual trackball surface
  15. represented by a gizmo and mapped in intuitive and consistent camera movements.
  16. Dragging cursor/fingers will cause camera to orbit around the center of the trackball in a conservative way (returning to the starting point
  17. will make the camera to return to its starting orientation).<br><br>
  18. In addition to supporting pan, zoom and pinch gestures, Arcball controls provide <i>focus</i> functionality with a double click/tap for
  19. intuitively moving the object's point of interest in the center of the virtual trackball.
  20. Focus allows a much better inspection and navigation in complex environment.
  21. Moreover Arcball controls allow FOV manipulation (in a vertigo-style method) and z-rotation.
  22. Saving and restoring of Camera State is supported also through clipboard
  23. (use ctrl+c and ctrl+v shortcuts for copy and paste the state).<br><br>
  24. Unlike [page:OrbitControls] and [page:TrackballControls], [name] doesn't require [page:.update] to be called externally in an animation loop when animations
  25. are on.<br><br>
  26. To use this, as with all files in the /examples directory, you will have to
  27. include the file separately in your HTML.
  28. </p>
  29. <h2>Import</h2>
  30. <p>
  31. [name] is an add-on, and must be imported explicitly.
  32. See [link:#manual/introduction/Installation Installation / Addons].
  33. </p>
  34. <code>
  35. import { ArcballControls } from 'three/addons/controls/ArcballControls.js';
  36. </code>
  37. <h2>Code Example</h2>
  38. <code>
  39. const renderer = new THREE.WebGLRenderer();
  40. renderer.setSize( window.innerWidth, window.innerHeight );
  41. document.body.appendChild( renderer.domElement );
  42. const scene = new THREE.Scene();
  43. const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
  44. const controls = new ArcballControls( camera, renderer.domElement, scene );
  45. controls.addEventListener( 'change', function () {
  46. renderer.render( scene, camera );
  47. } );
  48. //controls.update() must be called after any manual changes to the camera's transform
  49. camera.position.set( 0, 20, 100 );
  50. controls.update();
  51. </code>
  52. <h2>Examples</h2>
  53. <p>[example:misc_controls_arcball misc / controls / arcball ]</p>
  54. <h2>Constructor</h2>
  55. <h3>[name]( [param:Camera camera], [param:HTMLDOMElement domElement], [param:Scene scene] )</h3>
  56. <p>
  57. [page:Camera camera]: (required) The camera to be controlled. The camera must not be a child of another object, unless that object is the scene itself.<br><br>
  58. [page:HTMLDOMElement domElement]: The HTML element used for event listeners.<br><br>
  59. [page:Scene scene]: The scene rendered by the camera. If not given, gizmos cannot be shown.
  60. </p>
  61. <h2>Events</h2>
  62. <h3>change</h3>
  63. <p>
  64. Fires when the camera has been transformed by the controls.
  65. </p>
  66. <h3>start</h3>
  67. <p>
  68. Fires when an interaction was initiated.
  69. </p>
  70. <h3>end</h3>
  71. <p>
  72. Fires when an interaction has finished.
  73. </p>
  74. <h2>Properties</h2>
  75. <h3>[property:Boolean adjustNearFar]</h3>
  76. <p>
  77. If true, camera's near and far values will be adjusted every time zoom is performed trying to mantain the same visible portion
  78. given by initial near and far values ( [page:PerspectiveCamera] only ).
  79. Default is false.
  80. </p>
  81. <h3>[property:Camera camera]</h3>
  82. <p>
  83. The camera being controlled.
  84. </p>
  85. <h3>[property:Boolean cursorZoom]</h3>
  86. <p>
  87. Set to true to make zoom become cursor centered.
  88. </p>
  89. <h3>
  90. [property:Float dampingFactor]</h3>
  91. <p>
  92. The damping inertia used if [page:.enableAnimations] is set to true.
  93. </p>
  94. <h3>[property:HTMLDOMElement domElement]</h3>
  95. <p>
  96. The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will
  97. not set up new event listeners.
  98. </p>
  99. <h3>[property:Boolean enabled]</h3>
  100. <p>
  101. When set to `false`, the controls will not respond to user input. Default is `true`.
  102. </p>
  103. <h3>[property:Boolean enableAnimations]</h3>
  104. <p>
  105. Set to true to enable animations for rotation (damping) and focus operation. Default is true.
  106. </p>
  107. <h3>[property:Boolean enableGrid]</h3>
  108. <p>
  109. When set to true, a grid will appear when panning operation is being performed (desktop interaction only). Default is false.
  110. </p>
  111. <h3>[property:Boolean enablePan]</h3>
  112. <p>
  113. Enable or disable camera panning. Default is true.
  114. </p>
  115. <h3>[property:Boolean enableRotate]</h3>
  116. <p>
  117. Enable or disable camera rotation. Default is true.
  118. </p>
  119. <h3>[property:Boolean enableZoom]</h3>
  120. <p>
  121. Enable or disable zooming of the camera.
  122. </p>
  123. <h3>[property:Float focusAnimationTime]</h3>
  124. <p>
  125. Duration time of focus animation.
  126. </p>
  127. <h3>[property:Float maxDistance]</h3>
  128. <p>
  129. How far you can dolly out ( [page:PerspectiveCamera] only ). Default is Infinity.
  130. </p>
  131. <h3>[property:Float maxZoom]</h3>
  132. <p>
  133. How far you can zoom out ( [page:OrthographicCamera] only ). Default is Infinity.
  134. </p>
  135. <h3>[property:Float minDistance]</h3>
  136. <p>
  137. How far you can dolly in ( [page:PerspectiveCamera] only ). Default is 0.
  138. </p>
  139. <h3>[property:Float minZoom]</h3>
  140. <p>
  141. How far you can zoom in ( [page:OrthographicCamera] only ). Default is 0.
  142. </p>
  143. <h3>[property:Float radiusFactor]</h3>
  144. <p>
  145. The size of the gizmo relative to the screen width and height. Default is 0.67.
  146. </p>
  147. <h3>[property:Float rotateSpeed]</h3>
  148. <p>
  149. Speed of rotation. Default is 1.
  150. </p>
  151. <h3>[property:Float scaleFactor]</h3>
  152. <p>
  153. The scaling factor used when performing zoom operation.
  154. </p>
  155. <h3>[property:Scene scene]</h3>
  156. <p>
  157. The scene rendered by the camera.
  158. </p>
  159. <h3>[property:Float wMax]</h3>
  160. <p>
  161. Maximum angular velocity allowed on rotation animation start.
  162. </p>
  163. <h2>Methods</h2>
  164. <h3>[method:undefined activateGizmos] ( [param:Boolean isActive] )</h3>
  165. <p>
  166. Make gizmos more or less visible.
  167. </p>
  168. <h3>[method:undefined copyState] ()</h3>
  169. <p>
  170. Copy the current state to clipboard (as a readable JSON text).
  171. </p>
  172. <h3>[method:undefined dispose] ()</h3>
  173. <p>
  174. Remove all the event listeners, cancel any pending animation and clean the scene from gizmos and grid.
  175. </p>
  176. <h3>[method:undefined pasteState] ()</h3>
  177. <p>
  178. Set the controls state from the clipboard, assumes that the clipboard stores a JSON text as saved from [page:.copyState].
  179. </p>
  180. <h3>[method:undefined reset] ()</h3>
  181. <p>
  182. Reset the controls to their state from either the last time the [page:.saveState] was called, or the initial state.
  183. </p>
  184. <h3>[method:undefined saveState] ()</h3>
  185. <p>
  186. Save the current state of the controls. This can later be recovered with [page:.reset].
  187. </p>
  188. <h3>[method:undefined setCamera] ( [param:Camera camera] )</h3>
  189. <p>
  190. Set the camera to be controlled. Must be called in order to set a new camera to be controlled.
  191. </p>
  192. <h3>[method:undefined setGizmosVisible] ( [param:Boolean value] )</h3>
  193. <p>
  194. Set the visible property of gizmos.
  195. </p>
  196. <h3>[method:undefined setTbRadius] ( [param:Float value] )</h3>
  197. <p>
  198. Update the `radiusFactor` value, redraw the gizmo and send a `changeEvent` to visualise the changes.
  199. </p>
  200. <h3>[method:Boolean setMouseAction] ( [param:String operation], mouse, key )</h3>
  201. <p>
  202. Set a new mouse action by specifying the operation to be performed and a mouse/key combination. In case of conflict, replaces the existing one.<br><br>
  203. Operations can be specified as 'ROTATE', 'PAN', 'FOV' or 'ZOOM'.<br>
  204. Mouse inputs can be specified as mouse buttons 0, 1 and 2 or 'WHEEL' for wheel notches.<br>
  205. Keyboard modifiers can be specified as 'CTRL', 'SHIFT' or null if not needed.
  206. </p>
  207. <h3>[method:Boolean unsetMouseAction] ( mouse, key )</h3>
  208. <p>
  209. Removes a mouse action by specifying its mouse/key combination.<br><br>
  210. Mouse inputs can be specified as mouse buttons 0, 1 and 2 or 'WHEEL' for wheel notches.<br>
  211. Keyboard modifiers can be specified as 'CTRL', 'SHIFT' or null if not needed.
  212. </p>
  213. <h3>[method:undefined update] ()</h3>
  214. <p>
  215. Update the controls. Must be called after any manual changes to the camera's transform.
  216. </p>
  217. <h3>[method:Raycaster getRaycaster] ()</h3>
  218. <p>
  219. Returns the [page:Raycaster] object that is used for user interaction. This object is shared between all instances of
  220. ArcballControls. If you set the [page:Object3D.layers .layers] property of the [name], you will also want to
  221. set the [page:Raycaster.layers .layers] property on the [page:Raycaster] with a matching value, or else the [name]
  222. won't work as expected.
  223. </p>
  224. <h2>Source</h2>
  225. <p>
  226. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/ArcballControls.js examples/jsm/controls/ArcballControls.js]
  227. </p>
  228. </body>
  229. </html>