mediapipe-loop
Source: mediapipe-loop.js:14
Runtime loop for MediaPipe FaceLandmarker.
Loads the 478-landmark MediaPipe face mesh model, runs inference against the lab <video> element, and dispatches gstmxx.events.landmarks3d whenever a throttled new video frame has landmarks available. This module deliberately runs beside the face-api engine with separate models and backend state, so 3D overlays and future plugins can listen to the shared event bus without changing the 2D recognition engine.
Instance Methods
getFrameDelayMs(): number
Reads the MediaPipe loop throttle from the lab FPS selector and falls back to the project default interval when the UI control is missing or invalid.
Returns
number— Milliseconds to wait between FaceLandmarker inferences.
- See:
- tick - Uses the delay to avoid running MediaPipe on every animation frame.
waitForVideoReady(v: HTMLVideoElement): Promise.<void>
Waits until the webcam video element has enough data for MediaPipe video-mode inference. Startup uses this so the first detectForVideo call happens only after the camera stream has produced usable frame data.
Parameters
v(HTMLVideoElement) — Lab webcam video element.
Returns
Promise.<void>— Resolves immediately when the video is already ready.
- See:
- init - Waits for the camera stream before announcing `mediapipeReady`.
init(): Promise.<void>
Initializes the MediaPipe landmark loop after the Ghostmaxxing UI has exposed window.gstmxx, the event bus, and the webcam video element. It loads the CDN FaceLandmarker task, exposes the FaceLandmarker constants for UV/3D plugins, logs readiness, emits mediapipeReady, and starts the animation loop. The Italian warning and error messages in this function report missing gstmxx.events, missing #video, or MediaPipe load failure during startup.
Returns
Promise.<void>— Resolves after setup starts the loop, or exits early when prerequisites fail.
- See:
- main - Dispatches `ghostatiReady` once `window.gstmxx`, state, and DOM handles are ready.
- tick - Started after MediaPipe and the video stream are ready.
- initPlugins3dLoader - Receives `FaceLandmarker` through `window.gstmxx.FaceLandmarker`.
tick(): void
Runs the per-frame MediaPipe work: throttles duplicate/too-fast video frames, extracts the current 478-point mesh, caches it on window.gstmxx.lastLandmarks3d, and publishes landmarks3d for overlays, 3D ghostyles, and efficacy compositing. The cached landmarks let engine-3d and plugins reuse the latest mesh without re-running FaceLandmarker inference.
Returns
void
- See:
- init - Starts the loop after `mediapipeReady` is dispatched.
- tick - Re-schedules itself with `requestAnimationFrame` while running.
- onLandmarks3d - Consumes `landmarks3d` to repaint the bounding-box/mesh overlay.
- initPlugins3dLoader - Consumes `landmarks3d` to render active `paintUV` ghostyles.
- compositeAndDetect3d - Reads cached landmarks for 3D efficacy compositing.