Prompt specification
Build or customize the Three.js 3D scene "Hillside garden with three linked terraces" 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: Hillside garden with three linked terraces
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hillside-garden-with-three-linked-terraces-x2215
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing retaining walls and hillside terraces. Create three garden terraces connected by steps and a separate drainage channel. Keep each planted surface level and align retaining walls with the changes in ground elevation. Voxel style.
Working Three.js Starter (hillside-garden-with-three-linked-terraces-x2215):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Hillside Garden Terraces</title>
<style>
:root {
color-scheme: light;
--ink: #17352d;
--panel: rgba(248, 250, 244, 0.88);
--border: rgba(23, 53, 45, 0.14);
--water: #38a9d6;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbdad2;
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;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 14px 38px rgba(24, 55, 44, 0.13);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-card {
top: 22px;
left: 22px;
max-width: 360px;
padding: 18px 20px 16px;
border-radius: 16px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
color: #668176;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(22px, 3vw, 31px);
font-weight: 780;
line-height: 1.02;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: #5b7168;
font-size: 12px;
line-height: 1.5;
}
.legend {
right: 22px;
bottom: 22px;
width: 218px;
padding: 14px;
border-radius: 14px;
pointer-events: none;
}
.legend-title {
margin: 0 0 10px;
color: #71847c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr auto;
gap: 9px;
align-items: center;
margin-top: 8px;
color: #365248;
font-size: 11px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.level-number {
color: #83938c;
font-variant-numeric: tabular-nums;
font-size: 10px;
}
.controls {
left: 22px;
bottom: 22px;
padding: 10px 13px;
border-radius: 11px;
color: #567066;
font-size: 10px;
pointer-events: none;
}
.controls strong {
color: #29493e;
font-weight: 750;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #365248;
background: #cbdad2;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.3s ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
.title-card {
top: 12px;
left: 12px;
right: 12px;
max-width: none;
padding: 13px 15px;
}
.subtitle {
max-width: 300px;
}
.legend {
right: 12px;
bottom: 52px;
width: 190px;
padding: 11px;
}
.controls {
left: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="loading" class="loading">Building hillside terraces…</div>
<section class="panel title-card">
<p class="eyebrow">Voxel landscape study</p>
<h1>Hillside Garden Terraces</h1>
<p class="subtitle">
Three level planting beds, masonry retaining walls, broad garden steps,
and a separate blue-lined drainage channel.
</p>
</section>
<section class="panel legend">
<p class="legend-title">Elevation key</p>
<div class="legend-row">
<span class="swatch" style="background:#7fa653"></span>
<span>Low garden terrace</span>
<span class="level-number">+0.9</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#668f47"></span>
<span>Middle garden terrace</span>
<span class="level-number">+2.5</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#52783c"></span>
<span>Upper garden terrace</span>
<span class="level-number">+4.1</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#38a9d6"></span>
<span>Separate drainage</span>
<span class="level-number">↘</span>
</div>
</section>
<section class="panel controls">
<strong>Drag</strong> orbit ·
<strong>Wheel</strong> zoom ·
<strong>Shift-drag</strong> pan
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbdad2);
scene.fog = new THREE.Fog(0xcbdad2, 32, 58);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const orbit = {
azimuth: 0.73,
polar: 0.86,
zoom: 1,
radius: 23,
target: new THREE.Vector3(0, 1.8, -0.25)
};
const hemisphere = new THREE.HemisphereLight(0xf4fff8, 0x59684e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cf, 2.8);
sun.position.set(-9, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dcff, 0.65);
fill.position.set(10, 7, -9);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
baseSoil: material(0x80664d),
baseGrass: material(0x78945a),
terraceSoil: material(0x725843),
grassLow: material(0x86ad60),
grassMiddle: material(0x719b50),
grassHigh: material(0x5d8241),
bedSoil: material(0x49372a),
wood: material(0x936641),
woodDark: material(0x67452f),
mortar: material(0x777970),
trunk: material(0x6f4b32),
leaf1: material(0x3f743c),
leaf2: material(0x568a43),
leaf3: material(0x75a34e),
leafLight: material(0x93b957),
redFlower: material(0xd85b52),
yellowFlower: material(0xe9c85b),
blueFlower: material(0x6b8ed8),
whiteFlower: material(0xf4ead2),
metal: material(0x57645f, { metalness: 0.55, roughness: 0.52 }),
dark: material(0x273b38),
water: material(0x38a9d6, {
emissive: 0x0b6489,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.88,
roughness: 0.28,
metalness: 0.05,
depthWrite: false
}),
waterBright: material(0x75d6ef, {
emissive: 0x167da5,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.92,
roughness: 0.2,
depthWrite: false
})
};
const stoneMaterials = [
material(0xa7a99b),
material(0x969b90),
material(0xb5b3a3),
material(0x8d958a),
material(0xc0b9a5)
];
const stoneCap = material(0xc3c1af);
let randomSeed = 82417;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6D2B79F5) | 0;
let value = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
}
function pick(list) {
return list[Math.floor(random() * list.length)];
}
function addBox(
width,
height,
depth,
x,
y,
z,
mat,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addGroundPlane() {
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
material(0xa8bca2)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.04;
ground.receiveShadow = true;
scene.add(ground);
// The stepped garden sits on a compact voxel diorama base.
addBox(
14.8, 0.8, 13.6,
0, -0.62, 0,
materials.baseSoil
);
addBox(
14.65, 0.14, 13.45,
0, -0.15, 0,
materials.baseGrass
);
}
// -------------------------------------------------------------------------
// Level data. Every planted surface uses its listed y value exactly.
// -------------------------------------------------------------------------
const terraces = [
{
name: "Low",
level: 0.9,
centerZ: 3.0,
depth: 2.8,
grass: materials.grassLow
},
{
name: "Middle",
level: 2.5,
centerZ: -0.2,
depth: 3.6,
grass: materials.grassMiddle
},
{
name: "Upper",
level: 4.1,
centerZ: -3.4,
depth: 2.8,
grass: materials.grassHigh
}
];
function buildTerraceBody(terrace) {
const bottom = -0.08;
const bodyTop = terrace.level - 0.12;
const bodyHeight = bodyTop - bottom;
addBox(
10.4,
bodyHeight,
terrace.depth,
0,
bottom + bodyHeight / 2,
terrace.centerZ,
materials.terraceSoil
);
// The visible planted surface is perfectly horizontal.
addBox(
10.0,
0.12,
terrace.depth - 0.04,
0,
terrace.level - 0.06,
terrace.centerZ,
terrace.gGrass || terrace.grass
);
}
// -------------------------------------------------------------------------
// Retaining walls
// -------------------------------------------------------------------------
function buildFrontWall(z, baseY, topY, gapCenter = null, gapWidth = 0) {
const leftEdge = -5.05;
const rightEdge = 5.05;
const height = topY - baseY;
const rows = Math.max(1, Math.ceil(height / 0.4));
const rowHeight = height / rows;
const gapLeft = gapCenter === null
? rightEdge
: gapCenter - gapWidth / 2;
const gapRight = gapCenter === null
? leftEdge
: gapCenter + gapWidth / 2;
// Mortar backing, split around the stair opening.
if (gapCenter === null) {
addBox(
rightEdge - leftEdge,
height,
0.18,
(leftEdge + rightEdge) / 2,
baseY + height / 2,
z - 0.08,
materials.mortar
);
} else {
if (gapLeft > leftEdge) {
addBox(
gapLeft - leftEdge,
height,
0.18,
(leftEdge + gapLeft) / 2,
baseY + height / 2,
z - 0.08,
materials.mortar
);
}
if (gapRight < rightEdge) {
addBox(
rightEdge - gapRight,
height,
0.18,
(gapRight + rightEdge) / 2,
baseY + height / 2,
z - 0.08,
materials.mortar
);
}
}
const blockWidth = 0.82;
const blockGap = 0.045;
for (let row = 0; row < rows; row++) {
const y = baseY + row * rowHeight + rowHeight / 2;
const stagger = row % 2 === 0 ? 0 : blockWidth / 2;
let x = leftEdge + stagger;
while (x < rightEdge) {
const width = Math.min(blockWidth, rightEdge - x);
const overlapsGap =
gapCenter !== null &&
x < gapRight + 0.08 &&
x + width > gapLeft - 0.08;
if (!overlapsGap && width > 0.12) {
const isCap = row === rows - 1;
const depth = isCap ? 0.42 : 0.36;
addBox(
width - 0.025,
rowHeight - 0.025,
depth,
x + width / 2,
y,
z + (isCap ? 0.015 : 0),
isCap ? stoneCap : pick(stoneMaterials)
);
}
x += blockWidth + blockGap;
}
}
}
function buildSideWall(x, zStart, zEnd, baseY, topY) {
const height = topY - baseY;
const rows = Math.max(1, Math.ceil(height / 0.42));
const rowHeight = height / rows;
const blockLength = 0.86;
for (let row = 0; row < rows; row++) {
const y = baseY + row * rowHeight + rowHeight / 2;
const stagger = row % 2 === 0 ? 0 : blockLength / 2;
let z = zStart + stagger;
while (z < zEnd) {
const length = Math.min(blockLength, zEnd - z);
if (length > 0.12) {
addBox(
0.3,
rowHeight - 0.025,
length - 0.025,
x,
y,
z + length / 2,
row === rows - 1 ? stoneCap : pick(stoneMaterials)
);
}
z += blockLength + 0.04;
}
}
}
function buildRetainingWalls() {
// The outer stepped side walls retain each terrace's soil mass.
buildSideWall(-5.2, 1.6, 4.4, -0.08, 0.9);
buildSideWall(5.2, 1.6, 4.4, -0.08, 0.9);
buildSideWall(-5.2, -2.0, 1.6, -0.08, 2.5);
buildSideWall(5.2, -2.0, 1.6, -0.08, 2.5);
buildSideWall(-5.2, -4.8, -2.0, -0.08, 4.1);
buildSideWall(5.2, -4.8, -2.0, -0.08, 4.1);
// Front walls terminate exactly at the next lower elevation.
buildFrontWall(4.43, -0.08, 0.9);
buildFrontWall(1.63, 0.9, 2.5, -2.35, 2.18);
buildFrontWall(-1.97, 2.5, 4.1, 2.35, 2.18);
}
// -------------------------------------------------------------------------
// Broad voxel stairs connecting the terraces
// -------------------------------------------------------------------------
function buildStairs({
x,
startZ,
endZ,
startY,
endY,
baseY,
width = 1.9,
steps = 8
}) {
const run = (endZ - startZ) / steps;
const rise = (startY - endY) / steps;
for (let i = 0; i < steps; i++) {
const z = startZ + (i + 0.5) * run;
const top = startY - (i + 1) * rise;
const mainTop = top - 0.08;
const mainHeight = Math.max(0.08, mainTop - baseY);
addBox(
width,
mainHeight,
run + 0.018,
x,
baseY + mainHeight / 2,
z,
stoneMaterials[2]
);
addBox(
width + 0.035,
0.08,
run + 0.025,
x,
top - 0.04,
z,
i % 2 === 0 ? stoneCap : materials.mortar
);
}
// Low chunky cheek walls emphasize the stair cut through the wall.
for (const side of [-1, 1]) {
for (let i = 0; i < steps; i += 2) {
const z = startZ + (i + 1) * run;
const top = startY - (i + 1) * rise + 0.12;
const height = top - baseY;
addBox(
0.18,
height,
run * 2 + 0.05,
x + side * (width / 2 + 0.12),
baseY + height / 2,
z,
pick(stoneMaterials)
);
}
}
}
// -------------------------------------------------------------------------
// Planting
// -------------------------------------------------------------------------
function makeBed(x, z, width, depth, level) {
const soilTop = level + 0.16;
addBox(
width,
0.16,
depth,
x,
level + 0.08,
z,
materials.bedSoil
);
addBox(
width + 0.12,
0.22,
0.1,
x,
level + 0.11,
z - depth / 2,
materials.wood
);
addBox(
width + 0.12,
0.22,
0.1,
x,
level + 0.11,
z + depth / 2,
materials.wood
);
addBox(
0.1,
0.22,
depth,
x - width / 2,
level + 0.11,
z,
materials.woodDark
);
addBox(
0.1,
0.22,
depth,
x + width / 2,
level + 0.11,
z,
materials.woodDark
);
return soilTop;
}
function makeVegetable(x, y, z, scale = 1) {
addBox(
0.07 * scale,
0.25 * scale,
0.07 * scale,
x,
y + 0.125 * scale,
z,
materials.leaf1
);
addBox(
0.25 * scale,
0.14 * scale,
0.22 * scale,
x - 0.07 * scale,
y + 0.23 * scale,
z,
materials.leaf2
);
addBox(
0.22 * scale,
0.15 * scale,
0.25 * scale,
x + 0.08 * scale,
y + 0.24 * scale,
z + 0.03 * scale,
materials.leaf3
);
addBox(
0.13 * scale,
0.12 * scale,
0.13 * scale,
x,
y + 0.34 * scale,
z,
materials.leafLight
);
}
function makeHerb(x, y, z) {
addBox(
0.055,
0.31,
0.055,
x,
y + 0.155,
z,
materials.leaf1
);
addBox(
0.24,
0.12,
0.12,
x - 0.07,
y + 0.25,
z,
materials.leaf3
);
addBox(
0.12,
0.11,
0.24,
x + 0.07,
y + 0.28,
z,
materials.leaf2
);
}
function makeFlower(x, y, z, colorMaterial, height = 0.48) {
addBox(
0.045,
height,
0.045,
x,
y + height / 2,
z,
materials.leaf1
);
addBox(
0.17,
0.09,
0.09,
x - 0.06,
y + height * 0.52,
z,
materials.leaf3
);
addBox(
0.19,
0.17,
0.19,
x,
y + height,
z,
colorMaterial
);
addBox(
0.09,
0.08,
0.09,
x,
y + height + 0.115,
z,
materials.yellowFlower
);
}
function populateVegetableBed(x, z, width, depth, y) {
const columns = Math.max(2, Math.floor(width / 0.46));
const rows = Math.max(1, Math.floor(depth / 0.42));
for (let c = 0; c < columns; c++) {
for (let r = 0; r < rows; r++) {
const px = x - width * 0.34 + (c / Math.max(1, columns - 1)) * width * 0.68;
const pz = z - depth * 0.25 + (r / Math.max(1, rows - 1)) * depth * 0.5;
makeVegetable(px, y, pz, 0.8 + random() * 0.22);
}
}
}
function populateHerbBed(x, z, width, depth, y) {
const columns = Math.max(3, Math.floor(width / 0.38));
const rows = Math.max(1, Math.floor(depth / 0.38));
for (let c = 0; c < columns; c++) {
for (let r = 0; r < rows; r++) {
const px = x - width * 0.35 + (c / Math.max(1, columns - 1)) * width * 0.7;
const pz = z - depth * 0.28 + (r / Math.max(1, rows - 1)) * depth * 0.56;
makeHerb(px, y, pz);
}
}
}
function populateFlowerBed(x, z, width, depth, y) {
const columns = Math.max(3, Math.floor(width / 0.4));
const rows = Math.max(1, Math.floor(depth / 0.36));
const flowerMaterials = [
materials.redFlower,
materials.yellowFlower,
materials.blueFlower,
materials.whiteFlower
];
for (let c = 0; c < columns; c++) {
for (let r = 0; r < rows; r++) {
const px = x - width * 0.36 + (c / Math.max(1, columns - 1)) * width * 0.72;
const pz = z - depth * 0.27 + (r / Math.max(1, rows - 1)) * depth * 0.54;
makeFlower(
px,
y,
pz,
pick(flowerMaterials),
0.37 + random() * 0.18
);
}
}
}
function makeTree(x, z, level, scale = 1) {
addBox(
0.3 * scale,
1.35 * scale,
0.3 * scale,
x,
level + 0.675 * scale,
z,
materials.trunk
);
addBox(
1.15 * scale,
0.72 * scale,
1.05 * scale,
x,
level + 1.38 * scale,
z,
materials.leaf1
);
addBox(
0.86 * scale,
0.72 * scale,
0.9 * scale,
x - 0.17 * scale,
level + 1.82 * scale,
z + 0.04 * scale,
materials.leaf2
);
addBox(
0.82 * scale,
0.74 * scale,
0.78 * scale,
x + 0.23 * scale,
level + 1.83 * scale,
z - 0.08 * scale,
materials.leaf3
);
addBox(
0.68 * scale,
0.55 * scale,
0.65 * scale,
x + 0.02 * scale,
level + 2.31 * scale,
z + 0.02 * scale,
materials.leafLight
);
addBox(
0.48 * scale,
0.42 * scale,
0.52 * scale,
x - 0.45 * scale,
level + 1.55 * scale,
z + 0.08 * scale,
materials.leaf3
);
}
function makeBush(x, z, level, scale = 1) {
addBox(
0.5 * scale,
0.38 * scale,
0.5 * scale,
x,
level + 0.19 * scale,
z,
materials.leaf2
);
addBox(
0.4 * scale,
0.42 * scale,
0.4 * scale,
x - 0.25 * scale,
level + 0.32 * scale,
z + 0.08 * scale,
materials.leaf3
);
addBox(
0.4 * scale,
0.4 * scale,
0.4 * scale,
x + 0.23 * scale,
level + 0.31 * scale,
z - 0.04 * scale,
materials.leaf1
);
}
function makeMarker(x, z, level, color) {
addBox(
0.09,
0.65,
0.09,
x,
level + 0.325,
z,
materials.woodDark
);
addBox(
0.42,
0.28,
0.09,
x + 0.17,
level + 0.57,
z,
material(color)
);
}
function buildPlanting() {
// Low terrace
let bedY = makeBed(0.2, 2.65, 2.0, 1.0, 0.9);
populateVegetableBed(0.2, 2.65, 2.0, 1.0, bedY);
bedY = makeBed(2.85, 2.65, 1.7, 1.0, 0.9);
populateVegetableBed(2.85, 2.65, 1.7, 1.0, bedY);
bedY = makeBed(0.35, 3.72, 2.0, 0.72, 0.9);
populateFlowerBed(0.35, 3.72, 2.0, 0.72, bedY);
makeBush(4.05, 3.6, 0.9, 0.9);
makeMarker(4.35, 2.45, 0.9, 0x9bc264);
// Middle terrace
bedY = makeBed(-3.65, -0.55, 1.8, 1.12, 2.5);
populateVegetableBed(-3.65, -0.55, 1.8, 1.12, bedY);
bedY = makeBed(-1.15, -0.55, 1.8, 1.12, 2.5);
populateHerbBed(-1.15, -0.55, 1.8, 1.12, bedY);
bedY = makeBed(1.12, -0.72, 1.42, 1.0, 2.5);
populateFlowerBed(1.12, -0.72, 1.42, 1.0, bedY);
makeBush(-4.25, 0.68, 2.5, 0.9);
makeMarker(-4.25, -1.28, 2.5, 0x71a951);
// Upper terrace
bedY = makeBed(-2.65, -3.48, 2.05, 1.08, 4.1);
populateVegetableBed(-2.65, -3.48, 2.05, 1.08, bedY);
bedY = makeBed(-0.05, -3.48, 2.05, 1.08, 4.1);
populateFlowerBed(-0.05, -3.48, 2.05, 1.08, bedY);
makeTree(3.72, -3.72, 4.1, 0.86);
makeTree(-4.05, -4.0, 4.1, 0.58);
makeBush(1.28, -4.16, 4.1, 0.82);
makeMarker(4.25, -2.55, 4.1, 0x557f40);
}
// -------------------------------------------------------------------------
// Separate drainage channel
// -------------------------------------------------------------------------
const channelSegments = [
{ start: -4.78, end: -2.02, bed: 4.1 },
{ start: -2.02, end: 1.58, bed: 2.5 },
{ start: 1.58, end: 4.43, bed: 0.9 }
];
const flowParticles = [];
const fallingParticles = [];
function buildChannelSegment(segment, segmentIndex) {
const x = 6.08;
const length = segment.end - segment.start;
const centerZ = (segment.start + segment.end) / 2;
const bottom = -0.08;
const supportHeight = segment.bed - bottom;
// Raised concrete support follows the side of the hill.
addBox(
1.16,
supportHeight,
length,
x,
bottom + supportHeight / 2,
centerZ,
stoneMaterials[1]
);
// Dark channel invert.
addBox(
0.76,
0.08,
length,
x,
segment.bed + 0.04,
centerZ,
materials.dark
);
// Two distinct concrete curbs.
addBox(
0.16,
0.27,
length,
x - 0.46,
segment.bed + 0.135,
centerZ,
stoneCap
);
addBox(
0.16,
0.27,
length,
x + 0.46,
segment.bed + 0.135,
centerZ,
stoneCap
);
// Thin blue water strip.
addBox(
0.48,
0.045,
length - 0.03,
x,
segment.bed + 0.102,
centerZ,
materials.water,
scene,
false
);
for (let i = 0; i < 3; i++) {
const droplet = addBox(
0.095,
0.075,
0.16,
x,
segment.bed + 0.15,
segment.start,
materials.waterBright,
scene,
false
);
flowParticles.push({
mesh: droplet,
start: segment.start + 0.12,
end: segment.end - 0.12,
y: segment.bed + 0.15,
offset: (i / 3 + segmentIndex * 0.07) % 1,
speed: 0.12 + segmentIndex * 0.014
});
}
}
function buildChannelDrop(z, upperBed, lowerBed) {
const x = 6.08;
const height = upperBed - lowerBed;
// Dark vertical chute behind the falling water.
addBox(
0.8,
height + 0.08,
0.18,
x,
(upperBed + lowerBed) / 2,
z - 0.13,
materials.dark
);
addBox(
0.36,
height,
0.1,
x,
(upperBed + lowerBed) / 2,
z + 0.01,
materials.waterBright,
scene,
false
);
for (const side of [-1, 1]) {
addBox(
0.13,
height + 0.12,
0.28,
x + side * 0.43,
(upperBed + lowerBed) / 2,
z - 0.04,
stoneCap
);
}
for (let i = 0; i < 4; i++) {
const drop = addBox(
0.11,
0.11,
0.11,
x,
upperBed,
z + 0.05,
materials.waterBright,
scene,
false
);
fallingParticles.push({
mesh: drop,
upper: upperBed,
lower: lowerBed,
z: z + 0.06,
offset: i / 4,
speed: 0.5 + i * 0.025
});
}
}
function buildDrainage() {
channelSegments.forEach(buildChannelSegment);
buildChannelDrop(-2.02, 4.1, 2.5);
buildChannelDrop(1.58, 2.5, 0.9);
// Inlet grate at the top of the channel.
for (let i = 0; i < 6; i++) {
addBox(
0.065,
0.085,
0.46,
5.71 + i * 0.148,
4.21,
-4.67,
materials.metal
);
}
// A small outlet basin at the lower end.
addBox(
1.48,
0.28,
1.05,
6.08,
0.48,
4.92,
stoneMaterials[2]
);
addBox(
0.9,
0.07,
0.66,
6.08,
0.655,
4.94,
materials.dark
);
addBox(
0.62,
0.035,
0.53,
6.08,
0.705,
4.94,
materials.water,
scene,
false
);
buildChannelDrop(4.46, 0.9, 0.7);
}
// -------------------------------------------------------------------------
// Small voxel landscaping details
// -------------------------------------------------------------------------
function buildLandscapeDetails() {
const rockMaterial = material(0x8d9186);
const rocks = [
[-6.55, -0.02, 3.7, 0.65],
[-6.7, 0.13, 3.95, 0.42],
[6.85, -0.02, 2.5, 0.54],
[7.0, 0.1, 2.72, 0.34],
[-6.4, -0.02, -3.8, 0.52],
[6.8, -0.02, -4.25, 0.45]
];
for (const [x, y, z, size] of rocks) {
addBox(
size,
size * 0.62,
size * 0.78,
x,
y + size * 0.31,
z,
rockMaterial
);
}
// A short blue marker post identifies the drainage route.
addBox(
0.1,
0.75,
0.1,
6.92,
0.375,
0.35,
materials.woodDark
);
addBox(
0.32,
0.26,
0.1,
6.85,
0.67,
0.35,
materials.waterBright
);
}
// -------------------------------------------------------------------------
// Assemble the scene
// -------------------------------------------------------------------------
addGroundPlane();
terraces.forEach(buildTerraceBody);
buildRetainingWalls();
buildStairs({
x: 2.35,
startZ: -1.97,
endZ: 1.58,
startY: 4.1,
endY: 2.5,
baseY: 2.5,
width: 1.9,
steps: 8
});
buildStairs({
x: -2.35,
startZ: 1.63,
endZ: 3.83,
startY: 2.5,
endY: 0.9,
baseY: 0.9,
width: 1.9,
steps: 8
});
buildPlanting();
buildDrainage();
buildLandscapeDetails();
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan and keyboard input
// -------------------------------------------------------------------------
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(11.8, 15.1 / aspect) / orbit.zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
const sinPolar = Math.sin(orbit.polar);
const cosPolar = Math.cos(orbit.polar);
camera.position.set(
orbit.target.x + orbit.radius * sinPolar * Math.sin(orbit.azimuth),
orbit.target.y + orbit.radius * cosPolar,
orbit.target.z + orbit.radius * sinPolar * Math.cos(orbit.azimuth)
);
camera.lookAt(orbit.target);
}
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
shift: false
};
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.shift = event.shiftKey;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (event.shiftKey || pointer.shift) {
const right = new THREE.Vector3(
Math.cos(orbit.azimuth),
0,
-Math.sin(orbit.azimuth)
);
const forward = new THREE.Vector3(
-Math.sin(orbit.azimuth),
0,
-Math.cos(orbit.azimuth)
);
const scale = 0.012 / orbit.zoom;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(forward, dy * scale);
orbit.target.x = THREE.MathUtils.clamp(
orbit.target.x,
-5,
5
);
orbit.target.z = THREE.MathUtils.clamp(
orbit.target.z,
-5,
5
);
} else {
orbit.azimuth -= dx * 0.006;
orbit.polar = THREE.MathUtils.clamp(
orbit.polar + dy * 0.005,
0.47,
1.28
);
}
updateCamera();
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(event.deltaY * 0.001),
0.65,
1.9
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.azimuth += 0.1;
break;
case "ArrowRight":
orbit.azimuth -= 0.1;
break;
case "ArrowUp":
orbit.polar = Math.max(0.47, orbit.polar - 0.07);
break;
case "ArrowDown":
orbit.polar = Math.min(1.28, orbit.polar + 0.07);
break;
case "+":
case "=":
orbit.zoom = Math.min(1.9, orbit.zoom * 1.1);
break;
case "-":
case "_":
orbit.zoom = Math.max(0.65, orbit.zoom / 1.1);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
// -------------------------------------------------------------------------
// Water animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animateWater(elapsedTime) {
materials.water.emissiveIntensity =
0.38 + Math.sin(elapsedTime * 2.2) * 0.08;
materials.waterBright.emissiveIntensity =
0.52 + Math.sin(elapsedTime * 3.1) * 0.12;
for (const particle of flowParticles) {
const t = (elapsedTime * particle.speed + particle.offset) % 1;
particle.mesh.position.z = THREE.MathUtils.lerp(
particle.start,
particle.end,
t
);
particle.mesh.position.y =
particle.y + Math.sin(t * Math.PI * 4) * 0.018;
}
for (const particle of fallingParticles) {
const t = (elapsedTime * particle.speed + particle.offset) % 1;
particle.mesh.position.y = THREE.MathUtils.lerp(
particle.upper - 0.08,
particle.lower + 0.1,
t
);
particle.mesh.scale.y = 0.75 + t * 0.8;
}
}
updateCamera();
document.getElementById("loading").classList.add("hidden");
renderer.setAnimationLoop(() => {
const elapsedTime = clock.getElapsedTime();
animateWater(elapsedTime);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```