Prompt specification
Build or customize the Three.js 3D scene "Sign under changing illumination" 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: Sign under changing illumination
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sign-under-changing-illumination-x0414
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts high-contrast wayfinding signs. Move a lamp across a corridor sign and compare matte versus glossy finishes; show glare and shadow changes while the direction arrow remains geometrically identical. Low-poly.
Working Three.js Starter (sign-under-changing-illumination-x0414):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Wayfinding Finish Study</title>
<style>
:root {
color-scheme: dark;
--ink: #071018;
--panel: rgba(8, 15, 23, 0.86);
--line: rgba(255, 255, 255, 0.16);
--white: #f4f7f8;
--muted: #9baab4;
--yellow: #ffd54a;
--cyan: #70d9df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--white);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.topbar {
position: fixed;
top: 28px;
left: 30px;
z-index: 10;
width: min(520px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--yellow);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 3px;
content: "";
background: var(--yellow);
}
h1 {
margin: 0;
font-size: clamp(30px, 4.5vw, 62px);
font-weight: 850;
letter-spacing: -0.045em;
line-height: 0.98;
}
.topbar p {
max-width: 460px;
margin: 14px 0 0;
color: #d1dbe0;
font-size: 14px;
line-height: 1.55;
}
.legend {
position: fixed;
top: 28px;
right: 28px;
z-index: 10;
display: grid;
gap: 8px;
width: 210px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(8, 15, 23, 0.72);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row strong {
color: var(--white);
font-size: 11px;
}
.swatch {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 7px;
border-radius: 50%;
}
.swatch.matte {
background: var(--cyan);
box-shadow: 0 0 12px rgba(112, 217, 223, 0.5);
}
.swatch.gloss {
background: var(--yellow);
box-shadow: 0 0 12px rgba(255, 213, 74, 0.5);
}
.control-panel {
position: fixed;
left: 28px;
bottom: 26px;
z-index: 20;
width: min(390px, calc(100vw - 56px));
padding: 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(16px);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.panel-title span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#lampReadout {
color: var(--yellow);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 20px;
margin: 0;
accent-color: var(--yellow);
cursor: ew-resize;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 1px;
color: #788994;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 15px;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.05);
color: var(--white);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.05em;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(255, 255, 255, 0.38);
background: rgba(255, 255, 255, 0.1);
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: rgba(255, 213, 74, 0.5);
background: rgba(255, 213, 74, 0.13);
color: var(--yellow);
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.metric {
min-height: 54px;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
}
.metric small {
display: block;
margin-bottom: 5px;
color: #82929c;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric strong {
color: #e8eef1;
font-size: 11px;
font-weight: 750;
}
.camera-hint {
position: fixed;
right: 28px;
bottom: 28px;
z-index: 10;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 15, 23, 0.64);
color: #aab7be;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
pointer-events: none;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #071018;
color: var(--yellow);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.topbar {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
.topbar p {
display: none;
}
.legend {
top: auto;
right: 18px;
bottom: 220px;
width: 174px;
}
.control-panel {
left: 18px;
bottom: 18px;
width: calc(100vw - 36px);
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D corridor comparing matte and glossy signs"></div>
<header class="topbar">
<div class="eyebrow">Wayfinding / optical study</div>
<h1>Same direction.<br />Different finish.</h1>
<p>
A moving inspection lamp reveals diffuse response on the matte panel and
a traveling clearcoat highlight on the glossy panel. Both arrows use
exactly the same geometry.
</p>
</header>
<aside class="legend" aria-label="Finish legend">
<div class="legend-row">
<span><i class="swatch matte"></i>Left panel</span>
<strong>Matte</strong>
</div>
<div class="legend-row">
<span><i class="swatch gloss"></i>Right panel</span>
<strong>Gloss</strong>
</div>
</aside>
<section class="control-panel" aria-label="Scene controls">
<div class="panel-title">
<span>Lamp travel</span>
<output id="lampReadout">+0.00 m</output>
</div>
<input
id="lampSlider"
type="range"
min="0"
max="100"
value="50"
aria-label="Move lamp across the corridor signs"
/>
<div class="range-labels">
<span>Left edge</span>
<span>Right edge</span>
</div>
<div class="buttons">
<button id="playButton" class="primary" type="button">Pause sweep</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div class="metrics">
<div class="metric">
<small>Arrow buffer</small>
<strong>Shared / identical</strong>
</div>
<div class="metric">
<small>Lighting behavior</small>
<strong>Diffuse + specular</strong>
</div>
</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="loading">Loading corridor study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const slider = document.getElementById("lampSlider");
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const lampReadout = document.getElementById("lampReadout");
// -----------------------------------------------------------------------
// Renderer and scene
// -----------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1219);
scene.fog = new THREE.Fog(0x0b1219, 12, 29);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
50
);
// Custom orbit controls: no addons are used.
const cameraTarget = new THREE.Vector3(0, 1.6, -6.65);
const spherical = new THREE.Spherical(12.7, 1.46, 0);
const cameraOffset = new THREE.Vector3();
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 1.17, 1.55);
spherical.theta = THREE.MathUtils.clamp(spherical.theta, -0.48, 0.48);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 8.4, 17.5);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraOffset).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function resetCamera() {
spherical.set(12.7, 1.46, 0);
updateCamera();
}
resetCamera();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
spherical.theta -= dx * 0.0045;
spherical.phi -= dy * 0.0035;
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (
event &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
// -----------------------------------------------------------------------
// Lighting
// -----------------------------------------------------------------------
scene.add(
new THREE.HemisphereLight(0xa9c6dc, 0x17120d, 1.05)
);
const softFill = new THREE.DirectionalLight(0xc6d9e8, 0.75);
softFill.position.set(2.5, 5.5, 5.5);
scene.add(softFill);
const fixtureMaterial = new THREE.MeshStandardMaterial({
color: 0xe8f0df,
emissive: 0xd8e6d3,
emissiveIntensity: 2.6,
roughness: 0.7,
});
// -----------------------------------------------------------------------
// Low-poly corridor
// -----------------------------------------------------------------------
function addBox(
width,
height,
depth,
material,
x,
y,
z,
castShadow = false,
receiveShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
scene.add(mesh);
return mesh;
}
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x202830,
roughness: 0.88,
metalness: 0.05,
});
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x303a40,
roughness: 0.92,
});
const ceilingMaterial = new THREE.MeshStandardMaterial({
color: 0x202930,
roughness: 0.96,
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0x4c5961,
roughness: 0.58,
metalness: 0.32,
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(12, 25),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.z = -1;
floor.receiveShadow = true;
scene.add(floor);
addBox(0.2, 4.25, 25, wallMaterial, -6, 2.12, -1);
addBox(0.2, 4.25, 25, wallMaterial, 6, 2.12, -1);
addBox(12.2, 0.18, 25, ceilingMaterial, 0, 4.2, -1);
addBox(12.2, 4.25, 0.2, wallMaterial, 0, 2.12, -8.45);
// A broad receiver panel makes the moving cast shadows easy to read.
addBox(
8.45,
2.95,
0.08,
new THREE.MeshStandardMaterial({
color: 0x667176,
roughness: 0.95,
}),
0,
1.86,
-8.31
);
for (const z of [-7, -3, 1, 5, 9]) {
addBox(12, 0.08, 0.13, trimMaterial, 0, 4.08, z);
}
for (const z of [-6, -2, 2, 6, 10]) {
addBox(0.08, 3.4, 0.08, trimMaterial, -5.83, 2.05, z);
addBox(0.08, 3.4, 0.08, trimMaterial, 5.83, 2.05, z);
}
// Sparse floor joints.
const floorLinePoints = [];
for (let x = -5; x <= 5; x += 1) {
floorLinePoints.push(x, 0.008, -13, x, 0.008, 11.5);
}
for (let z = -12; z <= 11; z += 2) {
floorLinePoints.push(-5.85, 0.009, z, 5.85, 0.009, z);
}
const floorLines = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(floorLinePoints, 3)
),
new THREE.LineBasicMaterial({
color: 0x59656d,
transparent: true,
opacity: 0.32,
})
);
scene.add(floorLines);
// Static practical lights keep the corridor readable.
for (const z of [-4.5, 1, 6.5]) {
addBox(
1.85,
0.055,
0.32,
fixtureMaterial,
0,
4.045,
z,
false,
false
);
const practical = new THREE.PointLight(0xe2eadf, 16, 5.5, 2);
practical.position.set(0, 3.82, z);
scene.add(practical);
}
// -----------------------------------------------------------------------
// Sign textures
// -----------------------------------------------------------------------
function makeTextTexture(mainText, subText) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 320;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#ffffff";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "900 176px Arial, sans-serif";
context.fillText(mainText, 512, 115);
context.fillStyle = "#d8e4eb";
context.font = "700 66px Arial, sans-serif";
context.fillText(subText, 512, 248);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeGlareTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
128,
64,
2,
128,
64,
126
);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.16, "rgba(255,248,220,0.9)");
gradient.addColorStop(0.48, "rgba(255,226,160,0.25)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 128);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeFinishLabel(title, detail, accent) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(7,16,24,0.92)";
context.fillRect(0, 0, 768, 160);
context.fillStyle = accent;
context.fillRect(0, 0, 13, 160);
context.textBaseline = "middle";
context.fillStyle = "#ffffff";
context.font = "900 58px Arial, sans-serif";
context.fillText(title, 42, 55);
context.fillStyle = "#9db0bb";
context.font = "700 29px Arial, sans-serif";
context.fillText(detail, 43, 111);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false,
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.45, 0.51, 1);
return sprite;
}
const titleTexture = makeTextTexture("GATES", "A—F / LEVEL 02");
const titleMaterial = new THREE.MeshBasicMaterial({
map: titleTexture,
transparent: true,
depthWrite: false,
toneMapped: false,
});
// One geometry is shared by both arrow meshes. It is never scaled,
// rotated, or replaced during the lighting demonstration.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.62, -0.11);
arrowShape.lineTo(0.05, -0.11);
arrowShape.lineTo(0.05, -0.4);
arrowShape.lineTo(0.7, 0);
arrowShape.lineTo(0.05, 0.4);
arrowShape.lineTo(0.05, 0.11);
arrowShape.lineTo(-0.62, 0.11);
arrowShape.closePath();
const arrowGeometry = new THREE.ExtrudeGeometry(arrowShape, {
depth: 0.065,
bevelEnabled: false,
steps: 1,
curveSegments: 1,
});
arrowGeometry.computeVertexNormals();
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffd447,
roughness: 0.38,
metalness: 0.04,
emissive: 0x5d3900,
emissiveIntensity: 0.2,
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x8f9ba1,
roughness: 0.33,
metalness: 0.72,
});
const matteMaterial = new THREE.MeshPhysicalMaterial({
color: 0x082b52,
emissive: 0x011124,
emissiveIntensity: 0.18,
roughness: 0.94,
metalness: 0,
clearcoat: 0,
specularIntensity: 0.22,
});
const glossyMaterial = new THREE.MeshPhysicalMaterial({
color: 0x082b52,
emissive: 0x011124,
emissiveIntensity: 0.18,
roughness: 0.16,
metalness: 0.05,
clearcoat: 1,
clearcoatRoughness: 0.035,
specularIntensity: 1.25,
});
const glareTexture = makeGlareTexture();
const signs = [];
function createSign(x, material, labelTitle, labelDetail, accent) {
addBox(
3.06,
1.58,
0.16,
frameMaterial,
x,
2.05,
-8.2,
true,
true
);
const board = addBox(
2.95,
1.46,
0.11,
material,
x,
2.05,
-8.085,
true,
true
);
const title = new THREE.Mesh(
new THREE.PlaneGeometry(1.55, 0.32),
titleMaterial
);
title.position.set(x - 0.34, 2.51, -8.008);
scene.add(title);
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.position.set(x + 0.56, 1.78, -7.94);
arrow.castShadow = true;
arrow.receiveShadow = true;
scene.add(arrow);
const label = makeFinishLabel(labelTitle, labelDetail, accent);
label.position.set(x, 1.01, -7.96);
label.renderOrder = 5;
scene.add(label);
let glare = null;
if (material === glossyMaterial) {
// A controlled broad reflection supplements the physically based
// clearcoat highlight, making the moving glare legible on screen.
glare = new THREE.Mesh(
new THREE.PlaneGeometry(1.48, 0.48),
new THREE.MeshBasicMaterial({
map: glareTexture,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false,
})
);
glare.position.set(x, 2.47, -8.016);
glare.renderOrder = 2;
scene.add(glare);
}
signs.push({ x, board, arrow, glare });
}
createSign(
-1.7,
matteMaterial,
"MATTE",
"ROUGH 0.94 / DIFFUSE",
"#70d9df"
);
createSign(
1.7,
glossyMaterial,
"GLOSS",
"CLEARCOAT 1.0 / SPECULAR",
"#ffd54a"
);
// -----------------------------------------------------------------------
// Moving inspection lamp
// -----------------------------------------------------------------------
const lampGroup = new THREE.Group();
lampGroup.position.set(0, 2.16, -6.25);
scene.add(lampGroup);
const lampRing = new THREE.Mesh(
new THREE.TorusGeometry(0.3, 0.052, 6, 14),
new THREE.MeshStandardMaterial({
color: 0x313941,
roughness: 0.28,
metalness: 0.78,
})
);
lampGroup.add(lampRing);
const lampBulb = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 1),
new THREE.MeshBasicMaterial({
color: 0xfff1b9,
toneMapped: false,
})
);
lampBulb.position.z = -0.1;
lampGroup.add(lampBulb);
const movingLight = new THREE.PointLight(0xffd99b, 145, 11, 2);
movingLight.position.z = -0.16;
movingLight.castShadow = true;
movingLight.shadow.mapSize.set(1024, 1024);
movingLight.shadow.camera.near = 0.08;
movingLight.shadow.camera.far = 12;
movingLight.shadow.bias = -0.00025;
movingLight.shadow.normalBias = 0.012;
lampGroup.add(movingLight);
// A very low-intensity neighboring source broadens the apparent bulb
// reflection without changing the primary shadow behavior.
const softLampFill = new THREE.PointLight(0xffe8bd, 15, 7, 2);
softLampFill.position.set(0.28, 0.06, -0.18);
lampGroup.add(softLampFill);
// -----------------------------------------------------------------------
// Interaction and animation
// -----------------------------------------------------------------------
let automatic = true;
let manualPosition = 0.5;
let sweepPhase = 0;
let lastTime = performance.now();
function updatePlayButton() {
playButton.textContent = automatic ? "Pause sweep" : "Play sweep";
playButton.setAttribute("aria-pressed", String(automatic));
}
slider.addEventListener("input", () => {
automatic = false;
manualPosition = Number(slider.value) / 100;
updatePlayButton();
});
playButton.addEventListener("click", () => {
automatic = !automatic;
if (automatic) {
sweepPhase = Math.asin(
THREE.MathUtils.clamp((manualPosition - 0.5) * 2, -1, 1)
);
}
updatePlayButton();
});
window.addEventListener("keydown", (event) => {
if (event.target === slider) return;
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.code === "ArrowLeft" || event.code === "ArrowRight") {
automatic = false;
manualPosition = THREE.MathUtils.clamp(
manualPosition + (event.code === "ArrowRight" ? 0.025 : -0.025),
0,
1
);
slider.value = String(Math.round(manualPosition * 100));
updatePlayButton();
}
});
function smoothstep(min, max, value) {
const t = THREE.MathUtils.clamp(
(value - min) / (max - min),
0,
1
);
return t * t * (3 - 2 * t);
}
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
let travel = manualPosition;
if (automatic) {
sweepPhase += dt * 0.62;
travel = 0.5 + 0.5 * Math.sin(sweepPhase);
slider.value = String(Math.round(travel * 100));
}
const lampX = THREE.MathUtils.lerp(-3.35, 3.35, travel);
lampGroup.position.x = lampX;
lampGroup.position.y = 2.16 + Math.sin(now * 0.0021) * 0.025;
lampGroup.rotation.z = Math.sin(now * 0.0014) * 0.025;
lampReadout.textContent = `${lampX >= 0 ? "+" : ""}${lampX.toFixed(2)} m`;
for (const sign of signs) {
if (!sign.glare) continue;
const distance = Math.abs(lampX - sign.x);
const proximity = 1 - smoothstep(0.4, 2.8, distance);
const reflectedOffset = THREE.MathUtils.clamp(
(lampX - sign.x) * 0.68,
-0.88,
0.88
);
sign.glare.position.x = sign.x + reflectedOffset;
sign.glare.position.y = 2.47 + Math.sin(lampX * 1.6) * 0.055;
sign.glare.material.opacity = proximity * proximity * 0.42;
sign.glare.scale.set(
0.58 + proximity * 0.5,
0.58 + proximity * 0.5,
1
);
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.domElement.style.cursor = "grab";
updatePlayButton();
renderer.render(scene, camera);
loading.classList.add("hidden");
requestAnimationFrame(animate);
</script>
</body>
</html>
```