Prompt specification
Build or customize the Three.js 3D scene "Map-to-room correspondence" 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: Map-to-room correspondence
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/map-to-room-correspondence-x0474
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a room model above its raised map; selecting one map feature highlights the corresponding doorway, service desk, or seating area in the larger scene. Voxel style.
Working Three.js Starter (map-to-room-correspondence-x0474):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Room / Interactive Site Map</title>
<style>
:root {
--ink: #173532;
--muted: #6c7d78;
--paper: #f7f4e9;
--accent: #f2b84b;
--line: rgba(23, 53, 50, 0.14);
--shadow: 0 18px 55px rgba(26, 47, 44, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e7dd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app,
#canvas-host,
#labels {
position: fixed;
inset: 0;
}
#canvas-host canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.brand {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 14px;
pointer-events: none;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(2, 11px);
grid-template-rows: repeat(2, 11px);
gap: 3px;
transform: rotate(-8deg);
}
.brand-mark i {
display: block;
background: var(--ink);
border-radius: 1px;
}
.brand-mark i:nth-child(2) {
opacity: 0.55;
}
.brand-mark i:nth-child(3) {
opacity: 0.75;
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1;
letter-spacing: 0.14em;
font-weight: 800;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.model-badge {
position: fixed;
z-index: 5;
top: 28px;
left: 50%;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(247, 244, 233, 0.72);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
pointer-events: none;
}
.model-badge::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 8px;
border-radius: 50%;
background: #39aa8a;
box-shadow: 0 0 0 4px rgba(57, 170, 138, 0.12);
vertical-align: 1px;
}
.tools {
position: fixed;
z-index: 6;
top: 24px;
right: 24px;
width: 250px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(247, 244, 233, 0.86);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.tools-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.tools-label {
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
color: var(--muted);
}
.reset-button {
border: 1px solid var(--line);
border-radius: 9px;
padding: 7px 10px;
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
transition: background 160ms ease, transform 160ms ease;
}
.reset-button:hover {
background: rgba(23, 53, 50, 0.07);
transform: translateY(-1px);
}
.range-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px 12px;
align-items: center;
margin-top: 13px;
}
.range-row output {
color: var(--ink);
font-size: 11px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.range-row input {
grid-column: 1 / -1;
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 999px;
background: rgba(23, 53, 50, 0.16);
cursor: pointer;
}
.range-row input::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 8px rgba(23, 53, 50, 0.24);
}
.range-row input::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 8px rgba(23, 53, 50, 0.24);
}
.info-panel {
position: fixed;
z-index: 5;
top: 125px;
right: 24px;
width: 290px;
padding: 21px;
border: 1px solid var(--line);
border-radius: 19px;
background: rgba(247, 244, 233, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.info-kicker {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.info-number {
display: inline-flex;
align-items: center;
justify-content: center;
width: 31px;
height: 31px;
border-radius: 9px;
background: var(--accent);
color: #173532;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.04em;
}
.info-panel h2 {
margin: 22px 0 5px;
font-size: 27px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.info-subtitle {
color: var(--accent);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.info-panel p {
margin: 17px 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
padding: 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.3);
}
.metric small {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric strong {
font-size: 12px;
font-weight: 800;
}
.feature-nav {
position: fixed;
z-index: 6;
left: 24px;
bottom: 24px;
display: flex;
gap: 8px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(247, 244, 233, 0.86);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.feature-button {
display: flex;
align-items: center;
gap: 10px;
min-width: 143px;
padding: 10px 12px;
border: 1px solid transparent;
border-radius: 11px;
background: transparent;
text-align: left;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease,
transform 160ms ease;
}
.feature-button:hover {
transform: translateY(-1px);
background: rgba(23, 53, 50, 0.05);
}
.feature-button[aria-pressed="true"] {
border-color: var(--line);
background: rgba(255, 255, 255, 0.55);
}
.feature-swatch {
display: grid;
place-items: center;
width: 29px;
height: 29px;
flex: 0 0 auto;
border-radius: 8px;
color: var(--ink);
font-size: 10px;
font-weight: 900;
}
.feature-button strong {
display: block;
font-size: 11px;
font-weight: 850;
}
.feature-button small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.05em;
}
.hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 31px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
background: rgba(247, 244, 233, 0.68);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
pointer-events: none;
white-space: nowrap;
}
.map-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px 5px 5px;
border: 1px solid rgba(23, 53, 50, 0.13);
border-radius: 9px;
background: rgba(247, 244, 233, 0.92);
box-shadow: 0 5px 18px rgba(23, 53, 50, 0.13);
color: var(--ink);
transform: translate(-50%, -100%);
pointer-events: auto;
cursor: pointer;
white-space: nowrap;
transition: opacity 150ms ease, box-shadow 150ms ease;
}
.map-label:hover {
box-shadow: 0 7px 22px rgba(23, 53, 50, 0.2);
}
.map-label .label-number,
.room-label .label-number {
display: grid;
place-items: center;
min-width: 22px;
height: 22px;
padding: 0 4px;
border-radius: 6px;
color: var(--ink);
font-size: 9px;
font-weight: 900;
}
.map-label .label-text,
.room-label .label-text {
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.room-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(23, 53, 50, 0.16);
border-radius: 10px;
background: rgba(247, 244, 233, 0.96);
box-shadow: 0 9px 24px rgba(23, 53, 50, 0.18);
transform: translate(-50%, -100%);
pointer-events: none;
white-space: nowrap;
}
.room-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: var(--ink);
opacity: 0.45;
}
.scene-tag {
position: absolute;
color: rgba(23, 53, 50, 0.52);
transform: translate(-50%, -50%);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e9e7dd;
transition: opacity 350ms ease, visibility 350ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.loader-cubes {
display: flex;
gap: 3px;
}
.loader-cubes i {
width: 8px;
height: 8px;
background: var(--ink);
animation: bounce 900ms ease-in-out infinite alternate;
}
.loader-cubes i:nth-child(2) {
animation-delay: 120ms;
}
.loader-cubes i:nth-child(3) {
animation-delay: 240ms;
}
@keyframes bounce {
to {
transform: translateY(-7px);
opacity: 0.35;
}
}
@media (max-width: 900px) {
.model-badge,
.hint {
display: none;
}
.brand {
top: 17px;
left: 17px;
}
.tools {
top: 16px;
right: 16px;
width: 210px;
}
.info-panel {
top: 108px;
right: 16px;
width: 245px;
padding: 17px;
}
.info-panel h2 {
margin-top: 16px;
font-size: 23px;
}
.info-panel p {
font-size: 12px;
}
.feature-nav {
left: 16px;
bottom: 16px;
}
.feature-button {
min-width: auto;
}
.feature-button .feature-copy {
display: none;
}
}
@media (max-width: 560px) {
.brand h1 {
font-size: 14px;
}
.brand p {
font-size: 9px;
}
.tools {
width: 156px;
}
.tools-label {
font-size: 8px;
}
.reset-button {
padding: 6px 7px;
font-size: 8px;
}
.info-panel {
top: auto;
right: 12px;
bottom: 76px;
width: 210px;
}
.info-panel p,
.metrics {
display: none;
}
.info-panel h2 {
margin-bottom: 8px;
font-size: 20px;
}
.feature-nav {
right: 12px;
left: 12px;
justify-content: center;
}
.feature-button {
flex: 1;
justify-content: center;
padding: 8px;
}
.map-label .label-text {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<div id="canvas-host"></div>
<div id="labels"></div>
<header class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div>
<h1>ROOM / INDEX</h1>
<p>Interactive voxel study</p>
</div>
</header>
<div class="model-badge">Exploded model · interactive</div>
<section class="tools" aria-label="View controls">
<div class="tools-row">
<span class="tools-label">Camera</span>
<button class="reset-button" id="reset-view" type="button">Reset view</button>
</div>
<div class="range-row">
<label class="tools-label" for="separation">Model lift</label>
<output id="separation-value" for="separation">6.8 m</output>
<input
id="separation"
type="range"
min="4.8"
max="9"
step="0.1"
value="6.8"
/>
</div>
</section>
<aside class="info-panel" aria-live="polite">
<div class="info-kicker">
<span>Selected element</span>
<span class="info-number" id="info-number">01</span>
</div>
<h2 id="info-title">Main doorway</h2>
<div class="info-subtitle" id="info-subtitle">Threshold / D-01</div>
<p id="info-description"></p>
<div class="metrics">
<div class="metric">
<small id="metric-label-a">Opening</small>
<strong id="metric-value-a">2.6 m</strong>
</div>
<div class="metric">
<small id="metric-label-b">Location</small>
<strong id="metric-value-b">North wall</strong>
</div>
</div>
</aside>
<nav class="feature-nav" aria-label="Model features">
<button class="feature-button" type="button" data-feature="doorway" aria-pressed="true">
<span class="feature-swatch" style="background:#f2b84b">01</span>
<span class="feature-copy">
<strong>Doorway</strong>
<small>D-01</small>
</span>
</button>
<button class="feature-button" type="button" data-feature="service" aria-pressed="false">
<span class="feature-swatch" style="background:#ee725f">02</span>
<span class="feature-copy">
<strong>Service desk</strong>
<small>S-02</small>
</span>
</button>
<button class="feature-button" type="button" data-feature="seating" aria-pressed="false">
<span class="feature-swatch" style="background:#34a89a">03</span>
<span class="feature-copy">
<strong>Seating area</strong>
<small>A-03</small>
</span>
</button>
</nav>
<div class="hint">Drag to orbit · Scroll to zoom · Select a colored map zone</div>
<div id="loading">
<div class="loader">
<span class="loader-cubes"><i></i><i></i><i></i></span>
Building voxel model
</div>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* ------------------------------------------------------------------
Renderer and scene
------------------------------------------------------------------ */
const host = document.getElementById("canvas-host");
const labelLayer = document.getElementById("labels");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel room model above a raised floor-plan map"
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e7dd);
scene.fog = new THREE.Fog(0xe9e7dd, 38, 70);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x53645f, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff6df, 3.25);
sun.position.set(11, 19, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 19;
sun.shadow.camera.bottom = -19;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d5d2, 1.1);
fill.position.set(-12, 9, -10);
scene.add(fill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({
color: 0xe9e7dd,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.76;
ground.receiveShadow = true;
scene.add(ground);
/* ------------------------------------------------------------------
Feature definitions
------------------------------------------------------------------ */
const featureDefinitions = [
{
id: "doorway",
number: "01",
title: "Main doorway",
subtitle: "Threshold / D-01",
color: 0xf2b84b,
softColor: 0xf5dca0,
description:
"The primary entry is emphasized with a deep yellow frame. Its footprint links directly to the highlighted threshold above.",
metricA: ["Opening", "2.6 m"],
metricB: ["Location", "North wall"],
mapPosition: [0, 0, -3.78],
roomPosition: [0, 0, -4.28],
mapAnchorY: 1.55,
roomAnchorY: 3.45
},
{
id: "service",
number: "02",
title: "Service desk",
subtitle: "Reception / S-02",
color: 0xee725f,
softColor: 0xf4b3a9,
description:
"A coral service counter marks the arrival point. The matching upper counter, screen, and queue elements illuminate together.",
metricA: ["Counter", "2.8 m"],
metricB: ["Location", "Central east"],
mapPosition: [3.72, 0, 0.22],
roomPosition: [3.72, 0, 0.22],
mapAnchorY: 1.25,
roomAnchorY: 2.45
},
{
id: "seating",
number: "03",
title: "Seating area",
subtitle: "Lounge / A-03",
color: 0x34a89a,
softColor: 0xa7d9d1,
description:
"Four teal seats gather around a central table. The corresponding lounge zone on the raised map remains linked by a voxel guide.",
metricA: ["Capacity", "4 seats"],
metricB: ["Location", "West lounge"],
mapPosition: [-2.78, 0, 1.36],
roomPosition: [-2.78, 0, 1.36],
mapAnchorY: 1.25,
roomAnchorY: 1.72
}
];
const features = Object.fromEntries(
featureDefinitions.map((definition) => [
definition.id,
{
...definition,
materials: [],
mapGroup: null,
roomGroup: null,
mapAnchor: null,
roomAnchor: null
}
])
);
const mapGroup = new THREE.Group();
const roomGroup = new THREE.Group();
const connectorGroup = new THREE.Group();
const mapMarkerGroup = new THREE.Group();
const roomMarkerGroup = new THREE.Group();
scene.add(mapGroup, roomGroup, connectorGroup, mapMarkerGroup, roomMarkerGroup);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 1,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
function box(parent, size, position, color, options = {}) {
const material = makeMaterial(color, options);
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.feature) {
mesh.userData.featureId = options.feature;
features[options.feature].materials.push({
material,
baseEmissive: material.emissive.clone()
});
}
parent.add(mesh);
return mesh;
}
function createFeatureGroups() {
for (const feature of Object.values(features)) {
feature.mapGroup = new THREE.Group();
feature.mapGroup.position.set(...feature.mapPosition);
feature.mapGroup.userData.featureId = feature.id;
mapGroup.add(feature.mapGroup);
feature.roomGroup = new THREE.Group();
feature.roomGroup.position.set(...feature.roomPosition);
feature.roomGroup.userData.featureId = feature.id;
roomGroup.add(feature.roomGroup);
feature.mapAnchor = new THREE.Object3D();
feature.mapAnchor.position.set(0, feature.mapAnchorY, 0);
feature.mapGroup.add(feature.mapAnchor);
feature.roomAnchor = new THREE.Object3D();
feature.roomAnchor.position.set(0, feature.roomAnchorY, 0);
feature.roomGroup.add(feature.roomAnchor);
}
}
createFeatureGroups();
/* ------------------------------------------------------------------
Raised site map
------------------------------------------------------------------ */
function buildMap() {
// Pedestal and feet.
box(mapGroup, [15.4, 0.55, 10.4], [0, 0, 0], 0x304b48);
box(mapGroup, [14.9, 0.16, 9.9], [0, 0.36, 0], 0xd9d5c3);
const footPositions = [
[-6.55, -0.48, -4.2],
[6.55, -0.48, -4.2],
[-6.55, -0.48, 4.2],
[6.55, -0.48, 4.2]
];
footPositions.forEach((position) => {
box(mapGroup, [0.58, 0.46, 0.58], position, 0x213936);
});
// Fine plan grid.
for (let x = -6; x <= 6; x += 1) {
box(
mapGroup,
[0.022, 0.012, 9.25],
[x, 0.451, 0],
0xc7c3b3,
{ castShadow: false }
);
}
for (let z = -4; z <= 4; z += 1) {
box(
mapGroup,
[14.25, 0.012, 0.022],
[0, 0.451, z],
0xc7c3b3,
{ castShadow: false }
);
}
// Low perimeter walls.
box(mapGroup, [14.55, 0.32, 0.18], [0, 0.61, -4.65], 0x68756e);
box(mapGroup, [14.55, 0.32, 0.18], [0, 0.61, 4.65], 0x68756e);
box(mapGroup, [0.18, 0.32, 9.15], [-7.18, 0.61, 0], 0x68756e);
box(mapGroup, [0.18, 0.32, 9.15], [7.18, 0.61, 0], 0x68756e);
// Interior plan partitions.
box(mapGroup, [0.17, 0.36, 4.25], [-0.68, 0.61, 1.4], 0x8a948a);
box(mapGroup, [3.45, 0.36, 0.17], [2.05, 0.61, -2.08], 0x8a948a);
box(mapGroup, [2.1, 0.36, 0.17], [-4.25, 0.61, -2.08], 0x8a948a);
// Doorway miniature.
const door = features.doorway.mapGroup;
box(door, [2.8, 0.14, 0.98], [0, 0.53, 0], 0xf5dca0, {
feature: "doorway"
});
box(door, [0.18, 0.74, 0.22], [-1.02, 0.88, -0.22], 0xf2b84b, {
feature: "doorway"
});
box(door, [0.18, 0.74, 0.22], [1.02, 0.88, -0.22], 0xf2b84b, {
feature: "doorway"
});
box(door, [2.22, 0.16, 0.22], [0, 1.18, -0.22], 0xf2b84b, {
feature: "doorway"
});
// Service desk miniature.
const service = features.service.mapGroup;
box(service, [2.72, 0.14, 1.72], [0, 0.53, 0], 0xf4b3a9, {
feature: "service"
});
box(service, [1.72, 0.38, 0.58], [0, 0.76, -0.08], 0xee725f, {
feature: "service"
});
box(service, [0.38, 0.28, 0.09], [0.2, 1.08, -0.1], 0x294743, {
feature: "service"
});
// Seating miniature.
const seating = features.seating.mapGroup;
box(seating, [3.34, 0.14, 2.62], [0, 0.53, 0], 0xa7d9d1, {
feature: "seating"
});
box(seating, [0.9, 0.5, 0.9], [0, 0.75, 0], 0xf0c68e, {
feature: "seating"
});
box(seating, [0.68, 0.18, 0.68], [-1.08, 0.69, 0], 0x34a89a, {
feature: "seating"
});
box(seating, [0.68, 0.18, 0.68], [1.08, 0.69, 0], 0x34a89a, {
feature: "seating"
});
}
/* ------------------------------------------------------------------
Upper voxel room
------------------------------------------------------------------ */
function buildRoom() {
// Structural shell.
box(roomGroup, [14, 0.45, 9], [0, 0, 0], 0xf1ecdc);
box(roomGroup, [14.25, 0.16, 9.25], [0, -0.28, 0], 0xc8c3b3);
// Floor grid.
for (let x = -6; x <= 6; x += 1.5) {
box(
roomGroup,
[0.025, 0.018, 8.5],
[x, 0.235, 0],
0xddd7c8,
{ castShadow: false }
);
}
for (let z = -3; z <= 3; z += 1.5) {
box(
roomGroup,
[13.5, 0.018, 0.025],
[0, 0.235, z],
0xddd7c8,
{ castShadow: false }
);
}
// Back wall with an opening for the doorway.
box(roomGroup, [5.45, 3.8, 0.32], [-4.24, 2.12, -4.35], 0xe6e1d2);
box(roomGroup, [5.45, 3.8, 0.32], [4.24, 2.12, -4.35], 0xe6e1d2);
box(roomGroup, [3.05, 1.0, 0.32], [0, 3.31, -4.35], 0xe6e1d2);
// Left wall and open front/right cutaways.
box(roomGroup, [0.32, 3.45, 8.7], [-6.85, 1.95, 0], 0xdedbcc);
box(roomGroup, [13.7, 0.25, 0.25], [0, 0.34, 4.28], 0xd8d4c6);
box(roomGroup, [0.25, 0.25, 8.55], [6.84, 0.34, 0], 0xd8d4c6);
// Structural columns and trim.
[-6.72, 6.72].forEach((x) => {
box(roomGroup, [0.48, 3.55, 0.48], [x, 2.02, -4.2], 0xc7c2b3);
box(roomGroup, [0.48, 0.5, 0.48], [x, 0.47, 4.15], 0xc7c2b3);
});
box(roomGroup, [13.55, 0.13, 0.4], [0, 3.93, -4.31], 0xc7c2b3);
box(roomGroup, [0.4, 0.13, 8.5], [-6.67, 3.62, 0], 0xc7c2b3);
// Window-like voxel panels on the left wall.
box(roomGroup, [0.07, 1.55, 2.75], [-6.66, 2.35, -1.55], 0xa7cdd0, {
roughness: 0.35,
transparent: true,
opacity: 0.78
});
box(roomGroup, [0.11, 0.1, 2.85], [-6.61, 2.35, -1.55], 0x607f80);
box(roomGroup, [0.11, 1.65, 0.1], [-6.61, 2.35, -1.55], 0x607f80);
// Doorway feature.
const door = features.doorway.roomGroup;
box(door, [0.24, 2.85, 0.42], [-1.25, 1.66, -4.3], 0xf2b84b, {
feature: "doorway"
});
box(door, [0.24, 2.85, 0.42], [1.25, 1.66, -4.3], 0xf2b84b, {
feature: "doorway"
});
box(door, [2.74, 0.24, 0.42], [0, 3.04, -4.3], 0xf2b84b, {
feature: "doorway"
});
box(door, [2.35, 0.08, 0.8], [0, 0.29, -4.0], 0xd5ad62, {
feature: "doorway"
});
// Service desk feature.
const service = features.service.roomGroup;
box(service, [2.5, 1.05, 0.88], [0, 0.77, 0], 0xdc6957, {
feature: "service"
});
box(service, [2.82, 0.16, 1.04], [0, 1.37, 0], 0xf1b779, {
feature: "service"
});
box(service, [0.72, 0.52, 0.11], [0.18, 1.84, -0.18], 0x244542, {
feature: "service"
});
box(service, [0.11, 0.35, 0.11], [0.18, 1.52, -0.18], 0x244542, {
feature: "service"
});
box(service, [0.58, 0.06, 0.42], [-0.74, 1.49, 0.03], 0x244542, {
feature: "service"
});
// Queue markers.
[-1.65, 1.65].forEach((x) => {
box(service, [0.16, 0.72, 0.16], [x, 0.6, 1.03], 0xee725f, {
feature: "service"
});
box(service, [0.34, 0.16, 0.34], [x, 0.99, 1.03], 0xf2b84b, {
feature: "service"
});
});
// Seating area feature.
const seating = features.seating.roomGroup;
box(seating, [3.48, 0.07, 2.72], [0, 0.285, 0], 0xa7d9d1, {
feature: "seating"
});
box(seating, [0.92, 0.7, 0.92], [0, 0.72, 0], 0xefc78f, {
feature: "seating"
});
box(seating, [0.35, 0.35, 0.35], [0, 1.22, 0], 0xd9a96f, {
feature: "seating"
});
function chair(x, z, rotationY) {
const chairGroup = new THREE.Group();
chairGroup.position.set(x, 0, z);
chairGroup.rotation.y = rotationY;
seating.add(chairGroup);
box(chairGroup, [0.76, 0.18, 0.76], [0, 0.49, 0], 0x34a89a, {
feature: "seating"
});
box(chairGroup, [0.76, 0.66, 0.16], [0, 0.77, 0.34], 0x2c8f84, {
feature: "seating"
});
[-0.26, 0.26].forEach((legX) => {
box(chairGroup, [0.1, 0.3, 0.1], [legX, 0.29, 0], 0x47635f, {
feature: "seating"
});
});
}
chair(-1.18, 0, Math.PI / 2);
chair(1.18, 0, -Math.PI / 2);
chair(0, -1.18, 0);
chair(0, 1.18, Math.PI);
// Wall art.
box(roomGroup, [1.1, 0.76, 0.09], [-4.3, 2.38, -4.13], 0xd39d68);
box(roomGroup, [0.42, 0.42, 0.06], [-4.42, 2.4, -4.06], 0xf3d3a4);
box(roomGroup, [1.25, 0.76, 0.09], [4.25, 2.38, -4.13], 0x78aaa2);
box(roomGroup, [0.58, 0.32, 0.06], [4.1, 2.4, -4.06], 0xd7e4d9);
// Shelf and books.
box(roomGroup, [2.15, 0.13, 0.62], [-5.2, 1.35, -3.95], 0xa98661);
box(roomGroup, [2.15, 0.13, 0.62], [-5.2, 2.08, -3.95], 0xa98661);
for (let i = 0; i < 7; i++) {
box(
roomGroup,
[0.16, 0.42 + (i % 3) * 0.07, 0.28],
[-6.02 + i * 0.27, 1.65, -3.92],
[0xcf725e, 0xe2b85f, 0x4f938a][i % 3]
);
}
// Voxel plant.
box(roomGroup, [0.62, 0.58, 0.62], [5.62, 0.52, 3.25], 0xb97954);
box(roomGroup, [0.2, 1.15, 0.2], [5.62, 1.23, 3.25], 0x537d5b);
box(roomGroup, [0.72, 0.42, 0.55], [5.45, 1.63, 3.25], 0x4c8b65);
box(roomGroup, [0.55, 0.5, 0.68], [5.86, 1.98, 3.28], 0x5e9c6d);
}
buildMap();
buildRoom();
/* ------------------------------------------------------------------
Labels
------------------------------------------------------------------ */
const mapLabels = {};
const featureButtons = [...document.querySelectorAll(".feature-button")];
featureDefinitions.forEach((definition) => {
const feature = features[definition.id];
const button = document.createElement("button");
button.className = "map-label";
button.type = "button";
button.setAttribute("aria-label", `Select ${definition.title}`);
button.innerHTML = `
<span
class="label-number"
style="background:#${definition.color.toString(16).padStart(6, "0")}"
>${definition.number}</span>
<span class="label-text">${definition.title}</span>
`;
button.addEventListener("click", () => selectFeature(definition.id));
labelLayer.appendChild(button);
mapLabels[definition.id] = button;
feature.mapLabel = button;
});
const roomLabel = document.createElement("div");
roomLabel.className = "room-label";
labelLayer.appendChild(roomLabel);
const mapTag = document.createElement("div");
mapTag.className = "scene-tag";
mapTag.textContent = "Lower / Raised site map";
labelLayer.appendChild(mapTag);
const roomTag = document.createElement("div");
roomTag.className = "scene-tag";
roomTag.textContent = "Upper / Voxel room model";
labelLayer.appendChild(roomTag);
const mapTagAnchor = new THREE.Object3D();
mapTagAnchor.position.set(-5.65, 0.15, 4.95);
mapGroup.add(mapTagAnchor);
const roomTagAnchor = new THREE.Object3D();
roomTagAnchor.position.set(5.7, 0.2, 4.35);
roomGroup.add(roomTagAnchor);
/* ------------------------------------------------------------------
Selection and highlighting
------------------------------------------------------------------ */
let selectedId = "doorway";
function getFeatureId(object) {
let current = object;
while (current) {
if (current.userData.featureId) {
return current.userData.featureId;
}
current = current.parent;
}
return null;
}
function clearGeneratedGroup(group) {
while (group.children.length) {
const child = group.children[0];
group.remove(child);
child.traverse((object) => {
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => material.dispose());
}
});
}
}
function rebuildConnectors() {
clearGeneratedGroup(connectorGroup);
for (const feature of Object.values(features)) {
const link = new THREE.Group();
link.userData.featureId = feature.id;
const startY = 0.72;
const endY = separation - 0.13;
const count = Math.max(6, Math.floor((endY - startY) / 0.42));
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const x = THREE.MathUtils.lerp(
feature.mapPosition[0],
feature.roomPosition[0],
t
);
const z = THREE.MathUtils.lerp(
feature.mapPosition[2],
feature.roomPosition[2],
t
);
const y = THREE.MathUtils.lerp(startY, endY, t);
const material = new THREE.MeshBasicMaterial({
color: feature.color,
transparent: true,
opacity: feature.id === selectedId ? 0.92 : 0.27,
depthWrite: false
});
const linkBlock = new THREE.Mesh(cubeGeometry, material);
linkBlock.position.set(x, y, z);
linkBlock.scale.set(0.075, 0.2, 0.075);
link.add(linkBlock);
}
connectorGroup.add(link);
}
}
function addMarkerCube(parent, position, size, color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.94,
depthTest: false
});
const marker = new THREE.Mesh(cubeGeometry, material);
marker.position.set(...position);
marker.scale.set(...size);
marker.userData.baseScale = marker.scale.clone();
marker.renderOrder = 10;
parent.add(marker);
}
function rebuildSelectionMarkers() {
clearGeneratedGroup(mapMarkerGroup);
clearGeneratedGroup(roomMarkerGroup);
scene.updateMatrixWorld(true);
const feature = features[selectedId];
const color = feature.color;
// Four map corner markers.
const mapBounds = new THREE.Box3().setFromObject(feature.mapGroup);
const mapCorners = [
[mapBounds.min.x, mapBounds.min.z],
[mapBounds.min.x, mapBounds.max.z],
[mapBounds.max.x, mapBounds.min.z],
[mapBounds.max.x, mapBounds.max.z]
];
mapCorners.forEach(([x, z]) => {
addMarkerCube(
mapMarkerGroup,
[x, mapBounds.min.y + 0.18, z],
[0.13, 0.5, 0.13],
color
);
});
// Eight room corner markers.
const roomBounds = new THREE.Box3().setFromObject(feature.roomGroup);
const roomCorners = [];
[roomBounds.min.x, roomBounds.max.x].forEach((x) => {
[roomBounds.min.y, roomBounds.max.y].forEach((y) => {
[roomBounds.min.z, roomBounds.max.z].forEach((z) => {
roomCorners.push([x, y, z]);
});
});
});
roomCorners.forEach((position) => {
addMarkerCube(
roomMarkerGroup,
position,
[0.17, 0.17, 0.17],
color
);
});
}
function applyHighlight() {
for (const feature of Object.values(features)) {
const selected = feature.id === selectedId;
feature.materials.forEach(({ material, baseEmissive }) => {
material.emissive.copy(
selected ? new THREE.Color(feature.color) : baseEmissive
);
material.emissiveIntensity = selected ? 0.38 : 0;
});
}
connectorGroup.traverse((object) => {
if (object.material) {
const selected = getFeatureId(object) === selectedId;
object.material.opacity = selected ? 0.92 : 0.27;
}
});
featureButtons.forEach((button) => {
button.setAttribute(
"aria-pressed",
String(button.dataset.feature === selectedId)
);
});
const feature = features[selectedId];
const colorHex = `#${feature.color.toString(16).padStart(6, "0")}`;
document.documentElement.style.setProperty("--accent", colorHex);
document.getElementById("info-number").textContent = feature.number;
document.getElementById("info-title").textContent = feature.title;
document.getElementById("info-subtitle").textContent = feature.subtitle;
document.getElementById("info-description").textContent = feature.description;
document.getElementById("metric-label-a").textContent = feature.metricA[0];
document.getElementById("metric-value-a").textContent = feature.metricA[1];
document.getElementById("metric-label-b").textContent = feature.metricB[0];
document.getElementById("metric-value-b").textContent = feature.metricB[1];
roomLabel.innerHTML = `
<span
class="label-number"
style="background:${colorHex}"
>${feature.number}</span>
<span class="label-text">${feature.title}</span>
`;
rebuildSelectionMarkers();
}
function selectFeature(id) {
if (!features[id]) return;
selectedId = id;
applyHighlight();
}
featureButtons.forEach((button) => {
button.addEventListener("click", () => {
selectFeature(button.dataset.feature);
});
});
/* ------------------------------------------------------------------
Custom camera controls and picking
------------------------------------------------------------------ */
function fittedRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.65) return 36;
if (aspect < 1.1) return 29;
return 25;
}
let separation = 6.8;
roomGroup.position.y = separation;
const controls = {
theta: 0.62,
phi: 1.01,
radius: fittedRadius(),
target: new THREE.Vector3(0, 0.8 + separation * 0.46, 0)
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function pickFeature(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(scene.children, true);
if (!hits.length) return null;
// Respect visible geometry: the first solid hit must belong to a feature.
const firstHit = hits.find((hit) => {
if (!hit.object.visible) return false;
const material = hit.object.material;
return !material || !material.transparent || material.opacity > 0.2;
});
return firstHit ? getFeatureId(firstHit.object) : null;
}
const pointerState = {
down: false,
id: null,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
moved: false
};
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerState.down = true;
pointerState.id = event.pointerId;
pointerState.startX = pointerState.lastX = event.clientX;
pointerState.startY = pointerState.lastY = event.clientY;
pointerState.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerState.down && pointerState.id === event.pointerId) {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
const totalDistance = Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
);
if (totalDistance > 4) pointerState.moved = true;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.43,
1.34
);
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
updateCamera();
} else {
const id = pickFeature(event);
renderer.domElement.style.cursor = id ? "pointer" : "grab";
}
});
function finishPointer(event) {
if (!pointerState.down || pointerState.id !== event.pointerId) return;
if (!pointerState.moved) {
const id = pickFeature(event);
if (id) selectFeature(id);
}
pointerState.down = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", finishPointer);
renderer.domElement.addEventListener("pointercancel", finishPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
16,
43
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset-view").addEventListener("click", () => {
controls.theta = 0.62;
controls.phi = 1.01;
controls.radius = fittedRadius();
controls.target.set(0, 0.8 + separation * 0.46, 0);
updateCamera();
});
const separationInput = document.getElementById("separation");
const separationValue = document.getElementById("separation-value");
separationInput.addEventListener("input", () => {
separation = Number(separationInput.value);
roomGroup.position.y = separation;
controls.target.set(0, 0.8 + separation * 0.46, 0);
separationValue.textContent = `${separation.toFixed(1)} m`;
rebuildConnectors();
rebuildSelectionMarkers();
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "1") selectFeature("doorway");
if (event.key === "2") selectFeature("service");
if (event.key === "3") selectFeature("seating");
if (event.key.toLowerCase() === "r") {
document.getElementById("reset-view").click();
}
});
/* ------------------------------------------------------------------
Projection of DOM labels
------------------------------------------------------------------ */
const projected = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
function projectLabel(element, anchor) {
anchor.getWorldPosition(worldPosition);
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function projectSceneTag(element, anchor) {
anchor.getWorldPosition(worldPosition);
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.1 &&
projected.x < 1.1 &&
projected.y > -1.1 &&
projected.y < 1.1;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
/* ------------------------------------------------------------------
Resize and animation
------------------------------------------------------------------ */
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.08;
const selectedMaterials = features[selectedId].materials;
selectedMaterials.forEach(({ material }) => {
material.emissiveIntensity = 0.34 + Math.sin(elapsed * 3.2) * 0.08;
});
[mapMarkerGroup, roomMarkerGroup].forEach((group) => {
group.traverse((object) => {
if (object.isMesh && object.userData.baseScale) {
const base = object.userData.baseScale;
object.scale.set(base.x, base.y * pulse, base.z);
}
});
});
scene.updateMatrixWorld(true);
for (const feature of Object.values(features)) {
projectLabel(feature.mapLabel, feature.mapAnchor);
}
projectLabel(roomLabel, features[selectedId].roomAnchor);
projectSceneTag(mapTag, mapTagAnchor);
projectSceneTag(roomTag, roomTagAnchor);
renderer.render(scene, camera);
}
rebuildConnectors();
applyHighlight();
updateCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```