Prompt specification
Build or customize the Three.js 3D scene "Sudden-shower street 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: Sudden-shower street vignette
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sudden-shower-street-vignette-x0631
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Compose pedestrians, storefront shelter, paving, and umbrellas; one visitor opens an umbrella only after stepping clear of others, then follows the shared sidewalk route.
Working Three.js Starter (sudden-shower-street-vignette-x0631):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rainy Corner — Shared Sidewalk</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(15, 30, 39, 0.78);
--line: rgba(255, 255, 255, 0.14);
--text: #f4f7f5;
--muted: #b7c6ca;
--accent: #ffd166;
--teal: #75d5c5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #8ca4ae;
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;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
max-width: 360px;
padding: 17px 19px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(10, 25, 31, 0.18);
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
font-weight: 750;
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.story {
position: absolute;
left: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
padding: 16px 17px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 15px;
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(10, 25, 31, 0.18);
}
.story-head {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(255, 209, 102, 0.12);
}
#status {
font-size: 13px;
font-weight: 650;
line-height: 1.35;
}
.progress-track {
height: 4px;
overflow: hidden;
background: rgba(255, 255, 255, 0.12);
border-radius: 10px;
}
#progress {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--teal), var(--accent));
border-radius: inherit;
transition: width 0.15s linear;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 13px;
backdrop-filter: blur(14px);
pointer-events: auto;
}
.hint {
padding: 0 5px;
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
button {
padding: 9px 12px;
color: #173139;
background: var(--accent);
border: 0;
border-radius: 9px;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition:
transform 0.15s ease,
filter 0.15s ease;
}
button:hover {
filter: brightness(1.07);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.legend {
position: absolute;
right: 24px;
top: 24px;
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
color: var(--muted);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 999px;
backdrop-filter: blur(14px);
font-size: 11px;
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
}
@media (max-width: 720px) {
.brand {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
padding: 14px 15px;
}
.subtitle,
.legend {
display: none;
}
.story {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.controls {
right: 14px;
bottom: 126px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="overlay">
<section class="brand">
<div class="eyebrow">A small moment in the rain</div>
<h1>Rainy Corner</h1>
<p class="subtitle">
One visitor leaves the crowded shelter, opens an umbrella only after
making space, then joins the shared sidewalk.
</p>
</section>
<div class="legend">
<span class="legend-dot"></span>
<span>Follow the visitor in yellow</span>
</div>
<section class="story" aria-live="polite">
<div class="story-head">
<span class="status-dot"></span>
<span id="status">Waiting beneath the storefront shelter</span>
</div>
<div class="progress-track">
<div id="progress"></div>
</div>
</section>
<div class="controls">
<span class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</span>
<button id="replay" type="button">Replay</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x8ea6b0);
scene.fog = new THREE.Fog(0x8ea6b0, 18, 48);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xc9e4ef, 0x3a4b48, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xe8f3f1, 3.1);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00035;
scene.add(sun);
const warmFill = new THREE.DirectionalLight(0xffc77b, 1.1);
warmFill.position.set(9, 7, -10);
scene.add(warmFill);
const cameraTarget = new THREE.Vector3(0, 0.65, -2.1);
const spherical = new THREE.Spherical(22, 1.02, 0.72);
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Direct camera controls — no external control modules
// ------------------------------------------------------------
let pointerDown = false;
let panMode = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
panMode = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panMode) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const amount = spherical.radius * 0.0015;
cameraTarget.addScaledVector(right, -dx * amount);
cameraTarget.addScaledVector(up, dy * amount);
} else {
spherical.theta -= dx * 0.005;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.005,
0.28,
1.42
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
10,
38
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------
// Materials and reusable helpers
// ------------------------------------------------------------
const palette = {
asphalt: new THREE.MeshStandardMaterial({
color: 0x34464a,
roughness: 0.76
}),
sidewalk: new THREE.MeshStandardMaterial({
color: 0xb8c1bb,
roughness: 0.86
}),
curb: new THREE.MeshStandardMaterial({
color: 0xd3d3c7,
roughness: 0.82
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x26373b,
roughness: 0.42,
metalness: 0.62
}),
warmMetal: new THREE.MeshStandardMaterial({
color: 0x9b7751,
roughness: 0.58,
metalness: 0.2
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0xb8dce2,
roughness: 0.16,
metalness: 0.05,
transparent: true,
opacity: 0.38,
depthWrite: false
}),
warmWindow: new THREE.MeshStandardMaterial({
color: 0xf4c985,
emissive: 0xe6a94d,
emissiveIntensity: 0.72,
roughness: 0.35
})
};
function mesh(geometry, material, x = 0, y = 0, z = 0) {
const object = new THREE.Mesh(geometry, material);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
return object;
}
function box(width, height, depth, material, x, y, z) {
return mesh(
new THREE.BoxGeometry(width, height, depth),
material,
x,
y,
z
);
}
function cylinder(
radiusTop,
radiusBottom,
height,
material,
x,
y,
z,
segments = 10
) {
return mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material,
x,
y,
z
);
}
function signTexture(text, bg = "#25383c", fg = "#f5ead5") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = fg;
ctx.font = "700 64px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeSign(text, width, x, y, z, bg, fg) {
const material = new THREE.MeshBasicMaterial({
map: signTexture(text, bg, fg)
});
const sign = new THREE.Mesh(new THREE.PlaneGeometry(width, 0.52), material);
sign.position.set(x, y, z);
scene.add(sign);
return sign;
}
// ------------------------------------------------------------
// Ground, paving, curb, and shared route
// ------------------------------------------------------------
box(34, 0.22, 26, palette.asphalt, 0, -0.2, 0);
const tileGeometry = new THREE.BoxGeometry(1.13, 0.07, 1.13);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82
});
const tileColumns = 22;
const tileRows = 17;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileColumns * tileRows
);
tiles.receiveShadow = true;
tiles.castShadow = false;
const tileMatrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < tileRows; row++) {
for (let column = 0; column < tileColumns; column++) {
const x = -12.9 + column * 1.2;
const z = -5.4 + row * 1.2;
tileMatrix.makeTranslation(x, -0.035, z);
tiles.setMatrixAt(tileIndex, tileMatrix);
const shade = 0.48 + Math.random() * 0.12;
tileColor.setHSL(0.43, 0.07, shade);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
box(27.2, 0.18, 3.2, palette.sidewalk, 0, 0.08, -3.05);
box(27.2, 0.23, 0.16, palette.curb, 0, 0.1, -1.42);
box(27.2, 0.08, 1.7, palette.sidewalk, 0, 0.005, -4.98);
// Tactile paving and a restrained shared-route inlay.
const tactileMaterial = new THREE.MeshStandardMaterial({
color: 0xc6a86c,
roughness: 0.82
});
box(25.8, 0.045, 0.22, tactileMaterial, 0, 0.19, -1.75);
for (let x = -12.2; x < 12.5; x += 0.34) {
box(0.08, 0.02, 0.17, palette.curb, x, 0.225, -1.75);
}
const routeMaterial = new THREE.MeshStandardMaterial({
color: 0x72b9ad,
roughness: 0.88
});
for (let x = -12.4; x < 12.8; x += 1.25) {
box(0.68, 0.018, 0.035, routeMaterial, x, 0.182, -2.48);
}
const arrowPositions = [];
for (let x = -11; x < 12; x += 3) {
arrowPositions.push(
x - 0.24, 0.205, -2.72,
x + 0.12, 0.205, -2.48,
x - 0.24, 0.205, -2.24,
x + 0.12, 0.205, -2.48
);
}
const arrowGeometry = new THREE.BufferGeometry();
arrowGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(arrowPositions, 3)
);
scene.add(
new THREE.LineSegments(
arrowGeometry,
new THREE.LineBasicMaterial({ color: 0x4f8f87 })
)
);
// A subtle inlaid circle marks the clear area without looking like a game.
const clearCircle = new THREE.Mesh(
new THREE.RingGeometry(0.77, 0.82, 48),
new THREE.MeshBasicMaterial({
color: 0x83b9ae,
transparent: true,
opacity: 0.65,
side: THREE.DoubleSide
})
);
clearCircle.rotation.x = -Math.PI / 2;
clearCircle.position.set(-1.8, 0.025, 0.9);
scene.add(clearCircle);
// ------------------------------------------------------------
// Storefront
// ------------------------------------------------------------
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xc5b9a4,
roughness: 0.88
});
box(25, 6.2, 1.4, wallMaterial, 0, 3.1, -7.35);
box(25.4, 0.24, 1.8, palette.darkMetal, 0, 6.25, -7.25);
box(25.1, 0.35, 1.7, palette.curb, 0, 0.12, -7.25);
const shopColors = [0x315c5e, 0x855b4a, 0x3e526c, 0x7b7048];
for (let i = 0; i < 4; i++) {
const x = -9.2 + i * 6.1;
box(4.9, 3.25, 0.12, palette.darkMetal, x, 1.8, -6.57);
box(4.45, 2.86, 0.08, palette.warmWindow, x, 1.72, -6.49);
for (let pane = -1; pane <= 1; pane++) {
box(0.07, 2.85, 0.1, palette.darkMetal, x + pane * 1.45, 1.72, -6.42);
}
box(0.09, 2.9, 0.1, palette.darkMetal, x, 1.72, -6.41);
box(4.95, 0.2, 0.13, palette.darkMetal, x, 0.54, -6.38);
const awningMaterial = new THREE.MeshStandardMaterial({
color: shopColors[i],
roughness: 0.72
});
const awning = box(5.15, 0.17, 1.22, awningMaterial, x, 3.55, -6.08);
awning.rotation.x = -0.12;
for (let stripe = -2; stripe <= 2; stripe++) {
const stripeMaterial = new THREE.MeshStandardMaterial({
color: stripe % 2 === 0 ? 0xe7dcc7 : shopColors[i],
roughness: 0.74
});
box(0.43, 0.025, 1.23, stripeMaterial, x + stripe * 0.85, 3.65, -6.08);
}
}
makeSign("RAIN & RUE MARKET", 5.3, 0, 5.45, -6.61, "#26383c", "#f3d78c");
makeSign("COFFEE", 2.1, 9.2, 4.58, -6.55, "#855b4a", "#f8ead8");
makeSign("BOOKS", 2.1, 3.1, 4.58, -6.55, "#3e526c", "#edf0e8");
makeSign("FLOWERS", 2.3, -3.1, 4.58, -6.55, "#315c5e", "#e4ead8");
makeSign("BAKERY", 2.1, -9.2, 4.58, -6.55, "#7b7048", "#fff1cf");
// Warm pools of light beneath the storefront.
for (const x of [-9.2, -3.1, 3.1, 9.2]) {
const light = new THREE.PointLight(0xffbd68, 9, 8, 2);
light.position.set(x, 2.5, -5.8);
scene.add(light);
}
// ------------------------------------------------------------
// Shelter
// ------------------------------------------------------------
const shelter = new THREE.Group();
shelter.position.set(-6.05, 0, -2.72);
scene.add(shelter);
const shelterWidth = 4.8;
const shelterDepth = 2.65;
const roof = new THREE.Mesh(
new THREE.BoxGeometry(shelterWidth, 0.09, shelterDepth),
palette.glass
);
roof.position.y = 2.58;
roof.castShadow = true;
shelter.add(roof);
box(shelterWidth + 0.12, 0.12, 0.12, palette.darkMetal, 0, 2.55, 1.24);
box(shelterWidth + 0.12, 0.12, 0.12, palette.darkMetal, 0, 2.55, -1.24);
for (const x of [-2.25, 2.25]) {
for (const z of [-1.15, 1.15]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, 2.55, 10),
palette.darkMetal
);
post.position.set(x, 1.275, z);
post.castShadow = true;
shelter.add(post);
}
}
const bench = new THREE.Group();
bench.position.set(-0.85, 0, -0.92);
shelter.add(bench);
box(2.25, 0.14, 0.48, palette.warmMetal, 0, 0.55, 0);
box(2.25, 0.55, 0.1, palette.warmMetal, 0, 0.93, -0.2);
box(0.12, 0.55, 0.42, palette.darkMetal, -0.85, 0.26, 0);
box(0.12, 0.55, 0.42, palette.darkMetal, 0.85, 0.26, 0);
const shelterSign = makeSign(
"SHELTER",
1.4,
-6.05,
2.75,
-1.35,
"#26383c",
"#b7ddd4"
);
shelterSign.rotation.y = 0;
// ------------------------------------------------------------
// Umbrella geometry
// ------------------------------------------------------------
function makeUmbrellaCanopy(radius = 0.68, colorA = 0xffd166, colorB = 0xf29f58) {
const group = new THREE.Group();
const segments = 10;
const positions = [];
const colors = [];
const panelColors = [
new THREE.Color(colorA),
new THREE.Color(colorB)
];
for (let i = 0; i < segments; i++) {
const a0 = (i / segments) * Math.PI * 2;
const a1 = ((i + 1) / segments) * Math.PI * 2;
const center = [0, 0, 0];
const p0 = [
Math.cos(a0) * radius,
-0.25,
Math.sin(a0) * radius
];
const p1 = [
Math.cos(a1) * radius,
-0.25,
Math.sin(a1) * radius
];
positions.push(...center, ...p0, ...p1);
const color = panelColors[i % 2];
for (let j = 0; j < 3; j++) {
colors.push(color.r, color.g, color.b);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const canopy = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.68,
side: THREE.DoubleSide
})
);
canopy.castShadow = true;
group.add(canopy);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.014, 6, 40),
new THREE.MeshStandardMaterial({
color: 0x32464a,
roughness: 0.65
})
);
rim.rotation.x = Math.PI / 2;
rim.position.y = -0.25;
group.add(rim);
const ribPositions = [];
for (let i = 0; i < segments; i++) {
const a = (i / segments) * Math.PI * 2;
ribPositions.push(
0, 0, 0,
Math.cos(a) * radius,
-0.24,
Math.sin(a) * radius
);
}
const ribGeometry = new THREE.BufferGeometry();
ribGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(ribPositions, 3)
);
group.add(
new THREE.LineSegments(
ribGeometry,
new THREE.LineBasicMaterial({ color: 0x405257 })
)
);
return group;
}
function makeCarriedUmbrella(colorA, colorB) {
const root = new THREE.Group();
root.position.set(0, 1.57, 0.02);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.86, 8),
palette.darkMetal
);
shaft.position.set(0.28, -0.42, 0);
shaft.castShadow = true;
root.add(shaft);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.055, 0.014, 6, 14, Math.PI * 1.5),
palette.darkMetal
);
handle.position.set(0.28, -0.87, 0);
handle.rotation.z = Math.PI / 2;
root.add(handle);
const canopy = makeUmbrellaCanopy(0.68, colorA, colorB);
canopy.position.x = 0.28;
root.add(canopy);
const closed = new THREE.Group();
closed.position.set(0.28, -0.06, 0);
const foldedFabric = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.32, 8),
new THREE.MeshStandardMaterial({ color: colorA, roughness: 0.75 })
);
foldedFabric.position.y = 0.08;
foldedFabric.castShadow = true;
closed.add(foldedFabric);
const band = new THREE.Mesh(
new THREE.CylinderGeometry(0.061, 0.061, 0.035, 8),
palette.darkMetal
);
band.position.y = -0.03;
closed.add(band);
root.add(closed);
return { root, canopy, closed };
}
function setUmbrellaAmount(umbrella, amount) {
umbrella.canopy.visible = amount > 0.01;
umbrella.closed.visible = amount < 0.98;
const s = 0.08 + amount * 0.92;
umbrella.canopy.scale.set(s, 0.28 + amount * 0.72, s);
umbrella.closed.scale.setScalar(1 - amount * 0.2);
}
// ------------------------------------------------------------
// Café furniture and decorative umbrellas
// ------------------------------------------------------------
function addCafeSet(x, z, umbrellaColors) {
const tableTop = new THREE.Mesh(
new THREE.CylinderGeometry(0.65, 0.65, 0.09, 18),
new THREE.MeshStandardMaterial({
color: 0xd4c6a7,
roughness: 0.8
})
);
tableTop.position.set(x, 0.85, z);
tableTop.castShadow = true;
tableTop.receiveShadow = true;
scene.add(tableTop);
cylinder(0.055, 0.075, 0.78, palette.darkMetal, x, 0.42, z);
cylinder(0.38, 0.38, 0.06, palette.darkMetal, x, 0.04, z);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.045, 2.45, 10),
palette.darkMetal
);
pole.position.set(x, 1.22, z);
pole.castShadow = true;
scene.add(pole);
const canopy = makeUmbrellaCanopy(
0.95,
umbrellaColors[0],
umbrellaColors[1]
);
canopy.position.set(x, 2.38, z);
scene.add(canopy);
for (const angle of [0.65, 2.75, 4.65]) {
const chairX = x + Math.cos(angle) * 1.08;
const chairZ = z + Math.sin(angle) * 1.08;
const seat = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.29, 0.08, 12),
new THREE.MeshStandardMaterial({
color: 0x48615f,
roughness: 0.8
})
);
seat.position.set(chairX, 0.43, chairZ);
seat.castShadow = true;
scene.add(seat);
cylinder(0.035, 0.05, 0.4, palette.darkMetal, chairX, 0.2, chairZ);
const back = new THREE.Mesh(
new THREE.TorusGeometry(0.27, 0.025, 6, 16, Math.PI),
palette.darkMetal
);
back.position.set(chairX, 0.68, chairZ);
back.rotation.x = Math.PI / 2;
back.rotation.z = angle + Math.PI / 2;
scene.add(back);
}
}
addCafeSet(4.25, 1.2, [0xe6b65f, 0xf1d9a5]);
addCafeSet(7.4, 0.3, [0x9f5348, 0xe7c9ae]);
addCafeSet(10.1, 2.1, [0x3d7774, 0xb9d8c9]);
// ------------------------------------------------------------
// Stylized pedestrians
// ------------------------------------------------------------
function createPerson({
coat = 0x425b70,
trousers = 0x29383d,
skin = 0xd8a37f,
hair = 0x3a2e2a,
umbrella = null,
umbrellaAmount = 0
} = {}) {
const root = new THREE.Group();
const coatMaterial = new THREE.MeshStandardMaterial({
color: coat,
roughness: 0.84
});
const trouserMaterial = new THREE.MeshStandardMaterial({
color: trousers,
roughness: 0.88
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: skin,
roughness: 0.9
});
const hairMaterial = new THREE.MeshStandardMaterial({
color: hair,
roughness: 0.96
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.26, 0.76, 9),
coatMaterial
);
body.position.y = 0.78;
body.castShadow = true;
root.add(body);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.205, 0.205, 0.1, 10),
new THREE.MeshStandardMaterial({
color: new THREE.Color(coat).multiplyScalar(0.78),
roughness: 0.9
})
);
collar.position.y = 1.12;
root.add(collar);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.205, 12, 9),
skinMaterial
);
head.position.y = 1.36;
head.castShadow = true;
root.add(head);
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(0.212, 12, 8, 0, Math.PI * 2, 0, Math.PI * 0.55),
hairMaterial
);
hairCap.position.y = 1.39;
hairCap.rotation.x = -0.12;
hairCap.castShadow = true;
root.add(hairCap);
const nose = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 8, 6),
skinMaterial
);
nose.position.set(0, 1.35, 0.195);
root.add(nose);
const legPivots = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.105, 0.43, 0);
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.075, 0.4, 8),
trouserMaterial
);
leg.position.y = -0.19;
leg.castShadow = true;
pivot.add(leg);
const shoe = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.09, 0.23),
palette.darkMetal
);
shoe.position.set(0, -0.39, 0.055);
shoe.castShadow = true;
pivot.add(shoe);
root.add(pivot);
legPivots.push(pivot);
}
const armPivots = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.25, 1.02, 0);
const arm = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.065, 0.43, 8),
coatMaterial
);
arm.position.y = -0.2;
arm.castShadow = true;
pivot.add(arm);
const hand = new THREE.Mesh(
new THREE.SphereGeometry(0.064, 8, 6),
skinMaterial
);
hand.position.y = -0.43;
pivot.add(hand);
root.add(pivot);
armPivots.push(pivot);
}
let carriedUmbrella = null;
if (umbrella) {
carriedUmbrella = makeCarriedUmbrella(umbrella[0], umbrella[1]);
root.add(carriedUmbrella.root);
setUmbrellaAmount(carriedUmbrella, umbrellaAmount);
}
scene.add(root);
return {
root,
legPivots,
armPivots,
umbrella: carriedUmbrella,
walkPhase: Math.random() * Math.PI * 2,
moving: false
};
}
function animatePerson(person, moving, dt, speed = 1) {
if (moving) {
person.walkPhase += dt * 6.6 * speed;
}
const swing = moving ? Math.sin(person.walkPhase) * 0.55 : 0;
const bob = moving ? Math.abs(Math.sin(person.walkPhase)) * 0.025 : 0;
person.legPivots[0].rotation.x = swing;
person.legPivots[1].rotation.x = -swing;
person.armPivots[0].rotation.x = -swing * 0.72;
person.armPivots[1].rotation.x = swing * 0.72;
person.root.position.y += bob;
}
function faceDirection(person, dx, dz) {
if (Math.abs(dx) + Math.abs(dz) < 0.0001) return;
const target = Math.atan2(dx, dz);
let difference = target - person.root.rotation.y;
difference = Math.atan2(Math.sin(difference), Math.cos(difference));
person.root.rotation.y += difference * 0.14;
}
const visitor = createPerson({
coat: 0xe1a839,
trousers: 0x334b50,
skin: 0xc98f6e,
hair: 0x2d2928,
umbrella: [0xffd166, 0xef9f54]
});
visitor.root.position.set(-6.6, 0.08, -1.62);
const scarf = new THREE.Mesh(
new THREE.TorusGeometry(0.2, 0.035, 6, 18),
new THREE.MeshStandardMaterial({
color: 0xb8554d,
roughness: 0.9
})
);
scarf.position.y = 1.16;
scarf.rotation.x = Math.PI / 2;
visitor.root.add(scarf);
const visitorRing = new THREE.Mesh(
new THREE.RingGeometry(0.44, 0.48, 40),
new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.75,
side: THREE.DoubleSide
})
);
visitorRing.rotation.x = -Math.PI / 2;
scene.add(visitorRing);
const people = [
createPerson({
coat: 0x607b69,
trousers: 0x354347,
skin: 0x9b684f,
hair: 0x1f2425
}),
createPerson({
coat: 0x8e5f56,
trousers: 0x29383f,
skin: 0xe0ad86,
hair: 0x5a3f2f
}),
createPerson({
coat: 0x3e6175,
trousers: 0x25333b,
skin: 0xc48765,
hair: 0x282424
}),
createPerson({
coat: 0x6e6688,
trousers: 0x29343b,
skin: 0xe0b292,
hair: 0x3c302a,
umbrella: [0x536b89, 0x263a55],
umbrellaAmount: 1
}),
createPerson({
coat: 0xb76e53,
trousers: 0x3d4143,
skin: 0x8e5d48,
hair: 0x201f1e
})
];
// ------------------------------------------------------------
// Street details
// ------------------------------------------------------------
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0x354447,
roughness: 0.48,
metalness: 0.55
});
for (const x of [-11.2, 0.2, 11.2]) {
cylinder(0.055, 0.09, 4.1, lampMaterial, x, 2.05, -5.35);
cylinder(0.28, 0.1, 0.28, lampMaterial, x, 4.12, -5.35);
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 10, 8),
new THREE.MeshBasicMaterial({ color: 0xffe3a2 })
);
lamp.position.set(x, 3.96, -5.35);
scene.add(lamp);
const glow = new THREE.PointLight(0xffcf7c, 4, 5, 2);
glow.position.set(x, 3.8, -5.2);
scene.add(glow);
}
for (const x of [-12, -10.8, 11.7, 12.9]) {
cylinder(0.11, 0.14, 0.65, lampMaterial, x, 0.33, 4.8);
cylinder(0.145, 0.145, 0.06, palette.curb, x, 0.67, 4.8);
}
const puddleMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8eb9c2,
roughness: 0.12,
metalness: 0.05,
transparent: true,
opacity: 0.22,
depthWrite: false,
side: THREE.DoubleSide
});
for (let i = 0; i < 14; i++) {
const puddle = new THREE.Mesh(
new THREE.CircleGeometry(0.45 + Math.random() * 0.8, 24),
puddleMaterial
);
puddle.rotation.x = -Math.PI / 2;
puddle.scale.y = 0.35 + Math.random() * 0.45;
puddle.position.set(
-12 + Math.random() * 24,
0.035,
-4.5 + Math.random() * 10
);
scene.add(puddle);
}
// ------------------------------------------------------------
// Rain
// ------------------------------------------------------------
const rainCount = 720;
const rainPositions = new Float32Array(rainCount * 6);
const rainDrops = [];
for (let i = 0; i < rainCount; i++) {
rainDrops.push({
x: -17 + Math.random() * 34,
y: Math.random() * 15,
z: -13 + Math.random() * 24,
speed: 6.5 + Math.random() * 4.5,
length: 0.22 + Math.random() * 0.32
});
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rain = new THREE.LineSegments(
rainGeometry,
new THREE.LineBasicMaterial({
color: 0xd8edf0,
transparent: true,
opacity: 0.37,
depthWrite: false
})
);
scene.add(rain);
const ripples = [];
for (let i = 0; i < 22; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0xc4e0e2,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.12, 0.135, 24),
material
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(
-13 + Math.random() * 26,
0.065,
-4.7 + Math.random() * 10
);
ripple.userData.life = Math.random();
scene.add(ripple);
ripples.push(ripple);
}
// ------------------------------------------------------------
// Visitor journey
// ------------------------------------------------------------
const visitorPath = [
new THREE.Vector3(-1.8, 0.075, 0.9),
new THREE.Vector3(-1.18, 0.18, -2.48),
new THREE.Vector3(12.8, 0.18, -2.48)
];
const pathSegments = [];
let totalPathLength = 0;
for (let i = 0; i < visitorPath.length - 1; i++) {
const start = visitorPath[i];
const end = visitorPath[i + 1];
const length = start.distanceTo(end);
pathSegments.push({ start, end, length });
totalPathLength += length;
}
function sampleVisitorPath(distance) {
let remaining = THREE.MathUtils.clamp(
distance,
0,
totalPathLength
);
for (const segment of pathSegments) {
if (remaining <= segment.length) {
const t = segment.length === 0 ? 0 : remaining / segment.length;
const point = segment.start.clone().lerp(segment.end, t);
const direction = segment.end.clone().sub(segment.start).normalize();
return { point, direction };
}
remaining -= segment.length;
}
const last = visitorPath[visitorPath.length - 1];
return {
point: last.clone(),
direction: new THREE.Vector3(1, 0, 0)
};
}
let worldTime = 0;
let journeyTime = 0;
let visitorPhase = "wait";
let umbrellaAmount = 0;
let routeStartTime = 0;
let lastStatus = "";
const statusElement = document.getElementById("status");
const progressElement = document.getElementById("progress");
function setStatus(text) {
if (text !== lastStatus) {
statusElement.textContent = text;
lastStatus = text;
}
}
function horizontalDistance(a, b) {
return Math.hypot(a.x - b.x, a.z - b.z);
}
function nearestOtherDistance() {
let nearest = Infinity;
for (const person of people) {
nearest = Math.min(
nearest,
horizontalDistance(
visitor.root.position,
person.root.position
)
);
}
return nearest;
}
function resetJourney() {
worldTime = 0;
journeyTime = 0;
visitorPhase = "wait";
umbrellaAmount = 0;
routeStartTime = 0;
visitor.root.position.set(-6.6, 0.08, -1.62);
visitor.root.rotation.y = Math.PI * 0.5;
setUmbrellaAmount(visitor.umbrella, 0);
setStatus("Waiting beneath the storefront shelter");
progressElement.style.width = "0%";
}
document.getElementById("replay").addEventListener("click", resetJourney);
resetJourney();
function updateOtherPeople(dt) {
// Two people waiting under or near the shelter.
const p0x = -5.02 + Math.sin(worldTime * 0.72) * 0.24;
const p0z = -2.45 + Math.cos(worldTime * 0.61) * 0.13;
people[0].root.position.set(p0x, 0.19, p0z);
faceDirection(people[0], Math.cos(worldTime * 0.72) * 0.2, 0);
animatePerson(people[0], true, dt, 0.35);
const p1x = -7.08 + Math.sin(worldTime * 0.54 + 1.2) * 0.16;
const p1z = -2.16 + Math.cos(worldTime * 0.58 + 0.8) * 0.12;
people[1].root.position.set(p1x, 0.19, p1z);
faceDirection(people[1], 0, Math.cos(worldTime * 0.58 + 0.8) * 0.1);
animatePerson(people[1], true, dt, 0.25);
// Shared sidewalk users moving in the opposite direction.
const p2x = 2.7 - ((worldTime * 1.12) % 20);
people[2].root.position.set(p2x, 0.19, -1.93);
faceDirection(people[2], -1, 0);
animatePerson(people[2], true, dt, 1);
const p3x = 10.8 - ((worldTime * 1.34) % 25);
people[3].root.position.set(p3x, 0.19, -3.55);
faceDirection(people[3], -1, 0);
animatePerson(people[3], true, dt, 1.1);
// Café visitor.
people[4].root.position.set(5.25, 0.08, 0.35);
people[4].root.rotation.y = -0.8;
animatePerson(people[4], false, dt);
}
function updateVisitor(dt) {
let moving = false;
if (visitorPhase === "wait") {
setStatus("Waiting beneath the storefront shelter");
animatePerson(visitor, false, dt);
if (journeyTime >= 2.0) {
visitorPhase = "exit";
}
} else if (visitorPhase === "exit") {
moving = true;
setStatus("Stepping away from the group");
const t = THREE.MathUtils.clamp(
(journeyTime - 2.0) / 3.6,
0,
1
);
const eased = t * t * (3 - 2 * t);
const startX = -6.6;
const startZ = -1.62;
const endX = -1.8;
const endZ = 0.9;
visitor.root.position.x =
startX + (endX - startX) * eased;
visitor.root.position.z =
startZ + (endZ - startZ) * eased;
visitor.root.position.y = 0.075;
faceDirection(
visitor,
endX - startX,
endZ - startZ
);
animatePerson(visitor, moving, dt);
if (t >= 1) {
visitorPhase = "waitClear";
}
} else if (visitorPhase === "waitClear") {
setStatus("Making enough space for the umbrella");
animatePerson(visitor, false, dt);
if (nearestOtherDistance() > 1.5) {
visitorPhase = "opening";
}
} else if (visitorPhase === "opening") {
const clearDistance = nearestOtherDistance();
if (clearDistance > 1.45) {
umbrellaAmount = Math.min(1, umbrellaAmount + dt / 0.9);
setStatus("Clear of everyone — opening the yellow umbrella");
} else {
setStatus("Yielding space before opening the umbrella");
}
setUmbrellaAmount(visitor.umbrella, umbrellaAmount);
animatePerson(visitor, false, dt);
if (umbrellaAmount >= 1) {
visitorPhase = "route";
routeStartTime = journeyTime;
}
} else if (visitorPhase === "route") {
moving = true;
setStatus("Following the shared sidewalk route");
const routeDistance = (journeyTime - routeStartTime) * 1.12;
const sample = sampleVisitorPath(routeDistance);
visitor.root.position.copy(sample.point);
faceDirection(
visitor,
sample.direction.x,
sample.direction.z
);
animatePerson(visitor, moving, dt);
if (routeDistance >= totalPathLength) {
visitorPhase = "done";
}
} else {
setStatus("Route complete — sharing the sidewalk with everyone else");
animatePerson(visitor, false, dt);
}
visitorRing.position.set(
visitor.root.position.x,
visitor.root.position.y + 0.012,
visitor.root.position.z
);
const pulse = 1 + Math.sin(worldTime * 3) * 0.055;
visitorRing.scale.setScalar(pulse);
visitorRing.material.opacity =
visitorPhase === "waitClear" || visitorPhase === "opening"
? 0.9
: 0.52;
progressElement.style.width = `${Math.min(
100,
(journeyTime / 22) * 100
)}%`;
}
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
worldTime += dt;
journeyTime += dt;
updateOtherPeople(dt);
updateVisitor(dt);
// Rain falls and wraps back to the top.
for (let i = 0; i < rainCount; i++) {
const drop = rainDrops[i];
drop.y -= drop.speed * dt;
if (drop.y < -0.5) {
drop.y = 13 + Math.random() * 3;
drop.x = -17 + Math.random() * 34;
drop.z = -13 + Math.random() * 24;
}
const index = i * 6;
rainPositions[index] = drop.x;
rainPositions[index + 1] = drop.y;
rainPositions[index + 2] = drop.z;
rainPositions[index + 3] = drop.x + 0.035;
rainPositions[index + 4] = drop.y + drop.length;
rainPositions[index + 5] = drop.z;
}
rainGeometry.attributes.position.needsUpdate = true;
// Expanding raindrop rings.
for (const ripple of ripples) {
ripple.userData.life += dt * 0.72;
if (ripple.userData.life > 1) {
ripple.userData.life = 0;
ripple.position.x = -13 + Math.random() * 26;
ripple.position.z = -4.7 + Math.random() * 10;
}
const life = ripple.userData.life;
ripple.scale.setScalar(0.4 + life * 4.5);
ripple.material.opacity = Math.sin(life * Math.PI) * 0.28;
}
renderer.render(scene, camera);
}
animate();
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```