Prompt specification
Build or customize the Three.js 3D scene "Comparing observations at different magnifications" 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: Comparing observations at different magnifications
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/comparing-observations-at-different-magnifications-x2507
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts historical microscopy and observational scale. Build a teaching scene with one specimen viewed at three magnifications. Preserve the same features and show when enlarging the view adds no new resolved detail. Low-poly.
Working Three.js Starter (comparing-observations-at-different-magnifications-x2507):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Magnification Is Not Resolution</title>
<style>
:root {
--ink: #eef0df;
--muted: #a9b9ad;
--gold: #d5ad67;
--gold-bright: #f0ca7d;
--panel: rgba(8, 24, 25, 0.82);
--line: rgba(213, 173, 103, 0.34);
--red: #db8063;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b1b1c;
color: var(--ink);
font-family: 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;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: clamp(18px, 3vw, 38px);
left: clamp(18px, 3vw, 42px);
max-width: 560px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.75);
}
.eyebrow {
margin-bottom: 9px;
color: var(--gold-bright);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 520px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 58px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
header p {
max-width: 470px;
margin: 14px 0 0;
color: var(--muted);
font-size: clamp(12px, 1.15vw, 15px);
line-height: 1.55;
}
.controls {
position: absolute;
top: clamp(16px, 2.5vw, 32px);
right: clamp(16px, 2.5vw, 32px);
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.controls button {
min-width: 42px;
height: 42px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(8, 24, 25, 0.78);
color: var(--ink);
font: inherit;
font-size: 18px;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.controls button:hover,
.controls button:focus-visible {
border-color: var(--gold-bright);
background: rgba(42, 49, 35, 0.9);
color: var(--gold-bright);
outline: none;
}
.controls .reset {
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.view-label {
position: absolute;
top: 0;
left: 0;
width: max-content;
max-width: 190px;
padding: 9px 11px 10px;
transform: translate(-50%, calc(-100% - 10px));
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(7, 22, 23, 0.84);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(9px);
transition:
border-color 180ms ease,
background 180ms ease;
}
.view-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 11px;
background: var(--gold);
opacity: 0.75;
}
.view-label.active {
border-color: var(--gold-bright);
background: rgba(29, 42, 32, 0.92);
}
.view-label .heading {
display: flex;
align-items: baseline;
gap: 8px;
margin-bottom: 4px;
}
.view-label .magnification {
color: var(--gold-bright);
font-family: Georgia, serif;
font-size: 22px;
line-height: 1;
}
.view-label .kind {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.view-label strong {
display: block;
font-family: Georgia, serif;
font-size: 14px;
font-weight: 500;
}
.view-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.card {
position: absolute;
border: 1px solid var(--line);
border-radius: 7px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(14px);
}
.specimen-card {
bottom: clamp(18px, 3vw, 38px);
left: clamp(18px, 3vw, 42px);
width: 304px;
padding: 17px;
}
.card-label {
margin-bottom: 10px;
color: var(--gold-bright);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.specimen-row {
display: flex;
align-items: center;
gap: 13px;
}
#sourcePreview {
width: 58px;
height: 58px;
flex: 0 0 auto;
border: 1px solid rgba(230, 197, 126, 0.5);
image-rendering: pixelated;
background: #112927;
box-shadow: 0 0 0 3px rgba(213, 173, 103, 0.08);
}
.specimen-name {
margin: 0 0 4px;
font-family: Georgia, serif;
font-size: 18px;
font-weight: 500;
}
.specimen-detail {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.specimen-card p:last-child {
margin: 12px 0 0;
padding-top: 11px;
border-top: 1px solid rgba(213, 173, 103, 0.19);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.stats-card {
right: clamp(18px, 3vw, 42px);
bottom: clamp(18px, 3vw, 38px);
width: min(480px, 46vw);
padding: 17px 18px 14px;
}
.stats-header {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 12px;
}
.stats-header .card-label {
margin: 0;
}
.stats-header span:last-child {
color: var(--muted);
font-size: 10px;
}
.matrix {
display: grid;
grid-template-columns: 1.35fr repeat(3, 1fr);
overflow: hidden;
border: 1px solid rgba(213, 173, 103, 0.2);
border-radius: 4px;
font-size: 10px;
}
.matrix > div {
padding: 8px 9px;
border-right: 1px solid rgba(213, 173, 103, 0.14);
border-bottom: 1px solid rgba(213, 173, 103, 0.14);
}
.matrix > div:nth-child(4n) {
border-right: 0;
}
.matrix > div:nth-last-child(-n + 4) {
border-bottom: 0;
}
.matrix .column {
text-align: center;
color: var(--gold-bright);
font-weight: 800;
}
.matrix .axis {
color: var(--muted);
font-weight: 700;
}
.matrix .limit {
color: var(--red);
font-weight: 800;
}
.stats-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.stats-note strong {
color: var(--ink);
font-weight: 650;
}
.hint {
position: absolute;
left: 50%;
bottom: 15px;
transform: translateX(-50%);
color: rgba(225, 230, 213, 0.58);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 900px) {
header p {
display: none;
}
.specimen-card {
width: 270px;
}
.stats-card {
width: 410px;
}
.hint {
display: none;
}
}
@media (max-width: 700px) {
header {
top: 16px;
left: 15px;
max-width: calc(100vw - 150px);
}
h1 {
font-size: 27px;
}
.eyebrow {
font-size: 8px;
}
.controls {
top: 14px;
right: 14px;
}
.controls button {
min-width: 36px;
height: 36px;
padding: 0 9px;
}
.controls .reset {
font-size: 0;
}
.controls .reset::before {
content: "↺";
font-size: 20px;
}
.specimen-card {
display: none;
}
.stats-card {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 12px;
}
.stats-note {
font-size: 9px;
}
.matrix > div {
padding: 6px;
font-size: 8px;
}
.view-label {
max-width: 145px;
padding: 6px 8px;
}
.view-label .magnification {
font-size: 18px;
}
.view-label strong {
font-size: 11px;
}
.view-label small {
font-size: 8px;
}
}
@media (max-height: 650px) {
.specimen-card {
display: none;
}
.stats-card {
padding: 11px 13px;
}
.stats-note {
display: none;
}
header p {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header>
<div class="eyebrow">Historical optics · field lesson 03</div>
<h1>Magnification is not resolution.</h1>
<p>
One specimen, three magnifications. The final lens makes the image
larger, but it cannot recover information the optical system did not resolve.
</p>
</header>
<div class="controls" aria-label="Camera controls">
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="reset" class="reset" type="button">Reset</button>
</div>
<div id="label10" class="view-label">
<div class="heading">
<span class="magnification">10×</span>
<span class="kind">survey</span>
</div>
<strong>Coarse field</strong>
<small>Cell walls only</small>
</div>
<div id="label40" class="view-label">
<div class="heading">
<span class="magnification">40×</span>
<span class="kind">limit</span>
</div>
<strong>Detail resolved</strong>
<small>Nuclei become visible</small>
</div>
<div id="label100" class="view-label">
<div class="heading">
<span class="magnification">100×</span>
<span class="kind">empty</span>
</div>
<strong>Empty magnification</strong>
<small>Same 64² raster as 40×</small>
</div>
<section class="card specimen-card" aria-label="Specimen information">
<div class="card-label">Prepared specimen · one source</div>
<div class="specimen-row">
<canvas
id="sourcePreview"
width="64"
height="64"
aria-label="Pixelated source view of the onion epidermis specimen"
></canvas>
<div>
<h2 class="specimen-name">Onion epidermis</h2>
<p class="specimen-detail">
Cell walls and nuclei<br />
Historical teaching mount
</p>
</div>
</div>
<p>
The 40× and 100× panels reuse the same optical raster. Only the display
scale changes.
</p>
</section>
<section class="card stats-card" aria-label="Resolution comparison">
<div class="stats-header">
<div class="card-label">The resolution ceiling</div>
<span>one specimen · three apparent scales</span>
</div>
<div class="matrix" role="table" aria-label="Magnification comparison">
<div class="column"></div>
<div class="column">10×</div>
<div class="column">40×</div>
<div class="column">100×</div>
<div class="axis">Optical raster</div>
<div>16² px</div>
<div>64² px</div>
<div>64² px</div>
<div class="axis">Resolved detail</div>
<div>Walls</div>
<div>Walls + nuclei</div>
<div>Walls + nuclei</div>
<div class="axis">New information</div>
<div>Baseline</div>
<div>Added</div>
<div class="limit">0 added</div>
</div>
<p class="stats-note">
<strong>The 100× view contains exactly the same information as 40×.</strong>
Frame diameters are compressed to fit the scene; the raster counts are literal.
</p>
</section>
<div class="hint">Drag to orbit · scroll to zoom · click a lens to inspect</div>
<div id="status" class="sr-only" aria-live="polite"></div>
</div>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, and direct camera controls
// ------------------------------------------------------------
const host = document.getElementById("scene");
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;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1b1c);
scene.fog = new THREE.Fog(0x0b1b1c, 13, 29);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
80
);
const target = new THREE.Vector3(0.65, 1.6, 0);
const desiredTarget = target.clone();
let radius = 16.5;
let desiredRadius = radius;
let theta = -0.1;
let desiredTheta = theta;
let phi = 1.47;
let desiredPhi = phi;
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let downX = 0;
let downY = 0;
let pointerMoved = false;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const clamp = THREE.MathUtils.clamp;
function fittedRadius() {
if (window.innerWidth < 700) return 28;
if (window.innerWidth < 1050) return 21;
return 16.5;
}
function resetView() {
desiredTarget.set(0.65, 1.6, 0);
desiredRadius = fittedRadius();
desiredTheta = -0.1;
desiredPhi = 1.47;
document.querySelectorAll(".view-label").forEach(label => {
label.classList.remove("active");
});
document.getElementById("status").textContent =
"Wide view restored. One specimen is shown at three magnifications.";
}
function zoomBy(factor) {
desiredRadius = clamp(desiredRadius * factor, 5, 33);
}
document.getElementById("zoomIn").addEventListener("click", () => zoomBy(0.82));
document.getElementById("zoomOut").addEventListener("click", () => zoomBy(1.22));
document.getElementById("reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerMoved = false;
pointerId = event.pointerId;
lastX = downX = event.clientX;
lastY = downY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.hypot(event.clientX - downX, event.clientY - downY) > 5) {
pointerMoved = true;
}
desiredTheta -= dx * 0.005;
desiredPhi = clamp(desiredPhi - dy * 0.004, 1.12, 1.52);
theta = desiredTheta;
phi = desiredPhi;
lastX = event.clientX;
lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", event => {
if (dragging && !pointerMoved) {
inspectAt(event.clientX, event.clientY);
}
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
pointerId = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerId = null;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredRadius = clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
5,
33
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetView();
});
// ------------------------------------------------------------
// Lighting and materials
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xc2ddd5, 0x21140d, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffd6a0, 3.4);
keyLight.position.set(-4, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8fc6c4, 1.5);
rimLight.position.set(6, 5, -5);
scene.add(rimLight);
const brass = new THREE.MeshStandardMaterial({
color: 0xb78a47,
metalness: 0.76,
roughness: 0.31
});
const darkBrass = new THREE.MeshStandardMaterial({
color: 0x6e512e,
metalness: 0.7,
roughness: 0.42
});
const wood = new THREE.MeshStandardMaterial({
color: 0x513225,
metalness: 0.02,
roughness: 0.83
});
const darkWood = new THREE.MeshStandardMaterial({
color: 0x241b18,
metalness: 0.03,
roughness: 0.88
});
const teal = new THREE.MeshStandardMaterial({
color: 0x143b39,
metalness: 0.12,
roughness: 0.67
});
const amber = new THREE.MeshStandardMaterial({
color: 0xb97832,
emissive: 0x361607,
emissiveIntensity: 0.24,
metalness: 0.05,
roughness: 0.55,
transparent: true,
opacity: 0.88
});
const nucleusMaterial = new THREE.MeshStandardMaterial({
color: 0x7d302a,
emissive: 0x2b0906,
emissiveIntensity: 0.2,
roughness: 0.7
});
const glass = new THREE.MeshStandardMaterial({
color: 0xa7d6cd,
metalness: 0.08,
roughness: 0.18,
transparent: true,
opacity: 0.42
});
function addMesh(parent, geometry, material, position, rotation) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rod(parent, start, end, radius, material, segments = 8) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const mesh = addMesh(
parent,
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// ------------------------------------------------------------
// One optical specimen record
// ------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function makeSpecimenRaster() {
const canvas = document.createElement("canvas");
canvas.width = 64;
canvas.height = 64;
const ctx = canvas.getContext("2d");
const random = seededRandom(2846);
ctx.fillStyle = "#102826";
ctx.fillRect(0, 0, 64, 64);
const columns = 4;
const rows = 6;
const cellWidth = 64 / columns;
const cellHeight = 64 / rows;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x0 = column * cellWidth;
const y0 = row * cellHeight;
const x1 = (column + 1) * cellWidth;
const y1 = (row + 1) * cellHeight;
const points = [
[x0 + 1.6 + random() * 2.2, y0 + 1.0 + random() * 1.5],
[x1 - 1.8 - random() * 2.0, y0 + 1.4 + random() * 1.5],
[x1 - 1.4 - random() * 1.6, y1 - 1.2 - random() * 1.6],
[x0 + 1.4 + random() * 2.2, y1 - 1.2 - random() * 1.5]
];
const lightness = 20 + random() * 7;
ctx.beginPath();
points.forEach(([x, y], index) => {
if (index === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.closePath();
ctx.fillStyle = `hsl(34, 37%, ${lightness}%)`;
ctx.fill();
ctx.strokeStyle = "#d9bd79";
ctx.lineWidth = 1.25;
ctx.stroke();
}
}
const nuclei = [
[22, 17],
[39, 29],
[22, 48],
[52, 51]
];
nuclei.forEach(([cx, cy], index) => {
const radius = 2.3 + index * 0.12;
const sides = 7;
ctx.beginPath();
for (let side = 0; side < sides; side++) {
const angle = (side / sides) * Math.PI * 2;
const r = radius * (0.78 + random() * 0.35);
const x = cx + Math.cos(angle) * r;
const y = cy + Math.sin(angle) * r;
if (side === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.closePath();
ctx.fillStyle = "#692b28";
ctx.fill();
ctx.strokeStyle = "#e7a56f";
ctx.lineWidth = 0.8;
ctx.stroke();
});
// Tiny inclusions, resolved only in the higher-resolution record.
for (let i = 0; i < 20; i++) {
ctx.fillStyle = i % 3 === 0 ? "#e4c785" : "#472f28";
ctx.fillRect(
Math.floor(random() * 64),
Math.floor(random() * 64),
1,
1
);
}
return canvas;
}
const highRaster = makeSpecimenRaster();
const lowRaster = document.createElement("canvas");
lowRaster.width = 16;
lowRaster.height = 16;
const lowContext = lowRaster.getContext("2d");
lowContext.imageSmoothingEnabled = false;
lowContext.drawImage(highRaster, 0, 0, 16, 16);
const preview = document.getElementById("sourcePreview");
const previewContext = preview.getContext("2d");
previewContext.imageSmoothingEnabled = false;
previewContext.drawImage(highRaster, 0, 0);
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
texture.generateMipmaps = false;
texture.needsUpdate = true;
return texture;
}
const lowTexture = canvasTexture(lowRaster);
const highTexture = canvasTexture(highRaster);
// ------------------------------------------------------------
// Platform, backdrop, and low-poly historical microscope
// ------------------------------------------------------------
const floor = addMesh(
scene,
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x0d2222,
roughness: 0.94
}),
[0, -0.22, 0],
[-Math.PI / 2, 0, 0]
);
floor.castShadow = false;
addMesh(
scene,
new THREE.BoxGeometry(13.8, 0.18, 3.5),
darkWood,
[0.8, -0.11, -0.1]
);
addMesh(
scene,
new THREE.BoxGeometry(13.1, 0.025, 0.025),
darkBrass,
[0.8, 0.005, 1.45]
);
const microscope = new THREE.Group();
microscope.position.set(-4.0, 0, 0.2);
scene.add(microscope);
// Broad wooden foot.
addMesh(
microscope,
new THREE.CylinderGeometry(1.02, 1.1, 0.22, 12),
wood,
[0, 0.12, 0]
);
addMesh(
microscope,
new THREE.CylinderGeometry(0.86, 0.98, 0.08, 12),
darkBrass,
[0, 0.25, 0]
);
// Upright and focusing hardware.
rod(
microscope,
[-0.55, 0.25, 0],
[-0.55, 2.32, 0],
0.115,
brass
);
rod(
microscope,
[-0.55, 2.3, 0],
[0.32, 2.3, 0],
0.12,
brass
);
addMesh(
microscope,
new THREE.CylinderGeometry(0.28, 0.28, 0.14, 12),
darkBrass,
[-0.55, 1.36, 0],
[0, 0, Math.PI / 2]
);
// Single-lens barrel.
rod(
microscope,
[0.32, 2.28, 0],
[0.32, 1.72, 0],
0.18,
brass,
10
);
addMesh(
microscope,
new THREE.CylinderGeometry(0.23, 0.23, 0.2, 10),
darkBrass,
[0.32, 2.22, 0]
);
addMesh(
microscope,
new THREE.TorusGeometry(0.19, 0.045, 6, 18),
brass,
[0.32, 1.68, 0],
[Math.PI / 2, 0, 0]
);
const lensGlass = addMesh(
microscope,
new THREE.CircleGeometry(0.15, 18),
new THREE.MeshBasicMaterial({
color: 0x8ac8c1,
transparent: true,
opacity: 0.5
}),
[0.32, 1.68, 0.015],
[-Math.PI / 2, 0, 0]
);
lensGlass.castShadow = false;
// Stage and the one physical specimen.
addMesh(
microscope,
new THREE.BoxGeometry(1.02, 0.13, 0.76),
wood,
[0.3, 1.18, 0.03]
);
addMesh(
microscope,
new THREE.BoxGeometry(0.73, 0.035, 0.51),
glass,
[0.3, 1.27, 0.03]
);
addMesh(
microscope,
new THREE.CylinderGeometry(0.31, 0.31, 0.055, 12),
amber,
[0.3, 1.31, 0.03]
);
const specimenNucleus = addMesh(
microscope,
new THREE.IcosahedronGeometry(0.075, 0),
nucleusMaterial,
[0.33, 1.37, 0.03]
);
specimenNucleus.rotation.set(0.4, 0.6, 0.2);
// Candle provides a warm historical laboratory light.
const candle = new THREE.Group();
candle.position.set(-1.08, 0.25, -0.23);
microscope.add(candle);
addMesh(
candle,
new THREE.CylinderGeometry(0.22, 0.25, 0.08, 10),
darkBrass,
[0, 0.04, 0]
);
addMesh(
candle,
new THREE.CylinderGeometry(0.14, 0.16, 0.72, 10),
new THREE.MeshStandardMaterial({
color: 0xd5c6a0,
roughness: 0.88
}),
[0, 0.42, 0]
);
addMesh(
candle,
new THREE.CylinderGeometry(0.018, 0.018, 0.13, 6),
darkWood,
[0, 0.84, 0]
);
const flame = addMesh(
candle,
new THREE.ConeGeometry(0.075, 0.25, 7),
new THREE.MeshBasicMaterial({
color: 0xffb84e,
toneMapped: false
}),
[0, 1.02, 0]
);
flame.castShadow = false;
const flameGlow = new THREE.PointLight(0xffa44d, 15, 7, 2);
flameGlow.position.set(0, 1.0, 0);
candle.add(flameGlow);
// ------------------------------------------------------------
// Three optical records
// ------------------------------------------------------------
const panelSpecs = [
{
x: -0.65,
radius: 0.9,
texture: lowTexture,
label: "label10",
description: "10 times magnification: coarse survey raster"
},
{
x: 1.75,
radius: 1.35,
texture: highTexture,
label: "label40",
description: "40 times magnification: resolution limit reached"
},
{
x: 5.15,
radius: 1.95,
texture: highTexture,
label: "label100",
description: "100 times magnification: the same 64 by 64 raster as 40 times"
}
];
const panelCenters = [];
const panelDisks = [];
const panelRims = [];
panelSpecs.forEach(spec => {
const group = new THREE.Group();
group.position.set(spec.x, 2.25, -0.42);
scene.add(group);
// Dark backing plate.
addMesh(
group,
new THREE.CylinderGeometry(
spec.radius + 0.14,
spec.radius + 0.14,
0.17,
32
),
teal,
[0, 0, -0.08],
[Math.PI / 2, 0, 0]
);
// The actual raster is always drawn without filtering.
const disk = addMesh(
group,
new THREE.CircleGeometry(spec.radius, 48),
new THREE.MeshBasicMaterial({
map: spec.texture,
side: THREE.DoubleSide,
toneMapped: false
}),
[0, 0, 0.045]
);
disk.castShadow = false;
disk.userData.panelIndex = panelSpecs.indexOf(spec);
panelDisks.push(disk);
const rimMaterial = brass.clone();
const rim = addMesh(
group,
new THREE.TorusGeometry(
spec.radius + 0.045,
0.085,
6,
48
),
rimMaterial,
[0, 0, 0.12]
);
panelRims.push(rim);
addMesh(
group,
new THREE.TorusGeometry(
spec.radius - 0.035,
0.018,
5,
48
),
darkBrass,
[0, 0, 0.135]
);
// Six low-poly fasteners.
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const boltRadius = spec.radius + 0.08;
addMesh(
group,
new THREE.SphereGeometry(0.036, 6, 4),
darkBrass,
[
Math.cos(angle) * boltRadius,
Math.sin(angle) * boltRadius,
0.17
]
);
}
// Stand behind each optical record.
addMesh(
group,
new THREE.CylinderGeometry(
spec.radius * 0.52,
spec.radius * 0.62,
0.12,
10
),
darkWood,
[0, -2.14, -0.24]
);
rod(
group,
[0, -2.08, -0.24],
[0, -spec.radius * 0.22, -0.24],
0.065,
darkBrass
);
panelCenters.push(group.position.clone());
});
// Fine optical paths from the one specimen to the three records.
const specimenWorld = new THREE.Vector3(-3.7, 1.36, 0.23);
panelSpecs.forEach((spec, index) => {
const start = specimenWorld.clone();
const end = new THREE.Vector3(spec.x, 2.25, -0.34);
const control = new THREE.Vector3(
(start.x + end.x) * 0.5,
2.85,
0.85 - index * 0.08
);
const curve = new THREE.QuadraticBezierCurve3(start, control, end);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(48)
);
const material = new THREE.LineDashedMaterial({
color: index === 2 ? 0xc98061 : 0xd0ad69,
transparent: true,
opacity: index === 2 ? 0.34 : 0.2,
dashSize: 0.11,
gapSize: 0.09
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
scene.add(line);
});
// ------------------------------------------------------------
// Floating dust
// ------------------------------------------------------------
const dustCount = 90;
const dustPositions = new Float32Array(dustCount * 3);
const dustSpeeds = new Float32Array(dustCount);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 15;
dustPositions[i * 3 + 1] = Math.random() * 5;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 6;
dustSpeeds[i] = 0.025 + Math.random() * 0.055;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xe9d49a,
size: 0.035,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
scene.add(dust);
// ------------------------------------------------------------
// Lens selection and projected HTML labels
// ------------------------------------------------------------
function inspectAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(panelDisks, false);
if (!hits.length) return;
const index = hits[0].object.userData.panelIndex;
const spec = panelSpecs[index];
desiredTarget.set(spec.x, 2.25, -0.35);
desiredRadius = Math.max(4.2, spec.radius * 3.15);
desiredTheta = 0;
desiredPhi = 1.49;
document.querySelectorAll(".view-label").forEach(label => {
label.classList.remove("active");
});
document.getElementById(spec.label).classList.add("active");
panelRims.forEach((rim, rimIndex) => {
rim.material.emissive.setHex(
rimIndex === index ? 0x6b4318 : 0x000000
);
rim.material.emissiveIntensity = rimIndex === index ? 0.55 : 0;
});
document.getElementById("status").textContent = spec.description;
}
const projectedLabels = panelSpecs.map(spec => ({
element: document.getElementById(spec.label),
position: new THREE.Vector3(
spec.x,
2.25 + spec.radius + 0.3,
-0.2
)
}));
const projection = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
projectedLabels.forEach(item => {
projection.copy(item.position).project(camera);
const visible =
projection.z > -1 &&
projection.z < 1 &&
Math.abs(projection.x) < 1.15 &&
Math.abs(projection.y) < 1.15;
item.element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projection.x * 0.5 + 0.5) * width;
const y = (-projection.y * 0.5 + 0.5) * height;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
});
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 700 ? 50 : 40;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
radius = desiredRadius = fittedRadius();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
target.lerp(desiredTarget, 0.085);
radius += (desiredRadius - radius) * 0.085;
theta += (desiredTheta - theta) * 0.09;
phi += (desiredPhi - phi) * 0.09;
const sinPhi = Math.sin(phi);
const offset = new THREE.Vector3(
sinPhi * Math.sin(theta),
Math.cos(phi),
sinPhi * Math.cos(theta)
);
camera.position.copy(target).addScaledVector(offset, radius);
camera.lookAt(target);
const flicker =
0.92 +
Math.sin(elapsed * 10.7) * 0.045 +
Math.sin(elapsed * 17.3) * 0.025;
flame.scale.y = flicker;
flameGlow.intensity = 15 * flicker;
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3 + 1] += dustSpeeds[i];
if (dustPositions[i * 3 + 1] > 5.2) {
dustPositions[i * 3 + 1] = -0.05;
dustPositions[i * 3] = (Math.random() - 0.5) * 15;
}
}
dustGeometry.attributes.position.needsUpdate = true;
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```