Prompt specification
Build or customize the Three.js 3D scene "Stream stone microbial community scene" 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: Stream stone microbial community scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/stream-stone-microbial-community-scene-x0807
Scene Description Prompt:
Stream stone microbial community scene. Compose a shallow stream, pebbles, light gradient, and enlarged biofilm inset; connect location and resource availability conceptually without inventing precise microbial composition. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (stream-stone-microbial-community-scene-x0807):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Stream Stone Microbial Community</title>
<style>
:root {
--ink: #173b35;
--muted: #55736b;
--panel: rgba(250, 253, 246, 0.88);
--line: rgba(31, 80, 67, 0.16);
--lime: #b8ce62;
--gold: #e7ad3c;
--aqua: #5abfc3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(
circle at 15% 7%,
rgba(255, 249, 207, 0.98) 0,
rgba(255, 244, 187, 0.46) 22%,
transparent 48%
),
radial-gradient(
circle at 83% 73%,
rgba(115, 204, 181, 0.42),
transparent 42%
),
linear-gradient(145deg, #edf4e8 0%, #cce3d8 48%, #9fc9c0 100%);
}
button {
font: inherit;
}
#main-canvas,
#connector-layer {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#main-canvas canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#main-canvas canvas.dragging {
cursor: grabbing;
}
#connector-layer {
z-index: 4;
pointer-events: none;
}
.panel {
position: fixed;
z-index: 8;
border: 1px solid var(--line);
background: var(--panel);
box-shadow:
0 20px 60px rgba(27, 73, 61, 0.12),
inset 0 1px 0 rgba(255, 255, 255, 0.72);
backdrop-filter: blur(16px) saturate(1.08);
-webkit-backdrop-filter: blur(16px) saturate(1.08);
}
#intro {
top: 24px;
left: 24px;
width: min(350px, calc(100vw - 48px));
padding: 22px;
border-radius: 20px;
}
.eyebrow,
.inset-kicker {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: #4c7165;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before,
.inset-kicker::before {
width: 8px;
height: 8px;
content: "";
background: var(--lime);
box-shadow: 0 0 0 4px rgba(184, 206, 98, 0.18);
}
h1,
h2,
p {
margin: 0;
}
h1 {
max-width: 290px;
font-size: clamp(1.8rem, 3vw, 2.65rem);
line-height: 0.98;
letter-spacing: -0.055em;
}
#intro > p {
margin-top: 14px;
color: var(--muted);
font-size: 0.9rem;
line-height: 1.55;
}
.concept-note {
margin-top: 16px !important;
padding: 12px 13px;
border-left: 3px solid var(--gold);
border-radius: 0 9px 9px 0;
background: rgba(240, 196, 91, 0.12);
color: #5b5a40 !important;
font-size: 0.76rem !important;
}
.controls {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 16px;
}
.control-hint {
color: #678078;
font-size: 0.72rem;
line-height: 1.35;
}
#reset-view {
flex: 0 0 auto;
padding: 9px 12px;
border: 1px solid rgba(39, 92, 77, 0.2);
border-radius: 10px;
color: var(--ink);
background: rgba(255, 255, 255, 0.58);
cursor: pointer;
font-size: 0.73rem;
font-weight: 750;
transition:
background 160ms ease,
transform 160ms ease;
}
#reset-view:hover {
background: rgba(255, 255, 255, 0.95);
transform: translateY(-1px);
}
#inset-card {
top: 24px;
right: 24px;
width: min(350px, calc(100vw - 48px));
padding: 18px;
border-radius: 20px;
}
#inset-stage {
position: relative;
height: 245px;
margin: 13px 0;
overflow: hidden;
border: 1px solid rgba(28, 86, 71, 0.15);
border-radius: 14px;
background:
radial-gradient(
circle at 23% 8%,
rgba(255, 248, 188, 0.84),
rgba(255, 248, 188, 0.15) 35%,
transparent 62%
),
linear-gradient(155deg, #dcefdc 0%, #9fd1c6 54%, #6fa9a4 100%);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
#inset-stage canvas {
display: block;
width: 100%;
height: 100%;
}
.inset-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.inset-title h2 {
max-width: 250px;
font-size: 1.1rem;
line-height: 1.08;
letter-spacing: -0.025em;
}
.zoom-badge {
flex: 0 0 auto;
padding: 6px 8px;
border-radius: 8px;
color: #365d50;
background: rgba(104, 151, 126, 0.13);
font-size: 0.61rem;
font-weight: 850;
letter-spacing: 0.1em;
}
.inset-caption {
margin-top: 7px !important;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.45;
}
.stage-label {
position: absolute;
z-index: 2;
padding: 5px 7px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 7px;
color: #355d52;
background: rgba(250, 255, 246, 0.66);
backdrop-filter: blur(5px);
font-size: 0.58rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.stage-label.light {
top: 10px;
left: 10px;
}
.stage-label.resource {
right: 9px;
bottom: 9px;
color: #78541e;
background: rgba(255, 242, 199, 0.74);
}
.resource-meter {
padding-top: 12px;
border-top: 1px solid var(--line);
}
.resource-meter-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
font-size: 0.68rem;
font-weight: 750;
}
.resource-meter-head span:last-child {
color: var(--muted);
font-weight: 600;
}
.resource-gradient {
position: relative;
height: 9px;
margin-top: 8px;
overflow: hidden;
border-radius: 20px;
background: linear-gradient(
90deg,
#91b2ac 0%,
#b9c982 37%,
#e4c45c 70%,
#ee9f3d 100%
);
}
.resource-gradient::after {
position: absolute;
inset: 0;
content: "";
background:
radial-gradient(circle, rgba(255,255,255,.65) 0 1px, transparent 1.6px)
0 0 / 15px 9px;
opacity: 0.55;
}
.inset-note {
margin-top: 9px !important;
color: #6c7668 !important;
font-size: 0.66rem !important;
line-height: 1.4 !important;
}
#legend {
position: fixed;
z-index: 7;
bottom: 24px;
left: 24px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(248, 252, 244, 0.82);
box-shadow: 0 12px 36px rgba(28, 69, 58, 0.09);
backdrop-filter: blur(12px);
}
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 11px 15px;
align-items: center;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #45645b;
font-size: 0.66rem;
font-weight: 650;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow:
inset -2px -2px 0 rgba(0, 0, 0, 0.08),
0 1px 2px rgba(0, 0, 0, 0.12);
}
.swatch.water {
background: #56b9c0;
}
.swatch.shallow {
background: #a7ded0;
}
.swatch.biofilm {
background: #a9c653;
}
.swatch.resource {
background: #e8ac3c;
}
.legend-note {
margin-top: 7px;
color: #748078;
font-size: 0.59rem;
}
#scene-labels {
position: fixed;
z-index: 5;
inset: 0;
pointer-events: none;
}
.scene-label {
position: absolute;
transform: translate(-50%, -100%);
white-space: nowrap;
text-align: center;
transition: opacity 120ms ease;
}
.scene-label .label-main {
display: inline-block;
padding: 6px 9px;
border: 1px solid rgba(42, 84, 69, 0.18);
border-radius: 8px;
color: #284f43;
background: rgba(250, 253, 246, 0.9);
box-shadow: 0 7px 20px rgba(28, 66, 57, 0.12);
backdrop-filter: blur(8px);
font-size: 0.63rem;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.scene-label.source .label-main {
color: #6b4a13;
border-color: rgba(218, 158, 45, 0.35);
background: rgba(255, 247, 215, 0.94);
}
.scene-label .label-sub {
margin-top: 4px;
color: #557168;
font-size: 0.59rem;
font-weight: 650;
text-shadow: 0 1px 5px rgba(255, 255, 255, 0.9);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: #45675d;
background: #e8f1e4;
font-size: 0.8rem;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 920px) {
#intro {
width: 300px;
}
#inset-card {
width: 305px;
}
#inset-stage {
height: 195px;
}
#legend {
display: none;
}
}
@media (max-width: 660px) {
#intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 15px;
}
#intro h1 {
max-width: none;
font-size: 1.55rem;
}
#intro > p:not(.concept-note),
.control-hint {
display: none;
}
.concept-note {
margin-top: 10px !important;
padding: 8px 10px;
font-size: 0.66rem !important;
}
.controls {
margin-top: 9px;
}
#inset-card {
top: auto;
right: 10px;
bottom: 10px;
width: min(270px, calc(100vw - 20px));
padding: 12px;
}
#inset-stage {
height: 135px;
margin: 8px 0;
}
.inset-title h2 {
font-size: 0.9rem;
}
.inset-caption,
.inset-note {
display: none !important;
}
.stage-label {
font-size: 0.49rem;
}
#connector-layer {
display: none;
}
}
</style>
</head>
<body>
<div id="main-canvas" aria-label="Interactive three-dimensional voxel stream scene"></div>
<svg id="connector-layer" aria-hidden="true">
<defs>
<filter id="connector-glow" x="-30%" y="-30%" width="160%" height="160%">
<feGaussianBlur stdDeviation="2.2" result="blur" />
<feMerge>
<feMergeNode in="blur" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
<path
id="connector-path"
fill="none"
stroke="#d89a2f"
stroke-width="1.6"
stroke-linecap="round"
stroke-dasharray="5 7"
opacity="0.85"
filter="url(#connector-glow)"
/>
<circle id="source-dot" r="4" fill="#e5a936" />
<circle id="inset-dot" r="4" fill="#e5a936" />
</svg>
<div id="scene-labels">
<div id="source-label" class="scene-label source">
<div class="label-main">Biofilm location</div>
<div class="label-sub">shallow, illuminated margin</div>
</div>
<div id="flow-label" class="scene-label">
<div class="label-main">Flow direction</div>
</div>
</div>
<section id="intro" class="panel">
<div class="eyebrow">Conceptual voxel landscape</div>
<h1>Stream stone microbial community</h1>
<p>
A shallow stream, mineral pebbles and attached surface growth. The
highlighted location is enlarged to connect its setting with a relative
light and resource cue.
</p>
<p class="concept-note">
Schematic only: no taxa, abundances, or measured concentrations are
implied. Brightness and amber voxels indicate relative conditions, not
microbial composition.
</p>
<div class="controls">
<div class="control-hint">Drag to orbit<br />Scroll to zoom</div>
<button id="reset-view" type="button">Reset view</button>
</div>
</section>
<section id="inset-card" class="panel">
<div class="inset-kicker">Enlarged location</div>
<div class="inset-title">
<h2>Biofilm on the stone surface</h2>
<div class="zoom-badge">MAGNIFIED</div>
</div>
<p class="inset-caption">
A schematic enlargement of the highlighted stream-margin patch.
</p>
<div id="inset-stage">
<div class="stage-label light">Relative light</div>
<div class="stage-label resource">Resource cue</div>
</div>
<div class="resource-meter">
<div class="resource-meter-head">
<span>Relative resource availability</span>
<span>conceptual, not measured</span>
</div>
<div class="resource-gradient"></div>
</div>
<p class="inset-note">
Amber cubes are a visual availability cue near the illuminated margin.
They do not represent measured particles or a named microbial group.
</p>
</section>
<aside id="legend" aria-label="Scene legend">
<div class="legend-row">
<div class="legend-item">
<span class="swatch water"></span>
Deeper water cue
</div>
<div class="legend-item">
<span class="swatch shallow"></span>
Brighter shallow edge
</div>
<div class="legend-item">
<span class="swatch biofilm"></span>
Biofilm cue
</div>
<div class="legend-item">
<span class="swatch resource"></span>
Relative resource cue
</div>
</div>
<div class="legend-note">Voxel scale and color gradients are illustrative.</div>
</aside>
<div id="loading">Building voxel stream…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Shared helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(240619);
function makeInstances(items, material, castShadow = true, receiveShadow = true) {
const mesh = new THREE.InstancedMesh(unitBox, material, items.length);
items.forEach((item, index) => {
dummy.position.set(item.p[0], item.p[1], item.p[2]);
dummy.scale.set(item.s[0], item.s[1], item.s[2]);
dummy.rotation.set(
item.rx || 0,
item.ry || 0,
item.rz || 0
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(
index,
item.c instanceof THREE.Color
? item.c.clone()
: new THREE.Color(item.c)
);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
return mesh;
}
function channelCenter(z) {
return 0.52 * Math.sin(z * 0.38);
}
function channelHalfWidth(z) {
return 2.18 + 0.24 * Math.sin(z * 0.29 + 0.7);
}
// -------------------------------------------------------------------------
// Main scene
// -------------------------------------------------------------------------
const mainCanvas = document.getElementById("main-canvas");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mainCanvas.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xcfe3d9, 17, 32);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const controls = {
yaw: 0.57,
pitch: 0.53,
radius: 18,
target: new THREE.Vector3(0.35, 0.1, 0)
};
function updateCamera() {
const { yaw, pitch, radius, target } = controls;
const horizontal = radius * Math.cos(pitch);
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf4fff1, 0x5b7166, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1b3, 3.1);
sun.position.set(-7, 11, 5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x8edbe2, 1.05);
coolFill.position.set(7, 4, -8);
scene.add(coolFill);
const terrainItems = [];
const waterItems = [];
const pebbleItems = [];
const biofilmItems = [];
const markerItems = [];
const resourceItems = [];
const deepWater = new THREE.Color("#267d9a");
const shallowWater = new THREE.Color("#a9dfd1");
const wetSand = new THREE.Color("#9a9271");
const bankGreen = new THREE.Color("#7d9b65");
const bankEarth = new THREE.Color("#a29270");
// The stream bed, water and banks are all constructed from separated cubes.
for (let z = -8; z <= 8; z += 0.5) {
const center = channelCenter(z);
const halfWidth = channelHalfWidth(z);
for (let x = -6; x <= 6; x += 0.5) {
const offset = Math.abs(x - center);
const inChannel = offset < halfWidth;
if (inChannel) {
const edgeRatio = offset / halfWidth;
const jitter = (random() - 0.5) * 0.08;
terrainItems.push({
p: [x, -0.47 + random() * 0.025, z],
s: [0.46, 0.42, 0.46],
c: wetSand
.clone()
.lerp(new THREE.Color("#6f826f"), random() * 0.16)
});
const waterColor = deepWater
.clone()
.lerp(shallowWater, Math.pow(edgeRatio, 0.72) * 0.88 + jitter);
waterItems.push({
p: [x, 0.015, z],
s: [0.45, 0.32, 0.45],
c: waterColor,
phase: x * 0.7 + z * 0.55
});
} else {
const outside = offset - halfWidth;
const bankColor = bankGreen
.clone()
.lerp(bankEarth, Math.min(1, outside / 2.4))
.lerp(
new THREE.Color("#c0b383"),
random() * 0.2
);
terrainItems.push({
p: [x, 0.035 + Math.min(outside, 2) * 0.018, z],
s: [0.46, 0.72 + Math.min(outside, 1.8) * 0.12, 0.46],
c: bankColor
});
if (random() > 0.965 && outside < 1.8) {
const tuftHeight = 0.16 + random() * 0.18;
terrainItems.push({
p: [x, 0.58 + tuftHeight * 0.5, z],
s: [0.17, tuftHeight, 0.17],
c: random() > 0.5 ? "#638d55" : "#91ad66"
});
}
}
}
}
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.88,
metalness: 0
});
const terrain = makeInstances(terrainItems, terrainMaterial, true, true);
scene.add(terrain);
const waterMaterial = new THREE.MeshPhysicalMaterial({
vertexColors: true,
transparent: true,
opacity: 0.8,
roughness: 0.28,
metalness: 0,
depthWrite: false
});
const water = makeInstances(waterItems, waterMaterial, false, true);
water.renderOrder = 2;
scene.add(water);
// Pebble clusters: intentionally cubic rather than smooth.
const pebblePalette = [
"#777e79",
"#92958b",
"#aaa99a",
"#8a8278",
"#b0a391",
"#6e7878"
];
const pebbleLocations = [
[-7.0, -0.65, 0.31],
[-5.5, 0.8, 0.4],
[-4.4, -1.1, 0.29],
[-3.0, 0.55, 0.42],
[-1.7, -0.95, 0.35],
[-0.2, 0.9, 0.31],
[1.0, -0.65, 0.38],
[2.1, 1.0, 0.33],
[3.35, -0.8, 0.42],
[4.7, 0.7, 0.3],
[6.1, -0.55, 0.39],
[7.0, 0.95, 0.28]
];
pebbleLocations.forEach(([z, offset, scale]) => {
const center = channelCenter(z);
const count = 5 + Math.floor(random() * 7);
for (let i = 0; i < count; i++) {
const size = scale * (0.48 + random() * 0.58);
const px =
center +
offset +
(random() - 0.5) * (0.45 + scale);
const pz = z + (random() - 0.5) * 0.48;
const py = 0.02 + size * 0.5 + random() * 0.12;
pebbleItems.push({
p: [px, py, pz],
s: [size, size * (0.72 + random() * 0.35), size],
c: pebblePalette[Math.floor(random() * pebblePalette.length)]
});
}
});
// A few bank stones add another layer of scale.
for (let i = 0; i < 18; i++) {
const z = -7 + random() * 14;
const center = channelCenter(z);
const halfWidth = channelHalfWidth(z);
const side = random() > 0.5 ? 1 : -1;
const size = 0.22 + random() * 0.28;
pebbleItems.push({
p: [
center + side * (halfWidth + 0.22 + random() * 0.42),
0.48 + size * 0.45,
z
],
s: [size, size * 0.78, size],
c: pebblePalette[Math.floor(random() * pebblePalette.length)]
});
}
const pebbleMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.76,
metalness: 0.02
});
const pebbles = makeInstances(pebbleItems, pebbleMaterial, true, true);
scene.add(pebbles);
// Highlighted source location on a shallow-margin stone.
const sourceZ = 2.55;
const sourceX = channelCenter(sourceZ) + 1.08;
for (let ix = -1; ix <= 1; ix++) {
for (let iz = -1; iz <= 1; iz++) {
if (Math.abs(ix) + Math.abs(iz) > 1.6) continue;
pebbleItems.length; // Keep source stones visually tied to the pebble set.
const px = sourceX + ix * 0.34;
const pz = sourceZ + iz * 0.32;
const py = 0.25 + (ix === 0 && iz === 0 ? 0.08 : 0);
pebbleItems.push({
p: [px, py, pz],
s: [0.34, 0.36, 0.33],
c: ix === 0 ? "#697975" : "#7d8980"
});
const coatOffsets = [
[-0.16, -0.14],
[0.04, -0.16],
[0.18, 0.02],
[-0.08, 0.08],
[0.12, 0.2],
[-0.2, 0.16]
];
if (ix + iz < 1) {
const [dx, dz] = coatOffsets[(ix + 2) % coatOffsets.length];
biofilmItems.push({
p: [px + dx, 0.48 + random() * 0.07, pz + dz],
s: [0.18 + random() * 0.05, 0.12, 0.18 + random() * 0.04],
c: ["#8faf49", "#b3c957", "#6e984b", "#c6d36b"][
Math.floor(random() * 4)
]
});
}
}
}
// Rebuild pebbles because source stones were added after the first mesh.
const allPebbleMaterial = pebbleMaterial;
const pebbleMesh2 = makeInstances(pebbleItems, allPebbleMaterial, true, true);
scene.remove(pebbles);
scene.add(pebbleMesh2);
const biofilmMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.67,
metalness: 0
});
const biofilm = makeInstances(biofilmItems, biofilmMaterial, true, true);
scene.add(biofilm);
// A cubic amber perimeter marks the selected location.
const markerHalf = 0.65;
for (let i = 0; i < 6; i++) {
const t = -markerHalf + (i / 5) * markerHalf * 2;
markerItems.push({
p: [sourceX + t, 0.66, sourceZ - markerHalf],
s: [0.095, 0.095, 0.095],
c: "#f1b43f"
});
markerItems.push({
p: [sourceX + t, 0.66, sourceZ + markerHalf],
s: [0.095, 0.095, 0.095],
c: "#f1b43f"
});
markerItems.push({
p: [sourceX - markerHalf, 0.66, sourceZ + t],
s: [0.095, 0.095, 0.095],
c: "#f1b43f"
});
markerItems.push({
p: [sourceX + markerHalf, 0.66, sourceZ + t],
s: [0.095, 0.095, 0.095],
c: "#f1b43f"
});
}
const markerMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
emissive: 0xd98717,
emissiveIntensity: 1.25,
transparent: true,
opacity: 0.9,
roughness: 0.4,
depthWrite: false
});
const marker = makeInstances(markerItems, markerMaterial, false, false);
marker.renderOrder = 5;
scene.add(marker);
// Relative resource cue in the main scene; intentionally abstract.
for (let i = 0; i < 20; i++) {
const angle = random() * Math.PI * 2;
const radius = 0.38 + random() * 0.85;
resourceItems.push({
p: [
sourceX + Math.cos(angle) * radius,
0.38 + random() * 0.58,
sourceZ + Math.sin(angle) * radius
],
s: [0.065 + random() * 0.045, 0.065, 0.065 + random() * 0.045],
c: random() > 0.28 ? "#e9b347" : "#f3d479",
phase: random() * Math.PI * 2
});
}
const resourceMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
emissive: 0x9b5f0e,
emissiveIntensity: 0.75,
transparent: true,
opacity: 0.78,
roughness: 0.5,
depthWrite: false
});
const resources = makeInstances(resourceItems, resourceMaterial, false, false);
resources.renderOrder = 4;
scene.add(resources);
// White cubic flow tracers.
const tracerCount = 44;
const tracerItems = [];
const tracerMaterial = new THREE.MeshStandardMaterial({
color: 0xf4fff2,
transparent: true,
opacity: 0.83,
roughness: 0.35,
depthWrite: false
});
const tracers = new THREE.InstancedMesh(
unitBox,
tracerMaterial,
tracerCount
);
tracers.renderOrder = 4;
scene.add(tracers);
const tracerData = [];
for (let i = 0; i < tracerCount; i++) {
tracerData.push({
phase: random(),
lane: (random() - 0.5) * 2.2,
height: 0.25 + random() * 0.08,
size: 0.07 + random() * 0.07
});
}
// Static voxel arrows clarify downstream direction.
const arrowItems = [];
[-5.8, -2.3, 1.0].forEach((z, arrowIndex) => {
const x = channelCenter(z) + (arrowIndex - 1) * 0.25;
for (let i = 0; i < 4; i++) {
arrowItems.push({
p: [x, 0.29, z - 0.35 + i * 0.18],
s: [0.08, 0.08, 0.16],
c: "#f4fff2"
});
}
arrowItems.push({
p: [x, 0.29, z + 0.38],
s: [0.09, 0.09, 0.18],
c: "#f4fff2"
});
arrowItems.push({
p: [x - 0.17, 0.29, z + 0.2],
s: [0.09, 0.09, 0.18],
c: "#f4fff2"
});
arrowItems.push({
p: [x + 0.17, 0.29, z + 0.2],
s: [0.09, 0.09, 0.18],
c: "#f4fff2"
});
});
const arrowMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
transparent: true,
opacity: 0.86,
roughness: 0.4,
depthWrite: false
});
const arrows = makeInstances(arrowItems, arrowMaterial, false, false);
arrows.renderOrder = 4;
scene.add(arrows);
// -------------------------------------------------------------------------
// Enlarged biofilm inset scene
// -------------------------------------------------------------------------
const insetStage = document.getElementById("inset-stage");
const insetRenderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
insetRenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
insetRenderer.setClearColor(0x000000, 0);
insetRenderer.outputColorSpace = THREE.SRGBColorSpace;
insetRenderer.toneMapping = THREE.ACESFilmicToneMapping;
insetRenderer.toneMappingExposure = 1.08;
insetRenderer.shadowMap.enabled = true;
insetRenderer.shadowMap.type = THREE.PCFSoftShadowMap;
insetStage.prepend(insetRenderer.domElement);
const insetScene = new THREE.Scene();
const insetCamera = new THREE.OrthographicCamera(-3.4, 3.4, 2.8, -2.8, 0.1, 50);
insetCamera.position.set(5.2, 4.7, 6.3);
insetCamera.lookAt(0, 0.45, 0);
insetScene.add(
new THREE.HemisphereLight(0xfffbe1, 0x4f766e, 2.2)
);
const insetSun = new THREE.DirectionalLight(0xffe9a4, 3.6);
insetSun.position.set(-4, 7, 4);
insetSun.castShadow = true;
insetSun.shadow.mapSize.set(1024, 1024);
insetSun.shadow.camera.left = -5;
insetSun.shadow.camera.right = 5;
insetSun.shadow.camera.top = 5;
insetSun.shadow.camera.bottom = -5;
insetSun.shadow.bias = -0.0005;
insetScene.add(insetSun);
const insetFill = new THREE.DirectionalLight(0x8cd9dd, 1.25);
insetFill.position.set(4, 2, -5);
insetScene.add(insetFill);
const insetBaseItems = [];
const insetBiofilmItems = [];
const insetResourceItems = [];
for (let iz = -3; iz <= 2; iz++) {
for (let ix = -3; ix <= 2; ix++) {
const x = ix * 0.58;
const z = iz * 0.58;
insetBaseItems.push({
p: [x, -0.35, z],
s: [0.55, 0.28, 0.55],
c: random() > 0.5 ? "#77786c" : "#8d8874"
});
const distance = Math.hypot(x * 0.78, z);
const mound = 3.2 - distance * 0.92 + (random() - 0.5) * 0.8;
if (distance < 2.65 && mound > 0.35) {
const layers = Math.max(1, Math.floor(mound));
for (let layer = 0; layer < layers; layer++) {
const top = layer === layers - 1;
insetBiofilmItems.push({
p: [x, -0.13 + layer * 0.46, z],
s: top
? [0.5, 0.43 + random() * 0.05, 0.5]
: [0.51, 0.45, 0.51],
c: top
? ["#b8cd60", "#8eae4d", "#c9d66d", "#759c4d"][
Math.floor(random() * 4)
]
: ["#6f9948", "#83a84b", "#9fba53", "#789e49"][
Math.floor(random() * 4)
]
});
}
}
}
}
const insetBaseMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.82
});
const insetBiofilmMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.62
});
const insetBase = makeInstances(
insetBaseItems,
insetBaseMaterial,
true,
true
);
insetScene.add(insetBase);
const insetBiofilm = makeInstances(
insetBiofilmItems,
insetBiofilmMaterial,
true,
true
);
insetScene.add(insetBiofilm);
// Amber cues become more numerous toward the lighter side of the inset.
for (let i = 0; i < 28; i++) {
const sideBias = random();
const x = -2.1 + sideBias * 3.8 + (random() - 0.5) * 0.5;
const z = (random() - 0.5) * 3.6;
const size = 0.075 + random() * 0.075;
insetResourceItems.push({
p: [x, 0.65 + random() * 1.8, z],
s: [size, size, size],
c: random() > 0.3 ? "#e8ac3c" : "#f3d074",
phase: random() * Math.PI * 2,
baseY: 0.65 + random() * 1.8
});
}
const insetResourceMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
emissive: 0x9e5c08,
emissiveIntensity: 0.9,
transparent: true,
opacity: 0.9,
roughness: 0.42,
depthWrite: false
});
const insetResources = makeInstances(
insetResourceItems,
insetResourceMaterial,
false,
false
);
insetResources.renderOrder = 5;
insetScene.add(insetResources);
// -------------------------------------------------------------------------
// Direct camera controls: no addons are used.
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.18,
1.15
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("pointerleave", (event) => {
if (dragging && event.buttons === 0) stopDragging();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
11,
27
);
updateCamera();
},
{ passive: false }
);
function resetView() {
controls.yaw = 0.57;
controls.pitch = 0.53;
controls.radius = 18;
controls.target.set(0.35, 0.1, 0);
updateCamera();
}
document.getElementById("reset-view").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.yaw += 0.08;
else if (event.key === "ArrowRight") controls.yaw -= 0.08;
else if (event.key === "ArrowUp") controls.pitch += 0.05;
else if (event.key === "ArrowDown") controls.pitch -= 0.05;
else if (event.key === "+" || event.key === "=") controls.radius -= 0.5;
else if (event.key === "-") controls.radius += 0.5;
else return;
controls.pitch = THREE.MathUtils.clamp(controls.pitch, 0.18, 1.15);
controls.radius = THREE.MathUtils.clamp(controls.radius, 11, 27);
updateCamera();
});
// -------------------------------------------------------------------------
// Resizing and projected annotations
// -------------------------------------------------------------------------
function resizeInset() {
const width = Math.max(1, insetStage.clientWidth);
const height = Math.max(1, insetStage.clientHeight);
const aspect = width / height;
insetRenderer.setSize(width, height);
let halfHeight = 2.75;
if (aspect < 1.15) halfHeight = 3.0 / aspect;
insetCamera.left = -halfHeight * aspect;
insetCamera.right = halfHeight * aspect;
insetCamera.top = halfHeight;
insetCamera.bottom = -halfHeight;
insetCamera.updateProjectionMatrix();
}
function resizeMain() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
document
.getElementById("connector-layer")
.setAttribute("viewBox", `0 0 ${width} ${height}`);
}
window.addEventListener("resize", () => {
resizeMain();
resizeInset();
});
resizeMain();
resizeInset();
const sourceLabel = document.getElementById("source-label");
const flowLabel = document.getElementById("flow-label");
const connectorPath = document.getElementById("connector-path");
const sourceDot = document.getElementById("source-dot");
const insetDot = document.getElementById("inset-dot");
const insetCard = document.getElementById("inset-card");
const sourceWorld = new THREE.Vector3(sourceX, 1.12, sourceZ);
const flowWorld = new THREE.Vector3(
channelCenter(-5.3) - 0.2,
0.75,
-5.3
);
function projectToScreen(worldPosition) {
const projected = worldPosition.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
visible:
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12
};
}
function updateAnnotations() {
const source = projectToScreen(sourceWorld);
const flow = projectToScreen(flowWorld);
const rect = insetCard.getBoundingClientRect();
sourceLabel.style.left = `${source.x}px`;
sourceLabel.style.top = `${source.y - 10}px`;
sourceLabel.style.opacity = source.visible ? "1" : "0";
flowLabel.style.left = `${flow.x}px`;
flowLabel.style.top = `${flow.y}px`;
flowLabel.style.opacity = flow.visible ? "1" : "0";
const insetX = rect.left;
const insetY = rect.top + rect.height * 0.42;
sourceDot.setAttribute("cx", source.x);
sourceDot.setAttribute("cy", source.y);
insetDot.setAttribute("cx", insetX);
insetDot.setAttribute("cy", insetY);
const bend = Math.min(150, Math.max(70, Math.abs(insetX - source.x) * 0.22));
const path = [
`M ${source.x} ${source.y}`,
`C ${source.x + bend} ${source.y - 18}`,
`${insetX - bend} ${insetY + 16}`,
`${insetX} ${insetY}`
].join(" ");
connectorPath.setAttribute("d", path);
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateWater(time) {
waterItems.forEach((item, index) => {
dummy.position.set(
item.p[0],
item.p[1] + Math.sin(time * 1.2 + item.phase) * 0.018,
item.p[2]
);
dummy.scale.set(item.s[0], item.s[1], item.s[2]);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
water.setMatrixAt(index, dummy.matrix);
});
water.instanceMatrix.needsUpdate = true;
}
function updateTracers(time) {
tracerData.forEach((tracer, index) => {
const progress = (tracer.phase + time * 0.025) % 1;
const z = -8.2 + progress * 16.4;
const x =
channelCenter(z) +
tracer.lane * (0.72 + 0.18 * Math.sin(z * 0.4)) +
Math.sin(time * 0.7 + tracer.phase * 8) * 0.05;
dummy.position.set(
x,
tracer.height + Math.sin(time * 2 + tracer.phase * 7) * 0.025,
z
);
dummy.scale.set(tracer.size, tracer.size, tracer.size * 1.8);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tracers.setMatrixAt(index, dummy.matrix);
});
tracers.instanceMatrix.needsUpdate = true;
}
function updateMainResources(time) {
resourceItems.forEach((item, index) => {
dummy.position.set(
item.p[0],
item.p[1] + Math.sin(time * 0.9 + item.phase) * 0.055,
item.p[2]
);
dummy.scale.set(item.s[0], item.s[1], item.s[2]);
dummy.rotation.set(
time * 0.12 + item.phase,
time * 0.16,
0
);
dummy.updateMatrix();
resources.setMatrixAt(index, dummy.matrix);
});
resources.instanceMatrix.needsUpdate = true;
}
function updateInsetResources(time) {
insetResourceItems.forEach((item, index) => {
dummy.position.set(
item.p[0],
item.baseY + Math.sin(time * 0.85 + item.phase) * 0.12,
item.p[2]
);
dummy.scale.set(item.s[0], item.s[1], item.s[2]);
dummy.rotation.set(
time * 0.25 + item.phase,
time * 0.18,
time * 0.12
);
dummy.updateMatrix();
insetResources.setMatrixAt(index, dummy.matrix);
});
insetResources.instanceMatrix.needsUpdate = true;
}
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
updateWater(time);
updateTracers(time);
updateMainResources(time);
updateInsetResources(time);
markerMaterial.opacity = 0.72 + Math.sin(time * 2.2) * 0.18;
// A very slow inset orbit exposes the dimensionality of the voxels.
const insetAngle = 0.72 + time * 0.08;
insetCamera.position.set(
Math.sin(insetAngle) * 7.5,
4.8,
Math.cos(insetAngle) * 7.5
);
insetCamera.lookAt(0, 0.4, 0);
renderer.render(scene, camera);
camera.updateMatrixWorld();
updateAnnotations();
insetRenderer.render(insetScene, insetCamera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => {
document.getElementById("loading").remove();
}, 350);
});
</script>
</body>
</html>
```