Prompt specification
Build or customize the Three.js 3D scene "Evening light interruption sequence" 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: Evening light interruption sequence
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/evening-light-interruption-sequence-x3898
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a household power interruption and alternative activities. Animate a room light turning off, a character locating the lantern, and the lantern illuminating the table; preserve object positions so the causal sequence stays clear. Low-poly.
Working Three.js Starter (evening-light-interruption-sequence-x3898):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>When the Lights Go Out</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(12, 22, 33, 0.82);
--border: rgba(255, 255, 255, 0.14);
--muted: #a9b8c5;
--text: #f4f1e8;
--amber: #ffbd66;
--blue: #77c7df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09131e;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.glass {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
header {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
max-width: 520px;
pointer-events: none;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.65);
}
.eyebrow {
margin-bottom: 6px;
color: var(--amber);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(26px, 3.2vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
}
header p {
max-width: 460px;
margin: 10px 0 0;
color: #c4d0d8;
font-size: 13px;
line-height: 1.5;
}
#story-panel {
position: fixed;
z-index: 5;
top: 22px;
right: 24px;
width: 286px;
padding: 17px;
border-radius: 16px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: #dbe4e9;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#power-badge {
padding: 5px 8px;
border-radius: 999px;
color: #8ce2b2;
background: rgba(80, 220, 145, 0.11);
border: 1px solid rgba(80, 220, 145, 0.25);
letter-spacing: 0.06em;
transition: color 0.2s, background 0.2s;
}
#power-badge.off {
color: #ff8c91;
background: rgba(255, 85, 92, 0.11);
border-color: rgba(255, 85, 92, 0.26);
}
.steps {
display: grid;
gap: 9px;
}
.step {
display: grid;
grid-template-columns: 26px 1fr;
align-items: center;
gap: 9px;
color: #82919d;
font-size: 12px;
transition: color 0.25s;
}
.step-number {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 50%;
font-size: 10px;
font-weight: 800;
}
.step.active {
color: #fff7e9;
}
.step.active .step-number {
color: #17130d;
background: var(--amber);
border-color: var(--amber);
box-shadow: 0 0 18px rgba(255, 189, 102, 0.3);
}
.step.done {
color: #a9b9c4;
}
.step.done .step-number {
color: var(--blue);
border-color: rgba(119, 199, 223, 0.45);
}
#bottom-panel {
position: fixed;
z-index: 5;
left: 24px;
right: 24px;
bottom: 20px;
display: grid;
grid-template-columns: minmax(260px, 1fr) minmax(340px, 620px);
align-items: center;
gap: 22px;
padding: 16px 18px;
border-radius: 17px;
}
#caption-wrap {
min-width: 0;
}
#phase {
margin-bottom: 4px;
color: var(--amber);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#caption {
color: #eef2f3;
font-size: 14px;
line-height: 1.4;
}
#controls {
display: grid;
grid-template-columns: auto auto 1fr;
align-items: center;
gap: 9px;
}
button {
height: 36px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 9px;
color: #edf2f3;
background: rgba(255, 255, 255, 0.07);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background 0.2s, transform 0.1s;
}
button:hover {
background: rgba(255, 255, 255, 0.12);
}
button:active {
transform: translateY(1px);
}
#timeline {
width: 100%;
height: 5px;
margin: 0 4px;
accent-color: var(--amber);
cursor: pointer;
}
#hint {
position: fixed;
z-index: 4;
right: 25px;
bottom: 112px;
color: rgba(220, 231, 237, 0.52);
font-size: 10px;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 3;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 6px;
color: #e7edf0;
background: rgba(8, 16, 24, 0.74);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transform: translate(-50%, -50%);
pointer-events: none;
white-space: nowrap;
}
.world-label.amber {
color: #ffd49a;
border-color: rgba(255, 189, 102, 0.35);
}
.world-label.blue {
color: #9ee8ff;
border-color: rgba(119, 199, 223, 0.32);
}
@media (max-width: 800px) {
header {
top: 16px;
left: 16px;
right: 16px;
}
header p {
display: none;
}
#story-panel {
display: none;
}
#bottom-panel {
left: 12px;
right: 12px;
bottom: 12px;
grid-template-columns: 1fr;
gap: 12px;
padding: 13px;
}
#controls {
grid-template-columns: auto auto 1fr;
}
#hint {
display: none;
}
.world-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header>
<div class="eyebrow">A household story in five moments</div>
<h1>When the Lights Go Out</h1>
<p>
A low-poly power interruption becomes an opportunity to read by lantern light
and listen to a battery-powered radio.
</p>
</header>
<aside id="story-panel" class="glass">
<div class="panel-title">
<span>Sequence</span>
<span id="power-badge">Grid on</span>
</div>
<div class="steps">
<div class="step active" data-step="0">
<span class="step-number">1</span>
<span>Household light</span>
</div>
<div class="step" data-step="1">
<span class="step-number">2</span>
<span>Power interruption</span>
</div>
<div class="step" data-step="2">
<span class="step-number">3</span>
<span>Locate the lantern</span>
</div>
<div class="step" data-step="3">
<span class="step-number">4</span>
<span>Carry and place it</span>
</div>
<div class="step" data-step="4">
<span class="step-number">5</span>
<span>Read and listen</span>
</div>
</div>
</aside>
<div id="bottom-panel" class="glass">
<div id="caption-wrap">
<div id="phase">Household power</div>
<div id="caption">The room is lit by the overhead household lamp.</div>
</div>
<div id="controls">
<button id="play" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<input
id="timeline"
type="range"
min="0"
max="18"
step="0.01"
value="0"
aria-label="Animation timeline"
>
</div>
</div>
<div id="hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<div id="label-main" class="world-label blue">Main light</div>
<div id="label-lantern" class="world-label amber">Lantern</div>
<div id="label-table" class="world-label">Activity table</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const playButton = document.getElementById("play");
const restartButton = document.getElementById("restart");
const timeline = document.getElementById("timeline");
const phaseElement = document.getElementById("phase");
const captionElement = document.getElementById("caption");
const powerBadge = document.getElementById("power-badge");
const stepElements = [...document.querySelectorAll(".step")];
const DURATION = 18;
const state = {
time: 0,
playing: true,
lastTime: performance.now()
};
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
const lerp = (a, b, t) => a + (b - a) * t;
function smooth(a, b, value) {
const x = clamp((value - a) / (b - a), 0, 1);
return x * x * (3 - 2 * x);
}
function range(value, a, b) {
return clamp((value - a) / (b - a), 0, 1);
}
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a1420);
scene.fog = new THREE.Fog(0x0a1420, 15, 29);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
const orbit = {
theta: 0.69,
phi: 1.01,
radius: 15.8,
targetTheta: 0.69,
targetPhi: 1.01,
targetRadius: 15.8
};
function updateCamera() {
orbit.theta = lerp(orbit.theta, orbit.targetTheta, 0.09);
orbit.phi = lerp(orbit.phi, orbit.targetPhi, 0.09);
orbit.radius = lerp(orbit.radius, orbit.targetRadius, 0.09);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
// Direct camera controls, without addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.targetTheta = clamp(orbit.targetTheta - dx * 0.005, -0.2, 1.28);
orbit.targetPhi = clamp(orbit.targetPhi - dy * 0.004, 0.65, 1.28);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = clamp(
orbit.targetRadius + event.deltaY * 0.012,
10.5,
21
);
},
{ passive: false }
);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function box(size, position, mat, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
topRadius,
bottomRadius,
height,
position,
mat,
parent = scene,
segments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function ico(radius, position, mat, parent = scene, detail = 1) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const wallMat = material(0x4d6670);
const leftWallMat = material(0x435b66);
const trimMat = material(0x263943);
const darkWoodMat = material(0x513b2c);
const woodMat = material(0x8e6845);
const darkMetalMat = material(0x243039, { metalness: 0.35 });
const creamMat = material(0xd8d0b8);
const blueFabricMat = material(0x355c6d);
const tealFabricMat = material(0x2e7777);
// ------------------------------------------------------------
// Room shell and fixed furnishings
// ------------------------------------------------------------
box([10, 0.3, 8], [0, -0.17, 0], material(0x343a3d));
const plankColors = [0x74513a, 0x805a40, 0x6d4a35, 0x885f42];
for (let i = 0; i < 9; i++) {
const plank = box(
[1.08, 0.055, 7.8],
[-4.5 + i * 1.125, 0.005, 0],
material(plankColors[i % plankColors.length])
);
plank.receiveShadow = true;
}
box([10, 5.4, 0.25], [0, 2.5, -4], wallMat);
box([0.25, 5.4, 8], [-5, 2.5, 0], leftWallMat);
box([10, 0.16, 0.1], [0, 0.12, -3.83], trimMat);
box([0.1, 0.16, 8], [-4.83, 0.12, 0], trimMat);
// Night window.
const glassMat = material(0x153b55, {
emissive: 0x12344a,
emissiveIntensity: 0.38,
roughness: 0.28
});
box([2.25, 1.55, 0.05], [2.05, 3.25, -3.84], glassMat);
box([2.42, 0.09, 0.13], [2.05, 4.04, -3.75], trimMat);
box([2.42, 0.09, 0.13], [2.05, 2.46, -3.75], trimMat);
box([0.09, 1.67, 0.13], [0.9, 3.25, -3.75], trimMat);
box([0.09, 1.67, 0.13], [3.2, 3.25, -3.75], trimMat);
box([0.07, 1.55, 0.1], [2.05, 3.25, -3.73], trimMat);
// A small wall outlet makes the source of the outage explicit.
box([0.24, 0.3, 0.06], [-0.45, 1.35, -3.82], creamMat);
const outletLedMat = material(0x67dc9a, {
emissive: 0x67dc9a,
emissiveIntensity: 1.8
});
ico(0.025, [-0.45, 1.43, -3.77], outletLedMat, scene, 0);
// Rug.
box([4.7, 0.045, 3.25], [0.95, 0.06, 1.05], material(0x3a5960));
box(
[4.35, 0.012, 2.9],
[0.95, 0.09, 1.05],
material(0x547178, { roughness: 1 })
);
// Sofa.
const sofa = new THREE.Group();
sofa.position.set(3.75, 0, -2.65);
scene.add(sofa);
box([2.65, 0.35, 1.1], [0, 0.45, 0], blueFabricMat, sofa);
box([2.65, 0.95, 0.28], [0, 1, -0.42], blueFabricMat, sofa);
box([0.3, 0.68, 1.1], [-1.18, 0.75, 0], blueFabricMat, sofa);
box([0.3, 0.68, 1.1], [1.18, 0.75, 0], blueFabricMat, sofa);
box([0.55, 0.42, 0.18], [-0.62, 0.8, 0.3], tealFabricMat, sofa);
box([0.55, 0.42, 0.18], [0.62, 0.8, 0.3], tealFabricMat, sofa);
// Side table and plant.
cylinder(0.46, 0.52, 0.12, [4.4, 0.78, -0.85], darkWoodMat);
cylinder(0.07, 0.08, 0.72, [4.4, 0.38, -0.85], darkWoodMat);
cylinder(0.23, 0.18, 0.42, [-4.42, 0.28, -2.2], material(0x9c5e43));
cylinder(0.035, 0.045, 1.1, [-4.42, 0.95, -2.2], darkWoodMat, scene, 6);
ico(0.38, [-4.42, 1.45, -2.2], material(0x3d7857), scene, 0);
ico(0.3, [-4.08, 1.25, -2.08], material(0x4a8a62), scene, 0);
ico(0.3, [-4.7, 1.25, -2.36], material(0x346e4e), scene, 0);
// Lantern shelf. It never moves.
box([1.75, 0.12, 0.66], [-3.5, 0.82, -3.55], darkWoodMat);
box([0.14, 0.75, 0.48], [-4.22, 0.43, -3.63], darkWoodMat);
box([0.14, 0.75, 0.48], [-2.78, 0.43, -3.63], darkWoodMat);
// Activity table. Its position remains fixed for the whole story.
const tableMat = material(0x9a714d);
box([3.2, 0.16, 1.8], [1, 1.3, 0.25], tableMat);
for (const x of [-0.35, 2.35]) {
for (const z of [-0.4, 0.9]) {
box([0.14, 1.22, 0.14], [x, 0.61, z], darkWoodMat);
}
}
// ------------------------------------------------------------
// Lights
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xa8c8e2, 0x3b2b21, 1.0);
scene.add(hemisphere);
const moonlight = new THREE.DirectionalLight(0x91bad8, 0.38);
moonlight.position.set(-3, 8, 5);
moonlight.castShadow = true;
moonlight.shadow.mapSize.set(1024, 1024);
moonlight.shadow.camera.left = -7;
moonlight.shadow.camera.right = 7;
moonlight.shadow.camera.top = 7;
moonlight.shadow.camera.bottom = -7;
moonlight.shadow.camera.near = 0.5;
moonlight.shadow.camera.far = 24;
moonlight.shadow.bias = -0.0006;
scene.add(moonlight);
const overheadFixture = new THREE.Group();
overheadFixture.position.set(0, 4.55, -0.3);
scene.add(overheadFixture);
cylinder(0.025, 0.025, 0.62, [0, 0.35, 0], darkMetalMat, overheadFixture, 6);
cylinder(0.18, 0.48, 0.32, [0, 0, 0], creamMat, overheadFixture, 8);
const mainBulbMat = material(0xfff0bf, {
emissive: 0xffd98c,
emissiveIntensity: 3.2,
roughness: 0.3
});
ico(0.16, [0, -0.16, 0], mainBulbMat, overheadFixture, 1);
const roomLight = new THREE.PointLight(0xffd29a, 70, 11, 2);
roomLight.position.set(0, 4.25, -0.3);
roomLight.castShadow = true;
roomLight.shadow.mapSize.set(512, 512);
roomLight.shadow.bias = -0.002;
scene.add(roomLight);
// ------------------------------------------------------------
// Lantern
// ------------------------------------------------------------
function createLantern() {
const group = new THREE.Group();
scene.add(group);
const metal = material(0x303a3e, { metalness: 0.45, roughness: 0.58 });
const brass = material(0xa76c32, { metalness: 0.38, roughness: 0.52 });
const glass = material(0xf5d18b, {
transparent: true,
opacity: 0.3,
emissive: 0x7b4a16,
emissiveIntensity: 0.08,
depthWrite: false
});
cylinder(0.2, 0.22, 0.08, [0, 0.04, 0], metal, group, 8);
cylinder(0.15, 0.18, 0.34, [0, 0.25, 0], glass, group, 8);
cylinder(0.12, 0.2, 0.09, [0, 0.46, 0], metal, group, 8);
cylinder(0.14, 0.12, 0.1, [0, 0.55, 0], brass, group, 8);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.16, 0.023, 4, 10, Math.PI),
brass
);
handle.position.set(0, 0.57, 0);
handle.castShadow = true;
group.add(handle);
const flameMat = material(0xffb13d, {
emissive: 0xff7b12,
emissiveIntensity: 0.2
});
const flame = ico(0.075, [0, 0.24, 0], flameMat, group, 0);
flame.scale.set(0.75, 1.35, 0.75);
const point = new THREE.PointLight(0xffa348, 0, 6.5, 2);
point.position.set(0, 0.28, 0);
group.add(point);
group.userData.flame = flame;
group.userData.flameMat = flameMat;
group.userData.point = point;
return group;
}
const lantern = createLantern();
const lanternShelfPosition = new THREE.Vector3(-3.5, 0.91, -3.35);
const lanternTablePosition = new THREE.Vector3(0.61, 1.39, 1.02);
lantern.position.copy(lanternShelfPosition);
const lanternSpot = new THREE.SpotLight(
0xffae52,
0,
7,
Math.PI / 2.55,
0.72,
1.8
);
lanternSpot.castShadow = true;
lanternSpot.shadow.mapSize.set(512, 512);
lanternSpot.shadow.bias = -0.001;
scene.add(lanternSpot);
scene.add(lanternSpot.target);
const warmPool = new THREE.Mesh(
new THREE.CircleGeometry(1.02, 32),
new THREE.MeshBasicMaterial({
color: 0xffb65e,
transparent: true,
opacity: 0,
depthWrite: false
})
);
warmPool.rotation.x = -Math.PI / 2;
warmPool.position.set(lanternTablePosition.x, 1.389, lanternTablePosition.z);
scene.add(warmPool);
// ------------------------------------------------------------
// Character
// ------------------------------------------------------------
function createCharacter() {
const root = new THREE.Group();
scene.add(root);
const upper = new THREE.Group();
root.add(upper);
const skin = material(0xc98f68);
const shirt = material(0xd88d4d);
const trousers = material(0x29495a);
const shoes = material(0x1d252b);
const hair = material(0x2b2420);
box([0.58, 0.66, 0.34], [0, 1.1, 0], shirt, upper);
box([0.53, 0.2, 0.34], [0, 0.73, 0], trousers, upper);
const head = ico(0.29, [0, 1.72, 0], skin, upper, 1);
head.scale.set(0.9, 1.08, 0.9);
const hairCap = ico(0.29, [0, 1.84, -0.025], hair, upper, 1);
hairCap.scale.set(0.93, 0.72, 0.93);
ico(0.06, [0, 1.7, 0.275], skin, upper, 0);
for (const x of [-0.095, 0.095]) {
ico(0.025, [x, 1.76, 0.257], material(0x1c2024), upper, 0);
}
function createArm(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.39, 1.39, 0);
upper.add(pivot);
cylinder(
0.085,
0.075,
0.34,
[0, -0.17, 0],
shirt,
pivot,
6
);
cylinder(
0.07,
0.065,
0.27,
[0, -0.43, 0],
skin,
pivot,
6
);
ico(0.09, [0, -0.59, 0], skin, pivot, 0);
return pivot;
}
const rightArm = createArm(1);
const leftArm = createArm(-1);
function createLeg(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.17, 0.73, 0);
root.add(pivot);
cylinder(
0.105,
0.095,
0.61,
[0, -0.305, 0],
trousers,
pivot,
6
);
box([0.22, 0.15, 0.36], [0, -0.67, 0.07], shoes, pivot);
return pivot;
}
const rightLeg = createLeg(1);
const leftLeg = createLeg(-1);
root.userData = {
upper,
rightArm,
leftArm,
rightLeg,
leftLeg
};
return root;
}
const character = createCharacter();
const characterStart = new THREE.Vector3(-2.4, 0, 2.55);
const shelfApproach = new THREE.Vector3(-3.11, 0, -2.55);
const tableApproach = new THREE.Vector3(1, 0, 2.55);
const tablePosition = new THREE.Vector3(1, 0, 1.72);
// ------------------------------------------------------------
// Book and battery radio
// ------------------------------------------------------------
const book = new THREE.Group();
book.position.set(1.35, 1.4, 0.72);
book.rotation.y = -0.13;
scene.add(book);
const bookCoverMat = material(0x7f3f3f);
const pageMat = material(0xe8dfc6);
const inkMat = material(0x726d62);
box([0.72, 0.035, 0.48], [0, 0.02, 0], bookCoverMat, book);
box([0.025, 0.03, 0.46], [0, 0.05, 0], material(0x56302f), book);
const leftPage = box(
[0.335, 0.025, 0.43],
[0, 0.055, 0],
pageMat,
book
);
const rightPage = box(
[0.335, 0.025, 0.43],
[0, 0.058, 0],
pageMat,
book
);
const pageLines = [];
for (let i = 0; i < 5; i++) {
pageLines.push(
box(
[0.22, 0.006, 0.012],
[0, 0.074, -0.13 + i * 0.06],
inkMat,
rightPage
)
);
}
const radio = new THREE.Group();
radio.position.set(2.3, 1.39, 0.42);
scene.add(radio);
const radioMat = material(0x48585c);
const radioFaceMat = material(0x27383d);
box([0.72, 0.43, 0.28], [0, 0.215, 0], radioMat, radio);
box([0.61, 0.33, 0.025], [0, 0.22, 0.15], radioFaceMat, radio);
const speaker = cylinder(
0.14,
0.14,
0.025,
[-0.12, 0.21, 0.175],
darkMetalMat,
radio,
12
);
speaker.rotation.x = Math.PI / 2;
const radioLedMat = material(0x274044, {
emissive: 0x66d9ef,
emissiveIntensity: 0
});
ico(0.035, [0.2, 0.28, 0.18], radioLedMat, radio, 0);
const knob = cylinder(
0.06,
0.06,
0.04,
[0.2, 0.12, 0.18],
creamMat,
radio,
10
);
knob.rotation.x = Math.PI / 2;
const antenna = cylinder(
0.012,
0.015,
0.62,
[-0.24, 0.68, -0.04],
darkMetalMat,
radio,
6
);
antenna.rotation.z = -0.22;
const radioBars = [];
for (let i = 0; i < 3; i++) {
const bar = box(
[0.026, 0.15, 0.025],
[-0.08 + i * 0.075, 0.84, 0.06],
new THREE.MeshBasicMaterial({
color: 0x69d9ed,
transparent: true,
opacity: 0
}),
radio
);
radioBars.push(bar);
}
// Mug and a small notebook add to the quiet activity setup.
cylinder(0.1, 0.085, 0.18, [1.95, 1.48, 0.8], creamMat, scene, 10);
const mugHandle = new THREE.Mesh(
new THREE.TorusGeometry(0.075, 0.018, 4, 10, Math.PI * 1.55),
creamMat
);
mugHandle.position.set(2.065, 1.49, 0.8);
mugHandle.rotation.z = -0.4;
mugHandle.castShadow = true;
scene.add(mugHandle);
box([0.52, 0.055, 0.38], [0.15, 1.42, 0.66], material(0x486f68));
// ------------------------------------------------------------
// Deterministic timeline
// ------------------------------------------------------------
function sampleCharacter(t) {
let position;
let yaw;
if (t < 2.8) {
position = characterStart.clone();
yaw = 0.88;
} else if (t < 6.1) {
const p = smooth(2.8, 6.1, t);
position = characterStart.clone().lerp(shelfApproach, p);
yaw = t < 2.35
? 0.88
: lerp(0.88, Math.PI, smooth(2.35, 3.05, t));
} else if (t < 7.35) {
position = shelfApproach.clone();
yaw = Math.PI;
} else if (t < 10.7) {
const p = smooth(7.35, 10.7, t);
position = shelfApproach.clone().lerp(tableApproach, p);
yaw = t < 7.9
? lerp(Math.PI, 0.64, smooth(7.35, 7.9, t))
: 0.64;
} else {
const p = smooth(10.7, 11.55, t);
position = tableApproach.clone().lerp(tablePosition, p);
yaw = lerp(0.64, Math.PI, smooth(10.7, 11.2, t));
}
return { position, yaw };
}
function rightArmAngle(t) {
if (t < 5.95) return 0;
if (t < 6.2) return lerp(0, -1.45, smooth(5.95, 6.2, t));
if (t < 7.05) return -1.45;
if (t < 7.6) return lerp(-1.45, -1.18, smooth(7.05, 7.6, t));
if (t < 11.55) return -1.18;
if (t < 12.05) return lerp(-1.18, -1.42, smooth(11.55, 12.05, t));
if (t < 13.0) return lerp(-1.42, -1.08, smooth(12.05, 13.0, t));
return lerp(-1.08, -1.3, smooth(13.0, 14.0, t));
}
function handWorldPosition(rootPosition, yaw, side, armAngle, upperOffset, forwardOffset) {
const armLength = 0.62;
const localX = side * 0.39;
const localY = 1.39 + upperOffset - armLength * Math.cos(armAngle);
const localZ = forwardOffset - armLength * Math.sin(armAngle);
const cos = Math.cos(yaw);
const sin = Math.sin(yaw);
return new THREE.Vector3(
rootPosition.x + localX * cos + localZ * sin,
localY,
rootPosition.z - localX * sin + localZ * cos
);
}
const captions = [
{
until: 1.6,
phase: "Household power",
caption: "The room is lit by the overhead household lamp."
},
{
until: 2.8,
phase: "Power interruption",
caption: "The grid fails. The ceiling lamp dims and the room falls into darkness."
},
{
until: 7.35,
phase: "Locate the lantern",
caption: "The resident follows the wall, finds the shelf, and picks up the lantern."
},
{
until: 12.35,
phase: "Carry and place",
caption: "The lantern is carried across the room and set down on the fixed table."
},
{
until: 13.8,
phase: "Lantern light",
caption: "The lantern is lit, creating a warm pool of light over the tabletop."
},
{
until: DURATION,
phase: "Alternative activities",
caption: "The book opens and the battery radio plays: quiet activities without the grid."
}
];
function updateStoryUI(t) {
let stageIndex = 0;
let caption = captions[0];
for (let i = 0; i < captions.length; i++) {
if (t < captions[i].until) {
stageIndex = i;
caption = captions[i];
break;
}
}
if (t >= DURATION) {
stageIndex = 5;
caption = captions[captions.length - 1];
}
phaseElement.textContent = caption.phase;
captionElement.textContent = caption.caption;
const visibleStep = Math.min(stageIndex, 4);
stepElements.forEach((element, index) => {
element.classList.toggle("active", index === visibleStep);
element.classList.toggle("done", index < visibleStep);
});
const gridOn = t < 1.6;
powerBadge.textContent = gridOn ? "Grid on" : "Grid off";
powerBadge.classList.toggle("off", !gridOn);
}
function applyTimeline(t) {
// 1. Household power interruption.
const powerLevel = 1 - smooth(1.6, 2.4, t);
hemisphere.intensity = lerp(0.18, 1.0, powerLevel);
moonlight.intensity = lerp(0.14, 0.38, powerLevel);
roomLight.intensity = 70 * powerLevel;
mainBulbMat.emissiveIntensity = 0.08 + 3.12 * powerLevel;
outletLedMat.color.setHex(powerLevel > 0.4 ? 0x67dc9a : 0xff535c);
outletLedMat.emissive.copy(outletLedMat.color);
outletLedMat.emissiveIntensity = powerLevel > 0.4 ? 1.8 : 1.25;
// 2-4. Character movement and arm poses.
const characterState = sampleCharacter(t);
character.position.copy(characterState.position);
character.rotation.y = characterState.yaw;
const rightAngle = rightArmAngle(t);
const walking =
(t > 2.8 && t < 6.1) ||
(t > 7.35 && t < 11.55);
const walkAmount = walking ? 1 : 0;
const walkCycle = Math.sin(t * 9.2) * 0.48 * walkAmount;
const lean = smooth(12.65, 13.4, t);
const upperOffset = -0.03 * lean;
const forwardOffset = 0.2 * lean;
character.userData.upper.position.set(0, upperOffset, forwardOffset);
character.userData.rightArm.rotation.x = rightAngle;
const leftAngle = lerp(
walkCycle * 0.55,
-1.65,
smooth(12.9, 14.0, t)
);
character.userData.leftArm.rotation.x = leftAngle;
character.userData.rightLeg.rotation.x = -walkCycle;
character.userData.leftLeg.rotation.x = walkCycle;
// Lantern follows the right hand and then stays fixed on the table.
let lanternPosition;
if (t < 6.1) {
lanternPosition = lanternShelfPosition.clone();
} else if (t < 7.15) {
const hand = handWorldPosition(
characterState.position,
characterState.yaw,
1,
rightAngle,
upperOffset,
forwardOffset
);
hand.y -= 0.53;
lanternPosition = lanternShelfPosition.clone().lerp(
hand,
smooth(6.1, 7.15, t)
);
} else if (t < 11.55) {
const hand = handWorldPosition(
characterState.position,
characterState.yaw,
1,
rightAngle,
upperOffset,
forwardOffset
);
hand.y -= 0.53;
lanternPosition = hand;
} else if (t < 12.35) {
const hand = handWorldPosition(
characterState.position,
characterState.yaw,
1,
rightAngle,
upperOffset,
forwardOffset
);
hand.y -= 0.53;
lanternPosition = hand.lerp(
lanternTablePosition.clone(),
smooth(11.55, 12.35, t)
);
} else {
lanternPosition = lanternTablePosition.clone();
}
lantern.position.copy(lanternPosition);
lantern.rotation.y = lerp(0, -0.12, smooth(7.2, 11.5, t));
// 5. Ignite the lantern after it is placed.
const ignition = smooth(12.35, 12.75, t);
const flicker = 1 + Math.sin(t * 21) * 0.035 + Math.sin(t * 37) * 0.02;
lantern.userData.point.intensity = 27 * ignition * flicker;
lantern.userData.flameMat.emissiveIntensity = 0.15 + 3.4 * ignition * flicker;
lantern.userData.flame.scale.set(
0.75 * (0.95 + Math.sin(t * 18) * 0.05),
1.35 * flicker,
0.75 * (0.95 + Math.cos(t * 16) * 0.05)
);
lanternSpot.position.set(
lanternTablePosition.x,
lanternTablePosition.y + 0.38,
lanternTablePosition.z
);
lanternSpot.target.position.set(
lanternTablePosition.x,
1.36,
lanternTablePosition.z
);
lanternSpot.intensity = 31 * ignition * flicker;
warmPool.material.opacity = 0.13 * ignition;
// Alternative activities: open a book and activate a radio.
const bookOpen = smooth(13.05, 14.0, t);
const pageFlutter = bookOpen * Math.sin((t - 14.8) * 2.2) * 0.035;
leftPage.position.x = -0.17 * bookOpen;
rightPage.position.x = 0.17 * bookOpen;
rightPage.rotation.z = pageFlutter * (t > 14.8 ? 1 : 0);
const radioOn = smooth(14.05, 14.45, t);
radioLedMat.emissiveIntensity = 3.6 * radioOn;
radioBars.forEach((bar, index) => {
const pulse = 0.45 +
0.35 * Math.sin(t * 7 + index * 1.7) +
0.2 * Math.sin(t * 13 + index);
const height = 0.15 * Math.max(0.12, pulse);
bar.scale.y = height / 0.15;
bar.position.y = 0.76 + height / 2;
bar.material.opacity = 0.8 * radioOn;
});
updateStoryUI(t);
timeline.value = t.toFixed(2);
}
// ------------------------------------------------------------
// Projected labels
// ------------------------------------------------------------
const labelElements = {
main: document.getElementById("label-main"),
lantern: document.getElementById("label-lantern"),
table: document.getElementById("label-table")
};
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateLabels() {
positionLabel(
labelElements.main,
new THREE.Vector3(0, 4.55, -0.3)
);
positionLabel(
labelElements.lantern,
lantern.position.clone().add(new THREE.Vector3(0, 0.78, 0))
);
positionLabel(
labelElements.table,
new THREE.Vector3(1, 1.62, 0.25)
);
}
// ------------------------------------------------------------
// Controls
// ------------------------------------------------------------
playButton.addEventListener("click", () => {
if (state.time >= DURATION) state.time = 0;
state.playing = !state.playing;
playButton.textContent = state.playing ? "Pause" : "Play";
});
restartButton.addEventListener("click", () => {
state.time = 0;
state.playing = true;
playButton.textContent = "Pause";
});
timeline.addEventListener("input", () => {
state.time = Number(timeline.value);
state.playing = false;
playButton.textContent = "Play";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.code === "Home") {
state.time = 0;
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
function animate(now) {
const dt = Math.min((now - state.lastTime) / 1000, 0.05);
state.lastTime = now;
if (state.playing) {
state.time = Math.min(DURATION, state.time + dt);
if (state.time >= DURATION) {
state.playing = false;
playButton.textContent = "Replay";
}
}
updateCamera();
applyTimeline(state.time);
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
applyTimeline(0);
requestAnimationFrame(animate);
</script>
</body>
</html>
```