Interactive Vision From Zero · Episode 28

Face Jutsu — Your Face in Every Material

Face Jutsu — Your Face in Every Material is Episode 28 of Interactive Vision From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.

Part of the MasterAllArts Creative 3D Roadmap .

← Interactive Vision From Zero Bonus · Episode 28
Bonus · Episode 28 · Interactive Vision From Zero

The particle episodes drew your face out of dots. This one gives it a surface. MediaPipe's 468 face landmarks aren't just a point cloud — they come with a fixed triangulation, the same 898 triangles every time, so the landmarks are really the moving vertices of a complete face mesh. Once it's a mesh, it can wear a material — and that's the bridge to the hand-glass-cube project: we lift its real materials (the refractive glass, the water gel, liquid chrome, fire, lightning) and paint your tracked face with them. Your face, cast in glass, refracting the world behind it.

The demo is alive on load with a synthetic, gently-talking face. Switch material to recast it; the kanji "jutsu" title fires on each change. Hit use my camera and the mesh deforms to your face in real time — blink, open your mouth, tilt your head — wearing whichever material you picked.

0 fps
drag to orbit · switch material →
🔒 runs on-device · nothing leaves your machine
synthetic face · 468 verts · 898 tris
Glass — a refractive mask that bends the scene behind your face.

🔒 The camera button runs MediaPipe's Face Landmarker entirely in your browser. No frame is ever uploaded; nothing leaves your machine. Until you press it, the demo runs on a synthetic face and makes zero network requests.

What you're looking at

A single triangle mesh whose 468 vertices are wherever the face landmarks are this frame, and whose triangles never change. Deform the vertices, recompute the normals, and you have a head-shaped surface that follows a face. Swap the material on that one mesh and the same face becomes glass, water, metal, or fire — because in Three.js, geometry and material are independent. This is exactly how the hand-glass-cube effects are built (a shape + a swappable material); here the shape happens to be you.

468 landmarks ──► vertex positions ┐ 898 fixed triangles ─────────────────┼──► one BufferGeometry ──► Mesh │ ▲ pick a material (glass/water/…) ──────┴────────────┘ (geometry + material are independent) per frame: positions[i] = landmark[i] → geometry.computeVertexNormals()

The materials

Each is a near-verbatim lift of a hand-glass-cube effect's material — the shape changed from a cube to your face, the material did not:

  • Glass — a MeshPhysicalMaterial with transmission: 1, a glassy IOR and a touch of dispersion. It refracts whatever is behind it (here, a colored backdrop), so your face becomes a clear lens.
  • Water gel — the same family, tuned bluer and softer (ior 1.33, clearcoat, a faint cyan attenuation) — the Mizu look.
  • Chrome — metalness: 1, near-zero roughness, lit only by the environment: a liquid-metal mask.
  • Fire / Lightning — emissive ShaderMaterials with a fresnel rim and a time-driven flicker; no lights needed, the face glows from within.

How the code works

(a) Build the mesh once from the canonical triangulation

The 898 triangles never change, so the index buffer is set once. The vertex positions start at the canonical neutral face (which also drives the no-camera demo). Both the neutral verts and the triangle list are baked from MediaPipe's canonical_face_model, so vertex i is the same facial point as landmark i:

import { FACE_NEUTRAL, FACE_TRIS } from './face-mesh-data.js';

const geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.BufferAttribute(FACE_NEUTRAL.slice(), 3));
geo.setIndex(new THREE.BufferAttribute(FACE_TRIS, 1));   // 898 triangles, fixed forever
geo.computeVertexNormals();

const mesh = new THREE.Mesh(geo, MATERIALS.glass);     // geometry + material, independent
scene.add(mesh);

(b) Deform every frame — one path for synthetic + camera

Whether the vertices come from a synthetic "talking" neutral face or from your live landmarks, the move is identical: write 468 positions, then recompute normals so the lighting and refraction look right on the new shape:

function deform(srcXYZ) {              // srcXYZ: 468 world-space points
  const p = geo.attributes.position.array;
  for (let i = 0; i < 468; i++) {
    p[i*3] = srcXYZ[i*3]; p[i*3+1] = srcXYZ[i*3+1]; p[i*3+2] = srcXYZ[i*3+2];
  }
  geo.attributes.position.needsUpdate = true;
  geo.computeVertexNormals();              // the step people forget → flat, wrong-lit glass
}

// camera path: map each landmark to world (mirror-X), recenter on the mean
//   p[i] = ((0.5 - lm[i].x)*W, (0.5 - lm[i].y)*H, -lm[i].z*D) − centroid

(c) Swap the material — that's the whole "jutsu"

Recasting your face is one assignment. The geometry, the tracking, the deform loop are all untouched; only mesh.material changes:

matSelect.addEventListener('change', () => {
  mesh.material = MATERIALS[matSelect.value];   // glass → water → chrome → fire → …
  announceJutsu(matSelect.value);               // 水晶 / 水 / 鋼 / 火 / 雷
});

Common pitfalls

  • The face is faceted / lit wrong after it moves. You deformed the vertices but didn't call computeVertexNormals(). Transmission and metal need correct normals every frame, or the surface looks like crumpled foil.
  • Glass shows nothing / looks solid black. Transmission needs an environment to refract and reflect. Set scene.environment from a PMREMGenerator (here, RoomEnvironment) and give the material some thickness. With nothing behind it, a glass face has nothing to bend.
  • The mesh is inside-out / triangles missing. OBJ faces are 1-indexed; subtract 1 when building the index buffer, and use side: THREE.DoubleSide so you see the back of the open face shell.
  • The live face is mirrored or drifts off-screen. Map X as 0.5 − x (selfie) and subtract the landmark centroid each frame so the head stays centered no matter where you sit.
  • It judders at the silhouette. Raw landmarks are noisy; smooth each vertex toward its target (a small lerp) instead of snapping — the same smoothing the hand episodes use.

Exercises

  1. Refract the webcam. Add a video-textured plane behind the mesh (the hand-glass-cube backdrop trick) so the glass face refracts the real room, not just a gradient.
  2. Mouth-driven emissive. In the fire material, read the lip-gap landmarks and push emissiveIntensity up as you open your mouth — breathe fire.
  3. Two materials at once. Render the mesh twice — a chrome pass and a glass pass at slightly different scales — for a clear shell over a metal core.

What's next

You've now driven a face four ways: as flat filters (Ep 12), as a point cloud (Eps 25–26), as a morphing swarm (Ep 27), and now as a material-bearing surface. The full hand-glass-cube project is where each of these materials lives in production form — wire its glass/water/chrome straight onto this mesh and you've fused the two projects.