Prompt specification
Build or customize the Three.js 3D scene "Footpath crossing a dry streambed" 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: Footpath crossing a dry streambed
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/footpath-crossing-a-dry-streambed-x1345
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a footpath and bridge across a dry streambed. Model a footpath through a shallow dry channel with a higher bridge nearby. Distinguish the direct ground route from the elevated alternative using colored route strips. Stylized solid forms.
Working Three.js Starter (footpath-crossing-a-dry-streambed-x1345):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dry Creek Crossing</title>
<style>
:root {
color-scheme: light;
--ink: #26322d;
--panel: rgba(249, 247, 239, 0.9);
--ground-route: #f0643a;
--bridge-route: #00a6a6;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe6e3;
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;
}
.panel {
position: fixed;
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 18px 20px;
border: 1px solid rgba(38, 50, 45, 0.12);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(38, 50, 45, 0.14);
backdrop-filter: blur(12px);
pointer-events: none;
user-select: none;
}
.eyebrow {
margin-bottom: 5px;
color: #68766f;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(23px, 3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 15px;
color: #5d6963;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: grid;
gap: 9px;
padding-top: 13px;
border-top: 1px solid rgba(38, 50, 45, 0.12);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #39463f;
font-size: 13px;
font-weight: 650;
}
.swatch {
width: 27px;
height: 8px;
border-radius: 99px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.09);
}
.swatch.ground {
background: var(--ground-route);
}
.swatch.bridge {
background: var(--bridge-route);
}
.hint {
position: fixed;
bottom: 18px;
left: 50%;
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(38, 50, 45, 0.1);
border-radius: 999px;
background: rgba(249, 247, 239, 0.83);
color: #59665f;
box-shadow: 0 8px 24px rgba(38, 50, 45, 0.1);
font-size: 12px;
white-space: nowrap;
pointer-events: none;
user-select: none;
}
.season {
position: fixed;
top: 22px;
right: 22px;
padding: 9px 12px;
border-radius: 999px;
background: rgba(249, 247, 239, 0.78);
color: #6a756f;
box-shadow: 0 8px 24px rgba(38, 50, 45, 0.08);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
user-select: none;
}
@media (max-width: 600px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
margin-bottom: 10px;
}
.season {
display: none;
}
.hint {
bottom: 10px;
max-width: calc(100vw - 20px);
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>
</head>
<body>
<div class="panel">
<div class="eyebrow">Dry Creek Crossing</div>
<h1>Two ways across</h1>
<p class="subtitle">
A shallow dry channel splits the trail. Take the direct ground route through
the streambed, or follow the elevated bridge alternative.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch ground"></span>
Direct ground route
</div>
<div class="legend-row">
<span class="swatch bridge"></span>
Elevated bridge route
</div>
</div>
</div>
<div class="season">Stylized trail map · Dry season</div>
<div class="hint">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
<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 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;
renderer.domElement.setAttribute("aria-label", "Interactive dry creek trail scene");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe6e3);
scene.fog = new THREE.Fog(0xdbe6e3, 62, 108);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const cameraTarget = new THREE.Vector3(0, -0.15, 3);
let cameraTheta = 0.43;
let cameraPhi = 0.84;
let cameraRadius = 59;
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraRadius,
cameraPhi,
cameraTheta
);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe7f7ff, 0x77654b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.2);
sun.position.set(-20, 36, 26);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -43;
sun.shadow.camera.right = 43;
sun.shadow.camera.top = 43;
sun.shadow.camera.bottom = -43;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9df, 0.75);
fill.position.set(24, 14, -28);
scene.add(fill);
// -------------------------------------------------------------------------
// Terrain and dry streambed
// -------------------------------------------------------------------------
const TERRAIN_WIDTH = 72;
const TERRAIN_DEPTH = 68;
const TERRAIN_SEGMENTS_X = 120;
const TERRAIN_SEGMENTS_Z = 112;
function smoothstep(value, min, max) {
return THREE.MathUtils.smoothstep(value, min, max);
}
function creekCenter(z) {
return Math.sin(z * 0.115) * 4.2 + Math.sin(z * 0.27) * 0.7;
}
function terrainHeight(x, z) {
const distanceFromCreek = Math.abs(x - creekCenter(z));
const channelFactor =
1 - smoothstep(distanceFromCreek, 1.45, 4.8);
const rolling =
0.2 * Math.sin(x * 0.13) * Math.cos(z * 0.11) +
0.09 * Math.sin((x + z) * 0.23);
const outerRise = 0.45 * smoothstep(Math.abs(x), 23, 36);
const bedVariation =
0.075 *
Math.sin(x * 1.7 + z * 0.6) *
Math.sin(z * 0.8) *
channelFactor;
return (
0.38 +
rolling +
outerRise -
1.62 * channelFactor +
bedVariation
);
}
const terrainPositions = [];
const terrainColors = [];
const terrainIndices = [];
const grassA = new THREE.Color(0x849968);
const grassB = new THREE.Color(0x9aa874);
const sand = new THREE.Color(0xc8a971);
const paleSand = new THREE.Color(0xd7bb80);
for (let iz = 0; iz <= TERRAIN_SEGMENTS_Z; iz++) {
const z =
-TERRAIN_DEPTH / 2 +
(TERRAIN_DEPTH * iz) / TERRAIN_SEGMENTS_Z;
for (let ix = 0; ix <= TERRAIN_SEGMENTS_X; ix++) {
const x =
-TERRAIN_WIDTH / 2 +
(TERRAIN_WIDTH * ix) / TERRAIN_SEGMENTS_X;
const y = terrainHeight(x, z);
terrainPositions.push(x, y, z);
const distance = Math.abs(x - creekCenter(z));
const channelFactor = 1 - smoothstep(distance, 1.4, 4.9);
const variation =
0.5 + 0.5 * Math.sin(x * 0.31 + z * 0.19);
const color = grassA.clone().lerp(grassB, variation);
const bedColor = sand.clone().lerp(paleSand, variation * 0.75);
color.lerp(bedColor, channelFactor * 0.94);
terrainColors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < TERRAIN_SEGMENTS_Z; iz++) {
for (let ix = 0; ix < TERRAIN_SEGMENTS_X; ix++) {
const a = iz * (TERRAIN_SEGMENTS_X + 1) + ix;
const b = a + 1;
const c = a + TERRAIN_SEGMENTS_X + 1;
const d = c + 1;
terrainIndices.push(a, c, b, b, c, d);
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.setIndex(terrainIndices);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0
})
);
terrain.receiveShadow = true;
scene.add(terrain);
// Solid earth-colored base beneath the terrain.
const base = new THREE.Mesh(
new THREE.BoxGeometry(TERRAIN_WIDTH, 1.2, TERRAIN_DEPTH),
new THREE.MeshStandardMaterial({
color: 0x735b42,
roughness: 1
})
);
base.position.y = -2.6;
base.receiveShadow = true;
scene.add(base);
// Terrain edge skirt, making the scene read as a solid diorama.
const skirtPositions = [];
const skirtIndices = [];
const perimeter = [];
const edgeSteps = 54;
for (let i = 0; i < edgeSteps; i++) {
perimeter.push([
-TERRAIN_WIDTH / 2 +
(TERRAIN_WIDTH * i) / edgeSteps,
-TERRAIN_DEPTH / 2
]);
}
for (let i = 0; i < edgeSteps; i++) {
perimeter.push([
TERRAIN_WIDTH / 2,
-TERRAIN_DEPTH / 2 +
(TERRAIN_DEPTH * i) / edgeSteps
]);
}
for (let i = 0; i < edgeSteps; i++) {
perimeter.push([
TERRAIN_WIDTH / 2 -
(TERRAIN_WIDTH * i) / edgeSteps,
TERRAIN_DEPTH / 2
]);
}
for (let i = 0; i < edgeSteps; i++) {
perimeter.push([
-TERRAIN_WIDTH / 2,
TERRAIN_DEPTH / 2 -
(TERRAIN_DEPTH * i) / edgeSteps
]);
}
perimeter.forEach(([x, z]) => {
skirtPositions.push(x, terrainHeight(x, z), z);
skirtPositions.push(x, -2.0, z);
});
for (let i = 0; i < perimeter.length; i++) {
const next = (i + 1) % perimeter.length;
const a = i * 2;
const b = next * 2;
skirtIndices.push(a, b, a + 1, b, b + 1, a + 1);
}
const skirtGeometry = new THREE.BufferGeometry();
skirtGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(skirtPositions, 3)
);
skirtGeometry.setIndex(skirtIndices);
skirtGeometry.computeVertexNormals();
const skirt = new THREE.Mesh(
skirtGeometry,
new THREE.MeshStandardMaterial({
color: 0x80664a,
roughness: 1,
side: THREE.DoubleSide
})
);
skirt.receiveShadow = true;
scene.add(skirt);
// -------------------------------------------------------------------------
// Route ribbon helper
// -------------------------------------------------------------------------
function offsetY(points, amount) {
return points.map(point =>
new THREE.Vector3(point.x, point.y + amount, point.z)
);
}
function makeRibbon(points, width, material) {
const vertices = [];
const indices = [];
for (let i = 0; i < points.length; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(points.length - 1, i + 1)];
const tangent = new THREE.Vector3().subVectors(next, previous);
tangent.y = 0;
if (tangent.lengthSq() < 0.000001) {
tangent.set(0, 0, 1);
}
tangent.normalize();
const side = new THREE.Vector3(tangent.z, 0, -tangent.x);
const left = points[i].clone().addScaledVector(side, -width / 2);
const right = points[i].clone().addScaledVector(side, width / 2);
vertices.push(left.x, left.y, left.z);
vertices.push(right.x, right.y, right.z);
}
for (let i = 0; i < points.length - 1; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, c, b, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
return mesh;
}
function samplePolyline(points, stepsPerSegment = 16) {
const result = [];
for (let i = 0; i < points.length - 1; i++) {
const start = points[i];
const end = points[i + 1];
for (let step = 0; step < stepsPerSegment; step++) {
result.push(start.clone().lerp(end, step / stepsPerSegment));
}
}
result.push(points[points.length - 1].clone());
return result;
}
const routeEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x5d4f3d,
roughness: 1,
side: THREE.DoubleSide
});
const groundRouteMaterial = new THREE.MeshStandardMaterial({
color: 0xf0643a,
roughness: 0.72,
side: THREE.DoubleSide
});
const bridgeRouteMaterial = new THREE.MeshStandardMaterial({
color: 0x00a6a6,
roughness: 0.68,
side: THREE.DoubleSide
});
const boardwalkMaterial = new THREE.MeshStandardMaterial({
color: 0xb18c60,
roughness: 0.95
});
// -------------------------------------------------------------------------
// Direct ground route: descends into and crosses the dry channel
// -------------------------------------------------------------------------
const directCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-19, 0, 25),
new THREE.Vector3(-14, 0, 19),
new THREE.Vector3(-8, 0, 14),
new THREE.Vector3(-3, 0, 11.7),
new THREE.Vector3(1, 0, 10.4),
new THREE.Vector3(5, 0, 9.8),
new THREE.Vector3(11, 0, 11.3),
new THREE.Vector3(18, 0, 17)
],
false,
"catmullrom",
0.28
);
const directPoints = directCurve.getPoints(190).map(point => {
point.y = terrainHeight(point.x, point.z) + 0.115;
return point;
});
scene.add(
makeRibbon(
offsetY(directPoints, -0.045),
1.72,
routeEdgeMaterial
)
);
scene.add(
makeRibbon(
directPoints,
1.13,
groundRouteMaterial
)
);
// -------------------------------------------------------------------------
// Elevated route: branches north along the west bank
// -------------------------------------------------------------------------
const elevatedGroundCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-8, 0, 14),
new THREE.Vector3(-9.5, 0, 9),
new THREE.Vector3(-8.5, 0, 5),
new THREE.Vector3(-10, 0, 3)
],
false,
"catmullrom",
0.3
);
const elevatedGroundPoints = elevatedGroundCurve.getPoints(100).map(point => {
point.y = terrainHeight(point.x, point.z) + 0.12;
return point;
});
scene.add(
makeRibbon(
offsetY(elevatedGroundPoints, -0.04),
1.48,
routeEdgeMaterial
)
);
scene.add(
makeRibbon(
elevatedGroundPoints,
0.94,
bridgeRouteMaterial
)
);
// -------------------------------------------------------------------------
// Bridge
// -------------------------------------------------------------------------
const BRIDGE_Z = -1;
const BRIDGE_TOP = 2.75;
const bridgeDeck = new THREE.Mesh(
new THREE.BoxGeometry(18.6, 0.4, 3.3),
new THREE.MeshStandardMaterial({
color: 0xc6ad82,
roughness: 0.92
})
);
bridgeDeck.position.set(0, BRIDGE_TOP - 0.2, BRIDGE_Z);
bridgeDeck.castShadow = true;
bridgeDeck.receiveShadow = true;
scene.add(bridgeDeck);
// Stone abutments and piers.
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x8d8a7c,
roughness: 1
});
function addBridgeSupport(x, bottom, height, width, depth) {
const support = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
stoneMaterial
);
support.position.set(x, bottom + height / 2, BRIDGE_Z);
support.castShadow = true;
support.receiveShadow = true;
scene.add(support);
}
addBridgeSupport(-8.2, -0.25, 2.6, 1.3, 3.0);
addBridgeSupport(8.2, -0.25, 2.6, 1.3, 3.0);
addBridgeSupport(-3.6, -1.55, 3.9, 1.15, 2.35);
addBridgeSupport(3.6, -1.55, 3.9, 1.15, 2.35);
// Bridge rails.
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x5a665d,
roughness: 0.8
});
function addCylinderBetween(start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
for (const railZ of [BRIDGE_Z - 1.48, BRIDGE_Z + 1.48]) {
for (const x of [-8.3, -4.2, 0, 4.2, 8.3]) {
addCylinderBetween(
new THREE.Vector3(x, BRIDGE_TOP, railZ),
new THREE.Vector3(x, BRIDGE_TOP + 0.82, railZ),
0.065,
railMaterial
);
}
addCylinderBetween(
new THREE.Vector3(-8.3, BRIDGE_TOP + 0.82, railZ),
new THREE.Vector3(8.3, BRIDGE_TOP + 0.82, railZ),
0.07,
railMaterial
);
addCylinderBetween(
new THREE.Vector3(-8.3, BRIDGE_TOP + 0.39, railZ),
new THREE.Vector3(8.3, BRIDGE_TOP + 0.39, railZ),
0.045,
railMaterial
);
}
// -------------------------------------------------------------------------
// Raised ramps and the continuous cyan bridge route
// -------------------------------------------------------------------------
function makeBeamBetween(start, end, width, thickness, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const beam = new THREE.Mesh(
new THREE.BoxGeometry(length, thickness, width),
material
);
beam.position.copy(start).add(end).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.normalize()
);
beam.castShadow = true;
beam.receiveShadow = true;
scene.add(beam);
}
const westRamp = [
new THREE.Vector3(-10, terrainHeight(-10, 3) + 0.12, 3),
new THREE.Vector3(-9.5, 1.65, 0.5),
new THREE.Vector3(-8, BRIDGE_TOP + 0.09, BRIDGE_Z)
];
const eastRamp = [
new THREE.Vector3(8, BRIDGE_TOP + 0.09, BRIDGE_Z),
new THREE.Vector3(9.5, 1.95, -3),
new THREE.Vector3(13, 0.75, -7),
new THREE.Vector3(
16,
terrainHeight(16, -11) + 0.12,
-11
)
];
for (const ramp of [westRamp, eastRamp]) {
for (let i = 0; i < ramp.length - 1; i++) {
const start = ramp[i];
const end = ramp[i + 1];
makeBeamBetween(
start.clone().add(new THREE.Vector3(0, -0.14, 0)),
end.clone().add(new THREE.Vector3(0, -0.14, 0)),
2.15,
0.22,
boardwalkMaterial
);
}
}
// Ramp support posts.
for (const [x, z, top] of [
[-9.7, 1.8, 1.2],
[10.2, -4, 1.45],
[13.8, -8.2, 0.65]
]) {
const bottom = terrainHeight(x, z);
const height = Math.max(0.15, top - bottom);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.15, height, 8),
boardwalkMaterial
);
post.position.set(x, bottom + height / 2, z);
post.castShadow = true;
scene.add(post);
}
const westRampPoints = samplePolyline(westRamp, 24);
const eastRampPoints = samplePolyline(eastRamp, 30);
scene.add(
makeRibbon(westRampPoints, 1.0, bridgeRouteMaterial)
);
scene.add(
makeRibbon(
[
new THREE.Vector3(-8.2, BRIDGE_TOP + 0.09, BRIDGE_Z),
new THREE.Vector3(8.2, BRIDGE_TOP + 0.09, BRIDGE_Z)
],
1.0,
bridgeRouteMaterial
)
);
scene.add(
makeRibbon(eastRampPoints, 1.0, bridgeRouteMaterial)
);
// -------------------------------------------------------------------------
// Route markers
// -------------------------------------------------------------------------
function addRouteMarker(x, z, color, rotation = 0) {
const group = new THREE.Group();
const ground = terrainHeight(x, z);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.11, 1.8, 8),
new THREE.MeshStandardMaterial({
color: 0x6a5946,
roughness: 1
})
);
post.position.y = 0.9;
post.castShadow = true;
group.add(post);
const panel = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 0.42, 0.12),
new THREE.MeshStandardMaterial({
color,
roughness: 0.7
})
);
panel.position.set(0.22, 1.62, 0);
panel.castShadow = true;
group.add(panel);
group.position.set(x, ground, z);
group.rotation.y = rotation;
scene.add(group);
}
addRouteMarker(-4.8, 12.2, 0xf0643a, -0.35);
addRouteMarker(-9.2, 7.8, 0x00a6a6, 0.35);
addRouteMarker(10.2, -3.2, 0x00a6a6, -0.25);
// -------------------------------------------------------------------------
// Rocks, bushes, and dry vegetation
// -------------------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(72419);
const dummy = new THREE.Object3D();
// Low-poly stones in the dry streambed.
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const rocks = new THREE.InstancedMesh(
rockGeometry,
rockMaterial,
58
);
const rockColors = [
new THREE.Color(0x9a8d73),
new THREE.Color(0xb5a17c),
new THREE.Color(0x817967),
new THREE.Color(0xc1aa7e)
];
for (let i = 0; i < rocks.count; i++) {
const z = -31 + random() * 62;
const x = creekCenter(z) + (random() - 0.5) * 3.5;
const scale = 0.18 + random() * 0.48;
dummy.position.set(x, terrainHeight(x, z) + scale * 0.34, z);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
dummy.scale.set(
scale * (0.8 + random() * 0.5),
scale * (0.45 + random() * 0.35),
scale * (0.8 + random() * 0.5)
);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
rocks.setColorAt(i, rockColors[i % rockColors.length]);
}
rocks.instanceMatrix.needsUpdate = true;
if (rocks.instanceColor) rocks.instanceColor.needsUpdate = true;
rocks.castShadow = true;
rocks.receiveShadow = true;
scene.add(rocks);
// Faceted shrubs around the channel banks.
const shrubGeometry = new THREE.IcosahedronGeometry(1, 1);
const shrubMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const shrubs = new THREE.InstancedMesh(
shrubGeometry,
shrubMaterial,
64
);
const shrubColors = [
new THREE.Color(0x647954),
new THREE.Color(0x78895c),
new THREE.Color(0x536b4d),
new THREE.Color(0x89946a)
];
for (let i = 0; i < shrubs.count; i++) {
const z = -31 + random() * 62;
const side = random() > 0.5 ? 1 : -1;
const x = creekCenter(z) + side * (5 + random() * 12);
const scale = 0.45 + random() * 0.85;
dummy.position.set(x, terrainHeight(x, z) + scale * 0.52, z);
dummy.rotation.set(
random() * 0.5,
random() * Math.PI * 2,
random() * 0.5
);
dummy.scale.set(
scale * (0.8 + random() * 0.35),
scale * (0.72 + random() * 0.3),
scale * (0.8 + random() * 0.35)
);
dummy.updateMatrix();
shrubs.setMatrixAt(i, dummy.matrix);
shrubs.setColorAt(i, shrubColors[i % shrubColors.length]);
}
shrubs.instanceMatrix.needsUpdate = true;
if (shrubs.instanceColor) shrubs.instanceColor.needsUpdate = true;
shrubs.castShadow = true;
shrubs.receiveShadow = true;
scene.add(shrubs);
// Small dry grass tufts made from solid tapered cones.
const grassGeometry = new THREE.ConeGeometry(0.11, 0.7, 5);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x8d8651,
roughness: 1,
flatShading: true
});
const grassTufts = new THREE.InstancedMesh(
grassGeometry,
grassMaterial,
90
);
for (let i = 0; i < grassTufts.count; i++) {
const z = -31 + random() * 62;
const side = random() > 0.5 ? 1 : -1;
const x = creekCenter(z) + side * (3.6 + random() * 12);
const scale = 0.55 + random() * 0.8;
dummy.position.set(x, terrainHeight(x, z) + 0.3 * scale, z);
dummy.rotation.set(
(random() - 0.5) * 0.18,
random() * Math.PI * 2,
(random() - 0.5) * 0.18
);
dummy.scale.set(scale, scale, scale);
dummy.updateMatrix();
grassTufts.setMatrixAt(i, dummy.matrix);
}
grassTufts.instanceMatrix.needsUpdate = true;
grassTufts.castShadow = true;
scene.add(grassTufts);
// -------------------------------------------------------------------------
// Custom orbit, zoom, and pan controls
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let dragButton = 0;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", event => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragButton = event.button;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
event.preventDefault();
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragButton === 2 || event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
const scale = cameraRadius * 0.0015;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(up, dy * scale);
cameraTarget.x = THREE.MathUtils.clamp(
cameraTarget.x,
-24,
24
);
cameraTarget.z = THREE.MathUtils.clamp(
cameraTarget.z,
-20,
24
);
cameraTarget.y = THREE.MathUtils.clamp(
cameraTarget.y,
-2,
7
);
} else {
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.005,
0.25,
1.46
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
25,
92
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraTarget.set(0, -0.15, 3);
cameraTheta = 0.43;
cameraPhi = 0.84;
cameraRadius = 59;
updateCamera();
});
window.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraTheta += 0.08;
else if (key === "arrowright") cameraTheta -= 0.08;
else if (key === "arrowup") cameraPhi -= 0.05;
else if (key === "arrowdown") cameraPhi += 0.05;
else if (key === "+" || key === "=") cameraRadius -= 2;
else if (key === "-") cameraRadius += 2;
else if (key === "r") {
cameraTarget.set(0, -0.15, 3);
cameraTheta = 0.43;
cameraPhi = 0.84;
cameraRadius = 59;
} else {
return;
}
cameraPhi = THREE.MathUtils.clamp(cameraPhi, 0.25, 1.46);
cameraRadius = THREE.MathUtils.clamp(cameraRadius, 25, 92);
updateCamera();
event.preventDefault();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```