Prompt specification
Build or customize the Three.js 3D scene "Connected and Disconnected Tile Clusters" 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: Connected and Disconnected Tile Clusters
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/connected-and-disconnected-tile-clusters-x3585
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a scene with two equal-sized tile groups, one connected and one split. Show adjacency explicitly so equal area is not confused with equal accessibility. Voxel style.
Working Three.js Starter (connected-and-disconnected-tile-clusters-x3585):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Adjacency — Equal Area, Unequal Access</title>
<style>
:root {
--bg: #090e1a;
--panel: rgba(15, 23, 39, 0.88);
--border: rgba(156, 184, 220, 0.18);
--text: #edf5ff;
--muted: #91a4bd;
--connected: #54e0d0;
--split: #ff9d5c;
--second-island: #b78aff;
--danger: #ff6278;
--probe: #ffe46b;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.title-block {
position: absolute;
top: 20px;
left: 22px;
max-width: 480px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--connected);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 44px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 440px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.stats {
position: absolute;
top: 20px;
right: 22px;
display: grid;
grid-template-columns: repeat(2, 145px);
gap: 10px;
padding: 12px;
border-radius: 16px;
}
.stat {
min-height: 78px;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.stat-title {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.stat-values {
display: flex;
align-items: baseline;
gap: 7px;
font-size: 23px;
line-height: 1;
}
.stat-values b:first-child {
color: var(--connected);
}
.stat-values b:last-child {
color: var(--split);
}
.stat-values i {
color: #61728a;
font-size: 13px;
font-style: normal;
}
.stat-key {
display: block;
margin-top: 7px;
color: #687b94;
font-size: 9px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.world-label {
position: absolute;
z-index: 4;
min-width: 190px;
padding: 10px 12px;
transform: translate(-50%, -100%);
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(10, 16, 29, 0.88);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
pointer-events: none;
transition: opacity 150ms ease;
}
.world-label .label-tag {
display: inline-block;
margin-bottom: 5px;
color: var(--connected);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.world-label.split .label-tag {
color: var(--split);
}
.world-label strong {
display: block;
font-size: 14px;
letter-spacing: -0.01em;
}
.world-label .meta,
.world-label .reach {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.world-label .reach {
color: #c8d6e8;
}
.island-tag {
position: absolute;
z-index: 3;
transform: translate(-50%, -50%);
padding: 5px 8px;
border-radius: 7px;
background: rgba(10, 16, 29, 0.82);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.island-tag.a {
color: var(--split);
border: 1px solid rgba(255, 157, 92, 0.35);
}
.island-tag.b {
color: var(--second-island);
border: 1px solid rgba(183, 138, 255, 0.35);
}
.no-link-label {
position: absolute;
z-index: 4;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(255, 98, 120, 0.45);
border-radius: 7px;
background: rgba(41, 15, 28, 0.9);
color: var(--danger);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
.bottom-bar {
position: absolute;
right: 22px;
bottom: 20px;
left: 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 12px 14px;
border-radius: 15px;
}
.legend {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 9px 18px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
color: #b9c8da;
font-size: 11px;
white-space: nowrap;
}
.swatch {
width: 16px;
height: 8px;
border-radius: 2px;
background: var(--connected);
box-shadow: 0 0 12px rgba(84, 224, 208, 0.7);
}
.swatch.probe {
width: 10px;
height: 10px;
background: var(--probe);
box-shadow: 0 0 12px rgba(255, 228, 107, 0.75);
}
.swatch.dim {
background: #30394c;
box-shadow: none;
border: 1px solid #4a556c;
}
.swatch.gap {
width: 11px;
height: 11px;
background: transparent;
border: 2px solid var(--danger);
box-shadow: none;
transform: rotate(45deg);
}
.controls {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition:
background 120ms ease,
border-color 120ms ease;
}
button:hover {
border-color: rgba(84, 224, 208, 0.5);
background: rgba(84, 224, 208, 0.1);
}
button.active {
color: var(--connected);
border-color: rgba(84, 224, 208, 0.38);
}
.hint {
position: absolute;
bottom: 86px;
left: 50%;
transform: translateX(-50%);
padding: 6px 10px;
border-radius: 999px;
background: rgba(9, 14, 26, 0.65);
color: #8295ae;
font-size: 10px;
white-space: nowrap;
}
#probeStatus {
position: absolute;
bottom: 126px;
left: 50%;
transform: translateX(-50%);
color: #b9c8da;
font-size: 11px;
text-align: center;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: var(--muted);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
@media (max-width: 900px) {
.title-block {
max-width: 360px;
}
.stats {
grid-template-columns: repeat(2, 125px);
}
.stat {
min-height: 70px;
}
.bottom-bar {
align-items: flex-start;
flex-direction: column;
}
.hint {
bottom: 112px;
}
#probeStatus {
bottom: 145px;
}
}
@media (max-width: 680px) {
.title-block {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
}
h1 {
max-width: 330px;
font-size: 27px;
}
.subtitle {
display: none;
}
.stats {
top: 83px;
right: 14px;
left: 14px;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
padding: 7px;
}
.stat {
min-height: 66px;
padding: 7px;
}
.stat-title {
min-height: 23px;
font-size: 8px;
}
.stat-values {
gap: 4px;
font-size: 18px;
}
.stat-key {
display: none;
}
.world-label {
min-width: 145px;
padding: 7px 9px;
}
.world-label .meta {
display: none;
}
.world-label strong {
font-size: 11px;
}
.world-label .reach {
font-size: 9px;
}
.island-tag {
display: none;
}
.bottom-bar {
right: 14px;
bottom: 14px;
left: 14px;
gap: 10px;
padding: 10px;
}
.legend {
gap: 7px 12px;
}
.legend-item {
font-size: 9px;
}
.controls {
width: 100%;
}
button {
flex: 1;
}
.hint {
display: none;
}
#probeStatus {
bottom: 126px;
width: calc(100vw - 32px);
font-size: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel adjacency comparison"></canvas>
<div class="hud">
<header class="title-block">
<div class="eyebrow">Voxel topology study</div>
<h1>Equal area.<br />Unequal access.</h1>
<p class="subtitle">
Both inventories contain exactly 12 tiles. Cyan tracks show direct
grid-face adjacency. Click any tile to move a probe and reveal the
connected region reachable from that tile.
</p>
</header>
<section class="stats panel" aria-label="Comparison statistics">
<div class="stat">
<span class="stat-title">Total tile area</span>
<div class="stat-values"><b>12</b><i>=</i><b>12</b></div>
<span class="stat-key">connected / split</span>
</div>
<div class="stat">
<span class="stat-title">Components</span>
<div class="stat-values"><b>1</b><i>vs</i><b>2</b></div>
<span class="stat-key">connected / split</span>
</div>
<div class="stat">
<span class="stat-title">Best component</span>
<div class="stat-values"><b>12</b><i>vs</i><b>7</b></div>
<span class="stat-key">connected / split</span>
</div>
<div class="stat">
<span class="stat-title">Face links</span>
<div class="stat-values"><b>17</b><i>vs</i><b>13</b></div>
<span class="stat-key">connected / split</span>
</div>
</section>
<div id="connectedLabel" class="world-label">
<span class="label-tag">Connected</span>
<strong>12-tile connected island</strong>
<span class="meta">17 direct face links · 1 component</span>
<span class="reach">12 / 12 reachable from probe</span>
</div>
<div id="splitLabel" class="world-label split">
<span class="label-tag">Split</span>
<strong>12 tiles · 7 + 5 islands</strong>
<span class="meta">13 direct face links · 2 components</span>
<span class="reach">7 / 12 reachable from probe</span>
</div>
<div id="islandATag" class="island-tag a">Island A · 7 tiles</div>
<div id="islandBTag" class="island-tag b">Island B · 5 tiles</div>
<div id="noLinkLabel" class="no-link-label">No shared face</div>
<div id="probeStatus">
Probe placed in the 12-tile island and the 7-tile island.
</div>
<div class="hint">
Drag to orbit · Wheel to zoom · Right-drag to pan · Click a tile to probe
</div>
<footer class="bottom-bar panel">
<div class="legend">
<span class="legend-item"><i class="swatch"></i>Direct adjacency</span>
<span class="legend-item"><i class="swatch probe"></i>Access probe</span>
<span class="legend-item"><i class="swatch dim"></i>Unreachable</span>
<span class="legend-item"><i class="swatch gap"></i>No connection</span>
</div>
<div class="controls">
<button id="toggleLinks" class="active" type="button">Links on</button>
<button id="resetView" type="button">Reset view</button>
</div>
</footer>
</div>
<div id="loading">Building voxel comparison…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x090e1a);
scene.fog = new THREE.Fog(0x090e1a, 28, 55);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const target = new THREE.Vector3(0, 0.25, 0);
const orbit = {
theta: 0.59,
phi: 0.91,
zoom: 1
};
function updateCamera() {
const radius = 30;
camera.position.set(
target.x + radius * Math.sin(orbit.phi) * Math.sin(orbit.theta),
target.y + radius * Math.cos(orbit.phi),
target.z + radius * Math.sin(orbit.phi) * Math.cos(orbit.theta)
);
camera.lookAt(target);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(12, 22 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemi = new THREE.HemisphereLight(0xc9f5ff, 0x151827, 1.65);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.6);
keyLight.position.set(-8, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 42;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5d8cff, 1.0);
rimLight.position.set(12, 7, -12);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 45),
new THREE.MeshStandardMaterial({
color: 0x0b1120,
roughness: 0.94,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.26;
floor.receiveShadow = true;
scene.add(floor);
const SPACING = 1.08;
const TILE_SIZE = 0.94;
const TILE_HEIGHT = 0.9;
const ROOT_X = 4.8;
const tileGeometry = new THREE.BoxGeometry(
TILE_SIZE,
TILE_HEIGHT,
TILE_SIZE
);
const tileEdgeGeometry = new THREE.EdgesGeometry(tileGeometry);
const traceMaterial = new THREE.MeshBasicMaterial({
color: 0x62f3e2,
toneMapped: false
});
const nodeGeometry = new THREE.BoxGeometry(0.14, 0.04, 0.14);
const horizontalTraceGeometry = new THREE.BoxGeometry(SPACING, 0.035, 0.07);
const verticalTraceGeometry = new THREE.BoxGeometry(0.07, 0.035, SPACING);
const traceMeshes = [];
const nodeMeshes = [];
const tileMeshes = [];
const groups = {};
const selected = {};
const dimColor = new THREE.Color(0x293247);
const black = new THREE.Color(0x000000);
function addPlatform(x) {
const platform = new THREE.Mesh(
new THREE.BoxGeometry(9.2, 0.24, 5.4),
new THREE.MeshStandardMaterial({
color: 0x111a2b,
roughness: 0.82,
metalness: 0.08
})
);
platform.position.set(x, -0.12, 0);
platform.receiveShadow = true;
scene.add(platform);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(platform.geometry),
new THREE.LineBasicMaterial({
color: 0x35445d,
transparent: true,
opacity: 0.8
})
);
edge.position.copy(platform.position);
scene.add(edge);
const gridPoints = [];
for (let gx = -4; gx <= 4; gx++) {
gridPoints.push(
new THREE.Vector3(x + gx * SPACING, 0.012, -2.55),
new THREE.Vector3(x + gx * SPACING, 0.012, 2.55)
);
}
for (let gz = -2; gz <= 2; gz++) {
gridPoints.push(
new THREE.Vector3(x - 4.25, 0.012, gz * SPACING),
new THREE.Vector3(x + 4.25, 0.012, gz * SPACING)
);
}
const grid = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(gridPoints),
new THREE.LineBasicMaterial({
color: 0x25334a,
transparent: true,
opacity: 0.48
})
);
scene.add(grid);
}
addPlatform(-ROOT_X);
addPlatform(ROOT_X);
function buildGroup(name, cells, rootX) {
const root = new THREE.Group();
root.position.x = rootX;
scene.add(root);
let minC = Infinity;
let maxC = -Infinity;
let minR = Infinity;
let maxR = -Infinity;
for (const [c, r] of cells) {
minC = Math.min(minC, c);
maxC = Math.max(maxC, c);
minR = Math.min(minR, r);
maxR = Math.max(maxR, r);
}
const centerC = (minC + maxC) / 2;
const centerR = (minR + maxR) / 2;
const cellMap = new Map();
const records = [];
for (const [c, r] of cells) {
const record = {
id: records.length,
c,
r,
x: (c - centerC) * SPACING,
z: (r - centerR) * SPACING,
neighbors: [],
component: -1
};
record.key = `${c},${r}`;
cellMap.set(record.key, record);
records.push(record);
}
const directions = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1]
];
for (const record of records) {
for (const [dc, dr] of directions) {
const neighbor = cellMap.get(`${record.c + dc},${record.r + dr}`);
if (neighbor) record.neighbors.push(neighbor);
}
}
// Connected components are computed from the actual adjacency graph.
let componentIndex = 0;
for (const start of records) {
if (start.component !== -1) continue;
const queue = [start];
start.component = componentIndex;
while (queue.length) {
const current = queue.shift();
for (const neighbor of current.neighbors) {
if (neighbor.component === -1) {
neighbor.component = componentIndex;
queue.push(neighbor);
}
}
}
componentIndex++;
}
const componentSizes = Array(componentIndex).fill(0);
for (const record of records) componentSizes[record.component]++;
const group = {
name,
root,
records,
cellMap,
componentCount: componentIndex,
componentSizes
};
groups[name] = group;
for (const record of records) {
let baseHex;
if (name === "connected") {
baseHex = 0x287d88;
} else {
baseHex = record.component === 0 ? 0xc66b3f : 0x7651ad;
}
record.baseColor = new THREE.Color(baseHex);
const material = new THREE.MeshStandardMaterial({
color: record.baseColor,
emissive: record.baseColor,
emissiveIntensity: 0.27,
roughness: 0.73,
metalness: 0.06,
flatShading: true
});
const mesh = new THREE.Mesh(tileGeometry, material);
mesh.position.set(record.x, TILE_HEIGHT / 2, record.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.record = record;
root.add(mesh);
record.mesh = mesh;
record.material = material;
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x9ffff0,
transparent: true,
opacity: 0.72
});
const edges = new THREE.LineSegments(tileEdgeGeometry, edgeMaterial);
mesh.add(edges);
record.edgeMaterial = edgeMaterial;
tileMeshes.push(mesh);
const node = new THREE.Mesh(nodeGeometry, traceMaterial);
node.position.set(record.x, TILE_HEIGHT + 0.035, record.z);
root.add(node);
nodeMeshes.push(node);
}
// Each trace joins the centers of two orthogonally adjacent tiles.
for (const record of records) {
for (const neighbor of record.neighbors) {
if (record.id >= neighbor.id) continue;
const trace = new THREE.Mesh(
record.c === neighbor.c
? verticalTraceGeometry
: horizontalTraceGeometry,
traceMaterial
);
trace.position.set(
(record.x + neighbor.x) / 2,
TILE_HEIGHT + 0.017,
(record.z + neighbor.z) / 2
);
root.add(trace);
traceMeshes.push(trace);
}
}
const probe = createProbe();
root.add(probe);
group.probe = probe;
return group;
}
function createProbe() {
const probe = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: 0xffe46b,
toneMapped: false
});
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.24, 0.055),
material
);
stem.position.y = 0.12;
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 0.13, 0.19),
material
);
cube.position.y = 0.31;
probe.add(stem, cube);
probe.userData.cube = cube;
return probe;
}
const connectedCells = [];
for (let r = 0; r < 3; r++) {
for (let c = 0; c < 4; c++) connectedCells.push([c, r]);
}
// Two separated groups in the same coordinate system.
// There is intentionally no cell at c = 3.
const splitCells = [
[0, 0], [1, 0], [2, 0],
[0, 1], [1, 1],
[0, 2], [1, 2],
[4, 1], [5, 1], [6, 1],
[4, 2], [5, 2]
];
buildGroup("connected", connectedCells, -ROOT_X);
buildGroup("split", splitCells, ROOT_X);
// A red X in the missing connection zone.
const noLinkGroup = new THREE.Group();
noLinkGroup.position.set(0, TILE_HEIGHT + 0.065, 0);
const noLinkMaterial = new THREE.MeshBasicMaterial({
color: 0xff6278,
transparent: true,
opacity: 0.86,
toneMapped: false
});
for (const angle of [Math.PI / 4, -Math.PI / 4]) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.035, 0.075),
noLinkMaterial
);
bar.rotation.y = angle;
noLinkGroup.add(bar);
}
groups.split.root.add(noLinkGroup);
let hoverRecord = null;
function updateHighlights() {
for (const group of Object.values(groups)) {
const selectedRecord = selected[group.name];
for (const record of group.records) {
const reachable = record.component === selectedRecord.component;
const hovered = record === hoverRecord;
record.material.color.copy(
reachable ? record.baseColor : dimColor
);
record.material.emissive.copy(
reachable ? record.baseColor : black
);
record.material.emissiveIntensity = reachable
? hovered
? 0.42
: 0.27
: hovered
? 0.07
: 0;
record.edgeMaterial.color.set(
reachable ? 0x9ffff0 : 0x414b60
);
record.edgeMaterial.opacity = reachable ? 0.76 : 0.48;
}
}
}
function moveProbe(group, record) {
selected[group.name] = record;
group.probe.position.set(record.x, TILE_HEIGHT + 0.025, record.z);
const size = group.componentSizes[record.component];
const reachElement = document.querySelector(
group.name === "connected"
? "#connectedLabel .reach"
: "#splitLabel .reach"
);
reachElement.textContent = `${size} / ${group.records.length} reachable from probe`;
const status = document.querySelector("#probeStatus");
if (group.name === "connected") {
status.textContent =
`Connected probe: all ${size} tiles are face-reachable from the probe.`;
} else {
status.textContent =
`Split probe: ${size} of ${group.records.length} tiles are face-reachable; the other island is unreachable.`;
}
updateHighlights();
}
selected.connected = groups.connected.records[0];
const largestSplitComponent = groups.split.componentSizes.indexOf(
Math.max(...groups.split.componentSizes)
);
selected.split = groups.split.records.find(
record => record.component === largestSplitComponent
);
moveProbe(groups.connected, selected.connected);
moveProbe(groups.split, selected.split);
// Projected HTML labels stay attached to world positions.
const labelAnchors = [
{
element: document.querySelector("#connectedLabel"),
position: new THREE.Vector3(-ROOT_X, 1.95, -2.05)
},
{
element: document.querySelector("#splitLabel"),
position: new THREE.Vector3(ROOT_X, 1.95, -2.05)
},
{
element: document.querySelector("#islandATag"),
position: new THREE.Vector3(
ROOT_X - 1.62,
1.36,
0
)
},
{
element: document.querySelector("#islandBTag"),
position: new THREE.Vector3(
ROOT_X + 1.62,
1.36,
0.54
)
},
{
element: document.querySelector("#noLinkLabel"),
position: new THREE.Vector3(
ROOT_X,
1.25,
0
)
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const anchor of labelAnchors) {
const projected = anchor.position.clone().project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
anchor.element.style.opacity = visible ? "1" : "0";
anchor.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
anchor.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function setPointer(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 pickTile(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(tileMeshes, false);
return hits.length ? hits[0].object.userData.record : null;
}
let drag = null;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
drag = {
lastX: event.clientX,
lastY: event.clientY,
startX: event.clientX,
startY: event.clientY,
button: event.button,
shift: event.shiftKey,
moved: 0
};
});
canvas.addEventListener("pointermove", event => {
if (drag) {
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.moved += Math.abs(dx) + Math.abs(dy);
if (drag.button === 2 || drag.shift) {
const unitsPerPixel =
(camera.top - camera.bottom) / camera.zoom / window.innerHeight;
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
right.y = 0;
right.normalize();
const forward = camera.getWorldDirection(new THREE.Vector3());
forward.y = 0;
forward.normalize();
target.addScaledVector(right, -dx * unitsPerPixel);
target.addScaledVector(forward, dy * unitsPerPixel);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.38,
1.35
);
}
drag.lastX = event.clientX;
drag.lastY = event.clientY;
updateCamera();
return;
}
const record = pickTile(event);
if (record !== hoverRecord) {
hoverRecord = record;
canvas.style.cursor = record ? "pointer" : "grab";
updateHighlights();
}
});
canvas.addEventListener("pointerup", event => {
if (!drag) return;
const wasClick =
drag.moved < 6 && drag.button === 0 && !drag.shift;
drag = null;
if (wasClick) {
const record = pickTile(event);
if (record) {
const group = groups[record.mesh.parent.userData.groupName ||
(record.component !== undefined && record.baseColor.getHex() === 0x287d88
? groups.connected
: groups.split)];
// The robust lookup uses the record's owning root.
const owningGroup =
Object.values(groups).find(g =>
g.records.includes(record)
);
moveProbe(owningGroup, record);
}
}
});
canvas.addEventListener("pointerleave", () => {
if (!drag) {
hoverRecord = null;
canvas.style.cursor = "grab";
updateHighlights();
}
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.2
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#resetView").addEventListener("click", () => {
orbit.theta = 0.59;
orbit.phi = 0.91;
orbit.zoom = 1;
target.set(0, 0.25, 0);
updateCamera();
});
const toggleLinks = document.querySelector("#toggleLinks");
let linksVisible = true;
toggleLinks.addEventListener("click", () => {
linksVisible = !linksVisible;
for (const mesh of traceMeshes) mesh.visible = linksVisible;
for (const mesh of nodeMeshes) mesh.visible = linksVisible;
toggleLinks.textContent = linksVisible ? "Links on" : "Links off";
toggleLinks.classList.toggle("active", linksVisible);
});
canvas.addEventListener("dblclick", () => {
orbit.theta = 0.59;
orbit.phi = 0.91;
orbit.zoom = 1;
target.set(0, 0.25, 0);
updateCamera();
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const group of Object.values(groups)) {
group.probe.position.y =
TILE_HEIGHT + 0.025 + Math.sin(elapsed * 2.7) * 0.035;
group.probe.userData.cube.rotation.y = elapsed * 0.7;
}
noLinkMaterial.opacity = 0.68 + Math.sin(elapsed * 2.2) * 0.18;
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 260);
});
</script>
</body>
</html>
```