Prompt specification
Build or customize the Three.js 3D scene "Wave Markers Through a Schematic Root Field" 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: Wave Markers Through a Schematic Root Field
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wave-markers-through-a-schematic-root-field-x3922
Scene Description Prompt:
Wave markers weaken through a voxel mangrove-root field under an explicitly illustrative rule. Three.js from cdnjs, one HTML file.
Working Three.js Starter (wave-markers-through-a-schematic-root-field-x3922):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Mangrove Wave Attenuation</title>
<style>
:root {
color-scheme: dark;
--ink: #d9f7f3;
--muted: #8eafb0;
--cyan: #59f3df;
--coral: #ff8064;
--panel: rgba(5, 20, 28, 0.82);
--line: rgba(117, 226, 214, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #06131d;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100vw;
height: 100vh;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 42%, rgba(1, 8, 13, 0.48) 100%),
linear-gradient(180deg, rgba(3, 13, 21, 0.1), rgba(3, 13, 21, 0.3));
z-index: 1;
}
.ui {
position: fixed;
z-index: 2;
pointer-events: none;
}
.ui button,
.ui input,
.panel {
pointer-events: auto;
}
header {
top: 24px;
left: 26px;
max-width: 530px;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 6px;
font-size: clamp(24px, 3vw, 39px);
line-height: 1.02;
letter-spacing: -0.035em;
font-weight: 620;
text-shadow: 0 2px 25px rgba(0, 0, 0, 0.45);
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
max-width: 480px;
}
.panel {
top: 22px;
right: 22px;
width: 286px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
color: #bce5e1;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: #77aaa8;
letter-spacing: 0.08em;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
}
.control {
margin: 0 0 15px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
color: #c3dedc;
font-size: 12px;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-size: 11px;
}
input[type="range"] {
width: 100%;
height: 3px;
margin: 0;
border-radius: 4px;
appearance: none;
background: linear-gradient(90deg, #327a77, #59f3df);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #092029;
border-radius: 50%;
appearance: none;
background: #d8fff9;
box-shadow: 0 0 0 1px rgba(89, 243, 223, 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #092029;
border-radius: 50%;
background: #d8fff9;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
button {
min-height: 34px;
border: 1px solid rgba(111, 219, 207, 0.22);
border-radius: 8px;
background: rgba(27, 73, 78, 0.46);
color: #cbe9e6;
font: inherit;
font-size: 11px;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
button:hover {
border-color: rgba(89, 243, 223, 0.55);
background: rgba(42, 106, 105, 0.62);
}
button:active { transform: translateY(1px); }
.metric {
display: flex;
align-items: flex-end;
justify-content: space-between;
margin-top: 17px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.metric span {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
color: var(--cyan);
font-size: 22px;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.legend {
margin-top: 15px;
}
.legend-bar {
height: 5px;
border-radius: 6px;
background: linear-gradient(90deg, var(--coral), #f4d06d 48%, var(--cyan));
box-shadow: 0 0 14px rgba(89, 243, 223, 0.12);
}
.legend-labels {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #789c9d;
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.rule {
left: 24px;
bottom: 24px;
width: min(530px, calc(100vw - 48px));
padding: 15px 17px;
border: 1px solid var(--line);
border-left: 2px solid var(--cyan);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
}
.rule-title {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.formula {
display: inline-block;
margin-right: 8px;
color: #f0fffc;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
}
.rule p {
display: inline;
margin: 0;
color: #9db8b8;
font-size: 11px;
line-height: 1.6;
}
.hint {
right: 24px;
bottom: 25px;
color: rgba(173, 207, 205, 0.58);
font-size: 10px;
letter-spacing: 0.04em;
text-align: right;
}
@media (max-width: 760px) {
header {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
h1 { font-size: 25px; }
.subtitle { max-width: 360px; font-size: 11px; }
.panel {
top: auto;
right: 14px;
bottom: 157px;
width: 230px;
padding: 12px;
}
.rule {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 12px 13px;
}
.hint { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel mangrove-root wave attenuation visualization"></canvas>
<div class="vignette"></div>
<header class="ui">
<div class="eyebrow">Illustrative field study / 01</div>
<h1>Wave markers through<br>voxel mangrove roots</h1>
<p class="subtitle">
Moving markers lose strength whenever they enter an occupied root voxel
on the same lane. Bright cyan means stronger; coral means weaker.
</p>
</header>
<section class="panel ui" aria-label="Visualization controls">
<div class="panel-title">
<span>Field controls</span>
<span class="live" id="liveState">running</span>
</div>
<div class="control">
<div class="control-row">
<label for="absorption">Illustrative absorption, a</label>
<output id="absorptionValue" for="absorption">0.32</output>
</div>
<input id="absorption" type="range" min="0" max="0.8" step="0.01" value="0.32">
</div>
<div class="control">
<div class="control-row">
<label for="speed">Marker speed</label>
<output id="speedValue" for="speed">2.8 u/s</output>
</div>
<input id="speed" type="range" min="0.4" max="6" step="0.1" value="2.8">
</div>
<div class="buttons">
<button id="pause" type="button">Pause</button>
<button id="resetWaves" type="button">Reset waves</button>
<button id="resetCamera" type="button">Reset camera</button>
<button id="toggleWater" type="button">Hide water</button>
</div>
<div class="metric">
<span>Median survival<br>after root field</span>
<strong id="survival">—</strong>
</div>
<div class="legend" aria-label="Wave marker strength color legend">
<div class="legend-bar"></div>
<div class="legend-labels">
<span>Weak / 0</span>
<span>Marker strength S</span>
<span>Strong / 1</span>
</div>
</div>
</section>
<aside class="rule ui">
<div class="rule-title">Explicitly illustrative rule — not a hydrodynamic model</div>
<p>
<span class="formula">S ← S · (1 − aρ)</span>
On entering each occupied root voxel on its lane, a marker is multiplied by
<span class="formula">1 − aρ</span>, where ρ is the voxel's displayed density.
There is no reflection, refraction, diffraction, branching, or geometric spreading.
Markers reset to S = 1 when they re-enter the source.
</p>
</aside>
<div class="hint ui">Drag to orbit · Shift/right-drag to pan · Wheel to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const absorptionInput = document.querySelector("#absorption");
const absorptionValue = document.querySelector("#absorptionValue");
const speedInput = document.querySelector("#speed");
const speedValue = document.querySelector("#speedValue");
const survivalValue = document.querySelector("#survival");
const pauseButton = document.querySelector("#pause");
const resetWavesButton = document.querySelector("#resetWaves");
const resetCameraButton = document.querySelector("#resetCamera");
const toggleWaterButton = document.querySelector("#toggleWater");
const liveState = document.querySelector("#liveState");
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06131d);
scene.fog = new THREE.FogExp2(0x06131d, 0.022);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
120
);
// Custom camera controls: no controls addon is used.
const cameraState = {
theta: 0.32,
phi: 1.03,
radius: 25,
target: new THREE.Vector3(0, 0.25, 0)
};
const desiredCamera = {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
};
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
desiredCamera.theta = 0.32;
desiredCamera.phi = 1.03;
desiredCamera.radius = 25;
desiredCamera.target.set(0, 0.25, 0);
}
let pointerDrag = null;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointerDrag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
mode: event.button === 2 || event.shiftKey ? "pan" : "orbit"
};
});
canvas.addEventListener("pointermove", event => {
if (!pointerDrag || event.pointerId !== pointerDrag.id) return;
const dx = event.clientX - pointerDrag.x;
const dy = event.clientY - pointerDrag.y;
pointerDrag.x = event.clientX;
pointerDrag.y = event.clientY;
if (pointerDrag.mode === "orbit") {
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.25,
1.46
);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = desiredCamera.radius * 0.00145;
desiredCamera.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
desiredCamera.target.x = THREE.MathUtils.clamp(
desiredCamera.target.x, -9, 9
);
desiredCamera.target.y = THREE.MathUtils.clamp(
desiredCamera.target.y, -0.5, 2
);
desiredCamera.target.z = THREE.MathUtils.clamp(
desiredCamera.target.z, -6, 6
);
}
});
function endPointer(event) {
if (pointerDrag && event.pointerId === pointerDrag.id) {
pointerDrag = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
10,
43
);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
resetCameraButton.addEventListener("click", resetCamera);
// Lighting.
scene.add(new THREE.HemisphereLight(0x8fd8e2, 0x173027, 1.55));
const sun = new THREE.DirectionalLight(0xffd3a2, 3.1);
sun.position.set(-8, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x4cc9ff, 1.7);
rim.position.set(10, 6, -12);
scene.add(rim);
// Ground and custom grid.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(38, 20),
new THREE.MeshStandardMaterial({
color: 0x071c24,
roughness: 0.94,
metalness: 0.04
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.3;
ground.receiveShadow = true;
scene.add(ground);
const gridPositions = [];
for (let x = -18; x <= 18; x += 1) {
gridPositions.push(x, -1.285, -9, x, -1.285, 9);
}
for (let z = -9; z <= 9; z += 1) {
gridPositions.push(-18, -1.285, z, 18, -1.285, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
scene.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x4c9998,
transparent: true,
opacity: 0.12
})
));
// Water is only a visual layer; it does not affect the rule.
const water = new THREE.Mesh(
new THREE.PlaneGeometry(35, 16),
new THREE.MeshPhysicalMaterial({
color: 0x0d6972,
transparent: true,
opacity: 0.2,
roughness: 0.26,
metalness: 0.08,
depthWrite: false,
side: THREE.DoubleSide
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.01;
water.renderOrder = 2;
scene.add(water);
toggleWaterButton.addEventListener("click", () => {
water.visible = !water.visible;
toggleWaterButton.textContent = water.visible ? "Hide water" : "Show water";
});
const SOURCE_X = -12.4;
const EXIT_X = 12.4;
const TRAVEL_LENGTH = EXIT_X - SOURCE_X;
// Deterministic voxel-root field.
const CELL = 0.72;
const COLS = 19;
const ROWS = 9;
const FIELD_START_X = -5.4;
const LANE_Z = Array.from(
{ length: ROWS },
(_, index) => (index - (ROWS - 1) / 2) * 0.82
);
const clusters = [
{ x: -3.8, z: -2.45, rx: 2.2, rz: 1.8 },
{ x: -2.1, z: -0.30, rx: 1.8, rz: 1.6 },
{ x: 0.7, z: 1.80, rx: 2.3, rz: 1.8 },
{ x: 2.4, z: -0.80, rx: 1.7, rz: 1.4 },
{ x: 5.4, z: -2.00, rx: 1.8, rz: 1.6 },
{ x: 5.0, z: 2.60, rx: 1.8, rz: 1.7 }
];
function fract(value) {
return value - Math.floor(value);
}
const roots = [];
const rootsByLane = Array.from({ length: ROWS }, () => []);
for (let ix = 0; ix < COLS; ix++) {
const x = FIELD_START_X + ix * CELL;
for (let iz = 0; iz < ROWS; iz++) {
const z = LANE_Z[iz];
const hashA = fract(Math.sin(ix * 127.1 + iz * 311.7) * 43758.5453);
const hashB = fract(Math.sin((ix + 1) * 269.5 + (iz + 1) * 183.3) * 24634.6345);
let clusterWeight = 0;
for (const cluster of clusters) {
const dx = (x - cluster.x) / cluster.rx;
const dz = (z - cluster.z) / cluster.rz;
clusterWeight = Math.max(
clusterWeight,
Math.exp(-1.15 * (dx * dx + dz * dz))
);
}
const rawDensity = THREE.MathUtils.clamp(
0.08 + clusterWeight * 0.78 + (hashA - 0.5) * 0.18,
0.08,
1
);
const occupied = rawDensity > 0.28 + hashB * 0.13;
if (!occupied) continue;
const density = THREE.MathUtils.clamp(
Math.max(0.35, rawDensity),
0.35,
1
);
const root = {
x,
z,
lane: iz,
density,
entryX: x - CELL * 0.5,
stemHeight: 1.55 * (0.72 + hashA * 0.48)
};
roots.push(root);
rootsByLane[iz].push(root);
}
}
const rootGroup = new THREE.Group();
scene.add(rootGroup);
const rootTopGeometry = new THREE.BoxGeometry(CELL * 0.82, 0.62, CELL * 0.82);
const rootStemGeometry = new THREE.BoxGeometry(CELL * 0.22, 1.55, CELL * 0.22);
const rootTopMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.04
});
const rootStemMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
metalness: 0.02
});
const rootTops = new THREE.InstancedMesh(
rootTopGeometry,
rootTopMaterial,
roots.length
);
const rootStems = new THREE.InstancedMesh(
rootStemGeometry,
rootStemMaterial,
roots.length
);
rootTops.castShadow = true;
rootTops.receiveShadow = true;
rootStems.castShadow = true;
rootStems.receiveShadow = true;
const dummy = new THREE.Object3D();
const earthColor = new THREE.Color(0x633826);
const mossColor = new THREE.Color(0x368b73);
roots.forEach((root, index) => {
dummy.position.set(root.x, 0.25, root.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
rootTops.setMatrixAt(index, dummy.matrix);
const topColor = earthColor.clone().lerp(
mossColor,
Math.min(0.68, root.density * 0.48)
);
topColor.multiplyScalar(0.78 + root.density * 0.24);
rootTops.setColorAt(index, topColor);
const stemHeight = root.stemHeight;
dummy.position.set(root.x, -1.28 + stemHeight / 2, root.z);
dummy.scale.set(1, stemHeight / 1.55, 1);
dummy.updateMatrix();
rootStems.setMatrixAt(index, dummy.matrix);
rootStems.setColorAt(index, topColor.clone().multiplyScalar(0.48));
});
rootTops.instanceMatrix.needsUpdate = true;
rootStems.instanceMatrix.needsUpdate = true;
rootTops.instanceColor.needsUpdate = true;
rootStems.instanceColor.needsUpdate = true;
rootGroup.add(rootStems, rootTops);
// A faint occupancy underlay communicates the voxel grid.
const tileGeometry = new THREE.PlaneGeometry(CELL * 0.91, CELL * 0.91);
const tileMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.15,
depthWrite: false
});
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, roots.length);
roots.forEach((root, index) => {
dummy.position.set(root.x, -1.275, root.z);
dummy.rotation.set(-Math.PI / 2, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
const tileColor = new THREE.Color(0x275d57).lerp(
new THREE.Color(0x59f3df),
root.density * 0.48
);
tiles.setColorAt(index, tileColor);
});
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
rootGroup.add(tiles);
// Field boundary.
const fieldMinX = FIELD_START_X - CELL / 2;
const fieldMaxX = FIELD_START_X + (COLS - 1) * CELL + CELL / 2;
const fieldMinZ = LANE_Z[0] - 0.42;
const fieldMaxZ = LANE_Z[ROWS - 1] + 0.42;
const boundaryGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(fieldMinX, 0.59, fieldMinZ),
new THREE.Vector3(fieldMaxX, 0.59, fieldMinZ),
new THREE.Vector3(fieldMaxX, 0.59, fieldMaxZ),
new THREE.Vector3(fieldMinX, 0.59, fieldMaxZ),
new THREE.Vector3(fieldMinX, 0.59, fieldMinZ)
]);
rootGroup.add(new THREE.Line(
boundaryGeometry,
new THREE.LineBasicMaterial({
color: 0x59f3df,
transparent: true,
opacity: 0.28
})
));
// Faint lanes make marker paths legible.
for (const z of LANE_Z) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(SOURCE_X, -0.03, z),
new THREE.Vector3(EXIT_X, -0.03, z)
]);
scene.add(new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x59f3df,
transparent: true,
opacity: 0.075
})
));
}
// Direction arrows.
const arrowGeometry = new THREE.ConeGeometry(0.11, 0.33, 3);
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x59f3df,
transparent: true,
opacity: 0.3
});
for (let x = -10; x <= 10; x += 2.2) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.position.set(x, -1.15, -6.1);
arrow.rotation.z = -Math.PI / 2;
scene.add(arrow);
}
// Source and exit beacons.
function makeBeacon(x, color) {
const group = new THREE.Group();
group.position.x = x;
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.032, 8, 40),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85
})
);
ring.rotation.y = Math.PI / 2;
ring.position.y = 0.27;
const core = new THREE.Mesh(
new THREE.OctahedronGeometry(0.17, 0),
new THREE.MeshBasicMaterial({ color })
);
core.position.y = 0.27;
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.055, 1.55, 8),
new THREE.MeshStandardMaterial({
color: 0x24434a,
roughness: 0.7
})
);
post.position.y = -0.48;
group.add(post, ring, core);
scene.add(group);
return { group, ring, core };
}
const sourceBeacon = makeBeacon(SOURCE_X, 0x59f3df);
const exitBeacon = makeBeacon(EXIT_X, 0xffb36e);
// Canvas-generated labels.
function makeTextSprite(text, color = "#a9e9e1") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.font = "700 42px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.shadowColor = color;
context.shadowBlur = 13;
context.fillStyle = color;
context.fillText(text, 256, 64);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(4.1, 1.025, 1);
sprite.renderOrder = 12;
scene.add(sprite);
return sprite;
}
const sourceLabel = makeTextSprite("SOURCE");
sourceLabel.position.set(SOURCE_X, 2.05, 0);
const fieldLabel = makeTextSprite("VOXEL ROOT FIELD");
fieldLabel.position.set(1.0, 3.25, 0);
const exitLabel = makeTextSprite("EXIT", "#ffc18b");
exitLabel.position.set(EXIT_X, 2.05, 0);
// Soft halo texture for wave markers.
const haloCanvas = document.createElement("canvas");
haloCanvas.width = 128;
haloCanvas.height = 128;
const haloContext = haloCanvas.getContext("2d");
const haloGradient = haloContext.createRadialGradient(
64, 64, 0,
64, 64, 64
);
haloGradient.addColorStop(0, "rgba(255,255,255,1)");
haloGradient.addColorStop(0.16, "rgba(255,255,255,.72)");
haloGradient.addColorStop(0.48, "rgba(255,255,255,.18)");
haloGradient.addColorStop(1, "rgba(255,255,255,0)");
haloContext.fillStyle = haloGradient;
haloContext.fillRect(0, 0, 128, 128);
const haloTexture = new THREE.CanvasTexture(haloCanvas);
haloTexture.colorSpace = THREE.SRGBColorSpace;
const markerGeometry = new THREE.OctahedronGeometry(0.14, 0);
const markerRingGeometry = new THREE.TorusGeometry(0.27, 0.022, 6, 24);
const markers = [];
const phases = [0, 0.2, 0.4, 0.6, 0.8];
const strongColor = new THREE.Color(0x59f3df);
const weakColor = new THREE.Color(0xff8064);
for (let lane = 0; lane < ROWS; lane++) {
for (const phase of phases) {
const group = new THREE.Group();
const orb = new THREE.Mesh(
markerGeometry,
new THREE.MeshBasicMaterial({
color: strongColor,
transparent: true,
opacity: 1,
depthWrite: false
})
);
const ring = new THREE.Mesh(
markerRingGeometry,
new THREE.MeshBasicMaterial({
color: strongColor,
transparent: true,
opacity: 0.8,
depthWrite: false,
depthTest: false,
blending: THREE.AdditiveBlending
})
);
ring.rotation.y = Math.PI / 2;
ring.renderOrder = 5;
const halo = new THREE.Sprite(new THREE.SpriteMaterial({
map: haloTexture,
color: strongColor,
transparent: true,
opacity: 0.8,
depthWrite: false,
depthTest: false,
blending: THREE.AdditiveBlending
}));
halo.scale.set(1.05, 1.05, 1);
halo.renderOrder = 4;
group.add(halo, ring, orb);
group.position.y = 0.27;
group.position.z = LANE_Z[lane];
scene.add(group);
markers.push({ group, orb, ring, halo, lane, phase });
}
}
let absorption = Number(absorptionInput.value);
let speed = Number(speedInput.value);
let simulationTime = 0;
let paused = false;
function markerStrength(lane, x) {
let strength = 1;
for (const root of rootsByLane[lane]) {
if (x >= root.entryX) {
strength *= Math.max(0, 1 - absorption * root.density);
}
}
return THREE.MathUtils.clamp(strength, 0, 1);
}
function updateSurvivalReadout() {
const values = rootsByLane.map(lane => {
let strength = 1;
for (const root of lane) {
strength *= Math.max(0, 1 - absorption * root.density);
}
return strength;
}).sort((a, b) => a - b);
const middle = Math.floor(values.length / 2);
const median = values.length % 2
? values[middle]
: (values[middle - 1] + values[middle]) / 2;
survivalValue.textContent = `${Math.round(median * 100)}%`;
}
absorptionInput.addEventListener("input", () => {
absorption = Number(absorptionInput.value);
absorptionValue.textContent = absorption.toFixed(2);
updateSurvivalReadout();
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
speedValue.textContent = `${speed.toFixed(1)} u/s`;
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
liveState.textContent = paused ? "paused" : "running";
liveState.style.color = paused ? "#ffb16e" : "";
});
resetWavesButton.addEventListener("click", () => {
simulationTime = 0;
});
updateSurvivalReadout();
applyCamera();
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (!paused) {
simulationTime += delta;
}
// Damped custom camera controls.
cameraState.theta += (desiredCamera.theta - cameraState.theta) * 0.12;
cameraState.phi += (desiredCamera.phi - cameraState.phi) * 0.12;
cameraState.radius += (desiredCamera.radius - cameraState.radius) * 0.12;
cameraState.target.lerp(desiredCamera.target, 0.12);
applyCamera();
for (const marker of markers) {
const progress = (
simulationTime * speed / TRAVEL_LENGTH + marker.phase
) % 1;
const x = SOURCE_X + progress * TRAVEL_LENGTH;
const strength = markerStrength(marker.lane, x);
const colorMix = Math.pow(strength, 0.68);
const pulse = 0.95 + Math.sin(
simulationTime * 5.5 + marker.phase * Math.PI * 2
) * 0.05;
marker.group.position.x = x;
marker.group.scale.setScalar((0.72 + strength * 0.46) * pulse);
marker.orb.material.color.copy(weakColor).lerp(strongColor, colorMix);
marker.orb.material.opacity = 0.32 + strength * 0.68;
marker.orb.rotation.y = simulationTime * 1.4 + marker.phase * 4;
marker.orb.rotation.x = simulationTime * 0.8;
marker.ring.material.color.copy(weakColor).lerp(strongColor, colorMix);
marker.ring.material.opacity = 0.08 + strength * 0.68;
marker.ring.scale.setScalar(0.9 + Math.sin(
simulationTime * 4 + marker.phase * 5
) * 0.08);
marker.halo.material.color.copy(weakColor).lerp(strongColor, colorMix);
marker.halo.material.opacity = 0.08 + Math.pow(strength, 1.45) * 0.62;
}
const beaconPulse = 1 + Math.sin(simulationTime * 3.1) * 0.08;
sourceBeacon.ring.scale.setScalar(beaconPulse);
sourceBeacon.core.rotation.y = simulationTime * 1.2;
exitBeacon.ring.scale.setScalar(1.02 - Math.sin(simulationTime * 2.2) * 0.04);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```