Prompt specification
Build or customize the Three.js 3D scene "Outdoor Picnic Rain Plan" 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: Outdoor Picnic Rain Plan
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/outdoor-picnic-rain-plan-x3222
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts contingency plans for uncertain events. Show an outdoor picnic setup and a reserved indoor option with limited capacity. Toggle a fictional rain event and move only activities that fit the alternate space. Voxel style.
Working Three.js Starter (outdoor-picnic-rain-plan-x3222):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Contingency Lab — Picnic Rain Plan</title>
<style>
:root {
--ink: #173b35;
--muted: #61736d;
--paper: #fbf7ed;
--line: rgba(23, 59, 53, 0.16);
--orange: #ff704f;
--green: #54a879;
--blue: #5797c4;
--shadow: 0 14px 40px rgba(31, 62, 54, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
pointer-events: auto;
}
.brand {
top: 22px;
left: 24px;
width: 330px;
pointer-events: none;
}
.brand-kicker,
.control-kicker,
.dock-kicker {
margin: 0 0 7px;
font-size: 10px;
line-height: 1;
font-weight: 900;
letter-spacing: 0.18em;
text-transform: uppercase;
color: var(--muted);
}
.brand h1 {
margin: 0;
max-width: 310px;
font-size: clamp(25px, 3vw, 43px);
line-height: 0.96;
letter-spacing: -0.055em;
font-weight: 950;
}
.brand p:last-child {
margin: 12px 0 0;
max-width: 310px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.control-card {
top: 22px;
right: 24px;
width: 292px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 18px;
background: rgba(251, 247, 237, 0.92);
backdrop-filter: blur(14px);
box-shadow: var(--shadow);
}
.weather-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-top: 11px;
}
.weather-title strong {
display: block;
font-size: 15px;
letter-spacing: -0.02em;
}
.weather-title small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 49px;
height: 28px;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch-track {
position: absolute;
inset: 0;
border-radius: 20px;
background: #cbd4cf;
box-shadow: inset 0 0 0 1px rgba(23, 59, 53, 0.08);
transition: background 180ms ease;
cursor: pointer;
}
.switch-track::after {
content: "";
position: absolute;
top: 4px;
left: 4px;
width: 20px;
height: 20px;
border-radius: 5px;
background: #fffaf0;
box-shadow: 0 2px 8px rgba(23, 59, 53, 0.2);
transition: transform 180ms ease, background 180ms ease;
}
.switch input:checked + .switch-track {
background: var(--blue);
}
.switch input:checked + .switch-track::after {
transform: translateX(21px);
background: #eef8ff;
}
.weather-copy {
min-height: 46px;
margin: 14px 0;
padding: 11px 12px;
border-radius: 11px;
background: #eef2eb;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.weather-copy.raining {
background: #e4f0f6;
color: #315b6d;
}
.control-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.action-button {
min-height: 36px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
.action-button.primary {
border-color: var(--ink);
background: var(--ink);
color: #fffaf0;
}
.action-button:hover {
transform: translateY(-1px);
background: rgba(23, 59, 53, 0.07);
}
.action-button.primary:hover {
background: #24554c;
}
.control-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.activity-dock {
left: 50%;
bottom: 20px;
width: min(1010px, calc(100vw - 48px));
transform: translateX(-50%);
padding: 13px 14px 12px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 19px;
background: rgba(251, 247, 237, 0.94);
backdrop-filter: blur(16px);
box-shadow: var(--shadow);
}
.dock-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 2px 10px;
}
.dock-heading {
font-size: 13px;
font-weight: 900;
}
.dock-heading span {
margin-left: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.capacity {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.capacity-slots {
display: flex;
gap: 4px;
}
.capacity-slot {
width: 22px;
height: 8px;
border: 1px solid rgba(23, 59, 53, 0.18);
border-radius: 3px;
background: transparent;
transition: background 180ms ease, border-color 180ms ease;
}
.capacity-slot.filled {
border-color: var(--green);
background: var(--green);
}
.activity-list {
display: grid;
grid-template-columns: repeat(5, minmax(145px, 1fr));
gap: 8px;
}
.activity-card {
position: relative;
min-width: 0;
overflow: hidden;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.45);
cursor: pointer;
transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
.activity-card::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 4px;
height: 100%;
background: var(--activity-color);
}
.activity-card:hover,
.activity-card.selected {
transform: translateY(-2px);
border-color: var(--activity-color);
background: #fffdf7;
}
.activity-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.activity-name {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 12px;
font-weight: 900;
}
.activity-icon {
display: grid;
place-items: center;
flex: 0 0 auto;
width: 24px;
height: 24px;
border-radius: 7px;
background: var(--activity-color);
color: #fff;
font-size: 12px;
font-weight: 950;
}
.activity-meta {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.activity-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 7px;
margin-top: 9px;
}
.status-badge {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--muted);
font-size: 9px;
font-weight: 850;
}
.status-badge.indoor {
color: #317453;
}
.status-badge.warning {
color: #a24c36;
}
.move-button {
flex: 0 0 auto;
padding: 5px 7px;
border: 0;
border-radius: 7px;
background: var(--ink);
color: white;
font-size: 9px;
font-weight: 850;
cursor: pointer;
}
.move-button:disabled {
background: #dfe4df;
color: #88938e;
cursor: not-allowed;
}
.world-tag,
.activity-tag {
position: fixed;
z-index: 4;
left: 0;
top: 0;
pointer-events: none;
will-change: transform;
}
.world-tag {
min-width: 118px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 9px;
background: rgba(251, 247, 237, 0.9);
box-shadow: 0 7px 18px rgba(23, 59, 53, 0.13);
text-align: center;
font-size: 10px;
font-weight: 950;
letter-spacing: 0.08em;
}
.world-tag small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.06em;
}
.activity-tag {
padding: 4px 6px;
border-radius: 5px;
background: rgba(23, 59, 53, 0.86);
color: white;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.06em;
box-shadow: 0 4px 12px rgba(23, 59, 53, 0.15);
}
.activity-tag.moving {
background: var(--orange);
}
.view-help {
position: fixed;
right: 24px;
bottom: 198px;
z-index: 6;
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
pointer-events: none;
}
.view-reset {
pointer-events: auto;
padding: 7px 10px;
border: 1px solid rgba(23, 59, 53, 0.16);
border-radius: 8px;
background: rgba(251, 247, 237, 0.84);
font-size: 10px;
font-weight: 850;
cursor: pointer;
}
.toast {
position: fixed;
z-index: 20;
left: 50%;
top: 22px;
max-width: min(430px, calc(100vw - 40px));
padding: 11px 16px;
border-radius: 10px;
background: var(--ink);
color: #fffaf0;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 750;
text-align: center;
opacity: 0;
transform: translate(-50%, -12px);
transition: opacity 180ms ease, transform 180ms ease;
pointer-events: none;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #dce7df;
color: var(--ink);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.brand {
top: 12px;
left: 14px;
width: 220px;
}
.brand p:last-child {
display: none;
}
.control-card {
top: 12px;
right: 12px;
width: 230px;
padding: 14px;
}
.control-note {
display: none;
}
.activity-dock {
bottom: 10px;
width: calc(100vw - 20px);
}
.activity-list {
grid-template-columns: repeat(5, 155px);
overflow-x: auto;
padding-bottom: 3px;
}
.view-help {
right: 12px;
bottom: 178px;
}
.view-help span {
display: none;
}
}
@media (max-width: 560px) {
.brand {
width: 150px;
}
.brand h1 {
font-size: 22px;
}
.brand-kicker {
font-size: 8px;
}
.control-card {
width: 195px;
}
.weather-copy {
min-height: 39px;
margin: 10px 0;
padding: 8px;
font-size: 9px;
}
.control-kicker {
font-size: 8px;
}
.weather-title strong {
font-size: 12px;
}
.weather-title small {
font-size: 9px;
}
.action-button {
font-size: 9px;
}
.dock-heading span {
display: none;
}
.capacity {
font-size: 9px;
}
.capacity-slot {
width: 16px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel picnic contingency scene"></canvas>
<header class="brand panel">
<p class="brand-kicker">Contingency Lab / Scenario 01</p>
<h1>Community picnic, rain-ready.</h1>
<p>
A reserved indoor room has four activity slots. Only compatible activities
with enough space are moved when the fictional rain event begins.
</p>
</header>
<aside class="control-card panel">
<p class="control-kicker">Fictional weather control</p>
<div class="weather-title">
<div>
<strong>Rain event</strong>
<small id="weatherState">Dry forecast</small>
</div>
<label class="switch" title="Toggle the fictional rain scenario">
<input id="rainToggle" type="checkbox" aria-label="Toggle fictional rain event" />
<span class="switch-track"></span>
</label>
</div>
<div id="weatherCopy" class="weather-copy">
Turn on rain to run the contingency plan. The indoor reserve will fill
without exceeding its four-slot capacity.
</div>
<div class="control-actions">
<button id="autoPlan" class="action-button primary">Auto-fill room</button>
<button id="clearPlan" class="action-button">Clear moves</button>
</div>
<p class="control-note">
Craft carts use two slots. Sand play is not suitable for the indoor room.
</p>
</aside>
<section class="activity-dock panel">
<div class="dock-header">
<div class="dock-heading">
Activity manifest
<span>Select an activity, then move it manually</span>
</div>
<div class="capacity" aria-live="polite">
<span id="capacityText">0 / 4 slots</span>
<div class="capacity-slots" id="capacitySlots">
<span class="capacity-slot"></span>
<span class="capacity-slot"></span>
<span class="capacity-slot"></span>
<span class="capacity-slot"></span>
</div>
</div>
</div>
<div id="activityList" class="activity-list"></div>
</section>
<div id="outdoorTag" class="world-tag">
OUTDOOR PICNIC
<small>OPEN-AIR BASE</small>
</div>
<div id="indoorTag" class="world-tag">
RAIN RESERVE
<small>4-SLOT INDOOR ROOM</small>
</div>
<div class="view-help">
<span>Drag to orbit · Scroll to zoom</span>
<button id="resetView" class="view-reset">Reset view</button>
</div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<div id="loading" class="loading">Building contingency scene…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State and activity manifest
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const rainToggle = document.querySelector("#rainToggle");
const weatherState = document.querySelector("#weatherState");
const weatherCopy = document.querySelector("#weatherCopy");
const activityList = document.querySelector("#activityList");
const capacityText = document.querySelector("#capacityText");
const capacitySlotElements = [...document.querySelectorAll(".capacity-slot")];
const toast = document.querySelector("#toast");
const loading = document.querySelector("#loading");
const CAPACITY = 4;
const slotDefinitions = [
{ id: 0, x: 2.65, z: -1.25 },
{ id: 1, x: 5.75, z: -1.25 },
{ id: 2, x: 2.65, z: 1.05 },
{ id: 3, x: 5.75, z: 1.05 }
];
const activityDefinitions = [
{
id: "board",
name: "Board games",
short: "BOARD",
icon: "B",
slots: 1,
priority: 1,
indoorReady: true,
color: "#ff704f",
outdoor: { x: -7.35, z: -1.85 },
build: buildBoardGames
},
{
id: "reading",
name: "Reading nook",
short: "READ",
icon: "R",
slots: 1,
priority: 2,
indoorReady: true,
color: "#5797c4",
outdoor: { x: -1.72, z: -1.95 },
build: buildReadingNook
},
{
id: "craft",
name: "Craft cart",
short: "MAKE",
icon: "M",
slots: 2,
priority: 3,
indoorReady: true,
color: "#a77bc6",
outdoor: { x: -7.15, z: 1.72 },
build: buildCraftCart
},
{
id: "story",
name: "Story circle",
short: "TELL",
icon: "S",
slots: 1,
priority: 4,
indoorReady: true,
color: "#e2ad43",
outdoor: { x: -1.7, z: 1.95 },
build: buildStoryCircle
},
{
id: "sand",
name: "Sand play",
short: "SAND",
icon: "×",
slots: 2,
priority: 5,
indoorReady: false,
color: "#d67d54",
outdoor: { x: -4.72, z: 2.72 },
build: buildSandPlay
}
];
const state = {
raining: false,
rainMix: 0,
indoor: new Set(),
assignments: new Map(),
selected: null
};
const activities = new Map();
// -------------------------------------------------------------------------
// Renderer, camera, and manual orbit controls
// -------------------------------------------------------------------------
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.05;
const scene = new THREE.Scene();
const skyColor = new THREE.Color(0xdce7df);
const stormColor = new THREE.Color(0xbdcdd0);
scene.background = skyColor.clone();
scene.fog = new THREE.Fog(skyColor.clone(), 24, 43);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraRig = {
target: new THREE.Vector3(0, 0.6, 0),
radius: 18.5,
azimuth: 0.28,
elevation: 0.58
};
const defaultCamera = { ...cameraRig, target: cameraRig.target.clone() };
function updateCamera() {
const horizontal = cameraRig.radius * Math.cos(cameraRig.elevation);
camera.position.set(
cameraRig.target.x + horizontal * Math.sin(cameraRig.azimuth),
cameraRig.target.y + cameraRig.radius * Math.sin(cameraRig.elevation),
cameraRig.target.z + horizontal * Math.cos(cameraRig.azimuth)
);
camera.lookAt(cameraRig.target);
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const height = Math.max(12.8, 19.5 / aspect);
camera.left = (-height * aspect) / 2;
camera.right = (height * aspect) / 2;
camera.top = height / 2;
camera.bottom = -height / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
let pointerDown = false;
let pointerMoved = false;
let pointerStart = { x: 0, y: 0 };
let previousPointer = { x: 0, y: 0 };
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
if (
Math.abs(event.clientX - pointerStart.x) +
Math.abs(event.clientY - pointerStart.y) > 5
) {
pointerMoved = true;
}
cameraRig.azimuth -= dx * 0.006;
cameraRig.elevation = THREE.MathUtils.clamp(
cameraRig.elevation + dy * 0.004,
0.25,
1.05
);
previousPointer = { x: event.clientX, y: event.clientY };
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
canvas.classList.remove("dragging");
if (!pointerMoved) {
selectActivityAt(event.clientX, event.clientY);
}
pointerDown = false;
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRig.radius = THREE.MathUtils.clamp(
cameraRig.radius + event.deltaY * 0.012,
11.5,
27
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#resetView").addEventListener("click", () => {
cameraRig.radius = defaultCamera.radius;
cameraRig.azimuth = defaultCamera.azimuth;
cameraRig.elevation = defaultCamera.elevation;
cameraRig.target.copy(defaultCamera.target);
updateCamera();
});
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf5f1dd, 0x506f68, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0007;
scene.add(sun);
const indoorLight = new THREE.PointLight(0xffe9ba, 18, 10, 2);
indoorLight.position.set(4.2, 3.4, -0.2);
scene.add(indoorLight);
// -------------------------------------------------------------------------
// Voxel construction helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function solidMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function box(parent, size, position, color, material = null) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material || solidMaterial(color)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderPixels(parent, radius, height, position, color) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, 8),
solidMaterial(color)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeSign(parent, title, subtitle, position, width = 3.2) {
const signCanvas = document.createElement("canvas");
signCanvas.width = 512;
signCanvas.height = 160;
const context = signCanvas.getContext("2d");
context.fillStyle = "#fbf7ed";
context.fillRect(0, 0, 512, 160);
context.strokeStyle = "#173b35";
context.lineWidth = 12;
context.strokeRect(6, 6, 500, 148);
context.fillStyle = "#173b35";
context.font = "900 52px Arial";
context.textAlign = "center";
context.fillText(title, 256, 76);
context.fillStyle = "#61736d";
context.font = "700 22px Arial";
context.fillText(subtitle, 256, 119);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide
});
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 160 / 512),
material
);
sign.position.set(position[0], position[1], position[2]);
parent.add(sign);
return sign;
}
function makePerson(parent, shirt, x, z, scale = 1) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.scale.setScalar(scale);
parent.add(person);
box(person, [0.18, 0.34, 0.2], [-0.13, 0.18, 0], 0x334e52);
box(person, [0.18, 0.34, 0.2], [0.13, 0.18, 0], 0x334e52);
box(person, [0.5, 0.52, 0.3], [0, 0.61, 0], shirt);
box(person, [0.33, 0.33, 0.32], [0, 1.03, 0], 0xd8a57b);
box(person, [0.36, 0.12, 0.34], [0, 1.17, -0.015], 0x3c3530);
return person;
}
function makeFlag(parent, color, x = 0.68, z = -0.42) {
box(parent, [0.055, 0.72, 0.055], [x, 0.39, z], 0x655847);
box(parent, [0.43, 0.25, 0.055], [x + 0.19, 0.73, z], color);
}
// -------------------------------------------------------------------------
// Site, picnic setup, and indoor reserve
// -------------------------------------------------------------------------
const site = new THREE.Group();
scene.add(site);
box(site, [19.3, 0.55, 7.9], [-0.15, -0.48, 0], 0xc8c7b7);
const lawnMaterial = new THREE.MeshStandardMaterial({
color: 0x86aa70,
roughness: 0.95
});
box(site, [8.65, 0.17, 6.85], [-4.65, -0.13, 0], 0x86aa70, lawnMaterial);
box(site, [8.7, 0.06, 1.1], [-0.05, -0.12, 0.55], 0xd8c9a8);
box(site, [7.15, 0.22, 5.45], [4.2, -0.08, 0], 0xd9cbb2);
box(site, [7.3, 0.06, 5.58], [4.2, 0.05, 0], 0xb88f68);
// Picnic blanket.
const blanketColors = [0xe8d8ad, 0xc36e58, 0xe8d8ad, 0x6e9a8b];
for (let ix = 0; ix < 6; ix++) {
for (let iz = 0; iz < 4; iz++) {
box(
site,
[0.56, 0.025, 0.56],
[-5.98 + ix * 0.56, 0.012, -0.86 + iz * 0.56],
blanketColors[(ix + iz) % blanketColors.length]
);
}
}
// Picnic table.
box(site, [2.0, 0.16, 0.9], [-4.65, 0.98, 0.05], 0xc69058);
box(site, [0.16, 0.93, 0.16], [-5.42, 0.46, -0.23], 0x745944);
box(site, [0.16, 0.93, 0.16], [-3.88, 0.46, -0.23], 0x745944);
box(site, [0.16, 0.93, 0.16], [-5.42, 0.46, 0.34], 0x745944);
box(site, [0.16, 0.93, 0.16], [-3.88, 0.46, 0.34], 0x745944);
box(site, [1.6, 0.22, 0.32], [-4.65, 0.5, 0.05], 0x9b7049);
// Food, basket, and bottles.
box(site, [0.46, 0.28, 0.38], [-5.3, 1.2, 0.03], 0xb9824c);
box(site, [0.42, 0.1, 0.35], [-5.3, 1.38, 0.03], 0xd8ac67);
box(site, [0.22, 0.28, 0.22], [-4.08, 1.22, 0.02], 0xe7d9b6);
box(site, [0.24, 0.32, 0.24], [-3.86, 1.24, 0.16], 0x6d9b70);
box(site, [0.18, 0.18, 0.18], [-4.1, 1.16, -0.18], 0xd87b55);
// Umbrella.
const umbrella = new THREE.Group();
umbrella.position.set(-4.65, 0, 0.05);
site.add(umbrella);
box(umbrella, [0.08, 2.8, 0.08], [0, 1.4, 0], 0x715946);
box(umbrella, [2.45, 0.16, 2.05], [0, 2.67, 0], 0xe7d9b8);
box(umbrella, [1.65, 0.18, 1.3], [0, 2.84, 0], 0xe7d9b8);
box(umbrella, [0.72, 0.2, 0.62], [0, 3.01, 0], 0xe7d9b8);
box(umbrella, [0.08, 0.08, 2.07], [0, 2.77, 0], 0xc76e58);
box(umbrella, [2.47, 0.08, 0.08], [0, 2.77, 0], 0xc76e58);
// Outdoor fencing.
for (let i = 0; i < 7; i++) {
box(site, [0.12, 0.82, 0.12], [-8.35 + i * 1.25, 0.33, -3.35], 0xe4d8ba);
}
box(site, [7.45, 0.1, 0.1], [-4.72, 0.57, -3.35], 0xe4d8ba);
// Voxel trees.
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
site.add(tree);
box(tree, [0.32, 1.8, 0.32], [0, 0.85, 0], 0x795941);
box(tree, [1.45, 0.9, 1.25], [0, 2.0, 0], 0x557f58);
box(tree, [1.0, 0.85, 0.9], [-0.48, 2.55, 0.05], 0x6e9661);
box(tree, [0.95, 0.8, 0.95], [0.48, 2.5, -0.05], 0x638c59);
box(tree, [0.7, 0.7, 0.65], [0, 3.05, 0], 0x7ca168);
}
makeTree(-8.45, -2.85, 1.05);
makeTree(-0.62, -3.12, 0.85);
makeTree(-8.48, 3.05, 0.95);
// Indoor room shell.
const room = new THREE.Group();
scene.add(room);
box(room, [7.15, 3.55, 0.18], [4.2, 1.76, -2.72], 0xf1dfbd);
box(room, [0.18, 3.55, 5.4], [7.68, 1.76, 0], 0xe8d3ad);
box(room, [0.18, 1.15, 5.4], [0.72, 0.56, 0], 0xe8d3ad);
box(room, [0.18, 0.12, 5.4], [0.72, 1.12, 0], 0xc48b60);
box(room, [7.25, 0.16, 0.25], [4.2, 3.57, -2.72], 0xb57e57);
// Window on the side wall.
box(room, [0.06, 1.25, 1.95], [7.56, 2.12, -0.55], 0x8bc0cf);
box(room, [0.09, 0.09, 2.08], [7.51, 2.12, -0.55], 0xf5e5c7);
box(room, [0.09, 1.38, 0.09], [7.51, 2.12, -0.55], 0xf5e5c7);
box(room, [0.09, 1.38, 0.09], [7.51, 2.12, -1.52], 0xf5e5c7);
box(room, [0.09, 1.38, 0.09], [7.51, 2.12, 0.42], 0xf5e5c7);
// Low sofa.
box(room, [0.72, 0.35, 2.35], [6.96, 0.31, 0.75], 0x678b83);
box(room, [0.26, 0.85, 2.35], [7.23, 0.69, 0.75], 0x56786f);
box(room, [0.83, 0.25, 0.35], [6.93, 0.57, -0.25], 0x678b83);
box(room, [0.83, 0.25, 0.35], [6.93, 0.57, 1.75], 0x678b83);
// Small bookcase against the back wall.
box(room, [1.45, 1.12, 0.42], [1.45, 0.57, -2.35], 0x9c754f);
box(room, [1.55, 0.12, 0.52], [1.45, 1.17, -2.35], 0xc39360);
for (let i = 0; i < 7; i++) {
box(
room,
[0.11, 0.34 + (i % 3) * 0.06, 0.18],
[0.92 + i * 0.16, 0.72, -2.18],
[0xd56f55, 0x5797c4, 0xe3b14d, 0x6c9e72][i % 4]
);
}
// Indoor plant.
box(room, [0.42, 0.48, 0.42], [1.15, 0.25, 1.92], 0xb76f4f);
box(room, [0.18, 0.78, 0.18], [1.15, 0.78, 1.92], 0x466b52);
box(room, [0.54, 0.25, 0.42], [1.03, 1.06, 1.92], 0x5e8c5d);
box(room, [0.45, 0.22, 0.5], [1.33, 1.22, 1.92], 0x76a26c);
// Pendant lamps.
box(room, [0.035, 0.85, 0.035], [3.25, 3.22, -0.4], 0x594e43);
box(room, [0.52, 0.18, 0.52], [3.25, 2.76, -0.4], 0xf0b956);
box(room, [0.035, 0.85, 0.035], [5.35, 3.22, 0.7], 0x594e43);
box(room, [0.52, 0.18, 0.52], [5.35, 2.76, 0.7], 0xf0b956);
makeSign(room, "RAIN ROOM", "RESERVED / 4 SLOTS", [4.35, 2.88, -2.61], 3.35);
makeSign(site, "PICNIC", "OUTDOOR BASE", [-4.65, 1.3, -3.2], 2.6);
// Indoor slot pads and their borders.
const slotVisuals = [];
for (const definition of slotDefinitions) {
const material = new THREE.MeshStandardMaterial({
color: 0xf2e7ce,
transparent: true,
opacity: 0.42,
roughness: 1
});
const pad = box(
room,
[2.68, 0.025, 1.8],
[definition.x, 0.095, definition.z],
0xffffff,
material
);
pad.castShadow = false;
const borderMaterial = new THREE.MeshBasicMaterial({
color: 0x66877d,
transparent: true,
opacity: 0.38
});
box(room, [2.72, 0.025, 0.035], [definition.x, 0.115, definition.z - 0.9], 0xffffff, borderMaterial);
box(room, [2.72, 0.025, 0.035], [definition.x, 0.115, definition.z + 0.9], 0xffffff, borderMaterial);
box(room, [0.035, 0.025, 1.8], [definition.x - 1.34, 0.115, definition.z], 0xffffff, borderMaterial);
box(room, [0.035, 0.025, 1.8], [definition.x + 1.34, 0.115, definition.z], 0xffffff, borderMaterial);
slotVisuals.push({ pad, borderMaterial });
}
// -------------------------------------------------------------------------
// Activity models
// -------------------------------------------------------------------------
function buildBoardGames(group) {
box(group, [1.65, 0.07, 1.2], [0, 0.05, 0], 0x76a9b4);
box(group, [1.0, 0.14, 0.72], [0, 0.62, 0], 0xc18a57);
box(group, [0.14, 0.54, 0.14], [-0.36, 0.31, -0.23], 0x7b5b42);
box(group, [0.14, 0.54, 0.14], [0.36, 0.31, -0.23], 0x7b5b42);
box(group, [0.14, 0.54, 0.14], [-0.36, 0.31, 0.23], 0x7b5b42);
box(group, [0.14, 0.54, 0.14], [0.36, 0.31, 0.23], 0x7b5b42);
for (let x = 0; x < 5; x++) {
for (let z = 0; z < 4; z++) {
box(
group,
[0.16, 0.025, 0.15],
[-0.32 + x * 0.16, 0.705, -0.225 + z * 0.15],
(x + z) % 2 === 0 ? 0xf4ead3 : 0x3d625e
);
}
}
box(group, [0.13, 0.13, 0.13], [0.2, 0.78, 0.13], 0xff704f);
box(group, [0.12, 0.12, 0.12], [0.36, 0.78, -0.1], 0xf3c553);
makePerson(group, 0xd26855, 0, -0.55, 0.82);
makeFlag(group, 0xff704f);
}
function buildReadingNook(group) {
box(group, [1.55, 0.06, 1.18], [0, 0.04, 0], 0x8c8eaf);
box(group, [0.76, 0.42, 0.72], [0.15, 0.27, 0], 0x7e9f91);
box(group, [0.18, 0.77, 0.72], [0.48, 0.56, 0], 0x668b80);
box(group, [0.75, 0.72, 0.16], [-0.48, 0.39, 0], 0x6b8e84);
box(group, [0.34, 0.03, 0.45], [0.05, 0.52, 0.02], 0xe9dfc7);
box(group, [0.31, 0.025, 0.4], [0.05, 0.55, 0.02], 0xd4a85c);
makePerson(group, 0x5797c4, 0.05, -0.02, 0.86);
makeFlag(group, 0x5797c4);
}
function buildCraftCart(group) {
box(group, [1.85, 0.07, 1.18], [0, 0.04, 0], 0xb79ac7);
box(group, [1.2, 0.18, 0.78], [0.1, 0.68, 0], 0xd2b67d);
box(group, [0.12, 0.57, 0.12], [-0.35, 0.34, -0.26], 0x745944);
box(group, [0.12, 0.57, 0.12], [0.55, 0.34, -0.26], 0x745944);
box(group, [0.12, 0.57, 0.12], [-0.35, 0.34, 0.26], 0x745944);
box(group, [0.12, 0.57, 0.12], [0.55, 0.34, 0.26], 0x745944);
box(group, [0.58, 0.1, 0.1], [-0.58, 1.13, 0.2], 0x745944);
box(group, [0.1, 0.75, 0.1], [-0.86, 0.79, 0.2], 0x745944);
box(group, [0.1, 0.75, 0.1], [-0.31, 0.79, 0.2], 0x745944);
box(group, [0.62, 0.48, 0.08], [-0.58, 1.07, 0.2], 0xf1e7cf);
const blockColors = [0xff704f, 0x5797c4, 0xe2ad43, 0x6c9e72, 0xa77bc6];
for (let i = 0; i < 6; i++) {
box(
group,
[0.17, 0.17, 0.17],
[-0.15 + (i % 3) * 0.22, 0.86 + Math.floor(i / 3) * 0.18, -0.08],
blockColors[i]
);
}
makeFlag(group, 0xa77bc6, 0.78, -0.43);
}
function buildStoryCircle(group) {
box(group, [1.58, 0.06, 1.22], [0, 0.04, 0], 0xe6c26b);
box(group, [0.8, 0.08, 0.5], [0, 0.14, -0.12], 0xf3e4c1);
makePerson(group, 0xdf7258, -0.48, 0.32, 0.72);
makePerson(group, 0x548a78, 0.47, 0.33, 0.7);
makePerson(group, 0x6d78a8, 0, -0.43, 0.7);
box(group, [0.08, 0.72, 0.08], [0.57, 0.4, -0.43], 0x745944);
box(group, [0.55, 0.36, 0.08], [0.57, 0.73, -0.43], 0xf4e8ca);
box(group, [0.42, 0.05, 0.09], [0.57, 0.73, -0.37], 0xe2ad43);
makeFlag(group, 0xe2ad43);
}
function buildSandPlay(group) {
box(group, [1.68, 0.18, 1.35], [0, 0.11, 0], 0xb7774d);
box(group, [1.42, 0.08, 1.1], [0, 0.23, 0], 0xe5c77d);
box(group, [0.1, 0.25, 0.1], [0.4, 0.38, 0.16], 0x5b91a5);
box(group, [0.34, 0.28, 0.34], [0.41, 0.39, 0.19], 0x5b91a5);
box(group, [0.07, 0.52, 0.07], [-0.48, 0.51, 0.14], 0x745944);
box(group, [0.22, 0.18, 0.07], [-0.34, 0.73, 0.14], 0xd96c52);
makePerson(group, 0xd96c52, 0.27, -0.2, 0.64);
makeFlag(group, 0xd67d54);
}
const interactiveMeshes = [];
for (const definition of activityDefinitions) {
const group = new THREE.Group();
group.position.set(definition.outdoor.x, 0, definition.outdoor.z);
group.userData.activityId = definition.id;
scene.add(group);
definition.build(group);
group.traverse((child) => {
if (child.isMesh) {
child.userData.activityId = definition.id;
interactiveMeshes.push(child);
}
});
const label = document.createElement("div");
label.className = "activity-tag";
label.textContent = definition.name.toUpperCase();
document.body.appendChild(label);
activities.set(definition.id, {
definition,
group,
label,
basePosition: new THREE.Vector3(definition.outdoor.x, 0, definition.outdoor.z),
baseRotation: 0,
animation: null,
animationKey: "outdoor"
});
}
// -------------------------------------------------------------------------
// Rain and clouds
// -------------------------------------------------------------------------
const rainCount = 180;
const rainMaterial = new THREE.MeshBasicMaterial({
color: 0x78b9d4,
transparent: true,
opacity: 0,
depthWrite: false
});
const rainMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.035, 0.43, 0.035),
rainMaterial,
rainCount
);
rainMesh.frustumCulled = false;
scene.add(rainMesh);
let randomSeed = 71423;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6D2B79F5) | 0;
let value = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
}
const rainDrops = Array.from({ length: rainCount }, () => ({
x: -9.2 + random() * 8.7,
y: random() * 8,
z: -3.7 + random() * 7.4,
speed: 8 + random() * 5
}));
const rainDummy = new THREE.Object3D();
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0x81949a,
transparent: true,
opacity: 0,
roughness: 1
});
const cloudGroup = new THREE.Group();
cloudGroup.position.set(-4.4, 5.85, -1.3);
scene.add(cloudGroup);
const cloudBlocks = [
[-1.35, 0, 0, 1.5, 0.8, 1.2],
[0, 0.25, 0, 1.8, 1.05, 1.45],
[1.45, 0.02, 0, 1.35, 0.75, 1.05],
[-0.45, 0.72, 0, 1.2, 0.65, 1.0]
];
for (const block of cloudBlocks) {
box(
cloudGroup,
[block[3], block[4], block[5]],
[block[0], block[1], block[2]],
0xffffff,
cloudMaterial
);
}
// -------------------------------------------------------------------------
// Slot allocation and plan logic
// -------------------------------------------------------------------------
function usedSlots() {
let count = 0;
for (const id of state.indoor) {
count += activities.get(id).definition.slots;
}
return count;
}
function allocateSlots(definition, assignmentMap) {
const occupied = new Set();
for (const ids of assignmentMap.values()) {
ids.forEach((id) => occupied.add(id));
}
if (definition.slots === 1) {
const id = slotDefinitions.find((slot) => !occupied.has(slot.id))?.id;
return id === undefined ? null : [id];
}
const pairs = [
[0, 1],
[2, 3],
[0, 2],
[1, 3]
];
for (const pair of pairs) {
if (!occupied.has(pair[0]) && !occupied.has(pair[1])) {
return [...pair];
}
}
return null;
}
function canPlace(definition) {
return allocateSlots(definition, state.assignments) !== null;
}
function runAutoPlan(announce = true) {
state.indoor.clear();
state.assignments.clear();
const ordered = [...activityDefinitions].sort(
(a, b) => a.priority - b.priority
);
for (const definition of ordered) {
if (!definition.indoorReady) continue;
const allocation = allocateSlots(definition, state.assignments);
if (allocation) {
state.indoor.add(definition.id);
state.assignments.set(definition.id, allocation);
}
}
updateUI();
updateSlotVisuals();
if (announce) {
showToast(
state.raining
? "Auto plan: board games, reading, and craft moved indoors. The reserve is full."
: "Preview complete: three compatible activities fit inside the four-slot reserve."
);
}
}
function clearMoves(announce = true) {
state.indoor.clear();
state.assignments.clear();
updateUI();
updateSlotVisuals();
if (announce) showToast("All activities returned to the outdoor picnic area.");
}
function toggleActivityLocation(id) {
const activity = activities.get(id);
const definition = activity.definition;
if (state.indoor.has(id)) {
state.indoor.delete(id);
state.assignments.delete(id);
updateUI();
updateSlotVisuals();
showToast(`${definition.name} returned outdoors.`);
return;
}
if (!state.raining) {
showToast("Turn on the fictional rain event before relocating activities.");
return;
}
if (!definition.indoorReady) {
showToast(`${definition.name} is outdoor-only and cannot move into the reserve.`);
return;
}
if (!canPlace(definition)) {
const needed = definition.slots - (CAPACITY - usedSlots());
showToast(
`${definition.name} does not fit: ${needed} more slot${
needed === 1 ? " is" : "s are"
} needed. Return another activity first.`
);
return;
}
const allocation = allocateSlots(definition, state.assignments);
state.indoor.add(id);
state.assignments.set(id, allocation);
updateUI();
updateSlotVisuals();
showToast(`${definition.name} moved into the indoor reserve.`);
}
function updateSlotVisuals() {
const occupiedBySlot = new Map();
for (const [activityId, slotIds] of state.assignments.entries()) {
const definition = activities.get(activityId).definition;
for (const slotId of slotIds) {
occupiedBySlot.set(slotId, definition);
}
}
slotVisuals.forEach((visual, index) => {
const definition = occupiedBySlot.get(index);
visual.pad.material.color.set(definition ? definition.color : 0xf2e7ce);
visual.pad.material.opacity = definition ? 0.3 : 0.1;
visual.borderMaterial.color.set(definition ? definition.color : 0x66877d);
visual.borderMaterial.opacity = definition ? 0.95 : 0.25;
});
capacitySlotElements.forEach((element, index) => {
element.classList.toggle("filled", occupiedBySlot.has(index));
});
}
// -------------------------------------------------------------------------
// Manifest UI
// -------------------------------------------------------------------------
function createManifest() {
for (const definition of activityDefinitions) {
const card = document.createElement("article");
card.className = "activity-card";
card.style.setProperty("--activity-color", definition.color);
card.dataset.id = definition.id;
card.innerHTML = `
<div class="activity-top">
<div class="activity-name">${definition.name}</div>
<div class="activity-icon">${definition.icon}</div>
</div>
<div class="activity-meta">
${definition.slots} slot${definition.slots === 1 ? "" : "s"} ·
${definition.indoorReady ? "Indoor compatible" : "Outdoor only"}
</div>
<div class="activity-bottom">
<span class="status-badge"></span>
<button class="move-button" type="button"></button>
</div>
`;
card.addEventListener("click", (event) => {
if (event.target.closest(".move-button")) return;
selectActivity(definition.id);
});
card.querySelector(".move-button").addEventListener("click", (event) => {
event.stopPropagation();
toggleActivityLocation(definition.id);
});
activityList.appendChild(card);
}
}
function updateUI() {
const used = usedSlots();
const indoorCount = state.indoor.size;
capacityText.textContent = `${used} / ${CAPACITY} slots`;
for (const definition of activityDefinitions) {
const card = activityList.querySelector(`[data-id="${definition.id}"]`);
const badge = card.querySelector(".status-badge");
const button = card.querySelector(".move-button");
card.classList.toggle("selected", state.selected === definition.id);
if (state.indoor.has(definition.id)) {
badge.textContent = "Moved indoors";
badge.className = "status-badge indoor";
button.textContent = "Move out";
button.disabled = false;
} else if (!definition.indoorReady) {
badge.textContent = state.raining ? "Stays outside" : "Outdoor only";
badge.className = "status-badge warning";
button.textContent = "No move";
button.disabled = true;
} else if (state.raining && !canPlace(definition)) {
badge.textContent = "No room";
badge.className = "status-badge warning";
button.textContent = "No fit";
button.disabled = false;
} else {
badge.textContent = state.raining ? "Still outdoors" : "At picnic";
badge.className = "status-badge";
button.textContent = state.raining ? "Move in" : "Await rain";
button.disabled = !state.raining;
}
}
weatherState.textContent = state.raining
? "Fictional rain active"
: "Dry forecast";
weatherCopy.classList.toggle("raining", state.raining);
weatherCopy.textContent = state.raining
? `Rain is active. ${indoorCount} activities fit inside, using ${used} of ${CAPACITY} reserved slots.`
: "Turn on rain to run the contingency plan. The indoor reserve will fill without exceeding its four-slot capacity.";
document.querySelector("#autoPlan").textContent = state.raining
? "Re-run plan"
: "Preview plan";
}
createManifest();
updateUI();
updateSlotVisuals();
// -------------------------------------------------------------------------
// Selection and feedback
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const selectionBox = new THREE.BoxHelper(new THREE.Object3D(), 0xff704f);
selectionBox.material.transparent = true;
selectionBox.material.opacity = 0.8;
selectionBox.material.depthTest = false;
selectionBox.visible = false;
selectionBox.renderOrder = 10;
scene.add(selectionBox);
function selectActivityAt(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 hits = raycaster.intersectObjects(interactiveMeshes, false);
if (hits.length) {
selectActivity(hits[0].object.userData.activityId);
} else {
selectActivity(null);
}
}
function selectActivity(id) {
state.selected = id;
updateUI();
if (!id) {
selectionBox.visible = false;
return;
}
const activity = activities.get(id);
selectionBox.setFromObject(activity.group);
selectionBox.visible = true;
showToast(`${activity.definition.name} selected.`);
}
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 3200);
}
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") selectActivity(null);
});
// -------------------------------------------------------------------------
// UI events
// -------------------------------------------------------------------------
rainToggle.addEventListener("change", () => {
state.raining = rainToggle.checked;
if (state.raining) {
runAutoPlan(false);
showToast("Fictional rain started. Compatible activities are moving into the reserve.");
} else {
clearMoves(false);
showToast("Rain event ended. All activities returned outdoors.");
}
});
document.querySelector("#autoPlan").addEventListener("click", () => {
runAutoPlan(true);
});
document.querySelector("#clearPlan").addEventListener("click", () => {
clearMoves(true);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const dryLawn = new THREE.Color(0x86aa70);
const wetLawn = new THREE.Color(0x5e7864);
const drySky = new THREE.Color(0xdce7df);
const wetSky = new THREE.Color(0xbdcdd0);
function indoorTarget(activity) {
const ids = state.assignments.get(activity.definition.id);
if (!ids?.length) return activity.basePosition.clone();
const positions = ids.map((id) => slotDefinitions[id]);
const target = new THREE.Vector3();
for (const position of positions) {
target.x += position.x;
target.z += position.z;
}
target.multiplyScalar(1 / positions.length);
target.y = 0;
return target;
}
function smoothStep(value) {
return value * value * (3 - 2 * value);
}
function updateActivities(delta) {
for (const activity of activities.values()) {
const isIndoor = state.indoor.has(activity.definition.id);
const slotIds = state.assignments.get(activity.definition.id);
const key = isIndoor ? `indoor:${slotIds.join(",")}` : "outdoor";
const target = isIndoor
? indoorTarget(activity)
: activity.basePosition.clone();
if (activity.animationKey !== key) {
activity.animation = {
from: activity.group.position.clone(),
to: target,
progress: 0
};
activity.animationKey = key;
}
if (activity.animation) {
activity.animation.progress = Math.min(
1,
activity.animation.progress + delta / 0.9
);
const eased = smoothStep(activity.animation.progress);
activity.group.position.lerpVectors(
activity.animation.from,
activity.animation.to,
eased
);
activity.group.position.y += Math.sin(eased * Math.PI) * 1.45;
activity.group.rotation.y =
activity.baseRotation + Math.sin(eased * Math.PI) * 0.12;
activity.label.classList.add("moving");
if (activity.animation.progress >= 1) {
activity.animation = null;
activity.group.position.copy(target);
activity.group.rotation.y = activity.baseRotation;
activity.label.classList.remove("moving");
}
}
}
}
function updateRain(delta) {
const target = state.raining ? 1 : 0;
state.rainMix +=
(target - state.rainMix) * Math.min(1, delta * 2.8);
rainMaterial.opacity = state.rainMix * 0.68;
rainMesh.visible = state.rainMix > 0.01;
cloudMaterial.opacity = state.rainMix * 0.92;
cloudGroup.visible = state.rainMix > 0.01;
cloudGroup.position.x = -4.4 + Math.sin(clock.elapsedTime * 0.16) * 0.28;
if (rainMesh.visible) {
rainDrops.forEach((drop, index) => {
drop.y -= drop.speed * delta;
drop.x -= delta * 0.48;
if (drop.y < -0.05) {
drop.y = 7.5 + random() * 1.2;
drop.x = -0.7 + random() * 8.5;
}
rainDummy.position.set(drop.x, drop.y, drop.z);
rainDummy.rotation.z = -0.08;
rainDummy.updateMatrix();
rainMesh.setMatrixAt(index, rainDummy.matrix);
});
rainMesh.instanceMatrix.needsUpdate = true;
}
lawnMaterial.color.lerpColors(dryLawn, wetLawn, state.rainMix);
scene.background.lerpColors(drySky, wetSky, state.rainMix * 0.75);
scene.fog.color.copy(scene.background);
sun.intensity = 3.1 - state.rainMix * 1.25;
hemisphere.intensity = 2.2 - state.rainMix * 0.35;
}
const projected = new THREE.Vector3();
function positionTag(element, worldPosition, offsetY = 0) {
projected.copy(worldPosition);
projected.y += offsetY;
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform = `translate(-50%, -100%) translate(${x}px, ${y}px)`;
}
const outdoorTagPosition = new THREE.Vector3(-4.65, 3.75, -3.2);
const indoorTagPosition = new THREE.Vector3(4.2, 4.05, -2.72);
function updateLabels() {
positionTag(
document.querySelector("#outdoorTag"),
outdoorTagPosition
);
positionTag(
document.querySelector("#indoorTag"),
indoorTagPosition
);
for (const activity of activities.values()) {
const labelPosition = activity.group.position.clone();
labelPosition.y += activity.definition.id === "craft" ? 1.75 : 1.52;
positionTag(activity.label, labelPosition);
}
if (state.selected && selectionBox.visible) {
selectionBox.setFromObject(activities.get(state.selected).group);
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateActivities(delta);
updateRain(delta);
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 300);
});
</script>
</body>
</html>
```