Prompt specification
Build or customize the Three.js 3D scene "Fictional Metropolitan Transit 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: Fictional Metropolitan Transit Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fictional-metropolitan-transit-table-x2115
Scene Description Prompt:
Create a fictional voxel transit city with districts, route lines, and an interchange. One self-contained HTML file using Three.js from cdnjs.
Working Three.js Starter (fictional-metropolitan-transit-table-x2115):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mosaic City — Voxel Transit Atlas</title>
<style>
:root {
--ink: #17242d;
--panel: rgba(245, 248, 244, 0.9);
--line: rgba(23, 36, 45, 0.14);
--ember: #ff5364;
--tidal: #00bfc4;
--sun: #ffc247;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bdd4d8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#city {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 48%, rgba(18, 37, 45, 0.13) 100%),
linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 25%);
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 3;
}
.map-label {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
transform-origin: center;
will-change: transform;
}
.district-label {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 3px;
background: rgba(23, 36, 45, 0.74);
box-shadow: 0 5px 18px rgba(13, 29, 35, 0.12);
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.station-label {
padding: 4px 7px;
border-left: 3px solid var(--station-color, white);
border-radius: 2px;
background: rgba(250, 251, 246, 0.94);
box-shadow: 0 4px 12px rgba(13, 29, 35, 0.14);
color: #23343d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
}
.union-label {
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 3px;
background: #17242d;
box-shadow: 0 7px 20px rgba(13, 29, 35, 0.22);
color: white;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.interactive {
pointer-events: auto;
}
#brand {
top: 24px;
left: 24px;
width: 360px;
max-width: calc(100vw - 48px);
}
.brand-row {
display: flex;
align-items: flex-start;
gap: 12px;
}
#brandButton {
display: flex;
align-items: center;
gap: 11px;
padding: 0;
border: 0;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
}
.brand-mark {
position: relative;
width: 39px;
height: 39px;
flex: 0 0 auto;
border: 3px solid var(--ink);
background:
linear-gradient(90deg, transparent 45%, var(--ink) 45%, var(--ink) 55%, transparent 55%),
linear-gradient(transparent 45%, var(--ink) 45%, var(--ink) 55%, transparent 55%),
#edf2e9;
box-shadow: 5px 5px 0 rgba(23, 36, 45, 0.15);
}
.brand-mark::after {
content: "";
position: absolute;
width: 9px;
height: 9px;
right: -5px;
top: -5px;
background: var(--ember);
border: 2px solid var(--ink);
}
.eyebrow {
margin-bottom: 3px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.2em;
text-transform: uppercase;
opacity: 0.64;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.5vw, 30px);
font-weight: 950;
line-height: 0.94;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.brand-subtitle {
margin: 7px 0 0 50px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
opacity: 0.68;
}
#legend {
top: 24px;
right: 24px;
width: 244px;
padding: 15px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 7px;
background: var(--panel);
box-shadow: 0 15px 45px rgba(26, 47, 53, 0.13);
backdrop-filter: blur(13px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live-pill {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 4px 6px;
border-radius: 999px;
background: rgba(42, 176, 116, 0.12);
color: #287c5b;
font-size: 8px;
letter-spacing: 0.08em;
}
.live-pill::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #35b77c;
box-shadow: 0 0 0 3px rgba(53, 183, 124, 0.13);
}
.route-row {
display: grid;
grid-template-columns: 23px 1fr auto;
align-items: center;
width: 100%;
gap: 8px;
margin-top: 5px;
padding: 9px 8px;
border: 1px solid transparent;
border-radius: 4px;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.route-row:hover,
.route-row.active {
border-color: var(--line);
background: rgba(255, 255, 255, 0.72);
transform: translateX(-2px);
}
.route-code {
display: grid;
place-items: center;
width: 23px;
height: 23px;
border-radius: 3px;
background: var(--route-color);
color: #14222a;
font-size: 9px;
font-weight: 950;
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.route-name {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.025em;
}
.route-meta {
margin-top: 2px;
color: #66757b;
font-size: 8px;
font-weight: 700;
}
.route-count {
color: #7b878b;
font-size: 9px;
font-weight: 800;
}
.legend-footer {
display: flex;
justify-content: space-between;
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #68767b;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#detail {
left: 24px;
bottom: 24px;
width: 330px;
padding: 17px 18px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 7px;
background: var(--panel);
box-shadow: 0 15px 45px rgba(26, 47, 53, 0.13);
backdrop-filter: blur(13px);
}
#detailKicker {
color: #6a7a7f;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#detailTitle {
margin: 5px 0 7px;
font-size: 21px;
line-height: 1;
letter-spacing: -0.035em;
}
#detailText {
margin: 0;
color: #526269;
font-size: 11px;
font-weight: 550;
line-height: 1.55;
}
#detailMeta {
display: inline-block;
margin-top: 12px;
padding: 5px 7px;
border-radius: 3px;
background: rgba(23, 36, 45, 0.07);
color: #405158;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#help {
right: 24px;
bottom: 25px;
padding: 8px 10px;
border-radius: 4px;
background: rgba(23, 36, 45, 0.76);
color: rgba(255, 255, 255, 0.86);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.055em;
backdrop-filter: blur(8px);
}
#zoomControls {
position: fixed;
right: 24px;
bottom: 66px;
z-index: 6;
display: grid;
gap: 4px;
}
.zoom-button {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 4px;
background: rgba(245, 248, 244, 0.9);
color: var(--ink);
box-shadow: 0 5px 16px rgba(22, 41, 48, 0.12);
cursor: pointer;
}
.zoom-button:hover {
background: white;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #bdd4d8;
transition: opacity 400ms ease, visibility 400ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-box {
padding: 18px 22px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 5px;
background: rgba(245, 248, 244, 0.82);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@media (max-width: 760px) {
#brand {
top: 16px;
left: 16px;
}
#legend {
top: auto;
right: 12px;
bottom: 12px;
width: 185px;
padding: 10px;
}
#detail {
left: 12px;
bottom: 12px;
width: calc(100vw - 220px);
min-width: 145px;
padding: 12px;
}
#detailText {
display: none;
}
#detailTitle {
font-size: 16px;
}
#help {
display: none;
}
#zoomControls {
right: 12px;
bottom: 186px;
}
.route-row {
grid-template-columns: 20px 1fr;
padding: 6px;
}
.route-count,
.route-meta {
display: none;
}
.brand-subtitle {
display: none;
}
}
</style>
</head>
<body>
<canvas id="city" aria-label="Interactive voxel transit city"></canvas>
<div id="vignette"></div>
<div id="labels"></div>
<header id="brand" class="hud">
<div class="brand-row">
<button id="brandButton" class="interactive" title="Reset the city view">
<span class="brand-mark"></span>
<span>
<span class="eyebrow">Fictional Transit Atlas · 2049</span>
<h1>Mosaic City</h1>
</span>
</button>
</div>
<div class="brand-subtitle">THREE ELEVATED LINES / ONE CENTRAL INTERCHANGE</div>
</header>
<aside id="legend" class="hud interactive">
<div class="panel-heading">
<span>Metro Network</span>
<span class="live-pill">Live</span>
</div>
<div id="routeList"></div>
<div class="legend-footer">
<span>9 Stations</span>
<span>Voxel Grid 08</span>
</div>
</aside>
<section id="detail" class="hud">
<div id="detailKicker">Interchange 01</div>
<h2 id="detailTitle">Union Interchange</h2>
<p id="detailText">
A stacked transfer hub joining the Ember Loop, Tidal Line, and Sun Spur above Mosaic City's civic heart.
</p>
<div id="detailMeta">3 lines · central transfer · open 05:00–01:30</div>
</section>
<div id="zoomControls" class="interactive">
<button class="zoom-button" id="zoomIn" aria-label="Zoom in">+</button>
<button class="zoom-button" id="zoomOut" aria-label="Zoom out">−</button>
</div>
<div id="help" class="hud">
DRAG TO ORBIT · WHEEL TO ZOOM · SHIFT-DRAG TO PAN · WASD TO MOVE · R TO RESET
</div>
<div id="loading">
<div class="loading-box">Assembling voxel transit city…</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 canvas = document.querySelector("#city");
const labelsLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbdd4d8);
scene.fog = new THREE.Fog(0xbdd4d8, 145, 285);
const camera = new THREE.OrthographicCamera(-95, 95, 60, -60, 0.1, 500);
scene.add(new THREE.HemisphereLight(0xeafcff, 0x7f8067, 1.55));
const sun = new THREE.DirectionalLight(0xfff3d6, 2.65);
sun.position.set(-55, 95, 38);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -95;
sun.shadow.camera.right = 95;
sun.shadow.camera.top = 90;
sun.shadow.camera.bottom = -90;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 220;
sun.shadow.normalBias = 0.035;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fdaff, 0.45);
fill.position.set(60, 40, -60);
scene.add(fill);
let randomSeed = 2049;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const range = (a, b) => a + (b - a) * random();
const clamp = THREE.MathUtils.clamp;
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.03,
flatShading: true,
...options
});
}
const materials = {
base: standardMaterial(0x61716d),
cityGround: standardMaterial(0xa8b39c),
road: standardMaterial(0x455158),
roadEdge: standardMaterial(0xc4c3b5),
lane: standardMaterial(0xe5dfc5),
plaza: standardMaterial(0xc9c6b6),
civic: standardMaterial(0xd9d1b9),
civicRoof: standardMaterial(0x69777c),
old: standardMaterial(0xc97958),
oldRoof: standardMaterial(0x8d5546),
market: standardMaterial(0xb85b54),
marketRoof: standardMaterial(0x694a48),
maker: standardMaterial(0x566f83),
makerRoof: standardMaterial(0x314a5e),
innovation: standardMaterial(0x668f9d),
innovationRoof: standardMaterial(0x416875),
garden: standardMaterial(0xe7dfc7),
gardenRoof: standardMaterial(0x768b71),
cream: standardMaterial(0xe5d9b9),
paleBlue: standardMaterial(0x94b9c5),
teal: standardMaterial(0x4f9a95),
yellow: standardMaterial(0xd9a646),
orange: standardMaterial(0xd97c48),
dark: standardMaterial(0x27363d),
trackBed: standardMaterial(0x334047, { metalness: 0.45, roughness: 0.5 }),
glass: standardMaterial(0x9dd5df, {
metalness: 0.28,
roughness: 0.25,
transparent: true,
opacity: 0.72
}),
treeTrunk: standardMaterial(0x70503b),
treeCrown: standardMaterial(0x5f8d61),
treeCrownLight: standardMaterial(0x7da56d),
water: standardMaterial(0x62b8c6, {
metalness: 0.15,
roughness: 0.3
})
};
const districtGround = {
civic: materials.plaza,
market: standardMaterial(0xbba08a),
maker: standardMaterial(0x8c9693),
innovation: standardMaterial(0x98aaa7),
garden: standardMaterial(0x91ad83)
};
function addBox(parent, w, h, d, x, y, z, material, castShadow = true, receiveShadow = false) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Ground, roads, and district blocks
// ---------------------------------------------------------------------
addBox(scene, 152, 0.8, 132, 0, -0.4, 0, materials.base, false, true);
addBox(scene, 150, 0.14, 130, 0, 0.05, 0, materials.cityGround, false, true);
const roadX = [-60, -40, -20, 0, 20, 40, 60];
const roadZ = [-60, -40, -20, 0, 20, 40, 60];
for (const x of roadX) {
addBox(scene, 4.7, 0.12, 124, x, 0.16, 0, materials.roadEdge, false, true);
addBox(scene, 3.35, 0.14, 124, x, 0.25, 0, materials.road, false, true);
for (let z = -57; z <= 57; z += 6) {
if (!roadZ.some((crossZ) => Math.abs(crossZ - z) < 4)) {
addBox(scene, 0.13, 0.035, 1.55, x, 0.34, z, materials.lane, false);
}
}
}
for (const z of roadZ) {
addBox(scene, 124, 0.12, 4.7, 0, 0.17, z, materials.roadEdge, false, true);
addBox(scene, 124, 0.14, 3.35, 0, 0.26, z, materials.road, false, true);
for (let x = -57; x <= 57; x += 6) {
if (!roadX.some((crossX) => Math.abs(crossX - x) < 4)) {
addBox(scene, 1.55, 0.035, 0.13, x, 0.35, z, materials.lane, false);
}
}
}
// Crosswalks around the central junction.
for (const offset of [-2.8, -1.4, 0, 1.4, 2.8]) {
addBox(scene, 0.55, 0.04, 4.8, offset, 0.37, 5.1, materials.lane, false);
addBox(scene, 0.55, 0.04, 4.8, offset, 0.37, -5.1, materials.lane, false);
addBox(scene, 4.8, 0.04, 0.55, 5.1, 0.38, offset, materials.lane, false);
addBox(scene, 4.8, 0.04, 0.55, -5.1, 0.38, offset, materials.lane, false);
}
const blockCenters = [-50, -30, -10, 10, 30, 50];
const windowInstances = [];
const treeTrunks = [];
const treeCrowns = [];
const buildingPalettes = {
civic: [
materials.civic,
materials.cream,
standardMaterial(0xc7bda2),
standardMaterial(0x8fa6a4)
],
market: [
materials.market,
standardMaterial(0xca735d),
standardMaterial(0xd0a75c),
materials.old
],
maker: [
materials.maker,
standardMaterial(0x687b91),
standardMaterial(0x6f9b98),
standardMaterial(0x776d7e)
],
innovation: [
materials.innovation,
materials.paleBlue,
standardMaterial(0x7896a0),
standardMaterial(0x548287)
],
garden: [
materials.garden,
standardMaterial(0xd7c7a3),
standardMaterial(0x9db4a0),
materials.cream
]
};
function districtAt(x, z) {
if (z < -30) return "market";
if (x < -20) return "innovation";
if (x > 20) return "maker";
if (z > 20) return "garden";
return "civic";
}
function queueWindow(x, y, z, sx, sz, color) {
windowInstances.push({ x, y, z, sx, sz, color });
}
function createBuilding(x, z, w, d, h, district, paletteIndex) {
const palette = buildingPalettes[district];
const bodyMaterial = palette[paletteIndex % palette.length];
const roofMaterial =
district === "civic" ? materials.civicRoof :
district === "market" ? materials.marketRoof :
district === "maker" ? materials.makerRoof :
district === "innovation" ? materials.innovationRoof :
materials.gardenRoof;
const baseY = 0.38;
addBox(scene, w, h, d, x, baseY + h / 2, z, bodyMaterial);
addBox(
scene,
w + 0.28,
0.28,
d + 0.28,
x,
baseY + h + 0.08,
z,
roofMaterial
);
if (random() > 0.42) {
const roofWidth = range(0.9, Math.max(1.1, w * 0.38));
addBox(
scene,
roofWidth,
range(0.5, 1.3),
range(0.9, Math.max(1.1, d * 0.36)),
x + range(-w * 0.16, w * 0.16),
baseY + h + 0.55,
z + range(-d * 0.16, d * 0.16),
roofMaterial
);
}
if (district === "market" && random() > 0.25) {
const awningMaterial = palette[(paletteIndex + 1) % palette.length];
addBox(
scene,
w * 0.82,
0.18,
1.15,
x,
baseY + 1.45,
z + d / 2 + 0.46,
awningMaterial
);
}
const rowCount = Math.max(1, Math.floor((h - 1.3) / 2.15));
const columnCount = Math.max(1, Math.floor((w - 0.6) / 1.45));
for (let row = 0; row < rowCount; row++) {
const y = baseY + 1.75 + row * 2.15;
for (let column = 0; column < columnCount; column++) {
const wx = x - w / 2 + 0.85 + column * 1.45;
const color = random() < 0.48
? new THREE.Color(0xffd178)
: random() < 0.7
? new THREE.Color(0x8bd8ee)
: new THREE.Color(0x465860);
queueWindow(wx, y, z + d / 2 + 0.045, 0.62, 0.055, color);
queueWindow(wx, y, z - d / 2 - 0.045, 0.62, 0.055, color);
}
const sideColumnCount = Math.max(1, Math.floor((d - 0.6) / 1.45));
for (let column = 0; column < sideColumnCount; column++) {
const wz = z - d / 2 + 0.85 + column * 1.45;
const color = random() < 0.48
? new THREE.Color(0xffd178)
: random() < 0.7
? new THREE.Color(0x8bd8ee)
: new THREE.Color(0x465860);
queueWindow(x + w / 2 + 0.045, y, wz, 0.055, 0.62, color);
queueWindow(x - w / 2 - 0.045, y, wz, 0.055, 0.62, color);
}
}
}
function createTree(x, z, size = 1) {
const trunkHeight = 1.4 * size;
treeTrunks.push({
x,
y: 0.35 + trunkHeight / 2,
z,
sx: 0.46 * size,
sy: trunkHeight,
sz: 0.46 * size
});
treeCrowns.push({
x,
y: 0.35 + trunkHeight + 0.65 * size,
z,
sx: 2.0 * size,
sy: 1.6 * size,
sz: 2.0 * size,
material: materials.treeCrown
});
treeCrowns.push({
x: x + 0.3 * size,
y: 0.35 + trunkHeight + 1.35 * size,
z: z - 0.15 * size,
sx: 1.35 * size,
sy: 1.15 * size,
sz: 1.35 * size,
material: materials.treeCrownLight
});
}
for (const cx of blockCenters) {
for (const cz of blockCenters) {
if (Math.abs(cx) <= 10 && Math.abs(cz) <= 10) continue;
if ((cx === 30 && cz === -10) || (cx === 50 && cz === 10)) continue;
const district = districtAt(cx, cz);
addBox(
scene,
16.7,
0.2,
16.7,
cx,
0.28,
cz,
districtGround[district],
false,
true
);
const isPark = district === "garden" && random() < 0.68;
if (isPark) {
if (random() > 0.4) {
addBox(
scene,
range(6.5, 9.5),
0.07,
range(3.8, 5.5),
cx + range(-2, 2),
0.42,
cz + range(-2, 2),
materials.water,
false,
true
);
}
for (let i = 0; i < 12; i++) {
const tx = cx + range(-6.5, 6.5);
const tz = cz + range(-6.5, 6.5);
createTree(tx, tz, range(0.75, 1.2));
}
for (let i = 0; i < 3; i++) {
addBox(
scene,
2.2,
0.22,
0.55,
cx + range(-5, 5),
0.62,
cz + range(-5, 5),
materials.treeTrunk
);
}
} else {
const offsets = district === "garden"
? [[-4.2, -3.4], [4.2, -3.4], [-4.2, 4.0]]
: [[-4.3, -4.2], [4.3, -4.2], [-4.3, 4.2], [4.3, 4.2]];
offsets.forEach(([ox, oz], index) => {
if (district === "civic" && random() < 0.17) return;
const w = range(3.4, 5.35);
const d = range(3.4, 5.35);
let h;
if (district === "market") h = range(4.0, 8.4);
else if (district === "garden") h = range(2.8, 6.8);
else if (district === "maker") h = range(8.5, 19.5);
else if (district === "innovation") h = range(7.5, 17.5);
else h = range(4.8, 11.5);
createBuilding(
cx + ox,
cz + oz,
w,
d,
h,
district,
index + Math.floor(random() * 4)
);
});
}
}
}
function createTower(x, z, h, color, roofColor) {
const body = standardMaterial(color, { roughness: 0.55 });
const band = standardMaterial(roofColor, { roughness: 0.6 });
addBox(scene, 7.2, h, 7.2, x, 0.4 + h / 2, z, body);
addBox(scene, 7.8, 0.5, 7.8, x, 0.65 + h, z, band);
for (let y = 3; y < h - 1; y += 3.2) {
addBox(scene, 7.5, 0.18, 7.5, x, y, z, band, false);
}
addBox(scene, 1.2, 4.5, 1.2, x + 1.9, h + 2.8, z - 1.9, band);
addBox(scene, 0.3, 3.5, 0.3, x - 1.7, h + 2.3, z + 1.7, materials.dark);
addBox(scene, 0.7, 0.7, 0.7, x - 1.7, h + 4.2, z + 1.7, materials.yellow);
}
createTower(30, -10, 28, 0x789ba7, 0x355666);
createTower(50, 10, 35, 0x5e7187, 0x293f56);
createTower(-50, 10, 23, 0x6c9ca3, 0x3c6972);
// ---------------------------------------------------------------------
// Instanced windows and trees
// ---------------------------------------------------------------------
const windowMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
toneMapped: false
});
const windowMesh = new THREE.InstancedMesh(
unitBox,
windowMaterial,
windowInstances.length
);
const dummy = new THREE.Object3D();
windowInstances.forEach((window, index) => {
dummy.position.set(window.x, window.y, window.z);
dummy.scale.set(window.sx, 0.55, window.sz);
dummy.updateMatrix();
windowMesh.setMatrixAt(index, dummy.matrix);
windowMesh.setColorAt(index, window.color);
});
windowMesh.instanceMatrix.needsUpdate = true;
if (windowMesh.instanceColor) windowMesh.instanceColor.needsUpdate = true;
windowMesh.computeBoundingSphere();
scene.add(windowMesh);
const trunkMesh = new THREE.InstancedMesh(
unitBox,
materials.treeTrunk,
treeTrunks.length
);
treeTrunks.forEach((tree, index) => {
dummy.position.set(tree.x, tree.y, tree.z);
dummy.scale.set(tree.sx, tree.sy, tree.sz);
dummy.updateMatrix();
trunkMesh.setMatrixAt(index, dummy.matrix);
});
trunkMesh.instanceMatrix.needsUpdate = true;
trunkMesh.computeBoundingSphere();
scene.add(trunkMesh);
const crownGroups = [
{ material: materials.treeCrown, items: treeCrowns.filter((tree) => tree.material === materials.treeCrown) },
{ material: materials.treeCrownLight, items: treeCrowns.filter((tree) => tree.material === materials.treeCrownLight) }
];
crownGroups.forEach((group) => {
const mesh = new THREE.InstancedMesh(unitBox, group.material, group.items.length);
group.items.forEach((tree, index) => {
dummy.position.set(tree.x, tree.y, tree.z);
dummy.scale.set(tree.sx, tree.sy, tree.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.computeBoundingSphere();
scene.add(mesh);
});
// ---------------------------------------------------------------------
// Elevated transit routes
// ---------------------------------------------------------------------
const routes = [
{
code: "E1",
name: "Ember Loop",
color: 0xff5364,
css: "#ff5364",
y: 4.25,
path: [
[-62, -38], [-20, -38], [-20, -18], [0, -18], [0, 0],
[0, 18], [20, 18], [20, 38], [62, 38]
],
stops: [
{ index: 1, name: "Old Mint" },
{ index: 4, name: "Union Interchange" },
{ index: 7, name: "Copper Row" }
],
description: "A warm-colored orbital service connecting Market Row, the central exchange, and the eastern workshops."
},
{
code: "T2",
name: "Tidal Line",
color: 0x00bfc4,
css: "#00bfc4",
y: 5.4,
path: [
[-62, 18], [-42, 18], [-42, -2], [-22, -2], [-22, -22],
[2, -22], [2, 0], [2, 22], [22, 22], [22, -42], [62, -42]
],
stops: [
{ index: 2, name: "Byte Park" },
{ index: 6, name: "Union Interchange" },
{ index: 9, name: "Harbor Gate" }
],
description: "The turquoise cross-city line linking Innovation West, Union Interchange, and the southern harbor district."
},
{
code: "S3",
name: "Sun Spur",
color: 0xffc247,
css: "#ffc247",
y: 6.55,
path: [
[-52, -58], [52, -58], [52, 8], [32, 8], [32, -8],
[12, -8], [12, 8], [-8, 8], [-8, 28], [18, 28], [18, 48], [58, 48]
],
stops: [
{ index: 2, name: "Solar Yards" },
{ index: 6, name: "Union Interchange" },
{ index: 10, name: "Orchard End" }
],
description: "A high-level golden spur running above the market yards, the civic core, and the Garden Belt."
}
];
const pickables = [];
const mapLabels = [];
const stations = [];
function registerLabel(text, position, className, color = null) {
const element = document.createElement("div");
element.className = `map-label ${className}`;
element.textContent = text;
if (color) element.style.setProperty("--station-color", color);
labelsLayer.appendChild(element);
mapLabels.push({ element, position: position.clone() });
return element;
}
function registerStation(name, position, route, kind = "station") {
const data = {
name,
position,
route,
kind,
description: kind === "interchange"
? "A stacked transfer hub joining the Ember Loop, Tidal Line, and Sun Spur above Mosaic City's civic heart."
: `${name} is a compact elevated stop on the ${route.name}, built around a single island platform and a covered voxel concourse.`
};
stations.push(data);
return data;
}
function addBeam(x1, z1, x2, z2, y, width, height, material) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const beam = addBox(
scene,
length + 0.35,
height,
width,
(x1 + x2) / 2,
y,
(z1 + z2) / 2,
material
);
beam.rotation.y = angle;
return beam;
}
routes.forEach((route, routeIndex) => {
route.trackMaterial = standardMaterial(route.color, {
emissive: route.color,
emissiveIntensity: 0.28,
roughness: 0.46,
metalness: 0.18
});
route.points = route.path.map(([x, z]) => new THREE.Vector3(x, route.y, z));
route.segments = [];
route.length = 0;
for (let i = 0; i < route.points.length - 1; i++) {
const a = route.points[i];
const b = route.points[i + 1];
const segmentLength = Math.hypot(b.x - a.x, b.z - a.z);
route.segments.push({
a,
b,
length: segmentLength,
start: route.length
});
route.length += segmentLength;
addBeam(
a.x, a.z, b.x, b.z,
route.y - 0.18,
2.0, 0.46,
materials.trackBed
);
const segmentBeam = addBeam(
a.x, a.z, b.x, b.z,
route.y + 0.18,
1.05, 0.22,
route.trackMaterial
);
const distance = 10;
for (let d = distance; d < segmentLength - 4; d += 13) {
const t = d / segmentLength;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
if (Math.hypot(x, z) < 15) continue;
const pylonHeight = route.y - 0.65;
addBox(scene, 0.62, pylonHeight, 0.62, x, 0.35 + pylonHeight / 2, z, materials.trackBed);
const arm = addBox(scene, 3.0, 0.34, 0.58, x, route.y - 0.5, z, materials.trackBed);
arm.rotation.y = segmentBeam.rotation.y;
}
}
route.points.forEach((point) => {
addBox(
scene,
1.45,
0.3,
1.45,
point.x,
route.y + 0.18,
point.z,
route.trackMaterial
);
});
});
function createLocalStation(route, stop) {
const point = route.points[stop.index];
const previous = route.points[Math.max(0, stop.index - 1)];
const next = route.points[Math.min(route.points.length - 1, stop.index + 1)];
const tangent = new THREE.Vector3(
next.x - previous.x,
0,
next.z - previous.z
).normalize();
const perpendicular = new THREE.Vector3(-tangent.z, 0, tangent.x);
const platformX = point.x + perpendicular.x * 3.25;
const platformZ = point.z + perpendicular.z * 3.25;
addBox(
scene,
6.7,
0.45,
5.8,
platformX,
route.y - 0.72,
platformZ,
materials.trackBed
);
addBox(
scene,
2.0,
0.2,
5.7,
platformX,
route.y - 0.43,
platformZ,
route.trackMaterial
);
const canopy = addBox(
scene,
5.2,
0.3,
4.4,
platformX,
route.y + 2.15,
platformZ,
route.trackMaterial
);
canopy.rotation.y = -Math.atan2(tangent.z, tangent.x);
for (const sx of [-2.1, 2.1]) {
for (const sz of [-1.7, 1.7]) {
addBox(
scene,
0.22,
2.4,
0.22,
platformX + sx,
route.y + 0.85,
platformZ + sz,
materials.dark
);
}
}
const signPosition = new THREE.Vector3(
platformX + perpendicular.x * 2.25,
route.y + 2.9,
platformZ + perpendicular.z * 2.25
);
addBox(scene, 1.5, 0.85, 0.18, signPosition.x, signPosition.y, signPosition.z, route.trackMaterial);
addBox(scene, 0.16, 1.3, 0.16, signPosition.x, signPosition.y - 1.05, signPosition.z, materials.dark);
const pickMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const pickMesh = addBox(
scene,
7,
4,
6,
platformX,
route.y + 0.2,
platformZ,
pickMaterial,
false
);
pickMesh.userData.stationName = stop.name;
pickables.push(pickMesh);
const labelPosition = new THREE.Vector3(
signPosition.x,
signPosition.y + 0.9,
signPosition.z
);
registerLabel(stop.name, labelPosition, "station-label", route.css);
registerStation(stop.name, labelPosition, route);
}
routes.forEach((route) => {
route.stops.forEach((stop) => {
if (!stop.name.includes("Union")) {
createLocalStation(route, stop);
}
});
});
// ---------------------------------------------------------------------
// Union Interchange
// ---------------------------------------------------------------------
addBox(scene, 28, 0.8, 28, 0, 0.85, 0, materials.civic);
addBox(scene, 24, 0.8, 24, 0, 1.65, 0, materials.dark);
addBox(scene, 13, 1.8, 13, 0, 2.9, 0, materials.glass);
addBox(scene, 14.5, 0.35, 14.5, 0, 3.95, 0, materials.civicRoof);
// Colored platform edges on three stacked interchange levels.
addBox(scene, 3.0, 0.18, 22, 0, 3.95, 0, routes[0].trackMaterial);
addBox(scene, 3.0, 0.18, 22, 2, 5.1, 0, routes[1].trackMaterial);
addBox(scene, 24, 0.18, 3.0, 0, 6.25, 8, routes[2].trackMaterial);
for (const [x, z] of [[-10, -10], [10, -10], [-10, 10], [10, 10]]) {
addBox(scene, 0.8, 6.5, 0.8, x, 3.6, z, materials.dark);
addBox(scene, 1.1, 0.55, 1.1, x, 7.0, z, routes[(x + z > 0 ? 1 : 0)].trackMaterial);
}
const beacon = new THREE.Group();
beacon.position.set(10.8, 0, 10.8);
scene.add(beacon);
addBox(beacon, 1.6, 9, 1.6, 0, 4.7, 0, materials.dark);
addBox(beacon, 2.2, 0.55, 2.2, 0, 9.25, 0, routes[1].trackMaterial);
addBox(beacon, 1.2, 0.55, 1.2, 0, 10.05, 0, routes[2].trackMaterial);
for (const [x, z] of [[-12, 0], [12, 0], [0, -12], [0, 12]]) {
addBox(scene, 4.5, 1.2, 4.5, x, 1.25, z, materials.civic);
addBox(scene, 3.4, 0.25, 3.4, x, 1.95, z, materials.road);
}
const unionPickMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const unionPick = addBox(
scene,
27,
9,
27,
0,
4.5,
0,
unionPickMaterial,
false
);
unionPick.userData.stationName = "Union Interchange";
pickables.push(unionPick);
const unionLabelPosition = new THREE.Vector3(0, 12, 0);
registerLabel("Union Interchange", unionLabelPosition, "union-label");
registerStation("Union Interchange", unionLabelPosition, routes[0], "interchange");
// District labels.
registerLabel("Market Row", new THREE.Vector3(-36, 1.5, -47), "district-label");
registerLabel("Innovation West", new THREE.Vector3(-47, 1.5, -9), "district-label");
registerLabel("Makers' Yard", new THREE.Vector3(43, 1.5, 17), "district-label");
registerLabel("Garden Belt", new THREE.Vector3(-37, 1.5, 39), "district-label");
registerLabel("Civic Plaza", new THREE.Vector3(17, 1.5, -13), "district-label");
// ---------------------------------------------------------------------
// Animated trains
// ---------------------------------------------------------------------
function createTrainCar(route) {
const car = new THREE.Group();
const bodyMaterial = standardMaterial(route.color, {
roughness: 0.38,
metalness: 0.12,
emissive: route.color,
emissiveIntensity: 0.08
});
addBox(car, 2.55, 1.15, 1.42, 0, 0.73, 0, bodyMaterial);
addBox(car, 2.15, 0.22, 1.22, 0, 1.42, 0, materials.cream);
addBox(car, 0.05, 0.48, 1.05, 1.29, 0.92, 0, materials.glass, false);
addBox(car, 1.45, 0.38, 0.05, 0, 0.95, 0.73, materials.glass, false);
addBox(car, 1.45, 0.38, 0.05, 0, 0.95, -0.73, materials.glass, false);
addBox(car, 0.35, 0.15, 0.3, 1.38, 0.52, 0, materials.lane, false);
scene.add(car);
return car;
}
routes.forEach((route, routeIndex) => {
route.cars = [];
for (let i = 0; i < 3; i++) {
route.cars.push(createTrainCar(route));
}
route.phase = routeIndex * route.length * 0.23;
});
function sampleRoute(route, distance) {
let d = ((distance % route.length) + route.length) % route.length;
for (const segment of route.segments) {
if (d <= segment.length || segment === route.segments[route.segments.length - 1]) {
const t = clamp(d / segment.length, 0, 1);
const position = new THREE.Vector3().lerpVectors(segment.a, segment.b, t);
const tangent = new THREE.Vector3().subVectors(segment.b, segment.a).normalize();
return { position, tangent };
}
d -= segment.length;
}
return { position: route.points[0].clone(), tangent: new THREE.Vector3(1, 0, 0) };
}
// ---------------------------------------------------------------------
// Route legend and information panel
// ---------------------------------------------------------------------
const routeList = document.querySelector("#routeList");
const detailKicker = document.querySelector("#detailKicker");
const detailTitle = document.querySelector("#detailTitle");
const detailText = document.querySelector("#detailText");
const detailMeta = document.querySelector("#detailMeta");
let selectedRoute = routes[0];
function selectRoute(route) {
selectedRoute = route;
routes.forEach((item) => {
item.trackMaterial.emissiveIntensity = item === route ? 0.75 : 0.28;
});
document.querySelectorAll(".route-row").forEach((button) => {
button.classList.toggle("active", button.dataset.route === route.code);
});
detailKicker.textContent = `Transit line ${route.code}`;
detailTitle.textContent = route.name;
detailText.textContent = route.description;
detailMeta.textContent = "3 stops · elevated transit · trains in motion";
const center = new THREE.Vector3();
route.points.forEach((point) => center.add(point));
center.divideScalar(route.points.length);
center.y = 0;
controls.desiredTarget.lerp(center, 0.55);
controls.desiredZoom = Math.max(controls.desiredZoom, 1.04);
}
routes.forEach((route) => {
const button = document.createElement("button");
button.className = "route-row";
button.dataset.route = route.code;
button.style.setProperty("--route-color", route.css);
button.innerHTML = `
<span class="route-code">${route.code}</span>
<span>
<span class="route-name">${route.name}</span>
<span class="route-meta" style="display:block">Elevated urban service</span>
</span>
<span class="route-count">3 stops</span>
`;
button.addEventListener("click", () => selectRoute(route));
routeList.appendChild(button);
});
// ---------------------------------------------------------------------
// Custom camera controls — no addon modules
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0, 0),
desiredTarget: new THREE.Vector3(0, 0, 0),
yaw: 0.72,
desiredYaw: 0.72,
pitch: 0.72,
desiredPitch: 0.72,
zoom: 1,
desiredZoom: 1,
distance: 180
};
selectRoute(routes[0]);
function resetCamera() {
controls.desiredTarget.set(0, 0, 0);
controls.desiredYaw = 0.72;
controls.desiredPitch = 0.72;
controls.desiredZoom = 1;
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewWidth = 190;
const viewHeight = Math.max(112, viewWidth / aspect);
camera.left = -viewWidth / 2;
camera.right = viewWidth / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
const pointer = {
active: false,
dragging: false,
button: 0,
lastX: 0,
lastY: 0,
startX: 0,
startY: 0,
distance: 0
};
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
function pickStation(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointerNdc.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (!hits.length) return;
const name = hits[0].object.userData.stationName;
const station = stations.find((item) => item.name === name);
if (!station) return;
detailKicker.textContent = station.kind === "interchange" ? "Interchange 01" : "Elevated station";
detailTitle.textContent = station.name;
detailText.textContent = station.description;
detailMeta.textContent = station.kind === "interchange"
? "3 lines · central transfer · open 05:00–01:30"
: `${station.route.name} · single island platform · step-free access`;
selectRoute(station.route);
// Keep the selection context while retaining a comfortable city overview.
controls.desiredZoom = Math.max(controls.desiredZoom, 1.07);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
pointer.active = true;
pointer.dragging = false;
pointer.button = event.button;
pointer.lastX = pointer.startX = event.clientX;
pointer.lastY = pointer.startY = event.clientY;
pointer.distance = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active) return;
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.distance += Math.abs(dx) + Math.abs(dy);
if (pointer.distance > 5) pointer.dragging = true;
const panMode = event.shiftKey || pointer.button === 2;
if (panMode) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, new THREE.Vector3(0, 1, 0)).normalize();
const worldPerPixel = 190 / window.innerWidth / camera.zoom;
controls.desiredTarget
.addScaledVector(right, -dx * worldPerPixel)
.addScaledVector(forward, dy * worldPerPixel);
} else {
controls.desiredYaw -= dx * 0.006;
controls.desiredPitch = clamp(controls.desiredPitch + dy * 0.0045, 0.36, 1.28);
}
});
canvas.addEventListener("pointerup", (event) => {
if (!pointer.active) return;
if (!pointer.dragging && pointer.distance < 7) {
pickStation(event.clientX, event.clientY);
}
pointer.active = false;
pointer.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointer.active = false;
pointer.dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredZoom = clamp(
controls.desiredZoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.4
);
},
{ passive: false }
);
document.querySelector("#zoomIn").addEventListener("click", () => {
controls.desiredZoom = clamp(controls.desiredZoom * 1.16, 0.62, 2.4);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
controls.desiredZoom = clamp(controls.desiredZoom / 1.16, 0.62, 2.4);
});
document.querySelector("#brandButton").addEventListener("click", resetCamera);
const keys = new Set();
window.addEventListener("keydown", (event) => {
keys.add(event.key.toLowerCase());
if (event.key.toLowerCase() === "r") resetCamera();
});
window.addEventListener("keyup", (event) => {
keys.delete(event.key.toLowerCase());
});
const upVector = new THREE.Vector3(0, 1, 0);
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 8);
controls.target.lerp(controls.desiredTarget, smoothing);
controls.yaw += (controls.desiredYaw - controls.yaw) * smoothing;
controls.pitch += (controls.desiredPitch - controls.pitch) * smoothing;
controls.zoom += (controls.desiredZoom - controls.zoom) * smoothing;
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, upVector).normalize();
const panSpeed = 44 * delta / camera.zoom;
if (keys.has("w")) controls.desiredTarget.addScaledVector(forward, panSpeed);
if (keys.has("s")) controls.desiredTarget.addScaledVector(forward, -panSpeed);
if (keys.has("a")) controls.desiredTarget.addScaledVector(right, -panSpeed);
if (keys.has("d")) controls.desiredTarget.addScaledVector(right, panSpeed);
const cosPitch = Math.cos(controls.pitch);
camera.position.set(
controls.target.x + controls.distance * cosPitch * Math.sin(controls.yaw),
controls.target.y + controls.distance * Math.sin(controls.pitch),
controls.target.z + controls.distance * cosPitch * Math.cos(controls.yaw)
);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
routes.forEach((route, routeIndex) => {
route.cars.forEach((car, carIndex) => {
const sample = sampleRoute(
route,
route.phase + elapsed * (5.4 + routeIndex * 0.35) - carIndex * 3.25
);
car.position.copy(sample.position);
car.position.y += 0.22;
car.rotation.y = -Math.atan2(sample.tangent.z, sample.tangent.x);
});
});
beacon.rotation.y = elapsed * 0.28;
mapLabels.forEach((label) => {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.visibility = visible ? "visible" : "hidden";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
});
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```