Prompt specification
Build or customize the Three.js 3D scene "Oasis well rim and shaded planting basin" 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: Oasis well rim and shaded planting basin
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/oasis-well-rim-and-shaded-planting-basin-x3113
Scene Description Prompt:
A voxel oasis well beside a shaded palm planting basin, with roots and dry ground visible. Three.js from cdnjs, one HTML file.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Generate a nonempty water region before applying instance colors. Keep the visible well rim, water, and shaded planting basin distinguishable.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (oasis-well-rim-and-shaded-planting-basin-x3113):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#dfd2b6">
<title>Voxel Oasis — Procedural Field Plate</title>
<style>
:root {
--ink: #342d26;
--muted: #75685a;
--paper: rgba(255, 250, 238, 0.91);
--line: rgba(78, 65, 50, 0.22);
--accent: #287e8f;
--green: #426d45;
--shadow: rgba(67, 48, 28, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfd2b6;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
body::after {
content: "";
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
box-shadow: inset 0 0 150px rgba(81, 61, 38, 0.13);
background:
repeating-linear-gradient(
0deg,
rgba(255, 255, 255, 0.012) 0,
rgba(255, 255, 255, 0.012) 1px,
transparent 1px,
transparent 4px
);
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
touch-action: none;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
}
.brand {
position: fixed;
z-index: 5;
top: 28px;
left: 30px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.38);
}
.eyebrow {
margin-bottom: 7px;
color: #6f604f;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 51px);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.95;
}
.brand p {
margin: 10px 0 0;
color: #66594b;
font-size: 11px;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.toolbar {
position: fixed;
z-index: 6;
top: 25px;
right: 28px;
display: flex;
gap: 7px;
}
.tool-button {
min-height: 36px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 4px;
color: var(--ink);
background: rgba(255, 250, 238, 0.84);
box-shadow: 0 5px 18px rgba(76, 55, 32, 0.08);
cursor: pointer;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(9px);
}
.tool-button:hover,
.tool-button:focus-visible {
border-color: rgba(40, 126, 143, 0.58);
color: #1f6877;
outline: none;
transform: translateY(-1px);
}
.inspector {
position: fixed;
z-index: 6;
left: 28px;
bottom: 27px;
width: 318px;
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 6px;
background: var(--paper);
box-shadow: 0 16px 45px var(--shadow);
backdrop-filter: blur(12px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
padding-bottom: 10px;
border-bottom: 1px solid var(--line);
}
.panel-heading strong {
font-size: 10px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: #49734a;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #5f925c;
box-shadow: 0 0 0 3px rgba(95, 146, 92, 0.12);
}
.stat-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 11px 17px;
}
.stat {
min-width: 0;
}
.stat span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.stat strong {
display: block;
overflow: hidden;
color: var(--ink);
font-size: 12px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.audit-line {
display: flex;
align-items: center;
gap: 8px;
margin-top: 14px;
padding: 9px 10px;
border: 1px solid rgba(70, 112, 70, 0.22);
border-radius: 3px;
color: #456d49;
background: rgba(92, 139, 88, 0.08);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.audit-line::before {
content: "";
flex: 0 0 auto;
width: 7px;
height: 7px;
border: 2px solid #5f925c;
border-radius: 50%;
}
.audit-line.failed {
color: #9a493b;
border-color: rgba(154, 73, 59, 0.3);
background: rgba(154, 73, 59, 0.08);
}
.audit-line.failed::before {
border-color: #a45142;
}
.selection-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
#selectionStatus {
text-align: right;
}
.next-button {
width: 100%;
margin-top: 13px;
padding: 10px 12px;
border: 1px solid rgba(40, 126, 143, 0.4);
border-radius: 3px;
color: #f5fbf8;
background: #347f8d;
box-shadow: 0 5px 14px rgba(40, 126, 143, 0.18);
cursor: pointer;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.next-button:hover,
.next-button:focus-visible {
background: #286f7d;
outline: 2px solid rgba(40, 126, 143, 0.22);
outline-offset: 2px;
}
.hint {
position: fixed;
z-index: 5;
right: 30px;
bottom: 28px;
max-width: 360px;
color: rgba(57, 49, 40, 0.72);
font-size: 9px;
line-height: 1.7;
letter-spacing: 0.07em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
}
.hint b {
color: #3e352c;
}
#labelLayer {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.annotation {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px 5px 5px;
border: 1px solid rgba(69, 58, 46, 0.27);
border-radius: 3px;
color: #493e32;
background: rgba(255, 250, 236, 0.88);
box-shadow: 0 5px 14px rgba(64, 47, 28, 0.1);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
line-height: 1;
white-space: nowrap;
backdrop-filter: blur(5px);
}
.annotation::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 21px;
background: rgba(63, 51, 39, 0.46);
}
.annotation b {
display: grid;
width: 18px;
height: 18px;
place-items: center;
border-radius: 2px;
color: #fffaf0;
background: #66594b;
font-size: 8px;
}
.annotation.cell-label {
border-color: rgba(40, 126, 143, 0.38);
color: #235e69;
background: rgba(232, 250, 244, 0.92);
}
.annotation.cell-label b {
background: #347f8d;
}
body.labels-off .annotation {
opacity: 0 !important;
visibility: hidden !important;
}
#error {
position: fixed;
inset: 24px;
z-index: 20;
display: grid;
place-content: center;
padding: 30px;
border: 1px solid rgba(120, 65, 45, 0.35);
border-radius: 6px;
color: #563a2d;
background: #f2e6cf;
box-shadow: 0 25px 80px rgba(70, 45, 25, 0.25);
text-align: center;
}
#error h2 {
margin: 0 0 10px;
font-family: Georgia, serif;
font-weight: 500;
}
#error p {
max-width: 620px;
margin: 0;
font-size: 12px;
line-height: 1.6;
}
[hidden] {
display: none !important;
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
}
.brand h1 {
font-size: 31px;
}
.brand p {
display: none;
}
.toolbar {
top: 17px;
right: 17px;
}
.tool-button {
padding: 0 9px;
font-size: 8px;
}
.inspector {
left: 14px;
bottom: 14px;
width: min(310px, calc(100vw - 28px));
padding: 13px 14px;
}
.stat-grid {
gap: 8px 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive procedural voxel oasis"></div>
<div id="labelLayer" aria-hidden="true">
<div class="annotation" id="labelWell"><b>A</b><span>STONE WELL</span></div>
<div class="annotation" id="labelBasin"><b>B</b><span>PALM BASIN / SHADE</span></div>
<div class="annotation" id="labelRoots"><b>C</b><span>EXPOSED ROOT ZONE</span></div>
<div class="annotation" id="labelWater"><b>D</b><span>WATER CELL FIELD</span></div>
<div class="annotation" id="labelDry"><b>E</b><span>DRY GROUND</span></div>
<div class="annotation cell-label" id="labelCell"><b>W</b><span>WATER CELL</span></div>
</div>
<header class="brand">
<div class="eyebrow">Schematic field plate / 07</div>
<h1>Voxel Oasis</h1>
<p>Stone well · shaded palm planting basin</p>
</header>
<nav class="toolbar" aria-label="Scene controls">
<button class="tool-button" id="resetView" type="button">Reset view</button>
<button class="tool-button" id="toggleLabels" type="button" aria-pressed="true">Hide labels</button>
</nav>
<section class="inspector" aria-label="Geometry inspector">
<div class="panel-heading">
<strong>Scene inspection</strong>
<span class="live">Live geometry</span>
</div>
<div class="stat-grid">
<div class="stat">
<span>Water records / instances</span>
<strong id="waterGeometry">—</strong>
</div>
<div class="stat">
<span>Selected cell</span>
<strong id="selectedCell">—</strong>
</div>
<div class="stat">
<span>Instance ID</span>
<strong id="selectedInstance">—</strong>
</div>
<div class="stat">
<span>Root segments</span>
<strong id="rootCount">—</strong>
</div>
</div>
<div class="audit-line" id="geometryAudit">Checking linked geometry</div>
<div class="selection-row">
<span id="selectedCoords">Grid —</span>
<span id="selectionStatus" aria-live="polite">Preparing selection</span>
</div>
<button class="next-button" id="nextCell" type="button">Select next water cell</button>
</section>
<div class="hint">
<b>Drag</b> orbit · <b>Shift + drag</b> pan · <b>Wheel</b> zoom<br>
<b>Click</b> a blue water voxel · <b>R</b> reset · <b>L</b> labels
</div>
<div id="error" role="alert" hidden>
<h2>Scene unavailable</h2>
<p id="errorMessage"></p>
</div>
<script type="module">
const errorPanel = document.getElementById("error");
const errorMessage = document.getElementById("errorMessage");
try {
const THREE = await import("https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js");
initializeScene(THREE);
} catch (error) {
console.error(error);
errorMessage.textContent =
"The Three.js module or scene initialization could not be completed. " +
(error && error.message ? error.message : String(error));
errorPanel.hidden = false;
}
function initializeScene(THREE) {
const viewport = document.getElementById("viewport");
const waterGeometryLabel = document.getElementById("waterGeometry");
const selectedCellLabel = document.getElementById("selectedCell");
const selectedInstanceLabel = document.getElementById("selectedInstance");
const rootCountLabel = document.getElementById("rootCount");
const geometryAuditLabel = document.getElementById("geometryAudit");
const selectionStatus = document.getElementById("selectionStatus");
const selectedCoords = document.getElementById("selectedCoords");
const cellLabel = document.getElementById("labelCell");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfd2b6);
scene.fog = new THREE.Fog(0xdfd2b6, 28, 54);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Voxel oasis diorama");
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-12, 12, 8, -8, 0.1, 100);
const orbit = {
yaw: 0.62,
pitch: 0.67,
zoom: 1.03
};
const cameraTarget = new THREE.Vector3(0, 0.85, 0);
const hemisphere = new THREE.HemisphereLight(0xfff0cf, 0x6e5c49, 1.65);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe9b9, 3.15);
sun.position.set(7, 18, 1);
sun.target.position.set(2, 0, -1);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun, sun.target);
const coolFill = new THREE.DirectionalLight(0x9fc5cf, 0.5);
coolFill.position.set(-10, 7, -8);
scene.add(coolFill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, roughness = 0.86) {
const key = `${color}:${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, roughness = 0.86) {
const mesh = new THREE.Mesh(unitBox, getMaterial(color, roughness));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function hash2(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
function cellKey(x, z) {
return `${x},${z}`;
}
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xd9cbb0,
roughness: 1,
metalness: 0
})
);
backdrop.rotation.x = -Math.PI / 2;
backdrop.position.y = -1.27;
backdrop.receiveShadow = true;
scene.add(backdrop);
const poolRows = [
{ z: -3, xs: [-6, -5, -4] },
{ z: -2, xs: [-7, -6, -5, -4, -3] },
{ z: -1, xs: [-7, -6, -5, -4, -3, -2] },
{ z: 0, xs: [-7, -6, -5, -4, -3, -2, -1] },
{ z: 1, xs: [-6, -5, -4, -3, -2, -1, 0] },
{ z: 2, xs: [-5, -4, -3, -2, -1] },
{ z: 3, xs: [-4, -3] }
];
const poolCells = [];
const poolSet = new Set();
for (const row of poolRows) {
for (const x of row.xs) {
poolCells.push({ x, z: row.z });
poolSet.add(cellKey(x, row.z));
}
}
const terrainData = [];
const terrainTop = new Map();
for (let x = -9; x <= 9; x++) {
for (let z = -7; z <= 7; z++) {
const footprint = (x / 9.6) ** 2 + (z / 7.6) ** 2;
const edgeVariation = (hash2(x + 17, z - 9) - 0.5) * 0.13;
if (footprint > 1.03 + edgeVariation) continue;
if (poolSet.has(cellKey(x, z))) continue;
let top = 0.025 + hash2(x, z) * 0.095;
if (x > 1 && z > 1) {
top += 0.035 + hash2(x - 5, z + 8) * 0.035;
}
const height = 1.24 + top;
terrainData.push({ x, z, top, height });
terrainTop.set(cellKey(x, z), top);
}
}
const terrainMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const terrain = new THREE.InstancedMesh(
unitBox,
terrainMaterial,
terrainData.length
);
terrain.name = "DryGroundTiles";
terrain.castShadow = true;
terrain.receiveShadow = true;
const dummy = new THREE.Object3D();
const earthPalette = [
0xb68154, 0xc39363, 0xc99d6d, 0xb47d52,
0xd0a575, 0xbe8b5c, 0xcaa16e
];
terrainData.forEach((tile, index) => {
dummy.position.set(tile.x, tile.top - tile.height / 2, tile.z);
dummy.scale.set(0.982, tile.height, 0.982);
dummy.updateMatrix();
terrain.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color(
earthPalette[Math.floor(hash2(tile.x - 3, tile.z + 11) * earthPalette.length)]
);
color.offsetHSL(0, 0, (hash2(tile.x + 8, tile.z) - 0.5) * 0.045);
terrain.setColorAt(index, color);
});
terrain.instanceMatrix.setUsage(THREE.StaticDrawUsage);
terrain.instanceColor.needsUpdate = true;
terrain.computeBoundingSphere();
scene.add(terrain);
function groundY(x, z) {
return terrainTop.get(cellKey(Math.round(x), Math.round(z))) ?? 0.08;
}
for (const cell of poolCells) {
addBox(
scene,
[0.94, 0.13, 0.94],
[cell.x, -0.26, cell.z],
hash2(cell.x, cell.z) > 0.52 ? 0x236f83 : 0x1e6176,
0.98
);
}
const cardinalDirections = [
[1, 0], [-1, 0], [0, 1], [0, -1]
];
for (const cell of poolCells) {
for (const [dx, dz] of cardinalDirections) {
if (poolSet.has(cellKey(cell.x + dx, cell.z + dz))) continue;
addBox(
scene,
[0.94, 0.30, 0.94],
[cell.x + dx * 0.47, 0.10, cell.z + dz * 0.47],
hash2(cell.x + dx * 7, cell.z + dz * 9) > 0.5 ? 0xc79b67 : 0xb98759
);
}
for (const [dx, dz] of [[1, 1], [1, -1], [-1, 1], [-1, -1]]) {
const sideA = poolSet.has(cellKey(cell.x + dx, cell.z));
const sideB = poolSet.has(cellKey(cell.x, cell.z + dz));
if (!sideA && !sideB) {
addBox(
scene,
[0.82, 0.26, 0.82],
[cell.x + dx * 0.47, 0.08, cell.z + dz * 0.47],
0xc0925e
);
}
}
}
const waterGeometry = new THREE.BoxGeometry(0.77, 0.20, 0.77);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.27,
metalness: 0.025,
emissive: 0x092a35,
emissiveIntensity: 0.28,
flatShading: true
});
const waterMesh = new THREE.InstancedMesh(
waterGeometry,
waterMaterial,
poolCells.length
);
waterMesh.name = "WaterCellInstances";
waterMesh.castShadow = false;
waterMesh.receiveShadow = true;
waterMesh.frustumCulled = false;
const waterPalette = [0x278da7, 0x339db4, 0x3ca6ba, 0x247f9b, 0x48a8ba];
const waterData = [];
poolCells.forEach((cell, index) => {
dummy.position.set(cell.x, 0.07, cell.z);
dummy.scale.set(1, 1, 1);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
waterMesh.setMatrixAt(index, dummy.matrix);
const baseColor = new THREE.Color(
waterPalette[Math.floor(hash2(cell.x + 4, cell.z - 6) * waterPalette.length)]
);
baseColor.offsetHSL(0, 0, (hash2(cell.x - 7, cell.z + 2) - 0.5) * 0.045);
waterMesh.setColorAt(index, baseColor);
waterData.push({
index,
id: `W-${String(index + 1).padStart(2, "0")}`,
x: cell.x,
z: cell.z,
baseColor
});
});
waterMesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
waterMesh.instanceColor.setUsage(THREE.DynamicDrawUsage);
waterMesh.instanceColor.needsUpdate = true;
waterMesh.computeBoundingSphere();
scene.add(waterMesh);
const selectedWaterColor = new THREE.Color(0x91ead6);
const selectionMarker = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.81, 0.235, 0.81)),
new THREE.LineBasicMaterial({
color: 0xffedb0,
transparent: true,
opacity: 0.95,
depthWrite: false
})
);
selectionMarker.name = "SelectedWaterCellOutline";
selectionMarker.renderOrder = 4;
scene.add(selectionMarker);
const basin = new THREE.Group();
basin.position.set(4.0, 0, -1.2);
scene.add(basin);
const soilColors = [0x493727, 0x55402d, 0x3f3023];
for (let ix = -2; ix <= 2; ix++) {
for (let iz = -2; iz <= 2; iz++) {
if (ix * ix + iz * iz > 4.25) continue;
addBox(
basin,
[0.94, 0.22, 0.94],
[ix, 0.20, iz],
soilColors[Math.abs(ix + iz) % soilColors.length],
1
);
}
}
for (let index = 0; index < 24; index++) {
const angle = (index / 24) * Math.PI * 2;
const rim = addBox(
basin,
[0.76, 0.52, 0.68],
[Math.cos(angle) * 2.18, 0.25, Math.sin(angle) * 2.18],
index % 3 === 0 ? 0xb39a74 : 0xc0a77f
);
rim.rotation.y = -angle;
}
function addPalm(baseX, baseZ, height, scale, leanX, leanZ, phase) {
const palm = new THREE.Group();
palm.position.set(baseX, 0, baseZ);
scene.add(palm);
const segmentCount = Math.max(7, Math.round(height / 0.52));
const segmentHeight = height / segmentCount;
const trunkColors = [0x8c5b37, 0x9a6740, 0x7f5132];
for (let index = 0; index < segmentCount; index++) {
const t = index / Math.max(1, segmentCount - 1);
const width = (0.49 - t * 0.15) * scale;
const segment = addBox(
palm,
[width, segmentHeight * 0.91, width],
[
leanX * t * t,
0.35 + (index + 0.5) * segmentHeight,
leanZ * t * t
],
trunkColors[index % trunkColors.length],
0.94
);
segment.rotation.y = phase + t * 0.28;
segment.rotation.z = -leanX * 0.018;
}
const crownX = leanX;
const crownY = 0.35 + height;
const crownZ = leanZ;
const leafColors = [0x3e7541, 0x4e8b49, 0x32653b, 0x629650];
for (let branch = 0; branch < 8; branch++) {
const angle = phase + branch * (Math.PI * 2 / 8) + (hash2(branch, scale * 10) - 0.5) * 0.16;
const length = (3.05 + hash2(branch + 4, scale * 7) * 0.65) * scale;
for (let segment = 0; segment < 7; segment++) {
const t = segment / 6;
const radius = t * length;
const leafSize = (0.65 - t * 0.24) * scale;
const leaf = addBox(
palm,
[leafSize * 0.96, leafSize * 0.43, leafSize * 0.62],
[
crownX + Math.cos(angle) * radius,
crownY + (1.22 * Math.sin(t * Math.PI * 0.9) - 1.52 * t * t) * scale,
crownZ + Math.sin(angle) * radius
],
leafColors[(branch + segment) % leafColors.length],
0.91
);
leaf.rotation.set(0, -angle, 0.18 * (1 - t * 2));
}
}
addBox(palm, [0.72 * scale, 0.48 * scale, 0.72 * scale], [crownX, crownY, crownZ], 0x3f713e);
for (let index = 0; index < 3; index++) {
const angle = phase + index * 2.1;
addBox(
palm,
[0.30 * scale, 0.30 * scale, 0.30 * scale],
[
crownX + Math.cos(angle) * 0.34 * scale,
crownY - 0.28 * scale,
crownZ + Math.sin(angle) * 0.34 * scale
],
0x68452a
);
}
}
addPalm(3.72, -1.48, 5.65, 1.0, -0.38, 0.18, 0.35);
addPalm(5.18, -1.74, 4.15, 0.73, 0.32, -0.18, 1.15);
addPalm(3.00, -2.55, 3.35, 0.58, -0.24, -0.12, 2.25);
const well = new THREE.Group();
well.position.set(-0.9, 0, -3.2);
scene.add(well);
const wellStoneColors = [0x9d917d, 0xaaa087, 0x8e836f, 0xb2a88e];
for (let level = 0; level < 3; level++) {
for (let ix = -1; ix <= 1; ix++) {
for (let iz = -1; iz <= 1; iz++) {
if (ix === 0 && iz === 0) continue;
const color = wellStoneColors[Math.floor(hash2(ix + 4, iz + level * 3) * wellStoneColors.length)];
addBox(
well,
[0.59, 0.34, 0.59],
[ix * 0.62, 0.23 + level * 0.34, iz * 0.62],
color,
0.98
);
}
}
}
addBox(well, [0.91, 0.08, 0.91], [0, 0.43, 0], 0x287f91, 0.3);
addBox(well, [0.22, 2.50, 0.22], [-1.03, 1.43, 0], 0x67452f);
addBox(well, [0.22, 2.50, 0.22], [1.03, 1.43, 0], 0x745036);
addBox(well, [2.48, 0.19, 0.23], [0, 2.73, 0], 0x5e402d);
addBox(well, [0.58, 0.10, 0.13], [1.32, 2.73, 0], 0x765138);
addBox(well, [0.11, 0.34, 0.11], [1.54, 2.61, 0], 0x4b3b2c);
addBox(well, [0.035, 1.22, 0.035], [0, 1.95, 0], 0x5b4b36, 1);
addBox(well, [0.52, 0.34, 0.08], [0, 1.08, 0.24], 0x7a5132);
addBox(well, [0.52, 0.34, 0.08], [0, 1.08, -0.24], 0x69472f);
addBox(well, [0.08, 0.34, 0.40], [0.24, 1.08, 0], 0x825735);
addBox(well, [0.08, 0.34, 0.40], [-0.24, 1.08, 0], 0x71492f);
addBox(well, [0.47, 0.055, 0.45], [0, 0.91, 0], 0x2f2924);
let rootSegmentCount = 0;
const xAxis = new THREE.Vector3(1, 0, 0);
function addRootPath(points, color) {
for (let index = 0; index < points.length - 1; index++) {
const start = new THREE.Vector3(...points[index]);
const end = new THREE.Vector3(...points[index + 1]);
const direction = end.clone().sub(start);
const length = direction.length();
const root = addBox(
scene,
[length, 0.12, 0.16],
start.clone().add(end).multiplyScalar(0.5).toArray(),
color,
0.98
);
root.quaternion.setFromUnitVectors(xAxis, direction.normalize());
root.castShadow = false;
rootSegmentCount++;
}
}
addRootPath([
[3.72, 0.32, -1.30], [3.35, 0.25, -0.35], [3.18, 0.19, 0.78],
[3.02, 0.16, 1.65], [2.45, 0.15, 2.55], [1.65, 0.15, 3.35]
], 0x8a5f3d);
addRootPath([
[3.75, 0.31, -1.35], [4.32, 0.24, -0.55], [4.74, 0.18, 0.55],
[5.18, 0.16, 1.52], [5.85, 0.15, 2.50], [6.55, 0.15, 3.38]
], 0x765137);
addRootPath([
[3.60, 0.30, -1.50], [3.05, 0.22, -2.55], [2.30, 0.16, -3.25],
[1.35, 0.15, -3.75]
], 0x684a35);
addRootPath([
[3.18, 0.18, 0.78], [3.85, 0.15, 0.98], [4.45, 0.15, 1.38]
], 0x9a7048);
addRootPath([
[4.74, 0.18, 0.55], [4.55, 0.15, -0.08], [4.02, 0.15, -0.55]
], 0x83593c);
function addCrack(points, width = 0.045) {
for (let index = 0; index < points.length - 1; index++) {
const start = new THREE.Vector3(points[index][0], 0, points[index][1]);
const end = new THREE.Vector3(points[index + 1][0], 0, points[index + 1][1]);
const direction = end.clone().sub(start);
const length = direction.length();
const y = Math.max(groundY(start.x, start.z), groundY(end.x, end.z)) + 0.018;
const crack = addBox(
scene,
[length, 0.026, width],
[(start.x + end.x) / 2, y, (start.z + end.z) / 2],
0x74573f,
1
);
crack.quaternion.setFromUnitVectors(xAxis, direction.normalize());
crack.castShadow = false;
}
}
addCrack([
[1.15, 2.65], [2.15, 3.08], [3.12, 2.82], [3.78, 3.52],
[4.87, 3.34], [5.78, 4.02], [7.05, 3.84]
]);
addCrack([
[3.12, 2.82], [3.45, 1.95], [4.08, 1.56]
], 0.037);
addCrack([
[5.78, 4.02], [6.14, 4.78], [6.82, 5.08]
], 0.035);
function addDryTuft(x, z) {
const base = groundY(x, z);
for (let index = 0; index < 4; index++) {
const angle = index * 1.7;
const blade = addBox(
scene,
[0.065, 0.31 + index * 0.025, 0.065],
[
x + Math.cos(angle) * 0.075,
base + 0.16,
z + Math.sin(angle) * 0.075
],
index % 2 ? 0xa88955 : 0x8d7046
);
blade.rotation.set(
Math.sin(angle) * 0.2,
angle,
Math.cos(angle) * 0.26
);
blade.castShadow = false;
}
}
[
[1.1, 3.75], [1.85, 4.65], [2.65, 4.9], [4.8, 4.55],
[6.65, 2.72], [7.15, 4.55], [5.95, 5.25], [2.2, 1.25],
[6.95, 0.55], [7.25, 1.35]
].forEach(([x, z]) => addDryTuft(x, z));
[
[1.45, 3.15, 0.31], [2.82, 4.35, 0.25], [4.55, 4.72, 0.34],
[6.85, 3.12, 0.27], [5.38, 1.48, 0.23], [7.3, 2.28, 0.32]
].forEach(([x, z, size], index) => {
const rock = addBox(
scene,
[size, size * 0.72, size * 0.9],
[x, groundY(x, z) + size * 0.33, z],
index % 2 ? 0x9c8060 : 0xaa8b68
);
rock.rotation.y = hash2(x, z) * Math.PI;
});
function addReeds(x, z) {
for (let index = 0; index < 4; index++) {
const offsetX = (index - 1.5) * 0.12;
const height = 0.48 + hash2(index, x) * 0.42;
addBox(
scene,
[0.075, height, 0.075],
[x + offsetX, 0.24 + height / 2, z + Math.sin(index) * 0.08],
index % 2 ? 0x587947 : 0x6b8b4c
);
}
}
addReeds(-6.82, -1.25);
addReeds(-3.68, -3.52);
addReeds(0.42, 1.38);
addReeds(-4.72, 3.46);
let selectedIndex = -1;
const auditMatrix = new THREE.Matrix4();
function auditWaterState() {
const record = selectedIndex >= 0 ? waterData[selectedIndex] : null;
const recordsMatchInstances =
waterData.length === waterMesh.count &&
waterData.every((cell, index) => cell.index === index);
let matrixMatches = false;
if (record) {
waterMesh.getMatrixAt(selectedIndex, auditMatrix);
const elements = auditMatrix.elements;
matrixMatches =
Math.abs(elements[12] - record.x) < 0.001 &&
Math.abs(elements[14] - record.z) < 0.001;
}
const linked =
recordsMatchInstances &&
!!waterMesh.instanceColor &&
!!record &&
matrixMatches;
geometryAuditLabel.textContent = linked
? `Geometry + color linked · ${waterMesh.count}/${waterData.length}`
: "Linked-state check failed";
geometryAuditLabel.classList.toggle("failed", !linked);
return linked;
}
function selectWater(index) {
const record = waterData[index];
if (!record || !waterMesh || !waterMesh.instanceColor) {
selectionStatus.textContent = "No valid water instance";
return false;
}
if (selectedIndex >= 0 && waterData[selectedIndex]) {
waterMesh.setColorAt(selectedIndex, waterData[selectedIndex].baseColor);
}
waterMesh.setColorAt(record.index, selectedWaterColor);
waterMesh.instanceColor.needsUpdate = true;
selectedIndex = record.index;
selectionMarker.position.set(record.x, 0.085, record.z);
selectedCellLabel.textContent = record.id;
selectedInstanceLabel.textContent = String(record.index).padStart(2, "0");
selectedCoords.textContent = `Grid x ${record.x} / z ${record.z}`;
selectionStatus.textContent = `Linked to instance ${record.index}`;
cellLabel.querySelector("span").textContent = `${record.id} · INSTANCE ${record.index}`;
auditWaterState();
return true;
}
const initialWater = waterData.reduce((closest, cell) => {
const distance = Math.abs(cell.x + 4) + Math.abs(cell.z);
const closestDistance = Math.abs(closest.x + 4) + Math.abs(closest.z);
return distance < closestDistance ? cell : closest;
}, waterData[0]);
selectWater(initialWater.index);
waterGeometryLabel.textContent = `${waterData.length} / ${waterMesh.count}`;
rootCountLabel.textContent = String(rootSegmentCount);
function updateCamera() {
const radius = 30;
camera.position.set(
cameraTarget.x + Math.sin(orbit.yaw) * Math.cos(orbit.pitch) * radius,
cameraTarget.y + Math.sin(orbit.pitch) * radius,
cameraTarget.z + Math.cos(orbit.yaw) * Math.cos(orbit.pitch) * radius
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
orbit.yaw = 0.62;
orbit.pitch = 0.67;
orbit.zoom = 1.03;
cameraTarget.set(0, 0.85, 0);
updateCamera();
}
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
const viewHeight = Math.max(14.6, 23 / aspect);
renderer.setSize(width, height, false);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
if ("ResizeObserver" in window) {
new ResizeObserver(resize).observe(viewport);
}
resize();
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickWater(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObject(waterMesh, false);
for (const intersection of intersections) {
const index = intersection.instanceId;
if (Number.isInteger(index) && waterData[index]) {
return index;
}
}
return -1;
}
let activePointer = null;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
event.preventDefault();
activePointer = {
id: event.pointerId,
button: event.button,
startX: event.clientX,
startY: event.clientY,
startYaw: orbit.yaw,
startPitch: orbit.pitch,
startTarget: cameraTarget.clone(),
pan: event.button === 2 || event.shiftKey,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointer || event.pointerId !== activePointer.id) {
const hoverIndex = pickWater(event.clientX, event.clientY);
renderer.domElement.style.cursor = hoverIndex >= 0 ? "pointer" : "grab";
return;
}
const totalX = event.clientX - activePointer.startX;
const totalY = event.clientY - activePointer.startY;
if (Math.hypot(totalX, totalY) > 4) activePointer.moved = true;
if (!activePointer.moved) return;
if (activePointer.pan) {
const pixelsPerUnit = viewport.clientHeight /
((camera.top - camera.bottom) / camera.zoom);
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 2);
forward.y = 0;
forward.normalize();
cameraTarget
.copy(activePointer.startTarget)
.addScaledVector(right, -totalX / pixelsPerUnit)
.addScaledVector(forward, -totalY / pixelsPerUnit);
} else {
orbit.yaw = activePointer.startYaw - totalX * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
activePointer.startPitch + totalY * 0.0045,
0.28,
1.18
);
}
updateCamera();
});
function finishPointer(event, cancelled = false) {
if (!activePointer || event.pointerId !== activePointer.id) return;
const wasClick =
!cancelled &&
!activePointer.moved &&
!activePointer.pan &&
activePointer.button === 0;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
activePointer = null;
if (wasClick) {
const index = pickWater(event.clientX, event.clientY);
if (index >= 0) {
selectWater(index);
} else {
selectionStatus.textContent = "Selection retained · choose a blue cell";
}
}
renderer.domElement.style.cursor =
pickWater(event.clientX, event.clientY) >= 0 ? "pointer" : "grab";
}
renderer.domElement.addEventListener("pointerup", (event) => finishPointer(event));
renderer.domElement.addEventListener("pointercancel", (event) => finishPointer(event, true));
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.8
);
updateCamera();
}, { passive: false });
document.getElementById("resetView").addEventListener("click", resetCamera);
document.getElementById("nextCell").addEventListener("click", () => {
if (!waterData.length) return;
selectWater((selectedIndex + 1) % waterData.length);
});
let labelsEnabled = true;
const toggleLabels = document.getElementById("toggleLabels");
toggleLabels.addEventListener("click", () => {
labelsEnabled = !labelsEnabled;
document.body.classList.toggle("labels-off", !labelsEnabled);
toggleLabels.setAttribute("aria-pressed", String(labelsEnabled));
toggleLabels.textContent = labelsEnabled ? "Hide labels" : "Show labels";
});
window.addEventListener("keydown", (event) => {
if (event.ctrlKey || event.metaKey || event.altKey) return;
const key = event.key.toLowerCase();
if (key === "r") resetCamera();
if (key === "l") toggleLabels.click();
if (key === "n" && waterData.length) {
selectWater((selectedIndex + 1) % waterData.length);
}
});
const annotationItems = [
{
element: document.getElementById("labelWell"),
point: new THREE.Vector3(-0.9, 3.03, -3.2),
offset: [18, -8]
},
{
element: document.getElementById("labelBasin"),
point: new THREE.Vector3(4.0, 5.95, -1.2),
offset: [38, -12]
},
{
element: document.getElementById("labelRoots"),
point: new THREE.Vector3(3.55, 0.28, 2.25),
offset: [30, 7]
},
{
element: document.getElementById("labelWater"),
point: new THREE.Vector3(-4.0, 0.22, 0.0),
offset: [-24, -13]
},
{
element: document.getElementById("labelDry"),
point: new THREE.Vector3(5.8, 0.24, 4.1),
offset: [25, 9]
}
];
const selectedCellAnchor = new THREE.Vector3(
initialWater.x,
0.24,
initialWater.z
);
const projected = new THREE.Vector3();
function positionLabel(element, point, offsetX = 0, offsetY = 0) {
projected.copy(point).project(camera);
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const x = (projected.x * 0.5 + 0.5) * width + offsetX;
const y = (-projected.y * 0.5 + 0.5) * height + offsetY;
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
x > -80 &&
x < width + 80 &&
y > -40 &&
y < height + 60;
element.style.visibility = visible ? "visible" : "hidden";
element.style.transform =
`translate3d(${x.toFixed(1)}px, ${y.toFixed(1)}px, 0) translate(-50%, -100%)`;
}
function updateLabels() {
annotationItems.forEach((item) => {
positionLabel(item.element, item.point, item.offset[0], item.offset[1]);
});
positionLabel(cellLabel, selectedCellAnchor, 0, -18);
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
updateLabels();
}
animate();
}
</script>
</body>
</html>
```