Prompt specification
Build or customize the Three.js 3D scene "Andean hillside farming settlement" 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 hillside farming settlement
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/andean-hillside-farming-settlement-x2255
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: Andean hillside farming settlement. Build a referenced Andean farming scene with terraces, paths, storage buildings, and different elevation bands. Avoid assigning exact crop suitability without a source for the selected location.
Working Three.js Starter (andean-hillside-farming-settlement-x2255):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Andean Hillside Farming Settlement</title>
<style>
:root {
color-scheme: light;
--ink: #263128;
--paper: rgba(248, 244, 230, 0.91);
--line: rgba(65, 71, 54, 0.18);
--earth: #a66d42;
--stone: #887c67;
--path: #c5a264;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c7d7d4;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
top: 20px;
left: 20px;
width: min(360px, calc(100vw - 40px));
padding: 18px 19px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(43, 51, 42, 0.14);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 7px;
color: #8a5537;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 4vw, 31px);
line-height: 1.02;
letter-spacing: -0.035em;
}
.description {
margin: 10px 0 15px;
color: #586055;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #5c6259;
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.stone {
background: var(--stone);
}
.swatch.path {
background: var(--path);
}
.swatch.building {
background: var(--earth);
}
.controls {
position: absolute;
right: 20px;
top: 20px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 40px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(43, 51, 42, 0.11);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 750;
backdrop-filter: blur(12px);
}
button:hover {
background: #fffdf4;
}
button:focus-visible {
outline: 3px solid rgba(166, 109, 66, 0.28);
outline-offset: 2px;
}
.hint {
position: absolute;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
width: max-content;
max-width: calc(100vw - 40px);
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(248, 244, 230, 0.86);
color: #596056;
box-shadow: 0 8px 24px rgba(43, 51, 42, 0.1);
font-size: 11px;
text-align: center;
backdrop-filter: blur(10px);
}
.note {
position: absolute;
left: 20px;
bottom: 20px;
width: min(355px, calc(100vw - 40px));
padding: 11px 13px;
border-left: 3px solid #9b6948;
border-radius: 0 10px 10px 0;
background: rgba(248, 244, 230, 0.86);
color: #62665c;
box-shadow: 0 8px 24px rgba(43, 51, 42, 0.09);
font-size: 10px;
line-height: 1.45;
backdrop-filter: blur(10px);
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: min(310px, calc(100vw - 24px));
padding: 14px 15px;
}
.description {
margin-bottom: 10px;
}
.legend {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 56px;
}
.hint {
bottom: 12px;
}
.note {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<section class="panel">
<p class="eyebrow">Low-poly landscape study</p>
<h1>Andean Hillside Settlement</h1>
<p class="description">
A stylized farming landscape with stepped terraces, stone retaining
walls, winding footpaths, clustered homes, and elevated storage
structures.
</p>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch stone"></i> Stonework</span>
<span><i class="swatch path"></i> Paths</span>
<span><i class="swatch building"></i> Settlement</span>
</div>
</section>
<div class="controls">
<button id="reset" type="button">Reset view</button>
</div>
<div class="hint">
Drag to orbit · Wheel or pinch to zoom · Arrow keys to pan · +/− to zoom
</div>
<div class="note">
Illustrative landscape only. The elevation bands and decorative
vegetation are not crop-suitability zoning or an agronomic recommendation
for any selected location.
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8d9d6);
scene.fog = new THREE.Fog(0xc8d9d6, 27, 66);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
140
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8f3ed, 0x6d6047, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe7b9, 3.15);
sun.position.set(-13, 22, 14);
sun.target.position.set(0, 2.5, -2);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -23;
sun.shadow.camera.right = 23;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun, sun.target);
const fill = new THREE.DirectionalLight(0x9dbbc1, 0.55);
fill.position.set(18, 10, -18);
scene.add(fill);
// ------------------------------------------------------------
// Deterministic random helpers
// ------------------------------------------------------------
let seed = 18473;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...options
});
}
const earthMaterial = material(0x806447, {
side: THREE.DoubleSide
});
const pathMaterial = material(0xc3a067, {
side: THREE.DoubleSide
});
const stairMaterial = material(0xb38f60);
const stoneMaterial = material(0xffffff);
const woodMaterial = material(0x594534);
const darkMaterial = material(0x34322c);
const adobeMaterials = [
material(0xc38a61),
material(0xb97655),
material(0xd1a477),
material(0xa9624d)
];
const roofMaterials = [
material(0x9a7543),
material(0x765f3e),
material(0x9b563c),
material(0x6c5540)
];
const vegetationMaterials = [
material(0x667951),
material(0x78815a),
material(0x55684c),
material(0x8b8d5d)
];
const rockMaterial = material(0x8b806c);
// ------------------------------------------------------------
// Terrain data: front -> back, with each successive band higher
// ------------------------------------------------------------
const bands = [
{ front: 10, back: 6, y: 0.15, wf: 14.0, wb: 13.6 },
{ front: 6, back: 2, y: 1.45, wf: 13.6, wb: 13.1 },
{ front: 2, back: -2, y: 2.85, wf: 13.1, wb: 12.5 },
{ front: -2, back: -6, y: 4.25, wf: 12.5, wb: 11.8 },
{ front: -6, back: -10, y: 5.75, wf: 11.8, wb: 11.0 },
{ front: -10, back: -14, y: 7.35, wf: 11.0, wb: 10.3 }
];
const bandColors = [
0x93885c,
0x81855a,
0x74805a,
0x697b59,
0x62765a,
0x5e725b
];
const buildingClearings = [
{ x: -1.6, z: 9.0, r: 2.0 },
{ x: 4.7, z: 9.0, r: 2.3 },
{ x: 9.7, z: 8.7, r: 1.8 },
{ x: -3.2, z: 5.1, r: 2.2 },
{ x: 7.4, z: 5.0, r: 2.3 },
{ x: -9.0, z: 0.2, r: 1.7 },
{ x: -1.2, z: -1.0, r: 2.0 },
{ x: 7.1, z: -4.0, r: 2.2 },
{ x: -7.2, z: -8.2, r: 1.8 }
];
function clearOfBuildings(x, z, padding = 0.8) {
return buildingClearings.every(
(item) => Math.hypot(item.x - x, item.z - z) > item.r + padding
);
}
function addTriangle(positions, colors, a, b, c, color) {
positions.push(...a, ...b, ...c);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
function createBandSurface(band, bandIndex) {
const positions = [];
const colors = [];
const columns = 10;
const rows = 5;
const base = new THREE.Color(bandColors[bandIndex]);
function point(i, j) {
const u = i / columns;
const v = j / rows;
const width = THREE.MathUtils.lerp(band.wf, band.wb, v);
const x = (u * 2 - 1) * width;
const z = THREE.MathUtils.lerp(band.front, band.back, v);
return [x, band.y, z];
}
for (let j = 0; j < rows; j++) {
for (let i = 0; i < columns; i++) {
const a = point(i, j);
const b = point(i + 1, j);
const c = point(i, j + 1);
const d = point(i + 1, j + 1);
const variation = range(-0.055, 0.055);
const color = base.clone().offsetHSL(
range(-0.018, 0.018),
range(-0.025, 0.025),
variation
);
if ((i + j + bandIndex) % 2 === 0) {
addTriangle(positions, colors, a, b, c, color);
addTriangle(positions, colors, b, d, c, color);
} else {
addTriangle(positions, colors, a, b, d, color);
addTriangle(positions, colors, a, d, c, color);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
material(0xffffff, {
vertexColors: true,
side: THREE.DoubleSide
})
);
mesh.receiveShadow = true;
scene.add(mesh);
}
bands.forEach(createBandSurface);
// ------------------------------------------------------------
// Sloping earth around the terraced landform
// ------------------------------------------------------------
function addSlopeQuad(a, b, c, d, color) {
const positions = [];
const colors = [];
const tint = new THREE.Color(color);
addTriangle(positions, colors, a, c, b, tint);
addTriangle(positions, colors, c, d, b, tint.clone().offsetHSL(0, 0, 0.025));
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
material(0xffffff, {
vertexColors: true,
side: THREE.DoubleSide
})
);
mesh.receiveShadow = true;
scene.add(mesh);
}
bands.forEach((band, index) => {
const depth = band.front - band.back;
addSlopeQuad(
[-band.wf, band.y, band.front],
[-band.wb, band.y, band.back],
[-19.5, -1.15, band.front - depth * 0.5],
[-18.0, -1.15, band.back - depth * 0.5],
0x80664b
);
addSlopeQuad(
[band.wf, band.y, band.front],
[band.wb, band.y, band.back],
[19.5, -1.15, band.front - depth * 0.5],
[18.0, -1.15, band.back - depth * 0.5],
0x786047
);
});
// Front slope beneath the lowest terrace.
addSlopeQuad(
[-bands[0].wf, bands[0].y, bands[0].front],
[bands[0].wf, bands[0].y, bands[0].front],
[-17.5, -1.15, 16],
[17.5, -1.15, 16],
0x88704f
);
// Ground and distant landforms.
const ground = new THREE.Mesh(
new THREE.CircleGeometry(46, 48),
material(0x85896a)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.17;
ground.receiveShadow = true;
scene.add(ground);
const mountainMaterials = [
material(0x71837c),
material(0x7f8c82),
material(0x687b76),
material(0x89958a)
];
const mountainData = [
[-23, -29, 12, 17],
[-9, -34, 14, 20],
[7, -32, 13, 18],
[22, -27, 11, 15],
[31, -35, 16, 22]
];
mountainData.forEach(([x, z, radius, height], index) => {
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 5 + (index % 2), 1),
mountainMaterials[index % mountainMaterials.length]
);
mountain.position.set(x, -1.15 + height * 0.5, z);
mountain.rotation.y = range(0, Math.PI);
mountain.scale.z = range(0.6, 0.9);
mountain.receiveShadow = true;
scene.add(mountain);
});
// ------------------------------------------------------------
// Stone retaining walls
// ------------------------------------------------------------
const accessPoints = [-7, 5, -5, 5, -2];
const wallBlocks = [];
for (let bandIndex = 1; bandIndex < bands.length; bandIndex++) {
const band = bands[bandIndex];
const lower = bands[bandIndex - 1];
const rise = band.y - lower.y;
const width = band.wf;
const count = Math.ceil(width / 0.93);
const step = width / count;
const accessX = accessPoints[bandIndex - 1];
for (let course = 0; course < 2; course++) {
for (let i = 0; i < count; i++) {
const x =
-width * 0.5 +
(i + 0.5) * step +
(course === 1 ? step * 0.18 : 0);
if (x > width * 0.5) continue;
// Leave openings where the stairways meet the terrace walls.
if (Math.abs(x - accessX) < 1.05) continue;
const blockWidth = step * range(0.82, 0.98);
const blockHeight = rise * (course === 0 ? 0.51 : 0.44);
const y =
lower.y +
(course === 0 ? rise * 0.27 : rise * 0.72);
wallBlocks.push({
x,
y,
z: band.front + range(-0.03, 0.08),
w: blockWidth,
h: blockHeight,
d: range(0.45, 0.68),
rotation: range(-0.055, 0.055),
color: new THREE.Color(
[0x978b74, 0x887d69, 0xa0957d, 0x7d7464][
Math.floor(random() * 4)
]
)
});
}
}
}
const wallMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
stoneMaterial,
wallBlocks.length
);
const dummy = new THREE.Object3D();
wallBlocks.forEach((block, index) => {
dummy.position.set(block.x, block.y, block.z);
dummy.rotation.set(0, block.rotation, range(-0.018, 0.018));
dummy.scale.set(block.w, block.h, block.d);
dummy.updateMatrix();
wallMesh.setMatrixAt(index, dummy.matrix);
wallMesh.setColorAt(index, block.color);
});
wallMesh.instanceMatrix.needsUpdate = true;
wallMesh.instanceColor.needsUpdate = true;
wallMesh.castShadow = true;
wallMesh.receiveShadow = true;
scene.add(wallMesh);
// ------------------------------------------------------------
// Stone stairways
// ------------------------------------------------------------
function addStair(x, frontZ, lowerY, upperY) {
const rise = upperY - lowerY;
const steps = 8;
for (let i = 0; i < steps; i++) {
const top = lowerY + ((i + 1) / steps) * rise;
const depth = 0.4;
const z = frontZ + 2.35 - i * 0.36;
const stair = new THREE.Mesh(
new THREE.BoxGeometry(1.35, top - lowerY, depth),
stairMaterial
);
stair.position.set(x, lowerY + (top - lowerY) * 0.5, z);
stair.castShadow = true;
stair.receiveShadow = true;
scene.add(stair);
}
// Small stone markers beside the upper landing.
[-0.8, 0.8].forEach((offset) => {
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.12, 0.7, 5),
rockMaterial
);
marker.position.set(x + offset, upperY + 0.35, frontZ - 0.3);
marker.castShadow = true;
scene.add(marker);
});
}
for (let i = 1; i < bands.length; i++) {
addStair(
accessPoints[i - 1],
bands[i].front,
bands[i - 1].y,
bands[i].y
);
}
// ------------------------------------------------------------
// Winding paths
// ------------------------------------------------------------
function addRibbonPath(points, width = 0.72) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.18
);
const positions = [];
const colors = [];
const samples = 64;
const pathColor = new THREE.Color(0xc5a164);
const left = [];
const right = [];
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const point = curve.getPoint(t);
const tangent = curve.getTangent(t);
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
left.push(point.clone().addScaledVector(side, width * 0.5));
right.push(point.clone().addScaledVector(side, -width * 0.5));
}
for (let i = 0; i < samples; i++) {
const a = left[i].toArray();
const b = right[i].toArray();
const c = left[i + 1].toArray();
const d = right[i + 1].toArray();
const tint = pathColor.clone().offsetHSL(
0,
0,
range(-0.035, 0.035)
);
addTriangle(positions, colors, a, c, b, tint);
addTriangle(positions, colors, c, d, b, tint);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
material(0xffffff, {
vertexColors: true,
side: THREE.DoubleSide
})
);
mesh.receiveShadow = true;
scene.add(mesh);
}
const pathY = [0.22, 1.52, 2.92, 4.32, 5.82, 7.42];
addRibbonPath([
[-11.5, pathY[0], 8.7],
[-7, pathY[0], 8.35],
[-3, pathY[0], 8.45],
[1, pathY[0], 7.85],
[6, pathY[0], 8.35],
[10.8, pathY[0], 7.45]
]);
addRibbonPath([
[-7, pathY[1], 5.45],
[-6, pathY[1], 3.85],
[-1, pathY[1], 3.6],
[2, pathY[1], 4.25],
[5, pathY[1], 4.4],
[10.5, pathY[1], 3.95]
]);
addRibbonPath([
[5, pathY[2], 1.45],
[1, pathY[2], 0.8],
[-3, pathY[2], 1.0],
[-5, pathY[2], 0.4]
]);
addRibbonPath([
[-5, pathY[3], -2.5],
[-1, pathY[3], -3.25],
[3, pathY[3], -2.9],
[5, pathY[3], -3.6]
]);
addRibbonPath([
[5, pathY[4], -6.45],
[1, pathY[4], -7.25],
[-2, pathY[4], -7.55]
]);
addRibbonPath([
[-2, pathY[5], -10.45],
[2, pathY[5], -11.2],
[6.5, pathY[5], -10.7]
]);
// ------------------------------------------------------------
// Buildings
// ------------------------------------------------------------
function createRoofGeometry(width, depth, height) {
const w = width * 0.5;
const d = depth * 0.5;
const vertices = [
[-w, 0, -d],
[w, 0, -d],
[w, 0, d],
[-w, 0, d],
[-w, height, 0],
[w, height, 0]
];
const faces = [
[0, 1, 5],
[0, 5, 4],
[3, 4, 5],
[3, 5, 2],
[0, 4, 3],
[1, 2, 5]
];
const positions = [];
faces.forEach(([a, b, c]) => {
positions.push(...vertices[a], ...vertices[b], ...vertices[c]);
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
function addBuilding({
x,
z,
y,
w = 2.1,
d = 1.7,
h = 1.8,
rotation = 0,
wallColor = 0,
roofColor = 0,
storage = false
}) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
const foundation = new THREE.Mesh(
new THREE.BoxGeometry(w + 0.3, 0.2, d + 0.3),
material(0x81755f)
);
foundation.position.y = 0.1;
foundation.castShadow = true;
foundation.receiveShadow = true;
group.add(foundation);
const walls = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
adobeMaterials[wallColor % adobeMaterials.length]
);
walls.position.y = 0.2 + h * 0.5;
walls.castShadow = true;
walls.receiveShadow = true;
group.add(walls);
const roofHeight = storage ? 0.9 : 0.78;
const roof = new THREE.Mesh(
createRoofGeometry(w + 0.42, d + 0.42, roofHeight),
roofMaterials[roofColor % roofMaterials.length]
);
roof.material.side = THREE.DoubleSide;
roof.position.y = 0.2 + h;
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
// Dark ridge beam.
const ridge = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, w + 0.3, 5),
woodMaterial
);
ridge.rotation.z = Math.PI * 0.5;
ridge.position.set(0, 0.2 + h + roofHeight + 0.025, 0);
ridge.castShadow = true;
group.add(ridge);
// Entrance.
const doorWidth = storage ? 0.7 : 0.48;
const doorHeight = storage ? 1.25 : 1.1;
const door = new THREE.Mesh(
new THREE.BoxGeometry(doorWidth, doorHeight, 0.055),
woodMaterial
);
door.position.set(
storage ? 0 : -w * 0.16,
0.2 + doorHeight * 0.5,
d * 0.5 + 0.03
);
door.castShadow = true;
group.add(door);
if (storage) {
// Simple vertical door slats.
for (let i = -1; i <= 1; i++) {
const slat = new THREE.Mesh(
new THREE.BoxGeometry(0.045, doorHeight * 0.93, 0.04),
darkMaterial
);
slat.position.set(
i * 0.18,
0.2 + doorHeight * 0.5,
d * 0.5 + 0.065
);
group.add(slat);
}
} else {
// Small recessed window.
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.36, 0.38, 0.05),
material(0x31444a, { roughness: 0.55 })
);
windowMesh.position.set(
w * 0.28,
0.2 + h * 0.58,
d * 0.5 + 0.035
);
group.add(windowMesh);
const frame = new THREE.Mesh(
new THREE.BoxGeometry(0.46, 0.47, 0.035),
woodMaterial
);
frame.position.copy(windowMesh.position);
frame.position.z -= 0.015;
group.add(frame);
windowMesh.position.z += 0.025;
}
// A few irregular foundation stones.
for (let i = 0; i < 3; i++) {
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.16, 0),
rockMaterial
);
stone.position.set(
-w * 0.38 + i * w * 0.38,
0.16,
d * 0.5 + 0.05
);
stone.scale.set(
range(0.8, 1.2),
range(0.55, 0.85),
range(0.7, 1.0)
);
stone.castShadow = true;
group.add(stone);
}
scene.add(group);
return group;
}
function addRoundStore(x, z, y) {
const group = new THREE.Group();
group.position.set(x, y, z);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.88, 0.96, 0.22, 8),
rockMaterial
);
base.position.y = 0.11;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.67, 0.82, 2.05, 8),
adobeMaterials[2]
);
body.position.y = 1.24;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(0.96, 0.9, 8),
roofMaterials[1]
);
roof.position.y = 2.69;
roof.castShadow = true;
group.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 1.1, 0.06),
woodMaterial
);
door.position.set(0, 0.77, 0.81);
door.castShadow = true;
group.add(door);
const band = new THREE.Mesh(
new THREE.CylinderGeometry(0.75, 0.78, 0.12, 8),
stoneMaterial
);
band.position.y = 1.48;
group.add(band);
scene.add(group);
}
addBuilding({
x: -1.6,
z: 9.0,
y: bands[0].y,
w: 2.0,
d: 1.45,
h: 1.65,
rotation: -0.05,
wallColor: 2,
roofColor: 0
});
addBuilding({
x: 4.7,
z: 9.0,
y: bands[0].y,
w: 2.7,
d: 1.45,
h: 1.75,
rotation: 0.03,
wallColor: 1,
roofColor: 2,
storage: true
});
addBuilding({
x: 9.7,
z: 8.7,
y: bands[0].y,
w: 1.7,
d: 1.35,
h: 1.55,
rotation: -0.12,
wallColor: 3,
roofColor: 1
});
addBuilding({
x: -3.2,
z: 5.1,
y: bands[1].y,
w: 2.15,
d: 1.55,
h: 1.8,
rotation: 0.04,
wallColor: 0,
roofColor: 0
});
addBuilding({
x: 7.4,
z: 5.0,
y: bands[1].y,
w: 2.8,
d: 1.55,
h: 1.95,
rotation: -0.035,
wallColor: 3,
roofColor: 3,
storage: true
});
addRoundStore(-9.0, 0.2, bands[2].y);
addBuilding({
x: -1.2,
z: -1.0,
y: bands[2].y,
w: 2.15,
d: 1.5,
h: 1.75,
rotation: 0.06,
wallColor: 2,
roofColor: 1,
storage: true
});
addBuilding({
x: 7.1,
z: -4.0,
y: bands[3].y,
w: 2.7,
d: 1.55,
h: 1.9,
rotation: -0.07,
wallColor: 0,
roofColor: 2,
storage: true
});
addBuilding({
x: -7.2,
z: -8.2,
y: bands[4].y,
w: 1.8,
d: 1.4,
h: 1.55,
rotation: 0.08,
wallColor: 1,
roofColor: 0
});
// ------------------------------------------------------------
// Decorative vegetation and rocks
// ------------------------------------------------------------
const shrubGeometry = new THREE.DodecahedronGeometry(0.36, 0);
const grassGeometry = new THREE.ConeGeometry(0.12, 0.48, 3);
const rockGeometry = new THREE.DodecahedronGeometry(0.3, 0);
const trunkGeometry = new THREE.CylinderGeometry(0.11, 0.16, 1.25, 5);
const canopyGeometry = new THREE.DodecahedronGeometry(0.72, 0);
for (let i = 0; i < 48; i++) {
const bandIndex = Math.floor(random() * bands.length);
const band = bands[bandIndex];
let x = range(-band.wf + 0.6, band.wf - 0.6);
let z = range(band.back + 0.5, band.front - 0.5);
if (!clearOfBuildings(x, z, 0.35)) {
x = Math.sign(x || 1) * Math.min(Math.abs(x) + 2, band.wf - 0.5);
z = range(band.back + 0.5, band.front - 0.5);
}
const shrub = new THREE.Mesh(
shrubGeometry,
vegetationMaterials[Math.floor(random() * vegetationMaterials.length)]
);
shrub.position.set(x, band.y + 0.22, z);
shrub.scale.set(
range(0.65, 1.35),
range(0.45, 0.9),
range(0.65, 1.25)
);
shrub.rotation.y = range(0, Math.PI * 2);
shrub.castShadow = true;
scene.add(shrub);
}
for (let i = 0; i < 42; i++) {
const bandIndex = Math.floor(random() * bands.length);
const band = bands[bandIndex];
const tuft = new THREE.Mesh(
grassGeometry,
vegetationMaterials[Math.floor(random() * vegetationMaterials.length)]
);
tuft.position.set(
range(-band.wf + 0.5, band.wf - 0.5),
band.y + 0.22,
range(band.back + 0.4, band.front - 0.4)
);
tuft.rotation.y = range(0, Math.PI * 2);
tuft.scale.setScalar(range(0.7, 1.3));
tuft.castShadow = true;
scene.add(tuft);
}
for (let i = 0; i < 26; i++) {
const bandIndex = Math.floor(random() * bands.length);
const band = bands[bandIndex];
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
rock.position.set(
range(-band.wf + 0.7, band.wf - 0.7),
band.y + 0.14,
range(band.back + 0.5, band.front - 0.5)
);
rock.scale.set(
range(0.45, 1.25),
range(0.35, 0.9),
range(0.5, 1.2)
);
rock.rotation.set(
range(-0.2, 0.2),
range(0, Math.PI * 2),
range(-0.2, 0.2)
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
function addTree(x, z, y, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(trunkGeometry, woodMaterial);
trunk.position.y = 0.62;
trunk.castShadow = true;
group.add(trunk);
const lowerCanopy = new THREE.Mesh(
canopyGeometry,
vegetationMaterials[0]
);
lowerCanopy.position.set(0, 1.3, 0);
lowerCanopy.scale.set(1.05, 0.9, 0.95);
lowerCanopy.castShadow = true;
group.add(lowerCanopy);
const upperCanopy = new THREE.Mesh(
canopyGeometry,
vegetationMaterials[2]
);
upperCanopy.position.set(0.18, 1.72, -0.08);
upperCanopy.scale.setScalar(0.72);
upperCanopy.castShadow = true;
group.add(upperCanopy);
scene.add(group);
}
[
[-11.3, 7.2, bands[0].y, 0.95],
[11.5, 6.8, bands[0].y, 1.05],
[-11.0, 2.8, bands[1].y, 0.85],
[11.5, 2.2, bands[1].y, 1.0],
[-11.0, -3.1, bands[3].y, 0.85],
[10.5, -7.5, bands[4].y, 0.9],
[-8.6, -11.3, bands[5].y, 0.8]
].forEach((tree) => addTree(...tree));
// ------------------------------------------------------------
// Low-poly clouds
// ------------------------------------------------------------
const cloudMaterial = material(0xf2f1df, {
roughness: 1,
emissive: 0x6f756d,
emissiveIntensity: 0.05
});
function addCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
[
[-0.9, 0, 0, 0.75],
[0, 0.18, 0, 1.0],
[0.95, -0.03, 0, 0.68],
[0.35, -0.18, 0.1, 0.85]
].forEach(([cx, cy, cz, s]) => {
const puff = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.7, 0),
cloudMaterial
);
puff.position.set(cx, cy, cz);
puff.scale.set(s, s * 0.65, s * 0.72);
group.add(puff);
});
scene.add(group);
}
addCloud(-15, 14.5, -25, 1.2);
addCloud(5, 17.0, -30, 1.45);
addCloud(22, 13.8, -23, 0.95);
// ------------------------------------------------------------
// Custom camera controls — no external control addon
// ------------------------------------------------------------
class OrbitControls {
constructor(camera, element) {
this.camera = camera;
this.element = element;
this.target = new THREE.Vector3(0, 2.5, -1.5);
this.theta = 0.58;
this.phi = 1.02;
this.radius = 29;
this.targetTheta = this.theta;
this.targetPhi = this.phi;
this.targetRadius = this.radius;
this.pointers = new Map();
this.dragging = false;
this.lastX = 0;
this.lastY = 0;
this.pinchDistance = 0;
this.reset = this.reset.bind(this);
this.onPointerDown = this.onPointerDown.bind(this);
this.onPointerMove = this.onPointerMove.bind(this);
this.onPointerUp = this.onPointerUp.bind(this);
this.onWheel = this.onWheel.bind(this);
this.onKeyDown = this.onKeyDown.bind(this);
this.onDoubleClick = this.onDoubleClick.bind(this);
element.addEventListener("pointerdown", this.onPointerDown);
element.addEventListener("pointermove", this.onPointerMove);
element.addEventListener("pointerup", this.onPointerUp);
element.addEventListener("pointercancel", this.onPointerUp);
element.addEventListener("wheel", this.onWheel, { passive: false });
element.addEventListener("dblclick", this.onDoubleClick);
window.addEventListener("keydown", this.onKeyDown);
this.update(0, true);
}
reset() {
this.target.set(0, 2.5, -1.5);
this.targetTheta = 0.58;
this.targetPhi = 1.02;
this.targetRadius = 29;
}
onPointerDown(event) {
this.element.setPointerCapture(event.pointerId);
this.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (this.pointers.size === 1) {
this.dragging = true;
this.lastX = event.clientX;
this.lastY = event.clientY;
} else if (this.pointers.size === 2) {
this.pinchDistance = this.getPinchDistance();
}
}
onPointerMove(event) {
if (!this.pointers.has(event.pointerId)) return;
this.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (this.pointers.size >= 2) {
const nextDistance = this.getPinchDistance();
if (this.pinchDistance > 0) {
this.targetRadius = THREE.MathUtils.clamp(
this.targetRadius * (this.pinchDistance / nextDistance),
12,
46
);
}
this.pinchDistance = nextDistance;
return;
}
if (!this.dragging) return;
const dx = event.clientX - this.lastX;
const dy = event.clientY - this.lastY;
this.lastX = event.clientX;
this.lastY = event.clientY;
this.targetTheta -= dx * 0.0055;
this.targetPhi = THREE.MathUtils.clamp(
this.targetPhi - dy * 0.0045,
0.28,
1.43
);
}
onPointerUp(event) {
this.pointers.delete(event.pointerId);
if (this.pointers.size < 2) {
this.pinchDistance = 0;
}
if (this.pointers.size === 0) {
this.dragging = false;
}
}
getPinchDistance() {
const points = [...this.pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
onWheel(event) {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.0011);
this.targetRadius = THREE.MathUtils.clamp(
this.targetRadius * factor,
12,
46
);
}
onDoubleClick() {
this.reset();
}
onKeyDown(event) {
const panAmount = 0.65;
switch (event.key) {
case "ArrowLeft":
this.target.x -= panAmount;
break;
case "ArrowRight":
this.target.x += panAmount;
break;
case "ArrowUp":
this.target.z -= panAmount;
break;
case "ArrowDown":
this.target.z += panAmount;
break;
case "+":
case "=":
this.targetRadius = Math.max(12, this.targetRadius - 1.5);
break;
case "-":
case "_":
this.targetRadius = Math.min(46, this.targetRadius + 1.5);
break;
case "r":
case "R":
this.reset();
break;
}
}
update(delta, immediate = false) {
const damping = immediate ? 1 : Math.min(1, delta * 8);
this.theta += (this.targetTheta - this.theta) * damping;
this.phi += (this.targetPhi - this.phi) * damping;
this.radius += (this.targetRadius - this.radius) * damping;
const sinPhi = Math.sin(this.phi);
this.camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * Math.cos(this.phi),
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
this.camera.lookAt(this.target);
}
}
const controls = new OrbitControls(camera, renderer.domElement);
document.getElementById("reset").addEventListener("click", () => {
controls.reset();
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
function animate(time) {
const delta = Math.min(0.05, (time - previousTime) / 1000);
previousTime = time;
controls.update(delta);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```