Prompt specification
Build or customize the Three.js 3D scene "Urban river crossing comparison" 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: Urban river crossing comparison
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/urban-river-crossing-comparison-x1343
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring river crossings linked by bridges and detours. Create a compact city section with road, rail, and pedestrian bridges. Give each traveler type its permitted network and show distinct routes to the same destination. Low-poly.
Working Three.js Starter (urban-river-crossing-comparison-x1343):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Crossingways — A City of Routes</title>
<style>
:root {
--ink: #172b35;
--muted: #657780;
--panel: rgba(247, 249, 246, 0.9);
--line: rgba(23, 43, 53, 0.14);
--road: #18a7a1;
--rail: #f28b45;
--walk: #e5b83e;
--accent: #326b73;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8e8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: absolute;
z-index: 5;
border: 1px solid rgba(255, 255, 255, 0.7);
background: var(--panel);
box-shadow: 0 16px 50px rgba(40, 64, 69, 0.16);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.title-panel {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
background: var(--accent);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 0.98;
}
.title-panel p {
margin: 12px 0 0;
max-width: 330px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.hub-chip {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid rgba(49, 107, 115, 0.18);
border-radius: 999px;
background: rgba(49, 107, 115, 0.08);
color: #315d64;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.hub-chip i {
width: 7px;
height: 7px;
border-radius: 50%;
background: #4e9aa3;
box-shadow: 0 0 0 4px rgba(78, 154, 163, 0.13);
}
.control-panel {
top: 24px;
right: 24px;
width: 232px;
padding: 15px;
border-radius: 16px;
}
.control-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.segmented {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
}
.segmented button {
height: 32px;
padding: 0;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.52);
color: var(--muted);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: 160ms ease;
}
.segmented button:hover,
.segmented button.active {
border-color: var(--accent);
background: var(--accent);
color: white;
transform: translateY(-1px);
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.control-row label {
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.control-row input {
accent-color: var(--accent);
}
.reset-button {
width: 100%;
margin-top: 13px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: 160ms ease;
}
.reset-button:hover {
border-color: var(--accent);
color: var(--accent);
}
.route-panel {
bottom: 24px;
left: 24px;
width: min(450px, calc(100vw - 48px));
padding: 15px;
border-radius: 18px;
}
.route-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 3px 11px;
}
.route-heading strong {
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#route-status {
color: var(--muted);
font-size: 10px;
}
.route-list {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.route-card {
position: relative;
min-width: 0;
padding: 12px 11px 11px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.48);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 180ms ease;
}
.route-card::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 3px;
background: var(--route-color);
content: "";
opacity: 0.75;
}
.route-card:hover,
.route-card.active {
border-color: var(--route-color);
background: white;
box-shadow: 0 8px 24px rgba(32, 53, 58, 0.09);
transform: translateY(-2px);
}
.route-card .icon {
display: grid;
width: 24px;
height: 24px;
margin-bottom: 9px;
place-items: center;
border-radius: 7px;
background: var(--route-color);
color: white;
font-size: 11px;
font-weight: 900;
}
.route-card strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
}
.route-card small {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
text-overflow: ellipsis;
white-space: nowrap;
}
.hint {
position: absolute;
right: 24px;
bottom: 24px;
z-index: 4;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 10px;
background: rgba(247, 249, 246, 0.72);
color: #526970;
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(10px);
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 7px;
background: rgba(247, 249, 246, 0.84);
box-shadow: 0 5px 14px rgba(37, 57, 62, 0.1);
color: #425a62;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
transform: translate(-50%, -50%);
white-space: nowrap;
}
.map-label.destination {
border-color: rgba(49, 107, 115, 0.28);
background: rgba(231, 242, 241, 0.94);
color: #285c64;
}
.map-label.route-label {
color: white;
border: 0;
}
.map-label.road {
background: var(--road);
}
.map-label.rail {
background: var(--rail);
}
.map-label.walk {
background: var(--walk);
color: #3e391f;
}
@media (max-width: 760px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.title-panel p {
display: none;
}
.hub-chip {
margin-top: 10px;
}
.control-panel {
top: 151px;
right: 12px;
width: 190px;
padding: 11px;
}
.route-panel {
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 11px;
}
.route-card {
padding: 10px 8px;
}
.route-card small {
display: none;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<div id="scene"></div>
<section class="panel title-panel">
<div class="eyebrow">Crossingways</div>
<h1>One city.<br />Three ways through.</h1>
<p>
A compact river district where cars, trains, and pedestrians each follow
their own permitted network toward the same civic hub.
</p>
<div class="hub-chip"><i></i> Shared destination hub</div>
</section>
<section class="panel control-panel">
<div class="control-title">Visible route</div>
<div class="segmented" aria-label="Filter routes">
<button class="active" data-filter="all">All</button>
<button data-filter="road">Road</button>
<button data-filter="rail">Rail</button>
<button data-filter="walk">Walk</button>
</div>
<div class="control-row">
<label for="infrastructure">Infrastructure layer</label>
<input id="infrastructure" type="checkbox" checked />
</div>
<button class="reset-button" id="reset-view">Reset camera</button>
</section>
<section class="panel route-panel">
<div class="route-heading">
<strong>Permitted networks</strong>
<span id="route-status">3 routes visible</span>
</div>
<div class="route-list">
<button
class="route-card active"
data-filter="road"
style="--route-color: var(--road)"
>
<span class="icon">R</span>
<strong>Road traveler</strong>
<small>North road bridge</small>
</button>
<button
class="route-card active"
data-filter="rail"
style="--route-color: var(--rail)"
>
<span class="icon">T</span>
<strong>Rail traveler</strong>
<small>Central rail bridge</small>
</button>
<button
class="route-card active"
data-filter="walk"
style="--route-color: var(--walk)"
>
<span class="icon">W</span>
<strong>Pedestrian</strong>
<small>Arched footbridge + detour</small>
</button>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · 1–4 filters routes</div>
<div id="labels"></div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const mount = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe8e8);
scene.fog = new THREE.Fog(0xdbe8e8, 38, 76);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
mount.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xeaf7f7, 0x9b876d, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d8, 3.1);
sun.position.set(-13, 23, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.0005;
scene.add(sun);
const world = new THREE.Group();
scene.add(world);
const infrastructure = new THREE.Group();
world.add(infrastructure);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const standard = (color, roughness = 0.8, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const materials = {
base: standard(0x62757a, 0.9),
leftGround: standard(0xd9d1bf, 0.96),
rightGround: standard(0xd7d4c5, 0.96),
road: standard(0x39474c, 0.92),
roadEdge: standard(0x667477, 0.9),
marking: standard(0xe6dfc6, 0.8),
railBed: standard(0x5c5851, 0.96),
sleeper: standard(0x705347, 0.96),
rail: standard(0x596166, 0.45, 0.65),
footpath: standard(0xc6ae87, 0.98),
steel: standard(0x52666b, 0.55, 0.35),
darkSteel: standard(0x34464d, 0.6, 0.4),
concrete: standard(0xa9aaa3, 0.95),
window: standard(0x55747c, 0.34, 0.12),
windowLit: standard(0xe9c87f, 0.5),
trunk: standard(0x765844, 1),
leafA: standard(0x6f9271, 1),
leafB: standard(0x557d68, 1),
leafC: standard(0x8ca079, 1),
plaza: standard(0xc4d2cb, 0.9),
white: standard(0xf4f1e6, 0.75)
};
function box(
parent,
width,
height,
depth,
x,
y,
z,
material,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.position.copy(a).add(b).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 flatSegment(
parent,
a,
b,
width,
y,
material
) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const segment = box(
parent,
width,
0.055,
length,
(a.x + b.x) / 2,
y,
(a.z + b.z) / 2,
material,
false
);
segment.rotation.y = Math.atan2(dx, dz);
return segment;
}
// -------------------------------------------------------------------------
// Diorama base, river, and banks
// -------------------------------------------------------------------------
box(world, 26.2, 0.55, 26.2, 0, -0.88, 0, materials.base, false);
box(world, 10, 0.72, 26, -7.55, -0.36, 0, materials.leftGround, false);
box(world, 10, 0.72, 26, 7.55, -0.36, 0, materials.rightGround, false);
const waterGeometry = new THREE.PlaneGeometry(5.08, 26, 8, 26)
.rotateX(-Math.PI / 2)
.toNonIndexed();
const waterPalette = [
new THREE.Color(0x6caeb8),
new THREE.Color(0x78bac0),
new THREE.Color(0x5fa6b2),
new THREE.Color(0x8ac4c5)
];
const waterColors = [];
for (let i = 0; i < waterGeometry.attributes.position.count; i += 3) {
const color =
waterPalette[Math.floor(Math.random() * waterPalette.length)];
for (let j = 0; j < 3; j++) {
waterColors.push(color.r, color.g, color.b);
}
}
waterGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.34,
metalness: 0.05,
flatShading: true
})
);
water.position.y = -0.08;
water.receiveShadow = true;
world.add(water);
// -------------------------------------------------------------------------
// Roads
// -------------------------------------------------------------------------
const roadZ = -5.5;
const roadWidth = 1.7;
// Land-side road surfaces.
box(
infrastructure,
9.9,
0.075,
roadWidth,
-7.55,
0.025,
roadZ,
materials.road,
false
);
box(
infrastructure,
9.9,
0.075,
roadWidth,
7.55,
0.025,
roadZ,
materials.road,
false
);
box(
infrastructure,
roadWidth,
0.075,
20.1,
-10.2,
0.025,
-0.35,
materials.road,
false
);
box(
infrastructure,
roadWidth,
0.075,
20.1,
10.2,
0.025,
-0.35,
materials.road,
false
);
// Road bridge deck and ramp-like approaches.
box(
infrastructure,
5.15,
0.27,
2.2,
0,
0.115,
roadZ,
materials.roadEdge
);
const leftRoadRamp = box(
infrastructure,
1.05,
0.17,
2.2,
-3.1,
0.075,
roadZ,
materials.roadEdge
);
leftRoadRamp.rotation.z = 0.18;
const rightRoadRamp = box(
infrastructure,
1.05,
0.17,
2.2,
3.1,
0.075,
roadZ,
materials.roadEdge
);
rightRoadRamp.rotation.z = -0.18;
// Road bridge supports.
for (const x of [-1.45, 1.45]) {
box(
infrastructure,
0.42,
1.25,
1.45,
x,
-0.52,
roadZ,
materials.concrete
);
}
// Railings.
for (const z of [roadZ - 1.02, roadZ + 1.02]) {
cylinderBetween(
infrastructure,
new THREE.Vector3(-2.55, 0.95, z),
new THREE.Vector3(2.55, 0.95, z),
0.045,
materials.steel
);
for (let x = -2.5; x <= 2.51; x += 0.5) {
cylinderBetween(
infrastructure,
new THREE.Vector3(x, 0.25, z),
new THREE.Vector3(x, 0.95, z),
0.032,
materials.steel
);
}
}
// Lane markings.
for (let x = -12.1; x < 12.5; x += 1.25) {
if (Math.abs(x) > 2.7) {
box(
infrastructure,
0.55,
0.018,
0.055,
x,
0.075,
roadZ,
materials.marking,
false
);
}
}
for (const x of [-10.2, 10.2]) {
for (let z = -9.8; z < 9.7; z += 1.25) {
box(
infrastructure,
0.055,
0.018,
0.55,
x,
0.075,
z,
materials.marking,
false
);
}
}
// -------------------------------------------------------------------------
// Rail line and truss bridge
// -------------------------------------------------------------------------
const railZ = 1;
for (const x of [-7.55, 7.55]) {
box(
infrastructure,
9.9,
0.08,
2.05,
x,
0.015,
railZ,
materials.railBed,
false
);
}
// Sleepers.
for (let x = -12.3; x <= 12.3; x += 0.62) {
const onBridge = Math.abs(x) < 2.72;
const y = onBridge ? 0.405 : 0.075;
box(
infrastructure,
0.13,
0.065,
1.72,
x,
y,
railZ,
materials.sleeper,
false
);
}
// Rails on land.
for (const x of [-7.55, 7.55]) {
for (const z of [railZ - 0.48, railZ + 0.48]) {
box(
infrastructure,
9.9,
0.075,
0.075,
x,
0.135,
z,
materials.rail,
false
);
}
}
// Rail bridge.
box(
infrastructure,
5.4,
0.28,
2.42,
0,
0.315,
railZ,
materials.darkSteel
);
for (const z of [railZ - 0.48, railZ + 0.48]) {
box(
infrastructure,
5.1,
0.075,
0.075,
0,
0.535,
z,
materials.rail,
false
);
}
for (const x of [-1.45, 1.45]) {
box(
infrastructure,
0.44,
1.6,
1.8,
x,
-0.62,
railZ,
materials.concrete
);
}
// Low-poly truss.
const trussTop = 1.62;
const trussXs = [-2.45, -1.63, -0.81, 0, 0.81, 1.63, 2.45];
for (const z of [railZ - 1.03, railZ + 1.03]) {
cylinderBetween(
infrastructure,
new THREE.Vector3(-2.5, trussTop, z),
new THREE.Vector3(2.5, trussTop, z),
0.055,
materials.steel
);
for (const x of trussXs) {
cylinderBetween(
infrastructure,
new THREE.Vector3(x, 0.44, z),
new THREE.Vector3(x, trussTop, z),
0.04,
materials.steel
);
}
for (let i = 0; i < trussXs.length - 1; i++) {
const a = new THREE.Vector3(trussXs[i], 0.47, z);
const b = new THREE.Vector3(
trussXs[i + 1],
trussTop,
z
);
cylinderBetween(
infrastructure,
a,
b,
0.03,
materials.steel
);
}
}
// -------------------------------------------------------------------------
// Pedestrian paths and arched footbridge
// -------------------------------------------------------------------------
const footZ = 7.5;
flatSegment(
infrastructure,
new THREE.Vector3(-10.3, 0, footZ),
new THREE.Vector3(-2.65, 0, footZ),
0.85,
0.055,
materials.footpath
);
flatSegment(
infrastructure,
new THREE.Vector3(2.65, 0, footZ),
new THREE.Vector3(4.85, 0, 6.3),
0.85,
0.055,
materials.footpath
);
flatSegment(
infrastructure,
new THREE.Vector3(4.85, 0, 6.3),
new THREE.Vector3(6.05, 0, 5.15),
0.85,
0.055,
materials.footpath
);
flatSegment(
infrastructure,
new THREE.Vector3(6.05, 0, 5.15),
new THREE.Vector3(6.05, 0, 3.05),
0.85,
0.055,
materials.footpath
);
flatSegment(
infrastructure,
new THREE.Vector3(6.05, 0, 3.05),
new THREE.Vector3(7.25, 0, 1.8),
0.85,
0.055,
materials.footpath
);
flatSegment(
infrastructure,
new THREE.Vector3(7.25, 0, 1.8),
new THREE.Vector3(8.5, 0, 0.9),
0.85,
0.055,
materials.footpath
);
function footbridgeHeight(x) {
const t = THREE.MathUtils.clamp((x + 2.6) / 5.2, 0, 1);
return 0.18 + Math.sin(t * Math.PI) * 0.78;
}
const plankCount = 14;
const plankWidth = 5.2 / plankCount;
for (let i = 0; i < plankCount; i++) {
const x = -2.6 + plankWidth * (i + 0.5);
const height = footbridgeHeight(x);
const nextHeight = footbridgeHeight(x + plankWidth);
const angle = Math.atan2(
nextHeight - height,
plankWidth
);
const plank = box(
infrastructure,
plankWidth * 1.04,
0.12,
1.45,
x,
height - 0.06,
footZ,
materials.footpath
);
plank.rotation.z = angle;
}
// Bridge footbridge railing.
for (const z of [footZ - 0.72, footZ + 0.72]) {
const railPoints = [];
for (let i = 0; i <= 12; i++) {
const x = -2.6 + (5.2 * i) / 12;
const y = footbridgeHeight(x);
railPoints.push(new THREE.Vector3(x, y + 0.53, z));
cylinderBetween(
infrastructure,
new THREE.Vector3(x, y, z),
new THREE.Vector3(x, y + 0.53, z),
0.025,
materials.steel
);
}
for (let i = 0; i < railPoints.length - 1; i++) {
cylinderBetween(
infrastructure,
railPoints[i],
railPoints[i + 1],
0.025,
materials.steel
);
}
}
// -------------------------------------------------------------------------
// Buildings and parks
// -------------------------------------------------------------------------
const buildingPalette = [
0xc78269,
0xd4a878,
0x8da8a3,
0x7896a0,
0xb6a887,
0xcf8b78,
0x839c8b
];
const roofPalette = [0x8f5d50, 0x5c7073, 0x6d766d, 0xa16d5e];
function addBuilding(x, z, width, depth, height, index) {
const wallMaterial = standard(
buildingPalette[index % buildingPalette.length],
0.9
);
const roofMaterial = standard(
roofPalette[index % roofPalette.length],
0.86
);
box(
world,
width,
height,
depth,
x,
height / 2,
z,
wallMaterial
);
box(
world,
width + 0.12,
0.14,
depth + 0.12,
x,
height + 0.07,
z,
roofMaterial
);
if (height > 1.25) {
const floors = Math.max(1, Math.floor(height / 1.05));
const columns = Math.max(2, Math.floor(width / 0.58));
for (let floor = 0; floor < floors; floor++) {
for (let column = 0; column < columns; column++) {
const wx =
x -
width / 2 +
((column + 1) * width) / (columns + 1);
const wy = 0.52 + floor * 0.82;
box(
world,
0.25,
0.27,
0.035,
wx,
wy,
z + depth / 2 + 0.02,
(floor + column + index) % 4 === 0
? materials.windowLit
: materials.window,
false
);
}
}
}
// Small rooftop volume.
if (index % 3 === 0) {
box(
world,
width * 0.34,
0.35,
depth * 0.3,
x + width * 0.12,
height + 0.3,
z - depth * 0.08,
roofMaterial
);
}
}
const buildings = [
[-8.2, -10.5, 2.1, 1.6, 2.8],
[-5.5, -10.3, 1.7, 1.8, 3.6],
[-7.4, -8.1, 1.8, 1.7, 1.8],
[-4.1, -8.0, 1.7, 1.8, 2.3],
[-7.6, -2.8, 2.0, 1.8, 2.6],
[-4.5, -2.6, 1.5, 1.8, 1.7],
[-8.0, -3.0, 1.3, 1.4, 1.6],
[-7.5, 3.5, 1.9, 1.7, 2.2],
[-4.4, 3.6, 1.5, 1.8, 1.5],
[-6.2, 5.15, 1.3, 1.2, 0.9],
[5.0, -10.3, 2.0, 1.8, 3.1],
[7.5, -9.9, 1.6, 1.7, 2.2],
[4.0, -8.0, 1.8, 1.6, 1.7],
[6.6, -7.9, 2.0, 1.6, 2.5],
[8.1, -2.8, 1.7, 1.8, 1.8],
[4.2, -2.4, 1.5, 1.6, 2.0],
[11.45, -2.8, 1.0, 1.5, 2.8],
[3.65, 4.3, 1.25, 1.35, 0.95],
[3.6, 9.2, 1.7, 1.5, 2.4],
[11.45, 8.8, 1.0, 1.5, 1.8]
];
buildings.forEach((building, index) => {
addBuilding(...building, index);
});
// Small station at the shared destination.
box(world, 2.2, 0.8, 1.0, 7.55, 0.4, 2.65, materials.white);
box(world, 2.35, 0.12, 1.15, 7.55, 0.86, 2.65, materials.darkSteel);
for (let x = 6.65; x < 8.5; x += 0.45) {
box(
world,
0.26,
0.32,
0.035,
x,
0.52,
2.17,
materials.window,
false
);
}
function addTree(x, z, scale, variant = 0) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.1, 0.65, 6),
materials.trunk
);
trunk.position.set(x, 0.325, z);
trunk.castShadow = true;
world.add(trunk);
const leafMaterial = [
materials.leafA,
materials.leafB,
materials.leafC
][variant % 3];
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.48 * scale, 1.25 * scale, 7),
leafMaterial
);
crown.position.set(x, 0.78 + 0.48 * scale, z);
crown.castShadow = true;
crown.receiveShadow = true;
world.add(crown);
}
const trees = [
[-5.2, 6.0, 0.8],
[-4.1, 5.35, 0.72],
[-7.8, 5.6, 0.85],
[-8.6, 4.6, 0.66],
[4.65, 5.35, 0.75],
[5.25, 4.55, 0.66],
[7.85, 5.7, 0.82],
[8.8, 5.25, 0.72],
[3.0, 8.2, 0.8],
[4.2, 8.75, 0.68],
[8.8, 8.4, 0.85],
[-3.15, -8.8, 0.7],
[3.05, -9.5, 0.72]
];
trees.forEach((tree, index) => {
addTree(tree[0], tree[1], tree[2], index);
});
// -------------------------------------------------------------------------
// Shared destination
// -------------------------------------------------------------------------
const destination = new THREE.Group();
destination.position.set(8.5, 0, 0.9);
world.add(destination);
const plaza = new THREE.Mesh(
new THREE.CylinderGeometry(1.08, 1.08, 0.14, 24),
materials.plaza
);
plaza.position.y = 0.025;
plaza.receiveShadow = true;
destination.add(plaza);
const destinationRing = new THREE.Mesh(
new THREE.RingGeometry(0.55, 0.68, 32),
new THREE.MeshBasicMaterial({
color: 0x3e8991,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9
})
);
destinationRing.rotation.x = -Math.PI / 2;
destinationRing.position.y = 0.105;
destination.add(destinationRing);
const beaconMaterial = new THREE.MeshBasicMaterial({
color: 0x67b8bd,
transparent: true,
opacity: 0.24,
depthWrite: false
});
const beacon = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.12, 2.4, 8),
beaconMaterial
);
beacon.position.y = 1.25;
destination.add(beacon);
const beaconHead = new THREE.Mesh(
new THREE.OctahedronGeometry(0.22),
new THREE.MeshBasicMaterial({ color: 0x3b8e98 })
);
beaconHead.position.y = 2.55;
destination.add(beaconHead);
// -------------------------------------------------------------------------
// Route paths
// -------------------------------------------------------------------------
const routeColors = {
road: 0x18a7a1,
rail: 0xf28b45,
walk: 0xe5b83e
};
function makeCurvePath(points) {
const path = new THREE.CurvePath();
for (let i = 0; i < points.length - 1; i++) {
path.add(
new THREE.LineCurve3(
new THREE.Vector3(...points[i]),
new THREE.Vector3(...points[i + 1])
)
);
}
return path;
}
function createRoute(id, points, color, speed) {
const group = new THREE.Group();
world.add(group);
const path = makeCurvePath(points);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92
});
for (let i = 0; i < points.length - 1; i++) {
const a = new THREE.Vector3(...points[i]);
const b = new THREE.Vector3(...points[i + 1]);
cylinderBetween(
group,
a.clone().add(new THREE.Vector3(0, 0.045, 0)),
b.clone().add(new THREE.Vector3(0, 0.045, 0)),
0.045,
material,
8
);
}
points.forEach((point) => {
const joint = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 8, 6),
material
);
joint.position.set(
point[0],
point[1] + 0.045,
point[2]
);
group.add(joint);
});
// Direction arrows make the permitted route explicit.
for (let t = 0.08; t < 0.96; t += 0.16) {
const point = path.getPointAt(t);
const tangent = path.getTangentAt(t).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.38, 6),
material
);
arrow.position.copy(point).add(new THREE.Vector3(0, 0.08, 0));
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
group.add(arrow);
}
return {
id,
group,
path,
material,
speed,
traveler: null
};
}
const roadRoute = createRoute(
"road",
[
[-10.2, 0.10, 7.0],
[-10.2, 0.10, -4.5],
[-10.2, 0.10, -5.5],
[-3.4, 0.10, -5.5],
[-2.55, 0.28, -5.5],
[2.55, 0.28, -5.5],
[3.4, 0.10, -5.5],
[10.2, 0.10, -5.5],
[10.2, 0.10, 0.9],
[8.5, 0.10, 0.9]
],
routeColors.road,
0.043
);
const railRoute = createRoute(
"rail",
[
[-11.5, 0.20, 1.0],
[-3.2, 0.20, 1.0],
[-2.6, 0.57, 1.0],
[2.6, 0.57, 1.0],
[3.2, 0.20, 1.0],
[8.5, 0.20, 1.0]
],
routeColors.rail,
0.055
);
const walkRoute = createRoute(
"walk",
[
[-8.4, 0.11, 7.5],
[-2.65, 0.11, 7.5],
[-2.3, footbridgeHeight(-2.3) + 0.07, 7.5],
[-1.45, footbridgeHeight(-1.45) + 0.07, 7.5],
[0, footbridgeHeight(0) + 0.07, 7.5],
[1.45, footbridgeHeight(1.45) + 0.07, 7.5],
[2.3, footbridgeHeight(2.3) + 0.07, 7.5],
[2.65, 0.11, 7.5],
[4.85, 0.11, 6.3],
[6.05, 0.11, 5.15],
[6.05, 0.11, 3.05],
[7.25, 0.11, 1.8],
[8.5, 0.11, 0.9]
],
routeColors.walk,
0.027
);
const routes = [roadRoute, railRoute, walkRoute];
// -------------------------------------------------------------------------
// Traveler models
// -------------------------------------------------------------------------
function createCar() {
const group = new THREE.Group();
const teal = standard(routeColors.road, 0.42, 0.12);
const dark = standard(0x26383e, 0.72);
const glass = standard(0x9fc4c5, 0.28, 0.25);
box(group, 0.64, 0.25, 1.05, 0, 0.19, 0, teal);
box(group, 0.52, 0.23, 0.48, 0, 0.41, -0.08, glass);
for (const x of [-0.35, 0.35]) {
for (const z of [-0.32, 0.32]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.09, 10),
dark
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.12, z);
wheel.castShadow = true;
group.add(wheel);
}
}
const light = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.08, 0.035),
new THREE.MeshBasicMaterial({ color: 0xffe6a1 })
);
light.position.set(-0.18, 0.22, 0.54);
group.add(light);
const light2 = light.clone();
light2.position.x = 0.18;
group.add(light2);
world.add(group);
return group;
}
function createTrain() {
const group = new THREE.Group();
const orange = standard(routeColors.rail, 0.42, 0.1);
const cream = standard(0xe9dfc9, 0.75);
const dark = standard(0x28383c, 0.72);
box(group, 0.72, 0.42, 1.5, 0, 0.36, 0.15, orange);
box(group, 0.76, 0.3, 0.65, 0, 0.58, 0.55, orange);
box(group, 0.62, 0.19, 0.08, 0, 0.63, 0.9, materials.window);
box(group, 0.58, 0.28, 0.58, 0, 0.36, -0.82, cream);
for (const x of [-0.38, 0.38]) {
for (const z of [-0.45, 0.18, 0.7]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.1, 10),
dark
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.13, z);
wheel.castShadow = true;
group.add(wheel);
}
}
world.add(group);
return group;
}
function createWalker() {
const group = new THREE.Group();
const yellow = standard(routeColors.walk, 0.72);
const skin = standard(0xd6a47c, 0.9);
const body = new THREE.Mesh(
new THREE.ConeGeometry(0.17, 0.43, 7),
yellow
);
body.position.y = 0.32;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 8, 6),
skin
);
head.position.y = 0.64;
head.castShadow = true;
group.add(head);
world.add(group);
return group;
}
roadRoute.traveler = createCar();
railRoute.traveler = createTrain();
walkRoute.traveler = createWalker();
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelRoot = document.getElementById("labels");
const labels = [];
function addLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `map-label ${className}`;
element.textContent = text;
labelRoot.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(...position)
});
}
addLabel("Road bridge", [0, 1.25, roadZ]);
addLabel("Rail bridge", [0, 1.95, railZ]);
addLabel("Footbridge", [0, 1.65, footZ]);
addLabel("Shared destination", [8.5, 2.9, 0.9], "destination");
addLabel("Road start", [-10.2, 1.25, 7.0], "road");
addLabel("Rail start", [-11.5, 1.15, 1.0], "rail");
addLabel("Walk start", [-8.4, 0.95, 7.5], "walk");
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
label.element.style.display = visible ? "block" : "none";
if (visible) {
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
}
// -------------------------------------------------------------------------
// Custom camera controls — no addons required
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0.35, 0),
yaw: 0.62,
pitch: 0.69,
radius: 29
};
const defaultOrbit = {
yaw: orbit.yaw,
pitch: orbit.pitch,
radius: orbit.radius
};
function updateCamera() {
const cosPitch = Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x +
orbit.radius * Math.sin(orbit.yaw) * cosPitch,
orbit.target.y + orbit.radius * Math.sin(orbit.pitch),
orbit.target.z +
orbit.radius * Math.cos(orbit.yaw) * cosPitch
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
orbit.yaw -= dx * 0.005;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.004,
0.28,
1.32
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.015,
15,
45
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset-view").addEventListener("click", () => {
orbit.yaw = defaultOrbit.yaw;
orbit.pitch = defaultOrbit.pitch;
orbit.radius = defaultOrbit.radius;
updateCamera();
});
// -------------------------------------------------------------------------
// UI filters
// -------------------------------------------------------------------------
const filterButtons = [
...document.querySelectorAll("[data-filter]")
];
const routeStatus = document.getElementById("route-status");
function setFilter(filter) {
routes.forEach((route) => {
const visible = filter === "all" || route.id === filter;
route.group.visible = visible;
route.traveler.visible = visible;
});
filterButtons.forEach((button) => {
const active =
button.dataset.filter === filter ||
(filter === "all" && button.dataset.filter !== "all");
button.classList.toggle("active", active);
});
routeStatus.textContent =
filter === "all"
? "3 routes visible"
: `1 route visible · ${filter}`;
}
filterButtons.forEach((button) => {
button.addEventListener("click", () => {
setFilter(button.dataset.filter);
});
});
document
.getElementById("infrastructure")
.addEventListener("change", (event) => {
infrastructure.visible = event.target.checked;
});
window.addEventListener("keydown", (event) => {
const keyMap = {
"1": "all",
"2": "road",
"3": "rail",
"4": "walk"
};
if (keyMap[event.key]) {
setFilter(keyMap[event.key]);
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
const forward = new THREE.Vector3(0, 0, 1);
const targetQuaternion = new THREE.Quaternion();
function animateRoute(route, elapsed) {
if (!route.group.visible) return;
const t = (elapsed * route.speed) % 1;
const point = route.path.getPointAt(t);
const tangent = route.path.getTangentAt(t).normalize();
route.traveler.position.copy(point);
if (route.id !== "walk") {
targetQuaternion.setFromUnitVectors(forward, tangent);
route.traveler.quaternion.slerp(targetQuaternion, 0.18);
}
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
water.position.y = -0.08 + Math.sin(elapsed * 0.72) * 0.012;
beaconHead.rotation.y = elapsed * 0.8;
beaconHead.position.y = 2.55 + Math.sin(elapsed * 2.1) * 0.08;
const pulse = 1 + Math.sin(elapsed * 2.2) * 0.07;
beacon.scale.set(pulse, 1, pulse);
destinationRing.material.opacity =
0.72 + Math.sin(elapsed * 2.2) * 0.16;
routes.forEach((route) => animateRoute(route, elapsed));
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
setFilter("all");
animate();
</script>
</body>
</html>
```