3D engine that AI agents drive
Add three home-hero prototypes: object, world and type-led (design exploration, no site files touched)
Nguyen Xuan Anb202681fd8b8
diff --git a/hero-a.html b/hero-a.htmlnew file mode 100644index 00000000..e047bd88--- /dev/null+++ b/hero-a.html@@ -0,0 +1,37 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <meta name="theme-color" content="#09070f" />+ <meta name="robots" content="noindex" />+ <title>Hero A · Object · 67js</title>+ <link rel="icon" href="/favicon.svg" />+ <link rel="preload" as="image" href="/hero-lab/poster-a.webp" media="(min-width: 701px)" fetchpriority="high" />+ </head>+ <body>+ <a class="skip-link" href="#content">Skip to content</a>+ <header class="lab-nav">+ <a class="lab-brand" href="/hero-lab.html" aria-label="67js home"><img src="/logo.svg" alt="" width="30" height="30" />67js</a>+ <a href="/docs.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h6a3 3 0 0 1 3 3v14a4 4 0 0 0-4-2H4V4Zm9 3a3 3 0 0 1 3-3h5v15h-4a4 4 0 0 0-4 2"/></svg>Docs</a>+ <a href="/showcase.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 3 8v9l9 5 9-5V8l-9-5ZM3 8l9 5 9-5M12 13v9"/></svg>Showcase</a>+ <a href="/changelog.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 2.6-6.4L3 8M3 3v5h5M12 7v5l3.5 2"/></svg>Changelog</a>+ <a href="https://github.com/codepawl/67.js" aria-label="GitHub"><span class="logo-mask logo-github" aria-hidden="true"></span>GitHub</a>+ </header>+ <main id="content" class="hero-a">+ <div class="stage" id="stage">+ <picture><source media="(max-width: 700px)" srcset="/hero-lab/poster-a-mobile.webp" /><img class="poster" src="/hero-lab/poster-a.webp" alt="" width="1440" height="900" fetchpriority="high" /></picture>+ <canvas id="viewport" aria-label="A live 3D robot. Move the pointer to turn it."></canvas>+ </div>+ <div class="copy">+ <h1 class="rise" style="--i:0">A 3D engine<br />agents can drive</h1>+ <p class="lede rise" style="--i:1">WebGL2 rendering, deterministic animation and an MCP server in one package.</p>+ <div class="lab-actions rise" style="--i:2">+ <a class="lab-button is-primary" href="/docs.html#getting-started"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h6a3 3 0 0 1 3 3v14a4 4 0 0 0-4-2H4V4Zm9 3a3 3 0 0 1 3-3h5v15h-4a4 4 0 0 0-4 2"/></svg>Get started<svg class="arrow" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg></a>+ <a class="lab-button" href="https://www.npmjs.com/package/@codepawlhq/67js"><span class="logo-mask logo-npm" aria-hidden="true"></span>npm</a>+ </div>+ </div>+ </main>+ <script type="module" src="/src/hero-lab/hero-a.js"></script>+ </body>+</html>diff --git a/hero-b.html b/hero-b.htmlnew file mode 100644index 00000000..55408432--- /dev/null+++ b/hero-b.html@@ -0,0 +1,47 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <meta name="theme-color" content="#09070f" />+ <meta name="robots" content="noindex" />+ <title>Hero B · World · 67js</title>+ <link rel="icon" href="/favicon.svg" />+ <link rel="preload" as="image" href="/hero-lab/poster-b.webp" media="(min-width: 701px)" fetchpriority="high" />+ </head>+ <body>+ <a class="skip-link" href="#content">Skip to content</a>+ <header class="lab-nav">+ <a class="lab-brand" href="/hero-lab.html" aria-label="67js home"><img src="/logo.svg" alt="" width="30" height="30" />67js</a>+ <a href="/docs.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h6a3 3 0 0 1 3 3v14a4 4 0 0 0-4-2H4V4Zm9 3a3 3 0 0 1 3-3h5v15h-4a4 4 0 0 0-4 2"/></svg>Docs</a>+ <a href="/showcase.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 3 8v9l9 5 9-5V8l-9-5ZM3 8l9 5 9-5M12 13v9"/></svg>Showcase</a>+ <a href="/changelog.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 2.6-6.4L3 8M3 3v5h5M12 7v5l3.5 2"/></svg>Changelog</a>+ <a href="https://github.com/codepawl/67.js" aria-label="GitHub"><span class="logo-mask logo-github" aria-hidden="true"></span>GitHub</a>+ </header>+ <main id="content" class="hero-b">+ <div class="pin" id="pin">+ <div class="stage" id="stage">+ <picture><source media="(max-width: 700px)" srcset="/hero-lab/poster-b-mobile.webp" /><img class="poster" src="/hero-lab/poster-b.webp" alt="" width="1440" height="900" fetchpriority="high" /></picture>+ <canvas id="viewport" aria-label="A live 3D airport ramp. Scroll to move the camera."></canvas>+ </div>+ <div class="progress" aria-hidden="true"><i id="progress-fill"></i></div>+ <div class="chapter chapter-one" id="chapter-one">+ <h1 class="rise" style="--i:0">A 3D engine<br />agents can drive</h1>+ <p class="lede rise" style="--i:1">WebGL2 rendering, deterministic animation and an MCP server in one package.</p>+ <div class="lab-actions rise" style="--i:2">+ <a class="lab-button is-primary" href="/docs.html#getting-started"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h6a3 3 0 0 1 3 3v14a4 4 0 0 0-4-2H4V4Zm9 3a3 3 0 0 1 3-3h5v15h-4a4 4 0 0 0-4 2"/></svg>Get started<svg class="arrow" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg></a>+ <a class="lab-button" href="https://www.npmjs.com/package/@codepawlhq/67js"><span class="logo-mask logo-npm" aria-hidden="true"></span>npm</a>+ </div>+ </div>+ <div class="chapter chapter-two" id="chapter-two">+ <h2>Every frame is real geometry,<br />lit and shadowed in your browser.</h2>+ <div class="lab-actions">+ <a class="lab-button is-primary" href="/showcase.html?scene=airport"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 3 8v9l9 5 9-5V8l-9-5ZM3 8l9 5 9-5M12 13v9"/></svg>Open this scene live<svg class="arrow" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg></a>+ </div>+ </div>+ <p class="cue rise" style="--i:4" id="cue"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>Scroll</p>+ </div>+ </main>+ <script type="module" src="/src/hero-lab/hero-b.js"></script>+ </body>+</html>diff --git a/hero-c.html b/hero-c.htmlnew file mode 100644index 00000000..8df228bb--- /dev/null+++ b/hero-c.html@@ -0,0 +1,45 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <meta name="theme-color" content="#09070f" />+ <meta name="robots" content="noindex" />+ <title>Hero C · Type · 67js</title>+ <link rel="icon" href="/favicon.svg" />+ <link rel="preload" as="image" href="/hero-lab/poster-c.webp" fetchpriority="high" />+ </head>+ <body>+ <a class="skip-link" href="#content">Skip to content</a>+ <header class="lab-nav">+ <a class="lab-brand" href="/hero-lab.html" aria-label="67js home"><img src="/logo.svg" alt="" width="30" height="30" />67js</a>+ <a href="/docs.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h6a3 3 0 0 1 3 3v14a4 4 0 0 0-4-2H4V4Zm9 3a3 3 0 0 1 3-3h5v15h-4a4 4 0 0 0-4 2"/></svg>Docs</a>+ <a href="/showcase.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 3 8v9l9 5 9-5V8l-9-5ZM3 8l9 5 9-5M12 13v9"/></svg>Showcase</a>+ <a href="/changelog.html"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 2.6-6.4L3 8M3 3v5h5M12 7v5l3.5 2"/></svg>Changelog</a>+ <a href="https://github.com/codepawl/67.js" aria-label="GitHub"><span class="logo-mask logo-github" aria-hidden="true"></span>GitHub</a>+ </header>+ <main id="content" class="hero-c">+ <div class="words">+ <h1 aria-label="A 3D engine agents can drive">+ <span class="line" aria-hidden="true"><span style="--i:0">A 3D engine</span></span>+ <span class="line" aria-hidden="true"><span style="--i:1">agents can</span></span>+ <span class="line" aria-hidden="true"><span style="--i:2">drive.</span></span>+ </h1>+ <ul class="chips rise" style="--i:4" aria-label="What agents get">+ <li><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 3 8v9l9 5 9-5V8l-9-5ZM3 8l9 5 9-5M12 13v9"/></svg>22 MCP tools</li>+ <li><svg viewBox="0 0 24 24" aria-hidden="true"><path d="m8 6-6 6 6 6m8-12 6 6-6 6m-3-15-2 18"/></svg>Scene recipes</li>+ <li><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 3h18v18H3V3Zm0 14 6-6 5 5 3-3 4 4M16 8h.01"/></svg>Visual review</li>+ </ul>+ <div class="lab-actions rise" style="--i:5">+ <a class="lab-button is-primary" id="cta" href="/docs.html#getting-started"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h6a3 3 0 0 1 3 3v14a4 4 0 0 0-4-2H4V4Zm9 3a3 3 0 0 1 3-3h5v15h-4a4 4 0 0 0-4 2"/></svg>Get started<svg class="arrow" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg></a>+ <a class="lab-button" href="https://www.npmjs.com/package/@codepawlhq/67js"><span class="logo-mask logo-npm" aria-hidden="true"></span>npm</a>+ </div>+ </div>+ <div class="stage rise" id="stage" style="--i:2">+ <img class="poster" src="/hero-lab/poster-c.webp" alt="" width="520" height="520" fetchpriority="high" />+ <canvas id="viewport" aria-label="A small live 3D scene. It brightens when you hover Get started."></canvas>+ </div>+ </main>+ <script type="module" src="/src/hero-lab/hero-c.js"></script>+ </body>+</html>diff --git a/hero-lab.html b/hero-lab.htmlnew file mode 100644index 00000000..8f7c628e--- /dev/null+++ b/hero-lab.html@@ -0,0 +1,19 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <meta name="robots" content="noindex" />+ <title>Home hero directions · 67js</title>+ <link rel="icon" href="/favicon.svg" />+ </head>+ <body>+ <main class="lab-index">+ <h1>Home hero directions</h1>+ <a href="/hero-a.html"><strong>A · Object</strong><span>One model that follows the pointer.</span></a>+ <a href="/hero-b.html"><strong>B · World</strong><span>An airport ramp where scroll moves the camera.</span></a>+ <a href="/hero-c.html"><strong>C · Type</strong><span>Big type, a small live scene that lights up with the call to action.</span></a>+ </main>+ <script type="module" src="/src/hero-lab/index.js"></script>+ </body>+</html>diff --git a/public/hero-lab/poster-a-mobile.webp b/public/hero-lab/poster-a-mobile.webpnew file mode 100644index 00000000..a8d96f98Binary files /dev/null and b/public/hero-lab/poster-a-mobile.webp differdiff --git a/public/hero-lab/poster-a.webp b/public/hero-lab/poster-a.webpnew file mode 100644index 00000000..a6787690Binary files /dev/null and b/public/hero-lab/poster-a.webp differdiff --git a/public/hero-lab/poster-b-mobile.webp b/public/hero-lab/poster-b-mobile.webpnew file mode 100644index 00000000..523050a8Binary files /dev/null and b/public/hero-lab/poster-b-mobile.webp differdiff --git a/public/hero-lab/poster-b.webp b/public/hero-lab/poster-b.webpnew file mode 100644index 00000000..2647ed35Binary files /dev/null and b/public/hero-lab/poster-b.webp differdiff --git a/public/hero-lab/poster-c.webp b/public/hero-lab/poster-c.webpnew file mode 100644index 00000000..1496740eBinary files /dev/null and b/public/hero-lab/poster-c.webp differdiff --git a/src/hero-lab/hero-a.js b/src/hero-lab/hero-a.jsnew file mode 100644index 00000000..aa60a01c--- /dev/null+++ b/src/hero-lab/hero-a.js@@ -0,0 +1,95 @@+// Direction A: one hero object. The camera follows the pointer with damping, so the robot seems to turn toward it.+import './lab.css';+import { vec3 } from 'gl-matrix';+import { Renderer67 } from '../renderer.js';+import { loadGltf } from '../gltf.js';+import { damp, prefersReducedMotion, showStageError, startLoop } from './stage.js';++const stage = document.querySelector('#stage');+const canvas = document.querySelector('#viewport');++const REST_YAW = 0.62;+const REST_PITCH = 0.2;+const YAW_RANGE = 0.55;+const PITCH_RANGE = 0.14;+const FOLLOW_RATE = prefersReducedMotion ? 14 : 5;+const SWAY_SPEED = 0.45;+const SWAY_AMOUNT = 0.07;++function measureBounds(parts) {+ const minimum = [Infinity, Infinity, Infinity];+ const maximum = [-Infinity, -Infinity, -Infinity];+ const corner = vec3.create();+ for (const part of parts) {+ const positions = part.geometry.positions;+ const stride = Math.max(3, Math.floor(positions.length / 3 / 2000) * 3);+ for (let index = 0; index < positions.length; index += stride) {+ vec3.transformMat4(corner, positions.subarray(index, index + 3), part.matrix);+ for (let axis = 0; axis < 3; axis++) {+ minimum[axis] = Math.min(minimum[axis], corner[axis]);+ maximum[axis] = Math.max(maximum[axis], corner[axis]);+ }+ }+ }+ return { minimum, maximum };+}++async function start() {+ const asset = await loadGltf('/wall-e.glb');+ const bounds = measureBounds(asset.parts);+ const center = bounds.minimum.map((value, axis) => (value + bounds.maximum[axis]) / 2);+ const extent = Math.max(...bounds.maximum.map((value, axis) => value - bounds.minimum[axis]));+ const target = [center[0], center[1] - extent * 0.02, center[2]];+ const distance = extent * 2.35;+ const renderer = new Renderer67(canvas, asset.parts, {+ hdr: true,+ transparent: true,+ ground: false,+ samples: 4,+ pixelRatio: Math.min(devicePixelRatio, 1.5),+ memoryBudgetMiB: 256,+ shadowBounds: { target: center, eye: [center[0] - extent, center[1] + extent * 2, center[2] + extent], extent: extent * 1.5, near: extent * 0.01, far: extent * 8 },+ });++ const view = { yaw: REST_YAW, pitch: REST_PITCH, aim: { yaw: REST_YAW, pitch: REST_PITCH } };+ let pointerActive = false;++ window.addEventListener('pointermove', event => {+ pointerActive = true;+ const horizontal = event.clientX / innerWidth * 2 - 1;+ const vertical = event.clientY / innerHeight * 2 - 1;+ view.aim.yaw = REST_YAW + horizontal * YAW_RANGE;+ view.aim.pitch = REST_PITCH - vertical * PITCH_RANGE;+ loop.wake();+ }, { passive: true });+ document.documentElement.addEventListener('pointerleave', () => {+ pointerActive = false;+ view.aim.yaw = REST_YAW;+ view.aim.pitch = REST_PITCH;+ loop.wake();+ });++ const loop = startLoop(stage, (seconds, timestamp) => {+ const sway = pointerActive || prefersReducedMotion ? 0 : Math.sin(timestamp / 1000 * SWAY_SPEED * Math.PI * 2) * SWAY_AMOUNT;+ view.yaw = damp(view.yaw, view.aim.yaw + sway, FOLLOW_RATE, seconds);+ view.pitch = damp(view.pitch, view.aim.pitch, FOLLOW_RATE, seconds);+ const mobile = canvas.clientWidth <= 700;+ renderer.projection[8] = mobile ? 0 : -0.24;+ const horizontalReach = Math.cos(view.pitch) * distance * (mobile ? 1.25 : 1);+ renderer.render({+ target,+ eye: [+ target[0] + Math.sin(view.yaw) * horizontalReach,+ target[1] + Math.sin(view.pitch) * distance,+ target[2] + Math.cos(view.yaw) * horizontalReach,+ ],+ exposure: 1,+ effects: { vignette: 0.08, bloom: { strength: 0.12, threshold: 1.15, radius: 1 } },+ });+ // The robot rests once the camera has settled and the page has no motion left to show.+ return !(prefersReducedMotion && Math.abs(view.yaw - view.aim.yaw) < 0.0005 && Math.abs(view.pitch - view.aim.pitch) < 0.0005);+ });+ window.__heroState = { view, renderer };+}++start().catch(error => showStageError(stage, `Live view unavailable: ${error.message}`));diff --git a/src/hero-lab/hero-b.js b/src/hero-lab/hero-b.jsnew file mode 100644index 00000000..3544861b--- /dev/null+++ b/src/hero-lab/hero-b.js@@ -0,0 +1,93 @@+// Direction B: a world. Scroll position scrubs a camera path around the airport ramp.+// Only the first part of the showcase world loads (ground and hero aircraft) with the small preview sky, about 2.2 MB.+import './lab.css';+import { Renderer67 } from '../renderer.js';+import { loadGltf } from '../gltf.js';+import { loadHdri } from '../hdri.js';+import { createCascadedShadows } from '../cascaded-shadows.js';+import { clamp, damp, prefersReducedMotion, showStageError, smoothstep, startLoop } from './stage.js';++const stage = document.querySelector('#stage');+const canvas = document.querySelector('#viewport');+const root = document.querySelector('.hero-b');+const chapterOne = document.querySelector('#chapter-one');+const chapterTwo = document.querySelector('#chapter-two');+const cue = document.querySelector('#cue');+const progressFill = document.querySelector('#progress-fill');++// Camera path: [eye, target, field of view]. Linear blend between keys, eased by the page's own scroll.+const KEYS = [+ { at: 0, eye: [138, 64, 36], target: [1, 3, -13], fov: 20 },+ { at: 0.55, eye: [74, 26, 62], target: [-4, 6, -14], fov: 26 },+ { at: 1, eye: [-30, 14, 70], target: [-12, 8, -14], fov: 34 },+];+const SCRUB_RATE = prefersReducedMotion ? 30 : 7;++function lerp(first, second, amount) {+ return first + (second - first) * amount;+}++function pathAt(progress) {+ let index = 0;+ while (index < KEYS.length - 2 && progress > KEYS[index + 1].at) index++;+ const from = KEYS[index];+ const to = KEYS[index + 1];+ const amount = smoothstep(0, 1, clamp((progress - from.at) / (to.at - from.at), 0, 1));+ return {+ eye: from.eye.map((value, axis) => lerp(value, to.eye[axis], amount)),+ target: from.target.map((value, axis) => lerp(value, to.target[axis], amount)),+ fov: lerp(from.fov, to.fov, amount),+ };+}++function scrollProgress() {+ const travel = root.offsetHeight - innerHeight;+ return clamp(-root.getBoundingClientRect().top / travel, 0, 1);+}++// Chapter copy is driven by the same progress value as the camera, using transform and opacity only.+function paintChapters(progress) {+ const leaving = smoothstep(0.12, 0.38, progress);+ chapterOne.style.opacity = String(1 - leaving);+ chapterOne.style.transform = `translateY(${-28 * leaving}px)`;+ chapterOne.style.pointerEvents = leaving > 0.5 ? 'none' : '';+ const arriving = smoothstep(0.62, 0.9, progress);+ chapterTwo.style.opacity = String(arriving);+ chapterTwo.style.transform = `translateY(${24 * (1 - arriving)}px)`;+ cue.style.opacity = String(1 - smoothstep(0.02, 0.12, progress));+ progressFill.style.transform = `scaleY(${progress})`;+}++async function start() {+ const description = await (await fetch('/showcase/airport/scene.json')).json();+ const [asset, sky] = await Promise.all([+ loadGltf(description.glb, description.gltfOptions),+ loadHdri(description.hdriPreview, description.hdriOptions),+ ]);+ const options = description.renderer;+ const renderer = new Renderer67(canvas, asset.parts, {+ ...options,+ pixelRatio: Math.min(devicePixelRatio, 1.25),+ memoryBudgetMiB: 384,+ shadowCascades: createCascadedShadows(options.shadowCascades),+ environment: { ...options.environment, map: sky },+ });++ const state = { progress: scrollProgress(), aim: scrollProgress() };+ const loop = startLoop(stage, seconds => {+ state.aim = scrollProgress();+ state.progress = damp(state.progress, state.aim, SCRUB_RATE, seconds);+ const settled = Math.abs(state.progress - state.aim) < 0.0004;+ if (settled) state.progress = state.aim;+ const camera = pathAt(state.progress);+ renderer.render({ ...description.frame, eye: camera.eye, target: camera.target, fov: camera.fov });+ paintChapters(state.progress);+ return !settled;+ });+ window.addEventListener('scroll', loop.wake, { passive: true });+ window.addEventListener('resize', loop.wake);+ window.__heroState = { state, renderer };+}++paintChapters(scrollProgress());+start().catch(error => showStageError(stage, `Live view unavailable: ${error.message}`));diff --git a/src/hero-lab/hero-c.js b/src/hero-lab/hero-c.jsnew file mode 100644index 00000000..4b011469--- /dev/null+++ b/src/hero-lab/hero-c.js@@ -0,0 +1,83 @@+// Direction C: type first. A small procedural scene (a ring of spheres around a torus, no downloads) that+// brightens and speeds up while the call to action is hovered or focused.+import './lab.css';+import { mat4, quat } from 'gl-matrix';+import { Renderer67 } from '../renderer.js';+import { sphere, torus } from '../geometry.js';+import { damp, prefersReducedMotion, showStageError, startLoop } from './stage.js';++const stage = document.querySelector('#stage');+const canvas = document.querySelector('#viewport');+const cta = document.querySelector('#cta');++const SPHERE_COUNT = 7;+const RING_RADIUS = 1.5;+const IDLE_SPEED = 0.28;+const EXCITED_SPEED = 1.1;+const LIGHT_RATE = 9;++function transform(position, scale, rotation = [0, 0, 0]) {+ const orientation = quat.fromEuler(quat.create(), ...rotation.map(angle => angle * 180 / Math.PI));+ return mat4.fromRotationTranslationScale(mat4.create(), orientation, position, scale);+}++function buildParts() {+ const ball = sphere(48, 32);+ const ring = torus(0.06, 96, 20);+ const parts = [+ { name: 'ring', geometry: ring, matrix: transform([0, 0, 0], [RING_RADIUS, RING_RADIUS, RING_RADIUS], [Math.PI / 2, 0, 0]), material: { tag: 'ring', color: [0.8, 0.8, 0.84], metallic: 1, roughness: 0.22, emission: 0 } },+ { name: 'core', geometry: ball, matrix: transform([0, 0, 0], [0.62, 0.62, 0.62]), material: { tag: 'core', color: [1, 0.26, 0.05], metallic: 0.1, roughness: 0.35, emission: 0.9 } },+ ];+ for (let index = 0; index < SPHERE_COUNT; index++) {+ parts.push({ name: `bead-${index}`, geometry: ball, matrix: transform([0, 0, 0], [0.2, 0.2, 0.2]), material: { tag: `bead-${index}`, color: [0.92, 0.9, 0.96], metallic: 0.9, roughness: 0.16, emission: 0 } });+ }+ return parts;+}++function placeBeads(parts, turn, lift) {+ for (let index = 0; index < SPHERE_COUNT; index++) {+ const angle = turn + index / SPHERE_COUNT * Math.PI * 2;+ const bob = Math.sin(angle * 2 + turn) * 0.16 * lift;+ parts[2 + index].matrix = transform([Math.cos(angle) * RING_RADIUS, bob, Math.sin(angle) * RING_RADIUS], [0.2, 0.2, 0.2]);+ }+}++function start() {+ const parts = buildParts();+ const renderer = new Renderer67(canvas, parts, { hdr: true, transparent: true, samples: 4, ground: false, pixelRatio: Math.min(devicePixelRatio, 2), memoryBudgetMiB: 128 });+ const state = { turn: 0.6, speed: IDLE_SPEED, light: 0, wanted: 0 };++ const setExcited = value => {+ state.wanted = value;+ loop.wake();+ };+ cta.addEventListener('pointerenter', () => setExcited(1));+ cta.addEventListener('pointerleave', () => setExcited(0));+ cta.addEventListener('focus', () => setExcited(1));+ cta.addEventListener('blur', () => setExcited(0));++ const loop = startLoop(stage, seconds => {+ state.light = damp(state.light, state.wanted, LIGHT_RATE, seconds);+ const idleSpeed = prefersReducedMotion ? 0 : IDLE_SPEED;+ const speed = idleSpeed + (EXCITED_SPEED - IDLE_SPEED) * state.light * (prefersReducedMotion ? 0.25 : 1);+ state.turn += speed * seconds;+ placeBeads(parts, state.turn, 1);+ renderer.updateParts(parts, { shadows: false });+ const aimed = [0.2, 1.3, 7.4];+ renderer.render({+ target: [0, 0, 0],+ eye: aimed,+ exposure: 1 + state.light * 0.55,+ effects: { vignette: 0.1, bloom: { strength: 0.18 + state.light * 0.55, threshold: 0.9, radius: 1.1 } },+ });+ const resting = prefersReducedMotion && state.light < 0.002 && state.wanted === 0;+ return !resting;+ });+ window.__heroState = { state, renderer };+}++try {+ start();+} catch (error) {+ showStageError(stage, `Live view unavailable: ${error.message}`);+}diff --git a/src/hero-lab/index.js b/src/hero-lab/index.jsnew file mode 100644index 00000000..57d6ea5e--- /dev/null+++ b/src/hero-lab/index.js@@ -0,0 +1 @@+import './lab.css';diff --git a/src/hero-lab/lab.css b/src/hero-lab/lab.cssnew file mode 100644index 00000000..0e3930f7--- /dev/null+++ b/src/hero-lab/lab.css@@ -0,0 +1,130 @@+/* Home-hero prototypes. One shared set of tokens and parts; each direction adds its own layout at the end.+ Motion follows the animate skill: transform and opacity only, strong ease-out for entrances, short eases for hover,+ hover effects gated to real pointers, everything softened under prefers-reduced-motion. */+:root {+ color-scheme: dark;+ --bg: #09070f;+ --surface: #17141f;+ --surface-hover: #221e2c;+ --text: #f1eff5;+ --muted: #a9a4b5;+ --accent: #ff6a2b;+ --focus: #a6c1ff;+ --ease-out: cubic-bezier(0.23, 1, 0.32, 1);+ --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);+ --press: 140ms;+ --hover: 160ms;+ --enter: 700ms;+ font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;+}++* { box-sizing: border-box; }+html, body { margin: 0; background: var(--bg); color: var(--text); }+body { min-height: 100svh; -webkit-font-smoothing: antialiased; }+a { color: inherit; text-decoration: none; }+a:focus-visible, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 10px; }++.skip-link { position: absolute; left: 12px; top: -48px; z-index: 20; padding: 8px 12px; border-radius: 10px; background: var(--text); color: var(--bg); transition: transform var(--hover) var(--ease-out); }+.skip-link:focus { transform: translateY(60px); }++/* Navigation: quiet text links, a soft fill on hover, no rules. */+.lab-nav { position: absolute; z-index: 10; inset: 0 0 auto 0; display: flex; align-items: center; gap: 4px; padding: 18px clamp(16px, 4vw, 48px); }+.lab-brand { display: inline-flex; align-items: center; gap: 10px; margin-right: auto; font-weight: 650; font-size: 18px; letter-spacing: -0.02em; }+.lab-brand img { width: 30px; height: 30px; }+.lab-nav a:not(.lab-brand) { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 12px; border-radius: 12px; color: var(--muted); font-size: 14px; font-weight: 500; transition: background-color var(--hover) ease, color var(--hover) ease, transform var(--press) var(--ease-out); }+.lab-nav a:not(.lab-brand):active { transform: scale(0.97); }+.lab-nav svg { flex: none; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }+@media (hover: hover) and (pointer: fine) {+ .lab-nav a:not(.lab-brand):hover { background: var(--surface); color: var(--text); }+}++.logo-mask { flex: none; display: inline-block; width: 17px; height: 17px; background: currentColor; mask: var(--logo) center / contain no-repeat; -webkit-mask: var(--logo) center / contain no-repeat; }+.logo-github { --logo: url('/logos/github.svg'); }+.logo-npm { --logo: url('/logos/npm.svg'); }++/* Buttons: press feedback 140 ms, hover only on pointers that hover, the arrow nudges 3 px. */+.lab-actions { display: flex; flex-wrap: wrap; gap: 10px; }+.lab-button { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 46px; padding: 0 20px; border: 0; border-radius: 14px; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; background: var(--surface); color: var(--text); transition: transform var(--press) var(--ease-out), background-color var(--hover) ease, box-shadow var(--hover) ease; }+.lab-button svg { flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--hover) var(--ease-out); }+.lab-button.is-primary { background: var(--text); color: var(--bg); }+.lab-button:active { transform: scale(0.97); }+@media (hover: hover) and (pointer: fine) {+ .lab-button:hover { background: var(--surface-hover); }+ .lab-button.is-primary:hover { background: #ffffff; box-shadow: 0 0 0 6px rgb(255 106 43 / 0.18); }+ .lab-button:hover .arrow { transform: translateX(3px); }+}++/* Entrance: opacity and a short rise, staggered by --i. Under reduced motion only the fade remains. */+@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }+@keyframes fade { from { opacity: 0; } to { opacity: 1; } }+.rise { animation: rise var(--enter) var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 70ms + 120ms); }+@media (prefers-reduced-motion: reduce) {+ .rise { animation-name: fade; animation-duration: 300ms; animation-delay: 0ms; }+}++/* The stage: poster first, the live canvas fades in over it, then the poster leaves. */+.stage { position: absolute; inset: 0; overflow: hidden; background: var(--bg); }+.stage canvas, .stage .poster { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }+.stage .poster { object-fit: cover; z-index: 1; transition: opacity 520ms ease 80ms; }+.stage canvas { z-index: 0; touch-action: pan-y; }+.stage[data-live='true'] .poster { opacity: 0; pointer-events: none; }+.stage-status { position: absolute; z-index: 2; right: 16px; bottom: 16px; display: flex; align-items: center; gap: 8px; margin: 0; padding: 8px 12px; border-radius: 12px; background: var(--surface); color: var(--text); font-size: 13px; }++h1 { margin: 0; font-weight: 640; letter-spacing: -0.04em; line-height: 0.98; text-wrap: balance; }+.lede { margin: 0; color: var(--muted); font-size: clamp(16px, 1.5vw, 19px); line-height: 1.5; max-width: 34ch; }++/* ---------- Direction A: one object that follows the pointer ---------- */+.hero-a { position: relative; min-height: max(100svh, 720px); overflow: hidden; }+.hero-a .copy { position: relative; z-index: 3; display: flex; flex-direction: column; gap: 24px; justify-content: center; min-height: max(100svh, 720px); padding: 96px clamp(16px, 6vw, 96px) 64px; max-width: 760px; pointer-events: none; }+.hero-a .copy > * { pointer-events: auto; }+.hero-a h1 { font-size: clamp(44px, 6.4vw, 92px); }+.hero-a .stage::after { content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: radial-gradient(120% 90% at 78% 52%, transparent 38%, rgb(9 7 15 / 0.55) 100%); }+@media (max-width: 700px) {+ .hero-a .copy { justify-content: flex-end; padding-bottom: 36px; background: linear-gradient(to top, rgb(9 7 15 / 0.92) 0%, rgb(9 7 15 / 0.7) 45%, transparent 100%); }+ .hero-a h1 { font-size: 40px; }+}++/* ---------- Direction B: a world, the scroll moves the camera ---------- */+.hero-b { position: relative; height: 260svh; }+.hero-b .pin { position: sticky; top: 0; height: 100svh; overflow: hidden; }+.hero-b .stage::after { content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: linear-gradient(to top, rgb(9 7 15 / 0.82) 0%, transparent 52%); }+.hero-b .chapter { position: absolute; z-index: 3; left: clamp(16px, 6vw, 96px); bottom: clamp(32px, 9svh, 96px); max-width: 640px; display: flex; flex-direction: column; gap: 22px; will-change: transform, opacity; }+.hero-b h1 { font-size: clamp(42px, 6vw, 88px); }+.hero-b .chapter-two { pointer-events: none; opacity: 0; }+.hero-b .chapter-two h2 { margin: 0; font-size: clamp(28px, 3.6vw, 52px); font-weight: 620; letter-spacing: -0.03em; line-height: 1.04; }+.hero-b .chapter-two .lab-actions { pointer-events: auto; }+.hero-b .cue { position: absolute; z-index: 3; right: clamp(16px, 4vw, 48px); bottom: clamp(32px, 9svh, 96px); display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }+.hero-b .cue svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; animation: nudge 1.8s var(--ease-in-out) infinite; }+@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }+@media (prefers-reduced-motion: reduce) { .hero-b .cue svg { animation: none; } }+.hero-b .progress { position: absolute; z-index: 3; left: clamp(16px, 4vw, 48px); top: 50%; width: 6px; height: 96px; margin-top: -48px; border-radius: 6px; background: rgb(255 255 255 / 0.14); overflow: hidden; }+.hero-b .progress i { position: absolute; inset: 0; background: var(--text); border-radius: 6px; transform-origin: top; transform: scaleY(0); }+@media (max-width: 700px) { .hero-b .progress { display: none; } .hero-b .cue { display: none; } }++/* ---------- Direction C: type-led, a small live scene, loud UI ---------- */+.hero-c { position: relative; min-height: max(100svh, 760px); display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: center; gap: clamp(16px, 4vw, 64px); padding: 110px clamp(16px, 6vw, 96px) 64px; overflow: hidden; }+.hero-c .words { display: flex; flex-direction: column; gap: 32px; }+.hero-c h1 { font-size: clamp(54px, 9.4vw, 148px); line-height: 0.92; letter-spacing: -0.055em; }+.hero-c h1 .line { display: block; overflow: hidden; padding-bottom: 0.08em; margin-bottom: -0.08em; }+.hero-c h1 .line > span { display: block; animation: line-up 900ms var(--ease-out) both; animation-delay: calc(var(--i) * 90ms + 100ms); }+@keyframes line-up { from { transform: translateY(105%); } to { transform: none; } }+@media (prefers-reduced-motion: reduce) { .hero-c h1 .line > span { animation-name: fade; animation-duration: 300ms; animation-delay: 0ms; } }+.hero-c .chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }+.hero-c .chips li { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 12px; border-radius: 12px; background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 500; }+.hero-c .chips svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }+.hero-c .stage { position: relative; inset: auto; aspect-ratio: 1; width: 100%; max-width: 520px; justify-self: end; border-radius: 32px; background: radial-gradient(circle at 50% 40%, #1d1829 0%, #100d18 70%); }+.hero-c .stage canvas, .hero-c .stage .poster { border-radius: 32px; }+@media (max-width: 800px) {+ .hero-c { grid-template-columns: 1fr; padding-top: 96px; }+ .hero-c .stage { justify-self: center; max-width: 340px; order: -1; }+ .hero-c h1 { font-size: clamp(46px, 14vw, 72px); }+}++/* ---------- Index of the three directions ---------- */+.lab-index { display: grid; gap: 12px; max-width: 760px; margin: 0 auto; padding: 120px 24px; }+.lab-index h1 { font-size: 40px; margin-bottom: 16px; }+.lab-index a { display: flex; flex-direction: column; gap: 6px; padding: 20px 22px; border-radius: 18px; background: var(--surface); transition: background-color var(--hover) ease, transform var(--press) var(--ease-out); }+.lab-index a:active { transform: scale(0.99); }+@media (hover: hover) and (pointer: fine) { .lab-index a:hover { background: var(--surface-hover); } }+.lab-index strong { font-size: 18px; }+.lab-index span { color: var(--muted); font-size: 14px; }diff --git a/src/hero-lab/stage.js b/src/hero-lab/stage.jsnew file mode 100644index 00000000..819c6db3--- /dev/null+++ b/src/hero-lab/stage.js@@ -0,0 +1,93 @@+// Shared helpers for the home-hero prototypes: the poster-to-canvas load path, a render loop that+// pauses when the page is hidden or the hero is off screen, damping, and the numbers the measurement script reads.++export const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;++// Frame-rate independent smoothing. A new target at any time only changes where the value is heading, so it stays interruptible.+export function damp(current, target, rate, seconds) {+ return target + (current - target) * Math.exp(-rate * seconds);+}++export function clamp(value, minimum, maximum) {+ return Math.max(minimum, Math.min(maximum, value));+}++export function smoothstep(edgeStart, edgeEnd, value) {+ const amount = clamp((value - edgeStart) / (edgeEnd - edgeStart), 0, 1);+ return amount * amount * (3 - 2 * amount);+}++export function median(values) {+ if (!values.length) return 0;+ const sorted = [...values].sort((first, second) => first - second);+ return sorted[Math.floor(sorted.length / 2)];+}++// window.__hero is read by the measurement script: when the first live frame was submitted and how long frames took after that.+export const metrics = window.__hero = {+ firstLiveFrameMs: null,+ frameIntervals: [],+ renderMilliseconds: [],+ bytesNote: 'transfer size comes from the network log, not from the page',+ error: null,+};++const WARNING_ICON = '<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"><path d="M12 3 2.5 20h19L12 3Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M12 10v4.5M12 17.2v.1" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';++// The poster is a still of the opening frame. The live canvas sits under it, draws once, then the poster fades out.+export function revealLiveCanvas(stage) {+ if (stage.dataset.live === 'true') return;+ metrics.firstLiveFrameMs = Math.round(performance.now());+ requestAnimationFrame(() => { stage.dataset.live = 'true'; });+}++export function showStageError(stage, message) {+ metrics.error = message;+ const notice = document.createElement('p');+ notice.className = 'stage-status';+ notice.setAttribute('role', 'status');+ notice.innerHTML = `${WARNING_ICON}<span></span>`;+ notice.querySelector('span').textContent = message;+ stage.append(notice);+}++// Calls draw(seconds, now) on every animation frame while the stage is visible and the tab is shown.+// draw returns false when nothing moved and the loop may rest until wake() is called.+export function startLoop(stage, draw) {+ let frameRequest = 0;+ let lastTimestamp = 0;+ let visible = true;+ let firstDrawn = false;++ const step = timestamp => {+ frameRequest = 0;+ if (document.hidden || !visible) {+ lastTimestamp = 0;+ return;+ }+ const seconds = lastTimestamp ? Math.min((timestamp - lastTimestamp) / 1000, 0.05) : 0.016;+ if (lastTimestamp && firstDrawn) metrics.frameIntervals.push(timestamp - lastTimestamp);+ lastTimestamp = timestamp;+ const started = performance.now();+ const keepGoing = draw(seconds, timestamp) !== false;+ if (firstDrawn) metrics.renderMilliseconds.push(performance.now() - started);+ if (!firstDrawn) {+ firstDrawn = true;+ revealLiveCanvas(stage);+ }+ if (keepGoing) wake();+ else lastTimestamp = 0;+ };++ function wake() {+ if (!frameRequest && visible && !document.hidden) frameRequest = requestAnimationFrame(step);+ }++ new IntersectionObserver(entries => {+ visible = entries[0].isIntersecting;+ wake();+ }).observe(stage);+ document.addEventListener('visibilitychange', wake);+ wake();+ return { wake };+}