Prompt specification
Build or customize the Three.js 3D scene "Two-lens telescope ray model" 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: Two-lens telescope ray model
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-lens-telescope-ray-model-x1593
Scene Description Prompt:
Build a simplified objective and eyepiece on an optical axis with rays from a distant target; state the paraxial approximation and distinguish aperture from magnification. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (two-lens-telescope-ray-model-x1593):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paraxial Telescope — Objective and Eyepiece</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 18, 32, 0.88);
--border: rgba(120, 190, 235, 0.25);
--text: #e9f4ff;
--muted: #9eb3c8;
--cyan: #73dcff;
--gold: #ffd166;
--green: #62f6c5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
color: var(--text);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: absolute;
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 20px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(15px);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}
.kicker {
margin-bottom: 5px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0 0 8px;
font-size: 25px;
line-height: 1.12;
}
p {
margin: 0 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
display: grid;
gap: 12px;
margin: 17px 0;
}
.control label {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 6px;
color: var(--text);
font-size: 12px;
font-weight: 650;
}
.control output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--cyan);
}
.metrics {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
margin: 15px 0;
}
.metric {
padding: 10px;
border: 1px solid rgba(120, 190, 235, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.metric span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric strong {
font-size: 17px;
font-variant-numeric: tabular-nums;
}
.note {
margin: 12px 0;
padding: 11px 12px;
border-left: 3px solid var(--gold);
border-radius: 0 8px 8px 0;
background: rgba(255, 209, 102, 0.07);
color: #d9e4ed;
font-size: 12px;
line-height: 1.48;
}
.note strong {
color: var(--gold);
}
details {
margin-top: 12px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
summary {
cursor: pointer;
color: var(--text);
font-weight: 700;
}
details p {
margin: 9px 0 0;
font-size: 12px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 14px;
color: var(--muted);
font-size: 11px;
}
.legend span::before {
display: inline-block;
width: 16px;
height: 3px;
margin-right: 5px;
vertical-align: middle;
border-radius: 2px;
background: var(--color);
content: "";
}
.camera-help {
position: absolute;
right: 16px;
bottom: 14px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(7, 17, 31, 0.72);
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
.reset {
width: 100%;
margin-top: 13px;
padding: 9px 12px;
border: 1px solid rgba(115, 220, 255, 0.35);
border-radius: 9px;
background: rgba(115, 220, 255, 0.08);
color: var(--cyan);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
.reset:hover {
background: rgba(115, 220, 255, 0.15);
}
@media (max-width: 700px) {
.panel {
top: 10px;
left: 10px;
width: min(350px, calc(100vw - 20px));
max-height: 62vh;
padding: 15px;
}
h1 {
font-size: 21px;
}
.camera-help {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D telescope ray diagram"></canvas>
<section class="panel">
<div class="kicker">Geometrical Optics</div>
<h1>Objective + eyepiece</h1>
<p>
A distant target supplies nearly parallel rays. The objective creates a
real inverted intermediate image; the eyepiece turns that image into a
collimated bundle for the observer.
</p>
<div class="controls">
<div class="control">
<label for="objectiveFocal">
Objective focal length f<sub>o</sub>
<output id="objectiveFocalValue"></output>
</label>
<input id="objectiveFocal" type="range" min="2.8" max="4.2" step="0.05" value="3.4">
</div>
<div class="control">
<label for="eyepieceFocal">
Eyepiece focal length f<sub>e</sub>
<output id="eyepieceFocalValue"></output>
</label>
<input id="eyepieceFocal" type="range" min="0.8" max="1.4" step="0.05" value="1.1">
</div>
<div class="control">
<label for="aperture">
Objective aperture diameter D
<output id="apertureValue"></output>
</label>
<input id="aperture" type="range" min="2.4" max="5.2" step="0.1" value="4.6">
</div>
<div class="control">
<label for="targetAngle">
Target elevation
<output id="targetAngleValue"></output>
</label>
<input id="targetAngle" type="range" min="0" max="4" step="0.1" value="2.6">
</div>
</div>
<div class="metrics">
<div class="metric">
<span>Angular magnification</span>
<strong id="magnificationValue"></strong>
</div>
<div class="metric">
<span>Approx. objective NA</span>
<strong id="naValue"></strong>
</div>
<div class="metric">
<span>Lens separation</span>
<strong id="separationValue"></strong>
</div>
<div class="metric">
<span>Output direction</span>
<strong id="outputAngleValue"></strong>
</div>
</div>
<div class="note">
<strong>Aperture is not magnification.</strong>
The aperture D controls how much of the ray cone is admitted, light
gathering (approximately proportional to D²), and diffraction-limited
resolution (approximately proportional to 1/D). Magnification is set
by the focal-length ratio, M = −f<sub>o</sub>/f<sub>e</sub>.
</div>
<details open>
<summary>Paraxial approximation</summary>
<p>
Both lenses are treated as thin lenses. Small ray angles use
tan θ ≈ θ, and spherical/chromatic aberrations, vignetting, and
finite lens thickness are neglected. For an afocal telescope,
d = f<sub>o</sub> + f<sub>e</sub>, so the objective's real focal plane
coincides with the eyepiece's front focal plane.
</p>
</details>
<div class="legend">
<span style="--color:#ffd166">Incoming parallel rays</span>
<span style="--color:#ff9f43">Inside telescope</span>
<span style="--color:#62f6c5">Collimated output</span>
</div>
<button class="reset" id="resetCamera">Reset camera</button>
</section>
<div class="camera-help">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const state = {
objectiveFocal: 3.4,
eyepieceFocal: 1.1,
aperture: 4.6,
targetAngle: 2.6
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 22, 43);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
scene.add(new THREE.HemisphereLight(0xa8dcff, 0x111827, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.2);
keyLight.position.set(-5, 9, 12);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3bbcff, 1.2);
rimLight.position.set(8, 2, -7);
scene.add(rimLight);
const grid = new THREE.GridHelper(30, 30, 0x26445f, 0x172b40);
grid.position.y = -3.4;
grid.material.transparent = true;
grid.material.opacity = 0.3;
grid.material.depthWrite = false;
scene.add(grid);
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-12.3, 0, 0),
new THREE.Vector3(9.2, 0, 0)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x6f91ad,
dashSize: 0.22,
gapSize: 0.14,
transparent: true,
opacity: 0.65
})
);
axis.computeLineDistances();
scene.add(axis);
const opticGroup = new THREE.Group();
const dynamicGroup = new THREE.Group();
const rayGroup = new THREE.Group();
const labelGroup = new THREE.Group();
scene.add(opticGroup, dynamicGroup, rayGroup, labelGroup);
const glassMaterial = new THREE.MeshPhongMaterial({
color: 0x70d8ff,
transparent: true,
opacity: 0.3,
shininess: 120,
side: THREE.DoubleSide,
depthWrite: false
});
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0x334c60,
metalness: 0.72,
roughness: 0.28
});
const housingMaterial = new THREE.MeshStandardMaterial({
color: 0x101a27,
metalness: 0.62,
roughness: 0.35
});
const targetMaterial = new THREE.MeshStandardMaterial({
color: 0xffad42,
emissive: 0xa43c00,
emissiveIntensity: 1.6,
roughness: 0.4
});
const imageMaterial = new THREE.MeshBasicMaterial({
color: 0xff7b4d,
toneMapped: false
});
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x172637,
metalness: 0.25,
roughness: 0.58
});
const irisMaterial = new THREE.MeshBasicMaterial({
color: 0x62f6c5,
transparent: true,
opacity: 0.28,
side: THREE.DoubleSide,
depthWrite: false
});
const pupilMaterial = new THREE.MeshBasicMaterial({
color: 0x02070d,
side: THREE.DoubleSide
});
const incomingMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
toneMapped: false
});
const internalMaterial = new THREE.MeshBasicMaterial({
color: 0xff9f43,
toneMapped: false
});
const outputMaterial = new THREE.MeshBasicMaterial({
color: 0x62f6c5,
toneMapped: false
});
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const TARGET_X = -11.2;
function disposeChildren(group) {
for (const child of [...group.children]) {
group.remove(child);
if (child.geometry) {
child.geometry.dispose();
}
if (child.isSprite) {
if (child.material.map) child.material.map.dispose();
child.material.dispose();
}
}
}
function addTorus(group, radius, tube, x, material, segments = 28) {
const geometry = new THREE.TorusGeometry(radius, tube, 6, segments);
geometry.rotateY(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.x = x;
group.add(mesh);
return mesh;
}
function createLens(radius, thickness, isEyepiece = false) {
const group = new THREE.Group();
const diskGeometry = new THREE.CylinderGeometry(
radius,
radius,
thickness,
24,
1,
false
);
diskGeometry.rotateZ(Math.PI / 2);
const disk = new THREE.Mesh(diskGeometry, glassMaterial);
disk.renderOrder = 2;
group.add(disk);
addTorus(group, radius, 0.055, -thickness * 0.5, rimMaterial);
addTorus(group, radius, 0.055, thickness * 0.5, rimMaterial);
if (isEyepiece) {
addTorus(group, radius + 0.10, 0.12, 0.22, housingMaterial);
addTorus(group, radius + 0.10, 0.12, 0.52, housingMaterial);
} else {
addTorus(group, radius + 0.12, 0.10, -0.19, housingMaterial);
addTorus(group, radius + 0.12, 0.10, 0.19, housingMaterial);
}
return group;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(title, subtitle = "", accent = "#73dcff") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 180;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 640, 180);
roundedRect(ctx, 4, 4, 632, 172, 24);
ctx.fillStyle = "rgba(5, 14, 25, 0.88)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 4;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = accent;
ctx.font = "700 36px system-ui, sans-serif";
ctx.fillText(title, 320, subtitle ? 66 : 90);
if (subtitle) {
ctx.fillStyle = "#d8e7f3";
ctx.font = "500 25px system-ui, sans-serif";
ctx.fillText(subtitle, 320, 124);
}
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(3.55, 1.0, 1);
sprite.renderOrder = 20;
return sprite;
}
function addBeamSegment(group, a, b, material, radius = 0.015) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
if (length < 1e-6) return;
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
6,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
group.add(mesh);
}
// Distant target marker.
const targetGroup = new THREE.Group();
const targetDiamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.43, 0),
targetMaterial
);
targetGroup.add(targetDiamond);
addTorus(targetGroup, 0.72, 0.045, 0, targetMaterial, 20);
scene.add(targetGroup);
function updateModel() {
disposeChildren(opticGroup);
disposeChildren(dynamicGroup);
disposeChildren(rayGroup);
disposeChildren(labelGroup);
const fo = state.objectiveFocal;
const fe = state.eyepieceFocal;
const diameter = state.aperture;
const objectiveRadius = diameter / 2;
const eyepieceX = fo + fe;
const targetAngle = THREE.MathUtils.degToRad(state.targetAngle);
// The target is above the optical axis. Light propagating toward +x
// therefore has a negative transverse slope.
const inputSlope = -Math.tan(targetAngle);
const inputDirection = new THREE.Vector2(inputSlope, 0);
const objective = createLens(objectiveRadius, 0.17, false);
opticGroup.add(objective);
const eyepiece = createLens(1.45, 0.13, true);
eyepiece.position.x = eyepieceX;
opticGroup.add(eyepiece);
targetGroup.position.set(
TARGET_X,
inputSlope * TARGET_X,
0
);
// Transverse ray samples across the circular objective aperture.
const samples = [{ y: 0, z: 0, center: true }];
const sampledRadius = objectiveRadius * 0.80;
for (let i = 0; i < 8; i++) {
const angle = i * Math.PI / 4 + Math.PI / 8;
samples.push({
y: sampledRadius * Math.cos(angle),
z: sampledRadius * Math.sin(angle),
center: false
});
}
const imagePoint = new THREE.Vector2(
fo * inputDirection.x,
fo * inputDirection.y
);
const outputDirection = new THREE.Vector2(
-(fo / fe) * inputDirection.x,
-(fo / fe) * inputDirection.y
);
let centralEyePoint = null;
for (const sample of samples) {
const p0 = new THREE.Vector2(sample.y, sample.z);
const incomingStart = new THREE.Vector2(
sample.y + inputDirection.x * TARGET_X,
sample.z + inputDirection.y * TARGET_X
);
// Thin-lens ray transfer: u_out = u_in - y/f.
const afterObjectiveSlope = new THREE.Vector2(
inputDirection.x - p0.x / fo,
inputDirection.y - p0.y / fo
);
const atEyepiece = new THREE.Vector2(
imagePoint.x + fe * afterObjectiveSlope.x,
imagePoint.y + fe * afterObjectiveSlope.y
);
const outputEnd = new THREE.Vector2(
atEyepiece.x + outputDirection.x * (8.34 - eyepieceX),
atEyepiece.y + outputDirection.y * (8.34 - eyepieceX)
);
const incomingRadius = sample.center ? 0.023 : 0.014;
const internalRadius = sample.center ? 0.022 : 0.013;
const outputRadius = sample.center ? 0.023 : 0.014;
addBeamSegment(
rayGroup,
new THREE.Vector3(TARGET_X, incomingStart.x, incomingStart.y),
new THREE.Vector3(0, p0.x, p0.y),
incomingMaterial,
incomingRadius
);
addBeamSegment(
rayGroup,
new THREE.Vector3(0, p0.x, p0.y),
new THREE.Vector3(fo, imagePoint.x, imagePoint.y),
internalMaterial,
internalRadius
);
addBeamSegment(
rayGroup,
new THREE.Vector3(fo, imagePoint.x, imagePoint.y),
new THREE.Vector3(eyepieceX, atEyepiece.x, atEyepiece.y),
internalMaterial,
internalRadius
);
addBeamSegment(
rayGroup,
new THREE.Vector3(eyepieceX, atEyepiece.x, atEyepiece.y),
new THREE.Vector3(8.34, outputEnd.x, outputEnd.y),
outputMaterial,
outputRadius
);
if (sample.center) {
centralEyePoint = atEyepiece.clone();
}
}
// Real intermediate image at the shared focal plane.
const imageMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 10, 8),
imageMaterial
);
imageMarker.position.set(fo, imagePoint.x, imagePoint.y);
dynamicGroup.add(imageMarker);
// A simple low-poly observer's eye aligned with the central output ray.
if (centralEyePoint) {
const eye = new THREE.Group();
const eyeX = 7.95;
const eyeY =
centralEyePoint.x +
outputDirection.x * (eyeX - eyepieceX);
const socket = new THREE.Mesh(
new THREE.SphereGeometry(1, 12, 8),
eyeMaterial
);
socket.scale.set(0.42, 0.62, 0.78);
eye.add(socket);
const iris = new THREE.Mesh(
new THREE.CircleGeometry(0.72, 20),
irisMaterial
);
iris.rotation.y = Math.PI / 2;
iris.position.x = 0.36;
eye.add(iris);
const pupil = new THREE.Mesh(
new THREE.CircleGeometry(0.24, 16),
pupilMaterial
);
pupil.rotation.y = Math.PI / 2;
pupil.position.x = 0.375;
eye.add(pupil);
eye.position.set(eyeX, eyeY, 0);
eye.rotation.z = Math.atan(outputDirection.x);
dynamicGroup.add(eye);
}
// Labels.
const objectiveLabel = makeLabel(
"OBJECTIVE",
`f_o = ${fo.toFixed(2)} · D = ${diameter.toFixed(2)}`,
"#73dcff"
);
objectiveLabel.position.set(-0.2, objectiveRadius + 1.05, 0);
labelGroup.add(objectiveLabel);
const eyepieceLabel = makeLabel(
"EYEPIECE",
`f_e = ${fe.toFixed(2)}`,
"#73dcff"
);
eyepieceLabel.position.set(eyepieceX, 2.25, 0);
labelGroup.add(eyepieceLabel);
const imageLabel = makeLabel(
"REAL INVERTED IMAGE",
"shared focal plane",
"#ff9f43"
);
imageLabel.position.set(fo, -1.05, 0);
imageLabel.scale.set(3.65, 1.03, 1);
labelGroup.add(imageLabel);
const targetLabel = makeLabel(
"DISTANT TARGET",
`parallel input · ${state.targetAngle.toFixed(1)}° elevation`,
"#ffd166"
);
targetLabel.position.set(TARGET_X, targetGroup.position.y + 1.25, 0);
labelGroup.add(targetLabel);
const observerLabel = makeLabel(
"OBSERVER",
"collimated output bundle",
"#62f6c5"
);
observerLabel.position.set(8.0, 1.35, 0);
labelGroup.add(observerLabel);
updateReadouts();
}
function updateReadouts() {
const fo = state.objectiveFocal;
const fe = state.eyepieceFocal;
const diameter = state.aperture;
const magnification = -fo / fe;
const numericalAperture = diameter / (2 * fo);
const outputAngle = Math.atan(-(fo / fe) * -Math.tan(
THREE.MathUtils.degToRad(state.targetAngle)
));
document.querySelector("#objectiveFocalValue").textContent =
`${fo.toFixed(2)} units`;
document.querySelector("#eyepieceFocalValue").textContent =
`${fe.toFixed(2)} units`;
document.querySelector("#apertureValue").textContent =
`${diameter.toFixed(2)} units`;
document.querySelector("#targetAngleValue").textContent =
`${state.targetAngle.toFixed(1)}°`;
document.querySelector("#magnificationValue").textContent =
`${magnification.toFixed(2)}×`;
document.querySelector("#naValue").textContent =
numericalAperture.toFixed(2);
document.querySelector("#separationValue").textContent =
`${(fo + fe).toFixed(2)} units`;
document.querySelector("#outputAngleValue").textContent =
`${THREE.MathUtils.radToDeg(outputAngle).toFixed(1)}°`;
}
// Direct camera controls: no examples/addons modules are used.
const cameraTarget = new THREE.Vector3(-1.8, 0.15, 0);
let yaw = 0.13;
let pitch = 0.20;
let cameraRadius = 19.5;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const responsiveScale = innerWidth / innerHeight < 1 ? 1.35 : 1;
const radius = cameraRadius * responsiveScale;
const cosPitch = Math.cos(pitch);
camera.position.set(
cameraTarget.x + Math.sin(yaw) * cosPitch * radius,
cameraTarget.y + Math.sin(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * cosPitch * radius
);
camera.lookAt(cameraTarget);
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, -0.55, 0.85);
updateCamera();
});
canvas.addEventListener("pointerup", event => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
10,
29
);
updateCamera();
}, { passive: false });
document.querySelector("#resetCamera").addEventListener("click", () => {
yaw = 0.13;
pitch = 0.20;
cameraRadius = 19.5;
updateCamera();
});
const bindings = [
["objectiveFocal", "objectiveFocal"],
["eyepieceFocal", "eyepieceFocal"],
["aperture", "aperture"],
["targetAngle", "targetAngle"]
];
for (const [id, key] of bindings) {
document.querySelector(`#${id}`).addEventListener("input", event => {
state[key] = Number(event.target.value);
updateModel();
});
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
updateCamera();
}
addEventListener("resize", resize);
updateModel();
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```