Prompt specification
Build or customize the Three.js 3D scene "Crossed and aligned polarizer comparison" 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: Crossed and aligned polarizer comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/crossed-and-aligned-polarizer-comparison-x1566
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Place matched filter pairs at aligned, intermediate, and crossed angles; display ideal transmitted intensity using the stated polarization assumptions rather than arbitrary opacity changes.
Working Three.js Starter (crossed-and-aligned-polarizer-comparison-x1566):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ideal Polarization Filters</title>
<style>
:root {
color-scheme: dark;
--bg: #061019;
--panel: rgba(8, 20, 31, 0.78);
--border: rgba(135, 221, 255, 0.2);
--text: #e8f8ff;
--muted: #8ca8b8;
--cyan: #78e8ff;
--yellow: #ffd166;
--green: #7af0c2;
--red: #ff7f91;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px) saturate(125%);
-webkit-backdrop-filter: blur(16px) saturate(125%);
}
.brand {
position: fixed;
top: 22px;
left: 22px;
width: 350px;
padding: 18px 19px;
border-radius: 18px;
pointer-events: auto;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.12;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.button-row {
display: flex;
gap: 8px;
margin-top: 14px;
}
button {
appearance: none;
border: 1px solid rgba(120, 232, 255, 0.22);
border-radius: 9px;
padding: 7px 11px;
background: rgba(120, 232, 255, 0.08);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(120, 232, 255, 0.16);
border-color: rgba(120, 232, 255, 0.48);
transform: translateY(-1px);
}
.assumptions {
position: fixed;
top: 22px;
right: 22px;
width: 348px;
padding: 17px 18px;
border-radius: 18px;
pointer-events: auto;
}
.assumptions h2 {
margin: 0 0 10px;
font-size: 13px;
letter-spacing: 0.02em;
}
.assumptions ul {
margin: 0;
padding-left: 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.formula {
margin-top: 12px;
padding: 10px 11px;
border: 1px solid rgba(120, 232, 255, 0.14);
border-radius: 10px;
background: rgba(0, 0, 0, 0.15);
color: #d8f8ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.65;
}
.formula strong {
color: var(--cyan);
}
.note {
margin-top: 9px;
color: #718d9d;
font-size: 10.5px;
line-height: 1.45;
}
.legend {
position: fixed;
right: 22px;
bottom: 186px;
width: 260px;
padding: 12px 14px;
border-radius: 13px;
color: var(--muted);
font-size: 10.5px;
line-height: 1.55;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin: 4px 0;
}
.swatch {
width: 22px;
height: 4px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(120, 232, 255, 0.6);
}
.swatch.angle {
width: 12px;
height: 12px;
border: 2px solid var(--yellow);
border-radius: 50%;
background: transparent;
box-shadow: none;
}
.cards {
position: fixed;
left: 50%;
bottom: 22px;
display: grid;
grid-template-columns: repeat(3, minmax(205px, 250px));
gap: 10px;
transform: translateX(-50%);
pointer-events: auto;
}
.card {
min-height: 142px;
padding: 14px 15px 13px;
border-radius: 16px;
}
.card-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 8px;
}
.card-title {
font-size: 13px;
font-weight: 750;
}
.angle-badge {
color: var(--yellow);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
}
.reading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-top: 14px;
}
.reading-label {
color: var(--muted);
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.1em;
}
.reading-value {
color: var(--cyan);
font-size: 22px;
font-weight: 780;
letter-spacing: -0.04em;
}
.card.crossed .reading-value {
color: var(--red);
}
.bar {
height: 5px;
margin-top: 9px;
overflow: hidden;
border-radius: 5px;
background: rgba(255, 255, 255, 0.07);
}
.bar > span {
display: block;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #43bddd, var(--cyan));
box-shadow: 0 0 12px rgba(120, 232, 255, 0.4);
}
.card.crossed .bar > span {
background: var(--red);
}
.card-footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 9px;
color: #718d9d;
font-size: 9.5px;
}
.hint {
position: fixed;
left: 22px;
bottom: 24px;
color: rgba(190, 219, 232, 0.55);
font-size: 10.5px;
letter-spacing: 0.02em;
pointer-events: none;
}
@media (max-width: 1050px) {
.brand {
width: 310px;
}
.assumptions {
width: 310px;
}
.cards {
grid-template-columns: repeat(3, 190px);
}
.legend {
display: none;
}
.hint {
display: none;
}
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 13px 15px;
}
.brand h1 {
font-size: 20px;
}
.brand .subtitle,
.brand .button-row {
display: none;
}
.assumptions {
top: 113px;
left: 10px;
right: 10px;
width: auto;
padding: 12px 14px;
}
.assumptions ul {
font-size: 10.5px;
}
.assumptions .note {
display: none;
}
.cards {
right: 10px;
bottom: 10px;
left: auto;
grid-template-columns: 1fr;
width: min(88vw, 340px);
transform: none;
}
.card {
min-height: 104px;
padding: 10px 12px;
}
.reading {
margin-top: 7px;
}
.card-footer {
margin-top: 6px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="brand panel">
<div class="eyebrow">Optics / Polarization</div>
<h1>Ideal Linear Filter Pairs</h1>
<p class="subtitle">
Matched ideal polarizers compared at aligned, intermediate, and crossed
relative angles. Beam brightness is calculated from Malus’s law.
</p>
<div class="button-row">
<button id="resetView" type="button">Reset overview</button>
</div>
</header>
<aside class="assumptions panel">
<h2>Polarization assumptions</h2>
<ul>
<li>The incident beam is unpolarized with intensity I₀.</li>
<li>Both filters are identical, ideal linear polarizers.</li>
<li>The first filter is fixed at 0° in every pair.</li>
<li>The yellow arc shows the analyzer’s relative angle Δθ.</li>
</ul>
<div class="formula">
<strong>I₁ = I₀ / 2</strong><br>
<strong>Iout = I₀ / 2 · cos²(Δθ)</strong>
</div>
<div class="note">
A pre-polarized input aligned with the first filter would use I₀ instead
of I₀/2. Beam RGB is linearly scaled by I/I₀; beam alpha is fixed.
</div>
</aside>
<div class="legend panel">
<div class="legend-row">
<span class="swatch"></span>
<span>Beam radiance ∝ calculated transmitted intensity</span>
</div>
<div class="legend-row">
<span class="swatch angle"></span>
<span>Relative analyzer angle Δθ</span>
</div>
</div>
<section class="cards" aria-label="Calculated transmitted intensities">
<article class="card panel">
<div class="card-top">
<div class="card-title">Aligned</div>
<div class="angle-badge">Δθ = 0°</div>
</div>
<div class="reading">
<span class="reading-label">Iout / I₀</span>
<span class="reading-value">50.0%</span>
</div>
<div class="bar"><span style="width: 50%"></span></div>
<div class="card-footer">
<span>cos²(0°) = 1</span>
<button type="button" data-focus="0">Focus</button>
</div>
</article>
<article class="card panel">
<div class="card-top">
<div class="card-title">Intermediate</div>
<div class="angle-badge">Δθ = 45°</div>
</div>
<div class="reading">
<span class="reading-label">Iout / I₀</span>
<span class="reading-value">25.0%</span>
</div>
<div class="bar"><span style="width: 25%"></span></div>
<div class="card-footer">
<span>cos²(45°) = 0.5</span>
<button type="button" data-focus="1">Focus</button>
</div>
</article>
<article class="card panel crossed">
<div class="card-top">
<div class="card-title">Crossed</div>
<div class="angle-badge">Δθ = 90°</div>
</div>
<div class="reading">
<span class="reading-label">Iout / I₀</span>
<span class="reading-value">0.0%</span>
</div>
<div class="bar"><span style="width: 0%"></span></div>
<div class="card-footer">
<span>cos²(90°) = 0</span>
<button type="button" data-focus="2">Focus</button>
</div>
</article>
</section>
<div class="hint">Drag to orbit · Wheel to zoom · Select a card to focus</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive Three.js scene showing three ideal polarization filter pairs"
);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x061019);
scene.fog = new THREE.FogExp2(0x061019, 0.022);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
// ------------------------------------------------------------
// Camera controls implemented directly, without addons
// ------------------------------------------------------------
const desired = {
target: new THREE.Vector3(0, 0.1, 0),
radius: 27,
theta: 0.53,
phi: 1.04
};
const current = {
target: desired.target.clone(),
radius: desired.radius,
theta: desired.theta,
phi: desired.phi
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= dx * 0.0055;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.0045,
0.52,
1.43
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
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();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
10,
42
);
},
{ passive: false }
);
function damp(currentValue, targetValue, lambda, dt) {
return THREE.MathUtils.lerp(
currentValue,
targetValue,
1 - Math.exp(-lambda * dt)
);
}
// ------------------------------------------------------------
// Lighting and environment
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9bdfff, 0x071018, 1.35));
const keyLight = new THREE.DirectionalLight(0xe9f8ff, 2.5);
keyLight.position.set(-8, 13, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -22;
keyLight.shadow.camera.right = 22;
keyLight.shadow.camera.top = 16;
keyLight.shadow.camera.bottom = -16;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 50;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x29c9ff, 48, 35, 2);
rimLight.position.set(2, 7, 8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x07131d,
roughness: 0.88,
metalness: 0.12
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.76;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(54, 54, 0x24546a, 0x163140);
grid.position.y = -1.745;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
// ------------------------------------------------------------
// Shared materials
// ------------------------------------------------------------
const benchMaterial = new THREE.MeshStandardMaterial({
color: 0x122735,
roughness: 0.58,
metalness: 0.56
});
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0x10202b,
roughness: 0.42,
metalness: 0.72
});
const mountMaterial = new THREE.MeshStandardMaterial({
color: 0x466272,
roughness: 0.34,
metalness: 0.76
});
const sourceMaterial = new THREE.MeshStandardMaterial({
color: 0x213846,
roughness: 0.28,
metalness: 0.78
});
const detectorMaterial = new THREE.MeshStandardMaterial({
color: 0x182b37,
roughness: 0.36,
metalness: 0.68
});
// Filter opacity is fixed and is not used to encode output intensity.
const filterMaterial = new THREE.MeshStandardMaterial({
color: 0x50c8e5,
roughness: 0.28,
metalness: 0.08,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false
});
const filterRingMaterial = new THREE.MeshStandardMaterial({
color: 0xb8f5ff,
emissive: 0x36c9ef,
emissiveIntensity: 1.35,
roughness: 0.3,
metalness: 0.55
});
const axisMaterial = new THREE.MeshStandardMaterial({
color: 0xe3fbff,
emissive: 0x5ddfff,
emissiveIntensity: 1.9,
roughness: 0.25,
metalness: 0.2
});
const accentMaterial = new THREE.MeshBasicMaterial({
color: 0x2b829e,
toneMapped: false
});
const angleMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
toneMapped: false
});
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function addBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderZ(
radius,
length,
material,
x,
y,
z,
parent = scene,
radialSegments = 48
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.rotation.x = Math.PI / 2;
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addMount(x, z) {
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.36, 0.42, 0.12, 32),
edgeMaterial
);
foot.position.set(x, -1.44, z);
foot.castShadow = true;
foot.receiveShadow = true;
scene.add(foot);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, 0.9, 20),
mountMaterial
);
post.position.set(x, -0.98, z);
post.castShadow = true;
scene.add(post);
}
function createFilter(x, z, angleDegrees) {
addMount(x, z);
const group = new THREE.Group();
group.position.set(x, 0.25, z);
group.rotation.z = THREE.MathUtils.degToRad(angleDegrees);
scene.add(group);
const plate = new THREE.Mesh(
new THREE.CircleGeometry(0.88, 72),
filterMaterial
);
plate.renderOrder = 2;
group.add(plate);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.92, 0.036, 12, 80),
filterRingMaterial
);
ring.castShadow = true;
group.add(ring);
// The bright bar represents the filter's transmission axis.
// It is always the local X axis before the group rotation.
const axis = new THREE.Mesh(
new THREE.BoxGeometry(1.52, 0.075, 0.075),
axisMaterial
);
axis.position.z = 0.045;
group.add(axis);
for (const side of [-1, 1]) {
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 16, 12),
axisMaterial
);
cap.position.set(side * 0.72, 0, 0.045);
group.add(cap);
}
return group;
}
function createBeam(x, zStart, zEnd, intensity) {
const length = zEnd - zStart;
const centerZ = (zStart + zEnd) * 0.5;
const baseColor = new THREE.Color(0xa7edff);
// Only the RGB radiance changes. Alpha is constant across all beams.
const coreMaterial = new THREE.MeshBasicMaterial({
color: baseColor.clone().multiplyScalar(intensity * 1.45),
transparent: true,
opacity: 0.76,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const haloMaterial = new THREE.MeshBasicMaterial({
color: baseColor.clone().multiplyScalar(intensity * 0.2),
transparent: true,
opacity: 0.2,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const core = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, length, 28, 1, true),
coreMaterial
);
core.rotation.x = Math.PI / 2;
core.position.set(x, 0.25, centerZ);
scene.add(core);
const halo = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.25, length, 28, 1, true),
haloMaterial
);
halo.rotation.x = Math.PI / 2;
halo.position.set(x, 0.25, centerZ);
scene.add(halo);
}
// ------------------------------------------------------------
// Canvas-generated labels
// ------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width * 0.5, height * 0.5);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeBadge(title, delta, output) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 758, 210, 30);
ctx.fillStyle = "rgba(6, 18, 29, 0.88)";
ctx.fill();
ctx.strokeStyle = "rgba(120, 232, 255, 0.32)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = "#78e8ff";
ctx.fillRect(30, 31, 7, 150);
ctx.fillStyle = "#e8f8ff";
ctx.font = "750 43px system-ui, sans-serif";
ctx.fillText(title.toUpperCase(), 59, 65);
ctx.fillStyle = "#ffd166";
ctx.font = "600 28px ui-monospace, monospace";
ctx.fillText(`ANALYZER Δθ = ${delta}°`, 59, 115);
ctx.fillStyle = "#8ca8b8";
ctx.font = "500 23px system-ui, sans-serif";
ctx.fillText("Ideal transmitted intensity", 59, 157);
ctx.fillStyle = output === 0 ? "#ff7f91" : "#78e8ff";
ctx.font = "780 37px system-ui, sans-serif";
ctx.textAlign = "right";
ctx.fillText(`${output.toFixed(1)}% of I₀`, 726, 183);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(4.65, 1.33, 1);
return sprite;
}
function makeTinyLabel(text, x, y, z) {
const canvas = document.createElement("canvas");
canvas.width = 160;
canvas.height = 100;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 160, 100);
roundedRect(ctx, 8, 8, 144, 84, 22);
ctx.fillStyle = "rgba(6, 18, 29, 0.9)";
ctx.fill();
ctx.strokeStyle = "rgba(120, 232, 255, 0.3)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = "#dff9ff";
ctx.font = "750 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 80, 52);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(0.55, 0.34, 1);
scene.add(sprite);
}
// ------------------------------------------------------------
// Physical model
// ------------------------------------------------------------
// Unpolarized input through an ideal first polarizer:
// I1 = I0 / 2.
//
// The second ideal polarizer transmits:
// Iout = I1 * cos^2(delta).
function idealTransmittedIntensity(deltaDegrees) {
const delta = THREE.MathUtils.degToRad(deltaDegrees);
return 0.5 * Math.pow(Math.cos(delta), 2);
}
const stations = [
{
name: "Aligned",
x: -7,
delta: 0
},
{
name: "Intermediate",
x: 0,
delta: 45
},
{
name: "Crossed",
x: 7,
delta: 90
}
];
stations.forEach((station) => {
const output = idealTransmittedIntensity(station.delta);
station.output = output;
const x = station.x;
// Optical bench.
addBox(3.7, 0.22, 10.25, benchMaterial, x, -1.62, 0);
addBox(0.065, 0.055, 9.95, accentMaterial, x - 1.72, -1.475, 0);
addBox(0.065, 0.055, 9.95, accentMaterial, x + 1.72, -1.475, 0);
// Source housing and aperture.
addMount(x, -4.3);
addCylinderZ(0.59, 0.78, sourceMaterial, x, 0.25, -4.32);
const sourceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.055, 12, 64),
filterRingMaterial
);
sourceRing.position.set(x, 0.25, -3.9);
scene.add(sourceRing);
const sourceAperture = new THREE.Mesh(
new THREE.CircleGeometry(0.34, 64),
new THREE.MeshBasicMaterial({
color: new THREE.Color(0xb9f2ff).multiplyScalar(1.35),
toneMapped: false
})
);
sourceAperture.position.set(x, 0.25, -3.88);
scene.add(sourceAperture);
// First polarizer at 0° and analyzer at the relative angle.
createFilter(x, -1.65, 0);
createFilter(x, 1.25, station.delta);
// Horizontal reference line for the analyzer angle.
const referenceGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x - 1.2, 0.25, 1.335),
new THREE.Vector3(x + 1.2, 0.25, 1.335)
]);
const referenceLine = new THREE.Line(
referenceGeometry,
new THREE.LineBasicMaterial({
color: 0x78909c,
transparent: true,
opacity: 0.55
})
);
scene.add(referenceLine);
if (station.delta > 0) {
const arc = new THREE.Mesh(
new THREE.TorusGeometry(
1.08,
0.022,
10,
72,
THREE.MathUtils.degToRad(station.delta)
),
angleMaterial
);
arc.position.set(x, 0.25, 1.35);
scene.add(arc);
}
// Detector housing and luminous output screen.
addBox(1.35, 1.35, 0.55, detectorMaterial, x, 0.25, 4.25);
const detectorRing = new THREE.Mesh(
new THREE.TorusGeometry(0.53, 0.055, 12, 72),
filterRingMaterial
);
detectorRing.position.set(x, 0.25, 3.94);
scene.add(detectorRing);
const detectorScreen = new THREE.Mesh(
new THREE.CircleGeometry(0.46, 64),
new THREE.MeshBasicMaterial({
color: new THREE.Color(0x78e8ff).multiplyScalar(output * 2.1),
toneMapped: false
})
);
detectorScreen.position.set(x, 0.25, 3.91);
scene.add(detectorScreen);
// Physical beam segments.
createBeam(x, -3.84, -1.67, 1.0); // Before first polarizer: I0
createBeam(x, -1.62, 1.22, 0.5); // After first polarizer: I0/2
createBeam(x, 1.28, 3.88, output); // After analyzer: calculated Iout
// Scene labels.
makeTinyLabel("P", x + 1.2, -0.62, -1.65);
makeTinyLabel("A", x + 1.2, -0.62, 1.25);
const badge = makeBadge(
station.name,
station.delta,
output * 100
);
badge.position.set(x, 2.24, -0.1);
scene.add(badge);
});
// ------------------------------------------------------------
// UI camera actions
// ------------------------------------------------------------
document.getElementById("resetView").addEventListener("click", () => {
desired.target.set(0, 0.1, 0);
desired.radius = 27;
desired.theta = 0.53;
desired.phi = 1.04;
});
document.querySelectorAll("[data-focus]").forEach((button) => {
button.addEventListener("click", () => {
const index = Number(button.dataset.focus);
const station = stations[index];
desired.target.set(station.x, 0.1, 0);
desired.radius = 15.5;
desired.theta = 0.28;
desired.phi = 1.08;
});
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
current.target.lerp(
desired.target,
1 - Math.exp(-5.5 * dt)
);
current.radius = damp(
current.radius,
desired.radius,
5.5,
dt
);
current.theta = damp(
current.theta,
desired.theta,
6.5,
dt
);
current.phi = damp(
current.phi,
desired.phi,
6.5,
dt
);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x +
current.radius * sinPhi * Math.sin(current.theta),
current.target.y +
current.radius * Math.cos(current.phi),
current.target.z +
current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```