Class: CanvasRenderer<ResultT>
@geenee/armature.CanvasRenderer
Generic renderer using ResponsiveCanvas
Generic Renderer utilizing ResponsiveCanvas. Refer to their documentation for more details. CanvasRenderer can have several layers and there're two basic usage patterns. Use separate layers for video and scene and effectively render scene on top of the video stream. Advantage of this approach is that image and scene can be processed independently and one can apply different effects or postprocessing. This pattern is also easier to implement. Or one can use only one canvas layer and embed video stream into the scene as object via a texture or background component. This approach will have more complex implementation dependent on particular renderer. On the other hand, rendering effects affecting the whole scene will also apply to the video stream. This can improve performance and allows advanced rendering/postprocessing techniques to be used.
Type parameters
Name | Type | Description |
---|---|---|
ResultT | extends Object = {} | Type of processing results |
Hierarchy
PluginRenderer
<ResultT
>↳
CanvasRenderer
Constructors
constructor
• new CanvasRenderer<ResultT
>(params
)
Constructor
Type parameters
Name | Type |
---|---|
ResultT | extends Object = {} |
Parameters
Name | Type | Description |
---|---|---|
params | CanvasParams | Parameters of responsive canvas |
Overrides
Properties
cameraAngle
• Protected
cameraAngle: number
Camera vertical angle in radians
Inherited from
cameraRatio
• Protected
cameraRatio: number
Camera aspect ratio
Inherited from
canvas
• canvas: ResponsiveCanvas
Responsive canvas
loaded
• Protected
loaded: boolean
= false
Loaded state
Inherited from
padCtx
• Protected
padCtx: [null
| CanvasRenderingContext2D
, null
| CanvasRenderingContext2D
]
Drawing context of padding canvases
plugins
• Protected
plugins: Plugin
<ResultT
>[] = []
Attached plugins
Inherited from
videoRatio
• Protected
videoRatio: number
Aspect ratio of input video
Inherited from
videoSize
• Protected
videoSize: Size
Resolution of input video
Inherited from
Methods
addListener
▸ addListener<E
>(event
, listener
): CanvasRenderer
<ResultT
>
Adds the listener function to the end of the listeners array
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | RendererEvents [E ] | The callback function |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
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
Name | Type |
---|---|
plugin | Plugin <ResultT > |
Returns
Promise
<void
>
Inherited from
dispose
▸ dispose(): void
Dispose renderer object
Extended to dispose all attached plugins.
Returns
void
Inherited from
emit
▸ emit<E
>(event
, ...args
): boolean
Synchronously calls each of the listeners registered for the event
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
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
eventNames
▸ eventNames(): (string
| symbol
)[]
List of emitter's events
Returns
(string
| symbol
)[]
List of emitter's events
Inherited from
getMaxListeners
▸ getMaxListeners(): number
Maximum number of listeners per event
Returns
number
Maximum number of listeners per event
Inherited from
PluginRenderer.getMaxListeners
listenerCount
▸ listenerCount<E
>(event
): number
The number of listeners listening to the event
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
Returns
number
Number of listeners
Inherited from
listeners
▸ listeners<E
>(event
): Function
[]
Copy of the array of listeners for the event
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
Returns
Function
[]
Copy of the listeners array
Inherited from
load
▸ load(): Promise
<void
>
Initialize renderer
Initializes all attached plugins.
Returns
Promise
<void
>
Promise resolving when initialization is finished
Inherited from
off
▸ off<E
>(event
, listener
): CanvasRenderer
<ResultT
>
Removes the listener from the listener array for the event
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | RendererEvents [E ] | The callback function |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
on
▸ on<E
>(event
, listener
): CanvasRenderer
<ResultT
>
Adds the listener function to the event
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | RendererEvents [E ] | The callback function |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
once
▸ once<E
>(event
, listener
): CanvasRenderer
<ResultT
>
Adds a one-time listener function for the event
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | RendererEvents [E ] | The callback function |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
prependListener
▸ prependListener<E
>(event
, listener
): CanvasRenderer
<ResultT
>
Adds the listener function to the beginning of the listeners array
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | RendererEvents [E ] | The callback function |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
PluginRenderer.prependListener
prependOnceListener
▸ prependOnceListener<E
>(event
, listener
): CanvasRenderer
<ResultT
>
Adds a one-time listener function to the beginning of the listeners array
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | RendererEvents [E ] | The callback function |
Returns
CanvasRenderer
<ResultT
>
Inherited from
PluginRenderer.prependOnceListener
rawListeners
▸ rawListeners<E
>(event
): Function
[]
Copy of the array of listeners for the event including wrappers
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
Returns
Function
[]
Copy of the listeners array
Inherited from
removeAllListeners
▸ removeAllListeners<E
>(event?
): CanvasRenderer
<ResultT
>
Removes all listeners, or those of the specified event
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event? | E | The name of the event |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
PluginRenderer.removeAllListeners
removeAllPlugins
▸ removeAllPlugins(): void
Remove all render plugins
Renderer will dispose all plugins before detaching them.
Returns
void
Inherited from
PluginRenderer.removeAllPlugins
removeListener
▸ removeListener<E
>(event
, listener
): CanvasRenderer
<ResultT
>
Removes the specified listener from the listener array
Type parameters
Name | Type |
---|---|
E | extends keyof RendererEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | RendererEvents [E ] | The callback function |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
removePlugin
▸ removePlugin(plugin
): void
Remove render plugin
Renderer will dispose the plugin before detaching it.
Parameters
Name | Type |
---|---|
plugin | Plugin <ResultT > |
Returns
void
Inherited from
setMaxListeners
▸ setMaxListeners(n
): CanvasRenderer
<ResultT
>
Sets maximum number of listeners per event
Parameters
Name | Type | Description |
---|---|---|
n | number | Maximum number of listeners |
Returns
CanvasRenderer
<ResultT
>
This EventEmitter
Inherited from
PluginRenderer.setMaxListeners
setMirror
▸ setMirror(mirror
): void
Set mirror mode
CanvasRenderer sets mirror mode of ResponsiveCanvas.
Parameters
Name | Type |
---|---|
mirror | boolean |
Returns
void
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
Name | Type | Description |
---|---|---|
ratio | number | Aspect ration of input video |
angle | number | - |
Returns
void
Inherited from
setupPadding
▸ Protected
setupPadding(): void
Setup padding canvases
Callback sets up size of padding canvases.
Returns
void
setupVideo
▸ setupVideo(size
, ratio?
): void
Set video parameters
Callback passes aspect ratio to responsive canvas.
Parameters
Name | Type | Description |
---|---|---|
size | Size | Resolution of input video |
ratio? | number | Aspect ration of input video |
Returns
void
Overrides
unload
▸ unload(): void
Reset renderer
Resets all attached plugins.
Returns
void
Inherited from
update
▸ update(result
, stream
): Promise
<void
>
Update the scene
Updates all attached plugins.
Parameters
Name | Type | Description |
---|---|---|
result | ResultT | Results of video processing |
stream | HTMLCanvasElement | Captured video frame |
Returns
Promise
<void
>
Promise resolving when update is finished
Inherited from
updatePads
▸ Protected
updatePads(stream
): void
Update padding canvases
Updates padding canvases using portions of video frame.
Parameters
Name | Type | Description |
---|---|---|
stream | HTMLCanvasElement | Captured video frame |
Returns
void
updatePlugins
▸ Protected
updatePlugins(result
, stream
): Promise
<void
>
Update attached plugins
Calls update() of all attached plugins.
Parameters
Name | Type | Description |
---|---|---|
result | ResultT | Results of video processing |
stream | HTMLCanvasElement | Captured video frame |
Returns
Promise
<void
>
Promise resolving when update is finished
Inherited from
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
updateVideo
▸ Protected
updateVideo(stream
): void
Update the video layer
Updates padding canvases using portions of video frame.
Parameters
Name | Type | Description |
---|---|---|
stream | HTMLCanvasElement | Captured video frame |
Returns
void