Prompt specification
Build or customize the Three.js 3D scene "Scoreboard With Named State Slots" 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: Scoreboard With Named State Slots
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/scoreboard-with-named-state-slots-x3649
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a hierarchical sports scoreboard. Build a generic scoreboard with separate point, game, and set indicators. Show the hierarchy without assuming the same counting rule applies at every level. Stylized solid forms.
Working Three.js Starter (scoreboard-with-named-state-slots-x3649):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hierarchical Sports Scoreboard</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(12, 24, 33, 0.84);
--line: rgba(255, 255, 255, 0.13);
--text: #f4f7f7;
--muted: #8fa4ad;
--point: #ff704d;
--game: #35d7c1;
--set: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
touch-action: none;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
.heading {
top: 28px;
left: 30px;
max-width: 390px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--game);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(24px, 4vw, 42px);
font-weight: 850;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 340px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.hierarchy {
display: flex;
align-items: center;
gap: 8px;
margin-top: 18px;
color: #dbe6e9;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
}
.hierarchy span:nth-child(1) { color: var(--point); }
.hierarchy span:nth-child(3) { color: var(--game); }
.hierarchy span:nth-child(5) { color: var(--set); }
.hierarchy i {
color: #61747c;
font-style: normal;
}
.help {
top: 28px;
right: 28px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(6, 14, 20, 0.58);
color: #aebdc3;
font-size: 11px;
letter-spacing: 0.04em;
backdrop-filter: blur(12px);
}
.dock {
bottom: 24px;
left: 50%;
width: min(720px, calc(100% - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: repeat(3, 1fr) auto;
gap: 9px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.42);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.counter {
position: relative;
min-width: 0;
padding: 11px 12px 10px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 13px;
background: rgba(255, 255, 255, 0.035);
}
.counter::before {
position: absolute;
inset: 0 auto 0 0;
width: 3px;
content: "";
background: var(--accent);
box-shadow: 0 0 18px color-mix(in srgb, var(--accent), transparent 45%);
}
.counter[data-level="point"] { --accent: var(--point); }
.counter[data-level="game"] { --accent: var(--game); }
.counter[data-level="set"] { --accent: var(--set); }
.counter-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.counter-name {
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
}
.counter output {
color: var(--text);
font-size: 24px;
font-weight: 850;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
.counter-rule {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.06em;
}
.increment {
width: 34px;
height: 34px;
flex: 0 0 auto;
border: 1px solid color-mix(in srgb, var(--accent), transparent 55%);
border-radius: 10px;
background: color-mix(in srgb, var(--accent), transparent 87%);
color: var(--accent);
font: inherit;
font-size: 18px;
font-weight: 800;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
opacity 120ms ease;
}
.increment:hover:not(:disabled) {
transform: translateY(-1px);
background: color-mix(in srgb, var(--accent), transparent 74%);
}
.increment:active:not(:disabled) {
transform: translateY(1px);
}
.increment:disabled {
cursor: default;
opacity: 0.3;
}
button:focus-visible {
outline: 2px solid #ffffff;
outline-offset: 3px;
}
.reset {
min-width: 74px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.045);
color: #b8c6cb;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
cursor: pointer;
transition: background 120ms ease;
}
.reset:hover {
background: rgba(255, 255, 255, 0.09);
}
.note {
bottom: 126px;
left: 50%;
transform: translateX(-50%);
color: #70858e;
font-size: 10px;
letter-spacing: 0.05em;
text-align: center;
white-space: nowrap;
}
@media (max-width: 680px) {
.heading {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.hierarchy {
margin-top: 12px;
}
.help {
top: 18px;
right: 18px;
max-width: 110px;
border-radius: 12px;
text-align: center;
}
.dock {
bottom: 12px;
width: calc(100% - 20px);
grid-template-columns: repeat(3, 1fr);
gap: 6px;
padding: 7px;
border-radius: 16px;
}
.counter {
padding: 9px 8px 9px 11px;
}
.counter-top {
gap: 4px;
}
.counter output {
font-size: 20px;
}
.counter-rule {
font-size: 8px;
}
.increment {
width: 30px;
height: 30px;
}
.reset {
grid-column: 1 / -1;
min-height: 34px;
}
.note {
bottom: 139px;
font-size: 8px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive 3D hierarchical sports scoreboard"></main>
<header class="hud heading">
<div class="eyebrow">Generic score system</div>
<h1>ASCENT<br />SCOREBOARD</h1>
<p class="subtitle">
Three solid score levels arranged by hierarchy. Each level keeps its own
range and step—there is no automatic point-to-game or game-to-set rollover.
</p>
<div class="hierarchy" aria-label="Hierarchy from point to game to set">
<span>POINT</span><i>→</i>
<span>GAME</span><i>→</i>
<span>SET</span>
</div>
</header>
<div class="hud help">Drag · orbit<br />Scroll · zoom</div>
<div class="hud note">
Click a 3D tier or use the controls. Counters advance independently.
</div>
<section class="hud dock" aria-label="Scoreboard controls">
<article class="counter" data-level="point">
<div class="counter-top">
<div>
<div class="counter-name">POINT</div>
<output id="point-value" aria-live="polite">24</output>
<div class="counter-rule">00–99 · step 1</div>
</div>
<button class="increment" data-step="point" aria-label="Add one point">+1</button>
</div>
</article>
<article class="counter" data-level="game">
<div class="counter-top">
<div>
<div class="counter-name">GAME</div>
<output id="game-value" aria-live="polite">1</output>
<div class="counter-rule">0–3 · step 1</div>
</div>
<button class="increment" data-step="game" aria-label="Add one game">+1</button>
</div>
</article>
<article class="counter" data-level="set">
<div class="counter-top">
<div>
<div class="counter-name">SET</div>
<output id="set-value" aria-live="polite">0</output>
<div class="counter-rule">0–2 · step 1</div>
</div>
<button class="increment" data-step="set" aria-label="Add one set">+1</button>
</div>
</article>
<button class="reset" id="reset-score">RESET</button>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.FogExp2(0x071018, 0.026);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.35, 0);
const cameraHome = {
yaw: 0.58,
pitch: 0.31,
distance: 12.4
};
const orbit = { ...cameraHome };
function updateCamera() {
const horizontal =
Math.cos(orbit.pitch) * orbit.distance;
camera.position.set(
Math.sin(orbit.yaw) * horizontal,
cameraTarget.y + Math.sin(orbit.pitch) * orbit.distance,
Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xa6e7f1, 0x10121a, 1.5));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.3);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4ee9dc, 1.7);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const warmLight = new THREE.DirectionalLight(0xff805e, 1.15);
warmLight.position.set(6, 2, -3);
scene.add(warmLight);
// Materials
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x17242c,
metalness: 0.45,
roughness: 0.42
});
const faceMaterial = new THREE.MeshStandardMaterial({
color: 0x081116,
metalness: 0.18,
roughness: 0.68
});
const bronze = new THREE.MeshStandardMaterial({
color: 0x8a5d3c,
metalness: 0.72,
roughness: 0.3
});
function roundedShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
shape.closePath();
return shape;
}
function roundedPanel(
width,
height,
depth,
radius,
material,
bevel = true
) {
const geometry = new THREE.ExtrudeGeometry(
roundedShape(width, height, radius),
{
depth,
steps: 1,
bevelEnabled: bevel,
bevelSegments: 2,
bevelSize: Math.min(0.045, radius * 0.35),
bevelThickness: Math.min(0.035, depth * 0.25),
curveSegments: 8
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeTextTexture(title, subtitle, color) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.textBaseline = "alphabetic";
ctx.fillStyle = color;
ctx.font = "800 60px system-ui, sans-serif";
ctx.fillText(title, 20, 105);
ctx.fillStyle = "rgba(210, 226, 232, 0.76)";
ctx.font = "700 27px system-ui, sans-serif";
ctx.fillText(subtitle, 22, 168);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeTextPlane(title, subtitle, color, width, height) {
const texture = makeTextTexture(title, subtitle, color);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
return new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
}
function makePlaque(
title,
subtitle,
color,
width = 1.34,
height = 0.72
) {
const group = new THREE.Group();
const accentMaterial = new THREE.MeshStandardMaterial({
color,
metalness: 0.18,
roughness: 0.42,
emissive: color,
emissiveIntensity: 0.08
});
const plate = roundedPanel(
width,
height,
0.07,
0.1,
accentMaterial,
false
);
const text = makeTextPlane(
title,
subtitle,
"#f5fafb",
width * 0.91,
height * 0.88
);
text.position.z = 0.046;
group.add(plate, text);
return group;
}
function makeRuleTag(title, subtitle, color) {
const group = new THREE.Group();
const backing = roundedPanel(
1.12,
0.66,
0.045,
0.09,
new THREE.MeshStandardMaterial({
color: 0x101d24,
metalness: 0.25,
roughness: 0.55
}),
false
);
const text = makeTextPlane(title, subtitle, color, 1.02, 0.54);
text.position.z = 0.03;
group.add(backing, text);
return group;
}
// Seven-segment solid display
const digitSegments = {
0: "abcdef",
1: "bc",
2: "abdeg",
3: "abcdg",
4: "bcfg",
5: "acdfg",
6: "acdefg",
7: "abc",
8: "abcdefg",
9: "abcdfg"
};
class SevenSegmentDisplay {
constructor(digitCount, height, color) {
this.group = new THREE.Group();
this.color = new THREE.Color(color);
this.digits = [];
this.width = height * 0.56;
this.thickness = height * 0.095;
this.height = height;
for (let digitIndex = 0; digitIndex < digitCount; digitIndex++) {
const digit = {
segments: new Map(),
meshes: []
};
const digitWidth = this.width;
const t = this.thickness;
const h = height;
const definitions = {
a: {
size: [digitWidth * 0.73, t, 0.1],
position: [0, h * 0.44, 0]
},
b: {
size: [t, h * 0.38, 0.1],
position: [digitWidth * 0.42, h * 0.24, 0]
},
c: {
size: [t, h * 0.38, 0.1],
position: [digitWidth * 0.42, -h * 0.24, 0]
},
d: {
size: [digitWidth * 0.73, t, 0.1],
position: [0, -h * 0.44, 0]
},
e: {
size: [t, h * 0.38, 0.1],
position: [-digitWidth * 0.42, -h * 0.24, 0]
},
f: {
size: [t, h * 0.38, 0.1],
position: [-digitWidth * 0.42, h * 0.24, 0]
},
g: {
size: [digitWidth * 0.73, t, 0.1],
position: [0, 0, 0]
}
};
for (const [name, definition] of Object.entries(definitions)) {
const material = new THREE.MeshStandardMaterial({
color: 0x17252c,
metalness: 0.35,
roughness: 0.4,
emissive: 0x000000
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...definition.size),
material
);
mesh.position.set(...definition.position);
mesh.castShadow = true;
mesh.receiveShadow = true;
digit.segments.set(name, material);
digit.meshes.push(mesh);
this.group.add(mesh);
}
this.digits.push(digit);
}
this.update(0);
}
update(value) {
const text = String(value).padStart(this.digits.length, "0");
this.activeSegments = [];
text.split("").forEach((character, index) => {
const active = digitSegments[Number(character)];
const digit = this.digits[index];
for (const [name, material] of digit.segments) {
const isActive = active.includes(name);
material.color.set(isActive ? this.color : 0x17252c);
material.emissive.set(isActive ? this.color : 0x000000);
material.emissiveIntensity = isActive ? 0.38 : 0;
if (isActive) {
this.activeSegments.push(material);
}
}
});
}
animate(time) {
const pulse = 0.34 + Math.sin(time * 2.2) * 0.07;
for (const material of this.activeSegments || []) {
material.emissiveIntensity = pulse;
}
}
}
// Stage and architectural forms
const stage = new THREE.Group();
scene.add(stage);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x071017,
metalness: 0.12,
roughness: 0.9
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.5;
floor.receiveShadow = true;
stage.add(floor);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(5.3, 5.75, 0.38, 64),
new THREE.MeshStandardMaterial({
color: 0x101b22,
metalness: 0.48,
roughness: 0.5
})
);
base.position.y = -0.28;
base.receiveShadow = true;
base.castShadow = true;
stage.add(base);
const baseInset = new THREE.Mesh(
new THREE.CylinderGeometry(4.65, 4.85, 0.12, 64),
new THREE.MeshStandardMaterial({
color: 0x0a151b,
metalness: 0.3,
roughness: 0.65
})
);
baseInset.position.y = -0.03;
baseInset.receiveShadow = true;
stage.add(baseInset);
for (const radius of [4.72, 5.48, 6.35]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.025, 8, 96),
new THREE.MeshStandardMaterial({
color: 0x21444a,
metalness: 0.7,
roughness: 0.32,
emissive: 0x12343b,
emissiveIntensity: 0.35
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.075;
stage.add(ring);
}
// Rear support makes the three tiers read as one hierarchy.
const spine = roundedPanel(
1.25,
5.35,
0.82,
0.24,
darkMetal
);
spine.position.set(0, 2.5, -0.47);
stage.add(spine);
const spineEdge = roundedPanel(
0.24,
4.85,
0.12,
0.08,
bronze,
false
);
spineEdge.position.set(0, 2.5, -0.01);
stage.add(spineEdge);
// Decorative solid pylons
const pylonMaterial = new THREE.MeshStandardMaterial({
color: 0x12252d,
metalness: 0.5,
roughness: 0.42
});
for (let side = -1; side <= 1; side += 2) {
for (let i = 0; i < 4; i++) {
const height = 0.35 + i * 0.13;
const pylon = roundedPanel(
0.22,
height,
0.28,
0.05,
pylonMaterial
);
pylon.position.set(
side * (3.45 + i * 0.48),
-0.34 + height / 2,
-0.55 - i * 0.18
);
pylon.rotation.y = side * (0.18 + i * 0.05);
stage.add(pylon);
}
}
// Independent state. No value is derived from another level.
const state = {
point: 24,
game: 1,
set: 0
};
const limits = {
point: 99,
game: 3,
set: 2
};
const clickablePanels = [];
const displays = [];
const pipSets = [];
function makeSquarePips(count, color) {
const group = new THREE.Group();
const pips = [];
for (let i = 0; i < count; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0x17252c,
metalness: 0.38,
roughness: 0.42,
emissive: 0x000000
});
const pip = roundedPanel(
0.23,
0.23,
0.09,
0.045,
material,
false
);
pip.position.x = i * 0.34;
pip.userData.index = i;
pips.push(pip);
group.add(pip);
}
pipSets.push({ pips, color: new THREE.Color(color) });
return group;
}
function makeDiamondPips(count, color) {
const group = new THREE.Group();
const pips = [];
for (let i = 0; i < count; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0x17252c,
metalness: 0.38,
roughness: 0.42,
emissive: 0x000000
});
const pip = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.18, 0.09, 4),
material
);
pip.rotation.x = Math.PI / 2;
pip.rotation.z = Math.PI / 4;
pip.position.x = i * 0.42;
pips.push(pip);
group.add(pip);
}
pipSets.push({ pips, color: new THREE.Color(color) });
return group;
}
function buildModule({
level,
y,
width,
color,
title,
subtitle,
ruleTitle,
ruleSubtitle,
digitCount,
leftOffset,
scoreOffset,
rightOffset
}) {
const group = new THREE.Group();
group.position.y = y;
const accentMaterial = new THREE.MeshStandardMaterial({
color,
metalness: 0.26,
roughness: 0.36,
emissive: color,
emissiveIntensity: 0.055
});
const panel = roundedPanel(
width,
1.38,
0.34,
0.19,
accentMaterial
);
panel.userData.level = level;
clickablePanels.push(panel);
const face = roundedPanel(
width - 0.2,
1.18,
0.075,
0.13,
faceMaterial,
false
);
face.position.z = 0.205;
const plaque = makePlaque(title, subtitle, color);
plaque.position.set(leftOffset, 0, 0.275);
const display = new SevenSegmentDisplay(digitCount, 0.76, color);
display.group.position.set(scoreOffset, -0.015, 0.39);
displays[level] = display;
group.add(panel, face, plaque, display.group);
if (level === "point") {
const tag = makeRuleTag(ruleTitle, ruleSubtitle, color);
tag.position.set(rightOffset, 0, 0.275);
group.add(tag);
} else {
const pips =
level === "game"
? makeSquarePips(3, color)
: makeDiamondPips(2, color);
pips.position.set(rightOffset, -0.02, 0.39);
group.add(pips);
}
// Small fastener details.
for (const x of [-width / 2 + 0.13, width / 2 - 0.13]) {
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.025, 12),
bronze
);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(x, 0.54, 0.265);
group.add(bolt);
}
stage.add(group);
return group;
}
// The tapering stack communicates hierarchy:
// POINT → GAME → SET.
buildModule({
level: "point",
y: 0.98,
width: 5.8,
color: 0xff704d,
title: "POINT",
subtitle: "SCORE",
ruleTitle: "00–99",
ruleSubtitle: "+1 / SCORE",
digitCount: 2,
leftOffset: -2.04,
scoreOffset: 0.06,
rightOffset: 2.06
});
buildModule({
level: "game",
y: 2.61,
width: 4.9,
color: 0x35d7c1,
title: "GAME",
subtitle: "WINS",
ruleTitle: "0–3",
ruleSubtitle: "+1 / GAME",
digitCount: 1,
leftOffset: -1.6,
scoreOffset: -0.2,
rightOffset: 0.88
});
buildModule({
level: "set",
y: 4.24,
width: 4.0,
color: 0xffd166,
title: "SET",
subtitle: "WINS",
ruleTitle: "0–2",
ruleSubtitle: "+1 / SET",
digitCount: 1,
leftOffset: -1.24,
scoreOffset: -0.2,
rightOffset: 0.82
});
// Small crown indicates the top of the hierarchy.
const crown = new THREE.Group();
crown.position.set(0, 5.12, -0.05);
const crownWidths = [1.65, 1.25, 0.85];
for (let i = 0; i < crownWidths.length; i++) {
const bar = roundedPanel(
crownWidths[i],
0.16,
0.32,
0.05,
bronze
);
bar.position.y = i * 0.16;
crown.add(bar);
}
stage.add(crown);
// Floating solid fragments provide depth without image textures.
const floatingCubes = [];
const cubeMaterials = [
new THREE.MeshStandardMaterial({
color: 0x15343b,
metalness: 0.55,
roughness: 0.42
}),
new THREE.MeshStandardMaterial({
color: 0x4b2924,
metalness: 0.45,
roughness: 0.5
}),
new THREE.MeshStandardMaterial({
color: 0x50431f,
metalness: 0.5,
roughness: 0.46
})
];
for (let i = 0; i < 24; i++) {
const size = 0.055 + (i % 4) * 0.018;
const cube = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
cubeMaterials[i % cubeMaterials.length]
);
const angle = (i / 24) * Math.PI * 2;
const radius = 5.6 + (i % 5) * 0.62;
cube.position.set(
Math.sin(angle) * radius,
0.4 + (i % 7) * 0.62,
Math.cos(angle) * radius - 0.8
);
cube.rotation.set(i * 0.17, i * 0.29, i * 0.11);
cube.userData.baseY = cube.position.y;
cube.userData.phase = i * 0.73;
floatingCubes.push(cube);
stage.add(cube);
}
function updatePips() {
const values = {
point: state.point,
game: state.game,
set: state.set
};
pipSets.forEach((pipSet) => {
// Pip groups are added in module order: game, then set.
const level = pipSet.pips[0].parent.parent === undefined
? null
: null;
// Use the actual active pip count supplied below.
pipSet.activeCount = pipSet.activeCount ?? 0;
});
}
// Store exact pip references so each distinct visual convention updates.
const gamePips = pipSets[0];
const setPips = pipSets[1];
function updatePipSet(pipSet, value) {
pipSet.pips.forEach((pip, index) => {
const active = index < value;
pip.material.color.set(active ? pipSet.color : 0x17252c);
pip.material.emissive.set(active ? pipSet.color : 0x000000);
pip.material.emissiveIntensity = active ? 0.32 : 0;
});
}
function updateScore() {
displays.point.update(state.point);
displays.game.update(state.game);
displays.set.update(state.set);
updatePipSet(gamePips, state.game);
updatePipSet(setPips, state.set);
document.querySelector("#point-value").textContent =
String(state.point).padStart(2, "0");
document.querySelector("#game-value").textContent = state.game;
document.querySelector("#set-value").textContent = state.set;
document.querySelector('[data-step="point"]').disabled =
state.point >= limits.point;
document.querySelector('[data-step="game"]').disabled =
state.game >= limits.game;
document.querySelector('[data-step="set"]').disabled =
state.set >= limits.set;
}
function increment(level) {
if (state[level] < limits[level]) {
state[level] += 1;
updateScore();
}
}
document.querySelectorAll("[data-step]").forEach((button) => {
button.addEventListener("click", () => {
increment(button.dataset.step);
});
});
document.querySelector("#reset-score").addEventListener("click", () => {
state.point = 0;
state.game = 0;
state.set = 0;
updateScore();
});
updateScore();
// Direct camera controls, implemented without Three.js addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const canvas = renderer.domElement;
let dragging = false;
let pointerStart = { x: 0, y: 0 };
let previousPointer = { x: 0, y: 0 };
let dragDistance = 0;
function setPointerFromEvent(event) {
const rect = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function hitPanel(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
clickablePanels,
false
);
return hits.length ? hits[0].object.userData.level : null;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragDistance = 0;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { ...pointerStart };
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
dragDistance += Math.abs(dx) + Math.abs(dy);
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.005,
0.08,
0.85
);
previousPointer = {
x: event.clientX,
y: event.clientY
};
updateCamera();
} else {
canvas.style.cursor = hitPanel(event) ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
if (dragDistance < 7) {
const level = hitPanel(event);
if (level) increment(level);
}
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance + event.deltaY * 0.009,
7.5,
18
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
Object.assign(orbit, cameraHome);
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
if (event.key === "ArrowLeft") orbit.yaw -= 0.09;
if (event.key === "ArrowRight") orbit.yaw += 0.09;
if (event.key === "ArrowUp") orbit.pitch += 0.06;
if (event.key === "ArrowDown") orbit.pitch -= 0.06;
if (event.key === "+" || event.key === "=") orbit.distance -= 0.5;
if (event.key === "-" || event.key === "_") orbit.distance += 0.5;
if (event.key.toLowerCase() === "r") {
Object.assign(orbit, cameraHome);
}
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch, 0.08, 0.85);
orbit.distance = THREE.MathUtils.clamp(orbit.distance, 7.5, 18);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
for (const cube of floatingCubes) {
cube.position.y =
cube.userData.baseY +
Math.sin(time * 0.72 + cube.userData.phase) * 0.08;
cube.rotation.x += 0.0015;
cube.rotation.y += 0.002;
}
for (const display of Object.values(displays)) {
display.animate(time);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```