Prompt specification
Build or customize the Three.js 3D scene "Bedroom shadow-story theater" 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: Bedroom shadow-story theater
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bedroom-shadow-story-theater-x0371
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: bedroom shadow-story theater. Compose a small curtain stage with two puppets and movable props; perform a short greeting scene where silhouettes remain separated and easily readable on the screen. Return one self-contained HTML file.
Working Three.js Starter (bedroom-shadow-story-theater-x0371):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#191827" />
<title>Afterlights — Bedroom Shadow Theater</title>
<style>
:root {
--ink: #191827;
--cream: #fff3d6;
--muted: #c9bdd0;
--gold: #f6c66f;
--coral: #e97965;
--panel: rgba(28, 25, 45, 0.82);
--line: rgba(255, 237, 203, 0.16);
--shadow: 0 20px 60px rgba(7, 6, 17, 0.34);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--cream);
font-family: "Trebuchet MS", "Segoe UI", system-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;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.vignette,
.pixel-grain {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.vignette {
background:
radial-gradient(circle at 52% 44%, transparent 34%, rgba(9, 8, 20, 0.18) 72%, rgba(9, 8, 20, 0.62) 120%),
linear-gradient(180deg, rgba(13, 12, 25, 0.16), transparent 35%, rgba(13, 12, 25, 0.18));
}
.pixel-grain {
opacity: 0.11;
background-image:
radial-gradient(rgba(255, 255, 255, 0.45) 0.55px, transparent 0.7px),
radial-gradient(rgba(0, 0, 0, 0.35) 0.5px, transparent 0.7px);
background-position: 0 0, 2px 2px;
background-size: 4px 4px;
mix-blend-mode: soft-light;
}
.brand {
position: fixed;
z-index: 5;
top: 28px;
left: 32px;
max-width: 520px;
pointer-events: none;
text-shadow: 0 2px 20px rgba(10, 8, 22, 0.65);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
content: "";
background: var(--gold);
box-shadow: 0 0 16px rgba(246, 198, 111, 0.8);
transform: rotate(45deg);
}
.brand h1 {
margin: 0;
font-size: clamp(30px, 3.6vw, 54px);
font-weight: 800;
line-height: 0.95;
letter-spacing: -0.055em;
}
.brand p {
max-width: 420px;
margin: 12px 0 0;
color: rgba(255, 243, 214, 0.73);
font-size: 13px;
line-height: 1.5;
}
.status {
position: fixed;
z-index: 6;
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 11px;
padding: 8px 9px 8px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(25, 23, 39, 0.65);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #ff9478;
box-shadow: 0 0 13px rgba(255, 148, 120, 0.9);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.8);
}
}
#phase-label {
min-width: 116px;
color: #f8e8c8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.icon-button {
display: grid;
width: 31px;
height: 31px;
padding: 0;
place-items: center;
border: 0;
border-radius: 50%;
background: rgba(255, 255, 255, 0.08);
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
.icon-button:hover {
background: rgba(246, 198, 111, 0.18);
transform: rotate(-12deg);
}
.panel {
position: fixed;
z-index: 6;
bottom: 24px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(1.15);
}
.story-panel {
left: 28px;
width: 340px;
}
.prop-panel {
right: 28px;
width: 294px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
color: #f5e7ca;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.panel-heading span {
color: rgba(255, 243, 214, 0.45);
font-size: 10px;
letter-spacing: 0.08em;
}
.play-row {
display: flex;
align-items: center;
gap: 9px;
}
.primary-button,
.secondary-button {
min-height: 39px;
border-radius: 11px;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
.primary-button {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
gap: 9px;
border: 1px solid rgba(255, 229, 178, 0.18);
background: var(--gold);
color: #30243a;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.04em;
}
.primary-button:hover {
background: #ffd98a;
transform: translateY(-1px);
}
#play-icon {
width: 16px;
font-size: 13px;
text-align: center;
}
.secondary-button {
width: 40px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.06);
color: #f8e8c8;
font-size: 18px;
}
.secondary-button:hover {
border-color: rgba(246, 198, 111, 0.45);
background: rgba(246, 198, 111, 0.1);
}
.timeline {
position: relative;
height: 4px;
margin: 15px 0 9px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.1);
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--coral), var(--gold));
box-shadow: 0 0 15px rgba(246, 198, 111, 0.35);
}
.timeline-labels {
display: flex;
justify-content: space-between;
color: rgba(255, 243, 214, 0.42);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.prop-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 13px;
}
.prop-button {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 38px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: rgba(255, 243, 214, 0.55);
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: 150ms ease;
}
.prop-button.visible {
color: #fff0cf;
}
.prop-button.selected {
border-color: rgba(246, 198, 111, 0.62);
background: rgba(246, 198, 111, 0.13);
box-shadow: inset 0 0 0 1px rgba(246, 198, 111, 0.08);
}
.prop-symbol {
color: var(--gold);
font-size: 17px;
line-height: 1;
}
.slider-row {
display: grid;
grid-template-columns: 47px 1fr 30px;
align-items: center;
gap: 9px;
min-height: 27px;
color: rgba(255, 243, 214, 0.58);
font-size: 10px;
}
.slider-row output {
color: var(--gold);
font-variant-numeric: tabular-nums;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 3px;
border-radius: 99px;
appearance: none;
background: rgba(255, 255, 255, 0.14);
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 13px;
height: 13px;
border: 2px solid #30243a;
border-radius: 3px;
appearance: none;
background: var(--gold);
box-shadow: 0 0 0 1px rgba(246, 198, 111, 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid #30243a;
border-radius: 3px;
background: var(--gold);
}
.prop-tip {
margin: 10px 0 0;
color: rgba(255, 243, 214, 0.42);
font-size: 9px;
line-height: 1.45;
}
.subtitle {
position: fixed;
z-index: 5;
bottom: 161px;
left: 50%;
width: min(560px, calc(100vw - 40px));
transform: translateX(-50%);
pointer-events: none;
text-align: center;
text-shadow: 0 3px 18px rgba(8, 7, 16, 0.85);
}
#caption {
display: inline-block;
padding: 9px 15px;
border: 1px solid rgba(255, 240, 207, 0.13);
border-radius: 999px;
background: rgba(25, 23, 39, 0.56);
color: #fff0d1;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(13px, 1.35vw, 17px);
font-style: italic;
line-height: 1.35;
backdrop-filter: blur(10px);
}
.keyboard-hint {
margin-top: 7px;
color: rgba(255, 243, 214, 0.34);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#toast {
position: fixed;
z-index: 8;
top: 84px;
right: 30px;
max-width: 260px;
padding: 9px 12px;
border: 1px solid rgba(246, 198, 111, 0.25);
border-radius: 10px;
background: rgba(30, 27, 45, 0.85);
color: #f9e8c7;
font-size: 10px;
line-height: 1.45;
opacity: 0;
pointer-events: none;
transform: translateY(-6px);
transition: opacity 180ms ease, transform 180ms ease;
backdrop-filter: blur(12px);
}
#toast.visible {
opacity: 1;
transform: translateY(0);
}
@media (max-width: 860px) {
.brand {
top: 18px;
left: 18px;
}
.brand h1 {
max-width: 330px;
font-size: 34px;
}
.brand p {
display: none;
}
.status {
top: 18px;
right: 16px;
}
#phase-label {
display: none;
}
.story-panel {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
}
.prop-panel {
top: 78px;
right: 12px;
bottom: auto;
width: 228px;
padding: 13px;
}
.subtitle {
bottom: 143px;
}
.keyboard-hint {
display: none;
}
#toast {
top: 76px;
right: 12px;
}
}
@media (max-width: 520px) {
.brand h1 {
max-width: 235px;
font-size: 29px;
}
.eyebrow {
font-size: 9px;
}
.prop-panel {
top: 73px;
width: 202px;
}
.prop-panel .panel-heading span,
.prop-tip {
display: none;
}
.subtitle {
bottom: 134px;
}
#caption {
padding: 8px 12px;
}
}
@media (max-height: 650px) and (min-width: 861px) {
.panel {
bottom: 12px;
padding: 12px;
}
.subtitle {
bottom: 135px;
}
}
@media (prefers-reduced-motion: reduce) {
.status-dot {
animation: none;
}
button,
#toast {
transition: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="A voxel bedroom with a small shadow puppet theater"></canvas>
<div class="vignette"></div>
<div class="pixel-grain"></div>
<header class="brand">
<div class="eyebrow">Afterlights presents</div>
<h1>Bedroom Shadow Theater</h1>
<p>A tiny bedtime stage, two friendly puppets, and a story made for the quiet hours.</p>
</header>
<div class="status" aria-live="polite">
<span class="status-dot"></span>
<span id="phase-label">Curtain call</span>
<button class="icon-button" id="reset-view" type="button" aria-label="Reset camera view" title="Reset view">↺</button>
</div>
<section class="panel story-panel" aria-label="Story playback controls">
<div class="panel-heading">
<h2>The Greeting</h2>
<span>16 second mini-story</span>
</div>
<div class="play-row">
<button class="primary-button" id="play" type="button">
<span id="play-icon">Ⅱ</span>
<span id="play-text">Pause story</span>
</button>
<button class="secondary-button" id="replay" type="button" aria-label="Replay story" title="Replay">↻</button>
</div>
<div class="timeline"><div id="progress"></div></div>
<div class="timeline-labels">
<span>Curtain call</span>
<span>Good night</span>
</div>
</section>
<section class="panel prop-panel" aria-label="Movable prop controls">
<div class="panel-heading">
<h2>Prop Desk</h2>
<span>Drag on stage</span>
</div>
<div class="prop-buttons">
<button class="prop-button visible selected" id="moon-button" type="button" aria-pressed="true">
<span class="prop-symbol">☾</span><span>Moon</span>
</button>
<button class="prop-button visible" id="star-button" type="button" aria-pressed="true">
<span class="prop-symbol">✦</span><span>Star</span>
</button>
</div>
<div class="slider-row">
<label for="x-range">Across</label>
<input id="x-range" type="range" min="-3.2" max="3.2" step="0.01" value="-2.55" />
<output id="x-value">-2.6</output>
</div>
<div class="slider-row">
<label for="y-range">Height</label>
<input id="y-range" type="range" min="0.95" max="4.45" step="0.01" value="3.82" />
<output id="y-value">3.8</output>
</div>
<p class="prop-tip">Select a prop, drag it on the screen, or nudge it with the sliders. Click the selected prop again to hide it.</p>
</section>
<div class="subtitle" aria-live="polite">
<div id="caption">Every good story begins with a little light.</div>
<div class="keyboard-hint">Drag the room to look around · Scroll to zoom · Space to pause</div>
</div>
<div id="toast" role="status"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x191827);
scene.fog = new THREE.Fog(0x191827, 19, 38);
const camera = new THREE.PerspectiveCamera(34, 1, 0.1, 80);
const cameraTarget = new THREE.Vector3(-0.45, 2.38, 0.15);
const orbit = {
theta: 0.285,
phi: 1.34,
radius: 14.2,
fitRadius: 14.2
};
function applyCamera() {
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);
}
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(parent, size, position, material, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(
unitBox,
typeof material === "number" ? getMaterial(material) : material
);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function beamBetween(parent, a, b, thickness, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = box(
parent,
[thickness, thickness, direction.length()],
midpoint.toArray(),
material,
false,
false
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.clone().normalize()
);
return mesh;
}
const palette = {
wall: 0x49445f,
wallDark: 0x302d46,
floor: 0x685263,
rug: 0x40395f,
rugEdge: 0x766079,
wood: 0x805846,
woodDark: 0x513849,
cream: 0xffe1a8,
red: 0x9f4054,
redDark: 0x713247,
brass: 0xc99b57,
blue: 0x566985,
blueDark: 0x303d58,
mint: 0x6d9b8c,
yellow: 0xe7b866,
puppet: 0x282238,
puppetAlt: 0x332a43,
white: 0xeee5d2
};
const glowGold = new THREE.MeshStandardMaterial({
color: 0xffd784,
emissive: 0xff9d45,
emissiveIntensity: 1.8,
roughness: 0.5
});
const glowBlue = new THREE.MeshStandardMaterial({
color: 0x91b7cf,
emissive: 0x4d7598,
emissiveIntensity: 0.65,
roughness: 0.8
});
const screenMaterial = new THREE.MeshStandardMaterial({
color: 0xffdfa5,
roughness: 1,
metalness: 0
});
const room = new THREE.Group();
scene.add(room);
function buildRoom() {
box(room, [24, 0.24, 16], [0, -0.14, 1.5], palette.floor, false, true);
box(room, [24, 10, 0.3], [0, 4.5, -4.35], palette.wall, false, true);
box(room, [24, 0.35, 0.22], [0, 0.2, -4.12], palette.wallDark, false, true);
box(room, [0.25, 10, 15], [-12, 4.5, 2], palette.wallDark, false, true);
// Soft rug and its block-stitched border.
box(room, [12.5, 0.055, 7.4], [-0.1, 0.015, 1.1], palette.rug, false, true);
box(room, [11.8, 0.035, 0.16], [-0.1, 0.052, -2.25], palette.rugEdge, false, true);
box(room, [11.8, 0.035, 0.16], [-0.1, 0.052, 4.45], palette.rugEdge, false, true);
box(room, [0.16, 0.035, 6.55], [-5.85, 0.052, 1.1], palette.rugEdge, false, true);
box(room, [0.16, 0.035, 6.55], [5.65, 0.052, 1.1], palette.rugEdge, false, true);
// Voxel bed.
const bed = new THREE.Group();
bed.position.set(-7.15, 0, -1.5);
room.add(bed);
box(bed, [4.35, 0.55, 5.45], [0, 0.43, 0], palette.woodDark);
box(bed, [4.05, 0.42, 5.05], [0, 0.9, 0], palette.white);
box(bed, [4.48, 2.8, 0.36], [0, 1.95, -2.68], palette.wood);
box(bed, [3.88, 0.2, 3.48], [0, 1.17, 0.9], 0x66728e);
box(bed, [3.95, 0.12, 0.34], [0, 1.3, 2.54], 0x8795ad);
box(bed, [3.18, 0.34, 0.88], [0, 1.23, -1.95], 0xf3ead9);
box(bed, [0.32, 0.48, 0.32], [-1.75, 0.13, -2.22], palette.woodDark);
box(bed, [0.32, 0.48, 0.32], [1.75, 0.13, -2.22], palette.woodDark);
box(bed, [0.32, 0.48, 0.32], [-1.75, 0.13, 2.18], palette.woodDark);
box(bed, [0.32, 0.48, 0.32], [1.75, 0.13, 2.18], palette.woodDark);
// A little bedside cabinet and lamp.
const nightstand = new THREE.Group();
nightstand.position.set(6.8, 0, -1.5);
room.add(nightstand);
box(nightstand, [2.05, 1.55, 1.65], [0, 0.83, 0], palette.wood);
box(nightstand, [1.62, 0.7, 0.12], [0, 1.05, 0.87], palette.woodDark);
box(nightstand, [0.28, 0.08, 0.12], [0, 1.05, 0.96], palette.brass);
box(nightstand, [0.66, 0.16, 0.66], [0, 1.67, 0], palette.brass);
box(nightstand, [0.18, 0.78, 0.18], [0, 2.04, 0], palette.brass);
box(nightstand, [1.15, 0.28, 1.05], [0, 2.56, 0], 0xf1b96b);
box(nightstand, [0.9, 0.27, 0.82], [0, 2.82, 0], 0xf7ca7e);
box(nightstand, [0.58, 0.24, 0.55], [0, 3.05, 0], 0xffdda0);
// Pixel-style window.
const windowGroup = new THREE.Group();
windowGroup.position.set(7.15, 4.55, -4.08);
room.add(windowGroup);
box(windowGroup, [3.7, 3.1, 0.16], [0, 0, 0], palette.woodDark);
box(windowGroup, [3.32, 2.72, 0.12], [0, 0, 0.11], glowBlue, false, false);
box(windowGroup, [0.13, 2.8, 0.16], [0, 0, 0.2], palette.cream);
box(windowGroup, [3.4, 0.13, 0.16], [0, 0, 0.2], palette.cream);
box(windowGroup, [3.95, 0.19, 0.48], [0, -1.59, 0.23], palette.wood);
box(windowGroup, [0.22, 2.1, 0.14], [-1.17, 0.55, 0.24], glowGold, false, false);
box(windowGroup, [0.17, 1.3, 0.14], [-0.82, 0.15, 0.24], glowGold, false, false);
box(windowGroup, [0.18, 0.85, 0.14], [-0.8, 0.48, 0.24], glowGold, false, false);
box(windowGroup, [0.16, 0.46, 0.14], [-1.12, 0.84, 0.24], glowGold, false, false);
// Books and a block plant.
box(nightstand, [0.72, 0.13, 0.9], [0.5, 1.64, -0.34], 0x9e5666);
box(nightstand, [0.66, 0.12, 0.82], [0.54, 1.77, -0.32], 0x657a9c);
box(nightstand, [0.62, 0.12, 0.78], [0.46, 1.89, -0.29], 0xc29b62);
const plant = new THREE.Group();
plant.position.set(9.35, 0, -1.9);
room.add(plant);
box(plant, [1.1, 1.1, 1.1], [0, 0.58, 0], 0xa86d59);
box(plant, [0.18, 1.4, 0.18], [0, 1.75, 0], 0x496d58);
box(plant, [0.75, 0.2, 0.38], [-0.28, 2.2, 0], 0x6f9272);
box(plant, [0.2, 0.82, 0.22], [0.35, 2.42, 0], 0x7da080);
box(plant, [0.67, 0.2, 0.36], [0.32, 2.78, 0], 0x5e8266);
// Wall picture.
const picture = new THREE.Group();
picture.position.set(-8.5, 5.25, -4.05);
room.add(picture);
box(picture, [2.1, 1.65, 0.14], [0, 0, 0], palette.woodDark);
box(picture, [1.78, 1.34, 0.08], [0, 0, 0.1], 0xc48c72);
box(picture, [0.72, 0.88, 0.08], [0, -0.1, 0.16], 0x6b7898);
box(picture, [0.27, 0.27, 0.08], [0.44, 0.36, 0.16], glowGold, false, false);
// String of warm square lights.
const points = [];
for (let i = 0; i < 11; i++) {
const x = -10.1 + i * 2.02;
const y = 7.35 - Math.sin(i * 0.78) * 0.35;
points.push([x, y, -3.93]);
box(room, [0.15, 0.15, 0.15], [x, y - 0.16, -3.91], glowGold, false, false);
}
for (let i = 0; i < points.length - 1; i++) {
beamBetween(room, points[i], points[i + 1], 0.025, palette.woodDark);
}
}
buildRoom();
const stage = new THREE.Group();
scene.add(stage);
function buildStage() {
// Screen and timber frame.
const screenPanel = box(
stage,
[7.4, 4.25, 0.18],
[0, 2.78, 0],
screenMaterial,
false,
true
);
screenPanel.userData.isScreen = true;
box(stage, [0.38, 5.35, 0.52], [-3.85, 2.7, 0.16], palette.wood);
box(stage, [0.38, 5.35, 0.52], [3.85, 2.7, 0.16], palette.wood);
box(stage, [8.1, 0.38, 0.54], [0, 5.16, 0.16], palette.wood);
box(stage, [8.05, 0.3, 0.5], [0, 0.54, 0.18], palette.woodDark);
// Open velvet curtains.
for (const side of [-1, 1]) {
for (let i = 0; i < 6; i++) {
const height = 4.05 - (i % 2) * 0.14;
box(
stage,
[0.35, height, 0.5],
[side * (3.02 + i * 0.105), 0.7 + height / 2, 0.52],
i % 2 ? palette.redDark : palette.red
);
}
box(stage, [0.78, 0.16, 0.58], [side * 3.33, 1.62, 0.55], palette.brass);
}
// Valance made from little voxel folds.
for (let i = -6; i <= 6; i++) {
box(
stage,
[0.61, 0.62 + (Math.abs(i) % 2) * 0.08, 0.54],
[i * 0.59, 4.82, 0.52],
i % 2 ? palette.redDark : palette.red
);
}
// Raised wooden platform and front step.
box(stage, [8.65, 0.36, 3.3], [0, 0.34, 1.2], palette.wood);
box(stage, [8.15, 0.19, 0.75], [0, 0.16, 3.05], palette.woodDark);
box(stage, [7.55, 0.12, 0.62], [0, 0.32, 2.72], palette.wood);
// Tiny footlights.
for (let i = -3; i <= 3; i++) {
box(stage, [0.26, 0.16, 0.22], [i * 1.02, 0.62, 2.73], glowGold, false, false);
}
// Decorative screen rivets.
for (const x of [-3.46, 3.46]) {
for (const y of [0.88, 4.67]) {
box(stage, [0.11, 0.11, 0.12], [x, y, 0.14], palette.brass, false, false);
}
}
}
buildStage();
function createBunny() {
const root = new THREE.Group();
root.position.set(-1.72, 0.54, 1.22);
stage.add(root);
box(root, [0.86, 1.23, 0.52], [0, 1.18, 0], palette.puppet);
box(root, [0.98, 0.9, 0.56], [0, 2.22, 0], palette.puppet);
box(root, [0.2, 0.82, 0.29], [-0.27, 2.99, 0], palette.puppet);
box(root, [0.2, 0.82, 0.29], [0.27, 2.99, 0], palette.puppet);
box(root, [0.36, 0.52, 0.44], [-0.25, 0.27, 0.06], palette.puppet);
box(root, [0.36, 0.52, 0.44], [0.25, 0.27, 0.06], palette.puppet);
box(root, [0.48, 0.2, 0.58], [-0.25, 0.06, 0.14], palette.puppetAlt);
box(root, [0.48, 0.2, 0.58], [0.25, 0.06, 0.14], palette.puppetAlt);
box(root, [0.31, 0.31, 0.25], [-0.59, 1.08, -0.04], palette.puppetAlt);
box(root, [1.04, 0.16, 0.6], [0, 1.75, 0], palette.red);
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0xffd67b,
emissive: 0xb76d27,
emissiveIntensity: 0.75,
roughness: 0.65
});
box(root, [0.09, 0.1, 0.05], [-0.2, 2.29, 0.3], eyeMaterial, false, false);
box(root, [0.09, 0.1, 0.05], [0.2, 2.29, 0.3], eyeMaterial, false, false);
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-0.58, 1.63, 0);
armR.position.set(0.58, 1.63, 0);
root.add(armL, armR);
box(armL, [0.25, 0.82, 0.28], [0, -0.36, 0], palette.puppet);
box(armL, [0.3, 0.26, 0.31], [0, -0.8, 0], palette.puppet);
box(armR, [0.25, 0.82, 0.28], [0, -0.36, 0], palette.puppet);
box(armR, [0.3, 0.26, 0.31], [0, -0.8, 0], palette.puppet);
const head = new THREE.Group();
root.add(head);
return { root, armL, armR, head, baseX: -1.72, baseY: 0.54 };
}
function createRobot() {
const root = new THREE.Group();
root.position.set(1.72, 0.54, 1.23);
stage.add(root);
box(root, [1.02, 1.18, 0.58], [0, 1.14, 0], palette.puppetAlt);
box(root, [1.1, 0.88, 0.64], [0, 2.19, 0], palette.puppet);
box(root, [0.1, 0.42, 0.1], [0, 2.84, 0], palette.puppetAlt);
box(root, [0.2, 0.2, 0.2], [0, 3.12, 0], glowGold);
box(root, [0.28, 0.43, 0.48], [-0.68, 2.23, 0], palette.puppetAlt);
box(root, [0.28, 0.43, 0.48], [0.68, 2.23, 0], palette.puppetAlt);
box(root, [0.4, 0.55, 0.45], [-0.26, 0.3, 0], palette.puppetAlt);
box(root, [0.4, 0.55, 0.45], [0.26, 0.3, 0], palette.puppetAlt);
box(root, [0.53, 0.23, 0.62], [-0.26, 0.06, 0.13], palette.puppet);
box(root, [0.53, 0.23, 0.62], [0.26, 0.06, 0.13], palette.puppet);
box(root, [0.47, 0.31, 0.08], [0, 1.28, 0.33], glowGold, false, false);
const visor = new THREE.MeshStandardMaterial({
color: 0xf6c96f,
emissive: 0xd77c32,
emissiveIntensity: 0.55,
roughness: 0.7
});
box(root, [0.62, 0.13, 0.06], [0, 2.27, 0.34], visor, false, false);
box(root, [0.07, 0.07, 0.05], [0.16, 2.27, 0.38], palette.puppet, false, false);
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-0.65, 1.61, 0);
armR.position.set(0.65, 1.61, 0);
root.add(armL, armR);
box(armL, [0.27, 0.84, 0.3], [0, -0.37, 0], palette.puppetAlt);
box(armL, [0.32, 0.26, 0.32], [0, -0.82, 0], palette.puppet);
box(armR, [0.27, 0.84, 0.3], [0, -0.37, 0], palette.puppetAlt);
box(armR, [0.32, 0.26, 0.32], [0, -0.82, 0], palette.puppet);
const head = new THREE.Group();
root.add(head);
return { root, armL, armR, head, baseX: 1.72, baseY: 0.54 };
}
const bunny = createBunny();
const robot = createRobot();
function createMoonProp() {
const root = new THREE.Group();
root.position.set(-2.55, 3.82, 1.02);
root.rotation.z = -0.12;
root.userData.isProp = true;
stage.add(root);
const size = 0.105;
for (let y = -3; y <= 3; y++) {
for (let x = -3; x <= 3; x++) {
const distance = x * x + y * y;
const insideMoon = distance <= 8.5 && !(x > 0.4 && y > -1.1);
if (insideMoon) {
box(root, [size, size, 0.16], [x * size, y * size, 0], palette.puppet);
}
}
}
return root;
}
function createStarProp() {
const root = new THREE.Group();
root.position.set(2.72, 3.93, 1.05);
root.rotation.z = 0.12;
root.userData.isProp = true;
stage.add(root);
const size = 0.13;
const cells = [
[0, 0], [0, 1], [0, -1], [1, 0], [-1, 0],
[0, 2], [0, -2], [2, 0], [-2, 0],
[1, 1], [-1, -1], [1, -1], [-1, 1]
];
for (const [x, y] of cells) {
box(root, [size, size, 0.17], [x * size, y * size, 0], palette.puppet);
}
return root;
}
const moon = createMoonProp();
const star = createStarProp();
const props = [moon, star];
// Lighting: a warm room plus an off-axis story light that throws clear
// puppet silhouettes onto the screen.
const hemisphere = new THREE.HemisphereLight(0xd8e3ff, 0x3b2948, 0.92);
scene.add(hemisphere);
const ambient = new THREE.AmbientLight(0x8c7aa0, 0.24);
scene.add(ambient);
const storyLight = new THREE.DirectionalLight(0xffe0ae, 2.7);
storyLight.position.set(4, 8, 10);
storyLight.target.position.set(-0.5, 2.25, 0);
storyLight.castShadow = true;
storyLight.shadow.mapSize.set(
window.innerWidth < 700 ? 1024 : 2048,
window.innerWidth < 700 ? 1024 : 2048
);
storyLight.shadow.camera.left = -8;
storyLight.shadow.camera.right = 8;
storyLight.shadow.camera.top = 8;
storyLight.shadow.camera.bottom = -6;
storyLight.shadow.camera.near = 1;
storyLight.shadow.camera.far = 26;
storyLight.shadow.bias = -0.00025;
storyLight.shadow.normalBias = 0.025;
stage.add(storyLight, storyLight.target);
const warmSpot = new THREE.SpotLight(0xffb868, 85, 26, 0.72, 0.48, 1.4);
warmSpot.position.set(1.5, 7.2, 7);
warmSpot.target.position.set(0, 2.4, 0);
stage.add(warmSpot, warmSpot.target);
const lampGlow = new THREE.PointLight(0xffa855, 28, 8, 1.7);
lampGlow.position.set(6.8, 3.1, -1.2);
scene.add(lampGlow);
// A handful of quiet floating dust blocks.
const motes = [];
const moteMaterial = new THREE.MeshStandardMaterial({
color: 0xffdda0,
emissive: 0xffae63,
emissiveIntensity: 1.2,
roughness: 0.8
});
const motePositions = [
[-4.6, 3.4, 1.8], [-3.1, 5.2, 0.9], [-1.2, 4.5, 2.2],
[0.6, 5.7, 1.3], [2.2, 4.8, 2.1], [4.1, 5.1, 1.2],
[4.8, 2.9, 1.9], [-4.3, 1.8, 2.7], [1.1, 3.1, 3.1],
[-0.5, 5.9, 0.4]
];
motePositions.forEach((position, index) => {
const mote = box(scene, [0.035, 0.035, 0.035], position, moteMaterial, false, false);
motes.push({
mesh: mote,
baseY: position[1],
phase: index * 1.73,
speed: 0.32 + index * 0.018
});
});
// Story playback.
const duration = 16;
let elapsed = 0.35;
let playing = true;
let previousTime = performance.now();
let lastPhase = -1;
const phaseLabel = document.querySelector("#phase-label");
const caption = document.querySelector("#caption");
const progress = document.querySelector("#progress");
const playButton = document.querySelector("#play");
const playIcon = document.querySelector("#play-icon");
const playText = document.querySelector("#play-text");
const phases = [
{ at: 0, label: "Curtain call", text: "Every good story begins with a little light." },
{ at: 1.3, label: "Milo says hello", text: "Milo: “Hello, little room!”" },
{ at: 4.3, label: "Pip waves back", text: "Pip: “Hello, new friend.”" },
{ at: 7.4, label: "A friendly bow", text: "Milo and Pip bow: “We’re glad you’re here.”" },
{ at: 10.0, label: "Good evening", text: "“Good evening! Good night! See you soon.”" },
{ at: 13.5, label: "A tiny goodnight", text: "A tiny hello, made just for you." }
];
function smoothstep(edge0, edge1, value) {
const x = THREE.MathUtils.clamp((value - edge0) / (edge1 - edge0), 0, 1);
return x * x * (3 - 2 * x);
}
function resetRig(rig) {
rig.root.position.set(rig.baseX, rig.baseY, rig.root.position.z);
rig.root.rotation.set(0, 0, 0);
rig.armL.rotation.set(0, 0, 0);
rig.armR.rotation.set(0, 0, 0);
rig.head.rotation.set(0, 0, 0);
}
function updateStory(time) {
resetRig(bunny);
resetRig(robot);
const intro = smoothstep(0, 1.15, time);
const bob = Math.sin(time * 2.35) * 0.025;
bunny.root.position.y = bunny.baseY - (1 - intro) * 0.68 + bob;
robot.root.position.y = robot.baseY - (1 - intro) * 0.82 + Math.cos(time * 2.1) * 0.025;
bunny.armL.rotation.z = -0.04;
bunny.armR.rotation.z = 0.04;
robot.armL.rotation.z = -0.04;
robot.armR.rotation.z = 0.04;
// Milo waves with his inner arm.
if (time >= 1.3 && time < 4.3) {
const amount = smoothstep(1.3, 1.8, time) * (1 - smoothstep(3.8, 4.3, time));
const flutter = Math.sin((time - 1.5) * 10.5) * 0.16 * amount;
bunny.armR.rotation.z = 2.34 * amount + flutter;
bunny.armR.rotation.x = -0.24 * amount;
bunny.head.rotation.z = -0.08 * amount + flutter * 0.35;
}
// Pip answers with his inner arm.
if (time >= 4.3 && time < 7.4) {
const amount = smoothstep(4.3, 4.8, time) * (1 - smoothstep(6.9, 7.4, time));
const flutter = Math.sin((time - 4.5) * 9.4) * 0.17 * amount;
robot.armL.rotation.z = -2.3 * amount + flutter;
robot.armL.rotation.x = -0.22 * amount;
robot.head.rotation.z = 0.08 * amount - flutter * 0.3;
}
// A synchronized bow keeps both silhouettes clearly apart.
if (time >= 7.4 && time < 10.0) {
const amount = smoothstep(7.4, 8.05, time) * (1 - smoothstep(9.35, 10.0, time));
bunny.root.rotation.x = 0.28 * amount;
robot.root.rotation.x = 0.25 * amount;
bunny.armL.rotation.z = 0.38 * amount;
bunny.armR.rotation.z = -0.38 * amount;
robot.armL.rotation.z = -0.35 * amount;
robot.armR.rotation.z = 0.35 * amount;
bunny.head.rotation.x = 0.15 * amount;
robot.head.rotation.x = 0.12 * amount;
}
// Their final greeting opens outward rather than crossing into the
// other silhouette, preserving a clear gap for the shadow story.
if (time >= 10.0) {
const amount = smoothstep(10.0, 10.7, time);
const flutter = Math.sin((time - 10.2) * 7.6) * 0.13 * amount;
bunny.armL.rotation.z = -2.08 * amount + flutter;
bunny.armL.rotation.x = -0.5 * amount;
robot.armR.rotation.z = 2.08 * amount - flutter;
robot.armR.rotation.x = -0.5 * amount;
bunny.root.rotation.y = 0.045 * amount;
robot.root.rotation.y = -0.045 * amount;
}
let phaseIndex = 0;
for (let i = 0; i < phases.length; i++) {
if (time >= phases[i].at) phaseIndex = i;
}
if (phaseIndex !== lastPhase) {
phaseLabel.textContent = phases[phaseIndex].label;
caption.textContent = phases[phaseIndex].text;
lastPhase = phaseIndex;
}
progress.style.width = `${(time / duration) * 100}%`;
}
function updatePlayButton() {
playIcon.textContent = playing ? "Ⅱ" : "▶";
playText.textContent = playing ? "Pause story" : "Play story";
playButton.setAttribute("aria-pressed", String(playing));
}
function togglePlay() {
playing = !playing;
updatePlayButton();
}
document.querySelector("#play").addEventListener("click", togglePlay);
document.querySelector("#replay").addEventListener("click", () => {
elapsed = 0;
lastPhase = -1;
playing = true;
updatePlayButton();
});
// Movable props.
const xRange = document.querySelector("#x-range");
const yRange = document.querySelector("#y-range");
const xValue = document.querySelector("#x-value");
const yValue = document.querySelector("#y-value");
const moonButton = document.querySelector("#moon-button");
const starButton = document.querySelector("#star-button");
const toast = document.querySelector("#toast");
let selectedProp = moon;
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2200);
}
function updatePropUI() {
xRange.value = selectedProp ? selectedProp.position.x : 0;
yRange.value = selectedProp ? selectedProp.position.y : 0;
xValue.textContent = selectedProp ? selectedProp.position.x.toFixed(1) : "—";
yValue.textContent = selectedProp ? selectedProp.position.y.toFixed(1) : "—";
xRange.disabled = !selectedProp;
yRange.disabled = !selectedProp;
moonButton.classList.toggle("visible", moon.visible);
moonButton.classList.toggle("selected", selectedProp === moon);
starButton.classList.toggle("visible", star.visible);
starButton.classList.toggle("selected", selectedProp === star);
moonButton.setAttribute("aria-pressed", String(moon.visible));
starButton.setAttribute("aria-pressed", String(star.visible));
}
function selectProp(prop) {
if (!prop.visible) return;
selectedProp = prop;
updatePropUI();
}
function choosePropButton(prop, button) {
if (!prop.visible) {
prop.visible = true;
selectedProp = prop;
showToast(`${prop === moon ? "Moon" : "Star"} added to the stage.`);
} else if (selectedProp !== prop) {
selectedProp = prop;
showToast(`${prop === moon ? "Moon" : "Star"} selected — drag it on the screen.`);
} else {
prop.visible = false;
selectedProp = moon.visible ? moon : (star.visible ? star : null);
showToast(`${prop === moon ? "Moon" : "Star"} tucked away.`);
}
updatePropUI();
}
moonButton.addEventListener("click", () => choosePropButton(moon, moonButton));
starButton.addEventListener("click", () => choosePropButton(star, starButton));
function moveSelectedProp(x, y) {
if (!selectedProp) return;
selectedProp.position.x = THREE.MathUtils.clamp(x, -3.2, 3.2);
selectedProp.position.y = THREE.MathUtils.clamp(y, 0.95, 4.45);
updatePropUI();
}
xRange.addEventListener("input", () => {
if (selectedProp) moveSelectedProp(Number(xRange.value), selectedProp.position.y);
});
yRange.addEventListener("input", () => {
if (selectedProp) moveSelectedProp(selectedProp.position.x, Number(yRange.value));
});
updatePropUI();
// Custom camera and prop dragging controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 0, 1), -1);
const dragPoint = new THREE.Vector3();
const dragOffset = new THREE.Vector2();
let pointerMode = null;
let lastX = 0;
let lastY = 0;
let draggedProp = null;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function findPropRoot(object) {
let current = object;
while (current) {
if (current.userData.isProp) return current;
current = current.parent;
}
return null;
}
canvas.addEventListener("pointerdown", (event) => {
updatePointer(event);
const visibleProps = props.filter((prop) => prop.visible);
const hits = raycaster.intersectObjects(visibleProps, true);
if (hits.length) {
draggedProp = findPropRoot(hits[0].object);
selectProp(draggedProp);
dragPlane.set(new THREE.Vector3(0, 0, 1), -draggedProp.position.z);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
dragOffset.set(
draggedProp.position.x - dragPoint.x,
draggedProp.position.y - dragPoint.y
);
} else {
dragOffset.set(0, 0);
}
pointerMode = "prop";
canvas.setPointerCapture(event.pointerId);
showToast(`${draggedProp === moon ? "Moon" : "Star"} selected — drag to reposition.`);
} else {
pointerMode = "camera";
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerMode) return;
if (pointerMode === "prop" && draggedProp) {
updatePointer(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
moveSelectedProp(
dragPoint.x + dragOffset.x,
dragPoint.y + dragOffset.y
);
}
} else if (pointerMode === "camera") {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.theta = THREE.MathUtils.clamp(orbit.theta - dx * 0.0042, -0.38, 0.63);
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.0032, 1.12, 1.48);
applyCamera();
}
});
function endPointer(event) {
pointerMode = null;
draggedProp = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + Math.sign(event.deltaY) * 0.65,
10.5,
28
);
applyCamera();
},
{ passive: false }
);
function resetView() {
orbit.theta = 0.285;
orbit.phi = 1.34;
orbit.radius = orbit.fitRadius;
applyCamera();
}
document.querySelector("#reset-view").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.code === "Space") {
event.preventDefault();
togglePlay();
} else if (event.key.toLowerCase() === "r") {
elapsed = 0;
lastPhase = -1;
playing = true;
updatePlayButton();
} else if (event.key.toLowerCase() === "m") {
choosePropButton(moon, moonButton);
} else if (event.key.toLowerCase() === "s") {
choosePropButton(star, starButton);
} else if (selectedProp && event.key.startsWith("Arrow")) {
event.preventDefault();
const amount = event.shiftKey ? 0.2 : 0.06;
let x = selectedProp.position.x;
let y = selectedProp.position.y;
if (event.key === "ArrowLeft") x -= amount;
if (event.key === "ArrowRight") x += amount;
if (event.key === "ArrowUp") y += amount;
if (event.key === "ArrowDown") y -= amount;
moveSelectedProp(x, y);
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
camera.aspect = aspect;
// Keep the full stage visible on narrow screens.
orbit.fitRadius = aspect < 1
? 14.2 * Math.pow(1 / aspect, 0.78)
: 14.2;
if (Math.abs(orbit.radius - orbit.fitRadius) < 0.01 || window.innerWidth > 860) {
orbit.radius = orbit.fitRadius;
}
camera.updateProjectionMatrix();
applyCamera();
}
window.addEventListener("resize", resize);
resize();
updatePlayButton();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
elapsed += dt;
if (elapsed >= duration) elapsed %= duration;
}
updateStory(elapsed);
const totalTime = now * 0.001;
for (const mote of motes) {
mote.mesh.position.y = mote.baseY + Math.sin(totalTime * mote.speed + mote.phase) * 0.13;
mote.mesh.rotation.x = totalTime * 0.18 + mote.phase;
mote.mesh.rotation.y = totalTime * 0.14 + mote.phase;
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```