Prompt specification
Build or customize the Three.js 3D scene "Convection pathway exploration exhibit" 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: Convection pathway exploration exhibit
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/convection-pathway-exploration-exhibit-x1460
Scene Description Prompt:
Allow moving a heater and opening a vent in a toy room model; update clearly predefined circulation patterns and explain the limitations of qualitative airflow visualization. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (convection-pathway-exploration-exhibit-x1460):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Toy Room Airflow Explorer</title>
<style>
:root {
--ink: #26333a;
--muted: #607078;
--panel: rgba(255, 253, 248, 0.94);
--warm: #ef6b3a;
--cool: #238ea8;
--line: rgba(38, 51, 58, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #e9e5dc;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.title-block {
position: fixed;
top: 20px;
left: 22px;
z-index: 5;
max-width: 390px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}
.eyebrow {
margin-bottom: 5px;
color: #b64926;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.35rem, 2.6vw, 2rem);
line-height: 1.06;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 0.9rem;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
right: 18px;
width: min(350px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(38, 51, 58, 0.16),
0 2px 8px rgba(38, 51, 58, 0.08);
backdrop-filter: blur(14px);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 15px;
}
.panel h2,
.panel h3 {
margin: 0;
letter-spacing: -0.025em;
}
.panel h2 {
font-size: 1.05rem;
}
.badge {
flex: 0 0 auto;
padding: 5px 9px;
border-radius: 999px;
background: #e5e9e8;
color: #536268;
font-size: 0.67rem;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.badge.open {
color: #126b7e;
background: #d8f1f3;
}
.control-section {
padding: 13px 0;
border-top: 1px solid var(--line);
}
.control-section:first-of-type {
border-top: 0;
padding-top: 0;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
font-size: 0.79rem;
font-weight: 750;
}
.value {
color: var(--muted);
font-variant-numeric: tabular-nums;
font-weight: 600;
}
input[type="range"] {
width: 100%;
margin: 4px 0 12px;
accent-color: var(--warm);
cursor: pointer;
}
input[type="range"]:last-of-type {
margin-bottom: 2px;
}
button {
min-height: 38px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: #fffdf9;
font: inherit;
font-size: 0.8rem;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
box-shadow 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: white;
box-shadow: 0 4px 12px rgba(38, 51, 58, 0.08);
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(35, 142, 168, 0.28);
outline-offset: 2px;
}
button.primary {
width: 100%;
border-color: transparent;
color: white;
background: var(--cool);
}
button.primary[aria-pressed="true"] {
background: #176f83;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 9px;
}
.pattern-card {
padding: 13px;
border: 1px solid rgba(239, 107, 58, 0.22);
border-radius: 13px;
background:
linear-gradient(135deg, rgba(239, 107, 58, 0.08), transparent 65%),
#fffdf9;
}
.pattern-card h3 {
margin-bottom: 7px;
font-size: 0.95rem;
}
.pattern-card p {
margin: 0;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.5;
}
.rule {
margin-top: 9px !important;
padding-top: 9px;
border-top: 1px solid var(--line);
font-size: 0.72rem !important;
}
.flow-steps {
margin: 10px 0 0;
padding-left: 18px;
color: var(--muted);
font-size: 0.75rem;
line-height: 1.45;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 0.7rem;
}
.swatch {
width: 22px;
height: 4px;
flex: 0 0 auto;
border-radius: 99px;
background: var(--warm);
}
.swatch.cool {
background: var(--cool);
}
details {
color: var(--muted);
font-size: 0.74rem;
line-height: 1.5;
}
summary {
color: var(--ink);
font-weight: 750;
cursor: pointer;
}
details ul {
margin: 9px 0 0;
padding-left: 18px;
}
.help {
position: fixed;
z-index: 4;
left: 22px;
bottom: 18px;
max-width: min(440px, calc(100vw - 44px));
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 10px;
color: #526168;
background: rgba(255, 253, 248, 0.88);
box-shadow: 0 6px 20px rgba(38, 51, 58, 0.08);
font-size: 0.72rem;
pointer-events: none;
}
.help strong {
color: var(--ink);
}
@media (max-width: 720px) {
.title-block {
top: 13px;
left: 15px;
max-width: calc(100vw - 30px);
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 48vh;
padding: 14px;
border-radius: 14px;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="title-block">
<div class="eyebrow">Interactive flow model</div>
<h1>Toy Room Airflow Explorer</h1>
<p class="subtitle">
Move the heater, open the high vent, and compare predefined circulation cells.
</p>
</header>
<aside class="panel" aria-label="Airflow model controls">
<div class="panel-header">
<h2>Room controls</h2>
<span id="modeBadge" class="badge">Vent sealed</span>
</div>
<section class="control-section">
<div class="control-label">
<label for="heaterX">Across room · X</label>
<span id="heaterXValue" class="value">0.60 u</span>
</div>
<input
id="heaterX"
type="range"
min="-3"
max="3"
step="0.05"
value="0.6"
aria-label="Heater horizontal position"
>
<div class="control-label">
<label for="heaterZ">Front–back · Z</label>
<span id="heaterZValue" class="value">0.45 u</span>
</div>
<input
id="heaterZ"
type="range"
min="-2"
max="2"
step="0.05"
value="0.45"
aria-label="Heater depth position"
>
<div class="button-row">
<button id="resetHeater" type="button">Reset heater</button>
<button id="resetCamera" type="button">Reset camera</button>
</div>
</section>
<section class="control-section">
<div class="control-label">
<span>High rear vent</span>
<span id="ventState" class="value">Closed</span>
</div>
<button
id="ventButton"
class="primary"
type="button"
aria-pressed="false"
>
Open vent
</button>
</section>
<section class="control-section" aria-live="polite">
<div class="pattern-card">
<h3 id="patternTitle">Central convection cell</h3>
<p id="patternDescription"></p>
<p id="patternRule" class="rule"></p>
<ol id="flowSteps" class="flow-steps"></ol>
</div>
<div class="legend" aria-label="Flow color legend">
<div class="legend-item">
<span class="swatch"></span>
<span>Warm / rising path</span>
</div>
<div class="legend-item">
<span class="swatch cool"></span>
<span>Return / intake path</span>
</div>
</div>
</section>
<section class="control-section">
<details>
<summary>What this visualization can and cannot show</summary>
<ul>
<li>
Paths follow a small set of authored rules for the heater's zone
and the vent state.
</li>
<li>
The arrows are not calculated from fluid pressure, buoyancy,
turbulence, temperature, or room geometry.
</li>
<li>
Furniture is shown for context but does not redirect the flow.
</li>
<li>
Colors indicate conceptual flow roles, not measured temperature
or speed.
</li>
<li>
Use a validated CFD or airflow-analysis tool for quantitative
predictions.
</li>
</ul>
</details>
</section>
</aside>
<div class="help">
<strong>Controls:</strong>
drag the orange heater to move it · drag the room to orbit ·
scroll to zoom · click the rear vent to toggle it
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and scene
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional toy room with a movable heater and airflow paths"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5dc);
scene.fog = new THREE.Fog(0xe9e5dc, 15, 29);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Camera controls are implemented locally; no examples or addons are used.
const cameraState = {
yaw: 0.69,
pitch: 0.48,
radius: 11.2,
target: new THREE.Vector3(0, 1.05, 0)
};
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x78909a, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2dc, 3.1);
sun.position.set(5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfe4f0, 0.8);
fill.position.set(-6, 4, 1);
scene.add(fill);
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
function standardMaterial(color, roughness = 0.82) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true
});
}
function addBox(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(...size);
const material = options.material || standardMaterial(color);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
position,
color
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
standardMaterial(color)
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, width = 350, height = 82) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
context.fillStyle = "rgba(255, 253, 248, 0.94)";
context.strokeStyle = "rgba(38, 51, 58, 0.2)";
context.lineWidth = 4;
context.beginPath();
context.roundRect(3, 3, width - 6, height - 6, 16);
context.fill();
context.stroke();
context.fillStyle = "#26333a";
context.font = "700 25px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.75, 0.41, 1);
sprite.renderOrder = 20;
return sprite;
}
const v3 = (x, y, z) => new THREE.Vector3(x, y, z);
// -------------------------------------------------------------------------
// Low-poly room shell
// -------------------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
addBox(
room,
[8.25, 0.18, 5.65],
[0, -0.09, 0],
0xd7b982,
{ receiveShadow: true }
);
// Back wall.
addBox(
room,
[8.25, 3.4, 0.18],
[0, 1.7, -2.73],
0xf1e8d7,
{ castShadow: false }
);
// A low side wall preserves the cutaway doll-house view.
addBox(
room,
[0.18, 1.25, 5.65],
[-4.04, 0.625, 0],
0xe5d8c2,
{ castShadow: false }
);
addBox(
room,
[8.05, 0.12, 0.09],
[0, 0.09, -2.59],
0xb99367
);
addBox(
room,
[0.09, 0.12, 5.35],
[-3.91, 0.09, 0],
0xb99367
);
// Window decoration.
addBox(
room,
[1.55, 1.12, 0.06],
[-1.25, 2.2, -2.61],
0x9ed2de,
{ castShadow: false }
);
addBox(
room,
[1.72, 0.09, 0.11],
[-1.25, 2.2, -2.55],
0xfffaf0
);
addBox(
room,
[0.09, 1.2, 0.11],
[-1.25, 2.2, -2.55],
0xfffaf0
);
// Rug.
addBox(
room,
[3.35, 0.035, 2.55],
[0.35, 0.025, 0.48],
0xd78365,
{ castShadow: false }
);
addBox(
room,
[2.75, 0.018, 1.95],
[0.35, 0.048, 0.48],
0xe6a27f,
{ castShadow: false }
);
// Sofa.
const sofa = new THREE.Group();
sofa.position.set(-2.35, 0, -1.45);
room.add(sofa);
addBox(sofa, [2.35, 0.42, 1.0], [0, 0.31, 0], 0x5e899d);
addBox(sofa, [2.35, 1.08, 0.22], [0, 0.84, -0.43], 0x50788b);
addBox(sofa, [0.25, 0.72, 1.0], [-1.08, 0.59, 0], 0x50788b);
addBox(sofa, [0.25, 0.72, 1.0], [1.08, 0.59, 0], 0x50788b);
addBox(sofa, [0.87, 0.17, 0.72], [-0.52, 0.59, 0.06], 0x7da8b8);
addBox(sofa, [0.87, 0.17, 0.72], [0.52, 0.59, 0.06], 0x7da8b8);
addBox(sofa, [0.57, 0.57, 0.17], [-0.54, 0.86, -0.22], 0xe6bb58);
addBox(sofa, [0.57, 0.57, 0.17], [0.54, 0.86, -0.22], 0xd78365);
// Small table.
const table = new THREE.Group();
table.position.set(2.65, 0, 0.72);
room.add(table);
addBox(table, [1.55, 0.13, 0.92], [0, 0.82, 0], 0xb9845c);
addBox(table, [0.13, 0.78, 0.13], [-0.57, 0.41, -0.28], 0x8d684c);
addBox(table, [0.13, 0.78, 0.13], [0.57, 0.41, -0.28], 0x8d684c);
addBox(table, [0.13, 0.78, 0.13], [-0.57, 0.41, 0.28], 0x8d684c);
addBox(table, [0.13, 0.78, 0.13], [0.57, 0.41, 0.28], 0x8d684c);
// Toy blocks.
addBox(room, [0.42, 0.42, 0.42], [1.77, 0.24, 1.73], 0x6e9f7a);
addBox(room, [0.34, 0.34, 0.34], [2.17, 0.20, 1.65], 0xe3b84f);
addBox(room, [0.3, 0.3, 0.3], [1.95, 0.61, 1.72], 0x6b8fb4);
// Low-poly plant.
addCylinder(room, 0.23, 0.18, 0.38, 8, [-3.43, 0.2, 1.72], 0xc47c55);
addCylinder(room, 0.04, 0.08, 0.85, 7, [-3.43, 0.78, 1.72], 0x567b4f);
addBox(room, [0.42, 0.12, 0.2], [-3.29, 1.05, 1.72], 0x668d5d);
addBox(room, [0.42, 0.12, 0.2], [-3.54, 0.84, 1.72], 0x557747);
// -------------------------------------------------------------------------
// Heater
// -------------------------------------------------------------------------
const heater = new THREE.Group();
heater.position.set(0.6, 0, 0.45);
scene.add(heater);
addBox(heater, [0.92, 1.02, 0.58], [0, 0.62, 0], 0xe76335);
addBox(heater, [0.99, 0.13, 0.63], [0, 1.17, 0], 0xf39453);
addBox(heater, [0.72, 0.72, 0.055], [0, 0.64, 0.315], 0x3c4245);
for (let i = 0; i < 5; i++) {
addBox(
heater,
[0.64, 0.025, 0.035],
[0, 0.41 + i * 0.115, 0.355],
0xb9aa96
);
}
addBox(heater, [0.15, 0.09, 0.08], [0.29, 0.96, 0.36], 0xf6d263);
addBox(heater, [0.72, 0.09, 0.35], [0, 0.08, -0.02], 0x4e5355);
addBox(heater, [0.09, 0.12, 0.13], [-0.32, 0.12, 0], 0x4e5355);
addBox(heater, [0.09, 0.12, 0.13], [0.32, 0.12, 0], 0x4e5355);
const heaterGlow = new THREE.PointLight(0xff8a3d, 0.75, 3.2, 2);
heaterGlow.position.set(0, 0.8, 0.45);
heater.add(heaterGlow);
const heaterLabel = makeLabel("DRAG HEATER");
heaterLabel.position.set(0, 1.58, 0);
heater.add(heaterLabel);
// -------------------------------------------------------------------------
// High rear vent
// -------------------------------------------------------------------------
const VENT_X = 2.35;
const VENT_Y = 2.65;
const vent = new THREE.Group();
vent.position.set(VENT_X, VENT_Y, -2.54);
scene.add(vent);
addBox(
vent,
[1.2, 0.74, 0.08],
[0, 0, 0],
0x39464a,
{ castShadow: false }
);
addBox(vent, [1.34, 0.09, 0.13], [0, 0.41, 0.05], 0xf7f0e3);
addBox(vent, [1.34, 0.09, 0.13], [0, -0.41, 0.05], 0xf7f0e3);
addBox(vent, [0.09, 0.74, 0.13], [-0.62, 0, 0.05], 0xf7f0e3);
addBox(vent, [0.09, 0.74, 0.13], [0.62, 0, 0.05], 0xf7f0e3);
const ventFlapPivot = new THREE.Group();
ventFlapPivot.position.set(0, 0.34, 0.09);
vent.add(ventFlapPivot);
addBox(
ventFlapPivot,
[1.12, 0.64, 0.065],
[0, -0.31, 0],
0xd7e1df
);
for (let i = 0; i < 3; i++) {
addBox(
ventFlapPivot,
[0.95, 0.025, 0.025],
[0, -0.17 - i * 0.14, 0.045],
0x89999b
);
}
const ventLabel = makeLabel("HIGH VENT");
ventLabel.position.set(0, 0.72, 0);
ventLabel.scale.set(1.42, 0.34, 1);
vent.add(ventLabel);
// -------------------------------------------------------------------------
// Airflow rendering
// -------------------------------------------------------------------------
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const warmMaterial = new THREE.MeshBasicMaterial({
color: 0xef6b3a,
transparent: true,
opacity: 0.56,
depthTest: false,
depthWrite: false
});
const coolMaterial = new THREE.MeshBasicMaterial({
color: 0x238ea8,
transparent: true,
opacity: 0.48,
depthTest: false,
depthWrite: false
});
const warmArrowMaterial = new THREE.MeshBasicMaterial({
color: 0xff7941,
transparent: true,
opacity: 0.96,
depthTest: false,
depthWrite: false
});
const coolArrowMaterial = new THREE.MeshBasicMaterial({
color: 0x25a8c2,
transparent: true,
opacity: 0.94,
depthTest: false,
depthWrite: false
});
const warmParticleMaterial = new THREE.MeshBasicMaterial({
color: 0xffb14a,
depthTest: false,
depthWrite: false
});
const coolParticleMaterial = new THREE.MeshBasicMaterial({
color: 0x66d1df,
depthTest: false,
depthWrite: false
});
let animatedPaths = [];
function createFlowPath(points, type, arrowCount = 4) {
if (points.length < 2) return;
const curve = new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.28
);
const isWarm = type === "warm";
const tubeRadius = isWarm ? 0.047 : 0.036;
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 42, tubeRadius, 5, false),
isWarm ? warmMaterial : coolMaterial
);
tube.renderOrder = 8;
flowGroup.add(tube);
const arrowGeometry = new THREE.ConeGeometry(
isWarm ? 0.115 : 0.095,
isWarm ? 0.31 : 0.26,
5
);
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < arrowCount; i++) {
const t = (i + 0.7) / (arrowCount + 0.35);
const arrow = new THREE.Mesh(
arrowGeometry,
isWarm ? warmArrowMaterial : coolArrowMaterial
);
arrow.position.copy(curve.getPointAt(t));
arrow.quaternion.setFromUnitVectors(
up,
curve.getTangentAt(t).normalize()
);
arrow.renderOrder = 9;
flowGroup.add(arrow);
}
const particles = [];
for (let i = 0; i < 3; i++) {
const particle = new THREE.Mesh(
new THREE.IcosahedronGeometry(isWarm ? 0.072 : 0.06, 0),
isWarm ? warmParticleMaterial : coolParticleMaterial
);
particle.renderOrder = 10;
flowGroup.add(particle);
particles.push({
mesh: particle,
offset: i / 3
});
}
animatedPaths.push({
curve,
particles,
speed: isWarm ? 0.095 : 0.075
});
}
function clearFlow() {
flowGroup.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
flowGroup.clear();
animatedPaths = [];
}
// -------------------------------------------------------------------------
// Predefined circulation rules
// -------------------------------------------------------------------------
function getHeaterCell(x, z) {
if (x <= -2.15) {
return {
key: "left",
title: "Left-wall guided cell",
rule:
"Left-zone rule: the rising plume bends toward the left wall before spreading across the upper room.",
farX: -3.42,
farZ: z >= 0 ? 1.45 : -1.3,
bendX: -3.05,
bendZ: z >= 0 ? 0.7 : -1.45
};
}
if (x >= 2.15) {
return {
key: "right",
title: "Right-wall guided cell",
rule:
"Right-zone rule: the rising plume bends toward the right wall before spreading across the upper room.",
farX: 3.42,
farZ: z >= 0 ? 1.45 : -1.3,
bendX: 3.05,
bendZ: z >= 0 ? 0.7 : -1.45
};
}
if (z <= -1.4) {
return {
key: "rear",
title: "Rear-wall pocket cell",
rule:
"Rear-zone rule: the plume rises close to the back wall, producing a compact upper-room loop.",
farX: x >= 0 ? -2.65 : 2.65,
farZ: -2.38,
bendX: x * 0.65,
bendZ: -2.15
};
}
if (z >= 1.35) {
return {
key: "front",
title: "Front-to-back circulation cell",
rule:
"Front-zone rule: the plume rises in the open front area and then travels rearward under the ceiling.",
farX: x >= 0 ? -2.8 : 2.8,
farZ: -1.95,
bendX: x * 0.65,
bendZ: -0.4
};
}
return {
key: "center",
title: "Central convection cell",
rule:
"Center-zone rule: the plume spreads broadly under the ceiling and returns through the room center.",
farX: x >= 0 ? -3.0 : 3.0,
farZ: z >= 0 ? -1.75 : 1.65,
bendX: (x + (x >= 0 ? -3.0 : 3.0)) * 0.52,
bendZ: (z + (z >= 0 ? -1.75 : 1.65)) * 0.5
};
}
let ventOpen = false;
function updateFlow() {
clearFlow();
const x = heater.position.x;
const z = heater.position.z;
const cell = getHeaterCell(x, z);
if (!ventOpen) {
// Sealed room: warm air rises and spreads, then descends at the
// prescribed far side and returns along the floor.
const warmPoints = [
v3(x, 1.22, z),
v3(x, 1.95, z),
v3(cell.bendX, 2.93, cell.bendZ),
v3(cell.farX, 2.7, cell.farZ)
];
const returnPoints = [
v3(cell.farX, 2.7, cell.farZ),
v3(cell.farX, 1.45, cell.farZ),
v3(cell.farX * 0.9, 0.28, cell.farZ * 0.85),
v3((x + cell.farX) * 0.5, 0.24, (z + cell.farZ) * 0.5),
v3(x, 0.5, z)
];
createFlowPath(warmPoints, "warm", 4);
createFlowPath(returnPoints, "cool", 4);
} else {
// Open vent: warm air exits through the high rear vent. The open
// front of the cutaway room acts as the illustrated intake opening.
let bend;
switch (cell.key) {
case "left":
bend = v3(-3.18, 2.58, -1.45);
break;
case "right":
bend = v3(3.18, 2.58, -1.45);
break;
case "rear":
bend = v3(x * 0.72, 2.56, -2.28);
break;
case "front":
bend = v3(x * 0.65, 2.83, -0.75);
break;
default:
bend = v3(x * 0.65, 2.9, -1.55);
}
const exhaustPoints = [
v3(x, 1.22, z),
v3(x, 2.03, z),
bend,
v3(VENT_X, VENT_Y, -2.54),
v3(VENT_X, VENT_Y, -3.45)
];
const intakePoints = [
v3(3.52, 0.3, 2.48),
v3(3.08, 0.25, 1.78),
v3(x * 0.82 + 0.35, 0.23, z * 0.65),
v3(x, 0.5, z)
];
createFlowPath(exhaustPoints, "warm", 5);
createFlowPath(intakePoints, "cool", 4);
}
updatePatternPanel(cell);
}
function updatePatternPanel(cell) {
const title = document.getElementById("patternTitle");
const description = document.getElementById("patternDescription");
const rule = document.getElementById("patternRule");
const steps = document.getElementById("flowSteps");
const badge = document.getElementById("modeBadge");
const ventState = document.getElementById("ventState");
const ventButton = document.getElementById("ventButton");
if (ventOpen) {
title.textContent = `${cell.title} · vent exchange`;
description.textContent =
"The high vent is open. The warm plume is routed toward the rear vent and exits; replacement air is shown entering through the open front and moving along the floor.";
steps.innerHTML = `
<li>Warm arrows rise from the heater and bend toward the high vent.</li>
<li>The exit arrow passes through the open vent.</li>
<li>Intake arrows travel from the open front toward the heater.</li>
`;
badge.textContent = "Vent open";
badge.classList.add("open");
ventState.textContent = "Open";
ventButton.textContent = "Close vent";
ventButton.setAttribute("aria-pressed", "true");
} else {
title.textContent = `${cell.title} · sealed recirculation`;
description.textContent =
"The vent is closed. The warm plume spreads below the ceiling, descends on the prescribed far side, and returns along the floor to the heater.";
steps.innerHTML = `
<li>Warm arrows rise from the heater and spread across the ceiling.</li>
<li>The descending return leg follows the far wall.</li>
<li>Low return arrows travel back toward the heater.</li>
`;
badge.textContent = "Vent sealed";
badge.classList.remove("open");
ventState.textContent = "Closed";
ventButton.textContent = "Open vent";
ventButton.setAttribute("aria-pressed", "false");
}
rule.textContent = cell.rule;
}
function toggleVent() {
ventOpen = !ventOpen;
updateFlow();
}
// -------------------------------------------------------------------------
// UI synchronization
// -------------------------------------------------------------------------
const heaterXInput = document.getElementById("heaterX");
const heaterZInput = document.getElementById("heaterZ");
const heaterXValue = document.getElementById("heaterXValue");
const heaterZValue = document.getElementById("heaterZValue");
function syncHeaterUI() {
const x = heater.position.x;
const z = heater.position.z;
heaterXInput.value = x.toFixed(2);
heaterZInput.value = z.toFixed(2);
heaterXValue.textContent = `${x.toFixed(2)} u`;
heaterZValue.textContent = `${z.toFixed(2)} u`;
}
function setHeaterPosition(x, z) {
heater.position.x = THREE.MathUtils.clamp(x, -3, 3);
heater.position.z = THREE.MathUtils.clamp(z, -2, 2);
syncHeaterUI();
updateFlow();
}
heaterXInput.addEventListener("input", () => {
setHeaterPosition(
Number(heaterXInput.value),
heater.position.z
);
});
heaterZInput.addEventListener("input", () => {
setHeaterPosition(
heater.position.x,
Number(heaterZInput.value)
);
});
document
.getElementById("resetHeater")
.addEventListener("click", () => setHeaterPosition(0.6, 0.45));
document
.getElementById("resetCamera")
.addEventListener("click", () => {
cameraState.yaw = 0.69;
cameraState.pitch = 0.48;
cameraState.radius = 11.2;
cameraState.target.set(0, 1.05, 0);
updateCamera();
});
document
.getElementById("ventButton")
.addEventListener("click", toggleVent);
// -------------------------------------------------------------------------
// Direct pointer controls: orbit camera, drag heater, click vent
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const floorPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
let orbiting = false;
let draggingHeater = false;
let previousPointerX = 0;
let previousPointerY = 0;
const heaterDragOffset = new THREE.Vector3();
function setPointerFromEvent(event) {
const bounds = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function pointerHitsHeater() {
return raycaster.intersectObject(heater, true).length > 0;
}
function pointerHitsVent() {
return raycaster.intersectObject(vent, true).length > 0;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
setPointerFromEvent(event);
if (pointerHitsHeater()) {
const floorIntersection = new THREE.Vector3();
if (raycaster.ray.intersectPlane(floorPlane, floorIntersection)) {
draggingHeater = true;
heaterDragOffset
.copy(heater.position)
.sub(floorIntersection);
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
return;
}
if (pointerHitsVent()) {
toggleVent();
return;
}
orbiting = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
setPointerFromEvent(event);
if (draggingHeater) {
const floorIntersection = new THREE.Vector3();
if (raycaster.ray.intersectPlane(floorPlane, floorIntersection)) {
setHeaterPosition(
floorIntersection.x + heaterDragOffset.x,
floorIntersection.z + heaterDragOffset.z
);
}
return;
}
if (orbiting) {
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.0045,
0.12,
1.42
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
return;
}
if (pointerHitsHeater()) {
renderer.domElement.style.cursor = "grab";
} else if (pointerHitsVent()) {
renderer.domElement.style.cursor = "pointer";
} else {
renderer.domElement.style.cursor = "grab";
}
});
function endPointerInteraction(event) {
draggingHeater = false;
orbiting = false;
renderer.domElement.style.cursor = "grab";
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointerInteraction);
renderer.domElement.addEventListener("pointercancel", endPointerInteraction);
renderer.domElement.addEventListener("pointerleave", () => {
if (!draggingHeater && !orbiting) {
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.009,
7.2,
17
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// -------------------------------------------------------------------------
// Animation and resizing
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Smoothly open or close the physical flap.
const flapTarget = ventOpen ? -1.28 : 0;
ventFlapPivot.rotation.x = THREE.MathUtils.lerp(
ventFlapPivot.rotation.x,
flapTarget,
0.12
);
// Moving particles reinforce the direction of each authored path.
for (const path of animatedPaths) {
for (const particle of path.particles) {
const t = (elapsed * path.speed + particle.offset) % 1;
particle.mesh.position.copy(path.curve.getPointAt(t));
}
}
const glow = 0.68 + Math.sin(elapsed * 3.2) * 0.08;
heaterGlow.intensity = glow;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
syncHeaterUI();
updateFlow();
resize();
animate();
</script>
</body>
</html>
```