Prompt specification
Build or customize the Three.js 3D scene "Greenhouse-effect educational 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: Greenhouse-effect educational exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/greenhouse-effect-educational-exhibit-x1219
Scene Description Prompt:
Show a voxel Sun–Earth greenhouse schematic with atmospheric absorption and emission traveling in both directions. One HTML file using Three.js from cdnjs.
Working Three.js Starter (greenhouse-effect-educational-exhibit-x1219):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Greenhouse — Sun–Earth Schematic</title>
<style>
:root {
color-scheme: dark;
--bg: #050914;
--panel: rgba(9, 17, 32, 0.78);
--panel-strong: rgba(10, 19, 36, 0.92);
--border: rgba(159, 196, 255, 0.16);
--text: #edf6ff;
--muted: #91a6c1;
--solar: #ffd166;
--surface-ir: #ff7a45;
--space-ir: #ff5577;
--down-ir: #d66cff;
--cyan: #67d9ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
z-index: 10;
top: 25px;
left: 27px;
pointer-events: none;
max-width: 430px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 23px;
height: 1px;
content: "";
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 43px);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.subtitle {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.24),
inset 0 1px 0 rgba(255, 255, 255, 0.03);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.legend {
left: 25px;
bottom: 25px;
width: 268px;
padding: 16px;
}
.panel-title {
margin: 0 0 12px;
color: #c8d8eb;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
align-items: center;
margin: 10px 0;
}
.legend-line {
position: relative;
height: 10px;
}
.legend-line::before {
position: absolute;
top: 4px;
right: 0;
left: 0;
height: 2px;
content: "";
background: currentColor;
box-shadow: 0 0 7px currentColor;
}
.legend-line::after {
position: absolute;
top: 1px;
right: 0;
width: 7px;
height: 7px;
content: "";
border-radius: 1px;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.legend-row strong {
display: block;
font-size: 12px;
font-weight: 650;
}
.legend-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.solar { color: var(--solar); }
.surface-ir { color: var(--surface-ir); }
.space-ir { color: var(--space-ir); }
.down-ir { color: var(--down-ir); }
.note {
margin: 12px 0 0;
padding-top: 11px;
border-top: 1px solid var(--border);
color: #7389a5;
font-size: 9px;
line-height: 1.5;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.readout {
top: 25px;
right: 25px;
width: 322px;
padding: 20px;
}
.readout h2 {
margin: 7px 0 15px;
font-size: 23px;
line-height: 1.06;
letter-spacing: -0.035em;
}
.steps {
display: grid;
gap: 12px;
margin: 0;
padding: 0;
list-style: none;
}
.steps li {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
color: #afc0d5;
font-size: 11px;
line-height: 1.5;
}
.step-number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(103, 217, 255, 0.22);
border-radius: 7px;
background: rgba(103, 217, 255, 0.06);
color: var(--cyan);
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.steps strong {
color: #e7f2ff;
font-weight: 650;
}
.callout {
margin-top: 17px;
padding: 12px 13px;
border-left: 2px solid var(--down-ir);
border-radius: 0 9px 9px 0;
background: rgba(214, 108, 255, 0.08);
color: #d8c8e6;
font-size: 11px;
line-height: 1.5;
}
.controls {
position: fixed;
z-index: 12;
bottom: 25px;
left: 50%;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel-strong);
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
transform: translateX(-50%);
backdrop-filter: blur(15px);
}
.control-button {
min-width: 38px;
height: 36px;
padding: 0 11px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: #b9c9dc;
cursor: pointer;
font-size: 11px;
font-weight: 650;
transition: 150ms ease;
}
.control-button:hover {
border-color: var(--border);
background: rgba(255, 255, 255, 0.05);
color: white;
}
.control-button.active {
border-color: rgba(103, 217, 255, 0.28);
background: rgba(103, 217, 255, 0.1);
color: var(--cyan);
}
.divider {
width: 1px;
height: 25px;
background: var(--border);
}
.speed {
display: flex;
align-items: center;
gap: 8px;
padding: 0 7px;
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
input[type="range"] {
width: 82px;
accent-color: var(--cyan);
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
transition: opacity 150ms ease;
}
#labels.hidden {
opacity: 0;
}
.scene-label {
position: absolute;
min-width: 120px;
max-width: 190px;
padding: 8px 10px;
border: 1px solid rgba(153, 193, 255, 0.18);
border-radius: 9px;
background: rgba(5, 12, 24, 0.78);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.24);
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.scene-label::before {
position: absolute;
top: 50%;
left: -4px;
width: 6px;
height: 6px;
content: "";
border-radius: 1px;
background: var(--label-color, #c8d8eb);
box-shadow: 0 0 9px var(--label-color, #c8d8eb);
transform: translateY(-50%);
}
.scene-label b {
display: block;
color: var(--label-color, #edf6ff);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
line-height: 1.2;
text-transform: uppercase;
}
.scene-label small {
display: block;
margin-top: 3px;
color: #92a8c3;
font-size: 9px;
line-height: 1.35;
}
.loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading::before {
width: 10px;
height: 10px;
margin-right: 12px;
content: "";
background: var(--cyan);
box-shadow: 0 0 18px var(--cyan);
animation: blink 900ms steps(2) infinite;
}
@keyframes blink {
50% { opacity: 0.2; }
}
@media (max-width: 1120px) {
.readout {
display: none;
}
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
h1 {
font-size: 27px;
}
.subtitle {
max-width: 310px;
font-size: 11px;
}
.legend {
right: 14px;
bottom: 79px;
left: 14px;
width: auto;
padding: 11px 13px;
}
.legend-row {
display: inline-grid;
width: 49%;
margin: 7px 0;
vertical-align: top;
}
.legend-row small,
.note {
display: none;
}
.panel-title {
margin-bottom: 5px;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
justify-content: center;
transform: none;
}
.speed {
padding: 0 2px;
}
input[type="range"] {
width: 62px;
}
.scene-label {
min-width: 100px;
max-width: 145px;
padding: 6px 8px;
}
.scene-label b {
font-size: 8px;
}
.scene-label small {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels"></div>
<header class="brand">
<div class="eyebrow">Interactive energy schematic</div>
<h1>Voxel Greenhouse</h1>
<p class="subtitle">
Sun → atmosphere → surface → space.<br />
Watch longwave energy absorbed, re-emitted, and returned.
</p>
</header>
<aside class="panel legend">
<div class="panel-title">Energy pathways</div>
<div class="legend-row">
<div class="legend-line solar"></div>
<div>
<strong>Incoming shortwave</strong>
<small>Solar energy toward Earth</small>
</div>
</div>
<div class="legend-row">
<div class="legend-line surface-ir"></div>
<div>
<strong>Surface longwave</strong>
<small>Thermal infrared emission</small>
</div>
</div>
<div class="legend-row">
<div class="legend-line space-ir"></div>
<div>
<strong>Atmosphere → space</strong>
<small>Upward infrared emission</small>
</div>
</div>
<div class="legend-row">
<div class="legend-line down-ir"></div>
<div>
<strong>Atmosphere → surface</strong>
<small>Downward infrared emission</small>
</div>
</div>
<p class="note">Conceptual model · not to scale · drag to orbit</p>
</aside>
<aside class="panel readout">
<div class="eyebrow">Atmospheric heat redistribution</div>
<h2>Shortwave in.<br />Longwave out—and back down.</h2>
<ol class="steps">
<li>
<span class="step-number">01</span>
<span><strong>Sunlight arrives.</strong> Clouds, ozone, and other constituents absorb some shortwave energy aloft.</span>
</li>
<li>
<span class="step-number">02</span>
<span><strong>The surface warms.</strong> Absorbed solar energy raises surface temperature.</span>
</li>
<li>
<span class="step-number">03</span>
<span><strong>The surface emits IR.</strong> CO₂ and H₂O absorb parts of this terrestrial longwave radiation.</span>
</li>
<li>
<span class="step-number">04</span>
<span><strong>The atmosphere re-emits IR.</strong> Energy travels both upward into space and downward toward the surface.</span>
</li>
</ol>
<div class="callout">
The downward infrared branch returns thermal energy to the surface—the core of the greenhouse effect.
</div>
</aside>
<nav class="controls" aria-label="Visualization controls">
<button class="control-button active" id="playButton" aria-label="Pause animation">Pause</button>
<button class="control-button active" id="labelButton">Labels</button>
<button class="control-button" id="resetButton">Reset view</button>
<span class="divider"></span>
<label class="speed">
Speed
<input id="speedSlider" type="range" min="0.2" max="2.4" step="0.1" value="1" />
<span id="speedValue">1.0×</span>
</label>
</nav>
<div class="loading" id="loading">Building voxel system</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.querySelector("#stage");
const labelLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const COLORS = {
solar: 0xffd166,
surfaceIR: 0xff7a45,
spaceIR: 0xff5577,
downIR: 0xd66cff,
cyan: 0x67d9ff
};
const sunCenter = new THREE.Vector3(-12, 0, 0);
const earthCenter = new THREE.Vector3(6.2, 0, 0);
const earthRadius = 2.2;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050914);
scene.fog = new THREE.FogExp2(0x050914, 0.009);
const renderer = new THREE.WebGLRenderer({
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.18;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
180
);
const orbit = {
target: new THREE.Vector3(-1.5, 0.25, 0),
radius: 31,
theta: 0.015,
phi: 1.245
};
function applyCamera() {
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);
}
applyCamera();
scene.add(new THREE.HemisphereLight(0x9ec7ff, 0x07101b, 1.05));
scene.add(new THREE.AmbientLight(0x6f86aa, 0.34));
const sunlight = new THREE.DirectionalLight(0xffedcf, 2.6);
sunlight.position.set(-10, 7, 11);
sunlight.target.position.copy(earthCenter);
scene.add(sunlight, sunlight.target);
const sunLight = new THREE.PointLight(0xff9c48, 55, 34, 2);
sunLight.position.copy(sunCenter);
scene.add(sunLight);
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 256;
const ctx = canvas.getContext("2d");
const gradient = ctx.createRadialGradient(
128, 128, 0,
128, 128, 128
);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.18, "rgba(255,255,255,0.72)");
gradient.addColorStop(0.48, "rgba(255,255,255,0.18)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const glowTexture = makeGlowTexture();
function addGlow(position, color, scale, opacity) {
const material = new THREE.SpriteMaterial({
map: glowTexture,
color,
transparent: true,
opacity,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(scale, scale, 1);
scene.add(sprite);
return sprite;
}
// Deterministic pseudo-random values keep the voxel layout stable.
let randomSeed = 57391;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function addStars() {
const count = 700;
const positions = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
positions[i * 3] = (random() - 0.5) * 100;
positions[i * 3 + 1] = (random() - 0.5) * 55;
positions[i * 3 + 2] = -8 - random() * 70;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const material = new THREE.PointsMaterial({
color: 0xa9c9ff,
size: 0.055,
transparent: true,
opacity: 0.68,
sizeAttenuation: true,
depthWrite: false
});
const stars = new THREE.Points(geometry, material);
scene.add(stars);
return stars;
}
const stars = addStars();
function instanceTransform(mesh, index, position, scale) {
const matrix = new THREE.Matrix4();
matrix.compose(
position,
new THREE.Quaternion(),
new THREE.Vector3(scale, scale, scale)
);
mesh.setMatrixAt(index, matrix);
}
function buildSun() {
const radius = 2.15;
const cell = 0.31;
const positions = [];
const colors = [];
const extent = Math.ceil(radius / cell);
for (let x = -extent; x <= extent; x++) {
for (let y = -extent; y <= extent; y++) {
for (let z = -extent; z <= extent; z++) {
const px = x * cell;
const py = y * cell;
const pz = z * cell;
const distance = Math.hypot(px, py, pz);
if (
distance <= radius &&
distance > radius - cell * 1.45
) {
positions.push(
new THREE.Vector3(
sunCenter.x + px,
sunCenter.y + py,
sunCenter.z + pz
)
);
const heat = random();
const color = new THREE.Color().lerpColors(
new THREE.Color(0xff9e22),
new THREE.Color(0xfff1a1),
heat
);
colors.push(color);
}
}
}
}
const geometry = new THREE.BoxGeometry(cell * 0.92, cell * 0.92, cell * 0.92);
const material = new THREE.MeshBasicMaterial({ color: 0xffffff });
const mesh = new THREE.InstancedMesh(geometry, material, positions.length);
positions.forEach((position, index) => {
instanceTransform(mesh, index, position, 1);
mesh.setColorAt(index, colors[index]);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
scene.add(mesh);
const corona = addGlow(
sunCenter,
0xff8c24,
8.4,
0.45
);
corona.renderOrder = -1;
return { mesh, corona };
}
const sun = buildSun();
function surfaceNoise(x, y, z) {
return (
Math.sin(x * 1.45 + z * 0.8) +
Math.cos(z * 1.75 - y * 0.65) +
0.55 * Math.sin((x + z) * 2.3) +
0.35 * Math.cos(y * 3.1 - x * 0.5)
);
}
function buildEarth() {
const radius = earthRadius;
const cell = 0.29;
const extent = Math.ceil(radius / cell);
const layers = {
ocean: { positions: [], colors: [] },
land: { positions: [], colors: [] },
ice: { positions: [], colors: [] }
};
for (let x = -extent; x <= extent; x++) {
for (let y = -extent; y <= extent; y++) {
for (let z = -extent; z <= extent; z++) {
const px = x * cell;
const py = y * cell;
const pz = z * cell;
const distance = Math.hypot(px, py, pz);
if (
distance > radius ||
distance <= radius - cell * 1.48
) {
continue;
}
const position = new THREE.Vector3(
earthCenter.x + px,
earthCenter.y + py,
earthCenter.z + pz
);
const noise = surfaceNoise(px, py, pz);
const variation = random() * 0.13;
if (Math.abs(py) > radius * 0.76) {
layers.ice.positions.push(position);
layers.ice.colors.push(
new THREE.Color(0xd8f1ff).offsetHSL(0, 0, variation - 0.05)
);
} else if (noise > 0.63) {
layers.land.positions.push(position);
layers.land.colors.push(
new THREE.Color(
noise > 1.25 ? 0x79b85f : 0x378a59
).offsetHSL(0, 0, variation - 0.04)
);
} else {
layers.ocean.positions.push(position);
layers.ocean.colors.push(
new THREE.Color(
pz > 0 ? 0x176fa7 : 0x125184
).offsetHSL(0, 0, variation - 0.05)
);
}
}
}
}
const geometry = new THREE.BoxGeometry(
cell * 0.93,
cell * 0.93,
cell * 0.93
);
const materials = {
ocean: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.62,
metalness: 0.12
}),
land: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0
}),
ice: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.02
})
};
const meshes = [];
for (const name of Object.keys(layers)) {
const layer = layers[name];
const mesh = new THREE.InstancedMesh(
geometry,
materials[name],
layer.positions.length
);
layer.positions.forEach((position, index) => {
instanceTransform(mesh, index, position, 1);
mesh.setColorAt(index, layer.colors[index]);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
scene.add(mesh);
meshes.push(mesh);
}
const halo = addGlow(
earthCenter,
0x348dff,
8.6,
0.20
);
halo.renderOrder = -2;
return { meshes, halo };
}
const earth = buildEarth();
function buildAtmosphere() {
const cell = 0.4;
const extent = 9;
const positions = [];
for (let x = -extent; x <= extent; x++) {
for (let y = -extent; y <= extent; y++) {
for (let z = -extent; z <= extent; z++) {
const px = x * cell;
const py = y * cell;
const pz = z * cell;
const distance = Math.hypot(px, py, pz);
if (
distance > earthRadius * 1.04 &&
distance < earthRadius * 1.34
) {
positions.push(
new THREE.Vector3(
earthCenter.x + px,
earthCenter.y + py,
earthCenter.z + pz
)
);
}
}
}
}
const atmosphereGeometry = new THREE.BoxGeometry(
cell * 0.91,
cell * 0.91,
cell * 0.91
);
const atmosphereMaterial = new THREE.MeshBasicMaterial({
color: 0x65d6ff,
transparent: true,
opacity: 0.105,
depthWrite: false
});
const atmosphere = new THREE.InstancedMesh(
atmosphereGeometry,
atmosphereMaterial,
positions.length
);
positions.forEach((position, index) => {
instanceTransform(atmosphere, index, position, 1);
});
atmosphere.instanceMatrix.needsUpdate = true;
atmosphere.computeBoundingSphere();
atmosphere.renderOrder = 2;
scene.add(atmosphere);
// Bright pink voxels identify greenhouse-gas tracers inside the shell.
const tracerPositions = [];
for (let i = 0; i < positions.length; i += 21) {
tracerPositions.push(positions[i]);
}
const tracerGeometry = new THREE.BoxGeometry(0.18, 0.18, 0.18);
const tracerMaterial = new THREE.MeshBasicMaterial({
color: COLORS.downIR,
transparent: true,
opacity: 0.58,
depthWrite: false
});
const tracers = new THREE.InstancedMesh(
tracerGeometry,
tracerMaterial,
tracerPositions.length
);
tracerPositions.forEach((position, index) => {
instanceTransform(tracers, index, position, 1);
});
tracers.instanceMatrix.needsUpdate = true;
tracers.computeBoundingSphere();
tracers.renderOrder = 3;
scene.add(tracers);
return { atmosphere, tracers };
}
const atmosphere = buildAtmosphere();
// A faint dotted orbital guide helps establish the atmospheric boundary.
const guidePoints = [];
for (let i = 0; i <= 160; i++) {
const angle = (i / 160) * Math.PI * 2;
guidePoints.push(
new THREE.Vector3(
earthCenter.x + Math.cos(angle) * 3.35,
earthCenter.y + Math.sin(angle) * 3.35,
earthCenter.z - 0.3
)
);
}
const guide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(guidePoints),
new THREE.LineDashedMaterial({
color: 0x65b9e6,
dashSize: 0.11,
gapSize: 0.13,
transparent: true,
opacity: 0.19,
depthWrite: false
})
);
guide.computeLineDistances();
scene.add(guide);
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const xAxis = new THREE.Vector3(1, 0, 0);
function makeBlockArrow(color, opacity = 0.72) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthTest: false,
depthWrite: false
});
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.36, 0.075, 0.075),
material
);
shaft.position.x = 0.05;
const upperWing = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.075, 0.075),
material
);
upperWing.position.set(-0.055, 0.105, 0);
upperWing.rotation.z = -0.68;
const lowerWing = upperWing.clone();
lowerWing.position.y = -0.105;
lowerWing.rotation.z = 0.68;
group.add(shaft, upperWing, lowerWing);
group.renderOrder = 9;
return group;
}
class VoxelFlow {
constructor(points, options = {}) {
this.points = points.map((point) =>
point.isVector3 ? point.clone() : new THREE.Vector3(...point)
);
this.curve = new THREE.CurvePath();
for (let i = 0; i < this.points.length - 1; i++) {
this.curve.add(
new THREE.LineCurve3(this.points[i], this.points[i + 1])
);
}
this.speed = options.speed ?? 0.12;
this.count = options.count ?? 4;
this.phase = options.phase ?? 0;
this.size = options.size ?? 0.16;
this.packets = [];
const rail = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(this.points),
new THREE.LineDashedMaterial({
color: options.color,
dashSize: options.dashSize ?? 0.18,
gapSize: options.gapSize ?? 0.15,
transparent: true,
opacity: options.railOpacity ?? 0.25,
depthWrite: false
})
);
rail.computeLineDistances();
flowGroup.add(rail);
const packetMaterial = new THREE.MeshBasicMaterial({
color: options.color,
transparent: true,
opacity: 0.96,
depthWrite: false
});
const trailMaterial = packetMaterial.clone();
trailMaterial.opacity = 0.48;
for (let i = 0; i < this.count; i++) {
const packet = new THREE.Group();
const core = new THREE.Mesh(
new THREE.BoxGeometry(
this.size,
this.size,
this.size
),
packetMaterial
);
const trailA = new THREE.Mesh(
new THREE.BoxGeometry(
this.size * 0.58,
this.size * 0.58,
this.size * 0.58
),
trailMaterial
);
trailA.position.x = -this.size * 1.02;
const trailB = new THREE.Mesh(
new THREE.BoxGeometry(
this.size * 0.34,
this.size * 0.34,
this.size * 0.34
),
trailMaterial
);
trailB.position.x = -this.size * 1.8;
packet.add(core, trailA, trailB);
flowGroup.add(packet);
this.packets.push(packet);
}
if (options.arrowAt !== undefined) {
const arrow = makeBlockArrow(
options.color,
options.arrowOpacity ?? 0.72
);
arrow.position.copy(
this.curve.getPointAt(options.arrowAt)
);
arrow.quaternion.setFromUnitVectors(
xAxis,
this.curve.getTangentAt(options.arrowAt).normalize()
);
flowGroup.add(arrow);
}
}
update(delta) {
this.phase = (this.phase + this.speed * delta) % 1;
this.packets.forEach((packet, index) => {
const t = (this.phase + index / this.packets.length) % 1;
const point = this.curve.getPointAt(t);
const tangent = this.curve.getTangentAt(t).normalize();
packet.position.copy(point);
packet.quaternion.setFromUnitVectors(xAxis, tangent);
const pulse = 0.9 + Math.sin(t * Math.PI * 8 + index) * 0.12;
packet.children[0].scale.setScalar(pulse);
});
}
}
const flows = [];
// Solar energy absorbed by the atmosphere before reaching the surface.
flows.push(
new VoxelFlow(
[
new THREE.Vector3(-9.85, 1.6, -0.2),
new THREE.Vector3(-2.0, 1.6, -0.2),
new THREE.Vector3(4.05, 1.6, -0.2)
],
{
color: COLORS.solar,
speed: 0.11,
count: 4,
phase: 0.05,
arrowAt: 0.78,
railOpacity: 0.27
}
)
);
// Solar energy passing through the atmosphere and absorbed by the surface.
flows.push(
new VoxelFlow(
[
new THREE.Vector3(-9.85, -0.35, 0.8),
new THREE.Vector3(-2.0, -0.35, 0.8),
new THREE.Vector3(4.28, -0.35, 0.8)
],
{
color: COLORS.solar,
speed: 0.115,
count: 5,
phase: 0.36,
arrowAt: 0.75,
size: 0.15
}
)
);
// Terrestrial longwave radiation emitted by the surface.
flows.push(
new VoxelFlow(
[
new THREE.Vector3(6.2, 2.08, 0.8),
new THREE.Vector3(6.2, 3.08, 0.8)
],
{
color: COLORS.surfaceIR,
speed: 0.17,
count: 3,
phase: 0.1,
arrowAt: 0.64,
size: 0.17
}
)
);
// Atmospheric infrared emission upward into space.
flows.push(
new VoxelFlow(
[
new THREE.Vector3(6.2, 3.08, 0.8),
new THREE.Vector3(6.35, 5.5, 0.8),
new THREE.Vector3(6.55, 8.25, 0.8)
],
{
color: COLORS.spaceIR,
speed: 0.145,
count: 5,
phase: 0.2,
arrowAt: 0.72,
size: 0.17
}
)
);
// Atmospheric infrared emission downward toward the surface.
flows.push(
new VoxelFlow(
[
new THREE.Vector3(6.2, 3.08, 0.8),
new THREE.Vector3(6.2, 2.58, 0.86),
new THREE.Vector3(6.2, 2.08, 0.8)
],
{
color: COLORS.downIR,
speed: 0.15,
count: 4,
phase: 0.56,
arrowAt: 0.62,
size: 0.16
}
)
);
// A faint direct-escape path represents transmission through an
// atmospheric spectral window rather than absorption and re-emission.
flows.push(
new VoxelFlow(
[
new THREE.Vector3(7.55, 1.4, 1.0),
new THREE.Vector3(9.3, 3.65, 1.0),
new THREE.Vector3(12.1, 6.35, 1.0)
],
{
color: COLORS.surfaceIR,
speed: 0.09,
count: 3,
phase: 0.38,
arrowAt: 0.7,
railOpacity: 0.13,
arrowOpacity: 0.42,
size: 0.12
}
)
);
const eventMarkers = [];
function makeEventMarker(position, color) {
const group = new THREE.Group();
group.position.copy(position);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false
});
const cubeSize = 0.13;
const offsets = [
[0, 0, 0],
[0.14, 0, 0],
[-0.14, 0, 0],
[0, 0.14, 0],
[0, -0.14, 0],
[0, 0, 0.14]
];
offsets.forEach((offset, index) => {
const cube = new THREE.Mesh(
new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize),
material
);
cube.position.set(...offset);
if (index > 0) {
cube.scale.setScalar(0.68);
}
group.add(cube);
});
const glow = addGlow(position, color, 1.35, 0.48);
glow.renderOrder = 8;
scene.add(group);
eventMarkers.push({ group, glow, phase: random() * Math.PI * 2 });
return group;
}
makeEventMarker(
new THREE.Vector3(4.05, 1.6, -0.2),
COLORS.solar
);
makeEventMarker(
new THREE.Vector3(4.28, -0.35, 0.8),
COLORS.solar
);
makeEventMarker(
new THREE.Vector3(6.2, 3.08, 0.8),
COLORS.surfaceIR
);
const labels = [];
function addLabel(title, subtitle, position, color, offset = [0, 0]) {
const element = document.createElement("div");
element.className = "scene-label";
element.style.setProperty("--label-color", `#${color.toString(16).padStart(6, "0")}`);
element.innerHTML = `<b>${title}</b><small>${subtitle}</small>`;
labelLayer.appendChild(element);
labels.push({
element,
position: position.clone(),
offset
});
}
addLabel(
"Solar shortwave",
"Visible and near-infrared energy",
new THREE.Vector3(-11.9, 2.55, 0),
COLORS.solar,
[0, -10]
);
addLabel(
"Atmosphere",
"CO₂ · H₂O · O₃ and other constituents",
new THREE.Vector3(3.7, 2.75, 0.8),
COLORS.cyan,
[-28, -38]
);
addLabel(
"Shortwave absorption",
"Some energy is absorbed aloft",
new THREE.Vector3(4.05, 1.6, -0.2),
COLORS.solar,
[58, -15]
);
addLabel(
"Surface heating",
"Incoming energy becomes thermal energy",
new THREE.Vector3(4.28, -0.35, 0.8),
COLORS.solar,
[-45, 32]
);
addLabel(
"Surface longwave",
"Earth radiates thermal infrared",
new THREE.Vector3(6.2, 2.12, 0.8),
COLORS.surfaceIR,
[83, -12]
);
addLabel(
"IR absorption",
"Greenhouse gases absorb terrestrial IR",
new THREE.Vector3(6.2, 3.08, 0.8),
COLORS.surfaceIR,
[-94, -2]
);
addLabel(
"Atmospheric emission ↑",
"Infrared energy travels into space",
new THREE.Vector3(6.55, 6.55, 0.8),
COLORS.spaceIR,
[78, -2]
);
addLabel(
"Atmospheric emission ↓",
"Infrared energy returns to the surface",
new THREE.Vector3(6.2, 2.65, 0.85),
COLORS.downIR,
[86, 22]
);
addLabel(
"Earth surface",
"Warms and drives longwave emission",
new THREE.Vector3(6.2, -2.35, 0),
0x8dd9ff,
[0, 26]
);
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 x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -80 &&
x < width + 80 &&
y > -40 &&
y < height + 40;
label.element.style.display = visible ? "block" : "none";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// Direct camera controls, implemented without addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.005;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.005,
0.28,
Math.PI - 0.28
);
applyCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
19,
49
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.radius = 31;
orbit.theta = 0.015;
orbit.phi = 1.245;
applyCamera();
});
let paused = false;
let speed = 1;
let labelsVisible = true;
const playButton = document.querySelector("#playButton");
const labelButton = document.querySelector("#labelButton");
const resetButton = document.querySelector("#resetButton");
const speedSlider = document.querySelector("#speedSlider");
const speedValue = document.querySelector("#speedValue");
function togglePause() {
paused = !paused;
playButton.textContent = paused ? "Play" : "Pause";
playButton.classList.toggle("active", !paused);
}
playButton.addEventListener("click", togglePause);
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelLayer.classList.toggle("hidden", !labelsVisible);
labelButton.classList.toggle("active", labelsVisible);
});
resetButton.addEventListener("click", () => {
orbit.radius = 31;
orbit.theta = 0.015;
orbit.phi = 1.245;
applyCamera();
});
speedSlider.addEventListener("input", () => {
speed = Number(speedSlider.value);
speedValue.textContent = `${speed.toFixed(1)}×`;
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
if (event.key.toLowerCase() === "l") {
labelButton.click();
}
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (!paused) {
flows.forEach((flow) => flow.update(delta * speed));
sun.mesh.rotation.y += delta * 0.055;
sun.mesh.rotation.x += delta * 0.018;
sun.corona.material.opacity = 0.41 + Math.sin(elapsed * 1.7) * 0.055;
atmosphere.atmosphere.rotation.y += delta * 0.012;
atmosphere.tracers.rotation.y -= delta * 0.022;
atmosphere.tracers.rotation.x += delta * 0.006;
earth.meshes.forEach((mesh, index) => {
mesh.rotation.y += delta * (index === 0 ? 0.008 : 0.004);
});
stars.rotation.y += delta * 0.0015;
eventMarkers.forEach((marker) => {
marker.phase += delta * 2.4;
const scale = 0.9 + Math.sin(marker.phase) * 0.16;
marker.group.scale.setScalar(scale);
marker.group.rotation.y += delta * 0.8;
marker.glow.material.opacity = 0.38 + Math.sin(marker.phase) * 0.16;
});
}
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```