Prompt specification
Build or customize the Three.js 3D scene "Dawn market street transformation" 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: Dawn market street transformation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/dawn-market-street-transformation-x0511
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows folding market stalls. Build a short street that changes from empty pavement to several active stalls; delivery carts leave after setup and a continuous central walking lane remains. Voxel style.
Working Three.js Starter (dawn-market-street-transformation-x0511):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Folding Street Market</title>
<style>
:root {
--ink: #20313a;
--paper: rgba(255, 252, 240, 0.94);
--accent: #e75b3f;
--mint: #4f9b83;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bdd5db;
color: var(--ink);
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;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 18px 18px 16px;
border: 1px solid rgba(32, 49, 58, 0.12);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 12px 32px rgba(33, 51, 58, 0.16);
backdrop-filter: blur(10px);
user-select: none;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 4vw, 30px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 9px 0 15px;
color: #64737a;
font-size: 13px;
line-height: 1.45;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
font-size: 12px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: 0.06em;
}
#stall-count {
color: #6b777c;
font-size: 11px;
white-space: nowrap;
}
.progress {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: #e3e5dd;
}
#progress-fill {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent), #e7aa3e);
transform: scaleX(0);
transform-origin: left center;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 14px;
}
button {
min-height: 38px;
padding: 0 14px;
border: 0;
border-radius: 10px;
background: var(--ink);
color: #fffdf5;
font: inherit;
font-size: 13px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #344b55;
}
button.secondary {
background: #e8e9df;
color: var(--ink);
}
button.secondary:hover {
background: #daddd0;
}
.hint {
position: fixed;
z-index: 10;
right: 20px;
bottom: 18px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(255, 252, 240, 0.82);
color: #43565e;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(8px);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 12px;
color: #68777d;
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
@media (max-width: 600px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.subtitle {
display: none;
}
.hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<section class="panel" aria-label="Market animation controls">
<div class="eyebrow">Voxel Street Study</div>
<h1>Folding Market</h1>
<p class="subtitle">
Empty pavement becomes a lively market. Stalls unfold on both sides while
deliveries use the outer service lane.
</p>
<div class="status-row">
<span id="status">Empty pavement</span>
<span id="stall-count">0 / 6 stalls active</span>
</div>
<div class="progress" aria-hidden="true">
<div id="progress-fill"></div>
</div>
<div class="buttons">
<button id="replay" type="button">Replay</button>
<button id="pause" class="secondary" type="button">Pause</button>
</div>
<div class="legend">
<span><i class="swatch" style="background:#e85e42"></i>Market activity</span>
<span><i class="swatch" style="background:#4f9b83"></i>Clear walking lane</span>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · R to replay</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbdd5db);
scene.fog = new THREE.Fog(0xbdd5db, 42, 82);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 150);
const cameraTarget = new THREE.Vector3(0, 1.4, -0.5);
const cameraState = {
azimuth: 0.61,
polar: 1.03,
zoom: 1
};
const hemiLight = new THREE.HemisphereLight(0xe8f7ff, 0x7b684f, 2.2);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.2);
sun.position.set(-16, 26, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
flatShading: true
});
}
const MAT = {
asphalt: material(0x667174),
sidewalk: material(0xc8c3b1),
sidewalkAlt: material(0xb9b6a7),
lane: material(0xa8c6bb),
seam: material(0x738e86),
curb: material(0xe0d8c3),
dark: material(0x28363c),
wood: material(0xa86f42),
woodDark: material(0x70492e),
cream: material(0xfff0cc),
red: material(0xe85e42),
teal: material(0x4f9b83),
blue: material(0x4f7fa6),
yellow: material(0xe7aa3e),
purple: material(0x8c6aa8),
green: material(0x6e9d52),
orange: material(0xef8a3c),
white: material(0xf8f4e8),
black: material(0x24292a),
lamp: material(0xffd98a, {
emissive: 0xffb84d,
emissiveIntensity: 1.5
})
};
function makeBox(width, height, depth, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smooth(value) {
const t = clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function rangeProgress(time, start, duration) {
return smooth((time - start) / duration);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
// -------------------------------------------------------------------------
// Street, continuous pedestrian lane, curbs, and paving details
// -------------------------------------------------------------------------
makeBox(18, 0.5, 46, MAT.asphalt, 0, -0.3, 0);
// The central lane is one uninterrupted strip, never occupied by stalls or carts.
makeBox(4.4, 0.08, 44, MAT.lane, 0, -0.01, 0);
for (const side of [-1, 1]) {
makeBox(6.35, 0.16, 44, MAT.sidewalk, side * 5.62, 0, 0);
makeBox(0.18, 0.24, 44.8, MAT.curb, side * 2.28, 0.055, 0);
makeBox(0.08, 0.025, 43.5, MAT.white, side * 2.12, 0.035, 0);
for (let z = -21; z <= 21; z += 2) {
makeBox(6.25, 0.012, 0.025, MAT.sidewalkAlt, side * 5.62, 0.085, z);
}
}
for (let z = -21.5; z <= 21.5; z += 1.5) {
makeBox(4.25, 0.012, 0.035, MAT.seam, 0, 0.035, z);
}
// Small edge markers emphasize the protected walking corridor.
for (const side of [-1, 1]) {
for (const z of [-18, -6, 6, 18]) {
makeBox(0.18, 0.52, 0.18, MAT.dark, side * 2.52, 0.34, z);
makeBox(0.22, 0.08, 0.22, MAT.yellow, side * 2.52, 0.62, z);
}
}
// -------------------------------------------------------------------------
// Simple voxel city backdrop
// -------------------------------------------------------------------------
const buildingColors = [
material(0xd89272),
material(0x9cb6ad),
material(0xc8a878),
material(0x879eb1),
material(0xb9a3a0)
];
for (const side of [-1, 1]) {
for (let i = 0; i < 4; i++) {
const z = -15 + i * 10;
const height = 5.5 + ((i + (side > 0 ? 1 : 0)) % 3) * 1.45;
const x = side * 10.65;
const building = new THREE.Group();
building.position.set(x, 0, z);
scene.add(building);
makeBox(3.25, height, 8.4, buildingColors[(i + 2) % buildingColors.length],
0, height / 2, 0, building);
makeBox(3.45, 0.35, 8.6, MAT.cream,
0, height + 0.12, 0, building);
// Windows on the street-facing facade.
for (let row = 0; row < 3; row++) {
for (let col = -1; col <= 1; col++) {
makeBox(0.08, 0.8, 0.85, MAT.dark,
-side * 1.67, 1.45 + row * 1.45, col * 2.25, building);
}
}
makeBox(0.12, 1.3, 1.2, MAT.woodDark,
-side * 1.68, 0.65, 0, building);
}
}
// -------------------------------------------------------------------------
// Folding market stalls
// -------------------------------------------------------------------------
const canopyColors = [MAT.red, MAT.cream, MAT.teal, MAT.cream, MAT.red];
const produceColors = [
MAT.orange, MAT.green, MAT.red, MAT.yellow,
MAT.purple, MAT.blue, MAT.green, MAT.red
];
const stalls = [];
function addVendor(parent, color, vendorGroup) {
const torso = makeBox(0.48, 0.62, 0.34, color, 0, 1.04, 0, vendorGroup);
makeBox(0.34, 0.34, 0.32, MAT.cream, 0, 1.52, 0, vendorGroup);
makeBox(0.42, 0.12, 0.36, MAT.woodDark, 0, 1.72, 0, vendorGroup);
makeBox(0.18, 0.52, 0.2, MAT.dark, -0.13, 0.43, 0, vendorGroup);
makeBox(0.18, 0.52, 0.2, MAT.dark, 0.13, 0.43, 0, vendorGroup);
vendorGroup.userData.torso = torso;
}
function addProduce(parent, index) {
const goods = new THREE.Group();
parent.add(goods);
for (let i = 0; i < 3; i++) {
const x = -1.05 + i * 1.05;
makeBox(0.72, 0.24, 0.58, MAT.wood, x, 1.29, 0.22, goods);
makeBox(0.64, 0.05, 0.5, MAT.woodDark, x, 1.43, 0.22, goods);
for (let j = 0; j < 4; j++) {
const color = produceColors[(index * 3 + i + j) % produceColors.length];
makeBox(
0.17,
0.17,
0.17,
color,
x - 0.22 + (j % 2) * 0.28,
1.57,
0.08 + Math.floor(j / 2) * 0.25,
goods
);
}
}
return goods;
}
function createStall(side, z, index) {
const root = new THREE.Group();
root.position.set(side * 5.6, 0.08, z);
root.rotation.y = side < 0 ? Math.PI / 2 : -Math.PI / 2;
root.visible = false;
scene.add(root);
const counter = new THREE.Group();
const frame = new THREE.Group();
const goods = new THREE.Group();
root.add(counter, frame, goods);
makeBox(3.2, 0.95, 1.3, index % 2 ? MAT.wood : MAT.woodDark,
0, 0.5, 0.16, counter);
makeBox(3.48, 0.16, 1.52, MAT.cream,
0, 1.07, 0.16, counter);
// Folding front panels give the counter a hand-built market appearance.
for (let i = 0; i < 4; i++) {
makeBox(0.72, 0.72, 0.06, i % 2 ? MAT.cream : MAT.wood,
-1.2 + i * 0.8, 0.49, 0.83, counter);
}
makeBox(0.13, 3.45, 0.13, MAT.dark,
-1.57, 1.73, -0.66, frame);
makeBox(0.13, 3.15, 0.13, MAT.dark,
1.57, 1.58, -0.66, frame);
makeBox(0.13, 3.15, 0.13, MAT.dark,
-1.57, 1.58, 0.77, frame);
makeBox(0.13, 3.15, 0.13, MAT.dark,
1.57, 1.58, 0.77, frame);
makeBox(3.4, 0.13, 0.13, MAT.dark,
0, 3.39, -0.67, frame);
const awningPivot = new THREE.Group();
awningPivot.position.set(0, 3.39, -0.67);
frame.add(awningPivot);
for (let i = 0; i < 5; i++) {
const stripe = makeBox(
0.68,
0.12,
1.72,
canopyColors[(i + index) % canopyColors.length],
-1.36 + i * 0.68,
0,
0.86,
awningPivot
);
stripe.rotation.x = 0.025;
makeBox(
0.68,
0.28,
0.10,
canopyColors[(i + index) % canopyColors.length],
-1.36 + i * 0.68,
-0.14,
1.72,
awningPivot
);
}
// A simple block sign and two warm bulbs.
makeBox(1.16, 0.42, 0.09, MAT.cream, 0, 2.65, -0.58, frame);
for (let i = -1; i <= 1; i++) {
makeBox(0.15, 0.15, 0.04, MAT.red, i * 0.27, 2.65, -0.515, frame);
}
makeBox(0.16, 0.16, 0.16, MAT.lamp, -1.35, 3.13, 0.65, frame);
makeBox(0.16, 0.16, 0.16, MAT.lamp, 1.35, 3.13, 0.65, frame);
addProduce(goods, index);
const vendor = new THREE.Group();
vendor.position.set(0, 0, -1.08);
root.add(vendor);
addVendor(vendor, [MAT.blue, MAT.teal, MAT.purple][index % 3], vendor);
const stall = {
root,
counter,
frame,
goods,
awningPivot,
vendor,
index,
start: 1.1 + index * 0.42,
active: false
};
stalls.push(stall);
return stall;
}
createStall(-1, 10, 0);
createStall(-1, 0, 1);
createStall(-1, -10, 2);
createStall(1, 10, 3);
createStall(1, 0, 4);
createStall(1, -10, 5);
// -------------------------------------------------------------------------
// Delivery carts in the outer service corridor
// -------------------------------------------------------------------------
const carts = [];
function createCart(index, targetZ) {
const root = new THREE.Group();
root.position.set(7.55, 0.08, 21.5);
root.visible = false;
scene.add(root);
makeBox(1.08, 0.18, 1.45, MAT.dark, 0, 0.48, 0, root);
makeBox(0.92, 0.34, 1.12, MAT.wood, 0, 0.72, 0, root);
for (const x of [-0.58, 0.58]) {
for (const z of [-0.48, 0.48]) {
makeBox(0.16, 0.34, 0.34, MAT.black, x, 0.27, z, root);
makeBox(0.06, 0.14, 0.14, MAT.cream, x * 1.08, 0.27, z, root);
}
}
makeBox(0.12, 1.15, 0.12, MAT.dark, -0.42, 1.03, 0.7, root);
makeBox(0.12, 1.15, 0.12, MAT.dark, 0.42, 1.03, 0.7, root);
makeBox(1.0, 0.12, 0.12, MAT.dark, 0, 1.57, 0.7, root);
const cargo = new THREE.Group();
root.add(cargo);
makeBox(0.72, 0.5, 0.72, MAT.cream, 0, 1.16, -0.12, cargo);
makeBox(0.55, 0.42, 0.55, MAT.yellow, 0, 1.58, -0.12, cargo);
makeBox(0.61, 0.08, 0.61, MAT.red, 0, 1.83, -0.12, cargo);
const parcel = makeBox(0.52, 0.42, 0.52, MAT.teal, 0, 0, 0);
parcel.visible = false;
const receivedCrate = makeBox(
0.58,
0.34,
0.58,
MAT.teal,
5.63,
1.42,
targetZ
);
receivedCrate.visible = false;
const start = 2.15 + index * 0.95;
const entryEnd = start + 2.4;
const exitEnd = entryEnd + 3.85;
carts.push({
root,
cargo,
parcel,
receivedCrate,
targetZ,
start,
entryEnd,
exitEnd,
deliveryStart: entryEnd + 0.08,
deliveryEnd: entryEnd + 0.76
});
}
createCart(0, 10);
createCart(1, 0);
createCart(2, -10);
// -------------------------------------------------------------------------
// Block-style pedestrians using only the central walking lane
// -------------------------------------------------------------------------
const people = [];
function createPerson(index) {
const root = new THREE.Group();
const shirt = [
MAT.red,
MAT.teal,
MAT.yellow,
MAT.blue,
MAT.purple,
MAT.orange
][index % 6];
const torso = makeBox(0.45, 0.62, 0.32, shirt, 0, 1.03, 0, root);
makeBox(0.33, 0.33, 0.31, MAT.cream, 0, 1.5, 0, root);
makeBox(0.39, 0.11, 0.34, MAT.woodDark, 0, 1.69, 0, root);
const leftLeg = makeBox(0.17, 0.57, 0.2, MAT.dark, -0.12, 0.42, 0, root);
const rightLeg = makeBox(0.17, 0.57, 0.2, MAT.dark, 0.12, 0.42, 0, root);
makeBox(0.13, 0.52, 0.16, shirt, -0.31, 1.02, 0, root);
makeBox(0.13, 0.52, 0.16, shirt, 0.31, 1.02, 0, root);
root.visible = false;
scene.add(root);
people.push({
root,
torso,
leftLeg,
rightLeg,
speed: 0.8 + (index % 4) * 0.17,
offset: index * 5.7,
laneOffset: -1.15 + (index % 5) * 0.54,
phase: index * 1.7
});
}
for (let i = 0; i < 8; i++) {
createPerson(i);
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
let simTime = 0;
let playing = true;
let previousTime = performance.now();
const statusElement = document.getElementById("status");
const stallCountElement = document.getElementById("stall-count");
const progressElement = document.getElementById("progress-fill");
const pauseButton = document.getElementById("pause");
const replayButton = document.getElementById("replay");
function updateStalls(time) {
let activeCount = 0;
for (const stall of stalls) {
const setup = rangeProgress(time, stall.start, 1.65);
const unfold = rangeProgress(time, stall.start + 0.42, 1.12);
const stock = rangeProgress(time, stall.start + 0.82, 0.92);
if (time >= stall.start + 1.7) {
activeCount++;
}
stall.root.visible = time >= stall.start;
stall.counter.scale.set(1, Math.max(0.001, setup), 1);
stall.frame.scale.set(1, Math.max(0.001, setup), 1);
stall.awningPivot.rotation.x = -Math.PI / 2 * (1 - unfold);
stall.goods.scale.setScalar(Math.max(0.001, stock));
stall.vendor.scale.setScalar(Math.max(0.001, rangeProgress(time, stall.start + 0.95, 0.7)));
if (stall.vendor.visible) {
stall.vendor.position.y = Math.sin(time * 3 + stall.index) * 0.015;
}
}
stallCountElement.textContent = `${activeCount} / 6 stalls active`;
return activeCount;
}
function updateCarts(time) {
for (const cart of carts) {
if (time < cart.start || time >= cart.exitEnd) {
cart.root.visible = false;
cart.parcel.visible = false;
continue;
}
cart.root.visible = true;
if (time < cart.entryEnd) {
const p = smooth((time - cart.start) / (cart.entryEnd - cart.start));
cart.root.position.z = lerp(21.5, cart.targetZ, p);
cart.root.rotation.y = 0;
cart.cargo.scale.setScalar(1);
} else if (time < cart.entryEnd + 0.9) {
cart.root.position.z = cart.targetZ;
cart.root.rotation.y = 0;
const unload = clamp(
(time - cart.deliveryStart) / (cart.deliveryEnd - cart.deliveryStart),
0,
1
);
cart.cargo.scale.setScalar(Math.max(0.001, 1 - unload));
} else {
const p = smooth((time - cart.entryEnd - 0.9) / (cart.exitEnd - cart.entryEnd - 0.9));
cart.root.position.z = lerp(cart.targetZ, -22.5, p);
cart.root.rotation.y = 0;
cart.cargo.scale.setScalar(0.001);
}
// A crate arcs from the cart to the stall counter.
if (time >= cart.deliveryStart && time <= cart.deliveryEnd + 0.12) {
const p = clamp(
(time - cart.deliveryStart) / (cart.deliveryEnd - cart.deliveryStart),
0,
1
);
const eased = smooth(p);
cart.parcel.visible = true;
cart.parcel.position.set(
lerp(7.55, 5.63, eased),
lerp(1.38, 1.42, eased) + Math.sin(p * Math.PI) * 0.85,
cart.targetZ
);
cart.parcel.rotation.y = p * Math.PI * 2;
if (p >= 0.99) {
cart.receivedCrate.visible = true;
}
} else {
cart.parcel.visible = false;
}
if (time > cart.deliveryEnd + 0.15) {
cart.receivedCrate.visible = true;
const pop = rangeProgress(time, cart.deliveryEnd + 0.05, 0.35);
cart.receivedCrate.scale.setScalar(Math.max(0.001, pop));
}
}
}
function updatePeople(time) {
const reveal = rangeProgress(time, 7.1, 1.2);
for (const person of people) {
person.root.visible = time >= 7.1;
if (!person.root.visible) continue;
const travel = (person.offset + time * person.speed) % 44;
const z = -22 + travel;
const x = person.laneOffset + Math.sin(time * 0.65 + person.phase) * 0.16;
person.root.position.set(x, 0.04, z);
person.root.scale.setScalar(Math.max(0.001, reveal));
person.root.rotation.y = person.speed > 1 ? 0 : Math.PI;
const stride = Math.sin(time * 7 * person.speed + person.phase) * 0.42;
person.leftLeg.rotation.x = stride;
person.rightLeg.rotation.x = -stride;
person.torso.position.y = 1.03 + Math.abs(stride) * 0.035;
}
}
function updateStatus(time) {
let label;
let progress;
if (time < 1.1) {
label = "Empty pavement";
progress = time / 10.5;
} else if (time < 5.35) {
label = "Unfolding stalls";
progress = time / 10.5;
} else if (time < 10.5) {
label = "Deliveries clearing";
progress = time / 10.5;
} else {
label = "Market open";
progress = 1;
}
if (!playing) {
label = "Paused · " + label.toLowerCase();
}
statusElement.textContent = label;
progressElement.style.transform = `scaleX(${clamp(progress, 0, 1)})`;
pauseButton.textContent = playing ? "Pause" : "Resume";
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan-free target, and orthographic zoom
// -------------------------------------------------------------------------
function updateCamera() {
const radius = 43;
const { azimuth, polar, zoom } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(polar) * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
cameraState.azimuth = 0.61;
cameraState.polar = 1.03;
cameraState.zoom = 1;
updateCamera();
}
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 deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= deltaX * 0.006;
cameraState.polar = clamp(cameraState.polar + deltaY * 0.005, 0.62, 1.38);
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.zoom = clamp(cameraState.zoom - event.deltaY * 0.001, 0.72, 1.75);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI and resize
// -------------------------------------------------------------------------
function replay() {
simTime = 0;
playing = true;
for (const cart of carts) {
cart.root.visible = false;
cart.parcel.visible = false;
cart.receivedCrate.visible = false;
cart.receivedCrate.scale.setScalar(0.001);
cart.cargo.scale.setScalar(1);
}
for (const person of people) {
person.root.visible = false;
}
}
replayButton.addEventListener("click", replay);
pauseButton.addEventListener("click", () => {
playing = !playing;
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playing = !playing;
}
if (event.key.toLowerCase() === "r") {
replay();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(28, 26 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
simTime += delta;
}
updateStalls(simTime);
updateCarts(simTime);
updatePeople(simTime);
updateStatus(simTime);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```