Prompt specification
Build or customize the Three.js 3D scene "Andean terrace wall and planting strip" 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: Andean terrace wall and planting strip
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/andean-terrace-wall-and-planting-strip-x2253
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: Andean terrace wall and planting strip. Build one stone-supported planting terrace on a steep slope. Expose the retaining wall, level growing surface, and drainage layers using a compact cutaway section. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (andean-terrace-wall-and-planting-strip-x2253):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Andean Terrace — Cutaway Study</title>
<style>
:root {
--ink: #29251f;
--muted: #71685b;
--paper: rgba(248, 241, 224, 0.9);
--line: rgba(73, 59, 42, 0.18);
--accent: #d78d3f;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 66% 30%, rgba(255, 249, 229, 0.96), transparent 34%),
linear-gradient(155deg, #f4ead8 0%, #dfcfb4 55%, #c8b28e 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage, #leaders, #annotations {
position: fixed;
inset: 0;
}
#stage {
z-index: 0;
touch-action: none;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
}
canvas.dragging { cursor: grabbing; }
#leaders {
z-index: 2;
width: 100%;
height: 100%;
pointer-events: none;
overflow: visible;
transition: opacity 180ms ease;
}
#leaders path {
fill: none;
stroke: rgba(72, 55, 35, 0.72);
stroke-width: 1.15;
stroke-dasharray: 4 5;
vector-effect: non-scaling-stroke;
}
#leaders circle {
fill: #f8edcf;
stroke: #76512d;
stroke-width: 1.5;
vector-effect: non-scaling-stroke;
}
#annotations {
z-index: 3;
pointer-events: none;
transition: opacity 180ms ease;
}
.pin {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 8px;
min-width: 150px;
padding: 8px 11px 8px 8px;
border: 1px solid rgba(93, 70, 41, 0.2);
border-radius: 999px;
background: rgba(250, 244, 226, 0.9);
box-shadow: 0 7px 22px rgba(73, 52, 30, 0.12);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
white-space: nowrap;
will-change: transform;
}
.pin b {
display: grid;
place-items: center;
width: 24px;
height: 24px;
flex: 0 0 auto;
border-radius: 50%;
background: #725337;
color: #fff7df;
font-size: 10px;
letter-spacing: 0.04em;
}
.pin span {
font-size: 11px;
font-weight: 700;
letter-spacing: 0.025em;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid rgba(87, 67, 42, 0.17);
background: var(--paper);
box-shadow: 0 14px 42px rgba(83, 58, 28, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 4px 18px 18px 18px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #8a5e31;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 330px;
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.controls {
top: 22px;
right: 22px;
display: flex;
gap: 6px;
padding: 6px;
border-radius: 13px;
}
.controls button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 7px;
min-height: 35px;
padding: 0 12px;
border: 0;
border-radius: 9px;
background: transparent;
color: #51483c;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
cursor: pointer;
transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
.controls button:hover {
background: rgba(112, 81, 42, 0.1);
color: #2f2922;
}
.controls button:active { transform: translateY(1px); }
.controls svg {
width: 15px;
height: 15px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.legend {
right: 22px;
bottom: 22px;
width: 290px;
padding: 14px 15px 15px;
border-radius: 16px 4px 16px 16px;
pointer-events: none;
}
.legend-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 11px;
padding-bottom: 9px;
border-bottom: 1px solid var(--line);
}
.legend-head strong {
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-head small {
color: #877866;
font-size: 9px;
white-space: nowrap;
}
.legend-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
color: #5f5548;
font-size: 10px;
line-height: 1.25;
}
.legend-item i {
width: 13px;
height: 13px;
flex: 0 0 auto;
border: 1px solid rgba(41, 31, 20, 0.18);
border-radius: 3px;
box-shadow: inset 0 1px rgba(255,255,255,.25);
}
.legend-item b {
display: block;
color: #3b342b;
font-size: 10px;
font-weight: 750;
}
.legend-item small {
display: block;
margin-top: 1px;
color: #8a7c69;
font-size: 8px;
}
.hint {
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border-radius: 999px;
color: #716657;
font-size: 10px;
pointer-events: none;
}
.mouse {
position: relative;
width: 14px;
height: 19px;
border: 1.5px solid #776552;
border-radius: 8px;
}
.mouse::after {
content: "";
position: absolute;
top: 3px;
left: 50%;
width: 2px;
height: 5px;
border-radius: 2px;
background: #8b6e48;
transform: translateX(-50%);
}
.labels-off #annotations,
.labels-off #leaders {
opacity: 0;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #eadfc9;
color: #755437;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
body.ready #loading {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 112px);
padding: 13px 14px;
}
.eyebrow { margin-bottom: 6px; font-size: 8px; }
.eyebrow::before { width: 16px; }
h1 { font-size: clamp(21px, 6vw, 29px); }
.subtitle { display: none; }
.controls {
top: 12px;
right: 12px;
flex-direction: column;
padding: 5px;
}
.controls button {
width: 37px;
min-height: 34px;
padding: 0;
}
.controls button span { display: none; }
.legend {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 10px 11px;
border-radius: 13px;
}
.legend-head { margin-bottom: 8px; padding-bottom: 7px; }
.legend-grid {
display: flex;
gap: 12px;
overflow-x: auto;
scrollbar-width: none;
}
.legend-grid::-webkit-scrollbar { display: none; }
.legend-item { flex: 0 0 auto; }
.hint { display: none; }
.pin {
min-width: 0;
padding: 5px 8px 5px 5px;
gap: 6px;
}
.pin b {
width: 20px;
height: 20px;
font-size: 8px;
}
.pin span {
max-width: 100px;
overflow: hidden;
font-size: 9px;
text-overflow: ellipsis;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<svg id="leaders" aria-hidden="true">
<path id="leader-wall"></path>
<path id="leader-surface"></path>
<path id="leader-drainage"></path>
<circle id="dot-wall" r="4"></circle>
<circle id="dot-surface" r="4"></circle>
<circle id="dot-drainage" r="4"></circle>
</svg>
<div id="annotations" aria-hidden="true">
<div class="pin" id="pin-wall"><b>01</b><span>Stone retaining wall</span></div>
<div class="pin" id="pin-surface"><b>02</b><span>Level growing surface</span></div>
<div class="pin" id="pin-drainage"><b>03</b><span>Drainage layers + outlet</span></div>
</div>
<header class="panel title-card">
<div class="eyebrow">Andean terrace · cutaway study</div>
<h1>Stone-supported<br>planting terrace</h1>
<p class="subtitle">
A compact section through a high-altitude terrace, revealing the masonry support,
level cultivation bed, and graded drainage courses.
</p>
</header>
<nav class="panel controls" aria-label="Scene controls">
<button id="focus-section" type="button" title="Focus on cutaway section">
<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="6"></circle><path d="m16 16 4 4M11 8v6M8 11h6"></path></svg>
<span>Section</span>
</button>
<button id="reset-view" type="button" title="Reset camera">
<svg viewBox="0 0 24 24"><path d="M4 11a8 8 0 1 1 2 5.3M4 16v-5h5"></path></svg>
<span>Reset</span>
</button>
<button id="toggle-labels" type="button" title="Toggle annotations">
<svg viewBox="0 0 24 24"><path d="M4 6h16v12H9l-5 3V6Z"></path><path d="M8 10h8M8 14h5"></path></svg>
<span>Labels</span>
</button>
</nav>
<aside class="panel legend">
<div class="legend-head">
<strong>Section A—A</strong>
<small>schematic · not to scale</small>
</div>
<div class="legend-grid">
<div class="legend-item">
<i style="background:#8d7b62"></i>
<span><b>Stone masonry</b><small>retaining wall</small></span>
</div>
<div class="legend-item">
<i style="background:#4c3327"></i>
<span><b>Topsoil</b><small>190 mm</small></span>
</div>
<div class="legend-item">
<i style="background:#75513b"></i>
<span><b>Subsoil</b><small>600 mm</small></span>
</div>
<div class="legend-item">
<i style="background:#c9a870"></i>
<span><b>Filter sand</b><small>200 mm</small></span>
</div>
<div class="legend-item">
<i style="background:#92816c"></i>
<span><b>Drainage gravel</b><small>380 mm</small></span>
</div>
<div class="legend-item">
<i style="background:#a77955"></i>
<span><b>Compacted base</b><small>1,000 mm</small></span>
</div>
</div>
</aside>
<div class="panel hint">
<span class="mouse"></span>
<span>Drag to orbit · scroll to zoom · shift-drag to pan</span>
</div>
<div id="loading">Building terrace section…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
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;
renderer.domElement.setAttribute("aria-label", "Interactive Three.js cutaway of an Andean planting terrace");
renderer.domElement.tabIndex = 0;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe8ddc9, 20, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 2.15, -0.8);
const desiredTarget = cameraTarget.clone();
let desiredTheta = 0.58;
let desiredPhi = 1.03;
let desiredZoom = 1;
let currentTheta = desiredTheta;
let currentPhi = desiredPhi;
let currentZoom = desiredZoom;
const sceneRadius = 18;
let seed = 731984;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
function makeTexture(base, fleckColors, count = 450, size = 128) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = size;
const ctx = canvas.getContext("2d");
ctx.fillStyle = base;
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < count; i++) {
const color = fleckColors[Math.floor(random() * fleckColors.length)];
ctx.globalAlpha = range(0.035, 0.16);
ctx.fillStyle = color;
const r = range(0.4, 2.7);
ctx.beginPath();
ctx.arc(random() * size, random() * size, r, 0, Math.PI * 2);
ctx.fill();
}
ctx.globalAlpha = 1;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const stoneTexture = makeTexture(
"#eee3ce",
["#7f725d", "#b7a68a", "#d4c5a8", "#685d4d"],
650
);
stoneTexture.repeat.set(2, 2);
const soilTexture = makeTexture(
"#60432f",
["#261d18", "#9a7050", "#bd8b5b", "#3f2b21"],
700
);
soilTexture.repeat.set(3, 2);
const subsoilTexture = makeTexture(
"#77523a",
["#4b3428", "#a77851", "#b89064", "#674431"],
650
);
subsoilTexture.repeat.set(3, 2);
const gravelTexture = makeTexture(
"#92816d",
["#5f584d", "#b8ac98", "#d0c2a8", "#7a6e60"],
950
);
gravelTexture.repeat.set(3, 2);
const sandTexture = makeTexture(
"#c9a870",
["#e2c993", "#a78352", "#f0d8a7", "#b58e5c"],
850
);
sandTexture.repeat.set(3, 2);
const baseTexture = makeTexture(
"#a77955",
["#74513b", "#c39468", "#8c6244", "#d0a67c"],
550
);
baseTexture.repeat.set(3, 2);
const earthTexture = makeTexture(
"#d9bd91",
["#9e7955", "#e8cfa3", "#b58d62", "#7f6046"],
950
);
earthTexture.repeat.set(7, 5);
const materials = {
topsoil: new THREE.MeshStandardMaterial({
map: soilTexture, color: 0xffffff, roughness: 0.98
}),
subsoil: new THREE.MeshStandardMaterial({
map: subsoilTexture, color: 0xffffff, roughness: 1
}),
gravel: new THREE.MeshStandardMaterial({
map: gravelTexture, color: 0xffffff, roughness: 0.93
}),
sand: new THREE.MeshStandardMaterial({
map: sandTexture, color: 0xffffff, roughness: 0.96
}),
base: new THREE.MeshStandardMaterial({
map: baseTexture, color: 0xffffff, roughness: 1
})
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xf2dfb9,
transparent: true,
opacity: 0.46
});
function addLayer(bottom, top, material) {
const height = top - bottom;
const geometry = new THREE.BoxGeometry(8, height, 2.84);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, bottom + height / 2, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const edges = new THREE.LineSegments(new THREE.EdgesGeometry(geometry, 20), edgeMaterial);
edges.position.copy(mesh.position);
scene.add(edges);
return mesh;
}
// Level terrace section: compacted base, drainage, filter, subsoil, topsoil.
addLayer(0.08, 1.08, materials.base);
addLayer(1.08, 1.46, materials.gravel);
addLayer(1.46, 1.66, materials.sand);
addLayer(1.66, 2.26, materials.subsoil);
addLayer(2.26, 2.45, materials.topsoil);
// Retaining wall backing and individually laid masonry stones.
const mortarMaterial = new THREE.MeshStandardMaterial({
color: 0x675e50,
roughness: 1
});
const wallBacking = new THREE.Mesh(
new THREE.BoxGeometry(6.68, 2.28, 0.38),
mortarMaterial
);
wallBacking.position.set(-0.73, 1.22, 1.34);
wallBacking.castShadow = true;
wallBacking.receiveShadow = true;
scene.add(wallBacking);
const stoneMaterials = [
0x95856d, 0x897a64, 0xa09279, 0x7f715d, 0x9b8d75
].map(color => new THREE.MeshStandardMaterial({
color,
map: stoneTexture,
roughness: 0.94,
flatShading: true
}));
const unitStone = new THREE.BoxGeometry(1, 1, 1);
const wallEnd = 2.55;
function addStone(x, y, z, sx, sy, sz, materialIndex) {
const stone = new THREE.Mesh(unitStone, stoneMaterials[materialIndex]);
stone.position.set(x, y, z);
stone.scale.set(sx, sy, sz);
stone.rotation.z = range(-0.024, 0.024);
stone.rotation.y = range(-0.012, 0.012);
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
}
for (let row = 0; row < 6; row++) {
const y = 0.285 + row * 0.345;
let x = -4.02;
let first = true;
while (x < wallEnd - 0.08) {
let width = first ? range(0.83, 1.08) : range(0.58, 0.93);
width = Math.min(width, wallEnd - x);
if (width < 0.2) break;
addStone(
x + width / 2,
y + range(-0.012, 0.012),
1.52,
width * 0.94,
range(0.292, 0.324),
range(0.255, 0.31),
Math.floor(random() * stoneMaterials.length)
);
x += width + range(0.025, 0.05);
first = false;
}
}
// Irregular capstones stop at the exposed cutaway corner.
let capX = -4.13;
while (capX < 2.58) {
const width = Math.min(range(0.67, 0.96), 2.66 - capX);
if (width < 0.16) break;
addStone(
capX + width / 2,
2.38 + range(-0.008, 0.012),
1.52,
width * 0.96,
0.16,
0.40,
Math.floor(random() * stoneMaterials.length)
);
capX += width + 0.035;
}
// Left cheek wall.
const leftBacking = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 2.28, 2.9),
mortarMaterial
);
leftBacking.position.set(-3.97, 1.22, 0);
leftBacking.castShadow = true;
leftBacking.receiveShadow = true;
scene.add(leftBacking);
for (let row = 0; row < 6; row++) {
const y = 0.285 + row * 0.345;
let z = -1.42;
while (z < 1.39) {
const length = Math.min(range(0.48, 0.77), 1.48 - z);
if (length < 0.18) break;
addStone(
-3.95,
y,
z + length / 2,
0.29,
0.30,
length * 0.94,
Math.floor(random() * stoneMaterials.length)
);
z += length + 0.035;
}
}
// Gold section-cut outline around the open front/right corner.
const cutGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(2.57, 0.08, 1.455),
new THREE.Vector3(2.57, 2.47, 1.455),
new THREE.Vector3(4.015, 2.47, 1.455),
new THREE.Vector3(4.015, 2.47, -1.425),
new THREE.Vector3(4.015, 0.08, -1.425),
new THREE.Vector3(4.015, 0.08, 1.455)
]);
const cutLine = new THREE.Line(
cutGeometry,
new THREE.LineBasicMaterial({ color: 0xf1bd65, transparent: true, opacity: 0.95 })
);
scene.add(cutLine);
// Exposed aggregate in the gravel course.
const aggregateGeometry = new THREE.IcosahedronGeometry(1, 0);
const aggregateMaterial = new THREE.MeshStandardMaterial({
color: 0xb7aa92,
roughness: 0.95,
flatShading: true
});
const aggregate = new THREE.InstancedMesh(aggregateGeometry, aggregateMaterial, 42);
const dummy = new THREE.Object3D();
const aggregateColor = new THREE.Color();
for (let i = 0; i < 42; i++) {
const size = range(0.035, 0.077);
if (i < 24) {
dummy.position.set(4.012, range(1.105, 1.445), range(-1.28, 1.31));
} else {
dummy.position.set(range(2.62, 3.96), range(1.105, 1.445), 1.447);
}
dummy.scale.set(size, size * range(0.65, 1), size * range(0.7, 1.15));
dummy.rotation.set(random() * 3, random() * 3, random() * 3);
dummy.updateMatrix();
aggregate.setMatrixAt(i, dummy.matrix);
aggregateColor.setHSL(range(0.09, 0.13), range(0.08, 0.18), range(0.52, 0.72));
aggregate.setColorAt(i, aggregateColor);
}
aggregate.castShadow = true;
aggregate.receiveShadow = true;
scene.add(aggregate);
// A small clay drainage outlet visible in the opened wall section.
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0x9d5937,
roughness: 0.87
});
const pipe = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.25, 16),
pipeMaterial
);
pipe.rotation.x = Math.PI / 2;
pipe.position.set(3.31, 1.27, 1.34);
pipe.castShadow = true;
scene.add(pipe);
const pipeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.032, 7, 18),
pipeMaterial
);
pipeRing.position.set(3.31, 1.27, 1.475);
scene.add(pipeRing);
const pipeHole = new THREE.Mesh(
new THREE.CircleGeometry(0.108, 18),
new THREE.MeshBasicMaterial({ color: 0x241b16 })
);
pipeHole.position.set(3.31, 1.27, 1.479);
scene.add(pipeHole);
// Raised, level cultivation strips.
const bedMaterial = new THREE.MeshStandardMaterial({
map: soilTexture,
color: 0xc3a486,
roughness: 1
});
[-0.48, 0.54].forEach(z => {
const bed = new THREE.Mesh(new THREE.BoxGeometry(6.48, 0.11, 0.57), bedMaterial);
bed.position.set(-0.77, 2.50, z);
bed.castShadow = true;
bed.receiveShadow = true;
scene.add(bed);
});
// Stylized highland crop rows, instanced for a light scene.
const plantRows = [-0.48, 0.54];
const plantXs = [];
plantRows.forEach(z => {
for (let x = -3.55; x <= 2.27; x += 0.45) {
plantXs.push([x, z]);
}
});
const leafGeometry = new THREE.SphereGeometry(1, 8, 6);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.86,
flatShading: true
});
const leaves = new THREE.InstancedMesh(leafGeometry, leafMaterial, plantXs.length * 5);
const leafPalette = [0x47743d, 0x5f873f, 0x789a45, 0x3d693a, 0x8ca64d];
const leafColor = new THREE.Color();
const quaternion = new THREE.Quaternion();
const euler = new THREE.Euler();
const radial = new THREE.Vector3();
let leafIndex = 0;
plantXs.forEach(([x, z]) => {
const baseY = 2.55;
const plantScale = range(0.82, 1.12);
for (let leaf = 0; leaf < 5; leaf++) {
const angle = (leaf / 5) * Math.PI * 2 + range(-0.25, 0.25);
const tilt = leaf === 0 ? range(0.02, 0.13) : range(0.55, 0.98);
const height = range(0.34, 0.48) * plantScale;
radial.set(Math.cos(angle), 0, Math.sin(angle));
dummy.position.set(
x + radial.x * Math.sin(tilt) * 0.12,
baseY + (leaf === 0 ? height * 0.47 : height * 0.34),
z + radial.z * Math.sin(tilt) * 0.12
);
euler.set(tilt, angle, range(-0.08, 0.08), "YXZ");
quaternion.setFromEuler(euler);
dummy.quaternion.copy(quaternion);
dummy.scale.set(
range(0.085, 0.125),
height * 0.48,
range(0.055, 0.085)
);
dummy.updateMatrix();
leaves.setMatrixAt(leafIndex, dummy.matrix);
leafColor.setHex(leafPalette[Math.floor(random() * leafPalette.length)]);
leaves.setColorAt(leafIndex, leafColor);
leafIndex++;
}
});
leaves.castShadow = true;
leaves.receiveShadow = true;
scene.add(leaves);
// Small yellow crop flowers.
const flowers = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.055, 7, 5),
new THREE.MeshStandardMaterial({ color: 0xe2b64e, roughness: 0.85 }),
10
);
for (let i = 0; i < 10; i++) {
const p = plantXs[Math.floor(random() * plantXs.length)];
dummy.position.set(p[0] + range(-0.08, 0.08), 2.98 + range(0, 0.09), p[1]);
dummy.rotation.set(random(), random(), random());
dummy.scale.setScalar(range(0.8, 1.25));
dummy.updateMatrix();
flowers.setMatrixAt(i, dummy.matrix);
}
flowers.castShadow = true;
scene.add(flowers);
// Steep Andean hillside behind the terrace.
function terrainY(x, z) {
const rise = Math.max(0, -1.45 - z);
return 2.43
+ rise * 0.59
+ Math.sin(x * 0.53) * 0.095 * Math.min(1, rise)
+ Math.cos(z * 1.15 + x * 0.18) * 0.045 * Math.min(1, rise);
}
const slopeGeometry = new THREE.PlaneGeometry(22, 10, 44, 28);
slopeGeometry.rotateX(-Math.PI / 2);
slopeGeometry.translate(0, 0, -6.45);
const slopePositions = slopeGeometry.attributes.position;
const slopeColors = new Float32Array(slopePositions.count * 3);
const colorA = new THREE.Color(0xb28e66);
const colorB = new THREE.Color(0xd2b17e);
const tempColor = new THREE.Color();
for (let i = 0; i < slopePositions.count; i++) {
const x = slopePositions.getX(i);
const z = slopePositions.getZ(i);
slopePositions.setY(i, terrainY(x, z));
const blend = THREE.MathUtils.clamp((z + 11.45) / 10 * 0.7 + random() * 0.15, 0, 1);
tempColor.copy(colorA).lerp(colorB, blend);
tempColor.offsetHSL(0, 0, range(-0.035, 0.035));
slopeColors[i * 3] = tempColor.r;
slopeColors[i * 3 + 1] = tempColor.g;
slopeColors[i * 3 + 2] = tempColor.b;
}
slopeGeometry.setAttribute("color", new THREE.BufferAttribute(slopeColors, 3));
slopeGeometry.computeVertexNormals();
const slopeMaterial = new THREE.MeshStandardMaterial({
map: earthTexture,
color: 0xffffff,
vertexColors: true,
roughness: 1,
flatShading: true
});
const slope = new THREE.Mesh(slopeGeometry, slopeMaterial);
slope.receiveShadow = true;
slope.castShadow = true;
scene.add(slope);
const hillsideFront = new THREE.Mesh(
new THREE.BoxGeometry(22, 2.7, 0.24),
new THREE.MeshStandardMaterial({ map: baseTexture, color: 0xb99772, roughness: 1 })
);
hillsideFront.position.set(0, 1.08, -1.46);
hillsideFront.receiveShadow = true;
scene.add(hillsideFront);
function addHillsideSide(x) {
const vertices = [];
const segments = 32;
for (let i = 0; i < segments; i++) {
const z1 = -1.45 - (i / segments) * 10;
const z2 = -1.45 - ((i + 1) / segments) * 10;
const y1 = terrainY(x, z1);
const y2 = terrainY(x, z2);
const bottom = -0.24;
vertices.push(
x, bottom, z1,
x, y1, z1,
x, y2, z2,
x, bottom, z1,
x, y2, z2,
x, bottom, z2
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.computeVertexNormals();
const side = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
map: baseTexture,
color: 0xba9872,
roughness: 1,
side: THREE.DoubleSide
})
);
side.castShadow = true;
side.receiveShadow = true;
scene.add(side);
}
addHillsideSide(-11);
addHillsideSide(11);
// Fine topographic lines emphasize the steep grade.
const contourMaterial = new THREE.LineBasicMaterial({
color: 0xd5b47f,
transparent: true,
opacity: 0.54
});
[-2.0, -3.2, -4.5, -6.0, -7.7, -9.4].forEach(z => {
const points = [];
for (let i = 0; i <= 42; i++) {
const x = -10.8 + (i / 42) * 21.6;
points.push(new THREE.Vector3(x, terrainY(x, z) + 0.035, z));
}
scene.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints(points), contourMaterial));
});
// Scattered stones on the hillside.
const hillsideStoneGeometry = new THREE.IcosahedronGeometry(1, 0);
const hillsideStoneMaterial = new THREE.MeshStandardMaterial({
color: 0x9c8b71,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 28; i++) {
const x = range(-10.4, 10.4);
const z = range(-10.6, -2.0);
const size = range(0.08, 0.25);
const rock = new THREE.Mesh(hillsideStoneGeometry, hillsideStoneMaterial);
rock.position.set(x, terrainY(x, z) + size * 0.35, z);
rock.scale.set(size * range(0.7, 1.3), size * range(0.45, 0.8), size);
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// Grounded foreground.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({ color: 0xcbb795, roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.25;
ground.receiveShadow = true;
scene.add(ground);
// Lighting.
scene.add(new THREE.HemisphereLight(0xfff4dc, 0x705541, 2.25));
const sun = new THREE.DirectionalLight(0xffedc8, 3.4);
sun.position.set(7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7c9c7, 0.85);
fill.position.set(-9, 6, -5);
scene.add(fill);
const ambient = new THREE.AmbientLight(0xfff4df, 0.22);
scene.add(ambient);
// Custom orthographic orbit controls.
const canvas = renderer.domElement;
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = 0.012 / currentZoom;
desiredTarget.addScaledVector(right, -dx * panScale);
desiredTarget.addScaledVector(up, dy * panScale);
desiredTarget.x = THREE.MathUtils.clamp(desiredTarget.x, -7, 7);
desiredTarget.y = THREE.MathUtils.clamp(desiredTarget.y, 0.5, 6);
desiredTarget.z = THREE.MathUtils.clamp(desiredTarget.z, -5, 3);
} else {
desiredTheta -= dx * 0.005;
desiredPhi = THREE.MathUtils.clamp(desiredPhi - dy * 0.0042, 0.38, 1.43);
}
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
desiredZoom = THREE.MathUtils.clamp(
desiredZoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.45
);
}, { passive: false });
canvas.addEventListener("keydown", event => {
const step = 0.08;
if (event.key === "ArrowLeft") desiredTheta += step;
if (event.key === "ArrowRight") desiredTheta -= step;
if (event.key === "ArrowUp") desiredPhi = THREE.MathUtils.clamp(desiredPhi - step, 0.38, 1.43);
if (event.key === "ArrowDown") desiredPhi = THREE.MathUtils.clamp(desiredPhi + step, 0.38, 1.43);
if (event.key === "+" || event.key === "=") desiredZoom = Math.min(2.45, desiredZoom * 1.08);
if (event.key === "-") desiredZoom = Math.max(0.68, desiredZoom / 1.08);
});
function resetCamera() {
desiredTheta = 0.58;
desiredPhi = 1.03;
desiredZoom = 1;
desiredTarget.set(0, 2.15, -0.8);
}
function focusSection() {
desiredTheta = 0.88;
desiredPhi = 1.00;
desiredZoom = window.innerWidth < 760 ? 1.36 : 1.62;
desiredTarget.set(2.35, 1.70, 0.12);
}
document.querySelector("#reset-view").addEventListener("click", resetCamera);
document.querySelector("#focus-section").addEventListener("click", focusSection);
document.querySelector("#toggle-labels").addEventListener("click", () => {
document.body.classList.toggle("labels-off");
});
// World-space annotations.
const annotationData = {
wall: {
point: new THREE.Vector3(-1.18, 1.31, 1.72),
offset: new THREE.Vector2(-150, -38),
pin: document.querySelector("#pin-wall"),
path: document.querySelector("#leader-wall"),
dot: document.querySelector("#dot-wall")
},
surface: {
point: new THREE.Vector3(-2.65, 2.56, 0.18),
offset: new THREE.Vector2(-95, -88),
pin: document.querySelector("#pin-surface"),
path: document.querySelector("#leader-surface"),
dot: document.querySelector("#dot-surface")
},
drainage: {
point: new THREE.Vector3(3.31, 1.27, 1.49),
offset: new THREE.Vector2(145, -2),
pin: document.querySelector("#pin-drainage"),
path: document.querySelector("#leader-drainage"),
dot: document.querySelector("#dot-drainage")
}
};
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
const factor = THREE.MathUtils.clamp(width / 1100, 0.6, 1);
Object.values(annotationData).forEach(data => {
const projected = data.point.clone().project(camera);
const sx = (projected.x * 0.5 + 0.5) * width;
const sy = (-projected.y * 0.5 + 0.5) * height;
const visible = projected.z > -1 && projected.z < 1;
let tx = sx + data.offset.x * factor;
let ty = sy + data.offset.y * factor;
const marginX = width < 760 ? 78 : 105;
const marginY = width < 760 ? 52 : 70;
tx = THREE.MathUtils.clamp(tx, marginX, width - marginX);
ty = THREE.MathUtils.clamp(ty, marginY, height - marginY);
data.pin.style.transform = `translate3d(${tx}px, ${ty}px, 0) translate(-50%, -50%)`;
data.path.setAttribute("d", `M ${sx.toFixed(1)} ${sy.toFixed(1)} L ${tx.toFixed(1)} ${ty.toFixed(1)}`);
data.dot.setAttribute("cx", sx.toFixed(1));
data.dot.setAttribute("cy", sy.toFixed(1));
data.pin.style.visibility = visible ? "visible" : "hidden";
data.path.style.visibility = visible ? "visible" : "hidden";
data.dot.style.visibility = visible ? "visible" : "hidden";
});
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 1 ? 13.2 / aspect : 10.6;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const svg = document.querySelector("#leaders");
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-dt * 8.5);
currentTheta += (desiredTheta - currentTheta) * damping;
currentPhi += (desiredPhi - currentPhi) * damping;
currentZoom += (desiredZoom - currentZoom) * damping;
cameraTarget.lerp(desiredTarget, damping);
camera.position.set(
cameraTarget.x + sceneRadius * Math.sin(currentPhi) * Math.sin(currentTheta),
cameraTarget.y + sceneRadius * Math.cos(currentPhi),
cameraTarget.z + sceneRadius * Math.sin(currentPhi) * Math.cos(currentTheta)
);
camera.zoom = currentZoom;
camera.updateProjectionMatrix();
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
updateAnnotations();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => document.body.classList.add("ready"));
</script>
</body>
</html>
```