Prompt specification
Build or customize the Three.js 3D scene "Nighttime rooftop cooling 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: Nighttime rooftop cooling exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/nighttime-rooftop-cooling-exhibit-x1511
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring thermal radiation between surfaces and surroundings. Compose a roof beneath a stylized sky with upward and downward infrared arrows; identify the energy-exchange concept without treating the sky as a single fixed-temperature black surface universally. Voxel style.
Working Three.js Starter (nighttime-rooftop-cooling-exhibit-x1511):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Thermal Radiation — Roof & Sky</title>
<style>
:root {
--ink: #eff8ff;
--muted: #a9c2d3;
--panel: rgba(8, 24, 39, 0.88);
--line: rgba(174, 213, 235, 0.17);
--cyan: #63dcff;
--orange: #ffad59;
--violet: #c6a2ff;
--green: #8ee3ad;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071827;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#stage,
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
outline: none;
touch-action: none;
}
.hud {
position: absolute;
inset: 0;
pointer-events: none;
}
.title-block {
position: absolute;
top: 24px;
left: 28px;
max-width: 470px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(2, 12, 21, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: #c9e7f7;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 3px;
background: var(--orange);
box-shadow: 0 0 15px rgba(255, 173, 89, 0.7);
}
h1 {
margin: 7px 0 5px;
font-size: clamp(28px, 4vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 850;
}
.title-block p {
max-width: 410px;
margin: 0;
color: #d1e1eb;
font-size: 13px;
line-height: 1.55;
}
.panel {
position: absolute;
top: 150px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 18px;
border: 1px solid var(--line);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(16, 43, 62, 0.94), var(--panel));
box-shadow:
0 22px 70px rgba(0, 9, 18, 0.34),
inset 0 1px 0 rgba(255, 255, 255, 0.045);
backdrop-filter: blur(16px);
pointer-events: auto;
overflow: hidden;
}
.panel::after {
content: "";
position: absolute;
inset: 0;
pointer-events: none;
background-image:
linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
background-size: 18px 18px;
mask-image: linear-gradient(to bottom, transparent, black 35%, transparent);
}
.panel > * {
position: relative;
z-index: 1;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.model-badge {
padding: 5px 8px;
border: 1px solid rgba(99, 220, 255, 0.25);
border-radius: 7px;
color: var(--cyan);
background: rgba(99, 220, 255, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
white-space: nowrap;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
padding: 4px;
border-radius: 11px;
background: rgba(1, 13, 23, 0.48);
}
.segmented button {
min-height: 34px;
border: 0;
border-radius: 8px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
transition: 160ms ease;
}
.segmented button:hover {
color: white;
background: rgba(255, 255, 255, 0.055);
}
.segmented button.active {
color: #071724;
background: var(--cyan);
box-shadow: 0 4px 15px rgba(99, 220, 255, 0.18);
}
.control {
margin-top: 16px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
margin-bottom: 7px;
}
.control label {
color: #d9e8f1;
font-size: 11px;
font-weight: 650;
}
.control output {
color: var(--cyan);
font-size: 12px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
border-radius: 99px;
outline: none;
background:
linear-gradient(
90deg,
var(--cyan) 0 var(--fill, 50%),
rgba(174, 213, 235, 0.16) var(--fill, 50%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid #0c2538;
border-radius: 50%;
background: white;
box-shadow: 0 0 0 2px var(--cyan);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #0c2538;
border-radius: 50%;
background: white;
box-shadow: 0 0 0 2px var(--cyan);
}
.balance {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 18px;
}
.metric {
min-width: 0;
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(0, 11, 21, 0.3);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric strong {
display: block;
font-size: 17px;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.metric strong.up {
color: var(--orange);
}
.metric strong.down {
color: var(--cyan);
}
.metric strong.net {
color: var(--green);
}
.metric small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
}
.net-message {
margin-top: 9px;
padding: 9px 10px;
border-left: 3px solid var(--green);
border-radius: 0 8px 8px 0;
color: #dcebf3;
background: rgba(142, 227, 173, 0.075);
font-size: 10px;
line-height: 1.45;
}
.equation {
margin-top: 14px;
padding: 11px 10px;
border: 1px solid var(--line);
border-radius: 10px;
color: #d8edf8;
background: rgba(0, 10, 20, 0.35);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10px;
line-height: 1.55;
text-align: center;
}
.note {
margin: 11px 1px 0;
color: #a9c0ce;
font-size: 10px;
line-height: 1.55;
}
.note strong {
color: #e6f4fb;
}
.band-readout {
display: grid;
gap: 6px;
margin-top: 12px;
}
.band {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 7px 9px;
border-radius: 8px;
color: #bed3df;
background: rgba(99, 220, 255, 0.055);
font-size: 9px;
}
.band b {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
.legend {
position: absolute;
top: 25px;
right: 25px;
width: 205px;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(7, 24, 38, 0.72);
box-shadow: 0 15px 35px rgba(0, 9, 18, 0.2);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
color: #d8eaf4;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: #aec7d6;
font-size: 10px;
}
.legend-arrow {
display: grid;
width: 19px;
height: 19px;
place-items: center;
border-radius: 5px;
font-size: 15px;
font-weight: 900;
}
.legend-arrow.orange {
color: var(--orange);
background: rgba(255, 173, 89, 0.11);
}
.legend-arrow.cyan {
color: var(--cyan);
background: rgba(99, 220, 255, 0.11);
}
.legend-arrow.violet {
color: var(--violet);
background: rgba(198, 162, 255, 0.11);
}
.view-controls {
position: absolute;
right: 25px;
bottom: 25px;
display: flex;
gap: 7px;
pointer-events: auto;
}
.view-controls button {
min-height: 36px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 9px;
color: #d8ebf5;
background: rgba(7, 24, 38, 0.76);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
.view-controls button:hover,
.view-controls button.active {
color: #061622;
border-color: var(--cyan);
background: var(--cyan);
}
.camera-hint {
position: absolute;
left: 50%;
bottom: 27px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 99px;
color: rgba(225, 240, 249, 0.76);
background: rgba(6, 21, 34, 0.5);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
backdrop-filter: blur(10px);
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(205, 232, 246, 0.25);
border-radius: 8px;
color: #eff8ff;
background: rgba(6, 23, 37, 0.8);
box-shadow: 0 7px 25px rgba(0, 8, 16, 0.22);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.035em;
white-space: nowrap;
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
backdrop-filter: blur(8px);
}
.scene-label::before {
content: "";
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 10px currentColor;
}
.scene-label.up::before {
background: var(--orange);
}
.scene-label.ground::before {
background: var(--violet);
}
.scene-label small {
color: #9fbdcd;
font-size: 8px;
font-weight: 650;
}
#panelToggle {
display: none;
position: absolute;
right: 16px;
bottom: 72px;
width: 42px;
height: 42px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(7, 24, 38, 0.84);
pointer-events: auto;
}
@media (max-width: 800px) {
.title-block {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
.title-block p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 70px;
left: 12px;
width: auto;
max-height: 58vh;
overflow-y: auto;
transform: translateY(calc(100% + 90px));
transition: transform 220ms ease;
}
.panel.open {
transform: translateY(0);
}
#panelToggle {
display: block;
}
.legend {
top: 98px;
right: 14px;
width: 170px;
}
.camera-hint {
display: none;
}
.view-controls {
right: 14px;
bottom: 16px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="hud">
<div class="title-block">
<div class="eyebrow">Thermal exchange study</div>
<h1>Roof / Sky</h1>
<p>
Net longwave radiative exchange between a roof, the surrounding ground,
and a sky whose radiance changes with wavelength and atmosphere.
</p>
</div>
<section class="panel" id="panel" aria-label="Thermal radiation controls">
<div class="panel-heading">
<h2>Radiative balance</h2>
<span class="model-badge" id="modelBadge">CLEAR / DRY</span>
</div>
<div class="segmented" role="group" aria-label="Atmospheric condition">
<button class="active" data-model="clear">CLEAR</button>
<button data-model="humid">HUMID</button>
<button data-model="cloudy">CLOUDY</button>
</div>
<div class="control">
<div class="control-row">
<label for="roofTemp">Roof surface temperature</label>
<output id="roofTempOut" for="roofTemp">31 °C</output>
</div>
<input id="roofTemp" type="range" min="5" max="45" step="1" value="31" />
</div>
<div class="control">
<div class="control-row">
<label for="roofEmissivity">Roof longwave emissivity</label>
<output id="roofEmissivityOut" for="roofEmissivity">0.90</output>
</div>
<input
id="roofEmissivity"
type="range"
min="0.10"
max="0.98"
step="0.01"
value="0.90"
/>
</div>
<div class="control">
<div class="control-row">
<label for="groundTemp">Surrounding ground temperature</label>
<output id="groundTempOut" for="groundTemp">18 °C</output>
</div>
<input id="groundTemp" type="range" min="5" max="35" step="1" value="18" />
</div>
<div class="balance" aria-live="polite">
<div class="metric">
<span>Roof emits</span>
<strong class="up" id="outValue">0</strong>
<small>W/m² outward</small>
</div>
<div class="metric">
<span>Absorbed</span>
<strong class="down" id="inValue">0</strong>
<small>W/m² inward</small>
</div>
<div class="metric">
<span>Net</span>
<strong class="net" id="netValue">0</strong>
<small>W/m²</small>
</div>
</div>
<div class="net-message" id="netMessage">
Net radiative heat transfer is being calculated.
</div>
<div class="equation">
q<sub>net</sub> =
εσT<sub>r</sub><sup>4</sup>F<sub>sky</sub> − εq<sub>sky↓</sub>
+
εσT<sub>r</sub><sup>4</sup>F<sub>ground</sub>
− εε<sub>g</sub>σT<sub>g</sub><sup>4</sup>F<sub>ground</sub>
</div>
<div class="band-readout" id="bandReadout"></div>
<p class="note">
<strong>The sky is not one universal black surface.</strong>
This compact model represents downwelling longwave as two effective
infrared bands. Their radiance changes with water vapor, clouds,
altitude, and view direction. Nearby ground contributes separately
through its own temperature, emissivity, and view factor.
</p>
</section>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Infrared pathways</div>
<div class="legend-item">
<span class="legend-arrow orange">↑</span>
<span>Thermal emission from roof</span>
</div>
<div class="legend-item">
<span class="legend-arrow cyan">↓</span>
<span>Atmospheric longwave</span>
</div>
<div class="legend-item">
<span class="legend-arrow violet">↑</span>
<span>Longwave from surroundings</span>
</div>
</aside>
<div id="labels">
<div class="scene-label" id="roofLabel">
ROOF <small id="roofLabelDetail">31 °C · ε 0.90</small>
</div>
<div class="scene-label up" id="upLabel">
↑ EMITTED IR <small>εσT⁴</small>
</div>
<div class="scene-label" id="downLabel">
↓ SKY LONGWAVE <small>banded radiance</small>
</div>
<div class="scene-label ground" id="groundLabel">
↑ GROUND IR <small>nearby surroundings</small>
</div>
</div>
<div class="view-controls">
<button id="resetView" type="button">RESET VIEW</button>
<button id="orbitToggle" type="button">AUTO ORBIT</button>
</div>
<button id="panelToggle" type="button" aria-label="Toggle controls">☰</button>
<div class="camera-hint">DRAG TO ORBIT · SCROLL TO ZOOM · SHIFT-DRAG TO PAN</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
// ------------------------------------------------------------
// Renderer, scene, camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x9cc7cf, 22, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraTarget = new THREE.Vector3(0, 3.0, 0);
let cameraTheta = 0.70;
let cameraPhi = 1.08;
let cameraRadius = 18.5;
let autoOrbit = false;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Stylized sky
// ------------------------------------------------------------
const skyUniforms = {
topColor: { value: new THREE.Color("#3e88bd") },
horizonColor: { value: new THREE.Color("#d7ddd1") },
lowerColor: { value: new THREE.Color("#8ab6b3") }
};
const sky = new THREE.Mesh(
new THREE.SphereGeometry(58, 32, 18),
new THREE.ShaderMaterial({
side: THREE.BackSide,
depthWrite: false,
uniforms: skyUniforms,
vertexShader: `
varying vec3 vWorldPosition;
void main() {
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`,
fragmentShader: `
uniform vec3 topColor;
uniform vec3 horizonColor;
uniform vec3 lowerColor;
varying vec3 vWorldPosition;
void main() {
float h = normalize(vWorldPosition).y;
vec3 upper = mix(
horizonColor,
topColor,
smoothstep(-0.02, 0.72, h)
);
vec3 lower = mix(
lowerColor,
horizonColor,
smoothstep(-0.35, 0.02, h)
);
vec3 color = h < 0.0 ? lower : upper;
gl_FragColor = vec4(color, 1.0);
}
`
})
);
scene.add(sky);
const hemiLight = new THREE.HemisphereLight(0xc8ecff, 0x687044, 2.0);
scene.add(hemiLight);
const sunLight = new THREE.DirectionalLight(0xffe3b5, 3.2);
sunLight.position.set(-11, 17, 9);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -18;
sunLight.shadow.camera.right = 18;
sunLight.shadow.camera.top = 18;
sunLight.shadow.camera.bottom = -18;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 45;
sunLight.shadow.bias = -0.0004;
scene.add(sunLight);
const rimLight = new THREE.DirectionalLight(0x79cfff, 0.65);
rimLight.position.set(10, 8, -12);
scene.add(rimLight);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
metalness: 0
}),
wall: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88
}),
roof: new THREE.MeshStandardMaterial({
color: 0x43515a,
roughness: 0.82,
metalness: 0.08,
emissive: 0x36170c,
emissiveIntensity: 0.08
}),
roofTrim: new THREE.MeshStandardMaterial({
color: 0x29363d,
roughness: 0.78
}),
window: new THREE.MeshStandardMaterial({
color: 0x70c7df,
emissive: 0x173d52,
emissiveIntensity: 0.38,
roughness: 0.25,
metalness: 0.12
}),
door: new THREE.MeshStandardMaterial({
color: 0x694b3f,
roughness: 0.85
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x74533d,
roughness: 1
}),
leaves: new THREE.MeshStandardMaterial({
color: 0x4d805c,
roughness: 1
}),
cloud: new THREE.MeshStandardMaterial({
color: 0xf4f7f1,
roughness: 1,
transparent: true,
opacity: 0.82,
depthWrite: false
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff9a36,
emissive: 0xff5d0a,
emissiveIntensity: 1.55,
roughness: 0.35,
transparent: true,
opacity: 0.78
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x50d9ff,
emissive: 0x009dde,
emissiveIntensity: 1.45,
roughness: 0.35,
transparent: true,
opacity: 0.76
}),
violet: new THREE.MeshStandardMaterial({
color: 0xc6a2ff,
emissive: 0x7444dc,
emissiveIntensity: 1.25,
roughness: 0.4,
transparent: true,
opacity: 0.7
})
};
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(boxGeometry, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Voxel ground
// ------------------------------------------------------------
const groundTiles = new THREE.InstancedMesh(
boxGeometry,
materials.ground,
28 * 24
);
const tileMatrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let x = -14; x < 14; x++) {
for (let z = -12; z < 12; z++) {
const variation = ((x * 17 + z * 31) % 7) / 6;
tileColor.setHSL(
0.255 + variation * 0.025,
0.22 + variation * 0.08,
0.39 + variation * 0.055
);
tileMatrix.makeTranslation(x * 0.96, -0.14 + variation * 0.025, z * 0.96);
groundTiles.setMatrixAt(tileIndex, tileMatrix);
groundTiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
groundTiles.receiveShadow = true;
groundTiles.instanceMatrix.needsUpdate = true;
groundTiles.instanceColor.needsUpdate = true;
scene.add(groundTiles);
// Foundation
addBox(scene, [9.2, 0.32, 6.0], [0, 0.12, 0], materials.roofTrim);
// ------------------------------------------------------------
// Voxel house walls
// ------------------------------------------------------------
const wallBlocks = [];
const blockSize = 0.64;
const wallRows = 4;
// Front and back walls
for (const z of [-2.58, 2.58]) {
for (let row = 0; row < wallRows; row++) {
for (let col = 0; col < 12; col++) {
const x = -3.52 + col * 0.64;
const y = 0.55 + row * 0.64;
const isFront = z > 0;
const windowOpening =
isFront &&
(row === 1 || row === 2) &&
(col === 2 || col === 3 || col === 8 || col === 9);
const doorOpening =
isFront &&
row < 2 &&
(col === 5 || col === 6);
if (!windowOpening && !doorOpening) {
wallBlocks.push({ x, y, z, tone: ((row + col) % 3) / 3 });
}
}
}
}
// Side walls
for (const x of [-3.84, 3.84]) {
for (let row = 0; row < wallRows; row++) {
for (let col = 0; col < 8; col++) {
const z = -2.24 + col * 0.64;
const y = 0.55 + row * 0.64;
wallBlocks.push({ x, y, z, tone: ((row * 2 + col) % 3) / 3 });
}
}
}
const wallMesh = new THREE.InstancedMesh(
boxGeometry,
materials.wall,
wallBlocks.length
);
wallBlocks.forEach((block, index) => {
tileMatrix.makeTranslation(block.x, block.y, block.z);
wallMesh.setMatrixAt(index, tileMatrix);
tileColor.setHSL(
0.095,
0.30,
0.69 + block.tone * 0.035
);
wallMesh.setColorAt(index, tileColor);
});
wallMesh.castShadow = true;
wallMesh.receiveShadow = true;
wallMesh.instanceMatrix.needsUpdate = true;
wallMesh.instanceColor.needsUpdate = true;
scene.add(wallMesh);
// Windows and door
addBox(scene, [1.22, 1.18, 0.12], [-2.23, 1.45, 2.72], materials.window);
addBox(scene, [1.22, 1.18, 0.12], [2.23, 1.45, 2.72], materials.window);
addBox(scene, [1.18, 1.95, 0.14], [0, 1.26, 2.73], materials.door);
addBox(scene, [0.09, 1.2, 0.15], [-2.23, 1.45, 2.80], materials.roofTrim);
addBox(scene, [0.09, 1.2, 0.15], [2.23, 1.45, 2.80], materials.roofTrim);
addBox(scene, [0.06, 0.45, 0.17], [0.38, 1.25, 2.84], materials.roofTrim);
// Flat roof slab
addBox(scene, [8.55, 0.35, 5.65], [0, 3.18, 0], materials.roofTrim);
// Individual voxel roof tiles
const roofTileCount = 13 * 9;
const roofTiles = new THREE.InstancedMesh(
boxGeometry,
materials.roof,
roofTileCount
);
let roofIndex = 0;
for (let x = 0; x < 13; x++) {
for (let z = 0; z < 9; z++) {
const px = -3.6 + x * 0.6;
const pz = -2.4 + z * 0.6;
const shade = ((x * 7 + z * 3) % 5) / 4;
tileMatrix.makeTranslation(px, 3.43 + shade * 0.012, pz);
roofTiles.setMatrixAt(roofIndex, tileMatrix);
tileColor.setHSL(
0.56,
0.10 + shade * 0.025,
0.25 + shade * 0.035
);
roofTiles.setColorAt(roofIndex, tileColor);
roofIndex++;
}
}
roofTiles.castShadow = true;
roofTiles.receiveShadow = true;
roofTiles.instanceMatrix.needsUpdate = true;
roofTiles.instanceColor.needsUpdate = true;
scene.add(roofTiles);
// Parapet edges
addBox(scene, [8.6, 0.36, 0.20], [0, 3.55, -2.75], materials.roofTrim);
addBox(scene, [8.6, 0.36, 0.20], [0, 3.55, 2.75], materials.roofTrim);
addBox(scene, [0.20, 0.36, 5.3], [-4.22, 3.55, 0], materials.roofTrim);
addBox(scene, [0.20, 0.36, 5.3], [4.22, 3.55, 0], materials.roofTrim);
// Small roof equipment
addBox(scene, [1.05, 0.65, 0.9], [-2.7, 3.78, -1.55], materials.roofTrim);
addBox(scene, [0.72, 0.12, 0.72], [-2.7, 4.16, -1.55], materials.window);
// ------------------------------------------------------------
// Voxel trees
// ------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
addBox(group, [0.42, 1.7, 0.42], [0, 0.85, 0], materials.trunk);
const leafPositions = [
[-0.55, 1.65, 0], [0.55, 1.65, 0],
[0, 1.65, -0.55], [0, 1.65, 0.55],
[-0.55, 2.35, -0.55], [0.55, 2.35, 0.55],
[-0.55, 2.35, 0.55], [0.55, 2.35, -0.55],
[0, 3.05, 0]
];
leafPositions.forEach((p, index) => {
const leaf = addBox(
group,
[0.95, 0.95, 0.95],
p,
materials.leaves
);
leaf.rotation.y = (index % 3) * 0.12;
});
scene.add(group);
}
makeTree(-7.8, -4.6, 1.15);
makeTree(-9.6, 1.7, 0.85);
makeTree(8.1, -5.4, 1.05);
makeTree(9.2, 2.1, 0.72);
makeTree(-6.6, 6.1, 0.78);
makeTree(6.8, 6.7, 0.9);
// ------------------------------------------------------------
// Stylized sun and clouds
// ------------------------------------------------------------
const sunBlock = new THREE.Mesh(
boxGeometry,
new THREE.MeshBasicMaterial({ color: 0xffd27a })
);
sunBlock.scale.set(1.5, 1.5, 0.45);
sunBlock.position.set(-13, 13, -21);
scene.add(sunBlock);
const cloudGroup = new THREE.Group();
scene.add(cloudGroup);
const cloudCenters = [
[-10, 0, -5, 1.0],
[-5, 0.5, -9, 1.25],
[2, 0.2, -8, 1.0],
[9, 0.6, -4, 1.3],
[13, -0.2, 1, 0.9],
[-1, 1.1, 4, 0.8]
];
for (const [cx, cy, cz, cs] of cloudCenters) {
const chunks = [
[-0.85, 0, 0, 1.1],
[0, 0.15, 0, 1.5],
[0.95, 0, 0, 1.05],
[-0.35, 0.55, 0.1, 1.15],
[0.55, 0.48, -0.05, 1.0]
];
chunks.forEach(([x, y, z, s]) => {
addBox(
cloudGroup,
[1.35 * s, 0.62 * s, 0.9 * s],
[cx + x * cs, cy + y * cs, cz + z * cs],
materials.cloud,
false
);
});
}
// ------------------------------------------------------------
// Atmospheric IR layers: dotted, voxel-like horizontal bands
// ------------------------------------------------------------
const atmosphereLayers = [];
for (let layer = 0; layer < 3; layer++) {
const count = 24;
const geometry = new THREE.BoxGeometry(0.11, 0.11, 0.11);
const material = new THREE.MeshBasicMaterial({
color: layer === 1 ? 0x89ddff : 0x6db9e2,
transparent: true,
opacity: 0.32,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(geometry, material, count);
const matrix = new THREE.Matrix4();
for (let i = 0; i < count; i++) {
const x = -6.6 + (i / (count - 1)) * 13.2;
const z = layer % 2 === 0 ? -1.75 : 1.75;
const y = 5.35 + layer * 1.28 + ((i % 3) - 1) * 0.11;
matrix.makeTranslation(x, y, z);
mesh.setMatrixAt(i, matrix);
}
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);
atmosphereLayers.push(mesh);
}
// ------------------------------------------------------------
// Voxel infrared arrows
// ------------------------------------------------------------
class VoxelArrow {
constructor({
colorMaterial,
x,
y,
z,
length,
direction = "up",
packetCount = 7
}) {
this.length = length;
this.direction = direction;
this.root = new THREE.Group();
this.root.position.set(x, y, z);
if (direction === "down") {
this.root.rotation.z = Math.PI;
}
this.visual = new THREE.Group();
this.root.add(this.visual);
const segmentHeight = 0.62;
const segmentGap = 0.08;
const segmentCount = Math.floor((length - 1.15) / (segmentHeight + segmentGap));
for (let i = 0; i < segmentCount; i++) {
addBox(
this.visual,
[0.26, segmentHeight, 0.26],
[0, 0.25 + i * (segmentHeight + segmentGap), 0],
colorMaterial,
false
);
}
// Stepped voxel arrowhead
const headBase = length - 1.05;
addBox(this.visual, [0.90, 0.25, 0.90], [0, headBase, 0], colorMaterial, false);
addBox(this.visual, [0.62, 0.25, 0.62], [0, headBase + 0.27, 0], colorMaterial, false);
addBox(this.visual, [0.34, 0.25, 0.34], [0, headBase + 0.54, 0], colorMaterial, false);
this.packets = [];
for (let i = 0; i < packetCount; i++) {
const packet = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.18, 0.18),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
packet.userData.phase = i / packetCount;
packet.userData.drift = (i % 2 === 0 ? 1 : -1) * 0.12;
this.root.add(packet);
this.packets.push(packet);
}
scene.add(this.root);
}
update(time, widthScale) {
this.visual.scale.x = widthScale;
this.visual.scale.z = widthScale;
this.packets.forEach((packet, index) => {
const phase = (packet.userData.phase + time * 0.13 + index * 0.017) % 1;
packet.position.set(
packet.userData.drift,
0.25 + phase * (this.length - 0.35),
0
);
packet.rotation.y = time * 0.8 + index;
packet.rotation.x = time * 0.55;
});
}
}
const emittedArrow = new VoxelArrow({
colorMaterial: materials.orange,
x: -2.25,
y: 3.72,
z: 0.75,
length: 5.1,
direction: "up",
packetCount: 8
});
const skyArrow = new VoxelArrow({
colorMaterial: materials.cyan,
x: 2.25,
y: 8.65,
z: -0.45,
length: 5.1,
direction: "down",
packetCount: 8
});
const groundArrow = new VoxelArrow({
colorMaterial: materials.violet,
x: -5.15,
y: 0.18,
z: -1.55,
length: 2.65,
direction: "up",
packetCount: 5
});
// ------------------------------------------------------------
// Radiation model
// ------------------------------------------------------------
const SIGMA = 5.670374419e-8;
const GROUND_EMISSIVITY = 0.95;
const SKY_VIEW_FACTOR = 0.78;
const GROUND_VIEW_FACTOR = 0.22;
const skyModels = {
clear: {
label: "CLEAR / DRY",
bands: [
{ label: "8–13 μm atmospheric window", temperature: 252, emissivity: 0.55 },
{ label: "13+ μm infrared band", temperature: 278, emissivity: 0.76 }
],
cloudScale: 0.72,
cloudY: 10.6,
top: "#3e91c4",
horizon: "#d9dfd3",
lower: "#8cb8b4"
},
humid: {
label: "HUMID / WARM",
bands: [
{ label: "8–13 μm atmospheric window", temperature: 258, emissivity: 0.42 },
{ label: "13+ μm infrared band", temperature: 284, emissivity: 0.88 }
],
cloudScale: 1.0,
cloudY: 9.7,
top: "#4b88b4",
horizon: "#d5d8cc",
lower: "#8fb3aa"
},
cloudy: {
label: "CLOUDY",
bands: [
{ label: "8–13 μm atmospheric window", temperature: 272, emissivity: 0.22 },
{ label: "13+ μm infrared band", temperature: 292, emissivity: 0.95 }
],
cloudScale: 1.34,
cloudY: 8.25,
top: "#637f93",
horizon: "#c8cec8",
lower: "#839b9b"
}
};
let currentModelName = "clear";
let currentModel = skyModels.clear;
const roofTempInput = document.getElementById("roofTemp");
const roofEmissivityInput = document.getElementById("roofEmissivity");
const groundTempInput = document.getElementById("groundTemp");
const roofTempOut = document.getElementById("roofTempOut");
const roofEmissivityOut = document.getElementById("roofEmissivityOut");
const groundTempOut = document.getElementById("groundTempOut");
const outValue = document.getElementById("outValue");
const inValue = document.getElementById("inValue");
const netValue = document.getElementById("netValue");
const netMessage = document.getElementById("netMessage");
const modelBadge = document.getElementById("modelBadge");
const bandReadout = document.getElementById("bandReadout");
const roofLabelDetail = document.getElementById("roofLabelDetail");
let currentBalance = null;
function setRangeFill(input) {
const fraction =
(Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min));
input.style.setProperty("--fill", `${fraction * 100}%`);
}
function updateModelAppearance() {
cloudGroup.scale.set(
currentModel.cloudScale,
currentModel.cloudScale,
currentModel.cloudScale
);
cloudGroup.position.y = currentModel.cloudY;
materials.cloud.opacity = currentModelName === "cloudy" ? 0.98 : 0.82;
skyUniforms.topColor.value.set(currentModel.top);
skyUniforms.horizonColor.value.set(currentModel.horizon);
skyUniforms.lowerColor.value.set(currentModel.lower);
scene.fog.color.set(currentModel.horizon);
hemiLight.color.set(currentModelName === "cloudy" ? 0xd4e4ec : 0xc8ecff);
sunLight.intensity = currentModelName === "cloudy" ? 1.35 : 3.2;
document.querySelectorAll("[data-model]").forEach((button) => {
button.classList.toggle("active", button.dataset.model === currentModelName);
});
modelBadge.textContent = currentModel.label;
}
function calculateBalance() {
const roofC = Number(roofTempInput.value);
const groundC = Number(groundTempInput.value);
const roofEpsilon = Number(roofEmissivityInput.value);
const roofK = roofC + 273.15;
const groundK = groundC + 273.15;
const roofEmissionTotal = roofEpsilon * SIGMA * Math.pow(roofK, 4);
const outgoingSky = roofEmissionTotal * SKY_VIEW_FACTOR;
const outgoingGround = roofEmissionTotal * GROUND_VIEW_FACTOR;
const incomingSkyIrradiance = currentModel.bands.reduce(
(sum, band) =>
sum +
band.emissivity *
SIGMA *
Math.pow(band.temperature, 4) *
SKY_VIEW_FACTOR,
0
);
const incomingGroundIrradiance =
GROUND_EMISSIVITY *
SIGMA *
Math.pow(groundK, 4) *
GROUND_VIEW_FACTOR;
const absorbedSky = roofEpsilon * incomingSkyIrradiance;
const absorbedGround = roofEpsilon * incomingGroundIrradiance;
const outgoingTotal = outgoingSky + outgoingGround;
const incomingTotal = absorbedSky + absorbedGround;
const net = outgoingTotal - incomingTotal;
return {
roofC,
groundC,
roofEpsilon,
outgoingTotal,
incomingTotal,
incomingSkyIrradiance,
incomingGroundIrradiance,
absorbedSky,
absorbedGround,
outgoingSky,
outgoingGround,
net
};
}
function updateInterface() {
const balance = calculateBalance();
currentBalance = balance;
roofTempOut.textContent = `${balance.roofC} °C`;
roofEmissivityOut.textContent = balance.roofEpsilon.toFixed(2);
groundTempOut.textContent = `${balance.groundC} °C`;
outValue.textContent = Math.round(balance.outgoingTotal);
inValue.textContent = Math.round(balance.incomingTotal);
netValue.textContent =
`${balance.net >= 0 ? "+" : "−"}${Math.abs(Math.round(balance.net))}`;
if (balance.net > 0) {
netMessage.textContent =
`The roof loses approximately ${Math.round(balance.net)} W/m² by net longwave radiation.`;
netMessage.style.borderLeftColor = "var(--orange)";
} else {
netMessage.textContent =
`The roof gains approximately ${Math.abs(Math.round(balance.net))} W/m² through net longwave radiation.`;
netMessage.style.borderLeftColor = "var(--cyan)";
}
roofLabelDetail.textContent =
`${balance.roofC} °C · ε ${balance.roofEpsilon.toFixed(2)}`;
bandReadout.innerHTML = currentModel.bands
.map(
(band) => `
<div class="band">
<span>${band.label}</span>
<b>${band.temperature} K · ε ${band.emissivity.toFixed(2)}</b>
</div>
`
)
.join("");
setRangeFill(roofTempInput);
setRangeFill(roofEmissivityInput);
setRangeFill(groundTempInput);
// Tint the roof surface according to its current temperature.
const temperatureFraction = THREE.MathUtils.clamp(
(balance.roofC - 5) / 40,
0,
1
);
const coolRoof = new THREE.Color("#455d6b");
const warmRoof = new THREE.Color("#9a654b");
materials.roof.color.copy(coolRoof).lerp(warmRoof, temperatureFraction);
materials.roof.emissive.set(
balance.net >= 0 ? 0x7c2d08 : 0x073b58
);
materials.roof.emissiveIntensity =
0.055 + Math.min(Math.abs(balance.net) / 1000, 0.18);
}
[roofTempInput, roofEmissivityInput, groundTempInput].forEach((input) => {
input.addEventListener("input", updateInterface);
});
document.querySelectorAll("[data-model]").forEach((button) => {
button.addEventListener("click", () => {
currentModelName = button.dataset.model;
currentModel = skyModels[currentModelName];
updateModelAppearance();
updateInterface();
});
});
updateModelAppearance();
updateInterface();
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan, touch pinch
// ------------------------------------------------------------
const pointers = new Map();
let lastPointerX = 0;
let lastPointerY = 0;
let lastPinchDistance = 0;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (event.shiftKey) {
const panScale = cameraRadius * 0.0013;
cameraTarget.x -= dx * panScale;
cameraTarget.z -= dy * panScale;
} else {
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.005,
0.28,
1.43
);
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (lastPinchDistance / Math.max(distance, 1)),
9,
32
);
}
lastPinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
9,
32
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") cameraTheta += step;
if (event.key === "ArrowRight") cameraTheta -= step;
if (event.key === "ArrowUp") cameraPhi = Math.max(0.28, cameraPhi - step);
if (event.key === "ArrowDown") cameraPhi = Math.min(1.43, cameraPhi + step);
updateCamera();
});
document.getElementById("resetView").addEventListener("click", () => {
cameraTheta = 0.70;
cameraPhi = 1.08;
cameraRadius = 18.5;
cameraTarget.set(0, 3.0, 0);
autoOrbit = false;
document.getElementById("orbitToggle").classList.remove("active");
updateCamera();
});
document.getElementById("orbitToggle").addEventListener("click", (event) => {
autoOrbit = !autoOrbit;
event.currentTarget.classList.toggle("active", autoOrbit);
});
document.getElementById("panelToggle").addEventListener("click", () => {
document.getElementById("panel").classList.toggle("open");
});
// ------------------------------------------------------------
// HTML labels projected into the 3D scene
// ------------------------------------------------------------
const labels = [
{
element: document.getElementById("roofLabel"),
position: new THREE.Vector3(0.15, 4.08, 2.7)
},
{
element: document.getElementById("upLabel"),
position: new THREE.Vector3(-2.35, 7.35, 1.15)
},
{
element: document.getElementById("downLabel"),
position: new THREE.Vector3(2.35, 7.35, -0.85)
},
{
element: document.getElementById("groundLabel"),
position: new THREE.Vector3(-5.15, 2.15, -1.8)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
label.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
});
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (autoOrbit) {
cameraTheta += delta * 0.055;
updateCamera();
}
// Gentle atmospheric cloud drift.
cloudGroup.position.x = Math.sin(time * 0.035) * 0.7;
cloudGroup.position.z = Math.cos(time * 0.027) * 0.35;
// Atmospheric voxel layers breathe gently.
atmosphereLayers.forEach((layer, layerIndex) => {
layer.position.y = Math.sin(time * 0.5 + layerIndex) * 0.035;
layer.rotation.y = Math.sin(time * 0.08 + layerIndex) * 0.012;
});
if (currentBalance) {
const maximum = 750;
const emittedWidth = THREE.MathUtils.clamp(
0.72 + (currentBalance.outgoingTotal / maximum) * 0.72,
0.72,
1.48
);
const skyIncomingWidth = THREE.MathUtils.clamp(
0.72 + (currentBalance.absorbedSky / maximum) * 0.72,
0.72,
1.48
);
const groundIncomingWidth = THREE.MathUtils.clamp(
0.62 + (currentBalance.absorbedGround / 180) * 0.7,
0.62,
1.3
);
emittedArrow.update(time, emittedWidth);
skyArrow.update(time, skyIncomingWidth);
groundArrow.update(time, groundIncomingWidth);
}
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```