Prompt specification
Build or customize the Three.js 3D scene "Small-town station departure story" 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: Small-town station departure story
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/small-town-station-departure-story-x3915
Scene Description Prompt:
Use Three.js from cdnjs to compose platform, bench, train doorway, and waiting room; a farewell sequence ends with the train leaving while the remaining person stays behind the platform boundary. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (small-town-station-departure-story-x3915):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#c7dce2" />
<title>One More Stop — A Voxel Farewell</title>
<style>
:root {
--ink: #21313a;
--paper: rgba(250, 247, 235, 0.92);
--accent: #efb84d;
--teal: #2e8587;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c7dce2;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 17px 19px 18px;
border: 1px solid rgba(33, 49, 58, 0.16);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 12px 40px rgba(33, 49, 58, 0.14);
backdrop-filter: blur(10px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 10px;
height: 10px;
background: var(--accent);
box-shadow: 3px 3px 0 rgba(33, 49, 58, 0.12);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.06em;
text-transform: uppercase;
}
.subtitle {
margin: 9px 0 0;
color: #5d6c70;
font-size: 12px;
line-height: 1.5;
}
.help {
position: absolute;
top: 27px;
right: 27px;
padding: 9px 12px;
border-radius: 3px;
background: rgba(250, 247, 235, 0.74);
color: #516168;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.caption {
position: absolute;
left: 24px;
bottom: 24px;
width: min(520px, calc(100vw - 48px));
padding: 15px 17px 14px;
border-left: 5px solid var(--accent);
background: var(--paper);
box-shadow: 0 12px 40px rgba(33, 49, 58, 0.14);
backdrop-filter: blur(10px);
}
.phase-label {
margin-bottom: 6px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#phase-text {
min-height: 34px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(16px, 2vw, 21px);
line-height: 1.25;
}
.progress {
width: 100%;
height: 3px;
margin-top: 13px;
overflow: hidden;
background: rgba(33, 49, 58, 0.12);
}
.progress > span {
display: block;
width: 100%;
height: 100%;
transform: scaleX(0);
transform-origin: left center;
background: var(--teal);
}
button {
position: absolute;
right: 24px;
bottom: 24px;
pointer-events: auto;
border: 0;
border-radius: 3px;
padding: 13px 18px;
background: var(--ink);
color: #fffaf0;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 8px 25px rgba(33, 49, 58, 0.22);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: var(--teal);
transform: translateY(-2px);
}
button:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #c7dce2;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.ready {
opacity: 0;
pointer-events: none;
}
.loading-block {
width: 18px;
height: 18px;
margin: 0 auto 14px;
background: var(--accent);
animation: pulse 900ms steps(2, end) infinite;
}
@keyframes pulse {
50% {
transform: translateX(8px);
background: var(--teal);
}
}
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
.help {
display: none;
}
.caption {
left: 14px;
bottom: 14px;
width: calc(100vw - 116px);
}
button {
right: 14px;
bottom: 14px;
padding: 13px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="A voxel train platform farewell scene"></canvas>
<div class="overlay">
<section class="title-card">
<div class="eyebrow">Platform 04 · 18:42</div>
<h1>One More Stop</h1>
<p class="subtitle">
A small departure, a long look, and one person staying behind.
</p>
</section>
<div class="help">Drag to orbit · Scroll to zoom</div>
<section class="caption">
<div id="phase-label" class="phase-label">Chapter 01</div>
<div id="phase-text">The train waits at the platform.</div>
<div class="progress"><span id="progress-fill"></span></div>
</section>
<button id="replay" type="button">Replay</button>
</div>
<div id="loading">
<div>
<div class="loading-block"></div>
Building the platform
</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 lighting
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc7dce2);
scene.fog = new THREE.Fog(0xc7dce2, 43, 82);
const camera = new THREE.OrthographicCamera(-20, 20, 12, -12, 0.1, 120);
const cameraTarget = new THREE.Vector3(0, 1.6, 4.2);
const cameraRadius = 36;
let azimuth = 0.54;
let polar = 1.02;
let viewSize = 21.8;
scene.add(new THREE.HemisphereLight(0xf9fcff, 0x59656a, 2.25));
const sun = new THREE.DirectionalLight(0xfff1d5, 3.1);
sun.position.set(-13, 26, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00045;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7dce7, 1.1);
fill.position.set(18, 12, -15);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and voxel construction helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
ground: material(0x52616a),
ballast: material(0x39464e),
sleeper: material(0x66594d),
rail: material(0x8d989c, { metalness: 0.45, roughness: 0.42 }),
curb: material(0x46545b),
platformBase: material(0x7d8584),
tileA: material(0xb5b4a9),
tileB: material(0xc2bfb1),
tileC: material(0xa9aea7),
yellow: material(0xf0b844),
cream: material(0xf1ead5),
white: material(0xf8f4e7),
teal: material(0x347f83),
tealDark: material(0x245b61),
navy: material(0x263f4a),
glass: material(0x77aeb9, {
roughness: 0.25,
metalness: 0.12,
emissive: 0x173a45,
emissiveIntensity: 0.22
}),
darkGlass: material(0x294b58, {
roughness: 0.22,
metalness: 0.15,
emissive: 0x112e38,
emissiveIntensity: 0.18
}),
black: material(0x202a30),
wheel: material(0x22292d),
metal: material(0x7e8b8e, { metalness: 0.5, roughness: 0.42 }),
wood: material(0x9d6f4f),
woodLight: material(0xc58c5b),
shelter: material(0x668d91),
shelterRoof: material(0x2d5960),
lamp: material(0xffe3a0, {
emissive: 0xffca62,
emissiveIntensity: 1.15
}),
suitcase: material(0xb96248),
suitcaseHandle: material(0x3f4547),
buildingA: material(0x81979b),
buildingB: material(0x9eaaa5),
buildingC: material(0x72878e),
tree: material(0x5f7d69),
treeDark: material(0x456356)
};
function box(parent, w, h, d, x, y, z, mat, cast = true, receive = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function textSprite(text, options = {}) {
const {
foreground = "#f8f4e7",
background = "#245b61",
width = 512,
height = 128
} = options;
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = "rgba(255,255,255,0.18)";
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, width - 16, height - 16);
ctx.fillStyle = foreground;
ctx.font = `800 ${Math.floor(height * 0.43)}px monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 3);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(options.scaleX ?? 4.2, options.scaleY ?? 1.05, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Ground, rails, and platform
// -------------------------------------------------------------------------
box(scene, 56, 0.55, 31, 0, -0.72, 1, M.ground, false, true);
box(scene, 47, 0.32, 5.1, 0, -0.26, 2.05, M.ballast, false, true);
for (let x = -23; x <= 23; x += 1.3) {
box(scene, 0.32, 0.18, 4.55, x, -0.04, 2.05, M.sleeper, false, true);
}
box(scene, 47, 0.16, 0.16, 0, 0.11, 1.55, M.rail, false, true);
box(scene, 47, 0.16, 0.16, 0, 0.11, 3.55, M.rail, false, true);
box(scene, 36, 0.68, 7.5, 0, -0.34, 8.05, M.platformBase);
box(scene, 36.1, 0.14, 0.28, 0, -0.05, 4.3, M.curb);
const tileMaterials = [M.tileA, M.tileB, M.tileC];
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 24; col++) {
const x = -17.25 + col * 1.5;
const z = 5.12 + row * 1.67;
const mat = tileMaterials[(row + col) % tileMaterials.length];
box(
scene,
1.46,
0.065,
1.62,
x,
0.035,
z,
mat,
false,
true
);
}
}
// The yellow block line is the platform boundary. The remaining traveler
// never crosses beyond its platform-facing side.
for (let x = -17.55; x <= 17.55; x += 0.72) {
box(scene, 0.55, 0.085, 0.43, x, 0.105, 4.63, M.yellow, false, true);
}
// Small tactile blocks behind the yellow line.
for (let x = -17; x <= 17; x += 0.48) {
box(scene, 0.12, 0.07, 0.12, x, 0.095, 5.02, M.curb, false, true);
}
// -------------------------------------------------------------------------
// Waiting room
// -------------------------------------------------------------------------
const waitingRoom = new THREE.Group();
waitingRoom.position.set(-11, 0, 8.55);
scene.add(waitingRoom);
box(waitingRoom, 7.4, 0.16, 4.15, 0, 0.1, 0, M.shelter);
box(waitingRoom, 7.4, 2.75, 0.22, 0, 1.52, 1.95, M.shelter);
box(waitingRoom, 0.22, 2.75, 2.35, -3.58, 1.52, 0.7, M.shelter);
box(waitingRoom, 0.22, 2.75, 2.35, 3.58, 1.52, 0.7, M.shelter);
box(waitingRoom, 7.8, 0.28, 4.55, 0, 3.03, -0.05, M.shelterRoof);
for (const x of [-3.55, 3.55]) {
box(waitingRoom, 0.32, 2.8, 0.32, x, 1.48, -1.95, M.tealDark);
box(waitingRoom, 0.42, 0.22, 0.42, x, 0.22, -1.95, M.tealDark);
}
// Back-wall window blocks.
for (const x of [-2.25, -0.75, 0.75, 2.25]) {
box(waitingRoom, 1.2, 1.15, 0.08, x, 1.82, 1.8, M.glass, false, false);
box(waitingRoom, 0.08, 1.15, 0.1, x, 1.82, 1.72, M.tealDark, false, false);
}
// Bench inside the waiting room.
box(waitingRoom, 4.4, 0.18, 0.7, 0, 0.72, 1.05, M.woodLight);
box(waitingRoom, 4.4, 0.75, 0.16, 0, 1.27, 1.42, M.wood);
for (const x of [-1.7, 1.7]) {
box(waitingRoom, 0.2, 0.68, 0.58, x, 0.36, 1.05, M.navy);
}
const waitingSign = textSprite("WAITING ROOM");
waitingSign.position.set(-11, 3.72, 6.3);
scene.add(waitingSign);
// -------------------------------------------------------------------------
// Platform bench, lamps, and signs
// -------------------------------------------------------------------------
function makeBench(x, z, scale = 1) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.scale.setScalar(scale);
scene.add(bench);
for (let i = 0; i < 4; i++) {
box(bench, 5, 0.16, 0.19, 0, 0.73, -0.27 + i * 0.22, M.woodLight);
}
for (let i = 0; i < 3; i++) {
box(bench, 5, 0.17, 0.18, 0, 1.13 + i * 0.26, 0.48, M.wood);
}
for (const side of [-1.9, 1.9]) {
box(bench, 0.18, 0.73, 0.18, side, 0.37, 0, M.navy);
box(bench, 0.18, 1.1, 0.18, side, 1.0, 0.48, M.navy);
box(bench, 0.2, 0.14, 0.8, side, 0.72, 0.05, M.navy);
}
return bench;
}
makeBench(9.4, 8.25);
function makeLamp(x, z) {
box(scene, 0.23, 4.5, 0.23, x, 2.25, z, M.navy);
box(scene, 1.2, 0.18, 0.25, x, 4.48, z, M.navy);
box(scene, 0.62, 0.25, 0.5, x, 4.32, z, M.lamp, false, false);
box(scene, 0.5, 0.16, 0.42, x, 0.1, z, M.navy);
}
makeLamp(-3.1, 10.9);
makeLamp(14.3, 10.8);
const platformSign = textSprite("PLATFORM 04", {
background: "#263f4a",
scaleX: 4.6,
scaleY: 1.15
});
platformSign.position.set(14.1, 4.15, 10.7);
scene.add(platformSign);
// -------------------------------------------------------------------------
// Voxel train
// -------------------------------------------------------------------------
const train = new THREE.Group();
train.position.z = 2.55;
scene.add(train);
const wheelMeshes = [];
const carCenters = [-11, 0, 11];
for (const carX of carCenters) {
box(train, 10.6, 2.9, 2.4, carX, 2.05, 0, M.cream);
box(train, 10.85, 0.26, 2.55, carX, 3.64, 0, M.navy);
box(train, 10.72, 0.42, 2.48, carX, 0.78, 0, M.tealDark);
// Roof equipment.
box(train, 2.1, 0.22, 1.35, carX - 2.1, 3.88, 0, M.tealDark);
box(train, 1.25, 0.2, 1.1, carX + 2.5, 3.88, 0, M.metal);
// Bogies and square voxel wheels.
for (const bogieX of [carX - 3.4, carX + 3.4]) {
box(train, 2.1, 0.36, 1.75, bogieX, 0.49, 0, M.black);
for (const side of [-1, 1]) {
const wheel = box(
train,
0.68,
0.68,
0.3,
bogieX,
0.32,
side * 0.96,
M.wheel
);
wheelMeshes.push(wheel);
const hub = box(
train,
0.22,
0.22,
0.34,
bogieX,
0.32,
side * 0.97,
M.metal
);
hub.rotation.z = Math.PI / 4;
}
}
const windowOffsets = [-4.15, -2.2, 2.2, 4.15];
for (const offset of windowOffsets) {
const wx = carX + offset;
// Near-side window.
box(train, 1.55, 1.12, 0.08, wx, 2.63, 1.235, M.navy, false, false);
box(train, 1.37, 0.94, 0.09, wx, 2.63, 1.285, M.glass, false, false);
// Far-side window, kept simple but visible from wider orbit angles.
box(train, 1.45, 1.02, 0.07, wx, 2.63, -1.235, M.darkGlass, false, false);
}
if (carX !== 0) {
box(train, 10.1, 0.18, 0.07, carX, 1.26, 1.245, M.yellow, false, false);
} else {
// Split the stripe around the central doorway.
box(train, 4.25, 0.18, 0.07, -3.15, 1.26, 1.245, M.yellow, false, false);
box(train, 4.25, 0.18, 0.07, 3.15, 1.26, 1.245, M.yellow, false, false);
}
}
// Couplings between cars.
for (const x of [-5.5, 5.5]) {
box(train, 1.0, 0.35, 1.55, x, 1.0, 0, M.black);
box(train, 0.55, 2.25, 1.9, x, 2.05, 0, M.navy);
}
// Central doorway and dark interior.
box(train, 1.62, 2.52, 0.12, 0, 1.86, 1.24, M.black, false, false);
box(train, 1.58, 0.14, 1.9, 0, 0.64, 0.1, M.tealDark);
box(train, 1.62, 0.13, 0.16, 0, 0.61, 1.5, M.yellow);
box(train, 0.16, 2.6, 0.17, -0.86, 1.85, 1.35, M.tealDark);
box(train, 0.16, 2.6, 0.17, 0.86, 1.85, 1.35, M.tealDark);
box(train, 1.88, 0.16, 0.17, 0, 3.13, 1.35, M.tealDark);
function makeDoorPanel(side) {
const panel = new THREE.Group();
panel.position.set(side * 0.39, 1.86, 1.39);
train.add(panel);
box(panel, 0.74, 2.34, 0.12, 0, 0, 0, M.white);
box(panel, 0.5, 0.76, 0.06, 0, 0.48, 0.075, M.darkGlass, false, false);
box(panel, 0.57, 0.08, 0.08, 0, 0.48, 0.11, M.teal, false, false);
box(panel, 0.1, 0.12, 0.08, -side * 0.22, -0.2, 0.1, M.tealDark, false, false);
return panel;
}
const leftDoor = makeDoorPanel(-1);
const rightDoor = makeDoorPanel(1);
// Front cab face and block lights.
box(train, 0.12, 1.28, 1.75, 16.36, 2.68, 0, M.darkGlass, false, false);
box(train, 0.14, 0.28, 0.35, 16.44, 1.23, -0.72, M.lamp, false, false);
box(train, 0.14, 0.28, 0.35, 16.44, 1.23, 0.72, M.lamp, false, false);
// -------------------------------------------------------------------------
// Voxel people
// -------------------------------------------------------------------------
function makePerson({
shirt,
pants,
skin,
hair,
accent = M.white
}) {
const root = new THREE.Group();
const leftLeg = new THREE.Group();
leftLeg.position.set(-0.18, 0.73, 0);
root.add(leftLeg);
box(leftLeg, 0.27, 0.7, 0.29, 0, -0.35, 0, pants);
box(leftLeg, 0.3, 0.15, 0.4, 0, -0.65, 0.05, M.black);
const rightLeg = new THREE.Group();
rightLeg.position.set(0.18, 0.73, 0);
root.add(rightLeg);
box(rightLeg, 0.27, 0.7, 0.29, 0, -0.35, 0, pants);
box(rightLeg, 0.3, 0.15, 0.4, 0, -0.65, 0.05, M.black);
box(root, 0.68, 0.72, 0.38, 0, 1.06, 0, shirt);
box(root, 0.72, 0.16, 0.42, 0, 0.75, 0, accent);
const leftArm = new THREE.Group();
leftArm.position.set(-0.46, 1.34, 0);
root.add(leftArm);
box(leftArm, 0.2, 0.62, 0.22, 0, -0.27, 0, shirt);
box(leftArm, 0.21, 0.18, 0.23, 0, -0.62, 0, skin);
const rightArm = new THREE.Group();
rightArm.position.set(0.46, 1.34, 0);
root.add(rightArm);
box(rightArm, 0.2, 0.62, 0.22, 0, -0.27, 0, shirt);
box(rightArm, 0.21, 0.18, 0.23, 0, -0.62, 0, skin);
const head = new THREE.Group();
head.position.set(0, 1.64, 0);
root.add(head);
box(head, 0.5, 0.48, 0.48, 0, 0, 0, skin);
box(head, 0.53, 0.16, 0.51, 0, 0.25, -0.01, hair);
box(head, 0.13, 0.12, 0.07, 0, 0.25, 0.24, hair);
box(head, 0.065, 0.065, 0.035, -0.11, 0.04, 0.253, M.black, false, false);
box(head, 0.065, 0.065, 0.035, 0.11, 0.04, 0.253, M.black, false, false);
return {
root,
head,
leftArm,
rightArm,
leftLeg,
rightLeg
};
}
const traveler = makePerson({
shirt: M.teal,
pants: M.navy,
skin: material(0xd9a47e),
hair: material(0x49362d),
accent: M.yellow
});
const stayer = makePerson({
shirt: material(0xc96b59),
pants: material(0x405761),
skin: material(0xa97050),
hair: material(0x282525),
accent: M.cream
});
scene.add(traveler.root);
scene.add(stayer.root);
// A little suitcase for the departing traveler.
const suitcase = new THREE.Group();
suitcase.position.set(-0.58, 0.28, 0.16);
traveler.root.add(suitcase);
box(suitcase, 0.42, 0.52, 0.3, 0, 0, 0, M.suitcase);
box(suitcase, 0.07, 0.4, 0.07, 0, 0.42, 0, M.suitcaseHandle);
box(suitcase, 0.28, 0.07, 0.07, 0, 0.62, 0, M.suitcaseHandle);
box(suitcase, 0.3, 0.08, 0.33, 0, 0.05, 0, M.yellow, false, false);
// -------------------------------------------------------------------------
// Background city blocks and planters
// -------------------------------------------------------------------------
const buildings = [
[-19, 4.7, -9, 4.2, 9.4, 4.5, M.buildingA],
[-13.5, 2.6, -10, 3.1, 5.2, 3.4, M.buildingB],
[-8.5, 4.2, -9.5, 4.8, 8.4, 4.0, M.buildingC],
[-3, 2.2, -11, 3.5, 4.4, 3.2, M.buildingB],
[3.2, 3.8, -10, 4.6, 7.6, 4.5, M.buildingA],
[9, 2.5, -10.5, 4.2, 5, 3.6, M.buildingC],
[14.5, 4.5, -9.5, 4.4, 9, 4.8, M.buildingB],
[20, 3.1, -10, 4.3, 6.2, 4.1, M.buildingA]
];
for (const [x, y, z, w, h, d, mat] of buildings) {
box(scene, w, h, d, x, y - 0.05, z, mat, false, true);
box(scene, w + 0.3, 0.25, d + 0.3, x, y + h / 2 - 0.05, z, M.navy, false, true);
}
function makePlanter(x, z) {
box(scene, 2.1, 0.55, 1.4, x, 0.27, z, M.curb);
box(scene, 0.38, 1.5, 0.38, x, 1.1, z, M.wood);
box(scene, 1.65, 1.15, 1.35, x, 2.25, z, M.tree);
box(scene, 1.1, 0.9, 1.0, x + 0.25, 2.85, z, M.treeDark);
}
makePlanter(-18.3, 9.7);
makePlanter(18.5, 9.6);
// -------------------------------------------------------------------------
// Farewell animation
// -------------------------------------------------------------------------
const phaseLabel = document.querySelector("#phase-label");
const phaseText = document.querySelector("#phase-text");
const progressFill = document.querySelector("#progress-fill");
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
const lerp = (a, b, t) => a + (b - a) * t;
const smooth = (v) => {
v = clamp(v, 0, 1);
return v * v * (3 - 2 * v);
};
let elapsed = 0;
let previousTime = performance.now();
let previousChapter = "";
function setChapter(chapter, text) {
if (chapter === previousChapter) return;
previousChapter = chapter;
phaseLabel.textContent = chapter;
phaseText.textContent = text;
}
function updateSequence(t) {
// Doors: open, remain open for the farewell and boarding, then close.
let doorOpen;
if (t < 1.45) {
doorOpen = smooth(t / 1.45);
} else if (t < 7.8) {
doorOpen = 1;
} else if (t < 9.2) {
doorOpen = 1 - smooth((t - 7.8) / 1.4);
} else {
doorOpen = 0;
}
leftDoor.position.x = -(0.39 + doorOpen * 0.74);
rightDoor.position.x = 0.39 + doorOpen * 0.74;
// The remaining passenger stays well behind the yellow platform line.
const approach = smooth((t - 9.2) / 3.5);
stayer.root.position.set(1.2 + approach * 0.1, 0.08, 6.78 - approach * 0.3);
stayer.root.rotation.y = -Math.PI / 2 + Math.sin(t * 1.4) * 0.025;
stayer.leftArm.rotation.set(0, 0, -0.08);
stayer.rightArm.rotation.set(0, 0, 0.15);
stayer.leftLeg.rotation.set(0, 0, 0);
stayer.rightLeg.rotation.set(0, 0, 0);
if (t > 1.2) {
const waveStrength = t < 9.2 ? 0.62 : 1.0;
stayer.rightArm.rotation.z =
0.15 + Math.sin(t * (t < 9.2 ? 7.2 : 8.2)) * waveStrength;
}
stayer.head.rotation.y = Math.sin(t * 0.9) * 0.035;
traveler.leftArm.rotation.set(0, 0, 0);
traveler.rightArm.rotation.set(0, 0, 0);
traveler.leftLeg.rotation.set(0, 0, 0);
traveler.rightLeg.rotation.set(0, 0, 0);
if (t < 4.5) {
// The two travelers exchange a final wave.
traveler.root.visible = true;
traveler.root.position.set(-4.0, 0.08, 7.08);
traveler.root.rotation.y = Math.PI / 2 + Math.sin(t * 1.5) * 0.025;
if (t > 1.2) {
traveler.leftArm.rotation.z =
-0.15 - Math.sin(t * 7.1) * 0.72;
}
suitcase.rotation.z = Math.sin(t * 1.3) * 0.025;
} else if (t < 6.8) {
// Walk diagonally to the doorway.
const u = smooth((t - 4.5) / 2.3);
traveler.root.position.set(
lerp(-4.0, 0.0, u),
0.08,
lerp(7.08, 3.68, u)
);
traveler.root.rotation.y = lerp(Math.PI / 2, Math.PI, smooth(u));
const step = Math.sin(t * 12.5);
traveler.leftLeg.rotation.x = step * 0.52;
traveler.rightLeg.rotation.x = -step * 0.52;
traveler.leftArm.rotation.x = -step * 0.34;
traveler.rightArm.rotation.x = step * 0.34;
suitcase.rotation.x = Math.sin(t * 12.5 + 0.8) * 0.05;
} else if (t < 7.8) {
// Final step through the train doorway.
const u = smooth((t - 6.8) / 1.0);
traveler.root.position.set(0, 0.08, lerp(3.68, 3.02, u));
traveler.root.rotation.y = Math.PI;
const step = Math.sin(t * 13.5);
traveler.leftLeg.rotation.x = step * 0.42;
traveler.rightLeg.rotation.x = -step * 0.42;
} else {
traveler.root.visible = false;
}
// The train departs only after the doorway is closed.
const departure = smooth((t - 9.2) / 7.3);
train.position.x = departure * 40;
for (const wheel of wheelMeshes) {
wheel.rotation.z = -train.position.x / 0.34;
}
progressFill.style.transform = `scaleX(${clamp(t / 16.5, 0, 1)})`;
if (t < 1.45) {
setChapter("Chapter 01", "The doors slide open at Platform 04.");
} else if (t < 4.5) {
setChapter("Chapter 02", "One last wave between the two travelers.");
} else if (t < 6.8) {
setChapter("Chapter 03", "The traveler turns and walks toward the train.");
} else if (t < 7.8) {
setChapter("Chapter 04", "A final step through the open doorway.");
} else if (t < 9.2) {
setChapter("Chapter 05", "The doors close between them.");
} else if (t < 16.5) {
setChapter("Chapter 06", "The train pulls away along the tracks.");
} else {
setChapter(
"Chapter 07",
"One person remains — safely behind the yellow platform line."
);
}
}
// -------------------------------------------------------------------------
// Direct camera controls, implemented without external addons
// -------------------------------------------------------------------------
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
const effectiveHeight = viewSize * Math.max(1, 1.32 / aspect);
camera.left = (-effectiveHeight * aspect) / 2;
camera.right = (effectiveHeight * aspect) / 2;
camera.top = effectiveHeight / 2;
camera.bottom = -effectiveHeight / 2;
camera.updateProjectionMatrix();
}
function updateCamera() {
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(polar) * Math.sin(azimuth),
cameraTarget.y + cameraRadius * Math.cos(polar),
cameraTarget.z + cameraRadius * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateProjection();
}
window.addEventListener("resize", resize);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth -= dx * 0.006;
polar = clamp(polar + dy * 0.005, 0.5, 1.38);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
viewSize = clamp(viewSize + event.deltaY * 0.012, 14, 31);
updateProjection();
},
{ passive: false }
);
document.querySelector("#replay").addEventListener("click", () => {
elapsed = 0;
previousTime = performance.now();
previousChapter = "";
train.position.x = 0;
traveler.root.visible = true;
updateSequence(0);
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
resize();
updateCamera();
updateSequence(0);
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
elapsed += dt;
updateSequence(elapsed);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame((now) => {
previousTime = now;
document.querySelector("#loading").classList.add("ready");
animate(now);
});
</script>
</body>
</html>
```