Prompt specification
Build or customize the Three.js 3D scene "Rainy Platform Commuter Scene" 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: Rainy Platform Commuter Scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rainy-platform-commuter-scene-x3707
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts clothing layers and attachments on moving characters. Build a small fictional transit platform with original characters wearing varied rain gear. Show umbrellas, bags, and coats moving consistently with bodies and avoiding overlapping silhouettes. Voxel style.
Working Three.js Starter (rainy-platform-commuter-scene-x3707):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mossvale Rainline — Voxel Transit Scene</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf8f5;
--muted: #a9c4c4;
--panel: rgba(13, 31, 37, 0.78);
--line: rgba(181, 231, 224, 0.22);
--mint: #91dfc8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9bb9be;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.title-card {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 19px 16px;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 3px;
box-shadow: 0 12px 35px rgba(8, 24, 29, 0.22);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 0.98;
letter-spacing: -0.06em;
text-transform: uppercase;
}
.subtitle {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.commuters {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 15px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
color: #d7e8e6;
border: 1px solid rgba(181, 231, 224, 0.14);
background: rgba(255, 255, 255, 0.035);
font-size: 9px;
letter-spacing: 0.05em;
}
.dot {
width: 7px;
height: 7px;
background: var(--chip-color);
box-shadow: 0 0 9px color-mix(in srgb, var(--chip-color) 60%, transparent);
}
.controls {
position: absolute;
right: 22px;
top: 22px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
button {
min-width: 92px;
padding: 10px 13px;
color: #e7f7f4;
background: rgba(13, 31, 37, 0.84);
border: 1px solid rgba(181, 231, 224, 0.3);
border-radius: 2px;
font: 800 10px/1 ui-monospace, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: rgba(30, 64, 67, 0.94);
border-color: rgba(181, 231, 224, 0.62);
}
.weather {
padding: 10px 12px;
color: #d5e9e7;
background: rgba(13, 31, 37, 0.7);
border: 1px solid var(--line);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.weather::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 8px;
background: #8ce4d1;
border-radius: 50%;
box-shadow: 0 0 10px #8ce4d1;
vertical-align: 1px;
}
.hint {
position: absolute;
right: 22px;
bottom: 20px;
padding: 9px 11px;
color: rgba(232, 247, 244, 0.8);
background: rgba(13, 31, 37, 0.62);
border: 1px solid rgba(181, 231, 224, 0.16);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: #d8efeb;
background: #172f35;
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.subtitle,
.commuters {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
}
.weather {
display: none;
}
.hint {
right: auto;
left: 12px;
bottom: 15px;
max-width: 48vw;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Rainline 07 · Live voxel diorama</div>
<h1>Mossvale<br />Junction</h1>
<p class="subtitle">
Four original commuters share a single-file platform lane.
Coats, scarves, bags, and umbrellas remain attached to their moving
body pivots while their silhouettes stay separated.
</p>
<div class="commuters" aria-label="Commuter colors">
<span class="chip" style="--chip-color:#2b7b78">
<i class="dot"></i>ADA
</span>
<span class="chip" style="--chip-color:#e3ad35">
<i class="dot"></i>IVO
</span>
<span class="chip" style="--chip-color:#b54d62">
<i class="dot"></i>MINA
</span>
<span class="chip" style="--chip-color:#655a9b">
<i class="dot"></i>SOL
</span>
</div>
</section>
<div class="controls">
<div class="weather">Rain 82% · 11°C</div>
<button id="motionButton" type="button" aria-live="polite">Pause</button>
</div>
<div class="hint">Drag to orbit · wheel / pinch to zoom</div>
</div>
<div id="loading" class="loading">Assembling Mossvale Junction…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.8));
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.13;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9bb9be);
scene.fog = new THREE.Fog(0x9bb9be, 27, 58);
const camera = new THREE.OrthographicCamera(-14, 14, 8, -8, 0.1, 100);
const cameraState = {
target: new THREE.Vector3(0, 1.05, 0),
azimuth: 0.64,
elevation: 0.47,
distance: 28,
zoom: 1
};
function updateCamera() {
const { target, azimuth, elevation, distance } = cameraState;
const horizontal = Math.cos(elevation) * distance;
camera.position.set(
target.x + horizontal * Math.sin(azimuth),
target.y + Math.sin(elevation) * distance,
target.z + horizontal * Math.cos(azimuth)
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = 15.5;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.8));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Direct camera controls: no addons are used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= dx * 0.005;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.0035,
0.24,
1.02
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.15
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Lighting and reusable helpers
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xd8f0f2, 0x425157, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5bd, 3.0);
sun.position.set(-11, 18, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00045;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x8bcbd0, 1.0);
rim.position.set(12, 8, -14);
scene.add(rim);
const materialCache = new Map();
function matte(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true
})
);
}
return materialCache.get(color);
}
function cuboid(
parent,
size,
position,
material,
{ castShadow = true, receiveShadow = true } = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
typeof material === "number" ? matte(material) : material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function boxOutline(parent, size, position, color, thickness = 0.025) {
const [w, h, d] = size;
const [x, y, z] = position;
const material = matte(color);
cuboid(parent, [w, thickness, thickness], [x, y + h / 2, z + d / 2], material);
cuboid(parent, [w, thickness, thickness], [x, y - h / 2, z + d / 2], material);
cuboid(parent, [w, thickness, thickness], [x, y + h / 2, z - d / 2], material);
cuboid(parent, [w, thickness, thickness], [x, y - h / 2, z - d / 2], material);
cuboid(parent, [thickness, h, thickness], [x - w / 2, y, z + d / 2], material);
cuboid(parent, [thickness, h, thickness], [x + w / 2, y, z + d / 2], material);
cuboid(parent, [thickness, h, thickness], [x - w / 2, y, z - d / 2], material);
cuboid(parent, [thickness, h, thickness], [x + w / 2, y, z - d / 2], material);
}
// -------------------------------------------------------------------------
// Platform, track, city, and shelter
// -------------------------------------------------------------------------
const platform = new THREE.Group();
scene.add(platform);
cuboid(platform, [40, 0.72, 7.6], [0, -0.36, 1.0], 0x65777a);
cuboid(platform, [40, 0.12, 0.18], [0, 0.02, -2.72], 0xd3b75c);
cuboid(platform, [40, 0.15, 0.14], [0, -0.04, 4.69], 0x394e54);
// Tile seams.
const tilePoints = [];
for (let x = -19.5; x <= 19.5; x += 1.25) {
tilePoints.push(x, 0.012, -2.65, x, 0.012, 4.65);
}
for (let z = -2.5; z <= 4.5; z += 1.2) {
tilePoints.push(-19.8, 0.012, z, 19.8, 0.012, z);
}
const tileGeometry = new THREE.BufferGeometry();
tileGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tilePoints, 3)
);
platform.add(
new THREE.LineSegments(
tileGeometry,
new THREE.LineBasicMaterial({
color: 0x9aabad,
transparent: true,
opacity: 0.25
})
)
);
// Tactile paving studs.
const studGeometry = new THREE.BoxGeometry(0.085, 0.025, 0.085);
const studMaterial = matte(0xd8b954);
const studCount = 86 * 2;
const studs = new THREE.InstancedMesh(studGeometry, studMaterial, studCount);
const studMatrix = new THREE.Matrix4();
let studIndex = 0;
for (let x = -19.5; x <= 19.5; x += 0.45) {
for (const z of [-2.35, -2.55]) {
studMatrix.makeTranslation(x, 0.025, z);
studs.setMatrixAt(studIndex++, studMatrix);
}
}
studs.receiveShadow = true;
platform.add(studs);
// Shallow wet patches.
const puddleMaterial = new THREE.MeshBasicMaterial({
color: 0xa8d3d4,
transparent: true,
opacity: 0.25,
depthWrite: false
});
const puddles = [
[-11, 2.0, 2.7, 1.0],
[-5.8, -0.8, 1.4, 2.0],
[1.2, 2.9, 1.5, 0.8],
[7.2, 0.2, 2.1, 1.2],
[12.8, 3.3, 1.7, 0.9]
];
for (const [x, z, w, d] of puddles) {
const puddle = cuboid(
platform,
[w, 0.012, d],
[x, 0.022, z],
puddleMaterial,
{ castShadow: false, receiveShadow: false }
);
puddle.rotation.y = (x % 3) * 0.11;
}
// Tracks below platform level.
const track = new THREE.Group();
scene.add(track);
cuboid(track, [42, 0.34, 3.5], [0, -1.0, -5.15], 0x3f4c50);
cuboid(track, [42, 0.12, 0.12], [0, -0.68, -4.35], 0xa6b2b0);
cuboid(track, [42, 0.12, 0.12], [0, -0.68, -5.95], 0xa6b2b0);
for (let x = -20; x <= 20; x += 1.25) {
cuboid(track, [0.24, 0.14, 2.0], [x, -0.78, -5.15], 0x5a5048);
}
// Shelter behind the walking lane.
const shelter = new THREE.Group();
shelter.position.x = -8.2;
scene.add(shelter);
cuboid(shelter, [8.2, 0.28, 2.7], [0, 2.82, -1.55], 0x29444b);
cuboid(shelter, [8.35, 0.10, 2.8], [0, 2.96, -1.55], 0x79a5a7);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0xaed8d8,
transparent: true,
opacity: 0.22,
roughness: 0.25,
depthWrite: false
});
cuboid(
shelter,
[7.45, 1.85, 0.08],
[0, 1.52, -2.38],
glassMaterial,
{ castShadow: false }
);
for (const x of [-3.7, 3.7]) {
cuboid(shelter, [0.18, 2.75, 0.18], [x, 1.38, -2.25], 0x405b61);
}
// Bench.
const bench = new THREE.Group();
bench.position.set(8.2, 0, -1.85);
scene.add(bench);
for (let i = 0; i < 3; i++) {
cuboid(bench, [3.6, 0.13, 0.24], [0, 0.62, i * 0.27 - 0.27], 0x946f52);
}
for (const x of [-1.35, 1.35]) {
cuboid(bench, [0.18, 0.62, 0.62], [x, 0.31, 0], 0x344c50);
}
// Lamps.
for (const x of [-15.2, 14.9]) {
cuboid(scene, [0.14, 3.3, 0.14], [x, 1.65, -1.7], 0x30494e);
cuboid(scene, [0.85, 0.18, 0.35], [x, 3.28, -1.55], 0xdde7cf);
cuboid(scene, [0.58, 0.08, 0.24], [x, 3.16, -1.55], 0xffedb7);
}
// Voxel city backdrop.
let seed = 19;
function random() {
seed = (seed * 9301 + 49297) % 233280;
return seed / 233280;
}
const cityColors = [0x64777b, 0x738487, 0x596d74, 0x829092, 0x506870];
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xe8d9a7,
emissive: 0xc8a75d,
emissiveIntensity: 0.5,
roughness: 0.7
});
for (let i = 0; i < 15; i++) {
const width = 2.0 + random() * 2.5;
const depth = 2.0 + random() * 2.2;
const height = 3.0 + random() * 7.5;
const x = -25 + i * 3.65 + random() * 0.7;
const z = -12.5 - random() * 4.0;
cuboid(
scene,
[width, height, depth],
[x, height / 2 - 1.1, z],
cityColors[i % cityColors.length]
);
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 2; col++) {
if (random() > 0.32) {
cuboid(
scene,
[0.38, 0.52, 0.035],
[
x + (col - 0.5) * width * 0.46,
0.5 + row * 1.55,
z + depth / 2 + 0.02
],
windowMaterial,
{ castShadow: false }
);
}
}
}
}
// -------------------------------------------------------------------------
// Fictional station sign made with a canvas texture
// -------------------------------------------------------------------------
function makeStationSign() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.fillStyle = "#17363d";
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#88d8c2";
context.fillRect(0, 0, 28, canvas.height);
context.fillRect(54, 34, 916, 5);
context.fillStyle = "#edf8f3";
context.font = "900 92px monospace";
context.fillText("MOSSVALE", 92, 136);
context.fillStyle = "#9dc3c1";
context.font = "700 34px monospace";
context.fillText("RAINLINE 07 / PLATFORM A", 96, 207);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const group = new THREE.Group();
group.position.set(1.3, 2.75, -2.72);
cuboid(group, [5.35, 1.55, 0.16], [0, 0, -0.09], 0x20383e);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(5.15, 1.29),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
})
);
face.position.z = 0.005;
group.add(face);
scene.add(group);
for (const x of [-2.1, 2.1]) {
cuboid(scene, [0.15, 2.0, 0.15], [1.3 + x, 1.45, -2.74], 0x304a4f);
}
}
makeStationSign();
// -------------------------------------------------------------------------
// Train
// -------------------------------------------------------------------------
const train = new THREE.Group();
train.position.z = -5.12;
scene.add(train);
cuboid(train, [7.4, 1.85, 2.25], [0, -0.03, 0], 0x93beb3);
cuboid(train, [7.15, 0.22, 2.1], [0, 0.98, 0], 0xd5dfd0);
cuboid(train, [6.9, 0.18, 1.75], [0, -1.03, 0], 0x354c4d);
const trainWindow = new THREE.MeshStandardMaterial({
color: 0x244652,
emissive: 0x2e6470,
emissiveIntensity: 0.42,
roughness: 0.35
});
for (let x = -2.8; x <= 2.8; x += 1.4) {
cuboid(
train,
[0.92, 0.74, 0.045],
[x, 0.28, 1.145],
trainWindow,
{ castShadow: false }
);
}
for (const x of [-2.3, 2.3]) {
cuboid(train, [0.35, 0.35, 0.35], [x, -1.15, 0.88], 0x263b3d);
cuboid(train, [0.35, 0.35, 0.35], [x, -1.15, -0.88], 0x263b3d);
}
cuboid(train, [0.13, 0.14, 1.6], [0, -0.56, 1.19], 0xe3b75a);
// -------------------------------------------------------------------------
// Character construction
//
// Every wearable and carried object is parented to the appropriate moving
// body pivot. Coat tails and scarves use hip/neck pivots; the tote uses a
// hand pivot; the umbrella uses a hand pivot with counter-rotation; packs
// and satchels use torso pivots.
// -------------------------------------------------------------------------
function createBackpack(parent, color, trimColor) {
const pack = new THREE.Group();
pack.position.set(-0.49, 1.53, 0);
cuboid(pack, [0.36, 0.76, 0.70], [0, 0, 0], color);
cuboid(pack, [0.13, 0.34, 0.72], [-0.23, -0.19, 0], trimColor);
cuboid(pack, [0.07, 0.61, 0.09], [0.22, 0.06, -0.27], trimColor);
cuboid(pack, [0.07, 0.61, 0.09], [0.22, 0.06, 0.27], trimColor);
parent.add(pack);
return pack;
}
function createUmbrella(arm, mainColor, trimColor) {
const umbrella = new THREE.Group();
umbrella.position.set(0, -0.72, 0);
// Handle and shaft.
cuboid(umbrella, [0.07, 1.48, 0.07], [0, 0.72, 0], 0x3d5557);
cuboid(umbrella, [0.08, 0.28, 0.08], [0, 0.12, 0], 0x3d5557);
cuboid(umbrella, [0.25, 0.08, 0.08], [0.09, -0.02, 0], 0x3d5557);
// Stepped cuboid canopy.
cuboid(umbrella, [1.50, 0.14, 1.68], [0, 1.40, 0], mainColor);
cuboid(umbrella, [1.23, 0.14, 1.36], [0, 1.54, 0], trimColor);
cuboid(umbrella, [0.91, 0.14, 1.01], [0, 1.68, 0], mainColor);
cuboid(umbrella, [0.08, 0.28, 0.08], [0, 1.86, 0], 0x40585a);
// Pixel-like ribs.
cuboid(umbrella, [1.05, 0.025, 0.045], [0, 1.76, 0], trimColor);
cuboid(umbrella, [0.045, 0.025, 1.03], [0, 1.76, 0], trimColor);
arm.add(umbrella);
return umbrella;
}
function createTote(arm, color, trimColor) {
const tote = new THREE.Group();
tote.position.set(0, -0.76, 0);
cuboid(tote, [0.52, 0.60, 0.34], [0.02, -0.36, 0], color);
cuboid(tote, [0.09, 0.25, 0.07], [-0.11, -0.02, 0], trimColor);
cuboid(tote, [0.09, 0.25, 0.07], [0.15, -0.02, 0], trimColor);
cuboid(tote, [0.28, 0.09, 0.07], [0.02, -0.05, 0], trimColor);
arm.add(tote);
return tote;
}
function createSatchel(parent, color, trimColor) {
const bag = new THREE.Group();
bag.position.set(-0.03, 1.27, 0.63);
cuboid(bag, [0.52, 0.53, 0.23], [0, 0, 0], color);
cuboid(bag, [0.38, 0.16, 0.25], [0, 0.12, 0], trimColor);
cuboid(bag, [0.09, 0.10, 0.25], [0, -0.08, 0], trimColor);
const strap = cuboid(
parent,
[0.055, 0.95, 0.11],
[0.37, 1.57, 0.41],
trimColor
);
strap.rotation.x = -0.50;
parent.add(bag);
return bag;
}
function createCharacter(config, index) {
const root = new THREE.Group();
root.position.z = config.laneZ;
scene.add(root);
const coatMaterial = matte(config.coat);
const trimMaterial = matte(config.trim);
const pantsMaterial = matte(config.pants);
const skinMaterial = matte(config.skin);
const bootMaterial = matte(config.boots || 0x26383c);
const darkMaterial = matte(0x17272c);
const legs = [];
const arms = {};
// Layer 1: trousers and boots.
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(0, 0.92, side * 0.225);
cuboid(pivot, [0.43, 0.70, 0.38], [0, -0.35, 0], pantsMaterial);
cuboid(pivot, [0.59, 0.23, 0.42], [0.10, -0.78, 0], bootMaterial);
cuboid(pivot, [0.12, 0.08, 0.43], [0.30, -0.87, 0], trimMaterial);
root.add(pivot);
legs.push(pivot);
}
// Layer 2: hips and raincoat body.
cuboid(root, [0.62, 0.27, 0.80], [0, 1.01, 0], pantsMaterial);
cuboid(root, [0.69, 0.93, 0.92], [0, 1.53, 0], coatMaterial);
cuboid(root, [0.73, 0.14, 0.95], [0, 1.05, 0], trimMaterial);
cuboid(root, [0.045, 0.68, 0.11], [0.365, 1.48, 0], trimMaterial);
for (const y of [1.34, 1.63]) {
cuboid(root, [0.055, 0.07, 0.07], [0.397, y, 0], darkMaterial);
}
// Layer 3: separate split coat tails on hip pivots.
const coatPanels = [];
const tailLength = config.tailLength ?? 0.70;
for (const side of [-1, 1]) {
const panelPivot = new THREE.Group();
panelPivot.position.set(-0.015, 1.10, side * 0.225);
cuboid(
panelPivot,
[0.66, tailLength, 0.41],
[0, -tailLength / 2, 0],
coatMaterial
);
cuboid(
panelPivot,
[0.68, 0.09, 0.43],
[0, -tailLength + 0.045, 0],
trimMaterial
);
root.add(panelPivot);
coatPanels.push(panelPivot);
}
// Layer 4: coat sleeves and hands.
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(0, 1.82, side * 0.61);
cuboid(pivot, [0.42, 0.62, 0.35], [0, -0.29, 0], coatMaterial);
cuboid(pivot, [0.44, 0.11, 0.37], [0, -0.61, 0], trimMaterial);
cuboid(pivot, [0.32, 0.27, 0.31], [0.02, -0.76, 0], skinMaterial);
root.add(pivot);
arms[side] = pivot;
}
// Neck, head, hood, and facial details.
cuboid(root, [0.35, 0.25, 0.34], [0, 2.07, 0], skinMaterial);
const head = new THREE.Group();
head.position.set(0, 2.24, 0);
root.add(head);
cuboid(head, [0.53, 0.51, 0.53], [0.08, 0.05, 0], skinMaterial);
if (config.hood) {
cuboid(head, [0.48, 0.66, 0.70], [-0.16, 0.12, 0], coatMaterial);
cuboid(head, [0.10, 0.58, 0.72], [-0.22, 0.09, 0], trimMaterial);
} else {
cuboid(head, [0.55, 0.14, 0.55], [0.05, 0.34, 0], config.hair || 0x3b302d);
}
if (config.beanie) {
cuboid(head, [0.58, 0.20, 0.59], [0.04, 0.37, 0], config.trim);
cuboid(head, [0.49, 0.13, 0.50], [0.04, 0.51, 0], config.coat);
}
cuboid(head, [0.035, 0.055, 0.055], [0.365, 0.14, -0.13], darkMaterial);
cuboid(head, [0.035, 0.055, 0.055], [0.365, 0.14, 0.13], darkMaterial);
cuboid(head, [0.10, 0.075, 0.075], [0.39, 0.00, 0], skinMaterial);
// Layer 5: optional scarf, with its own trailing pivot.
let scarfPivot = null;
if (config.scarf) {
const scarfMaterial = matte(config.scarf);
cuboid(root, [0.57, 0.16, 0.65], [0, 1.99, 0], scarfMaterial);
scarfPivot = new THREE.Group();
scarfPivot.position.set(0.38, 1.91, 0.17);
cuboid(scarfPivot, [0.10, 0.47, 0.19], [0, -0.23, 0], scarfMaterial);
root.add(scarfPivot);
}
// Layer 6: torso-mounted and hand-mounted attachments.
let backpack = null;
let satchel = null;
let tote = null;
let umbrella = null;
if (config.backpack) {
backpack = createBackpack(root, config.backpack, config.trim);
}
if (config.satchel) {
satchel = createSatchel(root, config.satchel, config.trim);
}
if (config.tote) {
tote = createTote(arms[-1], config.tote, config.trim);
}
if (config.umbrella) {
umbrella = createUmbrella(
arms[1],
config.umbrella,
config.umbrellaTrim || config.trim
);
}
return {
root,
legs,
arms,
coatPanels,
scarfPivot,
backpack,
satchel,
tote,
umbrella,
phase: config.phase || 0
};
}
// Equal spacing plus equal walking speed guarantees that the commuters
// remain separated in one lane, including at the loop boundaries.
const laneZ = 1.25;
const characterConfigs = [
{
name: "Ada",
offset: -12,
phase: 0.2,
laneZ,
coat: 0x2b7b78,
trim: 0xe66d5c,
scarf: 0xe66d5c,
pants: 0x273e50,
skin: 0x9b6447,
hair: 0x302927,
satchel: 0xc7684f,
tailLength: 0.78
},
{
name: "Ivo",
offset: -4,
phase: 1.5,
laneZ,
coat: 0xe3ad35,
trim: 0x31586c,
pants: 0x31586c,
skin: 0xe0aa82,
hair: 0x654a39,
tote: 0x3f7474,
umbrella: 0x31586c,
umbrellaTrim: 0xe9dfc2,
tailLength: 0.58
},
{
name: "Mina",
offset: 4,
phase: 2.8,
laneZ,
coat: 0xb54d62,
trim: 0xe4cfb3,
pants: 0x39404b,
skin: 0xbe7f5c,
hair: 0x47322c,
hood: true,
backpack: 0xd4a044,
tailLength: 0.72
},
{
name: "Sol",
offset: 12,
phase: 4.1,
laneZ,
coat: 0x655a9b,
trim: 0x8ad0b5,
pants: 0x293c45,
skin: 0x744a37,
hair: 0x211f23,
beanie: true,
backpack: 0x3d8d82,
umbrella: 0x8ad0b5,
umbrellaTrim: 0xf0e2bb,
tailLength: 0.64
}
];
const characters = characterConfigs.map(createCharacter);
// -------------------------------------------------------------------------
// Rain: one LineSegments draw call with animated vertical streaks
// -------------------------------------------------------------------------
const rainCount = 190;
const rainPositions = new Float32Array(rainCount * 6);
const rainDrops = [];
for (let i = 0; i < rainCount; i++) {
rainDrops.push({
x: -22 + Math.random() * 44,
y: Math.random() * 15,
z: -5 + Math.random() * 17,
length: 0.34 + Math.random() * 0.42,
speed: 7.5 + Math.random() * 4.5
});
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rain = new THREE.LineSegments(
rainGeometry,
new THREE.LineBasicMaterial({
color: 0xd8eff0,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
rain.frustumCulled = false;
scene.add(rain);
function updateRain(dt) {
for (let i = 0; i < rainCount; i++) {
const drop = rainDrops[i];
drop.y -= drop.speed * dt;
drop.x -= 0.34 * dt;
if (drop.y < -0.2 || drop.x < -23) {
drop.y = 14 + Math.random() * 2;
drop.x = -22 + Math.random() * 44;
}
const offset = i * 6;
rainPositions[offset] = drop.x;
rainPositions[offset + 1] = drop.y;
rainPositions[offset + 2] = drop.z;
rainPositions[offset + 3] = drop.x - 0.09;
rainPositions[offset + 4] = drop.y + drop.length;
rainPositions[offset + 5] = drop.z + 0.025;
}
rainGeometry.attributes.position.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
let paused = false;
const motionButton = document.getElementById("motionButton");
motionButton.addEventListener("click", () => {
paused = !paused;
motionButton.textContent = paused ? "Resume" : "Pause";
motionButton.setAttribute("aria-label", paused ? "Resume animation" : "Pause animation");
});
function updateCharacters(time) {
const pathStart = -18;
const pathLength = 36;
const walkSpeed = 1.35;
characters.forEach((character, index) => {
const config = characterConfigs[index];
const phase = time * 6.4 + character.phase;
// All characters share the same lane and velocity. The fixed offsets
// maintain approximately eight world units between silhouettes.
character.root.position.x =
((time * walkSpeed + config.offset - pathStart) % pathLength) +
pathStart;
character.root.position.y = Math.abs(Math.sin(phase)) * 0.035;
character.root.rotation.z = 0.025 + Math.sin(phase * 2) * 0.006;
character.legs[0].rotation.z = Math.sin(phase) * 0.50;
character.legs[1].rotation.z = -Math.sin(phase) * 0.50;
character.arms[-1].rotation.z = -Math.sin(phase) * 0.42;
character.arms[1].rotation.z = Math.sin(phase) * 0.30;
character.coatPanels[0].rotation.z =
-0.14 - Math.abs(Math.sin(phase)) * 0.07 + Math.sin(phase + 0.5) * 0.035;
character.coatPanels[1].rotation.z =
-0.14 - Math.abs(Math.sin(phase)) * 0.07 + Math.sin(phase + 1.0) * 0.035;
if (character.scarfPivot) {
character.scarfPivot.rotation.z =
-0.17 + Math.sin(time * 2.7 + character.phase) * 0.12;
}
if (character.satchel) {
character.satchel.rotation.z =
Math.sin(time * 2.0 + character.phase) * 0.025;
}
if (character.umbrella) {
// Counter-rotate the umbrella against most of the arm's swing so the
// canopy remains readable while the hand and shaft still follow it.
character.umbrella.rotation.z =
-character.arms[1].rotation.z * 0.84 +
Math.sin(time * 2.1 + character.phase) * 0.035;
character.umbrella.rotation.x =
Math.sin(time * 1.7 + character.phase) * 0.025;
}
if (character.tote) {
character.tote.rotation.z =
Math.sin(phase + 0.7) * 0.05;
}
});
}
function updateTrain(time) {
const cycle = time % 40;
if (cycle < 28) {
train.visible = true;
train.position.x = -24 + (cycle / 28) * 48;
} else {
train.visible = false;
}
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed += dt;
updateCharacters(elapsed);
updateRain(dt);
updateTrain(elapsed);
}
renderer.render(scene, camera);
}
updateCharacters(0);
updateRain(0);
updateTrain(0);
renderer.render(scene, camera);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
animate();
</script>
</body>
</html>
```