Skip to main content

Class: SceneRenderer<ResultT, SceneT>

@geenee/armature.SceneRenderer

Generic scene renderer

Extends VideoRenderer to be used with the particular WebGL engine e.g. Babylon.js or Three.js. Type of the scene is additional parametrization of generic. ScenePlugin written for WebGL engine can be attached to a SceneRenderer. Usually they perform simple scene tasks that can be separated from the main context into atomic building blocks, for example control node of a scene to follow (be attached to) user's head or replace its geometry with detected face mesh (mask effect).

Type parameters

NameTypeDescription
ResultTextends Object = {}Type of processing results
SceneTundefinedType of renderer's scene

Hierarchy

Constructors

constructor

new SceneRenderer<ResultT, SceneT>(params)

Constructor

Type parameters

NameType
ResultTextends Object = {}
SceneTundefined

Parameters

NameTypeDescription
paramsCanvasParamsParameters of responsive canvas

Inherited from

ShaderRenderer.constructor

Properties

cameraAngle

Protected cameraAngle: number

Camera vertical angle in radians

Inherited from

ShaderRenderer.cameraAngle


cameraRatio

Protected cameraRatio: number

Camera aspect ratio

Inherited from

ShaderRenderer.cameraRatio


canvas

canvas: ResponsiveCanvas

Responsive canvas

Inherited from

ShaderRenderer.canvas


current

current: null | WebGLTexture = null

Current image texture

Inherited from

ShaderRenderer.current


input

Protected Optional input: ImageTexture

Input image texture

Inherited from

ShaderRenderer.input


loaded

Protected loaded: boolean = false

Loaded state

Inherited from

ShaderRenderer.loaded


padCtx

Protected padCtx: [null | CanvasRenderingContext2D, null | CanvasRenderingContext2D]

Drawing context of padding canvases

Inherited from

ShaderRenderer.padCtx


plugins

Protected plugins: Plugin<ResultT>[] = []

Attached plugins

Inherited from

ShaderRenderer.plugins


scene

Optional scene: SceneT

Renderer scene


shader

Protected Optional shader: ShaderProgram

Rendering shader

Inherited from

ShaderRenderer.shader


shaderCtx

shaderCtx: null | WebGL2RenderingContext = null

Context of the video canvas layer

Inherited from

ShaderRenderer.shaderCtx


videoRatio

Protected videoRatio: number

Aspect ratio of input video

Inherited from

ShaderRenderer.videoRatio


videoSize

Protected videoSize: Size

Resolution of input video

Inherited from

ShaderRenderer.videoSize

Methods

addListener

addListener<E>(event, listener): SceneRenderer<ResultT, SceneT>

Adds the listener function to the end of the listeners array

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerRendererEvents[E]The callback function

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.addListener


addPlugin

addPlugin(plugin): Promise<void>

Add render plugin

Initializes the plugin if it's not loaded yet but renderer is ready. Renderer takes ownership of the plugin instance meaning it will release it when plugin is detached or renderer is disposed itself.

Parameters

NameType
pluginPlugin<ResultT>

Returns

Promise<void>

Inherited from

ShaderRenderer.addPlugin


dispose

dispose(): void

Dispose renderer object

Extended to dispose scene object.

Returns

void

Overrides

ShaderRenderer.dispose


emit

emit<E>(event, ...args): boolean

Synchronously calls each of the listeners registered for the event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
...argsArgs<RendererEvents[E]>Arguments passed to the listeners

Returns

boolean

True if the event had listeners, False otherwise

Inherited from

ShaderRenderer.emit


eventNames

eventNames(): (string | symbol)[]

List of emitter's events

Returns

(string | symbol)[]

List of emitter's events

Inherited from

ShaderRenderer.eventNames


getMaxListeners

getMaxListeners(): number

Maximum number of listeners per event

Returns

number

Maximum number of listeners per event

Inherited from

ShaderRenderer.getMaxListeners


listenerCount

listenerCount<E>(event): number

The number of listeners listening to the event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event

Returns

number

Number of listeners

Inherited from

ShaderRenderer.listenerCount


listeners

listeners<E>(event): Function[]

Copy of the array of listeners for the event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

ShaderRenderer.listeners


load

load(): Promise<void>

Initialize renderer

Initializes rendering context, shader program and buffers.

Returns

Promise<void>

Promise resolving when initialization is finished

Inherited from

ShaderRenderer.load


off

off<E>(event, listener): SceneRenderer<ResultT, SceneT>

Removes the listener from the listener array for the event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerRendererEvents[E]The callback function

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.off


on

on<E>(event, listener): SceneRenderer<ResultT, SceneT>

Adds the listener function to the event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerRendererEvents[E]The callback function

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.on


once

