Prompt specification
Build or customize the Three.js 3D scene "Blocked-route map update" 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: Blocked-route map update
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/blocked-route-map-update-x0434
Scene Description Prompt:
Build a voxel abstract navigation puzzle: block one building corridor and highlight a new route to another exit. One HTML file, Three.js from cdnjs.
Working Three.js Starter (blocked-route-map-update-x0434):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Closed Corridor — Voxel Navigation Puzzle</title>
<style>
:root {
--bg: #07101d;
--panel: rgba(9, 20, 35, 0.82);
--line: rgba(160, 196, 225, 0.16);
--text: #edf7ff;
--muted: #8ca3b8;
--cyan: #58e5ff;
--lime: #b9ff63;
--red: #ff6378;
--amber: #ffc65a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
outline: none;
touch-action: none;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
margin-bottom: 22px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand-mark {
position: relative;
width: 25px;
height: 25px;
border: 2px solid currentColor;
transform: rotate(45deg);
}
.brand-mark::after {
content: "";
position: absolute;
width: 7px;
height: 7px;
left: 7px;
top: 7px;
background: currentColor;
}
h1 {
max-width: 590px;
margin: 0;
font-size: clamp(34px, 4.5vw, 68px);
font-weight: 620;
line-height: 0.98;
letter-spacing: -0.055em;
text-shadow: 0 4px 30px rgba(0, 0, 0, 0.24);
}
h1 span {
color: var(--muted);
font-weight: 430;
}
.intro-copy {
max-width: 430px;
margin: 18px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.live-badge {
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(7, 16, 29, 0.68);
color: #bfd0df;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(14px);
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
animation: pulse 1.8s ease-in-out infinite;
}
body.blocked .live-dot {
background: var(--lime);
box-shadow: 0 0 14px var(--lime);
}
.control-panel {
position: absolute;
left: 28px;
bottom: 28px;
width: min(390px, calc(100vw - 56px));
padding: 20px;
border: 1px solid var(--line);
border-radius: 18px;
background:
linear-gradient(140deg, rgba(21, 40, 60, 0.82), rgba(7, 17, 30, 0.88));
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 18px;
}
.step {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
body.blocked .step {
color: var(--lime);
}
.state {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.state::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
}
body.blocked .state::before {
background: var(--red);
}
.panel-panel h2 {
margin: 0 0 9px;
font-size: 24px;
font-weight: 620;
letter-spacing: -0.035em;
}
.panel-description {
min-height: 48px;
margin: 0 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 14px;
}
.metric {
padding: 11px 12px;
border: 1px solid rgba(155, 190, 218, 0.12);
border-radius: 10px;
background: rgba(1, 8, 17, 0.24);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: #70869a;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric-value {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
font-weight: 700;
}
.metric-value.cyan {
color: var(--cyan);
}
.metric-value.lime {
color: var(--lime);
}
.button-row {
display: flex;
gap: 8px;
}
.action-button,
.camera-button {
min-height: 46px;
border: 0;
border-radius: 10px;
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease,
border-color 160ms ease;
}
.action-button {
display: flex;
flex: 1;
align-items: center;
justify-content: space-between;
padding: 0 14px 0 16px;
background: var(--cyan);
color: #03131a;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.03em;
}
body.blocked .action-button {
background: var(--lime);
}
.action-button:hover {
transform: translateY(-1px);
filter: brightness(1.08);
}
.button-icon {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border: 1px solid rgba(0, 20, 28, 0.25);
border-radius: 6px;
font-size: 17px;
}
.camera-button {
width: 46px;
border: 1px solid var(--line);
background: rgba(115, 151, 181, 0.08);
color: #b9cada;
font-size: 19px;
}
.camera-button:hover {
border-color: rgba(88, 229, 255, 0.45);
background: rgba(88, 229, 255, 0.09);
}
.legend {
position: absolute;
right: 28px;
bottom: 28px;
width: 226px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(7, 17, 30, 0.68);
backdrop-filter: blur(14px);
}
.legend-title {
margin-bottom: 12px;
color: #6f879c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 9px 0;
color: #a8bac9;
font-size: 11px;
}
.legend-swatch {
width: 17px;
height: 6px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(88, 229, 255, 0.5);
}
.legend-swatch.lime {
background: var(--lime);
box-shadow: 0 0 10px rgba(185, 255, 99, 0.5);
}
.legend-swatch.red {
background: var(--red);
box-shadow: 0 0 10px rgba(255, 99, 120, 0.5);
}
.legend-swatch.amber {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 198, 90, 0.5);
}
.hint {
position: absolute;
right: 28px;
top: 82px;
color: rgba(169, 191, 210, 0.6);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
line-height: 1.8;
text-align: right;
letter-spacing: 0.04em;
}
.map-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(154, 195, 225, 0.2);
border-radius: 6px;
background: rgba(5, 13, 24, 0.78);
color: #c7d7e4;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
transform: translate(-50%, -100%);
transition:
opacity 220ms ease,
color 220ms ease,
border-color 220ms ease;
backdrop-filter: blur(8px);
}
.map-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -12px;
width: 1px;
height: 12px;
background: currentColor;
opacity: 0.55;
}
.map-label .dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.start-label,
.exit-a-label {
color: var(--cyan);
}
.exit-b-label {
color: var(--lime);
opacity: 0.58;
}
.block-label {
color: var(--amber);
}
body.blocked .exit-a-label {
opacity: 0.45;
}
body.blocked .exit-b-label {
opacity: 1;
border-color: rgba(185, 255, 99, 0.35);
}
body.blocked .block-label {
color: var(--red);
border-color: rgba(255, 99, 120, 0.35);
}
@keyframes pulse {
0%,
100% {
opacity: 0.45;
transform: scale(0.85);
}
50% {
opacity: 1;
transform: scale(1.1);
}
}
@media (max-width: 800px) {
.topbar {
top: 18px;
left: 18px;
right: 18px;
}
h1 {
max-width: 440px;
font-size: clamp(31px, 9vw, 52px);
}
.intro-copy {
display: none;
}
.live-badge {
position: absolute;
top: 0;
right: 0;
}
.hint,
.legend {
display: none;
}
.control-panel {
left: 14px;
right: 14px;
bottom: 14px;
width: auto;
padding: 16px;
}
.panel-panel h2 {
font-size: 20px;
}
.panel-description {
min-height: 0;
}
.metrics {
display: none;
}
}
@media (max-height: 650px) {
.intro-copy,
.metrics,
.legend,
.hint {
display: none;
}
.brand {
margin-bottom: 12px;
}
.control-panel {
padding: 14px;
}
.panel-heading {
margin-bottom: 10px;
}
.panel-description {
margin-bottom: 10px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel building navigation puzzle"></main>
<div id="ui">
<header class="topbar">
<div>
<div class="brand">
<span class="brand-mark" aria-hidden="true"></span>
Wayfinding Lab / 07
</div>
<h1>
One corridor.<br />
<span>Two possible exits.</span>
</h1>
<p class="intro-copy">
Block the direct passage and watch the navigation system discover a new
route through the building.
</p>
</div>
<div class="live-badge">
<span class="live-dot"></span>
<span id="liveText">Route active</span>
</div>
</header>
<section class="control-panel" aria-live="polite">
<div class="panel-heading">
<span class="step" id="stepText">Step 01 / 02</span>
<span class="state" id="stateText">Corridor open</span>
</div>
<div class="panel-panel">
<h2 id="panelTitle">Take the direct route</h2>
<p class="panel-description" id="panelDescription">
Exit A is currently reachable. Block the highlighted passage to test
the alternate route.
</p>
<div class="metrics">
<div class="metric">
<span class="metric-label">Direct route</span>
<span class="metric-value cyan">22 m</span>
</div>
<div class="metric">
<span class="metric-label">Alternate route</span>
<span class="metric-value lime" id="alternateMetric">27 m</span>
</div>
</div>
<div class="button-row">
<button class="action-button" id="actionButton" type="button">
<span id="buttonText">Block corridor</span>
<span class="button-icon" aria-hidden="true">×</span>
</button>
<button
class="camera-button"
id="cameraButton"
type="button"
aria-label="Reset camera"
title="Reset camera"
>
↺
</button>
</div>
</div>
</section>
<aside class="legend">
<div class="legend-title">Navigation key</div>
<div class="legend-row">
<span class="legend-swatch"></span>
Active direct route
</div>
<div class="legend-row">
<span class="legend-swatch lime"></span>
Alternate route
</div>
<div class="legend-row">
<span class="legend-swatch red"></span>
Blocked passage
</div>
<div class="legend-row">
<span class="legend-swatch amber"></span>
Selectable corridor
</div>
</aside>
<div class="hint">
DRAG · ORBIT<br />
SHIFT + DRAG · PAN<br />
SCROLL · ZOOM<br />
B · TOGGLE BLOCK
</div>
<div class="map-label start-label" id="startLabel">
<span class="dot"></span>
START
</div>
<div class="map-label exit-a-label" id="exitALabel">
<span class="dot"></span>
EXIT A
</div>
<div class="map-label exit-b-label" id="exitBLabel">
<span class="dot"></span>
EXIT B
</div>
<div class="map-label block-label" id="blockLabel">
<span class="dot"></span>
<span id="blockLabelText">CLICK TO BLOCK</span>
</div>
</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 camera
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#07101d");
scene.fog = new THREE.FogExp2("#07101d", 0.018);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const orbit = {
current: {
theta: 0.42,
phi: 0.67,
radius: 31,
target: new THREE.Vector3(0, 0, -0.4)
},
goal: {
theta: 0.42,
phi: 0.67,
radius: 31,
target: new THREE.Vector3(0, 0, -0.4)
}
};
const defaultCamera = {
theta: 0.42,
phi: 0.67,
radius: 31,
target: new THREE.Vector3(0, 0, -0.4)
};
function updateCamera() {
const { theta, phi, radius, target } = orbit.current;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * Math.sin(theta) * sinPhi,
target.y + radius * Math.cos(phi),
target.z + radius * Math.cos(theta) * sinPhi
);
camera.lookAt(target);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const ambient = new THREE.AmbientLight("#9eb8d1", 0.72);
scene.add(ambient);
const hemisphere = new THREE.HemisphereLight("#c7e7ff", "#142131", 1.4);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#dceeff", 3.1);
sun.position.set(11, 22, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#316b9e", 1.4);
fill.position.set(-15, 10, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
base: new THREE.MeshStandardMaterial({
color: "#16283a",
roughness: 0.82,
metalness: 0.08
}),
wall: [
new THREE.MeshStandardMaterial({
color: "#4a6074",
roughness: 0.88
}),
new THREE.MeshStandardMaterial({
color: "#40576b",
roughness: 0.9
}),
new THREE.MeshStandardMaterial({
color: "#52697c",
roughness: 0.86
})
],
wallCap: new THREE.MeshStandardMaterial({
color: "#688094",
roughness: 0.72
}),
path: new THREE.MeshStandardMaterial({
color: "#19364a",
roughness: 0.95
}),
lowerPath: new THREE.MeshStandardMaterial({
color: "#19352f",
roughness: 0.95
}),
cyan: new THREE.MeshStandardMaterial({
color: "#58e5ff",
emissive: "#1d8fa8",
emissiveIntensity: 1.8,
roughness: 0.35
}),
lime: new THREE.MeshStandardMaterial({
color: "#b9ff63",
emissive: "#559b1d",
emissiveIntensity: 1.8,
roughness: 0.35
}),
red: new THREE.MeshStandardMaterial({
color: "#ff6378",
emissive: "#8d1f32",
emissiveIntensity: 1.2,
roughness: 0.5
}),
amber: new THREE.MeshBasicMaterial({
color: "#ffc65a",
transparent: true,
opacity: 0.9
})
};
// -------------------------------------------------------------------------
// Ground and building base
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(160, 160),
new THREE.MeshStandardMaterial({
color: "#07111e",
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.73;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(100, 100, "#193149", "#102438");
grid.position.y = -0.715;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const buildingBase = new THREE.Mesh(
new THREE.BoxGeometry(26.5, 0.55, 18.5),
materials.base
);
buildingBase.position.y = -0.42;
buildingBase.castShadow = true;
buildingBase.receiveShadow = true;
scene.add(buildingBase);
// Instanced floor tiles.
const tileGeometry = new THREE.BoxGeometry(1.94, 0.14, 1.94);
const floorMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 0.94
});
const floorTiles = new THREE.InstancedMesh(
tileGeometry,
floorMaterial,
13 * 9
);
const floorDummy = new THREE.Object3D();
const floorColor = new THREE.Color();
let floorIndex = 0;
for (let z = -8; z <= 8; z += 2) {
for (let x = -12; x <= 12; x += 2) {
floorDummy.position.set(x, -0.11, z);
floorDummy.updateMatrix();
floorTiles.setMatrixAt(floorIndex, floorDummy.matrix);
const variation = ((x + 20) * 3 + (z + 20) * 5) % 4;
const colors = ["#263b4d", "#223647", "#294052", "#25394a"];
floorColor.set(colors[variation]);
floorTiles.setColorAt(floorIndex, floorColor);
floorIndex++;
}
}
floorTiles.receiveShadow = true;
scene.add(floorTiles);
// Colored floor strips define the two corridor networks.
function addFloorStrip(x, z, width, depth, material) {
const strip = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.045, depth),
material
);
strip.position.set(x, -0.015, z);
strip.receiveShadow = true;
scene.add(strip);
return strip;
}
addFloorStrip(0, 4, 23.5, 2.15, materials.path);
addFloorStrip(0, -1, 23.5, 2.15, materials.lowerPath);
addFloorStrip(-6, 1.5, 2.15, 7.2, materials.path);
addFloorStrip(7, 1.5, 2.15, 7.2, materials.path);
// -------------------------------------------------------------------------
// Voxel wall builder
// -------------------------------------------------------------------------
function addVoxelWall(
axis,
fixed,
start,
end,
height = 1.65,
thickness = 0.34,
cap = true
) {
const length = Math.abs(end - start);
const count = Math.max(1, Math.ceil(length / 1.4));
const segmentLength = length / count;
for (let i = 0; i < count; i++) {
const positionAlong = start + (i + 0.5) * segmentLength;
const geometry =
axis === "x"
? new THREE.BoxGeometry(segmentLength - 0.055, height, thickness)
: new THREE.BoxGeometry(thickness, height, segmentLength - 0.055);
const mesh = new THREE.Mesh(
geometry,
materials.wall[i % materials.wall.length]
);
if (axis === "x") {
mesh.position.set(positionAlong, height / 2 + 0.03, fixed);
} else {
mesh.position.set(fixed, height / 2 + 0.03, positionAlong);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
if (cap) {
const capGeometry =
axis === "x"
? new THREE.BoxGeometry(
segmentLength - 0.075,
0.09,
thickness + 0.07
)
: new THREE.BoxGeometry(
thickness + 0.07,
0.09,
segmentLength - 0.075
);
const capMesh = new THREE.Mesh(capGeometry, materials.wallCap);
if (axis === "x") {
capMesh.position.set(
positionAlong,
height + 0.075,
fixed
);
} else {
capMesh.position.set(
fixed,
height + 0.075,
positionAlong
);
}
capMesh.castShadow = true;
scene.add(capMesh);
}
}
}
// Outer shell. The near wall is lower to keep the cutaway readable.
addVoxelWall("x", 8.45, -12.4, 12.4, 0.95);
addVoxelWall("x", -8.45, -12.4, 12.4, 1.8);
addVoxelWall("z", -12.45, -8.4, 8.4, 1.7);
addVoxelWall("z", 12.45, -8.4, 8.4, 1.7);
// Wall between the direct and alternate corridors, with two door openings.
addVoxelWall("x", 1.5, -12.2, -6.8);
addVoxelWall("x", 1.5, -5.2, 6.2);
addVoxelWall("x", 1.5, 7.8, 12.2);
// Front and back boundaries.
addVoxelWall("x", 6.5, -12.2, 12.2, 1.05);
addVoxelWall("x", -3.55, -12.2, 12.2, 1.55);
// Small room partitions.
for (const x of [-8, -4, 0, 4, 8]) {
addVoxelWall("z", x, 6.72, 8.2, 1.15, 0.28);
addVoxelWall("z", x, -8.2, -3.78, 1.3, 0.28);
}
// Voxel furnishings outside the circulation paths.
const furnitureMaterial = new THREE.MeshStandardMaterial({
color: "#30495d",
roughness: 0.88
});
const furniture = [
[-9.9, 0.45, 7.65, 1.5, 0.9, 1.2],
[-3.3, 0.3, 7.7, 1.0, 0.6, 1.2],
[3.4, 0.4, 7.65, 1.4, 0.8, 1.2],
[9.8, 0.32, 7.7, 1.1, 0.65, 1.2],
[-9.7, 0.35, -6.8, 1.4, 0.7, 1.1],
[-3.3, 0.5, -6.9, 1.6, 1.0, 1.1],
[3.4, 0.3, -6.8, 1.0, 0.6, 1.1],
[9.7, 0.42, -6.8, 1.4, 0.85, 1.1]
];
for (const [x, y, z, sx, sy, sz] of furniture) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
furnitureMaterial
);
block.position.set(x, y, z);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
}
// -------------------------------------------------------------------------
// Portals
// -------------------------------------------------------------------------
const portalBeacons = [];
function createPortal(x, z, color, isStart = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const postMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: isStart ? 1.15 : 1.45,
roughness: 0.35
});
for (const offset of [-0.72, 0.72]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 1.8, 0.34),
postMaterial
);
post.position.set(0, 0.9, offset);
post.castShadow = true;
group.add(post);
}
const lintel = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.34, 1.78),
postMaterial
);
lintel.position.set(0, 1.8, 0);
lintel.castShadow = true;
group.add(lintel);
const floorMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.38
});
const floorMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.8, 0.035, 1.55),
floorMaterial
);
floorMarker.position.y = 0.04;
group.add(floorMarker);
const light = new THREE.PointLight(color, isStart ? 1.5 : 2.1, 5.5, 2);
light.position.set(0, 1.2, 0);
group.add(light);
portalBeacons.push({ light, material: postMaterial, floorMaterial });
scene.add(group);
return group;
}
createPortal(-11.25, 4, "#58e5ff", true);
createPortal(11.25, 4, "#58e5ff");
createPortal(11.25, -1, "#b9ff63");
// -------------------------------------------------------------------------
// Routes
// -------------------------------------------------------------------------
function createRoute(points, color) {
const group = new THREE.Group();
const tileMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.94,
depthWrite: false
});
const glowMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.12,
depthWrite: false
});
const arrowMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.98,
depthWrite: false
});
const tileGeometry = new THREE.BoxGeometry(0.43, 0.08, 0.43);
const glowTileGeometry = new THREE.BoxGeometry(0.74, 0.025, 0.74);
const tiles = [];
for (let segment = 0; segment < points.length - 1; segment++) {
const a = points[segment];
const b = points[segment + 1];
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
direction.normalize();
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const stripGeometry =
Math.abs(direction.x) > Math.abs(direction.z)
? new THREE.BoxGeometry(length, 0.026, 0.78)
: new THREE.BoxGeometry(0.78, 0.026, length);
const strip = new THREE.Mesh(stripGeometry, glowMaterial);
strip.position.set(midpoint.x, 0.045, midpoint.z);
group.add(strip);
const count = Math.max(1, Math.floor(length / 0.48));
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const position = new THREE.Vector3().lerpVectors(a, b, t);
const glow = new THREE.Mesh(glowTileGeometry, glowMaterial);
glow.position.set(position.x, 0.075, position.z);
group.add(glow);
const tile = new THREE.Mesh(tileGeometry, tileMaterial);
tile.position.set(position.x, 0.15, position.z);
tile.userData.baseIndex = tiles.length;
group.add(tile);
tiles.push(tile);
}
let distance = 1.25;
while (distance < length - 0.45) {
const t = distance / length;
const position = new THREE.Vector3().lerpVectors(a, b, t);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.19, 0.46, 3),
arrowMaterial
);
arrow.position.set(position.x, 0.25, position.z);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
group.add(arrow);
distance += 2.35;
}
}
scene.add(group);
return {
group,
tiles,
tileMaterial,
glowMaterial,
arrowMaterial
};
}
const directRoute = createRoute(
[
new THREE.Vector3(-10.8, 0, 4),
new THREE.Vector3(0, 0, 4),
new THREE.Vector3(10.8, 0, 4)
],
"#58e5ff"
);
const alternateRoute = createRoute(
[
new THREE.Vector3(-10.8, 0, 4),
new THREE.Vector3(-6, 0, 4),
new THREE.Vector3(-6, 0, -1),
new THREE.Vector3(10.8, 0, -1)
],
"#b9ff63"
);
alternateRoute.group.visible = false;
// -------------------------------------------------------------------------
// Selectable corridor marker and blocking voxels
// -------------------------------------------------------------------------
const corridorPosition = new THREE.Vector3(-2, 0, 4);
const markerGroup = new THREE.Group();
markerGroup.position.set(corridorPosition.x, 0.12, corridorPosition.z);
const markerCorners = [
[-0.85, -0.85, 1, 1],
[0.85, -0.85, -1, 1],
[-0.85, 0.85, 1, -1],
[0.85, 0.85, -1, -1]
];
for (const [x, z, sx, sz] of markerCorners) {
const horizontal = new THREE.Mesh(
new THREE.BoxGeometry(0.65, 0.045, 0.11),
materials.amber
);
horizontal.position.set(x + sx * 0.19, 0, z);
markerGroup.add(horizontal);
const vertical = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.045, 0.65),
materials.amber
);
vertical.position.set(x, 0, z + sz * 0.19);
markerGroup.add(vertical);
}
const markerHit = new THREE.Mesh(
new THREE.BoxGeometry(2.2, 0.5, 2.2),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
markerHit.position.y = 0.25;
markerGroup.add(markerHit);
scene.add(markerGroup);
const barrierGroup = new THREE.Group();
barrierGroup.position.set(corridorPosition.x, 0, corridorPosition.z);
barrierGroup.visible = false;
const barrierCubes = [
[-0.43, -0.43],
[0.43, -0.43],
[-0.43, 0.43],
[0.43, 0.43]
];
for (const [x, z] of barrierCubes) {
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.82, 1.45, 0.82),
materials.red
);
cube.position.set(x, 0.76, z);
cube.castShadow = true;
cube.receiveShadow = true;
barrierGroup.add(cube);
}
const warningMaterial = new THREE.MeshStandardMaterial({
color: "#ffc65a",
emissive: "#8a4f00",
emissiveIntensity: 1.15,
roughness: 0.5
});
for (const z of [-0.43, 0.43]) {
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(1.74, 0.1, 0.2),
warningMaterial
);
stripe.position.set(0, 1.52, z);
stripe.rotation.y = 0.15;
stripe.castShadow = true;
barrierGroup.add(stripe);
}
const barrierHit = new THREE.Mesh(
new THREE.BoxGeometry(2.1, 2, 2.1),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
barrierHit.position.y = 1;
barrierGroup.add(barrierHit);
scene.add(barrierGroup);
// -------------------------------------------------------------------------
// Decorative exterior voxels
// -------------------------------------------------------------------------
const exteriorMaterial = new THREE.MeshStandardMaterial({
color: "#172d42",
roughness: 0.9
});
const exteriorBlocks = [
[-14.4, 0.35, 5.8, 1.2, 0.7, 1.2],
[-14.4, 0.55, 3.8, 0.8, 1.1, 0.8],
[-14.3, 0.25, -4.2, 1.5, 0.5, 1.5],
[-14.3, 0.8, -6.2, 0.9, 1.6, 0.9],
[14.3, 0.35, 6.7, 1.3, 0.7, 1.3],
[14.4, 0.7, 3.3, 0.9, 1.4, 0.9],
[14.3, 0.3, -5.7, 1.4, 0.6, 1.4],
[14.2, 0.65, -2.8, 0.8, 1.3, 0.8]
];
for (const [x, y, z, sx, sy, sz] of exteriorBlocks) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
exteriorMaterial
);
block.position.set(x, y, z);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
}
// -------------------------------------------------------------------------
// Puzzle state and UI
// -------------------------------------------------------------------------
let blocked = false;
let barrierScale = 1;
const body = document.body;
const actionButton = document.querySelector("#actionButton");
const buttonText = document.querySelector("#buttonText");
const stepText = document.querySelector("#stepText");
const stateText = document.querySelector("#stateText");
const panelTitle = document.querySelector("#panelTitle");
const panelDescription = document.querySelector("#panelDescription");
const liveText = document.querySelector("#liveText");
const blockLabelText = document.querySelector("#blockLabelText");
function applyPuzzleState() {
body.classList.toggle("blocked", blocked);
barrierGroup.visible = blocked;
markerGroup.visible = !blocked;
directRoute.group.visible = true;
alternateRoute.group.visible = blocked;
if (blocked) {
directRoute.tileMaterial.color.set("#3a5266");
directRoute.tileMaterial.opacity = 0.25;
directRoute.glowMaterial.color.set("#3a5266");
directRoute.glowMaterial.opacity = 0.035;
directRoute.arrowMaterial.color.set("#3a5266");
directRoute.arrowMaterial.opacity = 0.25;
stepText.textContent = "Step 02 / 02";
stateText.textContent = "Corridor blocked";
panelTitle.textContent = "A new route is active";
panelDescription.textContent =
"The direct passage is closed. Navigation now uses the west junction and lower corridor to reach Exit B.";
liveText.textContent = "Alternate route active";
buttonText.textContent = "Restore corridor";
blockLabelText.textContent = "PASSAGE BLOCKED";
} else {
directRoute.tileMaterial.color.set("#58e5ff");
directRoute.tileMaterial.opacity = 0.94;
directRoute.glowMaterial.color.set("#58e5ff");
directRoute.glowMaterial.opacity = 0.12;
directRoute.arrowMaterial.color.set("#58e5ff");
directRoute.arrowMaterial.opacity = 0.98;
stepText.textContent = "Step 01 / 02";
stateText.textContent = "Corridor open";
panelTitle.textContent = "Take the direct route";
panelDescription.textContent =
"Exit A is currently reachable. Block the highlighted passage to test the alternate route.";
liveText.textContent = "Route active";
buttonText.textContent = "Block corridor";
blockLabelText.textContent = "CLICK TO BLOCK";
}
}
function toggleBlock() {
blocked = !blocked;
if (blocked) {
barrierScale = 0.05;
barrierGroup.scale.setScalar(barrierScale);
}
applyPuzzleState();
}
actionButton.addEventListener("click", toggleBlock);
// -------------------------------------------------------------------------
// Custom pointer controls and picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let moved = false;
let lastX = 0;
let lastY = 0;
let startX = 0;
let startY = 0;
const rendererCanvas = renderer.domElement;
rendererCanvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
moved = false;
lastX = event.clientX;
lastY = event.clientY;
startX = event.clientX;
startY = event.clientY;
rendererCanvas.setPointerCapture(event.pointerId);
});
rendererCanvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (
Math.abs(event.clientX - startX) +
Math.abs(event.clientY - startY) >
4
) {
moved = true;
}
if (event.shiftKey) {
const scale = orbit.goal.radius * 0.0014;
const right = new THREE.Vector3(
Math.cos(orbit.goal.theta),
0,
-Math.sin(orbit.goal.theta)
);
const forward = new THREE.Vector3(
-Math.sin(orbit.goal.theta),
0,
-Math.cos(orbit.goal.theta)
);
orbit.goal.target.addScaledVector(right, -dx * scale);
orbit.goal.target.addScaledVector(forward, -dy * scale);
orbit.goal.target.x = THREE.MathUtils.clamp(
orbit.goal.target.x,
-9,
9
);
orbit.goal.target.z = THREE.MathUtils.clamp(
orbit.goal.target.z,
-8,
8
);
} else {
orbit.goal.theta -= dx * 0.005;
orbit.goal.phi = THREE.MathUtils.clamp(
orbit.goal.phi - dy * 0.004,
0.28,
1.25
);
}
lastX = event.clientX;
lastY = event.clientY;
});
rendererCanvas.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
if (!moved) {
const rect = rendererCanvas.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);
const target = blocked ? barrierGroup : markerGroup;
const hits = raycaster.intersectObject(target, true);
if (hits.length > 0) {
toggleBlock();
}
}
if (rendererCanvas.hasPointerCapture(event.pointerId)) {
rendererCanvas.releasePointerCapture(event.pointerId);
}
});
rendererCanvas.addEventListener("pointercancel", () => {
dragging = false;
});
rendererCanvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.goal.radius = THREE.MathUtils.clamp(
orbit.goal.radius + event.deltaY * 0.025,
16,
49
);
},
{ passive: false }
);
function resetCamera() {
orbit.goal.theta = defaultCamera.theta;
orbit.goal.phi = defaultCamera.phi;
orbit.goal.radius = defaultCamera.radius;
orbit.goal.target.copy(defaultCamera.target);
}
document.querySelector("#cameraButton").addEventListener("click", resetCamera);
rendererCanvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "b") {
toggleBlock();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Projected map labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#startLabel"),
position: new THREE.Vector3(-11.25, 2.05, 4)
},
{
element: document.querySelector("#exitALabel"),
position: new THREE.Vector3(11.25, 2.05, 4)
},
{
element: document.querySelector("#exitBLabel"),
position: new THREE.Vector3(11.25, 2.05, -1)
},
{
element: document.querySelector("#blockLabel"),
position: new THREE.Vector3(
corridorPosition.x,
blocked ? 2.2 : 1.15,
corridorPosition.z
)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "" : "0";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
orbit.current.theta = THREE.MathUtils.lerp(
orbit.current.theta,
orbit.goal.theta,
0.1
);
orbit.current.phi = THREE.MathUtils.lerp(
orbit.current.phi,
orbit.goal.phi,
0.1
);
orbit.current.radius = THREE.MathUtils.lerp(
orbit.current.radius,
orbit.goal.radius,
0.1
);
orbit.current.target.lerp(orbit.goal.target, 0.1);
updateCamera();
for (let i = 0; i < directRoute.tiles.length; i++) {
const tile = directRoute.tiles[i];
const scale = 1 + Math.sin(elapsed * 4.2 - i * 0.35) * 0.1;
tile.scale.set(scale, 1, scale);
}
for (let i = 0; i < alternateRoute.tiles.length; i++) {
const tile = alternateRoute.tiles[i];
const scale = 1 + Math.sin(elapsed * 4.6 - i * 0.28) * 0.12;
tile.scale.set(scale, 1, scale);
}
const markerPulse = 1 + Math.sin(elapsed * 4.5) * 0.06;
markerGroup.scale.set(markerPulse, 1, markerPulse);
if (blocked) {
barrierScale = THREE.MathUtils.lerp(barrierScale, 1, 0.12);
barrierGroup.scale.setScalar(barrierScale);
}
for (let i = 0; i < portalBeacons.length; i++) {
const beacon = portalBeacons[i];
const pulse = 1.5 + Math.sin(elapsed * 2.8 + i * 1.6) * 0.45;
beacon.light.intensity = pulse;
beacon.material.emissiveIntensity = 1.15 + pulse * 0.18;
beacon.floorMaterial.opacity = 0.29 + Math.sin(elapsed * 2.8 + i) * 0.08;
}
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
applyPuzzleState();
</script>
</body>
</html>
```