Prompt specification
Build or customize the Three.js 3D scene "Practice Drill With a Blocked Hallway" 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: Practice Drill With a Blocked Hallway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/practice-drill-with-a-blocked-hallway-x3226
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring coordination of fictional emergency tasks and routes. Animate a small group following a predeclared drill route, then use an alternate open path. Prevent intersections with walls and keep movement calm and non-graphic. Voxel style.
Working Three.js Starter (practice-drill-with-a-blocked-hallway-x3226):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Civic Drill Coordinator</title>
<style>
:root {
color-scheme: dark;
--ink: #eef6f7;
--muted: #a8bdc2;
--panel: rgba(17, 35, 43, 0.91);
--panel-edge: rgba(205, 233, 236, 0.14);
--teal: #41d6c3;
--amber: #ffc15a;
--green: #7be495;
--blue: #7eb8ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9dc;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
color: #17313a;
filter: drop-shadow(0 2px 10px rgba(255, 255, 255, 0.55));
}
.brand-mark {
display: grid;
grid-template-columns: repeat(2, 8px);
grid-template-rows: repeat(2, 8px);
gap: 3px;
padding: 7px;
border: 2px solid #17313a;
background: rgba(255, 255, 255, 0.62);
}
.brand-mark i {
display: block;
background: #17313a;
}
.brand-mark i:last-child {
background: #d98538;
}
.brand strong {
display: block;
font-size: 14px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.brand span {
display: block;
margin-top: 2px;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
opacity: 0.72;
}
.simulation-badge {
padding: 9px 13px;
border: 1px solid rgba(23, 49, 58, 0.28);
background: rgba(255, 255, 255, 0.78);
color: #17313a;
border-radius: 9px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
box-shadow: 0 8px 22px rgba(23, 49, 58, 0.1);
}
.panel {
position: fixed;
z-index: 10;
top: 88px;
left: 20px;
width: min(350px, calc(100vw - 40px));
max-height: calc(100vh - 122px);
overflow: auto;
padding: 19px;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--panel-edge);
border-radius: 18px;
box-shadow: 0 22px 55px rgba(18, 35, 42, 0.24);
backdrop-filter: blur(16px);
scrollbar-width: thin;
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 23px;
line-height: 1.12;
letter-spacing: -0.03em;
}
.summary {
margin: 9px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.safety {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 16px;
padding: 10px 11px;
border: 1px solid rgba(123, 228, 149, 0.23);
border-radius: 10px;
background: rgba(123, 228, 149, 0.08);
color: #c8f4d5;
font-size: 11px;
line-height: 1.35;
}
.safety-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--green);
box-shadow: 0 0 13px rgba(123, 228, 149, 0.7);
}
.progress-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.progress-track {
height: 7px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.09);
}
#progressFill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), var(--blue));
transition: width 0.12s linear;
}
.section-title {
margin: 19px 0 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.route-list {
display: grid;
gap: 7px;
}
.route-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 9px;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
transition: border-color 0.25s, background 0.25s;
}
.route-row.active {
border-color: rgba(65, 214, 195, 0.38);
background: rgba(65, 214, 195, 0.075);
}
.route-row.done {
border-color: rgba(123, 228, 149, 0.28);
}
.route-color {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--teal);
}
.route-row.alternate .route-color {
background: var(--amber);
}
.route-name {
font-size: 12px;
font-weight: 750;
}
.route-detail {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
.route-state {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.route-row.active .route-state {
color: var(--teal);
}
.route-row.alternate.active .route-state {
color: var(--amber);
}
.route-row.done .route-state {
color: var(--green);
}
.task-list {
display: grid;
gap: 8px;
}
.task {
padding: 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
}
.task-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.task-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 750;
}
.task-letter {
display: grid;
width: 22px;
height: 22px;
place-items: center;
border-radius: 5px;
background: rgba(126, 184, 255, 0.14);
color: var(--blue);
font-size: 10px;
font-weight: 900;
}
.task-status {
padding: 4px 7px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.07);
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.task.complete .task-status {
background: rgba(123, 228, 149, 0.13);
color: var(--green);
}
.task.active .task-status {
background: rgba(255, 193, 90, 0.14);
color: var(--amber);
}
.task-owner {
margin: 7px 0 0 30px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 18px;
}
button {
min-height: 38px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 255, 255, 0.065);
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
button:hover {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.22);
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: rgba(65, 214, 195, 0.32);
color: #082b2a;
background: var(--teal);
}
button.primary:hover {
background: #6be5d6;
}
button:disabled {
cursor: default;
opacity: 0.45;
}
.status-line {
min-height: 34px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.09);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.status-line strong {
color: var(--ink);
}
.scene-help {
position: fixed;
z-index: 8;
right: 20px;
bottom: 18px;
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid rgba(23, 49, 58, 0.16);
border-radius: 9px;
color: #17313a;
background: rgba(255, 255, 255, 0.78);
box-shadow: 0 8px 22px rgba(23, 49, 58, 0.1);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.03em;
}
.scene-help button {
min-height: 26px;
padding: 4px 8px;
border-color: rgba(23, 49, 58, 0.16);
color: #17313a;
background: rgba(255, 255, 255, 0.72);
font-size: 9px;
}
#toast {
position: fixed;
z-index: 20;
left: 50%;
bottom: 24px;
max-width: min(440px, calc(100vw - 32px));
padding: 12px 16px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 10px;
color: #eef8f8;
background: rgba(18, 37, 44, 0.93);
box-shadow: 0 15px 35px rgba(18, 37, 44, 0.24);
font-size: 12px;
font-weight: 700;
text-align: center;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity 0.25s, transform 0.25s;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 760px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand span {
display: none;
}
.simulation-badge {
max-width: 140px;
text-align: right;
}
.panel {
top: auto;
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
max-height: 43vh;
padding: 15px;
border-radius: 15px;
}
h1 {
font-size: 19px;
}
.summary {
margin-bottom: 12px;
}
.scene-help {
top: 66px;
right: 12px;
bottom: auto;
}
.scene-help span {
display: none;
}
#toast {
bottom: calc(43vh + 24px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated voxel emergency drill route"></canvas>
<div class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<strong>Civic Drill Coordinator</strong>
<span>Fictional readiness exercise 04</span>
</div>
</div>
<div class="simulation-badge">Simulation · Non-graphic</div>
</div>
<aside class="panel">
<p class="eyebrow">Community Support Drill</p>
<h1>Team Echo route check</h1>
<p class="summary">
Four responders follow the predeclared west-hall route, verify a supply
task, then continue through the open east courtyard.
</p>
<div class="safety">
<span class="safety-dot"></span>
<span><strong>Wall-safe routing active.</strong> Every movement follows a grid-safe centerline.</span>
</div>
<div class="progress-label">
<span>Drill progress</span>
<span id="progressValue">0%</span>
</div>
<div class="progress-track"><div id="progressFill"></div></div>
<h2 class="section-title">Route Plan</h2>
<div class="route-list">
<div class="route-row" id="primaryRoute">
<span class="route-color"></span>
<div>
<span class="route-name">Predeclared drill route</span>
<span class="route-detail">West hall → south room door</span>
</div>
<span class="route-state" id="primaryState">Active</span>
</div>
<div class="route-row alternate" id="alternateRoute">
<span class="route-color"></span>
<div>
<span class="route-name">Alternate open path</span>
<span class="route-detail">Task room → east courtyard</span>
</div>
<span class="route-state" id="alternateState">Planned</span>
</div>
</div>
<h2 class="section-title">Coordinated Tasks</h2>
<div class="task-list">
<div class="task active" id="taskA">
<div class="task-top">
<div class="task-title"><span class="task-letter">A</span> Supply inventory</div>
<span class="task-status" id="taskAStatus">In progress</span>
</div>
<p class="task-owner">Mara + Ivo · Supply room · Verify labeled shelves</p>
</div>
<div class="task" id="taskB">
<div class="task-top">
<div class="task-title"><span class="task-letter">B</span> Wayfinding handoff</div>
<span class="task-status" id="taskBStatus">Queued</span>
</div>
<p class="task-owner">Nia + Sol · East courtyard · Confirm information point</p>
</div>
</div>
<div class="controls">
<button id="pauseButton" class="primary" type="button">Pause drill</button>
<button id="restartButton" type="button">Restart</button>
<button id="resetCameraButton" type="button">Reset camera</button>
<button id="focusButton" type="button">Focus team</button>
</div>
<div class="status-line" id="statusLine" aria-live="polite">
<strong>Primary route active.</strong> The team is moving toward Task A.
</div>
</aside>
<div class="scene-help">
<span>Drag to orbit · Shift/right-drag to pan · Scroll to zoom</span>
<button id="helpReset" type="button">Reset view</button>
</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";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd9dc);
scene.fog = new THREE.Fog(0xcbd9dc, 48, 82);
const camera = new THREE.OrthographicCamera(-18, 18, 18, -18, 0.1, 120);
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
theta: 0.72,
phi: 0.94,
radius: 38
};
const hemisphere = new THREE.HemisphereLight(0xeafaff, 0x78908d, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d8, 3.2);
sun.position.set(-15, 30, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ad9ff, 0.9);
fill.position.set(20, 14, -22);
scene.add(fill);
// -------------------------------------------------------------------------
// Grid and wall-safe pathfinding
// -------------------------------------------------------------------------
const COLS = 24;
const ROWS = 18;
const CELL = 1.25;
const gridKey = (x, z) => `${x},${z}`;
const blocked = new Set();
function gridToWorld(x, z, y = 0) {
return new THREE.Vector3(
(x - (COLS - 1) / 2) * CELL,
y,
(z - (ROWS - 1) / 2) * CELL
);
}
function addWall(x, z) {
blocked.add(gridKey(x, z));
}
// Outer walls.
for (let x = 0; x < COLS; x++) {
addWall(x, 0);
addWall(x, ROWS - 1);
}
for (let z = 0; z < ROWS; z++) {
addWall(0, z);
addWall(COLS - 1, z);
}
// Interior architecture, including deliberate door gaps for the routes.
for (let z = 4; z <= 8; z++) addWall(8, z);
for (let x = 9; x <= 14; x++) addWall(x, 3);
for (let x = 9; x <= 10; x++) addWall(x, 9);
for (let x = 13; x <= 14; x++) addWall(x, 9);
for (let z = 4; z <= 5; z++) addWall(15, z);
for (let z = 7; z <= 8; z++) addWall(15, z);
for (let z = 4; z <= 5; z++) addWall(18, z);
for (let z = 7; z <= 9; z++) addWall(18, z);
for (let x = 17; x <= 21; x++) addWall(x, 12);
// Props are also registered as blocked cells.
const treeCells = [
[2, 5], [5, 5], [3, 3], [20, 7], [21, 13]
];
const crateCells = [
[18, 11], [19, 11], [21, 8], [5, 8]
];
const cabinetCells = [
[12, 5], [13, 5]
];
const kioskCells = [
[19, 4]
];
for (const cell of [...treeCells, ...crateCells, ...cabinetCells, ...kioskCells]) {
blocked.add(gridKey(cell[0], cell[1]));
}
const START = [3, 14];
const TASK_A = [12, 6];
const TASK_B = [18, 3];
const primaryWaypoints = [
START,
[3, 11],
[6, 11],
[10, 11],
[12, 11],
[12, 9],
TASK_A
];
const alternateWaypoints = [
TASK_A,
[14, 6],
[16, 6],
[18, 6],
[20, 6],
[20, 3],
TASK_B
];
function manhattan(a, b) {
return Math.abs(a.x - b.x) + Math.abs(a.z - b.z);
}
function aStar(startCell, endCell) {
const start = { x: startCell[0], z: startCell[1] };
const end = { x: endCell[0], z: endCell[1] };
if (blocked.has(gridKey(start.x, start.z)) ||
blocked.has(gridKey(end.x, end.z))) {
throw new Error("A route endpoint is blocked.");
}
const open = [{
x: start.x,
z: start.z,
g: 0,
f: manhattan(start, end)
}];
const cameFrom = new Map();
const gScore = new Map([[gridKey(start.x, start.z), 0]]);
while (open.length) {
open.sort((a, b) => a.f - b.f);
const current = open.shift();
if (current.x === end.x && current.z === end.z) {
const path = [];
let key = gridKey(current.x, current.z);
while (key) {
const [x, z] = key.split(",").map(Number);
path.push([x, z]);
key = cameFrom.get(key);
}
return path.reverse();
}
const neighbors = [
{ x: current.x + 1, z: current.z },
{ x: current.x, z: current.z + 1 },
{ x: current.x - 1, z: current.z },
{ x: current.x, z: current.z - 1 }
];
for (const neighbor of neighbors) {
if (
neighbor.x < 0 || neighbor.x >= COLS ||
neighbor.z < 0 || neighbor.z >= ROWS ||
blocked.has(gridKey(neighbor.x, neighbor.z))
) {
continue;
}
const tentative = current.g + 1;
const key = gridKey(neighbor.x, neighbor.z);
if (tentative < (gScore.get(key) ?? Infinity)) {
cameFrom.set(key, gridKey(current.x, current.z));
gScore.set(key, tentative);
const h = manhattan(neighbor, end);
open.push({
x: neighbor.x,
z: neighbor.z,
g: tentative,
f: tentative + h
});
}
}
}
throw new Error("No wall-safe route could be found.");
}
function buildRoute(waypoints) {
const route = [];
for (let i = 0; i < waypoints.length - 1; i++) {
const segment = aStar(waypoints[i], waypoints[i + 1]);
if (route.length) route.pop();
route.push(...segment);
}
// Final safety assertion: no route cell may coincide with a wall or prop.
for (const [x, z] of route) {
if (blocked.has(gridKey(x, z))) {
throw new Error("Blocked cell detected in a generated route.");
}
}
return route;
}
const primaryCells = buildRoute(primaryWaypoints);
const alternateCells = buildRoute(alternateWaypoints);
const fullCells = [
...primaryCells,
...alternateCells.slice(1)
];
function createRouteData(cells) {
const points = cells.map(([x, z]) => gridToWorld(x, z));
const cumulative = [0];
for (let i = 1; i < points.length; i++) {
cumulative.push(
cumulative[i - 1] + points[i].distanceTo(points[i - 1])
);
}
return {
cells,
points,
cumulative,
length: cumulative[cumulative.length - 1]
};
}
const primaryRoute = createRouteData(primaryCells);
const alternateRoute = createRouteData(alternateCells);
const fullRoute = createRouteData(fullCells);
function sampleRoute(route, distance) {
const d = THREE.MathUtils.clamp(distance, 0, route.length);
let low = 0;
let high = route.cumulative.length - 1;
while (low < high - 1) {
const middle = Math.floor((low + high) / 2);
if (route.cumulative[middle] <= d) low = middle;
else high = middle;
}
const a = route.points[low];
const b = route.points[high];
const segmentLength = route.cumulative[high] - route.cumulative[low];
const alpha = segmentLength > 0
? (d - route.cumulative[low]) / segmentLength
: 0;
return {
position: a.clone().lerp(b, alpha),
tangent: b.clone().sub(a).normalize()
};
}
// -------------------------------------------------------------------------
// Voxel environment
// -------------------------------------------------------------------------
const dummy = new THREE.Object3D();
function createFloor() {
const geometry = new THREE.BoxGeometry(CELL * 0.94, 0.09, CELL * 0.94);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
});
const count = COLS * ROWS;
const floor = new THREE.InstancedMesh(geometry, material, count);
floor.receiveShadow = true;
let index = 0;
const color = new THREE.Color();
for (let z = 0; z < ROWS; z++) {
for (let x = 0; x < COLS; x++) {
const p = gridToWorld(x, z, -0.08);
dummy.position.copy(p);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
floor.setMatrixAt(index, dummy.matrix);
if (x >= 9 && x <= 14 && z >= 3 && z <= 8) {
color.set(0xd8cbb5);
} else if (x >= 16 && x <= 22 && z >= 3 && z <= 10) {
color.set(0xbfdcd3);
} else if (z >= 12 && x >= 8 && x <= 14) {
color.set(0xc7d5de);
} else {
color.set(0xd3ddd5);
}
color.offsetHSL(0, 0, ((x + z) % 3 - 1) * 0.012);
floor.setColorAt(index, color);
index++;
}
}
floor.instanceMatrix.needsUpdate = true;
floor.instanceColor.needsUpdate = true;
scene.add(floor);
}
function createWalls() {
const wallCells = [...blocked].filter((key) => {
const [x, z] = key.split(",").map(Number);
const isProp =
treeCells.some(c => c[0] === x && c[1] === z) ||
crateCells.some(c => c[0] === x && c[1] === z) ||
cabinetCells.some(c => c[0] === x && c[1] === z) ||
kioskCells.some(c => c[0] === x && c[1] === z);
return !isProp;
});
const bodyGeometry = new THREE.BoxGeometry(CELL * 0.94, 1.45, CELL * 0.94);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x78909a,
roughness: 0.82
});
const capGeometry = new THREE.BoxGeometry(CELL * 0.98, 0.12, CELL * 0.98);
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xaab9be,
roughness: 0.8
});
const body = new THREE.InstancedMesh(
bodyGeometry,
bodyMaterial,
wallCells.length
);
const cap = new THREE.InstancedMesh(
capGeometry,
capMaterial,
wallCells.length
);
body.castShadow = true;
body.receiveShadow = true;
cap.castShadow = true;
cap.receiveShadow = true;
wallCells.forEach((key, i) => {
const [x, z] = key.split(",").map(Number);
const p = gridToWorld(x, z);
dummy.position.set(p.x, 0.69, p.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
body.setMatrixAt(i, dummy.matrix);
dummy.position.set(p.x, 1.47, p.z);
dummy.updateMatrix();
cap.setMatrixAt(i, dummy.matrix);
});
body.instanceMatrix.needsUpdate = true;
cap.instanceMatrix.needsUpdate = true;
scene.add(body, cap);
}
function addBox(parent, size, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createProps() {
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x76533d,
roughness: 1
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x548c63,
roughness: 0.95
});
const leafLightMaterial = new THREE.MeshStandardMaterial({
color: 0x77a96e,
roughness: 0.95
});
const crateMaterial = new THREE.MeshStandardMaterial({
color: 0xb8874f,
roughness: 0.85
});
const crateTopMaterial = new THREE.MeshStandardMaterial({
color: 0xd0a36c,
roughness: 0.85
});
const cabinetMaterial = new THREE.MeshStandardMaterial({
color: 0x6c91a2,
roughness: 0.72
});
const kioskMaterial = new THREE.MeshStandardMaterial({
color: 0x596f83,
roughness: 0.72
});
for (const [x, z] of treeCells) {
const p = gridToWorld(x, z);
const tree = new THREE.Group();
tree.position.copy(p);
addBox(tree, [0.28, 0.8, 0.28], [0, 0.4, 0], trunkMaterial);
addBox(tree, [0.9, 0.75, 0.9], [0, 1.05, 0], leafMaterial);
addBox(tree, [0.65, 0.55, 0.65], [0.15, 1.55, -0.08], leafLightMaterial);
scene.add(tree);
}
for (const [x, z] of crateCells) {
const p = gridToWorld(x, z);
const crate = new THREE.Group();
crate.position.copy(p);
addBox(crate, [0.86, 0.66, 0.86], [0, 0.33, 0], crateMaterial);
addBox(crate, [0.92, 0.1, 0.92], [0, 0.69, 0], crateTopMaterial);
scene.add(crate);
}
for (const [x, z] of cabinetCells) {
const p = gridToWorld(x, z);
const cabinet = new THREE.Group();
cabinet.position.copy(p);
addBox(cabinet, [0.9, 1.18, 0.48], [0, 0.59, 0], cabinetMaterial);
addBox(cabinet, [0.66, 0.05, 0.04], [0, 0.9, 0.25], crateTopMaterial);
scene.add(cabinet);
}
for (const [x, z] of kioskCells) {
const p = gridToWorld(x, z);
const kiosk = new THREE.Group();
kiosk.position.copy(p);
addBox(kiosk, [0.9, 0.35, 0.65], [0, 0.175, 0], kioskMaterial);
addBox(kiosk, [0.12, 1.2, 0.12], [0, 0.95, 0], kioskMaterial);
addBox(kiosk, [0.85, 0.58, 0.14], [0, 1.42, 0], crateTopMaterial);
scene.add(kiosk);
}
}
createFloor();
createWalls();
createProps();
// -------------------------------------------------------------------------
// Route dashes and markers
// -------------------------------------------------------------------------
function makeRouteDashes(route, color) {
const placements = [];
for (let i = 1; i < route.points.length; i++) {
const a = route.points[i - 1];
const b = route.points[i];
const length = a.distanceTo(b);
const steps = Math.max(1, Math.floor(length / 0.36));
for (let s = 0; s < steps; s++) {
const alpha = (s + 0.5) / steps;
placements.push({
position: a.clone().lerp(b, alpha),
angle: Math.atan2(b.x - a.x, b.z - a.z)
});
}
}
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.3, 0.07, 0.12),
material,
placements.length
);
placements.forEach((placement, i) => {
dummy.position.set(
placement.position.x,
0.065,
placement.position.z
);
dummy.rotation.set(0, placement.angle, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.renderOrder = 2;
scene.add(mesh);
return mesh;
}
const primaryDashes = makeRouteDashes(primaryRoute, 0x24cdb8);
const alternateDashes = makeRouteDashes(alternateRoute, 0xffb83e);
alternateDashes.material.opacity = 0.42;
function makeLabel(text, background = "#203b46", foreground = "#f4ffff") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.fillStyle = background;
context.fillRect(0, 0, 512, 128);
context.strokeStyle = "rgba(255,255,255,0.25)";
context.lineWidth = 5;
context.strokeRect(3, 3, 506, 122);
context.fillStyle = foreground;
context.font = "700 32px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(4.8, 1.2, 1);
sprite.renderOrder = 10;
return sprite;
}
function createTaskMarker(cell, text, color) {
const group = new THREE.Group();
group.position.copy(gridToWorld(cell[0], cell[1]));
const markerMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const padMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.8,
depthWrite: false
});
const pad = new THREE.Group();
for (const [x, z, sx, sz] of [
[-0.42, 0, 0.65, 0.12],
[0.42, 0, 0.65, 0.12],
[0, -0.42, 0.12, 0.65],
[0, 0.42, 0.12, 0.65]
]) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(sx, 0.07, sz),
padMaterial
);
bar.position.set(x, 0.075, z);
pad.add(bar);
}
group.add(pad);
const beacon = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.32, 0.32),
markerMaterial
);
beacon.position.y = 2.0;
beacon.castShadow = true;
group.add(beacon);
const label = makeLabel(text);
label.position.y = 2.95;
group.add(label);
group.userData = {
beacon,
beaconMaterial: markerMaterial,
padMaterial,
baseY: 2.0,
phase: Math.random() * Math.PI * 2
};
scene.add(group);
return group;
}
const taskAMarker = createTaskMarker(
TASK_A,
"A · SUPPLY CHECK",
"#41d6c3"
);
const taskBMarker = createTaskMarker(
TASK_B,
"B · WAYFINDING",
"#7eb8ff"
);
const startMarker = createTaskMarker(
START,
"START · STAGING",
"#9eb9c4"
);
startMarker.userData.beacon.scale.setScalar(0.72);
startMarker.children[2].scale.set(3.8, 0.95, 1);
// -------------------------------------------------------------------------
// Voxel responders
// -------------------------------------------------------------------------
const skinMaterials = [
new THREE.MeshStandardMaterial({ color: 0xd8a27f, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0x9b684b, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0xe5bd91, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0x744b38, roughness: 0.9 })
];
const pantsMaterial = new THREE.MeshStandardMaterial({
color: 0x293d4b,
roughness: 0.95
});
const helmetMaterial = new THREE.MeshStandardMaterial({
color: 0xf2b84b,
roughness: 0.72
});
const faceMaterial = new THREE.MeshStandardMaterial({
color: 0x263640,
roughness: 1
});
function createResponder(index) {
const group = new THREE.Group();
const uniformColors = [
0x287b7f, 0x426c9a, 0x705c93, 0x617f4b
];
const uniformMaterial = new THREE.MeshStandardMaterial({
color: uniformColors[index],
roughness: 0.82
});
const vestMaterial = new THREE.MeshStandardMaterial({
color: 0xe6efe9,
roughness: 0.82
});
addBox(group, [0.38, 0.52, 0.29], [0, 0.82, 0], uniformMaterial);
addBox(group, [0.31, 0.14, 0.31], [0, 0.61, 0], vestMaterial);
addBox(group, [0.29, 0.29, 0.28], [0, 1.22, 0], skinMaterials[index]);
addBox(group, [0.35, 0.13, 0.33], [0, 1.42, 0], helmetMaterial);
addBox(group, [0.09, 0.07, 0.015], [0, 1.24, 0.145], faceMaterial);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.26, 1.01, 0);
rightArm.position.set(0.26, 1.01, 0);
addBox(leftArm, [0.13, 0.43, 0.14], [0, -0.2, 0], uniformMaterial);
addBox(rightArm, [0.13, 0.43, 0.14], [0, -0.2, 0], uniformMaterial);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.105, 0.56, 0);
rightLeg.position.set(0.105, 0.56, 0);
addBox(leftLeg, [0.14, 0.44, 0.16], [0, -0.22, 0], pantsMaterial);
addBox(rightLeg, [0.14, 0.44, 0.16], [0, -0.22, 0], pantsMaterial);
group.add(leftArm, rightArm, leftLeg, rightLeg);
group.userData = {
leftArm,
rightArm,
leftLeg,
rightLeg,
phase: index * 0.8
};
scene.add(group);
return group;
}
const responders = Array.from({ length: 4 }, (_, i) => createResponder(i));
// -------------------------------------------------------------------------
// Drill state and UI
// -------------------------------------------------------------------------
const state = {
mode: "primary",
running: true,
distance: 0,
speed: 1.75,
velocity: 0,
transitionTimer: 0,
elapsed: 0
};
const ui = {
progressFill: document.querySelector("#progressFill"),
progressValue: document.querySelector("#progressValue"),
primaryRoute: document.querySelector("#primaryRoute"),
alternateRoute: document.querySelector("#alternateRoute"),
primaryState: document.querySelector("#primaryState"),
alternateState: document.querySelector("#alternateState"),
taskA: document.querySelector("#taskA"),
taskB: document.querySelector("#taskB"),
taskAStatus: document.querySelector("#taskAStatus"),
taskBStatus: document.querySelector("#taskBStatus"),
statusLine: document.querySelector("#statusLine"),
pauseButton: document.querySelector("#pauseButton"),
restartButton: document.querySelector("#restartButton"),
resetCameraButton: document.querySelector("#resetCameraButton"),
focusButton: document.querySelector("#focusButton"),
helpReset: document.querySelector("#helpReset"),
toast: document.querySelector("#toast")
};
let toastTimeout;
function showToast(message) {
clearTimeout(toastTimeout);
ui.toast.textContent = message;
ui.toast.classList.add("show");
toastTimeout = setTimeout(() => {
ui.toast.classList.remove("show");
}, 2800);
}
function updateHUD() {
let progress;
if (state.mode === "primary") {
progress = 0.5 * (state.distance / primaryRoute.length);
} else if (state.mode === "transition") {
progress = 0.5;
} else if (state.mode === "alternate") {
progress = 0.5 + 0.5 * (
(state.distance - primaryRoute.length) /
(fullRoute.length - primaryRoute.length)
);
} else {
progress = 1;
}
progress = THREE.MathUtils.clamp(progress, 0, 1);
ui.progressFill.style.width = `${(progress * 100).toFixed(1)}%`;
ui.progressValue.textContent = `${Math.round(progress * 100)}%`;
const primaryActive = state.mode === "primary";
const primaryDone = ["transition", "alternate", "complete"].includes(state.mode);
const alternateActive = ["transition", "alternate"].includes(state.mode);
const alternateDone = state.mode === "complete";
ui.primaryRoute.classList.toggle("active", primaryActive);
ui.primaryRoute.classList.toggle("done", primaryDone);
ui.alternateRoute.classList.toggle("active", alternateActive);
ui.alternateRoute.classList.toggle("done", alternateDone);
ui.primaryState.textContent = primaryDone ? "Verified" : primaryActive ? "Active" : "Planned";
ui.alternateState.textContent = alternateDone
? "Verified"
: alternateActive
? "Active"
: "Planned";
const taskAComplete = primaryDone;
const taskBActive = alternateActive;
const taskBComplete = alternateDone;
ui.taskA.classList.toggle("complete", taskAComplete);
ui.taskA.classList.toggle("active", !taskAComplete);
ui.taskB.classList.toggle("complete", taskBComplete);
ui.taskB.classList.toggle("active", taskBActive);
ui.taskAStatus.textContent = taskAComplete ? "Verified" : "In progress";
ui.taskBStatus.textContent = taskBComplete
? "Verified"
: taskBActive
? "In progress"
: "Queued";
if (state.mode === "primary") {
ui.statusLine.innerHTML = state.running
? "<strong>Primary route active.</strong> The team is moving toward Task A."
: "<strong>Drill paused.</strong> The team is holding safely on the route.";
} else if (state.mode === "transition") {
ui.statusLine.innerHTML =
"<strong>Task A verified.</strong> Preparing the alternate east-courtyard path.";
} else if (state.mode === "alternate") {
ui.statusLine.innerHTML = state.running
? "<strong>Alternate open path active.</strong> The team is proceeding to Task B."
: "<strong>Drill paused.</strong> The alternate route remains clear and confirmed.";
} else {
ui.statusLine.innerHTML =
"<strong>Drill complete.</strong> Both fictional tasks and both routes were verified.";
}
ui.pauseButton.textContent = state.mode === "complete"
? "Drill complete"
: state.running
? "Pause drill"
: "Resume drill";
ui.pauseButton.disabled = state.mode === "complete";
}
function resetDrill() {
state.mode = "primary";
state.running = true;
state.distance = 0;
state.velocity = 0;
state.transitionTimer = 0;
state.elapsed = 0;
showToast("Predeclared drill route active — Team Echo is moving calmly.");
updateHUD();
}
ui.pauseButton.addEventListener("click", () => {
if (state.mode === "complete") return;
state.running = !state.running;
updateHUD();
});
ui.restartButton.addEventListener("click", resetDrill);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset, keyboard
// -------------------------------------------------------------------------
function updateCamera() {
const { target, theta, phi, radius } = cameraState;
const horizontal = Math.sin(phi) * radius;
camera.position.set(
target.x + horizontal * Math.sin(theta),
target.y + Math.cos(phi) * radius,
target.z + horizontal * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.target.set(0, 0, 0);
cameraState.theta = 0.72;
cameraState.phi = 0.94;
camera.zoom = 1;
camera.updateProjectionMatrix();
updateCamera();
}
ui.resetCameraButton.addEventListener("click", resetCamera);
ui.helpReset.addEventListener("click", resetCamera);
ui.focusButton.addEventListener("click", () => {
const focus = sampleRoute(fullRoute, state.distance).position;
cameraState.target.set(focus.x, 0, focus.z);
camera.zoom = 1.55;
camera.updateProjectionMatrix();
updateCamera();
});
let drag = null;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || event.pointerId !== drag.id) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const scale = 0.035 / camera.zoom;
const right = new THREE.Vector3(1, 0, 0)
.applyQuaternion(camera.quaternion);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.cross(camera.up)
.normalize();
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.42,
1.34
);
}
updateCamera();
});
function endDrag(event) {
if (!drag || event.pointerId !== drag.id) return;
drag = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.5
);
camera.updateProjectionMatrix();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
updateCamera();
break;
case "ArrowRight":
cameraState.theta -= 0.08;
updateCamera();
break;
case "ArrowUp":
cameraState.phi = Math.max(0.42, cameraState.phi - 0.06);
updateCamera();
break;
case "ArrowDown":
cameraState.phi = Math.min(1.34, cameraState.phi + 0.06);
updateCamera();
break;
case "+":
case "=":
camera.zoom = Math.min(2.5, camera.zoom * 1.1);
camera.updateProjectionMatrix();
break;
case "-":
camera.zoom = Math.max(0.62, camera.zoom / 1.1);
camera.updateProjectionMatrix();
break;
case "r":
case "R":
resetCamera();
break;
case " ":
event.preventDefault();
if (state.mode !== "complete") {
state.running = !state.running;
updateHUD();
}
break;
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function lerpAngle(a, b, t) {
const difference = Math.atan2(Math.sin(b - a), Math.cos(b - a));
return a + difference * t;
}
function updateResponders(dt) {
const moving =
state.running &&
(state.mode === "primary" || state.mode === "alternate");
const motionAmount = moving ? 1 : 0;
responders.forEach((responder, index) => {
const sample = sampleRoute(
fullRoute,
Math.max(0, state.distance - index * 0.82)
);
responder.position.copy(sample.position);
responder.position.y += 0.03;
const targetYaw = Math.atan2(sample.tangent.x, sample.tangent.z);
responder.rotation.y = lerpAngle(
responder.rotation.y,
targetYaw,
1 - Math.exp(-dt * 10)
);
const stride = moving
? Math.sin(state.distance * 5.2 + responder.userData.phase) * 0.34
: 0;
responder.userData.leftLeg.rotation.x = stride;
responder.userData.rightLeg.rotation.x = -stride;
responder.userData.leftArm.rotation.x = -stride * 0.72;
responder.userData.rightArm.rotation.x = stride * 0.72;
responder.position.y += Math.abs(Math.sin(state.distance * 5.2)) * 0.018 * motionAmount;
});
}
function updateMarkers(elapsed) {
const markers = [taskAMarker, taskBMarker, startMarker];
for (const marker of markers) {
const bob = reducedMotion ? 0.025 : 0.075;
marker.userData.beacon.position.y =
marker.userData.baseY + Math.sin(elapsed * 1.8 + marker.userData.phase) * bob;
marker.userData.beacon.rotation.y += 0.008;
}
if (["transition", "alternate", "complete"].includes(state.mode)) {
taskAMarker.userData.beaconMaterial.color.set(0x7be495);
taskAMarker.userData.padMaterial.color.set(0x7be495);
}
if (state.mode === "complete") {
taskBMarker.userData.beaconMaterial.color.set(0x7be495);
taskBMarker.userData.padMaterial.color.set(0x7be495);
} else if (state.mode === "alternate" || state.mode === "transition") {
taskBMarker.userData.beaconMaterial.color.set(0xffc15a);
taskBMarker.userData.padMaterial.color.set(0xffc15a);
}
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
state.elapsed += dt;
if (state.running) {
if (state.mode === "primary" || state.mode === "alternate") {
const remaining =
state.mode === "primary"
? primaryRoute.length - state.distance
: fullRoute.length - state.distance;
const travel = Math.min(remaining, state.speed * dt);
state.distance += travel;
state.velocity = travel / Math.max(dt, 0.001);
if (
state.mode === "primary" &&
state.distance >= primaryRoute.length - 0.001
) {
state.distance = primaryRoute.length;
state.mode = "transition";
state.transitionTimer = 0;
state.velocity = 0;
showToast("Task A verified — Team Echo is taking the open east path.");
} else if (
state.mode === "alternate" &&
state.distance >= fullRoute.length - 0.001
) {
state.distance = fullRoute.length;
state.mode = "complete";
state.velocity = 0;
showToast("Drill complete — both tasks and both routes were verified.");
}
} else if (state.mode === "transition") {
state.transitionTimer += dt;
state.velocity = 0;
if (state.transitionTimer >= 1.35) {
state.mode = "alternate";
}
}
} else {
state.velocity = 0;
}
primaryDashes.material.opacity =
state.mode === "primary" ? 0.96 : 0.56;
alternateDashes.material.opacity =
state.mode === "alternate"
? 0.98
: state.mode === "transition"
? 0.82
: state.mode === "complete"
? 0.72
: 0.42;
updateResponders(dt);
updateMarkers(state.elapsed);
updateHUD();
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const viewHeight = aspect < 0.85 ? 34 / aspect : 21;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
resetCamera();
updateHUD();
animate();
setTimeout(() => {
showToast("Predeclared drill route active — Team Echo is moving calmly.");
}, 450);
</script>
</body>
</html>
```