Prompt specification
Build or customize the Three.js 3D scene "Reading desk optics exhibit" 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: Reading desk optics exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/reading-desk-optics-exhibit-x1035
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a scene with a book, distant window, and enlarged eye inset with selectable targets; show a labeled approximation of accommodation without diagnostic interpretation or prescription values. Voxel style.
Working Three.js Starter (reading-desk-optics-exhibit-x1035):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="An interactive voxel-style illustration of approximate accommodation, with selectable near and distant visual targets."
/>
<title>Accommodation — Voxel Sketch</title>
<style>
:root {
color-scheme: light;
--ink: #142d32;
--muted: #607477;
--panel: rgba(247, 250, 247, 0.94);
--panel-solid: #f7faf7;
--line: rgba(20, 45, 50, 0.16);
--lime: #c9f36a;
--lime-dark: #6d8f19;
--teal: #1c7771;
--orange: #ff9d57;
--navy: #102b32;
--shadow: 0 18px 60px rgba(22, 51, 56, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe6e5;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
z-index: 0;
outline: none;
touch-action: none;
}
#scene:focus-visible {
outline: 3px solid var(--lime);
outline-offset: -5px;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.masthead {
position: absolute;
top: 28px;
left: 32px;
width: min(460px, calc(100vw - 64px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 3px;
background: var(--lime-dark);
box-shadow: 8px 0 0 rgba(109, 143, 25, 0.35);
}
h1 {
margin: 0;
max-width: 440px;
font-size: clamp(31px, 4vw, 54px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 820;
}
.masthead p {
max-width: 390px;
margin: 14px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.target-label {
position: absolute;
z-index: 3;
transform: translate(-50%, -100%);
display: flex;
align-items: center;
gap: 8px;
min-height: 34px;
padding: 8px 12px;
border: 1px solid rgba(20, 45, 50, 0.18);
border-radius: 999px;
background: rgba(250, 252, 248, 0.9);
color: var(--ink);
box-shadow: 0 8px 24px rgba(22, 51, 56, 0.12);
backdrop-filter: blur(10px);
pointer-events: auto;
cursor: pointer;
font-size: 11px;
font-weight: 760;
letter-spacing: 0.025em;
white-space: nowrap;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.target-label:hover {
transform: translate(-50%, calc(-100% - 2px));
border-color: rgba(109, 143, 25, 0.55);
}
.target-label[aria-pressed="true"] {
border-color: rgba(109, 143, 25, 0.75);
background: rgba(238, 249, 209, 0.95);
}
.target-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: #a8b7b6;
box-shadow: 0 0 0 3px rgba(168, 183, 182, 0.17);
}
.target-label[aria-pressed="true"] .target-dot {
background: var(--lime-dark);
box-shadow: 0 0 0 3px rgba(109, 143, 25, 0.17);
}
.control-card {
position: absolute;
left: 28px;
bottom: 28px;
width: 340px;
padding: 19px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.card-kicker {
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.control-card h2 {
margin: 6px 0 14px;
font-size: 21px;
line-height: 1.12;
letter-spacing: -0.035em;
}
.target-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.target-button {
min-height: 58px;
padding: 11px 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.target-button:hover {
transform: translateY(-1px);
border-color: rgba(109, 143, 25, 0.5);
}
.target-button[aria-checked="true"] {
border-color: var(--lime-dark);
background: #edf8d5;
box-shadow: inset 0 0 0 1px rgba(109, 143, 25, 0.12);
}
.button-icon {
display: inline-grid;
place-items: center;
width: 22px;
height: 22px;
margin-right: 5px;
border-radius: 5px;
background: #dce7e5;
vertical-align: middle;
}
.target-button[aria-checked="true"] .button-icon {
background: var(--lime);
}
.button-title {
font-size: 12px;
font-weight: 800;
}
.button-subtitle {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
line-height: 1.2;
}
.readout {
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.readout-top {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
}
.readout-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#lensState {
font-size: 16px;
letter-spacing: -0.02em;
}
.qual-track {
position: relative;
height: 8px;
margin-top: 12px;
border-radius: 99px;
background: linear-gradient(90deg, #b9d5d0, var(--lime));
}
#lensMarker {
position: absolute;
top: 50%;
left: 14%;
width: 14px;
height: 14px;
border: 3px solid var(--panel-solid);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 6px rgba(20, 45, 50, 0.28);
transform: translate(-50%, -50%);
transition: left 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.track-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
.light-note {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 12px;
padding: 9px 10px;
border-radius: 9px;
background: rgba(28, 119, 113, 0.07);
font-size: 10px;
}
.light-note span:first-child {
color: var(--muted);
}
.light-note strong {
font-weight: 800;
}
.disclaimer {
margin: 13px 0 0;
color: #6b7778;
font-size: 9.5px;
line-height: 1.45;
}
.inset-card {
position: absolute;
top: 28px;
right: 28px;
width: 420px;
overflow: hidden;
border: 1px solid rgba(16, 43, 50, 0.24);
border-radius: 18px;
background: transparent;
box-shadow: var(--shadow);
pointer-events: none;
}
.inset-head {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 57px;
padding: 0 16px;
background: var(--navy);
color: #f2f8f4;
pointer-events: none;
}
.inset-title {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.schematic-badge {
padding: 5px 8px;
border: 1px solid rgba(201, 243, 106, 0.35);
border-radius: 999px;
color: var(--lime);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#eyeViewport {
position: relative;
height: 262px;
background: transparent;
pointer-events: none;
}
.viewport-caption {
position: absolute;
left: 13px;
top: 12px;
z-index: 3;
color: rgba(233, 247, 242, 0.65);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
}
.viewport-legend {
position: absolute;
right: 12px;
bottom: 10px;
display: flex;
gap: 11px;
color: rgba(233, 247, 242, 0.7);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 13px;
height: 3px;
background: #ffc266;
}
.legend-swatch.mint {
background: #8df0bb;
}
.part-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
padding: 10px 12px 8px;
background: var(--navy);
pointer-events: auto;
}
.part-button {
min-height: 31px;
border: 1px solid rgba(233, 247, 242, 0.16);
border-radius: 8px;
background: rgba(255, 255, 255, 0.055);
color: rgba(233, 247, 242, 0.72);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
.part-button:hover,
.part-button[aria-pressed="true"] {
border-color: rgba(201, 243, 106, 0.55);
background: rgba(201, 243, 106, 0.12);
color: var(--lime);
}
#partInfo {
min-height: 68px;
padding: 9px 13px 12px;
background: var(--navy);
color: rgba(233, 247, 242, 0.72);
pointer-events: none;
}
#partInfo strong {
display: block;
margin-bottom: 4px;
color: #f2f8f4;
font-size: 11px;
}
#partInfo span {
display: block;
font-size: 9.5px;
line-height: 1.42;
}
.interaction-hint {
position: absolute;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(20, 45, 50, 0.12);
border-radius: 999px;
background: rgba(247, 250, 247, 0.78);
color: #536769;
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.045em;
white-space: nowrap;
}
.reset-button {
position: absolute;
right: 28px;
bottom: 28px;
min-height: 38px;
padding: 9px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(247, 250, 247, 0.9);
color: var(--ink);
box-shadow: 0 8px 26px rgba(22, 51, 56, 0.12);
backdrop-filter: blur(10px);
pointer-events: auto;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
.reset-button:hover {
background: #f4f9e7;
}
.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;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #dbe6e5;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
pointer-events: none;
}
#loading.hidden {
opacity: 0;
}
@media (max-width: 900px) {
.masthead {
top: 22px;
left: 22px;
width: 360px;
}
.masthead h1 {
font-size: 38px;
}
.masthead p {
max-width: 320px;
}
.inset-card {
top: 20px;
right: 20px;
width: 370px;
}
#eyeViewport {
height: 230px;
}
.control-card {
left: 20px;
bottom: 20px;
width: 315px;
}
.reset-button {
right: 20px;
bottom: 20px;
}
}
@media (max-width: 700px) {
.masthead {
top: 15px;
left: 16px;
width: calc(100vw - 32px);
}
.masthead h1 {
max-width: 250px;
font-size: 30px;
}
.masthead p {
display: none;
}
.eyebrow {
margin-bottom: 7px;
font-size: 9px;
}
.inset-card {
top: 100px;
right: 12px;
width: min(350px, calc(100vw - 24px));
border-radius: 14px;
}
#eyeViewport {
height: 195px;
}
.inset-head {
min-height: 47px;
}
#partInfo {
min-height: 58px;
}
.control-card {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 14px;
border-radius: 15px;
}
.control-card h2 {
margin-bottom: 10px;
font-size: 18px;
}
.target-button {
min-height: 50px;
}
.readout {
margin-top: 11px;
padding-top: 11px;
}
.disclaimer {
margin-top: 10px;
}
.interaction-hint,
.reset-button {
display: none;
}
.target-label {
display: none;
}
}
@media (max-height: 700px) and (min-width: 701px) {
.masthead p {
display: none;
}
.inset-card {
top: 18px;
}
#eyeViewport {
height: 205px;
}
.control-card {
bottom: 18px;
padding: 14px;
}
.control-card h2 {
margin-bottom: 10px;
}
.readout {
margin-top: 10px;
padding-top: 10px;
}
.disclaimer {
margin-top: 9px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional room with a book, a distant window, and selectable visual targets. Drag to orbit, scroll to zoom, and use the labeled buttons to select a target."
></canvas>
<div id="loading">Building voxel scene…</div>
<main class="hud">
<header class="masthead">
<div class="eyebrow">Interactive optics sketch</div>
<h1>Accommodation,<br />in voxels.</h1>
<p>
Choose a visual target and compare a schematic, qualitative change in
lens shape. The enlarged eye inset shows the simplified optical idea.
</p>
</header>
<button
id="windowLabel"
class="target-label"
data-target="window"
type="button"
aria-pressed="true"
>
<span class="target-dot"></span>
Distant target · Window
</button>
<button
id="bookLabel"
class="target-label"
data-target="book"
type="button"
aria-pressed="false"
>
<span class="target-dot"></span>
Near target · Book
</button>
<section class="control-card" aria-labelledby="targetHeading">
<div class="card-kicker">Selectable targets</div>
<h2 id="targetHeading">Where are you looking?</h2>
<div class="target-buttons" id="targetControls" role="radiogroup" aria-label="Visual target">
<button
class="target-button"
data-target="window"
type="button"
role="radio"
aria-checked="true"
>
<span class="button-icon" aria-hidden="true">▦</span>
<span class="button-title">Distant window</span>
<span class="button-subtitle">Far visual target</span>
</button>
<button
class="target-button"
data-target="book"
type="button"
role="radio"
aria-checked="false"
>
<span class="button-icon" aria-hidden="true">▤</span>
<span class="button-title">Near book</span>
<span class="button-subtitle">Close visual target</span>
</button>
</div>
<div class="readout" aria-live="polite">
<div class="readout-top">
<span class="readout-label">Approximate lens shape</span>
<strong id="lensState">Flatter</strong>
</div>
<div class="qual-track" aria-hidden="true">
<span id="lensMarker"></span>
</div>
<div class="track-labels" aria-hidden="true">
<span>Flatter</span>
<span>More rounded</span>
</div>
<div class="light-note">
<span>Incoming light</span>
<strong id="lightState">Parallel · schematic</strong>
</div>
</div>
<p class="disclaimer">
Approximation for education only. Not a diagnostic test, clinical
interpretation, measurement, or prescription.
</p>
</section>
<aside class="inset-card" aria-labelledby="insetTitle">
<div class="inset-head">
<div id="insetTitle" class="inset-title">Enlarged eye inset</div>
<div class="schematic-badge">Approximation</div>
</div>
<div id="eyeViewport" aria-label="Enlarged schematic cross-section of an eye">
<div class="viewport-caption">Click a square marker</div>
<div class="viewport-legend" aria-hidden="true">
<span class="legend-item"><i class="legend-swatch"></i>Incoming</span>
<span class="legend-item"><i class="legend-swatch mint"></i>Converging</span>
</div>
</div>
<div class="part-row" aria-label="Select an eye structure">
<button class="part-button" data-part="cornea" type="button" aria-pressed="false">
Cornea
</button>
<button class="part-button" data-part="lens" type="button" aria-pressed="true">
Lens
</button>
<button class="part-button" data-part="retina" type="button" aria-pressed="false">
Retina
</button>
</div>
<div id="partInfo" aria-live="polite">
<strong>Lens</strong>
<span>
A schematic curvature change suggests accommodation: flatter for the
distant target and more rounded for the near target.
</span>
</div>
</aside>
<div class="interaction-hint">
Drag to orbit · Scroll to zoom · Click a target
</div>
<button id="resetButton" class="reset-button" type="button">
Reset view
</button>
<div id="liveStatus" class="sr-only" aria-live="polite"></div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and shared state
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const eyeViewport = document.querySelector("#eyeViewport");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe6e5);
scene.fog = new THREE.Fog(0xdbe6e5, 18, 37);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
theta: 0.48,
phi: 1.14,
radius: 15.8,
target: new THREE.Vector3(-1.05, 2.45, -1.05)
};
let selectedTarget = "window";
let rayMix = 0;
let elapsed = 0;
const prefersReducedMotion =
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(
parent,
size,
position,
mat,
{ cast = true, receive = true } = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Main room
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xf4fff8,
0x7c8f85,
2.05
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d8, 3.1);
sun.position.set(-5, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaed9dc, 1.15);
fill.position.set(8, 5, -5);
scene.add(fill);
const floorMaterial = material(0xb9c9c4);
const wallMaterial = material(0xe6ece6);
const deskMaterial = material(0xaa7453);
const deskEdgeMaterial = material(0x80543d);
const darkWood = material(0x5f4336);
const pageMaterial = material(0xf6efd9, { roughness: 0.96 });
const inkMaterial = material(0x607779);
const floor = addBox(
scene,
[24, 0.25, 20],
[0, -0.2, -1.2],
floorMaterial,
{ cast: false }
);
// Floor seams emphasize the voxel grid.
for (let x = -10; x <= 10; x += 2) {
addBox(
scene,
[0.035, 0.015, 19],
[x, -0.065, -1],
material(0xa5b7b2),
{ cast: false }
);
}
for (let z = -9; z <= 7; z += 2) {
addBox(
scene,
[23, 0.015, 0.035],
[0, -0.064, z],
material(0xa5b7b2),
{ cast: false }
);
}
const backWall = addBox(
scene,
[24, 10.5, 0.4],
[0, 5, -8.55],
wallMaterial,
{ cast: false }
);
const leftWall = addBox(
scene,
[0.4, 10.5, 18],
[-10.4, 5, -0.5],
material(0xd8e2dc),
{ cast: false }
);
// Sparse wall blocks give the room a constructed, modular appearance.
const wallBlockMaterial = material(0xdce5df);
for (let y = 1; y <= 8; y += 2) {
addBox(
scene,
[0.06, 0.06, 12],
[-10.17, y, -0.7],
wallBlockMaterial,
{ cast: false }
);
}
// Desk.
const desk = new THREE.Group();
scene.add(desk);
addBox(desk, [10.6, 0.34, 5.7], [-1.1, 1.02, 1.65], deskMaterial);
addBox(desk, [10.2, 0.12, 5.3], [-1.1, 0.79, 1.65], deskEdgeMaterial);
for (const x of [-5.55, 3.35]) {
for (const z of [-0.3, 3.55]) {
addBox(desk, [0.55, 1.45, 0.55], [x, 0.25, z], darkWood);
}
}
// Desk plank seams.
for (const z of [-0.25, 1.0, 2.25, 3.5]) {
addBox(
desk,
[10.25, 0.012, 0.035],
[-1.1, 1.195, z],
material(0x8f6047),
{ cast: false }
);
}
// -------------------------------------------------------------------------
// Distant voxel window
// -------------------------------------------------------------------------
const windowGroup = new THREE.Group();
scene.add(windowGroup);
const skyGlass = material(0x91cad0, {
emissive: 0x518b94,
emissiveIntensity: 0.25,
roughness: 0.55
});
const windowFrameMaterial = material(0xf0eee3, {
emissive: 0x000000,
emissiveIntensity: 0
});
const windowCenterX = -2.8;
const windowCenterY = 4.65;
addBox(
windowGroup,
[5.65, 3.95, 0.1],
[windowCenterX, windowCenterY, -8.22],
skyGlass,
{ cast: false }
);
// Pixel-like sky.
const skyMaterials = [
material(0x9fd5d8, { emissive: 0x477d82, emissiveIntensity: 0.2 }),
material(0xb8e1df, { emissive: 0x5b9693, emissiveIntensity: 0.18 }),
material(0x7ebcc8, { emissive: 0x326d78, emissiveIntensity: 0.2 })
];
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 9; col++) {
const x = windowCenterX - 2.36 + col * 0.59;
const y = windowCenterY - 1.48 + row * 0.59;
if ((row === 1 && col > 1 && col < 6) ||
(row === 2 && col > 3 && col < 7)) {
addBox(
windowGroup,
[0.55, 0.55, 0.035],
[x, y, -8.145],
material(0xe6eee5, {
emissive: 0x7b8d82,
emissiveIntensity: 0.12
}),
{ cast: false }
);
} else {
addBox(
windowGroup,
[0.55, 0.55, 0.035],
[x, y, -8.145],
skyMaterials[(row + col) % skyMaterials.length],
{ cast: false }
);
}
}
}
// Window frame.
addBox(
windowGroup,
[0.24, 4.18, 0.28],
[windowCenterX - 2.87, windowCenterY, -8.0],
windowFrameMaterial
);
addBox(
windowGroup,
[0.24, 4.18, 0.28],
[windowCenterX + 2.87, windowCenterY, -8.0],
windowFrameMaterial
);
addBox(
windowGroup,
[5.95, 0.24, 0.28],
[windowCenterX, windowCenterY - 2.02, -8.0],
windowFrameMaterial
);
addBox(
windowGroup,
[5.95, 0.24, 0.28],
[windowCenterX, windowCenterY + 2.02, -8.0],
windowFrameMaterial
);
addBox(
windowGroup,
[0.14, 3.82, 0.18],
[windowCenterX, windowCenterY, -7.94],
windowFrameMaterial
);
addBox(
windowGroup,
[5.62, 0.14, 0.18],
[windowCenterX, windowCenterY, -7.94],
windowFrameMaterial
);
addBox(
windowGroup,
[6.25, 0.23, 0.68],
[windowCenterX, windowCenterY - 2.13, -7.82],
windowFrameMaterial
);
const windowLight = new THREE.PointLight(0xb8edf0, 4.2, 11, 2);
windowLight.position.set(windowCenterX, windowCenterY, -7.2);
scene.add(windowLight);
// -------------------------------------------------------------------------
// Open voxel book
// -------------------------------------------------------------------------
const bookGroup = new THREE.Group();
bookGroup.position.set(-1.65, 1.22, 1.5);
bookGroup.rotation.y = -0.16;
scene.add(bookGroup);
const coverMaterial = material(0x285f5d, {
roughness: 0.72
});
const pageEdgeMaterial = material(0xe8dfc8);
const bookmarkMaterial = material(0xf08b54);
addBox(bookGroup, [2.18, 0.13, 3.45], [-1.09, 0.08, 0], coverMaterial);
addBox(bookGroup, [2.18, 0.13, 3.45], [1.09, 0.08, 0], coverMaterial);
addBox(bookGroup, [1.99, 0.27, 3.23], [-1.04, 0.27, 0], pageMaterial);
addBox(bookGroup, [1.99, 0.27, 3.23], [1.04, 0.27, 0], pageMaterial);
addBox(bookGroup, [0.18, 0.27, 3.35], [0, 0.25, 0], pageEdgeMaterial);
// Page stacks.
for (const side of [-1, 1]) {
for (let i = 0; i < 4; i++) {
addBox(
bookGroup,
[1.94, 0.018, 3.15],
[side * 1.04, 0.15 + i * 0.045, 0],
i % 2 ? pageMaterial : pageEdgeMaterial
);
}
}
// Printed page lines.
for (const side of [-1, 1]) {
for (let row = 0; row < 8; row++) {
const lineWidth = row % 3 === 0 ? 1.42 : 1.68;
addBox(
bookGroup,
[lineWidth, 0.018, 0.035],
[side * 1.04, 0.422, -1.15 + row * 0.31],
inkMaterial,
{ cast: false }
);
}
}
// Central spine and bookmark.
addBox(bookGroup, [0.18, 0.18, 3.5], [0, 0.18, 0], coverMaterial);
addBox(bookGroup, [0.13, 0.025, 0.95], [0.19, 0.44, 1.18], bookmarkMaterial);
// A small block of stacked books on the opposite side.
const stack = new THREE.Group();
stack.position.set(2.55, 1.27, 2.4);
stack.rotation.y = 0.13;
scene.add(stack);
addBox(stack, [2.1, 0.28, 2.75], [0, 0.14, 0], material(0xd78358));
addBox(stack, [1.95, 0.23, 2.62], [0.08, 0.39, 0.03], material(0xe9ddc1));
addBox(stack, [2.0, 0.24, 2.68], [0, 0.62, 0], material(0x477879));
// -------------------------------------------------------------------------
// Active-target corner brackets
// -------------------------------------------------------------------------
const bracketMaterial = new THREE.MeshBasicMaterial({
color: 0xc9f36a,
transparent: true,
opacity: 0.95
});
function createBracket(width, height, depth, arm = 0.42) {
const group = new THREE.Group();
const x = width / 2;
const y = height / 2;
for (const sx of [-1, 1]) {
for (const sy of [-1, 1]) {
addBox(
group,
[arm, 0.075, 0.075],
[sx * (x - arm / 2), sy * y, 0],
bracketMaterial,
{ cast: false, receive: false }
);
addBox(
group,
[0.075, arm, 0.075],
[sx * x, sy * (y - arm / 2), 0],
bracketMaterial,
{ cast: false, receive: false }
);
}
}
return group;
}
const windowBracket = createBracket(6.2, 4.4, 0.12, 0.5);
windowBracket.position.set(windowCenterX, windowCenterY, -7.75);
scene.add(windowBracket);
const bookBracket = createBracket(4.7, 0.8, 3.75, 0.32);
bookBracket.position.set(-1.65, 1.68, 1.5);
scene.add(bookBracket);
// -------------------------------------------------------------------------
// Raycast registration for room targets
// -------------------------------------------------------------------------
const targetMeshes = [];
function registerTarget(group, type) {
group.traverse((object) => {
if (object.isMesh) {
object.userData.target = type;
targetMeshes.push(object);
}
});
}
registerTarget(windowGroup, "window");
registerTarget(bookGroup, "book");
// -------------------------------------------------------------------------
// Enlarged eye inset scene
// -------------------------------------------------------------------------
const eyeScene = new THREE.Scene();
eyeScene.background = new THREE.Color(0x102b32);
const eyeCamera = new THREE.OrthographicCamera(
-8,
8,
5.5,
-5.5,
0.1,
50
);
eyeCamera.position.set(0, 0, 10);
eyeCamera.lookAt(0, 0, 0);
eyeScene.add(new THREE.HemisphereLight(0xe9fff7, 0x173a42, 2.2));
const eyeLight = new THREE.DirectionalLight(0xffffff, 2.2);
eyeLight.position.set(-3, 5, 7);
eyeScene.add(eyeLight);
const eyeFill = new THREE.DirectionalLight(0x8de2d4, 1.0);
eyeFill.position.set(4, -2, 5);
eyeScene.add(eyeFill);
const shellMaterial = material(0x4b9f98, {
emissive: 0x153f3f,
emissiveIntensity: 0.32,
roughness: 0.76
});
const retinaMaterial = material(0xe47a67, {
emissive: 0x7d2f2a,
emissiveIntensity: 0.45
});
const corneaMaterial = material(0x7dd8d4, {
emissive: 0x277e82,
emissiveIntensity: 0.48,
roughness: 0.48
});
const lensMaterial = material(0xf2bd61, {
emissive: 0x8a561c,
emissiveIntensity: 0.48,
roughness: 0.46
});
// The eye shell is constructed from a grid of cube instances.
const shellPoints = [];
const retinaPoints = [];
const spacing = 0.31;
for (let ix = -16; ix <= 16; ix++) {
const x = ix * spacing;
for (let iy = -10; iy <= 10; iy++) {
const y = iy * spacing;
const q =
(x * x) / (5.05 * 5.05) +
(y * y) / (3.05 * 3.05);
if (q <= 1 && q >= 0.70) {
if (x > 3.72) {
retinaPoints.push([x, y]);
} else {
shellPoints.push([x, y]);
}
}
}
}
const dummy = new THREE.Object3D();
function createVoxelInstances(points, mat, z = -0.08) {
const geometry = new THREE.BoxGeometry(0.285, 0.285, 0.28);
const mesh = new THREE.InstancedMesh(
geometry,
mat,
points.length
);
points.forEach(([x, y], index) => {
dummy.position.set(x, y, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
eyeScene.add(mesh);
return mesh;
}
createVoxelInstances(shellPoints, shellMaterial);
createVoxelInstances(retinaPoints, retinaMaterial, 0.03);
// A separate blocky cornea arc.
for (let i = -4; i <= 4; i++) {
const y = i * 0.36;
const bulge = 0.3 * (1 - Math.pow(y / 1.55, 2));
addBox(
eyeScene,
[0.27, 0.32, 0.31],
[-4.79 - bulge, y, 0.15],
corneaMaterial,
{ cast: false, receive: false }
);
}
// Lens is a voxel biconvex cluster. Its group is animated in Y.
const lensGroup = new THREE.Group();
lensGroup.position.set(-2.25, 0, 0.16);
eyeScene.add(lensGroup);
const lensOffsets = [-0.48, -0.24, 0, 0.24, 0.48];
for (const offset of lensOffsets) {
const normalized = Math.abs(offset) / 0.72;
const halfHeight = 1.16 * Math.pow(1 - normalized, 0.72);
const count = Math.max(1, Math.round((halfHeight * 2) / 0.22));
for (let row = -Math.floor(count / 2); row <= Math.floor(count / 2); row++) {
addBox(
lensGroup,
[0.225, 0.225, 0.34],
[offset, row * 0.22, 0],
lensMaterial,
{ cast: false, receive: false }
);
}
}
// Selectable voxel markers.
const hotspotMeshes = [];
const hotspotMaterials = {};
const hotspotPositions = {
cornea: [-5.05, 0, 0.48],
lens: [-2.25, 0, 0.52],
retina: [4.26, 0, 0.46]
};
for (const [part, position] of Object.entries(hotspotPositions)) {
const hotspotMaterial = material(0xff9d57, {
emissive: 0xff6c1f,
emissiveIntensity: 0.55
});
hotspotMaterials[part] = hotspotMaterial;
const hotspot = addBox(
eyeScene,
[0.29, 0.29, 0.26],
position,
hotspotMaterial,
{ cast: false, receive: false }
);
hotspot.userData.part = part;
hotspotMeshes.push(hotspot);
}
// -------------------------------------------------------------------------
// Optical ray sketches
// -------------------------------------------------------------------------
function makeRay(points, color, z = 0.38) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map(([x, y]) => new THREE.Vector3(x, y, z))
);
const mat = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0,
depthTest: false
});
const line = new THREE.Line(geometry, mat);
line.renderOrder = 5;
eyeScene.add(line);
return line;
}
const distantRays = [];
const nearRays = [];
for (const y of [-1.35, 0, 1.35]) {
distantRays.push(
makeRay(
[[-8.25, y], [-2.48, y]],
0xffc266
),
makeRay(
[[-2.48, y], [4.18, 0]],
0x8df0bb
)
);
}
for (const y of [-0.9, 0, 0.9]) {
nearRays.push(
makeRay(
[[-8.0, 0], [-2.48, y]],
0xffc266
),
makeRay(
[[-2.48, y], [4.18, 0]],
0x8df0bb
)
);
}
const focusMarker = addBox(
eyeScene,
[0.19, 0.19, 0.34],
[4.18, 0, 0.48],
material(0xd9ff72, {
emissive: 0x8fc72c,
emissiveIntensity: 0.75
}),
{ cast: false, receive: false }
);
focusMarker.renderOrder = 6;
// -------------------------------------------------------------------------
// UI state and interactions
// -------------------------------------------------------------------------
const lensState = document.querySelector("#lensState");
const lensMarker = document.querySelector("#lensMarker");
const lightState = document.querySelector("#lightState");
const liveStatus = document.querySelector("#liveStatus");
const targetButtons = [...document.querySelectorAll("#targetControls [data-target]")];
const targetLabels = [...document.querySelectorAll(".target-label")];
const partButtons = [...document.querySelectorAll("[data-part]")];
const partInfo = document.querySelector("#partInfo");
const partDescriptions = {
cornea: {
title: "Cornea",
body:
"The front surface bends incoming light. Its shape is kept constant in this simplified accommodation sketch."
},
lens: {
title: "Lens",
body:
"A schematic curvature change suggests accommodation: flatter for the distant target and more rounded for the near target."
},
retina: {
title: "Retina",
body:
"The back surface marks the focal plane. The crossing rays are a simplified focus cue, not a measured result."
}
};
let selectedPart = "lens";
function selectPart(part) {
if (!partDescriptions[part]) return;
selectedPart = part;
const description = partDescriptions[part];
for (const button of partButtons) {
button.setAttribute(
"aria-pressed",
String(button.dataset.part === part)
);
}
for (const [name, hotspot] of hotspotMeshes.entries()) {
const partName = hotspot.userData.part;
const active = partName === part;
hotspot.scale.setScalar(active ? 1.38 : 1);
hotspotMaterials[partName].color.set(
active ? 0xd9ff72 : 0xff9d57
);
hotspotMaterials[partName].emissive.set(
active ? 0x8fc72c : 0xff6c1f
);
}
partInfo.innerHTML = `
<strong>${description.title}</strong>
<span>${description.body}</span>
`;
liveStatus.textContent = `${description.title} selected. ${description.body}`;
}
function selectTarget(target) {
selectedTarget = target;
for (const button of targetButtons) {
button.setAttribute(
"aria-checked",
String(button.dataset.target === target)
);
}
for (const label of targetLabels) {
label.setAttribute(
"aria-pressed",
String(label.dataset.target === target)
);
}
const isNear = target === "book";
lensState.textContent = isNear ? "More rounded" : "Flatter";
lensMarker.style.left = isNear ? "86%" : "14%";
lightState.textContent = isNear
? "Diverging · schematic"
: "Parallel · schematic";
windowBracket.visible = !isNear;
bookBracket.visible = isNear;
windowFrameMaterial.emissive.setHex(isNear ? 0x000000 : 0x71972a);
windowFrameMaterial.emissiveIntensity = isNear ? 0 : 0.24;
windowLight.intensity = isNear ? 2.8 : 4.2;
coverMaterial.emissive.setHex(isNear ? 0x2b4b18 : 0x000000);
coverMaterial.emissiveIntensity = isNear ? 0.24 : 0;
liveStatus.textContent = isNear
? "Near book selected. The schematic lens becomes more rounded."
: "Distant window selected. The schematic lens becomes flatter.";
}
for (const button of targetButtons) {
button.addEventListener("click", () => selectTarget(button.dataset.target));
}
for (const label of targetLabels) {
label.addEventListener("click", () => selectTarget(label.dataset.target));
}
for (const button of partButtons) {
button.addEventListener("click", () => selectPart(button.dataset.part));
}
// -------------------------------------------------------------------------
// Direct camera controls: no external control add-ons
// -------------------------------------------------------------------------
const pointer = {
down: false,
moved: false,
x: 0,
y: 0,
startX: 0,
startY: 0,
overEye: false
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function isInsideEyeViewport(clientX, clientY) {
const rect = eyeViewport.getBoundingClientRect();
return (
clientX >= rect.left &&
clientX <= rect.right &&
clientY >= rect.top &&
clientY <= rect.bottom
);
}
function pickEyePart(clientX, clientY) {
const rect = eyeViewport.getBoundingClientRect();
pointerNDC.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, eyeCamera);
const hits = raycaster.intersectObjects(hotspotMeshes, false);
if (hits.length) {
selectPart(hits[0].object.userData.part);
}
}
function pickRoomTarget(clientX, clientY) {
pointerNDC.x = (clientX / window.innerWidth) * 2 - 1;
pointerNDC.y = -(clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(targetMeshes, false);
if (hits.length) {
selectTarget(hits[0].object.userData.target);
}
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointer.down = true;
pointer.moved = false;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
pointer.overEye = isInsideEyeViewport(event.clientX, event.clientY);
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
const overEye = isInsideEyeViewport(event.clientX, event.clientY);
canvas.style.cursor = overEye ? "pointer" : "grab";
if (!pointer.down) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
if (
Math.abs(event.clientX - pointer.startX) +
Math.abs(event.clientY - pointer.startY) > 4
) {
pointer.moved = true;
}
if (pointer.overEye) return;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.45,
1.38
);
pointer.x = event.clientX;
pointer.y = event.clientY;
});
canvas.addEventListener("pointerup", (event) => {
if (!pointer.down) return;
const wasOverEye = pointer.overEye;
const moved = pointer.moved;
pointer.down = false;
canvas.releasePointerCapture(event.pointerId);
if (!moved) {
if (wasOverEye) {
pickEyePart(event.clientX, event.clientY);
} else {
pickRoomTarget(event.clientX, event.clientY);
}
}
});
canvas.addEventListener("pointercancel", () => {
pointer.down = false;
pointer.moved = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
9.2,
23
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") controls.theta += 0.08;
else if (key === "ArrowRight") controls.theta -= 0.08;
else if (key === "ArrowUp") controls.phi = Math.max(0.45, controls.phi - 0.06);
else if (key === "ArrowDown") controls.phi = Math.min(1.38, controls.phi + 0.06);
else if (key === "+" || key === "=") controls.radius = Math.max(9.2, controls.radius - 0.7);
else if (key === "-" || key === "_") controls.radius = Math.min(23, controls.radius + 0.7);
else return;
event.preventDefault();
});
document.querySelector("#resetButton").addEventListener("click", () => {
controls.theta = 0.48;
controls.phi = 1.14;
controls.radius = 15.8;
controls.target.set(-1.05, 2.45, -1.05);
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const windowAnchor = new THREE.Vector3(-2.8, 6.85, -7.7);
const bookAnchor = new THREE.Vector3(-1.65, 2.8, 1.5);
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.visibility = visible ? "visible" : "hidden";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
// -------------------------------------------------------------------------
// Resize and render
// -------------------------------------------------------------------------
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
const rect = eyeViewport.getBoundingClientRect();
const aspect = Math.max(0.5, rect.width / Math.max(1, rect.height));
const halfWidth = 8.15;
const halfHeight = halfWidth / aspect;
eyeCamera.left = -halfWidth;
eyeCamera.right = halfWidth;
eyeCamera.top = halfHeight;
eyeCamera.bottom = -halfHeight;
eyeCamera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
updateCamera();
const targetNear = selectedTarget === "book" ? 1 : 0;
const smoothing = prefersReducedMotion ? 1 : 1 - Math.exp(-delta * 5.5);
rayMix = THREE.MathUtils.lerp(rayMix, targetNear, smoothing);
// Qualitative accommodation: the lens becomes rounder for the near target.
lensGroup.scale.y = THREE.MathUtils.lerp(0.77, 1.08, rayMix);
lensGroup.scale.x = THREE.MathUtils.lerp(0.95, 1.01, rayMix);
for (const ray of distantRays) {
ray.material.opacity = (1 - rayMix) * 0.9;
}
for (const ray of nearRays) {
ray.material.opacity = rayMix * 0.9;
}
if (!prefersReducedMotion) {
const pulse = 1 + Math.sin(elapsed * 3.1) * 0.07;
focusMarker.scale.setScalar(pulse);
}
projectLabel(document.querySelector("#windowLabel"), windowAnchor);
projectLabel(document.querySelector("#bookLabel"), bookAnchor);
// Main scene.
renderer.setScissorTest(false);
renderer.setViewport(0, 0, window.innerWidth, window.innerHeight);
renderer.render(scene, camera);
// Eye inset, rendered into the transparent DOM viewport rectangle.
const rect = eyeViewport.getBoundingClientRect();
const canvasRect = canvas.getBoundingClientRect();
const left = rect.left - canvasRect.left;
const bottom = canvasRect.bottom - rect.bottom;
const width = rect.width;
const height = rect.height;
if (width > 0 && height > 0) {
renderer.setScissorTest(true);
renderer.setViewport(left, bottom, width, height);
renderer.setScissor(left, bottom, width, height);
renderer.clearDepth();
renderer.render(eyeScene, eyeCamera);
renderer.setScissorTest(false);
}
}
selectTarget("window");
selectPart("lens");
resize();
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```