Prompt specification
Build or customize the Three.js 3D scene "Courtyard window ventilation" 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 window ventilation
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-window-ventilation-x0079
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a casement window latch. Create a small room with two operable windows and hanging ribbons; opening opposite windows produces a labeled qualitative airflow route through the occupied space. Stylized solid forms.
Working Three.js Starter (courtyard-window-ventilation-x0079):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Casement Crossflow</title>
<style>
:root {
color-scheme: light;
--ink: #21312f;
--muted: #657572;
--paper: rgba(250, 248, 241, 0.9);
--line: rgba(33, 49, 47, 0.14);
--teal: #087f78;
--teal-light: #d6efeb;
--gold: #d59a35;
--coral: #d96b55;
--shadow: 0 16px 45px rgba(27, 45, 42, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5e2;
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%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.card {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
position: fixed;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--gold);
box-shadow: 0 0 0 4px rgba(213, 154, 53, 0.14);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
line-height: 1;
letter-spacing: -0.035em;
font-weight: 780;
}
header p {
margin: 9px 0 0;
max-width: 330px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
#status {
position: fixed;
top: 24px;
right: 24px;
max-width: min(340px, calc(100vw - 48px));
padding: 12px 15px;
border-radius: 14px;
display: flex;
align-items: center;
gap: 11px;
pointer-events: none;
}
#status-dot {
flex: 0 0 auto;
width: 10px;
height: 10px;
border-radius: 50%;
background: #a6afac;
box-shadow: 0 0 0 5px rgba(166, 175, 172, 0.15);
transition: 200ms ease;
}
#status.active #status-dot {
background: var(--teal);
box-shadow: 0 0 0 5px rgba(8, 127, 120, 0.15);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% { box-shadow: 0 0 0 8px rgba(8, 127, 120, 0.03); }
}
#status-title {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#status-detail {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
#controls {
position: fixed;
right: 24px;
bottom: 24px;
width: min(336px, calc(100vw - 48px));
padding: 16px;
border-radius: 19px;
}
.control-title {
margin-bottom: 12px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--muted);
}
.window-controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 8px;
}
.window-controls + .window-controls {
padding-top: 8px;
border-top: 1px solid var(--line);
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 10px;
padding: 10px 11px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease,
color 140ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(8, 127, 120, 0.35);
background: #fff;
}
button:active { transform: translateY(0); }
button:focus-visible {
outline: 3px solid rgba(8, 127, 120, 0.25);
outline-offset: 2px;
}
button.primary {
background: var(--teal);
border-color: var(--teal);
color: white;
}
button.primary:hover { background: #076f69; }
button.latch {
color: #8a641f;
background: rgba(213, 154, 53, 0.11);
border-color: rgba(213, 154, 53, 0.26);
}
button.latch.released {
color: var(--teal);
background: var(--teal-light);
border-color: rgba(8, 127, 120, 0.22);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.camera-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 8px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.camera-row button {
padding: 8px 5px;
font-size: 11px;
}
#legend {
position: fixed;
left: 24px;
bottom: 24px;
max-width: 305px;
padding: 14px 16px;
border-radius: 15px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin: 5px 0;
color: var(--ink);
font-weight: 650;
}
.swatch {
display: inline-block;
width: 23px;
height: 4px;
border-radius: 4px;
background: var(--teal);
}
.swatch.ribbon {
width: 8px;
height: 18px;
border-radius: 2px;
background: var(--coral);
}
.note {
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid var(--line);
}
#toast {
position: fixed;
left: 50%;
bottom: 28px;
transform: translate(-50%, 18px);
max-width: min(420px, calc(100vw - 36px));
padding: 10px 15px;
border-radius: 999px;
background: rgba(27, 44, 42, 0.92);
color: white;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
font-size: 12px;
font-weight: 650;
opacity: 0;
pointer-events: none;
transition: 180ms ease;
z-index: 10;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 720px) {
header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
header p { display: none; }
#status {
top: 108px;
left: 12px;
right: auto;
max-width: calc(100vw - 24px);
}
#controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
#legend { display: none; }
.window-controls {
grid-template-columns: 1fr 1fr;
}
#toast { bottom: 286px; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional casement window crossflow scene"></div>
<header class="card">
<div class="eyebrow">Room airflow study</div>
<h1>Casement / Crossflow</h1>
<p>
Release the gold latches and open the opposite casements.
Ribbons and arrows illustrate a directional route through the occupied zone.
</p>
</header>
<div id="status" class="card" role="status" aria-live="polite">
<div id="status-dot"></div>
<div>
<div id="status-title">No through-flow</div>
<div id="status-detail">Release both latches, then open both windows.</div>
</div>
</div>
<section id="controls" class="card" aria-label="Scene controls">
<div class="control-title">Casement controls</div>
<div class="window-controls">
<button id="window-A" data-window="A">Open window A</button>
<button id="latch-A" class="latch" data-latch="A">Release latch A</button>
</div>
<div class="window-controls">
<button id="window-B" data-window="B">Open window B</button>
<button id="latch-B" class="latch" data-latch="B">Release latch B</button>
</div>
<div class="button-row">
<button id="open-both" class="primary">Open both</button>
<button id="reset">Reset</button>
</div>
<div class="camera-row" aria-label="Camera views">
<button data-camera="overview">Room</button>
<button data-camera="A">Latch A</button>
<button data-camera="B">Latch B</button>
</div>
</section>
<aside id="legend" class="card">
<div class="legend-row">
<span class="swatch"></span>
Qualitative airflow direction
</div>
<div class="legend-row">
<span class="swatch ribbon"></span>
Hanging ribbon motion indicator
</div>
<div class="note">
Directional illustration only — not a pressure, velocity, or CFD solution.
Drag to orbit and scroll to zoom.
</div>
</aside>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const statusBox = document.getElementById("status");
const statusTitle = document.getElementById("status-title");
const statusDetail = document.getElementById("status-detail");
const toastBox = document.getElementById("toast");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5e2);
scene.fog = new THREE.Fog(0xdce5e2, 15, 25);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.08,
60
);
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.05;
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xeaf7f5, 0x87705e, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d4, 3.2);
sun.position.set(4.5, 9, 7.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 24;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.PointLight(0xbbe5df, 24, 12, 2);
fill.position.set(-1, 3.4, 1.2);
scene.add(fill);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
const materials = {
wall: standard(0xe8e2d6),
wallTrim: standard(0xf4eee3),
floor: standard(0xb99a7b),
rug: standard(0xd47c64),
frame: standard(0x315653),
frameLight: standard(0x466c67),
glass: standard(0x8ab9bd, { roughness: 0.55 }),
exterior: standard(0x9acbd0),
gold: standard(0xd69a31, {
roughness: 0.32,
metalness: 0.48,
emissive: 0x3a2100,
emissiveIntensity: 0.18
}),
sofa: standard(0x477f78),
sofaLight: standard(0x5c948c),
wood: standard(0x85634b),
dark: standard(0x273e3b),
terracotta: standard(0xbe694f),
leaf: standard(0x4e8260)
};
function box(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
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 cylinder(
radiusTop,
radiusBottom,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 24,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRectPath(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(
title,
subtitle = "",
options = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const bg = options.background ?? "rgba(250,248,241,0.94)";
const fg = options.color ?? "#21312f";
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRectPath(ctx, 10, 10, 1004, 236, 30);
ctx.fillStyle = bg;
ctx.fill();
ctx.strokeStyle = options.border ?? "rgba(33,49,47,0.15)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = fg;
ctx.font = `800 ${options.titleSize ?? 48}px system-ui, sans-serif`;
ctx.fillText(
title,
512,
subtitle ? 91 : 130,
940
);
if (subtitle) {
ctx.fillStyle = options.subtitleColor ?? "#60716e";
ctx.font = `650 ${options.subtitleSize ?? 31}px system-ui, sans-serif`;
ctx.fillText(subtitle, 512, 166, 930);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const height = options.height ?? 0.42;
sprite.scale.set(height * 3.45, height, 1);
sprite.renderOrder = 20;
return sprite;
}
// ---------------------------------------------------------------------
// Small cutaway room
// ---------------------------------------------------------------------
const roomWidth = 8.2;
const roomDepth = 6.2;
const roomHeight = 4.6;
const wallThickness = 0.22;
const openingBottom = 1.28;
const openingTop = 3.62;
const openingHalfDepth = 1.18;
box(
roomWidth,
0.2,
roomDepth,
materials.floor,
0,
-0.12,
0
);
box(
roomWidth,
roomHeight,
wallThickness,
materials.wall,
0,
roomHeight / 2,
-3.1
);
function buildSideWall(sideSign) {
const x = sideSign * 4.02;
// Below the opening.
box(
wallThickness,
openingBottom,
roomDepth,
materials.wall,
x,
openingBottom / 2,
0
);
// Above the opening.
box(
wallThickness,
roomHeight - openingTop,
roomDepth,
materials.wall,
x,
(roomHeight + openingTop) / 2,
0
);
// Solid portions toward the back and front.
const segmentDepth = 3.1 - openingHalfDepth;
box(
wallThickness,
roomHeight,
segmentDepth,
materials.wall,
x,
roomHeight / 2,
-(openingHalfDepth + segmentDepth / 2)
);
box(
wallThickness,
roomHeight,
segmentDepth,
materials.wall,
x,
roomHeight / 2,
openingHalfDepth + segmentDepth / 2
);
// Interior baseboard.
box(
0.12,
0.14,
roomDepth,
materials.wallTrim,
sideSign * 3.88,
0.09,
0
);
}
buildSideWall(-1);
buildSideWall(1);
// Back-wall trim.
box(
roomWidth,
0.14,
0.12,
materials.wallTrim,
0,
0.09,
-2.95
);
// Upper perimeter beams suggest the missing ceiling.
box(
roomWidth,
0.16,
0.2,
materials.wallTrim,
0,
4.52,
-2.96
);
box(
0.2,
0.16,
roomDepth,
materials.wallTrim,
-4.0,
4.52,
0
);
box(
0.2,
0.16,
roomDepth,
materials.wallTrim,
4.0,
4.52,
0
);
// ---------------------------------------------------------------------
// Occupied-space furnishings
// ---------------------------------------------------------------------
const rug = box(
3.35,
0.025,
2.3,
materials.rug,
0.15,
0.002,
-0.35
);
rug.castShadow = false;
// Sofa.
box(
2.75,
0.44,
0.85,
materials.sofa,
0.15,
0.34,
-2.25
);
box(
2.75,
0.82,
0.18,
materials.sofa,
0.15,
0.85,
-2.64
);
box(
0.23,
0.62,
0.95,
materials.sofaLight,
-1.26,
0.57,
-2.25
);
box(
0.23,
0.62,
0.95,
materials.sofaLight,
1.56,
0.57,
-2.25
);
for (const x of [-0.58, 0.2, 0.98]) {
box(
0.72,
0.18,
0.67,
materials.sofaLight,
x,
0.64,
-2.18
);
}
box(
0.58,
0.43,
0.16,
materials.rug,
-0.68,
1.0,
-2.46
);
// Round table.
cylinder(
0.73,
0.73,
0.09,
materials.wood,
0.15,
0.62,
-0.32,
36
);
cylinder(
0.13,
0.19,
0.52,
materials.dark,
0.15,
0.31,
-0.32,
20
);
cylinder(
0.37,
0.4,
0.06,
materials.dark,
0.15,
0.05,
-0.32,
28
);
// Small solid book on the table.
const book = box(
0.35,
0.055,
0.25,
standard(0xe2b85c),
0.3,
0.71,
-0.35
);
book.rotation.y = 0.22;
// Plant.
cylinder(
0.27,
0.22,
0.48,
materials.terracotta,
2.65,
0.25,
-2.25,
18
);
cylinder(
0.035,
0.045,
1.1,
materials.wood,
2.65,
0.93,
-2.25,
12
);
const leafGeometry = new THREE.SphereGeometry(0.24, 12, 8);
const leafPositions = [
[2.42, 1.25, -2.22, -0.5],
[2.83, 1.38, -2.28, 0.55],
[2.55, 1.6, -2.0, -0.2],
[2.91, 1.66, -2.15, 0.5],
[2.27, 1.62, -2.3, -0.65]
];
for (const [x, y, z, rz] of leafPositions) {
const leaf = new THREE.Mesh(leafGeometry, materials.leaf);
leaf.position.set(x, y, z);
leaf.scale.set(0.65, 1.25, 0.3);
leaf.rotation.z = rz;
leaf.rotation.x = 0.3;
leaf.castShadow = true;
scene.add(leaf);
}
// Framed geometric artwork.
box(
1.8,
1.28,
0.12,
materials.wood,
0.2,
2.75,
-2.9
);
box(
1.58,
1.06,
0.035,
standard(0xe8c879),
0.2,
2.75,
-2.82
);
box(
0.42,
0.78,
0.04,
materials.rug,
-0.12,
2.72,
-2.78
);
const sunShape = new THREE.Mesh(
new THREE.CylinderGeometry(0.26, 0.26, 0.035, 24),
materials.terracotta
);
sunShape.rotation.x = Math.PI / 2;
sunShape.position.set(0.57, 2.94, -2.77);
scene.add(sunShape);
// ---------------------------------------------------------------------
// Casement windows and gold latches
// ---------------------------------------------------------------------
const states = {
A: {
key: "A",
side: "left",
open: false,
locked: true,
angle: 0,
targetAngle: 0,
latchAngle: 0,
targetLatch: 0,
sash: null,
handlePivot: null
},
B: {
key: "B",
side: "right",
open: false,
locked: true,
angle: 0,
targetAngle: 0,
latchAngle: 0,
targetLatch: 0,
sash: null,
handlePivot: null
}
};
const interactiveObjects = [];
function createCasement(key, side) {
const sideSign = side === "left" ? -1 : 1;
const extensionSign = sideSign === -1 ? 1 : -1;
const frameX = sideSign * 3.9;
const sashX = sideSign * 3.82;
const hingeZ = -extensionSign * 1.04;
const sashWidth = 2.08;
const sashHeight = 2.1;
const sashCenterZ = extensionSign * sashWidth / 2;
// Fixed frame around the wall opening.
box(
0.18,
2.42,
0.14,
materials.frame,
frameX,
2.45,
-1.19
);
box(
0.18,
2.42,
0.14,
materials.frame,
frameX,
2.45,
1.19
);
box(
0.18,
0.14,
2.52,
materials.frame,
frameX,
1.24,
0
);
box(
0.18,
0.14,
2.52,
materials.frame,
frameX,
3.66,
0
);
// Interior sill.
box(
0.45,
0.09,
2.58,
materials.frameLight,
sideSign * 3.78,
1.2,
0
);
// Opaque stylized sky beyond the opening.
box(
0.07,
2.3,
2.3,
materials.exterior,
sideSign * 4.27,
2.45,
0
);
const sash = new THREE.Group();
sash.position.set(sashX, 2.45, hingeZ);
sash.userData.windowKey = key;
scene.add(sash);
// Opaque inset pane.
const pane = box(
0.055,
sashHeight - 0.16,
sashWidth - 0.16,
materials.glass,
0,
0,
sashCenterZ,
sash
);
pane.userData.windowKey = key;
// Sash perimeter.
box(
0.11,
0.11,
sashWidth + 0.08,
materials.frameLight,
0,
-sashHeight / 2,
sashCenterZ,
sash
);
box(
0.11,
0.11,
sashWidth + 0.08,
materials.frameLight,
0,
sashHeight / 2,
sashCenterZ,
sash
);
box(
0.11,
sashHeight,
0.1,
materials.frameLight,
0,
0,
0,
sash
);
box(
0.11,
sashHeight,
0.1,
materials.frameLight,
0,
0,
extensionSign * sashWidth,
sash
);
// Solid muntins.
box(
0.14,
sashHeight - 0.1,
0.065,
materials.frame,
0,
0,
sashCenterZ,
sash
);
box(
0.14,
0.065,
sashWidth - 0.08,
materials.frame,
0,
0,
sashCenterZ,
sash
);
// Latch handle on the room-facing side of the sash.
const innerX = sideSign === -1 ? 0.13 : -0.13;
const handlePivot = new THREE.Group();
handlePivot.position.set(
innerX,
0.04,
extensionSign * (sashWidth - 0.18)
);
sash.add(handlePivot);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.085, 0.08, 18),
materials.gold
);
base.rotation.z = Math.PI / 2;
base.castShadow = true;
base.userData.action = { type: "latch", key };
handlePivot.add(base);
const leverPivot = new THREE.Group();
leverPivot.userData.action = { type: "latch", key };
handlePivot.add(leverPivot);
const lever = box(
0.08,
0.3,
0.075,
materials.gold,
0,
-0.11,
0,
leverPivot
);
lever.userData.action = { type: "latch", key };
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.018, 8, 24),
materials.gold
);
ring.rotation.y = Math.PI / 2;
ring.position.x = sideSign === -1 ? 0.04 : -0.04;
ring.userData.action = { type: "latch", key };
handlePivot.add(ring);
interactiveObjects.push(base, lever, ring);
sash.traverse((object) => {
if (object.isMesh) {
object.userData.windowKey = key;
interactiveObjects.push(object);
}
});
const label = makeLabel(
`WINDOW ${key}`,
side === "left" ? "Opposite casement" : "Opposite casement",
{
height: 0.34,
titleSize: 47,
subtitleSize: 25,
background: "rgba(33,49,47,0.90)",
color: "#ffffff",
subtitleColor: "#d7e5e2",
border: "rgba(255,255,255,0.14)"
}
);
label.position.set(sideSign * 3.42, 3.98, 0.15);
scene.add(label);
const state = states[key];
state.sash = sash;
state.handlePivot = handlePivot;
state.leverPivot = leverPivot;
state.sideSign = sideSign;
}
createCasement("A", "left");
createCasement("B", "right");
// ---------------------------------------------------------------------
// Hanging ribbon indicators
// ---------------------------------------------------------------------
box(
5.55,
0.07,
0.08,
materials.wood,
0,
4.2,
0.52
);
const ribbons = [];
const ribbonColors = [
0xd96b55,
0xe1b458,
0x3d9b91,
0xd96b55,
0xe1b458,
0x3d9b91,
0xd96b55,
0xe1b458,
0x3d9b91,
0xd96b55
];
function createRibbon(baseX, color, phase) {
const segments = 10;
const positions = new Float32Array((segments + 1) * 2 * 3);
const indices = [];
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = a + 1;
const c = (i + 1) * 2;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
const mesh = new THREE.Mesh(
geometry,
standard(color, { side: THREE.DoubleSide })
);
mesh.castShadow = true;
mesh.frustumCulled = false;
scene.add(mesh);
ribbons.push({ mesh, geometry, baseX, phase, segments });
}
for (let i = 0; i < 10; i++) {
createRibbon(
-2.42 + i * 0.54,
ribbonColors[i],
i * 0.77
);
}
function updateRibbons(time, active) {
const amplitude = active ? 0.3 : 0.075;
const speed = active ? 2.35 : 0.72;
for (const ribbon of ribbons) {
const attribute = ribbon.geometry.getAttribute("position");
for (let j = 0; j <= ribbon.segments; j++) {
const t = j / ribbon.segments;
const wave = Math.sin(
time * speed + ribbon.phase + t * 5.2
);
const secondary = Math.cos(
time * speed * 0.74 + ribbon.phase + t * 4.1
);
const x =
ribbon.baseX +
wave * amplitude * t +
(active ? Math.sin(t * 2.4 + time) * 0.08 * t : 0);
const y = 4.15 - t * 2.18;
const z = 0.52 + secondary * amplitude * 0.38 * t;
const width = 0.105 * (1 - 0.15 * Math.sin(Math.PI * t));
attribute.setXYZ(j * 2, x - width / 2, y, z);
attribute.setXYZ(j * 2 + 1, x + width / 2, y, z);
}
attribute.needsUpdate = true;
ribbon.geometry.computeVertexNormals();
}
}
// ---------------------------------------------------------------------
// Qualitative airflow route
// ---------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-3.8, 1.72, 0.02),
new THREE.Vector3(-2.55, 1.6, 0.12),
new THREE.Vector3(-1.05, 1.38, -0.1),
new THREE.Vector3(0.45, 1.34, 0.14),
new THREE.Vector3(2.15, 1.55, 0.02),
new THREE.Vector3(3.8, 1.72, 0.02)
]);
const routeLineMaterial = new THREE.LineDashedMaterial({
color: 0x087f78,
dashSize: 0.17,
gapSize: 0.11,
transparent: true,
opacity: 0,
depthTest: false
});
const routeLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(
routeCurve.getPoints(90)
),
routeLineMaterial
);
routeLine.computeLineDistances();
routeLine.renderOrder = 15;
routeGroup.add(routeLine);
const routeArrows = [];
const arrowGeometry = new THREE.ConeGeometry(0.105, 0.31, 14);
const upVector = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < 8; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0x087f78,
transparent: true,
opacity: 0,
depthTest: false
});
const arrow = new THREE.Mesh(arrowGeometry, material);
arrow.renderOrder = 16;
routeGroup.add(arrow);
routeArrows.push(arrow);
}
const routeLabel = makeLabel(
"QUALITATIVE AIRFLOW ROUTE",
"IN → OCCUPIED SPACE → OUT",
{
height: 0.52,
titleSize: 43,
subtitleSize: 28,
background: "rgba(8,127,120,0.94)",
color: "#ffffff",
subtitleColor: "#d8f2ef",
border: "rgba(255,255,255,0.2)"
}
);
routeLabel.position.set(0, 2.25, 0.08);
routeGroup.add(routeLabel);
const intakeLabel = makeLabel("INTAKE", "", {
height: 0.29,
titleSize: 47,
background: "rgba(250,248,241,0.94)",
color: "#087f78"
});
intakeLabel.position.set(-3.02, 1.9, 0.05);
routeGroup.add(intakeLabel);
const exhaustLabel = makeLabel("EXHAUST", "", {
height: 0.29,
titleSize: 47,
background: "rgba(250,248,241,0.94)",
color: "#087f78"
});
exhaustLabel.position.set(3.02, 1.9, 0.05);
routeGroup.add(exhaustLabel);
const occupiedLabel = makeLabel(
"OCCUPIED SPACE",
"Furniture and activity zone",
{
height: 0.34,
titleSize: 43,
subtitleSize: 25,
background: "rgba(250,248,241,0.92)",
color: "#21312f"
}
);
occupiedLabel.position.set(0.12, 1.02, 1.35);
scene.add(occupiedLabel);
// ---------------------------------------------------------------------
// UI state and controls
// ---------------------------------------------------------------------
let toastTimer;
function showToast(message) {
toastBox.textContent = message;
toastBox.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastBox.classList.remove("visible");
}, 2200);
}
function updateUI() {
const openCount =
Number(states.A.open) + Number(states.B.open);
const crossflow = states.A.open && states.B.open;
for (const key of ["A", "B"]) {
const state = states[key];
const windowButton = document.getElementById(`window-${key}`);
const latchButton = document.getElementById(`latch-${key}`);
windowButton.textContent = state.open
? `Close window ${key}`
: `Open window ${key}`;
windowButton.setAttribute(
"aria-pressed",
String(state.open)
);
latchButton.textContent = state.locked
? `Release latch ${key}`
: `Latch ${key} released`;
latchButton.classList.toggle("released", !state.locked);
latchButton.setAttribute(
"aria-pressed",
String(!state.locked)
);
}
statusBox.classList.toggle("active", crossflow);
if (crossflow) {
statusTitle.textContent = "Crossflow active";
statusDetail.textContent =
"Opposite casements reveal a directional route through the room.";
} else if (openCount === 1) {
statusTitle.textContent = "One casement open";
statusDetail.textContent =
"No continuous through-route until both sides are open.";
} else {
statusTitle.textContent = "No through-flow";
statusDetail.textContent =
"Release both latches, then open both windows.";
}
}
function toggleWindow(key) {
const state = states[key];
if (state.open) {
state.open = false;
state.targetAngle = 0;
showToast(`Closing window ${key}`);
} else {
if (state.locked) {
showToast(`Release latch ${key} before opening the sash.`);
return;
}
state.open = true;
state.targetAngle = 0.94;
showToast(`Window ${key} opening into the room.`);
}
updateUI();
}
function toggleLatch(key) {
const state = states[key];
if (state.locked) {
state.locked = false;
state.targetLatch = Math.PI / 2;
showToast(`Latch ${key} released.`);
} else {
state.locked = true;
state.targetLatch = 0;
if (state.open) {
state.open = false;
state.targetAngle = 0;
showToast(`Closing and locking window ${key}.`);
} else {
showToast(`Latch ${key} locked.`);
}
}
updateUI();
}
function openBoth() {
for (const key of ["A", "B"]) {
const state = states[key];
state.locked = false;
state.targetLatch = Math.PI / 2;
state.open = true;
state.targetAngle = 0.94;
}
updateUI();
showToast("Both latches released — crossflow route enabled.");
}
function resetScene() {
for (const key of ["A", "B"]) {
const state = states[key];
state.open = false;
state.targetAngle = 0;
state.locked = true;
state.targetLatch = 0;
}
setCameraView("overview");
updateUI();
showToast("Windows closed and latches locked.");
}
document.querySelectorAll("[data-window]").forEach((button) => {
button.addEventListener("click", () => {
toggleWindow(button.dataset.window);
});
});
document.querySelectorAll("[data-latch]").forEach((button) => {
button.addEventListener("click", () => {
toggleLatch(button.dataset.latch);
});
});
document
.getElementById("open-both")
.addEventListener("click", openBoth);
document
.getElementById("reset")
.addEventListener("click", resetScene);
// ---------------------------------------------------------------------
// Custom camera controls, implemented without Three.js add-ons
// ---------------------------------------------------------------------
const orbitActual = {
yaw: 0.02,
pitch: 0.39,
radius: 10.9,
target: new THREE.Vector3(0, 1.65, 0)
};
const orbitDesired = {
yaw: 0.02,
pitch: 0.39,
radius: 10.9,
target: new THREE.Vector3(0, 1.65, 0)
};
let detailKey = null;
function setCameraView(view) {
if (view === "overview") {
detailKey = null;
orbitDesired.yaw = 0.02;
orbitDesired.pitch = 0.39;
orbitDesired.radius = 10.9;
orbitDesired.target.set(0, 1.65, 0);
} else {
detailKey = view;
const state = states[view];
orbitDesired.yaw = state.sideSign === -1 ? 0.62 : -0.62;
orbitDesired.pitch = 0.28;
orbitDesired.radius = 3.15;
}
}
document.querySelectorAll("[data-camera]").forEach((button) => {
button.addEventListener("click", () => {
setCameraView(button.dataset.camera);
});
});
const pointer = {
down: false,
id: null,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
moved: 0
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function pickAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x =
((clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(
interactiveObjects,
false
);
if (!hits.length) return null;
let object = hits[0].object;
while (object) {
if (object.userData.action) {
return object.userData.action;
}
if (object.userData.windowKey) {
return {
type: "window",
key: object.userData.windowKey
};
}
object = object.parent;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.id = event.pointerId;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.moved = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointer.down && event.pointerId === pointer.id) {
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.moved += Math.abs(dx) + Math.abs(dy);
orbitDesired.yaw -= dx * 0.005;
orbitDesired.pitch = THREE.MathUtils.clamp(
orbitDesired.pitch + dy * 0.004,
0.12,
1.05
);
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
} else {
const hit = pickAt(event.clientX, event.clientY);
renderer.domElement.style.cursor = hit
? "pointer"
: "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointer.down || event.pointerId !== pointer.id) return;
pointer.down = false;
if (pointer.moved < 7) {
const action = pickAt(event.clientX, event.clientY);
if (action?.type === "latch") {
toggleLatch(action.key);
} else if (action?.type === "window") {
toggleWindow(action.key);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitDesired.radius = THREE.MathUtils.clamp(
orbitDesired.radius + event.deltaY * 0.008,
2.6,
17
);
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let routeOpacity = 0;
function updateRoute(time) {
const active = states.A.open && states.B.open;
const targetOpacity = active ? 1 : 0;
routeOpacity +=
(targetOpacity - routeOpacity) *
(1 - Math.exp(-clock.getDelta() * 0));
// Use frame delta separately to keep this section deterministic.
routeOpacity = THREE.MathUtils.clamp(
routeOpacity + (targetOpacity - routeOpacity) * 0.065,
0,
1
);
if (routeOpacity > 0.005) {
routeGroup.visible = true;
} else {
routeGroup.visible = false;
}
routeLineMaterial.opacity = routeOpacity * 0.82;
for (let i = 0; i < routeArrows.length; i++) {
const arrow = routeArrows[i];
const t = (time * 0.14 + i / routeArrows.length) % 1;
const position = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t).normalize();
arrow.position.copy(position);
arrow.quaternion.setFromUnitVectors(upVector, tangent);
arrow.material.opacity = routeOpacity;
}
routeLabel.material.opacity = routeOpacity;
intakeLabel.material.opacity = routeOpacity;
exhaustLabel.material.opacity = routeOpacity;
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
const damping = 1 - Math.exp(-dt * 5.5);
for (const key of ["A", "B"]) {
const state = states[key];
state.angle +=
(state.targetAngle - state.angle) * damping;
state.latchAngle +=
(state.targetLatch - state.latchAngle) * damping;
state.sash.rotation.y = state.angle;
state.leverPivot.rotation.x =
state.latchAngle * state.sideSign;
}
const crossflowActive = states.A.open && states.B.open;
updateRibbons(time, crossflowActive);
// Route fade uses its own frame-rate-independent interpolation.
const routeTarget = crossflowActive ? 1 : 0;
routeOpacity +=
(routeTarget - routeOpacity) *
(1 - Math.exp(-dt * 5));
routeOpacity = THREE.MathUtils.clamp(routeOpacity, 0, 1);
routeGroup.visible = routeOpacity > 0.005;
routeLineMaterial.opacity = routeOpacity * 0.82;
for (let i = 0; i < routeArrows.length; i++) {
const arrow = routeArrows[i];
const t = (time * 0.14 + i / routeArrows.length) % 1;
const position = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t).normalize();
arrow.position.copy(position);
arrow.quaternion.setFromUnitVectors(upVector, tangent);
arrow.material.opacity = routeOpacity;
}
routeLabel.material.opacity = routeOpacity;
intakeLabel.material.opacity = routeOpacity;
exhaustLabel.material.opacity = routeOpacity;
// Keep a latch detail camera focused on the moving handle.
if (detailKey) {
const state = states[detailKey];
const handlePosition = new THREE.Vector3();
state.handlePivot.getWorldPosition(handlePosition);
orbitDesired.target.lerp(handlePosition, 1 - Math.exp(-dt * 7));
}
const cameraDamping = 1 - Math.exp(-dt * 8);
orbitActual.yaw +=
(orbitDesired.yaw - orbitActual.yaw) * cameraDamping;
orbitActual.pitch +=
(orbitDesired.pitch - orbitActual.pitch) * cameraDamping;
orbitActual.radius +=
(orbitDesired.radius - orbitActual.radius) * cameraDamping;
orbitActual.target.lerp(
orbitDesired.target,
cameraDamping
);
const horizontalRadius =
Math.cos(orbitActual.pitch) * orbitActual.radius;
camera.position.set(
orbitActual.target.x +
Math.sin(orbitActual.yaw) * horizontalRadius,
orbitActual.target.y +
Math.sin(orbitActual.pitch) * orbitActual.radius,
orbitActual.target.z +
Math.cos(orbitActual.yaw) * horizontalRadius
);
camera.lookAt(orbitActual.target);
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
updateUI();
animate();
</script>
</body>
</html>
```