Prompt specification
Build or customize the Three.js 3D scene "Close openings and inspect airflow connectivity" 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: Close openings and inspect airflow connectivity
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/close-openings-and-inspect-airflow-connectivity-x2192
Scene Description Prompt:
Close openings and inspect airflow connectivity. Let users open or close selected windows in a courtyard model. Recompute path connectivity and highlight stagnant zones as illustrative consequences rather than quantitative ventilation predictions. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (close-openings-and-inspect-airflow-connectivity-x2192):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Courtyard Opening Lab</title>
<style>
:root {
--ink: #173238;
--muted: #667b80;
--paper: #f4f7f5;
--panel: #fbfcfb;
--line: #dce5e2;
--teal: #159f98;
--teal-dark: #087a76;
--teal-soft: #dff4f0;
--coral: #d9675e;
--coral-soft: #f9e5e2;
--amber: #d99b35;
--amber-soft: #fff0d5;
--shadow: 0 16px 42px rgba(26, 54, 59, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
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 {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 68px minmax(0, 1fr);
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 0 22px;
background: rgba(251, 252, 251, 0.96);
border-bottom: 1px solid var(--line);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
min-width: 0;
gap: 12px;
}
.brand-mark {
position: relative;
width: 36px;
height: 36px;
flex: 0 0 auto;
border: 2px solid var(--teal);
border-radius: 9px;
background: var(--teal-soft);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--teal);
}
.brand-mark::before {
left: 8px;
right: 8px;
top: 16px;
height: 2px;
box-shadow:
0 -7px 0 var(--teal),
0 7px 0 var(--teal);
}
.brand-mark::after {
top: 8px;
bottom: 8px;
left: 16px;
width: 2px;
}
.brand-copy {
min-width: 0;
}
.brand-copy h1 {
margin: 0;
font-size: 16px;
line-height: 1.2;
letter-spacing: 0.01em;
white-space: nowrap;
}
.brand-copy p {
margin: 3px 0 0;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
}
.disclaimer-badge {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid #efd8ad;
border-radius: 999px;
color: #8a611f;
background: #fff7e8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
}
.disclaimer-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--amber);
}
.app-body {
min-height: 0;
display: grid;
grid-template-columns: 340px minmax(0, 1fr);
}
.panel {
min-height: 0;
overflow-y: auto;
padding: 18px;
background: var(--panel);
border-right: 1px solid var(--line);
z-index: 10;
scrollbar-width: thin;
scrollbar-color: #bfcfca transparent;
}
.panel-section {
padding-bottom: 20px;
margin-bottom: 20px;
border-bottom: 1px solid var(--line);
}
.panel-section:last-child {
margin-bottom: 0;
border-bottom: 0;
}
.eyebrow {
margin: 0 0 6px;
color: var(--teal-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
h2 {
margin: 0;
font-size: 19px;
letter-spacing: -0.02em;
}
.intro {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.wind-label {
display: flex;
justify-content: space-between;
align-items: center;
margin: 16px 0 8px;
font-size: 11px;
font-weight: 750;
}
.wind-label span:last-child {
color: var(--muted);
font-weight: 550;
}
.segmented {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
padding: 4px;
background: #edf2f0;
border-radius: 10px;
}
.segmented button {
padding: 8px 4px;
border: 0;
border-radius: 7px;
background: transparent;
color: var(--muted);
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: 160ms ease;
}
.segmented button:hover {
color: var(--ink);
}
.segmented button.active {
color: white;
background: var(--teal);
box-shadow: 0 3px 9px rgba(21, 159, 152, 0.22);
}
.stats {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 7px;
margin-top: 15px;
}
.stat {
min-width: 0;
padding: 11px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
}
.stat strong {
display: block;
color: var(--ink);
font-size: 19px;
line-height: 1;
}
.stat span {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 11px;
}
.section-heading h3 {
margin: 0;
font-size: 13px;
}
.count-pill {
padding: 4px 7px;
border-radius: 999px;
color: var(--teal-dark);
background: var(--teal-soft);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.opening-list {
display: grid;
gap: 6px;
}
.opening-row {
display: grid;
grid-template-columns: 28px minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
min-height: 42px;
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 9px;
background: white;
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease;
}
.opening-row:hover {
border-color: #9cc9c4;
background: #fafffd;
}
.opening-row.is-open {
border-color: #b8dfda;
background: #f3fbf9;
}
.opening-row.is-closed {
border-color: #ecd1ce;
background: #fffafa;
}
.opening-row input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch {
position: relative;
width: 27px;
height: 16px;
border-radius: 999px;
background: #c9d2cf;
transition: background 150ms ease;
}
.switch::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 10px;
height: 10px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
transition: transform 150ms ease;
}
.is-open .switch {
background: var(--teal);
}
.is-open .switch::after {
transform: translateX(11px);
}
.opening-name {
min-width: 0;
font-size: 11px;
font-weight: 700;
}
.opening-meta {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 550;
}
.role-badge {
padding: 4px 6px;
border-radius: 5px;
color: var(--muted);
background: #edf1f0;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.is-open .role-badge {
color: var(--teal-dark);
background: #dff3ef;
}
.bulk-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 10px;
}
.button {
min-height: 35px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: white;
color: var(--ink);
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: 150ms ease;
}
.button:hover {
border-color: #9cc9c4;
background: #f4fbf9;
transform: translateY(-1px);
}
.button.primary {
border-color: var(--teal);
color: white;
background: var(--teal);
}
.button.primary:hover {
background: var(--teal-dark);
}
.button.subtle {
color: var(--muted);
background: transparent;
}
.view-options {
display: grid;
gap: 8px;
}
.option-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: white;
cursor: pointer;
}
.option-copy strong {
display: block;
font-size: 11px;
}
.option-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.option-row input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle {
position: relative;
width: 34px;
height: 19px;
flex: 0 0 auto;
border-radius: 999px;
background: #cbd4d1;
transition: background 150ms ease;
}
.toggle::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
transition: transform 150ms ease;
}
.option-row input:checked + .toggle {
background: var(--teal);
}
.option-row input:checked + .toggle::after {
transform: translateX(15px);
}
.method-note {
padding: 12px;
border: 1px solid #efd8ad;
border-radius: 10px;
color: #74551f;
background: #fff8eb;
font-size: 10px;
line-height: 1.55;
}
.method-note strong {
display: block;
margin-bottom: 4px;
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dce8e6;
}
.viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
.scene-title {
position: absolute;
top: 17px;
left: 18px;
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 11px;
background: rgba(250, 253, 251, 0.84);
box-shadow: 0 7px 20px rgba(35, 66, 71, 0.08);
backdrop-filter: blur(9px);
pointer-events: none;
}
.scene-title strong {
display: block;
font-size: 12px;
}
.scene-title span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.camera-tools {
position: absolute;
top: 17px;
right: 18px;
display: flex;
gap: 6px;
padding: 5px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 10px;
background: rgba(250, 253, 251, 0.86);
box-shadow: 0 7px 20px rgba(35, 66, 71, 0.08);
backdrop-filter: blur(9px);
}
.camera-tools button {
min-height: 30px;
padding: 6px 9px;
border: 0;
border-radius: 7px;
background: transparent;
color: var(--muted);
font-size: 9px;
font-weight: 750;
cursor: pointer;
}
.camera-tools button:hover,
.camera-tools button.active {
color: var(--teal-dark);
background: var(--teal-soft);
}
.legend {
position: absolute;
left: 18px;
bottom: 18px;
display: grid;
gap: 7px;
min-width: 176px;
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 11px;
background: rgba(250, 253, 251, 0.87);
box-shadow: 0 8px 24px rgba(35, 66, 71, 0.1);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-title {
margin-bottom: 1px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 9px;
}
.legend-swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--teal);
}
.legend-swatch.no-exit {
background: var(--amber);
}
.legend-swatch.isolated {
background: var(--coral);
}
.legend-swatch.window-open {
border: 2px solid var(--teal);
background: white;
}
.legend-swatch.window-closed {
border: 2px solid var(--coral);
background: white;
}
.interaction-hint {
position: absolute;
right: 18px;
bottom: 18px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 9px;
color: var(--muted);
background: rgba(250, 253, 251, 0.82);
font-size: 9px;
line-height: 1.55;
text-align: right;
backdrop-filter: blur(8px);
pointer-events: none;
}
.interaction-hint strong {
color: var(--ink);
}
#zoneLabels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.zone-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 5px;
padding: 4px 6px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 6px;
color: #315156;
background: rgba(255, 255, 255, 0.77);
box-shadow: 0 3px 10px rgba(35, 66, 71, 0.08);
font-size: 8px;
font-weight: 800;
white-space: nowrap;
backdrop-filter: blur(4px);
}
.zone-label .zone-dot {
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--teal);
}
.zone-label.connected .zone-dot {
background: var(--teal);
}
.zone-label.no-exit .zone-dot {
background: var(--amber);
}
.zone-label.isolated .zone-dot {
background: var(--coral);
}
.tooltip {
position: absolute;
z-index: 30;
max-width: 220px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 8px;
color: var(--ink);
background: rgba(255, 255, 255, 0.94);
box-shadow: var(--shadow);
font-size: 10px;
line-height: 1.4;
pointer-events: none;
opacity: 0;
transform: translate(12px, 12px);
transition: opacity 100ms ease;
}
.tooltip.visible {
opacity: 1;
}
.tooltip strong {
display: block;
margin-bottom: 2px;
}
.tooltip span {
color: var(--muted);
}
.notice {
position: absolute;
left: 50%;
top: 18px;
padding: 9px 13px;
border: 1px solid #efd8ad;
border-radius: 9px;
color: #74551f;
background: rgba(255, 248, 235, 0.93);
font-size: 10px;
font-weight: 650;
box-shadow: 0 8px 22px rgba(35, 66, 71, 0.08);
transform: translate(-50%, -120%);
opacity: 0;
pointer-events: none;
transition: 220ms ease;
}
.notice.show {
transform: translate(-50%, 0);
opacity: 1;
}
@media (max-width: 900px) {
.app {
grid-template-rows: 60px minmax(0, 1fr);
}
.app-body {
grid-template-columns: 1fr;
grid-template-rows: minmax(350px, 58vh) minmax(0, 42vh);
}
.viewport {
grid-row: 1;
}
.panel {
grid-row: 2;
border-right: 0;
border-top: 1px solid var(--line);
}
.brand-copy p,
.disclaimer-badge,
.interaction-hint {
display: none;
}
.scene-title {
top: 12px;
left: 12px;
}
.camera-tools {
top: 12px;
right: 12px;
}
.legend {
left: 12px;
bottom: 12px;
}
}
@media (max-width: 560px) {
.topbar {
padding: 0 13px;
}
.brand-copy h1 {
font-size: 14px;
}
.header-actions .button {
display: none;
}
.scene-title span,
.legend-item:nth-last-child(-n + 2) {
display: none;
}
.camera-tools button {
padding-inline: 7px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<h1>Courtyard Opening Lab</h1>
<p>Interactive airflow connectivity study</p>
</div>
</div>
<div class="header-actions">
<span class="disclaimer-badge">Illustrative · Not CFD</span>
<button class="button" id="headerReset" type="button">Reset scenario</button>
</div>
</header>
<div class="app-body">
<aside class="panel" aria-label="Scenario controls">
<section class="panel-section">
<p class="eyebrow">Scenario</p>
<h2>Openings & connectivity</h2>
<p class="intro">
Select the windward façade, then open or close courtyard windows.
The schematic route graph updates immediately.
</p>
<div class="wind-label">
<span>Wind from</span>
<span id="windDescription">North façade</span>
</div>
<div class="segmented" id="windButtons" aria-label="Wind direction">
<button type="button" data-wind="N" class="active">North</button>
<button type="button" data-wind="E">East</button>
<button type="button" data-wind="S">South</button>
<button type="button" data-wind="W">West</button>
</div>
<div class="stats" aria-live="polite">
<div class="stat">
<strong id="openCount">12</strong>
<span>Openings</span>
</div>
<div class="stat">
<strong id="connectedCount">9/9</strong>
<span>Sectors</span>
</div>
<div class="stat">
<strong id="routeCount">27</strong>
<span>Routes</span>
</div>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<h3>Courtyard openings</h3>
<span class="count-pill" id="openingCountPill">12 open</span>
</div>
<div class="opening-list" id="openingList"></div>
<div class="bulk-actions">
<button class="button" id="openAll" type="button">Open all</button>
<button class="button" id="closeAll" type="button">Close all</button>
<button class="button subtle" id="closeOutlets" type="button">Close outlets</button>
<button class="button subtle" id="baseline" type="button">Baseline</button>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<h3>Display</h3>
</div>
<div class="view-options">
<label class="option-row">
<span class="option-copy">
<strong>Flow connections</strong>
<span>Show the active schematic route network</span>
</span>
<input id="flowToggle" type="checkbox" checked />
<span class="toggle" aria-hidden="true"></span>
</label>
<label class="option-row">
<span class="option-copy">
<strong>Stagnant zones</strong>
<span>Highlight sectors without a complete route</span>
</span>
<input id="stagnantToggle" type="checkbox" checked />
<span class="toggle" aria-hidden="true"></span>
</label>
</div>
</section>
<section class="panel-section">
<div class="method-note">
<strong>How to read this model</strong>
The courtyard is divided into nine conceptual sectors. Open windows on
the windward façade act as inlets; other open windows act as outlets.
“Stagnant” means only that no inlet-to-outlet route was found in this
simplified graph.
</div>
</section>
</aside>
<main class="viewport" id="viewport" aria-label="Interactive 3D courtyard model">
<div id="zoneLabels"></div>
<div class="scene-title">
<strong>Low-poly courtyard model</strong>
<span id="sceneSubtitle">North wind · 9 sectors · 12 controllable openings</span>
</div>
<div class="camera-tools" aria-label="Camera controls">
<button type="button" data-view="perspective" class="active">Oblique</button>
<button type="button" data-view="plan">Plan</button>
<button type="button" data-view="reset">Reset</button>
</div>
<div class="legend" aria-label="Legend">
<div class="legend-title">Schematic status</div>
<div class="legend-item">
<span class="legend-swatch"></span>
Connected route
</div>
<div class="legend-item">
<span class="legend-swatch no-exit"></span>
Reached, no open outlet
</div>
<div class="legend-item">
<span class="legend-swatch isolated"></span>
No inlet connection
</div>
<div class="legend-item">
<span class="legend-swatch window-open"></span>
Open window
</div>
<div class="legend-item">
<span class="legend-swatch window-closed"></span>
Closed window
</div>
</div>
<div class="interaction-hint">
<strong>Drag</strong> orbit · <strong>Wheel</strong> zoom<br />
<strong>Shift-drag / right-drag</strong> pan · <strong>Click</strong> a window
</div>
<div class="tooltip" id="tooltip"></div>
<div class="notice" id="notice"></div>
</main>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and application state
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const openingList = document.getElementById("openingList");
const zoneLabels = document.getElementById("zoneLabels");
const tooltip = document.getElementById("tooltip");
const notice = document.getElementById("notice");
const openCountEl = document.getElementById("openCount");
const connectedCountEl = document.getElementById("connectedCount");
const routeCountEl = document.getElementById("routeCount");
const openingCountPill = document.getElementById("openingCountPill");
const windDescription = document.getElementById("windDescription");
const sceneSubtitle = document.getElementById("sceneSubtitle");
const flowToggle = document.getElementById("flowToggle");
const stagnantToggle = document.getElementById("stagnantToggle");
const state = {
wind: "N",
openings: [],
zones: [],
edges: [],
connected: new Set(),
noExit: new Set(),
isolated: new Set(),
routeCount: 0,
hoveredOpening: null
};
const zoneNames = [
"A · NW",
"B · N",
"C · NE",
"D · W",
"E · C",
"F · E",
"G · SW",
"H · S",
"I · SE"
];
const zonePositions = [
[-5.25, -4.25],
[0, -4.25],
[5.25, -4.25],
[-5.25, 0],
[0, 0],
[5.25, 0],
[-5.25, 4.25],
[0, 4.25],
[5.25, 4.25]
];
const windNames = {
N: "North",
E: "East",
S: "South",
W: "West"
};
// -------------------------------------------------------------------------
// Three.js setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e6);
scene.fog = new THREE.Fog(0xdce8e6, 44, 82);
const camera = new THREE.PerspectiveCamera(
42,
viewport.clientWidth / viewport.clientHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "3D courtyard with clickable windows");
renderer.domElement.tabIndex = 0;
viewport.prepend(renderer.domElement);
const hemiLight = new THREE.HemisphereLight(0xf8fffd, 0x7b8d86, 2.25);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xfff6df, 3.1);
sun.position.set(-13, 24, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfe7ea, 0.85);
fill.position.set(15, 10, -15);
scene.add(fill);
const cameraState = {
target: new THREE.Vector3(0, 0.8, 0),
yaw: 0.68,
pitch: 0.69,
distance: 34,
mode: "perspective"
};
function updateCamera() {
const cosPitch = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
cameraState.distance * Math.sin(cameraState.yaw) * cosPitch,
cameraState.target.y + cameraState.distance * Math.sin(cameraState.pitch),
cameraState.target.z +
cameraState.distance * Math.cos(cameraState.yaw) * cosPitch
);
camera.lookAt(cameraState.target);
}
function setCameraView(mode) {
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === mode);
});
if (mode === "plan") {
cameraState.mode = "plan";
cameraState.target.set(0, 0, 0);
cameraState.yaw = 0;
cameraState.pitch = 1.48;
cameraState.distance = 29;
} else {
cameraState.mode = "perspective";
cameraState.target.set(0, 0.8, 0);
cameraState.yaw = 0.68;
cameraState.pitch = 0.69;
cameraState.distance = 34;
}
updateCamera();
}
// -------------------------------------------------------------------------
// Materials and low-poly helpers
// -------------------------------------------------------------------------
const materials = {
north: new THREE.MeshStandardMaterial({
color: 0xd9d2c3,
roughness: 0.93,
flatShading: true
}),
south: new THREE.MeshStandardMaterial({
color: 0xcdd8d3,
roughness: 0.94,
flatShading: true
}),
east: new THREE.MeshStandardMaterial({
color: 0xe4d8c7,
roughness: 0.95,
flatShading: true
}),
west: new THREE.MeshStandardMaterial({
color: 0xc9d7d9,
roughness: 0.92,
flatShading: true
}),
roof: new THREE.MeshStandardMaterial({
color: 0x65787b,
roughness: 0.86,
flatShading: true
}),
roofTop: new THREE.MeshStandardMaterial({
color: 0x879b9c,
roughness: 0.92,
flatShading: true
}),
frame: new THREE.MeshStandardMaterial({
color: 0x38565a,
roughness: 0.74,
flatShading: true
}),
trim: new THREE.MeshStandardMaterial({
color: 0xf2eee4,
roughness: 0.92,
flatShading: true
}),
darkWindow: new THREE.MeshStandardMaterial({
color: 0x284a51,
roughness: 0.48,
metalness: 0.08,
flatShading: true
}),
paving: new THREE.MeshStandardMaterial({
color: 0xd8ded7,
roughness: 1,
flatShading: true
}),
pavingDark: new THREE.MeshStandardMaterial({
color: 0xb7c4bd,
roughness: 1,
flatShading: true
}),
planter: new THREE.MeshStandardMaterial({
color: 0x9a785c,
roughness: 1,
flatShading: true
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x76543e,
roughness: 1,
flatShading: true
}),
foliage: new THREE.MeshStandardMaterial({
color: 0x6f9b78,
roughness: 1,
flatShading: true
}),
foliageLight: new THREE.MeshStandardMaterial({
color: 0x93b48a,
roughness: 1,
flatShading: true
}),
bench: new THREE.MeshStandardMaterial({
color: 0x98775b,
roughness: 1,
flatShading: true
})
};
function addBox(parent, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createBuilding({
width,
depth,
height,
x,
z,
material,
facade
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
addBox(group, width, height, depth, material, 0, height / 2, 0);
addBox(
group,
width + 0.35,
0.28,
depth + 0.35,
materials.roof,
0,
height + 0.08,
0
);
addBox(
group,
width - 0.55,
0.13,
depth - 0.55,
materials.roofTop,
0,
height + 0.27,
0
);
const roofUnits = facade === "N" || facade === "S" ? 5 : 3;
for (let i = 0; i < roofUnits; i++) {
const unitX =
facade === "N" || facade === "S"
? (i - (roofUnits - 1) / 2) * 3.6
: 0;
const unitZ =
facade === "E" || facade === "W"
? (i - (roofUnits - 1) / 2) * 3.2
: 0;
const unit = addBox(
group,
facade === "N" || facade === "S" ? 1.1 : 1.8,
0.65,
facade === "E" || facade === "W" ? 1.1 : 1.8,
materials.roof,
unitX,
height + 0.62,
unitZ
);
unit.rotation.y = i * 0.31;
}
scene.add(group);
return group;
}
function createDecorativeWindow(x, y, z, rotationY, width = 1.05, height = 1.35) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotationY;
addBox(group, width, height, 0.07, materials.darkWindow, 0, 0, 0.03);
addBox(group, 0.08, height + 0.18, 0.12, materials.trim, -width / 2, 0, 0.08);
addBox(group, 0.08, height + 0.18, 0.12, materials.trim, width / 2, 0, 0.08);
addBox(group, width + 0.18, 0.08, 0.12, materials.trim, 0, height / 2, 0.08);
addBox(group, width + 0.18, 0.08, 0.12, materials.trim, 0, -height / 2, 0.08);
scene.add(group);
}
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
addBox(group, 1.4, 0.42, 1.4, materials.planter, 0, 0.18, 0);
addBox(group, 1.18, 0.12, 1.18, materials.pavingDark, 0, 0.43, 0);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.18, 1.5, 6),
materials.trunk
);
trunk.position.y = 1.15;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.82, 0),
materials.foliage
);
crown.position.y = 2.15;
crown.scale.set(0.88, 1.2, 0.88);
crown.castShadow = true;
group.add(crown);
const crown2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.55, 0),
materials.foliageLight
);
crown2.position.set(0.42, 2.45, -0.08);
crown2.castShadow = true;
group.add(crown2);
scene.add(group);
}
function createBench(x, z, rotationY = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotationY;
addBox(group, 1.85, 0.16, 0.48, materials.bench, 0, 0.72, 0);
addBox(group, 1.85, 0.48, 0.13, materials.bench, 0, 1.08, -0.21);
addBox(group, 0.16, 0.65, 0.16, materials.frame, -0.68, 0.35, 0);
addBox(group, 0.16, 0.65, 0.16, materials.frame, 0.68, 0.35, 0);
scene.add(group);
}
// -------------------------------------------------------------------------
// Courtyard geometry
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
new THREE.MeshStandardMaterial({
color: 0xb8c8c2,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.22;
ground.receiveShadow = true;
scene.add(ground);
const courtyardBase = addBox(
scene,
16.45,
0.25,
14.45,
materials.paving,
0,
-0.08,
0
);
courtyardBase.castShadow = false;
// Paving seams.
for (let x = -8; x <= 8; x += 4) {
addBox(scene, 0.045, 0.025, 14, materials.pavingDark, x, 0.055, 0);
}
for (let z = -7; z <= 7; z += 3.5) {
addBox(scene, 16, 0.025, 0.045, materials.pavingDark, 0, 0.056, z);
}
createBuilding({
width: 28,
depth: 6.4,
height: 6.6,
x: 0,
z: -10.2,
material: materials.north,
facade: "N"
});
createBuilding({
width: 28,
depth: 6.4,
height: 6.1,
x: 0,
z: 10.2,
material: materials.south,
facade: "S"
});
createBuilding({
width: 6.4,
depth: 14,
height: 6.4,
x: 11.2,
z: 0,
material: materials.east,
facade: "E"
});
createBuilding({
width: 6.4,
depth: 14,
height: 5.9,
x: -11.2,
z: 0,
material: materials.west,
facade: "W"
});
// Decorative upper-floor windows.
[-10.5, -6.3, -2.1, 2.1, 6.3, 10.5].forEach((x) => {
createDecorativeWindow(x, 5.15, -6.93, 0);
createDecorativeWindow(x, 4.95, 6.93, Math.PI);
});
[-5.1, -1.7, 1.7, 5.1].forEach((z) => {
createDecorativeWindow(7.93, 5.0, z, -Math.PI / 2);
createDecorativeWindow(-7.93, 4.7, z, Math.PI / 2);
});
createTree(-6.75, -5.65, 0.72);
createTree(6.75, -5.65, 0.67);
createTree(-6.75, 5.65, 0.65);
createTree(6.75, 5.65, 0.72);
createBench(-6.65, 0, Math.PI / 2);
createBench(6.65, 0, -Math.PI / 2);
// -------------------------------------------------------------------------
// Sector tiles and labels
// -------------------------------------------------------------------------
const zoneTileGeometry = new THREE.PlaneGeometry(4.72, 3.75);
zonePositions.forEach(([x, z], index) => {
const material = new THREE.MeshBasicMaterial({
color: 0x159f98,
transparent: true,
opacity: 0.33,
depthWrite: false,
side: THREE.DoubleSide
});
const tile = new THREE.Mesh(zoneTileGeometry, material);
tile.rotation.x = -Math.PI / 2;
tile.position.set(x, 0.09, z);
tile.renderOrder = 2;
scene.add(tile);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(zoneTileGeometry),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.42
})
);
edge.rotation.copy(tile.rotation);
edge.position.copy(tile.position);
edge.position.y += 0.006;
edge.renderOrder = 3;
scene.add(edge);
const label = document.createElement("div");
label.className = "zone-label";
label.innerHTML = `<span class="zone-dot"></span>${zoneNames[index]}`;
zoneLabels.appendChild(label);
state.zones.push({
index,
position: new THREE.Vector3(x, 0.15, z),
tile,
edge,
label
});
});
// -------------------------------------------------------------------------
// Interactive openings
// -------------------------------------------------------------------------
const openingDefinitions = [
{
id: "n-0",
label: "North · West",
facade: "N",
row: 0,
col: 0,
position: [-5.25, 2.55, -6.91],
rotation: 0
},
{
id: "n-1",
label: "North · Centre",
facade: "N",
row: 0,
col: 1,
position: [0, 2.55, -6.91],
rotation: 0
},
{
id: "n-2",
label: "North · East",
facade: "N",
row: 0,
col: 2,
position: [5.25, 2.55, -6.91],
rotation: 0
},
{
id: "e-0",
label: "East · Upper",
facade: "E",
row: 0,
col: 2,
position: [7.91, 2.55, -4.25],
rotation: -Math.PI / 2
},
{
id: "e-1",
label: "East · Centre",
facade: "E",
row: 1,
col: 2,
position: [7.91, 2.55, 0],
rotation: -Math.PI / 2
},
{
id: "e-2",
label: "East · Lower",
facade: "E",
row: 2,
col: 2,
position: [7.91, 2.55, 4.25],
rotation: -Math.PI / 2
},
{
id: "s-0",
label: "South · West",
facade: "S",
row: 2,
col: 0,
position: [-5.25, 2.55, 6.91],
rotation: Math.PI
},
{
id: "s-1",
label: "South · Centre",
facade: "S",
row: 2,
col: 1,
position: [0, 2.55, 6.91],
rotation: Math.PI
},
{
id: "s-2",
label: "South · East",
facade: "S",
row: 2,
col: 2,
position: [5.25, 2.55, 6.91],
rotation: Math.PI
},
{
id: "w-0",
label: "West · Upper",
facade: "W",
row: 0,
col: 0,
position: [-7.91, 2.55, -4.25],
rotation: Math.PI / 2
},
{
id: "w-1",
label: "West · Centre",
facade: "W",
row: 1,
col: 0,
position: [-7.91, 2.55, 0],
rotation: Math.PI / 2
},
{
id: "w-2",
label: "West · Lower",
facade: "W",
row: 2,
col: 0,
position: [-7.91, 2.55, 4.25],
rotation: Math.PI / 2
}
];
const hitTargets = [];
function createOpening(definition) {
const group = new THREE.Group();
group.position.set(...definition.position);
group.rotation.y = definition.rotation;
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x315f66,
roughness: 0.38,
metalness: 0.05,
transparent: true,
opacity: 0.45,
depthWrite: false,
side: THREE.DoubleSide
});
const shutterMaterial = new THREE.MeshStandardMaterial({
color: 0x4f7678,
roughness: 0.83,
flatShading: true
});
const statusMaterial = new THREE.MeshStandardMaterial({
color: 0x159f98,
emissive: 0x0b6b66,
emissiveIntensity: 0.65,
roughness: 0.62
});
const glass = addBox(
group,
1.92,
1.88,
0.045,
glassMaterial,
0,
0,
0.02
);
glass.castShadow = false;
addBox(group, 0.12, 2.15, 0.16, materials.frame, -1.03, 0, 0.06);
addBox(group, 0.12, 2.15, 0.16, materials.frame, 1.03, 0, 0.06);
addBox(group, 2.15, 0.12, 0.16, materials.frame, 0, 1.04, 0.06);
addBox(group, 2.15, 0.12, 0.16, materials.frame, 0, -1.04, 0.06);
addBox(group, 0.07, 1.9, 0.13, materials.frame, 0, 0, 0.08);
const leftPivot = new THREE.Group();
leftPivot.position.set(-1.0, 0, 0.12);
addBox(
leftPivot,
0.86,
1.9,
0.09,
shutterMaterial,
0.43,
0,
0
);
group.add(leftPivot);
const rightPivot = new THREE.Group();
rightPivot.position.set(1.0, 0, 0.12);
addBox(
rightPivot,
0.86,
1.9,
0.09,
shutterMaterial,
-0.43,
0,
0
);
group.add(rightPivot);
addBox(
group,
2.14,
0.075,
0.1,
statusMaterial,
0,
-1.11,
0.16
);
const hitMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false
});
const hit = new THREE.Mesh(
new THREE.BoxGeometry(2.35, 2.45, 0.4),
hitMaterial
);
hit.position.z = 0.1;
group.add(hit);
scene.add(group);
const opening = {
...definition,
zoneIndex: definition.row * 3 + definition.col,
group,
leftPivot,
rightPivot,
shutterMaterial,
statusMaterial,
hit,
open: true
};
hit.userData.openingId = definition.id;
hitTargets.push(hit);
return opening;
}
state.openings = openingDefinitions.map(createOpening);
// -------------------------------------------------------------------------
// Opening list UI
// -------------------------------------------------------------------------
function openingRole(opening) {
return opening.facade === state.wind ? "Inlet" : "Outlet";
}
function buildOpeningList() {
openingList.innerHTML = "";
state.openings.forEach((opening) => {
const row = document.createElement("label");
row.className = "opening-row is-open";
row.dataset.id = opening.id;
row.innerHTML = `
<input type="checkbox" checked aria-label="${opening.label} open" />
<span class="switch" aria-hidden="true"></span>
<span class="opening-name">
${opening.label}
<span class="opening-meta">Click to toggle in model</span>
</span>
<span class="role-badge">Inlet</span>
`;
const checkbox = row.querySelector("input");
checkbox.addEventListener("change", () => {
opening.open = checkbox.checked;
updateOpeningVisual(opening);
recomputeConnectivity();
});
openingList.appendChild(row);
});
}
function updateOpeningList() {
state.openings.forEach((opening) => {
const row = openingList.querySelector(`[data-id="${opening.id}"]`);
const checkbox = row.querySelector("input");
const badge = row.querySelector(".role-badge");
row.classList.toggle("is-open", opening.open);
row.classList.toggle("is-closed", !opening.open);
checkbox.checked = opening.open;
checkbox.setAttribute(
"aria-label",
`${opening.label} ${opening.open ? "open" : "closed"}`
);
badge.textContent = openingRole(opening);
});
}
function updateOpeningVisual(opening) {
const color = opening.open ? 0x159f98 : 0xd9675e;
const emissive = opening.open ? 0x08736e : 0x7e2520;
opening.statusMaterial.color.setHex(color);
opening.statusMaterial.emissive.setHex(emissive);
opening.shutterMaterial.color.setHex(
opening.open ? 0x4d8c88 : 0x89645f
);
}
function toggleOpening(id) {
const opening = state.openings.find((item) => item.id === id);
if (!opening) return;
opening.open = !opening.open;
updateOpeningVisual(opening);
updateOpeningList();
recomputeConnectivity();
showNotice(
`${opening.label} ${opening.open ? "opened" : "closed"} — connectivity updated`
);
}
// -------------------------------------------------------------------------
// Illustrative connectivity graph
// -------------------------------------------------------------------------
function buildGraph() {
const adjacency = Array.from({ length: 9 }, () => []);
const reverse = Array.from({ length: 9 }, () => []);
const edges = [];
const addEdge = (from, to) => {
edges.push({ from, to });
adjacency[from].push(to);
reverse[to].push(from);
};
if (state.wind === "N") {
for (let col = 0; col < 3; col++) {
addEdge(col, 3 + col);
addEdge(3 + col, 6 + col);
}
} else if (state.wind === "S") {
for (let col = 0; col < 3; col++) {
addEdge(6 + col, 3 + col);
addEdge(3 + col, col);
}
} else if (state.wind === "E") {
for (let row = 0; row < 3; row++) {
addEdge(row * 3 + 2, row * 3 + 1);
addEdge(row * 3 + 1, row * 3);
}
} else if (state.wind === "W") {
for (let row = 0; row < 3; row++) {
addEdge(row * 3, row * 3 + 1);
addEdge(row * 3 + 1, row * 3 + 2);
}
}
state.edges = edges;
return { adjacency, reverse };
}
function bfs(adjacency, starts) {
const visited = new Set();
const queue = [];
starts.forEach((node) => {
if (!visited.has(node)) {
visited.add(node);
queue.push(node);
}
});
while (queue.length) {
const current = queue.shift();
adjacency[current].forEach((next) => {
if (!visited.has(next)) {
visited.add(next);
queue.push(next);
}
});
}
return visited;
}
function findPath(adjacency, start, goal) {
const queue = [start];
const visited = new Set([start]);
const previous = new Map([[start, null]]);
while (queue.length) {
const current = queue.shift();
if (current === goal) break;
for (const next of adjacency[current]) {
if (!visited.has(next)) {
visited.add(next);
previous.set(next, current);
queue.push(next);
}
}
}
if (!previous.has(goal)) return null;
const path = [];
let current = goal;
while (current !== null) {
path.push(current);
current = previous.get(current);
}
return path.reverse();
}
function classifyZones(sourceReach, sinkReach) {
state.connected.clear();
state.noExit.clear();
state.isolated.clear();
for (let index = 0; index < 9; index++) {
if (sourceReach.has(index) && sinkReach.has(index)) {
state.connected.add(index);
} else if (sourceReach.has(index)) {
state.noExit.add(index);
} else {
state.isolated.add(index);
}
}
}
function recomputeConnectivity() {
const { adjacency, reverse } = buildGraph();
const inletOpenings = state.openings.filter(
(opening) => opening.open && opening.facade === state.wind
);
const outletOpenings = state.openings.filter(
(opening) => opening.open && opening.facade !== state.wind
);
const sourceNodes = [...new Set(inletOpenings.map((o) => o.zoneIndex))];
const sinkNodes = [...new Set(outletOpenings.map((o) => o.zoneIndex))];
const sourceReach = bfs(adjacency, sourceNodes);
const sinkReach = bfs(reverse, sinkNodes);
classifyZones(sourceReach, sinkReach);
let routes = 0;
const representativeRoutes = [];
inletOpenings.forEach((inlet) => {
outletOpenings.forEach((outlet) => {
const path = findPath(adjacency, inlet.zoneIndex, outlet.zoneIndex);
if (!path) return;
routes++;
if (
!representativeRoutes.some(
(route) => route.outlet.id === outlet.id
)
) {
representativeRoutes.push({ inlet, outlet, path });
}
});
});
state.routeCount = routes;
const openCount = state.openings.filter((opening) => opening.open).length;
openCountEl.textContent = String(openCount);
connectedCountEl.textContent = `${state.connected.size}/9`;
routeCountEl.textContent = String(routes);
openingCountPill.textContent = `${openCount} open`;
updateZoneTiles();
updateFlowNetwork(representativeRoutes);
updateOpeningList();
}
function updateZoneTiles() {
state.zones.forEach((zone) => {
const connected = state.connected.has(zone.index);
const noExit = state.noExit.has(zone.index);
let color = 0x159f98;
let opacity = 0.34;
if (!stagnantToggle.checked) {
color = 0x8aa39f;
opacity = 0.16;
} else if (noExit) {
color = 0xd99b35;
opacity = 0.42;
} else if (!connected) {
color = 0xd9675e;
opacity = 0.4;
}
zone.tile.material.color.setHex(color);
zone.tile.material.opacity = opacity;
zone.label.classList.toggle("connected", connected);
zone.label.classList.toggle("no-exit", noExit);
zone.label.classList.toggle("isolated", !connected && !noExit);
});
}
// -------------------------------------------------------------------------
// Flow route visualization
// -------------------------------------------------------------------------
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const flowMaterial = new THREE.MeshBasicMaterial({
color: 0x19aaa3,
transparent: true,
opacity: 0.82,
depthWrite: false
});
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xeafffb,
transparent: true,
opacity: 0.95,
depthWrite: false
});
function clearFlowGroup() {
while (flowGroup.children.length) {
const child = flowGroup.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
flowGroup.remove(child);
}
}
function cylinderBetween(start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
if (length < 0.001) return null;
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 6),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.renderOrder = 4;
flowGroup.add(mesh);
return mesh;
}
function addArrow(start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
if (length < 0.25) return;
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.17, 0.43, 5),
arrowMaterial
);
arrow.position.copy(start).add(end).multiplyScalar(0.5);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
arrow.renderOrder = 5;
flowGroup.add(arrow);
}
function updateFlowNetwork(routes) {
clearFlowGroup();
const segmentKeys = new Set();
routes.forEach((route) => {
const points = [];
points.push(
new THREE.Vector3(
route.inlet.position[0],
0.31,
route.inlet.position[2]
)
);
route.path.forEach((zoneIndex) => {
const [x, z] = zonePositions[zoneIndex];
points.push(new THREE.Vector3(x, 0.31, z));
});
points.push(
new THREE.Vector3(
route.outlet.position[0],
0.31,
route.outlet.position[2]
)
);
for (let i = 0; i < points.length - 1; i++) {
const start = points[i];
const end = points[i + 1];
const key = [
start.x.toFixed(2),
start.z.toFixed(2),
end.x.toFixed(2),
end.z.toFixed(2)
].join("|");
if (!segmentKeys.has(key)) {
segmentKeys.add(key);
cylinderBetween(start, end, 0.055, flowMaterial);
addArrow(start, end);
}
}
});
flowGroup.visible = flowToggle.checked;
}
// -------------------------------------------------------------------------
// Camera controls, raycasting and tooltip
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragging = false;
let panning = false;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickOpening(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(hitTargets, false);
return intersections.length ? intersections[0].object : null;
}
function showTooltip(event, opening) {
const rect = viewport.getBoundingClientRect();
tooltip.innerHTML = `
<strong>${opening.label}</strong>
<span>${opening.open ? "Open" : "Closed"} · ${
opening.facade === state.wind ? "windward inlet" : "outlet"
} · click to toggle</span>
`;
tooltip.style.left = `${event.clientX - rect.left}px`;
tooltip.style.top = `${event.clientY - rect.top}px`;
tooltip.classList.add("visible");
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = {
x: event.clientX,
y: event.clientY,
button: event.button
};
dragging = true;
panning = event.button === 2 || event.shiftKey;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging && pointerDown) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 3) {
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const panScale = cameraState.distance * 0.0012;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(forward, dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-10,
10
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-10,
10
);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.22,
1.48
);
}
}
tooltip.classList.remove("visible");
return;
}
const hit = pickOpening(event);
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
if (hit) {
const opening = state.openings.find(
(item) => item.id === hit.userData.openingId
);
showTooltip(event, opening);
} else {
tooltip.classList.remove("visible");
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
pointerDown &&
Math.abs(event.clientX - pointerDown.x) +
Math.abs(event.clientY - pointerDown.y) <
6;
if (wasClick && pointerDown.button === 0 && !panning) {
const hit = pickOpening(event);
if (hit) {
toggleOpening(hit.userData.openingId);
}
}
dragging = false;
panning = false;
pointerDown = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointerleave", () => {
tooltip.classList.remove("visible");
if (!dragging) {
dragging = false;
pointerDown = null;
}
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
16,
55
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Interface actions
// -------------------------------------------------------------------------
function showNotice(message) {
notice.textContent = message;
notice.classList.add("show");
clearTimeout(showNotice.timer);
showNotice.timer = setTimeout(() => {
notice.classList.remove("show");
}, 2200);
}
document.getElementById("windButtons").addEventListener("click", (event) => {
const button = event.target.closest("button[data-wind]");
if (!button) return;
state.wind = button.dataset.wind;
document.querySelectorAll("[data-wind]").forEach((item) => {
item.classList.toggle("active", item === button);
});
windDescription.textContent = `${windNames[state.wind]} façade`;
sceneSubtitle.textContent = `${windNames[state.wind]} wind · 9 sectors · 12 controllable openings`;
recomputeConnectivity();
showNotice(`Wind direction changed to ${windNames[state.wind]}`);
});
document.getElementById("openAll").addEventListener("click", () => {
state.openings.forEach((opening) => {
opening.open = true;
updateOpeningVisual(opening);
});
recomputeConnectivity();
});
document.getElementById("closeAll").addEventListener("click", () => {
state.openings.forEach((opening) => {
opening.open = false;
updateOpeningVisual(opening);
});
recomputeConnectivity();
showNotice("All openings closed — no inlet connection remains");
});
document.getElementById("closeOutlets").addEventListener("click", () => {
state.openings.forEach((opening) => {
opening.open = opening.facade === state.wind;
updateOpeningVisual(opening);
});
recomputeConnectivity();
showNotice("All non-windward outlets closed");
});
function resetScenario() {
state.wind = "N";
state.openings.forEach((opening) => {
opening.open = true;
updateOpeningVisual(opening);
});
document.querySelectorAll("[data-wind]").forEach((item) => {
item.classList.toggle("active", item.dataset.wind === "N");
});
windDescription.textContent = "North façade";
sceneSubtitle.textContent = "North wind · 9 sectors · 12 controllable openings";
flowToggle.checked = true;
stagnantToggle.checked = true;
flowGroup.visible = true;
recomputeConnectivity();
showNotice("Baseline scenario restored");
}
document.getElementById("baseline").addEventListener("click", resetScenario);
document.getElementById("headerReset").addEventListener("click", resetScenario);
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setCameraView(button.dataset.view);
});
});
flowToggle.addEventListener("change", () => {
flowGroup.visible = flowToggle.checked;
});
stagnantToggle.addEventListener("change", updateZoneTiles);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateZoneLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
state.zones.forEach((zone) => {
projected.copy(zone.position);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
zone.label.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
zone.label.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
});
}
function animate() {
requestAnimationFrame(animate);
updateCamera();
state.openings.forEach((opening) => {
const targetLeft = opening.open ? -1.18 : 0;
const targetRight = opening.open ? 1.18 : 0;
opening.leftPivot.rotation.y = THREE.MathUtils.lerp(
opening.leftPivot.rotation.y,
targetLeft,
0.12
);
opening.rightPivot.rotation.y = THREE.MathUtils.lerp(
opening.rightPivot.rotation.y,
targetRight,
0.12
);
opening.statusMaterial.emissiveIntensity =
opening.open
? 0.5 + Math.sin(performance.now() * 0.002) * 0.12
: 0.2;
});
flowMaterial.opacity = 0.73 + Math.sin(performance.now() * 0.0025) * 0.09;
renderer.render(scene, camera);
updateZoneLabels();
}
// Initialize.
buildOpeningList();
updateOpeningList();
state.openings.forEach(updateOpeningVisual);
recomputeConnectivity();
updateCamera();
animate();
</script>
</body>
</html>
```