Prompt specification
Build or customize the Three.js 3D scene "Urban roof reflectivity diorama" 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: Urban roof reflectivity diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/urban-roof-reflectivity-diorama-x1203
Scene Description Prompt:
Compare illustrative radiative energy budgets for three voxel roofs with equal sunlight but different reflectivity. Build one HTML scene with Three.js from cdnjs.
Working Three.js Starter (urban-roof-reflectivity-diorama-x1203):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Roof Lab — Radiative Energy Budgets</title>
<style>
:root {
color-scheme: dark;
--bg: #07121d;
--panel: rgba(10, 24, 37, 0.82);
--line: rgba(180, 221, 241, 0.14);
--text: #eef8fc;
--muted: #91a9b8;
--sun: #ffd166;
--reflected: #63dcff;
--absorbed: #ff9856;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
background:
radial-gradient(circle at 52% 32%, rgba(28, 70, 94, 0.42), transparent 42%),
linear-gradient(180deg, #091723 0%, #050c14 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(180deg, rgba(2, 8, 13, 0.42), transparent 22%),
linear-gradient(0deg, rgba(2, 8, 13, 0.55), transparent 36%);
}
.header {
position: fixed;
z-index: 5;
top: 28px;
left: 32px;
width: min(560px, calc(100vw - 64px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #a8c5d4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 1px;
content: "";
background: var(--reflected);
box-shadow: 0 0 12px rgba(99, 220, 255, 0.65);
}
h1 {
margin: 0;
font-size: clamp(34px, 4.1vw, 66px);
font-weight: 620;
line-height: 0.98;
letter-spacing: -0.055em;
text-wrap: balance;
}
.lede {
max-width: 520px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.lede strong {
color: #d7e9f2;
font-weight: 650;
}
.top-panel {
position: fixed;
z-index: 8;
top: 28px;
right: 30px;
display: grid;
justify-items: end;
gap: 12px;
}
.legend {
display: grid;
gap: 8px;
min-width: 190px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(7, 18, 29, 0.62);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(14px);
}
.legend-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
color: #b7cbd6;
font-size: 11px;
}
.legend-label {
display: flex;
align-items: center;
gap: 8px;
}
.legend-value {
color: #eef8fc;
font-variant-numeric: tabular-nums;
font-weight: 650;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.sun {
color: var(--sun);
}
.reflected {
color: var(--reflected);
}
.absorbed {
color: var(--absorbed);
}
.legend-note {
margin-top: 2px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #78909e;
font-size: 9px;
line-height: 1.45;
letter-spacing: 0.04em;
}
.controls {
display: flex;
align-items: center;
gap: 9px;
color: #7f99a8;
font-size: 10px;
letter-spacing: 0.025em;
}
#reset {
appearance: none;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(9, 23, 36, 0.84);
color: #c8dce6;
cursor: pointer;
font: inherit;
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease;
}
#reset:hover {
border-color: rgba(99, 220, 255, 0.45);
background: rgba(15, 36, 51, 0.95);
color: white;
}
.model-tag {
position: fixed;
z-index: 4;
padding: 7px 10px;
border: 1px solid rgba(161, 210, 232, 0.18);
border-radius: 999px;
background: rgba(7, 18, 29, 0.78);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
color: #c7dce7;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
}
.model-tag span {
margin-right: 7px;
color: var(--reflected);
}
.budgets {
position: fixed;
z-index: 10;
right: 24px;
bottom: 22px;
left: 24px;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
width: min(1120px, calc(100vw - 48px));
margin: auto;
}
.card {
position: relative;
overflow: hidden;
padding: 16px 17px 14px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.3),
inset 0 1px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(18px);
}
.card::before {
position: absolute;
top: 0;
right: 0;
left: 0;
height: 2px;
content: "";
background: linear-gradient(90deg, var(--accent), transparent 78%);
opacity: 0.8;
}
.card-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.sample-id {
display: block;
margin-bottom: 5px;
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
}
.card h2 {
margin: 0;
font-size: 15px;
font-weight: 650;
letter-spacing: -0.02em;
}
.reflectivity {
flex: none;
padding: 5px 8px;
border: 1px solid rgba(152, 206, 229, 0.16);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: #e7f4f9;
font-size: 10px;
font-variant-numeric: tabular-nums;
font-weight: 700;
white-space: nowrap;
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
margin-top: 17px;
}
.stat span {
display: block;
margin-bottom: 3px;
color: #829aa8;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong {
color: var(--stat-color);
font-size: 20px;
font-weight: 620;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
.stat small {
color: #90a7b4;
font-size: 9px;
font-weight: 500;
letter-spacing: 0;
}
.energy-bar {
display: flex;
overflow: hidden;
height: 7px;
margin-top: 14px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.055);
}
.energy-bar span {
display: block;
height: 100%;
}
.energy-bar .reflected-segment {
background: var(--reflected);
box-shadow: 0 0 12px rgba(99, 220, 255, 0.4);
}
.energy-bar .absorbed-segment {
background: var(--absorbed);
box-shadow: 0 0 12px rgba(255, 152, 86, 0.3);
}
.balance {
margin-top: 8px;
color: #708995;
font-size: 9px;
letter-spacing: 0.02em;
}
.balance b {
color: #b9ccd6;
font-weight: 600;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #07121d;
color: #9fc3d5;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1000px) {
.header {
top: 22px;
left: 22px;
}
.top-panel {
top: 22px;
right: 22px;
}
.lede {
max-width: 400px;
}
.budgets {
right: 14px;
bottom: 14px;
left: 14px;
gap: 8px;
width: calc(100vw - 28px);
}
.card {
padding: 13px;
}
.stats {
gap: 7px;
margin-top: 12px;
}
.stat strong {
font-size: 17px;
}
}
@media (max-width: 720px) {
.header {
top: 17px;
left: 17px;
width: calc(100vw - 34px);
}
h1 {
max-width: 320px;
font-size: 38px;
}
.lede {
display: none;
}
.top-panel {
top: auto;
right: 16px;
bottom: 206px;
}
.legend {
display: none;
}
.controls {
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(7, 18, 29, 0.74);
}
.controls span {
display: none;
}
.model-tag {
display: none;
}
.budgets {
display: flex;
overflow-x: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 1px;
scrollbar-width: none;
}
.budgets::-webkit-scrollbar {
display: none;
}
.card {
flex: 0 0 230px;
}
}
@media (max-height: 690px) and (min-width: 721px) {
.lede {
display: none;
}
.card {
padding-top: 12px;
padding-bottom: 11px;
}
.stats {
margin-top: 10px;
}
.energy-bar {
margin-top: 10px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional comparison of three voxel roofs with different solar reflectivity."
></canvas>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">Roof Lab / Radiative Exchange</div>
<h1>One sun.<br />Three ways out.</h1>
<p class="lede">
Each roof receives the same <strong>1,000 W/m²</strong> of sunlight.
Cyan energy is reflected; amber energy is absorbed.
This is an idealized surface balance.
</p>
</header>
<aside class="top-panel" aria-label="Scene legend and controls">
<div class="legend">
<div class="legend-row">
<span class="legend-label"><i class="dot sun"></i>Incoming</span>
<span class="legend-value">1,000 W/m²</span>
</div>
<div class="legend-row">
<span class="legend-label"><i class="dot reflected"></i>Reflected</span>
<span class="legend-value">R × 1,000</span>
</div>
<div class="legend-row">
<span class="legend-label"><i class="dot absorbed"></i>Absorbed</span>
<span class="legend-value">1 − R</span>
</div>
<div class="legend-note">
Instantaneous balance · no convection or thermal storage
</div>
</div>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
</aside>
<div class="model-tag" data-tag="0"><span>01</span>DARK SLATE</div>
<div class="model-tag" data-tag="1"><span>02</span>MID-TONE TILE</div>
<div class="model-tag" data-tag="2"><span>03</span>WHITE MEMBRANE</div>
<main class="budgets" aria-label="Illustrative energy budgets">
<article class="card" style="--accent: #62d8ff">
<div class="card-head">
<div>
<span class="sample-id">Sample 01</span>
<h2>Dark slate</h2>
</div>
<div class="reflectivity">R = 15%</div>
</div>
<div class="stats">
<div class="stat" style="--stat-color: var(--reflected)">
<span>Reflected</span>
<strong>150 <small>W/m²</small></strong>
</div>
<div class="stat" style="--stat-color: var(--absorbed)">
<span>Absorbed</span>
<strong>850 <small>W/m²</small></strong>
</div>
</div>
<div class="energy-bar" aria-label="15 percent reflected, 85 percent absorbed">
<span class="reflected-segment" style="width: 15%"></span>
<span class="absorbed-segment" style="width: 85%"></span>
</div>
<div class="balance"><b>15% leaves</b> · 85% retained by the surface</div>
</article>
<article class="card" style="--accent: #8fe4d8">
<div class="card-head">
<div>
<span class="sample-id">Sample 02</span>
<h2>Mid-tone tile</h2>
</div>
<div class="reflectivity">R = 40%</div>
</div>
<div class="stats">
<div class="stat" style="--stat-color: var(--reflected)">
<span>Reflected</span>
<strong>400 <small>W/m²</small></strong>
</div>
<div class="stat" style="--stat-color: var(--absorbed)">
<span>Absorbed</span>
<strong>600 <small>W/m²</small></strong>
</div>
</div>
<div class="energy-bar" aria-label="40 percent reflected, 60 percent absorbed">
<span class="reflected-segment" style="width: 40%"></span>
<span class="absorbed-segment" style="width: 60%"></span>
</div>
<div class="balance"><b>40% leaves</b> · 60% retained by the surface</div>
</article>
<article class="card" style="--accent: #d7f4fb">
<div class="card-head">
<div>
<span class="sample-id">Sample 03</span>
<h2>White membrane</h2>
</div>
<div class="reflectivity">R = 70%</div>
</div>
<div class="stats">
<div class="stat" style="--stat-color: var(--reflected)">
<span>Reflected</span>
<strong>700 <small>W/m²</small></strong>
</div>
<div class="stat" style="--stat-color: var(--absorbed)">
<span>Absorbed</span>
<strong>300 <small>W/m²</small></strong>
</div>
</div>
<div class="energy-bar" aria-label="70 percent reflected, 30 percent absorbed">
<span class="reflected-segment" style="width: 70%"></span>
<span class="absorbed-segment" style="width: 30%"></span>
</div>
<div class="balance"><b>70% leaves</b> · 30% retained by the surface</div>
</article>
</main>
<div id="loading">Initializing roof lab</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 resetButton = document.querySelector("#reset");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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(0x07121d);
scene.fog = new THREE.Fog(0x07121d, 18, 43);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0, 2.25, 0),
radius: 23,
theta: 0.28,
phi: 1.13
};
let userAdjusted = false;
// Lighting
const hemisphere = new THREE.HemisphereLight(0xb9dfff, 0x17212b, 1.8);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffedcb, 3.2);
sunlight.position.set(-7, 14, 8);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -18;
sunlight.shadow.camera.right = 18;
sunlight.shadow.camera.top = 16;
sunlight.shadow.camera.bottom = -12;
sunlight.shadow.camera.near = 0.5;
sunlight.shadow.camera.far = 40;
sunlight.shadow.normalBias = 0.035;
scene.add(sunlight);
scene.add(sunlight.target);
const rim = new THREE.DirectionalLight(0x5ccfff, 1.05);
rim.position.set(10, 7, -10);
scene.add(rim);
// Ground
const ground = new THREE.Mesh(
new THREE.CircleGeometry(32, 96),
new THREE.MeshStandardMaterial({
color: 0x081722,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(36, 36, 0x24475a, 0x132b38);
grid.position.y = -0.012;
grid.material.transparent = true;
grid.material.opacity = 0.52;
scene.add(grid);
const samples = [
{
x: -6.7,
number: "01",
name: "DARK SLATE",
reflectivity: 0.15,
absorbed: 0.85,
color: 0x26343c,
roughness: 0.9,
accent: "#62d8ff"
},
{
x: 0,
number: "02",
name: "MID-TONE TILE",
reflectivity: 0.4,
absorbed: 0.6,
color: 0x8b8172,
roughness: 0.78,
accent: "#8fe4d8"
},
{
x: 6.7,
number: "03",
name: "WHITE MEMBRANE",
reflectivity: 0.7,
absorbed: 0.3,
color: 0xdce8e7,
roughness: 0.42,
accent: "#d7f4fb"
}
];
const flows = [];
const sunMarkers = [];
const modelAnchors = [];
const particleGeometry = new THREE.SphereGeometry(0.065, 10, 10);
const arrowY = new THREE.Vector3(0, 1, 0);
function addEdges(mesh, color = 0x4b7184, opacity = 0.3) {
const edges = new THREE.EdgesGeometry(mesh.geometry);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const lines = new THREE.LineSegments(edges, material);
lines.position.copy(mesh.position);
return lines;
}
function createArrow(start, direction, length, color, options = {}) {
const {
opacity = 0.9,
shaftRadius = 0.022,
headRadius = 0.11,
headLength = 0.28
} = options;
const group = new THREE.Group();
group.position.copy(start);
group.quaternion.setFromUnitVectors(arrowY, direction.clone().normalize());
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const shaftLength = Math.max(0.01, length - headLength);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(
shaftRadius,
shaftRadius,
shaftLength,
12
),
material
);
shaft.position.y = shaftLength / 2;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(headRadius, headLength, 16),
material
);
head.position.y = shaftLength + headLength / 2;
group.add(head);
return group;
}
function addFlow(parent, start, direction, length, color, count, speed) {
for (let i = 0; i < count; i++) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.96,
depthWrite: false
});
const particle = new THREE.Mesh(particleGeometry, material);
parent.add(particle);
flows.push({
mesh: particle,
start: start.clone(),
direction: direction.clone().normalize(),
length,
speed,
phase: i / count
});
}
}
function roundedRect(ctx, x, y, w, h, radius) {
const r = Math.min(radius, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function createPlaque(text, accent) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 512;
textureCanvas.height = 160;
const ctx = textureCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 160);
roundedRect(ctx, 6, 6, 500, 148, 28);
ctx.fillStyle = "rgba(7, 18, 29, 0.92)";
ctx.fill();
ctx.strokeStyle = "rgba(150, 205, 230, 0.32)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent;
ctx.font = "700 58px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(text.slice(0, 2), 38, 82);
ctx.fillStyle = "#e8f4f9";
ctx.font = "650 43px system-ui, sans-serif";
ctx.fillText(text.slice(3), 178, 83);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(1.72, 0.54),
material
);
plaque.position.set(0, 1.01, 1.622);
return plaque;
}
function createModel(sample, index) {
const group = new THREE.Group();
group.position.x = sample.x;
scene.add(group);
// Display platform
const platform = new THREE.Mesh(
new THREE.BoxGeometry(4.95, 0.18, 4.15),
new THREE.MeshStandardMaterial({
color: 0x102431,
roughness: 0.68,
metalness: 0.22
})
);
platform.position.y = 0.1;
platform.castShadow = true;
platform.receiveShadow = true;
group.add(platform);
group.add(addEdges(platform, 0x4e8298, 0.3));
const platformRing = new THREE.Mesh(
new THREE.RingGeometry(2.47, 2.5, 72),
new THREE.MeshBasicMaterial({
color: 0x54d6ff,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide,
depthWrite: false
})
);
platformRing.rotation.x = -Math.PI / 2;
platformRing.position.y = 0.015;
group.add(platformRing);
// Small building body
const body = new THREE.Mesh(
new THREE.BoxGeometry(4.05, 1.65, 3.2),
new THREE.MeshStandardMaterial({
color: index === 1 ? 0xd0c9ba : 0xd9d8cf,
roughness: 0.86,
metalness: 0.01
})
);
body.position.y = 1.02;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x173542,
emissive: 0x143745,
emissiveIntensity: 0.55,
roughness: 0.28,
metalness: 0.18
});
[-1.32, 1.32].forEach((x) => {
const windowPanel = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.48, 0.045),
windowMaterial
);
windowPanel.position.set(x, 1.01, 1.622);
group.add(windowPanel);
});
group.add(createPlaque(`${sample.number} R ${Math.round(sample.reflectivity * 100)}%`, sample.accent));
// Dark support beneath the voxel roof
const underlay = new THREE.Mesh(
new THREE.BoxGeometry(4.63, 0.13, 3.86),
new THREE.MeshStandardMaterial({
color: 0x1a252c,
emissive: 0xff7438,
emissiveIntensity: sample.absorbed * 0.45,
roughness: 0.82
})
);
underlay.position.y = 1.87;
underlay.castShadow = true;
group.add(underlay);
// Absorbed-energy halo: brighter for more absorptive surfaces
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xff9856,
transparent: true,
opacity: 0.22 + sample.absorbed * 0.6,
depthWrite: false
});
const frontHalo = new THREE.Mesh(
new THREE.BoxGeometry(4.58, 0.045, 0.045),
haloMaterial
);
frontHalo.position.set(0, 1.865, 1.91);
group.add(frontHalo);
const backHalo = frontHalo.clone();
backHalo.position.z = -1.91;
group.add(backHalo);
const sideHalo = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.045, 3.82),
haloMaterial
);
sideHalo.position.set(2.28, 1.865, 0);
group.add(sideHalo);
const oppositeHalo = sideHalo.clone();
oppositeHalo.position.x = -2.28;
group.add(oppositeHalo);
// Voxel roof tiles
const cols = 6;
const rows = 5;
const spacing = 0.76;
const tileSize = 0.7;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const variation = 0.88 + ((col * 5 + row * 3) % 6) * 0.036;
const color = new THREE.Color(sample.color).multiplyScalar(variation);
const material = new THREE.MeshStandardMaterial({
color,
roughness: sample.roughness,
metalness: sample.reflectivity > 0.6 ? 0.06 : 0.015
});
const tile = new THREE.Mesh(
new THREE.BoxGeometry(tileSize, 0.58, tileSize),
material
);
tile.position.set(
(col - (cols - 1) / 2) * spacing,
2.18 + ((col + row) % 3) * 0.006,
(row - (rows - 1) / 2) * spacing
);
tile.castShadow = true;
tile.receiveShadow = true;
group.add(tile);
}
}
// Equal incoming sunlight: same arrow length for all samples
const incomingOffsets = [-1.2, 0, 1.2];
incomingOffsets.forEach((offset, arrowIndex) => {
const start = new THREE.Vector3(offset, 6.35, -0.22);
const direction = new THREE.Vector3(0, -1, 0);
const length = 3.9;
const arrow = createArrow(start, direction, length, 0xffd166, {
opacity: 0.88,
shaftRadius: 0.024,
headRadius: 0.115,
headLength: 0.3
});
group.add(arrow);
addFlow(
group,
start,
direction,
length,
0xffe2a1,
3,
0.25 + arrowIndex * 0.012
);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 14, 14),
new THREE.MeshBasicMaterial({ color: 0xffd166 })
);
marker.position.copy(start);
group.add(marker);
sunMarkers.push({ mesh: marker, phase: arrowIndex + index });
});
// Reflected arrows scale with reflectivity
const reflectedLength = 1.1 + sample.reflectivity * 4.2;
[-1, 1].forEach((side, arrowIndex) => {
const start = new THREE.Vector3(side * 1.15, 2.5, -0.15);
const direction = new THREE.Vector3(side * 0.32, 0.92, 0.18).normalize();
const arrow = createArrow(
start,
direction,
reflectedLength,
0x63dcff,
{
opacity: 0.95,
shaftRadius: 0.026,
headRadius: 0.13,
headLength: 0.31
}
);
group.add(arrow);
const count = Math.round(4 + sample.reflectivity * 7);
addFlow(
group,
start,
direction,
reflectedLength,
0xb9f2ff,
count,
0.33 + arrowIndex * 0.018
);
});
modelAnchors.push(
new THREE.Vector3(sample.x, 0.55, 2.3)
);
}
samples.forEach(createModel);
// Subtle atmospheric motes
const motePositions = new Float32Array(180 * 3);
for (let i = 0; i < 180; i++) {
motePositions[i * 3] = (Math.random() - 0.5) * 28;
motePositions[i * 3 + 1] = Math.random() * 10;
motePositions[i * 3 + 2] = (Math.random() - 0.5) * 18;
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute(
"position",
new THREE.BufferAttribute(motePositions, 3)
);
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0x7abbd3,
size: 0.025,
transparent: true,
opacity: 0.35,
depthWrite: false
})
);
scene.add(motes);
// Project DOM labels into the 3D scene.
const tagElements = [...document.querySelectorAll("[data-tag]")];
function updateTags() {
const width = window.innerWidth;
const height = window.innerHeight;
tagElements.forEach((element, index) => {
const projected = modelAnchors[index].clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
// Direct camera controls, implemented without Three.js addons.
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
controls.radius,
controls.phi,
controls.theta
);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
}
function defaultRadius() {
const verticalHalfAngle = THREE.MathUtils.degToRad(camera.fov * 0.5);
const horizontalNeeded = 9.4 / (Math.tan(verticalHalfAngle) * camera.aspect);
return Math.max(22, horizontalNeeded * 1.08);
}
function resetCamera() {
controls.radius = defaultRadius();
controls.theta = 0.28;
controls.phi = 1.13;
controls.target.set(0, 2.25, 0);
userAdjusted = false;
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.48,
1.42
);
userAdjusted = true;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (pinchDistance / distance),
13,
58
);
userAdjusted = true;
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
13,
58
);
userAdjusted = true;
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") controls.theta += step;
else if (event.key === "ArrowRight") controls.theta -= step;
else if (event.key === "ArrowUp") {
controls.phi = Math.max(0.48, controls.phi - step);
} else if (event.key === "ArrowDown") {
controls.phi = Math.min(1.42, controls.phi + step);
} else if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(13, controls.radius - 1);
} else if (event.key === "-") {
controls.radius = Math.min(58, controls.radius + 1);
} else {
return;
}
userAdjusted = true;
event.preventDefault();
});
canvas.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (!userAdjusted) {
controls.radius = defaultRadius();
}
updateCamera();
}
window.addEventListener("resize", resize);
resize();
resetCamera();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
flows.forEach((flow) => {
const progress = (elapsed * flow.speed + flow.phase) % 1;
projected
.copy(flow.start)
.addScaledVector(flow.direction, progress * (flow.length - 0.14));
flow.mesh.position.copy(projected);
});
sunMarkers.forEach(({ mesh, phase }) => {
const pulse = 1 + Math.sin(elapsed * 2.2 + phase) * 0.08;
mesh.scale.setScalar(pulse);
});
motes.rotation.y = elapsed * 0.008;
motes.position.y = Math.sin(elapsed * 0.16) * 0.12;
updateCamera();
updateTags();
renderer.render(scene, camera);
if (!loading.classList.contains("hidden")) {
loading.classList.add("hidden");
}
}
animate();
</script>
</body>
</html>
```