1
0

ArcballControls.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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:Controls] &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. (optional)<br><br>
  59. [page:Scene scene]: The scene rendered by the camera. If not given, gizmos cannot be shown. (optional)
  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. <p>See the base [page:Controls] class for common properties.</p>
  76. <h3>[property:Boolean adjustNearFar]</h3>
  77. <p>
  78. If true, camera's near and far values will be adjusted every time zoom is performed trying to mantain the same visible portion
  79. given by initial near and far values ( [page:PerspectiveCamera] only ).
  80. Default is false.
  81. </p>
  82. <h3>[property:Camera camera]</h3>
  83. <p>
  84. The camera being controlled.
  85. </p>
  86. <h3>[property:Boolean cursorZoom]</h3>
  87. <p>
  88. Set to true to make zoom become cursor centered.
  89. </p>
  90. <h3>
  91. [property:Float dampingFactor]</h3>
  92. <p>
  93. The damping inertia used if [page:.enableAnimations] is set to true.
  94. </p>
  95. <h3>[property:Boolean enableAnimations]</h3>
  96. <p>
  97. Set to true to enable animations for rotation (damping) and focus operation. Default is true.
  98. </p>
  99. <h3>[property:Boolean enableGrid]</h3>
  100. <p>
  101. When set to true, a grid will appear when panning operation is being performed (desktop interaction only). Default is false.
  102. </p>
  103. <h3>[property:Boolean enablePan]</h3>
  104. <p>
  105. Enable or disable camera panning. Default is true.
  106. </p>
  107. <h3>[property:Boolean enableRotate]</h3>
  108. <p>
  109. Enable or disable camera rotation. Default is true.
  110. </p>
  111. <h3>[property:Boolean enableZoom]</h3>
  112. <p>
  113. Enable or disable zooming of the camera.
  114. </p>
  115. <h3>[property:Float focusAnimationTime]</h3>
  116. <p>
  117. Duration time of focus animation.
  118. </p>
  119. <h3>[property:Float maxDistance]</h3>
  120. <p>
  121. How far you can dolly out ( [page:PerspectiveCamera] only ). Default is Infinity.
  122. </p>
  123. <h3>[property:Float maxZoom]</h3>
  124. <p>
  125. How far you can zoom out ( [page:OrthographicCamera] only ). Default is Infinity.
  126. </p>
  127. <h3>[property:Float minDistance]</h3>
  128. <p>
  129. How far you can dolly in ( [page:PerspectiveCamera] only ). Default is 0.
  130. </p>
  131. <h3>[property:Float minZoom]</h3>
  132. <p>
  133. How far you can zoom in ( [page:OrthographicCamera] only ). Default is 0.
  134. </p>
  135. <h3>[property:Float radiusFactor]</h3>
  136. <p>
  137. The size of the gizmo relative to the screen width and height. Default is 0.67.
  138. </p>
  139. <h3>[property:Float rotateSpeed]</h3>
  140. <p>
  141. Speed of rotation. Default is 1.
  142. </p>
  143. <h3>[property:Float scaleFactor]</h3>
  144. <p>
  145. The scaling factor used when performing zoom operation.
  146. </p>
  147. <h3>[property:Scene scene]</h3>
  148. <p>
  149. The scene rendered by the camera.
  150. </p>
  151. <h3>[property:Float wMax]</h3>
  152. <p>
  153. Maximum angular velocity allowed on rotation animation start.
  154. </p>
  155. <h2>Methods</h2>
  156. <p>See the base [page:Controls] class for common methods.</p>
  157. <h3>[method:undefined activateGizmos] ( [param:Boolean isActive] )</h3>
  158. <p>
  159. Make gizmos more or less visible.
  160. </p>
  161. <h3>[method:undefined copyState] ()</h3>
  162. <p>
  163. Copy the current state to clipboard (as a readable JSON text).
  164. </p>
  165. <h3>[method:undefined pasteState] ()</h3>
  166. <p>
  167. Set the controls state from the clipboard, assumes that the clipboard stores a JSON text as saved from [page:.copyState].
  168. </p>
  169. <h3>[method:undefined reset] ()</h3>
  170. <p>
  171. Reset the controls to their state from either the last time the [page:.saveState] was called, or the initial state.
  172. </p>
  173. <h3>[method:undefined saveState] ()</h3>
  174. <p>
  175. Save the current state of the controls. This can later be recovered with [page:.reset].
  176. </p>
  177. <h3>[method:undefined setCamera] ( [param:Camera camera] )</h3>
  178. <p>
  179. Set the camera to be controlled. Must be called in order to set a new camera to be controlled.
  180. </p>
  181. <h3>[method:undefined setGizmosVisible] ( [param:Boolean value] )</h3>
  182. <p>
  183. Set the visible property of gizmos.
  184. </p>
  185. <h3>[method:undefined setTbRadius] ( [param:Float value] )</h3>
  186. <p>
  187. Update the `radiusFactor` value, redraw the gizmo and send a `changeEvent` to visualise the changes.
  188. </p>
  189. <h3>[method:Boolean setMouseAction] ( [param:String operation], mouse, key )</h3>
  190. <p>
  191. 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>
  192. Operations can be specified as 'ROTATE', 'PAN', 'FOV' or 'ZOOM'.<br>
  193. Mouse inputs can be specified as mouse buttons 0, 1 and 2 or 'WHEEL' for wheel notches.<br>
  194. Keyboard modifiers can be specified as 'CTRL', 'SHIFT' or null if not needed.
  195. </p>
  196. <h3>[method:Boolean unsetMouseAction] ( mouse, key )</h3>
  197. <p>
  198. Removes a mouse action by specifying its mouse/key combination.<br><br>
  199. Mouse inputs can be specified as mouse buttons 0, 1 and 2 or 'WHEEL' for wheel notches.<br>
  200. Keyboard modifiers can be specified as 'CTRL', 'SHIFT' or null if not needed.
  201. </p>
  202. <h3>[method:Raycaster getRaycaster] ()</h3>
  203. <p>
  204. Returns the [page:Raycaster] object that is used for user interaction. This object is shared between all instances of
  205. ArcballControls. If you set the [page:Object3D.layers .layers] property of the [name], you will also want to
  206. set the [page:Raycaster.layers .layers] property on the [page:Raycaster] with a matching value, or else the [name]
  207. won't work as expected.
  208. </p>
  209. <h2>Source</h2>
  210. <p>
  211. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/ArcballControls.js examples/jsm/controls/ArcballControls.js]
  212. </p>
  213. </body>
  214. </html>