A 3D Product Page in React and Three.js: Scroll Becomes a Number, One Camera Shot per Panel, One Choice Drives Everything
Aurel One, a fictional pair of headphones built from plain three.js shapes, turns as you scroll, frames each feature with its own camera pose, repaints with 1 - e^(-dt*5) colour blending, and keeps a sticky buy box in sync, all from one scroll ref and one finish state. Phones get a still until they tap View in 3D.
What you will learn
- Turn scroll position into a progress number kept in a ref, so the 3D scene reads it every frame without React re-renders
- Blend between camera poses and damp toward them so the model glides
- Build a model from simple shapes (tube, lathe, torus) and blend finish colours frame by frame
- Drive the model, swatches and buy box from one piece of state, and lazy-load the 3D for phones
Before you start
- React useState, useRef and useEffect
- Three.js: what it can do
This is the kind of page brands pay agencies for: a 3D product page. Spin it, scroll it, buy it. A pair of headphones sits in the middle of the screen. You scroll, and they turn to show the part being described. You pick a colour, and they repaint. We cover the foundations: you don't have to memorise every line, but you should know what each part does so the code makes sense when the page grows.
The product is Aurel One, a fictional pair of headphones, built from simple three.js shapes, so there's no model file to download. The project uses React with React Three Fiber.

