← All components Next componentPrism Accordion→
Gallery · Helix
Spiral Helix
An endless helix of images scrolled by wheel or drag; click a card to center it.
<SpiralHelixGallery />Live
Scroll or drag · click to center
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 spiral-helix
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber @react-three/drei && npm install -D @types/three
02
Add the component
One self-contained file: create components/SpiralHelixGallery.tsx and paste it in.
components/SpiralHelixGallery.tsx
1"use client";23import {4 Component,5 memo,6 Suspense,7 useCallback,8 useEffect,9 useLayoutEffect,10 useMemo,11 useRef,12 useState,13 type CSSProperties,14 type ReactNode,15 type Ref,16} from "react";17import * as THREE from "three";18import {19 Canvas,20 useFrame,21 useThree,22 type CanvasProps,23 type ThreeElements,24 type ThreeEvent,25} from "@react-three/fiber";26import { useTexture } from "@react-three/drei";2728/**29 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep30 * their own tailored scenes).31 *32 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its33 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):34 *35 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }36 *37 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,38 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are39 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.40 */4142/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */43export type TiltAxis = "both" | "x-only" | "y-only" | "none";4445/** 1. Cursor: how the pointer pulls, pushes and drags the object. */46interface CursorProps {47 /** 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). */48 cursorRadius?: number;49 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */50 cursorForce?: number;51 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */52 magneticStrength?: number;53 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */54 cursorDamping?: number;55}5657/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */58interface TiltProps {59 /** Largest lean towards the pointer, in degrees. Default 15. */60 maxTiltAngle?: number;61 /** Axes that follow the pointer. Default "both". */62 tiltAxis?: TiltAxis;63 /** Lean away from the pointer instead of towards it. Default false. */64 invertTilt?: boolean;65 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */66 parallaxOffset?: number;67}6869/** 3. Text and 3D typography, for components that draw a label. */70interface Text3DProps {71 /** The label drawn by the component. */72 text?: string;73 /** Scale of the lettering. Default 1. */74 fontSize?: number;75 /** Extrusion depth of 3D letters. Default 0.2. */76 textDepth?: number;77 /** Bevelled, light-catching edges on 3D letters. Default true. */78 bevelEnabled?: boolean;79 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */80 fontUrl?: string;81}8283/** 4. Rendering, materials and glow. */84interface MaterialProps {85 /** Main color of the object. Default "#6366f1". */86 primaryColor?: string;87 /** Color of the glow. Default "#00f0ff". */88 emissiveColor?: string;89 /** Strength of the glow, 0 (none) to 3. Default 1. */90 emissiveIntensity?: number;91 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */92 roughness?: number;93 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */94 metalness?: number;95 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */96 transmission?: number;97 /** Technical wireframe rendering. Default false. */98 wireframe?: boolean;99}100101/** 5. Particles, idle motion and shader animation. */102interface MotionProps {103 /** Number of instanced elements. Default depends on the component. */104 particleCount?: number;105 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */106 autoRotateSpeed?: number;107 /** Pulses or ripples per second. Default 1. */108 pulseRate?: number;109 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */110 displacementScale?: number;111}112113/** 6. Environment and camera. */114interface EnvironmentProps {115 /** Camera field of view, in degrees. Default depends on the component. */116 cameraFov?: number;117 /** Color of the depth fog. Default "#0a0a0a". */118 fogColor?: string;119 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */120 fogDensity?: number;121}122123/** 7. Performance and accessibility. */124interface PerformanceProps {125 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */126 lowPowerMode?: boolean;127 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */128 respectReducedMotion?: boolean;129 /** Stop the render loop while the component is scrolled out of view. Default true. */130 pauseWhenOffscreen?: boolean;131}132133/** Every group at once. Components extend only the groups they apply (see the top of this file). */134interface Base3DComponentProps135 extends CursorProps,136 TiltProps,137 Text3DProps,138 MaterialProps,139 MotionProps,140 EnvironmentProps,141 PerformanceProps {}142143type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;144145/** The values a prop takes when it is left out. A component may override one, and then documents it. */146const DEFAULT_3D_PROPS: Defaults = {147 cursorRadius: 220,148 cursorForce: 1,149 magneticStrength: 0,150 cursorDamping: 0.1,151 maxTiltAngle: 15,152 tiltAxis: "both",153 invertTilt: false,154 parallaxOffset: 1,155 fontSize: 1,156 textDepth: 0.2,157 bevelEnabled: true,158 primaryColor: "#6366f1",159 emissiveColor: "#00f0ff",160 emissiveIntensity: 1,161 roughness: 0.3,162 metalness: 0.5,163 transmission: 0,164 wireframe: false,165 autoRotateSpeed: 0,166 pulseRate: 1,167 displacementScale: 1,168 fogColor: "#0a0a0a",169 fogDensity: 0,170 lowPowerMode: false,171 respectReducedMotion: true,172 pauseWhenOffscreen: true,173};174175/** Fills the positioned parent. Unlike the backgrounds, galleries receive pointer events. */176const GALLERY_STYLE: CSSProperties = {177 position: "absolute",178 top: 0,179 left: 0,180 width: "100%",181 height: "100%",182};183184interface GalleryCanvasProps extends Omit<CanvasProps, "children" | "style" | "frameloop" | "gl">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {185 children: ReactNode;186 /**187 * The gallery uses the wheel: Lenis (site-wide smooth scroll) is told to leave wheel events188 * over the canvas alone, so the gallery's own handler decides whether the page scrolls.189 */190 captureWheel?: boolean;191 /** CSS touch-action of the canvas: "pan-y" keeps vertical page scrolling on touch screens. */192 touchAction?: CSSProperties["touchAction"];193}194195/**196 * Ready-to-use <Canvas> shared by every gallery: the render loop pauses while the gallery is197 * scrolled out of view, and R3F disposes the renderer and its WebGL context on unmount.198 */199function GalleryCanvas({ children, captureWheel = false, touchAction = "pan-y", dpr = [1, 2], pauseWhenOffscreen = DEFAULT_3D_PROPS.pauseWhenOffscreen, lowPowerMode = DEFAULT_3D_PROPS.lowPowerMode, ...canvasProps }: GalleryCanvasProps) {200 const containerRef = useRef<HTMLDivElement>(null);201 const [inView, setInView] = useState(true);202203 useEffect(() => {204 const el = containerRef.current;205 if (!el) return undefined;206 const observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));207 observer.observe(el);208 return () => observer.disconnect();209 }, []);210211 return (212 <div ref={containerRef} style={GALLERY_STYLE} {...(captureWheel ? { "data-lenis-prevent": "" } : {})}>213 <Canvas214 dpr={lowPowerMode ? 1 : dpr}215 frameloop={inView || !pauseWhenOffscreen ? "always" : "never"}216 gl={{ antialias: true, alpha: true, powerPreference: "high-performance" }}217 style={{ touchAction }}218 {...canvasProps}219 >220 {children}221 </Canvas>222 </div>223 );224}225226interface DragHandlers {227 /** false: the canvas ignores drags (no grab cursor). Default true. */228 enabled?: boolean;229 onStart?: () => void;230 /** Movement since the previous event, in CSS pixels. */231 onMove: (dx: number, dy: number) => void;232 /** Release velocity, in CSS pixels per second (for inertia). */233 onEnd?: (vx: number, vy: number) => void;234}235236/** Drag on the canvas (mouse, pen or touch), with release velocity for inertia. */237function useCanvasDrag(handlers: DragHandlers) {238 const gl = useThree((state) => state.gl);239 const handlersRef = useRef(handlers);240 useEffect(() => {241 handlersRef.current = handlers;242 });243244 useEffect(() => {245 const el = gl.domElement;246 let pointerId: number | null = null;247 let lastX = 0;248 let lastY = 0;249 let lastTime = 0;250 let vx = 0;251 let vy = 0;252 const grab = () => (handlersRef.current.enabled === false ? "" : "grab");253 el.style.cursor = grab();254255 const down = (event: PointerEvent) => {256 if (event.button !== 0 || pointerId !== null || handlersRef.current.enabled === false) return;257 pointerId = event.pointerId;258 lastX = event.clientX;259 lastY = event.clientY;260 lastTime = performance.now();261 vx = 0;262 vy = 0;263 el.style.cursor = "grabbing";264 handlersRef.current.onStart?.();265 };266 const move = (event: PointerEvent) => {267 if (event.pointerId !== pointerId) return;268 const now = performance.now();269 const dt = Math.max(1, now - lastTime) / 1000;270 const dx = event.clientX - lastX;271 const dy = event.clientY - lastY;272 // Smoothed velocity: a single jittery event at release must not decide the inertia273 vx = vx * 0.6 + (dx / dt) * 0.4;274 vy = vy * 0.6 + (dy / dt) * 0.4;275 lastX = event.clientX;276 lastY = event.clientY;277 lastTime = now;278 handlersRef.current.onMove(dx, dy);279 };280 const up = (event: PointerEvent) => {281 if (event.pointerId !== pointerId) return;282 pointerId = null;283 el.style.cursor = grab();284 // A pause before releasing means no throw285 const idle = performance.now() - lastTime > 80;286 handlersRef.current.onEnd?.(idle ? 0 : vx, idle ? 0 : vy);287 };288289 el.addEventListener("pointerdown", down);290 window.addEventListener("pointermove", move, { passive: true });291 window.addEventListener("pointerup", up);292 window.addEventListener("pointercancel", up);293 return () => {294 el.removeEventListener("pointerdown", down);295 window.removeEventListener("pointermove", move);296 window.removeEventListener("pointerup", up);297 window.removeEventListener("pointercancel", up);298 el.style.cursor = "";299 };300 }, [gl]);301}302303/**304 * Wheel over the canvas. The handler returns true when it used the event: the page then does not305 * scroll. Returning false (e.g. at the end of a tunnel) lets the page scroll on.306 */307function useCanvasWheel(onWheel: (event: WheelEvent) => boolean) {308 const gl = useThree((state) => state.gl);309 const handlerRef = useRef(onWheel);310 useEffect(() => {311 handlerRef.current = onWheel;312 });313 useEffect(() => {314 const el = gl.domElement;315 const listener = (event: WheelEvent) => {316 if (handlerRef.current(event)) event.preventDefault();317 };318 el.addEventListener("wheel", listener, { passive: false });319 return () => el.removeEventListener("wheel", listener);320 }, [gl]);321}322323/**324 * Collects the textures loaded by a gallery's cards and disposes them (plus drei's loader cache325 * entries) when the gallery unmounts or its image list changes.326 */327function useGalleryTextures(urls: string[]) {328 const textures = useRef(new Set<THREE.Texture>());329 const key = urls.join("\n");330 const onTexture = useCallback((texture: THREE.Texture) => {331 textures.current.add(texture);332 }, []);333334 useEffect(() => {335 const loaded = textures.current;336 return () => {337 loaded.forEach((texture) => texture.dispose());338 loaded.clear();339 const list = key ? key.split("\n") : [];340 if (list.length) useTexture.clear(list);341 };342 }, [key]);343344 return onTexture;345}346347/** Repeats the image list until it has at least `min` entries (a sphere or a ring needs enough cards). */348function cycleImages(images: string[], min: number) {349 if (!images.length) return [];350 const count = Math.max(images.length, min);351 return Array.from({ length: count }, (_, i) => images[i % images.length]);352}353354const cardVertexShader = /* glsl */ `355uniform float uCurve; // 1 / radius: bends the card around the Y axis, convex side out (0 = flat)356357varying vec2 vUv;358varying float vFacing;359360void main() {361 vUv = uv;362 vec3 p = position;363 vec3 n = vec3(0.0, 0.0, 1.0);364 if (uCurve > 0.0001) {365 float a = p.x * uCurve;366 p.x = sin(a) / uCurve;367 p.z = (cos(a) - 1.0) / uCurve;368 n = vec3(sin(a), 0.0, cos(a));369 }370 vec4 mvPosition = modelViewMatrix * vec4(p, 1.0);371 vFacing = abs(dot(normalize(normalMatrix * n), normalize(-mvPosition.xyz)));372 gl_Position = projectionMatrix * mvPosition;373}374`;375376const cardFragmentShader = /* glsl */ `377uniform sampler2D uMap;378uniform float uHasMap; // 1 once the texture is loaded379uniform float uReveal; // 0 → 1 fade from the placeholder to the image380uniform float uImageAspect;381uniform vec2 uSize; // card size in world units382uniform float uRadius; // corner radius in world units383uniform float uZoom; // > 1 crops into the image (headroom for parallax)384uniform vec2 uOffset; // image shift inside the card (parallax), in UV units385uniform float uBlur; // motion blur length, in UV units386uniform vec2 uBlurDir;387uniform float uOpacity;388uniform float uDim; // 0 = full brightness, 1 = black389uniform float uHover; // 0 → 1 highlight390uniform float uShade; // how much faces turned away from the camera darken391uniform float uTime;392uniform vec3 uTint; // placeholder color393394varying vec2 vUv;395varying float vFacing;396397// "object-fit: cover": the image fills the card without stretching398vec2 coverUv(vec2 uv) {399 float planeAspect = uSize.x / uSize.y;400 vec2 scale = planeAspect > uImageAspect ? vec2(1.0, uImageAspect / planeAspect) : vec2(planeAspect / uImageAspect, 1.0);401 return (uv - 0.5) * scale / uZoom + 0.5 + uOffset;402}403404float roundedMask(vec2 uv) {405 vec2 p = (uv - 0.5) * uSize;406 vec2 q = abs(p) - (uSize * 0.5 - uRadius);407 float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - uRadius;408 float aa = fwidth(d);409 return 1.0 - smoothstep(-aa, aa, d);410}411412void main() {413 vec2 uv = vUv;414 // Seen from behind (a ring's far side), the image would be mirrored: flip it back415 if (!gl_FrontFacing) uv.x = 1.0 - uv.x;416417 float mask = roundedMask(vUv);418 float alpha = mask * uOpacity;419 if (alpha < 0.005) discard;420421 // Placeholder: dark tint with a sweeping shimmer while the texture loads422 float shimmer = pow(max(0.0, sin((vUv.x - vUv.y * 0.5) * 3.0 - uTime * 2.5)), 12.0);423 vec3 color = uTint + shimmer * 0.06;424425 if (uHasMap > 0.5) {426 vec2 imageUv = coverUv(uv);427 vec3 image;428 if (uBlur > 0.0005) {429 // Motion blur: 7 taps along the direction of travel430 image = vec3(0.0);431 for (int i = 0; i < 7; i++) {432 float t = (float(i) / 6.0 - 0.5) * uBlur;433 image += texture2D(uMap, imageUv + uBlurDir * t).rgb;434 }435 image /= 7.0;436 } else {437 image = texture2D(uMap, imageUv).rgb;438 }439 color = mix(color, image, uReveal);440 }441442 color *= mix(1.0, 0.35 + 0.65 * vFacing, uShade);443 color *= 1.0 - uDim;444 color += uHover * 0.07;445 gl_FragColor = vec4(color, alpha);446 #include <colorspace_fragment>447}448`;449450interface CardUniforms {451 uMap: THREE.IUniform<THREE.Texture | null>;452 uHasMap: THREE.IUniform<number>;453 uReveal: THREE.IUniform<number>;454 uImageAspect: THREE.IUniform<number>;455 uSize: THREE.IUniform<THREE.Vector2>;456 uRadius: THREE.IUniform<number>;457 uCurve: THREE.IUniform<number>;458 uZoom: THREE.IUniform<number>;459 uOffset: THREE.IUniform<THREE.Vector2>;460 uBlur: THREE.IUniform<number>;461 uBlurDir: THREE.IUniform<THREE.Vector2>;462 uOpacity: THREE.IUniform<number>;463 uDim: THREE.IUniform<number>;464 uHover: THREE.IUniform<number>;465 uShade: THREE.IUniform<number>;466 uTime: THREE.IUniform<number>;467 uTint: THREE.IUniform<THREE.Color>;468}469470function createCardMaterial() {471 const uniforms: CardUniforms = {472 uMap: { value: null },473 uHasMap: { value: 0 },474 uReveal: { value: 0 },475 uImageAspect: { value: 1 },476 uSize: { value: new THREE.Vector2(1, 1) },477 uRadius: { value: 0.06 },478 uCurve: { value: 0 },479 uZoom: { value: 1 },480 uOffset: { value: new THREE.Vector2() },481 uBlur: { value: 0 },482 uBlurDir: { value: new THREE.Vector2(0, 1) },483 uOpacity: { value: 1 },484 uDim: { value: 0 },485 uHover: { value: 0 },486 uShade: { value: 0 },487 uTime: { value: 0 },488 uTint: { value: new THREE.Color() },489 };490 return new THREE.ShaderMaterial({491 uniforms: uniforms as unknown as Record<string, THREE.IUniform>,492 vertexShader: cardVertexShader,493 fragmentShader: cardFragmentShader,494 transparent: true,495 side: THREE.DoubleSide,496 });497}498499/** Typed access to a card's uniforms from its mesh (galleries animate them in useFrame). */500function cardUniforms(mesh: THREE.Mesh) {501 return (mesh.material as THREE.ShaderMaterial).uniforms as unknown as CardUniforms;502}503504/** Plane sized in world units; enough columns to bend smoothly when the card is curved. */505function createCardGeometry(width: number, height: number, segments = 1) {506 return new THREE.PlaneGeometry(width, height, segments, 1);507}508509function TextureBinder({ url, material, onTexture }: { url: string; material: THREE.ShaderMaterial; onTexture?: (texture: THREE.Texture) => void }) {510 const texture = useTexture(url); // suspends until loaded; drei caches it per URL511 useLayoutEffect(() => {512 if (texture.colorSpace !== THREE.SRGBColorSpace) {513 texture.colorSpace = THREE.SRGBColorSpace;514 texture.needsUpdate = true;515 }516 texture.anisotropy = 4;517 const image = texture.image as { width?: number; height?: number } | undefined;518 const u = material.uniforms as unknown as CardUniforms;519 if (u.uMap.value !== texture) u.uReveal.value = 0; // fade in each new image520 u.uMap.value = texture;521 u.uImageAspect.value = image?.width && image?.height ? image.width / image.height : 1;522 u.uHasMap.value = 1;523 onTexture?.(texture);524 }, [texture, material, onTexture]);525 return null;526}527528/** A failed image keeps its placeholder instead of breaking the whole gallery. */529class TextureErrorBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {530 state = { failed: false };531 static getDerivedStateFromError() {532 return { failed: true };533 }534 render() {535 return this.state.failed ? null : this.props.children;536 }537}538539interface ImageCardProps extends Omit<ThreeElements["mesh"], "geometry" | "material" | "ref"> {540 url: string;541 width: number;542 height: number;543 /** Shared plane from createCardGeometry(width, height, segments). */544 geometry: THREE.BufferGeometry;545 radius?: number;546 /** 1 / radius of the surface the card is bent on (0 = flat). */547 curve?: number;548 /** 0–1: darken the card as it turns away from the camera. */549 shade?: number;550 zoom?: number;551 placeholderColor?: string;552 onTexture?: (texture: THREE.Texture) => void;553 ref?: Ref<THREE.Mesh>;554}555556/**557 * Image card: rounded corners, cover-fit image, placeholder shimmer while loading, fade-in once558 * loaded, placeholder kept if the image fails. Its material is created once and disposed on unmount.559 */560const ImageCard = memo(function ImageCard({561 url,562 width,563 height,564 geometry,565 radius = 0.06,566 curve = 0,567 shade = 0,568 zoom = 1,569 placeholderColor = "#151517",570 onTexture,571 ref,572 ...meshProps573}: ImageCardProps) {574 const material = useMemo(() => createCardMaterial(), []);575 const u = material.uniforms as unknown as CardUniforms;576577 useEffect(() => {578 u.uSize.value.set(width, height);579 u.uRadius.value = Math.min(radius, width / 2, height / 2);580 u.uCurve.value = curve;581 u.uShade.value = shade;582 u.uZoom.value = zoom;583 u.uTint.value.set(placeholderColor);584 }, [u, width, height, radius, curve, shade, zoom, placeholderColor]);585586 useEffect(() => () => material.dispose(), [material]);587588 useFrame((state, delta) => {589 if (u.uHasMap.value > 0.5) {590 if (u.uReveal.value < 0.999) u.uReveal.value = THREE.MathUtils.damp(u.uReveal.value, 1, 5, delta);591 } else {592 u.uTime.value = state.clock.elapsedTime;593 }594 });595596 return (597 // The shader bends the card: the plane's own bounds are not reliable for frustum culling598 <mesh ref={ref} geometry={geometry} material={material} frustumCulled={false} {...meshProps}>599 <TextureErrorBoundary key={url}>600 <Suspense fallback={null}>601 <TextureBinder url={url} material={material} onTexture={onTexture} />602 </Suspense>603 </TextureErrorBoundary>604 </mesh>605 );606});607608export interface SpiralHelixProps extends Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {609 images: string[];610 /** Distance of the cards from the helix axis. Default 3.2. */611 radius?: number;612 /** Height between two consecutive cards. Default 0.75. */613 verticalSpacing?: number;614 /** Rotation between two consecutive cards, in radians. Default 0.42. */615 twistFactor?: number;616}617618const CARD_WIDTH = 1.7;619const CARD_HEIGHT = 1.12;620621/** Wraps v into [-span/2, span/2). */622function wrap(v: number, span: number) {623 return ((((v + span / 2) % span) + span) % span) - span / 2;624}625626const Helix = memo(function Helix({ images, radius, verticalSpacing, twistFactor }: Required<Omit<SpiralHelixProps, "pauseWhenOffscreen" | "lowPowerMode">>) {627 const onTexture = useGalleryTextures(images);628 // Enough cards for three full turns, so the loop point is always far out of view629 const turns = Math.ceil((2 * Math.PI) / Math.max(0.05, twistFactor));630 const cards = useMemo(() => cycleImages(images, Math.max(24, turns * 3)), [images, turns]);631 const cardRefs = useRef<(THREE.Mesh | null)[]>([]);632 const hovered = useRef(-1);633 const scroll = useRef({ current: 0, target: 0, velocity: 0 });634 const total = cards.length * verticalSpacing;635636 const geometry = useMemo(() => createCardGeometry(CARD_WIDTH, CARD_HEIGHT, 24), []);637 useEffect(() => () => geometry.dispose(), [geometry]);638639 // Infinite: the wheel and vertical drags move along the spiral forever640 useCanvasWheel((event) => {641 scroll.current.target += event.deltaY * 0.0035 * verticalSpacing;642 return true;643 });644 useCanvasDrag({645 onStart: () => {646 scroll.current.velocity = 0;647 },648 onMove: (_, dy) => {649 scroll.current.target -= dy * 0.012;650 },651 onEnd: (_, vy) => {652 scroll.current.velocity = -vy * 0.012;653 },654 });655656 useFrame((state, delta) => {657 const dt = Math.min(delta, 1 / 30);658 const s = scroll.current;659 s.target += s.velocity * dt;660 s.velocity *= Math.exp(-3 * dt);661 s.current = THREE.MathUtils.damp(s.current, s.target, 6, dt);662663 cardRefs.current.forEach((mesh, i) => {664 if (!mesh) return;665 // Height relative to the camera, looped; the angle follows the height, so the whole helix666 // turns in sync as it scrolls and the card at eye level always faces the camera667 const y = -wrap(i * verticalSpacing - s.current, total);668 const angle = (-y / verticalSpacing) * twistFactor;669 mesh.position.set(Math.sin(angle) * radius, y, Math.cos(angle) * radius);670 mesh.rotation.y = angle;671672 const u = cardUniforms(mesh);673 const facing = Math.cos(angle) * 0.5 + 0.5;674 const level = 1 - THREE.MathUtils.smoothstep(Math.abs(y), 0.5, 4.5);675 const emphasis = facing * (0.35 + 0.65 * level);676 u.uDim.value = (1 - emphasis) * 0.8;677 u.uOpacity.value = (0.25 + 0.75 * facing) * (1 - THREE.MathUtils.smoothstep(Math.abs(y), total * 0.3, total * 0.45));678 const hover = THREE.MathUtils.damp(u.uHover.value, hovered.current === i ? 1 : 0, 10, dt);679 u.uHover.value = hover;680 mesh.scale.setScalar(0.85 + emphasis * 0.2 + hover * 0.06);681 });682683 state.camera.position.x = THREE.MathUtils.damp(state.camera.position.x, state.pointer.x * 0.7, 2, dt);684 state.camera.position.y = THREE.MathUtils.damp(state.camera.position.y, 0.6 + state.pointer.y * 0.5, 2, dt);685 state.camera.lookAt(0, 0, 0);686 });687688 return (689 <>690 {/* Faint spine along the axis */}691 <mesh position={[0, 0, 0]}>692 <cylinderGeometry args={[0.012, 0.012, 40, 8]} />693 <meshBasicMaterial color="#ffffff" transparent opacity={0.12} />694 </mesh>695 {cards.map((url, i) => (696 <ImageCard697 key={i}698 ref={(mesh) => {699 cardRefs.current[i] = mesh;700 }}701 url={url}702 width={CARD_WIDTH}703 height={CARD_HEIGHT}704 geometry={geometry}705 curve={1 / radius}706 shade={0.5}707 radius={0.07}708 onTexture={onTexture}709 onPointerOver={(e: ThreeEvent<PointerEvent>) => {710 e.stopPropagation();711 hovered.current = i;712 }}713 onPointerOut={() => {714 if (hovered.current === i) hovered.current = -1;715 }}716 onClick={(e: ThreeEvent<MouseEvent>) => {717 e.stopPropagation();718 if (e.delta > 6) return;719 // Click: scroll the shortest way until that card is at eye level720 const s = scroll.current;721 s.target += wrap(i * verticalSpacing - s.target, total);722 s.velocity = 0;723 }}724 />725 ))}726 </>727 );728});729730function SpiralHelixGallery({ images, radius = 3.2, verticalSpacing = 0.75, twistFactor = 0.42, pauseWhenOffscreen, lowPowerMode }: SpiralHelixProps) {731 return (732 <GalleryCanvas pauseWhenOffscreen={pauseWhenOffscreen} lowPowerMode={lowPowerMode} captureWheel touchAction="pan-x" camera={{ position: [0, 0.6, radius + 6.5], fov: 45 }}>733 <Helix images={images} radius={radius} verticalSpacing={verticalSpacing} twistFactor={twistFactor} />734 </GalleryCanvas>735 );736}737738export default memo(SpiralHelixGallery);
03
Drop it in a page
Updated live with the settings above.
app/page.tsx
1import SpiralHelixGallery from "@/components/SpiralHelixGallery";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 <SpiralHelixGallery8 images={[9 "/3d1.jpg",10 "/3d2.jpg",11 "/3d3.jpg",12 "/3d4.jpg",13 "/blackhole.jpg",14 "/cowboy.jpg",15 "/girl.jpg",16 "/haine.jpg",17 "/heart.jpg",18 "/piastri.jpg",19 "/touching.jpg",20 "/scroll-expand-bg.jpg",21 ]}22 radius={3.2}23 verticalSpacing={0.75}24 twistFactor={0.42}25 />26 </div>27 );28}