Prompt specification
Build or customize the Three.js 3D scene "Plant stem water-path exhibit" 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: Plant stem water-path exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/plant-stem-water-path-exhibit-x1447
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: plant stem water-path exhibit. Compose a stem cross section, a water reservoir, and a narrow-channel analogy; explain that real plant water transport includes mechanisms beyond simple capillary rise. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (plant-stem-water-path-exhibit-x1447):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Exhibit — Plant Water Transport</title>
<style>
:root {
--ink: #24332d;
--muted: #64736c;
--paper: #f7f2e8;
--panel: rgba(255, 252, 245, 0.92);
--line: rgba(36, 51, 45, 0.14);
--green: #3d7b52;
--water: #238db4;
--xylem: #19a6a6;
--bark: #75503b;
--amber: #dc824d;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee8dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.topbar {
position: absolute;
top: 24px;
left: 26px;
max-width: 470px;
text-shadow: 0 1px 0 rgba(255,255,255,.65);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 3px;
background: var(--green);
border-radius: 2px;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 44px);
line-height: .98;
letter-spacing: -.045em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
font-weight: 550;
}
.info-card {
position: absolute;
top: 24px;
right: 24px;
width: min(355px, calc(100vw - 48px));
max-height: calc(100vh - 48px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(255,255,255,.85);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(62, 55, 42, .13),
inset 0 0 0 1px rgba(36,51,45,.05);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.mode-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
padding: 4px;
border-radius: 11px;
background: #eae4d8;
}
.mode-tabs button {
border: 0;
border-radius: 8px;
padding: 9px 8px;
color: #68746e;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: .06em;
text-transform: uppercase;
transition: .18s ease;
}
.mode-tabs button.active {
color: #fff;
background: var(--green);
box-shadow: 0 4px 12px rgba(61,123,82,.22);
}
.info-card h2 {
margin: 17px 0 7px;
font-size: 18px;
letter-spacing: -.025em;
}
.info-card p {
margin: 0 0 12px;
color: #52615a;
font-size: 13px;
line-height: 1.52;
}
.info-card ul {
margin: 0;
padding: 0;
list-style: none;
}
.info-card li {
position: relative;
margin: 0 0 10px;
padding: 0 0 0 18px;
color: #45554d;
font-size: 12px;
line-height: 1.45;
}
.info-card li::before {
content: "";
position: absolute;
left: 1px;
top: .48em;
width: 7px;
height: 7px;
background: var(--water);
border-radius: 2px;
}
.note {
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #778179;
font-size: 10px;
line-height: 1.4;
letter-spacing: .04em;
text-transform: uppercase;
}
.legend {
position: absolute;
left: 26px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 9px 15px;
max-width: 490px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 12px;
background: rgba(255,252,245,.78);
box-shadow: 0 8px 25px rgba(62,55,42,.08);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 750;
letter-spacing: .035em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 7px;
pointer-events: auto;
}
.controls button {
border: 1px solid rgba(36,51,45,.12);
border-radius: 10px;
padding: 10px 12px;
color: #3e4d45;
background: rgba(255,252,245,.9);
box-shadow: 0 7px 20px rgba(62,55,42,.09);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: transform .15s ease, background .15s ease;
}
.controls button:hover { transform: translateY(-2px); }
.controls button[aria-pressed="true"] {
color: white;
background: #335f49;
border-color: #335f49;
}
.hint {
position: absolute;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
color: rgba(44,59,51,.65);
background: rgba(255,255,255,.52);
font-size: 10px;
font-weight: 700;
letter-spacing: .04em;
white-space: nowrap;
}
.world-label {
position: absolute;
z-index: 3;
min-width: 132px;
padding: 9px 11px 10px;
border: 1px solid rgba(255,255,255,.9);
border-radius: 10px;
background: rgba(255,252,245,.9);
box-shadow: 0 8px 24px rgba(62,55,42,.12);
transform: translate(-50%, -100%);
transition: opacity .2s ease;
backdrop-filter: blur(9px);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 23px;
background: rgba(43,69,54,.45);
}
.world-label::before {
content: "";
position: absolute;
left: calc(50% - 3px);
top: calc(100% + 20px);
width: 7px;
height: 7px;
border-radius: 50%;
background: #3b7551;
box-shadow: 0 0 0 3px rgba(255,255,255,.75);
}
.world-label strong {
display: block;
color: #304139;
font-size: 10px;
letter-spacing: .085em;
text-transform: uppercase;
}
.world-label small {
display: block;
margin-top: 3px;
color: #718078;
font-size: 10px;
}
body.labels-off .world-label { opacity: 0; }
@media (max-width: 780px) {
.topbar {
top: 15px;
left: 15px;
max-width: calc(100vw - 30px);
}
.subtitle { display: none; }
.info-card {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 39vh;
padding: 13px;
border-radius: 14px;
}
.info-card h2 { margin-top: 11px; font-size: 16px; }
.info-card p { font-size: 12px; margin-bottom: 8px; }
.info-card li { font-size: 11px; margin-bottom: 7px; }
.note { display: none; }
.legend { display: none; }
.hint { display: none; }
.controls {
top: 92px;
right: 10px;
bottom: auto;
flex-direction: column;
}
.controls button {
padding: 8px 10px;
font-size: 10px;
}
.world-label {
min-width: 108px;
padding: 7px 8px;
}
.world-label strong { font-size: 8px; }
.world-label small { font-size: 8px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel exhibit showing a water reservoir, a narrow capillary channel, and a plant stem cross-section"></canvas>
<div class="ui">
<header class="topbar">
<div class="eyebrow">Voxel science exhibit · 03 models</div>
<h1>The plant water path</h1>
<p class="subtitle">Stored water, capillary action, and the biological forces that move water upward.</p>
</header>
<aside class="info-card" aria-label="Exhibit explanation">
<div class="mode-tabs" role="tablist" aria-label="Choose explanation">
<button type="button" role="tab" data-mode="capillary">Channel model</button>
<button type="button" role="tab" class="active" data-mode="plant">Real plant</button>
</div>
<h2 id="mode-title">Plants use more than capillary rise</h2>
<p id="mode-intro">
The narrow channel isolates one force. In a living plant, evaporation and the
whole water column work together.
</p>
<ul id="mode-list">
<li><strong>Transpiration pull</strong> from leaves is usually the main upward driver.</li>
<li><strong>Cohesion and adhesion</strong> help maintain a continuous water column.</li>
<li><strong>Root pressure</strong> can contribute, but usually cannot raise water to a tall crown alone.</li>
<li>Hydraulic resistance and <strong>cavitation</strong> limit and regulate the flow.</li>
</ul>
<div class="note">Conceptual scale · colors identify materials · not to scale</div>
</aside>
<div class="legend" aria-label="Color legend">
<span><i class="dot" style="background:#238db4"></i>Water</span>
<span><i class="dot" style="background:#19a6a6"></i>Xylem</span>
<span><i class="dot" style="background:#91b96e"></i>Stem tissue</span>
<span><i class="dot" style="background:#75503b"></i>Bark</span>
<span><i class="dot" style="background:#dc824d"></i>Reference height</span>
</div>
<div class="controls">
<button id="flow-toggle" type="button" aria-pressed="true">Flow: on</button>
<button id="labels-toggle" type="button" aria-pressed="true">Labels: on</button>
<button id="reset-view" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · wheel or pinch to zoom · arrow keys also work</div>
</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,
alpha: false
});
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("#eee8dc");
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.72,
phi: 1.02,
radius: 17,
targetTheta: 0.72,
targetPhi: 1.02,
targetRadius: 17,
target: new THREE.Vector3(0, 2.15, 0)
};
function applyCamera() {
const aspect = window.innerWidth / window.innerHeight;
const fit = aspect < 0.75 ? 1.68 : aspect < 1.15 ? 1.28 : 1;
const radius = orbit.radius * fit;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + radius * Math.cos(orbit.phi),
orbit.target.z + radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
applyCamera();
const hemi = new THREE.HemisphereLight("#ffffff", "#b8aa91", 2.0);
scene.add(hemi);
const key = new THREE.DirectionalLight("#fff7df", 3.0);
key.position.set(8, 13, 9);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -13;
key.shadow.camera.right = 13;
key.shadow.camera.top = 13;
key.shadow.camera.bottom = -13;
key.shadow.camera.near = 1;
key.shadow.camera.far = 40;
key.shadow.bias = -0.0004;
scene.add(key);
const fill = new THREE.DirectionalLight("#c9e6ef", 1.1);
fill.position.set(-9, 6, -7);
scene.add(fill);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, opacity = 1) {
const key = `${color}-${opacity}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.015,
transparent: opacity < 1,
opacity,
depthWrite: opacity === 1
}));
}
return materialCache.get(key);
}
function addBox(parent, x, y, z, width, height, depth, color, options = {}) {
const material = options.material || getMaterial(
options.color || color,
options.opacity ?? 1
);
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.castShadow ?? (options.opacity ?? 1) === 1;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addVoxelLine(parent, a, b, color, size = 0.16, step = 0.16) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const distance = start.distanceTo(end);
const count = Math.max(1, Math.ceil(distance / step));
for (let i = 0; i <= count; i++) {
const t = i / count;
const p = start.clone().lerp(end, t);
addBox(parent, p.x, p.y, p.z, size, size, size, color);
}
}
const world = new THREE.Group();
scene.add(world);
// Ground and exhibit plinth.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
getMaterial("#e8e1d4")
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.53;
ground.receiveShadow = true;
scene.add(ground);
addBox(world, 0, -0.27, 0, 14.2, 0.5, 8.3, "#cdbfa8");
addBox(world, 0, -0.015, 0, 14.05, 0.07, 8.15, "#eee6d6");
// Subtle floor tiles.
for (let x = -6; x <= 6; x += 2) {
for (let z = -3; z <= 3; z += 2) {
addBox(
world,
x, 0.035, z,
1.88, 0.025, 1.88,
(x + z) % 4 === 0 ? "#e7dfd0" : "#ebe3d5"
);
}
}
// Section dividers.
addBox(world, -2.75, 0.07, 0, 0.07, 0.035, 6.7, "#bba98f");
addBox(world, 0.75, 0.07, 0, 0.07, 0.035, 6.7, "#bba98f");
// ---------------------------------------------------------------
// 1. WATER RESERVOIR
// ---------------------------------------------------------------
const reservoir = new THREE.Group();
reservoir.position.set(-4.65, 0, 0.62);
world.add(reservoir);
const basinColor = "#8b9691";
const basinLight = "#a6aea7";
addBox(reservoir, 0, 0.14, 0, 2.92, 0.20, 2.30, basinColor);
addBox(reservoir, -1.38, 0.73, 0, 0.28, 1.12, 2.36, basinColor);
addBox(reservoir, 1.38, 0.73, 0, 0.28, 1.12, 2.36, basinColor);
addBox(reservoir, 0, 0.73, -1.04, 2.82, 1.12, 0.28, basinColor);
addBox(reservoir, 0, 0.73, 1.04, 2.82, 1.12, 0.28, basinLight);
// Voxel water tiles.
const surfaceTiles = [];
for (let ix = 0; ix < 7; ix++) {
for (let iz = 0; iz < 5; iz++) {
const x = -1.08 + ix * 0.36;
const z = -0.72 + iz * 0.36;
const color = (ix + iz) % 3 === 0 ? "#249dc1" : "#238db4";
addBox(reservoir, x, 0.52, z, 0.335, 0.57, 0.335, color, {
opacity: 0.9
});
const top = addBox(
reservoir, x, 0.825, z,
0.34, 0.055, 0.34,
(ix + iz) % 2 === 0 ? "#54bdd2" : "#3caec8"
);
surfaceTiles.push({ mesh: top, baseY: 0.825, phase: ix * 0.6 + iz * 0.9 });
}
}
// Level gauge.
addBox(reservoir, -1.62, 0.72, 0.72, 0.16, 1.25, 0.18, "#f4eee1");
for (let i = 0; i < 5; i++) {
addBox(
reservoir,
-1.70, 0.32 + i * 0.20, 0.83,
0.14, 0.055, 0.08,
i < 3 ? "#238db4" : "#dc824d"
);
}
// ---------------------------------------------------------------
// 2. NARROW-CHANNEL CAPILLARY ANALOGY
// ---------------------------------------------------------------
const channel = new THREE.Group();
channel.position.set(-1.42, 0, 0.63);
world.add(channel);
// Feed from reservoir toward the base of the slit.
for (let i = 0; i < 7; i++) {
addBox(
channel,
-1.61 + i * 0.26, 0.57, 0,
0.235, 0.20, 0.46,
i % 2 ? "#238db4" : "#2b9dbd"
);
}
const glassMaterial = new THREE.MeshStandardMaterial({
color: "#d8f0f4",
roughness: 0.25,
metalness: 0,
transparent: true,
opacity: 0.26,
depthWrite: false
});
// Two transparent voxel walls form a very narrow slit.
for (let i = 0; i < 10; i++) {
const y = 0.35 + i * 0.30;
addBox(channel, -0.34, y, 0, 0.17, 0.285, 0.65, "#d8f0f4", {
material: glassMaterial,
castShadow: false
});
addBox(channel, 0.34, y, 0, 0.17, 0.285, 0.65, "#d8f0f4", {
material: glassMaterial,
castShadow: false
});
// Wetting strips emphasize adhesion at the channel walls.
addBox(channel, -0.245, y, 0, 0.035, 0.275, 0.58, "#79d3df", {
opacity: 0.7
});
addBox(channel, 0.245, y, 0, 0.035, 0.275, 0.58, "#79d3df", {
opacity: 0.7
});
}
// Water column within the slit.
for (let i = 0; i < 9; i++) {
addBox(
channel,
0, 0.40 + i * 0.285, 0,
0.18, 0.27, 0.48,
i % 2 ? "#2aa8c6" : "#238db4"
);
}
addBox(channel, 0, 2.89, 0, 0.25, 0.07, 0.53, "#7de0e7");
addBox(channel, 0, 3.02, 0, 0.98, 0.055, 0.12, "#dc824d");
addBox(channel, -0.47, 3.02, 0, 0.09, 0.14, 0.12, "#dc824d");
addBox(channel, 0.47, 3.02, 0, 0.09, 0.14, 0.12, "#dc824d");
// ---------------------------------------------------------------
// 3. PLANT STEM CUTAWAY
// ---------------------------------------------------------------
const plant = new THREE.Group();
plant.position.set(3.2, 0, -0.10);
world.add(plant);
const cell = 0.43;
const stemX = 0;
const stemZ = 0;
const tissueColors = ["#91b96e", "#a1c47b", "#86ad63", "#9abd75"];
const barkColors = ["#75503b", "#684733", "#7f5940"];
// Voxel stem: bark outside, living tissue inside, exposed front section.
for (let layer = 0; layer < 11; layer++) {
const y = 0.32 + layer * cell;
for (let ix = -3; ix <= 3; ix++) {
for (let iz = -2; iz <= 2; iz++) {
const x = stemX + ix * cell;
const z = stemZ + iz * cell;
const isBark =
Math.abs(ix) === 3 ||
iz === -2 ||
(iz === 2 && Math.abs(ix) === 3);
const color = isBark
? barkColors[(layer + Math.abs(ix)) % barkColors.length]
: tissueColors[(layer + ix + iz + 9) % tissueColors.length];
addBox(plant, x, y, z, 0.395, 0.395, 0.395, color);
}
}
}
// Xylem conduits on the exposed section.
const xylemOffsets = [-0.43, 0, 0.43];
xylemOffsets.forEach((offset, index) => {
for (let layer = 0; layer < 11; layer++) {
const y = 0.32 + layer * cell;
addBox(
plant,
offset, y, 0.895,
index === 1 ? 0.15 : 0.12,
0.365,
0.085,
"#159fa5"
);
}
});
// Root uptake / lower xylem at the base.
addVoxelLine(plant, [0, 0.25, 0.89], [0, 0.15, 1.25], "#159fa5", 0.13, 0.12);
addVoxelLine(plant, [0, 0.18, 1.18], [-0.58, 0.13, 1.46], "#159fa5", 0.11, 0.11);
addVoxelLine(plant, [0, 0.18, 1.18], [0.62, 0.13, 1.46], "#159fa5", 0.11, 0.11);
addVoxelLine(plant, [-0.55, 0.13, 1.45], [-0.82, 0.12, 1.67], "#159fa5", 0.09, 0.09);
addVoxelLine(plant, [0.58, 0.13, 1.45], [0.86, 0.12, 1.67], "#159fa5", 0.09, 0.09);
// Branches and voxel leaves.
const leafColors = ["#3f8754", "#4f965f", "#69a864", "#32794c"];
addVoxelLine(plant, [0, 4.55, 0], [-1.35, 5.18, 0.02], "#75503b", 0.22, 0.16);
addVoxelLine(plant, [0, 4.58, 0], [1.30, 5.08, -0.02], "#75503b", 0.22, 0.16);
addVoxelLine(plant, [0, 4.60, 0.1], [0.36, 5.54, 0.63], "#75503b", 0.21, 0.15);
function addLeafCluster(cx, cy, cz, sx, sy, sz) {
for (let x = 0; x < sx; x++) {
for (let y = 0; y < sy; y++) {
for (let z = 0; z < sz; z++) {
const color = leafColors[(x + y + z + Math.round(cx * 2)) % leafColors.length];
addBox(
plant,
cx + (x - (sx - 1) / 2) * 0.39,
cy + (y - (sy - 1) / 2) * 0.39,
cz + (z - (sz - 1) / 2) * 0.39,
0.37, 0.37, 0.37, color
);
}
}
}
}
addLeafCluster(-1.55, 5.27, 0.02, 3, 2, 2);
addLeafCluster(-2.12, 5.52, 0.03, 2, 2, 2);
addLeafCluster(1.55, 5.15, -0.02, 3, 2, 2);
addLeafCluster(2.08, 5.40, -0.03, 2, 2, 2);
addLeafCluster(0.48, 5.67, 0.62, 2, 3, 2);
addLeafCluster(0.50, 6.03, 0.64, 2, 2, 2);
// Small blue branch segments suggest xylem continuing into leaves.
addVoxelLine(plant, [-0.70, 4.96, 0.12], [-1.35, 5.18, 0.08], "#159fa5", 0.09, 0.12);
addVoxelLine(plant, [0.70, 4.94, 0.12], [1.30, 5.08, 0.08], "#159fa5", 0.09, 0.12);
addVoxelLine(plant, [0.20, 5.15, 0.32], [0.36, 5.54, 0.63], "#159fa5", 0.08, 0.11);
// ---------------------------------------------------------------
// Animated flow markers
// ---------------------------------------------------------------
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const brightWater = new THREE.MeshBasicMaterial({ color: "#b9f4f4" });
const channelParticles = [];
for (let i = 0; i < 8; i++) {
const mesh = new THREE.Mesh(cubeGeometry, brightWater);
mesh.scale.set(0.075, 0.12, 0.075);
mesh.position.set(-1.42, 0.5, 0.63);
flowGroup.add(mesh);
channelParticles.push({
mesh,
phase: i / 8,
x: -1.42 + (i % 2 ? 0.035 : -0.035)
});
}
const stemParticles = [];
xylemOffsets.forEach((offset, column) => {
for (let i = 0; i < 4; i++) {
const mesh = new THREE.Mesh(cubeGeometry, brightWater);
mesh.scale.set(0.07, 0.12, 0.07);
mesh.position.set(3.2 + offset, 0.4, 0.97);
flowGroup.add(mesh);
stemParticles.push({
mesh,
phase: (i + column * 0.21) / 4,
x: 3.2 + offset
});
}
});
const transpirationParticles = [];
const transpirationSources = [
[-1.8, 5.65, 0.1],
[1.8, 5.50, 0.0],
[0.50, 6.30, 0.65]
];
transpirationSources.forEach((source, index) => {
for (let i = 0; i < 3; i++) {
const material = new THREE.MeshBasicMaterial({
color: "#9ae9e9",
transparent: true,
opacity: 0
});
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(0.07, 0.09, 0.07);
flowGroup.add(mesh);
transpirationParticles.push({
mesh,
material,
source,
phase: (i + index * 0.17) / 3,
drift: (i % 2 ? 1 : -1) * 0.13
});
}
});
// ---------------------------------------------------------------
// Screen-space labels projected from 3D anchors
// ---------------------------------------------------------------
const labelData = [
{
title: "01 · Water reservoir",
subtitle: "Stored water supplies the model",
anchor: new THREE.Vector3(-4.65, 1.72, 1.65)
},
{
title: "02 · Narrow channel",
subtitle: "Capillary-rise analogy",
anchor: new THREE.Vector3(-1.42, 3.65, 0.63)
},
{
title: "03 · Stem cutaway",
subtitle: "Xylem, roots, leaves, transpiration",
anchor: new THREE.Vector3(3.2, 6.55, 0.15)
}
];
const labelElements = labelData.map(data => {
const element = document.createElement("div");
element.className = "world-label";
element.innerHTML = `<strong>${data.title}</strong><small>${data.subtitle}</small>`;
document.body.appendChild(element);
return element;
});
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelData.forEach((data, index) => {
const projected = data.anchor.clone().project(camera);
const element = labelElements[index];
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible = projected.z > -1 && projected.z < 1 &&
x > -80 && x < width + 80 && y > -40 && y < height + 40;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.visibility = visible ? "visible" : "hidden";
});
}
// ---------------------------------------------------------------
// UI behavior
// ---------------------------------------------------------------
const modeContent = {
capillary: {
title: "How the narrow channel rises",
intro:
"The tiny slit makes surface forces unusually important. Water climbs without a pump in this simplified model.",
items: [
"<strong>Capillary pressure</strong> forms at the curved meniscus.",
"Adhesion wets the walls while cohesion holds water molecules together.",
"The column rises until surface forces balance the weight of the lifted water."
]
},
plant: {
title: "Plants use more than capillary rise",
intro:
"The narrow channel isolates one force. In a living plant, evaporation and the whole water column work together.",
items: [
"<strong>Transpiration pull</strong> from leaves is usually the main upward driver.",
"<strong>Cohesion and adhesion</strong> help maintain a continuous water column.",
"<strong>Root pressure</strong> can contribute, but usually cannot raise water to a tall crown alone.",
"Hydraulic resistance and <strong>cavitation</strong> limit and regulate the flow."
]
}
};
document.querySelectorAll("[data-mode]").forEach(button => {
button.addEventListener("click", () => {
const mode = button.dataset.mode;
const content = modeContent[mode];
document.querySelectorAll("[data-mode]").forEach(tab => {
tab.classList.toggle("active", tab === button);
tab.setAttribute("aria-selected", String(tab === button));
});
document.querySelector("#mode-title").textContent = content.title;
document.querySelector("#mode-intro").textContent = content.intro;
document.querySelector("#mode-list").innerHTML = content.items
.map(item => `<li>${item}</li>`)
.join("");
});
});
const flowToggle = document.querySelector("#flow-toggle");
flowToggle.addEventListener("click", () => {
const enabled = flowToggle.getAttribute("aria-pressed") !== "true";
flowToggle.setAttribute("aria-pressed", String(enabled));
flowToggle.textContent = `Flow: ${enabled ? "on" : "off"}`;
flowGroup.visible = enabled;
});
const labelsToggle = document.querySelector("#labels-toggle");
labelsToggle.addEventListener("click", () => {
const enabled = labelsToggle.getAttribute("aria-pressed") !== "true";
labelsToggle.setAttribute("aria-pressed", String(enabled));
labelsToggle.textContent = `Labels: ${enabled ? "on" : "off"}`;
document.body.classList.toggle("labels-off", !enabled);
});
document.querySelector("#reset-view").addEventListener("click", () => {
orbit.targetTheta = 0.72;
orbit.targetPhi = 1.02;
orbit.targetRadius = 17;
});
// ---------------------------------------------------------------
// Direct camera controls: no addons or external control libraries.
// ---------------------------------------------------------------
const pointers = new Map();
let activePointer = null;
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
activePointer = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
pinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && event.pointerId === activePointer) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(
orbit.targetPhi + dy * 0.005,
0.42,
1.34
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius * (pinchDistance / distance),
10,
25
);
}
pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (event.pointerId === activePointer) {
activePointer = pointers.keys().next().value ?? null;
const next = pointers.get(activePointer);
if (next) {
lastX = next.x;
lastY = next.y;
}
}
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius + event.deltaY * 0.009,
10,
25
);
}, { passive: false });
canvas.addEventListener("dblclick", () => {
orbit.targetTheta = 0.72;
orbit.targetPhi = 1.02;
orbit.targetRadius = 17;
});
window.addEventListener("keydown", event => {
const step = 0.08;
if (event.key === "ArrowLeft") orbit.targetTheta += step;
if (event.key === "ArrowRight") orbit.targetTheta -= step;
if (event.key === "ArrowUp") orbit.targetPhi = Math.max(0.42, orbit.targetPhi - step);
if (event.key === "ArrowDown") orbit.targetPhi = Math.min(1.34, orbit.targetPhi + step);
if (event.key === "+" || event.key === "=") {
orbit.targetRadius = Math.max(10, orbit.targetRadius - 0.7);
}
if (event.key === "-" || event.key === "_") {
orbit.targetRadius = Math.min(25, orbit.targetRadius + 0.7);
}
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// ---------------------------------------------------------------
// Animation
// ---------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
const damping = 1 - Math.exp(-dt * 10);
orbit.theta += (orbit.targetTheta - orbit.theta) * damping;
orbit.phi += (orbit.targetPhi - orbit.phi) * damping;
orbit.radius += (orbit.targetRadius - orbit.radius) * damping;
applyCamera();
surfaceTiles.forEach(tile => {
tile.mesh.position.y = tile.baseY + Math.sin(time * 1.8 + tile.phase) * 0.012;
});
channelParticles.forEach(particle => {
const t = (time * 0.38 + particle.phase) % 1;
particle.mesh.position.y = 0.50 + t * 2.32;
particle.mesh.position.x = particle.x + Math.sin(time * 4 + particle.phase * 9) * 0.018;
particle.mesh.visible = t < 0.94;
});
stemParticles.forEach(particle => {
const t = (time * 0.31 + particle.phase) % 1;
particle.mesh.position.y = 0.40 + t * 4.20;
particle.mesh.position.x = particle.x;
particle.mesh.visible = t < 0.96;
});
transpirationParticles.forEach(particle => {
const t = (time * 0.25 + particle.phase) % 1;
particle.mesh.position.set(
particle.source[0] + particle.drift * t,
particle.source[1] + t * 1.1,
particle.source[2] + Math.sin(t * Math.PI * 2) * 0.08
);
particle.material.opacity = Math.sin(t * Math.PI) * 0.8;
});
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```