Prompt specification
Build or customize the Three.js 3D scene "Weather-dependent event planning game" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Weather-dependent event planning game
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/weather-dependent-event-planning-game-x3896
Scene Description Prompt:
Relocate low-poly park activities during fictional weather changes, respecting shelter capacity and keeping people and belongings together. Make one HTML with Three.js from cdnjs.
Working Three.js Starter (weather-dependent-event-planning-game-x3896):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ParkShift — Low-Poly Weather Dispatch</title>
<style>
:root {
--ink: #ecf8f4;
--muted: #9eb7b4;
--panel: rgba(15, 35, 40, 0.88);
--panel-soft: rgba(24, 49, 54, 0.78);
--line: rgba(207, 241, 231, 0.14);
--mint: #78e0b5;
--yellow: #ffd36b;
--coral: #ff897b;
--blue: #72c9ee;
--danger: #ff6f75;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9d7d9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 16px 45px rgba(11, 28, 33, 0.22);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.panel {
position: fixed;
z-index: 10;
border-radius: 18px;
overflow: hidden;
}
.panel-scroll {
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.panel-scroll::-webkit-scrollbar { width: 5px; }
.panel-scroll::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.18);
border-radius: 10px;
}
#brand {
position: fixed;
top: 16px;
left: 16px;
z-index: 12;
display: flex;
align-items: center;
gap: 11px;
padding: 10px 15px 10px 11px;
border-radius: 16px;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 12px;
color: #123b36;
background: linear-gradient(145deg, #a4f3cf, #65cda8);
font-size: 22px;
font-weight: 900;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.brand h1 {
margin: 0;
font-size: 16px;
line-height: 1.1;
letter-spacing: .02em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: .11em;
text-transform: uppercase;
}
#stats {
position: fixed;
top: 16px;
right: 16px;
z-index: 12;
display: flex;
gap: 2px;
padding: 8px;
border-radius: 16px;
}
.stat {
min-width: 92px;
padding: 5px 11px;
border-right: 1px solid var(--line);
}
.stat:last-child { border-right: 0; }
.stat small {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: .1em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 2px;
font-size: 16px;
}
#weatherPanel {
top: 88px;
left: 16px;
width: 286px;
padding: 15px;
}
.eyebrow {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.weather-main {
display: grid;
grid-template-columns: 49px 1fr;
gap: 12px;
align-items: center;
margin-top: 9px;
}
#weatherIcon {
width: 49px;
height: 49px;
display: grid;
place-items: center;
border-radius: 15px;
background: rgba(255, 211, 107, .14);
color: var(--yellow);
font-size: 29px;
}
#weatherName {
font-size: 20px;
line-height: 1.05;
font-weight: 800;
}
#weatherBlurb {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.weather-track {
height: 5px;
margin: 14px 0 6px;
overflow: hidden;
border-radius: 10px;
background: rgba(255,255,255,.08);
}
#weatherFill {
height: 100%;
width: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--mint), var(--yellow));
transition: width .12s linear;
}
.weather-meta {
display: flex;
justify-content: space-between;
gap: 10px;
color: var(--muted);
font-size: 10px;
}
#requirement {
color: var(--yellow);
font-weight: 700;
}
#requirement.danger { color: var(--coral); }
#requirement.safe { color: var(--mint); }
#forecast {
display: flex;
gap: 6px;
margin-top: 12px;
}
.forecast-chip {
flex: 1;
min-width: 0;
padding: 7px 4px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,.035);
text-align: center;
}
.forecast-chip span {
display: block;
font-size: 15px;
}
.forecast-chip small {
display: block;
margin-top: 3px;
overflow: hidden;
color: var(--muted);
font-size: 8px;
text-overflow: ellipsis;
white-space: nowrap;
}
#groupsPanel {
top: 316px;
left: 16px;
width: 286px;
max-height: calc(100vh - 415px);
padding: 13px 10px 10px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1px 5px 10px;
}
.panel-heading h2 {
margin: 0;
font-size: 12px;
letter-spacing: .03em;
}
.panel-heading span {
color: var(--muted);
font-size: 9px;
}
#groupList {
display: grid;
gap: 7px;
}
.group-row {
width: 100%;
display: grid;
grid-template-columns: 12px 1fr auto;
gap: 9px;
align-items: center;
padding: 10px;
color: var(--ink);
text-align: left;
border: 1px solid transparent;
border-radius: 12px;
background: rgba(255,255,255,.035);
cursor: pointer;
transition: background .15s, border .15s, transform .15s;
}
.group-row:hover {
background: rgba(255,255,255,.075);
transform: translateX(2px);
}
.group-row.selected {
border-color: rgba(120,224,181,.7);
background: rgba(120,224,181,.11);
}
.group-dot {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(255,255,255,.035);
}
.group-copy strong {
display: block;
font-size: 11px;
}
.group-copy small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.group-state {
max-width: 72px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
line-height: 1.25;
text-align: right;
text-transform: uppercase;
}
.group-state.safe { color: var(--mint); }
.group-state.risk { color: var(--coral); }
.exposure-track {
grid-column: 2 / 4;
height: 3px;
margin-top: 1px;
overflow: hidden;
border-radius: 8px;
background: rgba(255,255,255,.07);
}
.exposure-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--coral);
transition: width .15s linear;
}
#dispatchPanel {
top: 88px;
right: 16px;
width: 306px;
max-height: calc(100vh - 210px);
padding: 14px;
}
.dispatch-note {
margin: 8px 0 13px;
padding: 10px 11px;
color: #c9dfda;
border: 1px solid rgba(120,224,181,.18);
border-radius: 11px;
background: rgba(120,224,181,.065);
font-size: 10px;
line-height: 1.45;
}
#selectedName {
display: block;
margin: 2px 0 11px;
font-size: 16px;
}
#shelterList {
display: grid;
gap: 9px;
}
.shelter-card {
padding: 11px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255,255,255,.035);
}
.shelter-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.shelter-title strong { font-size: 12px; }
.best-tag {
padding: 3px 6px;
border-radius: 20px;
color: #123b36;
background: var(--mint);
font-size: 7px;
font-weight: 900;
letter-spacing: .07em;
text-transform: uppercase;
}
.capacity-row {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: var(--muted);
font-size: 9px;
}
.capacity-row strong { color: var(--ink); }
.capacity-track {
height: 5px;
margin-top: 5px;
overflow: hidden;
border-radius: 10px;
background: rgba(255,255,255,.08);
}
.capacity-fill {
height: 100%;
width: 0;
border-radius: inherit;
background: var(--blue);
transition: width .15s;
}
.capacity-fill.near { background: var(--yellow); }
.capacity-fill.full { background: var(--coral); }
.shelter-button {
width: 100%;
margin-top: 10px;
padding: 8px 9px;
color: var(--ink);
border: 1px solid rgba(120,224,181,.35);
border-radius: 9px;
background: rgba(120,224,181,.12);
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: background .15s, transform .15s;
}
.shelter-button:hover:not(:disabled) {
background: rgba(120,224,181,.24);
transform: translateY(-1px);
}
.shelter-button:disabled {
opacity: .35;
cursor: not-allowed;
}
.shelter-button.no-fit {
border-color: rgba(255,111,117,.25);
background: rgba(255,111,117,.08);
}
#dispatchBest {
width: 100%;
margin-top: 10px;
padding: 10px;
color: #123b36;
border: 0;
border-radius: 11px;
background: var(--mint);
font-size: 11px;
font-weight: 900;
cursor: pointer;
}
#dispatchBest:disabled {
opacity: .32;
cursor: not-allowed;
}
.protocol {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin-top: 12px;
}
.protocol div {
padding: 8px 4px;
border-radius: 9px;
background: rgba(255,255,255,.035);
color: var(--muted);
font-size: 8px;
text-align: center;
}
.protocol b {
display: block;
margin-bottom: 3px;
color: var(--ink);
font-size: 13px;
}
#bottomBar {
bottom: 16px;
left: 50%;
width: min(760px, calc(100vw - 32px));
padding: 10px 12px;
border-radius: 16px;
transform: translateX(-50%);
}
.bottom-row {
display: flex;
align-items: center;
gap: 8px;
}
.small-button {
padding: 8px 11px;
color: var(--ink);
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,.055);
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.small-button:hover { background: rgba(255,255,255,.11); }
.small-button.primary {
color: #133a36;
border-color: transparent;
background: var(--mint);
}
#timeline {
flex: 1;
display: flex;
align-items: center;
justify-content: space-around;
gap: 5px;
min-width: 0;
}
.timeline-node {
display: flex;
align-items: center;
gap: 5px;
color: var(--muted);
font-size: 9px;
}
.timeline-node b {
width: 23px;
height: 23px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
font-size: 12px;
}
.timeline-node.active { color: var(--ink); }
.timeline-node.active b {
color: #133a36;
border-color: transparent;
background: var(--mint);
box-shadow: 0 0 0 4px rgba(120,224,181,.09);
}
#cameraControls {
position: fixed;
right: 18px;
bottom: 108px;
z-index: 11;
display: flex;
gap: 5px;
}
#cameraControls button {
width: 34px;
height: 34px;
padding: 0;
color: var(--ink);
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel);
cursor: pointer;
}
#interactionHint {
position: fixed;
left: 18px;
bottom: 104px;
z-index: 9;
padding: 8px 11px;
border-radius: 10px;
color: rgba(240,255,250,.82);
background: rgba(15,35,40,.66);
font-size: 9px;
pointer-events: none;
}
#toast {
position: fixed;
top: 17px;
left: 50%;
z-index: 30;
max-width: min(420px, calc(100vw - 40px));
padding: 11px 16px;
border: 1px solid rgba(255,255,255,.16);
border-radius: 12px;
opacity: 0;
color: #fff;
background: rgba(18,42,47,.95);
box-shadow: 0 12px 35px rgba(0,0,0,.18);
font-size: 11px;
font-weight: 700;
text-align: center;
transform: translate(-50%, -12px);
transition: opacity .18s, transform .18s;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.error { border-color: rgba(255,111,117,.55); }
#toast.good { border-color: rgba(120,224,181,.55); }
#weatherWash {
position: fixed;
inset: 0;
z-index: 3;
opacity: 0;
pointer-events: none;
mix-blend-mode: soft-light;
}
#modal {
position: fixed;
inset: 0;
z-index: 50;
display: none;
place-items: center;
padding: 20px;
background: rgba(7,22,26,.54);
backdrop-filter: blur(7px);
}
#modal.show { display: grid; }
.modal-card {
width: min(430px, 100%);
padding: 27px;
border: 1px solid rgba(255,255,255,.18);
border-radius: 22px;
background: #17383d;
box-shadow: 0 25px 80px rgba(0,0,0,.35);
text-align: center;
}
.modal-symbol {
width: 64px;
height: 64px;
display: grid;
place-items: center;
margin: 0 auto 13px;
border-radius: 20px;
color: #143a35;
background: var(--mint);
font-size: 34px;
}
.modal-card h2 { margin: 0; font-size: 25px; }
.modal-card p {
margin: 10px 0 20px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.modal-actions {
display: flex;
justify-content: center;
gap: 8px;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: #123b36;
background: #a9d7d9;
font-size: 13px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
@media (max-width: 980px) {
#groupsPanel { max-height: calc(100vh - 400px); }
#dispatchPanel { width: 280px; }
#weatherPanel, #groupsPanel { width: 265px; }
.stat { min-width: 78px; }
.timeline-node span { display: none; }
}
@media (max-width: 760px) {
#brand p { display: none; }
#brand { padding-right: 10px; }
#stats { top: 70px; left: 10px; right: auto; }
#weatherPanel {
top: 70px;
left: 10px;
width: calc(100% - 20px);
}
#weatherBlurb { max-width: 260px; }
#groupsPanel {
top: 276px;
left: 10px;
width: calc(50% - 15px);
max-height: calc(100vh - 385px);
}
#dispatchPanel {
top: 276px;
right: 10px;
width: calc(50% - 15px);
max-height: calc(100vh - 385px);
}
.protocol { display: none; }
#interactionHint { display: none; }
#bottomBar { bottom: 10px; width: calc(100vw - 20px); }
#cameraControls { bottom: 89px; }
.timeline-node:nth-child(n+4) { display: none; }
}
@media (max-width: 520px) {
#stats { transform: scale(.88); transform-origin: top left; }
#weatherPanel { padding: 11px; }
#forecast { display: none; }
#groupsPanel, #dispatchPanel { top: 250px; }
.group-copy small { font-size: 8px; }
#timeline { display: none; }
#bottomBar { justify-content: center; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly park dispatch scene"></canvas>
<div id="weatherWash"></div>
<div id="brand" class="glass">
<div class="brand-mark">P</div>
<div>
<h1>ParkShift</h1>
<p>Weather dispatch for whole parties</p>
</div>
</div>
<div id="stats" class="glass">
<div class="stat">
<small>Sheltered</small>
<strong id="safeStat">0 / 16</strong>
</div>
<div class="stat">
<small>Comfort</small>
<strong id="comfortStat">100%</strong>
</div>
<div class="stat">
<small>Incidents</small>
<strong id="incidentStat">0</strong>
</div>
</div>
<section id="weatherPanel" class="panel glass">
<div class="eyebrow">Fictional forecast</div>
<div class="weather-main">
<div id="weatherIcon">☀</div>
<div>
<div id="weatherName">Sunspell</div>
<div id="weatherBlurb">Warm, harmless fictional sunshine.</div>
</div>
</div>
<div class="weather-track"><div id="weatherFill"></div></div>
<div class="weather-meta">
<span id="requirement" class="safe">No cover required</span>
<span id="weatherTimer">22s</span>
</div>
<div id="forecast"></div>
</section>
<section id="groupsPanel" class="panel glass panel-scroll">
<div class="panel-heading">
<h2>Activity parties</h2>
<span>SELECT A PARTY</span>
</div>
<div id="groupList"></div>
</section>
<section id="dispatchPanel" class="panel glass panel-scroll">
<div class="eyebrow">Dispatch desk</div>
<span id="selectedName">No party selected</span>
<div class="dispatch-note">
Select an activity party, then choose a pavilion. People and every
belonging travel together as one inseparable group.
</div>
<div id="shelterList"></div>
<button id="dispatchBest" disabled>Select a party first</button>
<div class="protocol">
<div><b>1</b>Select party</div>
<div><b>2</b>Check fit</div>
<div><b>3</b>Dispatch</div>
</div>
</section>
<div id="interactionHint">
Click a party, then a shelter · Drag to orbit · Right-drag to pan · Scroll to zoom
</div>
<div id="cameraControls">
<button id="zoomIn" title="Zoom in">+</button>
<button id="zoomOut" title="Zoom out">−</button>
<button id="resetView" title="Reset camera">⌂</button>
</div>
<div id="bottomBar" class="glass">
<div class="bottom-row">
<button id="pauseButton" class="small-button">Pause</button>
<button id="speedButton" class="small-button">1×</button>
<div id="timeline"></div>
<button id="shiftWeather" class="small-button primary">Shift weather</button>
<button id="resetScenario" class="small-button">Reset</button>
</div>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="modal">
<div class="modal-card">
<div class="modal-symbol">✓</div>
<h2 id="modalTitle">Park secured</h2>
<p id="modalText"></p>
<div class="modal-actions">
<button id="continueButton" class="small-button primary">Continue simulation</button>
<button id="newScenario" class="small-button">New scenario</button>
</div>
</div>
</div>
<div id="loading">Building the park…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Core scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9d7d9);
scene.fog = new THREE.Fog(0xa9d7d9, 48, 88);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
160
);
const cameraState = {
yaw: 0.68,
pitch: 0.72,
distance: 45,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
camera.position.set(
target.x + distance * Math.cos(pitch) * Math.sin(yaw),
target.y + distance * Math.sin(pitch),
target.z + distance * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xe7fbff, 0x718b56, 2.25);
scene.add(hemi);
const sunLight = new THREE.DirectionalLight(0xfff0cf, 2.55);
sunLight.position.set(-14, 25, 13);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -28;
sunLight.shadow.camera.right = 28;
sunLight.shadow.camera.top = 25;
sunLight.shadow.camera.bottom = -25;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 65;
sunLight.shadow.bias = -0.0005;
scene.add(sunLight);
const rimLight = new THREE.DirectionalLight(0xa7d8ff, 0.55);
rimLight.position.set(18, 10, -18);
scene.add(rimLight);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
flatShading: true,
...options
});
const mats = {
grass: material(0x8fbd72),
grassDark: material(0x78a95f),
path: material(0xdacfa9),
pathEdge: material(0xc8b98e),
wood: material(0x9a6543),
woodDark: material(0x70462f),
trunk: material(0x765039),
leafA: material(0x4f9869),
leafB: material(0x69a96d),
leafC: material(0x3f805f),
cream: material(0xf3ead3),
coral: material(0xf18f79),
teal: material(0x5eb4aa),
navy: material(0x34586d),
yellow: material(0xffd166),
pink: material(0xe9a3b5),
dark: material(0x263c42),
white: material(0xf4f7f2),
blue: material(0x70bce0),
gray: material(0x899da0),
red: material(0xe76f61)
};
function box(parent, width, height, depth, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, rTop, rBottom, height, segments, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeRoundedLabel(text, options = {}) {
const canvasLabel = document.createElement("canvas");
canvasLabel.width = 512;
canvasLabel.height = 128;
const ctx = canvasLabel.getContext("2d");
const texture = new THREE.CanvasTexture(canvasLabel);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(options.scale || 4.2, 1.05, 1);
sprite.renderOrder = 20;
function roundedRect(x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function setLabel(nextText, accent = options.accent || "#78e0b5") {
const key = nextText + "|" + accent;
if (sprite.userData.key === key) return;
sprite.userData.key = key;
ctx.clearRect(0, 0, 512, 128);
ctx.fillStyle = options.background || "rgba(16,43,47,.9)";
roundedRect(10, 12, 492, 104, 25);
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 4;
roundedRect(12, 14, 488, 100, 23);
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(28, 43, 9, 42, 5);
ctx.fill();
ctx.fillStyle = "#f1fbf7";
ctx.font = "700 31px system-ui, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(nextText, 55, 64, 425);
texture.needsUpdate = true;
}
setLabel(text);
return { sprite, setLabel };
}
// -------------------------------------------------------------------------
// Park environment
// -------------------------------------------------------------------------
const park = new THREE.Group();
scene.add(park);
box(park, 44, 0.6, 34, mats.grass, 0, -0.35, 0);
box(park, 44, 0.08, 3.2, mats.pathEdge, 0, -0.01, 2);
box(park, 3.2, 0.09, 34, mats.pathEdge, 0, 0, 0);
box(park, 44, 0.1, 3.1, mats.path, 0, 0.04, 2);
box(park, 3.1, 0.1, 34, mats.path, 0, 0.05, 0);
// Subtle grass patches.
for (let i = 0; i < 22; i++) {
const angle = i * 2.399;
const radius = 8 + (i % 6) * 2.4;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius * 0.62;
if (Math.abs(x) < 3 || Math.abs(z - 2) < 2.5) continue;
const patch = new THREE.Mesh(
new THREE.CircleGeometry(1.1 + (i % 3) * 0.28, 9),
mats.grassDark
);
patch.rotation.x = -Math.PI / 2;
patch.position.set(x, 0.015, z);
patch.scale.y = 0.45;
patch.receiveShadow = true;
park.add(patch);
}
// Pond.
const pond = new THREE.Mesh(
new THREE.CircleGeometry(3.1, 32),
material(0x66b9cf, { roughness: 0.28, metalness: 0.05 })
);
pond.rotation.x = -Math.PI / 2;
pond.position.set(-16.2, 0.08, 9.6);
pond.scale.set(1.2, 0.72, 1);
pond.receiveShadow = true;
park.add(pond);
const pondEdge = new THREE.Mesh(
new THREE.RingGeometry(3.05, 3.45, 32),
material(0xc7b886)
);
pondEdge.rotation.x = -Math.PI / 2;
pondEdge.position.set(-16.2, 0.09, 9.6);
pondEdge.scale.set(1.2, 0.72, 1);
park.add(pondEdge);
// Deterministic pseudo-random layout.
let randomSeed = 9147;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
cylinder(tree, 0.2, 0.28, 2.25, 7, mats.trunk, 0, 1.1, 0);
const foliageA = new THREE.Mesh(
new THREE.ConeGeometry(1.35, 2.7, 7),
random() > 0.5 ? mats.leafA : mats.leafB
);
foliageA.position.y = 3.15;
foliageA.castShadow = true;
tree.add(foliageA);
const foliageB = new THREE.Mesh(
new THREE.ConeGeometry(0.95, 2.1, 7),
random() > 0.5 ? mats.leafB : mats.leafC
);
foliageB.position.set(0.16, 4.05, -0.08);
foliageB.castShadow = true;
tree.add(foliageB);
park.add(tree);
}
const treePositions = [
[-20,-12,1.1],[-17,-13,.9],[-13,-14,1.15],[-7,-14,.95],
[4,-14,1.05],[8,-13,.9],[15,-14,1.2],[19,-11,1],
[20,-5,.95],[20,2,1.1],[19,10,1.15],[16,13,.9],
[8,14,1.05],[2,14,.92],[-5,14,1.15],[-12,14,1],
[-19,13,.95],[-20,5,1.05],[-20,-4,.92],[-6,-11,.7],
[5,-11,.72],[18,-2,.72]
];
treePositions.forEach(([x, z, s]) => addTree(x, z, s));
function addBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
box(bench, 2.5, .16, .62, mats.wood, 0, .72, 0);
box(bench, 2.5, .5, .12, mats.woodDark, 0, 1.18, -.27);
box(bench, .16, .72, .16, mats.woodDark, -.95, .35, 0);
box(bench, .16, .72, .16, mats.woodDark, .95, .35, 0);
box(bench, .16, .72, .16, mats.woodDark, -.95, 1.05, -.27);
box(bench, .16, .72, .16, mats.woodDark, .95, 1.05, -.27);
park.add(bench);
}
addBench(-8, 4, 0);
addBench(8, 4, 0);
addBench(16, 4, Math.PI / 2);
addBench(-18, 1, Math.PI / 2);
// Small flower clusters.
const flowerMaterials = [
material(0xffdf75),
material(0xf497aa),
material(0xf8f3e5),
material(0x9b8ee8)
];
for (let i = 0; i < 75; i++) {
const x = -20 + random() * 40;
const z = -15 + random() * 30;
if (Math.abs(x) < 2.3 || Math.abs(z - 2) < 2.1) continue;
if (x > -20 && x < -12 && z > 5 && z < 14) continue;
const flower = new THREE.Mesh(
new THREE.IcosahedronGeometry(.09 + random() * .06, 0),
flowerMaterials[i % flowerMaterials.length]
);
flower.position.set(x, .18, z);
park.add(flower);
}
// Activity site decorations. Belongings themselves remain with their party.
const picnicBlanket = box(
park, 5.3, .08, 3.7,
material(0xe68e78), -12, .11, -7
);
picnicBlanket.rotation.y = -.08;
for (let i = 0; i < 5; i++) {
const stripe = box(
park, .34, .02, 3.75,
i % 2 ? mats.cream : mats.coral,
-14 + i * 1.0, .16, -7
);
stripe.rotation.y = -.08;
}
const frisbeeRing = new THREE.Mesh(
new THREE.RingGeometry(2.2, 2.38, 32),
material(0xb7d892)
);
frisbeeRing.rotation.x = -Math.PI / 2;
frisbeeRing.position.set(0, .13, -8);
park.add(frisbeeRing);
const artPad = new THREE.Mesh(
new THREE.CircleGeometry(2.65, 18),
material(0xd2b9c9)
);
artPad.rotation.x = -Math.PI / 2;
artPad.position.set(11, .12, -7);
artPad.scale.set(1.2, .75, 1);
park.add(artPad);
const familyPad = new THREE.Mesh(
new THREE.RingGeometry(1.8, 2.0, 24),
material(0xe9d79e)
);
familyPad.rotation.x = -Math.PI / 2;
familyPad.position.set(15, .13, -1);
familyPad.scale.set(1.2, .8, 1);
park.add(familyPad);
// -------------------------------------------------------------------------
// Shelters
// -------------------------------------------------------------------------
const shelters = [
{
id: "A",
name: "Willow Pavilion",
x: -10,
z: 7,
capacity: 10,
gearCapacity: 3,
color: 0x64b8aa
},
{
id: "B",
name: "Kite Pavilion",
x: 10,
z: 7,
capacity: 8,
gearCapacity: 3,
color: 0xee927c
}
];
function createShelter(shelter) {
const root = new THREE.Group();
root.position.set(shelter.x, 0, shelter.z);
root.userData.shelterId = shelter.id;
scene.add(root);
const floor = box(
root, 8.5, .16, 6.3,
material(shelter.color, { roughness: .93 }),
0, .13, 0
);
floor.userData.shelterId = shelter.id;
const postMat = mats.woodDark;
[-3.55, 3.55].forEach(x => {
[-2.45, 2.45].forEach(z => {
const post = cylinder(root, .11, .14, 3.2, 7, postMat, x, 1.65, z);
post.userData.shelterId = shelter.id;
});
});
const roofMaterial = material(shelter.color, {
transparent: true,
opacity: .92,
side: THREE.DoubleSide
});
const roof = new THREE.Mesh(
new THREE.ConeGeometry(5.75, 1.65, 4),
roofMaterial
);
roof.position.y = 3.85;
roof.rotation.y = Math.PI / 4;
roof.scale.z = .79;
roof.castShadow = true;
roof.receiveShadow = true;
roof.userData.shelterId = shelter.id;
root.add(roof);
const trim = new THREE.Mesh(
new THREE.TorusGeometry(5.75, .09, 5, 4),
mats.cream
);
trim.position.y = 3.05;
trim.rotation.x = Math.PI / 2;
trim.rotation.z = Math.PI / 4;
trim.scale.y = .79;
root.add(trim);
const label = makeRoundedLabel(
`${shelter.id} · 0/${shelter.capacity}`,
{ accent: shelter.id === "A" ? "#78e0b5" : "#ff9b86", scale: 3.6 }
);
label.sprite.position.set(0, 5.15, 0);
label.sprite.userData.shelterId = shelter.id;
root.add(label.sprite);
shelter.root = root;
shelter.label = label;
}
shelters.forEach(createShelter);
// -------------------------------------------------------------------------
// Parties, people and belongings
// -------------------------------------------------------------------------
const groupDefinitions = [
{
id: "picnic",
name: "Picnic Club",
location: "North lawn",
people: 5,
gear: "Basket + cooler",
color: 0xf08c78,
position: new THREE.Vector3(-12, 0, -7),
targetOffset: new THREE.Vector3(-1.4, 0, 0)
},
{
id: "frisbee",
name: "Frisbee Circle",
location: "West field",
people: 4,
gear: "Discs + sports bag",
color: 0x63b7d6,
position: new THREE.Vector3(0, 0, -8),
targetOffset: new THREE.Vector3(1.4, 0, 0)
},
{
id: "art",
name: "Pocket Painters",
location: "East garden",
people: 3,
gear: "Easels + paint box",
color: 0xb18acb,
position: new THREE.Vector3(11, 0, -7),
targetOffset: new THREE.Vector3(-1.4, 0, 0)
},
{
id: "family",
name: "Riverside Family",
location: "Picnic path",
people: 4,
gear: "Wagon + sunhat",
color: 0xe7b84d,
position: new THREE.Vector3(15, 0, -1),
targetOffset: new THREE.Vector3(1.4, 0, 0)
}
];
const hairMaterials = [
material(0x3c2a24),
material(0x6d4932),
material(0x1f2527),
material(0xa86e42)
];
const skinMaterials = [
material(0xf0c39f),
material(0xc98d68),
material(0x8f5b43),
material(0xe4aa82)
];
function formation(count) {
if (count === 3) {
return [[-.85,-.42],[.55,-.42],[0,.65]];
}
if (count === 4) {
return [[-.95,-.55],[.35,-.55],[-.95,.65],[.55,.65]];
}
return [
[-1.08,-.55],[-.35,-.55],[.42,-.55],
[-.7,.68],[.35,.68]
];
}
function addPerson(root, position, color, index) {
const pivot = new THREE.Group();
pivot.position.set(position[0], 0, position[1]);
pivot.rotation.y = (index * 1.7) % (Math.PI * 2);
root.add(pivot);
const shirt = material(color);
const skin = skinMaterials[index % skinMaterials.length];
const hair = hairMaterials[(index + 1) % hairMaterials.length];
const trousers = index % 2 ? mats.navy : mats.dark;
const torso = cylinder(pivot, .19, .26, .58, 6, shirt, 0, .78, 0);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(.21, 1),
skin
);
head.position.y = 1.24;
head.castShadow = true;
pivot.add(head);
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(.215, 8, 5, 0, Math.PI * 2, 0, Math.PI * .52),
hair
);
hairCap.position.y = 1.28;
hairCap.rotation.z = (index % 3 - 1) * .08;
pivot.add(hairCap);
const leftLeg = box(pivot, .13, .46, .15, trousers, -.12, .27, 0);
const rightLeg = box(pivot, .13, .46, .15, trousers, .12, .27, 0);
leftLeg.castShadow = false;
rightLeg.castShadow = false;
const leftArm = cylinder(pivot, .07, .09, .48, 5, shirt, -.29, .79, 0);
const rightArm = cylinder(pivot, .07, .09, .48, 5, shirt, .29, .79, 0);
leftArm.rotation.z = -.16;
rightArm.rotation.z = .16;
pivot.userData.phase = index * .8;
pivot.userData.leftLeg = leftLeg;
pivot.userData.rightLeg = rightLeg;
return pivot;
}
function addGear(root, group) {
const gearRoot = new THREE.Group();
gearRoot.position.set(0, 0, 1.22);
root.add(gearRoot);
if (group.id === "picnic") {
box(gearRoot, .68, .42, .48, mats.wood, -.35, .25, 0);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(.2, .045, 5, 12, Math.PI),
mats.woodDark
);
handle.position.set(-.35, .47, 0);
gearRoot.add(handle);
box(gearRoot, .68, .38, .46, mats.blue, .38, .23, 0);
box(gearRoot, .7, .08, .48, mats.white, .38, .45, 0);
}
if (group.id === "frisbee") {
for (let i = 0; i < 3; i++) {
cylinder(
gearRoot, .28, .28, .055, 12,
i === 0 ? mats.coral : i === 1 ? mats.yellow : mats.blue,
-.28 + i * .28, .08 + i * .06, 0
);
}
box(gearRoot, .62, .35, .34, mats.navy, .35, .22, 0);
}
if (group.id === "art") {
const easel = new THREE.Group();
easel.position.x = -.25;
gearRoot.add(easel);
box(easel, .08, 1.25, .08, mats.wood, -.38, .62, 0);
box(easel, .08, 1.25, .08, mats.wood, .38, .62, 0);
box(easel, .08, 1.1, .08, mats.wood, 0, .55, .25);
box(easel, .92, .75, .07, mats.cream, 0, 1.02, .08);
box(easel, .22, .2, .28, mats.blue, .7, .16, 0);
const brush = cylinder(easel, .025, .025, .7, 5, mats.woodDark, .35, .35, 0);
brush.rotation.z = -.28;
}
if (group.id === "family") {
box(gearRoot, .9, .5, .62, mats.coral, -.25, .28, 0);
box(gearRoot, .94, .08, .65, mats.cream, -.25, .57, 0);
const wheelA = cylinder(gearRoot, .18, .18, .09, 10, mats.navy, -.5, .12, -.34);
const wheelB = cylinder(gearRoot, .18, .18, .09, 10, mats.navy, .02, .12, -.34);
wheelA.rotation.x = Math.PI / 2;
wheelB.rotation.x = Math.PI / 2;
cylinder(gearRoot, .42, .38, .07, 12, mats.yellow, .57, .09, 0);
cylinder(gearRoot, .12, .15, .25, 8, mats.yellow, .57, .21, 0);
}
}
const groups = groupDefinitions.map((definition, groupIndex) => {
const root = new THREE.Group();
root.position.copy(definition.position);
root.userData.groupId = definition.id;
scene.add(root);
const groupColor = new THREE.Color(definition.color);
const footprint = new THREE.Mesh(
new THREE.CircleGeometry(definition.people === 5 ? 1.75 : 1.5, 28),
new THREE.MeshBasicMaterial({
color: groupColor,
transparent: true,
opacity: .15,
depthWrite: false
})
);
footprint.rotation.x = -Math.PI / 2;
footprint.position.y = .19;
root.add(footprint);
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(definition.people === 5 ? 1.82 : 1.57, .045, 6, 36),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.position.y = .22;
selectionRing.visible = false;
root.add(selectionRing);
const positions = formation(definition.people);
const people = positions.map((position, index) =>
addPerson(root, position, definition.color, index + groupIndex)
);
addGear(root, definition);
const label = makeRoundedLabel(
`${definition.name} · ${definition.people}`,
{ accent: "#" + groupColor.getHexString(), scale: 3.5 }
);
label.sprite.position.set(0, 2.1, 0);
root.add(label.sprite);
return {
...definition,
root,
figures: people,
selectionRing,
label,
originalPosition: definition.position.clone(),
assignedShelter: null,
arrivedShelter: null,
moving: false,
travel: null,
exposure: 0,
incidentLogged: false
};
});
// -------------------------------------------------------------------------
// Weather visuals
// -------------------------------------------------------------------------
const cloudMaterial = new THREE.MeshLambertMaterial({
color: 0xdce9e9,
transparent: true,
opacity: 0
});
const clouds = new THREE.Group();
scene.add(clouds);
for (let i = 0; i < 10; i++) {
const cloud = new THREE.Group();
cloud.position.set(-24 + i * 5.4, 10.5 + (i % 3) * 1.1, -11 + (i % 4) * 6);
for (let j = 0; j < 3; j++) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.8 + (j % 2) * .5, 1),
cloudMaterial
);
puff.position.set((j - 1) * 1.6, (j % 2) * .3, 0);
puff.scale.set(1.2, .65, .85);
cloud.add(puff);
}
clouds.add(cloud);
}
const sunOrb = new THREE.Mesh(
new THREE.IcosahedronGeometry(2.7, 2),
new THREE.MeshBasicMaterial({ color: 0xffe497 })
);
sunOrb.position.set(-16, 17, -15);
scene.add(sunOrb);
const rainCount = 650;
const rainPositions = new Float32Array(rainCount * 3);
for (let i = 0; i < rainCount; i++) {
rainPositions[i * 3] = -25 + Math.random() * 50;
rainPositions[i * 3 + 1] = 1 + Math.random() * 20;
rainPositions[i * 3 + 2] = -19 + Math.random() * 38;
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rainMaterial = new THREE.PointsMaterial({
color: 0xbbe8f2,
size: .095,
transparent: true,
opacity: .72,
depthWrite: false
});
const rain = new THREE.Points(rainGeometry, rainMaterial);
rain.visible = false;
scene.add(rain);
// -------------------------------------------------------------------------
// Weather rules and game state
// -------------------------------------------------------------------------
const weatherDefinitions = [
{
id: "sun",
name: "Sunspell",
icon: "☀",
duration: 22,
requiresCover: false,
exposureRate: 0,
blurb: "Warm, harmless fictional sunshine.",
sky: 0xa9d7d9,
fog: 0xa9d7d9,
cloud: 0,
rain: 0,
light: 0xfff0cf,
lightPower: 2.55,
hemiPower: 2.25,
wash: "rgba(255,210,110,.08)"
},
{
id: "rain",
name: "Petalfall",
icon: "☂",
duration: 30,
requiresCover: true,
exposureRate: 3.1,
blurb: "Imaginary flower-rain soaks anyone left outside.",
sky: 0x829fae,
fog: 0x91aab3,
cloud: .82,
rain: .72,
light: 0xc8dbea,
lightPower: 1.25,
hemiPower: 1.65,
wash: "rgba(83,147,186,.15)"
},
{
id: "storm",
name: "Thunder Orchard",
icon: "ϟ",
duration: 26,
requiresCover: true,
exposureRate: 6.6,
blurb: "The orchard trees thunder overhead. Cover is essential.",
sky: 0x596d80,
fog: 0x637888,
cloud: 1,
rain: 1,
light: 0xa9c5df,
lightPower: .8,
hemiPower: 1.25,
wash: "rgba(49,67,91,.25)"
},
{
id: "heat",
name: "Ember Noon",
icon: "♨",
duration: 24,
requiresCover: true,
exposureRate: 4.4,
blurb: "A fictional heat shimmer makes shade urgently necessary.",
sky: 0xe4b18c,
fog: 0xe3b58e,
cloud: .08,
rain: 0,
light: 0xffc17f,
lightPower: 3.1,
hemiPower: 1.8,
wash: "rgba(255,112,64,.18)"
}
];
let weatherIndex = 0;
let weatherTime = 0;
let gameTime = 0;
let speed = 1;
let paused = false;
let selectedGroupId = null;
let incidents = 0;
let safeHold = 0;
let successShown = false;
let toastTimer = null;
const targetVisual = {
cloud: 0,
rain: 0,
sky: new THREE.Color(),
fog: new THREE.Color(),
light: new THREE.Color(),
lightPower: 2.5,
hemiPower: 2.2
};
function currentWeather() {
return weatherDefinitions[weatherIndex];
}
function setVisualTarget() {
const weather = currentWeather();
targetVisual.cloud = weather.cloud;
targetVisual.rain = weather.rain;
targetVisual.sky.set(weather.sky);
targetVisual.fog.set(weather.fog);
targetVisual.light.set(weather.light);
targetVisual.lightPower = weather.lightPower;
targetVisual.hemiPower = weather.hemiPower;
document.querySelector("#weatherWash").style.background = weather.wash;
}
function notify(message, type = "") {
const toast = document.querySelector("#toast");
toast.textContent = message;
toast.className = `show ${type}`;
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.className = "";
}, 3200);
}
function shelterLoad(shelterId) {
let people = 0;
let gear = 0;
let parties = 0;
groups.forEach(group => {
if (group.assignedShelter === shelterId) {
people += group.people;
gear += 1;
parties += 1;
}
});
return { people, gear, parties };
}
function groupIsSheltered(group) {
return Boolean(
group.assignedShelter &&
group.arrivedShelter === group.assignedShelter &&
!group.moving
);
}
function selectGroup(groupId) {
selectedGroupId = groupId;
updateUI();
}
function targetPositionFor(group, shelter) {
return new THREE.Vector3(
shelter.x + group.targetOffset.x,
0,
shelter.z + group.targetOffset.z
);
}
function attemptMove(groupId, shelterId) {
const group = groups.find(item => item.id === groupId);
const shelter = shelters.find(item => item.id === shelterId);
if (!group || !shelter) return;
if (!selectedGroupId) {
selectedGroupId = groupId;
notify("Party selected. Now choose a pavilion.");
updateUI();
return;
}
if (selectedGroupId !== groupId) {
selectedGroupId = groupId;
updateUI();
return;
}
if (group.moving) {
notify(`${group.name} is still on the move.`, "error");
return;
}
if (group.assignedShelter === shelterId) {
notify(`${group.name} is already assigned to ${shelter.name}.`);
return;
}
const load = shelterLoad(shelterId);
if (load.people + group.people > shelter.capacity) {
notify(
`${shelter.name} only has ${shelter.capacity - load.people} places left.`,
"error"
);
return;
}
if (load.gear + 1 > shelter.gearCapacity) {
notify(`${shelter.name} has no free gear bay for this party.`, "error");
return;
}
group.assignedShelter = shelterId;
group.arrivedShelter = null;
group.moving = true;
const from = group.root.position.clone();
const to = targetPositionFor(group, shelter);
const distance = from.distanceTo(to);
group.travel = {
t: 0,
from,
to,
duration: 1.1 + distance / 9
};
notify(
`${group.name} and all ${group.gear.toLowerCase()} are moving to ${shelter.name}.`,
"good"
);
updateUI();
}
function bestShelterFor(group) {
if (!group) return null;
return shelters
.filter(shelter => {
const load = shelterLoad(shelter.id);
return (
load.people + group.people <= shelter.capacity &&
load.gear + 1 <= shelter.gearCapacity &&
group.assignedShelter !== shelter.id
);
})
.sort((a, b) => {
const aFree = a.capacity - shelterLoad(a.id).people;
const bFree = b.capacity - shelterLoad(b.id).people;
return bFree - aFree;
})[0] || null;
}
function shiftWeather(manual = false) {
weatherIndex = (weatherIndex + 1) % weatherDefinitions.length;
weatherTime = 0;
setVisualTarget();
const weather = currentWeather();
const message = weather.requiresCover
? `${weather.name}: everyone needs pavilion cover now.`
: `${weather.name}: no cover is required yet.`;
notify(message, weather.requiresCover ? "error" : "");
updateUI();
}
function updateGroupMovement(dt) {
groups.forEach(group => {
if (!group.moving || !group.travel) return;
group.travel.t = Math.min(1, group.travel.t + dt / group.travel.duration);
const t = group.travel.t;
const eased = t * t * (3 - 2 * t);
group.root.position.lerpVectors(
group.travel.from,
group.travel.to,
eased
);
if (t >= 1) {
group.root.position.copy(group.travel.to);
group.moving = false;
group.arrivedShelter = group.assignedShelter;
group.travel = null;
const shelter = shelters.find(item => item.id === group.arrivedShelter);
notify(`${group.name} arrived safely at ${shelter.name}.`, "good");
}
});
}
function updatePeople(dt) {
groups.forEach(group => {
group.figures.forEach(person => {
const phase = person.userData.phase;
if (group.moving) {
const step = Math.sin(gameTime * 11 + phase);
person.position.y = Math.abs(step) * .055;
person.userData.leftLeg.rotation.x = step * .45;
person.userData.rightLeg.rotation.x = -step * .45;
} else {
person.position.y = 0;
person.userData.leftLeg.rotation.x = 0;
person.userData.rightLeg.rotation.x = 0;
}
});
});
}
function updateWeather(dt) {
const weather = currentWeather();
weatherTime += dt;
if (weatherTime >= weather.duration) {
shiftWeather(false);
}
groups.forEach(group => {
const sheltered = groupIsSheltered(group);
if (weather.requiresCover && !sheltered) {
const transitPenalty = group.moving ? 1.18 : 1;
group.exposure = Math.min(
100,
group.exposure + weather.exposureRate * transitPenalty * dt
);
} else {
group.exposure = Math.max(0, group.exposure - 5.5 * dt);
}
if (group.exposure >= 100 && !group.incidentLogged) {
group.incidentLogged = true;
incidents += 1;
notify(
`${group.name} has a comfort incident. Move them under cover.`,
"error"
);
}
});
const everyoneSafe = groups.every(groupIsSheltered);
if (everyoneSafe && weather.requiresCover) {
safeHold += dt;
} else {
safeHold = 0;
}
if (safeHold > 4.5 && !successShown) {
showSuccess();
}
}
function showSuccess() {
successShown = true;
const averageExposure =
groups.reduce((sum, group) => sum + group.exposure, 0) / groups.length;
const score = Math.max(
0,
Math.round(100 - averageExposure * .65 - incidents * 12)
);
document.querySelector("#modalTitle").textContent = "Park secured";
document.querySelector("#modalText").textContent =
`All 16 people, four activity parties, and every belonging are safely under cover. ` +
`Dispatch score: ${score}. Comfort incidents: ${incidents}.`;
document.querySelector("#modal").classList.add("show");
}
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
function statusFor(group) {
if (group.moving) {
const shelter = shelters.find(item => item.id === group.assignedShelter);
return { text: `To ${shelter.id}`, className: "" };
}
if (groupIsSheltered(group)) {
const shelter = shelters.find(item => item.id === group.assignedShelter);
return { text: `Safe · ${shelter.id}`, className: "safe" };
}
if (currentWeather().requiresCover) {
return { text: "Outside", className: "risk" };
}
return { text: "Outside", className: "" };
}
function updateUI() {
const weather = currentWeather();
const totalPeople = groups.reduce((sum, group) => sum + group.people, 0);
const shelteredPeople = groups
.filter(groupIsSheltered)
.reduce((sum, group) => sum + group.people, 0);
const averageExposure =
groups.reduce((sum, group) => sum + group.exposure, 0) / groups.length;
document.querySelector("#safeStat").textContent =
`${shelteredPeople} / ${totalPeople}`;
document.querySelector("#comfortStat").textContent =
`${Math.round(100 - averageExposure)}%`;
document.querySelector("#incidentStat").textContent = incidents;
document.querySelector("#weatherIcon").textContent = weather.icon;
document.querySelector("#weatherName").textContent = weather.name;
document.querySelector("#weatherBlurb").textContent = weather.blurb;
document.querySelector("#weatherTimer").textContent =
`${Math.max(0, Math.ceil(weather.duration - weatherTime))}s`;
document.querySelector("#weatherFill").style.width =
`${Math.max(0, (weather.duration - weatherTime) / weather.duration * 100)}%`;
const requirement = document.querySelector("#requirement");
requirement.textContent = weather.requiresCover
? "Cover required now"
: "No cover required";
requirement.className = weather.requiresCover ? "danger" : "safe";
const forecast = [];
for (let offset = 0; offset < 4; offset++) {
const item = weatherDefinitions[(weatherIndex + offset) % weatherDefinitions.length];
forecast.push(
`<div class="forecast-chip">
<span>${item.icon}</span>
<small>${item.name}</small>
</div>`
);
}
document.querySelector("#forecast").innerHTML = forecast.join("");
const groupList = document.querySelector("#groupList");
groupList.innerHTML = groups.map(group => {
const status = statusFor(group);
const color = "#" + new THREE.Color(group.color).getHexString();
return `
<button class="group-row ${selectedGroupId === group.id ? "selected" : ""}"
data-group="${group.id}">
<span class="group-dot" style="background:${color}"></span>
<span class="group-copy">
<strong>${group.name}</strong>
<small>${group.people} people · ${group.gear}</small>
</span>
<span class="group-state ${status.className}">${status.text}</span>
<span class="exposure-track">
<span class="exposure-fill" style="width:${group.exposure}%"></span>
</span>
</button>
`;
}).join("");
const selectedGroup = groups.find(group => group.id === selectedGroupId);
document.querySelector("#selectedName").textContent = selectedGroup
? selectedGroup.name
: "No party selected";
const best = bestShelterFor(selectedGroup);
const dispatchBest = document.querySelector("#dispatchBest");
dispatchBest.disabled = !selectedGroup || !best;
if (!selectedGroup) {
dispatchBest.textContent = "Select a party first";
} else if (!best) {
dispatchBest.textContent = "No pavilion can accept this party";
} else {
dispatchBest.textContent = `Send to best fit · ${best.name}`;
}
const shelterList = document.querySelector("#shelterList");
shelterList.innerHTML = shelters.map(shelter => {
const load = shelterLoad(shelter.id);
const peoplePercent = load.people / shelter.capacity * 100;
const capacityClass =
load.people >= shelter.capacity
? "full"
: load.people / shelter.capacity >= .7
? "near"
: "";
const canFit = selectedGroup
? load.people + selectedGroup.people <= shelter.capacity &&
load.gear + 1 <= shelter.gearCapacity
: false;
const alreadyThere = selectedGroup?.assignedShelter === shelter.id;
return `
<div class="shelter-card">
<div class="shelter-title">
<strong>${shelter.id} · ${shelter.name}</strong>
${best?.id === shelter.id ? '<span class="best-tag">Best fit</span>' : ""}
</div>
<div class="capacity-row">
<span>People <strong>${load.people}/${shelter.capacity}</strong></span>
<span>Gear bays <strong>${load.gear}/${shelter.gearCapacity}</strong></span>
</div>
<div class="capacity-track">
<div class="capacity-fill ${capacityClass}" style="width:${peoplePercent}%"></div>
</div>
<button class="shelter-button ${selectedGroup && !canFit ? "no-fit" : ""}"
data-shelter="${shelter.id}"
${!selectedGroup ? "disabled" : ""}>
${
!selectedGroup
? "Choose a party first"
: alreadyThere
? "Party already assigned"
: canFit
? `Send ${selectedGroup.name} here`
: "Does not fit — choose another"
}
</button>
</div>
`;
}).join("");
shelters.forEach(shelter => {
const load = shelterLoad(shelter.id);
shelter.label.setLabel(
`${shelter.id} · ${load.people}/${shelter.capacity}`,
shelter.id === "A" ? "#78e0b5" : "#ff9b86"
);
});
groups.forEach(group => {
group.selectionRing.visible = group.id === selectedGroupId;
});
const timeline = document.querySelector("#timeline");
timeline.innerHTML = Array.from({ length: 4 }, (_, offset) => {
const item = weatherDefinitions[(weatherIndex + offset) % weatherDefinitions.length];
return `
<div class="timeline-node ${offset === 0 ? "active" : ""}">
<b>${item.icon}</b><span>${item.name}</span>
</div>
`;
}).join("");
}
document.querySelector("#groupList").addEventListener("click", event => {
const row = event.target.closest("[data-group]");
if (row) selectGroup(row.dataset.group);
});
document.querySelector("#shelterList").addEventListener("click", event => {
const button = event.target.closest("[data-shelter]");
if (!button || !selectedGroupId) return;
attemptMove(selectedGroupId, button.dataset.shelter);
});
document.querySelector("#dispatchBest").addEventListener("click", () => {
const group = groups.find(item => item.id === selectedGroupId);
const shelter = bestShelterFor(group);
if (group && shelter) attemptMove(group.id, shelter.id);
});
document.querySelector("#pauseButton").addEventListener("click", () => {
paused = !paused;
document.querySelector("#pauseButton").textContent = paused ? "Resume" : "Pause";
});
document.querySelector("#speedButton").addEventListener("click", () => {
speed = speed === 1 ? 2 : 1;
document.querySelector("#speedButton").textContent = `${speed}×`;
});
document.querySelector("#shiftWeather").addEventListener("click", () => {
shiftWeather(true);
});
document.querySelector("#continueButton").addEventListener("click", () => {
document.querySelector("#modal").classList.remove("show");
});
document.querySelector("#newScenario").addEventListener("click", resetScenario);
document.querySelector("#resetScenario").addEventListener("click", resetScenario);
function resetScenario() {
selectedGroupId = null;
incidents = 0;
safeHold = 0;
successShown = false;
weatherIndex = 0;
weatherTime = 0;
gameTime = 0;
paused = false;
speed = 1;
groups.forEach(group => {
group.root.position.copy(group.originalPosition);
group.assignedShelter = null;
group.arrivedShelter = null;
group.moving = false;
group.travel = null;
group.exposure = 0;
group.incidentLogged = false;
});
document.querySelector("#pauseButton").textContent = "Pause";
document.querySelector("#speedButton").textContent = "1×";
document.querySelector("#modal").classList.remove("show");
setVisualTarget();
updateUI();
notify("New scenario. The first fictional change is approaching.", "good");
}
// -------------------------------------------------------------------------
// Direct camera controls and object picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragState = null;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragState = {
id: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
button: event.button,
moved: false
};
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragState || dragState.id !== event.pointerId) return;
const dx = event.clientX - dragState.lastX;
const dy = event.clientY - dragState.lastY;
const totalDistance = Math.hypot(
event.clientX - dragState.startX,
event.clientY - dragState.startY
);
if (totalDistance > 5) dragState.moved = true;
if (dragState.button === 2 || event.shiftKey) {
const scale = cameraState.distance * .00125;
cameraState.target.x -= dx * scale * Math.cos(cameraState.yaw);
cameraState.target.z += dx * scale * Math.sin(cameraState.yaw);
cameraState.target.z += dy * scale;
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -15, 15);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -12, 12);
} else {
cameraState.yaw -= dx * .005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * .004,
.32,
1.18
);
}
dragState.lastX = event.clientX;
dragState.lastY = event.clientY;
});
canvas.addEventListener("pointerup", event => {
if (!dragState || dragState.id !== event.pointerId) return;
const wasClick = !dragState.moved && dragState.button === 0;
dragState = null;
canvas.style.cursor = "grab";
if (wasClick) pickScene(event.clientX, event.clientY);
});
canvas.addEventListener("pointercancel", () => {
dragState = null;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * .025,
22,
68
);
},
{ passive: false }
);
function pickScene(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = (clientX - rect.left) / rect.width * 2 - 1;
pointer.y = -(clientY - rect.top) / rect.height * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(scene.children, true);
for (const intersection of intersections) {
let object = intersection.object;
while (object && object !== scene) {
if (object.userData.groupId) {
selectGroup(object.userData.groupId);
return;
}
if (object.userData.shelterId) {
if (selectedGroupId) {
attemptMove(selectedGroupId, object.userData.shelterId);
} else {
notify("Choose an activity party before dispatching.");
}
return;
}
object = object.parent;
}
}
}
document.querySelector("#zoomIn").addEventListener("click", () => {
cameraState.distance = Math.max(22, cameraState.distance - 4);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
cameraState.distance = Math.min(68, cameraState.distance + 4);
});
document.querySelector("#resetView").addEventListener("click", () => {
cameraState.yaw = .68;
cameraState.pitch = .72;
cameraState.distance = 45;
cameraState.target.set(0, 0, 0);
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
document.querySelector("#pauseButton").click();
}
if (event.code === "Escape") {
selectedGroupId = null;
updateUI();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const realDt = Math.min(clock.getDelta(), .05);
const dt = paused ? 0 : realDt * speed;
gameTime += dt;
updateGroupMovement(dt);
updatePeople(dt);
updateWeather(dt);
// Smoothly blend weather colors.
scene.background.lerp(targetVisual.sky, realDt * 1.6);
scene.fog.color.lerp(targetVisual.fog, realDt * 1.6);
sunLight.color.lerp(targetVisual.light, realDt * 1.6);
sunLight.intensity = THREE.MathUtils.lerp(
sunLight.intensity,
targetVisual.lightPower,
realDt * 1.6
);
hemi.intensity = THREE.MathUtils.lerp(
hemi.intensity,
targetVisual.hemiPower,
realDt * 1.6
);
cloudMaterial.opacity = THREE.MathUtils.lerp(
cloudMaterial.opacity,
targetVisual.cloud,
realDt * 1.5
);
clouds.visible = cloudMaterial.opacity > .015;
const targetRain = targetVisual.rain;
rainMaterial.opacity = THREE.MathUtils.lerp(
rainMaterial.opacity,
targetRain * .72,
realDt * 2
);
rain.visible = rainMaterial.opacity > .01;
if (rain.visible) {
const positions = rainGeometry.attributes.position.array;
const fallSpeed = currentWeather().id === "storm" ? 18 : 11;
for (let i = 0; i < rainCount; i++) {
const index = i * 3;
positions[index + 1] -= fallSpeed * realDt;
positions[index] -= 1.4 * realDt;
if (positions[index + 1] < 0) {
positions[index + 1] = 19;
positions[index] = -25 + Math.random() * 50;
positions[index + 2] = -19 + Math.random() * 38;
}
}
rainGeometry.attributes.position.needsUpdate = true;
}
sunOrb.visible = currentWeather().id !== "storm";
uiAccumulator += realDt;
if (uiAccumulator > .18) {
updateUI();
uiAccumulator = 0;
}
updateCamera();
renderer.render(scene, camera);
}
setVisualTarget();
updateUI();
document.querySelector("#loading").remove();
animate();
setTimeout(() => {
notify("Select an activity party, then dispatch it to a pavilion.", "good");
}, 500);
</script>
</body>
</html>
```