Prompt specification
Build or customize the Three.js 3D scene "Accessible Target-Ball Play Area" 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: Accessible Target-Ball Play Area
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/accessible-target-ball-play-area-x3663
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts boccia balls and distance to the target jack. Build an original inclusive target-ball setting with a seated player proxy and optional ramp. Show the activity layout without claiming official sport or accessibility compliance. Voxel style.
Working Three.js Starter (accessible-target-ball-play-area-x3663):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Boccia Ball Activity Scene</title>
<style>
:root {
color-scheme: light;
--ink: #17342d;
--panel: rgba(255, 255, 255, 0.92);
--line: rgba(23, 52, 45, 0.16);
--green: #1d6b55;
--green-dark: #124b3c;
--yellow: #ffd45c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background: #cfe0d8;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
canvas:focus-visible {
outline: 4px solid var(--yellow);
outline-offset: -4px;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow: 0 14px 40px rgba(24, 54, 45, 0.16);
backdrop-filter: blur(12px);
}
#info {
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
padding: 17px 18px 15px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: var(--green);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.25rem, 2.2vw, 1.75rem);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 11px;
font-size: 0.92rem;
line-height: 1.45;
color: #45645c;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 11px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border-radius: 999px;
background: #e8f0ec;
font-size: 0.72rem;
font-weight: 750;
}
.chip::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--green);
}
.disclaimer {
margin: 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #5c716b;
font-size: 0.72rem;
line-height: 1.4;
}
#readout {
top: 18px;
right: 18px;
min-width: 230px;
padding: 14px 16px;
}
.readout-label {
display: block;
color: #60766f;
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#distance {
display: block;
margin: 3px 0 2px;
font-size: 1.8rem;
font-weight: 850;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
#selected-name {
color: var(--green-dark);
font-size: 0.83rem;
font-weight: 700;
}
#controls {
left: 50%;
bottom: 18px;
width: min(760px, calc(100vw - 36px));
padding: 11px;
transform: translateX(-50%);
}
.control-row {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 7px;
}
.control-row + .control-row {
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid var(--line);
}
.control-label {
margin-right: 3px;
color: #61766f;
font-size: 0.71rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
button {
appearance: none;
min-height: 38px;
padding: 8px 12px;
border: 1px solid #cbd8d3;
border-radius: 10px;
background: #f8fbf9;
color: var(--ink);
font: inherit;
font-size: 0.8rem;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
button:hover {
border-color: #91aaa1;
background: #edf5f1;
}
button:active {
transform: translateY(1px);
}
button:focus-visible {
outline: 3px solid rgba(29, 107, 85, 0.35);
outline-offset: 2px;
}
button[aria-pressed="true"] {
border-color: var(--green);
background: var(--green);
color: white;
}
.ball-button {
display: inline-flex;
align-items: center;
gap: 7px;
}
.dot {
width: 11px;
height: 11px;
border-radius: 3px;
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.14);
}
.dot.blue { background: #2575d4; }
.dot.green { background: #36a269; }
.dot.purple { background: #8457c5; }
.dot.coral { background: #ec6d55; }
#help {
margin: 7px 0 0;
color: #62776f;
text-align: center;
font-size: 0.7rem;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #cfe0d8;
color: var(--green-dark);
font-weight: 800;
letter-spacing: 0.05em;
}
@media (max-width: 700px) {
#info {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px 13px;
}
#readout {
top: auto;
right: 10px;
bottom: 155px;
min-width: 185px;
padding: 10px 12px;
}
#distance {
font-size: 1.4rem;
}
#controls {
bottom: 10px;
width: calc(100vw - 20px);
}
.control-label {
width: 100%;
text-align: center;
}
button {
padding: 7px 9px;
font-size: 0.74rem;
}
#help {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the voxel activity scene…</div>
<section id="info" class="panel" aria-labelledby="scene-title">
<p class="eyebrow">Original activity concept</p>
<h1 id="scene-title">Voxel Boccia Ball Studio</h1>
<p class="subtitle">
Explore a seated-player layout, select a boccia ball, and compare its
illustrative distance to the target jack.
</p>
<div class="chips" aria-label="Scene features">
<span class="chip">Seated player proxy</span>
<span class="chip">Optional rolling ramp</span>
<span class="chip">Selectable balls</span>
</div>
<p class="disclaimer">
Original layout and illustrative metre scale. This is not an official
boccia court, and no accessibility compliance is claimed or implied.
</p>
</section>
<section id="readout" class="panel" aria-live="polite">
<span class="readout-label">Distance to target jack</span>
<output id="distance">—</output>
<span id="selected-name">Select a ball</span>
</section>
<section id="controls" class="panel" aria-label="Scene controls">
<div class="control-row">
<span class="control-label">Ball</span>
<button class="ball-button" data-ball="blue" aria-pressed="true">
<span class="dot blue" aria-hidden="true"></span>Blue 1
</button>
<button class="ball-button" data-ball="green" aria-pressed="false">
<span class="dot green" aria-hidden="true"></span>Green 2
</button>
<button class="ball-button" data-ball="purple" aria-pressed="false">
<span class="dot purple" aria-hidden="true"></span>Purple 3
</button>
<button class="ball-button" data-ball="coral" aria-pressed="false">
<span class="dot coral" aria-hidden="true"></span>Coral 4
</button>
</div>
<div class="control-row">
<button id="ramp-toggle" aria-pressed="true">Ramp: shown</button>
<button id="view-toggle" aria-pressed="false">Top view</button>
<button id="reset-view">Reset camera</button>
</div>
<p id="help">
Drag to orbit · wheel to zoom · click a ball · arrow keys rotate ·
+/− zoom · R resets · P changes view
</p>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lights
// ------------------------------------------------------------
const loading = document.querySelector("#loading");
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;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional boccia ball activity scene"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfe0d8);
scene.fog = new THREE.Fog(0xcfe0d8, 40, 78);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(
0xe8f7ff,
0x6b7555,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1ce, 3.25);
sun.position.set(-10, 20, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9ff, 0.65);
fill.position.set(12, 8, -12);
scene.add(fill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function addBox(
parent,
sizeX,
sizeY,
sizeZ,
x,
y,
z,
color,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(sizeX, sizeY, sizeZ),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRectPath(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeLabel(
lines,
{
width = 512,
height = 128,
scale = [3.4, 0.85],
foreground = "#ffffff",
background = "rgba(20, 58, 47, 0.92)",
accent = "#ffd45c"
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
roundedRectPath(context, 5, 5, width - 10, height - 10, 24);
context.fillStyle = background;
context.fill();
context.strokeStyle = "rgba(255,255,255,0.22)";
context.lineWidth = 3;
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
if (lines.length === 1) {
context.fillStyle = foreground;
context.font = `800 ${Math.floor(height * 0.38)}px system-ui, sans-serif`;
context.fillText(lines[0], width / 2, height / 2 + 2);
} else {
context.fillStyle = accent;
context.font = `800 ${Math.floor(height * 0.25)}px system-ui, sans-serif`;
context.fillText(lines[0], width / 2, height * 0.36);
context.fillStyle = foreground;
context.font = `800 ${Math.floor(height * 0.32)}px system-ui, sans-serif`;
context.fillText(lines[1], width / 2, height * 0.68);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 20;
sprite.userData.canvas = canvas;
sprite.userData.texture = texture;
sprite.userData.options = {
width,
height,
foreground,
background,
accent
};
return sprite;
}
function updateLabel(sprite, lines) {
const {
width,
height,
foreground,
background,
accent
} = sprite.userData.options;
const canvas = sprite.userData.canvas;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
roundedRectPath(context, 5, 5, width - 10, height - 10, 24);
context.fillStyle = background;
context.fill();
context.strokeStyle = "rgba(255,255,255,0.22)";
context.lineWidth = 3;
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
if (lines.length === 1) {
context.fillStyle = foreground;
context.font = `800 ${Math.floor(height * 0.38)}px system-ui, sans-serif`;
context.fillText(lines[0], width / 2, height / 2 + 2);
} else {
context.fillStyle = accent;
context.font = `800 ${Math.floor(height * 0.25)}px system-ui, sans-serif`;
context.fillText(lines[0], width / 2, height * 0.36);
context.fillStyle = foreground;
context.font = `800 ${Math.floor(height * 0.32)}px system-ui, sans-serif`;
context.fillText(lines[1], width / 2, height * 0.68);
}
sprite.userData.texture.needsUpdate = true;
}
function makeFloorText(text, width, depth, color = "#d9eee3") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = color;
context.font = "800 90px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
opacity: 0.8
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = 0.065;
mesh.renderOrder = 2;
return mesh;
}
// ------------------------------------------------------------
// Court and activity layout
// ------------------------------------------------------------
const activity = new THREE.Group();
scene.add(activity);
// Wooden deck and court slab.
addBox(activity, 25, 0.5, 19, 0, -0.48, 0, 0xb58b61);
addBox(activity, 21, 0.32, 14.5, 0, -0.14, 0, 0x4f8e68);
addBox(activity, 20.3, 0.12, 13.8, 0, 0.025, 0, 0x5fa476);
// Court perimeter.
addBox(activity, 20.8, 0.08, 0.15, 0, 0.105, -7.02, 0xe9ead0);
addBox(activity, 20.8, 0.08, 0.15, 0, 0.105, 7.02, 0xe9ead0);
addBox(activity, 0.15, 0.08, 14.1, -10.32, 0.105, 0, 0xe9ead0);
addBox(activity, 0.15, 0.08, 14.1, 10.32, 0.105, 0, 0xe9ead0);
// Dashed activity divider.
for (let x = -9.5; x <= 9.5; x += 1.5) {
addBox(activity, 0.72, 0.035, 0.09, x, 0.1, -0.15, 0xbad0be, false);
}
// Player bay.
addBox(activity, 5.2, 0.045, 3.4, -1.4, 0.1, 4.45, 0x447c5e, false);
addBox(activity, 5.35, 0.06, 0.1, -1.4, 0.13, 6.12, 0xdce6cf, false);
addBox(activity, 5.35, 0.06, 0.1, -1.4, 0.13, 2.78, 0xdce6cf, false);
// Target-zone square around the jack.
const targetX = 2.2;
const targetZ = -2.8;
addBox(activity, 3.5, 0.05, 0.12, targetX, 0.13, targetZ - 1.7, 0xf3e8c5, false);
addBox(activity, 3.5, 0.05, 0.12, targetX, 0.13, targetZ + 1.7, 0xf3e8c5, false);
addBox(activity, 0.12, 0.05, 3.28, targetX - 1.69, 0.13, targetZ, 0xf3e8c5, false);
addBox(activity, 0.12, 0.05, 3.28, targetX + 1.69, 0.13, targetZ, 0xf3e8c5, false);
addBox(activity, 4.7, 0.04, 0.09, targetX, 0.11, targetZ - 2.3, 0xb9d2bd, false);
addBox(activity, 4.7, 0.04, 0.09, targetX, 0.11, targetZ + 2.3, 0xb9d2bd, false);
addBox(activity, 0.09, 0.04, 4.6, targetX - 2.3, 0.11, targetZ, 0xb9d2bd, false);
addBox(activity, 0.09, 0.04, 4.6, targetX + 2.3, 0.11, targetZ, 0xb9d2bd, false);
const playerBayText = makeFloorText("PLAYER BAY", 3.4, 0.8);
playerBayText.position.set(-1.4, 0.07, 5.45);
activity.add(playerBayText);
const targetText = makeFloorText("TARGET ZONE", 3.9, 0.9, "#f7edc9");
targetText.position.set(targetX, 0.07, targetZ - 2.95);
activity.add(targetText);
// Small visual landmarks outside the play area.
function makeVoxelTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addBox(tree, 0.48, 2.2, 0.48, 0, 1.1, 0, 0x78503b);
addBox(tree, 1.8, 0.85, 1.6, 0, 2.35, 0, 0x4e8055);
addBox(tree, 1.35, 0.85, 1.75, -0.2, 3.05, 0.1, 0x5c9564);
addBox(tree, 1.6, 0.7, 1.25, 0.25, 3.65, -0.05, 0x76a971);
addBox(tree, 1.05, 0.65, 1.05, -0.2, 4.08, 0.05, 0x84b77a);
scene.add(tree);
}
makeVoxelTree(-12, -8.3, 1.15);
makeVoxelTree(12.2, -8.8, 1.0);
makeVoxelTree(12.8, 7.5, 1.2);
// Bench in a companion waiting area.
const bench = new THREE.Group();
bench.position.set(6.2, 0, 5.35);
addBox(bench, 4.1, 0.25, 0.78, 0, 1.05, 0, 0x8d6648);
addBox(bench, 4.1, 0.95, 0.18, 0, 1.62, 0.34, 0x8d6648);
addBox(bench, 0.25, 1.0, 0.65, -1.6, 0.5, 0, 0x46554f);
addBox(bench, 0.25, 1.0, 0.65, 1.6, 0.5, 0, 0x46554f);
scene.add(bench);
// ------------------------------------------------------------
// Optional rolling ramp
// ------------------------------------------------------------
const rampRoot = new THREE.Group();
rampRoot.position.set(-7.25, 0, 7.05);
const rampSlab = addBox(
rampRoot,
2.45,
0.18,
3.65,
0,
0.46,
0,
0xc7925e
);
rampSlab.rotation.x = -0.28;
const rampRailLeft = addBox(
rampRoot,
0.14,
0.42,
3.65,
-1.1,
0.73,
0,
0xf0d39a
);
rampRailLeft.rotation.x = -0.28;
const rampRailRight = addBox(
rampRoot,
0.14,
0.42,
3.65,
1.1,
0.73,
0,
0xf0d39a
);
rampRailRight.rotation.x = -0.28;
const rampLabel = makeLabel("OPTIONAL RAMP", {
width: 512,
height: 112,
scale: [3.1, 0.68],
background: "rgba(87, 59, 37, 0.92)"
});
rampLabel.position.set(0, 1.8, 0);
rampRoot.add(rampLabel);
scene.add(rampRoot);
// ------------------------------------------------------------
// Seated player proxy and supportive chair
// ------------------------------------------------------------
const player = new THREE.Group();
player.position.set(-1.4, 0, 4.5);
// Supportive chair frame and seat.
addBox(player, 1.75, 0.24, 1.55, 0, 1.08, 0, 0x334d47);
addBox(player, 1.68, 1.8, 0.22, 0, 1.98, 0.62, 0x334d47);
addBox(player, 0.18, 0.16, 1.35, -0.98, 1.56, -0.08, 0x334d47);
addBox(player, 0.18, 0.16, 1.35, 0.98, 1.56, -0.08, 0x334d47);
// Voxel chair wheels.
for (const side of [-1, 1]) {
const wheelX = side * 1.08;
for (let index = 0; index < 12; index += 1) {
const angle = (index / 12) * Math.PI * 2;
const wheelVoxel = addBox(
player,
0.24,
0.28,
0.25,
wheelX,
0.66 + Math.cos(angle) * 0.47,
0.38 + Math.sin(angle) * 0.47,
0x253a38
);
wheelVoxel.castShadow = true;
}
addBox(player, 0.28, 0.28, 0.28, wheelX, 0.66, 0.38, 0x71827d);
addBox(player, 0.25, 0.42, 0.25, side * 0.74, 0.26, -0.72, 0x253a38);
}
// Seated proxy: hips, torso, head, and bent legs.
addBox(player, 1.05, 0.45, 0.82, 0, 1.52, 0.02, 0x33445f);
addBox(player, 1.18, 1.15, 0.76, 0, 2.24, -0.02, 0x218777);
addBox(player, 0.32, 0.62, 0.08, 0, 2.18, -0.43, 0xf1cf67);
addBox(player, 0.7, 0.76, 0.68, 0, 3.18, -0.04, 0x9b684f);
addBox(player, 0.76, 0.28, 0.73, 0, 3.53, -0.01, 0x3d302b);
addBox(player, 0.77, 0.28, 0.22, 0, 3.4, -0.42, 0x3d302b);
addBox(player, 0.09, 0.09, 0.045, -0.17, 3.22, -0.395, 0x26332f);
addBox(player, 0.09, 0.09, 0.045, 0.17, 3.22, -0.395, 0x26332f);
addBox(player, 0.18, 0.07, 0.045, 0, 3.02, -0.395, 0x6e4339);
// Thighs and lower legs.
for (const side of [-1, 1]) {
addBox(player, 0.4, 0.38, 1.08, side * 0.29, 1.42, -0.42, 0x33445f);
addBox(player, 0.36, 0.72, 0.36, side * 0.29, 0.91, -0.9, 0x33445f);
addBox(player, 0.43, 0.25, 0.68, side * 0.29, 0.53, -1.16, 0x253638);
// Upper arm and forward forearm.
addBox(player, 0.3, 0.82, 0.34, side * 0.72, 2.36, -0.08, 0x218777);
addBox(player, 0.28, 0.28, 0.92, side * 0.72, 2.04, -0.56, 0x9b684f);
addBox(player, 0.3, 0.24, 0.34, side * 0.72, 2.03, -1.02, 0x9b684f);
}
scene.add(player);
const playerLabel = makeLabel("SEATED PLAYER PROXY", {
width: 512,
height: 112,
scale: [4.0, 0.78],
background: "rgba(22, 72, 60, 0.94)"
});
playerLabel.position.set(-1.4, 4.22, 4.5);
scene.add(playerLabel);
// A small equipment table beside the player.
const equipmentTable = new THREE.Group();
equipmentTable.position.set(-4.25, 0, 4.65);
addBox(equipmentTable, 1.75, 0.18, 1.1, 0, 1.0, 0, 0x966b49);
addBox(equipmentTable, 0.18, 1.0, 0.75, -0.65, 0.5, 0, 0x4e5d56);
addBox(equipmentTable, 0.18, 1.0, 0.75, 0.65, 0.5, 0, 0x4e5d56);
addBox(equipmentTable, 0.95, 0.15, 0.62, 0, 1.17, 0, 0xe7d8b2);
scene.add(equipmentTable);
// ------------------------------------------------------------
// Voxel boccia balls
// ------------------------------------------------------------
const ballMeshes = [];
function makeVoxelBall(id, baseColor, accentColor, position, scale = 1) {
const group = new THREE.Group();
group.position.copy(position);
group.scale.setScalar(scale);
const cells = [];
const step = 0.22;
for (let x = -3; x <= 3; x += 1) {
for (let y = -3; y <= 3; y += 1) {
for (let z = -3; z <= 3; z += 1) {
const d2 = x * x + y * y + z * z;
if (d2 <= 10.8) {
cells.push({ x, y, z, d2 });
}
}
}
}
const geometry = new THREE.BoxGeometry(step, step, step);
const mesh = new THREE.InstancedMesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.42,
metalness: 0.01
}),
cells.length
);
const matrix = new THREE.Matrix4();
const base = new THREE.Color(baseColor);
const accent = new THREE.Color(accentColor);
cells.forEach((cell, index) => {
matrix.makeTranslation(
cell.x * step,
cell.y * step,
cell.z * step
);
mesh.setMatrixAt(index, matrix);
const hasSeam =
cell.d2 > 4.5 &&
(Math.abs(cell.x) < 0.7 || Math.abs(cell.z) < 0.7);
mesh.setColorAt(index, hasSeam ? accent : base);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.ballId = id;
group.add(mesh);
scene.add(group);
ballMeshes.push(mesh);
return { id, group, mesh };
}
const ballDefinitions = [
{
id: "blue",
name: "Blue 1",
color: 0x2575d4,
accent: 0xf4f2df,
position: new THREE.Vector3(-1.6, 0.69, 2.0)
},
{
id: "green",
name: "Green 2",
color: 0x36a269,
accent: 0xf4f2df,
position: new THREE.Vector3(1.1, 0.69, 0.8)
},
{
id: "purple",
name: "Purple 3",
color: 0x8457c5,
accent: 0xf4f2df,
position: new THREE.Vector3(0.1, 0.69, -1.0)
},
{
id: "coral",
name: "Coral 4",
color: 0xec6d55,
accent: 0xf4f2df,
position: new THREE.Vector3(3.5, 0.69, 1.1)
}
];
const balls = {};
for (const definition of ballDefinitions) {
const ball = makeVoxelBall(
definition.id,
definition.color,
definition.accent,
definition.position
);
ball.name = definition.name;
balls[definition.id] = ball;
const label = makeLabel(definition.name.toUpperCase(), {
width: 420,
height: 100,
scale: [2.25, 0.54],
background: "rgba(26, 48, 42, 0.88)"
});
label.position.set(
definition.position.x,
1.78,
definition.position.z
);
scene.add(label);
}
const jack = makeVoxelBall(
"jack",
0xf06436,
0xffe4a6,
new THREE.Vector3(targetX, 0.47, targetZ),
0.62
);
const jackLabel = makeLabel("TARGET JACK", {
width: 460,
height: 112,
scale: [2.65, 0.65],
background: "rgba(121, 57, 32, 0.95)",
accent: "#ffd77c"
});
jackLabel.position.set(targetX, 1.63, targetZ);
scene.add(jackLabel);
// ------------------------------------------------------------
// Selected-ball marker and distance line
// ------------------------------------------------------------
const selectionMarker = new THREE.Group();
for (const side of [-1, 1]) {
addBox(
selectionMarker,
0.58,
0.055,
0.09,
side * 0.72,
0,
-0.72,
0xffd45c,
false
);
addBox(
selectionMarker,
0.58,
0.055,
0.09,
side * 0.72,
0,
0.72,
0xffd45c,
false
);
addBox(
selectionMarker,
0.09,
0.055,
0.58,
-0.72,
0,
side * 0.72,
0xffd45c,
false
);
addBox(
selectionMarker,
0.09,
0.055,
0.58,
0.72,
0,
side * 0.72,
0xffd45c,
false
);
}
scene.add(selectionMarker);
const distanceGeometry = new THREE.BufferGeometry();
const distanceLine = new THREE.Line(
distanceGeometry,
new THREE.LineDashedMaterial({
color: 0xfff0a6,
dashSize: 0.34,
gapSize: 0.19,
transparent: true,
opacity: 0.95
})
);
distanceLine.renderOrder = 5;
scene.add(distanceLine);
const distanceLabel = makeLabel(["SELECTED BALL", "0.0 m"], {
width: 560,
height: 150,
scale: [4.0, 1.07],
background: "rgba(24, 48, 40, 0.95)",
accent: "#ffd45c"
});
scene.add(distanceLabel);
const distanceOutput = document.querySelector("#distance");
const selectedNameOutput = document.querySelector("#selected-name");
const ballButtons = [...document.querySelectorAll("[data-ball]")];
let selectedBallId = "blue";
function selectBall(id) {
const ball = balls[id];
if (!ball) return;
selectedBallId = id;
for (const button of ballButtons) {
button.setAttribute(
"aria-pressed",
String(button.dataset.ball === id)
);
}
const start = ball.group.position.clone();
const end = jack.group.position.clone();
const distance = Math.hypot(
end.x - start.x,
end.z - start.z
);
start.y = 0.16;
end.y = 0.16;
distanceGeometry.setFromPoints([start, end]);
distanceLine.computeLineDistances();
const midpoint = start.clone().lerp(end, 0.5);
distanceLabel.position.set(midpoint.x, 1.55, midpoint.z);
selectionMarker.position.set(
ball.group.position.x,
0.16,
ball.group.position.z
);
updateLabel(distanceLabel, [
`${ball.name.toUpperCase()} → JACK`,
`${distance.toFixed(1)} m`
]);
distanceOutput.value = `${distance.toFixed(1)} m`;
selectedNameOutput.textContent =
`${ball.name} selected · illustrative scale`;
}
for (const button of ballButtons) {
button.addEventListener("click", () => {
selectBall(button.dataset.ball);
});
}
selectBall("blue");
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, picking, and keyboard
// ------------------------------------------------------------
const defaultView = {
yaw: 0.64,
pitch: 0.67,
radius: 31
};
const desiredView = { ...defaultView };
const currentView = { ...defaultView };
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
pointerMoved = true;
}
desiredView.yaw -= dx * 0.006;
desiredView.pitch = THREE.MathUtils.clamp(
desiredView.pitch + dy * 0.005,
0.28,
1.48
);
previousX = event.clientX;
previousY = event.clientY;
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved) {
const rect = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
ballMeshes,
false
);
if (intersections.length > 0) {
const ballId = intersections[0].object.userData.ballId;
selectBall(ballId);
}
}
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius + event.deltaY * 0.018,
15,
52
);
},
{ passive: false }
);
function resetCamera() {
desiredView.yaw = defaultView.yaw;
desiredView.pitch = defaultView.pitch;
desiredView.radius = defaultView.radius;
}
const viewToggle = document.querySelector("#view-toggle");
let topView = false;
viewToggle.addEventListener("click", () => {
topView = !topView;
if (topView) {
desiredView.yaw = 0;
desiredView.pitch = 1.47;
desiredView.radius = 29;
} else {
resetCamera();
}
viewToggle.setAttribute("aria-pressed", String(topView));
viewToggle.textContent = topView ? "3D view" : "Top view";
});
document.querySelector("#reset-view").addEventListener("click", () => {
topView = false;
viewToggle.setAttribute("aria-pressed", "false");
viewToggle.textContent = "Top view";
resetCamera();
});
const rampToggle = document.querySelector("#ramp-toggle");
rampToggle.addEventListener("click", () => {
const visible = !rampRoot.visible;
rampRoot.visible = visible;
rampToggle.setAttribute("aria-pressed", String(visible));
rampToggle.textContent = visible ? "Ramp: shown" : "Ramp: hidden";
});
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLButtonElement ||
event.target instanceof HTMLInputElement
) {
return;
}
const key = event.key.toLowerCase();
if (event.key === "ArrowLeft") {
desiredView.yaw += 0.12;
} else if (event.key === "ArrowRight") {
desiredView.yaw -= 0.12;
} else if (event.key === "ArrowUp") {
desiredView.pitch = THREE.MathUtils.clamp(
desiredView.pitch + 0.08,
0.28,
1.48
);
} else if (event.key === "ArrowDown") {
desiredView.pitch = THREE.MathUtils.clamp(
desiredView.pitch - 0.08,
0.28,
1.48
);
} else if (key === "+" || key === "=") {
desiredView.radius = Math.max(
15,
desiredView.radius - 2
);
} else if (key === "-" || key === "_") {
desiredView.radius = Math.min(
52,
desiredView.radius + 2
);
} else if (key === "r") {
resetCamera();
} else if (key === "p") {
viewToggle.click();
} else {
return;
}
event.preventDefault();
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function updateCamera() {
currentView.yaw +=
(desiredView.yaw - currentView.yaw) * 0.09;
currentView.pitch +=
(desiredView.pitch - currentView.pitch) * 0.09;
currentView.radius +=
(desiredView.radius - currentView.radius) * 0.09;
const horizontal =
Math.cos(currentView.pitch) * currentView.radius;
camera.position.set(
Math.sin(currentView.yaw) * horizontal,
Math.sin(currentView.pitch) * currentView.radius,
Math.cos(currentView.yaw) * horizontal
);
camera.lookAt(0, 0.45, 0.3);
}
renderer.setAnimationLoop(() => {
updateCamera();
renderer.render(scene, camera);
});
loading.remove();
</script>
</body>
</html>
```