Prompt specification
Build or customize the Three.js 3D scene "Repair Versus Replace Story Table" 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 Versus Replace Story Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/repair-versus-replace-story-table-x3292
Scene Description Prompt:
Create a fictional household decision scene with repair time, available parts, and material use. Compare outcomes under stated assumptions without declaring one choice always superior. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (repair-versus-replace-story-table-x3292):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Block & Seal — Household Repair Decision</title>
<style>
:root {
color-scheme: dark;
--bg: #08111f;
--panel: rgba(13, 24, 42, 0.92);
--panel-border: rgba(148, 163, 184, 0.22);
--text: #e8eef8;
--muted: #9fb0c7;
--orange: #f59e0b;
--blue: #38bdf8;
--red: #fb7185;
--green: #a3e635;
--purple: #c084fc;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
#scene:focus-visible {
outline: 2px solid var(--blue);
outline-offset: -3px;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 20;
background: #08111f;
color: #cbd5e1;
letter-spacing: 0.14em;
font-size: 12px;
text-transform: uppercase;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
transition: opacity 250ms ease;
}
header {
position: fixed;
z-index: 5;
top: 16px;
left: 18px;
max-width: 560px;
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
padding: 5px 9px;
border: 1px solid rgba(56, 189, 248, 0.36);
border-radius: 999px;
background: rgba(8, 17, 31, 0.76);
color: #7dd3fc;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--blue);
box-shadow: 0 0 14px var(--blue);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.04em;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.45);
}
header p {
margin: 9px 0 0;
max-width: 530px;
color: #b8c5d8;
font-size: 13px;
line-height: 1.45;
text-shadow: 0 2px 12px #000;
}
.panel {
position: fixed;
z-index: 6;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#information {
top: 82px;
right: 16px;
width: 340px;
max-height: calc(100vh - 292px);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #334155 transparent;
}
.panel-section {
padding: 15px 16px;
border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}
.panel-section:last-child { border-bottom: 0; }
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
color: #f8fafc;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scenario-tag {
color: #7dd3fc;
font-size: 9px;
letter-spacing: 0.08em;
}
#scenarioName {
margin: 0 0 8px;
font-size: 15px;
font-weight: 750;
}
.muted {
color: var(--muted);
font-size: 11.5px;
line-height: 1.55;
}
.assumption-list {
margin: 0;
padding: 0;
list-style: none;
}
.assumption-list li {
position: relative;
margin: 0 0 8px;
padding-left: 14px;
color: #b7c4d6;
font-size: 11px;
line-height: 1.45;
}
.assumption-list li::before {
content: "";
position: absolute;
top: 6px;
left: 0;
width: 5px;
height: 5px;
border-radius: 1px;
background: #64748b;
}
.inventory {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.stock {
min-width: 0;
padding: 9px 7px;
border: 1px solid rgba(148, 163, 184, 0.14);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
text-align: center;
}
.stock .dot {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 4px;
border-radius: 2px;
vertical-align: -1px;
}
.stock strong {
display: block;
margin-top: 5px;
font-size: 16px;
}
.stock small {
color: #8191a8;
font-size: 9px;
}
#outcomeTitle {
margin: 0 0 5px;
font-size: 16px;
}
#outcomeText,
#tradeoffText {
margin: 0;
color: #b8c5d8;
font-size: 11.5px;
line-height: 1.5;
}
#tradeoffText {
margin-top: 8px;
color: #d6deeb;
}
.progress-track {
height: 5px;
margin-top: 12px;
overflow: hidden;
border-radius: 999px;
background: rgba(148, 163, 184, 0.13);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #38bdf8, #a3e635);
transition: width 80ms linear;
}
#statusText {
min-height: 17px;
margin-top: 7px;
color: #8fa1b8;
font-size: 10px;
}
#comparison {
bottom: 16px;
left: 16px;
width: min(810px, calc(100vw - 32px));
padding: 12px;
}
.comparison-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 0 3px 10px;
}
.comparison-heading strong {
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.comparison-heading span {
color: #8293aa;
font-size: 10px;
}
.cards {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 9px;
}
.choice {
position: relative;
min-width: 0;
padding: 12px;
border: 1px solid rgba(148, 163, 184, 0.18);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
color: var(--text);
text-align: left;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.choice:hover {
transform: translateY(-2px);
border-color: rgba(148, 163, 184, 0.42);
background: rgba(255, 255, 255, 0.045);
}
.choice:focus-visible {
outline: 2px solid #7dd3fc;
outline-offset: 2px;
}
.choice.active {
border-color: var(--accent);
background: color-mix(in srgb, var(--accent) 9%, transparent);
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}
.choice-top {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
}
.letter {
display: grid;
width: 24px;
height: 24px;
flex: 0 0 24px;
place-items: center;
border-radius: 7px;
background: var(--accent);
color: #07101d;
font-size: 12px;
font-weight: 900;
}
.choice-title {
overflow: hidden;
font-size: 12px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
margin-bottom: 8px;
}
.metric {
padding: 6px 7px;
border-radius: 7px;
background: rgba(0, 0, 0, 0.18);
}
.metric b {
display: block;
font-size: 13px;
}
.metric span {
color: #8495ad;
font-size: 8.5px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.parts {
min-height: 16px;
color: #c7d2e2;
font-size: 10px;
line-height: 1.35;
}
.result-line {
margin-top: 7px;
padding-top: 7px;
border-top: 1px solid rgba(148, 163, 184, 0.12);
color: var(--accent);
font-size: 9.5px;
font-weight: 750;
}
#hint {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 4;
display: flex;
align-items: center;
gap: 9px;
color: #8090a6;
font-size: 10px;
pointer-events: none;
}
#hint kbd {
padding: 4px 6px;
border: 1px solid rgba(148, 163, 184, 0.2);
border-bottom-width: 2px;
border-radius: 5px;
background: rgba(13, 24, 42, 0.75);
color: #cbd5e1;
font-family: inherit;
font-size: 9px;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
padding: 4px 7px;
border: 1px solid rgba(148, 163, 184, 0.25);
border-radius: 5px;
background: rgba(6, 14, 27, 0.78);
color: #b8c5d8;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.28);
}
.world-label.option-label.active {
border-color: var(--label-color);
color: #fff;
box-shadow:
0 5px 18px rgba(0, 0, 0, 0.28),
0 0 15px color-mix(in srgb, var(--label-color) 25%, transparent);
}
@media (max-width: 980px) {
header {
max-width: 420px;
}
header p { display: none; }
#information {
top: 73px;
width: 290px;
max-height: calc(100vh - 280px);
}
#comparison {
width: calc(100vw - 32px);
}
.cards {
grid-template-columns: repeat(3, minmax(210px, 1fr));
overflow-x: auto;
padding-bottom: 3px;
}
#hint { display: none; }
}
@media (max-width: 600px) {
h1 { font-size: 25px; }
#information {
top: 67px;
right: 8px;
width: min(270px, calc(100vw - 16px));
max-height: 37vh;
}
#comparison {
bottom: 8px;
left: 8px;
width: calc(100vw - 16px);
padding: 9px;
}
.comparison-heading span { display: none; }
.choice { padding: 9px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
scroll-behavior: auto !important;
transition-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel scene of a leaking kitchen sink, repair pump, and household parts shelf"
></canvas>
<div id="loading">Assembling voxel workshop…</div>
<header>
<div class="eyebrow">Fictional household decision lab</div>
<h1>Block & Seal</h1>
<p>
A leaking kitchen booster pump, a limited parts shelf, and three defensible
responses. Compare work time, materials, and immediate water availability.
</p>
</header>
<aside id="information" class="panel" aria-label="Scenario assumptions and selected outcome">
<section class="panel-section">
<div class="section-title">
Scenario
<span class="scenario-tag">Maple Street apartment</span>
</div>
<p id="scenarioName">Kitchen booster pump: flange gasket leak</p>
<p class="muted">
The gasket is confirmed as the leak path. The pump’s remaining life is
unknown, so replacing it may remove an uncertain component—but also adds
work and material.
</p>
</section>
<section class="panel-section">
<div class="section-title">Stated assumptions</div>
<ul class="assumption-list">
<li>One worker, tools ready, and no hidden parts delay.</li>
<li>Time includes setup and testing, but not drying or curing.</li>
<li>Material is the mass of new parts; packaging is excluded.</li>
<li>A safe shutoff valve exists; deferring means about 18 hours without water.</li>
<li>Labor price, water damage, future failure probability, and recycling impact are not modeled.</li>
</ul>
</section>
<section class="panel-section">
<div class="section-title">Parts remaining in preview</div>
<div class="inventory">
<div class="stock">
<span><i class="dot" style="background:#fb7185"></i>Pump</span>
<strong id="pumpStock">1</strong>
<small>on shelf</small>
</div>
<div class="stock">
<span><i class="dot" style="background:#f59e0b"></i>Gasket</span>
<strong id="gasketStock">1</strong>
<small>on shelf</small>
</div>
<div class="stock">
<span><i class="dot" style="background:#a3e635"></i>Seal kit</span>
<strong id="sealStock">1</strong>
<small>on shelf</small>
</div>
</div>
</section>
<section class="panel-section">
<div class="section-title">Selected outcome</div>
<h2 id="outcomeTitle">A — Gasket repair</h2>
<p id="outcomeText"></p>
<p id="tradeoffText"></p>
<div class="progress-track"><div id="progressFill"></div></div>
<div id="statusText" aria-live="polite"></div>
</section>
<section class="panel-section">
<div class="section-title">How to read the comparison</div>
<p class="muted">
C uses the least work and material now but interrupts water service.
A restores water using little new material, while leaving the pump’s
lifespan uncertain. B commits the most time and material to new
components. Which is preferable depends on the household’s priorities
and the evidence about pump condition—not on one universally superior option.
</p>
</section>
</aside>
<section id="comparison" class="panel" aria-label="Compare repair outcomes">
<div class="comparison-heading">
<strong>Compare outcomes</strong>
<span>Click a card or a colored voxel plinth</span>
</div>
<div class="cards">
<button
class="choice active"
data-option="seal"
style="--accent:#f59e0b"
aria-pressed="true"
>
<div class="choice-top">
<span class="letter">A</span>
<span class="choice-title">Gasket repair</span>
</div>
<div class="metrics">
<div class="metric"><b>45 min</b><span>Work now</span></div>
<div class="metric"><b>0.12 kg</b><span>New material</span></div>
</div>
<div class="parts">Uses 1 gasket. Existing pump is retained.</div>
<div class="result-line">Water restored tonight</div>
</button>
<button
class="choice"
data-option="replace"
style="--accent:#38bdf8"
aria-pressed="false"
>
<div class="choice-top">
<span class="letter">B</span>
<span class="choice-title">Replace pump</span>
</div>
<div class="metrics">
<div class="metric"><b>100 min</b><span>Work now</span></div>
<div class="metric"><b>2.40 kg</b><span>New material</span></div>
</div>
<div class="parts">Uses 1 pump, 1 gasket, and 1 seal kit.</div>
<div class="result-line">Water restored tonight; old pump retained</div>
</button>
<button
class="choice"
data-option="defer"
style="--accent:#fb7185"
aria-pressed="false"
>
<div class="choice-top">
<span class="letter">C</span>
<span class="choice-title">Isolate & defer</span>
</div>
<div class="metrics">
<div class="metric"><b>10 min</b><span>Work now</span></div>
<div class="metric"><b>0.00 kg</b><span>New material</span></div>
</div>
<div class="parts">Uses no parts. A future repair remains necessary.</div>
<div class="result-line">Water off for about 18 hours</div>
</button>
</div>
</section>
<div id="hint">
<span>Drag to orbit · Scroll to zoom</span>
<kbd>R</kbd><span>reset</span>
</div>
<div id="labels" aria-hidden="true">
<div id="labelSeal" class="world-label option-label active"
style="--label-color:#f59e0b">A · Gasket</div>
<div id="labelReplace" class="world-label option-label"
style="--label-color:#38bdf8">B · Pump</div>
<div id="labelDefer" class="world-label option-label"
style="--label-color:#fb7185">C · Isolate</div>
<div id="labelSink" class="world-label">Sink + booster pump</div>
<div id="labelStock" class="world-label">Parts on hand</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scenario data
// ------------------------------------------------------------
const options = {
seal: {
letter: "A",
title: "A — Gasket repair",
time: 45,
material: 0.12,
parts: "1 gasket",
used: { pump: 0, gasket: 1, seal: 0 },
color: 0xf59e0b,
outcome:
"The gasket is replaced and the original pump remains in service.",
tradeoff:
"This restores water with little new material, but the suspected pump wear and possible repeat failure remain unresolved."
},
replace: {
letter: "B",
title: "B — Replace pump",
time: 100,
material: 2.40,
parts: "1 pump, 1 gasket, and 1 seal kit",
used: { pump: 1, gasket: 1, seal: 1 },
color: 0x38bdf8,
outcome:
"A new pump assembly is installed, and the removed pump is retained for inspection or parts recovery.",
tradeoff:
"This addresses the uncertain component but takes 55 more minutes and uses 2.28 kg more new material than the gasket repair."
},
defer: {
letter: "C",
title: "C — Isolate & defer",
time: 10,
material: 0,
parts: "no parts",
used: { pump: 0, gasket: 0, seal: 0 },
color: 0xfb7185,
outcome:
"The supply valve is isolated, stopping the leak without beginning a repair.",
tradeoff:
"This uses no new material and the least work now, but the household loses water service and still needs a future repair."
}
};
const reducedMotion =
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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(0x08111f);
scene.fog = new THREE.Fog(0x08111f, 11, 25);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
60
);
const ambient = new THREE.HemisphereLight(0xb8dcff, 0x182033, 1.8);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff1d6, 3.2);
keyLight.position.set(-4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const blueLight = new THREE.PointLight(0x38bdf8, 18, 8, 2);
blueLight.position.set(-1.5, 3.2, -1.5);
scene.add(blueLight);
const orangeLight = new THREE.PointLight(0xf59e0b, 10, 7, 2);
orangeLight.position.set(3.5, 2.5, 1.6);
scene.add(orangeLight);
// ------------------------------------------------------------
// Voxel construction helpers
// ------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function standardMaterial(color, metalness = 0, roughness = 0.8) {
const key = `${color}-${metalness}-${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({ color, metalness, roughness })
);
}
return materialCache.get(key);
}
function box(
parent,
x, y, z,
width, height, depth,
color,
overrideMaterial = null
) {
const mesh = new THREE.Mesh(
cubeGeometry,
overrideMaterial || standardMaterial(color)
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Floor: an instanced field of individual voxel blocks.
const floorGeometry = new THREE.BoxGeometry(1, 1, 1);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
vertexColors: true
});
const columns = 14;
const rows = 10;
const floor = new THREE.InstancedMesh(
floorGeometry,
floorMaterial,
columns * rows
);
const matrixHelper = new THREE.Object3D();
const floorColor = new THREE.Color();
let instance = 0;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
matrixHelper.position.set(
(col - (columns - 1) / 2) * 0.84,
-0.12,
(row - (rows - 1) / 2) * 0.73 - 0.2
);
matrixHelper.scale.set(0.81, 0.18, 0.70);
matrixHelper.updateMatrix();
floor.setMatrixAt(instance, matrixHelper.matrix);
const shade = (row + col) % 2 === 0 ? 0x15243a : 0x192b42;
floorColor.set(shade);
floor.setColorAt(instance, floorColor);
instance++;
}
}
floor.receiveShadow = true;
scene.add(floor);
// Back wall assembled from visible blocks.
const wallGroup = new THREE.Group();
scene.add(wallGroup);
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 13; col++) {
const offset = row % 2 ? 0.48 : 0;
box(
wallGroup,
(col - 6) * 1.02 + offset,
0.55 + row * 0.82,
-3.55,
0.98,
0.78,
0.24,
(row + col) % 3 === 0 ? 0x293a50 : 0x223248
);
}
}
// Counter and sink station.
const station = new THREE.Group();
scene.add(station);
// Cabinet supports and open under-sink area.
box(station, -3.15, 1.05, -2.35, 0.28, 2.1, 1.55, 0x6d4b36);
box(station, 0.12, 1.05, -2.35, 0.28, 2.1, 1.55, 0x6d4b36);
box(station, -1.52, 0.17, -2.45, 3.45, 0.24, 1.35, 0x5b4032);
box(station, -1.52, 1.05, -3.03, 3.45, 1.75, 0.16, 0x674938);
// Counter slab.
box(station, -1.52, 2.08, -1.72, 3.75, 0.28, 1.95, 0xb57c4f);
// Voxel sink basin.
const steel = standardMaterial(0xa8bac9, 0.62, 0.34);
box(station, -1.77, 2.26, -1.64, 1.40, 0.13, 1.12, 0x92a6b8, steel);
box(station, -2.48, 2.43, -1.64, 0.13, 0.34, 1.14, 0x9eb0bf, steel);
box(station, -1.06, 2.43, -1.64, 0.13, 0.34, 1.14, 0x9eb0bf, steel);
box(station, -1.77, 2.43, -2.16, 1.42, 0.34, 0.13, 0x9eb0bf, steel);
box(station, -1.77, 2.43, -1.11, 1.42, 0.34, 0.13, 0x9eb0bf, steel);
// Faucet made only from blocks.
box(station, -1.78, 2.58, -2.12, 0.18, 0.72, 0.18, 0xb9c8d2, steel);
box(station, -1.78, 2.90, -1.86, 0.18, 0.18, 0.62, 0xb9c8d2, steel);
box(station, -1.78, 2.78, -1.57, 0.18, 0.25, 0.18, 0xb9c8d2, steel);
box(station, -2.03, 2.64, -2.12, 0.38, 0.12, 0.14, 0x7d909f, steel);
// Pipe path under the sink.
box(station, -1.40, 1.58, -1.82, 0.18, 0.82, 0.18, 0x8799a7, steel);
box(station, -1.40, 1.98, -1.82, 0.18, 0.18, 0.18, 0x8799a7, steel);
box(station, -1.40, 1.18, -1.82, 0.20, 0.18, 0.20, 0xf59e0b);
// Valve and warning lamp.
const warningMaterial = new THREE.MeshStandardMaterial({
color: 0xfb7185,
emissive: 0xfb7185,
emissiveIntensity: 0.15
});
box(station, -1.06, 1.24, -1.82, 0.18, 0.18, 0.48, 0x6e8190, steel);
box(station, -1.06, 1.24, -1.58, 0.22, 0.22, 0.18, 0xfb7185, warningMaterial);
// ------------------------------------------------------------
// Pump assemblies
// ------------------------------------------------------------
function buildPump() {
const group = new THREE.Group();
const blue = standardMaterial(0x2584c5, 0.35, 0.46);
const red = standardMaterial(0xe85d75, 0.28, 0.48);
const dark = standardMaterial(0x334155, 0.42, 0.55);
box(group, 0, 0.20, 0, 0.70, 0.58, 0.68, 0x2584c5, blue);
box(group, 0.54, 0.20, 0, 0.44, 0.44, 0.48, 0xe85d75, red);
box(group, 0, 0.63, 0, 0.18, 0.46, 0.18, 0x94a3b8, steel);
box(group, -0.22, -0.15, 0, 0.18, 0.18, 0.58, 0x334155, dark);
box(group, 0.22, -0.15, 0, 0.18, 0.18, 0.58, 0x334155, dark);
box(group, 0.32, 0.42, 0.29, 0.16, 0.16, 0.08, 0xfde68a);
return group;
}
const oldPump = buildPump();
oldPump.position.set(-1.40, 0.47, -1.83);
scene.add(oldPump);
const newPump = buildPump();
newPump.position.copy(oldPump.position);
newPump.visible = false;
scene.add(newPump);
// Recovery bin for the removed pump.
const recoveryBin = new THREE.Group();
recoveryBin.position.set(4.15, 0.05, -0.55);
scene.add(recoveryBin);
box(recoveryBin, 0, 0.34, 0, 1.15, 0.68, 1.05, 0x334155);
box(recoveryBin, 0, 0.70, 0, 1.22, 0.12, 1.12, 0x64748b);
box(recoveryBin, -0.50, 0.38, 0.56, 0.14, 0.58, 0.12, 0x475569);
box(recoveryBin, 0.50, 0.38, 0.56, 0.14, 0.58, 0.12, 0x475569);
box(recoveryBin, 0, 0.38, 0.56, 1.05, 0.58, 0.12, 0x475569);
const oldPumpInBin = buildPump();
oldPumpInBin.position.set(0, 0.62, 0);
oldPumpInBin.rotation.y = -0.35;
oldPumpInBin.scale.setScalar(0.72);
oldPumpInBin.visible = false;
recoveryBin.add(oldPumpInBin);
// ------------------------------------------------------------
// Parts shelf
// ------------------------------------------------------------
const shelf = new THREE.Group();
shelf.position.set(2.65, 0, -2.58);
scene.add(shelf);
box(shelf, -1.0, 1.25, 0, 0.14, 2.55, 0.90, 0x59677a);
box(shelf, 1.0, 1.25, 0, 0.14, 2.55, 0.90, 0x59677a);
box(shelf, 0, 0.48, 0, 2.15, 0.15, 1.0, 0x718096);
box(shelf, 0, 1.48, 0, 2.15, 0.15, 1.0, 0x718096);
box(shelf, 0, 2.48, 0, 2.15, 0.15, 1.0, 0x718096);
function buildGasket() {
const group = new THREE.Group();
const gasketMaterial = new THREE.MeshStandardMaterial({
color: 0x475569,
roughness: 0.98
});
const locations = [
[-0.19, 0], [0.19, 0],
[-0.19, 0.19], [0.19, 0.19],
[-0.19, -0.19], [0.19, -0.19],
[0, 0.19], [0, -0.19]
];
for (const [x, z] of locations) {
box(group, x, 0, z, 0.13, 0.13, 0.13, 0x475569, gasketMaterial);
}
return group;
}
const gasketRings = [];
for (let i = 0; i < 2; i++) {
const gasket = buildGasket();
gasket.position.set(-0.50 + i * 0.72, 0.62, 0.18);
shelf.add(gasket);
gasketRings.push(gasket);
}
// Pump stock box, built from blocks.
const pumpStock = new THREE.Group();
pumpStock.position.set(-0.38, 1.70, 0.05);
shelf.add(pumpStock);
box(pumpStock, 0, 0, 0, 0.82, 0.30, 0.64, 0x256da0);
box(pumpStock, 0.26, 0.03, 0, 0.34, 0.34, 0.52, 0xe85d75);
box(pumpStock, 0, 0.25, 0, 0.18, 0.25, 0.18, 0xa8bac9, steel);
// Seal-kit stock, also made from cubes.
const sealStock = new THREE.Group();
sealStock.position.set(0.46, 2.62, 0.10);
shelf.add(sealStock);
box(sealStock, 0, 0.02, 0, 0.78, 0.16, 0.58, 0x65a30d);
box(sealStock, -0.18, 0.18, 0, 0.20, 0.18, 0.20, 0xd9f99d);
box(sealStock, 0.16, 0.17, -0.08, 0.16, 0.14, 0.22, 0xecfccb);
box(sealStock, 0.16, 0.17, 0.16, 0.16, 0.14, 0.16, 0xecfccb);
// ------------------------------------------------------------
// Decision plinths
// ------------------------------------------------------------
const clickableMeshes = [];
const optionVisuals = {};
function buildOptionPlinth(key, x, color, iconType) {
const group = new THREE.Group();
group.position.set(x, 0, 2.10);
scene.add(group);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x25354b,
roughness: 0.88
});
const accentMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.16,
roughness: 0.55
});
box(group, 0, 0.08, 0, 1.65, 0.16, 1.10, 0x25354b, platformMaterial);
// Four square corner markers.
for (const sx of [-0.68, 0.68]) {
for (const sz of [-0.39, 0.39]) {
box(group, sx, 0.21, sz, 0.20, 0.09, 0.20, color, accentMaterial);
}
}
if (iconType === "seal") {
const positions = [
[-0.22, 0], [0.22, 0],
[-0.22, 0.22], [0.22, 0.22],
[-0.22, -0.22], [0.22, -0.22],
[0, 0.22], [0, -0.22]
];
for (const [ix, iz] of positions) {
box(group, ix, 0.42, iz, 0.14, 0.28, 0.14, color, accentMaterial);
}
} else if (iconType === "replace") {
box(group, 0, 0.42, -0.08, 0.50, 0.42, 0.48, color, accentMaterial);
box(group, 0.29, 0.38, -0.08, 0.28, 0.30, 0.38, 0xfb7185, accentMaterial);
box(group, 0, 0.70, -0.08, 0.18, 0.28, 0.18, 0xcbd5e1, accentMaterial);
} else {
box(group, 0, 0.38, 0, 0.36, 0.36, 0.36, color, accentMaterial);
box(group, 0, 0.58, 0, 0.72, 0.14, 0.14, 0xcbd5e1, accentMaterial);
box(group, 0, 0.40, 0, 0.14, 0.62, 0.14, 0xcbd5e1, accentMaterial);
}
group.traverse((object) => {
if (object.isMesh) {
object.userData.option = key;
clickableMeshes.push(object);
}
});
optionVisuals[key] = {
group,
accentMaterial,
platformMaterial,
baseColor: new THREE.Color(color)
};
}
buildOptionPlinth("seal", -2.9, 0xf59e0b, "seal");
buildOptionPlinth("replace", 0, 0x38bdf8, "replace");
buildOptionPlinth("defer", 2.9, 0xfb7185, "defer");
// ------------------------------------------------------------
// Water, leak, and flow blocks
// ------------------------------------------------------------
const leakMaterial = new THREE.MeshStandardMaterial({
color: 0x38bdf8,
emissive: 0x0e7490,
emissiveIntensity: 0.65,
transparent: true,
opacity: 0.9
});
const flowMaterial = new THREE.MeshStandardMaterial({
color: 0x38bdf8,
emissive: 0x0284c7,
emissiveIntensity: 0.75,
transparent: true,
opacity: 0.82
});
const pipeWaterMaterial = new THREE.MeshStandardMaterial({
color: 0x38bdf8,
emissive: 0x075985,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.15
});
const leakDrops = [];
for (let i = 0; i < 12; i++) {
const drop = box(
scene,
-1.25,
1.0,
-1.75,
0.10,
0.14,
0.10,
0x38bdf8,
leakMaterial
);
leakDrops.push(drop);
}
// Small pooled blocks under the leak.
for (let i = 0; i < 7; i++) {
box(
scene,
-1.42 + (i % 4) * 0.16,
0.01,
-1.58 + Math.floor(i / 4) * 0.18,
0.20,
0.035,
0.16,
0x0ea5e9,
leakMaterial
);
}
const flowDrops = [];
for (let i = 0; i < 8; i++) {
const drop = box(
scene,
-1.78,
2.70,
-1.57,
0.09,
0.13,
0.09,
0x38bdf8,
flowMaterial
);
flowDrops.push(drop);
}
box(
scene,
-1.40,
1.74,
-1.82,
0.11,
0.72,
0.11,
0x38bdf8,
pipeWaterMaterial
);
// ------------------------------------------------------------
// UI and selection state
// ------------------------------------------------------------
const cards = [...document.querySelectorAll(".choice")];
const labels = {
seal: document.querySelector("#labelSeal"),
replace: document.querySelector("#labelReplace"),
defer: document.querySelector("#labelDefer")
};
const outcomeTitle = document.querySelector("#outcomeTitle");
const outcomeText = document.querySelector("#outcomeText");
const tradeoffText = document.querySelector("#tradeoffText");
const statusText = document.querySelector("#statusText");
const progressFill = document.querySelector("#progressFill");
let selected = "seal";
let progress = 0;
let lastStatus = "";
function updateInventory() {
const used = options[selected].used;
document.querySelector("#pumpStock").textContent = 1 - used.pump;
document.querySelector("#gasketStock").textContent = 2 - used.gasket;
document.querySelector("#sealStock").textContent = 1 - used.seal;
gasketRings[0].visible = used.gasket === 0;
gasketRings[1].visible = true;
pumpStock.visible = used.pump === 0;
sealStock.visible = used.seal === 0;
}
function selectOption(key) {
if (!options[key]) return;
selected = key;
progress = reducedMotion ? 1 : 0;
lastStatus = "";
const data = options[key];
cards.forEach((card) => {
const active = card.dataset.option === key;
card.classList.toggle("active", active);
card.setAttribute("aria-pressed", String(active));
});
for (const [optionKey, visual] of Object.entries(optionVisuals)) {
const active = optionKey === key;
visual.accentMaterial.color.copy(visual.baseColor);
visual.accentMaterial.emissive.copy(visual.baseColor);
visual.accentMaterial.emissiveIntensity = active ? 0.62 : 0.08;
visual.platformMaterial.color.copy(visual.baseColor);
visual.platformMaterial.color.multiplyScalar(active ? 0.36 : 0.13);
labels[optionKey].classList.toggle("active", active);
}
outcomeTitle.textContent = data.title;
outcomeText.textContent = data.outcome;
tradeoffText.textContent = data.tradeoff;
updateInventory();
}
cards.forEach((card) => {
card.addEventListener("click", () => selectOption(card.dataset.option));
});
// ------------------------------------------------------------
// Direct camera controls — no addons
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 1.45, -0.75);
const orbit = {
theta: 0.58,
phi: 1.02,
radius: 11.2
};
function updateCamera() {
const horizontal = Math.sin(orbit.phi) * orbit.radius;
camera.position.set(
target.x + horizontal * Math.sin(orbit.theta),
target.y + Math.cos(orbit.phi) * orbit.radius,
target.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
function resetCamera() {
orbit.theta = 0.58;
orbit.phi = 1.02;
orbit.radius = 11.2;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let travel = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
travel = 0;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
travel += Math.abs(dx) + Math.abs(dy);
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.007;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.006,
0.38,
1.30
);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (travel < 6) {
const pointer = new THREE.Vector2(
(event.clientX / window.innerWidth) * 2 - 1,
-(event.clientY / window.innerHeight) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickableMeshes, false);
if (hits.length) {
selectOption(hits[0].object.userData.option);
}
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
7,
18
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.key === "ArrowLeft") {
orbit.theta -= 0.08;
updateCamera();
}
if (event.key === "ArrowRight") {
orbit.theta += 0.08;
updateCamera();
}
if (event.key === "ArrowUp") {
orbit.phi = Math.max(0.38, orbit.phi - 0.06);
updateCamera();
}
if (event.key === "ArrowDown") {
orbit.phi = Math.min(1.30, orbit.phi + 0.06);
updateCamera();
}
});
// ------------------------------------------------------------
// Screen-space labels
// ------------------------------------------------------------
const labelAnchors = [
{ element: labels.seal, position: new THREE.Vector3(-2.9, 0.72, 2.1) },
{ element: labels.replace, position: new THREE.Vector3(0, 0.72, 2.1) },
{ element: labels.defer, position: new THREE.Vector3(2.9, 0.72, 2.1) },
{ element: document.querySelector("#labelSink"),
position: new THREE.Vector3(-1.7, 3.25, -1.7) },
{ element: document.querySelector("#labelStock"),
position: new THREE.Vector3(2.65, 3.12, -2.58) }
];
function updateLabels() {
for (const item of labelAnchors) {
const projected = item.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
item.element.style.display = visible ? "block" : "none";
item.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
item.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
function updateScenario(dt, elapsedSeconds) {
const data = options[selected];
const animationDuration =
selected === "replace" ? 6.2 :
selected === "seal" ? 4.4 :
1.8;
if (progress < 1) {
progress = Math.min(1, progress + dt / animationDuration);
}
const simulatedMinutes = Math.min(
data.time,
Math.floor(data.time * progress)
);
progressFill.style.width = `${progress * 100}%`;
if (selected === "seal") {
leakMaterial.opacity = Math.max(0, 0.9 - progress * 1.25);
pipeWaterMaterial.opacity = 0.15 + progress * 0.55;
flowMaterial.opacity = 0.82;
oldPump.visible = true;
newPump.visible = false;
oldPumpInBin.visible = false;
warningMaterial.emissiveIntensity = 0.10;
statusText.textContent =
progress < 0.92
? `Replacing gasket and testing — ${simulatedMinutes} of 45 min simulated`
: "Repair complete — water service restored; pump condition remains uncertain";
}
if (selected === "replace") {
const swapped = progress >= 0.43;
oldPump.visible = !swapped;
newPump.visible = swapped;
oldPumpInBin.visible = swapped;
leakMaterial.opacity = Math.max(0, 0.9 - progress * 1.35);
pipeWaterMaterial.opacity = 0.15 + progress * 0.55;
flowMaterial.opacity = 0.82;
warningMaterial.emissiveIntensity = 0.10;
statusText.textContent =
progress < 0.43
? `Removing old assembly — ${simulatedMinutes} of 100 min simulated`
: progress < 0.93
? `Installing new pump — ${simulatedMinutes} of 100 min simulated`
: "Repair complete — new pump installed; old unit retained for recovery";
}
if (selected === "defer") {
const isolated = progress >= 0.42;
leakMaterial.opacity = Math.max(0, 0.9 - progress * 2.2);
pipeWaterMaterial.opacity = isolated ? 0.04 : 0.15;
flowMaterial.opacity = 0;
warningMaterial.emissiveIntensity =
isolated ? 0.45 + Math.sin(elapsedSeconds * 4) * 0.25 : 0.1;
oldPump.visible = true;
newPump.visible = false;
oldPumpInBin.visible = false;
statusText.textContent = isolated
? "Water safely isolated — no parts consumed; a future repair remains"
: `Closing and testing the valve — ${simulatedMinutes} of 10 min simulated`;
}
if (statusText.textContent !== lastStatus) {
lastStatus = statusText.textContent;
}
// Leak cube animation.
for (let i = 0; i < leakDrops.length; i++) {
const phase = (elapsedSeconds * 1.55 + i * 0.083) % 1;
leakDrops[i].position.y = 1.05 - phase * 0.92;
leakDrops[i].position.x = -1.25 + Math.sin(i * 2.4 + phase * 5) * 0.12;
leakDrops[i].position.z = -1.75 + Math.cos(i * 1.7 + phase * 4) * 0.08;
}
// Faucet flow animation.
const flowVisible =
(selected === "seal" && progress >= 0.88) ||
(selected === "replace" && progress >= 0.91);
for (let i = 0; i < flowDrops.length; i++) {
flowDrops[i].visible = flowVisible;
if (flowVisible) {
const phase = (elapsedSeconds * 1.8 + i * 0.12) % 1;
flowDrops[i].position.y = 2.72 - phase * 0.38;
flowDrops[i].position.x = -1.78 + Math.sin(i * 2.1) * 0.035;
flowDrops[i].position.z = -1.57 + Math.cos(i * 1.4) * 0.025;
}
}
}
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
updateScenario(dt, now / 1000);
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetCamera();
selectOption("seal");
updateCamera();
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => document.querySelector("#loading").remove(), 300);
});
</script>
</body>
</html>
```