once<E>(event, listener): SceneRenderer<ResultT, SceneT>

Adds a one-time listener function for the event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerRendererEvents[E]The callback function

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.once


prependListener

prependListener<E>(event, listener): SceneRenderer<ResultT, SceneT>

Adds the listener function to the beginning of the listeners array

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerRendererEvents[E]The callback function

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.prependListener


prependOnceListener

prependOnceListener<E>(event, listener): SceneRenderer<ResultT, SceneT>

Adds a one-time listener function to the beginning of the listeners array

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerRendererEvents[E]The callback function

Returns

SceneRenderer<ResultT, SceneT>

Inherited from

ShaderRenderer.prependOnceListener


rawListeners

rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

ShaderRenderer.rawListeners


removeAllListeners

removeAllListeners<E>(event?): SceneRenderer<ResultT, SceneT>

Removes all listeners, or those of the specified event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
event?EThe name of the event

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.removeAllListeners


removeAllPlugins

removeAllPlugins(): void

Remove all render plugins

Renderer will dispose all plugins before detaching them.

Returns

void

Inherited from

ShaderRenderer.removeAllPlugins


removeListener

removeListener<E>(event, listener): SceneRenderer<ResultT, SceneT>

Removes the specified listener from the listener array

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerRendererEvents[E]The callback function

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.removeListener


removePlugin

removePlugin(plugin): void

Remove render plugin

Renderer will dispose the plugin before detaching it.

Parameters

NameType
pluginPlugin<ResultT>

Returns

void

Inherited from

ShaderRenderer.removePlugin


setMaxListeners

setMaxListeners(n): SceneRenderer<ResultT, SceneT>

Sets maximum number of listeners per event

Parameters

NameTypeDescription
nnumberMaximum number of listeners

Returns

SceneRenderer<ResultT, SceneT>

This EventEmitter

Inherited from

ShaderRenderer.setMaxListeners


setMirror

setMirror(mirror): void

Set mirror mode

CanvasRenderer sets mirror mode of ResponsiveCanvas.

Parameters

NameType
mirrorboolean

Returns

void

Inherited from

ShaderRenderer.setMirror


setMode

setMode(mode): void

Set fitting mode

CanvasRenderer sets fitting mode of ResponsiveCanvas.

Parameters

NameTypeDescription
modeCanvasModeFitting mode

Returns

void

Inherited from

ShaderRenderer.setMode


setupCamera

setupCamera(ratio, angle): void

Set camera parameters

Callback sets up all attached plugins.

Parameters

NameTypeDescription
rationumberCamera aspect ratio
anglenumberCamera vertical angle in radians

Returns

void

Inherited from

ShaderRenderer.setupCamera


setupPadding

Protected setupPadding(): void

Setup padding canvases

Callback sets up size of padding canvases.

Returns

void

Inherited from

ShaderRenderer.setupPadding


setupVideo

setupVideo(size, ratio?): void

Set video parameters

Callback sets up size of video canvas layer, resizes texture and allocates new storage.

Parameters

NameTypeDescription
sizeSizeResolution of input video
ratio?numberAspect ration of input video

Returns

void

Inherited from

ShaderRenderer.setupVideo


unload

unload(): void

Reset renderer

Releases all resources and instances created in load(). Releases rendering context, shader program and buffers.

Returns

void

Inherited from

ShaderRenderer.unload


update

update(result, stream): Promise<void>

Update the scene

Renderers input video frame on corresponding canvas layer.

Parameters

NameTypeDescription
resultResultTResults of video processing
streamHTMLCanvasElementCaptured video frame

Returns

Promise<void>

Promise resolving when update is finished

Inherited from

ShaderRenderer.update


updatePads

Protected updatePads(stream): void

Update padding canvases

Updates padding canvases using portions of video frame.

Parameters

NameTypeDescription
streamHTMLCanvasElementCaptured video frame

Returns

void

Inherited from

ShaderRenderer.updatePads


updatePlugins

Protected updatePlugins(result, stream): Promise<void>

Update attached plugins

Calls update() of all attached plugins.

Parameters

NameTypeDescription
resultResultTResults of video processing
streamHTMLCanvasElementCaptured video frame

Returns

Promise<void>

Promise resolving when update is finished

Inherited from

ShaderRenderer.updatePlugins


updateScene

Protected updateScene(): void

Update and render the scene

Virtual method updating and rendering the scene. Overridden by implementation of derived renderer.

Returns

void

Inherited from

ShaderRenderer.updateScene


updateVideo

Protected updateVideo(stream): void

Update the video layer

Calls rendering shaders with current input texture.

Parameters

NameTypeDescription
streamHTMLCanvasElementCaptured video frame

Returns

void

Inherited from

ShaderRenderer.updateVideo