Prompt specification
Build or customize the Three.js 3D scene "Pinhole camera box and inverted image plane" 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: Pinhole camera box and inverted image plane
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pinhole-camera-box-and-inverted-image-plane-x2509
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring the inverted projection of an early pinhole camera. Build a dark box cutaway with a small aperture and image plane. Draw rays from a simple object to show the inverted projection geometrically. Stylized solid forms.
Working Three.js Starter (pinhole-camera-box-and-inverted-image-plane-x2509):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Obscura — Inverted Pinhole Projection</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #05080c;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.panel {
position: absolute;
border: 1px solid rgba(126, 196, 202, 0.18);
background: linear-gradient(
145deg,
rgba(10, 18, 24, 0.88),
rgba(7, 12, 17, 0.72)
);
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title {
top: 22px;
left: 22px;
width: min(365px, calc(100vw - 44px));
padding: 19px 21px 18px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #63d9d3;
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 1px;
content: "";
background: #63d9d3;
box-shadow: 0 0 8px rgba(99, 217, 211, 0.8);
}
h1 {
margin: 0;
color: #edf7f5;
font-size: clamp(25px, 3vw, 36px);
font-weight: 520;
line-height: 1.02;
letter-spacing: -0.045em;
}
#title p {
margin: 12px 0 0;
max-width: 310px;
color: #91a6aa;
font-size: 12px;
line-height: 1.65;
}
#legend {
left: 22px;
bottom: 22px;
padding: 14px 16px;
border-radius: 4px;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 7px 0;
color: #a9bbbd;
font: 500 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.swatch {
width: 24px;
height: 2px;
border-radius: 2px;
box-shadow: 0 0 10px currentColor;
}
.swatch.incoming {
color: #ffb24a;
background: currentColor;
}
.swatch.projected {
color: #51e5df;
background: currentColor;
}
#help {
right: 22px;
bottom: 22px;
padding: 12px 15px;
border-radius: 4px;
color: #83999d;
font: 500 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#help b {
color: #c2d4d5;
font-weight: 600;
}
#loader {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #05080c;
color: #69d9d4;
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.24em;
transition: opacity 400ms ease;
}
#loader.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
#title {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
#title p {
display: none;
}
#legend {
left: 14px;
bottom: 14px;
}
#help {
right: 14px;
bottom: 14px;
max-width: 150px;
text-align: right;
}
}
</style>
</head>
<body>
<div id="loader">INITIALIZING OPTICAL MODEL</div>
<div id="hud">
<section id="title" class="panel">
<div class="eyebrow">Obscura / Study 01</div>
<h1>Inverted<br>projection</h1>
<p>
Light from a solid object converges at a single aperture.
Beyond it, the rays form a reduced, reversed image on the image plane.
</p>
</section>
<section id="legend" class="panel">
<div class="legend-row">
<span class="swatch incoming"></span>
Incident rays
</div>
<div class="legend-row">
<span class="swatch projected"></span>
Projected rays
</div>
</section>
<section id="help" class="panel">
<b>Drag</b> to orbit · <b>Scroll</b> to zoom<br>
<b>R</b> or double-click to reset
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive pinhole camera projection");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x05080c);
scene.fog = new THREE.Fog(0x05080c, 19, 36);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom camera controls; no Three.js addons are used.
const orbit = {
target: new THREE.Vector3(0, -0.1, 0),
radius: 15.7,
theta: 0.72,
phi: 1.03
};
const initialOrbit = {
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.radius = initialOrbit.radius;
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
updateCamera();
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.48,
1.34
);
updateCamera();
});
function endDrag(event) {
dragging = false;
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
9,
24
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
});
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb4e9ec, 0x101015, 1.15));
const keyLight = new THREE.DirectionalLight(0xfff3dd, 2.7);
keyLight.position.set(4.5, 8.5, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const warmLight = new THREE.PointLight(0xff9b43, 18, 8, 2);
warmLight.position.set(-2.8, 0.8, 2.2);
scene.add(warmLight);
const coolLight = new THREE.PointLight(0x3be7df, 15, 7, 2);
coolLight.position.set(2.7, 0.5, 1.6);
scene.add(coolLight);
// ------------------------------------------------------------
// Materials and helpers
// ------------------------------------------------------------
const graphite = new THREE.MeshStandardMaterial({
color: 0x111920,
roughness: 0.72,
metalness: 0.36
});
const graphiteDark = new THREE.MeshStandardMaterial({
color: 0x080d12,
roughness: 0.82,
metalness: 0.22
});
const insetMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1218,
roughness: 0.9,
metalness: 0.12
});
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0x31525a,
roughness: 0.4,
metalness: 0.7
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xc4934d,
emissive: 0x3b1d05,
emissiveIntensity: 0.7,
roughness: 0.27,
metalness: 0.78
});
function addBox(width, height, depth, material, x, y, z, cast = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function lineSegments(points, color, opacity = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const lines = new THREE.LineSegments(geometry, material);
scene.add(lines);
return lines;
}
function addCylinderBetween(start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8, 1, true),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
scene.add(mesh);
return mesh;
}
function addLabel(text, color, x, y, z, width = 2.35) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 144;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
const gradient = context.createLinearGradient(0, 0, canvas.width, 0);
gradient.addColorStop(0, "rgba(7, 14, 19, 0.9)");
gradient.addColorStop(1, "rgba(7, 14, 19, 0.48)");
context.fillStyle = gradient;
context.strokeStyle = color;
context.lineWidth = 2;
context.beginPath();
context.roundRect(4, 4, canvas.width - 8, canvas.height - 8, 12);
context.fill();
context.stroke();
context.fillStyle = color;
context.font =
"600 35px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
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,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(width, width * 0.225, 1);
scene.add(sprite);
return sprite;
}
// ------------------------------------------------------------
// Dark cutaway camera box
// ------------------------------------------------------------
addBox(11.2, 6.2, 0.18, graphiteDark, 0, 0, -4.42);
addBox(0.18, 6.2, 8.9, graphiteDark, -5.52, 0, 0);
addBox(11.2, 0.18, 8.9, graphite, 0, -3.1, 0);
// A partial ceiling leaves the optical assembly exposed.
addBox(11.2, 0.16, 1.35, graphite, 0, 3.1, -3.75);
// Front-left frame member and upper cutaway beam.
addBox(0.12, 6.2, 0.12, edgeMaterial, -5.5, 0, 4.38);
addBox(11.1, 0.12, 0.12, edgeMaterial, 0, 3.1, 4.38);
// Low right-side rail marks the removed wall without obscuring it.
addBox(0.12, 0.28, 8.9, edgeMaterial, 5.52, -2.94, 0);
// Rear inset panel and ribs.
addBox(10.55, 5.48, 0.035, insetMaterial, 0, 0, -4.29);
for (const x of [-4.4, -2.2, 2.2, 4.4]) {
addBox(0.028, 5.45, 0.035, edgeMaterial, x, 0, -4.255);
}
for (const y of [-1.75, 1.75]) {
addBox(10.5, 0.025, 0.035, edgeMaterial, 0, y, -4.255);
}
// Subtle floor grid.
const floorGrid = new THREE.GridHelper(10.7, 18, 0x28454c, 0x152a30);
floorGrid.position.y = -2.995;
floorGrid.scale.z = 0.82;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.22;
floorGrid.material.depthWrite = false;
scene.add(floorGrid);
// Cut edges around the removed front and right walls.
lineSegments(
[
new THREE.Vector3(-5.5, -2.98, 4.4),
new THREE.Vector3(5.5, -2.98, 4.4),
new THREE.Vector3(5.5, -2.98, 4.4),
new THREE.Vector3(5.5, -2.98, -4.4),
new THREE.Vector3(-5.5, 3.08, 4.4),
new THREE.Vector3(5.5, 3.08, 4.4)
],
0x4a7c80,
0.38
);
// ------------------------------------------------------------
// Aperture partition with a real circular hole
// ------------------------------------------------------------
const partitionShape = new THREE.Shape();
partitionShape.moveTo(-4.25, -3.0);
partitionShape.lineTo(4.25, -3.0);
partitionShape.lineTo(4.25, 3.0);
partitionShape.lineTo(-4.25, 3.0);
partitionShape.closePath();
const apertureHole = new THREE.Path();
apertureHole.absarc(0, 0, 0.44, 0, Math.PI * 2, true);
partitionShape.holes.push(apertureHole);
const partitionGeometry = new THREE.ExtrudeGeometry(partitionShape, {
depth: 0.16,
bevelEnabled: false,
curveSegments: 40,
steps: 1
});
// The shape's local X becomes world Z; extrusion becomes world X.
partitionGeometry.rotateY(Math.PI / 2);
partitionGeometry.translate(-0.08, 0, 0);
const partition = new THREE.Mesh(partitionGeometry, graphite);
partition.castShadow = true;
partition.receiveShadow = true;
scene.add(partition);
const partitionEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(partitionGeometry, 20),
new THREE.LineBasicMaterial({
color: 0x35545b,
transparent: true,
opacity: 0.38
})
);
scene.add(partitionEdges);
// Dark aperture sleeve.
const sleeve = new THREE.Mesh(
new THREE.CylinderGeometry(0.415, 0.415, 0.28, 48, 1, true),
new THREE.MeshStandardMaterial({
color: 0x020304,
roughness: 0.95,
side: THREE.DoubleSide
})
);
sleeve.rotation.z = Math.PI / 2;
scene.add(sleeve);
// Brass aperture ring.
const apertureRing = new THREE.Mesh(
new THREE.TorusGeometry(0.47, 0.075, 12, 56),
brassMaterial
);
apertureRing.rotation.y = Math.PI / 2;
apertureRing.position.x = 0.13;
apertureRing.castShadow = true;
scene.add(apertureRing);
const aperturePointMaterial = new THREE.MeshStandardMaterial({
color: 0xbffff8,
emissive: 0x39e9df,
emissiveIntensity: 2.1,
roughness: 0.2
});
const aperturePoint = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 20, 12),
aperturePointMaterial
);
aperturePoint.position.set(0.13, 0, 0);
scene.add(aperturePoint);
// ------------------------------------------------------------
// Stylized solid object
// ------------------------------------------------------------
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.35, -1.4);
arrowShape.lineTo(0.35, -1.4);
arrowShape.lineTo(0.35, 0.35);
arrowShape.lineTo(1.05, 0.35);
arrowShape.lineTo(0, 1.55);
arrowShape.lineTo(-1.05, 0.35);
arrowShape.lineTo(-0.35, 0.35);
arrowShape.closePath();
const objectGeometry = new THREE.ExtrudeGeometry(arrowShape, {
depth: 0.72,
bevelEnabled: true,
bevelThickness: 0.07,
bevelSize: 0.06,
bevelSegments: 2,
curveSegments: 1,
steps: 1
});
objectGeometry.center();
objectGeometry.rotateY(-Math.PI / 2);
const objectMaterial = new THREE.MeshStandardMaterial({
color: 0xf0a12e,
emissive: 0x522000,
emissiveIntensity: 0.38,
roughness: 0.32,
metalness: 0.18
});
const objectMesh = new THREE.Mesh(objectGeometry, objectMaterial);
objectMesh.position.set(-3.56, 0, 0);
objectMesh.castShadow = true;
objectMesh.receiveShadow = true;
scene.add(objectMesh);
const objectEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(objectGeometry, 25),
new THREE.LineBasicMaterial({
color: 0xffd58b,
transparent: true,
opacity: 0.42
})
);
objectMesh.add(objectEdges);
// Pedestal.
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(1.12, 1.22, 0.2, 48),
graphite
);
pedestal.position.set(-3.56, -2.86, 0);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const pedestalRing = new THREE.Mesh(
new THREE.TorusGeometry(1.08, 0.022, 8, 64),
new THREE.MeshBasicMaterial({ color: 0x9c5d24 })
);
pedestalRing.rotation.x = Math.PI / 2;
pedestalRing.position.set(-3.56, -2.74, 0);
scene.add(pedestalRing);
// ------------------------------------------------------------
// Image plane and inverted projected form
// ------------------------------------------------------------
const imagePlane = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 5.25, 6.25),
new THREE.MeshStandardMaterial({
color: 0x174149,
emissive: 0x082c32,
emissiveIntensity: 0.5,
transparent: true,
opacity: 0.24,
depthWrite: false,
side: THREE.DoubleSide,
roughness: 0.22,
metalness: 0.25
})
);
imagePlane.position.set(3.18, 0, 0);
scene.add(imagePlane);
// Image-plane border.
lineSegments(
[
new THREE.Vector3(3.215, -2.625, -3.125),
new THREE.Vector3(3.215, 2.625, -3.125),
new THREE.Vector3(3.215, 2.625, 3.125),
new THREE.Vector3(3.215, -2.625, 3.125),
new THREE.Vector3(3.215, -2.625, -3.125),
new THREE.Vector3(3.215, -2.625, 3.125),
new THREE.Vector3(3.215, 2.625, -3.125),
new THREE.Vector3(3.215, 2.625, 3.125)
],
0x68d6d1,
0.7
);
// Fine coordinate grid on the image plane.
const imageGridPoints = [];
for (let y = -2.5; y <= 2.51; y += 0.5) {
imageGridPoints.push(
new THREE.Vector3(3.215, y, -3.1),
new THREE.Vector3(3.215, y, 3.1)
);
}
for (let z = -3; z <= 3.01; z += 0.5) {
imageGridPoints.push(
new THREE.Vector3(3.215, -2.6, z),
new THREE.Vector3(3.215, 2.6, z)
);
}
lineSegments(imageGridPoints, 0x3c8587, 0.15);
// Flat, luminous, inverted copy of the object.
const projectedGeometry = new THREE.ExtrudeGeometry(arrowShape, {
depth: 0.065,
bevelEnabled: false,
curveSegments: 1,
steps: 1
});
projectedGeometry.center();
projectedGeometry.rotateY(-Math.PI / 2);
const projectedMaterial = new THREE.MeshStandardMaterial({
color: 0x54e9e0,
emissive: 0x20c7c0,
emissiveIntensity: 1.15,
roughness: 0.35,
metalness: 0.05,
transparent: true,
opacity: 0.92,
side: THREE.DoubleSide
});
const projectedMesh = new THREE.Mesh(
projectedGeometry,
projectedMaterial
);
projectedMesh.position.set(3.225, 0, 0);
projectedMesh.scale.set(1, -1, -1);
scene.add(projectedMesh);
const projectedEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(projectedGeometry, 20),
new THREE.LineBasicMaterial({
color: 0xb5fff9,
transparent: true,
opacity: 0.9
})
);
projectedMesh.add(projectedEdges);
// ------------------------------------------------------------
// Geometric rays
// ------------------------------------------------------------
const aperture = new THREE.Vector3(0.13, 0, 0);
const sourceX = -3.2;
const imageX = 3.2;
const featurePoints = [
new THREE.Vector3(sourceX, 1.475, 0), // arrow tip
new THREE.Vector3(sourceX, -1.475, -0.72), // lower corner
new THREE.Vector3(sourceX, -1.475, 0.72), // lower corner
new THREE.Vector3(sourceX, 0.275, -1.02), // shoulder
new THREE.Vector3(sourceX, 0.275, 1.02) // shoulder
];
const incomingCore = new THREE.MeshBasicMaterial({
color: 0xffb24a,
transparent: true,
opacity: 0.9,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const incomingGlow = new THREE.MeshBasicMaterial({
color: 0xff8a1f,
transparent: true,
opacity: 0.09,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const outgoingCore = new THREE.MeshBasicMaterial({
color: 0x51e5df,
transparent: true,
opacity: 0.86,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const outgoingGlow = new THREE.MeshBasicMaterial({
color: 0x20d9d2,
transparent: true,
opacity: 0.08,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const sourceNodeMaterial = new THREE.MeshBasicMaterial({
color: 0xffd18a
});
const imageNodeMaterial = new THREE.MeshBasicMaterial({
color: 0x8ffff7
});
for (const point of featurePoints) {
// The image is inverted in both height and depth.
const projectedPoint = new THREE.Vector3(
imageX,
-point.y,
-point.z
);
addCylinderBetween(point, aperture, 0.012, incomingCore);
addCylinderBetween(point, aperture, 0.035, incomingGlow);
addCylinderBetween(aperture, projectedPoint, 0.011, outgoingCore);
addCylinderBetween(aperture, projectedPoint, 0.032, outgoingGlow);
const sourceNode = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 12, 8),
sourceNodeMaterial
);
sourceNode.position.copy(point);
scene.add(sourceNode);
const imageNode = new THREE.Mesh(
new THREE.SphereGeometry(0.043, 12, 8),
imageNodeMaterial
);
imageNode.position.copy(projectedPoint);
scene.add(imageNode);
}
// ------------------------------------------------------------
// Labels
// ------------------------------------------------------------
addLabel("SOLID OBJECT", "#ffb24a", -3.25, 2.25, 0, 2.25);
addLabel("PINHOLE", "#70e3dd", 0.1, 2.65, 0, 1.65);
addLabel("INVERTED IMAGE", "#70e3dd", 3.3, 2.65, 0, 2.55);
// Leader lines.
lineSegments(
[
new THREE.Vector3(-3.25, 2.02, 0),
new THREE.Vector3(-3.25, 1.62, 0),
new THREE.Vector3(0.1, 2.39, 0),
new THREE.Vector3(0.1, 1.68, 0),
new THREE.Vector3(3.3, 2.39, 0),
new THREE.Vector3(3.3, 1.66, 0)
],
0x72aaa9,
0.38
);
// ------------------------------------------------------------
// Atmospheric dust
// ------------------------------------------------------------
const dustCount = 170;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 10.5;
dustPositions[i * 3 + 1] = (Math.random() - 0.5) * 5.7;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 8.2;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x86c7c9,
size: 0.025,
transparent: true,
opacity: 0.32,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
scene.add(dust);
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
aperturePointMaterial.emissiveIntensity =
1.9 + Math.sin(elapsed * 2.2) * 0.28;
projectedMaterial.emissiveIntensity =
1.05 + Math.sin(elapsed * 1.7 + 0.8) * 0.16;
dust.rotation.y = elapsed * 0.008;
dust.position.y = Math.sin(elapsed * 0.18) * 0.035;
renderer.render(scene, camera);
});
document.getElementById("loader").classList.add("hidden");
</script>
</body>
</html>
```