OrbitControls

Orbit controls allow the camera to orbit around a target object.

Example

misc / controls / orbit
var renderer = new v3d.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); var scene = new v3d.Scene(); var camera = new v3d.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000); var controls = new v3d.OrbitControls(camera); //controls.update() must be called after any manual changes to the camera's transform camera.position.set(0, 20, 100); controls.update(); function animate() { requestAnimationFrame(animate); // required if controls.enableDamping or controls.autoRotate are set to true controls.update(); renderer.render(scene, camera); }

Constructor

OrbitControls(object, domElement)

object: (required) The camera to be controlled.

domElement: (optional) The HTML element used for event listeners. By default this is the whole document, however if you only want to the controls to work over a specific element (e.g. the canvas) you can specify that here.

Properties

.autoRotate undefined : Boolean

Set to true to automatically rotate around the target object.
Note that if this is enabled, you must call .update () in your animation loop.

.autoRotateSpeed undefined : Float

How fast to rotate around the target object if .autoRotate undefined : Booleanis true. Default is 2.0, which equates to 30 seconds per rotation at 60fps.
Note that if .autoRotate undefined : Booleanis enabled, you must call .update () in your animation loop.

.dampingFactor undefined : Float

The damping inertia used if .enableDamping undefined : Booleanis set to true.
Note that for this to work, you must call .update () in your animation loop.

.domElement undefined : HTMLDOMElement

The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will not set up new event listeners. Default is the whole document.

.enabled undefined : Boolean

Whether or not the controls are enabled.

.enableDamping undefined : Boolean

Set to true to enable damping (inertia), which can be used to give a sense of weight to the controls. Default is false.
Note that if this is enabled, you must call .update () in your animation loop.

.enableKeys undefined : Boolean

Enable or disable the use of keyboard controls.

.enablePan undefined : Boolean

Enable or disable camera panning. Default is true.

.enableRotate undefined : Boolean

Enable or disable horizontal and vertical rotation of the camera. Default is true.
Note that it is possible to disable a single axis by setting the min and max of the polar angle or azimuth angle to the same value, which will cause the vertical or horizontal rotation to be fixed at that value.

.enableZoom undefined : Boolean

Enable or disable zooming (dollying) of the camera.

.keyPanSpeed undefined : Float

How fast to pan the camera when the keyboard is used. Default is 7.0 pixels per keypress.

.keys undefined : Object

This object contains references to the keycodes for controlling camera panning. Default is the 4 arrow keys. controls.keys = { LEFT: 37, //left arrow UP: 38, // up arrow RIGHT: 39, // right arrow BOTTOM: 40 // down arrow } See this page for a full list of keycodes.

.maxAzimuthAngle undefined : Float

How far you can orbit horizontally, upper limit. Range is - Math.PI to Math.PI (or Infinity for no limit) and default is Infinity;

.maxDistance undefined : Float

How far you can dolly out (PerspectiveCamera only). Default is Infinity.

.maxPolarAngle undefined : Float

How far you can orbit vertically, upper limit. Range is 0 to Math.PI radians, and default is Math.PI.

.maxZoom undefined : Float

How far you can zoom out (OrthographicCamera only). Default is Infinity.

.minAzimuthAngle undefined : Float

How far you can orbit horizontally, lower limit. Range is - Math.PI to Math.PI (or - Infinity for no limit) and default is - Infinity;

.minDistance undefined : Float

How far you can dolly in (PerspectiveCamera only). Default is 0.

.minPolarAngle undefined : Float

How far you can orbit vertically, lower limit. Range is 0 to Math.PI radians, and default is 0.

.minZoom undefined : Float

How far you can zoom in (OrthographicCamera only). Default is 0.

.mouseButtons undefined : Object

This object contains references to the mouse buttons used for the controls. controls.mouseButtons = { ROTATE: v3d.MOUSE.LEFT, ZOOM: v3d.MOUSE.MIDDLE, PAN: v3d.MOUSE.RIGHT }

.object undefined : Camera

The camera (or other object) that is being controlled.

.position0 undefined : Vector3

Used internally by the .saveState and .reset methods.

.rotateSpeed undefined : Float

Speed of rotation. Default is 1.

.target0 undefined : Vector3

Used internally by the .saveState and .reset methods.

.targetObj undefined : Object3D

An Object3D which position in the world space acts as the focus point of the controls, the .object orbits around this. It can be updated manually at any point to change the focus of the controls.

.zoom0 undefined : Float

Used internally by the .saveState and .reset methods.

.zoomSpeed undefined : Float

Speed of zooming / dollying. Default is 1.

Methods

.dispose () : null

Remove all the event listeners.

.getAzimuthalAngle () : radians

Get the current horizontal rotation, in radians.

.getPolarAngle () : radians

Get the current vertical rotation, in radians.

.reset () : null

Reset the controls to their state from either the last time the .saveState was called, or the initial state.

.saveState () : null

Save the current state of the controls. This can later be recovered with .reset.

.update () : false

Update the controls. Must be called after any manual changes to the camera's transform, or in the update loop if .autoRotate or .enableDamping are set.

Source

For more info on how to obtain the source code of this module see this page.