Prompt specification
Build or customize the Three.js 3D scene "Village paths across irrigated field strips" 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 paths across irrigated field strips
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/village-paths-across-irrigated-field-strips-x2367
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring irrigation in a medieval Japanese farming village. Build a compact referenced rural scene with homes, fields, footpaths, and channels. Preserve access to each field without forcing people through planted or flooded areas. Voxel style.
Working Three.js Starter (village-paths-across-irrigated-field-strips-x2367):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mizu no Mura — Irrigated Medieval Village</title>
<style>
:root {
color-scheme: dark;
--ink: #f2ead8;
--muted: #c8c0ae;
--panel: rgba(31, 38, 32, 0.88);
--border: rgba(238, 224, 190, 0.22);
--path: #d9b978;
--water: #65c5d1;
--crop: #83ad65;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9bca9;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 14px 40px rgba(20, 26, 20, 0.18);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
#title-card {
top: 22px;
left: 22px;
width: min(355px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 5px 17px 5px 5px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #d9c796;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: #c88b56;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 4vw, 34px);
font-weight: 500;
letter-spacing: 0.015em;
}
#title-card p {
margin: 8px 0 0;
max-width: 295px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#legend {
top: 22px;
right: 22px;
width: 214px;
padding: 14px 15px;
border-radius: 13px 5px 5px 5px;
pointer-events: none;
}
.legend-title {
margin-bottom: 10px;
color: #ead9ae;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
color: #e5dfd1;
font-size: 11px;
}
.swatch {
width: 17px;
height: 17px;
flex: 0 0 auto;
border: 1px solid rgba(255,255,255,0.18);
border-radius: 3px;
box-shadow: inset 0 -3px rgba(0,0,0,0.1);
}
.swatch.path { background: var(--path); }
.swatch.water { background: var(--water); }
.swatch.crop { background: var(--crop); }
.swatch.bridge { background: #956846; }
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--border);
color: #aeb7a7;
font-size: 10px;
line-height: 1.45;
}
#controls {
bottom: 20px;
left: 50%;
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
border-radius: 12px;
transform: translateX(-50%);
}
button {
appearance: none;
border: 1px solid rgba(240, 228, 199, 0.19);
border-radius: 7px;
padding: 9px 12px;
color: var(--ink);
background: rgba(244, 234, 207, 0.07);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
white-space: nowrap;
}
button:hover {
border-color: rgba(240, 228, 199, 0.4);
background: rgba(244, 234, 207, 0.14);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#hint {
padding: 0 8px 0 4px;
color: #b8beb0;
font-size: 10px;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: #eee5cf;
background: #879c84;
font-family: Georgia, serif;
font-size: 20px;
letter-spacing: 0.08em;
transition: opacity 450ms ease;
pointer-events: none;
}
#loading.hidden {
opacity: 0;
}
@media (max-width: 720px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#title-card p {
display: none;
}
#legend {
top: 102px;
right: 12px;
width: 174px;
padding: 11px 12px;
}
.legend-note {
display: none;
}
#controls {
bottom: 12px;
max-width: calc(100vw - 24px);
}
#hint {
display: none;
}
button {
padding: 9px 10px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional voxel village"></div>
<section id="title-card" class="panel">
<div class="eyebrow">Medieval Japan · 14th century</div>
<h1>Mizu no Mura</h1>
<p>
A compact farming village where timber homes, raised plots, and carefully
routed water channels remain connected by dry, continuous footpaths.
</p>
</section>
<aside id="legend" class="panel">
<div class="legend-title">Village Plan</div>
<div class="legend-row"><span class="swatch path"></span>Dry footpath</div>
<div class="legend-row"><span class="swatch water"></span>Irrigation channel</div>
<div class="legend-row"><span class="swatch crop"></span>Protected crop field</div>
<div class="legend-row"><span class="swatch bridge"></span>Dry timber crossing</div>
<div class="legend-note">
Every field has a gate-side approach. No route requires crossing crops
or standing in an irrigated plot.
</div>
</aside>
<nav id="controls" class="panel" aria-label="Scene controls">
<button id="reset-view" type="button" title="Reset the camera">Reset view</button>
<button id="top-view" type="button" title="Show the village plan">Plan view</button>
<button id="flow-toggle" type="button" title="Pause or resume the water">Pause water</button>
<span id="hint">Drag to orbit · Scroll to zoom · Arrow keys to rotate</span>
</nav>
<div id="loading">Preparing the village…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const mount = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9bca9);
scene.fog = new THREE.Fog(0xa9bca9, 48, 92);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemi = new THREE.HemisphereLight(0xd9e8df, 0x5b533e, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6ba, 3.15);
sun.position.set(-18, 30, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8fc3d5, 0.55);
fill.position.set(20, 12, -20);
scene.add(fill);
// Shared cube geometry keeps the voxel scene efficient.
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.94,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function box(w, h, d, color, x, y, z, parent = scene, options = {}) {
const mesh = new THREE.Mesh(
cubeGeometry,
options.material || material(color)
);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
if (options.rotationY) mesh.rotation.y = options.rotationY;
if (options.rotationX) mesh.rotation.x = options.rotationX;
if (options.rotationZ) mesh.rotation.z = options.rotationZ;
mesh.castShadow =
options.cast !== false && h > 0.09 && !options.transparent;
mesh.receiveShadow = options.receive !== false;
parent.add(mesh);
return mesh;
}
let seed = 13741;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x4ca9b8,
roughness: 0.26,
metalness: 0.08,
transparent: true,
opacity: 0.86
});
const glintMaterial = new THREE.MeshStandardMaterial({
color: 0xb8edf0,
roughness: 0.35,
transparent: true,
opacity: 0.72
});
const animatedGlints = [];
const animatedPeople = [];
// -------------------------------------------------------------------------
// Island terrain and distant voxel landscape
// -------------------------------------------------------------------------
box(36, 1.55, 28, 0x6b5037, 0, -0.84, 0, scene, { cast: false });
box(35.8, 0.3, 27.8, 0x718957, 0, -0.08, 0, scene, { cast: false });
// Exposed earth strata and irregular blocky edges.
box(36.05, 0.18, 27.95, 0x8a6745, 0, -0.52, 0, scene, { cast: false });
box(35.65, 0.16, 27.6, 0x594633, 0, -1.28, 0, scene, { cast: false });
const edgeSoil = [
[-17.7, -0.55, -8, 0.7, 0.9, 2.4],
[-17.7, -0.5, 4.5, 0.65, 1, 3.2],
[17.7, -0.55, -5, 0.7, 0.9, 2.7],
[17.7, -0.6, 7.5, 0.7, 0.8, 2.2],
[-11.5, -0.55, 13.7, 2.7, 0.9, 0.65],
[4.5, -0.55, 13.7, 3.4, 0.9, 0.65]
];
for (const [x, y, z, w, h, d] of edgeSoil) {
box(w, h, d, 0x76533a, x, y, z, scene, { cast: false });
}
// Subtle grass color patches.
for (let i = 0; i < 42; i++) {
const x = (random() - 0.5) * 34;
const z = (random() - 0.5) * 26;
const w = 0.4 + random() * 1.5;
const d = 0.4 + random() * 1.5;
const colors = [0x738b50, 0x81945c, 0x667d49];
box(w, 0.035, d, colors[i % colors.length], x, 0.087, z, scene, {
cast: false
});
}
// Large ground plane catches the diorama's soft shadow.
box(130, 0.3, 130, 0x84977d, 0, -1.78, 0, scene, { cast: false });
function voxelHill(x, z, sx, sy, sz, color) {
box(sx, sy, sz, color, x, -1.6 + sy / 2, z, scene, { cast: false });
box(sx * 0.72, sy * 0.52, sz * 0.7, color, x, -1.6 + sy + sy * 0.26, z, scene, {
cast: false
});
box(sx * 0.42, sy * 0.35, sz * 0.44, color, x, -1.6 + sy * 1.48, z, scene, {
cast: false
});
}
voxelHill(-22, -23, 13, 7, 9, 0x718579);
voxelHill(-7, -25, 16, 9, 10, 0x7c9182);
voxelHill(9, -24, 15, 7.5, 9, 0x6f8278);
voxelHill(23, -20, 13, 6, 9, 0x7f9183);
// A few cubic clouds.
const cloud = new THREE.Group();
scene.add(cloud);
box(5, 1.2, 2, 0xe7eadc, -13, 19, -25, cloud, { cast: false });
box(3.4, 1.8, 2.3, 0xf1efe3, -11.6, 19.8, -25, cloud, { cast: false });
box(7, 1.1, 2.1, 0xe9eade, 13, 22, -28, cloud, { cast: false });
box(3.5, 1.6, 2.2, 0xf0eee2, 15, 22.7, -28, cloud, { cast: false });
// -------------------------------------------------------------------------
// Dry, continuous route network
//
// Main paths run around the fields, never through planted or flooded soil.
// The two outer irrigation branches are crossed by raised timber bridges.
// -------------------------------------------------------------------------
const PATH = 0xd4b67c;
const PATH_EDGE = 0xb69a68;
function path(w, d, x, z) {
box(w, 0.08, d, PATH, x, 0.115, z, scene, { cast: false });
}
path(31.8, 1.42, 0.1, 2.35); // east-west village route
path(1.42, 22.0, -5.3, -0.35); // west internal route
path(1.42, 22.0, 5.3, -0.35); // east internal route
path(1.05, 21.8, -15.55, -0.35); // west perimeter
path(1.05, 21.8, 15.85, -0.35); // east perimeter
path(31.0, 1.18, 0, -11.25); // rear village route
path(11.2, 1.08, -0.2, -5.15); // house frontage
path(30.0, 1.1, 0, 12.05); // dry southern footpath
// Short gate approaches for the three southern fields.
for (const x of [-10, 0, 10]) {
path(1.15, 1.05, x, 3.12);
}
// Irregular path edging.
for (let i = 0; i < 30; i++) {
const x = -15 + random() * 30;
const z = 1.5 + (random() > 0.5 ? 0.72 : -0.72);
box(0.28 + random() * 0.25, 0.12, 0.18, PATH_EDGE, x, 0.12, z, scene, {
cast: false
});
}
// -------------------------------------------------------------------------
// Irrigation channels
// -------------------------------------------------------------------------
function channelVertical(x, z1, z2, width = 0.82) {
const length = z2 - z1;
const center = (z1 + z2) / 2;
box(width + 0.24, 0.13, length, 0x675d47, x, 0.09, center, scene, {
cast: false
});
box(width, 0.075, length, 0x4ca9b8, x, 0.19, center, scene, {
material: waterMaterial,
transparent: true,
cast: false
});
const count = Math.max(2, Math.floor(length / 1.25));
for (let i = 0; i < count; i++) {
const z = z1 + 0.55 + i * (length - 1.1) / Math.max(1, count - 1);
const glint = box(
0.44,
0.025,
0.08,
0xb8edf0,
x,
0.245,
z,
scene,
{ material: glintMaterial, transparent: true, cast: false }
);
animatedGlints.push({
mesh: glint,
axis: "z",
min: z1 + 0.35,
max: z2 - 0.35,
speed: 0.32 + random() * 0.2,
offset: random()
});
}
// Small blocky bank stones.
for (let z = z1 + 0.35; z < z2; z += 1.45) {
box(0.18, 0.18, 0.48, 0x8e8066, x - width / 2 - 0.16, 0.13, z, scene);
if (random() > 0.35) {
box(0.18, 0.18, 0.45, 0x9b8d72, x + width / 2 + 0.16, 0.13, z, scene);
}
}
}
function channelHorizontal(z, x1, x2, width = 0.82) {
const length = x2 - x1;
const center = (x1 + x2) / 2;
box(length, 0.13, width + 0.24, 0x675d47, center, 0.09, z, scene, {
cast: false
});
box(length, 0.075, width, 0x4ca9b8, center, 0.19, z, scene, {
material: waterMaterial,
transparent: true,
cast: false
});
const count = Math.max(3, Math.floor(length / 1.35));
for (let i = 0; i < count; i++) {
const x = x1 + 0.55 + i * (length - 1.1) / Math.max(1, count - 1);
const glint = box(
0.08,
0.025,
0.42,
0xb8edf0,
x,
0.245,
z,
scene,
{ material: glintMaterial, transparent: true, cast: false }
);
animatedGlints.push({
mesh: glint,
axis: "x",
min: x1 + 0.35,
max: x2 - 0.35,
speed: 0.28 + random() * 0.18,
offset: random()
});
}
for (let x = x1 + 0.35; x < x2; x += 1.5) {
box(0.5, 0.18, 0.18, 0x8e8066, x, 0.13, z - width / 2 - 0.16, scene);
if (random() > 0.4) {
box(0.46, 0.18, 0.18, 0x9b8d72, x, 0.13, z + width / 2 + 0.16, scene);
}
}
}
// Southern distribution channel and the branches beside field edges.
channelHorizontal(10.8, -14.15, 15.2);
channelVertical(-14.15, -4.0, 10.45);
channelVertical(-4.15, 3.7, 10.45);
channelVertical(4.15, 3.7, 10.45);
channelVertical(14.15, -4.0, 10.45);
// Main spring-fed channel on the eastern boundary.
channelVertical(15.2, -5.3, 10.45, 0.94);
box(2.4, 0.7, 1.4, 0x77766a, 15.2, 0.34, -5.7, scene);
box(1.2, 0.16, 1.05, 0x4ca9b8, 15.2, 0.74, -5.7, scene, {
material: waterMaterial,
transparent: true,
cast: false
});
// Raised dry crossings over the two outer branch channels.
function bridge(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(1.85, 0.15, 1.42, 0x805a3d, 0, 0.34, 0, group);
for (let i = -4; i <= 4; i++) {
box(0.18, 0.12, 1.45, i % 2 ? 0xa77b50 : 0x936844, i * 0.2, 0.46, 0, group);
}
for (const side of [-1, 1]) {
box(1.9, 0.12, 0.12, 0x644630, 0, 0.92, side * 0.68, group);
box(0.12, 0.55, 0.12, 0x644630, -0.78, 0.67, side * 0.68, group);
box(0.12, 0.55, 0.12, 0x644630, 0.78, 0.67, side * 0.68, group);
}
}
bridge(-14.15, 2.35);
bridge(14.15, 2.35);
// Wooden sluice gates controlling field inlets.
function sluice(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(0.15, 1.15, 0.18, 0x65462f, -0.55, 0.65, 0, group);
box(0.15, 1.15, 0.18, 0x65462f, 0.55, 0.65, 0, group);
box(1.25, 0.14, 0.18, 0x8c6540, 0, 1.15, 0, group);
box(0.88, 0.52, 0.11, 0x705036, 0, 0.68, 0, group);
box(0.09, 0.52, 0.13, 0x4e3828, 0, 0.68, 0, group);
}
sluice(-13.55, 5.1, Math.PI / 2);
sluice(-3.55, 7.0, Math.PI / 2);
sluice(3.55, 7.0, Math.PI / 2);
sluice(13.55, -0.8, Math.PI / 2);
// -------------------------------------------------------------------------
// Fields: protected crop plots with perimeter borders and gate approaches
// -------------------------------------------------------------------------
function fieldGate(x, z, north = true) {
const sign = north ? -1 : 1;
for (const side of [-1, 1]) {
box(0.13, 0.65, 0.13, 0x805b3d, x + side * 0.68, 0.43, z + sign * 0.05, scene);
}
box(0.08, 0.12, 0.08, 0xd7bc78, x + 0.72, 0.72, z + sign * 0.05, scene);
}
function createField(cx, cz, w, d, type) {
const isPaddy = type === "paddy";
const isCarrot = type === "carrot";
const borderColor = isPaddy ? 0x8c8066 : 0x76553a;
box(w, 0.22, d, isPaddy ? 0x53604a : 0x725038, cx, 0.19, cz, scene, {
cast: false
});
if (isPaddy) {
box(w - 0.32, 0.07, d - 0.32, 0x4ca9b8, cx, 0.33, cz, scene, {
material: waterMaterial,
transparent: true,
cast: false
});
} else {
const rowCount = 6;
for (let r = 0; r < rowCount; r++) {
const z = cz - d / 2 + 0.65 + r * (d - 1.3) / (rowCount - 1);
box(w - 0.5, 0.035, 0.22, 0x5b3d2b, cx, 0.32, z, scene, {
cast: false
});
}
}
// Borders clearly separate crop or water from the circulation network.
box(w + 0.16, 0.34, 0.18, borderColor, cx, 0.3, cz - d / 2, scene);
box(w + 0.16, 0.34, 0.18, borderColor, cx, 0.3, cz + d / 2, scene);
box(0.18, 0.34, d, borderColor, cx - w / 2, 0.3, cz, scene);
box(0.18, 0.34, d, borderColor, cx + w / 2, 0.3, cz, scene);
const rows = isPaddy ? 7 : 6;
const cols = isPaddy ? 10 : 8;
const innerW = w - 0.8;
const innerD = d - 0.8;
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
const x = cx - innerW / 2 + (c + 0.5) * innerW / cols;
const z = cz - innerD / 2 + (r + 0.5) * innerD / rows;
if (isPaddy) {
const height = 0.32 + random() * 0.16;
box(
0.13,
height,
0.13,
r % 2 ? 0x75904d : 0x92a85b,
x,
0.4 + height / 2,
z,
scene,
{ cast: false }
);
} else if (isCarrot) {
box(0.18, 0.28, 0.18, 0x4f7741, x, 0.47, z, scene, { cast: false });
box(0.11, 0.12, 0.11, 0xd78937, x, 0.37, z, scene, { cast: false });
} else {
const green = [0x668844, 0x789950, 0x587b42][(r + c) % 3];
box(0.18, 0.34, 0.18, green, x, 0.49, z, scene, { cast: false });
if ((r + c) % 2 === 0) {
box(0.1, 0.18, 0.28, 0x87a45b, x, 0.58, z, scene, { cast: false });
}
}
}
}
// Southern plots are reached from the central route on their south edge.
if (cz < 0) {
fieldGate(cx, cz + d / 2, false);
} else {
fieldGate(cx, cz - d / 2, true);
}
}
createField(-10, 6.5, 7, 6, "vegetables");
createField(0, 6.5, 7, 6, "paddy");
createField(10, 6.5, 7, 6, "paddy");
createField(-10, -0.4, 7, 5.2, "vegetables");
createField(10, -0.4, 7, 5.2, "carrots");
// -------------------------------------------------------------------------
// Medieval Japanese village architecture
// -------------------------------------------------------------------------
function createHouse(x, z, w, d, roofColor = 0x3f4a4b, thatch = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
// Stone plinth.
box(w + 0.35, 0.35, d + 0.35, 0x77766a, 0, 0.25, 0, group);
box(w + 0.1, 0.2, d + 0.1, 0x8e8876, 0, 0.47, 0, group);
// Plaster body.
box(w, 2.25, d, 0xd7c9a8, 0, 1.67, 0, group);
// Dark timber framing.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
0.18,
2.3,
0.18,
0x5c412c,
sx * (w / 2 - 0.08),
1.67,
sz * (d / 2 - 0.05),
group
);
}
}
for (const y of [0.76, 2.62]) {
box(w + 0.08, 0.15, d + 0.08, 0x5c412c, 0, y, 0, group);
}
// Front sliding doors.
const doorW = Math.min(1.45, w * 0.27);
for (const side of [-1, 1]) {
const dx = side * (w * 0.18);
box(doorW, 1.55, 0.09, 0x72513a, dx, 1.55, d / 2 + 0.055, group);
box(doorW - 0.14, 1.4, 0.025, 0xc4b998, dx, 1.55, d / 2 + 0.11, group);
for (let i = 0; i < 4; i++) {
box(0.045, 1.35, 0.035, 0x73563e, dx - doorW * 0.34 + i * doorW * 0.225, 1.55, d / 2 + 0.14, group);
}
for (let i = 0; i < 3; i++) {
box(doorW - 0.12, 0.04, 0.035, 0x73563e, dx, 1.08 + i * 0.42, d / 2 + 0.14, group);
}
}
// Shoji-style side windows.
for (const side of [-1, 1]) {
const wx = side * (w * 0.34);
box(1.12, 0.92, 0.08, 0xc9bd9c, wx, 1.85, d / 2 + 0.055, group);
for (let i = 0; i < 4; i++) {
box(0.035, 0.86, 0.035, 0x6b4c34, wx - 0.39 + i * 0.26, 1.85, d / 2 + 0.11, group);
}
for (let i = 0; i < 3; i++) {
box(1.02, 0.035, 0.035, 0x6b4c34, wx, 1.54 + i * 0.31, d / 2 + 0.11, group);
}
}
// Stepped voxel roof with deep eaves.
const stepDepth = d / 10;
const roofRise = thatch ? 0.32 : 0.3;
for (const side of [-1, 1]) {
for (let step = 0; step < 5; step++) {
const rz = side * (d / 2 - (step + 0.5) * stepDepth);
const ry = 2.73 + step * roofRise;
const roofShade = step % 2 === 0 ? roofColor : new THREE.Color(roofColor).offsetHSL(0, 0, 0.035).getHex();
box(
w + 1.12,
0.25,
stepDepth + 0.08,
roofShade,
0,
ry,
rz,
group
);
}
}
box(w + 1.38, 0.22, d + 0.12, roofColor, 0, 2.72, 0, group);
box(w + 1.2, 0.25, 0.46, roofColor, 0, 4.25, 0, group);
if (thatch) {
for (let i = 0; i < 10; i++) {
const rz = -d / 2 + (i + 0.5) * d / 10;
for (const side of [-1, 1]) {
box(
w + 0.86,
0.07,
0.08,
0xb9934f,
0,
2.93 + (4 - Math.abs(4.5 - (rz / stepDepth + 5))) * 0.27,
rz + side * 0.025,
group,
{ cast: false }
);
}
}
}
// Small porch and stone step.
box(w * 0.55, 0.16, 0.85, 0x785237, 0, 0.36, d / 2 + 0.4, group);
box(w * 0.47, 0.12, 0.45, 0x8b8877, 0, 0.21, d / 2 + 0.72, group);
return group;
}
createHouse(-12.3, -8.3, 4.8, 4.3, 0x3d494b);
createHouse(-7.65, -8.55, 3.6, 3.85, 0x805b36, true);
createHouse(0.15, -8.2, 5.1, 4.25, 0x414b4c);
// Raised rice storehouse.
function createStorehouse(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(0.28, 1.15, 0.28, 0x60442d, sx * 1.65, 0.73, sz * 1.1, group);
}
}
box(4, 0.28, 3, 0x765138, 0, 1.38, 0, group);
box(3.55, 2.1, 2.55, 0xbdab86, 0, 2.52, 0, group);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(0.16, 2.12, 0.16, 0x5f422c, sx * 1.69, 2.52, sz * 1.22, group);
}
}
box(1.15, 1.55, 0.1, 0x6e4c33, 0, 2.18, 1.31, group);
box(0.95, 0.07, 0.13, 0xb58d52, 0, 2.48, 1.37, group);
for (let i = 0; i < 5; i++) {
const zStep = -1.25 + i * 0.5;
box(4.7, 0.22, 0.55, i % 2 ? 0x454f4e : 0x3b4648, 0, 3.72 + i * 0.27, zStep, group);
box(4.7, 0.22, 0.55, i % 2 ? 0x454f4e : 0x3b4648, 0, 3.72 + i * 0.27, -zStep, group);
}
box(5.0, 0.23, 0.42, 0x343f41, 0, 5.15, 0, group);
box(1.5, 0.7, 0.12, 0xc8b996, 0, 2.65, 1.39, group);
}
createStorehouse(-12.0, -4.85);
// Vermilion village gate.
const torii = new THREE.Group();
torii.position.set(-5.3, 0, -5.35);
scene.add(torii);
for (const side of [-1, 1]) {
box(0.22, 2.75, 0.24, 0xa94932, side * 0.82, 1.52, 0, torii);
box(0.42, 0.25, 0.43, 0x4d4b3c, side * 0.82, 0.22, 0, torii);
}
box(2.25, 0.25, 0.32, 0xa94932, 0, 2.6, 0, torii);
box(2.62, 0.22, 0.42, 0x8d392a, 0, 2.98, 0, torii);
box(0.7, 0.28, 0.35, 0x493e32, 0, 2.46, 0, torii);
// -------------------------------------------------------------------------
// Village props: fences, stone lanterns, baskets, trees, and bamboo
// -------------------------------------------------------------------------
function fence(x1, x2, z, count) {
for (let i = 0; i < count; i++) {
const x = x1 + (x2 - x1) * i / (count - 1);
box(0.12, 0.95, 0.12, 0x6e5235, x, 0.58, z, scene);
}
box(x2 - x1 + 0.1, 0.1, 0.12, 0x76583a, (x1 + x2) / 2, 0.82, z, scene);
box(x2 - x1 + 0.1, 0.1, 0.12, 0x76583a, (x1 + x2) / 2, 0.46, z, scene);
}
fence(-15.3, -7.0, -10.95, 12);
fence(2.7, 4.8, -5.2, 4);
function stoneLantern(x, z) {
box(0.65, 0.22, 0.65, 0x767568, x, 0.2, z, scene);
box(0.28, 0.75, 0.28, 0x8c8979, x, 0.65, z, scene);
box(0.62, 0.18, 0.62, 0x8c8979, x, 1.08, z, scene);
box(0.48, 0.42, 0.48, 0xb6ad8c, x, 1.39, z, scene);
box(0.76, 0.18, 0.76, 0x6d7169, x, 1.68, z, scene);
box(0.3, 0.28, 0.3, 0x76786f, x, 1.89, z, scene);
}
stoneLantern(-6.55, -4.45);
stoneLantern(3.55, -5.0);
function basket(x, z, scale = 1) {
box(0.6 * scale, 0.42 * scale, 0.6 * scale, 0x9a7545, x, 0.34 * scale, z, scene);
box(0.68 * scale, 0.09 * scale, 0.68 * scale, 0x6e4e31, x, 0.57 * scale, z, scene);
box(0.35 * scale, 0.1 * scale, 0.08, 0x6e4e31, x, 0.66 * scale, z, scene);
}
basket(-3.25, -4.95, 0.8);
basket(-3.7, -5.1, 0.65);
basket(2.55, -5.15, 0.75);
function tree(x, z, scale = 1, autumn = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.44, 2.65, 0.44, 0x66503a, 0, 1.42, 0, group);
box(0.3, 1.05, 0.3, 0x66503a, 0.62, 2.38, 0, group, { rotationZ: -0.55 });
box(0.28, 0.95, 0.28, 0x66503a, -0.52, 2.5, 0.15, group, { rotationZ: 0.6 });
const leaf = autumn ? 0xb55f3f : 0x597943;
const lightLeaf = autumn ? 0xd18a4e : 0x718c4f;
box(2.3, 1.5, 2.0, leaf, 0, 3.25, 0, group);
box(1.8, 1.15, 1.7, lightLeaf, 0.7, 3.9, -0.25, group);
box(1.6, 1.1, 1.5, leaf, -0.8, 3.85, 0.35, group);
box(1.25, 0.85, 1.25, lightLeaf, 0.05, 4.55, 0.05, group);
}
tree(-16.0, -8.6, 1.05, true);
tree(-3.7, -10.0, 0.9, true);
tree(3.55, -9.8, 1.1, false);
tree(12.7, -8.7, 1.25, false);
tree(-16.1, -0.4, 0.9, false);
function bamboo(x, z) {
for (let i = 0; i < 7; i++) {
const bx = x + (random() - 0.5) * 1.7;
const bz = z + (random() - 0.5) * 1.5;
const height = 3.6 + random() * 1.8;
box(0.14, height, 0.14, 0x728c45, bx, height / 2, bz, scene);
for (let y = 0.6; y < height; y += 0.72) {
box(0.18, 0.07, 0.18, 0x95a65d, bx, y, bz, scene, { cast: false });
}
box(0.7, 0.12, 0.18, 0x688540, bx + 0.25, height * 0.78, bz, scene);
}
}
bamboo(12.6, -11.0);
bamboo(15.8, -9.0);
// -------------------------------------------------------------------------
// Irrigation wheel
// -------------------------------------------------------------------------
const wheel = new THREE.Group();
wheel.position.set(15.2, 1.35, -2.35);
scene.add(wheel);
box(1.5, 0.24, 0.24, 0x65462e, 0, 0, 0, wheel);
for (let i = 0; i < 10; i++) {
const a = i / 10 * Math.PI * 2;
const paddle = box(
0.86,
0.17,
0.42,
i % 2 ? 0x86613d : 0x755035,
0,
Math.cos(a) * 0.87,
Math.sin(a) * 0.87,
wheel
);
paddle.rotation.x = a;
}
box(1.9, 0.18, 0.18, 0x4f3927, 0, 0, 0, wheel);
// -------------------------------------------------------------------------
// Villagers standing only on paths
// -------------------------------------------------------------------------
function villager(x, z, shirt = 0x68735a, hat = true, facing = 0) {
const group = new THREE.Group();
group.position.set(x, 0.15, z);
group.rotation.y = facing;
scene.add(group);
box(0.18, 0.55, 0.2, 0x3f3930, -0.14, 0.28, 0, group);
box(0.18, 0.55, 0.2, 0x3f3930, 0.14, 0.28, 0, group);
box(0.5, 0.68, 0.3, shirt, 0, 0.84, 0, group);
box(0.16, 0.62, 0.18, shirt, -0.34, 0.83, 0, group);
box(0.16, 0.62, 0.18, shirt, 0.34, 0.83, 0, group);
box(0.31, 0.34, 0.31, 0xc59d72, 0, 1.37, 0, group);
box(0.34, 0.08, 0.34, 0x443b31, 0, 1.55, 0, group);
if (hat) {
box(0.65, 0.08, 0.65, 0xb59557, 0, 1.64, 0, group);
box(0.38, 0.25, 0.38, 0xa2844c, 0, 1.75, 0, group);
}
animatedPeople.push({ group, phase: random() * Math.PI * 2 });
return group;
}
villager(-4.9, -4.15, 0x6c7159, true, 0.25);
villager(-9.9, 3.08, 0x7c5b42, false, 0);
villager(3.1, 2.15, 0x536b70, true, -0.3);
villager(-12.5, -5.35, 0x74624a, false, 0.6);
// -------------------------------------------------------------------------
// Camera controls implemented directly without addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.65, 0),
yaw: 0.64,
pitch: 0.64,
distance: 39
};
function updateCamera() {
const cp = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * cp * cameraState.distance,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * cp * cameraState.distance
);
camera.lookAt(cameraState.target);
}
function resetCamera(plan = false) {
cameraState.yaw = 0.64;
cameraState.pitch = plan ? 1.32 : 0.64;
cameraState.distance = plan ? 43 : (window.innerWidth < 700 ? 49 : 39);
cameraState.target.set(0, 0.65, plan ? 0 : 0.1);
updateCamera();
}
const canvas = renderer.domElement;
const pointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.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);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const current = { x: event.clientX, y: event.clientY };
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.25,
1.38
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * (pinchDistance / distance),
16,
65
);
}
pinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
16,
65
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.yaw -= 0.08;
break;
case "ArrowRight":
cameraState.yaw += 0.08;
break;
case "ArrowUp":
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + 0.06, 0.25, 1.38);
break;
case "ArrowDown":
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch - 0.06, 0.25, 1.38);
break;
case "+":
case "=":
cameraState.distance = Math.max(16, cameraState.distance - 1.5);
break;
case "-":
cameraState.distance = Math.min(65, cameraState.distance + 1.5);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("reset-view").addEventListener("click", () => resetCamera());
document.getElementById("top-view").addEventListener("click", () => resetCamera(true));
let waterFlowing = true;
const flowButton = document.getElementById("flow-toggle");
flowButton.addEventListener("click", () => {
waterFlowing = !waterFlowing;
flowButton.textContent = waterFlowing ? "Pause water" : "Resume water";
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
if (waterFlowing) {
for (const glint of animatedGlints) {
const span = glint.max - glint.min;
const position = glint.min + ((elapsed * glint.speed + glint.offset * span) % span);
if (glint.axis === "x") {
glint.mesh.position.x = position;
} else {
glint.mesh.position.z = position;
}
glint.mesh.position.y = 0.247 + Math.sin(elapsed * 2.2 + glint.offset * 8) * 0.008;
}
wheel.rotation.x -= delta * 0.7;
}
for (const person of animatedPeople) {
person.group.position.y = 0.15 + Math.sin(elapsed * 1.6 + person.phase) * 0.012;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resetCamera();
updateCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => document.getElementById("loading").remove(), 600);
});
</script>
</body>
</html>
```