Initializing Components

Render Controller

Render Controller handles the rendering pipeline - It takes textures from the cameras setup , processes them and renders the final output onto the specified canvas.
1
/* We query the canvas where the output has to be displayed and pass
2
along with its webgl context to the Render Controller */
3
4
var canvaswgl = document.querySelector("#canvas");
5
var gl = canvaswgl.getContext("webgl", {preserveDrawingBuffer : true});
6
var convergenceDistance = 20;
7
8
const controller = RenderController;
9
controller.initialize(canvaswgl, gl, window);
10
controller.setConvergence(convergenceDistance);
Copied!
Render Controller expects
  1. 1.
    Canvas where the output has to be rendered
  2. 2.
    WebGL context of the output canvas
  3. 3.
    Window object
  4. 4.
    Convergence distance
This initialization can be done once on launch along with your framework initialization.

Cameras and Projections Matrices

Depending on the device the application is being developed for , the scene typically requires 4 to N cameras to be setup. The positions and the projection matrices of these cameras can be queried from the SDK while setting up. Before the cameras are setup.
1
var cameraPositions = controller.getCameraPositions();
2
3
for(var i = 0 ; i < cameraPositions.length ; i++)
4
{
5
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
6
camera.position.set(cameraPositions[i], 4, 20);
7
cameras.push(camera);
8
scene.add(camera);
9
}
Copied!
The projection matrices in from SDK vary with the camera type, so the type of the camera has to be specified while querying 'perspective' or 'orthographic' for the projection matrices. These projection matrices can be set to the cameras that were initially setup
1
2
let projectionMatrices = controller.getProjectionMatrices(camType);
3
for(let i = 0; i<projectionMatrices.length; i++) {
4
let matrix = new THREE.Matrix4();
5
matrix.elements = projectionMatrices[i];
6
cameras[i].projectionMatrix = matrix.clone();
7
cameras[i].projectionMatrixInverse = matrix.clone().invert();
8
}
9
Copied!

Render Textures

Once the cameras are setup, a render texture can be created to render the camera output and passed on to the SDK
The width and height of the render texture can be queried from the SDK as follows
1
RenderController.setupCanvas(gl);
2
const rtWidth = controller.getRenderTextureWidth();
3
const rtHeight = controller.getRenderTextureHeight();
4
const renderTarget = new THREE.WebGLRenderTarget(rtWidth,rtHeight);
Copied!
Last modified 1mo ago