Skip to main content

How It Works

Rendering is managed through a collection of RenderView instances, which are internally handled within the Main class.

ℹ️ Note
You can access the WebGLRenderer instance using the renderer property of the Main class.

RenderView

To create and add instances of RenderView to this collection, you can utilize the createView method of the Main object. This method accepts the following parameters:

ParameterTypeDescription
backgroundAlphanumberBackground alpha value of the view (optional, default: 1).
backgroundColorColorRepresentationBackground color of the view (optional, default: 'black').
cameraCameraCamera used to view the scene (avoid using the same camera for different scenes).
composerEffectComposerEffect composer used for post-processing (optional).
enabledbooleanDetermines whether InteractionEvents will be triggered for the view (optional, default: true).
onAfterRender() => voidFunction called after rendering the view (optional).
onBeforeRender() => voidFunction called before rendering the view (optional).
sceneSceneScene rendered in the view.
tagsstring[]Tags of the view (optional).
viewportViewportNormalized viewport defining dimensions and position of the view (optional). Values range from 0 to 1.
visiblebooleanDetermines if the view is visible (optional, default: true).

ℹ️ Note
You can access the documentation for the RenderView class here.

⚠️ Warning
Manually creating instances of RenderView is not recommended.

Viewport

The Viewport object has the following properties:

ParameterTypeDescription
bottomnumberBottom coordinate of the viewport.
heightnumberHeight of the viewport.
leftnumberLeft coordinate of the viewport.
widthnumberWidth of the viewport.

Example

const main = new Main();
main.createView({
scene: sceneObj, // Mandatory
camera: cameraObj, // Mandatory
backgroundAlpha: 1,
backgroundColor: 'black',
composer: composerObj,
enabled: true,
onAfterRender: () => {
/** Code */
},
onBeforeRender: () => {
/** Code */
},
tags: ['A', 'B'],
visible: true,
viewport: {
bottom: 0,
height: 1,
left: 0,
width: 1
}
});

Live Examples

⚡ Stackblitz - Template
⚡ Stackblitz - Multiple Views
⚡ Stackblitz - Focus Outline (EffectComposer)