ThreeJsViewerCamera
Introduction
The ThreeJsViewerCamera class extends the THREE.PerspectiveCamera from the Three.js library. It provides additional functionality for managing the camera within a Three.js scene, including integration with OrbitControls for interactive camera manipulation.
Getting started
Javascript
The ThreeJsViewerCamera class can be instantiated directly and is typically used as part of a Three.js scene setup. In the ThreeJsViewer class, the camera is automatically created and managed by the camera manager like so:
this._cameraManager = new ThreeJsViewerCamera(this._renderer, {
aspectRatio: this.$el.clientWidth / this.$el.clientHeight,
fov: args.camera.fov,
near: args.camera.near,
far: args.camera.far,
orbitControlProps: args.camera.orbitControlProps,
});
API
constructor(renderer, args = {fov, near, far, orbitControlProps})
The constructor method initialises the new ThreeJsViewerCamera instance.
Parameters
renderer: A Three.js renderer instance that is used to render the scene.args: The configuration object used by the constructor to initialise the ThreeJsViewerCamera in the desired way.fov: The field of view of the camera. Default is35.near: The near clipping plane of the camera. Default is0.1.far: The far clipping plane of the camera. Default is100.orbitControlProps: An object that contains the configuration for theOrbitControlsinstance. Default is{}.
Methods
update()
The update method is called every frame and is used to update the camera and its controls.
resize()
The resize method is used to update the camera aspect ratio when the window is resized.
Getters & Setters
setPosition(x, y, z)
The setPosition method is used to set the position of the camera.
getCameraPosition()
The getCameraPosition method is used to get the position of the camera.
getCameraRotation()
The getCameraRotation method is used to get the rotation of the camera.
External dependencies
- Three.js: The main library used to create the 3D scene.