Prompt specification
Build or customize the Three.js 3D scene "Village pond through seasonal states" 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: Village pond through seasonal states
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/village-pond-through-seasonal-states-x1247
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts seasonal landscapes. Build a pond, deciduous trees, footbridge, and garden plots; transition vegetation and water appearance coherently while keeping all buildings and paths spatially fixed. Voxel style.
Working Three.js Starter (village-pond-through-seasonal-states-x1247):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Four Seasons — Voxel Valley</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(20, 29, 32, 0.78);
--border: rgba(255, 255, 255, 0.16);
--text: #f7f3e9;
--muted: rgba(247, 243, 233, 0.66);
--accent: #b9dc79;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9bcbd5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 18px 20px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
backdrop-filter: blur(14px);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.16);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 34px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.fixed-note {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
color: rgba(247, 243, 233, 0.78);
font-size: 10px;
}
.fixed-note::before {
width: 7px;
height: 7px;
content: "";
border-radius: 50%;
background: #a9d576;
box-shadow: 0 0 10px rgba(169, 213, 118, 0.65);
}
.controls {
position: fixed;
z-index: 20;
right: 22px;
bottom: 22px;
width: min(420px, calc(100vw - 44px));
padding: 15px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--border);
border-radius: 17px;
backdrop-filter: blur(14px);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
user-select: none;
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.season-readout {
min-width: 0;
}
#season-name {
display: block;
font-size: 17px;
font-weight: 750;
letter-spacing: -0.025em;
}
#season-detail {
display: block;
overflow: hidden;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
#auto-button {
flex: 0 0 auto;
padding: 8px 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.09);
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
#auto-button.active {
color: #24301e;
background: var(--accent);
border-color: var(--accent);
}
.season-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-bottom: 13px;
}
.season-button {
position: relative;
padding: 9px 5px 8px;
overflow: hidden;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.season-button::before {
position: absolute;
top: 0;
right: 0;
left: 0;
height: 3px;
content: "";
background: var(--swatch);
}
.season-button:hover {
background: rgba(255, 255, 255, 0.11);
transform: translateY(-1px);
}
.season-button.active {
background: rgba(255, 255, 255, 0.16);
border-color: rgba(255, 255, 255, 0.27);
}
.timeline {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
background: linear-gradient(
90deg,
#9bd2a0 0%,
#72bddf 25%,
#d78c49 50%,
#c7dce4 75%,
#9bd2a0 100%
);
border-radius: 99px;
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
background: #fff9e8;
border: 2px solid rgba(20, 29, 32, 0.7);
border-radius: 50%;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
background: #fff9e8;
border: 2px solid rgba(20, 29, 32, 0.7);
border-radius: 50%;
}
.camera-hint {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
padding: 9px 12px;
color: rgba(255, 255, 255, 0.78);
background: rgba(20, 29, 32, 0.55);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
backdrop-filter: blur(9px);
font-size: 10px;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: #f5f1e7;
background: #779b92;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
.fixed-note {
margin-top: 9px;
}
.controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the valley…</div>
<section class="title-card">
<div class="eyebrow">An interactive voxel landscape</div>
<h1>Four Seasons</h1>
<p class="subtitle">
Watch the pond, deciduous canopy, and garden plots change together
through the turning year.
</p>
<div class="fixed-note">Buildings, bridges, and paths remain spatially fixed</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<section class="controls" aria-label="Season controls">
<div class="control-top">
<div class="season-readout">
<span id="season-name">Spring</span>
<span id="season-detail">Fresh buds and clear water</span>
</div>
<button id="auto-button" class="active" type="button">Auto cycle</button>
</div>
<div class="season-buttons">
<button
class="season-button active"
style="--swatch:#9bd2a0"
data-season="0"
type="button"
>Spring</button>
<button
class="season-button"
style="--swatch:#72bddf"
data-season="1"
type="button"
>Summer</button>
<button
class="season-button"
style="--swatch:#d78c49"
data-season="2"
type="button"
>Autumn</button>
<button
class="season-button"
style="--swatch:#c7dce4"
data-season="3"
type="button"
>Winter</button>
</div>
<div class="timeline">
<span>Year</span>
<input
id="year-slider"
type="range"
min="0"
max="1000"
step="1"
value="0"
aria-label="Seasonal timeline"
>
<span>Cycle</span>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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.05;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaadce8);
scene.fog = new THREE.FogExp2(0xb7d8d1, 0.0115);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemisphere = new THREE.HemisphereLight(0xd9f1ff, 0x5a4934, 1.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d6, 1.5);
sun.position.set(-16, 25, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ebbd0, 0.45);
fill.position.set(18, 10, -18);
scene.add(fill);
// ------------------------------------------------------------
// Small helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const position = new THREE.Vector3();
const scratchColor = new THREE.Color();
const white = new THREE.Color(0xf4f8f8);
const soilBase = new THREE.Color(0x694331);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
...options
});
}
function addBox(parent, width, height, depth, x, y, z, material) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function hash(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
// ------------------------------------------------------------
// Seasonal keyframes
// ------------------------------------------------------------
const SEASONS = [
{
name: "Spring",
detail: "Fresh buds, blossoms, and clear water",
sky: 0xaadce8,
fog: 0xb7d8d1,
ground: 0x67984c,
foliage: 0x8acb62,
water: 0x63b0ae,
path: 0xc7b38e,
cloud: 0xf8ffff,
particle: 0xffb6c9,
sun: 0xfff1d6,
foliageOpacity: 0.64,
blossomOpacity: 1,
snow: 0,
light: 1.5,
particleOpacity: 0.65,
ripple: 0.35
},
{
name: "Summer",
detail: "Full canopy, green crops, and bright ripples",
sky: 0x72bde5,
fog: 0xa6cfd8,
ground: 0x4f803d,
foliage: 0x2f7d3d,
water: 0x2f8e9c,
path: 0xb9a37a,
cloud: 0xffffff,
particle: 0xffe28a,
sun: 0xfff4d2,
foliageOpacity: 1,
blossomOpacity: 0,
snow: 0,
light: 2,
particleOpacity: 0.35,
ripple: 0.55
},
{
name: "Autumn",
detail: "Amber leaves, harvest crops, and muted water",
sky: 0xe6b77d,
fog: 0xcaa176,
ground: 0x8a7145,
foliage: 0xd4772c,
water: 0x6f8e7d,
path: 0xa88f68,
cloud: 0xf4c092,
particle: 0xe47a36,
sun: 0xffc980,
foliageOpacity: 0.88,
blossomOpacity: 0,
snow: 0.18,
light: 1.45,
particleOpacity: 0.8,
ripple: 0.2
},
{
name: "Winter",
detail: "Bare trees, snowy gardens, and icy water",
sky: 0xc7dbe5,
fog: 0xd9e5ea,
ground: 0xe6eef0,
foliage: 0x7b654a,
water: 0x9bbdc7,
path: 0xd6d5cc,
cloud: 0xe7eef2,
particle: 0xffffff,
sun: 0xd9ecff,
foliageOpacity: 0,
blossomOpacity: 0,
snow: 1,
light: 1.05,
particleOpacity: 0.85,
ripple: 0.08
}
];
const state = {
sky: new THREE.Color(),
fog: new THREE.Color(),
ground: new THREE.Color(),
foliage: new THREE.Color(),
water: new THREE.Color(),
path: new THREE.Color(),
cloud: new THREE.Color(),
particle: new THREE.Color(),
sun: new THREE.Color(),
foliageOpacity: 1,
blossomOpacity: 0,
snow: 0,
light: 1.5,
particleOpacity: 0.5,
ripple: 0.3,
weights: [0, 0, 0, 0]
};
const colorProperties = [
"sky",
"fog",
"ground",
"foliage",
"water",
"path",
"cloud",
"particle",
"sun"
];
function sampleSeason(time) {
const wrapped = ((time % 1) + 1) % 1;
const phase = wrapped * 4;
const index = Math.min(3, Math.floor(phase));
const blend = phase - index;
const next = (index + 1) % 4;
for (const property of colorProperties) {
state[property].setHex(SEASONS[index][property]);
state[property].lerp(
scratchColor.setHex(SEASONS[next][property]),
blend
);
}
for (const property of [
"foliageOpacity",
"blossomOpacity",
"snow",
"light",
"particleOpacity",
"ripple"
]) {
state[property] = THREE.MathUtils.lerp(
SEASONS[index][property],
SEASONS[next][property],
blend
);
}
for (let season = 0; season < 4; season++) {
const first = index === season ? 1 - blend : 0;
const second = next === season ? blend : 0;
state.weights[season] = first + second;
}
}
// ------------------------------------------------------------
// Fixed path layout
// ------------------------------------------------------------
const pathCells = new Set();
function addPathLine(x1, z1, x2, z2) {
if (x1 === x2) {
const step = Math.sign(z2 - z1) || 1;
for (let z = z1; ; z += step) {
pathCells.add(`${x1},${z}`);
if (z === z2) break;
}
} else if (z1 === z2) {
const step = Math.sign(x2 - x1) || 1;
for (let x = x1; ; x += step) {
pathCells.add(`${x},${z1}`);
if (x === x2) break;
}
}
}
// All path geometry below is created once and never transformed.
addPathLine(-12, -8, -7, -8);
addPathLine(-7, -8, -7, 0);
addPathLine(7, 0, 7, 5);
addPathLine(7, 5, 15, 5);
addPathLine(15, 5, 15, -8);
addPathLine(15, -8, 17, -8);
addPathLine(17, -8, 17, -9);
addPathLine(7, 5, 7, 11);
addPathLine(11, 5, 11, 11);
const pathArray = [...pathCells].map((entry) => {
const [x, z] = entry.split(",").map(Number);
return { x, z };
});
function nearPath(x, z) {
for (const cell of pathArray) {
if (Math.abs(cell.x - x) < 0.55 && Math.abs(cell.z - z) < 0.55) {
return true;
}
}
return false;
}
// ------------------------------------------------------------
// Voxel terrain and pond
// ------------------------------------------------------------
const GRID = 42;
const terrainCells = [];
const waterCells = [];
const heightMap = new Map();
for (let ix = 0; ix < GRID; ix++) {
for (let iz = 0; iz < GRID; iz++) {
const x = ix - 20.5;
const z = iz - 20.5;
const ellipse = Math.sqrt(
(x * x) / (6.8 * 6.8) +
(z * z) / (4.5 * 4.5)
);
const noise = hash(ix, iz);
if (ellipse <= 1) {
waterCells.push({ x, z, noise });
continue;
}
const cottagePad =
Math.hypot(x + 12, z + 10) < 3.4;
const shedPad =
Math.hypot(x - 17, z + 11) < 2.6;
const gardenPad =
x > 6.3 && x < 15.3 && z > 4.2 && z < 13.2;
let height =
0.07 +
noise * 0.17 +
Math.max(0, ellipse - 1) * 0.15 +
Math.max(0, (Math.hypot(x, z) - 13) / 8) * 0.2;
if (nearPath(x, z) || cottagePad || shedPad || gardenPad) {
height = 0.05;
}
const cell = { x, z, height, noise };
terrainCells.push(cell);
heightMap.set(`${ix},${iz}`, height);
}
}
function heightAt(x, z) {
const ix = THREE.MathUtils.clamp(Math.round(x + 20.5), 0, GRID - 1);
const iz = THREE.MathUtils.clamp(Math.round(z + 20.5), 0, GRID - 1);
return heightMap.get(`${ix},${iz}`) ?? 0.1;
}
const earthMaterial = standardMaterial(0x554132);
addBox(scene, 43, 1.4, 43, 0, -1.9, 0, earthMaterial);
const terrainMaterial = standardMaterial(0xffffff);
const terrainMesh = new THREE.InstancedMesh(
unitBox,
terrainMaterial,
terrainCells.length
);
terrainMesh.receiveShadow = true;
terrainMesh.castShadow = false;
terrainCells.forEach((cell, index) => {
position.set(cell.x, -1.2 + cell.height / 2, cell.z);
scale.set(0.985, cell.height, 0.985);
matrix.compose(position, quaternion, scale);
terrainMesh.setMatrixAt(index, matrix);
});
terrainMesh.instanceMatrix.needsUpdate = true;
scene.add(terrainMesh);
const pathMaterial = standardMaterial(0xc7b38e, { roughness: 1 });
const pathMesh = new THREE.InstancedMesh(
unitBox,
pathMaterial,
pathArray.length
);
pathMesh.receiveShadow = true;
pathMesh.castShadow = true;
pathArray.forEach((cell, index) => {
position.set(cell.x, 0.1, cell.z);
scale.set(0.86, 0.12, 0.86);
matrix.compose(position, quaternion, scale);
pathMesh.setMatrixAt(index, matrix);
});
pathMesh.instanceMatrix.needsUpdate = true;
scene.add(pathMesh);
const waterMaterial = standardMaterial(0xffffff, {
roughness: 0.24,
metalness: 0.08,
transparent: true,
opacity: 0.9
});
const waterMesh = new THREE.InstancedMesh(
unitBox,
waterMaterial,
waterCells.length
);
waterMesh.receiveShadow = true;
waterMesh.castShadow = false;
waterCells.forEach((cell, index) => {
position.set(cell.x, 0.01, cell.z);
scale.set(0.985, 0.08, 0.985);
matrix.compose(position, quaternion, scale);
waterMesh.setMatrixAt(index, matrix);
});
waterMesh.instanceMatrix.needsUpdate = true;
scene.add(waterMesh);
const shoreMaterial = standardMaterial(0x777a70);
for (let i = 0; i < 34; i++) {
const angle = (i / 34) * Math.PI * 2;
const radius = 6.95 + Math.sin(i * 2.4) * 0.15;
const zRadius = 4.65 + Math.cos(i * 1.7) * 0.12;
const stoneSize = 0.35 + hash(i, 4) * 0.42;
addBox(
scene,
stoneSize,
0.22 + hash(i, 8) * 0.18,
stoneSize * 0.8,
Math.cos(angle) * radius,
0.12,
Math.sin(angle) * zRadius,
shoreMaterial
);
}
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xe9ffff,
transparent: true,
opacity: 0.35,
depthWrite: false
});
for (let i = 0; i < 22; i++) {
const x = (hash(i, 21) - 0.5) * 9;
const z = (hash(i, 35) - 0.5) * 5.6;
if ((x * x) / (6.1 * 6.1) + (z * z) / (3.8 * 3.8) < 1) {
const ripple = addBox(
scene,
0.35 + hash(i, 3) * 0.55,
0.025,
0.07,
x,
0.075,
z,
rippleMaterial
);
ripple.castShadow = false;
ripple.receiveShadow = false;
}
}
// ------------------------------------------------------------
// Footbridge — fixed geometry
// ------------------------------------------------------------
const bridge = new THREE.Group();
scene.add(bridge);
const woodMaterial = standardMaterial(0x79533a);
const bridgeDarkMaterial = standardMaterial(0x513d31);
const bridgeAccentMaterial = standardMaterial(0x9a6a45);
const plankWidth = 13.2 / 14;
for (let i = 0; i < 14; i++) {
addBox(
bridge,
plankWidth * 0.86,
0.18,
2.2,
-6.6 + (i + 0.5) * plankWidth,
0.52,
0,
i % 2 === 0 ? woodMaterial : bridgeAccentMaterial
);
}
for (const z of [-0.96, 0.96]) {
addBox(bridge, 13.5, 0.16, 0.16, 0, 1.58, z, bridgeDarkMaterial);
for (const x of [-6, -3, 0, 3, 6]) {
addBox(bridge, 0.2, 1.35, 0.2, x, 0.97, z, bridgeDarkMaterial);
}
}
for (const x of [-6, 0, 6]) {
for (const z of [-0.82, 0.82]) {
addBox(bridge, 0.22, 1.1, 0.22, x, 0.0, z, bridgeDarkMaterial);
}
}
// ------------------------------------------------------------
// Cottage and shed — fixed positions and transforms
// ------------------------------------------------------------
const wallMaterial = standardMaterial(0xe4d5b7);
const trimMaterial = standardMaterial(0x69483a);
const roofMaterial = standardMaterial(0x744b3f);
const doorMaterial = standardMaterial(0x4d7561);
const foundationMaterial = standardMaterial(0x777268);
const windowMaterial = standardMaterial(0xffdc87, {
roughness: 0.35,
emissive: 0xffb84d,
emissiveIntensity: 0.35
});
const snowMaterial = standardMaterial(0xf4f8f8, {
roughness: 0.95,
transparent: true,
opacity: 0,
depthWrite: false
});
const cottage = new THREE.Group();
cottage.position.set(-12, 0.05, -10);
scene.add(cottage);
addBox(cottage, 4.35, 0.28, 3.95, 0, 0.14, 0, foundationMaterial);
addBox(cottage, 4, 3, 3.6, 0, 1.5, 0, wallMaterial);
addBox(cottage, 0.82, 2.05, 0.13, 0, 1.05, 1.83, doorMaterial);
addBox(cottage, 0.12, 2.16, 0.16, 0, 1.08, 1.91, trimMaterial);
for (const x of [-1.25, 1.25]) {
addBox(cottage, 0.92, 0.9, 0.13, x, 1.72, 1.83, trimMaterial);
addBox(cottage, 0.7, 0.68, 0.14, x, 1.72, 1.91, windowMaterial);
addBox(cottage, 0.06, 0.7, 0.16, x, 1.72, 1.98, trimMaterial);
}
const cottageRoofSnow = new THREE.Group();
cottage.add(cottageRoofSnow);
for (let tier = 0; tier < 5; tier++) {
const roofWidth = 5.4 - tier * 1.0;
const roofDepth = 4.4 - tier * 0.65;
const roofY = 3.24 + tier * 0.4;
addBox(
cottage,
roofWidth,
0.48,
roofDepth,
0,
roofY,
0,
roofMaterial
);
addBox(
cottageRoofSnow,
roofWidth * 0.96,
0.075,
roofDepth * 0.96,
0,
roofY + 0.265,
0,
snowMaterial
);
}
addBox(cottage, 0.7, 1.8, 0.7, 1.15, 4.15, -0.55, trimMaterial);
const shed = new THREE.Group();
shed.position.set(17, 0.05, -11);
scene.add(shed);
addBox(shed, 3.1, 0.25, 2.85, 0, 0.125, 0, foundationMaterial);
addBox(shed, 2.8, 2.35, 2.5, 0, 1.18, 0, wallMaterial);
addBox(shed, 1.15, 1.75, 0.13, 0, 0.88, 1.28, doorMaterial);
const shedRoofSnow = new THREE.Group();
shed.add(shedRoofSnow);
for (let tier = 0; tier < 3; tier++) {
const roofWidth = 3.65 - tier * 0.95;
const roofDepth = 3.15 - tier * 0.78;
const roofY = 2.5 + tier * 0.38;
addBox(shed, roofWidth, 0.42, roofDepth, 0, roofY, 0, roofMaterial);
addBox(
shedRoofSnow,
roofWidth * 0.96,
0.07,
roofDepth * 0.96,
0,
roofY + 0.245,
0,
snowMaterial
);
}
// ------------------------------------------------------------
// Deciduous voxel trees
// ------------------------------------------------------------
const trunkMaterial = standardMaterial(0x65442f);
const leafMaterial = standardMaterial(0x2f7d3d, {
transparent: true,
opacity: 1
});
const blossomMaterial = standardMaterial(0xf2b3c6, {
transparent: true,
opacity: 0,
depthWrite: false
});
const leafGroups = [];
const blossomGroups = [];
const treeSnowGroups = [];
const treePositions = [
[-15.5, -3.5, 1.05],
[-15, 3.5, 1.12],
[-12, 8.5, 0.92],
[-8, 12.5, 1.08],
[-2, 13.5, 0.9],
[4, 13, 1.1],
[18, 10.5, 1.0],
[17, 4.5, 1.12],
[18, -2.5, 0.95],
[10, -13, 1.08],
[2, -13.5, 0.92],
[-5, -13, 1.08],
[-16.5, -14, 0.95],
[-3.5, -7, 0.9],
[4, -8.5, 1.0]
];
for (const [x, z, treeScale] of treePositions) {
const tree = new THREE.Group();
tree.position.set(x, heightAt(x, z), z);
tree.scale.setScalar(treeScale);
scene.add(tree);
addBox(tree, 0.58, 3.2, 0.58, 0, 1.6, 0, trunkMaterial);
addBox(tree, 1.25, 0.34, 0.34, 0.35, 2.45, 0, trunkMaterial);
addBox(tree, 0.34, 0.34, 1.2, 0, 2.75, 0.3, trunkMaterial);
addBox(tree, 0.9, 0.3, 0.3, -0.35, 3.0, 0, trunkMaterial);
const leaves = new THREE.Group();
tree.add(leaves);
addBox(leaves, 1.9, 1.65, 1.8, -0.55, 3.35, -0.2, leafMaterial);
addBox(leaves, 1.8, 1.7, 1.75, 0.62, 3.48, 0.12, leafMaterial);
addBox(leaves, 1.95, 1.65, 1.9, 0.02, 4.35, 0, leafMaterial);
addBox(leaves, 1.65, 1.45, 1.55, -0.15, 3.35, 0.8, leafMaterial);
addBox(leaves, 1.75, 1.45, 1.6, 0, 3.2, -0.82, leafMaterial);
leafGroups.push(leaves);
const blossoms = new THREE.Group();
tree.add(blossoms);
addBox(blossoms, 0.18, 0.18, 0.18, -0.55, 4.18, -0.15, blossomMaterial);
addBox(blossoms, 0.17, 0.17, 0.17, 0.55, 4.3, 0.1, blossomMaterial);
addBox(blossoms, 0.16, 0.16, 0.16, 0.05, 5.15, 0, blossomMaterial);
addBox(blossoms, 0.16, 0.16, 0.16, -0.15, 4.05, 0.8, blossomMaterial);
blossomGroups.push(blossoms);
const snow = new THREE.Group();
tree.add(snow);
addBox(snow, 0.75, 0.12, 0.34, 0.05, 3.18, 0, snowMaterial);
addBox(snow, 0.34, 0.12, 0.75, 0, 3.04, 0.3, snowMaterial);
addBox(snow, 0.8, 0.12, 0.35, 0.35, 2.66, 0, snowMaterial);
treeSnowGroups.push(snow);
}
// ------------------------------------------------------------
// Garden plots and seasonal crops
// ------------------------------------------------------------
const gardenSoilMaterial = standardMaterial(0x694331);
const springCropMaterial = standardMaterial(0x75b94d, {
transparent: true,
opacity: 0,
depthWrite: false
});
const summerCropMaterial = standardMaterial(0x3d873f, {
transparent: true,
opacity: 0,
depthWrite: false
});
const summerFruitMaterial = standardMaterial(0xd84d3f, {
transparent: true,
opacity: 0,
depthWrite: false
});
const autumnCropMaterial = standardMaterial(0x9f6a2e, {
transparent: true,
opacity: 0,
depthWrite: false
});
const autumnFruitMaterial = standardMaterial(0xdf7c2d, {
transparent: true,
opacity: 0,
depthWrite: false
});
const winterCropMaterial = standardMaterial(0xf0f7f7, {
transparent: true,
opacity: 0,
depthWrite: false
});
const springCropGroups = [];
const summerCropGroups = [];
const summerFruitGroups = [];
const autumnCropGroups = [];
const autumnFruitGroups = [];
const winterCropGroups = [];
const bedPositions = [
[9, 7],
[13, 7],
[9, 9.5],
[13, 9.5],
[9, 12],
[13, 12]
];
for (const [x, z] of bedPositions) {
const bed = new THREE.Group();
bed.position.set(x, heightAt(x, z), z);
scene.add(bed);
addBox(bed, 2.4, 0.28, 1.7, 0, 0.14, 0, gardenSoilMaterial);
const spring = new THREE.Group();
const summer = new THREE.Group();
const summerFruit = new THREE.Group();
const autumn = new THREE.Group();
const autumnFruit = new THREE.Group();
const winter = new THREE.Group();
bed.add(spring, summer, summerFruit, autumn, autumnFruit, winter);
for (const plantX of [-0.72, 0, 0.72]) {
for (const plantZ of [-0.43, 0.43]) {
addBox(spring, 0.07, 0.42, 0.07, plantX, 0.49, plantZ, springCropMaterial);
addBox(spring, 0.26, 0.12, 0.26, plantX, 0.62, plantZ, springCropMaterial);
addBox(summer, 0.1, 1.05, 0.1, plantX, 0.8, plantZ, summerCropMaterial);
addBox(summer, 0.48, 0.15, 0.34, plantX - 0.12, 0.78, plantZ, summerCropMaterial);
addBox(summer, 0.38, 0.15, 0.42, plantX + 0.1, 1.16, plantZ, summerCropMaterial);
addBox(summerFruit, 0.22, 0.22, 0.22, plantX + 0.15, 0.68, plantZ + 0.08, summerFruitMaterial);
addBox(autumn, 0.08, 0.82, 0.08, plantX, 0.69, plantZ, autumnCropMaterial);
addBox(autumnFruit, 0.38, 0.32, 0.38, plantX, 0.46, plantZ, autumnFruitMaterial);
addBox(winter, 0.58, 0.16, 0.48, plantX, 0.37, plantZ, winterCropMaterial);
}
}
springCropGroups.push(spring);
summerCropGroups.push(summer);
summerFruitGroups.push(summerFruit);
autumnCropGroups.push(autumn);
autumnFruitGroups.push(autumnFruit);
winterCropGroups.push(winter);
}
// A small fixed garden fence.
const fenceMaterial = standardMaterial(0x826044);
for (const x of [6.3, 14.7]) {
for (let z = 4.5; z <= 13; z += 1.5) {
addBox(scene, 0.16, 0.9, 0.16, x, 0.5, z, fenceMaterial);
}
addBox(scene, 0.12, 0.12, 8.8, x, 0.72, 8.7, fenceMaterial);
addBox(scene, 0.12, 0.12, 8.8, x, 0.38, 8.7, fenceMaterial);
}
// ------------------------------------------------------------
// Voxel clouds
// ------------------------------------------------------------
const cloudMaterial = standardMaterial(0xf8ffff, {
transparent: true,
opacity: 0.82,
depthWrite: false
});
const cloudDefinitions = [
[-12, 11.5, -17, 1.25],
[8, 13, -19, 1.0],
[18, 10.5, 2, 0.8],
[-19, 12, 5, 0.9]
];
for (const [x, y, z, cloudScale] of cloudDefinitions) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(cloudScale);
scene.add(cloud);
addBox(cloud, 3.0, 0.8, 1.3, 0, 0, 0, cloudMaterial);
addBox(cloud, 1.8, 1.2, 1.5, -1.0, 0.45, 0, cloudMaterial);
addBox(cloud, 1.7, 1.0, 1.4, 1.0, 0.3, 0, cloudMaterial);
}
// ------------------------------------------------------------
// Seasonal weather voxels
// ------------------------------------------------------------
const particleMaterial = standardMaterial(0xffffff, {
transparent: true,
opacity: 0,
depthWrite: false
});
const particleCount = 52;
const weatherMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.11, 0.11, 0.11),
particleMaterial,
particleCount
);
weatherMesh.frustumCulled = false;
scene.add(weatherMesh);
const particles = Array.from({ length: particleCount }, (_, index) => ({
x: hash(index, 2) * 38 - 19,
z: hash(index, 5) * 38 - 19,
y: hash(index, 9) * 8,
phase: hash(index, 13) * Math.PI * 2,
speed: 0.45 + hash(index, 17) * 0.8
}));
// ------------------------------------------------------------
// Custom camera controls implemented without addons
// ------------------------------------------------------------
const orbit = {
yaw: 0.72,
pitch: 0.93,
radius: 31,
targetRadius: 31,
dragging: false,
pointerX: 0,
pointerY: 0
};
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const deltaX = event.clientX - orbit.pointerX;
const deltaY = event.clientY - orbit.pointerY;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
orbit.yaw -= deltaX * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + deltaY * 0.0045,
0.48,
1.36
);
});
function stopDragging(event) {
orbit.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius * Math.exp(event.deltaY * 0.001),
18,
48
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
orbit.yaw = 0.72;
orbit.pitch = 0.93;
orbit.targetRadius = 31;
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbit.yaw += 0.08;
if (event.key === "ArrowRight") orbit.yaw -= 0.08;
if (event.key === "ArrowUp") orbit.pitch = Math.max(0.48, orbit.pitch - 0.05);
if (event.key === "ArrowDown") orbit.pitch = Math.min(1.36, orbit.pitch + 0.05);
if (event.key === "+" || event.key === "=") {
orbit.targetRadius = Math.max(18, orbit.targetRadius - 1);
}
if (event.key === "-") {
orbit.targetRadius = Math.min(48, orbit.targetRadius + 1);
}
});
function updateCamera(delta) {
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
orbit.targetRadius,
1 - Math.exp(-delta * 8)
);
const sinPitch = Math.sin(orbit.pitch);
const x = Math.sin(orbit.yaw) * sinPitch * orbit.radius;
const y = Math.cos(orbit.pitch) * orbit.radius + 1.1;
const z = Math.cos(orbit.yaw) * sinPitch * orbit.radius;
camera.position.set(x, y, z);
camera.lookAt(0, 1.1, 0);
}
// ------------------------------------------------------------
// UI and time controls
// ------------------------------------------------------------
const autoButton = document.querySelector("#auto-button");
const seasonName = document.querySelector("#season-name");
const seasonDetail = document.querySelector("#season-detail");
const seasonButtons = [...document.querySelectorAll(".season-button")];
const slider = document.querySelector("#year-slider");
let currentTime = 0;
let targetTime = 0;
let autoCycle = true;
let scrubbing = false;
function setAuto(value) {
autoCycle = value;
autoButton.classList.toggle("active", autoCycle);
autoButton.textContent = autoCycle ? "Auto cycle" : "Paused";
}
autoButton.addEventListener("click", () => {
setAuto(!autoCycle);
});
seasonButtons.forEach((button) => {
button.addEventListener("click", () => {
const destination = Number(button.dataset.season) / 4;
const currentWrapped = ((currentTime % 1) + 1) % 1;
let delta = (destination - currentWrapped + 1) % 1;
if (delta < 0.002) delta = 1;
targetTime = currentTime + delta;
setAuto(false);
});
});
slider.addEventListener("pointerdown", () => {
scrubbing = true;
setAuto(false);
});
window.addEventListener("pointerup", () => {
scrubbing = false;
});
slider.addEventListener("input", () => {
currentTime = Number(slider.value) / 1000;
targetTime = currentTime;
setAuto(false);
});
function updateInterface() {
const wrapped = ((currentTime % 1) + 1) % 1;
const nearest = Math.round(wrapped * 4) % 4;
seasonName.textContent = SEASONS[nearest].name;
seasonDetail.textContent = SEASONS[nearest].detail;
seasonButtons.forEach((button, index) => {
button.classList.toggle("active", index === nearest);
});
if (!scrubbing) {
slider.value = Math.round(wrapped * 1000);
}
}
// ------------------------------------------------------------
// Seasonal appearance updates
// ------------------------------------------------------------
const terrainColor = new THREE.Color();
const waterColor = new THREE.Color();
function updateSeason(delta, elapsed) {
if (autoCycle) {
currentTime = (currentTime + delta / 48) % 1;
} else {
const difference = targetTime - currentTime;
currentTime += difference * (1 - Math.exp(-delta * 1.7));
}
sampleSeason(currentTime);
scene.background.copy(state.sky);
scene.fog.color.copy(state.fog);
sun.color.copy(state.sun);
sun.intensity = state.light;
hemisphere.color.copy(state.sky);
pathMaterial.color.copy(state.path);
leafMaterial.color.copy(state.foliage);
leafMaterial.opacity = state.foliageOpacity;
blossomMaterial.opacity = state.blossomOpacity;
cloudMaterial.color.copy(state.cloud);
windowMaterial.emissiveIntensity = 0.25 + state.snow * 1.05;
snowMaterial.opacity = state.snow;
cottageRoofSnow.visible = state.snow > 0.01;
shedRoofSnow.visible = state.snow > 0.01;
for (const group of leafGroups) {
group.visible = state.foliageOpacity > 0.015;
}
for (const group of blossomGroups) {
group.visible = state.blossomOpacity > 0.015;
}
for (const group of treeSnowGroups) {
group.visible = state.snow > 0.01;
}
gardenSoilMaterial.color
.copy(soilBase)
.lerp(white, state.snow * 0.42);
springCropMaterial.opacity = state.weights[0];
summerCropMaterial.opacity = state.weights[1];
summerFruitMaterial.opacity = state.weights[1];
autumnCropMaterial.opacity = state.weights[2];
autumnFruitMaterial.opacity = state.weights[2];
winterCropMaterial.opacity = state.weights[3];
springCropGroups.forEach((group) => {
group.visible = state.weights[0] > 0.01;
});
summerCropGroups.forEach((group) => {
group.visible = state.weights[1] > 0.01;
});
summerFruitGroups.forEach((group) => {
group.visible = state.weights[1] > 0.01;
});
autumnCropGroups.forEach((group) => {
group.visible = state.weights[2] > 0.01;
});
autumnFruitGroups.forEach((group) => {
group.visible = state.weights[2] > 0.01;
});
winterCropGroups.forEach((group) => {
group.visible = state.weights[3] > 0.01;
});
terrainCells.forEach((cell, index) => {
terrainColor
.copy(state.ground)
.multiplyScalar(0.8 + cell.noise * 0.3);
if (state.snow > 0) {
terrainColor.lerp(
white,
Math.min(1, state.snow * (0.76 + cell.noise * 0.24))
);
}
terrainMesh.setColorAt(index, terrainColor);
});
terrainMesh.instanceColor.needsUpdate = true;
waterCells.forEach((cell, index) => {
waterColor
.copy(state.water)
.multiplyScalar(0.86 + cell.noise * 0.2);
waterMesh.setColorAt(index, waterColor);
});
waterMesh.instanceColor.needsUpdate = true;
rippleMaterial.opacity =
state.ripple * (0.85 + Math.sin(elapsed * 1.7) * 0.15);
particleMaterial.color.copy(state.particle);
particleMaterial.opacity = state.particleOpacity;
const wrapped = ((currentTime % 1) + 1) % 1;
const particleSeason = Math.round(wrapped * 4) % 4;
const motionSpeeds = [0.75, 0.22, 0.7, 0.43];
particles.forEach((particle, index) => {
const speed = motionSpeeds[particleSeason] * particle.speed;
const fall = (elapsed * speed + particle.y) % 8;
const sway = particleSeason === 1 ? 0.25 : 1.0;
position.set(
particle.x + Math.sin(elapsed * 1.25 + particle.phase) * sway,
0.35 + (8 - fall),
particle.z + Math.cos(elapsed * 0.9 + particle.phase) * sway * 0.55
);
const particleScale = particleSeason === 3 ? 1 : 0.82;
scale.setScalar(particleScale);
matrix.compose(position, quaternion, scale);
weatherMesh.setMatrixAt(index, matrix);
});
weatherMesh.instanceMatrix.needsUpdate = true;
updateInterface();
}
// ------------------------------------------------------------
// 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, 1.8));
});
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
updateSeason(delta, elapsed);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
const loading = document.querySelector("#loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
}
}
animate();
</script>
</body>
</html>
```