Prompt specification
Build or customize the Three.js 3D scene "Leaf-to-greenhouse scale bridge" 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: Leaf-to-greenhouse scale bridge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/leaf-to-greenhouse-scale-bridge-x0791
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts leaf stomata. Compose a greenhouse bench with plants and a magnified leaf inset; synchronized controls connect visible leaf surfaces to conceptual gas exchange without pretending to simulate complete physiology. Voxel style.
Working Three.js Starter (leaf-to-greenhouse-scale-bridge-x0791):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stomata — Voxel Greenhouse</title>
<style>
:root {
--ink: #eaf7ef;
--muted: #9fb9ae;
--panel: rgba(12, 38, 35, 0.94);
--panel-deep: #0b2826;
--line: rgba(184, 225, 207, 0.2);
--mint: #65e0b7;
--teal: #42d8ce;
--gold: #ffd166;
--vapor: #b9dcff;
--warning: #ffb86b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbdcd3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(18, 51, 44, 0.12), transparent 30%),
radial-gradient(circle at 45% 42%, transparent 52%, rgba(16, 45, 40, 0.18));
z-index: 1;
}
.masthead {
position: fixed;
top: 24px;
left: 26px;
z-index: 4;
max-width: 590px;
pointer-events: none;
text-shadow: 0 2px 14px rgba(20, 50, 43, 0.3);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
background: rgba(13, 48, 41, 0.82);
border: 1px solid rgba(216, 246, 231, 0.28);
color: #d9f6e8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
background: var(--mint);
box-shadow: 0 0 12px var(--mint);
}
h1 {
margin: 12px 0 6px;
color: #f4fff7;
font-size: clamp(24px, 3vw, 42px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 800;
}
.masthead p {
margin: 0;
max-width: 540px;
color: #e6f5eb;
font-size: 13px;
line-height: 1.5;
}
.concept-badge {
position: fixed;
top: 26px;
right: 398px;
z-index: 4;
padding: 9px 12px;
border: 1px solid rgba(255, 200, 128, 0.62);
background: rgba(45, 40, 24, 0.78);
color: #ffe0aa;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.lab-panel {
position: fixed;
z-index: 5;
top: 22px;
right: 22px;
bottom: 22px;
width: 356px;
overflow: auto;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 60px rgba(18, 44, 38, 0.28);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: #416c60 transparent;
}
.panel-head {
padding: 15px 16px 12px;
border-bottom: 1px solid var(--line);
}
.panel-head-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.panel-kicker {
color: var(--mint);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.selected-chip {
padding: 5px 7px;
border: 1px solid rgba(255, 209, 102, 0.42);
background: rgba(255, 209, 102, 0.08);
color: var(--gold);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.panel-title {
margin: 8px 0 5px;
font-size: 18px;
letter-spacing: -0.025em;
}
.panel-copy {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.inset-section {
padding: 12px 12px 0;
}
.inset-viewport {
position: relative;
height: 222px;
overflow: hidden;
border: 1px solid rgba(136, 220, 193, 0.28);
background: var(--panel-deep);
}
.inset-viewport canvas {
display: block;
width: 100%;
height: 100%;
}
.inset-label {
position: absolute;
top: 9px;
left: 10px;
z-index: 2;
padding: 5px 7px;
background: rgba(5, 24, 23, 0.76);
border: 1px solid rgba(153, 229, 205, 0.22);
color: #bfe9d9;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
.inset-scale {
position: absolute;
right: 9px;
bottom: 8px;
z-index: 2;
color: #a9cbc0;
font-size: 9px;
letter-spacing: 0.08em;
pointer-events: none;
}
.inset-scale::before {
content: "";
display: block;
width: 42px;
height: 5px;
margin-bottom: 4px;
border: 1px solid #a9cbc0;
border-top: 0;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
padding: 9px 3px 11px;
color: #b8cec5;
font-size: 9px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 7px;
height: 7px;
background: currentColor;
}
.legend .co2 {
color: var(--teal);
}
.legend .o2 {
color: var(--gold);
}
.legend .water {
color: var(--vapor);
}
.section {
padding: 14px 16px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 10px;
margin-bottom: 12px;
}
.section-title h2 {
margin: 0;
font-size: 11px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.section-title span {
color: #789d90;
font-size: 9px;
}
.control {
margin-bottom: 13px;
}
.control:last-child {
margin-bottom: 0;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: #dbece4;
font-size: 11px;
}
.control-label output {
min-width: 38px;
padding: 3px 6px;
background: rgba(118, 222, 185, 0.1);
border: 1px solid rgba(118, 222, 185, 0.18);
color: #a8e8d1;
text-align: center;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 4px;
background: linear-gradient(90deg, #406f61, #6edbb4);
border-radius: 0;
}
input[type="range"]::-webkit-slider-thumb {
width: 11px;
height: 15px;
margin-top: -6px;
appearance: none;
border: 2px solid #d7f8e9;
border-radius: 0;
background: #65d8ae;
box-shadow: 0 0 0 2px rgba(8, 31, 27, 0.8);
}
input[type="range"]::-moz-range-track {
height: 4px;
background: linear-gradient(90deg, #406f61, #6edbb4);
border-radius: 0;
}
input[type="range"]::-moz-range-thumb {
width: 9px;
height: 13px;
border: 2px solid #d7f8e9;
border-radius: 0;
background: #65d8ae;
}
.preset-row,
.toggle-row {
display: flex;
gap: 6px;
margin-top: 12px;
}
.small-button {
flex: 1;
padding: 7px 6px;
border: 1px solid rgba(157, 211, 194, 0.22);
border-radius: 0;
background: rgba(103, 169, 148, 0.09);
color: #cce4da;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
}
.small-button:hover,
.small-button.active {
background: rgba(101, 224, 183, 0.17);
border-color: rgba(101, 224, 183, 0.48);
color: #eafff5;
}
.bar-row {
margin-bottom: 12px;
}
.bar-row:last-child {
margin-bottom: 0;
}
.bar-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
color: #d7e9e1;
font-size: 10px;
}
.bar-label span:last-child {
color: #88a99d;
font-variant-numeric: tabular-nums;
}
.bar {
height: 8px;
overflow: hidden;
background: rgba(196, 226, 215, 0.09);
border: 1px solid rgba(196, 226, 215, 0.1);
}
.bar i {
display: block;
width: 0;
height: 100%;
transition: width 180ms ease-out;
}
#co2Bar {
background: var(--teal);
}
#o2Bar {
background: var(--gold);
}
#waterBar {
background: var(--vapor);
}
.status {
min-height: 38px;
margin-top: 12px;
padding: 9px 10px;
border-left: 2px solid var(--mint);
background: rgba(101, 224, 183, 0.07);
color: #bcd7cc;
font-size: 10px;
line-height: 1.45;
}
.disclaimer {
padding: 13px 16px 16px;
border-top: 1px solid var(--line);
color: #819f94;
font-size: 9px;
line-height: 1.55;
}
.disclaimer strong {
display: block;
margin-bottom: 4px;
color: var(--warning);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.camera-toolbar {
position: fixed;
z-index: 4;
left: 24px;
bottom: 24px;
display: flex;
gap: 5px;
padding: 5px;
background: rgba(11, 42, 37, 0.84);
border: 1px solid rgba(177, 222, 206, 0.24);
backdrop-filter: blur(10px);
}
.camera-button {
min-width: 44px;
height: 31px;
padding: 0 9px;
border: 1px solid transparent;
border-radius: 0;
background: transparent;
color: #c6ddd3;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
}
.camera-button:hover {
border-color: rgba(101, 224, 183, 0.35);
background: rgba(101, 224, 183, 0.1);
color: white;
}
.hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 29px;
transform: translateX(-50%);
padding: 8px 12px;
background: rgba(11, 42, 37, 0.76);
border: 1px solid rgba(177, 222, 206, 0.2);
color: #c2d9cf;
font-size: 10px;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #173c35;
color: #bce9d8;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#loading::before {
content: "";
width: 14px;
height: 14px;
margin-right: 12px;
background: var(--mint);
box-shadow: 7px 7px 0 rgba(101, 224, 183, 0.35);
animation: loading 900ms steps(2, end) infinite;
}
@keyframes loading {
50% {
transform: translate(5px, 5px);
}
}
@media (max-width: 980px) {
.concept-badge {
right: 356px;
}
.masthead {
max-width: 470px;
}
.hint {
display: none;
}
}
@media (max-width: 760px) {
.masthead {
top: 14px;
left: 14px;
max-width: calc(100% - 28px);
}
.masthead p {
max-width: 390px;
font-size: 11px;
}
.concept-badge {
display: none;
}
.lab-panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 55vh;
}
.inset-viewport {
height: 175px;
}
.camera-toolbar {
top: 125px;
bottom: auto;
left: 14px;
}
.camera-button {
min-width: 38px;
padding: 0 7px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="vignette"></div>
<header class="masthead">
<div class="eyebrow">Voxel botany / greenhouse study 04</div>
<h1>Stomata at the greenhouse bench</h1>
<p>
Orbit the voxel canopy and select a leaf to inspect its surface.
One control state drives the canopy markers, magnified inset, and relative exchange cues.
</p>
</header>
<div class="concept-badge">Conceptual map · not predictive</div>
<aside class="lab-panel" aria-label="Conceptual stomata controls">
<div class="panel-head">
<div class="panel-head-row">
<span class="panel-kicker">Surface inspector</span>
<span class="selected-chip" id="selectedLeaf">Leaf 01</span>
</div>
<h2 class="panel-title">Magnified leaf surface</h2>
<p class="panel-copy">
Guard-cell pairs are schematic. The opening shown here follows the aperture control.
</p>
</div>
<div class="inset-section">
<div class="inset-viewport" id="insetViewport">
<div class="inset-label">Selected leaf · surface view</div>
<div class="inset-scale">Schematic ×40</div>
</div>
<div class="legend" aria-label="Exchange cue legend">
<span class="co2"><i></i>CO₂ inward cue</span>
<span class="o2"><i></i>O₂ outward cue</span>
<span class="water"><i></i>Water-vapor cue</span>
</div>
</div>
<section class="section">
<div class="section-title">
<h2>Shared controls</h2>
<span>All visible leaves</span>
</div>
<div class="control">
<label class="control-label" for="light">
<span>Light availability</span>
<output id="lightValue" for="light">68</output>
</label>
<input id="light" type="range" min="0" max="100" value="68">
</div>
<div class="control">
<label class="control-label" for="co2">
<span>CO₂ availability</span>
<output id="co2Value" for="co2">52</output>
</label>
<input id="co2" type="range" min="0" max="100" value="52">
</div>
<div class="control">
<label class="control-label" for="humidity">
<span>Humidity</span>
<output id="humidityValue" for="humidity">58</output>
</label>
<input id="humidity" type="range" min="0" max="100" value="58">
</div>
<div class="control">
<label class="control-label" for="aperture">
<span>Stomatal aperture</span>
<output id="apertureValue" for="aperture">55</output>
</label>
<input id="aperture" type="range" min="0" max="100" value="55">
</div>
<div class="preset-row">
<button class="small-button" data-preset="balanced" type="button">Balanced</button>
<button class="small-button" data-preset="open" type="button">Open pores</button>
<button class="small-button" data-preset="closed" type="button">Close pores</button>
</div>
<div class="toggle-row">
<button
class="small-button active"
id="markersToggle"
type="button"
aria-pressed="true"
>Surface markers</button>
<button
class="small-button active"
id="motesToggle"
type="button"
aria-pressed="true"
>Exchange cues</button>
</div>
</section>
<section class="section">
<div class="section-title">
<h2>Relative exchange cues</h2>
<span>0–100 · no physical units</span>
</div>
<div class="bar-row">
<div class="bar-label">
<span>CO₂ inward tendency</span>
<span id="co2Index">0</span>
</div>
<div class="bar"><i id="co2Bar"></i></div>
</div>
<div class="bar-row">
<div class="bar-label">
<span>O₂ outward tendency</span>
<span id="o2Index">0</span>
</div>
<div class="bar"><i id="o2Bar"></i></div>
</div>
<div class="bar-row">
<div class="bar-label">
<span>Water-vapor outward tendency</span>
<span id="waterIndex">0</span>
</div>
<div class="bar"><i id="waterBar"></i></div>
</div>
<div class="status" id="statusText" aria-live="polite">
The shared aperture control is opening the schematic pores.
</div>
</section>
<div class="disclaimer">
<strong>Teaching model, not physiology simulation</strong>
The displayed relationships and colored cues are illustrative only.
They are not measured fluxes, rates, concentrations, or predictions.
Real stomatal behavior also depends on temperature, vapor-pressure deficit,
tissue demand, transport, species, and time.
</div>
</aside>
<nav class="camera-toolbar" aria-label="Camera views">
<button class="camera-button" data-view="reset" type="button">Reset</button>
<button class="camera-button" data-view="front" type="button">Front</button>
<button class="camera-button" data-view="side" type="button">Side</button>
<button class="camera-button" data-view="top" type="button">Top</button>
</nav>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Click a leaf</div>
<div id="loading">Building greenhouse</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const clamp = THREE.MathUtils.clamp;
const stage = $("#stage");
const insetViewport = $("#insetViewport");
const state = {
light: 68,
co2: 52,
humidity: 58,
aperture: 55,
showMarkers: true,
showMotes: true,
selectedLeaf: 0
};
// -----------------------------------------------------------------------
// Shared procedural helpers
// -----------------------------------------------------------------------
let randomSeed = 1437;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.0,
flatShading: true,
...options
});
}
function basicMaterial(color, options = {}) {
return new THREE.MeshBasicMaterial({
color,
...options
});
}
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function cube(parent, sx, sy, sz, x, y, z, material, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -----------------------------------------------------------------------
// Main greenhouse renderer and scene
// -----------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel greenhouse. Drag to orbit, scroll to zoom, and click a leaf."
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbdcd3);
scene.fog = new THREE.Fog(0xcbdcd3, 18, 38);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf5fff8, 0x526d61, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5dc, 3.4);
sun.position.set(-5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8edbd2, 1.1);
fill.position.set(7, 5, -5);
scene.add(fill);
const materials = {
frame: standardMaterial(0xe2eee7),
frameDark: standardMaterial(0x87a99c),
glass: standardMaterial(0x8fc5bd, {
transparent: true,
opacity: 0.15,
depthWrite: false,
roughness: 0.25,
side: THREE.DoubleSide
}),
floor: standardMaterial(0x718c80),
floorLight: standardMaterial(0x91a89d),
floorDark: standardMaterial(0x647d72),
bench: standardMaterial(0xb4875e),
benchEdge: standardMaterial(0x805c3d),
pot: standardMaterial(0xb96845),
potLight: standardMaterial(0xcd7950),
soil: standardMaterial(0x3b3a2d),
stem: standardMaterial(0x39744d),
vein: standardMaterial(0x74a85d),
guard: standardMaterial(0x244f3c),
pore: standardMaterial(0x10251f),
sensor: standardMaterial(0xd7e4d9),
screen: standardMaterial(0x173e38, { emissive: 0x0b221d }),
beacon: basicMaterial(0xffd166)
};
// Greenhouse floor.
cube(scene, 16.5, 0.34, 14.5, 0, -0.2, 0, materials.floorDark);
for (let ix = -7; ix <= 7; ix++) {
for (let iz = -6; iz <= 6; iz++) {
const material =
(ix + iz) % 2 === 0 ? materials.floorLight : materials.floor;
cube(
scene,
1.03,
0.07,
1.03,
ix * 1.05,
0.005,
iz * 1.05,
material,
false
);
}
}
// Back glass wall.
for (let i = 0; i < 6; i++) {
cube(
scene,
2.32,
5.8,
0.045,
-6.12 + i * 2.45,
3.05,
-6.55,
materials.glass,
false
);
}
for (let i = 0; i <= 6; i++) {
const x = -7.35 + i * 2.45;
cube(scene, 0.1, 6.1, 0.12, x, 3.1, -6.55, materials.frame);
}
cube(scene, 15, 0.12, 0.14, 0, 0.22, -6.55, materials.frame);
cube(scene, 15, 0.12, 0.14, 0, 6.02, -6.55, materials.frame);
// Side glass and uprights.
for (const x of [-7.35, 7.35]) {
for (let i = 0; i < 4; i++) {
cube(
scene,
0.045,
5.8,
3.15,
x,
3.05,
-4.95 + i * 3.3,
materials.glass,
false
);
}
for (let i = 0; i <= 4; i++) {
cube(
scene,
0.12,
6.1,
0.12,
x,
3.1,
-6.55 + i * 3.3,
materials.frame
);
}
cube(scene, 0.14, 0.12, 13.2, x, 6.02, 0, materials.frame);
}
// Voxel roof grid.
for (let i = 0; i <= 4; i++) {
cube(
scene,
14.8,
0.09,
0.09,
0,
6.02,
-6.55 + i * 3.3,
materials.frame
);
}
// Greenhouse bench.
cube(scene, 11.8, 0.28, 3.35, 0, 1.45, 0.25, materials.bench);
cube(scene, 12.0, 0.14, 3.5, 0, 1.27, 0.25, materials.benchEdge);
cube(scene, 10.9, 0.16, 2.7, 0, 0.38, 0.25, materials.benchEdge);
for (const x of [-5.25, -1.75, 1.75, 5.25]) {
for (const z of [-1.05, 1.55]) {
cube(scene, 0.22, 1.35, 0.22, x, 0.66, z, materials.benchEdge);
}
}
// A simple voxel sensor on the bench.
cube(scene, 0.42, 0.18, 0.42, 5.05, 1.68, 0.95, materials.sensor);
cube(scene, 0.28, 0.09, 0.28, 5.05, 1.81, 0.95, materials.screen);
cube(scene, 0.05, 0.55, 0.05, 5.05, 2.03, 0.95, materials.frame);
// -----------------------------------------------------------------------
// Voxel plants and leaves
// -----------------------------------------------------------------------
const leafRecords = [];
const pickMeshes = [];
const leafPalette = [0x4f9c52, 0x68ad58, 0x3e8650, 0x79b75d];
const leafMaterials = leafPalette.map((color) => standardMaterial(color));
const leafBaseColors = leafPalette.map((color) => new THREE.Color(color));
function makeLeaf(parent, plantIndex, leafIndex, angle, height, scale) {
const pivot = new THREE.Group();
pivot.position.set(0, height, 0);
pivot.rotation.set(0, -angle, 0.08 + (leafIndex % 3) * 0.07);
pivot.scale.setScalar(scale);
parent.add(pivot);
const leaf = new THREE.Group();
leaf.position.x = 0.08;
pivot.add(leaf);
const materialIndex =
(plantIndex + leafIndex * 2) % leafMaterials.length;
const leafMaterial = leafMaterials[materialIndex];
// Pixelated elliptical blade assembled from square cells.
for (let ix = -3; ix <= 3; ix++) {
const normalized = Math.abs(ix) / 3;
const halfWidth = Math.max(
0,
Math.round(2.1 * (1 - normalized * normalized))
);
for (let iz = -halfWidth; iz <= halfWidth; iz++) {
const tile = cube(
leaf,
0.27,
0.13,
0.26,
ix * 0.29,
0,
iz * 0.28,
leafMaterial
);
tile.userData.leafIndex = leafRecords.length;
pickMeshes.push(tile);
}
}
// Central and branching veins.
cube(leaf, 1.58, 0.025, 0.035, 0, 0.078, 0, materials.vein);
for (const x of [-0.44, 0.02, 0.46]) {
cube(leaf, 0.028, 0.024, 0.43, x, 0.078, 0, materials.vein);
}
const markerGroup = new THREE.Group();
leaf.add(markerGroup);
const guardCells = [];
const markerPositions = [
[-0.38, 0.1],
[0.0, -0.1],
[0.38, 0.1]
];
for (const [x, z] of markerPositions) {
for (const side of [-1, 1]) {
const guard = cube(
markerGroup,
0.12,
0.07,
0.045,
x,
0.12,
z + side * 0.04,
materials.guard
);
guard.userData.leafIndex = leafRecords.length;
pickMeshes.push(guard);
guardCells.push({ mesh: guard, side, centerZ: z });
}
const pore = cube(
markerGroup,
0.13,
0.018,
0.02,
x,
0.105,
z,
materials.pore,
false
);
pore.userData.leafIndex = leafRecords.length;
pickMeshes.push(pore);
}
const anchor = new THREE.Object3D();
anchor.position.set(0.25, 0.14, 0);
leaf.add(anchor);
leafRecords.push({
group: leaf,
pivot,
plantIndex,
materialIndex,
markerGroup,
guardCells,
poreMeshes: markerGroup.children.filter((child) =>
child.material === materials.pore
),
anchor
});
return leaf;
}
const plantX = [-4.55, -2.3, 0, 2.3, 4.55];
const leafAngles = [0.05, 2.0, 4.1, 0.9, 3.25, 5.35];
const leafHeights = [2.55, 2.83, 3.02, 3.32, 3.52, 3.72];
plantX.forEach((x, plantIndex) => {
const plant = new THREE.Group();
plant.position.set(x, 0, 0.25);
scene.add(plant);
// Stacked square pot.
cube(plant, 0.92, 0.34, 0.92, 0, 1.79, 0, materials.pot);
cube(plant, 0.77, 0.29, 0.77, 0, 2.08, 0, materials.potLight);
cube(plant, 0.62, 0.22, 0.62, 0, 2.32, 0, materials.pot);
cube(plant, 0.56, 0.07, 0.56, 0, 2.46, 0, materials.soil);
// Blocky stem.
const stemHeight = 1.36 + plantIndex * 0.035;
cube(
plant,
0.13,
stemHeight,
0.13,
0,
2.48 + stemHeight / 2,
0,
materials.stem
);
for (let i = 0; i < 6; i++) {
makeLeaf(
plant,
plantIndex,
i,
leafAngles[i] + plantIndex * 0.09,
leafHeights[i] + (plantIndex % 2) * 0.08,
0.88 + (i % 3) * 0.07
);
}
});
scene.updateMatrixWorld(true);
// Selection beacon.
const selectionBeacon = cube(
scene,
0.11,
0.11,
0.11,
0,
0,
0,
materials.beacon,
false
);
function selectLeaf(index) {
state.selectedLeaf = clamp(index, 0, leafRecords.length - 1);
const record = leafRecords[state.selectedLeaf];
if (selectionBeacon.parent) {
selectionBeacon.parent.remove(selectionBeacon);
}
record.group.add(selectionBeacon);
selectionBeacon.position.set(0.45, 0.35, 0);
selectionBeacon.scale.set(0.1, 0.1, 0.1);
$("#selectedLeaf").textContent =
`Leaf ${String(state.selectedLeaf + 1).padStart(2, "0")} · plant ${
record.plantIndex + 1
}`;
updateVisuals();
}
// -----------------------------------------------------------------------
// Magnified leaf inset
// -----------------------------------------------------------------------
const insetRenderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
insetRenderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
insetRenderer.outputColorSpace = THREE.SRGBColorSpace;
insetRenderer.toneMapping = THREE.ACESFilmicToneMapping;
insetRenderer.toneMappingExposure = 1.15;
insetViewport.appendChild(insetRenderer.domElement);
const insetScene = new THREE.Scene();
insetScene.background = new THREE.Color(0x0b2927);
const insetCamera = new THREE.OrthographicCamera(-2, 2, 1.2, -1.2, 0.1, 30);
insetCamera.position.set(0, 4.2, 3.4);
insetCamera.lookAt(0, 0, 0);
const insetAmbient = new THREE.AmbientLight(0xd9fff0, 1.8);
insetScene.add(insetAmbient);
const insetLight = new THREE.DirectionalLight(0xffedc9, 2.3);
insetLight.position.set(-3, 6, 4);
insetScene.add(insetLight);
const insetBaseMaterial = standardMaterial(0x183f31);
const insetCellMaterial = standardMaterial(0x4f9c52);
const insetCellAlternate = standardMaterial(0x3f8149);
const insetGuardMaterial = standardMaterial(0x8ec16b);
const insetPoreMaterial = standardMaterial(0x071d18);
cube(insetScene, 2.55, 0.12, 1.58, 0, -0.07, 0, insetBaseMaterial);
const insetCells = [];
for (let ix = 0; ix < 12; ix++) {
for (let iz = 0; iz < 7; iz++) {
const material =
(ix + iz) % 3 === 0 ? insetCellAlternate : insetCellMaterial;
const cell = cube(
insetScene,
0.165,
0.11,
0.165,
(ix - 5.5) * 0.18,
0.045,
(iz - 3) * 0.18,
material,
false
);
insetCells.push(cell);
}
}
const insetStomata = [];
const insetStomaPositions = [
[-0.63, 0.18],
[-0.21, -0.18],
[0.21, 0.18],
[0.63, -0.18]
];
for (const [x, z] of insetStomaPositions) {
const left = cube(
insetScene,
0.2,
0.13,
0.07,
x,
0.15,
z - 0.07,
insetGuardMaterial,
false
);
const right = cube(
insetScene,
0.2,
0.13,
0.07,
x,
0.15,
z + 0.07,
insetGuardMaterial,
false
);
const pore = cube(
insetScene,
0.205,
0.025,
0.025,
x,
0.145,
z,
insetPoreMaterial,
false
);
insetStomata.push({ left, right, pore, centerZ: z });
}
// Yellow corner markers identify the magnified surface area.
for (const x of [-1.2, 1.2]) {
for (const z of [-0.73, 0.73]) {
cube(
insetScene,
0.09,
0.09,
0.09,
x,
0.09,
z,
materials.beacon,
false
);
}
}
// -----------------------------------------------------------------------
// Exchange cue particles: visual teaching cues, not a physical model
// -----------------------------------------------------------------------
const co2Material = basicMaterial(0x42dfd0, {
transparent: true,
opacity: 0.72,
depthWrite: false
});
const o2Material = basicMaterial(0xffd166, {
transparent: true,
opacity: 0.75,
depthWrite: false
});
const vaporMaterial = basicMaterial(0xb9dcff, {
transparent: true,
opacity: 0.65,
depthWrite: false
});
const mainMotes = [];
const insetMotes = [];
function createMainMote(type, index) {
const leaf =
leafRecords[Math.floor(random() * leafRecords.length)];
const anchor = new THREE.Vector3();
leaf.anchor.getWorldPosition(anchor);
const material =
type === 0 ? co2Material : type === 1 ? o2Material : vaporMaterial;
const mesh = cube(
scene,
0.065,
0.065,
0.065,
anchor.x,
anchor.y,
anchor.z,
material,
false
);
mainMotes.push({
type,
index,
mesh,
anchor,
offsetX: (random() - 0.5) * 0.26,
offsetZ: (random() - 0.5) * 0.26,
phase: random()
});
}
function createInsetMote(type, index) {
const material =
type === 0 ? co2Material : type === 1 ? o2Material : vaporMaterial;
const mesh = cube(
insetScene,
0.045,
0.045,
0.045,
0,
0,
0,
material,
false
);
insetMotes.push({
type,
index,
mesh,
x: (random() - 0.5) * 1.75,
z: (random() - 0.5) * 0.82,
phase: random()
});
}
for (let type = 0; type < 3; type++) {
for (let i = 0; i < 12; i++) {
createMainMote(type, i);
createInsetMote(type, i);
}
}
// -----------------------------------------------------------------------
// Conceptual relationships
// -----------------------------------------------------------------------
function computeRates() {
const aperture = state.aperture / 100;
const light = state.light / 100;
const co2 = state.co2 / 100;
const vaporGradient = (100 - state.humidity) / 100;
// These normalized indices are intentionally simple visual relationships.
const co2In = clamp(
100 * aperture * (0.18 + 0.82 * co2) * (0.25 + 0.75 * light),
0,
100
);
const o2Out = clamp(
100 * aperture * (0.15 + 0.85 * light) * (0.35 + 0.65 * co2),
0,
100
);
const waterOut = clamp(
100 *
aperture *
(0.12 + 0.88 * vaporGradient) *
(0.25 + 0.75 * light),
0,
100
);
return { co2In, o2Out, waterOut };
}
function updateVisuals() {
const rates = computeRates();
const opening = 0.012 + (state.aperture / 100) * 0.095;
const lightFactor = 0.76 + (state.light / 100) * 0.28;
// Light changes the illustrative leaf brightness.
leafMaterials.forEach((material, i) => {
material.color
.copy(leafBaseColors[i])
.multiplyScalar(lightFactor);
});
// Every canopy stomatal marker follows the shared aperture.
for (const record of leafRecords) {
record.markerGroup.visible = state.showMarkers;
for (const guard of record.guardCells) {
guard.mesh.position.z =
guard.centerZ + guard.side * (opening / 2 + 0.022);
}
for (const pore of record.poreMeshes) {
pore.scale.z = Math.max(0.012, opening);
}
}
// Magnified guard cells follow the same shared opening.
for (const stoma of insetStomata) {
stoma.left.position.z =
stoma.centerZ - (opening / 2 + 0.035);
stoma.right.position.z =
stoma.centerZ + (opening / 2 + 0.035);
stoma.pore.scale.z = Math.max(0.012, opening);
}
const selected = leafRecords[state.selectedLeaf];
const selectedColor = leafMaterials[selected.materialIndex].color;
insetCellMaterial.color.copy(selectedColor).multiplyScalar(1.08);
insetCellAlternate.color.copy(selectedColor).multiplyScalar(0.88);
$("#co2Bar").style.width = `${rates.co2In}%`;
$("#o2Bar").style.width = `${rates.o2Out}%`;
$("#waterBar").style.width = `${rates.waterOut}%`;
$("#co2Index").textContent = Math.round(rates.co2In);
$("#o2Index").textContent = Math.round(rates.o2Out);
$("#waterIndex").textContent = Math.round(rates.waterOut);
if (state.aperture < 18) {
$("#statusText").textContent =
"Narrow pores visually restrict the shared route. The exchange cues recede in the canopy and inset.";
} else if (state.aperture < 72) {
$("#statusText").textContent =
"A moderate opening links the canopy markers, magnified guard cells, and relative exchange cues.";
} else {
$("#statusText").textContent =
"Wide schematic pores emphasize the shared route. Colored cubes remain conceptual cues, not simulated fluxes.";
}
}
function syncInputs() {
$("#light").value = state.light;
$("#co2").value = state.co2;
$("#humidity").value = state.humidity;
$("#aperture").value = state.aperture;
$("#lightValue").value = state.light;
$("#co2Value").value = state.co2;
$("#humidityValue").value = state.humidity;
$("#apertureValue").value = state.aperture;
updateVisuals();
}
["light", "co2", "humidity", "aperture"].forEach((id) => {
$(`#${id}`).addEventListener("input", (event) => {
state[id] = Number(event.target.value);
syncInputs();
});
});
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const preset = button.dataset.preset;
if (preset === "open") {
state.aperture = 88;
} else if (preset === "closed") {
state.aperture = 10;
} else {
state.light = 68;
state.co2 = 52;
state.humidity = 58;
state.aperture = 55;
}
syncInputs();
});
});
$("#markersToggle").addEventListener("click", (event) => {
state.showMarkers = !state.showMarkers;
event.currentTarget.classList.toggle("active", state.showMarkers);
event.currentTarget.setAttribute(
"aria-pressed",
String(state.showMarkers)
);
updateVisuals();
});
$("#motesToggle").addEventListener("click", (event) => {
state.showMotes = !state.showMotes;
event.currentTarget.classList.toggle("active", state.showMotes);
event.currentTarget.setAttribute(
"aria-pressed",
String(state.showMotes)
);
});
// -----------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard, and raycast selection
// -----------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.2, 0.25),
theta: 0.72,
phi: 1.08,
radius: 14.7
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
let pointerStart = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
pointerStart = {
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: 0,
button: event.button,
shift: event.shiftKey
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerStart) return;
const dx = event.clientX - pointerStart.lastX;
const dy = event.clientY - pointerStart.lastY;
pointerStart.moved += Math.abs(dx) + Math.abs(dy);
pointerStart.lastX = event.clientX;
pointerStart.lastY = event.clientY;
if (event.shiftKey || pointerStart.shift) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const scale = cameraState.radius * 0.0012;
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
cameraState.target.x = clamp(cameraState.target.x, -5, 5);
cameraState.target.y = clamp(cameraState.target.y, 0.6, 5);
cameraState.target.z = clamp(cameraState.target.z, -4, 4);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(
cameraState.phi - dy * 0.005,
0.43,
1.45
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerStart) return;
const clickDistance = Math.hypot(
event.clientX - pointerStart.x,
event.clientY - pointerStart.y
);
if (
pointerStart.button === 0 &&
clickDistance < 6 &&
pointerStart.moved < 12
) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
if (hits.length) {
selectLeaf(hits[0].object.userData.leafIndex);
}
}
pointerStart = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerStart = null;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.5,
24
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
break;
case "ArrowRight":
cameraState.theta -= 0.08;
break;
case "ArrowUp":
cameraState.phi = clamp(cameraState.phi - 0.06, 0.43, 1.45);
break;
case "ArrowDown":
cameraState.phi = clamp(cameraState.phi + 0.06, 0.43, 1.45);
break;
case "+":
case "=":
cameraState.radius = clamp(cameraState.radius - 0.6, 7.5, 24);
break;
case "-":
cameraState.radius = clamp(cameraState.radius + 0.6, 7.5, 24);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
const view = button.dataset.view;
if (view === "reset") {
cameraState.target.set(0, 2.2, 0.25);
cameraState.theta = 0.72;
cameraState.phi = 1.08;
cameraState.radius = 14.7;
} else if (view === "front") {
cameraState.theta = 0;
cameraState.phi = 1.25;
cameraState.radius = 13.5;
} else if (view === "side") {
cameraState.theta = Math.PI / 2;
cameraState.phi = 1.16;
cameraState.radius = 14.2;
} else if (view === "top") {
cameraState.theta = 0.7;
cameraState.phi = 0.46;
cameraState.radius = 15.5;
}
updateCamera();
});
});
// -----------------------------------------------------------------------
// Responsive inset and animation
// -----------------------------------------------------------------------
function resizeInset() {
const width = insetViewport.clientWidth;
const height = insetViewport.clientHeight;
insetRenderer.setSize(width, height, false);
const aspect = width / Math.max(height, 1);
const halfHeight = 1.28;
insetCamera.left = -halfHeight * aspect;
insetCamera.right = halfHeight * aspect;
insetCamera.top = halfHeight;
insetCamera.bottom = -halfHeight;
insetCamera.updateProjectionMatrix();
}
function resizeMain() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", () => {
resizeMain();
resizeInset();
});
if ("ResizeObserver" in window) {
new ResizeObserver(resizeInset).observe(insetViewport);
}
resizeInset();
function animateMotes(time) {
const rates = computeRates();
const rateValues = [rates.co2In, rates.o2Out, rates.waterOut];
for (const mote of mainMotes) {
const activeCount = Math.ceil((rateValues[mote.type] / 100) * 12);
mote.mesh.visible = state.showMotes && mote.index < activeCount;
if (!mote.mesh.visible) continue;
const speed = 0.18 + (rateValues[mote.type] / 100) * 0.28;
const phase = (time * speed + mote.phase) % 1;
mote.mesh.position.x =
mote.anchor.x + mote.offsetX + Math.sin(time * 1.2 + mote.phase * 6) * 0.035;
mote.mesh.position.z =
mote.anchor.z + mote.offsetZ + Math.cos(time + mote.phase * 6) * 0.035;
if (mote.type === 0) {
mote.mesh.position.y = mote.anchor.y + 0.95 - phase * 0.86;
} else {
mote.mesh.position.y = mote.anchor.y + 0.08 + phase * 0.95;
}
mote.mesh.rotation.y = time * 0.6 + mote.phase * 6;
}
for (const mote of insetMotes) {
const activeCount = Math.ceil((rateValues[mote.type] / 100) * 12);
mote.mesh.visible = state.showMotes && mote.index < activeCount;
if (!mote.mesh.visible) continue;
const speed = 0.12 + (rateValues[mote.type] / 100) * 0.25;
const phase = (time * speed + mote.phase) % 1;
mote.mesh.position.x = mote.x;
mote.mesh.position.z = mote.z;
if (mote.type === 0) {
mote.mesh.position.y = 1.28 - phase * 1.08;
} else {
mote.mesh.position.y = 0.16 + phase * 1.12;
}
mote.mesh.rotation.y = time * 0.8 + mote.phase * 6;
mote.mesh.rotation.x = time * 0.45;
}
}
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
const elapsed = now / 1000;
previousTime = now;
selectionBeacon.position.y = 0.35 + Math.sin(elapsed * 3.2) * 0.035;
selectionBeacon.rotation.y += delta * 1.4;
animateMotes(elapsed);
renderer.render(scene, camera);
insetRenderer.render(insetScene, insetCamera);
requestAnimationFrame(animate);
}
selectLeaf(0);
syncInputs();
resizeMain();
resizeInset();
$("#loading").remove();
requestAnimationFrame(animate);
</script>
</body>
</html>
```