← All components Next componentChrome Rings→
Isolated · Chrome
Chrome Formation
Thirty chrome cubes assembling into formations, ready to be driven by scroll.
<ChromePyramidObject />Live
Move your cursor over it
Customize
Color#f0f3f8
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-pyramid
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber @react-three/drei three-stdlib02
Add the component
One self-contained file: create components/ChromePyramidObject.js and paste it in.
components/ChromePyramidObject.js
1"use client";23import { Suspense, useEffect, useMemo, useRef, useState } from "react";4import * as THREE from "three";5import { Canvas, useFrame } from "@react-three/fiber";6import { Environment } from "@react-three/drei";7import { RoundedBoxGeometry } from "three-stdlib";89/**10 * Reusable <Canvas> shell for every scene in /components/3d.11 *12 * - Pauses the render loop (frameloop="never") while the canvas is13 * scrolled out of view, so idle scenes stop burning GPU/battery.14 * - Caps devicePixelRatio to [1, 2] to avoid over-rendering on retina/4K.15 * - WebGL resources (geometries, materials, the GL context itself) are16 * disposed automatically by R3F when the Canvas unmounts.17 */18function Canvas3DWrapper({19 children,20 className = "",21 camera = { position: [0, 0, 5], fov: 45 },22 dpr = [1, 2],23 fallback = null,24 ...canvasProps25}) {26 const containerRef = useRef(null);27 // Start "in view" so every scene renders at least one real frame before28 // a canvas below the fold can be paused — some WebGL backends show an29 // opaque black canvas if frameloop="never" is set before anything has30 // ever been drawn, instead of the expected transparent clear color.31 const [inView, setInView] = useState(true);3233 useEffect(() => {34 const el = containerRef.current;35 if (!el) return;36 const observer = new IntersectionObserver(37 ([entry]) => setInView(entry.isIntersecting),38 { threshold: 0.1 }39 );40 observer.observe(el);41 return () => observer.disconnect();42 }, []);4344 return (45 <div ref={containerRef} className={className}>46 <Canvas47 dpr={dpr}48 camera={camera}49 frameloop={inView ? "always" : "never"}50 gl={{ antialias: true, alpha: true, powerPreference: "high-performance" }}51 onCreated={({ gl }) => gl.setClearColor(0x000000, 0)}52 {...canvasProps}53 >54 <Suspense fallback={fallback}>{children}</Suspense>55 </Canvas>56 </div>57 );58}5960export const FORMATION_COUNT = 4;6162function useWindowPointerParallax(targetRef, intensity = 0.3, damping = 0.06) {63 const pointerTarget = useRef({ x: 0, y: 0 });64 const current = useRef({ x: 0, y: 0 });6566 useEffect(() => {67 const handleMove = event => {68 pointerTarget.current.x = (event.clientX / window.innerWidth) * 2 - 1;69 pointerTarget.current.y = -((event.clientY / window.innerHeight) * 2 - 1);70 };71 window.addEventListener("pointermove", handleMove, { passive: true });72 return () => window.removeEventListener("pointermove", handleMove);73 }, []);7475 useFrame(() => {76 current.current.x += (pointerTarget.current.x - current.current.x) * damping;77 current.current.y += (pointerTarget.current.y - current.current.y) * damping;7879 const obj = targetRef.current;80 if (!obj) return;81 obj.rotation.y = current.current.x * intensity;82 obj.rotation.x = -current.current.y * intensity * 0.6;83 });84}8586const CUBE_SIZE = 0.46;87const SPACING = CUBE_SIZE * 1.18;8889function pyramidFormation() {90 const layers = [4, 3, 2, 1];91 const positions = [];92 let y = -SPACING * 1.1;93 for (const side of layers) {94 const offset = ((side - 1) * SPACING) / 2;95 for (let i = 0; i < side; i++) {96 for (let j = 0; j < side; j++) {97 positions.push(new THREE.Vector3(i * SPACING - offset, y, j * SPACING - offset));98 }99 }100 y += SPACING;101 }102 return positions;103}104105function sphereFormation(count) {106 const golden = Math.PI * (3 - Math.sqrt(5));107 const radius = SPACING * 2.6;108 const positions = [];109 for (let i = 0; i < count; i++) {110 const yFrac = 1 - (i / (count - 1)) * 2;111 const r = Math.sqrt(1 - yFrac * yFrac);112 const theta = golden * i;113 positions.push(new THREE.Vector3(Math.cos(theta) * r * radius, yFrac * radius, Math.sin(theta) * r * radius));114 }115 return positions;116}117118function ringFormation(count) {119 const radius = SPACING * 2.4;120 const positions = [];121 for (let i = 0; i < count; i++) {122 const a = (i / count) * Math.PI * 2;123 const wobble = Math.sin(a * 3) * 0.18;124 positions.push(125 new THREE.Vector3(Math.cos(a) * (radius + wobble * radius), Math.sin(a * 2) * SPACING * 0.6, Math.sin(a) * (radius + wobble * radius))126 );127 }128 return positions;129}130131function gridFormation(count) {132 const cols = 6;133 const rows = Math.ceil(count / cols);134 const positions = [];135 for (let i = 0; i < count; i++) {136 const c = i % cols;137 const r = Math.floor(i / cols);138 positions.push(new THREE.Vector3((c - (cols - 1) / 2) * SPACING, (r - (rows - 1) / 2) * SPACING, 0));139 }140 return positions;141}142143/**144 * Génère une carte d'environnement HDRI haute dynamique enrichie145 * avec softboxes de studio et gradients de rim-lighting contrastés.146 */147function createStudioEnvironmentTexture() {148 const canvas = document.createElement("canvas");149 canvas.width = 2048;150 canvas.height = 1024;151 const ctx = canvas.getContext("2d");152153 // Fond studio sombre à très haut contraste154 const sky = ctx.createLinearGradient(0, 0, 0, canvas.height);155 sky.addColorStop(0, "#090a0f");156 sky.addColorStop(0.45, "#181a20");157 sky.addColorStop(0.5, "#ffffff"); // Horizon blanc très vif pour la ligne de réflexion158 sky.addColorStop(0.55, "#181a20");159 sky.addColorStop(1, "#090a0f");160 ctx.fillStyle = sky;161 ctx.fillRect(0, 0, canvas.width, canvas.height);162163 // Panneaux lumineux (Softboxes) ultra-brillants164 const softboxes = [165 { x: 220, width: 140, color: "255,255,255", alpha: 1.0 },166 { x: 500, width: 90, color: "180,220,255", alpha: 0.8 },167 { x: 780, width: 220, color: "255,255,255", alpha: 0.95 },168 { x: 1150, width: 70, color: "10,12,18", alpha: 1.0 }, // Cache noir net169 { x: 1380, width: 160, color: "255,255,255", alpha: 1.0 },170 { x: 1720, width: 110, color: "255,220,200", alpha: 0.85 },171 { x: 1940, width: 90, color: "255,255,255", alpha: 0.9 },172 ];173174 for (const box of softboxes) {175 const grad = ctx.createLinearGradient(box.x - box.width, 0, box.x + box.width, 0);176 grad.addColorStop(0, `rgba(${box.color},0)`);177 grad.addColorStop(0.5, `rgba(${box.color},${box.alpha})`);178 grad.addColorStop(1, `rgba(${box.color},0)`);179 ctx.fillStyle = grad;180 ctx.fillRect(box.x - box.width, 0, box.width * 2, canvas.height);181 }182183 // Reflet rose / néon cyan en dégradé périphérique pour la richesse chromatique184 const accentGradient = ctx.createLinearGradient(0, canvas.height * 0.6, 0, canvas.height);185 accentGradient.addColorStop(0, "rgba(253,164,175,0)");186 accentGradient.addColorStop(0.6, "rgba(244,114,182,0.25)");187 accentGradient.addColorStop(1, "rgba(168,85,247,0.4)");188 ctx.fillStyle = accentGradient;189 ctx.fillRect(0, canvas.height * 0.6, canvas.width, canvas.height * 0.4);190191 const texture = new THREE.CanvasTexture(canvas);192 texture.mapping = THREE.EquirectangularReflectionMapping;193 texture.colorSpace = THREE.SRGBColorSpace;194 return texture;195}196197function Cubes({ targetFormation, targetFormationRef, parallaxIntensity, cubeColor, roughness, envMapIntensity, zoom }) {198 const groupRef = useRef(null);199 const meshRef = useRef(null);200 const floatFormation = useRef(0);201 useWindowPointerParallax(groupRef, parallaxIntensity);202203 const count = 30;204 const formations = useMemo(205 () => [pyramidFormation(), sphereFormation(count), ringFormation(count), gridFormation(count)],206 []207 );208209 const cubes = useMemo(210 () =>211 Array.from({ length: count }, () => ({212 delay: Math.random() * 0.35,213 spinAxis: new THREE.Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalize(),214 spinAmount: (Math.random() - 0.5) * 6,215 floatSpeed: 0.8 + Math.random() * 1.2,216 floatAmpY: 0.04 + Math.random() * 0.05,217 floatAmpX: 0.02 + Math.random() * 0.03,218 floatRotSpeed: 0.3 + Math.random() * 0.5,219 phase: Math.random() * Math.PI * 2,220 })),221 [count]222 );223224 const dummy = useMemo(() => new THREE.Object3D(), []);225 const tempEuler = useMemo(() => new THREE.Euler(), []);226227 useFrame((state, delta) => {228 if (groupRef.current) groupRef.current.rotation.y += delta * 0.12;229230 const wanted = targetFormationRef ? targetFormationRef.current : targetFormation;231 const diff = wanted - floatFormation.current;232 floatFormation.current += diff * Math.min(1, delta * 2.6);233234 const stage = Math.floor(floatFormation.current);235 const stageIndex = ((stage % FORMATION_COUNT) + FORMATION_COUNT) % FORMATION_COUNT;236 const nextIndex = (stageIndex + 1) % FORMATION_COUNT;237 const blend = floatFormation.current - stage;238239 const from = formations[stageIndex];240 const to = formations[nextIndex];241 const mesh = meshRef.current;242 if (!mesh) return;243244 const t = state.clock.elapsedTime;245 for (let i = 0; i < count; i++) {246 const cube = cubes[i];247 const local = THREE.MathUtils.clamp((blend - cube.delay) / (1 - cube.delay), 0, 1);248 const eased = local < 0.5 ? 4 * local ** 3 : 1 - (-2 * local + 2) ** 3 / 2;249250 dummy.position.lerpVectors(from[i], to[i], eased);251252 const floatTime = t * cube.floatSpeed + cube.phase;253 dummy.position.y += Math.sin(floatTime) * cube.floatAmpY;254 dummy.position.x += Math.cos(floatTime * 0.7) * cube.floatAmpX;255 dummy.position.z += Math.sin(floatTime * 0.5) * cube.floatAmpX;256257 const rotX = Math.sin(floatTime * cube.floatRotSpeed) * 0.08;258 const rotY = Math.cos(floatTime * cube.floatRotSpeed * 0.8) * 0.08;259 const rotZ = Math.sin(floatTime * cube.floatRotSpeed * 1.2) * 0.05;260 tempEuler.set(rotX, rotY, rotZ);261 dummy.quaternion.setFromEuler(tempEuler);262263 const flight = Math.sin(Math.PI * local);264 if (flight > 0.001) {265 const flightQuat = new THREE.Quaternion().setFromAxisAngle(cube.spinAxis, cube.spinAmount * flight);266 dummy.quaternion.multiply(flightQuat);267 }268269 const wobble = flight * 0.45;270 dummy.scale.set(271 1 + wobble * Math.sin(t * 9 + i * 1.7),272 1 + wobble * Math.sin(t * 10 + i * 2.3 + 2.1),273 1 + wobble * Math.sin(t * 8 + i * 1.1 + 4.2)274 );275 dummy.updateMatrix();276 mesh.setMatrixAt(i, dummy.matrix);277 }278 mesh.instanceMatrix.needsUpdate = true;279 });280281 // Augmentation du rayon du biseau (0.06) et des segments (6) pour capturer des highlights plus doux et réalistes282 const geometry = useMemo(() => new RoundedBoxGeometry(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE, 6, 0.06), []);283 useEffect(() => () => geometry.dispose(), [geometry]);284285 return (286 <group ref={groupRef} scale={zoom}>287 <instancedMesh ref={meshRef} args={[geometry, undefined, count]} frustumCulled={false}>288 {/* Matériau Chrome Physiquement Réaliste d'Ultra-Haute Qualité */}289 <meshPhysicalMaterial290 color={cubeColor}291 metalness={1.0}292 roughness={roughness} // Surface miroir quasi-parfaite293 clearcoat={1.0}294 clearcoatRoughness={0.008}295 envMapIntensity={envMapIntensity} // Puissance d'intensité de la carte studio296297 // Subtile iridescence prismatique sur les arrêtes de réflexion298 iridescence={0.3}299 iridescenceIOR={1.6}300 iridescenceThicknessRange={[100, 400]}301302 // Légère anisotropie pour imiter un micro-polissage usiné303 anisotropy={0.15}304 anisotropyRotation={Math.PI / 4}305 />306 </instancedMesh>307 </group>308 );309}310311/**312 * Every visual knob is a prop — formation, cube color, roughness/reflection313 * intensity, zoom and the cursor-tilt strength — so a demo page can drive314 * it live from a Leva panel. Defaults match the tuned studio look above.315 */316export default function ChromePyramidObject({317 targetFormation = 0,318 targetFormationRef,319 parallaxIntensity = 0.25,320 cubeColor = "#f0f3f8",321 roughness = 0.005,322 envMapIntensity = 4.0,323 zoom = 1,324 className = "",325}) {326 const envMap = useMemo(() => createStudioEnvironmentTexture(), []);327 useEffect(() => () => envMap.dispose(), [envMap]);328329 return (330 <Canvas3DWrapper className={className} camera={{ position: [1.2, 1.6, 6.8], fov: 36 }}>331 <Environment map={envMap} background={false} />332333 {/* Configuration Studio multi-lumières pour maximiser les éclats spéculaires */}334 <ambientLight intensity={0.55} />335 <directionalLight position={[2, 4, 6]} intensity={3.5} color="#ffffff" />336 <directionalLight position={[-4, -2, -3]} intensity={1.8} color="#fda4af" />337 <directionalLight position={[-3, 5, 2]} intensity={2.2} color="#e0f2fe" />338 <pointLight position={[0, -2, 3]} intensity={1.5} color="#ffffff" />339340 <Cubes341 targetFormation={targetFormation}342 targetFormationRef={targetFormationRef}343 parallaxIntensity={parallaxIntensity}344 cubeColor={cubeColor}345 roughness={roughness}346 envMapIntensity={envMapIntensity}347 zoom={zoom}348 />349 </Canvas3DWrapper>350 );351}
03
Drop it in a page
Updated live with the settings above.
app/page.jsx
1import ChromePyramidObject from "@/components/ChromePyramidObject";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 <ChromePyramidObject8 targetFormation={0}9 roughness={0.005}10 envMapIntensity={4}11 zoom={1}12 parallaxIntensity={0.25}13 cubeColor="#f0f3f8"14 />15 </div>16 );17}