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.

Extends

Extended by

Type Parameters

ResultT extends object = object

Type of processing results

Constructors

new PluginRenderer()

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

Constructor

Returns

PluginRenderer<ResultT>

Inherited from

Renderer.constructor

Properties

cameraAngle

protected cameraAngle: number

Camera vertical angle in radians

Inherited from

Renderer.cameraAngle


cameraRatio

protected cameraRatio: number

Camera aspect ratio

Inherited from

Renderer.cameraRatio


loaded

protected loaded: boolean = false

Loaded state

Inherited from

Renderer.loaded


plugins

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

Attached plugins


videoRatio

protected videoRatio: number

Aspect ratio of input video

Inherited from

Renderer.videoRatio


videoSize

protected videoSize: Size

Resolution of input video

Inherited from

Renderer.videoSize

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

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

plugin: Plugin<ResultT>

Returns

Promise<void>


dispose()

dispose(): void

Dispose renderer object

Extended to dispose all attached plugins.

Returns

void

Overrides

Renderer.dispose


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

Renderer.emit


eventNames()

eventNames(): (string | symbol)[]

List of emitter’s events

Returns

(string | symbol)[]

List of emitter’s events

Inherited from

Renderer.eventNames


getMaxListeners()

getMaxListeners(): number

Maximum number of listeners per event

Returns

number

Maximum number of listeners per event

Inherited from

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

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

Renderer.listeners


load()

load(): Promise<void>

Initialize renderer

Initializes all attached plugins.

Returns

Promise<void>

Promise resolving when initialization is finished

Overrides

Renderer.load


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

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

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

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

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

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

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

Renderer.removeAllListeners


removeAllPlugins()

removeAllPlugins(): void

Remove all render plugins

Renderer will dispose all plugins before detaching them.

Returns

void


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

Renderer.removeListener


removePlugin()

removePlugin(plugin): void

Remove render plugin

Renderer will dispose the plugin before detaching it.

Parameters

plugin: Plugin<ResultT>

Returns

void


setMaxListeners()

setMaxListeners(n): this

Sets maximum number of listeners per event

Parameters

n: number

Maximum number of listeners

Returns

this

This EventEmitter

Inherited from

Renderer.setMaxListeners


setupCamera()

setupCamera(ratio, angle): void

Set camera parameters

Callback sets up all attached plugins.

Parameters

ratio: number

Camera aspect ratio

angle: number

Camera vertical angle in radians

Returns

void

Overrides

Renderer.setupCamera


setupVideo()

setupVideo(size, ratio?): void

Set video parameters

Callback sets up all attached plugins.

Parameters

size: Size

Resolution of input video

ratio?: number

Aspect ration of input video

Returns

void

Overrides

Renderer.setupVideo


unload()

unload(): void

Reset renderer

Resets all attached plugins.

Returns

void

Overrides

Renderer.unload


update()

update(result, stream): Promise<void>

Update the scene

Updates all attached plugins.

Parameters

result: ResultT

Results of video processing

stream: HTMLCanvasElement

Captured video frame

Returns

Promise<void>

Promise resolving when update is finished

Overrides

Renderer.update


updatePlugins()

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

Update attached plugins

Calls update() of all attached plugins.

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

Inherited from

Renderer.updateScene


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

Inherited from

Renderer.updateVideo