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.

ResultT

Type of processing results

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

Constructor

Renderer<ResultT>

EventEmitterT.constructor

protected cameraAngle: number

Camera vertical angle in radians


protected cameraRatio: number

Camera aspect ratio


protected loaded: boolean = false

Loaded state


protected videoRatio: number

Aspect ratio of input video


protected videoSize: Size

Resolution of input video

addListener<E>(event, listener): this

Adds the listener function to the end of the listeners array

E extends keyof RendererEvents

E

The name of the event

RendererEvents[E]

The callback function

this

This EventEmitter

EventEmitterT.addListener


dispose(): void

Dispose renderer object

void


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

Synchronously calls each of the listeners registered for the event

E extends keyof RendererEvents

E

The name of the event

Args<RendererEvents[E]>

Arguments passed to the listeners

boolean

True if the event had listeners, False otherwise

EventEmitterT.emit


eventNames(): (string | symbol)[]

List of emitter’s events

(string | symbol)[]

List of emitter’s events

EventEmitterT.eventNames


getMaxListeners(): number

Maximum number of listeners per event

number

Maximum number of listeners per event

EventEmitterT.getMaxListeners


listenerCount<E>(event): number

The number of listeners listening to the event

E extends keyof RendererEvents

E

The name of the event

number

Number of listeners

EventEmitterT.listenerCount


listeners<E>(event): Function[]

Copy of the array of listeners for the event

E extends keyof RendererEvents

E

The name of the event

Function[]

Copy of the listeners array

EventEmitterT.listeners


load(): Promise<void>

Initialize renderer

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

Promise<void>

Promise resolving when initialization is finished


off<E>(event, listener): this

Removes the listener from the listener array for the event

E extends keyof RendererEvents

E

The name of the event

RendererEvents[E]

The callback function

this

This EventEmitter

EventEmitterT.off


on<E>(event, listener): this

Adds the listener function to the event

E extends keyof RendererEvents

E

The name of the event

RendererEvents[E]

The callback function

this

This EventEmitter

EventEmitterT.on


once<E>(event, listener): this

Adds a one-time listener function for the event

E extends keyof RendererEvents

E

The name of the event

RendererEvents[E]

The callback function

this

This EventEmitter

EventEmitterT.once


prependListener<E>(event, listener): this

Adds the listener function to the beginning of the listeners array

E extends keyof RendererEvents

E

The name of the event

RendererEvents[E]

The callback function

this

This EventEmitter

EventEmitterT.prependListener


prependOnceListener<E>(event, listener): this

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

E extends keyof RendererEvents

E

The name of the event

RendererEvents[E]

The callback function

this

EventEmitterT.prependOnceListener


rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

E extends keyof RendererEvents

E

The name of the event

Function[]

Copy of the listeners array

EventEmitterT.rawListeners


removeAllListeners<E>(event?): this

Removes all listeners, or those of the specified event

E extends keyof RendererEvents

E

The name of the event

this

This EventEmitter

EventEmitterT.removeAllListeners


removeListener<E>(event, listener): this

Removes the specified listener from the listener array

E extends keyof RendererEvents

E

The name of the event

RendererEvents[E]

The callback function

this

This EventEmitter

EventEmitterT.removeListener


setMaxListeners(n): this

Sets maximum number of listeners per event

number

Maximum number of listeners

this

This EventEmitter

EventEmitterT.setMaxListeners


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.

number

Camera aspect ratio

number

Camera vertical angle in radians

void


setupVideo(size, ratio?): void

Set video parameters

Could be overridden to adjust rendering pipeline.

Size

Resolution of input video

number

Aspect ration of input video

void


unload(): void

Reset renderer

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

void


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.

ResultT

Results of video processing

HTMLCanvasElement

Captured video frame

Promise<void>

Promise resolving when update is finished


protected updateScene(): void

Update and render the scene

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

void


protected updateVideo(stream): void

Update the video layer

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

HTMLCanvasElement

Captured video frame

void