Prompt specification
Build or customize the Three.js 3D scene "Panel Tilt and Projected Exposure" 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: Panel Tilt and Projected Exposure
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/panel-tilt-and-projected-exposure-x3978
Scene Description Prompt:
Panel tilt and projected exposure. Animate panel tilt under fixed illumination and compute a declared cosine-based exposure proxy. Label it as an ideal geometric proxy rather than a calibrated power prediction. Please build this with Three.js from cdnjs in one self-contained HTML file, using a 3D cutaway.
Working Three.js Starter (panel-tilt-and-projected-exposure-x3978):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Panel Tilt and Projected Exposure</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 24, 40, 0.82);
--panel-border: rgba(156, 206, 255, 0.16);
--text: #edf7ff;
--muted: #91a8bd;
--cyan: #70dcff;
--amber: #ffcb73;
--green: #8ff0c0;
--red: #ff9d9d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.hero {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
max-width: 570px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
content: "";
}
h1 {
margin: 0;
font-size: clamp(27px, 3.2vw, 48px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 1.02;
}
.subtitle {
max-width: 520px;
margin: 11px 0 0;
color: #b3c5d4;
font-size: 13px;
line-height: 1.55;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 15px;
}
.badge {
padding: 7px 10px;
border: 1px solid rgba(143, 218, 255, 0.2);
border-radius: 999px;
background: rgba(8, 25, 42, 0.72);
color: #c7dbe9;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.readout {
position: fixed;
top: 24px;
right: 24px;
z-index: 6;
width: min(330px, calc(100vw - 48px));
max-height: calc(100vh - 48px);
overflow: auto;
padding: 19px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 65px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px) saturate(125%);
}
.readout-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.hero-number {
display: flex;
align-items: baseline;
gap: 5px;
margin: 6px 0 1px;
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
#proxy-value {
font-size: 52px;
font-weight: 750;
letter-spacing: -0.055em;
line-height: 1;
}
.hero-number span {
font-size: 20px;
font-weight: 700;
}
.proxy-caption {
color: #b8ccdc;
font-size: 12px;
line-height: 1.45;
}
.formula {
margin: 16px 0;
padding: 12px 13px;
border: 1px solid rgba(112, 220, 255, 0.14);
border-radius: 11px;
background: rgba(3, 13, 25, 0.44);
color: #dcefff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.55;
text-align: center;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-height: 76px;
padding: 11px;
border: 1px solid rgba(255, 255, 255, 0.075);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
}
.metric-name {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
line-height: 1.35;
text-transform: uppercase;
}
.metric-value {
margin-top: 6px;
color: #f4f9ff;
font-size: 18px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.metric-value small {
color: var(--muted);
font-size: 10px;
font-weight: 600;
}
.chart-wrap {
margin-top: 14px;
}
.chart-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#response-chart {
display: block;
width: 100%;
height: 112px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 10px;
background: rgba(2, 10, 20, 0.42);
}
.disclaimer {
margin-top: 14px;
padding: 11px 12px;
border: 1px solid rgba(255, 203, 115, 0.24);
border-radius: 11px;
background: rgba(255, 185, 77, 0.075);
color: #ffe0aa;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.075em;
line-height: 1.5;
text-transform: uppercase;
}
.disclaimer small {
display: block;
margin-top: 4px;
color: #c9bfae;
font-size: 9px;
font-weight: 600;
letter-spacing: 0.025em;
text-transform: none;
}
.controls {
position: fixed;
left: 50%;
bottom: 23px;
z-index: 7;
display: flex;
align-items: center;
gap: 13px;
width: min(760px, calc(100vw - 36px));
padding: 12px 14px;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: rgba(8, 22, 37, 0.86);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
transform: translateX(-50%);
backdrop-filter: blur(18px) saturate(130%);
}
.control-button {
flex: 0 0 auto;
min-width: 84px;
height: 39px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.055);
color: #eaf7ff;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.control-button:hover {
border-color: rgba(112, 220, 255, 0.5);
background: rgba(112, 220, 255, 0.12);
}
.control-button:active {
transform: translateY(1px);
}
.control-button.primary {
border-color: rgba(112, 220, 255, 0.32);
background: rgba(112, 220, 255, 0.14);
color: #bcefff;
}
.slider-block {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
flex: 1;
gap: 10px;
min-width: 180px;
}
.slider-block label,
#tilt-value {
color: #c9dbe8;
font-size: 11px;
font-weight: 700;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
#tilt-value {
min-width: 50px;
color: var(--cyan);
text-align: right;
}
input[type="range"] {
width: 100%;
height: 4px;
border-radius: 999px;
appearance: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--fill, 10%),
rgba(255, 255, 255, 0.13) var(--fill, 10%),
rgba(255, 255, 255, 0.13) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #10293e;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(112, 220, 255, 0.55);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #10293e;
border-radius: 50%;
background: var(--cyan);
}
.hint {
position: fixed;
left: 26px;
bottom: 28px;
z-index: 5;
color: rgba(207, 225, 239, 0.64);
font-size: 10px;
line-height: 1.55;
pointer-events: none;
}
.hint strong {
color: rgba(225, 241, 252, 0.88);
font-weight: 700;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.hero {
top: 17px;
left: 18px;
max-width: calc(100vw - 36px);
}
h1 {
font-size: 31px;
}
.subtitle {
max-width: 390px;
font-size: 11px;
}
.readout {
top: auto;
right: 12px;
bottom: 91px;
width: 255px;
padding: 13px;
}
#proxy-value {
font-size: 39px;
}
.formula,
.chart-wrap {
display: none;
}
.metrics {
gap: 6px;
}
.metric {
min-height: 62px;
padding: 8px;
}
.metric-value {
font-size: 15px;
}
.disclaimer {
margin-top: 8px;
padding: 8px;
font-size: 8px;
}
.controls {
bottom: 10px;
gap: 8px;
padding: 9px;
}
.control-button {
min-width: 70px;
padding: 0 9px;
}
.hint {
display: none;
}
}
@media (max-width: 560px) {
.badges,
.subtitle {
display: none;
}
.readout {
width: 205px;
}
.metrics {
grid-template-columns: 1fr;
}
.metric:nth-child(n + 3) {
display: none;
}
.slider-block {
grid-template-columns: 1fr auto;
}
.slider-block label {
display: none;
}
#reset-view,
#cutaway-toggle {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="hero">
<div class="eyebrow">Interactive geometric study</div>
<h1>Panel tilt &<br>projected exposure</h1>
<p class="subtitle">
A sectioned 3D photovoltaic module rotates beneath a fixed solar vector.
The displayed exposure follows the ideal cosine law for a flat receiving surface.
</p>
<div class="badges">
<div class="badge">Fixed sun · 55° elevation</div>
<div class="badge">Area · 10.78 m²</div>
<div class="badge">Live cutaway</div>
</div>
</header>
<aside class="readout" aria-label="Geometric exposure readout">
<div class="readout-label">Ideal geometric exposure proxy</div>
<div class="hero-number">
<span id="proxy-value">57.4</span><span>%</span>
</div>
<div class="proxy-caption">
Relative to normal incidence under the same fixed illumination.
</div>
<div class="formula">
E<sub>geo</sub> / E<sub>ref</sub><br>
= max(0, n̂ · ŝ) = cos θ
</div>
<div class="metrics">
<div class="metric">
<div class="metric-name">Panel tilt from horizontal</div>
<div class="metric-value"><span id="tilt-metric">8.0</span><small> °</small></div>
</div>
<div class="metric">
<div class="metric-name">Incidence angle</div>
<div class="metric-value"><span id="angle-metric">47.0</span><small> °</small></div>
</div>
<div class="metric">
<div class="metric-name">Area normal to rays</div>
<div class="metric-value"><span id="normal-area">6.19</span><small> m²</small></div>
</div>
<div class="metric">
<div class="metric-name">Ground ray projection</div>
<div class="metric-value"><span id="ground-area">10.78</span><small> m²</small></div>
</div>
</div>
<div class="chart-wrap">
<div class="chart-head">
<span>Cosine response</span>
<span>Peak at 55°</span>
</div>
<canvas id="response-chart" width="560" height="210"></canvas>
</div>
<div class="disclaimer">
Ideal geometric proxy — not a calibrated power prediction
<small>
Ignores atmospheric variation, spectral response, temperature,
material losses, reflections, and partial shading.
</small>
</div>
</aside>
<div class="controls">
<button class="control-button primary" id="play-toggle" type="button">Pause</button>
<div class="slider-block">
<label for="tilt-slider">Tilt</label>
<input
id="tilt-slider"
type="range"
min="0"
max="75"
step="0.1"
value="8"
aria-label="Panel tilt from horizontal"
>
<output id="tilt-value">8.0°</output>
</div>
<button class="control-button" id="cutaway-toggle" type="button">Cutaway</button>
<button class="control-button" id="reset-view" type="button">Reset view</button>
</div>
<div class="hint">
<strong>Drag</strong> to orbit · <strong>Wheel / pinch</strong> to zoom<br>
<strong>Double-click</strong> to reset the camera
</div>
<div class="loading" id="loading">Building geometric scene…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
// -------------------------------------------------------------------------
// Constants and scene
// -------------------------------------------------------------------------
const PANEL_WIDTH = 4.4;
const PANEL_HEIGHT = 2.45;
const PANEL_AREA = PANEL_WIDTH * PANEL_HEIGHT;
const SUN_ELEVATION = THREE.MathUtils.degToRad(55);
const MAX_TILT = 75;
const panelCenter = new THREE.Vector3(0, 1.55, 0);
const sunDirection = new THREE.Vector3(
0,
Math.sin(SUN_ELEVATION),
Math.cos(SUN_ELEVATION)
).normalize();
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 12, 27);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.08,
80
);
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.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
$("viewport").appendChild(renderer.domElement);
const hemiLight = new THREE.HemisphereLight(0xc8ecff, 0x07101a, 1.35);
scene.add(hemiLight);
const sunLight = new THREE.DirectionalLight(0xffe0a3, 3.2);
sunLight.position.copy(panelCenter).addScaledVector(sunDirection, 9);
sunLight.target.position.copy(panelCenter);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -7;
sunLight.shadow.camera.right = 7;
sunLight.shadow.camera.top = 7;
sunLight.shadow.camera.bottom = -7;
sunLight.shadow.camera.near = 0.5;
sunLight.shadow.camera.far = 24;
sunLight.shadow.bias = -0.00015;
scene.add(sunLight, sunLight.target);
const fillLight = new THREE.DirectionalLight(0x7ecfff, 0.9);
fillLight.position.set(-5, 5, 6);
scene.add(fillLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1723,
roughness: 0.92,
metalness: 0.03
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x31516a, 0x183044);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x172a3b,
metalness: 0.65,
roughness: 0.32
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.76, 0.13, 48),
baseMaterial
);
base.position.y = 0.065;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// -------------------------------------------------------------------------
// Direct camera controls — no external controls addon
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const defaultView = {
theta: 0.58,
phi: 1.05,
radius: 9.1
};
const view = { ...defaultView };
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);
}
function resetCamera() {
Object.assign(view, defaultView);
updateCamera();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.005,
0.42,
1.34
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
4.8,
16
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Label and glow sprite helpers
// -------------------------------------------------------------------------
function createTextSprite(text, color = "#8ee8ff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(4, 17, 31, 0.86)";
ctx.strokeStyle = "rgba(151, 219, 255, 0.34)";
ctx.lineWidth = 3;
if (typeof ctx.roundRect === "function") {
ctx.beginPath();
ctx.roundRect(5, 5, 502, 118, 25);
ctx.fill();
ctx.stroke();
} else {
ctx.fillRect(5, 5, 502, 118);
ctx.strokeRect(5, 5, 502, 118);
}
ctx.fillStyle = color;
ctx.font = "700 40px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 64);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.5, 0.375, 1);
sprite.renderOrder = 20;
return sprite;
}
function createGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
const gradient = ctx.createRadialGradient(64, 64, 0, 64, 64, 64);
gradient.addColorStop(0, "rgba(255, 231, 163, 1)");
gradient.addColorStop(0.16, "rgba(255, 205, 112, 0.8)");
gradient.addColorStop(0.48, "rgba(255, 183, 77, 0.19)");
gradient.addColorStop(1, "rgba(255, 183, 77, 0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 128, 128);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// -------------------------------------------------------------------------
// Panel: local XY face, local +Z normal
// -------------------------------------------------------------------------
const panelRoot = new THREE.Group();
panelRoot.position.copy(panelCenter);
scene.add(panelRoot);
const aluminumMaterial = new THREE.MeshStandardMaterial({
color: 0xb7c7d0,
metalness: 0.86,
roughness: 0.24
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x233748,
metalness: 0.72,
roughness: 0.35
});
const backSheetMaterial = new THREE.MeshStandardMaterial({
color: 0xe7e0cf,
metalness: 0.02,
roughness: 0.82
});
const cellMaterials = [
new THREE.MeshStandardMaterial({
color: 0x164a7d,
emissive: 0x06182d,
emissiveIntensity: 0.28,
metalness: 0.38,
roughness: 0.27
}),
new THREE.MeshStandardMaterial({
color: 0x103d6b,
emissive: 0x041326,
emissiveIntensity: 0.3,
metalness: 0.4,
roughness: 0.3
})
];
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x9adfff,
transparent: true,
opacity: 0.17,
roughness: 0.08,
metalness: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const backing = new THREE.Mesh(
new THREE.BoxGeometry(
PANEL_WIDTH - 0.16,
PANEL_HEIGHT - 0.16,
0.045
),
backSheetMaterial
);
backing.position.z = -0.055;
backing.castShadow = true;
backing.receiveShadow = true;
panelRoot.add(backing);
// Aluminum perimeter.
const frameDepth = 0.17;
const frameThickness = 0.09;
function addFrameBox(size, position) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...size),
aluminumMaterial
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
panelRoot.add(mesh);
return mesh;
}
addFrameBox(
[PANEL_WIDTH, frameThickness, frameDepth],
[0, PANEL_HEIGHT / 2 - frameThickness / 2, 0.065]
);
addFrameBox(
[PANEL_WIDTH, frameThickness, frameDepth],
[0, -PANEL_HEIGHT / 2 + frameThickness / 2, 0.065]
);
addFrameBox(
[frameThickness, PANEL_HEIGHT - frameThickness * 2, frameDepth],
[-PANEL_WIDTH / 2 + frameThickness / 2, 0, 0.065]
);
addFrameBox(
[frameThickness, PANEL_HEIGHT - frameThickness * 2, frameDepth],
[PANEL_WIDTH / 2 - frameThickness / 2, 0, 0.065]
);
// Six columns by four rows. The final column is removed in cutaway mode.
const columns = 6;
const rows = 4;
const gridLeft = -PANEL_WIDTH / 2 + 0.16;
const gridBottom = -PANEL_HEIGHT / 2 + 0.16;
const gridWidth = PANEL_WIDTH - 0.32;
const gridHeight = PANEL_HEIGHT - 0.32;
const cellWidth = gridWidth / columns;
const cellHeight = gridHeight / rows;
const cellGroups = [];
const busMaterial = new THREE.LineBasicMaterial({
color: 0xb9d8e8,
transparent: true,
opacity: 0.75
});
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const group = new THREE.Group();
group.position.set(
gridLeft + cellWidth * (column + 0.5),
gridBottom + cellHeight * (row + 0.5),
0.005
);
const w = cellWidth - 0.032;
const h = cellHeight - 0.032;
const cell = new THREE.Mesh(
new THREE.BoxGeometry(w, h, 0.026),
cellMaterials[(row + column) % 2]
);
cell.castShadow = true;
cell.receiveShadow = true;
group.add(cell);
const busPoints = [];
for (const x of [-w * 0.24, w * 0.24]) {
busPoints.push(
new THREE.Vector3(x, -h * 0.43, 0.016),
new THREE.Vector3(x, h * 0.43, 0.016)
);
}
const busbars = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(busPoints),
busMaterial
);
group.add(busbars);
group.userData.column = column;
cellGroups.push(group);
panelRoot.add(group);
}
}
// Split front glazing so the last column can be removed cleanly.
const cutX = 1.34;
const innerLeft = -PANEL_WIDTH / 2 + 0.08;
const innerRight = PANEL_WIDTH / 2 - 0.08;
const glassHeight = PANEL_HEIGHT - 0.16;
const mainGlass = new THREE.Mesh(
new THREE.BoxGeometry(cutX - innerLeft, glassHeight, 0.035),
glassMaterial
);
mainGlass.position.set(
(innerLeft + cutX) / 2,
0,
0.092
);
mainGlass.renderOrder = 3;
panelRoot.add(mainGlass);
const rightGlass = new THREE.Mesh(
new THREE.BoxGeometry(innerRight - cutX, glassHeight, 0.035),
glassMaterial
);
rightGlass.position.set(
(cutX + innerRight) / 2,
0,
0.092
);
rightGlass.renderOrder = 3;
panelRoot.add(rightGlass);
// Exposed layer stack in the sectioned region.
const sectionGroup = new THREE.Group();
const sectionWidth = innerRight - cutX - 0.035;
const sectionCenter = (cutX + innerRight) / 2;
const substrateMaterial = new THREE.MeshStandardMaterial({
color: 0xe4a34b,
metalness: 0.05,
roughness: 0.65
});
const sectionSubstrate = new THREE.Mesh(
new THREE.BoxGeometry(sectionWidth, PANEL_HEIGHT - 0.34, 0.025),
substrateMaterial
);
sectionSubstrate.position.set(sectionCenter, 0, -0.014);
sectionSubstrate.castShadow = true;
sectionGroup.add(sectionSubstrate);
const sectionCell = new THREE.Mesh(
new THREE.BoxGeometry(
sectionWidth - 0.045,
PANEL_HEIGHT - 0.42,
0.018
),
cellMaterials[0]
);
sectionCell.position.set(sectionCenter, 0, 0.022);
sectionCell.castShadow = true;
sectionGroup.add(sectionCell);
const traceMaterial = new THREE.MeshStandardMaterial({
color: 0xe4c178,
metalness: 0.78,
roughness: 0.28
});
for (const x of [sectionCenter - 0.11, sectionCenter + 0.11]) {
const trace = new THREE.Mesh(
new THREE.BoxGeometry(0.012, PANEL_HEIGHT - 0.5, 0.009),
traceMaterial
);
trace.position.set(x, 0, 0.037);
sectionGroup.add(trace);
}
const sectionEdge = new THREE.Mesh(
new THREE.BoxGeometry(0.025, PANEL_HEIGHT - 0.3, 0.13),
new THREE.MeshBasicMaterial({ color: 0xffc96f })
);
sectionEdge.position.set(cutX, 0, 0.018);
sectionGroup.add(sectionEdge);
panelRoot.add(sectionGroup);
const cutLabel = createTextSprite("SECTIONED STACK", "#ffd28b");
cutLabel.scale.set(1.35, 0.338, 1);
cutLabel.position.set(2.65, 0.84, 0.16);
panelRoot.add(cutLabel);
const callout = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(1.72, 0.58, 0.09),
new THREE.Vector3(2.24, 0.84, 0.13),
new THREE.Vector3(2.48, 0.84, 0.15)
]),
new THREE.LineBasicMaterial({
color: 0xffca75,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
callout.renderOrder = 19;
panelRoot.add(callout);
// Rear junction box and two short leads.
const junctionBox = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.32, 0.12),
darkMetalMaterial
);
junctionBox.position.set(-1.05, -0.68, -0.145);
junctionBox.castShadow = true;
panelRoot.add(junctionBox);
const leadMaterial = new THREE.MeshStandardMaterial({
color: 0x141a20,
roughness: 0.68
});
for (const offset of [-0.1, 0.1]) {
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-1.05 + offset, -0.68, -0.21),
new THREE.Vector3(-1.35 + offset, -0.78, -0.25),
new THREE.Vector3(-1.85 + offset, -0.7, -0.18),
new THREE.Vector3(-2.13 + offset, -0.46, -0.08)
]);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 30, 0.018, 8, false),
leadMaterial
);
tube.castShadow = true;
panelRoot.add(tube);
}
// -------------------------------------------------------------------------
// Support stand and axle
// -------------------------------------------------------------------------
const column = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.11, 1.42, 24),
darkMetalMaterial
);
column.position.set(0, 0.78, 0);
column.castShadow = true;
scene.add(column);
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 4.85, 24),
aluminumMaterial
);
axle.rotation.z = Math.PI / 2;
axle.position.copy(panelCenter);
axle.castShadow = true;
scene.add(axle);
function cylinderBetween(start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 20),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
cylinderBetween(
new THREE.Vector3(-0.48, 0.14, 0.45),
new THREE.Vector3(0, 1.5, 0),
0.043,
darkMetalMaterial
);
cylinderBetween(
new THREE.Vector3(0.48, 0.14, 0.45),
new THREE.Vector3(0, 1.5, 0),
0.043,
darkMetalMaterial
);
// -------------------------------------------------------------------------
// Fixed light source, incoming rays, normal, and incidence arc
// -------------------------------------------------------------------------
const sunPosition = panelCenter.clone().addScaledVector(sunDirection, 6.2);
const sunSphere = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 24, 16),
new THREE.MeshBasicMaterial({ color: 0xffd27a })
);
sunSphere.position.copy(sunPosition);
scene.add(sunSphere);
const sunGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createGlowTexture(),
transparent: true,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
sunGlow.position.copy(sunPosition);
sunGlow.scale.set(2.7, 2.7, 1);
scene.add(sunGlow);
const sunLabel = createTextSprite("FIXED SUN VECTOR", "#ffd98f");
sunLabel.position.copy(sunPosition).add(new THREE.Vector3(0, 0.52, 0));
scene.add(sunLabel);
const incomingRayMaterial = new THREE.LineBasicMaterial({
color: 0xffd27a,
transparent: true,
opacity: 0.68
});
for (const xOffset of [-2, -1, 0, 1, 2]) {
const arrow = new THREE.ArrowHelper(
sunDirection.clone().negate(),
panelCenter
.clone()
.addScaledVector(sunDirection, 3.25)
.add(new THREE.Vector3(xOffset, 0, 0)),
2.5,
0xffce75,
0.22,
0.1
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.66;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.8;
scene.add(arrow);
}
const normalArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
panelCenter,
1.42,
0x70dcff,
0.23,
0.115
);
normalArrow.line.material.depthTest = false;
normalArrow.cone.material.depthTest = false;
normalArrow.renderOrder = 18;
scene.add(normalArrow);
const sunAxisArrow = new THREE.ArrowHelper(
sunDirection,
panelCenter,
1.9,
0xffc96f,
0.22,
0.11
);
sunAxisArrow.line.material.depthTest = false;
sunAxisArrow.cone.material.depthTest = false;
sunAxisArrow.renderOrder = 18;
scene.add(sunAxisArrow);
const arcGeometry = new THREE.BufferGeometry();
arcGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(33 * 3), 3)
);
const incidenceArc = new THREE.Line(
arcGeometry,
new THREE.LineBasicMaterial({
color: 0xffdc92,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
incidenceArc.renderOrder = 19;
scene.add(incidenceArc);
const thetaLabel = createTextSprite("θ", "#ffe0a0");
thetaLabel.scale.set(0.48, 0.12, 1);
scene.add(thetaLabel);
// -------------------------------------------------------------------------
// Ray-projected footprint on the ground
// -------------------------------------------------------------------------
const footprintGeometry = new THREE.BufferGeometry();
footprintGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(12), 3)
);
footprintGeometry.setIndex([0, 1, 2, 0, 2, 3]);
const footprint = new THREE.Mesh(
footprintGeometry,
new THREE.MeshBasicMaterial({
color: 0xffbd62,
transparent: true,
opacity: 0.12,
side: THREE.DoubleSide,
depthWrite: false
})
);
footprint.renderOrder = 1;
scene.add(footprint);
const footprintLineGeometry = new THREE.BufferGeometry();
footprintLineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(15), 3)
);
const footprintLine = new THREE.LineLoop(
footprintLineGeometry,
new THREE.LineBasicMaterial({
color: 0xffca78,
transparent: true,
opacity: 0.72
})
);
scene.add(footprintLine);
const footprintLabel = createTextSprite("RAY-PROJECTED PANEL AREA", "#ffd28b");
footprintLabel.scale.set(1.65, 0.413, 1);
scene.add(footprintLabel);
// -------------------------------------------------------------------------
// Mathematical state and geometry updates
// -------------------------------------------------------------------------
let tilt = 8;
let playing = true;
let cutawayEnabled = true;
let lastChartTilt = -999;
const panelNormal = new THREE.Vector3();
const rayDirection = sunDirection.clone().negate();
const localCorners = [
new THREE.Vector3(-PANEL_WIDTH / 2, -PANEL_HEIGHT / 2, 0),
new THREE.Vector3(PANEL_WIDTH / 2, -PANEL_HEIGHT / 2, 0),
new THREE.Vector3(PANEL_WIDTH / 2, PANEL_HEIGHT / 2, 0),
new THREE.Vector3(-PANEL_WIDTH / 2, PANEL_HEIGHT / 2, 0)
];
function slerpDirection(a, b, t) {
const dot = THREE.MathUtils.clamp(a.dot(b), -1, 1);
const omega = Math.acos(dot);
const so = Math.sin(omega);
if (Math.abs(so) < 1e-6) {
return a.clone();
}
return a
.clone()
.multiplyScalar(Math.sin((1 - t) * omega) / so)
.add(b.clone().multiplyScalar(Math.sin(t * omega) / so))
.normalize();
}
function updateFootprint() {
const projected = [];
for (const corner of localCorners) {
const world = panelRoot.localToWorld(corner.clone());
const distance = (0.035 - world.y) / rayDirection.y;
projected.push(
world.clone().addScaledVector(rayDirection, distance)
);
}
const positions = footprintGeometry.attributes.position;
for (let i = 0; i < projected.length; i++) {
positions.setXYZ(
i,
projected[i].x,
projected[i].y,
projected[i].z
);
}
positions.needsUpdate = true;
footprintGeometry.computeBoundingSphere();
const linePositions = footprintLineGeometry.attributes.position;
for (let i = 0; i < 4; i++) {
linePositions.setXYZ(
i,
projected[i].x,
projected[i].y + 0.008,
projected[i].z
);
}
linePositions.setXYZ(
4,
projected[0].x,
projected[0].y + 0.008,
projected[0].z
);
linePositions.needsUpdate = true;
footprintLineGeometry.computeBoundingSphere();
const centroid = new THREE.Vector3();
for (const point of projected) centroid.add(point);
centroid.multiplyScalar(0.25);
footprintLabel.position.set(
centroid.x,
0.13,
centroid.z
);
}
function updateIncidenceArc() {
const attribute = arcGeometry.attributes.position;
const mid = new THREE.Vector3();
for (let i = 0; i <= 32; i++) {
const direction = slerpDirection(
panelNormal,
sunDirection,
i / 32
);
attribute.setXYZ(
i,
panelCenter.x + direction.x * 0.88,
panelCenter.y + direction.y * 0.88,
panelCenter.z + direction.z * 0.88
);
if (i === 16) mid.copy(direction);
}
attribute.needsUpdate = true;
arcGeometry.computeBoundingSphere();
thetaLabel.position.copy(panelCenter).addScaledVector(mid, 1.03);
thetaLabel.position.y += 0.06;
}
function applyCutaway() {
for (const group of cellGroups) {
group.visible = !cutawayEnabled || group.userData.column < 5;
}
rightGlass.visible = !cutawayEnabled;
sectionGroup.visible = cutawayEnabled;
cutLabel.visible = cutawayEnabled;
callout.visible = cutawayEnabled;
$("cutaway-toggle").textContent = cutawayEnabled
? "Cutaway on"
: "Solid panel";
}
function updatePanel() {
const tiltRadians = THREE.MathUtils.degToRad(tilt);
// Local +Z is transformed into the world-space panel normal.
panelNormal.set(
0,
Math.cos(tiltRadians),
Math.sin(tiltRadians)
);
panelRoot.rotation.x = -Math.PI / 2 + tiltRadians;
panelRoot.updateMatrixWorld(true);
normalArrow.setDirection(panelNormal);
normalArrow.position.copy(panelCenter);
sunAxisArrow.position.copy(panelCenter);
updateIncidenceArc();
updateFootprint();
updateReadout();
$("tilt-slider").value = tilt.toFixed(1);
$("tilt-value").textContent = `${tilt.toFixed(1)}°`;
$("tilt-slider").style.setProperty(
"--fill",
`${(tilt / MAX_TILT) * 100}%`
);
}
// -------------------------------------------------------------------------
// Readout and response chart
// -------------------------------------------------------------------------
function updateReadout() {
const cosine = Math.max(0, panelNormal.dot(sunDirection));
const incidenceAngle = THREE.MathUtils.radToDeg(
Math.acos(THREE.MathUtils.clamp(cosine, -1, 1))
);
const projectedNormalArea = PANEL_AREA * cosine;
const groundProjectedArea =
projectedNormalArea / Math.max(0.001, Math.sin(SUN_ELEVATION));
$("proxy-value").textContent = (cosine * 100).toFixed(1);
$("tilt-metric").textContent = tilt.toFixed(1);
$("angle-metric").textContent = incidenceAngle.toFixed(1);
$("normal-area").textContent = projectedNormalArea.toFixed(2);
$("ground-area").textContent = groundProjectedArea.toFixed(2);
if (Math.abs(tilt - lastChartTilt) > 0.08) {
drawResponseChart(tilt);
lastChartTilt = tilt;
}
}
function drawResponseChart(currentTilt) {
const canvas = $("response-chart");
const ctx = canvas.getContext("2d");
const width = canvas.width;
const height = canvas.height;
const pad = {
left: 38,
right: 18,
top: 18,
bottom: 30
};
const chartWidth = width - pad.left - pad.right;
const chartHeight = height - pad.top - pad.bottom;
const toX = (degrees) =>
pad.left + (degrees / MAX_TILT) * chartWidth;
const toY = (cosine) =>
pad.top + (1 - cosine) * chartHeight;
ctx.clearRect(0, 0, width, height);
ctx.strokeStyle = "rgba(255,255,255,0.08)";
ctx.lineWidth = 1;
for (const value of [0.5, 0.75, 1]) {
const y = toY(value);
ctx.beginPath();
ctx.moveTo(pad.left, y);
ctx.lineTo(width - pad.right, y);
ctx.stroke();
ctx.fillStyle = "rgba(196,218,233,0.55)";
ctx.font = "18px system-ui";
ctx.textAlign = "right";
ctx.textBaseline = "middle";
ctx.fillText(`${Math.round(value * 100)}%`, pad.left - 7, y);
}
for (const value of [0, 25, 50, 75]) {
const x = toX(value);
ctx.beginPath();
ctx.moveTo(x, pad.top);
ctx.lineTo(x, height - pad.bottom);
ctx.stroke();
ctx.fillStyle = "rgba(196,218,233,0.55)";
ctx.font = "18px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "top";
ctx.fillText(`${value}°`, x, height - pad.bottom + 8);
}
const optimumX = toX(55);
ctx.setLineDash([6, 6]);
ctx.strokeStyle = "rgba(255, 205, 119, 0.6)";
ctx.beginPath();
ctx.moveTo(optimumX, pad.top);
ctx.lineTo(optimumX, height - pad.bottom);
ctx.stroke();
ctx.setLineDash([]);
ctx.strokeStyle = "#70dcff";
ctx.lineWidth = 4;
ctx.beginPath();
for (let degrees = 0; degrees <= MAX_TILT; degrees += 0.5) {
const response = Math.cos(
Math.abs(THREE.MathUtils.degToRad(55 - degrees))
);
const x = toX(degrees);
const y = toY(response);
if (degrees === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
const currentResponse = Math.cos(
Math.abs(THREE.MathUtils.degToRad(55 - currentTilt))
);
const markerX = toX(currentTilt);
const markerY = toY(currentResponse);
ctx.fillStyle = "#ffcb73";
ctx.beginPath();
ctx.arc(markerX, markerY, 8, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "rgba(255, 203, 115, 0.45)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(markerX, markerY);
ctx.lineTo(markerX, height - pad.bottom);
ctx.stroke();
}
// -------------------------------------------------------------------------
// UI behavior
// -------------------------------------------------------------------------
function setPlaying(value) {
playing = value;
$("play-toggle").textContent = playing ? "Pause" : "Play";
}
$("play-toggle").addEventListener("click", () => {
setPlaying(!playing);
});
$("tilt-slider").addEventListener("input", (event) => {
setPlaying(false);
tilt = Number(event.target.value);
updatePanel();
});
$("cutaway-toggle").addEventListener("click", () => {
cutawayEnabled = !cutawayEnabled;
applyCutaway();
});
$("reset-view").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const cycleDuration = 13.5;
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (playing) {
const phase = (elapsed % cycleDuration) / cycleDuration;
const triangle = phase < 0.5 ? phase * 2 : 2 - phase * 2;
const eased = triangle * triangle * (3 - 2 * triangle);
tilt = 8 + 60 * eased;
updatePanel();
}
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
applyCutaway();
updateCamera();
updatePanel();
drawResponseChart(tilt);
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```