← All components Next componentChrome Swarm→
Isolated · Chrome
Chrome Rings
A gyroscope of three chrome rings that align, then grow past the viewport, driven by a progress value.
<ChromeRingsControlled />Live
0 free spin · 0.45 aligned · 1 through
Customize
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add chrome-rings
01
Install
The 3D packages this component is built on.
$ npm install three02
Add the component
One self-contained file: create components/ChromeRingsControlled.js and paste it in.
components/ChromeRingsControlled.js
1"use client";23import { useEffect, useRef } from "react";4import * as THREE from "three";5import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";67/**8 * Chrome gyroscope: three nested rings, each spinning on its own axis, in the9 * same polished chrome as ChromeField (plain three.js, PMREM RoomEnvironment).10 * The pointer tilts the whole object. Rendering pauses while off screen.11 *12 * Props:13 * - `boxRef`: element giving the resting size of the gyroscope. The canvas14 * itself fills its parent (e.g. the whole viewport) so the rings can grow15 * past the box; at rest they are scaled down to fit inside `boxRef`.16 * - `progressRef`: `{ current: 0..1 }`, usually written by a ScrollTrigger.17 * 0 → free gyroscope; ~0.45 → rings aligned face-on (concentric circles);18 * 1 → rings scaled up past the viewport, as if the visitor flew through them.19 */2021// Rings from outer to inner: radius, tube, spin axis and speed (rad/s)22const RINGS = [23 { radius: 1.6, tube: 0.13, axis: [1, 0, 0], speed: 0.45 },24 { radius: 1.22, tube: 0.13, axis: [0, 1, 0], speed: -0.6 },25 { radius: 0.84, tube: 0.13, axis: [0.6, 0, 1], speed: 0.8 },26];2728// Inner edge of the smallest ring: once it clears the viewport corners, the visitor is "inside"29const INNER_EDGE = RINGS[RINGS.length - 1].radius - RINGS[RINGS.length - 1].tube;3031const smoothstep = (a, b, x) => {32 const t = Math.min(1, Math.max(0, (x - a) / (b - a)));33 return t * t * (3 - 2 * t);34};3536function ChromeRings({ boxRef, progressRef }) {37 const hostRef = useRef(null);3839 useEffect(() => {40 // A fresh canvas per mount: its context is released on unmount (forceContextLoss), so a remount41 // (React StrictMode, HMR, navigation) must not reuse it42 const host = hostRef.current;43 if (!host) return undefined;44 const canvas = document.createElement("canvas");45 canvas.className = "block h-full w-full";46 host.appendChild(canvas);4748 const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;4950 const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: "high-performance" });51 renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));52 renderer.setClearColor(0x000000, 0);53 renderer.outputColorSpace = THREE.SRGBColorSpace;54 renderer.toneMapping = THREE.ACESFilmicToneMapping;55 renderer.toneMappingExposure = 1.1;5657 const scene = new THREE.Scene();5859 // Chrome reflections: a lit room, prefiltered once with PMREM60 const pmrem = new THREE.PMREMGenerator(renderer);61 const room = new RoomEnvironment();62 const envTarget = pmrem.fromScene(room, 0.04);63 scene.environment = envTarget.texture;64 room.dispose();65 pmrem.dispose();6667 const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 50);68 camera.position.set(0, 0, 7);6970 // White / cool lights: crisp highlights on the edges71 const key = new THREE.DirectionalLight(0xffffff, 2.4);72 key.position.set(6, 8, 10);73 scene.add(key);74 const rim = new THREE.DirectionalLight(0xcfe0ff, 2);75 rim.position.set(-8, -3, -6);76 scene.add(rim);7778 const material = new THREE.MeshPhysicalMaterial({79 color: 0xffffff,80 metalness: 1,81 roughness: 0.08,82 envMapIntensity: 1.35,83 });8485 const gyro = new THREE.Group();86 scene.add(gyro);87 const rings = RINGS.map((ring) => {88 const mesh = new THREE.Mesh(new THREE.TorusGeometry(ring.radius, ring.tube, 32, 160), material);89 const axis = new THREE.Vector3(...ring.axis).normalize();90 // Free spin kept apart from the displayed orientation, which is blended towards face-on when aligning.91 // Each ring starts at a different angle so the gyroscope reads as 3D from the first frame.92 mesh.userData = { axis, speed: ring.speed, spin: new THREE.Quaternion().setFromAxisAngle(axis, Math.random() * Math.PI) };93 mesh.quaternion.copy(mesh.userData.spin);94 gyro.add(mesh);95 return mesh;96 });9798 const IDENTITY = new THREE.Quaternion(); // torus default: in the XY plane, facing the camera99 const step = new THREE.Quaternion();100 const tilt = new THREE.Quaternion();101 const euler = new THREE.Euler();102 const pointer = { x: 0, y: 0, sx: 0, sy: 0 };103 let baseScale = 1;104 let endScale = 1; // scale reached at progress 1105 // Starts where the caller says (e.g. 1 for a section that opens with the rings already past the viewport)106 let progress = progressRef?.current ?? 0;107 let visible = true;108109 const resize = () => {110 const w = canvas.parentElement.clientWidth;111 const h = canvas.parentElement.clientHeight;112 if (!w || !h) return;113 renderer.setSize(w, h, false);114 camera.aspect = w / h;115 camera.updateProjectionMatrix();116 // At scale 1 the gyroscope fits the canvas height; shrink it to the resting box117 const box = boxRef?.current;118 baseScale = box ? Math.min(box.clientWidth, box.clientHeight) / h : 1;119 // Half-diagonal of the visible frame at the rings' depth, with a margin120 const halfH = camera.position.z * Math.tan(THREE.MathUtils.degToRad(camera.fov / 2));121 endScale = (halfH * Math.hypot(1, camera.aspect) * 1.15) / INNER_EDGE;122 if (reduced) {123 gyro.scale.setScalar(baseScale);124 renderer.render(scene, camera);125 }126 };127 const onPointer = (event) => {128 pointer.x = (event.clientX / window.innerWidth) * 2 - 1;129 pointer.y = (event.clientY / window.innerHeight) * 2 - 1;130 };131132 const resizeObserver = new ResizeObserver(resize);133 resizeObserver.observe(canvas.parentElement);134 if (boxRef?.current) resizeObserver.observe(boxRef.current);135 const visibility = new IntersectionObserver(([entry]) => {136 visible = entry.isIntersecting;137 });138 visibility.observe(canvas);139140 let raf = 0;141 let timer = null;142143 if (reduced) {144 gyro.rotation.set(0.35, -0.5, 0);145 resize();146 } else {147 resize();148 window.addEventListener("pointermove", onPointer, { passive: true });149150 timer = new THREE.Timer();151 timer.connect(document); // pauses time while the tab is hidden152153 const frame = () => {154 raf = requestAnimationFrame(frame);155 if (document.hidden || !visible) return;156 timer.update();157 const dt = Math.min(timer.getDelta(), 0.1);158 const t = timer.getElapsed();159160 // Scroll progress, lightly smoothed on top of the ScrollTrigger scrub161 progress += ((progressRef?.current ?? 0) - progress) * 0.12;162 const align = smoothstep(0, 0.45, progress); // rings come face-on, concentric163 const enter = smoothstep(0.4, 1, progress); // then grow past the viewport164 const free = 1 - align;165166 // Each ring keeps spinning (slower as it aligns), its displayed orientation blends towards face-on167 rings.forEach((ring) => {168 const { axis, speed, spin } = ring.userData;169 spin.multiply(step.setFromAxisAngle(axis, speed * dt * free));170 ring.quaternion.copy(spin).slerp(IDENTITY, align);171 });172173 // Whole object: slow drift + pointer tilt, faded out while aligning174 pointer.sx += (pointer.x - pointer.sx) * 0.05;175 pointer.sy += (pointer.y - pointer.sy) * 0.05;176 tilt.setFromEuler(euler.set(0.35 + pointer.sy * 0.3, t * 0.15 + pointer.sx * 0.4, 0));177 gyro.quaternion.copy(tilt).slerp(IDENTITY, align);178 gyro.position.y = Math.sin(t * 0.8) * 0.08 * free;179 // Eased in: the rings rush towards the visitor at the end180 gyro.scale.setScalar(THREE.MathUtils.lerp(baseScale, endScale, enter * enter));181182 renderer.render(scene, camera);183 };184 frame();185 }186187 return () => {188 cancelAnimationFrame(raf);189 timer?.dispose();190 resizeObserver.disconnect();191 visibility.disconnect();192 window.removeEventListener("pointermove", onPointer);193 rings.forEach((ring) => ring.geometry.dispose());194 material.dispose();195 envTarget.dispose();196 renderer.dispose();197 // dispose() keeps the WebGL context alive: release it now, or remounts (HMR, navigation) pile them up198 renderer.forceContextLoss();199 canvas.remove();200 };201 }, [boxRef, progressRef]);202203 return <div ref={hostRef} aria-hidden="true" className="pointer-events-none block h-full w-full" />;204}205206/**207 * ChromeRings driven by a plain `progress` prop (0–1) instead of a ref written by a ScrollTrigger:208 * 0 = free gyroscope · ~0.45 = rings aligned face-on · 1 = grown past the viewport.209 * The rings rest at `restSize` (share of the wrapper's smallest side) and can grow past it.210 */211export default function ChromeRingsControlled({ progress = 0, restSize = 0.6, className = "relative h-full w-full" }) {212 const boxRef = useRef(null);213 const progressRef = useRef(progress);214 progressRef.current = progress;215216 return (217 <div className={`${className} flex items-center justify-center`}>218 <div ref={boxRef} aria-hidden="true" className="invisible aspect-square" style={{ width: `min(${restSize * 100}%, ${restSize * 100}vh, 520px)` }} />219 <div className="absolute inset-0">220 <ChromeRings boxRef={boxRef} progressRef={progressRef} />221 </div>222 </div>223 );224}
03
Drop it in a page
Updated live with the settings above.
app/page.jsx
1import ChromeRingsControlled from "@/components/ChromeRingsControlled";23export default function Section() {4 return (5 // The component fills this box: give it a position and a height6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>7 <ChromeRingsControlled8 progress={0}9 />10 </div>11 );12}