Prompt specification
Build or customize the Three.js 3D scene "Nitrogen transformation pathway model" 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: Nitrogen transformation pathway model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/nitrogen-transformation-pathway-model-x0742
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring legume root nodules. Animate symbolic nitrogen moving through labeled stages involving bacteria and plant tissues; keep chemical categories distinct and avoid suggesting that plants directly absorb atmospheric nitrogen unchanged. Low-poly.
Working Three.js Starter (nitrogen-transformation-pathway-model-x0742):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Legume Root Nodules — Symbolic Nitrogen Fixation</title>
<style>
:root {
--n2: #20bfb8;
--nh4: #ffc857;
--organic: #a875e8;
--plant: #79b96a;
--bacteria: #d96b42;
--ink: #17342f;
--muted: #526a64;
--paper: rgba(248, 252, 246, 0.88);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 34% 25%, rgba(255,255,255,.98) 0 12%, transparent 43%),
radial-gradient(circle at 72% 74%, rgba(185,220,190,.68), transparent 46%),
linear-gradient(150deg, #e9f3ec 0%, #dcebe5 50%, #efe8d9 100%);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
header {
position: absolute;
top: 28px;
left: 32px;
width: min(520px, calc(100vw - 410px));
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(25,78,67,.16);
border-radius: 999px;
background: rgba(255,255,255,.62);
color: #315e53;
font-size: 10px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--plant);
box-shadow: 0 0 0 4px rgba(121,185,106,.16);
}
h1 {
margin: 12px 0 6px;
font-size: clamp(30px, 4.1vw, 62px);
line-height: .96;
letter-spacing: -.055em;
font-weight: 850;
}
header p {
margin: 10px 0 0;
max-width: 470px;
color: var(--muted);
font-size: clamp(13px, 1.3vw, 17px);
line-height: 1.45;
}
.panel {
pointer-events: auto;
border: 1px solid rgba(25,78,67,.13);
background: var(--paper);
box-shadow: 0 18px 55px rgba(37,74,61,.13);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#science {
position: absolute;
top: 28px;
right: 28px;
width: 330px;
padding: 18px 18px 16px;
border-radius: 20px;
}
.panel h2 {
margin: 0 0 10px;
font-size: 13px;
letter-spacing: .08em;
text-transform: uppercase;
}
.equation {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
padding: 12px 0;
margin-bottom: 10px;
border-top: 1px solid rgba(25,78,67,.1);
border-bottom: 1px solid rgba(25,78,67,.1);
font-size: 13px;
font-weight: 800;
}
.equation .n2 { color: #078d88; }
.equation .nh4 { color: #b67a00; }
.equation .organic { color: #7545b3; }
.equation small {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
#science p {
margin: 0 0 10px;
color: #405a53;
font-size: 12px;
line-height: 1.52;
}
#science strong { color: var(--ink); }
.tissue-key {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 12px;
font-size: 10px;
color: #496159;
}
.tissue-key span {
display: flex;
align-items: center;
gap: 6px;
}
.tissue-key i {
width: 9px;
height: 9px;
border-radius: 3px;
display: inline-block;
}
.note {
margin-top: 12px !important;
padding: 9px 10px;
border-left: 3px solid var(--plant);
border-radius: 0 9px 9px 0;
background: rgba(121,185,106,.12);
color: #315348 !important;
}
#legend {
position: absolute;
left: 28px;
bottom: 25px;
width: 390px;
padding: 14px 16px;
border-radius: 17px;
}
#legend h2 {
margin: 0 0 9px;
font-size: 10px;
letter-spacing: .12em;
text-transform: uppercase;
color: #5c716a;
}
.legend-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
color: #3f5851;
}
.legend-item b {
color: var(--ink);
font-size: 12px;
}
.swatch {
width: 24px;
height: 20px;
position: relative;
flex: 0 0 24px;
}
.atom {
position: absolute;
width: 9px;
height: 9px;
border-radius: 3px;
transform: rotate(30deg);
}
.atom.a { left: 1px; top: 5px; }
.atom.b { left: 13px; top: 5px; }
.atom.c { left: 7px; top: 1px; }
.swatch.n2 .atom { background: var(--n2); }
.swatch.nh4 .atom {
width: 12px;
height: 12px;
left: 6px;
top: 4px;
background: var(--nh4);
}
.swatch.organic .atom { background: var(--organic); }
.swatch.organic .atom.a { left: 1px; top: 9px; }
.swatch.organic .atom.b { left: 13px; top: 9px; }
.swatch.organic .atom.c { left: 7px; top: 2px; }
.swatch.nitrate .atom { background: #ef6b63; }
.swatch.nitrate .atom.c {
width: 12px;
height: 12px;
left: 6px;
top: 4px;
background: #3f7fe8;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 3;
}
#leaders line {
stroke-width: 1.3;
stroke-dasharray: 4 5;
vector-effect: non-scaling-stroke;
}
#leaders circle {
stroke: white;
stroke-width: 2;
vector-effect: non-scaling-stroke;
}
.callout {
position: absolute;
z-index: 4;
width: 255px;
padding: 12px 13px 12px 48px;
border: 1px solid rgba(30,72,61,.14);
border-radius: 15px;
background: rgba(250,253,248,.9);
box-shadow: 0 12px 30px rgba(35,70,56,.12);
transform: translate(-50%, -50%);
transition: opacity .25s, border-color .25s, box-shadow .25s, background .25s;
opacity: .58;
backdrop-filter: blur(11px);
-webkit-backdrop-filter: blur(11px);
}
.callout.active {
opacity: 1;
border-color: color-mix(in srgb, var(--accent) 58%, white);
background: rgba(255,255,252,.96);
box-shadow:
0 15px 38px rgba(35,70,56,.15),
0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent);
}
.callout .number {
position: absolute;
left: 12px;
top: 12px;
width: 26px;
height: 26px;
display: grid;
place-items: center;
border-radius: 9px;
background: var(--accent);
color: white;
font-size: 12px;
font-weight: 900;
box-shadow: inset 0 -2px 0 rgba(0,0,0,.09);
}
.callout h3 {
margin: 0 0 4px;
font-size: 13px;
line-height: 1.15;
}
.callout p {
margin: 0;
color: #526961;
font-size: 10.5px;
line-height: 1.4;
}
.callout code {
color: var(--accent);
font-family: inherit;
font-weight: 850;
}
#callout0 { --accent: var(--n2); }
#callout1 { --accent: #e59c2f; }
#callout2 { --accent: var(--organic); }
#callout3 { --accent: #5f548f; }
#nitrate-note {
position: absolute;
z-index: 4;
width: 235px;
padding: 8px 11px;
border-radius: 11px;
border: 1px solid rgba(63,127,232,.22);
background: rgba(244,249,255,.86);
color: #49617c;
font-size: 10px;
line-height: 1.35;
transform: translate(-50%, -50%);
backdrop-filter: blur(9px);
}
#nitrate-note b { color: #315fa9; }
#hint {
position: absolute;
right: 28px;
bottom: 27px;
padding: 9px 12px;
border-radius: 999px;
background: rgba(255,255,255,.68);
border: 1px solid rgba(25,78,67,.11);
color: #557068;
font-size: 10px;
letter-spacing: .03em;
}
@media (max-width: 900px) {
header {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 { font-size: 34px; }
header p { max-width: 390px; font-size: 12px; }
#science {
top: auto;
right: 15px;
bottom: 65px;
width: 280px;
padding: 13px;
}
#science p, .tissue-key, #science .note { display: none; }
#science .equation { margin: 0; border: 0; padding: 0; }
#legend {
left: 15px;
bottom: 15px;
width: 300px;
padding: 11px;
}
.legend-grid { gap: 6px; }
.legend-item { font-size: 9px; }
.callout { width: 215px; }
#hint { display: none; }
}
@media (max-width: 620px) {
#science { display: none; }
#legend { width: calc(100vw - 30px); }
.legend-grid { grid-template-columns: repeat(4, 1fr); }
.legend-item { display: block; }
.legend-item .swatch { margin-bottom: 3px; }
.callout { width: 185px; padding: 10px 9px 10px 40px; }
.callout h3 { font-size: 11px; }
.callout p { font-size: 9px; }
.callout .number { left: 8px; top: 10px; width: 23px; height: 23px; }
#nitrate-note { width: 190px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<svg id="leaders" aria-hidden="true">
<g id="leader0"><line/><circle r="4"/></g>
<g id="leader1"><line/><circle r="4"/></g>
<g id="leader2"><line/><circle r="4"/></g>
<g id="leader3"><line/><circle r="4"/></g>
<g id="leaderN"><line/><circle r="4"/></g>
</svg>
<div class="ui">
<header>
<div class="eyebrow">Biological nitrogen fixation · schematic</div>
<h1>Inside a legume<br>root nodule</h1>
<p>
Follow symbolic nitrogen from atmospheric N<sub>2</sub> through bacterial fixation,
plant assimilation, and transport within the root.
</p>
</header>
<aside id="science" class="panel">
<h2>What is actually transferred?</h2>
<div class="equation">
<span class="n2">N₂</span>
<small>bacteria</small><span>→</span>
<span class="nh4">NH₄⁺</span>
<small>plant enzymes</small><span>→</span>
<span class="organic">organic N</span>
</div>
<p>
Rhizobial bacteria inside the nodule use <strong>nitrogenase</strong> to reduce
atmospheric N₂ to NH₃, commonly represented as NH₄⁺ at near-neutral pH.
The plant supplies carbon and receives <strong>fixed nitrogen</strong>.
</p>
<p>
Plant enzymes then incorporate that fixed N into compounds such as
<strong>glutamine and glutamate</strong>. The symbols show chemical categories,
not exact molecular structures.
</p>
<div class="tissue-key">
<span><i style="background:var(--plant)"></i>plant tissue</span>
<span><i style="background:var(--bacteria)"></i>bacterial zone</span>
<span><i style="background:#536c80"></i>vascular tissue</span>
<span><i style="background:#85683c"></i>root tissue</span>
</div>
<p class="note">
The plant does <strong>not</strong> absorb atmospheric N₂ unchanged.
Fixation occurs in the symbiont bacteria; the plant receives fixed N.
</p>
</aside>
<div id="callout0" class="callout">
<span class="number">1</span>
<h3>N₂ reaches the bacterial zone</h3>
<p>
Gaseous <code>N₂</code> diffuses into the nodule. It enters bacterial space,
not the plant as unchanged atmospheric nitrogen.
</p>
</div>
<div id="callout1" class="callout">
<span class="number">2</span>
<h3>Bacterial fixation</h3>
<p>
Nitrogenase converts <code>N₂ → NH₃/NH₄⁺</code>.
The single amber symbol represents fixed inorganic nitrogen.
</p>
</div>
<div id="callout2" class="callout">
<span class="number">3</span>
<h3>Assimilation in plant tissue</h3>
<p>
Plant enzymes incorporate fixed N into <code>glutamine / glutamate</code>.
Purple clusters represent organic nitrogen.
</p>
</div>
<div id="callout3" class="callout">
<span class="number">4</span>
<h3>Transport through the root</h3>
<p>
Organic N, including amino compounds and amides, moves through plant
vascular tissue. Exact routes vary by compound.
</p>
</div>
<div id="nitrate-note">
<b>Separate route:</b> roots can also absorb soil NO₃⁻ directly.
This is distinct from atmospheric N₂ fixation.
</div>
<section id="legend" class="panel">
<h2>Chemical categories — symbols are deliberately distinct</h2>
<div class="legend-grid">
<div class="legend-item">
<span class="swatch n2"><i class="atom a"></i><i class="atom b"></i></span>
<span><b>N₂</b> · atmospheric diatomic N</span>
</div>
<div class="legend-item">
<span class="swatch nh4"><i class="atom"></i></span>
<span><b>NH₄⁺</b> · fixed inorganic N</span>
</div>
<div class="legend-item">
<span class="swatch organic"><i class="atom a"></i><i class="atom b"></i><i class="atom c"></i></span>
<span><b>Organic N</b> · amino / amide</span>
</div>
<div class="legend-item">
<span class="swatch nitrate"><i class="atom a"></i><i class="atom b"></i><i class="atom c"></i></span>
<span><b>NO₃⁻</b> · soil inorganic N</span>
</div>
</div>
</section>
<div id="hint">Drag to orbit · scroll to zoom · double-click to reset</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------------
// Renderer, camera, lights
// ---------------------------------------------------------------------------
const mount = document.getElementById("scene");
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.localClippingEnabled = true;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0xe3eee6, 0.018);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0.15, 0.05, 0);
const spherical = new THREE.Spherical(10.1, 1.16, 0.54);
const defaultSpherical = spherical.clone();
scene.add(new THREE.HemisphereLight(0xf8fff7, 0x6b5140, 2.0));
const key = new THREE.DirectionalLight(0xfff4d8, 3.1);
key.position.set(4, 8, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0006;
scene.add(key);
const rim = new THREE.DirectionalLight(0x8ed9cd, 1.65);
rim.position.set(-5, 2, -5);
scene.add(rim);
const fill = new THREE.DirectionalLight(0xffc995, 0.75);
fill.position.set(-4, -1, 5);
scene.add(fill);
// ---------------------------------------------------------------------------
// Materials and helpers
// ---------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.0,
flatShading: true,
...options
});
}
const M = {
root: material(0xa8794e),
rootLight: material(0xc59668),
rootDark: material(0x76513b),
plant: material(0x79b96a),
plantLight: material(0xb7d99d),
plantDark: material(0x4f8e52),
bacteria: material(0xd96b42),
bacteriaLight: material(0xf29a61),
vascular: material(0x536c80),
vascularPurple: material(0x675681),
soil: material(0x846342),
n2: material(0x20bfb8, {
emissive: 0x075e5b,
emissiveIntensity: 0.3,
roughness: 0.45
}),
nh4: material(0xffc857, {
emissive: 0x8a5400,
emissiveIntensity: 0.34,
roughness: 0.42
}),
organic: material(0xa875e8, {
emissive: 0x3e176d,
emissiveIntensity: 0.35,
roughness: 0.45
}),
nitrateN: material(0x3f7fe8, {
emissive: 0x102d7a,
emissiveIntensity: 0.25
}),
nitrateO: material(0xef6b63)
};
function mesh(geometry, mat, position, scale, rotation) {
const object = new THREE.Mesh(geometry, mat);
if (position) object.position.set(...position);
if (scale) object.scale.set(...scale);
if (rotation) object.rotation.set(...rotation);
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
return object;
}
function cylinderBetween(start, end, radius, mat, radialSegments = 7) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(radius, radius, length, radialSegments, 1, false);
const object = new THREE.Mesh(geometry, mat);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
return object;
}
function tube(points, color, radius = 0.055) {
const curve = new THREE.CatmullRomCurve3(
points.map(p => new THREE.Vector3(...p))
);
const object = new THREE.Mesh(
new THREE.TubeGeometry(curve, 28, radius, 5, false),
material(color)
);
object.castShadow = true;
scene.add(object);
return object;
}
function dashedPath(curve, color, opacity = 0.68) {
const geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(90));
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.10,
gapSize: 0.065,
depthTest: false,
depthWrite: false
})
);
line.computeLineDistances();
line.renderOrder = 4;
scene.add(line);
return line;
}
function arrowOnCurve(curve, t, color, size = 1) {
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.075 * size, 0.22 * size, 5),
material(color, { emissive: color, emissiveIntensity: 0.15 })
);
cone.position.copy(curve.getPointAt(t));
cone.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
curve.getTangentAt(t).normalize()
);
cone.castShadow = true;
cone.renderOrder = 5;
scene.add(cone);
return cone;
}
// ---------------------------------------------------------------------------
// Soil, root, branches, shoot, leaves
// ---------------------------------------------------------------------------
const soilSurface = mesh(
new THREE.CircleGeometry(4.7, 36),
material(0x876745, {
transparent: true,
opacity: 0.16,
depthWrite: false,
side: THREE.DoubleSide
}),
[0, 1.72, 0],
null,
[-Math.PI / 2, 0, 0]
);
soilSurface.castShadow = false;
const root = mesh(
new THREE.CylinderGeometry(0.235, 0.33, 5.1, 8, 4),
M.root,
[0, -0.75, 0]
);
for (let i = 0; i < 7; i++) {
const y = 1.45 - i * 0.68;
const radius = THREE.MathUtils.lerp(0.235, 0.33, (1.45 - y) / 5.1);
mesh(
new THREE.TorusGeometry(radius + 0.012, 0.022, 5, 10),
i % 2 ? M.rootLight : M.rootDark,
[0, y, 0],
null,
[Math.PI / 2, 0, 0]
);
}
// Visible schematic of a central root transport strand.
const vascularStrip = mesh(
new THREE.CylinderGeometry(0.076, 0.076, 4.65, 7),
M.vascular,
[0, -0.73, 0.286]
);
const branches = [
[[0, -1.15, 0], [-0.85, -1.55, 0.02], [-1.45, -1.85, 0.05]],
[[0, -1.72, 0], [0.72, -2.05, -0.02], [1.32, -2.28, -0.02]],
[[0, -2.18, 0], [-0.58, -2.48, 0.06], [-1.03, -2.78, 0.08]],
[[0, -0.28, 0], [-0.55, -0.42, 0.08], [-1.02, -0.48, 0.10]],
[[0, -2.55, 0], [0.48, -2.84, -0.08], [0.86, -3.12, -0.12]]
];
for (const branch of branches) {
cylinderBetween(branch[0], branch[1], 0.075, M.rootLight, 7);
cylinderBetween(branch[1], branch[2], 0.045, M.root, 6);
}
const smallNoduleMat = material(0x8ebc72);
const smallNoduleCoreMat = material(0xc78158);
for (const [x, y, z] of [
[-1.02, -0.48, 0.10],
[-1.43, -1.86, 0.06],
[1.30, -2.28, -0.01],
[-1.03, -2.79, 0.08]
]) {
const nodule = mesh(
new THREE.DodecahedronGeometry(0.22, 0),
smallNoduleMat,
[x, y, z],
[1, 0.82, 0.72]
);
nodule.rotation.set(0.2, 0.6, -0.25);
const core = mesh(
new THREE.IcosahedronGeometry(0.105, 0),
smallNoduleCoreMat,
[x + 0.04, y, z + 0.14],
[1, 0.82, 0.42]
);
core.rotation.set(0.3, 0.1, 0.5);
}
// Shoot and low-poly leaves.
cylinderBetween([0, 1.76, 0], [0.03, 3.25, 0], 0.105, M.plantDark, 7);
const leafMat = material(0x65a85b);
const leafLight = material(0x92c66f);
function addLeaf(position, scale, rotation) {
const leaf = mesh(
new THREE.IcosahedronGeometry(0.65, 1),
leafMat,
position,
scale,
rotation
);
leaf.castShadow = true;
return leaf;
}
cylinderBetween([0.02, 2.42, 0], [-0.42, 2.63, 0.02], 0.045, M.plantDark, 6);
addLeaf([-0.78, 2.69, 0.02], [1.05, 0.12, 0.39], [0.08, 0.15, 0.55]);
cylinderBetween([0.02, 2.68, 0], [0.42, 2.88, -0.02], 0.045, M.plantDark, 6);
addLeaf([0.79, 2.96, -0.02], [1.0, 0.12, 0.37], [-0.08, -0.1, -0.55]);
addLeaf([0.08, 3.30, 0], [0.34, 0.1, 0.30], [0.08, 0.3, 0.1]);
// Small low-poly soil particles.
let seed = 27;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 32; i++) {
const angle = random() * Math.PI * 2;
const radius = 0.8 + random() * 3.2;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
const y = 0.6 - random() * 3.2;
if (Math.abs(x) < 0.55) continue;
const size = 0.05 + random() * 0.09;
const stone = mesh(
new THREE.DodecahedronGeometry(size, 0),
material(random() > 0.5 ? 0x806247 : 0x9c7954),
[x, y, z],
[1.2, 0.65, 0.85]
);
stone.rotation.set(random(), random(), random());
}
// ---------------------------------------------------------------------------
// Large cutaway root nodule
// ---------------------------------------------------------------------------
const nodule = new THREE.Group();
nodule.position.set(1.30, -0.25, 0);
scene.add(nodule);
// Clip the front of the outer shell so the interior is visible.
const frontClip = new THREE.Plane(new THREE.Vector3(0, 0, -1), 0.13);
const outerShell = new THREE.Mesh(
new THREE.SphereGeometry(1.0, 14, 10),
material(0x6eac62, {
side: THREE.DoubleSide,
clippingPlanes: [frontClip],
clipShadows: true
})
);
outerShell.scale.set(1.25, 1.0, 1.0);
outerShell.castShadow = true;
outerShell.receiveShadow = true;
nodule.add(outerShell);
// Flat, pale-green cut face represents plant nodule cortex.
const cortexDisk = new THREE.Mesh(
new THREE.CylinderGeometry(0.87, 0.87, 0.10, 18),
M.plantLight
);
cortexDisk.rotation.x = Math.PI / 2;
cortexDisk.scale.x = 1.20;
cortexDisk.position.z = 0.075;
cortexDisk.castShadow = true;
cortexDisk.receiveShadow = true;
nodule.add(cortexDisk);
const cortexRim = new THREE.Mesh(
new THREE.TorusGeometry(1.02, 0.14, 6, 18),
M.plant
);
cortexRim.scale.x = 1.20;
cortexRim.position.z = 0.135;
cortexRim.castShadow = true;
nodule.add(cortexRim);
// Coral mass is the bacterial/symbiont zone.
const bacterialMass = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.60, 1),
M.bacteria
);
bacterialMass.scale.set(1.05, 0.86, 0.34);
bacterialMass.position.z = 0.19;
bacterialMass.castShadow = true;
bacterialMass.receiveShadow = true;
nodule.add(bacterialMass);
// Individual bacteria shown as tiny low-poly orange bodies.
const bacteriaParticles = [];
for (let i = 0; i < 17; i++) {
const angle = (i / 17) * Math.PI * 2 + (random() - 0.5) * 0.22;
const radiusX = 0.38 + random() * 0.13;
const radiusY = 0.28 + random() * 0.12;
const bacterium = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.065 + random() * 0.02, 0),
i % 3 === 0 ? M.bacteriaLight : M.bacteria
);
bacterium.position.set(
Math.cos(angle) * radiusX,
Math.sin(angle) * radiusY,
0.32 + random() * 0.11
);
bacterium.rotation.set(random() * 3, random() * 3, random() * 3);
bacterium.castShadow = true;
nodule.add(bacterium);
bacteriaParticles.push({
mesh: bacterium,
base: bacterium.position.clone(),
phase: random() * Math.PI * 2
});
}
// Cortex texture plates around the cut edge.
for (let i = 0; i < 11; i++) {
const angle = (i / 11) * Math.PI * 2;
const plate = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.16, 0),
i % 2 ? M.plant : M.plantDark
);
plate.position.set(
Math.cos(angle) * 1.09,
Math.sin(angle) * 0.87,
0.16
);
plate.scale.set(1.15, 0.72, 0.48);
plate.rotation.set(random(), random(), angle);
plate.castShadow = true;
nodule.add(plate);
}
// Root-to-nodule bridge and vascular connection.
tube([
[0.05, -0.26, 0.24],
[0.42, -0.30, 0.27],
[0.78, -0.27, 0.32]
], 0x719459, 0.12);
tube([
[0.03, -0.28, 0.38],
[0.48, -0.31, 0.42],
[0.91, -0.27, 0.43],
[1.28, -0.25, 0.44]
], 0x536c80, 0.065);
tube([
[0.02, -0.38, 0.41],
[0.43, -0.43, 0.44],
[0.91, -0.40, 0.45],
[1.28, -0.34, 0.46]
], 0x675681, 0.047);
// A pulsing reaction halo marks the bacterial fixation step.
const reactionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.026, 5, 24),
material(0xffc857, {
emissive: 0xffa400,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0,
depthTest: false
})
);
reactionRing.position.set(1.30, -0.25, 0.47);
reactionRing.renderOrder = 6;
scene.add(reactionRing);
const reactionLight = new THREE.PointLight(0xffbd54, 0, 2.3);
reactionLight.position.set(1.30, -0.25, 0.72);
scene.add(reactionLight);
// ---------------------------------------------------------------------------
// Symbolic chemical tokens
// ---------------------------------------------------------------------------
function makeN2() {
const group = new THREE.Group();
const atomGeometry = new THREE.OctahedronGeometry(0.11, 0);
const a = new THREE.Mesh(atomGeometry, M.n2);
a.position.x = -0.115;
a.castShadow = true;
group.add(a);
const b = new THREE.Mesh(atomGeometry, M.n2);
b.position.x = 0.115;
b.castShadow = true;
group.add(b);
const bond = new THREE.Mesh(
new THREE.CylinderGeometry(0.023, 0.023, 0.23, 5),
M.n2
);
bond.rotation.z = Math.PI / 2;
group.add(bond);
return group;
}
function makeNH4() {
const group = new THREE.Group();
const atom = new THREE.Mesh(
new THREE.OctahedronGeometry(0.17, 0),
M.nh4
);
atom.castShadow = true;
group.add(atom);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.012, 4, 16),
material(0xffc857, {
emissive: 0xff9f18,
emissiveIntensity: 0.5,
transparent: true,
opacity: 0.55,
depthTest: false
})
);
halo.renderOrder = 6;
group.add(halo);
return group;
}
function makeOrganic() {
const group = new THREE.Group();
const positions = [
new THREE.Vector3(-0.115, -0.07, 0),
new THREE.Vector3(0.115, -0.07, 0),
new THREE.Vector3(0, 0.105, 0.02)
];
positions.forEach((position, index) => {
const atom = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.095, 0),
M.organic
);
atom.position.copy(position);
atom.rotation.set(index * 0.8, index * 0.5, index * 0.3);
atom.castShadow = true;
group.add(atom);
});
const bondGeometry = new THREE.CylinderGeometry(0.018, 0.018, 0.20, 5);
for (let i = 0; i < 2; i++) {
const start = positions[i];
const end = positions[2];
const direction = end.clone().sub(start);
const bond = new THREE.Mesh(bondGeometry, M.organic);
bond.position.copy(start).add(end).multiplyScalar(0.5);
bond.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
group.add(bond);
}
return group;
}
function makeNitrate() {
const group = new THREE.Group();
const positions = [
new THREE.Vector3(0, 0.15, 0),
new THREE.Vector3(-0.13, -0.075, 0),
new THREE.Vector3(0.13, -0.075, 0)
];
positions.forEach(position => {
const oxygen = new THREE.Mesh(
new THREE.OctahedronGeometry(0.075, 0),
M.nitrateO
);
oxygen.position.copy(position);
group.add(oxygen);
});
const nitrogen = new THREE.Mesh(
new THREE.OctahedronGeometry(0.115, 0),
M.nitrateN
);
group.add(nitrogen);
const bondGeometry = new THREE.CylinderGeometry(0.014, 0.014, 0.16, 5);
positions.forEach(position => {
const direction = position.clone();
const bond = new THREE.Mesh(bondGeometry, M.nitrateN);
bond.position.copy(position).multiplyScalar(0.50);
bond.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
group.add(bond);
});
return group;
}
// ---------------------------------------------------------------------------
// Flow curves and animated flow sets
// ---------------------------------------------------------------------------
const gasCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-2.18, 1.08, 0.76),
new THREE.Vector3(-1.42, 0.98, 0.71),
new THREE.Vector3(-0.43, 0.72, 0.65),
new THREE.Vector3(0.57, 0.28, 0.60),
new THREE.Vector3(1.29, -0.25, 0.57)
]);
const fixedCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.29, -0.25, 0.57),
new THREE.Vector3(1.53, -0.25, 0.55),
new THREE.Vector3(1.78, -0.20, 0.52),
new THREE.Vector3(1.96, -0.12, 0.49)
]);
const assimilationCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.96, -0.12, 0.49),
new THREE.Vector3(2.12, 0.04, 0.47),
new THREE.Vector3(2.00, 0.20, 0.45),
new THREE.Vector3(1.72, 0.13, 0.43),
new THREE.Vector3(1.56, -0.12, 0.43)
]);
const transportCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.56, -0.12, 0.43),
new THREE.Vector3(1.10, -0.36, 0.43),
new THREE.Vector3(0.54, -0.55, 0.43),
new THREE.Vector3(0.03, -0.75, 0.43),
new THREE.Vector3(0.00, -1.50, 0.43),
new THREE.Vector3(0.00, -0.20, 0.43),
new THREE.Vector3(0.00, 1.05, 0.43)
]);
const nitrateCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-1.85, -2.28, 0.68),
new THREE.Vector3(-1.20, -2.05, 0.63),
new THREE.Vector3(-0.57, -1.76, 0.56),
new THREE.Vector3(-0.18, -1.44, 0.43)
]);
const pathSpecs = [
[gasCurve, 0x20bfb8],
[fixedCurve, 0xffc857],
[assimilationCurve, 0xa875e8],
[transportCurve, 0x8d72c8]
];
pathSpecs.forEach(([curve, color]) => {
dashedPath(curve, color);
arrowOnCurve(curve, 0.50, color, 0.9);
arrowOnCurve(curve, 0.82, color, 0.9);
});
dashedPath(nitrateCurve, 0x4c80d7, 0.42);
arrowOnCurve(nitrateCurve, 0.73, 0x4c80d7, 0.78);
const flowSets = [
{
kind: "n2",
maker: makeN2,
curve: gasCurve,
start: 0,
duration: 2.5,
count: 3
},
{
kind: "nh4",
maker: makeNH4,
curve: fixedCurve,
start: 2.5,
duration: 2.5,
count: 3
},
{
kind: "organic",
maker: makeOrganic,
curve: assimilationCurve,
start: 5,
duration: 2.5,
count: 3
},
{
kind: "organic",
maker: makeOrganic,
curve: transportCurve,
start: 7.5,
duration: 2.5,
count: 4
}
];
for (const set of flowSets) {
set.tokens = [];
for (let i = 0; i < set.count; i++) {
const token = set.maker();
token.visible = false;
scene.add(token);
set.tokens.push(token);
}
}
// Separate soil-nitrate route.
const nitrateTokens = [];
for (let i = 0; i < 2; i++) {
const token = makeNitrate();
token.scale.setScalar(0.82);
scene.add(token);
nitrateTokens.push(token);
}
// ---------------------------------------------------------------------------
// DOM callouts and leader lines
// ---------------------------------------------------------------------------
const callouts = [
document.getElementById("callout0"),
document.getElementById("callout1"),
document.getElementById("callout2"),
document.getElementById("callout3")
];
const anchors = [
gasCurve.getPointAt(0.40),
new THREE.Vector3(1.30, -0.25, 0.57),
new THREE.Vector3(2.00, 0.04, 0.47),
new THREE.Vector3(0.00, -1.28, 0.43)
];
const leaderColors = ["#20bfb8", "#e59c2f", "#a875e8", "#675681"];
const leaderElements = callouts.map((_, i) => {
const group = document.getElementById(`leader${i}`);
return {
line: group.querySelector("line"),
circle: group.querySelector("circle")
};
});
const nitrateLeader = (() => {
const group = document.getElementById("leaderN");
return {
line: group.querySelector("line"),
circle: group.querySelector("circle")
};
})();
const nitrateNote = document.getElementById("nitrate-note");
function desktopPositions() {
return [
{ x: 0.09, y: 0.39 },
{ x: 0.48, y: 0.18 },
{ x: 0.67, y: 0.53 },
{ x: 0.36, y: 0.71 }
];
}
function mobilePositions() {
return [
{ x: 0.12, y: 0.43 },
{ x: 0.54, y: 0.25 },
{ x: 0.56, y: 0.59 },
{ x: 0.19, y: 0.76 }
];
}
function projectedPoint(worldPoint) {
const point = worldPoint.clone().project(camera);
return {
x: (point.x * 0.5 + 0.5) * window.innerWidth,
y: (-point.y * 0.5 + 0.5) * window.innerHeight,
visible: point.z >= -1 && point.z <= 1
};
}
function updateCallouts(activeStage) {
const positions = window.innerWidth < 620
? mobilePositions()
: desktopPositions();
callouts.forEach((callout, i) => {
const pos = positions[i];
const labelX = pos.x * window.innerWidth;
const labelY = pos.y * window.innerHeight;
callout.style.left = `${pos.x * 100}%`;
callout.style.top = `${pos.y * 100}%`;
callout.classList.toggle("active", i === activeStage);
const anchor = projectedPoint(anchors[i]);
const leader = leaderElements[i];
leader.line.setAttribute("x1", labelX);
leader.line.setAttribute("y1", labelY);
leader.line.setAttribute("x2", anchor.x);
leader.line.setAttribute("y2", anchor.y);
leader.line.setAttribute("stroke", leaderColors[i]);
leader.line.setAttribute("opacity", i === activeStage ? "0.85" : "0.30");
leader.circle.setAttribute("cx", anchor.x);
leader.circle.setAttribute("cy", anchor.y);
leader.circle.setAttribute("fill", leaderColors[i]);
leader.circle.setAttribute("opacity", i === activeStage ? "1" : "0.45");
});
const mobileNitrate = window.innerWidth < 620
? { x: 0.18, y: 0.61 }
: { x: 0.13, y: 0.62 };
nitrateNote.style.left = `${mobileNitrate.x * 100}%`;
nitrateNote.style.top = `${mobileNitrate.y * 100}%`;
const nitrateAnchor = projectedPoint(nitrateCurve.getPointAt(0.72));
nitrateLeader.line.setAttribute("x1", mobileNitrate.x * window.innerWidth);
nitrateLeader.line.setAttribute("y1", mobileNitrate.y * window.innerHeight);
nitrateLeader.line.setAttribute("x2", nitrateAnchor.x);
nitrateLeader.line.setAttribute("y2", nitrateAnchor.y);
nitrateLeader.line.setAttribute("stroke", "#4c80d7");
nitrateLeader.line.setAttribute("opacity", "0.48");
nitrateLeader.circle.setAttribute("cx", nitrateAnchor.x);
nitrateLeader.circle.setAttribute("cy", nitrateAnchor.y);
nitrateLeader.circle.setAttribute("fill", "#4c80d7");
nitrateLeader.circle.setAttribute("opacity", "0.72");
}
// ---------------------------------------------------------------------------
// Direct camera controls: no external controls/addons
// ---------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.006,
0.38,
2.62
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * factor,
6.1,
15
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
spherical.copy(defaultSpherical);
});
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------------
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const motionScale = reducedMotion ? 0.25 : 1;
let elapsed = 0;
function updateFlowSet(set, phase) {
const local = phase - set.start;
const active = local >= 0 && local < set.duration;
set.tokens.forEach((token, i) => {
token.visible = active;
if (!active) return;
const progress = (local / set.duration + i / set.count) % 1;
token.position.copy(set.curve.getPointAt(progress));
const envelope = THREE.MathUtils.clamp(
Math.min(local / 0.16, (set.duration - local) / 0.16),
0,
1
);
const pulse = 0.92 + Math.sin(elapsed * 5 + i * 1.7) * 0.07;
token.scale.setScalar(pulse * envelope);
token.rotation.y = elapsed * 0.45 + i;
token.rotation.z = Math.sin(elapsed * 2 + i) * 0.14;
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta * motionScale;
const cycle = 10;
const phase = elapsed % cycle;
const activeStage = Math.min(3, Math.floor(phase / 2.5));
flowSets.forEach(set => updateFlowSet(set, phase));
// Animate the separate soil-nitrate uptake route.
nitrateTokens.forEach((token, i) => {
const progress = (elapsed * 0.115 + i * 0.5) % 1;
token.position.copy(nitrateCurve.getPointAt(progress));
token.rotation.y = elapsed * 0.35 + i;
token.rotation.z = Math.sin(elapsed + i) * 0.1;
});
// Highlight bacterial fixation while stage 2 is active.
const fixationStrength = phase >= 2.5 && phase < 5
? Math.sin((phase - 2.5) / 2.5 * Math.PI)
: 0;
reactionRing.material.opacity = 0.20 + fixationStrength * 0.75;
reactionRing.scale.setScalar(0.86 + fixationStrength * 0.30 + Math.sin(elapsed * 4) * 0.03);
reactionRing.rotation.z = elapsed * 0.28;
reactionLight.intensity = fixationStrength * 2.1;
// Subtle movement in the bacterial colony.
bacteriaParticles.forEach((bacterium, i) => {
bacterium.mesh.position.x =
bacterium.base.x + Math.sin(elapsed * 2.1 + bacterium.phase) * 0.012;
bacterium.mesh.position.y =
bacterium.base.y + Math.cos(elapsed * 1.7 + bacterium.phase) * 0.010;
bacterium.mesh.rotation.z += delta * (0.25 + (i % 3) * 0.08);
});
bacterialMass.scale.z = 0.34 + Math.sin(elapsed * 2.3) * 0.018;
nodule.rotation.z = Math.sin(elapsed * 0.32) * 0.006;
updateCamera();
updateCallouts(activeStage);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```