Prompt specification
Build or customize the Three.js 3D scene "Small Transit Street With Two Stops" 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: Small Transit Street With Two Stops
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/small-transit-street-with-two-stops-x2087
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: small transit street with two stops. Build an original street with buses, shelters, and pedestrian approaches. Model fixed travel and dwell times and display why a following bus may catch up.
Working Three.js Starter (small-transit-street-with-two-stops-x2087):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Voxel Transit Street — Cedar Street Bunching</title>
<style>
:root {
--ink: #172235;
--muted: #65738a;
--glass: rgba(248, 251, 255, 0.90);
--line: rgba(23, 34, 53, 0.12);
--orange: #f06b45;
--blue: #3276e8;
--cyan: #1aa6a6;
--amber: #e3a52f;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd8e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene, #scene canvas {
position: fixed;
inset: 0;
display: block;
}
.glass {
position: fixed;
z-index: 10;
background: var(--glass);
border: 1px solid rgba(255,255,255,.75);
box-shadow: 0 18px 55px rgba(37, 54, 76, .18);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 18px;
left: 18px;
width: 335px;
padding: 17px 18px 16px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 4px;
font-size: 25px;
line-height: 1.05;
letter-spacing: -.035em;
}
#intro p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.route-tag {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 11px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255,255,255,.7);
color: #36465d;
font-size: 10px;
font-weight: 750;
}
.route-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(26,166,166,.14);
}
#info {
top: 18px;
right: 18px;
width: 382px;
max-height: calc(100vh - 98px);
overflow: auto;
padding: 17px 18px 16px;
border-radius: 18px;
scrollbar-width: thin;
}
.panel-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.panel-title h2 {
margin: 4px 0 0;
font-size: 20px;
line-height: 1.12;
letter-spacing: -.025em;
}
#clock {
flex: 0 0 auto;
padding: 6px 8px;
border-radius: 8px;
background: #172235;
color: white;
font: 750 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.badge {
margin-top: 12px;
padding: 8px 10px;
border-radius: 10px;
background: #e7f6f4;
border: 1px solid rgba(26,166,166,.18);
color: #137e7e;
font-size: 10px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
.badge.hot {
background: #fff0e9;
border-color: rgba(240,107,69,.24);
color: #bd4b2c;
animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse {
to { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(240,107,69,.18); }
}
.reason {
margin: 11px 0 14px;
font-size: 12px;
line-height: 1.52;
color: #46556b;
}
.reason strong { color: var(--ink); }
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.metric {
min-width: 0;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.62);
}
.metric span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
}
.metric b {
display: block;
margin-top: 4px;
overflow: hidden;
color: var(--ink);
font-size: 13px;
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
}
.gap-track {
height: 7px;
margin-top: 12px;
overflow: hidden;
border-radius: 999px;
background: #dde4ec;
}
#gapBar {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), #f4bd54);
transition: width .08s linear;
}
.timeline-wrap {
margin-top: 16px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.timeline-title {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 9px;
}
.timeline-title b {
font-size: 11px;
letter-spacing: .06em;
text-transform: uppercase;
}
.timeline-title span {
color: var(--muted);
font-size: 9px;
}
.timeline-row {
display: grid;
grid-template-columns: 39px 1fr;
align-items: center;
gap: 8px;
margin: 6px 0;
}
.timeline-row > b {
font-size: 10px;
}
.track {
position: relative;
height: 18px;
overflow: hidden;
border-radius: 5px;
background:
repeating-linear-gradient(90deg, transparent 0, transparent calc(10% - 1px),
rgba(23,34,53,.08) calc(10% - 1px), rgba(23,34,53,.08) 10%);
}
.seg {
position: absolute;
top: 0;
bottom: 0;
min-width: 2px;
}
.seg.run { background: #8eb6e9; }
.seg.dwell { background: #f5a565; }
.seg.queue { background: repeating-linear-gradient(135deg,#e76845 0 5px,#f8ad70 5px 10px); }
.seg.after { background: #b9c5d4; }
.legend {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 9px;
color: var(--muted);
font-size: 9px;
}
.legend i {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 4px;
border-radius: 2px;
vertical-align: -1px;
}
.legend .run { background: #8eb6e9; }
.legend .dwell { background: #f5a565; }
.legend .queue { background: #e76845; }
.fixed-times {
margin-top: 14px;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.55);
}
.fixed-times h3 {
margin: 0 0 7px;
font-size: 10px;
letter-spacing: .08em;
text-transform: uppercase;
}
.fixed-times div {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 4px 0;
color: #536176;
font-size: 10px;
}
.fixed-times b { color: var(--ink); }
.note {
margin-top: 11px;
color: #7b8798;
font-size: 9px;
line-height: 1.45;
}
#controls {
left: 50%;
bottom: 18px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 14px;
transform: translateX(-50%);
}
button {
border: 0;
border-radius: 9px;
padding: 9px 11px;
background: #edf1f6;
color: #33445b;
font: inherit;
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: transform .12s ease, background .12s ease;
}
button:hover { transform: translateY(-1px); background: #e2e8f0; }
button:active { transform: translateY(0); }
button.primary { background: var(--ink); color: white; }
button.accent { background: #fff0e9; color: #b8492b; }
button[aria-pressed="true"] { background: var(--cyan); color: white; }
.divider {
width: 1px;
height: 25px;
margin: 0 2px;
background: var(--line);
}
#hint {
position: fixed;
z-index: 5;
left: 18px;
bottom: 20px;
padding: 7px 10px;
border-radius: 8px;
background: rgba(23,34,53,.78);
color: rgba(255,255,255,.78);
font-size: 9px;
pointer-events: none;
}
@media (max-width: 900px) {
#intro {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 12px 14px;
}
#intro p, .route-tag { display: none; }
h1 { font-size: 19px; }
#info {
top: auto;
right: 10px;
bottom: 74px;
width: calc(100% - 20px);
max-height: 43vh;
padding: 14px;
}
#controls {
bottom: 10px;
max-width: calc(100% - 20px);
overflow-x: auto;
justify-content: flex-start;
}
#hint { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="intro" class="glass">
<div class="eyebrow">Deterministic Transit Study</div>
<h1>Cedar Street<br>Bunching Lab</h1>
<p>Two fixed-route buses. Two curbside stops. One long boarding dwell turns a following bus into a queue.</p>
<div class="route-tag"><span class="route-dot"></span> ROUTE 7 · EASTBOUND · CEDAR STREET</div>
</section>
<section id="info" class="glass">
<div class="panel-title">
<div>
<div class="eyebrow">Why Bus 07 Catches Bus 01</div>
<h2>A dwell creates the bunch.</h2>
</div>
<div id="clock">00:00.0</div>
</div>
<div id="eventBadge" class="badge">Scenario running</div>
<p class="reason">
Bus <strong>01</strong> reaches Cedar Market A after <strong>6.7 s</strong> and dwells for
<strong>22.0 s</strong>. Bus <strong>07</strong> would arrive in <strong>11.3 s</strong>
without the leader, so it catches the stopped bus and closes the usable gap.
</p>
<div class="metrics">
<div class="metric">
<span>Bus 01</span>
<b id="leadStatus">Approaching A</b>
</div>
<div class="metric">
<span>Bus 07</span>
<b id="followStatus">Approaching A</b>
</div>
<div class="metric">
<span>Centre gap</span>
<b id="gapValue">10.0 m</b>
</div>
</div>
<div class="gap-track"><div id="gapBar"></div></div>
<div class="timeline-wrap">
<div class="timeline-title">
<b>Fixed event timeline</b>
<span>0–70 seconds</span>
</div>
<div class="timeline-row">
<b>01</b>
<div class="track">
<span class="seg run" style="left:0%;width:9.52%"></span>
<span class="seg dwell" style="left:9.52%;width:31.43%"></span>
<span class="seg run" style="left:40.95%;width:8.93%"></span>
<span class="seg dwell" style="left:49.88%;width:25.72%"></span>
<span class="seg after" style="left:75.60%;width:24.40%"></span>
</div>
</div>
<div class="timeline-row">
<b>07</b>
<div class="track">
<span class="seg run" style="left:0%;width:13.17%"></span>
<span class="seg queue" style="left:13.17%;width:30.76%"></span>
<span class="seg dwell" style="left:43.93%;width:17.15%"></span>
<span class="seg run" style="left:61.08%;width:8.35%"></span>
<span class="seg queue" style="left:69.43%;width:8.80%"></span>
<span class="seg dwell" style="left:78.23%;width:20.00%"></span>
</div>
</div>
<div class="legend">
<span><i class="run"></i>travel</span>
<span><i class="dwell"></i>fixed dwell</span>
<span><i class="queue"></i>blocked behind leader</span>
</div>
</div>
<div class="fixed-times">
<h3>Fixed operating assumptions</h3>
<div><span>01 → A / dwell A</span><b>6.7 s / 22.0 s</b></div>
<div><span>A → B / dwell B</span><b>6.3 s / 18.0 s</b></div>
<div><span>07 free-flow → A</span><b>11.3 s</b></div>
<div><span>07 actual arrival A</span><b>30.8 s</b></div>
<div><span>07 dwell A / B</span><b>12.0 s / 14.0 s</b></div>
<div><span>Minimum centre gap</span><b>4.8 m</b></div>
</div>
<div class="note">
Illustrative deterministic dwell times, not a live schedule. The 22 s stop is
2 alightings × 4 s + 2 boardings × 5 s + 4 s door/queue clearance.
</div>
</section>
<div id="controls" class="glass">
<button id="play" class="primary">Pause</button>
<button id="reset">Restart</button>
<button id="jump" class="accent">Jump to catch-up</button>
<div class="divider"></div>
<button class="speed" data-speed="1" aria-pressed="true">1×</button>
<button class="speed" data-speed="2" aria-pressed="false">2×</button>
<button class="speed" data-speed="4" aria-pressed="false">4×</button>
<div class="divider"></div>
<button id="viewIso">Isometric</button>
<button id="viewTop">Top view</button>
</div>
<div id="hint">Drag to orbit · Scroll to zoom · Arrow keys rotate · Space pauses · R restarts</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd8e2);
scene.fog = new THREE.Fog(0xcbd8e2, 62, 108);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
$("scene").appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(42, window.innerWidth / window.innerHeight, 0.1, 180);
const cameraState = {
yaw: 0.53,
pitch: 0.67,
distance: 58,
target: new THREE.Vector3(-1.5, 1.2, 0)
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
camera.position.set(
target.x + distance * Math.cos(pitch) * Math.sin(yaw),
target.y + distance * Math.sin(pitch),
target.z + distance * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xeaf5ff, 0x71806c, 2.25));
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(-18, 34, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -45;
sun.shadow.camera.right = 45;
sun.shadow.camera.top = 35;
sun.shadow.camera.bottom = -35;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.0004;
scene.add(sun);
const materialCache = new Map();
function material(color, options = {}) {
const key = color + "|" + JSON.stringify(options);
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
}));
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function textCanvas(text, background = "#172235", foreground = "#ffffff", width = 512, height = 128) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = foreground;
ctx.font = `800 ${Math.floor(height * 0.38)}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 2, width - 30);
return canvas;
}
function makeSprite(text, scale = [5, 1.25, 1], bg = "#172235", fg = "#ffffff") {
const texture = new THREE.CanvasTexture(textCanvas(text, bg, fg));
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.scale.set(scale[0], scale[1], scale[2]);
return sprite;
}
function makeSignPlane(text, width, height, bg = "#172235", fg = "#ffffff") {
const texture = new THREE.CanvasTexture(textCanvas(text, bg, fg));
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide,
depthWrite: false
})
);
return mesh;
}
const ground = new THREE.Group();
scene.add(ground);
box(ground, [74, 0.8, 31], [0, -0.58, 0], 0x9bb89c);
box(ground, [74, 0.24, 10], [0, 0, 0], 0x465365);
box(ground, [74, 0.36, 4.5], [0, 0.18, 7.25], 0xd8d5cb);
box(ground, [74, 0.36, 4.5], [0, 0.18, -7.25], 0xd8d5cb);
for (let x = -35; x <= 35; x += 3.2) {
box(ground, [1.45, 0.025, 0.11], [x, 0.145, 0], 0xf2f1df);
}
for (let x = -35; x <= 35; x += 2.8) {
box(ground, [1.15, 0.027, 0.12], [x, 0.153, 3.2], 0x55d2c4);
}
box(ground, [72, 0.035, 0.10], [0, 0.145, 4.84], 0xf7f2dd);
box(ground, [72, 0.035, 0.10], [0, 0.145, -4.84], 0xf7f2dd);
for (let x = -33; x < 35; x += 2.0) {
box(ground, [0.82, 0.028, 4.1], [x, 0.154, 0], 0xe9e6d7);
}
const stopA = -8;
const stopB = 12;
const BUS_Z = 3.15;
function shelter(x, name, accent) {
const group = new THREE.Group();
group.position.set(x, 0, 0);
scene.add(group);
box(group, [5.2, 0.20, 1.95], [0, 3.02, 6.45], accent);
box(group, [5.0, 0.12, 1.72], [0, 3.18, 6.43], 0xf4f5ef);
box(group, [4.65, 1.62, 0.07], [0, 1.55, 7.14], 0xa9d8df, {
transparent: true,
opacity: 0.38,
depthWrite: false
});
box(group, [0.07, 1.62, 1.45], [-2.30, 1.55, 6.42], 0xa9d8df, {
transparent: true,
opacity: 0.32,
depthWrite: false
});
for (const px of [-2.25, 2.25]) {
box(group, [0.11, 2.65, 0.11], [px, 1.48, 5.52], 0x30445b);
box(group, [0.11, 2.65, 0.11], [px, 1.48, 7.30], 0x30445b);
}
box(group, [3.25, 0.16, 0.55], [0, 0.83, 6.92], 0x8b6045);
box(group, [3.25, 0.48, 0.10], [0, 1.15, 7.12], 0x8b6045);
box(group, [0.12, 0.45, 0.12], [-1.2, 0.56, 6.92], 0x30445b);
box(group, [0.12, 0.45, 0.12], [1.2, 0.56, 6.92], 0x30445b);
box(group, [0.12, 3.2, 0.12], [2.82, 1.75, 4.78], 0x30445b);
box(group, [1.20, 1.05, 0.13], [2.82, 3.22, 4.78], accent);
const sign = makeSignPlane(name, 1.08, 0.46, "#ffffff", accent === 0xf06b45 ? "#b94c2d" : "#227b80");
sign.position.set(2.82, 3.22, 4.87);
group.add(sign);
const label = makeSprite(name, [5.7, 1.25, 1], "#ffffff", accent === 0xf06b45 ? "#a8472c" : "#176f74");
label.position.set(0, 4.10, 6.4);
group.add(label);
box(group, [2.4, 0.035, 0.70], [0, 0.39, 4.62], 0xe2c558);
for (let i = -4; i <= 4; i++) {
box(group, [0.07, 0.04, 0.65], [i * 0.23, 0.41, 4.62], 0xb99c3f);
}
return group;
}
shelter(stopA, "CEDAR MARKET A", 0xf06b45);
shelter(stopB, "RIVER SQUARE B", 0x1aa6a6);
function tree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
scene.add(g);
box(g, [0.42, 2.4, 0.42], [0, 1.2, 0], 0x76563e);
box(g, [2.3, 1.55, 2.0], [0, 3.05, 0], 0x4f8a60);
box(g, [1.45, 1.1, 1.45], [0.42, 4.0, 0.1], 0x65a56c);
box(g, [1.25, 0.85, 1.15], [-0.52, 3.55, -0.25], 0x76b779);
}
tree(-25, 7.7, 0.9);
tree(-15, 7.8, 0.75);
tree(2.5, 7.8, 0.85);
tree(21, 7.8, 0.8);
tree(-22, -7.8, 0.8);
tree(-10, -7.8, 0.72);
tree(7, -7.8, 0.9);
tree(25, -7.8, 0.78);
function streetLamp(x, z) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [0.12, 4.5, 0.12], [0, 2.25, 0], 0x30445b);
box(g, [0.8, 0.14, 0.14], [0.35, 4.43, 0], 0x30445b);
box(g, [0.52, 0.18, 0.34], [0.67, 4.30, 0], 0xfff0b0, {
emissive: 0xffd76a,
emissiveIntensity: 0.45
});
}
streetLamp(-21, 8.9);
streetLamp(-2, 8.9);
streetLamp(17, 8.9);
function building(x, z, width, depth, height, color, name) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [width, height, depth], [0, height / 2 + 0.36, 0], color);
box(g, [width + 0.28, 0.25, depth + 0.28], [0, height + 0.44, 0], 0x53637a);
box(g, [width + 0.12, 0.40, depth + 0.10], [0, 0.53, 0], 0x6e7781);
const frontZ = z > 0 ? z - depth / 2 - 0.06 : z + depth / 2 + 0.06;
const facingSouth = z > 0;
const windows = Math.max(2, Math.floor(width / 2.1));
for (let i = 0; i < windows; i++) {
const wx = -width / 2 + (i + 0.5) * width / windows;
box(g, [1.05, 1.15, 0.07], [wx, height * 0.58, frontZ], 0x9ac7d1, {
emissive: 0x4e7c83,
emissiveIntensity: 0.10
});
}
const sign = makeSignPlane(name, Math.min(width - 0.5, 5.3), 0.82, "#f4eee0", "#30445b");
sign.position.set(0, height * 0.28, frontZ + (facingSouth ? -0.055 : 0.055));
if (facingSouth) sign.rotation.y = Math.PI;
g.add(sign);
}
building(-26, 14.0, 7.5, 7, 6.5, 0xd3a889, "CEDAR DEPOT");
building(-14, 14.2, 7, 7, 8.3, 0x9eb8ae, "MARKET");
building(-1, 14.0, 7.5, 7, 5.8, 0xc5a3a3, "BOOKS");
building(13, 14.2, 8, 7, 8.8, 0xa9b8c8, "RIVER HALL");
building(26, 14.0, 7, 7, 6.1, 0xc9b487, "CAFE");
building(-25, -14.0, 8, 7, 7.1, 0x9eb2c5, "WORKS");
building(-11, -14.1, 7, 7, 5.4, 0xc7a59b, "STUDIO");
building(4, -14.0, 8, 7, 8.4, 0xa9b5a0, "GROCER");
building(20, -14.1, 8, 7, 6.4, 0xc7b18f, "CYCLES");
function makePerson(color, accent = 0x30445b) {
const group = new THREE.Group();
const leftLeg = box(group, [0.20, 0.70, 0.22], [-0.16, 0.43, 0], accent);
const rightLeg = box(group, [0.20, 0.70, 0.22], [0.16, 0.43, 0], accent);
box(group, [0.60, 0.66, 0.34], [0, 1.04, 0], color);
box(group, [0.40, 0.40, 0.38], [0, 1.62, 0], 0xe7b891);
const leftArm = box(group, [0.14, 0.62, 0.18], [-0.40, 1.02, 0], color);
const rightArm = box(group, [0.14, 0.62, 0.18], [0.40, 1.02, 0], color);
box(group, [0.43, 0.10, 0.42], [0, 1.85, 0], 0x3a4351);
group.userData.legs = [leftLeg, rightLeg];
group.userData.arms = [leftArm, rightArm];
return group;
}
function animatePerson(person, moving, time) {
const swing = moving ? Math.sin(time * 9 + person.userData.swingPhase) * 0.48 : 0;
person.userData.legs[0].rotation.x = swing;
person.userData.legs[1].rotation.x = -swing;
person.userData.arms[0].rotation.x = -swing * 0.75;
person.userData.arms[1].rotation.x = swing * 0.75;
}
const ambientPeople = [];
const personColors = [0xef835b, 0x397eb7, 0xe2b64d, 0x6d9b72, 0xa86cb0, 0x526a91];
function addAmbientPerson(x, z, offset, lane) {
const p = makePerson(personColors[ambientPeople.length % personColors.length]);
p.position.set(x, 0.39, z);
p.userData.swingPhase = ambientPeople.length * 1.7;
scene.add(p);
ambientPeople.push({ mesh: p, offset, lane });
}
addAmbientPerson(-18, 8.55, 0, 1);
addAmbientPerson(9, -8.55, 3, -1);
addAmbientPerson(-3, 8.55, 7, 1);
const crossingPerson = makePerson(0xe2b64d);
crossingPerson.userData.swingPhase = 9;
crossingPerson.position.set(3, 0.39, 7);
scene.add(crossingPerson);
const stopCrowds = {};
function createStopCrowd(x) {
const people = [];
const specs = [
{ role: "alighter", color: 0x5c82b0 },
{ role: "boarder", color: 0xd36d4b },
{ role: "boarder", color: 0x5f9472 }
];
for (let i = 0; i < specs.length; i++) {
const p = makePerson(specs[i].color);
p.userData.swingPhase = x * 0.1 + i * 2;
p.position.set(x - 1.3 + i * 0.9, 0.39, 6.45);
scene.add(p);
people.push({ ...specs[i], mesh: p });
}
return people;
}
stopCrowds.A = createStopCrowd(stopA);
stopCrowds.B = createStopCrowd(stopB);
function makeBus(color, number, accent) {
const group = new THREE.Group();
group.position.z = BUS_Z;
scene.add(group);
box(group, [4.05, 0.42, 1.78], [0, 0.63, 0], 0x26313d);
box(group, [3.95, 1.52, 1.76], [0, 1.55, 0], color);
box(group, [3.78, 0.18, 1.66], [0, 2.39, 0], accent);
for (const x of [-1.25, 1.25]) {
for (const z of [-0.88, 0.88]) {
box(group, [0.58, 0.58, 0.18], [x, 0.55, z], 0x1c252f);
box(group, [0.20, 0.20, 0.20], [x, 0.55, z * 1.08], 0x9ca8af);
}
}
box(group, [0.08, 0.74, 1.48], [1.99, 1.75, 0], 0x294657);
box(group, [0.08, 0.62, 1.42], [-1.99, 1.76, 0], 0x294657);
for (const z of [-0.89, 0.89]) {
for (const x of [-1.35, -0.50]) {
box(group, [0.67, 0.66, 0.035], [x, 1.78, z], 0x24495b);
}
}
const door = box(group, [0.62, 1.35, 0.055], [0.80, 1.35, 0.91], 0x1c303b);
box(group, [0.06, 1.38, 0.07], [1.14, 1.35, 0.94], 0xe7ece8);
for (const z of [-0.58, 0.58]) {
box(group, [0.06, 0.18, 0.28], [2.03, 1.05, z], 0xffed9a, {
emissive: 0xffd35c,
emissiveIntensity: 0.7
});
box(group, [0.06, 0.18, 0.25], [-2.03, 1.05, z], 0xd9473c, {
emissive: 0x8d1c17,
emissiveIntensity: 0.35
});
}
const routePlate = makeSignPlane(number, 0.85, 0.35, "#ffffff", color === 0xf06b45 ? "#b94d2e" : "#2166c4");
routePlate.position.set(-1.10, 1.15, 0.91);
group.add(routePlate);
const label = makeSprite(number + " · CEDAR", [4.2, 1.0, 1], color === 0xf06b45 ? "#b84b2d" : "#245eb1");
label.position.set(0, 3.20, 0);
group.add(label);
group.userData.door = door;
return group;
}
const leadBus = makeBus(0xf06b45, "01", 0xffb68e);
const followBus = makeBus(0x3276e8, "07", 0x92c3ff);
const catchLabel = makeSprite("QUEUE · GAP 4.8 m", [4.8, 1.0, 1], "#a53f27", "#ffffff");
catchLabel.position.set(0, 4.25, 0);
catchLabel.visible = false;
followBus.add(catchLabel);
const gapMarker = box(scene, [1, 0.045, 0.16], [0, 0.18, BUS_Z], 0xf06b45, {
transparent: true,
opacity: 0.72,
emissive: 0xf06b45,
emissiveIntensity: 0.25
});
gapMarker.visible = false;
function makeCar(color, x, z, direction = -1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [2.7, 0.62, 1.42], [0, 0.72, 0], color);
box(g, [1.35, 0.60, 1.25], [0.08, 1.30, 0], 0x9db3bf);
for (const wx of [-0.88, 0.88]) {
for (const wz of [-0.72, 0.72]) {
box(g, [0.48, 0.48, 0.16], [wx, 0.49, wz], 0x202832);
}
}
g.userData.direction = direction;
g.userData.speed = 2.6;
return g;
}
const cars = [
makeCar(0xd7aa58, -8, -2.75),
makeCar(0x9db1c0, 15, -2.75),
makeCar(0xc97061, 29, -2.75)
];
const FIX = {
leadRunA: 16 / 2.4,
leadDwellA: 22,
leadRunAB: 20 / 3.2,
leadDwellB: 18,
followRunA: 26 / 2.3,
followDwellA: 12,
followRunAB: 20 / 2.6,
followDwellB: 14,
separation: 4.8
};
let simTime = 0;
let running = true;
let speedMultiplier = 1;
const lead = {
x: -24,
phase: "toA",
timer: 0
};
const follow = {
x: -34,
phase: "toA",
timer: 0
};
function resetSimulation() {
simTime = 0;
lead.x = -24;
lead.phase = "toA";
lead.timer = 0;
follow.x = -34;
follow.phase = "toA";
follow.timer = 0;
cars[0].position.x = -8;
cars[1].position.x = 15;
cars[2].position.x = 29;
updateBusVisuals();
}
function updateLeader(dt) {
if (lead.phase === "toA") {
lead.x = Math.min(-8, lead.x + 2.4 * dt);
if (lead.x >= -8) {
lead.x = -8;
lead.phase = "dwellA";
lead.timer = FIX.leadDwellA;
}
} else if (lead.phase === "dwellA") {
lead.timer -= dt;
if (lead.timer <= 0) {
lead.timer = 0;
lead.phase = "toB";
}
} else if (lead.phase === "toB") {
lead.x = Math.min(12, lead.x + 3.2 * dt);
if (lead.x >= 12) {
lead.x = 12;
lead.phase = "dwellB";
lead.timer = FIX.leadDwellB;
}
} else if (lead.phase === "dwellB") {
lead.timer -= dt;
if (lead.timer <= 0) {
lead.timer = 0;
lead.phase = "exit";
}
} else if (lead.phase === "exit") {
lead.x = Math.min(34, lead.x + 3.2 * dt);
if (lead.x >= 34) lead.phase = "done";
}
}
function updateFollower(dt) {
if (follow.phase === "toA") {
follow.x = Math.min(-8, follow.x + 2.3 * dt);
if (lead.x - follow.x < FIX.separation && lead.x > follow.x) {
follow.x = lead.x - FIX.separation;
}
if (follow.x >= -8) {
follow.x = -8;
follow.phase = "dwellA";
follow.timer = FIX.followDwellA;
}
} else if (follow.phase === "dwellA") {
follow.timer -= dt;
if (follow.timer <= 0) {
follow.timer = 0;
follow.phase = "toB";
}
} else if (follow.phase === "toB") {
follow.x = Math.min(12, follow.x + 2.6 * dt);
if (lead.x - follow.x < FIX.separation && lead.x > follow.x) {
follow.x = lead.x - FIX.separation;
}
if (follow.x >= 12) {
follow.x = 12;
follow.phase = "dwellB";
follow.timer = FIX.followDwellB;
}
} else if (follow.phase === "dwellB") {
follow.timer -= dt;
if (follow.timer <= 0) {
follow.timer = 0;
follow.phase = "exit";
}
} else if (follow.phase === "exit") {
follow.x = Math.min(29.2, follow.x + 2.8 * dt);
if (follow.x >= 29.2) follow.phase = "done";
}
}
function isCatchUp() {
const gap = lead.x - follow.x;
const leaderStopped = lead.phase === "dwellA" || lead.phase === "dwellB";
const followerMoving = follow.phase === "toA" || follow.phase === "toB";
return leaderStopped && followerMoving && gap <= FIX.separation + 0.12;
}
function activeDwell(stop) {
const leadPhase = stop === "A" ? "dwellA" : "dwellB";
const followPhase = stop === "A" ? "dwellA" : "dwellB";
if (lead.phase === leadPhase) {
const duration = stop === "A" ? FIX.leadDwellA : FIX.leadDwellB;
return { elapsed: duration - lead.timer, duration };
}
if (follow.phase === followPhase) {
const duration = stop === "A" ? FIX.followDwellA : FIX.followDwellB;
return { elapsed: duration - follow.timer, duration };
}
return null;
}
function updatePeople() {
for (const p of ambientPeople) {
const span = p.lane > 0 ? -35 : 35;
const end = p.lane > 0 ? 35 : -35;
p.mesh.position.x = ((p.offset + simTime * 0.62 * p.lane + 35) % 70 + 70) % 70 - 35;
p.mesh.position.y = 0.39;
animatePerson(p.mesh, true, simTime);
}
const crossT = (simTime % 17) / 17;
crossingPerson.position.z = lerp(7.4, -7.4, crossT);
crossingPerson.position.y = Math.abs(crossingPerson.position.z) > 5 ? 0.39 : 0.17;
crossingPerson.rotation.y = Math.PI / 2;
animatePerson(crossingPerson, true, simTime);
for (const [key, x] of [["A", stopA], ["B", stopB]]) {
const crowd = stopCrowds[key];
const dwell = activeDwell(key);
crowd.forEach((person, i) => {
const queueX = x - 1.5 + i * 1.1;
let targetX = queueX;
let targetZ = 6.45;
let moving = false;
if (dwell) {
if (person.role === "alighter") {
const p = clamp(dwell.elapsed / (dwell.duration * 0.32), 0, 1);
targetX = lerp(x + 0.8, x - 1.7, p);
targetZ = lerp(4.36, 6.45, p);
moving = p > 0 && p < 1;
} else {
const p = clamp((dwell.elapsed / dwell.duration - 0.34) / 0.54, 0, 1);
targetX = lerp(queueX, x + 0.8 + (i - 1) * 0.55, p);
targetZ = lerp(6.45, 4.36, p);
moving = p > 0 && p < 1;
}
}
person.mesh.position.x = targetX;
person.mesh.position.z = targetZ;
person.mesh.position.y = targetZ > 5 ? 0.39 : 0.20;
person.mesh.rotation.y = targetZ < 5 ? Math.PI / 2 : 0;
animatePerson(person.mesh, moving, simTime);
});
}
}
function updateBusVisuals() {
leadBus.position.x = lead.x;
followBus.position.x = follow.x;
const leadDwelling = lead.phase === "dwellA" || lead.phase === "dwellB";
const followDwelling = follow.phase === "dwellA" || follow.phase === "dwellB";
leadBus.userData.door.scale.y = leadDwelling ? 0.08 : 1;
followBus.userData.door.scale.y = followDwelling ? 0.08 : 1;
const gap = Math.max(0, lead.x - follow.x);
gapMarker.visible = gap < 12;
gapMarker.scale.x = Math.max(0.1, gap);
gapMarker.position.x = (lead.x + follow.x) / 2;
gapMarker.material.color.setHex(gap < 6 ? 0xf06b45 : 0x1aa6a6);
gapMarker.material.emissive.setHex(gap < 6 ? 0xf06b45 : 0x1aa6a6);
catchLabel.visible = isCatchUp();
}
function step(dt) {
simTime += dt;
updateLeader(dt);
updateFollower(dt);
for (const car of cars) {
car.position.x += car.userData.direction * car.userData.speed * dt;
if (car.position.x < -36) car.position.x = 36;
if (car.position.x > 36) car.position.x = -36;
}
updatePeople();
updateBusVisuals();
}
function leadStatusText() {
if (lead.phase === "toA") return "Approaching A";
if (lead.phase === "dwellA") return "Boarding A";
if (lead.phase === "toB") return "A → B";
if (lead.phase === "dwellB") return "Boarding B";
if (lead.phase === "exit") return "Leaving";
return "Clear";
}
function followerStatusText() {
if (isCatchUp()) return "Queued behind 01";
if (follow.phase === "toA") return "Approaching A";
if (follow.phase === "dwellA") return "Boarding A";
if (follow.phase === "toB") return "A → B";
if (follow.phase === "dwellB") return "Boarding B";
if (follow.phase === "exit") return "Leaving";
return "Clear";
}
function formatClock(t) {
const m = Math.floor(t / 60).toString().padStart(2, "0");
const s = (t % 60).toFixed(1).padStart(4, "0");
return `${m}:${s}`;
}
let hudTimer = 0;
function updateHUD() {
$("clock").textContent = formatClock(simTime);
$("leadStatus").textContent = leadStatusText();
$("followStatus").textContent = followerStatusText();
const gap = Math.max(0, lead.x - follow.x);
$("gapValue").textContent = gap.toFixed(1) + " m";
const gapRatio = clamp((gap - FIX.separation) / (10 - FIX.separation), 0, 1);
$("gapBar").style.width = (gapRatio * 100).toFixed(1) + "%";
const badge = $("eventBadge");
if (isCatchUp()) {
badge.textContent = "Catch-up event · Bus 07 is queued";
badge.classList.add("hot");
} else if ((lead.phase === "dwellA" || lead.phase === "dwellB") && gap < 8) {
badge.textContent = "Gap closing behind dwell";
badge.classList.add("hot");
} else {
badge.textContent = "Scenario running";
badge.classList.remove("hot");
}
}
function seek(time) {
resetSimulation();
const target = Math.max(0, time);
while (simTime < target) {
step(Math.min(0.01, target - simTime));
}
updateHUD();
}
// Direct camera controls: no examples/addons are imported.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = clamp(cameraState.pitch + dy * 0.005, 0.25, 1.42);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && 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();
cameraState.distance = clamp(cameraState.distance * Math.exp(event.deltaY * 0.001), 25, 82);
updateCamera();
}, { passive: false });
$("play").addEventListener("click", () => {
running = !running;
$("play").textContent = running ? "Pause" : "Play";
});
$("reset").addEventListener("click", () => {
resetSimulation();
updateHUD();
});
$("jump").addEventListener("click", () => {
seek(9.4);
running = true;
$("play").textContent = "Pause";
});
document.querySelectorAll(".speed").forEach(button => {
button.addEventListener("click", () => {
speedMultiplier = Number(button.dataset.speed);
document.querySelectorAll(".speed").forEach(b => {
b.setAttribute("aria-pressed", String(b === button));
});
});
});
$("viewIso").addEventListener("click", () => {
cameraState.yaw = 0.53;
cameraState.pitch = 0.67;
cameraState.distance = 58;
cameraState.target.set(-1.5, 1.2, 0);
updateCamera();
});
$("viewTop").addEventListener("click", () => {
cameraState.yaw = 0;
cameraState.pitch = 1.38;
cameraState.distance = 66;
cameraState.target.set(-1.5, 0, 0);
updateCamera();
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
$("play").click();
} else if (event.key.toLowerCase() === "r") {
resetSimulation();
updateHUD();
} else if (event.key === "ArrowLeft") {
cameraState.yaw -= 0.08;
updateCamera();
} else if (event.key === "ArrowRight") {
cameraState.yaw += 0.08;
updateCamera();
} else if (event.key === "ArrowUp") {
cameraState.pitch = clamp(cameraState.pitch + 0.06, 0.25, 1.42);
updateCamera();
} else if (event.key === "ArrowDown") {
cameraState.pitch = clamp(cameraState.pitch - 0.06, 0.25, 1.42);
updateCamera();
} else if (event.key === "+" || event.key === "=") {
cameraState.distance = clamp(cameraState.distance - 3, 25, 82);
updateCamera();
} else if (event.key === "-") {
cameraState.distance = clamp(cameraState.distance + 3, 25, 82);
updateCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
resetSimulation();
updateHUD();
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const realDt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (running) {
let remaining = realDt * speedMultiplier;
while (remaining > 0) {
const dt = Math.min(remaining, 0.025);
step(dt);
remaining -= dt;
}
}
hudTimer += realDt;
if (hudTimer > 0.08) {
hudTimer = 0;
updateHUD();
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```