Prompt specification
Build or customize the Three.js 3D scene "Railway telegraph office and line repair" 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 telegraph office and line repair
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/railway-telegraph-office-and-line-repair-x2543
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: Railway telegraph office and line repair. Build a referenced railway office with operator, message desk, and nearby line poles. Show how a broken connection interrupts signaling between otherwise intact stations. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (railway-telegraph-office-and-line-repair-x2543):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Railway Telegraph Office — Broken Connection</title>
<style>
:root {
--ink: #24343a;
--paper: #f5f0df;
--red: #c94335;
--amber: #e6a43b;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe7e3;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
touch-action: none;
}
#overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 22px;
left: 22px;
max-width: min(440px, calc(100vw - 44px));
padding: 16px 19px 14px;
border-left: 5px solid var(--red);
background: rgba(247, 242, 224, 0.91);
box-shadow: 0 8px 24px rgba(34, 49, 51, 0.16);
backdrop-filter: blur(5px);
}
.eyebrow {
margin-bottom: 5px;
color: #7e493d;
font: 700 11px/1.2 Arial, sans-serif;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1.03;
font-weight: 700;
}
.subtitle {
margin-top: 8px;
font: 13px/1.45 Arial, sans-serif;
color: #526267;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
margin-top: 12px;
font: 11px/1.2 Arial, sans-serif;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
display: inline-block;
box-shadow: 0 0 0 2px rgba(255,255,255,.55);
}
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }
.dot.green { background: #6f9274; }
#controls {
position: absolute;
top: 20px;
right: 20px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(36, 52, 58, .22);
background: rgba(247, 242, 224, .92);
color: var(--ink);
padding: 9px 12px;
font: 700 11px Arial, sans-serif;
letter-spacing: .05em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 5px 15px rgba(35, 49, 51, .11);
}
button:hover { background: #fffaf0; }
button:active { transform: translateY(1px); }
#caption {
position: absolute;
left: 22px;
bottom: 20px;
max-width: 420px;
padding: 11px 14px;
background: rgba(36, 52, 58, .86);
color: #f8f2df;
font: 12px/1.45 Arial, sans-serif;
box-shadow: 0 6px 18px rgba(24, 39, 42, .16);
}
#caption strong {
color: #ffc166;
}
#help {
position: absolute;
right: 20px;
bottom: 20px;
color: rgba(36, 52, 58, .76);
font: 11px/1.4 Arial, sans-serif;
text-align: right;
}
@media (max-width: 700px) {
.title-card { top: 12px; left: 12px; padding: 12px 14px; }
#controls { top: auto; right: 12px; bottom: 54px; }
#caption { left: 12px; bottom: 12px; max-width: calc(100vw - 24px); }
#help { display: none; }
.legend { gap: 6px 11px; }
}
</style>
</head>
<body>
<div id="overlay">
<div class="title-card">
<div class="eyebrow">Branch line infrastructure · circa 1900</div>
<h1>Railway Telegraph Office</h1>
<div class="subtitle">A damaged pole connection has interrupted the block-signal circuit between two structurally intact stations.</div>
<div class="legend">
<span><i class="dot amber"></i> Message pulse</span>
<span><i class="dot red"></i> Broken link / stop signal</span>
<span><i class="dot green"></i> Intact station</span>
</div>
</div>
<div id="controls">
<button id="labelsButton" type="button">Hide labels</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div id="caption">
<strong>Repair in progress:</strong> the amber message pulse reaches the broken wire but cannot cross the gap. Both semaphore signals remain at <strong>STOP</strong>.
</div>
<div id="help">
Drag to orbit · Shift-drag to pan · Scroll or pinch to zoom<br>
Arrow keys rotate · + / − zoom · R resets
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe7e3);
scene.fog = new THREE.Fog(0xdbe7e3, 45, 90);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 160);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf5fbff, 0x6b7256, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe7bd, 3.2);
sun.position.set(-18, 30, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 85;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const labelGroup = new THREE.Group();
scene.add(labelGroup);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
flatShading: true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
const M = {
grass: material(0x879b70),
grassDark: material(0x687c59),
ballast: material(0x77756e),
sleeper: material(0x5b4634),
rail: material(0x777d7d, { roughness: 0.38, metalness: 0.65 }),
platform: material(0xb5a994),
platformEdge: material(0xd3c4a8),
brick: material(0xa85f47),
brickDark: material(0x754438),
trim: material(0xe2d5b5),
roof: material(0x3e4d53),
roofLight: material(0x526269),
wood: material(0x765039),
woodLight: material(0xa17b50),
dark: material(0x263238),
black: material(0x1d2528),
cream: material(0xe8dcc0),
brass: material(0xb88a37, { roughness: 0.38, metalness: 0.58 }),
copper: material(0xa85c35, { roughness: 0.45, metalness: 0.4 }),
glass: material(0x3b5962, { roughness: 0.35 }),
skin: material(0xc99470),
navy: material(0x263f55),
navyLight: material(0x35566f),
red: material(0xb63c31),
redBright: material(0xe54b3e, { emissive: 0x5d0d08, emissiveIntensity: 1.1 }),
amber: material(0xf2a936, { emissive: 0x9d4d05, emissiveIntensity: 1.7 }),
vest: material(0xe47b2e),
helmet: material(0xf2c84a),
greenDark: material(0x355b43),
leaf: material(0x536f4d),
leafLight: material(0x6f8756),
trunk: material(0x6b4b35),
wire: material(0x252b2c, { roughness: 0.55, metalness: 0.3 }),
porcelain: material(0xc9b99a)
};
function box(w, h, d, x, y, z, mat, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rTop, rBottom, h, x, y, z, mat, segments = 10, parent = scene) {
const mesh = new THREE.Mesh(new THREE.CylinderGeometry(rTop, rBottom, h, segments), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function ico(radius, x, y, z, mat, detail = 1, parent = scene) {
const mesh = new THREE.Mesh(new THREE.IcosahedronGeometry(radius, detail), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, mat, segments = 8, parent = scene) {
const av = new THREE.Vector3(...a);
const bv = new THREE.Vector3(...b);
const direction = bv.clone().sub(av);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), segments),
mat
);
mesh.position.copy(av).add(bv).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function textTexture(text, bg = "#f0e5c9", fg = "#263238", border = null) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (bg) {
ctx.fillStyle = bg;
roundedRect(ctx, 8, 8, 1008, 240, 18);
ctx.fill();
}
if (border) {
ctx.strokeStyle = border;
ctx.lineWidth = 8;
roundedRect(ctx, 14, 14, 996, 228, 14);
ctx.stroke();
}
const lines = text.split("\n");
ctx.fillStyle = fg;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
if (lines.length === 1) {
ctx.font = `700 ${text.length > 24 ? 54 : 68}px Georgia`;
ctx.fillText(text, 512, 130, 940);
} else {
ctx.font = "700 58px Georgia";
ctx.fillText(lines[0], 512, 91, 930);
ctx.font = "700 40px Arial";
ctx.fillText(lines[1], 512, 170, 930);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function board(text, w, h, x, y, z, options = {}) {
const tex = textTexture(
text,
options.bg ?? "#f0e5c9",
options.fg ?? "#263238",
options.border ?? null
);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({
map: tex,
transparent: true,
toneMapped: false,
side: options.side ?? THREE.FrontSide
})
);
mesh.position.set(x, y, z);
if (options.rotationX) mesh.rotation.x = options.rotationX;
scene.add(mesh);
return mesh;
}
function label(text, w, h, x, y, z, options = {}) {
const tex = textTexture(
text,
options.bg ?? "#f4eedc",
options.fg ?? "#263238",
options.border ?? "#8d4a3d"
);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: tex,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(w, h, 1);
sprite.position.set(x, y, z);
sprite.renderOrder = 10;
labelGroup.add(sprite);
return sprite;
}
function gableRoof(w, d, h, x, y, z, mat) {
const p = [
[-w/2, 0, -d/2], [w/2, 0, -d/2], [w/2, h, 0], [-w/2, h, 0],
[-w/2, 0, d/2], [w/2, 0, d/2]
];
const tris = [
0,1,2, 0,2,3,
4,2,5, 4,3,2,
0,3,4,
1,5,2,
0,4,5, 0,5,1
];
const positions = [];
for (const i of tris) positions.push(...p[i]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function windowPanel(x, y, z, w = 1.1, h = 1.25) {
box(w + 0.16, h + 0.16, 0.09, x, y, z, M.trim);
box(w, h, 0.11, x, y, z + 0.06, M.glass);
box(0.07, h, 0.14, x, y, z + 0.12, M.trim);
box(w, 0.07, 0.14, x, y, z + 0.12, M.trim);
}
function makeStation(x, name) {
const base = 0.72;
const width = 6.0;
const depth = 4.2;
const wallH = 3.15;
box(width, wallH, depth, x, base + wallH/2, 0, M.brick);
box(width + 0.2, 0.16, depth + 0.2, x, base + 0.06, 0, M.brickDark);
gableRoof(width + 0.55, depth + 0.55, 1.25, x, base + wallH, 0, M.roof);
box(1.18, 2.2, 0.12, x, base + 1.1, depth/2 + 0.08, M.dark);
box(1.36, 0.14, 0.3, x, base + 2.18, depth/2 + 0.16, M.trim);
windowPanel(x - 1.9, base + 1.75, depth/2 + 0.04, 1.25, 1.3);
windowPanel(x + 1.9, base + 1.75, depth/2 + 0.04, 1.25, 1.3);
windowPanel(x, base + 1.7, -depth/2 - 0.06, 1.4, 1.25);
box(0.78, 1.65, 0.78, x + 1.8, base + wallH + 0.9, -0.45, M.brickDark);
box(0.95, 0.18, 0.95, x + 1.8, base + wallH + 1.73, -0.45, M.trim);
board(name, 3.35, 0.74, x, base + 2.68, depth/2 + 0.15, {
bg: "#ede1bd",
fg: "#25333a",
border: "#25333a"
});
label(`${name}\nINTACT STATION`, 3.7, 0.9, x, 5.25, 2.35, {
bg: "#e9e5ce",
fg: "#355442",
border: "#557b5b"
});
}
function makeBench(x, z) {
box(2.4, 0.15, 0.62, x, 1.32, z, M.woodLight);
box(2.4, 0.7, 0.12, x, 1.68, z - 0.28, M.wood);
box(0.12, 0.85, 0.5, x - 0.92, 0.99, z, M.dark);
box(0.12, 0.85, 0.5, x + 0.92, 0.99, z, M.dark);
}
function makeSemaphore(x, direction) {
const z = 4.22;
cylinder(0.09, 0.13, 4.25, x, 2.84, z, M.dark, 8);
cylinder(0.34, 0.4, 0.25, x, 0.87, z, M.trim, 10);
box(1.72, 0.28, 0.14, x + direction * 0.72, 3.68, z, M.red);
box(0.22, 0.31, 0.17, x + direction * 0.62, 3.68, z + 0.02, M.cream);
const lens = cylinder(0.18, 0.18, 0.13, x + direction * 1.18, 3.68, z + 0.14, M.redBright, 12);
lens.rotation.x = Math.PI / 2;
const offLens = cylinder(0.12, 0.12, 0.1, x, 4.27, z + 0.12, M.greenDark, 12);
offLens.rotation.x = Math.PI / 2;
label("SIGNAL: STOP", 3.2, 0.72, x, 5.25, z + 0.2, {
bg: "#f0d7c9",
fg: "#9d2d25",
border: "#a3372d"
});
}
function makeTree(x, z, scale = 1) {
cylinder(0.15 * scale, 0.21 * scale, 1.7 * scale, x, 0.8 * scale, z, M.trunk, 7);
const lower = new THREE.Mesh(new THREE.ConeGeometry(1.25 * scale, 2.35 * scale, 7), M.leaf);
lower.position.set(x, 2.25 * scale, z);
lower.castShadow = true;
scene.add(lower);
const upper = new THREE.Mesh(new THREE.ConeGeometry(0.9 * scale, 1.8 * scale, 7), M.leafLight);
upper.position.set(x, 3.2 * scale, z);
upper.castShadow = true;
scene.add(upper);
}
function makeBush(x, z, s = 1) {
ico(0.55 * s, x, 0.35 * s, z, M.leaf, 0);
ico(0.42 * s, x + 0.45 * s, 0.28 * s, z + 0.1, M.leafLight, 0);
}
function wirePoints(x1, x2, z, top = 7.82, sag = 0.43, count = 12) {
const points = [];
for (let i = 0; i <= count; i++) {
const t = i / count;
points.push(new THREE.Vector3(
THREE.MathUtils.lerp(x1, x2, t),
top - 4 * sag * t * (1 - t),
z
));
}
return points;
}
function makeWire(points) {
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal");
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, Math.max(12, points.length * 2), 0.025, 4, false),
M.wire
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
// Terrain and railway
box(60, 0.3, 28, 0, -0.17, -0.5, M.grass);
box(52, 0.16, 2.35, 0, 0.08, 5.9, M.ballast);
for (let x = -25.5; x <= 25.5; x += 0.78) {
box(0.28, 0.12, 1.85, x, 0.21, 5.9, M.sleeper);
}
box(52, 0.12, 0.12, 0, 0.33, 5.38, M.rail);
box(52, 0.12, 0.12, 0, 0.33, 6.42, M.rail);
box(51, 0.72, 3.75, 0, 0.36, 2.65, M.platform);
box(51, 0.12, 0.14, 0, 0.75, 4.49, M.platformEdge);
// A low-poly distant landscape
for (const h of [
[-28, -11, 8, 5, 5],
[-18, -13, 10, 6, 7],
[2, -14, 12, 5, 6],
[20, -12, 11, 7, 6],
[30, -10, 8, 5, 5]
]) {
const hill = new THREE.Mesh(
new THREE.ConeGeometry(h[2], h[3], 7),
material(h[4] % 2 ? 0x718768 : 0x7d906d)
);
hill.position.set(h[0], h[3]/2 - 0.05, h[1]);
hill.rotation.y = 0.3;
hill.receiveShadow = true;
scene.add(hill);
}
for (const t of [
[-25,-5.8,1.1], [-21,-7.2,.85], [-15,-7.8,.95],
[-2,-6.5,1.0], [6,-7.3,.9], [13,-6.8,1.05],
[23,-6.3,1.15], [27,-4.8,.85]
]) makeTree(...t);
for (const b of [
[-14,-4.2,.9], [-4.5,-4.7,.8], [8,-4.8,.9],
[16,-5.1,1.0], [-26,2.2,.8], [26,2.5,.9]
]) makeBush(...b);
// Stations
makeStation(-19, "PINEBRIDGE");
makeStation(19, "RIDGEND");
makeBench(-14.8, 2.8);
makeBench(15.0, 2.8);
// Telegraph office: open-front cutaway so the operator and desk remain visible.
const officeX = -9;
const officeBase = 0.72;
const officeWallH = 3.25;
box(6.15, 0.14, 4.35, officeX, officeBase + 0.05, -0.02, M.brickDark);
box(6.0, officeWallH, 0.25, officeX, officeBase + officeWallH/2, -2.05, M.brick);
box(0.25, officeWallH, 4.2, officeX - 3, officeBase + officeWallH/2, -0.05, M.brickDark);
box(0.25, officeWallH, 4.2, officeX + 3, officeBase + officeWallH/2, -0.05, M.brick);
box(0.28, officeWallH, 0.28, officeX - 2.86, officeBase + officeWallH/2, 2.0, M.trim);
box(0.28, officeWallH, 0.28, officeX + 2.86, officeBase + officeWallH/2, 2.0, M.trim);
box(6.0, 0.34, 0.28, officeX, officeBase + officeWallH - 0.13, 2.0, M.trim);
gableRoof(6.6, 4.7, 1.35, officeX, officeBase + officeWallH, -0.03, M.roof);
box(0.7, 1.65, 0.72, officeX + 2.05, officeBase + officeWallH + 0.88, -0.95, M.brickDark);
box(0.86, 0.17, 0.87, officeX + 2.05, officeBase + officeWallH + 1.72, -0.95, M.trim);
board("TELEGRAPH OFFICE", 4.45, 0.66, officeX, 3.69, 2.17, {
bg: "#ead9b1",
fg: "#263238",
border: "#263238"
});
// Office status board on the rear wall
board("BLOCK SIGNALS\nLINE HELD", 2.3, 0.88, officeX + 1.25, 2.75, -1.88, {
bg: "#263238",
fg: "#f2d57d",
border: "#b13b31"
});
const officeStatusLamp = ico(0.13, officeX + 2.38, 2.75, -1.77, M.redBright, 1);
// Message desk
const deskX = officeX;
const deskZ = 0.9;
box(2.65, 0.15, 1.05, deskX, 1.48, deskZ, M.woodLight);
box(0.16, 0.78, 0.76, deskX - 1.15, 1.08, deskZ, M.wood);
box(0.16, 0.78, 0.76, deskX + 1.15, 1.08, deskZ, M.wood);
box(2.38, 0.12, 0.78, deskX, 0.78, deskZ, M.wood);
board("MESSAGE DESK", 1.42, 0.34, deskX, 1.18, 1.435, {
bg: "#d9c79f",
fg: "#29363b",
border: "#5a4431"
});
// Telegraph key, sounder, papers, and message card
box(0.48, 0.08, 0.32, deskX - 0.72, 1.59, deskZ + 0.03, M.black);
cylinderBetween(
[deskX - 0.9, 1.65, deskZ + 0.03],
[deskX - 0.52, 1.73, deskZ + 0.03],
0.035,
M.brass
);
ico(0.075, deskX - 0.52, 1.73, deskZ + 0.03, M.brass, 1);
box(0.72, 0.25, 0.42, deskX + 0.65, 1.68, deskZ - 0.04, M.dark);
box(0.48, 0.08, 0.27, deskX + 0.65, 1.84, deskZ - 0.04, M.brass);
box(0.34, 0.025, 0.44, deskX + 0.05, 1.565, deskZ + 0.08, M.cream);
board("MESSAGE 27\nHOLD", 0.76, 0.25, deskX + 0.05, 1.584, deskZ + 0.08, {
bg: "#f5edcf",
fg: "#473c32",
border: "#8a7356",
rotationX: -Math.PI / 2
});
// Seated operator, facing the viewer and the message desk
const operator = new THREE.Group();
operator.position.set(deskX, 0, -0.1);
scene.add(operator);
box(0.75, 0.12, 0.72, 0, 0.93, -0.12, M.dark, operator);
box(0.75, 0.86, 0.12, 0, 1.35, -0.46, M.dark, operator);
cylinder(0.06, 0.06, 0.9, 0, 0.48, -0.12, M.dark, 8, operator);
cylinderBetween([-0.18, 0.95, -0.02], [-0.22, 0.68, 0.42], 0.105, M.navy, 7, operator);
cylinderBetween([0.18, 0.95, -0.02], [0.22, 0.68, 0.42], 0.105, M.navy, 7, operator);
box(0.23, 0.15, 0.42, -0.22, 0.66, 0.5, M.black, operator);
box(0.23, 0.15, 0.42, 0.22, 0.66, 0.5, M.black, operator);
box(0.66, 0.78, 0.42, 0, 1.48, 0, M.navy, operator);
box(0.68, 0.12, 0.44, 0, 1.15, 0, M.red, operator);
ico(0.285, 0, 2.07, 0.04, M.skin, 1, operator);
ico(0.075, 0, 2.03, 0.29, M.skin, 0, operator);
cylinder(0.27, 0.29, 0.16, 0, 2.28, 0.02, M.navy, 10, operator);
box(0.46, 0.055, 0.28, 0, 2.23, 0.25, M.dark, operator);
box(0.48, 0.055, 0.07, 0, 2.19, 0.32, M.red, operator);
cylinderBetween([-0.38, 1.72, 0.03], [-0.48, 1.54, 0.53], 0.085, M.navyLight, 7, operator);
cylinderBetween([0.38, 1.72, 0.03], [0.48, 1.54, 0.53], 0.085, M.navyLight, 7, operator);
ico(0.095, -0.48, 1.54, 0.53, M.skin, 0, operator);
ico(0.095, 0.48, 1.54, 0.53, M.skin, 0, operator);
for (let i = 0; i < 3; i++) {
ico(0.035, 0, 1.4 + i * 0.17, 0.225, M.brass, 0, operator);
}
label("OPERATOR / MESSAGE DESK", 3.6, 0.75, officeX, 3.02, 2.45, {
bg: "#e9e1c9",
fg: "#304553",
border: "#526d79"
});
// Nearby telegraph poles
const poleXs = [-24, -18, -12, -6, 0, 6, 12, 18, 24];
const wireZ = [1.28, 1.78, 2.28];
for (const x of poleXs) {
cylinder(0.13, 0.19, 7.35, x, 4.25, 1.78, M.wood, 8);
box(0.2, 0.18, 1.75, x, 7.48, 1.78, M.woodLight);
box(0.18, 1.05, 0.18, x - 0.16, 6.98, 1.78, M.wood);
box(0.18, 1.05, 0.18, x + 0.16, 6.98, 1.78, M.wood);
for (const z of wireZ) {
cylinder(0.065, 0.075, 0.24, x, 7.72, z, M.porcelain, 8);
}
}
// Complete outer circuits and the healthy middle-wire spans
for (let i = 0; i < poleXs.length - 1; i++) {
const x1 = poleXs[i];
const x2 = poleXs[i + 1];
for (let j = 0; j < wireZ.length; j++) {
const z = wireZ[j];
const brokenMiddleSpan = x1 === 0 && x2 === 6 && j === 1;
if (brokenMiddleSpan) {
makeWire(wirePoints(x1, 2.25, z, 7.82, 0.24, 9));
makeWire(wirePoints(3.75, x2, z, 7.82, 0.24, 9));
cylinderBetween([2.19, 7.44, z], [2.45, 7.08, z], 0.045, M.wire, 7);
cylinderBetween([3.81, 7.54, z], [3.55, 7.19, z], 0.045, M.wire, 7);
cylinderBetween([2.13, 7.47, z], [2.32, 7.23, z], 0.075, M.red, 8);
cylinderBetween([3.87, 7.57, z], [3.68, 7.33, z], 0.075, M.red, 8);
} else {
makeWire(wirePoints(x1, x2, z, 7.82, 0.43, 14));
}
}
}
label("BROKEN CONNECTION", 4.8, 0.96, 3, 9.05, 1.78, {
bg: "#f0d3c8",
fg: "#9f2f27",
border: "#a33229"
});
const breakLight = new THREE.PointLight(0xff4638, 1.1, 4.5, 2);
breakLight.position.set(3, 7.4, 1.9);
scene.add(breakLight);
// Line-repair worker
const worker = new THREE.Group();
worker.position.set(3.35, 0.72, 1.3);
scene.add(worker);
cylinderBetween([-0.17, 0.1, 0], [-0.17, 0.86, 0], 0.115, M.navy, 7, worker);
cylinderBetween([0.17, 0.1, 0], [0.17, 0.86, 0], 0.115, M.navy, 7, worker);
box(0.3, 0.16, 0.5, -0.17, 0.08, 0.08, M.black, worker);
box(0.3, 0.16, 0.5, 0.17, 0.08, 0.08, M.black, worker);
box(0.7, 0.8, 0.42, 0, 1.22, 0, M.vest, worker);
box(0.73, 0.11, 0.44, 0, 1.21, 0, M.cream, worker);
ico(0.28, 0, 1.88, 0.03, M.skin, 1, worker);
cylinder(0.28, 0.31, 0.19, 0, 2.09, 0.02, M.helmet, 10, worker);
cylinder(0.38, 0.38, 0.05, 0, 2.02, 0.02, M.helmet, 10, worker);
cylinderBetween([-0.4, 1.48, 0], [-0.63, 1.02, 0.3], 0.09, M.vest, 7, worker);
cylinderBetween([0.4, 1.48, 0], [0.57, 1.16, 0.42], 0.09, M.vest, 7, worker);
ico(0.095, -0.63, 1.02, 0.3, M.skin, 0, worker);
ico(0.095, 0.57, 1.16, 0.42, M.skin, 0, worker);
label("LINE REPAIR", 3.1, 0.72, 3.4, 3.1, 1.6, {
bg: "#f0e4c4",
fg: "#68442b",
border: "#bb6b32"
});
// Tall maintenance ladder
const ladderBaseA = new THREE.Vector3(4.7, 0.74, 1.58);
const ladderBaseB = new THREE.Vector3(5.28, 0.74, 1.58);
const ladderTopA = new THREE.Vector3(2.15, 6.9, 1.77);
const ladderTopB = new THREE.Vector3(2.55, 6.9, 1.77);
cylinderBetween(ladderBaseA.toArray(), ladderTopA.toArray(), 0.055, M.woodLight, 7);
cylinderBetween(ladderBaseB.toArray(), ladderTopB.toArray(), 0.055, M.woodLight, 7);
for (let i = 0; i <= 13; i++) {
const t = i / 13;
const a = ladderBaseA.clone().lerp(ladderTopA, t);
const b = ladderBaseB.clone().lerp(ladderTopB, t);
cylinderBetween(a.toArray(), b.toArray(), 0.035, M.wood, 6);
}
// Toolbox and wire spool
box(0.85, 0.38, 0.48, 5.65, 0.93, 1.15, M.red);
box(0.88, 0.08, 0.49, 5.65, 1.16, 1.15, M.dark);
cylinderBetween([4.9, 0.94, 1.95], [5.45, 0.94, 1.95], 0.07, M.dark, 8);
const spool = cylinder(0.3, 0.3, 0.55, 5.18, 0.94, 1.95, M.copper, 12);
spool.rotation.z = Math.PI / 2;
// Block signals remain at danger because no signal information can pass.
makeSemaphore(-14.6, -1);
makeSemaphore(14.6, 1);
// A small explanatory board near the office
cylinder(0.07, 0.07, 2.25, -5.7, 1.8, 1.35, M.dark, 8);
cylinder(0.07, 0.07, 2.25, -4.45, 1.8, 1.35, M.dark, 8);
board("NO MESSAGE PASSED\nLINE HELD", 2.2, 0.85, -5.08, 2.72, 1.38, {
bg: "#29363b",
fg: "#f3d77c",
border: "#b34033"
});
// Moving message pulses
const nearPacket = ico(0.14, 0, 0, 0, M.amber, 1);
const farPacket = ico(0.14, 0, 0, 0, M.amber, 1);
nearPacket.renderOrder = 5;
farPacket.renderOrder = 5;
const pulseLight = new THREE.PointLight(0xffa22f, 0.8, 2.5);
scene.add(pulseLight);
function smoothstep(t) {
t = THREE.MathUtils.clamp(t, 0, 1);
return t * t * (3 - 2 * t);
}
function wireHeightAt(x) {
for (let i = 0; i < poleXs.length - 1; i++) {
const a = poleXs[i];
const b = poleXs[i + 1];
if (x >= a && x <= b) {
const t = (x - a) / (b - a);
let sag = 0.43;
if (a === 0 && b === 6) sag = x < 3 ? 0.24 : 0.22;
return 7.82 - 4 * sag * t * (1 - t);
}
}
return 7.82;
}
// Small boundary fencing
for (let x = -25; x <= 25; x += 2.5) {
cylinder(0.055, 0.065, 1.15, x, 0.57, -4.3, M.wood, 6);
}
box(50, 0.08, 0.08, 0, 0.95, -4.3, M.wood);
box(50, 0.08, 0.08, 0, 0.55, -4.3, M.wood);
// Direct camera controls: orbit, pan, zoom, keyboard, and touch pinch.
const target = new THREE.Vector3(0, 1.8, 1.4);
const spherical = new THREE.Spherical(43, 1.31, 0.56);
const defaultTarget = target.clone();
const defaultRadius = 43;
let defaultPhi = 1.31;
let defaultTheta = 0.56;
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.28, 1.49);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 17, 72);
camera.position.copy(target).add(new THREE.Vector3().setFromSpherical(spherical));
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
target.copy(defaultTarget);
spherical.radius = defaultRadius;
spherical.phi = defaultPhi;
spherical.theta = defaultTheta;
updateCamera();
}
updateCamera();
const pointers = new Map();
let activePointer = null;
let lastPinchDistance = 0;
let dragMode = "orbit";
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
renderer.domElement.addEventListener("contextmenu", e => e.preventDefault());
renderer.domElement.addEventListener("pointerdown", e => {
renderer.domElement.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
activePointer = e.pointerId;
dragMode = e.shiftKey || e.button === 2 ? "pan" : "orbit";
if (pointers.size === 2) lastPinchDistance = pointerDistance();
});
renderer.domElement.addEventListener("pointermove", e => {
if (!pointers.has(e.pointerId)) return;
const old = pointers.get(e.pointerId);
const dx = e.clientX - old.x;
const dy = e.clientY - old.y;
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
if (pointers.size >= 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
spherical.radius *= lastPinchDistance / distance;
updateCamera();
}
lastPinchDistance = distance;
return;
}
if (dragMode === "pan") {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = spherical.radius * 0.0012;
target.addScaledVector(right, -dx * scale);
target.addScaledVector(up, dy * scale);
target.x = THREE.MathUtils.clamp(target.x, -15, 15);
target.y = THREE.MathUtils.clamp(target.y, 0.5, 6);
target.z = THREE.MathUtils.clamp(target.z, -8, 10);
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
}
updateCamera();
});
function releasePointer(e) {
pointers.delete(e.pointerId);
if (activePointer === e.pointerId) {
activePointer = pointers.size ? [...pointers.keys()][0] : null;
}
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener("wheel", e => {
e.preventDefault();
spherical.radius *= Math.exp(e.deltaY * 0.001);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
addEventListener("keydown", e => {
let handled = true;
switch (e.key.toLowerCase()) {
case "arrowleft": spherical.theta += 0.08; break;
case "arrowright": spherical.theta -= 0.08; break;
case "arrowup": spherical.phi -= 0.06; break;
case "arrowdown": spherical.phi += 0.06; break;
case "+":
case "=": spherical.radius *= 0.9; break;
case "-":
case "_": spherical.radius *= 1.1; break;
case "r": resetCamera(); break;
default: handled = false;
}
if (handled) {
e.preventDefault();
updateCamera();
}
});
document.getElementById("resetButton").addEventListener("click", resetCamera);
const labelsButton = document.getElementById("labelsButton");
labelsButton.addEventListener("click", () => {
labelGroup.visible = !labelGroup.visible;
labelsButton.textContent = labelGroup.visible ? "Hide labels" : "Show labels";
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.fov = camera.aspect < 0.8 ? 55 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
const clock = new THREE.Clock();
function animate() {
const t = clock.getElapsedTime();
const cycle = (t % 8) / 8;
nearPacket.visible = false;
farPacket.visible = false;
if (cycle < 0.43) {
const p = smoothstep(cycle / 0.43);
const x = THREE.MathUtils.lerp(-18, 2.08, p);
nearPacket.position.set(x, wireHeightAt(x) + 0.1, 1.78);
nearPacket.scale.setScalar(THREE.MathUtils.lerp(1, 0.25, smoothstep((p - 0.82) / 0.18)));
nearPacket.visible = true;
pulseLight.position.copy(nearPacket.position);
pulseLight.intensity = 0.9;
} else if (cycle > 0.50 && cycle < 0.93) {
const p = smoothstep((cycle - 0.50) / 0.43);
const x = THREE.MathUtils.lerp(18, 3.92, p);
farPacket.position.set(x, wireHeightAt(x) + 0.1, 1.78);
farPacket.scale.setScalar(THREE.MathUtils.lerp(1, 0.25, smoothstep((p - 0.82) / 0.18)));
farPacket.visible = true;
pulseLight.position.copy(farPacket.position);
pulseLight.intensity = 0.9;
} else {
pulseLight.intensity = 0.15;
}
breakLight.intensity = 0.8 + Math.sin(t * 5.2) * 0.25;
officeStatusLamp.material.emissiveIntensity = 0.9 + Math.sin(t * 3.5) * 0.18;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```