Prompt specification
Build or customize the Three.js 3D scene "Service Beacon and Reachable Tiles" 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: Service Beacon and Reachable Tiles
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/service-beacon-and-reachable-tiles-x3577
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel service beacon on a small square grid. Place a wall with one narrow opening between the beacon and several house tokens. Offer two explicit coverage rules: straight-line radius and shortest traversable grid-path distance. Under the first rule, a nearby house may lie inside the circle even when the wall blocks a route; under the second, the path must pass through the opening. Display the chosen distance for one selected house and highlight its actual path. Keep the grid small enough that someone can count the steps directly and check the result.
Working Three.js Starter (service-beacon-and-reachable-tiles-x3577):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Beacon Coverage Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 23, 39, 0.92);
--panel-line: rgba(148, 163, 184, 0.18);
--text: #e7f0fa;
--muted: #8ea4bb;
--cyan: #49e3cf;
--cyan-soft: rgba(73, 227, 207, 0.14);
--orange: #ffb45b;
--red: #ff667d;
--green: #72ef9a;
}
* { 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;
cursor: pointer;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 0;
left: 0;
right: 0;
min-height: 74px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 16px 22px;
pointer-events: none;
background: linear-gradient(
to bottom,
rgba(4, 11, 21, 0.95),
rgba(4, 11, 21, 0.62) 70%,
transparent
);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 38px;
height: 38px;
position: relative;
display: grid;
place-items: center;
border: 1px solid rgba(73, 227, 207, 0.55);
border-radius: 11px;
background: var(--cyan-soft);
box-shadow: 0 0 28px rgba(73, 227, 207, 0.12);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 50%;
}
.brand-mark::before {
width: 13px;
height: 13px;
border: 2px solid var(--cyan);
}
.brand-mark::after {
width: 4px;
height: 4px;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
h1 {
margin: 0;
font-size: 16px;
font-weight: 720;
letter-spacing: 0.03em;
}
.subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.grid-badge {
padding: 8px 11px;
border: 1px solid var(--panel-line);
border-radius: 999px;
color: #b9cadc;
background: rgba(9, 20, 34, 0.72);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.1em;
white-space: nowrap;
}
.panel {
position: fixed;
z-index: 6;
left: 18px;
top: 88px;
width: 346px;
max-height: calc(100vh - 108px);
overflow: auto;
padding: 17px;
border: 1px solid var(--panel-line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #31475e transparent;
}
.eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section {
padding-bottom: 15px;
margin-bottom: 15px;
border-bottom: 1px solid var(--panel-line);
}
.section:last-child {
margin-bottom: 0;
border-bottom: 0;
padding-bottom: 0;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
margin: 10px 0;
padding: 4px;
border-radius: 12px;
background: rgba(2, 10, 19, 0.7);
border: 1px solid rgba(148, 163, 184, 0.1);
}
.segmented button {
min-height: 45px;
padding: 8px 7px;
border: 1px solid transparent;
border-radius: 9px;
color: #9fb2c6;
background: transparent;
font-size: 12px;
font-weight: 650;
transition: 150ms ease;
}
.segmented button:hover {
color: white;
background: rgba(255, 255, 255, 0.04);
}
.segmented button.active {
color: #ecfffb;
border-color: rgba(73, 227, 207, 0.45);
background: rgba(73, 227, 207, 0.13);
box-shadow: inset 0 0 20px rgba(73, 227, 207, 0.04);
}
.rule-description {
min-height: 52px;
margin: 0 0 13px;
color: #a9bbcd;
font-size: 12px;
line-height: 1.5;
}
.range-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
color: #c8d6e4;
font-size: 11px;
}
.range-label strong {
color: var(--cyan);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0 7px;
appearance: none;
border-radius: 99px;
background: linear-gradient(90deg, #284059, #1b2d41);
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #c8fff7;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(73, 227, 207, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #c8fff7;
border-radius: 50%;
background: var(--cyan);
}
.selected-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.selected-title {
margin-top: 4px;
font-size: 18px;
font-weight: 720;
}
.selected-coordinate {
color: var(--muted);
font-size: 11px;
}
.coverage-pill {
padding: 6px 9px;
border: 1px solid rgba(114, 239, 154, 0.35);
border-radius: 999px;
color: var(--green);
background: rgba(114, 239, 154, 0.1);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
}
.coverage-pill.outside {
color: var(--orange);
border-color: rgba(255, 180, 91, 0.35);
background: rgba(255, 180, 91, 0.09);
}
.metric {
display: flex;
align-items: baseline;
gap: 9px;
margin: 13px 0 3px;
}
.metric strong {
font-size: 34px;
line-height: 1;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.metric span {
color: var(--muted);
font-size: 12px;
}
.metric-caption {
min-height: 30px;
color: #8fa4b8;
font-size: 11px;
}
.comparison {
display: grid;
gap: 6px;
margin-top: 12px;
}
.compare-row {
display: grid;
grid-template-columns: 70px 1fr auto;
align-items: center;
gap: 8px;
padding: 8px 9px;
border: 1px solid rgba(148, 163, 184, 0.1);
border-radius: 9px;
background: rgba(1, 8, 16, 0.34);
font-size: 10px;
}
.compare-row > span {
color: var(--muted);
}
.compare-row strong {
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.compare-row em {
color: var(--green);
font-size: 9px;
font-style: normal;
font-weight: 800;
letter-spacing: 0.06em;
}
.compare-row em.outside {
color: var(--orange);
}
.insight {
margin: 12px 0 0;
padding: 10px 11px;
border-left: 2px solid var(--cyan);
border-radius: 0 8px 8px 0;
color: #b6c8d9;
background: rgba(73, 227, 207, 0.055);
font-size: 11px;
line-height: 1.5;
}
.route-text {
display: block;
margin-top: 5px;
color: #d9fff9;
font-size: 10px;
line-height: 1.5;
}
.house-picker {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 9px;
}
.house-button {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(148, 163, 184, 0.16);
border-radius: 9px;
color: #a9bbcd;
background: rgba(1, 8, 16, 0.32);
font-size: 11px;
}
.house-button:hover,
.house-button.active {
color: white;
border-color: rgba(73, 227, 207, 0.45);
background: rgba(73, 227, 207, 0.09);
}
.house-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 8px currentColor;
}
.legend {
position: fixed;
z-index: 5;
right: 18px;
bottom: 18px;
width: 228px;
padding: 13px 14px;
border: 1px solid var(--panel-line);
border-radius: 14px;
background: rgba(8, 19, 33, 0.86);
backdrop-filter: blur(14px);
font-size: 10px;
}
.legend-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: #b8c8d8;
}
.swatch {
width: 22px;
height: 4px;
border-radius: 99px;
background: var(--cyan);
}
.swatch.dashed {
height: 0;
border-top: 2px dashed var(--orange);
background: transparent;
}
.swatch.red { background: var(--red); }
.swatch.green { background: var(--green); }
.controls {
position: fixed;
z-index: 5;
right: 18px;
top: 88px;
display: flex;
gap: 6px;
}
.controls button {
min-width: 37px;
height: 37px;
padding: 0 10px;
border: 1px solid var(--panel-line);
border-radius: 10px;
color: #bfd0e0;
background: rgba(8, 19, 33, 0.85);
backdrop-filter: blur(12px);
font-size: 11px;
}
.controls button:hover {
color: white;
border-color: rgba(73, 227, 207, 0.4);
}
.help {
position: fixed;
z-index: 4;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
color: rgba(190, 208, 224, 0.66);
font-size: 10px;
letter-spacing: 0.035em;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 760px) {
.topbar {
min-height: 64px;
padding: 12px 14px;
}
h1 { font-size: 13px; }
.subtitle { font-size: 9px; }
.grid-badge { display: none; }
.panel {
top: auto;
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 46vh;
padding: 14px;
}
.controls {
top: 74px;
right: 10px;
}
.legend {
display: none;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>VOXEL BEACON · COVERAGE LAB</h1>
<div class="subtitle">Radius versus traversable grid path</div>
</div>
</div>
<div class="grid-badge">10 × 10 CELLS · 1 CELL = 1 STEP</div>
</header>
<aside class="panel" aria-label="Coverage controls">
<section class="section">
<div class="eyebrow">Coverage rule</div>
<div class="segmented">
<button id="radiusRule" class="active" type="button">Straight-line radius</button>
<button id="pathRule" type="button">Grid-path distance</button>
</div>
<p id="ruleDescription" class="rule-description"></p>
<label class="range-label" for="radiusRange">
<span>Straight-line radius</span>
<strong id="radiusValue">5.25 tiles</strong>
</label>
<input id="radiusRange" type="range" min="3" max="8" step="0.25" value="5.25">
<label class="range-label" for="pathRange">
<span>Maximum traversable path</span>
<strong id="pathValue">5 steps</strong>
</label>
<input id="pathRange" type="range" min="2" max="12" step="1" value="5">
</section>
<section class="section">
<div class="selected-head">
<div>
<div class="eyebrow">Selected house</div>
<div id="selectedTitle" class="selected-title">House H4</div>
<div id="selectedCoordinate" class="selected-coordinate">Cell H4</div>
</div>
<div id="coveragePill" class="coverage-pill">COVERED</div>
</div>
<div class="metric">
<strong id="chosenDistance">5.10</strong>
<span id="distanceUnit">tiles</span>
</div>
<div id="metricCaption" class="metric-caption"></div>
<div class="comparison">
<div id="radiusCompare" class="compare-row"></div>
<div id="pathCompare" class="compare-row"></div>
</div>
<p id="insight" class="insight"></p>
</section>
<section class="section">
<div class="eyebrow">Choose a house</div>
<div id="housePicker" class="house-picker"></div>
</section>
</aside>
<div class="controls" aria-label="Camera controls">
<button id="topView" type="button">Top</button>
<button id="zoomIn" type="button">+</button>
<button id="zoomOut" type="button">−</button>
<button id="resetView" type="button">Reset</button>
</div>
<div class="legend" aria-label="Legend">
<div class="legend-title">Scene legend</div>
<div class="legend-item"><i class="swatch"></i>Actual traversable path</div>
<div class="legend-item"><i class="swatch dashed"></i>Straight distance / sightline</div>
<div class="legend-item"><i class="swatch red"></i>Blocked wall intersection</div>
<div class="legend-item"><i class="swatch green"></i>Only wall opening · F5</div>
</div>
<div class="help">Drag: orbit · Right-drag: pan · Wheel: zoom · Click a house to select</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const GRID = 10;
const BEACON = { x: 2, z: 4 };
const WALL_X = 5;
const OPENING_Z = 4;
const houseDefinitions = [
{ id: "H4", label: "House H4", x: 7, z: 3, color: 0xff9a70 },
{ id: "G6", label: "House G6", x: 6, z: 5, color: 0xf4cf62 },
{ id: "I8", label: "House I8", x: 8, z: 7, color: 0xb89cff },
{ id: "I2", label: "House I2", x: 8, z: 1, color: 0x72b9ff },
{ id: "G9", label: "House G9", x: 6, z: 8, color: 0x74d69b }
];
const key = (x, z) => `${x}:${z}`;
const worldX = x => x - (GRID - 1) / 2;
const worldZ = z => z - (GRID - 1) / 2;
const cellName = (x, z) => `${String.fromCharCode(65 + x)}${z + 1}`;
const wallCells = new Set();
for (let z = 0; z < GRID; z++) {
if (!(WALL_X === 5 && z === OPENING_Z)) {
wallCells.add(key(WALL_X, z));
}
}
function isWalkable(x, z) {
return x >= 0 && x < GRID &&
z >= 0 && z < GRID &&
!wallCells.has(key(x, z));
}
function bfsDistanceMap(start) {
const distances = new Map([[key(start.x, start.z), 0]]);
const queue = [start];
for (let i = 0; i < queue.length; i++) {
const current = queue[i];
const currentDistance = distances.get(key(current.x, current.z));
for (const [dx, dz] of [[1, 0], [0, -1], [0, 1], [-1, 0]]) {
const nx = current.x + dx;
const nz = current.z + dz;
const nextKey = key(nx, nz);
if (!isWalkable(nx, nz) || distances.has(nextKey)) continue;
distances.set(nextKey, currentDistance + 1);
queue.push({ x: nx, z: nz });
}
}
return distances;
}
function shortestPath(start, target) {
if (!isWalkable(target.x, target.z)) return [];
const queue = [start];
const cameFrom = new Map([[key(start.x, start.z), null]]);
for (let i = 0; i < queue.length; i++) {
const current = queue[i];
if (current.x === target.x && current.z === target.z) break;
for (const [dx, dz] of [[1, 0], [0, -1], [0, 1], [-1, 0]]) {
const nx = current.x + dx;
const nz = current.z + dz;
const nextKey = key(nx, nz);
if (!isWalkable(nx, nz) || cameFrom.has(nextKey)) continue;
cameFrom.set(nextKey, current);
queue.push({ x: nx, z: nz });
}
}
if (!cameFrom.has(key(target.x, target.z))) return [];
const path = [];
let current = target;
while (current) {
path.push({ x: current.x, z: current.z });
current = cameFrom.get(key(current.x, current.z));
}
return path.reverse();
}
const distanceMap = bfsDistanceMap(BEACON);
const houseModels = houseDefinitions.map(house => {
const path = shortestPath(BEACON, house);
return {
...house,
path,
pathSteps: path.length - 1,
straightDistance: Math.hypot(
house.x - BEACON.x,
house.z - BEACON.z
)
};
});
let selectedId = "H4";
let rule = "radius";
let radius = 5.25;
let pathLimit = 5;
const selectedHouse = () =>
houseModels.find(house => house.id === selectedId);
/* ---------- Renderer and camera ---------- */
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 21, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraState = {
yaw: -0.62,
pitch: 0.72,
distance: 28,
target: new THREE.Vector3(0, 0, 0),
viewSize: 12.8
};
function updateCamera() {
const { yaw, pitch, distance, target, viewSize } = cameraState;
const aspect = window.innerWidth / window.innerHeight;
const verticalSize = Math.max(viewSize, viewSize / aspect);
camera.left = -verticalSize * aspect / 2;
camera.right = verticalSize * aspect / 2;
camera.top = verticalSize / 2;
camera.bottom = -verticalSize / 2;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * distance,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * Math.cos(pitch) * distance
);
camera.lookAt(target);
camera.updateProjectionMatrix();
}
function resetCamera() {
cameraState.yaw = -0.62;
cameraState.pitch = 0.72;
cameraState.target.set(0, 0, 0);
cameraState.viewSize = 12.8;
updateCamera();
}
function topCamera() {
cameraState.yaw = 0;
cameraState.pitch = Math.PI / 2 - 0.015;
cameraState.target.set(0, 0, 0);
cameraState.viewSize = 12.2;
updateCamera();
}
updateCamera();
/* ---------- Lighting ---------- */
scene.add(new THREE.HemisphereLight(0xb9ddff, 0x08111d, 1.8));
const sun = new THREE.DirectionalLight(0xffffff, 3.1);
sun.position.set(-7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0006;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x49e3cf, 1.3);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
/* ---------- Helpers ---------- */
function createBox(parent, width, height, depth, x, y, z, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.arcTo(x + width, y, x + width, y + height, radius);
context.arcTo(x + width, y + height, x, y + height, radius);
context.arcTo(x, y + height, x, y, radius);
context.arcTo(x, y, x + width, y, radius);
context.closePath();
}
function textSprite(text, options = {}) {
const {
color = "#dffaff",
background = "rgba(5, 15, 27, 0.88)",
border = "rgba(73, 227, 207, 0.35)",
scale = [1.3, 0.32],
fontSize = 42
} = options;
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 4, 4, 504, 120, 22);
context.fillStyle = background;
context.fill();
if (border) {
context.lineWidth = 3;
context.strokeStyle = border;
context.stroke();
}
context.font = `700 ${fontSize}px ui-sans-serif, system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = color;
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 20;
return sprite;
}
/* ---------- Grid ---------- */
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0x101d2b,
roughness: 0.78,
metalness: 0.15
});
const plinth = createBox(
scene, 10.65, 0.34, 10.65,
0, -0.29, 0, plinthMaterial
);
plinth.castShadow = false;
const tileGeometry = new THREE.BoxGeometry(0.94, 0.14, 0.94);
const tileMaterials = [
new THREE.MeshStandardMaterial({
color: 0x172a3a,
roughness: 0.95,
metalness: 0.03
}),
new THREE.MeshStandardMaterial({
color: 0x1a2e40,
roughness: 0.95,
metalness: 0.03
})
];
for (let z = 0; z < GRID; z++) {
for (let x = 0; x < GRID; x++) {
const tile = new THREE.Mesh(
tileGeometry,
tileMaterials[(x + z) % 2]
);
tile.position.set(worldX(x), -0.07, worldZ(z));
tile.receiveShadow = true;
scene.add(tile);
}
}
const gridPositions = [];
for (let i = 0; i <= GRID; i++) {
const p = -GRID / 2 + i;
gridPositions.push(p, 0.015, -GRID / 2, p, 0.015, GRID / 2);
gridPositions.push(-GRID / 2, 0.015, p, GRID / 2, 0.015, p);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
scene.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x527087,
transparent: true,
opacity: 0.35
})
));
for (let x = 0; x < GRID; x++) {
const label = textSprite(String.fromCharCode(65 + x), {
color: "#8fa8bc",
background: "rgba(6, 17, 29, 0.78)",
border: null,
scale: [0.36, 0.18],
fontSize: 54
});
label.position.set(worldX(x), 0.1, 5.55);
scene.add(label);
}
for (let z = 0; z < GRID; z++) {
const label = textSprite(String(z + 1), {
color: "#8fa8bc",
background: "rgba(6, 17, 29, 0.78)",
border: null,
scale: [0.36, 0.18],
fontSize: 54
});
label.position.set(-5.55, 0.1, worldZ(z));
scene.add(label);
}
/* ---------- Wall and opening ---------- */
const wallGroup = new THREE.Group();
scene.add(wallGroup);
const wallMaterials = [
new THREE.MeshStandardMaterial({
color: 0x405268,
roughness: 0.7,
metalness: 0.12
}),
new THREE.MeshStandardMaterial({
color: 0x35475c,
roughness: 0.72,
metalness: 0.12
}),
new THREE.MeshStandardMaterial({
color: 0x60758b,
roughness: 0.6,
metalness: 0.15
})
];
for (let z = 0; z < GRID; z++) {
if (z === OPENING_Z) continue;
createBox(
wallGroup, 0.9, 0.72, 0.9,
worldX(WALL_X), 0.36, worldZ(z), wallMaterials[z % 2]
);
createBox(
wallGroup, 0.9, 0.72, 0.9,
worldX(WALL_X), 1.08, worldZ(z), wallMaterials[(z + 1) % 2]
);
createBox(
wallGroup, 0.94, 0.12, 0.94,
worldX(WALL_X), 1.5, worldZ(z), wallMaterials[2]
);
}
const openingMaterial = new THREE.MeshStandardMaterial({
color: 0x1d725d,
emissive: 0x36d99a,
emissiveIntensity: 0.85,
roughness: 0.42,
metalness: 0.08
});
createBox(
scene, 0.88, 0.055, 0.88,
worldX(WALL_X), 0.025, worldZ(OPENING_Z), openingMaterial
);
const openingLabel = textSprite("ONLY GAP · F5", {
color: "#a7ffcf",
background: "rgba(7, 37, 33, 0.9)",
border: "rgba(114, 239, 154, 0.6)",
scale: [1.65, 0.34],
fontSize: 38
});
openingLabel.position.set(worldX(WALL_X), 1.95, worldZ(OPENING_Z));
scene.add(openingLabel);
/* ---------- Beacon ---------- */
const beaconGroup = new THREE.Group();
beaconGroup.position.set(worldX(BEACON.x), 0, worldZ(BEACON.z));
scene.add(beaconGroup);
const beaconBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x223b4e,
roughness: 0.55,
metalness: 0.35
});
const beaconCoreMaterial = new THREE.MeshStandardMaterial({
color: 0x44d9d0,
emissive: 0x20cdbf,
emissiveIntensity: 1.8,
roughness: 0.28,
metalness: 0.12
});
const beaconWhiteMaterial = new THREE.MeshStandardMaterial({
color: 0xe9fffb,
emissive: 0x8ffff0,
emissiveIntensity: 1.5,
roughness: 0.25
});
createBox(beaconGroup, 0.78, 0.2, 0.78, 0, 0.1, 0, beaconBaseMaterial);
createBox(beaconGroup, 0.52, 0.62, 0.52, 0, 0.51, 0, beaconCoreMaterial);
createBox(beaconGroup, 0.36, 0.2, 0.36, 0, 0.92, 0, beaconWhiteMaterial);
createBox(beaconGroup, 0.08, 0.38, 0.08, 0, 1.2, 0, beaconBaseMaterial);
createBox(beaconGroup, 0.22, 0.18, 0.22, 0, 1.46, 0, beaconCoreMaterial);
const beaconLight = new THREE.PointLight(0x49e3cf, 7, 5, 2);
beaconLight.position.set(0, 1.1, 0);
beaconGroup.add(beaconLight);
const beaconRings = [];
for (let i = 0; i < 2; i++) {
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x49e3cf,
transparent: true,
opacity: 0.5,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.55 + i * 0.15, 0.025, 8, 56),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.11;
beaconGroup.add(ring);
beaconRings.push(ring);
}
const beaconLabel = textSprite("BEACON · C5", {
color: "#c9fff8",
background: "rgba(5, 35, 39, 0.9)",
border: "rgba(73, 227, 207, 0.65)",
scale: [1.65, 0.35]
});
beaconLabel.position.set(worldX(BEACON.x), 1.95, worldZ(BEACON.z));
scene.add(beaconLabel);
/* ---------- House tokens ---------- */
const houseRoots = new Map();
for (const house of houseModels) {
const group = new THREE.Group();
group.position.set(worldX(house.x), 0, worldZ(house.z));
group.userData.houseId = house.id;
scene.add(group);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: house.color,
roughness: 0.78,
metalness: 0.03
});
const roofColor = new THREE.Color(house.color).multiplyScalar(0.62);
const roofMaterial = new THREE.MeshStandardMaterial({
color: roofColor,
roughness: 0.8
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0xe9f3fa,
roughness: 0.65
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xbff8ff,
emissive: 0x4bbfd0,
emissiveIntensity: 0.85,
roughness: 0.35
});
createBox(group, 0.74, 0.1, 0.74, 0, 0.05, 0, roofMaterial);
createBox(group, 0.58, 0.5, 0.58, 0, 0.35, 0, bodyMaterial);
createBox(group, 0.66, 0.18, 0.66, 0, 0.68, 0, roofMaterial);
createBox(group, 0.44, 0.18, 0.44, 0, 0.86, 0, roofMaterial);
createBox(group, 0.22, 0.18, 0.22, 0, 1.03, 0, roofMaterial);
createBox(group, 0.12, 0.28, 0.035, 0.12, 0.25, 0.306, trimMaterial);
createBox(group, 0.15, 0.14, 0.035, -0.15, 0.43, 0.307, windowMaterial);
createBox(group, 0.12, 0.28, 0.12, 0.17, 0.95, -0.12, roofMaterial);
const statusMaterial = new THREE.MeshBasicMaterial({
color: 0xffb45b,
transparent: true,
opacity: 0.8,
depthWrite: false
});
const statusRing = new THREE.Mesh(
new THREE.TorusGeometry(0.49, 0.035, 8, 48),
statusMaterial
);
statusRing.rotation.x = Math.PI / 2;
statusRing.position.y = 0.11;
group.add(statusRing);
const label = textSprite(house.id, {
color: "#fff4ec",
background: "rgba(30, 23, 30, 0.86)",
border: "rgba(255, 255, 255, 0.16)",
scale: [0.72, 0.25],
fontSize: 52
});
label.position.set(0, 1.42, 0);
group.add(label);
houseRoots.set(house.id, {
group,
statusRing,
statusMaterial
});
}
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.64, 0.045, 8, 56),
selectionMaterial
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.position.y = 0.16;
scene.add(selectionRing);
/* ---------- Radius circle ---------- */
const circleGroup = new THREE.Group();
circleGroup.position.set(worldX(BEACON.x), 0, worldZ(BEACON.z));
scene.add(circleGroup);
const circleFillMaterial = new THREE.MeshBasicMaterial({
color: 0x49e3cf,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
});
const circleFill = new THREE.Mesh(
new THREE.CircleGeometry(1, 96),
circleFillMaterial
);
circleFill.rotation.x = -Math.PI / 2;
circleFill.position.y = 0.035;
circleGroup.add(circleFill);
const circlePoints = [];
for (let i = 0; i < 96; i++) {
const angle = i / 96 * Math.PI * 2;
circlePoints.push(new THREE.Vector3(
Math.cos(angle),
0.055,
Math.sin(angle)
));
}
const circleLine = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(circlePoints),
new THREE.LineBasicMaterial({
color: 0x61f4dc,
transparent: true,
opacity: 0.85
})
);
circleGroup.add(circleLine);
/* ---------- Reachable cells for path rule ---------- */
const reachableGroup = new THREE.Group();
scene.add(reachableGroup);
const reachableMaterial = new THREE.MeshBasicMaterial({
color: 0x49e3cf,
transparent: true,
opacity: 0.14,
side: THREE.DoubleSide,
depthWrite: false
});
const reachableCells = new Map();
for (let z = 0; z < GRID; z++) {
for (let x = 0; x < GRID; x++) {
const cell = new THREE.Mesh(
new THREE.PlaneGeometry(0.9, 0.9),
reachableMaterial
);
cell.rotation.x = -Math.PI / 2;
cell.position.set(worldX(x), 0.028, worldZ(z));
cell.visible = false;
reachableGroup.add(cell);
reachableCells.set(key(x, z), cell);
}
}
/* ---------- Actual path and direct line ---------- */
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeMaterial = new THREE.MeshStandardMaterial({
color: 0x49e3cf,
emissive: 0x1db9aa,
emissiveIntensity: 1.05,
roughness: 0.32,
metalness: 0.05
});
const routeSegmentGeometry = new THREE.BoxGeometry(1, 0.075, 0.17);
const routeNodeGeometry = new THREE.SphereGeometry(0.105, 12, 8);
function clearGroup(group) {
while (group.children.length) {
group.remove(group.children[0]);
}
}
function rebuildRoute(house) {
clearGroup(routeGroup);
for (let i = 0; i < house.path.length - 1; i++) {
const a = house.path[i];
const b = house.path[i + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const segment = new THREE.Mesh(routeSegmentGeometry, routeMaterial);
segment.position.set(
(worldX(a.x) + worldX(b.x)) / 2,
0.14,
(worldZ(a.z) + worldZ(b.z)) / 2
);
segment.rotation.y = -Math.atan2(dz, dx);
segment.scale.x = length;
segment.castShadow = false;
routeGroup.add(segment);
}
for (const point of house.path) {
const node = new THREE.Mesh(routeNodeGeometry, routeMaterial);
node.position.set(worldX(point.x), 0.16, worldZ(point.z));
routeGroup.add(node);
}
}
const directGroup = new THREE.Group();
scene.add(directGroup);
const directLineMaterial = new THREE.LineDashedMaterial({
color: 0xffb45b,
dashSize: 0.22,
gapSize: 0.14,
transparent: true,
opacity: 0.9,
depthTest: false
});
const blockedMarker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.14),
new THREE.MeshBasicMaterial({
color: 0xff667d,
depthTest: false
})
);
blockedMarker.renderOrder = 15;
directGroup.add(blockedMarker);
const blockedLabel = textSprite("BLOCKED", {
color: "#ffd7de",
background: "rgba(70, 16, 31, 0.9)",
border: "rgba(255, 102, 125, 0.7)",
scale: [1.15, 0.28],
fontSize: 45
});
directGroup.add(blockedLabel);
function directWallIntersection(house) {
const t = (WALL_X - BEACON.x) / (house.x - BEACON.x);
const z = BEACON.z + (house.z - BEACON.z) * t;
const zCell = Math.round(z);
const blocked = wallCells.has(key(WALL_X, zCell));
return {
blocked,
x: worldX(WALL_X),
z: worldZ(z),
zCell
};
}
function rebuildDirectLine(house) {
clearGroup(directGroup);
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(worldX(BEACON.x), 0.98, worldZ(BEACON.z)),
new THREE.Vector3(worldX(house.x), 0.98, worldZ(house.z))
]);
const line = new THREE.Line(geometry, directLineMaterial);
line.computeLineDistances();
line.renderOrder = 14;
directGroup.add(line);
const intersection = directWallIntersection(house);
blockedMarker.visible = intersection.blocked;
blockedLabel.visible = intersection.blocked;
if (intersection.blocked) {
blockedMarker.position.set(intersection.x, 1.38, intersection.z);
blockedLabel.position.set(intersection.x, 1.92, intersection.z);
}
}
/* ---------- UI ---------- */
const radiusRuleButton = document.querySelector("#radiusRule");
const pathRuleButton = document.querySelector("#pathRule");
const radiusRange = document.querySelector("#radiusRange");
const pathRange = document.querySelector("#pathRange");
const radiusValue = document.querySelector("#radiusValue");
const pathValue = document.querySelector("#pathValue");
const ruleDescription = document.querySelector("#ruleDescription");
const selectedTitle = document.querySelector("#selectedTitle");
const selectedCoordinate = document.querySelector("#selectedCoordinate");
const coveragePill = document.querySelector("#coveragePill");
const chosenDistance = document.querySelector("#chosenDistance");
const distanceUnit = document.querySelector("#distanceUnit");
const metricCaption = document.querySelector("#metricCaption");
const radiusCompare = document.querySelector("#radiusCompare");
const pathCompare = document.querySelector("#pathCompare");
const insight = document.querySelector("#insight");
const housePicker = document.querySelector("#housePicker");
housePicker.innerHTML = houseModels.map(house => `
<button class="house-button" type="button" data-house-id="${house.id}">
<i class="house-dot" id="dot-${house.id}"></i>
${house.id}
</button>
`).join("");
function setRule(nextRule) {
rule = nextRule;
radiusRuleButton.classList.toggle("active", rule === "radius");
pathRuleButton.classList.toggle("active", rule === "path");
updateAll();
}
function setSelected(id) {
selectedId = id;
updateAll();
}
radiusRuleButton.addEventListener("click", () => setRule("radius"));
pathRuleButton.addEventListener("click", () => setRule("path"));
radiusRange.addEventListener("input", event => {
radius = Number(event.target.value);
updateAll();
});
pathRange.addEventListener("input", event => {
pathLimit = Number(event.target.value);
updateAll();
});
housePicker.querySelectorAll("[data-house-id]").forEach(button => {
button.addEventListener("click", () => {
setSelected(button.dataset.houseId);
});
});
document.querySelector("#topView").addEventListener("click", topCamera);
document.querySelector("#resetView").addEventListener("click", resetCamera);
document.querySelector("#zoomIn").addEventListener("click", () => {
cameraState.viewSize = Math.max(7, cameraState.viewSize * 0.88);
updateCamera();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
cameraState.viewSize = Math.min(22, cameraState.viewSize / 0.88);
updateCamera();
});
function updateAll() {
const house = selectedHouse();
const radiusCovered = house.straightDistance <= radius;
const pathCovered = house.pathSteps <= pathLimit;
const activeCovered = rule === "radius" ? radiusCovered : pathCovered;
radiusValue.textContent = `${radius.toFixed(2)} tiles`;
pathValue.textContent = `${pathLimit} ${pathLimit === 1 ? "step" : "steps"}`;
if (rule === "radius") {
ruleDescription.textContent =
"A house is covered when its straight-line center distance is within the radius. Walls do not affect this test.";
} else {
ruleDescription.textContent =
"A house is covered when a four-neighbor grid path reaches it within the step limit. The route must use the F5 opening.";
}
selectedTitle.textContent = house.label;
selectedCoordinate.textContent = `Cell ${house.id} · beacon at C5`;
coveragePill.textContent = activeCovered ? "COVERED" : "OUTSIDE";
coveragePill.classList.toggle("outside", !activeCovered);
if (rule === "radius") {
chosenDistance.textContent = house.straightDistance.toFixed(2);
distanceUnit.textContent = "tiles";
metricCaption.textContent = "Euclidean center-to-center distance; no wall test.";
} else {
chosenDistance.textContent = String(house.pathSteps);
distanceUnit.textContent = "steps";
metricCaption.textContent = "Shortest legal grid path, counted cell-to-cell.";
}
radiusCompare.innerHTML = `
<span>Radius</span>
<strong>${house.straightDistance.toFixed(2)} tiles</strong>
<em class="${radiusCovered ? "" : "outside"}">
${radiusCovered ? "COVERED" : "OUTSIDE"}
</em>
`;
pathCompare.innerHTML = `
<span>Path</span>
<strong>${house.pathSteps} steps</strong>
<em class="${pathCovered ? "" : "outside"}">
${pathCovered ? "COVERED" : "OUTSIDE"}
</em>
`;
if (rule === "radius") {
const intersection = directWallIntersection(house);
insight.innerHTML = intersection.blocked
? `H4-style radius coverage ignores obstacles: ${house.id} is ${house.straightDistance.toFixed(2)} tiles from C5 and lies inside the ${radius.toFixed(2)}-tile circle. Its straight sightline hits the wall at ${cellName(WALL_X, intersection.zCell)}.`
: `${house.id} is ${house.straightDistance.toFixed(2)} tiles from C5, inside the ${radius.toFixed(2)}-tile radius. The straight sightline is not blocked by the wall.`;
} else {
const routeText = house.path.map(point => cellName(point.x, point.z)).join(" → ");
insight.innerHTML = `
The shortest legal route is ${house.pathSteps} steps and must enter the wall at F5.
<span class="route-text">${routeText}</span>
Current path limit: ${pathLimit} steps.
`;
}
circleGroup.visible = rule === "radius";
circleGroup.scale.setScalar(radius);
for (const [cellKey, cell] of reachableCells) {
const distance = distanceMap.get(cellKey);
cell.visible = rule === "path" &&
distance !== undefined &&
distance <= pathLimit;
}
for (const item of houseModels) {
const covered = rule === "radius"
? item.straightDistance <= radius
: item.pathSteps <= pathLimit;
const visual = houseRoots.get(item.id);
visual.statusMaterial.color.setHex(covered ? 0x72ef9a : 0xffb45b);
visual.statusMaterial.opacity = covered ? 0.95 : 0.55;
const dot = document.querySelector(`#dot-${item.id}`);
if (dot) {
dot.style.background = covered ? "#72ef9a" : "#ffb45b";
}
const button = housePicker.querySelector(`[data-house-id="${item.id}"]`);
if (button) button.classList.toggle("active", item.id === selectedId);
}
selectionRing.position.set(worldX(house.x), 0.16, worldZ(house.z));
rebuildRoute(house);
rebuildDirectLine(house);
directLineMaterial.opacity = rule === "radius" ? 0.9 : 0.27;
routeMaterial.emissiveIntensity = rule === "path" ? 1.65 : 0.95;
}
/* ---------- Direct camera interaction ---------- */
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: false,
button: 0,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0
};
function findHouseId(object) {
while (object) {
if (object.userData.houseId) return object.userData.houseId;
object = object.parent;
}
return null;
}
function pickHouse(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
[...houseRoots.values()].map(item => item.group),
true
);
for (const intersection of intersections) {
const id = findHouseId(intersection.object);
if (id) return id;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerState.down = true;
pointerState.moved = false;
pointerState.button = event.button;
pointerState.startX = event.clientX;
pointerState.startY = event.clientY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerState.down) {
renderer.domElement.style.cursor =
pickHouse(event.clientX, event.clientY) ? "pointer" : "grab";
return;
}
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
if (Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
) > 4) {
pointerState.moved = true;
}
if (pointerState.button === 0) {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.28,
1.35
);
} else if (pointerState.button === 2) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale = cameraState.viewSize / 700;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
pointerState.down = false;
if (
pointerState.button === 0 &&
!pointerState.moved
) {
const id = pickHouse(event.clientX, event.clientY);
if (id) setSelected(id);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
});
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.viewSize = THREE.MathUtils.clamp(
cameraState.viewSize * Math.exp(event.deltaY * 0.001),
7,
22
);
updateCamera();
}, { passive: false });
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
/* ---------- Animation ---------- */
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
beaconCoreMaterial.emissiveIntensity =
1.6 + Math.sin(time * 3.2) * 0.32;
beaconLight.intensity =
6.3 + Math.sin(time * 3.2) * 1.2;
beaconRings.forEach((ring, index) => {
const phase = (time * 0.65 + index * 0.5) % 1;
ring.scale.setScalar(0.85 + phase * 0.7);
ring.material.opacity = 0.52 * (1 - phase);
});
openingMaterial.emissiveIntensity =
rule === "path"
? 0.95 + Math.sin(time * 3.5) * 0.25
: 0.65;
selectionRing.scale.setScalar(
1 + Math.sin(time * 4.2) * 0.035
);
renderer.render(scene, camera);
}
updateAll();
animate();
</script>
</body>
</html>
```