Skip to main content

Class: Renderer<ResultT>

@geenee/armature.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 () and () 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.

Type parameters

NameDescription
ResultTType of processing results

Hierarchy

Constructors

constructor

new Renderer<ResultT>()

Constructor

Type parameters

Name
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): Renderer<ResultT>

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

Renderer<ResultT>

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

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

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

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe 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

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
eventEThe 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): Renderer<ResultT>

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

Renderer<ResultT>

This EventEmitter

Inherited from

EventEmitterT.off


on

on<E>(event, listener): Renderer<ResultT>

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

Renderer<ResultT>

This EventEmitter

Inherited from

EventEmitterT.on


once

once<E>(event, listener): Renderer<ResultT>

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

Renderer<ResultT>

This EventEmitter

Inherited from

EventEmitterT.once


prependListener

prependListener<E>(event, listener): Renderer<ResultT>

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

Renderer<ResultT>

This EventEmitter

Inherited from

EventEmitterT.prependListener


prependOnceListener

prependOnceListener<E>(event, listener): Renderer<ResultT>

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

Renderer<ResultT>

Inherited from

EventEmitterT.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

EventEmitterT.rawListeners


removeAllListeners

removeAllListeners<E>(event?): Renderer<ResultT>

Removes all listeners, or those of the specified event

Type parameters

NameType
Eextends keyof RendererEvents

Parameters

NameTypeDescription
event?EThe name of the event

Returns

Renderer<ResultT>

This EventEmitter

Inherited from

EventEmitterT.removeAllListeners


removeListener

removeListener<E>(event, listener): Renderer<ResultT>

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

Renderer<ResultT>

This EventEmitter

Inherited from

EventEmitterT.removeListener


setMaxListeners

setMaxListeners(n): Renderer<ResultT>

Sets maximum number of listeners per event

Parameters

NameTypeDescription
nnumberMaximum number of listeners

Returns

Renderer<ResultT>

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

NameTypeDescription
rationumberCamera aspect ratio
anglenumberCamera vertical angle in radians

Returns

void


setupVideo

setupVideo(size, ratio?): void

Set video parameters

Could be overridden to adjust rendering pipeline.

Parameters

NameTypeDescription
sizeSizeResolution of input video
ratio?numberAspect 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

NameTypeDescription
resultResultTResults of video processing
streamHTMLCanvasElementCaptured 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

NameTypeDescription
streamHTMLCanvasElementCaptured video frame

Returns

void