Prompt specification
Build or customize the Three.js 3D scene "Biofilm resource-gradient explorer" 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: Biofilm resource-gradient explorer
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/biofilm-resource-gradient-explorer-x0808
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing biofilm layers. Provide an illustrative nutrient boundary above a layered colony; visualize a declining concentration field with depth and explain that the chosen profile is a toy model. Low-poly.
Working Three.js Starter (biofilm-resource-gradient-explorer-x0808):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Illustrative Biofilm Nutrient Gradient</title>
<style>
:root {
color-scheme: dark;
--ink: #eef8f4;
--muted: #9db2b6;
--panel: rgba(9, 22, 34, 0.78);
--line: rgba(183, 231, 222, 0.16);
--amber: #ffd166;
--teal: #43cfba;
--violet: #55518b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111d;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 48%, transparent 40%, rgba(2, 7, 14, 0.42) 100%),
linear-gradient(180deg, rgba(3, 9, 16, 0.22), transparent 28%, transparent 72%, rgba(3, 9, 16, 0.36));
}
.hero {
position: fixed;
z-index: 5;
top: 28px;
left: 30px;
width: min(450px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.kicker {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.kicker::before {
width: 23px;
height: 2px;
content: "";
background: var(--teal);
box-shadow: 0 0 14px rgba(67, 207, 186, 0.65);
}
h1 {
max-width: 430px;
margin: 0;
font-size: clamp(30px, 4.1vw, 54px);
font-weight: 780;
letter-spacing: -0.055em;
line-height: 0.98;
}
.hero p {
max-width: 400px;
margin: 16px 0 0;
color: #b7c9ca;
font-size: 13px;
line-height: 1.55;
}
.model-card {
position: fixed;
z-index: 6;
top: 26px;
right: 26px;
width: 318px;
padding: 20px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px) saturate(125%);
-webkit-backdrop-filter: blur(18px) saturate(125%);
}
.card-label {
margin-bottom: 8px;
color: var(--amber);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.model-card h2 {
margin: 0;
font-size: 19px;
letter-spacing: -0.025em;
}
.model-card p {
margin: 9px 0 0;
color: var(--muted);
font-size: 11.5px;
line-height: 1.55;
}
.equation {
margin: 16px 0 13px;
padding: 12px 13px;
border: 1px solid rgba(255, 209, 102, 0.18);
border-radius: 11px;
background: rgba(255, 209, 102, 0.055);
color: #ffe2a0;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
text-align: center;
}
.equation small {
display: block;
margin-top: 5px;
color: #a9b9b9;
font-family: inherit;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.chart-wrap {
position: relative;
margin-top: 13px;
padding: 8px 8px 5px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 12px;
background: rgba(0, 0, 0, 0.12);
}
.chart-wrap svg {
display: block;
width: 100%;
height: auto;
}
.chart-caption {
display: flex;
justify-content: space-between;
color: #83999d;
font-size: 9px;
letter-spacing: 0.05em;
}
.legend {
display: grid;
grid-template-columns: 18px 1fr;
gap: 11px;
align-items: stretch;
margin-top: 17px;
}
.legend-bar {
position: relative;
min-height: 105px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 20px;
background: linear-gradient(
180deg,
var(--amber) 0%,
#66d5ba 33%,
var(--teal) 50%,
#3b6880 72%,
var(--violet) 100%
);
box-shadow: inset 0 0 0 4px rgba(5, 13, 22, 0.34);
}
.legend-bar::after {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
content: "";
background: rgba(255, 255, 255, 0.38);
}
.legend-copy {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 2px 0;
}
.legend-copy strong {
display: block;
font-size: 11px;
letter-spacing: 0.03em;
}
.legend-copy span {
display: block;
margin-top: 3px;
color: #91a6aa;
font-size: 9.5px;
line-height: 1.35;
}
.legend-note {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #8ea5a8;
font-size: 10px;
line-height: 1.5;
}
.legend-note strong {
color: #c8d8d7;
}
.strata-key {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.strata-key span {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 5px 7px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
color: #aebfc0;
font-size: 8.5px;
letter-spacing: 0.03em;
}
.strata-key i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--c);
}
.annotation {
position: fixed;
z-index: 4;
top: 0;
left: 0;
max-width: 210px;
padding: 6px 9px;
border: 1px solid rgba(181, 226, 220, 0.2);
border-radius: 6px;
background: rgba(7, 19, 30, 0.72);
color: #d9e7e4;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
line-height: 1.25;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.annotation::after {
position: absolute;
top: 50%;
left: -19px;
width: 18px;
height: 1px;
content: "";
background: rgba(181, 226, 220, 0.36);
}
.annotation.boundary {
border-color: rgba(255, 209, 102, 0.34);
color: #ffe1a0;
}
.annotation.boundary::after {
background: rgba(255, 209, 102, 0.55);
}
.layer-readout {
position: fixed;
z-index: 5;
left: 30px;
bottom: 30px;
max-width: 340px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(7, 18, 29, 0.68);
color: #9fb4b7;
font-size: 10px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.layer-readout strong {
color: #e1efeb;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint {
position: fixed;
z-index: 5;
right: 28px;
bottom: 28px;
color: rgba(209, 226, 224, 0.62);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
pointer-events: none;
}
.controls {
position: fixed;
z-index: 7;
right: 27px;
bottom: 52px;
display: flex;
gap: 7px;
}
.controls button {
width: 36px;
height: 36px;
padding: 0;
border: 1px solid rgba(204, 235, 229, 0.2);
border-radius: 10px;
background: rgba(8, 22, 34, 0.8);
color: #d9e8e5;
font: inherit;
font-size: 18px;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
.controls button:hover {
background: rgba(31, 70, 77, 0.9);
transform: translateY(-1px);
}
.controls button:focus-visible {
outline: 2px solid var(--amber);
outline-offset: 2px;
}
.controls #reset {
width: auto;
padding: 0 12px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.hero {
top: 17px;
left: 17px;
width: calc(100vw - 34px);
}
h1 {
max-width: 330px;
font-size: 31px;
}
.hero p {
display: none;
}
.model-card {
top: 112px;
right: 14px;
left: 14px;
width: auto;
max-height: 47vh;
padding: 15px;
overflow-y: auto;
border-radius: 14px;
}
.model-card h2 {
font-size: 16px;
}
.model-card p {
font-size: 10.5px;
}
.equation {
margin: 12px 0;
padding: 9px;
font-size: 16px;
}
.chart-wrap {
display: none;
}
.legend {
margin-top: 12px;
}
.legend-bar {
min-height: 82px;
}
.legend-note {
margin-top: 10px;
padding-top: 10px;
}
.annotation {
display: none;
}
.layer-readout {
right: 14px;
bottom: 14px;
left: 14px;
max-width: none;
}
.hint {
display: none;
}
.controls {
right: 15px;
bottom: 92px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive low-poly biofilm colony beneath an illustrative nutrient boundary"
></canvas>
<div class="vignette"></div>
<header class="hero">
<div class="kicker">Illustrative biofilm section</div>
<h1>A colony built in layers</h1>
<p>
A nutrient-rich interface sits above a low-poly microbial colony.
Color and scale encode an assumed concentration that becomes weaker with depth.
</p>
</header>
<aside class="model-card" aria-label="Toy concentration model">
<div class="card-label">Toy model · not calibrated</div>
<h2>Exponential nutrient decline</h2>
<p>
Depth <strong>d</strong> is measured downward from the nutrient interface.
The chosen profile simply makes the assumed trend legible.
</p>
<div class="equation">
C(d) = C₀ · exp(−d / ℓ)
<small>ℓ = 3.0 illustrative scene units</small>
</div>
<div class="chart-wrap">
<svg viewBox="0 0 270 94" role="img" aria-label="Exponential concentration profile">
<defs>
<linearGradient id="curveGradient" x1="0" y1="0" x2="1" y2="0">
<stop offset="0" stop-color="#ffd166" />
<stop offset="0.52" stop-color="#43cfba" />
<stop offset="1" stop-color="#55518b" />
</linearGradient>
<linearGradient id="areaGradient" x1="0" y1="0" x2="1" y2="0">
<stop offset="0" stop-color="#ffd166" stop-opacity="0.22" />
<stop offset="1" stop-color="#55518b" stop-opacity="0.02" />
</linearGradient>
</defs>
<line x1="24" y1="10" x2="24" y2="72" stroke="#60777a" stroke-width="1" />
<line x1="24" y1="72" x2="244" y2="72" stroke="#60777a" stroke-width="1" />
<path id="profileArea" fill="url(#areaGradient)" />
<path
id="profilePath"
fill="none"
stroke="url(#curveGradient)"
stroke-width="3"
stroke-linecap="round"
/>
<circle id="profileDot" r="3.5" fill="#ffd166" />
<text x="24" y="87" fill="#82999c" font-size="8">0</text>
<text x="229" y="87" fill="#82999c" font-size="8">8.0 depth</text>
<text x="8" y="14" fill="#82999c" font-size="8">C</text>
<text x="8" y="70" fill="#82999c" font-size="8">0</text>
</svg>
<div class="chart-caption">
<span>Nutrient-rich interface</span>
<span>Deeper, weaker</span>
</div>
</div>
<div class="legend">
<div class="legend-bar" aria-hidden="true"></div>
<div class="legend-copy">
<div>
<strong>High concentration</strong>
<span>Amber, larger field marks</span>
</div>
<div>
<strong>Low concentration</strong>
<span>Violet, smaller field marks</span>
</div>
<div>
<strong>Amber arrows</strong>
<span>Assumed downward nutrient flux</span>
</div>
</div>
</div>
<div class="strata-key" aria-label="Colony layer colors">
<span><i style="--c:#d5dd83"></i>Surface</span>
<span><i style="--c:#3ba083"></i>Interior</span>
<span><i style="--c:#4b3f76"></i>Basal</span>
</div>
<div class="legend-note">
<strong>This is a chosen toy profile.</strong>
It is not a calibrated diffusion, reaction, oxygen, or mass-transfer
simulation, and the geometry should not be read as biological measurements.
</div>
</aside>
<div class="annotation boundary" id="labelBoundary">Nutrient-rich boundary</div>
<div class="annotation" id="labelColony">Layered colony</div>
<div class="annotation" id="labelProfile">C(d) sample profile</div>
<div class="layer-readout" id="layerReadout">
<strong>Explore the colony</strong><br />
Click a cell layer to inspect its illustrative role.
</div>
<div class="controls" aria-label="Camera controls">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="reset" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · scroll to zoom · double-click to reset</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 renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
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(0x07111d);
scene.fog = new THREE.FogExp2(0x07111d, 0.024);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// ----- Toy model parameters -------------------------------------------
const SURFACE_Y = 7.6;
const DECAY_LENGTH = 3.0;
const MAX_MODEL_DEPTH = 8.0;
function concentrationAtDepth(depth) {
return Math.exp(-Math.max(0, depth) / DECAY_LENGTH);
}
function concentrationColor(value, target = new THREE.Color()) {
const low = new THREE.Color(0x45427f);
const middle = new THREE.Color(0x43cfba);
const high = new THREE.Color(0xffd166);
const c = THREE.MathUtils.clamp(value, 0, 1);
if (c < 0.52) {
target.copy(low).lerp(middle, c / 0.52);
} else {
target.copy(middle).lerp(high, (c - 0.52) / 0.48);
}
return target;
}
// ----- Lighting -------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xbfeaff, 0x21172d, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xd8f7ff, 3.0);
keyLight.position.set(-8, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const nutrientLight = new THREE.PointLight(0xffca68, 42, 23, 2);
nutrientLight.position.set(0, 10.5, 1);
scene.add(nutrientLight);
const sideLight = new THREE.PointLight(0x38d6c0, 24, 20, 2);
sideLight.position.set(9, 3, -7);
scene.add(sideLight);
// ----- Ground ---------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.CylinderGeometry(8.6, 9.0, 0.36, 18),
new THREE.MeshStandardMaterial({
color: 0x101d29,
roughness: 0.96,
metalness: 0.02
})
);
ground.position.y = -0.48;
ground.receiveShadow = true;
scene.add(ground);
const floorGrid = new THREE.GridHelper(38, 38, 0x31515a, 0x17303a);
floorGrid.position.y = -0.68;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.18;
scene.add(floorGrid);
const baseRingPoints = [];
for (let i = 0; i < 48; i++) {
const a = (i / 48) * Math.PI * 2;
baseRingPoints.push(new THREE.Vector3(Math.cos(a) * 8.45, -0.28, Math.sin(a) * 8.45));
}
const baseRing = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(baseRingPoints),
new THREE.LineBasicMaterial({
color: 0x4db7ad,
transparent: true,
opacity: 0.38
})
);
scene.add(baseRing);
// ----- Deterministic random helper ------------------------------------
let randomSeed = 48291;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6D2B79F5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
// ----- Layered biofilm colony -----------------------------------------
const colony = new THREE.Group();
scene.add(colony);
const layers = [
{ y: 0.18, radius: 5.35, count: 45, color: 0x4b3f76, name: "Basal / low-activity zone" },
{ y: 0.98, radius: 5.80, count: 49, color: 0x37677a, name: "Deep matrix stratum" },
{ y: 1.78, radius: 5.45, count: 44, color: 0x2f8581, name: "Lower cell stratum" },
{ y: 2.58, radius: 4.90, count: 38, color: 0x3ba083, name: "Middle cell stratum" },
{ y: 3.38, radius: 4.15, count: 31, color: 0x66b982, name: "Upper cell stratum" },
{ y: 4.18, radius: 3.15, count: 23, color: 0x9ad176, name: "Surface cell stratum" },
{ y: 4.88, radius: 1.85, count: 12, color: 0xd5dd83, name: "EPS-rich cap" }
];
const cellGeometry = new THREE.IcosahedronGeometry(1, 0);
const cellMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
flatShading: true,
roughness: 0.78,
metalness: 0.03
});
const dummy = new THREE.Object3D();
const pickableLayers = [];
layers.forEach((layer, layerIndex) => {
const shell = new THREE.Mesh(
new THREE.CylinderGeometry(
layer.radius,
layer.radius * 0.98,
0.48,
18,
1,
true
),
new THREE.MeshBasicMaterial({
color: layer.color,
wireframe: true,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
})
);
shell.position.y = layer.y - 0.10;
colony.add(shell);
const cells = new THREE.InstancedMesh(
cellGeometry,
cellMaterial,
layer.count
);
cells.castShadow = true;
cells.receiveShadow = true;
cells.frustumCulled = false;
cells.userData.layerIndex = layerIndex;
cells.userData.layerName = layer.name;
const baseColor = new THREE.Color(layer.color);
for (let i = 0; i < layer.count; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * layer.radius;
const x = Math.cos(angle) * radius + (random() - 0.5) * 0.34;
const z = Math.sin(angle) * radius + (random() - 0.5) * 0.34;
const y = layer.y + (random() - 0.5) * 0.34;
const size = 0.39 + random() * 0.34;
const sx = size * (0.78 + random() * 0.48);
const sy = size * (0.52 + random() * 0.38);
const sz = size * (0.78 + random() * 0.48);
dummy.position.set(x, y, z);
dummy.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
dummy.scale.set(sx, sy, sz);
dummy.updateMatrix();
cells.setMatrixAt(i, dummy.matrix);
const cellColor = baseColor.clone();
cellColor.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.12,
(random() - 0.5) * 0.11
);
cells.setColorAt(i, cellColor);
}
cells.instanceMatrix.needsUpdate = true;
if (cells.instanceColor) {
cells.instanceColor.needsUpdate = true;
}
colony.add(cells);
pickableLayers.push(cells);
});
// ----- Nutrient boundary ---------------------------------------------
const boundaryGroup = new THREE.Group();
boundaryGroup.position.y = SURFACE_Y;
scene.add(boundaryGroup);
const boundaryMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.085,
side: THREE.DoubleSide,
depthWrite: false
});
const boundaryPlane = new THREE.Mesh(
new THREE.PlaneGeometry(17, 12),
boundaryMaterial
);
boundaryPlane.rotation.x = -Math.PI / 2;
boundaryGroup.add(boundaryPlane);
const gridPositions = [];
for (let x = -8; x <= 8; x += 2) {
gridPositions.push(x, 0.018, -6, x, 0.018, 6);
}
for (let z = -6; z <= 6; z += 2) {
gridPositions.push(-8.5, 0.018, z, 8.5, 0.018, z);
}
const boundaryGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.20,
depthWrite: false
})
);
boundaryGroup.add(boundaryGrid);
const boundaryFrame = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-8.5, 0.025, -6),
new THREE.Vector3(8.5, 0.025, -6),
new THREE.Vector3(8.5, 0.025, 6),
new THREE.Vector3(-8.5, 0.025, 6),
new THREE.Vector3(-8.5, 0.025, -6)
]),
new THREE.LineDashedMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.6,
dashSize: 0.28,
gapSize: 0.16
})
);
boundaryFrame.computeLineDistances();
boundaryGroup.add(boundaryFrame);
// ----- Downward nutrient arrows --------------------------------------
const arrows = [];
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.64,
depthWrite: false
});
const arrowShaftGeometry = new THREE.CylinderGeometry(0.035, 0.035, 0.54, 5);
const arrowHeadGeometry = new THREE.ConeGeometry(0.15, 0.34, 5);
const arrowPositions = [];
for (const x of [-6, -3, 0, 3, 6]) {
for (const z of [-3.5, 0, 3.5]) {
arrowPositions.push([x, z]);
}
}
arrowPositions.forEach(([x, z], index) => {
const arrow = new THREE.Group();
arrow.position.set(x, 8.75 + (index % 2) * 0.08, z);
const shaft = new THREE.Mesh(arrowShaftGeometry, arrowMaterial);
arrow.add(shaft);
const head = new THREE.Mesh(arrowHeadGeometry, arrowMaterial);
head.position.y = -0.43;
head.rotation.z = Math.PI;
arrow.add(head);
arrow.userData.baseY = arrow.position.y;
arrow.userData.phase = index * 0.63;
arrows.push(arrow);
scene.add(arrow);
});
// ----- Nutrient concentration field ----------------------------------
// Low-poly octahedral marks. Color, size, and sparseness all decline
// with depth to make the illustrative field readable.
const fieldGeometry = new THREE.OctahedronGeometry(1, 0);
const fieldMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
vertexColors: true,
transparent: true,
opacity: 0.66,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const fieldTransforms = [];
const fieldColors = [];
const attempts = 1500;
for (let i = 0; i < attempts; i++) {
const x = (random() - 0.5) * 18.0;
const z = (random() - 0.5) * 13.0;
const y = -0.25 + random() * 11.0;
const depth = Math.max(0, SURFACE_Y - y);
const concentration = Math.min(1, concentrationAtDepth(depth));
// Deliberately visual encoding, not a physical particle count.
if (random() > 0.30 + concentration * 0.70) {
continue;
}
const size = 0.022 + concentration * 0.083;
dummy.position.set(x, y, z);
dummy.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
dummy.scale.setScalar(size);
dummy.updateMatrix();
fieldTransforms.push(dummy.matrix.clone());
fieldColors.push(concentrationColor(concentration));
}
const field = new THREE.InstancedMesh(
fieldGeometry,
fieldMaterial,
fieldTransforms.length
);
fieldTransforms.forEach((matrix, index) => {
field.setMatrixAt(index, matrix);
field.setColorAt(index, fieldColors[index]);
});
field.instanceMatrix.needsUpdate = true;
if (field.instanceColor) {
field.instanceColor.needsUpdate = true;
}
field.frustumCulled = false;
scene.add(field);
// ----- Explicit vertical concentration sample ------------------------
const profileX = 0;
const profileZ = 7.45;
const profileBottom = -0.2;
const profileTop = SURFACE_Y;
const profileLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(profileX, profileBottom, profileZ),
new THREE.Vector3(profileX, profileTop, profileZ)
]),
new THREE.LineBasicMaterial({
color: 0xc3d9d5,
transparent: true,
opacity: 0.38
})
);
scene.add(profileLine);
const profileNodeGeometry = new THREE.OctahedronGeometry(0.13, 0);
for (let i = 0; i <= 16; i++) {
const y = THREE.MathUtils.lerp(profileBottom, profileTop, i / 16);
const concentration = concentrationAtDepth(SURFACE_Y - y);
const node = new THREE.Mesh(
profileNodeGeometry,
new THREE.MeshBasicMaterial({
color: concentrationColor(concentration),
transparent: true,
opacity: 0.95
})
);
node.position.set(profileX, y, profileZ);
scene.add(node);
}
// ----- SVG chart matching the scene model ----------------------------
const chartX = 24;
const chartWidth = 220;
const chartY = 72;
const chartHeight = 62;
const chartPoints = [];
for (let i = 0; i <= 60; i++) {
const depth = MAX_MODEL_DEPTH * (i / 60);
const concentration = concentrationAtDepth(depth);
const x = chartX + chartWidth * (i / 60);
const y = chartY - chartHeight * concentration;
chartPoints.push([x, y]);
}
const pathData = chartPoints
.map(([x, y], index) => `${index === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)}`)
.join(" ");
const areaData =
`${pathData} L${chartX + chartWidth},${chartY} L${chartX},${chartY} Z`;
document.querySelector("#profilePath").setAttribute("d", pathData);
document.querySelector("#profileArea").setAttribute("d", areaData);
const hoverDot = document.querySelector("#profileDot");
const [hoverX, hoverY] = chartPoints[0];
hoverDot.setAttribute("cx", hoverX);
hoverDot.setAttribute("cy", hoverY);
// ----- Direct camera controls ----------------------------------------
const target = new THREE.Vector3(0, 3.7, 0);
const desired = {
theta: -0.62,
phi: 1.05,
radius: 22.5
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
let dragging = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
let moved = false;
let autoRotate = !reducedMotion;
let resumeTimer = 0;
function stopAutoRotate() {
autoRotate = false;
window.clearTimeout(resumeTimer);
if (!reducedMotion) {
resumeTimer = window.setTimeout(() => {
autoRotate = true;
}, 9000);
}
}
function resetView() {
desired.theta = -0.62;
desired.phi = 1.05;
desired.radius = 22.5;
stopAutoRotate();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
moved = false;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
stopAutoRotate();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) {
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
moved = true;
}
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.48,
1.43
);
previousX = event.clientX;
previousY = event.clientY;
});
canvas.addEventListener("pointerup", (event) => {
if (event.pointerId !== pointerId) {
return;
}
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (!moved) {
inspectCell(event);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.012,
14,
31
);
stopAutoRotate();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.querySelector("#zoomIn").addEventListener("click", () => {
desired.radius = Math.max(14, desired.radius - 2);
stopAutoRotate();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
desired.radius = Math.min(31, desired.radius + 2);
stopAutoRotate();
});
document.querySelector("#reset").addEventListener("click", resetView);
// ----- Click-to-inspect cells ----------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const layerReadout = document.querySelector("#layerReadout");
function inspectCell(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickableLayers, false);
if (hits.length > 0) {
const hit = hits[0];
const index = hit.object.userData.layerIndex;
const name = hit.object.userData.layerName;
const layer = layers[index];
layerReadout.innerHTML = `
<strong>Layer ${String(index + 1).padStart(2, "0")} · ${name}</strong><br />
Illustrative stratum at y ≈ ${layer.y.toFixed(1)}.
Cell size and layer thickness are not measured values.
`;
}
}
// ----- Projected scene labels ----------------------------------------
const labels = [
{
element: document.querySelector("#labelBoundary"),
position: new THREE.Vector3(7.0, SURFACE_Y + 0.05, -1.3)
},
{
element: document.querySelector("#labelColony"),
position: new THREE.Vector3(-5.8, 2.65, 2.4)
},
{
element: document.querySelector("#labelProfile"),
position: new THREE.Vector3(0, SURFACE_Y + 0.25, 7.45)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
}
}
}
// ----- Resize --------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
// ----- Animation -----------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
if (autoRotate && !dragging) {
desired.theta += delta * 0.10;
}
const damping = 0.085;
current.theta += (desired.theta - current.theta) * damping;
current.phi += (desired.phi - current.phi) * damping;
current.radius += (desired.radius - current.radius) * damping;
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
if (!reducedMotion) {
boundaryMaterial.opacity = 0.075 + Math.sin(elapsed * 1.4) * 0.018;
boundaryGrid.material.opacity = 0.18 + Math.sin(elapsed * 1.4) * 0.045;
nutrientLight.intensity = 40 + Math.sin(elapsed * 1.2) * 4;
arrows.forEach((arrow) => {
arrow.position.y =
arrow.userData.baseY +
Math.sin(elapsed * 1.25 + arrow.userData.phase) * 0.075;
});
}
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```