Prompt specification
Build or customize the Three.js 3D scene "Surface reflectivity teaching controls" 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: Surface reflectivity teaching controls
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/surface-reflectivity-teaching-controls-x1204
Scene Description Prompt:
Adjust albedo on a low-poly ground tile; conserve reflected plus absorbed incident energy in a stated toy model. Standalone HTML using Three.js from cdnjs.
Acceptance checks: Implement reflected energy = incident × albedo and absorbed energy = incident − reflected. For 100 W at albedo 0.80, the scene must show 80 W reflected and 20 W absorbed; test both endpoints and keep the visual brightness consistent with the numerical direction.
Return a single complete HTML document. It must work in a sandbox that allows scripts, with the cdnjs Three.js r160 module and inline CSS. Use procedural geometry and local button handlers; no native form submission, pointer lock, remote assets, or runtime network requests besides Three.js.
Working Three.js Starter (surface-reflectivity-teaching-controls-x1204):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<link rel="icon" href="data:,">
<title>Low-Poly Albedo Energy Lab</title>
<style>
:root {
--bg: #07121d;
--panel: rgba(10, 24, 38, 0.88);
--line: rgba(158, 207, 229, 0.18);
--text: #eef8ff;
--muted: #91aabb;
--reflected: #59efd2;
--absorbed: #ff9b57;
--incident: #ffe38a;
}
* {
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;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active,
canvas.grabbing {
cursor: grabbing;
}
canvas:focus-visible {
outline: 2px solid var(--reflected);
outline-offset: -4px;
}
.hero {
position: fixed;
z-index: 5;
top: 26px;
left: 28px;
max-width: min(430px, calc(100vw - 440px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
margin-bottom: 8px;
color: var(--reflected);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.hero h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.hero p {
max-width: 390px;
margin: 13px 0 0;
color: #b6cad8;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 10;
top: 24px;
right: 24px;
width: min(380px, calc(100vw - 48px));
max-height: calc(100dvh - 48px);
overflow: auto;
padding: 20px;
border: 1px solid var(--line);
border-radius: 22px;
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent 42%),
var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
backdrop-filter: blur(18px);
}
.panel-kicker {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel-kicker::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--reflected);
box-shadow: 0 0 14px var(--reflected);
content: "";
}
.equations {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.equation {
min-width: 0;
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 13px;
background: rgba(255, 255, 255, 0.035);
}
.equation span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.equation code {
color: #dff9ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 13px;
white-space: nowrap;
}
.balance {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 10px 0 15px;
padding: 9px 11px;
border-radius: 11px;
background: rgba(89, 239, 210, 0.075);
color: var(--muted);
font-size: 11px;
}
.balance strong {
color: var(--reflected);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
white-space: nowrap;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.energy-card {
position: relative;
overflow: hidden;
padding: 14px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 15px;
background: rgba(255, 255, 255, 0.04);
}
.energy-card::after {
position: absolute;
right: -15px;
bottom: -24px;
width: 72px;
height: 72px;
border-radius: 50%;
background: currentColor;
opacity: 0.08;
filter: blur(2px);
content: "";
}
.energy-card.reflected {
color: var(--reflected);
}
.energy-card.absorbed {
color: var(--absorbed);
}
.energy-card span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.energy-card strong {
color: currentColor;
font-size: 30px;
line-height: 1;
letter-spacing: -0.04em;
}
.energy-card small {
color: var(--muted);
font-size: 10px;
}
.split-bar {
display: flex;
height: 8px;
overflow: hidden;
margin: 13px 0 20px;
border-radius: 99px;
background: #152535;
}
.split-bar > div {
width: 50%;
transition: width 120ms ease-out;
}
#reflectedBar {
background: var(--reflected);
box-shadow: 0 0 12px rgba(89, 239, 210, 0.55);
}
#absorbedBar {
background: var(--absorbed);
box-shadow: 0 0 12px rgba(255, 155, 87, 0.45);
}
.slider-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 10px;
}
.slider-heading label {
color: #d9e9f3;
font-size: 13px;
font-weight: 750;
}
#albedoValue {
color: var(--reflected);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 16px;
font-weight: 800;
}
#albedo {
--fill: 80%;
width: 100%;
height: 7px;
margin: 8px 0 9px;
border-radius: 99px;
outline: none;
background: linear-gradient(
to right,
var(--reflected) 0%,
var(--reflected) var(--fill),
#23394b var(--fill),
#23394b 100%
);
appearance: none;
cursor: pointer;
}
#albedo::-webkit-slider-thumb {
width: 19px;
height: 19px;
border: 3px solid #09202c;
border-radius: 50%;
background: var(--reflected);
box-shadow: 0 0 0 1px var(--reflected), 0 0 15px rgba(89, 239, 210, 0.55);
appearance: none;
}
#albedo::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid #09202c;
border-radius: 50%;
background: var(--reflected);
box-shadow: 0 0 0 1px var(--reflected), 0 0 15px rgba(89, 239, 210, 0.55);
}
.range-notes {
display: flex;
justify-content: space-between;
color: #71899b;
font-size: 10px;
}
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 15px;
}
.preset {
min-height: 48px;
padding: 8px 5px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
color: #b8cad6;
font: inherit;
font-size: 10px;
line-height: 1.3;
cursor: pointer;
transition: border-color 140ms, background 140ms, color 140ms, transform 140ms;
}
.preset:hover,
.preset:focus-visible {
border-color: rgba(89, 239, 210, 0.55);
background: rgba(89, 239, 210, 0.08);
color: #eafffb;
transform: translateY(-1px);
}
.preset.active {
border-color: rgba(89, 239, 210, 0.7);
background: rgba(89, 239, 210, 0.12);
color: var(--reflected);
}
#modelStatus {
min-height: 38px;
margin: 13px 0 0;
color: #d7e8f2;
font-size: 12px;
line-height: 1.5;
}
.brightness-note {
margin: 10px 0 0;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: #8299aa;
font-size: 10px;
line-height: 1.55;
}
.brightness-note b {
color: #c6d9e5;
font-weight: 700;
}
.world-label {
position: fixed;
z-index: 4;
top: 0;
left: 0;
min-width: 116px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 10px;
background: rgba(5, 15, 25, 0.78);
box-shadow: 0 8px 26px rgba(0, 0, 0, 0.3);
pointer-events: none;
white-space: nowrap;
backdrop-filter: blur(10px);
will-change: transform;
}
.world-label small {
display: block;
margin-bottom: 1px;
color: #8ea6b7;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.world-label strong {
font-size: 13px;
}
.world-label.reflected {
border-color: rgba(89, 239, 210, 0.38);
color: var(--reflected);
}
.world-label.absorbed {
border-color: rgba(255, 155, 87, 0.42);
color: var(--absorbed);
}
.world-label.incident {
border-color: rgba(255, 227, 138, 0.35);
color: var(--incident);
}
.world-label.tile {
color: #dbeaf4;
}
.controls-hint {
position: fixed;
z-index: 4;
bottom: 22px;
left: 28px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 99px;
background: rgba(5, 15, 25, 0.55);
color: #8199aa;
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 760px) {
.hero {
top: 14px;
left: 16px;
max-width: calc(100vw - 32px);
}
.hero h1 {
font-size: 29px;
}
.hero p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 57dvh;
padding: 16px;
border-radius: 18px;
}
.controls-hint {
display: none;
}
.world-label {
transform: scale(0.88);
}
.world-label.incident,
.world-label.tile {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="hero">
<div class="eyebrow">Surface energy study / 01</div>
<h1>Low-poly<br>albedo lab</h1>
<p>
Tune the ground tile's albedo. The cyan reflection beam brightens as
reflected energy rises, while the orange absorption glow strengthens
as absorbed energy rises.
</p>
</header>
<section class="panel" aria-label="Albedo energy controls and readings">
<div class="panel-kicker">Conserved toy model</div>
<div class="equations">
<div class="equation">
<span>Reflected</span>
<code>E<sub>r</sub> = E<sub>i</sub> × a</code>
</div>
<div class="equation">
<span>Absorbed</span>
<code>E<sub>a</sub> = E<sub>i</sub> − E<sub>r</sub></code>
</div>
</div>
<div class="balance">
<span>Energy balance</span>
<strong id="balanceText">80 W + 20 W = 100 W</strong>
</div>
<div class="readouts" aria-live="polite">
<article class="energy-card reflected">
<span>Reflected energy</span>
<strong id="reflectedValue">80 W</strong>
<small>cyan beam / brighter tile</small>
</article>
<article class="energy-card absorbed">
<span>Absorbed energy</span>
<strong id="absorbedValue">20 W</strong>
<small>orange heat glow</small>
</article>
</div>
<div class="split-bar" aria-hidden="true">
<div id="reflectedBar"></div>
<div id="absorbedBar"></div>
</div>
<div class="slider-heading">
<label for="albedo">Ground tile albedo</label>
<output id="albedoValue" for="albedo">0.80</output>
</div>
<input
id="albedo"
type="range"
min="0"
max="1"
step="0.01"
value="0.8"
aria-label="Ground tile albedo"
>
<div class="range-notes">
<span>0.00 · absorb all</span>
<span>1.00 · reflect all</span>
</div>
<div class="presets" aria-label="Albedo test points">
<button
class="preset"
type="button"
data-albedo="0"
aria-label="Test low albedo endpoint, zero"
>Endpoint A<br><strong>0.00</strong><br>absorb all</button>
<button
class="preset active"
type="button"
data-albedo="0.8"
aria-label="Test reference albedo, 0.80"
>Reference<br><strong>0.80</strong><br>80 / 20 W</button>
<button
class="preset"
type="button"
data-albedo="1"
aria-label="Test high albedo endpoint, one"
>Endpoint B<br><strong>1.00</strong><br>reflect all</button>
</div>
<p id="modelStatus" aria-live="polite">
Reference point: 80 W reflected + 20 W absorbed = 100 W.
</p>
<p class="brightness-note">
<b>Directional cue:</b> the tile and cyan beam brighten as albedo and
reflected energy increase. The orange glow and downward absorption arrow
brighten as absorbed energy increases. This is a schematic conservation
model, without thermal re-emission or directional BRDF effects.
</p>
</section>
<div id="reflectedLabel" class="world-label reflected">
<small>Reflected</small>
<strong data-energy>80 W</strong>
</div>
<div id="absorbedLabel" class="world-label absorbed">
<small>Absorbed</small>
<strong data-energy>20 W</strong>
</div>
<div id="incidentLabel" class="world-label incident">
<small>Incident</small>
<strong>100 W</strong>
</div>
<div id="tileLabel" class="world-label tile">
<small>Ground tile</small>
<strong id="tileLabelValue">a = 0.80</strong>
</div>
<div class="controls-hint">Drag to orbit · Scroll to zoom · Arrow keys rotate</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const INCIDENT_ENERGY = 100;
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07121d);
scene.fog = new THREE.Fog(0x07121d, 14, 33);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D low-poly ground tile. Drag to orbit and scroll to zoom."
);
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const controls = {
theta: 0.72,
phi: 0.96,
radius: 12.8,
target: new THREE.Vector3(0, 0.35, 0)
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.radius * sinPhi * Math.sin(controls.theta),
controls.radius * Math.cos(controls.phi),
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemiLight = new THREE.HemisphereLight(0xc8ecff, 0x14202c, 1.45);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xfff1d6, 2.65);
keyLight.position.set(-3.5, 8, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x73dfff, 1.05);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x08131e,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.66;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x1c4657, 0x102a37);
grid.position.y = -0.645;
grid.material.transparent = true;
grid.material.opacity = 0.55;
scene.add(grid);
function terrainHeight(x, z) {
return (
0.16 +
0.12 * Math.sin(x * 1.17 + 0.35) * Math.cos(z * 1.31 - 0.2) +
0.04 * Math.sin((x - z) * 2.15)
);
}
function createFacetedTileGeometry() {
const divisions = 5;
const size = 7.5;
const step = size / divisions;
const positions = [];
const colors = [];
const point = (ix, iz) => {
const x = -size / 2 + ix * step;
const z = -size / 2 + iz * step;
return new THREE.Vector3(x, terrainHeight(x, z), z);
};
const pushTriangle = (a, b, c, shade) => {
positions.push(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
for (let i = 0; i < 3; i++) {
colors.push(shade, shade, shade);
}
};
for (let iz = 0; iz < divisions; iz++) {
for (let ix = 0; ix < divisions; ix++) {
const p00 = point(ix, iz);
const p10 = point(ix + 1, iz);
const p01 = point(ix, iz + 1);
const p11 = point(ix + 1, iz + 1);
const shadeA = 0.84 + 0.08 * Math.sin((ix + 1) * 2.1 + iz * 1.7);
const shadeB = 0.88 + 0.07 * Math.cos(ix * 1.3 - (iz + 2) * 1.9);
pushTriangle(p00, p01, p10, shadeA);
pushTriangle(p10, p01, p11, shadeB);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const tileGeometry = createFacetedTileGeometry();
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
flatShading: true,
roughness: 0.83,
metalness: 0.035
});
const tile = new THREE.Mesh(tileGeometry, tileMaterial);
tile.castShadow = true;
tile.receiveShadow = true;
scene.add(tile);
const tileEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(tileGeometry, 14),
new THREE.LineBasicMaterial({
color: 0xb6e5ef,
transparent: true,
opacity: 0.11
})
);
tile.add(tileEdges);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x182d3b,
roughness: 0.76,
metalness: 0.08
});
const tileBase = new THREE.Mesh(
new THREE.BoxGeometry(8.15, 0.58, 8.15),
baseMaterial
);
tileBase.position.y = -0.34;
tileBase.castShadow = true;
tileBase.receiveShadow = true;
scene.add(tileBase);
const lowerBand = new THREE.Mesh(
new THREE.BoxGeometry(8.28, 0.08, 8.28),
new THREE.MeshStandardMaterial({
color: 0x2c5663,
emissive: 0x12343d,
emissiveIntensity: 0.32,
roughness: 0.58,
metalness: 0.22
})
);
lowerBand.position.y = -0.57;
scene.add(lowerBand);
const hitPoint = new THREE.Vector3(
0,
terrainHeight(0, 0) + 0.055,
0
);
function createEnergyArrow(color, radius, length) {
const group = new THREE.Group();
const headLength = Math.min(0.38, length * 0.36);
const shaftLength = length - headLength;
const coreMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const haloMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.16,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 8, 1, true),
coreMaterial
);
shaft.scale.y = shaftLength;
shaft.position.y = shaftLength / 2;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(radius * 2.45, headLength, 8),
coreMaterial
);
head.position.y = shaftLength + headLength / 2;
group.add(head);
const halo = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 2.15, radius * 2.15, 1, 8, 1, true),
haloMaterial
);
halo.scale.y = shaftLength;
halo.position.y = shaftLength / 2;
group.add(halo);
return {
group,
shaft,
head,
halo,
coreMaterial,
haloMaterial
};
}
const incidentStart = new THREE.Vector3(-4.4, 5.6, 2.6);
const reflectedEnd = new THREE.Vector3(4.0, 3.8, 3.3);
const incidentArrow = createEnergyArrow(0xffe38a, 0.055, hitPoint.distanceTo(incidentStart));
incidentArrow.group.position.copy(incidentStart);
incidentArrow.group.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
hitPoint.clone().sub(incidentStart).normalize()
);
scene.add(incidentArrow.group);
const reflectedArrow = createEnergyArrow(
0x59efd2,
0.075,
hitPoint.distanceTo(reflectedEnd)
);
reflectedArrow.group.position.copy(hitPoint);
reflectedArrow.group.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
reflectedEnd.clone().sub(hitPoint).normalize()
);
scene.add(reflectedArrow.group);
const absorptionArrow = createEnergyArrow(0xff9851, 0.055, 1.05);
absorptionArrow.group.position.copy(hitPoint).add(new THREE.Vector3(0, 1.05, 0));
absorptionArrow.group.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, -1, 0)
);
scene.add(absorptionArrow.group);
const heatRingMaterial = new THREE.MeshBasicMaterial({
color: 0xff9851,
transparent: true,
opacity: 0.8,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const heatRing = new THREE.Mesh(
new THREE.TorusGeometry(0.58, 0.045, 8, 32),
heatRingMaterial
);
heatRing.rotation.x = Math.PI / 2;
heatRing.position.copy(hitPoint);
heatRing.position.y += 0.025;
scene.add(heatRing);
const outerHeatMaterial = new THREE.MeshBasicMaterial({
color: 0xff7040,
transparent: true,
opacity: 0.28,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const outerHeatRing = new THREE.Mesh(
new THREE.TorusGeometry(0.92, 0.022, 8, 40),
outerHeatMaterial
);
outerHeatRing.rotation.x = Math.PI / 2;
outerHeatRing.position.copy(hitPoint);
outerHeatRing.position.y += 0.018;
scene.add(outerHeatRing);
const heatPatchMaterial = new THREE.MeshBasicMaterial({
color: 0xff8b48,
transparent: true,
opacity: 0.08,
depthWrite: false,
side: THREE.DoubleSide
});
const heatPatch = new THREE.Mesh(
new THREE.CircleGeometry(0.42, 24),
heatPatchMaterial
);
heatPatch.rotation.x = -Math.PI / 2;
heatPatch.position.copy(hitPoint);
heatPatch.position.y += 0.012;
scene.add(heatPatch);
const slider = document.getElementById("albedo");
const albedoValue = document.getElementById("albedoValue");
const reflectedValue = document.getElementById("reflectedValue");
const absorbedValue = document.getElementById("absorbedValue");
const balanceText = document.getElementById("balanceText");
const reflectedBar = document.getElementById("reflectedBar");
const absorbedBar = document.getElementById("absorbedBar");
const modelStatus = document.getElementById("modelStatus");
const reflectedLabel = document.getElementById("reflectedLabel");
const absorbedLabel = document.getElementById("absorbedLabel");
const incidentLabel = document.getElementById("incidentLabel");
const tileLabel = document.getElementById("tileLabel");
const tileLabelValue = document.getElementById("tileLabelValue");
const presetButtons = [...document.querySelectorAll("[data-albedo]")];
function formatEnergy(value) {
const rounded = Math.round(value);
return Number.isInteger(rounded) ? `${rounded} W` : `${rounded.toFixed(1)} W`;
}
function setAlbedo(value) {
const albedo = THREE.MathUtils.clamp(Number(value), 0, 1);
const reflected = INCIDENT_ENERGY * albedo;
const absorbed = INCIDENT_ENERGY - reflected;
const reflectedFraction = reflected / INCIDENT_ENERGY;
const absorbedFraction = absorbed / INCIDENT_ENERGY;
slider.value = albedo.toFixed(2);
slider.style.setProperty("--fill", `${albedo * 100}%`);
albedoValue.textContent = albedo.toFixed(2);
reflectedValue.textContent = formatEnergy(reflected);
absorbedValue.textContent = formatEnergy(absorbed);
balanceText.textContent =
`${formatEnergy(reflected)} + ${formatEnergy(absorbed)} = ${INCIDENT_ENERGY} W`;
reflectedBar.style.width = `${reflectedFraction * 100}%`;
absorbedBar.style.width = `${absorbedFraction * 100}%`;
reflectedLabel.querySelector("[data-energy]").textContent = formatEnergy(reflected);
absorbedLabel.querySelector("[data-energy]").textContent = formatEnergy(absorbed);
tileLabelValue.textContent = `a = ${albedo.toFixed(2)}`;
reflectedLabel.style.opacity = reflectedFraction > 0 ? "1" : "0.48";
absorbedLabel.style.opacity = absorbedFraction > 0 ? "1" : "0.48";
// Tile brightness follows albedo and therefore reflected energy.
tileMaterial.color.setHSL(
0.105,
0.36,
0.105 + 0.49 * albedo
);
tileMaterial.roughness = 0.94 - albedo * 0.16;
baseMaterial.color.setHSL(0.57, 0.18, 0.07 + albedo * 0.055);
// Cyan beam brightness and width follow reflected energy.
reflectedArrow.group.visible = reflectedFraction > 0;
reflectedArrow.group.scale.set(
Math.sqrt(reflectedFraction),
1,
Math.sqrt(reflectedFraction)
);
reflectedArrow.coreMaterial.opacity = 0.2 + reflectedFraction * 0.75;
reflectedArrow.haloMaterial.opacity = reflectedFraction * 0.2;
reflectedArrow.coreMaterial.color.setRGB(
0.16 + reflectedFraction * 0.84,
1,
0.7 + reflectedFraction * 0.3
);
// Orange heat cues follow absorbed energy and move in the opposite direction.
absorptionArrow.group.visible = absorbedFraction > 0;
absorptionArrow.group.scale.set(
Math.sqrt(absorbedFraction),
1,
Math.sqrt(absorbedFraction)
);
absorptionArrow.coreMaterial.opacity = 0.16 + absorbedFraction * 0.82;
absorptionArrow.haloMaterial.opacity = absorbedFraction * 0.24;
heatRingMaterial.opacity = absorbedFraction * 0.88;
outerHeatMaterial.opacity = absorbedFraction * 0.34;
heatPatchMaterial.opacity = absorbedFraction * 0.11;
for (const button of presetButtons) {
const active = Math.abs(Number(button.dataset.albedo) - albedo) < 0.005;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
if (albedo === 0) {
modelStatus.textContent =
"Endpoint A verified: 0 W reflected + 100 W absorbed = 100 W. The cyan beam is absent and the orange absorption glow is strongest.";
} else if (albedo === 1) {
modelStatus.textContent =
"Endpoint B verified: 100 W reflected + 0 W absorbed = 100 W. The cyan beam and tile are brightest and the orange absorption glow is absent.";
} else if (Math.abs(albedo - 0.8) < 0.005) {
modelStatus.textContent =
"Reference point: 80 W reflected + 20 W absorbed = 100 W.";
} else {
modelStatus.textContent =
`Balanced: ${formatEnergy(reflected)} reflected + ${formatEnergy(absorbed)} absorbed = ${INCIDENT_ENERGY} W.`;
}
}
slider.addEventListener("input", (event) => {
setAlbedo(event.target.value);
});
for (const button of presetButtons) {
button.addEventListener("click", () => {
setAlbedo(button.dataset.albedo);
});
}
setAlbedo(0.8);
let activePointer = null;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointer = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("grabbing");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (event.pointerId !== activePointer) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
controls.theta -= dx * 0.008;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.006,
0.48,
1.38
);
updateCamera();
});
function releasePointer(event) {
if (event.pointerId !== activePointer) return;
activePointer = null;
renderer.domElement.classList.remove("grabbing");
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
8,
18
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.theta += 0.09;
break;
case "ArrowRight":
controls.theta -= 0.09;
break;
case "ArrowUp":
controls.phi = Math.max(0.48, controls.phi - 0.06);
break;
case "ArrowDown":
controls.phi = Math.min(1.38, controls.phi + 0.06);
break;
case "+":
case "=":
controls.radius = Math.max(8, controls.radius - 0.6);
break;
case "-":
controls.radius = Math.min(18, controls.radius + 0.6);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.visibility = visible ? "visible" : "hidden";
element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const reflectedLabelAnchor = new THREE.Vector3();
const absorbedLabelAnchor = hitPoint.clone().add(
new THREE.Vector3(-1.25, 0.28, 0.75)
);
const incidentLabelAnchor = incidentStart.clone().add(
new THREE.Vector3(-0.35, 0.25, 0)
);
const tileLabelAnchor = new THREE.Vector3(0, 0.18, 2.75);
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const currentAlbedo = Number(slider.value);
const reflectedFraction = currentAlbedo;
const pulse = 1 + Math.sin(elapsed * 2.5) * 0.065;
outerHeatRing.scale.setScalar(pulse);
heatRing.rotation.z = elapsed * 0.18;
reflectedLabelAnchor.copy(hitPoint).lerp(
reflectedEnd,
0.25 + reflectedFraction * 0.75
);
positionLabel(reflectedLabel, reflectedLabelAnchor);
positionLabel(absorbedLabel, absorbedLabelAnchor);
positionLabel(incidentLabel, incidentLabelAnchor);
positionLabel(tileLabel, tileLabelAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```