Prompt specification
Build or customize the Three.js 3D scene "Low inlet and high outlet model" 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: Low inlet and high outlet model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/low-inlet-and-high-outlet-model-x1070
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts greenhouse ventilation. Animate labeled qualitative airflow arrows entering low openings and leaving a roof vent; toggles reveal how closing one opening changes the displayed route. Low-poly.
Working Three.js Starter (low-inlet-and-high-outlet-model-x1070):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Greenhouse Ventilation</title>
<style>
:root {
--ink: #173d36;
--muted: #60756f;
--panel: rgba(248, 252, 248, 0.88);
--line: rgba(31, 84, 73, 0.16);
--green: #169c91;
--amber: #e89a30;
--closed: #8b9994;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8f1ec;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#title-card {
position: fixed;
z-index: 5;
top: 20px;
left: 20px;
width: min(370px, calc(100vw - 40px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(32, 72, 60, 0.09);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 31px);
line-height: 1.05;
letter-spacing: -0.04em;
}
#title-card p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--green);
}
.legend-dot.amber {
background: var(--amber);
}
#controls {
position: fixed;
z-index: 6;
right: 20px;
bottom: 20px;
width: min(325px, calc(100vw - 40px));
padding: 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(32, 72, 60, 0.11);
backdrop-filter: blur(14px);
}
.controls-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.controls-heading strong {
font-size: 13px;
}
.status-badge {
padding: 5px 8px;
border-radius: 999px;
background: rgba(22, 156, 145, 0.11);
color: var(--green);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.status-badge.amber {
background: rgba(232, 154, 48, 0.14);
color: #aa6813;
}
.status-badge.closed {
background: rgba(92, 110, 104, 0.12);
color: var(--closed);
}
.toggle {
display: grid;
grid-template-columns: 13px 1fr auto;
align-items: center;
gap: 10px;
width: 100%;
margin-top: 8px;
padding: 11px 12px;
border: 1px solid rgba(31, 84, 73, 0.12);
border-radius: 12px;
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
font: inherit;
text-align: left;
cursor: pointer;
transition:
transform 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
.toggle:hover {
transform: translateY(-1px);
border-color: rgba(22, 156, 145, 0.42);
background: rgba(255, 255, 255, 0.86);
}
.toggle:focus-visible {
outline: 3px solid rgba(22, 156, 145, 0.25);
outline-offset: 2px;
}
.toggle .indicator {
width: 11px;
height: 11px;
border: 2px solid #aab5b1;
border-radius: 50%;
background: transparent;
transition: all 160ms ease;
}
.toggle.is-open .indicator {
border-color: var(--green);
background: var(--green);
box-shadow: 0 0 0 4px rgba(22, 156, 145, 0.11);
}
.toggle-copy {
display: flex;
flex-direction: column;
gap: 2px;
}
.toggle-copy b {
font-size: 12px;
}
.toggle-copy small {
color: var(--muted);
font-size: 10px;
}
.toggle .state {
color: var(--closed);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
}
.toggle.is-open .state {
color: var(--green);
}
#route-summary {
margin: 14px 0 0;
font-size: 12px;
font-weight: 800;
line-height: 1.4;
}
#route-detail {
min-height: 34px;
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: 145px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 11px;
background: rgba(250, 254, 251, 0.84);
box-shadow: 0 6px 18px rgba(30, 69, 58, 0.11);
backdrop-filter: blur(8px);
transform: translate(-50%, -50%);
transition:
opacity 180ms ease,
filter 180ms ease;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -13px;
width: 1px;
height: 13px;
background: rgba(23, 61, 54, 0.28);
}
.scene-label i {
flex: 0 0 auto;
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(22, 156, 145, 0.11);
}
.scene-label div {
display: flex;
flex-direction: column;
gap: 1px;
}
.scene-label strong {
color: var(--ink);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.scene-label span {
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.scene-label.closed {
opacity: 0.55;
filter: grayscale(0.8);
}
.scene-label.closed i {
background: var(--closed);
box-shadow: none;
}
#label-vent i {
background: #de7c31;
box-shadow: 0 0 0 4px rgba(222, 124, 49, 0.11);
}
#hint {
position: fixed;
z-index: 5;
left: 20px;
bottom: 20px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(248, 252, 248, 0.75);
color: var(--muted);
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 720px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#title-card p,
#legend {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
#hint {
display: none;
}
.toggle {
padding: 8px 10px;
}
.toggle-copy small {
display: none;
}
.scene-label {
min-width: auto;
padding: 6px 8px;
}
.scene-label span {
display: none;
}
}
</style>
</head>
<body>
<div id="title-card">
<div class="eyebrow">Interactive systems study</div>
<h1>Greenhouse Ventilation</h1>
<p>
Close a low opening or the ridge vent to compare how the qualitative
airflow route changes. Arrow direction is illustrative, not to scale.
</p>
<div id="legend">
<span class="legend-item">
<i class="legend-dot"></i>
Through-flow
</span>
<span class="legend-item">
<i class="legend-dot amber"></i>
Recirculation
</span>
</div>
</div>
<div id="labels">
<div id="label-left" class="scene-label">
<i></i>
<div>
<strong id="left-label-title">Left low opening</strong>
<span id="left-label-sub">Open · cool air enters</span>
</div>
</div>
<div id="label-right" class="scene-label">
<i></i>
<div>
<strong id="right-label-title">Right low opening</strong>
<span id="right-label-sub">Open · cool air enters</span>
</div>
</div>
<div id="label-vent" class="scene-label">
<i></i>
<div>
<strong id="vent-label-title">Roof ridge vent</strong>
<span id="vent-label-sub">Open · warm air exits</span>
</div>
</div>
</div>
<div id="controls">
<div class="controls-heading">
<strong>Ventilation controls</strong>
<span id="status-badge" class="status-badge">Balanced flow</span>
</div>
<button id="left-toggle" class="toggle is-open" aria-pressed="true">
<i class="indicator"></i>
<span class="toggle-copy">
<b>Left low opening</b>
<small>Low-level air inlet</small>
</span>
<span class="state">OPEN</span>
</button>
<button id="right-toggle" class="toggle is-open" aria-pressed="true">
<i class="indicator"></i>
<span class="toggle-copy">
<b>Right low opening</b>
<small>Low-level air inlet</small>
</span>
<span class="state">OPEN</span>
</button>
<button id="roof-toggle" class="toggle is-open" aria-pressed="true">
<i class="indicator"></i>
<span class="toggle-copy">
<b>Roof ridge vent</b>
<small>Warm-air outlet</small>
</span>
<span class="state">OPEN</span>
</button>
<p id="route-summary">Air enters through both low openings.</p>
<p id="route-detail">
The two inlet streams merge near the ridge and escape through the roof vent.
</p>
</div>
<div id="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8f1ec);
scene.fog = new THREE.Fog(0xe8f1ec, 16, 30);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly greenhouse ventilation scene"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf8fff9, 0x6b8173, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5df, 3.2);
sun.position.set(7, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7e8ed, 1.0);
fill.position.set(-7, 5, -6);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x315d53,
roughness: 0.78,
metalness: 0.08,
flatShading: true
});
const flapMaterial = new THREE.MeshStandardMaterial({
color: 0x8eb8a8,
roughness: 0.72,
metalness: 0.02,
flatShading: true
});
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0xc4e8e1,
roughness: 0.25,
metalness: 0,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthWrite: false
});
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xcbdcc7,
roughness: 1,
flatShading: true
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xb8c6b7,
roughness: 0.95,
flatShading: true
});
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x5b4935,
roughness: 1,
flatShading: true
});
const foliageMaterials = [
new THREE.MeshStandardMaterial({
color: 0x4c8a55,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x67a763,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x86b96a,
roughness: 0.9,
flatShading: true
})
];
function addBox(width, height, depth, material, x, y, z, rotationX = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.rotation.x = rotationX;
mesh.castShadow = !material.transparent;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const up = new THREE.Vector3(0, 1, 0);
function addBeam(start, end, radius = 0.055, material = frameMaterial) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 6),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Greenhouse structure
// -------------------------------------------------------------------------
const W = 3.6;
const D = 2.6;
const EAVE = 2.2;
const RIDGE = 4.05;
const roofAngle = Math.atan2(RIDGE - EAVE, D);
const roofLength = Math.hypot(RIDGE - EAVE, D);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 24),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
addBox(7.35, 0.18, 5.35, floorMaterial, 0, 0.09, 0);
// Side wall panels, leaving a low central opening on each side.
for (const side of [-1, 1]) {
const x = side * W;
// Upper side glass.
addBox(0.045, 1.08, 5.2, glassMaterial, x, 1.65, 0);
// Lower glass in front of and behind each opening.
addBox(0.045, 0.84, 1.82, glassMaterial, x, 0.68, -1.69);
addBox(0.045, 0.84, 1.82, glassMaterial, x, 0.68, 1.69);
// Side rails.
addBeam(
new THREE.Vector3(x, EAVE, -D),
new THREE.Vector3(x, EAVE, D),
0.065
);
addBeam(
new THREE.Vector3(x, 0.18, -D),
new THREE.Vector3(x, 0.18, D),
0.065
);
// Corner and midpoint posts.
for (const z of [-D, 0, D]) {
addBeam(
new THREE.Vector3(x, 0.18, z),
new THREE.Vector3(x, EAVE, z),
z === 0 ? 0.045 : 0.065
);
}
// Opening frame.
for (const z of [-0.77, 0.77]) {
addBeam(
new THREE.Vector3(x, 0.24, z),
new THREE.Vector3(x, 1.1, z),
0.047
);
}
addBeam(
new THREE.Vector3(x, 1.1, -0.8),
new THREE.Vector3(x, 1.1, 0.8),
0.047
);
}
// End-wall glass and frames.
for (const z of [-D, D]) {
addBox(7.2, 2.18, 0.04, glassMaterial, 0, 1.1, z);
for (const x of [-W, W]) {
addBeam(
new THREE.Vector3(x, 0.18, z),
new THREE.Vector3(x, EAVE, z),
0.065
);
}
addBeam(
new THREE.Vector3(-W, EAVE, z),
new THREE.Vector3(W, EAVE, z),
0.065
);
addBeam(
new THREE.Vector3(-W, EAVE, z),
new THREE.Vector3(0, RIDGE, z),
0.065
);
addBeam(
new THREE.Vector3(0, RIDGE, z),
new THREE.Vector3(W, EAVE, z),
0.065
);
}
// Ridge beam.
addBeam(
new THREE.Vector3(-W, RIDGE, 0),
new THREE.Vector3(W, RIDGE, 0),
0.075
);
// Roof rafters.
for (const x of [-W, -1.8, 0, 1.8, W]) {
addBeam(
new THREE.Vector3(x, RIDGE, 0),
new THREE.Vector3(x, EAVE, -D),
0.052
);
addBeam(
new THREE.Vector3(x, RIDGE, 0),
new THREE.Vector3(x, EAVE, D),
0.052
);
}
// Two low-poly roof panels.
const frontRoof = addBox(
W * 2,
0.045,
roofLength,
glassMaterial,
0,
(RIDGE + EAVE) / 2,
D / 2,
roofAngle
);
frontRoof.renderOrder = 1;
const backRoof = addBox(
W * 2,
0.045,
roofLength,
glassMaterial,
0,
(RIDGE + EAVE) / 2,
-D / 2,
-roofAngle
);
backRoof.renderOrder = 1;
// Low-poly planting beds and plants.
function addPlanter(x, z, index) {
const planter = addBox(
1.12,
0.43,
1.03,
frameMaterial,
x,
0.4,
z
);
planter.rotation.y = index % 2 ? 0.04 : -0.05;
addBox(0.94, 0.06, 0.86, soilMaterial, x, 0.64, z);
for (let i = 0; i < 3; i++) {
const plant = new THREE.Mesh(
new THREE.ConeGeometry(0.22, 0.58 + i * 0.05, 5),
foliageMaterials[(index + i) % foliageMaterials.length]
);
plant.position.set(
x + (i - 1) * 0.25,
0.94 + i * 0.025,
z + (i % 2 ? 0.12 : -0.1)
);
plant.rotation.y = i * 0.8;
plant.castShadow = true;
scene.add(plant);
}
}
addPlanter(-2.3, -1.55, 0);
addPlanter(-2.3, 1.55, 1);
addPlanter(2.3, -1.55, 2);
addPlanter(2.3, 1.55, 3);
// -------------------------------------------------------------------------
// Hinged low openings
// -------------------------------------------------------------------------
function createLowFlap(side) {
const group = new THREE.Group();
group.position.set(side * W, 0.25, 0);
group.rotation.z = side === 1 ? -Math.PI / 2 : Math.PI / 2;
const panel = new THREE.Mesh(
new THREE.BoxGeometry(0.06, 0.78, 1.36),
flapMaterial
);
panel.position.y = 0.39;
panel.castShadow = true;
group.add(panel);
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0x456f62,
roughness: 0.8,
flatShading: true
});
const upperEdge = new THREE.Mesh(
new THREE.BoxGeometry(0.085, 0.055, 1.42),
edgeMaterial
);
upperEdge.position.y = 0.79;
group.add(upperEdge);
scene.add(group);
return group;
}
const leftFlap = createLowFlap(-1);
const rightFlap = createLowFlap(1);
// -------------------------------------------------------------------------
// Hinged roof vent
// -------------------------------------------------------------------------
const ventHinge = new THREE.Vector3(1.15, RIDGE - 0.035, -0.04);
const fixedVentFrame = new THREE.Group();
fixedVentFrame.position.copy(ventHinge);
fixedVentFrame.rotation.x = -roofAngle;
const ventFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x355f55,
roughness: 0.75,
flatShading: true
});
for (const x of [-0.72, 0.72]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.065, 0.08, 1.25),
ventFrameMaterial
);
rail.position.set(x, 0, -0.6);
fixedVentFrame.add(rail);
}
for (const z of [0, -1.2]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(1.5, 0.08, 0.065),
ventFrameMaterial
);
rail.position.set(0, 0, z);
fixedVentFrame.add(rail);
}
scene.add(fixedVentFrame);
const roofVent = new THREE.Group();
roofVent.position.copy(ventHinge);
roofVent.rotation.x = -roofAngle + 0.72;
const ventPanel = new THREE.Mesh(
new THREE.BoxGeometry(1.34, 0.055, 1.12),
flapMaterial
);
ventPanel.position.set(0, 0, -0.58);
ventPanel.castShadow = true;
roofVent.add(ventPanel);
const ventPanelEdge = new THREE.Mesh(
new THREE.BoxGeometry(1.38, 0.075, 0.075),
ventFrameMaterial
);
ventPanelEdge.position.set(0, 0, -1.13);
roofVent.add(ventPanelEdge);
scene.add(roofVent);
// -------------------------------------------------------------------------
// Qualitative airflow arrows
// -------------------------------------------------------------------------
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const arrowShaftGeometry = new THREE.CylinderGeometry(
0.045,
0.045,
0.34,
6
);
const arrowHeadGeometry = new THREE.ConeGeometry(0.12, 0.25, 6);
const teal = new THREE.Color(0x18a69d);
const amber = new THREE.Color(0xe99b32);
const state = {
left: true,
right: true,
roof: true
};
let flowRoutes = [];
let ventAmount = 1;
function makeCurve(points) {
return new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
false,
"catmullrom",
0.28
);
}
function leftThroughCurve() {
return makeCurve([
[-4.45, 0.68, 0],
[-3.55, 0.68, 0],
[-2.55, 0.78, 0.08],
[-1.45, 1.05, 0.18],
[-0.35, 1.8, 0.08],
[0.65, 2.75, -0.15],
[1.12, 3.65, -0.48],
[1.15, 4.78, -0.65]
]);
}
function rightThroughCurve() {
return makeCurve([
[4.45, 0.68, 0],
[3.55, 0.68, 0],
[2.55, 0.78, -0.08],
[1.55, 1.05, -0.18],
[0.65, 1.65, -0.1],
[1.08, 2.9, -0.48],
[1.15, 4.78, -0.65]
]);
}
function leftRecirculationCurve() {
return makeCurve([
[-4.4, 0.68, 0],
[-3.5, 0.72, 0],
[-2.2, 1.0, 0.1],
[-1.0, 2.1, 0.2],
[0.1, 2.85, 0.1],
[1.1, 2.45, -0.1],
[1.1, 1.35, 0.05],
[-0.8, 0.75, 0.2],
[-2.7, 0.7, 0.2],
[-3.45, 0.9, 0.2],
[-4.35, 1.15, 0.5]
]);
}
function rightRecirculationCurve() {
return makeCurve([
[4.4, 0.68, 0],
[3.5, 0.72, 0],
[2.2, 1.0, -0.1],
[1.0, 2.1, -0.2],
[-0.1, 2.85, -0.1],
[-1.1, 2.45, 0.1],
[-1.1, 1.35, -0.05],
[0.8, 0.75, -0.2],
[2.7, 0.7, -0.2],
[3.45, 0.9, -0.2],
[4.35, 1.15, -0.5]
]);
}
function clearFlowRoutes() {
for (const route of flowRoutes) {
flowGroup.remove(route.group);
route.tube.geometry.dispose();
route.lineMaterial.dispose();
route.arrowMaterial.dispose();
}
flowRoutes = [];
}
function addFlowRoute(curve, color, count, speed, phase = 0) {
const group = new THREE.Group();
const lineMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 72, 0.023, 6, false),
lineMaterial
);
group.add(tube);
const arrowMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.22,
roughness: 0.45,
metalness: 0.02,
flatShading: true
});
const arrows = [];
for (let i = 0; i < count; i++) {
const arrow = new THREE.Group();
const shaft = new THREE.Mesh(arrowShaftGeometry, arrowMaterial);
shaft.position.y = 0.15;
shaft.castShadow = true;
const head = new THREE.Mesh(arrowHeadGeometry, arrowMaterial);
head.position.y = 0.39;
head.castShadow = true;
arrow.add(shaft, head);
group.add(arrow);
arrows.push(arrow);
}
flowGroup.add(group);
flowRoutes.push({
group,
curve,
tube,
lineMaterial,
arrowMaterial,
arrows,
speed,
phase
});
}
function rebuildFlow() {
clearFlowRoutes();
const activeInlets = [];
if (state.left) activeInlets.push("left");
if (state.right) activeInlets.push("right");
if (activeInlets.length === 0) return;
if (state.roof) {
const count = activeInlets.length === 1 ? 10 : 6;
const speed = activeInlets.length === 1 ? 0.15 : 0.105;
if (state.left) {
addFlowRoute(
leftThroughCurve(),
teal,
count,
speed,
0.02
);
}
if (state.right) {
addFlowRoute(
rightThroughCurve(),
teal,
count,
speed,
0.52
);
}
} else {
if (state.left) {
addFlowRoute(
leftRecirculationCurve(),
amber,
8,
0.095,
0.02
);
}
if (state.right) {
addFlowRoute(
rightRecirculationCurve(),
amber,
8,
0.095,
0.52
);
}
}
}
// -------------------------------------------------------------------------
// UI and status text
// -------------------------------------------------------------------------
const leftToggle = document.getElementById("left-toggle");
const rightToggle = document.getElementById("right-toggle");
const roofToggle = document.getElementById("roof-toggle");
const statusBadge = document.getElementById("status-badge");
const routeSummary = document.getElementById("route-summary");
const routeDetail = document.getElementById("route-detail");
const labelLeft = document.getElementById("label-left");
const labelRight = document.getElementById("label-right");
const labelVent = document.getElementById("label-vent");
function updateButton(button, open) {
button.classList.toggle("is-open", open);
button.setAttribute("aria-pressed", String(open));
button.querySelector(".state").textContent = open ? "OPEN" : "CLOSED";
}
function updateStatus() {
updateButton(leftToggle, state.left);
updateButton(rightToggle, state.right);
updateButton(roofToggle, state.roof);
labelLeft.classList.toggle("closed", !state.left);
labelRight.classList.toggle("closed", !state.right);
labelVent.classList.toggle("closed", !state.roof);
document.getElementById("left-label-title").textContent =
state.left ? "Left low opening" : "Left low opening closed";
document.getElementById("right-label-title").textContent =
state.right ? "Right low opening" : "Right low opening closed";
document.getElementById("vent-label-title").textContent =
state.roof ? "Roof ridge vent" : "Roof ridge vent closed";
document.getElementById("left-label-sub").textContent =
state.left ? "Open · cool air enters" : "Closed · inlet blocked";
document.getElementById("right-label-sub").textContent =
state.right ? "Open · cool air enters" : "Closed · inlet blocked";
document.getElementById("vent-label-sub").textContent =
state.roof ? "Open · warm air exits" : "Closed · outlet blocked";
statusBadge.classList.remove("amber", "closed");
if (!state.left && !state.right) {
statusBadge.textContent = "No through-flow";
statusBadge.classList.add("closed");
routeSummary.textContent = "Both low openings are closed.";
routeDetail.textContent =
"No outdoor air can enter, so the displayed through-flow route disappears.";
} else if (!state.roof) {
statusBadge.textContent = "Recirculation";
statusBadge.classList.add("amber");
routeSummary.textContent = "The roof outlet is closed.";
routeDetail.textContent =
"Incoming air rises, circulates inside, and spills back toward the available low opening instead of escaping at the ridge.";
} else if (state.left && state.right) {
statusBadge.textContent = "Balanced flow";
routeSummary.textContent = "Air enters through both low openings.";
routeDetail.textContent =
"The two inlet streams merge near the ridge and escape through the roof vent.";
} else if (state.left) {
statusBadge.textContent = "Rerouted flow";
routeSummary.textContent = "The right inlet is closed.";
routeDetail.textContent =
"The remaining left opening carries the full through-flow route to the ridge vent.";
} else {
statusBadge.textContent = "Rerouted flow";
routeSummary.textContent = "The left inlet is closed.";
routeDetail.textContent =
"The remaining right opening carries the full through-flow route to the ridge vent.";
}
}
function togglePart(part) {
state[part] = !state[part];
updateStatus();
rebuildFlow();
}
leftToggle.addEventListener("click", () => togglePart("left"));
rightToggle.addEventListener("click", () => togglePart("right"));
roofToggle.addEventListener("click", () => togglePart("roof"));
updateStatus();
rebuildFlow();
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset
// -------------------------------------------------------------------------
const orbit = {
radius: 11.8,
theta: 0.72,
phi: 1.02,
target: new THREE.Vector3(0, 1.85, 0)
};
const defaultOrbit = {
radius: 11.8,
theta: 0.72,
phi: 1.02
};
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.42,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {
// Pointer capture may already have been released.
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
7.0,
18.0
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.radius = defaultOrbit.radius;
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const labelAnchors = {
left: new THREE.Vector3(-3.72, 1.5, 0.15),
right: new THREE.Vector3(3.72, 1.5, -0.15),
vent: new THREE.Vector3(1.15, 4.6, -0.52)
};
function positionLabel(element, anchor) {
const projected = anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "flex" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
const easing = 1 - Math.exp(-delta * 8);
const leftTarget = state.left ? Math.PI / 2 : 0;
const rightTarget = state.right ? -Math.PI / 2 : 0;
const ventTarget = state.roof ? 1 : 0;
leftFlap.rotation.z = THREE.MathUtils.lerp(
leftFlap.rotation.z,
leftTarget,
easing
);
rightFlap.rotation.z = THREE.MathUtils.lerp(
rightFlap.rotation.z,
rightTarget,
easing
);
ventAmount = THREE.MathUtils.lerp(
ventAmount,
ventTarget,
easing
);
roofVent.rotation.x = -roofAngle + ventAmount * 0.72;
for (const route of flowRoutes) {
route.arrows.forEach((arrow, index) => {
const t =
(elapsed * route.speed +
route.phase +
index / route.arrows.length) %
1;
const point = route.curve.getPointAt(t);
const tangent = route.curve.getTangentAt(t).normalize();
arrow.position.copy(point).addScaledVector(tangent, -0.18);
arrow.quaternion.setFromUnitVectors(up, tangent);
});
}
positionLabel(labelLeft, labelAnchors.left);
positionLabel(labelRight, labelAnchors.right);
positionLabel(labelVent, labelAnchors.vent);
renderer.render(scene, camera);
}
animate();
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```