Prompt specification
Build or customize the Three.js 3D scene "Neighbors share a lit common room" 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: Neighbors share a lit common room
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/neighbors-share-a-lit-common-room-x3899
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: neighbors share a lit common room. Compose an apartment common room with portable lights, books, board games, and visitors; a brief power interruption changes activities while shared seating remains orderly. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (neighbors-share-a-lit-common-room-x3899):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Room — A Brief Interruption</title>
<style>
:root {
--ink: #252b2a;
--muted: #68706c;
--paper: rgba(250, 247, 240, 0.88);
--line: rgba(48, 55, 52, 0.16);
--teal: #487a76;
--amber: #d39a4a;
--red: #c95f4c;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d1c4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 52%, rgba(44, 40, 34, 0.13) 115%),
linear-gradient(to bottom, rgba(255,255,255,0.05), transparent 30%);
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-card {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid rgba(255,255,255,0.48);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 15px 45px rgba(53, 47, 38, 0.12);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
border-radius: 2px;
background: var(--teal);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 38px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
max-width: 340px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.status-card {
top: 24px;
right: 24px;
min-width: 190px;
padding: 12px 15px;
border: 1px solid rgba(255,255,255,0.5);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(53, 47, 38, 0.1);
backdrop-filter: blur(14px);
text-align: right;
}
.status-row {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #6e9b68;
box-shadow: 0 0 0 4px rgba(110, 155, 104, 0.12);
transition: 250ms ease;
}
.status-dot.offline {
background: var(--amber);
box-shadow: 0 0 0 4px rgba(211, 154, 74, 0.14), 0 0 14px rgba(211, 154, 74, 0.45);
}
#status-copy {
margin-top: 7px;
color: var(--muted);
font-size: 11px;
}
.controls {
position: fixed;
z-index: 8;
left: 50%;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
width: min(760px, calc(100vw - 32px));
padding: 12px;
transform: translateX(-50%);
border: 1px solid rgba(255,255,255,0.55);
border-radius: 18px;
background: rgba(250, 247, 240, 0.9);
box-shadow: 0 18px 55px rgba(53, 47, 38, 0.17);
backdrop-filter: blur(16px);
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255,255,255,0.65);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(48, 55, 52, 0.28);
background: #fff;
}
button:active { transform: translateY(0); }
#toggle {
min-width: 82px;
height: 42px;
color: #fff;
border-color: transparent;
background: var(--teal);
}
#replay, #reset-view {
height: 42px;
padding: 0 13px;
white-space: nowrap;
}
.timeline {
flex: 1;
min-width: 180px;
padding: 0 7px;
}
.timeline-meta {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.track {
position: relative;
height: 6px;
overflow: visible;
border-radius: 10px;
background: #dcd6ca;
}
#progress {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: var(--teal);
}
.marker {
position: absolute;
top: -3px;
width: 2px;
height: 12px;
border-radius: 2px;
background: rgba(48, 55, 52, 0.28);
}
.marker.outage {
background: var(--amber);
}
.marker.restore {
background: var(--red);
}
.phase-copy {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 7px;
color: #858b87;
font-size: 9px;
}
.hint {
position: fixed;
z-index: 4;
right: 25px;
bottom: 98px;
padding: 8px 11px;
border-radius: 999px;
background: rgba(250, 247, 240, 0.68);
color: #747b77;
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(10px);
}
.visitor-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255,255,255,0.58);
border-radius: 999px;
background: rgba(250, 247, 240, 0.83);
box-shadow: 0 6px 18px rgba(40, 37, 31, 0.1);
color: #4e5652;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
}
.visitor-label::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--label-color, var(--teal));
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.subtitle { display: none; }
.status-card { display: none; }
.controls { bottom: 14px; gap: 7px; padding: 9px; }
#replay { display: none; }
#reset-view { padding: 0 10px; }
.phase-copy { display: none; }
.hint, .visitor-label { display: none; }
.timeline { padding: 0 3px; }
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="vignette"></div>
<section class="hud title-card">
<div class="eyebrow">Apartment vignette · floor 04</div>
<h1>The common room</h1>
<p class="subtitle">
Four neighbors share books, games, and a little light. When the grid fails,
their activities change—but the room and its seating stay composed.
</p>
</section>
<section class="hud status-card">
<div class="status-row">
<span id="status-dot" class="status-dot"></span>
<span id="status-title">Grid online</span>
</div>
<div id="status-copy">Reading, tea, and a board game</div>
</section>
<div id="labels"></div>
<div class="hint">Drag to orbit · scroll to zoom · Space to pause</div>
<section class="controls" aria-label="Scene controls">
<button id="toggle" type="button">Pause</button>
<button id="replay" type="button">↻ Replay</button>
<div class="timeline">
<div class="timeline-meta">
<span>Shared floor</span>
<span id="time">00:00 / 00:17</span>
</div>
<div class="track">
<div id="progress"></div>
<span class="marker" style="left:28.2%"></span>
<span class="marker outage" style="left:34.1%"></span>
<span class="marker" style="left:61.2%"></span>
<span class="marker restore" style="left:66.8%"></span>
</div>
<div class="phase-copy">
<span>Reading & tea</span>
<span>Portable light</span>
<span>Power returns</span>
</div>
</div>
<button id="reset-view" type="button">Reset view</button>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d1c4);
scene.fog = new THREE.Fog(0xd8d1c4, 24, 43);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.25, 1.05, -0.25);
let cameraTheta = 0.60;
let cameraPhi = 0.86;
let cameraRadius = window.innerWidth < 720 ? 24 : 19;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const mat = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
const palette = {
wall: mat(0xded5c6),
wallShade: mat(0xc8bbaa),
floorDark: mat(0x765842),
floorA: mat(0xb88961),
floorB: mat(0xc0936c),
wood: mat(0x936846),
woodDark: mat(0x59463a),
woodLight: mat(0xc6a27b),
cream: mat(0xeee2ca),
teal: mat(0x4d7774),
tealDark: mat(0x355c5b),
rust: mat(0xc96f54),
mustard: mat(0xd3a449),
blue: mat(0x55779b),
green: mat(0x718768),
charcoal: mat(0x3f4543),
plant: mat(0x5d805e),
plantDark: mat(0x3f6649),
terracotta: mat(0xb96f50),
paper: mat(0xf5ead2),
brass: mat(0xb08a4d, { metalness: 0.55, roughness: 0.42 }),
black: mat(0x252a29),
white: mat(0xf4f1e8)
};
function addMesh(parent, geometry, material, position = [0, 0, 0], rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(parent, size, position, material, rotation = [0, 0, 0]) {
return addMesh(
parent,
new THREE.BoxGeometry(...size),
material,
position,
rotation
);
}
function cylinder(parent, rt, rb, height, position, material, segments = 16, rotation = [0, 0, 0]) {
return addMesh(
parent,
new THREE.CylinderGeometry(rt, rb, height, segments),
material,
position,
rotation
);
}
function ball(parent, radius, position, material, scale = [1, 1, 1]) {
const mesh = addMesh(parent, new THREE.SphereGeometry(radius, 14, 10), material, position);
mesh.scale.set(...scale);
return mesh;
}
function group(parent, position = [0, 0, 0], rotation = [0, 0, 0]) {
const g = new THREE.Group();
g.position.set(...position);
g.rotation.set(...rotation);
parent.add(g);
return g;
}
function smoothstep(a, b, value) {
const x = THREE.MathUtils.clamp((value - a) / (b - a), 0, 1);
return x * x * (3 - 2 * x);
}
function bezierPoint(t, p0, p1, p2) {
const u = 1 - t;
return new THREE.Vector3(
u * u * p0.x + 2 * u * t * p1.x + t * t * p2.x,
0,
u * u * p0.z + 2 * u * t * p1.z + t * t * p2.z
);
}
// -------------------------------------------------------------------------
// Architecture: cutaway apartment room
// -------------------------------------------------------------------------
box(scene, [16, 0.24, 11], [0, -0.15, 0], palette.floorDark);
const plankMaterials = [palette.floorA, palette.floorB, palette.floorA, palette.floorB];
for (let i = 0; i < 20; i++) {
const x = -7.6 + i * 0.8;
box(
scene,
[0.785, 0.045, 10.9],
[x, -0.005, 0],
plankMaterials[i % plankMaterials.length]
);
}
// Back wall, built around a large window.
box(scene, [2.3, 6, 0.25], [-6.85, 3, -5.58], palette.wall);
box(scene, [6.6, 6, 0.25], [4.7, 3, -5.58], palette.wall);
box(scene, [6.4, 1.4, 0.25], [-2, 0.7, -5.58], palette.wall);
box(scene, [6.4, 1.5, 0.25], [-2, 5.25, -5.58], palette.wall);
box(scene, [0.25, 6, 11], [-8, 3, 0], palette.wall);
box(scene, [16, 0.16, 0.11], [0, 0.15, -5.42], palette.cream);
box(scene, [0.11, 0.16, 11], [-7.84, 0.15, 0], palette.cream);
const glass = new THREE.MeshStandardMaterial({
color: 0xa9c6c7,
roughness: 0.24,
metalness: 0,
transparent: true,
opacity: 0.48
});
const windowPane = addMesh(
scene,
new THREE.PlaneGeometry(6.4, 3.1),
glass,
[-2, 2.95, -5.48]
);
windowPane.castShadow = false;
const skyline = group(scene);
const cityColors = [0x82999b, 0x708487, 0x9aa7a2, 0x687b80];
const buildingXs = [-5.0, -4.25, -3.55, -2.8, -2.05, -1.35, -0.55, 0.3, 0.9];
buildingXs.forEach((x, i) => {
const h = 0.65 + (i % 4) * 0.28;
box(
skyline,
[0.58, h, 0.08],
[x, 1.4 + h / 2, -5.40],
mat(cityColors[i % cityColors.length])
);
if (i % 2 === 0) {
box(
skyline,
[0.11, 0.12, 0.03],
[x - 0.12, 1.75 + (i % 3) * 0.2, -5.34],
mat(0xd9c78e, { emissive: 0xb68d4c, emissiveIntensity: 0.25 })
);
}
});
const moon = addMesh(
scene,
new THREE.CircleGeometry(0.34, 24),
mat(0xe9d4a4, { emissive: 0xd8b56e, emissiveIntensity: 0.35 }),
[0.4, 4.03, -5.36]
);
moon.castShadow = false;
const frameMat = palette.cream;
box(scene, [6.55, 0.13, 0.15], [-2, 1.4, -5.31], frameMat);
box(scene, [6.55, 0.13, 0.15], [-2, 4.5, -5.31], frameMat);
box(scene, [0.13, 3.17, 0.15], [-5.22, 2.95, -5.31], frameMat);
box(scene, [0.13, 3.17, 0.15], [1.22, 2.95, -5.31], frameMat);
box(scene, [0.09, 3.1, 0.12], [-2, 2.95, -5.29], frameMat);
const curtainMat = mat(0xc8b797, { roughness: 1 });
for (const side of [-1, 1]) {
for (let i = 0; i < 5; i++) {
cylinder(
scene,
0.11,
0.13,
3.75,
[-2 + side * (3.55 + i * 0.13), 2.68, -5.12 + Math.sin(i) * 0.025],
curtainMat,
10
);
}
}
box(scene, [7.7, 0.08, 0.08], [-2, 4.59, -5.08], palette.brass);
// Wall art on the left wall.
const art = group(scene, [-7.82, 3.05, 1.7], [0, Math.PI / 2, 0]);
box(art, [1.55, 1.85, 0.09], [0, 0, 0], palette.woodDark);
box(art, [1.35, 1.65, 0.035], [0, 0, 0.06], palette.cream);
addMesh(art, new THREE.CircleGeometry(0.42, 24), mat(0xc9825f), [0, 0.25, 0.09]);
box(art, [0.75, 0.18, 0.03], [-0.15, -0.35, 0.1], palette.teal);
// -------------------------------------------------------------------------
// Rug, sofa, armchairs, tables
// -------------------------------------------------------------------------
box(scene, [7.4, 0.045, 5.1], [-1.45, 0.035, 0.1], mat(0xb89b72));
box(scene, [6.9, 0.012, 4.6], [-1.45, 0.063, 0.1], mat(0xd4bb8a));
for (let i = 0; i < 9; i++) {
box(
scene,
[0.055, 0.013, 4.25],
[-4.55 + i * 0.78, 0.074, 0.1],
mat(i % 2 ? 0xb98561 : 0x758d79)
);
}
const sofa = group(scene, [-3.5, 0, -4.0]);
box(sofa, [4.5, 0.38, 1.65], [0, 0.43, 0], palette.tealDark);
box(sofa, [4.35, 1.15, 0.28], [0, 1.13, -0.72], palette.teal);
box(sofa, [0.28, 0.88, 1.58], [-2.13, 0.91, -0.02], palette.teal);
box(sofa, [0.28, 0.88, 1.58], [2.13, 0.91, -0.02], palette.teal);
for (let i = 0; i < 3; i++) {
box(sofa, [1.29, 0.28, 1.28], [-1.38 + i * 1.38, 0.72, 0.02], palette.teal);
}
const pillowA = box(sofa, [0.62, 0.62, 0.17], [-1.42, 1.24, -0.47], palette.mustard, [0.05, 0, -0.12]);
pillowA.rotation.x = -0.12;
const pillowB = box(sofa, [0.6, 0.6, 0.18], [1.35, 1.25, -0.47], palette.rust, [-0.06, 0, 0.1]);
pillowB.rotation.x = -0.1;
function makeArmchair(x, z, rotation, fabric) {
const chair = group(scene, [x, 0, z], [0, rotation, 0]);
box(chair, [1.62, 0.32, 1.48], [0, 0.43, 0], palette.woodDark);
box(chair, [1.42, 0.28, 1.2], [0, 0.66, 0.04], fabric);
box(chair, [1.48, 1.18, 0.24], [0, 1.25, -0.57], fabric, [-0.12, 0, 0]);
box(chair, [0.2, 0.72, 1.35], [-0.73, 0.92, -0.01], fabric);
box(chair, [0.2, 0.72, 1.35], [0.73, 0.92, -0.01], fabric);
for (const lx of [-0.58, 0.58]) {
for (const lz of [-0.48, 0.48]) {
cylinder(chair, 0.06, 0.07, 0.4, [lx, 0.2, lz], palette.woodDark, 10);
}
}
return chair;
}
makeArmchair(-5.8, -0.25, 0.62, palette.rust);
const coffeeTable = group(scene, [-1.7, 0, 0.05]);
box(coffeeTable, [3.35, 0.14, 1.65], [0, 0.59, 0], palette.wood);
box(coffeeTable, [2.95, 0.04, 1.28], [0, 0.68, 0], palette.woodLight);
for (const x of [-1.35, 1.35]) {
for (const z of [-0.56, 0.56]) {
cylinder(coffeeTable, 0.07, 0.08, 0.5, [x, 0.27, z], palette.woodDark, 10);
}
}
const gameTable = group(scene, [3.2, 0, -0.25]);
box(gameTable, [2.75, 0.16, 2.15], [0, 0.78, 0], palette.wood);
box(gameTable, [2.42, 0.025, 1.82], [0, 0.875, 0], palette.woodLight);
for (const x of [-1.08, 1.08]) {
for (const z of [-0.76, 0.76]) {
cylinder(gameTable, 0.08, 0.09, 0.69, [x, 0.36, z], palette.woodDark, 10);
}
}
function makeChair(x, z, rotation = 0) {
const chair = group(scene, [x, 0, z], [0, rotation, 0]);
box(chair, [0.95, 0.16, 0.88], [0, 0.53, 0], palette.tealDark);
box(chair, [0.95, 0.92, 0.14], [0, 1.0, -0.39], palette.tealDark);
for (const lx of [-0.35, 0.35]) {
for (const lz of [-0.3, 0.3]) {
cylinder(chair, 0.045, 0.05, 0.48, [lx, 0.25, lz], palette.woodDark, 8);
}
}
return chair;
}
makeChair(3.15, 1.38, Math.PI);
makeChair(3.75, -1.7, 0);
makeChair(5.22, 1.38, Math.PI);
// -------------------------------------------------------------------------
// Kitchenette and shelves
// -------------------------------------------------------------------------
const kitchen = group(scene, [5.35, 0, -4.72]);
box(kitchen, [4.75, 0.88, 1.1], [0, 0.48, 0], palette.tealDark);
box(kitchen, [4.9, 0.12, 1.22], [0, 0.98, 0], palette.cream);
for (let i = 0; i < 5; i++) {
box(kitchen, [0.84, 0.65, 0.035], [-1.87 + i * 0.94, 0.51, 0.57], palette.teal);
box(kitchen, [0.22, 0.035, 0.045], [-1.87 + i * 0.94, 0.73, 0.60], palette.brass);
}
box(kitchen, [0.78, 0.035, 0.63], [-1.35, 1.06, 0.03], mat(0x748081, { metalness: 0.4, roughness: 0.35 }));
cylinder(kitchen, 0.035, 0.035, 0.55, [-1.35, 1.32, -0.31], palette.brass, 10);
const faucetArc = addMesh(
kitchen,
new THREE.TorusGeometry(0.18, 0.035, 8, 18, Math.PI),
palette.brass,
[-1.35, 1.58, -0.14],
[0, Math.PI / 2, 0]
);
faucetArc.castShadow = true;
const kettle = cylinder(kitchen, 0.22, 0.28, 0.34, [0.55, 1.21, -0.05], palette.rust, 14);
addMesh(kitchen, new THREE.TorusGeometry(0.15, 0.035, 8, 16, Math.PI), palette.brass, [0.55, 1.45, -0.05], [0, Math.PI / 2, 0]);
box(kitchen, [0.42, 0.03, 0.42], [1.55, 1.075, 0.02], palette.paper);
const shelf = group(scene, [-7.48, 0, -0.25], [0, Math.PI / 2, 0]);
box(shelf, [4.15, 3.15, 0.14], [0, 1.65, -0.30], palette.woodDark);
for (const y of [0.2, 1.08, 1.96, 2.85]) {
box(shelf, [4.2, 0.12, 0.72], [0, y, 0], palette.wood);
}
box(shelf, [0.12, 3.2, 0.72], [-2.04, 1.62, 0], palette.wood);
box(shelf, [0.12, 3.2, 0.72], [2.04, 1.62, 0], palette.wood);
const bookColors = [0xc16f54, 0x527c78, 0xd2a74f, 0x667c9b, 0x8b6e93, 0x6e8564, 0xd0b78d];
let bookIndex = 0;
for (const shelfY of [0.29, 1.17, 2.05]) {
let x = -1.82;
while (x < 1.72) {
const width = 0.11 + ((bookIndex * 7) % 5) * 0.025;
const height = 0.38 + ((bookIndex * 11) % 6) * 0.055;
const color = bookColors[bookIndex % bookColors.length];
const book = box(
shelf,
[width, height, 0.46],
[x + width / 2, shelfY + height / 2, 0.04],
mat(color)
);
book.rotation.z = bookIndex % 9 === 0 ? -0.07 : 0;
box(
shelf,
[width * 0.74, height * 0.88, 0.02],
[x + width / 2, shelfY + height / 2, 0.28],
palette.paper
);
x += width + 0.035;
bookIndex++;
}
}
// -------------------------------------------------------------------------
// Books, mugs, board game and plants
// -------------------------------------------------------------------------
function makeBookStack(parent, x, y, z, count = 3) {
let currentY = y;
for (let i = 0; i < count; i++) {
const cover = bookColors[(i + 2) % bookColors.length];
const w = 0.55 - i * 0.035;
const d = 0.39 - i * 0.02;
box(parent, [w, 0.055, d], [x + i * 0.025, currentY, z], mat(cover));
box(parent, [w - 0.035, 0.035, d - 0.025], [x + i * 0.025, currentY, z], palette.paper);
currentY += 0.065;
}
}
makeBookStack(coffeeTable, -0.85, 0.72, 0.04, 3);
makeBookStack(coffeeTable, 0.75, 0.72, -0.18, 2);
makeBookStack(kitchen, -0.75, 1.12, 0.04, 2);
function makeMug(parent, color = palette.blue, scale = 1) {
const mug = group(parent);
mug.scale.setScalar(scale);
cylinder(mug, 0.12, 0.10, 0.22, [0, 0.11, 0], color, 16);
cylinder(mug, 0.085, 0.085, 0.012, [0, 0.222, 0], mat(0x6b4431), 16);
addMesh(mug, new THREE.TorusGeometry(0.085, 0.022, 8, 14), color, [0.13, 0.12, 0]);
return mug;
}
makeMug(coffeeTable, palette.blue, 0.9);
makeMug(kitchen, palette.green, 0.9);
const board = group(gameTable, [0, 0.915, 0]);
box(board, [1.62, 0.025, 1.2], [0, 0, 0], mat(0xe4c994));
for (let i = 0; i < 6; i++) {
box(board, [0.014, 0.01, 1.12], [-0.7 + i * 0.28, 0.02, 0], palette.woodDark);
box(board, [1.52, 0.01, 0.014], [0, 0.02, -0.51 + i * 0.205], palette.woodDark);
}
const pieceMaterials = [palette.rust, palette.blue, palette.mustard, palette.green];
const piecePositions = [
[-0.52, 0.36], [-0.16, 0.16], [0.34, -0.28], [0.48, 0.34], [-0.43, -0.35]
];
piecePositions.forEach((p, i) => {
cylinder(board, 0.095, 0.11, 0.13, [p[0], 0.09, p[1]], pieceMaterials[i % 4], 12);
ball(board, 0.052, [p[0], 0.19, p[1]], pieceMaterials[i % 4], [1, 0.65, 1]);
});
const dice = group(scene, [3.9, 0.99, 0.02]);
box(dice, [0.17, 0.17, 0.17], [0, 0, 0], palette.white);
for (const p of [[-0.045, 0.09, 0.045], [0.045, 0.09, -0.045], [0, -0.09, 0]]) {
ball(dice, 0.017, p, palette.black);
}
function makePlant(x, z, scale = 1) {
const plant = group(scene, [x, 0, z]);
plant.scale.setScalar(scale);
cylinder(plant, 0.34, 0.25, 0.46, [0, 0.23, 0], palette.terracotta, 14);
cylinder(plant, 0.30, 0.30, 0.05, [0, 0.47, 0], mat(0x5e4937), 14);
for (let i = 0; i < 7; i++) {
const angle = i * 2.399;
const h = 0.55 + (i % 3) * 0.23;
const end = new THREE.Vector3(Math.cos(angle) * 0.38, h, Math.sin(angle) * 0.38);
cylinder(
plant,
0.025,
0.035,
h,
[end.x * 0.5, h * 0.5, end.z * 0.5],
palette.plantDark,
7,
[Math.sin(angle) * 0.22, 0, -Math.cos(angle) * 0.22]
);
const leaf = ball(plant, 0.34, [end.x, h, end.z], i % 2 ? palette.plant : palette.plantDark, [0.42, 1.15, 0.72]);
leaf.rotation.set(Math.sin(angle) * 0.5, angle, Math.cos(angle) * 0.45);
}
return plant;
}
makePlant(7.1, 3.6, 1.05);
makePlant(-7.1, 3.85, 0.8);
// -------------------------------------------------------------------------
// Portable lights and pendant
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf4ead9, 0x66706a, 1.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd9b0, 1.65);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const windowFill = new THREE.DirectionalLight(0xa8c8ce, 0.48);
windowFill.position.set(-3, 5, -8);
scene.add(windowFill);
const pendant = group(scene, [-0.3, 0, -0.85]);
cylinder(pendant, 0.025, 0.025, 1.2, [0, 5.35, 0], palette.charcoal, 8);
const pendantShade = cylinder(pendant, 0.28, 0.58, 0.48, [0, 4.6, 0], mat(0xc28e58, { side: THREE.DoubleSide }), 20);
const pendantBulbMaterial = mat(0xffe0a5, { emissive: 0xffb95d, emissiveIntensity: 1.7 });
ball(pendant, 0.18, [0, 4.39, 0], pendantBulbMaterial);
const pendantLight = new THREE.PointLight(0xffc87f, 34, 13, 2);
pendantLight.position.set(-0.3, 4.32, -0.85);
scene.add(pendantLight);
const floorLamp = group(scene, [-6.4, 0, -3.35]);
cylinder(floorLamp, 0.35, 0.39, 0.08, [0, 0.07, 0], palette.charcoal, 18);
cylinder(floorLamp, 0.035, 0.045, 2.65, [0, 1.4, 0], palette.brass, 10);
const floorShadeMaterial = mat(0xe5c18b, {
emissive: 0xe6a75c,
emissiveIntensity: 0.12,
side: THREE.DoubleSide
});
cylinder(floorLamp, 0.31, 0.53, 0.52, [0, 2.83, 0], floorShadeMaterial, 18);
const floorLampLight = new THREE.PointLight(0xffbd75, 4.5, 7, 2);
floorLampLight.position.set(-6.4, 2.65, -3.35);
scene.add(floorLampLight);
const taskLamp = group(coffeeTable, [0.15, 0.71, 0.35]);
cylinder(taskLamp, 0.18, 0.21, 0.045, [0, 0.02, 0], palette.charcoal, 14);
cylinder(taskLamp, 0.025, 0.025, 0.57, [0, 0.31, 0], palette.brass, 8, [0, 0, -0.3]);
const taskShadeMaterial = mat(0xe1a568, {
emissive: 0xe99d4e,
emissiveIntensity: 0.1,
side: THREE.DoubleSide
});
cylinder(taskLamp, 0.15, 0.24, 0.25, [-0.16, 0.63, 0], taskShadeMaterial, 14, [0, 0, -0.25]);
const taskLight = new THREE.PointLight(0xffc780, 2.5, 4.2, 2);
taskLight.position.set(-1.55, 1.32, 0.4);
scene.add(taskLight);
function makeLantern() {
const lantern = group(scene);
cylinder(lantern, 0.17, 0.19, 0.07, [0, 0.04, 0], palette.charcoal, 12);
const bulbMaterial = mat(0xe8c985, { emissive: 0xffb45a, emissiveIntensity: 0 });
cylinder(lantern, 0.13, 0.13, 0.27, [0, 0.205, 0], bulbMaterial, 12);
cylinder(lantern, 0.18, 0.16, 0.07, [0, 0.38, 0], palette.charcoal, 12);
const handle = addMesh(
lantern,
new THREE.TorusGeometry(0.12, 0.018, 8, 16, Math.PI),
palette.charcoal,
[0, 0.43, 0]
);
handle.castShadow = true;
const light = new THREE.PointLight(0xffb96c, 0, 5.2, 2);
light.position.set(0, 0.24, 0);
lantern.add(light);
lantern.userData.bulbMaterial = bulbMaterial;
lantern.userData.light = light;
return lantern;
}
const counterLantern = makeLantern();
counterLantern.position.set(5.55, 1.07, -4.28);
// -------------------------------------------------------------------------
// Stylized visitors
// -------------------------------------------------------------------------
function makeArm(side, parentArmRoot, shirtMaterial, skinMaterial) {
const arm = group(parentArmRoot, [side * 0.32, 0.36, 0]);
cylinder(arm, 0.085, 0.095, 0.33, [0, -0.165, 0], shirtMaterial, 9);
const forearm = group(arm, [0, -0.33, 0]);
cylinder(forearm, 0.065, 0.075, 0.31, [0, -0.155, 0], skinMaterial, 9);
const hand = group(forearm, [0, -0.34, 0]);
ball(hand, 0.075, [0, 0, 0], skinMaterial);
return { arm, forearm, hand };
}
function makePerson(options) {
const shirtMaterial = mat(options.shirt);
const skinMaterial = mat(options.skin);
const hairMaterial = mat(options.hair);
const trouserMaterial = mat(options.trousers ?? 0x465054);
const person = new THREE.Group();
scene.add(person);
const upper = group(person);
const torso = addMesh(
upper,
new THREE.CapsuleGeometry(0.235, 0.34, 4, 9),
shirtMaterial,
[0, 0.03, 0]
);
torso.scale.set(1, 1, 0.82);
cylinder(upper, 0.085, 0.09, 0.13, [0, 0.52, 0], skinMaterial, 10);
const head = group(upper, [0, 0.76, 0]);
ball(head, 0.235, [0, 0, 0], skinMaterial, [1, 1.04, 0.96]);
addMesh(
head,
new THREE.SphereGeometry(0.243, 12, 7, 0, Math.PI * 2, 0, Math.PI / 2),
hairMaterial,
[0, 0.015, 0]
);
ball(head, 0.052, [-0.215, -0.01, 0], skinMaterial, [0.55, 1, 0.75]);
ball(head, 0.052, [0.215, -0.01, 0], skinMaterial, [0.55, 1, 0.75]);
ball(head, 0.025, [-0.073, 0.035, 0.222], palette.black, [1, 1, 0.45]);
ball(head, 0.025, [0.073, 0.035, 0.222], palette.black, [1, 1, 0.45]);
ball(head, 0.027, [0, -0.018, 0.238], skinMaterial, [0.72, 0.85, 0.8]);
if (options.hairStyle === "bun") {
ball(head, 0.115, [0, 0.12, -0.205], hairMaterial);
} else if (options.hairStyle === "ponytail") {
ball(head, 0.13, [0, -0.05, -0.235], hairMaterial, [0.8, 1.6, 0.8]);
}
const parentArmRoot = upper;
const left = makeArm(-1, parentArmRoot, shirtMaterial, skinMaterial);
const right = makeArm(1, parentArmRoot, shirtMaterial, skinMaterial);
const pelvis = ball(person, 0.25, [0, 1.02, 0], trouserMaterial, [1, 0.55, 0.85]);
function makeLeg(side) {
const thigh = group(person, [side * 0.14, 1.02, 0]);
cylinder(thigh, 0.105, 0.12, 0.45, [0, -0.225, 0], trouserMaterial, 9);
const shin = group(thigh, [0, -0.45, 0]);
cylinder(shin, 0.08, 0.095, 0.43, [0, -0.215, 0], trouserMaterial, 9);
box(shin, [0.19, 0.11, 0.30], [0, -0.44, 0.055], palette.charcoal);
return { thigh, shin };
}
const leftLeg = makeLeg(-1);
const rightLeg = makeLeg(1);
const result = {
group: person,
upper,
torso,
head,
armL: left.arm,
armR: right.arm,
forearmL: left.forearm,
forearmR: right.forearm,
handL: left.hand,
handR: right.hand,
thighL: leftLeg.thigh,
thighR: rightLeg.thigh,
shinL: leftLeg.shin,
shinR: rightLeg.shin,
pelvis
};
result.setSeat = (amount) => {
const hipY = THREE.MathUtils.lerp(1.02, 0.66, amount);
upper.position.y = THREE.MathUtils.lerp(1.32, 0.95, amount);
pelvis.position.y = hipY;
leftLeg.thigh.position.y = hipY;
rightLeg.thigh.position.y = hipY;
leftLeg.thigh.rotation.x = -Math.PI / 2 * amount;
rightLeg.thigh.rotation.x = -Math.PI / 2 * amount;
leftLeg.shin.rotation.x = Math.PI / 2 * amount;
rightLeg.shin.rotation.x = Math.PI / 2 * amount;
};
result.setSeat(options.seated ? 1 : 0);
return result;
}
function makeOpenBook(parent, color = 0x557c9b) {
const book = group(parent);
const coverMaterial = mat(color);
box(book, [0.28, 0.045, 0.34], [-0.14, 0, 0], coverMaterial, [0, 0, -0.07]);
box(book, [0.28, 0.045, 0.34], [0.14, 0, 0], coverMaterial, [0, 0, 0.07]);
box(book, [0.25, 0.025, 0.31], [-0.13, 0.032, 0.005], palette.paper, [0, 0, -0.05]);
box(book, [0.25, 0.025, 0.31], [0.13, 0.032, 0.005], palette.paper, [0, 0, 0.05]);
return book;
}
const mara = makePerson({
shirt: 0xd2a449,
skin: 0xb97855,
hair: 0x342b28,
trousers: 0x485a62,
hairStyle: "bun",
seated: true
});
mara.group.position.set(-3.28, 0, -3.68);
mara.group.rotation.y = 0.04;
const maraBook = makeOpenBook(mara.upper, 0x557c9b);
maraBook.position.set(0, -0.12, 0.47);
maraBook.rotation.x = -0.16;
const phoneGroup = group(mara.upper);
const phoneMaterial = mat(0x7ca9d7, { emissive: 0x4e8fcf, emissiveIntensity: 0 });
box(phoneGroup, [0.13, 0.23, 0.025], [0, 0, 0], palette.charcoal);
box(phoneGroup, [0.105, 0.19, 0.008], [0, 0, 0.018], phoneMaterial);
const phoneLight = new THREE.PointLight(0x78b9ff, 0, 2.0, 2);
phoneLight.position.set(0, 0, 0.08);
phoneGroup.add(phoneLight);
phoneGroup.position.set(0.2, 0.42, 0.43);
phoneGroup.rotation.x = -0.14;
phoneGroup.visible = false;
mara.userData = { phoneGroup, phoneMaterial, phoneLight };
const ivo = makePerson({
shirt: 0xc66f54,
skin: 0xe0ad83,
hair: 0x8b5e3e,
trousers: 0x52635e,
hairStyle: "ponytail",
seated: true
});
ivo.group.position.set(-5.65, 0, -0.12);
ivo.group.rotation.y = 0.62;
const ivoBook = makeOpenBook(ivo.upper, 0x718967);
ivoBook.position.set(0, -0.12, 0.47);
ivoBook.rotation.x = -0.15;
const noor = makePerson({
shirt: 0x55779b,
skin: 0x7f4e38,
hair: 0x201f1d,
trousers: 0x343b3f,
seated: true
});
noor.group.position.set(3.15, 0, 1.18);
noor.group.rotation.y = Math.PI;
const eli = makePerson({
shirt: 0x718768,
skin: 0xd39a72,
hair: 0x514236,
trousers: 0x444b49,
seated: false
});
eli.group.position.set(5.75, 0, -3.35);
eli.group.rotation.y = 0.12;
const eliMug = makeMug(eli.handR, palette.rust, 0.82);
eliMug.position.set(0, -0.07, 0.035);
const carriedLantern = makeLantern();
eli.upper.add(carriedLantern);
carriedLantern.position.set(0.43, -0.28, 0.43);
carriedLantern.scale.setScalar(0.78);
carriedLantern.visible = false;
// -------------------------------------------------------------------------
// Projected visitor labels
// -------------------------------------------------------------------------
const labelRoot = document.getElementById("labels");
function makeLabel(person, text, color) {
const el = document.createElement("div");
el.className = "visitor-label";
el.style.setProperty("--label-color", color);
el.textContent = text;
labelRoot.appendChild(el);
const anchor = new THREE.Object3D();
anchor.position.set(0, 1.13, 0);
person.upper.add(anchor);
return { el, anchor, text, color };
}
const labels = {
mara: makeLabel(mara, "Mara · reading", "#d2a449"),
ivo: makeLabel(ivo, "Ivo · reading", "#c66f54"),
noor: makeLabel(noor, "Noor · board game", "#55779b"),
eli: makeLabel(eli, "Eli · making tea", "#718768")
};
const projected = new THREE.Vector3();
function updateLabels() {
for (const key of Object.keys(labels)) {
const label = labels[key];
label.anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.el.style.display = visible ? "flex" : "none";
if (!visible) continue;
label.el.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.el.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight - 8}px`;
}
}
// -------------------------------------------------------------------------
// Animation timeline
// -------------------------------------------------------------------------
const CYCLE = 17;
let simulationTime = 0;
let playing = true;
const clock = new THREE.Clock();
const pauseButton = document.getElementById("toggle");
const replayButton = document.getElementById("replay");
const resetViewButton = document.getElementById("reset-view");
const progressBar = document.getElementById("progress");
const timeLabel = document.getElementById("time");
const statusDot = document.getElementById("status-dot");
const statusTitle = document.getElementById("status-title");
const statusCopy = document.getElementById("status-copy");
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "Pause" : "Play";
});
replayButton.addEventListener("click", () => {
simulationTime = 0;
playing = true;
pauseButton.textContent = "Pause";
});
function resetView() {
cameraTheta = 0.60;
cameraPhi = 0.86;
cameraRadius = window.innerWidth < 720 ? 24 : 19;
updateCamera();
}
resetViewButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") replayButton.click();
});
function outageAmountAt(t) {
if (t < 4.8) return 0;
if (t < 5.6) return smoothstep(4.8, 5.6, t);
if (t < 10.4) return 1;
if (t < 11.4) return 1 - smoothstep(10.4, 11.4, t);
return 0;
}
function hostProgressAt(t) {
if (t < 5.2) return 0;
if (t < 8.8) return smoothstep(5.2, 8.8, t);
if (t < 12.2) return 1;
if (t < 15.8) return 1 - smoothstep(12.2, 15.8, t);
return 0;
}
const hostStart = new THREE.Vector3(5.75, 0, -3.35);
const hostControl = new THREE.Vector3(6.55, 0, -0.8);
const hostEnd = new THREE.Vector3(5.22, 0, 1.18);
function updateScene(t) {
const outage = outageAmountAt(t);
const active = 1 - outage;
// Grid power fades; portable lights take over.
hemisphere.intensity = THREE.MathUtils.lerp(1.05, 0.11, outage);
sun.intensity = THREE.MathUtils.lerp(1.65, 0.18, outage);
windowFill.intensity = THREE.MathUtils.lerp(0.48, 0.32, outage);
pendantLight.intensity = THREE.MathUtils.lerp(34, 0, outage);
floorLampLight.intensity = THREE.MathUtils.lerp(4.5, 20, outage);
taskLight.intensity = THREE.MathUtils.lerp(2.5, 12, outage);
pendantBulbMaterial.emissiveIntensity = THREE.MathUtils.lerp(1.7, 0, outage);
floorShadeMaterial.emissiveIntensity = THREE.MathUtils.lerp(0.12, 1.45, outage);
taskShadeMaterial.emissiveIntensity = THREE.MathUtils.lerp(0.1, 1.25, outage);
renderer.toneMappingExposure = THREE.MathUtils.lerp(1.08, 0.86, outage);
// Mara changes from reading to a phone-lit pause without leaving the sofa.
mara.armL.rotation.x = THREE.MathUtils.lerp(-1.05, -0.28, outage);
mara.armL.rotation.z = THREE.MathUtils.lerp(0.15, 0.05, outage);
mara.armR.rotation.x = THREE.MathUtils.lerp(-1.08, -1.92, outage);
mara.armR.rotation.z = THREE.MathUtils.lerp(-0.15, -0.08, outage);
mara.head.rotation.y = THREE.MathUtils.lerp(0, -0.12, outage);
maraBook.position.y = THREE.MathUtils.lerp(-0.12, -0.24, outage);
maraBook.position.z = THREE.MathUtils.lerp(0.47, 0.34, outage);
mara.userData.phoneGroup.visible = outage > 0.025;
mara.userData.phoneMaterial.emissiveIntensity = outage * 2.2;
mara.userData.phoneLight.intensity = outage * 2.4;
// Ivo closes the book and listens; his chair stays where it is.
ivo.armL.rotation.x = THREE.MathUtils.lerp(-1.0, -0.48, outage);
ivo.armR.rotation.x = THREE.MathUtils.lerp(-1.0, -0.48, outage);
ivo.armL.rotation.z = THREE.MathUtils.lerp(0.16, -0.08, outage);
ivo.armR.rotation.z = THREE.MathUtils.lerp(-0.16, 0.08, outage);
ivo.head.rotation.y = THREE.MathUtils.lerp(0, 0.42, outage);
ivoBook.scale.x = THREE.MathUtils.lerp(1, 0.10, outage);
ivoBook.rotation.y = THREE.MathUtils.lerp(0, 0.22, outage);
// The board game pauses during the interruption; the seating remains in order.
noor.armR.rotation.x = -0.92 + Math.sin(t * 3.2) * 0.14 * active;
noor.armR.rotation.z = -0.12;
noor.head.rotation.y = THREE.MathUtils.lerp(0, -0.48, outage);
noor.head.rotation.x = THREE.MathUtils.lerp(0, 0.08, outage);
dice.position.x = 3.9 + Math.sin(t * 3.2) * 0.18 * active;
dice.position.y = 0.99 + Math.abs(Math.sin(t * 3.2)) * 0.08 * active;
dice.rotation.y = t * 0.8 * active;
// Eli carries the battery lantern to the empty chair and joins the circle.
const hostProgress = hostProgressAt(t);
const hostPosition = bezierPoint(hostProgress, hostStart, hostControl, hostEnd);
eli.group.position.copy(hostPosition);
eli.group.rotation.y = Math.PI * smoothstep(0.42, 1, hostProgress);
const seatAmount = THREE.MathUtils.clamp((hostProgress - 0.28) / 0.44, 0, 1);
eli.setSeat(seatAmount * seatAmount * (3 - 2 * seatAmount));
eli.armL.rotation.x = THREE.MathUtils.lerp(-0.28, -0.82, seatAmount);
eli.armR.rotation.x = THREE.MathUtils.lerp(-0.18, -0.48, seatAmount);
eli.head.rotation.y = THREE.MathUtils.lerp(0, -0.22, outage);
const carryingLantern = t >= 5.2 && t < 15.8;
carriedLantern.visible = carryingLantern;
counterLantern.visible = !carryingLantern;
eliMug.visible = !carryingLantern;
carriedLantern.userData.bulbMaterial.emissiveIntensity = outage * 3.1;
carriedLantern.userData.light.intensity = outage * 22;
// Dynamic label language.
labels.mara.el.textContent = outage > 0.45 ? "Mara · phone light" : "Mara · reading";
labels.ivo.el.textContent = outage > 0.45 ? "Ivo · listening" : "Ivo · reading";
labels.noor.el.textContent = outage > 0.45 ? "Noor · game paused" : "Noor · board game";
labels.eli.el.textContent = outage > 0.45 ? "Eli · joins the circle" : "Eli · making tea";
// UI state and timeline.
progressBar.style.width = `${(t / CYCLE) * 100}%`;
timeLabel.textContent = `00:${String(Math.floor(t)).padStart(2, "0")} / 00:17`;
if (outage > 0.72) {
statusDot.classList.add("offline");
statusTitle.textContent = "Brief outage";
statusCopy.textContent = "Portable lights on · the room stays orderly";
} else if ((t > 4.8 && t < 5.6) || (t > 10.4 && t < 11.4)) {
statusDot.classList.toggle("offline", t < 10.4);
statusTitle.textContent = t < 10.4 ? "Power fading" : "Power restored";
statusCopy.textContent = t < 10.4 ? "Activities adapt to the light" : "The grid is coming back";
} else {
statusDot.classList.remove("offline");
statusTitle.textContent = "Grid online";
statusCopy.textContent = "Reading, tea, and a board game";
}
}
// -------------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel/pinch to zoom
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
const activePointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 1) {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
cameraRadius = THREE.MathUtils.clamp(cameraRadius + (pinchDistance - distance) * 0.02, 11, 29);
pinchDistance = distance;
updateCamera();
return;
}
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.005, 0.43, 1.35);
updateCamera();
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 0) dragging = false;
if (activePointers.size < 2) pinchDistance = 0;
renderer.domElement.classList.remove("dragging");
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(cameraRadius + event.deltaY * 0.012, 11, 29);
updateCamera();
}, { passive: false });
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
simulationTime = (simulationTime + delta) % CYCLE;
}
updateScene(simulationTime);
updateCamera();
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```