Prompt specification
Build or customize the Three.js 3D scene "Sidewalk assistance vignette" 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: Sidewalk assistance vignette
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sidewalk-assistance-vignette-x3911
Scene Description Prompt:
Compose a small sidewalk outside a shop with two neighbors, dropped groceries, and passing pedestrians; helpers clear the path while preserving space for others. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (sidewalk-assistance-vignette-x3911):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>A Little Care, Room for Everyone</title>
<style>
:root {
--ink: #183432;
--muted: #607572;
--paper: rgba(255, 253, 247, 0.9);
--mint: #cfe9df;
--green: #287563;
--orange: #df704c;
--line: rgba(24, 52, 50, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: 28px;
left: 30px;
max-width: 390px;
padding: 20px 22px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 22px;
background: var(--paper);
box-shadow: 0 14px 42px rgba(43, 74, 69, 0.12);
backdrop-filter: blur(16px);
}
.eyebrow {
margin: 0 0 9px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 330px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 49px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p:last-child {
max-width: 320px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 28px;
right: 30px;
display: flex;
gap: 8px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 17px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(43, 74, 69, 0.1);
backdrop-filter: blur(14px);
pointer-events: auto;
}
button {
appearance: none;
border: 0;
border-radius: 11px;
padding: 10px 13px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: #e6f1ed;
}
button:active {
transform: translateY(1px);
}
button.primary {
background: var(--ink);
color: white;
}
button.primary:hover {
background: #28504c;
}
.story {
position: absolute;
left: 30px;
bottom: 28px;
width: min(390px, calc(100vw - 60px));
padding: 17px 19px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 19px;
background: var(--paper);
box-shadow: 0 12px 36px rgba(43, 74, 69, 0.1);
backdrop-filter: blur(14px);
}
.story-heading {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(40, 117, 99, 0.12);
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
color: var(--muted);
font-size: 12px;
line-height: 1.35;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
}
.swatch.neighbor {
background: #de8b65;
}
.swatch.helper {
background: #e3b44d;
}
.swatch.passer {
background: #5f86a3;
}
.swatch.path {
background: #75b8a5;
}
.status {
position: absolute;
right: 30px;
bottom: 28px;
width: min(320px, calc(100vw - 60px));
padding: 17px 19px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 19px;
background: var(--paper);
box-shadow: 0 12px 36px rgba(43, 74, 69, 0.1);
backdrop-filter: blur(14px);
}
.status-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
}
.status-title strong {
font-size: 13px;
}
.status p {
margin: 8px 0 12px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.progress-track {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: #dce8e4;
}
#progress-fill {
width: 12%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #5fae98, #287563);
transition: width 250ms ease;
}
.camera-hint {
position: absolute;
top: 104px;
right: 31px;
color: rgba(24, 52, 50, 0.64);
font-size: 11px;
font-weight: 650;
text-align: right;
}
@media (max-width: 760px) {
.intro {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
padding: 15px 17px;
}
.intro p:last-child {
display: none;
}
.controls {
top: 126px;
right: 14px;
gap: 2px;
}
button {
padding: 9px 10px;
font-size: 11px;
}
.camera-hint {
top: 181px;
right: 15px;
}
.story {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.status {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Animated neighborhood sidewalk outside a shop"></div>
<main class="ui">
<section class="intro">
<p class="eyebrow">Neighborhood study · 01</p>
<h1>A little care,<br />room for everyone.</h1>
<p>
Neighbors chat beside the market while helpers clear a dropped grocery
run from the edge of the shared sidewalk.
</p>
</section>
<nav class="controls" aria-label="Scene controls">
<button id="pause" class="primary" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="overview" type="button">Overview</button>
<button id="top-view" type="button">Top</button>
</nav>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<section class="story">
<div class="story-heading">
<span class="legend-dot"></span>
Sharing the sidewalk
</div>
<div class="legend">
<span><i class="swatch neighbor"></i>Two neighbors</span>
<span><i class="swatch helper"></i>Two helpers</span>
<span><i class="swatch passer"></i>Passing pedestrians</span>
<span><i class="swatch path"></i>Clear shared path</span>
</div>
</section>
<section class="status" aria-live="polite">
<div class="status-title">
<span class="legend-dot"></span>
<strong id="status-text">Shared lane protected</strong>
</div>
<p id="status-copy">
Helpers work from the shop-side edge while people continue past.
</p>
<div class="progress-track">
<div id="progress-fill"></div>
</div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce9e6");
scene.fog = new THREE.Fog("#dce9e6", 24, 46);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.25, 0.25);
const cameraState = {
yaw: 0.64,
pitch: 0.62,
zoom: 1
};
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = Math.max(6.2, 10.5 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
const horizontal = Math.cos(cameraState.pitch) * 19;
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * horizontal,
cameraTarget.y + Math.sin(cameraState.pitch) * 19,
cameraTarget.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
updateCamera();
// Direct camera controls: no examples or addon modules.
let dragging = false;
let previousPointer = { x: 0, y: 0 };
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.28,
1.38
);
previousPointer = { x: event.clientX, y: event.clientY };
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.75
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf3fbff, 0x8c8574, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d6, 3.1);
sun.position.set(8, 14, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d9df, 0.75);
fill.position.set(-8, 7, 4);
scene.add(fill);
// -------------------------------------------------------------------------
// Geometry and material helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
flatShading: true,
...options
});
}
const materials = {
sidewalk: material("#ddd6c7"),
sidewalkEdge: material("#c8c0b0"),
pavingLine: material("#bdb6a8"),
road: material("#657578"),
roadLine: material("#e9dfbd"),
facade: material("#e9d8bc"),
trim: material("#fff4df"),
mint: material("#87b8a6"),
deepGreen: material("#315d54"),
coral: material("#d96f50"),
cream: material("#f5e7cc"),
wood: material("#b98357"),
dark: material("#263b3a"),
glass: material("#8dbbc0", {
roughness: 0.22,
metalness: 0.05,
transparent: true,
opacity: 0.88
}),
leaf: material("#4d8a62"),
leafLight: material("#75a56f"),
soil: material("#625344"),
metal: material("#526765", { roughness: 0.55, metalness: 0.25 })
};
function addBox(width, height, depth, mat, x, y, z, parent = scene) {
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 addCylinder(
topRadius,
bottomRadius,
height,
mat,
x,
y,
z,
parent = scene,
segments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(radius, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 14, 10),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function textTexture(
text,
{
width = 1024,
height = 256,
background = null,
color = "#183432",
fontSize = 72,
weight = 800,
subtitle = ""
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
if (background) {
ctx.fillStyle = background;
roundedRect(ctx, 8, 8, width - 16, height - 16, 34);
ctx.fill();
} else {
ctx.clearRect(0, 0, width, height);
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = `${weight} ${fontSize}px system-ui, sans-serif`;
ctx.fillText(text, width / 2, subtitle ? height * 0.43 : height / 2);
if (subtitle) {
ctx.font = `600 ${Math.round(fontSize * 0.31)}px system-ui, sans-serif`;
ctx.globalAlpha = 0.72;
ctx.fillText(subtitle, width / 2, height * 0.73);
ctx.globalAlpha = 1;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addTextPlane(text, width, height, x, y, z, options = {}) {
const texture = textTexture(text, options);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
function makeLabel(text, accent = "#287563") {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 84;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(255,253,247,0.94)";
roundedRect(ctx, 6, 6, 308, 72, 28);
ctx.fill();
ctx.fillStyle = accent;
roundedRect(ctx, 17, 17, 9, 50, 5);
ctx.fill();
ctx.fillStyle = "#183432";
ctx.font = "700 31px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 169, 43);
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(1.45, 0.38, 1);
sprite.renderOrder = 10;
return sprite;
}
// -------------------------------------------------------------------------
// Sidewalk, road, and shared path
// -------------------------------------------------------------------------
addBox(22, 0.32, 8.4, materials.sidewalk, 0, -0.16, 0.45);
addBox(22.3, 0.18, 0.25, materials.sidewalkEdge, 0, -0.06, 4.58);
addBox(24, 0.12, 2.5, materials.road, 0, -0.27, 5.75);
for (let x = -10; x <= 10; x += 1.25) {
addBox(0.018, 0.01, 7.9, materials.pavingLine, x, 0.008, 0.45);
}
for (let z = -3.1; z <= 4.1; z += 1.05) {
addBox(21.6, 0.01, 0.018, materials.pavingLine, 0, 0.009, z);
}
for (let x = -9.5; x <= 9.5; x += 2.1) {
addBox(1.05, 0.012, 0.06, materials.cream, x, -0.185, 5.8);
}
const pathMat = new THREE.MeshBasicMaterial({
color: "#75b8a5",
transparent: true,
opacity: 0.12,
depthWrite: false
});
addBox(20.2, 0.018, 1.62, pathMat, 0, 0.021, 1.38);
const pathDashMat = new THREE.MeshBasicMaterial({
color: "#4e9a87",
transparent: true,
opacity: 0.32,
depthWrite: false
});
for (let x = -9.5; x <= 9.5; x += 0.82) {
addBox(0.42, 0.014, 0.035, pathDashMat, x, 0.028, 0.57);
addBox(0.42, 0.014, 0.035, pathDashMat, x, 0.028, 2.19);
}
// A small, unobtrusive painted directional marker.
const arrowMat = new THREE.MeshBasicMaterial({
color: "#4e9a87",
transparent: true,
opacity: 0.19,
depthWrite: false,
side: THREE.DoubleSide
});
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.42, -0.11);
arrowShape.lineTo(0.06, -0.11);
arrowShape.lineTo(0.06, -0.28);
arrowShape.lineTo(0.5, 0);
arrowShape.lineTo(0.06, 0.28);
arrowShape.lineTo(0.06, 0.11);
arrowShape.lineTo(-0.42, 0.11);
arrowShape.closePath();
const arrow = new THREE.Mesh(new THREE.ShapeGeometry(arrowShape), arrowMat);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(-2.8, 0.031, 1.38);
scene.add(arrow);
// -------------------------------------------------------------------------
// Shop and neighboring storefronts
// -------------------------------------------------------------------------
addBox(18, 5.4, 2.1, materials.facade, 0, 2.6, -4.7);
addBox(18.2, 0.24, 2.2, materials.trim, 0, 0.08, -4.68);
addBox(18.1, 0.2, 2.2, materials.deepGreen, 0, 5.24, -4.68);
// Central market sign.
addBox(7.9, 1.1, 0.16, materials.deepGreen, 0, 4.05, -3.57);
addTextPlane(
"MORNING GOODS",
7.4,
0.72,
0,
4.13,
-3.47,
{
background: null,
color: "#fff2d6",
fontSize: 75
}
);
addTextPlane(
"GROCER • DELI • DAILY",
5.4,
0.32,
0,
3.72,
-3.45,
{
color: "#f4d7a0",
fontSize: 37,
weight: 650
}
);
// Side storefront signs.
addBox(4.1, 0.8, 0.13, materials.mint, -6.25, 3.85, -3.57);
addTextPlane("PETAL & STEM", 3.8, 0.55, -6.25, 3.85, -3.48, {
color: "#173d37",
fontSize: 58
});
addBox(4.1, 0.8, 0.13, materials.coral, 6.25, 3.85, -3.57);
addTextPlane("CORNER BOOKS", 3.8, 0.55, 6.25, 3.85, -3.48, {
color: "#fff6e7",
fontSize: 56
});
// Market windows.
for (const x of [-2.45, 2.45]) {
addBox(2.42, 1.82, 0.16, materials.trim, x, 1.35, -3.56);
addBox(2.14, 1.53, 0.12, materials.glass, x, 1.35, -3.45);
addBox(0.055, 1.55, 0.08, materials.trim, x, 1.35, -3.35);
// Quiet product silhouettes in the windows.
addBox(0.26, 0.42, 0.05, materials.coral, x - 0.48, 1.15, -3.36);
addBox(0.3, 0.28, 0.05, materials.leafLight, x + 0.2, 1.38, -3.36);
addBox(0.36, 0.24, 0.05, materials.cream, x + 0.57, 1.1, -3.36);
}
// Central door.
addBox(1.05, 2.28, 0.18, materials.trim, 0, 1.13, -3.55);
addBox(0.83, 1.94, 0.12, materials.glass, 0, 1.14, -3.43);
addCylinder(0.025, 0.025, 0.29, materials.metal, 0.29, 1.08, -3.32);
// Striped awning.
const awningColors = [
material("#d96f50"),
material("#f5e7cc")
];
for (let i = 0; i < 10; i++) {
const strip = addBox(
0.79,
0.11,
1.18,
awningColors[i % 2],
-3.55 + i * 0.79,
2.72,
-3.02
);
strip.rotation.x = -0.08;
}
addBox(8.0, 0.18, 0.1, materials.deepGreen, 0, 2.62, -2.46);
// Side shop windows.
for (const x of [-6.25, 6.25]) {
addBox(3.45, 1.95, 0.15, materials.trim, x, 1.45, -3.57);
addBox(3.15, 1.65, 0.11, materials.glass, x, 1.45, -3.46);
addBox(0.06, 1.7, 0.08, materials.trim, x, 1.45, -3.37);
}
// Small wall lights.
for (const x of [-4.2, 4.2]) {
addBox(0.16, 0.35, 0.17, materials.deepGreen, x, 2.2, -3.45);
addSphere(0.11, material("#ffe4a7", {
emissive: "#ffbd62",
emissiveIntensity: 0.35
}), x, 2.2, -3.31);
}
// Planters.
function addPlanter(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addBox(0.78, 0.5, 0.58, materials.coral, 0, 0.25, 0, group);
addBox(0.66, 0.06, 0.48, materials.soil, 0, 0.51, 0, group);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const leaf = addSphere(
0.22,
i % 2 ? materials.leaf : materials.leafLight,
Math.cos(angle) * 0.17,
0.69 + (i % 3) * 0.09,
Math.sin(angle) * 0.17,
group
);
leaf.scale.set(0.75, 1.35, 0.65);
leaf.rotation.z = Math.cos(angle) * 0.28;
}
return group;
}
addPlanter(-4.65, -2.72, 1.05);
addPlanter(4.65, -2.72, 1.05);
addPlanter(7.85, -2.7, 0.88);
// Bench and bin at the far edge.
addBox(2.1, 0.16, 0.62, materials.wood, -6.8, 0.68, -2.65);
addBox(2.1, 0.56, 0.12, materials.wood, -6.8, 1.05, -2.95);
addBox(0.13, 0.68, 0.5, materials.metal, -7.55, 0.34, -2.65);
addBox(0.13, 0.68, 0.5, materials.metal, -6.05, 0.34, -2.65);
addCylinder(0.3, 0.27, 0.78, materials.deepGreen, 8.0, 0.39, -2.58);
addCylinder(0.34, 0.34, 0.08, materials.metal, 8.0, 0.81, -2.58);
// A designated bag set-down area, away from the pedestrian lane.
const bagMat = new THREE.MeshBasicMaterial({
color: "#df704c",
transparent: true,
opacity: 0.13,
depthWrite: false
});
addBox(2.05, 0.016, 1.08, bagMat, -5.45, 0.026, -2.16);
// -------------------------------------------------------------------------
// Stylized low-poly people
// -------------------------------------------------------------------------
function createPerson({
shirt = "#df704c",
pants = "#38585d",
skin = "#d6a078",
hair = "#473a32",
scale = 1,
hat = false,
apron = false,
tote = false,
grayHair = false
} = {}) {
const root = new THREE.Group();
root.scale.setScalar(scale);
scene.add(root);
const upper = new THREE.Group();
upper.position.y = 0.72;
root.add(upper);
const shirtMat = material(shirt);
const pantsMat = material(pants);
const skinMat = material(skin);
const hairMat = material(grayHair ? "#d7d4ca" : hair);
const shoeMat = material("#293536");
addCylinder(0.205, 0.245, 0.49, shirtMat, 0, 0.27, 0, upper);
addCylinder(0.065, 0.065, 0.11, skinMat, 0, 0.56, 0, upper);
addSphere(0.185, skinMat, 0, 0.77, 0, upper);
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(
0.194,
14,
8,
0,
Math.PI * 2,
0,
Math.PI * 0.55
),
hairMat
);
hairCap.position.set(0, 0.81, 0);
hairCap.castShadow = true;
upper.add(hairCap);
addSphere(0.034, materials.dark, -0.065, 0.79, 0.164, upper);
addSphere(0.034, materials.dark, 0.065, 0.79, 0.164, upper);
addSphere(0.035, skinMat, 0, 0.75, 0.184, upper);
if (hat) {
addCylinder(0.19, 0.19, 0.055, shirtMat, 0, 0.96, 0, upper);
addBox(0.34, 0.035, 0.21, shirtMat, 0, 0.94, 0.13, upper);
}
if (apron) {
addBox(0.36, 0.48, 0.035, material("#f2e7c8"), 0, 0.2, 0.215, upper);
addBox(0.22, 0.11, 0.04, material("#f2e7c8"), 0, 0.29, 0.24, upper);
}
if (tote) {
addBox(0.28, 0.36, 0.16, material("#e8c46e"), 0.31, 0.02, 0.01, upper);
}
const legs = [];
const shoes = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.105, 0.72, 0);
root.add(pivot);
addCylinder(0.075, 0.065, 0.53, pantsMat, 0, -0.265, 0, pivot);
addBox(0.16, 0.1, 0.27, shoeMat, 0, -0.57, 0.045, pivot);
legs.push(pivot);
shoes.push(pivot.children[1]);
}
const arms = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.255, 0.43, 0);
upper.add(pivot);
addCylinder(0.063, 0.058, 0.32, shirtMat, 0, -0.16, 0, pivot);
addSphere(0.062, skinMat, 0, -0.36, 0, pivot);
arms.push(pivot);
}
return {
root,
upper,
legs,
arms,
shoes,
phase: Math.random() * Math.PI * 2
};
}
function animatePerson(person, phase, walking = false, bend = 0) {
const swing = Math.sin(phase);
person.legs[0].rotation.x = walking ? swing * 0.55 : 0;
person.legs[1].rotation.x = walking ? -swing * 0.55 : 0;
person.arms[0].rotation.x = walking ? -swing * 0.42 : 0;
person.arms[1].rotation.x = walking ? swing * 0.42 : 0;
person.upper.rotation.x = bend;
if (walking) {
person.root.position.y = Math.abs(Math.sin(phase)) * 0.025;
}
}
// Two neighbors chatting near the storefront.
const neighborA = createPerson({
shirt: "#d98668",
pants: "#546779",
skin: "#b87858",
hair: "#3c302c",
scale: 0.98
});
const neighborB = createPerson({
shirt: "#e7b94e",
pants: "#425f59",
skin: "#e2b18c",
grayHair: true,
tote: true,
scale: 0.93
});
neighborA.root.position.set(-3.65, 0, -2.02);
neighborA.root.rotation.y = 1.15;
neighborB.root.position.set(-2.55, 0, -2.18);
neighborB.root.rotation.y = -1.25;
const avaLabel = makeLabel("Ava · neighbor", "#df704c");
avaLabel.position.set(-3.65, 2.12, -2.02);
scene.add(avaLabel);
const benLabel = makeLabel("Ben · neighbor", "#df704c");
benLabel.position.set(-2.55, 2.05, -2.18);
scene.add(benLabel);
// One helper lifts and relocates groceries.
const helperA = createPerson({
shirt: "#e9aa3f",
pants: "#2e6470",
skin: "#8e5d43",
hair: "#292825",
hat: true,
apron: true,
scale: 1.02
});
// The second helper sweeps the small spill toward the edge.
const helperB = createPerson({
shirt: "#5f9d87",
pants: "#304f63",
skin: "#d39a72",
hair: "#6a4b38",
hat: true,
scale: 0.97
});
// Broom attached to the second helper.
const broom = new THREE.Group();
broom.position.set(0.39, 1.0, 0.15);
broom.rotation.z = -0.38;
helperB.root.add(broom);
addCylinder(0.022, 0.022, 1.05, materials.wood, 0, -0.48, 0, broom);
addBox(0.44, 0.08, 0.18, materials.deepGreen, 0, -1.01, 0.03, broom);
// -------------------------------------------------------------------------
// Dropped groceries
// -------------------------------------------------------------------------
function makeBag(color, kind = "paper") {
const group = new THREE.Group();
const bagMat = material(color);
if (kind === "paper") {
addBox(0.38, 0.44, 0.28, bagMat, 0, 0.22, 0, group);
const handleMaterial = material("#f1d6a0");
for (const x of [-0.1, 0.1]) {
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.017, 8, 16, Math.PI),
handleMaterial
);
handle.position.set(x, 0.44, 0);
handle.scale.y = 1.3;
handle.castShadow = true;
group.add(handle);
}
} else {
addBox(0.42, 0.32, 0.3, bagMat, 0, 0.16, 0, group);
addBox(0.28, 0.08, 0.2, material("#f4ead2"), 0, 0.35, 0, group);
}
return group;
}
const bagA = makeBag("#dc7654");
const bagB = makeBag("#72a67d");
const bagC = makeBag("#e7bd63", "box");
const groceries = [
{
group: bagA,
initial: new THREE.Vector3(0.28, 0.02, 0.12),
final: new THREE.Vector3(-5.85, 0.02, -2.31),
carryOffset: new THREE.Vector3(-0.12, 0.03, 0.28)
},
{
group: bagB,
initial: new THREE.Vector3(0.77, 0.02, 0.25),
final: new THREE.Vector3(-5.38, 0.02, -2.39),
carryOffset: new THREE.Vector3(0.11, 0.03, 0.31)
},
{
group: bagC,
initial: new THREE.Vector3(1.06, 0.02, 0.05),
final: new THREE.Vector3(-4.98, 0.02, -2.2),
carryOffset: new THREE.Vector3(0.13, 0.03, 0.12)
}
];
groceries.forEach((item) => {
item.group.position.copy(item.initial);
scene.add(item.group);
});
// A few groceries visible at the top of the bags.
addSphere(0.11, material("#d65445"), 0.3, 0.56, 0.13, bagA);
addSphere(0.1, material("#e8bd43"), 0.79, 0.51, 0.24, bagB);
// Small spill for the sweeper.
const crumbColors = ["#c87a42", "#d7a04d", "#a8673f"];
const crumbs = [];
for (let i = 0; i < 11; i++) {
const angle = (i / 11) * Math.PI * 2;
const radius = 0.12 + (i % 4) * 0.075;
const initial = new THREE.Vector3(
1.34 + Math.cos(angle) * radius,
0.045,
0.22 + Math.sin(angle) * radius * 0.55
);
const final = new THREE.Vector3(
4.88 + Math.cos(angle) * 0.12,
0.045,
-0.56 + Math.sin(angle) * 0.09
);
const crumb = addSphere(
0.045,
material(crumbColors[i % crumbColors.length]),
initial.x,
initial.y,
initial.z
);
crumb.scale.set(1, 0.65, 1.1);
crumbs.push({ mesh: crumb, initial, final });
}
// Dustpan follows the helper until it is set down.
const dustpan = new THREE.Group();
addBox(0.52, 0.055, 0.36, materials.metal, 0, 0.05, 0, dustpan);
addBox(0.065, 0.06, 0.78, materials.metal, 0, 0.055, 0.43, dustpan);
addBox(0.44, 0.025, 0.28, materials.deepGreen, 0, 0.085, -0.02, dustpan);
scene.add(dustpan);
const collectedCrumbs = new THREE.Group();
dustpan.add(collectedCrumbs);
for (let i = 0; i < 6; i++) {
addSphere(
0.035,
material(crumbColors[i % crumbColors.length]),
(i % 3 - 1) * 0.12,
0.11,
((i / 3) - 0.5) * 0.12,
collectedCrumbs
);
}
collectedCrumbs.visible = false;
// -------------------------------------------------------------------------
// Passing pedestrians
// -------------------------------------------------------------------------
const passerA = createPerson({
shirt: "#668aa6",
pants: "#344a56",
skin: "#c58a65",
hair: "#3a302d",
tote: true,
scale: 1.02
});
const passerB = createPerson({
shirt: "#9b6f8c",
pants: "#3f5260",
skin: "#e1ad87",
hair: "#72503a",
scale: 0.92
});
const passerC = createPerson({
shirt: "#d9a64c",
pants: "#53624f",
skin: "#895d46",
hair: "#282725",
scale: 0.98
});
const passers = [
{ person: passerA, z: 1.02, speed: 0.78, offset: 0, direction: 1 },
{ person: passerB, z: 1.45, speed: 0.94, offset: 8, direction: -1 },
{ person: passerC, z: 1.84, speed: 0.72, offset: 15, direction: 1 }
];
// -------------------------------------------------------------------------
// Cleanup animation
// -------------------------------------------------------------------------
const helperAStart = new THREE.Vector3(-1.3, 0, -0.04);
const helperAPick = new THREE.Vector3(-0.08, 0, 0.12);
const helperAFinal = new THREE.Vector3(-5.22, 0, -1.82);
const helperBStart = new THREE.Vector3(2.45, 0, 0.02);
const helperBPick = new THREE.Vector3(1.18, 0, 0.18);
const helperBFinal = new THREE.Vector3(4.83, 0, -0.56);
function smoothstep(min, max, value) {
const x = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return x * x * (3 - 2 * x);
}
function pulse(value, start, end) {
if (value < start || value > end) return 0;
return Math.sin(((value - start) / (end - start)) * Math.PI);
}
function angleLerp(a, b, amount) {
let difference = ((b - a + Math.PI) % (Math.PI * 2)) - Math.PI;
if (difference < -Math.PI) difference += Math.PI * 2;
return a + difference * amount;
}
function directionAngle(from, to) {
return Math.atan2(to.x - from.x, to.z - from.z);
}
function setHelperPosition(person, position) {
person.root.position.set(position.x, 0, position.z);
}
function updateHelpers(time) {
const t = Math.min(time, 7.35);
// Helper A: approach, lift, carry, and place.
let aMoving = false;
if (t < 2.45) {
const alpha = smoothstep(0, 2.45, t);
setHelperPosition(
helperA,
helperAStart.clone().lerp(helperAPick, alpha)
);
helperA.root.rotation.y = angleLerp(
helperA.root.rotation.y,
directionAngle(helperAStart, helperAPick),
0.12
);
aMoving = true;
} else if (t < 3.15) {
setHelperPosition(helperA, helperAPick);
helperA.root.rotation.y = angleLerp(
helperA.root.rotation.y,
1.25,
0.12
);
} else if (t < 6.2) {
const alpha = smoothstep(3.15, 6.2, t);
setHelperPosition(
helperA,
helperAPick.clone().lerp(helperAFinal, alpha)
);
helperA.root.rotation.y = angleLerp(
helperA.root.rotation.y,
directionAngle(helperAPick, helperAFinal),
0.08
);
aMoving = true;
} else {
setHelperPosition(helperA, helperAFinal);
helperA.root.rotation.y = angleLerp(
helperA.root.rotation.y,
0.35,
0.08
);
}
const liftBend = pulse(t, 2.2, 3.2);
const carryBend = t >= 3.1 && t < 6.35 ? 0.15 : 0;
const placeBend = pulse(t, 6.15, 7.2);
animatePerson(
helperA,
t * 7.5,
aMoving,
Math.max(liftBend, carryBend, placeBend)
);
if (t >= 2.8 && t < 6.7) {
helperA.arms[0].rotation.x = -0.8;
helperA.arms[1].rotation.x = -0.75;
}
helperA.root.updateMatrixWorld(true);
groceries.forEach((item) => {
if (t < 3.0) {
item.group.position.copy(item.initial);
} else if (t < 6.2) {
const alpha = smoothstep(3.0, 3.48, t);
const carryPosition = helperA.root.localToWorld(
item.carryOffset.clone()
);
item.group.position.copy(item.initial).lerp(carryPosition, alpha);
item.group.rotation.y = helperA.root.rotation.y;
} else if (t < 7.15) {
const alpha = smoothstep(6.2, 7.15, t);
item.group.position.lerp(item.final, alpha);
item.group.rotation.y = THREE.MathUtils.lerp(
helperA.root.rotation.y,
0.2,
alpha
);
} else {
item.group.position.copy(item.final);
item.group.rotation.y = 0.2;
}
});
// Helper B: sweep while staying below the pedestrian path.
let bMoving = false;
if (t < 1.85) {
const alpha = smoothstep(0, 1.85, t);
setHelperPosition(
helperB,
helperBStart.clone().lerp(helperBPick, alpha)
);
helperB.root.rotation.y = angleLerp(
helperB.root.rotation.y,
directionAngle(helperBStart, helperBPick),
0.12
);
bMoving = true;
} else if (t < 2.55) {
setHelperPosition(helperB, helperBPick);
helperB.root.rotation.y = angleLerp(
helperB.root.rotation.y,
1.35,
0.12
);
} else if (t < 6.2) {
const alpha = smoothstep(2.55, 6.2, t);
setHelperPosition(
helperB,
helperBPick.clone().lerp(helperBFinal, alpha)
);
helperB.root.rotation.y = angleLerp(
helperB.root.rotation.y,
directionAngle(helperBPick, helperBFinal),
0.09
);
bMoving = true;
} else {
setHelperPosition(helperB, helperBFinal);
helperB.root.rotation.y = angleLerp(
helperB.root.rotation.y,
0.2,
0.08
);
}
const sweepBend = Math.max(
pulse(t, 1.65, 2.55),
t >= 2.55 && t < 6.2 ? 0.17 : 0
);
animatePerson(helperB, t * 8.1, bMoving, sweepBend);
helperB.arms[0].rotation.x = -0.55;
helperB.arms[1].rotation.x = -0.35;
broom.rotation.y = Math.sin(t * 10) * 0.27;
broom.rotation.z = -0.38 + Math.sin(t * 10) * 0.08;
helperB.root.updateMatrixWorld(true);
if (t < 6.2) {
const panPosition = helperB.root.localToWorld(
new THREE.Vector3(0.43, 0, 0.02)
);
dustpan.position.copy(panPosition);
dustpan.rotation.y = helperB.root.rotation.y;
} else {
dustpan.position.set(5.2, 0, -0.65);
dustpan.rotation.y = 0.25;
}
crumbs.forEach((crumb) => {
if (t < 2.45) {
crumb.mesh.position.copy(crumb.initial);
crumb.mesh.visible = true;
} else if (t < 5.95) {
const alpha = smoothstep(2.45, 5.95, t);
crumb.mesh.position.copy(crumb.initial).lerp(crumb.final, alpha);
crumb.mesh.visible = true;
} else {
crumb.mesh.visible = false;
}
});
collectedCrumbs.visible = t >= 5.95;
}
// -------------------------------------------------------------------------
// Continuous animation and interface
// -------------------------------------------------------------------------
let elapsed = 0;
let paused = false;
let previousTime = performance.now();
const pauseButton = document.querySelector("#pause");
const replayButton = document.querySelector("#replay");
const overviewButton = document.querySelector("#overview");
const topButton = document.querySelector("#top-view");
const progressFill = document.querySelector("#progress-fill");
const statusText = document.querySelector("#status-text");
const statusCopy = document.querySelector("#status-copy");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
});
replayButton.addEventListener("click", () => {
elapsed = 0;
paused = false;
pauseButton.textContent = "Pause";
pauseButton.setAttribute("aria-pressed", "false");
updateHelpers(0);
updatePassers(0);
});
overviewButton.addEventListener("click", () => {
cameraState.yaw = 0.64;
cameraState.pitch = 0.62;
cameraState.zoom = 1;
updateCamera();
});
topButton.addEventListener("click", () => {
cameraState.yaw = 0;
cameraState.pitch = 1.36;
cameraState.zoom = 1.08;
updateCamera();
});
function updatePassers(time) {
passers.forEach((passer, index) => {
const travel = 23;
const raw = passer.offset + time * passer.speed * passer.direction;
const wrapped = ((raw % travel) + travel) % travel;
const x = -11.5 + wrapped;
passer.person.root.position.set(x, 0, passer.z);
passer.person.root.rotation.y =
passer.direction > 0 ? Math.PI / 2 : -Math.PI / 2;
animatePerson(
passer.person,
time * 7.4 + passer.person.phase + index,
true,
0
);
});
}
function updateNeighbors(time) {
animatePerson(neighborA, time * 1.1, false, 0);
animatePerson(neighborB, time * 1.1 + 1.3, false, 0);
neighborA.root.position.y = Math.sin(time * 1.5) * 0.008;
neighborB.root.position.y = Math.sin(time * 1.5 + 1) * 0.008;
neighborA.arms[1].rotation.z = -0.2 - Math.sin(time * 1.3) * 0.13;
neighborB.arms[0].rotation.x = -0.25 - Math.sin(time * 1.2) * 0.08;
avaLabel.position.y = 2.12 + Math.sin(time * 1.5) * 0.015;
benLabel.position.y = 2.05 + Math.sin(time * 1.5 + 1) * 0.015;
}
function updateStatus() {
const progress = THREE.MathUtils.clamp(elapsed / 7.2, 0, 1);
progressFill.style.width = `${12 + progress * 88}%`;
if (elapsed < 2.3) {
statusText.textContent = "Helpers approaching";
statusCopy.textContent =
"The helpers stay at the edge of the shared lane.";
} else if (elapsed < 6.2) {
statusText.textContent = "Shared lane protected";
statusCopy.textContent =
"Pedestrians keep moving while the spill is cleared from the edge.";
} else {
statusText.textContent = "The path is clear";
statusCopy.textContent =
"Groceries are set aside, crumbs are collected, and the sidewalk is open.";
}
}
function render(now) {
requestAnimationFrame(render);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
elapsed += delta;
}
updateHelpers(elapsed);
updatePassers(elapsed);
updateNeighbors(elapsed);
updateStatus();
renderer.render(scene, camera);
}
updateHelpers(0);
updatePassers(0);
updateNeighbors(0);
requestAnimationFrame(render);
</script>
</body>
</html>
```