Skip to content

Plugin

Generic renderer plugin

Plugin can be attached to a PluginRenderer instance. 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 application. Plugins are very similar to Renderer and also should implement two basic methods load() and update(). Renderer initializes a plugin calling load() and providing itself as argument, plugin in turn remembers renderer it’s attached to and gets access to required resources of the renderer, for example 2d or webgl context of a canvas or reference to a 3d scene. In update() method plugins implement actual logic given processing results. Renderer applies attached plugins in order defined by their ordinal number. In some cases priority of plugins execution is important, e.g. there can be a plugin that filters results of pose processing by some constraint, let’s say it passes 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.

Extended by

Type Parameters

ResultT extends object = object

Type of processing results

Constructors

new Plugin()

new Plugin<ResultT>(): Plugin<ResultT>

Returns

Plugin<ResultT>

Properties

loaded

loaded: boolean = false

Loaded state


ordinal

ordinal: number = PluginOrdinal.Render

Ordinal number


renderer?

protected optional renderer: Renderer<ResultT>

Renderer loaded the plugin

Methods

dispose()

dispose(): void

Dispose video plugin

Returns

void


load()

load(renderer): Promise<void>

Initialize plugin

Initializes resources/instances needed by plugin. Overridden by derived classes for particular task.

Parameters

renderer: Renderer<ResultT>

Renderer this plugin is attached to

Returns

Promise<void>

Promise resolving when initialization is finished


setupCamera()

setupCamera(ratio, angle): void

Set camera parameters

Could be overridden to adjust plugin’s pipeline.

Parameters

ratio: number

Aspect ration of input video

angle: number

Vertical field of view in radians

Returns

void


setupVideo()

setupVideo(size): void

Set video size

Could be overridden to adjust plugin’s pipeline.

Parameters

size: Size

Resolution of input video

Returns

void


unload()

unload(): void

Reset plugin

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

Returns

void


update()

update(result, stream): Promise<void>

Update

Main method implementing the logic of the plugin. Overridden by derived classes for particular task.

Parameters

result: ResultT

Results of video processing

stream: HTMLCanvasElement

Captured video frame

Returns

Promise<void>

Promise resolving when update is finished