Prompt specification
Build or customize the Three.js 3D scene "Original Gravity Observatory 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: Original Gravity Observatory Puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/original-gravity-observatory-puzzle-x3455
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build a fictional observatory room with three chambers and orientation-dependent doors. Preserve each chamber's stated gravity rule and make transitions visible before the player enters.
Acceptance checks: Use ordinary drag-to-look and keyboard controls that are usable in a sandbox without pointer lock or native forms. Include direct chamber selection or clear progression and a deterministic visible preview of each gravity transition before entry. Verify every chamber transition through the actual controls.
Return a single complete HTML document. It must work in a sandbox that allows scripts, with the cdnjs Three.js r160 module and inline CSS. Use procedural geometry and local button handlers; no native form submission, pointer lock, remote assets, or runtime network requests besides Three.js.
Working Three.js Starter (original-gravity-observatory-puzzle-x3455):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#050914">
<title>PARALLAX OBSERVATORY — Gravity Chambers</title>
<style>
:root {
--bg: #050914;
--panel: rgba(7, 14, 27, 0.88);
--panel-strong: rgba(8, 17, 32, 0.96);
--line: rgba(129, 218, 255, 0.24);
--line-strong: rgba(129, 218, 255, 0.62);
--text: #e8f7ff;
--muted: #83a0b7;
--cyan: #62e9ff;
--blue: #4e91ff;
--magenta: #e86cff;
--amber: #ffbd58;
--green: #6dffb1;
--danger: #ff6f91;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
body {
user-select: none;
-webkit-user-select: none;
}
button {
font: inherit;
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
#stage {
position: fixed;
inset: 0;
background:
radial-gradient(circle at 50% 42%, #101d31 0, #050914 60%, #02040a 100%);
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#stage canvas.dragging {
cursor: grabbing;
}
.vignette,
.scanlines {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 3;
}
.vignette {
background:
radial-gradient(circle at center, transparent 48%, rgba(0, 0, 0, 0.3) 78%, rgba(0, 0, 0, 0.72) 100%);
mix-blend-mode: multiply;
}
.scanlines {
opacity: 0.16;
background: repeating-linear-gradient(
to bottom,
rgba(255, 255, 255, 0.035) 0,
rgba(255, 255, 255, 0.035) 1px,
transparent 1px,
transparent 4px
);
}
.hud-panel {
position: fixed;
z-index: 10;
background:
linear-gradient(135deg, rgba(18, 34, 56, 0.52), transparent 42%),
var(--panel);
border: 1px solid var(--line);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.36),
inset 0 0 28px rgba(76, 170, 255, 0.035);
backdrop-filter: blur(13px);
-webkit-backdrop-filter: blur(13px);
}
.hud-panel::before {
content: "";
position: absolute;
top: -1px;
left: 18px;
width: 58px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
#brand {
position: fixed;
z-index: 12;
top: 18px;
left: 20px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: none;
text-shadow: 0 2px 18px #000;
}
.brand-mark {
width: 38px;
height: 38px;
border: 1px solid var(--line-strong);
display: grid;
place-items: center;
color: var(--cyan);
font-size: 20px;
transform: rotate(45deg);
background: rgba(5, 12, 24, 0.72);
box-shadow: 0 0 24px rgba(98, 233, 255, 0.12);
}
.brand-mark span {
transform: rotate(-45deg);
}
#brand strong {
display: block;
font-size: 13px;
letter-spacing: 0.23em;
line-height: 1.4;
}
#brand small {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.18em;
margin-top: 3px;
}
#consolePanel {
top: 82px;
left: 18px;
width: 292px;
max-height: calc(100vh - 164px);
padding: 16px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(98, 233, 255, 0.28) transparent;
}
.eyebrow {
color: var(--cyan);
font-size: 9px;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.panel-title {
margin: 5px 0 4px;
font-size: 18px;
letter-spacing: 0.04em;
font-weight: 700;
}
.panel-copy {
color: var(--muted);
font-size: 10px;
line-height: 1.6;
margin-bottom: 14px;
}
.chamber-list {
display: grid;
gap: 8px;
}
.chamber-card {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 38px 1fr 24px;
gap: 10px;
align-items: center;
padding: 12px 10px;
border: 1px solid rgba(129, 218, 255, 0.18);
background: rgba(5, 13, 26, 0.76);
color: var(--text);
text-align: left;
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.chamber-card:hover:not(:disabled) {
transform: translateX(3px);
border-color: rgba(98, 233, 255, 0.58);
background: rgba(16, 36, 56, 0.9);
}
.chamber-card.selected {
border-color: var(--card-color, var(--cyan));
background: linear-gradient(90deg, color-mix(in srgb, var(--card-color, var(--cyan)) 16%, transparent), rgba(5, 13, 26, 0.88));
box-shadow: inset 3px 0 0 var(--card-color, var(--cyan));
}
.chamber-card:disabled {
opacity: 0.42;
cursor: not-allowed;
}
.card-index {
color: var(--card-color, var(--cyan));
font-size: 18px;
font-weight: 800;
}
.card-name {
display: block;
font-size: 11px;
letter-spacing: 0.08em;
font-weight: 700;
}
.card-rule {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.card-arrow {
color: var(--card-color, var(--cyan));
font-size: 18px;
text-align: right;
}
.rule-manifest {
margin-top: 13px;
padding: 10px;
border: 1px solid rgba(129, 218, 255, 0.12);
background: rgba(0, 0, 0, 0.22);
color: var(--muted);
font-size: 9px;
line-height: 1.7;
}
.rule-manifest b {
color: var(--text);
font-weight: 500;
}
.route-ledger {
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid rgba(129, 218, 255, 0.14);
}
.ledger-head {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.12em;
margin-bottom: 8px;
}
#controlCount {
color: var(--green);
}
.route-row {
display: grid;
grid-template-columns: 24px 1fr auto;
gap: 8px;
align-items: center;
padding: 6px 0;
font-size: 9px;
color: var(--muted);
border-bottom: 1px dotted rgba(129, 218, 255, 0.09);
}
.route-row b {
color: var(--cyan);
font-size: 8px;
letter-spacing: 0.08em;
font-weight: 600;
}
.route-row b[data-state="entered"] {
color: var(--green);
}
#returnButton {
width: 100%;
margin-top: 12px;
padding: 10px 12px;
border: 1px solid rgba(255, 111, 145, 0.48);
background: rgba(255, 111, 145, 0.08);
color: #ffd5df;
letter-spacing: 0.12em;
font-size: 10px;
cursor: pointer;
}
#returnButton:hover {
background: rgba(255, 111, 145, 0.16);
}
#telemetryPanel {
top: 18px;
right: 18px;
width: 300px;
padding: 15px 16px;
pointer-events: none;
}
.room-line {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin: 8px 0 12px;
}
#roomName {
font-size: 16px;
letter-spacing: 0.08em;
font-weight: 700;
}
#roomNumber {
color: var(--muted);
font-size: 9px;
}
.gravity-box {
display: grid;
grid-template-columns: 42px 1fr;
align-items: center;
gap: 10px;
padding: 10px;
background: rgba(0, 0, 0, 0.24);
border: 1px solid rgba(129, 218, 255, 0.14);
}
#gravityGlyph {
display: grid;
place-items: center;
width: 40px;
height: 40px;
border: 1px solid var(--room-color, var(--cyan));
color: var(--room-color, var(--cyan));
font-size: 24px;
box-shadow: inset 0 0 18px color-mix(in srgb, var(--room-color, var(--cyan)) 12%, transparent);
}
.gravity-box small {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.14em;
margin-bottom: 4px;
}
#gravityRule {
display: block;
font-size: 10px;
letter-spacing: 0.04em;
}
.telemetry-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.telemetry-cell {
border-left: 2px solid rgba(98, 233, 255, 0.32);
padding-left: 8px;
}
.telemetry-cell span {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.11em;
margin-bottom: 4px;
}
.telemetry-cell b {
font-size: 9px;
font-weight: 500;
}
#previewPanel {
top: 220px;
right: 18px;
width: 362px;
max-height: calc(100vh - 292px);
padding: 16px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(98, 233, 255, 0.28) transparent;
}
#previewPanel::before {
background: var(--preview-color, var(--cyan));
box-shadow: 0 0 14px var(--preview-color, var(--cyan));
}
.close-button {
position: absolute;
top: 9px;
right: 9px;
width: 28px;
height: 28px;
border: 1px solid rgba(129, 218, 255, 0.22);
background: rgba(0, 0, 0, 0.22);
color: var(--muted);
cursor: pointer;
line-height: 1;
}
.close-button:hover {
color: var(--text);
border-color: var(--line-strong);
}
.preview-heading {
padding-right: 28px;
}
#previewName {
color: var(--preview-color, var(--cyan));
margin: 5px 0 4px;
font-size: 19px;
letter-spacing: 0.05em;
}
#previewSubtitle {
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.preview-visual {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 14px 0;
}
.diagram {
position: relative;
height: 160px;
border: 1px solid rgba(129, 218, 255, 0.17);
background:
linear-gradient(rgba(129, 218, 255, 0.045) 1px, transparent 1px),
linear-gradient(90deg, rgba(129, 218, 255, 0.045) 1px, transparent 1px),
rgba(0, 0, 0, 0.26);
background-size: 20px 20px;
overflow: hidden;
}
.diagram-label {
position: absolute;
left: 8px;
top: 7px;
z-index: 3;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.12em;
}
.axis-x,
.axis-y {
position: absolute;
background: rgba(129, 218, 255, 0.14);
}
.axis-x {
left: 8%;
right: 8%;
top: 50%;
height: 1px;
}
.axis-y {
top: 8%;
bottom: 8%;
left: 50%;
width: 1px;
}
#vectorNeedle {
position: absolute;
z-index: 2;
left: calc(50% - 4px);
bottom: 50%;
width: 8px;
height: 58px;
border-radius: 3px;
background: var(--preview-color, var(--cyan));
box-shadow: 0 0 13px color-mix(in srgb, var(--preview-color, var(--cyan)) 55%, transparent);
transform-origin: 50% 100%;
}
#vectorNeedle::before {
content: "";
position: absolute;
left: -7px;
top: -12px;
width: 0;
height: 0;
border-left: 11px solid transparent;
border-right: 11px solid transparent;
border-bottom: 15px solid var(--preview-color, var(--cyan));
}
#vectorNeedle::after {
content: "G";
position: absolute;
left: -12px;
bottom: -18px;
color: var(--preview-color, var(--cyan));
font-size: 9px;
font-weight: 700;
}
#miniDoor {
position: absolute;
left: 50%;
top: 50%;
width: 84px;
height: 112px;
transform: translate(-50%, -45%);
border: 5px solid rgba(129, 218, 255, 0.38);
box-shadow: 0 0 22px rgba(98, 233, 255, 0.07);
}
#miniDoor::before,
#miniDoor::after {
content: "";
position: absolute;
background: rgba(129, 218, 255, 0.22);
}
#miniDoor::before {
left: 50%;
top: 0;
bottom: 0;
width: 1px;
}
#miniDoor::after {
top: 50%;
left: 0;
right: 0;
height: 1px;
}
#miniKeel {
position: absolute;
z-index: 2;
left: calc(50% - 3px);
top: calc(50% - 41px);
width: 6px;
height: 82px;
background: var(--preview-color, var(--cyan));
box-shadow: 0 0 12px color-mix(in srgb, var(--preview-color, var(--cyan)) 50%, transparent);
transform-origin: 50% 50%;
}
#miniKeel::before {
content: "UP";
position: absolute;
top: -17px;
left: -9px;
color: var(--preview-color, var(--cyan));
font-size: 7px;
font-weight: 700;
}
#miniKeel::after {
content: "";
position: absolute;
left: -6px;
bottom: -7px;
width: 18px;
height: 3px;
background: var(--preview-color, var(--cyan));
}
.vector-readout {
position: absolute;
left: 7px;
right: 7px;
bottom: 7px;
color: var(--muted);
font-size: 8px;
text-align: center;
letter-spacing: 0.06em;
}
.preview-metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 11px;
}
.metric {
min-height: 55px;
padding: 8px;
border: 1px solid rgba(129, 218, 255, 0.13);
background: rgba(0, 0, 0, 0.22);
}
.metric span {
display: block;
color: var(--muted);
font-size: 7px;
letter-spacing: 0.09em;
margin-bottom: 6px;
}
.metric b {
color: var(--preview-color, var(--cyan));
font-size: 10px;
font-weight: 600;
line-height: 1.3;
}
.preview-steps {
display: grid;
gap: 6px;
margin: 10px 0 13px;
}
.preview-step {
display: grid;
grid-template-columns: 22px 1fr;
gap: 8px;
align-items: center;
color: var(--muted);
font-size: 9px;
}
.preview-step i {
display: grid;
place-items: center;
width: 20px;
height: 20px;
border: 1px solid rgba(129, 218, 255, 0.2);
color: var(--preview-color, var(--cyan));
font-style: normal;
font-size: 8px;
}
#previewStatement {
min-height: 43px;
margin: 0 0 12px;
padding: 9px 10px;
border-left: 2px solid var(--preview-color, var(--cyan));
background: color-mix(in srgb, var(--preview-color, var(--cyan)) 7%, transparent);
color: #c6dbea;
font-size: 9px;
line-height: 1.55;
}
.preview-actions {
display: grid;
grid-template-columns: 1fr 1.35fr;
gap: 8px;
}
.ui-button {
padding: 10px 9px;
border: 1px solid rgba(129, 218, 255, 0.32);
background: rgba(8, 21, 38, 0.9);
color: var(--text);
font-size: 9px;
letter-spacing: 0.08em;
cursor: pointer;
}
.ui-button:hover {
border-color: var(--line-strong);
background: rgba(20, 42, 65, 0.95);
}
.ui-button.primary {
border-color: var(--preview-color, var(--cyan));
background: color-mix(in srgb, var(--preview-color, var(--cyan)) 14%, rgba(8, 21, 38, 0.95));
color: #fff;
box-shadow: inset 0 0 18px color-mix(in srgb, var(--preview-color, var(--cyan)) 7%, transparent);
}
.ui-button.primary:hover {
background: color-mix(in srgb, var(--preview-color, var(--cyan)) 23%, rgba(8, 21, 38, 0.95));
}
#reticle {
position: fixed;
z-index: 8;
left: 50%;
top: 50%;
width: 18px;
height: 18px;
transform: translate(-50%, -50%);
pointer-events: none;
opacity: 0.72;
}
#reticle::before,
#reticle::after {
content: "";
position: absolute;
background: rgba(218, 247, 255, 0.82);
box-shadow: 0 0 5px rgba(98, 233, 255, 0.6);
}
#reticle::before {
left: 8px;
top: 2px;
width: 1px;
height: 14px;
}
#reticle::after {
left: 2px;
top: 8px;
width: 14px;
height: 1px;
}
#contextPrompt {
position: fixed;
z-index: 9;
left: 50%;
bottom: 92px;
transform: translateX(-50%);
max-width: min(620px, 88vw);
padding: 9px 13px;
border: 1px solid rgba(129, 218, 255, 0.2);
background: rgba(4, 10, 20, 0.78);
color: #c6dbea;
font-size: 9px;
letter-spacing: 0.08em;
text-align: center;
pointer-events: none;
}
#helpBar {
position: fixed;
z-index: 9;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
display: flex;
gap: 16px;
align-items: center;
padding: 9px 14px;
border: 1px solid rgba(129, 218, 255, 0.14);
background: rgba(3, 8, 17, 0.72);
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
pointer-events: none;
white-space: nowrap;
}
#helpBar b {
color: var(--cyan);
font-weight: 500;
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
top: 78px;
transform: translate(-50%, -18px);
padding: 10px 15px;
border: 1px solid rgba(109, 255, 177, 0.4);
background: rgba(6, 20, 17, 0.92);
color: #caffdf;
font-size: 10px;
letter-spacing: 0.08em;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#transitionBanner {
position: fixed;
z-index: 20;
left: 50%;
top: 24px;
transform: translate(-50%, -18px);
width: min(520px, calc(100vw - 40px));
padding: 12px 15px;
border: 1px solid rgba(98, 233, 255, 0.48);
background: rgba(5, 13, 26, 0.94);
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.42);
opacity: 0;
pointer-events: none;
transition: opacity 160ms ease, transform 160ms ease;
}
#transitionBanner.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.transition-head {
display: flex;
justify-content: space-between;
gap: 10px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.12em;
}
#transitionStage {
margin-top: 7px;
color: var(--cyan);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
}
.transition-track {
height: 3px;
margin-top: 9px;
overflow: hidden;
background: rgba(129, 218, 255, 0.12);
}
#transitionFill {
width: 0;
height: 100%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
transition: width 80ms linear;
}
@media (max-width: 980px) {
#consolePanel {
width: 250px;
}
#telemetryPanel {
width: 250px;
}
#previewPanel {
width: 330px;
}
#helpBar {
gap: 9px;
font-size: 7px;
}
}
@media (max-width: 760px) {
#brand {
top: 10px;
left: 12px;
}
#brand small {
display: none;
}
#consolePanel {
top: 62px;
left: 10px;
width: 218px;
max-height: 44vh;
padding: 11px;
}
.rule-manifest,
.route-ledger {
display: none;
}
#telemetryPanel {
top: 10px;
right: 10px;
width: 200px;
padding: 10px;
}
.telemetry-grid {
display: none;
}
#previewPanel {
top: auto;
right: 10px;
bottom: 54px;
width: min(370px, calc(100vw - 20px));
max-height: 54vh;
padding: 13px;
}
.preview-visual {
grid-template-columns: 1fr 1fr;
}
.diagram {
height: 125px;
}
#helpBar {
bottom: 8px;
max-width: calc(100vw - 16px);
overflow: hidden;
text-overflow: ellipsis;
}
#contextPrompt {
bottom: 48px;
font-size: 8px;
}
}
</style>
</head>
<body data-room="gallery">
<div id="stage"></div>
<div class="vignette"></div>
<div class="scanlines"></div>
<header id="brand">
<div class="brand-mark"><span>∴</span></div>
<div>
<strong>PARALLAX OBSERVATORY</strong>
<small>ORIENTATION / GRAVITY RESEARCH ANNEX</small>
</div>
</header>
<aside id="consolePanel" class="hud-panel">
<div class="eyebrow">Transit console</div>
<h1 class="panel-title">GRAVITY CHAMBERS</h1>
<p class="panel-copy">Select a chamber to expose its deterministic transition preview before entry.</p>
<div class="chamber-list">
<button class="chamber-card" type="button" data-chamber="A" style="--card-color: var(--cyan)">
<span class="card-index">01</span>
<span>
<span class="card-name">PLUMB HALL</span>
<span class="card-rule">Floor anchor (-Y)<br>Vertical sill / 0 degree turn</span>
</span>
<span class="card-arrow">↓</span>
</button>
<button class="chamber-card" type="button" data-chamber="B" style="--card-color: var(--magenta)">
<span class="card-index">02</span>
<span>
<span class="card-name">TANGENT HALL</span>
<span class="card-rule">East-wall anchor (+X)<br>Side sill / 90 degree turn</span>
</span>
<span class="card-arrow">→</span>
</button>
<button class="chamber-card" type="button" data-chamber="C" style="--card-color: var(--amber)">
<span class="card-index">03</span>
<span>
<span class="card-name">INVERSE DOME</span>
<span class="card-rule">Ceiling anchor (+Y)<br>Upper lintel / 180 degree turn</span>
</span>
<span class="card-arrow">↑</span>
</button>
</div>
<div class="rule-manifest">
<b>CHAMBER RULES ARE FIXED</b><br>
01 always pulls toward its floor.<br>
02 always pulls toward its east wall.<br>
03 always pulls toward its ceiling.
</div>
<div class="route-ledger">
<div class="ledger-head">
<span>CONTROL TRANSIT LOG</span>
<span id="controlCount">0 / 3 ENTERED</span>
</div>
<div class="route-row"><span>01</span><span>PLUMB HALL</span><b id="route-A">READY</b></div>
<div class="route-row"><span>02</span><span>TANGENT HALL</span><b id="route-B">READY</b></div>
<div class="route-row"><span>03</span><span>INVERSE DOME</span><b id="route-C">READY</b></div>
</div>
<button id="returnButton" type="button" hidden>PREVIEW RETURN TO GALLERY</button>
</aside>
<section id="telemetryPanel" class="hud-panel">
<div class="eyebrow">Live field telemetry</div>
<div class="room-line">
<span id="roomName">CENTRAL GALLERY</span>
<span id="roomNumber">G-00</span>
</div>
<div class="gravity-box">
<div id="gravityGlyph">↓</div>
<div>
<small>ACTIVE GRAVITY VECTOR</small>
<b id="gravityRule">FLOOR ANCHOR / -Y</b>
</div>
</div>
<div class="telemetry-grid">
<div class="telemetry-cell"><span>CONTROL</span><b id="controlState">MANUAL</b></div>
<div class="telemetry-cell"><span>DOOR STATE</span><b id="doorState">STANDBY</b></div>
<div class="telemetry-cell"><span>CHAMBER</span><b id="chamberState">NONE</b></div>
<div class="telemetry-cell"><span>TRANSITION</span><b id="transitionState">STABLE</b></div>
</div>
</section>
<section id="previewPanel" class="hud-panel" aria-live="polite" hidden>
<button id="closePreview" class="close-button" type="button" aria-label="Close preview">×</button>
<div class="preview-heading">
<div class="eyebrow">Deterministic gravity preview</div>
<h2 id="previewName">PLUMB HALL</h2>
<div id="previewSubtitle">Door 01 / gallery anchor to floor anchor</div>
</div>
<div class="preview-visual">
<div class="diagram">
<span class="diagram-label">VECTOR PATH</span>
<div class="axis-x"></div>
<div class="axis-y"></div>
<div id="vectorNeedle"></div>
<div class="vector-readout" id="vectorReadout">-Y / FLOOR</div>
</div>
<div class="diagram">
<span class="diagram-label">DOOR KEEL</span>
<div id="miniDoor">
<div id="miniKeel"></div>
</div>
<div class="vector-readout" id="doorReadout">VERTICAL / FLOOR SILL</div>
</div>
</div>
<div class="preview-metrics">
<div class="metric"><span>TURN ANGLE</span><b id="previewAngle">0 DEG</b></div>
<div class="metric"><span>SOURCE</span><b id="previewSource">FLOOR / -Y</b></div>
<div class="metric"><span>TARGET</span><b id="previewTarget">FLOOR / -Y</b></div>
</div>
<div class="preview-steps">
<div class="preview-step"><i>01</i><span>Route from the current position to the door apron.</span></div>
<div class="preview-step"><i>02</i><span>Rotate the door keel and gravity compass.</span></div>
<div class="preview-step"><i>03</i><span>Cross the threshold and lock the target vector.</span></div>
</div>
<p id="previewStatement">The plumb vector remains locked to the floor.</p>
<div class="preview-actions">
<button id="replayPreview" class="ui-button" type="button">REPLAY MOTION</button>
<button id="commitPreview" class="ui-button primary" type="button">APPROACH & ENTER</button>
</div>
</section>
<div id="reticle"></div>
<div id="contextPrompt">DRAG TO LOOK · W A S D TO MOVE · SELECT A CHAMBER</div>
<div id="helpBar">
<span><b>DRAG</b> LOOK</span>
<span><b>WASD</b> MOVE</span>
<span><b>ARROWS</b> LOOK</span>
<span><b>1–3</b> SELECT</span>
<span><b>E</b> PREVIEW</span>
<span><b>ENTER</b> COMMIT</span>
<span><b>R</b> RETURN</span>
</div>
<div id="toast" role="status"></div>
<div id="transitionBanner" role="status" aria-live="assertive">
<div class="transition-head">
<span id="transitionTitle">TRANSIT</span>
<span id="transitionPercent">0%</span>
</div>
<div id="transitionStage">ROUTING TO DOOR</div>
<div class="transition-track"><div id="transitionFill"></div></div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const V = (x = 0, y = 0, z = 0) => new THREE.Vector3(x, y, z);
const UP = V(0, 1, 0);
const DOWN = V(0, -1, 0);
const FORWARD_AXIS = V(0, 0, -1);
const smooth = (t) => t * t * (3 - 2 * t);
const clamp = THREE.MathUtils.clamp;
const chamberData = {
A: {
id: "A",
number: "01",
name: "PLUMB HALL",
rule: "FLOOR ANCHOR / -Y",
shortRule: "FLOOR / -Y",
gravity: V(0, -1, 0),
color: 0x62e9ff,
cssColor: "#62e9ff",
doorHeading: V(0, 0, -1),
returnLook: V(0, 0, 1),
galleryHeading: V(0, 0, 1),
approach: V(0, 1.65, -7.7),
enterThreshold: V(0, 1.65, -10.2),
arrival: V(0, 1.65, -13.0),
returnPoint: V(0, 1.65, -11.2),
returnThreshold: V(0, 1.65, -9.7),
galleryArrival: V(0, 1.65, -7.6),
portal: V(0, 2.2, -9.55),
threshold: V(0, 0.2, -10.4),
keelOffset: V(0, 0, 0.35),
doorMode: "VERTICAL / FLOOR SILL"
},
B: {
id: "B",
number: "02",
name: "TANGENT HALL",
rule: "EAST-WALL ANCHOR / +X",
shortRule: "EAST WALL / +X",
gravity: V(1, 0, 0),
color: 0xe86cff,
cssColor: "#e86cff",
doorHeading: V(1, 0, 0),
returnLook: V(0, 0, -1),
galleryHeading: V(-1, 0, 0),
approach: V(7.7, 1.65, 0),
enterThreshold: V(10.2, 1.65, 0),
arrival: V(16.35, 1.65, 0),
returnPoint: V(16.35, 1.65, 0),
returnThreshold: V(9.7, 1.65, 0),
galleryArrival: V(7.6, 1.65, 0),
portal: V(9.55, 2.2, 0),
threshold: V(17.72, 3.5, 0),
keelOffset: V(-0.35, 0, 0),
doorMode: "HORIZONTAL / SIDE SILL"
},
C: {
id: "C",
number: "03",
name: "INVERSE DOME",
rule: "CEILING ANCHOR / +Y",
shortRule: "CEILING / +Y",
gravity: V(0, 1, 0),
color: 0xffbd58,
cssColor: "#ffbd58",
doorHeading: V(-1, 0, 0),
returnLook: V(1, 0, 0),
galleryHeading: V(1, 0, 0),
approach: V(-7.7, 1.65, 0),
enterThreshold: V(-10.2, 1.65, 0),
arrival: V(-13.5, 4.35, 0),
returnPoint: V(-13.5, 4.35, 0),
returnThreshold: V(-9.7, 1.65, 0),
galleryArrival: V(-7.6, 1.65, 0),
portal: V(-9.55, 2.2, 0),
threshold: V(-14, 5.82, 0),
keelOffset: V(0.35, 0, 0),
doorMode: "INVERTED / UPPER LINTEL"
}
};
const stage = $("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x030711);
scene.fog = new THREE.FogExp2(0x030711, 0.015);
const camera = new THREE.PerspectiveCamera(68, innerWidth / innerHeight, 0.05, 120);
camera.position.set(0, 1.65, 5.5);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio || 1, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.setAttribute("aria-label", "Voxel observatory. Drag to look and use W A S D to move.");
const clock = new THREE.Clock();
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
const doors = {};
const routeState = {
A: { label: "READY", entered: false },
B: { label: "READY", entered: false },
C: { label: "READY", entered: false }
};
let selectedChamber = "A";
let previewDirection = "enter";
let previewSource = DOWN.clone();
let previewTarget = DOWN.clone();
let transition = null;
let toastTimer = 0;
let previewTimer = 0;
let selectedDoor = null;
const player = {
position: V(0, 1.65, 5.5),
velocity: V(),
gravity: DOWN.clone(),
yaw: 0,
pitch: 0,
zone: "gallery"
};
const keys = new Set();
function getMaterial(color, emissive = 0x000000, emissiveIntensity = 0, metalness = 0.08, roughness = 0.78, opacity = 1) {
const key = [color, emissive, emissiveIntensity, metalness, roughness, opacity].join("|");
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity,
metalness,
roughness,
transparent: opacity < 1,
opacity
}));
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const material = color && color.isMaterial ? color : getMaterial(
color,
options.emissive ?? 0x000000,
options.emissiveIntensity ?? 0,
options.metalness ?? 0.08,
options.roughness ?? 0.78,
options.opacity ?? 1
);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) mesh.rotation.set(...options.rotation);
if (options.edge) {
const edgeGeometry = new THREE.EdgesGeometry(unitBox);
const edgeMaterial = new THREE.LineBasicMaterial({
color: options.edge,
transparent: true,
opacity: options.edgeOpacity ?? 0.35
});
mesh.add(new THREE.LineSegments(edgeGeometry, edgeMaterial));
}
parent.add(mesh);
return mesh;
}
function tileSurface(origin, u, v, normal, countU, countV, step, color) {
const count = countU * countV;
const material = getMaterial(color, 0x000000, 0, 0.18, 0.7);
const mesh = new THREE.InstancedMesh(unitBox, material, count);
const dummy = new THREE.Object3D();
const zAxis = V().crossVectors(u, normal).normalize();
const basis = new THREE.Matrix4().makeBasis(u.clone().normalize(), normal.clone().normalize(), zAxis);
let index = 0;
for (let i = 0; i < countU; i++) {
for (let j = 0; j < countV; j++) {
dummy.position.copy(origin)
.addScaledVector(u, (i + 0.5) * step)
.addScaledVector(v, (j + 0.5) * step)
.addScaledVector(normal, 0.025);
dummy.quaternion.setFromRotationMatrix(basis);
dummy.scale.set(step * 0.92, 0.12, step * 0.92);
dummy.updateMatrix();
mesh.setMatrixAt(index++, dummy.matrix);
}
}
mesh.instanceMatrix.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function makeTextSprite(text, color = "#9adfff", width = 512, height = 96) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = width;
textureCanvas.height = height;
const context = textureCanvas.getContext("2d");
context.clearRect(0, 0, width, height);
context.fillStyle = "rgba(4, 10, 20, 0.82)";
context.fillRect(0, 0, width, height);
context.strokeStyle = color;
context.globalAlpha = 0.65;
context.strokeRect(3, 3, width - 6, height - 6);
context.globalAlpha = 1;
context.fillStyle = color;
context.font = "bold 31px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: true
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(4.3, 0.8, 1);
return sprite;
}
function addConsole(x, z, color, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
addBox(group, [2.7, 0.45, 1.2], [0, 0.25, 0], 0x17243a, { edge: color });
addBox(group, [2.35, 0.9, 0.65], [0, 0.78, -0.15], 0x223651, { edge: color });
addBox(group, [1.8, 0.45, 0.08], [0, 0.95, 0.21], color, {
emissive: color,
emissiveIntensity: 1.5,
castShadow: false
});
addBox(group, [0.18, 0.08, 0.18], [-0.85, 1.25, 0.14], 0xffd37a, {
emissive: 0xffb84f,
emissiveIntensity: 1.2,
castShadow: false
});
return group;
}
function makeGravityArrow(color) {
const group = new THREE.Group();
const material = getMaterial(color, color, 2.2, 0.12, 0.42);
addBox(group, [0.13, 0.86, 0.13], [0, -0.43, 0], material, { castShadow: false });
addBox(group, [0.44, 0.2, 0.13], [0, -0.93, 0], material, { castShadow: false });
addBox(group, [0.26, 0.18, 0.13], [0, -1.1, 0], material, { castShadow: false });
addBox(group, [0.2, 0.2, 0.2], [0, 0.08, 0], material, { castShadow: false });
return group;
}
function makeKeel(color) {
const group = new THREE.Group();
const material = getMaterial(color, color, 1.6, 0.15, 0.45);
addBox(group, [0.12, 3.45, 0.12], [0, 0, 0], material, { castShadow: false });
addBox(group, [0.5, 0.16, 0.18], [0, 1.55, 0], material, { castShadow: false });
addBox(group, [0.5, 0.16, 0.18], [0, -1.55, 0], material, { castShadow: false });
return group;
}
function makeThreshold(color) {
const group = new THREE.Group();
const base = getMaterial(0x102039, color, 0.28, 0.22, 0.62);
const edge = getMaterial(color, color, 2.1, 0.1, 0.4);
addBox(group, [3.5, 2.15, 0.12], [0, 0, 0], base, { castShadow: false });
addBox(group, [3.55, 0.11, 0.16], [0, 1.02, 0.05], edge, { castShadow: false });
addBox(group, [3.55, 0.11, 0.16], [0, -1.02, 0.05], edge, { castShadow: false });
addBox(group, [0.11, 2.15, 0.16], [-1.7, 0, 0.05], edge, { castShadow: false });
addBox(group, [0.11, 2.15, 0.16], [1.7, 0, 0.05], edge, { castShadow: false });
return group;
}
function createDoor(id, position, rotationY) {
const chamber = chamberData[id];
const group = new THREE.Group();
group.position.copy(position);
group.rotation.y = rotationY;
scene.add(group);
const frameMaterial = getMaterial(0x243c59, chamber.color, 0.18, 0.28, 0.56);
addBox(group, [0.28, 4.8, 0.45], [-2.34, 2.35, 0], frameMaterial, { edge: chamber.color });
addBox(group, [0.28, 4.8, 0.45], [2.34, 2.35, 0], frameMaterial, { edge: chamber.color });
addBox(group, [4.96, 0.28, 0.45], [0, 4.66, 0], frameMaterial, { edge: chamber.color });
addBox(group, [4.96, 0.18, 0.45], [0, 0.09, 0], frameMaterial, { edge: chamber.color });
const leafMaterial = new THREE.MeshStandardMaterial({
color: id === "B" ? 0x382143 : id === "C" ? 0x40301e : 0x173448,
emissive: chamber.color,
emissiveIntensity: 0.16,
metalness: 0.22,
roughness: 0.55,
transparent: true,
opacity: 0.91
});
const left = addBox(group, [2.12, 4.25, 0.18], [-1.07, 2.25, 0.16], leafMaterial, {
edge: chamber.color,
edgeOpacity: 0.42
});
const right = addBox(group, [2.12, 4.25, 0.18], [1.07, 2.25, 0.16], leafMaterial, {
edge: chamber.color,
edgeOpacity: 0.42
});
addBox(group, [0.12, 2.5, 0.06], [0, 2.25, 0.29], chamber.color, {
emissive: chamber.color,
emissiveIntensity: 1.6,
castShadow: false
});
const label = makeTextSprite(
`${chamber.number} ${chamber.name} / ${chamber.shortRule}`,
chamber.cssColor,
640,
96
);
label.position.set(0, 5.37, 0.2);
label.scale.set(4.9, 0.74, 1);
group.add(label);
const arrow = makeGravityArrow(chamber.color);
arrow.position.copy(chamber.portal);
scene.add(arrow);
const keel = makeKeel(chamber.color);
keel.position.copy(chamber.portal).add(chamber.keelOffset);
scene.add(keel);
const threshold = makeThreshold(chamber.color);
threshold.position.copy(chamber.threshold);
scene.add(threshold);
const door = {
id,
chamber,
group,
left,
right,
arrow,
keel,
threshold,
openAmount: 0,
openTarget: 0,
selected: false
};
doors[id] = door;
applyGravityVisual(door, chamber.gravity);
return door;
}
function applyGravityVisual(door, gravity) {
const direction = gravity.clone().normalize();
door.arrow.quaternion.setFromUnitVectors(DOWN, direction);
door.keel.quaternion.setFromUnitVectors(UP, direction.clone().negate());
door.threshold.quaternion.setFromUnitVectors(V(0, 0, 1), direction);
}
function buildGallery() {
addBox(scene, [20.3, 0.35, 20.3], [0, -0.2, 0], 0x0d1728, { edge: 0x24415f });
tileSurface(V(-10, 0, -10), V(1, 0, 0), V(0, 0, 1), V(0, 1, 0), 20, 20, 1, 0x17243a);
addBox(scene, [20.3, 0.3, 20.3], [0, 7.16, 0], 0x111d30, { edge: 0x294967, castShadow: false });
addBox(scene, [7.8, 7, 0.36], [-6.1, 3.5, -10], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [7.8, 7, 0.36], [6.1, 3.5, -10], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [4.4, 2.35, 0.36], [0, 5.82, -10], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [0.36, 7, 7.8], [10, 3.5, -6.1], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [0.36, 7, 7.8], [10, 3.5, 6.1], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [0.36, 2.35, 4.4], [10, 5.82, 0], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [0.36, 7, 7.8], [-10, 3.5, -6.1], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [0.36, 7, 7.8], [-10, 3.5, 6.1], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [0.36, 2.35, 4.4], [-10, 5.82, 0], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [20.3, 7, 0.36], [0, 3.5, 10], 0x18283d, { edge: 0x2e5373 });
addBox(scene, [0.12, 0.06, 9.2], [0, 0.075, -4.7], 0x62e9ff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.35,
castShadow: false
});
addBox(scene, [9.2, 0.06, 0.12], [4.7, 0.075, 0], 0xe86cff, {
emissive: 0xe86cff,
emissiveIntensity: 1.35,
castShadow: false
});
addBox(scene, [9.2, 0.06, 0.12], [-4.7, 0.075, 0], 0xffbd58, {
emissive: 0xffbd58,
emissiveIntensity: 1.35,
castShadow: false
});
for (let i = 0; i < 6; i++) {
addBox(scene, [0.22, 0.05, 0.65], [0, 0.085, -7.6 + i * 0.8], 0x62e9ff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.1,
castShadow: false
});
}
addConsole(-7, 6.5, 0x62e9ff, -0.2);
addConsole(7, 6.5, 0xe86cff, 0.2);
addConsole(-8.6, -5.8, 0xffbd58, Math.PI / 2);
addConsole(8.6, -5.8, 0x62e9ff, -Math.PI / 2);
for (const z of [-7.7, 0, 7.7]) {
addBox(scene, [19, 0.28, 0.28], [0, 6.55, z], 0x243b54, { edge: 0x3e688a });
}
for (const x of [-7.7, 0, 7.7]) {
addBox(scene, [0.28, 0.28, 19], [x, 6.55, 0], 0x243b54, { edge: 0x3e688a });
}
const manifest = makeTextSprite("RULE MANIFEST // 01:-Y 02:+X 03:+Y", "#9adfff", 720, 96);
manifest.position.set(0, 4.15, 9.55);
manifest.scale.set(8.4, 1.05, 1);
scene.add(manifest);
}
function buildChamberA() {
addBox(scene, [16.3, 0.35, 16.3], [0, -0.2, -18], 0x0d1829, { edge: 0x26415b });
tileSurface(V(-8, 0, -26), V(1, 0, 0), V(0, 0, 1), V(0, 1, 0), 16, 16, 1, 0x142b3b);
addBox(scene, [0.36, 7, 16.2], [-8.18, 3.5, -18], 0x14273a, { edge: 0x2a5367 });
addBox(scene, [0.36, 7, 16.2], [8.18, 3.5, -18], 0x14273a, { edge: 0x2a5367 });
addBox(scene, [16.7, 7, 0.36], [0, 3.5, -26.18], 0x14273a, { edge: 0x2a5367 });
addBox(scene, [16.3, 0.3, 16.3], [0, 7.16, -18], 0x101f30, { edge: 0x254b60, castShadow: false });
addBox(scene, [8.7, 3.6, 0.16], [0, 3.65, -25.94], 0x07111d, { edge: 0x62e9ff });
for (let i = 0; i < 34; i++) {
const x = -3.8 + ((i * 17) % 31) * 0.25;
const y = 2.25 + ((i * 11) % 17) * 0.16;
addBox(scene, [0.08, 0.08, 0.05], [x, y, -25.81], i % 3 ? 0x62e9ff : 0xffd978, {
emissive: i % 3 ? 0x62e9ff : 0xffd978,
emissiveIntensity: 1.8,
castShadow: false
});
}
addBox(scene, [2.8, 0.5, 2.8], [0, 0.25, -19], 0x1b3648, { edge: 0x62e9ff });
addBox(scene, [1.5, 1.1, 1.5], [0, 1.05, -19], 0x102536, { edge: 0x62e9ff });
addBox(scene, [0.62, 0.62, 0.62], [0, 2.25, -19], 0x62e9ff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.8
});
for (const x of [-6.5, 6.5]) {
addBox(scene, [1.1, 2.5, 0.8], [x, 1.25, -22.5], 0x193347, { edge: 0x39718a });
addBox(scene, [0.65, 0.45, 0.08], [x, 1.6, -22.05], 0x62e9ff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.5,
castShadow: false
});
}
}
function buildChamberB() {
addBox(scene, [8.3, 0.35, 16.3], [14, -0.2, 0], 0x181329, { edge: 0x49335c });
addBox(scene, [8.3, 0.3, 16.3], [14, 7.16, 0], 0x1c162b, { edge: 0x513764, castShadow: false });
addBox(scene, [0.38, 7, 16.2], [18.18, 3.5, 0], 0x211831, { edge: 0x70468c });
addBox(scene, [0.38, 7, 16.2], [9.82, 3.5, -8.18], 0x211831, { edge: 0x70468c });
addBox(scene, [0.38, 7, 16.2], [9.82, 3.5, 8.18], 0x211831, { edge: 0x70468c });
tileSurface(V(18, 0, -8), V(0, 1, 0), V(0, 0, 1), V(1, 0, 0), 8, 16, 1, 0x322044);
addBox(scene, [0.55, 1.2, 3.2], [17.55, 1.25, -3.8], 0x281a37, { edge: 0xe86cff });
addBox(scene, [0.12, 0.55, 2.4], [17.22, 1.55, -3.8], 0xe86cff, {
emissive: 0xe86cff,
emissiveIntensity: 1.7,
castShadow: false
});
addBox(scene, [0.55, 1.2, 3.2], [17.55, 5.75, 3.8], 0x281a37, { edge: 0xe86cff });
addBox(scene, [0.12, 0.55, 2.4], [17.22, 5.45, 3.8], 0xe86cff, {
emissive: 0xe86cff,
emissiveIntensity: 1.7,
castShadow: false
});
for (let i = 0; i < 20; i++) {
const angle = (i / 20) * Math.PI * 2;
addBox(scene, [0.25, 0.25, 0.25], [17.72, 3.5 + Math.cos(angle) * 2.15, Math.sin(angle) * 2.15], 0xe86cff, {
emissive: 0xe86cff,
emissiveIntensity: 1.2,
castShadow: false
});
}
addBox(scene, [0.4, 0.4, 0.4], [17.72, 3.5, 0], 0xffd1ff, {
emissive: 0xe86cff,
emissiveIntensity: 1.8
});
}
function buildChamberC() {
addBox(scene, [8.3, 0.35, 16.3], [-14, -0.2, 0], 0x211a13, { edge: 0x594329 });
addBox(scene, [8.3, 0.3, 16.3], [-14, 6.16, 0], 0x2b2116, { edge: 0x715032, castShadow: false });
addBox(scene, [0.38, 6, 16.2], [-18.18, 3, 0], 0x291f15, { edge: 0x6d4b2c });
addBox(scene, [0.38, 6, 16.2], [-9.82, 3, -8.18], 0x291f15, { edge: 0x6d4b2c });
addBox(scene, [0.38, 6, 16.2], [-9.82, 3, 8.18], 0x291f15, { edge: 0x6d4b2c });
tileSurface(V(-18, 6, -8), V(1, 0, 0), V(0, 0, 1), V(0, 1, 0), 8, 16, 1, 0x49331e);
for (const z of [-5.5, 0, 5.5]) {
addBox(scene, [0.38, 1.55, 0.38], [-14.5, 5.2, z], 0x4b321c, { edge: 0xffbd58 });
addBox(scene, [1.15, 0.28, 1.15], [-14.5, 4.38, z], 0x302316, { edge: 0xffbd58 });
addBox(scene, [0.48, 0.48, 0.48], [-14.5, 4.05, z], 0xffbd58, {
emissive: 0xffbd58,
emissiveIntensity: 1.7
});
}
addBox(scene, [0.45, 2.2, 4.2], [-17.55, 4.75, 0], 0x3a2917, { edge: 0xffbd58 });
addBox(scene, [0.12, 1.25, 3.2], [-17.25, 4.75, 0], 0xffbd58, {
emissive: 0xffbd58,
emissiveIntensity: 1.6,
castShadow: false
});
}
buildGallery();
buildChamberA();
buildChamberB();
buildChamberC();
createDoor("A", V(0, 0, -9.82), 0);
createDoor("B", V(9.82, 0, 0), Math.PI / 2);
createDoor("C", V(-9.82, 0, 0), -Math.PI / 2);
const hemisphere = new THREE.HemisphereLight(0x93cfff, 0x11101a, 1.45);
scene.add(hemisphere);
const ambient = new THREE.AmbientLight(0x6f88ad, 0.34);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xbfe9ff, 2.15);
keyLight.position.set(4, 12, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -24;
keyLight.shadow.camera.right = 24;
keyLight.shadow.camera.top = 24;
keyLight.shadow.camera.bottom = -24;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 60;
scene.add(keyLight);
function addPointLight(color, intensity, distance, position) {
const light = new THREE.PointLight(color, intensity, distance, 2);
light.position.copy(position);
scene.add(light);
return light;
}
addPointLight(0x62e9ff, 28, 18, V(0, 4.5, -12));
addPointLight(0x62e9ff, 22, 14, V(0, 3.5, -22));
addPointLight(0xe86cff, 32, 16, V(14, 3.5, 0));
addPointLight(0xe86cff, 20, 12, V(17, 4.5, -4));
addPointLight(0xffbd58, 30, 16, V(-14, 4.5, 0));
addPointLight(0xffbd58, 18, 12, V(-16, 4.2, 5));
addPointLight(0x6f9fff, 18, 15, V(0, 5, 3));
const galleryOrrery = new THREE.Group();
galleryOrrery.position.set(0, 3.85, 0);
scene.add(galleryOrrery);
addBox(galleryOrrery, [0.7, 0.7, 0.7], [0, 0, 0], 0x9cecff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.7
});
for (let i = 0; i < 28; i++) {
const angle = (i / 28) * Math.PI * 2;
addBox(galleryOrrery, [0.25, 0.25, 0.25], [Math.cos(angle) * 2.25, 0, Math.sin(angle) * 2.25], 0x62e9ff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.1,
castShadow: false
});
}
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
addBox(galleryOrrery, [0.18, 0.18, 0.18], [Math.cos(angle) * 1.55, Math.sin(angle) * 1.55, 0], 0xffd37a, {
emissive: 0xffb84f,
emissiveIntensity: 1.2,
castShadow: false
});
}
const chamberOrrery = new THREE.Group();
chamberOrrery.position.set(0, 3.25, -19);
scene.add(chamberOrrery);
addBox(chamberOrrery, [0.55, 0.55, 0.55], [0, 0, 0], 0xb5f6ff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.9
});
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
addBox(chamberOrrery, [0.22, 0.22, 0.22], [Math.cos(angle) * 1.7, Math.sin(angle) * 1.7, 0], 0x62e9ff, {
emissive: 0x62e9ff,
emissiveIntensity: 1.4,
castShadow: false
});
}
function seededRandom(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(17031);
const particleCount = 110;
const particleMesh = new THREE.InstancedMesh(
unitBox,
getMaterial(0x9cdfff, 0x62e9ff, 1.3, 0.05, 0.6),
particleCount
);
const particleDummy = new THREE.Object3D();
for (let i = 0; i < particleCount; i++) {
particleDummy.position.set((random() - 0.5) * 19, 1 + random() * 5.5, (random() - 0.5) * 19);
particleDummy.rotation.set(random() * 3, random() * 3, random() * 3);
const size = 0.025 + random() * 0.055;
particleDummy.scale.set(size, size, size);
particleDummy.updateMatrix();
particleMesh.setMatrixAt(i, particleDummy.matrix);
}
particleMesh.instanceMatrix.needsUpdate = true;
particleMesh.castShadow = false;
scene.add(particleMesh);
function quaternionFromHeading(up, heading) {
const localUp = up.clone().normalize();
let forward = heading.clone().addScaledVector(localUp, -heading.dot(localUp));
if (forward.lengthSq() < 0.0001) {
forward = FORWARD_AXIS.clone().addScaledVector(localUp, -FORWARD_AXIS.dot(localUp));
}
forward.normalize();
const right = V().crossVectors(forward, localUp).normalize();
const backward = forward.clone().negate();
const matrix = new THREE.Matrix4().makeBasis(right, localUp, backward);
return new THREE.Quaternion().setFromRotationMatrix(matrix);
}
function frameQuaternion(gravity) {
const up = gravity.clone().normalize().negate();
return quaternionFromHeading(up, FORWARD_AXIS);
}
function updateCameraFromLook() {
const frame = frameQuaternion(player.gravity);
const local = new THREE.Quaternion().setFromEuler(
new THREE.Euler(player.pitch, player.yaw, 0, "YXZ")
);
camera.quaternion.copy(frame.multiply(local));
camera.updateMatrixWorld();
}
function gravityLabel(vector) {
if (vector.x > 0.5) return "EAST WALL / +X";
if (vector.x < -0.5) return "WEST WALL / -X";
if (vector.y > 0.5) return "CEILING / +Y";
if (vector.y < -0.5) return "FLOOR / -Y";
if (vector.z > 0.5) return "NORTH / +Z";
return "SOUTH / -Z";
}
function shortGravityLabel(vector) {
if (vector.x > 0.5) return "EAST / +X";
if (vector.x < -0.5) return "WEST / -X";
if (vector.y > 0.5) return "UP / +Y";
if (vector.y < -0.5) return "DOWN / -Y";
if (vector.z > 0.5) return "NORTH / +Z";
return "SOUTH / -Z";
}
function cssGravityAngle(vector) {
if (vector.y > 0.5) return 0;
if (vector.x > 0.5) return 90;
if (vector.y < -0.5) return 180;
if (vector.x < -0.5) return -90;
return 0;
}
function cssUpAngle(vector) {
if (vector.y > 0.5) return 0;
if (vector.x > 0.5) return 90;
if (vector.y < -0.5) return 180;
if (vector.x < -0.5) return -90;
return 0;
}
function angleBetween(a, b) {
const dot = clamp(a.clone().normalize().dot(b.clone().normalize()), -1, 1);
return Math.round(Math.acos(dot) * 180 / Math.PI);
}
function interpolateGravity(source, target, amount) {
const rotation = new THREE.Quaternion().setFromUnitVectors(
source.clone().normalize(),
target.clone().normalize()
);
const interpolated = new THREE.Quaternion().identity().slerp(rotation, amount);
return source.clone().normalize().applyQuaternion(interpolated).normalize();
}
function setRouteState(id, label, entered = routeState[id].entered) {
routeState[id] = { label, entered };
const element = $(`route-${id}`);
element.textContent = label;
element.dataset.state = entered ? "entered" : label.toLowerCase();
const count = Object.values(routeState).filter((entry) => entry.entered).length;
$("controlCount").textContent = `${count} / 3 ENTERED`;
}
function updateCards() {
document.querySelectorAll(".chamber-card").forEach((card) => {
const id = card.dataset.chamber;
card.classList.toggle("selected", selectedChamber === id && player.zone === "gallery");
card.disabled = player.zone !== "gallery";
});
$("returnButton").hidden = player.zone === "gallery";
}
function updateTelemetry() {
let roomName = "CENTRAL GALLERY";
let roomNumber = "G-00";
let rule = "FLOOR ANCHOR / -Y";
let glyph = "↓";
let color = "#62e9ff";
let chamber = "NONE";
let control = "MANUAL";
if (player.zone !== "gallery") {
const data = chamberData[player.zone];
roomName = data.name;
roomNumber = `G-${data.number}`;
rule = data.rule;
glyph = data.gravity.x > 0 ? "→" : data.gravity.y > 0 ? "↑" : "↓";
color = data.cssColor;
chamber = `${data.number} / ${data.shortRule}`;
control = "CHAMBER";
}
$("roomName").textContent = roomName;
$("roomNumber").textContent = roomNumber;
$("gravityRule").textContent = rule;
$("gravityGlyph").textContent = glyph;
$("telemetryPanel").style.setProperty("--room-color", color);
$("chamberState").textContent = chamber;
$("controlState").textContent = control;
$("transitionState").textContent = transition ? "TRANSFERRING" : "STABLE";
$("doorState").textContent = transition ? "CYCLING" : selectedDoor ? "ARMED" : "STANDBY";
document.body.dataset.room = player.zone;
updateCards();
}
function showToast(message) {
clearTimeout(toastTimer);
$("toast").textContent = message;
$("toast").classList.add("show");
toastTimer = setTimeout(() => $("toast").classList.remove("show"), 2600);
}
function playPreviewMotion() {
const needle = $("vectorNeedle");
const keel = $("miniKeel");
needle.getAnimations().forEach((animation) => animation.cancel());
keel.getAnimations().forEach((animation) => animation.cancel());
const fromAngle = cssGravityAngle(previewSource);
const toAngle = cssGravityAngle(previewTarget);
const fromKeel = cssUpAngle(previewSource.clone().negate());
const toKeel = cssUpAngle(previewTarget.clone().negate());
needle.style.transform = `rotate(${fromAngle}deg)`;
keel.style.transform = `rotate(${fromKeel}deg)`;
if (needle.animate) {
needle.animate(
[
{ transform: `rotate(${fromAngle}deg)` },
{ transform: `rotate(${toAngle}deg)` }
],
{
duration: 1600,
easing: "cubic-bezier(.2,.75,.2,1)",
fill: "forwards"
}
);
keel.animate(
[
{ transform: `rotate(${fromKeel}deg)` },
{ transform: `rotate(${toKeel}deg)` }
],
{
duration: 1600,
easing: "cubic-bezier(.2,.75,.2,1)",
fill: "forwards"
}
);
} else {
needle.style.transform = `rotate(${toAngle}deg)`;
keel.style.transform = `rotate(${toKeel}deg)`;
}
clearTimeout(previewTimer);
previewTimer = setTimeout(() => {
needle.style.transform = `rotate(${toAngle}deg)`;
keel.style.transform = `rotate(${toKeel}deg)`;
}, 1620);
}
function openPreview(id, direction = "enter") {
if (transition) return;
const chamber = chamberData[id];
selectedChamber = id;
selectedDoor = doors[id];
previewDirection = direction;
previewSource = direction === "return" ? player.gravity.clone() : DOWN.clone();
previewTarget = direction === "return" ? DOWN.clone() : chamber.gravity.clone();
const angle = angleBetween(previewSource, previewTarget);
const isReturn = direction === "return";
const previewColor = chamber.cssColor;
$("previewPanel").hidden = false;
$("previewPanel").style.setProperty("--preview-color", previewColor);
$("previewName").textContent = isReturn ? `RETURN / ${chamber.name}` : chamber.name;
$("previewName").style.color = previewColor;
$("previewSubtitle").textContent = isReturn
? `Door ${chamber.number} / ${gravityLabel(previewSource)} back to the central gallery`
: `Door ${chamber.number} / gallery anchor to ${gravityLabel(previewTarget)}`;
$("previewAngle").textContent = `${angle} DEG`;
$("previewSource").textContent = shortGravityLabel(previewSource);
$("previewTarget").textContent = shortGravityLabel(previewTarget);
$("vectorReadout").textContent = `${shortGravityLabel(previewTarget)} / LOCK`;
$("doorReadout").textContent = isReturn ? "VERTICAL / GALLERY SILL" : chamber.doorMode;
$("commitPreview").textContent = isReturn ? "COMMIT RETURN" : "APPROACH & ENTER";
if (angle === 0) {
$("previewStatement").textContent = "The gravity vector is unchanged. The door compass remains plumb and the floor rule is preserved.";
} else if (angle === 90) {
$("previewStatement").textContent = "The floor vector rotates exactly 90 degrees toward +X. The door keel turns to a side sill before crossing.";
} else if (angle === 180) {
$("previewStatement").textContent = "The floor vector rotates exactly 180 degrees toward +Y. The door keel inverts to the upper lintel before crossing.";
} else {
$("previewStatement").textContent = `The gravity vector rotates ${angle} degrees. The target chamber rule is applied only after the threshold is crossed.`;
}
if (!routeState[id].entered) setRouteState(id, "PREVIEWED");
playPreviewMotion();
updateTelemetry();
}
function closePreview() {
if (transition) return;
$("previewPanel").hidden = true;
}
function selectChamber(id) {
if (player.zone !== "gallery" || transition) return;
selectedChamber = id;
openPreview(id, "enter");
}
function openReturnPreview() {
if (player.zone === "gallery" || transition) return;
openPreview(player.zone, "return");
}
function setTransitionBanner(title, stage, progress) {
$("transitionTitle").textContent = title;
$("transitionStage").textContent = stage;
$("transitionPercent").textContent = `${Math.round(clamp(progress, 0, 1) * 100)}%`;
$("transitionFill").style.width = `${clamp(progress, 0, 1) * 100}%`;
}
function beginEnter(chamberId) {
const chamber = chamberData[chamberId];
const source = player.gravity.clone();
const startPosition = player.position.clone();
const startQuaternion = camera.quaternion.clone();
const sourceUp = source.clone().negate();
const targetUp = chamber.gravity.clone().negate();
const doorQuaternion = quaternionFromHeading(sourceUp, chamber.doorHeading);
const targetQuaternion = quaternionFromHeading(targetUp, FORWARD_AXIS);
transition = {
kind: "enter",
chamberId,
doorId: chamberId,
elapsed: 0,
duration: 4.35,
startPosition,
approach: chamber.approach.clone(),
threshold: chamber.enterThreshold.clone(),
arrival: chamber.arrival.clone(),
startQuaternion,
doorQuaternion,
targetQuaternion,
source,
target: chamber.gravity.clone(),
gravityVisual: source.clone(),
endYaw: 0,
endPitch: 0
};
doors[chamberId].openTarget = 1;
player.velocity.set(0, 0, 0);
keys.clear();
$("previewPanel").hidden = true;
$("transitionBanner").classList.add("visible");
setTransitionBanner(`TRANSIT / ${chamber.name}`, "ROUTING TO ORIENTATION DOOR", 0);
updateTelemetry();
}
function beginReturn() {
const chamberId = player.zone;
const chamber = chamberData[chamberId];
const source = player.gravity.clone();
const startPosition = player.position.clone();
const startQuaternion = camera.quaternion.clone();
const sourceUp = source.clone().negate();
const doorQuaternion = quaternionFromHeading(sourceUp, chamber.returnLook);
const targetQuaternion = quaternionFromHeading(UP, chamber.galleryHeading);
const endYaw = Math.atan2(-chamber.galleryHeading.x, -chamber.galleryHeading.z);
transition = {
kind: "return",
chamberId,
doorId: chamberId,
elapsed: 0,
duration: 4.35,
startPosition,
approach: chamber.returnPoint.clone(),
threshold: chamber.returnThreshold.clone(),
arrival: chamber.galleryArrival.clone(),
startQuaternion,
doorQuaternion,
targetQuaternion,
source,
target: DOWN.clone(),
gravityVisual: source.clone(),
endYaw,
endPitch: 0
};
doors[chamberId].openTarget = 1;
player.velocity.set(0, 0, 0);
keys.clear();
$("previewPanel").hidden = true;
$("transitionBanner").classList.add("visible");
setTransitionBanner(`RETURN / ${chamber.name}`, "ROUTING TO RETURN HATCH", 0);
updateTelemetry();
}
function commitPreview() {
if (transition || $("previewPanel").hidden) return;
if (previewDirection === "enter") beginEnter(selectedChamber);
else beginReturn();
}
function finishTransition() {
const completed = transition;
transition = null;
if (completed.kind === "enter") {
const chamber = chamberData[completed.chamberId];
player.zone = chamber.id;
player.gravity.copy(chamber.gravity);
player.position.copy(completed.arrival);
player.yaw = completed.endYaw;
player.pitch = completed.endPitch;
player.velocity.set(0, 0, 0);
setRouteState(chamber.id, "ENTERED", true);
doors[chamber.id].openTarget = 0.75;
showToast(`${chamber.name}: ${chamber.rule} LOCKED`);
} else {
const chamber = chamberData[completed.chamberId];
player.zone = "gallery";
player.gravity.copy(DOWN);
player.position.copy(completed.arrival);
player.yaw = completed.endYaw;
player.pitch = completed.endPitch;
player.velocity.set(0, 0, 0);
setRouteState(chamber.id, "ENTERED / RETURN", true);
doors[chamber.id].openTarget = 0;
showToast("CENTRAL GALLERY: FLOOR ANCHOR / -Y RESTORED");
}
camera.quaternion.copy(completed.targetQuaternion);
$("transitionBanner").classList.remove("visible");
updateCameraFromLook();
updateTelemetry();
}
function updateTransition(dt) {
const tr = transition;
tr.elapsed += dt;
const t = tr.elapsed;
const progress = clamp(t / tr.duration, 0, 1);
const approachEnd = 1.25;
const alignEnd = 2.15;
const thresholdEnd = 2.62;
const crossEnd = 4.0;
if (t < approachEnd) {
const amount = smooth(t / approachEnd);
player.position.lerpVectors(tr.startPosition, tr.approach, amount);
camera.quaternion.copy(tr.startQuaternion).slerp(tr.doorQuaternion, amount);
tr.gravityVisual.copy(tr.source);
setTransitionBanner(
tr.kind === "enter" ? `TRANSIT / ${chamberData[tr.chamberId].name}` : `RETURN / ${chamberData[tr.chamberId].name}`,
"ROUTING TO ORIENTATION DOOR",
progress
);
} else if (t < alignEnd) {
const amount = smooth((t - approachEnd) / (alignEnd - approachEnd));
player.position.copy(tr.approach);
camera.quaternion.copy(tr.doorQuaternion);
tr.gravityVisual.copy(interpolateGravity(tr.source, tr.target, amount));
setTransitionBanner(
tr.kind === "enter" ? `TRANSIT / ${chamberData[tr.chamberId].name}` : `RETURN / ${chamberData[tr.chamberId].name}`,
"ALIGNING GRAVITY KEEL",
progress
);
} else if (t < thresholdEnd) {
const amount = smooth((t - alignEnd) / (thresholdEnd - alignEnd));
player.position.lerpVectors(tr.approach, tr.threshold, amount);
camera.quaternion.copy(tr.doorQuaternion);
tr.gravityVisual.copy(tr.target);
setTransitionBanner(
tr.kind === "enter" ? `TRANSIT / ${chamberData[tr.chamberId].name}` : `RETURN / ${chamberData[tr.chamberId].name}`,
"OPENING ORIENTATION DOOR",
progress
);
} else if (t < crossEnd) {
const amount = smooth((t - thresholdEnd) / (crossEnd - thresholdEnd));
player.position.lerpVectors(tr.threshold, tr.arrival, amount);
camera.quaternion.copy(tr.doorQuaternion).slerp(tr.targetQuaternion, amount);
tr.gravityVisual.copy(interpolateGravity(tr.source, tr.target, amount));
setTransitionBanner(
tr.kind === "enter" ? `TRANSIT / ${chamberData[tr.chamberId].name}` : `RETURN / ${chamberData[tr.chamberId].name}`,
amount < 0.48 ? "CROSSING THRESHOLD" : "LOCKING TARGET VECTOR",
progress
);
} else {
const amount = smooth((t - crossEnd) / (tr.duration - crossEnd));
player.position.copy(tr.arrival);
camera.quaternion.copy(tr.targetQuaternion);
tr.gravityVisual.copy(tr.target);
setTransitionBanner(
tr.kind === "enter" ? `TRANSIT / ${chamberData[tr.chamberId].name}` : `RETURN / ${chamberData[tr.chamberId].name}`,
"SETTLING ON ANCHOR PLANE",
progress
);
}
const activeDoor = doors[tr.doorId];
activeDoor.openTarget = 1;
applyGravityVisual(activeDoor, tr.gravityVisual);
if (t >= tr.duration) finishTransition();
}
function nearestGalleryDoor() {
let nearest = null;
let best = Infinity;
for (const id of ["A", "B", "C"]) {
const distance = player.position.distanceTo(chamberData[id].approach);
if (distance < best) {
best = distance;
nearest = id;
}
}
return best < 3 ? nearest : null;
}
function updateMovement(dt) {
if (keys.has("arrowleft")) player.yaw += 1.45 * dt;
if (keys.has("arrowright")) player.yaw -= 1.45 * dt;
if (keys.has("arrowup")) player.pitch += 1.2 * dt;
if (keys.has("arrowdown")) player.pitch -= 1.2 * dt;
player.pitch = clamp(player.pitch, -1.3, 1.3);
updateCameraFromLook();
const forwardInput = (keys.has("w") ? 1 : 0) - (keys.has("s") ? 1 : 0);
const rightInput = (keys.has("d") ? 1 : 0) - (keys.has("a") ? 1 : 0);
const forward = camera.getWorldDirection(V());
forward.addScaledVector(player.gravity, -forward.dot(player.gravity));
if (forward.lengthSq() < 0.0001) forward.copy(FORWARD_AXIS);
forward.normalize();
const right = V().setFromMatrixColumn(camera.matrix, 0);
right.addScaledVector(player.gravity, -right.dot(player.gravity));
if (right.lengthSq() < 0.0001) right.set(1, 0, 0);
right.normalize();
const desired = forward.multiplyScalar(forwardInput).addScaledVector(right, rightInput);
if (desired.lengthSq() > 1) desired.normalize();
desired.multiplyScalar(3.25);
player.velocity.lerp(desired, 1 - Math.exp(-10 * dt));
player.position.addScaledVector(player.velocity, dt);
if (player.zone === "gallery") {
player.position.y = 1.65;
if (player.position.z < -9.12) {
player.position.z = -9.12;
if (Math.abs(player.position.x) < 2.2 && $("previewPanel").hidden) openPreview("A");
} else {
player.position.z = Math.max(player.position.z, -9.12);
}
if (player.position.x > 9.12) {
player.position.x = 9.12;
if (Math.abs(player.position.z) < 2.2 && $("previewPanel").hidden) openPreview("B");
} else {
player.position.x = Math.min(player.position.x, 9.12);
}
if (player.position.x < -9.12) {
player.position.x = -9.12;
if (Math.abs(player.position.z) < 2.2 && $("previewPanel").hidden) openPreview("C");
} else {
player.position.x = Math.max(player.position.x, -9.12);
}
player.position.z = Math.min(player.position.z, 9.12);
} else if (player.zone === "A") {
player.position.y = 1.65;
player.position.x = clamp(player.position.x, -7.25, 7.25);
player.position.z = clamp(player.position.z, -24.2, -10.85);
if (player.position.z > -11.05 && Math.abs(player.position.x) < 2.2 && $("previewPanel").hidden) {
openPreview("A", "return");
}
} else if (player.zone === "B") {
player.position.x += player.gravity.x * 5.2 * dt;
player.position.x = Math.min(player.position.x, 16.35);
player.position.x = Math.max(player.position.x, 10.7);
player.position.y = clamp(player.position.y, 0.75, 6.25);
player.position.z = clamp(player.position.z, -7.25, 7.25);
} else if (player.zone === "C") {
player.position.y += player.gravity.y * 5.2 * dt;
player.position.y = Math.min(player.position.y, 4.35);
player.position.y = Math.max(player.position.y, 1.05);
player.position.x = clamp(player.position.x, -17.25, -10.65);
player.position.z = clamp(player.position.z, -7.25, 7.25);
}
}
function updateContextPrompt() {
let message = "";
if (transition) {
message = "TRANSIT IN PROGRESS // TARGET VECTOR LOCKING";
} else if (player.zone === "gallery") {
const near = nearestGalleryDoor();
if (near) {
message = `DOOR ${chamberData[near].number} // ${chamberData[near].name} // [E] INSPECT`;
} else {
message = `SELECTED ${chamberData[selectedChamber].number} ${chamberData[selectedChamber].name} // [E] PREVIEW // [ENTER] COMMIT`;
}
} else {
const chamber = chamberData[player.zone];
message = `${chamber.name} // ${chamber.rule} // [R] PREVIEW RETURN`;
}
if ($("contextPrompt").textContent !== message) $("contextPrompt").textContent = message;
}
function updateDoors(dt) {
for (const id of ["A", "B", "C"]) {
const door = doors[id];
door.openAmount += (door.openTarget - door.openAmount) * (1 - Math.exp(-5.5 * dt));
door.left.position.x = -1.07 - door.openAmount * 2.05;
door.right.position.x = 1.07 + door.openAmount * 2.05;
if (!(transition && transition.doorId === id)) {
applyGravityVisual(door, door.chamber.gravity);
}
const pulse = door.selected ? 1 + Math.sin(performance.now() * 0.0045) * 0.075 : 1;
door.arrow.scale.setScalar(pulse);
door.keel.scale.setScalar(pulse);
}
}
function updateWorld(dt) {
galleryOrrery.rotation.y += dt * 0.18;
galleryOrrery.rotation.x = Math.sin(performance.now() * 0.00035) * 0.12;
chamberOrrery.rotation.z += dt * 0.28;
particleMesh.rotation.y -= dt * 0.018;
particleMesh.position.y = Math.sin(performance.now() * 0.00035) * 0.12;
}
document.querySelectorAll(".chamber-card").forEach((card) => {
card.addEventListener("click", () => selectChamber(card.dataset.chamber));
});
$("closePreview").addEventListener("click", closePreview);
$("replayPreview").addEventListener("click", playPreviewMotion);
$("commitPreview").addEventListener("click", commitPreview);
$("returnButton").addEventListener("click", openReturnPreview);
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 || transition) return;
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId || transition) return;
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
player.yaw -= deltaX * 0.0032;
player.pitch -= deltaY * 0.0028;
player.pitch = clamp(player.pitch, -1.3, 1.3);
});
function endPointer(event) {
if (!dragging || event.pointerId !== pointerId) return;
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
pointerId = null;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (["w", "a", "s", "d", "arrowup", "arrowdown", "arrowleft", "arrowright", " ", "enter", "escape"].includes(key)) {
event.preventDefault();
}
keys.add(key);
if (event.repeat || transition) return;
if (key === "1") selectChamber("A");
else if (key === "2") selectChamber("B");
else if (key === "3") selectChamber("C");
else if (key === "e") {
if (player.zone === "gallery") {
const near = nearestGalleryDoor();
openPreview(near || selectedChamber);
} else {
openReturnPreview();
}
} else if (key === "r") {
openReturnPreview();
} else if (key === "enter") {
commitPreview();
} else if (key === "escape") {
closePreview();
}
});
window.addEventListener("keyup", (event) => {
keys.delete(event.key.toLowerCase());
});
window.addEventListener("blur", () => {
keys.clear();
dragging = false;
canvas.classList.remove("dragging");
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio || 1, 1.75));
});
updateCameraFromLook();
updateTelemetry();
selectChamber("A");
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (transition) updateTransition(dt);
else updateMovement(dt);
updateDoors(dt);
updateWorld(dt);
updateContextPrompt();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```