Prompt specification
Build or customize the Three.js 3D scene "Domino route around obstacles" 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: Domino route around obstacles
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/domino-route-around-obstacles-x0331
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Build a tabletop with blocks, arches, and a branching domino track; a single trigger advances through connected branches while isolated sections remain upright.
Working Three.js Starter (domino-route-around-obstacles-x0331):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Domino Relay</title>
<style>
:root {
color-scheme: dark;
--cyan: #78e8ff;
--cyan-soft: rgba(120, 232, 255, 0.16);
--coral: #ff806f;
--yellow: #ffd66b;
--panel: rgba(10, 18, 25, 0.78);
--line: rgba(190, 226, 237, 0.16);
--text: #e8f4f7;
--muted: #8fa8b2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #091118;
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 38%, rgba(2, 8, 12, 0.43) 100%),
linear-gradient(180deg, rgba(2, 8, 12, 0.18), transparent 25%, transparent 75%, rgba(2, 8, 12, 0.3));
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px 17px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--cyan);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.intro p {
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.status-panel {
top: 24px;
right: 24px;
width: 258px;
padding: 15px 16px;
border-radius: 4px;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
color: var(--muted);
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-value {
display: flex;
align-items: center;
gap: 8px;
color: var(--text);
letter-spacing: 0.05em;
}
#statusDot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--yellow);
box-shadow: 0 0 10px rgba(255, 214, 107, 0.8);
}
.progress-track {
height: 3px;
overflow: hidden;
background: rgba(255, 255, 255, 0.08);
}
#progressFill {
width: 0;
height: 100%;
background: linear-gradient(90deg, #33bddf, var(--cyan));
box-shadow: 0 0 12px var(--cyan);
transition: width 80ms linear;
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 13px;
}
.stat {
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
background: rgba(255, 255, 255, 0.025);
}
.stat span {
display: block;
color: var(--muted);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 7px;
font: 700 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.stat.connected strong {
color: var(--cyan);
}
.stat.isolated strong {
color: var(--coral);
}
.controls {
position: absolute;
left: 50%;
bottom: 25px;
display: flex;
align-items: center;
gap: 10px;
transform: translateX(-50%);
pointer-events: none;
}
button {
position: relative;
min-height: 48px;
padding: 0 22px;
border: 1px solid rgba(120, 232, 255, 0.52);
border-radius: 3px;
background: linear-gradient(180deg, rgba(51, 189, 223, 0.2), rgba(17, 79, 94, 0.34));
color: #eafcff;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
cursor: pointer;
pointer-events: auto;
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25), inset 0 0 18px rgba(120, 232, 255, 0.04);
transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
border-color: var(--cyan);
background: linear-gradient(180deg, rgba(51, 189, 223, 0.34), rgba(17, 79, 94, 0.43));
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: wait;
opacity: 0.62;
}
button.secondary {
min-width: 88px;
border-color: var(--line);
background: rgba(10, 18, 25, 0.82);
color: var(--muted);
font-size: 10px;
}
.hint {
position: absolute;
right: 24px;
bottom: 25px;
color: rgba(190, 216, 224, 0.52);
font: 600 9px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
.legend {
position: absolute;
left: 24px;
bottom: 25px;
display: grid;
gap: 8px;
color: var(--muted);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend div {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 18px;
height: 3px;
background: var(--cyan);
box-shadow: 0 0 8px rgba(120, 232, 255, 0.45);
}
.swatch.coral {
background: var(--coral);
box-shadow: 0 0 8px rgba(255, 128, 111, 0.4);
}
@media (max-width: 760px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.intro p {
display: none;
}
.status-panel {
top: 126px;
left: 14px;
right: auto;
width: 218px;
padding: 12px;
}
.stats {
margin-top: 9px;
}
.controls {
bottom: 16px;
}
button {
min-height: 45px;
padding: 0 15px;
font-size: 10px;
}
button.secondary {
min-width: 70px;
}
.hint,
.legend {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel domino relay scene"></canvas>
<div class="vignette"></div>
<div class="ui">
<section class="panel intro">
<div class="eyebrow">Propagation test 03</div>
<h1>Domino<br>Relay</h1>
<p>
One signal enters the connected voxel network. Every reachable branch
advances; disconnected test sections remain locked upright.
</p>
</section>
<section class="panel status-panel">
<div class="status-row">
<span>System</span>
<span class="status-value">
<i id="statusDot"></i>
<span id="stateText" aria-live="polite">Awaiting trigger</span>
</span>
</div>
<div class="progress-track">
<div id="progressFill"></div>
</div>
<div class="stats">
<div class="stat connected">
<span>Connected</span>
<strong id="connectedCount">0 / 22</strong>
</div>
<div class="stat isolated">
<span>Isolated</span>
<strong id="isolatedCount">9 locked</strong>
</div>
</div>
</section>
<div class="legend">
<div><i class="swatch"></i> Connected relay</div>
<div><i class="swatch coral"></i> Isolated / locked</div>
</div>
<div class="controls">
<button id="triggerBtn" type="button">Trigger chain</button>
<button id="resetBtn" class="secondary" type="button">Reset</button>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom<br>
Click yellow trigger domino · Space to fire
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091118);
scene.fog = new THREE.Fog(0x091118, 19, 38);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -0.25, 0);
const cameraState = {
yaw: -0.58,
pitch: 0.73,
radius: 24,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xc8e9f1, 0x17212a, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d2, 3.4);
keyLight.position.set(-7, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x62d9ff, 1.35);
rimLight.position.set(8, 7, -9);
scene.add(rimLight);
const fillLight = new THREE.DirectionalLight(0xff806f, 0.42);
fillLight.position.set(9, 3, 7);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials and shared geometry
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dominoBodyGeometry = new THREE.BoxGeometry(0.22, 0.78, 0.58);
const dominoCapGeometry = new THREE.BoxGeometry(0.24, 0.22, 0.60);
const GROUND = 0.05;
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.04,
...options
});
}
const materials = {
base: standard(0x111c24, { roughness: 0.9 }),
leg: standard(0x182630, { roughness: 0.78 }),
rim: standard(0x33434d, { roughness: 0.76 }),
stone: standard(0x647681, { roughness: 0.9 }),
stoneLight: standard(0x83939a, { roughness: 0.88 }),
stoneDark: standard(0x485b67, { roughness: 0.92 }),
connectedChannel: standard(0x183b47, {
emissive: 0x071c22,
emissiveIntensity: 0.7
}),
isolatedChannel: standard(0x482a2c, {
emissive: 0x18090a,
emissiveIntensity: 0.6
}),
terminal: standard(0x33444e),
yellow: standard(0xffd66b, {
emissive: 0x6b4800,
emissiveIntensity: 0.45
})
};
const tileMaterials = [
standard(0x24343d, { roughness: 0.95 }),
standard(0x273943, { roughness: 0.95 }),
standard(0x213039, { roughness: 0.95 }),
standard(0x2a3c45, { roughness: 0.95 }),
standard(0x263740, { roughness: 0.95 })
];
const blockMaterials = [
standard(0x3d6570),
standard(0x876d56),
standard(0x52616b),
standard(0x6b5b70),
standard(0x697d55),
standard(0x315c68)
];
function addBox(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededNoise(i) {
const value = Math.sin(i * 127.1 + 311.7) * 43758.5453123;
return value - Math.floor(value);
}
// -------------------------------------------------------------------------
// Tabletop, tiled playfield, legs, border, and floor
// -------------------------------------------------------------------------
addBox(19.2, 0.8, 12.0, materials.base, 0, -0.45, 0);
addBox(40, 0.12, 34, standard(0x0b141b), 0, -3.63, 0);
const legPositions = [
[-7.8, -4.6],
[7.8, -4.6],
[-7.8, 4.6],
[7.8, 4.6]
];
for (const [x, z] of legPositions) {
addBox(0.72, 3.4, 0.72, materials.leg, x, -1.85, z);
}
const columns = 13;
const rows = 8;
const tileWidth = 18.0 / columns;
const tileDepth = 10.8 / rows;
let tileIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = -9 + tileWidth * (column + 0.5);
const z = -5.4 + tileDepth * (row + 0.5);
const material = tileMaterials[
Math.floor(seededNoise(tileIndex) * tileMaterials.length)
];
addBox(
tileWidth - 0.045,
0.08,
tileDepth - 0.045,
material,
x,
0,
z
);
tileIndex++;
}
}
// Raised voxel border segments.
for (let i = 0; i < 13; i++) {
const x = -8.65 + i * 1.38;
const material = i % 2 ? materials.rim : materials.stoneDark;
addBox(1.26, 0.18, 0.28, material, x, 0.09, -5.58);
addBox(1.26, 0.18, 0.28, material, x, 0.09, 5.58);
}
for (let i = 0; i < 8; i++) {
const z = -4.72 + i * 1.35;
const material = i % 2 ? materials.rim : materials.stoneDark;
addBox(0.28, 0.18, 1.23, material, -9.18, 0.09, z);
addBox(0.28, 0.18, 1.23, material, 9.18, 0.09, z);
}
// -------------------------------------------------------------------------
// Voxel scenery
// -------------------------------------------------------------------------
function addBlockStack(x, z, levels, paletteIndex = 0, size = 0.52) {
for (let level = 0; level < levels; level++) {
const offset = level % 2 ? 0.045 : -0.025;
const material =
blockMaterials[
(paletteIndex + level + Math.floor(seededNoise(x * 7 + z + level) * 3)) %
blockMaterials.length
];
addBox(
size,
size,
size,
material,
x + offset,
GROUND + size * 0.5 + level * (size + 0.025),
z - offset
);
}
}
const stackLayout = [
[-8.05, -3.75, 3, 0],
[-7.05, -4.05, 2, 2],
[-8.10, -2.45, 2, 4],
[-6.40, -3.55, 4, 5],
[-4.75, -4.05, 2, 3],
[-3.35, -4.15, 3, 1],
[-1.80, -4.05, 2, 0],
[2.25, -4.10, 3, 2],
[3.25, -3.75, 2, 5],
[4.20, -4.15, 4, 1],
[7.65, -3.95, 3, 4],
[8.10, -2.55, 2, 0],
[7.70, -0.55, 4, 2],
[-8.00, 4.65, 2, 3],
[2.15, 4.85, 3, 4],
[3.25, 4.60, 2, 1]
];
stackLayout.forEach(([x, z, levels, palette]) =>
addBlockStack(x, z, levels, palette)
);
function addVoxelArch(centerX, centerZ, routeAxis = "x", scale = 1) {
const cube = 0.44 * scale;
const sideOffset = 0.88 * scale;
const levels = 3;
for (const side of [-1, 1]) {
for (let level = 0; level < levels; level++) {
const material =
level % 2 === 0 ? materials.stone : materials.stoneDark;
if (routeAxis === "x") {
addBox(
cube,
cube,
cube,
material,
centerX,
GROUND + cube * 0.5 + level * cube,
centerZ + side * sideOffset
);
} else {
addBox(
cube,
cube,
cube,
material,
centerX + side * sideOffset,
GROUND + cube * 0.5 + level * cube,
centerZ
);
}
}
}
for (let i = -2; i <= 2; i++) {
const material = i % 2 === 0 ? materials.stoneLight : materials.stone;
if (routeAxis === "x") {
addBox(
cube,
cube,
cube,
material,
centerX,
GROUND + levels * cube + cube * 0.5,
centerZ + i * sideOffset * 0.5
);
} else {
addBox(
cube,
cube,
cube,
material,
centerX + i * sideOffset * 0.5,
GROUND + levels * cube + cube * 0.5,
centerZ
);
}
}
}
addVoxelArch(-5.70, 2.40, "x", 1.0);
addVoxelArch(-2.55, 3.55, "x", 0.92);
addVoxelArch(-2.55, 1.25, "x", 0.92);
addVoxelArch(-0.45, 4.65, "x", 0.88);
addVoxelArch(5.00, 4.40, "x", 0.92);
// -------------------------------------------------------------------------
// Network data: one connected component plus disconnected test components.
// -------------------------------------------------------------------------
const connectedNodes = [
{ id: "T", x: -7.80, z: 2.40, trigger: true },
{ id: "A", x: -6.75, z: 2.40 },
{ id: "B", x: -5.70, z: 2.40 },
{ id: "C", x: -4.65, z: 2.40 },
{ id: "J", x: -3.60, z: 2.40 },
{ id: "N1", x: -3.60, z: 3.55 },
{ id: "N2", x: -2.55, z: 3.55 },
{ id: "N3", x: -1.50, z: 3.55 },
{ id: "N4", x: -0.45, z: 3.55 },
{ id: "N5", x: 0.60, z: 3.55 },
{ id: "U1", x: -1.50, z: 4.65 },
{ id: "U2", x: -0.45, z: 4.65 },
{ id: "U3", x: 0.60, z: 4.65 },
{ id: "S1", x: -3.60, z: 1.25 },
{ id: "S2", x: -2.55, z: 1.25 },
{ id: "S3", x: -1.50, z: 1.25 },
{ id: "S4", x: -0.45, z: 1.25 },
{ id: "S5", x: 0.60, z: 1.25 },
{ id: "D1", x: -1.50, z: 0.15 },
{ id: "D2", x: -0.45, z: 0.15 },
{ id: "D3", x: 0.60, z: 0.15 }
];
const connectedEdges = [
["T", "A"], ["A", "B"], ["B", "C"], ["C", "J"],
["J", "N1"], ["N1", "N2"], ["N2", "N3"],
["N3", "N4"], ["N4", "N5"],
["N3", "U1"], ["U1", "U2"], ["U2", "U3"],
["J", "S1"], ["S1", "S2"], ["S2", "S3"],
["S3", "S4"], ["S4", "S5"],
["S3", "D1"], ["D1", "D2"], ["D2", "D3"]
];
const isolatedNodes = [
{ id: "I1", x: 4.00, z: 4.40 },
{ id: "I2", x: 5.00, z: 4.40 },
{ id: "I3", x: 6.00, z: 4.40 },
{ id: "I4", x: 7.00, z: 4.40 },
{ id: "I5", x: 4.00, z: -1.50 },
{ id: "I6", x: 5.00, z: -1.50 },
{ id: "I7", x: 6.00, z: -1.50 },
{ id: "I8", x: 6.00, z: -2.60 },
{ id: "I9", x: 7.00, z: -2.60 }
];
const isolatedEdges = [
["I1", "I2"], ["I2", "I3"], ["I3", "I4"],
["I5", "I6"], ["I6", "I7"], ["I7", "I8"], ["I8", "I9"]
];
const nodeById = new Map();
connectedNodes.forEach(node => nodeById.set(node.id, node));
isolatedNodes.forEach(node => nodeById.set(node.id, node));
// Breadth-first traversal identifies the exact connected component of the
// trigger. Every other node is intentionally excluded from propagation.
const adjacency = new Map();
connectedNodes.forEach(node => adjacency.set(node.id, []));
for (const [a, b] of connectedEdges) {
adjacency.get(a).push(b);
adjacency.get(b).push(a);
}
const distances = new Map([["T", 0]]);
const parentMap = new Map();
const queue = ["T"];
for (let index = 0; index < queue.length; index++) {
const id = queue[index];
for (const neighbor of adjacency.get(id)) {
if (!distances.has(neighbor)) {
distances.set(neighbor, distances.get(id) + 1);
parentMap.set(neighbor, id);
queue.push(neighbor);
}
}
}
const childrenMap = new Map();
connectedNodes.forEach(node => childrenMap.set(node.id, []));
for (const [child, parent] of parentMap) {
childrenMap.get(parent).push(child);
}
const STEP_TIME = 0.38;
const FALL_TIME = 0.27;
for (const node of connectedNodes) {
node.schedule = distances.get(node.id) * STEP_TIME;
node.children = childrenMap.get(node.id);
node.parent = parentMap.get(node.id);
let directionX = 0;
let directionZ = 0;
if (node.children.length) {
for (const childId of node.children) {
const child = nodeById.get(childId);
directionX += child.x - node.x;
directionZ += child.z - node.z;
}
} else if (node.parent) {
const parent = nodeById.get(node.parent);
directionX = node.x - parent.x;
directionZ = node.z - parent.z;
} else {
directionX = 1;
}
const length = Math.hypot(directionX, directionZ) || 1;
directionX /= length;
directionZ /= length;
node.directionX = directionX;
node.directionZ = directionZ;
node.yaw = -Math.atan2(directionZ, directionX);
node.accent = node.trigger ? 0xffd66b : 0x78e8ff;
node.accentColor = new THREE.Color(node.accent);
}
// -------------------------------------------------------------------------
// Dominoes and route strips
// -------------------------------------------------------------------------
const triggerHitMeshes = [];
const pulseGeometry = new THREE.BoxGeometry(0.13, 0.13, 0.13);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xbdf7ff,
transparent: true,
opacity: 0.95
});
function createDomino(node, connected) {
const group = new THREE.Group();
group.position.set(node.x, GROUND, node.z);
group.rotation.order = "YXZ";
scene.add(group);
const bodyMaterial = standard(
node.trigger ? 0xfff2c6 : 0xd9e8e9,
{ roughness: 0.65, metalness: 0.03 }
);
const accent = connected
? node.trigger ? 0xffd66b : 0x78e8ff
: 0xff806f;
const capMaterial = standard(accent, {
roughness: 0.55,
emissive: accent,
emissiveIntensity: connected ? 0.16 : 0.1
});
const body = new THREE.Mesh(dominoBodyGeometry, bodyMaterial);
body.position.y = 0.39;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const cap = new THREE.Mesh(dominoCapGeometry, capMaterial);
cap.position.y = 0.89;
cap.castShadow = true;
group.add(cap);
node.group = group;
node.body = body;
node.cap = cap;
if (node.trigger) {
const hit = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 1.2, 0.9),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hit.position.y = 0.6;
group.add(hit);
triggerHitMeshes.push(body, cap, hit);
}
}
connectedNodes.forEach(node => createDomino(node, true));
isolatedNodes.forEach(node => {
node.accentColor = new THREE.Color(0xff806f);
createDomino(node, false);
});
const routeEdges = [];
function createRouteEdge(aId, bId, connected) {
const a = nodeById.get(aId);
const b = nodeById.get(bId);
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const yaw = -Math.atan2(dz, dx);
const channel = addBox(
length,
0.025,
connected ? 0.17 : 0.14,
connected ? materials.connectedChannel : materials.isolatedChannel,
(a.x + b.x) * 0.5,
GROUND + 0.018,
(a.z + b.z) * 0.5
);
channel.rotation.y = yaw;
channel.castShadow = false;
if (connected) {
const parent = parentMap.get(bId) === aId ? aId : bId;
const child = parent === aId ? bId : aId;
const pulse = new THREE.Mesh(pulseGeometry, pulseMaterial);
pulse.visible = false;
scene.add(pulse);
routeEdges.push({
parent,
child,
pulse,
start: nodeById.get(parent).schedule,
end: nodeById.get(child).schedule
});
}
}
connectedEdges.forEach(([a, b]) => createRouteEdge(a, b, true));
isolatedEdges.forEach(([a, b]) => createRouteEdge(a, b, false));
// -------------------------------------------------------------------------
// Trigger halo and branch receivers
// -------------------------------------------------------------------------
const triggerNode = nodeById.get("T");
const halo = new THREE.Group();
halo.position.set(triggerNode.x, GROUND + 0.035, triggerNode.z);
scene.add(halo);
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xffd66b,
transparent: true,
opacity: 0.72
});
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const block = addBox(
0.12,
0.06,
0.12,
haloMaterial,
Math.cos(angle) * 0.58,
0,
Math.sin(angle) * 0.58,
halo
);
block.rotation.y = -angle;
block.castShadow = false;
}
const triggerLight = new THREE.PointLight(0xffc84f, 1.2, 4.5, 2);
triggerLight.position.set(triggerNode.x, 1.2, triggerNode.z);
scene.add(triggerLight);
const terminals = [];
function addTerminal(x, z, endpointId, color = 0x78e8ff) {
addBox(0.56, 0.50, 0.56, materials.terminal, x, GROUND + 0.25, z);
addBox(0.68, 0.09, 0.68, materials.stoneDark, x, GROUND + 0.055, z);
const lampMaterial = standard(0x20313a, {
emissive: color,
emissiveIntensity: 0.03,
roughness: 0.42
});
const lamp = addBox(
0.31,
0.25,
0.31,
lampMaterial,
x,
GROUND + 0.62,
z
);
terminals.push({
lamp,
lampMaterial,
endpointId,
color
});
}
addTerminal(1.35, 3.55, "N5");
addTerminal(1.35, 4.65, "U3");
addTerminal(1.35, 1.25, "S5");
addTerminal(1.35, 0.15, "D3");
// -------------------------------------------------------------------------
// Inlaid floor labels
// -------------------------------------------------------------------------
function addFloorLabel(text, x, z, width, color) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
context.fillStyle = color;
context.font = "700 58px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 512, 68);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
opacity: 0.62,
polygonOffset: true,
polygonOffsetFactor: -1
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width, width / 8),
material
);
label.rotation.x = -Math.PI / 2;
label.position.set(x, GROUND + 0.025, z);
scene.add(label);
}
addFloorLabel("LINKED RELAY", -5.60, 0.45, 3.2, "#78e8ff");
addFloorLabel("SEALED TEST", 5.55, 3.25, 2.7, "#ff806f");
addFloorLabel("NO SIGNAL", 5.65, -0.45, 2.4, "#ff806f");
// -------------------------------------------------------------------------
// Animation state and UI
// -------------------------------------------------------------------------
const ui = {
triggerButton: document.querySelector("#triggerBtn"),
resetButton: document.querySelector("#resetBtn"),
stateText: document.querySelector("#stateText"),
statusDot: document.querySelector("#statusDot"),
progressFill: document.querySelector("#progressFill"),
connectedCount: document.querySelector("#connectedCount"),
isolatedCount: document.querySelector("#isolatedCount")
};
const STEP = 0.38;
const totalTime =
Math.max(...connectedNodes.map(node => node.schedule)) + FALL_TIME + 0.35;
let state = "idle";
let elapsed = 0;
function updateStatusUI() {
const toppled = connectedNodes.filter(
node => elapsed >= node.schedule + FALL_TIME * 0.72
).length;
ui.connectedCount.textContent = `${toppled} / ${connectedNodes.length}`;
ui.isolatedCount.textContent = `${isolatedNodes.length} locked`;
ui.progressFill.style.width = `${Math.min(elapsed / totalTime, 1) * 100}%`;
if (state === "idle") {
ui.stateText.textContent = "Awaiting trigger";
ui.statusDot.style.background = "#ffd66b";
ui.statusDot.style.boxShadow = "0 0 10px rgba(255,214,107,.8)";
} else if (state === "running") {
ui.stateText.textContent = "Propagating";
ui.statusDot.style.background = "#78e8ff";
ui.statusDot.style.boxShadow = "0 0 10px rgba(120,232,255,.9)";
} else {
ui.stateText.textContent = "Network complete";
ui.statusDot.style.background = "#78e8ff";
ui.statusDot.style.boxShadow = "0 0 10px rgba(120,232,255,.9)";
}
}
function resetScene() {
state = "idle";
elapsed = 0;
for (const node of connectedNodes) {
node.group.rotation.set(0, node.yaw, 0);
node.body.material.emissive.set(0x000000);
node.body.material.emissiveIntensity = 0;
node.cap.material.emissiveIntensity = 0.16;
}
for (const node of isolatedNodes) {
node.group.rotation.set(0, 0, 0);
node.body.material.emissive.set(0x000000);
node.body.material.emissiveIntensity = 0;
node.cap.material.emissiveIntensity = 0.1;
}
for (const edge of routeEdges) {
edge.pulse.visible = false;
}
for (const terminal of terminals) {
terminal.lampMaterial.color.setHex(0x20313a);
terminal.lampMaterial.emissiveIntensity = 0.03;
}
halo.visible = true;
haloMaterial.opacity = 0.72;
triggerLight.intensity = 1.2;
ui.triggerButton.disabled = false;
ui.triggerButton.textContent = "Trigger chain";
updateStatusUI();
}
function startChain() {
if (state === "running") return;
if (state === "complete") resetScene();
state = "running";
elapsed = 0;
ui.triggerButton.disabled = true;
ui.triggerButton.textContent = "Propagating";
updateStatusUI();
}
ui.triggerButton.addEventListener("click", startChain);
ui.resetButton.addEventListener("click", resetScene);
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
if (!event.repeat) startChain();
}
if (event.code === "KeyR") {
resetScene();
}
});
// -------------------------------------------------------------------------
// Direct camera controls, without external addons
// -------------------------------------------------------------------------
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.cos(pitch) * Math.sin(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
const viewHeight = aspect < 0.85 ? 18.5 / aspect : 14.8;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const pointer = {
down: false,
moved: false,
x: 0,
y: 0,
pointerId: null
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
canvas.addEventListener("pointerdown", event => {
pointer.down = true;
pointer.moved = false;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.pointerId = event.pointerId;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointer.down) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
if (Math.abs(dx) + Math.abs(dy) > 3) {
pointer.moved = true;
}
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.36,
1.28
);
pointer.x = event.clientX;
pointer.y = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", event => {
if (!pointer.down) return;
const wasClick = !pointer.moved;
pointer.down = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (wasClick) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(triggerHitMeshes, false);
if (hits.length) {
startChain();
}
}
});
canvas.addEventListener("pointercancel", () => {
pointer.down = false;
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.85
);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
canvas.addEventListener("contextmenu", event => event.preventDefault());
// -------------------------------------------------------------------------
// Main animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateDominoes() {
for (const node of connectedNodes) {
const hasFallen = elapsed >= node.schedule;
const fallProgress = hasFallen
? THREE.MathUtils.clamp(
(elapsed - node.schedule) / FALL_TIME,
0,
1
)
: 0;
const eased = fallProgress * fallProgress * (3 - 2 * fallProgress);
node.group.rotation.y = node.yaw;
node.group.rotation.z = -eased * Math.PI * 0.5;
const flash = hasFallen
? Math.max(0, 1 - (elapsed - node.schedule) / 0.48)
: 0;
node.body.material.emissive.copy(node.accentColor);
node.body.material.emissiveIntensity = flash * 0.75;
node.cap.material.emissiveIntensity = 0.16 + flash * 1.1;
}
// Isolated nodes are deliberately never scheduled, so they stay upright.
for (const node of isolatedNodes) {
node.group.rotation.set(0, 0, 0);
}
}
function updatePulses() {
for (const edge of routeEdges) {
if (elapsed >= edge.start && elapsed <= edge.end) {
const t = (elapsed - edge.start) / (edge.end - edge.start);
const parent = nodeById.get(edge.parent);
const child = nodeById.get(edge.child);
edge.pulse.visible = true;
edge.pulse.position.set(
THREE.MathUtils.lerp(parent.x, child.x, t),
GROUND + 0.19,
THREE.MathUtils.lerp(parent.z, child.z, t)
);
const pulse = 1 + Math.sin(t * Math.PI) * 0.65;
edge.pulse.scale.setScalar(pulse);
} else {
edge.pulse.visible = false;
}
}
}
function updateTerminals() {
for (const terminal of terminals) {
const endpoint = nodeById.get(terminal.endpointId);
const active = elapsed >= endpoint.schedule + FALL_TIME * 0.74;
terminal.lampMaterial.color.setHex(active ? terminal.color : 0x20313a);
terminal.lampMaterial.emissiveIntensity = active ? 1.8 : 0.03;
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state === "running") {
elapsed = Math.min(elapsed + delta, totalTime);
if (elapsed >= totalTime) {
state = "complete";
ui.triggerButton.disabled = false;
ui.triggerButton.textContent = "Run again";
}
}
updateDominoes();
updatePulses();
updateTerminals();
if (state === "idle") {
const pulse = 0.5 + 0.5 * Math.sin(clock.elapsedTime * 3.2);
halo.scale.setScalar(1 + pulse * 0.12);
haloMaterial.opacity = 0.38 + pulse * 0.38;
triggerLight.intensity = 0.75 + pulse * 0.85;
} else {
halo.rotation.y += delta * 0.8;
haloMaterial.opacity = Math.max(0, haloMaterial.opacity - delta * 1.8);
triggerLight.intensity = Math.max(0, triggerLight.intensity - delta * 2.5);
if (haloMaterial.opacity <= 0.01) halo.visible = false;
}
updateStatusUI();
renderer.render(scene, camera);
}
resetScene();
animate();
</script>
</body>
</html>
```