Prompt specification
Build or customize the Three.js 3D scene "Root-fungus contact zone" 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: Root-fungus contact zone
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/root-fungus-contact-zone-x0757
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring mycorrhizal resource exchange. Model a magnified root segment beside branching fungal filaments, with a labeled exchange region; use a specific schematic association type and avoid presenting it as universal. Stylized solid forms.
Working Three.js Starter (root-fungus-contact-zone-x0757):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Arbuscular Mycorrhizal Resource Exchange</title>
<style>
:root {
--ink: #25332d;
--muted: #65736c;
--paper: #f7f8f3;
--panel: rgba(255, 255, 252, 0.88);
--border: rgba(47, 70, 59, 0.15);
--root: #bf8a58;
--fungus: #ad5577;
--phosphorus: #7657b8;
--carbon: #2f907a;
--exchange: #e9ad62;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #edf1ea;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
z-index: 10;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 22px;
box-shadow:
0 18px 48px rgba(41, 58, 50, 0.12),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 22px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 13px;
padding: 7px 10px;
border-radius: 999px;
color: #76523b;
background: #f5e5d1;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.095em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--exchange);
content: "";
box-shadow: 0 0 0 4px rgba(233, 173, 98, 0.18);
}
h1 {
margin: 0;
max-width: 330px;
font-size: clamp(25px, 3vw, 35px);
font-weight: 760;
letter-spacing: -0.035em;
line-height: 1.06;
}
.description {
margin: 13px 0 15px;
color: #58665f;
font-size: 13.5px;
line-height: 1.55;
}
.fluxes {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 13px;
}
.flux {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(48, 65, 56, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.66);
color: #47564e;
font-size: 11.5px;
font-weight: 650;
}
.flux i {
width: 9px;
height: 9px;
border-radius: 50%;
background: currentColor;
}
.flux.p {
color: var(--phosphorus);
}
.flux.c {
color: var(--carbon);
}
.scope {
margin: 0;
padding-top: 12px;
border-top: 1px solid rgba(48, 65, 56, 0.11);
color: #6c7771;
font-size: 11.5px;
line-height: 1.48;
}
.scope strong {
color: #3e4d45;
}
#legend {
right: 22px;
bottom: 22px;
width: 210px;
padding: 16px 17px;
}
.legend-title {
margin-bottom: 11px;
color: #738078;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0;
color: #526159;
font-size: 11.5px;
font-weight: 600;
}
.swatch {
width: 18px;
height: 10px;
flex: 0 0 auto;
border-radius: 999px;
background: var(--root);
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}
.swatch.fungus {
background: var(--fungus);
}
.swatch.exchange {
background: #efd8ae;
border: 2px solid #986340;
}
.swatch.p {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--phosphorus);
}
.swatch.c {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--carbon);
}
#controls {
right: 22px;
top: 22px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
#reset {
border: 1px solid var(--border);
border-radius: 999px;
padding: 9px 13px;
color: #4f5f56;
background: rgba(255, 255, 252, 0.88);
box-shadow: 0 7px 22px rgba(41, 58, 50, 0.09);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
#reset:hover {
color: #27372f;
background: #fff;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
display: flex;
align-items: flex-start;
gap: 8px;
min-width: 112px;
padding: 8px 10px;
transform: translate(-50%, -50%);
border: 1px solid rgba(47, 70, 59, 0.13);
border-radius: 11px;
background: rgba(255, 255, 252, 0.91);
box-shadow: 0 8px 22px rgba(35, 51, 43, 0.12);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
transition: opacity 120ms ease;
}
.scene-label .dot {
width: 8px;
height: 8px;
margin-top: 3px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--root);
box-shadow: 0 0 0 3px rgba(191, 138, 88, 0.15);
}
.scene-label.fungus .dot {
background: var(--fungus);
box-shadow: 0 0 0 3px rgba(173, 85, 119, 0.15);
}
.scene-label.exchange .dot {
background: var(--exchange);
box-shadow: 0 0 0 3px rgba(233, 173, 98, 0.18);
}
.scene-label.arbuscule .dot {
background: var(--fungus);
box-shadow: 0 0 0 3px rgba(173, 85, 119, 0.15);
}
.scene-label b {
display: block;
color: #304039;
font-size: 9.5px;
font-weight: 850;
letter-spacing: 0.075em;
line-height: 1.2;
text-transform: uppercase;
}
.scene-label small {
display: block;
margin-top: 3px;
color: #718078;
font-size: 9.5px;
line-height: 1.25;
}
.hidden {
opacity: 0;
}
#hint {
left: 50%;
bottom: 22px;
transform: translateX(-50%);
padding: 9px 13px;
border: 1px solid rgba(47, 70, 59, 0.1);
border-radius: 999px;
color: #69766e;
background: rgba(255, 255, 252, 0.72);
font-size: 10.5px;
font-weight: 600;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: #68766e;
background: #edf1ea;
font-size: 13px;
font-weight: 700;
}
@media (max-width: 760px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
h1 {
max-width: 290px;
font-size: 24px;
}
.description {
margin: 9px 0 10px;
font-size: 11.5px;
}
.scope {
font-size: 10px;
}
#legend,
#hint {
display: none;
}
#controls {
top: auto;
right: 12px;
bottom: 12px;
}
.scene-label {
min-width: 92px;
padding: 6px 8px;
}
.scene-label small {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels">
<div id="label-root" class="scene-label">
<span class="dot"></span>
<div>
<b>Host root</b>
<small>magnified root segment</small>
</div>
</div>
<div id="label-fungus" class="scene-label fungus">
<span class="dot"></span>
<div>
<b>Fungal hyphae</b>
<small>branching filaments</small>
</div>
</div>
<div id="label-exchange" class="scene-label exchange">
<span class="dot"></span>
<div>
<b>Exchange region</b>
<small>root–fungus interface</small>
</div>
</div>
<div id="label-arbuscule" class="scene-label arbuscule">
<span class="dot"></span>
<div>
<b>Arbuscule</b>
<small>branched fungal structure</small>
</div>
</div>
</div>
<section id="intro" class="ui panel">
<div class="eyebrow">Schematic · arbuscular mycorrhizal association</div>
<h1>A two-way exchange at the root–fungus boundary</h1>
<p class="description">
In this arbuscular mycorrhizal model, fungal hyphae can deliver
phosphorus to root cortex, while the plant supplies carbon to the fungus.
</p>
<div class="fluxes" aria-label="Resource exchange legend">
<span class="flux p"><i></i>P → plant</span>
<span class="flux c"><i></i>plant → C</span>
</div>
<p class="scope">
<strong>Association shown—not a universal model.</strong>
This is one specific mycorrhizal pathway. Structures and resource flows
are simplified and not to scale.
</p>
</section>
<aside id="legend" class="ui panel" aria-label="Visual key">
<div class="legend-title">Visual key</div>
<div class="legend-item">
<span class="swatch"></span>
Host root tissue
</div>
<div class="legend-item">
<span class="swatch fungus"></span>
Fungal hyphae
</div>
<div class="legend-item">
<span class="swatch exchange"></span>
Exchange cortex
</div>
<div class="legend-item">
<span class="swatch p"></span>
Phosphorus
</div>
<div class="legend-item">
<span class="swatch c"></span>
Carbon
</div>
</aside>
<div id="controls" class="ui">
<button id="reset" type="button" aria-label="Reset camera view">
Reset view
</button>
</div>
<div id="hint" class="ui">Drag to orbit · Scroll to zoom · Arrow keys also work</div>
<div id="loading">Building the magnified root–fungus schematic…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xedf1ea);
scene.fog = new THREE.Fog(0xedf1ea, 11, 20);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional schematic of an arbuscular mycorrhizal exchange region"
);
renderer.domElement.tabIndex = 0;
sceneHost.appendChild(renderer.domElement);
const target = new THREE.Vector3(0.35, -0.05, 0);
const orbit = {
theta: 0.18,
phi: 1.18,
radius: 9.6
};
const defaultOrbit = { ...orbit };
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
updateCamera();
// Lighting and soft shadows.
scene.add(new THREE.HemisphereLight(0xffffff, 0x8a9a86, 1.85));
const keyLight = new THREE.DirectionalLight(0xfff2dc, 3.0);
keyLight.position.set(3.8, 7.2, 5.8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbdd8e5, 1.15);
fillLight.position.set(-5, 2, -4);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd3a3, 1.1);
rimLight.position.set(-2, 4, -5);
scene.add(rimLight);
// Solid presentation base.
const base = new THREE.Mesh(
new THREE.CylinderGeometry(5.55, 5.7, 0.18, 96),
new THREE.MeshStandardMaterial({
color: 0xe3e8dc,
roughness: 0.95,
metalness: 0
})
);
base.position.y = -2.18;
base.receiveShadow = true;
scene.add(base);
const materials = {
root: new THREE.MeshStandardMaterial({
color: 0xbf8a58,
roughness: 0.83,
metalness: 0
}),
rootDark: new THREE.MeshStandardMaterial({
color: 0x996844,
roughness: 0.9
}),
rootLight: new THREE.MeshStandardMaterial({
color: 0xf0d4a8,
roughness: 0.88
}),
exchangeBorder: new THREE.MeshStandardMaterial({
color: 0x8b5a3d,
roughness: 0.85
}),
fungus: new THREE.MeshStandardMaterial({
color: 0xad5577,
roughness: 0.58,
metalness: 0
}),
fungusLight: new THREE.MeshStandardMaterial({
color: 0xd47a93,
roughness: 0.6
}),
callout: new THREE.MeshStandardMaterial({
color: 0x66756d,
roughness: 0.75
}),
phosphorus: new THREE.MeshStandardMaterial({
color: 0x7657b8,
roughness: 0.38,
emissive: 0x2b1855,
emissiveIntensity: 0.12
}),
carbon: new THREE.MeshStandardMaterial({
color: 0x2f907a,
roughness: 0.38,
emissive: 0x123d33,
emissiveIntensity: 0.12
})
};
function meshShadows(object, cast = true, receive = true) {
object.castShadow = cast;
object.receiveShadow = receive;
return object;
}
function addTube(points, radius, material, options = {}) {
const {
segments = 64,
radialSegments = 10,
rounded = true,
castShadow = true
} = options;
const curve = new THREE.CatmullRomCurve3(
points.map((p) => p.clone()),
false,
"catmullrom",
0.42
);
const tube = meshShadows(
new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, radialSegments, false),
material
),
castShadow,
true
);
scene.add(tube);
if (rounded) {
const start = meshShadows(
new THREE.Mesh(new THREE.SphereGeometry(radius, 18, 12), material)
);
const end = meshShadows(
new THREE.Mesh(new THREE.SphereGeometry(radius, 18, 12), material)
);
start.position.copy(curve.getPointAt(0));
end.position.copy(curve.getPointAt(1));
scene.add(start, end);
}
return tube;
}
function rootRadiusAt(t) {
const clamped = THREE.MathUtils.clamp(t, 0, 1);
return (
0.3 +
0.46 *
Math.pow(
Math.sin(Math.PI * THREE.MathUtils.clamp(clamped, 0.001, 0.999)),
0.6
)
);
}
function createRootGeometry(curve, segments = 80, radialSegments = 28) {
const frames = curve.computeFrenetFrames(segments, false);
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const center = curve.getPointAt(t);
const normal = frames.normals[i];
const binormal = frames.binormals[i];
const baseRadius = rootRadiusAt(t);
for (let j = 0; j <= radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
const organic = 1 + 0.025 * Math.sin(angle * 3 + t * 11);
const radius = baseRadius * organic;
const vertex = center
.clone()
.addScaledVector(normal, Math.cos(angle) * radius)
.addScaledVector(binormal, Math.sin(angle) * radius);
positions.push(vertex.x, vertex.y, vertex.z);
uvs.push(j / radialSegments, t);
}
}
for (let i = 0; i < segments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * (radialSegments + 1) + j;
const b = (i + 1) * (radialSegments + 1) + j;
const c = (i + 1) * (radialSegments + 1) + j + 1;
const d = i * (radialSegments + 1) + j + 1;
indices.push(a, d, b, b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return { geometry, frames };
}
// Solid, organically tapered host root.
const rootCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-3.25, 0.12, 0),
new THREE.Vector3(-2.35, 0.28, 0.02),
new THREE.Vector3(-1.2, 0.2, -0.03),
new THREE.Vector3(0.0, 0.38, 0.02),
new THREE.Vector3(1.2, 0.25, -0.03),
new THREE.Vector3(2.35, 0.42, 0.02)
],
false,
"catmullrom",
0.45
);
const rootData = createRootGeometry(rootCurve);
const root = meshShadows(
new THREE.Mesh(rootData.geometry, materials.root)
);
scene.add(root);
// Rounded root ends.
for (const t of [0, 1]) {
const cap = meshShadows(
new THREE.Mesh(
new THREE.SphereGeometry(rootRadiusAt(t), 30, 20),
materials.root
)
);
cap.position.copy(rootCurve.getPointAt(t));
scene.add(cap);
}
// Subtle longitudinal root ridges.
for (const angle of [0.95, 2.35]) {
const ridgePoints = [];
for (let i = 0; i <= 34; i++) {
const t = 0.08 + (i / 34) * 0.84;
const center = rootCurve.getPointAt(t);
const frameIndex = Math.round(t * 80);
const normal = rootData.frames.normals[frameIndex];
const binormal = rootData.frames.binormals[frameIndex];
const radius = rootRadiusAt(t) + 0.012;
ridgePoints.push(
center
.clone()
.addScaledVector(normal, Math.cos(angle) * radius)
.addScaledVector(binormal, Math.sin(angle) * radius)
);
}
addTube(ridgePoints, 0.018, materials.rootDark, {
segments: 70,
radialSegments: 7,
rounded: false,
castShadow: false
});
}
// Exchange-region inset in the root cortex.
const exchangeT = 0.56;
const exchangeFrameIndex = Math.round(exchangeT * 80);
const patchCenter = rootCurve
.getPointAt(exchangeT)
.addScaledVector(
rootData.frames.normals[exchangeFrameIndex],
rootRadiusAt(exchangeT) * 0.88
);
const patchNormal = rootData.frames.normals[exchangeFrameIndex].clone();
const patchBorder = meshShadows(
new THREE.Mesh(new THREE.SphereGeometry(1, 48, 26), materials.exchangeBorder)
);
patchBorder.position.copy(patchCenter);
patchBorder.scale.set(0.86, 0.56, 0.115);
scene.add(patchBorder);
const patch = meshShadows(
new THREE.Mesh(new THREE.SphereGeometry(1, 48, 26), materials.rootLight)
);
patch.position.copy(patchCenter).addScaledVector(patchNormal, 0.045);
patch.scale.set(0.77, 0.47, 0.125);
scene.add(patch);
// Stylized arbuscule: a solid branching fungal structure in the cortex.
const arbusculeOrigin = patchCenter.clone().addScaledVector(patchNormal, 0.14);
const arbusculeCurves = [
[
[-0.38, -0.08],
[-0.19, -0.02],
[0.03, 0.03],
[0.27, 0.12],
[0.42, 0.25]
],
[
[-0.19, -0.02],
[-0.29, 0.17],
[-0.17, 0.31]
],
[
[-0.08, 0.01],
[-0.03, 0.23],
[0.10, 0.34]
],
[
[0.11, 0.07],
[0.18, 0.28],
[0.32, 0.36]
],
[
[0.27, 0.12],
[0.40, 0.05],
[0.49, 0.10]
],
[
[-0.02, 0.02],
[-0.08, -0.19],
[0.02, -0.28]
]
];
for (const points of arbusculeCurves) {
const worldPoints = points.map(
([x, y]) =>
new THREE.Vector3(
arbusculeOrigin.x + x,
arbusculeOrigin.y + y,
arbusculeOrigin.z
)
);
addTube(worldPoints, 0.032, materials.fungus, {
segments: 36,
radialSegments: 8
});
}
// External branching fungal filaments.
const fungalCurves = [
{
radius: 0.12,
material: materials.fungus,
points: [
[4.45, -1.18, 0.96],
[3.75, -0.95, 0.86],
[3.05, -0.62, 0.78],
[2.42, -0.35, 0.75],
[1.7, -0.12, 0.80],
[0.88, 0.12, 0.83],
[0.48, 0.29, 0.84]
]
},
{
radius: 0.085,
material: materials.fungusLight,
points: [
[2.42, -0.35, 0.75],
[2.12, 0.22, 0.71],
[1.67, 0.50, 0.70],
[1.02, 0.58, 0.77],
[0.45, 0.45, 0.84]
]
},
{
radius: 0.075,
material: materials.fungus,
points: [
[3.05, -0.62, 0.78],
[3.35, -1.17, 0.58],
[2.92, -1.65, 0.29],
[2.15, -1.82, 0.08]
]
},
{
radius: 0.068,
material: materials.fungusLight,
points: [
[3.75, -0.95, 0.86],
[4.13, -0.49, 0.50],
[4.48, 0.08, 0.18]
]
},
{
radius: 0.075,
material: materials.fungus,
points: [
[2.42, -0.35, 0.75],
[2.88, 0.10, 0.42],
[3.42, 0.39, 0.10],
[4.04, 0.49, -0.10]
]
},
{
radius: 0.062,
material: materials.fungusLight,
points: [
[1.70, -0.12, 0.80],
[1.39, -0.52, 0.51],
[1.02, -0.77, 0.26]
]
},
{
radius: 0.055,
material: materials.fungusLight,
points: [
[0.47, 0.30, 0.84],
[0.70, 0.67, 0.91],
[1.17, 0.72, 0.83],
[1.67, 0.51, 0.70]
]
}
];
for (const branch of fungalCurves) {
addTube(
branch.points.map((p) => new THREE.Vector3(...p)),
branch.radius,
branch.material,
{
segments: 76,
radialSegments: 10
}
);
}
// Junction nodes emphasize the solid, stylized construction.
for (const position of [
[3.05, -0.62, 0.78],
[2.42, -0.35, 0.75],
[1.70, -0.12, 0.80]
]) {
const node = meshShadows(
new THREE.Mesh(new THREE.SphereGeometry(0.12, 20, 14), materials.fungus)
);
node.position.set(...position);
scene.add(node);
}
function createSolidArrow(start, end, material, radius = 0.055) {
const direction = end.clone().sub(start);
const length = direction.length();
direction.normalize();
const headLength = Math.min(0.24, length * 0.34);
const shaftLength = Math.max(0.01, length - headLength);
const shaft = meshShadows(
new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, shaftLength, 14),
material
)
);
shaft.position.copy(start).addScaledVector(direction, shaftLength / 2);
shaft.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
scene.add(shaft);
const head = meshShadows(
new THREE.Mesh(
new THREE.ConeGeometry(radius * 2.35, headLength, 18),
material
)
);
head.position.copy(end).addScaledVector(direction, -headLength / 2);
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
scene.add(head);
return { start, end };
}
const phosphorusPath = createSolidArrow(
new THREE.Vector3(1.45, -0.02, 1.02),
new THREE.Vector3(0.56, 0.18, 0.90),
materials.phosphorus,
0.052
);
const carbonPath = createSolidArrow(
new THREE.Vector3(-0.05, 0.48, 0.94),
new THREE.Vector3(0.72, 0.73, 1.00),
materials.carbon,
0.052
);
// Small solid nutrient markers move along the two schematic paths.
const phosphorusMarker = meshShadows(
new THREE.Mesh(new THREE.SphereGeometry(0.075, 18, 12), materials.phosphorus)
);
const carbonMarker = meshShadows(
new THREE.Mesh(new THREE.SphereGeometry(0.075, 18, 12), materials.carbon)
);
scene.add(phosphorusMarker, carbonMarker);
function addCallout(anchor, labelPosition, material = materials.callout) {
const middle = anchor
.clone()
.lerp(labelPosition, 0.52)
.add(new THREE.Vector3(0.03, 0.08, 0));
addTube([anchor, middle, labelPosition], 0.012, material, {
segments: 28,
radialSegments: 6,
rounded: false,
castShadow: false
});
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 16, 10),
material
);
dot.position.copy(anchor);
scene.add(dot);
}
const rootLabelPoint = new THREE.Vector3(-2.02, 1.32, 0.12);
const fungusLabelPoint = new THREE.Vector3(3.72, 0.90, 0.67);
const exchangeLabelPoint = new THREE.Vector3(0.12, 1.48, 1.03);
const arbusculeLabelPoint = new THREE.Vector3(0.72, -0.46, 1.02);
addCallout(
new THREE.Vector3(-1.75, 0.74, 0.08),
rootLabelPoint,
materials.rootDark
);
addCallout(
new THREE.Vector3(3.65, -0.38, 0.81),
fungusLabelPoint,
materials.fungus
);
addCallout(
patchCenter.clone().addScaledVector(patchNormal, 0.10),
exchangeLabelPoint,
materials.exchangeBorder
);
addCallout(
arbusculeOrigin.clone().add(new THREE.Vector3(0.25, 0.02, 0)),
arbusculeLabelPoint,
materials.fungus
);
const labels = [
{
element: document.querySelector("#label-root"),
point: rootLabelPoint
},
{
element: document.querySelector("#label-fungus"),
point: fungusLabelPoint
},
{
element: document.querySelector("#label-exchange"),
point: exchangeLabelPoint
},
{
element: document.querySelector("#label-arbuscule"),
point: arbusculeLabelPoint
}
];
function positionLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const projected = label.point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.classList.toggle("hidden", !visible);
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// Direct camera controls: no addons are used.
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 deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.005,
0.55,
1.46
);
updateCamera();
});
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.006,
6.7,
13.0
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta -= 0.09;
break;
case "ArrowRight":
orbit.theta += 0.09;
break;
case "ArrowUp":
orbit.phi = Math.max(0.55, orbit.phi - 0.07);
break;
case "ArrowDown":
orbit.phi = Math.min(1.46, orbit.phi + 0.07);
break;
case "+":
case "=":
orbit.radius = Math.max(6.7, orbit.radius - 0.45);
break;
case "-":
case "_":
orbit.radius = Math.min(13, orbit.radius + 0.45);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.querySelector("#reset").addEventListener("click", () => {
Object.assign(orbit, defaultOrbit);
updateCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (!reducedMotion) {
const phosphorusT = (elapsed * 0.34) % 1;
const carbonT = 1 - ((elapsed * 0.29) % 1);
phosphorusMarker.position.lerpVectors(
phosphorusPath.start,
phosphorusPath.end,
phosphorusT
);
carbonMarker.position.lerpVectors(
carbonPath.start,
carbonPath.end,
carbonT
);
} else {
phosphorusMarker.position.copy(phosphorusPath.end);
carbonMarker.position.copy(carbonPath.end);
}
positionLabels();
renderer.render(scene, camera);
}
loading.style.display = "none";
animate();
</script>
</body>
</html>
```