Prompt specification
Build or customize the Three.js 3D scene "Detector patches at different radii" 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: Detector patches at different radii
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/detector-patches-at-different-radii-x1554
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: detector patches at different radii. Place equal-area detector squares on two spherical shells and display received power density; show the inverse-square relationship only where the point-source approximation applies. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (detector-patches-at-different-radii-x1554):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Spherical Flux Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #050914;
--panel: rgba(9, 17, 34, 0.76);
--line: rgba(154, 202, 255, 0.16);
--text: #eef7ff;
--muted: #91a7be;
--cyan: #43e8ff;
--violet: #856bff;
--pink: #e55ddd;
--green: #73f2ba;
--amber: #ffbe73;
}
* { 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;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
background:
radial-gradient(circle at 50% 42%, transparent 0 34%, rgba(2, 5, 15, .32) 78%),
linear-gradient(rgba(255,255,255,.012) 1px, transparent 1px);
background-size: auto, 100% 4px;
mix-blend-mode: screen;
opacity: .55;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.topbar {
position: fixed;
top: 24px;
left: 28px;
z-index: 5;
max-width: 540px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: .22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 1px;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
font-weight: 560;
letter-spacing: -.045em;
line-height: 1.02;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
letter-spacing: .02em;
}
.subtitle strong { color: #cfe8f8; font-weight: 600; }
.controls {
position: fixed;
top: 24px;
right: 24px;
z-index: 6;
width: 278px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(24, 39, 65, .58), rgba(7, 13, 28, .83));
box-shadow: 0 20px 60px rgba(0,0,0,.32), inset 0 1px rgba(255,255,255,.04);
backdrop-filter: blur(18px);
}
.control-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
margin-top: 9px;
padding: 4px;
border: 1px solid rgba(255,255,255,.06);
border-radius: 11px;
background: rgba(1, 6, 18, .48);
}
.segmented button {
border: 0;
border-radius: 8px;
padding: 9px 8px;
color: #8096ad;
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: .2s ease;
}
.segmented button:hover { color: white; }
.segmented button.active {
color: #05101c;
background: linear-gradient(135deg, #71efff, #8aa5ff);
box-shadow: 0 5px 20px rgba(71, 210, 255, .16);
}
.power-row {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-top: 18px;
}
.power-value {
color: white;
font-size: 14px;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 13px 0 2px;
appearance: none;
border-radius: 4px;
outline: none;
background: linear-gradient(90deg, var(--cyan), var(--violet));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #07101f;
border-radius: 50%;
background: #d8fbff;
box-shadow: 0 0 0 1px rgba(110,230,255,.55), 0 0 16px rgba(68,220,255,.55);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #07101f;
border-radius: 50%;
background: #d8fbff;
box-shadow: 0 0 0 1px rgba(110,230,255,.55), 0 0 16px rgba(68,220,255,.55);
}
.control-foot {
display: flex;
justify-content: space-between;
margin-top: 11px;
color: #6f879e;
font-size: 9px;
letter-spacing: .08em;
text-transform: uppercase;
}
.model-panel {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
width: 360px;
padding: 17px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(0,0,0,.34), inset 0 1px rgba(255,255,255,.035);
backdrop-filter: blur(18px);
}
.model-title {
display: flex;
justify-content: space-between;
align-items: center;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.model-status {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--green);
font-size: 9px;
}
.model-status::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.equation {
margin: 13px 0 7px;
color: #f5fbff;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
letter-spacing: -.02em;
}
.equation .scope {
display: block;
margin-bottom: 4px;
color: var(--cyan);
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
font-size: 8px;
font-weight: 800;
letter-spacing: .17em;
text-transform: uppercase;
}
.model-copy {
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.ratio-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
padding: 10px 11px;
border: 1px solid rgba(93, 205, 255, .13);
border-radius: 10px;
background: rgba(44, 145, 190, .07);
color: #a9c4d8;
font-size: 10px;
}
.ratio-row strong {
color: var(--cyan);
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.validity-list {
display: grid;
gap: 7px;
margin-top: 12px;
}
.validity-item {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
align-items: center;
padding: 9px 10px;
border-radius: 10px;
background: rgba(255,255,255,.035);
}
.validity-item small {
display: block;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.validity-item strong {
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.badge {
display: inline-block;
margin-top: 3px;
padding: 3px 6px;
border-radius: 999px;
font-size: 8px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
}
.badge.no {
color: #ffbf8a;
background: rgba(255, 164, 86, .11);
}
.badge.yes {
color: #78f1c0;
background: rgba(84, 231, 174, .11);
}
.legend {
position: fixed;
left: 28px;
bottom: 27px;
z-index: 5;
width: 225px;
pointer-events: none;
}
.legend-title {
display: flex;
justify-content: space-between;
margin-bottom: 9px;
color: #9bb1c7;
font-size: 9px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
.legend-gradient {
height: 7px;
border-radius: 99px;
background: linear-gradient(90deg, #655cff, #db5bdc 50%, #39e7ff);
box-shadow: 0 0 25px rgba(91, 166, 255, .17);
}
.legend-scale {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #6f879e;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.scene-tag {
position: fixed;
z-index: 4;
min-width: 145px;
padding: 10px 12px;
border: 1px solid rgba(128, 217, 255, .24);
border-radius: 11px;
background: rgba(6, 14, 29, .82);
box-shadow: 0 12px 35px rgba(0,0,0,.28), inset 0 1px rgba(255,255,255,.04);
backdrop-filter: blur(12px);
pointer-events: none;
transform: translate(-50%, -50%);
}
.scene-tag::before {
content: "";
position: absolute;
top: 50%;
width: 17px;
height: 1px;
background: rgba(114, 220, 255, .55);
}
.scene-tag.inner { margin-left: -126px; }
.scene-tag.inner::before { left: 100%; }
.scene-tag.outer { margin-left: 126px; }
.scene-tag.outer::before { right: 100%; }
.tag-kicker {
display: block;
color: #83a9c2;
font-size: 8px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
}
.tag-value {
display: inline-block;
margin-top: 4px;
color: #f5fbff;
font-size: 18px;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.tag-unit {
margin-left: 4px;
color: #8da7be;
font-size: 9px;
}
.tag-meta {
display: block;
margin-top: 3px;
color: #8fa8be;
font-size: 8px;
line-height: 1.4;
}
.tag-relation {
display: inline-block;
margin-top: 6px;
color: var(--green);
font-size: 8px;
font-weight: 750;
}
.tag-relation.no { color: var(--amber); }
.source-tag {
position: fixed;
z-index: 4;
padding: 5px 8px;
border: 1px solid rgba(80, 222, 255, .24);
border-radius: 999px;
color: #aeefff;
background: rgba(5, 13, 27, .78);
font-size: 8px;
font-weight: 750;
letter-spacing: .09em;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, 18px);
}
.tooltip {
position: fixed;
z-index: 10;
display: none;
min-width: 195px;
padding: 11px 12px;
border: 1px solid rgba(138, 211, 255, .23);
border-radius: 10px;
color: #dceeff;
background: rgba(5, 12, 26, .92);
box-shadow: 0 14px 40px rgba(0,0,0,.38);
backdrop-filter: blur(14px);
pointer-events: none;
font-size: 10px;
line-height: 1.55;
}
.tooltip strong {
display: block;
margin-bottom: 3px;
color: white;
font-size: 12px;
}
.tooltip .density {
color: var(--cyan);
font-size: 15px;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.tooltip .warning { color: var(--amber); }
.tooltip .valid { color: var(--green); }
.hint {
position: fixed;
left: 50%;
bottom: 19px;
z-index: 5;
color: rgba(146, 168, 192, .62);
font-size: 9px;
letter-spacing: .11em;
text-transform: uppercase;
transform: translateX(-50%);
pointer-events: none;
}
@media (max-width: 900px) {
.topbar { max-width: 52vw; }
.subtitle { display: none; }
.controls { width: 230px; }
.model-panel { width: 310px; }
.legend { width: 175px; }
.scene-tag { min-width: 125px; }
}
@media (max-width: 650px) {
.topbar { top: 17px; left: 17px; max-width: calc(100vw - 34px); }
h1 { font-size: 26px; }
.controls { top: auto; right: 14px; bottom: 14px; width: 190px; padding: 11px; }
.control-foot { display: none; }
.model-panel { left: 14px; right: auto; bottom: 14px; width: calc(100vw - 224px); padding: 12px; }
.equation { font-size: 19px; }
.model-copy, .validity-item small { font-size: 8px; }
.legend { display: none; }
.hint { display: none; }
.scene-tag { transform: translate(-50%, -50%) scale(.85); }
.scene-tag.inner { margin-left: -74px; }
.scene-tag.outer { margin-left: 74px; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="topbar">
<div class="eyebrow">Radiative transfer / spherical sampling</div>
<h1>Spherical Flux Lab</h1>
<div class="subtitle">
Equal-area detector squares on two shells.
<strong>Every patch is 2.4 m × 2.4 m = 5.76 m².</strong>
Color encodes received power density.
</div>
</header>
<aside class="controls">
<div class="control-label">Source model</div>
<div class="segmented" role="group" aria-label="Source model">
<button id="pointMode" type="button">Point emitter</button>
<button id="finiteMode" type="button" class="active">Finite emitter</button>
</div>
<div class="power-row">
<div class="control-label">Total emitted power</div>
<div class="power-value" id="powerValue">1000 W</div>
</div>
<input id="powerSlider" type="range" min="100" max="2000" step="50" value="1000">
<div class="control-foot">
<span>Inner shell · 8 m</span>
<span>Outer shell · 17 m</span>
</div>
</aside>
<section class="model-panel" id="modelPanel"></section>
<aside class="legend">
<div class="legend-title">
<span>Received power density</span>
<span>W/m²</span>
</div>
<div class="legend-gradient"></div>
<div class="legend-scale">
<span id="legendMin">0.00</span>
<span id="legendMax">0.00</span>
</div>
</aside>
<div class="scene-tag inner" id="innerTag">
<span class="tag-kicker">Inner shell · 8 m</span>
<span class="tag-value" id="innerFlux">—</span><span class="tag-unit">W/m²</span>
<span class="tag-meta" id="innerMeta"></span>
<span class="tag-relation" id="innerRelation"></span>
</div>
<div class="scene-tag outer" id="outerTag">
<span class="tag-kicker">Outer shell · 17 m</span>
<span class="tag-value" id="outerFlux">—</span><span class="tag-unit">W/m²</span>
<span class="tag-meta" id="outerMeta"></span>
<span class="tag-relation" id="outerRelation"></span>
</div>
<div class="source-tag" id="sourceTag">Finite emitter · Ø 4 m</div>
<div class="tooltip" id="tooltip"></div>
<div class="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const tooltip = document.getElementById("tooltip");
const modelPanel = document.getElementById("modelPanel");
const state = {
mode: "finite",
power: 1000,
innerRadius: 8,
outerRadius: 17,
sourceRadius: 2,
detectorSide: 2.4,
detectorArea: 2.4 * 2.4,
approximationGate: 8
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050914);
scene.fog = new THREE.FogExp2(0x050914, 0.0075);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D scene of detector patches on spherical shells"
);
viewport.appendChild(renderer.domElement);
const controls = {
theta: 0.73,
phi: 1.07,
distance: 45,
target: new THREE.Vector3(0, 0, 0),
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.distance * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.distance * Math.cos(controls.phi),
controls.target.z + controls.distance * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0x8ecbff, 0x101328, 1.55));
scene.add(new THREE.AmbientLight(0x7289ba, 0.55));
const keyLight = new THREE.DirectionalLight(0xcfe9ff, 2.3);
keyLight.position.set(12, 18, 20);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7a5cff, 1.7);
rimLight.position.set(-18, 8, -15);
scene.add(rimLight);
const sourceLight = new THREE.PointLight(0x57e6ff, 65, 48, 1.7);
scene.add(sourceLight);
const highlightDirection = new THREE.Vector3(0.64, 0.45, 0.62).normalize();
const detectorDirections = [
highlightDirection.clone(),
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(0.7, 0.7, 0).normalize(),
new THREE.Vector3(-0.7, 0.7, 0).normalize(),
new THREE.Vector3(0.7, -0.7, 0).normalize(),
new THREE.Vector3(-0.7, -0.7, 0).normalize(),
new THREE.Vector3(0.4, 0.2, 0.9).normalize(),
new THREE.Vector3(-0.2, 0.8, -0.55).normalize()
];
// Deterministic uniform sampling of a finite disk. Each sampled element
// radiates isotropically, so the disk becomes point-like at large distance.
const sourceElements = [];
{
const count = 2048;
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
const u = new THREE.Vector3()
.crossVectors(highlightDirection, new THREE.Vector3(0, 1, 0))
.normalize();
const v = new THREE.Vector3()
.crossVectors(highlightDirection, u)
.normalize();
for (let i = 0; i < count; i++) {
const radius = state.sourceRadius * Math.sqrt((i + 0.5) / count);
const angle = i * goldenAngle;
const point = u.clone().multiplyScalar(radius * Math.cos(angle))
.add(v.clone().multiplyScalar(radius * Math.sin(angle)));
sourceElements.push(point);
}
}
function pointFlux(radius) {
return state.power / (4 * Math.PI * radius * radius);
}
function finiteFlux(direction, radius) {
const detectorPosition = direction.clone().multiplyScalar(radius);
let sum = 0;
for (const element of sourceElements) {
const offset = detectorPosition.clone().sub(element);
const distanceSquared = offset.lengthSq();
const distance = Math.sqrt(distanceSquared);
const incidence = offset.dot(direction) / distance;
if (incidence > 0) {
sum += incidence / distanceSquared;
}
}
// Power is divided among elements; each isotropic element has
// intensity P / (4*pi*N).
return state.power * sum / (4 * Math.PI * sourceElements.length);
}
function createRadialGrid(radius, color, opacity) {
const positions = [];
const segments = 128;
for (let latitude = -75; latitude <= 75; latitude += 15) {
const phi = THREE.MathUtils.degToRad(latitude);
const y = radius * Math.sin(phi);
const ring = radius * Math.cos(phi);
for (let i = 0; i < segments; i++) {
const a = (i / segments) * Math.PI * 2;
const b = ((i + 1) / segments) * Math.PI * 2;
positions.push(
ring * Math.cos(a), y, ring * Math.sin(a),
ring * Math.cos(b), y, ring * Math.sin(b)
);
}
}
for (let longitude = 0; longitude < 180; longitude += 30) {
const lon = THREE.MathUtils.degToRad(longitude);
for (let i = 0; i < 64; i++) {
const a = -Math.PI / 2 + (i / 64) * Math.PI;
const b = -Math.PI / 2 + ((i + 1) / 64) * Math.PI;
positions.push(
radius * Math.cos(a) * Math.sin(lon),
radius * Math.sin(a),
radius * Math.cos(a) * Math.cos(lon),
radius * Math.cos(b) * Math.sin(lon),
radius * Math.sin(b),
radius * Math.cos(b) * Math.cos(lon)
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
return new THREE.LineSegments(geometry, material);
}
const innerShell = createRadialGrid(state.innerRadius, 0x5bcde5, 0.14);
const outerShell = createRadialGrid(state.outerRadius, 0x647ba8, 0.10);
scene.add(innerShell, outerShell);
const shellVolumes = [
new THREE.Mesh(
new THREE.SphereGeometry(state.innerRadius, 40, 28),
new THREE.MeshBasicMaterial({
color: 0x3b88b5,
transparent: true,
opacity: 0.018,
side: THREE.BackSide,
depthWrite: false
})
),
new THREE.Mesh(
new THREE.SphereGeometry(state.outerRadius, 40, 28),
new THREE.MeshBasicMaterial({
color: 0x586ba5,
transparent: true,
opacity: 0.011,
side: THREE.BackSide,
depthWrite: false
})
)
];
scene.add(...shellVolumes);
const comparisonRay = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
highlightDirection.clone().multiplyScalar(state.outerRadius * 1.08)
]),
new THREE.LineDashedMaterial({
color: 0x7ee8ff,
transparent: true,
opacity: 0.24,
dashSize: 0.45,
gapSize: 0.34
})
);
comparisonRay.computeLineDistances();
scene.add(comparisonRay);
const grid = new THREE.GridHelper(100, 60, 0x24425c, 0x13263d);
grid.position.y = -19.2;
grid.material.transparent = true;
grid.material.opacity = 0.16;
grid.material.depthWrite = false;
scene.add(grid);
// Sparse background stars.
{
const count = 700;
const positions = new Float32Array(count * 3);
let seed = 78123;
const random = () => {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
};
for (let i = 0; i < count; i++) {
const direction = new THREE.Vector3(
random() * 2 - 1,
random() * 2 - 1,
random() * 2 - 1
).normalize();
const radius = 48 + random() * 45;
positions[i * 3] = direction.x * radius;
positions[i * 3 + 1] = direction.y * radius;
positions[i * 3 + 2] = direction.z * radius;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
scene.add(new THREE.Points(
geometry,
new THREE.PointsMaterial({
color: 0xaed7ff,
size: 0.12,
transparent: true,
opacity: 0.38,
depthWrite: false,
sizeAttenuation: true
})
));
}
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 128;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(64, 64, 0, 64, 64, 64);
gradient.addColorStop(0, "rgba(220,252,255,1)");
gradient.addColorStop(0.08, "rgba(97,235,255,.95)");
gradient.addColorStop(0.28, "rgba(70,155,255,.36)");
gradient.addColorStop(0.65, "rgba(75,70,255,.08)");
gradient.addColorStop(1, "rgba(0,0,0,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 128, 128);
return new THREE.CanvasTexture(canvas);
}
const sourceGroup = new THREE.Group();
scene.add(sourceGroup);
const pointCore = new THREE.Mesh(
new THREE.SphereGeometry(0.28, 28, 18),
new THREE.MeshBasicMaterial({ color: 0xd9fbff })
);
sourceGroup.add(pointCore);
const sourceDisk = new THREE.Group();
sourceDisk.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
highlightDirection
);
const diskMesh = new THREE.Mesh(
new THREE.CircleGeometry(state.sourceRadius, 72),
new THREE.MeshBasicMaterial({
color: 0x64dfff,
transparent: true,
opacity: 0.22,
side: THREE.DoubleSide,
depthWrite: false
})
);
sourceDisk.add(diskMesh);
const diskRingPoints = [];
for (let i = 0; i < 128; i++) {
const a = (i / 128) * Math.PI * 2;
diskRingPoints.push(new THREE.Vector3(
Math.cos(a) * state.sourceRadius,
Math.sin(a) * state.sourceRadius,
0
));
}
sourceDisk.add(new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(diskRingPoints),
new THREE.LineBasicMaterial({
color: 0x8cecff,
transparent: true,
opacity: 0.72
})
));
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.015),
new THREE.Vector3(
Math.cos(angle) * state.sourceRadius,
Math.sin(angle) * state.sourceRadius,
0.015
)
]),
new THREE.LineBasicMaterial({
color: 0x70dfff,
transparent: true,
opacity: 0.22
})
);
sourceDisk.add(line);
}
sourceGroup.add(sourceDisk);
const glow = new THREE.Sprite(new THREE.SpriteMaterial({
map: makeGlowTexture(),
color: 0x7be9ff,
transparent: true,
blending: THREE.AdditiveBlending,
depthWrite: false
}));
glow.scale.set(7, 7, 1);
sourceGroup.add(glow);
const patches = [];
const patchMeshes = [];
function createDetectorGrid(size) {
const half = size / 2;
const positions = [
-half, 0, 0.055, half, 0, 0.055,
0, -half, 0.055, 0, half, 0.055,
0, 0, 0.055, 0, 0, 0
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
return new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0xe3fbff,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
}
for (const radius of [state.innerRadius, state.outerRadius]) {
for (const direction of detectorDirections) {
const group = new THREE.Group();
group.position.copy(direction).multiplyScalar(radius);
group.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction
);
const geometry = new THREE.BoxGeometry(
state.detectorSide,
state.detectorSide,
0.09
);
const material = new THREE.MeshStandardMaterial({
color: 0x43e8ff,
emissive: 0x43e8ff,
emissiveIntensity: 0.42,
metalness: 0.08,
roughness: 0.5,
transparent: true,
opacity: 0.94,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
group.add(mesh);
const frame = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0xe9fbff,
transparent: true,
opacity: 0.62
})
);
group.add(frame);
const gridLines = createDetectorGrid(state.detectorSide);
group.add(gridLines);
scene.add(group);
const patch = {
mesh,
frame,
gridLines,
group,
direction: direction.clone(),
radius,
flux: 0,
pointReference: pointFlux(radius),
valid: true,
selected: direction.equals(highlightDirection)
};
mesh.userData.patch = patch;
patches.push(patch);
patchMeshes.push(mesh);
}
}
const lowColor = new THREE.Color(0x655cff);
const midColor = new THREE.Color(0xdb5bdc);
const highColor = new THREE.Color(0x39e7ff);
function colorForFlux(value, minimum, maximum, target) {
const range = Math.max(maximum - minimum, 1e-9);
const normalized = THREE.MathUtils.clamp((value - minimum) / range, 0, 1);
const perceptual = Math.pow(normalized, 0.48);
if (perceptual < 0.5) {
target.copy(lowColor).lerp(midColor, perceptual * 2);
} else {
target.copy(midColor).lerp(highColor, (perceptual - 0.5) * 2);
}
return target;
}
const tempColor = new THREE.Color();
function formatPower(value) {
if (value >= 1000) {
return `${(value / 1000).toFixed(value % 1000 === 0 ? 0 : 1)} kW`;
}
return `${Math.round(value)} W`;
}
function updatePanel() {
if (state.mode === "point") {
const ratio = Math.pow(state.outerRadius / state.innerRadius, 2);
modelPanel.innerHTML = `
<div class="model-title">
<span>Ideal point source</span>
<span class="model-status">Inverse-square exact</span>
</div>
<div class="equation">S(r) = P / 4πr²</div>
<div class="model-copy">
The emitter is mathematically point-like, so the inverse-square relation
applies at both sampled radii.
</div>
<div class="ratio-row">
<span>S₈ / S₁₇</span>
<strong>${ratio.toFixed(2)}×</strong>
<span>inner vs outer</span>
</div>
`;
} else {
const innerRatio = state.innerRadius / state.sourceRadius;
const outerRatio = state.outerRadius / state.sourceRadius;
modelPanel.innerHTML = `
<div class="model-title">
<span>Finite source model</span>
<span class="model-status">Range-aware</span>
</div>
<div class="equation">
<span class="scope">Outer shell only · r/rₛ ≥ ${state.approximationGate}</span>
S(r) ≈ P / 4πr²
</div>
<div class="model-copy">
2,048 isotropic elements fill a ${2 * state.sourceRadius} m disk.
The point-source law is shown only in the far-field region.
</div>
<div class="validity-list">
<div class="validity-item">
<div>
<span class="badge no">1/r² withheld</span>
<small>8 m shell · r/rₛ = ${innerRatio.toFixed(1)}</small>
</div>
<strong>${document.getElementById("innerFlux").textContent} W/m²</strong>
</div>
<div class="validity-item">
<div>
<span class="badge yes">Approximation valid</span>
<small>17 m shell · r/rₛ = ${outerRatio.toFixed(1)}</small>
</div>
<strong>${document.getElementById("outerFlux").textContent} W/m²</strong>
</div>
</div>
`;
}
}
function updateModel() {
let minimum = Infinity;
let maximum = -Infinity;
for (const patch of patches) {
patch.flux = state.mode === "point"
? pointFlux(patch.radius)
: finiteFlux(patch.direction, patch.radius);
patch.pointReference = pointFlux(patch.radius);
patch.valid = state.mode === "point"
|| patch.radius / state.sourceRadius >= state.approximationGate;
minimum = Math.min(minimum, patch.flux);
maximum = Math.max(maximum, patch.flux);
}
for (const patch of patches) {
colorForFlux(patch.flux, minimum, maximum, tempColor);
patch.mesh.material.color.copy(tempColor);
patch.mesh.material.emissive.copy(tempColor);
patch.mesh.material.emissiveIntensity = patch.selected ? 0.66 : 0.34;
patch.mesh.material.opacity = patch.selected ? 1 : 0.83;
patch.frame.material.color.set(patch.selected ? 0xf0fdff : tempColor);
patch.frame.material.opacity = patch.selected ? 0.95 : 0.44;
patch.gridLines.material.opacity = patch.selected ? 0.28 : 0.11;
}
const inner = patches.find(p => p.radius === state.innerRadius && p.selected);
const outer = patches.find(p => p.radius === state.outerRadius && p.selected);
document.getElementById("innerFlux").textContent = inner.flux.toFixed(3);
document.getElementById("outerFlux").textContent = outer.flux.toFixed(3);
document.getElementById("innerMeta").textContent =
`${(inner.flux * state.detectorArea).toFixed(2)} W received · 5.76 m²`;
document.getElementById("outerMeta").textContent =
`${(outer.flux * state.detectorArea).toFixed(2)} W received · 5.76 m²`;
const innerRelation = document.getElementById("innerRelation");
const outerRelation = document.getElementById("outerRelation");
if (state.mode === "point") {
innerRelation.className = "tag-relation";
outerRelation.className = "tag-relation";
innerRelation.textContent = "1/r² valid · ideal point source";
outerRelation.textContent = "1/r² valid · ideal point source";
} else {
innerRelation.className = "tag-relation no";
outerRelation.className = "tag-relation";
innerRelation.textContent = "finite source · 1/r² withheld";
outerRelation.textContent = "point-source region · r/rₛ = 8.5";
}
document.getElementById("legendMin").textContent = minimum.toFixed(3);
document.getElementById("legendMax").textContent = maximum.toFixed(3);
document.getElementById("powerValue").textContent = formatPower(state.power);
document.getElementById("sourceTag").textContent = state.mode === "point"
? "Point emitter"
: "Finite emitter · Ø 4 m";
pointCore.visible = state.mode === "point";
sourceDisk.visible = state.mode === "finite";
glow.scale.setScalar(state.mode === "point" ? 5.2 : 7.7);
document.getElementById("pointMode").classList.toggle("active", state.mode === "point");
document.getElementById("finiteMode").classList.toggle("active", state.mode === "finite");
updatePanel();
if (hoveredPatch) showTooltip(hoveredPatch, pointerClientX, pointerClientY);
}
document.getElementById("pointMode").addEventListener("click", () => {
state.mode = "point";
updateModel();
});
document.getElementById("finiteMode").addEventListener("click", () => {
state.mode = "finite";
updateModel();
});
document.getElementById("powerSlider").addEventListener("input", event => {
state.power = Number(event.target.value);
updateModel();
});
// Direct camera controls: no examples/addons are used.
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", event => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointerup", event => {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
controls.dragging = false;
});
canvas.addEventListener("dblclick", () => {
controls.theta = 0.73;
controls.phi = 1.07;
controls.distance = 45;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
22,
72
);
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") controls.theta -= 0.08;
if (event.key === "ArrowRight") controls.theta += 0.08;
if (event.key === "ArrowUp") controls.phi = Math.max(0.18, controls.phi - 0.06);
if (event.key === "ArrowDown") controls.phi = Math.min(Math.PI - 0.18, controls.phi + 0.06);
if (event.key === "+" || event.key === "=") controls.distance = Math.max(22, controls.distance - 2);
if (event.key === "-") controls.distance = Math.min(72, controls.distance + 2);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let hoveredPatch = null;
let pointerClientX = 0;
let pointerClientY = 0;
function showTooltip(patch, x, y) {
const relation = state.mode === "point"
? `<div class="valid">Point source: exact 1/r² relation.</div>`
: patch.valid
? `<div class="valid">Point-source approximation valid<br>r/rₛ = ${(patch.radius / state.sourceRadius).toFixed(1)}</div>`
: `<div class="warning">Inverse-square relation withheld<br>r/rₛ = ${(patch.radius / state.sourceRadius).toFixed(1)}</div>`;
const reference = state.mode === "finite" && patch.valid
? `<div>Point reference: ${patch.pointReference.toFixed(3)} W/m²</div>`
: "";
tooltip.innerHTML = `
<strong>Detector at ${patch.radius.toFixed(0)} m</strong>
<div class="density">${patch.flux.toFixed(3)} W/m²</div>
<div>Received: ${(patch.flux * state.detectorArea).toFixed(2)} W</div>
<div>Area: ${state.detectorArea.toFixed(2)} m²</div>
${reference}
${relation}
`;
tooltip.style.display = "block";
const width = tooltip.offsetWidth;
const height = tooltip.offsetHeight;
tooltip.style.left = `${Math.min(x + 16, innerWidth - width - 12)}px`;
tooltip.style.top = `${Math.max(12, Math.min(y - height - 12, innerHeight - height - 12))}px`;
}
canvas.addEventListener("pointermove", event => {
pointerClientX = event.clientX;
pointerClientY = event.clientY;
if (controls.dragging) {
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.006,
0.18,
Math.PI - 0.18
);
controls.lastX = event.clientX;
controls.lastY = event.clientY;
tooltip.style.display = "none";
return;
}
pointer.x = (event.clientX / innerWidth) * 2 - 1;
pointer.y = -(event.clientY / innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersection = raycaster.intersectObjects(patchMeshes, false)[0];
hoveredPatch = intersection ? intersection.object.userData.patch : null;
if (hoveredPatch) {
showTooltip(hoveredPatch, pointerClientX, pointerClientY);
} else {
tooltip.style.display = "none";
}
});
canvas.addEventListener("pointerleave", () => {
hoveredPatch = null;
tooltip.style.display = "none";
});
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition, enabled = true) {
if (!enabled) {
element.style.display = "none";
return;
}
projected.copy(worldPosition).project(camera);
if (projected.z < -1 || projected.z > 1) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
updateModel();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
const pulse = 1 + Math.sin(elapsed * 2.2) * 0.035;
glow.material.opacity = 0.83 + Math.sin(elapsed * 2.4) * 0.08;
sourceLight.intensity = 60 + Math.sin(elapsed * 2.4) * 8;
if (state.mode === "finite") {
sourceDisk.rotation.z = elapsed * 0.045;
} else {
pointCore.scale.setScalar(pulse);
}
positionLabel(
document.getElementById("innerTag"),
highlightDirection.clone().multiplyScalar(state.innerRadius + 0.4)
);
positionLabel(
document.getElementById("outerTag"),
highlightDirection.clone().multiplyScalar(state.outerRadius + 0.4)
);
positionLabel(
document.getElementById("sourceTag"),
new THREE.Vector3(0, 0.1, 0)
);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```