Prompt specification
Build or customize the Three.js 3D scene "Message relay playground challenge" 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: Message relay playground challenge
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/message-relay-playground-challenge-x0384
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a string telephone. Create several cup-phone stations connected by strings; users establish a continuous route for a symbolic message while broken or slack links visibly interrupt transmission. Low-poly.
Working Three.js Starter (message-relay-playground-challenge-x0384):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Telephone — Signal Network</title>
<style>
:root {
--paper: #f4eddf;
--panel: rgba(250, 246, 237, 0.88);
--ink: #283a35;
--muted: #6e7a72;
--line: rgba(40, 58, 53, 0.14);
--teal: #168f83;
--teal-light: #48c6b4;
--amber: #d89132;
--red: #d65345;
--shadow: 0 12px 40px rgba(61, 67, 52, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
summary {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.brand {
position: absolute;
top: 22px;
left: 22px;
width: 330px;
padding: 19px 20px 17px;
border-radius: 19px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 18px;
height: 2px;
border-radius: 2px;
background: var(--teal);
}
h1 {
margin: 7px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3vw, 39px);
font-weight: 600;
line-height: 0.98;
letter-spacing: -0.04em;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status {
display: flex;
align-items: center;
gap: 10px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgba(22, 143, 131, 0.11);
}
.status.warning .status-dot {
background: var(--red);
box-shadow: 0 0 0 5px rgba(214, 83, 69, 0.12);
}
.status.complete .status-dot {
background: var(--amber);
box-shadow: 0 0 0 5px rgba(216, 145, 50, 0.13);
}
#status-title {
display: block;
font-size: 12px;
font-weight: 800;
}
#status-detail {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.network {
position: absolute;
top: 22px;
right: 22px;
width: 248px;
padding: 14px;
border-radius: 18px;
}
.network summary {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
list-style: none;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.02em;
}
.network summary::-webkit-details-marker {
display: none;
}
.network summary::after {
content: "+";
color: var(--teal);
font-size: 19px;
font-weight: 400;
}
.network details[open] summary::after {
content: "−";
}
.network-note {
margin: 8px 0 10px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#line-list {
display: grid;
gap: 5px;
max-height: 310px;
overflow: auto;
padding-right: 2px;
}
.line-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
padding: 7px 8px;
border: 1px solid transparent;
border-radius: 9px;
background: rgba(255, 255, 255, 0.38);
cursor: pointer;
text-align: left;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.line-row:hover {
background: rgba(255, 255, 255, 0.85);
border-color: rgba(22, 143, 131, 0.18);
transform: translateX(-2px);
}
.line-dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.line-dot.taut {
background: #6f5745;
}
.line-dot.slack {
background: var(--amber);
box-shadow: 0 0 0 3px rgba(216, 145, 50, 0.13);
}
.line-dot.broken {
background: var(--red);
box-shadow: 0 0 0 3px rgba(214, 83, 69, 0.13);
}
.line-names {
font-size: 10px;
font-weight: 750;
}
.line-state {
color: var(--muted);
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.route-panel {
position: absolute;
top: 22px;
left: 50%;
width: min(430px, 42vw);
padding: 13px 16px;
border-radius: 17px;
transform: translateX(-50%);
}
.route-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
}
.route-heading strong {
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.route-heading span {
color: var(--muted);
font-size: 9px;
}
#route-track {
display: flex;
align-items: center;
gap: 6px;
min-height: 28px;
overflow-x: auto;
white-space: nowrap;
scrollbar-width: none;
}
#route-track::-webkit-scrollbar {
display: none;
}
.route-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border-radius: 8px;
background: rgba(22, 143, 131, 0.11);
color: #116f67;
font-size: 10px;
font-weight: 850;
}
.route-chip small {
color: rgba(17, 111, 103, 0.62);
font-size: 8px;
font-weight: 650;
}
.route-arrow {
color: #9ca69f;
font-size: 10px;
}
.dock {
position: absolute;
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border-radius: 17px;
transform: translateX(-50%);
}
.dock button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.54);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}
.dock button:hover {
background: white;
transform: translateY(-1px);
}
.dock button:active {
transform: translateY(1px);
}
.dock .send {
min-width: 126px;
border-color: transparent;
background: var(--teal);
color: white;
box-shadow: 0 7px 18px rgba(22, 143, 131, 0.24);
}
.dock .send:hover {
background: #0f7f75;
}
.dock .send.blocked {
background: var(--red);
box-shadow: 0 7px 18px rgba(214, 83, 69, 0.22);
}
.divider {
width: 1px;
height: 25px;
margin: 0 2px;
background: var(--line);
}
#toast {
position: absolute;
bottom: 91px;
left: 50%;
max-width: min(520px, 88vw);
padding: 10px 15px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 12px;
background: rgba(39, 57, 52, 0.88);
color: white;
box-shadow: var(--shadow);
font-size: 11px;
line-height: 1.35;
text-align: center;
opacity: 0;
transform: translate(-50%, 8px);
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.warning {
background: rgba(171, 66, 54, 0.93);
}
.hint {
position: absolute;
bottom: 23px;
left: 22px;
width: 245px;
padding: 12px 14px;
border-radius: 14px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.hint strong {
color: var(--ink);
}
.legend {
display: flex;
gap: 11px;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: flex;
align-items: center;
gap: 4px;
}
.legend i {
width: 6px;
height: 6px;
border-radius: 50%;
background: #6f5745;
}
.legend i.slack {
background: var(--amber);
}
.legend i.broken {
background: var(--red);
}
@media (max-width: 980px) {
.route-panel {
top: 218px;
left: 22px;
width: 330px;
transform: none;
}
.hint {
display: none;
}
}
@media (max-width: 680px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.brand p,
.status {
display: none;
}
h1 {
font-size: 28px;
}
.network {
top: 112px;
right: 12px;
width: 190px;
padding: 10px;
}
.network-note {
display: none;
}
#line-list {
max-height: 165px;
}
.route-panel {
top: 112px;
left: 12px;
width: calc(100vw - 224px);
min-width: 125px;
padding: 10px;
}
.route-heading span {
display: none;
}
.dock {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
overflow-x: auto;
}
.dock button {
padding: 0 10px;
white-space: nowrap;
}
.dock .send {
min-width: 108px;
}
#toast {
bottom: 74px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly string telephone network"></canvas>
<main class="ui">
<header class="brand panel">
<div class="eyebrow">Field Network 07</div>
<h1>String Telephone</h1>
<p>
Build a continuous route between cups. A symbolic message only travels
through taut, unbroken strings.
</p>
<div id="status" class="status">
<span class="status-dot"></span>
<span>
<span id="status-title">Route staged</span>
<span id="status-detail">4 stations selected</span>
</span>
</div>
</header>
<section class="route-panel panel">
<div class="route-heading">
<strong>Your route</strong>
<span>Select cups in order</span>
</div>
<div id="route-track"></div>
</section>
<aside class="network panel">
<details open>
<summary>String network</summary>
<p class="network-note">
Tap a string in the scene or a row below to cycle between taut,
slack, and broken.
</p>
<div id="line-list"></div>
</details>
</aside>
<div id="toast" role="status" aria-live="polite"></div>
<section class="hint panel">
<strong>Controls</strong><br>
Drag to orbit · Shift-drag to pan · Scroll to zoom<br>
Click cups to add stations · Click the last cup to remove it
<div class="legend">
<span><i></i> Taut</span>
<span><i class="slack"></i> Slack</span>
<span><i class="broken"></i> Broken</span>
</div>
</section>
<nav class="dock panel" aria-label="Scene controls">
<button id="undo" type="button" title="Remove the last station">Undo</button>
<button id="clear" type="button">Clear route</button>
<div class="divider"></div>
<button id="repair" type="button">Make all taut</button>
<button id="reset-view" type="button" title="Reset camera">Reset view</button>
<button id="send" class="send" type="button">Send symbol</button>
</nav>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1eadc);
scene.fog = new THREE.Fog(0xf1eadc, 17, 34);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const target = new THREE.Vector3(0.65, 1.05, 0);
let cameraYaw = 0.53;
let cameraPitch = 0.57;
let cameraDistance = 16.5;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
target.x + Math.sin(cameraYaw) * horizontal,
target.y + Math.sin(cameraPitch) * cameraDistance,
target.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7e7, 0x83927a, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d5, 3.1);
sun.position.set(-7, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc5e8df, 0.8);
fill.position.set(8, 6, -8);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xd5ddc2,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.CircleGeometry(10.5, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const distantGround = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0xe9e2d3,
roughness: 1
})
);
distantGround.rotation.x = -Math.PI / 2;
distantGround.position.y = -0.035;
distantGround.receiveShadow = true;
scene.add(distantGround);
const patchColors = [0xc4d0ad, 0xbfcdb2, 0xd8d5b5, 0xcbd4bd];
const patchData = [
[-3.4, -0.8, 2.3, 0xc4d0ad],
[3.1, 0.8, 2.0, 0xbfcdb2],
[0.4, 2.6, 1.7, 0xd8d5b5],
[-1.5, -3.5, 1.4, 0xcbd4bd]
];
for (const [x, z, radius, color] of patchData) {
const patch = new THREE.Mesh(
new THREE.CircleGeometry(radius, 13),
new THREE.MeshStandardMaterial({
color,
roughness: 1,
transparent: true,
opacity: 0.58
})
);
patch.rotation.x = -Math.PI / 2;
patch.rotation.z = Math.random() * Math.PI;
patch.position.set(x, 0.008, z);
scene.add(patch);
}
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const temporaryDirection = new THREE.Vector3();
const temporaryMidpoint = new THREE.Vector3();
function cylinderBetween(start, end, radius, material, radialSegments = 7) {
const direction = new THREE.Vector3().subVectors(end, start);
const geometry = new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
radialSegments
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
temporaryDirection.copy(direction).normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function makeLabelSprite(letter, name, accent) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 320;
labelCanvas.height = 112;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 320, 112);
context.shadowColor = "rgba(42, 56, 45, 0.16)";
context.shadowBlur = 14;
context.shadowOffsetY = 6;
roundedRect(context, 8, 8, 304, 92, 25);
context.fillStyle = "rgba(250, 247, 238, 0.96)";
context.fill();
context.shadowColor = "transparent";
context.fillStyle = accent;
roundedRect(context, 24, 27, 53, 53, 16);
context.fill();
context.fillStyle = "#ffffff";
context.font = "800 30px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(letter, 50, 53);
context.textAlign = "left";
context.fillStyle = "#31423c";
context.font = "800 19px system-ui, sans-serif";
context.fillText(name.toUpperCase(), 94, 46);
context.fillStyle = "#78837c";
context.font = "500 13px system-ui, sans-serif";
context.fillText("CUP STATION", 94, 69);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.85, 0.65, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeWarningSprite(type) {
const warningCanvas = document.createElement("canvas");
warningCanvas.width = 128;
warningCanvas.height = 128;
const context = warningCanvas.getContext("2d");
context.clearRect(0, 0, 128, 128);
context.beginPath();
context.arc(64, 64, 47, 0, Math.PI * 2);
context.fillStyle = type === "broken" ? "#d65345" : "#d89132";
context.fill();
context.strokeStyle = "rgba(255,255,255,0.85)";
context.lineWidth = 7;
context.lineCap = "round";
if (type === "broken") {
context.beginPath();
context.moveTo(43, 43);
context.lineTo(85, 85);
context.moveTo(85, 43);
context.lineTo(43, 85);
context.stroke();
} else {
context.beginPath();
context.moveTo(64, 34);
context.lineTo(64, 72);
context.stroke();
context.beginPath();
context.arc(64, 91, 4, 0, Math.PI * 2);
context.fillStyle = "white";
context.fill();
}
const texture = new THREE.CanvasTexture(warningCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.55, 0.55, 1);
sprite.renderOrder = 25;
return sprite;
}
// -------------------------------------------------------------------------
// Low-poly stations
// -------------------------------------------------------------------------
const nodeData = [
{ letter: "A", name: "Alder", position: [-4.65, 1.5, -1.95], color: 0xc96e4b },
{ letter: "B", name: "Birch", position: [-2.45, 1.62, -3.65], color: 0x3e8d83 },
{ letter: "C", name: "Clover", position: [0.05, 1.43, -2.82], color: 0xd3a33f },
{ letter: "D", name: "Dune", position: [2.75, 1.62, -0.55], color: 0x668e68 },
{ letter: "E", name: "Echo", position: [4.25, 1.45, 2.15], color: 0xc96e4b },
{ letter: "F", name: "Fern", position: [1.35, 1.55, 3.72], color: 0x3e8d83 },
{ letter: "G", name: "Grove", position: [-2.4, 1.48, 2.58], color: 0xd3a33f }
];
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x75573f,
roughness: 0.88
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x5f4938,
roughness: 0.92
});
const cordMaterial = new THREE.LineBasicMaterial({
color: 0x675344
});
const nodes = [];
const nodePickMeshes = [];
for (let index = 0; index < nodeData.length; index++) {
const data = nodeData[index];
const station = new THREE.Group();
station.position.set(data.position[0], 0, data.position[2]);
scene.add(station);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(0.73, 0.81, 0.13, 8),
new THREE.MeshStandardMaterial({
color: 0xe7ddc8,
roughness: 0.92
})
);
platform.position.set(0, 0.065, -0.18);
platform.receiveShadow = true;
platform.castShadow = true;
station.add(platform);
const postStart = new THREE.Vector3(0, 0.12, -0.62);
const postEnd = new THREE.Vector3(0, 2.55, -0.62);
station.add(
cylinderBetween(postStart, postEnd, 0.055, darkWoodMaterial, 6)
);
const armStart = new THREE.Vector3(0, 2.25, -0.62);
const armEnd = new THREE.Vector3(0, 2.25, 0);
station.add(
cylinderBetween(armStart, armEnd, 0.045, darkWoodMaterial, 6)
);
const hangingGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 2.25, 0),
new THREE.Vector3(0, 1.05, 0)
]);
station.add(new THREE.Line(hangingGeometry, cordMaterial));
const cup = new THREE.Group();
cup.position.y = data.position[1];
cup.rotation.y = [-0.1, 0.18, -0.22, 0.12, -0.16, 0.2, -0.08][index];
station.add(cup);
const cupMaterial = new THREE.MeshStandardMaterial({
color: data.color,
roughness: 0.74,
metalness: 0,
side: THREE.DoubleSide,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.48, 0.34, 0.78, 10, 1, true),
cupMaterial
);
body.castShadow = true;
body.receiveShadow = true;
cup.add(body);
const inside = new THREE.Mesh(
new THREE.CircleGeometry(0.435, 10),
new THREE.MeshStandardMaterial({
color: 0x493a32,
roughness: 0.95,
side: THREE.DoubleSide
})
);
inside.rotation.x = -Math.PI / 2;
inside.position.y = 0.37;
cup.add(inside);
const bottom = new THREE.Mesh(
new THREE.CylinderGeometry(0.345, 0.34, 0.08, 10),
cupMaterial
);
bottom.position.y = -0.39;
bottom.castShadow = true;
cup.add(bottom);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.052, 5, 12),
cupMaterial
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.39;
rim.castShadow = true;
cup.add(rim);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.235, 0.062, 5, 10),
cupMaterial
);
handle.position.set(0.44, 0.02, 0);
handle.castShadow = true;
cup.add(handle);
const label = makeLabelSprite(
data.letter,
data.name,
`#${data.color.toString(16).padStart(6, "0")}`
);
label.position.set(0, 2.96, -0.25);
station.add(label);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x27a99b,
transparent: true,
opacity: 0.12,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.62, 0.028, 5, 24),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(0, 0.145, -0.18);
station.add(ring);
const pickMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const pickMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.63, 8, 6),
pickMaterial
);
pickMesh.position.set(
data.position[0],
data.position[1],
data.position[2]
);
pickMesh.userData.nodeIndex = index;
scene.add(pickMesh);
nodePickMeshes.push(pickMesh);
nodes.push({
...data,
group: station,
cup,
ring,
ringMaterial,
label
});
}
// -------------------------------------------------------------------------
// Decorative low-poly vegetation
// -------------------------------------------------------------------------
function makeTree(x, z, scale, color) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.18, 1.5, 5),
woodMaterial
);
trunk.position.y = 0.75;
trunk.castShadow = true;
tree.add(trunk);
const foliageMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
});
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.88, 1.8, 6),
foliageMaterial
);
lower.position.y = 1.75;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.65, 1.55, 6),
foliageMaterial
);
upper.position.y = 2.55;
upper.castShadow = true;
tree.add(upper);
scene.add(tree);
}
const trees = [
[-8.1, -4.8, 1.2, 0x6f8f69],
[-6.8, 5.7, 0.95, 0x78966d],
[-4.9, 7.2, 1.25, 0x5f8263],
[6.9, 5.2, 1.15, 0x76916a],
[8.2, 1.0, 0.9, 0x668863],
[6.7, -5.3, 1.3, 0x78966d],
[-0.8, -7.3, 1.0, 0x698b68],
[3.0, -6.6, 0.8, 0x809b70]
];
for (const tree of trees) {
makeTree(...tree);
}
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0xa8aa92,
roughness: 1,
flatShading: true
});
const rockData = [
[-6.2, -0.1, 0.35],
[-3.8, 4.9, 0.28],
[5.6, 4.4, 0.32],
[2.8, -4.8, 0.24],
[-0.7, 5.4, 0.2]
];
for (const [x, z, scale] of rockData) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
rockMaterial
);
rock.position.set(x, scale * 0.45, z);
rock.scale.set(1.25, 0.7, 1);
rock.rotation.set(Math.random(), Math.random(), Math.random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// -------------------------------------------------------------------------
// String network
// -------------------------------------------------------------------------
const linkDefinitions = [
{ a: 0, b: 1, state: "taut" },
{ a: 1, b: 2, state: "slack" },
{ a: 2, b: 3, state: "taut" },
{ a: 3, b: 4, state: "broken" },
{ a: 4, b: 5, state: "taut" },
{ a: 5, b: 6, state: "taut" },
{ a: 6, b: 0, state: "taut" },
{ a: 1, b: 6, state: "taut" },
{ a: 2, b: 5, state: "taut" }
];
const stateColors = {
taut: 0x6f5745,
slack: 0xd89132,
broken: 0xd65345
};
const links = [];
const linkPickMeshes = [];
const linkGroup = new THREE.Group();
const routeGroup = new THREE.Group();
scene.add(linkGroup, routeGroup);
function edgeBetween(a, b) {
return links.find(
(link) =>
(link.a === a && link.b === b) ||
(link.a === b && link.b === a)
);
}
function getLinkCurve(link, state = link.state) {
const startNode = nodes[link.a];
const endNode = nodes[link.b];
const start = new THREE.Vector3(
startNode.position[0],
1.64,
startNode.position[2]
);
const end = new THREE.Vector3(
endNode.position[0],
1.64,
endNode.position[2]
);
const direction = new THREE.Vector3().subVectors(end, start);
direction.y = 0;
direction.normalize();
start.addScaledVector(direction, 0.54);
end.addScaledVector(direction, -0.54);
const midpoint = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5);
const perpendicular = new THREE.Vector3(-direction.z, 0, direction.x);
if (state === "taut") {
midpoint.y -= 0.17;
midpoint.addScaledVector(perpendicular, 0.035);
} else if (state === "slack") {
midpoint.y -= 1.02;
midpoint.addScaledVector(perpendicular, 0.16);
} else {
midpoint.y -= 0.37;
midpoint.addScaledVector(perpendicular, -0.08);
}
return new THREE.QuadraticBezierCurve3(start, midpoint, end);
}
function makeCurveSegment(curve, from, to) {
const points = [];
for (let i = 0; i <= 10; i++) {
points.push(curve.getPoint(THREE.MathUtils.lerp(from, to, i / 10)));
}
return new THREE.CatmullRomCurve3(points, false, "centripetal");
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (object.material.map) object.material.map.dispose();
object.material.dispose();
}
});
}
}
function updateLinkVisual(link, refresh = true) {
clearGroup(link.group);
link.curve = getLinkCurve(link);
const material = new THREE.MeshStandardMaterial({
color: stateColors[link.state],
roughness: 0.88,
metalness: 0,
flatShading: true
});
if (link.state === "broken") {
const firstCurve = makeCurveSegment(link.curve, 0, 0.455);
const secondCurve = makeCurveSegment(link.curve, 0.545, 1);
const first = new THREE.Mesh(
new THREE.TubeGeometry(firstCurve, 22, 0.031, 5, false),
material
);
const second = new THREE.Mesh(
new THREE.TubeGeometry(secondCurve, 22, 0.031, 5, false),
material
);
first.castShadow = true;
second.castShadow = true;
link.group.add(first, second);
link.warning = makeWarningSprite("broken");
link.warning.position.copy(link.curve.getPointAt(0.5));
link.warning.position.y += 0.36;
link.group.add(link.warning);
} else {
const tube = new THREE.Mesh(
new THREE.TubeGeometry(link.curve, 36, 0.031, 5, false),
material
);
tube.castShadow = true;
link.group.add(tube);
if (link.state === "slack") {
link.warning = new THREE.Mesh(
new THREE.OctahedronGeometry(0.12, 0),
new THREE.MeshStandardMaterial({
color: 0xe5a13c,
emissive: 0x7b3900,
emissiveIntensity: 0.35,
roughness: 0.6
})
);
link.warning.position.copy(link.curve.getPointAt(0.5));
link.warning.position.y += 0.26;
link.warning.castShadow = true;
link.group.add(link.warning);
} else {
link.warning = null;
}
}
const pickMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const pickMesh = new THREE.Mesh(
new THREE.TubeGeometry(link.curve, 32, 0.13, 5, false),
pickMaterial
);
pickMesh.userData.linkIndex = links.indexOf(link);
link.pickMesh = pickMesh;
linkPickMeshes.push(pickMesh);
link.group.add(pickMesh);
if (refresh) { updateRouteVisuals(); updateNetworkPanel(); }
}
for (const definition of linkDefinitions) {
const link = {
...definition,
group: new THREE.Group(),
curve: null,
warning: null,
pickMesh: null
};
links.push(link);
linkGroup.add(link.group);
}
for (const link of links) {
updateLinkVisual(link, false);
}
// -------------------------------------------------------------------------
// Route UI and route visualization
// -------------------------------------------------------------------------
const route = [0, 1, 2, 3];
let toastTimer = 0;
let message = null;
const routeTrack = document.querySelector("#route-track");
const lineList = document.querySelector("#line-list");
const statusElement = document.querySelector("#status");
const statusTitle = document.querySelector("#status-title");
const statusDetail = document.querySelector("#status-detail");
const toastElement = document.querySelector("#toast");
const sendButton = document.querySelector("#send");
function showToast(messageText, tone = "") {
toastElement.textContent = messageText;
toastElement.className = `show ${tone}`;
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.className = tone;
}, 2800);
}
function setStatus(title, detail, mode = "") {
statusTitle.textContent = title;
statusDetail.textContent = detail;
statusElement.className = `status ${mode}`;
}
function updateRouteUI() {
routeTrack.innerHTML = route
.map((nodeIndex, index) => {
const node = nodes[nodeIndex];
const chip = `
<span class="route-chip">
${node.letter}
<small>${node.name}</small>
</span>
`;
if (index < route.length - 1) {
return `${chip}<span class="route-arrow">→</span>`;
}
return chip;
})
.join("");
if (!message) {
setStatus(
route.length > 1 ? "Route staged" : "Build a route",
`${route.length} station${route.length === 1 ? "" : "s"} selected`
);
}
sendButton.classList.toggle("blocked", message?.phase === "blocked");
sendButton.textContent =
message?.phase === "blocked"
? "Resend symbol"
: message?.phase === "complete"
? "Send again"
: "Send symbol";
}
function updateRouteVisuals() {
clearGroup(routeGroup);
for (let i = 0; i < route.length - 1; i++) {
const link = edgeBetween(route[i], route[i + 1]);
if (!link) continue;
const color =
link.state === "taut"
? 0x27b8a8
: link.state === "slack"
? 0xe4a13f
: 0xe05a4b;
const ranges =
link.state === "broken" ? [[0.03, 0.42], [0.58, 0.97]] : [[0.03, 0.97]];
for (const [from, to] of ranges) {
const count = 13;
for (let step = 0; step < count; step++) {
const t = THREE.MathUtils.lerp(from, to, step / (count - 1));
const bead = new THREE.Mesh(
new THREE.OctahedronGeometry(0.047, 0),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85
})
);
bead.position.copy(link.curve.getPointAt(t));
bead.position.y += 0.025;
routeGroup.add(bead);
}
}
}
for (let i = 0; i < nodes.length; i++) {
const selected = route.includes(i);
const node = nodes[i];
node.ringMaterial.opacity = selected ? 0.88 : 0.1;
node.ringMaterial.color.set(selected ? 0x21aa9c : 0x60746a);
}
}
function updateNetworkPanel() {
lineList.innerHTML = links
.map((link, index) => {
const start = nodes[link.a];
const end = nodes[link.b];
return `
<button class="line-row" type="button" data-link="${index}">
<span class="line-dot ${link.state}"></span>
<span class="line-names">${start.letter} — ${end.letter}</span>
<span class="line-state">${link.state}</span>
</button>
`;
})
.join("");
lineList.querySelectorAll(".line-row").forEach((button) => {
button.addEventListener("click", () => {
cycleLink(Number(button.dataset.link));
});
});
}
function cycleLink(index) {
const link = links[index];
const nextState =
link.state === "taut" ? "slack" : link.state === "slack" ? "broken" : "taut";
link.state = nextState;
const oldPickIndex = linkPickMeshes.indexOf(link.pickMesh);
if (oldPickIndex !== -1) linkPickMeshes.splice(oldPickIndex, 1);
updateLinkVisual(link);
const start = nodes[link.a];
const end = nodes[link.b];
showToast(
`${start.letter}–${end.letter} is now ${nextState}. ` +
(nextState === "taut"
? "Signal can pass."
: nextState === "slack"
? "The line sags and blocks transmission."
: "The line has a visible gap.")
);
}
// -------------------------------------------------------------------------
// Symbolic message
// -------------------------------------------------------------------------
const packet = new THREE.Group();
packet.visible = false;
scene.add(packet);
const packetCore = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.115, 0),
new THREE.MeshStandardMaterial({
color: 0xffd34e,
emissive: 0xd47c0b,
emissiveIntensity: 1.3,
roughness: 0.35,
flatShading: true
})
);
packet.add(packetCore);
const packetShell = new THREE.Mesh(
new THREE.OctahedronGeometry(0.21, 0),
new THREE.MeshBasicMaterial({
color: 0xffef9b,
wireframe: true,
transparent: true,
opacity: 0.72
})
);
packet.add(packetShell);
const packetLight = new THREE.PointLight(0xffc94f, 1.2, 2.4, 2);
packet.add(packetLight);
const trail = [];
const trailMaterial = new THREE.MeshBasicMaterial({
color: 0xffdf69,
transparent: true,
opacity: 0.7
});
for (let i = 0; i < 6; i++) {
const dot = new THREE.Mesh(
new THREE.OctahedronGeometry(0.055 - i * 0.005, 0),
trailMaterial.clone()
);
dot.visible = false;
scene.add(dot);
trail.push(dot);
}
function stopMessage() {
message = null;
packet.visible = false;
for (const dot of trail) dot.visible = false;
}
function sendMessage() {
stopMessage();
if (route.length < 2) {
showToast("Select at least two cups to create a route.", "warning");
setStatus("Route incomplete", "Add another cup station");
return;
}
for (let i = 0; i < route.length - 1; i++) {
if (!edgeBetween(route[i], route[i + 1])) {
const start = nodes[route[i]];
const end = nodes[route[i + 1]];
showToast(
`${start.letter} and ${end.letter} are not directly connected. Choose a neighboring cup.`,
"warning"
);
setStatus("Route is not continuous", `${start.letter} → ${end.letter} has no string`);
return;
}
}
message = {
phase: "moving",
edgeIndex: 0,
progress: 0,
elapsed: 0
};
packet.visible = true;
packet.position.copy(links[0].curve.getPointAt(0));
packet.position.y += 0.13;
setStatus(
"Symbol travelling",
`Line 1 of ${route.length - 1}`,
"complete"
);
showToast("The symbolic message is moving through the selected route.");
updateRouteUI();
}
function updateMessage(delta) {
if (!message || message.phase !== "moving") return;
const currentRoute = message.route || route;
message.route = currentRoute;
const link = edgeBetween(
currentRoute[message.edgeIndex],
currentRoute[message.edgeIndex + 1]
);
if (!link) {
message.phase = "blocked";
return;
}
const speed = 0.72;
if (link.state === "taut") {
message.progress += delta * speed;
if (message.progress >= 1) {
message.progress = 0;
message.edgeIndex++;
if (message.edgeIndex >= currentRoute.length - 1) {
message.phase = "complete";
packet.position.copy(link.curve.getPointAt(1));
packet.position.y += 0.13;
setStatus(
"Symbol received",
`${nodes[currentRoute[currentRoute.length - 1]].name} station reached`,
"complete"
);
showToast("Message delivered. Every selected line was taut and unbroken.");
} else {
const nextLink = edgeBetween(
currentRoute[message.edgeIndex],
currentRoute[message.edgeIndex + 1]
);
packet.position.copy(nextLink.curve.getPointAt(0));
packet.position.y += 0.13;
setStatus(
"Symbol travelling",
`Line ${message.edgeIndex + 1} of ${currentRoute.length - 1}`,
"complete"
);
}
}
} else {
const stopAt = link.state === "slack" ? 0.34 : 0.435;
message.progress = Math.min(stopAt, message.progress + delta * speed);
if (message.progress >= stopAt) {
message.phase = "blocked";
message.blockedLink = link;
const reason =
link.state === "slack"
? "The string is too slack"
: "The string is broken";
setStatus(
"Transmission interrupted",
`${reason} at ${nodes[link.a].letter}–${nodes[link.b].letter}`,
"warning"
);
showToast(
`${reason}. The symbol cannot cross ${nodes[link.a].letter}–${nodes[link.b].letter}.`,
"warning"
);
}
}
const activeLink =
message.phase === "complete"
? link
: edgeBetween(
currentRoute[message.edgeIndex],
currentRoute[message.edgeIndex + 1]
);
if (activeLink) {
packet.position.copy(activeLink.curve.getPointAt(message.progress));
packet.position.y += 0.13;
}
updateRouteUI();
}
// -------------------------------------------------------------------------
// Interaction and custom camera controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerStart = null;
let pointerLast = null;
let pointerMoved = 0;
function setPointerFromEvent(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 pickScene(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const nodeHits = raycaster.intersectObjects(nodePickMeshes, false);
if (nodeHits.length) {
addOrRemoveNode(nodeHits[0].object.userData.nodeIndex);
return;
}
const linkHits = raycaster.intersectObjects(linkPickMeshes, false);
if (linkHits.length) {
cycleLink(linkHits[0].object.userData.linkIndex);
}
}
function addOrRemoveNode(nodeIndex) {
stopMessage();
if (route.length && route[route.length - 1] === nodeIndex) {
route.pop();
} else if (route.includes(nodeIndex)) {
showToast("Use Undo or click the final cup to revise an earlier station.");
return;
} else {
route.push(nodeIndex);
}
updateRouteUI();
updateRouteVisuals();
showToast(
route.length > 1
? `${nodes[nodeIndex].name} added. Continue to a directly connected cup.`
: `${nodes[nodeIndex].name} selected. Choose the next cup.`
);
}
canvas.addEventListener("pointerdown", (event) => {
pointerStart = {
x: event.clientX,
y: event.clientY
};
pointerLast = {
x: event.clientX,
y: event.clientY
};
pointerMoved = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerStart || !pointerLast) return;
const dx = event.clientX - pointerLast.x;
const dy = event.clientY - pointerLast.y;
pointerMoved += Math.abs(dx) + Math.abs(dy);
if (event.shiftKey) {
camera.updateMatrixWorld();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, Y_AXIS).normalize();
const panScale = cameraDistance * 0.0014;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(forward, dy * panScale);
} else {
cameraYaw -= dx * 0.0055;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.004,
0.19,
1.22
);
}
pointerLast.x = event.clientX;
pointerLast.y = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (pointerStart && pointerMoved < 7) {
pickScene(event);
}
pointerStart = null;
pointerLast = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerStart = null;
pointerLast = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.012,
9,
25
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraYaw = 0.53;
cameraPitch = 0.57;
cameraDistance = 16.5;
target.set(0.65, 1.05, 0);
updateCamera();
});
// -------------------------------------------------------------------------
// Buttons
// -------------------------------------------------------------------------
document.querySelector("#undo").addEventListener("click", () => {
stopMessage();
route.pop();
updateRouteUI();
updateRouteVisuals();
showToast("The last station was removed.");
});
document.querySelector("#clear").addEventListener("click", () => {
stopMessage();
route.length = 0;
updateRouteUI();
updateRouteVisuals();
showToast("Route cleared. Select a cup to begin again.");
});
document.querySelector("#repair").addEventListener("click", () => {
stopMessage();
for (const link of links) {
link.state = "taut";
const oldPickIndex = linkPickMeshes.indexOf(link.pickMesh);
if (oldPickIndex !== -1) linkPickMeshes.splice(oldPickIndex, 1);
updateLinkVisual(link);
}
updateRouteVisuals();
showToast("Every string is now taut. The network is ready to carry a symbol.");
});
document.querySelector("#reset-view").addEventListener("click", () => {
cameraYaw = 0.53;
cameraPitch = 0.57;
cameraDistance = 16.5;
target.set(0.65, 1.05, 0);
updateCamera();
});
sendButton.addEventListener("click", sendMessage);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateMessage(delta);
packet.rotation.y += delta * 1.5;
packet.rotation.x += delta * 0.7;
packetShell.scale.setScalar(1 + Math.sin(elapsed * 5) * 0.08);
if (message) {
for (let i = 0; i < trail.length; i++) {
const dot = trail[i];
const trailTime = i * 0.07;
const previousProgress = Math.max(0, message.progress - trailTime);
const activeLink =
message.phase === "complete"
? links[0]
: edgeBetween(
(message.route || route)[message.edgeIndex],
(message.route || route)[message.edgeIndex + 1]
);
if (activeLink) {
dot.visible = true;
dot.position.copy(activeLink.curve.getPointAt(previousProgress));
dot.position.y += 0.1;
dot.material.opacity = 0.68 * (1 - i / trail.length);
}
}
}
for (const link of links) {
if (link.warning) {
const pulse = 1 + Math.sin(elapsed * 4 + links.indexOf(link)) * 0.1;
link.warning.scale.setScalar(pulse);
}
}
for (let i = 0; i < nodes.length; i++) {
if (route.includes(i)) {
const pulse = 1 + Math.sin(elapsed * 3 + i) * 0.035;
nodes[i].ring.scale.setScalar(pulse);
} else {
nodes[i].ring.scale.setScalar(1);
}
}
renderer.render(scene, camera);
}
updateRouteUI();
updateRouteVisuals();
updateNetworkPanel();
showToast("The route is staged. Send the symbol, or choose cups to create a new route.");
animate();
</script>
</body>
</html>
```