Prompt specification
Build or customize the Three.js 3D scene "Schematic eye lens and retinal screen" 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: Schematic eye lens and retinal screen
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/schematic-eye-lens-and-retinal-screen-x1033
Scene Description Prompt:
Create a standalone cutaway scene in one HTML file using Three.js from cdnjs. Model a transparent eye outline with corneal region, lens, pupil opening, and curved retinal screen; label optical surfaces simplified and distinguish pupil from lens.
Working Three.js Starter (schematic-eye-lens-and-retinal-screen-x1033):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transparent Eye — Anatomical Cutaway</title>
<style>
:root {
color-scheme: dark;
--text: #eaf7fb;
--muted: #8ca7b4;
--panel: rgba(7, 17, 25, 0.72);
--line: rgba(183, 226, 242, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 46%, #122a38 0%, #08131c 42%, #04090e 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 8;
opacity: 0.2;
background-image:
linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
background-size: 34px 34px;
mask-image: radial-gradient(circle at center, black, transparent 82%);
}
#stage {
position: fixed;
inset: 0;
z-index: 1;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
#leaders,
#labels {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
#leaders {
z-index: 3;
overflow: visible;
}
#labels {
z-index: 4;
}
.leader {
fill: none;
stroke-width: 1;
opacity: 0.8;
}
.anchor-dot {
stroke-width: 1.5;
fill: #08131c;
}
.callout {
position: absolute;
min-width: 156px;
max-width: 210px;
padding: 9px 11px 10px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-left: 2px solid var(--accent);
border-radius: 3px;
background:
linear-gradient(135deg, rgba(255,255,255,0.055), transparent 65%),
var(--panel);
box-shadow:
0 8px 30px rgba(0, 0, 0, 0.25),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
transform: translateY(-50%);
transition: opacity 160ms ease;
}
.callout-title {
display: block;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
line-height: 1.25;
text-transform: uppercase;
}
.callout-sub {
display: block;
margin-top: 4px;
color: #adc2cc;
font-size: 10px;
line-height: 1.35;
}
.header {
position: fixed;
z-index: 6;
top: 28px;
left: 30px;
max-width: 430px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: #74dff4;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: #74dff4;
box-shadow: 0 0 10px rgba(116, 223, 244, 0.7);
}
h1 {
margin: 11px 0 8px;
font-size: clamp(24px, 3vw, 42px);
font-weight: 520;
letter-spacing: -0.035em;
line-height: 1.03;
}
.subtitle {
max-width: 390px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.view-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 14px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(9, 20, 29, 0.54);
color: #b6cad3;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.view-badge i {
width: 5px;
height: 5px;
border-radius: 50%;
background: #ffab62;
box-shadow: 0 0 9px #ffab62;
}
.legend {
position: fixed;
z-index: 6;
left: 28px;
bottom: 26px;
width: min(350px, calc(100vw - 56px));
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 5px;
background: var(--panel);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
color: #698695;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 18px 70px 1fr;
align-items: center;
gap: 5px;
margin-top: 7px;
font-size: 10px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
justify-self: center;
}
.swatch.pupil {
background: #ff9b50;
box-shadow: 0 0 9px rgba(255, 155, 80, 0.65);
}
.swatch.lens {
background: #74e4ff;
box-shadow: 0 0 9px rgba(116, 228, 255, 0.65);
}
.legend-key {
color: #d8e8ee;
font-weight: 700;
letter-spacing: 0.05em;
}
.legend-value {
color: #8fa8b4;
}
.controls {
position: fixed;
z-index: 7;
right: 28px;
bottom: 27px;
display: flex;
align-items: center;
gap: 9px;
}
.hint {
color: #728b98;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
button {
appearance: none;
border: 1px solid rgba(169, 220, 238, 0.22);
border-radius: 4px;
padding: 9px 12px;
background: rgba(8, 19, 27, 0.8);
color: #c6dbe4;
font: inherit;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.06em;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 150ms ease,
color 150ms ease,
background 150ms ease;
}
button:hover {
border-color: rgba(116, 223, 244, 0.65);
background: rgba(16, 39, 50, 0.9);
color: #eafaff;
}
.scale-note {
position: fixed;
z-index: 6;
right: 29px;
top: 30px;
color: #607b88;
font-size: 9px;
letter-spacing: 0.1em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
}
.hidden {
opacity: 0 !important;
visibility: hidden;
}
@media (max-width: 700px) {
.header {
top: 20px;
left: 20px;
right: 20px;
}
.subtitle {
max-width: 300px;
font-size: 11px;
}
.scale-note {
display: none;
}
.legend {
left: 18px;
bottom: 18px;
width: 240px;
}
.controls {
right: 18px;
bottom: 18px;
}
.hint {
display: none;
}
.callout {
min-width: 125px;
max-width: 150px;
padding: 7px 8px;
}
.callout-sub {
display: none;
}
.callout-title {
font-size: 9px;
}
}
@media (max-width: 440px) {
.legend {
width: 210px;
}
.legend-row {
grid-template-columns: 16px 55px 1fr;
font-size: 9px;
}
.subtitle {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive transparent eye anatomical cutaway"></main>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<header class="header">
<div class="eyebrow">Optical anatomy / simplified</div>
<h1>Transparent eye cutaway</h1>
<p class="subtitle">
A layered view of the anterior optical surfaces, the dark pupil aperture,
the refractive lens, and the curved retinal screen.
</p>
<div class="view-badge"><i></i> Cutaway inspection model</div>
</header>
<div class="scale-note">
Simplified geometry<br>
Not anatomically to scale
</div>
<aside class="legend" aria-label="Pupil and lens distinction">
<div class="legend-title">Reading the anterior segment</div>
<div class="legend-row">
<span class="swatch pupil"></span>
<span class="legend-key">Pupil</span>
<span class="legend-value">Dark opening in the iris</span>
</div>
<div class="legend-row">
<span class="swatch lens"></span>
<span class="legend-key">Lens</span>
<span class="legend-value">Transparent refractive body</span>
</div>
</aside>
<div class="controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="labelsButton" type="button">Hide labels</button>
<button id="resetButton" type="button">Reset view</button>
</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 stage = document.querySelector("#stage");
const labelRoot = document.querySelector("#labels");
const leaderRoot = document.querySelector("#leaders");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const model = new THREE.Group();
scene.add(model);
const hemisphere = new THREE.HemisphereLight(0xd9f5ff, 0x081019, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xeafaff, 3.2);
keyLight.position.set(-4, 5, 6);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65cfff, 2.0);
rimLight.position.set(5, 1, -4);
scene.add(rimLight);
const retinalLight = new THREE.PointLight(0xff6a42, 4.2, 6, 2);
retinalLight.position.set(1.1, 0.2, 1.4);
scene.add(retinalLight);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function makeLine(points, color, opacity = 1, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.055,
gapSize: 0.075,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
if (dashed) line.computeLineDistances();
return line;
}
function makeCirclePoints(x, radius, segments = 96) {
const points = [];
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
points.push(
new THREE.Vector3(
x,
radius * Math.cos(angle),
radius * Math.sin(angle)
)
);
}
return points;
}
// Surface of revolution around the optical X axis.
function makeAxialSurface(
segments,
rings,
maxTheta,
radiusAt,
xAt
) {
const positions = [];
const indices = [];
for (let ring = 0; ring <= rings; ring++) {
const theta = (ring / rings) * maxTheta;
const radius = radiusAt(theta);
const x = xAt(theta);
for (let segment = 0; segment <= segments; segment++) {
const phi = (segment / segments) * Math.PI * 2;
positions.push(
x,
radius * Math.cos(phi),
radius * Math.sin(phi)
);
}
}
for (let ring = 0; ring < rings; ring++) {
for (let segment = 0; segment < segments; segment++) {
const a = ring * (segments + 1) + segment;
const b = (ring + 1) * (segments + 1) + segment;
const c = b + 1;
const d = a + 1;
indices.push(a, d, b, b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
// -------------------------------------------------------------------------
// Transparent outer eye and cut edge
// -------------------------------------------------------------------------
const globeCenterX = 0.12;
const globeRadiusX = 1.62;
const globeRadiusY = 1.14;
const globeRadiusZ = 1.12;
const ghostGlobe = new THREE.Mesh(
new THREE.SphereGeometry(1, 72, 48),
new THREE.MeshPhysicalMaterial({
color: 0xa9d8e8,
roughness: 0.42,
transparent: true,
opacity: 0.045,
side: THREE.DoubleSide,
depthWrite: false
})
);
ghostGlobe.scale.set(
globeRadiusX,
globeRadiusY,
globeRadiusZ
);
ghostGlobe.position.x = globeCenterX;
model.add(ghostGlobe);
// The lower half is more visible, creating the cutaway reading.
const cutawayShell = new THREE.Mesh(
new THREE.SphereGeometry(
1,
72,
36,
0,
Math.PI * 2,
Math.PI / 2,
Math.PI / 2
),
new THREE.MeshPhysicalMaterial({
color: 0x8dc9de,
roughness: 0.3,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
})
);
cutawayShell.scale.set(
globeRadiusX,
globeRadiusY,
globeRadiusZ
);
cutawayShell.position.x = globeCenterX;
model.add(cutawayShell);
// Sagittal outer silhouette.
const silhouettePoints = [];
for (let i = 0; i <= 160; i++) {
const angle = (i / 160) * Math.PI * 2;
silhouettePoints.push(
new THREE.Vector3(
globeCenterX + globeRadiusX * Math.cos(angle),
globeRadiusY * Math.sin(angle),
0
)
);
}
model.add(makeLine(silhouettePoints, 0x8abccc, 0.42));
// Equatorial cut line.
const cutEdgePoints = [];
for (let i = 0; i <= 160; i++) {
const angle = (i / 160) * Math.PI * 2;
cutEdgePoints.push(
new THREE.Vector3(
globeCenterX + globeRadiusX * Math.cos(angle),
0,
globeRadiusZ * Math.sin(angle)
)
);
}
model.add(makeLine(cutEdgePoints, 0x9ed9ec, 0.62));
// Very subtle vitreous volume.
const vitreous = new THREE.Mesh(
new THREE.SphereGeometry(1, 64, 40),
new THREE.MeshPhysicalMaterial({
color: 0x80c6d6,
roughness: 0.65,
transparent: true,
opacity: 0.022,
side: THREE.DoubleSide,
depthWrite: false
})
);
vitreous.scale.set(1.43, 0.98, 0.98);
vitreous.position.x = 0.26;
model.add(vitreous);
// -------------------------------------------------------------------------
// Transparent corneal cap
// -------------------------------------------------------------------------
const corneaEdgeX = -1.05;
const corneaBulge = 0.72;
const corneaRadius = 0.82;
const corneaMaxTheta = 1.25;
const corneaGeometry = makeAxialSurface(
80,
34,
corneaMaxTheta,
theta => corneaRadius * Math.sin(theta),
theta => corneaEdgeX - corneaBulge * Math.cos(theta)
);
const cornea = new THREE.Mesh(
corneaGeometry,
new THREE.MeshPhysicalMaterial({
color: 0x72dcff,
roughness: 0.07,
metalness: 0,
transmission: 0.16,
transparent: true,
opacity: 0.27,
thickness: 0.18,
ior: 1.376,
clearcoat: 1,
clearcoatRoughness: 0.05,
side: THREE.DoubleSide,
depthWrite: false
})
);
model.add(cornea);
const corneaRimX =
corneaEdgeX - corneaBulge * Math.cos(corneaMaxTheta);
const corneaRimRadius =
corneaRadius * Math.sin(corneaMaxTheta);
model.add(
makeLine(
makeCirclePoints(corneaRimX, corneaRimRadius),
0x8de7ff,
0.66
)
);
// Corneal meridians.
for (const side of [-1, 1]) {
const points = [];
for (let i = 0; i <= 80; i++) {
const theta = (i / 80) * corneaMaxTheta;
points.push(
new THREE.Vector3(
corneaEdgeX - corneaBulge * Math.cos(theta),
side * corneaRadius * Math.sin(theta),
0
)
);
}
model.add(makeLine(points, 0x8ce8ff, 0.5));
}
// -------------------------------------------------------------------------
// Iris and pupil: the pupil is the dark aperture in the iris
// -------------------------------------------------------------------------
const irisX = -1.075;
const pupilRadius = 0.285;
const irisOuterRadius = 0.55;
const iris = new THREE.Mesh(
new THREE.RingGeometry(pupilRadius, irisOuterRadius, 112),
new THREE.MeshStandardMaterial({
color: 0x259c9c,
roughness: 0.42,
metalness: 0.05,
emissive: 0x073d42,
emissiveIntensity: 0.32,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9
})
);
iris.rotation.y = -Math.PI / 2;
iris.position.x = irisX;
model.add(iris);
// Radial iris fibers.
const irisFiberPositions = [];
for (let i = 0; i < 72; i++) {
const angle = (i / 72) * Math.PI * 2;
irisFiberPositions.push(
irisX + 0.002,
pupilRadius * 1.04 * Math.cos(angle),
pupilRadius * 1.04 * Math.sin(angle),
irisX + 0.002,
irisOuterRadius * 0.95 * Math.cos(angle),
irisOuterRadius * 0.95 * Math.sin(angle)
);
}
const irisFiberGeometry = new THREE.BufferGeometry();
irisFiberGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(irisFiberPositions, 3)
);
model.add(
new THREE.LineSegments(
irisFiberGeometry,
new THREE.LineBasicMaterial({
color: 0x78e1d6,
transparent: true,
opacity: 0.34,
depthWrite: false
})
)
);
const pupil = new THREE.Mesh(
new THREE.CircleGeometry(pupilRadius, 112),
new THREE.MeshBasicMaterial({
color: 0x02080d,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.98
})
);
pupil.rotation.y = -Math.PI / 2;
pupil.position.x = irisX - 0.006;
model.add(pupil);
const pupilRim = new THREE.Mesh(
new THREE.TorusGeometry(pupilRadius, 0.011, 12, 112),
new THREE.MeshStandardMaterial({
color: 0xffa05d,
emissive: 0xff6c2c,
emissiveIntensity: 0.6,
roughness: 0.35
})
);
pupilRim.rotation.y = -Math.PI / 2;
pupilRim.position.x = irisX - 0.012;
model.add(pupilRim);
model.add(
makeLine(
makeCirclePoints(irisX - 0.013, pupilRadius),
0xffb26e,
0.86
)
);
// -------------------------------------------------------------------------
// Transparent crystalline lens
// -------------------------------------------------------------------------
const lensCenterX = -0.63;
const lensThickness = 0.24;
const lensRadius = 0.46;
const lens = new THREE.Mesh(
new THREE.SphereGeometry(1, 72, 48),
new THREE.MeshPhysicalMaterial({
color: 0x81e4ff,
roughness: 0.045,
metalness: 0,
transmission: 0.28,
transparent: true,
opacity: 0.36,
thickness: 0.55,
ior: 1.42,
clearcoat: 1,
clearcoatRoughness: 0.03,
side: THREE.DoubleSide,
depthWrite: false
})
);
lens.scale.set(lensThickness, lensRadius, lensRadius);
lens.position.x = lensCenterX;
model.add(lens);
// Lens profile outlines emphasize that it is a solid refractive body.
for (const axis of ["y", "z"]) {
const points = [];
for (let i = 0; i <= 120; i++) {
const angle = (i / 120) * Math.PI * 2;
const x = lensCenterX + lensThickness * Math.cos(angle);
const r = lensRadius * Math.sin(angle);
points.push(
axis === "y"
? new THREE.Vector3(x, r, 0)
: new THREE.Vector3(x, 0, r)
);
}
model.add(makeLine(points, 0x7de8ff, 0.42));
}
// Small lens highlight.
const lensHighlight = [];
for (let i = 0; i <= 36; i++) {
const t = i / 36;
const angle = THREE.MathUtils.lerp(1.15, 1.75, t);
lensHighlight.push(
new THREE.Vector3(
lensCenterX + lensThickness * Math.cos(angle) * 1.015,
lensRadius * Math.sin(angle) * 1.015,
0
)
);
}
model.add(makeLine(lensHighlight, 0xffffff, 0.58));
// -------------------------------------------------------------------------
// Curved retinal screen with an illuminated grid
// -------------------------------------------------------------------------
const retinaMaxTheta = 0.92;
const retinaRadius = 1.0;
const retinaBulge = 1.48;
const retinaGeometry = makeAxialSurface(
96,
36,
retinaMaxTheta,
theta => retinaRadius * Math.sin(theta),
theta => globeCenterX + retinaBulge * Math.cos(theta)
);
const retina = new THREE.Mesh(
retinaGeometry,
new THREE.MeshStandardMaterial({
color: 0xff674f,
emissive: 0x7b160c,
emissiveIntensity: 0.42,
roughness: 0.68,
metalness: 0,
transparent: true,
opacity: 0.68,
side: THREE.DoubleSide,
depthWrite: false
})
);
model.add(retina);
// Concentric curved grid rings.
for (let ring = 1; ring <= 7; ring++) {
const theta = (ring / 7) * retinaMaxTheta;
const radius = retinaRadius * Math.sin(theta);
const x = globeCenterX + retinaBulge * Math.cos(theta);
const points = [];
for (let segment = 0; segment <= 96; segment++) {
const phi = (segment / 96) * Math.PI * 2;
points.push(
new THREE.Vector3(
x,
radius * Math.cos(phi),
radius * Math.sin(phi)
)
);
}
model.add(makeLine(points, 0xffb08a, 0.42));
}
// Radial grid meridians.
for (let meridian = 0; meridian < 16; meridian++) {
const phi = (meridian / 16) * Math.PI * 2;
const points = [];
for (let step = 0; step <= 48; step++) {
const theta = (step / 48) * retinaMaxTheta;
const radius = retinaRadius * Math.sin(theta);
const x = globeCenterX + retinaBulge * Math.cos(theta);
points.push(
new THREE.Vector3(
x,
radius * Math.cos(phi),
radius * Math.sin(phi)
)
);
}
model.add(makeLine(points, 0xffc2a6, 0.35));
}
// Sparse photoreceptor-like points.
let randomSeed = 37;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const receptorPositions = [];
for (let i = 0; i < 420; i++) {
const theta = Math.sqrt(random()) * retinaMaxTheta;
const phi = random() * Math.PI * 2;
const radius = retinaRadius * Math.sin(theta);
const x = globeCenterX + retinaBulge * Math.cos(theta) - 0.008;
receptorPositions.push(
x,
radius * Math.cos(phi),
radius * Math.sin(phi)
);
}
const receptorGeometry = new THREE.BufferGeometry();
receptorGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(receptorPositions, 3)
);
model.add(
new THREE.Points(
receptorGeometry,
new THREE.PointsMaterial({
color: 0xffd1a8,
size: 0.027,
transparent: true,
opacity: 0.8,
sizeAttenuation: true,
depthWrite: false
})
)
);
// Simplified optical axis.
model.add(
makeLine(
[
new THREE.Vector3(-1.74, 0, 0),
new THREE.Vector3(1.52, 0, 0)
],
0xf2d59b,
0.34,
true
)
);
// -------------------------------------------------------------------------
// HTML/SVG callouts projected from 3D anchors
// -------------------------------------------------------------------------
const callouts = [
{
title: "Cornea",
sub: "Transparent anterior optical surface",
anchor: new THREE.Vector3(-1.68, 0.40, 0.18),
offset: [-155, -92],
color: "#79def7"
},
{
title: "Iris / Diaphragm",
sub: "Muscular ring surrounding the opening",
anchor: new THREE.Vector3(-1.075, 0.43, 0),
offset: [-215, 0],
color: "#6de0c8"
},
{
title: "Pupil",
sub: "Dark aperture in the iris",
anchor: new THREE.Vector3(-1.09, 0, 0),
offset: [-150, 82],
color: "#ff9b50"
},
{
title: "Crystalline lens",
sub: "Transparent biconvex refractive body",
anchor: new THREE.Vector3(-0.64, 0.20, 0.03),
offset: [-48, -128],
color: "#79e5ff"
},
{
title: "Retinal screen",
sub: "Curved posterior receptor surface",
anchor: new THREE.Vector3(1.36, 0.28, 0.16),
offset: [72, -100],
color: "#ff866d"
},
{
title: "Scleral outline",
sub: "Transparent outer globe / cut edge",
anchor: new THREE.Vector3(0.40, -0.86, 0),
offset: [85, 62],
color: "#91b7c7"
}
];
const svgNS = "http://www.w3.org/2000/svg";
for (const callout of callouts) {
const element = document.createElement("div");
element.className = "callout";
element.style.setProperty("--accent", callout.color);
element.innerHTML = `
<span class="callout-title">${callout.title}</span>
<span class="callout-sub">${callout.sub}</span>
`;
labelRoot.appendChild(element);
const path = document.createElementNS(svgNS, "path");
path.setAttribute("class", "leader");
path.setAttribute("stroke", callout.color);
leaderRoot.appendChild(path);
const dot = document.createElementNS(svgNS, "circle");
dot.setAttribute("class", "anchor-dot");
dot.setAttribute("r", "3");
dot.setAttribute("stroke", callout.color);
leaderRoot.appendChild(dot);
callout.element = element;
callout.path = path;
callout.dot = dot;
}
function updateCallouts() {
const width = window.innerWidth;
const height = window.innerHeight;
const offsetScale = THREE.MathUtils.clamp(width / 1050, 0.58, 1);
for (const callout of callouts) {
const projected = callout.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
const screenX = (projected.x * 0.5 + 0.5) * width;
const screenY = (-projected.y * 0.5 + 0.5) * height;
const element = callout.element;
const elementWidth = element.offsetWidth;
const elementHeight = element.offsetHeight;
const desiredX = screenX + callout.offset[0] * offsetScale;
const desiredY = screenY + callout.offset[1] * offsetScale;
const x = THREE.MathUtils.clamp(
desiredX,
12,
Math.max(12, width - elementWidth - 12)
);
const y = THREE.MathUtils.clamp(
desiredY,
76,
Math.max(76, height - elementHeight - 118)
);
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = visible ? "1" : "0";
let attachX;
let attachY;
if (screenX >= x && screenX <= x + elementWidth) {
attachX = screenX;
attachY = screenY < y ? y : y + elementHeight;
} else {
attachX = screenX < x ? x : x + elementWidth;
attachY = y + elementHeight * 0.5;
}
const elbowX = attachX + (screenX < attachX ? -16 : 16);
callout.path.setAttribute(
"d",
`M ${screenX.toFixed(2)} ${screenY.toFixed(2)}
L ${elbowX.toFixed(2)} ${screenY.toFixed(2)}
L ${attachX.toFixed(2)} ${attachY.toFixed(2)}`
);
callout.path.style.opacity = visible ? "0.8" : "0";
callout.dot.setAttribute("cx", screenX.toFixed(2));
callout.dot.setAttribute("cy", screenY.toFixed(2));
callout.dot.style.opacity = visible ? "1" : "0";
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan, keyboard and touch
// -------------------------------------------------------------------------
const spherical = new THREE.Spherical();
const initialPhi = -0.72;
const initialTheta = 1.24;
function preferredRadius() {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 0.9 ? 9.5 : aspect < 1.25 ? 8.2 : 7.25;
}
const current = {
radius: preferredRadius(),
phi: initialPhi,
theta: initialTheta,
target: new THREE.Vector3()
};
const desired = {
radius: current.radius,
phi: current.phi,
theta: current.theta,
target: current.target.clone()
};
const clock = new THREE.Clock();
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointer = null;
function updateCamera() {
spherical.set(
current.radius,
current.phi,
current.theta
);
camera.position.setFromSpherical(spherical).add(current.target);
camera.lookAt(current.target);
}
function resetView() {
desired.radius = preferredRadius();
desired.phi = initialPhi;
desired.theta = initialTheta;
desired.target.set(0, 0, 0);
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1);
const panScale = desired.radius * 0.0013;
desired.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
desired.target.x = THREE.MathUtils.clamp(
desired.target.x, -1.8, 1.8
);
desired.target.y = THREE.MathUtils.clamp(
desired.target.y, -1.2, 1.2
);
} else {
desired.phi -= dx * 0.006;
desired.theta = THREE.MathUtils.clamp(
desired.theta - dy * 0.005,
0.22,
Math.PI - 0.22
);
}
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
4.4,
11.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
document.querySelector("#resetButton").addEventListener("click", resetView);
let labelsVisible = true;
const labelsButton = document.querySelector("#labelsButton");
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelRoot.classList.toggle("hidden", !labelsVisible);
leaderRoot.classList.toggle("hidden", !labelsVisible);
labelsButton.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "l") {
labelsButton.click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
leaderRoot.setAttribute(
"viewBox",
`0 0 ${window.innerWidth} ${window.innerHeight}`
);
});
leaderRoot.setAttribute(
"viewBox",
`0 0 ${window.innerWidth} ${window.innerHeight}`
);
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
updateCamera();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-delta * 10);
current.radius +=
(desired.radius - current.radius) * damping;
current.phi +=
(desired.phi - current.phi) * damping;
current.theta +=
(desired.theta - current.theta) * damping;
current.target.lerp(desired.target, damping);
updateCamera();
updateCallouts();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```