Prompt specification
Build or customize the Three.js 3D scene "Weather front passing a rural town" 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: Weather front passing a rural town
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/weather-front-passing-a-rural-town-x1275
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: weather front passing a rural town. Compose farms, a hill, and a small town beneath a moving transparent front; show staged clouds and rainfall with a timeline rather than a forecast claim. Return one self-contained HTML file.
Working Three.js Starter (weather-front-passing-a-rural-town-x1275):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Passing Front — A Rural Voxel Timeline</title>
<style>
:root {
--ink: #17313a;
--muted: #526a72;
--paper: rgba(247, 244, 229, 0.92);
--line: rgba(23, 49, 58, 0.18);
--accent: #d26b45;
--rain: #5f92aa;
--shadow: 0 16px 50px rgba(20, 45, 52, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fc8d8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body { position: relative; }
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
max-width: min(440px, calc(100vw - 48px));
padding: 17px 19px 16px;
border: 1px solid rgba(255, 255, 255, 0.52);
border-radius: 16px;
background: rgba(247, 244, 229, 0.82);
backdrop-filter: blur(12px);
box-shadow: var(--shadow);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--accent);
box-shadow: 13px 0 0 rgba(210, 107, 69, 0.35);
margin-right: 10px;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 36px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
max-width: 380px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.status-card {
position: absolute;
top: 24px;
right: 24px;
width: 260px;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 16px;
background: rgba(247, 244, 229, 0.82);
backdrop-filter: blur(12px);
box-shadow: var(--shadow);
}
.status-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
padding: 8px 0;
border-top: 1px solid var(--line);
font-size: 11px;
}
.status-row:first-of-type { border-top: 0; }
.status-row span:first-child {
color: var(--muted);
font-weight: 650;
}
.status-row strong {
font-variant-numeric: tabular-nums;
font-weight: 800;
}
.meter {
height: 5px;
margin-top: 6px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 49, 58, 0.1);
}
.meter > div {
width: 0;
height: 100%;
border-radius: inherit;
transition: width 120ms linear;
}
#cloud-meter { background: #73838a; }
#rain-meter { background: var(--rain); }
.not-forecast {
margin-top: 10px;
padding: 9px 10px;
border-radius: 9px;
background: rgba(210, 107, 69, 0.11);
color: #87472f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
line-height: 1.4;
text-transform: uppercase;
}
.timeline-panel {
position: absolute;
right: 24px;
bottom: 24px;
left: 24px;
width: min(900px, calc(100vw - 48px));
margin: 0 auto;
padding: 16px 18px 14px;
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 18px;
background: var(--paper);
backdrop-filter: blur(14px);
box-shadow: var(--shadow);
pointer-events: auto;
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin-bottom: 10px;
}
.stage-wrap {
min-width: 0;
display: flex;
align-items: baseline;
gap: 12px;
}
#stage-name {
flex: 0 0 auto;
color: var(--accent);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#stage-description {
overflow: hidden;
color: var(--muted);
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
#timecode {
flex: 0 0 auto;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
font-weight: 750;
letter-spacing: 0.06em;
}
.timeline-controls {
display: flex;
align-items: center;
gap: 12px;
}
button, select {
border: 1px solid var(--line);
color: var(--ink);
background: rgba(255, 255, 255, 0.5);
font: inherit;
}
button {
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.9);
}
button:focus-visible, select:focus-visible, input:focus-visible {
outline: 3px solid rgba(210, 107, 69, 0.35);
outline-offset: 2px;
}
#play {
width: 40px;
height: 40px;
flex: 0 0 40px;
border-radius: 12px;
font-size: 15px;
font-weight: 900;
}
#restart {
height: 40px;
padding: 0 13px;
border-radius: 12px;
font-size: 12px;
font-weight: 800;
}
#speed {
height: 40px;
padding: 0 28px 0 10px;
border-radius: 11px;
font-size: 12px;
font-weight: 750;
}
#timeline {
width: 100%;
height: 8px;
margin: 0;
border-radius: 999px;
appearance: none;
background:
linear-gradient(to right,
#c8d0c8 0%,
#9faeb2 36%,
#607f91 55%,
#91a9af 77%,
#c8d0c8 100%);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 4px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 9px rgba(23, 49, 58, 0.35);
}
#timeline::-moz-range-thumb {
width: 13px;
height: 13px;
border: 4px solid var(--paper);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 9px rgba(23, 49, 58, 0.35);
}
.chapters {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 4px;
margin-top: 7px;
}
.chapter {
padding: 5px 4px;
border: 0;
border-radius: 7px;
background: transparent;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.055em;
text-align: left;
text-transform: uppercase;
}
.chapter.active {
color: var(--accent);
background: rgba(210, 107, 69, 0.09);
}
.camera-help {
position: absolute;
right: 26px;
bottom: 190px;
padding: 8px 10px;
border-radius: 8px;
background: rgba(247, 244, 229, 0.66);
color: rgba(23, 49, 58, 0.7);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #9fc8d8;
color: var(--ink);
font-size: 12px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 12px;
left: 12px;
padding: 13px 14px;
}
.brand .subtitle { display: none; }
.status-card {
top: 12px;
right: 12px;
width: 205px;
padding: 12px;
}
.status-row { padding: 5px 0; }
.not-forecast { font-size: 8px; }
.timeline-panel {
right: 12px;
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
.timeline-top { margin-bottom: 8px; }
#stage-description { display: none; }
.chapter { font-size: 7px; }
.camera-help { display: none; }
#speed { display: none; }
}
@media (max-width: 460px) {
.status-card { display: none; }
.brand { max-width: calc(100vw - 24px); }
h1 { font-size: 24px; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel scene of a weather front passing a rural town"></div>
<div class="hud">
<section class="brand">
<div class="eyebrow">Rural weather study</div>
<h1>Passing Front</h1>
<p class="subtitle">
A small town, working farms, and a hill beneath a moving translucent weather front.
Scrub the timeline to compose the scene.
</p>
</section>
<aside class="status-card" aria-live="polite">
<div class="status-row">
<span>Cloud cover</span>
<strong id="cloud-value">0%</strong>
</div>
<div class="meter"><div id="cloud-meter"></div></div>
<div class="status-row">
<span>Rain density</span>
<strong id="rain-value">0%</strong>
</div>
<div class="meter"><div id="rain-meter"></div></div>
<div class="status-row">
<span>Front position</span>
<strong id="front-value">West</strong>
</div>
<div class="not-forecast">
Visual sequence only — not a weather forecast
</div>
</aside>
<div class="camera-help">Drag to orbit · Wheel to zoom · Shift-drag to pan · Double-click to reset</div>
<section class="timeline-panel" aria-label="Weather front visual timeline">
<div class="timeline-top">
<div class="stage-wrap">
<span id="stage-name">01 / Still Air</span>
<span id="stage-description">Open sky and distant high clouds.</span>
</div>
<span id="timecode">00:00 / 00:42</span>
</div>
<div class="timeline-controls">
<button id="play" type="button" aria-label="Pause timeline">Ⅱ</button>
<input id="timeline" type="range" min="0" max="1000" value="280" aria-label="Visual sequence timeline">
<select id="speed" aria-label="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="2">2×</option>
</select>
<button id="restart" type="button">Restart</button>
</div>
<div class="chapters">
<button class="chapter" type="button" data-time="0.08">Still air</button>
<button class="chapter" type="button" data-time="0.28">Cloud build</button>
<button class="chapter" type="button" data-time="0.50">Front enters</button>
<button class="chapter" type="button" data-time="0.62">Rain core</button>
<button class="chapter" type="button" data-time="0.88">Clearing east</button>
</div>
</section>
</div>
<div id="loading">Building the valley…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9fc8d8);
scene.fog = new THREE.Fog(0x9fc8d8, 55, 115);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const world = new THREE.Group();
scene.add(world);
const hemi = new THREE.HemisphereLight(0xd9f0f3, 0x5a6048, 1.65);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedc8, 2.3);
sun.position.set(-24, 36, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 38;
sun.shadow.camera.bottom = -38;
sun.shadow.camera.near = 2;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8eb6cc, 0.42);
fill.position.set(25, 14, -22);
scene.add(fill);
// Seeded randomness keeps the composition stable while scrubbing.
let randomSeed = 93721;
function random() {
randomSeed |= 0;
randomSeed = randomSeed + 0x6D2B79F5 | 0;
let t = Math.imul(randomSeed ^ randomSeed >>> 15, 1 | randomSeed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
const smooth = THREE.MathUtils.smoothstep;
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
}
const materials = {
road: standard(0x776f63),
roadEdge: standard(0x9a927b),
trunk: standard(0x66503a),
leafDark: standard(0x385943),
leafMid: standard(0x50764e),
leafLight: standard(0x668b55),
cropGreen: standard(0x71964d),
cropGold: standard(0xc7a34c),
soil: standard(0x8b6348),
stone: standard(0x777c72),
stoneLight: standard(0x92978d),
metal: standard(0x9ba6a4, { roughness: 0.65, metalness: 0.18 }),
barnTrim: standard(0xf0e6cc),
fence: standard(0xd6c49a),
hay: standard(0xd5ad4f),
black: standard(0x303735),
white: standard(0xe8e3d1)
};
const windowMaterial = standard(0xffd47d, {
emissive: 0xffa63c,
emissiveIntensity: 0.2,
roughness: 0.4
});
function addBox(parent, w, h, d, x, y, z, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function terrainHeight(x, z) {
const mainHill = 8.4 * Math.exp(
-Math.pow((x + 16) / 9.4, 2) -
Math.pow((z + 14) / 8.0, 2)
);
const shoulder = 2.1 * Math.exp(
-Math.pow((x - 7) / 13, 2) -
Math.pow((z + 19) / 5.7, 2)
);
return 0.32 + mainHill + shoulder;
}
// Voxel terrain.
const tileSize = 2;
const tileColumns = 32;
const tileRows = 28;
const terrainGeometry = new THREE.BoxGeometry(tileSize, 1, tileSize);
const terrainMaterial = standard(0xffffff);
const terrain = new THREE.InstancedMesh(
terrainGeometry,
terrainMaterial,
tileColumns * tileRows
);
terrain.receiveShadow = true;
terrain.castShadow = false;
const dummy = new THREE.Object3D();
const terrainColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < tileRows; row++) {
for (let col = 0; col < tileColumns; col++) {
const x = -31 + col * tileSize;
const z = -27 + row * tileSize;
const h = terrainHeight(x, z);
dummy.position.set(x, (h - 2) / 2, z);
dummy.scale.set(1, h + 2, 1);
dummy.updateMatrix();
terrain.setMatrixAt(tileIndex, dummy.matrix);
const variation = (random() - 0.5) * 0.07;
if (h > 2.4) {
terrainColor.setHSL(0.285 + variation, 0.27, 0.37 + variation);
} else if (x > 10 && z > 7) {
terrainColor.setHSL(0.15 + variation, 0.34, 0.43 + variation);
} else if (z < -16) {
terrainColor.setHSL(0.30 + variation, 0.25, 0.35 + variation);
} else {
terrainColor.setHSL(0.23 + variation, 0.31, 0.39 + variation);
}
terrain.setColorAt(tileIndex, terrainColor);
tileIndex++;
}
}
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
world.add(terrain);
addBox(
world,
190,
1,
190,
0,
-2.55,
0,
standard(0x66765a),
false,
true
);
// Roads and paths.
addBox(world, 55, 0.12, 2.35, -1, 0.45, 6, materials.road);
addBox(world, 2.35, 0.12, 28, 1, 0.46, 5, materials.road);
addBox(world, 13, 0.10, 1.7, 23, 0.45, 1.5, materials.road);
addBox(world, 10, 0.10, 1.6, -21, 0.45, 5, materials.road);
// A few road-edge stones.
for (let x = -25; x <= 24; x += 5) {
addBox(world, 0.25, 0.16, 0.28, x, 0.54, 4.65, materials.stoneLight, false);
addBox(world, 0.25, 0.16, 0.28, x + 1.5, 0.54, 7.35, materials.stoneLight, false);
}
function makeHouse(x, z, w, d, h, bodyColor, roofColor) {
const base = terrainHeight(x, z);
const bodyMat = standard(bodyColor);
const roofMat = standard(roofColor);
addBox(world, w, h, d, x, base + h / 2, z, bodyMat);
addBox(world, w + 0.22, 0.28, d + 0.22, x, base + 0.14, z, materials.stoneLight);
const roofStep = d / 3.1;
for (let layer = 0; layer < 4; layer++) {
const roofDepth = Math.max(0.55, d + 0.9 - layer * roofStep);
const roofY = base + h + 0.22 + layer * 0.39;
addBox(world, w + 0.9, 0.4, roofDepth, x, roofY, z, roofMat);
}
addBox(world, 0.72, 1.4, 0.12, x, base + 0.7, z + d / 2 + 0.04, materials.barnTrim);
addBox(world, 0.78, 0.12, 0.15, x, base + 1.37, z + d / 2 + 0.06, roofMat);
const windowY = base + h * 0.58;
const windowOffset = w * 0.27;
addBox(world, 0.68, 0.68, 0.1, x - windowOffset, windowY, z + d / 2 + 0.04, windowMaterial);
addBox(world, 0.68, 0.68, 0.1, x + windowOffset, windowY, z + d / 2 + 0.04, windowMaterial);
addBox(world, 0.12, 0.74, 0.14, x - windowOffset, windowY, z + d / 2 + 0.11, materials.barnTrim, false);
addBox(world, 0.74, 0.12, 0.14, x - windowOffset, windowY, z + d / 2 + 0.11, materials.barnTrim, false);
if (w > 3.5) {
addBox(world, 0.5, 1.4, 0.5, x + w * 0.27, base + h + 1.05, z - d * 0.18, materials.stone);
}
}
// Small town.
const houseColors = [0xc7b18a, 0xa9b9a3, 0xd0a27e, 0xb7c2b2, 0xc38e73, 0xd5c69f];
const roofColors = [0x5e5148, 0x765146, 0x46575a, 0x6d453e];
const townHouses = [
[-8.1, 1.3, 3.2, 3.3, 2.15],
[-3.5, 1.0, 3.7, 3.3, 2.35],
[1.8, 1.1, 3.2, 3.4, 2.10],
[6.4, 0.7, 3.5, 3.5, 2.30],
[-7.2, -5.3, 3.4, 3.2, 2.35],
[-2.8, -6.2, 3.8, 3.4, 2.55],
[2.1, -6.5, 3.4, 3.4, 2.25],
[6.7, -6.0, 3.6, 3.5, 2.45]
];
townHouses.forEach((house, index) => {
makeHouse(
house[0], house[1], house[2], house[3], house[4],
houseColors[index % houseColors.length],
roofColors[index % roofColors.length]
);
});
// Church.
{
const x = -11.2;
const z = -7.2;
const base = terrainHeight(x, z);
const cream = standard(0xd7cfaa);
const roof = standard(0x5e4e47);
addBox(world, 3.2, 3.8, 4.2, x, base + 1.9, z, cream);
addBox(world, 3.8, 0.42, 4.7, x, base + 3.85, z, roof);
addBox(world, 3.0, 0.42, 3.8, x, base + 4.18, z, roof);
addBox(world, 2.2, 0.42, 2.9, x, base + 4.51, z, roof);
addBox(world, 1.4, 5.5, 1.5, x, base + 2.75, z + 2.65, cream);
addBox(world, 1.8, 0.4, 1.8, x, base + 5.55, z + 2.65, roof);
addBox(world, 1.25, 0.4, 1.25, x, base + 5.9, z + 2.65, roof);
addBox(world, 0.18, 1.0, 0.18, x, base + 6.6, z + 2.65, roof);
addBox(world, 0.7, 0.18, 0.18, x, base + 6.85, z + 2.65, roof);
addBox(world, 0.65, 1.6, 0.12, x, base + 0.8, z + 2.11, materials.barnTrim);
}
// Town hall.
{
const x = 7.2;
const z = -12.1;
const base = terrainHeight(x, z);
addBox(world, 5.5, 3.6, 3.8, x, base + 1.8, z, standard(0xb77759));
addBox(world, 6.0, 0.4, 4.3, x, base + 3.65, z, standard(0x514b46));
addBox(world, 4.8, 0.4, 3.1, x, base + 3.95, z, standard(0x514b46));
addBox(world, 1.1, 2.1, 0.12, x, base + 1.05, z + 1.95, materials.barnTrim);
for (const dx of [-1.7, 1.7]) {
addBox(world, 0.7, 1.1, 0.12, x + dx, base + 2.1, z + 1.95, windowMaterial);
}
}
// Farm barn.
{
const x = 18;
const z = -6.4;
const base = terrainHeight(x, z);
const red = standard(0xa84d3c);
const darkRoof = standard(0x4f4842);
addBox(world, 6.6, 3.9, 4.5, x, base + 1.95, z, red);
addBox(world, 7.3, 0.42, 5.2, x, base + 3.95, z, darkRoof);
addBox(world, 6.0, 0.42, 3.8, x, base + 4.27, z, darkRoof);
addBox(world, 4.7, 0.42, 2.4, x, base + 4.59, z, darkRoof);
addBox(world, 2.6, 2.8, 0.15, x, base + 1.4, z + 2.3, materials.barnTrim);
addBox(world, 0.18, 2.8, 0.18, x, base + 1.4, z + 2.4, red);
addBox(world, 2.6, 0.18, 0.18, x, base + 1.4, z + 2.4, red);
for (let i = 0; i < 3; i++) {
addBox(world, 0.12, 3.9, 0.12, x - 3.34, base + 1.95, z - 1.2 + i * 1.2, materials.barnTrim, false);
}
}
// Voxel silo.
{
const x = 24.3;
const z = -7.1;
const base = terrainHeight(x, z);
addBox(world, 2.7, 3.8, 2.7, x, base + 1.9, z, materials.metal);
addBox(world, 2.35, 0.55, 2.35, x, base + 4.02, z, materials.metal);
addBox(world, 1.85, 0.55, 1.85, x, base + 4.57, z, materials.metal);
addBox(world, 1.3, 0.45, 1.3, x, base + 5.07, z, materials.metal);
addBox(world, 0.12, 4.2, 0.12, x + 1.39, base + 2.1, z, materials.stoneLight, false);
}
makeHouse(25.1, 0.4, 4.1, 3.5, 2.4, 0xd7c291, 0x665247);
function makeField(x, z, width, depth, cropMaterial) {
const base = terrainHeight(x, z);
addBox(world, width, 0.10, depth, x, base + 0.02, z, materials.soil, false);
const rowGap = 0.72;
const rows = Math.floor((depth - 0.45) / rowGap);
for (let i = 0; i < rows; i++) {
const rowZ = z - depth / 2 + 0.35 + i * rowGap;
addBox(world, width - 0.35, 0.22, 0.28, x, base + 0.19, rowZ, cropMaterial, false);
}
}
makeField(16.6, 10.3, 8.6, 4.3, materials.cropGold);
makeField(25.0, 10.6, 5.2, 4.4, materials.cropGreen);
makeField(-20.0, 11.0, 9.0, 4.8, materials.cropGreen);
makeField(-19.8, 3.8, 7.6, 3.6, materials.cropGold);
function makeFenceLine(x1, z1, x2, z2) {
const length = Math.hypot(x2 - x1, z2 - z1);
const count = Math.max(2, Math.round(length / 2.1));
for (let i = 0; i <= count; i++) {
const t = i / count;
const x = lerp(x1, x2, t);
const z = lerp(z1, z2, t);
const base = terrainHeight(x, z);
addBox(world, 0.16, 1.15, 0.16, x, base + 0.58, z, materials.fence);
}
const centerX = (x1 + x2) / 2;
const centerZ = (z1 + z2) / 2;
const base = terrainHeight(centerX, centerZ);
if (Math.abs(x2 - x1) > Math.abs(z2 - z1)) {
addBox(world, length, 0.13, 0.13, centerX, base + 0.63, z1, materials.fence, false);
addBox(world, length, 0.13, 0.13, centerX, base + 0.98, z1, materials.fence, false);
} else {
addBox(world, 0.13, 0.13, length, x1, base + 0.63, centerZ, materials.fence, false);
addBox(world, 0.13, 0.13, length, x1, base + 0.98, centerZ, materials.fence, false);
}
}
makeFenceLine(12.0, 7.8, 21.2, 7.8);
makeFenceLine(12.0, 12.8, 21.2, 12.8);
makeFenceLine(12.0, 7.8, 12.0, 12.8);
makeFenceLine(21.2, 7.8, 21.2, 12.8);
makeFenceLine(-24.5, 8.4, -15.5, 8.4);
makeFenceLine(-24.5, 13.6, -15.5, 13.6);
// Hay bales.
for (const [x, z] of [[13.0, -1.8], [14.0, -2.4], [22.7, -2.5]]) {
const base = terrainHeight(x, z);
addBox(world, 1.1, 0.85, 0.85, x, base + 0.43, z, materials.hay);
addBox(world, 0.16, 0.88, 0.88, x, base + 0.44, z, standard(0xb58d3c), false);
}
function makeTree(x, z, scale = 1) {
const base = terrainHeight(x, z);
const leaf = [materials.leafDark, materials.leafMid, materials.leafLight][
Math.floor(random() * 3)
];
addBox(world, 0.48 * scale, 1.8 * scale, 0.48 * scale,
x, base + 0.9 * scale, z, materials.trunk);
addBox(world, 2.25 * scale, 1.45 * scale, 2.0 * scale,
x, base + 2.05 * scale, z, leaf);
addBox(world, 1.75 * scale, 1.25 * scale, 1.65 * scale,
x + 0.08 * scale, base + 3.0 * scale, z - 0.05 * scale, leaf);
addBox(world, 1.05 * scale, 0.9 * scale, 1.05 * scale,
x - 0.04 * scale, base + 3.85 * scale, z, materials.leafLight);
}
const treeSpots = [
[-23, -7], [-21, -2], [-19, -21], [-14, -22], [-10, -18],
[-8, -23], [-25, -16], [-17, -5], [-27, 3], [-12, 14],
[-9, 17], [-25, 17], [11, -17], [14, -19], [27, -17],
[28, -11], [28, 16], [10, 17], [8, 15], [-2, 16]
];
treeSpots.forEach(([x, z]) => makeTree(x, z, 0.85 + random() * 0.35));
for (let i = 0; i < 25; i++) {
const x = -26 + random() * 17;
const z = -24 + random() * 13;
if (terrainHeight(x, z) > 1.2) {
makeTree(x, z, 0.55 + random() * 0.38);
}
}
// Hilltop stone outcrops.
for (let i = 0; i < 17; i++) {
const x = -22 + random() * 13;
const z = -20 + random() * 10;
const h = terrainHeight(x, z);
if (h > 2.5) {
const size = 0.45 + random() * 0.75;
addBox(world, size, size * 0.8, size, x, h + size * 0.35, z,
random() > 0.5 ? materials.stone : materials.stoneLight);
}
}
// Small voxel livestock near the farm.
function makeCow(x, z, flip = false) {
const base = terrainHeight(x, z);
const bodyMat = random() > 0.45 ? materials.white : materials.black;
addBox(world, 0.9, 0.52, 0.48, x, base + 0.62, z, bodyMat);
addBox(world, 0.36, 0.36, 0.34, x + 0.48, base + 0.77, z, bodyMat);
for (const dx of [-0.3, 0.3]) {
for (const dz of [-0.16, 0.16]) {
addBox(world, 0.11, 0.4, 0.11, x + dx, base + 0.22, z + dz, materials.black, false);
}
}
}
makeCow(25.7, 3.1);
makeCow(27.0, 4.1);
makeCow(22.8, 4.0);
// Voxel sun.
{
const sunGroup = new THREE.Group();
sunGroup.position.set(-25, 24, -38);
const sunMat = new THREE.MeshBasicMaterial({ color: 0xffd677 });
for (let x = -1; x <= 1; x++) {
for (let y = -1; y <= 1; y++) {
addBox(sunGroup, 1.05, 1.05, 0.35, x * 1.03, y * 1.03, 0, sunMat, false, false);
}
}
world.add(sunGroup);
}
// Cloud construction: clusters of opaque voxel blocks.
const cloudGeometry = new THREE.BoxGeometry(1, 1, 1);
const cloudWhite = new THREE.Color(0xf1f0e7);
const cloudStorm = new THREE.Color(0x71818a);
function makeCloud(scale = 1) {
const group = new THREE.Group();
const material = standard(0xf1f0e7, {
transparent: true,
opacity: 1,
depthWrite: false,
roughness: 1
});
for (let i = 0; i < 25; i++) {
const mesh = new THREE.Mesh(cloudGeometry, material);
const size = (1.2 + random() * 1.9) * scale;
mesh.position.set(
(random() - 0.5) * 7.8 * scale,
(random() - 0.5) * 1.8 * scale,
(random() - 0.5) * 3.2 * scale
);
mesh.scale.set(
size * (0.8 + random() * 0.45),
size * (0.55 + random() * 0.4),
size * (0.75 + random() * 0.4)
);
mesh.castShadow = false;
mesh.receiveShadow = false;
group.add(mesh);
}
group.userData.material = material;
return group;
}
const movingCloudA = makeCloud(1.15);
const movingCloudB = makeCloud(1.05);
const movingCloudC = makeCloud(0.92);
const movingCloudD = makeCloud(0.78);
world.add(movingCloudA, movingCloudB, movingCloudC, movingCloudD);
const distantClouds = [];
for (let i = 0; i < 4; i++) {
const cloud = makeCloud(0.55 + random() * 0.25);
cloud.position.set(-28 + i * 17, 18 + random() * 4, -25 - random() * 7);
cloud.userData.material.opacity = 0.32;
distantClouds.push(cloud);
world.add(cloud);
}
// The transparent moving front: a translucent volume and a voxel curtain.
const frontGroup = new THREE.Group();
world.add(frontGroup);
const frontVeilMaterial = new THREE.MeshBasicMaterial({
color: 0x8ba9b6,
transparent: true,
opacity: 0.055,
depthWrite: false,
side: THREE.DoubleSide
});
const frontVeil = new THREE.Mesh(
new THREE.BoxGeometry(5.4, 15.5, 48),
frontVeilMaterial
);
frontVeil.position.y = 8;
frontVeil.renderOrder = 1;
frontGroup.add(frontVeil);
const frontVoxelMaterial = new THREE.MeshBasicMaterial({
color: 0x8da8b3,
transparent: true,
opacity: 0.105,
depthWrite: false
});
const frontColumns = 33;
const frontRows = 11;
const frontVoxels = new THREE.InstancedMesh(
cloudGeometry,
frontVoxelMaterial,
frontColumns * frontRows
);
frontVoxels.instanceMatrix.setUsage(THREE.StaticDrawUsage);
frontVoxels.frustumCulled = false;
frontVoxels.renderOrder = 2;
const frontColor = new THREE.Color();
let frontIndex = 0;
for (let column = 0; column < frontColumns; column++) {
const columnHeight = 6 + Math.floor(random() * 5);
const z = (column - (frontColumns - 1) / 2) * 1.48;
for (let row = 0; row < frontRows; row++) {
dummy.position.set(
-0.2 - random() * 4.6,
0.65 + row * 1.22,
z + (random() - 0.5) * 0.12
);
if (row >= columnHeight) {
dummy.scale.set(0.001, 0.001, 0.001);
} else {
dummy.scale.set(
0.35 + random() * 0.38,
1.15 + random() * 0.15,
1.37 + random() * 0.12
);
}
dummy.updateMatrix();
frontVoxels.setMatrixAt(frontIndex, dummy.matrix);
frontColor.setHSL(0.54, 0.16, 0.53 + random() * 0.14);
frontVoxels.setColorAt(frontIndex, frontColor);
frontIndex++;
}
}
frontVoxels.instanceMatrix.needsUpdate = true;
frontVoxels.instanceColor.needsUpdate = true;
frontGroup.add(frontVoxels);
// Rain is drawn as animated line segments, using only core Three.js.
const MAX_RAIN = 760;
const rainPositions = new Float32Array(MAX_RAIN * 6);
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3).setUsage(THREE.DynamicDrawUsage)
);
const rainMaterial = new THREE.LineBasicMaterial({
color: 0xb9dbe7,
transparent: true,
opacity: 0.67,
depthWrite: false
});
const rain = new THREE.LineSegments(rainGeometry, rainMaterial);
rain.frustumCulled = false;
rain.renderOrder = 3;
world.add(rain);
const rainSeeds = Array.from({ length: MAX_RAIN }, () => ({
x: -16 + random() * 18,
z: -25 + random() * 50,
phase: random() * 19,
speed: 8 + random() * 7,
length: 0.65 + random() * 0.7
}));
// Timeline state.
const DURATION = 42;
let timeline = 0.28;
let playing = true;
let playbackSpeed = 1;
let scrubbing = false;
const timelineInput = document.querySelector("#timeline");
const playButton = document.querySelector("#play");
const restartButton = document.querySelector("#restart");
const speedSelect = document.querySelector("#speed");
const chapterButtons = [...document.querySelectorAll(".chapter")];
const stageName = document.querySelector("#stage-name");
const stageDescription = document.querySelector("#stage-description");
const timecode = document.querySelector("#timecode");
const cloudValue = document.querySelector("#cloud-value");
const rainValue = document.querySelector("#rain-value");
const cloudMeter = document.querySelector("#cloud-meter");
const rainMeter = document.querySelector("#rain-meter");
const frontValue = document.querySelector("#front-value");
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute("aria-label", playing ? "Pause timeline" : "Play timeline");
}
playButton.addEventListener("click", () => setPlaying(!playing));
restartButton.addEventListener("click", () => {
timeline = 0;
setPlaying(true);
});
speedSelect.addEventListener("change", () => {
playbackSpeed = Number(speedSelect.value);
});
timelineInput.addEventListener("pointerdown", () => {
scrubbing = true;
setPlaying(false);
});
window.addEventListener("pointerup", () => {
scrubbing = false;
});
timelineInput.addEventListener("input", () => {
timeline = Number(timelineInput.value) / 1000;
});
chapterButtons.forEach(button => {
button.addEventListener("click", () => {
timeline = Number(button.dataset.time);
setPlaying(false);
});
});
function formatTime(seconds) {
const whole = Math.max(0, Math.floor(seconds));
const minutes = Math.floor(whole / 60);
const remainder = String(whole % 60).padStart(2, "0");
return `${String(minutes).padStart(2, "0")}:${remainder}`;
}
let lastStage = -1;
function updateInterface(t, cloudiness, rainIntensity, frontX) {
const stage =
t < 0.18 ? 0 :
t < 0.40 ? 1 :
t < 0.60 ? 2 :
t < 0.80 ? 3 : 4;
const stages = [
["01 / Still Air", "Open sky and distant high clouds."],
["02 / Cloud Build", "Cloud banks gather ahead of the translucent front."],
["03 / Front Arrival", "The front crosses the fields and reaches the town."],
["04 / Rain Core", "Rain trails behind the leading edge."],
["05 / Clearing East", "The front moves away and the sky begins to open."]
];
if (stage !== lastStage) {
lastStage = stage;
stageName.textContent = stages[stage][0];
stageDescription.textContent = stages[stage][1];
chapterButtons.forEach((button, index) => {
button.classList.toggle("active", index === stage);
});
}
if (!scrubbing) {
timelineInput.value = String(Math.round(t * 1000));
}
timecode.textContent = `${formatTime(t * DURATION)} / ${formatTime(DURATION)}`;
const cloudPercent = Math.round(cloudiness * 100);
const rainPercent = Math.round(rainIntensity * 100);
cloudValue.textContent = `${cloudPercent}%`;
rainValue.textContent = `${rainPercent}%`;
cloudMeter.style.width = `${cloudPercent}%`;
rainMeter.style.width = `${rainPercent}%`;
if (frontX < -15) frontValue.textContent = "West";
else if (frontX < 5) frontValue.textContent = "Approaching";
else if (frontX < 18) frontValue.textContent = "Over town";
else frontValue.textContent = "East";
}
// Camera controls implemented directly, without examples or addons.
const controls = {
target: new THREE.Vector3(0, 3.0, 0),
desiredTarget: new THREE.Vector3(0, 3.0, 0),
yaw: 0.66,
desiredYaw: 0.66,
pitch: 0.62,
desiredPitch: 0.62,
distance: 58,
desiredDistance: 58
};
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
if (event.shiftKey || event.buttons === 2) {
const scale = controls.desiredDistance * 0.0014;
const rightX = Math.cos(controls.desiredYaw);
const rightZ = -Math.sin(controls.desiredYaw);
controls.desiredTarget.x -= dx * rightX * scale;
controls.desiredTarget.z -= dy * rightZ * scale;
} else {
controls.desiredYaw -= dx * 0.005;
controls.desiredPitch = clamp(
controls.desiredPitch + dy * 0.004,
0.24,
1.20
);
}
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const nextDistance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && nextDistance > 0) {
controls.desiredDistance = clamp(
controls.desiredDistance * pinchDistance / nextDistance,
28,
92
);
}
pinchDistance = nextDistance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.desiredDistance = clamp(
controls.desiredDistance + event.deltaY * 0.035,
28,
92
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
controls.desiredTarget.set(0, 3, 0);
controls.desiredYaw = 0.66;
controls.desiredPitch = 0.62;
controls.desiredDistance = 58;
});
function updateCamera(delta) {
const damping = 1 - Math.exp(-delta * 8);
controls.yaw = lerp(controls.yaw, controls.desiredYaw, damping);
controls.pitch = lerp(controls.pitch, controls.desiredPitch, damping);
controls.distance = lerp(controls.distance, controls.desiredDistance, damping);
controls.target.lerp(controls.desiredTarget, damping);
const horizontal = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
}
const clearSky = new THREE.Color(0x9fc8d8);
const stormSky = new THREE.Color(0x748692);
const clearingSky = new THREE.Color(0xa9cbd5);
const warmSun = new THREE.Color(0xffedc8);
const coolSun = new THREE.Color(0xb7cad2);
function updateWeather(t, elapsed) {
const approach = smooth(t, 0.18, 0.50);
const clearing = smooth(t, 0.76, 1.0);
const cloudiness = clamp(
smooth(t, 0.08, 0.40) * (1 - clearing * 0.55),
0,
1
);
const rainPeak = Math.exp(-Math.pow((t - 0.57) / 0.17, 2));
const rainIntensity = clamp(
(0.06 + approach * 0.12 + rainPeak * 0.82) * (1 - clearing),
0,
0.96
);
const frontX = -30 + t * 60;
frontGroup.position.x = frontX;
frontVeilMaterial.opacity = 0.028 + cloudiness * 0.045 + rainIntensity * 0.025;
frontVoxelMaterial.opacity = 0.055 + cloudiness * 0.045 + rainIntensity * 0.045;
movingCloudA.position.set(
frontX - 1.5 + Math.sin(elapsed * 0.12) * 0.7,
16.3 + Math.sin(elapsed * 0.08) * 0.15,
-7.2
);
movingCloudB.position.set(
frontX + 2.8 + Math.sin(elapsed * 0.09 + 1) * 0.6,
18.0,
4.6
);
movingCloudC.position.set(
frontX + 5.6 + Math.sin(elapsed * 0.10 + 2) * 0.8,
15.6,
-2.8
);
movingCloudD.position.set(
frontX - 7.0 + Math.sin(elapsed * 0.07) * 0.5,
13.8,
7.8
);
const cloudOpacities = [
0.08 + smooth(t, 0.05, 0.22) * 0.92,
smooth(t, 0.18, 0.39) * (1 - clearing * 0.7),
smooth(t, 0.31, 0.52) * (1 - clearing * 0.65),
smooth(t, 0.40, 0.59) * (1 - clearing * 0.78)
];
[movingCloudA, movingCloudB, movingCloudC, movingCloudD].forEach((cloud, index) => {
const opacity = clamp(cloudOpacities[index], 0, 1);
cloud.userData.material.opacity = opacity;
cloud.userData.material.color.copy(cloudWhite).lerp(
cloudStorm,
cloudiness * (0.45 + index * 0.08)
);
cloud.visible = opacity > 0.01;
});
distantClouds.forEach((cloud, index) => {
cloud.userData.material.opacity = 0.22 + cloudiness * 0.16;
cloud.userData.material.color.copy(cloudWhite).lerp(cloudStorm, cloudiness * 0.45);
cloud.position.x += 0.0025 * (index + 1);
if (cloud.position.x > 35) cloud.position.x = -35;
});
// Rain occupies the trailing side of the moving front.
const activeRain = Math.floor(MAX_RAIN * rainIntensity);
rainGeometry.setDrawRange(0, activeRain * 2);
rainMaterial.opacity = 0.30 + rainIntensity * 0.48;
for (let i = 0; i < activeRain; i++) {
const seed = rainSeeds[i];
const y = 19.5 - ((elapsed * seed.speed + seed.phase) % 19.5);
const x = frontX + seed.x + (19.5 - y) * 0.12;
const offset = i * 6;
rainPositions[offset] = x;
rainPositions[offset + 1] = y;
rainPositions[offset + 2] = seed.z;
rainPositions[offset + 3] = x - 0.25;
rainPositions[offset + 4] = y + seed.length;
rainPositions[offset + 5] = seed.z + 0.05;
}
rainGeometry.attributes.position.needsUpdate = true;
const skyMix = cloudiness * 0.82;
scene.background.copy(clearSky).lerp(stormSky, skyMix);
scene.background.lerp(clearingSky, clearing * 0.28);
scene.fog.color.copy(scene.background);
scene.fog.near = lerp(55, 30, cloudiness);
scene.fog.far = lerp(115, 66, cloudiness);
sun.intensity = lerp(2.3, 0.42, cloudiness * 0.65 + rainIntensity * 0.35);
sun.color.copy(warmSun).lerp(coolSun, cloudiness);
hemi.intensity = lerp(1.65, 0.82, cloudiness);
fill.intensity = lerp(0.42, 0.68, cloudiness);
windowMaterial.emissiveIntensity = 0.18 + rainIntensity * 1.15;
updateInterface(t, cloudiness, rainIntensity, frontX);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
let elapsed = 0;
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (playing && !scrubbing) {
timeline += delta * playbackSpeed / DURATION;
if (timeline >= 1) {
timeline = 1;
setPlaying(false);
}
}
updateCamera(delta);
updateWeather(timeline, elapsed);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("hidden"));
}
}
animate();
</script>
</body>
</html>
```