Prompt specification
Build or customize the Three.js 3D scene "Hillside road drainage diorama" 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 road drainage diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hillside-road-drainage-diorama-x1159
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing landslide slopes. Compose a cut slope, retaining wall, roadside ditch, and downhill vegetation; trace water routes clearly and identify stabilization elements without asserting design adequacy. Voxel style.
Working Three.js Starter (hillside-road-drainage-diorama-x1159):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Landslide Slope — Voxel Terrain and Drainage Study</title>
<style>
:root {
--ink: #23343a;
--muted: #62747a;
--panel: rgba(250, 252, 249, 0.92);
--border: rgba(35, 52, 58, 0.16);
--accent: #168b91;
--water: #00bde8;
--earth: #b88348;
--concrete: #879397;
--vegetation: #4d8c55;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e6;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport,
#labels {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 12px 40px rgba(35, 52, 58, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#overview {
top: 16px;
left: 16px;
width: min(330px, calc(100vw - 32px));
padding: 18px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 32px);
line-height: 1.03;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 13px;
}
.chip {
padding: 5px 8px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(255, 255, 255, 0.62);
color: #52666b;
font-size: 10px;
font-weight: 700;
}
#systems {
top: 16px;
right: 16px;
width: 288px;
padding: 16px;
max-height: calc(100vh - 32px);
overflow: auto;
}
.panel h2 {
margin: 0 0 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.section + .section {
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--border);
}
.layer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 31px;
color: #3f555b;
font-size: 12px;
cursor: pointer;
}
.layer span {
display: flex;
align-items: center;
gap: 9px;
}
.layer input {
width: 15px;
height: 15px;
margin: 0;
accent-color: var(--accent);
cursor: pointer;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--swatch, #777);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.feature-list {
display: grid;
gap: 8px;
margin: 0;
padding: 0;
list-style: none;
}
.feature-list li {
display: grid;
grid-template-columns: 27px 1fr;
gap: 9px;
align-items: start;
color: #52666b;
font-size: 11px;
line-height: 1.35;
}
.feature-number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border-radius: 7px;
background: #e4ece9;
color: var(--accent);
font-size: 9px;
font-weight: 900;
}
.feature-list strong {
display: block;
margin-bottom: 1px;
color: var(--ink);
font-size: 11px;
}
.buttons {
display: grid;
grid-template-columns: 1fr auto auto;
gap: 6px;
margin-top: 15px;
}
button {
min-height: 34px;
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
button:hover {
border-color: rgba(22, 139, 145, 0.42);
background: #fff;
}
button:focus-visible,
input:focus-visible {
outline: 2px solid rgba(22, 139, 145, 0.6);
outline-offset: 2px;
}
#legend {
left: 16px;
bottom: 16px;
width: min(530px, calc(100vw - 32px));
padding: 13px 15px;
}
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 13px;
align-items: center;
color: #53666b;
font-size: 10px;
font-weight: 750;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.flow {
margin-top: 9px;
padding-top: 9px;
border-top: 1px solid var(--border);
color: #147f91;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.035em;
line-height: 1.4;
}
#disclaimer {
right: 16px;
bottom: 16px;
width: 330px;
padding: 12px 14px;
color: #65777c;
font-size: 10px;
line-height: 1.45;
}
#disclaimer strong {
color: #43585e;
}
.scene-label {
position: absolute;
min-width: 125px;
max-width: 210px;
padding: 7px 9px 7px 10px;
transform: translate(-50%, -100%);
border: 1px solid rgba(35, 52, 58, 0.18);
border-left: 3px solid var(--label-accent, #168b91);
border-radius: 7px;
background: rgba(252, 253, 250, 0.94);
box-shadow: 0 5px 18px rgba(35, 52, 58, 0.12);
color: var(--ink);
white-space: nowrap;
transition: opacity 120ms linear;
}
.scene-label::after {
position: absolute;
left: 50%;
bottom: -11px;
width: 1px;
height: 10px;
background: rgba(35, 52, 58, 0.42);
content: "";
}
.scene-label .label-title {
display: flex;
align-items: center;
gap: 6px;
font-size: 10px;
font-weight: 850;
}
.scene-label .label-index {
color: var(--label-accent, #168b91);
font-size: 8px;
font-weight: 950;
letter-spacing: 0.06em;
}
.scene-label .label-sub {
margin-top: 2px;
color: #6c7d81;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.015em;
}
@media (max-width: 820px) {
#overview {
top: 10px;
left: 10px;
width: min(300px, calc(100vw - 20px));
padding: 14px;
}
#systems {
top: auto;
right: 10px;
bottom: 10px;
width: 270px;
max-height: 52vh;
padding: 13px;
}
#legend {
display: none;
}
#disclaimer {
right: 10px;
bottom: auto;
top: 10px;
width: 245px;
}
}
@media (max-width: 560px) {
#overview {
width: calc(100vw - 20px);
}
#overview .subtitle,
#overview .chips,
#disclaimer {
display: none;
}
#systems {
width: calc(100vw - 20px);
max-height: 43vh;
}
.feature-list {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels"></div>
<section class="panel" id="overview">
<div class="eyebrow">Voxel terrain / drainage study</div>
<h1>Landslide slope</h1>
<p class="subtitle">
Cut slope, roadway, retaining wall, roadside ditch, toe outlet, and
downhill vegetation shown as a conceptual block model.
</p>
<div class="chips">
<span class="chip">Schematic</span>
<span class="chip">Not to scale</span>
<span class="chip">Water route highlighted</span>
</div>
</section>
<section class="panel" id="systems">
<div class="section">
<h2>Visible systems</h2>
<label class="layer">
<span><i class="swatch" style="--swatch:#b88348"></i>Cut slope</span>
<input type="checkbox" data-layer="cut" checked>
</label>
<label class="layer">
<span><i class="swatch" style="--swatch:#879397"></i>Retaining wall</span>
<input type="checkbox" data-layer="wall" checked>
</label>
<label class="layer">
<span><i class="swatch" style="--swatch:#a5afb1"></i>Roadside ditch</span>
<input type="checkbox" data-layer="ditch" checked>
</label>
<label class="layer">
<span><i class="swatch" style="--swatch:#4d8c55"></i>Vegetation</span>
<input type="checkbox" data-layer="vegetation" checked>
</label>
<label class="layer">
<span><i class="swatch" style="--swatch:#00bde8"></i>Schematic water route</span>
<input type="checkbox" data-layer="water" checked>
</label>
<label class="layer">
<span><i class="swatch" style="--swatch:#d59746"></i>Annotations</span>
<input type="checkbox" data-layer="labels" checked>
</label>
</div>
<div class="section">
<h2>Stabilization elements identified</h2>
<ol class="feature-list">
<li>
<span class="feature-number">01</span>
<span><strong>Stepped cut benches</strong>Form the terraced cut slope.</span>
</li>
<li>
<span class="feature-number">02</span>
<span><strong>Stacked retaining wall</strong>Shown along the downhill road edge.</span>
</li>
<li>
<span class="feature-number">03</span>
<span><strong>Lined roadside ditch</strong>Collects water along the road.</span>
</li>
<li>
<span class="feature-number">04</span>
<span><strong>Culvert and toe outlet</strong>Carry the schematic drainage alignment.</span>
</li>
<li>
<span class="feature-number">05</span>
<span><strong>Vegetated cover</strong>Occupies the downhill slope.</span>
</li>
</ol>
</div>
<div class="buttons">
<button id="reset-view" type="button">Reset view</button>
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
</div>
</section>
<section class="panel" id="legend">
<div class="legend-row">
<span class="legend-item"><i class="swatch" style="--swatch:#b88348"></i>Soil / cut</span>
<span class="legend-item"><i class="swatch" style="--swatch:#879397"></i>Concrete</span>
<span class="legend-item"><i class="swatch" style="--swatch:#4d8c55"></i>Vegetation</span>
<span class="legend-item"><i class="swatch" style="--swatch:#00bde8"></i>Water route</span>
</div>
<div class="flow">
RUNOFF → BENCHES → DITCH → CATCH BASIN → CULVERT → TOE OUTLET → DOWNHILL SWALE
</div>
</section>
<section class="panel" id="disclaimer">
<strong>Conceptual visualization only.</strong>
Stabilization elements are identified for discussion. The model does not
represent a geotechnical design or establish structural capacity,
factor of safety, drainage performance, or design adequacy.
</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 orthographic camera
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e6);
scene.fog = new THREE.Fog(0xdce8e6, 55, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-25, 25, 16, -16, 0.1, 180);
const cameraTarget = new THREE.Vector3(0, 6.4, 2.0);
const orbit = {
theta: 0.68,
phi: 0.86,
radius: 43
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 1 ? 36 / aspect : 32;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Lighting and materials
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf7fff9, 0x8c755a, 2.15));
const sun = new THREE.DirectionalLight(0xfff5dc, 3.1);
sun.position.set(-22, 34, 21);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -38;
sun.shadow.camera.right = 38;
sun.shadow.camera.top = 38;
sun.shadow.camera.bottom = -38;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00035;
scene.add(sun);
const cube = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
}
const materials = {
earth: standardMaterial(0xa96f38),
earthDark: standardMaterial(0x87552f),
earthLight: standardMaterial(0xc08b51),
soilCap: standardMaterial(0x9f7842),
grassCap: standardMaterial(0x6f9850),
grassCap2: standardMaterial(0x5f884b),
road: standardMaterial(0x3f4a4c),
roadEdge: standardMaterial(0x657173),
lineWhite: standardMaterial(0xe7e9df),
lineYellow: standardMaterial(0xe5bd54),
concrete: standardMaterial(0x8b9699),
concreteDark: standardMaterial(0x707c80),
concreteLight: standardMaterial(0xa0aaac),
trunk: standardMaterial(0x6d5034),
foliage: standardMaterial(0x3f7548),
foliageLight: standardMaterial(0x57955a),
foliageDark: standardMaterial(0x315f3c),
swale: standardMaterial(0x566b45),
floor: standardMaterial(0xd6e1de),
black: standardMaterial(0x263338)
};
const groups = {
base: new THREE.Group(),
cut: new THREE.Group(),
wall: new THREE.Group(),
ditch: new THREE.Group(),
vegetation: new THREE.Group(),
water: new THREE.Group()
};
Object.values(groups).forEach(group => scene.add(group));
function box(parent, width, height, depth, x, y, z, material, cast = true) {
const mesh = new THREE.Mesh(cube, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function instanceBoxes(parent, entries, material) {
const mesh = new THREE.InstancedMesh(cube, material, entries.length);
const dummy = new THREE.Object3D();
entries.forEach((entry, index) => {
dummy.position.set(entry.x, entry.y, entry.z);
dummy.scale.set(entry.w, entry.h, entry.d);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (entry.color !== undefined) {
mesh.setColorAt(index, new THREE.Color(entry.color));
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 481927;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function randomBetween(min, max) {
return min + (max - min) * random();
}
// -------------------------------------------------------------------------
// Base platform
// -------------------------------------------------------------------------
box(groups.base, 92, 0.3, 92, 0, -2.45, 3, materials.floor, false);
box(groups.base, 32.5, 1.2, 36.5, 0, -1.8, 2.2, materials.earthDark);
box(groups.base, 32.5, 0.16, 36.5, 0, -1.25, 2.2, materials.earth);
// Thin strata bands make the cut block read as a voxel section.
box(groups.base, 32.65, 0.13, 36.65, 0, -1.62, 2.2, materials.earthLight, false);
box(groups.base, 32.65, 0.10, 36.65, 0, -2.18, 2.2, materials.earthDark, false);
// -------------------------------------------------------------------------
// Stepped cut slope and benches
// -------------------------------------------------------------------------
const cutBands = [
{ z: -10.5, depth: 3.0, top: 15.0 },
{ z: -7.5, depth: 3.0, top: 12.5 },
{ z: -4.5, depth: 3.0, top: 10.0 },
{ z: -2.25, depth: 1.5, top: 8.25 }
];
const earthVariants = [
materials.earth,
materials.earthLight,
materials.earthDark
];
for (let col = 0; col < 20; col++) {
const x = -14.25 + col * 1.5;
for (let bandIndex = 0; bandIndex < cutBands.length; bandIndex++) {
const band = cutBands[bandIndex];
const baseY = -1.15;
const height = band.top - baseY;
const color = earthVariants[(col + bandIndex) % earthVariants.length];
box(
groups.cut,
1.48,
height,
band.depth - 0.035,
x,
baseY + height / 2,
band.z,
color
);
const capMaterial = bandIndex < 2
? (random() > 0.45 ? materials.grassCap : materials.soilCap)
: materials.soilCap;
box(
groups.cut,
1.46,
0.10,
band.depth - 0.04,
x,
band.top + 0.04,
band.z,
capMaterial,
false
);
}
}
// Scattered exposed blocks along the cut faces.
for (let i = 0; i < 28; i++) {
const x = randomBetween(-14, 14);
const band = cutBands[Math.floor(randomBetween(0, 3))];
const size = randomBetween(0.22, 0.52);
box(
groups.cut,
size,
size,
0.12,
x,
band.top - randomBetween(0.1, 0.75),
band.z + band.depth / 2 + 0.03,
random() > 0.5 ? materials.earthLight : materials.earthDark
);
}
// -------------------------------------------------------------------------
// Road slab, lane markings, and shoulder
// -------------------------------------------------------------------------
box(groups.base, 30.5, 0.8, 3.65, 0, 7.6, 0.475, materials.road);
box(groups.base, 30.5, 0.12, 0.22, 0, 8.02, -1.08, materials.lineWhite, false);
box(groups.base, 30.5, 0.12, 0.22, 0, 8.02, 1.98, materials.lineWhite, false);
for (let x = -14; x <= 14; x += 2.5) {
box(groups.base, 1.35, 0.055, 0.14, x, 8.03, 0.43, materials.lineYellow, false);
}
// -------------------------------------------------------------------------
// Retaining wall: stacked concrete voxels
// -------------------------------------------------------------------------
const wallBlocks = [];
const wallColors = [0x879194, 0x929da0, 0x7c888b, 0x9ba4a5];
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 30; col++) {
wallBlocks.push({
x: -14.5 + col,
y: 3.025 + row * 0.65,
z: 2.64,
w: 0.965,
h: 0.59,
d: 0.90,
color: wallColors[(row * 3 + col) % wallColors.length]
});
}
}
instanceBoxes(groups.wall, wallBlocks, standardMaterial(0xffffff));
const wallCaps = [];
for (let col = 0; col < 30; col++) {
wallCaps.push({
x: -14.5 + col,
y: 7.94,
z: 2.64,
w: 0.985,
h: 0.28,
d: 1.03,
color: col % 3 === 0 ? 0xa3abad : 0x929c9e
});
}
instanceBoxes(groups.wall, wallCaps, standardMaterial(0xffffff));
// -------------------------------------------------------------------------
// Roadside ditch: concrete U-channel
// -------------------------------------------------------------------------
const ditchBlocks = [];
for (let col = 0; col < 20; col++) {
const x = -13.4 + col * 1.2;
ditchBlocks.push({
x,
y: 8.34,
z: -2.25,
w: 1.15,
h: 0.14,
d: 1.08,
color: 0x9aa4a5
});
ditchBlocks.push({
x,
y: 8.51,
z: -2.88,
w: 1.15,
h: 0.42,
d: 0.18,
color: 0x858f92
});
ditchBlocks.push({
x,
y: 8.51,
z: -1.62,
w: 1.15,
h: 0.42,
d: 0.18,
color: 0x909a9c
});
}
instanceBoxes(groups.ditch, ditchBlocks, standardMaterial(0xffffff));
// Catch basin / grated inlet at the downstream end of the ditch.
box(groups.ditch, 1.55, 0.10, 1.45, 8.8, 8.43, -2.25, materials.black, false);
box(groups.ditch, 1.75, 0.35, 0.18, 8.8, 8.55, -3.02, materials.concreteLight);
box(groups.ditch, 1.75, 0.35, 0.18, 8.8, 8.55, -1.48, materials.concreteLight);
box(groups.ditch, 0.18, 0.35, 1.45, 7.92, 8.55, -2.25, materials.concreteLight);
box(groups.ditch, 0.18, 0.35, 1.45, 9.68, 8.55, -2.25, materials.concreteLight);
for (let i = -2; i <= 2; i++) {
box(
groups.ditch,
0.12,
0.10,
1.25,
8.8 + i * 0.25,
8.55,
-2.25,
materials.concreteDark,
false
);
}
// -------------------------------------------------------------------------
// Downhill terraced ground with a schematic swale corridor
// -------------------------------------------------------------------------
const downhillBands = [
{ z: 4.5, depth: 3.2, top: 2.7 },
{ z: 8.1, depth: 4.0, top: 1.7 },
{ z: 12.2, depth: 4.2, top: 0.7 },
{ z: 16.0, depth: 3.6, top: 0.0 }
];
function isSwaleCell(x) {
return Math.abs(x - 8.8) < 0.84;
}
for (let col = 0; col < 20; col++) {
const x = -14.25 + col * 1.5;
for (let bandIndex = 0; bandIndex < downhillBands.length; bandIndex++) {
const band = downhillBands[bandIndex];
let top = band.top;
if (isSwaleCell(x)) {
top -= bandIndex === 0 ? 0.9 : bandIndex === 1 ? 0.9 : 0.55;
if (top < -0.1) top = -0.1;
}
const baseY = -1.15;
const height = top - baseY;
box(
groups.base,
1.48,
height,
band.depth - 0.035,
x,
baseY + height / 2,
band.z,
bandIndex < 2 ? materials.earthDark : materials.earth
);
const capMaterial = isSwaleCell(x)
? materials.swale
: (random() > 0.44 ? materials.grassCap : materials.grassCap2);
box(
groups.base,
1.46,
0.10,
band.depth - 0.04,
x,
top + 0.04,
band.z,
capMaterial,
false
);
}
}
function downhillTop(z, x = -4) {
let top;
if (z < 6.1) top = 2.7;
else if (z < 10.1) top = 1.7;
else if (z < 14.3) top = 0.7;
else top = 0.0;
if (isSwaleCell(x)) {
if (z < 6.1) top -= 0.9;
else if (z < 10.1) top -= 0.9;
else if (z < 14.3) top -= 0.55;
else top -= 0.1;
}
return top;
}
// Toe outlet opening and stepped erosion-control blocks.
box(groups.ditch, 0.82, 0.82, 0.12, 8.8, 3.28, 3.12, materials.black, false);
box(groups.ditch, 0.60, 0.60, 0.10, 8.8, 3.28, 3.20, materials.roadEdge, false);
const chuteBlocks = [
{ x: 8.8, y: 2.25, z: 3.80, w: 1.10, h: 0.40, d: 1.00 },
{ x: 8.8, y: 1.65, z: 4.60, w: 1.25, h: 0.38, d: 1.10 },
{ x: 8.8, y: 1.05, z: 5.55, w: 1.35, h: 0.34, d: 1.15 },
{ x: 8.8, y: 0.55, z: 6.55, w: 1.45, h: 0.30, d: 1.15 }
];
chuteBlocks.forEach(block => {
box(
groups.ditch,
block.w,
block.h,
block.d,
block.x,
block.y,
block.z,
materials.concreteDark
);
});
// -------------------------------------------------------------------------
// Downhill vegetation: cubic trees and block shrubs
// -------------------------------------------------------------------------
function addTree(x, z, scale = 1) {
const ground = downhillTop(z, x);
const trunkHeight = 1.25 * scale;
box(
groups.vegetation,
0.34 * scale,
trunkHeight,
0.34 * scale,
x,
ground + trunkHeight / 2 + 0.08,
z,
materials.trunk
);
const canopyY = ground + trunkHeight + 0.35 * scale;
box(
groups.vegetation,
1.18 * scale,
1.05 * scale,
1.18 * scale,
x,
canopyY,
z,
materials.foliage
);
box(
groups.vegetation,
0.72 * scale,
0.65 * scale,
0.72 * scale,
x - 0.48 * scale,
canopyY + 0.25 * scale,
z + 0.08 * scale,
materials.foliageLight
);
box(
groups.vegetation,
0.65 * scale,
0.60 * scale,
0.65 * scale,
x + 0.46 * scale,
canopyY + 0.12 * scale,
z - 0.12 * scale,
materials.foliageDark
);
if (random() > 0.35) {
box(
groups.vegetation,
0.58 * scale,
0.55 * scale,
0.58 * scale,
x + 0.05 * scale,
canopyY + 0.67 * scale,
z - 0.08 * scale,
materials.foliage
);
}
}
const treePositions = [
[-12.4, 4.6], [-10.7, 7.2], [-8.7, 4.1], [-6.4, 5.5],
[-3.2, 8.5], [-0.8, 4.2], [2.5, 7.8], [5.4, 4.4],
[-12.0, 11.1], [-9.2, 13.7], [-6.3, 10.8], [-4.1, 15.0],
[-1.5, 12.1], [1.8, 14.0], [4.4, 11.3], [6.4, 14.7],
[-13.0, 16.0], [-10.6, 16.5], [-7.8, 15.6], [-2.5, 16.3],
[2.5, 16.6], [5.8, 16.3]
];
treePositions.forEach(([x, z]) => {
addTree(x, z, randomBetween(0.78, 1.12));
});
for (let i = 0; i < 58; i++) {
const x = randomBetween(-14.2, 14.2);
const z = randomBetween(3.5, 16.5);
if (Math.abs(x - 8.8) < 1.25) continue;
const ground = downhillTop(z, x);
const size = randomBetween(0.24, 0.64);
box(
groups.vegetation,
size,
size * randomBetween(0.65, 1.1),
size,
x,
ground + size / 2 + 0.08,
z,
random() > 0.5 ? materials.foliageLight : materials.foliage
);
}
// -------------------------------------------------------------------------
// Water route: schematic square-section alignment and moving voxel droplets
// -------------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-10.0, 15.20, -10.70),
new THREE.Vector3(-10.0, 15.20, -8.80),
new THREE.Vector3(-10.0, 12.72, -8.80),
new THREE.Vector3(-10.0, 12.62, -5.80),
new THREE.Vector3(-10.0, 10.22, -5.80),
new THREE.Vector3(-10.0, 10.12, -2.25),
new THREE.Vector3(-10.0, 8.48, -2.25),
new THREE.Vector3(8.80, 8.48, -2.25),
new THREE.Vector3(8.80, 3.28, -2.25),
new THREE.Vector3(8.80, 3.28, 3.20),
new THREE.Vector3(8.80, 2.25, 3.80),
new THREE.Vector3(8.80, 1.65, 4.60),
new THREE.Vector3(8.80, 1.05, 5.55),
new THREE.Vector3(8.80, 0.55, 6.55),
new THREE.Vector3(8.80, 0.30, 10.00),
new THREE.Vector3(8.80, 0.18, 13.50),
new THREE.Vector3(8.80, 0.10, 16.70)
];
const routeCoreMaterial = new THREE.MeshBasicMaterial({
color: 0x00bde8,
transparent: true,
opacity: 0.96,
depthTest: false,
depthWrite: false
});
const routeGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x3bd9ff,
transparent: true,
opacity: 0.16,
depthTest: false,
depthWrite: false
});
function beamBetween(parent, a, b, width, material, renderOrder = 40) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const mesh = new THREE.Mesh(cube, material);
mesh.position.copy(midpoint);
mesh.scale.set(width, width, length);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.clone().normalize()
);
mesh.renderOrder = renderOrder;
parent.add(mesh);
return mesh;
}
for (let i = 0; i < routePoints.length - 1; i++) {
const a = routePoints[i];
const b = routePoints[i + 1];
beamBetween(groups.water, a, b, 0.38, routeGlowMaterial, 39);
beamBetween(groups.water, a, b, 0.14, routeCoreMaterial, 40);
}
// Physical blue strip visible in the lined ditch.
box(
groups.ditch,
23.55,
0.055,
0.28,
-2.45,
8.46,
-2.25,
new THREE.MeshBasicMaterial({ color: 0x00bde8 }),
false
);
// Arrow chevrons make the direction of runoff explicit.
function addArrow(position, direction, planeNormal = new THREE.Vector3(0, 1, 0)) {
const d = direction.clone().normalize();
let side = new THREE.Vector3().crossVectors(d, planeNormal);
if (side.lengthSq() < 0.001) {
side = new THREE.Vector3().crossVectors(d, new THREE.Vector3(1, 0, 0));
}
side.normalize();
const tip = position.clone();
const back = tip.clone().addScaledVector(d, -0.62);
const wingA = back.clone().addScaledVector(side, 0.32);
const wingB = back.clone().addScaledVector(side, -0.32);
beamBetween(groups.water, tip, wingA, 0.18, routeCoreMaterial, 42);
beamBetween(groups.water, tip, wingB, 0.18, routeCoreMaterial, 42);
}
addArrow(new THREE.Vector3(-10, 15.38, -9.45), new THREE.Vector3(0, 0, 1));
addArrow(new THREE.Vector3(-6.6, 8.66, -2.25), new THREE.Vector3(1, 0, 0));
addArrow(new THREE.Vector3(4.6, 8.66, -2.25), new THREE.Vector3(1, 0, 0));
addArrow(new THREE.Vector3(8.8, 4.35, -2.25), new THREE.Vector3(0, -1, 0), new THREE.Vector3(0, 0, 1));
addArrow(new THREE.Vector3(8.8, 0.75, 8.8), new THREE.Vector3(0, 0, 1));
addArrow(new THREE.Vector3(8.8, 0.38, 14.4), new THREE.Vector3(0, 0, 1));
const routeLengths = [];
let totalRouteLength = 0;
for (let i = 0; i < routePoints.length - 1; i++) {
const length = routePoints[i].distanceTo(routePoints[i + 1]);
routeLengths.push(length);
totalRouteLength += length;
}
function sampleRoute(distance) {
let remaining = Math.max(0, Math.min(totalRouteLength, distance));
for (let i = 0; i < routeLengths.length; i++) {
if (remaining <= routeLengths[i] || i === routeLengths.length - 1) {
const t = remaining / routeLengths[i];
return new THREE.Vector3().lerpVectors(
routePoints[i],
routePoints[i + 1],
Math.min(1, t)
);
}
remaining -= routeLengths[i];
}
return routePoints[0].clone();
}
const dropletMaterial = new THREE.MeshBasicMaterial({
color: 0xd8fbff,
transparent: true,
opacity: 0.96,
depthTest: false,
depthWrite: false
});
const droplets = [];
for (let i = 0; i < 15; i++) {
const mesh = new THREE.Mesh(cube, dropletMaterial);
const size = i % 4 === 0 ? 0.26 : 0.18;
mesh.scale.set(size, size, size);
mesh.renderOrder = 45;
groups.water.add(mesh);
droplets.push(mesh);
}
// -------------------------------------------------------------------------
// Projected HTML annotations
// -------------------------------------------------------------------------
const labelSpecs = [
{
anchor: new THREE.Vector3(-10, 15.45, -10.5),
number: "01",
title: "Stepped cut slope",
sub: "Cut benches · stabilization",
color: "#c28a43",
dx: -8,
dy: -8
},
{
anchor: new THREE.Vector3(-7.4, 8.9, -2.25),
number: "02",
title: "Roadside ditch",
sub: "Lined drainage element",
color: "#7f8b8e",
dx: 0,
dy: -4
},
{
anchor: new THREE.Vector3(0.4, 6.9, 3.15),
number: "03",
title: "Retaining wall",
sub: "Stacked concrete blocks",
color: "#879397",
dx: 8,
dy: -4
},
{
anchor: new THREE.Vector3(8.8, 7.9, 0.2),
number: "04",
title: "Under-road culvert",
sub: "Schematic drainage alignment",
color: "#00a9d6",
dx: 48,
dy: -18
},
{
anchor: new THREE.Vector3(8.8, 2.6, 4.0),
number: "05",
title: "Toe outlet chute",
sub: "Outlet and erosion blocks",
color: "#00a9d6",
dx: 45,
dy: 14
},
{
anchor: new THREE.Vector3(-4.8, 4.25, 9.8),
number: "06",
title: "Vegetated cover",
sub: "Downhill slope planting",
color: "#4d8c55",
dx: -10,
dy: 16
}
];
const labels = labelSpecs.map(spec => {
const element = document.createElement("div");
element.className = "scene-label";
element.style.setProperty("--label-accent", spec.color);
element.innerHTML = `
<div class="label-title">
<span class="label-index">${spec.number}</span>
<span>${spec.title}</span>
</div>
<div class="label-sub">${spec.sub}</div>
`;
labelLayer.appendChild(element);
return { ...spec, element };
});
let labelsVisible = true;
function updateLabels() {
if (!labelsVisible) return;
const rect = renderer.domElement.getBoundingClientRect();
labels.forEach(label => {
const projected = label.anchor.clone().project(camera);
if (projected.z < -1 || projected.z > 1) {
label.element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * rect.width + label.dx;
const y = (-projected.y * 0.5 + 0.5) * rect.height + label.dy;
const visible =
x > -120 &&
x < rect.width + 120 &&
y > -80 &&
y < rect.height + 80;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// -------------------------------------------------------------------------
// Layer controls
// -------------------------------------------------------------------------
document.querySelectorAll("[data-layer]").forEach(input => {
input.addEventListener("change", () => {
const layer = input.dataset.layer;
if (layer === "labels") {
labelsVisible = input.checked;
labelLayer.style.display = labelsVisible ? "block" : "none";
} else if (groups[layer]) {
groups[layer].visible = input.checked;
}
});
});
// -------------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
event.preventDefault();
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.34, 1.42);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
25,
62
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
function resetView() {
orbit.theta = 0.68;
orbit.phi = 0.86;
orbit.radius = 43;
cameraTarget.set(0, 6.4, 2.0);
updateCamera();
}
document.getElementById("reset-view").addEventListener("click", resetView);
document.getElementById("zoom-in").addEventListener("click", () => {
orbit.radius = Math.max(25, orbit.radius - 3);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
orbit.radius = Math.min(62, orbit.radius + 3);
updateCamera();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (groups.water.visible) {
droplets.forEach((droplet, index) => {
const phase = (elapsed * 0.034 + index / droplets.length) % 1;
droplet.position.copy(sampleRoute(phase * totalRouteLength));
});
routeGlowMaterial.opacity = 0.12 + Math.sin(elapsed * 2.2) * 0.035;
}
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```