← All components Next componentChrome Formation→
Isolated · Chrome
Chrome Cube
A single sharp-edged chrome cube, alone on stage, tilting towards the cursor.
<ChromeCubeSingle />Live
Move your cursor over it
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-cube
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber @react-three/drei02
Add the component
One self-contained file: create components/ChromeCubeSingle.js and paste it in.
components/ChromeCubeSingle.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";78/**9 * Reusable <Canvas> shell for every scene in /components/3d.10 *11 * - Pauses the render loop (frameloop="never") while the canvas is12 * scrolled out of view, so idle scenes stop burning GPU/battery.13 * - Caps devicePixelRatio to [1, 2] to avoid over-rendering on retina/4K.14 * - WebGL resources (geometries, materials, the GL context itself) are15 * disposed automatically by R3F when the Canvas unmounts.16 */17function Canvas3DWrapper({18 children,19 className = "",20 camera = { position: [0, 0, 5], fov: 45 },21 dpr = [1, 2],22 fallback = null,23 ...canvasProps24}) {25 const containerRef = useRef(null);26 // Start "in view" so every scene renders at least one real frame before27 // a canvas below the fold can be paused — some WebGL backends show an28 // opaque black canvas if frameloop="never" is set before anything has29 // ever been drawn, instead of the expected transparent clear color.30 const [inView, setInView] = useState(true);3132 useEffect(() => {33 const el = containerRef.current;34 if (!el) return;35 const observer = new IntersectionObserver(36 ([entry]) => setInView(entry.isIntersecting),37 { threshold: 0.1 }38 );39 observer.observe(el);40 return () => observer.disconnect();41 }, []);4243 return (44 <div ref={containerRef} className={className}>45 <Canvas46 dpr={dpr}47 camera={camera}48 frameloop={inView ? "always" : "never"}49 gl={{ antialias: true, alpha: true, powerPreference: "high-performance" }}50 onCreated={({ gl }) => gl.setClearColor(0x000000, 0)}51 {...canvasProps}52 >53 <Suspense fallback={fallback}>{children}</Suspense>54 </Canvas>55 </div>56 );57}5859// Same procedural studio HDRI technique as the other chrome scenes — a60// runtime canvas texture sampled equirectangularly, no HDR file to fetch.61function createStudioEnvironmentTexture() {62 const canvas = document.createElement("canvas");63 canvas.width = 2048;64 canvas.height = 1024;65 const ctx = canvas.getContext("2d");6667 const sky = ctx.createLinearGradient(0, 0, 0, canvas.height);68 sky.addColorStop(0, "#15161a");69 sky.addColorStop(0.48, "#2c2d33");70 sky.addColorStop(0.5, "#ffffff");71 sky.addColorStop(0.52, "#2c2d33");72 sky.addColorStop(1, "#15161a");73 ctx.fillStyle = sky;74 ctx.fillRect(0, 0, canvas.width, canvas.height);7576 const bars = [77 { x: 250, width: 140, alpha: 1.0 },78 { x: 600, width: 220, alpha: 0.9 },79 { x: 1050, width: 90, alpha: 0.95 },80 { x: 1400, width: 260, alpha: 0.85 },81 { x: 1850, width: 110, alpha: 0.9 },82 ];83 for (const bar of bars) {84 const grad = ctx.createLinearGradient(bar.x - bar.width, 0, bar.x + bar.width, 0);85 grad.addColorStop(0, "rgba(255,255,255,0)");86 grad.addColorStop(0.5, `rgba(255,255,255,${bar.alpha})`);87 grad.addColorStop(1, "rgba(255,255,255,0)");88 ctx.fillStyle = grad;89 ctx.fillRect(bar.x - bar.width, 0, bar.width * 2, canvas.height);90 }9192 const glow = ctx.createLinearGradient(0, canvas.height * 0.6, 0, canvas.height);93 glow.addColorStop(0, "rgba(255,255,255,0)");94 glow.addColorStop(1, "rgba(253,164,175,0.3)");95 ctx.fillStyle = glow;96 ctx.fillRect(0, canvas.height * 0.6, canvas.width, canvas.height * 0.4);9798 const texture = new THREE.CanvasTexture(canvas);99 texture.mapping = THREE.EquirectangularReflectionMapping;100 texture.colorSpace = THREE.SRGBColorSpace;101 return texture;102}103104// Window-level pointer tracking so the cube reacts to the cursor anywhere105// on the page.106function useWindowPointerParallax(targetRef, intensity, damping = 0.06) {107 const pointerTarget = useRef({ x: 0, y: 0 });108 const current = useRef({ x: 0, y: 0 });109110 useEffect(() => {111 const handleMove = event => {112 pointerTarget.current.x = (event.clientX / window.innerWidth) * 2 - 1;113 pointerTarget.current.y = -((event.clientY / window.innerHeight) * 2 - 1);114 };115 window.addEventListener("pointermove", handleMove, { passive: true });116 return () => window.removeEventListener("pointermove", handleMove);117 }, []);118119 useFrame(() => {120 current.current.x += (pointerTarget.current.x - current.current.x) * damping;121 current.current.y += (pointerTarget.current.y - current.current.y) * damping;122123 const obj = targetRef.current;124 if (!obj) return;125 obj.rotation.y = current.current.x * intensity;126 obj.rotation.x = -current.current.y * intensity * 0.6;127 });128}129130function Cube({ size, color, roughness, envMapIntensity, zoom, parallaxIntensity }) {131 const groupRef = useRef(null);132 const cubeRef = useRef(null);133 useWindowPointerParallax(groupRef, parallaxIntensity);134135 useFrame((_, delta) => {136 if (cubeRef.current) {137 cubeRef.current.rotation.y += delta * 0.2;138 cubeRef.current.rotation.x += delta * 0.07;139 }140 });141142 return (143 <group ref={groupRef} scale={zoom}>144 {/* Plain BoxGeometry — sharp 90° edges, no bevel, no displacement. */}145 <mesh ref={cubeRef}>146 <boxGeometry args={[size, size, size]} />147 <meshPhysicalMaterial148 color={color}149 metalness={1}150 roughness={roughness}151 clearcoat={1}152 clearcoatRoughness={0.01}153 envMapIntensity={envMapIntensity}154 />155 </mesh>156 </group>157 );158}159160/**161 * A single sharp-edged chrome cube — one object, isolated, no formation.162 * Kept distinct from ChromePyramidObject/ChromeCube.js (multi-cube163 * formations) so "single object" and "multiple objects" stay two clearly164 * different library entries. Every visual knob is a prop — size, color,165 * roughness/reflection intensity, zoom and the cursor-tilt strength — so a166 * demo page can drive it live from a Leva panel.167 */168export default function ChromeCubeSingle({169 size = 2.2,170 color = "#ffffff",171 roughness = 0.02,172 envMapIntensity = 3.4,173 zoom = 1,174 parallaxIntensity = 0.3,175 className = "",176}) {177 const envMap = useMemo(() => createStudioEnvironmentTexture(), []);178 useEffect(() => () => envMap.dispose(), [envMap]);179180 return (181 <Canvas3DWrapper className={className} camera={{ position: [1.4, 1.2, 5.4], fov: 38 }}>182 <Environment map={envMap} background={false} />183 <ambientLight intensity={0.45} />184 <directionalLight position={[4, 6, 5]} intensity={2.2} color="#ffffff" />185 <directionalLight position={[-4, -3, -4]} intensity={0.9} color="#fda4af" />186 <directionalLight position={[-2, 4, 3]} intensity={1.1} color="#ffffff" />187 <Cube188 size={size}189 color={color}190 roughness={roughness}191 envMapIntensity={envMapIntensity}192 zoom={zoom}193 parallaxIntensity={parallaxIntensity}194 />195 </Canvas3DWrapper>196 );197}
03
Drop it in a page
Updated live with the settings above.
app/page.jsx
1import ChromeCubeSingle from "@/components/ChromeCubeSingle";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 <ChromeCubeSingle8 size={2.2}9 roughness={0.02}10 envMapIntensity={3.4}11 zoom={1}12 parallaxIntensity={0.3}13 color="#ffffff"14 />15 </div>16 );17}