Prompt specification
Build or customize the Three.js 3D scene "School Court Rotation Teaching Scene" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: School Court Rotation Teaching Scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/school-court-rotation-teaching-scene-x3667
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Build a small volleyball court with original stylized players and clear position markers. Allow stepwise rotation and inspect where each player starts and finishes.
Working Three.js Starter (school-court-rotation-teaching-scene-x3667):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Rotation Lab</title>
<style>
:root {
--bg: #090e1a;
--panel: #111a2b;
--panel-2: #172237;
--line: rgba(170, 198, 230, 0.14);
--text: #eef6ff;
--muted: #93a8c3;
--cyan: #35d8ee;
--coral: #ff7187;
--green: #65e6ae;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 350px;
width: 100%;
height: 100%;
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
background:
radial-gradient(circle at 45% 30%, #172740 0%, #0a1220 48%, #070b14 100%);
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.scene-header {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
z-index: 3;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.title-block {
max-width: 520px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
content: "";
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 14px rgba(53, 216, 238, 0.75);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 0;
color: #afc2d9;
font-size: 13px;
line-height: 1.5;
}
.court-chip {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(10, 18, 31, 0.72);
color: #c7d7e9;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.legend {
position: absolute;
bottom: 24px;
left: 24px;
z-index: 3;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100% - 48px);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(10, 18, 31, 0.76);
color: #c9d8e9;
font-size: 11px;
font-weight: 700;
backdrop-filter: blur(10px);
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
}
.swatch.start {
background: var(--cyan);
box-shadow: 0 0 10px rgba(53, 216, 238, 0.6);
}
.swatch.finish {
background: var(--coral);
box-shadow: 0 0 10px rgba(255, 113, 135, 0.6);
}
.swatch.path {
height: 3px;
border-radius: 2px;
background: #a78bfa;
}
.scene-help {
position: absolute;
right: 24px;
bottom: 24px;
z-index: 3;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(10, 18, 31, 0.72);
color: #91a7c0;
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(10px);
}
#tooltip {
position: absolute;
z-index: 8;
display: none;
min-width: 120px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
background: rgba(8, 14, 25, 0.94);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.35);
pointer-events: none;
transform: translate(12px, 12px);
}
#tooltip strong,
#tooltip small {
display: block;
}
#tooltip strong {
margin-bottom: 2px;
font-size: 12px;
}
#tooltip small {
color: var(--muted);
font-size: 10px;
}
aside {
position: relative;
z-index: 5;
overflow: auto;
padding: 20px;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 24%),
var(--panel);
box-shadow: -18px 0 55px rgba(0, 0, 0, 0.18);
}
.panel-section + .panel-section {
margin-top: 22px;
padding-top: 20px;
border-top: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.micro-label {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.step-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.button {
min-height: 38px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel-2);
color: #dce9f7;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.button:hover {
border-color: rgba(53, 216, 238, 0.45);
background: #1c2a41;
}
.button:active {
transform: translateY(1px);
}
.button.active {
border-color: rgba(53, 216, 238, 0.6);
background: rgba(53, 216, 238, 0.14);
color: #aaf5ff;
}
.button.primary {
border-color: rgba(53, 216, 238, 0.38);
background: #17384a;
color: #c9f8ff;
}
.button.wide {
width: 100%;
margin-top: 8px;
}
.angle-readout {
display: flex;
align-items: baseline;
justify-content: space-between;
margin: 11px 1px 4px;
}
.angle-readout strong {
font-variant-numeric: tabular-nums;
font-size: 21px;
letter-spacing: -0.03em;
}
.angle-readout span {
color: var(--muted);
font-size: 10px;
}
.toggle-list {
display: grid;
gap: 8px;
margin-top: 12px;
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
color: #b9cbe0;
font-size: 12px;
cursor: pointer;
}
.toggle input {
width: 16px;
height: 16px;
accent-color: var(--cyan);
cursor: pointer;
}
.roster {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.player-chip {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
padding: 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: #121d30;
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.player-chip:hover {
background: #19263a;
}
.player-chip.selected {
border-color: var(--player);
background: color-mix(in srgb, var(--player) 13%, #121d30);
box-shadow: inset 3px 0 0 var(--player);
}
.jersey-number {
display: grid;
flex: 0 0 25px;
width: 25px;
height: 25px;
place-items: center;
border-radius: 6px;
background: var(--player);
color: #07101c;
font-size: 11px;
font-weight: 900;
}
.player-chip b,
.player-chip small {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.player-chip b {
font-size: 11px;
}
.player-chip small {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.inspector {
margin-top: 12px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: #0e1728;
}
.inspector-top {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
}
.inspector-avatar {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border-radius: 9px;
background: var(--player);
color: #07101c;
font-size: 16px;
font-weight: 900;
}
.inspector-top strong,
.inspector-top small {
display: block;
}
.inspector-top strong {
font-size: 14px;
}
.inspector-top small {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.route {
display: grid;
grid-template-columns: 1fr 20px 1fr;
align-items: center;
gap: 4px;
}
.route-node {
min-width: 0;
padding: 9px;
border-radius: 8px;
background: #152136;
}
.route-node.start {
border-top: 2px solid var(--cyan);
}
.route-node.finish {
border-top: 2px solid var(--coral);
}
.route-node span,
.route-node b,
.route-node small {
display: block;
}
.route-node span {
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
}
.route-node b {
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.route-node small {
margin-top: 3px;
color: #8fa5bf;
font-size: 9px;
}
.route-arrow {
color: #61748e;
text-align: center;
}
.inspector-note {
margin: 11px 0 0;
color: #a9bad0;
font-size: 10px;
line-height: 1.5;
}
.motion-readout {
display: flex;
justify-content: space-between;
margin: 2px 1px 8px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 6px 0 13px;
border-radius: 999px;
accent-color: var(--cyan);
cursor: pointer;
}
.motion-buttons {
display: grid;
grid-template-columns: 1fr 1.3fr 1fr;
gap: 6px;
}
.coordinates-note {
margin: 12px 0 0;
color: #70859e;
font-size: 9px;
line-height: 1.5;
}
#loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #09111f;
color: #a7bdd4;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
html,
body {
overflow: auto;
}
#app {
grid-template-columns: 1fr;
height: auto;
min-height: 100%;
}
#viewport {
height: 58vh;
min-height: 430px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.scene-help {
display: none;
}
}
@media (max-width: 520px) {
.scene-header {
top: 16px;
left: 16px;
right: 16px;
}
.court-chip {
display: none;
}
.subtitle {
max-width: 300px;
font-size: 11px;
}
.legend {
left: 16px;
bottom: 16px;
}
.legend-item {
padding: 6px 8px;
font-size: 9px;
}
aside {
padding: 16px;
}
}
</style>
</head>
<body>
<div id="app">
<main id="viewport">
<canvas id="scene" tabindex="0" aria-label="Interactive voxel volleyball court"></canvas>
<header class="scene-header">
<div class="title-block">
<div class="eyebrow">Movement study</div>
<h1>Voxel Rotation Lab</h1>
<p class="subtitle">
Inspect each player's starting zone and finishing zone, then orbit
the court in deliberate steps.
</p>
</div>
<div class="court-chip">18 × 9 m · Eight-player study</div>
</header>
<div class="legend">
<div class="legend-item"><span class="swatch start"></span>S = start</div>
<div class="legend-item"><span class="swatch finish"></span>F = finish</div>
<div class="legend-item"><span class="swatch path"></span>Dashed route</div>
</div>
<div class="scene-help">Drag to orbit · Wheel to zoom · Click a player</div>
<div id="tooltip"></div>
<div id="loading">Building voxel court…</div>
</main>
<aside>
<section class="panel-section">
<div class="section-heading">
<h2>Stepwise orbit</h2>
<span class="micro-label">Camera controls</span>
</div>
<div class="step-grid">
<button class="button" data-step="-45" type="button">−45°</button>
<button class="button" data-step="-15" type="button">−15°</button>
<button class="button" data-step="15" type="button">+15°</button>
<button class="button" data-step="45" type="button">+45°</button>
</div>
<div class="angle-readout">
<strong id="angleValue">0°</strong>
<span>azimuth</span>
</div>
<button id="autoStep" class="button wide" type="button">
Auto-step 360°
</button>
<button id="resetView" class="button wide" type="button">
Reset court view
</button>
<div class="toggle-list">
<label class="toggle">
<span>Endpoint markers</span>
<input id="toggleMarkers" type="checkbox" checked>
</label>
<label class="toggle">
<span>Movement paths</span>
<input id="togglePaths" type="checkbox" checked>
</label>
<label class="toggle">
<span>Player name tags</span>
<input id="toggleNames" type="checkbox" checked>
</label>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Player inspector</h2>
<span class="micro-label">Select a player</span>
</div>
<div id="roster" class="roster"></div>
<div id="inspector" class="inspector"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Start → finish</h2>
<span class="micro-label">Playback</span>
</div>
<div class="motion-readout">
<span>Movement timeline</span>
<span id="motionValue">0% · START</span>
</div>
<input
id="motionRange"
type="range"
min="0"
max="1000"
value="0"
aria-label="Player movement from start to finish"
>
<div class="motion-buttons">
<button id="goStart" class="button" type="button">Start</button>
<button id="playMotion" class="button primary" type="button">Play</button>
<button id="goFinish" class="button" type="button">Finish</button>
</div>
<p class="coordinates-note">
Coordinates use the court center as X 0 / Z 0. X follows court length;
Z follows court width. S markers are cyan, F markers are coral.
</p>
</section>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Data
// -------------------------------------------------------------------------
const players = [
{
id: "mara",
name: "Mara",
role: "Setter",
team: "HOME",
number: 1,
color: "#55dfd1",
skin: "#d99b76",
hair: "#253149",
start: [-4.7, -2.8],
finish: [-1.8, -1.45],
note: "Moves from the back-right zone into the front-right setter position."
},
{
id: "ivo",
name: "Ivo",
role: "Opposite",
team: "HOME",
number: 4,
color: "#ffc857",
skin: "#b87956",
hair: "#39241f",
start: [-1.8, -1.45],
finish: [-1.8, 1.45],
note: "Rotates through the front row and finishes on the opposite front zone."
},
{
id: "nia",
name: "Nia",
role: "Outside",
team: "HOME",
number: 7,
color: "#f48fb1",
skin: "#8f5a45",
hair: "#171b28",
start: [-1.8, 1.45],
finish: [-4.7, 2.8],
note: "Leaves the front-left zone and completes the rotation in the back row."
},
{
id: "sol",
name: "Sol",
role: "Middle",
team: "HOME",
number: 9,
color: "#a991ff",
skin: "#e4b58f",
hair: "#d9a441",
start: [-4.7, 2.8],
finish: [-4.7, -2.8],
note: "Crosses the back zone during the rotation and finishes behind the setter."
},
{
id: "kip",
name: "Kip",
role: "Libero",
team: "AWAY",
number: 2,
color: "#62e6a9",
skin: "#6f4739",
hair: "#111827",
start: [4.7, 2.8],
finish: [1.8, 1.45],
note: "Advances from the back-left zone to a front-row defensive position."
},
{
id: "ada",
name: "Ada",
role: "Outside",
team: "AWAY",
number: 5,
color: "#62a8ff",
skin: "#efbd98",
hair: "#8f4930",
start: [1.8, 1.45],
finish: [1.8, -1.45],
note: "Moves across the front row and finishes on the opposite attacking zone."
},
{
id: "leo",
name: "Leo",
role: "Middle",
team: "AWAY",
number: 8,
color: "#ff9d57",
skin: "#b97858",
hair: "#281d1c",
start: [1.8, -1.45],
finish: [4.7, -2.8],
note: "Drops from the front zone into the back-right finishing position."
},
{
id: "zoe",
name: "Zoë",
role: "Opposite",
team: "AWAY",
number: 11,
color: "#ed7eb4",
skin: "#7d4b3b",
hair: "#20263a",
start: [4.7, -2.8],
finish: [4.7, 2.8],
note: "Travels around the back row to complete the away-side rotation."
}
];
const FLOOR_Y = 0.17;
const COURT_LENGTH = 18;
const COURT_WIDTH = 9;
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const viewport = document.querySelector("#viewport");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a1220);
scene.fog = new THREE.Fog(0x0a1220, 35, 75);
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 150);
const cameraState = {
theta: 0.82,
phi: 1.02,
radius: 24,
targetTheta: 0.82,
targetPhi: 1.02,
targetRadius: 24,
target: new THREE.Vector3(0, 0.8, 0),
targetGoal: new THREE.Vector3(0, 0.8, 0)
};
const hemisphere = new THREE.HemisphereLight(0xc5e6ff, 0x283043, 2.35);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-9, 18, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -14;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 50;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x52d9ff, 1.4);
rimLight.position.set(13, 8, -12);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8a65, 22, 28, 2);
warmLight.position.set(-8, 5, -6);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextTexture(
text,
background = "rgba(9,16,28,0.90)",
foreground = "#eef8ff",
width = 256,
height = 96
) {
const textCanvas = document.createElement("canvas");
textCanvas.width = width;
textCanvas.height = height;
const ctx = textCanvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
roundedRect(ctx, 3, 3, width - 6, height - 6, 18);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.16)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = `800 ${Math.round(height * 0.38)}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeLabelSprite(
text,
options = {
scale: [1.5, 0.5],
background: "rgba(9,16,28,0.90)",
foreground: "#eef8ff"
}
) {
const texture = makeTextTexture(
text,
options.background,
options.foreground
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(options.scale[0], options.scale[1], 1);
sprite.renderOrder = 20;
return sprite;
}
function addBox(
parent,
size,
position,
material,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] || 0,
options.rotation[1] || 0,
options.rotation[2] || 0
);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function makeGroundText(text, x, z, width, color = "#dceaf4") {
const texture = makeTextTexture(
text,
"rgba(0,0,0,0)",
color,
512,
128
);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width / 4),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, FLOOR_Y + 0.035, z);
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Ground, court, lines, net
// -------------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x101a2a,
roughness: 0.96,
metalness: 0.03
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.52;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(80, 80, 0x263a52, 0x18283d);
grid.position.y = -0.505;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const courtBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x26354b,
roughness: 0.88
});
const courtBase = new THREE.Mesh(
new THREE.BoxGeometry(20.5, 0.5, 11.5),
courtBaseMaterial
);
courtBase.position.y = -0.25;
courtBase.castShadow = true;
courtBase.receiveShadow = true;
scene.add(courtBase);
const courtMaterial = new THREE.MeshStandardMaterial({
color: 0x287d82,
roughness: 0.78,
metalness: 0.02
});
const court = new THREE.Mesh(
new THREE.BoxGeometry(COURT_LENGTH, 0.16, COURT_WIDTH),
courtMaterial
);
court.position.y = 0.08;
court.castShadow = true;
court.receiveShadow = true;
scene.add(court);
const lineMaterial = new THREE.MeshStandardMaterial({
color: 0xf3f7ee,
roughness: 0.72
});
function courtLine(size, x, z) {
return addBox(
scene,
size,
[x, FLOOR_Y + 0.013, z],
lineMaterial,
{ castShadow: false }
);
}
courtLine([COURT_LENGTH, 0.026, 0.09], 0, -COURT_WIDTH / 2);
courtLine([COURT_LENGTH, 0.026, 0.09], 0, COURT_WIDTH / 2);
courtLine([0.09, 0.026, COURT_WIDTH], -COURT_LENGTH / 2, 0);
courtLine([0.09, 0.026, COURT_WIDTH], COURT_LENGTH / 2, 0);
courtLine([0.075, 0.026, COURT_WIDTH], -3, 0);
courtLine([0.075, 0.026, COURT_WIDTH], 3, 0);
// Voxel border blocks.
const borderMaterial = new THREE.MeshStandardMaterial({
color: 0x1a3147,
roughness: 0.7,
metalness: 0.18
});
for (let x = -9.75; x <= 9.75; x += 0.75) {
addBox(
scene,
[0.7, 0.22, 0.45],
[x, -0.05, -5.42],
borderMaterial
);
addBox(
scene,
[0.7, 0.22, 0.45],
[x, -0.05, 5.42],
borderMaterial
);
}
makeGroundText("HOME", -7.25, 3.7, 2.5, "#d9f8f2");
makeGroundText("AWAY", 7.25, -3.7, 2.5, "#ffe5e9");
const netGroup = new THREE.Group();
scene.add(netGroup);
const postMaterial = new THREE.MeshStandardMaterial({
color: 0xdbe6ef,
roughness: 0.46,
metalness: 0.55
});
const netMaterial = new THREE.MeshBasicMaterial({
color: 0x152233,
transparent: true,
opacity: 0.66
});
const antennaMaterial = new THREE.MeshStandardMaterial({
color: 0xff657c,
emissive: 0x5c0c18,
emissiveIntensity: 0.3,
roughness: 0.45
});
for (const z of [-4.9, 4.9]) {
addBox(
netGroup,
[0.18, 2.85, 0.18],
[0, 1.42, z],
postMaterial
);
addBox(
netGroup,
[0.16, 0.16, 0.8],
[0, 1.0, z + Math.sign(z) * 0.12],
postMaterial
);
}
addBox(
netGroup,
[0.09, 0.1, 9.7],
[0, 2.48, 0],
postMaterial
);
for (let z = -4.5; z <= 4.5; z += 0.5) {
addBox(
netGroup,
[0.025, 1.83, 0.025],
[0, 1.55, z],
netMaterial,
{ castShadow: false }
);
}
for (const y of [0.68, 1.12, 1.56, 2.0, 2.43]) {
addBox(
netGroup,
[0.025, 0.025, 9.1],
[0, y, 0],
netMaterial,
{ castShadow: false }
);
}
for (const z of [-4.52, 4.52]) {
addBox(
netGroup,
[0.065, 1.12, 0.065],
[0, 2.95, z],
antennaMaterial,
{ castShadow: false }
);
}
// -------------------------------------------------------------------------
// Low voxel stands and corner beacons
// -------------------------------------------------------------------------
const standMaterial = new THREE.MeshStandardMaterial({
color: 0x19283b,
roughness: 0.92
});
const seatColors = [
0x416a8a,
0x695b91,
0x3f847d,
0x9c5d72,
0x9a7948
];
for (const side of [-1, 1]) {
addBox(
scene,
[18.8, 0.35, 1.25],
[0, -0.16, side * 6.1],
standMaterial
);
for (let i = 0; i < 13; i++) {
const x = -8.4 + i * 1.4;
const material = new THREE.MeshStandardMaterial({
color: seatColors[i % seatColors.length],
roughness: 0.82
});
addBox(
scene,
[0.68, 0.42, 0.62],
[x, 0.12, side * 6.18],
material
);
if (i % 2 === 0) {
const spectatorMaterial = new THREE.MeshStandardMaterial({
color: [0xe2aa83, 0x9b634d, 0xd79b79][i % 3],
roughness: 0.9
});
addBox(
scene,
[0.24, 0.27, 0.24],
[x, 0.47, side * 6.18],
spectatorMaterial
);
}
}
}
const beaconBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x22354b,
roughness: 0.75,
metalness: 0.25
});
const beaconLightMaterial = new THREE.MeshStandardMaterial({
color: 0x55e8ff,
emissive: 0x1a8ea7,
emissiveIntensity: 1.2,
roughness: 0.35
});
for (const x of [-10.2, 10.2]) {
for (const z of [-6.1, 6.1]) {
addBox(
scene,
[0.55, 2.15, 0.55],
[x, 0.55, z],
beaconBaseMaterial
);
addBox(
scene,
[0.64, 0.32, 0.64],
[x, 1.72, z],
beaconLightMaterial,
{ castShadow: false }
);
}
}
// -------------------------------------------------------------------------
// Players and endpoint markers
// -------------------------------------------------------------------------
const playerObjects = [];
const markerObjects = [];
const interactiveObjects = [];
function createFrameMarker(color, label, x, z, playerId) {
const group = new THREE.Group();
group.position.set(x, FLOOR_Y + 0.025, z);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.42,
roughness: 0.5,
metalness: 0.12
});
const size = 1.02;
const thickness = 0.075;
addBox(
group,
[size, thickness, thickness],
[0, 0, -size / 2],
material,
{ castShadow: false }
);
addBox(
group,
[size, thickness, thickness],
[0, 0, size / 2],
material,
{ castShadow: false }
);
addBox(
group,
[thickness, thickness, size],
[-size / 2, 0, 0],
material,
{ castShadow: false }
);
addBox(
group,
[thickness, thickness, size],
[size / 2, 0, 0],
material,
{ castShadow: false }
);
addBox(
group,
[0.065, 0.48, 0.065],
[-size / 2, 0.23, -size / 2],
material,
{ castShadow: false }
);
const sprite = makeLabelSprite(label, {
scale: [0.82, 0.31],
background: "rgba(7,15,26,0.92)",
foreground: color
});
sprite.position.set(0, 0.56, 0);
group.add(sprite);
group.traverse((child) => {
child.userData.playerId = playerId;
});
scene.add(group);
return {
group,
sprite,
material,
baseScale: 1,
playerId
};
}
function createPlayer(data) {
const root = new THREE.Group();
const jerseyMaterial = new THREE.MeshStandardMaterial({
color: data.color,
roughness: 0.73,
metalness: 0.03,
emissive: data.color,
emissiveIntensity: 0
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: data.skin,
roughness: 0.9
});
const hairMaterial = new THREE.MeshStandardMaterial({
color: data.hair,
roughness: 0.92
});
const shortsMaterial = new THREE.MeshStandardMaterial({
color: data.team === "HOME" ? 0x162c45 : 0x25213e,
roughness: 0.84
});
const shoeMaterial = new THREE.MeshStandardMaterial({
color: 0xf4f5ef,
roughness: 0.62
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x101722,
roughness: 0.7
});
// Shoes and legs.
for (const side of [-1, 1]) {
addBox(
root,
[0.31, 0.16, 0.48],
[side * 0.19, 0.08, 0.055],
shoeMaterial
);
addBox(
root,
[0.26, 0.68, 0.28],
[side * 0.19, 0.5, 0],
skinMaterial
);
}
addBox(root, [0.72, 0.25, 0.43], [0, 0.82, 0], shortsMaterial);
addBox(root, [0.78, 0.73, 0.44], [0, 1.26, 0], jerseyMaterial);
// Small chest band.
addBox(
root,
[0.8, 0.08, 0.455],
[0, 1.46, 0],
new THREE.MeshStandardMaterial({
color: 0xf4f8f4,
roughness: 0.65
})
);
// Arms and hands.
for (const side of [-1, 1]) {
addBox(
root,
[0.23, 0.63, 0.27],
[side * 0.51, 1.16, 0],
skinMaterial,
{ rotation: [0, 0, side * 0.12] }
);
addBox(
root,
[0.24, 0.22, 0.25],
[side * 0.55, 0.75, 0],
skinMaterial
);
}
// Neck and head.
addBox(root, [0.22, 0.18, 0.23], [0, 1.7, 0], skinMaterial);
addBox(root, [0.55, 0.55, 0.55], [0, 2.0, 0], skinMaterial);
addBox(root, [0.59, 0.16, 0.59], [0, 2.24, -0.015], hairMaterial);
addBox(root, [0.59, 0.27, 0.15], [0, 2.1, -0.24], hairMaterial);
// Face details.
addBox(
root,
[0.07, 0.07, 0.025],
[-0.12, 2.02, 0.285],
darkMaterial,
{ castShadow: false }
);
addBox(
root,
[0.07, 0.07, 0.025],
[0.12, 2.02, 0.285],
darkMaterial,
{ castShadow: false }
);
// Distinctive headband for the setter.
if (data.id === "mara") {
addBox(
root,
[0.61, 0.09, 0.61],
[0, 2.18, 0],
new THREE.MeshStandardMaterial({
color: 0xf5f0c9,
roughness: 0.6
})
);
}
// Number sprite.
const numberSprite = makeLabelSprite(String(data.number), {
scale: [0.38, 0.38],
background: "rgba(8,15,27,0.86)",
foreground: data.color
});
numberSprite.position.set(0, 1.27, 0.25);
root.add(numberSprite);
// Name tag.
const nameSprite = makeLabelSprite(`${data.number} ${data.name.toUpperCase()}`, {
scale: [1.45, 0.42],
background: "rgba(8,15,27,0.88)",
foreground: "#eef7ff"
});
nameSprite.position.set(0, 2.67, 0);
root.add(nameSprite);
// Selected-player floor frame.
const selectionMaterial = new THREE.MeshBasicMaterial({
color: data.color,
transparent: true,
opacity: 0.92,
depthWrite: false
});
const selection = new THREE.Group();
selection.position.y = 0.015;
selection.visible = false;
for (const z of [-0.68, 0.68]) {
addBox(
selection,
[1.36, 0.035, 0.055],
[0, 0, z],
selectionMaterial,
{ castShadow: false }
);
}
for (const x of [-0.68, 0.68]) {
addBox(
selection,
[0.055, 0.035, 1.36],
[x, 0, 0],
selectionMaterial,
{ castShadow: false }
);
}
root.add(selection);
root.position.set(data.start[0], FLOOR_Y, data.start[1]);
root.rotation.y = data.team === "HOME" ? Math.PI / 2 : -Math.PI / 2;
root.traverse((child) => {
child.userData.playerId = data.id;
});
scene.add(root);
interactiveObjects.push(root);
return {
data,
root,
jerseyMaterial,
nameSprite,
numberSprite,
selection,
selectionMaterial,
startMarker: null,
finishMarker: null,
path: null
};
}
for (const data of players) {
const player = createPlayer(data);
playerObjects.push(player);
player.startMarker = createFrameMarker(
0x35d8ee,
`S${data.number}`,
data.start[0],
data.start[1],
data.id
);
player.finishMarker = createFrameMarker(
0xff7187,
`F${data.number}`,
data.finish[0],
data.finish[1],
data.id
);
markerObjects.push(player.startMarker, player.finishMarker);
interactiveObjects.push(
player.startMarker.group,
player.finishMarker.group
);
const pathGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(data.start[0], FLOOR_Y + 0.055, data.start[1]),
new THREE.Vector3(data.finish[0], FLOOR_Y + 0.055, data.finish[1])
]);
const pathMaterial = new THREE.LineDashedMaterial({
color: data.color,
dashSize: 0.26,
gapSize: 0.16,
transparent: true,
opacity: 0.72
});
const path = new THREE.Line(pathGeometry, pathMaterial);
path.computeLineDistances();
scene.add(path);
player.path = path;
}
// -------------------------------------------------------------------------
// Voxel volleyball
// -------------------------------------------------------------------------
const ball = new THREE.Group();
const ballMaterial = new THREE.MeshStandardMaterial({
color: 0xf5f0d8,
roughness: 0.76
});
const ballPatchMaterial = new THREE.MeshStandardMaterial({
color: 0x3b92e8,
roughness: 0.72
});
addBox(ball, [0.46, 0.46, 0.46], [0, 0, 0], ballMaterial);
addBox(ball, [0.47, 0.1, 0.47], [0, 0.13, 0], ballPatchMaterial);
addBox(ball, [0.1, 0.47, 0.47], [0.13, 0, 0], ballPatchMaterial);
addBox(ball, [0.47, 0.47, 0.1], [0, 0, -0.13], ballPatchMaterial);
scene.add(ball);
// -------------------------------------------------------------------------
// UI and player selection
// -------------------------------------------------------------------------
const rosterElement = document.querySelector("#roster");
const inspectorElement = document.querySelector("#inspector");
const tooltip = document.querySelector("#tooltip");
let selectedId = players[0].id;
let motion = 0;
let motionPlaying = false;
let autoStepTimer = null;
function formatCoordinate(value) {
return `${value < 0 ? "−" : "+"}${Math.abs(value).toFixed(1)}`;
}
function getSelectedPlayer() {
return playerObjects.find((player) => player.data.id === selectedId);
}
for (const data of players) {
const button = document.createElement("button");
button.type = "button";
button.className = "player-chip";
button.dataset.id = data.id;
button.style.setProperty("--player", data.color);
button.innerHTML = `
<span class="jersey-number">${data.number}</span>
<span>
<b>${data.name}</b>
<small>${data.role}</small>
</span>
`;
rosterElement.appendChild(button);
}
function renderInspector() {
const player = getSelectedPlayer();
const data = player.data;
inspectorElement.style.setProperty("--player", data.color);
inspectorElement.innerHTML = `
<div class="inspector-top">
<div class="inspector-avatar">${data.number}</div>
<div>
<strong>${data.name}</strong>
<small>${data.team} · ${data.role}</small>
</div>
</div>
<div class="route">
<div class="route-node start">
<span>START</span>
<b>X ${formatCoordinate(data.start[0])} m</b>
<small>Z ${formatCoordinate(data.start[1])} m</small>
</div>
<div class="route-arrow">→</div>
<div class="route-node finish">
<span>FINISH</span>
<b>X ${formatCoordinate(data.finish[0])} m</b>
<small>Z ${formatCoordinate(data.finish[1])} m</small>
</div>
</div>
<p class="inspector-note">${data.note}</p>
<button id="focusPlayer" class="button wide" type="button">
Focus ${data.name}
</button>
`;
document.querySelector("#focusPlayer").addEventListener("click", () => {
focusPlayer();
});
}
function selectPlayer(id) {
if (!players.some((player) => player.id === id)) return;
selectedId = id;
for (const button of rosterElement.querySelectorAll(".player-chip")) {
button.classList.toggle("selected", button.dataset.id === selectedId);
}
for (const player of playerObjects) {
const selected = player.data.id === selectedId;
player.jerseyMaterial.emissiveIntensity = selected ? 0.32 : 0;
player.selection.visible = selected;
player.path.material.opacity = selected ? 1 : 0.32;
for (const marker of [player.startMarker, player.finishMarker]) {
marker.material.emissiveIntensity = selected ? 0.95 : 0.42;
marker.sprite.scale.set(
selected ? 1.04 : 0.82,
selected ? 0.4 : 0.31,
1
);
}
}
renderInspector();
}
rosterElement.addEventListener("click", (event) => {
const button = event.target.closest(".player-chip");
if (button) selectPlayer(button.dataset.id);
});
// -------------------------------------------------------------------------
// Motion playback
// -------------------------------------------------------------------------
const motionRange = document.querySelector("#motionRange");
const motionValue = document.querySelector("#motionValue");
const playMotion = document.querySelector("#playMotion");
function updateMotionUI() {
const percent = Math.round(motion * 100);
motionRange.value = String(Math.round(motion * 1000));
motionValue.textContent =
percent === 0
? "0% · START"
: percent === 100
? "100% · FINISH"
: `${percent}% · IN TRANSITION`;
playMotion.textContent = motionPlaying ? "Pause" : "Play";
}
function setMotion(value) {
motion = THREE.MathUtils.clamp(value, 0, 1);
const eased = motion * motion * (3 - 2 * motion);
for (const player of playerObjects) {
const { data, root } = player;
root.position.x = THREE.MathUtils.lerp(
data.start[0],
data.finish[0],
eased
);
root.position.z = THREE.MathUtils.lerp(
data.start[1],
data.finish[1],
eased
);
root.position.y = FLOOR_Y + Math.sin(Math.PI * motion) * 0.045;
}
updateMotionUI();
}
motionRange.addEventListener("input", () => {
motionPlaying = false;
setMotion(Number(motionRange.value) / 1000);
});
document.querySelector("#goStart").addEventListener("click", () => {
motionPlaying = false;
setMotion(0);
});
document.querySelector("#goFinish").addEventListener("click", () => {
motionPlaying = false;
setMotion(1);
});
playMotion.addEventListener("click", () => {
if (!motionPlaying && motion >= 0.999) {
setMotion(0);
}
motionPlaying = !motionPlaying;
updateMotionUI();
});
// -------------------------------------------------------------------------
// Camera: custom orbit controls and discrete stepping
// -------------------------------------------------------------------------
function stepCamera(degrees) {
cameraState.targetTheta += THREE.MathUtils.degToRad(degrees);
updateAngleReadout();
}
function updateAngleReadout() {
let degrees = THREE.MathUtils.radToDeg(cameraState.targetTheta) % 360;
if (degrees < 0) degrees += 360;
document.querySelector("#angleValue").textContent =
`${Math.round(degrees)}°`;
}
for (const button of document.querySelectorAll("[data-step]")) {
button.addEventListener("click", () => {
stepCamera(Number(button.dataset.step));
});
}
const autoStepButton = document.querySelector("#autoStep");
autoStepButton.addEventListener("click", () => {
if (autoStepTimer !== null) {
clearInterval(autoStepTimer);
autoStepTimer = null;
autoStepButton.classList.remove("active");
autoStepButton.textContent = "Auto-step 360°";
return;
}
autoStepButton.classList.add("active");
autoStepButton.textContent = "Stop auto-step";
autoStepTimer = setInterval(() => {
stepCamera(15);
}, 420);
});
function resetView() {
cameraState.target.set(0, 0.8, 0);
cameraState.targetGoal.set(0, 0.8, 0);
cameraState.targetTheta = 0.82;
cameraState.targetPhi = 1.02;
cameraState.targetRadius = 24;
updateAngleReadout();
}
document.querySelector("#resetView").addEventListener("click", resetView);
function focusPlayer() {
const player = getSelectedPlayer();
const goal = new THREE.Vector3(
player.root.position.x,
0.9,
player.root.position.z
);
cameraState.targetGoal.copy(goal);
cameraState.targetRadius = 9.5;
}
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
moved: 0
};
canvas.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.moved = 0;
canvas.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (pointer.active && event.pointerId === pointer.id) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.moved += Math.abs(dx) + Math.abs(dy);
cameraState.targetTheta -= dx * 0.006;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi + dy * 0.005,
0.38,
1.42
);
updateAngleReadout();
return;
}
updateHover(event);
});
canvas.addEventListener("pointerup", (event) => {
if (event.pointerId !== pointer.id) return;
if (pointer.moved < 6) {
pickPlayer(event);
}
pointer.active = false;
pointer.id = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointer.active = false;
pointer.id = null;
});
canvas.addEventListener("pointerleave", () => {
if (!pointer.active) tooltip.style.display = "none";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius + event.deltaY * 0.012,
7,
38
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
stepCamera(-15);
} else if (event.key === "ArrowRight") {
stepCamera(15);
} else if (event.key === "ArrowUp") {
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - 0.12,
0.38,
1.42
);
} else if (event.key === "ArrowDown") {
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi + 0.12,
0.38,
1.42
);
} else if (event.key === " ") {
event.preventDefault();
playMotion.click();
}
});
// -------------------------------------------------------------------------
// Raycasting
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const normalizedPointer = new THREE.Vector2();
function raycastAt(event) {
const rect = canvas.getBoundingClientRect();
normalizedPointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
normalizedPointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(normalizedPointer, camera);
return raycaster.intersectObjects(interactiveObjects, true);
}
function findPlayerId(object) {
let current = object;
while (current) {
if (current.userData.playerId) {
return current.userData.playerId;
}
current = current.parent;
}
return null;
}
function pickPlayer(event) {
const hit = raycastAt(event)[0];
if (!hit) return;
const id = findPlayerId(hit.object);
if (id) selectPlayer(id);
}
function updateHover(event) {
const hit = raycastAt(event)[0];
const id = hit ? findPlayerId(hit.object) : null;
if (!id) {
tooltip.style.display = "none";
canvas.style.cursor = "grab";
return;
}
const data = players.find((player) => player.id === id);
tooltip.innerHTML = `
<strong>${data.name} · #${data.number}</strong>
<small>${data.role} — click to inspect</small>
`;
const rect = viewport.getBoundingClientRect();
tooltip.style.left = `${event.clientX - rect.left}px`;
tooltip.style.top = `${event.clientY - rect.top}px`;
tooltip.style.display = "block";
canvas.style.cursor = "pointer";
}
// -------------------------------------------------------------------------
// Overlay toggles
// -------------------------------------------------------------------------
document.querySelector("#toggleMarkers").addEventListener("change", (event) => {
for (const marker of markerObjects) {
marker.group.visible = event.target.checked;
}
});
document.querySelector("#togglePaths").addEventListener("change", (event) => {
for (const player of playerObjects) {
player.path.visible = event.target.checked;
}
});
document.querySelector("#toggleNames").addEventListener("change", (event) => {
for (const player of playerObjects) {
player.nameSprite.visible = event.target.checked;
}
});
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
function resizeRenderer() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
resizeRenderer();
const clock = new THREE.Clock();
function updateCamera(delta) {
const damping = 1 - Math.exp(-delta * 9);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.targetTheta,
damping
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.targetPhi,
damping
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.targetRadius,
damping
);
cameraState.target.lerp(
cameraState.targetGoal,
damping
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (motionPlaying) {
const next = motion + delta / 2.4;
if (next >= 1) {
setMotion(1);
motionPlaying = false;
updateMotionUI();
} else {
setMotion(next);
}
}
updateCamera(delta);
// A gentle floating volleyball above the net.
ball.position.set(
-2.8 + motion * 5.6,
3.15 + Math.sin(motion * Math.PI) * 2.05,
-1.35 + motion * 2.7
);
ball.rotation.set(
elapsed * 0.65,
elapsed * 0.95,
elapsed * 0.42
);
// Subtle pulse on the selected endpoint markers.
const pulse = 1 + Math.sin(elapsed * 4.2) * 0.055;
for (const player of playerObjects) {
const selected = player.data.id === selectedId;
if (selected) {
player.startMarker.group.scale.setScalar(pulse);
player.finishMarker.group.scale.setScalar(pulse);
} else {
player.startMarker.group.scale.setScalar(1);
player.finishMarker.group.scale.setScalar(1);
}
}
renderer.render(scene, camera);
}
selectPlayer(selectedId);
setMotion(0);
updateAngleReadout();
camera.position.set(16, 14, 17);
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 300);
});
</script>
</body>
</html>
```