Capítulo 306 de 859

Chapter 306: ArcballControls

Core Idea

Arcball controls allow the camera to be controlled by a virtual trackball with full touch support and advanced navigation functionality. Cursor/finger positions and movements are mapped over a virtual trackball surface represented by a gizmo and mapped in intuitive and consistent camera movements. Dragging cursor/fingers will cause camera to orbit around the center of the trackball in a conservative way (returning to the starting point will make the camera return to its starting orientation).

In addition to supporting pan, zoom and pinch gestures, double clicking/tapping focuses on a point, intuitively moving the object's point of interest to the center of the virtual trackball. Focus allows a much better inspection and navigation in complex environment. Moreover Arcball controls allow FOV manipulation (in a vertigo-style method) and z-rotation. Saving and restoring of Camera State is supported also through clipboard (use ctrl+c and ctrl+v shortcuts for copy and paste the state).

Unlike OrbitControls and TrackballControls, ArcballControls doesn't require update() to be called externally in an animation loop when animations are on.

Key Concepts

  • adjustNearFar : boolean: If set to true, the camera's near and far values will be adjusted every time zoom is performed trying to maintain the same visible portio…
  • cursorZoom : boolean: Set to true to make zoom become cursor centered.
  • dampingFactor : number: The damping inertia used if 'enableAnimationsis set totrue`.
  • enableAnimations : boolean: Set to true to enable animations for rotation (damping) and focus operation.
  • enableFocus : boolean: Enable or disable camera focusing on double-tap (or click) operations.
  • enableGizmos : boolean: Enable or disable gizmos.
  • enableGrid : boolean: If set to true, a grid will appear when panning operation is being performed (desktop interaction only).
  • enablePan : boolean: Enable or disable camera panning.
  • enableRotate : boolean: Enable or disable camera rotation.
  • enableZoom : boolean: Enable or disable camera zoom.

Code Examples

import { ArcballControls } from 'three/addons/controls/ArcballControls.js';
  • What it demonstrates: Typical usage of ArcballControls.

Reference Tables

Constructor

Signature
new ArcballControls( camera : Camera, domElement : HTMLElement, scene : Scene )

Properties

PropertyDescription
.adjustNearFar : booleanIf set to true, the camera's near and far values will be adjusted every time zoom is performed trying to maintain the same visible portion given by initial near and far values. Only works with pers…
.cursorZoom : booleanSet to true to make zoom become cursor centered.
.dampingFactor : numberThe damping inertia used if 'enableAnimationsis set totrue`.
.enableAnimations : booleanSet to true to enable animations for rotation (damping) and focus operation.
.enableFocus : booleanEnable or disable camera focusing on double-tap (or click) operations.
.enableGizmos : booleanEnable or disable gizmos.
.enableGrid : booleanIf set to true, a grid will appear when panning operation is being performed (desktop interaction only).
.enablePan : booleanEnable or disable camera panning.
.enableRotate : booleanEnable or disable camera rotation.
.enableZoom : booleanEnable or disable camera zoom.
.focusAnimationTime : numberDuration of focus animations in ms.
.maxDistance : numberHow far you can dolly out. For perspective cameras only.
.maxFov : numberThe maximum FOV in degrees.
.maxZoom : numberHow far you can zoom out. For orthographic cameras only.
.minDistance : numberHow far you can dolly in. For perspective cameras only.
.minFov : numberThe minimum FOV in degrees.
.minZoom : numberHow far you can zoom in. For orthographic cameras only.
.mouseActions : Array.<Object>Holds the mouse actions of this controls. This property is maintained by the methods setMouseAction() and unsetMouseAction().
.radiusFactor : numberThe size of the gizmo relative to the screen width and height.
.rotateSpeed : numberSpeed of rotation.
.scaleFactor : numberThe scaling factor used when performing zoom operation.
.scene : SceneThe scene rendered by the camera. If not given, gizmos cannot be shown.
.target : Vector3The control's focus point.
.wMax : numberMaximum angular velocity allowed on rotation animation start.

Methods

MethodDescription
.activateGizmos( isActive : boolean )Makes rotation gizmos more or less visible.
.copyState()Copy the current state to clipboard (as a readable JSON text).
.disposeGrid()Removes the grid from the scene.
.getRaycaster() : RaycasterReturns the raycaster that is used for user interaction. This object is shared between all instances of ArcballControls.
.pasteState()Set the controls state from the clipboard, assumes that the clipboard stores a JSON text as saved from copyState().
.reset()Resets the controls.
.saveState()Saves the current state of the control. This can later be recover with reset().
.setCamera( camera : Camera )Sets the camera to be controlled. Must be called in order to set a new camera to be controlled.
.setGizmosVisible( value : boolean )Sets gizmos visibility.
`.setMouseAction( operation : 'PAN''ROTATE'
.setTbRadius( value : number )Sets gizmos radius factor and redraws gizmos.
`.unsetMouseAction( mouse : 01

Key Takeaways

  1. ArcballControls extends: EventDispatcher → Controls
  2. Most relevant properties: adjustNearFar, cursorZoom, dampingFactor, enableAnimations.
  3. Key methods: activateGizmos, copyState, disposeGrid, getRaycaster.

Connects To