Prompt specification
Build or customize the Three.js 3D scene "Earth radiation balance desk model" 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: Earth radiation balance desk model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/earth-radiation-balance-desk-model-x1217
Scene Description Prompt:
A low-poly Earth model separates incoming sunlight, reflected light, and outgoing infrared with schematic atmospheric interactions. Three.js from cdnjs, one HTML file.
Working Three.js Starter (earth-radiation-balance-desk-model-x1217):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Earth Energy Exchange</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 17, 34, 0.72);
--border: rgba(151, 197, 229, 0.2);
--text: #eef7ff;
--muted: #91a8bd;
--sun: #ffd166;
--reflection: #6bd9ff;
--infrared: #ff596d;
--reemission: #ffae57;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 42%, rgba(18, 58, 95, 0.22), transparent 34%),
radial-gradient(circle at 18% 28%, rgba(63, 45, 91, 0.16), transparent 27%),
#030712;
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#viewport canvas {
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.intro {
position: absolute;
top: 27px;
left: 30px;
max-width: 430px;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.65);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #87b6d2;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #66e6ae;
box-shadow: 0 0 12px rgba(102, 230, 174, 0.8);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 380px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: absolute;
top: 28px;
right: 28px;
width: 235px;
padding: 17px 18px;
border: 1px solid var(--border);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(15px);
}
.legend-title {
margin-bottom: 12px;
color: #8ca8be;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr;
gap: 10px;
align-items: start;
margin: 10px 0;
}
.swatch {
width: 8px;
height: 8px;
margin-top: 3px;
border-radius: 50%;
box-shadow: 0 0 13px currentColor;
}
.legend-row strong {
display: block;
margin-bottom: 2px;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.07em;
}
.legend-row small {
display: block;
color: #8299ad;
font-size: 10px;
line-height: 1.35;
}
.legend-divider {
height: 1px;
margin: 14px 0 12px;
background: rgba(151, 197, 229, 0.12);
}
.legend-note {
display: flex;
align-items: center;
gap: 8px;
color: #8ca4b8;
font-size: 10px;
line-height: 1.4;
}
.legend-note::before {
content: "";
width: 22px;
height: 1px;
background: linear-gradient(90deg, transparent, #69b9ea);
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
}
.callout {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px 7px 8px;
border: 1px solid rgba(157, 198, 226, 0.18);
border-radius: 8px;
background: rgba(6, 13, 26, 0.76);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(9px);
transform: translate(-50%, -50%);
transition: opacity 160ms ease;
white-space: nowrap;
}
.callout .dot {
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--c);
box-shadow: 0 0 11px var(--c);
}
.callout b {
display: block;
color: var(--c);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
}
.callout small {
display: block;
margin-top: 2px;
color: #a7b8c7;
font-size: 9px;
}
.controls {
position: absolute;
right: 28px;
bottom: 26px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
padding: 9px 13px;
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(8, 17, 34, 0.82);
color: #c8d9e7;
font: inherit;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.05em;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
color 150ms ease,
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
button:hover {
color: #fff;
border-color: rgba(125, 210, 255, 0.55);
background: rgba(17, 39, 60, 0.92);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid #6bd9ff;
outline-offset: 2px;
}
.hint {
position: absolute;
left: 30px;
bottom: 29px;
color: #6f879b;
font-size: 10px;
letter-spacing: 0.035em;
}
.hint span {
margin: 0 8px;
color: #3d566b;
}
@media (max-width: 760px) {
.intro {
top: 18px;
left: 18px;
}
h1 {
font-size: 29px;
}
.subtitle {
display: none;
}
.legend {
top: auto;
right: 16px;
bottom: 67px;
left: 16px;
width: auto;
padding: 12px 14px;
}
.legend-title,
.legend-divider,
.legend-note {
display: none;
}
.legend-content {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
.legend-row {
margin: 0;
grid-template-columns: 8px 1fr;
gap: 7px;
}
.legend-row small {
display: none;
}
.controls {
right: 16px;
bottom: 17px;
}
.hint {
display: none;
}
.callout {
padding: 5px 7px;
}
.callout small {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="hud">
<header class="intro">
<div class="eyebrow">
<span class="status-dot" id="statusDot"></span>
<span id="statusText">Flow live · interactive model</span>
</div>
<h1>Earth energy<br />exchange</h1>
<p class="subtitle">
A low-poly view of sunlight entering the atmosphere, visible light
reflecting from the surface, and infrared energy leaving Earth.
</p>
</header>
<aside class="legend" aria-label="Energy path legend">
<div class="legend-title">Energy pathways</div>
<div class="legend-content">
<div class="legend-row">
<span class="swatch" style="color:var(--sun);background:var(--sun)"></span>
<div>
<strong style="color:var(--sun)">SUNLIGHT</strong>
<small>Incoming shortwave radiation</small>
</div>
</div>
<div class="legend-row">
<span
class="swatch"
style="color:var(--reflection);background:var(--reflection)"
></span>
<div>
<strong style="color:var(--reflection)">REFLECTION</strong>
<small>Visible light returning to space</small>
</div>
</div>
<div class="legend-row">
<span
class="swatch"
style="color:var(--infrared);background:var(--infrared)"
></span>
<div>
<strong style="color:var(--infrared)">INFRARED</strong>
<small>Surface thermal emission</small>
</div>
</div>
</div>
<div class="legend-divider"></div>
<div class="legend-note">
Atmospheric absorption can delay infrared energy before it escapes.
</div>
</aside>
<div id="labels" aria-hidden="true">
<div class="callout" id="labelSunlight" style="--c:var(--sun)">
<span class="dot"></span>
<span><b>SUNLIGHT</b><small>shortwave energy in</small></span>
</div>
<div class="callout" id="labelReflection" style="--c:var(--reflection)">
<span class="dot"></span>
<span><b>REFLECTED</b><small>visible light out</small></span>
</div>
<div class="callout" id="labelInfrared" style="--c:var(--infrared)">
<span class="dot"></span>
<span><b>SURFACE IR</b><small>thermal energy</small></span>
</div>
<div class="callout" id="labelReemission" style="--c:var(--reemission)">
<span class="dot"></span>
<span><b>RE-EMISSION</b><small>atmosphere to space</small></span>
</div>
<div class="callout" id="labelAtmosphere" style="--c:#8bd8ff">
<span class="dot"></span>
<span><b>ATMOSPHERE</b><small>absorbs and redirects</small></span>
</div>
</div>
<div class="hint">
Drag to orbit <span>•</span> Scroll or pinch to zoom <span>•</span>
Double-click to reset
</div>
<div class="controls">
<button id="pauseButton" type="button">Pause flow</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x030712, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-1, 0, 0);
const view = {
theta: 0.02,
phi: 1.17,
radius: 11.5,
desiredTheta: 0.02,
desiredPhi: 1.17,
desiredRadius: 11.5
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + view.radius * sinPhi * Math.sin(view.theta),
cameraTarget.y + view.radius * Math.cos(view.phi),
cameraTarget.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.AmbientLight(0x8fb6d7, 0.62));
const sunlight = new THREE.DirectionalLight(0xffedc4, 3.2);
sunlight.position.set(-6.2, 2.4, 0.2);
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0x65a9ff, 0.72);
fillLight.position.set(5, -1, 7);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0x6cc8ff, 0.8);
rimLight.position.set(2, 5, -6);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Deterministic random helpers
// ---------------------------------------------------------------------
let randomSeed = 731942;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function hash2(x, y) {
const value = Math.sin(x * 12.9898 + y * 78.233) * 43758.5453;
return value - Math.floor(value);
}
// ---------------------------------------------------------------------
// Star field
// ---------------------------------------------------------------------
const starCount = 760;
const starPositions = new Float32Array(starCount * 3);
const starColors = new Float32Array(starCount * 3);
const starColor = new THREE.Color();
for (let i = 0; i < starCount; i++) {
const theta = random() * Math.PI * 2;
const phi = Math.acos(2 * random() - 1);
const radius = 24 + random() * 17;
starPositions[i * 3] = radius * Math.sin(phi) * Math.cos(theta);
starPositions[i * 3 + 1] = radius * Math.cos(phi);
starPositions[i * 3 + 2] = radius * Math.sin(phi) * Math.sin(theta);
const warmth = random();
starColor.setHSL(0.54 + warmth * 0.1, 0.35, 0.58 + random() * 0.25);
starColors[i * 3] = starColor.r;
starColors[i * 3 + 1] = starColor.g;
starColors[i * 3 + 2] = starColor.b;
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.BufferAttribute(starPositions, 3)
);
starGeometry.setAttribute("color", new THREE.BufferAttribute(starColors, 3));
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
size: 0.065,
sizeAttenuation: true,
vertexColors: true,
transparent: true,
opacity: 0.82,
depthWrite: false
})
);
scene.add(stars);
// ---------------------------------------------------------------------
// Low-poly Earth
// ---------------------------------------------------------------------
const landPolygons = [
// North America
[
[-168, 70], [-145, 72], [-130, 61], [-123, 50], [-116, 32],
[-105, 22], [-96, 17], [-87, 16], [-81, 25], [-80, 34],
[-66, 45], [-53, 50], [-62, 61], [-94, 73], [-126, 76]
],
// Greenland
[
[-73, 60], [-50, 59], [-22, 70], [-25, 81], [-47, 84],
[-66, 78], [-73, 69]
],
// South America
[
[-81, 12], [-69, 11], [-59, 7], [-49, 0], [-35, -7],
[-40, -21], [-52, -35], [-61, -53], [-72, -55], [-75, -35],
[-78, -15]
],
// Africa
[
[-17, 35], [8, 37], [31, 31], [43, 13], [50, 9],
[42, -12], [32, -30], [18, -35], [5, -29], [-5, -10],
[-16, 14]
],
// Europe and Asia
[
[-11, 36], [-9, 44], [-2, 49], [8, 55], [20, 61],
[32, 71], [62, 76], [96, 78], [130, 72], [165, 68],
[178, 55], [155, 50], [142, 37], [130, 31], [122, 20],
[110, 8], [102, 1], [94, 8], [80, 20], [70, 24],
[57, 29], [48, 38], [35, 42], [27, 37], [20, 40],
[8, 43], [3, 38]
],
// Australia
[
[113, -11], [122, -16], [137, -12], [146, -19],
[153, -28], [146, -39], [132, -35], [115, -34], [111, -24]
],
// Madagascar
[[47, -13], [50, -17], [47, -26], [44, -24], [44, -16]],
// Japan
[[130, 32], [136, 35], [141, 40], [145, 44], [141, 35], [134, 33]],
// British Isles
[[-8, 50], [-3, 51], [1, 53], [-2, 59], [-7, 57]],
// Iceland
[[-24, 63], [-14, 64], [-14, 67], [-23, 67]],
// Indonesia
[[95, 5], [119, 7], [141, -3], [130, -9], [110, -8], [100, -3]],
// Cuba / Caribbean
[[-85, 22], [-76, 20], [-73, 23], [-83, 24]],
// New Zealand
[[166, -35], [174, -39], [178, -46], [170, -46], [166, -41]]
];
function pointInPolygon(x, y, polygon) {
let inside = false;
for (
let i = 0, j = polygon.length - 1;
i < polygon.length;
j = i++
) {
const xi = polygon[i][0];
const yi = polygon[i][1];
const xj = polygon[j][0];
const yj = polygon[j][1];
const intersects =
yi > y !== yj > y &&
x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
if (intersects) inside = !inside;
}
return inside;
}
function isLand(lon, lat) {
if (lat < -70) return true;
for (const polygon of landPolygons) {
if (pointInPolygon(lon, lat, polygon)) return true;
}
return false;
}
function surfaceColor(lon, lat) {
const variation = hash2(lon * 0.08, lat * 0.08);
if (isLand(lon, lat)) {
if (lat > 73 || (lon > -75 && lon < -20 && lat > 60)) {
return new THREE.Color(0xd9eceb);
}
const isDesert =
(lon > -17 && lon < 49 && lat > 12 && lat < 34) ||
(lon > 35 && lon < 62 && lat > 15 && lat < 34) ||
(lon > 116 && lon < 145 && lat > -36 && lat < -18);
if (isDesert) {
return new THREE.Color().setHSL(
0.105 + variation * 0.025,
0.31,
0.49 + variation * 0.08
);
}
if (lat > 48 || (lon > 45 && lon < 115 && lat > 38)) {
return new THREE.Color().setHSL(
0.22,
0.16,
0.43 + variation * 0.07
);
}
return new THREE.Color().setHSL(
0.38 + variation * 0.035,
0.31 + variation * 0.1,
0.32 + variation * 0.09
);
}
const deepOcean = new THREE.Color(0x083857);
const shallowOcean = new THREE.Color(0x145c7f);
const ocean = deepOcean.clone().lerp(shallowOcean, variation * 0.65);
if (Math.abs(lat) > 60) ocean.lerp(new THREE.Color(0x8dc3d2), 0.28);
return ocean;
}
const earthBaseGeometry = new THREE.SphereGeometry(2, 36, 22);
const earthGeometry = earthBaseGeometry.toNonIndexed();
earthBaseGeometry.dispose();
const earthPositions = earthGeometry.getAttribute("position");
const earthColors = new Float32Array(earthPositions.count * 3);
const triangleCenter = new THREE.Vector3();
for (let i = 0; i < earthPositions.count; i += 3) {
triangleCenter
.set(
earthPositions.getX(i) +
earthPositions.getX(i + 1) +
earthPositions.getX(i + 2),
earthPositions.getY(i) +
earthPositions.getY(i + 1) +
earthPositions.getY(i + 2),
earthPositions.getZ(i) +
earthPositions.getZ(i + 1) +
earthPositions.getZ(i + 2)
)
.multiplyScalar(1 / 3)
.normalize();
const lon = THREE.MathUtils.radToDeg(
Math.atan2(triangleCenter.z, triangleCenter.x)
);
const lat = THREE.MathUtils.radToDeg(
Math.asin(triangleCenter.y)
);
const color = surfaceColor(lon, lat);
for (let vertex = 0; vertex < 3; vertex++) {
const offset = (i + vertex) * 3;
earthColors[offset] = color.r;
earthColors[offset + 1] = color.g;
earthColors[offset + 2] = color.b;
}
}
earthGeometry.setAttribute(
"color",
new THREE.BufferAttribute(earthColors, 3)
);
earthGeometry.computeVertexNormals();
const earth = new THREE.Mesh(
earthGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.91,
metalness: 0.02
})
);
earth.rotation.y = -0.18;
scene.add(earth);
const wireframe = new THREE.LineSegments(
new THREE.WireframeGeometry(earthGeometry),
new THREE.LineBasicMaterial({
color: 0xb5e4f4,
transparent: true,
opacity: 0.045,
depthWrite: false
})
);
wireframe.rotation.copy(earth.rotation);
wireframe.scale.setScalar(1.001);
scene.add(wireframe);
// ---------------------------------------------------------------------
// Atmospheric shell
// ---------------------------------------------------------------------
const atmosphereMaterial = new THREE.ShaderMaterial({
uniforms: {
uTime: { value: 0 },
uColor: { value: new THREE.Color(0x58bfff) }
},
vertexShader: `
varying vec3 vWorldNormal;
varying vec3 vWorldPosition;
void main() {
vWorldNormal = normalize(mat3(modelMatrix) * normal);
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`,
fragmentShader: `
uniform float uTime;
uniform vec3 uColor;
varying vec3 vWorldNormal;
varying vec3 vWorldPosition;
void main() {
vec3 viewDirection = normalize(cameraPosition - vWorldPosition);
float fresnel = pow(
1.0 - max(dot(normalize(vWorldNormal), viewDirection), 0.0),
2.35
);
float pulse = 0.9 + 0.1 * sin(uTime * 1.4);
float alpha = fresnel * 0.72 * pulse;
gl_FragColor = vec4(uColor, alpha);
}
`,
transparent: true,
blending: THREE.AdditiveBlending,
side: THREE.FrontSide,
depthWrite: false
});
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(2.19, 48, 32),
atmosphereMaterial
);
atmosphere.renderOrder = 3;
scene.add(atmosphere);
// ---------------------------------------------------------------------
// Low-poly cloud patches
// ---------------------------------------------------------------------
const cloudGeometry = new THREE.CircleGeometry(1, 7);
const cloudMaterial = new THREE.MeshBasicMaterial({
color: 0xf4fbff,
transparent: true,
opacity: 0.25,
side: THREE.DoubleSide,
depthWrite: false
});
const cloudCount = 92;
const clouds = new THREE.InstancedMesh(
cloudGeometry,
cloudMaterial,
cloudCount
);
const dummy = new THREE.Object3D();
const zAxis = new THREE.Vector3(0, 0, 1);
for (let i = 0; i < cloudCount; i++) {
const lon = (random() - 0.5) * Math.PI * 2;
const lat = (random() - 0.5) * 2.32;
const normal = new THREE.Vector3(
Math.cos(lat) * Math.cos(lon),
Math.sin(lat),
Math.cos(lat) * Math.sin(lon)
);
const size = 0.045 + random() * 0.115;
dummy.position.copy(normal).multiplyScalar(2.038);
dummy.quaternion.setFromUnitVectors(zAxis, normal);
dummy.scale.set(
size * (1.0 + random() * 0.65),
size * (0.45 + random() * 0.3),
1
);
dummy.updateMatrix();
clouds.setMatrixAt(i, dummy.matrix);
}
clouds.instanceMatrix.needsUpdate = true;
clouds.renderOrder = 2;
scene.add(clouds);
// ---------------------------------------------------------------------
// Sun and procedural glow
// ---------------------------------------------------------------------
const sunPosition = new THREE.Vector3(-6.2, 2.4, 0.2);
const sun = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.43, 2),
new THREE.MeshBasicMaterial({ color: 0xffd36a })
);
sun.position.copy(sunPosition);
scene.add(sun);
const sunHalo = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72, 2),
new THREE.MeshBasicMaterial({
color: 0xffbd45,
transparent: true,
opacity: 0.09,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
sunHalo.position.copy(sunPosition);
scene.add(sunHalo);
const glowCanvas = document.createElement("canvas");
glowCanvas.width = 128;
glowCanvas.height = 128;
const glowContext = glowCanvas.getContext("2d");
const glowGradient = glowContext.createRadialGradient(
64,
64,
0,
64,
64,
64
);
glowGradient.addColorStop(0, "rgba(255,224,140,0.95)");
glowGradient.addColorStop(0.18, "rgba(255,190,70,0.46)");
glowGradient.addColorStop(0.52, "rgba(255,154,42,0.13)");
glowGradient.addColorStop(1, "rgba(255,130,30,0)");
glowContext.fillStyle = glowGradient;
glowContext.fillRect(0, 0, 128, 128);
const glowTexture = new THREE.CanvasTexture(glowCanvas);
glowTexture.colorSpace = THREE.SRGBColorSpace;
const glowSprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: glowTexture,
transparent: true,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
glowSprite.position.copy(sunPosition);
glowSprite.scale.set(3.7, 3.7, 1);
scene.add(glowSprite);
const sunLight = new THREE.PointLight(0xffd27a, 95, 18, 2);
sunLight.position.copy(sunPosition);
scene.add(sunLight);
// ---------------------------------------------------------------------
// Energy-flow helper
// ---------------------------------------------------------------------
const flows = [];
const yAxis = new THREE.Vector3(0, 1, 0);
function createFlow({
points,
color,
radius = 0.026,
opacity = 0.88,
particles = 4,
speed = 0.15,
arrow = true
}) {
const curve =
points.length === 2
? new THREE.LineCurve3(points[0], points[1])
: new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.28);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const path = new THREE.Mesh(
new THREE.TubeGeometry(curve, 72, radius, 6, false),
material
);
path.renderOrder = 4;
scene.add(path);
let arrowMesh = null;
if (arrow) {
const arrowHeight = radius * 8.5;
arrowMesh = new THREE.Mesh(
new THREE.ConeGeometry(radius * 3.2, arrowHeight, 8),
material.clone()
);
const tangent = curve.getTangentAt(1).normalize();
const end = curve.getPointAt(1);
arrowMesh.position.copy(end).addScaledVector(tangent, -arrowHeight / 2);
arrowMesh.quaternion.setFromUnitVectors(yAxis, tangent);
arrowMesh.renderOrder = 5;
scene.add(arrowMesh);
}
const particleColor = new THREE.Color(color).lerp(
new THREE.Color(0xffffff),
0.42
);
const flowParticles = [];
for (let i = 0; i < particles; i++) {
const particle = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius * 1.7, 1),
new THREE.MeshBasicMaterial({
color: particleColor,
transparent: true,
opacity: 0.96,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
particle.userData.phase = i / particles;
particle.renderOrder = 6;
scene.add(particle);
flowParticles.push(particle);
}
const flow = {
curve,
particles: flowParticles,
speed,
arrow: arrowMesh
};
flows.push(flow);
return flow;
}
// ---------------------------------------------------------------------
// Incoming sunlight
// ---------------------------------------------------------------------
const impactTargets = [
new THREE.Vector3(-1.65, 0.55, 1.15),
new THREE.Vector3(-1.45, 1.05, 1.0),
new THREE.Vector3(-1.75, -0.05, 1.0),
new THREE.Vector3(-1.15, 0.65, 1.45),
new THREE.Vector3(-1.35, 1.42, 0.95)
].map((point) => point.normalize().multiplyScalar(2.035));
impactTargets.forEach((target, index) => {
const start = sunPosition
.clone()
.add(
new THREE.Vector3(
0.12 + index * 0.025,
(index - 2) * 0.075,
(index - 2) * 0.035
)
);
createFlow({
points: [start, target],
color: 0xffd166,
radius: 0.022,
opacity: 0.83,
particles: 3,
speed: 0.16 + index * 0.008,
arrow: true
});
});
// ---------------------------------------------------------------------
// Reflected visible light
// ---------------------------------------------------------------------
const reflectionOrigin = impactTargets[0];
const reflectionPaths = [
[
reflectionOrigin,
reflectionOrigin.clone().add(new THREE.Vector3(-0.6, 0.38, 0.12)),
new THREE.Vector3(-3.8, 2.25, 1.25),
new THREE.Vector3(-5.15, 2.85, 1.45)
],
[
reflectionOrigin.clone().add(new THREE.Vector3(0.04, 0.08, 0)),
reflectionOrigin.clone().add(new THREE.Vector3(-0.45, 0.55, 0.15)),
new THREE.Vector3(-3.45, 3.25, 1.35),
new THREE.Vector3(-4.55, 3.75, 1.25)
],
[
reflectionOrigin.clone().add(new THREE.Vector3(0, -0.05, 0.08)),
reflectionOrigin.clone().add(new THREE.Vector3(-0.55, 0.18, 0.28)),
new THREE.Vector3(-3.75, 1.75, 2.05),
new THREE.Vector3(-4.9, 2.0, 2.25)
]
];
reflectionPaths.forEach((points, index) => {
createFlow({
points,
color: 0x6bd9ff,
radius: 0.024,
opacity: 0.9,
particles: 4,
speed: 0.19 + index * 0.015,
arrow: true
});
});
// ---------------------------------------------------------------------
// Outgoing infrared and atmospheric interactions
// ---------------------------------------------------------------------
const surfaceA = new THREE.Vector3(0.25, 1.45, 1.45)
.normalize()
.multiplyScalar(2.03);
const atmosphereA = surfaceA.clone().normalize().multiplyScalar(2.25);
const surfaceB = new THREE.Vector3(0.95, 0.65, 1.45)
.normalize()
.multiplyScalar(2.03);
const atmosphereB = surfaceB.clone().normalize().multiplyScalar(2.25);
const surfaceC = new THREE.Vector3(1.12, -0.08, 1.68)
.normalize()
.multiplyScalar(2.03);
const atmosphereC = surfaceC.clone().normalize().multiplyScalar(2.25);
// Surface infrared reaching the atmosphere.
createFlow({
points: [surfaceA, atmosphereA],
color: 0xff596d,
radius: 0.03,
opacity: 0.92,
particles: 3,
speed: 0.13,
arrow: true
});
createFlow({
points: [surfaceB, atmosphereB],
color: 0xff596d,
radius: 0.028,
opacity: 0.9,
particles: 3,
speed: 0.15,
arrow: true
});
// Atmospheric re-emission into space.
createFlow({
points: [
atmosphereA,
atmosphereA.clone().add(new THREE.Vector3(0.35, 0.5, 0.02)),
new THREE.Vector3(2.35, 3.35, 0.75),
new THREE.Vector3(3.45, 4.15, 0.35)
],
color: 0xffae57,
radius: 0.026,
opacity: 0.88,
particles: 5,
speed: 0.15,
arrow: true
});
createFlow({
points: [
atmosphereB,
atmosphereB.clone().add(new THREE.Vector3(0.45, 0.15, 0.12)),
new THREE.Vector3(2.65, 1.1, 1.35),
new THREE.Vector3(4.05, 1.65, 1.55)
],
color: 0xff9e4d,
radius: 0.024,
opacity: 0.84,
particles: 4,
speed: 0.17,
arrow: true
});
// A direct infrared escape route.
createFlow({
points: [
surfaceC,
atmosphereC,
atmosphereC.clone().add(new THREE.Vector3(0.35, 0.45, 0.1)),
new THREE.Vector3(2.65, 2.85, 1.75),
new THREE.Vector3(3.25, 3.55, 1.55)
],
color: 0xff765c,
radius: 0.025,
opacity: 0.86,
particles: 5,
speed: 0.14,
arrow: true
});
// Pulsing nodes emphasize atmospheric absorption/re-emission.
const interactionNodes = [];
[atmosphereA, atmosphereB].forEach((position, index) => {
const node = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.085, 1),
new THREE.MeshBasicMaterial({
color: 0xffb35f,
transparent: true,
opacity: 0.9,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
node.position.copy(position);
node.userData.phase = index * Math.PI;
node.renderOrder = 6;
scene.add(node);
interactionNodes.push(node);
});
// ---------------------------------------------------------------------
// Screen-space labels
// ---------------------------------------------------------------------
const labelDefinitions = [
{
element: document.getElementById("labelSunlight"),
position: new THREE.Vector3(-4.35, 2.12, 0.55),
offset: [-8, -42]
},
{
element: document.getElementById("labelReflection"),
position: new THREE.Vector3(-4.45, 2.95, 1.55),
offset: [-50, -7]
},
{
element: document.getElementById("labelInfrared"),
position: surfaceA.clone(),
offset: [45, -38]
},
{
element: document.getElementById("labelReemission"),
position: atmosphereA.clone(),
offset: [65, -8]
},
{
element: document.getElementById("labelAtmosphere"),
position: new THREE.Vector3(1.45, -1.55, 1.45),
offset: [60, 25]
}
];
const projectedLabel = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of labelDefinitions) {
projectedLabel.copy(definition.position).project(camera);
const visible =
projectedLabel.z > -1 &&
projectedLabel.z < 1 &&
Math.abs(projectedLabel.x) < 1.2 &&
Math.abs(projectedLabel.y) < 1.2;
const x = (projectedLabel.x * 0.5 + 0.5) * width;
const y = (-projectedLabel.y * 0.5 + 0.5) * height;
definition.element.style.left = `${x + definition.offset[0]}px`;
definition.element.style.top = `${y + definition.offset[1]}px`;
definition.element.style.opacity = visible ? "1" : "0";
}
}
// ---------------------------------------------------------------------
// Direct camera controls
// ---------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointer = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
view.desiredTheta -= deltaX * 0.006;
view.desiredPhi = THREE.MathUtils.clamp(
view.desiredPhi + deltaY * 0.005,
0.3,
Math.PI - 0.3
);
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.desiredRadius = THREE.MathUtils.clamp(
view.desiredRadius * Math.exp(event.deltaY * 0.001),
6.4,
18
);
},
{ passive: false }
);
function resetView() {
view.desiredTheta = 0.02;
view.desiredPhi = 1.17;
view.desiredRadius = 11.5;
}
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("resetButton").addEventListener("click", resetView);
// ---------------------------------------------------------------------
// Playback controls
// ---------------------------------------------------------------------
let playing = true;
let simulationTime = 0;
const pauseButton = document.getElementById("pauseButton");
const statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "Pause flow" : "Resume flow";
statusText.textContent = playing
? "Flow live · interactive model"
: "Flow paused · camera still active";
statusDot.style.background = playing ? "#66e6ae" : "#ffb45e";
statusDot.style.boxShadow = playing
? "0 0 12px rgba(102, 230, 174, 0.8)"
: "0 0 12px rgba(255, 180, 94, 0.8)";
});
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) simulationTime += delta;
// Smooth orbit and zoom.
view.theta += (view.desiredTheta - view.theta) * 0.1;
view.phi += (view.desiredPhi - view.phi) * 0.1;
view.radius += (view.desiredRadius - view.radius) * 0.1;
updateCamera();
atmosphereMaterial.uniforms.uTime.value = simulationTime;
clouds.rotation.y = simulationTime * 0.004;
stars.rotation.y = simulationTime * -0.0007;
for (const flow of flows) {
for (const particle of flow.particles) {
const t =
(simulationTime * flow.speed + particle.userData.phase) % 1;
particle.position.copy(flow.curve.getPointAt(t));
const pulse = 1 + Math.sin(simulationTime * 7 + particle.userData.phase * 10) * 0.12;
particle.scale.setScalar(pulse);
}
}
for (const node of interactionNodes) {
const pulse = 1 + Math.sin(simulationTime * 3 + node.userData.phase) * 0.28;
node.scale.setScalar(pulse);
node.material.opacity = 0.7 + Math.sin(simulationTime * 3 + node.userData.phase) * 0.18;
}
const sunPulse = 1 + Math.sin(simulationTime * 1.7) * 0.045;
sun.scale.setScalar(sunPulse);
sunHalo.scale.setScalar(1 + Math.sin(simulationTime * 1.3) * 0.08);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```