Prompt specification
Build or customize the Three.js 3D scene "Neighborhood commute disruption" 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: Neighborhood commute disruption
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-commute-disruption-x3855
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Build two nearby bus stops, connecting sidewalk, café, and crossing; a delayed traveler follows an alternate route while the original waiting group remains at the first stop.
Working Three.js Starter (neighborhood-commute-disruption-x3855):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Long Way Around — Stylized Transit Scene</title>
<style>
:root {
--ink: #18333c;
--muted: #5d7378;
--panel: rgba(250, 252, 247, 0.9);
--line: rgba(24, 51, 60, 0.13);
--amber: #f5a524;
--cyan: #18a6a6;
--shadow: 0 18px 45px rgba(34, 58, 61, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e4;
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;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid var(--line);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 5px rgba(24, 166, 166, 0.12);
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.brand p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: absolute;
top: 24px;
right: 24px;
display: grid;
gap: 9px;
width: 220px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
font-size: 12px;
font-weight: 700;
}
.legend-line {
width: 29px;
height: 4px;
flex: 0 0 auto;
border-radius: 99px;
}
.legend-line.amber {
background: var(--amber);
box-shadow: 0 0 0 4px rgba(245, 165, 36, 0.12);
}
.legend-line.cyan {
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(24, 166, 166, 0.1);
}
.legend small {
margin-left: auto;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.status {
position: absolute;
left: 24px;
bottom: 24px;
width: min(370px, calc(100vw - 48px));
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.status-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.status-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
font-weight: 800;
}
.status-title::before {
content: "";
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 5px rgba(245, 165, 36, 0.13);
}
.eta {
padding: 5px 8px;
border-radius: 8px;
background: rgba(245, 165, 36, 0.14);
color: #9b5e00;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
.status-detail {
margin: 10px 0 12px;
color: var(--muted);
font-size: 12px;
line-height: 1.4;
}
.progress {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: rgba(24, 51, 60, 0.09);
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #f5a524, #ffc964);
transition: width 80ms linear;
}
.status-foot {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: min(430px, calc(100vw - 48px));
pointer-events: auto;
}
button {
min-height: 42px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(250, 252, 247, 0.92);
color: var(--ink);
box-shadow: 0 8px 24px rgba(34, 58, 61, 0.11);
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fffef9;
}
button:focus-visible {
outline: 3px solid rgba(24, 166, 166, 0.35);
outline-offset: 2px;
}
button.primary {
border-color: transparent;
background: var(--ink);
color: #fffef9;
}
button.primary[aria-pressed="true"] {
background: var(--cyan);
}
.hint {
position: absolute;
right: 24px;
bottom: 77px;
padding: 7px 10px;
border-radius: 9px;
background: rgba(250, 252, 247, 0.72);
color: rgba(24, 51, 60, 0.62);
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(8px);
}
.loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #dce9e4;
color: var(--ink);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease, visibility 350ms ease;
}
.loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.brand p {
display: none;
}
.legend {
top: 132px;
right: 12px;
width: 182px;
padding: 11px;
}
.status {
left: 12px;
bottom: 66px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.status-detail {
margin: 7px 0 9px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
}
button {
min-height: 40px;
padding: 0 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading" class="loading">Building the neighborhood…</div>
<div class="hud">
<section class="brand" aria-label="Scene description">
<div class="eyebrow"><span class="live-dot"></span> Live transit scenario</div>
<h1>The Long Way Around</h1>
<p>
A delayed traveler follows the amber detour past the café and crossing,
while the original waiting group stays at Stop 01.
</p>
</section>
<aside class="legend" aria-label="Route legend">
<div class="legend-row">
<span class="legend-line amber"></span>
Alternate route
<small>TRAVELER</small>
</div>
<div class="legend-row">
<span class="legend-line cyan"></span>
Bus corridor
<small>STOP 01–02</small>
</div>
</aside>
<section class="status" aria-live="polite">
<div class="status-head">
<div class="status-title">Alternate route active</div>
<div class="eta">BUS +6 MIN</div>
</div>
<div id="route-detail" class="status-detail">Leaving Stop 01 by the garden path.</div>
<div class="progress"><div id="route-progress"></div></div>
<div class="status-foot">
<span>4 people still waiting at Stop 01</span>
<span id="traveler-percent">0%</span>
</div>
</section>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<nav class="controls" aria-label="Scene controls">
<button id="follow" class="primary" type="button" aria-pressed="false">Follow traveler</button>
<button id="pause" type="button">Pause walk</button>
<button id="reset" type="button">Reset view</button>
</nav>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e4);
scene.fog = new THREE.Fog(0xdce9e4, 43, 78);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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;
renderer.domElement.setAttribute(
"aria-label",
"A stylized three-dimensional neighborhood with two bus stops, a café, a crossing, and a traveler on an alternate route."
);
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf5fff8, 0x879a83, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0ce, 3.3);
sun.position.set(13, 22, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 26;
sun.shadow.camera.bottom = -26;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
scene.add(sun);
const materialCache = new Map();
function material(color, roughness = 0.86) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({ color, roughness, metalness: 0 })
);
}
return materialCache.get(color);
}
function box(w, h, d, color, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
typeof color === "object" ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, color, x, y, z, radialSegments = 12, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, radialSegments),
typeof color === "object" ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(r, color, x, y, z, parent = scene, detail = 14) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(r, detail, Math.max(8, detail - 4)),
typeof color === "object" ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(text, color = "#18333c", width = 4.8, background = "rgba(250,252,247,0.94)") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
roundedRect(ctx, 12, 12, 744, 136, 30);
ctx.fill();
ctx.strokeStyle = "rgba(24,51,60,0.12)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "800 38px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
let fontSize = 38;
while (ctx.measureText(text).width > 700 && fontSize > 22) {
fontSize -= 2;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
}
ctx.fillText(text, 384, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * (160 / 768), 1);
sprite.renderOrder = 20;
return sprite;
}
// ---------------------------------------------------------------------
// Ground, street, sidewalks, and crossing
// ---------------------------------------------------------------------
box(58, 0.25, 42, 0xcbd9bd, 0, -0.18, 1);
box(42, 0.12, 7.2, 0x465761, 0, 0, 0);
box(42, 0.18, 3.3, 0xe7e2d5, 0, 0.05, 5.0);
box(42, 0.18, 3.3, 0xe7e2d5, 0, 0.05, -5.0);
box(42, 0.19, 0.22, 0xf4eee2, 0, 0.11, 3.34);
box(42, 0.19, 0.22, 0xf4eee2, 0, 0.11, -3.34);
for (let x = -19; x <= 19; x += 3) {
if (Math.abs(x - 1.4) < 3.3) continue;
box(1.25, 0.035, 0.09, 0xf3c85e, x, 0.075, 0);
}
box(42, 0.025, 0.07, 0xf4eee2, 0, 0.074, 2.65);
box(42, 0.025, 0.07, 0xf4eee2, 0, 0.074, -2.65);
// Zebra crossing and small crossing signs.
for (let z = -2.75; z <= 2.8; z += 0.72) {
box(3.45, 0.035, 0.39, 0xfaf7ed, 1.4, 0.092, z);
}
for (const x of [-0.45, 3.25]) {
cylinder(0.045, 0.045, 2.35, 0x41565b, x, 1.18, 3.48, 8);
box(0.56, 0.38, 0.08, 0xf5a524, x, 2.25, 3.48);
}
// Sidewalk scoring.
for (let x = -20; x <= 20; x += 1.35) {
box(0.025, 0.015, 3.0, 0xc8c4b8, x, 0.148, 5.0);
box(0.025, 0.015, 3.0, 0xc8c4b8, x, 0.148, -5.0);
}
// ---------------------------------------------------------------------
// Route geometry
// ---------------------------------------------------------------------
const routeY = 0.205;
const alternatePoints = [
new THREE.Vector3(-7.8, routeY, 5.35),
new THREE.Vector3(-8.0, routeY, 7.5),
new THREE.Vector3(4.5, routeY, 7.5),
new THREE.Vector3(4.5, routeY, 6.5),
new THREE.Vector3(1.4, routeY, 6.5),
new THREE.Vector3(1.4, routeY, -5.2),
new THREE.Vector3(8.7, routeY, -5.2),
new THREE.Vector3(8.7, routeY, 5.25)
];
const segmentLengths = [];
const cumulative = [0];
let routeLength = 0;
for (let i = 0; i < alternatePoints.length - 1; i++) {
const length = alternatePoints[i].distanceTo(alternatePoints[i + 1]);
segmentLengths.push(length);
routeLength += length;
cumulative.push(routeLength);
}
function polyline(points, color, radius) {
const group = new THREE.Group();
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
new THREE.MeshBasicMaterial({ color })
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
group.add(mesh);
}
scene.add(group);
return group;
}
polyline(alternatePoints, 0xf5a524, 0.065);
polyline(
[
new THREE.Vector3(-13, routeY, 5.25),
new THREE.Vector3(13, routeY, 5.25)
],
0x18a6a6,
0.035
);
// Small arrows showing the original bus-side connection.
const arrowGeometry = new THREE.ConeGeometry(0.12, 0.43, 3);
for (const x of [-5.2, -0.9, 5.2, 11.0]) {
const arrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshBasicMaterial({ color: 0x18a6a6 })
);
arrow.position.set(x, 0.25, 5.25);
arrow.rotation.z = -Math.PI / 2;
scene.add(arrow);
}
const routeDots = [];
for (let i = 0; i < 3; i++) {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 12, 8),
new THREE.MeshBasicMaterial({ color: 0xffbd4a })
);
scene.add(dot);
routeDots.push(dot);
}
// ---------------------------------------------------------------------
// Bus stops
// ---------------------------------------------------------------------
function makeShelter(x, accent) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
for (const px of [-1.9, 1.9]) {
cylinder(0.07, 0.07, 2.65, 0x40555a, px, 1.33, 4.75, 8, group);
}
box(4.4, 0.22, 1.85, accent, 0, 2.7, 4.72, group);
box(4.15, 1.75, 0.09, 0xb9d8d4, 0, 1.48, 4.18, group);
box(3.55, 0.16, 0.58, 0x8a6b50, 0, 0.59, 4.4, group);
box(3.55, 0.55, 0.11, 0x8a6b50, 0, 0.94, 4.16, group);
for (const px of [-1.45, 1.45]) {
box(0.09, 0.55, 0.48, 0x40555a, px, 0.29, 4.4, group);
}
cylinder(0.055, 0.055, 3.0, 0x40555a, 2.75, 1.5, 3.55, 8, group);
box(0.66, 0.66, 0.09, 0x18a6a6, 2.75, 2.82, 3.55, group);
box(0.34, 0.08, 0.11, 0xf8f4e8, 2.75, 2.88, 3.48, group);
const stopLabel = makeLabel(
x < 0 ? "STOP 01 · CEDAR AVE" : "STOP 02 · MARKET SQ",
"#18333c",
4.7
);
stopLabel.position.set(x, 3.55, 3.5);
scene.add(stopLabel);
}
makeShelter(-9.8, 0x18a6a6);
makeShelter(8.35, 0xf5a524);
// ---------------------------------------------------------------------
// People
// ---------------------------------------------------------------------
function makePerson({
coat,
skin = 0xd9a57c,
hair = 0x3c302d,
scale = 1,
luggage = false
}) {
const group = new THREE.Group();
group.scale.setScalar(scale);
const legGeometry = new THREE.CylinderGeometry(0.105, 0.095, 0.58, 9);
const legL = new THREE.Group();
const legR = new THREE.Group();
legL.position.set(-0.14, 0.7, 0);
legR.position.set(0.14, 0.7, 0);
group.add(legL, legR);
for (const leg of [legL, legR]) {
const limb = new THREE.Mesh(legGeometry, material(0x33474c));
limb.position.y = -0.27;
limb.castShadow = true;
leg.add(limb);
box(0.2, 0.13, 0.32, 0x24383d, 0, -0.58, 0.07, leg);
}
cylinder(0.27, 0.33, 0.72, coat, 0, 1.05, 0, 10, group);
cylinder(0.085, 0.085, 0.18, skin, 0, 1.47, 0, 9, group);
sphere(0.235, skin, 0, 1.66, 0, group);
const hairMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.244, 14, 10, 0, Math.PI * 2, 0, Math.PI * 0.56),
material(hair)
);
hairMesh.position.set(0, 1.69, -0.005);
hairMesh.castShadow = true;
group.add(hairMesh);
sphere(0.027, 0x26383c, -0.075, 1.68, 0.215, group, 8);
sphere(0.027, 0x26383c, 0.075, 1.68, 0.215, group, 8);
const armGeometry = new THREE.CylinderGeometry(0.075, 0.065, 0.56, 9);
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-0.32, 1.34, 0);
armR.position.set(0.32, 1.34, 0);
group.add(armL, armR);
for (const arm of [armL, armR]) {
const limb = new THREE.Mesh(armGeometry, material(coat));
limb.position.y = -0.25;
limb.castShadow = true;
arm.add(limb);
sphere(0.075, skin, 0, -0.56, 0, arm, 9);
}
if (luggage) {
box(0.36, 0.55, 0.25, 0x516c75, 0.44, 0.36, -0.55, group);
box(0.3, 0.045, 0.045, 0xd8e0dc, 0.44, 0.71, -0.55, group);
box(0.045, 0.34, 0.045, 0xd8e0dc, 0.44, 0.84, -0.55, group);
box(0.04, 0.09, 0.04, 0x26383c, 0.34, 0.1, -0.55, group);
box(0.04, 0.09, 0.04, 0x26383c, 0.54, 0.1, -0.55, group);
}
scene.add(group);
return { group, legL, legR, armL, armR };
}
// The original waiting group remains in place at Stop 01.
const waitingPeople = [
makePerson({ coat: 0x5b78a8, skin: 0xe1b18a, hair: 0x342b29 }),
makePerson({ coat: 0xd17b65, skin: 0x8f5d43, hair: 0x201d1c, scale: 0.96 }),
makePerson({ coat: 0x829c72, skin: 0xd7a27c, hair: 0x594337, scale: 1.02 }),
makePerson({ coat: 0x8f6d9d, skin: 0xf0c5a2, hair: 0x8c5c3c, scale: 0.93 })
];
const waitingPositions = [
[-11.0, 4.66],
[-10.15, 4.72],
[-9.25, 4.63],
[-8.5, 4.72]
];
waitingPeople.forEach((person, index) => {
person.group.position.set(waitingPositions[index][0], 0.15, waitingPositions[index][1]);
person.group.rotation.y = [0.15, -0.2, 0.35, -0.15][index];
person.armL.rotation.z = 0.08;
person.armR.rotation.z = -0.08;
});
const waitingLabel = makeLabel("4 WAITING · STOP 01", "#355f67", 4.2);
waitingLabel.position.set(-9.8, 3.03, 4.35);
scene.add(waitingLabel);
const traveler = makePerson({
coat: 0xf5a524,
skin: 0xc88862,
hair: 0x392923,
scale: 1.02,
luggage: true
});
const travelerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.47, 0.035, 7, 32),
new THREE.MeshBasicMaterial({
color: 0xf5a524,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
travelerRing.rotation.x = Math.PI / 2;
travelerRing.position.y = 0.035;
traveler.group.add(travelerRing);
const travelerLabel = makeLabel("DELAYED · ALTERNATE ROUTE", "#9b5e00", 5.3);
scene.add(travelerLabel);
// ---------------------------------------------------------------------
// Café and street life
// ---------------------------------------------------------------------
// Main café building.
box(6.8, 4.0, 4.2, 0xe47e62, 8.0, 2.0, 10.65);
box(7.25, 0.28, 4.65, 0x35545a, 8.0, 4.13, 10.65);
box(6.45, 0.25, 3.85, 0xd4aa83, 8.0, 0.13, 10.65);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x315d69,
roughness: 0.3,
metalness: 0.08
});
box(1.75, 1.55, 0.08, windowMaterial, 6.35, 1.7, 8.51);
box(1.75, 1.55, 0.08, windowMaterial, 9.65, 1.7, 8.51);
box(0.78, 2.15, 0.09, 0x416b70, 8.0, 1.25, 8.49);
box(0.06, 0.36, 0.12, 0xf1d07b, 8.29, 1.25, 8.4);
for (let i = 0; i < 10; i++) {
const stripe = box(
0.61,
0.13,
1.35,
i % 2 === 0 ? 0xf6e7cf : 0xe7795e,
5.25 + i * 0.61,
3.0,
7.92
);
stripe.rotation.x = -0.13;
}
const cafeLabel = makeLabel("CORNER CAFÉ", "#7f3f31", 4.25, "rgba(255,242,219,0.96)");
cafeLabel.position.set(8.0, 4.85, 8.25);
scene.add(cafeLabel);
// Café terrace.
cylinder(0.08, 0.12, 0.75, 0x506268, 3.25, 0.49, 6.9, 10);
cylinder(0.72, 0.72, 0.12, 0xe1b873, 3.25, 0.94, 6.9, 18);
cylinder(0.12, 0.16, 0.32, 0xbd6c55, 3.0, 1.12, 6.9, 12);
for (const dx of [-0.95, 0.95]) {
box(0.55, 0.12, 0.55, 0x5f7d74, 3.25 + dx, 0.46, 6.9);
box(0.55, 0.62, 0.09, 0x5f7d74, 3.25 + dx, 0.78, 7.12);
for (const legX of [-0.18, 0.18]) {
box(0.06, 0.44, 0.06, 0x41575b, 3.25 + dx + legX, 0.23, 6.9);
}
}
// Background homes.
function backgroundHouse(x, z, w, h, d, color) {
box(w, h, d, color, x, h / 2, z);
box(w + 0.25, 0.25, d + 0.25, 0x4c6468, x, h + 0.08, z);
for (const wx of [-w * 0.25, w * 0.25]) {
box(w * 0.2, h * 0.22, 0.06, 0x50777d, x + wx, h * 0.58, z - d / 2 - 0.04);
}
box(w * 0.16, h * 0.32, 0.07, 0x755c4d, x, h * 0.22, z - d / 2 - 0.05);
}
backgroundHouse(-13.2, 13.2, 5.1, 4.3, 3.8, 0xc5b179);
backgroundHouse(-5.9, 13.7, 4.7, 5.0, 3.8, 0x8eaaa1);
backgroundHouse(14.0, 13.1, 4.6, 4.6, 3.7, 0xc98873);
// Trees and planters.
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.15, 0.22, 2.25, 0x7e624d, 0, 1.12, 0, 9, group);
const crownMaterial = material(0x729a75);
const crown1 = new THREE.Mesh(new THREE.IcosahedronGeometry(1.35, 1), crownMaterial);
crown1.position.set(0, 2.85, 0);
crown1.castShadow = true;
group.add(crown1);
const crown2 = new THREE.Mesh(new THREE.IcosahedronGeometry(0.98, 1), crownMaterial);
crown2.position.set(0.55, 3.35, -0.12);
crown2.castShadow = true;
group.add(crown2);
}
makeTree(-14.2, 5.5, 1.0);
makeTree(-12.7, 9.0, 0.78);
makeTree(-4.6, 8.7, 0.9);
makeTree(13.0, 6.4, 0.88);
makeTree(-16.0, -7.8, 0.9);
makeTree(12.0, -8.0, 0.82);
for (const [x, z] of [[-13.7, 4.1], [11.6, 4.5], [-3.6, -4.0]]) {
box(0.95, 0.4, 0.95, 0xb77758, x, 0.25, z);
cylinder(0.07, 0.09, 1.45, 0x765b45, x, 0.95, z, 8);
sphere(0.62, 0x6f956e, x, 1.9, z);
}
// Street lamps.
for (const x of [-14.8, -5.3, 12.8]) {
cylinder(0.055, 0.07, 3.6, 0x40565a, x, 1.8, 3.65, 8);
box(0.62, 0.12, 0.12, 0x40565a, x + 0.22, 3.58, 3.65);
box(0.36, 0.1, 0.28, 0xffedb5, x + 0.4, 3.49, 3.65);
}
// ---------------------------------------------------------------------
// Delayed bus at Stop 02
// ---------------------------------------------------------------------
const bus = new THREE.Group();
bus.position.set(8.0, 0, 1.35);
scene.add(bus);
box(5.8, 1.75, 2.25, 0x49aaa4, 0, 1.28, 0, bus);
box(5.95, 0.18, 2.34, 0xe9e2cf, 0, 2.23, 0, bus);
box(5.65, 0.22, 2.14, 0x2e7775, 0, 0.47, 0, bus);
const busWindow = new THREE.MeshStandardMaterial({
color: 0x244b59,
roughness: 0.25,
metalness: 0.15
});
for (const x of [-1.9, -0.65, 0.65, 1.9]) {
box(0.92, 0.73, 0.06, busWindow, x, 1.63, 1.15, bus);
}
box(0.08, 0.75, 1.6, busWindow, -2.93, 1.6, 0, bus);
for (const x of [-1.85, 1.85]) {
for (const z of [-1.13, 1.13]) {
const wheel = cylinder(0.48, 0.48, 0.25, 0x27373c, x, 0.48, z, 16, bus);
wheel.rotation.x = Math.PI / 2;
const hub = cylinder(0.2, 0.2, 0.27, 0xa9b4b0, x, 0.48, z, 14, bus);
hub.rotation.x = Math.PI / 2;
}
}
for (const z of [-0.75, 0.75]) {
box(0.06, 0.22, 0.34, 0xffe5a0, -2.94, 0.88, z, bus);
}
const busLabel = makeLabel("ROUTE 8 · +6 MIN", "#175b5b", 4.0);
busLabel.position.set(8.0, 2.85, 1.35);
scene.add(busLabel);
// ---------------------------------------------------------------------
// Animation and route sampling
// ---------------------------------------------------------------------
const segmentNames = [
"Leaving Stop 01 by the garden path.",
"Following the café terrace toward the crossing.",
"Skirting the café entrance and turning downhill.",
"Joining the marked pedestrian crossing.",
"Crossing Market Street on the zebra stripes.",
"Taking the lower sidewalk around the block.",
"Turning north toward Stop 02."
];
function sampleRoute(distance) {
const d = THREE.MathUtils.clamp(distance, 0, routeLength);
let segment = segmentLengths.length - 1;
for (let i = 0; i < segmentLengths.length; i++) {
if (d <= cumulative[i + 1]) {
segment = i;
break;
}
}
const local = d - cumulative[segment];
const t = segmentLengths[segment] === 0 ? 0 : local / segmentLengths[segment];
const point = new THREE.Vector3().lerpVectors(
alternatePoints[segment],
alternatePoints[segment + 1],
t
);
const tangent = new THREE.Vector3()
.subVectors(alternatePoints[segment + 1], alternatePoints[segment])
.normalize();
return { point, tangent, segment };
}
let routeCursor = 0;
let routeDirection = 1;
let paused = false;
let following = false;
let walkPhase = 0;
const clock = new THREE.Clock();
function shortestAngle(from, to) {
return Math.atan2(Math.sin(to - from), Math.cos(to - from));
}
function updateTraveler(delta, elapsed) {
if (!paused) {
routeCursor += routeDirection * delta * 1.32;
if (routeCursor >= routeLength) {
routeCursor = routeLength;
routeDirection = -1;
} else if (routeCursor <= 0) {
routeCursor = 0;
routeDirection = 1;
}
walkPhase += delta * 8.8;
}
const sample = sampleRoute(routeCursor);
const actualTangent = sample.tangent.clone().multiplyScalar(routeDirection);
traveler.group.position.copy(sample.point);
traveler.group.position.y += Math.abs(Math.sin(walkPhase)) * 0.026;
const desiredAngle = Math.atan2(actualTangent.x, actualTangent.z);
traveler.group.rotation.y += shortestAngle(
traveler.group.rotation.y,
desiredAngle
) * Math.min(1, delta * 10);
const stride = Math.sin(walkPhase) * 0.47;
traveler.legL.rotation.x = stride;
traveler.legR.rotation.x = -stride;
traveler.armL.rotation.x = -stride * 0.72;
traveler.armR.rotation.x = stride * 0.72;
traveler.armR.rotation.z = -0.08;
const pulse = 1 + Math.sin(elapsed * 4.2) * 0.13;
travelerRing.scale.setScalar(pulse);
travelerRing.material.opacity = 0.5 + Math.sin(elapsed * 4.2) * 0.15;
travelerLabel.position.copy(traveler.group.position);
travelerLabel.position.y += 2.25;
for (let i = 0; i < routeDots.length; i++) {
const d = (elapsed * 0.038 + i / routeDots.length) % 1;
const dotSample = sampleRoute(d * routeLength);
routeDots[i].position.copy(dotSample.point);
routeDots[i].position.y += 0.04;
}
const percent = Math.round((routeCursor / routeLength) * 100);
$("#route-progress").style.width = `${percent}%`;
$("#traveler-percent").textContent = `${percent}%`;
$("#route-detail").textContent = segmentNames[sample.segment];
}
// ---------------------------------------------------------------------
// Custom orbit, pan, zoom, pinch, and follow controls
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.65, 3.1),
radius: 31,
theta: 0.61,
phi: 0.79
};
function applyCamera() {
const spherical = new THREE.Spherical(controls.radius, controls.phi, controls.theta);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetCamera() {
following = false;
$("#follow").setAttribute("aria-pressed", "false");
controls.target.set(0, 0.65, 3.1);
controls.radius = window.innerWidth < 760 ? 35 : 31;
controls.theta = 0.61;
controls.phi = 0.79;
applyCamera();
}
function toggleFollow() {
following = !following;
$("#follow").setAttribute("aria-pressed", String(following));
$("#follow").textContent = following ? "Following traveler" : "Follow traveler";
}
function togglePause() {
paused = !paused;
$("#pause").textContent = paused ? "Resume walk" : "Pause walk";
}
$("#follow").addEventListener("click", toggleFollow);
$("#pause").addEventListener("click", togglePause);
$("#reset").addEventListener("click", resetCamera);
const canvas = renderer.domElement;
const pointers = new Map();
let drag = null;
let pinchStart = 0;
let radiusStart = controls.radius;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.shiftKey || event.button === 2
};
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchStart = Math.hypot(a.x - b.x, a.y - b.y);
radiusStart = controls.radius;
drag = null;
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchStart > 0) {
controls.radius = THREE.MathUtils.clamp(
radiusStart * (pinchStart / Math.max(1, distance)),
12,
50
);
applyCamera();
}
return;
}
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.setY(0)
.normalize();
const forward = camera.getWorldDirection(new THREE.Vector3()).setY(0).normalize();
const factor = controls.radius * 0.00135;
controls.target
.addScaledVector(right, -dx * factor)
.addScaledVector(forward, -dy * factor);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -16, 16);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -12, 15);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.28,
1.28
);
}
applyCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) drag = null;
else if (pointers.size === 1) {
const [id, point] = [...pointers.entries()][0];
drag = { id, x: point.x, y: point.y, pan: false };
pinchStart = 0;
}
}
canvas.addEventListener("pointerup", removePointer);
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
12,
50
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
togglePause();
} else if (event.key.toLowerCase() === "f") {
toggleFollow();
} else if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ---------------------------------------------------------------------
// Main loop
// ---------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateTraveler(delta, elapsed);
if (following) {
const desiredTarget = traveler.group.position.clone();
desiredTarget.y = 0.8;
const targetMove = desiredTarget
.sub(controls.target)
.multiplyScalar(1 - Math.exp(-delta * 4.5));
controls.target.add(targetMove);
camera.position.add(targetMove);
}
applyCamera();
renderer.render(scene, camera);
}
resetCamera();
updateTraveler(0, 0);
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```