Prompt specification
Build or customize the Three.js 3D scene "House Slots and Shared Well Capacity" 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: House Slots and Shared Well Capacity
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/house-slots-and-shared-well-capacity-x3557
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring settlement population and infrastructure capacity. Model houses with occupant slots beside a well with finite supply markers. Show demand totals from the number of occupied slots under an explicit toy rule. Low-poly.
Working Three.js Starter (house-slots-and-shared-well-capacity-x3557):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dce5df" />
<title>Hollowmere — Settlement Capacity</title>
<style>
:root {
--ink: #24332f;
--muted: #67736d;
--paper: rgba(250, 248, 241, 0.92);
--paper-solid: #faf8f1;
--line: rgba(36, 51, 47, 0.14);
--orange: #ce6948;
--gold: #e2a84f;
--blue: #3c91a3;
--green: #477663;
--shadow: 0 14px 45px rgba(30, 48, 42, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #dce5df;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.62);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.intro {
top: 22px;
left: 22px;
width: 330px;
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(206, 105, 72, 0.12);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.metrics {
top: 22px;
right: 22px;
width: 306px;
padding: 17px;
border-radius: 18px;
}
.metrics-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--green);
font-size: 9px;
}
.live::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: #5f9b7f;
content: "";
}
.metric {
margin-top: 12px;
}
.metric-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
font-size: 12px;
}
.metric-label {
color: var(--muted);
}
.metric-value {
font-size: 17px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.bar {
height: 5px;
margin-top: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(36, 51, 47, 0.09);
}
.bar > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 280ms ease;
}
#populationBar {
background: var(--gold);
}
#reserveBar {
background: var(--blue);
}
.balance {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 16px;
padding: 11px 12px;
border: 1px solid rgba(206, 105, 72, 0.18);
border-radius: 11px;
color: #8d462e;
background: rgba(206, 105, 72, 0.08);
font-size: 11px;
}
.balance.good {
border-color: rgba(71, 118, 99, 0.2);
color: var(--green);
background: rgba(71, 118, 99, 0.08);
}
.balance strong {
font-size: 13px;
white-space: nowrap;
}
.rule {
bottom: 22px;
left: 22px;
width: 345px;
padding: 16px 18px;
border-radius: 16px;
}
.rule-label {
margin-bottom: 7px;
color: var(--orange);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.equation {
font-size: 14px;
line-height: 1.5;
}
.equation strong {
color: var(--orange);
}
.rule-note {
margin-top: 6px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.controls {
right: 22px;
bottom: 22px;
width: 306px;
padding: 14px;
border-radius: 16px;
}
.control-label {
margin: 0 2px 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.button-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.button-grid button,
.view-button {
min-height: 38px;
padding: 8px 10px;
border: 1px solid rgba(36, 51, 47, 0.13);
border-radius: 10px;
color: var(--ink);
background: rgba(255, 255, 255, 0.65);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
transform 120ms ease,
background 120ms ease,
opacity 120ms ease;
}
.button-grid button:hover,
.view-button:hover {
transform: translateY(-1px);
background: white;
}
.button-grid button:active,
.view-button:active {
transform: translateY(0);
}
.button-grid button:disabled {
cursor: default;
opacity: 0.38;
transform: none;
}
.button-grid .primary {
border-color: var(--ink);
color: white;
background: var(--ink);
}
.button-grid .primary:hover {
background: #354842;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px;
margin-top: 11px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.key {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
}
.key.occupied {
background: var(--gold);
}
.key.open {
border: 1px solid #829089;
background: transparent;
}
.key.water {
border-radius: 1px;
background: var(--blue);
transform: rotate(45deg);
}
.hint {
position: fixed;
z-index: 5;
bottom: 25px;
left: 50%;
padding: 8px 12px;
border-radius: 999px;
color: rgba(36, 51, 47, 0.72);
background: rgba(250, 248, 241, 0.64);
font-size: 10px;
font-weight: 650;
pointer-events: none;
transform: translateX(-50%);
white-space: nowrap;
}
#toast {
position: fixed;
z-index: 20;
top: 24px;
left: 50%;
max-width: min(390px, calc(100vw - 32px));
padding: 10px 15px;
border-radius: 999px;
color: white;
background: rgba(36, 51, 47, 0.92);
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -12px);
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #dce5df;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#loading.hidden {
display: none;
}
@media (max-width: 800px) {
.intro {
top: 12px;
left: 12px;
width: calc(100% - 24px);
padding: 14px 16px;
}
h1 {
font-size: 25px;
}
.subtitle {
display: none;
}
.metrics {
top: 112px;
right: 12px;
width: 238px;
padding: 13px;
}
.metric {
margin-top: 9px;
}
.rule {
bottom: 12px;
left: 12px;
width: calc(100% - 24px);
padding: 13px 15px;
}
.controls {
right: 12px;
bottom: 122px;
width: 238px;
padding: 11px;
}
.control-label,
.legend {
display: none;
}
.button-grid {
gap: 6px;
}
.button-grid button {
min-height: 34px;
padding: 6px;
font-size: 9px;
}
.hint {
display: none;
}
}
@media (max-width: 480px) {
.metrics {
top: 103px;
left: 12px;
right: 12px;
width: auto;
}
.controls {
top: 336px;
bottom: auto;
left: 12px;
right: 12px;
width: auto;
}
.rule {
font-size: 11px;
}
}
@media (prefers-reduced-motion: reduce) {
* {
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly settlement model"></div>
<header class="panel intro">
<div class="eyebrow">Field model 07 · Water capacity</div>
<h1>Hollowmere</h1>
<p class="subtitle">
A tiny settlement where occupied home slots create a daily water demand.
</p>
</header>
<section class="panel metrics" aria-label="Settlement statistics">
<div class="metrics-title">
<span>Settlement capacity</span>
<span class="live">Live model</span>
</div>
<div class="metric">
<div class="metric-head">
<span class="metric-label">Housing · 4 homes</span>
<span class="metric-value" id="capacityValue">9 / 16</span>
</div>
<div class="bar"><span id="populationBar"></span></div>
</div>
<div class="metric">
<div class="metric-head">
<span class="metric-label">Daily water demand</span>
<span class="metric-value" id="demandValue">18 units</span>
</div>
</div>
<div class="metric">
<div class="metric-head">
<span class="metric-label">Well reserve · max 12</span>
<span class="metric-value" id="reserveValue">12 / 12</span>
</div>
<div class="bar"><span id="reserveBar"></span></div>
</div>
<div class="balance" id="balance">
<span id="balanceLabel">Current coverage</span>
<strong id="balanceValue">Short 6 units</strong>
</div>
</section>
<section class="panel rule">
<div class="rule-label">Explicit toy rule</div>
<div class="equation" id="equation">
9 occupied slots × 2 units = <strong>18 units/day</strong>
</div>
<div class="rule-note" id="ruleNote">
Each occupied occupant slot requires two water units per day.
Empty slots add no demand.
</div>
</section>
<section class="panel controls">
<div class="control-label">Model controls</div>
<div class="button-grid">
<button id="addResident" type="button">+ Resident</button>
<button id="deliverWater" type="button">+ 4 water</button>
<button id="advanceDay" class="primary" type="button">Advance day</button>
<button id="resetModel" type="button">Reset model</button>
</div>
<div class="legend" aria-label="Scene legend">
<span><i class="key occupied"></i> Occupied slot</span>
<span><i class="key open"></i> Open slot</span>
<span><i class="key water"></i> Water unit</span>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Click a slot</div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="loading">Building settlement…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const MAX_RESERVE = 12;
const WATER_PER_OCCUPANT = 2;
const INITIAL_OCCUPANCY = [3, 2, 2, 2];
const state = {
occupancy: [...INITIAL_OCCUPANCY],
reserve: MAX_RESERVE,
day: 0,
lastUnmet: 0
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5df);
scene.fog = new THREE.Fog(0xdce5df, 19, 38);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional settlement with houses, occupant slots, and a well"
);
$("scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf6f3df, 0x65796c, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d4, 3.1);
sun.position.set(-7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d7df, 0.7);
fill.position.set(9, 7, -10);
scene.add(fill);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...extra
});
const palette = {
soil: material(0x71836b),
soilDark: material(0x586b58),
grass: material(0x93a887),
path: material(0xc7b995),
stone: material(0x8d9187),
stoneDark: material(0x606a63),
wood: material(0x785844),
cream: material(0xe8ddc1),
cream2: material(0xd9c7a4),
roof: material(0xb95f43),
roofDark: material(0x8f4937),
window: material(0x547d82, { roughness: 0.5 }),
dark: material(0x293a35),
gold: material(0xe0a047),
blue: material(0x3e9caf, {
emissive: 0x174c58,
emissiveIntensity: 0.3,
roughness: 0.48
}),
blueDark: material(0x42646a),
skin: material(0xd59d72),
leaf: material(0x547b5c),
leafLight: material(0x6f9267),
trunk: material(0x72513e)
};
function mesh(geometry, mat, x = 0, y = 0, z = 0, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, mat, x, y, z, parent = scene) {
return mesh(new THREE.BoxGeometry(w, h, d), mat, x, y, z, parent);
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(text, width = 3.1) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * (96 / 512), 1);
sprite.renderOrder = 20;
function setText(value) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 4, 8, 504, 80, 20);
ctx.fillStyle = "rgba(34, 50, 45, 0.91)";
ctx.fill();
ctx.fillStyle = "#fffaf0";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "700 31px system-ui, sans-serif";
ctx.fillText(value, 256, 49);
texture.needsUpdate = true;
}
setText(text);
return { sprite, setText };
}
// Low-poly island.
const island = mesh(
new THREE.CylinderGeometry(9.35, 9.9, 1.08, 14),
palette.soilDark,
0,
-0.58,
0
);
island.receiveShadow = true;
const ground = mesh(
new THREE.CylinderGeometry(9.28, 9.28, 0.18, 14),
palette.grass,
0,
-0.04,
0
);
ground.receiveShadow = true;
// Irregular stones around the perimeter.
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
const radius = 8.9 + Math.sin(i * 2.7) * 0.12;
const rock = mesh(
new THREE.DodecahedronGeometry(0.3 + (i % 3) * 0.035, 0),
i % 2 ? palette.stone : palette.stoneDark,
Math.cos(angle) * radius,
0.08,
Math.sin(angle) * radius
);
rock.scale.set(1.2, 0.6 + (i % 2) * 0.2, 0.9);
rock.rotation.set(i * 0.2, i * 0.7, i * 0.12);
}
const houseConfigs = [
{ name: "Alder", x: -5.1, z: 2.25, roof: 0xb95f43 },
{ name: "Birch", x: -3.25, z: -4.65, roof: 0xc27a45 },
{ name: "Cedar", x: 3.7, z: -4.15, roof: 0xa85442 },
{ name: "Dune", x: 5.25, z: 1.75, roof: 0xb96648 }
];
// Paths radiating from the well.
houseConfigs.forEach((house) => {
const length = 3.15;
const radius = 3.0;
const angle = Math.atan2(house.x, house.z);
const path = box(
0.68,
0.035,
length,
palette.path,
Math.sin(angle) * radius,
0.075,
Math.cos(angle) * radius
);
path.rotation.y = angle;
path.receiveShadow = true;
});
const slotPads = [];
const people = [];
const houseLabels = [];
function createHouse(config, index) {
const group = new THREE.Group();
group.position.set(config.x, 0.06, config.z);
group.rotation.y = Math.atan2(-config.x, -config.z);
scene.add(group);
box(2.62, 0.2, 2.35, palette.stone, 0, 0.13, 0, group);
box(2.3, 1.48, 2.0, index % 2 ? palette.cream : palette.cream2, 0, 0.97, 0, group);
// Simple pyramidal low-poly roof.
const roof = mesh(
new THREE.ConeGeometry(1.92, 1.13, 4),
material(config.roof),
0,
2.25,
0,
group
);
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.74;
// Door and windows on the inward-facing side.
box(0.46, 0.88, 0.075, palette.wood, 0, 0.61, 1.035, group);
box(0.055, 0.055, 0.095, palette.gold, 0.15, 0.6, 1.09, group);
box(0.43, 0.43, 0.07, palette.window, -0.68, 1.12, 1.035, group);
box(0.43, 0.43, 0.07, palette.window, 0.68, 1.12, 1.035, group);
box(0.055, 0.44, 0.08, palette.cream2, -0.68, 1.12, 1.078, group);
box(0.055, 0.44, 0.08, palette.cream2, 0.68, 1.12, 1.078, group);
box(0.3, 0.68, 0.3, palette.stoneDark, 0.62, 2.48, -0.38, group);
// Porch holds four visible occupant slots.
box(2.46, 0.12, 0.7, palette.wood, 0, 0.16, 1.25, group);
box(2.45, 0.13, 0.17, palette.cream2, 0, 0.34, 1.55, group);
for (let slot = 0; slot < 4; slot++) {
const padMaterial = material(0x6d7c72);
const pad = mesh(
new THREE.CylinderGeometry(0.22, 0.24, 0.065, 8),
padMaterial,
-0.75 + slot * 0.5,
0.245,
1.88,
group
);
pad.userData = {
type: "occupant-slot",
houseIndex: index,
slotIndex: slot
};
slotPads.push(pad);
const person = new THREE.Group();
person.position.set(-0.75 + slot * 0.5, 0.27, 1.88);
group.add(person);
mesh(
new THREE.CylinderGeometry(0.07, 0.1, 0.24, 6),
palette.gold,
0,
0.15,
0,
person
);
mesh(
new THREE.IcosahedronGeometry(0.095, 0),
palette.skin,
0,
0.34,
0,
person
);
person.visible = false;
people.push(person);
}
const label = makeLabel(`${config.name} · 0/4`, 2.7);
label.sprite.position.set(0, 3.12, 0);
group.add(label.sprite);
houseLabels.push(label);
}
houseConfigs.forEach(createHouse);
// Central low-poly well.
const well = new THREE.Group();
well.position.set(0, 0.06, 0);
scene.add(well);
mesh(
new THREE.CylinderGeometry(1.06, 1.14, 0.34, 10),
palette.stone,
0,
0.22,
0,
well
);
mesh(
new THREE.CylinderGeometry(0.7, 0.7, 0.08, 10),
palette.dark,
0,
0.41,
0,
well
);
mesh(
new THREE.CylinderGeometry(0.57, 0.57, 0.035, 10),
palette.blue,
0,
0.46,
0,
well
);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const stone = box(
0.29,
0.3,
0.25,
i % 2 ? palette.stone : palette.stoneDark,
Math.cos(angle) * 0.87,
0.52,
Math.sin(angle) * 0.87,
well
);
stone.rotation.y = -angle + 0.22;
}
box(0.16, 1.62, 0.16, palette.wood, -0.82, 1.22, 0, well);
box(0.16, 1.62, 0.16, palette.wood, 0.82, 1.22, 0, well);
box(1.86, 0.14, 0.14, palette.wood, 0, 1.92, 0, well);
const wellRoof = mesh(
new THREE.ConeGeometry(1.48, 0.72, 4),
palette.roofDark,
0,
2.25,
0,
well
);
wellRoof.rotation.y = Math.PI / 4;
wellRoof.scale.z = 0.78;
box(0.22, 0.25, 0.22, palette.wood, 0.45, 0.88, 0.2, well);
// Twelve finite supply markers: one blue diamond represents one unit.
const supplyMarkers = [];
for (let i = 0; i < MAX_RESERVE; i++) {
const angle = (i / MAX_RESERVE) * Math.PI * 2;
const radius = 1.72;
const socketMaterial = material(0x536b62);
const socket = mesh(
new THREE.CylinderGeometry(0.19, 0.22, 0.08, 6),
socketMaterial,
Math.cos(angle) * radius,
0.12,
Math.sin(angle) * radius,
well
);
const crystal = mesh(
new THREE.OctahedronGeometry(0.17, 0),
palette.blue,
Math.cos(angle) * radius,
0.34,
Math.sin(angle) * radius,
well
);
crystal.scale.y = 1.35;
supplyMarkers.push({ socket, crystal, socketMaterial });
}
const wellLabel = makeLabel("WELL · 12/12 UNITS", 3.1);
wellLabel.sprite.position.set(0, 3.0, 0);
well.add(wellLabel.sprite);
// Sparse low-poly landscaping.
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
group.scale.setScalar(scale);
scene.add(group);
mesh(
new THREE.CylinderGeometry(0.11, 0.16, 1.2, 6),
palette.trunk,
0,
0.6,
0,
group
);
mesh(
new THREE.ConeGeometry(0.68, 1.45, 7),
palette.leaf,
0,
1.45,
0,
group
);
mesh(
new THREE.ConeGeometry(0.48, 1.05, 7),
palette.leafLight,
0,
1.92,
0,
group
);
}
[
[-7.1, -2.7, 1.05],
[-6.4, 5.2, 0.9],
[6.9, -5.25, 1.1],
[7.05, 4.7, 0.88],
[0.25, 7.25, 1.0],
[-2.2, 6.75, 0.72]
].forEach((tree) => createTree(...tree));
// Small fence sections.
function createFence(x, z, rotation, count) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.rotation.y = rotation;
scene.add(group);
for (let i = 0; i < count; i++) {
box(0.1, 0.62, 0.1, palette.wood, i * 0.38, 0.31, 0, group);
}
box(count * 0.38, 0.09, 0.09, palette.wood, (count - 1) * 0.19, 0.45, 0, group);
}
createFence(-7.0, 0.0, 0.3, 5);
createFence(6.8, -2.6, -0.25, 5);
createFence(1.4, 7.1, 0.05, 5);
// Low-poly rocks and flowers.
for (let i = 0; i < 22; i++) {
const angle = i * 2.399;
const radius = 5.9 + (i % 5) * 0.55;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
if (Math.abs(x) < 1.4 && Math.abs(z) < 1.4) continue;
const flower = mesh(
new THREE.IcosahedronGeometry(0.08, 0),
i % 3 === 0 ? palette.gold : palette.cream,
x,
0.11,
z
);
flower.castShadow = false;
}
// Direct camera controls: no addons or legacy controls are used.
const cameraState = {
targetTheta: 0.72,
targetPhi: 0.91,
targetRadius: 21.5,
theta: 0.72,
phi: 0.91,
radius: 21.5,
target: new THREE.Vector3(0, 0.65, 0)
};
function updateCamera() {
cameraState.theta +=
(cameraState.targetTheta - cameraState.theta) * 0.09;
cameraState.phi +=
(cameraState.targetPhi - cameraState.phi) * 0.09;
cameraState.radius +=
(cameraState.targetRadius - cameraState.radius) * 0.09;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
function raycastSlot(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(slotPads, false);
return hits.length ? hits[0].object : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
cameraState.targetTheta -= dx * 0.006;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - dy * 0.005,
0.48,
1.34
);
previousX = event.clientX;
previousY = event.clientY;
} else {
renderer.domElement.style.cursor = raycastSlot(event) ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerDown) return;
pointerDown = false;
if (!pointerMoved) {
const slot = raycastSlot(event);
if (slot) toggleSlot(slot.userData.houseIndex, slot.userData.slotIndex);
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius + event.deltaY * 0.014,
12,
31
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.key === "ArrowLeft") cameraState.targetTheta += 0.12;
if (event.key === "ArrowRight") cameraState.targetTheta -= 0.12;
if (event.key === "ArrowUp") {
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - 0.08,
0.48,
1.34
);
}
if (event.key === "ArrowDown") {
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi + 0.08,
0.48,
1.34
);
}
if (event.key === "+" || event.key === "=") {
cameraState.targetRadius = Math.max(12, cameraState.targetRadius - 1);
}
if (event.key === "-") {
cameraState.targetRadius = Math.min(31, cameraState.targetRadius + 1);
}
});
function occupiedCount() {
return state.occupancy.reduce((sum, value) => sum + value, 0);
}
function dailyDemand() {
return occupiedCount() * WATER_PER_OCCUPANT;
}
function updateHouseVisuals() {
houseConfigs.forEach((config, houseIndex) => {
for (let slotIndex = 0; slotIndex < 4; slotIndex++) {
const padIndex = houseIndex * 4 + slotIndex;
const occupied = state.occupancy[houseIndex] > slotIndex;
people[padIndex].visible = occupied;
slotPads[padIndex].material.color.setHex(
occupied ? 0xe0a047 : 0x6d7c72
);
}
houseLabels[houseIndex].setText(
`${config.name} · ${state.occupancy[houseIndex]}/4`
);
});
}
function updateSupplyVisuals() {
supplyMarkers.forEach((marker, index) => {
const active = index < state.reserve;
marker.crystal.visible = active;
marker.socketMaterial.color.setHex(active ? 0x536b62 : 0x69746e);
});
wellLabel.setText(`WELL · ${state.reserve}/${MAX_RESERVE} UNITS`);
}
function refreshUI() {
const occupied = occupiedCount();
const demand = dailyDemand();
const shortage = Math.max(0, demand - state.reserve);
const surplus = Math.max(0, state.reserve - demand);
$("capacityValue").textContent = `${occupied} / 16`;
$("demandValue").textContent = `${demand} units`;
$("reserveValue").textContent = `${state.reserve} / ${MAX_RESERVE}`;
$("populationBar").style.width = `${(occupied / 16) * 100}%`;
$("reserveBar").style.width = `${(state.reserve / MAX_RESERVE) * 100}%`;
$("equation").innerHTML =
`${occupied} occupied slots × ${WATER_PER_OCCUPANT} units = ` +
`<strong>${demand} units/day</strong>`;
const balance = $("balance");
balance.classList.toggle("good", shortage === 0);
if (state.reserve === 0 && demand > 0) {
$("balanceLabel").textContent = "No reserve remaining";
$("balanceValue").textContent = `Short ${demand} units`;
} else if (shortage > 0) {
$("balanceLabel").textContent = "Current coverage";
$("balanceValue").textContent = `Short ${shortage} units`;
} else if (surplus > 0) {
$("balanceLabel").textContent = "Current coverage";
$("balanceValue").textContent = `${surplus} units spare`;
} else {
$("balanceLabel").textContent = "Current coverage";
$("balanceValue").textContent = "Exactly covered";
}
const delivered = Math.min(4, MAX_RESERVE - state.reserve);
const deliveredText = delivered
? `Deliver ${delivered} water units`
: "Reserve already full";
$("deliverWater").textContent = `+ ${deliveredText}`;
$("deliverWater").disabled = delivered === 0;
$("addResident").disabled = occupied >= 16;
if (state.lastUnmet > 0) {
$("ruleNote").textContent =
`Each occupied slot requires two water units per day. ` +
`Last day ended with ${state.lastUnmet} unmet units.`;
} else {
$("ruleNote").textContent =
`Each occupied slot requires two water units per day. ` +
`Empty slots add no demand.`;
}
updateHouseVisuals();
updateSupplyVisuals();
}
let toastTimer;
function toast(message) {
$("toast").textContent = message;
$("toast").classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
$("toast").classList.remove("show");
}, 2300);
}
function toggleSlot(houseIndex, slotIndex) {
if (state.occupancy[houseIndex] > slotIndex) {
state.occupancy[houseIndex]--;
toast(`${houseConfigs[houseIndex].name}: occupant slot opened.`);
} else {
if (occupiedCount() >= 16) {
toast("Housing capacity reached: 16 occupant slots.");
return;
}
state.occupancy[houseIndex]++;
toast(`${houseConfigs[houseIndex].name}: a resident moved in.`);
}
refreshUI();
}
$("addResident").addEventListener("click", () => {
const houseIndex = state.occupancy.findIndex((value) => value < 4);
if (houseIndex === -1) {
toast("Housing capacity reached: 16 occupant slots.");
return;
}
state.occupancy[houseIndex]++;
toast(`${houseConfigs[houseIndex].name}: a resident moved in.`);
refreshUI();
});
$("deliverWater").addEventListener("click", () => {
const delivered = Math.min(4, MAX_RESERVE - state.reserve);
if (delivered <= 0) {
toast("The well reserve is already at its finite maximum.");
return;
}
state.reserve += delivered;
toast(`${delivered} water units delivered to the well reserve.`);
refreshUI();
});
$("advanceDay").addEventListener("click", () => {
const demand = dailyDemand();
const served = Math.min(state.reserve, demand);
const unmet = demand - served;
state.reserve -= served;
state.lastUnmet = unmet;
state.day++;
if (demand === 0) {
toast(`Day ${state.day}: no occupied slots, so no water was used.`);
} else if (unmet === 0) {
toast(
`Day ${state.day}: ${served} units served. ` +
`${state.reserve} units remain.`
);
} else {
toast(
`Day ${state.day}: ${unmet} units unmet. ` +
`The well reserve is now ${state.reserve}.`
);
}
refreshUI();
});
$("resetModel").addEventListener("click", () => {
state.occupancy = [...INITIAL_OCCUPANCY];
state.reserve = MAX_RESERVE;
state.day = 0;
state.lastUnmet = 0;
cameraState.targetTheta = 0.72;
cameraState.targetPhi = 0.91;
cameraState.targetRadius = 21.5;
refreshUI();
toast("Settlement reset to its starting capacity.");
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
refreshUI();
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
if (!reducedMotion) {
supplyMarkers.forEach((marker, index) => {
if (!marker.crystal.visible) return;
marker.crystal.rotation.y = elapsed * 0.65 + index * 0.3;
marker.crystal.position.y =
0.34 + Math.sin(elapsed * 1.35 + index * 0.7) * 0.025;
});
people.forEach((person, index) => {
if (!person.visible) return;
person.position.y =
0.27 + Math.sin(elapsed * 1.6 + index * 0.8) * 0.012;
});
}
renderer.render(scene, camera);
}
animate();
$("loading").classList.add("hidden");
</script>
</body>
</html>
```