Prompt specification
Build or customize the Three.js 3D scene "Tour boat passing beneath a Chicago bridge" 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: Tour boat passing beneath a Chicago bridge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tour-boat-passing-beneath-a-chicago-bridge-x2730
Scene Description Prompt:
A voxel tour boat passes beneath a Chicago River bridge while pedestrians follow the separate riverwalk. Three.js from cdnjs, one HTML file.
Working Three.js Starter (tour-boat-passing-beneath-a-chicago-bridge-x2730):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#102f43" />
<title>Chicago River — Voxel Tour</title>
<style>
:root {
--ink: #102f43;
--cream: #f5f0df;
--orange: #f25f3a;
--blue: #167b91;
--glass: rgba(13, 42, 56, 0.78);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9dce8;
color: white;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 3;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
padding: 16px 18px 14px;
min-width: 245px;
background: var(--glass);
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 4px;
box-shadow: 0 12px 35px rgba(7, 28, 39, 0.18);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #acdce5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #73e0b4;
box-shadow: 0 0 0 4px rgba(115, 224, 180, 0.12);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 900;
text-transform: uppercase;
}
.brand p {
margin: 9px 0 0;
color: rgba(255, 255, 255, 0.72);
font-size: 11px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.controls {
position: absolute;
top: 24px;
right: 26px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 3px;
padding: 11px 14px;
color: white;
background: var(--glass);
backdrop-filter: blur(12px);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(19, 65, 82, 0.94);
transform: translateY(-1px);
}
button.active {
color: #102f43;
background: #f2d36b;
border-color: #f2d36b;
}
.info {
position: absolute;
right: 26px;
bottom: 25px;
width: 220px;
padding: 15px 17px;
background: var(--glass);
border-left: 3px solid var(--orange);
backdrop-filter: blur(12px);
}
.info-row {
display: flex;
justify-content: space-between;
gap: 15px;
padding: 5px 0;
color: rgba(255, 255, 255, 0.65);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.info-row strong {
color: white;
font-variant-numeric: tabular-nums;
}
.hint {
position: absolute;
left: 26px;
bottom: 25px;
max-width: 330px;
color: rgba(16, 47, 67, 0.88);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
.hint span {
display: inline-block;
margin-right: 10px;
padding: 6px 8px;
color: white;
background: rgba(16, 47, 67, 0.76);
border-radius: 2px;
}
.world-label {
position: absolute;
left: 0;
top: 0;
z-index: 2;
pointer-events: none;
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 120ms linear;
white-space: nowrap;
}
.world-label.visible {
opacity: 1;
}
.world-label::after {
content: "";
display: block;
width: 1px;
height: 19px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.85);
}
.world-label span {
display: block;
padding: 6px 9px;
background: rgba(16, 47, 67, 0.83);
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 2px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
box-shadow: 0 5px 14px rgba(7, 28, 39, 0.2);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: white;
background: #102f43;
transition: opacity 450ms ease, visibility 450ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-box {
text-align: center;
}
.loading-cube {
width: 36px;
height: 36px;
margin: 0 auto 18px;
background: #f25f3a;
animation: cube-bounce 900ms ease-in-out infinite alternate;
}
.loading-box strong {
display: block;
font-size: 12px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.loading-box small {
display: block;
margin-top: 7px;
color: rgba(255, 255, 255, 0.55);
font-size: 10px;
letter-spacing: 0.08em;
}
@keyframes cube-bounce {
to {
transform: translateY(-10px) rotate(12deg);
}
}
@media (max-width: 700px) {
.brand {
top: 14px;
left: 14px;
min-width: 0;
padding: 12px 14px;
}
.brand p {
display: none;
}
.controls {
top: 14px;
right: 14px;
flex-direction: column;
}
button {
padding: 9px 11px;
font-size: 9px;
}
.info {
right: 14px;
bottom: 14px;
width: 190px;
}
.hint {
left: 14px;
bottom: 14px;
max-width: 150px;
line-height: 1.6;
}
.hint span {
display: block;
width: fit-content;
margin-bottom: 5px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated voxel scene of a Chicago tour boat beneath a river bridge"></canvas>
<div id="boatLabel" class="world-label">
<span>River Tour 06 · 2.8 kn</span>
</div>
<div id="walkLabel" class="world-label">
<span>Chicago Riverwalk</span>
</div>
<div class="overlay">
<header class="brand">
<div class="eyebrow">
<span class="live-dot"></span>
Live river study
</div>
<h1>Chicago<br />River</h1>
<p>Bridge district · voxel edition</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="followBtn" type="button">Follow boat</button>
<button id="pauseBtn" type="button">Pause</button>
<button id="resetBtn" type="button">Reset view</button>
</nav>
<div class="hint">
<span>Drag to orbit</span>
Shift-drag to pan · Scroll to zoom
</div>
<section class="info" aria-label="Scene information">
<div class="info-row">
<span>Location</span>
<strong>Chicago, IL</strong>
</div>
<div class="info-row">
<span>Water level</span>
<strong id="waterLevel">0.0 ft</strong>
</div>
<div class="info-row">
<span>Walkers</span>
<strong id="walkerCount">20</strong>
</div>
<div class="info-row">
<span>Status</span>
<strong id="status">Underway</strong>
</div>
</section>
</div>
<div id="loading">
<div class="loading-box">
<div class="loading-cube"></div>
<strong>Building the river</strong>
<small>Loading Three.js from cdnjs</small>
</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("#scene");
const loading = document.querySelector("#loading");
const followBtn = document.querySelector("#followBtn");
const pauseBtn = document.querySelector("#pauseBtn");
const resetBtn = document.querySelector("#resetBtn");
const statusEl = document.querySelector("#status");
const boatLabel = document.querySelector("#boatLabel");
const walkLabel = document.querySelector("#walkLabel");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9dce8);
scene.fog = new THREE.Fog(0xb9dce8, 48, 115);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemisphere = new THREE.HemisphereLight(0xdff5ff, 0x6c6555, 2.15);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffe3b3, 3.25);
sunlight.position.set(-28, 46, 28);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -65;
sunlight.shadow.camera.right = 65;
sunlight.shadow.camera.top = 55;
sunlight.shadow.camera.bottom = -45;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 120;
sunlight.shadow.bias = -0.0005;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0x9cd7ee, 0.7);
fillLight.position.set(30, 18, -30);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options
});
const materials = {
asphalt: material(0x38464b),
bridge: material(0x25556b, { metalness: 0.38, roughness: 0.5 }),
bridgeDark: material(0x173d50, { metalness: 0.45 }),
bridgeLight: material(0x3e7183, { metalness: 0.35 }),
stone: material(0x9d8c77),
stoneDark: material(0x776b5f),
concrete: material(0xc6bca7),
path: material(0xb8aa91),
pathDark: material(0x887f70),
grass: material(0x738d66),
trunk: material(0x6d4934),
leafA: material(0x52785c),
leafB: material(0x668b66),
rail: material(0x243f48, { metalness: 0.6, roughness: 0.45 }),
white: material(0xf4f0df),
boatBlue: material(0x126f8a, { roughness: 0.4 }),
boatDark: material(0x0b4058, { roughness: 0.38 }),
glass: material(0x83c8d6, {
roughness: 0.18,
metalness: 0.25,
emissive: 0x123d49,
emissiveIntensity: 0.18
}),
yellow: material(0xf0bd38),
orange: material(0xf25f3a),
black: material(0x17252c),
bus: material(0xbb3f37),
wood: material(0x98704a),
lamp: material(0xffe8a6, {
emissive: 0xffc75d,
emissiveIntensity: 1.6
}),
skin: material(0xd59a73),
shirtA: material(0xf05a3a),
shirtB: material(0x287f93),
shirtC: material(0xf0bd38),
shirtD: material(0x66547d),
shirtE: material(0xe8e0cf),
pants: material(0x273b49)
};
function box(w, h, d, mat, x, y, z, parent = scene, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(1909);
function canvasTexture(width, height, draw) {
const image = document.createElement("canvas");
image.width = width;
image.height = height;
const context = image.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(image);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function textTexture(text, background = "#123a4b", foreground = "#fff6dc") {
return canvasTexture(512, 128, (ctx, w, h) => {
ctx.fillStyle = background;
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = foreground;
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, w - 16, h - 16);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 45px Arial";
ctx.fillText(text, w / 2, h / 2 + 2);
});
}
function facadeTexture(base, seed) {
const rng = seededRandom(seed);
return canvasTexture(128, 256, (ctx, w, h) => {
ctx.fillStyle = base;
ctx.fillRect(0, 0, w, h);
const columns = 5;
const rows = 11;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const lit = rng() > 0.72;
ctx.fillStyle = lit ? "#f3d88b" : "#203d49";
ctx.globalAlpha = lit ? 0.92 : 0.66;
ctx.fillRect(
9 + col * 24,
10 + row * 22,
11,
12
);
}
}
ctx.globalAlpha = 1;
ctx.fillStyle = "rgba(255,255,255,0.08)";
ctx.fillRect(0, 0, w, 5);
});
}
// ---------------------------------------------------------------------
// River and embankments
// ---------------------------------------------------------------------
box(122, 0.25, 18, material(0x226d82, {
roughness: 0.25,
metalness: 0.3
}), 0, -0.24, 0, scene, false, true);
const waterMaterials = [
material(0x267f95, { roughness: 0.28, metalness: 0.28 }),
material(0x2e8ca0, { roughness: 0.3, metalness: 0.24 }),
material(0x337f97, { roughness: 0.32, metalness: 0.22 }),
material(0x3d91a2, { roughness: 0.3, metalness: 0.2 })
];
const waterTiles = [];
for (let x = -59; x < 60; x += 4) {
for (let z = -8; z <= 8; z += 2) {
const tile = box(
3.96,
0.12,
1.96,
waterMaterials[Math.floor(random() * waterMaterials.length)],
x + 2,
-0.03 + random() * 0.025,
z,
scene,
false,
true
);
tile.userData.phase = random() * Math.PI * 2;
tile.userData.baseY = tile.position.y;
waterTiles.push(tile);
}
}
box(124, 1.8, 30, material(0x8d927b), 0, 0.9, 24);
box(124, 1.8, 30, material(0x8d927b), 0, 0.9, -24);
// Stone embankment walls.
box(124, 2.2, 0.5, materials.stoneDark, 0, 0.85, 9.15);
box(124, 2.2, 0.5, materials.stoneDark, 0, 0.85, -9.15);
for (let x = -58; x <= 58; x += 4) {
box(3.85, 0.32, 0.65, materials.stone, x, 1.7, 9.25);
box(3.85, 0.32, 0.65, materials.stone, x, 1.7, -9.25);
}
// Separate raised riverwalks.
for (const side of [-1, 1]) {
box(124, 0.34, 4.2, materials.path, 0, 2.03, side * 14.4);
box(124, 0.08, 0.16, materials.pathDark, 0, 2.24, side * 14.4);
for (let x = -60; x <= 60; x += 4) {
box(0.035, 0.025, 4, materials.pathDark, x, 2.215, side * 14.4);
}
// Waterfront railing.
for (let x = -60; x <= 60; x += 4) {
box(0.11, 1.4, 0.11, materials.rail, x, 2.5, side * 9.75);
}
box(124, 0.12, 0.12, materials.rail, 0, 3.16, side * 9.75);
box(124, 0.08, 0.08, materials.rail, 0, 2.68, side * 9.75);
// Outer railing.
for (let x = -60; x <= 60; x += 5) {
box(0.1, 1.05, 0.1, materials.rail, x, 2.65, side * 16.55);
}
box(124, 0.09, 0.09, materials.rail, 0, 3.13, side * 16.55);
}
// ---------------------------------------------------------------------
// Voxel bridge
// ---------------------------------------------------------------------
const bridge = new THREE.Group();
scene.add(bridge);
// Stone abutments at both ends of the span.
box(9.2, 6.5, 2.6, materials.stoneDark, 0, 3.05, 12.7, bridge);
box(9.2, 6.5, 2.6, materials.stoneDark, 0, 3.05, -12.7, bridge);
for (const z of [11.55, 13.85, -11.55, -13.85]) {
box(9.5, 0.45, 0.22, materials.stone, 0, 5.95, z, bridge);
}
// Main deck and roadway.
box(8.3, 0.62, 29.5, materials.bridgeDark, 0, 6.72, 0, bridge);
box(7.35, 0.08, 28.8, materials.asphalt, 0, 7.07, 0, bridge, false, true);
for (let z = -13; z <= 13; z += 2.4) {
box(0.14, 0.025, 1.25, materials.yellow, 0, 7.125, z, bridge, false, false);
}
// Side trusses.
for (const x of [-3.85, 3.85]) {
box(0.42, 0.42, 22.5, materials.bridge, x, 7.15, 0, bridge);
box(0.42, 0.42, 22.5, materials.bridge, x, 11.55, 0, bridge);
for (let z = -10; z <= 10; z += 4) {
box(0.42, 4.4, 0.42, materials.bridgeLight, x, 9.35, z, bridge);
}
// Stepped diagonal braces preserve the blocky voxel language.
for (let bay = 0; bay < 5; bay++) {
const z0 = -10 + bay * 4;
for (let step = 0; step < 4; step++) {
box(
0.38,
0.38,
1.08,
materials.bridgeLight,
x,
7.35 + step * 1.02,
z0 + (step + 0.5) * 1,
bridge
);
}
}
}
// Top cross-beams.
for (let z = -10; z <= 10; z += 4) {
box(8.1, 0.3, 0.3, materials.bridge, 0, 11.58, z, bridge);
}
// Bridge sidewalk and guardrails.
for (const x of [-3.75, 3.75]) {
box(0.45, 0.25, 28.5, materials.concrete, x, 7.22, 0, bridge);
box(0.12, 0.85, 28.5, materials.rail, x, 7.72, 0, bridge);
for (let z = -14; z <= 14; z += 2) {
box(0.11, 0.9, 0.11, materials.rail, x, 7.7, z, bridge);
}
}
// Bridge sign.
const bridgeSignMaterial = new THREE.MeshBasicMaterial({
map: textTexture("CHICAGO"),
side: THREE.DoubleSide
});
const bridgeSign = new THREE.Mesh(
new THREE.PlaneGeometry(4.8, 1.2),
bridgeSignMaterial
);
bridgeSign.position.set(0, 9.15, 13.18);
bridge.add(bridgeSign);
// A small CTA-style bus crossing the bridge.
const bus = new THREE.Group();
bus.position.set(1.8, 7.25, -10);
scene.add(bus);
box(1.5, 1.55, 3.7, materials.bus, 0, 0.9, 0, bus);
box(1.53, 0.18, 3.85, materials.white, 0, 1.75, 0, bus);
box(1.54, 0.62, 0.05, materials.glass, 0, 1.2, -1.87, bus);
box(1.54, 0.62, 0.05, materials.glass, 0, 1.2, 1.87, bus);
box(0.05, 0.62, 2.7, materials.glass, 0.77, 1.2, 0, bus);
box(0.05, 0.62, 2.7, materials.glass, -0.77, 1.2, 0, bus);
for (const x of [-0.72, 0.72]) {
for (const z of [-1.2, 1.2]) {
box(0.28, 0.45, 0.65, materials.black, x, 0.24, z, bus);
}
}
// ---------------------------------------------------------------------
// Boat
// ---------------------------------------------------------------------
const boat = new THREE.Group();
scene.add(boat);
// Lower hull.
box(6.9, 0.7, 2.85, materials.boatDark, 0, 0.47, 0, boat);
box(6.65, 0.64, 2.95, materials.white, -0.05, 0.98, 0, boat);
// Stepped bow.
box(1.0, 0.6, 2.45, materials.white, 3.45, 0.94, 0, boat);
box(0.55, 0.52, 1.9, materials.white, 4.05, 0.88, 0, boat);
box(0.48, 0.7, 2.95, materials.boatBlue, 3.05, 0.48, 0, boat);
// Yellow stripe.
box(6.5, 0.12, 0.055, materials.yellow, 0, 0.95, 1.5, boat);
box(6.5, 0.12, 0.055, materials.yellow, 0, 0.95, -1.5, boat);
// Open rear deck.
box(2.7, 0.16, 2.4, materials.wood, -2.05, 1.38, 0, boat);
// Cabin.
box(2.65, 1.35, 2.2, materials.white, -0.55, 2.02, 0, boat);
box(2.85, 0.18, 2.35, materials.boatBlue, -0.55, 2.78, 0, boat);
for (const z of [-1.12, 1.12]) {
for (const x of [-1.4, -0.55, 0.3]) {
box(0.7, 0.62, 0.045, materials.glass, x, 2.13, z, boat);
}
}
box(0.05, 0.65, 1.65, materials.glass, 0.8, 2.15, 0, boat);
box(0.05, 0.65, 1.65, materials.glass, -1.9, 2.15, 0, boat);
// Front-facing upper deck and passengers.
box(1.15, 0.18, 2.15, materials.wood, 1.48, 1.52, 0, boat);
const passengerColors = [
materials.shirtA,
materials.shirtB,
materials.shirtC,
materials.shirtD,
materials.shirtE
];
for (let i = 0; i < 5; i++) {
const z = -0.82 + i * 0.41;
box(0.3, 0.5, 0.28, passengerColors[i], 1.35, 1.84, z, boat);
box(0.25, 0.25, 0.25, materials.skin, 1.35, 2.22, z, boat);
}
// Life ring and roof marker.
box(0.16, 0.62, 0.62, materials.orange, -1.45, 2.08, 1.18, boat);
box(0.12, 0.22, 0.22, materials.yellow, -0.55, 3.02, 0, boat);
// Boat lettering.
const boatSignMaterial = new THREE.MeshBasicMaterial({
map: textTexture("CHICAGO TOUR", "#0d6b86", "#fff3cf"),
transparent: false
});
const boatSign = new THREE.Mesh(
new THREE.PlaneGeometry(3.1, 0.72),
boatSignMaterial
);
boatSign.position.set(-0.2, 0.86, 1.515);
boat.add(boatSign);
// Wake blocks.
const wake = [];
for (let i = 0; i < 7; i++) {
const wakeMaterial = new THREE.MeshBasicMaterial({
color: 0xd8f2ee,
transparent: true,
opacity: 0.45,
depthWrite: false
});
const foam = box(
1.5,
0.025,
0.8,
wakeMaterial,
-4.1 - i * 1.05,
0.06,
i % 2 ? 0.55 : -0.55,
boat,
false,
false
);
wake.push(foam);
}
// ---------------------------------------------------------------------
// Riverwalk pedestrians
// ---------------------------------------------------------------------
const pedestrians = [];
const shirtMaterials = [
materials.shirtA,
materials.shirtB,
materials.shirtC,
materials.shirtD,
materials.shirtE
];
function createPedestrian(index, side) {
const group = new THREE.Group();
const shirt = shirtMaterials[index % shirtMaterials.length];
const leftLeg = box(
0.14,
0.68,
0.16,
materials.pants,
-0.09,
0.36,
0,
group
);
const rightLeg = box(
0.14,
0.68,
0.16,
materials.pants,
0.09,
0.36,
0,
group
);
box(0.38, 0.68, 0.25, shirt, 0, 1.0, 0, group);
box(0.28, 0.29, 0.27, materials.skin, 0, 1.52, 0, group);
const leftArm = box(
0.12,
0.57,
0.14,
shirt,
-0.27,
1.0,
0,
group
);
const rightArm = box(
0.12,
0.57,
0.14,
shirt,
0.27,
1.0,
0,
group
);
if (index % 4 === 0) {
box(0.26, 0.12, 0.27, materials.boatDark, 0, 1.71, 0, group);
}
const direction = index % 3 === 0 ? -1 : 1;
group.rotation.y = direction > 0 ? 0 : Math.PI;
group.position.set(
-56 + random() * 112,
2.22,
side * 14.4 + (random() - 0.5) * 1.4
);
scene.add(group);
pedestrians.push({
group,
leftLeg,
rightLeg,
leftArm,
rightArm,
direction,
speed: 0.7 + random() * 0.7,
phase: random() * Math.PI * 2
});
}
for (let i = 0; i < 12; i++) createPedestrian(i, -1);
for (let i = 12; i < 20; i++) createPedestrian(i, 1);
// ---------------------------------------------------------------------
// Riverwalk furniture
// ---------------------------------------------------------------------
function createLamp(x, side) {
const z = side * 16.1;
box(0.16, 3.1, 0.16, materials.rail, x, 3.7, z);
box(0.95, 0.12, 0.12, materials.rail, x + 0.38, 5.16, z);
box(0.48, 0.15, 0.3, materials.lamp, x + 0.72, 5.03, z);
}
for (let x = -48; x <= 48; x += 16) {
createLamp(x, -1);
createLamp(x, 1);
}
function createTree(x, z, scale = 1) {
box(0.45 * scale, 2.8 * scale, 0.45 * scale,
materials.trunk, x, 3.4 * scale, z);
box(2.5 * scale, 1.8 * scale, 2.4 * scale,
materials.leafA, x, 5.0 * scale, z);
box(1.7 * scale, 1.3 * scale, 1.8 * scale,
materials.leafB, x - 0.45 * scale, 6.0 * scale, z + 0.15);
box(1.25 * scale, 1.1 * scale, 1.3 * scale,
materials.leafA, x + 0.75 * scale, 5.9 * scale, z - 0.2);
}
for (let x = -46; x <= 46; x += 12) {
createTree(x + 3, -17.1, 0.78 + random() * 0.22);
}
for (const side of [-1, 1]) {
for (let x = -48; x <= 48; x += 18) {
box(2.1, 0.55, 0.85, materials.concrete, x, 2.48, side * 16.1);
box(1.85, 0.12, 0.68, materials.wood, x, 2.82, side * 16.1);
box(1.85, 0.58, 0.12, materials.wood, x, 3.12, side * 16.32);
box(0.14, 0.42, 0.55, materials.rail, x - 0.72, 2.55, side * 16.1);
box(0.14, 0.42, 0.55, materials.rail, x + 0.72, 2.55, side * 16.1);
}
}
// ---------------------------------------------------------------------
// Blocky Chicago skyline
// ---------------------------------------------------------------------
const buildingPalette = [
"#776f67",
"#6e7d7d",
"#867567",
"#596b72",
"#968777",
"#5f6973"
];
for (let x = -54; x <= 54; x += 6.5) {
if (Math.abs(x + 10) < 7) continue;
const width = 4.4 + random() * 2.1;
const depth = 5.5 + random() * 5;
const height = 8 + random() * 18;
const z = -21 - random() * 7.5;
const buildingMaterial = material(
new THREE.Color(buildingPalette[Math.floor(random() * buildingPalette.length)])
);
box(
width,
height,
depth,
buildingMaterial,
x,
1.8 + height / 2,
z,
scene
);
const facade = new THREE.Mesh(
new THREE.PlaneGeometry(width * 0.93, height * 0.94),
new THREE.MeshBasicMaterial({
map: facadeTexture(
buildingPalette[Math.floor(random() * buildingPalette.length)],
Math.floor(random() * 99999)
)
})
);
facade.position.set(x, 1.8 + height / 2, z + depth / 2 + 0.012);
scene.add(facade);
if (height > 20) {
box(
width * 0.55,
1.6,
depth * 0.55,
buildingMaterial,
x,
1.8 + height + 0.8,
z
);
}
}
// Recognizable stepped skyscraper silhouette.
const tower = new THREE.Group();
tower.position.set(-10, 0, -29);
scene.add(tower);
box(5.2, 18, 5.2, material(0x50616c), 0, 10.9, 0, tower);
box(4.2, 13, 4.2, material(0x5d6c72), 0, 26.35, 0, tower);
box(3.1, 8, 3.1, material(0x66737a), 0, 36.9, 0, tower);
box(1.7, 5, 1.7, material(0x718087), 0, 43.3, 0, tower);
box(0.16, 5.5, 0.16, materials.rail, -0.5, 48.3, 0, tower);
box(0.16, 4.5, 0.16, materials.rail, 0.5, 47.8, 0, tower);
const towerFacade = new THREE.Mesh(
new THREE.PlaneGeometry(4.8, 17),
new THREE.MeshBasicMaterial({
map: facadeTexture("#43535f", 442)
})
);
towerFacade.position.set(0, 10.9, 2.61);
tower.add(towerFacade);
// ---------------------------------------------------------------------
// Camera controls implemented without Three.js addons
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2.3, 0),
azimuth: 0.72,
elevation: 0.54,
radius: 42,
minRadius: 12,
maxRadius: 76,
follow: false
};
const initialCamera = {
target: controls.target.clone(),
azimuth: controls.azimuth,
elevation: controls.elevation,
radius: controls.radius
};
function updateCamera() {
const cosElevation = Math.cos(controls.elevation);
camera.position.set(
controls.target.x +
controls.radius * cosElevation * Math.sin(controls.azimuth),
controls.target.y + controls.radius * Math.sin(controls.elevation),
controls.target.z +
controls.radius * cosElevation * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
updateCamera();
const pointers = new Map();
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
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
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
previousPinchDistance = pointerDistance();
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0) {
const factor = previousPinchDistance / Math.max(distance, 1);
controls.radius = THREE.MathUtils.clamp(
controls.radius * factor,
controls.minRadius,
controls.maxRadius
);
}
previousPinchDistance = distance;
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
camera.updateMatrixWorld();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const scale = controls.radius * 0.00135;
controls.target.addScaledVector(right, -dx * scale);
controls.target.y += dy * scale;
controls.target.y = THREE.MathUtils.clamp(controls.target.y, -1, 12);
} else {
controls.azimuth -= dx * 0.006;
controls.elevation = THREE.MathUtils.clamp(
controls.elevation + dy * 0.005,
0.14,
1.28
);
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragging = false;
panning = false;
previousPinchDistance = 0;
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
controls.minRadius,
controls.maxRadius
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
controls.target.copy(initialCamera.target);
controls.azimuth = initialCamera.azimuth;
controls.elevation = initialCamera.elevation;
controls.radius = initialCamera.radius;
controls.follow = false;
followBtn.classList.remove("active");
followBtn.textContent = "Follow boat";
});
followBtn.addEventListener("click", () => {
controls.follow = !controls.follow;
followBtn.classList.toggle("active", controls.follow);
followBtn.textContent = controls.follow ? "Following boat" : "Follow boat";
});
let paused = false;
pauseBtn.addEventListener("click", () => {
paused = !paused;
pauseBtn.textContent = paused ? "Resume" : "Pause";
pauseBtn.classList.toggle("active", paused);
statusEl.textContent = paused ? "Paused" : "Underway";
});
resetBtn.addEventListener("click", () => {
controls.target.copy(initialCamera.target);
controls.azimuth = initialCamera.azimuth;
controls.elevation = initialCamera.elevation;
controls.radius = initialCamera.radius;
controls.follow = false;
followBtn.classList.remove("active");
followBtn.textContent = "Follow boat";
});
// ---------------------------------------------------------------------
// Animation and projected DOM labels
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let simulationTime = 0;
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
element.classList.toggle("visible", visible);
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta;
// Boat travels along the river and passes under the bridge.
boat.position.x = ((simulationTime * 2.8 + 39) % 92) - 46;
boat.position.y = 0.04 + Math.sin(simulationTime * 2.2) * 0.045;
boat.rotation.z = Math.sin(simulationTime * 1.4) * 0.012;
// Water tiles shimmer subtly.
for (const tile of waterTiles) {
tile.position.y =
tile.userData.baseY +
Math.sin(simulationTime * 1.7 + tile.userData.phase) * 0.018;
}
// Pedestrians remain on the separate riverwalk.
for (const person of pedestrians) {
person.group.position.x +=
person.direction * person.speed * delta;
if (person.group.position.x > 61) person.group.position.x = -61;
if (person.group.position.x < -61) person.group.position.x = 61;
const swing = Math.sin(simulationTime * 7 + person.phase) * 0.48;
person.leftLeg.rotation.z = swing;
person.rightLeg.rotation.z = -swing;
person.leftArm.rotation.z = -swing * 0.7;
person.rightArm.rotation.z = swing * 0.7;
person.group.position.y =
2.22 + Math.abs(Math.sin(simulationTime * 7 + person.phase)) * 0.035;
}
// Bridge traffic.
bus.position.z = ((simulationTime * 1.8 + 11) % 29) - 14.5;
// Wake expands and fades.
wake.forEach((foam, index) => {
const life = (simulationTime * 1.4 + index * 0.2) % 1;
foam.material.opacity = Math.max(0, 0.48 * (1 - life));
foam.scale.x = 1 + life * 1.6;
foam.scale.z = 1 + life * 0.7;
});
}
if (controls.follow) {
const desiredTarget = new THREE.Vector3(
boat.position.x,
2.3,
0
);
controls.target.lerp(
desiredTarget,
1 - Math.exp(-delta * 3.2)
);
}
updateCamera();
projectLabel(
boatLabel,
new THREE.Vector3(boat.position.x - 0.5, 4.0, 0)
);
projectLabel(
walkLabel,
new THREE.Vector3(10, 4.15, -14.4)
);
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
renderer.render(scene, camera);
requestAnimationFrame(() => loading.classList.add("hidden"));
animate();
</script>
</body>
</html>
```