โ† Back to Home โ† Back to Projects

Glyphmaster - 3D RPG with Gesture-Based Spellcasting

Sep - Dec 2024

Technologies: Three.js, WebGL, Socket.io, MediaPipe HandPose, Python (Flask), TensorFlow.js, HTML/CSS/JS

๐Ÿ“œ Overview

Glyphmaster is a 3D action RPG where players become wizards, drawing magical glyphs with mouse or hand gestures to cast spells. Battle monsters across 8 fantasy worlds (40 levels + infinite procedurally generated level), collect pets, and duel other players in real-time multiplayer. All core mechanics were implemented from scratch using Three.js.

โš™๏ธ 1. Basic Game Mechanisms (Built from Scratch with Three.js)

Game UI
Left: tutorial text; bottom right: permanent guide; centre: glyph hint overlay.

๐Ÿ—บ๏ธ 2. Single Player Levels & Scenes

World map
8 worlds ร— 5 levels = 40 hand-crafted levels (map drawn with Inkarnate)

๐Ÿ”ฎ 3. Magic Glyph Identification Algorithm (Core Innovation)

Unlike traditional gesture recognition, our algorithm evaluates drawn glyphs without fixed templates, allowing for size variation, rotation, and natural drawing inaccuracy.

6 Different Magic Glyphs
Different Magic Glyphs
  1. Drawing capture: Player draws on an off-screen canvas via mouse drag or hand-pose tracking (MediaPipe).
  2. Bounding box & normalization: Compute bounding box to obtain radius r and center (cx, cy) of the drawn shape.
  3. Binary downsampling: Convert the canvas to a small binary image (e.g., 64ร—64) to reduce computation.
  4. Distance to glyph primitives: For each of the 7 glyph definitions (combinations of straight lines, circles, arcs), we compute the distance from every binary pixel to the closest primitive.
    • Width tolerance = 0.1 ร— radius - pixel is โ€œinsideโ€ if distance < tolerance.
    • This function is also used to draw the translucent hint overlay in the centre of the screen.
  5. Dilation with inside/outside logic:
    • Original drawing is only 1-pixel wide; we dilate it to 0.1 ร— radius width, but not standard dilation:
    • If original pixel is inside the glyph โ†’ only dilated pixels inside the glyph are drawn.
    • If original pixel is outside the glyph โ†’ only dilated pixels outside are drawn.
    • This preserves shape boundaries and prevents over-scoring.
  6. Accuracy calculation:
    accuracy = (% of drawn pixels inside) - (% of drawn pixels outside)
    This subtractive formula prevents a simple circle from achieving high accuracy for all glyphs.
  7. Selection: Repeat steps 4-6 for all 7 glyphs, pick the one with the highest accuracy.

โœจ 4. Magic Spell Effects & Visuals

Fire spell
Fire glyph - fireball with particle trail and burn effect
Water spell
Water glyph - Area-of-effect splash

All particle effects (trails, explosions) are implemented with a custom Particle class using Three.js points.

๐Ÿ‘พ 5. Monsters Finite State Machine

Multiplayer
Monsters and Enemies
IDLE (wander)
โ†’
CHASE (alert distance)
โ†’
DRAW (attack distance)
โ†’
SHOOT
โ†บ

๐Ÿพ 6. Pet Finite State Machine

FOLLOW OWNER
โ†’
CHASE ENEMY (in sight)
โ†’
ATTACK
โ†’
RETURN (enemy lost)

๐ŸŒ 7. Multi-player Real-Time Battle Synchronization

Multiplayer
1v1 real-time battle with synchronised health bars and spells.

๐Ÿ–๏ธ Hand-Pose Drawing Integration

Hand pose drawing
Drawing fire glyph using index finger tracked by MediaPipe.
Pet generation
3D pet generated from a real-world cup via AI pipeline.

MediaPipe HandPose model is loaded once; fingertip positions are smoothed over three frames to reduce jitter. A fist gesture triggers โ€œpen upโ€.