Dwarves
Memo
Type ESC to close search bar

Cameras in ThreeJS

ThreeJS is a JavaScript 3D library that allows developers to develop and describe data in 3 dimensions, and then convert them into 2 dimensions and display them on HTML Canvas. Camera is one of the core elements of a ThreeJS project, beside Scene, Renderer and 3D objects (can be formed with Geometries and Materials).

This article gives basic information about characteristics of the frequently used types of camera in ThreeJS.

Most commonly used types of camera in ThreeJS

You cannot use the Camera class directly to initialize a new camera in ThreeJS. Instead, use the PerspectiveCamera or OrthographicCamera specifically. The perspective camera gives information about depth, distances, etc. since it represents perspective in real life. On the other hand, with an orthographic camera, all sizes are projected the same way and we can easily compare them accurately.

The image below shows the object viewed in perspective camera (upper) and in orthographic camera (lower).

Place them into the Oxyz coordinate…

Perspective camera

Some crucial attributes:

const camera = new THREE.PerspectiveCamera(45, 16 / 9, 1, 1000)
scene.add(camera)

In the example above, a perspective camera is initialized with fov of 45 degree, aspect-ratio of 16 / 9, near and far of 1 and 1000 respectively.

Perspective camera visualization from r105.threejsfundamentals.org with CameraHelper:

Orthographic camera

Some crucial attributes:

const camera = new THREE.OrthographicCamera(-2, 2, 1, -1, 1, 1000)
scene.add(camera)

In the example above, an orthographic camera is initialized with left, right, top and bottom equal -2, 2, 1 and -1 respectively. The last 2 numbers represent near and far.

Orthographic camera visualization from r105.threejsfundamentals.org with CameraHelper:

Other types of camera

Beside those 2 most frequently used cameras, ThreeJS also provides various options:

Reference