Skip to main content

Class: FaceTrackPlugin

@geenee/bodyrenderers-three.FaceTrackPlugin

Plugin assigning face point pose to a scene node

Plugin attaches provided node to the face point. Pose of the node (translation + rotation + scale) continuously updates according to pose estimation by @geenee/bodyprocessors!FaceProcessor. Children nodes inherently include this transform. The node can be seen as a virtual placeholder for real object. It's recommended to attach top-level nodes that don't include transforms relative to parent, otherwise head transform that is a pose in the world frame will be applied on top of them (will be treated as relative instead of absolute). Optionally anisotropic fine-tuning of the scale can be applied. In this case model will additionally adapt to shape of the face. If face isn't detected by FaceProcessor plugin recursively hides the node. One of approaches to accurately align meshes with a face point when modeling a scene is to make them children of a node which origin coincide with the corresponding vertex of the reference face mesh, set their relative transforms using base mesh as the reference, then instantiate FaceTrackPlugin for this scene node. You can also apply relative transforms of children of the face-attached parent node programmatically. It's useful to add occluder model (base mesh of a head) as a child of the node. This can be handy when parts are stored separately.

Hierarchy

Constructors

constructor

new FaceTrackPlugin(node, facePoint?, shapeScale?)

Constructor

Parameters

NameTypeDefault valueDescription
nodeObject3D<Event>undefinedScene node to attach
facePointnumber0Index of the face vertex
shapeScalebooleanfalseTune scale according to shape of the face

Overrides

ThreePlugin.constructor

Properties

facePoint

Protected facePoint: number = 0

Index of the face vertex


loaded

loaded: boolean

Loaded state

Inherited from

ThreePlugin.loaded


node

Protected node: Object3D<Event>

Scene node to attach


ordinal

ordinal: number

Ordinal number

Inherited from

ThreePlugin.ordinal


renderer

Protected Optional renderer: Renderer<FaceResult>

Renderer loaded the plugin

Inherited from

ThreePlugin.renderer


scene

Protected Optional scene: Scene

Reference to a scene instance

Inherited from

ThreePlugin.scene


shapeScale

Protected shapeScale: boolean = false

Tune scale according to shape of the face

Methods

dispose

dispose(): void

Dispose video plugin

Returns

void

Inherited from

ThreePlugin.dispose


load

load(renderer): Promise<void>

Initialize plugin

Prepares or modifies the attached node if required. Reference to the scene object is cached and used by plugin on update() and unload(). You need to reload plugin if you want to change scene it's attached to.

Parameters

NameTypeDescription
rendererRenderer<FaceResult>Renderer this plugin is attached to

Returns

Promise<void>

Promise resolving when initialization is finished

Inherited from

ThreePlugin.load


setupCamera

setupCamera(ratio, angle): void

Set camera parameters

Could be overridden to adjust plugin's pipeline.

Parameters

NameTypeDescription
rationumberAspect ration of input video
anglenumber-

Returns

void

Inherited from

ThreePlugin.setupCamera


setupVideo

setupVideo(size): void

Set video size

Could be overridden to adjust plugin's pipeline.

Parameters

NameTypeDescription
sizeSizeResolution of input video

Returns

void

Inherited from

ThreePlugin.setupVideo


unload

unload(): void

Reset plugin

Releases all resources allocated in load(). Deletes cached reference to the scene object.

Returns

void

Inherited from

ThreePlugin.unload


update

update(result, stream): Promise<void>

Update pose of the model

Updates node's pose (translation + rotation + scale) according to to the estimation from @geenee/bodyprocessors!FaceProcessor. If face isn't detected plugin recursively hides the attached node.

Parameters

NameTypeDescription
resultFaceResultResults of video processing
streamHTMLCanvasElementCaptured video frame

Returns

Promise<void>

Promise resolving when update is finished

Overrides

ThreePlugin.update