API

MultiViews Part 2

How to use Multi-Views

Babylon.js can render multiple views of the same scene.

Active cameras

A scene has an activeCamera property that defines the point of view. But you can define multiple active cameras using code like this:

scene.activeCameras.push(camera);
scene.activeCameras.push(camera2);

Viewports

If you want to use multiple cameras, you will need to specify a viewport for each camera:

import { Viewport } from "@babylonjs/core/Maths/math.viewport";
camera.viewport = new Viewport(0.5, 0, 0.5, 1.0);
camera2.viewport = new Viewport(0, 0, 0.5, 1.0);

A viewport is defined by the following constructor:

import { Viewport } from "@babylonjs/core/Maths/math.viewport";
Viewport = function (x, y, width, height);

where x and y define the lower-left corner of the viewport, followed by its width and height. Values for x, y, width, and height are numbers between 0 and 1, representing the fraction of the screen width and height, respectively.

Viewport Example