The Camera.clone()
method creates a new camera object that is a copy of the original camera. This is useful when you need to work with multiple cameras with different settings, but you don't want to modify the original camera object.
camera.clone();
The clone()
method returns a new instance of the Camera
object that is a copy of the original camera.
var originalCamera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
var clonedCamera = originalCamera.clone();
// Modify the cloned camera's position
clonedCamera.position.set(0, 0, 50);
// Use the original camera for the main rendering loop
renderer.render(scene, originalCamera);
// Use the cloned camera for a secondary view
renderer.render(scene, clonedCamera);
In this example, we create an original PerspectiveCamera
object and a new camera object that is a clone of the original. We then modify the new camera's position and use it to render the scene in a secondary view. The original camera remains unchanged and is used for the main rendering loop.
The clone()
method creates a deep copy of the camera object, which means that any changes made to the cloned camera will not affect the original camera, and vice versa.
This method is available for all camera types in Three.js.