Prompt specification
Build or customize the Three.js 3D scene "Moving Receiver Optical Puzzle" 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: Moving Receiver Optical Puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/moving-receiver-optical-puzzle-x3472
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: moving receiver optical puzzle. Create a playable mirror puzzle whose receiver follows a slow visible rail. Let players pause and adjust mirrors, validating actual beam intersection with the receiver.
Working Three.js Starter (moving-receiver-optical-puzzle-x3472):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rail Lab — Moving Receiver</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(10, 22, 38, 0.86);
--panel-strong: rgba(13, 29, 48, 0.96);
--line: rgba(148, 190, 220, 0.18);
--text: #e9f5ff;
--muted: #8ba4ba;
--cyan: #66e9ff;
--cyan-soft: rgba(102, 233, 255, 0.14);
--amber: #ffc45f;
--amber-soft: rgba(255, 196, 95, 0.14);
--green: #70f0a6;
--red: #ff7185;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#sceneRoot {
position: fixed;
inset: 0;
}
#sceneRoot canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow:
0 16px 45px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
position: absolute;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-4deg);
flex: 0 0 auto;
}
.brand-mark i {
display: block;
background: #214258;
border: 1px solid rgba(102, 233, 255, 0.13);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(8) {
background: var(--cyan);
box-shadow: 0 0 12px rgba(102, 233, 255, 0.42);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.brand h1 {
margin: 3px 0 0;
font-size: clamp(18px, 2.1vw, 27px);
line-height: 1;
letter-spacing: -0.035em;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.status-pill {
min-width: 84px;
padding: 9px 13px;
border: 1px solid rgba(112, 240, 166, 0.25);
border-radius: 999px;
background: rgba(21, 74, 54, 0.45);
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-align: center;
}
.status-pill.paused {
color: var(--amber);
border-color: rgba(255, 196, 95, 0.28);
background: rgba(100, 66, 18, 0.42);
}
.button {
border: 1px solid var(--line);
border-radius: 10px;
padding: 9px 13px;
color: var(--text);
background: rgba(13, 29, 48, 0.82);
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.button:hover {
border-color: rgba(102, 233, 255, 0.55);
background: rgba(23, 48, 72, 0.92);
}
.button:active {
transform: translateY(1px);
}
.button.primary {
color: #04121b;
border-color: var(--cyan);
background: var(--cyan);
font-weight: 800;
}
.button.primary:hover {
background: #a2f2ff;
}
.button.small {
padding: 7px 10px;
font-size: 11px;
}
.objective {
position: absolute;
top: 88px;
left: 20px;
width: 286px;
padding: 18px;
pointer-events: auto;
}
.objective h2 {
margin: 7px 0 9px;
font-size: 19px;
letter-spacing: -0.025em;
}
.objective p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.steps {
display: grid;
gap: 9px;
margin-top: 15px;
}
.step {
display: flex;
align-items: center;
gap: 10px;
color: #b9cddd;
font-size: 11px;
}
.step-number {
width: 23px;
height: 23px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid rgba(102, 233, 255, 0.25);
border-radius: 7px;
color: var(--cyan);
background: var(--cyan-soft);
font-size: 10px;
font-weight: 850;
}
.control-note {
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #718da4;
font-size: 10px;
line-height: 1.55;
}
kbd {
padding: 2px 5px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-bottom-width: 2px;
border-radius: 4px;
color: #c8d9e8;
background: rgba(255, 255, 255, 0.055);
font-size: 9px;
font-family: inherit;
}
.console {
position: absolute;
top: 88px;
right: 20px;
width: 326px;
padding: 17px;
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 14px;
letter-spacing: -0.01em;
}
.tiny-label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.signal-card {
padding: 13px;
border: 1px solid rgba(102, 233, 255, 0.14);
border-radius: 12px;
background: linear-gradient(135deg, rgba(24, 56, 79, 0.58), rgba(9, 23, 39, 0.75));
}
.signal-row {
display: flex;
align-items: center;
gap: 10px;
}
.signal-dot {
width: 11px;
height: 11px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 5px rgba(102, 233, 255, 0.08), 0 0 15px var(--cyan);
transition: 180ms ease;
}
.signal-dot.hit {
background: var(--green);
box-shadow: 0 0 0 5px rgba(112, 240, 166, 0.09), 0 0 18px var(--green);
}
.signal-dot.paused-hit {
background: var(--amber);
box-shadow: 0 0 0 5px rgba(255, 196, 95, 0.09), 0 0 18px var(--amber);
}
#signalText {
font-size: 12px;
font-weight: 850;
letter-spacing: 0.07em;
}
#signalDetail {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.capture-track {
height: 4px;
margin-top: 12px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
#captureFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--green));
box-shadow: 0 0 10px var(--green);
transition: width 80ms linear;
}
.receiver-readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.readout {
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(5, 15, 27, 0.38);
}
.readout strong {
display: block;
margin-top: 4px;
color: var(--amber);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.divider {
height: 1px;
margin: 15px 0;
background: var(--line);
}
.mirror-list {
display: grid;
gap: 8px;
}
.mirror-card {
padding: 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(6, 17, 30, 0.36);
cursor: pointer;
transition: 160ms ease;
}
.mirror-card:hover {
border-color: rgba(102, 233, 255, 0.28);
}
.mirror-card.selected {
border-color: rgba(102, 233, 255, 0.6);
background: rgba(25, 57, 78, 0.48);
box-shadow: inset 3px 0 0 var(--cyan);
}
.mirror-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.mirror-id {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
}
.mirror-position {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.mirror-actions {
display: flex;
align-items: center;
gap: 6px;
}
.angle-box {
min-width: 47px;
padding: 5px 6px;
border: 1px solid rgba(102, 233, 255, 0.18);
border-radius: 7px;
color: var(--cyan);
background: rgba(102, 233, 255, 0.07);
font-size: 11px;
font-weight: 850;
text-align: center;
font-variant-numeric: tabular-nums;
}
.rotate-button {
width: 27px;
height: 27px;
padding: 0;
border: 1px solid var(--line);
border-radius: 7px;
color: #c6d7e5;
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
}
.rotate-button:hover {
color: var(--cyan);
border-color: rgba(102, 233, 255, 0.45);
}
.selection-tools {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.selection-tools .button {
width: 100%;
font-size: 11px;
}
.hint-box {
margin-top: 11px;
padding: 10px 11px;
border-left: 2px solid var(--amber);
border-radius: 0 8px 8px 0;
color: #b8c8d5;
background: var(--amber-soft);
font-size: 10px;
line-height: 1.45;
}
.hint-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
}
.hint-header button {
border: 0;
padding: 0;
color: var(--amber);
background: transparent;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
cursor: pointer;
}
.console-footer {
display: flex;
gap: 8px;
margin-top: 11px;
}
.console-footer .button {
flex: 1;
font-size: 10px;
}
.success {
position: absolute;
left: 50%;
bottom: 23px;
width: min(460px, calc(100vw - 30px));
padding: 14px 17px;
display: none;
align-items: center;
justify-content: space-between;
gap: 18px;
transform: translateX(-50%);
border-color: rgba(112, 240, 166, 0.42);
background: rgba(10, 42, 32, 0.92);
pointer-events: auto;
}
.success.show {
display: flex;
animation: success-in 350ms ease both;
}
.success strong {
display: block;
color: var(--green);
font-size: 12px;
letter-spacing: 0.08em;
}
.success span {
display: block;
margin-top: 4px;
color: #a7c9b8;
font-size: 10px;
}
@keyframes success-in {
from {
opacity: 0;
transform: translate(-50%, 12px);
}
to {
opacity: 1;
transform: translate(-50%, 0);
}
}
.world-tag {
position: fixed;
z-index: 4;
pointer-events: none;
transform: translate(-50%, -100%);
padding: 4px 7px;
border: 1px solid rgba(137, 185, 215, 0.16);
border-radius: 5px;
color: #9db5c8;
background: rgba(4, 12, 23, 0.72);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
white-space: nowrap;
}
.world-tag.source {
color: var(--cyan);
}
.world-tag.receiver {
color: var(--amber);
}
@media (max-width: 820px) {
header {
top: 11px;
left: 12px;
right: 12px;
}
.brand-mark {
width: 31px;
height: 31px;
}
.status-pill {
display: none;
}
.objective {
top: 63px;
left: 12px;
width: 235px;
padding: 13px;
}
.objective h2 {
font-size: 15px;
}
.objective p,
.steps,
.control-note {
display: none;
}
.console {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 48vh;
overflow: auto;
padding: 13px;
}
.mirror-list {
grid-template-columns: 1fr 1fr;
}
.signal-card {
padding: 10px;
}
.divider {
margin: 10px 0;
}
.success {
bottom: calc(48vh + 23px);
}
}
@media (max-width: 520px) {
.brand .eyebrow {
display: none;
}
.brand h1 {
font-size: 17px;
}
.top-actions .button:not(.primary) {
display: none;
}
.objective {
width: 205px;
}
.mirror-list {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div id="sceneRoot"></div>
<div class="hud">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<div class="eyebrow">Optical Systems / Test 07</div>
<h1>RAIL LAB</h1>
</div>
</div>
<div class="top-actions">
<div id="statusPill" class="status-pill">RECEIVER LIVE</div>
<button id="cameraBtn" class="button small" type="button">Reset camera</button>
<button id="pauseBtn" class="button primary" type="button">Pause receiver</button>
</div>
</header>
<section class="objective glass">
<div class="eyebrow">Mission</div>
<h2>Catch the moving receiver</h2>
<p>
Rotate the two mirrors so the cyan beam reaches the amber receiver
while it travels along the rail.
</p>
<div class="steps">
<div class="step">
<span class="step-number">1</span>
<span>Turn the eastbound beam north at M-01.</span>
</div>
<div class="step">
<span class="step-number">2</span>
<span>Turn the northbound beam east at M-02.</span>
</div>
<div class="step">
<span class="step-number">3</span>
<span>Resume and wait for a real beam/lens intersection.</span>
</div>
</div>
<div class="control-note">
Click a mirror to select it. Rotate with the console buttons or
<kbd>Q</kbd>/<kbd>E</kbd>. Pause with <kbd>Space</kbd>.<br>
Drag empty space to orbit; scroll to zoom.
</div>
</section>
<section class="console glass">
<div class="panel-heading">
<h2>Mirror console</h2>
<span class="tiny-label">Live optical trace</span>
</div>
<div class="signal-card">
<div class="signal-row">
<span id="signalDot" class="signal-dot"></span>
<div>
<div id="signalText" aria-live="polite">SEARCHING</div>
<div id="signalDetail">The beam does not currently intersect the receiver lens.</div>
</div>
</div>
<div class="capture-track">
<div id="captureFill"></div>
</div>
</div>
<div class="receiver-readout">
<div class="readout">
<span class="tiny-label">Rail position</span>
<strong id="receiverCoord">Z -3.05</strong>
</div>
<div class="readout">
<span class="tiny-label">Velocity</span>
<strong id="receiverSpeed">1.24 u/s</strong>
</div>
</div>
<div class="divider"></div>
<div class="panel-heading">
<h2 id="selectedName">M-01 selected</h2>
<span id="selectedAngle" class="tiny-label">0°</span>
</div>
<div id="mirrorList" class="mirror-list">
<div class="mirror-card selected" data-mirror="0" role="button" tabindex="0">
<div class="mirror-top">
<div>
<div class="mirror-id">M-01</div>
<div class="mirror-position">X -3.0 · Z -5.0</div>
</div>
<div class="mirror-actions">
<button class="rotate-button" data-delta="-1" type="button" aria-label="Rotate M-01 counterclockwise">−</button>
<div class="angle-box">0°</div>
<button class="rotate-button" data-delta="1" type="button" aria-label="Rotate M-01 clockwise">+</button>
</div>
</div>
</div>
<div class="mirror-card" data-mirror="1" role="button" tabindex="0">
<div class="mirror-top">
<div>
<div class="mirror-id">M-02</div>
<div class="mirror-position">X -3.0 · Z 0.0</div>
</div>
<div class="mirror-actions">
<button class="rotate-button" data-delta="-1" type="button" aria-label="Rotate M-02 counterclockwise">−</button>
<div class="angle-box">90°</div>
<button class="rotate-button" data-delta="1" type="button" aria-label="Rotate M-02 clockwise">+</button>
</div>
</div>
</div>
</div>
<div class="selection-tools">
<button id="rotateLeft" class="button" type="button">− 45°</button>
<button id="rotateRight" class="button" type="button">+ 45°</button>
</div>
<div class="hint-box">
<div class="hint-header">
<span class="tiny-label" style="color: var(--amber)">Field note</span>
<button id="hintBtn" type="button">NEXT HINT</button>
</div>
<div id="hintText">Pause the carrier if you need time to plan.</div>
</div>
<div class="console-footer">
<button id="resetBtn" class="button" type="button">Reset puzzle</button>
<button id="solvePathBtn" class="button" type="button">Test optical path</button>
</div>
</section>
<div id="successToast" class="success glass">
<div>
<strong>SIGNAL CAPTURED</strong>
<span>The beam physically intersected the moving receiver lens.</span>
</div>
<button id="successReset" class="button small" type="button">Run again</button>
</div>
</div>
<div id="sourceTag" class="world-tag source">SOURCE</div>
<div id="m1Tag" class="world-tag">M-01</div>
<div id="m2Tag" class="world-tag">M-02</div>
<div id="receiverTag" class="world-tag receiver">CARRIER</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const sceneRoot = document.getElementById("sceneRoot");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 28, 52);
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.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneRoot.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
yaw: 0.62,
pitch: 0.76,
distance: 25,
target: new THREE.Vector3(-0.3, 0.15, 0)
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0x9ddfff, 0x162033, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xd8efff, 3.2);
keyLight.position.set(-7, 15, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x386dff, 1.25);
rimLight.position.set(12, 7, -10);
scene.add(rimLight);
const BEAM_Y = 1.05;
const MIRROR_LENGTH = 2.2;
const BOARD_MIN_X = -10.5;
const BOARD_MAX_X = 10.5;
const BOARD_MIN_Z = -8.5;
const BOARD_MAX_Z = 8.5;
const boardBase = new THREE.Mesh(
new THREE.BoxGeometry(21.8, 0.5, 17.8),
new THREE.MeshStandardMaterial({
color: 0x0a1727,
roughness: 0.9,
metalness: 0.08
})
);
boardBase.position.y = -0.42;
boardBase.receiveShadow = true;
boardBase.castShadow = true;
scene.add(boardBase);
// Instanced voxel floor.
const tileGeometry = new THREE.BoxGeometry(0.92, 0.12, 0.92);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0.03,
vertexColors: true
});
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, 21 * 17);
const tileDummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let x = -10; x <= 10; x++) {
for (let z = -8; z <= 8; z++) {
tileDummy.position.set(x, 0, z);
tileDummy.updateMatrix();
tiles.setMatrixAt(tileIndex, tileDummy.matrix);
const light = 0.115 + ((x + z + 40) % 4) * 0.009;
tileColor.setHSL(0.575, 0.27, light);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
const borderMaterial = new THREE.MeshStandardMaterial({
color: 0x203b50,
roughness: 0.55,
metalness: 0.35
});
function addBorderBox(w, h, d, x, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
borderMaterial
);
mesh.position.set(x, 0.03, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
addBorderBox(0.22, 0.26, 17.4, -10.65, 0);
addBorderBox(0.22, 0.26, 17.4, 10.65, 0);
addBorderBox(21.5, 0.26, 0.22, 0, -8.65);
addBorderBox(21.5, 0.26, 0.22, 0, 8.65);
// -------------------------------------------------------------------------
// Mirrors
// -------------------------------------------------------------------------
const mirrors = [];
const mirrorPickMeshes = [];
function createMirror(id, x, z, initialAngleIndex) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const base = new THREE.Mesh(
new THREE.BoxGeometry(0.92, 0.5, 0.92),
new THREE.MeshStandardMaterial({
color: 0x203447,
roughness: 0.65,
metalness: 0.4
})
);
base.position.y = 0.25;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0x67d8ee,
emissive: 0x0b465a,
emissiveIntensity: 0.65,
roughness: 0.16,
metalness: 0.78
});
const panel = new THREE.Mesh(
new THREE.BoxGeometry(MIRROR_LENGTH, 1.5, 0.15),
panelMaterial
);
panel.position.y = 1.16;
panel.castShadow = true;
panel.receiveShadow = true;
panel.userData.mirrorId = id;
group.add(panel);
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xc8f5ff,
emissive: 0x1e7284,
emissiveIntensity: 0.45,
roughness: 0.3,
metalness: 0.5
});
for (const side of [-1, 1]) {
const cap = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 1.58, 0.2),
capMaterial
);
cap.position.x = side * (MIRROR_LENGTH * 0.5 - 0.04);
cap.position.y = 1.16;
group.add(cap);
}
const ring = new THREE.Group();
ring.position.y = 0.13;
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xffc45f,
transparent: true,
opacity: 0.9
});
const horizontalRing = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.035, 0.07),
ringMaterial
);
const verticalRing = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 0.035, 1.25),
ringMaterial
);
horizontalRing.position.z = 0.63;
verticalRing.position.z = -0.63;
ring.add(horizontalRing, verticalRing);
const verticalRing2 = horizontalRing.clone();
verticalRing2.position.z = -0.63;
const horizontalRing2 = verticalRing.clone();
horizontalRing2.position.z = 0.63;
ring.add(verticalRing2, horizontalRing2);
group.add(ring);
const mirror = {
id,
group,
panel,
panelMaterial,
ring,
position: new THREE.Vector2(x, z),
angleIndex: initialAngleIndex
};
mirrors.push(mirror);
mirrorPickMeshes.push(panel);
return mirror;
}
createMirror(0, -3, -5, 0);
createMirror(1, -3, 0, 2);
let selectedMirror = 0;
let beamDirty = true;
function mirrorAngle(mirror) {
return mirror.angleIndex * Math.PI / 4;
}
function updateMirrorTransform(mirror) {
mirror.group.rotation.y = -mirrorAngle(mirror);
}
mirrors.forEach(updateMirrorTransform);
// -------------------------------------------------------------------------
// Emitter
// -------------------------------------------------------------------------
const emitter = new THREE.Group();
emitter.position.set(-9, 0, -5);
scene.add(emitter);
const emitterDark = new THREE.MeshStandardMaterial({
color: 0x1d3346,
roughness: 0.58,
metalness: 0.48
});
const emitterBase = new THREE.Mesh(
new THREE.BoxGeometry(1.7, 0.5, 1.7),
emitterDark
);
emitterBase.position.y = 0.25;
emitterBase.castShadow = true;
emitterBase.receiveShadow = true;
emitter.add(emitterBase);
const emitterBody = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 1.05, 1.25),
emitterDark
);
emitterBody.position.y = 0.88;
emitterBody.castShadow = true;
emitter.add(emitterBody);
const emitterTop = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.32, 0.72),
new THREE.MeshStandardMaterial({
color: 0x2b536b,
roughness: 0.45,
metalness: 0.55
})
);
emitterTop.position.y = 1.55;
emitterTop.castShadow = true;
emitter.add(emitterTop);
const emitterLensMaterial = new THREE.MeshStandardMaterial({
color: 0x83f4ff,
emissive: 0x23dfff,
emissiveIntensity: 4.2,
roughness: 0.15,
metalness: 0.25
});
const emitterLens = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.58, 0.58),
emitterLensMaterial
);
emitterLens.position.set(0.76, BEAM_Y, 0);
emitterLens.castShadow = true;
emitter.add(emitterLens);
const emitterLight = new THREE.PointLight(0x42e7ff, 13, 5.5, 2);
emitterLight.position.set(0.8, 1.2, 0);
emitter.add(emitterLight);
const emitterOrigin = new THREE.Vector2(-8.14, -5);
// -------------------------------------------------------------------------
// Visible receiver rail
// -------------------------------------------------------------------------
const railGroup = new THREE.Group();
scene.add(railGroup);
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x8d6731,
emissive: 0x5b3309,
emissiveIntensity: 0.45,
roughness: 0.48,
metalness: 0.55
});
const tieMaterial = new THREE.MeshStandardMaterial({
color: 0x354455,
roughness: 0.75,
metalness: 0.25
});
for (const x of [2.72, 3.28]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.15, 9.55),
railMaterial
);
rail.position.set(x, 0.18, 0);
rail.castShadow = true;
rail.receiveShadow = true;
railGroup.add(rail);
}
for (let z = -4.5; z <= 4.5; z += 0.75) {
const tie = new THREE.Mesh(
new THREE.BoxGeometry(1.18, 0.11, 0.16),
tieMaterial
);
tie.position.set(3, 0.1, z);
tie.castShadow = true;
tie.receiveShadow = true;
railGroup.add(tie);
}
// Gate markers show the rail's center position.
const gateMaterial = new THREE.MeshBasicMaterial({
color: 0xffc45f,
transparent: true,
opacity: 0.62
});
for (const x of [2.54, 3.46]) {
for (const z of [-0.44, 0.44]) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.045, 0.32),
gateMaterial
);
marker.position.set(x, 0.18, z);
railGroup.add(marker);
}
}
// -------------------------------------------------------------------------
// Moving receiver
// -------------------------------------------------------------------------
const receiver = new THREE.Group();
receiver.position.set(3, 0, -3.05);
scene.add(receiver);
const receiverMaterial = new THREE.MeshStandardMaterial({
color: 0x76552f,
roughness: 0.55,
metalness: 0.45
});
const carriage = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.28, 1.05),
receiverMaterial
);
carriage.position.y = 0.34;
carriage.castShadow = true;
carriage.receiveShadow = true;
receiver.add(carriage);
const receiverBody = new THREE.Mesh(
new THREE.BoxGeometry(0.82, 1.0, 0.85),
receiverMaterial
);
receiverBody.position.set(0.46, 0.9, 0);
receiverBody.castShadow = true;
receiverBody.receiveShadow = true;
receiver.add(receiverBody);
const receiverTop = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.18, 0.58),
new THREE.MeshStandardMaterial({
color: 0xa2783d,
roughness: 0.4,
metalness: 0.55
})
);
receiverTop.position.set(0.46, 1.48, 0);
receiverTop.castShadow = true;
receiver.add(receiverTop);
const receiverLensMaterial = new THREE.MeshStandardMaterial({
color: 0xffcf72,
emissive: 0xff9f22,
emissiveIntensity: 3.2,
roughness: 0.2,
metalness: 0.3
});
const receiverLens = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.6, 0.6),
receiverLensMaterial
);
receiverLens.position.set(0, BEAM_Y, 0);
receiverLens.castShadow = true;
receiver.add(receiverLens);
const receiverLight = new THREE.PointLight(0xffae36, 9, 4.5, 2);
receiverLight.position.set(-0.1, 1.35, 0);
receiver.add(receiverLight);
// -------------------------------------------------------------------------
// Voxel beam rendering
// -------------------------------------------------------------------------
const BEAM_CAPACITY = 1400;
const beamOuter = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.19, 0.19, 0.19),
new THREE.MeshBasicMaterial({
color: 0x38dcff,
transparent: true,
opacity: 0.2,
depthWrite: false
}),
BEAM_CAPACITY
);
const beamInner = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.095, 0.095, 0.095),
new THREE.MeshBasicMaterial({
color: 0xa8f7ff,
transparent: true,
opacity: 0.98,
depthWrite: false
}),
BEAM_CAPACITY
);
beamOuter.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
beamInner.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
beamOuter.frustumCulled = false;
beamInner.frustumCulled = false;
beamOuter.renderOrder = 2;
beamInner.renderOrder = 3;
scene.add(beamOuter, beamInner);
const beamDummy = new THREE.Object3D();
// -------------------------------------------------------------------------
// Physical 2D ray / mirror intersection and reflection
// -------------------------------------------------------------------------
const EPSILON = 1e-6;
function cross2(ax, ay, bx, by) {
return ax * by - ay * bx;
}
function raySegmentIntersection(origin, direction, a, b) {
const segmentX = b.x - a.x;
const segmentY = b.y - a.y;
const denominator = cross2(
direction.x,
direction.y,
segmentX,
segmentY
);
if (Math.abs(denominator) < EPSILON) {
return null;
}
const offsetX = a.x - origin.x;
const offsetY = a.y - origin.y;
const rayDistance = cross2(
offsetX,
offsetY,
segmentX,
segmentY
) / denominator;
const segmentDistance = cross2(
offsetX,
offsetY,
direction.x,
direction.y
) / denominator;
if (
rayDistance > 0.0001 &&
segmentDistance >= -0.00001 &&
segmentDistance <= 1.00001
) {
return { distance: rayDistance, segmentDistance };
}
return null;
}
function mirrorEndpoints(mirror) {
const angle = mirrorAngle(mirror);
const tangent = new THREE.Vector2(
Math.cos(angle),
Math.sin(angle)
);
const halfLength = MIRROR_LENGTH * 0.5;
return {
a: mirror.position.clone()
.addScaledVector(tangent, -halfLength),
b: mirror.position.clone()
.addScaledVector(tangent, halfLength),
tangent
};
}
function distanceToBoardExit(origin, direction) {
let distance = Infinity;
if (Math.abs(direction.x) > EPSILON) {
const edge = direction.x > 0 ? BOARD_MAX_X : BOARD_MIN_X;
const t = (edge - origin.x) / direction.x;
if (t > 0) distance = Math.min(distance, t);
}
if (Math.abs(direction.y) > EPSILON) {
const edge = direction.y > 0 ? BOARD_MAX_Z : BOARD_MIN_Z;
const t = (edge - origin.y) / direction.y;
if (t > 0) distance = Math.min(distance, t);
}
return Number.isFinite(distance) ? distance : 4;
}
function reflectDirection(direction, tangent) {
const dot = direction.dot(tangent);
return tangent.clone()
.multiplyScalar(2 * dot)
.sub(direction)
.normalize();
}
function traceBeam() {
const segments = [];
let origin = emitterOrigin.clone();
let direction = new THREE.Vector2(1, 0);
let lastMirror = -1;
for (let bounce = 0; bounce < 8; bounce++) {
let closest = null;
for (const mirror of mirrors) {
if (mirror.id === lastMirror) continue;
const { a, b } = mirrorEndpoints(mirror);
const intersection = raySegmentIntersection(
origin,
direction,
a,
b
);
if (
intersection &&
(!closest || intersection.distance < closest.intersection.distance)
) {
closest = { mirror, intersection };
}
}
if (!closest) {
const distance = distanceToBoardExit(origin, direction);
const end = origin.clone().addScaledVector(direction, distance);
segments.push({
a: new THREE.Vector3(origin.x, BEAM_Y, origin.y),
b: new THREE.Vector3(end.x, BEAM_Y, end.y)
});
break;
}
const hitPoint = origin.clone().addScaledVector(
direction,
closest.intersection.distance
);
segments.push({
a: new THREE.Vector3(origin.x, BEAM_Y, origin.y),
b: new THREE.Vector3(hitPoint.x, BEAM_Y, hitPoint.y)
});
const { tangent } = mirrorEndpoints(closest.mirror);
direction = reflectDirection(direction, tangent);
origin = hitPoint;
lastMirror = closest.mirror.id;
}
return segments;
}
let beamSegments = [];
function rebuildBeam() {
beamSegments = traceBeam();
let count = 0;
for (const segment of beamSegments) {
const length = segment.a.distanceTo(segment.b);
const steps = Math.max(1, Math.ceil(length / 0.16));
for (let i = 0; i <= steps && count < BEAM_CAPACITY; i++) {
const t = i / steps;
const position = segment.a.clone().lerp(segment.b, t);
beamDummy.position.copy(position);
beamDummy.rotation.set(0, 0, 0);
beamDummy.scale.set(1, 1, 1);
beamDummy.updateMatrix();
beamOuter.setMatrixAt(count, beamDummy.matrix);
beamInner.setMatrixAt(count, beamDummy.matrix);
count++;
}
}
beamOuter.count = count;
beamInner.count = count;
beamOuter.instanceMatrix.needsUpdate = true;
beamInner.instanceMatrix.needsUpdate = true;
}
// Exact segment-vs-box test against the receiver lens volume.
function segmentIntersectsBox(p0, p1, min, max) {
let tMin = 0;
let tMax = 1;
for (const axis of ["x", "y", "z"]) {
const delta = p1[axis] - p0[axis];
if (Math.abs(delta) < EPSILON) {
if (p0[axis] < min[axis] || p0[axis] > max[axis]) {
return false;
}
continue;
}
let t1 = (min[axis] - p0[axis]) / delta;
let t2 = (max[axis] - p0[axis]) / delta;
if (t1 > t2) {
const swap = t1;
t1 = t2;
t2 = swap;
}
tMin = Math.max(tMin, t1);
tMax = Math.min(tMax, t2);
if (tMin > tMax) return false;
}
return true;
}
const receiverMin = new THREE.Vector3();
const receiverMax = new THREE.Vector3();
function beamIntersectsReceiver() {
receiverMin.set(
3 - 0.24,
BEAM_Y - 0.3,
receiver.position.z - 0.3
);
receiverMax.set(
3 + 0.24,
BEAM_Y + 0.3,
receiver.position.z + 0.3
);
for (const segment of beamSegments) {
if (segmentIntersectsBox(
segment.a,
segment.b,
receiverMin,
receiverMax
)) {
return true;
}
}
return false;
}
// -------------------------------------------------------------------------
// UI and puzzle state
// -------------------------------------------------------------------------
const statusPill = document.getElementById("statusPill");
const pauseBtn = document.getElementById("pauseBtn");
const resetBtn = document.getElementById("resetBtn");
const cameraBtn = document.getElementById("cameraBtn");
const rotateLeft = document.getElementById("rotateLeft");
const rotateRight = document.getElementById("rotateRight");
const mirrorList = document.getElementById("mirrorList");
const selectedName = document.getElementById("selectedName");
const selectedAngle = document.getElementById("selectedAngle");
const signalDot = document.getElementById("signalDot");
const signalText = document.getElementById("signalText");
const signalDetail = document.getElementById("signalDetail");
const captureFill = document.getElementById("captureFill");
const receiverCoord = document.getElementById("receiverCoord");
const receiverSpeed = document.getElementById("receiverSpeed");
const hintBtn = document.getElementById("hintBtn");
const hintText = document.getElementById("hintText");
const successToast = document.getElementById("successToast");
const successReset = document.getElementById("successReset");
const solvePathBtn = document.getElementById("solvePathBtn");
let receiverPaused = false;
let receiverClock = 0;
let receiverZ = -3.05;
let captureProgress = 0;
let completed = false;
let actualHit = false;
const hints = [
"Pause the carrier if you need time to plan.",
"M-01 is the first turn: its face must send the eastbound beam north.",
"M-02 is the second turn: its face must send the northbound beam east.",
"Both mirror faces settle at 45°. Resume the receiver and wait for the lens overlap."
];
let hintIndex = 0;
function updateMirrorUI() {
document.querySelectorAll(".mirror-card").forEach((card) => {
const id = Number(card.dataset.mirror);
const mirror = mirrors[id];
const selected = id === selectedMirror;
card.classList.toggle("selected", selected);
card.querySelector(".angle-box").textContent = `${mirror.angleIndex * 45}°`;
});
const mirror = mirrors[selectedMirror];
selectedName.textContent = `M-0${selectedMirror + 1} selected`;
selectedAngle.textContent = `${mirror.angleIndex * 45}°`;
}
function selectMirror(id) {
selectedMirror = id;
updateMirrorUI();
}
function rotateMirror(id, delta) {
const mirror = mirrors[id];
mirror.angleIndex = (mirror.angleIndex + delta + 4) % 4;
updateMirrorTransform(mirror);
selectedMirror = id;
beamDirty = true;
updateMirrorUI();
}
function rotateSelected(delta) {
rotateMirror(selectedMirror, delta);
}
function updateMirrorMaterials() {
mirrors.forEach((mirror) => {
const selected = mirror.id === selectedMirror;
mirror.panelMaterial.color.setHex(selected ? 0xffcb70 : 0x67d8ee);
mirror.panelMaterial.emissive.setHex(selected ? 0x7d4c08 : 0x0b465a);
mirror.panelMaterial.emissiveIntensity = selected ? 0.9 : 0.65;
mirror.ring.visible = selected;
});
}
function togglePause() {
receiverPaused = !receiverPaused;
pauseBtn.textContent = receiverPaused
? "Resume receiver"
: "Pause receiver";
statusPill.textContent = receiverPaused
? "RECEIVER PAUSED"
: "RECEIVER LIVE";
statusPill.classList.toggle("paused", receiverPaused);
}
function resetPuzzle() {
mirrors[0].angleIndex = 0;
mirrors[1].angleIndex = 2;
mirrors.forEach((mirror) => {
updateMirrorTransform(mirror);
});
selectedMirror = 0;
receiverClock = 0;
receiverZ = -3.05;
captureProgress = 0;
completed = false;
receiverPaused = false;
beamDirty = true;
pauseBtn.textContent = "Pause receiver";
statusPill.textContent = "RECEIVER LIVE";
statusPill.classList.remove("paused");
successToast.classList.remove("show");
updateMirrorUI();
updateMirrorMaterials();
}
mirrorList.addEventListener("click", (event) => {
const rotateButton = event.target.closest("button[data-delta]");
if (rotateButton) {
const card = rotateButton.closest(".mirror-card");
rotateMirror(
Number(card.dataset.mirror),
Number(rotateButton.dataset.delta)
);
return;
}
const card = event.target.closest(".mirror-card");
if (card) selectMirror(Number(card.dataset.mirror));
});
mirrorList.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
const card = event.target.closest(".mirror-card");
if (!card) return;
event.preventDefault();
selectMirror(Number(card.dataset.mirror));
});
rotateLeft.addEventListener("click", () => rotateSelected(-1));
rotateRight.addEventListener("click", () => rotateSelected(1));
pauseBtn.addEventListener("click", togglePause);
resetBtn.addEventListener("click", resetPuzzle);
successReset.addEventListener("click", resetPuzzle);
hintBtn.addEventListener("click", () => {
hintText.textContent = hints[hintIndex];
hintIndex = (hintIndex + 1) % hints.length;
});
solvePathBtn.addEventListener("click", () => {
beamDirty = true;
hintText.textContent =
"Optical trace refreshed. Both mirrors use 45° to form an east–north–east route.";
});
cameraBtn.addEventListener("click", () => {
cameraState.yaw = 0.62;
cameraState.pitch = 0.76;
cameraState.distance = 25;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.repeat) return;
if (event.code === "Space") {
event.preventDefault();
togglePause();
} else if (event.key.toLowerCase() === "q") {
rotateSelected(-1);
} else if (event.key.toLowerCase() === "e") {
rotateSelected(1);
} else if (event.key === "1") {
selectMirror(0);
} else if (event.key === "2") {
selectMirror(1);
} else if (event.key.toLowerCase() === "r") {
resetPuzzle();
}
});
// -------------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// -------------------------------------------------------------------------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const canvas = renderer.domElement;
let dragging = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.34,
1.28
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (!pointerMoved) {
const rect = canvas.getBoundingClientRect();
pointer.x = (
(event.clientX - rect.left) / rect.width
) * 2 - 1;
pointer.y = -(
(event.clientY - rect.top) / rect.height
) * 2 + 1;
scene.updateMatrixWorld(true);
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(
mirrorPickMeshes,
false
)[0];
if (hit) {
selectMirror(hit.object.userData.mirrorId);
}
}
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.012,
17,
38
);
updateCamera();
}, { passive: false });
// -------------------------------------------------------------------------
// World-space HTML labels
// -------------------------------------------------------------------------
const tags = [
{
element: document.getElementById("sourceTag"),
position: new THREE.Vector3(-9, 2.25, -5)
},
{
element: document.getElementById("m1Tag"),
position: new THREE.Vector3(-3, 2.55, -5)
},
{
element: document.getElementById("m2Tag"),
position: new THREE.Vector3(-3, 2.55, 0)
},
{
element: document.getElementById("receiverTag"),
position: new THREE.Vector3(3, 2.35, receiverZ)
}
];
const projected = new THREE.Vector3();
function updateTags() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const tag of tags) {
projected.copy(tag.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
tag.element.style.display = visible ? "block" : "none";
if (!visible) continue;
tag.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
tag.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Animation and live intersection validation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateSignalUI() {
if (completed) {
signalDot.className = "signal-dot hit";
signalText.textContent = "SIGNAL CAPTURED";
signalDetail.textContent =
"The moving receiver intersected the live reflected beam.";
captureFill.style.width = "100%";
return;
}
if (actualHit && receiverPaused) {
signalDot.className = "signal-dot paused-hit";
signalText.textContent = "ALIGNMENT FOUND";
signalDetail.textContent =
"The paused lens overlaps the beam. Resume the receiver to capture.";
} else if (actualHit) {
signalDot.className = "signal-dot hit";
signalText.textContent = "BEAM ON TARGET";
signalDetail.textContent =
"Real segment/lens intersection detected. Holding signal lock…";
} else {
signalDot.className = "signal-dot";
signalText.textContent = "SEARCHING";
signalDetail.textContent =
"The beam does not currently intersect the receiver lens.";
}
captureFill.style.width =
`${Math.min(100, (captureProgress / 0.18) * 100)}%`;
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!receiverPaused) {
receiverClock += dt;
}
const receiverAmplitude = 3.8;
const receiverFrequency = 0.48;
const receiverPhase = receiverClock * receiverFrequency - 1.1;
receiverZ = receiverAmplitude * Math.sin(receiverPhase);
const velocity =
receiverAmplitude * receiverFrequency * Math.cos(receiverPhase);
receiver.position.z = receiverZ;
tags[3].position.z = receiverZ + 2.35;
if (beamDirty) {
rebuildBeam();
beamDirty = false;
}
actualHit = beamIntersectsReceiver();
if (!completed) {
if (actualHit && !receiverPaused) {
captureProgress += dt;
if (captureProgress >= 0.18) {
completed = true;
captureProgress = 0.18;
successToast.classList.add("show");
}
} else {
captureProgress = Math.max(
0,
captureProgress - dt * 1.8
);
}
}
const pulse = actualHit
? 1.08 + Math.sin(performance.now() * 0.018) * 0.07
: 1;
receiverLens.scale.setScalar(pulse);
receiverLensMaterial.emissiveIntensity = actualHit ? 5.4 : 3.2;
receiverLight.intensity = actualHit ? 15 : 9;
receiverCoord.textContent =
`Z ${receiverZ >= 0 ? "+" : ""}${receiverZ.toFixed(2)}`;
receiverSpeed.textContent =
`${Math.abs(velocity).toFixed(2)} u/s`;
updateMirrorMaterials();
updateSignalUI();
updateTags();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
updateMirrorUI();
updateMirrorMaterials();
rebuildBeam();
beamDirty = false;
animate();
</script>
</body>
</html>
```