Prompt specification
Build or customize the Three.js 3D scene "Pantanal grass clump on a low earth mound" 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: Pantanal grass clump on a low earth mound
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pantanal-grass-clump-on-a-low-earth-mound-x3105
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows the Pantanal's seasonal wetland mosaic. Build a small referenced wetland mound with grass, shallow water, and one higher dry patch. Make the tiny elevation differences visible through a sectional edge. Stylized solid forms.
Working Three.js Starter (pantanal-grass-clump-on-a-low-earth-mound-x3105):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pantanal — Seasonal Wetland Mosaic</title>
<style>
:root {
--ink: #263b32;
--muted: #68766d;
--paper: rgba(247, 244, 235, 0.92);
--line: rgba(38, 59, 50, 0.18);
--water: #4d9696;
--grass: #719457;
--dry: #b9854e;
--peat: #75503b;
--silt: #bc875e;
--sand: #d8b77e;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee9dd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
user-select: none;
}
.panel {
position: absolute;
padding: 18px 20px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 3px;
box-shadow:
0 12px 35px rgba(53, 58, 46, 0.10),
0 1px 0 rgba(255, 255, 255, 0.8) inset;
backdrop-filter: blur(10px);
}
#intro {
top: 28px;
left: 30px;
width: 320px;
}
.eyebrow {
margin-bottom: 9px;
color: #728174;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 11px;
color: #5f7065;
font-size: 12px;
font-weight: 650;
letter-spacing: 0.04em;
}
.description {
max-width: 265px;
margin: 15px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#legend {
left: 30px;
bottom: 28px;
display: flex;
flex-wrap: wrap;
gap: 9px 18px;
max-width: 460px;
padding: 13px 17px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #56675d;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
white-space: nowrap;
text-transform: uppercase;
}
.swatch {
display: inline-block;
width: 11px;
height: 11px;
border-radius: 50%;
box-shadow: 0 0 0 1px rgba(30, 45, 37, 0.12);
}
.swatch.water { background: var(--water); }
.swatch.grass { background: var(--grass); }
.swatch.dry { background: var(--dry); }
#section-card {
right: 30px;
bottom: 28px;
width: 252px;
}
.section-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 16px;
margin-bottom: 13px;
}
.section-title strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 500;
}
.section-title span {
color: #819084;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.stratum {
display: grid;
grid-template-columns: 16px 1fr auto;
align-items: center;
gap: 9px;
margin-top: 8px;
color: #5a685f;
font-size: 10px;
}
.stratum i {
width: 12px;
height: 8px;
border-radius: 1px;
}
.stratum b {
color: #7a847b;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
}
#controls {
top: 28px;
right: 30px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid var(--line);
border-radius: 2px;
padding: 10px 13px;
background: rgba(248, 246, 238, 0.9);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 7px 20px rgba(50, 55, 44, 0.08);
}
button:hover {
background: #fffdf7;
transform: translateY(-1px);
}
.callout {
position: absolute;
left: 0;
top: 0;
padding: 6px 9px;
border: 1px solid rgba(43, 65, 53, 0.18);
border-radius: 2px;
background: rgba(250, 247, 237, 0.92);
color: #334a3e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
box-shadow: 0 5px 16px rgba(43, 57, 45, 0.08);
}
.callout span {
display: block;
margin-top: 2px;
color: #839087;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.04em;
}
.callout::before {
content: "";
position: absolute;
left: -17px;
top: 50%;
width: 14px;
height: 1px;
background: rgba(43, 65, 53, 0.42);
}
#dry-tag::before {
left: auto;
right: -17px;
}
#hint {
position: absolute;
right: 31px;
top: 77px;
color: rgba(49, 70, 58, 0.65);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
@media (max-width: 760px) {
#intro {
top: 18px;
left: 18px;
width: 250px;
}
.description { display: none; }
#legend { left: 18px; bottom: 18px; right: 18px; }
#section-card { display: none; }
#controls { top: 18px; right: 18px; }
#hint { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D model of the Pantanal wetland mosaic"></canvas>
<div id="ui">
<section id="intro" class="panel">
<div class="eyebrow">Pantanal · Brazil</div>
<h1>Seasonal<br />wetland mosaic</h1>
<div class="subtitle">A small interpretive terrain model</div>
<p class="description">
Shallow seasonal water threads through low grassland.
A compact dry crown rises above the floodplain; the cut
edge reveals how slight changes in elevation organize the habitat.
</p>
</section>
<div id="controls">
<button id="reset" type="button">Reset view</button>
</div>
<div id="hint">Drag to orbit · scroll to zoom</div>
<section id="legend" class="panel">
<div class="legend-item">
<span class="swatch water"></span>Seasonal water
</div>
<div class="legend-item">
<span class="swatch grass"></span>Low grassland
</div>
<div class="legend-item">
<span class="swatch dry"></span>Dry crown
</div>
</section>
<section id="section-card" class="panel">
<div class="section-title">
<strong>Sectional edge</strong>
<span>0.8 m profile</span>
</div>
<div class="stratum">
<i style="background:var(--dry)"></i>
Root mat
<b>surface</b>
</div>
<div class="stratum">
<i style="background:var(--peat)"></i>
Flooded peat
<b>0–0.2</b>
</div>
<div class="stratum">
<i style="background:var(--silt)"></i>
Silt deposit
<b>−0.2–0.5</b>
</div>
<div class="stratum">
<i style="background:var(--sand)"></i>
Sandy subsoil
<b>−0.5–0.8</b>
</div>
</section>
<div id="cut-tag" class="callout">
Cut edge
<span>0.8 m section</span>
</div>
<div id="dry-tag" class="callout">
Higher dry patch
<span>+0.3 m crown</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9dd);
scene.fog = new THREE.Fog(0xeee9dd, 14, 28);
const camera = new THREE.PerspectiveCamera(
33,
window.innerWidth / window.innerHeight,
0.1,
60
);
const world = new THREE.Group();
scene.add(world);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff9e9, 0x817761, 1.65));
const sun = new THREE.DirectionalLight(0xfff4d8, 2.35);
sun.position.set(-4.5, 8.5, 5.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 22;
sun.shadow.bias = -0.0007;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaec9d0, 0.45);
fill.position.set(5, 3, -4);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared geometry helpers
// -------------------------------------------------------------------------
const WIDTH = 6;
const DEPTH = 4.2;
const WATER_LEVEL = 0.16;
const DRY_CENTER = { x: 1.35, z: 0.08 };
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function ellipseMask(x, z, cx, cz, rx, rz) {
const dx = (x - cx) / rx;
const dz = (z - cz) / rz;
return Math.sqrt(dx * dx + dz * dz);
}
function dryMask(x, z) {
return ellipseMask(x, z, DRY_CENTER.x, DRY_CENTER.z, 0.78, 0.55);
}
function mainWaterMask(x, z) {
return ellipseMask(x, z, -1.1, -0.27, 1.18, 0.63);
}
function smallWaterMask(x, z) {
return ellipseMask(x, z, -0.1, 0.72, 0.36, 0.21);
}
function heightAt(x, z) {
const broadMound =
0.115 * Math.exp(-(x * x / 7.5 + z * z / 4.8));
const dryCrown =
0.255 * Math.exp(
-(
Math.pow((x - DRY_CENTER.x) / 0.72, 2) +
Math.pow((z - DRY_CENTER.z) / 0.53, 2)
)
);
const mainBasin =
0.112 * Math.exp(
-(
Math.pow((x + 1.1) / 1.03, 2) +
Math.pow((z + 0.27) / 0.73, 2)
)
);
const smallBasin =
0.085 * Math.exp(
-(
Math.pow((x + 0.1) / 0.42, 2) +
Math.pow((z - 0.72) / 0.25, 2)
)
);
return 0.145 + broadMound + dryCrown - mainBasin - smallBasin;
}
function makeLine(points, color, opacity = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
const line = new THREE.Line(geometry, material);
world.add(line);
return line;
}
// -------------------------------------------------------------------------
// Topographic terrain
// -------------------------------------------------------------------------
function terrainColor(x, z, y) {
const color = new THREE.Color(0x719354);
const elevated = clamp((y - 0.16) * 1.65, 0, 0.8);
color.lerp(new THREE.Color(0x95a965), elevated);
const dry = dryMask(x, z);
if (dry < 1.12) {
color.lerp(
new THREE.Color(0xb28650),
clamp((1.12 - dry) * 1.15, 0, 0.82)
);
}
const wet = Math.min(mainWaterMask(x, z), smallWaterMask(x, z));
if (wet < 1.2) {
color.lerp(
new THREE.Color(0x587f62),
clamp((1.2 - wet) * 0.9, 0, 0.72)
);
}
const variation =
0.035 *
Math.sin(x * 5.7 + z * 2.1) *
Math.cos(z * 4.6 - x * 1.7);
color.offsetHSL(0, 0, variation);
return color;
}
const nx = 38;
const nz = 28;
const positions = [];
const colors = [];
const indices = [];
for (let iz = 0; iz <= nz; iz++) {
const z = -DEPTH / 2 + (iz / nz) * DEPTH;
for (let ix = 0; ix <= nx; ix++) {
const x = -WIDTH / 2 + (ix / nx) * WIDTH;
const y = heightAt(x, z);
const color = terrainColor(x, z, y);
positions.push(x, y, z);
colors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
terrainGeometry.setIndex(indices);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
})
);
terrain.receiveShadow = true;
terrain.castShadow = true;
world.add(terrain);
// -------------------------------------------------------------------------
// Section walls: the front edge exposes the soil profile.
// -------------------------------------------------------------------------
const layers = [
{
upper: (x, z) => heightAt(x, z),
lower: (x, z) => heightAt(x, z) - 0.055,
color: 0x405a3e
},
{
upper: (x, z) => heightAt(x, z) - 0.055,
lower: () => -0.04,
color: 0x73503b
},
{
upper: () => -0.04,
lower: () => -0.34,
color: 0xb9855c
},
{
upper: () => -0.34,
lower: () => -0.78,
color: 0xd6b47a
}
];
const wallEdges = [
{
a: [-WIDTH / 2, DEPTH / 2],
b: [ WIDTH / 2, DEPTH / 2],
segments: 40
},
{
a: [ WIDTH / 2, -DEPTH / 2],
b: [-WIDTH / 2, -DEPTH / 2],
segments: 40
},
{
a: [-WIDTH / 2, -DEPTH / 2],
b: [-WIDTH / 2, DEPTH / 2],
segments: 28
},
{
a: [ WIDTH / 2, DEPTH / 2],
b: [ WIDTH / 2, -DEPTH / 2],
segments: 28
}
];
function buildLayerWalls(layer) {
const wallPositions = [];
for (const edge of wallEdges) {
for (let i = 0; i < edge.segments; i++) {
const t0 = i / edge.segments;
const t1 = (i + 1) / edge.segments;
const ax = THREE.MathUtils.lerp(edge.a[0], edge.b[0], t0);
const az = THREE.MathUtils.lerp(edge.a[1], edge.b[1], t0);
const bx = THREE.MathUtils.lerp(edge.a[0], edge.b[0], t1);
const bz = THREE.MathUtils.lerp(edge.a[1], edge.b[1], t1);
const axTop = layer.upper(ax, az);
const azTop = layer.lower(ax, az);
const bxTop = layer.upper(bx, bz);
const bzTop = layer.lower(bx, bz);
wallPositions.push(
ax, azTop, az,
bx, bzTop, bz,
bx, bxTop, bz,
ax, azTop, az,
bx, bxTop, bz,
ax, axTop, az
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(wallPositions, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: layer.color,
roughness: 0.98,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
world.add(mesh);
}
layers.forEach(buildLayerWalls);
const base = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH + 0.1, 0.065, DEPTH + 0.1),
new THREE.MeshStandardMaterial({
color: 0xd9b982,
roughness: 1
})
);
base.position.y = -0.81;
base.receiveShadow = true;
base.castShadow = true;
world.add(base);
// Fine lines accent the exposed strata.
for (const y of [-0.04, -0.34]) {
const points = [];
for (let i = 0; i <= 50; i++) {
const x = -WIDTH / 2 + (i / 50) * WIDTH;
points.push(new THREE.Vector3(x, y, DEPTH / 2 + 0.012));
}
makeLine(points, 0x765e45, 0.55);
}
const topEdge = [];
for (let i = 0; i <= 50; i++) {
const x = -WIDTH / 2 + (i / 50) * WIDTH;
topEdge.push(
new THREE.Vector3(x, heightAt(x, DEPTH / 2) + 0.012, DEPTH / 2 + 0.014)
);
}
makeLine(topEdge, 0x314a39, 0.9);
// -------------------------------------------------------------------------
// Shallow seasonal water
// -------------------------------------------------------------------------
function makeFlatPatch(cx, cz, rx, rz, y, material, outlineColor) {
const count = 34;
const points = [];
const patchPositions = [cx, y, cz];
const patchIndices = [];
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
const irregular =
1 +
0.055 * Math.sin(angle * 3 + cx) +
0.035 * Math.cos(angle * 5 - cz);
const x = cx + Math.cos(angle) * rx * irregular;
const z = cz + Math.sin(angle) * rz * irregular;
points.push(new THREE.Vector3(x, y + 0.005, z));
patchPositions.push(x, y, z);
}
for (let i = 0; i < count; i++) {
const current = i + 1;
const next = ((i + 1) % count) + 1;
patchIndices.push(0, next, current);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(patchPositions, 3)
);
geometry.setIndex(patchIndices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
mesh.renderOrder = 2;
world.add(mesh);
const outline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: outlineColor,
transparent: true,
opacity: 0.82
})
);
outline.renderOrder = 3;
world.add(outline);
return { mesh, points };
}
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x4f9999,
roughness: 0.24,
metalness: 0.06,
transparent: true,
opacity: 0.82,
depthWrite: false,
side: THREE.DoubleSide
});
const smallWaterMaterial = waterMaterial.clone();
smallWaterMaterial.color.setHex(0x579b9a);
smallWaterMaterial.opacity = 0.76;
makeFlatPatch(
-1.1,
-0.27,
1.18,
0.63,
WATER_LEVEL,
waterMaterial,
0x376f70
);
makeFlatPatch(
-0.1,
0.72,
0.36,
0.21,
WATER_LEVEL + 0.001,
smallWaterMaterial,
0x3e7774
);
// A few restrained current marks help the water read as a flat surface.
for (const offset of [-0.18, 0.12]) {
const current = [];
for (let i = 0; i <= 16; i++) {
const t = i / 16;
const x = -1.68 + t * 1.14;
const z = -0.27 + offset + Math.sin(t * Math.PI * 2) * 0.035;
current.push(new THREE.Vector3(x, WATER_LEVEL + 0.009, z));
}
makeLine(current, 0xb4d3c7, 0.52);
}
// -------------------------------------------------------------------------
// Higher dry patch
// -------------------------------------------------------------------------
function makeDryPatch() {
const count = 26;
const center = new THREE.Vector3(
DRY_CENTER.x,
heightAt(DRY_CENTER.x, DRY_CENTER.z) + 0.021,
DRY_CENTER.z
);
const perimeter = [];
const dryPositions = [];
const dryColors = [];
const dryIndices = [];
const palette = [
new THREE.Color(0xb98b50),
new THREE.Color(0xc59a60),
new THREE.Color(0xaa7844),
new THREE.Color(0xc09a62)
];
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
const irregular =
1 +
0.065 * Math.sin(angle * 3 + 0.7) +
0.035 * Math.cos(angle * 5);
const x = DRY_CENTER.x + Math.cos(angle) * 0.78 * irregular;
const z = DRY_CENTER.z + Math.sin(angle) * 0.55 * irregular;
const y = heightAt(x, z) + 0.023;
perimeter.push(new THREE.Vector3(x, y + 0.004, z));
}
for (let i = 0; i < count; i++) {
const p0 = center;
const p1 = perimeter[i];
const p2 = perimeter[(i + 1) % count];
dryPositions.push(
p0.x, p0.y, p0.z,
p2.x, p2.y, p2.z,
p1.x, p1.y, p1.z
);
const color = palette[i % palette.length];
for (let j = 0; j < 3; j++) {
dryColors.push(color.r, color.g, color.b);
}
dryIndices.push(i * 3, i * 3 + 1, i * 3 + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dryPositions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(dryColors, 3)
);
geometry.setIndex(dryIndices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.renderOrder = 1;
world.add(mesh);
const outline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(perimeter),
new THREE.LineBasicMaterial({
color: 0x8d633c,
transparent: true,
opacity: 0.66
})
);
world.add(outline);
// An inner contour makes the small elevation change legible.
const inner = [];
for (let i = 0; i <= 32; i++) {
const angle = (i / 32) * Math.PI * 2;
const x = DRY_CENTER.x + Math.cos(angle) * 0.47;
const z = DRY_CENTER.z + Math.sin(angle) * 0.29;
inner.push(new THREE.Vector3(x, heightAt(x, z) + 0.028, z));
}
makeLine(inner, 0x8f6941, 0.48);
}
makeDryPatch();
// A few low-poly stones on the dry crown.
const rockGeometry = new THREE.DodecahedronGeometry(0.105, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x9b7854,
roughness: 1,
flatShading: true
});
const rockPositions = [
[1.14, 0.18, 0.065, 1.0],
[1.52, -0.08, 0.085, 0.85],
[1.48, 0.28, 0.055, 0.72],
[1.27, -0.02, 0.04, 0.6]
];
for (const [x, z, scale, flatten] of rockPositions) {
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
rock.position.set(x, heightAt(x, z) + 0.035, z);
rock.scale.set(scale, scale * flatten, scale * 0.88);
rock.rotation.set(0.2, x * 1.9, -0.1);
rock.castShadow = true;
rock.receiveShadow = true;
world.add(rock);
}
// -------------------------------------------------------------------------
// Stylized solid grass
// -------------------------------------------------------------------------
let randomSeed = 73921;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const grassGeometry = new THREE.ConeGeometry(0.043, 0.30, 4);
grassGeometry.translate(0, 0.15, 0);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
flatShading: true
});
const grassCount = 270;
const grass = new THREE.InstancedMesh(
grassGeometry,
grassMaterial,
grassCount
);
const dummy = new THREE.Object3D();
const grassPalette = [
new THREE.Color(0x527943),
new THREE.Color(0x668c4e),
new THREE.Color(0x789857),
new THREE.Color(0x456f3d)
];
let grassIndex = 0;
let attempts = 0;
while (grassIndex < grassCount && attempts < grassCount * 20) {
attempts++;
const x = (random() - 0.5) * (WIDTH - 0.18);
const z = (random() - 0.5) * (DEPTH - 0.18);
const y = heightAt(x, z);
const inWater =
mainWaterMask(x, z) < 1.08 ||
smallWaterMask(x, z) < 1.12;
const onDryPatch = dryMask(x, z) < 1.1;
if (y < 0.175 || inWater || onDryPatch) continue;
const size = 0.72 + random() * 0.62;
dummy.position.set(x, y + 0.006, z);
dummy.rotation.set(
(random() - 0.5) * 0.08,
random() * Math.PI * 2,
(random() - 0.5) * 0.08
);
dummy.scale.set(
0.75 + random() * 0.45,
size,
0.75 + random() * 0.45
);
dummy.updateMatrix();
grass.setMatrixAt(grassIndex, dummy.matrix);
grass.setColorAt(
grassIndex,
grassPalette[Math.floor(random() * grassPalette.length)]
);
grassIndex++;
}
grass.count = grassIndex;
grass.instanceMatrix.needsUpdate = true;
if (grass.instanceColor) grass.instanceColor.needsUpdate = true;
grass.castShadow = true;
grass.receiveShadow = true;
world.add(grass);
// Sparse emergent reeds around the main pool.
const reedGeometry = new THREE.CylinderGeometry(
0.012,
0.018,
0.36,
5
);
reedGeometry.translate(0, 0.18, 0);
const reedMaterial = new THREE.MeshStandardMaterial({
color: 0x426d47,
roughness: 0.9,
flatShading: true
});
const reedCount = 30;
const reeds = new THREE.InstancedMesh(
reedGeometry,
reedMaterial,
reedCount
);
for (let i = 0; i < reedCount; i++) {
const angle = (i / reedCount) * Math.PI * 2 + random() * 0.13;
const x = -1.1 + Math.cos(angle) * (1.08 + random() * 0.09);
const z = -0.27 + Math.sin(angle) * (0.55 + random() * 0.07);
dummy.position.set(x, WATER_LEVEL - 0.005, z);
dummy.rotation.set(
(random() - 0.5) * 0.14,
random() * Math.PI,
(random() - 0.5) * 0.14
);
dummy.scale.set(1, 0.72 + random() * 0.72, 1);
dummy.updateMatrix();
reeds.setMatrixAt(i, dummy.matrix);
}
reeds.instanceMatrix.needsUpdate = true;
reeds.castShadow = true;
world.add(reeds);
// -------------------------------------------------------------------------
// Elevation ruler at the cut edge
// -------------------------------------------------------------------------
makeLine(
[
new THREE.Vector3(3.23, -0.76, 2.18),
new THREE.Vector3(3.23, 0.62, 2.18)
],
0x6d6959,
0.8
);
for (const y of [-0.75, -0.5, -0.25, 0, 0.25, 0.5]) {
makeLine(
[
new THREE.Vector3(3.15, y, 2.18),
new THREE.Vector3(3.31, y, 2.18)
],
0x6d6959,
0.8
);
}
// -------------------------------------------------------------------------
// Ground and background
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xe8e3d7,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.85;
ground.receiveShadow = true;
scene.add(ground);
// A restrained elliptical grounding shadow beneath the model.
const shadowShape = new THREE.Mesh(
new THREE.CircleGeometry(1, 64),
new THREE.MeshBasicMaterial({
color: 0x5d584b,
transparent: true,
opacity: 0.08,
depthWrite: false
})
);
shadowShape.rotation.x = -Math.PI / 2;
shadowShape.scale.set(4.1, 2.8, 1);
shadowShape.position.set(0.12, -0.842, 0.15);
scene.add(shadowShape);
// -------------------------------------------------------------------------
// Direct camera controls — no external controls/addons
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, 0.02, 0);
const defaults = {
theta: 0.69,
phi: 0.96,
radius: 9.35
};
const orbit = { ...defaults };
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = clamp(orbit.phi + dy * 0.005, 0.38, 1.42);
updateCamera();
});
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();
orbit.radius = clamp(
orbit.radius + event.deltaY * 0.008,
6.1,
13.5
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
Object.assign(orbit, defaults);
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Projected annotations
// -------------------------------------------------------------------------
const cutTag = document.getElementById("cut-tag");
const dryTag = document.getElementById("dry-tag");
const cutAnchor = new THREE.Vector3(2.65, 0.48, 2.14);
const dryAnchor = new THREE.Vector3(1.35, 0.61, 0.08);
function placeAnnotation(element, anchor) {
const projected = anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.display = visible ? "block" : "none";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
renderer.setAnimationLoop(() => {
placeAnnotation(cutTag, cutAnchor);
placeAnnotation(dryTag, dryAnchor);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```