Prompt specification
Build or customize the Three.js 3D scene "You-are-here map orientation" 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: You-are-here map orientation
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/you-are-here-map-orientation-x0433
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows public-space wayfinding. Display a small floor plan beside its room model, with current position and two exits; align map direction with the viewer's facing direction explicitly. Stylized solid forms.
Working Three.js Starter (you-are-here-map-orientation-x0433):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Civic Commons — Public-Space Wayfinding</title>
<style>
:root {
--paper: #f5f1e8;
--panel: #fbf8f1;
--ink: #17242b;
--muted: #647078;
--line: #d9d5ca;
--accent: #ff6847;
--teal: #18a6a0;
--exit: #218c57;
--navy: #1e3039;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: var(--paper);
}
button {
font: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(300px, 360px) 1fr;
width: 100%;
height: 100%;
}
#sidebar {
position: relative;
z-index: 2;
display: flex;
flex-direction: column;
gap: 18px;
min-height: 0;
padding: 24px 22px;
overflow-y: auto;
background: var(--panel);
border-right: 1px solid var(--line);
box-shadow: 8px 0 30px rgba(29, 42, 46, 0.08);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
display: grid;
width: 42px;
height: 42px;
place-items: center;
color: white;
font-size: 21px;
font-weight: 900;
background: var(--navy);
border-radius: 13px;
}
.eyebrow {
margin: 0 0 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 20px;
line-height: 1.1;
letter-spacing: -0.04em;
}
.map-card {
overflow: hidden;
background: #eef0e9;
border: 1px solid #d8ddd5;
border-radius: 18px;
box-shadow: 0 12px 28px rgba(30, 48, 57, 0.08);
}
.map-heading {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 14px;
color: white;
background: var(--navy);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#headingReadout {
color: #b8f0e7;
font-variant-numeric: tabular-nums;
}
#minimap {
display: block;
width: 100%;
height: auto;
aspect-ratio: 7 / 5;
}
.alignment-note {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 13px;
color: #36545b;
background: #e0f2ec;
border-top: 1px solid #c9e1d9;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.alignment-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
background: var(--teal);
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(24, 166, 160, 0.14);
}
.section-title {
margin: 0 0 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.exit-list {
display: grid;
gap: 9px;
}
.exit-card {
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 11px;
width: 100%;
padding: 11px;
color: var(--ink);
text-align: left;
background: white;
border: 1px solid var(--line);
border-radius: 13px;
cursor: pointer;
transition:
transform 150ms ease,
border-color 150ms ease,
box-shadow 150ms ease;
}
.exit-card:hover {
transform: translateY(-1px);
border-color: #aebbb6;
}
.exit-card.active {
border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(255, 104, 71, 0.12);
}
.exit-code {
display: grid;
width: 38px;
height: 38px;
place-items: center;
color: white;
font-size: 15px;
font-weight: 900;
background: var(--exit);
border-radius: 10px;
}
.exit-card strong,
.exit-card small {
display: block;
}
.exit-card strong {
font-size: 13px;
}
.exit-card small {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.exit-distance {
color: var(--muted);
font-size: 11px;
font-weight: 800;
}
.route-summary {
padding: 14px;
background: #f0eee7;
border: 1px solid var(--line);
border-radius: 14px;
}
.route-summary strong {
display: block;
margin-bottom: 5px;
font-size: 14px;
}
.route-summary span {
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.position-row {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#positionReadout {
color: var(--ink);
font-variant-numeric: tabular-nums;
letter-spacing: 0;
text-transform: none;
}
.sidebar-help {
margin-top: auto;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
kbd {
padding: 2px 5px;
color: var(--ink);
background: white;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 4px;
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e8e5dc;
}
#viewport > canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport > canvas:active {
cursor: grabbing;
}
.scene-title {
position: absolute;
top: 22px;
left: 24px;
pointer-events: none;
}
.scene-title .eyebrow {
color: #536168;
}
.scene-title h2 {
margin: 0;
font-size: clamp(20px, 2.4vw, 34px);
font-weight: 750;
letter-spacing: -0.05em;
}
.scene-title p {
margin: 6px 0 0;
color: #5e696d;
font-size: 12px;
}
.scene-status {
position: absolute;
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
color: var(--ink);
background: rgba(255, 255, 255, 0.88);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
box-shadow: 0 8px 26px rgba(32, 47, 52, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.scene-status .live-dot {
width: 9px;
height: 9px;
background: var(--accent);
border-radius: 50%;
box-shadow: 0 0 0 5px rgba(255, 104, 71, 0.14);
}
.scene-status strong {
font-size: 12px;
}
.scene-status small {
color: var(--muted);
font-size: 10px;
}
.scene-compass {
position: absolute;
right: 24px;
bottom: 24px;
display: grid;
width: 66px;
height: 66px;
place-items: center;
background: rgba(255, 255, 255, 0.82);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 50%;
box-shadow: 0 8px 28px rgba(32, 47, 52, 0.13);
backdrop-filter: blur(10px);
pointer-events: none;
}
.scene-compass::before {
position: absolute;
inset: 8px;
content: "";
border: 1px solid #c8ceca;
border-radius: 50%;
}
#compassNeedle {
position: absolute;
width: 3px;
height: 24px;
transform-origin: 50% 100%;
background: linear-gradient(to top, #879398 50%, var(--accent) 50%);
border-radius: 3px;
}
#compassNeedle::before {
position: absolute;
top: -3px;
left: -4px;
content: "";
border-right: 5px solid transparent;
border-bottom: 9px solid var(--accent);
border-left: 5px solid transparent;
}
.compass-n {
position: absolute;
top: 8px;
left: 50%;
z-index: 2;
padding: 1px 4px;
color: white;
background: var(--navy);
border-radius: 4px;
font-size: 8px;
font-weight: 900;
transform: translateX(-50%);
}
.scene-help {
position: absolute;
bottom: 24px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 7px;
pointer-events: none;
}
.scene-help span {
padding: 7px 9px;
color: #4e5c62;
background: rgba(255, 255, 255, 0.78);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 8px;
box-shadow: 0 5px 18px rgba(32, 47, 52, 0.08);
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(8px);
}
.scale {
position: absolute;
right: 105px;
bottom: 26px;
width: 72px;
color: #4e5c62;
font-size: 9px;
font-weight: 800;
text-align: center;
pointer-events: none;
}
.scale::before {
display: block;
width: 72px;
height: 7px;
content: "";
border-right: 2px solid #536168;
border-bottom: 2px solid #536168;
border-left: 2px solid #536168;
}
@media (max-width: 780px) {
html,
body {
overflow: auto;
}
#app {
grid-template-columns: 1fr;
grid-template-rows: minmax(520px, 62vh) auto;
}
#viewport {
grid-row: 1;
}
#sidebar {
grid-row: 2;
overflow: visible;
border-top: 1px solid var(--line);
border-right: 0;
}
.scene-title {
top: 16px;
left: 16px;
}
.scene-status {
top: 16px;
right: 16px;
}
.scene-help {
bottom: 16px;
left: 16px;
}
.scene-compass {
right: 16px;
bottom: 16px;
}
.scale {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<aside id="sidebar">
<header class="brand">
<div class="brand-mark" aria-hidden="true">↗</div>
<div>
<p class="eyebrow">Civic Commons</p>
<h1>Public-space guide</h1>
</div>
</header>
<section class="map-card" aria-label="Live floor plan">
<div class="map-heading">
<span>Live floor plan</span>
<span id="headingReadout">N 000°</span>
</div>
<canvas
id="minimap"
width="560"
height="400"
aria-label="Rotating floor plan showing current position and two exits"
></canvas>
<div class="alignment-note">
<span class="alignment-dot"></span>
Map rotates with you · your view is always up
</div>
</section>
<section>
<h2 class="section-title">Choose a destination</h2>
<div class="exit-list">
<button class="exit-card" data-exit="b" type="button" aria-pressed="true">
<span class="exit-code">B</span>
<span>
<strong>North exit</strong>
<small>Main lobby · street level</small>
</span>
<span class="exit-distance" id="distanceB">—</span>
</button>
<button class="exit-card" data-exit="a" type="button" aria-pressed="false">
<span class="exit-code">A</span>
<span>
<strong>East exit</strong>
<small>East street · cycle access</small>
</span>
<span class="exit-distance" id="distanceA">—</span>
</button>
</div>
</section>
<section class="route-summary" aria-live="polite">
<strong id="routeTitle">Route to North exit</strong>
<span id="routeDescription">Follow the highlighted route.</span>
</section>
<div class="position-row">
<span>Current position</span>
<span id="positionReadout">X −0.7 · Z 4.8</span>
</div>
<div class="sidebar-help">
<kbd>W</kbd> <kbd>A</kbd> <kbd>S</kbd> <kbd>D</kbd> to walk ·
drag to turn · scroll to zoom · <kbd>1</kbd>/<kbd>2</kbd> select exits.
</div>
</aside>
<main id="viewport" aria-label="Interactive three-dimensional room model">
<div class="scene-title">
<p class="eyebrow">Community hall · Level 01</p>
<h2>Atrium & reception</h2>
<p>Solid-form spatial model with live wayfinding</p>
</div>
<div class="scene-status">
<span class="live-dot"></span>
<strong>Position tracked</strong>
<small>2 exits available</small>
</div>
<div class="scene-help">
<span>Drag to look</span>
<span>WASD to move</span>
<span>Scroll to zoom</span>
</div>
<div class="scale">5 meters</div>
<div class="scene-compass" aria-label="North indicator">
<span class="compass-n">N</span>
<span id="compassNeedle"></span>
</div>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const viewport = document.querySelector("#viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e5dc);
scene.fog = new THREE.Fog(0xe8e5dc, 38, 72);
const camera = new THREE.PerspectiveCamera(
49,
viewport.clientWidth / viewport.clientHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf8fbff, 0xb8a88e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 3.2);
sun.position.set(-8, 18, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9e6, 1.0);
fill.position.set(10, 8, -12);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
const palette = {
floor: 0xd8d0bf,
floorLight: 0xe7e0d3,
wall: 0xf0eadf,
wallEdge: 0xc9c1b4,
navy: 0x243841,
teal: 0x18a6a0,
coral: 0xff6847,
green: 0x218c57,
mustard: 0xe9ae45,
blue: 0x668ca5,
wood: 0xa77750,
foliage: 0x4f8062,
pot: 0xc97d5b,
white: 0xffffff
};
function material(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0.02,
...extra
});
}
function addBox(w, h, d, color, x, y, z, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
world.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
color,
x,
y,
z,
segments = 24,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
world.add(mesh);
return mesh;
}
function addSphere(radius, color, x, y, z, options = {}) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 20, 14),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
world.add(mesh);
return mesh;
}
function addLabel(text, background, foreground = "#ffffff", width = 2.5) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.beginPath();
context.roundRect(8, 8, 496, 144, 30);
context.fill();
context.fillStyle = foreground;
context.font = "800 66px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.3125, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Stylized room model
// Room coordinates: x = east/west, z = north/south.
// -------------------------------------------------------------------------
const ROOM = {
minX: -10,
maxX: 10,
minZ: -7,
maxZ: 7
};
const exits = {
a: {
id: "A",
name: "East exit",
x: 10,
z: 1,
color: palette.green
},
b: {
id: "B",
name: "North exit",
x: -3,
z: -7,
color: palette.green
}
};
// Main floor.
addBox(
20.4,
0.32,
14.4,
palette.floor,
0,
-0.17,
0
);
// Flat colored floor zones.
addBox(7.2, 0.035, 4.5, 0xe4d8bf, -5.6, 0.018, -2.8);
addBox(7.0, 0.035, 4.8, 0xd6e2df, 3.0, 0.019, -3.3);
addBox(4.4, 0.035, 3.2, 0xe6cdb8, -5.6, 0.021, 4.0);
// North wall, split around Exit B.
addBox(5.8, 2.6, 0.28, palette.wall, -7.1, 1.3, -7);
addBox(11.8, 2.6, 0.28, palette.wall, 4.1, 1.3, -7);
// East wall, split around Exit A.
addBox(0.28, 2.6, 6.8, palette.wall, 10, 1.3, -3.6);
addBox(0.28, 2.6, 4.8, palette.wall, 10, 1.3, 4.6);
// West and low front cutaway walls.
addBox(0.28, 2.6, 14, palette.wall, -10, 1.3, 0);
addBox(20, 0.75, 0.28, palette.wallEdge, 0, 0.375, 7);
// Wall caps for a cleaner cutaway-model appearance.
addBox(5.8, 0.08, 0.34, palette.wallEdge, -7.1, 2.63, -7);
addBox(11.8, 0.08, 0.34, palette.wallEdge, 4.1, 2.63, -7);
addBox(0.34, 0.08, 6.8, palette.wallEdge, 10, 2.63, -3.6);
addBox(0.34, 0.08, 4.8, palette.wallEdge, 10, 2.63, 4.6);
addBox(0.34, 0.08, 14, palette.wallEdge, -10, 2.63, 0);
// Exit A frame: east wall.
addBox(0.38, 2.55, 0.18, palette.green, 10, 1.275, -0.25);
addBox(0.38, 2.55, 0.18, palette.green, 10, 1.275, 2.25);
addBox(0.38, 0.18, 2.68, palette.green, 10, 2.55, 1);
addBox(1.2, 0.045, 2.4, 0x7ac59b, 9.35, 0.05, 1);
const exitALabel = addLabel("EXIT A", "#218c57", "#ffffff", 2.35);
exitALabel.position.set(9.85, 3.25, 1);
world.add(exitALabel);
// Exit B frame: north wall.
addBox(0.18, 2.55, 0.38, palette.green, -4.25, 1.275, -7);
addBox(0.18, 2.55, 0.38, palette.green, -1.75, 1.275, -7);
addBox(2.68, 0.18, 0.38, palette.green, -3, 2.55, -7);
addBox(2.4, 0.045, 1.2, 0x7ac59b, -3, 0.05, -6.35);
const exitBLabel = addLabel("EXIT B", "#218c57", "#ffffff", 2.35);
exitBLabel.position.set(-3, 3.25, -6.85);
world.add(exitBLabel);
// Exit floor rings.
function addExitRing(x, z, rotation = 0) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.075, 10, 36),
material(palette.green, { emissive: 0x0d3d25, emissiveIntensity: 0.3 })
);
ring.rotation.x = Math.PI / 2;
ring.rotation.z = rotation;
ring.position.set(x, 0.09, z);
ring.castShadow = true;
world.add(ring);
}
addExitRing(9.15, 1);
addExitRing(-3, -6.1);
// Reception desk.
addBox(3.8, 1.15, 1.45, palette.mustard, -5.8, 0.575, -2.7);
addBox(4.0, 0.13, 1.62, palette.white, -5.8, 1.215, -2.7);
addBox(0.8, 0.32, 0.45, palette.navy, -6.4, 1.43, -2.6);
const infoLabel = addLabel("INFORMATION", "#243841", "#ffffff", 2.8);
infoLabel.position.set(-5.8, 2.05, -2.7);
world.add(infoLabel);
// Waiting bench.
addBox(3.7, 0.48, 1.05, palette.blue, -5.6, 0.36, 4.0);
addBox(3.7, 0.9, 0.28, palette.blue, -5.6, 0.72, 4.45);
addBox(0.28, 0.58, 1.05, palette.navy, -7.25, 0.39, 4.0);
addBox(0.28, 0.58, 1.05, palette.navy, -3.95, 0.39, 4.0);
// Central round table and stools.
addCylinder(1.42, 1.42, 0.18, palette.wood, 2.0, 0.92, -0.3);
addCylinder(0.25, 0.32, 0.82, palette.navy, 2.0, 0.42, -0.3);
const stoolPositions = [
[0.25, 0.95],
[3.75, 0.95],
[0.25, -1.55],
[3.75, -1.55]
];
stoolPositions.forEach(([x, z]) => {
addCylinder(0.42, 0.46, 0.48, palette.coral, x, 0.31, z, 20);
addCylinder(0.09, 0.12, 0.42, palette.navy, x, 0.12, z, 12);
});
// Additional seating block.
addBox(2.9, 0.46, 0.95, palette.teal, 5.2, 0.35, 4.0);
addBox(2.9, 0.82, 0.25, palette.teal, 5.2, 0.68, 4.42);
// Columns.
[
[-7.0, -0.2],
[7.4, -4.0],
[-1.7, -3.8]
].forEach(([x, z]) => {
addCylinder(0.42, 0.48, 2.85, palette.wallEdge, x, 1.425, z, 20);
addCylinder(0.58, 0.58, 0.13, palette.wall, x, 2.9, z, 20);
});
// Planters and geometric trees.
function addPlanter(x, z, scale = 1) {
addCylinder(
0.62 * scale,
0.75 * scale,
0.7 * scale,
palette.pot,
x,
0.35 * scale,
z,
18
);
addCylinder(
0.12 * scale,
0.15 * scale,
1.5 * scale,
palette.wood,
x,
1.35 * scale,
z,
10
);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.9 * scale, 2.1 * scale, 9),
material(palette.foliage)
);
crown.position.set(x, 2.45 * scale, z);
crown.castShadow = true;
world.add(crown);
}
addPlanter(-7.6, 5.5, 0.95);
addPlanter(7.8, -5.5, 1.05);
addPlanter(6.0, 5.8, 0.8);
// Low display plinths.
addBox(1.2, 0.8, 1.2, palette.navy, -6.4, 0.4, -5.6);
addBox(0.75, 0.45, 0.75, palette.coral, -6.4, 1.02, -5.6);
addBox(1.2, 0.8, 1.2, palette.navy, 4.7, 0.4, -4.8);
addBox(0.75, 0.45, 0.75, palette.mustard, 4.7, 1.02, -4.8);
// -------------------------------------------------------------------------
// Current-position marker
// -------------------------------------------------------------------------
const player = new THREE.Vector3(-0.7, 0, 4.8);
const playerMarker = new THREE.Group();
world.add(playerMarker);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.28, 0.72, 12),
material(palette.navy)
);
body.position.y = 0.47;
body.castShadow = true;
playerMarker.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.2, 18, 12),
material(0xf2c5a7)
);
head.position.y = 1.02;
head.castShadow = true;
playerMarker.add(head);
const directionArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.31, 0.82, 3),
material(palette.coral)
);
directionArrow.rotation.x = -Math.PI / 2;
directionArrow.position.set(0, 0.16, -0.45);
directionArrow.castShadow = true;
playerMarker.add(directionArrow);
const playerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.055, 8, 32),
material(palette.teal, {
emissive: 0x0a504e,
emissiveIntensity: 0.35
})
);
playerRing.rotation.x = Math.PI / 2;
playerRing.position.y = 0.08;
playerMarker.add(playerRing);
// -------------------------------------------------------------------------
// Wayfinding state
// -------------------------------------------------------------------------
let heading = 0.18; // 0 = north (-Z), positive = clockwise/east.
let pitch = 0.72;
let cameraDistance = 24;
let selectedExit = "b";
let routeDirty = true;
const routeGroup = new THREE.Group();
world.add(routeGroup);
const keys = new Set();
function getRoutePoints(exitKey) {
if (exitKey === "a") {
return [
new THREE.Vector2(player.x, player.z),
new THREE.Vector2(7.6, player.z),
new THREE.Vector2(7.6, exits.a.z),
new THREE.Vector2(exits.a.x, exits.a.z)
];
}
return [
new THREE.Vector2(player.x, player.z),
new THREE.Vector2(exits.b.x, player.z),
new THREE.Vector2(exits.b.x, exits.b.z)
];
}
function routeLength(points) {
let length = 0;
for (let i = 1; i < points.length; i++) {
length += points[i].distanceTo(points[i - 1]);
}
return length;
}
function rebuildRoute() {
while (routeGroup.children.length) {
const child = routeGroup.children[0];
routeGroup.remove(child);
if (child.geometry) {
child.geometry.dispose();
}
}
const points = getRoutePoints(selectedExit);
for (let i = 1; i < points.length; i++) {
const start = points[i - 1];
const end = points[i];
const dx = end.x - start.x;
const dz = end.y - start.y;
const length = Math.hypot(dx, dz);
if (length < 0.01) continue;
const segment = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.055, 0.27),
material(palette.coral, {
emissive: 0x6f1c0d,
emissiveIntensity: 0.12
})
);
segment.position.set(
(start.x + end.x) / 2,
0.065,
(start.y + end.y) / 2
);
segment.rotation.y = -Math.atan2(dz, dx);
segment.receiveShadow = true;
routeGroup.add(segment);
}
const destination = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.07, 24),
material(palette.coral)
);
destination.position.set(exits[selectedExit].x, 0.09, exits[selectedExit].z);
routeGroup.add(destination);
}
// -------------------------------------------------------------------------
// Floor-plan canvas
// The world is rotated by -heading, making the current facing direction up.
// -------------------------------------------------------------------------
const mapCanvas = document.querySelector("#minimap");
const mapContext = mapCanvas.getContext("2d");
const MAP_W = mapCanvas.width;
const MAP_H = mapCanvas.height;
const MAP_SCALE = 24;
function drawMap() {
const context = mapContext;
context.clearRect(0, 0, MAP_W, MAP_H);
context.fillStyle = "#edf0e9";
context.fillRect(0, 0, MAP_W, MAP_H);
// Subtle drafting grid.
context.strokeStyle = "rgba(62, 82, 85, 0.055)";
context.lineWidth = 1;
for (let x = 0; x <= MAP_W; x += 24) {
context.beginPath();
context.moveTo(x, 0);
context.lineTo(x, MAP_H);
context.stroke();
}
for (let y = 0; y <= MAP_H; y += 24) {
context.beginPath();
context.moveTo(0, y);
context.lineTo(MAP_W, y);
context.stroke();
}
// World coordinates are transformed around the current position.
context.save();
context.translate(MAP_W / 2, MAP_H / 2);
context.rotate(-heading);
context.translate(-player.x * MAP_SCALE, -player.z * MAP_SCALE);
const S = MAP_SCALE;
// Floor.
context.fillStyle = "#d7cfbf";
context.fillRect(-10 * S, -7 * S, 20 * S, 14 * S);
// Zones.
context.fillStyle = "#e8d9b8";
context.fillRect(-9.2 * S, -5.05 * S, 7.2 * S, 4.5 * S);
context.fillStyle = "#c9ded9";
context.fillRect(-0.5 * S, -5.45 * S, 7 * S, 4.8 * S);
context.fillStyle = "#e2c4ae";
context.fillRect(-7.8 * S, 2.4 * S, 4.4 * S, 3.2 * S);
// Floor-plan furniture.
context.fillStyle = "#d89d32";
context.fillRect(-7.7 * S, -3.43 * S, 3.8 * S, 1.45 * S);
context.fillStyle = "#668ca5";
context.fillRect(-7.45 * S, 3.48 * S, 3.7 * S, 1.05 * S);
context.fillStyle = "#18a6a0";
context.fillRect(3.75 * S, 3.53 * S, 2.9 * S, 0.95 * S);
context.beginPath();
context.arc(2 * S, -0.3 * S, 1.42 * S, 0, Math.PI * 2);
context.fillStyle = "#a77750";
context.fill();
context.fillStyle = "#c4bbae";
[[-7, -0.2], [7.4, -4], [-1.7, -3.8]].forEach(([x, z]) => {
context.beginPath();
context.arc(x * S, z * S, 0.47 * S, 0, Math.PI * 2);
context.fill();
});
context.fillStyle = "#5f8768";
[[-7.6, 5.5], [7.8, -5.5], [6, 5.8]].forEach(([x, z]) => {
context.beginPath();
context.arc(x * S, z * S, 0.86 * S, 0, Math.PI * 2);
context.fill();
});
// Walls, with openings at both exits.
context.fillStyle = "#526168";
// North wall.
context.fillRect(-10 * S, -7 * S - 4, 5.75 * S, 8);
context.fillRect(-1.75 * S, -7 * S - 4, 11.75 * S, 8);
// East wall.
context.fillRect(10 * S - 4, -7 * S, 8, 6.75 * S);
context.fillRect(10 * S - 4, 2.25 * S, 8, 4.75 * S);
// West and south walls.
context.fillRect(-10 * S - 4, -7 * S, 8, 14 * S);
context.fillRect(-10 * S, 7 * S - 4, 20 * S, 8);
// Exit openings.
context.fillStyle = "#218c57";
context.fillRect(-4.25 * S, -7 * S - 7, 2.5 * S, 14);
context.fillRect(10 * S - 7, -0.25 * S, 14, 2.5 * S);
// Exit letters.
context.fillStyle = "#ffffff";
context.font = "900 18px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("B", -3 * S, -7 * S);
context.fillText("A", 10 * S, 1 * S);
// Selected route.
const points = getRoutePoints(selectedExit);
context.strokeStyle = "#ff6847";
context.lineWidth = 0.3 * S;
context.lineCap = "round";
context.lineJoin = "round";
context.beginPath();
points.forEach((point, index) => {
if (index === 0) context.moveTo(point.x * S, point.y * S);
else context.lineTo(point.x * S, point.y * S);
});
context.stroke();
context.fillStyle = "#ff6847";
context.beginPath();
context.arc(
exits[selectedExit].x * S,
exits[selectedExit].z * S,
0.42 * S,
0,
Math.PI * 2
);
context.fill();
context.restore();
// Facing cone remains fixed upward because the map itself is rotating.
context.save();
context.translate(MAP_W / 2, MAP_H / 2);
context.fillStyle = "rgba(24, 166, 160, 0.14)";
context.beginPath();
context.moveTo(0, 0);
context.lineTo(-42, -86);
context.lineTo(42, -86);
context.closePath();
context.fill();
// Current position.
context.fillStyle = "#ffffff";
context.strokeStyle = "#18a6a0";
context.lineWidth = 6;
context.beginPath();
context.arc(0, 0, 15, 0, Math.PI * 2);
context.fill();
context.stroke();
context.fillStyle = "#ff6847";
context.beginPath();
context.moveTo(0, -11);
context.lineTo(-7, 7);
context.lineTo(0, 3);
context.lineTo(7, 7);
context.closePath();
context.fill();
context.fillStyle = "#243841";
context.font = "800 12px system-ui, sans-serif";
context.textAlign = "center";
context.fillText("YOU", 0, 34);
context.restore();
// Fixed compass in the map corner. North is relative to the current view.
context.save();
context.translate(MAP_W - 42, 46);
context.rotate(-heading);
context.fillStyle = "#243841";
context.beginPath();
context.moveTo(0, -20);
context.lineTo(-7, 3);
context.lineTo(0, 0);
context.lineTo(7, 3);
context.closePath();
context.fill();
context.fillStyle = "#ffffff";
context.font = "900 11px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("N", 0, -13);
context.restore();
// Compass ring.
context.strokeStyle = "rgba(36, 56, 65, 0.28)";
context.lineWidth = 2;
context.beginPath();
context.arc(MAP_W - 42, 46, 27, 0, Math.PI * 2);
context.stroke();
}
// -------------------------------------------------------------------------
// HUD and controls
// -------------------------------------------------------------------------
const headingReadout = document.querySelector("#headingReadout");
const compassNeedle = document.querySelector("#compassNeedle");
const routeTitle = document.querySelector("#routeTitle");
const routeDescription = document.querySelector("#routeDescription");
const positionReadout = document.querySelector("#positionReadout");
const distanceA = document.querySelector("#distanceA");
const distanceB = document.querySelector("#distanceB");
const exitButtons = [...document.querySelectorAll(".exit-card")];
function cardinal(degrees) {
const names = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
return names[Math.round(degrees / 45) % 8];
}
function relativeDirection(targetBearing) {
let relative = targetBearing - heading;
relative = THREE.MathUtils.euclideanModulo(relative + Math.PI, Math.PI * 2) - Math.PI;
const absolute = Math.abs(relative);
const degrees = Math.round(THREE.MathUtils.radToDeg(absolute));
if (absolute < Math.PI / 6) return `straight ahead${degrees ? ` ${degrees}°` : ""}`;
if (relative > 0 && absolute < Math.PI / 2) return `ahead-right ${degrees}°`;
if (relative < 0 && absolute < Math.PI / 2) return `ahead-left ${degrees}°`;
if (relative > 0) return `behind-right ${degrees}°`;
return `behind-left ${degrees}°`;
}
function updateHUD() {
const degrees = THREE.MathUtils.radToDeg(heading);
const normalized = THREE.MathUtils.euclideanModulo(degrees, 360);
headingReadout.textContent = `${cardinal(normalized)} ${String(Math.round(normalized)).padStart(3, "0")}°`;
compassNeedle.style.transform = `rotate(${-normalized}deg)`;
const selected = exits[selectedExit];
const points = getRoutePoints(selectedExit);
const distance = routeLength(points);
const targetDeltaX = selected.x - player.x;
const targetDeltaZ = selected.z - player.z;
const targetBearing = Math.atan2(targetDeltaX, -targetDeltaZ);
routeTitle.textContent = `Route to ${selected.name}`;
routeDescription.textContent =
`${Math.round(distance)} meters · ${relativeDirection(targetBearing)}. ` +
`Follow the coral line in the model and map.`;
const aDistance = Math.round(routeLength(getRoutePoints("a")));
const bDistance = Math.round(routeLength(getRoutePoints("b")));
distanceA.textContent = `${aDistance} m`;
distanceB.textContent = `${bDistance} m`;
positionReadout.textContent =
`X ${player.x.toFixed(1)} · Z ${player.z.toFixed(1)}`;
exitButtons.forEach((button) => {
const active = button.dataset.exit === selectedExit;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
function selectExit(exitKey) {
selectedExit = exitKey;
routeDirty = true;
}
exitButtons.forEach((button) => {
button.addEventListener("click", () => selectExit(button.dataset.exit));
});
window.addEventListener("keydown", (event) => {
if (["KeyW", "KeyA", "KeyS", "KeyD", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(event.code)) {
keys.add(event.code);
event.preventDefault();
}
if (event.code === "Digit1") selectExit("a");
if (event.code === "Digit2") selectExit("b");
});
window.addEventListener("keyup", (event) => {
keys.delete(event.code);
});
window.addEventListener("blur", () => keys.clear());
// Direct camera controls: no addons or example modules are used.
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
heading += deltaX * 0.006;
pitch = THREE.MathUtils.clamp(pitch + deltaY * 0.004, 0.42, 1.12);
routeDirty = true;
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.018,
13,
36
);
},
{ passive: false }
);
function updateCamera() {
// The horizontal forward vector is shared by the camera and map.
const forward = new THREE.Vector3(
Math.sin(heading),
0,
-Math.cos(heading)
);
// Aim slightly toward the room center while following the walker.
const lookTarget = player.clone().multiplyScalar(0.72);
lookTarget.y = 0.58;
const horizontalDistance = Math.cos(pitch) * cameraDistance;
const verticalDistance = Math.sin(pitch) * cameraDistance;
camera.position.copy(lookTarget).addScaledVector(forward, -horizontalDistance);
camera.position.y += verticalDistance;
camera.lookAt(lookTarget);
}
function movePlayer(deltaTime) {
const originalX = player.x;
const originalZ = player.z;
const speed = 3.2 * deltaTime;
const forward = new THREE.Vector3(
Math.sin(heading),
0,
-Math.cos(heading)
);
const right = new THREE.Vector3(
Math.cos(heading),
0,
Math.sin(heading)
);
if (keys.has("KeyW") || keys.has("ArrowUp")) {
player.addScaledVector(forward, speed);
}
if (keys.has("KeyS") || keys.has("ArrowDown")) {
player.addScaledVector(forward, -speed);
}
if (keys.has("KeyD") || keys.has("ArrowRight")) {
player.addScaledVector(right, speed);
}
if (keys.has("KeyA") || keys.has("ArrowLeft")) {
player.addScaledVector(right, -speed);
}
player.x = THREE.MathUtils.clamp(player.x, -9.15, 9.15);
player.z = THREE.MathUtils.clamp(player.z, -6.15, 6.15);
if (player.x !== originalX || player.z !== originalZ) {
routeDirty = true;
}
}
const resizeObserver = new ResizeObserver(() => {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
});
resizeObserver.observe(viewport);
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
let previousTime = performance.now();
function animate(time) {
const deltaTime = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
movePlayer(deltaTime);
updateCamera();
playerMarker.position.set(player.x, 0, player.z);
playerMarker.rotation.y = -heading;
const pulse = 1 + Math.sin(time * 0.004) * 0.08;
playerRing.scale.setScalar(pulse);
if (routeDirty) {
rebuildRoute();
drawMap();
updateHUD();
routeDirty = false;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```