Prompt specification
Build or customize the Three.js 3D scene "Simple lens over a patterned specimen" 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: Simple lens over a patterned specimen
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/simple-lens-over-a-patterned-specimen-x2505
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a scene with a convex lens above a patterned specimen tile. Show an enlarged viewing inset and label the difference between physical specimen size and displayed magnification. Stylized solid forms.
Working Three.js Starter (simple-lens-over-a-patterned-specimen-x2505):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Convex Lens — Specimen Magnification Study</title>
<style>
:root {
color-scheme: dark;
--bg: #050d14;
--panel: #0b1720;
--panel-2: #101f29;
--line: rgba(157, 203, 214, 0.16);
--line-strong: rgba(157, 203, 214, 0.3);
--text: #eaf3f4;
--muted: #8ca6b0;
--aqua: #59dfcc;
--aqua-soft: rgba(89, 223, 204, 0.12);
--coral: #ff8c76;
--amber: #f2c96c;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
min-height: 100vh;
overflow-x: hidden;
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
.app {
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
min-height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 16px 24px;
border-bottom: 1px solid var(--line);
background: rgba(5, 13, 20, 0.9);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 39px;
height: 39px;
flex: 0 0 auto;
display: grid;
place-items: center;
border: 1px solid rgba(89, 223, 204, 0.45);
border-radius: 12px;
background: var(--aqua-soft);
color: var(--aqua);
}
.brand-mark svg {
width: 24px;
height: 24px;
}
.brand-copy {
min-width: 0;
}
.eyebrow {
margin: 0 0 4px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(16px, 2vw, 21px);
font-weight: 650;
letter-spacing: -0.025em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header-status {
display: flex;
align-items: center;
gap: 9px;
color: #a8c0c8;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--aqua);
box-shadow: 0 0 14px var(--aqua);
}
.workspace {
flex: 1;
display: grid;
grid-template-columns: minmax(0, 1.75fr) minmax(340px, 0.8fr);
gap: 18px;
padding: 18px;
}
.stage,
.inspector {
border: 1px solid var(--line);
border-radius: 20px;
overflow: hidden;
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
}
.stage {
position: relative;
min-height: 640px;
isolation: isolate;
background:
radial-gradient(circle at 50% 30%, rgba(43, 98, 109, 0.24), transparent 34%),
linear-gradient(155deg, #0c1b25 0%, #07131c 58%, #050d14 100%);
}
#mainCanvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#mainCanvas:active {
cursor: grabbing;
}
.stage-heading {
position: absolute;
z-index: 3;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.stage-heading h2 {
margin: 3px 0 5px;
font-size: clamp(22px, 3vw, 34px);
line-height: 1.05;
font-weight: 620;
letter-spacing: -0.045em;
}
.stage-heading p {
max-width: 430px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.lens-chip {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
border: 1px solid var(--line-strong);
border-radius: 999px;
background: rgba(7, 19, 28, 0.72);
color: #bdd2d8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
backdrop-filter: blur(12px);
}
.lens-chip::before {
content: "";
width: 7px;
height: 7px;
border: 1px solid var(--aqua);
border-radius: 50%;
box-shadow: 0 0 9px rgba(89, 223, 204, 0.7);
}
.stage-footer {
position: absolute;
z-index: 3;
left: 20px;
right: 20px;
bottom: 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.control-hint {
display: flex;
align-items: center;
gap: 9px;
color: #91a9b2;
font-size: 11px;
}
.control-hint svg {
width: 17px;
height: 17px;
color: var(--aqua);
}
.scale-tag {
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(5, 13, 20, 0.68);
color: #9fb5bd;
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.callout {
position: absolute;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid rgba(148, 196, 207, 0.28);
border-radius: 9px;
background: rgba(6, 17, 25, 0.84);
color: #d9e7e9;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(10px);
}
.callout::before {
content: "";
width: 7px;
height: 7px;
flex: 0 0 auto;
border: 2px solid var(--aqua);
border-radius: 50%;
box-shadow: 0 0 10px rgba(89, 223, 204, 0.7);
}
.callout.specimen::before {
border-color: var(--coral);
box-shadow: 0 0 10px rgba(255, 140, 118, 0.65);
}
.inspector {
display: flex;
flex-direction: column;
padding: 18px;
background:
linear-gradient(180deg, rgba(18, 36, 47, 0.78), rgba(8, 19, 27, 0.96));
}
.inspector-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-bottom: 14px;
}
.inspector-head h2 {
margin: 2px 0 0;
font-size: 19px;
font-weight: 650;
letter-spacing: -0.025em;
}
.badge {
padding: 7px 10px;
border: 1px solid rgba(89, 223, 204, 0.34);
border-radius: 999px;
background: var(--aqua-soft);
color: var(--aqua);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
white-space: nowrap;
}
.inset-frame {
position: relative;
aspect-ratio: 1.24 / 1;
min-height: 235px;
overflow: hidden;
border: 1px solid var(--line-strong);
border-radius: 15px;
background: #06151b;
box-shadow:
inset 0 0 40px rgba(0, 0, 0, 0.28),
0 12px 30px rgba(0, 0, 0, 0.18);
}
#insetCanvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
.inset-grid {
position: absolute;
inset: 0;
pointer-events: none;
opacity: 0.16;
background-image:
linear-gradient(rgba(167, 235, 230, 0.15) 1px, transparent 1px),
linear-gradient(90deg, rgba(167, 235, 230, 0.15) 1px, transparent 1px);
background-size: 25% 25%;
}
.inset-label {
position: absolute;
top: 11px;
left: 12px;
z-index: 2;
display: flex;
align-items: center;
gap: 7px;
color: #d9f2ef;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
pointer-events: none;
}
.inset-label::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--aqua);
box-shadow: 0 0 9px var(--aqua);
}
.crosshair {
position: absolute;
top: 50%;
left: 50%;
z-index: 2;
width: 18px;
height: 18px;
transform: translate(-50%, -50%);
pointer-events: none;
opacity: 0.65;
}
.crosshair::before,
.crosshair::after {
content: "";
position: absolute;
background: rgba(220, 255, 251, 0.8);
}
.crosshair::before {
top: 8px;
left: 0;
width: 18px;
height: 1px;
}
.crosshair::after {
top: 0;
left: 8px;
width: 1px;
height: 18px;
}
.scale-bar {
position: absolute;
z-index: 2;
right: 13px;
bottom: 13px;
width: 25%;
color: #e6f8f6;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-align: center;
pointer-events: none;
}
.scale-bar::before {
content: "";
display: block;
height: 6px;
margin-bottom: 4px;
border-right: 1px solid #e6f8f6;
border-bottom: 1px solid #e6f8f6;
border-left: 1px solid #e6f8f6;
}
.inset-field {
position: absolute;
z-index: 2;
top: 12px;
right: 12px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 7px;
background: rgba(4, 14, 20, 0.62);
color: #b9d0d5;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 13px;
}
.metric {
min-width: 0;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(4, 14, 21, 0.42);
}
.metric.physical {
border-color: rgba(255, 140, 118, 0.28);
background: rgba(255, 140, 118, 0.055);
}
.metric-label {
display: block;
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric strong {
display: block;
color: var(--text);
font-size: clamp(22px, 3vw, 30px);
font-weight: 620;
line-height: 1;
letter-spacing: -0.045em;
}
.metric strong small {
color: #a9c0c7;
font-size: 11px;
font-weight: 700;
letter-spacing: 0;
}
.metric p {
margin: 8px 0 0;
color: #829ca5;
font-size: 10px;
line-height: 1.45;
}
.formula {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 3px 12px;
margin-top: 12px;
padding: 14px 15px;
border: 1px solid rgba(89, 223, 204, 0.25);
border-radius: 13px;
background: var(--aqua-soft);
}
.formula span {
color: #a9c9cd;
font-size: 13px;
font-weight: 650;
}
.formula b {
grid-row: span 2;
color: var(--aqua);
font-size: 29px;
font-weight: 650;
letter-spacing: -0.04em;
}
.formula small {
color: #83a4a8;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.note {
display: flex;
gap: 10px;
margin-top: 12px;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(4, 14, 21, 0.34);
color: #91aab2;
font-size: 11px;
line-height: 1.55;
}
.note svg {
width: 16px;
height: 16px;
flex: 0 0 auto;
margin-top: 1px;
color: var(--amber);
}
.note strong {
color: #d8e6e8;
font-weight: 700;
}
.inspector-footer {
margin-top: auto;
padding-top: 14px;
color: #647f89;
font-size: 9px;
line-height: 1.55;
letter-spacing: 0.035em;
}
@media (max-width: 980px) {
.workspace {
grid-template-columns: 1fr;
}
.stage {
min-height: 570px;
}
.inspector {
min-height: auto;
}
}
@media (max-width: 600px) {
header {
padding: 13px 15px;
}
.header-status {
display: none;
}
.workspace {
padding: 10px;
gap: 10px;
}
.stage {
min-height: 520px;
border-radius: 16px;
}
.stage-heading {
top: 16px;
left: 16px;
right: 16px;
}
.stage-heading p {
max-width: 255px;
font-size: 11px;
}
.lens-chip {
display: none;
}
.inspector {
padding: 14px;
border-radius: 16px;
}
.metrics {
gap: 8px;
}
.metric {
padding: 12px;
}
.stage-footer {
left: 14px;
right: 14px;
bottom: 13px;
}
.scale-tag {
display: none;
}
.callout {
font-size: 8px;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M7 4h10l1.5 8-6.5 8-6.5-8L7 4Z" stroke="currentColor" stroke-width="1.4"/>
<path d="M12 4v16M7 4l5 3 5-3" stroke="currentColor" stroke-width="1.1" opacity=".7"/>
</svg>
</div>
<div class="brand-copy">
<p class="eyebrow">Optical study / specimen 07</p>
<h1>Lens & Specimen Magnification</h1>
</div>
</div>
<div class="header-status">
<span class="status-dot"></span>
Interactive 3D model
</div>
</header>
<main class="workspace">
<section class="stage" id="stage" aria-label="Interactive 3D lens and specimen scene">
<canvas id="mainCanvas" aria-label="3D scene of a convex lens above a patterned specimen tile"></canvas>
<div class="stage-heading">
<div>
<p class="eyebrow">Fig. 01 / optical inspection</p>
<h2>A magnified field of view</h2>
<p>
A stylized biconvex lens hovers above a patterned 24 mm specimen tile.
Drag the scene to inspect the arrangement.
</p>
</div>
<div class="lens-chip">Illustrative lens · f ≈ 60 mm</div>
</div>
<div class="callout" id="lensCallout">Bi-convex lens</div>
<div class="callout specimen" id="specimenCallout">24 mm specimen tile</div>
<div class="stage-footer">
<div class="control-hint">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M9 11V6a2 2 0 1 1 4 0v5-3a2 2 0 1 1 4 0v4-2a2 2 0 1 1 4 0v6c0 4-3 7-7 7h-1c-2.8 0-4.7-1.4-6-3.5L3.5 13a2 2 0 0 1 3.2-2.4L9 13v-2Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Drag to orbit · scroll to zoom
</div>
<div class="scale-tag">Not to physical scale</div>
</div>
</section>
<aside class="inspector" aria-label="Magnification measurements">
<div class="inspector-head">
<div>
<p class="eyebrow">Enlarged viewing inset</p>
<h2>Displayed specimen detail</h2>
</div>
<div class="badge">3.0× view</div>
</div>
<div class="inset-frame">
<canvas id="insetCanvas" aria-label="Enlarged top-down view of the patterned specimen"></canvas>
<div class="inset-grid"></div>
<div class="inset-label">Live specimen view</div>
<div class="inset-field">8 mm field</div>
<div class="crosshair"></div>
<div class="scale-bar">2 mm</div>
</div>
<div class="metrics">
<div class="metric physical">
<span class="metric-label">Physical specimen size</span>
<strong>24 × 18 <small>mm</small></strong>
<p>The actual dimensions of the complete tile.</p>
</div>
<div class="metric">
<span class="metric-label">Displayed field</span>
<strong>8 <small>mm wide</small></strong>
<p>The portion visible inside the enlarged inset.</p>
</div>
</div>
<div class="formula">
<span>24 mm ÷ 8 mm</span>
<b>= 3.0×</b>
<small>Displayed / apparent magnification</small>
</div>
<div class="note">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="1.5"/>
<path d="M12 10v6M12 7.2v.2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
</svg>
<div>
<strong>Magnification is not a change in size.</strong>
The specimen remains 24 mm wide. The inset simply shows an
8 mm field at 3× on screen.
</div>
</div>
<div class="inspector-footer">
Model dimensions are illustrative. Screen magnification describes the
displayed field relative to the complete physical specimen.
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const mainCanvas = document.getElementById("mainCanvas");
const insetCanvas = document.getElementById("insetCanvas");
const palette = [
0xef7768,
0xf0c766,
0x5bc5b6,
0x718fd0,
0xd783b5,
0xe9a568
];
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
function createSpecimenPattern(parent, baseY, detailed = false) {
const random = seededRandom(74017);
const group = new THREE.Group();
parent.add(group);
const nodeGeometry = new THREE.SphereGeometry(0.105, 18, 12);
const dotGeometry = new THREE.SphereGeometry(0.027, 10, 8);
for (let row = 0; row < 6; row++) {
for (let column = 0; column < 8; column++) {
const x = -1.4 + column * 0.4;
const z = -1.0 + row * 0.4;
const radius = 0.085 + random() * 0.035;
const color = palette[Math.floor(random() * palette.length)];
const node = new THREE.Mesh(
nodeGeometry,
new THREE.MeshStandardMaterial({
color,
roughness: 0.66,
metalness: 0.02
})
);
node.position.set(x, baseY + 0.055, z);
node.scale.set(radius / 0.105, 0.36, radius / 0.105);
group.add(node);
if (detailed || random() > 0.48) {
const dot = new THREE.Mesh(
dotGeometry,
new THREE.MeshStandardMaterial({
color: 0xf8f1df,
roughness: 0.75
})
);
dot.position.set(
x + (random() - 0.5) * 0.07,
baseY + 0.095,
z + (random() - 0.5) * 0.07
);
group.add(dot);
}
}
}
return group;
}
/* ---------------------------- Main scene ---------------------------- */
const renderer = new THREE.WebGLRenderer({
canvas: mainCanvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x081923, 13, 24);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 50);
const cameraTarget = new THREE.Vector3(0, 1.48, 0);
const orbit = {
theta: 0.72,
phi: 1.16,
radius: 9.2,
dragging: false,
previousX: 0,
previousY: 0
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xbceef4, 0x12202b, 2.0));
const keyLight = new THREE.DirectionalLight(0xdff9ff, 3.4);
keyLight.position.set(5, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x59dfcc, 1.4);
fillLight.position.set(-6, 4, 3);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xff9c82, 1.0);
rimLight.position.set(2, 5, -7);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x061018,
roughness: 0.95,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.295;
floor.receiveShadow = true;
scene.add(floor);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(4.15, 4.5, 0.36, 72),
new THREE.MeshStandardMaterial({
color: 0x142833,
roughness: 0.76,
metalness: 0.08
})
);
plinth.position.y = -0.1;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
for (const radius of [2.4, 3.15, 3.85]) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(radius, radius + 0.018, 96),
new THREE.MeshBasicMaterial({
color: 0x4ca99f,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.086;
scene.add(ring);
}
const tileBase = new THREE.Mesh(
new THREE.BoxGeometry(3.2, 0.18, 2.4),
new THREE.MeshStandardMaterial({
color: 0xd9e2df,
roughness: 0.72,
metalness: 0.02
})
);
tileBase.position.y = 0.2;
tileBase.castShadow = true;
tileBase.receiveShadow = true;
scene.add(tileBase);
const tileSurface = new THREE.Mesh(
new THREE.BoxGeometry(2.98, 0.045, 2.18),
new THREE.MeshStandardMaterial({
color: 0xcbd9d4,
roughness: 0.85
})
);
tileSurface.position.y = 0.305;
tileSurface.receiveShadow = true;
scene.add(tileSurface);
const grid = new THREE.GridHelper(3.0, 8, 0x638b8b, 0x638b8b);
grid.position.y = 0.331;
grid.scale.z = 0.73;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
createSpecimenPattern(scene, 0.335, true);
const lensAssembly = new THREE.Group();
lensAssembly.position.set(-0.42, 3.08, 0);
scene.add(lensAssembly);
const lensProfile = [
new THREE.Vector2(0, -0.29),
new THREE.Vector2(0.42, -0.265),
new THREE.Vector2(0.82, -0.19),
new THREE.Vector2(1.12, -0.085),
new THREE.Vector2(1.25, 0),
new THREE.Vector2(1.12, 0.085),
new THREE.Vector2(0.82, 0.19),
new THREE.Vector2(0.42, 0.265),
new THREE.Vector2(0, 0.29)
];
const lens = new THREE.Mesh(
new THREE.LatheGeometry(lensProfile, 72),
new THREE.MeshPhysicalMaterial({
color: 0x8be5df,
roughness: 0.12,
metalness: 0,
transmission: 0.18,
thickness: 0.55,
ior: 1.46,
clearcoat: 1,
clearcoatRoughness: 0.08,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide,
depthWrite: false
})
);
lens.renderOrder = 2;
lensAssembly.add(lens);
const lensRim = new THREE.Mesh(
new THREE.TorusGeometry(1.255, 0.065, 12, 96),
new THREE.MeshStandardMaterial({
color: 0x8fc9cf,
roughness: 0.3,
metalness: 0.52
})
);
lensRim.rotation.x = Math.PI / 2;
lensAssembly.add(lensRim);
const handle = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 1.65, 24),
new THREE.MeshStandardMaterial({
color: 0x234752,
roughness: 0.62,
metalness: 0.18
})
);
handle.rotation.z = Math.PI / 2;
handle.position.x = 1.98;
handle.castShadow = true;
lensAssembly.add(handle);
const grip = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.145, 0.92, 28),
new THREE.MeshStandardMaterial({
color: 0x112a34,
roughness: 0.86,
metalness: 0.03
})
);
grip.rotation.z = Math.PI / 2;
grip.position.x = 2.4;
grip.castShadow = true;
lensAssembly.add(grip);
const connector = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.3, 24),
new THREE.MeshStandardMaterial({
color: 0x759aa2,
roughness: 0.38,
metalness: 0.48
})
);
connector.rotation.z = Math.PI / 2;
connector.position.x = 1.24;
lensAssembly.add(connector);
const rayPositions = new Float32Array([
-1.48, 2.78, -1.08, -0.53, 0.35, -0.40,
-1.48, 2.78, 1.08, -0.53, 0.35, 0.40,
0.64, 2.78, -1.08, 0.53, 0.35, -0.40,
0.64, 2.78, 1.08, 0.53, 0.35, 0.40
]);
const rayGeometry = new THREE.BufferGeometry();
rayGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rayPositions, 3)
);
const rays = new THREE.LineSegments(
rayGeometry,
new THREE.LineBasicMaterial({
color: 0x65dfd0,
transparent: true,
opacity: 0.28
})
);
scene.add(rays);
const lensCallout = document.getElementById("lensCallout");
const specimenCallout = document.getElementById("specimenCallout");
function placeCallout(element, worldPosition, offsetX, offsetY) {
const projected = worldPosition.clone().project(camera);
const width = stage.clientWidth;
const height = stage.clientHeight;
const x = (projected.x * 0.5 + 0.5) * width + offsetX;
const y = (-projected.y * 0.5 + 0.5) * height + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
}
function resizeMain() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
new ResizeObserver(resizeMain).observe(stage);
resizeMain();
/* -------------------- Direct camera interaction -------------------- */
mainCanvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
orbit.dragging = true;
orbit.previousX = event.clientX;
orbit.previousY = event.clientY;
mainCanvas.setPointerCapture(event.pointerId);
});
mainCanvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const deltaX = event.clientX - orbit.previousX;
const deltaY = event.clientY - orbit.previousY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.005,
0.35,
1.43
);
orbit.previousX = event.clientX;
orbit.previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
orbit.dragging = false;
if (mainCanvas.hasPointerCapture(event.pointerId)) {
mainCanvas.releasePointerCapture(event.pointerId);
}
}
mainCanvas.addEventListener("pointerup", endDrag);
mainCanvas.addEventListener("pointercancel", endDrag);
mainCanvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
6.2,
13.5
);
updateCamera();
},
{ passive: false }
);
/* ---------------------------- Inset scene ---------------------------- */
const insetRenderer = new THREE.WebGLRenderer({
canvas: insetCanvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
insetRenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
insetRenderer.outputColorSpace = THREE.SRGBColorSpace;
insetRenderer.toneMapping = THREE.ACESFilmicToneMapping;
insetRenderer.toneMappingExposure = 1.12;
insetRenderer.shadowMap.enabled = true;
insetRenderer.shadowMap.type = THREE.PCFSoftShadowMap;
const insetScene = new THREE.Scene();
insetScene.background = new THREE.Color(0x06151b);
const insetCamera = new THREE.OrthographicCamera(-0.5333, 0.5333, 0.43, -0.43, 0.1, 20);
insetCamera.position.set(0, 6, 0);
insetCamera.up.set(0, 0, -1);
insetCamera.lookAt(0, 0, 0);
insetScene.add(new THREE.HemisphereLight(0xd8ffff, 0x19323b, 2.1));
const insetKey = new THREE.DirectionalLight(0xffffff, 3.0);
insetKey.position.set(2, 7, 4);
insetKey.castShadow = true;
insetKey.shadow.mapSize.set(1024, 1024);
insetKey.shadow.camera.left = -3;
insetKey.shadow.camera.right = 3;
insetKey.shadow.camera.top = 3;
insetKey.shadow.camera.bottom = -3;
insetScene.add(insetKey);
const insetFill = new THREE.DirectionalLight(0x63d8ce, 1.1);
insetFill.position.set(-4, 3, -2);
insetScene.add(insetFill);
const insetTile = new THREE.Mesh(
new THREE.BoxGeometry(3.2, 0.12, 2.4),
new THREE.MeshStandardMaterial({
color: 0xe2e9e3,
roughness: 0.82
})
);
insetTile.position.y = -0.04;
insetTile.receiveShadow = true;
insetScene.add(insetTile);
const insetSurface = new THREE.Mesh(
new THREE.BoxGeometry(2.98, 0.025, 2.18),
new THREE.MeshStandardMaterial({
color: 0xcbd9d2,
roughness: 0.9
})
);
insetSurface.position.y = 0.035;
insetSurface.receiveShadow = true;
insetScene.add(insetSurface);
const insetGrid = new THREE.GridHelper(3, 8, 0x527d7b, 0x527d7b);
insetGrid.position.y = 0.051;
insetGrid.scale.z = 0.73;
insetGrid.material.transparent = true;
insetGrid.material.opacity = 0.14;
insetScene.add(insetGrid);
createSpecimenPattern(insetScene, 0.055, true);
function resizeInset() {
const width = insetCanvas.clientWidth;
const height = insetCanvas.clientHeight;
const aspect = width / Math.max(height, 1);
/*
The complete tile is 24 mm wide and represented by 3.2 world units.
An 8 mm field therefore spans 3.2 × (8 / 24) = 1.0667 units.
*/
const fieldWidth = 3.2 * (8 / 24);
const halfWidth = fieldWidth / 2;
const halfHeight = halfWidth / aspect;
insetCamera.left = -halfWidth;
insetCamera.right = halfWidth;
insetCamera.top = halfHeight;
insetCamera.bottom = -halfHeight;
insetCamera.updateProjectionMatrix();
insetRenderer.setSize(width, height, false);
}
new ResizeObserver(resizeInset).observe(insetCanvas.parentElement);
resizeInset();
/* ------------------------------ Loop ------------------------------ */
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
insetRenderer.render(insetScene, insetCamera);
placeCallout(
lensCallout,
new THREE.Vector3(-0.42, 3.2, 0),
82,
-22
);
placeCallout(
specimenCallout,
new THREE.Vector3(-1.35, 0.36, 0.78),
-18,
34
);
}
animate();
</script>
</body>
</html>
```