Prompt specification
Build or customize the Three.js 3D scene "Moisture and Aeration Toy Comparison" 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: Moisture and Aeration Toy Comparison
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/moisture-and-aeration-toy-comparison-x3928
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a qualitative decomposition model with declared response assumptions for moisture and aeration. Compare scenarios without presenting the output as validated compost-management advice.
Working Three.js Starter (moisture-and-aeration-toy-comparison-x3928):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Decomposition Scenario Comparison</title>
<style>
:root {
color-scheme: light;
--ink: #21322c;
--muted: #65736c;
--paper: #f4f1e8;
--panel: #fffdf7;
--line: #d9ddd1;
--green: #416c51;
--green-dark: #294b37;
--blue: #388ca3;
--amber: #b87b32;
--danger: #a85745;
--shadow: 0 18px 55px rgba(41, 62, 50, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background:
radial-gradient(circle at 15% 5%, #e4eddf 0, transparent 31rem),
linear-gradient(135deg, #eef0e6, #e5ecdf);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
cursor: pointer;
}
.page {
width: min(1500px, 100%);
margin: 0 auto;
padding: 24px;
}
header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
margin-bottom: 18px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--green);
font-size: 0.76rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
max-width: 850px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(2rem, 4vw, 4.1rem);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 760px;
margin: 13px 0 0;
color: var(--muted);
font-size: 1rem;
line-height: 1.55;
}
.status {
flex: 0 0 auto;
border: 1px solid #b8c9b7;
border-radius: 999px;
background: rgba(255, 255, 255, 0.72);
padding: 10px 14px;
color: var(--green-dark);
font-size: 0.78rem;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
box-shadow: 0 8px 24px rgba(48, 72, 57, 0.08);
}
.status::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
margin-right: 8px;
border-radius: 50%;
background: #779d65;
box-shadow: 0 0 0 4px rgba(119, 157, 101, 0.16);
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1.65fr) minmax(340px, 0.75fr);
gap: 18px;
align-items: start;
}
.stage,
.panel {
border: 1px solid rgba(123, 145, 123, 0.32);
border-radius: 24px;
background: rgba(255, 253, 247, 0.9);
box-shadow: var(--shadow);
overflow: hidden;
}
.stage {
position: relative;
min-height: 650px;
background: #dce8d9;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.scene-top {
position: absolute;
z-index: 2;
top: 18px;
left: 18px;
right: 18px;
display: flex;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.scene-label,
.legend {
border: 1px solid rgba(50, 77, 58, 0.14);
border-radius: 14px;
background: rgba(255, 253, 247, 0.82);
box-shadow: 0 8px 26px rgba(40, 65, 49, 0.1);
backdrop-filter: blur(8px);
}
.scene-label {
max-width: 340px;
padding: 12px 14px;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.45;
}
.scene-label strong {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-size: 0.86rem;
}
.legend {
display: grid;
gap: 7px;
padding: 11px 13px;
color: var(--muted);
font-size: 0.72rem;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
}
.swatch.air {
border: 2px solid #3e9bb0;
background: rgba(93, 190, 211, 0.18);
}
.swatch.water {
border-radius: 2px;
background: #397ca6;
transform: rotate(45deg);
}
.swatch.microbe {
background: #d2c34d;
}
.scene-bottom {
position: absolute;
z-index: 2;
right: 18px;
bottom: 16px;
left: 18px;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 16px;
pointer-events: none;
}
.hint {
padding: 9px 12px;
border-radius: 12px;
background: rgba(42, 67, 51, 0.76);
color: #fff;
font-size: 0.72rem;
line-height: 1.4;
}
.scene-note {
max-width: 270px;
padding: 10px 12px;
border: 1px solid rgba(61, 87, 66, 0.12);
border-radius: 12px;
background: rgba(255, 253, 247, 0.82);
color: var(--muted);
font-size: 0.72rem;
line-height: 1.4;
text-align: right;
}
.panel {
padding: 20px;
}
.panel h2,
.panel h3 {
margin: 0;
}
.panel h2 {
font-family: Georgia, "Times New Roman", serif;
font-size: 1.45rem;
font-weight: 500;
}
.panel-intro {
margin: 6px 0 16px;
color: var(--muted);
font-size: 0.82rem;
line-height: 1.45;
}
.preset-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-bottom: 17px;
}
.preset {
border: 1px solid var(--line);
border-radius: 999px;
background: #f7f5ed;
padding: 7px 10px;
color: #536158;
font-size: 0.7rem;
font-weight: 700;
}
.preset:hover,
.preset:focus-visible {
border-color: #91aa8b;
background: #edf3e9;
outline: none;
}
.scenario {
padding: 16px;
border: 1px solid var(--line);
border-radius: 17px;
background: #fffef9;
}
.scenario + .scenario {
margin-top: 12px;
}
.scenario-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.scenario-title {
display: flex;
align-items: center;
gap: 9px;
font-weight: 800;
}
.scenario-dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(65, 108, 81, 0.12);
}
.scenario.b .scenario-dot {
background: var(--amber);
box-shadow: 0 0 0 4px rgba(184, 123, 50, 0.13);
}
.score {
text-align: right;
}
.score strong {
display: block;
color: var(--green-dark);
font-family: Georgia, "Times New Roman", serif;
font-size: 1.7rem;
font-weight: 500;
line-height: 0.9;
}
.scenario.b .score strong {
color: #805421;
}
.score span {
color: var(--muted);
font-size: 0.62rem;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.control {
margin-top: 12px;
}
.control label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 6px;
color: #4b5b52;
font-size: 0.76rem;
font-weight: 700;
}
.control output {
color: var(--green-dark);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 5px 0;
border-radius: 999px;
appearance: none;
background:
linear-gradient(
to right,
var(--green) 0 var(--fill, 50%),
#e1e4da var(--fill, 50%) 100%
);
outline: none;
}
.scenario.b input[type="range"] {
background:
linear-gradient(
to right,
var(--amber) 0 var(--fill, 50%),
#e1e4da var(--fill, 50%) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 3px solid #fff;
border-radius: 50%;
appearance: none;
background: currentColor;
box-shadow: 0 1px 5px rgba(25, 40, 31, 0.25);
cursor: grab;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #fff;
border-radius: 50%;
background: currentColor;
box-shadow: 0 1px 5px rgba(25, 40, 31, 0.25);
cursor: grab;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 13px;
}
.metric {
border-radius: 11px;
background: #f4f4ec;
padding: 9px 10px;
}
.metric span {
display: block;
color: var(--muted);
font-size: 0.62rem;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 3px;
color: var(--ink);
font-size: 0.76rem;
}
.constraint {
margin-top: 9px;
padding: 8px 10px;
border-left: 3px solid #94ad8d;
background: #eff5eb;
color: #48604f;
font-size: 0.72rem;
line-height: 1.35;
}
.scenario.b .constraint {
border-left-color: #c99a62;
background: #f8f1e5;
color: #765a39;
}
.comparison {
margin-top: 13px;
padding: 13px 14px;
border-radius: 14px;
background: var(--green-dark);
color: #f8f8ef;
font-size: 0.78rem;
line-height: 1.45;
}
.comparison strong {
color: #dbeccd;
}
details {
margin-top: 17px;
border-top: 1px solid var(--line);
padding-top: 14px;
}
summary {
color: var(--green-dark);
font-size: 0.82rem;
font-weight: 800;
cursor: pointer;
}
.assumptions {
padding: 10px 2px 0;
color: var(--muted);
font-size: 0.74rem;
line-height: 1.52;
}
.assumptions ul {
margin: 8px 0;
padding-left: 18px;
}
.formula {
margin: 10px 0;
padding: 10px;
border-radius: 10px;
background: #eef1e8;
color: #344c3c;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 0.69rem;
overflow-wrap: anywhere;
}
.disclaimer {
margin-top: 14px;
padding: 12px;
border: 1px solid #ddc99e;
border-radius: 12px;
background: #fff7e7;
color: #755d31;
font-size: 0.73rem;
line-height: 1.45;
}
footer {
padding: 17px 4px 0;
color: #66746c;
font-size: 0.72rem;
line-height: 1.5;
text-align: center;
}
@media (max-width: 980px) {
.layout {
grid-template-columns: 1fr;
}
.stage {
min-height: 560px;
}
.panel {
max-width: none;
}
}
@media (max-width: 620px) {
.page {
padding: 12px;
}
header {
display: block;
}
.status {
display: inline-block;
margin-top: 16px;
}
.stage {
min-height: 500px;
border-radius: 18px;
}
.scene-top {
display: block;
}
.legend {
display: none;
}
.scene-label {
max-width: 80%;
}
.scene-note {
display: none;
}
.panel {
padding: 14px;
border-radius: 18px;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<main class="page">
<header>
<div>
<p class="eyebrow">Interactive decomposition study</p>
<h1>Two piles, one visual model</h1>
<p class="subtitle">
Compare illustrative moisture and aeration scenarios in a low-poly compost scene.
The outputs are relative teaching indicators, not measured or validated predictions.
</p>
</div>
<div class="status">Qualitative · uncalibrated</div>
</header>
<section class="layout">
<div class="stage">
<canvas
id="scene"
aria-label="Interactive low-poly scene showing two compost piles and their illustrative activity indicators"
></canvas>
<div class="scene-top">
<div class="scene-label">
<strong>Scenario comparison</strong>
Particle density and motion visualize the relative index only. They do not represent
measured organisms, gases, or decomposition rate.
</div>
<div class="legend" aria-label="Particle legend">
<div class="legend-row">
<span class="swatch air"></span>
Air-filled pore proxy
</div>
<div class="legend-row">
<span class="swatch water"></span>
Moisture proxy
</div>
<div class="legend-row">
<span class="swatch microbe"></span>
Illustrative activity
</div>
</div>
</div>
<div class="scene-bottom">
<div class="hint">Drag to orbit · wheel to zoom · double-click to reset</div>
<div class="scene-note">
The scene omits temperature, material chemistry, microbial community,
and time-varying conditions.
</div>
</div>
</div>
<aside class="panel" aria-label="Scenario controls and model outputs">
<h2>Scenario inputs</h2>
<p class="panel-intro">
Adjust the two proxies for each pile. The model responds independently to
moisture and aeration, then combines their response factors.
</p>
<div class="preset-row" aria-label="Illustrative scenario presets">
<button class="preset" type="button" data-preset="balanced">Balanced reference</button>
<button class="preset" type="button" data-preset="dry">Dry / low air</button>
<button class="preset" type="button" data-preset="wet">Wet / low air</button>
<button class="preset" type="button" data-preset="open">Wet / open-air</button>
</div>
<section class="scenario" id="scenario-a">
<div class="scenario-head">
<div class="scenario-title">
<span class="scenario-dot"></span>
Scenario A
</div>
<div class="score">
<strong id="score-a">0</strong>
<span>relative index</span>
</div>
</div>
<div class="control">
<label for="moisture-a">
Moisture proxy
<output id="moisture-a-value" for="moisture-a">48%</output>
</label>
<input
id="moisture-a"
type="range"
min="0"
max="100"
step="1"
value="48"
aria-label="Scenario A moisture proxy"
>
</div>
<div class="control">
<label for="air-a">
Air-filled pore proxy
<output id="air-a-value" for="air-a">52%</output>
</label>
<input
id="air-a"
type="range"
min="0"
max="100"
step="1"
value="52"
aria-label="Scenario A air-filled pore proxy"
>
</div>
<div class="metrics">
<div class="metric">
<span>Moisture response</span>
<strong id="moisture-response-a">—</strong>
</div>
<div class="metric">
<span>Aeration response</span>
<strong id="air-response-a">—</strong>
</div>
</div>
<div class="constraint" id="constraint-a">Calculating…</div>
</section>
<section class="scenario b" id="scenario-b">
<div class="scenario-head">
<div class="scenario-title">
<span class="scenario-dot"></span>
Scenario B
</div>
<div class="score">
<strong id="score-b">0</strong>
<span>relative index</span>
</div>
</div>
<div class="control">
<label for="moisture-b">
Moisture proxy
<output id="moisture-b-value" for="moisture-b">68%</output>
</label>
<input
id="moisture-b"
type="range"
min="0"
max="100"
step="1"
value="68"
aria-label="Scenario B moisture proxy"
>
</div>
<div class="control">
<label for="air-b">
Air-filled pore proxy
<output id="air-b-value" for="air-b">26%</output>
</label>
<input
id="air-b"
type="range"
min="0"
max="100"
step="1"
value="26"
aria-label="Scenario B air-filled pore proxy"
>
</div>
<div class="metrics">
<div class="metric">
<span>Moisture response</span>
<strong id="moisture-response-b">—</strong>
</div>
<div class="metric">
<span>Aeration response</span>
<strong id="air-response-b">—</strong>
</div>
</div>
<div class="constraint" id="constraint-b">Calculating…</div>
</section>
<div class="comparison" id="comparison" aria-live="polite">
Comparing scenarios…
</div>
<details open>
<summary>Declared model assumptions</summary>
<div class="assumptions">
<ul>
<li>
Moisture and aeration are user-supplied percentage proxies, not validated
sensor readings.
</li>
<li>
The moisture response is assumed to plateau between 35% and 60%, decline
below 35%, and decline above 60%.
</li>
<li>
The aeration response is assumed to plateau between 30% and 70%, decline
below 30%, and decline above 70%.
</li>
<li>
A geometric mean prevents either response from being completely hidden
by the other.
</li>
<li>
Temperature is implicitly held at a favorable reference condition and is
not modeled.
</li>
<li>
Substrate chemistry, nitrogen availability, particle size, microbial
community, and time are omitted.
</li>
</ul>
<div class="formula">
M(m): 0→1 across 0–35; 1 across 35–60; then declines to 0.15 at 100.<br>
A(a): 0→1 across 0–30; 1 across 30–70; then declines to 0.10 at 100.<br>
Relative activity index R = 100 × √(M × A)
</div>
The score has no time unit. It does not estimate mass loss, completion date,
sanitation, odor, temperature, or compost safety.
</div>
</details>
<div class="disclaimer">
<strong>Interpretation limit:</strong> this is an educational comparison model,
not validated compost-management advice. It must not be used alone to judge
safety, readiness, odor control, nutrient loss, or pathogen reduction.
</div>
</aside>
</section>
<footer>
All geometry, textures, labels, controls, and model calculations are generated in this
single HTML file. Three.js is loaded from cdnjs; no addons or external assets are used.
</footer>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Qualitative model
// -------------------------------------------------------------------------
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
function moistureResponse(m) {
if (m < 35) return clamp(m / 35, 0, 1);
if (m <= 60) return 1;
return Math.max(0.15, 1 - 0.85 * ((m - 60) / 40));
}
function aerationResponse(a) {
if (a < 30) return clamp(a / 30, 0, 1);
if (a <= 70) return 1;
return Math.max(0.10, 1 - 0.90 * ((a - 70) / 30));
}
function evaluateScenario(m, a) {
const moisture = moistureResponse(m);
const air = aerationResponse(a);
const index = 100 * Math.sqrt(moisture * air);
let band;
if (index < 25) band = "very low illustrative activity";
else if (index < 45) band = "low illustrative activity";
else if (index < 65) band = "moderate illustrative activity";
else if (index < 82) band = "high illustrative activity";
else band = "very high illustrative activity";
let constraint;
if (Math.abs(moisture - air) < 0.08) {
constraint = "Both modeled responses are similarly limiting.";
} else if (moisture < air) {
constraint = "Moisture is the lower modeled response in this scenario.";
} else {
constraint = "Aeration is the lower modeled response in this scenario.";
}
return { moisture, air, index, band, constraint };
}
const inputs = {
a: {
moisture: document.querySelector("#moisture-a"),
air: document.querySelector("#air-a")
},
b: {
moisture: document.querySelector("#moisture-b"),
air: document.querySelector("#air-b")
}
};
const outputs = {
a: {
score: document.querySelector("#score-a"),
moisture: document.querySelector("#moisture-response-a"),
air: document.querySelector("#air-response-a"),
constraint: document.querySelector("#constraint-a")
},
b: {
score: document.querySelector("#score-b"),
moisture: document.querySelector("#moisture-response-b"),
air: document.querySelector("#air-response-b"),
constraint: document.querySelector("#constraint-b")
}
};
const scenarioState = {
a: evaluateScenario(48, 52),
b: evaluateScenario(68, 26)
};
function setRangeFill(input) {
const percent = 100 * (Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min));
input.style.setProperty("--fill", `${percent}%`);
}
function updateScenarioUI(key) {
const input = inputs[key];
const output = outputs[key];
const m = Number(input.moisture.value);
const a = Number(input.air.value);
const result = evaluateScenario(m, a);
scenarioState[key] = result;
document.querySelector(`#moisture-${key}-value`).textContent = `${m}%`;
document.querySelector(`#air-${key}-value`).textContent = `${a}%`;
output.score.textContent = Math.round(result.index);
output.moisture.textContent = `${Math.round(result.moisture * 100)}% · ${result.band}`;
output.air.textContent = `${Math.round(result.air * 100)}%`;
output.constraint.textContent = result.constraint;
input.moisture.setAttribute(
"aria-valuetext",
`${m} percent moisture proxy`
);
input.air.setAttribute(
"aria-valuetext",
`${a} percent air-filled pore proxy`
);
setRangeFill(input.moisture);
setRangeFill(input.air);
}
function updateComparison() {
const difference = scenarioState.a.index - scenarioState.b.index;
const absoluteDifference = Math.abs(difference);
let text;
if (absoluteDifference < 1) {
text = "The two scenarios have nearly identical illustrative indices.";
} else {
const higher = difference > 0 ? "A" : "B";
text =
`Scenario ${higher} has the higher illustrative index by ` +
`${Math.round(absoluteDifference)} points. ` +
`This describes the declared response model only; it does not identify a ` +
`preferred management practice.`;
}
document.querySelector("#comparison").innerHTML =
`<strong>Comparison:</strong> ${text}`;
}
function refreshAll() {
updateScenarioUI("a");
updateScenarioUI("b");
updateComparison();
updateCompostVisuals();
}
Object.values(inputs).forEach((group) => {
Object.values(group).forEach((input) => {
input.addEventListener("input", refreshAll);
});
});
const presets = {
balanced: { a: [48, 52], b: [48, 52] },
dry: { a: [22, 24], b: [48, 52] },
wet: { a: [72, 28], b: [48, 52] },
open: { a: [72, 62], b: [48, 52] }
};
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const preset = presets[button.dataset.preset];
inputs.a.moisture.value = preset.a[0];
inputs.a.air.value = preset.a[1];
inputs.b.moisture.value = preset.b[0];
inputs.b.air.value = preset.b[1];
refreshAll();
});
});
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const stage = canvas.parentElement;
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setClearColor(0xdce8d9);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xdce8d9, 13, 25);
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 80);
const cameraState = {
theta: 0.53,
phi: 0.94,
radius: 12.4,
target: new THREE.Vector3(0, 1.05, 0)
};
const cameraHome = {
theta: 0.53,
phi: 0.94,
radius: 12.4
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
// Direct camera controls: no external control addons are used.
let dragging = false;
let previousPointer = { x: 0, y: 0 };
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
cameraState.theta -= dx * 0.008;
cameraState.phi = clamp(cameraState.phi - dy * 0.006, 0.38, 1.38);
previousPointer = { x: event.clientX, y: event.clientY };
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.008,
7.2,
18
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.theta = cameraHome.theta;
cameraState.phi = cameraHome.phi;
cameraState.radius = cameraHome.radius;
});
function resizeScene() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
if ("ResizeObserver" in window) {
new ResizeObserver(resizeScene).observe(stage);
} else {
window.addEventListener("resize", resizeScene);
}
// Lighting
const hemisphere = new THREE.HemisphereLight(0xf7f4d9, 0x55705a, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d3, 3.2);
sun.position.set(-5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -6;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cc9d4, 0.8);
fill.position.set(7, 4, -6);
scene.add(fill);
// Materials
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
flatShading: true,
roughness: 0.92,
metalness: 0,
...extra
});
const groundMaterial = material(0x93ad79);
const soilMaterial = material(0x6e5138);
const woodMaterial = material(0x8b5a35);
const woodLightMaterial = material(0xb47d4e);
const darkWoodMaterial = material(0x5d3d28);
const stoneMaterial = material(0x9a9b86);
const leafMaterial = material(0x55784e);
const leafLightMaterial = material(0x73945d);
// Ground
const ground = new THREE.Mesh(
new THREE.CircleGeometry(17, 36),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const outerGround = new THREE.Mesh(
new THREE.CylinderGeometry(17.3, 17.6, 0.45, 36),
material(0x7f9b69)
);
outerGround.position.y = -0.28;
outerGround.receiveShadow = true;
scene.add(outerGround);
// A soft, faceted mound under the beds.
const mound = new THREE.Mesh(
new THREE.CylinderGeometry(6.2, 7.1, 0.22, 14),
material(0x829d6f)
);
mound.position.y = 0.1;
mound.receiveShadow = true;
scene.add(mound);
// Deterministic pseudo-random helper.
let seed = 8128;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function addBox(parent, size, position, mat, rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Low-poly trees and shrubs around the scene.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.17, 1.25, 6),
darkWoodMaterial
);
trunk.position.y = 0.62;
trunk.castShadow = true;
tree.add(trunk);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.82, 1.45, 7),
leafMaterial
);
lower.position.y = 1.55;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.61, 1.3, 7),
leafLightMaterial
);
upper.position.y = 2.18;
upper.castShadow = true;
tree.add(upper);
scene.add(tree);
}
addTree(-6.6, -3.8, 1.25);
addTree(6.5, -4.5, 1.05);
addTree(-7.5, 2.8, 0.82);
addTree(7.2, 2.4, 0.7);
for (let i = 0; i < 20; i++) {
const angle = random() * Math.PI * 2;
const radius = 6.7 + random() * 5.5;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.12 + random() * 0.18, 0),
stoneMaterial
);
rock.position.set(
Math.cos(angle) * radius,
0.08 + random() * 0.06,
Math.sin(angle) * radius
);
rock.scale.y = 0.55 + random() * 0.4;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
scene.add(rock);
}
function makeTextSprite(text, color = "#294536") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 160;
const context = labelCanvas.getContext("2d");
context.fillStyle = "rgba(255,253,247,0.92)";
context.beginPath();
context.roundRect(10, 10, 492, 140, 32);
context.fill();
context.strokeStyle = "rgba(52,83,63,0.18)";
context.lineWidth = 4;
context.stroke();
context.fillStyle = color;
context.font = "700 54px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 82);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(2.35, 0.73, 1);
return sprite;
}
function makeCompost(x, letter) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
// Base
addBox(group, [3.8, 0.18, 2.65], [0, 0.24, 0], soilMaterial);
// Wooden slats
addBox(group, [0.18, 1.45, 0.18], [-1.78, 0.92, -1.15], darkWoodMaterial);
addBox(group, [0.18, 1.45, 0.18], [1.78, 0.92, -1.15], darkWoodMaterial);
addBox(group, [0.18, 1.45, 0.18], [-1.78, 0.92, 1.15], darkWoodMaterial);
addBox(group, [0.18, 1.45, 0.18], [1.78, 0.92, 1.15], darkWoodMaterial);
addBox(group, [3.75, 0.19, 0.16], [0, 0.57, -1.15], woodMaterial);
addBox(group, [3.75, 0.19, 0.16], [0, 1.08, -1.15], woodLightMaterial);
addBox(group, [3.75, 0.19, 0.16], [0, 0.57, 1.15], woodLightMaterial);
addBox(group, [3.75, 0.19, 0.16], [0, 1.08, 1.15], woodMaterial);
addBox(group, [0.16, 0.19, 2.45], [-1.78, 0.57, 0], woodMaterial);
addBox(group, [0.16, 0.19, 2.45], [1.78, 1.08, 0], woodLightMaterial);
// Main faceted compost mound
const pileMaterial = material(0x745137);
const pile = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.28, 1),
pileMaterial
);
pile.position.set(0, 1.03, 0);
pile.scale.set(1.25, 0.78, 0.88);
pile.rotation.set(0.05, 0.25, -0.04);
pile.castShadow = true;
pile.receiveShadow = true;
group.add(pile);
// Additional faceted pieces suggest heterogeneous material.
const chunkMaterials = [
material(0x63452f),
material(0x8a6540),
material(0x77613a),
material(0x53633a)
];
for (let i = 0; i < 22; i++) {
const angle = random() * Math.PI * 2;
const radius = random() * 1.28;
const chunk = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.08 + random() * 0.12, 0),
chunkMaterials[i % chunkMaterials.length]
);
chunk.position.set(
Math.cos(angle) * radius,
0.73 + random() * 1.15,
Math.sin(angle) * radius * 0.66
);
chunk.rotation.set(random() * 2, random() * 2, random() * 2);
chunk.scale.y = 0.65 + random() * 0.5;
chunk.castShadow = true;
group.add(chunk);
}
const label = makeTextSprite(
`Scenario ${letter}`,
letter === "A" ? "#31513d" : "#815927"
);
label.position.set(0, 2.85, 0);
group.add(label);
// Microbe-like illustrative particles
const microbeMaterial = material(0xd0c64b, {
emissive: 0x302a05,
emissiveIntensity: 0.16
});
const microbes = [];
for (let i = 0; i < 30; i++) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.035 + random() * 0.025, 0),
microbeMaterial
);
const angle = random() * Math.PI * 2;
const radius = 0.2 + random() * 1.35;
mesh.userData = {
angle,
radius,
baseY: 1.25 + random() * 1.55,
phase: random() * Math.PI * 2,
speed: 0.35 + random() * 0.7
};
mesh.position.set(
Math.cos(angle) * radius,
mesh.userData.baseY,
Math.sin(angle) * radius * 0.72
);
group.add(mesh);
microbes.push(mesh);
}
// Air proxy: cyan open-looking low-poly spheres.
const airMaterial = new THREE.MeshBasicMaterial({
color: 0x5cc4d6,
wireframe: true,
transparent: true,
opacity: 0.8
});
const airParticles = [];
for (let i = 0; i < 16; i++) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.075 + random() * 0.04, 0),
airMaterial
);
const angle = random() * Math.PI * 2;
mesh.userData = {
angle,
radius: 0.4 + random() * 1.0,
baseY: 1.35 + random() * 1.8,
phase: random() * Math.PI * 2
};
mesh.position.set(
Math.cos(angle) * mesh.userData.radius,
mesh.userData.baseY,
Math.sin(angle) * mesh.userData.radius * 0.7
);
group.add(mesh);
airParticles.push(mesh);
}
// Moisture proxy: dark-blue faceted droplets.
const waterMaterial = material(0x3e7fa3, {
roughness: 0.42,
metalness: 0.05
});
const waterParticles = [];
for (let i = 0; i < 15; i++) {
const mesh = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.075 + random() * 0.035, 0),
waterMaterial
);
const angle = random() * Math.PI * 2;
mesh.userData = {
angle,
radius: 0.25 + random() * 1.3,
baseY: 1.05 + random() * 1.45,
phase: random() * Math.PI * 2
};
mesh.position.set(
Math.cos(angle) * mesh.userData.radius,
mesh.userData.baseY,
Math.sin(angle) * mesh.userData.radius * 0.66
);
group.add(mesh);
waterParticles.push(mesh);
}
return {
group,
pile,
pileMaterial,
microbes,
airParticles,
waterParticles,
state: {
index: 50,
moisture: 0.5,
air: 0.5
}
};
}
const compostA = makeCompost(-2.45, "A");
const compostB = makeCompost(2.45, "B");
const inactivePile = new THREE.Color(0x51483a);
const activePile = new THREE.Color(0x956237);
function updateCompostVisuals() {
[
[compostA, scenarioState.a],
[compostB, scenarioState.b]
].forEach(([compost, result]) => {
compost.state.index = result.index;
compost.state.moisture = result.moisture;
compost.state.air = result.air;
compost.pileMaterial.color
.copy(inactivePile)
.lerp(activePile, clamp(result.index / 100, 0, 1));
compost.pile.scale.y = 0.72 + 0.08 * result.moisture;
});
}
// Small sign between the two beds.
const sign = new THREE.Group();
sign.position.set(0, 0, -0.35);
addBox(sign, [0.12, 1.45, 0.12], [0, 0.72, 0], darkWoodMaterial);
const signBoard = addBox(
sign,
[1.15, 0.66, 0.12],
[0, 1.35, 0],
woodLightMaterial,
[0, 0, -0.04]
);
signBoard.castShadow = true;
scene.add(sign);
const signLabel = makeTextSprite("Compare", "#684921");
signLabel.scale.set(1.02, 0.32, 1);
signLabel.position.set(0, 1.35, 0.08);
sign.add(signLabel);
// Animate only visual particles; no physical process is simulated.
const clock = new THREE.Clock();
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function animate() {
const elapsed = reduceMotion ? 0 : clock.getElapsedTime();
[
[compostA, -0.16],
[compostB, 0.23]
].forEach(([compost, phaseOffset]) => {
const activity = compost.state.index / 100;
const movement = 0.045 + activity * 0.13;
compost.microbes.forEach((mesh, index) => {
const data = mesh.userData;
mesh.visible = index < Math.round(4 + activity * 26);
const angle = data.angle + elapsed * data.speed * (0.35 + activity);
mesh.position.x = Math.cos(angle) * data.radius;
mesh.position.z = Math.sin(angle) * data.radius * 0.72;
mesh.position.y =
data.baseY + Math.sin(elapsed * data.speed + data.phase) * movement;
mesh.rotation.x += 0.008 * (0.4 + activity);
mesh.rotation.y += 0.01 * (0.4 + activity);
});
compost.airParticles.forEach((mesh, index) => {
const data = mesh.userData;
mesh.visible = index < Math.round(compost.state.air * 16);
const angle = data.angle + elapsed * 0.18 + phaseOffset;
mesh.position.x = Math.cos(angle) * data.radius;
mesh.position.z = Math.sin(angle) * data.radius * 0.7;
mesh.position.y =
data.baseY + Math.sin(elapsed * 0.7 + data.phase) * 0.08;
mesh.rotation.y = elapsed * 0.4;
});
compost.waterParticles.forEach((mesh, index) => {
const data = mesh.userData;
mesh.visible = index < Math.round(compost.state.moisture * 15);
const angle = data.angle - elapsed * 0.11 + phaseOffset;
mesh.position.x = Math.cos(angle) * data.radius;
mesh.position.z = Math.sin(angle) * data.radius * 0.66;
mesh.position.y =
data.baseY + Math.sin(elapsed * 0.55 + data.phase) * 0.045;
mesh.rotation.y = elapsed * 0.3;
});
});
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resizeScene();
updateCamera();
refreshAll();
animate();
</script>
</body>
</html>
```