Prompt specification
Build or customize the Three.js 3D scene "Farewell before boarding" 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: Farewell before boarding
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/farewell-before-boarding-x3914
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a station farewell before departure. Animate two people greeting, exchanging a small keepsake, and separating as one boards; the gift stays with its recipient and the suitcase follows the traveler. Low-poly.
Working Three.js Starter (farewell-before-boarding-x3914):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One Last Stop — Station Farewell</title>
<style>
:root {
color-scheme: light;
--ink: #19343a;
--cream: #fffaf0;
--accent: #ee6b52;
--gold: #f2be55;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8e5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 48%, rgba(25, 52, 58, 0.09) 100%),
linear-gradient(to bottom, rgba(255,255,255,0.12), transparent 28%);
}
.header {
position: fixed;
top: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 48px);
right: clamp(20px, 4vw, 48px);
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
font-size: 11px;
line-height: 1;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
color: rgba(25, 52, 58, 0.62);
}
h1 {
margin: 0;
max-width: 520px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 5vw, 62px);
line-height: 0.96;
font-weight: 500;
letter-spacing: -0.045em;
}
.badge {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid rgba(25, 52, 58, 0.16);
border-radius: 999px;
background: rgba(255, 250, 240, 0.66);
backdrop-filter: blur(10px);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
}
.badge::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(238, 107, 82, 0.16);
}
.caption-wrap {
position: fixed;
left: 50%;
bottom: clamp(22px, 4vw, 46px);
width: min(620px, calc(100vw - 32px));
transform: translateX(-50%);
padding: 16px 18px 14px;
border: 1px solid rgba(25, 52, 58, 0.13);
border-radius: 18px;
background: rgba(255, 250, 240, 0.82);
box-shadow: 0 16px 50px rgba(25, 52, 58, 0.12);
backdrop-filter: blur(14px);
pointer-events: none;
}
.caption-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
#caption {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(16px, 2.4vw, 22px);
line-height: 1.25;
}
#replay {
flex: 0 0 auto;
border: 0;
border-radius: 999px;
padding: 10px 14px;
background: var(--ink);
color: var(--cream);
font: inherit;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.06em;
cursor: pointer;
pointer-events: auto;
transition: transform 160ms ease, background 160ms ease;
}
#replay:hover {
transform: translateY(-2px);
background: #28525a;
}
#replay:active {
transform: translateY(0);
}
.progress {
height: 3px;
margin-top: 13px;
overflow: hidden;
border-radius: 99px;
background: rgba(25, 52, 58, 0.1);
}
#progress-fill {
width: 100%;
height: 100%;
transform: scaleX(0);
transform-origin: left center;
background: linear-gradient(90deg, var(--accent), var(--gold));
}
.time {
margin-top: 7px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
color: rgba(25, 52, 58, 0.52);
}
@media (max-width: 640px) {
.badge {
display: none;
}
.caption-wrap {
padding: 14px;
}
#caption {
font-size: 17px;
}
}
</style>
</head>
<body>
<div class="vignette"></div>
<header class="header">
<div>
<div class="eyebrow">Platform 03 · Northbound</div>
<h1>One Last Stop</h1>
</div>
<div class="badge">A quiet farewell</div>
</header>
<section class="caption-wrap" aria-live="polite">
<div class="caption-row">
<p id="caption">A wave, a little longer than usual.</p>
<button id="replay" type="button">Replay</button>
</div>
<div class="progress"><div id="progress-fill"></div></div>
<div class="time" id="time-label">Scene 01 / Farewell</div>
</section>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe8e5);
scene.fog = new THREE.Fog(0xdbe8e5, 19, 38);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 80);
const cameraBase = new THREE.Vector3(6.6, 6.4, 13.8);
const cameraTarget = new THREE.Vector3(0.15, 1.05, 0);
camera.position.copy(cameraBase);
camera.lookAt(cameraTarget);
const hemi = new THREE.HemisphereLight(0xfff8e9, 0x6f8b8a, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6bd, 3.4);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbadfe2, 1.25);
fill.position.set(8, 5, -7);
scene.add(fill);
// -------------------------------------------------------------------------
// Helpers and materials
// -------------------------------------------------------------------------
const clamp = THREE.MathUtils.clamp;
function smoothstep(a, b, value) {
const t = clamp((value - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function segment(t, start, end) {
return smoothstep(start, end, t);
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function addMesh(geometry, mat, parent, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, mat, parent, x = 0, y = 0, z = 0) {
return addMesh(new THREE.BoxGeometry(w, h, d), mat, parent, x, y, z);
}
function cylinder(rt, rb, h, segments, mat, parent, x = 0, y = 0, z = 0) {
return addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat,
parent,
x,
y,
z
);
}
const palette = {
ground: material(0xb7c8c3),
platform: material(0xd8d3c7),
platformEdge: material(0xeee8dc),
yellow: material(0xf2be55),
dark: material(0x18363c),
rail: material(0x52676a, { metalness: 0.45, roughness: 0.55 }),
sleeper: material(0x78665d),
train: material(0x286e72),
trainDark: material(0x174e54),
trainCream: material(0xf3e8d2),
window: material(0x183d48, { roughness: 0.3, metalness: 0.15 }),
bench: material(0x9b6248),
metal: material(0x6c7b7a, { metalness: 0.35, roughness: 0.5 }),
redLight: material(0xe85d4a, {
emissive: 0x9f2018,
emissiveIntensity: 1.3
})
};
function createTextPanel(
lines,
width,
height,
parent,
x,
y,
z,
options = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
...options
})
);
mesh.position.set(x, y, z);
parent.add(mesh);
function draw(main, sub = "") {
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (options.background !== false) {
ctx.fillStyle = options.background || "#173b40";
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = options.color || "#fff6dc";
ctx.font = `700 ${sub ? 76 : 90}px Arial, sans-serif`;
ctx.fillText(main, 512, sub ? 94 : 128, 930);
if (sub) {
ctx.fillStyle = options.subColor || "#f2be55";
ctx.font = "700 40px Arial, sans-serif";
ctx.fillText(sub, 512, 177, 900);
}
texture.needsUpdate = true;
}
draw(...lines);
return { mesh, draw };
}
// -------------------------------------------------------------------------
// Platform, tracks, station furniture, and distant skyline
// -------------------------------------------------------------------------
box(35, 0.2, 30, palette.ground, scene, 0, -0.42, -4);
const platform = box(12.5, 0.32, 4.25, palette.platform, scene, 0, -0.16, 1.02);
platform.receiveShadow = true;
box(12.5, 0.09, 0.22, palette.yellow, scene, 0, 0.015, -0.88);
box(12.5, 0.08, 0.08, palette.trainCream, scene, 0, 0.01, -0.72);
for (let x = -5.8; x <= 5.8; x += 0.72) {
box(0.018, 0.012, 4.0, material(0xc5c0b5), scene, x, 0.007, 1.05);
}
// Tracks
for (const z of [-3.55, -4.65]) {
box(15, 0.12, 0.13, palette.rail, scene, 0, -0.2, z);
}
for (let x = -7; x <= 7; x += 0.62) {
box(0.19, 0.08, 1.55, palette.sleeper, scene, x, -0.29, -4.1);
}
// Distant low-poly buildings
const skylineMat = material(0xaec3c0);
const skylineMat2 = material(0x9db7b5);
for (let i = 0; i < 13; i++) {
const w = 0.65 + (i % 3) * 0.22;
const h = 1.2 + ((i * 7) % 5) * 0.48;
const x = -8.5 + i * 1.35;
box(w, h, 1.1, i % 2 ? skylineMat : skylineMat2, scene, x, h / 2 - 0.25, -7.1);
}
// Bench
const bench = new THREE.Group();
bench.position.set(-4.15, 0, 2.15);
scene.add(bench);
box(1.7, 0.13, 0.55, palette.bench, bench, 0, 0.52, 0);
box(1.7, 0.62, 0.12, palette.bench, bench, 0, 0.93, -0.25);
box(0.12, 0.52, 0.42, palette.metal, bench, -0.65, 0.25, 0);
box(0.12, 0.52, 0.42, palette.metal, bench, 0.65, 0.25, 0);
// Station sign and pole
cylinder(0.055, 0.07, 2.3, 8, palette.metal, scene, -3.45, 1.15, 0.15);
createTextPanel(
["PLATFORM 03"],
1.65,
0.48,
scene,
-3.45,
2.15,
0.17
);
// Departure board
const departureBoard = createTextPanel(
["BOARDING", "NORTHBOUND / 02:40"],
2.55,
0.74,
scene,
-3.35,
2.92,
0.18
);
// Platform lamp
cylinder(0.055, 0.075, 3.3, 8, palette.metal, scene, 4.45, 1.65, 1.8);
box(0.55, 0.12, 0.55, palette.dark, scene, 4.45, 3.32, 1.8);
box(0.36, 0.035, 0.36, material(0xffe4a3, {
emissive: 0xffca62,
emissiveIntensity: 1.5
}), scene, 4.45, 3.245, 1.8);
// Small planter
cylinder(0.29, 0.23, 0.42, 7, material(0xb56e50), scene, 3.45, 0.21, 2.4);
const leafMat = material(0x4f8272);
for (let i = 0; i < 6; i++) {
const leaf = addMesh(
new THREE.ConeGeometry(0.13, 0.65 + (i % 2) * 0.12, 5),
leafMat,
scene,
3.45 + Math.cos(i * 2.1) * 0.16,
0.72 + (i % 2) * 0.08,
2.4 + Math.sin(i * 2.1) * 0.16
);
leaf.rotation.z = Math.cos(i) * 0.45;
leaf.rotation.x = Math.sin(i) * 0.35;
}
// -------------------------------------------------------------------------
// Train, with an open doorway
// -------------------------------------------------------------------------
const train = new THREE.Group();
train.position.z = -2.75;
scene.add(train);
// Car body is split around the open doorway.
box(5.95, 3.1, 2.6, palette.train, train, -1.525, 1.55, 0);
box(1.85, 3.1, 2.6, palette.train, train, 3.675, 1.55, 0);
box(9.25, 0.26, 2.72, palette.trainDark, train, 0, 3.21, 0);
// Interior visible through the doorway.
box(1.3, 0.08, 2.48, palette.dark, train, 2.1, 0.04, 0);
box(1.3, 2.55, 0.08, palette.trainDark, train, 2.1, 1.32, -1.22);
// Cream belt and lower skirt.
box(5.95, 0.25, 0.055, palette.trainCream, train, -1.525, 1.26, 1.325);
box(1.85, 0.25, 0.055, palette.trainCream, train, 3.675, 1.26, 1.325);
box(5.95, 0.3, 0.055, palette.trainDark, train, -1.525, 0.22, 1.325);
box(1.85, 0.3, 0.055, palette.trainDark, train, 3.675, 0.22, 1.325);
// Windows
for (const x of [-3.7, -2.35, -1.0, 0.35, 3.65]) {
box(0.9, 0.78, 0.055, palette.window, train, x, 2.05, 1.33);
box(0.055, 0.82, 0.065, palette.trainCream, train, x - 0.47, 2.05, 1.35);
box(0.055, 0.82, 0.065, palette.trainCream, train, x + 0.47, 2.05, 1.35);
}
// Door frame and threshold.
box(0.13, 2.7, 0.16, palette.yellow, train, 1.42, 1.35, 1.34);
box(0.13, 2.7, 0.16, palette.yellow, train, 2.78, 1.35, 1.34);
box(1.48, 0.13, 0.16, palette.yellow, train, 2.1, 2.75, 1.34);
box(1.34, 0.08, 0.85, palette.metal, scene, 2.1, 0.015, -1.22);
// Sliding doors parked open.
const leftDoor = box(0.56, 2.52, 0.09, palette.trainDark, train, 1.13, 1.31, 1.36);
const rightDoor = box(0.56, 2.52, 0.09, palette.trainDark, train, 3.07, 1.31, 1.36);
box(0.39, 0.72, 0.025, palette.window, leftDoor, 0, 0.48, 0.055);
box(0.39, 0.72, 0.025, palette.window, rightDoor, 0, 0.48, 0.055);
createTextPanel(
["NORTHBOUND"],
2.0,
0.42,
train,
-0.85,
2.73,
1.36
);
// Wheels and undercarriage.
box(7.5, 0.24, 1.7, palette.dark, train, 0, 0.03, 0);
for (const x of [-3.2, -1.1, 1.1, 3.2]) {
for (const z of [-0.88, 0.88]) {
const wheel = cylinder(0.39, 0.39, 0.24, 10, palette.dark, train, x, -0.12, z);
wheel.rotation.x = Math.PI / 2;
}
}
// Front lights.
box(0.7, 0.52, 0.05, palette.dark, train, 4.59, 1.3, 0);
const trainLight = addMesh(
new THREE.SphereGeometry(0.11, 8, 5),
palette.redLight,
train,
4.63,
1.32,
0.8
);
trainLight.scale.z = 0.45;
// -------------------------------------------------------------------------
// Low-poly characters
// -------------------------------------------------------------------------
function createPerson(config) {
const root = new THREE.Group();
const coatMat = material(config.coat);
const trouserMat = material(config.trousers);
const skinMat = material(config.skin);
const hairMat = material(config.hair);
const shoeMat = material(config.shoes || 0x243b3e);
const scarfMat = material(config.scarf);
const torso = cylinder(0.31, 0.41, 0.78, 6, coatMat, root, 0, 1.34, 0);
torso.rotation.y = Math.PI / 6;
box(0.54, 0.12, 0.43, trouserMat, root, 0, 0.91, 0);
box(0.56, 0.065, 0.45, palette.dark, root, 0, 1.0, 0);
box(0.07, 0.07, 0.025, palette.yellow, root, 0, 1.0, 0.24);
cylinder(0.105, 0.12, 0.16, 6, skinMat, root, 0, 1.8, 0);
const head = new THREE.Group();
head.position.set(0, 1.99, 0);
root.add(head);
addMesh(new THREE.IcosahedronGeometry(0.255, 1), skinMat, head, 0, 0, 0);
addMesh(
new THREE.SphereGeometry(0.264, 6, 4, 0, Math.PI * 2, 0, Math.PI * 0.58),
hairMat,
head,
0,
0.035,
-0.015
);
addMesh(
new THREE.IcosahedronGeometry(0.022, 0),
palette.dark,
head,
-0.078,
0.018,
0.229
);
addMesh(
new THREE.IcosahedronGeometry(0.022, 0),
palette.dark,
head,
0.078,
0.018,
0.229
);
const nose = addMesh(
new THREE.ConeGeometry(0.035, 0.09, 5),
skinMat,
head,
0,
-0.025,
0.255
);
nose.rotation.x = Math.PI / 2;
box(0.075, 0.015, 0.018, material(0x9c5149), head, 0, -0.105, 0.237);
const scarf = addMesh(
new THREE.TorusGeometry(0.245, 0.065, 4, 8),
scarfMat,
root,
0,
1.72,
0
);
scarf.rotation.x = Math.PI / 2;
box(0.12, 0.42, 0.055, scarfMat, root, 0.1, 1.48, 0.255);
box(0.12, 0.42, 0.055, scarfMat, root, 0.1, 1.48, 0.255);
const arms = [];
const legs = [];
for (const side of [-1, 1]) {
const armPivot = new THREE.Group();
armPivot.position.set(side * 0.39, 1.56, 0.015);
root.add(armPivot);
cylinder(0.105, 0.115, 0.51, 6, coatMat, armPivot, 0, -0.255, 0);
cylinder(0.08, 0.095, 0.27, 6, coatMat, armPivot, 0, -0.59, 0);
const hand = new THREE.Group();
hand.position.set(0, -0.745, 0);
armPivot.add(hand);
addMesh(new THREE.IcosahedronGeometry(0.105, 1), skinMat, hand);
arms.push({ pivot: armPivot, hand, side });
}
for (const side of [-1, 1]) {
const legPivot = new THREE.Group();
legPivot.position.set(side * 0.16, 0.82, 0);
root.add(legPivot);
cylinder(0.105, 0.125, 0.66, 6, trouserMat, legPivot, 0, -0.33, 0);
box(0.24, 0.14, 0.39, shoeMat, legPivot, 0, -0.71, 0.075);
legs.push({ pivot: legPivot, side });
}
if (config.backpack) {
box(0.49, 0.61, 0.22, material(config.backpack), root, 0, 1.34, -0.34);
box(0.32, 0.18, 0.08, material(config.backpackAccent || 0xf2be55), root, 0, 1.18, -0.47);
}
return { root, torso, head, arms, legs };
}
const friend = createPerson({
coat: 0x49758a,
trousers: 0x314c59,
skin: 0xd79b73,
hair: 0x2e2928,
scarf: 0xf2be55,
shoes: 0x253b40
});
friend.root.scale.setScalar(0.98);
friend.root.position.set(0, 0, 1.2);
friend.root.rotation.y = -1.05;
scene.add(friend.root);
const traveler = createPerson({
coat: 0xe66f57,
trousers: 0x46555d,
skin: 0x8f5d45,
hair: 0x211f22,
scarf: 0x3d8b88,
shoes: 0x253439,
backpack: true,
backpackAccent: 0xf2be55
});
traveler.root.position.set(-1.9, 0, 1.2);
traveler.root.rotation.y = 1.05;
scene.add(traveler.root);
// -------------------------------------------------------------------------
// Keepsake: initially carried by the traveler, then left with the friend
// -------------------------------------------------------------------------
const gift = new THREE.Group();
const giftBoxMat = material(0xf0b83f);
const ribbonMat = material(0xfff1ca);
box(0.25, 0.22, 0.15, giftBoxMat, gift, 0, 0, 0);
box(0.055, 0.235, 0.165, ribbonMat, gift, 0, 0, 0);
box(0.265, 0.045, 0.165, ribbonMat, gift, 0, 0, 0);
const bowLeft = addMesh(
new THREE.TorusGeometry(0.07, 0.018, 4, 6),
ribbonMat,
gift,
-0.065,
0.13,
0
);
bowLeft.rotation.x = Math.PI / 2;
const bowRight = bowLeft.clone();
bowRight.position.x = 0.065;
gift.add(bowRight);
const travelerGiftHand = traveler.arms[0].hand;
const friendGiftHand = friend.arms[1].hand;
travelerGiftHand.add(gift);
gift.position.set(0, -0.08, 0.055);
gift.rotation.set(0, 0, 0);
let giftState = 0; // 0 carried, 1 transferring, 2 received
const giftStart = new THREE.Vector3();
const giftTarget = new THREE.Vector3();
// -------------------------------------------------------------------------
// Suitcase and flexible pull handle
// -------------------------------------------------------------------------
const suitcase = new THREE.Group();
const suitcaseMat = material(0xd99a4e);
const suitcaseDark = material(0x304b4d);
scene.add(suitcase);
box(0.57, 0.47, 0.38, suitcaseMat, suitcase, 0, 0.39, 0);
box(0.59, 0.055, 0.4, palette.yellow, suitcase, 0, 0.48, 0);
box(0.035, 0.46, 0.395, palette.trainCream, suitcase, 0, 0.39, 0);
const suitcaseHandle = new THREE.Group();
suitcaseHandle.position.set(0, 0.57, 0.12);
suitcase.add(suitcaseHandle);
cylinder(0.025, 0.025, 0.4, 6, palette.dark, suitcaseHandle, -0.17, 0.2, 0);
cylinder(0.025, 0.025, 0.4, 6, palette.dark, suitcaseHandle, 0.17, 0.2, 0);
box(0.39, 0.055, 0.055, palette.dark, suitcaseHandle, 0, 0.41, 0);
const suitcaseWheels = [];
for (const x of [-0.2, 0.2]) {
const wheel = cylinder(0.065, 0.065, 0.07, 8, palette.dark, suitcase, x, 0.09, 0.16);
wheel.rotation.z = Math.PI / 2;
suitcaseWheels.push(wheel);
}
suitcase.position.set(-2.68, 0, 1.46);
const tetherGeometry = new THREE.BufferGeometry();
tetherGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const tether = new THREE.Line(
tetherGeometry,
new THREE.LineBasicMaterial({ color: 0x354c4e })
);
tether.frustumCulled = false;
scene.add(tether);
// -------------------------------------------------------------------------
// Animation timeline
// -------------------------------------------------------------------------
const duration = 18.5;
let elapsed = 0;
let previousPhase = "";
const captionEl = document.getElementById("caption");
const progressEl = document.getElementById("progress-fill");
const timeEl = document.getElementById("time-label");
const replayButton = document.getElementById("replay");
const phases = [
{
end: 2.0,
caption: "A wave, a little longer than usual.",
label: "Scene 01 / A greeting"
},
{
end: 4.35,
caption: "One last hello on Platform 03.",
label: "Scene 02 / One last hello"
},
{
end: 6.5,
caption: "A small keepsake changes hands.",
label: "Scene 03 / A keepsake"
},
{
end: 9.0,
caption: "The gift stays with its recipient.",
label: "Scene 04 / What stays behind"
},
{
end: 12.1,
caption: "The suitcase follows its traveler.",
label: "Scene 05 / The way to the train"
},
{
end: 15.5,
caption: "One goodbye. One journey.",
label: "Scene 06 / All aboard"
},
{
end: Infinity,
caption: "Until the next stop.",
label: "Scene 07 / The next stop"
}
];
function setArm(arm, x, y, z) {
arm.pivot.rotation.set(x, y, z);
}
function resetScene() {
elapsed = 0;
previousPhase = "";
giftState = 0;
travelerGiftHand.add(gift);
gift.position.set(0, -0.08, 0.055);
gift.rotation.set(0, 0, 0);
gift.scale.set(1, 1, 1);
suitcase.position.set(-2.68, 0, 1.46);
departureBoard.draw("BOARDING", "NORTHBOUND / 02:40");
}
replayButton.addEventListener("click", resetScene);
const suitcaseTarget = new THREE.Vector3();
const suitcaseHandleWorld = new THREE.Vector3();
const travelerHandWorld = new THREE.Vector3();
function updateScene(t, dt) {
// Traveler walks toward the friend, then across the platform.
let travelerX;
if (t < 1.6) {
travelerX = -1.9;
} else if (t < 3.4) {
travelerX = THREE.MathUtils.lerp(
-1.9,
-1.35,
segment(t, 1.6, 3.4)
);
} else if (t < 7.8) {
travelerX = -1.35;
} else if (t < 10.5) {
travelerX = THREE.MathUtils.lerp(
-1.35,
2.1,
segment(t, 7.8, 10.5)
);
} else {
travelerX = 2.1;
}
let travelerZ;
if (t < 10.5) {
travelerZ = 1.2;
} else if (t < 14.2) {
travelerZ = THREE.MathUtils.lerp(
1.2,
-2.45,
segment(t, 10.5, 14.2)
);
} else {
travelerZ = -2.45;
}
traveler.root.position.x = travelerX;
traveler.root.position.z = travelerZ;
const turn = segment(t, 10.5, 11.6);
traveler.root.rotation.y = THREE.MathUtils.lerp(1.05, Math.PI, turn);
// The friend gently steps back after receiving the gift.
friend.root.position.x = THREE.MathUtils.lerp(
0,
-0.45,
segment(t, 7.8, 9.5)
);
friend.root.rotation.y = -1.05;
// Walking animation.
const walkingAcross = t > 7.8 && t < 10.5;
const walkingIntoTrain = t > 11.6 && t < 14.2;
const walking = walkingAcross || walkingIntoTrain;
const walkPhase = t * (walkingAcross ? 7.2 : 8.2);
const walkAmount = walking ? 1 : 0;
traveler.root.position.y = walking
? Math.abs(Math.sin(walkPhase)) * 0.035
: 0;
traveler.legs[0].pivot.rotation.x = Math.sin(walkPhase) * 0.48 * walkAmount;
traveler.legs[1].pivot.rotation.x = -Math.sin(walkPhase) * 0.48 * walkAmount;
friend.legs[0].pivot.rotation.x = Math.sin(t * 5.0) * 0.035 * segment(t, 7.8, 9.5);
friend.legs[1].pivot.rotation.x = -Math.sin(t * 5.0) * 0.035 * segment(t, 7.8, 9.5);
// Friend's receiving arm.
if (t < 1.7) {
setArm(
friend.arms[1],
-0.15,
0,
2.28 + Math.sin(t * 8.5) * 0.22
);
} else if (t < 3.15) {
const lower = segment(t, 1.7, 3.15);
setArm(
friend.arms[1],
THREE.MathUtils.lerp(-0.15, 0.05, lower),
0,
THREE.MathUtils.lerp(2.28, 0, lower)
);
} else if (t < 5.25) {
setArm(friend.arms[1], -1.43, 0, 0);
} else if (t < 7.55) {
const hold = segment(t, 5.25, 7.55);
setArm(
friend.arms[1],
THREE.MathUtils.lerp(-1.43, -0.7, hold),
0,
THREE.MathUtils.lerp(0, 0.32, hold)
);
} else {
setArm(
friend.arms[1],
-0.18,
0,
2.25 + Math.sin(t * 7.6) * 0.22
);
}
setArm(friend.arms[0], -0.06, 0, -0.08);
// Traveler's gift arm reaches forward, then releases the keepsake.
if (t < 3.15) {
setArm(traveler.arms[0], 0.03, 0, -0.13);
} else if (t < 5.25) {
setArm(traveler.arms[0], -1.43, 0, 0);
} else {
const lower = segment(t, 5.25, 6.6);
setArm(
traveler.arms[0],
THREE.MathUtils.lerp(-1.43, 0.02, lower),
0,
THREE.MathUtils.lerp(0, -0.13, lower)
);
}
// Traveler's other hand greets, swings while walking, and waves from the train.
if (t < 1.65) {
setArm(
traveler.arms[1],
-0.1,
0,
2.25 + Math.sin(t * 8.2) * 0.2
);
} else if (t > 14.5) {
setArm(
traveler.arms[1],
-0.1,
0,
2.15 + Math.sin(t * 7.4) * 0.22
);
} else {
setArm(
traveler.arms[1],
walking ? -Math.sin(walkPhase) * 0.3 : -0.08,
0,
0
);
}
// Small nods make the greeting feel warmer.
friend.head.rotation.x = Math.sin(t * 2.2) * 0.045;
traveler.head.rotation.x = Math.sin(t * 2.2 + 0.7) * 0.04;
// Keepake transfer. It is physically reparented to the friend's hand.
if (giftState === 0 && t >= 4.35) {
travelerGiftHand.getWorldPosition(giftStart);
scene.attach(gift);
gift.position.copy(giftStart);
giftState = 1;
}
if (giftState === 1) {
friendGiftHand.getWorldPosition(giftTarget);
giftTarget.y -= 0.08;
const transfer = segment(t, 4.35, 5.25);
gift.position.lerpVectors(giftStart, giftTarget, transfer);
gift.rotation.y = transfer * 0.45;
if (t >= 5.25) {
friendGiftHand.attach(gift);
giftState = 2;
}
}
// Suitcase target rotates from behind the traveler to behind their back.
const offsetX = THREE.MathUtils.lerp(-0.78, 0, turn);
const offsetZ = THREE.MathUtils.lerp(0.25, 0.72, turn);
suitcaseTarget.set(
traveler.root.position.x + offsetX,
0,
traveler.root.position.z + offsetZ
);
const follow = 1 - Math.exp(-dt * 6.2);
suitcase.position.lerp(suitcaseTarget, follow);
suitcase.position.y = 0.015;
const rolling = walking ? Math.sin(walkPhase) * 0.18 : 0;
suitcaseWheels.forEach(wheel => {
wheel.rotation.x += rolling;
});
// Flexible tether from the traveler's hand to the suitcase handle.
traveler.arms[1].hand.getWorldPosition(travelerHandWorld);
suitcaseHandle.localToWorld(suitcaseHandleWorld.set(0, 0.41, 0));
const tetherPositions = tetherGeometry.attributes.position.array;
tetherPositions[0] = travelerHandWorld.x;
tetherPositions[1] = travelerHandWorld.y;
tetherPositions[2] = travelerHandWorld.z;
tetherPositions[3] = suitcaseHandleWorld.x;
tetherPositions[4] = suitcaseHandleWorld.y;
tetherPositions[5] = suitcaseHandleWorld.z;
tetherGeometry.attributes.position.needsUpdate = true;
// Doorway lights gently blink near departure.
const blink = t > 13.7 ? (Math.sin(t * 6.5) > 0 ? 1.8 : 0.45) : 1.25;
palette.redLight.emissiveIntensity = blink;
if (t > 14.7) {
departureBoard.draw("DEPARTING SOON", "THANK YOU / GOODBYE");
} else if (t > 9.4) {
departureBoard.draw("BOARDING", "NORTHBOUND / 02:40");
}
// Caption and progress.
const phase = phases.find(p => t <= p.end);
if (phase.label !== previousPhase) {
previousPhase = phase.label;
captionEl.textContent = phase.caption;
timeEl.textContent = phase.label;
}
progressEl.style.transform = `scaleX(${clamp(t / duration, 0, 1)})`;
}
// -------------------------------------------------------------------------
// Subtle custom camera parallax; no external controls or addons
// -------------------------------------------------------------------------
const pointer = new THREE.Vector2();
const pointerTarget = new THREE.Vector2();
window.addEventListener("pointermove", event => {
pointerTarget.x = (event.clientX / window.innerWidth - 0.5) * 2;
pointerTarget.y = (event.clientY / window.innerHeight - 0.5) * 2;
});
window.addEventListener("pointerleave", () => {
pointerTarget.set(0, 0);
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(7.3, 13.2 / aspect);
const viewWidth = viewHeight * aspect;
camera.left = -viewWidth / 2;
camera.right = viewWidth / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed = Math.min(duration, elapsed + dt);
updateScene(elapsed, dt);
pointer.lerp(pointerTarget, 1 - Math.exp(-dt * 3.5));
camera.position.set(
cameraBase.x + pointer.x * 0.28,
cameraBase.y - pointer.y * 0.16,
cameraBase.z
);
camera.lookAt(cameraTarget);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```