← All components Next componentChrome Waves→
Isolated · Chrome
Chrome Shards
A cluster of low-poly chrome shards that breaks apart on hover.
<ChromeScene />Live
Hover to break it apart
Customize
Color#ffffff
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-shards
01
Install
The 3D packages this component is built on.
$ npm install three02
Add the component
One self-contained file: create components/ChromeScene.js and paste it in.
components/ChromeScene.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 scenes shared by the bento grid (BentoScenes, several scenes in one canvas) and by the9 * isolated component (ChromeScene, one scene in its own canvas).10 *11 * Each factory takes the shared chrome material and returns12 * `{ scene, camera, fit(), update(dt, t, hover, px, py), dispose() }`:13 * - `fit()` frames the scene for the current `camera.aspect` (call after changing it);14 * - `hover` goes 0 → 1 while the pointer is over the scene, `px`/`py` are its position in -1..1.15 */1617const I = new THREE.Quaternion();1819const smooth = (x) => x * x * (3 - 2 * x);2021// Fit a scene of radius `r` (centered at the origin) into the tile, whatever its aspect ratio22function fitCamera(camera, r, margin = 1.25) {23 const tan = Math.tan(THREE.MathUtils.degToRad(camera.fov / 2));24 camera.position.setLength((r * margin) / (tan * Math.min(1, camera.aspect)));25}2627const SCENES = {28 // Gyroscope: three chrome rings spinning freely; hover → they align face-on, concentric29 rings(material) {30 const scene = new THREE.Scene();31 const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 50);32 camera.position.set(0, 0, 7);33 const group = new THREE.Group();34 scene.add(group);35 const step = new THREE.Quaternion();36 const tilt = new THREE.Quaternion();37 const euler = new THREE.Euler();38 const rings = [39 [1.6, [1, 0, 0], 0.2],40 [1.22, [0, 1, 0], -0.27],41 [0.84, [0.6, 0, 1], 0.35],42 ].map(([radius, axis, speed]) => {43 const mesh = new THREE.Mesh(new THREE.TorusGeometry(radius, 0.11, 24, 128), material);44 const a = new THREE.Vector3(...axis).normalize();45 mesh.userData = { axis: a, speed, spin: new THREE.Quaternion().setFromAxisAngle(a, Math.random() * Math.PI) };46 group.add(mesh);47 return mesh;48 });49 return {50 scene,51 camera,52 fit: () => fitCamera(camera, 1.75),53 update(dt, t, hover, px, py) {54 const align = smooth(hover);55 rings.forEach((ring) => {56 const { axis, speed, spin } = ring.userData;57 spin.multiply(step.setFromAxisAngle(axis, speed * dt * (1 - align)));58 ring.quaternion.copy(spin).slerp(I, align);59 });60 tilt.setFromEuler(euler.set(0.4 + py * 0.25, t * 0.2 + px * 0.35, 0));61 group.quaternion.copy(tilt).slerp(I, align * 0.85);62 },63 dispose: () => rings.forEach((r) => r.geometry.dispose()),64 };65 },6667 // Small chrome field: instanced shapes rising slowly and wrapping; hover → they rush68 field(material) {69 const scene = new THREE.Scene();70 const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 50);71 camera.position.set(0, 0, 7);72 const geometries = [new THREE.IcosahedronGeometry(0.32, 0), new THREE.OctahedronGeometry(0.32), new THREE.BoxGeometry(0.4, 0.4, 0.4)];73 const PER = 16;74 const meshes = geometries.map((g) => {75 const m = new THREE.InstancedMesh(g, material, PER);76 m.frustumCulled = false;77 scene.add(m);78 return m;79 });80 const items = meshes.flatMap((mesh) =>81 Array.from({ length: PER }, (_, i) => ({82 mesh,83 i,84 x: (Math.random() * 2 - 1) * 3.2,85 y: (Math.random() * 2 - 1) * 2.8,86 z: (Math.random() * 2 - 1) * 2,87 axis: new THREE.Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalize(),88 spin: 0.4 + Math.random(),89 speed: 0.25 + Math.random() * 0.35,90 scale: 0.6 + Math.random() * 0.7,91 }))92 );93 const matrix = new THREE.Matrix4();94 const pos = new THREE.Vector3();95 const quat = new THREE.Quaternion();96 const scl = new THREE.Vector3();97 return {98 scene,99 camera,100 fit: () => fitCamera(camera, 2.6, 1),101 update(dt, t, hover, px, py) {102 const boost = 1 + hover * 3;103 items.forEach((s) => {104 s.y += s.speed * dt * boost;105 if (s.y > 3) s.y -= 6;106 pos.set(s.x + px * 0.4 * (s.z + 2), s.y, s.z);107 quat.setFromAxisAngle(s.axis, t * s.spin * (1 + hover));108 scl.setScalar(s.scale);109 s.mesh.setMatrixAt(s.i, matrix.compose(pos, quat, scl));110 });111 meshes.forEach((m) => {112 m.instanceMatrix.needsUpdate = true;113 });114 },115 dispose: () => geometries.forEach((g) => g.dispose()),116 };117 },118119 // Torus knot turning on itself; hover → it leans towards the cursor and grows a little120 knot(material) {121 const scene = new THREE.Scene();122 const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 50);123 camera.position.set(0, 0, 7);124 const mesh = new THREE.Mesh(new THREE.TorusKnotGeometry(0.85, 0.28, 220, 28, 2, 3), material);125 scene.add(mesh);126 let lean = 0;127 return {128 scene,129 camera,130 fit: () => fitCamera(camera, 1.35),131 update(dt, t, hover, px, py) {132 lean += (hover - lean) * Math.min(1, dt * 4);133 mesh.rotation.set(t * 0.3 + py * 0.6 * lean, t * 0.45 + px * 0.8 * lean, 0);134 mesh.scale.setScalar(1 + lean * 0.12);135 },136 dispose: () => mesh.geometry.dispose(),137 };138 },139140 // Low-poly shard cluster; hover → it breaks apart141 shards(material) {142 const scene = new THREE.Scene();143 const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 50);144 camera.position.set(0, 0, 7);145 const geometries = [new THREE.OctahedronGeometry(0.5, 0), new THREE.TetrahedronGeometry(0.6, 0)];146 const group = new THREE.Group();147 scene.add(group);148 const shards = Array.from({ length: 11 }, (_, i) => {149 const mesh = new THREE.Mesh(geometries[i % 2], material);150 const dir = new THREE.Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalize();151 mesh.userData = { dir, spin: new THREE.Vector3(Math.random(), Math.random(), Math.random()).multiplyScalar(1.2), near: 0.35 + Math.random() * 0.35 };152 mesh.scale.setScalar(0.7 + Math.random() * 0.5);153 group.add(mesh);154 return mesh;155 });156 let burst = 0;157 return {158 scene,159 camera,160 fit: () => fitCamera(camera, 1.9),161 update(dt, t, hover) {162 burst += (hover - burst) * Math.min(1, dt * 3);163 const b = smooth(burst);164 shards.forEach((m) => {165 const { dir, spin, near } = m.userData;166 m.position.copy(dir).multiplyScalar(near + b * 1.05);167 m.rotation.set(t * spin.x, t * spin.y, t * spin.z);168 });169 group.rotation.set(0.3, t * 0.25, 0);170 },171 dispose: () => geometries.forEach((g) => g.dispose()),172 };173 },174175 // Kinetic sculpture: a grid of chrome spheres in a travelling wave; hover → ripple under the cursor176 waves(material) {177 const scene = new THREE.Scene();178 const camera = new THREE.PerspectiveCamera(30, 1, 0.1, 80);179 const geometry = new THREE.SphereGeometry(0.2, 20, 14);180 const COLS = 26;181 const ROWS = 7;182 const GAP = 0.55;183 const mesh = new THREE.InstancedMesh(geometry, material, COLS * ROWS);184 mesh.frustumCulled = false;185 scene.add(mesh);186 const matrix = new THREE.Matrix4();187 const pos = new THREE.Vector3();188 const scl = new THREE.Vector3(1, 1, 1);189 const halfW = ((COLS - 1) * GAP) / 2;190 const halfD = ((ROWS - 1) * GAP) / 2;191 let ripple = 0;192 return {193 scene,194 camera,195 fit: () => {196 // Seen from the front, slightly above; far enough for the whole width to fit197 const tan = Math.tan(THREE.MathUtils.degToRad(camera.fov / 2));198 const dist = Math.min(22, (halfW + 0.6) / (tan * camera.aspect));199 camera.position.set(0, dist * 0.42, dist);200 camera.lookAt(0, -0.2, 0);201 },202 update(dt, t, hover, px) {203 ripple += (hover - ripple) * Math.min(1, dt * 4);204 const cx = px * halfW;205 let k = 0;206 for (let r = 0; r < ROWS; r++) {207 const z = r * GAP - halfD;208 for (let c = 0; c < COLS; c++) {209 const x = c * GAP - halfW;210 let y = 0.35 * Math.sin(x * 0.7 + t * 1.6) * Math.cos(z * 0.9 + t * 0.9);211 const d = Math.abs(x - cx);212 y += ripple * 0.75 * Math.exp(-d * d * 0.35) * Math.sin(t * 5 - d * 1.8);213 mesh.setMatrixAt(k++, matrix.compose(pos.set(x, y, z), I, scl));214 }215 }216 mesh.instanceMatrix.needsUpdate = true;217 },218 dispose: () => geometry.dispose(),219 };220 },221};222223// Chrome look shared by every scene: PMREM-filtered RoomEnvironment for reflections, polished metal224// material, and two cool lights per scene for crisp highlights. Call `dispose()` on unmount.225function createChromeKit(renderer) {226 const pmrem = new THREE.PMREMGenerator(renderer);227 const room = new RoomEnvironment();228 const envTarget = pmrem.fromScene(room, 0.04);229 room.dispose();230 pmrem.dispose();231 // Standard (pas Physical) : même rendu pour un métal poli sans vernis, shader nettement plus léger232 const material = new THREE.MeshStandardMaterial({ color: 0xffffff, metalness: 1, roughness: 0.08, envMapIntensity: 1.35 });233 return {234 material,235 setup(scene) {236 scene.environment = envTarget.texture;237 const key = new THREE.DirectionalLight(0xffffff, 2.4);238 key.position.set(6, 8, 10);239 const rim = new THREE.DirectionalLight(0xcfe0ff, 2);240 rim.position.set(-8, -3, -6);241 scene.add(key, rim);242 },243 dispose() {244 material.dispose();245 envTarget.dispose();246 },247 };248}249250/**251 * One chrome scene from chrome-scenes.js, alone in its own transparent canvas that fills the parent.252 * Same scenes as the bento grid on the home page, usable anywhere as an isolated object.253 *254 * Props:255 * - `scene`: "rings" | "field" | "knot" | "shards" | "waves"256 * - `color` (hex), `roughness` 0–0.5, `reflection` 0.2–3, `speed` 0–3 (time scale), `zoom` 0.6–1.6257 * - `className`: sizing of the wrapper (the canvas fills it)258 * Hovering the wrapper drives the scene (rings align, shards break apart, waves ripple...).259 */260export const CHROME_SCENE_DEFAULTS = { color: "#ffffff", roughness: 0.08, reflection: 1.35, speed: 1, zoom: 1 };261262export default function ChromeScene({ scene = "knot", className = "h-full w-full", ...props }) {263 const hostRef = useRef(null);264 // Latest props, read every frame (no scene rebuild when a value changes)265 const paramsRef = useRef({ ...CHROME_SCENE_DEFAULTS, ...props });266 paramsRef.current = { ...CHROME_SCENE_DEFAULTS, ...props };267268 useEffect(() => {269 const host = hostRef.current;270 const factory = SCENES[scene];271 if (!host || !factory) return undefined;272273 const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;274275 // Fresh canvas per mount: its context is released on unmount (forceContextLoss)276 const canvas = document.createElement("canvas");277 canvas.className = "block h-full w-full";278 host.appendChild(canvas);279280 const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: "high-performance" });281 renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));282 renderer.setClearColor(0x000000, 0);283 renderer.outputColorSpace = THREE.SRGBColorSpace;284 renderer.toneMapping = THREE.ACESFilmicToneMapping;285 renderer.toneMappingExposure = 1.1;286287 const chrome = createChromeKit(renderer);288 const s = factory(chrome.material);289 chrome.setup(s.scene);290291 const state = { hover: 0, target: 0, px: 0, py: 0, spx: 0, spy: 0 };292 let time = 0;293 // Look (color, finish, zoom) from the current props294 const applyLook = () => {295 const p = paramsRef.current;296 chrome.material.color.set(p.color);297 chrome.material.roughness = p.roughness;298 chrome.material.envMapIntensity = p.reflection;299 if (s.camera.zoom !== p.zoom) {300 s.camera.zoom = p.zoom;301 s.camera.updateProjectionMatrix();302 }303 };304305 const resize = () => {306 const w = host.clientWidth;307 const h = host.clientHeight;308 if (!w || !h) return;309 renderer.setSize(w, h, false);310 s.camera.aspect = w / h;311 s.camera.updateProjectionMatrix();312 s.fit();313 s.camera.updateProjectionMatrix();314 if (reduced) renderer.render(s.scene, s.camera);315 };316 const onMove = (event) => {317 const r = host.getBoundingClientRect();318 state.target = 1;319 state.px = ((event.clientX - r.left) / r.width) * 2 - 1;320 state.py = ((event.clientY - r.top) / r.height) * 2 - 1;321 };322 const onLeave = () => {323 state.target = 0;324 };325326 const resizeObserver = new ResizeObserver(resize);327 resizeObserver.observe(host);328 resize();329330 let visible = true;331 const visibility = new IntersectionObserver(([entry]) => {332 visible = entry.isIntersecting;333 });334 visibility.observe(host);335336 let raf = 0;337 let timer = null;338 if (reduced) {339 applyLook();340 s.update(0, 0, 0, 0, 0);341 renderer.render(s.scene, s.camera);342 } else {343 host.addEventListener("pointermove", onMove);344 host.addEventListener("pointerleave", onLeave);345 timer = new THREE.Timer();346 timer.connect(document); // pauses time while the tab is hidden347 const frame = () => {348 raf = requestAnimationFrame(frame);349 if (document.hidden || !visible) return;350 timer.update();351 // Speed scales the scene's own clock (motion), not the hover easing352 const dt = Math.min(timer.getDelta(), 0.1);353 const sdt = dt * paramsRef.current.speed;354 time += sdt;355 applyLook();356 state.hover += (state.target - state.hover) * Math.min(1, dt * 5);357 state.spx += (state.px - state.spx) * Math.min(1, dt * 6);358 state.spy += (state.py - state.spy) * Math.min(1, dt * 6);359 s.update(sdt, time, state.hover, state.spx, state.spy);360 renderer.render(s.scene, s.camera);361 };362 frame();363 }364365 return () => {366 cancelAnimationFrame(raf);367 timer?.dispose();368 resizeObserver.disconnect();369 visibility.disconnect();370 host.removeEventListener("pointermove", onMove);371 host.removeEventListener("pointerleave", onLeave);372 s.dispose();373 chrome.dispose();374 renderer.dispose();375 renderer.forceContextLoss();376 canvas.remove();377 };378 }, [scene]);379380 return <div ref={hostRef} className={className} />;381}
03
Drop it in a page
Updated live with the settings above.
app/page.jsx
1import ChromeScene from "@/components/ChromeScene";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 <ChromeScene8 scene="shards"9 speed={1}10 zoom={1}11 reflection={1.35}12 roughness={0.08}13 color="#ffffff"14 />15 </div>16 );17}