Prompt specification
Build or customize the Three.js 3D scene "Surface-cover resource sandbox" 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: Surface-cover resource sandbox
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/surface-cover-resource-sandbox-x1088
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts mulch cover. Create a toy garden with limited cover material and fictional evaporation rules; users allocate layers and compare displayed water retention while the underlying assumptions remain explicit. Low-poly.
Working Three.js Starter (surface-cover-resource-sandbox-x1088):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mulch Lab — A Toy Garden Water Model</title>
<style>
:root {
--ink: #24352e;
--muted: #6d776f;
--paper: #f5f1e7;
--panel: #fffdf7;
--line: #ddd8ca;
--green: #426b50;
--green-dark: #284936;
--green-soft: #e4eee2;
--mulch: #b77746;
--mulch-dark: #70472f;
--water: #4c91aa;
--water-soft: #e3f1f5;
--gold: #d7a44e;
--shadow: 0 12px 35px rgba(45, 53, 43, 0.11);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body { overflow: hidden; }
button {
font: inherit;
color: inherit;
}
button:focus-visible,
summary:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(76, 145, 170, 0.5);
outline-offset: 3px;
}
.app {
display: grid;
grid-template-columns: minmax(0, 1fr) 400px;
height: 100vh;
min-height: 650px;
}
.stage {
position: relative;
min-width: 0;
overflow: hidden;
background: #e9e5d9;
}
#garden {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#garden:active { cursor: grabbing; }
.scene-heading {
position: absolute;
z-index: 2;
top: 24px;
left: 26px;
max-width: 340px;
pointer-events: none;
text-shadow: 0 1px rgba(255,255,255,.65);
}
.eyebrow {
margin: 0 0 6px;
color: var(--green-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.scene-heading h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3.2vw, 48px);
font-weight: 500;
line-height: 1;
letter-spacing: -.035em;
}
.scene-heading p:last-child {
margin: 9px 0 0;
color: #58675e;
font-size: 13px;
line-height: 1.45;
}
.scene-tools {
position: absolute;
z-index: 4;
right: 20px;
top: 20px;
display: flex;
gap: 7px;
}
.tool-button {
display: grid;
place-items: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid rgba(62, 76, 66, .18);
border-radius: 11px;
background: rgba(255, 253, 247, .87);
box-shadow: 0 5px 18px rgba(45, 53, 43, .09);
backdrop-filter: blur(10px);
cursor: pointer;
transition: transform .15s ease, background .15s ease;
}
.tool-button:hover {
transform: translateY(-1px);
background: white;
}
.tool-button svg {
width: 17px;
height: 17px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.scene-bottom {
position: absolute;
z-index: 3;
left: 24px;
right: 24px;
bottom: 20px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
max-width: 520px;
padding: 10px 13px;
border: 1px solid rgba(62, 76, 66, .13);
border-radius: 13px;
background: rgba(255, 253, 247, .82);
box-shadow: 0 8px 24px rgba(45, 53, 43, .08);
backdrop-filter: blur(10px);
color: #59675e;
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--mulch);
transform: rotate(12deg);
}
.swatch.water {
border-radius: 50% 50% 50% 0;
background: var(--water);
transform: rotate(-45deg);
}
.swatch.soil {
border-radius: 2px;
background: #684331;
}
.hint {
color: #59675e;
font-size: 11px;
text-align: right;
text-shadow: 0 1px rgba(255,255,255,.8);
}
#toast {
position: absolute;
z-index: 10;
left: 50%;
bottom: 82px;
max-width: min(90%, 420px);
padding: 11px 15px;
border-radius: 12px;
background: var(--ink);
color: white;
box-shadow: var(--shadow);
font-size: 12px;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity .2s ease, transform .2s ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.panel {
height: 100%;
overflow-y: auto;
padding: 25px 25px 40px;
border-left: 1px solid var(--line);
background: var(--panel);
box-shadow: -8px 0 28px rgba(49, 55, 46, .04);
scrollbar-width: thin;
scrollbar-color: #c9c4b7 transparent;
}
.panel-intro {
margin-bottom: 19px;
}
.panel-intro .eyebrow { margin-bottom: 8px; }
.panel-intro h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 500;
letter-spacing: -.025em;
}
.panel-intro p {
margin: 8px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section {
padding: 18px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type {
border-top: 0;
padding-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.section-title h3 {
margin: 0;
font-size: 13px;
font-weight: 800;
letter-spacing: .02em;
}
.text-button {
padding: 0;
border: 0;
background: none;
color: var(--green);
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
.text-button:hover { text-decoration: underline; }
.budget-card {
padding: 15px;
border: 1px solid #d9ddcf;
border-radius: 16px;
background: #f4f6ec;
}
.budget-top {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
}
.budget-number {
font-size: 26px;
font-weight: 780;
letter-spacing: -.04em;
}
.budget-number small {
color: var(--muted);
font-size: 12px;
font-weight: 600;
letter-spacing: 0;
}
.budget-free {
color: var(--green-dark);
font-size: 11px;
font-weight: 750;
text-align: right;
}
.budget-track {
height: 8px;
margin: 12px 0 9px;
overflow: hidden;
border-radius: 99px;
background: #dce2d2;
}
.budget-fill {
width: 50%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #78976a, var(--green));
transition: width .25s ease;
}
.budget-hint {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.zone {
padding: 13px 0;
border-bottom: 1px solid #ece8dd;
}
.zone:last-child {
padding-bottom: 0;
border-bottom: 0;
}
.zone-main {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
gap: 12px;
}
.zone h4 {
margin: 0 0 4px;
font-size: 12px;
font-weight: 800;
}
.zone p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.layer-control {
display: flex;
align-items: center;
gap: 7px;
}
.layer-button {
display: grid;
place-items: center;
width: 30px;
height: 30px;
padding: 0;
border: 1px solid #d7d3c8;
border-radius: 9px;
background: white;
font-size: 18px;
font-weight: 500;
line-height: 1;
cursor: pointer;
transition: transform .12s ease, background .12s ease;
}
.layer-button:hover:not(:disabled) {
background: var(--green-soft);
transform: translateY(-1px);
}
.layer-button:disabled {
opacity: .32;
cursor: not-allowed;
}
.layer-pips {
display: flex;
gap: 3px;
width: 30px;
justify-content: center;
}
.layer-pips i {
width: 6px;
height: 17px;
border-radius: 2px;
background: #ddd9ce;
transition: background .2s ease, transform .2s ease;
}
.layer-pips i.active {
background: var(--mulch);
transform: translateY(-2px);
}
.compare-card {
padding: 15px;
border: 1px solid #d7e1df;
border-radius: 16px;
background: #f2f8f7;
}
.compare-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
}
.compare-heading strong {
font-size: 12px;
}
.proxy-badge {
padding: 4px 7px;
border-radius: 99px;
background: #dceeed;
color: #326a7c;
font-size: 9px;
font-weight: 800;
letter-spacing: .05em;
text-transform: uppercase;
}
.bar-row {
margin-top: 12px;
}
.bar-label {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 6px;
color: #586860;
font-size: 10px;
}
.bar-label strong {
color: var(--ink);
font-size: 11px;
}
.bar-track {
height: 10px;
overflow: hidden;
border-radius: 99px;
background: #dce5e1;
}
.bar-fill {
height: 100%;
border-radius: inherit;
transition: width .3s ease;
}
.bar-fill.baseline { background: #9ca9a2; }
.bar-fill.current { background: linear-gradient(90deg, #68a8b9, #397b93); }
.comparison-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid #d7e1df;
}
.comparison-summary span {
color: #64716b;
font-size: 10px;
}
.comparison-summary strong {
color: var(--green-dark);
font-size: 13px;
}
.evap-row {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 8px;
color: var(--muted);
font-size: 10px;
}
.preview-button {
width: 100%;
margin-top: 12px;
padding: 10px 12px;
border: 1px solid #bfcfc9;
border-radius: 11px;
background: white;
color: #315d67;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: background .15s ease, color .15s ease;
}
.preview-button:hover { background: #e9f3f1; }
.preview-button.active {
border-color: var(--green-dark);
background: var(--green-dark);
color: white;
}
details {
margin-top: 5px;
border: 1px solid var(--line);
border-radius: 14px;
background: #faf8f1;
}
summary {
padding: 13px 14px;
font-size: 11px;
font-weight: 800;
cursor: pointer;
list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::after {
content: "+";
float: right;
color: var(--green);
font-size: 16px;
line-height: 11px;
}
details[open] summary::after { content: "−"; }
.assumption-body {
padding: 0 14px 14px;
color: #687169;
font-size: 10px;
line-height: 1.55;
}
.assumption-body ul {
margin: 0;
padding-left: 17px;
}
.assumption-body li + li { margin-top: 7px; }
.formula {
margin: 10px 0;
padding: 10px;
border-radius: 9px;
background: #eeece4;
color: #4b574f;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
line-height: 1.55;
overflow-wrap: anywhere;
}
.disclaimer {
margin-top: 12px;
padding: 10px;
border-left: 3px solid var(--gold);
background: #faf2df;
color: #715c33;
}
@media (max-width: 880px) {
body { overflow: auto; }
.app {
display: block;
height: auto;
min-height: 100vh;
}
.stage {
height: 58vh;
min-height: 430px;
}
.panel {
height: auto;
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.scene-heading {
top: 18px;
left: 18px;
}
.scene-heading p:last-child { display: none; }
.scene-tools {
top: 16px;
right: 15px;
}
.scene-bottom {
left: 15px;
right: 15px;
bottom: 13px;
}
.hint { display: none; }
}
@media (max-width: 520px) {
.scene-heading h1 { font-size: 31px; }
.legend { gap: 7px 10px; font-size: 9px; }
.panel { padding: 22px 18px 36px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
transition-duration: .001ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<main class="stage" id="stage">
<canvas
id="garden"
tabindex="0"
aria-label="Interactive low-poly toy garden. Drag to orbit, scroll to zoom, or use the camera buttons."
></canvas>
<div class="scene-heading">
<p class="eyebrow">A tiny experiments table</p>
<h1>Mulch Lab</h1>
<p>Spread a limited pile of mulch, then compare the fictional water-retention model.</p>
</div>
<div class="scene-tools" aria-label="Camera controls">
<button class="tool-button" id="zoom-in" aria-label="Zoom in">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="10.5" cy="10.5" r="6.5"></circle>
<path d="M15.5 15.5 21 21M10.5 7.5v6M7.5 10.5h6"></path>
</svg>
</button>
<button class="tool-button" id="zoom-out" aria-label="Zoom out">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="10.5" cy="10.5" r="6.5"></circle>
<path d="M15.5 15.5 21 21M7.5 10.5h6"></path>
</svg>
</button>
<button class="tool-button" id="reset-camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 12a8 8 0 1 0 2.2-5.5L4 8.7"></path>
<path d="M4 4v4.7h4.7"></path>
</svg>
</button>
</div>
<div class="scene-bottom">
<div class="legend" aria-label="Scene legend">
<span><i class="swatch"></i> mulch chips</span>
<span><i class="swatch water"></i> fictional evaporation</span>
<span><i class="swatch soil"></i> root-zone soil</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
</div>
<div id="toast" role="status" aria-live="polite"></div>
</main>
<aside class="panel">
<header class="panel-intro">
<p class="eyebrow">Interactive garden model</p>
<h2>Build your mulch mix</h2>
<p>
You have 18 scoops. Add layers to the three garden zones and watch the
toy retention estimate change.
</p>
</header>
<section class="section">
<div class="section-title">
<h3>Cover material</h3>
<button class="text-button" id="reset-mix" type="button">Reset mix</button>
</div>
<div class="budget-card">
<div class="budget-top">
<div class="budget-number">
<span id="used-scoops">9</span><small> / 18 scoops used</small>
</div>
<div class="budget-free" id="free-scoops">9 scoops free</div>
</div>
<div class="budget-track" aria-hidden="true">
<div class="budget-fill" id="budget-fill"></div>
</div>
<p class="budget-hint" id="budget-hint"></p>
</div>
</section>
<section class="section">
<div class="section-title">
<h3>Allocate layers</h3>
</div>
<div class="zone" data-zone="open">
<div class="zone-main">
<div>
<h4>Open bed</h4>
<p>4 scoops / layer · 62% of the root zone</p>
</div>
<div class="layer-control">
<button class="layer-button" data-action="minus" aria-label="Remove open bed layer">−</button>
<div class="layer-pips" data-pips="open" aria-label="Open bed layers">
<i></i><i></i><i></i>
</div>
<button class="layer-button" data-action="plus" aria-label="Add open bed layer">+</button>
</div>
</div>
</div>
<div class="zone" data-zone="rings">
<div class="zone-main">
<div>
<h4>Plant collars</h4>
<p>5 scoops / layer · 38% of the root zone</p>
</div>
<div class="layer-control">
<button class="layer-button" data-action="minus" aria-label="Remove plant collar layer">−</button>
<div class="layer-pips" data-pips="rings" aria-label="Plant collar layers">
<i></i><i></i><i></i>
</div>
<button class="layer-button" data-action="plus" aria-label="Add plant collar layer">+</button>
</div>
</div>
</div>
<div class="zone" data-zone="border">
<div class="zone-main">
<div>
<h4>Garden border</h4>
<p>2 scoops / layer · visual cover only</p>
</div>
<div class="layer-control">
<button class="layer-button" data-action="minus" aria-label="Remove garden border layer">−</button>
<div class="layer-pips" data-pips="border" aria-label="Garden border layers">
<i></i><i></i>
</div>
<button class="layer-button" data-action="plus" aria-label="Add garden border layer">+</button>
</div>
</div>
</div>
</section>
<section class="section">
<div class="section-title">
<h3>Water retention comparison</h3>
</div>
<div class="compare-card">
<div class="compare-heading">
<strong>Moisture index after one fictional day</strong>
<span class="proxy-badge">Toy proxy</span>
</div>
<div class="bar-row">
<div class="bar-label">
<span>No mulch</span>
<strong id="baseline-value">79.7 / 100</strong>
</div>
<div class="bar-track">
<div class="bar-fill baseline" id="baseline-bar"></div>
</div>
</div>
<div class="bar-row">
<div class="bar-label">
<span>Your mulch mix</span>
<strong id="current-value">86.0 / 100</strong>
</div>
<div class="bar-track">
<div class="bar-fill current" id="current-bar"></div>
</div>
</div>
<div class="comparison-summary">
<span>Change from uncovered soil</span>
<strong id="comparison-delta">+6.2 units</strong>
</div>
<div class="evap-row">
<span>Fictional evaporation</span>
<span><strong id="baseline-evap">20.3</strong> → <strong id="current-evap">14.2</strong> / day</span>
</div>
<button class="preview-button" id="preview-uncovered" type="button" aria-pressed="false">
Preview uncovered garden
</button>
</div>
</section>
<section class="section">
<details open>
<summary>Toy rules and explicit assumptions</summary>
<div class="assumption-body">
<ul>
<li>Every soil zone starts at <strong>100 fictional moisture units</strong>.</li>
<li>Uncovered evaporation is <strong>18 units/day</strong> in the open bed and <strong>24 units/day</strong> around plants.</li>
<li>Each mulch layer reduces that zone’s evaporation by <strong>30% of its uncovered rate</strong>. Reductions stack linearly.</li>
<li>The moisture score weights the open bed at <strong>62%</strong> and plant collars at <strong>38%</strong>.</li>
<li>Border mulch is visible but does not affect the root-zone moisture score.</li>
<li>One layer costs 4 scoops in the open bed, 5 around plants, and 2 at the border.</li>
</ul>
<div class="formula">
M₀ = 0.62(100 − 18) + 0.38(100 − 24) = 79.72<br>
M = 0.62[100 − 18(1 − 0.30Lₒ)] + 0.38[100 − 24(1 − 0.30Lᵣ)]
</div>
<div class="disclaimer">
This is an intentionally fictional classroom model, not horticultural
guidance or a prediction of real-world soil moisture.
</div>
</div>
</details>
</section>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model state
// -------------------------------------------------------------------------
const MATERIAL_BUDGET = 18;
const ZONES = {
open: { cost: 4, max: 3 },
rings: { cost: 5, max: 3 },
border: { cost: 2, max: 2 }
};
const state = {
layers: { open: 1, rings: 1, border: 0 },
previewUncovered: false
};
const usedScoops = () =>
Object.entries(state.layers).reduce(
(total, [zone, layers]) => total + layers * ZONES[zone].cost,
0
);
function computeMetrics() {
const baselineEvaporation = 0.62 * 18 + 0.38 * 24;
const openEvaporation =
18 * (1 - 0.30 * state.layers.open);
const ringEvaporation =
24 * (1 - 0.30 * state.layers.rings);
const currentEvaporation =
0.62 * openEvaporation + 0.38 * ringEvaporation;
return {
baselineEvaporation,
currentEvaporation,
baselineMoisture: 100 - baselineEvaporation,
currentMoisture: 100 - currentEvaporation
};
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const canvas = document.getElementById("garden");
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5d9);
scene.fog = new THREE.Fog(0xe9e5d9, 19, 34);
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(
0xfff7df,
0x697361,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.1);
sun.position.set(-6, 11, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 28;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7e3e7, 0.8);
fill.position.set(7, 4, -7);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe7e1d3,
roughness: 0.96
});
const ground = new THREE.Mesh(
new THREE.CircleGeometry(24, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.48;
ground.receiveShadow = true;
scene.add(ground);
const islandMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d1bf,
roughness: 0.95,
flatShading: true
});
const island = new THREE.Mesh(
new THREE.CylinderGeometry(7.8, 8.05, 0.38, 32),
islandMaterial
);
island.position.set(0.35, -0.25, 0.1);
island.receiveShadow = true;
island.castShadow = true;
scene.add(island);
// Raised wooden toy garden bed.
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x9c6941,
roughness: 0.88,
flatShading: true
});
const woodLightMaterial = new THREE.MeshStandardMaterial({
color: 0xb57b4e,
roughness: 0.88,
flatShading: true
});
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x5a392b,
roughness: 1,
flatShading: true
});
const soilTop = 0.50;
const soil = new THREE.Mesh(
new THREE.BoxGeometry(7.9, 0.46, 4.9),
soilMaterial
);
soil.position.y = 0.27;
soil.receiveShadow = true;
scene.add(soil);
function addBox(width, height, depth, x, y, z, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
addBox(8.65, 0.58, 0.30, 0, 0.48, -2.63, woodMaterial);
addBox(8.65, 0.58, 0.30, 0, 0.48, 2.63, woodLightMaterial);
addBox(0.30, 0.58, 5.25, -4.18, 0.48, 0, woodMaterial);
addBox(0.30, 0.58, 5.25, 4.18, 0.48, 0, woodMaterial);
// Corner pegs.
for (const x of [-4.18, 4.18]) {
for (const z of [-2.63, 2.63]) {
addBox(0.38, 0.72, 0.38, x, 0.57, z, woodLightMaterial);
}
}
// A few shallow soil furrows help the bed read as a toy garden.
const furrowMaterial = new THREE.MeshStandardMaterial({
color: 0x493025,
roughness: 1
});
for (const z of [-1.25, 0, 1.25]) {
addBox(7.0, 0.018, 0.10, 0, soilTop + 0.005, z, furrowMaterial, false);
}
// Low-poly plants.
const plantPositions = [
{ x: -2.65, z: -1.18, scale: 1.08 },
{ x: -0.92, z: -1.28, scale: 0.92 },
{ x: 0.86, z: -1.12, scale: 1.12 },
{ x: 2.58, z: -1.18, scale: 0.94 },
{ x: -2.02, z: 0.83, scale: 1.05 },
{ x: 0.10, z: 1.05, scale: 1.16 },
{ x: 2.04, z: 0.90, scale: 0.96 }
];
const plantGroups = [];
const stemMaterials = [
new THREE.MeshStandardMaterial({ color: 0x476f3d, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x355d38, flatShading: true })
];
const leafMaterials = [
new THREE.MeshStandardMaterial({ color: 0x5f8c45, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x78994d, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x3f713e, flatShading: true })
];
const stemGeometry = new THREE.CylinderGeometry(
0.075, 0.12, 1.25, 5
);
const leafGeometry = new THREE.IcosahedronGeometry(0.31, 0);
plantPositions.forEach((position, plantIndex) => {
const group = new THREE.Group();
group.position.set(position.x, soilTop, position.z);
group.scale.setScalar(position.scale);
group.userData.phase = plantIndex * 0.73;
const stem = new THREE.Mesh(
stemGeometry,
stemMaterials[plantIndex % stemMaterials.length]
);
stem.position.y = 0.61;
stem.castShadow = true;
group.add(stem);
for (let leafIndex = 0; leafIndex < 6; leafIndex++) {
const leaf = new THREE.Mesh(
leafGeometry,
leafMaterials[(plantIndex + leafIndex) % leafMaterials.length]
);
const angle = (leafIndex / 6) * Math.PI * 2 + plantIndex * 0.25;
const height = 0.42 + leafIndex * 0.105;
leaf.position.set(
Math.cos(angle) * 0.24,
height,
Math.sin(angle) * 0.24
);
leaf.scale.set(1, 0.28, 0.62);
leaf.rotation.set(
Math.sin(angle) * 0.42,
-angle,
Math.cos(angle) * 0.48
);
leaf.castShadow = true;
group.add(leaf);
}
const budGeometry = new THREE.IcosahedronGeometry(0.15, 0);
const budMaterial = new THREE.MeshStandardMaterial({
color: plantIndex % 2 ? 0xd7a44e : 0xbc6a59,
flatShading: true
});
const bud = new THREE.Mesh(budGeometry, budMaterial);
bud.position.set(0, 1.26, 0);
bud.scale.set(1, 1.35, 1);
bud.castShadow = true;
group.add(bud);
plantGroups.push(group);
scene.add(group);
});
// Shared mulch geometry and a deliberately limited earthy palette.
const mulchGeometry = new THREE.ConeGeometry(0.18, 0.075, 5);
const mulchMaterials = [
new THREE.MeshStandardMaterial({ color: 0x9f623b, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0xb87843, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0xc28a55, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x7d4b31, roughness: 1, flatShading: true })
];
const mulchGroup = new THREE.Group();
scene.add(mulchGroup);
// Supply tray: unused scoops appear as small blocks in the tray.
const tray = new THREE.Group();
tray.position.set(5.15, -0.05, 1.88);
tray.rotation.y = -0.10;
scene.add(tray);
addBox(1.55, 0.12, 1.12, 5.15, -0.07, 1.88, woodMaterial);
addBox(1.55, 0.43, 0.12, 5.15, 0.14, 1.32, woodLightMaterial);
addBox(1.55, 0.43, 0.12, 5.15, 0.14, 2.44, woodLightMaterial);
addBox(0.12, 0.43, 1.12, 4.44, 0.14, 1.88, woodLightMaterial);
addBox(0.12, 0.43, 1.12, 5.86, 0.14, 1.88, woodLightMaterial);
const supplyFill = new THREE.Group();
tray.add(supplyFill);
const scoopGeometry = new THREE.BoxGeometry(0.31, 0.18, 0.31);
const scoopMaterial = new THREE.MeshStandardMaterial({
color: 0xb97845,
roughness: 1,
flatShading: true
});
// Blue faceted beads represent fictional evaporation.
const waterFX = new THREE.Group();
scene.add(waterFX);
const dropletGeometry = new THREE.OctahedronGeometry(0.095, 0);
for (let i = 0; i < 30; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0x68a7b9,
transparent: true,
opacity: 0.6,
depthWrite: false
});
const drop = new THREE.Mesh(dropletGeometry, material);
drop.userData.phase = i / 30;
drop.userData.x = THREE.MathUtils.randFloat(-3.2, 3.2);
drop.userData.z = THREE.MathUtils.randFloat(-1.85, 1.85);
drop.position.set(
drop.userData.x,
soilTop + 0.2,
drop.userData.z
);
drop.scale.set(0.72, 1.25, 0.72);
waterFX.add(drop);
}
// Small decorative stones outside the bed.
const stoneGeometry = new THREE.DodecahedronGeometry(0.25, 0);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0xa8aa9b,
roughness: 0.95,
flatShading: true
});
[
[-3.8, -0.05, 3.2],
[-2.9, -0.07, 3.45],
[3.1, -0.05, -3.15],
[4.0, -0.07, -2.7]
].forEach(([x, y, z], index) => {
const stone = new THREE.Mesh(stoneGeometry, stoneMaterial);
stone.position.set(x, y, z);
stone.scale.set(1 + index * 0.08, 0.7, 0.9);
stone.rotation.set(index, index * 0.4, index * 0.2);
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
});
// -------------------------------------------------------------------------
// Procedural visual updates
// -------------------------------------------------------------------------
function clearGroup(group) {
while (group.children.length) {
group.remove(group.children[group.children.length - 1]);
}
}
function addMulchChip(x, z, layerIndex, sizeFactor = 1) {
const chip = new THREE.Mesh(
mulchGeometry,
mulchMaterials[Math.floor(Math.random() * mulchMaterials.length)]
);
chip.position.set(
x,
soilTop + 0.055 + layerIndex * 0.022 + Math.random() * 0.015,
z
);
const scale = THREE.MathUtils.randFloat(0.65, 1.2) * sizeFactor;
chip.scale.set(
scale * THREE.MathUtils.randFloat(0.82, 1.22),
THREE.MathUtils.randFloat(0.75, 1.25),
scale * THREE.MathUtils.randFloat(0.72, 1.08)
);
chip.rotation.set(
THREE.MathUtils.randFloat(-0.18, 0.18),
Math.random() * Math.PI * 2,
THREE.MathUtils.randFloat(-0.18, 0.18)
);
mulchGroup.add(chip);
}
function rebuildMulch() {
clearGroup(mulchGroup);
// Open bed chips exclude the plant-collar circles.
const openLayers = state.layers.open;
for (let layer = 0; layer < openLayers; layer++) {
for (let i = 0; i < 32; i++) {
const x = THREE.MathUtils.randFloat(-3.35, 3.35);
const z = THREE.MathUtils.randFloat(-1.90, 1.90);
const inPlantCollar = plantPositions.some(
plant => Math.hypot(x - plant.x, z - plant.z) < 0.68
);
if (!inPlantCollar) {
addMulchChip(x, z, layer);
}
}
}
// Additional chips make each plant collar visibly denser.
const ringLayers = state.layers.rings;
for (let layer = 0; layer < ringLayers; layer++) {
plantPositions.forEach(plant => {
for (let i = 0; i < 6; i++) {
const angle = Math.random() * Math.PI * 2;
const radius = THREE.MathUtils.randFloat(0.20, 0.73);
addMulchChip(
plant.x + Math.cos(angle) * radius,
plant.z + Math.sin(angle) * radius,
layer,
0.9
);
}
});
}
// Border chips sit in a narrow outer band.
const borderLayers = state.layers.border;
for (let layer = 0; layer < borderLayers; layer++) {
for (let i = 0; i < 20; i++) {
const side = Math.floor(Math.random() * 4);
let x, z;
if (side === 0) {
x = THREE.MathUtils.randFloat(-3.60, 3.60);
z = -2.14 + THREE.MathUtils.randFloat(-0.10, 0.10);
} else if (side === 1) {
x = THREE.MathUtils.randFloat(-3.60, 3.60);
z = 2.14 + THREE.MathUtils.randFloat(-0.10, 0.10);
} else if (side === 2) {
x = -3.62 + THREE.MathUtils.randFloat(-0.10, 0.10);
z = THREE.MathUtils.randFloat(-2.05, 2.05);
} else {
x = 3.62 + THREE.MathUtils.randFloat(-0.10, 0.10);
z = THREE.MathUtils.randFloat(-2.05, 2.05);
}
addMulchChip(x, z, layer, 0.94);
}
}
}
function rebuildSupplyTray() {
clearGroup(supplyFill);
const remaining = MATERIAL_BUDGET - usedScoops();
for (let i = 0; i < remaining; i++) {
const column = i % 6;
const row = Math.floor(i / 6);
const scoop = new THREE.Mesh(scoopGeometry, scoopMaterial);
scoop.position.set(
-0.53 + column * 0.21,
0.12 + row * 0.18,
(row % 2) * 0.06
);
scoop.rotation.y = (i % 3) * 0.18;
scoop.castShadow = true;
scoop.receiveShadow = true;
supplyFill.add(scoop);
}
}
const drySoilColor = new THREE.Color(0x674332);
const wetSoilColor = new THREE.Color(0x493025);
function updateSoilColor(metrics) {
const moisture = state.previewUncovered
? metrics.baselineMoisture
: metrics.currentMoisture;
const t = THREE.MathUtils.clamp((moisture - 72) / 28, 0, 1);
soilMaterial.color.copy(drySoilColor).lerp(wetSoilColor, t);
}
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
let cameraYaw = 0.66;
let cameraPitch = 0.61;
let cameraRadius = window.innerWidth < 880 ? 15.6 : 12.7;
const cameraTarget = new THREE.Vector3(0.35, 0.70, 0);
function applyCamera() {
const sinPitch = Math.sin(cameraPitch);
camera.position.set(
cameraTarget.x + cameraRadius * sinPitch * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.cos(cameraPitch),
cameraTarget.z + cameraRadius * sinPitch * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraYaw = 0.66;
cameraPitch = 0.61;
cameraRadius = window.innerWidth < 880 ? 15.6 : 12.7;
applyCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointer = null;
canvas.addEventListener("pointerdown", event => {
dragging = true;
activePointer = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.0045,
0.28,
1.18
);
applyCamera();
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.009,
8.5,
18.5
);
applyCamera();
}, { passive: false });
canvas.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraYaw += 0.12;
break;
case "ArrowRight":
cameraYaw -= 0.12;
break;
case "ArrowUp":
cameraPitch = Math.max(0.28, cameraPitch - 0.08);
break;
case "ArrowDown":
cameraPitch = Math.min(1.18, cameraPitch + 0.08);
break;
case "+":
case "=":
cameraRadius = Math.max(8.5, cameraRadius - 0.8);
break;
case "-":
case "_":
cameraRadius = Math.min(18.5, cameraRadius + 0.8);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
applyCamera();
}
});
document.getElementById("zoom-in").addEventListener("click", () => {
cameraRadius = Math.max(8.5, cameraRadius - 0.9);
applyCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
cameraRadius = Math.min(18.5, cameraRadius + 0.9);
applyCamera();
});
document.getElementById("reset-camera").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// UI updates
// -------------------------------------------------------------------------
const usedElement = document.getElementById("used-scoops");
const freeElement = document.getElementById("free-scoops");
const budgetFill = document.getElementById("budget-fill");
const budgetHint = document.getElementById("budget-hint");
const baselineValue = document.getElementById("baseline-value");
const currentValue = document.getElementById("current-value");
const baselineBar = document.getElementById("baseline-bar");
const currentBar = document.getElementById("current-bar");
const comparisonDelta = document.getElementById("comparison-delta");
const baselineEvap = document.getElementById("baseline-evap");
const currentEvap = document.getElementById("current-evap");
const previewButton = document.getElementById("preview-uncovered");
const toast = document.getElementById("toast");
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
function updateAllocationUI() {
const used = usedScoops();
const free = MATERIAL_BUDGET - used;
usedElement.textContent = used;
freeElement.textContent = `${free} scoop${free === 1 ? "" : "s"} free`;
budgetFill.style.width = `${(used / MATERIAL_BUDGET) * 100}%`;
budgetHint.textContent = free === 0
? "The supply is fully allocated. Remove a layer to make room for another."
: `${free} scoops remain. Layer costs: open 4, collars 5, border 2.`;
document.querySelectorAll(".zone").forEach(zoneElement => {
const zone = zoneElement.dataset.zone;
const layers = state.layers[zone];
const config = ZONES[zone];
const pips = zoneElement.querySelectorAll(".layer-pips i");
pips.forEach((pip, index) => {
pip.classList.toggle("active", index < layers);
});
zoneElement.querySelector('[data-action="minus"]').disabled = layers <= 0;
zoneElement.querySelector('[data-action="plus"]').disabled =
layers >= config.max || used + config.cost > MATERIAL_BUDGET;
});
}
function updateComparisonUI(metrics) {
baselineValue.textContent = `${metrics.baselineMoisture.toFixed(1)} / 100`;
currentValue.textContent = `${metrics.currentMoisture.toFixed(1)} / 100`;
baselineBar.style.width = `${metrics.baselineMoisture}%`;
currentBar.style.width = `${metrics.currentMoisture}%`;
const delta = metrics.currentMoisture - metrics.baselineMoisture;
comparisonDelta.textContent =
`${delta >= 0 ? "+" : ""}${delta.toFixed(1)} units`;
baselineEvap.textContent = metrics.baselineEvaporation.toFixed(1);
currentEvap.textContent = metrics.currentEvaporation.toFixed(1);
}
function updatePreviewButton() {
previewButton.classList.toggle("active", state.previewUncovered);
previewButton.setAttribute("aria-pressed", String(state.previewUncovered));
previewButton.textContent = state.previewUncovered
? "Return to your mulch mix"
: "Preview uncovered garden";
}
function updateEverything() {
const metrics = computeMetrics();
updateAllocationUI();
updateComparisonUI(metrics);
updatePreviewButton();
rebuildMulch();
rebuildSupplyTray();
updateSoilColor(metrics);
mulchGroup.visible = !state.previewUncovered;
}
document.querySelectorAll(".layer-button").forEach(button => {
button.addEventListener("click", () => {
const zone = button.closest(".zone").dataset.zone;
const action = button.dataset.action;
const config = ZONES[zone];
if (action === "minus") {
state.layers[zone] = Math.max(0, state.layers[zone] - 1);
} else {
if (state.layers[zone] >= config.max) return;
if (usedScoops() + config.cost > MATERIAL_BUDGET) {
showToast("Not enough mulch scoops for another layer.");
return;
}
state.layers[zone] += 1;
}
state.previewUncovered = false;
updateEverything();
});
});
document.getElementById("reset-mix").addEventListener("click", () => {
state.layers = { open: 1, rings: 1, border: 0 };
state.previewUncovered = false;
updateEverything();
showToast("Mix reset to one open-bed layer and one collar layer.");
});
previewButton.addEventListener("click", () => {
state.previewUncovered = !state.previewUncovered;
updateEverything();
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
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();
}
new ResizeObserver(resize).observe(stage);
resize();
applyCamera();
updateEverything();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const metrics = computeMetrics();
const evaporation = state.previewUncovered
? metrics.baselineEvaporation
: metrics.currentEvaporation;
const visibleDrops = THREE.MathUtils.clamp(
Math.round(evaporation * 1.5),
3,
30
);
waterFX.children.forEach((drop, index) => {
drop.visible = index < visibleDrops;
if (!drop.visible) return;
const life = (elapsed * 0.23 + drop.userData.phase) % 1;
const fade = Math.sin(life * Math.PI);
drop.position.x = drop.userData.x;
drop.position.z = drop.userData.z;
drop.position.y = soilTop + 0.18 + life * 2.05;
drop.material.opacity = fade * 0.58;
drop.scale.set(
0.72 - life * 0.15,
1.25 - life * 0.25,
0.72 - life * 0.15
);
});
plantGroups.forEach(plant => {
plant.rotation.z =
Math.sin(elapsed * 0.72 + plant.userData.phase) * 0.014;
plant.rotation.x =
Math.cos(elapsed * 0.63 + plant.userData.phase) * 0.009;
});
renderer.render(scene, camera);
});
</script>
</body>
</html>
```