3D Material Finish Switcher
What it does
Full-viewport Three.js hero with a GLB pocket watch whose finish is swapped at runtime from a JSON of PBR presets: three MeshPhysicalMaterial recipes plus a real MeshTransmissionMaterial for the crystal, lit by nothing but a generated studio HDRI whose bright panel is aimed at the exact cone a flat case reflects. The dial stays towards the camera — the case sways instead of turning, and a drag eases back — so the highlight travels across the finish in every frame. A static poster is the LCP, the canvas is only built when the section enters the viewport, and a capability gate plus a runtime frame-time ladder decide whether the visitor gets transmission, plain physical, or the still.
How it's built
| Category | 3d-webgl |
|---|---|
| Tech | three, @pmndrs/vanilla |
| Complexity | section |
| Performance cost | heavy |
| Mobile-safe | yes |
How it works
A pocket watch hangs in a dark hero and sways gently with its dial towards the camera. Four buttons name four finishes, brushed metal, iridescent, red lacquer and cut glass, and pressing one rebuilds the case material in the same frame while the watch swings round far enough to show the new finish on its rim before settling back. There is no GSAP here and no tweening library: the motion is a single render loop where an idle sway is added to an angular velocity that the pointer feeds and friction slowly takes back.
Every finish is a physically based material in Three.js, and none of the numbers live in the JavaScript. They are read at runtime from a data file, mesh by mesh, so adding a fifth finish is an edit to that file rather than to the code. The glass crystal over the dial is a real transmission material: it refracts what is behind it, instead of being a transparent sheet.
Why the lighting is the hard part
There are no lights in the scene at all. The only light is an image-based environment, and on this object it decides everything through a very small window. A watch case is almost a flat disc, so it reflects a narrow cone of directions, and whatever fills that cone is the finish. A generic studio photo puts one evenly lit wall in that cone, and under an even wall polished steel and matte plastic look the same. The environment used here is generated and aimed at the geometry: a soft panel whose edge lands exactly where the centre of the case looks, which is what splits the case into a lit half and a dark half and makes it read as metal.
The refraction has its own cost. The glass needs a picture of the scene behind it, which means an extra render pass per frame with the glass itself hidden from that pass. The component shares a single pass between every glass surface instead of paying one per material, which matters on the all-glass finish. One of the finishes also depends on surface data that the compressed model no longer carries, and handled naively it renders as a flat plastic egg with no reflection; the prompt explains how to detect that and fall back.
Performance and mobile
This is a heavy scene, so it is built to be skipped. A static poster image paints first. The canvas is only created when the section scrolls into view and is paused when it leaves. Before anything downloads, a capability check decides a ceiling: reduced motion, data saver or a weak device get the poster and nothing else, while software-rendered WebGL and small touch screens get the physical materials without transmission. While it runs, the component measures frame time and steps quality down rung by rung, never back up, until it falls back to the poster if it has to.
Rebuild it with AI
This component's prompt is part of the paid library. Below you can read how it starts; the full prompt, the exact structure, timing and easing an AI agent needs to rebuild the effect, unlocks with any paid plan, yearly or lifetime.
# 3D Material Finish Switcher
## Goal
Build a full-viewport hero for a watch atelier. A single 3D object — a vintage pocket watch — hangs slightly right of centre, swaying gently about its own axis with the dial towards the camera, lit by nothing but an image-based environment. Four pill buttons across the bottom left name four finishes: brushed metal, iridescent, red lacquer, cut glass. Press one and the case answers immediately, in the same frame: the material is rebuilt from a table of physically-based numbers and the case swings far enough to show the new finish on the rim before easing back to the dial, so the change reads as a gesture rather than a flicker. The glass crystal over the dial is a **real transmission material** — it refracts what is behind it — while everything else is `MeshPhysicalMaterial`.
Four things separate this from a spinning-model demo, and all four are load-bearing:
1. **No PBR value is written in the JavaScript.** Every finish is read at runtime from a JSON file, mesh by mesh. Adding a fifth finish is a change to that file, not to the code.
2. **The environment is aimed, not chosen.** A watch case is an almost flat disc, so it reflects a narrow cone of directions and whatever fills that cone *is* the finish. The lighting here is a generated studio whose bright panel has its feathered edge exactly where the centre of the case looks — that edge is what splits the case into a lit half and a dark half, and it is the difference between a polished object and a plastic one.
3. **A static poster is the first thing that paints**, and on a device that should not be running this scene it is the *only* thing that paints. The canvas is never created until the section is on screen.
4. **The quality degrades by measured frame time, not by guesswork** — buffer resolution, then pixel ratio, then transmission itself, then back to the poster.
## Tech
Vanilla HTML/CSS/JS with ES module imports. **No GSAP, no Lenis, no scroll library, no tweening library at all.** The motion is one `requestAnimationFrame` loop: an idle sway plus an angular velocity the pointer feeds and friction takes back.
Runtime dependencies (both npm):
- `three`
…
Premium prompt
Unlock this prompt, and every other one
From $99/year, or $139 once for lifetime access. Commercial license included.
See pricing Or start with the free set Already bought? Sign in
New components in your inbox
One email a week, only when new components ship, each with its live demo and prompt.