Prompt specification
Build or customize the Three.js 3D scene "Railway-car table for the 1918 armistice" 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: Railway-car table for the 1918 armistice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/railway-car-table-for-the-1918-armistice-x2405
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Model a restrained railway-car table vignette labeled with the 1918 armistice. Use references for layout and avoid fabricated treaty text, signatures, or individual likeness details.
Working Three.js Starter (railway-car-table-for-the-1918-armistice-x2405):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light">
<title>The Armistice — 11 November 1918</title>
<style>
:root {
--ink: #25231f;
--muted: #625e56;
--paper: rgba(245, 241, 232, 0.94);
--line: rgba(51, 46, 38, 0.18);
--accent: #7b4937;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbc5b9;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.card {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 18px 50px rgba(34, 29, 23, 0.13);
backdrop-filter: blur(10px);
}
#title-card {
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 22px 24px 20px;
}
.eyebrow {
margin: 0 0 10px;
color: var(--accent);
font-size: 0.7rem;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(2rem, 4vw, 3.15rem);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.035em;
}
.date {
margin: 13px 0 4px;
font-size: 1.05rem;
font-weight: 720;
letter-spacing: 0.02em;
}
.place {
margin: 0;
color: var(--muted);
font-size: 0.94rem;
line-height: 1.45;
}
.fine-print {
margin: 16px 0 0;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 0.75rem;
line-height: 1.5;
}
.button-row {
display: flex;
gap: 8px;
margin-top: 16px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 0;
background: transparent;
color: var(--ink);
padding: 9px 12px;
font: inherit;
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
}
button:hover,
button:focus-visible {
background: rgba(123, 73, 55, 0.09);
border-color: rgba(123, 73, 55, 0.36);
outline: none;
}
#about-panel {
display: none;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 0.76rem;
line-height: 1.55;
}
#about-panel.open {
display: block;
}
#about-panel strong {
color: var(--ink);
}
#controls-hint {
position: fixed;
z-index: 8;
bottom: 18px;
left: 50%;
transform: translateX(-50%);
width: max-content;
max-width: calc(100vw - 30px);
padding: 9px 13px;
border: 1px solid rgba(50, 45, 38, 0.15);
background: rgba(245, 241, 232, 0.82);
color: #575149;
font-size: 0.7rem;
letter-spacing: 0.025em;
text-align: center;
pointer-events: none;
backdrop-filter: blur(8px);
}
.scene-label {
position: fixed;
z-index: 6;
transform: translate(-50%, -100%);
pointer-events: none;
opacity: 0;
transition: opacity 180ms ease;
}
.scene-label.visible {
opacity: 1;
}
.scene-label .label-box {
position: relative;
padding: 7px 10px;
border: 1px solid rgba(53, 47, 39, 0.18);
background: rgba(246, 241, 231, 0.9);
box-shadow: 0 8px 20px rgba(34, 29, 23, 0.1);
color: #3e3932;
font-size: 0.65rem;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
.scene-label .label-box::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 19px;
background: rgba(53, 47, 39, 0.42);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #cbc5b9;
color: #514b43;
font-size: 0.75rem;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 640px) {
#title-card {
top: 12px;
left: 12px;
width: min(320px, calc(100vw - 24px));
padding: 17px 18px;
}
h1 {
font-size: 2rem;
}
.fine-print {
display: none;
}
#controls-hint {
bottom: 10px;
font-size: 0.63rem;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Voxel reconstruction of the railway-car meeting associated with the armistice of 11 November 1918."
></canvas>
<section id="title-card" class="card" aria-labelledby="scene-title">
<p class="eyebrow">Reference-based voxel vignette</p>
<h1 id="scene-title">The Armistice</h1>
<p class="date">11 November 1918</p>
<p class="place">Railway-car meeting at Compiègne, France</p>
<p class="fine-print">
Schematic figures are intentionally anonymous. No treaty wording,
signatures, insignia, or individual likeness details are reproduced.
</p>
<div class="button-row">
<button id="about-toggle" type="button" aria-expanded="false">About</button>
<button id="reset-view" type="button">Reset view</button>
</div>
<div id="about-panel">
<strong>Reference basis.</strong> The composition follows the familiar
arrangement seen in widely reproduced photographs of the Wagon de
l’Armistice at Compiègne: delegates on opposing sides of a longitudinal
table, with attendants behind. The cutaway carriage and figures are
simplified interpretive forms rather than a literal reconstruction.
</div>
</section>
<div id="table-label" class="scene-label" aria-hidden="true">
<div class="label-box">Meeting table</div>
</div>
<div id="carriage-label" class="scene-label" aria-hidden="true">
<div class="label-box">Railway carriage</div>
</div>
<div id="controls-hint">
Drag to orbit · Scroll or pinch to zoom · Double-click to reset
</div>
<div id="loading">Constructing the carriage</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbc5b9);
scene.fog = new THREE.Fog(0xcbc5b9, 15, 29);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
const M = {
base: material(0x292722),
ground: material(0xbab4a8),
floorEdge: material(0x30251f),
wall: material(0x9b8f7d),
wallLight: material(0xb3a895),
wallDark: material(0x665b4e),
trim: material(0x4d392d),
woodDark: material(0x4a3024),
wood: material(0x684330),
woodLight: material(0x79503a),
table: material(0x63402d),
tableEdge: material(0x3e291f),
brass: material(0x9a7950, {
roughness: 0.42,
metalness: 0.55
}),
glass: material(0x91a8aa, {
roughness: 0.25,
metalness: 0.08,
transparent: true,
opacity: 0.82
}),
paper: material(0xe8dfca),
folder: material(0x55483d),
chair: material(0x5a3c2d),
black: material(0x242320),
lamp: material(0xe2bd76, {
emissive: 0x9f6d25,
emissiveIntensity: 0.75,
roughness: 0.45
}),
skinA: material(0xb99b82),
skinB: material(0x8f6d58),
trousers: material(0x393937),
uniformA: material(0x555650),
uniformB: material(0x68685f),
uniformC: material(0x454b48),
uniformD: material(0x6c6255),
civilianA: material(0x4b4d4c),
civilianB: material(0x69645c)
};
function box(parent, size, position, mat, rotation = null) {
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 (rotation) {
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent, position = [0, 0, 0], rotationY = 0) {
const result = new THREE.Group();
result.position.set(...position);
result.rotation.y = rotationY;
parent.add(result);
return result;
}
// ---------------------------------------------------------------------
// Ground and carriage shell
// ---------------------------------------------------------------------
box(scene, [60, 0.2, 60], [0, -0.64, 0], M.ground);
box(scene, [8.7, 0.42, 11.0], [0, -0.34, 0], M.base);
box(scene, [8.42, 0.13, 10.75], [0, -0.08, 0], M.floorEdge);
// Individual longitudinal floor boards.
const floorColors = [
material(0x654331),
material(0x6b4935),
material(0x5e3e2e),
material(0x704b36)
];
for (let i = 0; i < 11; i++) {
const x = -4.0 + i * 0.8;
box(
scene,
[0.76, 0.1, 10.62],
[x, 0.015, 0],
floorColors[i % floorColors.length]
);
}
// Rear wall: lower paneling, window band, upper panel and trim.
box(scene, [8.4, 1.18, 0.18], [0, 0.68, -5.25], M.wall);
box(scene, [8.4, 0.66, 0.18], [0, 3.03, -5.25], M.wallLight);
box(scene, [8.46, 0.13, 0.25], [0, 1.31, -5.18], M.trim);
box(scene, [8.46, 0.13, 0.25], [0, 2.74, -5.18], M.trim);
const rearWindowCenters = [-2.45, 0, 2.45];
for (const x of rearWindowCenters) {
box(scene, [2.08, 1.32, 0.05], [x, 2.03, -5.16], M.glass);
// Block-built window frames.
box(scene, [2.22, 0.09, 0.11], [x, 1.39, -5.10], M.trim);
box(scene, [2.22, 0.09, 0.11], [x, 2.67, -5.10], M.trim);
box(scene, [0.09, 1.37, 0.11], [x - 1.06, 2.03, -5.10], M.trim);
box(scene, [0.09, 1.37, 0.11], [x + 1.06, 2.03, -5.10], M.trim);
box(scene, [0.055, 1.35, 0.12], [x, 2.03, -5.09], M.wallDark);
}
// Wall posts between the rear windows.
for (const x of [-3.55, -1.23, 1.23, 3.55]) {
box(scene, [0.42, 1.43, 0.18], [x, 2.02, -5.23], M.wall);
}
// Left wall with a cutaway window rhythm.
box(scene, [0.18, 1.18, 10.55], [-4.15, 0.68, 0], M.wall);
box(scene, [0.18, 0.66, 10.55], [-4.15, 3.03, 0], M.wallLight);
box(scene, [0.25, 0.13, 10.6], [-4.08, 1.31, 0], M.trim);
box(scene, [0.25, 0.13, 10.6], [-4.08, 2.74, 0], M.trim);
const sideWindowCenters = [-3.55, -1.12, 1.32, 3.72];
for (const z of sideWindowCenters) {
box(scene, [0.05, 1.32, 1.82], [-4.06, 2.03, z], M.glass);
box(scene, [0.11, 0.09, 1.96], [-3.99, 1.39, z], M.trim);
box(scene, [0.11, 0.09, 1.96], [-3.99, 2.67, z], M.trim);
box(scene, [0.11, 1.37, 0.09], [-3.99, 2.03, z - 0.91], M.trim);
box(scene, [0.11, 1.37, 0.09], [-3.99, 2.03, z + 0.91], M.trim);
box(scene, [0.12, 1.35, 0.055], [-3.98, 2.03, z], M.wallDark);
}
for (const z of [-4.78, -2.34, 0.08, 2.5, 4.9]) {
box(scene, [0.18, 1.43, 0.4], [-4.13, 2.02, z], M.wall);
}
// Open roof frame and small luggage rack.
box(scene, [8.45, 0.18, 0.22], [0, 3.44, -5.16], M.trim);
box(scene, [0.22, 0.18, 10.55], [-4.08, 3.44, 0], M.trim);
for (const z of [-3.5, -1.15, 1.2, 3.55]) {
box(scene, [0.08, 0.08, 2.0], [-3.77, 2.88, z], M.brass);
}
box(scene, [0.10, 0.08, 8.3], [-3.72, 2.88, 0], M.brass);
// Carriage lamps.
for (const x of [-2.45, 0, 2.45]) {
box(scene, [0.22, 0.18, 0.22], [x, 2.88, -4.98], M.brass);
box(scene, [0.13, 0.17, 0.13], [x, 2.75, -4.98], M.lamp);
}
// ---------------------------------------------------------------------
// Long meeting table
// ---------------------------------------------------------------------
box(scene, [3.04, 0.17, 6.55], [0, 1.22, 0], M.tableEdge);
for (let i = 0; i < 4; i++) {
const x = -1.125 + i * 0.75;
box(
scene,
[0.71, 0.12, 6.42],
[x, 1.34, 0],
[M.table, M.wood, M.table, M.woodLight][i]
);
}
// Four simple square table legs.
for (const x of [-1.15, 1.15]) {
for (const z of [-2.55, 2.55]) {
box(scene, [0.19, 1.13, 0.19], [x, 0.61, z], M.tableEdge);
box(scene, [0.29, 0.10, 0.29], [x, 0.08, z], M.tableEdge);
}
}
// Unmarked document pads: deliberately blank, with no treaty wording.
const documentPositions = [
[-0.72, -1.95, -0.08],
[0.72, -0.18, 0.12],
[-0.74, 1.58, -0.12]
];
for (const [x, z, angle] of documentPositions) {
const pad = box(
scene,
[0.48, 0.025, 0.66],
[x, 1.42, z],
M.paper,
[0, angle, 0]
);
pad.castShadow = false;
const folder = box(
scene,
[0.53, 0.035, 0.72],
[x, 1.405, z],
M.folder,
[0, angle, 0]
);
folder.castShadow = false;
}
// A single closed portfolio, also without visible markings.
box(scene, [0.74, 0.09, 0.42], [0.45, 1.45, 2.45], M.black, [0, 0.08, 0]);
// ---------------------------------------------------------------------
// Schematic seated delegates
// ---------------------------------------------------------------------
function addChair(parent) {
box(parent, [0.72, 0.12, 0.68], [0, 0.73, 0], M.chair);
box(parent, [0.72, 0.84, 0.12], [0, 1.19, -0.31], M.chair);
for (const x of [-0.27, 0.27]) {
for (const z of [-0.24, 0.24]) {
box(parent, [0.11, 0.67, 0.11], [x, 0.36, z], M.tableEdge);
}
}
}
function addSeatedPerson(parent, clothing, skin, handedness = 1) {
// No face, hair, insignia, medals, or individualized costume.
box(parent, [0.63, 0.82, 0.39], [0, 1.30, 0], clothing);
box(parent, [0.17, 0.16, 0.17], [0, 1.80, 0], skin);
box(parent, [0.43, 0.47, 0.41], [0, 2.10, 0], skin);
// Seated legs.
for (const x of [-0.18, 0.18]) {
box(parent, [0.25, 0.27, 0.69], [x, 0.77, 0.25], M.trousers);
box(parent, [0.23, 0.60, 0.23], [x, 0.39, 0.57], M.trousers);
box(parent, [0.25, 0.13, 0.38], [x, 0.13, 0.67], M.black);
}
// Arms rest toward the table.
for (const x of [-0.39, 0.39]) {
box(parent, [0.18, 0.57, 0.19], [x, 1.40, 0.12], clothing);
box(parent, [0.18, 0.18, 0.62], [x, 1.26, 0.45], clothing);
box(parent, [0.17, 0.14, 0.18], [x, 1.28, 0.79], skin);
}
// A very small neutral collar block; no badges or facial features.
box(
parent,
[0.18, 0.07, 0.04],
[0, 1.70, 0.215],
M.paper
);
}
function seatedDelegate(x, z, facing, clothing, skin) {
const delegate = group(scene, [x, 0, z], facing);
addChair(delegate);
addSeatedPerson(delegate, clothing, skin);
return delegate;
}
const leftUniforms = [M.uniformA, M.uniformB, M.uniformC];
const rightUniforms = [M.uniformC, M.uniformD, M.uniformA];
const seatZ = [-2.15, 0, 2.15];
for (let i = 0; i < seatZ.length; i++) {
seatedDelegate(
-2.18,
seatZ[i],
Math.PI / 2,
leftUniforms[i],
i === 1 ? M.skinB : M.skinA
);
seatedDelegate(
2.18,
seatZ[i],
-Math.PI / 2,
rightUniforms[i],
i === 0 ? M.skinA : M.skinB
);
}
// ---------------------------------------------------------------------
// Two anonymous standing attendants behind the table
// ---------------------------------------------------------------------
function standingObserver(x, z, clothing, skin) {
const observer = group(scene, [x, 0, z], Math.PI);
for (const side of [-0.18, 0.18]) {
box(observer, [0.24, 0.83, 0.26], [side, 0.47, 0], M.trousers);
box(observer, [0.26, 0.14, 0.42], [side, 0.09, 0.08], M.black);
}
box(observer, [0.66, 0.88, 0.40], [0, 1.31, 0], clothing);
box(observer, [0.18, 0.16, 0.18], [0, 1.82, 0], skin);
box(observer, [0.43, 0.47, 0.41], [0, 2.11, 0], skin);
for (const side of [-0.42, 0.42]) {
box(observer, [0.18, 0.75, 0.20], [side, 1.33, 0], clothing);
box(observer, [0.17, 0.18, 0.18], [side, 0.93, 0], skin);
}
}
standingObserver(-2.85, -4.03, M.civilianA, M.skinB);
standingObserver(-3.25, -3.78, M.civilianB, M.skinA);
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf5ead7, 0x38322d, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffefd2, 2.8);
keyLight.position.set(5.5, 8.5, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc4d3d2, 0.72);
fillLight.position.set(-6, 4, 1);
scene.add(fillLight);
const carriageLight = new THREE.PointLight(0xe3aa63, 4.2, 8, 2);
carriageLight.position.set(0, 2.78, -4.75);
scene.add(carriageLight);
// ---------------------------------------------------------------------
// Direct camera controls — no examples/addons are imported
// ---------------------------------------------------------------------
const defaultCamera = {
theta: 0.28,
phi: 1.08,
radius: 10.9,
target: new THREE.Vector3(0, 1.25, -0.15)
};
const cameraState = {
theta: defaultCamera.theta,
phi: defaultCamera.phi,
radius: defaultCamera.radius,
target: defaultCamera.target.clone()
};
function resetCamera() {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
cameraState.target.copy(defaultCamera.target);
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const pointers = new Map();
let previousPinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.focus({ preventScroll: true });
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.classList.add("dragging");
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.72,
1.38
);
} else if (pointers.size === 2) {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (previousPinchDistance / distance),
6.0,
15.5
);
}
previousPinchDistance = distance;
return;
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.0,
15.5
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") {
cameraState.theta += step;
} else if (event.key === "ArrowRight") {
cameraState.theta -= step;
} else if (event.key === "ArrowUp") {
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - step,
0.72,
1.38
);
} else if (event.key === "ArrowDown") {
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + step,
0.72,
1.38
);
} else if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(6, cameraState.radius - 0.5);
} else if (event.key === "-" || event.key === "_") {
cameraState.radius = Math.min(15.5, cameraState.radius + 0.5);
} else if (event.key.toLowerCase() === "r") {
resetCamera();
} else {
return;
}
event.preventDefault();
});
document.querySelector("#reset-view").addEventListener("click", resetCamera);
const aboutButton = document.querySelector("#about-toggle");
const aboutPanel = document.querySelector("#about-panel");
aboutButton.addEventListener("click", () => {
const isOpen = aboutPanel.classList.toggle("open");
aboutButton.setAttribute("aria-expanded", String(isOpen));
aboutButton.textContent = isOpen ? "Close" : "About";
});
// ---------------------------------------------------------------------
// Projected scene labels
// ---------------------------------------------------------------------
const tableLabel = document.querySelector("#table-label");
const carriageLabel = document.querySelector("#carriage-label");
const labelAnchors = [
{
element: tableLabel,
point: new THREE.Vector3(0, 1.95, -3.16)
},
{
element: carriageLabel,
point: new THREE.Vector3(-2.45, 2.72, -5.12)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const anchor of labelAnchors) {
projected.copy(anchor.point).project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
anchor.element.classList.toggle("visible", visible);
if (visible) {
anchor.element.style.left =
`${(projected.x * 0.5 + 0.5) * innerWidth}px`;
anchor.element.style.top =
`${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(() => loading.classList.add("hidden"));
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```