Prompt specification
Build or customize the Three.js 3D scene "Walking and carpool routes across Montgomery" 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: Walking and carpool routes across Montgomery
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/walking-and-carpool-routes-across-montgomery-x2451
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a low-poly schematic neighborhood transport scene during the Montgomery bus boycott. Use historically sourced framing for the event, while making the particular street fragment and illustrated journeys explicitly schematic. Arrange homes, a gathering point, a workplace destination, and roads that can support walking and carpool routes. Animate small groups walking along sidewalks while a shared car collects passengers at agreed stops. Keep the same individuals identifiable as they move between waiting, riding, and arriving. Show how several trips are coordinated over time without claiming that these are documented journeys of specific people.
Working Three.js Starter (walking-and-carpool-routes-across-montgomery-x2451):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Schematic Montgomery — Walking and Carpool Coordination</title>
<style>
:root {
--ink: #172326;
--muted: #536267;
--paper: rgba(250, 248, 240, 0.94);
--line: rgba(23, 35, 38, 0.16);
--teal: #167f75;
--amber: #b8781c;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bfd5dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.card {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255,255,255,0.65);
box-shadow: 0 12px 34px rgba(26, 42, 45, 0.16);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.title-card {
position: absolute;
top: 18px;
left: 18px;
width: min(440px, calc(100vw - 36px));
padding: 16px 18px 15px;
border-radius: 15px;
}
.eyebrow {
margin-bottom: 6px;
color: #6b5140;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 36px);
font-weight: 600;
line-height: 1.04;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.disclaimer {
display: inline-block;
margin-top: 10px;
padding: 4px 7px;
border-radius: 5px;
background: #f2dfc7;
color: #704c2d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.history-card {
position: absolute;
top: 18px;
right: 18px;
width: min(365px, calc(100vw - 36px));
border-radius: 14px;
overflow: hidden;
}
.history-card summary {
cursor: pointer;
padding: 13px 16px;
list-style: none;
background: rgba(29, 48, 51, 0.96);
color: #fffdf6;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.history-card summary::-webkit-details-marker { display: none; }
.history-card summary::after {
content: "+";
float: right;
font-size: 17px;
line-height: 12px;
}
.history-card[open] summary::after { content: "−"; }
.history-body {
max-height: min(430px, calc(100vh - 140px));
overflow: auto;
padding: 15px 16px 14px;
font-size: 12px;
line-height: 1.52;
}
.history-body p { margin: 0 0 10px; }
.history-body strong { color: #143b3b; }
.sources {
margin: 11px 0 0;
padding: 10px 0 0;
border-top: 1px solid var(--line);
font-size: 11px;
}
.sources div {
margin: 0 0 5px;
color: var(--muted);
}
.sources a {
color: #146c72;
font-weight: 700;
text-decoration-thickness: 1px;
text-underline-offset: 2px;
}
.schedule-card {
position: absolute;
left: 18px;
right: 18px;
bottom: 18px;
display: grid;
grid-template-columns: minmax(210px, 0.8fr) minmax(320px, 1.5fr) minmax(250px, 0.8fr);
gap: 18px;
align-items: center;
padding: 14px 16px;
border-radius: 15px;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 7px;
align-items: center;
}
button, select {
min-height: 34px;
border: 1px solid rgba(23,35,38,0.2);
border-radius: 8px;
background: #fffdf8;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
}
button {
padding: 0 11px;
cursor: pointer;
}
button:hover { background: #f0eee6; }
select { padding: 0 26px 0 8px; }
.clock-label {
margin-top: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#cycle-clock {
margin-top: 2px;
font-variant-numeric: tabular-nums;
font-size: 20px;
font-weight: 800;
}
.trip-list {
display: grid;
gap: 10px;
}
.trip {
display: grid;
grid-template-columns: 106px 1fr;
gap: 10px;
align-items: center;
}
.trip-name {
font-size: 11px;
font-weight: 850;
line-height: 1.25;
}
.trip-name span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.trip-status {
display: flex;
justify-content: space-between;
gap: 8px;
margin-bottom: 4px;
font-size: 10px;
line-height: 1.2;
}
.trip-status strong {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.trip-time {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.progress {
height: 5px;
overflow: hidden;
border-radius: 5px;
background: rgba(23,35,38,0.1);
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
transition: width 0.08s linear;
}
.wave-a .progress > div { background: var(--teal); }
.wave-b .progress > div { background: var(--amber); }
.legend {
font-size: 10px;
line-height: 1.45;
color: var(--muted);
}
.legend-title {
margin-bottom: 5px;
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 7px;
margin-top: 4px;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 50%;
}
.camera-help {
position: absolute;
right: 18px;
bottom: 118px;
padding: 7px 10px;
border-radius: 8px;
background: rgba(23,35,38,0.76);
color: #fff;
font-size: 10px;
letter-spacing: 0.02em;
pointer-events: none;
}
@media (max-width: 900px) {
.schedule-card {
grid-template-columns: 1fr 1.5fr;
}
.legend { display: none; }
.camera-help { display: none; }
}
@media (max-width: 650px) {
.title-card {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px 14px;
}
.history-card {
top: auto;
right: 10px;
bottom: 153px;
width: min(330px, calc(100vw - 20px));
}
.history-body { max-height: 240px; }
.schedule-card {
left: 10px;
right: 10px;
bottom: 10px;
grid-template-columns: 1fr;
gap: 10px;
padding: 11px 12px;
}
.trip { grid-template-columns: 88px 1fr; }
.clock-wrap { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="overlay">
<section class="title-card card" aria-labelledby="scene-title">
<div class="eyebrow">Montgomery, Alabama · 1955–1956</div>
<h1 id="scene-title">Neighborhood journeys in coordination</h1>
<p class="subtitle">
A low-poly schematic of homes, agreed pickup stops, a community carpool,
and a downtown workplace during the Montgomery bus boycott.
</p>
<span class="disclaimer">Illustrative routes · not documented individual journeys</span>
</section>
<details class="history-card card" open>
<summary>Historical frame & sources</summary>
<div class="history-body">
<p>
After <strong>Rosa Parks was arrested on December 1, 1955</strong> for
refusing to surrender her seat on a segregated Montgomery bus, a
<strong>381-day boycott</strong> followed. The Montgomery Improvement
Association and Black community activists coordinated sustained
alternatives to segregated bus travel, including walking and carpools.
</p>
<p>
<strong>This scene is explanatory, not a reconstruction.</strong>
The street fragment, homes, gathering point, workplace, pickup stops,
schedule, and participants A1–B4 are invented. Their illustrated
journeys do not represent documented movements of specific people.
</p>
<div class="sources">
<div>Historical framing:</div>
<div>
<a href="https://www.nps.gov/articles/montgomery-bus-boycott.htm"
target="_blank" rel="noopener">National Park Service — Montgomery Bus Boycott</a>
</div>
<div>
<a href="https://encyclopediaofalabama.org/article/montgomery-bus-boycott/"
target="_blank" rel="noopener">Encyclopedia of Alabama — Montgomery Bus Boycott</a>
</div>
<div>
<a href="https://www.archives.gov/education/lessons/montgomery-bus-boycott"
target="_blank" rel="noopener">U.S. National Archives — Montgomery Bus Boycott resources</a>
</div>
</div>
</div>
</details>
<section class="schedule-card card" aria-label="Illustrative trip coordination">
<div class="clock-wrap">
<div class="controls">
<button id="play-toggle" type="button" aria-label="Pause animation">Pause</button>
<button id="restart" type="button">Restart</button>
<select id="speed" aria-label="Animation speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="1.5">1.5×</option>
<option value="2">2×</option>
</select>
</div>
<div class="clock-label">Illustrative coordination clock</div>
<div id="cycle-clock">00:00 / 00:42</div>
</div>
<div class="trip-list">
<div class="trip wave-a" id="trip-a">
<div class="trip-name">
Wave A / Car A
<span>A1 · A2 · A3 · A4</span>
</div>
<div>
<div class="trip-status">
<strong id="status-a">Walking to agreed stop</strong>
<span class="trip-time" id="time-a">00:00</span>
</div>
<div class="progress"><div></div></div>
</div>
</div>
<div class="trip wave-b" id="trip-b">
<div class="trip-name">
Wave B / Car B
<span>B1 · B2 · B3 · B4</span>
</div>
<div>
<div class="trip-status">
<strong id="status-b">Carpool ride to workplace</strong>
<span class="trip-time" id="time-b">00:21</span>
</div>
<div class="progress"><div></div></div>
</div>
</div>
</div>
<div class="legend">
<div class="legend-title">How to read the scene</div>
<div class="legend-row">
<span class="swatch" style="background:#167f75"></span>
Wave A participants and car
</div>
<div class="legend-row">
<span class="swatch" style="background:#b8781c"></span>
Wave B participants and car
</div>
<div class="legend-row">
<span class="swatch" style="background:#f5f0df; border:1px solid #788285"></span>
Sidewalk and agreed pickup stops
</div>
</div>
</section>
<div class="camera-help">Drag to orbit · wheel to zoom · double-click to reset camera</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Basic scene
// ---------------------------------------------------------------------
const container = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfd5dc);
scene.fog = new THREE.Fog(0xbfd5dc, 70, 118);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly schematic of a Montgomery neighborhood during the bus boycott"
);
container.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xeaf7ff, 0x78694e, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0ce, 3.1);
sun.position.set(-26, 42, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 95;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d8e8, 0.75);
fill.position.set(30, 18, -28);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
const M = {
ground: material(0x9eb786),
grass: material(0x829f6e),
road: material(0x454d50),
sidewalk: material(0xd9d4c7),
curb: material(0xeee9dc),
yellow: material(0xe8bb55),
white: material(0xf4f1e8),
brick: material(0xa95e48),
brickDark: material(0x7b4439),
teal: material(0x167f75),
amber: material(0xb8781c),
wood: material(0x70513c),
trunk: material(0x6f513a),
leaves: material(0x4f7852),
leavesLight: material(0x739661),
glass: material(0x39555d, { roughness: 0.25, metalness: 0.05 }),
tire: material(0x202729),
chrome: material(0xc3c8c5, { roughness: 0.35, metalness: 0.45 }),
dark: material(0x263437)
};
function addBox(w, h, d, x, y, z, mat, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
x,
y,
z,
mat,
segments = 10,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, width = 5, background = "#20393b", foreground = "#fffdf4") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
ctx.beginPath();
if (ctx.roundRect) {
ctx.roundRect(5, 5, 758, 182, 24);
} else {
ctx.rect(5, 5, 758, 182);
}
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.65)";
ctx.lineWidth = 5;
ctx.stroke();
const lines = text.split("\n");
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = `${lines.length > 1 ? 760 / lines.length : 880}px ${lines.length > 1 ? 650 : 800}px Arial`;
const startY = canvas.height / 2 - ((lines.length - 1) * 54);
lines.forEach((line, i) => ctx.fillText(line, canvas.width / 2, startY + i * 108));
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 30;
return sprite;
}
// ---------------------------------------------------------------------
// Ground, roads, sidewalks, markings
// ---------------------------------------------------------------------
addBox(66, 0.6, 45, 0, -0.3, 2, M.ground);
addBox(64, 0.08, 8, 0, 0.04, 0, M.road);
addBox(7, 0.08, 34, 25, 0.045, 3, M.road);
// Main-road sidewalks, interrupted at the vertical street.
addBox(53.4, 0.17, 2.2, -5.3, 0.085, 5.3, M.sidewalk);
addBox(3.6, 0.17, 2.2, 30.2, 0.085, 5.3, M.sidewalk);
addBox(53.4, 0.17, 2.2, -5.3, 0.085, -5.3, M.sidewalk);
addBox(3.6, 0.17, 2.2, 30.2, 0.085, -5.3, M.sidewalk);
// Side-street sidewalks.
addBox(1.5, 0.17, 30, 20.8, 0.085, 3.5, M.sidewalk);
addBox(1.5, 0.17, 30, 29.2, 0.085, 3.5, M.sidewalk);
// Curb strips.
addBox(53.4, 0.22, 0.24, -5.3, 0.11, 6.42, M.curb);
addBox(53.4, 0.22, 0.24, -5.3, 0.11, -6.42, M.curb);
addBox(0.24, 0.22, 30, 19.95, 0.11, 3.5, M.curb);
addBox(0.24, 0.22, 30, 30.05, 0.11, 3.5, M.curb);
for (let x = -29; x < 31; x += 4.2) {
addBox(2.1, 0.025, 0.12, x, 0.095, 0, M.yellow, scene, false);
}
for (let z = -10; z < 19; z += 4.2) {
addBox(0.12, 0.025, 2.1, 25, 0.1, z, M.yellow, scene, false);
}
// Crosswalk from the car drop-off toward the workplace sidewalk.
for (let x = 21.8; x < 29; x += 0.78) {
addBox(0.38, 0.025, 2.2, x, 0.11, 7, M.white, scene, false);
}
// Small grass islands and planting strips.
addBox(14, 0.16, 2.2, -10, 0.08, 8.6, M.grass);
addBox(4, 0.16, 2.2, 15, 0.08, -8.4, M.grass);
function addArrow(x, z, angle, color = 0xd6e3d2) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[0.9, 0, 0, -0.75, 0, 0.55, -0.75, 0, -0.55],
3
)
);
geometry.computeVertexNormals();
const arrow = new THREE.Mesh(geometry, material(color));
arrow.position.set(x, 0.125, z);
arrow.rotation.y = angle;
scene.add(arrow);
}
addArrow(-19, 2.15, 0);
addArrow(-5, 2.15, 0);
addArrow(11, 2.15, 0);
addArrow(19, 2.15, 0);
addArrow(26.5, 13, -Math.PI / 2);
// ---------------------------------------------------------------------
// Neighborhood houses
// ---------------------------------------------------------------------
const houseXs = [-28, -23.5, -19, -14.5, -10, -5.5, -1, 3.5];
const houseColors = [0xc2a06e, 0xb98661, 0xd6bd88, 0xa77760];
const roofColors = [0x5f5149, 0x7a4e42, 0x53615d, 0x6d594c];
function makeHouse(x, index) {
const group = new THREE.Group();
group.position.set(x, 0, 12);
const bodyMat = material(houseColors[index % houseColors.length]);
const roofMat = material(roofColors[index % roofColors.length]);
addBox(3.25, 3.15, 3.35, 0, 1.75, 0, bodyMat, group);
addBox(3.55, 0.22, 3.65, 0, 3.38, 0, roofMat, group);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.55, 1.55, 4),
roofMat
);
roof.position.y = 4.2;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.9;
roof.castShadow = true;
group.add(roof);
// Front door faces the road.
addBox(0.72, 1.65, 0.09, 0, 1.0, -1.72, M.wood, group);
addBox(1.05, 0.12, 0.7, 0, 0.18, -2.05, M.curb, group);
addBox(0.95, 0.85, 0.08, -1.05, 1.7, -1.72, M.glass, group);
addBox(0.95, 0.85, 0.08, 1.05, 1.7, -1.72, M.glass, group);
addBox(0.95, 0.85, 0.08, 0, 2.55, -1.72, M.glass, group);
// Tiny rear-facing windows for depth.
addBox(0.9, 0.8, 0.07, -0.75, 1.7, 1.71, M.glass, group);
addBox(0.9, 0.8, 0.07, 0.75, 1.7, 1.71, M.glass, group);
scene.add(group);
}
houseXs.forEach((x, i) => makeHouse(x, i));
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
addCylinder(0.18, 0.25, 1.8, 0, 0.9, 0, M.trunk, 7, group);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.25, 0),
i => i
);
crown.visible = false;
group.add(crown);
const crown1 = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.25, 0),
M.leaves
);
crown1.position.y = 2.55;
crown1.scale.set(1, 1.15, 1);
crown1.castShadow = true;
group.add(crown1);
const crown2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.9, 0),
M.leavesLight
);
crown2.position.set(0.55, 3.15, 0.1);
crown2.castShadow = true;
group.add(crown2);
scene.add(group);
}
[
[-30, 17.5], [-16.5, 17.5], [-2.5, 18],
[10.5, 16.5], [14, 8], [11, -9], [-18, -10],
[-29, -11], [7, -14]
].forEach(([x, z], i) => makeTree(x, z, 0.78 + (i % 3) * 0.12));
// ---------------------------------------------------------------------
// Community gathering point / symbolic carpool board
// ---------------------------------------------------------------------
addCylinder(3.1, 3.1, 0.18, 8, 0.1, 10, M.curb, 24);
addBox(0.18, 2.2, 0.18, 6.4, 1.25, 12, M.wood);
addBox(0.18, 2.2, 0.18, 9.6, 1.25, 12, M.wood);
addBox(3.55, 1.55, 0.18, 8, 2.15, 12, M.wood);
addBox(3.2, 1.2, 0.08, 8, 2.15, 11.88, material(0xe9dfc4));
const scheduleBoard = makeLabel(
"COMMUNITY GATHERING\nCARPOOL BOARD\nWAVE A 00:00 · WAVE B 00:21",
7.1,
"#674d36",
"#fff8df"
);
scheduleBoard.position.set(8, 3.7, 12);
scene.add(scheduleBoard);
// Benches.
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
addBox(2.1, 0.16, 0.52, 0, 0.62, 0, M.wood, group);
addBox(2.1, 0.7, 0.13, 0, 1.0, 0.25, M.wood, group);
addBox(0.16, 0.55, 0.45, -0.78, 0.3, 0, M.dark, group);
addBox(0.16, 0.55, 0.45, 0.78, 0.3, 0, M.dark, group);
scene.add(group);
}
addBench(6.4, 8.9, Math.PI / 2);
addBench(9.4, 8.9, Math.PI / 2);
// ---------------------------------------------------------------------
// Workplace destination
// ---------------------------------------------------------------------
addBox(8, 6, 6, 16.5, 3.15, 14, M.brick);
addBox(8.5, 0.35, 6.5, 16.5, 6.25, 14, M.brickDark);
addBox(1.45, 2.2, 0.12, 16.5, 1.25, 10.94, M.dark);
addBox(1.7, 0.14, 0.8, 16.5, 0.18, 10.55, M.curb);
for (const x of [13.4, 16.5, 19.6]) {
for (const y of [2.2, 4.45]) {
addBox(1.55, 1.35, 0.08, x, y, 10.94, M.glass);
}
}
const workplaceSign = makeLabel(
"WORKPLACE\nDOWNTOWN DESTINATION",
7.2,
"#694238",
"#fff5dc"
);
workplaceSign.position.set(16.5, 7.3, 13.4);
scene.add(workplaceSign);
const arrivalSign = makeLabel("ARRIVAL STOP\nWALK TO WORKPLACE", 5.2, "#35575a");
arrivalSign.position.set(20.7, 3.0, 8.5);
scene.add(arrivalSign);
// ---------------------------------------------------------------------
// Shared pickup stops
// ---------------------------------------------------------------------
const stopXs = [-12, 0];
function makeStop(x, number) {
addCylinder(0.07, 0.09, 2.6, x, 1.3, 6.0, M.dark, 8);
const sign = makeLabel(
`STOP ${number}\nA + B PICKUP`,
3.5,
number === 1 ? "#1d6663" : "#745421"
);
sign.position.set(x, 3.05, 6.0);
scene.add(sign);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.68, 0.08, 6, 18),
material(number === 1 ? 0x3bb7a7 : 0xe4a63e)
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.2, 4.72);
scene.add(ring);
}
stopXs.forEach((x, i) => makeStop(x, i + 1));
const schematicRoadSign = makeLabel(
"SCHEMATIC ROUTES\nNOT A RECONSTRUCTION",
6.8,
"#293f43",
"#fff9e8"
);
schematicRoadSign.position.set(-7, 2.4, -6.7);
scene.add(schematicRoadSign);
// ---------------------------------------------------------------------
// Period-style public bus, parked and out of service
// ---------------------------------------------------------------------
function makeBus() {
const bus = new THREE.Group();
bus.position.set(-28, 0.15, -2.15);
const busYellow = material(0xcda83e);
const busGreen = material(0x496f61);
const busCream = material(0xe4d5aa);
addBox(6.2, 1.25, 2.05, 0, 1.25, 0, busGreen, bus);
addBox(6.15, 0.75, 2.08, 0, 2.15, 0, busCream, bus);
addBox(6.3, 0.18, 2.12, 0, 2.62, 0, busYellow, bus);
addBox(6.0, 0.18, 1.95, 0, 0.73, 0, busYellow, bus);
for (const side of [-1, 1]) {
for (const x of [-2.1, -0.7, 0.7, 2.1]) {
addBox(1.12, 0.8, 0.055, x, 2.13, side * 1.055, M.glass, bus);
}
}
addBox(0.08, 1.0, 1.8, 3.12, 1.85, 0, M.glass, bus);
for (const x of [-2.0, 2.0]) {
for (const side of [-1, 1]) {
const wheel = addCylinder(
0.45, 0.45, 0.28, x, 0.48, side * 1.03, M.tire, 12, bus
);
wheel.rotation.x = Math.PI / 2;
}
}
const busLabel = makeLabel("PUBLIC BUS\nOUT OF SERVICE", 4.8, "#4d563c");
busLabel.position.set(0, 3.45, 0);
bus.add(busLabel);
scene.add(bus);
}
makeBus();
// ---------------------------------------------------------------------
// Shared open cars
// ---------------------------------------------------------------------
function makeCar(colorMat, shortName) {
const group = new THREE.Group();
group.position.y = 0.13;
addBox(3.8, 0.45, 1.75, 0, 0.72, 0, colorMat, group);
addBox(1.25, 0.38, 1.62, 1.25, 1.08, 0, colorMat, group);
addBox(0.22, 0.8, 1.75, -1.78, 1.15, 0, colorMat, group);
addBox(3.35, 0.14, 1.42, -0.2, 0.98, 0, M.dark, group);
// Low windshield frame, left open so riders remain identifiable.
const windshield = addBox(0.08, 0.72, 1.5, 0.82, 1.48, 0, M.glass, group);
windshield.rotation.z = -0.12;
for (const x of [-1.2, 1.2]) {
for (const side of [-1, 1]) {
const wheel = addCylinder(
0.43, 0.43, 0.25, x, 0.46, side * 0.91, M.tire, 12, group
);
wheel.rotation.x = Math.PI / 2;
const hub = addCylinder(
0.19, 0.19, 0.27, x, 0.46, side * 0.94, M.chrome, 10, group
);
hub.rotation.x = Math.PI / 2;
}
}
addBox(0.16, 0.18, 1.9, 1.98, 0.73, 0, M.chrome, group);
addBox(0.16, 0.18, 1.9, -1.98, 0.73, 0, M.chrome, group);
addBox(0.08, 0.24, 0.42, 2.03, 1.0, 0.57, M.white, group);
addBox(0.08, 0.24, 0.42, 2.03, 1.0, -0.57, M.white, group);
// Bench seats.
addBox(0.62, 0.52, 1.2, -1.0, 1.16, 0, M.dark, group);
addBox(0.62, 0.52, 1.2, 0.62, 1.16, 0, M.dark, group);
const id = makeLabel(shortName, 1.35, colorMat === M.teal ? "#125f59" : "#7b4d13");
id.position.set(1.28, 1.92, 0);
group.add(id);
scene.add(group);
return group;
}
// ---------------------------------------------------------------------
// People
// ---------------------------------------------------------------------
const shirtA = [0x198e80, 0x55b5a4, 0x116f67, 0x8acfc1];
const shirtB = [0xc28727, 0xe1b455, 0xa95f1f, 0xf0d28a];
const skinTones = [0x6f432d, 0x8d5b3c, 0xb87b52, 0x5b3929];
function makePerson(participantId, shirtColor, skinColor, index) {
const root = new THREE.Group();
const shirtMat = material(shirtColor);
const skinMat = material(skinColor);
const trouserMat = material(index % 2 ? 0x4b5150 : 0x304a51);
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.34, 0.75, 7),
shirtMat
);
torso.position.y = 1.03;
torso.castShadow = true;
root.add(torso);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.235, 8, 6),
skinMat
);
head.position.y = 1.64;
head.castShadow = true;
root.add(head);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.245, 8, 5, 0, Math.PI * 2, 0, Math.PI * 0.54),
material(0x2d2522)
);
hair.position.y = 1.68;
root.add(hair);
const legL = addBox(0.17, 0.58, 0.19, -0.15, 0.37, 0, trouserMat, root);
const legR = addBox(0.17, 0.58, 0.19, 0.15, 0.37, 0, trouserMat, root);
const armL = addBox(0.14, 0.62, 0.16, -0.39, 1.03, 0, shirtMat, root);
const armR = addBox(0.14, 0.62, 0.16, 0.39, 1.03, 0, shirtMat, root);
addBox(0.23, 0.17, 0.04, 0, 1.12, -0.3, M.white, root);
const label = makeLabel(
participantId,
1.2,
shirtColor === undefined ? "#263b3e" : "#263b3e"
);
label.position.set(0, 2.35, 0);
root.add(label);
scene.add(root);
return { root, legL, legR, armL, armR, label, index };
}
// ---------------------------------------------------------------------
// Route and timing helpers
// ---------------------------------------------------------------------
const CYCLE = 42;
const WAVE_OFFSET = 21;
function point(x, z, y = 0.18) {
return new THREE.Vector3(x, y, z);
}
function samplePath(points, progress) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let remaining = THREE.MathUtils.clamp(progress, 0, 1) * total;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i] || i === lengths.length - 1) {
const t = lengths[i] === 0 ? 0 : remaining / lengths[i];
const position = points[i].clone().lerp(points[i + 1], t);
const direction = points[i + 1].clone().sub(points[i]);
return { position, direction };
}
remaining -= lengths[i];
}
return { position: points[0].clone(), direction: new THREE.Vector3(0, 0, 1) };
}
function quadratic(a, b, c, t) {
const inv = 1 - t;
return new THREE.Vector2(
inv * inv * a.x + 2 * inv * t * b.x + t * t * c.x,
inv * inv * a.y + 2 * inv * t * b.y + t * t * c.y
);
}
// Car path:
// start → Stop 1 → Stop 2 → right turn → workplace drop-off →
// return lane → westbound return.
function carPosition(phase) {
const p = ((phase % CYCLE) + CYCLE) % CYCLE;
if (p < 3) {
return new THREE.Vector3(
THREE.MathUtils.lerp(-22, -12, p / 3),
2.15
);
}
if (p < 6) return new THREE.Vector2(-12, 2.15);
if (p < 11) {
return new THREE.Vector2(
THREE.MathUtils.lerp(-12, 0, (p - 6) / 5),
2.15
);
}
if (p < 14) return new THREE.Vector2(0, 2.15);
if (p < 19) {
return new THREE.Vector2(
THREE.MathUtils.lerp(0, 25, (p - 14) / 5),
2.15
);
}
if (p < 22) {
return quadratic(
new THREE.Vector2(25, 2.15),
new THREE.Vector2(26.5, 2.15),
new THREE.Vector2(26.5, 7),
(p - 19) / 3
);
}
if (p < 28) return new THREE.Vector2(26.5, 7);
if (p < 32) {
return new THREE.Vector2(
26.5,
THREE.MathUtils.lerp(7, -2.15, (p - 28) / 4)
);
}
if (p < 35) {
return quadratic(
new THREE.Vector2(26.5, -2.15),
new THREE.Vector2(21.5, -2.15),
new THREE.Vector2(18, -2.15),
(p - 32) / 3
);
}
if (p < 40) {
return new THREE.Vector2(
THREE.MathUtils.lerp(18, -22, (p - 35) / 5),
-2.15
);
}
return new THREE.Vector2(-22, -2.15);
}
function makeParticipantGroup({
name,
offset,
colorMat,
colorKey,
shirtColors,
homeXs
}) {
const car = makeCar(colorMat, name);
const people = [];
homeXs.forEach((homeX, i) => {
const person = makePerson(
`${name}${i + 1}`,
shirtColors[i],
skinTones[i % skinTones.length],
i
);
const stopX = i % 2 === 0 ? -12 : 0;
const stopNumber = i % 2 === 0 ? 1 : 2;
const walkEnd = stopNumber === 1 ? 3 : 11;
const boardingStart = stopNumber === 1 ? 6 : 14;
const walkPath = [
point(homeX, 10.35),
point(homeX, 7.25),
point(stopX, 7.25),
point(stopX, 4.72)
];
const arrivalPath = [
point(25.55, 7 + (i - 1.5) * 0.28),
point(20.55, 7 + (i - 1.5) * 0.28),
point(20.55, 9.1 + i * 0.28),
point(16.5 + (i - 1.5) * 0.75, 10.55)
];
people.push({
...person,
homeX,
stopX,
walkEnd,
boardingStart,
walkPath,
arrivalPath,
seat: new THREE.Vector3(
i < 2 ? -0.82 : 0.54,
0.66,
i % 2 === 0 ? -0.47 : 0.47
)
});
});
return { name, offset, colorKey, car, people, heading: 0 };
}
const groups = [
makeParticipantGroup({
name: "A",
offset: 0,
colorMat: M.teal,
colorKey: "#167f75",
shirtColors: shirtA,
homeXs: [-28, -23.5, -19, -14.5]
}),
makeParticipantGroup({
name: "B",
offset: WAVE_OFFSET,
colorMat: M.amber,
colorKey: "#b8781c",
shirtColors: shirtB,
homeXs: [-10, -5.5, -1, 3.5]
})
];
function animateLimbs(person, walking, phase) {
if (walking) {
const swing = Math.sin(phase * 2.2 + person.index * 1.4) * 0.52;
person.legL.rotation.x = swing;
person.legR.rotation.x = -swing;
person.armL.rotation.x = -swing * 0.75;
person.armR.rotation.x = swing * 0.75;
} else {
person.legL.rotation.x = 0;
person.legR.rotation.x = 0;
person.armL.rotation.x = 0;
person.armR.rotation.x = 0;
}
}
function updateGroup(group, phase, globalTime) {
const car = group.car;
const position = carPosition(phase);
car.position.x = position.x;
car.position.z = position.y;
const before = carPosition(phase - 0.035);
const after = carPosition(phase + 0.035);
const dx = after.x - before.x;
const dz = after.y - before.y;
if (Math.abs(dx) + Math.abs(dz) > 0.0001) {
group.heading = -Math.atan2(dz, dx);
}
car.rotation.y = group.heading;
car.updateMatrixWorld(true);
for (const person of group.people) {
let walking = false;
if (phase < person.walkEnd) {
const sample = samplePath(person.walkPath, phase / person.walkEnd);
person.root.position.copy(sample.position);
person.root.rotation.y = Math.atan2(sample.direction.x, sample.direction.z);
person.root.scale.set(1, 1, 1);
walking = true;
} else if (phase < person.boardingStart) {
person.root.position.copy(person.walkPath[person.walkPath.length - 1]);
person.root.rotation.y = Math.PI;
person.root.scale.set(1, 1, 1);
} else if (phase < 28) {
const seatWorld = person.seat.clone();
car.localToWorld(seatWorld);
person.root.position.copy(seatWorld);
person.root.rotation.y = group.heading + Math.PI / 2;
person.root.scale.set(1, 0.72, 1);
} else if (phase < 34) {
const sample = samplePath(
person.arrivalPath,
(phase - 28) / 6
);
person.root.position.copy(sample.position);
person.root.rotation.y = Math.atan2(sample.direction.x, sample.direction.z);
person.root.scale.set(1, 1, 1);
walking = true;
} else {
person.root.position.copy(person.arrivalPath[person.arrivalPath.length - 1]);
person.root.rotation.y = -Math.PI / 2;
person.root.scale.set(1, 1, 1);
}
animateLimbs(person, walking, globalTime);
}
}
function statusForPhase(phase) {
if (phase < 3) return "Walking to agreed stop";
if (phase < 6) return "Stop 1 · boarding";
if (phase < 11) return "En route · collecting Stop 2";
if (phase < 14) return "Stop 2 · boarding";
if (phase < 22) return "Carpool ride to workplace";
if (phase < 28) return "At arrival stop · unloading";
if (phase < 34) return "Walking into workplace";
return "Arrived · trip complete";
}
// ---------------------------------------------------------------------
// Direct camera controls — no addons
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0.8, 0.4, 3.0),
radius: 66,
theta: 0.57,
phi: 0.93
};
const defaultCamera = {
target: cameraState.target.clone(),
radius: cameraState.radius,
theta: cameraState.theta,
phi: cameraState.phi
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
let dragging = false;
let dragX = 0;
let dragY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.38,
1.28
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.045,
32,
92
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
updateCamera();
});
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft": cameraState.theta += 0.08; break;
case "ArrowRight": cameraState.theta -= 0.08; break;
case "ArrowUp":
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - 0.06, 0.38, 1.28);
break;
case "ArrowDown":
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + 0.06, 0.38, 1.28);
break;
case "+":
case "=": cameraState.radius = Math.max(32, cameraState.radius - 3); break;
case "-": cameraState.radius = Math.min(92, cameraState.radius + 3); break;
default: handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
updateCamera();
// ---------------------------------------------------------------------
// Timeline UI
// ---------------------------------------------------------------------
const playToggle = document.getElementById("play-toggle");
const restart = document.getElementById("restart");
const speedSelect = document.getElementById("speed");
const cycleClock = document.getElementById("cycle-clock");
let elapsed = 0;
let playing = true;
let playbackSpeed = 1;
playToggle.addEventListener("click", () => {
playing = !playing;
playToggle.textContent = playing ? "Pause" : "Play";
playToggle.setAttribute(
"aria-label",
playing ? "Pause animation" : "Play animation"
);
});
restart.addEventListener("click", () => {
elapsed = 0;
});
speedSelect.addEventListener("change", () => {
playbackSpeed = Number(speedSelect.value);
});
function clockText(seconds) {
const whole = Math.floor(seconds);
const minutes = Math.floor(whole / 60);
const remainder = whole % 60;
return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
}
function updateHUD() {
const cyclePhase = elapsed % CYCLE;
cycleClock.textContent = `${clockText(cyclePhase)} / 00:42`;
groups.forEach((group, i) => {
const phase = (elapsed + group.offset) % CYCLE;
const key = i === 0 ? "a" : "b";
const row = document.getElementById(`trip-${key}`);
const status = document.getElementById(`status-${key}`);
const time = document.getElementById(`time-${key}`);
const progress = row.querySelector(".progress > div");
status.textContent = statusForPhase(phase);
time.textContent = clockText(phase);
progress.style.width = `${(phase / CYCLE) * 100}%`;
});
}
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
let lastTime = performance.now();
let lastHUD = 0;
function render(now) {
requestAnimationFrame(render);
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
elapsed += dt * playbackSpeed;
}
groups.forEach(group => {
const phase = (elapsed + group.offset) % CYCLE;
updateGroup(group, phase, elapsed);
});
if (now - lastHUD > 80) {
updateHUD();
lastHUD = now;
}
renderer.render(scene, camera);
}
requestAnimationFrame(render);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```