Prompt specification
Build or customize the Three.js 3D scene "Elastic band fiber diagram" 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: Elastic band fiber diagram
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/elastic-band-fiber-diagram-x0581
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: elastic band fiber diagram. Display a fabric-covered waistband with one exposed section of symbolic elastic strands; compare relaxed and stretched forms without disconnecting the strand endpoints from their attachments. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (elastic-band-fiber-diagram-x0581):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Elastic Band — Fiber Response Diagram</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf4f7;
--muted: #91a6ae;
--cyan: #67e8f9;
--amber: #f4b76a;
--panel: rgba(8, 19, 27, 0.82);
--line: rgba(151, 213, 226, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071018;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.header {
position: absolute;
top: 24px;
left: 28px;
max-width: min(560px, calc(100vw - 56px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 14px rgba(103, 232, 249, 0.65);
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 46px);
font-weight: 620;
line-height: 1.02;
letter-spacing: -0.045em;
}
.subtitle {
margin-top: 10px;
max-width: 540px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.view-tools {
position: absolute;
top: 24px;
right: 26px;
display: flex;
gap: 8px;
align-items: center;
}
.chip,
.icon-button {
border: 1px solid var(--line);
background: rgba(8, 19, 27, 0.72);
backdrop-filter: blur(12px);
color: #bfd0d5;
border-radius: 999px;
font: inherit;
}
.chip {
padding: 9px 13px;
font-size: 11px;
letter-spacing: 0.04em;
}
.icon-button {
width: 36px;
height: 36px;
display: grid;
place-items: center;
cursor: pointer;
pointer-events: auto;
font-size: 18px;
}
.icon-button:hover,
.chip:hover {
border-color: rgba(103, 232, 249, 0.55);
color: white;
}
.legend {
position: absolute;
right: 26px;
bottom: 116px;
width: 228px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(8, 19, 27, 0.68);
backdrop-filter: blur(12px);
}
.legend-title {
margin-bottom: 10px;
color: #d9e9ed;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
color: #9eb2b9;
font-size: 11px;
}
.swatch {
width: 22px;
height: 5px;
flex: 0 0 auto;
border-radius: 99px;
}
.swatch.fabric { background: #c9b89b; }
.swatch.fiber { background: #f1d7b5; }
.swatch.anchor { background: #f4b76a; }
.legend-note {
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #829aa3;
font-size: 10px;
line-height: 1.5;
}
.controls {
position: absolute;
left: 50%;
bottom: 18px;
width: min(760px, calc(100vw - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: 1fr auto;
gap: 18px;
align-items: center;
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(18px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.3);
pointer-events: auto;
}
.slider-head {
display: flex;
justify-content: space-between;
gap: 16px;
margin-bottom: 9px;
font-size: 11px;
}
.slider-label {
color: #b8c9ce;
letter-spacing: 0.04em;
}
.readout {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-weight: 750;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 4px;
border-radius: 99px;
background: linear-gradient(90deg, #f4b76a, #67e8f9);
box-shadow: 0 0 12px rgba(103, 232, 249, 0.15);
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -6px;
appearance: none;
border: 2px solid #dffbff;
border-radius: 50%;
background: #163b46;
box-shadow: 0 0 0 5px rgba(103, 232, 249, 0.11);
}
input[type="range"]::-moz-range-track {
height: 4px;
border-radius: 99px;
background: linear-gradient(90deg, #f4b76a, #67e8f9);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 2px solid #dffbff;
border-radius: 50%;
background: #163b46;
}
.control-actions {
display: flex;
gap: 8px;
align-items: center;
}
.button {
min-height: 38px;
padding: 0 15px;
border: 1px solid rgba(103, 232, 249, 0.34);
border-radius: 10px;
background: rgba(34, 104, 118, 0.18);
color: #dffaff;
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.03em;
cursor: pointer;
white-space: nowrap;
}
.button:hover,
.button.active {
border-color: rgba(103, 232, 249, 0.75);
background: rgba(34, 139, 157, 0.28);
}
#loading {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
background: #071018;
color: #9ab6bd;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 700px) {
.header { top: 18px; left: 18px; }
.subtitle { display: none; }
.view-tools { top: 18px; right: 18px; }
.chip { display: none; }
.legend { display: none; }
.controls {
grid-template-columns: 1fr;
gap: 10px;
bottom: 12px;
padding: 12px 14px;
}
.control-actions { justify-content: flex-end; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="header">
<div class="eyebrow">Material response / Fiber diagram</div>
<h1>Elastic band under load</h1>
<div class="subtitle">
A fabric-covered waistband with a deliberate inspection window. Five symbolic
elastic fibers remain end-locked to sewn anchor tabs as the band extends.
</div>
</header>
<div class="view-tools">
<div class="chip">Drag to orbit · Wheel to zoom</div>
<button class="icon-button" id="resetView" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
<aside class="legend">
<div class="legend-title">Diagram key</div>
<div class="legend-row"><span class="swatch fabric"></span>Woven fabric shell</div>
<div class="legend-row"><span class="swatch fiber"></span>Elastic fiber bundle</div>
<div class="legend-row"><span class="swatch anchor"></span>End attachment tabs</div>
<div class="legend-note">
The right specimen is continuously remeshed from relaxed to stretched.
Every fiber endpoint remains coincident with its attachment rivet.
</div>
</aside>
<section class="controls" aria-label="Elastic stretch controls">
<div>
<div class="slider-head">
<span class="slider-label">Right specimen extension</span>
<span class="readout" id="extensionReadout" aria-live="polite">100%</span>
</div>
<input
id="stretch"
type="range"
min="0"
max="100"
value="100"
step="1"
aria-label="Stretch the right elastic band specimen"
/>
</div>
<div class="control-actions">
<button class="button" id="cycle">Cycle stretch</button>
</div>
</section>
</div>
<div id="loading">Building fiber diagram…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
loading.textContent = "WebGL is required to view this diagram.";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 13, 29);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
80
);
// Camera controls are implemented directly here; no addons are used.
const cameraState = {
target: new THREE.Vector3(0.35, 0.02, 0),
radius: 10.8,
theta: -0.10,
phi: 1.25
};
const desiredCamera = {
target: cameraState.target.clone(),
radius: cameraState.radius,
theta: cameraState.theta,
phi: cameraState.phi
};
function defaultRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.75) return 20;
if (aspect < 1.2) return 14.5;
return 10.8;
}
function resetCamera() {
desiredCamera.target.set(0.35, 0.02, 0);
desiredCamera.radius = defaultRadius();
desiredCamera.theta = -0.10;
desiredCamera.phi = 1.25;
}
function updateCamera(delta) {
const damping = 1 - Math.exp(-delta * 10);
cameraState.target.lerp(desiredCamera.target, damping);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius, desiredCamera.radius, damping
);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta, desiredCamera.theta, damping
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi, desiredCamera.phi, damping
);
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);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.62,
1.49
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
6.2,
25
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetView").addEventListener("click", resetCamera);
// Lighting and ground.
scene.add(new THREE.HemisphereLight(0xbdeaff, 0x19131a, 2.2));
const keyLight = new THREE.DirectionalLight(0xfff0dc, 4.2);
keyLight.position.set(3.5, 7.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x64dfff, 2.0);
rimLight.position.set(-6, 2.5, 4);
scene.add(rimLight);
const warmRim = new THREE.PointLight(0xffa85c, 18, 14, 2);
warmRim.position.set(3, -0.5, -4);
scene.add(warmRim);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(38, 25),
new THREE.MeshStandardMaterial({
color: 0x08131b,
roughness: 0.88,
metalness: 0.12
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.02;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x315464, 0x162a35);
grid.position.y = -1.005;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
function addPlinth(x, radius, xScale) {
const group = new THREE.Group();
group.position.set(x, -0.91, 0);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.035, 0.16, 72),
new THREE.MeshStandardMaterial({
color: 0x0c1c25,
roughness: 0.58,
metalness: 0.42
})
);
base.scale.x = xScale;
base.receiveShadow = true;
group.add(base);
const ring = new THREE.Mesh(
new THREE.RingGeometry(radius * 0.79, radius * 0.84, 96),
new THREE.MeshBasicMaterial({
color: 0x3dd6e8,
transparent: true,
opacity: 0.24,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.083;
ring.scale.x = xScale;
group.add(ring);
scene.add(group);
}
addPlinth(-2.15, 1.9, 1.03);
addPlinth(2.25, 2.43, 1.02);
// Procedural woven fabric texture.
function makeFabricTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 256;
const ctx = canvas.getContext("2d");
const image = ctx.createImageData(256, 256);
for (let y = 0; y < 256; y++) {
for (let x = 0; x < 256; x++) {
const index = (y * 256 + x) * 4;
const noise = (Math.random() - 0.5) * 17;
const weave = ((x % 8 < 2) ? -10 : 3) + ((y % 8 < 2) ? -7 : 4);
image.data[index] = 198 + noise + weave;
image.data[index + 1] = 181 + noise + weave * 0.8;
image.data[index + 2] = 151 + noise + weave * 0.55;
image.data[index + 3] = 255;
}
}
ctx.putImageData(image, 0, 0);
ctx.globalAlpha = 0.24;
ctx.strokeStyle = "#6d604f";
ctx.lineWidth = 1;
for (let i = 0; i < 256; i += 8) {
ctx.beginPath();
ctx.moveTo(i + 0.5, 0);
ctx.lineTo(i + 0.5, 256);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, i + 0.5);
ctx.lineTo(256, i + 0.5);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2.4, 2.4);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const fabricTexture = makeFabricTexture();
const materials = {
fabric: new THREE.MeshStandardMaterial({
color: 0xffffff,
map: fabricTexture,
bumpMap: fabricTexture,
bumpScale: 0.035,
roughness: 0.94,
metalness: 0.01
}),
hem: new THREE.MeshStandardMaterial({
color: 0x8f806a,
map: fabricTexture,
roughness: 0.98
}),
backing: new THREE.MeshStandardMaterial({
color: 0x9e8c70,
map: fabricTexture,
roughness: 0.9
}),
anchor: new THREE.MeshStandardMaterial({
color: 0xe4a85d,
roughness: 0.31,
metalness: 0.72,
emissive: 0x3a1c05,
emissiveIntensity: 0.14
}),
rivet: new THREE.MeshStandardMaterial({
color: 0xffcf85,
roughness: 0.22,
metalness: 0.88,
emissive: 0x5a2b08,
emissiveIntensity: 0.2
}),
stitch: new THREE.LineDashedMaterial({
color: 0xf1e7d2,
dashSize: 0.07,
gapSize: 0.045,
transparent: true,
opacity: 0.82
})
};
const strandColors = [0xf2d8b7, 0xd8e7dc, 0xf1c69f];
const strandMaterials = strandColors.map((color, index) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.43,
metalness: 0.04,
emissive: new THREE.Color(color).multiplyScalar(0.09),
emissiveIntensity: 0.22 + index * 0.04
})
);
const braidMaterials = strandColors.map((color) =>
new THREE.MeshStandardMaterial({
color: new THREE.Color(color).lerp(new THREE.Color(0xffffff), 0.38),
roughness: 0.36,
metalness: 0.05,
emissive: new THREE.Color(color).multiplyScalar(0.05),
emissiveIntensity: 0.16
})
);
function arch(x, halfWidth) {
return -0.14 * Math.pow(x / halfWidth, 2);
}
function pushQuad(positions, uvs, indices, p0, p1, p2, p3) {
const base = positions.length / 3;
const quad = [p0, p1, p2, p3];
const quadUV = [[0, 0], [1, 0], [1, 1], [0, 1]];
for (let i = 0; i < 4; i++) {
positions.push(quad[i][0], quad[i][1], quad[i][2]);
uvs.push(quadUV[i][0], quadUV[i][1]);
}
indices.push(base, base + 1, base + 2, base, base + 2, base + 3);
}
function makePanelGeometry(x0, x1, height, halfWidth) {
const nx = 22;
const ny = 6;
const row = nx + 1;
const layerSize = row * (ny + 1);
const positions = [];
const uvs = [];
const indices = [];
const frontZ = (x, y) =>
arch(x, halfWidth) + 0.024 * (1 - Math.pow((2 * y) / height, 2));
const thickness = 0.16;
for (let layer = 0; layer < 2; layer++) {
for (let j = 0; j <= ny; j++) {
const y = -height / 2 + (height * j) / ny;
for (let i = 0; i <= nx; i++) {
const x = THREE.MathUtils.lerp(x0, x1, i / nx);
const z = frontZ(x, y) - (layer === 1 ? thickness : 0);
positions.push(x, y, z);
uvs.push((x / halfWidth + 1) * 0.5, j / ny);
}
}
}
for (let j = 0; j < ny; j++) {
for (let i = 0; i < nx; i++) {
const a = j * row + i;
const b = a + 1;
const d = a + row;
const c = d + 1;
indices.push(a, b, d, b, c, d);
const ba = layerSize + a;
const bb = layerSize + b;
const bd = layerSize + d;
const bc = layerSize + c;
indices.push(ba, bd, bb, bb, bd, bc);
}
}
const y0 = -height / 2;
const y1 = height / 2;
// Left and right cut edges.
pushQuad(
positions, uvs, indices,
[x0, y0, frontZ(x0, y0)],
[x0, y1, frontZ(x0, y1)],
[x0, y1, frontZ(x0, y1) - thickness],
[x0, y0, frontZ(x0, y0) - thickness]
);
pushQuad(
positions, uvs, indices,
[x1, y0, frontZ(x1, y0)],
[x1, y1, frontZ(x1, y1)],
[x1, y1, frontZ(x1, y1) - thickness],
[x1, y0, frontZ(x1, y0) - thickness]
);
// Top and bottom edges.
pushQuad(
positions, uvs, indices,
[x0, y1, frontZ(x0, y1)],
[x1, y1, frontZ(x1, y1)],
[x1, y1, frontZ(x1, y1) - thickness],
[x0, y1, frontZ(x0, y1) - thickness]
);
pushQuad(
positions, uvs, indices,
[x0, y0, frontZ(x0, y0)],
[x1, y0, frontZ(x1, y0)],
[x1, y0, frontZ(x1, y0) - thickness],
[x0, y0, frontZ(x0, y0) - thickness]
);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabel() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 196;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.30, 0.587, 1);
sprite.renderOrder = 20;
function update(title, subtitle, accent) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 752, 180, 24);
ctx.fillStyle = "rgba(7, 18, 26, 0.88)";
ctx.fill();
ctx.lineWidth = 2;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(32, 32, 7, 132);
ctx.fillStyle = "#eff9fb";
ctx.font = "700 43px system-ui, sans-serif";
ctx.textBaseline = "alphabetic";
ctx.fillText(title, 64, 79);
ctx.fillStyle = "#92aab2";
ctx.font = "500 22px system-ui, sans-serif";
ctx.fillText(subtitle, 65, 120);
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(710, 65, 10, 0, Math.PI * 2);
ctx.fill();
texture.needsUpdate = true;
}
return { sprite, update };
}
const leftLabel = makeLabel();
leftLabel.sprite.position.set(-2.15, 1.18, 0.05);
leftLabel.update(
"01 RELAXED",
"Low load · slack fibers · compact spacing",
"#f4b76a"
);
scene.add(leftLabel.sprite);
const rightLabel = makeLabel();
rightLabel.sprite.position.set(2.25, 1.18, 0.05);
scene.add(rightLabel.sprite);
function disposeGroup(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
while (group.children.length) group.remove(group.children[0]);
}
function addSeam(group, points) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, materials.stitch);
line.computeLineDistances();
group.add(line);
}
function makeSpecimen(worldX) {
const group = new THREE.Group();
group.position.set(worldX, 0.13, 0);
scene.add(group);
const state = {
group,
stretch: -1,
arrows: []
};
function setStretch(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
if (Math.abs(t - state.stretch) < 0.0001) return;
state.stretch = t;
disposeGroup(group);
state.arrows.length = 0;
const halfWidth = THREE.MathUtils.lerp(1.55, 2.20, t);
const windowHalf = THREE.MathUtils.lerp(0.68, 1.12, t);
const height = 1.12;
const sag = THREE.MathUtils.lerp(0.115, 0.012, t);
const waveAmount = THREE.MathUtils.lerp(0.034, 0.008, t);
// Fabric-covered left and right portions.
for (const [x0, x1] of [
[-halfWidth, -windowHalf],
[windowHalf, halfWidth]
]) {
const panel = new THREE.Mesh(
makePanelGeometry(x0, x1, height, halfWidth),
materials.fabric
);
panel.castShadow = true;
panel.receiveShadow = true;
group.add(panel);
for (const y of [-height / 2 + 0.105, height / 2 - 0.105]) {
const points = [];
for (let i = 0; i <= 28; i++) {
const x = THREE.MathUtils.lerp(x0, x1, i / 28);
points.push(new THREE.Vector3(x, y, arch(x, halfWidth) + 0.064));
}
addSeam(group, points);
}
}
// Top and bottom hems frame the exposed inspection window.
for (const y of [-height / 2 + 0.018, height / 2 - 0.018]) {
const points = [];
for (let i = 0; i <= 60; i++) {
const x = THREE.MathUtils.lerp(-halfWidth, halfWidth, i / 60);
points.push(new THREE.Vector3(x, y, arch(x, halfWidth) + 0.064));
}
const hem = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(points),
96,
0.037,
8,
false
),
materials.hem
);
hem.castShadow = true;
group.add(hem);
}
// Two sewn attachment tabs bound the open center section.
for (const side of [-1, 1]) {
const anchorX = side * windowHalf;
const anchorZ = arch(anchorX, halfWidth);
const backing = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 0.98, 0.055),
materials.backing
);
backing.position.set(anchorX, 0, anchorZ + 0.045);
backing.castShadow = true;
group.add(backing);
const bar = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.86, 18),
materials.anchor
);
bar.position.set(anchorX, 0, anchorZ + 0.11);
bar.castShadow = true;
group.add(bar);
for (const y of [-0.43, 0.43]) {
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 18, 12),
materials.anchor
);
cap.position.set(anchorX, y, anchorZ + 0.11);
cap.castShadow = true;
group.add(cap);
}
}
// Five symbolic elastic fibers. The first and final points are copied
// directly into the rivet positions, guaranteeing attached endpoints.
const levels = [-0.38, -0.19, 0, 0.19, 0.38];
for (let strandIndex = 0; strandIndex < levels.length; strandIndex++) {
const level = levels[strandIndex];
const phase = strandIndex * 1.37;
const points = [];
for (let i = 0; i <= 120; i++) {
const u = i / 120;
const x = THREE.MathUtils.lerp(-windowHalf, windowHalf, u);
const slack = sag * 4 * u * (1 - u);
const ripple =
waveAmount *
Math.sin(Math.PI * u) *
Math.sin(Math.PI * 3 * u + phase);
const y = level + slack + ripple;
const z =
arch(x, halfWidth) +
0.16 +
0.03 * Math.sin(Math.PI * 4 * u + phase) * Math.sin(Math.PI * u);
points.push(new THREE.Vector3(x, y, z));
}
const curve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.5);
const core = new THREE.Mesh(
new THREE.TubeGeometry(curve, 96, 0.028, 9, false),
strandMaterials[strandIndex % strandMaterials.length]
);
core.castShadow = true;
core.receiveShadow = true;
group.add(core);
// A fine winding line suggests a twisted yarn construction.
const windingPoints = points.map((point, index) => {
const u = index / (points.length - 1);
const amount = Math.sin(Math.PI * u) * 0.018;
const angle = u * Math.PI * 18 + phase;
return new THREE.Vector3(
point.x,
point.y + Math.cos(angle) * amount,
point.z + Math.sin(angle) * amount
);
});
const winding = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(windingPoints),
96,
0.0065,
5,
false
),
braidMaterials[strandIndex % braidMaterials.length]
);
winding.castShadow = true;
group.add(winding);
// Rivets are positioned at exactly the strand endpoint coordinates.
for (const endpoint of [points[0], points[points.length - 1]]) {
const rivet = new THREE.Mesh(
new THREE.SphereGeometry(0.043, 18, 12),
materials.rivet
);
rivet.position.copy(endpoint);
rivet.castShadow = true;
group.add(rivet);
}
}
// Outward pull arrows communicate applied tensile load.
if (t > 0.015) {
const arrowY = -0.78;
const arrowZ = 0.18;
const leftArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(-halfWidth - 0.03, arrowY, arrowZ),
0.52,
0x67e8f9,
0.14,
0.085
);
const rightArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(halfWidth + 0.03, arrowY, arrowZ),
0.52,
0x67e8f9,
0.14,
0.085
);
group.add(leftArrow, rightArrow);
state.arrows.push(leftArrow, rightArrow);
}
}
state.setStretch = setStretch;
return state;
}
const relaxedSpecimen = makeSpecimen(-2.15);
const stretchedSpecimen = makeSpecimen(2.25);
relaxedSpecimen.setStretch(0);
stretchedSpecimen.setStretch(1);
const stretchInput = document.getElementById("stretch");
const readout = document.getElementById("extensionReadout");
const cycleButton = document.getElementById("cycle");
function updateRightSpecimen(t) {
stretchedSpecimen.setStretch(t);
const percent = Math.round(t * 100);
stretchInput.value = String(percent);
readout.textContent = `${percent}%`;
rightLabel.update(
"02 STRETCHED",
`${percent}% extension · taut fibers · expanded spacing`,
"#67e8f9"
);
}
updateRightSpecimen(1);
let cycling = false;
let lastCycleUpdate = 0;
stretchInput.addEventListener("input", (event) => {
cycling = false;
cycleButton.classList.remove("active");
cycleButton.textContent = "Cycle stretch";
updateRightSpecimen(Number(event.target.value) / 100);
});
cycleButton.addEventListener("click", () => {
cycling = !cycling;
cycleButton.classList.toggle("active", cycling);
cycleButton.textContent = cycling ? "Stop cycle" : "Cycle stretch";
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
desiredCamera.radius = defaultRadius();
const clock = new THREE.Clock();
renderer.setAnimationLoop((time) => {
const delta = Math.min(clock.getDelta(), 0.05);
if (cycling && time - lastCycleUpdate > 48) {
const phase = (Math.sin(time * 0.00115 - Math.PI / 2) + 1) * 0.5;
updateRightSpecimen(phase);
lastCycleUpdate = time;
}
// Subtle material shimmer; geometry and attachment positions remain fixed.
for (let i = 0; i < strandMaterials.length; i++) {
strandMaterials[i].emissiveIntensity =
0.18 + 0.055 * (1 + Math.sin(time * 0.002 + i));
braidMaterials[i].emissiveIntensity =
0.13 + 0.045 * (1 + Math.sin(time * 0.0024 + i * 0.7));
}
for (const arrow of stretchedSpecimen.arrows) {
const opacity = 0.58 + 0.22 * (0.5 + 0.5 * Math.sin(time * 0.003));
arrow.line.material.transparent = true;
arrow.line.material.opacity = opacity;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = opacity;
}
updateCamera(delta);
renderer.render(scene, camera);
});
loading.remove();
</script>
</body>
</html>
```