<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9" -->

---
title: Building a Real-Time 3D Face Mask with MediaPipe,...
description: A detailed technical walkthrough shows how to build a real-time 3D face mask that tracks a webcam feed using MediaPipe's Face Landmarker, Threlte, and...
canonical: https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Building a Real-Time 3D Face Mask with MediaPipe, Threlte and Three.js | daily.dev
og:description: A detailed technical walkthrough shows how to build a real-time 3D face mask that tracks a webcam feed using MediaPipe's Face Landmarker, Threlte, and...
og:url: https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9
og:image: https://api.daily.dev/og/posts/PK2vu7lh9.png
og:image:alt: Building a Real-Time 3D Face Mask with MediaPipe, Threlte and Three.js
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Building a Real-Time 3D Face Mask with MediaPipe, Threlte and Three.js

**[Codrops](https://daily.dev/sources/codrops)** · 13 min read · 2 upvotes · 0 comments

## Summary

A detailed technical walkthrough shows how to build a real-time 3D face mask that tracks a webcam feed using MediaPipe's Face Landmarker, Threlte, and Three.js. It covers recovering Google's fixed 468-point face topology and triangulation from TensorFlow.js's models repo, extracting UV coordinates from MediaPipe's canonical_face_model.obj via a custom Node script, and matching the mesh projection to a mirrored, object-cover-cropped video feed using perspective camera math. The piece explains how to keep the hot per-frame landmark data outside Svelte's reactive graph for performance, and how to correctly compute vertex normals, texture flipping, and depth-aware positioning so the rendered mesh stays aligned with the tracked face.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://tympanus.net/codrops/2026/09/06/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js>

## Questions this post answers

### How do I map MediaPipe Face Landmarker's 468 face landmarks to a Three.js BufferGeometry with correct triangulation?

Use the flattened triangle index array from Google's TensorFlow.js face-landmarks-detection triangulation.js file, which contains 2,640 indices forming 880 triangles across 468 vertices. This array can be copied directly into a Uint16Array and attached as the geometry's index attribute, since its ordering already determines correct triangle winding and front-face orientation.

_Developers wiring up face-tracking meshes can find similar WebGL and MediaPipe deep dives curated on daily.dev._

### How do I get correct UV texture coordinates for MediaPipe's 468 face landmarks?

Extract vertex-to-UV mappings from Google's canonical_face_model.obj file, which contains 468 vertex records, 468 texture coordinate records, and 898 face records linking each vertex index to a UV index. Since counts match but file order does not correspond, parse the OBJ's face lines to build a vertex-to-UV map, then flip the V coordinate with 1.0 minus v to avoid an upside-down texture.

_daily.dev surfaces practical Three.js and asset-pipeline write-ups for developers debugging texture mapping issues._

### Why does my Three.js face mesh become upside down or misaligned when tracking with MediaPipe on a mirrored webcam feed?

An upside-down mask usually results from flipping both the UV data and the texture instead of just one; only one flip should occur. Misalignment with a mirrored, object-cover-cropped video also requires reproducing that same cropping math when computing scaleX and scaleY, and inverting the sign of X and Y coordinates to match the mirrored image and Three.js's opposing Y axis.

_daily.dev collects hands-on debugging guides for developers aligning camera-driven WebGL projections._

## Similar posts on daily.dev

- [Check Out This Off-Axis Projection Demo Using Face Tracking](https://daily.dev/posts/check-out-this-off-axis-projection-demo-using-face-tracking-9o0xyah2r) · 80 LEVEL · 0 upvotes · 0 comments
- [Real-time Face Detection at 30 FPS on CPU using Mediapipe in Python: A Step-by-Step Guide.](https://daily.dev/posts/real-time-face-detection-at-30-fps-on-cpu-using-mediapipe-in-python-a-step-by-step-guide--hwd9gsy0k) · Towards Dev · 2 upvotes · 0 comments
- [I Built an Invisibility Cloak in the Browser No Green Screen, No Model Training](https://daily.dev/posts/i-built-an-invisibility-cloak-in-the-browser-no-green-screen-no-model-training-phnytuc0a) · Medium · 0 upvotes · 0 comments
- [Creating an Interactive 3D Cluster with Three.js, TSL and Three Start](https://daily.dev/posts/creating-an-interactive-3d-cluster-with-three-js-tsl-and-three-start-y4sedpfai) · Codrops · 2 upvotes · 0 comments
- [Jump to play: Building with Gemini & MediaPipe](https://daily.dev/posts/jump-to-play-building-with-gemini-mediapipe-vbl6dhw1d) · Google Developers · 0 upvotes · 0 comments

---

Tags: [#computer-vision](https://daily.dev/tags/computer-vision), [#svelte](https://daily.dev/tags/svelte), [#threejs](https://daily.dev/tags/threejs), [#webdev](https://daily.dev/tags/webdev), [#webgl](https://daily.dev/tags/webgl)

[View this post on daily.dev](https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Building a Real-Time 3D Face Mask with MediaPipe, Threlte and Three.js","url":"https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9"},"datePublished":"2026-09-06T13:12:17.517Z","dateModified":"2026-10-15T02:22:47.142Z","description":"A detailed technical walkthrough shows how to build a real-time 3D face mask that tracks a webcam feed using MediaPipe's Face Landmarker, Threlte, and...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/dd162b8f677b331d10be63a05797639b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/dd162b8f677b331d10be63a05797639b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Codrops","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Codrops","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/codrops","url":"https://daily.dev/sources/codrops"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"computer-vision,svelte,threejs,webdev,webgl","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Codrops","item":"https://daily.dev/sources/codrops"},{"@type":"ListItem","position":3,"name":"Building a Real-Time 3D Face Mask with MediaPipe, Threlte and Three.js"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/building-a-real-time-3d-face-mask-with-mediapipe-threlte-and-three-js-pk2vu7lh9#faq","mainEntity":[{"@type":"Question","name":"How do I map MediaPipe Face Landmarker's 468 face landmarks to a Three.js BufferGeometry with correct triangulation?","acceptedAnswer":{"@type":"Answer","text":"Use the flattened triangle index array from Google's TensorFlow.js face-landmarks-detection triangulation.js file, which contains 2,640 indices forming 880 triangles across 468 vertices. This array can be copied directly into a Uint16Array and attached as the geometry's index attribute, since its ordering already determines correct triangle winding and front-face orientation. Developers wiring up face-tracking meshes can find similar WebGL and MediaPipe deep dives curated on daily.dev."}},{"@type":"Question","name":"How do I get correct UV texture coordinates for MediaPipe's 468 face landmarks?","acceptedAnswer":{"@type":"Answer","text":"Extract vertex-to-UV mappings from Google's canonical_face_model.obj file, which contains 468 vertex records, 468 texture coordinate records, and 898 face records linking each vertex index to a UV index. Since counts match but file order does not correspond, parse the OBJ's face lines to build a vertex-to-UV map, then flip the V coordinate with 1.0 minus v to avoid an upside-down texture. daily.dev surfaces practical Three.js and asset-pipeline write-ups for developers debugging texture mapping issues."}},{"@type":"Question","name":"Why does my Three.js face mesh become upside down or misaligned when tracking with MediaPipe on a mirrored webcam feed?","acceptedAnswer":{"@type":"Answer","text":"An upside-down mask usually results from flipping both the UV data and the texture instead of just one; only one flip should occur. Misalignment with a mirrored, object-cover-cropped video also requires reproducing that same cropping math when computing scaleX and scaleY, and inverting the sign of X and Y coordinates to match the mirrored image and Three.js's opposing Y axis. daily.dev collects hands-on debugging guides for developers aligning camera-driven WebGL projections."}}]}
```

