Interactive Vision From Zero · Episode 10
Puppet an Avatar
Puppet an Avatar is Episode 10 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 .
So far the pose has driven dots and lines — a glowing skeleton that maps your body but still looks like a debug overlay. This episode crosses the line into puppetry. We take the same 33 landmarks and hang a little character off them: a head, a torso, two arms, two legs. You become the puppeteer. Wave, and the avatar waves back. Lean, and it leans. The dots disappear and a creature made of math copies your every move — that uncanny, delightful little jolt of "it's me, but it's not me."
The demo below boots alive: a synthetic walk cycle drives a styled character on first paint, no webcam, nothing downloaded. Step the stage dropdown from raw skeleton up through stick puppet, fleshed limbs, a face that tilts with your shoulders, and finally smoothing — the one trick that turns a twitchy mannequin into something that glides. When you're ready, click use my camera and the avatar leaves the synthetic walk and starts mirroring you, because everything downstream of the landmarks can't tell the two apart.
🔒 The camera button runs the pose model entirely in your
browser. No frame is ever uploaded; nothing leaves your machine.
Until you press it, the avatar is puppeteered by a synthetic walk and makes zero network
requests.
What you're looking at
An avatar — head, body, four limbs — pinned to a moving body pose. The trick of the whole episode is that we never animate the character by hand. There is no walk cycle authored into the puppet. Instead, every frame we read 33 landmarks, decide which pairs of them are bones, and draw a limb between each pair. The pose moves; the avatar follows. That's retargeting, or rigging — mapping a skeleton you measured onto a character you drew — and it's exactly how a motion-capture suit drives a movie creature, just with a webcam instead of a $50,000 rig.
Step the stage dropdown to watch the puppet get built up one layer at a time: bare skeleton, then sticks, then flesh, then a face, then the smoothing that removes the jitter. Drag the smoothing slider in any stage to feel raw versus glided. Switch style to reskin the same rig three ways.
The pose, and what a bone is
Episode 09 introduced the body model: 33 landmarks, each
{x, y, z, visibility}, with x, y normalized to
[0, 1] in image space. The ones we puppet with are the joints:
A bone is just two landmarks. The upper arm is the bone from shoulder
(11) to elbow (13); the forearm is elbow (13) to
wrist (15); the thigh is hip (23) to knee (25), and
so on. List every pair once and you have a rig. We draw a shape — a thick line, a tapered
capsule — along each pair, and the character is born. Get a pair wrong (say, you connect
shoulder to knee) and a limb shoots across the body; that's the number-one bug,
so we keep the bone list short and explicit.
Stage 1 — The pose skeleton
The reference view, same as Episode 09: landmarks as dots, the standard
POSE_CONNECTIONS drawn as thin bones. This is the data we're about to dress
up. Nothing here is "a character" yet — it's the armature underneath one. Keep this view
in your back pocket forever: when your avatar limbs go to the wrong place, drop back to
the skeleton and you'll instantly see whether the problem is the pose or your
drawing.
Stage 2 — Stick puppet
The smallest possible character. We walk the same bone list, but instead of thin debug lines we stroke each bone as a thick, round-capped segment — fat crayon strokes from joint to joint. Rounded caps matter: they fake a ball-joint at every elbow and knee so the figure reads as connected, not as a pile of disjoint sticks. Already it stops looking like a diagram and starts looking like a stick person mid-stride.
Stage 3 — Fleshed puppet
Now we give the sticks volume. Each limb becomes a tapered capsule — wide at the joint, narrower toward the tip — so an upper arm is chunky near the shoulder and slims at the elbow, like a real limb. We add a torso as a filled quad through the four shoulder/hip landmarks, and a round head sitting above the shoulder line near the nose. Suddenly there's a body. The proportions come entirely from the landmark distances, which is exactly why the next pitfall — clamping those distances — matters.
Stage 4 — Head + face follow
A blank circle for a head is lifeless. Here the head tilts with the shoulder line: we take the vector from the left shoulder to the right shoulder, measure its angle, and rotate the whole head by it. Drop one shoulder and the avatar cocks its head with you. Then we add two simple eyes, positioned in the head's rotated frame so they bank as it tilts. It's two dots and an angle, but the character instantly feels aware.
Stage 5 — Smoothing
This is the stage that earns the episode. Raw landmarks — synthetic and real —
jitter. A wrist that's "holding still" actually buzzes a pixel or two every frame, and on
a fleshed limb that buzz is grotesque: the whole forearm vibrates. The fix is one line per
joint. We keep a smoothed copy of every landmark and, each frame, ease it
a fraction of the way toward the raw target — a lerp. Slide
smoothing to 0 to feel the raw twitch; slide it up and the
puppet turns to honey, gliding into each pose with a beat of follow-through. Too high and
it goes laggy and underwater — there's a sweet spot, and finding it is the craft.
Stage 6 — A styled character
Everything together, dressed up. The fleshed, smoothed, head-tilting rig gets a palette and a couple of accents — pick from a mint robot, an amber bear, or a violet ghost with the style dropdown. It copies the synthetic walk out of the box; click use my camera and the same character mirrors you. This is the shippable thing: a VTuber-style avatar in ~200 lines, no rig file, no skeleton export — just landmarks in, character out.
How the code works
The architecture is the series' usual one: a single onLandmarks(pose)
path renders both the synthetic walk and the camera. Both hand it the same shape — an
array of 33 {x, y, z, visibility} objects in normalized space — so nothing
downstream knows or cares which is live. Four pieces carry the avatar.
(a) Mapping pose joints → bone segments
A bone is two landmark indices. We keep a small named list of the limbs we actually
draw, each with the two endpoints and a base thickness, plus the standard
POSE_CONNECTIONS for the skeleton stage. The mirror flip
lives in the pixel helper: this is a selfie view, so we map x to the screen
as (1 - lm.x) * W. Without it, raising your right arm raises the avatar's
left — the classic "why is it backwards?" Apply it to the synthetic pose too, so both
modes agree.
// The skeleton edge list (Stage 1), straight from MediaPipe.
const POSE_CONNECTIONS = [
[11,12],[11,23],[12,24],[23,24], // torso
[11,13],[13,15],[12,14],[14,16], // arms
[23,25],[25,27],[24,26],[26,28], // legs
[0,11],[0,12], // neck-ish
];
// The limbs we actually flesh out. A bone = [from, to]. w = thickness scale.
const BONES = [
{ a: 11, b: 13, w: 1.0 }, { a: 13, b: 15, w: 0.8 }, // left upper / fore arm
{ a: 12, b: 14, w: 1.0 }, { a: 14, b: 16, w: 0.8 }, // right upper / fore arm
{ a: 23, b: 25, w: 1.3 }, { a: 25, b: 27, w: 1.0 }, // left thigh / shin
{ a: 24, b: 26, w: 1.3 }, { a: 26, b: 28, w: 1.0 }, // right thigh / shin
];
// normalized [0,1] → canvas pixels, mirrored on X for the selfie view.
const px = (lm) => ({ x: (1 - lm.x) * W, y: lm.y * H });
(b) Drawing a tapered-capsule limb
The shape that makes flesh. Given two points and a start/end radius, we build a capsule
by hand: walk the perpendicular of the bone direction out by r0 at one end
and r1 at the other, connect the four corners, then cap each end with an arc.
A wider start radius than end radius gives the taper. Fill it, and an arm is no longer a
line — it has a silhouette.
// Tapered capsule from A→B, radius r0 at A shrinking to r1 at B.
function capsule(ctx, ax, ay, bx, by, r0, r1) {
const dx = bx - ax, dy = by - ay;
const len = Math.hypot(dx, dy) || 1e-5;
const nx = -dy / len, ny = dx / len; // unit perpendicular
ctx.beginPath();
ctx.moveTo(ax + nx * r0, ay + ny * r0); // one side of A
ctx.lineTo(bx + nx * r1, by + ny * r1); // same side of B
ctx.arc(bx, by, r1, Math.atan2(ny, nx), Math.atan2(-ny, -nx)); // round cap at B
ctx.lineTo(ax - nx * r0, ay - ny * r0); // back down the other side
ctx.arc(ax, ay, r0, Math.atan2(-ny, -nx), Math.atan2(ny, nx)); // round cap at A
ctx.closePath();
ctx.fill();
}
(c) Per-joint smoothing (lerp toward target)
The jitter killer. We hold a parallel array of smoothed landmarks. Every frame, each
smoothed point eases a fraction of the way toward its raw target — an exponential lerp.
The smoothing factor is how much of the old value we keep: 0
means snap to raw (jittery), 0.9 means crawl toward it (glassy, slightly
laggy). Crucially this is also where we handle low-visibility joints: if
a landmark's visibility drops (an arm leaves frame), we simply don't update
its target, so the limb holds its last good position instead of snapping to
garbage.
// smoothed[i] eases toward raw[i] each frame. s in [0,1) = how much history to keep.
function smoothPose(raw, s) {
for (let i = 0; i < raw.length; i++) {
const r = raw[i], sm = smoothed[i];
if ((r.visibility ?? 1) < 0.5) continue; // hold last good pos on lost joints
sm.x += (r.x - sm.x) * (1 - s); // lerp: more s = slower glide
sm.y += (r.y - sm.y) * (1 - s);
sm.z += ((r.z ?? 0) - sm.z) * (1 - s);
}
return smoothed;
}
(d) Head orientation from the shoulder vector
How the head knows to tilt. The line between the two shoulders is the avatar's "level."
Its angle — atan2 of the shoulder-to-shoulder vector — is the head roll. We
place the head above the midpoint of the shoulders (nudged toward the nose), size it from
the shoulder width so it scales with the body, and draw the eyes in that rotated frame so
they bank with the tilt. Mirror-aware: because the pixels are already flipped, the angle
comes out correct for a selfie.
// Head pose from the shoulder line (already in mirrored pixel space).
function headFromShoulders(L, R, nose) {
const midx = (L.x + R.x) / 2, midy = (L.y + R.y) / 2;
const shoulderW = Math.hypot(R.x - L.x, R.y - L.y);
const roll = Math.atan2(R.y - L.y, R.x - L.x); // tilt of the shoulder line
const radius = shoulderW * 0.42; // head scales with the body
// sit the head above the shoulders, biased toward the detected nose
const cx = midx + (nose.x - midx) * 0.5;
const cy = midy - shoulderW * 0.55 + (nose.y - midy) * 0.2;
return { cx, cy, radius, roll };
}
Common pitfalls
- A limb shoots across the body. You paired the wrong landmarks. A
bone is two adjacent joints — shoulder→elbow, elbow→wrist — never
shoulder→ankle. Keep an explicit
BONESlist and read it twice; almost every "broken avatar" is one bad index. - The avatar buzzes / vibrates. You're drawing raw landmarks. They're noisy every single frame, and flesh amplifies it. You must smooth — lerp each joint toward its target (Stage 5). This is not optional polish; an unsmoothed fleshed avatar is unwatchable.
- Limbs stretch and snap to silly lengths. Don't draw limb thickness (or length) straight from raw distances — a momentary mis-detection makes a forearm balloon or telescope. Clamp/normalize: derive a body scale from the shoulder width and size every limb relative to that, so proportions stay stable even when one joint glitches.
- It's mirrored / waves with the wrong arm. Selfie view needs the
1 - xflip in the pixel mapping, applied in both synthetic and camera modes. Skip it and the puppet is your mirror image's mirror image. - A limb jumps to the corner when it leaves frame. Lost tracking
returns low-
visibility(or absent) landmarks near0,0. Guard onvisibilityand hold the last good position instead of lerping toward the bad one — a frozen arm looks far better than one snapping to the top-left.
Exercises
- Add hands and feet. MediaPipe Pose includes wrist-adjacent points
(
17–22) and foot points (29–32). Draw little capsule mitts off the wrists and shoe shapes off the ankles so the avatar isn't an amputee. Bonus: rotate each hand to the forearm's angle. - A second outfit/skin. The
styledropdown is just a palette object (limb color, torso color, accent). Add a fourth — your own character — and maybe one accent shape (a hat near the head, a belt across the hips) drawn in the head/torso frame so it tracks the body. - Squash on a jump. Track the hips' vertical velocity; when both feet leave the ground (a jump), briefly squash the avatar — scale it wider and shorter for a few frames, then spring back. Classic squash-and-stretch, triggered by a detected jump. (Detecting the jump from joint motion is the doorway to Episode 11.)
What's next
Episode 11 — Rep Counter. We stop drawing the body and start reading it: compute the angle at the knees and elbows from three landmarks each, watch those angles cross thresholds, and count squats and jumping jacks automatically — with hysteresis so a wobble at the bottom of a squat doesn't tick the counter twice. The avatar you just rigged becomes a workout coach.