Prompt specification
Build or customize the Three.js 3D scene "Blocking a Silent Story" 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: Blocking a Silent Story
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/blocking-a-silent-story-x3356
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts an interactive voxel theatre stage for a silent misunderstanding. Use two original actors, a small table, a parcel, and a movable screen. One actor places the parcel down; the second moves it while the first actor's view is blocked; let users reposition the screen and actor marks before replaying the sequence; include a few selectable audience seats so an action visible from one seat may be hidden from another. Keep the parcel's motion and ownership consistent, and show each actor's facing direction. The story should be readable through blocking and contact rather than dialogue balloons explaining every action. Give the screen a visible floor footprint, and include one central audience position plus two side positions with distinctly different lines of sight.
Working Three.js Starter (blocking-a-silent-story-x3356):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quiet Errand — Voxel Theatre</title>
<style>
:root {
color-scheme: dark;
--ink: #f3f0e8;
--muted: #aeb9c5;
--nell: #f06a5e;
--bram: #4ba9c8;
--panel: rgba(14, 22, 31, 0.9);
--line: rgba(255, 255, 255, 0.14);
--green: #72e0a5;
--red: #ff756c;
}
* { box-sizing: border-box; }
body {
margin: 0;
overflow: hidden;
background: #111923;
color: var(--ink);
font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100vw;
height: 100vh;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(12px);
}
#hud {
top: 16px;
left: 16px;
width: min(330px, calc(100vw - 32px));
padding: 16px;
}
h1 {
margin: 0;
font-size: 24px;
line-height: 1.1;
letter-spacing: 0.01em;
}
.subtitle {
margin: 7px 0 14px;
color: var(--muted);
font-size: 12px;
}
.legend {
display: flex;
gap: 14px;
flex-wrap: wrap;
margin: 0 0 13px;
}
.dot {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 6px;
border-radius: 2px;
vertical-align: 0;
}
.nell { background: var(--nell); }
.bram { background: var(--bram); }
.row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 7px 0;
}
.row span:first-child {
color: var(--muted);
}
#visibility {
font-weight: 700;
text-align: right;
}
.clear { color: var(--green); }
.blocked { color: var(--red); }
.buttons {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 8px;
padding: 8px 10px;
background: #1b2a38;
color: var(--ink);
font: inherit;
cursor: pointer;
}
button:hover { background: #26394a; }
button.active { border-color: #d9e6ee; background: #355064; }
button.primary { background: #dce8ee; color: #14212c; font-weight: 700; }
button:disabled { opacity: 0.5; cursor: default; }
.progress {
height: 5px;
margin: 13px 0 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.1);
}
#progress-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--nell), var(--bram));
}
#clock {
color: var(--muted);
font-size: 11px;
text-align: right;
}
#editor {
top: 16px;
right: 16px;
width: min(320px, calc(100vw - 32px));
max-height: calc(100vh - 32px);
overflow: auto;
padding: 14px;
}
#editor summary {
cursor: pointer;
font-weight: 700;
letter-spacing: 0.02em;
}
.group-title {
margin: 15px 0 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control {
margin: 9px 0;
}
.control label {
display: flex;
justify-content: space-between;
gap: 10px;
color: #d7dee4;
font-size: 12px;
}
.control output {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 5px 0 0;
accent-color: #dce8ee;
}
#hint {
position: fixed;
z-index: 10;
left: 50%;
bottom: 14px;
transform: translateX(-50%);
max-width: min(760px, calc(100vw - 32px));
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(14, 22, 31, 0.82);
color: #cbd4dc;
text-align: center;
font-size: 12px;
pointer-events: none;
}
@media (max-width: 760px) {
#hud { top: 10px; left: 10px; }
#editor { top: auto; right: 10px; bottom: 64px; max-height: 43vh; }
#hint { font-size: 10px; }
}
</style>
</head>
<body>
<section id="hud" class="panel">
<h1>Quiet Errand</h1>
<div class="subtitle">A voxel misunderstanding told through placement, contact, and sightlines.</div>
<div class="legend">
<span><i class="dot nell"></i>Nell</span>
<span><i class="dot bram"></i>Bram</span>
</div>
<div class="row">
<span>Parcel</span>
<strong id="parcel-status">Held by Nell</strong>
</div>
<div class="row">
<span>Table sightline</span>
<strong id="visibility">Checking…</strong>
</div>
<div class="buttons" aria-label="Camera and audience positions">
<button id="overview">Overview</button>
<button data-seat="left">Left seat</button>
<button data-seat="center">Center seat</button>
<button data-seat="right">Right seat</button>
</div>
<div class="buttons" style="margin-top:10px">
<button id="replay" class="primary">Replay sequence</button>
<button id="pause">Pause</button>
<button id="rewind">Rewind</button>
</div>
<div class="progress"><div id="progress-fill"></div></div>
<div id="clock">0.0 / 14.0 s</div>
</section>
<section id="editor" class="panel">
<details open>
<summary>Stage blocking</summary>
<div class="group-title">Movable screen</div>
<div class="control">
<label for="screen-x">Horizontal <output id="screen-x-out"></output></label>
<input id="screen-x" type="range" min="-3.8" max="4.5" step="0.1" value="-1.35">
</div>
<div class="control">
<label for="screen-z">Depth <output id="screen-z-out"></output></label>
<input id="screen-z" type="range" min="-3" max="2.2" step="0.1" value="-0.2">
</div>
<div class="control">
<label for="screen-angle">Angle <output id="screen-angle-out"></output></label>
<input id="screen-angle" type="range" min="-80" max="80" step="1" value="0">
</div>
<div class="group-title">Nell’s starting mark</div>
<div class="control">
<label for="nell-x">Horizontal <output id="nell-x-out"></output></label>
<input id="nell-x" type="range" min="-6" max="6" step="0.1" value="-4.8">
</div>
<div class="control">
<label for="nell-z">Depth <output id="nell-z-out"></output></label>
<input id="nell-z" type="range" min="-3.5" max="3.2" step="0.1" value="2.3">
</div>
<div class="group-title">Bram’s starting mark</div>
<div class="control">
<label for="bram-x">Horizontal <output id="bram-x-out"></output></label>
<input id="bram-x" type="range" min="-6" max="6" step="0.1" value="3.8">
</div>
<div class="control">
<label for="bram-z">Depth <output id="bram-z-out"></output></label>
<input id="bram-z" type="range" min="-3.5" max="3.2" step="0.1" value="1.5">
</div>
<div class="buttons" style="margin-top:12px">
<button id="reset-blocking">Reset blocking</button>
</div>
</details>
</section>
<div id="hint">
Drag the screen or colored floor marks to reblock · Click seats or use seat buttons ·
Drag empty space to orbit · Wheel to zoom
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and renderer
// -------------------------------------------------------------------------
const COLORS = {
nell: 0xf06a5e,
bram: 0x4ba9c8,
wood: 0x916342,
parcel: 0xc99a58,
tape: 0xf1d29a,
screen: 0x31536c,
frame: 0x27333d,
footprint: 0x65d5d0,
floor: 0x222d36,
stage: 0x3b4650,
auditorium: 0x151e28,
gold: 0xd5b96f
};
const DURATION = 14;
const SCREEN_WIDTH = 4;
const SCREEN_HEIGHT = 2.8;
const TABLE = new THREE.Vector3(-3.2, 0, -1.8);
const TABLE_STAND = new THREE.Vector3(-3.2, 0, -0.8);
const TABLE_PARCEL = new THREE.Vector3(TABLE.x, 1.14, TABLE.z);
const DEFAULTS = {
screen: { x: -1.35, z: -0.2, angle: 0 },
nell: { x: -4.8, z: 2.3 },
bram: { x: 3.8, z: 1.5 }
};
const blocking = {
screen: { ...DEFAULTS.screen },
nell: { ...DEFAULTS.nell },
bram: { ...DEFAULTS.bram }
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101923);
scene.fog = new THREE.Fog(0x101923, 22, 42);
const camera = new THREE.PerspectiveCamera(
49,
innerWidth / innerHeight,
0.05,
80
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xcce8ff, 0x30251f, 2.1);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffe2bc, 3.1);
key.position.set(7, 13, 9);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 12;
key.shadow.camera.bottom = -12;
key.shadow.normalBias = 0.025;
scene.add(key);
const rim = new THREE.DirectionalLight(0x6fb9e7, 1.5);
rim.position.set(-8, 7, -7);
scene.add(rim);
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
let timeline = 0;
let isPlaying = false;
let cameraMode = "overview";
let selectedSeatId = "left";
const orbit = {
target: new THREE.Vector3(0, 0.8, -0.5),
radius: 18,
theta: 0.63,
phi: 1.02
};
const seatLook = { yaw: 0, pitch: 0 };
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0.02,
...options
});
}
function addBox(parent, w, h, d, color, x = 0, y = 0, z = 0, options = {}) {
const material = options.material || standardMaterial(color, options);
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function makeTextSprite(text, color = "#ffffff", width = 1.5) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(12,19,27,0.78)";
ctx.fillRect(8, 8, 496, 80);
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.strokeRect(8, 8, 496, 80);
ctx.fillStyle = color;
ctx.font = "700 46px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(width, width * 96 / 512, 1);
sprite.renderOrder = 20;
return sprite;
}
function setShadowRecursive(object) {
object.traverse(child => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
}
// -------------------------------------------------------------------------
// Stage, backdrop, curtains and footlights
// -------------------------------------------------------------------------
addBox(scene, 28, 0.4, 20, COLORS.auditorium, 0, -0.85, 2);
const stage = addBox(scene, 14.4, 0.4, 9.6, COLORS.stage, 0, -0.2, -0.5);
stage.castShadow = false;
const grid = new THREE.GridHelper(14, 28, 0x78909e, 0x596975);
grid.position.set(0, 0.012, -0.5);
grid.scale.z = 9.6 / 14;
grid.material.transparent = true;
grid.material.opacity = 0.27;
scene.add(grid);
addBox(scene, 14.4, 0.14, 0.16, 0x151d24, 0, -0.05, 4.3);
addBox(scene, 14.1, 4.7, 0.25, 0x17222c, 0, 2.25, -5.25);
for (const side of [-1, 1]) {
for (let i = 0; i < 4; i++) {
const x = side * (5.5 + i * 0.24);
addBox(scene, 0.28, 4.5, 0.42, i % 2 ? 0x6f2837 : 0x813443,
x, 2.15, -5.0);
}
}
for (let i = 0; i < 11; i++) {
addBox(scene, 0.34, 0.12, 0.28, 0xffd99a,
-6.2 + i * 1.24, 0.13, 4.04,
{ emissive: 0x8f5420, emissiveIntensity: 0.45 });
}
// Small table.
const table = new THREE.Group();
table.position.copy(TABLE);
scene.add(table);
addBox(table, 1.55, 0.18, 1.08, COLORS.wood, 0, 0.81, 0);
for (const x of [-0.58, 0.58]) {
for (const z of [-0.36, 0.36]) {
addBox(table, 0.15, 0.74, 0.15, 0x65412c, x, 0.37, z);
}
}
addBox(table, 1.24, 0.1, 0.72, 0x71482f, 0, 0.3, 0);
// -------------------------------------------------------------------------
// Actors
// Local forward direction is +Z. Nose and floor chevron show facing.
// -------------------------------------------------------------------------
function createActor(color, name) {
const root = new THREE.Group();
const visual = new THREE.Group();
root.add(visual);
scene.add(root);
const bodyMaterial = standardMaterial(color);
const skinMaterial = standardMaterial(0xdca77e);
const darkMaterial = standardMaterial(0x252a2e);
addBox(visual, 0.7, 0.72, 0.42, color, 0, 1.02, 0);
addBox(visual, 0.53, 0.5, 0.49, 0xdca77e, 0, 1.62, 0.015);
addBox(visual, 0.55, 0.15, 0.51, 0x343035, 0, 1.89, 0.005);
// Nose and eyes face local +Z.
addBox(visual, 0.12, 0.11, 0.1, skinMaterial, 0, 1.63, 0.29);
addBox(visual, 0.055, 0.055, 0.025, darkMaterial, -0.12, 1.69, 0.263);
addBox(visual, 0.055, 0.055, 0.025, darkMaterial, 0.12, 1.69, 0.263);
const legs = [];
for (const x of [-0.2, 0.2]) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.64, 0);
addBox(pivot, 0.23, 0.57, 0.25, 0x28333e, 0, -0.27, 0);
addBox(pivot, 0.25, 0.12, 0.39, 0x1d252c, 0, -0.56, 0.06);
visual.add(pivot);
legs.push(pivot);
}
const arms = [];
for (const x of [-0.46, 0.46]) {
const pivot = new THREE.Group();
pivot.position.set(x, 1.31, 0);
addBox(pivot, 0.18, 0.57, 0.2, color, 0, -0.25, 0);
addBox(pivot, 0.2, 0.16, 0.22, skinMaterial, 0, -0.56, 0);
visual.add(pivot);
arms.push(pivot);
}
// A floor chevron points in the actor's local forward direction.
const arrowMaterial = new THREE.MeshBasicMaterial({ color });
addBox(root, 0.08, 0.035, 0.58, color, 0, 0.035, 0.84,
{ material: arrowMaterial, castShadow: false });
const wingA = addBox(root, 0.08, 0.035, 0.46, color, -0.17, 0.035, 1.02,
{ material: arrowMaterial, castShadow: false });
wingA.rotation.y = -0.62;
const wingB = addBox(root, 0.08, 0.035, 0.46, color, 0.17, 0.035, 1.02,
{ material: arrowMaterial, castShadow: false });
wingB.rotation.y = 0.62;
const label = makeTextSprite(name, `#${color.toString(16).padStart(6, "0")}`, 1.22);
label.position.set(0, 2.42, 0);
root.add(label);
setShadowRecursive(visual);
return {
root,
visual,
legs,
arms,
name,
moving: false,
phase: Math.random() * Math.PI * 2
};
}
const nell = createActor(COLORS.nell, "NELL");
const bram = createActor(COLORS.bram, "BRAM");
function createMark(color, label) {
const group = new THREE.Group();
const plate = addBox(group, 0.74, 0.035, 0.74, color, 0, 0.03, 0, {
transparent: true,
opacity: 0.3,
depthWrite: false,
castShadow: false
});
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.76, 0.04, 0.76)),
new THREE.LineBasicMaterial({ color, transparent: true, opacity: 0.95 })
);
outline.position.y = 0.04;
group.add(outline);
const tag = makeTextSprite(label, `#${color.toString(16).padStart(6, "0")}`, 1.02);
tag.position.set(0, 0.24, 0);
group.add(tag);
plate.userData.pickType = label.includes("NELL") ? "nell-mark" : "bram-mark";
scene.add(group);
return { group, plate };
}
const nellMark = createMark(COLORS.nell, "NELL MARK");
const bramMark = createMark(COLORS.bram, "BRAM MARK");
// -------------------------------------------------------------------------
// Parcel. Its position is always derived from its current owner or support.
// -------------------------------------------------------------------------
const parcel = new THREE.Group();
scene.add(parcel);
addBox(parcel, 0.44, 0.44, 0.44, COLORS.parcel, 0, 0, 0);
addBox(parcel, 0.46, 0.055, 0.1, COLORS.tape, 0, 0.08, 0);
addBox(parcel, 0.1, 0.055, 0.46, COLORS.tape, 0, 0.08, 0);
const custodyTag = addBox(
parcel, 0.13, 0.07, 0.13, COLORS.gold, 0, 0.27, 0,
{ emissive: 0x3b2c0a, emissiveIntensity: 0.45 }
);
setShadowRecursive(parcel);
// -------------------------------------------------------------------------
// Movable screen, including a visible floor footprint.
// -------------------------------------------------------------------------
const screenGroup = new THREE.Group();
scene.add(screenGroup);
const screenPanel = addBox(
screenGroup, SCREEN_WIDTH, SCREEN_HEIGHT, 0.16,
COLORS.screen, 0, 1.46, 0
);
screenPanel.userData.pickType = "screen";
addBox(screenGroup, 0.12, SCREEN_HEIGHT + 0.15, 0.22, COLORS.frame,
-SCREEN_WIDTH / 2, 1.46, 0);
addBox(screenGroup, 0.12, SCREEN_HEIGHT + 0.15, 0.22, COLORS.frame,
SCREEN_WIDTH / 2, 1.46, 0);
addBox(screenGroup, SCREEN_WIDTH + 0.12, 0.1, 0.22, COLORS.frame,
0, SCREEN_HEIGHT + 0.1, 0);
addBox(screenGroup, SCREEN_WIDTH + 0.12, 0.1, 0.22, COLORS.frame,
0, 0.08, 0);
for (const x of [-SCREEN_WIDTH / 2 + 0.25, SCREEN_WIDTH / 2 - 0.25]) {
addBox(screenGroup, 0.09, 0.08, 0.95, COLORS.frame, x, 0.07, 0);
addBox(screenGroup, 0.2, 0.2, 0.2, 0x182128, x, 0.11, 0.37);
addBox(screenGroup, 0.2, 0.2, 0.2, 0x182128, x, 0.11, -0.37);
}
const footprint = addBox(
screenGroup, SCREEN_WIDTH + 0.28, 0.025, 0.88,
COLORS.footprint, 0, 0.025, 0,
{
transparent: true,
opacity: 0.19,
depthWrite: false,
castShadow: false
}
);
footprint.userData.pickType = "screen";
const footprintPoints = [
new THREE.Vector3(-SCREEN_WIDTH / 2 - 0.14, 0.055, 0.44),
new THREE.Vector3(SCREEN_WIDTH / 2 + 0.14, 0.055, 0.44),
new THREE.Vector3(SCREEN_WIDTH / 2 + 0.14, 0.055, -0.44),
new THREE.Vector3(-SCREEN_WIDTH / 2 - 0.14, 0.055, -0.44)
];
const footprintOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(footprintPoints),
new THREE.LineBasicMaterial({ color: COLORS.footprint })
);
screenGroup.add(footprintOutline);
const screenLabel = makeTextSprite("SCREEN", "#65d5d0", 1.1);
screenLabel.position.set(0, 3.15, 0);
screenGroup.add(screenLabel);
// -------------------------------------------------------------------------
// Audience seats: one center and two side positions.
// -------------------------------------------------------------------------
const seats = {};
const seatHitMeshes = [];
function createSeat(id, x, z, label, accent) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const upholstery = standardMaterial(0x263d50);
addBox(group, 0.95, 0.22, 0.8, upholstery, 0, -0.38, -0.05);
addBox(group, 0.95, 0.9, 0.18, upholstery, 0, 0.03, 0.31);
addBox(group, 0.12, 0.4, 0.12, 0x1a222a, -0.34, -0.65, -0.05);
addBox(group, 0.12, 0.4, 0.12, 0x1a222a, 0.34, -0.65, -0.05);
const marker = addBox(group, 0.12, 0.035, 0.75, accent, 0, -0.255, -0.05,
{ emissive: accent, emissiveIntensity: 0.15, castShadow: false });
const tag = makeTextSprite(label, `#${accent.toString(16).padStart(6, "0")}`, 1.2);
tag.position.set(0, 1.05, 0);
group.add(tag);
const hit = addBox(group, 1.15, 1.6, 1, 0xffffff, 0, 0, 0, {
transparent: true,
opacity: 0,
depthWrite: false,
castShadow: false
});
hit.userData.seatId = id;
seatHitMeshes.push(hit);
seats[id] = { group, marker, x, z, label };
}
createSeat("left", -6.4, 7.4, "LEFT", 0xf3b664);
createSeat("center", 0, 7.4, "CENTER", 0x9fd1e5);
createSeat("right", 6.4, 7.4, "RIGHT", 0xd991b4);
// Sightline from the selected seat to the table exchange.
const sightGeometry = new THREE.BufferGeometry();
sightGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const sightMaterial = new THREE.LineBasicMaterial({
color: COLORS.gold,
transparent: true,
opacity: 0.95
});
const sightLine = new THREE.Line(sightGeometry, sightMaterial);
sightLine.frustumCulled = false;
scene.add(sightLine);
// -------------------------------------------------------------------------
// UI references
// -------------------------------------------------------------------------
const parcelStatus = document.querySelector("#parcel-status");
const visibility = document.querySelector("#visibility");
const progressFill = document.querySelector("#progress-fill");
const clockLabel = document.querySelector("#clock");
const pauseButton = document.querySelector("#pause");
const rangeInputs = [
["screen-x", "screen", "x"],
["screen-z", "screen", "z"],
["screen-angle", "screen", "angle"],
["nell-x", "nell", "x"],
["nell-z", "nell", "z"],
["bram-x", "bram", "x"],
["bram-z", "bram", "z"]
];
// -------------------------------------------------------------------------
// Blocking calculations
// -------------------------------------------------------------------------
const blockingPoints = {
blind: new THREE.Vector3(),
inspect: new THREE.Vector3(),
nellEdge: new THREE.Vector3(),
bramEdge: new THREE.Vector3(),
bDrop: new THREE.Vector3(),
floorParcel: new THREE.Vector3()
};
const clamp = THREE.MathUtils.clamp;
const smooth = u => u * u * (3 - 2 * u);
const segment = (t, a, b) => clamp((t - a) / (b - a), 0, 1);
function lerpXZ(a, b, u) {
return new THREE.Vector3(
THREE.MathUtils.lerp(a.x, b.x, u),
0,
THREE.MathUtils.lerp(a.z, b.z, u)
);
}
function screenLocalToWorld(localX, localZ) {
const a = THREE.MathUtils.degToRad(blocking.screen.angle);
const c = Math.cos(a);
const s = Math.sin(a);
return new THREE.Vector3(
blocking.screen.x + c * localX + s * localZ,
0,
blocking.screen.z - s * localX + c * localZ
);
}
function worldToScreenLocal(point) {
const a = THREE.MathUtils.degToRad(blocking.screen.angle);
const c = Math.cos(a);
const s = Math.sin(a);
const dx = point.x - blocking.screen.x;
const dz = point.z - blocking.screen.z;
return { x: c * dx - s * dz, z: s * dx + c * dz };
}
function computeBlockingPoints() {
const tableLocal = worldToScreenLocal(TABLE);
// Pick a point P on the panel that lies between Nell's blind point
// and the table. Extending the table-to-P line places Nell beyond the panel.
const panelX = clamp(
tableLocal.x,
-SCREEN_WIDTH / 2 + 0.25,
SCREEN_WIDTH / 2 - 0.25
);
const p = screenLocalToWorld(panelX, 0);
const direction = p.clone().sub(TABLE);
if (direction.lengthSq() < 0.01) direction.set(1, 0, 0);
direction.normalize();
blockingPoints.blind.copy(p).addScaledVector(direction, 1.15);
// Nell's final inspection point is on the table side of the screen.
const awayFromScreen = TABLE.clone()
.sub(new THREE.Vector3(blocking.screen.x, 0, blocking.screen.z))
.normalize()
.multiplyScalar(1.35);
blockingPoints.inspect.copy(TABLE).add(awayFromScreen);
// Nell goes around the nearest screen edge instead of through the panel.
const blindLocal = worldToScreenLocal(blockingPoints.blind);
const nellSide = blindLocal.x >= 0 ? 1 : -1;
blockingPoints.nellEdge.copy(
screenLocalToWorld(nellSide * (SCREEN_WIDTH / 2 + 0.55), blindLocal.z)
);
// Bram also uses a clear route around the opposite side.
const bMark = new THREE.Vector3(blocking.bram.x, 0, blocking.bram.z);
blockingPoints.bDrop.copy(bMark).add(new THREE.Vector3(0, 0, -0.9));
blockingPoints.floorParcel.copy(blockingPoints.bDrop)
.add(new THREE.Vector3(0, 0, 0.55));
const destinationLocal = worldToScreenLocal(blockingPoints.bDrop);
const bramSide = destinationLocal.x >= 0 ? 1 : -1;
const standLocal = worldToScreenLocal(TABLE_STAND);
blockingPoints.bramEdge.copy(
screenLocalToWorld(bramSide * (SCREEN_WIDTH / 2 + 0.55), standLocal.z)
);
}
function syncControls() {
for (const [id, groupName, property] of rangeInputs) {
const input = document.querySelector(`#${id}`);
input.value = blocking[groupName][property];
const output = document.querySelector(`#${id}-out`);
if (property === "angle") {
output.textContent = `${Math.round(blocking[groupName][property])}°`;
} else {
output.textContent = blocking[groupName][property].toFixed(1);
}
}
}
function setEditorEnabled(enabled) {
for (const [id] of rangeInputs) {
document.querySelector(`#${id}`).disabled = !enabled;
}
}
function applyBlocking() {
screenGroup.position.set(blocking.screen.x, 0, blocking.screen.z);
screenGroup.rotation.y = THREE.MathUtils.degToRad(blocking.screen.angle);
nellMark.group.position.set(blocking.nell.x, 0, blocking.nell.z);
bramMark.group.position.set(blocking.bram.x, 0, blocking.bram.z);
computeBlockingPoints();
if (!isPlaying) {
updateTimeline(0);
updateSightline();
}
}
for (const [id, groupName, property] of rangeInputs) {
document.querySelector(`#${id}`).addEventListener("input", event => {
blocking[groupName][property] = Number(event.target.value);
isPlaying = false;
timeline = 0;
syncControls();
applyBlocking();
setEditorEnabled(true);
updatePlaybackButtons();
});
}
document.querySelector("#reset-blocking").addEventListener("click", () => {
blocking.screen = { ...DEFAULTS.screen };
blocking.nell = { ...DEFAULTS.nell };
blocking.bram = { ...DEFAULTS.bram };
timeline = 0;
isPlaying = false;
syncControls();
applyBlocking();
setEditorEnabled(true);
updatePlaybackButtons();
});
// -------------------------------------------------------------------------
// Timeline. This is the single source of truth for parcel custody.
// -------------------------------------------------------------------------
function placeActor(actor, position, faceTarget, moving = false) {
actor.root.position.set(position.x, 0, position.z);
const dx = faceTarget.x - position.x;
const dz = faceTarget.z - position.z;
if (dx * dx + dz * dz > 0.0001) {
actor.root.rotation.y = Math.atan2(dx, dz);
}
actor.moving = moving;
}
function carryPoint(actor) {
const yaw = actor.root.rotation.y;
return new THREE.Vector3(
actor.root.position.x + Math.sin(yaw) * 0.66,
0.98,
actor.root.position.z + Math.cos(yaw) * 0.66
);
}
function updateTimeline(t) {
timeline = t;
const nellStart = new THREE.Vector3(blocking.nell.x, 0, blocking.nell.z);
const bramStart = new THREE.Vector3(blocking.bram.x, 0, blocking.bram.z);
// NELL:
// Carry parcel to the table, place it, move behind the screen, discover
// the empty table after the transfer, then look toward the table.
if (t < 1) {
placeActor(nell, nellStart, TABLE);
} else if (t < 3.2) {
const u = smooth(segment(t, 1, 3.2));
const p = lerpXZ(nellStart, TABLE_STAND, u);
placeActor(nell, p, TABLE_STAND, true);
} else if (t < 4) {
placeActor(nell, TABLE_STAND, TABLE);
} else if (t < 5.1) {
const u = smooth(segment(t, 4, 5.1));
const p = lerpXZ(TABLE_STAND, blockingPoints.nellEdge, u);
placeActor(nell, p, blockingPoints.nellEdge, true);
} else if (t < 5.9) {
const u = smooth(segment(t, 5.1, 5.9));
const p = lerpXZ(blockingPoints.nellEdge, blockingPoints.blind, u);
placeActor(nell, p, blockingPoints.blind, true);
} else if (t < 11.7) {
placeActor(nell, blockingPoints.blind, TABLE);
} else if (t < 12.7) {
const u = smooth(segment(t, 11.7, 12.7));
const p = lerpXZ(blockingPoints.blind, blockingPoints.nellEdge, u);
placeActor(nell, p, blockingPoints.nellEdge, true);
} else if (t < 13.7) {
const u = smooth(segment(t, 12.7, 13.7));
const p = lerpXZ(blockingPoints.nellEdge, blockingPoints.inspect, u);
placeActor(nell, p, blockingPoints.inspect, true);
} else {
placeActor(nell, blockingPoints.inspect, TABLE);
}
// BRAM:
// Approach around the screen, contact the parcel, carry it to his mark,
// place it on the floor, and return empty-handed.
if (t < 6.5) {
placeActor(bram, bramStart, TABLE);
} else if (t < 7.3) {
const u = smooth(segment(t, 6.5, 7.3));
const p = lerpXZ(bramStart, blockingPoints.bramEdge, u);
placeActor(bram, p, blockingPoints.bramEdge, true);
} else if (t < 8.3) {
const u = smooth(segment(t, 7.3, 8.3));
const p = lerpXZ(blockingPoints.bramEdge, TABLE_STAND, u);
placeActor(bram, p, TABLE_STAND, true);
} else if (t < 8.5) {
placeActor(bram, TABLE_STAND, TABLE);
} else if (t < 9.8) {
const u = smooth(segment(t, 8.5, 9.8));
const p = lerpXZ(TABLE_STAND, blockingPoints.bramEdge, u);
placeActor(bram, p, blockingPoints.bramEdge, true);
} else if (t < 11.3) {
const u = smooth(segment(t, 9.8, 11.3));
const p = lerpXZ(blockingPoints.bramEdge, blockingPoints.bDrop, u);
placeActor(bram, p, blockingPoints.bDrop, true);
} else if (t < 12) {
placeActor(bram, blockingPoints.bDrop, bramStart);
} else if (t < DURATION) {
const u = smooth(segment(t, 12, DURATION));
const p = lerpXZ(blockingPoints.bDrop, bramStart, u);
placeActor(bram, p, bramStart, true);
} else {
placeActor(bram, bramStart, TABLE);
}
// Small body-language details: walking bob, leg swing and carrying arms.
for (const actor of [nell, bram]) {
const walk = actor.moving ? Math.abs(Math.sin(t * 10 + actor.phase)) : 0;
actor.visual.position.y = actor.moving ? walk * 0.045 : 0;
actor.legs[0].rotation.x = actor.moving ? Math.sin(t * 10 + actor.phase) * 0.48 : 0;
actor.legs[1].rotation.x = actor.moving ? -Math.sin(t * 10 + actor.phase) * 0.48 : 0;
}
// The parcel's custody changes only at actual contact/place moments.
let owner = null;
let parcelPosition;
if (t < 3.2) {
owner = "nell";
parcelPosition = carryPoint(nell);
} else if (t < 4) {
owner = "nell";
parcelPosition = carryPoint(nell).lerp(
TABLE_PARCEL,
smooth(segment(t, 3.2, 4))
);
} else if (t < 8.3) {
owner = null;
parcelPosition = TABLE_PARCEL.clone();
} else if (t < 9) {
owner = "bram";
parcelPosition = TABLE_PARCEL.clone().lerp(
carryPoint(bram),
smooth(segment(t, 8.3, 9))
);
} else if (t < 11.3) {
owner = "bram";
parcelPosition = carryPoint(bram);
} else if (t < 12) {
owner = "bram";
parcelPosition = carryPoint(bram).lerp(
blockingPoints.floorParcel,
smooth(segment(t, 11.3, 12))
);
} else {
owner = null;
parcelPosition = blockingPoints.floorParcel.clone();
}
parcel.position.copy(parcelPosition);
custodyTag.material.color.setHex(
owner === "nell" ? COLORS.nell :
owner === "bram" ? COLORS.bram :
COLORS.gold
);
nell.arms.forEach(arm => arm.rotation.x = owner === "nell" ? -0.82 : -0.08);
bram.arms.forEach(arm => arm.rotation.x = owner === "bram" ? -0.82 : -0.08);
if (owner === "nell") {
parcelStatus.textContent = "Held by Nell";
} else if (owner === "bram") {
parcelStatus.textContent = "Held by Bram";
} else if (t < 8.3) {
parcelStatus.textContent = "Resting on table";
} else {
parcelStatus.textContent = "On floor near Bram’s mark";
}
progressFill.style.width = `${(t / DURATION) * 100}%`;
clockLabel.textContent = `${t.toFixed(1)} / ${DURATION.toFixed(1)} s`;
}
// -------------------------------------------------------------------------
// Audience sightline test
// -------------------------------------------------------------------------
function updateSightline() {
scene.updateMatrixWorld(true);
const seat = seats[selectedSeatId];
const origin = new THREE.Vector3(seat.x, 0.25, seat.z);
const target = TABLE_PARCEL.clone();
const direction = target.clone().sub(origin);
const distance = direction.length();
direction.normalize();
raycaster.near = 0;
raycaster.far = distance;
raycaster.set(origin, direction);
const hits = raycaster.intersectObject(screenPanel, false);
const blocked = hits.length > 0 && hits[0].distance < distance - 0.02;
const endpoint = blocked ? hits[0].point.clone() : target;
const positions = sightGeometry.attributes.position;
positions.setXYZ(0, origin.x, origin.y, origin.z);
positions.setXYZ(1, endpoint.x, endpoint.y, endpoint.z);
positions.needsUpdate = true;
sightMaterial.color.setHex(blocked ? 0xff756c : 0x72e0a5);
visibility.textContent = blocked ? "SCREEN BLOCKS VIEW" : "CLEAR VIEW";
visibility.className = blocked ? "blocked" : "clear";
}
// -------------------------------------------------------------------------
// Camera and seat selection
// -------------------------------------------------------------------------
function updateOverviewCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function focusPoint() {
if (timeline > 11.7) return TABLE_PARCEL;
return parcel.position;
}
function updateSeatCamera() {
const seat = seats[selectedSeatId];
camera.position.set(seat.x, 0.25, seat.z);
camera.lookAt(focusPoint());
camera.rotateY(seatLook.yaw);
camera.rotateX(seatLook.pitch);
}
function updateSeatButtons() {
document.querySelectorAll("[data-seat]").forEach(button => {
button.classList.toggle("active", cameraMode === "seat" && button.dataset.seat === selectedSeatId);
});
document.querySelector("#overview").classList.toggle("active", cameraMode === "overview");
}
function selectSeat(id) {
selectedSeatId = id;
cameraMode = "seat";
seatLook.yaw = 0;
seatLook.pitch = 0;
updateSeatButtons();
updateSightline();
}
document.querySelector("#overview").addEventListener("click", () => {
cameraMode = "overview";
updateSeatButtons();
});
document.querySelectorAll("[data-seat]").forEach(button => {
button.addEventListener("click", () => selectSeat(button.dataset.seat));
});
// -------------------------------------------------------------------------
// Playback
// -------------------------------------------------------------------------
function updatePlaybackButtons() {
pauseButton.textContent = isPlaying ? "Pause" : (timeline > 0 ? "Continue" : "Pause");
}
document.querySelector("#replay").addEventListener("click", () => {
timeline = 0;
isPlaying = true;
updateTimeline(0);
setEditorEnabled(false);
updatePlaybackButtons();
});
pauseButton.addEventListener("click", () => {
if (timeline >= DURATION) timeline = 0;
isPlaying = !isPlaying;
setEditorEnabled(!isPlaying);
updatePlaybackButtons();
});
document.querySelector("#rewind").addEventListener("click", () => {
timeline = 0;
isPlaying = false;
updateTimeline(0);
setEditorEnabled(true);
updatePlaybackButtons();
updateSightline();
});
// -------------------------------------------------------------------------
// Direct manipulation: screen, actor marks and selectable seats
// -------------------------------------------------------------------------
const pickMeshes = [
screenPanel,
footprint,
nellMark.plate,
bramMark.plate
];
let pointerDrag = null;
function pointerRay(event) {
const rect = renderer.domElement.getBoundingClientRect();
const pointer = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
raycaster.near = 0;
raycaster.far = Infinity;
raycaster.setFromCamera(pointer, camera);
return pointer;
}
function groundPoint(event) {
pointerRay(event);
return raycaster.ray.intersectPlane(groundPlane, new THREE.Vector3());
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
const seatHit = raycaster.intersectObjects(seatHitMeshes, false)[0];
if (seatHit) {
selectSeat(seatHit.object.userData.seatId);
return;
}
const pickHit = raycaster.intersectObjects(pickMeshes, false)[0];
if (pickHit && !isPlaying) {
const type = pickHit.object.userData.pickType;
const point = groundPoint(event);
if (point) {
if (type === "screen") {
pointerDrag = {
type,
offsetX: blocking.screen.x - point.x,
offsetZ: blocking.screen.z - point.z
};
} else if (type === "nell-mark") {
pointerDrag = {
type,
offsetX: blocking.nell.x - point.x,
offsetZ: blocking.nell.z - point.z
};
} else if (type === "bram-mark") {
pointerDrag = {
type,
offsetX: blocking.bram.x - point.x,
offsetZ: blocking.bram.z - point.z
};
}
}
if (pointerDrag) {
renderer.domElement.style.cursor = "grabbing";
return;
}
}
pointerDrag = {
type: "camera",
lastX: event.clientX,
lastY: event.clientY
};
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDrag) return;
if (pointerDrag.type === "camera") {
const dx = event.clientX - pointerDrag.lastX;
const dy = event.clientY - pointerDrag.lastY;
if (cameraMode === "overview") {
orbit.theta -= dx * 0.005;
orbit.phi = clamp(orbit.phi - dy * 0.004, 0.24, 1.45);
} else {
seatLook.yaw -= dx * 0.003;
seatLook.pitch = clamp(seatLook.pitch - dy * 0.002, -0.65, 0.65);
}
pointerDrag.lastX = event.clientX;
pointerDrag.lastY = event.clientY;
return;
}
const point = groundPoint(event);
if (!point) return;
if (pointerDrag.type === "screen") {
blocking.screen.x = clamp(point.x + pointerDrag.offsetX, -3.8, 4.5);
blocking.screen.z = clamp(point.z + pointerDrag.offsetZ, -3, 2.2);
} else if (pointerDrag.type === "nell-mark") {
blocking.nell.x = clamp(point.x + pointerDrag.offsetX, -6, 6);
blocking.nell.z = clamp(point.z + pointerDrag.offsetZ, -3.5, 3.2);
} else if (pointerDrag.type === "bram-mark") {
blocking.bram.x = clamp(point.x + pointerDrag.offsetX, -6, 6);
blocking.bram.z = clamp(point.z + pointerDrag.offsetZ, -3.5, 3.2);
}
syncControls();
applyBlocking();
});
function endPointerDrag() {
pointerDrag = null;
renderer.domElement.style.cursor = "default";
}
renderer.domElement.addEventListener("pointerup", endPointerDrag);
renderer.domElement.addEventListener("pointercancel", endPointerDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
if (cameraMode === "overview") {
orbit.radius = clamp(orbit.radius + event.deltaY * 0.012, 8, 30);
} else {
camera.fov = clamp(camera.fov + event.deltaY * 0.025, 35, 78);
camera.updateProjectionMatrix();
}
}, { passive: false });
addEventListener("keydown", event => {
if (event.code === "Space" && !event.target.matches("input, button")) {
event.preventDefault();
pauseButton.click();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (isPlaying) {
timeline += dt;
if (timeline >= DURATION) {
timeline = DURATION;
isPlaying = false;
setEditorEnabled(true);
updatePlaybackButtons();
}
}
updateTimeline(timeline);
updateSightline();
if (cameraMode === "overview") {
updateOverviewCamera();
} else {
updateSeatCamera();
}
renderer.render(scene, camera);
}
syncControls();
applyBlocking();
updateSeatButtons();
updatePlaybackButtons();
updateOverviewCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```