Skip to content

HairEngine

Hair engine

Specialization of @geenee/armature!Engine for HairProcessor. Straightforward wrapper, instead of new Engine(HairProcessor, ...) you can use simpler const engine = new HairEngine(...}).

new HairEngine(engineParams?, Source?): HairEngine

Constructor

EngineParams

Parameters of the engine

() => VideoSource

Video source class or instance

HairEngine

Engine.constructor

protected optional engineParams: EngineParams

Parameters of the engine

Engine.engineParams


init: (procParams) => Promise<boolean>

Initialize engine. Sets up processor.

The SDK access token is required parameter that authenticates the user and enables the SDK on the current url. By default, path to required wasm modules provided with SDK packages is the current url. You can change the root path to wasms passing root parameter.

MaskParams

Parameters of the processor

Promise<boolean>

Status of initialization

Engine.init


protected iterate: () => Promise<void>

Iterate

Promise<void>

Engine.iterate


pause: () => void

Pause pipeline.

Nothing happens if pipeline is not started yet.

void

Engine.pause


protected optional processCanvas: HTMLCanvasElement

Shallow copy of canvas with video for processors

Engine.processCanvas


protected processor: HairProcessor

Processor utilized by the engine

Engine.processor


protected processSize: Size

Size of video for processors

Engine.processSize


protected renderers: Renderer<MaskResult>[]

Renderer attached to the engine

Engine.renderers


reset: () => void

Reset pipeline

Stops pipeline, resets video capture and processor. After reset one needs to reinitialize video capture calling setup() before pipeline can be started again.

void

Engine.reset


protected optional resizeBuffer: ImageBuffer

Buffer to resize frames

Engine.resizeBuffer


protected resizeEnabled: boolean

Original stream is resized

Engine.resizeEnabled


setup: (videoParams?) => Promise<boolean>

Setup engine. Initializes video capture.

Video capture can be setup by simplified VideoParams opening default front/rear camera with provided resolution. Additional fine-grained MediaStreamConstraints can be passed via opts field providing the most flexible way to setup video stream (for example, by requesting specific deviceId). Stream constraints have higher priority than rest or params. Another options are an external MediaStream allowing custom video sources (e.g. remote stream) or a media file defined by url or FileParams that allows to limit maximum capture size in cases resolution is too big for a device.

VideoSourceParams

Parameters of video capture

Promise<boolean>

Status of initialization

Engine.setup


start: () => Promise<void>

Start pipeline.

Pipeline can be started only after successful init and setup.

Promise<void>

Engine.start


protected optional streamCanvas: HTMLCanvasElement

Shallow copy of canvas with video for renderers

Engine.streamCanvas


protected streamSize: Size

Size of video for renderers

Engine.streamSize


protected video: VideoSource

Video source instance

Engine.video


protected videoRatio: number

Ratio of video stream

Engine.videoRatio

addListener<E>(event, listener): this

Adds the listener function to the end of the listeners array

E extends keyof EngineEvents

E

The name of the event

EngineEvents[E]

The callback function

this

This EventEmitter

Engine.addListener


addRenderer(renderer): Promise<void>

Attach Renderer to the engine

Renderer<MaskResult>

Object to be attached

Promise<void>

Engine.addRenderer


emit<E>(event, …args): boolean

Synchronously calls each of the listeners registered for the event

E extends keyof EngineEvents

E

The name of the event

Args<EngineEvents[E]>

Arguments passed to the listeners

boolean

True if the event had listeners, False otherwise

Engine.emit


protected enqueue(): void

Enqueue the next iteration

void

Engine.enqueue


eventNames(): (string | symbol)[]

List of emitter’s events

(string | symbol)[]

List of emitter’s events

Engine.eventNames


getMaxListeners(): number

Maximum number of listeners per event

number

Maximum number of listeners per event

Engine.getMaxListeners


listenerCount<E>(event): number

The number of listeners listening to the event

E extends keyof EngineEvents

E

The name of the event

number

Number of listeners

Engine.listenerCount


listeners<E>(event): Function[]

Copy of the array of listeners for the event

E extends keyof EngineEvents

E

The name of the event

Function[]

Copy of the listeners array

Engine.listeners


off<E>(event, listener): this

Removes the listener from the listener array for the event

E extends keyof EngineEvents

E

The name of the event

EngineEvents[E]

The callback function

this

This EventEmitter

Engine.off


on<E>(event, listener): this

Adds the listener function to the event

E extends keyof EngineEvents

E

The name of the event

EngineEvents[E]

The callback function

this

This EventEmitter

Engine.on


once<E>(event, listener): this

Adds a one-time listener function for the event

E extends keyof EngineEvents

E

The name of the event

EngineEvents[E]

The callback function

this

This EventEmitter

Engine.once


prependListener<E>(event, listener): this

Adds the listener function to the beginning of the listeners array

E extends keyof EngineEvents

E

The name of the event

EngineEvents[E]

The callback function

this

This EventEmitter

Engine.prependListener


prependOnceListener<E>(event, listener): this

Adds a one-time listener function to the beginning of the listeners array

E extends keyof EngineEvents

E

The name of the event

EngineEvents[E]

The callback function

this

Engine.prependOnceListener


rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

E extends keyof EngineEvents

E

The name of the event

Function[]

Copy of the listeners array

Engine.rawListeners


removeAllListeners<E>(event?): this

Removes all listeners, or those of the specified event

E extends keyof EngineEvents

E

The name of the event

this

This EventEmitter

Engine.removeAllListeners


removeListener<E>(event, listener): this

Removes the specified listener from the listener array

E extends keyof EngineEvents

E

The name of the event

EngineEvents[E]

The callback function

this

This EventEmitter

Engine.removeListener


removeRenderer(renderer): void

Remove attached Renderer

Renderer<MaskResult>

Renderer to be removed

void

Engine.removeRenderer


protected resizeVideo(size): void

Callback called when video resolution is changed

Size

Size of the video

void

Engine.resizeVideo


setMaxListeners(n): this

Sets maximum number of listeners per event

number

Maximum number of listeners

this

This EventEmitter

Engine.setMaxListeners


protected setupProcessor(procParams): Promise<boolean>

Setup processor

MaskParams

Promise<boolean>

Engine.setupProcessor


protected setupSize(size): Promise<void>

Setup video size

Size

Promise<void>

Engine.setupSize


protected setupVideo(videoParams?): Promise<boolean>

Setup video capture

VideoSourceParams

Promise<boolean>

Engine.setupVideo