Prompt specification
Build or customize the Three.js 3D scene "Route a message after a line failure" 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: Route a message after a line failure
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/route-a-message-after-a-line-failure-x2544
Scene Description Prompt:
Use Three.js from cdnjs in one HTML file to reroute a message through a fictional low-poly telegraph network, preserving order and simplified delays.
Working Three.js Starter (route-a-message-after-a-line-failure-x2544):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Northern Relay — Telegraph Network</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(10, 20, 28, 0.86);
--line: rgba(143, 205, 220, 0.18);
--text: #e8f2f2;
--muted: #829ba3;
--cyan: #7de8f4;
--gold: #ffc85c;
--green: #7ee0a7;
--red: #ff7d79;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #132c35 0%, #08141c 45%, #04090e 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(90deg, rgba(2, 7, 11, 0.48), transparent 32%),
radial-gradient(circle at center, transparent 50%, rgba(1, 5, 8, 0.48) 100%);
z-index: 1;
}
.topbar {
position: fixed;
z-index: 3;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
max-width: 470px;
}
.eyebrow,
.micro-label {
color: var(--cyan);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand h1 {
margin: 7px 0 5px;
font-size: clamp(26px, 3vw, 43px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 760;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.025em;
}
.telemetry {
display: flex;
gap: 8px;
pointer-events: auto;
}
.telemetry-card {
min-width: 112px;
padding: 11px 13px;
border: 1px solid var(--line);
background: rgba(8, 17, 23, 0.7);
backdrop-filter: blur(14px);
border-radius: 8px;
}
.telemetry-card strong {
display: block;
margin-top: 5px;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 15px;
color: var(--text);
}
.panel {
position: fixed;
z-index: 4;
top: 128px;
right: 28px;
width: min(360px, calc(100vw - 36px));
max-height: calc(100vh - 170px);
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 12px;
background:
linear-gradient(145deg, rgba(16, 31, 39, 0.93), rgba(7, 15, 21, 0.9));
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #35515a transparent;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 14px;
border-bottom: 1px solid var(--line);
}
.panel h2 {
margin: 5px 0 0;
font-size: 19px;
letter-spacing: -0.025em;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--green);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.8);
}
}
.field {
display: grid;
gap: 7px;
margin-top: 15px;
}
.field label {
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
input,
select {
width: 100%;
height: 39px;
padding: 0 11px;
color: var(--text);
border: 1px solid rgba(125, 232, 244, 0.18);
border-radius: 6px;
outline: none;
background: rgba(2, 9, 13, 0.55);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
}
input:focus,
select:focus {
border-color: rgba(125, 232, 244, 0.62);
box-shadow: 0 0 0 3px rgba(125, 232, 244, 0.07);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 14px;
}
button {
min-height: 40px;
padding: 0 12px;
border: 1px solid transparent;
border-radius: 6px;
cursor: pointer;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: not-allowed;
opacity: 0.38;
}
#sendButton {
color: #071015;
background: var(--cyan);
}
#rerouteButton {
color: var(--gold);
border-color: rgba(255, 200, 92, 0.35);
background: rgba(255, 200, 92, 0.08);
}
.waypoint {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
padding: 10px 11px;
border: 1px dashed rgba(255, 200, 92, 0.25);
border-radius: 6px;
background: rgba(255, 200, 92, 0.035);
}
.waypoint strong {
display: block;
margin-top: 4px;
color: var(--gold);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
}
.waypoint small {
display: block;
color: var(--muted);
font-size: 10px;
}
.section {
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.route-line {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
min-height: 30px;
}
.route-chip {
padding: 5px 7px;
border: 1px solid rgba(125, 232, 244, 0.18);
border-radius: 4px;
color: #c8e6eb;
background: rgba(125, 232, 244, 0.055);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
}
.route-arrow {
color: #53747e;
font-size: 11px;
}
.queue {
display: grid;
gap: 7px;
}
.queue-row {
display: grid;
grid-template-columns: 34px minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
padding: 8px 9px;
border-radius: 5px;
background: rgba(0, 0, 0, 0.18);
}
.queue-seq {
color: var(--cyan);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10px;
font-weight: 800;
}
.queue-body {
overflow: hidden;
color: #c4d4d8;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.queue-state {
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
}
.queue-state.active {
color: var(--gold);
}
.queue-state.delivered {
color: var(--green);
}
.protocol {
margin: 16px 0 0;
padding: 10px 11px;
border-left: 2px solid var(--green);
color: #94aeb3;
background: rgba(126, 224, 167, 0.035);
font-size: 10px;
line-height: 1.55;
}
.protocol strong {
color: var(--green);
}
.footer {
position: fixed;
z-index: 3;
left: 28px;
bottom: 24px;
display: flex;
align-items: center;
gap: 18px;
color: #78939b;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
letter-spacing: 0.08em;
pointer-events: none;
}
.legend {
display: flex;
align-items: center;
gap: 13px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px rgba(125, 232, 244, 0.65);
}
.legend-dot.gold {
background: var(--gold);
box-shadow: 0 0 8px rgba(255, 200, 92, 0.65);
}
.toast {
position: fixed;
z-index: 8;
left: 50%;
bottom: 68px;
max-width: min(520px, calc(100vw - 36px));
padding: 11px 15px;
border: 1px solid rgba(125, 232, 244, 0.25);
border-radius: 7px;
color: #d7e9ec;
background: rgba(7, 16, 22, 0.93);
box-shadow: 0 12px 45px rgba(0, 0, 0, 0.4);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10px;
line-height: 1.5;
text-align: center;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity 200ms ease, transform 200ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 800px) {
.topbar {
top: 15px;
left: 16px;
right: 16px;
}
.brand p {
display: none;
}
.brand h1 {
font-size: 27px;
}
.telemetry-card {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 47vh;
padding: 14px;
}
.footer {
display: none;
}
.toast {
bottom: calc(47vh + 24px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly telegraph network"></canvas>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Northern Relay / Fictional Field Network</div>
<h1>ORDER IS THE MESSAGE</h1>
<p>Route a transmission through the ridge. The queue never overtakes.</p>
</div>
<div class="telemetry">
<div class="telemetry-card">
<div class="micro-label">Relay State</div>
<strong id="topStatus">BOOTING</strong>
</div>
<div class="telemetry-card">
<div class="micro-label">Queued</div>
<strong id="queueCount">00</strong>
</div>
<div class="telemetry-card">
<div class="micro-label">Est. Latency</div>
<strong id="latency">0.0 s</strong>
</div>
</div>
</header>
<aside class="panel">
<div class="panel-header">
<div>
<div class="eyebrow">Transmission Desk</div>
<h2>Route a signal</h2>
</div>
<div class="status-pill" id="statusPill">
<span class="status-dot"></span>
<span id="statusText">Online</span>
</div>
</div>
<div class="field">
<label for="destination">Destination relay</label>
<select id="destination"></select>
</div>
<div class="field">
<label for="messageText">Message payload</label>
<input
id="messageText"
maxlength="42"
value="RIDGELINE / HOLD FOR RELEASE"
autocomplete="off"
/>
</div>
<div class="button-row">
<button id="sendButton">Send message</button>
<button id="rerouteButton" disabled>Reroute via tower</button>
</div>
<div class="waypoint">
<div>
<div class="micro-label">Recovery waypoint</div>
<strong id="waypointName">CINDER / C-08</strong>
<small>Click any tower to select it</small>
</div>
<span class="status-dot" style="color: var(--gold)"></span>
</div>
<section class="section">
<div class="section-title">
<span class="micro-label">Active Circuit</span>
<span class="micro-label" id="routeHint">Awaiting traffic</span>
</div>
<div id="route" class="route-line"></div>
</section>
<section class="section">
<div class="section-title">
<span class="micro-label">FIFO Transmissions</span>
<span class="micro-label" id="deliveredCount">0 Delivered</span>
</div>
<div id="queue" class="queue"></div>
</section>
<p class="protocol">
<strong>Protocol:</strong> one packet advances at a time.
Each hop takes 700 ms and each relay takes 350 ms.
A reroute takes effect at the next relay, so sequence order remains intact.
</p>
</aside>
<footer class="footer">
<div class="legend">
<span class="legend-item"><span class="legend-dot"></span> Network</span>
<span class="legend-item"><span class="legend-dot gold"></span> Active route</span>
</div>
<span>DRAG TO ORBIT · SCROLL TO ZOOM · CLICK TOWER TO REROUTE</span>
</footer>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and constants
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const destinationSelect = document.querySelector("#destination");
const messageInput = document.querySelector("#messageText");
const sendButton = document.querySelector("#sendButton");
const rerouteButton = document.querySelector("#rerouteButton");
const routeElement = document.querySelector("#route");
const queueElement = document.querySelector("#queue");
const waypointName = document.querySelector("#waypointName");
const topStatus = document.querySelector("#topStatus");
const queueCount = document.querySelector("#queueCount");
const latency = document.querySelector("#latency");
const routeHint = document.querySelector("#routeHint");
const deliveredCount = document.querySelector("#deliveredCount");
const statusPill = document.querySelector("#statusPill");
const statusText = document.querySelector("#statusText");
const toastElement = document.querySelector("#toast");
const HOP_DURATION = 0.7;
const RELAY_DURATION = 0.35;
const SOURCE = "moss";
const PACKET_COLOR = 0xffc85c;
// -------------------------------------------------------------------------
// Renderer, scene, camera, lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: 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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071018, 0.027);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0x9adce8, 0x152026, 1.45);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xd5f6ff, 2.1);
keyLight.position.set(-7, 15, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -17;
keyLight.shadow.camera.right = 17;
keyLight.shadow.camera.top = 17;
keyLight.shadow.camera.bottom = -17;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x50cddd, 0.75);
rimLight.position.set(11, 7, -12);
scene.add(rimLight);
const world = new THREE.Group();
scene.add(world);
// -------------------------------------------------------------------------
// Fictional network topology
// -------------------------------------------------------------------------
const rawNodes = {
moss: { name: "MOSS", code: "M-01", position: [-8.0, 0, 2.0] },
brine: { name: "BRINE", code: "B-02", position: [-5.0, 0, -4.2] },
ember: { name: "EMBER", code: "E-03", position: [ 0.0, 0, -6.2] },
quill: { name: "QUILL", code: "Q-04", position: [ 5.1, 0, -5.0] },
halo: { name: "HALO", code: "H-05", position: [ 8.0, 0, 0.8] },
dune: { name: "DUNE", code: "D-06", position: [ 3.2, 0, 6.2] },
pike: { name: "PIKE", code: "P-07", position: [-4.0, 0, 7.1] },
cinder:{ name: "CINDER", code: "C-08", position: [ 0.4, 0, 1.0] }
};
const nodes = {};
for (const [id, data] of Object.entries(rawNodes)) {
nodes[id] = {
...data,
position: new THREE.Vector3(...data.position),
neighbors: []
};
}
const rawLinks = [
["moss", "brine"],
["moss", "pike"],
["moss", "cinder"],
["brine", "ember"],
["brine", "cinder"],
["ember", "quill"],
["ember", "cinder"],
["ember", "dune"],
["quill", "halo"],
["quill", "cinder"],
["halo", "dune"],
["halo", "cinder"],
["dune", "pike"],
["dune", "cinder"],
["pike", "cinder"]
];
for (const [a, b] of rawLinks) {
nodes[a].neighbors.push(b);
nodes[b].neighbors.push(a);
}
// -------------------------------------------------------------------------
// Procedural low-poly island and atmospheric details
// -------------------------------------------------------------------------
let randomSeed = 7183;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const terrain = new THREE.Mesh(
new THREE.CylinderGeometry(14, 13.2, 1.2, 9, 1, false),
new THREE.MeshStandardMaterial({
color: 0x162d31,
roughness: 0.95,
metalness: 0.02,
flatShading: true
})
);
terrain.position.y = -0.62;
terrain.receiveShadow = true;
world.add(terrain);
const terrainTop = new THREE.Mesh(
new THREE.CircleGeometry(12.8, 9),
new THREE.MeshStandardMaterial({
color: 0x203b3b,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
terrainTop.rotation.x = -Math.PI / 2;
terrainTop.position.y = 0.005;
terrainTop.receiveShadow = true;
world.add(terrainTop);
const ridgeMaterial = new THREE.MeshStandardMaterial({
color: 0x193034,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 15; i++) {
const angle = (i / 15) * Math.PI * 2 + random() * 0.2;
const radius = 11.1 + random() * 1.4;
const height = 0.7 + random() * 1.6;
const width = 0.45 + random() * 0.75;
const ridge = new THREE.Mesh(
new THREE.ConeGeometry(width, height, 5),
ridgeMaterial
);
ridge.position.set(
Math.cos(angle) * radius,
height * 0.5 - 0.03,
Math.sin(angle) * radius
);
ridge.rotation.y = random() * Math.PI;
ridge.scale.z = 0.7 + random() * 0.7;
ridge.castShadow = true;
ridge.receiveShadow = true;
world.add(ridge);
}
const shardMaterial = new THREE.MeshStandardMaterial({
color: 0x31565b,
roughness: 0.85,
flatShading: true
});
for (let i = 0; i < 18; i++) {
const shard = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.08 + random() * 0.16),
shardMaterial
);
const angle = random() * Math.PI * 2;
const radius = 9.2 + random() * 3.2;
shard.position.set(
Math.cos(angle) * radius,
0.15 + random() * 0.28,
Math.sin(angle) * radius
);
shard.rotation.set(random() * 3, random() * 3, random() * 3);
world.add(shard);
}
const starPositions = [];
for (let i = 0; i < 260; i++) {
const radius = 24 + random() * 40;
const theta = random() * Math.PI * 2;
const phi = Math.acos(2 * random() - 1);
starPositions.push(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0x9bdce4,
size: 0.07,
transparent: true,
opacity: 0.52,
sizeAttenuation: true
})
);
scene.add(stars);
// -------------------------------------------------------------------------
// Labels and glow textures
// -------------------------------------------------------------------------
function makeGlowTexture() {
const glowCanvas = document.createElement("canvas");
glowCanvas.width = 128;
glowCanvas.height = 128;
const context = glowCanvas.getContext("2d");
const gradient = context.createRadialGradient(
64, 64, 0,
64, 64, 64
);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.12, "rgba(255,255,255,0.72)");
gradient.addColorStop(0.4, "rgba(255,255,255,0.16)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 128, 128);
const texture = new THREE.CanvasTexture(glowCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const glowTexture = makeGlowTexture();
function makeLabelSprite(text, accent = "#7de8f4") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 64;
const context = labelCanvas.getContext("2d");
context.fillStyle = "rgba(5, 14, 19, 0.84)";
context.fillRect(0, 0, 256, 64);
context.fillStyle = accent;
context.fillRect(0, 0, 4, 64);
context.font = "700 24px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#e8f6f7";
context.fillText(text, 132, 33);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.5, 0.625, 1);
sprite.renderOrder = 10;
return sprite;
}
// -------------------------------------------------------------------------
// Relay towers
// -------------------------------------------------------------------------
const nodeVisuals = {};
const nodeHitMeshes = [];
function createRelayTower(id, data) {
const group = new THREE.Group();
group.position.copy(data.position);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x3e5960,
roughness: 0.8,
metalness: 0.12,
flatShading: true
});
const towerMaterial = new THREE.MeshStandardMaterial({
color: 0x76939a,
roughness: 0.55,
metalness: 0.3,
flatShading: true
});
const capMaterial = new THREE.MeshStandardMaterial({
color: 0x263b42,
roughness: 0.68,
metalness: 0.38,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 0.88, 0.22, 6),
baseMaterial
);
base.position.y = 0.11;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const tower = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.37, 1.25, 5),
towerMaterial
);
tower.position.y = 0.81;
tower.castShadow = true;
group.add(tower);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.33, 0.42, 5),
capMaterial
);
cap.position.y = 1.62;
cap.castShadow = true;
group.add(cap);
const antenna = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.78, 5),
towerMaterial
);
antenna.position.y = 2.13;
group.add(antenna);
const orbMaterial = new THREE.MeshStandardMaterial({
color: 0xa9f7ff,
emissive: 0x37d5e9,
emissiveIntensity: 1.45,
roughness: 0.2,
metalness: 0.15,
flatShading: true
});
const orb = new THREE.Mesh(
new THREE.OctahedronGeometry(0.19, 0),
orbMaterial
);
orb.position.y = 1.92;
group.add(orb);
const glow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: glowTexture,
color: 0x5be5f2,
transparent: true,
opacity: 0.32,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
glow.position.y = 1.92;
glow.scale.set(1.45, 1.45, 1);
group.add(glow);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x5cd8e8,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.76, 0.035, 4, 24),
ringMaterial
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.04;
group.add(ring);
const label = makeLabelSprite(`${data.name} / ${data.code}`);
label.position.y = 2.82;
group.add(label);
base.userData.nodeId = id;
tower.userData.nodeId = id;
cap.userData.nodeId = id;
orb.userData.nodeId = id;
nodeHitMeshes.push(base, tower, cap, orb);
world.add(group);
nodeVisuals[id] = {
group,
orb,
orbMaterial,
glow,
ring,
ringMaterial,
label
};
}
for (const [id, data] of Object.entries(nodes)) {
createRelayTower(id, data);
}
// -------------------------------------------------------------------------
// Telegraph links
// -------------------------------------------------------------------------
const linkVisuals = [];
const yAxis = new THREE.Vector3(0, 1, 0);
function linkPoint(id, y = 0.42) {
const point = nodes[id].position.clone();
point.y = y;
return point;
}
function createLink(a, b, index) {
const start = linkPoint(a);
const end = linkPoint(b);
const direction = end.clone().sub(start);
const length = direction.length();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const material = new THREE.MeshBasicMaterial({
color: 0x3c7684,
transparent: true,
opacity: 0.52
});
const line = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, length, 5),
material
);
line.position.copy(midpoint);
line.quaternion.setFromUnitVectors(yAxis, direction.normalize());
world.add(line);
const halo = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.1, length, 5),
new THREE.MeshBasicMaterial({
color: 0x46cfe0,
transparent: true,
opacity: 0.055,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
halo.position.copy(midpoint);
halo.quaternion.copy(line.quaternion);
world.add(halo);
const pulse = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 6, 4),
new THREE.MeshBasicMaterial({
color: 0x7de8f4,
transparent: true,
opacity: 0.64
})
);
world.add(pulse);
linkVisuals.push({
a,
b,
start,
end,
pulse,
phase: index * 0.137,
speed: 0.055 + (index % 5) * 0.006
});
}
rawLinks.forEach(([a, b], index) => createLink(a, b, index));
const routeHighlightGroup = new THREE.Group();
world.add(routeHighlightGroup);
function clearRouteHighlight() {
while (routeHighlightGroup.children.length) {
const child = routeHighlightGroup.children[0];
routeHighlightGroup.remove(child);
if (child.geometry) child.geometry.dispose();
if (child.material) child.material.dispose();
}
}
function highlightRoute(route, isActive = true) {
clearRouteHighlight();
if (!route || route.length < 2) return;
const color = isActive ? PACKET_COLOR : 0x59d6e5;
for (let i = 0; i < route.length - 1; i++) {
const start = linkPoint(route[i], 0.46);
const end = linkPoint(route[i + 1], 0.46);
const direction = end.clone().sub(start);
const length = direction.length();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const segment = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.07, length, 6),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: isActive ? 0.78 : 0.25,
depthWrite: false
})
);
segment.position.copy(midpoint);
segment.quaternion.setFromUnitVectors(yAxis, direction.normalize());
routeHighlightGroup.add(segment);
const glowSegment = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.16, length, 6),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: isActive ? 0.075 : 0.025,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
glowSegment.position.copy(midpoint);
glowSegment.quaternion.copy(segment.quaternion);
routeHighlightGroup.add(glowSegment);
}
}
// -------------------------------------------------------------------------
// Active packet
// -------------------------------------------------------------------------
const packet = new THREE.Group();
packet.visible = false;
const packetCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.23, 0),
new THREE.MeshStandardMaterial({
color: 0xffe1a0,
emissive: PACKET_COLOR,
emissiveIntensity: 3,
roughness: 0.2,
metalness: 0.25,
flatShading: true
})
);
packet.add(packetCore);
const packetGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: glowTexture,
color: PACKET_COLOR,
transparent: true,
opacity: 0.65,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
packetGlow.scale.set(1.7, 1.7, 1);
packet.add(packetGlow);
const packetLight = new THREE.PointLight(PACKET_COLOR, 1.8, 5);
packet.add(packetLight);
const trail = [];
for (let i = 0; i < 4; i++) {
const trailPiece = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.085 - i * 0.012, 0),
new THREE.MeshBasicMaterial({
color: PACKET_COLOR,
transparent: true,
opacity: 0.48 - i * 0.09
})
);
trail.push(trailPiece);
packet.add(trailPiece);
}
scene.add(packet);
const packetLabelCanvas = document.createElement("canvas");
packetLabelCanvas.width = 320;
packetLabelCanvas.height = 72;
const packetLabelContext = packetLabelCanvas.getContext("2d");
const packetLabelTexture = new THREE.CanvasTexture(packetLabelCanvas);
packetLabelTexture.colorSpace = THREE.SRGBColorSpace;
const packetLabel = new THREE.Sprite(
new THREE.SpriteMaterial({
map: packetLabelTexture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
packetLabel.scale.set(2.9, 0.65, 1);
packetLabel.renderOrder = 20;
scene.add(packetLabel);
packetLabel.visible = false;
function setPacketLabel(message) {
packetLabelContext.clearRect(
0, 0,
packetLabelCanvas.width,
packetLabelCanvas.height
);
packetLabelContext.fillStyle = "rgba(6, 13, 18, 0.9)";
packetLabelContext.fillRect(0, 0, 320, 72);
packetLabelContext.fillStyle = "#ffc85c";
packetLabelContext.fillRect(0, 0, 5, 72);
packetLabelContext.font = "700 24px monospace";
packetLabelContext.textAlign = "center";
packetLabelContext.textBaseline = "middle";
packetLabelContext.fillStyle = "#fff0ca";
const destination = nodes[message.destination].name;
packetLabelContext.fillText(
`MSG ${String(message.sequence).padStart(2, "0")} → ${destination}`,
166,
37
);
packetLabelTexture.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Routing and FIFO transmission state
// -------------------------------------------------------------------------
const messages = [];
let activeMessage = null;
let selectedWaypoint = "cinder";
let sequenceCounter = 0;
let completedTransmissions = 0;
let nextStartDelay = 0;
let lastRoute = [];
function shortestPath(start, end, blockedIds = []) {
if (start === end) return [start];
const blocked = new Set(blockedIds);
blocked.delete(start);
const queue = [start];
const previous = new Map([[start, null]]);
while (queue.length) {
const current = queue.shift();
for (const neighbor of nodes[current].neighbors) {
if (previous.has(neighbor) || blocked.has(neighbor)) continue;
previous.set(neighbor, current);
if (neighbor === end) {
const path = [end];
let cursor = end;
while (previous.get(cursor) !== null) {
cursor = previous.get(cursor);
path.push(cursor);
}
return path.reverse();
}
queue.push(neighbor);
}
}
return null;
}
function enqueueMessage(body, destination) {
const route = shortestPath(SOURCE, destination);
if (!route) return;
sequenceCounter += 1;
const message = {
sequence: sequenceCounter,
body,
destination,
route,
step: 0,
status: "QUEUED",
progress: 0,
relayTimer: 0,
pendingRoute: null
};
messages.push(message);
if (!activeMessage) {
startNextMessage();
} else {
showToast(
`Transmission ${String(sequenceCounter).padStart(2, "0")} queued. ` +
"It will follow the active signal."
);
}
refreshInterface();
}
function startNextMessage() {
const next = messages.find(message => message.status === "QUEUED");
if (!next) return;
activeMessage = next;
activeMessage.status = "TRAVEL";
activeMessage.progress = 0;
activeMessage.step = 0;
packet.visible = true;
packetLabel.visible = true;
setPacketLabel(activeMessage);
refreshInterface();
}
function activeDisplayRoute() {
if (!activeMessage) return null;
if (activeMessage.pendingRoute) {
return activeMessage.route
.slice(0, activeMessage.step + 2)
.concat(activeMessage.pendingRoute.slice(1));
}
return activeMessage.route;
}
function calculateReroute(message, current, seen) {
if (current === message.destination) return null;
if (seen.includes(selectedWaypoint)) return null;
const visited = seen.filter(id => id !== current);
const blockedFirst = [...visited];
if (selectedWaypoint !== message.destination) {
blockedFirst.push(message.destination);
}
const firstLeg = shortestPath(
current,
selectedWaypoint,
blockedFirst
);
if (!firstLeg) return null;
const blockedSecond = [
...visited,
...firstLeg.slice(1, -1)
];
const secondLeg = shortestPath(
selectedWaypoint,
message.destination,
blockedSecond
);
if (!secondLeg) return null;
return firstLeg.concat(secondLeg.slice(1));
}
function applyReroute() {
if (!activeMessage) {
showToast("No active transmission to reroute.");
return;
}
if (!['TRAVEL', 'RELAY'].includes(activeMessage.status)) {
showToast("The signal is not currently on the network.");
return;
}
const current = activeMessage.route[activeMessage.step + 1];
const seen = activeMessage.route.slice(0, activeMessage.step + 2);
const newRoute = calculateReroute(activeMessage, current, seen);
if (!newRoute) {
showToast(
`Cannot reroute through ${nodes[selectedWaypoint].name}. ` +
"Choose a tower that has not already been visited."
);
return;
}
if (activeMessage.status === "TRAVEL") {
// The current segment is allowed to finish. The new circuit is committed
// at the next relay, preserving packet order and segment continuity.
activeMessage.pendingRoute = newRoute;
showToast(
`Reroute accepted via ${nodes[selectedWaypoint].name}. ` +
"It will take effect at the next relay."
);
} else {
activeMessage.route = newRoute;
activeMessage.step = -1;
showToast(
`Circuit changed via ${nodes[selectedWaypoint].name}. ` +
"Sequence position is unchanged."
);
}
refreshInterface();
}
function completeDelivery(message) {
message.status = "DELIVERED";
completedTransmissions += 1;
lastRoute = [...message.route];
packet.visible = false;
packetLabel.visible = false;
activeMessage = null;
nextStartDelay = 0.7;
showToast(
`Transmission ${String(message.sequence).padStart(2, "0")} delivered ` +
`to ${nodes[message.destination].name}.`
);
refreshInterface();
}
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
for (const [id, data] of Object.entries(nodes)) {
if (id === SOURCE) continue;
const option = document.createElement("option");
option.value = id;
option.textContent = `${data.name} / ${data.code}`;
destinationSelect.appendChild(option);
}
destinationSelect.value = "ember";
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(showToast.timer);
showToast.timer = setTimeout(() => {
toastElement.classList.remove("show");
}, 3300);
}
function refreshInterface() {
const displayedRoute = activeMessage
? activeDisplayRoute()
: (
lastRoute.length
? lastRoute
: shortestPath(SOURCE, destinationSelect.value)
);
routeElement.replaceChildren();
if (displayedRoute) {
displayedRoute.forEach((id, index) => {
const chip = document.createElement("span");
chip.className = "route-chip";
chip.textContent = nodes[id].name;
routeElement.appendChild(chip);
if (index < displayedRoute.length - 1) {
const arrow = document.createElement("span");
arrow.className = "route-arrow";
arrow.textContent = "→";
routeElement.appendChild(arrow);
}
});
}
queueElement.replaceChildren();
for (const message of messages.slice(-8)) {
const row = document.createElement("div");
row.className = "queue-row";
const sequence = document.createElement("span");
sequence.className = "queue-seq";
sequence.textContent = String(message.sequence).padStart(2, "0");
const body = document.createElement("span");
body.className = "queue-body";
body.textContent = message.body;
const state = document.createElement("span");
state.className = "queue-state";
if (message.status === "TRAVEL") {
state.textContent = "IN FLIGHT";
state.classList.add("active");
} else if (message.status === "RELAY") {
state.textContent = "RELAY";
state.classList.add("active");
} else if (message.status === "DELIVERED") {
state.textContent = "DELIVERED";
state.classList.add("delivered");
} else {
state.textContent = "HOLDING";
}
row.append(sequence, body, state);
queueElement.appendChild(row);
}
const queued = messages.filter(
message => message.status === "QUEUED"
).length;
queueCount.textContent = String(queued).padStart(2, "0");
deliveredCount.textContent = `${completedTransmissions} Delivered`;
const routeSegments = displayedRoute
? Math.max(0, displayedRoute.length - 1)
: 0;
latency.textContent = `${(routeSegments * (HOP_DURATION + RELAY_DURATION)).toFixed(1)} s`;
waypointName.textContent =
`${nodes[selectedWaypoint].name} / ${nodes[selectedWaypoint].code}`;
rerouteButton.disabled = !activeMessage;
if (activeMessage) {
if (activeMessage.status === "TRAVEL") {
const from = nodes[activeMessage.route[activeMessage.step]].name;
const to = nodes[activeMessage.route[activeMessage.step + 1]].name;
topStatus.textContent =
`${String(activeMessage.sequence).padStart(2, "0")} / ${from} → ${to}`;
statusText.textContent = "In flight";
statusPill.style.color = "var(--gold)";
routeHint.textContent = activeMessage.pendingRoute
? "Reroute pending"
: "Signal advancing";
} else {
const current = nodes[activeMessage.route[activeMessage.step + 1]].name;
topStatus.textContent =
`${String(activeMessage.sequence).padStart(2, "0")} / ${current}`;
statusText.textContent = "Relaying";
statusPill.style.color = "var(--gold)";
routeHint.textContent = "350 ms relay";
}
} else {
topStatus.textContent = queued ? "FIFO READY" : "NETWORK READY";
statusText.textContent = "Online";
statusPill.style.color = "var(--green)";
routeHint.textContent = queued ? "Next packet ready" : "Awaiting traffic";
}
highlightRoute(displayedRoute, Boolean(activeMessage));
}
sendButton.addEventListener("click", () => {
const body = messageInput.value.trim() || "UNTITLED TRANSMISSION";
enqueueMessage(body, destinationSelect.value);
});
rerouteButton.addEventListener("click", applyReroute);
messageInput.addEventListener("keydown", event => {
if (event.key === "Enter") {
event.preventDefault();
sendButton.click();
}
});
destinationSelect.addEventListener("change", () => {
if (!activeMessage) refreshInterface();
});
// -------------------------------------------------------------------------
// Custom camera controls and node picking
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.55, 0);
const cameraState = {
radius: 25,
targetRadius: 25,
theta: 0.68,
targetTheta: 0.68,
phi: 1.03,
targetPhi: 1.03
};
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: false,
x: 0,
y: 0,
lastX: 0,
lastY: 0
};
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 9);
cameraState.radius +=
(cameraState.targetRadius - cameraState.radius) * smoothing;
cameraState.theta +=
(cameraState.targetTheta - cameraState.theta) * smoothing;
cameraState.phi +=
(cameraState.targetPhi - cameraState.phi) * smoothing;
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraTarget.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * cosPhi,
cameraTarget.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
function pickNode(event) {
const bounds = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y = -((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(nodeHitMeshes, false);
if (!intersections.length) return;
const nodeId = intersections[0].object.userData.nodeId;
selectedWaypoint = nodeId;
refreshInterface();
showToast(
`${nodes[nodeId].name} selected as the recovery waypoint. ` +
(activeMessage
? "Press Reroute to commit the new circuit."
: "It will be used by the next transmission.")
);
}
canvas.addEventListener("pointerdown", event => {
pointerState.down = true;
pointerState.moved = false;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerState.down) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
if (
Math.abs(event.clientX - pointerState.x) +
Math.abs(event.clientY - pointerState.y) > 5
) {
pointerState.moved = true;
}
cameraState.targetTheta -= dx * 0.006;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi + dy * 0.005,
0.48,
1.36
);
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
});
canvas.addEventListener("pointerup", event => {
if (!pointerState.moved) pickNode(event);
pointerState.down = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerState.down = false;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius + event.deltaY * 0.014,
16,
39
);
}, { passive: false });
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateLinks(elapsed) {
for (const link of linkVisuals) {
const phase = (elapsed * link.speed + link.phase) % 1;
link.pulse.position.lerpVectors(link.start, link.end, phase);
link.pulse.material.opacity = 0.22 + Math.sin(phase * Math.PI) * 0.52;
link.pulse.scale.setScalar(0.75 + Math.sin(phase * Math.PI) * 0.45);
}
}
function updateNodeVisuals(elapsed) {
let activeFrom = null;
let activeTo = null;
if (activeMessage) {
if (activeMessage.status === "TRAVEL") {
activeFrom = activeMessage.route[activeMessage.step];
activeTo = activeMessage.route[activeMessage.step + 1];
} else {
activeTo = activeMessage.route[activeMessage.step + 1];
}
}
for (const [id, visual] of Object.entries(nodeVisuals)) {
const selected = id === selectedWaypoint;
const involved = id === activeFrom || id === activeTo;
visual.ringMaterial.color.set(
selected ? PACKET_COLOR : 0x5cd8e8
);
visual.ringMaterial.opacity =
selected ? 0.86 : involved ? 0.52 : 0.12;
const selectedScale = selected
? 1.05 + Math.sin(elapsed * 3.2) * 0.05
: involved
? 1.03
: 1;
visual.ring.scale.setScalar(selectedScale);
visual.orbMaterial.emissiveIntensity = involved
? 2.8 + Math.sin(elapsed * 5) * 0.4
: selected
? 1.9
: 1.2;
visual.glow.material.opacity = involved
? 0.65
: selected
? 0.46
: 0.24;
}
}
function updatePacket(delta, elapsed) {
if (!activeMessage) {
packet.visible = false;
packetLabel.visible = false;
return;
}
packet.visible = true;
packetLabel.visible = true;
const message = activeMessage;
if (message.status === "TRAVEL") {
message.progress = Math.min(1, message.progress + delta / HOP_DURATION);
const from = nodes[message.route[message.step]].position;
const to = nodes[message.route[message.step + 1]].position;
const direction = to.clone().sub(from).normalize();
packet.position.lerpVectors(from, to, message.progress);
packet.position.y = 0.84 + Math.sin(message.progress * Math.PI) * 0.16;
trail.forEach((piece, index) => {
piece.position.copy(direction).multiplyScalar(-(index + 1) * 0.16);
piece.rotation.x += delta * 4;
piece.rotation.y += delta * 5;
});
packetCore.rotation.x += delta * 4.4;
packetCore.rotation.y += delta * 3.2;
if (message.progress >= 1) {
message.status = "RELAY";
message.relayTimer = 0;
if (message.pendingRoute) {
message.route = message.pendingRoute;
message.step = -1;
message.pendingRoute = null;
}
refreshInterface();
}
} else if (message.status === "RELAY") {
message.relayTimer += delta;
const currentNode = message.route[message.step + 1];
packet.position.copy(nodes[currentNode].position);
packet.position.y =
1.58 + Math.sin(elapsed * 8) * 0.06;
trail.forEach((piece, index) => {
piece.position.set(
Math.cos(elapsed * 4 + index) * 0.16,
-0.35 - index * 0.05,
Math.sin(elapsed * 4 + index) * 0.16
);
piece.rotation.x += delta * 5;
});
if (message.relayTimer >= RELAY_DURATION) {
if (message.step + 1 >= message.route.length - 1) {
completeDelivery(message);
} else {
message.step += 1;
message.status = "TRAVEL";
message.progress = 0;
refreshInterface();
}
}
}
packetLabel.position.copy(packet.position);
packetLabel.position.y += 0.85;
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
updateLinks(elapsed);
updateNodeVisuals(elapsed);
updatePacket(delta, elapsed);
if (!activeMessage && nextStartDelay > 0) {
nextStartDelay -= delta;
if (nextStartDelay <= 0) startNextMessage();
} else if (!activeMessage && nextStartDelay <= 0) {
const queued = messages.some(
message => message.status === "QUEUED"
);
if (queued) startNextMessage();
}
stars.rotation.y = elapsed * 0.006;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Start with one demonstration transmission
// -------------------------------------------------------------------------
refreshInterface();
updateCamera(1);
animate();
setTimeout(() => {
enqueueMessage(
"RIDGELINE / HOLD FOR RELEASE",
destinationSelect.value
);
}, 700);
</script>
</body>
</html>
```