Prompt specification
Build or customize the Three.js 3D scene "Repair-or-replace decision 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: Repair-or-replace decision exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/repair-or-replace-decision-exhibit-x0244
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring bicycle inner-tube repair. Build a bicycle workshop with several schematic tube conditions; users identify isolated versus widespread damage using visible evidence, with the exhibit explaining its conceptual rather than instructional scope. Low-poly.
Working Three.js Starter (repair-or-replace-decision-exhibit-x0244):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tube Atlas — Bicycle Workshop Exhibit</title>
<style>
:root {
--ink: #202725;
--muted: #68706a;
--paper: #f5f0e5;
--paper-deep: #e9e1d2;
--orange: #e56e36;
--orange-dark: #9b3e19;
--teal: #416d68;
--line: rgba(32, 39, 37, 0.14);
--shadow: 0 24px 70px rgba(34, 37, 31, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8bea9;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 3px solid rgba(229, 110, 54, 0.42);
outline-offset: 3px;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(90deg, rgba(31, 37, 34, 0.08), transparent 28%),
radial-gradient(circle at 48% 42%, transparent 42%, rgba(32, 37, 33, 0.16));
z-index: 2;
}
.masthead {
position: fixed;
z-index: 5;
top: 28px;
left: 32px;
width: min(480px, calc(100vw - 450px));
pointer-events: none;
text-shadow: 0 1px 16px rgba(245, 240, 229, 0.35);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin: 0 0 12px;
color: #39413c;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 27px;
height: 2px;
content: "";
background: var(--orange);
}
.masthead h1 {
max-width: 430px;
margin: 0;
color: #25302c;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4vw, 58px);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.96;
}
.masthead p {
max-width: 390px;
margin: 16px 0 0;
color: #46504a;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
bottom: 22px;
width: 378px;
padding: 24px;
overflow: auto;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 24px;
background: rgba(247, 243, 234, 0.95);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.panel-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 22px;
}
.concept-pill {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(65, 109, 104, 0.2);
border-radius: 999px;
background: rgba(65, 109, 104, 0.08);
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.concept-pill::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--teal);
}
.icon-button {
display: grid;
width: 34px;
height: 34px;
padding: 0;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: transparent;
color: var(--muted);
cursor: pointer;
transition: 160ms ease;
}
.icon-button:hover {
border-color: rgba(32, 39, 37, 0.28);
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
}
.intro-copy {
margin: 0 0 22px;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.progress-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.progress-track {
height: 4px;
margin-bottom: 25px;
overflow: hidden;
border-radius: 10px;
background: rgba(32, 39, 37, 0.09);
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--orange);
transition: width 350ms ease;
}
.section-label {
margin: 0 0 8px;
color: var(--orange-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#specimen-number {
margin: 0 0 7px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#specimen-title {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 31px;
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1.05;
}
#specimen-description {
margin: 11px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.evidence-card {
position: relative;
margin: 0 0 20px;
padding: 16px 16px 16px 42px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 255, 255, 0.45);
}
.evidence-card::before {
position: absolute;
top: 18px;
left: 17px;
width: 10px;
height: 10px;
content: "";
border: 2px solid var(--orange);
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(229, 110, 54, 0.12);
}
.evidence-card h3 {
margin: 0 0 9px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#evidence-list {
margin: 0;
padding-left: 17px;
color: #59625c;
font-size: 12px;
line-height: 1.65;
}
#evidence-list li + li {
margin-top: 3px;
}
.choice-title {
margin: 0 0 10px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
}
.choices {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.choice {
min-height: 49px;
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.5);
color: var(--ink);
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: 160ms ease;
}
.choice:hover {
border-color: rgba(229, 110, 54, 0.5);
transform: translateY(-1px);
}
.choice.chosen {
border-color: var(--orange);
background: rgba(229, 110, 54, 0.1);
}
.feedback {
display: none;
margin-top: 14px;
padding: 13px 14px;
border-radius: 13px;
font-size: 12px;
line-height: 1.55;
}
.feedback.visible {
display: block;
}
.feedback.correct {
border: 1px solid rgba(65, 109, 104, 0.24);
background: rgba(65, 109, 104, 0.09);
color: #315954;
}
.feedback.incorrect {
border: 1px solid rgba(155, 62, 25, 0.24);
background: rgba(229, 110, 54, 0.09);
color: #7d3a1c;
}
.feedback strong {
display: block;
margin-bottom: 3px;
}
.scope-note {
margin-top: 23px;
padding-top: 18px;
border-top: 1px solid var(--line);
color: #70766f;
font-size: 11px;
line-height: 1.6;
}
.scope-note strong {
color: #454e48;
}
details {
margin-top: 14px;
color: #70766f;
font-size: 11px;
line-height: 1.6;
}
summary {
color: #454e48;
font-weight: 750;
cursor: pointer;
}
details p {
margin: 9px 0 0;
}
.panel-actions {
display: flex;
gap: 8px;
margin-top: 18px;
}
.text-button {
flex: 1;
padding: 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: transparent;
color: #59615c;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
.text-button:hover {
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
}
.scene-tools {
position: fixed;
z-index: 7;
left: 30px;
bottom: 28px;
display: flex;
align-items: center;
gap: 8px;
}
.tool-group {
display: flex;
align-items: center;
gap: 4px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 15px;
background: rgba(35, 42, 38, 0.83);
box-shadow: 0 12px 30px rgba(26, 31, 28, 0.17);
backdrop-filter: blur(12px);
}
.tool {
display: grid;
width: 34px;
height: 34px;
padding: 0;
place-items: center;
border: 0;
border-radius: 10px;
background: transparent;
color: #f0ebdf;
font-size: 17px;
cursor: pointer;
transition: 150ms ease;
}
.tool:hover {
background: rgba(255, 255, 255, 0.12);
}
.tool.wide {
width: auto;
padding: 0 11px;
gap: 6px;
font-size: 11px;
font-weight: 750;
}
.tool-divider {
width: 1px;
height: 20px;
margin: 0 2px;
background: rgba(255, 255, 255, 0.15);
}
.hint {
margin-left: 8px;
color: rgba(36, 44, 40, 0.78);
font-size: 11px;
font-weight: 650;
text-shadow: 0 1px 10px rgba(255, 255, 255, 0.45);
}
.evidence-toggle {
position: fixed;
z-index: 7;
right: 420px;
top: 28px;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 9px 5px 5px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 999px;
background: rgba(38, 45, 41, 0.82);
color: #f5f0e5;
box-shadow: 0 8px 22px rgba(28, 32, 29, 0.16);
font-size: 10px;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
transition: 150ms ease;
}
.scene-label:hover,
.scene-label.active {
border-color: rgba(229, 110, 54, 0.85);
background: rgba(43, 49, 45, 0.96);
}
.scene-label span {
display: grid;
width: 23px;
height: 23px;
place-items: center;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
color: #f1aa7f;
font-size: 9px;
font-weight: 850;
}
.scene-label b {
font-weight: 700;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #cfc6b3;
color: #39413c;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.masthead {
width: calc(100vw - 420px);
}
.masthead p {
display: none;
}
.hint {
display: none;
}
}
@media (max-width: 720px) {
.masthead {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.masthead h1 {
font-size: 34px;
}
.eyebrow {
margin-bottom: 8px;
font-size: 9px;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 47vh;
padding: 19px;
border-radius: 20px;
}
.panel-top,
.intro-copy,
.progress-track {
display: none;
}
.progress-row {
margin-bottom: 13px;
}
#specimen-title {
font-size: 25px;
}
.evidence-card {
margin-bottom: 14px;
padding: 12px 12px 12px 38px;
}
.scope-note {
margin-top: 15px;
padding-top: 13px;
}
.scene-tools {
top: 111px;
bottom: auto;
left: 18px;
}
.evidence-toggle {
top: 18px;
right: 18px;
}
.evidence-toggle .tool.wide span:last-child {
display: none;
}
.scene-label b {
display: none;
}
.scene-label {
padding-right: 5px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly bicycle workshop with four inner-tube condition specimens"></canvas>
<div id="vignette"></div>
<div id="labels"></div>
<header class="masthead">
<p class="eyebrow">Bicycle workshop · pattern study</p>
<h1>Inside the tube</h1>
<p>
Four schematic inner tubes. Read the visible evidence, then decide whether
the damage is isolated or widespread.
</p>
</header>
<button
id="evidence-toggle"
class="tool wide evidence-toggle"
type="button"
aria-pressed="true"
title="Toggle damage outlines"
>
<span aria-hidden="true">◎</span>
<span>Evidence outlines</span>
</button>
<aside class="panel" aria-label="Exhibit controls and specimen information">
<div class="panel-top">
<div class="concept-pill">Concept exhibit</div>
<button id="reset-study" class="icon-button" type="button" title="Reset all classifications" aria-label="Reset all classifications">
↺
</button>
</div>
<p class="intro-copy">
This gallery compares the spatial distribution of visible damage. It is a
visual classification exercise—not a diagnosis or a repair manual.
</p>
<div class="progress-row">
<span>Study progress</span>
<span id="progress-text">0 / 4</span>
</div>
<div class="progress-track"><div id="progress-fill"></div></div>
<p class="section-label">Current specimen</p>
<p id="specimen-number">Specimen 01 / 04</p>
<h2 id="specimen-title">Pinprick puncture</h2>
<p id="specimen-description"></p>
<section class="evidence-card" aria-labelledby="evidence-title">
<h3 id="evidence-title">Visible evidence</h3>
<ul id="evidence-list"></ul>
</section>
<p class="choice-title">How would you classify this pattern?</p>
<div class="choices">
<button class="choice" data-choice="isolated" type="button">Isolated</button>
<button class="choice" data-choice="widespread" type="button">Widespread</button>
</div>
<div id="feedback" class="feedback" role="status" aria-live="polite"></div>
<div class="scope-note">
<strong>Scope:</strong> The exhibit names broad visual patterns only. It
does not assess the safety or serviceability of a real tube, and it omits
patching procedures.
</div>
<details>
<summary>How to read the taxonomy</summary>
<p>
“Isolated” means the visible evidence is concentrated at one bounded
site. “Widespread” means evidence recurs at separated sites or extends
across a substantial portion of the tube.
</p>
</details>
<div class="panel-actions">
<button id="focus-specimen" class="text-button" type="button">Focus specimen</button>
<button id="next-specimen" class="text-button" type="button">Next specimen →</button>
</div>
</aside>
<div class="scene-tools">
<div class="tool-group" aria-label="Camera controls">
<button id="zoom-out" class="tool" type="button" title="Zoom out" aria-label="Zoom out">−</button>
<button id="zoom-in" class="tool" type="button" title="Zoom in" aria-label="Zoom in">+</button>
<span class="tool-divider"></span>
<button id="reset-view" class="tool wide" type="button" title="Reset camera">
<span aria-hidden="true">⌂</span><span>Reset view</span>
</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Shift-drag to pan</div>
</div>
<div id="loading">Preparing workshop…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State and DOM
// -------------------------------------------------------------------------
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const canvas = $("#scene");
const labelsRoot = $("#labels");
const feedback = $("#feedback");
const evidenceToggle = $("#evidence-toggle");
const conditions = [
{
id: "pinprick",
number: "01",
title: "Pinprick puncture",
description: "A small interruption appears within an otherwise continuous surface.",
evidence: [
"One dark puncture is visible.",
"The surrounding rubber surface remains visually continuous."
],
category: "isolated",
damage: [
{ angle: -0.68, kind: "puncture" }
]
},
{
id: "impact",
number: "02",
title: "Stone-strike cluster",
description: "Several separated impacts appear after contact with a rough surface.",
evidence: [
"Several distinct dark punctures are visible.",
"The marks continue across separated sections of the loop."
],
category: "widespread",
damage: [
{ angle: -2.30, kind: "puncture" },
{ angle: -1.52, kind: "puncture" },
{ angle: -0.68, kind: "puncture" },
{ angle: 0.18, kind: "puncture" },
{ angle: 1.02, kind: "puncture" },
{ angle: 1.82, kind: "puncture" }
]
},
{
id: "valve",
number: "03",
title: "Valve-base nick",
description: "A short split sits next to the metal valve fitting.",
evidence: [
"One elongated interruption is visible beside the valve.",
"The split remains confined to a single local site."
],
category: "isolated",
valveAngle: 1.05,
damage: [
{ angle: 1.24, kind: "nick" }
]
},
{
id: "rimwear",
number: "04",
title: "Rim-edge abrasion",
description: "Repeated flat scuffs follow areas of the outer rubber edge.",
evidence: [
"Multiple flat abrasion marks are visible.",
"The evidence is distributed around separated parts of the loop."
],
category: "widespread",
damage: [
{ angle: -2.70, kind: "abrasion" },
{ angle: -2.05, kind: "abrasion" },
{ angle: -1.24, kind: "abrasion" },
{ angle: -0.36, kind: "abrasion" },
{ angle: 0.50, kind: "abrasion" },
{ angle: 1.38, kind: "abrasion" },
{ angle: 2.18, kind: "abrasion" }
]
}
];
const state = {
selected: conditions[0].id,
answers: {},
evidence: true
};
function currentCondition() {
return conditions.find((condition) => condition.id === state.selected);
}
// -------------------------------------------------------------------------
// Renderer, camera, and lights
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9c0ad);
scene.fog = new THREE.Fog(0xc9c0ad, 17, 31);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
70
);
const homeView = {
target: new THREE.Vector3(-1.1, 2.65, -1.35),
yaw: 0.31,
pitch: 0.25,
radius: 11.8
};
const currentView = {
target: homeView.target.clone(),
yaw: homeView.yaw,
pitch: homeView.pitch,
radius: homeView.radius
};
const desiredView = {
target: homeView.target.clone(),
yaw: homeView.yaw,
pitch: homeView.pitch,
radius: homeView.radius
};
const hemisphere = new THREE.HemisphereLight(0xfff0d1, 0x55594e, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe8bd, 3.1);
sun.position.set(-5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9c8c4, 0.65);
fill.position.set(7, 5, -5);
scene.add(fill);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const makeMaterial = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
const materials = {
floor: makeMaterial(0x9b7652),
floorLight: makeMaterial(0xa8835c),
floorDark: makeMaterial(0x8c6949),
wall: makeMaterial(0xc8c0ad),
wallTrim: makeMaterial(0x7f8879),
wood: makeMaterial(0x80593e),
woodLight: makeMaterial(0xa9794f),
woodDark: makeMaterial(0x4d382b),
metal: makeMaterial(0x64706d, { metalness: 0.72, roughness: 0.34 }),
darkMetal: makeMaterial(0x303a38, { metalness: 0.55, roughness: 0.44 }),
orange: makeMaterial(0xd96530),
cream: makeMaterial(0xded3bd),
blue: makeMaterial(0x759a9c, { roughness: 0.38 }),
black: makeMaterial(0x242b29),
damage: makeMaterial(0x090d0c, { roughness: 1 }),
rubber: makeMaterial(0x38413e, { roughness: 0.95 })
};
function addBox(w, h, d, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
x,
y,
z,
material,
parent = scene,
segments = 10
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addRod(a, b, radius, material, parent = scene, segments = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
segments
),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addTorus(
radius,
tube,
x,
y,
z,
material,
parent = scene,
radialSegments = 6,
tubularSegments = 28
) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(
radius,
tube,
radialSegments,
tubularSegments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Workshop architecture
// -------------------------------------------------------------------------
addBox(20, 0.3, 17, 0, -0.18, -0.8, materials.floorDark);
for (let i = 0; i < 20; i += 1) {
const plankMaterial =
i % 3 === 0
? materials.floorLight
: i % 3 === 1
? materials.floor
: materials.floorDark;
addBox(
0.94,
0.055,
15.8,
-9.45 + i * 0.995,
0.015,
-0.65,
plankMaterial
);
}
addBox(20, 9, 0.22, 0, 4.45, -7.85, materials.wall);
addBox(0.22, 9, 15.5, -9.85, 4.45, -0.35, materials.wall);
addBox(20, 0.28, 0.28, 0, 8.8, -7.68, materials.wallTrim);
addBox(0.28, 0.28, 15.5, -9.68, 8.8, -0.35, materials.wallTrim);
addBox(20, 0.18, 0.16, 0, 1.05, -7.66, materials.wallTrim);
// Pegboard and a simple grid of holes.
addBox(5.4, 2.45, 0.12, -3.25, 4.62, -7.62, materials.woodDark);
for (let row = 0; row < 5; row += 1) {
for (let column = 0; column < 10; column += 1) {
const hole = addCylinder(
0.025,
0.025,
0.018,
-5.58 + column * 0.52,
3.68 + row * 0.47,
-7.535,
materials.black,
scene,
6
);
hole.rotation.x = Math.PI / 2;
}
}
// Hanging tools.
addBox(0.13, 0.65, 0.09, -4.92, 4.55, -7.42, materials.metal);
addBox(0.27, 0.14, 0.11, -4.92, 4.91, -7.42, materials.metal);
addBox(0.27, 0.14, 0.11, -4.92, 4.19, -7.42, materials.metal);
addRod([-3.95, 4.04, -7.38], [-3.95, 4.80, -7.38], 0.035, materials.metal);
addBox(0.19, 0.36, 0.15, -3.95, 4.91, -7.38, materials.orange);
addRod([-2.95, 4.02, -7.37], [-2.95, 4.91, -7.37], 0.035, materials.metal);
addBox(0.17, 0.31, 0.15, -2.95, 5.03, -7.37, materials.cream);
const plierLeft = addBox(0.09, 0.72, 0.10, -1.95, 4.55, -7.37, materials.darkMetal);
plierLeft.rotation.z = -0.25;
const plierRight = addBox(0.09, 0.72, 0.10, -1.62, 4.55, -7.37, materials.darkMetal);
plierRight.rotation.z = 0.25;
// Window.
addBox(3.8, 2.55, 0.16, 4.95, 5.35, -7.61, materials.woodDark);
addBox(3.48, 2.23, 0.08, 4.95, 5.35, -7.50, materials.blue);
addBox(0.12, 2.35, 0.14, 4.95, 5.35, -7.42, materials.cream);
addBox(3.58, 0.12, 0.14, 4.95, 5.35, -7.42, materials.cream);
addBox(4.05, 0.14, 0.52, 4.95, 4.0, -7.42, materials.woodLight);
// Shelving and containers.
addBox(4.75, 0.14, 0.72, 4.55, 2.45, -6.95, materials.woodLight);
addBox(4.75, 0.14, 0.72, 4.55, 3.55, -6.95, materials.woodLight);
addBox(0.16, 3.7, 0.16, 2.23, 3.0, -7.02, materials.darkMetal);
addBox(0.16, 3.7, 0.16, 6.87, 3.0, -7.02, materials.darkMetal);
addCylinder(0.27, 0.30, 0.48, 2.85, 2.77, -6.92, materials.orange);
addCylinder(0.24, 0.26, 0.44, 3.52, 2.79, -6.92, materials.cream);
addCylinder(0.23, 0.25, 0.40, 4.14, 2.77, -6.92, materials.teal || materials.blue);
addBox(0.72, 0.43, 0.45, 5.48, 3.84, -6.92, materials.wood);
// Workbench.
addBox(10.4, 0.22, 2.2, -1.1, 1.45, -0.95, materials.woodLight);
addBox(10.58, 0.09, 2.34, -1.1, 1.59, -0.95, materials.wood);
for (const x of [-5.25, -1.1, 3.05]) {
addBox(0.20, 1.34, 1.78, x, 0.72, -1.0, materials.woodDark);
}
addBox(3.0, 0.88, 1.72, -3.78, 0.55, -1.02, materials.wallTrim);
for (let i = 0; i < 3; i += 1) {
addBox(2.72, 0.04, 0.04, -3.78, 0.30 + i * 0.27, -0.13, materials.darkMetal);
addBox(0.32, 0.05, 0.06, -3.78, 0.30 + i * 0.27, -0.09, materials.metal);
}
// Bench vice.
addBox(0.75, 0.28, 0.55, 3.45, 1.74, -0.18, materials.darkMetal);
addBox(0.18, 0.42, 0.56, 3.66, 1.95, -0.18, materials.metal);
addCylinder(0.06, 0.06, 0.8, 3.35, 1.91, -0.18, materials.metal).rotation.z =
Math.PI / 2;
// Parts tray and small containers.
addBox(1.25, 0.08, 0.68, -0.02, 1.70, -0.55, materials.darkMetal);
addBox(1.08, 0.08, 0.51, -0.02, 1.76, -0.55, materials.metal);
addCylinder(0.12, 0.12, 0.25, 0.33, 1.82, -0.72, materials.orange);
addCylinder(0.10, 0.10, 0.22, 0.32, 1.79, -0.40, materials.cream);
// Articulated work lamp.
addCylinder(0.28, 0.31, 0.08, -5.05, 1.69, -0.45, materials.darkMetal);
addRod([-5.05, 1.74, -0.45], [-4.70, 2.63, -0.42], 0.045, materials.darkMetal);
addRod([-4.70, 2.63, -0.42], [-3.98, 3.12, -0.36], 0.045, materials.darkMetal);
const lampShade = new THREE.Mesh(
new THREE.ConeGeometry(0.34, 0.48, 8, 1, true),
materials.orange
);
lampShade.position.set(-3.95, 3.08, -0.33);
lampShade.rotation.z = -0.45;
lampShade.castShadow = true;
scene.add(lampShade);
const lampLight = new THREE.PointLight(0xffc66f, 8, 6, 2);
lampLight.position.set(-3.82, 2.85, -0.16);
scene.add(lampLight);
// -------------------------------------------------------------------------
// Stylized bicycle and repair stand
// -------------------------------------------------------------------------
const bicycle = new THREE.Group();
bicycle.position.set(-5.15, 0, -4.25);
scene.add(bicycle);
const rearWheel = addTorus(1.02, 0.065, -1.43, 1.95, 0, materials.black, bicycle);
const frontWheel = addTorus(1.02, 0.065, 1.43, 1.95, 0, materials.black, bicycle);
for (const wheelCenter of [
[-1.43, 1.95, 0],
[1.43, 1.95, 0]
]) {
for (let i = 0; i < 8; i += 1) {
const angle = (i / 8) * Math.PI * 2;
addRod(
wheelCenter,
[
wheelCenter[0] + Math.cos(angle) * 0.96,
wheelCenter[1] + Math.sin(angle) * 0.96,
0
],
0.012,
materials.metal,
bicycle,
5
);
}
}
const rearAxle = [-1.43, 1.95, 0];
const frontAxle = [1.43, 1.95, 0];
const crank = [-0.10, 1.82, 0];
const seatJoint = [-0.56, 3.13, 0];
const headJoint = [0.93, 3.04, 0];
addRod(rearAxle, crank, 0.065, materials.orange, bicycle);
addRod(crank, seatJoint, 0.065, materials.orange, bicycle);
addRod(seatJoint, headJoint, 0.065, materials.orange, bicycle);
addRod(headJoint, crank, 0.065, materials.orange, bicycle);
addRod(headJoint, frontAxle, 0.055, materials.darkMetal, bicycle);
addRod(rearAxle, seatJoint, 0.055, materials.orange, bicycle);
addRod(seatJoint, [-0.61, 3.43, 0], 0.05, materials.metal, bicycle);
addBox(0.52, 0.12, 0.30, -0.68, 3.49, 0, materials.black, bicycle);
addRod(headJoint, [0.91, 3.54, 0], 0.045, materials.metal, bicycle);
addRod([0.91, 3.54, -0.38], [0.91, 3.54, 0.38], 0.04, materials.darkMetal, bicycle);
addRod([0.91, 3.54, -0.38], [0.91, 3.54, 0.38], 0.015, materials.cream, bicycle);
addCylinder(0.17, 0.17, 0.12, crank[0], crank[1], crank[2], materials.darkMetal, bicycle);
addRod([-0.10, 1.82, 0], [-0.10, 1.82, 0.42], 0.025, materials.metal, bicycle);
addBox(0.38, 0.06, 0.14, -0.10, 1.82, 0.48, materials.black, bicycle);
// Repair stand in front of the bicycle.
addCylinder(0.43, 0.48, 0.10, -4.28, 0.10, -3.40, materials.darkMetal);
addCylinder(0.065, 0.075, 2.45, -4.28, 1.28, -3.40, materials.metal);
addRod([-4.28, 2.35, -3.40], [-5.17, 2.60, -3.73], 0.055, materials.metal);
addBox(0.32, 0.25, 0.26, -5.12, 2.58, -3.71, materials.orange);
// Spare tires on the wall.
addTorus(0.82, 0.12, 6.62, 5.45, -7.34, materials.rubber, scene, 6, 24);
addTorus(0.69, 0.10, 6.62, 5.45, -7.10, materials.woodDark, scene, 6, 24);
// -------------------------------------------------------------------------
// Inner tube exhibits
// -------------------------------------------------------------------------
const pickables = [];
const tubeMeta = new Map();
const damageHalos = [];
const tubeX = [-4.50, -2.15, 0.20, 2.55];
const tubeY = 3.04;
const tubeZ = -0.47;
const tubeRadius = 0.68;
const tubeThickness = 0.145;
function addDamageMarker(group, angle, kind) {
const radial = new THREE.Vector3(
Math.cos(angle),
Math.sin(angle),
0
);
const position = radial.clone().multiplyScalar(tubeRadius);
position.z = tubeThickness + 0.008;
let marker;
if (kind === "puncture") {
marker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.074, 0),
materials.damage
);
marker.scale.z = 0.26;
} else if (kind === "nick") {
marker = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.036, 0.025),
materials.damage
);
marker.rotation.z = angle;
} else {
marker = new THREE.Mesh(
new THREE.BoxGeometry(0.095, 0.027, 0.023),
materials.damage
);
marker.rotation.z = angle + Math.PI / 2;
}
marker.position.copy(position);
marker.castShadow = true;
group.add(marker);
const halo = new THREE.Mesh(
new THREE.RingGeometry(
kind === "abrasion" ? 0.075 : 0.088,
kind === "abrasion" ? 0.112 : 0.125,
16
),
new THREE.MeshBasicMaterial({
color: 0xff8a4f,
transparent: true,
opacity: 0.28,
side: THREE.DoubleSide,
depthWrite: false,
depthTest: false
})
);
halo.position.copy(position);
halo.position.z = 0.195;
halo.renderOrder = 5;
group.add(halo);
damageHalos.push(halo);
}
function addValve(group, angle) {
const radial = new THREE.Vector3(
Math.cos(angle),
Math.sin(angle),
0
);
const start = radial.clone().multiplyScalar(tubeRadius + 0.02);
const end = radial.clone().multiplyScalar(tubeRadius + 0.43);
addRod(
start.toArray(),
end.toArray(),
0.043,
materials.metal,
group,
8
);
const cap = addCylinder(
0.075,
0.075,
0.065,
end.x,
end.y,
end.z,
materials.darkMetal,
group,
8
);
cap.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
radial.normalize()
);
}
function createTube(condition, index) {
const group = new THREE.Group();
group.position.set(tubeX[index], tubeY, tubeZ);
scene.add(group);
const tubeMaterial = makeMaterial(0x39423f, {
roughness: 0.96,
metalness: 0,
emissive: 0x000000,
emissiveIntensity: 0
});
const torus = addTorus(
tubeRadius,
tubeThickness,
0,
0,
0,
tubeMaterial,
group,
6,
28
);
torus.userData.conditionId = condition.id;
pickables.push(torus);
const valveAngle = condition.valveAngle ?? -Math.PI / 2;
addValve(group, valveAngle);
for (const damage of condition.damage) {
addDamageMarker(group, damage.angle, damage.kind);
}
// Display stand.
addCylinder(
0.27,
0.31,
0.08,
tubeX[index],
1.66,
tubeZ,
materials.darkMetal
);
addRod(
[tubeX[index], 1.69, tubeZ],
[tubeX[index], 2.34, tubeZ],
0.035,
materials.metal
);
addRod(
[tubeX[index], 2.25, tubeZ - 0.08],
[tubeX[index] - 0.18, 2.43, tubeZ - 0.08],
0.028,
materials.metal
);
addRod(
[tubeX[index], 2.25, tubeZ - 0.08],
[tubeX[index] + 0.18, 2.43, tubeZ - 0.08],
0.028,
materials.metal
);
const indicator = new THREE.Mesh(
new THREE.RingGeometry(0.20, 0.29, 24),
new THREE.MeshBasicMaterial({
color: 0xe56e36,
transparent: true,
opacity: 0.12,
side: THREE.DoubleSide,
depthWrite: false
})
);
indicator.rotation.x = -Math.PI / 2;
indicator.position.set(tubeX[index], 1.575, tubeZ);
scene.add(indicator);
const anchor = new THREE.Object3D();
anchor.position.set(0, 1.00, 0);
group.add(anchor);
const label = document.createElement("button");
label.type = "button";
label.className = "scene-label";
label.innerHTML = `
<span>${condition.number}</span>
<b>${condition.title}</b>
`;
label.setAttribute("aria-label", `Select specimen ${condition.number}: ${condition.title}`);
label.addEventListener("click", () => selectCondition(condition.id, true));
labelsRoot.appendChild(label);
tubeMeta.set(condition.id, {
group,
torus,
material: tubeMaterial,
indicator,
anchor,
label
});
}
conditions.forEach(createTube);
// -------------------------------------------------------------------------
// UI behavior
// -------------------------------------------------------------------------
function updateProgress() {
const correctCount = Object.values(state.answers).filter(
(answer) => answer.correct
).length;
$("#progress-text").textContent = `${correctCount} / ${conditions.length}`;
$("#progress-fill").style.width =
`${(correctCount / conditions.length) * 100}%`;
}
function renderPanel() {
const condition = currentCondition();
const answer = state.answers[condition.id];
$("#specimen-number").textContent =
`Specimen ${condition.number} / ${String(conditions.length).padStart(2, "0")}`;
$("#specimen-title").textContent = condition.title;
$("#specimen-description").textContent = condition.description;
$("#evidence-list").innerHTML = condition.evidence
.map((item) => `<li>${item}</li>`)
.join("");
$$(".choice").forEach((button) => {
button.classList.toggle(
"chosen",
Boolean(answer && button.dataset.choice === answer.choice)
);
});
feedback.className = "feedback";
if (!answer) {
feedback.classList.remove("visible");
} else {
feedback.classList.add("visible");
if (answer.correct) {
feedback.classList.add("correct");
feedback.innerHTML = `
<strong>Correct pattern: ${condition.category}.</strong>
${
condition.category === "isolated"
? "The visible evidence is concentrated at one bounded site, so the exhibit classifies it as an isolated pattern."
: "The visible evidence recurs across separated areas, so the exhibit classifies it as a widespread pattern."
}
`;
} else {
feedback.classList.add("incorrect");
feedback.innerHTML = `
<strong>Try reading the extent again.</strong>
${
condition.category === "isolated"
? "The visible evidence is concentrated at one local site rather than spread across the loop."
: "The visible evidence occupies separated sections of the loop rather than one bounded site."
}
`;
}
}
for (const [id, meta] of tubeMeta) {
const selected = id === state.selected;
meta.label.classList.toggle("active", selected);
meta.material.color.setHex(selected ? 0x303a37 : 0x39423f);
meta.material.emissive.setHex(selected ? 0x3b1d0f : 0x000000);
meta.material.emissiveIntensity = selected ? 0.42 : 0;
}
updateProgress();
}
function selectCondition(id, focus = false) {
state.selected = id;
if (focus) {
const meta = tubeMeta.get(id);
desiredView.target.copy(meta.group.position);
desiredView.radius = 4.35;
desiredView.yaw = 0;
desiredView.pitch = 0.09;
}
renderPanel();
}
function choosePattern(choice) {
const condition = currentCondition();
const correct = choice === condition.category;
state.answers[condition.id] = { choice, correct };
renderPanel();
}
$$(".choice").forEach((button) => {
button.addEventListener("click", () => {
choosePattern(button.dataset.choice);
});
});
evidenceToggle.addEventListener("click", () => {
state.evidence = !state.evidence;
evidenceToggle.setAttribute("aria-pressed", String(state.evidence));
evidenceToggle.classList.toggle("active", state.evidence);
});
$("#focus-specimen").addEventListener("click", () => {
selectCondition(state.selected, true);
});
$("#next-specimen").addEventListener("click", () => {
const index = conditions.findIndex(
(condition) => condition.id === state.selected
);
const next = conditions[(index + 1) % conditions.length];
selectCondition(next.id, true);
});
$("#reset-study").addEventListener("click", () => {
state.answers = {};
selectCondition(conditions[0].id, false);
});
$("#reset-view").addEventListener("click", () => {
desiredView.target.copy(homeView.target);
desiredView.yaw = homeView.yaw;
desiredView.pitch = homeView.pitch;
desiredView.radius = homeView.radius;
});
$("#zoom-in").addEventListener("click", () => {
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * 0.82,
2.8,
18
);
});
$("#zoom-out").addEventListener("click", () => {
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * 1.22,
2.8,
18
);
});
window.addEventListener("keydown", (event) => {
if (event.key >= "1" && event.key <= String(conditions.length)) {
const index = Number(event.key) - 1;
selectCondition(conditions[index].id, true);
}
if (event.key.toLowerCase() === "r") {
desiredView.target.copy(homeView.target);
desiredView.yaw = homeView.yaw;
desiredView.pitch = homeView.pitch;
desiredView.radius = homeView.radius;
}
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan, and raycast selection
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let drag = null;
function setRayFromEvent(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickCondition(event) {
setRayFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickables, false)[0];
return hit ? hit.object.userData.conditionId : null;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
drag = {
id: event.pointerId,
button: event.button,
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY,
moved: false
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || drag.id !== event.pointerId) {
const hovered = pickCondition(event);
canvas.style.cursor = hovered ? "pointer" : "grab";
return;
}
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
const totalDistance = Math.hypot(
event.clientX - drag.startX,
event.clientY - drag.startY
);
if (totalDistance > 4) drag.moved = true;
if (event.shiftKey || drag.button === 2) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(
forward,
new THREE.Vector3(0, 1, 0)
);
const scale = desiredView.radius * 0.0011;
desiredView.target.addScaledVector(right, -dx * scale);
desiredView.target.addScaledVector(forward, dy * scale);
} else {
desiredView.yaw -= dx * 0.006;
desiredView.pitch = THREE.MathUtils.clamp(
desiredView.pitch + dy * 0.0045,
-0.08,
1.15
);
}
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointerup", (event) => {
if (!drag || drag.id !== event.pointerId) return;
const wasClick =
!drag.moved &&
drag.button === 0 &&
Math.hypot(
event.clientX - drag.startX,
event.clientY - drag.startY
) < 7;
if (wasClick) {
const id = pickCondition(event);
if (id) selectCondition(id, true);
}
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
drag = null;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointercancel", () => {
drag = null;
canvas.style.cursor = "grab";
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * Math.exp(event.deltaY * 0.001),
2.8,
18
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const projected = new THREE.Vector3();
function updateLabels() {
for (const condition of conditions) {
const meta = tubeMeta.get(condition.id);
projected.copy(meta.anchor.getWorldPosition(projected));
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
meta.label.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
meta.label.style.left = `${x}px`;
meta.label.style.top = `${y}px`;
}
}
}
let previousTime = performance.now();
function animate(time) {
const delta = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
const smoothing = 1 - Math.exp(-delta * 7.5);
currentView.target.lerp(desiredView.target, smoothing);
currentView.yaw = THREE.MathUtils.lerp(
currentView.yaw,
desiredView.yaw,
smoothing
);
currentView.pitch = THREE.MathUtils.lerp(
currentView.pitch,
desiredView.pitch,
smoothing
);
currentView.radius = THREE.MathUtils.lerp(
currentView.radius,
desiredView.radius,
smoothing
);
const horizontalRadius =
currentView.radius * Math.cos(currentView.pitch);
camera.position.set(
currentView.target.x +
Math.sin(currentView.yaw) * horizontalRadius,
currentView.target.y +
Math.sin(currentView.pitch) * currentView.radius,
currentView.target.z +
Math.cos(currentView.yaw) * horizontalRadius
);
camera.lookAt(currentView.target);
const pulse = 0.5 + 0.5 * Math.sin(time * 0.0032);
for (const halo of damageHalos) {
halo.visible = state.evidence;
halo.material.opacity = 0.18 + pulse * 0.19;
halo.scale.setScalar(0.96 + pulse * 0.08);
}
for (const [id, meta] of tubeMeta) {
meta.indicator.material.opacity =
id === state.selected ? 0.78 : 0.10 + pulse * 0.05;
}
updateLabels();
renderer.render(scene, camera);
}
renderPanel();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
$("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```