Prompt specification
Build or customize the Three.js 3D scene "Passenger Queue Boards One Bus" 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: Passenger Queue Boards One Bus
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/passenger-queue-boards-one-bus-x2086
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a counted passenger queue boarding one low-poly bus. Show a side section of the bus with one open door, a clear boarding step, and several visible seats, beside a short sidewalk queue. Passengers enter one at a time at a declared service rate and disappear from the waiting line only when they have actually crossed the doorway. Display the waiting, onboard, and completed counts separately. Let the queue length change between runs while keeping the boarding rate fixed, so the increased dwell time follows from the additional people rather than a scripted delay.
Working Three.js Starter (passenger-queue-boards-one-bus-x2086):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Bus Boarding Queue</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(15, 23, 42, 0.9);
--border: rgba(255, 255, 255, 0.13);
--muted: #a9b6c7;
--waiting: #fbbf24;
--onboard: #38bdf8;
--completed: #4ade80;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8ed;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
color: #f8fafc;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: 0 16px 42px rgba(15, 23, 42, 0.22);
backdrop-filter: blur(14px);
}
.brand {
position: absolute;
top: 22px;
left: 22px;
width: 330px;
padding: 17px 19px;
}
.eyebrow {
margin-bottom: 5px;
color: #7dd3fc;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 22px;
line-height: 1.15;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.metrics {
position: absolute;
top: 22px;
right: 22px;
display: flex;
gap: 10px;
}
.metric {
min-width: 125px;
padding: 15px 17px 14px;
}
.metric-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-value {
margin-top: 3px;
font-size: 30px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.metric.waiting .metric-value {
color: var(--waiting);
}
.metric.onboard .metric-value {
color: var(--onboard);
}
.metric.completed .metric-value {
color: var(--completed);
}
.controls {
position: absolute;
bottom: 22px;
left: 22px;
width: 365px;
padding: 17px 18px;
}
.control-row {
margin-bottom: 15px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 12px;
font-weight: 700;
}
.control-value {
color: #f8fafc;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
accent-color: #38bdf8;
cursor: pointer;
}
.rate-banner {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 5px 0 15px;
padding: 10px 12px;
border: 1px solid rgba(56, 189, 248, 0.25);
border-radius: 10px;
background: rgba(56, 189, 248, 0.08);
font-size: 11px;
}
.rate-banner strong {
color: #7dd3fc;
white-space: nowrap;
}
.buttons {
display: flex;
gap: 8px;
}
button {
flex: 1;
padding: 10px 12px;
color: #f8fafc;
font: inherit;
font-size: 12px;
font-weight: 800;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 9px;
background: rgba(255, 255, 255, 0.08);
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.14);
}
button.primary {
border-color: rgba(56, 189, 248, 0.5);
background: #0284c7;
}
.help {
margin: 11px 0 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.info {
position: absolute;
right: 22px;
bottom: 22px;
width: 315px;
padding: 16px 17px;
}
.info-title {
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.info-row {
display: flex;
justify-content: space-between;
gap: 14px;
margin: 7px 0;
color: var(--muted);
font-size: 11px;
}
.info-row strong {
color: #f8fafc;
font-variant-numeric: tabular-nums;
text-align: right;
}
.slot-track {
height: 6px;
margin: 12px 0 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
.slot-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #38bdf8, #4ade80);
}
#statusText {
min-height: 16px;
color: #cbd5e1;
font-size: 11px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px;
margin-top: 11px;
color: var(--muted);
font-size: 10px;
}
.legend span::before {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
background: currentColor;
content: "";
}
.legend .amber {
color: var(--waiting);
}
.legend .blue {
color: var(--onboard);
}
.legend .green {
color: var(--completed);
}
@media (max-width: 820px) {
.brand {
top: 12px;
left: 12px;
width: calc(100% - 24px);
padding: 13px 15px;
}
h1 {
font-size: 18px;
}
.subtitle {
display: none;
}
.metrics {
top: 91px;
right: 12px;
left: 12px;
gap: 6px;
}
.metric {
flex: 1;
min-width: 0;
padding: 10px 12px;
}
.metric-value {
font-size: 23px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 14px;
}
.info {
display: none;
}
}
</style>
</head>
<body>
<div id="hud">
<section class="panel brand">
<div class="eyebrow">Transit Simulation 07</div>
<h1>Fixed-rate bus boarding</h1>
<p class="subtitle">
Drag to orbit the cutaway bus and scroll to zoom.
Changing either control begins a new run.
</p>
</section>
<section class="metrics">
<div class="panel metric waiting">
<div class="metric-label">Waiting</div>
<div class="metric-value" id="waitingCount">08</div>
</div>
<div class="panel metric onboard">
<div class="metric-label">Onboard</div>
<div class="metric-value" id="onboardCount">00</div>
</div>
<div class="panel metric completed">
<div class="metric-label">Completed</div>
<div class="metric-value" id="completedCount">00</div>
</div>
</section>
<section class="panel controls">
<div class="control-row">
<label class="control-label" for="queueSize">
<span>Initial queue length</span>
<span class="control-value" id="queueValue">8 passengers</span>
</label>
<input id="queueSize" type="range" min="1" max="18" step="1" value="8">
</div>
<div class="control-row">
<label class="control-label" for="serviceInterval">
<span>Fixed service interval</span>
<span class="control-value" id="intervalValue">1.5 seconds</span>
</label>
<input id="serviceInterval" type="range" min="1" max="3" step="0.1" value="1.5">
</div>
<div class="rate-banner">
<span>Declared service rate</span>
<strong id="rateValue">40 passengers / min</strong>
</div>
<div class="buttons">
<button id="pauseButton" class="primary" type="button">Pause</button>
<button id="resetButton" type="button">New run</button>
</div>
<p class="help">
Waiting decreases only after the passenger crosses the doorway.
A longer queue takes longer because it requires more fixed-rate
service slots, not because an extra delay is inserted.
</p>
</section>
<section class="panel info">
<div class="info-title">Run telemetry</div>
<div class="info-row">
<span>Simulation clock</span>
<strong id="clockValue">0.00 s</strong>
</div>
<div class="info-row">
<span>Next fixed service slot</span>
<strong id="nextSlotValue">1.50 s</strong>
</div>
<div class="info-row">
<span>Projected doorway clearance</span>
<strong id="projectedValue">—</strong>
</div>
<div class="info-row">
<span>Actual doorway clearance</span>
<strong id="actualValue">—</strong>
</div>
<div class="slot-track">
<div class="slot-fill" id="slotFill"></div>
</div>
<div id="statusText">Preparing the queue…</div>
<div class="legend">
<span class="amber">Waiting / crossing</span>
<span class="blue">Onboard</span>
<span class="green">Completed boarding</span>
</div>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, lights, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe8ed);
scene.fog = new THREE.Fog(0xdbe8ed, 32, 68);
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive cutaway view of a bus boarding queue"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(1.8, 1.05, 0.2);
let cameraTheta = 0.34;
let cameraPhi = 1.08;
let cameraRadius = 25;
let cameraZoomed = false;
function updateCamera() {
const horizontalRadius = cameraRadius * Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + horizontalRadius * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xd9f1ff, 0x69705e, 2.0));
const sun = new THREE.DirectionalLight(0xfff3d6, 2.7);
sun.position.set(9, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9d9ff, 0.75);
fill.position.set(-10, 7, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Small geometry helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0.0,
flatShading: true,
...options
});
}
function box(parent, width, height, depth, mat, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, background = "#0f172a", foreground = "#f8fafc") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
const radius = 24;
const x = 8;
const y = 8;
const width = 496;
const height = 112;
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fillStyle = background;
context.fill();
context.fillStyle = foreground;
context.font = "800 46px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.1, 0.78, 1);
sprite.renderOrder = 10;
return sprite;
}
// -------------------------------------------------------------------------
// Ground and sidewalk
// -------------------------------------------------------------------------
const groundMat = material(0xaebc98);
const sidewalkMat = material(0xc9c6bb);
const curbMat = material(0xa7a59b);
const paintMat = material(0xf7f3df);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(44, 28),
groundMat
);
ground.rotation.x = -Math.PI / 2;
ground.position.set(2, -0.08, 1);
ground.receiveShadow = true;
scene.add(ground);
box(scene, 16.5, 0.16, 4.8, sidewalkMat, 9.0, 0.02, 3.4);
box(scene, 16.5, 0.22, 0.18, curbMat, 9.0, 0.0, 1.03);
for (let i = 0; i < 17; i++) {
box(scene, 0.42, 0.018, 0.08, paintMat, 6.4 + i * 0.62, 0.115, 3.12);
}
// -------------------------------------------------------------------------
// Low-poly cutaway bus
// -------------------------------------------------------------------------
const bus = new THREE.Group();
scene.add(bus);
const busYellow = material(0xe9a72d);
const busYellowDark = material(0xc88418);
const busInterior = material(0xd8cba6);
const darkWindow = material(0x244557, {
roughness: 0.35,
metalness: 0.18
});
const tireMat = material(0x20242a);
const hubMat = material(0xb8c0c5, {
metalness: 0.6,
roughness: 0.45
});
const seatMat = material(0x285b76);
const seatBackMat = material(0x1d455d);
const poleMat = material(0xf2b632, {
metalness: 0.35,
roughness: 0.45
});
// Chassis and floor.
box(bus, 12.0, 0.34, 3.65, busYellowDark, -0.15, 0.82, 0);
box(bus, 11.9, 0.18, 3.45, busInterior, -0.15, 1.05, 0);
// Far wall, rear wall, and front section.
box(bus, 11.85, 2.35, 0.14, busYellow, -0.2, 2.23, -1.77);
box(bus, 0.18, 2.55, 3.55, busYellow, -6.10, 2.22, 0);
box(bus, 0.28, 1.05, 3.55, busYellow, 5.78, 1.56, 0);
box(bus, 0.10, 1.25, 3.20, darkWindow, 5.82, 2.73, 0);
// The near side is intentionally cut away for visibility.
box(bus, 9.35, 0.34, 0.16, busYellow, -1.40, 1.18, 1.80);
box(bus, 0.55, 0.34, 0.16, busYellow, 5.42, 1.18, 1.80);
// A partial roof leaves the interior visible.
box(bus, 11.85, 0.17, 1.85, busYellow, -0.15, 3.56, -0.92);
box(bus, 11.85, 0.10, 0.12, busYellow, -0.15, 3.56, 1.76);
// Far-side windows.
for (const x of [-4.8, -2.65, -0.5, 1.65]) {
box(bus, 1.72, 1.00, 0.06, darkWindow, x, 2.62, -1.86);
}
// Rear lights and destination strip.
box(bus, 0.07, 0.28, 0.35, material(0xef4444), -6.21, 1.72, -1.18);
box(bus, 0.07, 0.28, 0.35, material(0xef4444), -6.21, 1.72, 1.18);
box(bus, 2.4, 0.24, 0.06, material(0x111827), -3.8, 3.18, 1.87);
// Wheels.
const wheelGeometry = new THREE.CylinderGeometry(0.58, 0.58, 0.34, 12);
const hubGeometry = new THREE.CylinderGeometry(0.27, 0.27, 0.37, 10);
for (const x of [-4.35, 3.75]) {
for (const z of [-1.84, 1.84]) {
const wheel = new THREE.Mesh(wheelGeometry, tireMat);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.60, z);
wheel.castShadow = true;
bus.add(wheel);
const hub = new THREE.Mesh(hubGeometry, hubMat);
hub.rotation.x = Math.PI / 2;
hub.position.set(x, 0.60, z);
bus.add(hub);
}
}
// Visible seats: six rows with two seats per row.
const seatPositions = [];
for (const x of [-4.85, -3.45, -2.05, -0.65, 0.75, 2.15]) {
for (const z of [-0.88, 0.46]) {
box(bus, 0.76, 0.16, 0.78, seatMat, x, 1.47, z);
box(bus, 0.16, 0.92, 0.78, seatBackMat, x - 0.33, 1.91, z);
box(bus, 0.08, 0.38, 0.08, poleMat, x, 1.25, z - 0.28);
seatPositions.push({
type: "seat",
x,
z,
yaw: Math.PI / 2
});
}
}
// Standing room destinations for the remaining passengers.
const standingPositions = [
{ type: "stand", x: -5.00, z: 1.18, yaw: Math.PI / 2 },
{ type: "stand", x: -3.65, z: 1.18, yaw: Math.PI / 2 },
{ type: "stand", x: -2.30, z: 1.18, yaw: Math.PI / 2 },
{ type: "stand", x: -0.95, z: 1.18, yaw: Math.PI / 2 },
{ type: "stand", x: 0.40, z: 1.18, yaw: Math.PI / 2 },
{ type: "stand", x: 1.75, z: 1.18, yaw: Math.PI / 2 }
];
const destinations = [...seatPositions, ...standingPositions];
// Grab poles.
for (const x of [-3.0, 0.0, 2.65]) {
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 2.35, 8),
poleMat
);
pole.position.set(x, 2.27, -0.12);
pole.castShadow = true;
bus.add(pole);
}
// Driver area.
box(bus, 0.78, 0.18, 0.80, seatBackMat, 4.75, 1.48, -0.65);
box(bus, 0.16, 0.92, 0.80, seatBackMat, 4.42, 1.91, -0.65);
const steeringWheel = new THREE.Mesh(
new THREE.TorusGeometry(0.25, 0.045, 6, 14),
tireMat
);
steeringWheel.position.set(5.25, 2.05, -0.65);
steeringWheel.rotation.y = Math.PI / 2;
bus.add(steeringWheel);
// Open doorway on the near side.
const doorLeftX = 3.45;
const doorRightX = 5.18;
const doorCenterX = (doorLeftX + doorRightX) / 2;
const doorWidth = doorRightX - doorLeftX;
box(bus, 0.11, 2.40, 0.11, poleMat, doorLeftX, 2.30, 1.82);
box(bus, 0.11, 2.40, 0.11, poleMat, doorRightX, 2.30, 1.82);
box(bus, doorWidth, 0.11, 0.11, poleMat, doorCenterX, 3.48, 1.82);
// A folded-back door leaf makes the open doorway explicit.
const foldedDoor = new THREE.Group();
foldedDoor.position.set(doorRightX, 1.10, 1.84);
foldedDoor.rotation.y = 1.08;
bus.add(foldedDoor);
box(foldedDoor, 0.72, 2.18, 0.07, darkWindow, -0.36, 1.09, 0);
box(foldedDoor, 0.05, 2.18, 0.08, poleMat, -0.70, 1.09, 0);
box(foldedDoor, 0.72, 0.05, 0.08, poleMat, -0.36, 2.15, 0);
// Clearly visible boarding steps.
box(bus, 1.26, 0.18, 0.55, busYellowDark, doorCenterX, 0.31, 2.18);
box(bus, 1.10, 0.18, 0.44, busYellow, doorCenterX, 0.65, 2.07);
box(bus, 1.04, 0.08, 0.13, poleMat, doorCenterX, 0.42, 2.43);
box(bus, 1.04, 0.08, 0.13, poleMat, doorCenterX, 0.76, 2.27);
const doorRing = new THREE.Mesh(
new THREE.TorusGeometry(0.24, 0.04, 6, 20),
material(0x4ade80, {
emissive: 0x14532d,
emissiveIntensity: 0.6
})
);
doorRing.rotation.x = Math.PI / 2;
doorRing.position.set(doorCenterX, 1.15, 1.84);
bus.add(doorRing);
const doorBeaconMaterial = material(0x4ade80, {
emissive: 0x16a34a,
emissiveIntensity: 0.8
});
const doorBeacon = new THREE.Mesh(
new THREE.SphereGeometry(0.11, 8, 5),
doorBeaconMaterial
);
doorBeacon.position.set(doorCenterX, 3.36, 1.92);
bus.add(doorBeacon);
const openDoorLabel = makeLabel("OPEN DOOR", "#166534", "#ecfdf5");
openDoorLabel.position.set(doorCenterX, 3.92, 1.92);
openDoorLabel.scale.set(2.4, 0.60, 1);
scene.add(openDoorLabel);
const stepLabel = makeLabel("BOARDING STEP", "#92400e", "#fffbeb");
stepLabel.position.set(doorCenterX, 0.62, 3.0);
stepLabel.scale.set(2.5, 0.63, 1);
scene.add(stepLabel);
const queueLabel = makeLabel("WAITING LINE", "#0f172a", "#f8fafc");
queueLabel.position.set(9.5, 2.55, 4.35);
scene.add(queueLabel);
// -------------------------------------------------------------------------
// Passenger construction
// -------------------------------------------------------------------------
const personGeometry = {
torso: new THREE.CylinderGeometry(0.24, 0.29, 0.56, 6),
head: new THREE.DodecahedronGeometry(0.18, 0),
hair: new THREE.DodecahedronGeometry(0.19, 0),
limb: new THREE.BoxGeometry(0.11, 0.44, 0.11),
arm: new THREE.BoxGeometry(0.10, 0.42, 0.11),
nose: new THREE.BoxGeometry(0.07, 0.07, 0.08)
};
const pantsMat = material(0x26354a);
const shoeMat = material(0x151b24);
const skinMaterials = [
material(0xf1c7a5),
material(0xd79b73),
material(0xa96d4f),
material(0x774b36),
material(0xe2ae83)
];
const shirtPalette = [
0xef4444,
0x3b82f6,
0x8b5cf6,
0x14b8a6,
0xf97316,
0xdb2777,
0x84cc16,
0x0ea5e9
];
function createPassenger(index, destination) {
const group = new THREE.Group();
const shirtMaterial = material(shirtPalette[index % shirtPalette.length]);
const skinMaterial = skinMaterials[index % skinMaterials.length];
const torso = new THREE.Mesh(personGeometry.torso, shirtMaterial);
torso.position.y = 0.83;
group.add(torso);
const head = new THREE.Mesh(personGeometry.head, skinMaterial);
head.position.y = 1.27;
group.add(head);
const hair = new THREE.Mesh(
personGeometry.hair,
material(index % 3 === 0 ? 0x704326 : 0x29231f)
);
hair.position.y = 1.36;
hair.scale.set(1, 0.48, 1);
group.add(hair);
const nose = new THREE.Mesh(personGeometry.nose, skinMaterial);
nose.position.set(0, 1.27, 0.17);
group.add(nose);
function makeLimb(isArm) {
const pivot = new THREE.Group();
const geometry = isArm ? personGeometry.arm : personGeometry.limb;
const mat = isArm ? shirtMaterial : pantsMat;
const limb = new THREE.Mesh(geometry, mat);
limb.position.y = isArm ? -0.20 : -0.22;
pivot.add(limb);
if (!isArm) {
const shoe = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.08, 0.22),
shoeMat
);
shoe.position.set(0, -0.44, 0.035);
pivot.add(shoe);
}
group.add(pivot);
return pivot;
}
const legLeft = makeLimb(false);
const legRight = makeLimb(false);
const armLeft = makeLimb(true);
const armRight = makeLimb(true);
legLeft.position.set(-0.11, 0.55, 0);
legRight.position.set(0.11, 0.55, 0);
armLeft.position.set(-0.29, 1.03, 0);
armRight.position.set(0.29, 1.03, 0);
group.traverse(object => {
if (object.isMesh) {
object.castShadow = true;
object.receiveShadow = true;
}
});
scene.add(group);
return {
index,
group,
legLeft,
legRight,
armLeft,
armRight,
shirtMaterial,
destination,
state: "queued",
phase: index * 1.73,
crossElapsed: 0,
crossDuration: 1,
insideElapsed: 0,
insideDuration: 1,
insidePath: null,
crossed: false
};
}
// -------------------------------------------------------------------------
// Simulation state
// -------------------------------------------------------------------------
const queueInput = document.querySelector("#queueSize");
const intervalInput = document.querySelector("#serviceInterval");
const queueValue = document.querySelector("#queueValue");
const intervalValue = document.querySelector("#intervalValue");
const rateValue = document.querySelector("#rateValue");
const pauseButton = document.querySelector("#pauseButton");
const resetButton = document.querySelector("#resetButton");
const waitingElement = document.querySelector("#waitingCount");
const onboardElement = document.querySelector("#onboardCount");
const completedElement = document.querySelector("#completedCount");
const clockElement = document.querySelector("#clockValue");
const nextSlotElement = document.querySelector("#nextSlotValue");
const projectedElement = document.querySelector("#projectedValue");
const actualElement = document.querySelector("#actualValue");
const slotFill = document.querySelector("#slotFill");
const statusText = document.querySelector("#statusText");
let passengers = [];
let waitingCount = 0;
let onboardCount = 0;
let completedCount = 0;
let initialQueue = 8;
let serviceInterval = 1.5;
let simulationTime = 0;
let nextServiceAt = serviceInterval;
let queueClearedAt = null;
let running = true;
const SIDEWALK_Y = 0.16;
const BUS_FLOOR_Y = 1.05;
const QUEUE_HEAD_X = 6.45;
const QUEUE_SPACING = 0.62;
const DOOR_X = 4.815;
const DOOR_Z = 1.82;
// The doorway threshold is reached at 76% of the crossing path.
const CROSS_THRESHOLD = 0.76;
function readControls() {
initialQueue = Number(queueInput.value);
serviceInterval = Number(intervalInput.value);
queueValue.textContent = `${initialQueue} passenger${initialQueue === 1 ? "" : "s"}`;
intervalValue.textContent = `${serviceInterval.toFixed(1)} second${serviceInterval === 1 ? "" : "s"}`;
rateValue.textContent = `${Math.round(60 / serviceInterval)} passengers / min`;
}
function resetRun() {
readControls();
for (const passenger of passengers) {
scene.remove(passenger.group);
passenger.shirtMaterial.dispose();
}
passengers = [];
waitingCount = initialQueue;
onboardCount = 0;
completedCount = 0;
simulationTime = 0;
nextServiceAt = serviceInterval;
queueClearedAt = null;
running = true;
pauseButton.textContent = "Pause";
for (let i = 0; i < initialQueue; i++) {
const passenger = createPassenger(i, destinations[i]);
passenger.group.position.set(
QUEUE_HEAD_X + i * QUEUE_SPACING,
SIDEWALK_Y,
3.12
);
passenger.group.rotation.y = -Math.PI / 2;
passengers.push(passenger);
}
const crossingOffset = serviceInterval * 0.72 * CROSS_THRESHOLD;
const projected = initialQueue * serviceInterval + crossingOffset;
projectedElement.textContent = `${projected.toFixed(2)} s`;
actualElement.textContent = "—";
updateHUD();
}
function beginCrossing(passenger) {
passenger.state = "crossing";
passenger.crossElapsed = 0;
passenger.crossDuration = serviceInterval * 0.72;
const start = passenger.group.position.clone();
passenger.crossPath = [
{ t: 0.00, point: start },
{ t: 0.18, point: new THREE.Vector3(5.55, SIDEWALK_Y, 2.72) },
{ t: 0.38, point: new THREE.Vector3(DOOR_X, 0.37, 2.34) },
{ t: 0.58, point: new THREE.Vector3(DOOR_X, 0.73, 2.12) },
{
t: CROSS_THRESHOLD,
point: new THREE.Vector3(DOOR_X, BUS_FLOOR_Y, 1.78)
},
{ t: 1.00, point: new THREE.Vector3(DOOR_X, BUS_FLOOR_Y, 1.18) }
];
}
function samplePath(path, t) {
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
if (t <= b.t) {
const localT = (t - a.t) / Math.max(0.00001, b.t - a.t);
return new THREE.Vector3().lerpVectors(a.point, b.point, localT);
}
}
return path[path.length - 1].point.clone();
}
function pathYaw(path, t) {
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
if (t <= b.t) {
const dx = b.point.x - a.point.x;
const dz = b.point.z - a.point.z;
if (Math.abs(dx) + Math.abs(dz) > 0.001) {
return Math.atan2(dx, dz);
}
return pathYaw(path, Math.max(0, t - 0.001));
}
}
return path[path.length - 1].yaw || 0;
}
function startInsideBoarding(passenger) {
passenger.state = "inside";
passenger.insideElapsed = 0;
const start = passenger.group.position.clone();
const destination = passenger.destination;
passenger.insidePath = [
{ t: 0.00, point: start },
{ t: 0.25, point: new THREE.Vector3(3.05, BUS_FLOOR_Y, 1.18) },
{
t: 0.72,
point: new THREE.Vector3(destination.x, BUS_FLOOR_Y, 1.18)
},
{
t: 1.00,
point: new THREE.Vector3(destination.x, BUS_FLOOR_Y, destination.z)
}
];
const distance = start.distanceTo(
new THREE.Vector3(destination.x, BUS_FLOOR_Y, destination.z)
);
passenger.insideDuration = THREE.MathUtils.clamp(
0.75 + distance / 2.8,
1.05,
2.8
);
}
function updateQueuedPassengers(delta) {
let queueIndex = 0;
const smoothing = 1 - Math.exp(-11 * delta);
for (const passenger of passengers) {
if (passenger.state !== "queued") {
continue;
}
const targetX = QUEUE_HEAD_X + queueIndex * QUEUE_SPACING;
passenger.group.position.x = THREE.MathUtils.lerp(
passenger.group.position.x,
targetX,
smoothing
);
passenger.group.position.y = SIDEWALK_Y;
passenger.group.position.z = THREE.MathUtils.lerp(
passenger.group.position.z,
3.12,
smoothing
);
passenger.group.rotation.y = -Math.PI / 2;
queueIndex++;
}
}
function animatePassenger(passenger, moving) {
const swing = moving
? Math.sin(simulationTime * 8.5 + passenger.phase) * 0.52
: 0;
passenger.legLeft.rotation.x = swing;
passenger.legRight.rotation.x = -swing;
passenger.armLeft.rotation.x = -swing * 0.72;
passenger.armRight.rotation.x = swing * 0.72;
}
function updatePassengers(delta) {
for (const passenger of passengers) {
if (passenger.state === "queued") {
animatePassenger(passenger, false);
continue;
}
if (passenger.state === "crossing") {
passenger.crossElapsed += delta;
const t = Math.min(1, passenger.crossElapsed / passenger.crossDuration);
passenger.group.position.copy(
samplePath(passenger.crossPath, t)
);
passenger.group.rotation.y = pathYaw(passenger.crossPath, t);
animatePassenger(passenger, true);
// A passenger leaves the waiting count only after crossing the
// doorway plane, not when the service slot starts.
if (t >= CROSS_THRESHOLD && !passenger.crossed) {
passenger.crossed = true;
waitingCount--;
onboardCount++;
startInsideBoarding(passenger);
if (waitingCount === 0 && queueClearedAt === null) {
queueClearedAt = simulationTime;
}
}
continue;
}
if (passenger.state === "inside") {
passenger.insideElapsed += delta;
const t = Math.min(
1,
passenger.insideElapsed / passenger.insideDuration
);
passenger.group.position.copy(
samplePath(passenger.insidePath, t)
);
passenger.group.rotation.y = pathYaw(passenger.insidePath, t);
animatePassenger(passenger, true);
if (t >= 1) {
const destination = passenger.destination;
passenger.group.position.set(
destination.x,
BUS_FLOOR_Y,
destination.z
);
passenger.group.rotation.y = destination.yaw;
if (destination.type === "seat") {
passenger.group.scale.set(1, 0.68, 1);
passenger.legLeft.rotation.x = -0.95;
passenger.legRight.rotation.x = -0.95;
passenger.state = "seated";
} else {
passenger.state = "standing";
}
passenger.armLeft.rotation.x = 0;
passenger.armRight.rotation.x = 0;
completedCount++;
}
}
}
}
function updateHUD() {
waitingElement.textContent = String(waitingCount).padStart(2, "0");
onboardElement.textContent = String(onboardCount).padStart(2, "0");
completedElement.textContent = String(completedCount).padStart(2, "0");
clockElement.textContent = `${simulationTime.toFixed(2)} s`;
const untilNext = Math.max(0, nextServiceAt - simulationTime);
nextSlotElement.textContent = `${untilNext.toFixed(2)} s`;
const slotProgress = (simulationTime % serviceInterval) / serviceInterval;
slotFill.style.width = `${slotProgress * 100}%`;
if (queueClearedAt !== null) {
actualElement.textContent = `${queueClearedAt.toFixed(2)} s`;
}
if (!running) {
statusText.textContent = "Paused. Resume to continue the fixed service schedule.";
} else if (waitingCount === 0 && completedCount === initialQueue) {
statusText.textContent = `All ${initialQueue} passengers have completed boarding.`;
} else if (waitingCount === 0) {
statusText.textContent =
"Doorway is clear. Passengers are finishing their walk to seats.";
} else {
statusText.textContent =
`Fixed slot in ${untilNext.toFixed(2)} s. ` +
`${waitingCount} still waiting, including any passenger on the step.`;
}
}
// -------------------------------------------------------------------------
// Direct camera controls, implemented without Three.js addons
// -------------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) {
return;
}
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraTheta = THREE.MathUtils.clamp(
cameraTheta - dx * 0.005,
-0.55,
0.85
);
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.004,
0.50,
1.42
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
17,
38
);
cameraZoomed = true;
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraTheta = 0.34;
cameraPhi = 1.08;
cameraRadius = 25;
cameraZoomed = false;
updateCamera();
});
// -------------------------------------------------------------------------
// UI and animation loop
// -------------------------------------------------------------------------
queueInput.addEventListener("input", resetRun);
intervalInput.addEventListener("input", resetRun);
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause" : "Resume";
updateHUD();
});
resetButton.addEventListener("click", resetRun);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (!cameraZoomed) {
cameraRadius = camera.aspect < 1 ? 35 : 25;
updateCamera();
}
});
if (window.innerWidth / window.innerHeight < 1) {
cameraRadius = 35;
updateCamera();
}
resetRun();
let previousFrame = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousFrame) / 1000, 0.05);
previousFrame = now;
if (running) {
simulationTime += delta;
// Fixed-rate service starts. Queue length never changes this interval.
while (simulationTime + 0.000001 >= nextServiceAt) {
const nextPassenger = passengers.find(
passenger => passenger.state === "queued"
);
if (nextPassenger) {
beginCrossing(nextPassenger);
}
nextServiceAt += serviceInterval;
}
updateQueuedPassengers(delta);
updatePassengers(delta);
}
const doorwayBusy = passengers.some(
passenger => passenger.state === "crossing"
);
doorBeaconMaterial.emissiveIntensity = doorwayBusy
? 1.6 + Math.sin(simulationTime * 13) * 0.45
: 0.55;
doorRing.material.emissiveIntensity = doorwayBusy ? 1.0 : 0.45;
updateHUD();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```