Prompt specification
Build or customize the Three.js 3D scene "Inspect which courtyards remain reachable after a passage closes" 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: Inspect which courtyards remain reachable after a passage closes
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/inspect-which-courtyards-remain-reachable-after-a-pass-x2816
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the connected courtyards of Berlin's Hackesche Höfe. Let users close one hypothetical connector in the schematic block. Highlight remaining accessible courts and identify dead ends without altering the permanent surrounding buildings. Voxel style.
Working Three.js Starter (inspect-which-courtyards-remain-reachable-after-a-pass-x2816):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hackesche Höfe — Connected Courtyards</title>
<style>
:root {
--ink: #17242b;
--muted: #607078;
--paper: rgba(250, 248, 238, 0.88);
--line: rgba(23, 36, 43, 0.14);
--green: #49c98d;
--teal: #28c7bd;
--amber: #f0ad43;
--red: #e65e68;
--gray: #727b82;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce3df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255,255,255,0.72);
box-shadow:
0 16px 45px rgba(24, 39, 43, 0.15),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-card {
position: fixed;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 21px 18px;
border-radius: 18px;
pointer-events: none;
z-index: 5;
}
.eyebrow {
color: #168d83;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 5px;
font-size: clamp(27px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
}
#title-card p {
margin: 9px 0 0;
max-width: 345px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#controls {
position: fixed;
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px;
border-radius: 18px;
z-index: 7;
}
.connector-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.connector-head strong {
font-size: 12px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#connector-state {
padding: 4px 8px;
border-radius: 999px;
color: #0b716a;
background: rgba(40, 199, 189, 0.14);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#connector-state.closed {
color: #b53f49;
background: rgba(230, 94, 104, 0.14);
}
#summary {
min-height: 34px;
margin-bottom: 12px;
color: #43535a;
font-size: 12px;
line-height: 1.45;
}
.buttons {
display: flex;
gap: 8px;
}
button {
min-height: 39px;
border: 0;
border-radius: 11px;
padding: 0 13px;
color: white;
background: #168f84;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: transform 120ms ease, filter 120ms ease;
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button:focus-visible {
outline: 3px solid rgba(40, 199, 189, 0.35);
outline-offset: 2px;
}
#connector-toggle {
flex: 1;
box-shadow: 0 7px 18px rgba(22, 143, 132, 0.2);
}
#connector-toggle.closed {
background: #bf4b56;
box-shadow: 0 7px 18px rgba(191, 75, 86, 0.18);
}
#reset-camera {
color: var(--ink);
background: rgba(23, 36, 43, 0.07);
box-shadow: none;
}
.lock-note {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.lock-icon {
display: grid;
place-items: center;
width: 22px;
height: 22px;
flex: 0 0 auto;
border-radius: 7px;
color: #168f84;
background: rgba(40, 199, 189, 0.13);
font-weight: 900;
}
#legend {
position: fixed;
top: 22px;
right: 22px;
width: 205px;
padding: 15px 16px;
border-radius: 16px;
z-index: 5;
pointer-events: none;
}
#legend h2 {
margin: 0 0 10px;
font-size: 11px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: #526168;
font-size: 11px;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--green);
box-shadow: 0 0 0 3px rgba(73, 201, 141, 0.12);
}
.swatch.dead { background: var(--amber); }
.swatch.cut { background: var(--gray); }
.swatch.connector { background: var(--teal); }
.swatch.closed { background: var(--red); }
#hint {
position: fixed;
right: 22px;
bottom: 22px;
padding: 10px 13px;
border-radius: 12px;
color: #56666c;
background: rgba(250, 248, 238, 0.76);
border: 1px solid rgba(255,255,255,0.6);
font-size: 10px;
line-height: 1.45;
text-align: right;
pointer-events: none;
z-index: 5;
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
z-index: 4;
}
.court-label {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
transform: translate(-50%, -50%);
filter: drop-shadow(0 4px 7px rgba(0,0,0,0.16));
white-space: nowrap;
}
.court-label .pin {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border: 2px solid rgba(255,255,255,0.9);
border-radius: 8px;
color: white;
background: #328e70;
font-size: 11px;
font-weight: 900;
box-shadow: 0 3px 9px rgba(0,0,0,0.2);
}
.court-label .meta {
padding: 4px 7px;
border-radius: 7px;
color: #26363b;
background: rgba(250,248,238,0.88);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.court-label.dead .pin { background: #c77c22; }
.court-label.cut .pin { background: #626b72; }
.court-label.cut .meta { color: #606970; }
#connector-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid rgba(255,255,255,0.7);
border-radius: 9px;
color: #126e68;
background: rgba(227, 255, 249, 0.92);
box-shadow: 0 6px 18px rgba(0,0,0,0.15);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
}
#connector-label.closed {
color: #a73743;
background: rgba(255, 232, 234, 0.94);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
color: #476067;
background: #dce3df;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
z-index: 20;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
#title-card p { display: none; }
#controls {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
#legend {
top: 112px;
right: 12px;
width: 160px;
padding: 11px 12px;
}
#hint { display: none; }
.court-label .meta { display: none; }
.court-label .pin { width: 22px; height: 22px; }
}
@media (prefers-reduced-motion: reduce) {
* { transition: none !important; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels">
<div id="connector-label">Hypothetical link · open</div>
</div>
<header id="title-card" class="glass">
<div class="eyebrow">Berlin · Voxel wayfinding</div>
<h1>Hackesche Höfe</h1>
<p>
An interpretive seven-courtyard schematic. Close the hypothetical
Hof 5–6 connector to see which courts remain reachable and which
route ends in a dead end.
</p>
</header>
<section id="controls" class="glass">
<div class="connector-head">
<strong>Hypothetical connector</strong>
<span id="connector-state">Open</span>
</div>
<div id="summary" aria-live="polite"></div>
<div class="buttons">
<button id="connector-toggle" type="button">Close connector</button>
<button id="reset-camera" type="button">Reset view</button>
</div>
<div class="lock-note">
<span class="lock-icon">⌑</span>
<span>
Permanent surrounding buildings remain unchanged.
Only schematic routes, courtyard highlights, and the movable gate respond.
</span>
</div>
</section>
<aside id="legend" class="glass">
<h2>Schematic legend</h2>
<div class="legend-row"><span class="swatch"></span>Accessible court</div>
<div class="legend-row"><span class="swatch dead"></span>Reachable dead end</div>
<div class="legend-row"><span class="swatch cut"></span>No active route</div>
<div class="legend-row"><span class="swatch connector"></span>Optional connector</div>
<div class="legend-row"><span class="swatch closed"></span>Closed connector</div>
</aside>
<div id="hint">
Drag: rotate · Shift/right-drag: pan · Wheel: zoom<br>
Click the teal connector or the 3D schematic block · C: toggle · R: reset
</div>
<div id="loading">Building the courtyard block…</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 sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce3df);
scene.fog = new THREE.Fog(0xdce3df, 47, 88);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemisphere = new THREE.HemisphereLight(0xf3f7ef, 0x53636b, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.0);
sun.position.set(13, 25, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ac9d0, 0.75);
fill.position.set(-18, 12, -20);
scene.add(fill);
const permanentBuildings = new THREE.Group();
permanentBuildings.name = "Permanent surrounding buildings";
scene.add(permanentBuildings);
const dynamicOverlay = new THREE.Group();
dynamicOverlay.name = "Schematic accessibility overlay";
scene.add(dynamicOverlay);
const animatedMaterials = [];
function setMaterialTarget(material, color, emissive = 0x000000, intensity = 0) {
if (!material.userData.targetColor) {
material.userData.targetColor = new THREE.Color(color);
material.userData.targetEmissive = new THREE.Color(emissive);
material.userData.targetIntensity = intensity;
} else {
material.userData.targetColor.set(color);
material.userData.targetEmissive.set(emissive);
material.userData.targetIntensity = intensity;
}
animatedMaterials.push(material);
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
function box(w, h, d, mat, x, y, z, parent = scene, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function boxBetween(a, b, width, height, mat, y, parent = scene) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, length),
mat
);
mesh.position.set((a.x + b.x) / 2, y, (a.z + b.z) / 2);
mesh.rotation.y = Math.atan2(dx, dz);
mesh.castShadow = false;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 8473;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// -------------------------------------------------------------------------
// Courtyard graph
// -------------------------------------------------------------------------
const courts = {
1: { x: -6.0, z: 4.5 },
2: { x: -6.0, z: -0.8 },
3: { x: 0.0, z: -0.8 },
4: { x: 0.0, z: -6.2 },
5: { x: -6.0, z: -6.2 },
6: { x: -6.0, z:-11.5 },
7: { x: 0.0, z:-11.5 }
};
const edges = [
{ a: 1, b: 2, optional: false },
{ a: 2, b: 3, optional: false },
{ a: 3, b: 4, optional: false },
{ a: 4, b: 5, optional: false },
{ a: 5, b: 6, optional: true },
{ a: 6, b: 7, optional: false }
];
const entrance = { x: -6.0, z: 8.8 };
let connectorOpen = true;
let reachable = new Set();
let deadEnds = new Set();
// -------------------------------------------------------------------------
// Materials and ground
// -------------------------------------------------------------------------
const groundMat = material(0xcfd8d3);
const baseMat = material(0x53656b);
const baseEdgeMat = material(0x738388);
const streetMat = material(0x76858a);
const pavingMat = material(0xbfc0b5);
const brickMats = [
material(0xa95443),
material(0xb7624e),
material(0x984b40),
material(0xc06f56)
];
const roofMat = material(0x6e4b43);
const windowMat = material(0x263b43, { roughness: 0.35, metalness: 0.12 });
const litWindowMat = material(0xd9b86d, {
emissive: 0x7c4b13,
emissiveIntensity: 0.35
});
const woodMat = material(0x7c5437);
const darkWoodMat = material(0x4d3a2d);
const metalMat = material(0x53666a, { roughness: 0.45, metalness: 0.35 });
const leafMats = [
material(0x4f8f5b),
material(0x69a667),
material(0x3f7b50)
];
const planterMat = material(0x72584a);
const clothMats = [
material(0xe05f52),
material(0x3f91b0),
material(0xe3b84f),
material(0x686caf),
material(0xe5d8bf)
];
box(90, 0.2, 90, groundMat, 0, -0.82, 0, scene, false);
// Main architectural base and street apron.
box(14.6, 0.62, 24.9, baseMat, -3.0, -0.48, -3.25, permanentBuildings);
box(14.9, 0.12, 25.2, baseEdgeMat, -3.0, -0.13, -3.25, permanentBuildings);
box(16.4, 0.12, 4.0, streetMat, -2.8, -0.22, 8.35, permanentBuildings, false);
box(3.4, 0.18, 3.0, pavingMat, -6.0, -0.08, 7.1, permanentBuildings, false);
// Subtle street lane blocks.
const laneMat = material(0xd7d3b9);
for (let i = 0; i < 8; i++) {
box(1.05, 0.025, 0.11, laneMat, -8.8 + i * 1.7, -0.145, 8.7, scene, false);
}
// -------------------------------------------------------------------------
// Permanent voxel building shell
// -------------------------------------------------------------------------
function addBuildingSegment(x, z, width, depth, height, index) {
const brick = brickMats[index % brickMats.length];
box(
width, height, depth, brick,
x, height / 2, z,
permanentBuildings
);
// Flat voxel roof and parapet cap.
box(
width + 0.1, 0.24, depth + 0.1, roofMat,
x, height + 0.12, z,
permanentBuildings
);
const levels = [1.25, 2.65, 4.05].filter(y => y < height - 0.35);
if (width >= depth) {
const count = Math.max(1, Math.floor(width / 1.35));
const usable = width - 0.5;
for (const y of levels) {
for (const face of [-1, 1]) {
for (let i = 0; i < count; i++) {
const wx = x - usable / 2 + usable * ((i + 0.5) / count);
const wz = z + face * (depth / 2 + 0.032);
const useLit = (index + i + levels.indexOf(y)) % 11 === 0;
box(
0.34, 0.52, 0.055,
useLit ? litWindowMat : windowMat,
wx, y, wz,
permanentBuildings, false
);
}
}
}
} else {
const count = Math.max(1, Math.floor(depth / 1.35));
const usable = depth - 0.5;
for (const y of levels) {
for (const face of [-1, 1]) {
for (let i = 0; i < count; i++) {
const wz = z - usable / 2 + usable * ((i + 0.5) / count);
const wx = x + face * (width / 2 + 0.032);
const useLit = (index + i + levels.indexOf(y)) % 11 === 0;
box(
0.055, 0.52, 0.34,
useLit ? litWindowMat : windowMat,
wx, y, wz,
permanentBuildings, false
);
}
}
}
}
}
// Only the schematic graph's passages are left open in the permanent shell.
const openSides = {
1: new Set(["N", "S"]),
2: new Set(["S", "E"]),
3: new Set(["W", "N"]),
4: new Set(["S", "W"]),
5: new Set(["E", "N"]),
6: new Set(["S", "E"]),
7: new Set(["W"])
};
let buildingIndex = 0;
for (const courtNumber of Object.keys(courts)) {
const { x, z } = courts[courtNumber];
const opens = openSides[courtNumber];
// North and south.
for (const [side, sign] of [["N", -1], ["S", 1]]) {
if (opens.has(side)) {
const segmentLength = 1.85;
const offset = 1.625;
addBuildingSegment(
x - offset, z + sign * 2.45,
segmentLength, 0.88,
5.5 + random() * 3.2,
buildingIndex++
);
addBuildingSegment(
x + offset, z + sign * 2.45,
segmentLength, 0.88,
5.5 + random() * 3.2,
buildingIndex++
);
} else {
addBuildingSegment(
x, z + sign * 2.45,
4.95, 0.88,
5.5 + random() * 3.2,
buildingIndex++
);
}
}
// West and east.
for (const [side, sign] of [["W", -1], ["E", 1]]) {
if (opens.has(side)) {
const segmentLength = 1.85;
const offset = 1.625;
addBuildingSegment(
x + sign * 2.45, z - offset,
0.88, segmentLength,
5.5 + random() * 3.2,
buildingIndex++
);
addBuildingSegment(
x + sign * 2.45, z + offset,
0.88, segmentLength,
5.5 + random() * 3.2,
buildingIndex++
);
} else {
addBuildingSegment(
x + sign * 2.45, z,
0.88, 4.95,
5.5 + random() * 3.2,
buildingIndex++
);
}
}
}
// Entrance portal: permanent architecture, separate from the hypothetical link.
box(0.32, 3.5, 0.42, brickMats[1], -6.8, 1.75, 7.05, permanentBuildings);
box(0.32, 3.5, 0.42, brickMats[1], -5.2, 1.75, 7.05, permanentBuildings);
box(1.95, 0.42, 0.52, roofMat, -6.0, 3.64, 7.05, permanentBuildings);
// -------------------------------------------------------------------------
// Courtyard floors and small voxel details
// -------------------------------------------------------------------------
const floorMaterials = {};
const borderMaterials = {};
const floorMeshes = {};
const borderGroups = {};
for (const id of Object.keys(courts)) {
const { x, z } = courts[id];
const floorMat = material(0x4f9b78, {
emissive: 0x153d2e,
emissiveIntensity: 0.2
});
floorMaterials[id] = floorMat;
setMaterialTarget(floorMat, 0x4f9b78, 0x153d2e, 0.2);
floorMeshes[id] = box(
4.15, 0.18, 4.15, floorMat,
x, 0.09, z,
dynamicOverlay, false
);
const borderMat = material(0x65d6a6, {
emissive: 0x164e38,
emissiveIntensity: 0.25
});
borderMaterials[id] = borderMat;
setMaterialTarget(borderMat, 0x65d6a6, 0x164e38, 0.25);
const group = new THREE.Group();
borderGroups[id] = group;
dynamicOverlay.add(group);
box(4.28, 0.065, 0.11, borderMat, x, 0.215, z - 2.02, group, false);
box(4.28, 0.065, 0.11, borderMat, x, 0.215, z + 2.02, group, false);
box(0.11, 0.065, 4.28, borderMat, x - 2.02, 0.215, z, group, false);
box(0.11, 0.065, 4.28, borderMat, x + 2.02, 0.215, z, group, false);
}
function addTree(x, z, size = 1) {
box(
0.22 * size, 1.25 * size, 0.22 * size,
woodMat, x, 0.62 * size + 0.18, z,
permanentBuildings
);
box(
1.05 * size, 0.72 * size, 1.0 * size,
leafMats[0], x, 1.45 * size + 0.18, z,
permanentBuildings
);
box(
0.72 * size, 0.58 * size, 0.75 * size,
leafMats[1], x + 0.32 * size, 1.82 * size + 0.18, z - 0.12 * size,
permanentBuildings
);
box(
0.62 * size, 0.52 * size, 0.65 * size,
leafMats[2], x - 0.31 * size, 1.78 * size + 0.18, z + 0.16 * size,
permanentBuildings
);
}
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
permanentBuildings.add(group);
box(1.25, 0.15, 0.38, woodMat, 0, 0.55, 0, group);
box(1.25, 0.42, 0.12, woodMat, 0, 0.83, -0.16, group);
box(0.12, 0.48, 0.30, metalMat, -0.48, 0.28, 0, group);
box(0.12, 0.48, 0.30, metalMat, 0.48, 0.28, 0, group);
}
function addPlanter(x, z) {
box(0.95, 0.38, 0.95, planterMat, x, 0.35, z, permanentBuildings);
box(0.76, 0.42, 0.76, leafMats[1], x, 0.67, z, permanentBuildings);
}
// Hof 1: café arrival court.
addTree(-7.25, 3.25, 0.78);
addPlanter(-4.75, 3.25);
addBench(-4.8, 5.05, Math.PI / 2);
box(0.72, 0.13, 0.72, woodMat, -4.8, 0.85, 4.0, permanentBuildings);
box(0.13, 0.72, 0.13, metalMat, -4.8, 0.48, 4.0, permanentBuildings);
box(1.1, 0.10, 1.1, clothMats[2], -4.8, 1.42, 4.0, permanentBuildings);
// Hof 2: small gallery and seating.
for (let i = 0; i < 4; i++) {
box(
0.13, 0.78, 0.58,
clothMats[i % clothMats.length],
-7.72, 0.62, -2.1 + i * 0.76,
permanentBuildings
);
}
addBench(-5.15, -2.05, 0);
// Hof 3: central tree and planters.
addTree(0.65, -1.7, 0.94);
addPlanter(-0.9, -0.15);
addBench(1.25, -2.2, Math.PI / 2);
// Hof 4: little fountain.
box(1.3, 0.28, 1.3, metalMat, 1.15, 0.33, -7.15, permanentBuildings);
box(0.92, 0.12, 0.92, material(0x4c9eb2), 1.15, 0.52, -7.15, permanentBuildings);
box(0.18, 0.78, 0.18, metalMat, 1.15, 0.75, -7.15, permanentBuildings);
box(0.48, 0.09, 0.18, metalMat, 1.15, 1.08, -7.15, permanentBuildings);
// Hof 5: quiet court.
addTree(-7.15, -7.15, 0.88);
addBench(-4.95, -5.45, 0);
addPlanter(-5.0, -6.85);
// Hof 6: planted garden court.
addTree(-7.15, -12.35, 0.9);
addTree(-4.9, -10.65, 0.67);
addPlanter(-7.15, -10.55);
addPlanter(-4.85, -12.15);
// Hof 7: colorful hanging laundry, a recognizable courtyard detail.
box(0.09, 1.8, 0.09, metalMat, -1.45, 1.08, -12.35, permanentBuildings);
box(0.09, 1.8, 0.09, metalMat, 1.45, 1.08, -12.35, permanentBuildings);
box(3.0, 0.055, 0.055, darkWoodMat, 0, 1.9, -12.35, permanentBuildings);
for (let i = 0; i < 5; i++) {
box(
0.42, 0.66, 0.055,
clothMats[i],
-1.12 + i * 0.56, 1.54, -12.35,
permanentBuildings
);
}
// -------------------------------------------------------------------------
// Text sprites for the 3D schematic block
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, radius) {
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 textSprite(text, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = options.width ?? 512;
canvas.height = options.height ?? 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (options.background !== "transparent") {
ctx.fillStyle = options.background ?? "rgba(250,248,238,0.93)";
roundedRect(
ctx, 5, 5,
canvas.width - 10, canvas.height - 10,
options.radius ?? 20
);
ctx.fill();
}
ctx.fillStyle = options.color ?? "#203138";
ctx.font = `${options.weight ?? 800} ${options.fontSize ?? 48}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
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,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(
options.scaleX ?? 3.3,
options.scaleX
? (options.scaleX * canvas.height) / canvas.width
: 0.82,
1
);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// 3D schematic block
// -------------------------------------------------------------------------
const panelOrigin = new THREE.Vector3(7.7, 0, -1.3);
const panelMat = material(0x30474e);
const panelTopMat = material(0x405b61);
const panelEdgeMat = material(0x789097);
box(5.0, 0.72, 9.5, panelMat, panelOrigin.x, 0.08, panelOrigin.z, permanentBuildings);
box(5.08, 0.12, 9.58, panelTopMat, panelOrigin.x, 0.49, panelOrigin.z, permanentBuildings);
box(5.2, 0.08, 0.18, panelEdgeMat, panelOrigin.x, 0.58, panelOrigin.z + 4.78, permanentBuildings);
const panelTitle = textSprite("SCHEMATIC BLOCK", {
scaleX: 3.65,
fontSize: 45,
color: "#d9f5ef",
background: "rgba(35,61,67,0.92)"
});
panelTitle.position.set(panelOrigin.x, 1.2, panelOrigin.z + 3.55);
scene.add(panelTitle);
const miniPositions = {
1: new THREE.Vector3(-1.25, 0.73, 2.70),
2: new THREE.Vector3(-1.25, 0.73, 1.30),
3: new THREE.Vector3( 1.05, 0.73, 1.30),
4: new THREE.Vector3( 1.05, 0.73, -0.15),
5: new THREE.Vector3(-1.25, 0.73, -0.15),
6: new THREE.Vector3(-1.25, 0.73, -1.60),
7: new THREE.Vector3( 1.05, 0.73, -1.60)
};
for (const id of Object.keys(miniPositions)) {
miniPositions[id].add(panelOrigin);
}
const miniNodeMaterials = {};
const miniNodeMeshes = {};
const miniEdgeMaterials = {};
for (const id of Object.keys(miniPositions)) {
const p = miniPositions[id];
const mat = material(0x49c98d, {
emissive: 0x164b35,
emissiveIntensity: 0.35
});
miniNodeMaterials[id] = mat;
setMaterialTarget(mat, 0x49c98d, 0x164b35, 0.35);
miniNodeMeshes[id] = box(
0.42, 0.42, 0.42, mat,
p.x, p.y, p.z,
dynamicOverlay, false
);
const number = textSprite(String(id), {
width: 96,
height: 96,
scaleX: 0.49,
fontSize: 52,
color: "#ffffff",
background: "transparent"
});
number.position.set(p.x, p.y + 0.08, p.z);
scene.add(number);
}
// -------------------------------------------------------------------------
// Actual route overlays and mini graph
// -------------------------------------------------------------------------
const actualEdgeMaterials = {};
for (const edge of edges) {
const a = courts[edge.a];
const b = courts[edge.b];
const actualMat = material(edge.optional ? 0x28c7bd : 0x49c98d, {
emissive: edge.optional ? 0x0a554f : 0x164b35,
emissiveIntensity: 0.35
});
actualEdgeMaterials[`${edge.a}-${edge.b}`] = actualMat;
boxBetween(
a, b,
edge.optional ? 0.38 : 0.28,
0.075,
actualMat,
0.265,
dynamicOverlay
);
const miniMat = material(edge.optional ? 0x28c7bd : 0x49c98d, {
emissive: edge.optional ? 0x0a554f : 0x164b35,
emissiveIntensity: 0.35
});
miniEdgeMaterials[`${edge.a}-${edge.b}`] = miniMat;
boxBetween(
miniPositions[edge.a],
miniPositions[edge.b],
edge.optional ? 0.27 : 0.17,
0.13,
miniMat,
0.70,
dynamicOverlay
);
}
const entranceMat = material(0x49c98d, {
emissive: 0x164b35,
emissiveIntensity: 0.35
});
setMaterialTarget(entranceMat, 0x49c98d, 0x164b35, 0.35);
boxBetween(entrance, courts[1], 0.34, 0.08, entranceMat, 0.265, dynamicOverlay);
// -------------------------------------------------------------------------
// Movable closure gate. This is never part of permanentBuildings.
// -------------------------------------------------------------------------
const closureGroup = new THREE.Group();
closureGroup.visible = false;
dynamicOverlay.add(closureGroup);
const gateMat = material(0xe65e68, {
emissive: 0x8e1d28,
emissiveIntensity: 0.4
});
const gateMidZ = (courts[5].z + courts[6].z) / 2;
box(0.15, 1.6, 0.2, gateMat, -6.62, 0.98, gateMidZ, closureGroup);
box(0.15, 1.6, 0.2, gateMat, -5.38, 0.98, gateMidZ, closureGroup);
box(1.55, 0.17, 0.22, gateMat, -6.0, 1.70, gateMidZ, closureGroup);
const gateX1 = box(
1.15, 0.09, 0.12, gateMat,
-6.0, 1.02, gateMidZ,
closureGroup
);
gateX1.rotation.z = Math.PI / 4;
const gateX2 = box(
1.15, 0.09, 0.12, gateMat,
-6.0, 1.02, gateMidZ,
closureGroup
);
gateX2.rotation.z = -Math.PI / 4;
// Larger invisible hit targets around the real connector and mini connector.
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const connectorHitTargets = [];
const realHitbox = new THREE.Mesh(
new THREE.BoxGeometry(2.0, 2.2, 1.45),
hitMaterial
);
realHitbox.position.set(-6.0, 1.05, gateMidZ);
scene.add(realHitbox);
connectorHitTargets.push(realHitbox);
const miniHitbox = new THREE.Mesh(
new THREE.BoxGeometry(0.75, 0.75, 1.75),
hitMaterial
);
miniHitbox.position.set(
miniPositions[5].x,
miniPositions[5].y + 0.05,
(miniPositions[5].z + miniPositions[6].z) / 2
);
scene.add(miniHitbox);
connectorHitTargets.push(miniHitbox);
// -------------------------------------------------------------------------
// DOM court labels
// -------------------------------------------------------------------------
const labelsHost = document.getElementById("labels");
const courtLabels = {};
for (const id of Object.keys(courts)) {
const el = document.createElement("div");
el.className = "court-label";
el.innerHTML = `
<span class="pin">${id}</span>
<span class="meta">Hof ${id} · accessible</span>
`;
labelsHost.appendChild(el);
courtLabels[id] = el;
}
const connectorLabel = document.getElementById("connector-label");
// -------------------------------------------------------------------------
// Reachability and status updates
// -------------------------------------------------------------------------
function activeNeighbors(id) {
const neighbors = [];
for (const edge of edges) {
if (edge.optional && !connectorOpen) continue;
if (edge.a === id) neighbors.push(edge.b);
if (edge.b === id) neighbors.push(edge.a);
}
return neighbors;
}
function computeReachability() {
reachable = new Set([1]);
const queue = [1];
while (queue.length) {
const current = queue.shift();
for (const next of activeNeighbors(current)) {
if (!reachable.has(next)) {
reachable.add(next);
queue.push(next);
}
}
}
deadEnds = new Set();
for (const id of reachable) {
// Hof 1 is the entrance court, so it is not considered a terminal dead end.
if (id !== 1 && activeNeighbors(id).length === 1) {
deadEnds.add(id);
}
}
}
const statusColors = {
accessible: {
floor: 0x4f9b78,
border: 0x65d6a6,
emissive: 0x153d2e,
node: 0x49c98d
},
dead: {
floor: 0xc98837,
border: 0xf0b44c,
emissive: 0x56310d,
node: 0xf0ad43
},
cut: {
floor: 0x687178,
border: 0x8b9499,
emissive: 0x25292d,
node: 0x727b82
}
};
function updateState() {
computeReachability();
for (const id of Object.keys(courts)) {
const numericId = Number(id);
const isDead = deadEnds.has(numericId);
const isCut = !reachable.has(numericId);
const state = isDead ? "dead" : isCut ? "cut" : "accessible";
const colors = statusColors[state];
setMaterialTarget(
floorMaterials[id],
colors.floor,
colors.emissive,
0.2
);
setMaterialTarget(
borderMaterials[id],
colors.border,
colors.emissive,
0.28
);
setMaterialTarget(
miniNodeMaterials[id],
colors.node,
colors.emissive,
0.34
);
const label = courtLabels[id];
label.classList.toggle("dead", isDead);
label.classList.toggle("cut", isCut);
const statusText = isDead
? "dead end"
: isCut
? "no route"
: numericId === 1
? "entry · open"
: "accessible";
label.querySelector(".meta").textContent = `Hof ${id} · ${statusText}`;
}
for (const edge of edges) {
const key = `${edge.a}-${edge.b}`;
const bothReachable =
reachable.has(edge.a) && reachable.has(edge.b);
let color = 0x49c98d;
let emissive = 0x164b35;
if (edge.optional) {
color = connectorOpen ? 0x28c7bd : 0xe65e68;
emissive = connectorOpen ? 0x0a554f : 0x8e1d28;
} else if (!bothReachable) {
color = 0x727b82;
emissive = 0x24292d;
} else if (
deadEnds.has(edge.a) !== deadEnds.has(edge.b)
) {
color = 0xf0ad43;
emissive = 0x68400f;
}
setMaterialTarget(actualEdgeMaterials[key], color, emissive, 0.35);
setMaterialTarget(miniEdgeMaterials[key], color, emissive, 0.35);
}
closureGroup.visible = !connectorOpen;
const toggle = document.getElementById("connector-toggle");
const stateBadge = document.getElementById("connector-state");
const summary = document.getElementById("summary");
toggle.textContent = connectorOpen ? "Close connector" : "Reopen connector";
toggle.classList.toggle("closed", !connectorOpen);
toggle.setAttribute("aria-pressed", String(!connectorOpen));
stateBadge.textContent = connectorOpen ? "Open" : "Closed";
stateBadge.classList.toggle("closed", !connectorOpen);
connectorLabel.textContent = connectorOpen
? "Hypothetical link · open"
: "Hypothetical link · closed";
connectorLabel.classList.toggle("closed", !connectorOpen);
const deadList = [...deadEnds].sort((a, b) => a - b);
const deadText = deadList.length
? `Hof ${deadList.join(", Hof ")}`
: "none";
if (connectorOpen) {
summary.textContent =
`${reachable.size} of 7 courts accessible. ` +
`${deadText} is the terminal dead end.`;
} else {
summary.textContent =
`${reachable.size} of 7 courts accessible. ` +
`${deadText} is the terminal dead end; Hof 6–7 have no active route.`;
}
}
function toggleConnector() {
connectorOpen = !connectorOpen;
updateState();
}
document.getElementById("connector-toggle").addEventListener("click", toggleConnector);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, and touch pinch
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-0.4, 0.1, -3.0),
yaw: 0.56,
pitch: 0.77,
radius: 40
};
function updateCamera() {
const cp = Math.cos(cameraState.pitch);
const sp = Math.sin(cameraState.pitch);
camera.position.set(
cameraState.target.x + cameraState.radius * Math.sin(cameraState.yaw) * cp,
cameraState.target.y + cameraState.radius * sp,
cameraState.target.z + cameraState.radius * Math.cos(cameraState.yaw) * cp
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(-0.4, 0.1, -3.0);
cameraState.yaw = 0.56;
cameraState.pitch = 0.77;
cameraState.radius = 40;
}
document.getElementById("reset-camera").addEventListener("click", resetCamera);
const pointers = new Map();
let dragDistance = 0;
let multiTouchUsed = false;
let dragMode = "rotate";
function pointerMetrics() {
const values = [...pointers.values()];
if (!values.length) return { distance: 0, midX: 0, midY: 0 };
if (values.length === 1) {
return {
distance: 0,
midX: values[0].x,
midY: values[0].y
};
}
return {
distance: Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
),
midX: (values[0].x + values[1].x) / 2,
midY: (values[0].y + values[1].y) / 2
};
}
function panCamera(dx, dy) {
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.00125;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -12, 12);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -18, 14);
cameraState.target.y = THREE.MathUtils.clamp(cameraState.target.y, -1, 6);
}
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function isConnectorUnderPointer(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);
return raycaster.intersectObjects(connectorHitTargets, true).length > 0;
}
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragDistance = 0;
multiTouchUsed = false;
dragMode =
event.pointerType === "mouse" &&
(event.button === 2 || event.shiftKey)
? "pan"
: "rotate";
} else {
multiTouchUsed = true;
}
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const before = pointerMetrics();
previous.x = event.clientX;
previous.y = event.clientY;
const after = pointerMetrics();
if (pointers.size === 1) {
const dx = event.clientX - before.midX;
const dy = event.clientY - before.midY;
dragDistance += Math.hypot(dx, dy);
if (dragMode === "pan") {
panCamera(dx, dy);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.26,
1.38
);
}
} else if (before.distance > 0 && after.distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (before.distance / after.distance),
21,
59
);
panCamera(
after.midX - before.midX,
after.midY - before.midY
);
}
renderer.domElement.style.cursor =
isConnectorUnderPointer(event) && dragDistance < 4
? "pointer"
: dragMode === "pan"
? "grabbing"
: "grab";
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("click", event => {
if (event.button !== 0 || multiTouchUsed || dragDistance > 6) return;
if (isConnectorUnderPointer(event)) {
toggleConnector();
}
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
21,
59
);
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLButtonElement) return;
if (event.key.toLowerCase() === "c") {
toggleConnector();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Project DOM labels and animate material transitions
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function positionLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.18 &&
Math.abs(projected.y) < 1.18;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const screenX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const screenY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${screenX}px`;
element.style.top = `${screenY}px`;
}
function animate() {
requestAnimationFrame(animate);
updateCamera();
for (const mat of animatedMaterials) {
if (!mat.userData.targetColor) continue;
mat.color.lerp(mat.userData.targetColor, 0.13);
mat.emissive.lerp(mat.userData.targetEmissive, 0.13);
mat.emissiveIntensity +=
(mat.userData.targetIntensity - mat.emissiveIntensity) * 0.13;
}
gateMat.emissiveIntensity =
0.38 + Math.sin(performance.now() * 0.004) * 0.12;
for (const id of Object.keys(courts)) {
const p = courts[id];
positionLabel(courtLabels[id], p.x, 0.72, p.z);
}
positionLabel(
connectorLabel,
-6.0,
connectorOpen ? 1.9 : 2.1,
gateMidZ
);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateState();
updateCamera();
renderer.render(scene, camera);
document.getElementById("loading").classList.add("hidden");
animate();
</script>
</body>
</html>
```