Prompt specification
Build or customize the Three.js 3D scene "Miniature Athletics Meet Diorama" 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: Miniature Athletics Meet Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/miniature-athletics-meet-diorama-x3671
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing running-track geometry and staggered starts. Build an original school athletics scene with readable lanes, staggered starts, and a finish line. Animate runners at equal speeds to demonstrate equal-distance alignment. Voxel style.
Working Three.js Starter (miniature-athletics-meet-diorama-x3671):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Maple Ridge High — 400 m Voxel Athletics</title>
<style>
:root {
--ink: #14213d;
--muted: #60708c;
--paper: rgba(255, 255, 255, 0.94);
--accent: #ff6b35;
--cyan: #1fc8e5;
--shadow: 0 14px 40px rgba(20, 33, 61, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bfe4f2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.78);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 31px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 8px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
min-height: 32px;
}
#status-dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 50%;
background: #ffb020;
box-shadow: 0 0 0 5px rgba(255, 176, 32, 0.15);
}
#status-text {
font-size: 13px;
font-weight: 800;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 14px;
}
.metric {
padding: 9px 10px;
border-radius: 11px;
background: #eef3f8;
}
.metric span {
display: block;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 3px;
font-size: 15px;
font-variant-numeric: tabular-nums;
}
#controls {
top: 18px;
right: 18px;
width: 286px;
padding: 16px;
border-radius: 18px;
}
.control-title {
margin-bottom: 11px;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.button-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 38px;
padding: 9px 12px;
border: 0;
border-radius: 10px;
background: #eaf0f6;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 850;
cursor: pointer;
transition: transform 0.15s ease, background 0.15s ease;
}
button:hover {
transform: translateY(-1px);
background: #dde7f1;
}
button.primary {
grid-column: 1 / -1;
background: var(--ink);
color: white;
}
button.primary:hover {
background: #23385f;
}
button.active {
background: #d9f5f7;
color: #087d8b;
}
.speed-control {
margin-top: 13px;
}
.speed-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
}
input[type="range"] {
width: 100%;
accent-color: var(--accent);
}
#lane-panel {
right: 18px;
bottom: 18px;
width: 286px;
max-height: 43vh;
overflow: auto;
padding: 16px;
border-radius: 18px;
}
.lane-table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.lane-table th {
padding: 0 0 7px;
color: var(--muted);
text-align: right;
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.lane-table th:first-child,
.lane-table td:first-child {
text-align: left;
}
.lane-table td {
padding: 5px 0;
border-top: 1px solid #e4eaf0;
text-align: right;
}
.lane-chip {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 6px;
border-radius: 2px;
vertical-align: -1px;
}
.progress-wrap {
position: fixed;
z-index: 10;
left: 50%;
bottom: 18px;
width: min(520px, calc(100vw - 36px));
padding: 13px 16px 14px;
border-radius: 16px;
background: rgba(20, 33, 61, 0.9);
color: white;
box-shadow: var(--shadow);
transform: translateX(-50%);
}
.progress-header {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
font-size: 11px;
font-weight: 850;
}
#progress-bars {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 5px;
}
.progress-track {
height: 6px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.16);
}
.progress-fill {
width: 0%;
height: 100%;
border-radius: inherit;
transition: width 0.08s linear;
}
#countdown {
position: fixed;
z-index: 20;
top: 46%;
left: 50%;
color: white;
font-size: clamp(60px, 12vw, 140px);
font-weight: 1000;
line-height: 1;
letter-spacing: -0.08em;
text-shadow: 0 8px 0 rgba(20, 33, 61, 0.3),
0 18px 45px rgba(20, 33, 61, 0.35);
transform: translate(-50%, -50%);
pointer-events: none;
}
#hint {
position: fixed;
z-index: 9;
left: 18px;
bottom: 18px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.84);
color: var(--muted);
font-size: 10px;
font-weight: 750;
box-shadow: 0 8px 25px rgba(20, 33, 61, 0.1);
}
@media (max-width: 850px) {
#controls {
top: auto;
right: 12px;
bottom: 92px;
width: 235px;
}
#lane-panel {
display: none;
}
#title-card {
top: 12px;
left: 12px;
width: min(340px, calc(100vw - 24px));
}
.metrics {
margin-top: 10px;
}
#hint {
display: none;
}
.progress-wrap {
bottom: 12px;
}
}
@media (max-width: 520px) {
#controls {
right: 10px;
bottom: 88px;
width: 208px;
padding: 12px;
}
#title-card {
padding: 14px;
}
.subtitle {
display: none;
}
.metric {
padding: 7px;
}
.metric strong {
font-size: 13px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="title-card" class="panel">
<div class="eyebrow">Maple Ridge High · School Athletics</div>
<h1>400 m Staggered Start</h1>
<p class="subtitle">
Eight runners, equal speed, and exactly 400.0 m remaining at the start.
The orange markers compensate for each lane’s longer curved path.
</p>
<div class="status-row">
<div id="status-dot"></div>
<div id="status-text">Preparing the athletes…</div>
</div>
<div class="metrics">
<div class="metric">
<span>Race</span>
<strong>400.0 m</strong>
</div>
<div class="metric">
<span>Runner speed</span>
<strong>6.5 m/s</strong>
</div>
<div class="metric">
<span>Distance run</span>
<strong id="distance-value">0.0 m</strong>
</div>
</div>
</section>
<section id="controls" class="panel">
<div class="control-title">Race & camera</div>
<div class="button-grid">
<button id="replay" class="primary">Replay 400 m race</button>
<button id="pause">Pause</button>
<button id="overview" class="active">Overview</button>
<button id="finish-view">Finish view</button>
</div>
<div class="speed-control">
<div class="speed-label">
<span>Playback speed</span>
<span id="speed-value">×5</span>
</div>
<input
id="speed"
type="range"
min="1"
max="10"
step="1"
value="5"
aria-label="Playback speed"
/>
</div>
</section>
<section id="lane-panel" class="panel">
<div class="control-title">Lane geometry</div>
<table class="lane-table">
<thead>
<tr>
<th>Lane</th>
<th>Lap length</th>
<th>Start shift</th>
</tr>
</thead>
<tbody id="lane-table-body"></tbody>
</table>
</section>
<section class="progress-wrap">
<div class="progress-header">
<span>Equal-distance progress</span>
<span id="race-clock">0.0 s</span>
</div>
<div id="progress-bars"></div>
</section>
<div id="countdown"></div>
<div id="hint">Drag: orbit · Scroll: zoom · Arrow keys: rotate · +/−: zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Configuration
// ------------------------------------------------------------
const LANE_COUNT = 8;
const LANE_WIDTH = 1.22;
const MEASUREMENT_RADIUS = 36.8;
const STRAIGHT_LENGTH = 84.39;
const HALF_STRAIGHT = STRAIGHT_LENGTH / 2;
const INNER_RADIUS = MEASUREMENT_RADIUS - LANE_WIDTH / 2;
const OUTER_RADIUS = INNER_RADIUS + LANE_COUNT * LANE_WIDTH;
const FINISH_X = 24;
const RACE_DISTANCE = 400;
const RUNNER_SPEED = 6.5;
const laneColors = [
0x29c5df,
0x7758e8,
0xf24f7b,
0xff7547,
0xffc83d,
0x58ce6c,
0x20b89f,
0xf05d5d
];
const laneRadii = Array.from(
{ length: LANE_COUNT },
(_, i) => MEASUREMENT_RADIUS + i * LANE_WIDTH
);
const laneLengths = laneRadii.map(
(r) => 2 * STRAIGHT_LENGTH + Math.PI * 2 * r
);
const laneStartDistances = laneLengths.map(
(length) => mod(FINISH_X + HALF_STRAIGHT - RACE_DISTANCE, length)
);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfe4f2);
scene.fog = new THREE.Fog(0xbfe4f2, 145, 285);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
500
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.getElementById("scene").appendChild(renderer.domElement);
const hemiLight = new THREE.HemisphereLight(0xd9f2ff, 0x72814f, 2.15);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xfff3d8, 3.0);
sun.position.set(-55, 95, 48);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -105;
sun.shadow.camera.right = 105;
sun.shadow.camera.top = 95;
sun.shadow.camera.bottom = -95;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 260;
sun.shadow.bias = -0.00025;
scene.add(sun);
const materialCache = new Map();
function material(color, roughness = 0.88, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({ color, roughness, metalness })
);
}
return materialCache.get(key);
}
function box(
width,
height,
depth,
color,
x,
y,
z,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
options.material || material(color, options.roughness, options.metalness)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotationY) mesh.rotation.y = options.rotationY;
if (options.rotationX) mesh.rotation.x = options.rotationX;
if (options.rotationZ) mesh.rotation.z = options.rotationZ;
return mesh;
}
function mod(value, divisor) {
return ((value % divisor) + divisor) % divisor;
}
// ------------------------------------------------------------
// Track path: straight → right semicircle → straight → left arc
// Distances are measured in real metres.
// ------------------------------------------------------------
function pathPoint(radius, distance) {
const total = 2 * STRAIGHT_LENGTH + Math.PI * 2 * radius;
const d = mod(distance, total);
const arcLength = Math.PI * radius;
if (d < STRAIGHT_LENGTH) {
return {
x: -HALF_STRAIGHT + d,
z: -radius,
tx: 1,
tz: 0,
rx: 0,
rz: -1
};
}
if (d < STRAIGHT_LENGTH + arcLength) {
const theta =
-Math.PI / 2 + (d - STRAIGHT_LENGTH) / radius;
return {
x: HALF_STRAIGHT + radius * Math.cos(theta),
z: radius * Math.sin(theta),
tx: -Math.sin(theta),
tz: Math.cos(theta),
rx: Math.cos(theta),
rz: Math.sin(theta)
};
}
if (d < 2 * STRAIGHT_LENGTH + arcLength) {
const q = d - STRAIGHT_LENGTH - arcLength;
return {
x: HALF_STRAIGHT - q,
z: radius,
tx: -1,
tz: 0,
rx: 0,
rz: 1
};
}
const theta =
Math.PI / 2 + (d - 2 * STRAIGHT_LENGTH - arcLength) / radius;
return {
x: -HALF_STRAIGHT + radius * Math.cos(theta),
z: radius * Math.sin(theta),
tx: -Math.sin(theta),
tz: Math.cos(theta),
rx: Math.cos(theta),
rz: Math.sin(theta)
};
}
// ------------------------------------------------------------
// Stadium-shaped mesh helpers
// ------------------------------------------------------------
function stadiumShape(radius) {
const shape = new THREE.Shape();
shape.moveTo(-HALF_STRAIGHT, -radius);
shape.lineTo(HALF_STRAIGHT, -radius);
shape.absarc(
HALF_STRAIGHT,
0,
radius,
-Math.PI / 2,
Math.PI / 2,
false
);
shape.lineTo(-HALF_STRAIGHT, radius);
shape.absarc(
-HALF_STRAIGHT,
0,
radius,
Math.PI / 2,
Math.PI * 1.5,
false
);
shape.closePath();
return shape;
}
function makeStadiumStrip(r0, r1, y, mat) {
const straightSteps = 34;
const arcSteps = 54;
const inner = [];
const outer = [];
function addSegment(steps, innerPoint, outerPoint) {
for (let i = 0; i < steps; i++) {
const t = i / steps;
inner.push(innerPoint(t));
outer.push(outerPoint(t));
}
}
addSegment(
straightSteps,
(t) => [-HALF_STRAIGHT + STRAIGHT_LENGTH * t, -r0],
(t) => [-HALF_STRAIGHT + STRAIGHT_LENGTH * t, -r1]
);
addSegment(
arcSteps,
(t) => {
const a = -Math.PI / 2 + Math.PI * t;
return [
HALF_STRAIGHT + r0 * Math.cos(a),
r0 * Math.sin(a)
];
},
(t) => {
const a = -Math.PI / 2 + Math.PI * t;
return [
HALF_STRAIGHT + r1 * Math.cos(a),
r1 * Math.sin(a)
];
}
);
addSegment(
straightSteps,
(t) => [HALF_STRAIGHT - STRAIGHT_LENGTH * t, r0],
(t) => [HALF_STRAIGHT - STRAIGHT_LENGTH * t, r1]
);
addSegment(
arcSteps,
(t) => {
const a = Math.PI / 2 + Math.PI * t;
return [
-HALF_STRAIGHT + r0 * Math.cos(a),
r0 * Math.sin(a)
];
},
(t) => {
const a = Math.PI / 2 + Math.PI * t;
return [
-HALF_STRAIGHT + r1 * Math.cos(a),
r1 * Math.sin(a)
];
}
);
const positions = [];
const indices = [];
const count = inner.length;
for (let i = 0; i < count; i++) {
positions.push(
inner[i][0], y, inner[i][1],
outer[i][0], y, outer[i][1]
);
}
for (let i = 0; i < count; i++) {
const j = (i + 1) % count;
const a = i * 2;
const b = i * 2 + 1;
const c = j * 2;
const d = j * 2 + 1;
indices.push(a, c, b, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
mat.side
? mat
: new THREE.MeshStandardMaterial({
color: mat.color,
roughness: mat.roughness,
metalness: mat.metalness,
side: THREE.DoubleSide
})
);
mesh.receiveShadow = true;
return mesh;
}
// Ground and infield.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(310, 270),
material(0x72a956)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.04;
ground.receiveShadow = true;
scene.add(ground);
const infield = new THREE.Mesh(
new THREE.ShapeGeometry(stadiumShape(INNER_RADIUS - 0.3)),
material(0x75ad58)
);
infield.rotation.x = -Math.PI / 2;
infield.position.y = 0.015;
infield.receiveShadow = true;
scene.add(infield);
// Track base, individual lanes, lane lines and curbs.
scene.add(
makeStadiumStrip(
INNER_RADIUS - 0.35,
OUTER_RADIUS + 0.36,
0.08,
material(0x963f32)
)
);
const laneSurfaceColors = [0xb95843, 0xc5634d];
for (let i = 0; i < LANE_COUNT; i++) {
const r0 = INNER_RADIUS + i * LANE_WIDTH;
const r1 = r0 + LANE_WIDTH;
scene.add(
makeStadiumStrip(
r0,
r1,
0.12,
material(laneSurfaceColors[i % 2])
)
);
}
for (let i = 0; i <= LANE_COUNT; i++) {
const r = INNER_RADIUS + i * LANE_WIDTH;
scene.add(
makeStadiumStrip(
r - 0.035,
r + 0.035,
0.155,
material(0xf8f4e8)
)
);
}
scene.add(
makeStadiumStrip(
INNER_RADIUS - 0.24,
INNER_RADIUS,
0.17,
material(0xf2eee1)
)
);
scene.add(
makeStadiumStrip(
OUTER_RADIUS,
OUTER_RADIUS + 0.34,
0.17,
material(0xf2eee1)
)
);
// ------------------------------------------------------------
// Canvas-generated signs and labels
// ------------------------------------------------------------
function textSprite(
text,
background = "#ffffff",
foreground = "#14213d",
width = 4,
height = 1.5,
options = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = options.tall ? 256 : 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
if (options.border) {
ctx.strokeStyle = options.border;
ctx.lineWidth = 12;
ctx.strokeRect(6, 6, canvas.width - 12, canvas.height - 12);
}
const fontSize = options.fontSize || 62;
ctx.fillStyle = foreground;
ctx.font = `900 ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(
text,
canvas.width / 2,
canvas.height / 2,
canvas.width - 38
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: options.depthTest !== false,
depthWrite: false
})
);
sprite.scale.set(width, height, 1);
return sprite;
}
// ------------------------------------------------------------
// Staggered start markers and common finish line
// ------------------------------------------------------------
laneStartDistances.forEach((startDistance, laneIndex) => {
const radius = laneRadii[laneIndex];
const p = pathPoint(radius, startDistance);
const yaw = Math.atan2(p.tx, p.tz);
const marker = new THREE.Group();
marker.position.set(p.x, 0.205, p.z);
marker.rotation.y = yaw;
const startLine = box(
LANE_WIDTH - 0.08,
0.045,
0.19,
0xff7b27,
0,
0,
0,
{ castShadow: false }
);
marker.add(startLine);
const pole = box(
0.08,
1.05,
0.08,
0xff7b27,
LANE_WIDTH * 0.63,
0.52,
0
);
marker.add(pole);
const cap = box(
0.2,
0.16,
0.2,
0xfff1d5,
LANE_WIDTH * 0.63,
1.07,
0
);
marker.add(cap);
scene.add(marker);
const label = textSprite(
`L${laneIndex + 1}`,
"#fff3df",
"#b33b08",
1.55,
0.85,
{ border: "#ff7b27", fontSize: 72 }
);
label.position.set(
p.x + p.rx * 1.45,
2.05,
p.z + p.rz * 1.45
);
scene.add(label);
});
// Checkered common finish line across all eight lanes.
for (let lane = 0; lane < LANE_COUNT; lane++) {
const r = laneRadii[lane];
for (let sub = 0; sub < 2; sub++) {
const z =
-INNER_RADIUS -
lane * LANE_WIDTH -
sub * (LANE_WIDTH / 2) -
LANE_WIDTH / 4;
const isWhite = (lane + sub) % 2 === 0;
scene.add(
box(
0.62,
0.045,
LANE_WIDTH / 2,
isWhite ? 0xffffff : 0x172033,
FINISH_X,
0.205,
z,
{ castShadow: false }
)
);
}
}
// Finish gantry.
scene.add(
box(0.38, 6.4, 0.38, 0xffffff, FINISH_X, 3.2, -INNER_RADIUS + 0.2)
);
scene.add(
box(0.38, 6.4, 0.38, 0xffffff, FINISH_X, 3.2, -OUTER_RADIUS - 0.2)
);
scene.add(
box(
0.42,
0.42,
OUTER_RADIUS - INNER_RADIUS + 1.0,
0xff6b35,
FINISH_X,
6.45,
-(INNER_RADIUS + OUTER_RADIUS) / 2
)
);
const finishSign = textSprite(
"FINISH",
"#ffffff",
"#14213d",
4.8,
1.25,
{ border: "#ff6b35", fontSize: 70 }
);
finishSign.position.set(FINISH_X, 7.25, -(INNER_RADIUS + OUTER_RADIUS) / 2);
scene.add(finishSign);
// ------------------------------------------------------------
// Voxel runners
// ------------------------------------------------------------
const runners = [];
function createRunner(color, laneIndex) {
const group = new THREE.Group();
const body = new THREE.Group();
group.add(body);
group.scale.setScalar(1.12);
const uniform = material(color, 0.72);
const dark = material(0x1c2940);
const skin = material(
[0xf2bd91, 0x9c6045, 0xe09a72, 0xc27a55][laneIndex % 4],
0.9
);
const shoe = material(0xf7f1df);
const torso = box(0.54, 0.62, 0.31, color, 0, 1.17, 0, {
material: uniform
});
body.add(torso);
body.add(
box(0.33, 0.24, 0.035, 0xfaf7ec, 0, 1.22, 0.174, {
castShadow: false
})
);
const head = box(0.34, 0.34, 0.32, skin.color, 0, 1.72, 0, {
material: skin
});
body.add(head);
body.add(
box(0.36, 0.12, 0.34, dark.color, 0, 1.91, -0.01, {
material: dark
})
);
// Pixel eyes on the forward face.
body.add(
box(0.045, 0.045, 0.025, 0x101827, -0.08, 1.76, 0.173, {
castShadow: false
})
);
body.add(
box(0.045, 0.045, 0.025, 0x101827, 0.08, 1.76, 0.173, {
castShadow: false
})
);
const legs = [];
const arms = [];
for (const side of [-1, 1]) {
const legPivot = new THREE.Group();
legPivot.position.set(side * 0.16, 0.82, 0);
body.add(legPivot);
legPivot.add(
box(0.19, 0.7, 0.21, dark.color, 0, -0.35, 0, {
material: dark
})
);
legPivot.add(
box(0.22, 0.14, 0.34, shoe.color, 0, -0.73, 0.07, {
material: shoe
})
);
legs.push(legPivot);
const armPivot = new THREE.Group();
armPivot.position.set(side * 0.37, 1.42, 0);
body.add(armPivot);
armPivot.add(
box(0.16, 0.58, 0.18, uniform.color, 0, -0.27, 0, {
material: uniform
})
);
armPivot.add(
box(0.17, 0.17, 0.18, skin.color, 0, -0.59, 0, {
material: skin
})
);
arms.push(armPivot);
}
group.userData = {
body,
legs,
arms,
laneIndex,
color
};
scene.add(group);
runners.push(group);
}
laneColors.forEach((color, i) => createRunner(color, i));
// ------------------------------------------------------------
// Original school scene: building, bleachers, spectators and trees
// ------------------------------------------------------------
// School building on the far side of the field.
scene.add(box(45, 12, 14, 0xb34e3f, -33, 6, -72));
scene.add(box(48, 1.1, 16, 0x243755, -33, 12.5, -72));
scene.add(box(37, 2.1, 12, 0xc86450, -33, 13.8, -72));
scene.add(box(25, 2.2, 10, 0xd3755d, -33, 15.4, -72));
scene.add(box(14, 1.8, 8, 0xe08768, -33, 17, -72));
// Windows.
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 8; col++) {
scene.add(
box(
3.0,
2.5,
0.16,
0x9ed9ed,
-51 + col * 5.2,
3.6 + row * 4.2,
-64.91,
{ roughness: 0.35, metalness: 0.05 }
)
);
}
}
scene.add(box(5.0, 6.0, 0.18, 0x243755, -33, 3, -64.9));
scene.add(box(0.16, 6.0, 0.22, 0xf3d59e, -33, 3, -64.78));
const schoolSign = textSprite(
"MAPLE RIDGE HIGH",
"#243755",
"#ffffff",
15,
2.1,
{ fontSize: 54 }
);
schoolSign.position.set(-33, 15.8, -63.8);
scene.add(schoolSign);
// Bleachers.
for (let tier = 0; tier < 4; tier++) {
scene.add(
box(
43,
0.65,
1.65,
tier % 2 ? 0xd8e0e8 : 0xc7d1dc,
18,
0.35 + tier * 0.65,
-51.5 - tier * 1.55
)
);
}
// Small voxel spectators.
const spectatorColors = [
0xef5350, 0x42a5f5, 0xffca28, 0x66bb6a, 0xab47bc, 0xff7043
];
let randomSeed = 9182;
function seededRandom() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
for (let tier = 0; tier < 4; tier++) {
for (let i = 0; i < 14; i++) {
const x = -1 + i * 3.0 + (seededRandom() - 0.5);
const y = 0.95 + tier * 0.65;
const z = -51.2 - tier * 1.55;
const color = spectatorColors[
Math.floor(seededRandom() * spectatorColors.length)
];
scene.add(box(0.48, 0.62, 0.42, color, x, y, z));
scene.add(
box(
0.36,
0.36,
0.34,
0xe6b48d,
x,
y + 0.48,
z
)
);
}
}
// Voxel trees.
function addTree(x, z, scale = 1) {
scene.add(
box(
1.2 * scale,
5.5 * scale,
1.2 * scale,
0x78523a,
x,
2.75 * scale,
z
)
);
scene.add(
box(
5.3 * scale,
4.1 * scale,
4.8 * scale,
0x3f7f45,
x,
6.4 * scale,
z
)
);
scene.add(
box(
3.7 * scale,
3.3 * scale,
4.2 * scale,
0x4e9950,
x + 0.8 * scale,
8.9 * scale,
z - 0.2 * scale
)
);
}
[
[-86, -73, 1.15],
[-72, -88, 0.95],
[-10, -92, 1.1],
[10, -88, 0.9],
[66, -82, 1.15],
[84, -65, 1.0],
[-94, -35, 0.85],
[94, -42, 0.9]
].forEach((v) => addTree(...v));
// Scoreboard.
scene.add(box(18, 8.5, 1.1, 0x243755, 70, 5.2, -14));
scene.add(box(19, 0.5, 1.3, 0xff6b35, 70, 9.6, -14));
scene.add(box(1.0, 8.5, 1.0, 0x60708c, 62, 4.2, -14));
scene.add(box(1.0, 8.5, 1.0, 0x60708c, 78, 4.2, -14));
const scoreboardText = textSprite(
"EQUAL SPEED\nEQUAL 400 m",
"#172033",
"#ffffff",
14.8,
4.8,
{ tall: true, fontSize: 48 }
);
scoreboardText.position.set(70, 5.3, -13.4);
scene.add(scoreboardText);
// Flag poles in the infield.
for (let i = 0; i < 5; i++) {
const x = -38 + i * 8;
scene.add(box(0.12, 7, 0.12, 0xe9eef3, x, 3.5, 23));
scene.add(
box(
2.5,
1.25,
0.08,
i % 2 ? 0xffca3a : 0x29c5df,
x + 1.2,
6.25,
23
)
);
}
// ------------------------------------------------------------
// Finish celebration confetti
// ------------------------------------------------------------
const confetti = [];
const confettiColors = [
0xff6b35, 0x29c5df, 0xffca3a, 0x7758e8, 0x58ce6c
];
for (let i = 0; i < 44; i++) {
const mesh = box(
0.22,
0.08,
0.13,
confettiColors[i % confettiColors.length],
0,
0,
0,
{ castShadow: false }
);
mesh.visible = false;
scene.add(mesh);
confetti.push({
mesh,
x: FINISH_X + (seededRandom() - 0.5) * 24,
z: -40 + (seededRandom() - 0.5) * 13,
y0: 8 + seededRandom() * 15,
phase: seededRandom() * Math.PI * 2,
speed: 3 + seededRandom() * 3
});
}
// ------------------------------------------------------------
// UI construction
// ------------------------------------------------------------
const tableBody = document.getElementById("lane-table-body");
const progressBars = document.getElementById("progress-bars");
laneColors.forEach((color, i) => {
const shift = Math.max(0, laneLengths[i] - laneLengths[0]);
const row = document.createElement("tr");
row.innerHTML = `
<td>
<span class="lane-chip" style="background:#${color.toString(16).padStart(6, "0")}"></span>
Lane ${i + 1}
</td>
<td>${laneLengths[i].toFixed(1)} m</td>
<td>+${shift.toFixed(1)} m</td>
`;
tableBody.appendChild(row);
const track = document.createElement("div");
track.className = "progress-track";
const fill = document.createElement("div");
fill.className = "progress-fill";
fill.style.background = `#${color.toString(16).padStart(6, "0")}`;
track.appendChild(fill);
progressBars.appendChild(track);
});
const progressFills = [
...document.querySelectorAll(".progress-fill")
];
const statusDot = document.getElementById("status-dot");
const statusText = document.getElementById("status-text");
const distanceValue = document.getElementById("distance-value");
const raceClock = document.getElementById("race-clock");
const countdown = document.getElementById("countdown");
const pauseButton = document.getElementById("pause");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speed-value");
// ------------------------------------------------------------
// Camera controls implemented directly without addons
// ------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0, 0),
radius: 153,
theta: 0.54,
phi: 0.87
};
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
orbit.theta -= dx * 0.005;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.22,
1.35
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (e) => e.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
25,
220
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
const key = event.key.toLowerCase();
if (key === "arrowleft") orbit.theta -= 0.08;
if (key === "arrowright") orbit.theta += 0.08;
if (key === "arrowup") {
orbit.phi = THREE.MathUtils.clamp(orbit.phi - 0.06, 0.22, 1.35);
}
if (key === "arrowdown") {
orbit.phi = THREE.MathUtils.clamp(orbit.phi + 0.06, 0.22, 1.35);
}
if (key === "+" || key === "=") orbit.radius *= 0.92;
if (key === "-" || key === "_") orbit.radius *= 1.08;
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 25, 220);
});
document.getElementById("overview").addEventListener("click", () => {
orbit.target.set(0, 0, 0);
orbit.radius = 153;
orbit.theta = 0.54;
orbit.phi = 0.87;
});
document.getElementById("finish-view").addEventListener("click", () => {
orbit.target.set(FINISH_X, 0, -40);
orbit.radius = 48;
orbit.theta = 0.43;
orbit.phi = 0.78;
});
// ------------------------------------------------------------
// Race state and animation
// ------------------------------------------------------------
let mode = "ready";
let raceDistance = 0;
let countdownRemaining = 3.2;
let goTimer = 0;
let paused = false;
let playbackSpeed = Number(speedInput.value);
let confettiTime = 0;
function beginCountdown() {
mode = "countdown";
raceDistance = 0;
countdownRemaining = 3.2;
goTimer = 0;
paused = false;
pauseButton.textContent = "Pause";
confetti.forEach(({ mesh }) => {
mesh.visible = false;
});
}
document.getElementById("replay").addEventListener("click", beginCountdown);
pauseButton.addEventListener("click", () => {
if (mode !== "running") return;
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
speedInput.addEventListener("input", () => {
playbackSpeed = Number(speedInput.value);
speedValue.textContent = `×${playbackSpeed}`;
});
function updateRunnerTransforms() {
runners.forEach((runner, i) => {
const radius = laneRadii[i];
const p = pathPoint(
radius,
laneStartDistances[i] + raceDistance
);
runner.position.set(p.x, 0.22, p.z);
runner.rotation.y = Math.atan2(p.tx, p.tz);
const phase = raceDistance * 2.35 + i * 0.12;
const swing = Math.sin(phase) * 0.62;
const { legs, arms, body } = runner.userData;
legs[0].rotation.x = swing;
legs[1].rotation.x = -swing;
arms[0].rotation.x = -swing * 0.82;
arms[1].rotation.x = swing * 0.82;
if (mode === "finished") {
arms[0].rotation.z = -1.0;
arms[1].rotation.z = 1.0;
arms[0].rotation.x = 0;
arms[1].rotation.x = 0;
} else {
arms[0].rotation.z = 0;
arms[1].rotation.z = 0;
}
body.position.y =
mode === "running" || mode === "finished"
? Math.abs(Math.sin(phase)) * 0.035
: 0;
});
}
function updateConfetti(dt) {
if (mode !== "finished") return;
confettiTime += dt;
confetti.forEach((piece, i) => {
piece.mesh.visible = true;
piece.mesh.position.set(
piece.x + Math.sin(confettiTime * 2 + piece.phase) * 1.2,
piece.y0 - confettiTime * piece.speed,
piece.z + Math.cos(confettiTime * 1.7 + piece.phase) * 0.8
);
piece.mesh.rotation.x = confettiTime * 3 + i;
piece.mesh.rotation.z = confettiTime * 2 + i * 0.3;
if (piece.mesh.position.y < 0.4) {
piece.mesh.position.y = 0.4;
}
});
}
function updateHUD() {
const percentage = Math.min(100, (raceDistance / RACE_DISTANCE) * 100);
distanceValue.textContent = `${raceDistance.toFixed(1)} m`;
raceClock.textContent = `${(raceDistance / RUNNER_SPEED).toFixed(1)} s`;
progressFills.forEach((fill) => {
fill.style.width = `${percentage}%`;
});
if (mode === "countdown") {
const number = Math.ceil(countdownRemaining);
countdown.textContent = number > 0 ? String(number) : "GO!";
statusText.textContent = "Staggered positions locked";
statusDot.style.background = "#ffb020";
statusDot.style.boxShadow = "0 0 0 5px rgba(255,176,32,.15)";
} else if (mode === "running") {
countdown.textContent = goTimer > 0 ? "GO!" : "";
statusText.textContent = paused
? "Race paused"
: "All runners moving at 6.5 m/s";
statusDot.style.background = "#26bf71";
statusDot.style.boxShadow = "0 0 0 5px rgba(38,191,113,.15)";
} else if (mode === "finished") {
countdown.textContent = "TOGETHER!";
statusText.textContent = "All eight finished simultaneously";
statusDot.style.background = "#29c5df";
statusDot.style.boxShadow = "0 0 0 5px rgba(41,197,223,.15)";
}
}
const clock = new THREE.Clock();
let hudAccumulator = 0;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
if (mode === "countdown") {
countdownRemaining -= dt;
if (countdownRemaining <= 0) {
mode = "running";
goTimer = 0.65;
}
} else if (mode === "running") {
raceDistance = Math.min(
RACE_DISTANCE,
raceDistance + dt * RUNNER_SPEED * playbackSpeed
);
goTimer = Math.max(0, goTimer - dt);
if (raceDistance >= RACE_DISTANCE) {
mode = "finished";
confettiTime = 0;
}
}
}
updateRunnerTransforms();
updateConfetti(dt);
updateCamera();
hudAccumulator += dt;
if (hudAccumulator > 0.08) {
updateHUD();
hudAccumulator = 0;
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateRunnerTransforms();
updateCamera();
updateHUD();
beginCountdown();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```