Skip to content

Renderer

Core generic renderer

Renderer is the core visualization part of any application. It’s attached to Engine. Results of processing and captured frame are provided to renderer that updates scene, visualization and application logic according to this data. Basically, renders define two methods load() and update(). The first one is used to initialize all assets and prepare the scene e.g. set up lightning, environment map. Engine will call load() method during pipeline initialization. The second one is used to update the scene using results of video processing. This’s where all the logic happens. By overriding/extending load() and update() you can add any custom logic, interactions, animations, post-processing effects, gesture recognition, physics, etc. to an app. Renderer is a generic abstract class defining common core interfaces.

Extends

Extended by

Type Parameters

ResultT

Type of processing results

Constructors

new Renderer()

new Renderer<ResultT>(): Renderer<ResultT>

Constructor

Returns

Renderer<ResultT>

Overrides

EventEmitterT.constructor

Properties

cameraAngle

protected cameraAngle: number

Camera vertical angle in radians


cameraRatio

protected cameraRatio: number

Camera aspect ratio


loaded

protected loaded: boolean = false

Loaded state


videoRatio

protected videoRatio: number

Aspect ratio of input video


videoSize

protected videoSize: Size

Resolution of input video

Methods

addListener()

addListener<E>(event, listener): this

Adds the listener function to the end of the listeners array

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

listener: RendererEvents[E]

The callback function

Returns

this

This EventEmitter

Inherited from

EventEmitterT.addListener


dispose()

dispose(): void

Dispose renderer object

Returns

void


emit()

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

Synchronously calls each of the listeners registered for the event

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

• …args: Args<RendererEvents[E]>

Arguments passed to the listeners

Returns

boolean

True if the event had listeners, False otherwise

Inherited from

EventEmitterT.emit


eventNames()

eventNames(): (string | symbol)[]

List of emitter’s events

Returns

(string | symbol)[]

List of emitter’s events

Inherited from

EventEmitterT.eventNames


getMaxListeners()

getMaxListeners(): number

Maximum number of listeners per event

Returns

number

Maximum number of listeners per event

Inherited from

EventEmitterT.getMaxListeners


listenerCount()

listenerCount<E>(event): number

The number of listeners listening to the event

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

Returns

number

Number of listeners

Inherited from

EventEmitterT.listenerCount


listeners()

listeners<E>(event): Function[]

Copy of the array of listeners for the event

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

EventEmitterT.listeners


load()

load(): Promise<void>

Initialize renderer

Initializes renderer, all required assets, and the scene. Overridden by derived classes for particular application.

Returns

Promise<void>

Promise resolving when initialization is finished


off()

off<E>(event, listener): this

Removes the listener from the listener array for the event

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

listener: RendererEvents[E]

The callback function

Returns

this

This EventEmitter

Inherited from

EventEmitterT.off


on()

on<E>(event, listener): this

Adds the listener function to the event

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

listener: RendererEvents[E]

The callback function

Returns

this

This EventEmitter

Inherited from

EventEmitterT.on


once()

once<E>(event, listener): this

Adds a one-time listener function for the event

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

listener: RendererEvents[E]

The callback function

Returns

this

This EventEmitter

Inherited from

EventEmitterT.once


prependListener()

prependListener<E>(event, listener): this

Adds the listener function to the beginning of the listeners array

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

listener: RendererEvents[E]

The callback function

Returns

this

This EventEmitter

Inherited from

EventEmitterT.prependListener


prependOnceListener()

prependOnceListener<E>(event, listener): this

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

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

listener: RendererEvents[E]

The callback function

Returns

this

Inherited from

EventEmitterT.prependOnceListener


rawListeners()

rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

EventEmitterT.rawListeners


removeAllListeners()

removeAllListeners<E>(event?): this

Removes all listeners, or those of the specified event

Type Parameters

E extends keyof RendererEvents

Parameters

event?: E

The name of the event

Returns

this

This EventEmitter

Inherited from

EventEmitterT.removeAllListeners


removeListener()

removeListener<E>(event, listener): this

Removes the specified listener from the listener array

Type Parameters

E extends keyof RendererEvents

Parameters

event: E

The name of the event

listener: RendererEvents[E]

The callback function

Returns

this

This EventEmitter

Inherited from

EventEmitterT.removeListener


setMaxListeners()

setMaxListeners(n): this

Sets maximum number of listeners per event

Parameters

n: number

Maximum number of listeners

Returns

this

This EventEmitter

Inherited from

EventEmitterT.setMaxListeners


setupCamera()

setupCamera(ratio, angle): void

Set camera parameters

Some video processors statically define camera parameters from just a video resolution. In this cases setupCamera() is used to pass these static camera parameters to renderer.

Parameters

ratio: number

Camera aspect ratio

angle: number

Camera vertical angle in radians

Returns

void


setupVideo()

setupVideo(size, ratio?): void

Set video parameters

Could be overridden to adjust rendering pipeline.

Parameters

size: Size

Resolution of input video

ratio?: number

Aspect ration of input video

Returns

void


unload()

unload(): void

Reset renderer

Releases all resources and instances created in load(). Overridden by derived classes for particular application.

Returns

void


update()

update(result, stream): Promise<void>

Update the scene

Main method defining the logic of the renderer. Updates the scene according to provided results. Overridden by derived classes for the application.

Parameters

result: ResultT

Results of video processing

stream: HTMLCanvasElement

Captured video frame

Returns

Promise<void>

Promise resolving when update is finished


updateScene()

protected updateScene(): void

Update and render the scene

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

Returns

void


updateVideo()

protected updateVideo(stream): void

Update the video layer

Virtual method drawing input video frame. Derived renderer provides implementation.

Parameters

stream: HTMLCanvasElement

Captured video frame

Returns

void