Prompt specification
Build or customize the Three.js 3D scene "Insulation and Ventilation Tradeoff Explorer" 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: Insulation and Ventilation Tradeoff Explorer
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/insulation-and-ventilation-tradeoff-explorer-x3988
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a toy thermal model varying wall resistance and a separately defined ventilation term. Show assumptions and avoid treating energy results as indoor-air-quality or health guarantees.
Working Three.js Starter (insulation-and-ventilation-tradeoff-explorer-x3988):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Toy Thermal Model</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(14, 24, 36, 0.92);
--panel-2: rgba(24, 38, 53, 0.86);
--border: rgba(255, 255, 255, 0.13);
--text: #edf6ff;
--muted: #a9bdce;
--cyan: #72d8ff;
--orange: #ffad66;
--green: #82e0a5;
--red: #ff8585;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #b8d8e8;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas#scene.dragging { cursor: grabbing; }
#panel {
position: fixed;
z-index: 10;
left: 16px;
top: 16px;
bottom: 16px;
width: 390px;
overflow-y: auto;
padding: 18px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(3, 12, 22, 0.28);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: #577086 transparent;
}
h1 {
margin: 0;
font-size: 22px;
line-height: 1.1;
letter-spacing: -0.03em;
}
.subtitle {
margin: 7px 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
margin-bottom: 12px;
padding: 6px 9px;
border: 1px solid rgba(130, 224, 165, 0.35);
border-radius: 999px;
background: rgba(130, 224, 165, 0.09);
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 10px var(--green);
}
.notice {
margin-bottom: 14px;
padding: 10px 11px;
border-left: 3px solid var(--orange);
border-radius: 8px;
background: rgba(255, 173, 102, 0.08);
color: #ffe0c2;
font-size: 11px;
line-height: 1.45;
}
.section-title {
margin: 16px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.controls {
display: grid;
gap: 10px;
}
.control {
padding: 10px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.control-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 7px;
font-size: 12px;
}
.control-head output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 4px 0;
accent-color: var(--cyan);
cursor: pointer;
}
.control small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
select,
button {
width: 100%;
border: 1px solid var(--border);
border-radius: 9px;
background: #203245;
color: var(--text);
padding: 9px 10px;
font: inherit;
font-size: 12px;
}
button {
cursor: pointer;
font-weight: 750;
}
button:hover {
background: #2b425a;
}
button.primary {
border-color: rgba(114, 216, 255, 0.42);
background: rgba(114, 216, 255, 0.15);
color: #d9f5ff;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 70px;
padding: 10px;
border: 1px solid var(--border);
border-radius: 10px;
background: var(--panel-2);
}
.metric .label {
color: var(--muted);
font-size: 10px;
line-height: 1.25;
}
.metric .value {
margin-top: 6px;
font-size: 21px;
font-weight: 850;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.metric .unit {
margin-left: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 600;
letter-spacing: 0;
}
#tempValue { color: var(--cyan); }
#powerValue { color: var(--orange); }
#energyValue { color: var(--green); }
#chart {
display: block;
width: 100%;
height: 175px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(5, 13, 22, 0.58);
}
.legend {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
}
.legend span::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
margin-right: 5px;
border-radius: 50%;
background: var(--cyan);
}
.legend span:last-child::before {
background: var(--orange);
}
details {
margin-top: 13px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
summary {
padding: 10px 11px;
cursor: pointer;
color: #dcecf7;
font-size: 12px;
font-weight: 800;
}
.details-body {
padding: 0 11px 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.48;
}
.details-body ul {
margin: 6px 0;
padding-left: 17px;
}
.equation {
margin: 8px 0;
padding: 9px;
overflow-x: auto;
border-radius: 7px;
background: rgba(0, 0, 0, 0.24);
color: #d9f5ff;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.5;
white-space: nowrap;
}
.scope {
margin-top: 13px;
padding: 11px;
border: 1px solid rgba(255, 133, 133, 0.27);
border-radius: 10px;
background: rgba(255, 133, 133, 0.07);
color: #ffd1d1;
font-size: 10.5px;
line-height: 1.48;
}
#status {
display: flex;
justify-content: space-between;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
#cameraHint {
position: fixed;
z-index: 5;
right: 16px;
bottom: 14px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 999px;
background: rgba(14, 24, 36, 0.76);
color: white;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
}
#viewReset {
position: fixed;
z-index: 6;
right: 16px;
top: 16px;
width: auto;
padding: 8px 11px;
background: rgba(14, 24, 36, 0.82);
backdrop-filter: blur(8px);
}
@media (max-width: 760px) {
#panel {
left: 8px;
right: 8px;
top: auto;
bottom: 8px;
width: auto;
max-height: 53vh;
padding: 14px;
border-radius: 15px;
}
h1 { font-size: 19px; }
.subtitle { margin-bottom: 9px; }
#cameraHint { display: none; }
#viewReset { top: 8px; right: 8px; }
.metrics { grid-template-columns: repeat(3, 1fr); }
.metric { min-height: 62px; padding: 8px; }
.metric .value { font-size: 18px; }
.control { padding: 8px; }
#chart { height: 140px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly cutaway house thermal model"></canvas>
<button id="viewReset" type="button">Reset view</button>
<div id="cameraHint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<aside id="panel">
<div class="badge">Toy model · illustrative only</div>
<h1>Low-Poly Thermal House</h1>
<p class="subtitle">
Explore how nominal opaque-wall resistance and a separately calculated
ventilation heat-loss term affect a simplified room-temperature model.
</p>
<div class="notice">
Energy output is a model result, not an actual utility estimate. This
simulation does not establish indoor-air quality, comfort, health,
safety, or code compliance.
</div>
<div class="section-title">Model inputs</div>
<div class="controls">
<div class="control">
<div class="control-head">
<label for="wallR">Opaque wall resistance, R<sub>wall</sub></label>
<output id="wallROutput">2.4 m²K/W</output>
</div>
<input id="wallR" type="range" min="0.5" max="6" step="0.1" value="2.4">
<small>
Applies only to 72 m² of opaque wall. Lower R means greater conductive
heat loss through those walls.
</small>
</div>
<div class="control">
<div class="control-head">
<label for="ventACH">Ventilation rate</label>
<output id="ventOutput">0.50 ACH</output>
</div>
<input id="ventACH" type="range" min="0" max="2" step="0.05" value="0.5">
<small>
Entered separately from envelope conductance. In this toy model,
ventilation exchanges sensible heat only.
</small>
</div>
<div class="row">
<div class="control">
<div class="control-head">
<label for="outdoor">Outdoor</label>
<output id="outdoorOutput">5 °C</output>
</div>
<input id="outdoor" type="range" min="-15" max="35" step="1" value="5">
</div>
<div class="control">
<div class="control-head">
<label for="target">Setpoint</label>
<output id="targetOutput">20 °C</output>
</div>
<input id="target" type="range" min="16" max="24" step="0.5" value="20">
</div>
</div>
<div class="row">
<div class="control">
<div class="control-head">
<label for="maxPower">Max heater</label>
<output id="maxPowerOutput">3000 W</output>
</div>
<input id="maxPower" type="range" min="500" max="6000" step="100" value="3000">
</div>
<div class="control">
<div class="control-head">
<label for="speed">Time scale</label>
<output id="speedOutput">300×</output>
</div>
<select id="speed">
<option value="1">1× real time</option>
<option value="60">60×</option>
<option value="300" selected>300×</option>
<option value="900">900×</option>
</select>
</div>
</div>
<div class="row">
<button id="pause" class="primary" type="button">Pause simulation</button>
<button id="resetRun" type="button">Reset run</button>
</div>
</div>
<div class="section-title">Live model outputs</div>
<div class="metrics">
<div class="metric">
<div class="label">Indoor air temperature</div>
<div class="value"><span id="tempValue">18.0</span><span class="unit">°C</span></div>
</div>
<div class="metric">
<div class="label">Heater output</div>
<div class="value"><span id="powerValue">0</span><span class="unit">W</span></div>
</div>
<div class="metric">
<div class="label">Accumulated heater energy</div>
<div class="value"><span id="energyValue">0.000</span><span class="unit">kWh</span></div>
</div>
<div class="metric">
<div class="label">Envelope heat flow</div>
<div class="value"><span id="envValue">0</span><span class="unit">W</span></div>
</div>
<div class="metric">
<div class="label">Ventilation heat flow</div>
<div class="value"><span id="ventValue">0</span><span class="unit">W</span></div>
</div>
<div class="metric">
<div class="label">Simulated elapsed time</div>
<div class="value" style="font-size:17px"><span id="timeValue">00:00:00</span></div>
</div>
</div>
<div class="section-title">Temperature and heater history</div>
<canvas id="chart" aria-label="Chart of indoor temperature and heater power"></canvas>
<div class="legend">
<span>Indoor temperature</span>
<span>Heater power</span>
</div>
<details open>
<summary>Assumptions and equations</summary>
<div class="details-body">
<ul>
<li>Room: 8 m × 6 m × 3 m; volume 144 m³.</li>
<li>Gross wall area: 84 m²; assumed window area: 12 m².</li>
<li>
Opaque wall conductance:
<strong>72 / R<sub>wall</sub></strong> W/K.
</li>
<li>
Separate window, roof, and floor conductances are fixed at
12/0.35, 48/2.2, and 48/2.5 W/K respectively.
</li>
<li>
Ventilation conductance:
<strong>ρc<sub>p</sub> · V · ACH / 3600</strong>,
with ρc<sub>p</sub> = 1200 J/(m³K).
</li>
<li>
Effective heat capacity: 180 kJ/K. No moisture, thermal mass,
infiltration distribution, or thermal bridges are modeled.
</li>
<li>
Fixed internal/solar gain proxy: 300 W. No day/night cycle is
simulated.
</li>
<li>
Ideal 100%-efficient electric heater with a proportional-integral
controller. No cooling is modeled.
</li>
</ul>
<div class="equation">
C dT/dt = Qheater + Qgains<br>
− UAenv(Tin − Tout) − UAvent(Tin − Tout)
</div>
<div class="equation">
UAenv = 72/Rwall + 12/0.35 + 48/2.2 + 48/2.5<br>
UAvent = 1200 × 144 × ACH / 3600
</div>
<div id="derivedValues"></div>
</div>
</details>
<div class="scope">
<strong>Scope and limitations:</strong> The ventilation number is only a
sensible-heat exchange term. It does not calculate CO₂, humidity,
particles, pathogens, filtration, air distribution, or contaminant
removal. Ventilation should not be selected from this energy toy to
claim an indoor-air-quality or health benefit. Use validated building
and ventilation analysis, measurement, and applicable public-health
guidance for real decisions.
</div>
<div id="status">
<span id="runStatus">Running at 300×</span>
<span>Initial temperature: 18 °C</span>
</div>
</aside>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Toy thermal model
// -------------------------------------------------------------------------
const MODEL = Object.freeze({
roomWidth: 8,
roomDepth: 6,
roomHeight: 3,
volume: 144,
grossWallArea: 84,
windowArea: 12,
opaqueWallArea: 72,
roofArea: 48,
floorArea: 48,
windowR: 0.35,
roofR: 2.2,
floorR: 2.5,
heatCapacity: 180000, // J/K
rhoCp: 1200, // J/(m³ K)
fixedGain: 300, // W, proxy for solar + internal gains
proportionalGain: 700, // W/K
integralGain: 18, // W/(K s)
dt: 0.25 // fixed simulation step, seconds
});
const controls = {
wallR: 2.4,
ach: 0.5,
outdoor: 5,
target: 20,
maxPower: 3000,
speed: 300
};
const state = {
indoor: 18,
heater: 0,
integral: 0,
energyJ: 0,
simTime: 0,
paused: false,
sampleClock: 0,
history: []
};
const $ = id => document.getElementById(id);
const ui = {
wallR: $("wallR"),
ach: $("ventACH"),
outdoor: $("outdoor"),
target: $("target"),
maxPower: $("maxPower"),
speed: $("speed"),
pause: $("pause"),
resetRun: $("resetRun"),
chart: $("chart")
};
function envelopeConductance() {
return (
MODEL.opaqueWallArea / controls.wallR +
MODEL.windowArea / MODEL.windowR +
MODEL.roofArea / MODEL.roofR +
MODEL.floorArea / MODEL.floorR
);
}
function ventilationConductance() {
return MODEL.rhoCp * MODEL.volume * controls.ach / 3600;
}
function heatFlows() {
const delta = state.indoor - controls.outdoor;
const envUA = envelopeConductance();
const ventUA = ventilationConductance();
return {
envUA,
ventUA,
envelope: envUA * delta,
ventilation: ventUA * delta
};
}
function resetSimulation() {
state.indoor = 18;
state.heater = 0;
state.integral = 0;
state.energyJ = 0;
state.simTime = 0;
state.sampleClock = 0;
state.history = [{ t: 0, temp: state.indoor, power: 0 }];
updateUI();
drawChart();
}
function simulationStep(dt) {
const error = controls.target - state.indoor;
// PI controller with simple anti-windup.
const previousIntegral = state.integral;
const integralLimit = controls.maxPower / MODEL.integralGain;
state.integral = THREE.MathUtils.clamp(
state.integral + error * dt,
-integralLimit,
integralLimit
);
let requested =
MODEL.proportionalGain * error +
MODEL.integralGain * state.integral;
if (requested >= controls.maxPower && error > 0) {
state.integral = previousIntegral;
requested =
MODEL.proportionalGain * error +
MODEL.integralGain * state.integral;
} else if (requested <= 0 && error < 0) {
state.integral = previousIntegral;
requested =
MODEL.proportionalGain * error +
MODEL.integralGain * state.integral;
}
state.heater = THREE.MathUtils.clamp(requested, 0, controls.maxPower);
const flows = heatFlows();
const netPower =
state.heater +
MODEL.fixedGain -
flows.envelope -
flows.ventilation;
state.indoor += (netPower / MODEL.heatCapacity) * dt;
state.energyJ += state.heater * dt;
state.simTime += dt;
state.sampleClock += dt;
if (state.sampleClock >= 15) {
state.sampleClock -= 15;
state.history.push({
t: state.simTime,
temp: state.indoor,
power: state.heater
});
if (state.history.length > 900) {
state.history.shift();
}
}
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d8e8);
scene.fog = new THREE.Fog(0xb8d8e8, 24, 55);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.3, 1.15, 0);
const cameraState = {
yaw: 0.78,
pitch: 0.48,
radius: 18.5
};
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.cos(pitch) * Math.cos(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(pitch) * Math.sin(yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Lighting.
const hemi = new THREE.HemisphereLight(0xeaf7ff, 0x697b58, 2.0);
scene.add(hemi);
const sunLight = new THREE.DirectionalLight(0xfff1cc, 3.0);
sunLight.position.set(-8, 12, -6);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -15;
sunLight.shadow.camera.right = 15;
sunLight.shadow.camera.top = 15;
sunLight.shadow.camera.bottom = -15;
sunLight.shadow.camera.near = 0.5;
sunLight.shadow.camera.far = 45;
sunLight.shadow.bias = -0.0008;
scene.add(sunLight);
const fill = new THREE.DirectionalLight(0x9edfff, 0.7);
fill.position.set(8, 6, 8);
scene.add(fill);
// Materials.
const mat = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
flatShading: true,
roughness: 0.85,
...options
});
const wallMaterial = mat(0xf0e6cf);
const wallTrimMaterial = mat(0x52677a);
const floorMaterial = mat(0xb78b5e);
const plankMaterial = mat(0xd1aa79);
const darkWoodMaterial = mat(0x745039);
const glassMaterial = mat(0x83d7ef, {
transparent: true,
opacity: 0.66,
roughness: 0.2,
metalness: 0.05,
side: THREE.DoubleSide
});
const insulationMaterial = mat(0xf2b568);
const roofMaterial = mat(0x8b5d48);
const redMaterial = mat(0xef725e);
const orangeMaterial = mat(0xffa45c, {
emissive: 0x5c1900,
emissiveIntensity: 0.25
});
const blueMaterial = mat(0x66c9e8);
const greenMaterial = mat(0x5f9f68);
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
segments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground.
const ground = new THREE.Mesh(
new THREE.CircleGeometry(15, 32),
mat(0x91b783)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.18;
ground.receiveShadow = true;
scene.add(ground);
const groundDisk = new THREE.Mesh(
new THREE.CylinderGeometry(13, 13.4, 0.35, 16),
mat(0x769c69)
);
groundDisk.position.y = -0.36;
groundDisk.receiveShadow = true;
scene.add(groundDisk);
// House floor.
addBox(
scene,
new THREE.Vector3(8.4, 0.3, 6.4),
new THREE.Vector3(0, 0, 0),
floorMaterial
);
for (let i = 0; i < 8; i++) {
addBox(
scene,
new THREE.Vector3(0.96, 0.055, 6.05),
new THREE.Vector3(-3.45 + i * 0.99, 0.175, 0),
plankMaterial,
false
);
}
// Back wall, split around a window.
const wallT = 0.22;
const backZ = -3;
const sideWidth = 2.4;
const windowWidth = 3.2;
const windowBottom = 1.0;
const windowTop = 2.4;
addBox(
scene,
new THREE.Vector3(sideWidth, 3, wallT),
new THREE.Vector3(-2.8, 1.5, backZ),
wallMaterial
);
addBox(
scene,
new THREE.Vector3(sideWidth, 3, wallT),
new THREE.Vector3(2.8, 1.5, backZ),
wallMaterial
);
addBox(
scene,
new THREE.Vector3(windowWidth, windowBottom, wallT),
new THREE.Vector3(0, windowBottom / 2, backZ),
wallMaterial
);
addBox(
scene,
new THREE.Vector3(windowWidth, 3 - windowTop, wallT),
new THREE.Vector3(0, (3 + windowTop) / 2, backZ),
wallMaterial
);
// Left wall.
addBox(
scene,
new THREE.Vector3(wallT, 3, 6),
new THREE.Vector3(-4, 1.5, 0),
wallMaterial
);
// Cutaway corner posts and roof beams.
addBox(
scene,
new THREE.Vector3(0.26, 3.15, 0.26),
new THREE.Vector3(-3.9, 1.57, 2.9),
wallTrimMaterial
);
addBox(
scene,
new THREE.Vector3(0.26, 3.15, 0.26),
new THREE.Vector3(3.9, 1.57, 2.9),
wallTrimMaterial
);
addBox(
scene,
new THREE.Vector3(8.15, 0.24, 0.26),
new THREE.Vector3(0, 3.08, 2.9),
roofMaterial
);
addBox(
scene,
new THREE.Vector3(0.26, 0.24, 6.15),
new THREE.Vector3(-3.9, 3.08, 0),
roofMaterial
);
// Window frame and glass.
const glass = addBox(
scene,
new THREE.Vector3(windowWidth - 0.12, windowTop - windowBottom - 0.12, 0.04),
new THREE.Vector3(0, (windowBottom + windowTop) / 2, -2.86),
glassMaterial,
false
);
addBox(
scene,
new THREE.Vector3(windowWidth + 0.12, 0.10, 0.12),
new THREE.Vector3(0, windowBottom, -2.82),
wallTrimMaterial
);
addBox(
scene,
new THREE.Vector3(windowWidth + 0.12, 0.10, 0.12),
new THREE.Vector3(0, windowTop, -2.82),
wallTrimMaterial
);
addBox(
scene,
new THREE.Vector3(0.10, windowTop - windowBottom, 0.12),
new THREE.Vector3(-windowWidth / 2, (windowBottom + windowTop) / 2, -2.82),
wallTrimMaterial
);
addBox(
scene,
new THREE.Vector3(0.10, windowTop - windowBottom, 0.12),
new THREE.Vector3(windowWidth / 2, (windowBottom + windowTop) / 2, -2.82),
wallTrimMaterial
);
addBox(
scene,
new THREE.Vector3(0.09, windowTop - windowBottom, 0.13),
new THREE.Vector3(0, (windowBottom + windowTop) / 2, -2.80),
wallTrimMaterial
);
// Schematic insulation panels on the left wall.
const insulationPanels = [];
const panelZ = [-2.45, -1.47, -0.49, 0.49, 1.47, 2.45];
for (const z of panelZ) {
for (const y of [0.78, 2.12]) {
const panel = addBox(
scene,
new THREE.Vector3(1, 1.14, 0.84),
new THREE.Vector3(-3.84, y, z),
insulationMaterial
);
insulationPanels.push(panel);
}
}
// Interior furnishings.
const rug = addBox(
scene,
new THREE.Vector3(3.6, 0.035, 2.25),
new THREE.Vector3(0.8, 0.215, 0.8),
mat(0x688f99),
false
);
// Sofa.
addBox(
scene,
new THREE.Vector3(2.25, 0.45, 0.8),
new THREE.Vector3(-2.0, 0.5, 1.25),
mat(0x687e91)
);
addBox(
scene,
new THREE.Vector3(2.25, 0.75, 0.25),
new THREE.Vector3(-2.0, 0.88, 0.88),
mat(0x7f95a6)
);
addBox(
scene,
new THREE.Vector3(0.24, 0.6, 0.8),
new THREE.Vector3(-3.0, 0.7, 1.25),
mat(0x52697d)
);
addBox(
scene,
new THREE.Vector3(0.24, 0.6, 0.8),
new THREE.Vector3(-1.0, 0.7, 1.25),
mat(0x52697d)
);
// Table.
addCylinder(
scene,
0.75,
0.85,
0.12,
new THREE.Vector3(1.15, 0.78, 0.35),
darkWoodMaterial,
8
);
addCylinder(
scene,
0.12,
0.18,
0.55,
new THREE.Vector3(1.15, 0.47, 0.35),
wallTrimMaterial,
8
);
// Plant.
addCylinder(
scene,
0.34,
0.27,
0.42,
new THREE.Vector3(2.85, 0.42, -1.65),
mat(0xba704e),
7
);
const plant = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.55, 0),
greenMaterial
);
plant.position.set(2.85, 1.0, -1.65);
plant.castShadow = true;
scene.add(plant);
// Heater/radiator.
const heaterGroup = new THREE.Group();
heaterGroup.position.set(-3.15, 0, 2.25);
scene.add(heaterGroup);
addBox(
heaterGroup,
new THREE.Vector3(0.95, 0.13, 0.28),
new THREE.Vector3(0, 0.28, 0),
wallTrimMaterial
);
const heaterBars = [];
for (let i = 0; i < 6; i++) {
const bar = addBox(
heaterGroup,
new THREE.Vector3(0.095, 0.92, 0.16),
new THREE.Vector3(-0.38 + i * 0.15, 0.78, 0),
orangeMaterial
);
heaterBars.push(bar);
}
// Ventilation fan on the open right side.
const fanGroup = new THREE.Group();
fanGroup.position.set(4.28, 1.45, -0.35);
scene.add(fanGroup);
const fanHousing = new THREE.Mesh(
new THREE.TorusGeometry(0.68, 0.09, 4, 10),
wallTrimMaterial
);
fanHousing.rotation.y = Math.PI / 2;
fanHousing.castShadow = true;
fanGroup.add(fanHousing);
const rotor = new THREE.Group();
fanGroup.add(rotor);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.15, 0.22, 8),
orangeMaterial
);
hub.rotation.z = Math.PI / 2;
rotor.add(hub);
for (let i = 0; i < 5; i++) {
const blade = new THREE.Group();
blade.rotation.x = (i / 5) * Math.PI * 2;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 0.17, 0.49),
blueMaterial
);
mesh.position.z = 0.28;
mesh.castShadow = true;
blade.add(mesh);
rotor.add(blade);
}
// 3D thermometer.
const thermometer = new THREE.Group();
thermometer.position.set(3.1, 0, 3.55);
scene.add(thermometer);
addBox(
thermometer,
new THREE.Vector3(0.3, 2.35, 0.22),
new THREE.Vector3(0, 1.55, 0),
mat(0xf4f1dc),
false
);
const thermometerFill = addBox(
thermometer,
new THREE.Vector3(0.14, 1, 0.08),
new THREE.Vector3(0, 0.65, 0.13),
mat(0xef725e),
false
);
const bulb = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.31, 0),
mat(0xef725e)
);
bulb.position.set(0, 0.38, 0.13);
bulb.castShadow = true;
thermometer.add(bulb);
for (let i = 0; i < 7; i++) {
addBox(
thermometer,
new THREE.Vector3(i % 2 === 0 ? 0.23 : 0.15, 0.025, 0.03),
new THREE.Vector3(0.09, 0.6 + i * 0.28, 0.12),
wallTrimMaterial,
false
);
}
// Heat arrows.
const heatArrows = [];
for (let i = 0; i < 3; i++) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(-3.1 + i * 0.16, 0.45, 1.75 + i * 0.28),
1.1,
0xf46f54,
0.25,
0.13
);
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
heatArrows.push(arrow);
scene.add(arrow);
}
// Ventilation arrows.
const ventArrows = [];
for (let i = 0; i < 3; i++) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(4.55, 0.8 + i * 0.48, -0.9 + i * 0.45),
1.55,
0x4dbce5,
0.28,
0.15
);
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
ventArrows.push(arrow);
scene.add(arrow);
}
// Low-poly sun.
const sun = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.05, 0),
mat(0xffd06b, {
emissive: 0xff9b21,
emissiveIntensity: 1.2
})
);
sun.position.set(-7.8, 8.2, -8.0);
scene.add(sun);
// Simple trees.
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.1, z);
group.scale.setScalar(scale);
addCylinder(
group,
0.18,
0.24,
1.7,
new THREE.Vector3(0, 0.85, 0),
darkWoodMaterial,
6
);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.0, 0),
greenMaterial
);
crown.position.y = 2.1;
crown.scale.set(1, 1.15, 0.9);
crown.castShadow = true;
group.add(crown);
scene.add(group);
}
addTree(-7.0, 3.7, 1.15);
addTree(7.1, -3.9, 0.95);
addTree(7.4, 5.2, 0.8);
addTree(-8.0, -4.9, 0.75);
// Rocks.
const rockGeometry = new THREE.DodecahedronGeometry(0.45, 0);
const rockMaterial = mat(0x9aa39d);
[
[-5.7, -2.5, 0.6],
[6.2, 1.7, 0.8],
[-2.4, 6.1, 0.45]
].forEach(([x, z, s]) => {
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
rock.position.set(x, 0.02, z);
rock.scale.set(s, s * 0.65, s * 0.8);
rock.rotation.set(0.2, x, 0.1);
rock.castShadow = true;
scene.add(rock);
});
// Canvas sprite labels.
function makeLabel(text, color = "#173247") {
const c = document.createElement("canvas");
c.width = 512;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(244, 249, 252, 0.92)";
ctx.fillRect(8, 12, 496, 104);
ctx.strokeStyle = color;
ctx.lineWidth = 8;
ctx.strokeRect(8, 12, 496, 104);
ctx.fillStyle = color;
ctx.font = "bold 46px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
})
);
sprite.scale.set(2.25, 0.56, 1);
return sprite;
}
const wallLabel = makeLabel("R WALL");
wallLabel.position.set(-3.1, 3.45, 1.25);
scene.add(wallLabel);
const ventLabel = makeLabel("VENTILATION");
ventLabel.position.set(4.65, 2.75, -0.35);
scene.add(ventLabel);
const heaterLabel = makeLabel("IDEAL HEATER");
heaterLabel.position.set(-3.05, 1.9, 2.3);
scene.add(heaterLabel);
const sunLabel = makeLabel("SUN · VISUAL");
sunLabel.position.set(-7.8, 9.55, -8);
scene.add(sunLabel);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without Three.js addons.
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function resetCamera() {
cameraState.yaw = 0.78;
cameraState.pitch = 0.48;
cameraState.radius = 18.5;
updateCamera();
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.007;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.006,
0.12,
1.22
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
31
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
$("viewReset").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// UI and chart
// -------------------------------------------------------------------------
function formatTime(seconds) {
const s = Math.floor(seconds);
const h = Math.floor(s / 3600);
const m = Math.floor((s % 3600) / 60);
const sec = s % 60;
return [h, m, sec]
.map(v => String(v).padStart(2, "0"))
.join(":");
}
function temperatureColor(temperature) {
const cold = new THREE.Color(0x72d8ff);
const mild = new THREE.Color(0x82e0a5);
const warm = new THREE.Color(0xffad66);
if (temperature < 18) {
return cold.lerp(mild, THREE.MathUtils.clamp(
(temperature + 10) / 28, 0, 1
));
}
return mild.lerp(warm, THREE.MathUtils.clamp(
(temperature - 18) / 15, 0, 1
));
}
function updateUI() {
const flows = heatFlows();
$("wallROutput").textContent = `${controls.wallR.toFixed(1)} m²K/W`;
$("ventOutput").textContent = `${controls.ach.toFixed(2)} ACH`;
$("outdoorOutput").textContent = `${controls.outdoor.toFixed(0)} °C`;
$("targetOutput").textContent = `${controls.target.toFixed(1)} °C`;
$("maxPowerOutput").textContent = `${controls.maxPower.toFixed(0)} W`;
$("speedOutput").textContent = `${controls.speed}×`;
$("tempValue").textContent = state.indoor.toFixed(1);
$("powerValue").textContent = Math.round(state.heater).toLocaleString();
$("energyValue").textContent = (state.energyJ / 3.6e6).toFixed(3);
$("envValue").textContent = Math.round(flows.envelope).toLocaleString();
$("ventValue").textContent = Math.round(flows.ventilation).toLocaleString();
$("timeValue").textContent = formatTime(state.simTime);
const totalUA = flows.envUA + flows.ventUA;
const timeConstantMinutes = MODEL.heatCapacity / totalUA / 60;
$("derivedValues").innerHTML = `
<ul>
<li>Current total envelope conductance: <strong>${flows.envUA.toFixed(1)} W/K</strong>.</li>
<li>Separate ventilation conductance: <strong>${flows.ventUA.toFixed(1)} W/K</strong>.</li>
<li>Approximate lumped time constant: <strong>${timeConstantMinutes.toFixed(1)} min</strong>.</li>
</ul>
`;
$("runStatus").textContent = state.paused
? "Simulation paused"
: `Running at ${controls.speed}×`;
ui.pause.textContent = state.paused
? "Resume simulation"
: "Pause simulation";
}
function drawChart() {
const c = ui.chart;
const rect = c.getBoundingClientRect();
if (!rect.width || !rect.height) return;
const dpr = Math.min(window.devicePixelRatio, 2);
const width = rect.width;
const height = rect.height;
if (c.width !== Math.round(width * dpr) ||
c.height !== Math.round(height * dpr)) {
c.width = Math.round(width * dpr);
c.height = Math.round(height * dpr);
}
const ctx = c.getContext("2d");
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, width, height);
const pad = {
left: 35,
right: 39,
top: 12,
bottom: 24
};
const plotW = width - pad.left - pad.right;
const plotH = height - pad.top - pad.bottom;
ctx.font = "9px system-ui, sans-serif";
ctx.textBaseline = "middle";
// Grid and left temperature scale.
for (let t = 0; t <= 30; t += 10) {
const y = pad.top + plotH * (1 - t / 30);
ctx.strokeStyle = "rgba(255,255,255,0.09)";
ctx.beginPath();
ctx.moveTo(pad.left, y);
ctx.lineTo(width - pad.right, y);
ctx.stroke();
ctx.fillStyle = "#8eb4c9";
ctx.textAlign = "right";
ctx.fillText(`${t}°`, pad.left - 6, y);
}
// Right heater scale.
for (let i = 0; i <= 2; i++) {
const fraction = i / 2;
const y = pad.top + plotH * (1 - fraction);
const watts = Math.round(controls.maxPower * fraction);
ctx.fillStyle = "#c89d76";
ctx.textAlign = "left";
ctx.fillText(`${watts}W`, width - pad.right + 5, y);
}
const xMin = Math.max(0, state.simTime - 6 * 3600);
const xMax = Math.max(3600, state.simTime);
const xScale = t => pad.left + (t - xMin) / (xMax - xMin) * plotW;
// X-axis labels.
ctx.fillStyle = "#8eb4c9";
ctx.textAlign = "left";
ctx.fillText(formatTime(xMin).slice(0, 5), pad.left, height - 10);
ctx.textAlign = "right";
ctx.fillText(formatTime(xMax).slice(0, 5), width - pad.right, height - 10);
const points = state.history.filter(p => p.t >= xMin);
if (!points.length) return;
// Temperature line.
ctx.strokeStyle = "#72d8ff";
ctx.lineWidth = 2;
ctx.beginPath();
points.forEach((p, i) => {
const x = xScale(p.t);
const y = pad.top + plotH * (1 - THREE.MathUtils.clamp(p.temp / 30, 0, 1));
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.stroke();
// Heater line.
ctx.strokeStyle = "#ffad66";
ctx.lineWidth = 1.7;
ctx.beginPath();
points.forEach((p, i) => {
const x = xScale(p.t);
const y = pad.top + plotH * (1 - THREE.MathUtils.clamp(p.power / controls.maxPower, 0, 1));
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.stroke();
}
function syncInputValues() {
controls.wallR = Number(ui.wallR.value);
controls.ach = Number(ui.ach.value);
controls.outdoor = Number(ui.outdoor.value);
controls.target = Number(ui.target.value);
controls.maxPower = Number(ui.maxPower.value);
controls.speed = Number(ui.speed.value);
// Visual insulation thickness is intentionally schematic, not to scale.
const thickness = 0.07 + controls.wallR * 0.032;
for (const panel of insulationPanels) {
panel.scale.x = thickness;
panel.position.x = -3.89 + thickness / 2;
}
const cool = new THREE.Color(0x7fbed3);
const warm = new THREE.Color(0xf2b568);
insulationMaterial.color.copy(
cool.lerp(warm, THREE.MathUtils.clamp(
(controls.wallR - 0.5) / 5.5, 0, 1
))
);
updateUI();
drawChart();
}
[
ui.wallR,
ui.ach,
ui.outdoor,
ui.target,
ui.maxPower,
ui.speed
].forEach(input => {
input.addEventListener("input", syncInputValues);
});
ui.pause.addEventListener("click", () => {
state.paused = !state.paused;
updateUI();
});
ui.resetRun.addEventListener("click", resetSimulation);
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
let previousTime = performance.now();
let uiClock = 0;
let chartClock = 0;
function animate(now) {
const realDt = Math.min((now - previousTime) / 1000, 0.1);
previousTime = now;
if (!state.paused) {
let remaining = realDt * controls.speed;
// Keep each frame bounded while retaining the fixed integration step.
while (remaining >= MODEL.dt) {
simulationStep(MODEL.dt);
remaining -= MODEL.dt;
}
}
// Fan motion and heat-flow indicators.
rotor.rotation.x += realDt * (1.5 + controls.ach * 10);
const heaterFraction = state.heater / Math.max(controls.maxPower, 1);
orangeMaterial.emissiveIntensity = 0.15 + heaterFraction * 1.6;
const flowColor = temperatureColor(state.indoor);
thermometerFill.material.color.copy(flowColor);
bulb.material.color.copy(flowColor);
const fillHeight = THREE.MathUtils.clamp(
(state.indoor + 10) / 50, 0.04, 1
) * 1.95;
thermometerFill.scale.y = fillHeight;
thermometerFill.position.y = 0.63 + fillHeight / 2;
heatArrows.forEach((arrow, i) => {
arrow.visible = state.heater > 10;
arrow.setLength(
0.65 + heaterFraction * 1.2,
0.25,
0.13
);
arrow.position.y = 0.45 + ((now * 0.00055 + i * 0.45) % 1.2);
arrow.line.material.opacity = 0.35 + heaterFraction * 0.55;
arrow.cone.material.opacity = 0.45 + heaterFraction * 0.55;
});
ventArrows.forEach((arrow, i) => {
arrow.visible = controls.ach > 0.01;
arrow.setLength(
0.8 + Math.min(controls.ach, 1.2) * 0.85,
0.28,
0.15
);
arrow.position.y = 0.8 + i * 0.48;
arrow.line.material.opacity = 0.35 + Math.min(controls.ach, 1) * 0.5;
arrow.cone.material.opacity = 0.45 + Math.min(controls.ach, 1) * 0.45;
});
// Gentle sun rotation.
sun.rotation.y += realDt * 0.12;
uiClock += realDt;
chartClock += realDt;
if (uiClock > 0.12) {
updateUI();
uiClock = 0;
}
if (chartClock > 0.45) {
drawChart();
chartClock = 0;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
drawChart();
});
syncInputValues();
resetSimulation();
requestAnimationFrame(animate);
</script>
</body>
</html>
```