← All components Next componentSecurity Badge→
Navigation · Interface
Holo Menu
A floating sci-fi menu panel with scanlines, glitch bursts on hover and a blip on click.
> awaiting input
<HoloMenu3D />Live
Move your cursor over it
Customize
Hologram#a78bfa
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add holo-menu
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber && npm install -D @types/three
02
Add the component
One self-contained file: create components/HoloMenu3D.tsx and paste it in.
components/HoloMenu3D.tsx
1"use client";23import {4 memo,5 useEffect,6 useLayoutEffect,7 useMemo,8 useRef,9 useState,10 type CSSProperties,11 type ReactNode,12 type RefObject,13} from "react";14import * as THREE from "three";15import { Canvas, useFrame, useThree, type CanvasProps, type ThreeEvent } from "@react-three/fiber";1617/**18 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep19 * their own tailored scenes).20 *21 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its22 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):23 *24 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }25 *26 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,27 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are28 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.29 */3031/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */32export type TiltAxis = "both" | "x-only" | "y-only" | "none";3334/** 1. Cursor: how the pointer pulls, pushes and drags the object. */35interface CursorProps {36 /** Reach of the pointer's influence, in the component's own space: CSS pixels for pixel-laid-out widgets, world units for 3D scenes (each component says which). Default 220 (px). */37 cursorRadius?: number;38 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */39 cursorForce?: number;40 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */41 magneticStrength?: number;42 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */43 cursorDamping?: number;44}4546/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */47interface TiltProps {48 /** Largest lean towards the pointer, in degrees. Default 15. */49 maxTiltAngle?: number;50 /** Axes that follow the pointer. Default "both". */51 tiltAxis?: TiltAxis;52 /** Lean away from the pointer instead of towards it. Default false. */53 invertTilt?: boolean;54 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */55 parallaxOffset?: number;56}5758/** 3. Text and 3D typography, for components that draw a label. */59interface Text3DProps {60 /** The label drawn by the component. */61 text?: string;62 /** Scale of the lettering. Default 1. */63 fontSize?: number;64 /** Extrusion depth of 3D letters. Default 0.2. */65 textDepth?: number;66 /** Bevelled, light-catching edges on 3D letters. Default true. */67 bevelEnabled?: boolean;68 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */69 fontUrl?: string;70}7172/** 4. Rendering, materials and glow. */73interface MaterialProps {74 /** Main color of the object. Default "#6366f1". */75 primaryColor?: string;76 /** Color of the glow. Default "#00f0ff". */77 emissiveColor?: string;78 /** Strength of the glow, 0 (none) to 3. Default 1. */79 emissiveIntensity?: number;80 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */81 roughness?: number;82 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */83 metalness?: number;84 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */85 transmission?: number;86 /** Technical wireframe rendering. Default false. */87 wireframe?: boolean;88}8990/** 5. Particles, idle motion and shader animation. */91interface MotionProps {92 /** Number of instanced elements. Default depends on the component. */93 particleCount?: number;94 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */95 autoRotateSpeed?: number;96 /** Pulses or ripples per second. Default 1. */97 pulseRate?: number;98 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */99 displacementScale?: number;100}101102/** 6. Environment and camera. */103interface EnvironmentProps {104 /** Camera field of view, in degrees. Default depends on the component. */105 cameraFov?: number;106 /** Color of the depth fog. Default "#0a0a0a". */107 fogColor?: string;108 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */109 fogDensity?: number;110}111112/** 7. Performance and accessibility. */113interface PerformanceProps {114 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */115 lowPowerMode?: boolean;116 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */117 respectReducedMotion?: boolean;118 /** Stop the render loop while the component is scrolled out of view. Default true. */119 pauseWhenOffscreen?: boolean;120}121122/** Every group at once. Components extend only the groups they apply (see the top of this file). */123interface Base3DComponentProps124 extends CursorProps,125 TiltProps,126 Text3DProps,127 MaterialProps,128 MotionProps,129 EnvironmentProps,130 PerformanceProps {}131132type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;133134/** The values a prop takes when it is left out. A component may override one, and then documents it. */135const DEFAULT_3D_PROPS: Defaults = {136 cursorRadius: 220,137 cursorForce: 1,138 magneticStrength: 0,139 cursorDamping: 0.1,140 maxTiltAngle: 15,141 tiltAxis: "both",142 invertTilt: false,143 parallaxOffset: 1,144 fontSize: 1,145 textDepth: 0.2,146 bevelEnabled: true,147 primaryColor: "#6366f1",148 emissiveColor: "#00f0ff",149 emissiveIntensity: 1,150 roughness: 0.3,151 metalness: 0.5,152 transmission: 0,153 wireframe: false,154 autoRotateSpeed: 0,155 pulseRate: 1,156 displacementScale: 1,157 fogColor: "#0a0a0a",158 fogDensity: 0,159 lowPowerMode: false,160 respectReducedMotion: true,161 pauseWhenOffscreen: true,162};163164/** Inline widget: fills its positioned parent and receives pointer events. */165const FILL_STYLE: CSSProperties = { position: "absolute", top: 0, left: 0, width: "100%", height: "100%" };166167/** Cursor overlay: covers the viewport, above everything, never intercepts the page's events. */168const OVERLAY_STYLE: CSSProperties = {169 position: "fixed",170 top: 0,171 left: 0,172 width: "100%",173 height: "100%",174 pointerEvents: "none",175 zIndex: 9999,176};177178/** Visually hidden but reachable by keyboard and screen readers. */179const SR_ONLY: CSSProperties = {180 position: "absolute",181 width: 1,182 height: 1,183 padding: 0,184 margin: -1,185 overflow: "hidden",186 clip: "rect(0, 0, 0, 0)",187 whiteSpace: "nowrap",188 border: 0,189};190191interface UICanvasProps extends Omit<CanvasProps, "children" | "style" | "gl">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {192 children: ReactNode;193 /** Full-viewport, click-through overlay (cursors) instead of an inline widget. */194 overlay?: boolean;195}196197/**198 * Ready-to-use <Canvas>: pauses its render loop while scrolled out of view (pauseWhenOffscreen), pixel199 * ratio 1 in lowPowerMode; R3F disposes the renderer and its WebGL context on unmount.200 */201function UICanvas({ children, overlay = false, dpr = [1, 2], pauseWhenOffscreen = DEFAULT_3D_PROPS.pauseWhenOffscreen, lowPowerMode = DEFAULT_3D_PROPS.lowPowerMode, ...canvasProps }: UICanvasProps) {202 const containerRef = useRef<HTMLDivElement>(null);203 // In view at first: the first frame is always drawn before the loop can be paused204 const [inView, setInView] = useState(true);205 useEffect(() => {206 const el = containerRef.current;207 if (!el || !pauseWhenOffscreen) return undefined;208 const observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));209 observer.observe(el);210 return () => observer.disconnect();211 }, [pauseWhenOffscreen]);212 return (213 <div ref={containerRef} style={overlay ? OVERLAY_STYLE : FILL_STYLE} aria-hidden="true">214 <Canvas215 dpr={lowPowerMode ? 1 : dpr}216 frameloop={inView || !pauseWhenOffscreen ? "always" : "never"}217 gl={{ antialias: true, alpha: true, powerPreference: "high-performance" }}218 style={overlay ? { pointerEvents: "none" } : undefined}219 {...canvasProps}220 >221 {children}222 </Canvas>223 </div>224 );225}226227/**228 * Perspective camera placed so that 1 world unit = 1 CSS pixel on the z = 0 plane: widgets are laid229 * out in pixels like the rest of the page, and still get real depth (presses, tilts, shadows).230 */231function PixelPerspective({ fov = 30 }: { fov?: number }) {232 const camera = useThree((state) => state.camera) as THREE.PerspectiveCamera;233 const size = useThree((state) => state.size);234 useLayoutEffect(() => {235 camera.fov = fov;236 camera.near = 1;237 camera.far = 20000;238 camera.position.set(0, 0, size.height / 2 / Math.tan(THREE.MathUtils.degToRad(fov / 2)));239 camera.lookAt(0, 0, 0);240 camera.updateProjectionMatrix();241 }, [camera, size, fov]);242 return null;243}244245function pageFontFamily() {246 if (typeof document === "undefined") return "sans-serif";247 return getComputedStyle(document.body).fontFamily || "sans-serif";248}249250interface LabelOptions {251 text: string;252 /** Second, smaller line under the text. */253 subtext?: string;254 /** Glyph drawn before the text (emoji, arrow, symbol…). */255 icon?: string;256 width: number;257 height: number;258 color: string;259 /** Face color; transparent when omitted. */260 background?: string;261 fontSize?: number;262 fontWeight?: number;263 /** Wrap the text over several lines within the width (minus padding). */264 wrap?: boolean;265 align?: "center" | "left";266 /** Horizontal padding, in CSS pixels (used by wrapping and left alignment). Default 0. */267 padding?: number;268 /** Line height, as a multiple of the font size. Default 1.35. */269 lineHeight?: number;270}271272function wrapLines(ctx: CanvasRenderingContext2D, text: string, maxWidth: number) {273 const lines: string[] = [];274 let line = "";275 for (const word of text.split(/\s+/)) {276 const candidate = line ? `${line} ${word}` : word;277 if (line && ctx.measureText(candidate).width > maxWidth) {278 lines.push(line);279 line = word;280 } else {281 line = candidate;282 }283 }284 if (line) lines.push(line);285 return lines;286}287288function drawLabel(canvas: HTMLCanvasElement, o: LabelOptions) {289 // Drawn at 2× (or the screen's ratio) so the text stays crisp once mapped on its plane290 const scale = Math.min(Math.max(window.devicePixelRatio || 1, 2), 3);291 canvas.width = Math.max(2, Math.ceil(o.width * scale));292 canvas.height = Math.max(2, Math.ceil(o.height * scale));293 const ctx = canvas.getContext("2d");294 if (!ctx) return;295 ctx.setTransform(scale, 0, 0, scale, 0, 0);296 ctx.clearRect(0, 0, o.width, o.height);297 if (o.background) {298 ctx.fillStyle = o.background;299 ctx.fillRect(0, 0, o.width, o.height);300 }301302 const family = pageFontFamily();303 const size = o.fontSize ?? 15;304 const weight = o.fontWeight ?? 600;305 ctx.fillStyle = o.color;306 ctx.textBaseline = "middle";307 ctx.textAlign = "center";308309 const padding = o.padding ?? 0;310 const left = o.align === "left";311 ctx.textAlign = left ? "left" : "center";312 const x = left ? padding : o.width / 2;313314 let text = o.text;315 if (o.icon) text = `${o.icon} ${text}`;316 ctx.font = `${weight} ${size}px ${family}`;317318 if (o.wrap) {319 const step = size * (o.lineHeight ?? 1.35);320 const lines = wrapLines(ctx, text, o.width - padding * 2);321 // Only as many lines as fit; the last one kept ends with an ellipsis322 const maxLines = Math.max(1, Math.floor(o.height / step));323 if (lines.length > maxLines) {324 lines.length = maxLines;325 let last = lines[maxLines - 1];326 while (last && ctx.measureText(`${last}…`).width > o.width - padding * 2) last = last.slice(0, -1);327 lines[maxLines - 1] = `${last.trimEnd()}…`;328 }329 const top = o.height / 2 - ((lines.length - 1) * step) / 2;330 lines.forEach((line, i) => ctx.fillText(line, x, top + i * step));331 return;332 }333334 const mainY = o.subtext ? o.height * 0.4 : o.height / 2;335 ctx.fillText(text, x, mainY);336337 if (o.subtext) {338 ctx.globalAlpha = 0.7;339 ctx.font = `500 ${Math.round(size * 0.72)}px ${family}`;340 ctx.fillText(o.subtext, x, o.height * 0.7);341 ctx.globalAlpha = 1;342 }343}344345/**346 * Text drawn into a CanvasTexture, in the page's own font: no font file to download (unlike drei's347 * <Text>). Redrawn once web fonts finish loading; disposed on unmount.348 */349function useLabelTexture(options: LabelOptions) {350 const key = JSON.stringify(options);351 const [fontsVersion, setFontsVersion] = useState(0);352 useEffect(() => {353 let alive = true;354 document.fonts?.ready.then(() => {355 if (alive) setFontsVersion((v) => v + 1);356 });357 return () => {358 alive = false;359 };360 }, []);361362 const texture = useMemo(() => {363 const t = new THREE.CanvasTexture(document.createElement("canvas"));364 t.colorSpace = THREE.SRGBColorSpace;365 t.anisotropy = 4;366 return t;367 }, []);368369 useLayoutEffect(() => {370 drawLabel(texture.image as HTMLCanvasElement, JSON.parse(key) as LabelOptions);371 texture.needsUpdate = true;372 }, [texture, key, fontsVersion]);373374 useEffect(() => () => texture.dispose(), [texture]);375 return texture;376}377378export interface HoloMenuItem {379 label: string;380 action: () => void;381}382383export interface HoloMenuProps extends Pick<MaterialProps, "emissiveColor">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {384 items: HoloMenuItem[];385 emissiveColor?: string;386 /** @deprecated Use `emissiveColor`. */387 holoColor?: string;388 /** 0–1: strength of the glitches. Default 0.5. */389 glitchIntensity?: number;390 /** Short synthesized blip on activation. Default true. */391 sound?: boolean;392 /** Panel title. Default "SYSTEM". */393 title?: string;394}395396const WIDTH = 320;397const ROW_H = 46;398const PAD = 22;399const HEADER = 54;400401const panelVertex = /* glsl */ `402uniform float uTime;403uniform float uGlitch;404varying vec2 vUv;405float hash(float n) { return fract(sin(n) * 43758.5453); }406void main() {407 vUv = uv;408 vec3 p = position;409 // Glitch: horizontal slices jump sideways for a few frames410 float slice = floor(uv.y * 18.0);411 float tick = floor(uTime * 24.0);412 float jump = step(0.86, hash(slice * 7.1 + tick)) * (hash(slice + tick * 3.3) - 0.5);413 p.x += jump * uGlitch * 26.0;414 gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);415}416`;417418const panelFragment = /* glsl */ `419uniform vec3 uColor;420uniform vec2 uSize;421uniform float uTime;422uniform float uGlitch;423uniform float uFlash;424varying vec2 vUv;425float hash(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }426void main() {427 vec2 px = vUv * uSize;428 // Distance to the panel's edge, in pixels429 float edge = min(min(px.x, uSize.x - px.x), min(px.y, uSize.y - px.y));430 // Cut corners: a sci-fi bevel on two opposite corners431 float corner = min(px.x + (uSize.y - px.y), (uSize.x - px.x) + px.y);432 if (corner < 18.0) discard;433 edge = min(edge, (corner - 18.0) * 0.7071);434435 float border = 1.0 - smoothstep(1.0, 2.5, edge);436 float glow = exp(-edge / 10.0) * 0.55;437 float scan = 0.5 + 0.5 * sin(px.y * 1.6 - uTime * 6.0);438 float sweep = smoothstep(0.0, 0.08, fract(vUv.y * 0.5 - uTime * 0.18)) * (1.0 - smoothstep(0.08, 0.12, fract(vUv.y * 0.5 - uTime * 0.18)));439 float noise = hash(floor(px / 2.0) + floor(uTime * 30.0));440 float flicker = 0.92 + 0.08 * sin(uTime * 37.0) * sin(uTime * 13.0);441442 vec3 color = uColor * (0.08 + scan * 0.05 + sweep * 0.2 + noise * 0.04 * (0.4 + uGlitch));443 color += uColor * (border * 1.6 + glow);444 color += vec3(1.0) * uFlash * 0.25;445 float alpha = clamp(0.35 + border + glow + uFlash * 0.3, 0.0, 1.0);446 gl_FragColor = vec4(color * flicker, alpha * flicker);447 #include <colorspace_fragment>448}449`;450451interface RowProps {452 label: string;453 index: number;454 y: number;455 hovered: RefObject<number>;456 color: string;457 geometry: THREE.PlaneGeometry;458 onHover: (index: number) => void;459 onSelect: (index: number) => void;460}461462function Row({ label, index, y, hovered, color, geometry, onHover, onSelect }: RowProps) {463 const gl = useThree((state) => state.gl);464 const texture = useLabelTexture({ text: `› ${label.toUpperCase()}`, width: WIDTH - PAD * 2, height: ROW_H, color: "#ffffff", fontSize: 15, fontWeight: 600, align: "left", padding: 14 });465 const labelMaterial = useMemo(() => new THREE.MeshBasicMaterial({ transparent: true, depthWrite: false, toneMapped: false }), []);466 const barMaterial = useMemo(() => new THREE.MeshBasicMaterial({ transparent: true, depthWrite: false, toneMapped: false, blending: THREE.AdditiveBlending }), []);467 const hitMaterial = useMemo(() => new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false }), []);468 const labelRef = useRef<THREE.Mesh>(null);469 const state = useRef({ hover: 0 });470471 useEffect(() => {472 labelMaterial.map = texture;473 labelMaterial.needsUpdate = true;474 }, [labelMaterial, texture]);475 useEffect(() => {476 labelMaterial.color.set(color);477 barMaterial.color.set(color);478 }, [labelMaterial, barMaterial, color]);479 useEffect(480 () => () => {481 labelMaterial.dispose();482 barMaterial.dispose();483 hitMaterial.dispose();484 },485 [labelMaterial, barMaterial, hitMaterial]486 );487488 useFrame((frame, delta) => {489 const s = state.current;490 s.hover = THREE.MathUtils.damp(s.hover, hovered.current === index ? 1 : 0, 14, delta);491 barMaterial.opacity = s.hover * 0.35;492 labelMaterial.opacity = 0.65 + s.hover * 0.35;493 // The hovered label slides right and jitters a little494 if (labelRef.current) {495 const jitter = s.hover > 0.5 && Math.sin(frame.clock.elapsedTime * 50) > 0.9 ? 2 : 0;496 labelRef.current.position.x = s.hover * 8 + jitter;497 }498 });499500 return (501 <group position={[0, y, 2]}>502 <mesh geometry={geometry} material={barMaterial} scale={[WIDTH - PAD * 2, ROW_H - 8, 1]} />503 <mesh ref={labelRef} geometry={geometry} material={labelMaterial} position={[0, 0, 1]} scale={[WIDTH - PAD * 2, ROW_H, 1]} />504 <mesh505 geometry={geometry}506 material={hitMaterial}507 scale={[WIDTH - PAD * 2, ROW_H, 1]}508 position={[0, 0, 2]}509 onPointerOver={(e: ThreeEvent<PointerEvent>) => {510 e.stopPropagation();511 onHover(index);512 gl.domElement.style.cursor = "pointer";513 }}514 onPointerOut={() => {515 onHover(-1);516 gl.domElement.style.cursor = "";517 }}518 onClick={(e: ThreeEvent<MouseEvent>) => {519 e.stopPropagation();520 onSelect(index);521 }}522 />523 </group>524 );525}526527/** Short square-wave blip for activations (Web Audio, nothing to download). */528function blip(context: AudioContext) {529 const t = context.currentTime;530 const osc = context.createOscillator();531 const gain = context.createGain();532 osc.type = "square";533 osc.frequency.setValueAtTime(880, t);534 osc.frequency.exponentialRampToValueAtTime(1760, t + 0.06);535 gain.gain.setValueAtTime(0.06, t);536 gain.gain.exponentialRampToValueAtTime(0.0001, t + 0.12);537 osc.connect(gain).connect(context.destination);538 osc.start(t);539 osc.stop(t + 0.13);540}541542const Panel = memo(function Panel({ items, emissiveColor, holoColor = emissiveColor ?? "#a78bfa", glitchIntensity = 0.5, sound = true, title = "SYSTEM" }: HoloMenuProps) {543 const groupRef = useRef<THREE.Group>(null);544 const hovered = useRef(-1);545 const fx = useRef({ glitch: 0, burst: 0, flash: 0 });546 const audio = useRef<AudioContext | null>(null);547 const height = HEADER + items.length * ROW_H + PAD;548549 const plane = useMemo(() => new THREE.PlaneGeometry(1, 1), []);550 const panelGeometry = useMemo(() => new THREE.PlaneGeometry(WIDTH, height, 1, 64), [height]);551 const panelMaterial = useMemo(552 () =>553 new THREE.ShaderMaterial({554 uniforms: { uColor: { value: new THREE.Color() }, uSize: { value: new THREE.Vector2(WIDTH, 1) }, uTime: { value: 0 }, uGlitch: { value: 0 }, uFlash: { value: 0 } },555 vertexShader: panelVertex,556 fragmentShader: panelFragment,557 transparent: true,558 depthWrite: false,559 blending: THREE.AdditiveBlending,560 }),561 []562 );563 const titleTexture = useLabelTexture({ text: `// ${title}`, width: WIDTH - PAD * 2, height: 28, color: "#ffffff", fontSize: 11, fontWeight: 700, align: "left", padding: 14 });564 const titleMaterial = useMemo(() => new THREE.MeshBasicMaterial({ transparent: true, depthWrite: false, opacity: 0.55, toneMapped: false }), []);565566 useEffect(() => {567 (panelMaterial.uniforms.uColor.value as THREE.Color).set(holoColor);568 (panelMaterial.uniforms.uSize.value as THREE.Vector2).set(WIDTH, height);569 titleMaterial.color.set(holoColor);570 }, [panelMaterial, titleMaterial, holoColor, height]);571 useEffect(() => {572 titleMaterial.map = titleTexture;573 titleMaterial.needsUpdate = true;574 }, [titleMaterial, titleTexture]);575 useEffect(() => () => plane.dispose(), [plane]);576 useEffect(() => () => panelGeometry.dispose(), [panelGeometry]);577 useEffect(578 () => () => {579 panelMaterial.dispose();580 titleMaterial.dispose();581 audio.current?.close();582 },583 [panelMaterial, titleMaterial]584 );585586 const onHover = (index: number) => {587 if (index >= 0 && index !== hovered.current) fx.current.burst = 1; // glitch burst on each new hover588 hovered.current = index;589 };590 const onSelect = (index: number) => {591 fx.current.flash = 1;592 fx.current.burst = 1;593 if (sound) {594 audio.current ??= new AudioContext();595 blip(audio.current);596 }597 navigator.vibrate?.(12);598 items[index]?.action();599 };600601 useFrame((state, delta) => {602 const dt = Math.min(delta, 1 / 30);603 const t = state.clock.elapsedTime;604 const f = fx.current;605 f.burst *= Math.exp(-9 * dt);606 f.flash *= Math.exp(-6 * dt);607 // Rare idle glitches, strong bursts on hover/click608 const idle = Math.sin(t * 0.7) > 0.985 ? 0.4 : 0;609 f.glitch = Math.max(idle, f.burst) * glitchIntensity;610 const u = panelMaterial.uniforms;611 u.uTime.value = t;612 u.uGlitch.value = f.glitch;613 u.uFlash.value = f.flash;614615 // Levitation drift, leaning slightly towards the pointer616 const g = groupRef.current;617 if (g) {618 g.position.y = Math.sin(t * 0.9) * 6;619 g.rotation.y = THREE.MathUtils.damp(g.rotation.y, state.pointer.x * 0.25 + Math.sin(t * 0.4) * 0.05, 3, dt);620 g.rotation.x = THREE.MathUtils.damp(g.rotation.x, -state.pointer.y * 0.18, 3, dt);621 }622 });623624 const top = height / 2;625 return (626 <group ref={groupRef}>627 <mesh geometry={panelGeometry} material={panelMaterial} />628 <mesh geometry={plane} material={titleMaterial} position={[0, top - PAD - 8, 2]} scale={[WIDTH - PAD * 2, 28, 1]} />629 {items.map((item, i) => (630 <Row631 key={`${i}-${item.label}`}632 label={item.label}633 index={i}634 y={top - HEADER - i * ROW_H - ROW_H / 2}635 hovered={hovered}636 color={holoColor}637 geometry={plane}638 onHover={onHover}639 onSelect={onSelect}640 />641 ))}642 </group>643 );644});645646/** Self-contained menu: fills its positioned parent and centers the panel; real buttons for keyboards. */647function HoloMenu3D(props: HoloMenuProps) {648 return (649 <>650 <UICanvas pauseWhenOffscreen={props.pauseWhenOffscreen} lowPowerMode={props.lowPowerMode}>651 <PixelPerspective />652 <Panel {...props} />653 </UICanvas>654 <nav aria-label={props.title ?? "Menu"} style={SR_ONLY}>655 {props.items.map((item, i) => (656 <button key={`${i}-${item.label}`} type="button" onClick={item.action}>657 {item.label}658 </button>659 ))}660 </nav>661 </>662 );663}664665export default memo(HoloMenu3D);
03
Drop it in a page
Updated live with the settings above.
app/page.tsx
1import HoloMenu3D from "@/components/HoloMenu3D";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 <HoloMenu3D8 glitchIntensity={0.5}9 emissiveColor="#a78bfa"10 />11 </div>12 );13}