Prompt specification
Build or customize the Three.js 3D scene "Two Tiny Houses Envelope Comparison" 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: Two Tiny Houses Envelope Comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-tiny-houses-envelope-comparison-x3987
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring matched schematic houses differing in one envelope property. Use an explicitly simplified thermal model and separate geometric design from measured real-building performance. Voxel style.
Working Three.js Starter (two-tiny-houses-envelope-comparison-x3987):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Envelope Lab — One-Variable Voxel Study</title>
<style>
:root {
--ink: #17252d;
--muted: #60717a;
--paper: rgba(248, 249, 245, 0.94);
--line: rgba(23, 37, 45, 0.13);
--a: #168c9d;
--a-soft: #d9f0f1;
--b: #d85f45;
--b-soft: #f8e2dc;
--warm: #ef7652;
--shadow: 0 18px 50px rgba(20, 37, 42, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe5e2;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.glass-card {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(430px, calc(100vw - 400px));
padding: 20px 22px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--warm);
box-shadow: 13px 0 0 #263c47;
}
h1 {
margin: 0;
font-size: clamp(25px, 2.6vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
}
#intro p {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.intro-tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 15px;
}
.tag {
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(255, 255, 255, 0.45);
color: #44565f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#panel {
position: fixed;
z-index: 20;
top: 20px;
right: 20px;
width: 348px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 18px;
border-radius: 18px;
scrollbar-width: thin;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.panel-heading h2 {
margin: 0 0 3px;
font-size: 17px;
letter-spacing: -0.025em;
}
.panel-heading p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
margin-bottom: 16px;
padding: 4px;
border-radius: 10px;
background: #e6ebe7;
}
.mode-switch button {
min-height: 34px;
padding: 7px 8px;
border: 0;
border-radius: 7px;
background: transparent;
color: #64747c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.mode-switch button.active {
background: #fff;
color: var(--ink);
box-shadow: 0 2px 8px rgba(25, 44, 51, 0.1);
}
.property-note {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 8px;
margin-bottom: 16px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.45);
}
.property-note .value {
font-size: 18px;
font-weight: 850;
letter-spacing: -0.04em;
}
.property-note .unit {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.property-note .only {
padding: 4px 6px;
border-radius: 5px;
background: #e9eeea;
color: #63737a;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-row {
margin-bottom: 14px;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
font-size: 11px;
font-weight: 750;
}
#temperatureValue {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
accent-color: var(--ink);
cursor: pointer;
}
.result-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.result {
position: relative;
overflow: hidden;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.52);
}
.result::after {
content: "";
position: absolute;
right: -12px;
bottom: -18px;
width: 56px;
height: 56px;
border-radius: 14px;
transform: rotate(18deg);
opacity: 0.42;
}
.result.a::after {
background: var(--a-soft);
}
.result.b::after {
background: var(--b-soft);
}
.result-label {
position: relative;
z-index: 1;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.result-u {
position: relative;
z-index: 1;
margin-top: 4px;
font-size: 10px;
color: #52636b;
}
.result-value {
position: relative;
z-index: 1;
margin-top: 9px;
font-size: 27px;
font-weight: 850;
line-height: 1;
letter-spacing: -0.055em;
font-variant-numeric: tabular-nums;
}
.result-value small {
margin-left: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0;
}
.mini-bar {
position: relative;
z-index: 1;
height: 4px;
margin-top: 11px;
overflow: hidden;
border-radius: 4px;
background: #e2e7e3;
}
.mini-bar span {
display: block;
width: 50%;
height: 100%;
border-radius: inherit;
transition: width 180ms ease;
}
.result.a .mini-bar span {
background: var(--a);
}
.result.b .mini-bar span {
background: var(--b);
}
.delta-strip {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
padding: 10px 12px;
border-radius: 10px;
background: #263b45;
color: #f5f7f4;
}
.delta-strip span {
font-size: 10px;
line-height: 1.35;
}
#delta {
flex: 0 0 auto;
color: #ffc1a8;
font-size: 22px;
font-weight: 850;
letter-spacing: -0.04em;
}
details {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
summary {
cursor: pointer;
color: #3d515a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.equation {
margin: 12px 0 10px;
padding: 10px;
border-radius: 8px;
background: #e8ede9;
color: #344851;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.55;
}
.input-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px 12px;
margin: 0;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.input-list b {
color: #34474f;
}
.warning {
margin-top: 13px;
padding: 11px 12px;
border: 1px solid rgba(216, 95, 69, 0.22);
border-radius: 9px;
background: rgba(248, 226, 220, 0.6);
color: #6c473d;
font-size: 9px;
line-height: 1.55;
}
.warning strong {
display: block;
margin-bottom: 3px;
color: #7e4032;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#labels {
position: fixed;
z-index: 8;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: 160px;
padding: 9px 11px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 9px;
background: rgba(250, 251, 247, 0.92);
box-shadow: 0 8px 22px rgba(24, 42, 48, 0.15);
backdrop-filter: blur(8px);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -9px;
width: 1px;
height: 9px;
background: rgba(41, 57, 64, 0.34);
}
.scene-label .name {
display: flex;
align-items: center;
gap: 6px;
color: #263a43;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-label .dot {
width: 7px;
height: 7px;
border-radius: 2px;
}
.scene-label.a .dot {
background: var(--a);
}
.scene-label.b .dot {
background: var(--b);
}
.scene-label .sub {
margin-top: 4px;
color: #6a7a81;
font-size: 9px;
line-height: 1.4;
}
.scene-label .output {
margin-top: 6px;
padding-top: 6px;
border-top: 1px solid rgba(31, 49, 57, 0.1);
color: #2f444d;
font-size: 11px;
font-weight: 800;
}
.geometry-mode .model-only {
display: none !important;
}
#legend {
position: fixed;
z-index: 10;
left: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 13px;
padding: 10px 13px;
border-radius: 10px;
color: #50636b;
font-size: 9px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
background: #e7e3d7;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.swatch.output-swatch {
background: var(--warm);
box-shadow: 0 0 8px rgba(239, 118, 82, 0.55);
}
#controls-hint {
position: fixed;
z-index: 10;
right: 20px;
bottom: 20px;
display: flex;
gap: 7px;
pointer-events: none;
}
#reset {
pointer-events: auto;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 9px;
background: rgba(248, 249, 245, 0.9);
color: #40545d;
box-shadow: var(--shadow);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#reset:hover {
background: #fff;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #dbe5e2;
color: #43565f;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
#intro {
width: calc(100vw - 40px);
max-width: 430px;
}
#intro p {
display: none;
}
#panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 46vh;
}
#legend {
display: none;
}
#controls-hint {
top: 126px;
right: 12px;
bottom: auto;
}
}
@media (max-width: 560px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
h1 {
font-size: 25px;
}
.intro-tags {
margin-top: 10px;
}
#panel {
right: 8px;
bottom: 8px;
left: 8px;
max-height: 48vh;
padding: 14px;
}
#controls-hint {
top: 120px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel comparison of two schematic houses"></canvas>
<header id="intro" class="glass-card">
<div class="eyebrow">Envelope Lab / Study 01</div>
<h1>Two houses.<br />One variable.</h1>
<p>
Matched voxel geometry and identical thermal inputs, with only the
schematic glazing U-value changed. The warm columns are model outputs,
not measured building performance.
</p>
<div class="intro-tags">
<span class="tag">Schematic geometry</span>
<span class="tag">Synthetic estimate</span>
<span class="tag">Not calibrated</span>
</div>
</header>
<aside id="panel" class="glass-card" aria-label="Comparison controls and model results">
<div class="panel-heading">
<div>
<h2>Glazing package comparison</h2>
<p>Everything else remains matched.</p>
</div>
</div>
<div class="mode-switch" role="group" aria-label="Scene display mode">
<button id="modeGeometry" type="button">Design geometry</button>
<button id="modeThermal" class="active" type="button">Thermal overlay</button>
</div>
<div class="property-note">
<div class="value">
<span id="uA">1.8</span>
<span class="unit">House A / W/m²K</span>
</div>
<span class="only">Only variable</span>
<div class="value">
<span id="uB">5.7</span>
<span class="unit">House B / W/m²K</span>
</div>
</div>
<div class="control-row">
<label class="control-label" for="temperature">
<span>Outdoor temperature</span>
<span id="temperatureValue">0 °C</span>
</label>
<input
id="temperature"
type="range"
min="-15"
max="15"
step="1"
value="0"
/>
</div>
<div class="result-grid">
<article class="result a">
<div class="result-label">House A / Baseline</div>
<div class="result-u">Ug = 1.8 W/m²K</div>
<div class="result-value"><span id="qA">1.45</span><small>kW</small></div>
<div class="mini-bar"><span id="barA"></span></div>
</article>
<article class="result b">
<div class="result-label">House B / Variant</div>
<div class="result-u">Ug = 5.7 W/m²K</div>
<div class="result-value"><span id="qB">2.55</span><small>kW</small></div>
<div class="mini-bar"><span id="barB"></span></div>
</article>
</div>
<div class="delta-strip">
<span>Variant heat-loss estimate relative to baseline</span>
<strong id="delta">+76%</strong>
</div>
<details>
<summary>Simplified model inputs</summary>
<div class="equation">
Q̇ = (U<sub>w</sub>A<sub>w</sub> + U<sub>r</sub>A<sub>r</sub><br />
+ U<sub>f</sub>A<sub>f</sub> + U<sub>g</sub>A<sub>g</sub><br />
+ 0.33 · ACH · V) · (T<sub>in</sub> − T<sub>out</sub>)
</div>
<div class="input-list">
<span><b>Indoor:</b> 21 °C</span>
<span><b>Volume:</b> 144 m³</span>
<span><b>Wall U:</b> 0.22 W/m²K</span>
<span><b>Roof U:</b> 0.16 W/m²K</span>
<span><b>Floor U:</b> 0.22 W/m²K</span>
<span><b>Ventilation:</b> 0.25 ACH</span>
<span><b>Opaque wall:</b> 67.2 m²</span>
<span><b>Glazing:</b> 13.44 m²</span>
<span><b>Roof / floor:</b> 48 m² each</span>
<span><b>Air capacity:</b> 0.33 Wh/m³K</span>
</div>
<div class="warning">
<strong>Separation of design and performance</strong>
The geometry is an illustrative design model. The displayed values are
synthetic steady-state heat-loss estimates from the listed assumptions.
They are not observations, a calibrated simulation, a code-compliance
result, or evidence about real buildings. Solar gains, internal gains,
thermal mass, moisture, thermal bridges, and time-dependent airflow
are omitted. The floor boundary is assumed equal to outdoor temperature.
</div>
</details>
</aside>
<div id="labels">
<div id="labelA" class="scene-label a">
<div class="name"><span class="dot"></span>House A / Baseline</div>
<div class="sub">Matched shell · Ug 1.8 W/m²K</div>
<div class="output model-only"></div>
</div>
<div id="labelB" class="scene-label b">
<div class="name"><span class="dot"></span>House B / Variant</div>
<div class="sub">Matched shell · Ug 5.7 W/m²K</div>
<div class="output model-only"></div>
</div>
</div>
<div id="legend" class="glass-card">
<div class="legend-item">
<span class="swatch"></span>
Matched design geometry
</div>
<div class="legend-item">
<span class="swatch output-swatch"></span>
Synthetic heat-loss output
</div>
</div>
<div id="controls-hint">
<button id="reset" type="button">Reset view</button>
</div>
<div id="loading">Loading voxel study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const ui = {
geometry: document.querySelector("#modeGeometry"),
thermal: document.querySelector("#modeThermal"),
temperature: document.querySelector("#temperature"),
temperatureValue: document.querySelector("#temperatureValue"),
qA: document.querySelector("#qA"),
qB: document.querySelector("#qB"),
barA: document.querySelector("#barA"),
barB: document.querySelector("#barB"),
delta: document.querySelector("#delta"),
labelA: document.querySelector("#labelA"),
labelB: document.querySelector("#labelB"),
reset: document.querySelector("#reset")
};
// -------------------------------------------------------------------------
// Explicitly simplified thermal model.
// All areas are derived from the same schematic dimensions used in the scene.
// -------------------------------------------------------------------------
const MODEL = {
indoorTemperature: 21,
width: 8,
depth: 6,
wallHeight: 3,
windowWidth: 1.6,
windowHeight: 1.4,
windowCount: 6,
doorWidth: 1.2,
doorHeight: 1.9,
uWall: 0.22,
uRoof: 0.16,
uFloor: 0.22,
uGlazingA: 1.8,
uGlazingB: 5.7,
airHeatCapacity: 0.33,
ach: 0.25
};
MODEL.volume =
MODEL.width * MODEL.depth * MODEL.wallHeight;
MODEL.grossWallArea =
2 * (MODEL.width + MODEL.depth) * MODEL.wallHeight;
MODEL.glazingArea =
MODEL.windowWidth *
MODEL.windowHeight *
MODEL.windowCount;
MODEL.doorArea =
MODEL.doorWidth *
MODEL.doorHeight;
MODEL.opaqueWallArea =
MODEL.grossWallArea -
MODEL.glazingArea -
MODEL.doorArea;
MODEL.roofArea = MODEL.width * MODEL.depth;
MODEL.floorArea = MODEL.width * MODEL.depth;
function estimateHeatLoss(outdoorTemperature, glazingU) {
const deltaT = MODEL.indoorTemperature - outdoorTemperature;
const components = {
wall:
MODEL.uWall *
MODEL.opaqueWallArea *
deltaT,
roof:
MODEL.uRoof *
MODEL.roofArea *
deltaT,
floor:
MODEL.uFloor *
MODEL.floorArea *
deltaT,
glazing:
glazingU *
MODEL.glazingArea *
deltaT,
ventilation:
MODEL.airHeatCapacity *
MODEL.ach *
MODEL.volume *
deltaT
};
components.total =
components.wall +
components.roof +
components.floor +
components.glazing +
components.ventilation;
return components;
}
let currentMode = "thermal";
let currentOutdoor = Number(ui.temperature.value);
// -------------------------------------------------------------------------
// Renderer and scene.
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe5e2);
scene.fog = new THREE.Fog(0xdbe5e2, 28, 56);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(
0xf5fbff,
0x718078,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2dc, 3.25);
sun.position.set(-9, 17, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e5ee, 0.75);
fill.position.set(10, 7, -11);
scene.add(fill);
// Shared geometry/materials for the matched scene elements.
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xc8d3ce,
roughness: 0.96
});
const ground = new THREE.Mesh(
new THREE.BoxGeometry(40, 0.5, 28),
groundMaterial
);
ground.position.y = -0.25;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(32, 32, 0x9aaba5, 0xb5c2bd);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xb9c5c0,
roughness: 0.92
});
const foundationMaterial = new THREE.MeshStandardMaterial({
color: 0x7f8b88,
roughness: 0.92
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x2f4149,
roughness: 0.72,
metalness: 0.08
});
const doorMaterial = new THREE.MeshStandardMaterial({
color: 0x57696d,
roughness: 0.78
});
const pathMaterial = new THREE.MeshStandardMaterial({
color: 0xa9b5af,
roughness: 0.95
});
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x80634d,
roughness: 1
});
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x5e8b68,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0x78a078,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0x4f7860,
roughness: 1
})
];
const outputMaterial = new THREE.MeshStandardMaterial({
color: 0xef7652,
emissive: 0xa62f19,
emissiveIntensity: 0.38,
roughness: 0.55
});
const outputSocketMaterial = new THREE.MeshStandardMaterial({
color: 0x4b5b60,
roughness: 0.9
});
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addPlatform(x) {
addBox(
scene,
[12.2, 0.3, 9.2],
[x, 0.15, 0],
platformMaterial,
false
);
}
function addVoxelTree(parent, x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
parent.add(tree);
addBox(tree, [0.34, 1.55, 0.34], [0, 0.775, 0], trunkMaterial);
addBox(tree, [1.7, 0.72, 1.7], [0, 1.65, 0], leafMaterials[0]);
addBox(tree, [1.35, 0.72, 1.35], [0, 2.25, 0], leafMaterials[1]);
addBox(tree, [0.9, 0.62, 0.9], [0, 2.82, 0], leafMaterials[2]);
}
function addBush(parent, x, z) {
addBox(
parent,
[0.85, 0.55, 0.85],
[x, 0.275, z],
leafMaterials[2]
);
addBox(
parent,
[0.58, 0.42, 0.58],
[x + 0.42, 0.21, z + 0.12],
leafMaterials[0]
);
}
function addWindow(parent, x, y, z, rotation, glassMaterial) {
const windowGroup = new THREE.Group();
windowGroup.position.set(x, y, z);
windowGroup.rotation.y = rotation;
parent.add(windowGroup);
addBox(
windowGroup,
[1.86, 1.66, 0.12],
[0, 0, 0],
frameMaterial
);
addBox(
windowGroup,
[1.6, 1.4, 0.13],
[0, 0, 0.075],
glassMaterial,
false
);
addBox(
windowGroup,
[0.075, 1.4, 0.16],
[0, 0, 0.09],
frameMaterial,
false
);
addBox(
windowGroup,
[1.6, 0.075, 0.16],
[0, 0, 0.09],
frameMaterial,
false
);
}
function addOutputColumn(parent) {
const column = new THREE.Group();
column.position.set(5.03, 0, -2.35);
parent.add(column);
addBox(
column,
[0.66, 0.18, 0.66],
[0, 0.09, 0],
outputSocketMaterial
);
const segments = [];
for (let i = 0; i < 12; i++) {
const segment = addBox(
column,
[0.43, 0.27, 0.43],
[0, 0.31 + i * 0.3, 0],
outputMaterial
);
segments.push(segment);
}
return { group: column, segments };
}
function createHouse({
x,
accent,
label
}) {
const group = new THREE.Group();
group.position.set(x, 0.3, 0);
scene.add(group);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xe8e4d8,
roughness: 0.92
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x536570,
roughness: 0.82,
metalness: 0.04
});
const glassMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.25,
roughness: 0.22,
metalness: 0.05,
transparent: true,
opacity: 0.94
});
// Foundation.
addBox(group, [8.55, 0.3, 6.55], [0, 0.15, 0], foundationMaterial);
// Four opaque walls. The same dimensions are used for both houses.
addBox(group, [8, 3, 0.22], [0, 1.8, 3], wallMaterial);
addBox(group, [8, 3, 0.22], [0, 1.8, -3], wallMaterial);
addBox(group, [0.22, 3, 6], [-4, 1.8, 0], wallMaterial);
addBox(group, [0.22, 3, 6], [4, 1.8, 0], wallMaterial);
// Voxel corner blocks.
for (const cornerX of [-3.9, 3.9]) {
for (const cornerZ of [-2.9, 2.9]) {
addBox(
group,
[0.32, 3.06, 0.32],
[cornerX, 1.83, cornerZ],
wallMaterial
);
}
}
// Six identical 1.6 m × 1.4 m schematic windows.
addWindow(group, -2.55, 1.82, 3.17, 0, glassMaterial);
addWindow(group, 2.55, 1.82, 3.17, 0, glassMaterial);
addWindow(group, -2.55, 1.82, -3.17, Math.PI, glassMaterial);
addWindow(group, 2.55, 1.82, -3.17, Math.PI, glassMaterial);
addWindow(group, 4.17, 1.82, 1.45, Math.PI / 2, glassMaterial);
addWindow(group, -4.17, 1.82, -1.45, -Math.PI / 2, glassMaterial);
// Door.
addBox(
group,
[1.45, 2.13, 0.13],
[0, 1.365, 3.16],
frameMaterial
);
addBox(
group,
[1.2, 1.9, 0.14],
[0, 1.31, 3.24],
doorMaterial
);
addBox(
group,
[0.09, 0.09, 0.08],
[0.38, 1.35, 3.34],
frameMaterial,
false
);
// Stepped voxel roof. Geometry does not vary between the two houses.
for (let i = 0; i < 6; i++) {
const depth = 6.65 - i * 0.73;
addBox(
group,
[8.62, 0.25, depth],
[0, 3.425 + i * 0.25, 0],
roofMaterial
);
}
// Small chimney and porch details.
addBox(group, [0.56, 1.1, 0.56], [2.75, 4.28, -0.65], foundationMaterial);
addBox(group, [0.7, 0.16, 0.7], [2.75, 4.85, -0.65], roofMaterial);
addBox(group, [2.0, 0.18, 0.75], [0, 0.09, 3.72], pathMaterial);
addBox(group, [1.55, 0.15, 0.72], [0, 0.075, 4.34], pathMaterial);
addBox(group, [1.2, 0.12, 0.72], [0, 0.06, 4.96], pathMaterial);
// Matched landscaping around each schematic.
addVoxelTree(group, -4.85, -2.85, 0.88);
addBush(group, -4.65, 2.95);
addBush(group, 3.65, 3.65);
const output = addOutputColumn(group);
const anchor = new THREE.Vector3(0, 5.35, 0);
group.localToWorld(anchor);
return {
group,
glassMaterial,
accent,
output,
anchor,
label
};
}
addPlatform(-7);
addPlatform(7);
const houseA = createHouse({
x: -7,
accent: 0x4ebed0,
label: ui.labelA
});
const houseB = createHouse({
x: 7,
accent: 0xf08062,
label: ui.labelB
});
// -------------------------------------------------------------------------
// Direct camera controls: no controls addon is imported.
// -------------------------------------------------------------------------
const initialCamera = {
radius: 24,
theta: 0.56,
phi: 0.72,
target: new THREE.Vector3(0, 1.15, 0)
};
const orbit = {
radius: initialCamera.radius,
theta: initialCamera.theta,
phi: initialCamera.phi,
target: initialCamera.target.clone()
};
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);
}
function resetCamera() {
orbit.radius = initialCamera.radius;
orbit.theta = initialCamera.theta;
orbit.phi = initialCamera.phi;
orbit.target.copy(initialCamera.target);
updateCamera();
}
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
orbit.theta -= dx * 0.0055;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.0045,
0.32,
1.28
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
14,
38
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") orbit.theta += 0.08;
if (event.key === "ArrowRight") orbit.theta -= 0.08;
if (event.key === "ArrowUp") orbit.phi = Math.max(0.32, orbit.phi - 0.06);
if (event.key === "ArrowDown") orbit.phi = Math.min(1.28, orbit.phi + 0.06);
if (event.key === "+" || event.key === "=") orbit.radius = Math.max(14, orbit.radius - 1);
if (event.key === "-") orbit.radius = Math.min(38, orbit.radius + 1);
if (event.key.toLowerCase() === "r") resetCamera();
updateCamera();
});
ui.reset.addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Presentation and result updates.
// -------------------------------------------------------------------------
function setMode(mode) {
currentMode = mode;
const thermal = mode === "thermal";
document.body.classList.toggle("geometry-mode", !thermal);
ui.geometry.classList.toggle("active", !thermal);
ui.thermal.classList.toggle("active", thermal);
const neutralGlass = new THREE.Color(0xb8c9c8);
for (const house of [houseA, houseB]) {
house.output.group.visible = thermal;
if (thermal) {
house.glassMaterial.color.set(house.accent);
house.glassMaterial.emissive.set(house.accent);
house.glassMaterial.emissiveIntensity = 0.27;
} else {
house.glassMaterial.color.copy(neutralGlass);
house.glassMaterial.emissive.set(0x000000);
house.glassMaterial.emissiveIntensity = 0;
}
}
updateResults();
}
function updateResults() {
const resultA = estimateHeatLoss(
currentOutdoor,
MODEL.uGlazingA
);
const resultB = estimateHeatLoss(
currentOutdoor,
MODEL.uGlazingB
);
const maxResult = Math.max(resultA.total, resultB.total, 1);
const countA = Math.max(
1,
Math.round((resultA.total / maxResult) * 12)
);
const countB = Math.max(
1,
Math.round((resultB.total / maxResult) * 12)
);
houseA.output.segments.forEach((segment, index) => {
segment.visible = index < countA;
});
houseB.output.segments.forEach((segment, index) => {
segment.visible = index < countB;
});
ui.temperatureValue.textContent = `${currentOutdoor} °C`;
ui.qA.textContent = (resultA.total / 1000).toFixed(2);
ui.qB.textContent = (resultB.total / 1000).toFixed(2);
ui.barA.style.width = `${(resultA.total / maxResult) * 100}%`;
ui.barB.style.width = `${(resultB.total / maxResult) * 100}%`;
const deltaPercent =
resultA.total > 0
? ((resultB.total - resultA.total) / resultA.total) * 100
: 0;
ui.delta.textContent = `+${deltaPercent.toFixed(0)}%`;
ui.labelA.querySelector(".output").textContent =
`Model estimate: ${(resultA.total / 1000).toFixed(2)} kW`;
ui.labelB.querySelector(".output").textContent =
`Model estimate: ${(resultB.total / 1000).toFixed(2)} kW`;
}
ui.temperature.addEventListener("input", () => {
currentOutdoor = Number(ui.temperature.value);
updateResults();
});
ui.geometry.addEventListener("click", () => setMode("geometry"));
ui.thermal.addEventListener("click", () => setMode("thermal"));
// -------------------------------------------------------------------------
// DOM labels projected from world positions.
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const inFront = projected.z > -1 && projected.z < 1;
element.style.visibility = inFront ? "visible" : "hidden";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
canvas.style.cursor = "grab";
updateCamera();
setMode("thermal");
function animate() {
requestAnimationFrame(animate);
houseA.group.updateWorldMatrix(true, false);
houseB.group.updateWorldMatrix(true, false);
placeLabel(ui.labelA, houseA.anchor);
placeLabel(ui.labelB, houseB.anchor);
renderer.render(scene, camera);
}
animate();
// Let the first frame render before removing the loader.
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 300);
});
</script>
</body>
</html>
```