Prompt specification
Build or customize the Three.js 3D scene "Historical microscope slide preparation desk" 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: Historical microscope slide preparation desk
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/historical-microscope-slide-preparation-desk-x2506
Scene Description Prompt:
Show a voxel early-microscopy desk with aligned illumination mirror, specimen support, and historical lens instrument. One HTML file using Three.js from cdnjs.
Working Three.js Starter (historical-microscope-slide-preparation-desk-x2506):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Early-Microscopy Desk</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #142020;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#header {
position: fixed;
top: 24px;
left: 26px;
z-index: 10;
max-width: min(460px, calc(100vw - 52px));
pointer-events: none;
color: #f5ead2;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
}
#header h1 {
margin: 0;
font-size: clamp(20px, 3vw, 34px);
line-height: 1.05;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#header p {
margin: 9px 0 0;
max-width: 390px;
color: #c7d0bf;
font-size: 12px;
line-height: 1.55;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#controls {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 20;
display: flex;
gap: 9px;
}
button {
border: 1px solid rgba(236, 216, 169, 0.32);
border-radius: 7px;
padding: 10px 14px;
background: rgba(17, 29, 28, 0.86);
color: #eadbb7;
font: 600 11px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
}
button:hover {
border-color: rgba(236, 216, 169, 0.7);
background: rgba(30, 47, 44, 0.94);
}
#hint {
position: fixed;
left: 24px;
bottom: 20px;
z-index: 10;
padding: 9px 12px;
border: 1px solid rgba(236, 216, 169, 0.16);
border-radius: 6px;
background: rgba(15, 26, 25, 0.68);
color: #bfc9ba;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(7px);
}
.callout {
position: fixed;
z-index: 8;
transform: translate(-50%, -100%);
padding: 7px 10px;
border: 1px solid rgba(240, 218, 165, 0.4);
border-radius: 4px;
background: rgba(18, 29, 28, 0.84);
color: #f2dfb2;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(6px);
}
.callout::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: rgba(240, 218, 165, 0.7);
}
@media (max-width: 650px) {
#header {
top: 17px;
left: 17px;
}
#header p {
display: none;
}
#hint {
left: 14px;
bottom: 14px;
max-width: 58vw;
line-height: 1.5;
}
#controls {
right: 14px;
bottom: 14px;
}
.callout {
font-size: 8px;
padding: 5px 7px;
}
}
</style>
</head>
<body>
<div id="header">
<h1>Early Optics Workbench</h1>
<p>Voxel reconstruction · illumination, specimen, and historical lens</p>
</div>
<div id="hint">Drag to orbit · wheel / pinch to zoom · double-click to reset</div>
<div id="controls">
<button id="reset">Reset view</button>
</div>
<div id="illuminationLabel" class="callout">Illumination mirror</div>
<div id="specimenLabel" class="callout">Specimen support</div>
<div id="lensLabel" class="callout">Historical lens</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x172322);
scene.fog = new THREE.Fog(0x172322, 19, 36);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const mat = {
wall: new THREE.MeshStandardMaterial({
color: 0x41514b,
roughness: 0.95
}),
wallTrim: new THREE.MeshStandardMaterial({
color: 0x253530,
roughness: 0.9
}),
floor: new THREE.MeshStandardMaterial({
color: 0x27322f,
roughness: 1
}),
wood: new THREE.MeshStandardMaterial({
color: 0x815034,
roughness: 0.82
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0xa16d43,
roughness: 0.8
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x4b3023,
roughness: 0.88
}),
woodEdge: new THREE.MeshStandardMaterial({
color: 0x3b291f,
roughness: 0.9
}),
brass: new THREE.MeshStandardMaterial({
color: 0xb58b36,
metalness: 0.7,
roughness: 0.31
}),
brassDark: new THREE.MeshStandardMaterial({
color: 0x745523,
metalness: 0.68,
roughness: 0.43
}),
iron: new THREE.MeshStandardMaterial({
color: 0x26302f,
metalness: 0.62,
roughness: 0.43
}),
ironBlack: new THREE.MeshStandardMaterial({
color: 0x161d1d,
metalness: 0.5,
roughness: 0.52
}),
mirror: new THREE.MeshStandardMaterial({
color: 0x9db9b4,
metalness: 0.9,
roughness: 0.16
}),
mirrorGlint: new THREE.MeshBasicMaterial({
color: 0xe6fff8
}),
glass: new THREE.MeshStandardMaterial({
color: 0xb6d9d4,
metalness: 0.08,
roughness: 0.12,
transparent: true,
opacity: 0.38,
depthWrite: false
}),
lens: new THREE.MeshStandardMaterial({
color: 0x173d48,
metalness: 0.72,
roughness: 0.12,
emissive: 0x183f45,
emissiveIntensity: 0.45
}),
paper: new THREE.MeshStandardMaterial({
color: 0xd9c9a6,
roughness: 0.94
}),
paperDark: new THREE.MeshStandardMaterial({
color: 0xb9aa8b,
roughness: 0.95
}),
ink: new THREE.MeshBasicMaterial({
color: 0x514c42
}),
specimen: new THREE.MeshStandardMaterial({
color: 0x8ba653,
roughness: 0.8
}),
specimenDark: new THREE.MeshStandardMaterial({
color: 0x566834,
roughness: 0.85
}),
flame: new THREE.MeshBasicMaterial({
color: 0xffcf58
}),
flameCore: new THREE.MeshBasicMaterial({
color: 0xfff1a4
}),
beam: new THREE.MeshBasicMaterial({
color: 0xffd66b,
transparent: true,
opacity: 0.72,
depthWrite: false
}),
outline: new THREE.LineBasicMaterial({
color: 0x17201e,
transparent: true,
opacity: 0.28
})
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function box(parent, w, h, d, x, y, z, material, outlined = false) {
const geometry = new THREE.BoxGeometry(w, h, d);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
mat.outline
);
mesh.add(edges);
}
return mesh;
}
function cylinder(
parent,
radius,
height,
x,
y,
z,
material,
segments = 12,
rotationX = 0,
rotationZ = 0
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.rotation.set(rotationX, 0, rotationZ);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addVoxelBeam(start, end, spacing = 0.14) {
const distance = start.distanceTo(end);
const count = Math.ceil(distance / spacing);
for (let i = 0; i <= count; i++) {
const p = new THREE.Vector3().lerpVectors(
start,
end,
i / count
);
const cube = box(
scene,
0.065,
0.065,
0.065,
p.x,
p.y,
p.z,
mat.beam
);
cube.castShadow = false;
cube.receiveShadow = false;
cube.renderOrder = 2;
}
}
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xd9e7df, 0x33291f, 1.55));
const keyLight = new THREE.DirectionalLight(0xffe1b0, 3.2);
keyLight.position.set(6, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9dc7c3, 1.25);
fillLight.position.set(-8, 7, 2);
scene.add(fillLight);
const lampLight = new THREE.PointLight(0xffb33f, 28, 5.5, 2);
lampLight.position.set(-4.3, 5.15, 0.1);
scene.add(lampLight);
// ------------------------------------------------------------
// Room
// ------------------------------------------------------------
box(scene, 30, 0.2, 30, 0, -0.12, 0, mat.floor);
box(scene, 20, 9, 0.3, 0, 4.45, -4.65, mat.wall);
box(scene, 20, 0.38, 0.35, 0, 0.18, -4.45, mat.wallTrim);
box(scene, 20, 0.18, 0.4, 0, 7.9, -4.42, mat.wallTrim);
// Background shelving
box(scene, 5.1, 0.18, 0.75, -4.1, 7.15, -4.08, mat.woodDark);
box(scene, 4.3, 0.18, 0.75, 4.0, 7.15, -4.08, mat.woodDark);
const bookColors = [
new THREE.MeshStandardMaterial({ color: 0x6b3831, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0x3c5d54, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0xa2814e, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0x4b4b68, roughness: 0.9 })
];
for (let i = 0; i < 7; i++) {
const height = 0.55 + (i % 3) * 0.12;
box(
scene,
0.25,
height,
0.4,
-5.95 + i * 0.34,
7.24 + height * 0.5,
-4.02,
bookColors[i % bookColors.length]
);
}
for (let i = 0; i < 5; i++) {
const height = 0.45 + (i % 2) * 0.16;
box(
scene,
0.3,
height,
0.4,
2.55 + i * 0.4,
7.24 + height * 0.5,
-4.02,
bookColors[(i + 1) % bookColors.length]
);
}
// Small wall notes
box(scene, 0.86, 0.62, 0.025, -0.9, 6.05, -4.46, mat.paper);
box(scene, 0.68, 0.5, 0.025, 0.15, 6.0, -4.46, mat.paperDark);
for (let i = 0; i < 3; i++) {
box(
scene,
0.5 - i * 0.07,
0.025,
0.01,
-0.98,
6.19 - i * 0.12,
-4.435,
mat.ink
);
}
// ------------------------------------------------------------
// Heavy voxel workbench
// ------------------------------------------------------------
const desk = new THREE.Group();
scene.add(desk);
// Separate top planks
for (let i = 0; i < 5; i++) {
const z = -2.48 + i * 1.24;
const plankMaterial = i % 2 === 0 ? mat.wood : mat.woodLight;
box(
desk,
12.8,
0.34,
1.17,
0,
3.34,
z,
plankMaterial,
true
);
}
box(desk, 12.5, 0.42, 0.35, 0, 2.96, 2.83, mat.woodDark, true);
box(desk, 12.5, 0.42, 0.35, 0, 2.96, -2.83, mat.woodDark, true);
box(desk, 0.35, 0.42, 5.4, -6.2, 2.96, 0, mat.woodDark, true);
box(desk, 0.35, 0.42, 5.4, 6.2, 2.96, 0, mat.woodDark, true);
for (const x of [-5.65, 5.65]) {
for (const z of [-2.25, 2.25]) {
box(desk, 0.58, 2.95, 0.58, x, 1.43, z, mat.woodDark, true);
box(desk, 0.78, 0.22, 0.78, x, 0.1, z, mat.woodEdge, true);
}
}
// Drawers and brass pulls
for (const x of [-3.55, 3.55]) {
box(desk, 3.2, 0.72, 0.16, x, 2.55, 2.99, mat.wood, true);
box(desk, 0.68, 0.08, 0.12, x, 2.55, 3.12, mat.brassDark);
for (const dx of [-0.28, 0.28]) {
box(desk, 0.08, 0.16, 0.11, x + dx, 2.55, 3.1, mat.brass);
}
}
// Lower stretcher
box(desk, 10.9, 0.25, 0.28, 0, 0.78, 0, mat.woodDark, true);
// ------------------------------------------------------------
// Historical oil lamp
// ------------------------------------------------------------
const lamp = new THREE.Group();
lamp.position.set(-4.65, 0, 0.1);
scene.add(lamp);
cylinder(lamp, 0.68, 0.2, 0, 3.64, 0, mat.brassDark, 12);
cylinder(lamp, 0.45, 0.22, 0, 3.83, 0, mat.brass, 12);
cylinder(lamp, 0.2, 0.78, 0, 4.25, 0, mat.brassDark, 10);
cylinder(lamp, 0.52, 0.18, 0, 4.64, 0, mat.brass, 12);
// Voxel glass chimney
box(lamp, 0.66, 0.75, 0.66, 0.26, 5.03, 0, mat.glass);
box(lamp, 0.52, 0.46, 0.52, 0.26, 5.57, 0, mat.glass);
box(lamp, 0.66, 0.1, 0.66, 0.26, 5.82, 0, mat.brassDark);
// Flame
box(lamp, 0.12, 0.3, 0.12, 0.29, 5.14, 0, mat.flame);
box(lamp, 0.08, 0.16, 0.08, 0.29, 5.21, 0, mat.flameCore);
// Wick/nozzle points toward the mirror
box(lamp, 0.38, 0.1, 0.12, 0.55, 4.69, 0, mat.brassDark);
// ------------------------------------------------------------
// Illumination mirror, geometrically aligned with the specimen
// ------------------------------------------------------------
const sourcePoint = new THREE.Vector3(-4.03, 5.15, 0.1);
const mirrorPoint = new THREE.Vector3(-2.85, 5.15, 0.1);
const specimenPoint = new THREE.Vector3(0.15, 4.03, 0.1);
const mirrorStand = new THREE.Group();
scene.add(mirrorStand);
box(mirrorStand, 1.35, 0.18, 0.9, -2.85, 3.62, 0.1, mat.iron, true);
cylinder(
mirrorStand,
0.11,
1.48,
-2.85,
4.4,
0.1,
mat.iron,
10
);
// Pivot block
box(mirrorStand, 0.35, 0.35, 0.35, -2.85, 5.08, 0.1, mat.brassDark, true);
const mirrorGroup = new THREE.Group();
mirrorGroup.position.copy(mirrorPoint);
scene.add(mirrorGroup);
const incoming = sourcePoint.clone().sub(mirrorPoint).normalize();
const outgoing = specimenPoint.clone().sub(mirrorPoint).normalize();
const mirrorNormal = incoming.clone().sub(outgoing).normalize();
mirrorGroup.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
mirrorNormal
);
box(mirrorGroup, 1.78, 1.18, 0.16, 0, 0, 0, mat.woodDark, true);
box(mirrorGroup, 1.53, 0.94, 0.055, 0, 0, 0.105, mat.mirror, true);
// Pixel-like reflected streaks
box(mirrorGroup, 0.12, 0.72, 0.015, -0.47, 0.02, 0.143, mat.mirrorGlint);
box(mirrorGroup, 0.065, 0.55, 0.015, -0.29, 0.1, 0.145, mat.mirrorGlint);
box(mirrorGroup, 0.045, 0.35, 0.015, -0.12, 0.18, 0.146, mat.mirrorGlint);
// Mirror adjustment knobs
cylinder(
mirrorStand,
0.22,
0.16,
-2.5,
5.05,
0.1,
mat.brass,
10,
0,
Math.PI / 2
);
// Visible voxel light path
addVoxelBeam(sourcePoint, mirrorPoint, 0.13);
addVoxelBeam(mirrorPoint, specimenPoint, 0.135);
// ------------------------------------------------------------
// Separate specimen support and glass slide
// ------------------------------------------------------------
const specimenSupport = new THREE.Group();
scene.add(specimenSupport);
box(specimenSupport, 1.85, 0.18, 1.28, 0.15, 3.61, 0.1, mat.iron, true);
box(specimenSupport, 1.46, 0.13, 0.92, 0.15, 3.78, 0.1, mat.ironBlack, true);
for (const x of [-0.48, 0.78]) {
box(specimenSupport, 0.15, 0.22, 0.88, x, 3.53, 0.1, mat.brassDark);
}
// Slide and specimen
box(specimenSupport, 1.08, 0.045, 0.4, 0.15, 3.88, 0.1, mat.glass);
box(specimenSupport, 0.16, 0.055, 0.38, -0.34, 3.91, 0.1, mat.paperDark);
const specimenCells = [
[-0.09, 0.03, 0.11, 0.08],
[0.03, 0.08, 0.12, 0.08],
[0.17, 0.02, 0.09, 0.07],
[-0.18, -0.03, 0.09, 0.07],
[0.09, -0.08, 0.11, 0.07],
[0.3, 0.04, 0.07, 0.08],
[-0.02, -0.04, 0.06, 0.05]
];
specimenCells.forEach((cell, index) => {
box(
specimenSupport,
cell[2],
cell[3],
cell[2],
0.15 + cell[0],
3.94 + cell[1],
0.1 + cell[3] * 0.18,
index % 2 ? mat.specimenDark : mat.specimen
);
});
// Stage knobs
cylinder(
specimenSupport,
0.17,
0.18,
0.98,
3.77,
0.1,
mat.brassDark,
10,
0,
Math.PI / 2
);
// ------------------------------------------------------------
// Historical brass lens instrument
// ------------------------------------------------------------
const antique = new THREE.Group();
scene.add(antique);
// Wooden plinth and brass sole plate
box(antique, 2.7, 0.34, 2.15, 2.02, 3.62, 0.02, mat.woodDark, true);
box(antique, 2.48, 0.16, 1.86, 2.02, 3.87, 0.02, mat.brassDark, true);
for (const x of [1.05, 3.0]) {
box(antique, 0.28, 0.17, 1.65, x, 3.45, 0.02, mat.brassDark);
}
// Rear column
box(antique, 0.5, 2.35, 0.52, 2.27, 5.08, -0.55, mat.wood, true);
box(antique, 0.56, 0.18, 0.58, 2.27, 4.08, -0.55, mat.brassDark, true);
box(antique, 0.58, 0.17, 0.59, 2.27, 6.13, -0.55, mat.brassDark, true);
// Focus rack teeth
for (let i = 0; i < 9; i++) {
box(
antique,
0.18,
0.065,
0.12,
2.0,
4.38 + i * 0.16,
-0.26,
mat.brass
);
}
// Stepped, block-built cantilever arm
box(antique, 2.45, 0.38, 0.52, 1.08, 6.3, -0.52, mat.woodDark, true);
box(antique, 0.58, 0.65, 0.62, 0.18, 5.98, -0.35, mat.brass, true);
box(antique, 0.58, 0.54, 0.58, 0.18, 5.51, 0.12, mat.brass, true);
// Objective barrel directly above the specimen
cylinder(antique, 0.43, 0.92, 0.15, 5.13, 0.1, mat.brass, 12);
cylinder(antique, 0.49, 0.12, 0.15, 4.76, 0.1, mat.brassDark, 12);
cylinder(antique, 0.49, 0.12, 0.15, 5.46, 0.1, mat.brassDark, 12);
cylinder(antique, 0.34, 0.065, 0.15, 4.67, 0.1, mat.lens, 16);
// Upper eyepiece
cylinder(antique, 0.31, 0.46, 0.15, 5.87, 0.1, mat.brassDark, 12);
cylinder(antique, 0.34, 0.08, 0.15, 6.08, 0.1, mat.brass, 12);
// Focus knobs
cylinder(
antique,
0.28,
0.26,
2.62,
5.14,
-0.53,
mat.brass,
10,
0,
Math.PI / 2
);
cylinder(
antique,
0.2,
0.22,
2.38,
4.66,
-0.55,
mat.brassDark,
10,
Math.PI / 2
);
// Small engraved brass plate
box(antique, 0.72, 0.22, 0.035, 2.08, 4.3, -0.255, mat.brass);
box(antique, 0.48, 0.025, 0.012, 2.08, 4.31, -0.232, mat.ink);
// ------------------------------------------------------------
// Desk accessories
// ------------------------------------------------------------
// Open field notebook
const notebook = new THREE.Group();
notebook.position.set(-2.55, 3.58, 1.72);
notebook.rotation.y = -0.14;
scene.add(notebook);
box(notebook, 2.05, 0.11, 1.3, 0, 0, 0, mat.woodDark, true);
box(notebook, 0.94, 0.06, 1.18, -0.5, 0.08, 0, mat.paper);
box(notebook, 0.94, 0.06, 1.18, 0.5, 0.08, 0, mat.paper);
box(notebook, 0.12, 0.075, 1.18, 0, 0.085, 0, mat.wood);
for (let i = 0; i < 4; i++) {
box(
notebook,
0.6,
0.012,
0.018,
-0.49,
0.115,
-0.38 + i * 0.24,
mat.ink
);
}
// Forceps
const forceps = new THREE.Group();
forceps.position.set(-0.8, 3.59, 1.85);
forceps.rotation.y = 0.38;
scene.add(forceps);
box(forceps, 1.25, 0.045, 0.07, 0, 0, 0.06, mat.iron);
box(forceps, 1.18, 0.045, 0.07, 0, 0, -0.06, mat.iron);
box(forceps, 0.28, 0.05, 0.18, 0.59, 0, 0, mat.brassDark);
// Specimen jars at the back-left
for (let i = 0; i < 3; i++) {
const x = -5.9 + i * 0.72;
const z = -1.85 + (i % 2) * 0.15;
cylinder(scene, 0.25, 0.62, x, 3.83, z, mat.glass, 10);
cylinder(scene, 0.27, 0.1, x, 4.18, z, mat.brassDark, 10);
box(scene, 0.32, 0.11, 0.32, x, 3.59, z, mat.woodDark);
}
// A small stack of slides
for (let i = 0; i < 5; i++) {
box(
scene,
0.78,
0.035,
0.32,
-1.2,
3.57 + i * 0.037,
-1.68,
i % 2 ? mat.glass : mat.paperDark
);
}
// ------------------------------------------------------------
// Subtle dust motes
// ------------------------------------------------------------
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(90 * 3);
for (let i = 0; i < 90; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 14;
dustPositions[i * 3 + 1] = 3.5 + Math.random() * 5;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 8;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xe7d6a6,
size: 0.035,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(dust);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, touch pinch, reset
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 3.25, 0);
const spherical = new THREE.Spherical(14.5, 1.12, 0.72);
const desiredSpherical = spherical.clone();
const pointers = new Map();
let lastX = 0;
let lastY = 0;
let lastPinchDistance = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function resetCamera() {
desiredSpherical.set(14.5, 1.12, 0.72);
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
desiredSpherical.theta -= dx * 0.006;
desiredSpherical.phi = clamp(
desiredSpherical.phi - dy * 0.006,
0.48,
1.43
);
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
desiredSpherical.radius = clamp(
desiredSpherical.radius * (lastPinchDistance / distance),
8.5,
21
);
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredSpherical.radius = clamp(
desiredSpherical.radius * Math.exp(event.deltaY * 0.001),
8.5,
21
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Screen-space callouts
// ------------------------------------------------------------
const labels = [
{
element: document.getElementById("illuminationLabel"),
position: new THREE.Vector3(-2.85, 5.95, 0.1)
},
{
element: document.getElementById("specimenLabel"),
position: new THREE.Vector3(0.15, 4.35, 0.1)
},
{
element: document.getElementById("lensLabel"),
position: new THREE.Vector3(0.15, 6.4, 0.1)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// ------------------------------------------------------------
// Animation and resize
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
const damping = 0.11;
spherical.radius +=
(desiredSpherical.radius - spherical.radius) * damping;
spherical.phi +=
(desiredSpherical.phi - spherical.phi) * damping;
spherical.theta +=
(desiredSpherical.theta - spherical.theta) * damping;
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
dust.rotation.y += 0.00015;
flameGlow();
updateLabels();
renderer.render(scene, camera);
}
const flame = box(
scene,
0.12,
0.3,
0.12,
-4.36,
5.14,
0.1,
mat.flame
);
const flameCore = box(
scene,
0.08,
0.16,
0.08,
-4.36,
5.21,
0.1,
mat.flameCore
);
function flameGlow() {
const flicker = 1 + Math.sin(performance.now() * 0.012) * 0.09;
flame.scale.y = flicker;
flameCore.scale.y = 1 / flicker;
lampLight.intensity = 27 + flicker * 2;
}
animate();
</script>
</body>
</html>
```