Prompt specification
Build or customize the Three.js 3D scene "Landmark-based school route game" 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: Landmark-based school route game
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/landmark-based-school-route-game-x3864
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a small school layout with consistent room symbols and route choices; users guide a newcomer through several destinations and receive feedback from spatially accurate landmark matches.
Working Three.js Starter (landmark-based-school-route-game-x3864):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Northstar School — Newcomer Orientation</title>
<style>
:root {
--ink: #172c3a;
--muted: #607480;
--paper: rgba(255, 255, 255, 0.94);
--line: rgba(23, 44, 58, 0.12);
--teal: #087f78;
--teal-light: #d9f2ed;
--gold: #e2a93b;
--red: #b64d4d;
--shadow: 0 18px 55px rgba(25, 53, 66, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #c9dfe4;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 14px 10px 10px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 15px;
background: rgba(255,255,255,.86);
box-shadow: 0 8px 30px rgba(30,60,75,.12);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
color: white;
border-radius: 12px;
background: var(--teal);
font-weight: 900;
letter-spacing: -.08em;
}
.brand strong {
display: block;
font-size: 14px;
letter-spacing: .03em;
}
.brand small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.toolbar {
display: flex;
gap: 8px;
pointer-events: auto;
}
.tool {
border: 1px solid rgba(255,255,255,.75);
border-radius: 12px;
padding: 10px 12px;
color: var(--ink);
background: rgba(255,255,255,.88);
box-shadow: 0 8px 30px rgba(30,60,75,.12);
cursor: pointer;
backdrop-filter: blur(12px);
}
.tool:hover { background: white; }
.tool.active { color: white; background: var(--teal); }
.panel {
position: absolute;
top: 88px;
left: 18px;
width: min(360px, calc(100vw - 36px));
max-height: calc(100vh - 116px);
overflow: auto;
padding: 20px;
border: 1px solid rgba(255,255,255,.76);
border-radius: 20px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.eyebrow {
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
}
.progress {
display: flex;
align-items: center;
gap: 7px;
margin: 15px 0 18px;
}
.progress span {
height: 5px;
flex: 1;
border-radius: 999px;
background: #dce5e7;
transition: background .25s;
}
.progress span.done { background: var(--teal); }
.progress span.current { background: var(--gold); }
h1 {
margin: 5px 0 7px;
font-size: clamp(25px, 4vw, 34px);
line-height: 1.04;
letter-spacing: -.045em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.clue {
display: flex;
align-items: center;
gap: 13px;
margin-top: 17px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(246,249,248,.82);
}
#targetIcon {
width: 52px;
height: 52px;
flex: 0 0 auto;
border-radius: 13px;
}
.clue strong {
display: block;
font-size: 13px;
}
.clue span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 12px;
line-height: 1.4;
}
.status {
min-height: 72px;
margin-top: 15px;
padding: 13px 14px;
border-left: 4px solid #9db0b8;
border-radius: 4px 12px 12px 4px;
background: #f0f4f5;
color: #405661;
font-size: 13px;
line-height: 1.48;
}
.status.good {
border-color: var(--teal);
background: var(--teal-light);
color: #185952;
}
.status.warn {
border-color: var(--red);
background: #f8e7e4;
color: #7e3838;
}
.status.info {
border-color: var(--gold);
background: #fbf1d9;
color: #6d5220;
}
.status b { color: inherit; }
.routes {
margin-top: 17px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.routes h2 {
margin: 0 0 4px;
font-size: 14px;
}
.routes > p {
margin: 0 0 11px;
color: var(--muted);
font-size: 12px;
}
.route-list {
display: grid;
gap: 8px;
}
.route-option {
width: 100%;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
background: white;
text-align: left;
cursor: pointer;
transition: .18s ease;
}
.route-option:hover {
border-color: rgba(8,127,120,.45);
transform: translateY(-1px);
}
.route-option.selected {
border-color: var(--teal);
background: var(--teal-light);
box-shadow: inset 0 0 0 1px var(--teal);
}
.route-option strong {
display: block;
font-size: 13px;
}
.route-option small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10.5px;
line-height: 1.4;
}
.primary {
width: 100%;
margin-top: 11px;
padding: 12px 14px;
border: 0;
border-radius: 12px;
color: white;
background: var(--teal);
font-weight: 800;
cursor: pointer;
}
.primary:hover { filter: brightness(.95); }
.primary:disabled { opacity: .42; cursor: not-allowed; }
.legend {
position: absolute;
right: 18px;
bottom: 20px;
width: 250px;
padding: 15px 16px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 16px;
background: rgba(255,255,255,.86);
box-shadow: 0 10px 35px rgba(30,60,75,.12);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.legend h2 {
margin: 0 0 9px;
font-size: 12px;
letter-spacing: .04em;
}
.legend p {
margin: 0 0 10px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.legend-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #40545f;
font-size: 10px;
}
.swatch {
width: 13px;
height: 13px;
flex: 0 0 auto;
border-radius: 4px;
}
.camera-help {
position: absolute;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 9px 13px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 999px;
color: #40545f;
background: rgba(255,255,255,.84);
box-shadow: 0 8px 30px rgba(30,60,75,.1);
font-size: 11px;
white-space: nowrap;
}
.camera-help kbd {
padding: 2px 5px;
border: 1px solid #ccd6d9;
border-radius: 4px;
background: white;
font: inherit;
}
#error {
position: fixed;
inset: 0;
display: none;
place-items: center;
padding: 30px;
color: white;
background: #243a46;
text-align: center;
}
[hidden] { display: none !important; }
@media (max-width: 760px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand small { display: none; }
.brand { padding-right: 10px; }
.brand-mark { width: 36px; height: 36px; }
.tool { padding: 9px 10px; font-size: 12px; }
.panel {
top: auto;
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 47vh;
padding: 16px;
border-radius: 17px;
}
.legend,
.camera-help { display: none; }
h1 { font-size: 25px; }
.progress { margin: 11px 0 13px; }
.clue { margin-top: 12px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="ui">
<header class="topbar">
<div class="brand">
<div class="brand-mark">N</div>
<div>
<strong>NORTHSTAR SCHOOL</strong>
<small>Newcomer wayfinding orientation</small>
</div>
</div>
<div class="toolbar">
<button class="tool" id="followButton" type="button">Follow: Off</button>
<button class="tool" id="resetViewButton" type="button">Reset view</button>
<button class="tool" id="resetButton" type="button">Restart</button>
</div>
</header>
<aside class="panel">
<div class="eyebrow" id="taskNumber">Orientation · 1 of 4</div>
<div class="progress" id="progress"></div>
<h1 id="taskTitle">Find the Library</h1>
<p class="subtitle" id="taskSubtitle"></p>
<div class="clue">
<canvas id="targetIcon" width="96" height="96"></canvas>
<div>
<strong id="symbolName">Open-book symbol</strong>
<span>All room signs use the same format: a colored square, a white symbol, and the room name.</span>
</div>
</div>
<div class="status" id="status" role="status" aria-live="polite"></div>
<section class="routes" id="routeSection" hidden>
<h2>Choose a route</h2>
<p>Each option is physically connected to the corridors. Select one to preview it.</p>
<div class="route-list" id="routeList"></div>
<button class="primary" id="guideButton" type="button" disabled>
Guide the newcomer
</button>
</section>
<button class="primary" id="nextButton" type="button" hidden>
Next destination
</button>
</aside>
<aside class="legend">
<h2>ORIENTATION LANDMARKS</h2>
<p>The destination signs appear above their actual rooms. Match the symbol, not just the wording.</p>
<div class="legend-list">
<div class="legend-item"><i class="swatch" style="background:#5f9b76"></i>Library</div>
<div class="legend-item"><i class="swatch" style="background:#4d98aa"></i>Science</div>
<div class="legend-item"><i class="swatch" style="background:#c77a70"></i>Cafeteria</div>
<div class="legend-item"><i class="swatch" style="background:#648ab7"></i>Music</div>
</div>
</aside>
<div class="camera-help">
<kbd>Drag</kbd> orbit · <kbd>Right-drag</kbd> pan · <kbd>Wheel</kbd> zoom
</div>
</div>
<div id="error">
<div>
<h1>Unable to start the 3D scene</h1>
<p>This demonstration requires a browser with WebGL enabled.</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.getElementById("scene");
const statusEl = document.getElementById("status");
const taskTitleEl = document.getElementById("taskTitle");
const taskSubtitleEl = document.getElementById("taskSubtitle");
const taskNumberEl = document.getElementById("taskNumber");
const symbolNameEl = document.getElementById("symbolName");
const targetIconEl = document.getElementById("targetIcon");
const progressEl = document.getElementById("progress");
const routeSectionEl = document.getElementById("routeSection");
const routeListEl = document.getElementById("routeList");
const guideButtonEl = document.getElementById("guideButton");
const nextButtonEl = document.getElementById("nextButton");
const followButtonEl = document.getElementById("followButton");
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
document.getElementById("error").style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneRoot.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9dfe4);
scene.fog = new THREE.Fog(0xc9dfe4, 65, 115);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
radius: 49,
yaw: 0.58,
pitch: 0.77
};
function updateCamera() {
const { target, radius, yaw, pitch } = cameraState;
camera.position.set(
target.x + radius * Math.cos(pitch) * Math.sin(yaw),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xe9fbff, 0x829078, 2.35);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4d8, 3.15);
sun.position.set(-24, 42, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -40;
sun.shadow.camera.right = 40;
sun.shadow.camera.top = 35;
sun.shadow.camera.bottom = -35;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaed9ff, 0.8);
fill.position.set(25, 16, -20);
scene.add(fill);
const materials = {
ground: new THREE.MeshStandardMaterial({ color: 0xa9c7a4, roughness: 1 }),
slab: new THREE.MeshStandardMaterial({ color: 0xbfc8c4, roughness: 0.92 }),
corridor: new THREE.MeshStandardMaterial({ color: 0xe8dfca, roughness: 0.9 }),
wall: new THREE.MeshStandardMaterial({ color: 0xf6f3e9, roughness: 0.88 }),
wallEdge: new THREE.MeshStandardMaterial({ color: 0x9eb2b4, roughness: 0.82 }),
wood: new THREE.MeshStandardMaterial({ color: 0xb98758, roughness: 0.84 }),
darkWood: new THREE.MeshStandardMaterial({ color: 0x76533c, roughness: 0.9 }),
metal: new THREE.MeshStandardMaterial({ color: 0x60777b, roughness: 0.52, metalness: 0.35 }),
white: new THREE.MeshStandardMaterial({ color: 0xf7f4e9, roughness: 0.8 }),
teal: new THREE.MeshStandardMaterial({ color: 0x167f79, roughness: 0.68 }),
coral: new THREE.MeshStandardMaterial({ color: 0xe27362, roughness: 0.75 }),
yellow: new THREE.MeshStandardMaterial({ color: 0xf1bc46, roughness: 0.75 })
};
function makeBox(w, h, d, x, y, z, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material instanceof THREE.Material ? material :
new THREE.MeshStandardMaterial({ color: material, roughness: 0.85 })
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function makeCylinder(radius, height, x, y, z, material, segments = 10) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material instanceof THREE.Material ? material :
new THREE.MeshStandardMaterial({ color: material, roughness: 0.85 })
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function drawSymbol(ctx, type, cx, cy, size, color = "#ffffff") {
ctx.save();
ctx.translate(cx, cy);
ctx.strokeStyle = color;
ctx.fillStyle = color;
ctx.lineWidth = size * 0.085;
ctx.lineCap = "round";
ctx.lineJoin = "round";
if (type === "book") {
ctx.beginPath();
ctx.moveTo(-size * 0.42, -size * 0.28);
ctx.quadraticCurveTo(-size * 0.2, -size * 0.36, 0, -size * 0.25);
ctx.quadraticCurveTo(size * 0.2, -size * 0.36, size * 0.42, -size * 0.28);
ctx.lineTo(size * 0.42, size * 0.31);
ctx.quadraticCurveTo(size * 0.2, size * 0.19, 0, size * 0.3);
ctx.quadraticCurveTo(-size * 0.2, size * 0.19, -size * 0.42, size * 0.31);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, -size * 0.25);
ctx.lineTo(0, size * 0.3);
ctx.stroke();
} else if (type === "flask") {
ctx.beginPath();
ctx.moveTo(-size * 0.12, -size * 0.4);
ctx.lineTo(-size * 0.12, -size * 0.14);
ctx.lineTo(-size * 0.4, size * 0.36);
ctx.quadraticCurveTo(0, size * 0.48, size * 0.4, size * 0.36);
ctx.lineTo(size * 0.12, -size * 0.14);
ctx.lineTo(size * 0.12, -size * 0.4);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-size * 0.26, -size * 0.4);
ctx.lineTo(size * 0.26, -size * 0.4);
ctx.moveTo(-size * 0.28, size * 0.15);
ctx.lineTo(size * 0.28, size * 0.15);
ctx.stroke();
} else if (type === "fork") {
ctx.beginPath();
ctx.moveTo(-size * 0.27, -size * 0.42);
ctx.lineTo(-size * 0.27, size * 0.04);
ctx.moveTo(-size * 0.09, -size * 0.42);
ctx.lineTo(-size * 0.09, size * 0.04);
ctx.moveTo(-size * 0.18, -size * 0.42);
ctx.lineTo(-size * 0.18, size * 0.18);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-size * 0.18, size * 0.18);
ctx.lineTo(-size * 0.18, size * 0.42);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(size * 0.22, -size * 0.42);
ctx.quadraticCurveTo(size * 0.05, -size * 0.16, size * 0.22, size * 0.02);
ctx.lineTo(size * 0.22, size * 0.42);
ctx.stroke();
} else if (type === "music") {
ctx.beginPath();
ctx.moveTo(-size * 0.08, size * 0.23);
ctx.lineTo(-size * 0.08, -size * 0.37);
ctx.lineTo(size * 0.35, -size * 0.48);
ctx.lineTo(size * 0.35, size * 0.12);
ctx.stroke();
ctx.beginPath();
ctx.ellipse(-size * 0.22, size * 0.27, size * 0.17, size * 0.12, -0.2, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.ellipse(size * 0.21, size * 0.15, size * 0.17, size * 0.12, -0.2, 0, Math.PI * 2);
ctx.fill();
} else if (type === "briefcase") {
roundedRect(ctx, -size * 0.42, -size * 0.25, size * 0.84, size * 0.62, size * 0.08);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-size * 0.17, -size * 0.25);
ctx.lineTo(-size * 0.17, -size * 0.42);
ctx.lineTo(size * 0.17, -size * 0.42);
ctx.lineTo(size * 0.17, -size * 0.25);
ctx.moveTo(-size * 0.42, size * 0.05);
ctx.lineTo(size * 0.42, size * 0.05);
ctx.stroke();
} else if (type === "dumbbell") {
ctx.beginPath();
ctx.moveTo(-size * 0.42, 0);
ctx.lineTo(size * 0.42, 0);
ctx.stroke();
[-0.34, 0.34].forEach(x => {
roundedRect(ctx, x * size - size * 0.1, -size * 0.28, size * 0.2, size * 0.56, size * 0.04);
ctx.fill();
});
[-0.19, 0.19].forEach(x => {
roundedRect(ctx, x * size - size * 0.07, -size * 0.18, size * 0.14, size * 0.36, size * 0.03);
ctx.fill();
});
} else if (type === "board") {
roundedRect(ctx, -size * 0.42, -size * 0.32, size * 0.84, size * 0.58, size * 0.05);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-size * 0.2, 0.05);
ctx.lineTo(size * 0.12, 0.05);
ctx.moveTo(-size * 0.05, -size * 0.1);
ctx.lineTo(size * 0.18, -size * 0.1);
ctx.stroke();
} else if (type === "palette") {
ctx.beginPath();
ctx.ellipse(0, 0, size * 0.43, size * 0.34, -0.18, 0, Math.PI * 2);
ctx.stroke();
[[-0.2, -0.08], [0, -0.14], [0.19, -0.05]].forEach(([x, y]) => {
ctx.beginPath();
ctx.arc(x * size, y * size, size * 0.055, 0, Math.PI * 2);
ctx.fill();
});
ctx.beginPath();
ctx.moveTo(size * 0.28, size * 0.11);
ctx.quadraticCurveTo(size * 0.53, size * 0.32, size * 0.46, size * 0.48);
ctx.stroke();
}
ctx.restore();
}
const rooms = [
{
id: "admin", name: "Admin Office", symbol: "briefcase",
color: 0x6d86a6, css: "#6d86a6", x: -14, z: -8, side: -1,
location: "the northwest block, west of the central atrium"
},
{
id: "library", name: "Library", symbol: "book",
color: 0x5f9b76, css: "#5f9b76", x: -7, z: -8, side: -1,
location: "the north side, immediately west of the central atrium"
},
{
id: "science", name: "Science Lab", symbol: "flask",
color: 0x4d98aa, css: "#4d98aa", x: 7, z: -8, side: -1,
location: "the north side, immediately east of the central atrium"
},
{
id: "gym", name: "Gym", symbol: "dumbbell",
color: 0xc99850, css: "#c99850", x: 14, z: -8, side: -1,
location: "the northeast corner"
},
{
id: "classroom", name: "Classroom", symbol: "board",
color: 0xb99a62, css: "#b99a62", x: -14, z: 8, side: 1,
location: "the southwest block"
},
{
id: "cafeteria", name: "Cafeteria", symbol: "fork",
color: 0xc77a70, css: "#c77a70", x: -7, z: 8, side: 1,
location: "the south side, immediately west of the central atrium"
},
{
id: "art", name: "Art Room", symbol: "palette",
color: 0x9a78ac, css: "#9a78ac", x: 7, z: 8, side: 1,
location: "the south side, immediately east of the central atrium"
},
{
id: "music", name: "Music Room", symbol: "music",
color: 0x648ab7, css: "#648ab7", x: 14, z: 8, side: 1,
location: "the southeast corner"
}
];
const roomById = new Map(rooms.map(room => [room.id, room]));
const tasks = [
{
room: "library",
title: "Find the Library",
subtitle: "Start at the Main Entrance and locate the open-book landmark on the north side.",
symbolName: "Open-book symbol",
symbolLabel: "BOOK"
},
{
room: "science",
title: "Reach Science Lab",
subtitle: "Continue from the Library and find the flask landmark on the opposite side of the atrium.",
symbolName: "Flask symbol",
symbolLabel: "FLASK"
},
{
room: "cafeteria",
title: "Guide to Cafeteria",
subtitle: "Cross the central corridors and locate the fork-and-knife landmark in the south-west section.",
symbolName: "Fork-and-knife symbol",
symbolLabel: "UTENSILS"
},
{
room: "music",
title: "Finish at Music Room",
subtitle: "Find the music-note landmark in the far southeast corner of the school.",
symbolName: "Music-note symbol",
symbolLabel: "NOTE"
}
];
// Ground and building slab.
makeBox(100, 0.3, 90, 0, -0.48, 0, materials.ground, false);
makeBox(40, 0.35, 32, 0, -0.18, 0, materials.slab, false);
// Main corridor and central north-south spine.
makeBox(38, 0.22, 4, 0, 0.03, 0, materials.corridor, false);
makeBox(4, 0.22, 27, 0, 0.04, 5.6, materials.corridor, false);
// Corridor center marks.
for (let x = -17; x <= 17; x += 2.4) {
if (Math.abs(x) > 2) {
makeBox(0.8, 0.025, 0.1, x, 0.17, 0, materials.yellow, false);
}
}
for (let z = 2.2; z < 13; z += 2.2) {
makeBox(0.1, 0.025, 0.8, 0, 0.17, z, materials.yellow, false);
}
const markerSprites = [];
const markerByRoom = new Map();
function createSignTexture(room) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(17, 37, 45, .22)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 8;
roundedRect(ctx, 8, 8, 496, 194, 22);
ctx.fillStyle = "#ffffff";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.lineWidth = 10;
ctx.strokeStyle = room.css;
roundedRect(ctx, 13, 13, 486, 184, 18);
ctx.stroke();
roundedRect(ctx, 30, 38, 144, 144, 18);
ctx.fillStyle = room.css;
ctx.fill();
drawSymbol(ctx, room.symbol, 102, 110, 92, "#ffffff");
ctx.fillStyle = "#172c3a";
ctx.textBaseline = "middle";
ctx.textAlign = "left";
let fontSize = room.name.length > 10 ? 34 : 42;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
while (ctx.measureText(room.name).width > 238 && fontSize > 24) {
fontSize -= 1;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
}
ctx.fillText(room.name, 204, 103);
ctx.fillStyle = "#6a7b84";
ctx.font = "700 19px system-ui, sans-serif";
ctx.fillText("ROOM SYMBOL", 207, 151);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function addFurniture(room) {
const { x, z, side, id } = room;
const floorY = 0.24;
const backZ = z + side * 3.15;
if (id === "admin") {
makeBox(2.4, 0.18, 1.15, x, floorY + 0.68, z - 0.6, materials.wood);
makeBox(0.18, 1.2, 0.18, x - 1.0, floorY + 0.6, z - 0.6, materials.metal);
makeBox(0.18, 1.2, 0.18, x + 1.0, floorY + 0.6, z - 0.6, materials.metal);
makeBox(0.85, 0.5, 0.12, x, floorY + 1.1, z - 0.6, materials.darkWood);
makeBox(0.8, 0.12, 0.75, x, floorY + 0.45, z + 1.1, materials.teal);
} else if (id === "library") {
for (let i = -1; i <= 1; i++) {
makeBox(1.35, 1.5, 0.42, x + i * 1.75, floorY + 0.75, backZ, materials.darkWood);
for (let row = 0; row < 3; row++) {
makeBox(
1.08, 0.25, 0.12,
x + i * 1.75, floorY + 0.3 + row * 0.4, backZ + 0.25,
[0xc7675d, 0xd5a84f, 0x5a8fa2][row]
);
}
}
makeBox(1.8, 0.16, 1.1, x, floorY + 0.75, z + 0.8, materials.wood);
} else if (id === "science") {
for (let i = -1; i <= 1; i++) {
makeBox(1.65, 0.14, 0.9, x + i * 1.65, floorY + 0.82, z - 0.5, materials.white);
makeBox(0.12, 0.75, 0.12, x + i * 1.65 - 0.6, floorY + 0.38, z - 0.5, materials.metal);
makeBox(0.12, 0.75, 0.12, x + i * 1.65 + 0.6, floorY + 0.38, z - 0.5, materials.metal);
makeCylinder(0.16, 0.42, x + i * 1.65, floorY + 1.08, z - 0.5, 0x91d4cf, 8);
}
} else if (id === "gym") {
makeBox(4.7, 0.025, 0.08, x, floorY + 0.03, z, materials.white, false);
makeBox(0.08, 0.025, 4.7, x, floorY + 0.03, z, materials.white, false);
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(0.5, 0.07, 6, 14),
materials.coral
);
hoop.position.set(x, floorY + 2.25, backZ);
hoop.rotation.x = Math.PI / 2;
scene.add(hoop);
} else if (id === "classroom") {
for (let i = -1; i <= 1; i++) {
for (let j = -1; j <= 1; j++) {
const dx = x + i * 1.55;
const dz = z + j * 1.4;
makeBox(0.9, 0.12, 0.58, dx, floorY + 0.72, dz, materials.wood);
makeBox(0.45, 0.45, 0.45, dx, floorY + 0.25, dz + 0.05, materials.teal);
}
}
} else if (id === "cafeteria") {
for (let i = -1; i <= 1; i++) {
const tx = x + i * 1.65;
makeCylinder(0.6, 0.14, tx, floorY + 0.76, z - 0.45, materials.white, 12);
makeCylinder(0.1, 0.75, tx, floorY + 0.37, z - 0.45, materials.metal, 8);
makeCylinder(0.25, 0.42, tx, floorY + 0.21, z + 0.65, materials.coral, 8);
}
} else if (id === "art") {
for (let i = -1; i <= 1; i++) {
const dx = x + i * 1.6;
makeBox(1.1, 0.12, 0.85, dx, floorY + 0.95, z - 0.7, materials.white);
makeBox(0.12, 0.9, 0.12, dx - 0.4, floorY + 0.45, z - 0.7, materials.wood);
makeBox(0.12, 0.9, 0.12, dx + 0.4, floorY + 0.45, z - 0.7, materials.wood);
}
} else if (id === "music") {
makeBox(3.6, 0.45, 2.0, x, floorY + 0.22, z - 0.8, materials.darkWood);
makeBox(0.55, 1.1, 0.5, x - 1.55, floorY + 0.55, z - 0.8, materials.metal);
makeBox(0.55, 1.1, 0.5, x + 1.55, floorY + 0.55, z - 0.8, materials.metal);
makeBox(0.22, 1.6, 0.22, x, floorY + 1.1, z - 0.8, materials.metal);
}
}
for (const room of rooms) {
const width = 6;
const depth = 7.6;
const frontZ = room.z - room.side * 3.8;
const backZ = room.z + room.side * 3.8;
makeBox(
width, 0.2, depth,
room.x, 0.08, room.z,
new THREE.MeshStandardMaterial({ color: room.color, roughness: 0.92 }),
false
);
// Side and rear walls.
makeBox(0.24, 1.75, depth, room.x - width / 2, 1.02, room.z, materials.wall);
makeBox(0.24, 1.75, depth, room.x + width / 2, 1.02, room.z, materials.wall);
makeBox(width, 1.75, 0.24, room.x, 1.02, backZ, materials.wall);
// Front wall with a centered doorway.
const sideWidth = 2.2;
makeBox(sideWidth, 1.75, 0.24, room.x - 1.9, 1.02, frontZ, materials.wall);
makeBox(sideWidth, 1.75, 0.24, room.x + 1.9, 1.02, frontZ, materials.wall);
// Door frame.
makeBox(0.16, 2.45, 0.3, room.x - 0.87, 1.35, frontZ, materials.wallEdge);
makeBox(0.16, 2.45, 0.3, room.x + 0.87, 1.35, frontZ, materials.wallEdge);
makeBox(1.9, 0.18, 0.3, room.x, 2.53, frontZ, materials.wallEdge);
// Door threshold joining the room to the corridor.
makeBox(
1.6, 0.12, 2.25,
room.x, 0.13, room.side * 3.18,
materials.corridor, false
);
addFurniture(room);
const signMaterial = new THREE.SpriteMaterial({
map: createSignTexture(room),
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sign = new THREE.Sprite(signMaterial);
sign.position.set(room.x, 4.35, frontZ);
sign.scale.set(5.25, 2.25, 1);
sign.renderOrder = 20;
sign.userData.roomId = room.id;
scene.add(sign);
markerSprites.push(sign);
markerByRoom.set(room.id, sign);
}
// Entrance gate.
makeBox(0.7, 3.5, 0.7, -2.6, 1.75, 15.0, materials.wall);
makeBox(0.7, 3.5, 0.7, 2.6, 1.75, 15.0, materials.wall);
makeBox(6.0, 0.55, 0.7, 0, 3.25, 15.0, materials.teal);
function createTextSprite(text, color = "#ffffff", background = null) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
if (background) {
roundedRect(ctx, 8, 8, 752, 144, 24);
ctx.fillStyle = background;
ctx.fill();
}
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 58px system-ui, sans-serif";
ctx.fillText(text, 384, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
}));
return sprite;
}
const entranceText = createTextSprite("MAIN ENTRANCE", "#ffffff", "#087f78");
entranceText.position.set(0, 3.25, 15.0);
entranceText.scale.set(5.5, 1.15, 1);
entranceText.renderOrder = 21;
scene.add(entranceText);
const schoolTitle = createTextSprite("NORTHSTAR SCHOOL", "#234655", null);
schoolTitle.position.set(0, 5.7, -15.7);
schoolTitle.scale.set(11, 2.3, 1);
scene.add(schoolTitle);
// Low-poly landscaping.
function addTree(x, z, scale = 1) {
makeCylinder(0.22 * scale, 1.8 * scale, x, 0.45 * scale, z, materials.darkWood, 7);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.25 * scale, 0),
new THREE.MeshStandardMaterial({ color: 0x5f9168, roughness: 1, flatShading: true })
);
crown.position.set(x, 2.15 * scale, z);
crown.castShadow = true;
scene.add(crown);
}
[
[-22, -13], [22, -13], [-22, 12], [22, 12],
[-22, 4], [22, 4], [-10, 20], [10, 20]
].forEach(([x, z], index) => addTree(x, z, 0.85 + (index % 3) * 0.12));
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
const seat = new THREE.Mesh(new THREE.BoxGeometry(2.5, 0.16, 0.58), materials.wood);
seat.position.y = 0.55;
seat.castShadow = true;
group.add(seat);
const back = new THREE.Mesh(new THREE.BoxGeometry(2.5, 0.7, 0.14), materials.wood);
back.position.set(0, 0.88, -0.24);
back.castShadow = true;
group.add(back);
[-0.9, 0.9].forEach(dx => {
const leg = new THREE.Mesh(new THREE.BoxGeometry(0.14, 0.55, 0.42), materials.metal);
leg.position.set(dx, 0.28, 0);
group.add(leg);
});
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
}
addBench(-7.2, 17.2, 0);
addBench(7.2, 17.2, 0);
addBench(-15.5, 16.2, Math.PI / 2);
addBench(15.5, 16.2, Math.PI / 2);
// Ground compass.
const compassGroup = new THREE.Group();
compassGroup.position.set(-15.8, 0.22, 13.3);
const compassDisc = new THREE.Mesh(
new THREE.CylinderGeometry(1.55, 1.55, 0.08, 24),
new THREE.MeshStandardMaterial({ color: 0xf0ead7, roughness: 1 })
);
compassGroup.add(compassDisc);
const northArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.38, 1.4, 3),
materials.coral
);
northArrow.rotation.x = Math.PI / 2;
northArrow.position.z = -0.5;
compassGroup.add(northArrow);
const southArrow = northArrow.clone();
southArrow.rotation.z = Math.PI;
southArrow.position.z = 0.5;
compassGroup.add(southArrow);
scene.add(compassGroup);
// Navigation graph. Coordinates correspond to visible corridors and doorways.
const graphNodes = new Map();
const graphEdges = new Map();
function addNode(id, x, z) {
graphNodes.set(id, { id, x, z });
graphEdges.set(id, []);
}
function connect(a, b) {
graphEdges.get(a).push(b);
graphEdges.get(b).push(a);
}
for (const room of rooms) {
addNode(`room:${room.id}`, room.x, room.z);
addNode(`door:${room.id}`, room.x, room.side * 3.18);
addNode(`hall:${room.id}`, room.x, 0);
connect(`room:${room.id}`, `door:${room.id}`);
connect(`door:${room.id}`, `hall:${room.id}`);
}
addNode("hall:0", 0, 0);
connect("hall:admin", "hall:library");
connect("hall:library", "hall:0");
connect("hall:0", "hall:science");
connect("hall:science", "hall:gym");
addNode("spine:north", 0, -8);
addNode("spine:south", 0, 8);
addNode("entrance", 0, 13.2);
connect("hall:0", "spine:north");
connect("hall:0", "spine:south");
connect("spine:south", "entrance");
function shortestPath(start, target, via = null) {
function run(a, b) {
const distances = new Map();
const previous = new Map();
const unvisited = new Set(graphNodes.keys());
graphNodes.forEach((_, id) => distances.set(id, Infinity));
distances.set(a, 0);
while (unvisited.size) {
let current = null;
let best = Infinity;
for (const id of unvisited) {
if (distances.get(id) < best) {
best = distances.get(id);
current = id;
}
}
if (current === null) break;
if (current === b) break;
unvisited.delete(current);
for (const neighbor of graphEdges.get(current)) {
if (!unvisited.has(neighbor)) continue;
const candidate = best + 1;
if (candidate < distances.get(neighbor)) {
distances.set(neighbor, candidate);
previous.set(neighbor, current);
}
}
}
if (!Number.isFinite(distances.get(b))) return [];
const result = [b];
let cursor = b;
while (cursor !== a) {
cursor = previous.get(cursor);
result.push(cursor);
}
return result.reverse();
}
if (!via) return run(start, target);
const first = run(start, via);
const second = run(via, target);
if (!first.length || !second.length) return [];
return [...first, ...second.slice(1)];
}
function nodeName(id) {
if (id.startsWith("room:")) return roomById.get(id.slice(5)).name;
if (id.startsWith("door:")) return `${roomById.get(id.slice(5)).name} doorway`;
if (id === "hall:admin") return "West junction";
if (id === "hall:library") return "Library junction";
if (id === "hall:0") return "Central junction";
if (id === "hall:science") return "Science junction";
if (id === "hall:gym") return "East junction";
if (id === "spine:north") return "North atrium";
if (id === "spine:south") return "South atrium";
if (id === "entrance") return "Main Entrance";
return id;
}
function pathSummary(path) {
const names = [];
for (const id of path) {
const name = nodeName(id);
if (!names.length || names[names.length - 1] !== name) names.push(name);
}
return names.join(" → ");
}
// Newcomer avatar.
const avatar = new THREE.Group();
const body = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.15, 6),
materials.coral
);
body.position.y = 0.78;
body.castShadow = true;
avatar.add(body);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.3, 0),
new THREE.MeshStandardMaterial({ color: 0xf0c49c, roughness: 0.85, flatShading: true })
);
head.position.y = 1.58;
head.castShadow = true;
avatar.add(head);
const backpack = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.55, 0.22),
materials.teal
);
backpack.position.set(0, 0.94, -0.38);
backpack.castShadow = true;
avatar.add(backpack);
[-0.18, 0.18].forEach(dx => {
makeCylinder(0.09, 0.45, 0, 0, 0, materials.darkWood, 6);
const leg = avatar.children[avatar.children.length - 1];
leg.position.set(dx, 0.25, 0);
});
avatar.position.set(0, 0.2, 12.7);
scene.add(avatar);
const avatarLabel = createTextSprite("NEW ARRIVAL", "#ffffff", "#087f78");
avatarLabel.position.set(0, 2.35, 0);
avatarLabel.scale.set(2.7, 0.56, 1);
avatar.add(avatarLabel);
// Target ring on the floor.
const targetRingMaterial = new THREE.MeshBasicMaterial({
color: 0xf2b93f,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const targetRing = new THREE.Mesh(
new THREE.TorusGeometry(2.15, 0.1, 8, 36),
targetRingMaterial
);
targetRing.rotation.x = Math.PI / 2;
targetRing.position.y = 0.33;
scene.add(targetRing);
const targetGlow = new THREE.Mesh(
new THREE.CylinderGeometry(2.3, 2.3, 0.04, 32),
new THREE.MeshBasicMaterial({
color: 0xffd56c,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
targetGlow.position.y = 0.27;
scene.add(targetGlow);
let routeLine = null;
function clearRouteLine() {
if (!routeLine) return;
scene.remove(routeLine);
routeLine.geometry.dispose();
routeLine.material.dispose();
routeLine = null;
}
function showRoute(path, color = 0x0aa99e) {
clearRouteLine();
const points = path.map(id => {
const node = graphNodes.get(id);
return new THREE.Vector3(node.x, 0.38, node.z);
});
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.55,
gapSize: 0.28,
linewidth: 2,
transparent: true,
opacity: 0.95
});
routeLine = new THREE.Line(geometry, material);
routeLine.computeLineDistances();
routeLine.renderOrder = 5;
scene.add(routeLine);
}
const state = {
taskIndex: 0,
phase: "find",
currentNode: "entrance",
routes: [],
selectedRoute: -1,
walk: null,
follow: false
};
function drawTargetIcon(room) {
const ctx = targetIconEl.getContext("2d");
ctx.clearRect(0, 0, 96, 96);
roundedRect(ctx, 0, 0, 96, 96, 16);
ctx.fillStyle = room.css;
ctx.fill();
drawSymbol(ctx, room.symbol, 48, 48, 58, "#ffffff");
}
function updateProgress() {
progressEl.innerHTML = "";
tasks.forEach((task, index) => {
const bar = document.createElement("span");
if (index < state.taskIndex) bar.className = "done";
if (index === state.taskIndex && state.phase !== "complete") bar.className = "current";
progressEl.appendChild(bar);
});
}
function setStatus(message, type = "") {
statusEl.className = `status ${type}`;
statusEl.innerHTML = message;
}
function currentCoordinates() {
const node = graphNodes.get(state.currentNode);
return node ? { x: node.x, z: node.z } : { x: 0, z: 13 };
}
function directionToTarget(room) {
const current = currentCoordinates();
const dx = room.x - current.x;
const dz = room.z - current.z;
const horizontal = dx > 2 ? "east" : dx < -2 ? "west" : "";
const vertical = dz > 2 ? "south" : dz < -2 ? "north" : "";
if (horizontal && vertical) return `${vertical}-${horizontal}`;
return horizontal || vertical || "at your current position";
}
function setTask(index) {
state.taskIndex = index;
state.phase = "find";
state.routes = [];
state.selectedRoute = -1;
state.walk = null;
const task = tasks[index];
const room = roomById.get(task.room);
markerSprites.forEach(sprite => sprite.material.color.setHex(0xffffff));
markerByRoom.get(room.id).material.color.setHex(0xdfffea);
taskNumberEl.textContent = `Orientation · ${index + 1} of ${tasks.length}`;
taskTitleEl.textContent = task.title;
taskSubtitleEl.textContent = task.subtitle;
symbolNameEl.textContent = task.symbolName;
drawTargetIcon(room);
targetRing.position.set(room.x, 0.33, room.z);
targetGlow.position.set(room.x, 0.27, room.z);
targetRingMaterial.color.setHex(0xf2b93f);
targetGlow.material.color.setHex(0xffd56c);
targetRingMaterial.opacity = 0.9;
targetGlow.material.opacity = 0.13;
routeSectionEl.hidden = true;
nextButtonEl.hidden = true;
guideButtonEl.disabled = true;
clearRouteLine();
setStatus(
`<b>Landmark match required.</b> Click the ${task.symbolName.toLowerCase()} sign in the scene. The highlighted gold ring shows where the destination is located.`,
"info"
);
updateProgress();
}
function buildRouteOptions() {
const targetNode = `room:${state.currentTargetRoom}`;
const direct = shortestPath(state.currentNode, targetNode);
const candidates = [
{ via: "hall:admin", name: "West-loop route" },
{ via: "hall:gym", name: "East-loop route" },
{ via: "spine:north", name: "North-atrium route" },
{ via: "spine:south", name: "South-atrium route" }
];
const alternatives = [];
for (const candidate of candidates) {
const path = shortestPath(state.currentNode, targetNode, candidate.via);
const signature = path.join("|");
if (
path.length &&
!alternatives.some(item => item.signature === signature) &&
signature !== direct.join("|")
) {
alternatives.push({
...candidate,
path,
signature,
summary: pathSummary(path)
});
}
if (alternatives.length === 2) break;
}
return [
{
name: "Direct route",
path: direct,
signature: direct.join("|"),
summary: pathSummary(direct)
},
...alternatives
];
}
function selectRoute(index) {
if (state.phase !== "route") return;
state.selectedRoute = index;
[...routeListEl.children].forEach((button, buttonIndex) => {
button.classList.toggle("selected", buttonIndex === index);
});
showRoute(state.routes[index].path);
guideButtonEl.disabled = false;
setStatus(
`<b>Route previewed.</b> ${state.routes[index].summary}. Press “Guide the newcomer” to follow it.`,
"info"
);
}
function handleRoomClick(roomId) {
if (state.phase !== "find") return;
const task = tasks[state.taskIndex];
const selectedRoom = roomById.get(roomId);
const targetRoom = roomById.get(task.room);
if (roomId !== task.room) {
setStatus(
`<b>Not the right landmark.</b> That is the ${selectedRoom.name}, in ${selectedRoom.location}. ` +
`The ${task.title.replace(/^(Find|Reach|Guide to|Finish at)\s+/, "")} is ${directionToTarget(targetRoom)} from your current position. Match the ${task.symbolName.toLowerCase()}.`,
"warn"
);
return;
}
state.phase = "route";
state.currentTargetRoom = task.room;
state.routes = buildRouteOptions();
routeSectionEl.hidden = false;
routeListEl.innerHTML = "";
state.routes.forEach((route, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = "route-option";
button.innerHTML = `<strong>${route.name}</strong><small>${route.summary}</small>`;
button.addEventListener("click", () => selectRoute(index));
routeListEl.appendChild(button);
});
markerByRoom.get(targetRoom.id).material.color.setHex(0xa9ffcf);
targetRingMaterial.color.setHex(0x20b99d);
targetGlow.material.color.setHex(0x36d5b9);
setStatus(
`<b>Landmark matched.</b> The ${targetRoom.name} is in ${targetRoom.location}. ` +
`Now choose a connected route from the newcomer’s current position.`,
"good"
);
updateProgress();
}
function beginWalking() {
if (state.phase !== "route" || state.selectedRoute < 0) return;
const route = state.routes[state.selectedRoute];
state.phase = "walking";
guideButtonEl.disabled = true;
const points = route.path.map(id => {
const node = graphNodes.get(id);
return new THREE.Vector3(node.x, 0.2, node.z);
});
let length = 0;
for (let i = 1; i < points.length; i++) {
length += points[i].distanceTo(points[i - 1]);
}
state.walk = {
points,
length,
speed: 5.2,
started: performance.now()
};
setStatus(
`<b>Guiding the newcomer…</b> ${route.name}. The dashed line shows the selected physical route through the corridors.`,
"info"
);
}
function finishWalking() {
const targetRoom = roomById.get(tasks[state.taskIndex].room);
state.currentNode = `room:${targetRoom.id}`;
state.phase = "arrived";
state.walk = null;
routeSectionEl.hidden = true;
nextButtonEl.hidden = false;
nextButtonEl.textContent =
state.taskIndex === tasks.length - 1 ? "Restart orientation" : "Next destination";
if (routeLine) routeLine.material.color.setHex(0x2eae76);
setStatus(
`<b>Arrived safely at the ${targetRoom.name}.</b> ` +
`The symbol and physical location matched the requested destination. The route remained inside the marked corridors and doorways.`,
"good"
);
updateProgress();
}
function advanceTask() {
if (state.taskIndex === tasks.length - 1) {
resetOrientation();
return;
}
setTask(state.taskIndex + 1);
}
function resetOrientation() {
state.taskIndex = 0;
state.phase = "find";
state.currentNode = "entrance";
state.routes = [];
state.selectedRoute = -1;
state.walk = null;
avatar.position.set(0, 0.2, 12.7);
avatar.rotation.y = 0;
clearRouteLine();
setTask(0);
}
guideButtonEl.addEventListener("click", beginWalking);
nextButtonEl.addEventListener("click", advanceTask);
document.getElementById("resetButton").addEventListener("click", resetOrientation);
followButtonEl.addEventListener("click", () => {
state.follow = !state.follow;
followButtonEl.classList.toggle("active", state.follow);
followButtonEl.textContent = `Follow: ${state.follow ? "On" : "Off"}`;
});
document.getElementById("resetViewButton").addEventListener("click", () => {
cameraState.target.set(0, 0, 0);
cameraState.radius = 49;
cameraState.yaw = 0.58;
cameraState.pitch = 0.77;
updateCamera();
});
// Click and camera controls are implemented without Three.js addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let drag = null;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY,
button: event.button,
moved: false
};
});
renderer.domElement.addEventListener("pointermove", event => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (
Math.abs(event.clientX - drag.startX) +
Math.abs(event.clientY - drag.startY) > 6
) {
drag.moved = true;
}
if (drag.button === 2 || event.shiftKey) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const scale = cameraState.radius * 0.0015;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -24, 24);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -21, 21);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.34,
1.36
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
if (!drag || drag.id !== event.pointerId) return;
const wasClick = !drag.moved && drag.button === 0;
drag = null;
if (!wasClick) return;
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;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(markerSprites, false);
if (hits.length) {
handleRoomClick(hits[0].object.userData.roomId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
drag = null;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
22,
82
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") cameraState.yaw -= 0.08;
if (event.key === "ArrowRight") cameraState.yaw += 0.08;
if (event.key === "ArrowUp") cameraState.pitch = Math.min(1.36, cameraState.pitch + 0.06);
if (event.key === "ArrowDown") cameraState.pitch = Math.max(0.34, cameraState.pitch - 0.06);
if (event.key === "+" || event.key === "=") cameraState.radius = Math.max(22, cameraState.radius - 3);
if (event.key === "-") cameraState.radius = Math.min(82, cameraState.radius + 3);
if (event.key.toLowerCase() === "r") resetOrientation();
updateCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
function animateWalk(now) {
if (state.phase !== "walking" || !state.walk) return;
const walk = state.walk;
const elapsed = (now - walk.started) / 1000;
const traveled = Math.min(walk.length, elapsed * walk.speed);
let accumulated = 0;
let segment = walk.points.length - 2;
for (let i = 0; i < walk.points.length - 1; i++) {
const distance = walk.points[i].distanceTo(walk.points[i + 1]);
if (accumulated + distance >= traveled) {
segment = i;
break;
}
accumulated += distance;
}
const start = walk.points[segment];
const end = walk.points[segment + 1];
const segmentLength = start.distanceTo(end);
const localT = segmentLength === 0 ? 1 : (traveled - accumulated) / segmentLength;
avatar.position.lerpVectors(start, end, THREE.MathUtils.clamp(localT, 0, 1));
if (segmentLength > 0) {
const direction = end.clone().sub(start);
avatar.rotation.y = Math.atan2(direction.x, direction.z);
}
if (traveled >= walk.length) {
avatar.position.copy(walk.points[walk.points.length - 1]);
finishWalking();
}
}
const clock = new THREE.Clock();
function render(now) {
requestAnimationFrame(render);
const pulse = 1 + Math.sin(now * 0.004) * 0.055;
targetRing.scale.set(pulse, pulse, pulse);
targetGlow.material.opacity = 0.1 + (Math.sin(now * 0.004) + 1) * 0.025;
animateWalk(now);
if (state.follow) {
const desired = avatar.position.clone();
desired.y = 0;
cameraState.target.lerp(desired, 0.035);
updateCamera();
}
const time = clock.getElapsedTime();
avatarLabel.position.y = 2.35 + Math.sin(time * 2.4) * 0.05;
renderer.render(scene, camera);
}
setTask(0);
requestAnimationFrame(render);
</script>
</body>
</html>
```