Prompt specification
Build or customize the Three.js 3D scene "Telescope parameter exploration bench" 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: Telescope parameter exploration bench
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/telescope-parameter-exploration-bench-x1596
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts telescope optics, aperture, and magnification. Allow objective and eyepiece focal-length changes within a simple model; calculate magnification and show image orientation while labeling diffraction and aberrations as omitted or separately illustrated. Voxel style.
Working Three.js Starter (telescope-parameter-exploration-bench-x1596):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Telescope Optics</title>
<style>
:root {
--bg: #07131d;
--panel: rgba(9, 25, 36, 0.88);
--panel-border: rgba(88, 218, 207, 0.28);
--text: #e7fbf8;
--muted: #91b3b5;
--cyan: #65e8ff;
--mint: #44e0bd;
--gold: #ffd166;
--red: #ff6b72;
}
* {
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;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.32),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
backdrop-filter: blur(12px);
}
#titleCard {
top: 18px;
left: 50%;
width: min(510px, calc(100vw - 36px));
padding: 14px 18px;
transform: translateX(-50%);
text-align: center;
border-radius: 12px;
}
.eyebrow {
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 4px 0 5px;
font-size: clamp(20px, 2.4vw, 31px);
line-height: 1.05;
}
#titleCard p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#controls {
top: 18px;
left: 18px;
width: 330px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 16px;
border-radius: 12px;
scrollbar-width: thin;
scrollbar-color: #28535b transparent;
}
#notes {
right: 18px;
bottom: 18px;
width: 330px;
padding: 15px;
border-radius: 12px;
}
h2 {
margin: 0 0 12px;
font-size: 13px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.control {
margin-bottom: 15px;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
font-size: 12px;
}
.control-head label {
color: #cce6e4;
font-weight: 650;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-weight: 750;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 5px 0 0;
appearance: none;
border-radius: 0;
background: linear-gradient(
90deg,
var(--mint) 0%,
var(--mint) var(--fill, 50%),
#173945 var(--fill, 50%),
#173945 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 18px;
appearance: none;
border: 2px solid #07131d;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 16px;
border: 2px solid #07131d;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan);
}
.formula {
padding: 10px;
margin: 4px 0 12px;
border-left: 3px solid var(--mint);
background: rgba(68, 224, 189, 0.07);
color: #c8ece8;
font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.readout {
min-height: 65px;
padding: 9px;
border: 1px solid rgba(101, 232, 255, 0.14);
background: rgba(255, 255, 255, 0.025);
}
.readout span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.readout strong {
display: block;
color: var(--text);
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.readout strong.orientation {
color: var(--red);
font-size: 14px;
line-height: 1.25;
}
.view-row {
display: flex;
align-items: center;
gap: 13px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.eyepiece-view {
position: relative;
flex: 0 0 78px;
height: 78px;
display: grid;
place-items: center;
overflow: hidden;
border: 2px solid #34717a;
border-radius: 50%;
background:
linear-gradient(rgba(101, 232, 255, 0.08) 1px, transparent 1px),
linear-gradient(90deg, rgba(101, 232, 255, 0.08) 1px, transparent 1px),
#061017;
background-size: 12px 12px;
box-shadow: inset 0 0 20px #000;
}
#miniArrow {
color: var(--red);
font: 700 54px/1 ui-monospace, monospace;
transform-origin: 50% 50%;
transition: transform 180ms ease;
}
.view-copy strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
}
.view-copy span {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 13px;
}
button {
flex: 1;
padding: 9px 8px;
border: 1px solid rgba(101, 232, 255, 0.25);
border-radius: 5px;
background: rgba(101, 232, 255, 0.08);
color: var(--text);
font: 700 10px/1.2 inherit;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
border-color: var(--cyan);
background: rgba(101, 232, 255, 0.15);
}
.hint {
margin: 11px 0 0;
color: #76999d;
font-size: 10px;
line-height: 1.45;
}
.idealization {
display: grid;
grid-template-columns: auto 1fr;
gap: 7px 10px;
padding: 10px 0;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.idealization:first-of-type {
border-top: 0;
padding-top: 0;
}
.idealization b {
align-self: start;
color: #d5eeee;
font-size: 11px;
}
.idealization p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.status {
display: inline-block;
margin-top: 4px;
padding: 2px 5px;
border: 1px solid rgba(255, 209, 102, 0.35);
color: var(--gold);
background: rgba(255, 209, 102, 0.08);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
padding: 5px 7px;
transform: translate(-50%, -100%);
border: 1px solid rgba(101, 232, 255, 0.32);
background: rgba(5, 17, 25, 0.83);
color: #dffafa;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.025em;
white-space: nowrap;
}
.scene-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
background: rgba(101, 232, 255, 0.48);
}
.scene-label.gold {
border-color: rgba(255, 209, 102, 0.38);
}
.scene-label.gold::after {
background: rgba(255, 209, 102, 0.5);
}
.scene-label.red {
border-color: rgba(255, 107, 114, 0.4);
}
.scene-label.red::after {
background: rgba(255, 107, 114, 0.5);
}
@media (max-width: 900px) {
#titleCard {
top: 10px;
}
#titleCard p {
display: none;
}
#controls {
top: auto;
bottom: 10px;
left: 10px;
width: min(310px, calc(100vw - 20px));
max-height: 48vh;
}
#notes {
right: 10px;
bottom: 10px;
width: min(280px, calc(100vw - 20px));
}
.scene-label {
display: none !important;
}
}
@media (max-width: 640px) {
#notes {
display: none;
}
#controls {
max-height: 52vh;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels" aria-hidden="true">
<div class="scene-label" id="labelObjective">Objective lens</div>
<div class="scene-label gold" id="labelAperture">Adjustable aperture</div>
<div class="scene-label red" id="labelImage">Inverted intermediate image</div>
<div class="scene-label" id="labelEyepiece">Positive eyepiece</div>
<div class="scene-label gold" id="labelObject">Upright distant object</div>
<div class="scene-label" id="labelFocal">fₒ</div>
<div class="scene-label gold" id="labelIncoming">Parallel input</div>
<div class="scene-label" id="labelOutgoing">Parallel output</div>
</div>
<header id="titleCard" class="panel">
<div class="eyebrow">Voxel Optics Laboratory</div>
<h1>Telescope Aperture & Magnification</h1>
<p>
Idealized Keplerian refractor · geometric ray model ·
drag to orbit and scroll to zoom
</p>
</header>
<section id="controls" class="panel">
<h2>Optical Parameters</h2>
<div class="control">
<div class="control-head">
<label for="fo">Objective focal length, fₒ</label>
<output id="foOut" for="fo">1000 mm</output>
</div>
<input id="fo" type="range" min="400" max="2000" step="25" value="1000">
</div>
<div class="control">
<div class="control-head">
<label for="fe">Eyepiece focal length, fₑ</label>
<output id="feOut" for="fe">25 mm</output>
</div>
<input id="fe" type="range" min="5" max="40" step="1" value="25">
</div>
<div class="control">
<div class="control-head">
<label for="aperture">Objective aperture</label>
<output id="apertureOut" for="aperture">120 mm</output>
</div>
<input id="aperture" type="range" min="40" max="200" step="5" value="120">
</div>
<div class="formula" id="formula">
M = −fₒ / fₑ = −1000 / 25 = −40.0×
</div>
<div class="readouts">
<div class="readout">
<span>Magnification</span>
<strong id="magReadout">40.0×</strong>
</div>
<div class="readout">
<span>Image orientation</span>
<strong class="orientation" id="orientationReadout">INVERTED</strong>
</div>
<div class="readout">
<span>Exit pupil</span>
<strong id="pupilReadout">3.0 mm</strong>
</div>
<div class="readout">
<span>Focal ratio</span>
<strong id="fRatioReadout">f/8.3</strong>
</div>
</div>
<div class="view-row">
<div class="eyepiece-view">
<div id="miniArrow">↑</div>
</div>
<div class="view-copy">
<strong>View through eyepiece</strong>
<span>
A positive eyepiece views the inverted real image formed by the
objective. Final image is at infinity.
</span>
</div>
</div>
<div class="buttons">
<button id="resetOptics" type="button">Reset optics</button>
<button id="resetView" type="button">Reset view</button>
</div>
<p class="hint">
The optical layout is schematic and not to scale. The square aperture is
a voxel-style representation of a conventional circular aperture.
</p>
</section>
<aside id="notes" class="panel">
<h2>Model Boundaries</h2>
<div class="idealization">
<b>Diffraction</b>
<p>
Omitted from the main ray model. No Airy disk, point-spread function,
or diffraction-limited resolution is calculated.
</p>
<span class="status">SEPARATELY ILLUSTRATED</span>
</div>
<div class="idealization">
<b>Aberrations</b>
<p>
Omitted. Rays are treated as ideal paraxial rays, with no spherical,
chromatic, coma, astigmatism, or field curvature.
</p>
<span class="status">SEPARATELY ILLUSTRATED</span>
</div>
</aside>
<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);
const stage = $("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 15, 35);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D telescope. Drag to orbit, scroll to zoom, and use arrow keys when focused."
);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(-0.75, -0.05, 0);
let cameraRadius = 10.8;
let cameraTheta = 0.34;
let cameraPhi = 1.18;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0x8ceeff, 0x10202a, 1.8));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3de5d2, 2.2);
rimLight.position.set(-5, 2, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffc55a, 24, 12, 2);
warmLight.position.set(-5, 1.5, 3);
scene.add(warmLight);
// Materials
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x174b5d,
roughness: 0.72,
metalness: 0.18
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x102b37,
roughness: 0.82,
metalness: 0.12
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0x2ccbb3,
roughness: 0.48,
metalness: 0.38
});
const silverMaterial = new THREE.MeshStandardMaterial({
color: 0x9bb9bd,
roughness: 0.45,
metalness: 0.62
});
const lensMaterial = new THREE.MeshStandardMaterial({
color: 0x67e7ff,
emissive: 0x0d4654,
emissiveIntensity: 0.6,
transparent: true,
opacity: 0.38,
roughness: 0.12,
metalness: 0.06,
depthWrite: false
});
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0x4b9eaa,
transparent: true,
opacity: 0.13,
roughness: 0.28,
metalness: 0.05,
depthWrite: false
});
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xff6670,
emissive: 0x5d111a,
emissiveIntensity: 0.55,
roughness: 0.62
});
const objectArrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x5b3b08,
emissiveIntensity: 0.45,
roughness: 0.62
});
const goldRayMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166
});
const cyanRayMaterial = new THREE.MeshBasicMaterial({
color: 0x65e8ff
});
const greenRayMaterial = new THREE.MeshBasicMaterial({
color: 0x63f0bd
});
const rayLineMaterial = new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.88
});
const rayMarkerGeometry = new THREE.BoxGeometry(0.052, 0.052, 0.052);
function addBox(parent, width, height, depth, material, x = 0, y = 0, z = 0) {
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 addFrame(
parent,
depth,
outer,
hole,
thickness,
material
) {
const group = new THREE.Group();
addBox(
group,
depth,
thickness,
outer,
material,
0,
(hole + thickness) / 2,
0
);
addBox(
group,
depth,
thickness,
outer,
material,
0,
-(hole + thickness) / 2,
0
);
addBox(
group,
depth,
hole,
thickness,
material,
0,
0,
(hole + thickness) / 2
);
addBox(
group,
depth,
hole,
thickness,
material,
0,
0,
-(hole + thickness) / 2
);
parent.add(group);
return group;
}
// Floor and voxel star field
const ground = addBox(
scene,
28,
0.12,
24,
new THREE.MeshStandardMaterial({
color: 0x091923,
roughness: 0.98
}),
0,
-2.24,
0
);
ground.castShadow = false;
const grid = new THREE.GridHelper(26, 26, 0x246271, 0x123540);
grid.position.y = -2.17;
scene.add(grid);
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(8421);
const starGeometry = new THREE.BoxGeometry(1, 1, 1);
const starMaterials = [
new THREE.MeshBasicMaterial({ color: 0x6cddeb }),
new THREE.MeshBasicMaterial({ color: 0xb2f6ec }),
new THREE.MeshBasicMaterial({ color: 0xffe4a3 })
];
for (let i = 0; i < 180; i++) {
const radius = 12 + random() * 19;
const theta = random() * Math.PI * 2;
const phi = Math.acos(2 * random() - 1);
const size = 0.025 + random() * 0.065;
const star = new THREE.Mesh(
starGeometry,
starMaterials[i % starMaterials.length]
);
star.position.set(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
star.scale.setScalar(size);
scene.add(star);
}
// Telescope assembly
const telescope = new THREE.Group();
scene.add(telescope);
const objectiveX = -3.5;
const objectiveGroup = new THREE.Group();
objectiveGroup.position.x = objectiveX;
telescope.add(objectiveGroup);
addFrame(objectiveGroup, 0.34, 1.35, 1.02, 0.165, darkMaterial);
addFrame(objectiveGroup, 0.13, 1.4, 1.04, 0.18, trimMaterial);
addBox(objectiveGroup, 0.09, 1.0, 1.0, lensMaterial, -0.035, 0, 0);
// Four square voxel blades form the adjustable aperture.
const bladeTop = addBox(
objectiveGroup, 0.08, 0.38, 1.05, silverMaterial, -0.25, 0, 0
);
const bladeBottom = addBox(
objectiveGroup, 0.08, 0.38, 1.05, silverMaterial, -0.25, 0, 0
);
const bladeLeft = addBox(
objectiveGroup, 0.08, 1, 0.32, silverMaterial, -0.25, 0, 0
);
const bladeRight = addBox(
objectiveGroup, 0.08, 1, 0.32, silverMaterial, -0.25, 0, 0
);
// Main tube; its length changes with the selected optics.
const tubeShell = addBox(scene, 1, 0.72, 0.72, shellMaterial);
const bottomRail = addBox(scene, 1, 0.12, 0.78, bodyMaterial);
const topRail = addBox(scene, 1, 0.09, 0.18, trimMaterial);
const tubeRibs = [];
for (let i = 0; i < 6; i++) {
const rib = addFrame(scene, 0.12, 0.86, 0.7, 0.08, bodyMaterial);
tubeRibs.push(rib);
}
// Finder scope
const finder = new THREE.Group();
finder.position.set(objectiveX + 1.35, 0.58, -0.08);
telescope.add(finder);
addBox(finder, 1.45, 0.2, 0.24, darkMaterial);
addBox(finder, 0.16, 0.26, 0.3, trimMaterial, -0.78, 0, 0);
addBox(finder, 0.08, 0.16, 0.16, lensMaterial, 0.75, 0, 0);
addBox(finder, 0.08, 0.32, 0.32, bodyMaterial, 0.05, -0.18, 0);
addBox(finder, 0.08, 0.32, 0.32, bodyMaterial, 0.38, -0.18, 0);
// Eyepiece / focuser
const eyepieceGroup = new THREE.Group();
telescope.add(eyepieceGroup);
addBox(eyepieceGroup, 0.42, 0.5, 0.5, darkMaterial, 0, 0, 0);
addBox(eyepieceGroup, 0.36, 0.36, 0.36, trimMaterial, 0.29, 0, 0);
addBox(eyepieceGroup, 0.28, 0.3, 0.3, darkMaterial, 0.54, 0, 0);
addBox(eyepieceGroup, 0.08, 0.28, 0.28, lensMaterial, 0.72, 0, 0);
addFrame(eyepieceGroup, 0.13, 0.5, 0.3, 0.1, bodyMaterial).position.x = 0.81;
addBox(eyepieceGroup, 0.1, 0.15, 0.15, silverMaterial, 0.94, 0, 0);
// Focus knobs
addBox(eyepieceGroup, 0.18, 0.18, 0.18, silverMaterial, 0.15, -0.3, 0.36);
addBox(eyepieceGroup, 0.18, 0.18, 0.18, silverMaterial, 0.15, -0.3, -0.36);
// Blocky alt-azimuth mount
const mount = new THREE.Group();
mount.position.x = -1.25;
telescope.add(mount);
addBox(mount, 1.8, 0.18, 1.35, darkMaterial, 0, -1.65, 0);
addBox(mount, 1.25, 0.12, 0.9, trimMaterial, 0, -1.52, 0);
addBox(mount, 0.3, 1.05, 0.4, bodyMaterial, 0, -1.0, 0);
addBox(mount, 0.75, 0.22, 0.95, darkMaterial, 0, -0.48, 0);
addBox(mount, 0.28, 0.75, 0.18, bodyMaterial, 0, -0.23, 0.55);
addBox(mount, 0.28, 0.75, 0.18, bodyMaterial, 0, -0.23, -0.55);
addBox(mount, 0.18, 0.18, 0.18, silverMaterial, 0, -0.3, 0.74);
addBox(mount, 0.18, 0.18, 0.18, silverMaterial, 0, -0.3, -0.74);
function createVoxelArrow(material) {
const group = new THREE.Group();
addBox(group, 0.14, 0.62, 0.14, material, 0, -0.13, 0);
addBox(group, 0.28, 0.18, 0.14, material, 0, 0.28, 0);
addBox(group, 0.14, 0.18, 0.14, material, -0.14, 0.11, 0);
addBox(group, 0.14, 0.18, 0.14, material, 0.14, 0.11, 0);
return group;
}
const objectArrow = createVoxelArrow(objectArrowMaterial);
objectArrow.position.set(-5.25, 0.9, -0.65);
objectArrow.scale.setScalar(0.68);
scene.add(objectArrow);
const imageArrow = createVoxelArrow(arrowMaterial);
imageArrow.scale.set(1, -1, 1); // Keplerian image inversion
scene.add(imageArrow);
const imagePlane = addBox(
scene,
0.035,
1.25,
1.25,
new THREE.MeshBasicMaterial({
color: 0x65e8ff,
transparent: true,
opacity: 0.09,
depthWrite: false
})
);
const focusGlow = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.15, 0.15),
new THREE.MeshBasicMaterial({ color: 0x9cf7ff })
);
scene.add(focusGlow);
// Focal-length ruler
const rulerMaterial = new THREE.LineBasicMaterial({
color: 0x65e8ff,
transparent: true,
opacity: 0.75
});
const focalRuler = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(objectiveX, -0.82, 0.85),
new THREE.Vector3(-1, -0.82, 0.85)
]),
rulerMaterial
);
scene.add(focalRuler);
const rulerStartTick = addBox(
scene, 0.035, 0.22, 0.035, trimMaterial, objectiveX, -0.82, 0.85
);
const rulerEndTick = addBox(
scene, 0.035, 0.22, 0.035, trimMaterial, -1, -0.82, 0.85
);
// Label anchors projected from 3D into HTML.
const anchors = {};
function addAnchor(name, parent, x, y, z) {
const anchor = new THREE.Object3D();
anchor.position.set(x, y, z);
parent.add(anchor);
anchors[name] = anchor;
return anchor;
}
addAnchor("objective", objectiveGroup, 0, 0.83, 0);
addAnchor("aperture", objectiveGroup, -0.25, 0.78, 0.4);
addAnchor("image", scene, 0, 0.78, 0);
addAnchor("eyepiece", eyepieceGroup, 0.55, 0.52, 0);
addAnchor("object", scene, -5.25, 1.45, -0.65);
addAnchor("focal", scene, -1, -0.68, 0.85);
addAnchor("incoming", scene, -5.65, 0.75, 0);
addAnchor("outgoing", scene, 3.45, 0.62, 0);
const labelElements = {
objective: $("labelObjective"),
aperture: $("labelAperture"),
image: $("labelImage"),
eyepiece: $("labelEyepiece"),
object: $("labelObject"),
focal: $("labelFocal"),
incoming: $("labelIncoming"),
outgoing: $("labelOutgoing")
};
const rayGroup = new THREE.Group();
scene.add(rayGroup);
function addRayDashes(a, b, material, spacing = 0.16) {
const distance = a.distanceTo(b);
const count = Math.max(1, Math.floor(distance / spacing));
for (let i = 1; i < count; i++) {
const marker = new THREE.Mesh(rayMarkerGeometry, material);
marker.position.lerpVectors(a, b, i / count);
marker.rotation.set(0, 0, Math.PI / 4);
rayGroup.add(marker);
}
}
function rebuildRays(focusX, eyepieceX, aperture) {
for (const child of [...rayGroup.children]) {
if (child.isLine) child.geometry.dispose();
rayGroup.remove(child);
}
const visualOpening = 0.22 + (aperture / 200) * 0.68;
const levels = [
-visualOpening,
-visualOpening * 0.54,
visualOpening * 0.54,
visualOpening
];
const gold = new THREE.Color(0xffd166);
const cyan = new THREE.Color(0x65e8ff);
const green = new THREE.Color(0x63f0bd);
for (const level of levels) {
const points = [
new THREE.Vector3(-6.25, level, 0),
new THREE.Vector3(objectiveX - 0.02, level, 0),
new THREE.Vector3(focusX, 0, 0),
new THREE.Vector3(eyepieceX + 0.72, -level * 0.18, 0),
new THREE.Vector3(3.95, -level * 0.18, 0)
];
const positions = [];
const colors = [];
points.forEach((point, index) => {
positions.push(point.x, point.y, point.z);
if (index <= 1) colors.push(gold.r, gold.g, gold.b);
else if (index === 2) colors.push(cyan.r, cyan.g, cyan.b);
else colors.push(green.r, green.g, green.b);
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
const line = new THREE.Line(geometry, rayLineMaterial);
rayGroup.add(line);
addRayDashes(points[0], points[1], goldRayMaterial);
addRayDashes(points[1], points[2], cyanRayMaterial);
addRayDashes(points[2], points[3], cyanRayMaterial);
addRayDashes(points[3], points[4], greenRayMaterial);
}
}
const state = {
fo: 1000,
fe: 25,
aperture: 120
};
function updateApertureBlades(apertureMm) {
const opening = 0.22 + (apertureMm / 200) * 0.68;
const bladeDepth = 0.38;
bladeTop.position.y = opening / 2 + bladeDepth / 2;
bladeBottom.position.y = -(opening / 2 + bladeDepth / 2);
bladeLeft.scale.y = opening;
bladeRight.scale.y = opening;
bladeLeft.position.z = -(opening / 2 + 0.16);
bladeRight.position.z = opening / 2 + 0.16;
}
function updateModel() {
const { fo, fe, aperture } = state;
// Schematic focus movement responds to objective focal length.
const focusX =
-1.15 + ((fo - 400) / (2000 - 400)) * 0.8;
// Positive eyepiece sits beyond the objective's real focal plane.
const eyepieceX =
focusX + 0.9 + ((fe - 5) / (40 - 5)) * 0.45;
const tubeStart = objectiveX + 0.38;
const tubeEnd = eyepieceX - 0.2;
const tubeLength = Math.max(0.8, tubeEnd - tubeStart);
const tubeCenter = (tubeStart + tubeEnd) / 2;
tubeShell.position.x = tubeCenter;
tubeShell.scale.x = tubeLength;
bottomRail.position.set(tubeCenter, -0.37, 0);
bottomRail.scale.x = tubeLength;
topRail.position.set(tubeCenter, 0.36, 0);
topRail.scale.x = tubeLength;
tubeRibs.forEach((rib, index) => {
const t = (index + 0.55) / tubeRibs.length;
rib.position.x = tubeStart + t * tubeLength;
});
eyepieceGroup.position.x = eyepieceX;
imageArrow.position.x = focusX;
imagePlane.position.x = focusX + 0.015;
focusGlow.position.set(focusX, 0, 0);
anchors.image.position.set(focusX, 0.78, 0);
focalRuler.geometry.dispose();
focalRuler.geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(objectiveX, -0.82, 0.85),
new THREE.Vector3(focusX, -0.82, 0.85)
]);
rulerEndTick.position.x = focusX;
anchors.focal.position.set(
(objectiveX + focusX) / 2,
-0.67,
0.85
);
updateApertureBlades(aperture);
rebuildRays(focusX, eyepieceX, aperture);
const signedMagnification = -fo / fe;
const magnification = Math.abs(signedMagnification);
const exitPupil = aperture / magnification;
const focalRatio = fo / aperture;
$("foOut").textContent = `${fo} mm`;
$("feOut").textContent = `${fe} mm`;
$("apertureOut").textContent = `${aperture} mm`;
$("magReadout").textContent = `${magnification.toFixed(1)}×`;
$("orientationReadout").textContent = "INVERTED · 180°";
$("pupilReadout").textContent = `${exitPupil.toFixed(1)} mm`;
$("fRatioReadout").textContent = `f/${focalRatio.toFixed(1)}`;
$("formula").textContent =
`M = −fₒ / fₑ = −${fo} / ${fe} = −${magnification.toFixed(1)}×`;
$("miniArrow").style.transform = "rotate(180deg)";
for (const id of ["fo", "fe", "aperture"]) {
const input = $(id);
const percentage =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
}
function bindRange(id, key) {
$(id).addEventListener("input", event => {
state[key] = Number(event.target.value);
updateModel();
});
}
bindRange("fo", "fo");
bindRange("fe", "fe");
bindRange("aperture", "aperture");
$("resetOptics").addEventListener("click", () => {
state.fo = 1000;
state.fe = 25;
state.aperture = 120;
$("fo").value = state.fo;
$("fe").value = state.fe;
$("aperture").value = state.aperture;
updateModel();
});
function resetView() {
cameraTarget.set(-0.75, -0.05, 0);
cameraRadius = 10.8;
cameraTheta = 0.34;
cameraPhi = 1.18;
updateCamera();
}
$("resetView").addEventListener("click", resetView);
// Camera controls implemented locally, without addons.
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.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.006,
0.18,
Math.PI - 0.18
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
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("pointerleave", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
6.5,
18
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraTheta -= 0.08;
break;
case "ArrowRight":
cameraTheta += 0.08;
break;
case "ArrowUp":
cameraPhi = Math.max(0.18, cameraPhi - 0.06);
break;
case "ArrowDown":
cameraPhi = Math.min(Math.PI - 0.18, cameraPhi + 0.06);
break;
case "+":
case "=":
cameraRadius = Math.max(6.5, cameraRadius - 0.4);
break;
case "-":
cameraRadius = Math.min(18, cameraRadius + 0.4);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
renderer.domElement.style.cursor = "grab";
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const [name, element] of Object.entries(labelElements)) {
const anchor = anchors[name];
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
}
updateModel();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
focusGlow.scale.setScalar(1 + Math.sin(time * 3.2) * 0.16);
lensMaterial.opacity = 0.36 + Math.sin(time * 1.5) * 0.035;
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```