Prompt specification
Build or customize the Three.js 3D scene "Museum room exploration diorama" 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: Museum room exploration diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/museum-room-exploration-diorama-x1887
Scene Description Prompt:
Compose rooms connected by doors and a symbolic graph inset; traverse available connections while preserving correspondence between each physical door and graph edge. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (museum-room-exploration-diorama-x1887):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Door Graph</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(8, 20, 34, 0.88);
--border: rgba(148, 184, 215, 0.22);
--text: #e7f2ff;
--muted: #91a9bf;
--cyan: #62e8ff;
}
* { 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;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
#status {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 16px 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0 0 7px;
font-size: 20px;
line-height: 1.2;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.status-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 12px;
}
.chip {
min-height: 27px;
display: inline-flex;
align-items: center;
padding: 4px 9px;
border: 1px solid rgba(148, 184, 215, 0.16);
border-radius: 999px;
background: rgba(255, 255, 255, 0.035);
color: #c8d9e9;
font-size: 11px;
}
.chip strong {
margin-right: 4px;
color: white;
}
#graph-panel {
right: 18px;
bottom: 18px;
width: 318px;
padding: 14px;
user-select: none;
}
.graph-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.graph-header h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.mapping {
color: var(--muted);
font-size: 10px;
}
#graph {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
.graph-edge {
stroke-width: 4;
opacity: 0.34;
transition: opacity 160ms ease, stroke-width 160ms ease;
}
.graph-edge.available {
opacity: 1;
stroke-width: 5;
filter: drop-shadow(0 0 5px currentColor);
}
.graph-edge.route {
opacity: 1;
stroke-width: 7;
filter: drop-shadow(0 0 8px currentColor);
}
.graph-edge.hovered {
opacity: 1;
stroke-width: 8;
}
.edge-hit {
stroke: transparent;
stroke-width: 18;
cursor: pointer;
}
.edge-label-bg {
fill: #0a1726;
stroke: rgba(160, 195, 220, 0.25);
stroke-width: 1;
}
.edge-label {
fill: #eaf5ff;
font-size: 9px;
font-weight: 800;
text-anchor: middle;
pointer-events: none;
}
.edge-group {
cursor: pointer;
}
.node {
cursor: pointer;
}
.node-halo {
fill: transparent;
stroke: transparent;
stroke-width: 3;
}
.node-circle {
fill: #102337;
stroke: #55738d;
stroke-width: 2;
transition: fill 160ms ease, stroke 160ms ease;
}
.node-label {
fill: #edf7ff;
font-size: 12px;
font-weight: 900;
text-anchor: middle;
pointer-events: none;
}
.node.available .node-circle {
fill: #17354b;
stroke: #67dff5;
}
.node.route .node-circle {
fill: #18374a;
stroke: #f7fbff;
stroke-width: 3;
}
.node.current .node-halo {
stroke: #62e8ff;
opacity: 0.9;
}
.node.current .node-circle {
fill: #62e8ff;
stroke: #ffffff;
}
.node.current .node-label {
fill: #06121e;
}
.graph-footer {
display: flex;
justify-content: space-between;
gap: 12px;
padding-top: 8px;
border-top: 1px solid rgba(148, 184, 215, 0.12);
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
#toolbar {
position: fixed;
z-index: 10;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.control-button {
padding: 9px 12px;
border: 1px solid rgba(148, 184, 215, 0.23);
border-radius: 9px;
background: rgba(8, 20, 34, 0.9);
color: #dbeaff;
cursor: pointer;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
}
.control-button:hover {
border-color: rgba(98, 232, 255, 0.65);
color: white;
}
.control-button.active {
border-color: var(--cyan);
color: var(--cyan);
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
top: 18px;
max-width: min(520px, calc(100vw - 36px));
padding: 10px 14px;
border: 1px solid rgba(98, 232, 255, 0.35);
border-radius: 10px;
background: rgba(7, 17, 31, 0.94);
color: #e7f7ff;
font-size: 12px;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -12px);
transition: opacity 180ms ease, transform 180ms ease;
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.32);
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 720px) {
#status {
width: min(330px, calc(100vw - 36px));
padding: 13px 14px;
}
h1 { font-size: 17px; }
#graph-panel {
right: 10px;
bottom: 64px;
width: 260px;
padding: 10px;
}
.graph-footer { display: none; }
#toolbar {
left: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<section id="status" class="panel" aria-live="polite">
<div class="eyebrow">Voxel topology</div>
<h1 id="current-room">Current chamber: A</h1>
<p class="subtitle">
Click a room, graph node, or numbered door. Routes follow connected doorways
one edge at a time.
</p>
<div class="status-row">
<span class="chip"><strong>Doors</strong><span id="door-count">6</span></span>
<span class="chip"><strong>Available</strong><span id="available-edges">D1</span></span>
<span class="chip"><strong>Route</strong><span id="route-label">Idle</span></span>
</div>
</section>
<section id="graph-panel" class="panel">
<div class="graph-header">
<h2>Symbolic graph</h2>
<span class="mapping">D# = physical door</span>
</div>
<svg id="graph" viewBox="0 0 236 220" aria-label="Room connection graph"></svg>
<div class="graph-footer">
<span>Click a node to route there.</span>
<span>Each edge shares its door label and color.</span>
</div>
</section>
<nav id="toolbar" aria-label="Camera controls">
<button id="overview" class="control-button active" type="button">Overview</button>
<button id="follow" class="control-button" type="button">Follow traveler</button>
<button id="reset" class="control-button" type="button">Reset view</button>
</nav>
<div id="toast" role="status"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const graphSvg = document.querySelector("#graph");
const currentRoomEl = document.querySelector("#current-room");
const availableEdgesEl = document.querySelector("#available-edges");
const routeLabelEl = document.querySelector("#route-label");
const toastEl = document.querySelector("#toast");
const ROOM_SPACING = 6.5;
const rooms = {
A: { name: "Atrium", x: -1, z: -1, color: "#62e6b5" },
B: { name: "Foundry", x: 0, z: -1, color: "#60a5fa" },
C: { name: "Junction", x: 0, z: 0, color: "#f472b6" },
D: { name: "Observatory", x: 1, z: 0, color: "#fbbf24" },
E: { name: "Garden", x: 0, z: 1, color: "#a78bfa" },
F: { name: "Archive", x: 1, z: -1, color: "#2dd4bf" }
};
const edges = [
{ id: "D1", a: "A", b: "B", color: "#62e6b5" },
{ id: "D2", a: "B", b: "C", color: "#60a5fa" },
{ id: "D3", a: "C", b: "D", color: "#fbbf24" },
{ id: "D4", a: "C", b: "E", color: "#a78bfa" },
{ id: "D5", a: "B", b: "F", color: "#f472b6" },
{ id: "D6", a: "F", b: "D", color: "#2dd4bf" }
];
const edgeById = new Map(edges.map(edge => [edge.id, edge]));
const roomWorld = {};
const adjacency = Object.fromEntries(Object.keys(rooms).map(id => [id, []]));
for (const [id, room] of Object.entries(rooms)) {
roomWorld[id] = new THREE.Vector3(
room.x * ROOM_SPACING,
0,
room.z * ROOM_SPACING
);
}
for (const edge of edges) {
adjacency[edge.a].push({ room: edge.b, edge: edge.id });
adjacency[edge.b].push({ room: edge.a, edge: edge.id });
const pa = roomWorld[edge.a];
const pb = roomWorld[edge.b];
edge.axis = pa.x !== pb.x ? "x" : "z";
edge.midpoint = pa.clone().add(pb).multiplyScalar(0.5);
}
// ---------- Renderer and camera ----------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 25, 58);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
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.15;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0x9ddcff, 0x101827, 1.75);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d6, 2.4);
sun.position.set(9, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0003;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x58b9ff, 1.15);
rim.position.set(-12, 7, -10);
scene.add(rim);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0x081522,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.31;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(70, 70, 0x1b3a50, 0x10263a);
grid.position.y = -0.295;
grid.material.transparent = true;
grid.material.opacity = 0.33;
scene.add(grid);
const pickMeshes = [];
const roomFloorMaterials = {};
const doorVisuals = new Map();
const effects = [];
// ---------- Helpers ----------
function addBlock(size, position, material, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
if (options.roomId) mesh.userData.roomId = options.roomId;
if (options.edgeId) mesh.userData.edgeId = options.edgeId;
scene.add(mesh);
if (options.pick !== false) pickMeshes.push(mesh);
return mesh;
}
function makeLabel(text, color, background = "#081522", width = 256, height = 96) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = background;
ctx.strokeStyle = color;
ctx.lineWidth = 7;
const x = 5;
const y = 5;
const w = width - 10;
const h = height - 10;
const r = 18;
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = color;
ctx.font = `900 ${Math.floor(height * 0.48)}px ui-sans-serif, system-ui`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 20;
return sprite;
}
function sideBetween(roomA, roomB) {
const dx = rooms[roomB].x - rooms[roomA].x;
const dz = rooms[roomB].z - rooms[roomA].z;
if (dx > 0) return "east";
if (dx < 0) return "west";
if (dz > 0) return "north";
return "south";
}
// ---------- Voxel rooms ----------
const wallMaterials = {
lower: new THREE.MeshStandardMaterial({
color: 0x1b3348,
roughness: 0.94,
metalness: 0.03
}),
upper: new THREE.MeshStandardMaterial({
color: 0x29475c,
roughness: 0.9,
metalness: 0.03
})
};
for (const [roomId, room] of Object.entries(rooms)) {
const center = roomWorld[roomId];
const accent = new THREE.Color(room.color);
const floorMaterial = new THREE.MeshStandardMaterial({
color: accent.clone().lerp(new THREE.Color(0x102234), 0.79),
emissive: accent,
emissiveIntensity: 0.025,
roughness: 0.9,
metalness: 0.03
});
roomFloorMaterials[roomId] = floorMaterial;
for (let x = -2; x <= 2; x++) {
for (let z = -2; z <= 2; z++) {
addBlock(
[0.92, 0.28, 0.92],
[center.x + x, -0.14, center.z + z],
floorMaterial,
{ roomId }
);
}
}
const openings = new Set(
edges
.filter(edge => edge.a === roomId || edge.b === roomId)
.map(edge =>
sideBetween(
edge.a === roomId ? edge.a : edge.b,
edge.a === roomId ? edge.b : edge.a
)
)
);
function addWall(side, t) {
let x = 0;
let z = 0;
if (side === "north") {
x = t;
z = 2.5;
} else if (side === "south") {
x = t;
z = -2.5;
} else if (side === "east") {
x = 2.5;
z = t;
} else {
x = -2.5;
z = t;
}
addBlock(
[0.98, 0.92, 0.98],
[center.x + x, 0.46, center.z + z],
wallMaterials.lower
);
addBlock(
[0.98, 0.92, 0.98],
[center.x + x, 1.38, center.z + z],
wallMaterials.upper
);
}
for (const side of ["north", "south", "east", "west"]) {
for (let t = -2; t <= 2; t++) {
if (openings.has(side) && t === 0) continue;
addWall(side, t);
}
}
// Small voxel furnishings in corners.
const propOffsets = {
A: [-1.35, -1.35],
B: [1.35, 1.35],
C: [-1.35, 1.35],
D: [1.35, -1.35],
E: [-1.35, 1.35],
F: [1.35, 1.35]
};
const [ox, oz] = propOffsets[roomId];
const propMaterial = new THREE.MeshStandardMaterial({
color: accent.clone().lerp(new THREE.Color(0x183047), 0.42),
emissive: accent,
emissiveIntensity: 0.09,
roughness: 0.75
});
addBlock(
[0.58, 0.5, 0.58],
[center.x + ox, 0.25, center.z + oz],
propMaterial
);
addBlock(
[0.36, 0.42, 0.36],
[center.x + ox + 0.08, 0.7, center.z + oz - 0.05],
propMaterial
);
const label = makeLabel(`${roomId} · ${room.name}`, room.color);
label.position.set(center.x, 3.15, center.z);
label.scale.set(2.35, 0.88, 1);
scene.add(label);
}
// ---------- Physical doors ----------
for (const edge of edges) {
const panelMaterial = new THREE.MeshStandardMaterial({
color: edge.color,
emissive: edge.color,
emissiveIntensity: 0.25,
roughness: 0.52,
metalness: 0.12,
transparent: true,
opacity: 0.92
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: edge.color,
emissive: edge.color,
emissiveIntensity: 0.3,
roughness: 0.42,
metalness: 0.18
});
const thresholdMaterial = new THREE.MeshStandardMaterial({
color: edge.color,
emissive: edge.color,
emissiveIntensity: 0.22,
roughness: 0.7
});
const mid = edge.midpoint;
const framePillars = [];
if (edge.axis === "x") {
framePillars.push(
addBlock(
[0.22, 2.05, 0.22],
[mid.x, 1.025, mid.z - 0.57],
frameMaterial,
{ edgeId: edge.id }
),
addBlock(
[0.22, 2.05, 0.22],
[mid.x, 1.025, mid.z + 0.57],
frameMaterial,
{ edgeId: edge.id }
),
addBlock(
[0.22, 0.18, 1.34],
[mid.x, 2.12, mid.z],
frameMaterial,
{ edgeId: edge.id }
),
addBlock(
[0.52, 0.28, 0.92],
[mid.x, -0.14, mid.z],
thresholdMaterial,
{ edgeId: edge.id }
)
);
} else {
framePillars.push(
addBlock(
[0.22, 2.05, 0.22],
[mid.x - 0.57, 1.025, mid.z],
frameMaterial,
{ edgeId: edge.id }
),
addBlock(
[0.22, 2.05, 0.22],
[mid.x + 0.57, 1.025, mid.z],
frameMaterial,
{ edgeId: edge.id }
),
addBlock(
[1.34, 0.18, 0.22],
[mid.x, 2.12, mid.z],
frameMaterial,
{ edgeId: edge.id }
),
addBlock(
[0.92, 0.28, 0.52],
[mid.x, -0.14, mid.z],
thresholdMaterial,
{ edgeId: edge.id }
)
);
}
const hinge = new THREE.Group();
if (edge.axis === "x") {
hinge.position.set(mid.x, 0, mid.z - 0.46);
hinge.rotation.y = -1.12;
} else {
hinge.position.set(mid.x - 0.46, 0, mid.z);
hinge.rotation.y = 1.12;
}
scene.add(hinge);
const panelSize = edge.axis === "x"
? [0.13, 1.72, 0.88]
: [0.88, 1.72, 0.13];
const panelOffset = edge.axis === "x"
? [0, 0.9, 0.44]
: [0.44, 0.9, 0];
const panel = new THREE.Mesh(
new THREE.BoxGeometry(...panelSize),
panelMaterial
);
panel.position.set(...panelOffset);
panel.castShadow = true;
panel.receiveShadow = true;
panel.userData.edgeId = edge.id;
hinge.add(panel);
pickMeshes.push(panel);
const handle = new THREE.Mesh(
new THREE.BoxGeometry(
edge.axis === "x" ? 0.18 : 0.18,
0.18,
edge.axis === "x" ? 0.18 : 0.18
),
new THREE.MeshStandardMaterial({
color: 0xf5fbff,
emissive: 0x9bdfff,
emissiveIntensity: 0.3,
roughness: 0.3
})
);
handle.position.set(
edge.axis === "x" ? 0.09 : 0.76,
0.92,
edge.axis === "x" ? 0.75 : 0.09
);
panel.add(handle);
const label = makeLabel(edge.id, edge.color, "#071522", 192, 80);
label.position.set(mid.x, 2.65, mid.z);
label.scale.set(0.76, 0.34, 1);
scene.add(label);
doorVisuals.set(edge.id, {
panelMaterial,
frameMaterial,
thresholdMaterial,
label,
framePillars
});
}
// ---------- Current-room marker ----------
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x9cf5ff,
transparent: true,
opacity: 0.75,
depthWrite: false
});
const currentMarker = new THREE.Group();
addBlock([4.9, 0.07, 0.10], [0, 0.04, -2.45], markerMaterial, {
pick: false
}).parent = currentMarker;
addBlock([4.9, 0.07, 0.10], [0, 0.04, 2.45], markerMaterial, {
pick: false
}).parent = currentMarker;
addBlock([0.10, 0.07, 4.9], [-2.45, 0.04, 0], markerMaterial, {
pick: false
}).parent = currentMarker;
addBlock([0.10, 0.07, 4.9], [2.45, 0.04, 0], markerMaterial, {
pick: false
}).parent = currentMarker;
scene.add(currentMarker);
// The helper added the blocks directly to the scene; move them into the group.
currentMarker.children.slice().forEach(child => currentMarker.remove(child));
[
[4.9, 0.07, 0.10, 0, 0.04, -2.45],
[4.9, 0.07, 0.10, 0, 0.04, 2.45],
[0.10, 0.07, 4.9, -2.45, 0.04, 0],
[0.10, 0.07, 4.9, 2.45, 0.04, 0]
].forEach(([sx, sy, sz, x, y, z]) => {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
markerMaterial
);
mesh.position.set(x, y, z);
currentMarker.add(mesh);
});
// ---------- Voxel traveler ----------
const player = new THREE.Group();
const playerBody = new THREE.Group();
player.add(playerBody);
scene.add(player);
const suitMaterial = new THREE.MeshStandardMaterial({
color: 0xe7f7ff,
emissive: 0x65dfff,
emissiveIntensity: 0.12,
roughness: 0.58
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x183149,
roughness: 0.75
});
const visorMaterial = new THREE.MeshStandardMaterial({
color: 0x5de7ff,
emissive: 0x32cfff,
emissiveIntensity: 1.2,
roughness: 0.25
});
const torso = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.7, 0.42),
suitMaterial
);
torso.position.y = 0.82;
torso.castShadow = true;
playerBody.add(torso);
const head = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.5, 0.5),
suitMaterial
);
head.position.y = 1.42;
head.castShadow = true;
playerBody.add(head);
const visor = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.12, 0.06),
visorMaterial
);
visor.position.set(0, 1.45, 0.26);
playerBody.add(visor);
const leftLeg = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.48, 0.27),
darkMaterial
);
leftLeg.position.set(-0.17, 0.25, 0);
leftLeg.castShadow = true;
playerBody.add(leftLeg);
const rightLeg = leftLeg.clone();
rightLeg.position.x = 0.17;
playerBody.add(rightLeg);
const leftArm = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.62, 0.22),
suitMaterial
);
leftArm.position.set(-0.43, 0.8, 0);
leftArm.castShadow = true;
playerBody.add(leftArm);
const rightArm = leftArm.clone();
rightArm.position.x = 0.43;
playerBody.add(rightArm);
const playerLight = new THREE.PointLight(0x64e8ff, 0.65, 4.5);
playerLight.position.y = 1.5;
player.add(playerLight);
// ---------- Symbolic graph inset ----------
const graphPositions = {
A: [48, 42],
B: [118, 42],
F: [188, 42],
C: [118, 112],
D: [188, 112],
E: [118, 182]
};
function buildGraph() {
let svg = "";
for (const edge of edges) {
const [x1, y1] = graphPositions[edge.a];
const [x2, y2] = graphPositions[edge.b];
const mx = (x1 + x2) / 2;
const my = (y1 + y2) / 2;
const vertical = x1 === x2;
const labelX = vertical ? mx + 14 : mx;
const labelY = vertical ? my : my - 11;
svg += `
<g class="edge-group" data-edge="${edge.id}">
<line class="edge-hit" x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}"></line>
<line class="graph-edge" x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}"
style="stroke:${edge.color};color:${edge.color}"></line>
<rect class="edge-label-bg" x="${labelX - 12}" y="${labelY - 9}"
width="24" height="18" rx="5"></rect>
<text class="edge-label" x="${labelX}" y="${labelY + 4}">${edge.id}</text>
</g>
`;
}
for (const [roomId, [x, y]] of Object.entries(graphPositions)) {
svg += `
<g class="node" data-room="${roomId}" transform="translate(${x} ${y})">
<circle class="node-halo" r="19"></circle>
<circle class="node-circle" r="14"></circle>
<text class="node-label" y="4">${roomId}</text>
</g>
`;
}
graphSvg.innerHTML = svg;
graphSvg.querySelectorAll(".edge-group").forEach(group => {
group.addEventListener("click", () => {
traverseEdge(group.dataset.edge);
});
});
graphSvg.querySelectorAll(".node").forEach(group => {
group.addEventListener("click", () => {
traverseToRoom(group.dataset.room);
});
});
}
buildGraph();
// ---------- Graph traversal ----------
let currentRoom = "A";
let busy = false;
let hoveredEdge = null;
let destinationRoom = "A";
let activeRoute = new Set();
function findPath(start, target) {
if (start === target) return [];
const queue = [start];
const previous = new Map([[start, null]]);
while (queue.length) {
const room = queue.shift();
for (const connection of adjacency[room]) {
if (previous.has(connection.room)) continue;
previous.set(connection.room, {
room,
edge: connection.edge
});
if (connection.room === target) {
const path = [];
let cursor = target;
while (previous.get(cursor)) {
const step = previous.get(cursor);
path.unshift(step.edge);
cursor = step.room;
}
return path;
}
queue.push(connection.room);
}
}
return [];
}
function setCurrentRoom(roomId) {
currentRoom = roomId;
currentMarker.position.copy(roomWorld[roomId]);
updateVisuals();
}
function routeToEdge(edgeId) {
const edge = edgeById.get(edgeId);
if (edge.a === currentRoom || edge.b === currentRoom) {
return {
path: [edgeId],
destination: edge.a === currentRoom ? edge.b : edge.a
};
}
const pathToA = findPath(currentRoom, edge.a);
const pathToB = findPath(currentRoom, edge.b);
if (pathToA.length <= pathToB.length) {
return {
path: [...pathToA, edgeId],
destination: edge.b
};
}
return {
path: [...pathToB, edgeId],
destination: edge.a
};
}
function traverseToRoom(roomId) {
if (busy) return;
if (roomId === currentRoom) {
showToast(`Already in chamber ${roomId}.`);
return;
}
const path = findPath(currentRoom, roomId);
if (!path.length) {
showToast("No connected route exists.");
return;
}
startTraversal(path, roomId);
}
function traverseEdge(edgeId) {
if (busy) return;
const route = routeToEdge(edgeId);
startTraversal(route.path, route.destination);
}
function startTraversal(path, destination) {
busy = true;
destinationRoom = destination;
activeRoute = new Set(path);
routeLabelEl.textContent = path.join(" → ");
updateVisuals();
const destinationName = rooms[destination].name;
showToast(`Routing to ${destination} · ${destinationName}`);
(async () => {
for (const edgeId of path) {
await traverseOneDoor(edgeId);
}
busy = false;
activeRoute.clear();
routeLabelEl.textContent = "Arrived";
updateVisuals();
showToast(`Arrived at chamber ${currentRoom} · ${rooms[currentRoom].name}.`);
})();
}
async function traverseOneDoor(edgeId) {
const edge = edgeById.get(edgeId);
const nextRoom = edge.a === currentRoom ? edge.b : edge.a;
const start = player.position.clone();
const midpoint = edge.midpoint.clone();
const end = roomWorld[nextRoom].clone();
faceDirection(midpoint.x - start.x, midpoint.z - start.z);
await tweenSegment(start, midpoint);
setCurrentRoom(nextRoom);
pulseDoor(edge.midpoint, edge.color);
faceDirection(end.x - midpoint.x, end.z - midpoint.z);
await tweenSegment(midpoint, end);
}
function faceDirection(dx, dz) {
if (Math.abs(dx) + Math.abs(dz) > 0.001) {
player.rotation.y = Math.atan2(dx, dz);
}
}
let moving = false;
function tweenSegment(from, to) {
const distance = from.distanceTo(to);
const duration = Math.max(430, (distance / 4.1) * 1000);
const startTime = performance.now();
moving = true;
return new Promise(resolve => {
function frame(now) {
const raw = Math.min(1, (now - startTime) / duration);
const t = raw * raw * (3 - 2 * raw);
player.position.lerpVectors(from, to, t);
const stride = Math.sin(raw * Math.PI * 8);
leftLeg.rotation.x = stride * 0.52;
rightLeg.rotation.x = -stride * 0.52;
leftArm.rotation.x = -stride * 0.34;
rightArm.rotation.x = stride * 0.34;
if (raw < 1) {
requestAnimationFrame(frame);
} else {
moving = false;
leftLeg.rotation.x = 0;
rightLeg.rotation.x = 0;
leftArm.rotation.x = 0;
rightArm.rotation.x = 0;
resolve();
}
}
requestAnimationFrame(frame);
});
}
function pulseDoor(position, color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.38, 0.54, 28),
material
);
ring.rotation.x = -Math.PI / 2;
ring.position.copy(position);
ring.position.y = 0.055;
scene.add(ring);
effects.push({
mesh: ring,
born: performance.now()
});
}
// ---------- Visual state synchronization ----------
function updateVisuals() {
const available = new Set(
edges
.filter(edge => edge.a === currentRoom || edge.b === currentRoom)
.map(edge => edge.id)
);
for (const [roomId, material] of Object.entries(roomFloorMaterials)) {
material.emissiveIntensity = roomId === currentRoom
? 0.22
: roomId === destinationRoom && activeRoute.size
? 0.1
: 0.025;
}
for (const edge of edges) {
const visual = doorVisuals.get(edge.id);
const isAvailable = available.has(edge.id);
const isHovered = hoveredEdge === edge.id;
const isRoute = activeRoute.has(edge.id);
visual.panelMaterial.emissiveIntensity = isHovered
? 1.0
: isRoute
? 0.72
: isAvailable
? 0.48
: 0.09;
visual.panelMaterial.opacity = isAvailable || isRoute ? 1 : 0.58;
visual.frameMaterial.emissiveIntensity = isHovered
? 0.9
: isRoute
? 0.7
: isAvailable
? 0.48
: 0.12;
visual.thresholdMaterial.emissiveIntensity = isAvailable ? 0.62 : 0.12;
}
graphSvg.querySelectorAll(".edge-group").forEach(group => {
const id = group.dataset.edge;
group.classList.toggle("available", available.has(id));
group.classList.toggle("route", activeRoute.has(id));
group.classList.toggle("hovered", hoveredEdge === id);
});
graphSvg.querySelectorAll(".node").forEach(group => {
const id = group.dataset.room;
const connected = adjacency[id].some(connection =>
connection.room === currentRoom
);
const routeNode = [...activeRoute].some(edgeId => {
const edge = edgeById.get(edgeId);
return edge.a === id || edge.b === id;
});
group.classList.toggle("current", id === currentRoom);
group.classList.toggle("available", connected);
group.classList.toggle("route", routeNode);
});
currentRoomEl.textContent =
`Current chamber: ${currentRoom} · ${rooms[currentRoom].name}`;
availableEdgesEl.textContent =
available.size ? [...available].sort().join(", ") : "None";
if (!busy && activeRoute.size === 0 && routeLabelEl.textContent === "Arrived") {
// Keep the arrival state until the next route begins.
}
}
let toastTimer;
function showToast(message) {
toastEl.textContent = message;
toastEl.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastEl.classList.remove("visible");
}, 2600);
}
// ---------- Direct camera controls ----------
const cameraState = {
yaw: 0.82,
pitch: 0.72,
radius: 29,
target: new THREE.Vector3(0, 0, 0),
desiredTarget: new THREE.Vector3(0, 0, 0),
desiredRadius: 29,
follow: false
};
const overviewButton = document.querySelector("#overview");
const followButton = document.querySelector("#follow");
const resetButton = document.querySelector("#reset");
function setOverview() {
cameraState.follow = false;
cameraState.desiredTarget.set(0, 0, 0);
cameraState.desiredRadius = 29;
cameraState.yaw = 0.82;
cameraState.pitch = 0.72;
overviewButton.classList.add("active");
followButton.classList.remove("active");
}
function setFollow() {
cameraState.follow = true;
cameraState.desiredRadius = 14.5;
overviewButton.classList.remove("active");
followButton.classList.add("active");
}
overviewButton.addEventListener("click", setOverview);
followButton.addEventListener("click", setFollow);
resetButton.addEventListener("click", setOverview);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let drag = null;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pick(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
return hits.length ? hits[0].object : null;
}
function setHoveredEdge(edgeId) {
if (hoveredEdge === edgeId) return;
hoveredEdge = edgeId;
renderer.domElement.style.cursor = edgeId ? "pointer" : "grab";
updateVisuals();
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
pointerId: event.pointerId,
button: event.button,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (drag && drag.pointerId === event.pointerId) {
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
if (
Math.abs(event.clientX - drag.startX) +
Math.abs(event.clientY - drag.startY) > 5
) {
drag.moved = true;
}
if (drag.button === 0) {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.32,
1.38
);
} else {
cameraState.follow = false;
overviewButton.classList.remove("active");
followButton.classList.remove("active");
const scale = cameraState.desiredRadius * 0.0017;
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.yaw),
0,
-Math.cos(cameraState.yaw)
);
cameraState.desiredTarget.addScaledVector(right, -dx * scale);
cameraState.desiredTarget.addScaledVector(forward, dy * scale);
}
drag.lastX = event.clientX;
drag.lastY = event.clientY;
return;
}
const object = pick(event);
setHoveredEdge(object?.userData.edgeId || null);
});
renderer.domElement.addEventListener("pointerup", event => {
if (!drag || drag.pointerId !== event.pointerId) return;
const wasClick = !drag.moved && drag.button === 0;
drag = null;
renderer.domElement.style.cursor = hoveredEdge ? "pointer" : "grab";
if (!wasClick || busy) return;
const object = pick(event);
if (!object) return;
if (object.userData.edgeId) {
traverseEdge(object.userData.edgeId);
} else if (object.userData.roomId) {
traverseToRoom(object.userData.roomId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
drag = null;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!drag) setHoveredEdge(null);
});
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
8,
44
);
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") cameraState.yaw += 0.12;
if (event.key === "ArrowRight") cameraState.yaw -= 0.12;
if (event.key === "ArrowUp") {
cameraState.pitch = Math.min(1.38, cameraState.pitch + 0.08);
}
if (event.key === "ArrowDown") {
cameraState.pitch = Math.max(0.32, cameraState.pitch - 0.08);
}
if (event.key === "+" || event.key === "=") {
cameraState.desiredRadius = Math.max(8, cameraState.desiredRadius - 1);
}
if (event.key === "-") {
cameraState.desiredRadius = Math.min(44, cameraState.desiredRadius + 1);
}
if (event.key.toLowerCase() === "f") setFollow();
if (event.key.toLowerCase() === "o") setOverview();
});
// ---------- Resize and animation ----------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
setCurrentRoom("A");
player.position.copy(roomWorld.A);
function animate(now) {
requestAnimationFrame(animate);
if (cameraState.follow) {
cameraState.desiredTarget.copy(player.position);
}
cameraState.target.lerp(cameraState.desiredTarget, 0.075);
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * 0.075;
const horizontal = Math.cos(cameraState.pitch) * cameraState.radius;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.radius,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
playerBody.position.y = moving
? Math.abs(Math.sin(now * 0.014)) * 0.075
: Math.sin(now * 0.0025) * 0.018;
markerMaterial.opacity = 0.66 + Math.sin(now * 0.004) * 0.14;
for (let i = effects.length - 1; i >= 0; i--) {
const effect = effects[i];
const age = (now - effect.born) / 720;
if (age >= 1) {
scene.remove(effect.mesh);
effect.mesh.geometry.dispose();
effect.mesh.material.dispose();
effects.splice(i, 1);
continue;
}
const scale = 1 + age * 1.8;
effect.mesh.scale.setScalar(scale);
effect.mesh.material.opacity = 0.9 * (1 - age);
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```