Prompt specification
Build or customize the Three.js 3D scene "Fabric structure comparison exhibit" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Fabric structure comparison exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fabric-structure-comparison-exhibit-x0600
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Create woven, knitted, and felt-like material models at matched scale; users stretch each through labeled qualitative animations and inspect how their underlying connections differ.
Working Three.js Starter (fabric-structure-comparison-exhibit-x0600):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Material Atlas — Woven, Knitted & Felt</title>
<style>
:root {
--ink: #182422;
--muted: #69716c;
--panel: #f5f3ec;
--paper: #fbfaf6;
--line: #d8d8ce;
--accent: #dfff72;
--woven: #247b79;
--knit: #e86e51;
--felt: #a27a31;
--shadow: 0 18px 50px rgba(28, 40, 36, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(36, 123, 121, 0.32);
outline-offset: 3px;
}
.app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 72px minmax(0, 1fr);
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(251, 250, 246, 0.96);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
width: 36px;
height: 36px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid var(--ink);
border-radius: 50%;
font-size: 11px;
font-weight: 800;
letter-spacing: -0.04em;
}
.brand-title {
min-width: 0;
}
.brand-title strong {
display: block;
font-size: 14px;
line-height: 1.1;
letter-spacing: 0.02em;
}
.brand-title span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.17em;
text-transform: uppercase;
white-space: nowrap;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
}
.top-button,
.tool-button {
appearance: none;
border: 1px solid var(--line);
background: #fff;
border-radius: 999px;
min-height: 36px;
padding: 0 15px;
cursor: pointer;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.top-button:hover,
.tool-button:hover {
transform: translateY(-1px);
border-color: #9da49d;
}
.top-button.primary {
background: var(--ink);
color: white;
border-color: var(--ink);
}
.layout {
min-height: 0;
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
}
.sidebar {
min-height: 0;
overflow-y: auto;
padding: 27px 24px 24px;
border-right: 1px solid var(--line);
background: var(--panel);
scrollbar-width: thin;
}
.eyebrow {
margin: 0 0 10px;
color: var(--woven);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 285px;
font-size: clamp(27px, 2.5vw, 38px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.intro {
margin: 14px 0 22px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 22px 0 10px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.sample-list {
display: grid;
gap: 8px;
}
.sample-card {
position: relative;
display: grid;
grid-template-columns: minmax(0, 1fr) 37px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.7);
transition:
border-color 160ms ease,
box-shadow 160ms ease,
transform 160ms ease;
}
.sample-card:hover {
transform: translateY(-1px);
border-color: #a9afa9;
}
.sample-card.active {
border-color: var(--ink);
background: #fff;
box-shadow: 0 8px 22px rgba(27, 39, 35, 0.09);
}
.sample-card.active::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--sample-color);
}
.sample-select {
min-width: 0;
display: grid;
grid-template-columns: 28px minmax(0, 1fr);
gap: 10px;
align-items: start;
padding: 13px 8px 13px 14px;
border: 0;
background: transparent;
text-align: left;
cursor: pointer;
}
.sample-number {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border-radius: 50%;
background: color-mix(in srgb, var(--sample-color) 17%, white);
color: var(--sample-color);
font-size: 9px;
font-weight: 850;
}
.sample-copy {
min-width: 0;
}
.sample-copy strong {
display: block;
margin: 1px 0 3px;
font-size: 13px;
letter-spacing: -0.01em;
}
.sample-copy span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.sample-status {
display: inline-block;
margin-top: 8px;
padding: 3px 7px;
border-radius: 999px;
background: #eceee8;
color: #68706c;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.sample-play {
align-self: center;
width: 29px;
height: 29px;
margin-right: 7px;
border: 1px solid var(--line);
border-radius: 50%;
background: #fff;
cursor: pointer;
font-size: 10px;
transition:
background 160ms ease,
color 160ms ease;
}
.sample-play:hover {
background: var(--sample-color);
color: white;
border-color: var(--sample-color);
}
.detail-card {
margin-top: 14px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.62);
}
.detail-card h2 {
margin: 0 0 7px;
font-size: 16px;
letter-spacing: -0.025em;
}
.detail-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.connection-chip {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 6px 9px;
border: 1px solid #d7d8cf;
border-radius: 999px;
background: #f5f5ef;
color: #4e5954;
font-size: 9px;
font-weight: 750;
}
.connection-chip::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--selected-color, var(--woven));
box-shadow: 0 0 0 3px color-mix(in srgb, var(--selected-color, var(--woven)) 17%, transparent);
}
.stretch-control {
margin-top: 18px;
padding: 17px;
border-radius: 13px;
background: var(--ink);
color: white;
}
.stretch-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.stretch-heading strong {
font-size: 12px;
}
.stretch-value {
color: var(--accent);
font-size: 11px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0 14px;
appearance: none;
border-radius: 99px;
background:
linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--value, 0%),
#53605c var(--value, 0%),
#53605c 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid var(--ink);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--ink);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
.play-button {
width: 100%;
min-height: 40px;
border: 0;
border-radius: 9px;
background: var(--accent);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.03em;
}
.play-button:hover {
filter: brightness(1.05);
}
.phase-note {
min-height: 48px;
margin: 13px 1px 0;
color: #d5dcd8;
font-size: 10px;
line-height: 1.5;
}
.options {
display: grid;
gap: 8px;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 39px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.58);
cursor: pointer;
font-size: 10px;
font-weight: 700;
}
.toggle-row input {
appearance: none;
position: relative;
width: 31px;
height: 17px;
flex: 0 0 auto;
border-radius: 99px;
background: #c9cdc6;
cursor: pointer;
transition: background 160ms ease;
}
.toggle-row input::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 11px;
height: 11px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
transition: transform 160ms ease;
}
.toggle-row input:checked {
background: var(--ink);
}
.toggle-row input:checked::after {
transform: translateX(14px);
}
.shortcut-note {
margin: 15px 0 0;
color: #848b87;
font-size: 9px;
line-height: 1.55;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #ebe8df;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.stage-top-left,
.stage-top-right {
position: absolute;
top: 20px;
z-index: 3;
display: flex;
align-items: center;
gap: 8px;
}
.stage-top-left {
left: 20px;
flex-direction: column;
align-items: flex-start;
pointer-events: none;
}
.stage-top-right {
right: 20px;
}
.scale-badge {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
border: 1px solid rgba(67, 77, 72, 0.18);
border-radius: 8px;
background: rgba(251, 250, 246, 0.82);
backdrop-filter: blur(8px);
color: #52605b;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.scale-badge i {
display: block;
width: 30px;
height: 7px;
border: 1px solid #596660;
border-top: 0;
}
.selection-badge {
color: #6f7874;
font-size: 10px;
font-weight: 650;
}
.tool-button {
min-height: 34px;
padding: 0 12px;
background: rgba(251, 250, 246, 0.84);
backdrop-filter: blur(8px);
}
.tool-button.icon {
width: 34px;
padding: 0;
font-size: 16px;
}
.stage-help {
position: absolute;
left: 20px;
bottom: 103px;
z-index: 3;
color: #68726e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
.timeline-panel {
position: absolute;
left: 50%;
bottom: 20px;
z-index: 4;
width: min(570px, calc(100% - 40px));
padding: 13px 16px 12px;
transform: translateX(-50%);
border: 1px solid rgba(74, 83, 78, 0.17);
border-radius: 13px;
background: rgba(251, 250, 246, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.timeline-head strong {
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-head span {
color: var(--muted);
font-size: 9px;
}
.timeline-track {
position: relative;
height: 4px;
margin: 0 4px 8px;
border-radius: 99px;
background: #d8dbd3;
}
.timeline-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: var(--selected-color, var(--woven));
}
.timeline-labels {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.timeline-labels span {
color: #8b918e;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-align: center;
text-transform: uppercase;
}
.timeline-labels span.active {
color: var(--selected-color, var(--woven));
}
@media (max-width: 920px) {
.layout {
grid-template-columns: 315px minmax(0, 1fr);
}
.sidebar {
padding: 24px 18px;
}
.topbar {
padding: 0 18px;
}
}
@media (max-width: 700px) {
.app {
grid-template-rows: 60px minmax(0, 1fr);
}
.brand-title span,
.top-button.secondary,
.selection-badge {
display: none;
}
.topbar {
padding: 0 12px;
}
.top-actions {
gap: 6px;
}
.top-button {
min-height: 33px;
padding: 0 11px;
font-size: 10px;
}
.layout {
display: grid;
grid-template-rows: 43% 57%;
grid-template-columns: 1fr;
}
.sidebar {
padding: 18px 16px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
h1 {
font-size: 27px;
}
.intro {
margin: 9px 0 13px;
}
.sample-list {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.sample-card {
grid-template-columns: 1fr;
}
.sample-select {
grid-template-columns: 1fr;
padding: 11px;
}
.sample-number,
.sample-copy span,
.sample-status,
.sample-play {
display: none;
}
.sample-copy strong {
font-size: 11px;
}
.detail-card,
.stretch-control {
display: none;
}
.stage-top-left,
.stage-top-right {
top: 12px;
}
.stage-top-left {
left: 12px;
}
.stage-top-right {
right: 12px;
}
.scale-badge {
padding: 6px 8px;
font-size: 8px;
}
.stage-help {
left: 12px;
bottom: 85px;
font-size: 8px;
}
.timeline-panel {
bottom: 10px;
width: calc(100% - 24px);
padding: 10px 12px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark">M/A</div>
<div class="brand-title">
<strong>Material Atlas</strong>
<span>Interactive structure study · 03</span>
</div>
</div>
<div class="top-actions">
<button class="top-button secondary" id="resetButton">Reset all</button>
<button class="top-button primary" id="compareButton">Compare stretch</button>
</div>
</header>
<div class="layout">
<aside class="sidebar">
<p class="eyebrow">Same scale. Different logic.</p>
<h1>How materials hold together.</h1>
<p class="intro">
Stretch three matched swatches to reveal how their connections
carry load. The surface changes, but the underlying structure tells
a different story.
</p>
<div class="section-label">
<span>Material samples</span>
<span>03 studies</span>
</div>
<div class="sample-list" id="sampleList"></div>
<div class="detail-card">
<h2 id="detailTitle">Woven structure</h2>
<p id="detailDescription"></p>
<div class="connection-chip" id="connectionChip"></div>
</div>
<div class="stretch-control">
<div class="stretch-heading">
<strong>Qualitative stretch</strong>
<span class="stretch-value" id="stretchValue">0%</span>
</div>
<input
id="stretchSlider"
type="range"
min="0"
max="100"
value="0"
aria-label="Stretch selected material"
/>
<button class="play-button" id="playButton">▶ Play stretch cycle</button>
<p class="phase-note" id="phaseNote" aria-live="polite"></p>
</div>
<div class="section-label">
<span>Inspect</span>
<span>View options</span>
</div>
<div class="options">
<label class="toggle-row">
<span>Highlight connections</span>
<input id="connectionsToggle" type="checkbox" checked />
</label>
<label class="toggle-row">
<span>Show sample labels</span>
<input id="labelsToggle" type="checkbox" checked />
</label>
</div>
<p class="shortcut-note">
Drag the scene to orbit · Scroll to zoom · Click a swatch to select<br />
Keyboard: Space plays the selected sample · R resets all samples
</p>
</aside>
<main class="stage" id="stage">
<div id="viewport"></div>
<div class="stage-top-left">
<div class="scale-badge">
<i></i>
Matched scale · 3.6 × 2.2 units
</div>
<div class="selection-badge" id="selectionBadge">Inspecting: Woven</div>
</div>
<div class="stage-top-right">
<button class="tool-button icon" id="zoomOutButton" title="Zoom out">−</button>
<button class="tool-button icon" id="zoomInButton" title="Zoom in">+</button>
<button class="tool-button" id="homeButton">Reset view</button>
</div>
<div class="stage-help">DRAG TO ORBIT · SCROLL TO ZOOM · CLICK TO SELECT</div>
<div class="timeline-panel" id="timelinePanel">
<div class="timeline-head">
<strong id="timelineTitle">Woven · stretch path</strong>
<span id="timelinePhase">Relaxed</span>
</div>
<div class="timeline-track">
<div class="timeline-fill" id="timelineFill"></div>
</div>
<div class="timeline-labels" id="timelineLabels">
<span class="active">Rest</span>
<span>Load</span>
<span>Open</span>
<span>Peak</span>
</div>
</div>
</main>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const stage = document.getElementById("stage");
const sampleList = document.getElementById("sampleList");
const slider = document.getElementById("stretchSlider");
const stretchValue = document.getElementById("stretchValue");
const playButton = document.getElementById("playButton");
const phaseNote = document.getElementById("phaseNote");
const detailTitle = document.getElementById("detailTitle");
const detailDescription = document.getElementById("detailDescription");
const connectionChip = document.getElementById("connectionChip");
const selectionBadge = document.getElementById("selectionBadge");
const timelinePanel = document.getElementById("timelinePanel");
const timelineTitle = document.getElementById("timelineTitle");
const timelinePhase = document.getElementById("timelinePhase");
const timelineFill = document.getElementById("timelineFill");
const timelineLabels = [...document.querySelectorAll("#timelineLabels span")];
const samples = [
{
id: "woven",
number: "01",
title: "Woven",
subtitle: "Orthogonal yarns",
accent: "#247b79",
description:
"Two yarn systems cross at right angles. Every crossing is a discrete over–under contact.",
connection: "Connections: alternating over–under crossings",
behavior:
"Extension opens the ordered lattice while straight yarns remain comparatively stable.",
phaseNotes: [
"At rest, warp and weft alternate clearly above and below one another.",
"Load transfers through the crossing points as the lattice begins to separate.",
"Openings grow, but the orthogonal grid and its repeating contacts remain ordered.",
"At peak, the woven network is stretched without changing its basic crossing logic."
]
},
{
id: "knitted",
number: "02",
title: "Knitted",
subtitle: "Intermeshed loops",
accent: "#e86e51",
description:
"A yarn forms loops that pass through neighboring loops, creating a linked, curved network.",
connection: "Connections: loop-through-loop interlocks",
behavior:
"Extension comes from loops rotating and opening rather than straight yarn paths.",
phaseNotes: [
"At rest, each rounded loop visibly passes through its neighbors.",
"The loops begin to rotate and their lower interlock points separate.",
"Loop arcs elongate while the row spacing expands across the swatch.",
"At peak, knitted loops carry much more extension than the straight yarns of the weave."
]
},
{
id: "felt",
number: "03",
title: "Felt-like",
subtitle: "Random fiber network",
accent: "#a27a31",
description:
"Loose fibers tangle and form irregular bonds with no dominant warp, weft, or loop direction.",
connection: "Connections: irregular fiber junctions and sliding bonds",
behavior:
"Fibers slip, unbond locally, and re-form contacts, so strain becomes uneven.",
phaseNotes: [
"At rest, fibers overlap in a dense but non-directional tangle.",
"Local contacts begin to slip and isolated regions carry the extension.",
"The random network separates unevenly while short fibers change orientation.",
"At peak, deformation is distributed irregularly rather than following a repeatable path."
]
}
];
let selectedIndex = 0;
let randomSeed = 73129;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function randomBetween(min, max) {
return min + (max - min) * random();
}
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xebe8df);
scene.fog = new THREE.Fog(0xebe8df, 18, 34);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 80);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional comparison of woven, knitted, and felt-like materials"
);
const hemi = new THREE.HemisphereLight(0xfffcf1, 0x7e8c86, 2.25);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff6df, 4.2);
key.position.set(4.5, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -10;
key.shadow.camera.right = 10;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.normalBias = 0.025;
scene.add(key);
const rim = new THREE.DirectionalLight(0xa8d9dc, 1.6);
rim.position.set(-7, 4, -5);
scene.add(rim);
const fill = new THREE.DirectionalLight(0xffd6b5, 1.1);
fill.position.set(2, 3, 8);
scene.add(fill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
new THREE.MeshStandardMaterial({
color: 0xe4e1d8,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.005;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0xaeb5ae, 0xc9cbc3);
grid.position.y = 0.003;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
const cameraState = {
target: new THREE.Vector3(0, 1.55, 0),
theta: 0,
phi: 1.43,
radius: 13.8
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function homeCamera() {
const requiredRadius =
13.6 /
(2 *
Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)) *
camera.aspect);
cameraState.target.set(0, 1.55, 0);
cameraState.theta = 0;
cameraState.phi = 1.43;
cameraState.radius = Math.max(12.8, requiredRadius);
updateCamera();
}
function makeTube(points, radius, material, radialSegments = 5, segments = null) {
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal");
const tubularSegments = segments ?? Math.max(10, points.length * 3);
const geometry = new THREE.TubeGeometry(
curve,
tubularSegments,
radius,
radialSegments,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeYarnMaterial(color, roughness = 0.9) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 1
});
}
function makeLabelSprite(title, subtitle, accent) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 170;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(251,250,246,0.94)";
context.strokeStyle = "rgba(40,50,46,0.18)";
context.lineWidth = 3;
const x = 8;
const y = 8;
const width = 624;
const height = 150;
const radius = 24;
context.beginPath();
context.moveTo(x + radius, y);
context.arcTo(x + width, y, x + width, y + height, radius);
context.arcTo(x + width, y + height, x, y + height, radius);
context.arcTo(x, y + height, x, y, radius);
context.arcTo(x, y, x + width, y, radius);
context.closePath();
context.fill();
context.stroke();
context.fillStyle = accent;
context.beginPath();
context.arc(51, 49, 10, 0, Math.PI * 2);
context.fill();
context.fillStyle = "#17221f";
context.font = "800 39px system-ui, sans-serif";
context.fillText(title.toUpperCase(), 77, 62);
context.fillStyle = "#68726e";
context.font = "600 23px system-ui, sans-serif";
context.fillText(subtitle, 30, 112);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(2.05, 0.54, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeMarkerMesh(count, color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.96,
depthTest: false,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.043, 6, 4),
material,
count
);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
mesh.renderOrder = 15;
return mesh;
}
function buildFrame(sample) {
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0xb8b9b1,
roughness: 0.63,
metalness: 0.12,
emissive: 0x000000,
emissiveIntensity: 0
});
sample.frameMaterial = frameMaterial;
const frame = new THREE.Group();
const width = 3.65;
const height = 2.38;
const thickness = 0.065;
const z = -0.17;
const horizontalGeometry = new THREE.BoxGeometry(
width + thickness,
thickness,
0.075
);
const verticalGeometry = new THREE.BoxGeometry(
thickness,
height,
0.075
);
const top = new THREE.Mesh(horizontalGeometry, frameMaterial);
const bottom = new THREE.Mesh(horizontalGeometry, frameMaterial);
const left = new THREE.Mesh(verticalGeometry, frameMaterial);
const right = new THREE.Mesh(verticalGeometry, frameMaterial);
top.position.set(0, height / 2, z);
bottom.position.set(0, -height / 2, z);
left.position.set(-width / 2, 0, z);
right.position.set(width / 2, 0, z);
for (const bar of [top, bottom, left, right]) {
bar.castShadow = true;
bar.receiveShadow = true;
frame.add(bar);
}
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xd5d3ca,
roughness: 0.86,
metalness: 0.04
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(3.2, 0.12, 0.68),
baseMaterial
);
base.position.set(0, -1.66, -0.02);
base.castShadow = true;
base.receiveShadow = true;
frame.add(base);
const legGeometry = new THREE.BoxGeometry(0.075, 0.42, 0.075);
for (const x of [-1.35, 1.35]) {
const leg = new THREE.Mesh(legGeometry, frameMaterial);
leg.position.set(x, -1.4, -0.15);
leg.castShadow = true;
frame.add(leg);
}
sample.root.add(frame);
}
function buildWoven(sample) {
const content = new THREE.Group();
sample.content = content;
sample.root.add(content);
const width = 3.34;
const height = 2.1;
const columns = 11;
const rows = 7;
const spacingX = width / (columns - 1);
const spacingY = height / (rows - 1);
const warpMaterial = makeYarnMaterial(0x247b79);
const weftMaterial = makeYarnMaterial(0xd89b51);
sample.surfaceMaterials.push(warpMaterial, weftMaterial);
const nodePositions = [];
for (let column = 0; column < columns; column++) {
const x = -width / 2 + column * spacingX;
const points = [];
for (let step = 0; step <= 36; step++) {
const y = -height / 2 + (step / 36) * height;
const phase = (y + height / 2) / spacingY;
const z = 0.076 * Math.cos(Math.PI * phase);
points.push(new THREE.Vector3(x, y, z));
}
const warp = makeTube(points, 0.052, warpMaterial, 5, 92);
content.add(warp);
}
for (let row = 0; row < rows; row++) {
const y = -height / 2 + row * spacingY;
const points = [];
for (let step = 0; step <= 44; step++) {
const x = -width / 2 + (step / 44) * width;
const phase = (x + width / 2) / spacingX;
const z = -0.076 * Math.cos(Math.PI * phase);
points.push(new THREE.Vector3(x, y, z));
}
const weft = makeTube(points, 0.052, weftMaterial, 5, 110);
content.add(weft);
}
for (let column = 0; column < columns; column++) {
for (let row = 0; row < rows; row++) {
const x = -width / 2 + column * spacingX;
const y = -height / 2 + row * spacingY;
const warpZ = 0.076 * Math.cos(Math.PI * row);
const weftZ = -0.076 * Math.cos(Math.PI * column);
nodePositions.push(
new THREE.Vector3(x, y, Math.max(warpZ, weftZ) + 0.064)
);
}
}
const markers = makeMarkerMesh(nodePositions.length, 0xfff4a7);
const matrix = new THREE.Matrix4();
nodePositions.forEach((position, index) => {
matrix.makeTranslation(position.x, position.y, position.z);
markers.setMatrixAt(index, matrix);
});
markers.instanceMatrix.needsUpdate = true;
sample.markers = markers;
content.add(markers);
}
function buildKnitted(sample) {
const content = new THREE.Group();
sample.content = content;
sample.root.add(content);
const columns = 9;
const rows = 6;
const spacingX = 0.39;
const spacingY = 0.36;
const materialA = makeYarnMaterial(0xe86e51, 0.88);
const materialB = makeYarnMaterial(0xf09169, 0.91);
sample.surfaceMaterials.push(materialA, materialB);
const loops = [];
const nodePositions = [];
const dummy = new THREE.Object3D();
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const baseX = (column - (columns - 1) / 2) * spacingX;
const baseY = (row - (rows - 1) / 2) * spacingY;
const baseZ = (column + row) % 2 === 0 ? 0.025 : -0.025;
const points = [
new THREE.Vector3(-0.24, -0.15, 0),
new THREE.Vector3(-0.235, 0.015, 0.012),
new THREE.Vector3(-0.155, 0.155, 0.02),
new THREE.Vector3(-0.045, 0.215, 0.025),
new THREE.Vector3(0.105, 0.165, 0.02),
new THREE.Vector3(0.225, 0.015, 0.012),
new THREE.Vector3(0.24, -0.15, 0)
];
const material = (column + row) % 3 === 0 ? materialB : materialA;
const loop = makeTube(points, 0.052, material, 5, 30);
loop.position.set(baseX, baseY, baseZ);
loop.userData.baseX = baseX;
loop.userData.baseY = baseY;
loop.userData.baseZ = baseZ;
content.add(loop);
loops.push(loop);
if (column < columns - 1) {
const nextX = baseX + spacingX;
nodePositions.push({
x: (baseX + nextX) / 2,
y: baseY - 0.085,
z: baseZ + 0.055
});
}
}
}
const markers = makeMarkerMesh(nodePositions.length, 0xfff4a7);
sample.markers = markers;
sample.knitLoops = loops;
sample.knitNodes = nodePositions;
content.add(markers);
sample.knitDummy = dummy;
}
function buildFelt(sample) {
const content = new THREE.Group();
sample.content = content;
sample.root.add(content);
const width = 3.26;
const height = 2.04;
const bodyGeometry = new THREE.PlaneGeometry(width, height, 4, 4);
const positions = bodyGeometry.attributes.position;
for (let index = 0; index < positions.count; index++) {
positions.setZ(
index,
randomBetween(-0.055, 0.055) +
Math.sin(positions.getX(index) * 2.7) * 0.025
);
}
bodyGeometry.computeVertexNormals();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xb58b40,
roughness: 1,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.33,
depthWrite: false,
side: THREE.DoubleSide
});
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.receiveShadow = true;
content.add(body);
sample.bodyMaterial = bodyMaterial;
sample.body = body;
const networkMaterial = makeYarnMaterial(0x9c7129, 0.98);
const fiberMaterial = makeYarnMaterial(0xd0aa5d, 0.96);
sample.surfaceMaterials.push(networkMaterial, fiberMaterial);
const nodes = [];
for (let index = 0; index < 24; index++) {
nodes.push(
new THREE.Vector3(
randomBetween(-width * 0.47, width * 0.47),
randomBetween(-height * 0.47, height * 0.47),
randomBetween(-0.075, 0.075)
)
);
}
const edgeKeys = new Set();
function addEdge(aIndex, bIndex) {
const key =
aIndex < bIndex
? `${aIndex}-${bIndex}`
: `${bIndex}-${aIndex}`;
if (aIndex === bIndex || edgeKeys.has(key)) return;
edgeKeys.add(key);
const a = nodes[aIndex];
const b = nodes[bIndex];
const middle = a.clone().add(b).multiplyScalar(0.5);
const direction = b.clone().sub(a);
const perpendicular = new THREE.Vector3(
-direction.y,
direction.x,
0
).normalize();
const bend = randomBetween(-0.09, 0.09);
const control = middle
.clone()
.add(perpendicular.multiplyScalar(bend))
.add(new THREE.Vector3(0, 0, randomBetween(-0.05, 0.05)));
const localPoints = [
a.clone().sub(middle),
control.clone().sub(middle),
b.clone().sub(middle)
];
const mesh = makeTube(
localPoints,
randomBetween(0.019, 0.026),
networkMaterial,
4,
10
);
mesh.position.copy(middle);
mesh.userData.basePosition = middle.clone();
mesh.userData.phase = randomBetween(0, Math.PI * 2);
mesh.userData.baseRotation = 0;
content.add(mesh);
sample.feltItems.push(mesh);
}
for (let index = 0; index < nodes.length; index++) {
const first = Math.floor(random() * nodes.length);
const second = Math.floor(random() * nodes.length);
addEdge(index, first);
if (random() > 0.4) addEdge(index, second);
}
for (let index = 0; index < 46; index++) {
const center = new THREE.Vector3(
randomBetween(-width * 0.5, width * 0.5),
randomBetween(-height * 0.5, height * 0.5),
randomBetween(-0.12, 0.12)
);
const angle = randomBetween(0, Math.PI * 2);
const length = randomBetween(0.12, 0.4);
const direction = new THREE.Vector3(
Math.cos(angle),
Math.sin(angle),
randomBetween(-0.22, 0.22)
).normalize();
const start = center
.clone()
.add(direction.clone().multiplyScalar(-length * 0.5));
const end = center
.clone()
.add(direction.clone().multiplyScalar(length * 0.5));
const bend = new THREE.Vector3(
randomBetween(-0.045, 0.045),
randomBetween(-0.045, 0.045),
randomBetween(-0.04, 0.04)
);
const localPoints = [
start.clone().sub(center),
bend,
end.clone().sub(center)
];
const fiber = makeTube(
localPoints,
randomBetween(0.013, 0.019),
fiberMaterial,
3,
8
);
fiber.position.copy(center);
fiber.userData.basePosition = center.clone();
fiber.userData.phase = randomBetween(0, Math.PI * 2);
fiber.userData.baseRotation = randomBetween(-0.2, 0.2);
content.add(fiber);
sample.feltItems.push(fiber);
}
const markers = makeMarkerMesh(nodes.length, 0xfff4a7);
sample.markers = markers;
sample.feltNodes = nodes;
content.add(markers);
}
function createSample(data, index) {
const sample = {
...data,
root: new THREE.Group(),
content: null,
frameMaterial: null,
surfaceMaterials: [],
bodyMaterial: null,
body: null,
markers: null,
knitLoops: [],
knitNodes: [],
feltItems: [],
feltNodes: [],
progress: 0,
playing: false,
startTime: 0,
startProgress: 0,
phase: 0,
lastStage: -1
};
sample.root.position.set((index - 1) * 4.15, 1.72, 0);
sample.root.userData.sampleIndex = index;
scene.add(sample.root);
buildFrame(sample);
if (index === 0) buildWoven(sample);
if (index === 1) buildKnitted(sample);
if (index === 2) buildFelt(sample);
const label = makeLabelSprite(
sample.title,
sample.subtitle,
sample.accent
);
label.position.set(0, 1.48, 0.15);
sample.root.add(label);
sample.label = label;
sample.root.traverse((object) => {
object.userData.sampleIndex = index;
});
return sample;
}
samples.forEach((data, index) => {
data.root = null;
data.content = null;
data.frameMaterial = null;
data.surfaceMaterials = [];
data.bodyMaterial = null;
data.body = null;
data.markers = null;
data.knitLoops = [];
data.knitNodes = [];
data.feltItems = [];
data.feltNodes = [];
data.progress = 0;
data.playing = false;
data.startTime = 0;
data.startProgress = 0;
data.phase = 0;
data.lastStage = -1;
});
samples.forEach((data, index) => {
const created = createSample(data, index);
samples[index] = created;
});
function updateWoven(sample, progress) {
sample.content.scale.set(
1 + 0.13 * progress,
1 - 0.035 * progress,
1 - 0.14 * progress
);
}
function updateKnitted(sample, progress) {
const columnSpread = 1 + 0.18 * progress;
const rowSpread = 1 + 0.07 * progress;
for (const loop of sample.knitLoops) {
loop.position.x = loop.userData.baseX * columnSpread;
loop.position.y = loop.userData.baseY * rowSpread;
loop.scale.set(
1 - 0.12 * progress,
1 + 0.17 * progress,
1
);
}
const matrix = new THREE.Matrix4();
sample.knitNodes.forEach((node, index) => {
const x = node.x * columnSpread;
const y = node.y * rowSpread;
const z = node.z * (1 - 0.1 * progress);
matrix.makeTranslation(x, y, z);
sample.markers.setMatrixAt(index, matrix);
});
sample.markers.instanceMatrix.needsUpdate = true;
}
function updateFelt(sample, progress) {
sample.body.scale.set(
1 + 0.085 * progress,
1 + 0.035 * progress,
1
);
for (const item of sample.feltItems) {
const base = item.userData.basePosition;
const phase = item.userData.phase;
item.position.x =
base.x * (1 + 0.08 * progress) +
Math.sin(phase + progress * 5.2) * 0.032 * progress;
item.position.y =
base.y * (1 + 0.035 * progress) +
Math.cos(phase * 1.3 + progress * 4.4) * 0.025 * progress;
item.rotation.z =
item.userData.baseRotation +
Math.sin(phase) * 0.16 * progress;
}
const matrix = new THREE.Matrix4();
sample.feltNodes.forEach((node, index) => {
const x =
node.x * (1 + 0.08 * progress) +
Math.sin(index * 2.17 + progress * 5.2) * 0.036 * progress;
const y =
node.y * (1 + 0.035 * progress) +
Math.cos(index * 1.71 + progress * 4.1) * 0.026 * progress;
const z = node.z * (1 - 0.18 * progress);
matrix.makeTranslation(x, y, z);
sample.markers.setMatrixAt(index, matrix);
});
sample.markers.instanceMatrix.needsUpdate = true;
}
function applySample(sample, progress) {
sample.progress = progress;
if (sample.id === "woven") updateWoven(sample, progress);
if (sample.id === "knitted") updateKnitted(sample, progress);
if (sample.id === "felt") updateFelt(sample, progress);
}
function stageForProgress(progress) {
if (progress < 0.08) return 0;
if (progress < 0.42) return 1;
if (progress < 0.88) return 2;
return 3;
}
const phaseNames = ["Relaxed", "Loading", "Opening", "Peak extension"];
function easeInOutCubic(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function startAnimation(index) {
const sample = samples[index];
if (sample.playing) {
sample.playing = false;
return;
}
sample.playing = true;
sample.startTime = performance.now();
sample.startProgress = sample.progress;
}
function startAllAnimations() {
samples.forEach((sample) => {
sample.playing = true;
sample.startTime = performance.now();
sample.startProgress = sample.progress;
});
}
function resetAll() {
samples.forEach((sample) => {
sample.playing = false;
applySample(sample, 0);
});
}
function setSelected(index) {
selectedIndex = index;
const sample = samples[index];
document.querySelectorAll(".sample-card").forEach((card, cardIndex) => {
card.classList.toggle("active", cardIndex === index);
});
samples.forEach((item, itemIndex) => {
const selected = itemIndex === index;
item.frameMaterial.color.set(
selected ? item.accent : 0xb8b9b1
);
item.frameMaterial.emissive.set(item.accent);
item.frameMaterial.emissiveIntensity = selected ? 0.055 : 0;
for (const material of item.surfaceMaterials) {
material.emissive.set(item.accent);
material.emissiveIntensity = selected ? 0.035 : 0;
}
});
detailTitle.textContent = `${sample.title} structure`;
detailDescription.textContent = sample.description;
connectionChip.textContent = sample.connection;
selectionBadge.textContent = `Inspecting: ${sample.title}`;
timelineTitle.textContent = `${sample.title} · stretch path`;
document.documentElement.style.setProperty(
"--selected-color",
sample.accent
);
updateSelectedUI();
}
function applyInspectionMode() {
const highlight = document.getElementById("connectionsToggle").checked;
for (const sample of samples) {
sample.markers.visible = highlight;
for (const material of sample.surfaceMaterials) {
material.opacity = highlight ? 0.58 : 1;
material.depthWrite = !highlight;
material.needsUpdate = true;
}
if (sample.bodyMaterial) {
sample.bodyMaterial.opacity = highlight ? 0.065 : 0.33;
}
}
}
function updateSelectedUI() {
const sample = samples[selectedIndex];
const progress = sample.progress;
const stage = sample.phase;
slider.value = Math.round(progress * 100);
slider.style.setProperty("--value", `${progress * 100}%`);
stretchValue.textContent = `${Math.round(progress * 100)}%`;
timelineFill.style.width = `${progress * 100}%`;
timelinePhase.textContent = phaseNames[stage];
timelineLabels.forEach((label, index) => {
label.classList.toggle("active", index === stage);
});
if (sample.lastStage !== stage) {
phaseNote.textContent = sample.phaseNotes[stage];
sample.lastStage = stage;
}
playButton.textContent = sample.playing
? "❚❚ Pause stretch cycle"
: "▶ Play stretch cycle";
}
samples.forEach((sample, index) => {
const card = document.createElement("article");
card.className = "sample-card";
card.style.setProperty("--sample-color", sample.accent);
card.innerHTML = `
<button class="sample-select" type="button">
<span class="sample-number">${sample.number}</span>
<span class="sample-copy">
<strong>${sample.title}</strong>
<span>${sample.subtitle}</span>
<span class="sample-status">Relaxed · 0%</span>
</span>
</button>
<button class="sample-play" type="button" title="Play ${sample.title} stretch cycle" aria-label="Play ${sample.title} stretch cycle">▶</button>
`;
card.querySelector(".sample-select").addEventListener("click", () => {
setSelected(index);
});
card.querySelector(".sample-play").addEventListener("click", () => {
setSelected(index);
startAnimation(index);
});
sampleList.appendChild(card);
sample.card = card;
sample.cardStatus = card.querySelector(".sample-status");
});
slider.addEventListener("input", () => {
const sample = samples[selectedIndex];
sample.playing = false;
applySample(sample, Number(slider.value) / 100);
updateSelectedUI();
});
playButton.addEventListener("click", () => {
startAnimation(selectedIndex);
});
document.getElementById("compareButton").addEventListener("click", () => {
startAllAnimations();
});
document.getElementById("resetButton").addEventListener("click", () => {
resetAll();
});
document.getElementById("connectionsToggle").addEventListener(
"change",
applyInspectionMode
);
document.getElementById("labelsToggle").addEventListener("change", (event) => {
samples.forEach((sample) => {
sample.label.visible = event.target.checked;
});
});
document.getElementById("homeButton").addEventListener("click", homeCamera);
document.getElementById("zoomInButton").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius - 1.2,
8.2,
25
);
updateCamera();
});
document.getElementById("zoomOutButton").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + 1.2,
8.2,
25
);
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
startAnimation(selectedIndex);
}
if (event.key.toLowerCase() === "r") {
resetAll();
}
});
// Custom camera controls — no examples/addons are used.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
let dragDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
dragDistance += Math.abs(deltaX) + Math.abs(deltaY);
cameraState.theta -= deltaX * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.0045,
0.64,
1.52
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
const moved =
Math.abs(event.clientX - pointerStartX) +
Math.abs(event.clientY - pointerStartY);
if (moved < 6 && dragDistance < 8) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
samples.map((sample) => sample.root),
true
);
if (hits.length > 0) {
const index = hits[0].object.userData.sampleIndex;
if (Number.isInteger(index)) setSelected(index);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
8.2,
25
);
updateCamera();
},
{ passive: false }
);
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
homeCamera();
setSelected(0);
applyInspectionMode();
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
for (const sample of samples) {
if (sample.playing) {
const elapsed = (now - sample.startTime) / 1000;
let progress;
if (elapsed < 1.65) {
progress = THREE.MathUtils.lerp(
sample.startProgress,
1,
easeInOutCubic(elapsed / 1.65)
);
sample.phase = progress < 0.08 ? 0 : 1;
} else if (elapsed < 2.45) {
progress = 1;
sample.phase = 3;
} else if (elapsed < 4.25) {
progress =
1 - easeInOutCubic((elapsed - 2.45) / 1.8);
sample.phase = progress < 0.08 ? 0 : 2;
} else {
progress = 0;
sample.phase = 0;
}
applySample(sample, progress);
if (elapsed >= 4.65) {
sample.playing = false;
sample.progress = 0;
sample.phase = 0;
applySample(sample, 0);
}
} else if (sample.phase === 3 && sample.progress < 0.88) {
sample.phase = stageForProgress(sample.progress);
}
}
samples.forEach((sample) => {
const percent = Math.round(sample.progress * 100);
const state =
percent < 2
? "Relaxed"
: percent > 96
? "Peak"
: "Extended";
sample.cardStatus.textContent = `${state} · ${percent}%`;
});
updateSelectedUI();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```