Prompt specification
Build or customize the Three.js 3D scene "Event Tokens on a Time Rail" 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: Event Tokens on a Time Rail
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/event-tokens-on-a-time-rail-x3573
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: event tokens on a time rail. Arrange arrival, service, and departure tokens along a marked timeline. Keep event timestamps distinct from animation duration so playback speed cannot change their order. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (event-tokens-on-a-time-rail-x3573):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Order Rail — Voxel Event Timeline</title>
<style>
:root {
color-scheme: dark;
--bg: #06101a;
--panel: rgba(7, 17, 29, 0.86);
--panel-solid: #091725;
--line: rgba(132, 177, 210, 0.22);
--text: #e8f5ff;
--muted: #8299ad;
--cyan: #45dcff;
--amber: #ffd166;
--green: #70efaa;
--orange: #ff9a52;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #10283a 0, #07131f 42%, #040a11 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
position: absolute;
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--line);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.32),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.eyebrow {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#brand {
top: 22px;
left: 22px;
width: 318px;
padding: 19px 20px 17px;
}
.brand-row {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 37px;
height: 37px;
flex: 0 0 auto;
border: 1px solid rgba(69, 220, 255, 0.55);
background: rgba(69, 220, 255, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
left: 7px;
right: 7px;
height: 4px;
background: var(--cyan);
box-shadow: 0 0 14px rgba(69, 220, 255, 0.65);
}
.brand-mark::before {
top: 10px;
}
.brand-mark::after {
bottom: 9px;
width: 14px;
right: auto;
}
h1 {
margin: 2px 0 0;
font-size: 21px;
line-height: 1;
letter-spacing: 0.055em;
font-weight: 780;
}
.brand-subtitle {
margin: 10px 0 16px;
color: #9eb2c3;
font-size: 12px;
line-height: 1.55;
}
.legend {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.legend-item {
min-width: 0;
}
.legend-color {
display: block;
width: 22px;
height: 5px;
margin-bottom: 7px;
background: currentColor;
box-shadow: 0 0 14px currentColor;
}
.legend-name {
display: block;
color: #dbeaf5;
font-size: 10px;
font-weight: 760;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-time {
display: block;
margin-top: 3px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
}
#controls {
top: 22px;
right: 22px;
width: 302px;
padding: 17px;
}
.clock-row {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
}
#clock {
display: block;
margin-top: 4px;
color: #f5fbff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 34px;
line-height: 1;
letter-spacing: -0.055em;
text-shadow: 0 0 22px rgba(69, 220, 255, 0.18);
}
.order-badge {
margin-bottom: 1px;
padding: 6px 8px;
color: var(--green);
border: 1px solid rgba(112, 239, 170, 0.24);
background: rgba(112, 239, 170, 0.055);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
}
.progress {
position: relative;
height: 4px;
margin: 16px 0 7px;
overflow: hidden;
background: #172636;
}
#progressFill {
position: absolute;
inset: 0 auto 0 0;
width: 0%;
background: linear-gradient(90deg, var(--cyan), #b2f3ff);
box-shadow: 0 0 13px rgba(69, 220, 255, 0.7);
}
.control-meta {
display: flex;
justify-content: space-between;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
letter-spacing: 0.04em;
}
#seek {
width: 100%;
height: 18px;
margin: 11px 0 5px;
accent-color: var(--cyan);
cursor: ew-resize;
}
.button-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 11px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 0;
color: var(--text);
background: #102235;
font: inherit;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(69, 220, 255, 0.48);
background: #152d43;
}
button:active {
transform: translateY(1px);
}
#playBtn {
min-height: 39px;
padding: 0 14px;
color: #041019;
border-color: var(--cyan);
background: var(--cyan);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#resetBtn {
width: 42px;
font-size: 18px;
}
.speed-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.speed-buttons {
display: flex;
gap: 4px;
}
.speed-buttons button {
min-width: 46px;
padding: 7px 8px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 700;
}
.speed-buttons button.active {
color: var(--cyan);
border-color: rgba(69, 220, 255, 0.5);
background: rgba(69, 220, 255, 0.1);
}
#selection {
left: 22px;
bottom: 22px;
width: 330px;
min-height: 148px;
padding: 17px 18px;
}
.selection-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
#selectedKind {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#selectedTime {
color: #a8bbca;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
}
#selectedTitle {
margin: 12px 0 7px;
font-size: 18px;
line-height: 1.2;
letter-spacing: 0.015em;
}
#selectedMeta {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
#technicalNote {
position: absolute;
right: 22px;
bottom: 22px;
max-width: 340px;
padding: 11px 13px;
color: #8ea4b6;
border-right: 2px solid rgba(255, 154, 82, 0.7);
background: rgba(6, 15, 25, 0.64);
font-size: 10px;
line-height: 1.55;
text-align: right;
}
#technicalNote strong {
color: #d5e2ed;
font-weight: 650;
}
#help {
position: absolute;
left: 50%;
bottom: 23px;
transform: translateX(-50%);
color: rgba(191, 213, 229, 0.56);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
letter-spacing: 0.04em;
white-space: nowrap;
}
@media (max-width: 900px) {
#brand {
width: 285px;
}
#controls {
width: 270px;
}
#technicalNote {
display: none;
}
#help {
right: 22px;
left: auto;
transform: none;
}
}
@media (max-width: 680px) {
#brand {
top: 12px;
left: 12px;
width: calc(100% - 24px);
padding: 14px;
}
.brand-subtitle,
.legend-time {
display: none;
}
.legend {
padding-top: 10px;
}
#controls {
top: auto;
right: 12px;
bottom: 12px;
width: calc(100% - 24px);
padding: 13px;
}
#selection {
display: none;
}
#help {
display: none;
}
#clock {
font-size: 27px;
}
}
</style>
</head>
<body>
<div id="hud">
<section id="brand" class="panel">
<div class="brand-row">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="eyebrow">Temporal Transit / Voxel Study</div>
<h1>ORDER RAIL</h1>
</div>
</div>
<p class="brand-subtitle">
Arrival, service, and departure tokens positioned by immutable event time.
</p>
<div class="legend">
<div class="legend-item" style="color: var(--cyan)">
<span class="legend-color"></span>
<span class="legend-name">Arrival</span>
<span class="legend-time">INBOUND</span>
</div>
<div class="legend-item" style="color: var(--amber)">
<span class="legend-color"></span>
<span class="legend-name">Service</span>
<span class="legend-time">PLATFORM</span>
</div>
<div class="legend-item" style="color: var(--green)">
<span class="legend-color"></span>
<span class="legend-name">Departure</span>
<span class="legend-time">OUTBOUND</span>
</div>
</div>
</section>
<section id="controls" class="panel">
<div class="clock-row">
<div>
<div class="eyebrow">Rail Clock</div>
<strong id="clock">08:00</strong>
</div>
<div class="order-badge">ORDER LOCKED</div>
</div>
<div class="progress"><div id="progressFill"></div></div>
<div class="control-meta">
<span id="eventCount">0 / 9 EVENTS</span>
<span>40 MIN WINDOW</span>
</div>
<input
id="seek"
type="range"
min="0"
max="40"
step="0.1"
value="0"
aria-label="Seek through the event timeline"
>
<div class="button-row">
<button id="playBtn" type="button">▶ Play</button>
<button id="resetBtn" type="button" title="Reset timeline" aria-label="Reset timeline">↺</button>
</div>
<div class="speed-row">
<div class="eyebrow">Playback Rate</div>
<div class="speed-buttons" aria-label="Playback speed">
<button type="button" data-speed="0.5">0.5×</button>
<button type="button" data-speed="1" class="active">1×</button>
<button type="button" data-speed="2">2×</button>
</div>
</div>
</section>
<section id="selection" class="panel">
<div class="selection-top">
<span id="selectedKind">NO SELECTION</span>
<span id="selectedTime">—</span>
</div>
<h2 id="selectedTitle">Select a voxel token</h2>
<p id="selectedMeta">
Token positions map directly from timestamp. Playback speed changes only the clock rate.
</p>
</section>
<div id="technicalNote">
<strong>Timeline model:</strong> event time controls X position;
animation duration controls only the reveal tween. Speed never reorders events.
</div>
<div id="help">
DRAG TO ORBIT · SHIFT/RIGHT-DRAG TO PAN · WHEEL TO ZOOM · SPACE TO PLAY
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Timeline model
// -------------------------------------------------------------------------
// EVENT_TIME_MINUTE is the authoritative timestamp used for X positioning.
// TOKEN_ANIMATION_MS is intentionally independent and controls only visuals.
// Playback speed changes simulated minutes per real second, never EVENT data.
const START_MINUTE = 8 * 60;
const TOTAL_MINUTES = 40;
const MINUTES_PER_SECOND = 1.25;
const TOKEN_ANIMATION_MS = 620;
const RAIL_MIN_X = -12;
const RAIL_MAX_X = 12;
const KIND = {
arrival: {
label: "ARRIVAL",
color: new THREE.Color("#45dcff"),
css: "#45dcff"
},
service: {
label: "SERVICE",
color: new THREE.Color("#ffd166"),
css: "#ffd166"
},
departure: {
label: "DEPARTURE",
color: new THREE.Color("#70efaa"),
css: "#70efaa"
}
};
const EVENTS = [
{
id: "K-101",
kind: "arrival",
minute: 2,
title: "Harbor inbound",
meta: "Inbound consist K-101 · north approach · platform 2"
},
{
id: "K-101",
kind: "service",
minute: 5,
title: "Platform inspection",
meta: "K-101 · platform 2 · dwell check and boarding release"
},
{
id: "K-101",
kind: "departure",
minute: 9,
title: "Eastbound release",
meta: "Outbound consist K-101 · east route · signal cleared"
},
{
id: "K-204",
kind: "arrival",
minute: 13,
title: "Summit inbound",
meta: "Inbound consist K-204 · elevated approach · platform 1"
},
{
id: "K-204",
kind: "service",
minute: 17,
title: "Platform inspection",
meta: "K-204 · platform 1 · dwell check and boarding release"
},
{
id: "K-204",
kind: "departure",
minute: 22,
title: "Southbound release",
meta: "Outbound consist K-204 · south route · signal cleared"
},
{
id: "K-317",
kind: "arrival",
minute: 26,
title: "Airport inbound",
meta: "Inbound consist K-317 · west approach · platform 4"
},
{
id: "K-317",
kind: "service",
minute: 30,
title: "Platform inspection",
meta: "K-317 · platform 4 · dwell check and boarding release"
},
{
id: "K-317",
kind: "departure",
minute: 35,
title: "Westbound release",
meta: "Outbound consist K-317 · west route · signal cleared"
}
];
const ui = {
clock: document.querySelector("#clock"),
progressFill: document.querySelector("#progressFill"),
eventCount: document.querySelector("#eventCount"),
seek: document.querySelector("#seek"),
play: document.querySelector("#playBtn"),
reset: document.querySelector("#resetBtn"),
selectedKind: document.querySelector("#selectedKind"),
selectedTime: document.querySelector("#selectedTime"),
selectedTitle: document.querySelector("#selectedTitle"),
selectedMeta: document.querySelector("#selectedMeta")
};
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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.12;
renderer.domElement.setAttribute("aria-label", "Interactive voxel event timeline");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#07121d");
scene.fog = new THREE.Fog("#07121d", 27, 53);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls; no addons are used.
const controls = {
theta: 0.62,
phi: 1.02,
radius: window.innerWidth < 700 ? 31 : 25,
target: new THREE.Vector3(0, 0.65, 0),
minRadius: 11,
maxRadius: 46
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const offset = new THREE.Vector3(
controls.radius * sinPhi * Math.sin(controls.theta),
controls.radius * Math.cos(controls.phi),
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight("#bceeff", "#09101a", 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#d8f4ff", 3.1);
keyLight.position.set(-8, 17, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight("#318dff", 1.5);
rimLight.position.set(12, 8, -12);
scene.add(rimLight);
const warmLight = new THREE.PointLight("#ff9a52", 28, 18, 2);
warmLight.position.set(-8, 5, 3);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Geometry and materials
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const cube = (width, height, depth) =>
new THREE.Mesh(unitBox, undefined).scale.set(width, height, depth);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: "#091724",
roughness: 0.88,
metalness: 0.12
}),
grid: new THREE.MeshBasicMaterial({
color: "#244358",
transparent: true,
opacity: 0.28
}),
rail: new THREE.MeshStandardMaterial({
color: "#607b8d",
roughness: 0.32,
metalness: 0.86
}),
sleeper: new THREE.MeshStandardMaterial({
color: "#243747",
roughness: 0.72,
metalness: 0.32
}),
socket: new THREE.MeshStandardMaterial({
color: "#172a3a",
roughness: 0.58,
metalness: 0.5
}),
darkStructure: new THREE.MeshStandardMaterial({
color: "#102232",
roughness: 0.78,
metalness: 0.24
}),
trim: new THREE.MeshStandardMaterial({
color: "#28495f",
roughness: 0.5,
metalness: 0.5
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and voxel-style grid.
addBox(scene, [30, 0.5, 15], [0, -0.3, 0], materials.floor, false);
for (let x = -14; x <= 14; x += 2) {
addBox(
scene,
[0.025, 0.018, 14.4],
[x, -0.035, 0],
materials.grid,
false
);
}
for (let z = -6; z <= 6; z += 2) {
addBox(
scene,
[29.4, 0.018, 0.025],
[0, -0.034, z],
materials.grid,
false
);
}
// Rail bed and twin rails.
addBox(scene, [25.2, 0.12, 1.25], [0, 0.03, 0], materials.sleeper, false);
addBox(scene, [24.6, 0.12, 0.11], [0, 0.15, -0.32], materials.rail);
addBox(scene, [24.6, 0.12, 0.11], [0, 0.15, 0.32], materials.rail);
for (let minute = 0; minute <= TOTAL_MINUTES; minute++) {
const x = minuteToX(minute);
addBox(
scene,
[0.1, 0.07, 0.93],
[x, 0.11, 0],
materials.sleeper,
false
);
}
// Decorative voxel infrastructure behind the rail.
const structures = [
{ x: -10.4, z: -4.4, w: 2.2, h: 2.7, d: 1.7 },
{ x: -7.6, z: -5.0, w: 1.4, h: 1.55, d: 1.3 },
{ x: 6.9, z: -4.7, w: 2.8, h: 2.05, d: 1.6 },
{ x: 10.2, z: -4.1, w: 1.7, h: 3.3, d: 1.8 }
];
for (const s of structures) {
addBox(
scene,
[s.w, s.h, s.d],
[s.x, s.h / 2, s.z],
materials.darkStructure
);
addBox(
scene,
[s.w + 0.18, 0.13, s.d + 0.18],
[s.x, s.h + 0.06, s.z],
materials.trim
);
for (let row = 0; row < Math.floor(s.h / 0.55); row++) {
const windowMat = new THREE.MeshBasicMaterial({
color: row % 2 === 0 ? "#3bb8da" : "#ffb968",
transparent: true,
opacity: 0.42
});
addBox(
scene,
[0.12, 0.12, 0.025],
[s.x - s.w * 0.25, 0.48 + row * 0.55, s.z + s.d / 2 + 0.015],
windowMat,
false
);
addBox(
scene,
[0.12, 0.12, 0.025],
[s.x + s.w * 0.25, 0.48 + row * 0.55, s.z + s.d / 2 + 0.015],
windowMat,
false
);
}
}
// Rail-end signal blocks.
for (const side of [-1, 1]) {
const x = side * 12.45;
addBox(scene, [0.2, 2.2, 0.2], [x, 1.1, -0.72], materials.trim);
addBox(scene, [0.4, 0.95, 0.38], [x, 2.35, -0.72], materials.darkStructure);
const signalMaterial = new THREE.MeshStandardMaterial({
color: side < 0 ? "#45dcff" : "#70efaa",
emissive: side < 0 ? "#45dcff" : "#70efaa",
emissiveIntensity: 1.4,
roughness: 0.35
});
addBox(scene, [0.13, 0.13, 0.06], [x, 2.48, -0.51], signalMaterial, false);
}
// -------------------------------------------------------------------------
// Canvas sprite labels
// -------------------------------------------------------------------------
function createLabelTexture({
title,
subtitle = "",
accent = "#45dcff",
width = 512,
height = 144
}) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = "rgba(6, 16, 27, 0.91)";
ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = "rgba(137, 181, 211, 0.38)";
ctx.lineWidth = 3;
ctx.strokeRect(2, 2, width - 4, height - 4);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 10, height);
ctx.textBaseline = "middle";
ctx.fillStyle = accent;
ctx.font = "700 32px monospace";
ctx.fillText(title, 29, subtitle ? 47 : height / 2);
if (subtitle) {
ctx.fillStyle = "#c8d8e5";
ctx.font = "600 25px monospace";
ctx.fillText(subtitle, 29, 94);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeSprite(texture, scaleX, scaleY, opacity = 1) {
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
opacity,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scaleX, scaleY, 1);
sprite.renderOrder = 20;
return sprite;
}
// Minute ticks.
const tickMaterials = [];
for (let minute = 0; minute <= TOTAL_MINUTES; minute++) {
const major = minute % 5 === 0;
const x = minuteToX(minute);
const tickMaterial = new THREE.MeshStandardMaterial({
color: "#294052",
emissive: "#162735",
emissiveIntensity: 0.2,
roughness: 0.5,
metalness: 0.2
});
tickMaterials.push({ minute, material: tickMaterial, major });
addBox(
scene,
major ? [0.075, 0.42, 0.12] : [0.045, 0.23, 0.1],
[x, 0.28, 0.64],
tickMaterial,
false
);
if (major) {
const texture = createLabelTexture({
title: formatClock(minute),
accent: "#6e8ba0",
width: 256,
height: 80
});
const sprite = makeSprite(texture, 1.24, 0.39, 0.8);
sprite.position.set(x, 0.48, 1.16);
sprite.renderOrder = 8;
scene.add(sprite);
}
}
// -------------------------------------------------------------------------
// Event tokens
// -------------------------------------------------------------------------
const pickMeshes = [];
const tokenVisuals = [];
function createEventToken(event, index) {
const group = new THREE.Group();
const x = minuteToX(event.minute);
// This X is never animated or changed by playback.
group.position.set(x, 0, 0);
scene.add(group);
const socket = addBox(
group,
[0.78, 0.13, 0.78],
[0, 0.25, 0],
materials.socket
);
socket.userData.eventIndex = index;
addBox(
group,
[0.1, 0.38, 0.1],
[0, 0.48, 0],
materials.trim
);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: event.kind === "arrival"
? KIND.arrival.color
: event.kind === "service"
? KIND.service.color
: KIND.departure.color,
emissive: event.kind === "arrival"
? KIND.arrival.color
: event.kind === "service"
? KIND.service.color
: KIND.departure.color,
emissiveIntensity: 0.12,
roughness: 0.28,
metalness: 0.26,
transparent: true,
opacity: 0.25,
depthWrite: false
});
const body = addBox(
group,
[0.58, 0.58, 0.58],
[0, 0.91, 0],
bodyMaterial
);
body.userData.eventIndex = index;
pickMeshes.push(body);
// Four small corner caps emphasize the voxel construction.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const capMaterial = bodyMaterial.clone();
addBox(
group,
[0.13, 0.13, 0.13],
[sx * 0.23, 1.25, sz * 0.23],
capMaterial,
false
);
}
}
const iconMaterial = new THREE.MeshBasicMaterial({
color: "#f5fbff",
transparent: true,
opacity: 0.28,
depthWrite: false
});
const iconBlocks = [];
if (event.kind === "arrival") {
// Down-pointing voxel arrow.
iconBlocks.push(
[0, 0, -0.12], [-0.13, 0, 0.02], [0.13, 0, 0.02],
[0, 0, 0.14]
);
} else if (event.kind === "service") {
// Cross / service mark.
iconBlocks.push(
[0, 0, 0], [-0.14, 0, 0], [0.14, 0, 0],
[0, 0, -0.14], [0, 0, 0.14]
);
} else {
// Up-pointing voxel arrow.
iconBlocks.push(
[0, 0, 0.12], [-0.13, 0, -0.02], [0.13, 0, -0.02],
[0, 0, -0.14]
);
}
for (const [ix, iy, iz] of iconBlocks) {
const icon = addBox(
group,
[0.1, 0.1, 0.1],
[ix, 1.255, iz],
iconMaterial,
false
);
icon.renderOrder = 4;
}
const labelTexture = createLabelTexture({
title: `${formatClock(event.minute)} ${KIND[event.kind].label}`,
subtitle: `${event.id} / ${event.title.toUpperCase()}`,
accent: KIND[event.kind].css
});
const label = makeSprite(labelTexture, 2.2, 0.62, 0.5);
label.position.set(0, 1.9 + (index % 2) * 0.28, 0);
group.add(label);
const selection = new THREE.Group();
selection.visible = false;
const selectionMaterial = new THREE.MeshBasicMaterial({
color: KIND[event.kind].color,
transparent: true,
opacity: 0.9,
depthWrite: false
});
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
selection,
[0.16, 0.07, 0.16],
[sx * 0.48, 0.17, sz * 0.48],
selectionMaterial,
false
);
}
}
group.add(selection);
event.activated = false;
event.reveal = 0;
event.activationStart = 0;
tokenVisuals.push({
group,
bodyMaterial,
iconMaterial,
label,
selection,
selectionMaterial,
baseColor: KIND[event.kind].color.clone()
});
}
EVENTS.forEach(createEventToken);
// -------------------------------------------------------------------------
// Playhead
// -------------------------------------------------------------------------
const playhead = new THREE.Group();
scene.add(playhead);
const playheadMaterial = new THREE.MeshBasicMaterial({
color: "#ff9a52",
transparent: true,
opacity: 0.72,
depthTest: false,
depthWrite: false
});
addBox(
playhead,
[0.045, 2.95, 0.045],
[0, 1.48, 0],
playheadMaterial,
false
);
addBox(
playhead,
[0.32, 0.16, 0.32],
[0, 2.98, 0],
playheadMaterial,
false
);
addBox(
playhead,
[0.18, 0.18, 0.18],
[0, 3.22, 0],
playheadMaterial,
false
);
const clockCanvas = document.createElement("canvas");
clockCanvas.width = 384;
clockCanvas.height = 112;
const clockContext = clockCanvas.getContext("2d");
const clockTexture = new THREE.CanvasTexture(clockCanvas);
clockTexture.colorSpace = THREE.SRGBColorSpace;
clockTexture.minFilter = THREE.LinearFilter;
const clockSprite = makeSprite(clockTexture, 2.55, 0.74, 0.95);
clockSprite.position.set(0, 3.55, 0);
scene.add(clockSprite);
let displayedClockMinute = -1;
function drawClockSprite(minute) {
const ctx = clockContext;
ctx.clearRect(0, 0, clockCanvas.width, clockCanvas.height);
ctx.fillStyle = "rgba(7, 17, 28, 0.93)";
ctx.fillRect(0, 0, clockCanvas.width, clockCanvas.height);
ctx.strokeStyle = "rgba(255, 154, 82, 0.72)";
ctx.lineWidth = 4;
ctx.strokeRect(2, 2, clockCanvas.width - 4, clockCanvas.height - 4);
ctx.fillStyle = "#ff9a52";
ctx.fillRect(0, 0, 10, clockCanvas.height);
ctx.fillStyle = "#ffb27b";
ctx.font = "700 25px monospace";
ctx.fillText("NOW", 30, 38);
ctx.fillStyle = "#f4f9fd";
ctx.font = "800 48px monospace";
ctx.fillText(formatClock(minute), 29, 82);
clockTexture.needsUpdate = true;
}
// -------------------------------------------------------------------------
// State and playback
// -------------------------------------------------------------------------
let playheadMinute = 0;
let playing = false;
let playbackSpeed = 1;
let nextEventIndex = 0;
let lastActivatedEvent = null;
let selectedEventIndex = null;
function minuteToX(minute) {
return RAIL_MIN_X + (minute / TOTAL_MINUTES) * (RAIL_MAX_X - RAIL_MIN_X);
}
function formatClock(minute) {
const total = START_MINUTE + Math.floor(minute);
const hours = Math.floor(total / 60);
const mins = total % 60;
return `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
}
function easeOutBack(value) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(value - 1, 3) + c1 * Math.pow(value - 1, 2);
}
function selectEvent(index) {
selectedEventIndex = index;
const event = EVENTS[index];
const kind = KIND[event.kind];
ui.selectedKind.textContent = `${kind.label} / ${event.id}`;
ui.selectedKind.style.color = kind.css;
ui.selectedTime.textContent = formatClock(event.minute);
ui.selectedTitle.textContent = event.title;
ui.selectedMeta.textContent = event.meta;
}
function seekTo(minute) {
playheadMinute = THREE.MathUtils.clamp(minute, 0, TOTAL_MINUTES);
const now = performance.now();
nextEventIndex = 0;
lastActivatedEvent = null;
selectedEventIndex = null;
for (let i = 0; i < EVENTS.length; i++) {
const event = EVENTS[i];
event.activated = event.minute <= playheadMinute + 0.0001;
event.reveal = event.activated ? 1 : 0;
event.activationStart = event.activated ? now - TOKEN_ANIMATION_MS : 0;
if (event.activated) {
nextEventIndex = i + 1;
lastActivatedEvent = event;
selectedEventIndex = i;
}
}
if (selectedEventIndex !== null) {
selectEvent(selectedEventIndex);
} else {
ui.selectedKind.textContent = "NO SELECTION";
ui.selectedKind.style.color = "#45dcff";
ui.selectedTime.textContent = "—";
ui.selectedTitle.textContent = "Select a voxel token";
ui.selectedMeta.textContent =
"Token positions map directly from timestamp. Playback speed changes only the clock rate.";
}
updateInterface();
}
function togglePlayback() {
if (playheadMinute >= TOTAL_MINUTES - 0.001) {
seekTo(0);
playing = true;
} else {
playing = !playing;
}
updateInterface();
}
function resetPlayback() {
playing = false;
seekTo(0);
updateInterface();
}
function updateInterface() {
const clockMinute = Math.floor(playheadMinute + 0.0001);
ui.clock.textContent = formatClock(clockMinute);
ui.progressFill.style.width = `${(playheadMinute / TOTAL_MINUTES) * 100}%`;
ui.seek.value = String(playheadMinute);
const activeCount = EVENTS.filter((event) => event.activated).length;
ui.eventCount.textContent = `${activeCount} / ${EVENTS.length} EVENTS`;
ui.play.textContent = playing
? "Ⅱ Pause"
: playheadMinute >= TOTAL_MINUTES - 0.001
? "↻ Replay"
: "▶ Play";
if (clockMinute !== displayedClockMinute) {
displayedClockMinute = clockMinute;
drawClockSprite(clockMinute);
}
}
ui.play.addEventListener("click", togglePlayback);
ui.reset.addEventListener("click", resetPlayback);
ui.seek.addEventListener("input", () => {
playing = false;
seekTo(Number(ui.seek.value));
updateInterface();
});
document.querySelectorAll("[data-speed]").forEach((button) => {
button.addEventListener("click", () => {
playbackSpeed = Number(button.dataset.speed);
document.querySelectorAll("[data-speed]").forEach((other) => {
other.classList.toggle("active", other === button);
});
});
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.code === "Space") {
event.preventDefault();
togglePlayback();
} else if (event.key.toLowerCase() === "r") {
resetPlayback();
}
});
// -------------------------------------------------------------------------
// Animation update
// -------------------------------------------------------------------------
function activateNextEvent(now) {
if (nextEventIndex >= EVENTS.length) return;
const next = EVENTS[nextEventIndex];
if (playheadMinute + 0.0001 < next.minute) return;
// Reveals are activated one at a time, even if the clock has crossed
// several timestamps. This makes visual completion order deterministic.
if (lastActivatedEvent && lastActivatedEvent.reveal < 1) return;
next.activated = true;
next.reveal = 0;
next.activationStart = now;
lastActivatedEvent = next;
nextEventIndex++;
if (selectedEventIndex === null) {
selectEvent(nextEventIndex - 1);
}
}
const inactiveColor = new THREE.Color("#1a2b38");
function updateTokens(now) {
for (let i = 0; i < EVENTS.length; i++) {
const event = EVENTS[i];
const visual = tokenVisuals[i];
if (event.activated) {
event.reveal = THREE.MathUtils.clamp(
(now - event.activationStart) / TOKEN_ANIMATION_MS,
0,
1
);
}
const reveal = event.reveal;
const eased = easeOutBack(reveal);
const scale = event.activated ? 0.73 + eased * 0.27 : 0.73;
visual.group.scale.setScalar(scale);
const bounce = event.activated ? Math.sin(reveal * Math.PI) * 0.24 : 0;
visual.group.position.y = bounce;
visual.bodyMaterial.color
.copy(visual.baseColor)
.lerp(inactiveColor, (1 - reveal) * 0.78);
visual.bodyMaterial.emissive.copy(visual.baseColor);
visual.bodyMaterial.emissiveIntensity = event.activated
? 0.12 + reveal * 0.72
: 0.06;
visual.bodyMaterial.opacity = event.activated ? 0.28 + reveal * 0.72 : 0.24;
visual.iconMaterial.opacity = event.activated ? 0.3 + reveal * 0.7 : 0.2;
visual.label.material.opacity = event.activated ? 0.52 + reveal * 0.48 : 0.48;
const selected = selectedEventIndex === i;
visual.selection.visible = selected;
if (selected) {
const pulse = 1 + Math.sin(now * 0.004) * 0.06;
visual.selection.scale.setScalar(pulse);
visual.selectionMaterial.opacity = 0.78 + Math.sin(now * 0.004) * 0.16;
}
}
}
function updateTicks() {
for (const tick of tickMaterials) {
const passed = playheadMinute + 0.0001 >= tick.minute;
if (tick.major) {
tick.material.color.set(passed ? "#45dcff" : "#294052");
tick.material.emissive.set(passed ? "#45dcff" : "#162735");
tick.material.emissiveIntensity = passed ? 0.75 : 0.16;
} else {
tick.material.color.set(passed ? "#5a8ca4" : "#263b4b");
tick.material.emissive.set(passed ? "#315d70" : "#101d28");
tick.material.emissiveIntensity = passed ? 0.35 : 0.08;
}
}
}
// -------------------------------------------------------------------------
// Direct pointer camera controls and token picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
pan: false,
button: 0
};
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerState.down = true;
pointerState.moved = false;
pointerState.startX = event.clientX;
pointerState.startY = event.clientY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
pointerState.button = event.button;
pointerState.pan = event.button === 2 || event.shiftKey;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState.down) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hover = raycaster.intersectObjects(pickMeshes, false).length > 0;
renderer.domElement.style.cursor = hover ? "pointer" : "grab";
return;
}
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
const totalDistance = Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
);
if (totalDistance > 4) pointerState.moved = true;
if (pointerState.pan) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const panScale = controls.radius * 0.00135;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(forward, -dy * panScale);
} else {
controls.theta -= dx * 0.0055;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0045,
0.46,
1.43
);
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerState.down = false;
if (!pointerState.moved) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
if (hits.length) {
const eventIndex = hits[0].object.userData.eventIndex;
selectEvent(eventIndex);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
controls.minRadius,
controls.maxRadius
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
controls.theta = 0.62;
controls.phi = 1.02;
controls.radius = window.innerWidth < 700 ? 31 : 25;
controls.target.set(0, 0.65, 0);
updateCamera();
});
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
if (playing) {
playheadMinute = Math.min(
TOTAL_MINUTES,
playheadMinute + dt * MINUTES_PER_SECOND * playbackSpeed
);
if (playheadMinute >= TOTAL_MINUTES) {
playing = false;
}
}
activateNextEvent(now);
updateTokens(now);
updateTicks();
const playheadX = minuteToX(playheadMinute);
playhead.position.x = playheadX;
clockSprite.position.x = playheadX;
playheadMaterial.opacity = 0.64 + Math.sin(now * 0.004) * 0.1;
updateInterface();
renderer.render(scene, camera);
}
updateInterface();
animate();
</script>
</body>
</html>
```