How I built a 3D video store in the browser with Three.js and zero assets
I wanted a 3D scene that loads instantly on a phone, so I set one rule: no image files, no models. Not one .jpg, not one .glb. Everything you see in the store is generated when the page loads.
That turned out to be a useful constraint, because the whole thing ships as plain HTML and ES modules with no build step. It also made me learn a few things the hard way.
Demo: https://rewind-video-3d.vercel.app/ Source: https://github.com/MostafaMedhat19/rewind-video-3d
A seeded catalog
The store has 8 genres with 16 tapes each: 128 films that do not exist. Each one gets a title, a year, a director, three cast members, a runtime, a rating and a one-line blurb, all from two word lists per genre and a seeded random function.
function mulberry32(a) {
return function () {
a |= 0;
a = (a + 0x6d2b79f5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
Same seed, same store, every time. I can change one genre and know exactly which covers change. There is no data file; the catalog is built in a loop at startup.
Painting 128 covers into one canvas atlas
The covers are drawn with the 2D canvas API, not loaded. Each one is a 128x192 cell: gradient background, a genre strip, the title, the cast, a rating badge and a "RENTAL" sticker. Six colour schemes are picked by a hash of the film id, so the shelves look varied without looking random.
All 128 covers are painted into a single canvas, 16 columns by 8 rows at 1.5x scale, and that canvas becomes one texture. One texture means no texture swaps as you walk, and one draw call for the covers. With 128 separate textures this would stutter on a phone.
One InstancedMesh for every tape on every shelf
The store holds about 2,700 tapes, five shelves high on both sides of a 60-metre aisle. They are all one InstancedMesh of a 0.2 x 0.3 x 0.045 box. Each instance has to show a different cover from the atlas, so the geometry carries an instanced attribute with the cell index and a custom shader does the maths:
float c = floor(vCell + 0.5);
float cx = mod(c, uCols);
float cy = floor(c / uCols);
vec2 uv = vec2((cx + vUv.x) / uCols, 1.0 - (cy + 1.0) / uRows + vUv.y / uRows);
col = texture2D(uMap, uv).rgb;
The same shader does the lighting: a soft sheen at the top of each box so it reads as plastic, a fake ceiling-lamp band that follows the aisle, and exponential fog that fades the far end out. Doing the fog in the shader instead of relying on the built-in material meant the tapes and the fog colour match exactly.
Walking
Movement is one number: z. The camera is locked to the aisle at eye height 1.55, with a small head bob that scales with how fast you are moving. Every input sets a target, and the camera eases toward it:
const k = 1 - Math.exp(-dt * 7);
z += (zTarget - z) * k;
Wheel, drag, arrow keys and the on-screen buttons all just change zTarget, so nothing fights anything else. The buttons do two things: a quick tap jumps to the next genre, holding walks. That one was worth adding, because holding a button to cross the whole store was slow.
Picking a tape
A click casts a ray against the InstancedMesh. The hit gives an instance id, which maps to a catalog entry and a shelf position. The picked tape is not moved: a second InstancedMesh with one instance is placed at the camera and animated there, while the shelf copy is scaled to zero. Putting it back runs the same animation backwards.
One trap: an InstancedMesh's bounding sphere does not update when instances move, so raycasts can miss them until it is recomputed. I keep picking on the shelf instances only, which never move, and hide rented ones with a zero-scale matrix.
Rentals that survive a reload
The small thing that made the demo feel real: renting a tape writes to localStorage, the slot stays empty after a reload, and a counter in the corner shows how many are out.
localStorage.setItem('rewind-rentals', JSON.stringify(rentals));
What I would do next
- Ambient sound.
- A tape that plays a fake trailer.
- More genres.
- And the mobile controls need another pass: the buttons work, but the tap-versus-hold window is a judgement call.
If you want to look around, the demo and the source (MIT) are linked above. Feedback on the mobile controls is the part I would find most useful.
Comments
No comments yet. Start the discussion.