Prompt specification
Build or customize the Three.js 3D scene "Miniature passive ventilation house" 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: Miniature passive ventilation house
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/miniature-passive-ventilation-house-x0080
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a casement window latch. Build a cutaway home with adjustable upper and lower windows; controls change opening combinations and display separate qualitative airflow arrows without claiming a fluid-accurate simulation. Low-poly.
Working Three.js Starter (miniature-passive-ventilation-house-x0080):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Casement Window Latch — Interactive Cutaway</title>
<style>
:root {
--ink: #21312f;
--muted: #667572;
--paper: #f7f3eb;
--panel: #fffaf1;
--line: #d9d8cf;
--teal: #238b9b;
--teal-soft: #d9edef;
--orange: #d9824b;
--orange-soft: #f6e2d4;
--charcoal: #30403f;
--shadow: 0 12px 30px rgba(42, 57, 54, 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 {
display: grid;
grid-template-columns: 340px minmax(0, 1fr);
width: 100%;
height: 100dvh;
}
.panel {
position: relative;
z-index: 10;
overflow-y: auto;
padding: 26px 24px 22px;
border-right: 1px solid var(--line);
background:
radial-gradient(circle at 15% 0%, rgba(35, 139, 155, 0.08), transparent 28%),
var(--panel);
box-shadow: 8px 0 30px rgba(44, 59, 56, 0.05);
}
.eyebrow {
margin: 0 0 9px;
color: var(--teal);
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
max-width: 270px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(2rem, 4vw, 2.75rem);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro {
margin: 15px 0 23px;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.55;
}
.section {
padding: 19px 0;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 15px;
font-size: 0.74rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-weight: 600;
letter-spacing: 0;
text-transform: none;
}
.control + .control {
margin-top: 17px;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.control label {
font-size: 0.88rem;
font-weight: 750;
}
.value {
min-width: 46px;
padding: 3px 7px;
border-radius: 999px;
background: #e8ece8;
color: var(--charcoal);
font-size: 0.76rem;
font-variant-numeric: tabular-nums;
text-align: center;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0 0;
appearance: none;
border-radius: 99px;
background: linear-gradient(
to right,
var(--teal) 0%,
var(--teal) var(--fill, 0%),
#d9deda var(--fill, 0%),
#d9deda 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 19px;
height: 19px;
appearance: none;
border: 4px solid var(--panel);
border-radius: 50%;
background: var(--teal);
box-shadow: 0 1px 7px rgba(20, 65, 68, 0.32);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 4px solid var(--panel);
border-radius: 50%;
background: var(--teal);
box-shadow: 0 1px 7px rgba(20, 65, 68, 0.32);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #87928e;
font-size: 0.65rem;
}
.preset-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 17px;
}
.preset {
min-height: 42px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: #fffdf8;
font-size: 0.75rem;
font-weight: 700;
cursor: pointer;
transition: 150ms ease;
}
.preset:hover,
.preset.active {
border-color: var(--teal);
background: var(--teal-soft);
color: #176b78;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.toggle-copy strong {
display: block;
margin-bottom: 3px;
font-size: 0.86rem;
}
.toggle-copy small {
display: block;
color: var(--muted);
font-size: 0.7rem;
line-height: 1.4;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 43px;
height: 24px;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch-track {
position: absolute;
inset: 0;
border-radius: 99px;
background: #cbd2ce;
cursor: pointer;
transition: 180ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 18px;
height: 18px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.16);
content: "";
transition: 180ms ease;
}
.switch input:checked + .switch-track {
background: var(--teal);
}
.switch input:checked + .switch-track::after {
transform: translateX(19px);
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 9px;
border-radius: 8px;
background: rgba(232, 235, 229, 0.65);
color: #52605d;
font-size: 0.68rem;
font-weight: 700;
}
.legend-line {
width: 21px;
height: 3px;
border-radius: 2px;
}
.legend-line.intake {
background: var(--teal);
}
.legend-line.exhaust {
background: var(--orange);
}
.latch-card {
display: grid;
grid-template-columns: 54px 1fr;
gap: 13px;
align-items: center;
padding: 13px;
border: 1px solid #e3d8c9;
border-radius: 12px;
background: linear-gradient(135deg, #fffaf0, #f8eddf);
}
.latch-icon {
position: relative;
width: 48px;
height: 54px;
border: 2px solid #98754d;
border-radius: 7px;
background: #fffaf0;
box-shadow: inset 0 0 0 4px #ead9c1;
}
.latch-icon::before {
position: absolute;
top: 19px;
left: 19px;
width: 8px;
height: 20px;
border-radius: 4px;
background: #b78b58;
content: "";
transform: rotate(35deg);
transform-origin: center bottom;
}
.latch-copy strong {
display: block;
margin-bottom: 4px;
font-size: 0.86rem;
}
.latch-copy p {
margin: 0;
color: #786e60;
font-size: 0.7rem;
line-height: 1.45;
}
.disclaimer {
margin: 2px 0 0;
padding: 13px 14px;
border-left: 3px solid var(--orange);
border-radius: 0 8px 8px 0;
background: var(--orange-soft);
color: #76523a;
font-size: 0.69rem;
line-height: 1.5;
}
.disclaimer strong {
color: #65422c;
}
.viewport {
position: relative;
min-width: 0;
overflow: hidden;
background: #e8e2d7;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.scene-top {
position: absolute;
z-index: 3;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.scene-title {
max-width: 300px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 10px;
background: rgba(255, 252, 245, 0.76);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
}
.scene-title small {
display: block;
margin-bottom: 3px;
color: var(--teal);
font-size: 0.61rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scene-title strong {
font-size: 0.78rem;
line-height: 1.35;
}
.scene-badge {
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.66);
border-radius: 999px;
background: rgba(255, 252, 245, 0.76);
box-shadow: var(--shadow);
color: #5d6966;
font-size: 0.66rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(9px);
}
.annotation {
position: absolute;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 8px;
background: rgba(255, 252, 245, 0.87);
box-shadow: 0 7px 20px rgba(50, 66, 63, 0.12);
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(6px);
transition: opacity 120ms ease;
}
.annotation::before {
width: 7px;
height: 7px;
border: 2px solid white;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 1px var(--teal);
content: "";
}
.annotation.latch::before {
background: var(--orange);
box-shadow: 0 0 0 1px var(--orange);
}
.annotation b,
.annotation small {
display: block;
}
.annotation b {
font-size: 0.67rem;
line-height: 1.1;
}
.annotation small {
margin-top: 2px;
color: var(--muted);
font-size: 0.58rem;
font-variant-numeric: tabular-nums;
}
.camera-tools {
position: absolute;
z-index: 5;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 7px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 11px;
background: rgba(255, 252, 245, 0.82);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
}
.camera-tools button {
padding: 8px 10px;
border: 0;
border-radius: 7px;
background: transparent;
color: #586562;
font-size: 0.68rem;
font-weight: 750;
cursor: pointer;
}
.camera-tools button:hover,
.camera-tools button.active {
background: var(--teal-soft);
color: #176b78;
}
.camera-hint {
position: absolute;
z-index: 3;
left: 24px;
bottom: 25px;
padding: 8px 10px;
border-radius: 7px;
background: rgba(255, 252, 245, 0.67);
color: #68736f;
font-size: 0.64rem;
pointer-events: none;
backdrop-filter: blur(5px);
}
.loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e8e2d7;
color: var(--muted);
font-size: 0.8rem;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 850px) {
html,
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: minmax(390px, 48dvh) minmax(430px, 52dvh);
height: auto;
min-height: 100dvh;
}
.panel {
grid-row: 2;
grid-column: 1;
border-top: 1px solid var(--line);
border-right: 0;
}
.viewport {
grid-row: 1;
grid-column: 1;
}
.scene-top {
top: 14px;
left: 14px;
right: 14px;
}
.camera-tools {
right: 12px;
bottom: 12px;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div class="app">
<aside class="panel">
<header>
<p class="eyebrow">Opening study / 01</p>
<h1>Casement<br />window latch</h1>
<p class="intro">
Explore two independently adjustable casement sashes in a cutaway home.
Select a preset or set each opening angle.
</p>
</header>
<section class="section">
<h2 class="section-title">
Opening combination
<span id="combinationText">0° / 0°</span>
</h2>
<div class="control">
<div class="control-head">
<label for="upperAngle">Upper casement</label>
<output class="value" id="upperValue">0°</output>
</div>
<input id="upperAngle" type="range" min="0" max="90" step="1" value="0" />
<div class="range-ends"><span>Closed</span><span>90° open</span></div>
</div>
<div class="control">
<div class="control-head">
<label for="lowerAngle">Lower casement</label>
<output class="value" id="lowerValue">0°</output>
</div>
<input id="lowerAngle" type="range" min="0" max="90" step="1" value="0" />
<div class="range-ends"><span>Closed</span><span>90° open</span></div>
</div>
<div class="preset-grid" aria-label="Opening presets">
<button class="preset active" data-upper="0" data-lower="0">All closed</button>
<button class="preset" data-upper="72" data-lower="45">Cross vent</button>
<button class="preset" data-upper="35" data-lower="82">Stacked vent</button>
<button class="preset" data-upper="85" data-lower="78">Both open</button>
</div>
</section>
<section class="section">
<h2 class="section-title">Qualitative layer</h2>
<div class="toggle-row">
<div class="toggle-copy">
<strong>Schematic airflow cues</strong>
<small>Shown as a separate visual layer</small>
</div>
<label class="switch">
<input id="airflowToggle" type="checkbox" checked />
<span class="switch-track"></span>
</label>
</div>
<div class="legend">
<div class="legend-item">
<span class="legend-line intake"></span>
<span>Intake cue</span>
</div>
<div class="legend-item">
<span class="legend-line exhaust"></span>
<span>Exhaust cue</span>
</div>
</div>
</section>
<section class="section">
<h2 class="section-title">Latch detail <span>Lower sash</span></h2>
<div class="latch-card">
<div class="latch-icon" aria-hidden="true"></div>
<div class="latch-copy">
<strong id="latchState">Engaged</strong>
<p id="latchDescription">
Sash is closed and the latch is shown in its seated position.
</p>
</div>
</div>
</section>
<p class="disclaimer">
<strong>Qualitative visualization only.</strong> The arrows are schematic
cues, not a fluid-accurate simulation or CFD result. Real airflow depends
on wind, pressure, temperature, room geometry, and the openings.
</p>
</aside>
<main class="viewport" id="viewport">
<div id="scene"></div>
<div class="scene-top">
<div class="scene-title">
<small>Interactive cutaway</small>
<strong id="sceneStatus">Both casements closed</strong>
</div>
<div class="scene-badge">Low-poly study</div>
</div>
<div class="annotation" id="upperAnnotation">
<div><b>Upper casement</b><small id="upperAnnotationValue">0°</small></div>
</div>
<div class="annotation" id="lowerAnnotation">
<div><b>Lower casement</b><small id="lowerAnnotationValue">0°</small></div>
</div>
<div class="annotation latch" id="latchAnnotation">
<div><b>Latch</b><small id="latchAnnotationValue">Engaged</small></div>
</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Click the latch for detail</div>
<div class="camera-tools" aria-label="Camera views">
<button class="active" data-camera="overview">Overview</button>
<button data-camera="windows">Windows</button>
<button data-camera="latch">Latch</button>
</div>
<div class="loading" id="loading">Building cutaway…</div>
</main>
</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.getElementById("viewport");
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e2d7);
scene.fog = new THREE.Fog(0xe8e2d7, 16, 36);
const camera = new THREE.PerspectiveCamera(
39,
viewport.clientWidth / viewport.clientHeight,
0.05,
80
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D cutaway. Drag to orbit, scroll to zoom, and use arrow keys when focused."
);
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8e9, 0x74827b, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d3, 3.3);
sun.position.set(7, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcce7ea, 0.8);
fill.position.set(-7, 5, 2);
scene.add(fill);
const material = (color, roughness = 0.78, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true,
});
const mats = {
ground: material(0xdfd8cb),
foundation: material(0xb8b3a8),
floor: material(0xbe8d5e),
floorDark: material(0x9e6f48),
wall: material(0xe8e1d5),
wallSide: material(0xd7d1c5),
trim: material(0xf6f0e4),
slab: material(0xc8c1b4),
frame: material(0x344441, 0.48, 0.22),
frameLight: material(0x52625d, 0.5, 0.18),
glass: new THREE.MeshPhysicalMaterial({
color: 0xaed9d8,
transparent: true,
opacity: 0.28,
roughness: 0.18,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false,
}),
brass: material(0xb88b52, 0.3, 0.7),
handle: material(0xf1dfbc, 0.48, 0.12),
sofa: material(0x7b9d91),
sofaDark: material(0x5f7c74),
rug: material(0xc8835f),
rugInset: material(0xe3ba8e),
plant: material(0x527f5d),
plantDark: material(0x3e6748),
pot: material(0xb66f50),
white: material(0xf5f0e5),
wood: material(0x8e5f3e),
book: material(0xd07c58),
};
function box(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radiusTop, radiusBottom, height, position, mat, segments = 10) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x8d918b, opacity = 0.24) {
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
})
);
mesh.add(edge);
return edge;
}
// Ground and architectural cutaway.
const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), mats.ground);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.2;
ground.receiveShadow = true;
scene.add(ground);
const foundation = box(scene, [6.45, 0.2, 4.85], [0, -0.08, 0], mats.foundation);
addEdges(foundation, 0x8d918b, 0.28);
box(scene, [6.1, 0.12, 4.5], [0, 0.05, 0], mats.floor);
// Simple floor plank seams.
for (let x = -2.7; x <= 2.7; x += 0.6) {
box(scene, [0.012, 0.006, 4.42], [x, 0.115, 0], mats.floorDark, false);
}
const upperSlab = box(scene, [6.1, 0.16, 4.5], [0, 2.36, 0], mats.slab);
addEdges(upperSlab, 0x8d918b, 0.2);
// Back wall segments leave two real window openings.
const wallZ = -2.27;
const wallHeight = 4.78;
const lowerOpening = { bottom: 0.5, top: 2.02, width: 2.5 };
const upperOpening = { bottom: 2.78, top: 4.18, width: 2.5 };
function backWallSegment(size, position) {
const mesh = box(scene, size, position, mats.wall);
addEdges(mesh, 0xb9b4aa, 0.18);
}
backWallSegment([1.78, wallHeight, 0.18], [-2.11, wallHeight / 2, wallZ]);
backWallSegment([1.78, wallHeight, 0.18], [2.11, wallHeight / 2, wallZ]);
backWallSegment(
[2.44, lowerOpening.bottom, 0.18],
[0, lowerOpening.bottom / 2, wallZ]
);
backWallSegment(
[2.44, upperOpening.bottom - lowerOpening.top, 0.18],
[0, (upperOpening.bottom + lowerOpening.top) / 2, wallZ]
);
backWallSegment(
[2.44, wallHeight - upperOpening.top, 0.18],
[0, (wallHeight + upperOpening.top) / 2, wallZ]
);
const sideWall = box(scene, [0.18, 4.78, 4.55], [-3.05, 2.39, 0], mats.wallSide);
addEdges(sideWall, 0xb3aea4, 0.2);
// Cutaway roof edge and structural posts.
box(scene, [6.22, 0.22, 0.25], [0, 4.77, -2.2], mats.trim);
box(scene, [0.2, 4.8, 0.2], [-2.96, 2.4, -2.1], mats.trim);
box(scene, [0.2, 4.8, 0.2], [2.96, 2.4, -2.1], mats.trim);
// Interior furnishings.
const rug = box(scene, [2.7, 0.025, 1.8], [0.75, 0.13, 0.65], mats.rug, false);
addEdges(rug, 0xa76548, 0.25);
box(scene, [2.35, 0.012, 1.45], [0.75, 0.151, 0.65], mats.rugInset, false);
box(scene, [1.75, 0.42, 0.78], [1.7, 0.42, 0.55], mats.sofa);
box(scene, [1.75, 0.65, 0.18], [1.7, 0.72, 0.08], mats.sofaDark);
box(scene, [0.18, 0.58, 0.78], [0.86, 0.7, 0.55], mats.sofaDark);
box(scene, [0.18, 0.58, 0.78], [2.54, 0.7, 0.55], mats.sofaDark);
box(scene, [0.7, 0.16, 0.6], [1.25, 0.68, 0.58], mats.sofaDark);
box(scene, [0.7, 0.16, 0.6], [2.1, 0.68, 0.58], mats.sofaDark);
// Side table.
cylinder(scene, 0.36, 0.42, 0.08, [0.35, 0.62, 0.7], mats.wood, 10);
cylinder(scene, 0.055, 0.07, 0.5, [0.35, 0.34, 0.7], mats.wood, 8);
// Plant.
cylinder(scene, 0.28, 0.22, 0.45, [-2.05, 0.34, 0.95], mats.pot, 9);
cylinder(scene, 0.035, 0.055, 1.05, [-2.05, 0.96, 0.95], mats.plantDark, 7);
const leafGeo = new THREE.ConeGeometry(0.18, 0.68, 5);
[
[-2.3, 1.0, 0.92, 0.55],
[-1.82, 1.2, 0.98, -0.6],
[-2.15, 1.45, 0.96, 0.15],
[-1.92, 0.95, 0.82, -0.9],
].forEach(([x, y, z, rz]) => {
const leaf = new THREE.Mesh(leafGeo, mats.plant);
leaf.position.set(x, y, z);
leaf.rotation.z = rz;
leaf.rotation.x = 0.25;
leaf.castShadow = true;
scene.add(leaf);
});
// Upstairs desk and shelf.
box(scene, [1.65, 0.09, 0.68], [1.75, 2.83, 0.3], mats.wood);
for (const x of [1.05, 2.45]) {
box(scene, [0.08, 0.4, 0.08], [x, 2.61, 0.56], mats.frame);
}
box(scene, [0.52, 0.04, 0.36], [1.45, 2.9, 0.28], mats.white);
box(scene, [0.43, 0.05, 0.32], [1.48, 2.96, 0.28], mats.book);
box(scene, [0.65, 0.08, 0.35], [-1.6, 3.68, -1.55], mats.wood);
box(scene, [0.11, 0.55, 0.11], [-1.6, 3.37, -1.55], mats.wood);
const latchMeshes = [];
function createLatch(parent, direction, leafWidth, isLower) {
const latch = new THREE.Group();
const x = direction * (leafWidth - 0.18);
latch.position.set(x, 0, 0.145);
parent.add(latch);
const plate = box(latch, [0.15, 0.34, 0.055], [0, 0, 0], mats.brass);
addEdges(plate, 0x6f4f2d, 0.35);
const spindle = cylinder(latch, 0.045, 0.045, 0.14, [0, 0.05, 0.09], mats.brass, 10);
spindle.rotation.x = Math.PI / 2;
const lever = new THREE.Group();
lever.position.set(0, 0.05, 0.15);
latch.add(lever);
const grip = box(
lever,
[0.095, 0.31, 0.095],
[0, 0.12, 0],
mats.handle
);
addEdges(grip, 0x8c7557, 0.25);
const knob = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 8, 5),
mats.handle
);
knob.position.set(0, 0.28, 0);
knob.castShadow = true;
lever.add(knob);
latch.traverse((child) => {
if (child.isMesh) {
child.userData.isLatch = true;
latchMeshes.push(child);
}
});
return {
group: latch,
lever,
direction,
isLower,
};
}
function createWindow({ name, centerY, height, width, direction }) {
const group = new THREE.Group();
scene.add(group);
const frameZ = -2.08;
const frameDepth = 0.2;
// Fixed perimeter frame.
box(group, [0.12, height + 0.15, frameDepth], [-width / 2, centerY, frameZ], mats.frame);
box(group, [0.12, height + 0.15, frameDepth], [width / 2, centerY, frameZ], mats.frame);
box(group, [width + 0.15, 0.12, frameDepth], [0, centerY - height / 2, frameZ], mats.frame);
box(group, [width + 0.15, 0.12, frameDepth], [0, centerY + height / 2, frameZ], mats.frame);
// Interior sill and a thin mullion that remains with the opening.
box(group, [width + 0.24, 0.08, 0.36], [0, centerY - height / 2 - 0.08, frameZ + 0.08], mats.trim);
const pivot = new THREE.Group();
const pivotX = direction === 1 ? -width / 2 : width / 2;
pivot.position.set(pivotX, centerY, frameZ + 0.03);
group.add(pivot);
const leafWidth = width - 0.13;
const leafHeight = height - 0.13;
const centerX = direction * leafWidth / 2;
// Sash rails.
box(pivot, [0.09, leafHeight, 0.14], [direction * 0.045, 0, 0], mats.frameLight);
box(
pivot,
[0.09, leafHeight, 0.14],
[direction * (leafWidth - 0.045), 0, 0],
mats.frameLight
);
box(pivot, [leafWidth, 0.09, 0.14], [centerX, leafHeight / 2 - 0.045, 0], mats.frameLight);
box(pivot, [leafWidth, 0.09, 0.14], [centerX, -leafHeight / 2 + 0.045, 0], mats.frameLight);
const glass = box(
pivot,
[leafWidth - 0.13, leafHeight - 0.13, 0.028],
[centerX, 0, 0],
mats.glass,
false
);
glass.receiveShadow = false;
const latch = createLatch(pivot, direction, leafWidth, name === "Lower");
// Hinge blocks.
for (const y of [-leafHeight * 0.28, leafHeight * 0.28]) {
box(
pivot,
[0.13, 0.16, 0.16],
[0, y, 0],
mats.brass
);
}
return { group, pivot, latch, direction };
}
const upperWindow = createWindow({
name: "Upper",
centerY: (upperOpening.bottom + upperOpening.top) / 2,
height: upperOpening.top - upperOpening.bottom,
width: upperOpening.width,
direction: -1,
});
const lowerWindow = createWindow({
name: "Lower",
centerY: (lowerOpening.bottom + lowerOpening.top) / 2,
height: lowerOpening.top - lowerOpening.bottom,
width: lowerOpening.width,
direction: 1,
});
// A small anchor follows the lower latch.
const latchAnchor = new THREE.Object3D();
lowerWindow.latch.group.add(latchAnchor);
latchAnchor.position.set(0, 0.05, 0.18);
// Separate, deliberately schematic airflow layer.
const airflowGroup = new THREE.Group();
scene.add(airflowGroup);
function createArrowLayer(points, color, name) {
const layer = new THREE.Group();
layer.name = name;
airflowGroup.add(layer);
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
false,
"catmullrom",
0.25
);
const lineGeometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(55));
const lineMaterial = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.22,
dashSize: 0.12,
gapSize: 0.08,
depthTest: false,
depthWrite: false,
});
const line = new THREE.Line(lineGeometry, lineMaterial);
line.computeLineDistances();
line.renderOrder = 20;
layer.add(line);
const arrows = [];
[0.18, 0.48, 0.78].forEach((t) => {
const arrow = new THREE.ArrowHelper(
curve.getTangentAt(t),
curve.getPointAt(t),
0.48,
color,
0.17,
0.12
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.8;
arrow.line.material.depthTest = false;
arrow.line.material.depthWrite = false;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.9;
arrow.cone.material.depthTest = false;
arrow.cone.material.depthWrite = false;
arrow.line.renderOrder = 21;
arrow.cone.renderOrder = 21;
layer.add(arrow);
arrows.push(arrow);
});
return { layer, line, lineMaterial, arrows };
}
const intake = createArrowLayer(
[
[-0.15, 1.28, -3.8],
[0.0, 1.3, -2.75],
[0.08, 1.52, -1.4],
[1.0, 1.75, 0.05],
[2.35, 2.08, 1.0],
],
0x238b9b,
"Schematic lower intake"
);
const exhaust = createArrowLayer(
[
[2.15, 2.25, 1.15],
[1.15, 2.85, 0.35],
[0.25, 3.38, -0.75],
[0.0, 3.48, -2.15],
[0.0, 3.48, -3.7],
],
0xd9824b,
"Schematic upper exhaust"
);
const transfer = createArrowLayer(
[
[-0.12, 1.32, -2.35],
[0.25, 1.78, -1.05],
[0.78, 2.55, -0.1],
[0.35, 3.3, -0.9],
[0.0, 3.47, -2.4],
],
0x5b9ca3,
"Schematic room transfer"
);
function setArrowStrength(arrowLayer, strength, visible) {
arrowLayer.layer.visible = visible;
arrowLayer.lineMaterial.opacity = 0.08 + strength * 0.22;
arrowLayer.arrows.forEach((arrow) => {
arrow.line.material.opacity = 0.22 + strength * 0.72;
arrow.cone.material.opacity = 0.25 + strength * 0.7;
});
}
// UI state.
const upperInput = document.getElementById("upperAngle");
const lowerInput = document.getElementById("lowerAngle");
const upperValue = document.getElementById("upperValue");
const lowerValue = document.getElementById("lowerValue");
const combinationText = document.getElementById("combinationText");
const sceneStatus = document.getElementById("sceneStatus");
const upperAnnotationValue = document.getElementById("upperAnnotationValue");
const lowerAnnotationValue = document.getElementById("lowerAnnotationValue");
const latchState = document.getElementById("latchState");
const latchDescription = document.getElementById("latchDescription");
const latchAnnotationValue = document.getElementById("latchAnnotationValue");
const airflowToggle = document.getElementById("airflowToggle");
let targetUpper = 0;
let targetLower = 0;
let currentUpper = 0;
let currentLower = 0;
function syncRangeFill(input) {
const percent = (Number(input.value) / Number(input.max)) * 100;
input.style.setProperty("--fill", `${percent}%`);
}
function describeCombination(upper, lower) {
if (upper < 1 && lower < 1) return "Both casements closed";
if (upper >= 1 && lower >= 1) return "Upper and lower casements open";
if (upper >= 1) return "Upper casement open · lower closed";
return "Lower casement open · upper closed";
}
function updateUI() {
const upper = Number(upperInput.value);
const lower = Number(lowerInput.value);
targetUpper = THREE.MathUtils.degToRad(upper);
targetLower = THREE.MathUtils.degToRad(lower);
upperValue.textContent = `${upper}°`;
lowerValue.textContent = `${lower}°`;
upperAnnotationValue.textContent = `${upper}°`;
lowerAnnotationValue.textContent = `${lower}°`;
combinationText.textContent = `${upper}° / ${lower}°`;
sceneStatus.textContent = describeCombination(upper, lower);
const engaged = lower < 1;
latchState.textContent = engaged ? "Engaged" : "Released";
latchAnnotationValue.textContent = engaged ? "Engaged" : "Released";
latchDescription.textContent = engaged
? "Sash is closed and the latch is shown in its seated position."
: "The handle is shown in a schematic released position while the sash is ajar.";
syncRangeFill(upperInput);
syncRangeFill(lowerInput);
document.querySelectorAll(".preset").forEach((button) => {
const active =
Number(button.dataset.upper) === upper &&
Number(button.dataset.lower) === lower;
button.classList.toggle("active", active);
});
}
upperInput.addEventListener("input", updateUI);
lowerInput.addEventListener("input", updateUI);
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
upperInput.value = button.dataset.upper;
lowerInput.value = button.dataset.lower;
updateUI();
});
});
// Custom camera controls implemented directly with pointer events.
const desiredTarget = new THREE.Vector3(0, 2.15, -0.1);
const currentTarget = desiredTarget.clone();
const desiredSpherical = {
radius: 11.2,
theta: 0.62,
phi: 1.12,
};
const currentSpherical = { ...desiredSpherical };
let cameraMode = "overview";
function setCameraButtons() {
document.querySelectorAll("[data-camera]").forEach((button) => {
button.classList.toggle("active", button.dataset.camera === cameraMode);
});
}
function setCameraPreset(mode) {
cameraMode = mode;
if (mode === "overview") {
desiredTarget.set(0, 2.15, -0.1);
desiredSpherical.radius = 11.2;
desiredSpherical.theta = 0.62;
desiredSpherical.phi = 1.12;
} else if (mode === "windows") {
desiredTarget.set(0, 2.45, -0.65);
desiredSpherical.radius = 7.25;
desiredSpherical.theta = 0.48;
desiredSpherical.phi = 1.18;
} else if (mode === "latch") {
desiredSpherical.radius = 2.25;
desiredSpherical.theta = 0.64;
desiredSpherical.phi = 1.2;
}
setCameraButtons();
}
document.querySelectorAll("[data-camera]").forEach((button) => {
button.addEventListener("click", () => setCameraPreset(button.dataset.camera));
});
const pointers = new Map();
let dragStart = null;
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragStart = {
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false,
};
} else {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && dragStart) {
const dx = event.clientX - dragStart.lastX;
const dy = event.clientY - dragStart.lastY;
if (Math.hypot(event.clientX - dragStart.x, event.clientY - dragStart.y) > 4) {
dragStart.moved = true;
}
cameraMode = "free";
setCameraButtons();
desiredSpherical.theta -= dx * 0.006;
desiredSpherical.phi = THREE.MathUtils.clamp(
desiredSpherical.phi - dy * 0.005,
0.48,
1.46
);
dragStart.lastX = event.clientX;
dragStart.lastY = event.clientY;
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
desiredSpherical.radius = THREE.MathUtils.clamp(
desiredSpherical.radius * (lastPinchDistance / distance),
1.35,
18
);
}
lastPinchDistance = distance;
cameraMode = "free";
setCameraButtons();
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
if (pointers.size === 0) dragStart = null;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredSpherical.radius = THREE.MathUtils.clamp(
desiredSpherical.radius * Math.exp(event.deltaY * 0.001),
1.35,
18
);
cameraMode = "free";
setCameraButtons();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.08;
let handled = true;
if (event.key === "ArrowLeft") desiredSpherical.theta += step;
else if (event.key === "ArrowRight") desiredSpherical.theta -= step;
else if (event.key === "ArrowUp") desiredSpherical.phi -= step;
else if (event.key === "ArrowDown") desiredSpherical.phi += step;
else if (event.key === "+" || event.key === "=") desiredSpherical.radius *= 0.9;
else if (event.key === "-") desiredSpherical.radius *= 1.1;
else if (event.key === "0") setCameraPreset("overview");
else handled = false;
if (handled) {
event.preventDefault();
cameraMode = "free";
setCameraButtons();
}
});
// Clicking the 3D latch moves directly to the detail camera.
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragStart || dragStart.moved) return;
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(latchMeshes, false);
if (hits.length) {
setCameraPreset("latch");
}
});
// Project DOM labels from their 3D anchors.
const upperLabel = document.getElementById("upperAnnotation");
const lowerLabel = document.getElementById("lowerAnnotation");
const latchLabel = document.getElementById("latchAnnotation");
const upperLabelAnchor = new THREE.Vector3(-1.7, 4.28, -1.8);
const lowerLabelAnchor = new THREE.Vector3(1.25, 0.45, -1.75);
function placeLabel(element, worldPosition, offsetX = 0, offsetY = 0) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const latchWorld = new THREE.Vector3();
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
new ResizeObserver(resize).observe(viewport);
resize();
updateUI();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.exp(-dt * 10);
currentUpper = THREE.MathUtils.lerp(currentUpper, targetUpper, easing);
currentLower = THREE.MathUtils.lerp(currentLower, targetLower, easing);
upperWindow.pivot.rotation.y = -upperWindow.direction * currentUpper;
lowerWindow.pivot.rotation.y = -lowerWindow.direction * currentLower;
const lowerOpen = THREE.MathUtils.clamp(currentLower / THREE.MathUtils.degToRad(90), 0, 1);
const upperOpen = THREE.MathUtils.clamp(currentUpper / THREE.MathUtils.degToRad(90), 0, 1);
upperWindow.latch.lever.rotation.z = THREE.MathUtils.lerp(
upperWindow.latch.lever.rotation.z,
upperWindow.latch.direction * -1.08 * (currentUpper > 0.008 ? 1 : 0),
easing
);
lowerWindow.latch.lever.rotation.z = THREE.MathUtils.lerp(
lowerWindow.latch.lever.rotation.z,
lowerWindow.latch.direction * -1.08 * (currentLower > 0.008 ? 1 : 0),
easing
);
airflowGroup.visible = airflowToggle.checked;
setArrowStrength(intake, lowerOpen, lowerOpen > 0.015);
setArrowStrength(exhaust, upperOpen, upperOpen > 0.015);
setArrowStrength(
transfer,
Math.min(lowerOpen, upperOpen),
lowerOpen > 0.015 && upperOpen > 0.015
);
scene.updateMatrixWorld(true);
if (cameraMode === "latch") {
latchAnchor.getWorldPosition(latchWorld);
desiredTarget.lerp(latchWorld, 0.2);
}
currentTarget.lerp(desiredTarget, easing);
currentSpherical.radius = THREE.MathUtils.lerp(
currentSpherical.radius,
desiredSpherical.radius,
easing
);
currentSpherical.theta = THREE.MathUtils.lerp(
currentSpherical.theta,
desiredSpherical.theta,
easing
);
currentSpherical.phi = THREE.MathUtils.lerp(
currentSpherical.phi,
desiredSpherical.phi,
easing
);
const sinPhi = Math.sin(currentSpherical.phi);
camera.position.set(
currentTarget.x + currentSpherical.radius * sinPhi * Math.sin(currentSpherical.theta),
currentTarget.y + currentSpherical.radius * Math.cos(currentSpherical.phi),
currentTarget.z + currentSpherical.radius * sinPhi * Math.cos(currentSpherical.theta)
);
camera.lookAt(currentTarget);
placeLabel(upperLabel, upperLabelAnchor, -48, -12);
placeLabel(lowerLabel, lowerLabelAnchor, 58, 22);
latchAnchor.getWorldPosition(latchWorld);
placeLabel(latchLabel, latchWorld, 68, -4);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```