Prompt specification
Build or customize the Three.js 3D scene "Community Object Repair Exhibition" 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: Community Object Repair Exhibition
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-object-repair-exhibition-x3291
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring wear, repair, and the continued use of crafted objects. Build a display of original everyday objects before and after different repairs. Explain which function was restored and preserve visible evidence of earlier use. Voxel style.
Working Three.js Starter (community-object-repair-exhibition-x3291):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Second Life — Everyday Repair Archive</title>
<style>
:root {
--paper: #eee5d4;
--ink: #252824;
--muted: #6d6d63;
--line: rgba(37, 40, 36, 0.17);
--before: #a6543f;
--after: #52755c;
--panel: rgba(243, 237, 224, 0.95);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8cebb;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
radial-gradient(circle at 48% 43%, transparent 45%, rgba(55, 43, 29, 0.1) 100%),
linear-gradient(180deg, rgba(255, 250, 238, 0.08), transparent 35%);
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.scene-tag {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
padding: 6px 9px;
border: 1px solid rgba(37, 40, 36, 0.25);
color: var(--ink);
background: rgba(244, 239, 226, 0.88);
box-shadow: 0 4px 12px rgba(45, 34, 22, 0.1);
backdrop-filter: blur(5px);
}
.scene-tag.before {
color: #743a2e;
border-color: rgba(166, 84, 63, 0.55);
}
.scene-tag.after {
color: #355e43;
border-color: rgba(82, 117, 92, 0.65);
}
.scene-tag.name {
padding: 7px 11px;
color: #f5f0e5;
background: rgba(37, 40, 36, 0.82);
border-color: rgba(255, 255, 255, 0.15);
letter-spacing: 0.09em;
}
header {
position: fixed;
z-index: 6;
top: 25px;
left: 28px;
right: 388px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.brand {
max-width: 540px;
text-shadow: 0 1px 12px rgba(242, 232, 212, 0.85);
}
.eyebrow,
.card-index,
.detail-label,
.state-label {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand .eyebrow {
color: #625f53;
margin-bottom: 7px;
}
h1 {
margin: 0;
font-size: clamp(32px, 4.5vw, 68px);
line-height: 0.9;
letter-spacing: -0.065em;
font-weight: 900;
}
h1 span {
color: var(--after);
}
.brand p {
margin: 12px 0 0;
max-width: 430px;
color: #56564e;
font-size: 14px;
line-height: 1.45;
}
#reset-view {
pointer-events: auto;
border: 1px solid rgba(37, 40, 36, 0.3);
background: rgba(244, 239, 226, 0.76);
color: var(--ink);
padding: 10px 13px;
cursor: pointer;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
#reset-view:hover {
background: rgba(255, 252, 244, 0.98);
}
#ledger {
position: fixed;
z-index: 7;
top: 18px;
right: 18px;
bottom: 18px;
width: 352px;
padding: 22px;
overflow-y: auto;
overscroll-behavior: contain;
background: var(--panel);
border: 1px solid rgba(37, 40, 36, 0.18);
box-shadow: 0 18px 55px rgba(49, 36, 23, 0.17);
backdrop-filter: blur(13px);
}
#ledger > .eyebrow {
color: var(--after);
}
#ledger h2 {
margin: 8px 0 6px;
font-size: 29px;
line-height: 1;
letter-spacing: -0.045em;
}
.ledger-intro {
margin: 0 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#cards {
display: grid;
gap: 8px;
}
.card {
width: 100%;
display: grid;
grid-template-columns: 28px 1fr;
gap: 9px;
padding: 12px;
text-align: left;
color: var(--ink);
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.27);
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.card:hover {
transform: translateX(-2px);
border-color: rgba(37, 40, 36, 0.38);
}
.card.active {
background: rgba(255, 255, 255, 0.72);
border-color: var(--after);
box-shadow: inset 3px 0 0 var(--after);
}
.card-index {
color: var(--after);
padding-top: 2px;
}
.card-title {
display: block;
font-size: 14px;
font-weight: 800;
margin-bottom: 3px;
}
.card-copy {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.detail {
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.detail-top {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
margin-bottom: 13px;
}
#detail-pair {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.state-switch {
display: flex;
padding: 2px;
border: 1px solid var(--line);
background: rgba(37, 40, 36, 0.05);
}
.state-switch button {
border: 0;
padding: 6px 8px;
cursor: pointer;
color: var(--muted);
background: transparent;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.state-switch button.active {
color: white;
background: var(--ink);
}
#detail-repair {
margin: 0 0 15px;
font-size: 14px;
line-height: 1.48;
font-weight: 650;
}
.detail-block {
padding: 12px;
margin-top: 9px;
background: rgba(82, 117, 92, 0.1);
border-left: 3px solid var(--after);
}
.detail-block.before-block {
background: rgba(166, 84, 63, 0.09);
border-left-color: var(--before);
}
.detail-label {
display: block;
margin-bottom: 5px;
color: var(--after);
}
.before-block .detail-label {
color: var(--before);
}
.detail-block strong {
display: block;
font-size: 12px;
line-height: 1.45;
}
.history-block {
margin-top: 14px;
padding-top: 13px;
border-top: 1px dashed var(--line);
}
.history-block .detail-label {
color: #7d6547;
}
#detail-history {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.legend {
position: fixed;
z-index: 5;
left: 28px;
bottom: 24px;
display: flex;
align-items: center;
gap: 16px;
padding: 9px 12px;
color: #55574f;
background: rgba(244, 239, 226, 0.7);
border: 1px solid rgba(37, 40, 36, 0.14);
backdrop-filter: blur(8px);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.dot {
width: 8px;
height: 8px;
background: var(--before);
}
.dot.after {
background: var(--after);
}
@media (max-width: 1100px) {
header {
right: 28px;
}
#ledger {
top: auto;
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
height: 248px;
display: grid;
grid-template-columns: 260px 1fr 1.2fr;
gap: 16px;
padding: 16px;
overflow: hidden;
}
#ledger > .eyebrow,
#ledger > h2,
.ledger-intro {
grid-column: 1;
}
#cards {
grid-column: 1;
overflow-y: auto;
}
.detail {
grid-column: 2 / 4;
grid-row: 1 / 5;
margin: 0;
padding: 0 0 0 16px;
border-top: 0;
border-left: 1px solid var(--line);
overflow-y: auto;
}
.legend {
bottom: 275px;
}
}
@media (max-width: 700px) {
header {
top: 17px;
left: 18px;
right: 18px;
}
.brand p {
display: none;
}
.brand .eyebrow {
font-size: 8px;
}
h1 {
font-size: 39px;
}
#reset-view {
padding: 9px;
font-size: 8px;
}
#ledger {
height: 245px;
display: block;
padding: 14px;
}
#ledger > .eyebrow,
#ledger > h2,
.ledger-intro {
display: none;
}
#cards {
grid-template-columns: repeat(3, 1fr);
display: grid;
overflow: visible;
margin-bottom: 12px;
}
.card {
grid-template-columns: 1fr;
padding: 9px;
}
.card-copy {
display: none;
}
.detail {
margin: 0;
padding: 12px 0 0;
border-left: 0;
border-top: 1px solid var(--line);
overflow-y: auto;
}
.legend {
display: none;
}
.scene-tag.name {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive voxel museum display showing three everyday objects before and after repair"
></canvas>
<div id="vignette"></div>
<div id="labels" aria-hidden="true"></div>
<header>
<div class="brand">
<div class="eyebrow">An everyday repair archive · 01—03</div>
<h1>SECOND <span>LIFE</span></h1>
<p>
Original objects, visible wear, and careful repairs that return useful
function without erasing the evidence of earlier use.
</p>
</div>
<button id="reset-view" type="button">Reset view</button>
</header>
<aside id="ledger" aria-label="Repair ledger">
<div class="eyebrow">Repair ledger</div>
<h2>Use, damage, repair.</h2>
<p class="ledger-intro">
Select an exhibit. Each repair restores a practical function while keeping
the object's patina, damage history, and signs of continued use.
</p>
<div id="cards"></div>
<section class="detail" aria-live="polite">
<div class="detail-top">
<div id="detail-pair">Pair 01 · Joinery</div>
<div class="state-switch" aria-label="Select before or after state">
<button type="button" data-state="before">Before</button>
<button type="button" data-state="after" class="active">After</button>
</div>
</div>
<p id="detail-repair"></p>
<div id="function-block" class="detail-block">
<span id="function-label" class="detail-label">Function restored</span>
<strong id="detail-function"></strong>
</div>
<div class="history-block">
<span class="detail-label">Earlier use, kept visible</span>
<p id="detail-history"></p>
</div>
</section>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="dot"></span>Before repair</div>
<div class="legend-item"><span class="dot after"></span>After repair</div>
<div>Drag: orbit · Shift-drag: pan · Wheel: zoom · Select: inspect</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* -----------------------------------------------------------------------
DATA AND INTERFACE
------------------------------------------------------------------------ */
const exhibits = {
chair: {
number: "01",
title: "Kitchen chair",
type: "Joinery / pegged tenon",
short: "A loose rear-leg joint was reset and pegged.",
center: -6,
before: {
repair:
"A fatigue split opened the rear-right leg tenon, allowing the seat to rack.",
function:
"Support is compromised: the chair should not be sat on until the joint is secured.",
history:
"The polished seat center, chipped teal paint, scratches, and old nail holes remain."
},
after: {
repair:
"The tenon was reset, bridged with an oak splice, and locked with two wooden pegs.",
function:
"The chair bears weight again and no longer racks under a seated load.",
history:
"Original paint loss, seat shine, dents, and fastener scars remain visible around the repair."
}
},
kettle: {
number: "02",
title: "Enamel kettle",
type: "Band / copper rivets",
short: "A separated handle was rejoined with a copper splice.",
center: 0,
before: {
repair:
"The enamel handle separated at its upper joint, and the bent section could open further.",
function:
"The lifting grip is unsafe, so controlled lifting and pouring are compromised.",
history:
"Old enamel chips, soot, water marks, and a shallow body dent are retained."
},
after: {
repair:
"The handle was realigned and bridged by a copper collar secured with two rivets.",
function:
"The kettle can be lifted, tilted, and poured without the handle opening.",
history:
"The repaired handle is new, but the chipped enamel, dark heat staining, and body dent remain."
}
},
lamp: {
number: "03",
title: "Task lamp",
type: "Electrical / cord and switch",
short: "A cut cord and failed switch were replaced and tested.",
center: 6,
before: {
repair:
"The cloth cord was severed near the base, and the original switch no longer responded.",
function:
"Electrical power and switching are lost, leaving the lamp inoperable.",
history:
"Faded blue paint, scratches on the base, dents, and old switch marks remain."
},
after: {
repair:
"The damaged lead was replaced with a braided cord and a new inline switch was fitted.",
function:
"The lamp lights reliably and its switch gives a clear, positive action.",
history:
"The new cord and switch contrast with the retained scratches, faded paint, and worn base."
}
}
};
const exhibitOrder = ["chair", "kettle", "lamp"];
const cardRoot = document.getElementById("cards");
const stateButtons = [...document.querySelectorAll(".state-switch button")];
let selectedExhibit = "chair";
let selectedState = "after";
for (const id of exhibitOrder) {
const item = exhibits[id];
const button = document.createElement("button");
button.type = "button";
button.className = "card";
button.dataset.exhibit = id;
button.innerHTML = `
<span class="card-index">${item.number}</span>
<span>
<span class="card-title">${item.title}</span>
<span class="card-copy">${item.short}</span>
</span>
`;
button.addEventListener("click", () => {
selectExhibit(id, "after", true);
});
cardRoot.appendChild(button);
}
function updateInterface() {
const item = exhibits[selectedExhibit];
const state = item[selectedState];
document.querySelectorAll(".card").forEach((card) => {
card.classList.toggle("active", card.dataset.exhibit === selectedExhibit);
});
stateButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.state === selectedState);
});
document.getElementById("detail-pair").textContent =
`Pair ${item.number} · ${item.type}`;
document.getElementById("detail-repair").textContent = state.repair;
document.getElementById("detail-function").textContent = state.function;
document.getElementById("detail-history").textContent = state.history;
document.getElementById("function-label").textContent =
selectedState === "after" ? "Function restored" : "Function at risk";
document.getElementById("function-block").classList.toggle(
"before-block",
selectedState === "before"
);
marker.position.x =
item.center + (selectedState === "after" ? 1.1 : -1.1);
marker.material.color.setHex(
selectedState === "after" ? 0x52755c : 0xa6543f
);
marker.material.emissive.setHex(
selectedState === "after" ? 0x193b25 : 0x45170e
);
}
stateButtons.forEach((button) => {
button.addEventListener("click", () => {
selectedState = button.dataset.state;
updateInterface();
});
});
/* -----------------------------------------------------------------------
THREE.JS SETUP
------------------------------------------------------------------------ */
const canvas = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8cebb);
scene.fog = new THREE.Fog(0xd8cebb, 26, 48);
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.1;
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xfff3d7, 0x6b7169, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe9c1, 4.1);
keyLight.position.set(-8, 14, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d8db, 1.2);
fillLight.position.set(12, 8, 5);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
const mat = {
floor: material(0xb9ad96),
floorLine: material(0x9f937e),
wall: material(0xe5dccb),
wallPanel: material(0xd9cfbd),
wallPanelAlt: material(0xe0d5c2),
plinth: material(0xc9b797),
plinthTop: material(0xdfcfb3),
plinthDark: material(0x786a58),
padBefore: material(0xd1c0ac),
padAfter: material(0xb8c7af),
teal: material(0x547b76),
tealDark: material(0x3f625e),
rawWood: material(0xb68450),
oldWood: material(0x6d4b35),
woodDark: material(0x49362b),
enamel: material(0x4f7458, { roughness: 0.63 }),
enamelDark: material(0x38553f, { roughness: 0.67 }),
copper: material(0xb97746, { roughness: 0.48, metalness: 0.52 }),
brass: material(0xc39a53, { roughness: 0.4, metalness: 0.62 }),
soot: material(0x302d29),
cream: material(0xe1d2b6),
lampBlue: material(0x5f788a),
lampBlueDark: material(0x435d6d),
bulbOff: material(0xb4a98c),
bulbOn: material(0xffe3a0, {
emissive: 0xffb84d,
emissiveIntensity: 2.6
}),
wireOld: material(0x35312d),
wireNew: material(0x9e4939),
exposedWire: material(0xb97d3c, {
roughness: 0.45,
metalness: 0.55
}),
white: material(0xeee4cf)
};
function addBox(parent, size, position, mat, options = {}) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] || 0,
options.rotation[1] || 0,
options.rotation[2] || 0
);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
/* -----------------------------------------------------------------------
GALLERY ARCHITECTURE
------------------------------------------------------------------------ */
addBox(scene, [25, 0.4, 14], [0, -0.2, 0], mat.floor);
addBox(scene, [25, 7, 0.35], [0, 3.3, -4.7], mat.wall);
addBox(scene, [0.35, 7, 10], [-12.25, 3.3, 0], mat.wall);
addBox(scene, [24.8, 0.22, 0.18], [0, 0.11, -4.46], mat.plinthDark);
// Voxel floor joints.
for (let x = -10; x <= 10; x += 2.5) {
addBox(
scene,
[0.035, 0.012, 12],
[x, 0.008, 0.4],
mat.floorLine,
{ castShadow: false }
);
}
for (let z = -3.5; z <= 5; z += 2.5) {
addBox(
scene,
[24, 0.012, 0.035],
[0, 0.009, z],
mat.floorLine,
{ castShadow: false }
);
}
// Exhibit wall panels and suspended workshop lights.
for (let i = 0; i < 3; i++) {
const center = (i - 1) * 6;
addBox(
scene,
[4.55, 4.05, 0.12],
[center, 2.16, -4.43],
i === 1 ? mat.wallPanelAlt : mat.wallPanel
);
addBox(
scene,
[4.2, 0.07, 0.16],
[center, 4.04, -4.32],
mat.plinthDark
);
addBox(
scene,
[2.5, 0.1, 0.24],
[center, 5.15, -2.6],
mat.bulbOn,
{ castShadow: false }
);
addBox(
scene,
[3.0, 0.07, 0.32],
[center, 5.22, -2.6],
mat.plinthDark
);
}
// Three long voxel plinths.
for (const id of exhibitOrder) {
const center = exhibits[id].center;
addBox(
scene,
[4.8, 0.48, 2.8],
[center, 0.24, 0],
mat.plinth
);
addBox(
scene,
[4.86, 0.09, 2.86],
[center, 0.49, 0],
mat.plinthTop
);
addBox(
scene,
[4.55, 0.07, 0.06],
[center, 0.4, 1.43],
mat.plinthDark
);
addBox(
scene,
[1.72, 0.025, 2.05],
[center - 1.1, 0.55, 0.05],
mat.padBefore
);
addBox(
scene,
[1.72, 0.025, 2.05],
[center + 1.1, 0.55, 0.05],
mat.padAfter
);
}
const markerMaterial = material(0x52755c, {
emissive: 0x193b25,
emissiveIntensity: 0.75
});
const marker = addBox(
scene,
[0.16, 0.04, 0.16],
[-4.9, 0.575, 0.82],
markerMaterial,
{ castShadow: false }
);
/* -----------------------------------------------------------------------
VOXEL OBJECT BUILDERS
------------------------------------------------------------------------ */
function buildChair(broken) {
const group = new THREE.Group();
// Front and rear legs.
addBox(group, [0.14, 1.1, 0.14], [-0.43, 0.55, 0.32], mat.teal);
addBox(group, [0.14, 1.1, 0.14], [0.43, 0.55, 0.32], mat.teal);
addBox(group, [0.14, 1.1, 0.14], [-0.43, 0.55, -0.32], mat.teal);
if (broken) {
addBox(group, [0.14, 0.55, 0.14], [0.43, 0.275, -0.32], mat.tealDark);
addBox(
group,
[0.145, 0.42, 0.145],
[0.45, 0.95, -0.32],
mat.teal,
{ rotation: [0, 0, -0.035] }
);
// Dark split and loose wood fragments.
addBox(group, [0.15, 0.035, 0.145], [0.43, 0.66, -0.32], mat.woodDark);
addBox(group, [0.09, 0.045, 0.045], [0.65, 0.035, -0.15], mat.rawWood);
addBox(group, [0.055, 0.03, 0.08], [0.58, 0.025, -0.06], mat.rawWood);
} else {
// Painted leg with a deliberately visible raw-wood splice.
addBox(group, [0.14, 0.58, 0.14], [0.43, 0.29, -0.32], mat.teal);
addBox(group, [0.153, 0.22, 0.153], [0.43, 0.69, -0.32], mat.rawWood);
addBox(group, [0.14, 0.32, 0.14], [0.43, 0.96, -0.32], mat.teal);
// Two pegs on the visible face.
addBox(group, [0.055, 0.055, 0.025], [0.43, 0.65, -0.235], mat.oldWood);
addBox(group, [0.055, 0.055, 0.025], [0.43, 0.74, -0.235], mat.oldWood);
}
// Seat, back posts, and slats.
addBox(group, [1.05, 0.14, 0.9], [0, 1.17, 0], mat.teal);
addBox(group, [0.13, 1.05, 0.13], [-0.44, 1.7, -0.39], mat.teal);
addBox(group, [0.13, 1.05, 0.13], [0.44, 1.7, -0.39], mat.teal);
addBox(group, [0.92, 0.17, 0.11], [0, 1.5, -0.39], mat.tealDark);
addBox(group, [0.92, 0.17, 0.11], [0, 1.81, -0.39], mat.teal);
addBox(group, [0.92, 0.17, 0.11], [0, 2.11, -0.39], mat.tealDark);
// Polished, lighter seat center.
addBox(group, [0.46, 0.012, 0.43], [0, 1.247, 0.02], mat.tealDark);
// Scratches and paint chips.
addBox(group, [0.19, 0.014, 0.018], [-0.14, 1.249, 0.18], mat.rawWood);
addBox(group, [0.13, 0.014, 0.016], [0.18, 1.249, -0.08], mat.rawWood);
addBox(group, [0.025, 0.07, 0.13], [-0.5, 1.17, 0.34], mat.rawWood);
addBox(group, [0.06, 0.05, 0.14], [0.5, 1.17, -0.2], mat.rawWood);
addBox(group, [0.08, 0.07, 0.018], [-0.25, 1.5, -0.327], mat.rawWood);
addBox(group, [0.06, 0.055, 0.018], [0.31, 1.81, -0.327], mat.rawWood);
// Old nail holes remain visible.
addBox(group, [0.025, 0.025, 0.015], [-0.31, 1.5, -0.326], mat.woodDark);
addBox(group, [0.025, 0.025, 0.015], [0.31, 1.5, -0.326], mat.woodDark);
addBox(group, [0.025, 0.025, 0.015], [-0.28, 2.11, -0.326], mat.woodDark);
return group;
}
function buildKettle(broken) {
const group = new THREE.Group();
// Stepped enamel body.
addBox(group, [0.9, 0.14, 0.72], [0, 0.08, 0], mat.enamelDark);
addBox(group, [1.08, 0.84, 0.86], [0, 0.56, 0], mat.enamel);
addBox(group, [0.96, 0.15, 0.76], [0, 1.04, 0], mat.enamel);
addBox(group, [0.78, 0.08, 0.62], [0, 1.16, 0], mat.enamelDark);
addBox(group, [0.27, 0.12, 0.23], [0, 1.26, 0], mat.cream);
// Voxel spout.
addBox(
group,
[0.58, 0.22, 0.3],
[-0.69, 0.82, 0],
mat.enamel,
{ rotation: [0, 0, -0.23] }
);
addBox(
group,
[0.28, 0.25, 0.31],
[-0.99, 0.98, 0],
mat.enamel,
{ rotation: [0, 0, -0.31] }
);
addBox(group, [0.035, 0.17, 0.21], [-1.105, 1.02, 0], mat.soot);
// Handle attachment blocks.
addBox(group, [0.56, 0.13, 0.17], [0.38, 0.28, 0], mat.enamelDark);
addBox(group, [0.56, 0.13, 0.17], [0.39, 1.31, 0], mat.enamelDark);
if (broken) {
addBox(group, [0.14, 0.47, 0.17], [0.63, 0.57, 0], mat.enamelDark);
addBox(
group,
[0.14, 0.39, 0.17],
[0.69, 1.15, 0],
mat.enamel,
{ rotation: [0, 0, -0.11] }
);
// Exposed fracture ends.
addBox(group, [0.15, 0.025, 0.18], [0.63, 0.81, 0], mat.brass);
addBox(group, [0.15, 0.025, 0.18], [0.66, 0.96, 0], mat.brass);
} else {
addBox(group, [0.14, 0.47, 0.17], [0.63, 0.57, 0], mat.enamelDark);
addBox(group, [0.14, 0.39, 0.17], [0.63, 1.15, 0], mat.enamelDark);
// Copper repair collar and rivets.
addBox(group, [0.18, 0.29, 0.205], [0.63, 0.885, 0], mat.copper);
addBox(group, [0.055, 0.055, 0.025], [0.63, 0.82, 0.113], mat.brass);
addBox(group, [0.055, 0.055, 0.025], [0.63, 0.95, 0.113], mat.brass);
}
// Retained enamel chips, soot, water marks, and dent.
addBox(group, [0.12, 0.055, 0.018], [-0.26, 0.42, 0.437], mat.rawWood);
addBox(group, [0.06, 0.085, 0.018], [0.24, 0.7, 0.437], mat.rawWood);
addBox(group, [0.22, 0.12, 0.018], [0.15, 0.24, 0.438], mat.soot);
addBox(group, [0.1, 0.18, 0.016], [-0.38, 0.66, 0.438], mat.enamelDark);
addBox(group, [0.34, 0.025, 0.016], [0.06, 0.36, 0.438], mat.enamelDark);
return group;
}
function buildLamp(broken) {
const group = new THREE.Group();
// Base and stem.
addBox(group, [0.98, 0.18, 0.75], [0, 0.1, 0], mat.lampBlue);
addBox(group, [0.76, 0.1, 0.58], [0, 0.23, 0], mat.lampBlueDark);
addBox(group, [0.13, 1.25, 0.13], [0, 0.9, 0], mat.lampBlue);
addBox(group, [0.52, 0.12, 0.17], [0, 1.49, 0], mat.lampBlueDark);
// Stepped lamp shade.
addBox(group, [1.42, 0.26, 0.76], [0, 1.78, 0], mat.lampBlue);
addBox(group, [1.27, 0.12, 0.64], [0, 1.97, 0], mat.lampBlueDark);
addBox(group, [1.1, 0.05, 0.62], [0, 1.635, 0], mat.cream);
const bulbMaterial = broken ? mat.bulbOff : mat.bulbOn;
addBox(group, [0.23, 0.13, 0.23], [0, 1.54, 0.07], bulbMaterial);
if (!broken) {
const lampLight = new THREE.PointLight(0xffc86b, 24, 4.2, 2);
lampLight.position.set(0, 1.48, 0.15);
group.add(lampLight);
}
if (broken) {
// Separated cord with exposed copper ends.
addBox(group, [0.065, 0.05, 0.36], [0.51, 0.055, 0.46], mat.wireOld);
addBox(group, [0.065, 0.05, 0.3], [0.7, 0.055, 0.89], mat.wireOld);
addBox(group, [0.07, 0.025, 0.025], [0.51, 0.055, 0.645], mat.exposedWire);
addBox(group, [0.07, 0.025, 0.025], [0.67, 0.055, 0.735], mat.exposedWire);
// Old switch remains visible but inoperative.
addBox(group, [0.24, 0.1, 0.28], [0.69, 0.1, 0.69], mat.lampBlueDark);
} else {
// Continuous stepped replacement cord.
addBox(group, [0.065, 0.05, 0.36], [0.51, 0.055, 0.46], mat.wireNew);
addBox(group, [0.24, 0.05, 0.065], [0.61, 0.055, 0.65], mat.wireNew);
addBox(group, [0.065, 0.05, 0.36], [0.71, 0.055, 0.81], mat.wireNew);
// New inline switch.
addBox(group, [0.25, 0.12, 0.3], [0.71, 0.1, 0.66], mat.cream);
addBox(group, [0.12, 0.035, 0.13], [0.71, 0.177, 0.66], mat.wireNew);
}
// Scratches, chips, and worn paint remain on both versions.
addBox(group, [0.2, 0.012, 0.025], [-0.18, 0.197, 0.13], mat.rawWood);
addBox(group, [0.12, 0.012, 0.02], [0.26, 0.197, -0.15], mat.rawWood);
addBox(group, [0.12, 0.065, 0.018], [0.42, 1.78, 0.389], mat.rawWood);
addBox(group, [0.08, 0.06, 0.018], [-0.48, 1.78, 0.389], mat.lampBlueDark);
addBox(group, [0.11, 0.11, 0.018], [-0.22, 0.1, 0.384], mat.lampBlueDark);
return group;
}
/* -----------------------------------------------------------------------
PLACE OBJECTS AND MAKE THEM SELECTABLE
------------------------------------------------------------------------ */
const pickables = [];
function placeObject(object, id, state, x, z = 0.05) {
object.position.set(x, 0.565, z);
scene.add(object);
object.traverse((child) => {
if (child.isMesh) {
child.userData.pick = { exhibit: id, state };
pickables.push(child);
}
});
}
for (const id of exhibitOrder) {
const center = exhibits[id].center;
const [build, depth] = {chair: [buildChair, 0.05], kettle: [buildKettle, 0.12], lamp: [buildLamp, -0.02]}[id];
placeObject(build(true), id, "before", center - 1.1, depth);
placeObject(build(false), id, "after", center + 1.1, depth);
}
/* -----------------------------------------------------------------------
PROJECTED HTML LABELS
------------------------------------------------------------------------ */
const labelsRoot = document.getElementById("labels");
const projectedLabels = [];
function addLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `scene-tag ${className}`;
element.textContent = text;
labelsRoot.appendChild(element);
projectedLabels.push({
element,
position: new THREE.Vector3(...position)
});
}
for (const id of exhibitOrder) {
const item = exhibits[id];
addLabel(
`${item.number} / ${item.title.toUpperCase()}`,
[item.center, 3.73, -4.05],
"name"
);
addLabel(
"BEFORE",
[item.center - 1.1, id === "kettle" ? 1.92 : 2.92, 0.05],
"before"
);
addLabel(
"AFTER",
[item.center + 1.1, id === "kettle" ? 1.92 : 2.92, 0.05],
"after"
);
}
/* -----------------------------------------------------------------------
DIRECT CAMERA CONTROLS
------------------------------------------------------------------------ */
const current = {
target: new THREE.Vector3(1.4, 1.15, 0.15),
theta: 0.67,
phi: 0.92,
zoom: 0.9
};
const desired = {
target: current.target.clone(),
theta: current.theta,
phi: current.phi,
zoom: current.zoom
};
let baseViewHeight = 10.2;
function resize() {
const aspect = window.innerWidth / window.innerHeight;
baseViewHeight = aspect < 0.8 ? 24 : 10.2;
camera.left = (-baseViewHeight * aspect) / 2;
camera.right = (baseViewHeight * aspect) / 2;
camera.top = baseViewHeight / 2;
camera.bottom = -baseViewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
function selectExhibit(id, state = "after", focus = false) {
selectedExhibit = id;
selectedState = state;
updateInterface();
if (focus) {
desired.target.x = exhibits[id].center;
desired.target.y = 1.12;
desired.zoom = 1.12;
}
}
document.getElementById("reset-view").addEventListener("click", () => {
desired.target.set(1.4, 1.15, 0.15);
desired.theta = 0.67;
desired.phi = 0.92;
desired.zoom = 0.9;
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerButton = 0;
let lastX = 0;
let lastY = 0;
let dragDistance = 0;
function setPointerFromEvent(event) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
}
function pickObject(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
const data = hits[0].object.userData.pick;
selectExhibit(data.exhibit, data.state, true);
}
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerButton = event.button;
lastX = event.clientX;
lastY = event.clientY;
dragDistance = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
canvas.style.cursor =
raycaster.intersectObjects(pickables, false).length ? "pointer" : "grab";
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
if (event.shiftKey || pointerButton === 2) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
right.y = 0;
right.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const worldPerPixel =
baseViewHeight / window.innerHeight / camera.zoom;
desired.target.addScaledVector(right, -dx * worldPerPixel);
desired.target.addScaledVector(up, dy * worldPerPixel);
desired.target.x = THREE.MathUtils.clamp(
desired.target.x,
-8.5,
8.5
);
desired.target.y = THREE.MathUtils.clamp(
desired.target.y,
0.4,
3.0
);
} else {
desired.theta = THREE.MathUtils.clamp(
desired.theta - dx * 0.006,
-0.25,
1.45
);
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.5,
1.35
);
}
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && pointerButton === 0 && dragDistance < 7) {
pickObject(event);
}
pointerDown = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.zoom = THREE.MathUtils.clamp(
desired.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.15
);
},
{ passive: false }
);
/* -----------------------------------------------------------------------
RENDER LOOP
------------------------------------------------------------------------ */
const projectionPoint = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
current.target.lerp(desired.target, 0.1);
current.theta += (desired.theta - current.theta) * 0.12;
current.phi += (desired.phi - current.phi) * 0.12;
current.zoom += (desired.zoom - current.zoom) * 0.12;
const radius = 22;
camera.position.set(
current.target.x + radius * Math.sin(current.phi) * Math.sin(current.theta),
current.target.y + radius * Math.cos(current.phi),
current.target.z + radius * Math.sin(current.phi) * Math.cos(current.theta)
);
camera.lookAt(current.target);
camera.zoom = current.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
renderer.render(scene, camera);
for (const label of projectedLabels) {
projectionPoint.copy(label.position).project(camera);
const visible =
projectionPoint.z > -1 &&
projectionPoint.z < 1 &&
projectionPoint.x > -1.25 &&
projectionPoint.x < 1.25 &&
projectionPoint.y > -1.2 &&
projectionPoint.y < 1.2;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projectionPoint.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectionPoint.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
updateInterface();
animate();
</script>
</body>
</html>
```