Prompt specification
Build or customize the Three.js 3D scene "Polarizer orientation frame pair" 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: Polarizer orientation frame pair
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/polarizer-orientation-frame-pair-x1565
Scene Description Prompt:
Use Three.js from cdnjs to build two transparent filter frames with marked transmission axes and a symbolic transverse field; distinguish polarization orientation from the ray's propagation direction. Deliver one self-contained HTML file with low-poly forms.
Working Three.js Starter (polarizer-orientation-frame-pair-x1565):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Polarization vs. Propagation</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(8, 18, 28, 0.82);
--border: rgba(164, 213, 235, 0.18);
--text: #e7f4fa;
--muted: #91a9b7;
--ray: #ff9f43;
--field: #ff4fd8;
--axis-a: #5cecff;
--axis-b: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #102b3b 0, #071018 58%, #04090e 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.title-panel,
.legend,
.controls,
.hint {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(440px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 16px;
pointer-events: none;
}
.kicker {
margin-bottom: 8px;
color: var(--axis-a);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.title-panel p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.distinction {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.distinction span {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 7px;
color: #c7dce7;
background: rgba(255, 255, 255, 0.035);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
}
.legend {
top: 22px;
right: 22px;
width: 275px;
padding: 15px 16px;
border-radius: 14px;
pointer-events: none;
}
.legend-title {
margin-bottom: 12px;
color: #d9edf7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 38px 1fr;
gap: 10px;
align-items: center;
margin-top: 10px;
}
.legend-row:first-of-type {
margin-top: 0;
}
.swatch {
position: relative;
display: block;
height: 2px;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.swatch.ray::after {
position: absolute;
top: -4px;
right: -1px;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 8px solid currentColor;
content: "";
}
.swatch.field {
color: var(--field);
transform: rotate(-28deg);
}
.swatch.field::after {
position: absolute;
top: -4px;
right: -1px;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 8px solid currentColor;
content: "";
}
.swatch.axis {
color: var(--axis-a);
transform: rotate(90deg);
}
.swatch.axis::before,
.swatch.axis::after {
position: absolute;
top: -3px;
width: 0;
height: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
content: "";
}
.swatch.axis::before {
left: -1px;
border-right: 7px solid currentColor;
}
.swatch.axis::after {
right: -1px;
border-left: 7px solid currentColor;
}
.swatch.glass {
height: 12px;
border: 1px solid rgba(92, 236, 255, 0.7);
background: rgba(92, 236, 255, 0.1);
box-shadow: none;
transform: skewX(-12deg);
}
.legend-row strong {
display: block;
color: #e4f2f8;
font-size: 12px;
}
.legend-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.controls {
right: 22px;
bottom: 22px;
width: 275px;
padding: 13px;
border-radius: 14px;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 36px;
padding: 8px 10px;
border: 1px solid rgba(151, 211, 237, 0.22);
border-radius: 9px;
color: #dff4fb;
background: rgba(123, 207, 238, 0.07);
font: 700 11px/1.2 inherit;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(92, 236, 255, 0.55);
background: rgba(92, 236, 255, 0.12);
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--axis-a);
outline-offset: 2px;
}
.slider-row {
display: grid;
grid-template-columns: auto 1fr;
gap: 11px;
align-items: center;
margin-top: 12px;
}
.slider-row label {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
accent-color: var(--field);
cursor: pointer;
}
.hint {
left: 22px;
bottom: 22px;
padding: 9px 12px;
border-radius: 10px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: var(--axis-a);
background: var(--bg);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.title-panel p {
display: none;
}
.legend {
top: auto;
right: 12px;
bottom: 83px;
left: 12px;
width: auto;
padding: 11px 13px;
}
.legend-title {
margin-bottom: 7px;
}
.legend-row {
display: inline-grid;
width: 48%;
margin-top: 5px;
vertical-align: top;
}
.legend-row strong {
font-size: 10px;
}
.legend-row small {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 10px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="title-panel">
<div class="kicker">Optics / polarization geometry</div>
<h1>Polarization ≠ Propagation</h1>
<p>
The ray travels normal to both filter planes. The magenta electric
field remains transverse and aligns with each filter’s marked
transmission axis.
</p>
<div class="distinction">
<span>FILTER PLANE = XY</span>
<span>RAY k = +Z</span>
<span>E ⟂ k</span>
</div>
</header>
<aside class="legend">
<div class="legend-title">Read the symbols</div>
<div class="legend-row">
<span class="swatch ray" style="color: var(--ray)"></span>
<span>
<strong>Propagation direction</strong>
<small>Single orange arrow along the ray, +Z.</small>
</span>
</div>
<div class="legend-row">
<span class="swatch field"></span>
<span>
<strong>Electric field E</strong>
<small>Single magenta arrow; it flips as the field oscillates.</small>
</span>
</div>
<div class="legend-row">
<span class="swatch axis"></span>
<span>
<strong>Transmission axis</strong>
<small>Double-ended line: orientation, not travel direction.</small>
</span>
</div>
<div class="legend-row">
<span class="swatch glass"></span>
<span>
<strong>Transparent filter</strong>
<small>Low-poly glass panel in a physical frame.</small>
</span>
</div>
</aside>
<section class="controls" aria-label="Scene controls">
<div class="button-row">
<button id="pause" type="button" aria-pressed="false">Pause field</button>
<button id="guides" type="button" aria-pressed="true">Hide guides</button>
<button id="reset" type="button">Reset view</button>
<button id="toggleLabels" type="button" aria-pressed="true">Hide labels</button>
</div>
<div class="slider-row">
<label for="amplitude">Field size</label>
<input
id="amplitude"
type="range"
min="0.35"
max="1.35"
step="0.01"
value="1"
aria-label="Electric field amplitude"
>
</div>
</section>
<div class="hint">DRAG TO ORBIT · WHEEL / PINCH TO ZOOM</div>
<div id="loading">Building optical 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 stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.FogExp2(0x071018, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional polarization filter demonstration"
);
stage.appendChild(renderer.domElement);
const COLORS = {
ray: 0xff9f43,
field: 0xff4fd8,
axisA: 0x5cecff,
axisB: 0xffd166,
frame: 0x8da2b1,
bench: 0x13232e,
benchTop: 0x1b3040
};
const hemisphere = new THREE.HemisphereLight(0xb9edff, 0x071018, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(COLORS.axisA, 28, 14, 2);
cyanLight.position.set(-4, 2.8, -3.8);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(COLORS.axisB, 24, 13, 2);
amberLight.position.set(4, 1.5, 4.2);
scene.add(amberLight);
const labelGroup = new THREE.Group();
const guideGroup = new THREE.Group();
scene.add(labelGroup, guideGroup);
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
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 makeLabel(text, accent = "#5cecff", width = 2.6) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 1014, 182, 22);
ctx.fillStyle = "rgba(5, 13, 21, 0.90)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 23, 35, 10, 122, 5);
ctx.fill();
let fontSize = 58;
ctx.font = `700 ${fontSize}px system-ui, sans-serif`;
while (ctx.measureText(text).width > 900 && fontSize > 26) {
fontSize -= 2;
ctx.font = `700 ${fontSize}px system-ui, sans-serif`;
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#e8f7fd";
ctx.fillText(text, 530, 98);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 192 / 1024, 1);
sprite.renderOrder = 20;
labelGroup.add(sprite);
return sprite;
}
function makeDoubleAxis(color) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
toneMapped: false
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.027, 1.9, 8),
material
);
group.add(shaft);
const headGeometry = new THREE.ConeGeometry(0.11, 0.28, 8);
const top = new THREE.Mesh(headGeometry, material);
top.position.y = 1.09;
group.add(top);
const bottom = new THREE.Mesh(headGeometry, material);
bottom.position.y = -1.09;
bottom.rotation.z = Math.PI;
group.add(bottom);
const center = new THREE.Mesh(
new THREE.OctahedronGeometry(0.085, 0),
material
);
group.add(center);
return group;
}
function makeFieldArrow() {
const group = new THREE.Group();
const fieldMaterial = new THREE.MeshStandardMaterial({
color: COLORS.field,
emissive: COLORS.field,
emissiveIntensity: 0.38,
roughness: 0.28,
metalness: 0.05
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.036, 0.036, 0.76, 8),
fieldMaterial
);
shaft.position.y = 0.38;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.24, 8),
fieldMaterial
);
head.position.y = 0.88;
group.add(head);
const base = new THREE.Mesh(
new THREE.SphereGeometry(0.07, 8, 6),
new THREE.MeshBasicMaterial({
color: 0xffe8fb,
toneMapped: false
})
);
group.add(base);
return group;
}
const frameMaterial = new THREE.MeshStandardMaterial({
color: COLORS.frame,
metalness: 0.7,
roughness: 0.3
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x263b48,
metalness: 0.65,
roughness: 0.38
});
// Optical bench.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x08131c,
roughness: 0.9,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.53;
floor.receiveShadow = true;
scene.add(floor);
const benchBase = new THREE.Mesh(
new THREE.BoxGeometry(7.7, 0.34, 9.5),
new THREE.MeshStandardMaterial({
color: COLORS.bench,
roughness: 0.48,
metalness: 0.48
})
);
benchBase.position.y = -2.35;
benchBase.castShadow = true;
benchBase.receiveShadow = true;
scene.add(benchBase);
const benchTop = new THREE.Mesh(
new THREE.BoxGeometry(7.4, 0.07, 9.15),
new THREE.MeshStandardMaterial({
color: COLORS.benchTop,
roughness: 0.4,
metalness: 0.56
})
);
benchTop.position.y = -2.145;
benchTop.castShadow = true;
benchTop.receiveShadow = true;
scene.add(benchTop);
const grid = new THREE.GridHelper(7.3, 18, 0x2e7893, 0x1b4255);
grid.position.y = -2.102;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
function createFilter({
index,
z,
axisAngle,
accent,
accentCss,
glassColor
}) {
const group = new THREE.Group();
group.position.z = z;
scene.add(group);
const panelMaterial = new THREE.MeshPhysicalMaterial({
color: glassColor,
emissive: glassColor,
emissiveIntensity: 0.06,
transparent: true,
opacity: 0.12,
roughness: 0.12,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const panel = new THREE.Mesh(
new THREE.PlaneGeometry(2.68, 2.68),
panelMaterial
);
panel.renderOrder = 2;
group.add(panel);
const barDepth = 0.19;
const outer = 1.42;
const barWidth = 0.13;
const left = new THREE.Mesh(
new THREE.BoxGeometry(barWidth, 2.96, barDepth),
frameMaterial
);
left.position.x = -outer;
left.castShadow = true;
group.add(left);
const right = left.clone();
right.position.x = outer;
group.add(right);
const topBar = new THREE.Mesh(
new THREE.BoxGeometry(2.96, barWidth, barDepth),
frameMaterial
);
topBar.position.y = outer;
topBar.castShadow = true;
group.add(topBar);
const bottomBar = topBar.clone();
bottomBar.position.y = -outer;
group.add(bottomBar);
// Low-poly corner fasteners.
const screwGeometry = new THREE.CylinderGeometry(0.05, 0.05, 0.035, 8);
const screwMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.22,
metalness: 0.55,
roughness: 0.3
});
for (const x of [-outer, outer]) {
for (const y of [-outer, outer]) {
const screw = new THREE.Mesh(screwGeometry, screwMaterial);
screw.rotation.x = Math.PI / 2;
screw.position.set(x, y, 0.12);
group.add(screw);
}
}
// Stand and feet.
for (const x of [-1.05, 1.05]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.65, 0.18),
darkMetal
);
post.position.set(x, -1.80, 0);
post.castShadow = true;
group.add(post);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.09, 0.48),
darkMetal
);
foot.position.set(x, -2.105, 0);
foot.castShadow = true;
group.add(foot);
}
const axis = makeDoubleAxis(accent);
axis.position.z = 0.16;
axis.rotation.z = axisAngle - Math.PI / 2;
group.add(axis);
const filterLabel = makeLabel(
`FILTER ${String(index).padStart(2, "0")} · AXIS ${axisAngle}°`,
accentCss,
2.85
);
filterLabel.position.set(0, -1.83, 0.22);
const axisLabel = makeLabel("TRANSMISSION AXIS", accentCss, 2.05);
axisLabel.position.set(
index === 1 ? 1.68 : 1.55,
index === 1 ? 0.72 : 1.05,
0.23
);
return group;
}
createFilter({
index: 1,
z: -1.65,
axisAngle: 90,
accent: COLORS.axisA,
accentCss: "#5cecff",
glassColor: 0x67dcff
});
createFilter({
index: 2,
z: 1.65,
axisAngle: 45,
accent: COLORS.axisB,
accentCss: "#ffd166",
glassColor: 0xffc75f
});
// Propagation ray: a single orange arrow along +Z.
const rayGroup = new THREE.Group();
scene.add(rayGroup);
const rayGlow = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 9.25, 8),
new THREE.MeshBasicMaterial({
color: COLORS.ray,
transparent: true,
opacity: 0.16,
blending: THREE.AdditiveBlending,
depthWrite: false,
toneMapped: false
})
);
rayGlow.rotation.x = Math.PI / 2;
rayGroup.add(rayGlow);
const rayCore = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 9.25, 8),
new THREE.MeshBasicMaterial({
color: COLORS.ray,
toneMapped: false
})
);
rayCore.rotation.x = Math.PI / 2;
rayGroup.add(rayCore);
const rayHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.34, 8),
new THREE.MeshBasicMaterial({
color: COLORS.ray,
toneMapped: false
})
);
rayHead.rotation.x = Math.PI / 2;
rayHead.position.z = 4.47;
rayGroup.add(rayHead);
const rayLabel = makeLabel("k / PROPAGATION +Z", "#ff9f43", 2.75);
rayLabel.position.set(1.0, -0.62, 4.65);
// Small moving dashes reinforce propagation along +Z.
const pulseGeometry = new THREE.BoxGeometry(0.045, 0.045, 0.25);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xffbd73,
toneMapped: false
});
const pulses = [];
for (let i = 0; i < 5; i++) {
const pulse = new THREE.Mesh(pulseGeometry, pulseMaterial);
scene.add(pulse);
pulses.push(pulse);
}
// Symbolic transverse electric field.
const fields = [
{ z: -3.25, angle: 90, maxLength: 1.45 },
{ z: -0.05, angle: 90, maxLength: 1.45 },
{ z: 3.15, angle: 45, maxLength: 1.025 }
].map((data) => {
const group = makeFieldArrow();
group.position.set(0, 0, data.z);
scene.add(group);
return { ...data, group };
});
const fieldLabelA = makeLabel("E / TRANSVERSE", "#ff4fd8", 2.05);
fieldLabelA.position.set(-1.42, 0.83, -3.25);
const fieldLabelB = makeLabel("E / AFTER FILTER 01", "#ff4fd8", 2.55);
fieldLabelB.position.set(-1.47, 0.91, -0.05);
const fieldLabelC = makeLabel("E / AFTER FILTER 02", "#ff4fd8", 2.55);
fieldLabelC.position.set(1.05, 1.05, 3.15);
// Right-angle construction showing E perpendicular to k.
const rightAnglePoints = [
new THREE.Vector3(0.25, 0, -0.05),
new THREE.Vector3(0.25, 0.45, -0.05),
new THREE.Vector3(0.25, 0.45, 0.35),
new THREE.Vector3(0.25, 0, 0.35)
];
const rightAngleGeometry = new THREE.BufferGeometry().setFromPoints(
rightAnglePoints
);
const rightAngle = new THREE.Line(
rightAngleGeometry,
new THREE.LineDashedMaterial({
color: 0xb5d6e4,
dashSize: 0.07,
gapSize: 0.045,
transparent: true,
opacity: 0.75
})
);
rightAngle.computeLineDistances();
guideGroup.add(rightAngle);
const perpendicularLabel = makeLabel("E ⟂ k", "#b5d6e4", 1.15);
perpendicularLabel.position.set(0.65, 0.32, 0.15);
// Direct camera controls: no external controls addon.
const orbit = {
theta: 0.68,
phi: 1.12,
radius: 11.2,
target: new THREE.Vector3(0, -0.12, 0)
};
const initialOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
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;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.28,
Math.PI - 0.38
);
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
6.5,
18
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
orbit.radius = initialOrbit.radius;
updateCamera();
});
const pauseButton = document.getElementById("pause");
const guidesButton = document.getElementById("guides");
const resetButton = document.getElementById("reset");
const labelsButton = document.getElementById("toggleLabels");
const amplitudeInput = document.getElementById("amplitude");
let paused = false;
let amplitudeScale = 1;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume field" : "Pause field";
pauseButton.setAttribute("aria-pressed", String(paused));
});
guidesButton.addEventListener("click", () => {
guideGroup.visible = !guideGroup.visible;
guidesButton.textContent = guideGroup.visible ? "Hide guides" : "Show guides";
guidesButton.setAttribute("aria-pressed", String(guideGroup.visible));
});
resetButton.addEventListener("click", () => {
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
orbit.radius = initialOrbit.radius;
updateCamera();
});
labelsButton.addEventListener("click", () => {
labelGroup.visible = !labelGroup.visible;
labelsButton.textContent = labelGroup.visible ? "Hide labels" : "Show labels";
labelsButton.setAttribute("aria-pressed", String(labelGroup.visible));
});
amplitudeInput.addEventListener("input", () => {
amplitudeScale = Number(amplitudeInput.value);
});
function updateFields(elapsed) {
const phase = Math.sin(elapsed * 2.35);
for (const field of fields) {
const signedLength = phase * field.maxLength * amplitudeScale;
const direction = signedLength < 0 ? 1 : 0;
field.group.rotation.z =
field.angle - Math.PI / 2 + direction * Math.PI;
field.group.scale.y = Math.max(0.045, Math.abs(signedLength));
}
pulses.forEach((pulse, index) => {
const z = ((elapsed * 1.35 + index * 2.05) % 9.1) - 4.55;
pulse.position.set(0, 0, z);
const pulsePhase = (elapsed * 2.2 + index) % (Math.PI * 2);
pulse.scale.y = 0.7 + 0.3 * Math.cos(pulsePhase);
});
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
let elapsed = 0;
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
elapsed += dt;
}
updateFields(elapsed);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateFields(0);
renderer.render(scene, camera);
loading.remove();
requestAnimationFrame(animate);
</script>
</body>
</html>
```