Skip to content

PluginRenderer

Generic plugin renderer

Extends Renderer implementing render plugin system. Plugins can be attached to an instance of the PluginRenderer. Usually they perform simple tasks that can be separated from bigger app context into atomic building blocks, for example control object on a scene to follow (be attached to) user’s head, apply image effect (smoothing, beautification), recognize gestures or poses, notify about state changes or perform other kinds of transformations, pre/post-processing, or analyzes with a 3D scene, video stream or raw data from a Processor. Plugin is a abstraction level to single out ready-made helpers that can be reused as atomic building blocks of an app. Plugins are very similar to Renderer but do only one task, they also should implement two basic methods load() and update(). PluginRenderer initializes all attached plugins calling their load() method and providing itself as an argument for plugin to acquire required resources, for example canvas context or reference to 3d scene. Every rendering cycle PluginRenderer calls update() of all attached and successfully loaded plugins passing results of video processing and current video frame. Plugins are ordered depending on processing or rendering stage they should step in, this order is defined by plugin ordinal number. For example there can be a plugin that filters results of processing by some constraint, let’s say it accepts only poses where upper body is in the field of view and asks a user to step back for better virtual try-on experience, this plugin should update poses before plugin that renders virtual apparel.

ResultT extends object = { }

Type of processing results

new PluginRenderer<ResultT>(): PluginRenderer<ResultT>

Constructor

PluginRenderer<ResultT>

Renderer.constructor

protected cameraAngle: number

Camera vertical angle in radians

Renderer.cameraAngle


protected cameraRatio: number

Camera aspect ratio

Renderer.cameraRatio


protected loaded: boolean = false

Loaded state

Renderer.loaded


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

Attached plugins


protected videoRatio: number

Aspect ratio of input video

Renderer.videoRatio


protected videoSize: Size

Resolution of input video

Renderer.videoSize

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

Renderer.addListener


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.

Plugin<ResultT>

Promise<void>


dispose(): void

Dispose renderer object

Extended to dispose all attached plugins.

void

Renderer.dispose


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

Renderer.emit


eventNames(): (string | symbol)[]

List of emitter’s events

(string | symbol)[]

List of emitter’s events

Renderer.eventNames


getMaxListeners(): number

Maximum number of listeners per event

number

Maximum number of listeners per event

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

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

Renderer.listeners


load(): Promise<void>

Initialize renderer

Initializes all attached plugins.

Promise<void>

Promise resolving when initialization is finished

Renderer.load


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

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

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

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

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

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

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

Renderer.removeAllListeners


removeAllPlugins(): void

Remove all render plugins

Renderer will dispose all plugins before detaching them.

void


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

Renderer.removeListener


removePlugin(plugin): void

Remove render plugin

Renderer will dispose the plugin before detaching it.

Plugin<ResultT>

void


setMaxListeners(n): this

Sets maximum number of listeners per event

number

Maximum number of listeners

this

This EventEmitter

Renderer.setMaxListeners


setupCamera(ratio, angle): void

Set camera parameters

Callback sets up all attached plugins.

number

Camera aspect ratio

number

Camera vertical angle in radians

void

Renderer.setupCamera


setupVideo(size, ratio?): void

Set video parameters

Callback sets up all attached plugins.

Size

Resolution of input video

number

Aspect ration of input video

void

Renderer.setupVideo


unload(): void

Reset renderer

Resets all attached plugins.

void

Renderer.unload


update(result, stream): Promise<void>

Update the scene

Updates all attached plugins.

ResultT

Results of video processing

HTMLCanvasElement

Captured video frame

Promise<void>

Promise resolving when update is finished

Renderer.update


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

Update attached plugins

Calls update() of all attached plugins.

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

Renderer.updateScene


protected updateVideo(stream): void

Update the video layer

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

HTMLCanvasElement

Captured video frame

void

Renderer.updateVideo