Scale Fold
A dark sheet of faceted hexagonal scales, folding in slow, deep waves under cool raking light. Thousands of real 3D scales pack edge to edge, each a cut, physically lit solid, so the facets along every crest glint blue while the crevices fall to black. It moves like springy armour: your cursor presses a gentle dent into the sheet and the scales around it flare up and settle back with a little bounce, a click sends a ripple running out across the surface, and scrolling drives the folds, which flow faster with momentum and ease back. On load the sheet rises out of the dark.
Tweak
LIVELIVEScales
Motion
Interactive
Hover to press and flare the scales, click for a ripple, scroll to drive the folds
Usage
Follows your tweaks.
import { ScaleFold } from "@/components/inreact/scale-fold";
export function Hero() {
return (
<ScaleFold
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the scales */}
</ScaleFold>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/scale-fold.jsonOr copy the source
Install the dependencies, then save this as components/inreact/scale-fold.tsx.
npm install three gsap"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
import * as THREE from "three";
import { EffectComposer } from "three/addons/postprocessing/EffectComposer.js";
import { OutputPass } from "three/addons/postprocessing/OutputPass.js";
import { RenderPass } from "three/addons/postprocessing/RenderPass.js";
import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js";
gsap.registerPlugin(ScrollTrigger);
/**
* Scale Fold: a dark sheet of faceted hexagonal scales, folding in slow waves under cool light.
*
* Thousands of real 3D hex-pyramid scales, packed edge to edge, ride a surface
* that rolls in deep soft folds. Every scale is a faceted, physically based
* solid lit by raking blue light and a strip-light studio, so the facets facing
* the light glint along the crest of each fold while the crevices fall to black.
* Drawn on the GPU in one call, supersampled and multisampled so the facets stay
* crisp.
*
* It moves like scaled armour, springy and alive: your cursor presses into the
* sheet and the scales around it flare up and settle back with a little spring;
* a click sends a ripple running out across the surface; scrolling drives the
* folds, which flow faster with momentum and ease back. On load the sheet rises
* out of the dark.
*
* <ScaleFold className="h-screen w-full">
* <YourHero />
* </ScaleFold>
*
* three.js (WebGL2), ACES tone mapping and a soft bloom. Pauses off-screen;
* reduced motion shows a still frame; a CSS gradient without WebGL2.
*/
export interface ScaleFoldProps {
/** Colour of the raking light. */
color?: string;
/** Colour of the scales themselves. */
body?: string;
/** Background colour. */
background?: string;
/** Size of the scales. */
scale?: number;
/** Depth of the folds. */
folds?: number;
/** Speed of the flowing folds. */
speed?: number;
/** Strength of the bloom on glints. */
glow?: number;
/** Cursor press and flare, click ripple, scroll flow. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the sheet. */
children?: ReactNode;
className?: string;
}
const FX = 80; // spring membrane grid (columns); rows follow the sheet's aspect
// one scale: a hexagonal pyramid with a softly convex profile. Each facet is flat across
// its width and smooth along its height, so it reads as a cut, polished solid.
function studGeometry() {
const prof: [number, number][] = [
[1, 0],
[0.97, 0.1],
[0.87, 0.28],
[0.68, 0.47],
[0.43, 0.62],
[0.18, 0.72],
[0.0, 0.76],
];
const pos: number[] = [], nor: number[] = [], idx: number[] = [];
const n = prof.length;
for (let k = 0; k < 6; k++) {
const a0 = (k * Math.PI) / 3 + Math.PI / 6;
const a1 = a0 + Math.PI / 3;
const ac = (a0 + a1) / 2;
const base = pos.length / 3;
for (let i = 0; i < n; i++) {
const [r, y] = prof[i];
const ip = Math.max(0, i - 1), inx = Math.min(n - 1, i + 1);
const dr = prof[inx][0] - prof[ip][0], dy = prof[inx][1] - prof[ip][1];
let nh = dy, nv = -dr * 0.866;
const l = Math.hypot(nh, nv) || 1;
nh /= l;
nv /= l;
for (const a of [a0, a1]) {
pos.push(r * Math.cos(a), y, r * Math.sin(a));
nor.push(nh * Math.cos(ac), nv, nh * Math.sin(ac));
}
}
for (let i = 0; i < n - 1; i++) {
const A = base + 2 * i, B = A + 1, C = A + 2, D = A + 3;
idx.push(A, C, B, B, C, D);
}
}
const g = new THREE.BufferGeometry();
g.setAttribute("position", new THREE.Float32BufferAttribute(pos, 3));
g.setAttribute("normal", new THREE.Float32BufferAttribute(nor, 3));
g.setIndex(idx);
return g;
}
// strip-light studio, tinted by the light colour: long reflections across the facets, no hot spots
function studio(tint: THREE.Color) {
const env = new THREE.Scene();
env.background = new THREE.Color(0x000000);
const panel = (w: number, h: number, power: number, x: number, y: number, z: number, white = false) => {
const c = white ? new THREE.Color(power, power, power) : tint.clone().multiplyScalar(power);
const m = new THREE.Mesh(new THREE.PlaneGeometry(w, h), new THREE.MeshBasicMaterial({ color: c, side: THREE.DoubleSide }));
m.position.set(x, y, z);
m.lookAt(0, 0, 0);
env.add(m);
};
panel(3, 14, 2.4, -5, 4, 1);
panel(12, 3, 1.8, 0, 6, -2);
panel(0.6, 12, 0.6, 5, -1, 3, true);
return env;
}
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
export function ScaleFold({
color = "#4f9fd6",
body = "#262c34",
background = "#000000",
scale = 1,
folds = 1,
speed = 1,
glow = 0.3,
interactive = true,
scroller,
children,
className,
}: ScaleFoldProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, body, background, scale, folds, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
const rebuild = useRef<(() => void) | null>(null);
useEffect(() => {
const prev = props.current;
props.current = { color, body, background, scale, folds, speed, glow, interactive };
if (prev.scale !== scale || prev.color !== color) rebuild.current?.();
redraw.current?.();
}, [color, body, background, scale, folds, speed, glow, interactive]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;";
host.prepend(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, antialias: false, alpha: false, powerPreference: "high-performance" });
} catch {
const p = props.current;
host.style.background = `radial-gradient(80% 60% at 30% 30%, ${p.color}33, transparent 70%), ${p.background}`;
canvas.remove();
return;
}
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.2;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
scene.background = new THREE.Color();
scene.fog = new THREE.Fog(0x000000, 6.5, 12.5);
const pmrem = new THREE.PMREMGenerator(renderer);
let envTex: THREE.Texture | null = null;
const buildEnv = () => {
envTex?.dispose();
const env = studio(new THREE.Color(props.current.color));
envTex = pmrem.fromScene(env, 0.02).texture;
env.traverse((o) => {
if (o instanceof THREE.Mesh) {
o.geometry.dispose();
(o.material as THREE.Material).dispose();
}
});
scene.environment = envTex;
};
buildEnv();
scene.environmentIntensity = 0.5;
const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 60);
const sheet = new THREE.Group();
scene.add(sheet);
// the sheet leans back and turns, so the folds run diagonally across the view
sheet.rotation.set(-0.64, 0.16, 0.48);
const rake = new THREE.DirectionalLight(0xffffff, 2.6);
rake.position.set(-5, 5, 2.5);
const back = new THREE.DirectionalLight(0xffffff, 1.0);
back.position.set(4, 3, -4);
const fill = new THREE.DirectionalLight(0xffffff, 0.15);
fill.position.set(2, -3, 5);
scene.add(rake, back, fill);
// ---- the spring membrane: height (pressed in, rippling) and flare (scales lifting) ----
let FY = 64;
let field = new Uint16Array(FX * FY * 2);
let hNow = new Float32Array(FX * FY), hVel = new Float32Array(FX * FY);
let fl = new Float32Array(FX * FY), flVel = new Float32Array(FX * FY);
const fieldTex = new THREE.DataTexture(field, FX, FY, THREE.RGFormat, THREE.HalfFloatType);
fieldTex.minFilter = fieldTex.magFilter = THREE.LinearFilter;
fieldTex.needsUpdate = true;
let fieldLive = false;
// ---- the scales: one instanced draw, each scale placed and oriented on the surface in the shader ----
const uni = {
uTime: { value: 0 },
uAmp: { value: 0 },
uRect: { value: new THREE.Vector4(-5, -5, 10, 10) },
uField: { value: fieldTex as THREE.Texture },
uStud: { value: 0.09 },
};
const mat = new THREE.MeshPhysicalMaterial({
color: 0x262c34,
metalness: 0.2,
roughness: 0.42,
clearcoat: 0.5,
clearcoatRoughness: 0.25,
specularIntensity: 1,
});
mat.onBeforeCompile = (sh) => {
Object.assign(sh.uniforms, uni);
sh.vertexShader = sh.vertexShader
.replace(
"#include <common>",
`#include <common>
attribute vec2 aGrid;
attribute float aSeed;
uniform float uTime, uAmp, uStud;
uniform vec4 uRect;
uniform sampler2D uField;
varying float vAO;
vec2 fieldAt(vec2 p) { return texture2D(uField, (p - uRect.xy) / uRect.zw).rg; }
// deep, soft folds rolling slowly across the sheet
float surf(vec2 p) {
float t = uTime;
vec2 q = p + vec2(0.45 * sin(p.y * 0.42 + t * 0.21), 0.3 * sin(p.x * 0.35 - t * 0.17));
// one big slow S-fold, then the rolling folds on top of it
float h = 1.5 * sin(q.x * 0.24 - q.y * 0.17 + t * 0.12 + 0.6);
h += 1.0 * sin(q.x * 0.5 + q.y * 0.3 + t * 0.32);
h += 0.62 * sin(-q.x * 0.28 + q.y * 0.66 - t * 0.24 + 1.7);
h += 0.3 * sin(q.x * 0.9 - q.y * 0.5 + t * 0.41 + 4.0);
return h * 1.32 * uAmp + fieldAt(p).r;
}`,
)
.replace(
"#include <beginnormal_vertex>",
`vec2 sfG = aGrid;
float sfE = 0.06;
float sfH = surf(sfG);
vec3 sfS = vec3(sfG, sfH);
vec3 sfT = normalize(vec3(sfE, 0.0, surf(sfG + vec2(sfE, 0.0)) - sfH));
vec3 sfB = normalize(vec3(0.0, sfE, surf(sfG + vec2(0.0, sfE)) - sfH));
vec3 sfN = normalize(cross(sfT, sfB));
sfB = cross(sfN, sfT);
// the scales flare: each one tips up from its trailing edge and stands a little taller
float lift = clamp(fieldAt(sfG).g, -0.2, 1.4);
float ang = lift * 1.0;
float ca = cos(ang), sa = sin(ang);
mat3 tip = mat3(1.0, 0.0, 0.0, 0.0, ca, sa, 0.0, -sa, ca);
float sz = uStud * (0.92 + 0.16 * aSeed);
mat3 sfM = mat3(sfT, sfN, -sfB); // right-handed: T x N = -B, so faces keep their winding
vec3 lp = position * vec3(1.0, 1.0 + 0.6 * max(lift, 0.0), 1.0);
lp.z += 0.55;
lp = tip * lp;
lp.z -= 0.55;
vec3 objectNormal = sfM * (tip * normal);
vAO = smoothstep(0.0, 0.62, position.y);`,
)
.replace("#include <begin_vertex>", "vec3 transformed = sfS + sfM * (lp * sz);");
sh.fragmentShader = sh.fragmentShader
.replace("#include <common>", "#include <common>\nvarying float vAO;")
.replace("#include <opaque_fragment>", "outgoingLight *= mix(0.12, 1.0, vAO);\n#include <opaque_fragment>");
};
const stud = studGeometry();
const geo = new THREE.InstancedBufferGeometry();
geo.index = stud.index;
geo.setAttribute("position", stud.getAttribute("position"));
geo.setAttribute("normal", stud.getAttribute("normal"));
const mesh = new THREE.Mesh(geo, mat);
mesh.frustumCulled = false;
sheet.add(mesh);
let w = 1, h = 1;
let sheetW = 10, sheetH = 10;
// lay the scales out on a hex grid covering everything the camera can see
const layout = () => {
const p = props.current;
const visH = 2 * Math.tan((camera.fov * Math.PI) / 360) * 8;
const visW = visH * camera.aspect;
sheetW = visW * 1.7 + 3;
sheetH = visH * 2.2 + 3;
const sp = 0.21 * Math.max(0.5, Math.min(2.5, p.scale));
const rowH = sp * 0.866;
const cols = Math.ceil(sheetW / sp), rows = Math.ceil(sheetH / rowH);
const n = cols * rows;
const grid = new Float32Array(n * 2);
const seed = new Float32Array(n);
let k = 0;
for (let j = 0; j < rows; j++)
for (let i = 0; i < cols; i++) {
grid[k * 2] = -sheetW / 2 + (i + (j % 2) * 0.5) * sp;
grid[k * 2 + 1] = -sheetH / 2 + j * rowH;
const x = Math.sin((i * 12.9898 + j * 78.233) * 1.0) * 43758.5453;
seed[k] = x - Math.floor(x);
k++;
}
geo.setAttribute("aGrid", new THREE.InstancedBufferAttribute(grid, 2));
geo.setAttribute("aSeed", new THREE.InstancedBufferAttribute(seed, 1));
geo.instanceCount = n;
uni.uStud.value = sp * 0.6;
uni.uRect.value.set(-sheetW / 2, -sheetH / 2, sheetW, sheetH);
// the membrane grid follows the sheet's aspect
const fy = Math.max(32, Math.min(160, Math.round((FX * sheetH) / sheetW)));
if (fy !== FY) {
FY = fy;
field = new Uint16Array(FX * FY * 2);
hNow = new Float32Array(FX * FY);
hVel = new Float32Array(FX * FY);
fl = new Float32Array(FX * FY);
flVel = new Float32Array(FX * FY);
fieldTex.dispose();
fieldTex.image = { data: field, width: FX, height: FY };
fieldTex.needsUpdate = true;
}
};
// ---- render: supersampled, multisampled HDR, soft bloom, ACES ----
const rt = new THREE.WebGLRenderTarget(1, 1, { type: THREE.HalfFloatType, samples: 4 });
const composer = new EffectComposer(renderer, rt);
composer.addPass(new RenderPass(scene, camera));
const bloom = new UnrealBloomPass(new THREE.Vector2(1, 1), 0.3, 0.4, 0.9);
composer.addPass(bloom);
composer.addPass(new OutputPass());
const resize = () => {
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
let pr = Math.min(2, (window.devicePixelRatio || 1) * 1.5);
pr = Math.min(pr, Math.sqrt(5e6 / (w * h)));
renderer.setPixelRatio(pr);
renderer.setSize(w, h, false);
composer.setPixelRatio(pr);
composer.setSize(w, h);
camera.aspect = w / h;
camera.fov = camera.aspect < 0.8 ? 46 : 35;
camera.updateProjectionMatrix();
layout();
};
resize();
rebuild.current = () => {
layout();
buildEnv();
};
// ---- motion ----
const s = { amp: still ? 1 : 0, light: still ? 1 : 0, cx: 0, cy: 0 };
let time = still ? 6 : 0, flowV = 0;
let lastST = 0;
const cruise = () => 1 * Math.max(0, props.current.speed);
const ptr = { x: 0, y: 0, in: false, u: 0, v: 0, hit: false, pu: 0, pv: 0 };
const camTo = { x: gsap.quickTo(s, "cx", { duration: 0.9, ease: "power3.out" }), y: gsap.quickTo(s, "cy", { duration: 0.9, ease: "power3.out" }) };
const ray = new THREE.Raycaster();
const ndc = new THREE.Vector2();
const plane = new THREE.Plane();
const tmp = new THREE.Vector3();
const inv = new THREE.Matrix4();
// cursor -> sheet coordinates (the base plane of the sheet)
const toSheet = (x: number, y: number) => {
ndc.set((x / w) * 2 - 1, 1 - (y / h) * 2);
ray.setFromCamera(ndc, camera);
sheet.updateMatrixWorld(true);
plane.setFromNormalAndCoplanarPoint(tmp.set(0, 0, 1).transformDirection(sheet.matrixWorld), sheet.position);
if (!ray.ray.intersectPlane(plane, tmp)) return null;
inv.copy(sheet.matrixWorld).invert();
tmp.applyMatrix4(inv);
return { u: tmp.x, v: tmp.y };
};
const cellOf = (u: number, v: number) => ({ ci: ((u + sheetW / 2) / sheetW) * FX - 0.5, cj: ((v + sheetH / 2) / sheetH) * FY - 0.5 });
const splat = (arr: Float32Array, u: number, v: number, amt: number, radius: number) => {
const { ci, cj } = cellOf(u, v);
const rc = (radius / sheetW) * FX;
const rr = Math.ceil(rc * 2.5);
for (let j = Math.max(1, Math.floor(cj - rr)); j <= Math.min(FY - 2, Math.ceil(cj + rr)); j++)
for (let i = Math.max(1, Math.floor(ci - rr)); i <= Math.min(FX - 2, Math.ceil(ci + rr)); i++) {
const d2 = (i - ci) ** 2 + (j - cj) ** 2;
arr[j * FX + i] += amt * Math.exp(-d2 / (rc * rc));
}
fieldLive = true;
};
const stepField = (dt: number, press: number) => {
// a springy membrane: tension carries ripples, a spring pulls it home, damping settles it
const dx = sheetW / FX;
const c2 = (2.6 / dx) ** 2, k = 7, damp = 2.4;
let live = false;
for (let j = 1; j < FY - 1; j++)
for (let i = 1; i < FX - 1; i++) {
const q = j * FX + i;
const lap = hNow[q - 1] + hNow[q + 1] + hNow[q - FX] + hNow[q + FX] - 4 * hNow[q];
hVel[q] += (c2 * lap - k * hNow[q] - damp * hVel[q]) * dt;
}
// the flare: each scale on its own spring (underdamped, so it settles with a small bounce)
const fk = 55, fc = 6.5;
for (let q = 0; q < FX * FY; q++) {
hNow[q] += hVel[q] * dt;
flVel[q] += (-fk * fl[q] - fc * flVel[q]) * dt;
fl[q] += flVel[q] * dt;
if (Math.abs(hNow[q]) > 1e-4 || Math.abs(hVel[q]) > 1e-4 || Math.abs(fl[q]) > 1e-4 || Math.abs(flVel[q]) > 1e-4) live = true;
}
// the cursor holds a gentle dent and keeps the scales around it lifted
if (press > 0.001 && ptr.hit) {
const { ci, cj } = cellOf(ptr.u, ptr.v);
const rc = (0.75 / sheetW) * FX, rf = (1.05 / sheetW) * FX;
const rr = Math.ceil(rf * 2.5);
for (let j = Math.max(1, Math.floor(cj - rr)); j <= Math.min(FY - 2, Math.ceil(cj + rr)); j++)
for (let i = Math.max(1, Math.floor(ci - rr)); i <= Math.min(FX - 2, Math.ceil(ci + rr)); i++) {
const q = j * FX + i;
const d2 = (i - ci) ** 2 + (j - cj) ** 2;
hVel[q] += -9 * press * Math.exp(-d2 / (rc * rc)) * dt;
flVel[q] += fk * 0.9 * press * Math.exp(-d2 / (rf * rf)) * dt;
}
live = true;
}
return live;
};
const bgCol = new THREE.Color();
const white = new THREE.Color(0xdde6ee);
const draw = () => {
const p = props.current;
bgCol.set(p.background);
(scene.background as THREE.Color).copy(bgCol);
(scene.fog as THREE.Fog).color.copy(bgCol);
mat.color.set(p.body);
// the raking light is mostly white, cooled by the colour; the back light and studio carry the colour
rake.color.set(p.color).lerp(white, 0.6);
back.color.set(p.color);
rake.intensity = 3.4 * s.light;
back.intensity = 1.0 * s.light;
fill.intensity = 0.15 * s.light;
scene.environmentIntensity = 0.9 * s.light;
bloom.strength = Math.max(0, p.glow);
uni.uTime.value = time;
uni.uAmp.value = Math.max(0, p.folds) * s.amp;
camera.position.set(s.cx, s.cy, 8);
camera.lookAt(0, 0, 0);
composer.render();
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
// ---- pointer ----
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
let press = 0;
const move = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const l = local(e);
ptr.x = l.x;
ptr.y = l.y;
ptr.in = true;
camTo.x(((l.x / w) * 2 - 1) * 0.35);
camTo.y((1 - (l.y / h) * 2) * 0.25);
};
const leave = () => {
ptr.in = false;
camTo.x(0);
camTo.y(0);
};
const down = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const tg = e.target as HTMLElement | null;
if (e.pointerType === "mouse" && tg && (tg === host || tg === canvas || tg.dataset.scaleLayer !== undefined)) e.preventDefault();
const l = local(e);
const at = toSheet(l.x, l.y);
if (!at) return;
// a click: a sharp tap that rings out across the sheet, and a burst of flared scales
splat(hVel, at.u, at.v, -7, 0.55);
splat(flVel, at.u, at.v, 70, 0.9);
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll drives the folds, with momentum ----
let lastScroll = 0;
const st = still
? null
: ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
const y = self.scroll();
const dy = y - lastScroll;
lastScroll = y;
lastST = performance.now();
if (!props.current.interactive || Math.abs(dy) > 2000) return;
flowV = Math.max(-6, Math.min(8, flowV + dy * 0.012));
},
});
if (st) lastScroll = st.scroll();
const wheel = (e: WheelEvent) => {
if (still || !props.current.interactive) return;
if (performance.now() - lastST < 80) return;
const dy = e.deltaMode === 1 ? e.deltaY * 16 : e.deltaY;
flowV = Math.max(-6, Math.min(8, flowV + Math.max(-200, Math.min(200, dy)) * 0.012));
};
host.addEventListener("wheel", wheel, { passive: true });
// ---- loop ----
let visible = true;
let prev = performance.now();
let acc = 0;
let intro: gsap.core.Timeline | null = null;
const tick = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
const p = props.current;
// scroll momentum eases back to the idle flow
flowV *= Math.exp(-dt * 1.3);
time += dt * (cruise() + flowV);
const on = ptr.in && p.interactive;
press += ((on ? 1 : 0) - press) * (1 - Math.exp(-dt * 6));
if (on) {
const at = toSheet(ptr.x, ptr.y);
ptr.hit = !!at;
if (at) {
ptr.u = at.u;
ptr.v = at.v;
}
}
// fixed 60 Hz physics steps (stable for these springs and this tension)
acc += dt;
let live = false, n = 0;
while (acc >= 1 / 60 && n < 4) {
acc -= 1 / 60;
n++;
if (fieldLive || press > 0.001) live = stepField(1 / 60, press) || live;
}
if (n === 4) acc = 0;
if (live || fieldLive) {
for (let q = 0; q < FX * FY; q++) {
field[q * 2] = THREE.DataUtils.toHalfFloat(live ? hNow[q] : 0);
field[q * 2 + 1] = THREE.DataUtils.toHalfFloat(live ? fl[q] : 0);
}
fieldTex.needsUpdate = true;
}
fieldLive = live;
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
if (still) {
draw();
redraw.current = draw;
} else {
flowV = 2.5; // the folds roll in and settle
intro = gsap
.timeline({ delay: 0.05 })
.to(s, { amp: 1, duration: 2.4, ease: "power3.out" }, 0)
.to(s, { light: 1, duration: 1.8, ease: "power2.out" }, 0);
io.observe(host);
gsap.ticker.add(tick);
}
return () => {
redraw.current = null;
rebuild.current = null;
gsap.ticker.remove(tick);
intro?.kill();
st?.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
host.removeEventListener("wheel", wheel);
gsap.killTweensOf(s);
stud.dispose();
geo.dispose();
mat.dispose();
fieldTex.dispose();
envTex?.dispose();
pmrem.dispose();
composer.dispose();
rt.dispose();
renderer.dispose();
renderer.forceContextLoss();
canvas.remove();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{children && (
<div data-scale-layer="" className="relative z-10 h-full">
{children}
</div>
)}
</div>
);
}
export default ScaleFold;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
11 propscolorstringColour of the raking light.default "#4f9fd6"default "#4f9fd6"bodystringColour of the scales themselves.default "#262c34"default "#262c34"backgroundstringBackground colour.default "#000000"default "#000000"scalenumberSize of the scales.default 1default 1foldsnumberDepth of the folds.default 1default 1speednumberSpeed of the flowing folds.default 1default 1glownumberStrength of the bloom on glints.default 0.3default 0.3interactivebooleanCursor press and flare, click ripple, scroll flow.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the scales.classNamestringSize it, e.g. h-screen w-full.