engine

Source: engine.js:2


Static Methods

detectFaceInCam(drawOverlay: boolean): Promise.<(Object|null)>

Detect a face in the webcam video and optionally draw an overlay. Returns the face detection result or null if no face is found.

Parameters

  • drawOverlay (boolean) — Whether to draw the detection overlay.

Returns

  • Promise.<(Object|null)> — Detection result, faceapi object.
  • See:
    • saveFace - uses detectFaceInCam before saving a face.
    • findFace - uses detectFaceInCam to compare against stored faces.
    • computeCompositeMetrics - uses detectFaceInCam as the baseline detection.

compositeAndDetect(liveResult: Object): Promise.<Object>

Build a canvas with video compositing and the active 2D/3D Ghostyle overlay. Calls the active 2D Ghostyle's onDraw() hook to render the overlay. Executes face-api detection on the composited frame. Executes a Face API detection with landmarks and descriptor on the composite. Returns an object containing the canvas, obfuscatedResult, and weakDetection flag. If detection with the normal threshold (scoreThreshold: 0.5) fails, it retries with a relaxed threshold (0.1) to still extract numeric metrics from the composite — useful as a "makeup efficacy indicator" even beyond the detection threshold. weakDetection indicates when a fallback detection was required.

Parameters

  • liveResult (Object) — Result from the live face detection.

Returns

  • Promise.<Object> — An object with canvas, obfuscatedResult, and weakDetection.
  • See:
    • findFace - uses this function to obtain a composite for post‑makeup comparison.
    • computeCompositeMetrics - uses detectFaceInCam as the baseline detection.

runEffectPass(): Promise.<boolean>

Run a single effect pass: performs face detection (with optional landmarks) and draws the effect overlay. Manages state flags to avoid concurrent inference.

Returns

  • Promise.<boolean> — Whether the overlay should be cleared (no face detected without active effect).
  • See:
    • drawGhostyleOverlay - invoked to render the effect.
    • detectFaceInCam - used internally for detection when an active effect is present.

drawGhostyleOverlay( result: Object, includeDetectionScaffold?: boolean, )

Draw the effect overlay onto the canvas, optionally including the detection scaffold. Resizes the canvas, clears previous drawings, and renders the active effect style if present.

Parameters

  • result (Object) — Face detection result.
  • includeDetectionScaffold (boolean, optional, default: false) — Whether to draw the detection scaffold.
  • See:
    • runEffectPass - calls this to render overlay after detection.
    • drawDetectionScaffold - optionally used when includeDetectionScaffold is true.

drawDetectionScaffold( ctx: CanvasRenderingContext2D, resized: Object, )

Draw visual scaffolding for a detection result: bounding box, eye line, and facial landmarks. Useful for debugging and user feedback.

Parameters

  • ctx (CanvasRenderingContext2D) — Canvas context to draw on.
  • resized (Object) — Resized detection result containing box and landmarks.
  • See:
    • drawGhostyleOverlay - may call this when includeDetectionScaffold is true.
    • drawResult - calls this to display detection scaffold.

drawResult(result: Object)

Draw the detection result on the overlay canvas, including the detection scaffold and any active effect.

Parameters

  • result (Object) — Detection result.
  • See:
    • drawDetectionScaffold - used to draw scaffold.
    • drawGhostyleOverlay - effect drawing is performed here if active.

saveFace()

Capture the current face, save its descriptor and metadata to the local database, and log the action.

  • See:
    • detectFaceInCam - obtains the face data to be saved.

hasActivePlugin(): boolean

Determine whether a 2D or 3D effect plugin is currently active.

Returns

  • boolean — True if an effect plugin is active.
  • See:
    • findFace - checks plugin status before compositing.