Prompt specification
Build or customize the Three.js 3D scene "Courtyard house with connected air paths" 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: Courtyard house with connected air paths
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-house-with-connected-air-paths-x2191
Scene Description Prompt:
Trace connected air paths through a voxel courtyard house's shaded openings, rooms, and high vents under a simplified wind condition. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (courtyard-house-with-connected-air-paths-x2191):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Air Trace — Voxel Courtyard House</title>
<style>
:root {
--ink: #18312d;
--muted: #657773;
--paper: rgba(248, 250, 246, 0.9);
--line: rgba(29, 61, 55, 0.13);
--teal: #138d80;
--amber: #e69a4d;
--indigo: #6878d6;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ede7;
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; }
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.68);
box-shadow: 0 16px 45px rgba(32, 58, 51, 0.12);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
header {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
height: 62px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 18px;
border-radius: 17px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
border-radius: 10px;
display: grid;
place-items: center;
background: #193d36;
color: #e9fff8;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand h1 {
margin: 0;
font-size: 15px;
line-height: 1.1;
letter-spacing: .08em;
text-transform: uppercase;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: .04em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.status {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border-radius: 999px;
background: rgba(255,255,255,.62);
font-size: 10px;
font-weight: 750;
letter-spacing: .12em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #18a57f;
box-shadow: 0 0 0 4px rgba(24,165,127,.12);
animation: pulse 2s infinite;
}
@keyframes pulse {
50% { box-shadow: 0 0 0 7px rgba(24,165,127,0); }
}
.panel {
position: fixed;
z-index: 10;
top: 98px;
left: 20px;
width: 304px;
max-height: calc(100vh - 122px);
overflow: auto;
border-radius: 20px;
padding: 18px;
scrollbar-width: thin;
}
.section + .section {
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.eyebrow {
margin-bottom: 6px;
color: #82908b;
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
h2 {
margin: 0 0 14px;
font-size: 16px;
letter-spacing: -.01em;
}
.control-head {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 8px;
font-size: 12px;
}
.control-head output {
font-variant-numeric: tabular-nums;
font-weight: 750;
color: #276d63;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0 13px;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(90deg, #2a8d7f 0%, #2a8d7f 55%, #d7dfda 55%);
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid #fff;
border-radius: 50%;
background: #208b7c;
box-shadow: 0 2px 7px rgba(20, 80, 69, .28);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #fff;
border-radius: 50%;
background: #208b7c;
box-shadow: 0 2px 7px rgba(20, 80, 69, .28);
cursor: pointer;
}
.wind-summary {
display: flex;
align-items: center;
gap: 12px;
padding: 12px;
margin: 3px 0 14px;
border-radius: 14px;
background: rgba(225, 237, 231, .78);
}
.compass {
position: relative;
flex: 0 0 auto;
width: 44px;
height: 44px;
border: 1px solid rgba(30, 91, 79, .15);
border-radius: 50%;
background: rgba(255,255,255,.64);
}
.compass::before {
content: "N";
position: absolute;
top: 2px;
left: 18px;
color: #72827e;
font-size: 8px;
font-weight: 800;
}
#windNeedle {
position: absolute;
left: 19px;
top: 10px;
width: 2px;
height: 24px;
border-radius: 2px;
background: #188b7c;
transform-origin: 50% 12px;
transition: transform .15s ease;
}
#windNeedle::before {
content: "";
position: absolute;
top: -1px;
left: -3px;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 7px solid #188b7c;
}
.wind-summary strong {
display: block;
font-size: 12px;
margin-bottom: 3px;
}
.wind-summary span {
display: block;
color: var(--muted);
font-size: 10px;
}
.button-row {
display: flex;
gap: 8px;
}
button {
border: 1px solid rgba(30, 71, 63, .13);
border-radius: 10px;
background: rgba(255,255,255,.72);
padding: 9px 11px;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background .15s, transform .15s;
}
button:hover { background: #fff; }
button:active { transform: translateY(1px); }
button.primary {
flex: 1;
border-color: transparent;
background: #1d5047;
color: #f4fffb;
}
button.primary:hover { background: #28665b; }
.route {
margin-top: 12px;
}
.route-head {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
font-size: 11px;
}
.route-dot {
width: 8px;
height: 8px;
border-radius: 50%;
flex: 0 0 auto;
}
.route-name {
flex: 1;
font-weight: 700;
}
.route-flow {
color: #5d706b;
font-variant-numeric: tabular-nums;
font-size: 10px;
}
.meter {
height: 4px;
margin-left: 16px;
overflow: hidden;
border-radius: 99px;
background: rgba(31, 66, 58, .08);
}
.meter i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width .25s ease;
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
padding: 7px 0;
font-size: 11px;
color: #526560;
cursor: pointer;
}
.toggle input {
width: 31px;
height: 17px;
appearance: none;
border-radius: 99px;
background: #cbd5d0;
position: relative;
cursor: pointer;
transition: background .18s;
}
.toggle input::after {
content: "";
position: absolute;
width: 13px;
height: 13px;
left: 2px;
top: 2px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0,0,0,.18);
transition: transform .18s;
}
.toggle input:checked { background: #278e7f; }
.toggle input:checked::after { transform: translateX(14px); }
.legend {
position: fixed;
z-index: 9;
right: 20px;
bottom: 20px;
width: 238px;
padding: 14px 16px;
border-radius: 16px;
font-size: 10px;
color: #536661;
}
.legend-title {
margin-bottom: 10px;
color: #7a8a85;
font-size: 9px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
}
.legend-line {
width: 25px;
height: 3px;
border-radius: 5px;
}
.legend-square {
width: 13px;
height: 13px;
border-radius: 3px;
background: #d8cfbf;
border: 1px solid rgba(73,66,52,.12);
}
.legend-screen {
width: 13px;
height: 13px;
border-radius: 3px;
background: repeating-linear-gradient(
0deg, #3e6d65 0 2px, #dce8e3 2px 4px
);
}
.viewbar {
position: fixed;
z-index: 10;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
display: flex;
gap: 4px;
padding: 5px;
border-radius: 14px;
}
.viewbar button {
border: 0;
background: transparent;
padding: 8px 11px;
color: #62736e;
font-size: 10px;
}
.viewbar button.active {
background: rgba(34, 84, 75, .1);
color: #235d53;
}
.hint {
position: fixed;
z-index: 8;
right: 20px;
top: 98px;
padding: 8px 10px;
border-radius: 9px;
background: rgba(248,250,246,.72);
border: 1px solid rgba(255,255,255,.55);
color: #6f7f7a;
font-size: 9px;
letter-spacing: .04em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #e8ede7;
transition: opacity .45s, visibility .45s;
}
#loading.hidden { opacity: 0; visibility: hidden; }
.loader {
display: flex;
align-items: center;
gap: 12px;
color: #42675f;
font-size: 12px;
font-weight: 700;
letter-spacing: .08em;
}
.spinner {
width: 24px;
height: 24px;
border: 3px solid rgba(39,117,104,.16);
border-top-color: #277d70;
border-radius: 50%;
animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 760px) {
header {
top: 10px;
left: 10px;
right: 10px;
height: 54px;
padding: 0 12px;
}
.brand p, .status span { display: none; }
.status { padding: 9px; }
.panel {
top: 76px;
left: 10px;
width: min(292px, calc(100vw - 20px));
max-height: 48vh;
padding: 15px;
}
.hint, .legend { display: none; }
.viewbar {
bottom: 10px;
white-space: nowrap;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="glass">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M3 8h11c3.8 0 3.8-5 0-5-2 0-3 1.3-3 3"
stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/>
<path d="M3 12h16M3 16h9c3.8 0 3.8 5 0 5-2 0-3-1.3-3-3"
stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/>
</svg>
</div>
<div>
<h1>Air Trace</h1>
<p>Voxel courtyard house · connected ventilation study</p>
</div>
</div>
<div class="status">
<i class="status-dot"></i>
<span>Simulation live</span>
</div>
</header>
<aside class="panel glass">
<section class="section">
<div class="eyebrow">01 / Wind condition</div>
<h2>Simplified steady wind</h2>
<div class="wind-summary">
<div class="compass" aria-hidden="true"><i id="windNeedle"></i></div>
<div>
<strong id="windBearingLabel">East · 090°</strong>
<span id="windVectorLabel">1.00 → 0.00 horizontal flow</span>
</div>
</div>
<div class="control-head">
<label for="windSpeed">Wind speed</label>
<output id="windSpeedValue">4.2 m/s</output>
</div>
<input id="windSpeed" type="range" min="0.5" max="8" step="0.1" value="4.2" />
<div class="control-head">
<label for="windBearing">Direction / bearing</label>
<output id="windBearingValue">090°</output>
</div>
<input id="windBearing" type="range" min="0" max="180" step="1" value="90" />
<div class="button-row">
<button id="pauseButton" class="primary">Pause flow</button>
<button id="resetCamera">Reset view</button>
</div>
</section>
<section class="section">
<div class="eyebrow">02 / Connected routes</div>
<h2>Traced air paths</h2>
<div class="route">
<div class="route-head">
<i class="route-dot" style="background:#138d80"></i>
<span class="route-name">West room → east high vent</span>
<span class="route-flow" id="flow0">—</span>
</div>
<div class="meter"><i id="meter0" style="background:#138d80"></i></div>
</div>
<div class="route">
<div class="route-head">
<i class="route-dot" style="background:#e69a4d"></i>
<span class="route-name">West room → north roof vent</span>
<span class="route-flow" id="flow1">—</span>
</div>
<div class="meter"><i id="meter1" style="background:#e69a4d"></i></div>
</div>
<div class="route">
<div class="route-head">
<i class="route-dot" style="background:#6878d6"></i>
<span class="route-name">West room → south roof vent</span>
<span class="route-flow" id="flow2">—</span>
</div>
<div class="meter"><i id="meter2" style="background:#6878d6"></i></div>
</div>
</section>
<section class="section">
<div class="eyebrow">03 / Layers</div>
<label class="toggle">Airflow paths<input id="airToggle" type="checkbox" checked /></label>
<label class="toggle">Shaded openings<input id="portToggle" type="checkbox" checked /></label>
<label class="toggle">Room labels<input id="labelToggle" type="checkbox" checked /></label>
<label class="toggle">Roof shell<input id="roofToggle" type="checkbox" /></label>
</section>
</aside>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Wheel to zoom</div>
<div class="legend glass">
<div class="legend-title">Model key</div>
<div class="legend-row"><i class="legend-square"></i> Voxel masonry</div>
<div class="legend-row"><i class="legend-screen"></i> Shaded louver</div>
<div class="legend-row"><i class="legend-line" style="background:#138d80"></i> Connected air route</div>
<div class="legend-row"><i class="legend-line" style="background:#f0a35b"></i> Roof / buoyancy path</div>
</div>
<nav class="viewbar glass" aria-label="Camera views">
<button class="active" data-view="axo">Axonometric</button>
<button data-view="plan">Plan</button>
<button data-view="inside">Interior</button>
</nav>
<div id="loading">
<div class="loader"><i class="spinner"></i> Building voxel airflow model</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ede7);
scene.fog = new THREE.Fog(0xe8ede7, 39, 78);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
140
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf8fff9, 0x83958b, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.1);
sun.position.set(-14, 25, 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.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc5e9e2, 0.75);
fill.position.set(16, 8, -18);
scene.add(fill);
const architecture = new THREE.Group();
const roofGroup = new THREE.Group();
const portGroup = new THREE.Group();
const labelGroup = new THREE.Group();
const airGroup = new THREE.Group();
scene.add(architecture, roofGroup, portGroup, labelGroup, airGroup);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d1c2,
roughness: 0.92
});
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and courtyard base.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({ color: 0xe0e7df, roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.03;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(60, 60, 0xb8c7bf, 0xcbd5ce);
grid.position.y = -1.01;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
addBox(
architecture,
[20.2, 0.5, 16.2],
[0, -0.76, 0],
floorMaterial
);
const floorColors = {
west: 0xcbd9d3,
east: 0xe3cbb5,
north: 0xd3d9c3,
south: 0xe2d7bd,
court: 0xaebfae
};
addBox(architecture, [4.9, .08, 14.8], [-6.65, -.47, 0],
new THREE.MeshStandardMaterial({ color: floorColors.west, roughness: 1 }));
addBox(architecture, [4.9, .08, 14.8], [6.65, -.47, 0],
new THREE.MeshStandardMaterial({ color: floorColors.east, roughness: 1 }));
addBox(architecture, [7.9, .08, 3.9], [0, -.47, -5.15],
new THREE.MeshStandardMaterial({ color: floorColors.north, roughness: 1 }));
addBox(architecture, [7.9, .08, 3.9], [0, -.47, 5.15],
new THREE.MeshStandardMaterial({ color: floorColors.south, roughness: 1 }));
addBox(architecture, [7.8, .1, 5.8], [0, -.44, 0],
new THREE.MeshStandardMaterial({ color: floorColors.court, roughness: 1 }));
// Courtyard gravel and stepping stones.
const stoneMat = new THREE.MeshStandardMaterial({
color: 0xd7d4c8,
roughness: 1
});
for (let i = 0; i < 8; i++) {
const stone = addBox(
architecture,
[0.72, 0.07, 0.52],
[-2.5 + i * 0.72, -0.34, 0.1 + Math.sin(i * .8) * 0.32],
stoneMat,
false
);
stone.rotation.y = (i % 2 ? 1 : -1) * 0.18;
}
// Voxel occupancy: one cubic meter per masonry cell.
const cells = new Set();
const key = (x, y, z) => `${x},${y},${z}`;
const addCell = (x, y, z) => cells.add(key(x, y, z));
// Exterior walls.
for (let z = -7; z <= 7; z++) {
for (let y = 0; y <= 4; y++) {
const westInletA = (z === -2 || z === -1) && (y === 0 || y === 1);
const westInletB = (z === 2 || z === 3) && (y === 1 || y === 2);
if (!westInletA && !westInletB) addCell(-9, y, z);
const eastVentA = (z === -2 || z === -1) && (y === 3 || y === 4);
const eastVentB = (z === 2 || z === 3) && (y === 3 || y === 4);
if (!eastVentA && !eastVentB) addCell(9, y, z);
}
}
for (let x = -9; x <= 9; x++) {
for (let y = 0; y <= 4; y++) {
const northWindow = (x === -2 || x === -1) && (y === 1 || y === 2);
const southWindow = (x === 0 || x === 1) && (y === 1 || y === 2);
if (!northWindow) addCell(x, y, -7);
if (!southWindow) addCell(x, y, 7);
}
}
// Interior room partitions with ground-level connecting doorways.
for (let z = -6; z <= 6; z++) {
for (let y = 0; y <= 3; y++) {
const westDoor = z >= -1 && z <= 1 && y <= 2;
const eastDoor = z >= -1 && z <= 1 && y <= 2;
if (!westDoor) addCell(-4, y, z);
if (!eastDoor) addCell(4, y, z);
}
}
for (let x = -4; x <= 4; x++) {
for (let y = 0; y <= 3; y++) {
const northDoor = x >= -1 && x <= 1 && y <= 2;
const southDoor = x >= -1 && x <= 1 && y <= 2;
if (!northDoor) addCell(x, y, -3);
if (!southDoor) addCell(x, y, 3);
}
}
function createVoxelMesh(cellList, roof = false) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: .9,
metalness: 0
});
const mesh = new THREE.InstancedMesh(geometry, material, cellList.length);
mesh.castShadow = true;
mesh.receiveShadow = true;
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
cellList.forEach((cell, i) => {
const [x, y, z] = cell.split(",").map(Number);
matrix.makeTranslation(x, y, z);
mesh.setMatrixAt(i, matrix);
if (roof) {
color.setHSL(.12, .12, .72 + ((x + z + 100) % 5) * .012);
} else {
const isExterior = Math.abs(x) === 9 || Math.abs(z) === 7;
color.setHSL(
isExterior ? .105 : .11,
isExterior ? .18 : .12,
isExterior ? .77 + ((x + z + 30) % 4) * .012
: .82 + ((x + y + z + 30) % 4) * .012
);
}
mesh.setColorAt(i, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
return mesh;
}
const wallCells = [...cells];
architecture.add(createVoxelMesh(wallCells));
// Roof cells around the open central courtyard.
const roofCells = [];
for (let x = -9; x <= 9; x++) {
for (let z = -7; z <= 7; z++) {
const sideWing = (x >= -9 && x <= -4) || (x >= 4 && x <= 9);
const northSouthWing = x >= -4 && x <= 4 &&
(z <= -3 || z >= 3);
if (!sideWing && !northSouthWing) continue;
const northVent = Math.abs(x) <= 0 && z === -6;
const southVent = Math.abs(x) <= 0 && z === 6;
if (!northVent && !southVent) roofCells.push(key(x, 5, z));
}
}
roofGroup.add(createVoxelMesh(roofCells, true));
roofGroup.visible = false;
// Small courtyard tree made from voxel clusters.
const tree = new THREE.Group();
tree.position.set(2.75, 0, 1.9);
architecture.add(tree);
const trunkMat = new THREE.MeshStandardMaterial({ color: 0x8d6c4c, roughness: 1 });
const leafMat = new THREE.MeshStandardMaterial({ color: 0x6e9270, roughness: 1 });
const leafMat2 = new THREE.MeshStandardMaterial({ color: 0x82a47b, roughness: 1 });
addBox(tree, [.35, 1.45, .35], [0, .3, 0], trunkMat);
const leaves = [
[0,1.15,0,.95], [.5,1.15,.1,.72], [-.48,1.2,.15,.78],
[.08,1.7,0,.86], [-.35,1.75,-.2,.7], [.4,1.85,.2,.7],
[0,2.25,0,.78], [.34,2.15,-.32,.63]
];
leaves.forEach((l, i) => {
addBox(tree, [l[3], l[3], l[3]], [l[0], l[1], l[2]],
i % 2 ? leafMat : leafMat2);
});
addBox(architecture, [1.45, .32, 1.45], [2.75, -.23, 1.9],
new THREE.MeshStandardMaterial({ color: 0xb7a994, roughness: 1 }));
// Shaded wall openings: recessed dark screens and teal louvers.
const recessMat = new THREE.MeshStandardMaterial({
color: 0x263f3a,
roughness: .8
});
const louverMat = new THREE.MeshStandardMaterial({
color: 0x4d7b70,
roughness: .62,
metalness: .12
});
const frameMat = new THREE.MeshStandardMaterial({
color: 0x668d82,
roughness: .65
});
function wallPort(x, z, y, width, height, facing) {
const g = new THREE.Group();
g.position.set(x, y, z);
addBox(g, [.12, height, width], [0, 0, 0], recessMat, false);
addBox(g, [.24, height + .22, .12], [0, 0, -width / 2], frameMat);
addBox(g, [.24, height + .22, .12], [0, 0, width / 2], frameMat);
addBox(g, [.24, .12, width + .12], [0, -height / 2, 0], frameMat);
addBox(g, [.24, .12, width + .12], [0, height / 2, 0], frameMat);
for (let i = 0; i < 5; i++) {
const blade = addBox(
g,
[.42, .07, width * .9],
[-.02, -height * .34 + i * height * .17, 0],
louverMat,
false
);
blade.rotation.z = -.16;
}
if (facing < 0) {
const shade = new THREE.Group();
for (let i = 0; i < 4; i++) {
addBox(
shade,
[1.2, .08, width * .95],
[-.68, .75 + i * .12, 0],
louverMat,
false
);
}
g.add(shade);
}
portGroup.add(g);
return g;
}
wallPort(-8.98, -1.5, .5, 2.0, 2.0, -1);
wallPort(-8.98, 2.5, 1.5, 2.0, 2.0, -1);
wallPort( 8.98, -1.5, 3.5, 2.0, 2.0, 1);
wallPort( 8.98, 2.5, 3.5, 2.0, 2.0, 1);
function roofPort(x, z) {
const g = new THREE.Group();
g.position.set(x, 5.5, z);
addBox(g, [2.0, .12, 1.0], [0, 0, 0], recessMat, false);
addBox(g, [.12, .28, 1.15], [-1.0, .12, 0], frameMat);
addBox(g, [.12, .28, 1.15], [ 1.0, .12, 0], frameMat);
addBox(g, [2.12, .28, .12], [0, .12, -.5], frameMat);
addBox(g, [2.12, .28, .12], [0, .12, .5], frameMat);
for (let i = 0; i < 5; i++) {
const blade = addBox(
g,
[1.9, .07, .12],
[0, .22, -.42 + i * .21],
louverMat,
false
);
blade.rotation.x = .2;
}
portGroup.add(g);
}
roofPort(0, -6);
roofPort(0, 6);
// Canvas-generated labels; no external assets or renderer addons.
function makeLabel(text, color = "#335d55", scale = 2.3) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(248,250,246,.90)";
ctx.strokeStyle = "rgba(50,83,75,.20)";
ctx.lineWidth = 3;
const r = 20;
ctx.beginPath();
ctx.moveTo(r, 4);
ctx.arcTo(508, 4, 508, 108, r);
ctx.arcTo(508, 108, 4, 108, r);
ctx.arcTo(4, 108, 4, 4, r);
ctx.arcTo(4, 4, 508, 4, r);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "700 27px Inter, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 58);
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(scale, scale * 112 / 512, 1);
sprite.renderOrder = 20;
return sprite;
}
function roomLabel(text, position, scale = 2.15) {
const label = makeLabel(text, "#4f6962", scale);
label.position.set(...position);
labelGroup.add(label);
}
roomLabel("WEST ROOM", [-6.8, .45, 0]);
roomLabel("COURTYARD", [0, .45, 0], 2.05);
roomLabel("EAST ROOM", [6.8, .45, 0]);
roomLabel("NORTH ROOM", [0, .45, -5.25]);
roomLabel("SOUTH ROOM", [0, .45, 5.25]);
const inletLabelA = makeLabel("SHADED INLET A", "#236d61", 2.5);
inletLabelA.position.set(-10.8, 2.55, -1.5);
portGroup.add(inletLabelA);
const inletLabelB = makeLabel("SHADED INLET B", "#236d61", 2.5);
inletLabelB.position.set(-10.8, 3.15, 2.5);
portGroup.add(inletLabelB);
const eastVentLabel = makeLabel("HIGH EXHAUST", "#b26c32", 2.55);
eastVentLabel.position.set(10.6, 5.25, -1.5);
portGroup.add(eastVentLabel);
const northVentLabel = makeLabel("ROOF VENT", "#b26c32", 2.05);
northVentLabel.position.set(0, 6.75, -6);
portGroup.add(northVentLabel);
const southVentLabel = makeLabel("ROOF VENT", "#5264b7", 2.05);
southVentLabel.position.set(0, 6.75, 6);
portGroup.add(southVentLabel);
// Connected route geometry. Each curve passes through an actual
// shaded opening, room doorway, courtyard, and terminating vent.
const routeDefinitions = [
{
color: 0x138d80,
points: [
[-11.8,.72,-1.5], [-8.4,.72,-1.5], [-6.5,.72,-1.5],
[-4.8,.72,-.72], [-3,.72,0], [0,.72,.78],
[3,.72,0], [4.8,.72,-.72], [6.8,.72,-1.5],
[8.35,3.35,-1.5], [9.9,3.5,-1.5]
]
},
{
color: 0xe69a4d,
points: [
[-11.8,1.72,2.5], [-8.4,1.72,2.5], [-6.5,1.72,2.5],
[-4.8,1.72,.72], [-3,1.72,0], [0,1.72,-2],
[-.15,2.35,-4], [0,5.95,-6]
]
},
{
color: 0x6878d6,
points: [
[-11.8,.72,-1.5], [-8.4,.72,-1.5], [-6.5,.72,-.72],
[-4.8,.72,0], [-2,.72,1], [0,.72,2.2],
[.15,2.35,4], [0,5.95,6]
]
}
];
const routeObjects = [];
const particleGeometry = new THREE.ConeGeometry(.095, .30, 7);
const upAxis = new THREE.Vector3(0, 1, 0);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scaleVector = new THREE.Vector3();
routeDefinitions.forEach((definition, routeIndex) => {
const curve = new THREE.CatmullRomCurve3(
definition.points.map(p => new THREE.Vector3(...p)),
false,
"centripetal",
.42
);
const color = new THREE.Color(definition.color);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 150, .055, 7, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: .26,
depthTest: false,
depthWrite: false
})
);
tube.renderOrder = 8;
airGroup.add(tube);
const core = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(180)),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: .72,
depthTest: false,
depthWrite: false
})
);
core.renderOrder = 9;
airGroup.add(core);
const particleCount = 22;
const particleMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: .94,
depthTest: false,
depthWrite: false
});
const particles = new THREE.InstancedMesh(
particleGeometry,
particleMaterial,
particleCount
);
particles.frustumCulled = false;
particles.renderOrder = 12;
airGroup.add(particles);
const start = curve.getPointAt(0);
const end = curve.getPointAt(1);
const startTangent = curve.getTangentAt(0);
const endTangent = curve.getTangentAt(1);
const startRing = new THREE.Mesh(
new THREE.TorusGeometry(.28, .035, 8, 28),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: .9,
depthTest: false
})
);
startRing.position.copy(start);
startRing.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
startTangent
);
startRing.renderOrder = 11;
airGroup.add(startRing);
const endArrow = new THREE.Mesh(
new THREE.ConeGeometry(.18, .48, 10),
new THREE.MeshBasicMaterial({
color,
depthTest: false,
transparent: true,
opacity: .95
})
);
endArrow.position.copy(end);
endArrow.quaternion.setFromUnitVectors(upAxis, endTangent);
endArrow.renderOrder = 11;
airGroup.add(endArrow);
// Junction nodes emphasize that the paths are connected networks.
definition.points.forEach((point, i) => {
if (i === 0 || i === definition.points.length - 1) return;
const node = new THREE.Mesh(
new THREE.SphereGeometry(.075, 8, 8),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: .82,
depthTest: false
})
);
node.position.set(...point);
node.renderOrder = 10;
airGroup.add(node);
});
routeObjects.push({
curve,
particles,
particleCount,
tube,
core,
flow: 0
});
});
// Wind direction arrows.
const windGroup = new THREE.Group();
scene.add(windGroup);
const windArrows = [];
const arrowPositions = [
[-12, 6.7, -5], [-12, 6.7, 0], [-12, 6.7, 5],
[-8, 8.4, -7], [-3, 8.4, -7], [3, 8.4, -7],
[8, 8.4, -5]
];
arrowPositions.forEach(p => {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(...p),
2.0,
0x4c9a8d,
.45,
.22
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = .7;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = .78;
windGroup.add(arrow);
windArrows.push(arrow);
});
// Direct camera controls implemented without Three.js addons.
const controls = {
theta: .73,
phi: .82,
radius: 30,
target: new THREE.Vector3(0, 1.0, 0)
};
const desired = {
theta: controls.theta,
phi: controls.phi,
radius: controls.radius,
target: controls.target.clone()
};
function setCameraPreset(name) {
if (name === "axo") {
desired.theta = .73;
desired.phi = .82;
desired.radius = 30;
desired.target.set(0, 1, 0);
} else if (name === "plan") {
desired.theta = 0;
desired.phi = .055;
desired.radius = 28;
desired.target.set(0, 0, 0);
} else {
desired.theta = .12;
desired.phi = 1.25;
desired.radius = 19;
desired.target.set(0, 1.65, 0);
}
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setCameraPreset(button.dataset.view));
});
const pointers = new Map();
let lastPinchDistance = 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 === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
if (event.shiftKey || event.buttons === 2) {
const panScale = desired.radius * .0014;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
desired.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -12, 12);
desired.target.y = THREE.MathUtils.clamp(desired.target.y, -1, 7);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -12, 12);
} else {
desired.theta -= dx * .006;
desired.phi = THREE.MathUtils.clamp(desired.phi - dy * .005, .06, 1.48);
}
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (lastPinchDistance / Math.max(1, distance)),
9,
52
);
}
lastPinchDistance = distance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * .001),
9,
52
);
}, { passive: false });
// Wind and flow controls.
const speedInput = document.querySelector("#windSpeed");
const bearingInput = document.querySelector("#windBearing");
const speedValue = document.querySelector("#windSpeedValue");
const bearingValue = document.querySelector("#windBearingValue");
const bearingLabel = document.querySelector("#windBearingLabel");
const vectorLabel = document.querySelector("#windVectorLabel");
const needle = document.querySelector("#windNeedle");
let windSpeed = Number(speedInput.value);
let windBearing = Number(bearingInput.value);
let paused = false;
let simulationTime = 0;
let flowValues = [0, 0, 0];
function bearingName(degrees) {
const names = ["North", "North-east", "East", "South-east",
"South", "South-west", "West", "North-west"];
return names[Math.round(degrees / 45) % 8];
}
function updateRangeFill(input) {
const percent = (Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min)) * 100;
input.style.background =
`linear-gradient(90deg, #2a8d7f 0%, #2a8d7f ${percent}%, #d7dfda ${percent}%)`;
}
function updateFlowModel() {
windSpeed = Number(speedInput.value);
windBearing = Number(bearingInput.value);
const radians = THREE.MathUtils.degToRad(windBearing);
const dir = new THREE.Vector3(
Math.sin(radians),
0,
-Math.cos(radians)
);
const sourceEfficiency = Math.max(.12, Math.sin(radians));
const northAlignment = Math.max(0, Math.cos(radians));
const southAlignment = Math.max(0, -Math.cos(radians));
const buoyancy = .22 + .035 * Math.sqrt(windSpeed);
flowValues = [
windSpeed * .105 * sourceEfficiency,
windSpeed * .060 * sourceEfficiency * (.34 + .66 * northAlignment)
+ windSpeed * .014 * buoyancy,
windSpeed * .054 * sourceEfficiency * (.34 + .66 * southAlignment)
+ windSpeed * .014 * buoyancy
];
speedValue.textContent = `${windSpeed.toFixed(1)} m/s`;
bearingValue.textContent = `${String(Math.round(windBearing)).padStart(3, "0")}°`;
bearingLabel.textContent = `${bearingName(windBearing)} · ${String(Math.round(windBearing)).padStart(3, "0")}°`;
vectorLabel.textContent =
`${dir.x.toFixed(2)} → ${(-dir.z).toFixed(2)} horizontal flow`;
needle.style.transform = `rotate(${windBearing}deg)`;
updateRangeFill(speedInput);
updateRangeFill(bearingInput);
windArrows.forEach(arrow => arrow.setDirection(dir));
const arrowScale = .72 + Math.min(windSpeed, 8) * .055;
windGroup.scale.setScalar(arrowScale);
const maxFlow = Math.max(...flowValues, .001);
flowValues.forEach((flow, i) => {
document.querySelector(`#flow${i}`).textContent = `${flow.toFixed(2)} m³/s`;
document.querySelector(`#meter${i}`).style.width =
`${Math.max(4, flow / maxFlow * 100)}%`;
routeObjects[i].flow = flow;
});
}
speedInput.addEventListener("input", updateFlowModel);
bearingInput.addEventListener("input", updateFlowModel);
document.querySelector("#pauseButton").addEventListener("click", event => {
paused = !paused;
event.currentTarget.textContent = paused ? "Resume flow" : "Pause flow";
document.querySelector(".status-dot").style.animationPlayState =
paused ? "paused" : "running";
});
document.querySelector("#resetCamera").addEventListener("click", () => {
setCameraPreset("axo");
});
document.querySelector("#airToggle").addEventListener("change", event => {
airGroup.visible = event.target.checked;
});
document.querySelector("#portToggle").addEventListener("change", event => {
portGroup.visible = event.target.checked;
});
document.querySelector("#labelToggle").addEventListener("change", event => {
labelGroup.visible = event.target.checked;
});
document.querySelector("#roofToggle").addEventListener("change", event => {
roofGroup.visible = event.target.checked;
});
updateFlowModel();
setCameraPreset("axo");
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), .05);
if (!paused) simulationTime += dt;
controls.theta += (desired.theta - controls.theta) * .09;
controls.phi += (desired.phi - controls.phi) * .09;
controls.radius += (desired.radius - controls.radius) * .09;
controls.target.lerp(desired.target, .09);
camera.position.set(
controls.target.x + controls.radius *
Math.sin(controls.phi) * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius *
Math.sin(controls.phi) * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
routeObjects.forEach((route, routeIndex) => {
const efficiency = route.flow / Math.max(.01, flowValues[routeIndex]);
const travelRate = .025 + windSpeed * .020 * Math.min(1.2, efficiency);
for (let i = 0; i < route.particleCount; i++) {
const t = (simulationTime * travelRate + i / route.particleCount) % 1;
const point = route.curve.getPointAt(t);
const tangent = route.curve.getTangentAt(t).normalize();
quaternion.setFromUnitVectors(upAxis, tangent);
const size = .75 + Math.min(.45, route.flow * .12);
scaleVector.set(size, size, size);
matrix.compose(point, quaternion, scaleVector);
route.particles.setMatrixAt(i, matrix);
}
route.particles.instanceMatrix.needsUpdate = true;
const strength = THREE.MathUtils.clamp(
route.flow / Math.max(.35, windSpeed * .11),
.28,
1
);
route.tube.material.opacity = .16 + strength * .18;
route.core.material.opacity = .48 + strength * .35;
route.particles.material.opacity = .6 + strength * .4;
});
renderer.render(scene, camera);
}
animate();
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
setTimeout(() => {
document.querySelector("#loading").classList.add("hidden");
}, 350);
</script>
</body>
</html>
```