One page, four tricks
- Spin: the model turns as you scroll.
- Repaint: a swatch blends a new colour into the model.
- Buy: a buy box stays with you while you scroll, so the button is always one click away.
- Fast: phones get a light version, so the page loads quickly.
Spin: scroll becomes a number
At the top the headphones sit in their hero pose. Scroll a little and they start turning; at the Sound panel you're looking at the driver side. All of it is driven by one number, from useStoryProgress.ts:
export function useStoryProgress(el: RefObject<HTMLElement | null>, steps: number) {
const progress = useRef(0)
const [active, setActive] = useState(0)
useEffect(() => {
let frame = 0
const update = () => {
frame = 0
const box = el.current?.getBoundingClientRect()
if (!box) return
const t = Math.min(1, Math.max(0, -box.top / (box.height - innerHeight)))
progress.current = t * steps
el.current!.style.setProperty('--p', String(progress.current))
setActive(Math.round(progress.current)) // React skips the render when the number did not change
}
const onScroll = () => { if (!frame) frame = requestAnimationFrame(update) }
update()
addEventListener('scroll', onScroll, { passive: true })
addEventListener('resize', onScroll)
return () => { removeEventListener('scroll', onScroll); removeEventListener('resize', onScroll); cancelAnimationFrame(frame) }
}, [el, steps])
return { progress, active }
}
Ask where the story section is (box.top), divide by the section height minus the window height, and clamp between 0 and 1. Multiply by the number of steps and you get progress from 0 to 4. The exact value goes to three places:
Scroll it: one camera shot per panel
Each panel gets its own pose. A pose is a few numbers: rot turns the model, scale zooms, focus is the point we want to look at, and at is where that point lands on screen.
export const POSES: Pose[] = [
{ rot: [0.22, -0.62, 0], focus: [0, 0.1, 0], at: [0.35, -0.15, 0], scale: 0.8 }, // hero
{ rot: [0.12, -1.2, 0.05], focus: [1.15, -0.62, 0], at: [0.95, -0.05, 0], scale: 1.25 }, // Sound: driver side
{ rot: [0.55, 0.62, 0], focus: [0, 0.4, 0], at: [0.8, -0.1, 0], scale: 0.95 }, // Comfort: headband pad + cushions
{ rot: [-0.75, -1.25, 0], focus: [1.05, -1.1, 0], at: [0.85, 0.15, 0], scale: 1.35 }, // Battery: port + LED under the right cup
{ rot: [0.05, 1.35, -0.05], focus: [-1.15, -0.62, 0], at: [0.8, -0.05, 0], scale: 1.25 }, // ANC: microphones on the left cup
]
For the Sound panel, scale is 1.25 and the focus sits at the driver side. Inside useFrame, the rig blends between the two nearest poses and then chases the target:
useFrame((state, dt) => {
const p = reduced ? 0 : progress.current
const i = Math.min(Math.floor(p), POSES.length - 2)
// hold each pose for the middle of its panel, move in between
const t = smooth(Math.min(1, Math.max(0, (p - i - 0.2) / 0.6)))
const a = POSES[i], b = POSES[i + 1]
// ... lerp rot, focus, at and scale from a to b by t ...
easing.dampE(g.rotation, [T.rot[0] + idle, T.rot[1], T.rot[2]], 0.35, dt)
easing.damp(g.scale, 'x', T.scale, 0.35, dt)
// ...
else easing.damp3(g.position, goal, 0.25, dt)
})
Each pose is held for the middle of its panel, with movement in between. dampE chases the target rotation a little on every frame. That's why it feels smooth: the model never jumps, it glides, and it feels heavy, like a real product in your hand.
Headphones from simple shapes
- Headband: a
TubeGeometrythat follows an arc. Stretched on the z axis (the lecture's slide uses scale z 2.1), the round tube becomes a wide, flat band. - Ear cup: a
LatheGeometry. Give it a side profile,CUP_PROFILE, and three.js spins it around to make a smooth cup. - Cushion: a
torusGeometry, a donut, squashed a little withscale={[1, 1, 0.7]}.
Stretch a tube and you get a headband. Spin a profile and you get an ear cup.
Repaint it: a swatch blends the colour in
Each finish is one line in finishes.ts: a body colour, a metal colour, a cushion colour, and a UI colour for the page accent. The project has four (the lecture slide shows three of them):
export const FINISHES: Finish[] = [
{ id: 'graphite', name: 'Graphite', body: '#3b3b3e', metal: '#a4a7ad', cushion: '#2a2a2d', ui: '#c9ccd3' },
{ id: 'sand', name: 'Sand', body: '#cbbda5', metal: '#c9a476', cushion: '#a8977d', ui: '#e6c99a' },
{ id: 'sage', name: 'Sage', body: '#86957f', metal: '#cfd3c6', cushion: '#5f6c5b', ui: '#b9cdae' },
{ id: 'midnight', name: 'Midnight Blue', body: '#1e2a46', metal: '#b48d5e', cushion: '#18203a', ui: '#93aee6' },
]
Every frame, the model moves its colours toward the target:
const k = instant ? 1 : 1 - Math.exp(-dt * 5)
m.body.color.lerp(target.body, k)
m.metal.color.lerp(target.metal, k)
m.grille.color.lerp(target.metal, k)
m.cushion.color.lerp(target.cushion, k)
k = 1 - e^(-dt*5) is a frame-rate-independent step. The colour doesn't snap; it moves a little closer every frame, and the page accent follows. Want a slower blend? Make the 5 smaller. Now you know exactly what to ask AI for.
Buy it: one choice drives everything
The buy box has the finish swatches, the price and an Add to bag button; clicking it shows a small toast. It all runs on one piece of state in App.tsx:
const [finish, setFinish] = useState<Finish>(() => FINISHES.find((f) => f.id === params.get('finish')) ?? FINISHES[0])
// ...
const buy = { finish, onFinish: setFinish, onAdd: addToBag }
The Scene gets the finish. The buy box sits in a sticky div as tall as the screen, so it stays beside you while you scroll:
<div className="sticky top-0 flex h-dvh items-center px-8 pt-16"><BuyBox {...buy} /></div>
One choice feeds the 3D model, the swatches, the buy box and the accent colour. That's why it feels like one product and not four separate widgets.
A still first, 3D on request
3D is heavy. On a phone you get a still image of the headphones in your chosen colour; tap View in 3D and the scene loads.
// three.js + the model live in this lazy chunk: phones without "View in 3D" never download it.
const Scene = lazy(() => import('./Scene'))
// ...
const small = useMedia('(max-width: 767px)')
const [webgl] = useState(hasWebGL)
const [wants3D, setWants3D] = useState(false)
const show3D = webgl && (!small || wants3D)
lazy means the three.js code isn't downloaded until the 3D is shown. show3D is true when WebGL is there and either the screen isn't small or the visitor asked for it. The still loads in a blink, and the visitor decides when to pay for 3D.
Showy, but kind to the visitor
- Reduced motion: the model holds the hero pose and all the text is visible (
const p = reduced ? 0 : progress.current). - Real buttons: the swatches are radio buttons, with names and a 44-pixel tap target.
- No downloads at runtime: fonts are bundled, and the lighting comes from local light panels.
Quick recap
| Trick | Key idea |
|---|---|
| Spin | Scroll to 0..4 in a ref, read by useFrame |
| Scroll it | POSES blended by progress, damped with maath/easing |
| Model | Tube, lathe and torus, no model file |
| Repaint | color.lerp(target, 1 - Math.exp(-dt * 5)) |
| Buy | One finish state, sticky buy box |
| Fast | lazy(() => import('./Scene')), a still on phones |
Try it yourself
Edit a pose in POSES to frame a different part. Add a fifth finish. Change dt * 5 to make the blend slower. Any editor works: VS Code, IntelliJ, even Notepad. The project files and prompts are in the community, free to join.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
React State, Events, Lists and Conditional Rendering: Follow One Click
Follow one click through a React counter, render by render: what useState hands back, why a plain variable never updates the page, ternaries and &&, map with keys, and the index-as-key bug that moves a typed note to the wrong task.
React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
Watch useEffect on a timeline with real render counts: the dependency array deciding re-runs, a timer cleanup that keeps one timer alive, the leak StrictMode exposes, and two effects you should delete (a copied total and a click flag).
Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
A task board where the filter is stuck in one component, fixed by lifting it to App. Then useRef as a box React does not watch (three clicks, zero renders), a ref that refocuses an input, and the tree React DevTools shows.
Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
Four versions of an add-task form, traced with real logs: a controlled input, a classic onSubmit, a form action that gets FormData and resets itself, and useActionState with a pending button from useFormStatus, plus the draft trick that keeps typed text after an error.
