Prompt specification
Build or customize the Three.js 3D scene "Hub and Ring Transport Tokens" 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: Hub and Ring Transport Tokens
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/hub-and-ring-transport-tokens-x2113
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: hub and ring transport tokens. Build two small networks with equal node counts but different connections. Show routes and distinguish high degree from being a critical connectivity point.
Working Three.js Starter (hub-and-ring-transport-tokens-x2113):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Transport Graph — Connectivity Lab</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(11, 24, 41, 0.84);
--panel-border: rgba(136, 197, 230, 0.18);
--text: #eaf7ff;
--muted: #8ca8bc;
--cyan: #65e6ff;
--purple: #a987ff;
--amber: #ffb454;
--red: #ff5577;
--green: #9bffb3;
}
* { 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;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 22px;
left: 24px;
max-width: 470px;
text-shadow: 0 2px 18px #000;
}
.kicker {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
margin-bottom: 8px;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.04em;
}
header p {
color: var(--muted);
margin: 10px 0 0;
font-size: 12px;
line-height: 1.55;
max-width: 440px;
}
.topology-grid {
position: absolute;
top: 20px;
right: 22px;
display: flex;
gap: 10px;
pointer-events: auto;
}
.network-card {
width: 218px;
padding: 15px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background:
linear-gradient(145deg, rgba(25, 48, 70, 0.78), var(--panel));
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.network-card .eyebrow {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.network-card h2 {
margin: 6px 0 5px;
font-size: 17px;
letter-spacing: -0.025em;
}
.network-card p {
min-height: 34px;
margin: 0 0 11px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.stats {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.stat {
padding: 5px 7px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 7px;
background: rgba(0, 0, 0, 0.15);
color: #c9dce8;
font-size: 9px;
}
.stat b {
color: white;
font-weight: 750;
}
.legend {
position: absolute;
left: 24px;
bottom: 25px;
width: 260px;
padding: 14px 15px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.legend-title {
margin-bottom: 11px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 9px 0;
color: #d8e8f2;
font-size: 11px;
}
.swatch {
position: relative;
flex: 0 0 auto;
width: 15px;
height: 15px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px rgba(101, 230, 255, 0.45);
}
.swatch.high {
width: 20px;
height: 20px;
background: var(--amber);
box-shadow: 0 0 0 3px rgba(255, 180, 84, 0.15),
0 0 17px rgba(255, 180, 84, 0.5);
}
.swatch.critical {
background: var(--red);
box-shadow: 0 0 0 3px rgba(255, 85, 119, 0.17),
0 0 17px rgba(255, 85, 119, 0.55);
}
.swatch.critical::after {
content: "";
position: absolute;
left: 6px;
top: -4px;
width: 3px;
height: 3px;
background: var(--red);
transform: rotate(45deg);
box-shadow: 0 0 8px var(--red);
}
.swatch.route {
width: 22px;
height: 3px;
border-radius: 3px;
background: linear-gradient(90deg, var(--cyan), var(--purple));
box-shadow: 0 0 9px rgba(101, 230, 255, 0.5);
}
.legend-note {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.inspect {
position: absolute;
right: 22px;
bottom: 25px;
width: 292px;
padding: 16px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.inspect-top {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
}
.node-tag {
display: inline-grid;
place-items: center;
min-width: 34px;
height: 28px;
padding: 0 8px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 8px;
background: rgba(255, 255, 255, 0.06);
color: white;
font-weight: 850;
}
.inspect h3 {
margin: 10px 0 3px;
font-size: 17px;
}
.inspect-description {
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.inspect-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 13px;
}
.metric {
padding: 9px;
border-radius: 9px;
background: rgba(0, 0, 0, 0.18);
border: 1px solid rgba(255, 255, 255, 0.06);
}
.metric b {
display: block;
margin-bottom: 2px;
font-size: 17px;
}
.metric span {
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
position: absolute;
top: 154px;
left: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(134, 208, 236, 0.22);
border-radius: 9px;
padding: 9px 12px;
background: rgba(12, 29, 46, 0.82);
color: #dff5ff;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
backdrop-filter: blur(12px);
transition: 150ms ease;
}
button:hover {
border-color: rgba(101, 230, 255, 0.65);
color: white;
background: rgba(24, 55, 76, 0.92);
transform: translateY(-1px);
}
.hint {
position: absolute;
left: 50%;
bottom: 26px;
transform: translateX(-50%);
color: rgba(183, 211, 226, 0.62);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
text-shadow: 0 2px 8px black;
}
@media (max-width: 900px) {
header {
max-width: 330px;
}
header p {
display: none;
}
.topology-grid {
top: 108px;
left: 20px;
right: auto;
}
.network-card {
width: 190px;
padding: 11px;
}
.network-card p {
display: none;
}
.controls {
top: 15px;
left: auto;
right: 20px;
}
.legend {
left: 20px;
bottom: 20px;
width: 220px;
}
.inspect {
right: 20px;
bottom: 20px;
width: 250px;
}
.hint {
display: none;
}
}
@media (max-width: 620px) {
.topology-grid {
right: 16px;
left: 16px;
gap: 7px;
}
.network-card {
width: calc(50% - 4px);
}
.network-card h2 {
font-size: 14px;
}
.legend {
display: none;
}
.inspect {
left: 16px;
right: 16px;
bottom: 16px;
width: auto;
}
.controls {
top: 88px;
right: 16px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="ui">
<header>
<div class="kicker">Connectivity laboratory / 08 nodes each</div>
<h1>Transport topology study</h1>
<p>
Compare a high-degree hub with a modest-degree articulation point.
Moving tokens reveal the routes; click any node to test its local and global role.
</p>
</header>
<section class="topology-grid">
<article class="network-card">
<div class="eyebrow">Network A</div>
<h2>Hub + bypass</h2>
<p>
One node connects to every outer node. The outer ring bypasses the hub,
so the hub is powerful but not essential.
</p>
<div class="stats" id="stats-a"></div>
</article>
<article class="network-card">
<div class="eyebrow">Network B</div>
<h2>Ring + branch</h2>
<p>
The ring is resilient, but a single branch creates one critical
attachment point with only three connections.
</p>
<div class="stats" id="stats-b"></div>
</article>
</section>
<div class="controls">
<button id="pause">Pause tokens</button>
<button id="reset">Reset view</button>
</div>
<aside class="legend">
<div class="legend-title">Visual key</div>
<div class="legend-row">
<span class="swatch high"></span>
<span>Large amber node · high degree (≥ 4)</span>
</div>
<div class="legend-row">
<span class="swatch critical"></span>
<span>Red halo + diamond · critical point</span>
</div>
<div class="legend-row">
<span class="swatch"></span>
<span>Cyan node · regular transport stop</span>
</div>
<div class="legend-row">
<span class="swatch route"></span>
<span>Colored tube · active transport route</span>
</div>
<div class="legend-note">
Degree is a local count of incident routes. Criticality is global:
remove the node and check whether the remaining graph disconnects.
</div>
</aside>
<aside class="inspect" id="inspect"></aside>
<div class="hint">Drag to orbit · wheel to zoom · click a node to inspect</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene
// ------------------------------------------------------------
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 19, 38);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.25;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb8eaff, 0x101727, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xc9f2ff, 2.7);
keyLight.position.set(-5, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x30cfff, 34, 16, 2);
cyanLight.position.set(-7, 5, 3);
scene.add(cyanLight);
const violetLight = new THREE.PointLight(0x9872ff, 26, 15, 2);
violetLight.position.set(7, 4, -2);
scene.add(violetLight);
const colors = {
cyan: 0x65e6ff,
blue: 0x2d83b0,
purple: 0xa987ff,
amber: 0xffb454,
red: 0xff5577,
green: 0x9bffb3,
white: 0xeaf7ff
};
const highDegreeThreshold = 4;
// Floor and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 28),
new THREE.MeshStandardMaterial({
color: 0x091625,
roughness: 0.88,
metalness: 0.18
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.38;
floor.receiveShadow = true;
scene.add(floor);
const gridPositions = [];
for (let x = -20; x <= 20; x += 1.25) {
gridPositions.push(x, -0.365, -12, x, -0.365, 12);
}
for (let z = -12; z <= 12; z += 1.25) {
gridPositions.push(-20, -0.365, z, 20, -0.365, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x4f829d,
transparent: true,
opacity: 0.13
})
);
scene.add(grid);
function createPlatform(x, accent) {
const group = new THREE.Group();
group.position.x = x;
const platform = new THREE.Mesh(
new THREE.BoxGeometry(8.15, 0.16, 6.65),
new THREE.MeshStandardMaterial({
color: 0x102236,
emissive: 0x071522,
emissiveIntensity: 0.55,
roughness: 0.7,
metalness: 0.22
})
);
platform.position.y = -0.28;
platform.receiveShadow = true;
group.add(platform);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(platform.geometry),
new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.32
})
);
outline.position.copy(platform.position);
group.add(outline);
const underglow = new THREE.Mesh(
new THREE.PlaneGeometry(8.5, 6.9),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.025,
depthWrite: false
})
);
underglow.rotation.x = -Math.PI / 2;
underglow.position.y = -0.365;
group.add(underglow);
scene.add(group);
return group;
}
createPlatform(-5, colors.cyan);
createPlatform(5, colors.purple);
// ------------------------------------------------------------
// Graph definitions
// ------------------------------------------------------------
const aOuter = Array.from({ length: 7 }, (_, i) => {
const angle = (i / 7) * Math.PI * 2 - Math.PI / 2;
return [Math.cos(angle) * 2.72, Math.sin(angle) * 2.72];
});
const bRing = Array.from({ length: 7 }, (_, i) => {
const angle = (i / 7) * Math.PI * 2;
return [Math.cos(angle) * 2.58, Math.sin(angle) * 2.58];
});
const networks = [
{
key: "A",
name: "Hub + bypass",
groupX: -5,
nodes: [
{ id: "H", p: [0, 0] },
...aOuter.map((p, i) => ({ id: `A${i + 1}`, p }))
],
edges: [
...Array.from({ length: 7 }, (_, i) => ({
a: 0,
b: i + 1,
kind: "spoke"
})),
...Array.from({ length: 7 }, (_, i) => ({
a: i + 1,
b: ((i + 1) % 7) + 1,
kind: "ring"
}))
]
},
{
key: "B",
name: "Ring + branch",
groupX: 5,
nodes: [
...bRing.map((p, i) => ({ id: `B${i + 1}`, p })),
{ id: "B8", p: [4.08, 0] }
],
edges: [
...Array.from({ length: 7 }, (_, i) => ({
a: i,
b: (i + 1) % 7,
kind: "ring"
})),
{ a: 0, b: 7, kind: "spur" }
]
}
];
// Graph utility: articulation means "removing this node disconnects
// at least one remaining node from the rest of the graph."
function findCriticalNodes(nodes, edges) {
const critical = new Set();
function connectedWithout(removed) {
const remaining = nodes
.map((_, index) => index)
.filter(index => index !== removed);
if (remaining.length <= 1) return true;
const adjacency = nodes.map(() => []);
for (const edge of edges) {
if (edge.a === removed || edge.b === removed) continue;
adjacency[edge.a].push(edge.b);
adjacency[edge.b].push(edge.a);
}
const visited = new Set([remaining[0]]);
const queue = [remaining[0]];
while (queue.length) {
const current = queue.shift();
for (const neighbor of adjacency[current]) {
if (!visited.has(neighbor)) {
visited.add(neighbor);
queue.push(neighbor);
}
}
}
return visited.size === remaining.length;
}
nodes.forEach((_, index) => {
if (!connectedWithout(index)) critical.add(index);
});
return critical;
}
function degreeOf(nodeIndex, edges) {
return edges.filter(edge => edge.a === nodeIndex || edge.b === nodeIndex).length;
}
// ------------------------------------------------------------
// Node and route rendering
// ------------------------------------------------------------
function makeLabel(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 160;
canvas.height = 72;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(5, 15, 26, 0.86)";
ctx.fillRect(22, 8, 116, 50);
ctx.strokeStyle = color;
ctx.lineWidth = 3;
ctx.strokeRect(22, 8, 116, 50);
ctx.fillStyle = "#f2fbff";
ctx.font = "bold 28px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 80, 34);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.76, 0.342, 1);
sprite.center.set(0.5, 0);
sprite.renderOrder = 5;
return sprite;
}
function createNode(network, index, definition, critical) {
const degree = degreeOf(index, network.edges);
const highDegree = degree >= highDegreeThreshold;
const color = critical
? colors.red
: highDegree
? colors.amber
: colors.cyan;
const radius = critical ? 0.285 : highDegree ? 0.34 : 0.235;
const node = {
id: definition.id,
network,
index,
degree,
highDegree,
critical,
position: new THREE.Vector3(definition.p[0], 0.48, definition.p[1]),
mesh: null,
halo: null,
beacon: null,
selection: null
};
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: critical ? 0.9 : highDegree ? 0.62 : 0.34,
roughness: 0.28,
metalness: 0.25
});
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 20, 14),
material
);
mesh.position.copy(node.position);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.node = node;
network.group.add(mesh);
node.mesh = mesh;
const haloMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: highDegree || critical ? 0.7 : 0.15,
depthWrite: false
});
const halo = new THREE.Mesh(
new THREE.TorusGeometry(radius * 1.75, 0.024, 8, 44),
haloMaterial
);
halo.rotation.x = Math.PI / 2;
halo.position.set(definition.p[0], 0.43, definition.p[1]);
network.group.add(halo);
node.halo = halo;
const selection = new THREE.Mesh(
new THREE.TorusGeometry(radius * 2.18, 0.022, 8, 48),
new THREE.MeshBasicMaterial({
color: colors.green,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
selection.rotation.x = Math.PI / 2;
selection.position.set(definition.p[0], 0.47, definition.p[1]);
selection.visible = false;
network.group.add(selection);
node.selection = selection;
if (critical) {
const beacon = new THREE.Mesh(
new THREE.OctahedronGeometry(0.14),
new THREE.MeshStandardMaterial({
color: colors.red,
emissive: colors.red,
emissiveIntensity: 1.2,
roughness: 0.25
})
);
beacon.position.set(definition.p[0], 1.05, definition.p[1]);
network.group.add(beacon);
node.beacon = beacon;
}
const label = makeLabel(definition.id, `#${new THREE.Color(color).getHexString()}`);
label.position.set(definition.p[0], 0.91, definition.p[1]);
network.group.add(label);
network.nodes[index].visual = node;
return node;
}
function createRoute(network, edge, edgeIndex) {
const start = network.nodes[edge.a].visual.position;
const end = network.nodes[edge.b].visual.position;
const color = edge.kind === "spoke"
? colors.cyan
: edge.kind === "ring"
? colors.purple
: colors.amber;
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const route = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.022, length, 8),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
route.position.copy(midpoint);
route.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
network.group.add(route);
// A second, dimmer route creates a subtle tube-like glow.
const glow = new THREE.Mesh(
new THREE.CylinderGeometry(0.057, 0.057, length, 8),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.045,
depthWrite: false
})
);
glow.position.copy(midpoint);
glow.quaternion.copy(route.quaternion);
network.group.add(glow);
const token = new THREE.Mesh(
new THREE.SphereGeometry(edge.kind === "spur" ? 0.13 : 0.105, 12, 8),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.3,
roughness: 0.2,
metalness: 0.1
})
);
network.group.add(token);
network.tokens.push({
mesh: token,
start,
end,
phase: (edgeIndex * 0.173 + network.key.charCodeAt(0) * 0.11) % 1,
speed: edge.kind === "spur" ? 0.21 : edge.kind === "ring" ? 0.12 : 0.17
});
}
const allNodes = [];
for (const network of networks) {
network.group = new THREE.Group();
network.group.position.x = network.groupX;
scene.add(network.group);
network.tokens = [];
network.critical = findCriticalNodes(network.nodes, network.edges);
network.nodes.forEach((definition, index) => {
const node = createNode(network, index, definition, network.critical.has(index));
allNodes.push(node);
});
network.edges.forEach((edge, index) => createRoute(network, edge, index));
const highCount = network.nodes.filter((_, i) =>
degreeOf(i, network.edges) >= highDegreeThreshold
).length;
document.getElementById(`stats-${network.key.toLowerCase()}`).innerHTML = `
<span class="stat"><b>${network.nodes.length}</b> nodes</span>
<span class="stat"><b>${network.edges.length}</b> routes</span>
<span class="stat"><b>${highCount}</b> high-degree</span>
<span class="stat"><b>${network.critical.size}</b> critical</span>
`;
}
// ------------------------------------------------------------
// Background particles
// ------------------------------------------------------------
const particleCount = 240;
const particlePositions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount; i++) {
particlePositions[i * 3] = (Math.random() - 0.5) * 32;
particlePositions[i * 3 + 1] = Math.random() * 9 - 1;
particlePositions[i * 3 + 2] = (Math.random() - 0.5) * 22;
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x7eb8d2,
size: 0.035,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(particles);
// ------------------------------------------------------------
// Selection and inspection
// ------------------------------------------------------------
let selectedNode = allNodes.find(node => node.id === "H");
function updateInspect(node) {
const role = node.critical
? "Critical connectivity point"
: node.highDegree
? "High-degree transport hub"
: "Regular transport stop";
const explanation = node.critical
? "Removing this node isolates at least one part of the graph."
: node.highDegree
? "This node has many direct routes, but the network remains connected without it."
: "This node has a local role only and is not required to keep the graph connected.";
document.getElementById("inspect").innerHTML = `
<div class="inspect-top">
<span class="node-tag">${node.id}</span>
<span>Network ${node.network.key} · ${node.network.name}</span>
</div>
<h3>${role}</h3>
<div class="inspect-description">${explanation}</div>
<div class="inspect-grid">
<div class="metric">
<b style="color:${node.critical ? "#ff5577" : node.highDegree ? "#ffb454" : "#65e6ff"}">
${node.degree}
</b>
<span>degree</span>
</div>
<div class="metric">
<b style="color:${node.critical ? "#ff5577" : "#9bffb3"}">
${node.critical ? "YES" : "NO"}
</b>
<span>critical</span>
</div>
<div class="metric">
<b style="color:#a987ff">${node.network.key}</b>
<span>network</span>
</div>
</div>
`;
}
function selectNode(node) {
selectedNode = node;
for (const item of allNodes) {
item.selection.visible = item === node;
}
updateInspect(node);
}
updateInspect(selectedNode);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 0.25, 0);
const spherical = new THREE.Spherical(19.2, 0.94, 0);
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.34, 1.46);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 12.5, 29);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
updateCamera();
let dragging = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
spherical.theta -= dx * 0.006;
spherical.phi += dy * 0.005;
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (!pointerMoved) {
const rect = renderer.domElement.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 hits = raycaster.intersectObjects(
allNodes.map(node => node.mesh),
false
);
if (hits.length) {
selectNode(hits[0].object.userData.node);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
spherical.radius += event.deltaY * 0.012;
updateCamera();
}, { passive: false });
document.getElementById("reset").addEventListener("click", () => {
spherical.radius = 19.2;
spherical.phi = 0.94;
spherical.theta = 0;
updateCamera();
});
let paused = false;
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume tokens" : "Pause tokens";
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta;
for (const network of networks) {
for (const token of network.tokens) {
const progress = (elapsed * token.speed + token.phase) % 1;
token.mesh.position.lerpVectors(token.start, token.end, progress);
token.mesh.position.y += 0.035 + Math.sin(elapsed * 4 + token.phase * 9) * 0.025;
const pulse = 1 + Math.sin(elapsed * 5 + token.phase * 12) * 0.1;
token.mesh.scale.setScalar(pulse);
}
}
for (const node of allNodes) {
if (node.critical && node.halo) {
node.halo.material.opacity = 0.5 + Math.sin(elapsed * 3.5) * 0.22;
node.halo.scale.setScalar(1 + Math.sin(elapsed * 3.5) * 0.08);
if (node.beacon) {
node.beacon.rotation.y = elapsed * 1.8;
node.beacon.rotation.x = elapsed * 0.8;
node.beacon.position.y = 1.05 + Math.sin(elapsed * 3) * 0.07;
}
}
if (node.highDegree && node.halo) {
node.halo.material.opacity = 0.53 + Math.sin(elapsed * 2.2) * 0.12;
node.halo.scale.setScalar(1 + Math.sin(elapsed * 2.2) * 0.04);
}
if (node.selection.visible) {
node.selection.rotation.z = elapsed * 0.7;
node.selection.material.opacity = 0.68 + Math.sin(elapsed * 3) * 0.2;
}
}
particles.rotation.y += delta * 0.009;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// ------------------------------------------------------------
// Resize
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```