Prompt specification
Build or customize the Three.js 3D scene "Lens-shape optical museum table" 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: Lens-shape optical museum table
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/lens-shape-optical-museum-table-x0588
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts eyeglass frames. Create abstract convex, concave, and flat transparent discs beside the frame display; idealized ray diagrams show their differing effects without suggesting medical correction or real lens selection. Low-poly.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Start the two incident rays separately and parallel in all three diagrams. Apply the direction changes where each ray reaches the lens and make the convex, concave, and parallel-plate outcomes distinct.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (lens-shape-optical-museum-table-x0588):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#ded8ca">
<title>Molho & Óptica Abstrata</title>
<style>
:root {
--ink: #263238;
--muted: #657075;
--paper: rgba(248, 245, 236, 0.91);
--line: rgba(54, 67, 70, 0.16);
--incident: #d69a31;
--outgoing: #278b83;
--virtual: #8575b2;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded8ca;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.intro {
position: fixed;
top: 20px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 12px 36px rgba(57, 48, 38, 0.09);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--outgoing);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 2.2vw, 34px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro p {
margin: 10px 0 0;
max-width: 345px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.disclaimer {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 6px 9px;
border: 1px solid rgba(133, 117, 178, 0.28);
border-radius: 999px;
background: rgba(133, 117, 178, 0.08);
color: #665a8c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.disclaimer::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--virtual);
}
.badge {
position: fixed;
top: 20px;
right: 22px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(248, 245, 236, 0.78);
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.views {
position: fixed;
top: 63px;
right: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
max-width: 340px;
}
.views button {
appearance: none;
border: 1px solid rgba(52, 65, 68, 0.16);
border-radius: 999px;
padding: 8px 11px;
background: rgba(248, 245, 236, 0.88);
color: #536064;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
.views button:hover {
transform: translateY(-1px);
background: #fbf8ef;
}
.views button[aria-pressed="true"] {
border-color: var(--outgoing);
background: var(--outgoing);
color: #f7fbf8;
}
.legend {
position: fixed;
left: 22px;
bottom: 20px;
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
max-width: min(530px, calc(100vw - 44px));
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
color: var(--muted);
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.legend i {
display: inline-block;
width: 21px;
height: 3px;
border-radius: 99px;
background: currentColor;
}
.legend .inc { color: var(--incident); }
.legend .out { color: var(--outgoing); }
.legend .vir {
color: var(--virtual);
background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px);
}
.readout {
position: fixed;
right: 22px;
bottom: 20px;
width: min(360px, calc(100vw - 44px));
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
box-shadow: 0 10px 28px rgba(57, 48, 38, 0.07);
pointer-events: none;
}
.readout strong {
display: block;
margin-bottom: 5px;
color: var(--outgoing);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.readout p {
margin: 0;
color: #596468;
font-size: 10.5px;
line-height: 1.48;
}
.hint {
position: fixed;
left: 50%;
top: 16px;
transform: translateX(-50%);
padding: 7px 10px;
border-radius: 999px;
background: rgba(38, 50, 56, 0.68);
color: rgba(255,255,255,0.88);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #ded8ca;
color: #536064;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease, visibility 300ms ease;
}
#loading.hide {
opacity: 0;
visibility: hidden;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
.intro p { display: none; }
.disclaimer { margin-top: 9px; }
.badge { display: none; }
.views {
top: auto;
right: 12px;
bottom: 128px;
max-width: calc(100vw - 24px);
}
.views button { padding: 7px 9px; font-size: 9px; }
.legend { left: 12px; bottom: 12px; max-width: calc(100vw - 24px); }
.readout { right: 12px; bottom: 62px; width: calc(100vw - 24px); }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="intro" aria-label="Apresentação da cena">
<div class="eyebrow">Atelier óptico abstrato</div>
<h1>Molho &<br>formas de vidro</h1>
<p>
Três discos sintéticos e trajetórias idealizadas. Os raios entram sempre
paralelos; somente a geometria posterior ao disco muda.
</p>
<div class="disclaimer">Sem correção, prescrição ou seleção real de lente</div>
</section>
<div class="badge">Cena procedural · baixa poligonização</div>
<div class="hint">Arraste para orbitar · roda para aproximar</div>
<nav class="views" aria-label="Vistas do diagrama">
<button type="button" data-view="all" aria-pressed="true">Vista completa</button>
<button type="button" data-view="convex" aria-pressed="false">Convexo</button>
<button type="button" data-view="concave" aria-pressed="false">Côncavo</button>
<button type="button" data-view="flat" aria-pressed="false">Plano</button>
</nav>
<div class="legend" aria-label="Legenda das trajetórias">
<span class="inc"><i></i>Incidente paralelo</span>
<span class="out"><i></i>Trajetória idealizada</span>
<span class="vir"><i></i>Extensão virtual tracejada</span>
</div>
<aside class="readout" aria-live="polite">
<strong id="readoutTitle">Três formas · mesma entrada</strong>
<p id="readoutText">
Em todos os diagramas, os dois raios incidentes são horizontais e paralelos.
As setas superior e inferior pertencem a trajetórias distintas.
</p>
</aside>
<div id="loading">Construindo a cena procedural…</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.querySelector('#stage');
const loading = document.querySelector('#loading');
const readoutTitle = document.querySelector('#readoutTitle');
const readoutText = document.querySelector('#readoutText');
const viewButtons = [...document.querySelectorAll('[data-view]')];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded8ca);
scene.fog = new THREE.Fog(0xded8ca, 19, 34);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute('aria-label', 'Cena tridimensional de um molho de óculos e três discos ópticos sintéticos');
renderer.domElement.tabIndex = 0;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(32, window.innerWidth / window.innerHeight, 0.1, 70);
const cameraTarget = new THREE.Vector3(0.35, 2.25, 0);
const desiredTarget = cameraTarget.clone();
let desiredRadius = 14.2;
let desiredTheta = 0.08;
let desiredPhi = 1.39;
let cameraRadius = desiredRadius;
let cameraTheta = desiredTheta;
let cameraPhi = desiredPhi;
const hemisphere = new THREE.HemisphereLight(0xfff8e7, 0x71807e, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d3, 2.35);
keyLight.position.set(-6, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dfdc, 0.85);
fillLight.position.set(7, 4, 6);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xd8c7f0, 0.55);
rimLight.position.set(2, 6, -5);
scene.add(rimLight);
const palette = {
floor: 0xd6d0c2,
wall: 0xe4ded1,
frame: 0x29363b,
brass: 0xb58a47,
board: 0xf3efe5,
border: 0xc8bcaa,
incident: 0xd69a31,
outgoing: 0x278b83,
virtual: 0x8575b2
};
const mat = {
floor: new THREE.MeshStandardMaterial({ color: palette.floor, roughness: 0.92, metalness: 0.02 }),
wall: new THREE.MeshStandardMaterial({ color: palette.wall, roughness: 0.95 }),
frame: new THREE.MeshStandardMaterial({ color: palette.frame, roughness: 0.42, metalness: 0.22, flatShading: true }),
brass: new THREE.MeshStandardMaterial({ color: palette.brass, roughness: 0.38, metalness: 0.62, flatShading: true }),
incident: new THREE.MeshBasicMaterial({ color: palette.incident }),
outgoing: new THREE.MeshBasicMaterial({ color: palette.outgoing }),
virtual: new THREE.MeshBasicMaterial({ color: palette.virtual })
};
function makeBox(width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function rod(a, b, radius, material, segments = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const geometry = new THREE.CylinderGeometry(radius, radius, direction.length(), segments, 1, false);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function arrowHead(position, direction, material, size = 1) {
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.046 * size, 0.145 * size, 6),
material
);
cone.position.set(...position);
cone.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(...direction).normalize()
);
return cone;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabel(text, {
width = 2,
color = '#334146',
background = 'rgba(248,245,236,0.92)',
border = 'rgba(55,67,70,0.16)',
fontSize = 52
} = {}) {
const canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 180;
const ctx = canvas.getContext('2d');
roundedRect(ctx, 4, 4, 1016, 172, 34);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 3;
ctx.stroke();
let size = fontSize;
ctx.font = `800 ${size}px Arial, sans-serif`;
while (ctx.measureText(text).width > 930 && size > 24) {
size -= 2;
ctx.font = `800 ${size}px Arial, sans-serif`;
}
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = color;
ctx.fillText(text, 512, 91);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
fog: false
}));
sprite.scale.set(width, width * 180 / 1024, 1);
sprite.renderOrder = 20;
return sprite;
}
// Environment
const floor = new THREE.Mesh(new THREE.PlaneGeometry(36, 28), mat.floor);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const wall = new THREE.Mesh(new THREE.PlaneGeometry(36, 13), mat.wall);
wall.position.set(0, 5.5, -3.8);
wall.receiveShadow = true;
scene.add(wall);
makeBox(36, 0.16, 0.18, new THREE.MeshStandardMaterial({
color: 0xb8ad9b, roughness: 0.86
}), 0, 0.08, -3.64);
// Low-poly eyeglass frame display
const frameDisplay = new THREE.Group();
frameDisplay.position.set(-3.0, 2.4, 0.3);
frameDisplay.rotation.y = -0.08;
scene.add(frameDisplay);
const rimGeometry = new THREE.TorusGeometry(0.88, 0.078, 5, 24);
[-1.02, 1.02].forEach(x => {
const rim = new THREE.Mesh(rimGeometry, mat.frame);
rim.position.x = x;
rim.castShadow = true;
rim.receiveShadow = true;
frameDisplay.add(rim);
});
const frameGlassMaterial = new THREE.MeshPhongMaterial({
color: 0xb7d7d2,
transparent: true,
opacity: 0.12,
shininess: 85,
side: THREE.DoubleSide,
depthWrite: false
});
[-1.02, 1.02].forEach(x => {
const insert = new THREE.Mesh(
new THREE.CylinderGeometry(0.795, 0.795, 0.035, 20),
frameGlassMaterial
);
insert.rotation.x = Math.PI / 2;
insert.position.x = x;
frameDisplay.add(insert);
});
const bridgeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.16, 0.09, 0),
new THREE.Vector3(-0.07, 0.25, 0),
new THREE.Vector3(0.07, 0.25, 0),
new THREE.Vector3(0.16, 0.09, 0)
]);
const bridge = new THREE.Mesh(new THREE.TubeGeometry(bridgeCurve, 16, 0.055, 5, false), mat.frame);
bridge.castShadow = true;
frameDisplay.add(bridge);
const bridgeAccent = new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.035, 0.07), mat.brass);
bridgeAccent.position.set(0, 0.255, 0.035);
frameDisplay.add(bridgeAccent);
[-1, 1].forEach(side => {
const templeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(side * 1.87, 0.08, 0),
new THREE.Vector3(side * 2.02, 0.08, -0.72),
new THREE.Vector3(side * 2.04, 0.0, -1.62),
new THREE.Vector3(side * 1.91, -0.22, -2.28)
]);
const temple = new THREE.Mesh(new THREE.TubeGeometry(templeCurve, 18, 0.052, 5, false), mat.frame);
temple.castShadow = true;
frameDisplay.add(temple);
const hinge = new THREE.Mesh(new THREE.CylinderGeometry(0.065, 0.065, 0.10, 8), mat.brass);
hinge.rotation.x = Math.PI / 2;
hinge.position.set(side * 1.88, 0.08, 0.015);
frameDisplay.add(hinge);
});
const padGeometry = new THREE.SphereGeometry(0.09, 7, 5);
[-0.18, 0.18].forEach(x => {
const pad = new THREE.Mesh(padGeometry, mat.brass);
pad.scale.set(0.7, 1.35, 0.55);
pad.position.set(x, -0.1, -0.12);
pad.rotation.z = x < 0 ? -0.25 : 0.25;
frameDisplay.add(pad);
});
const framePedestal = new THREE.Mesh(
new THREE.CylinderGeometry(1.25, 1.38, 0.32, 12),
new THREE.MeshStandardMaterial({ color: 0x4a5355, roughness: 0.65, metalness: 0.12, flatShading: true })
);
framePedestal.position.set(-3, 0.16, 0.05);
framePedestal.castShadow = true;
framePedestal.receiveShadow = true;
scene.add(framePedestal);
const framePedestalTop = new THREE.Mesh(
new THREE.CylinderGeometry(1.06, 1.12, 0.08, 12),
new THREE.MeshStandardMaterial({ color: 0xbca98d, roughness: 0.72, flatShading: true })
);
framePedestalTop.position.set(-3, 0.36, 0.05);
framePedestalTop.castShadow = true;
scene.add(framePedestalTop);
rod([-3.64, 0.4, 0.18], [-3.62, 1.66, 0.24], 0.035, mat.brass);
rod([-2.36, 0.4, 0.18], [-2.38, 1.66, 0.24], 0.035, mat.brass);
const frameLabel = makeLabel('MOLHO · TORUS BAIXA POLIGONAL', {
width: 2.65,
color: '#344146',
background: 'rgba(245,241,231,0.94)'
});
frameLabel.position.set(-3, 0.56, 0.62);
scene.add(frameLabel);
// Actual transparent lens geometry, revolved around its optical axis.
function makeLensGeometry(kind, radius = 0.58) {
let profile;
if (kind === 'convex') {
profile = [
[0, -0.09], [radius * 0.31, -0.086], [radius * 0.62, -0.07],
[radius * 0.9, -0.047], [radius, -0.022], [radius, 0.022],
[radius * 0.9, 0.047], [radius * 0.62, 0.07],
[radius * 0.31, 0.086], [0, 0.09]
];
} else if (kind === 'concave') {
profile = [
[0, -0.018], [radius * 0.31, -0.022], [radius * 0.62, -0.038],
[radius * 0.9, -0.068], [radius, -0.09], [radius, 0.09],
[radius * 0.9, 0.068], [radius * 0.62, 0.038],
[radius * 0.31, 0.022], [0, 0.018]
];
} else {
profile = [
[0, -0.045], [radius, -0.045], [radius, 0.045], [0, 0.045]
];
}
const segments = 24;
const positions = [];
const uvs = [];
const indices = [];
profile.forEach(([r, z], profileIndex) => {
for (let j = 0; j <= segments; j++) {
const angle = j / segments * Math.PI * 2;
positions.push(Math.cos(angle) * r, Math.sin(angle) * r, z);
uvs.push(j / segments, profileIndex / (profile.length - 1));
}
});
for (let p = 0; p < profile.length - 1; p++) {
for (let j = 0; j < segments; j++) {
const a = p * (segments + 1) + j;
const b = a + 1;
const c = (p + 1) * (segments + 1) + j;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute('uv', new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function glyphShape(kind, radius) {
const shape = new THREE.Shape();
if (kind === 'convex') {
shape.moveTo(-0.025, radius);
shape.lineTo(0.025, radius);
shape.lineTo(0.055, 0);
shape.lineTo(0.025, -radius);
shape.lineTo(-0.025, -radius);
shape.lineTo(-0.055, 0);
} else if (kind === 'concave') {
shape.moveTo(-0.06, radius);
shape.lineTo(0.06, radius);
shape.lineTo(0.025, 0);
shape.lineTo(0.06, -radius);
shape.lineTo(-0.06, -radius);
shape.lineTo(-0.025, 0);
} else {
shape.moveTo(-0.025, radius);
shape.lineTo(0.025, radius);
shape.lineTo(0.025, -radius);
shape.lineTo(-0.025, -radius);
}
shape.closePath();
return shape;
}
function dashedSegment(start, end, material, dashCount = 9) {
const group = new THREE.Group();
for (let i = 0; i < dashCount; i++) {
const t0 = i / dashCount;
const t1 = Math.min(t0 + 0.055, 1);
const a = new THREE.Vector3(...start).lerp(new THREE.Vector3(...end), t0);
const b = new THREE.Vector3(...start).lerp(new THREE.Vector3(...end), t1);
group.add(rod(a.toArray(), b.toArray(), 0.008, material, 5));
}
return group;
}
const optics = [
{
id: 'convex',
typeName: 'CONVEXO',
x: -0.2,
cy: 3.62,
mode: 'converge',
incidentStartX: -0.94,
incidentYs: [0.31, -0.31],
outgoingX: 0.92,
lensColor: 0x73c8c1
},
{
id: 'concave',
typeName: 'CÔNCAVO',
x: 2.05,
cy: 3.62,
mode: 'diverge',
incidentStartX: -0.94,
incidentYs: [0.31, -0.31],
outgoingX: 0.98,
virtualX: -0.72,
lensColor: 0x9cb9db
},
{
id: 'flat',
typeName: 'PLANO',
x: 4.3,
cy: 3.62,
mode: 'parallel',
incidentStartX: -0.94,
incidentYs: [0.31, -0.31],
outgoingX: 0.98,
lensColor: 0xa9d5b6
}
];
const chapterData = [];
const interactiveMeshes = [];
function buildChapter(data, index) {
const chapter = new THREE.Group();
scene.add(chapter);
// Diagram board
const boardMaterial = new THREE.MeshStandardMaterial({
color: palette.board,
roughness: 0.86,
metalness: 0.01
});
const board = new THREE.Mesh(new THREE.PlaneGeometry(2.25, 1.85), boardMaterial);
board.position.set(data.x, data.cy, -0.34);
board.receiveShadow = true;
chapter.add(board);
const borderMaterial = new THREE.MeshStandardMaterial({
color: palette.border,
roughness: 0.7,
metalness: 0.08,
flatShading: true
});
makeBox(2.25, 0.035, 0.035, borderMaterial, data.x, data.cy + 0.925, -0.30);
makeBox(2.25, 0.035, 0.035, borderMaterial, data.x, data.cy - 0.925, -0.30);
makeBox(0.035, 1.85, 0.035, borderMaterial, data.x - 1.125, data.cy, -0.30);
makeBox(0.035, 1.85, 0.035, borderMaterial, data.x + 1.125, data.cy, -0.30);
const title = makeLabel(`0${index + 1} · ${data.typeName} · IDEALIZADO`, {
width: 1.92,
color: '#344146',
background: 'rgba(250,247,239,0.95)',
border: 'rgba(39,139,131,0.25)'
});
title.position.set(data.x, data.cy + 0.70, 0.10);
chapter.add(title);
// Schematic cross-section of the lens.
const glyphMaterial = new THREE.MeshPhongMaterial({
color: data.lensColor,
transparent: true,
opacity: 0.72,
shininess: 100,
side: THREE.DoubleSide,
depthWrite: false
});
const glyphGeometry = new THREE.ShapeGeometry(glyphShape(data.id, 0.58));
const glyph = new THREE.Mesh(glyphGeometry, glyphMaterial);
glyph.position.set(data.x, data.cy, 0.015);
glyph.userData.view = data.id;
chapter.add(glyph);
interactiveMeshes.push(glyph);
const glyphEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(glyphGeometry),
new THREE.LineBasicMaterial({ color: 0x376f70, transparent: true, opacity: 0.65 })
);
glyphEdges.position.copy(glyph.position);
chapter.add(glyphEdges);
// Each incident ray has its own independent start point and arrowhead.
data.incidentYs.forEach(offset => {
const start = new THREE.Vector3(data.x + data.incidentStartX, data.cy + offset, 0.07);
const hit = new THREE.Vector3(data.x, data.cy + offset, 0.07);
chapter.add(rod(start.toArray(), hit.toArray(), 0.013, mat.incident, 6));
const arrowPosition = start.clone().lerp(hit, 0.16);
chapter.add(arrowHead(arrowPosition.toArray(), [1, 0, 0], mat.incident, 0.92));
});
let focusMarker = null;
if (data.mode === 'converge') {
const focus = new THREE.Vector3(data.x + data.outgoingX, data.cy, 0.07);
data.incidentYs.forEach(offset => {
const hit = new THREE.Vector3(data.x, data.cy + offset, 0.07);
chapter.add(rod(hit.toArray(), focus.toArray(), 0.015, mat.outgoing, 6));
const arrowPosition = hit.clone().lerp(focus, 0.58);
chapter.add(arrowHead(arrowPosition.toArray(), focus.clone().sub(hit).normalize().toArray(), mat.outgoing, 0.94));
});
focusMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.058, 8, 6),
new THREE.MeshBasicMaterial({ color: palette.outgoing })
);
focusMarker.position.copy(focus);
chapter.add(focusMarker);
const outputLabel = makeLabel('CONVERGEM', {
width: 1.12,
color: '#267970',
background: 'rgba(235,247,242,0.94)',
border: 'rgba(39,139,131,0.22)'
});
outputLabel.position.set(data.x + 0.47, data.cy - 0.66, 0.12);
chapter.add(outputLabel);
}
if (data.mode === 'diverge') {
const virtualFocus = new THREE.Vector3(data.x + data.virtualX, data.cy, 0.055);
data.incidentYs.forEach(offset => {
const hit = new THREE.Vector3(data.x, data.cy + offset, 0.07);
const end = new THREE.Vector3(data.x + data.outgoingX, data.cy + offset * 1.78, 0.07);
// The diagonal outgoing ray begins exactly at the lens.
chapter.add(rod(hit.toArray(), end.toArray(), 0.015, mat.outgoing, 6));
const arrowPosition = hit.clone().lerp(end, 0.58);
chapter.add(arrowHead(arrowPosition.toArray(), end.clone().sub(hit).normalize().toArray(), mat.outgoing, 0.94));
// Dashed backward extensions are explicitly separate from the incident rays.
chapter.add(dashedSegment(hit.toArray(), virtualFocus.toArray(), mat.virtual, 9));
});
focusMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.048, 8, 6),
new THREE.MeshBasicMaterial({ color: palette.virtual })
);
focusMarker.position.copy(virtualFocus);
chapter.add(focusMarker);
const virtualLabel = makeLabel('FOCO VIRTUAL', {
width: 1.18,
color: '#6e6096',
background: 'rgba(241,237,249,0.95)',
border: 'rgba(133,117,178,0.28)'
});
virtualLabel.position.set(data.x - 0.67, data.cy + 0.48, 0.12);
chapter.add(virtualLabel);
const outputLabel = makeLabel('DIVERGEM', {
width: 1.12,
color: '#267970',
background: 'rgba(235,247,242,0.94)',
border: 'rgba(39,139,131,0.22)'
});
outputLabel.position.set(data.x + 0.48, data.cy - 0.66, 0.12);
chapter.add(outputLabel);
}
if (data.mode === 'parallel') {
data.incidentYs.forEach(offset => {
const hit = new THREE.Vector3(data.x, data.cy + offset, 0.07);
const end = new THREE.Vector3(data.x + data.outgoingX, data.cy + offset, 0.07);
chapter.add(rod(hit.toArray(), end.toArray(), 0.015, mat.outgoing, 6));
const arrowPosition = hit.clone().lerp(end, 0.58);
chapter.add(arrowHead(arrowPosition.toArray(), [1, 0, 0], mat.outgoing, 0.94));
});
const outputLabel = makeLabel('PERMANECEM PARALELOS', {
width: 1.65,
color: '#267970',
background: 'rgba(235,247,242,0.94)',
border: 'rgba(39,139,131,0.22)'
});
outputLabel.position.set(data.x + 0.40, data.cy - 0.66, 0.12);
chapter.add(outputLabel);
}
const inputLabel = makeLabel('2 INCIDENTES ∥', {
width: 1.18,
color: '#a16e18',
background: 'rgba(251,244,228,0.95)',
border: 'rgba(214,154,49,0.28)'
});
inputLabel.position.set(data.x - 0.46, data.cy - 0.66, 0.12);
chapter.add(inputLabel);
// Physical synthetic disc and its low-poly stand.
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x566064,
roughness: 0.7,
metalness: 0.1,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.67, 0.75, 0.19, 9),
baseMaterial
);
base.position.set(data.x, 0.095, 0.30);
base.castShadow = true;
base.receiveShadow = true;
chapter.add(base);
const baseTop = new THREE.Mesh(
new THREE.CylinderGeometry(0.59, 0.62, 0.055, 9),
new THREE.MeshStandardMaterial({ color: 0xb7a78d, roughness: 0.72, flatShading: true })
);
baseTop.position.set(data.x, 0.215, 0.30);
baseTop.castShadow = true;
chapter.add(baseTop);
rod(
[data.x - 0.39, 0.23, 0.30],
[data.x - 0.40, 0.78, 0.35],
0.026, mat.brass
);
rod(
[data.x + 0.39, 0.23, 0.30],
[data.x + 0.40, 0.78, 0.35],
0.026, mat.brass
);
const lensGroup = new THREE.Group();
lensGroup.position.set(data.x, 1.18, 0.35);
lensGroup.rotation.y = index === 1 ? 0.16 : -0.16;
chapter.add(lensGroup);
const lensGeometry = makeLensGeometry(data.id, 0.58);
const lensMaterial = new THREE.MeshPhongMaterial({
color: data.lensColor,
transparent: true,
opacity: 0.48,
shininess: 110,
specular: 0xffffff,
side: THREE.DoubleSide,
depthWrite: false,
flatShading: true
});
const lensMesh = new THREE.Mesh(lensGeometry, lensMaterial);
lensMesh.castShadow = true;
lensMesh.userData.view = data.id;
lensGroup.add(lensMesh);
interactiveMeshes.push(lensMesh);
const lensEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(lensGeometry, 18),
new THREE.LineBasicMaterial({ color: 0xf4ffff, transparent: true, opacity: 0.66 })
);
lensGroup.add(lensEdges);
const physicalLabel = makeLabel(`${data.typeName} · DISCO SINTÉTICO`, {
width: 1.95,
color: '#344146',
background: 'rgba(248,245,236,0.94)',
border: 'rgba(55,67,70,0.18)'
});
physicalLabel.position.set(data.x, 0.43, 0.68);
chapter.add(physicalLabel);
// Dotted visual connector between the diagram and its physical specimen.
const connector = dashedSegment(
[data.x, data.cy - 0.94, -0.08],
[data.x, 1.83, 0.08],
new THREE.MeshBasicMaterial({ color: 0x9d9689, transparent: true, opacity: 0.55 }),
7
);
chapter.add(connector);
chapterData.push({
data,
boardMaterial,
borderMaterial,
focusMarker,
chapter
});
}
optics.forEach(buildChapter);
const descriptions = {
all: {
title: 'Três formas · mesma entrada',
text: 'Nos três diagramas, os dois raios incidentes são horizontais e paralelos. Cada seta superior e inferior está fixada à sua própria trajetória; os segmentos diagonais começam somente depois do disco.'
},
convex: {
title: 'Convexo · trajetórias idealizadas',
text: 'Dois raios paralelos atingem o disco em alturas +0,31 e −0,31. Após o disco, ambos convergem no ponto focal ilustrado em (+0,92; 0).'
},
concave: {
title: 'Côncavo · trajetórias idealizadas',
text: 'Dois raios paralelos atingem o disco em alturas +0,31 e −0,31. Após o disco, divergem. O tracejado à esquerda é apenas uma extensão virtual, não um raio incidente.'
},
flat: {
title: 'Plano · trajetórias idealizadas',
text: 'Dois raios paralelos atingem o disco nas mesmas alturas. Depois do disco, ambos continuam horizontais, mantendo o paralelismo e a separação constantes.'
}
};
let activeView = 'all';
function selectView(id) {
activeView = id;
viewButtons.forEach(button => {
button.setAttribute('aria-pressed', String(button.dataset.view === id));
});
const description = descriptions[id];
readoutTitle.textContent = description.title;
readoutText.textContent = description.text;
chapterData.forEach(({ data, borderMaterial }) => {
const selected = id === 'all' || id === data.id;
borderMaterial.color.setHex(selected ? (id === 'all' ? palette.border : palette.outgoing) : 0xd0c8ba);
borderMaterial.emissive.setHex(selected && id !== 'all' ? 0x0d302d : 0x000000);
borderMaterial.emissiveIntensity = 0.18;
});
if (id === 'all') {
desiredTarget.set(0.35, 2.25, 0);
desiredRadius = 14.2;
desiredTheta = 0.08;
desiredPhi = 1.39;
} else {
const selectedData = optics.find(item => item.id === id);
desiredTarget.set(selectedData.x, 2.27, 0);
desiredRadius = 11.7;
desiredTheta = 0.07;
desiredPhi = 1.38;
}
}
viewButtons.forEach(button => {
button.addEventListener('click', () => selectView(button.dataset.view));
});
// Direct camera controls implemented without external controls modules.
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let pointerStart = { x: 0, y: 0 };
let previousPointer = { x: 0, y: 0 };
let pointerTravel = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickView(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
if (hits.length) selectView(hits[0].object.userData.view);
}
renderer.domElement.addEventListener('pointerdown', event => {
dragging = true;
pointerTravel = 0;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { ...pointerStart };
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = 'grabbing';
});
renderer.domElement.addEventListener('pointermove', event => {
if (dragging) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
pointerTravel += Math.abs(dx) + Math.abs(dy);
desiredTheta = THREE.MathUtils.clamp(desiredTheta - dx * 0.005, -0.72, 0.72);
desiredPhi = THREE.MathUtils.clamp(desiredPhi - dy * 0.004, 0.88, 1.68);
previousPointer = { x: event.clientX, y: event.clientY };
} else {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hovering = raycaster.intersectObjects(interactiveMeshes, false).length > 0;
renderer.domElement.style.cursor = hovering ? 'pointer' : 'grab';
}
});
renderer.domElement.addEventListener('pointerup', event => {
if (dragging && pointerTravel < 6) pickView(event);
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = 'grab';
});
renderer.domElement.addEventListener('pointercancel', () => {
dragging = false;
renderer.domElement.style.cursor = 'grab';
});
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
8.8,
21
);
}, { passive: false });
renderer.domElement.addEventListener('keydown', event => {
if (event.key === 'ArrowLeft') desiredTheta = THREE.MathUtils.clamp(desiredTheta + 0.08, -0.72, 0.72);
if (event.key === 'ArrowRight') desiredTheta = THREE.MathUtils.clamp(desiredTheta - 0.08, -0.72, 0.72);
if (event.key === 'ArrowUp') desiredPhi = THREE.MathUtils.clamp(desiredPhi - 0.06, 0.88, 1.68);
if (event.key === 'ArrowDown') desiredPhi = THREE.MathUtils.clamp(desiredPhi + 0.06, 0.88, 1.68);
if (event.key === '+' || event.key === '=') desiredRadius = Math.max(8.8, desiredRadius - 0.7);
if (event.key === '-') desiredRadius = Math.min(21, desiredRadius + 0.7);
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.fov = aspect < 1.15
? THREE.MathUtils.radToDeg(2 * Math.atan(Math.tan(THREE.MathUtils.degToRad(25)) / aspect))
: 32;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener('resize', resize);
resize();
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function animate() {
const delta = clock.getDelta();
const smoothing = 1 - Math.pow(0.001, delta);
cameraTarget.lerp(desiredTarget, smoothing * 0.75);
cameraRadius += (desiredRadius - cameraRadius) * smoothing * 0.75;
cameraTheta += (desiredTheta - cameraTheta) * smoothing * 0.75;
cameraPhi += (desiredPhi - cameraPhi) * smoothing * 0.75;
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraRadius,
cameraPhi,
cameraTheta
);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
if (!reducedMotion) {
chapterData.forEach(({ focusMarker }, index) => {
if (focusMarker) {
const pulse = 1 + Math.sin(clock.elapsedTime * 2.4 + index) * 0.08;
focusMarker.scale.setScalar(pulse);
}
});
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => loading.classList.add('hide'));
</script>
</body>
</html>
```