Prompt specification
Build or customize the Three.js 3D scene "Shadow Garden Door 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: Shadow Garden Door Puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shadow-garden-door-puzzle-x3499
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: shadow garden door puzzle. Build an original garden with movable geometric sculptures and a light pedestal. Use a simple projection-based matching rule to unlock a clearly fictional door. Return one self-contained HTML file.
Working Three.js Starter (shadow-garden-door-puzzle-x3499):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shadow Garden — The Morrowleaf Triune</title>
<style>
:root {
color-scheme: dark;
--ink: #e7fff8;
--muted: #91aaa6;
--cyan: #70f6da;
--gold: #ffd28a;
--panel: rgba(8, 20, 24, 0.82);
--line: rgba(132, 255, 226, 0.19);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071218;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
touch-action: none;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.topbar {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 24px;
}
.brand {
max-width: 430px;
padding: 16px 19px 17px;
border: 1px solid var(--line);
border-left: 3px solid var(--cyan);
background:
linear-gradient(110deg, rgba(16, 37, 39, 0.92), rgba(7, 18, 23, 0.68));
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.28em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 2px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 39px);
font-weight: 500;
letter-spacing: -0.025em;
}
.subtitle {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.rules {
width: min(350px, 34vw);
padding: 15px 17px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.22);
}
.rules strong {
display: block;
margin-bottom: 7px;
color: var(--gold);
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.rules p {
margin: 0;
color: #b9cbc7;
font-size: 12px;
line-height: 1.55;
}
.rules .fine {
margin-top: 8px;
color: #718b86;
font-size: 10px;
}
.dock {
position: absolute;
left: 50%;
bottom: 22px;
width: min(920px, calc(100vw - 36px));
transform: translateX(-50%);
display: grid;
grid-template-columns: minmax(175px, 1fr) auto minmax(210px, 1fr);
align-items: center;
gap: 17px;
padding: 13px 15px;
pointer-events: auto;
border: 1px solid var(--line);
background:
linear-gradient(105deg, rgba(11, 28, 31, 0.94), rgba(6, 16, 21, 0.9));
box-shadow: 0 20px 65px rgba(0, 0, 0, 0.45), inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px);
}
.selected-block {
min-width: 0;
}
.mini-label {
color: #6f8d87;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
#selectedName {
display: block;
overflow: hidden;
margin-top: 4px;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
text-overflow: ellipsis;
white-space: nowrap;
}
#selectedDetail {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.actions {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 6px;
}
button {
min-height: 34px;
padding: 8px 11px;
border: 1px solid rgba(133, 226, 207, 0.2);
border-radius: 2px;
color: #d6eee8;
background: rgba(112, 246, 218, 0.055);
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
transition: 150ms ease;
}
button:hover {
border-color: rgba(112, 246, 218, 0.65);
color: #fff;
background: rgba(112, 246, 218, 0.12);
transform: translateY(-1px);
}
button:active { transform: translateY(0); }
button:disabled {
cursor: default;
opacity: 0.35;
transform: none;
}
button.primary {
border-color: rgba(255, 210, 138, 0.42);
color: var(--gold);
background: rgba(255, 210, 138, 0.08);
}
.progress-block {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px 12px;
align-items: center;
}
.pips {
display: flex;
gap: 6px;
}
.pip {
width: 27px;
height: 5px;
border: 1px solid rgba(115, 185, 171, 0.28);
background: rgba(115, 185, 171, 0.08);
transition: 250ms ease;
}
.pip.matched {
border-color: var(--cyan);
background: var(--cyan);
box-shadow: 0 0 13px rgba(112, 246, 218, 0.8);
}
#progressText {
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
#stationStates {
grid-column: 1 / -1;
display: flex;
justify-content: space-between;
gap: 8px;
color: #829b96;
font-size: 9px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.station-state.matched { color: var(--cyan); }
.station-state.wrong { color: #e7b676; }
.hint {
position: absolute;
left: 50%;
bottom: 128px;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(118, 193, 177, 0.12);
color: #77948e;
background: rgba(5, 15, 19, 0.56);
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
white-space: nowrap;
}
.toast {
position: absolute;
top: 50%;
left: 50%;
width: min(470px, calc(100vw - 36px));
padding: 28px 30px;
transform: translate(-50%, -45%) scale(0.96);
opacity: 0;
pointer-events: none;
text-align: center;
border: 1px solid rgba(255, 210, 138, 0.4);
background:
radial-gradient(circle at top, rgba(255, 210, 138, 0.13), transparent 60%),
rgba(7, 18, 22, 0.94);
box-shadow: 0 30px 100px rgba(0, 0, 0, 0.58), 0 0 50px rgba(112, 246, 218, 0.08);
backdrop-filter: blur(18px);
transition: 500ms cubic-bezier(.2,.8,.2,1);
}
.toast.show {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
.toast .seal {
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.3em;
text-transform: uppercase;
}
.toast h2 {
margin: 10px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
font-weight: 500;
}
.toast p {
margin: 0;
color: #aac0ba;
font-size: 12px;
line-height: 1.6;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #9cc9c0;
background: #071218;
font-size: 11px;
letter-spacing: 0.25em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.topbar { top: 12px; left: 12px; right: 12px; }
.brand { max-width: 310px; padding: 12px 14px; }
.rules { display: none; }
.dock {
bottom: 10px;
width: calc(100vw - 20px);
grid-template-columns: 1fr;
gap: 9px;
padding: 10px;
}
.selected-block { display: flex; align-items: baseline; gap: 8px; }
#selectedName { font-size: 17px; }
#selectedDetail { margin-left: auto; }
.actions { justify-content: flex-start; }
button { min-height: 32px; padding: 7px 9px; }
.hint { display: none; }
#stationStates { display: none; }
.progress-block { grid-template-columns: 1fr auto; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel shadow garden puzzle"></div>
<div class="hud">
<div class="topbar">
<section class="brand">
<div class="eyebrow">Shadow Garden</div>
<h1>The Morrowleaf Triune</h1>
<p class="subtitle">A fictional threshold that opens only for three remembered shadows.</p>
</section>
<aside class="rules">
<strong>Projection matching</strong>
<p>
Each brass socket sends one geometric silhouette to the matching etched panel.
Match both the <em>form</em> and its <em>quarter-turn</em>.
</p>
<p class="fine">
Drag sculptures between sockets, or use the controls below. Drag empty space to orbit;
scroll to zoom. Keys: 1–3 move · Q/R rotate · Tab cycles.
</p>
</aside>
</div>
<div class="hint">Select a sculpture, then match its cast shadow to the luminous etching.</div>
<section class="dock" aria-label="Puzzle controls">
<div class="selected-block">
<span class="mini-label">Selected sculpture</span>
<strong id="selectedName">Toll</strong>
<span id="selectedDetail">Quarter-turn 0°</span>
</div>
<div class="actions">
<button id="moveLeft" title="Move selected sculpture to the left socket">← Left</button>
<button id="moveCenter" title="Move selected sculpture to the center socket">◇ Center</button>
<button id="moveRight" title="Move selected sculpture to the right socket">Right →</button>
<button id="rotateCCW" title="Rotate counterclockwise">↶ Turn</button>
<button id="rotateCW" class="primary" title="Rotate clockwise">Turn ↷</button>
<button id="reset" title="Reset the puzzle">Reset</button>
</div>
<div class="progress-block">
<div class="pips" aria-hidden="true">
<span class="pip" id="pip0"></span>
<span class="pip" id="pip1"></span>
<span class="pip" id="pip2"></span>
</div>
<span id="progressText">0 / 3 echoes aligned</span>
<div id="stationStates">
<span class="station-state" id="state0">I · waiting</span>
<span class="station-state" id="state1">II · waiting</span>
<span class="station-state" id="state2">III · waiting</span>
</div>
</div>
</section>
<div class="toast" id="toast" role="status" aria-live="polite">
<div class="seal">The seal remembers</div>
<h2 id="toastTitle">The garden awakens.</h2>
<p id="toastText">The Morrowleaf Triune has opened.</p>
</div>
</div>
<div id="loading">Growing the shadow garden…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07151b);
scene.fog = new THREE.FogExp2(0x07151b, 0.0145);
const camera = new THREE.PerspectiveCamera(42, window.innerWidth / window.innerHeight, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.8, -2.8);
const cameraState = { yaw: 0.32, pitch: 0.43, radius: 20.5 };
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * Math.cos(pitch) * radius,
cameraTarget.y + Math.sin(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * Math.cos(pitch) * radius
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xa7e9ff, 0x1c3324, 1.55);
scene.add(hemi);
const moonLight = new THREE.DirectionalLight(0xc9e5ff, 2.0);
moonLight.position.set(8, 15, 8);
moonLight.castShadow = true;
moonLight.shadow.mapSize.set(2048, 2048);
moonLight.shadow.camera.left = -15;
moonLight.shadow.camera.right = 15;
moonLight.shadow.camera.top = 15;
moonLight.shadow.camera.bottom = -15;
moonLight.shadow.camera.near = 1;
moonLight.shadow.camera.far = 40;
moonLight.shadow.bias = -0.0003;
scene.add(moonLight);
const warmFill = new THREE.DirectionalLight(0xffc47f, 0.65);
warmFill.position.set(-10, 7, 4);
scene.add(warmFill);
function standard(color, roughness = 0.82, metalness = 0.0) {
return new THREE.MeshStandardMaterial({ color, roughness, metalness });
}
function box(w, h, d, material, x = 0, y = 0, z = 0, cast = true, receive = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
let seed = 9137;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const stonePalette = [0x41565a, 0x4a5e5f, 0x35494e, 0x526467, 0x3e5255];
const stoneMats = stonePalette.map(c => standard(c, 0.96));
const grassMats = [0x26483b, 0x2d5141, 0x315644, 0x294a3d].map(c => standard(c, 1));
const soilMat = standard(0x3d3024, 1);
const darkSoilMat = standard(0x211d19, 1);
const woodMat = standard(0x654635, 0.95);
const leafMats = [0x315a46, 0x3c6a50, 0x294e3d, 0x456f54].map(c => standard(c, 1));
const brassMat = standard(0xa8894c, 0.34, 0.72);
const cyanMat = standard(0x76f6db, 0.28, 0.25);
cyanMat.emissive = new THREE.Color(0x38e8cf);
cyanMat.emissiveIntensity = 1.4;
// Grounded voxel field.
box(25, 0.32, 27, standard(0x152a25, 1), 0, -0.24, -0.5, false, true);
const tileGeo = new THREE.BoxGeometry(1.015, 0.12, 1.015);
const tileMat = standard(0xffffff, 1);
const tileMesh = new THREE.InstancedMesh(tileGeo, tileMat, 18 * 18);
tileMesh.receiveShadow = true;
const tileMatrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let iz = 0; iz < 18; iz++) {
for (let ix = 0; ix < 18; ix++) {
tileMatrix.makeTranslation(-8.925 + ix * 1.05, -0.055, -8.925 + iz * 1.05);
tileMesh.setMatrixAt(tileIndex, tileMatrix);
tileColor.setHex(grassMats[Math.floor(random() * grassMats.length)].color.getHex());
tileColor.offsetHSL(0, 0, (random() - 0.5) * 0.035);
tileMesh.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tileMesh.instanceMatrix.needsUpdate = true;
tileMesh.instanceColor.needsUpdate = true;
scene.add(tileMesh);
// Stepping-stone path from the threshold to the light pedestal.
const pathMat = standard(0x66706a, 0.96);
const pathSideMat = standard(0x364744, 1);
for (let i = 0; i < 13; i++) {
const z = -8.0 + i * 1.02;
const width = i > 8 ? 2.2 : 1.65;
box(width, 0.16, 0.72, pathMat, (i % 2 ? 0.06 : -0.05), 0.12, z, false, true);
box(width + 0.14, 0.08, 0.52, pathSideMat, 0, 0.055, z, false, true);
}
// Raised beds.
function planter(x, z, w, d) {
box(w, 0.38, d, woodMat, x, 0.2, z);
box(w - 0.18, 0.12, d - 0.18, darkSoilMat, x, 0.43, z, false, true);
const border = standard(0x8b6243, 0.9);
box(w, 0.22, 0.15, border, x, 0.5, z - d / 2 + 0.06);
box(w, 0.22, 0.15, border, x, 0.5, z + d / 2 - 0.06);
}
planter(-6.6, -3.8, 3.1, 2.0);
planter(6.6, -3.8, 3.1, 2.0);
planter(-7.1, 4.7, 2.2, 4.0);
planter(7.1, 4.7, 2.2, 4.0);
// Small rill of dark water.
const waterMat = new THREE.MeshStandardMaterial({
color: 0x195568,
roughness: 0.22,
metalness: 0.18,
transparent: true,
opacity: 0.86,
emissive: 0x082833,
emissiveIntensity: 0.55
});
box(2.6, 0.13, 5.2, standard(0x263b3a, 1), -7.15, 0.1, 2.25, false, true);
const water = box(2.18, 0.08, 4.8, waterMat, -7.15, 0.2, 2.25, false, false);
for (let i = 0; i < 10; i++) {
const z = 0.05 + i * 0.48;
box(0.28, 0.13, 0.25, standard(0x6f7770, 0.95), -7.15 + (i % 2 ? 0.55 : -0.55), 0.27, z);
}
function tree(x, z, scale = 1, hue = 0) {
const trunk = box(0.48 * scale, 2.25 * scale, 0.48 * scale, woodMat, x, 1.13 * scale, z);
const clusters = [
[-0.55, 2.35, 0.05, 1.55], [0.48, 2.5, 0.12, 1.8],
[0.0, 3.0, -0.1, 1.55], [-0.25, 2.72, 0.75, 1.3],
[0.45, 3.18, -0.45, 1.25]
];
clusters.forEach((c, i) => {
const m = leafMats[(i + hue) % leafMats.length];
box(c[3] * scale, c[3] * scale, c[3] * scale, m,
x + c[0] * scale, c[1] * scale, z + c[2] * scale);
});
return trunk;
}
tree(-7.7, -6.3, 1.05, 0);
tree(7.7, -6.3, 1.05, 1);
tree(-9.3, 5.7, 0.85, 2);
tree(9.2, 5.7, 0.9, 3);
// Block hedges.
const hedgeMat = standard(0x244b39, 1);
for (let i = 0; i < 8; i++) {
box(0.74, 0.65 + (i % 3) * 0.09, 0.74, hedgeMat, -3.7, 0.43, -5.9 + i * 0.74);
box(0.74, 0.65 + ((i + 1) % 3) * 0.09, 0.74, hedgeMat, 3.7, 0.43, -5.9 + i * 0.74);
}
// Pixel flowers.
const stemGeo = new THREE.BoxGeometry(0.055, 0.42, 0.055);
const bloomGeo = new THREE.BoxGeometry(0.2, 0.2, 0.2);
const stemMesh = new THREE.InstancedMesh(stemGeo, standard(0x3b7452, 1), 72);
const bloomMesh = new THREE.InstancedMesh(bloomGeo, standard(0xffffff, 0.8), 72);
const flowerColors = [0xf4a95d, 0xec7da1, 0xa88bea, 0xbfea83, 0x70dce8];
const m4 = new THREE.Matrix4();
for (let i = 0; i < 72; i++) {
const side = i % 2 ? 1 : -1;
const x = side * (5.35 + random() * 1.5);
const z = -5.0 + random() * 10.5;
const y = 0.45;
m4.makeTranslation(x, y + 0.21, z);
stemMesh.setMatrixAt(i, m4);
m4.makeTranslation(x, y + 0.46, z);
bloomMesh.setMatrixAt(i, m4);
bloomMesh.setColorAt(i, new THREE.Color(flowerColors[i % flowerColors.length]));
}
stemMesh.instanceMatrix.needsUpdate = true;
bloomMesh.instanceMatrix.needsUpdate = true;
bloomMesh.instanceColor.needsUpdate = true;
scene.add(stemMesh, bloomMesh);
// The rear wall is built from individual voxel stones around a sealed opening.
for (let row = 0; row < 8; row++) {
const y = 0.4 + row * 0.78;
for (let col = 0; col < 16; col++) {
const x = -11.25 + col * 1.5 + (row % 2 ? 0.16 : 0);
const overlapsDoor = Math.abs(x) < 3.05 && y < 5.55;
if (overlapsDoor) continue;
const mat = stoneMats[Math.floor(random() * stoneMats.length)];
box(1.42, 0.71, 0.9, mat, x, y, -9.85);
}
}
// Side returns and a heavy lintel.
box(1.1, 6.3, 3.6, stoneMats[1], -11.65, 3.1, -8.15);
box(1.1, 6.3, 3.6, stoneMats[1], 11.65, 3.1, -8.15);
const frameMat = standard(0x64706b, 0.9);
box(0.62, 5.7, 1.2, frameMat, -2.88, 2.85, -9.5);
box(0.62, 5.7, 1.2, frameMat, 2.88, 2.85, -9.5);
box(6.35, 0.68, 1.25, frameMat, 0, 5.72, -9.5);
box(5.65, 0.28, 1.35, standard(0x394b4c, 0.95), 0, 6.18, -9.5);
// Portal behind the triune panels.
const portalGroup = new THREE.Group();
portalGroup.position.set(0, 0, -10.05);
scene.add(portalGroup);
const portalBack = new THREE.Mesh(
new THREE.PlaneGeometry(5.25, 5.45),
new THREE.MeshBasicMaterial({ color: 0x061c29 })
);
portalBack.position.y = 2.68;
portalGroup.add(portalBack);
const portalGlow = new THREE.Mesh(
new THREE.PlaneGeometry(5.1, 5.3),
new THREE.MeshBasicMaterial({
color: 0x58e8d2,
transparent: true,
opacity: 0.035,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
portalGlow.position.set(0, 2.68, 0.025);
portalGroup.add(portalGlow);
const portalStarsPositions = [];
for (let i = 0; i < 145; i++) {
portalStarsPositions.push(
(random() - 0.5) * 5.0,
0.1 + random() * 5.1,
0.08 + random() * 0.12
);
}
const portalStarsGeo = new THREE.BufferGeometry();
portalStarsGeo.setAttribute("position", new THREE.Float32BufferAttribute(portalStarsPositions, 3));
const portalStarsMat = new THREE.PointsMaterial({
color: 0xbaffed,
size: 0.055,
transparent: true,
opacity: 0.75,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const portalStars = new THREE.Points(portalStarsGeo, portalStarsMat);
portalGroup.add(portalStars);
const portalLight = new THREE.PointLight(0x58f6dc, 7, 12, 2);
portalLight.position.set(0, 2.8, -8.9);
scene.add(portalLight);
// A pool of light behind the fictional archive.
for (let i = 0; i < 3; i++) {
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-2.48 + i * 0.16, 0.12, 0.02),
new THREE.Vector3(2.48 - i * 0.16, 0.12, 0.02)
]),
new THREE.LineBasicMaterial({ color: 0x67f7dd, transparent: true, opacity: 0.45 })
);
line.position.y = 2.68 - i * 0.65;
portalGroup.add(line);
}
// Canvas labels are generated locally; no external assets are used.
function makeLabel(text, subtext = "", width = 2.8) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(5,18,22,0.82)";
ctx.strokeStyle = "rgba(112,246,218,0.42)";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.roundRect(8, 8, 752, 176, 14);
ctx.fill();
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = "#d9fff6";
ctx.font = "700 46px Georgia";
ctx.fillText(text, 384, subtext ? 82 : 110);
if (subtext) {
ctx.fillStyle = "#7ea79f";
ctx.font = "700 22px sans-serif";
ctx.letterSpacing = "4px";
ctx.fillText(subtext, 384, 132);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
return sprite;
}
const archiveLabel = makeLabel("MORROWLEAF TRIUNE", "ARCHIVE OF UNMADE SHADOWS", 5.2);
archiveLabel.position.set(0, 6.75, -9.05);
scene.add(archiveLabel);
// Light pedestal.
const pedestal = new THREE.Group();
pedestal.position.set(0, 0, 5.25);
scene.add(pedestal);
function localBox(group, w, h, d, mat, x, y, z, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
localBox(pedestal, 2.5, 0.28, 2.5, standard(0x334745, 0.95), 0, 0.14, 0);
localBox(pedestal, 1.85, 0.28, 1.85, standard(0x52605a, 0.88), 0, 0.4, 0);
localBox(pedestal, 0.58, 1.72, 0.58, brassMat, 0, 1.35, 0);
localBox(pedestal, 1.22, 0.22, 1.22, brassMat, 0, 2.28, 0);
localBox(pedestal, 0.84, 0.18, 0.84, standard(0x243d3e, 0.6, 0.4), 0, 2.47, 0);
const crystal = new THREE.Mesh(
new THREE.OctahedronGeometry(0.56, 0),
new THREE.MeshStandardMaterial({
color: 0xaaffed,
emissive: 0x42f3d2,
emissiveIntensity: 2.3,
roughness: 0.22,
metalness: 0.15
})
);
crystal.position.y = 2.95;
crystal.castShadow = true;
pedestal.add(crystal);
const pedestalLight = new THREE.PointLight(0x66ffe1, 18, 9, 2);
pedestalLight.position.set(0, 2.9, 0);
pedestal.add(pedestalLight);
const spot = new THREE.SpotLight(0x9affeb, 120, 30, 0.56, 0.72, 1.6);
spot.position.set(0, 2.95, 5.25);
spot.target.position.set(0, 3.0, -9.2);
scene.add(spot, spot.target);
// Broad transparent projection cone.
const source = new THREE.Vector3(0, 2.95, 5.25);
const beamEnd = new THREE.Vector3(0, 3.0, -9.25);
const beamVector = new THREE.Vector3().subVectors(beamEnd, source);
const beamLength = beamVector.length();
const beam = new THREE.Mesh(
new THREE.ConeGeometry(3.8, beamLength, 4, 1, true),
new THREE.MeshBasicMaterial({
color: 0x61f5dc,
transparent: true,
opacity: 0.025,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
beam.position.copy(source).add(beamEnd).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), beamVector.clone().normalize());
scene.add(beam);
// Projection sockets.
const stationPositions = [
new THREE.Vector3(-3.2, 1.43, -0.45),
new THREE.Vector3(0, 1.43, -0.45),
new THREE.Vector3(3.2, 1.43, -0.45)
];
const stationNames = ["I · MOON", "II · SEED", "III · SUN"];
stationPositions.forEach((p, i) => {
const base = box(1.48, 0.48, 1.48, stoneMats[1], p.x, 0.25, p.z);
const top = box(1.16, 0.15, 1.16, brassMat, p.x, 0.56, p.z);
top.castShadow = false;
const socket = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.055, 6, 24),
cyanMat
);
socket.rotation.x = Math.PI / 2;
socket.position.set(p.x, 0.68, p.z);
scene.add(socket);
const label = makeLabel(stationNames[i], "", 1.7);
label.position.set(p.x, 0.92, 0.43);
scene.add(label);
});
// Three slim rays visually connect the pedestal to the triune panels.
const panelXs = [-1.65, 0, 1.65];
panelXs.forEach((x) => {
const geometry = new THREE.BufferGeometry().setFromPoints([
source.clone(),
new THREE.Vector3(x, 3.2, -9.05)
]);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color: 0x74ffe2, transparent: true, opacity: 0.14 })
);
scene.add(line);
});
// Polygon silhouettes used for both the etched target and projected shadow.
const glyphPolygons = {
delta: [
[-1.5, -1.5], [1.5, -1.5], [1.5, -0.5], [0.5, -0.5],
[0.5, 0.5], [-0.5, 0.5], [-0.5, 1.5], [-1.5, 1.5], [-1.5, -1.5]
],
toll: [
[-1.5, 1.5], [1.5, 1.5], [1.5, 0.5], [0.5, 0.5],
[0.5, -1.5], [-0.5, -1.5], [-0.5, 0.5], [-1.5, 0.5], [-1.5, 1.5]
],
switch: [
[-1.5, 1.5], [0.5, 1.5], [0.5, 0.5], [1.5, 0.5],
[1.5, -1.5], [-0.5, -1.5], [-0.5, -0.5], [-1.5, -0.5], [-1.5, 1.5]
]
};
function shapeFrom(type) {
const shape = new THREE.Shape();
const points = glyphPolygons[type];
shape.moveTo(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) shape.lineTo(points[i][0], points[i][1]);
shape.closePath();
return shape;
}
function glyphGeometry(type) {
return new THREE.ShapeGeometry(shapeFrom(type));
}
function outlineGeometry(type) {
const points = glyphPolygons[type].map(p => new THREE.Vector3(p[0], p[1], 0));
return new THREE.BufferGeometry().setFromPoints(points);
}
const targetData = [
{ type: "switch", rot: 1 },
{ type: "delta", rot: 3 },
{ type: "toll", rot: 0 }
];
const panels = [];
targetData.forEach((target, i) => {
const group = new THREE.Group();
group.position.set(panelXs[i], 0, -9.35);
scene.add(group);
const panelMat = new THREE.MeshStandardMaterial({
color: 0x183638,
roughness: 0.64,
metalness: 0.18,
emissive: 0x061b1c,
emissiveIntensity: 0.65
});
const slab = new THREE.Mesh(new THREE.BoxGeometry(1.61, 5.28, 0.42), panelMat);
slab.position.y = 2.68;
slab.castShadow = true;
slab.receiveShadow = true;
group.add(slab);
const borderMat = standard(0x6b775e, 0.6, 0.38);
localBox(group, 0.11, 5.05, 0.12, borderMat, -0.71, 2.68, 0.27);
localBox(group, 0.11, 5.05, 0.12, borderMat, 0.71, 2.68, 0.27);
localBox(group, 1.53, 0.11, 0.12, borderMat, 0, 0.27, 0.27);
localBox(group, 1.53, 0.11, 0.12, borderMat, 0, 5.09, 0.27);
// Brass rivets and a small invented serial mark.
for (const y of [0.58, 2.68, 4.78]) {
for (const x of [-0.62, 0.62]) {
localBox(group, 0.1, 0.1, 0.08, brassMat, x, y, 0.34, false);
}
}
const targetFill = new THREE.Mesh(
glyphGeometry(target.type),
new THREE.MeshBasicMaterial({
color: 0x65ffe0,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
targetFill.position.set(0, 3.23, 0.255);
targetFill.scale.setScalar(0.44);
targetFill.rotation.z = target.rot * Math.PI / 2;
group.add(targetFill);
const outlineMat = new THREE.LineDashedMaterial({
color: 0x7dffe5,
transparent: true,
opacity: 0.95,
dashSize: 0.14,
gapSize: 0.075,
depthWrite: false
});
const outline = new THREE.Line(outlineGeometry(target.type), outlineMat);
outline.position.set(0, 3.23, 0.285);
outline.scale.setScalar(0.44);
outline.rotation.z = target.rot * Math.PI / 2;
outline.computeLineDistances();
group.add(outline);
const shadow = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshBasicMaterial({
color: 0x041012,
transparent: true,
opacity: 0.79,
depthWrite: false
})
);
shadow.position.set(0, 3.23, 0.268);
shadow.scale.setScalar(0.44);
shadow.visible = false;
group.add(shadow);
panels.push({ group, panelMat, targetFill, outline, shadow, matched: false });
});
// Sculptures are voxel-cell silhouettes mounted on invisible planar pivots.
const glyphCells = {
delta: [[-1,-1],[0,-1],[1,-1],[-1,0],[0,0],[-1,1]],
toll: [[-1,1],[0,1],[1,1],[0,0],[0,-1]],
switch: [[-1,1],[0,1],[0,0],[1,0],[1,-1]]
};
const typeInfo = {
delta: {
name: "Delta",
color: 0x67d9cb,
light: 0xa1fff0,
cells: glyphCells.delta
},
toll: {
name: "Toll",
color: 0xeeb25d,
light: 0xffd992,
cells: glyphCells.toll
},
switch: {
name: "Switchback",
color: 0xb886e8,
light: 0xd9b9ff,
cells: glyphCells.switch
}
};
const sculptures = [];
const hitMeshes = [];
function makeSculpture(type, station, rotation = 0) {
const info = typeInfo[type];
const group = new THREE.Group();
group.position.copy(stationPositions[station]);
group.rotation.z = rotation * Math.PI / 2;
scene.add(group);
const sculpture = {
id: type,
type,
name: info.name,
group,
station,
rot: rotation
};
const blockGeo = new THREE.BoxGeometry(0.56, 0.56, 0.36);
const edgeGeo = new THREE.EdgesGeometry(blockGeo);
const baseMat = new THREE.MeshStandardMaterial({
color: info.color,
roughness: 0.48,
metalness: 0.28,
emissive: info.color,
emissiveIntensity: 0.12
});
info.cells.forEach((cell, index) => {
const mat = baseMat.clone();
mat.color.offsetHSL(0, 0, index % 2 ? 0.055 : -0.025);
const mesh = new THREE.Mesh(blockGeo, mat);
mesh.position.set(cell[0] * 0.59, cell[1] * 0.59, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const edge = new THREE.LineSegments(
edgeGeo,
new THREE.LineBasicMaterial({
color: info.light,
transparent: true,
opacity: 0.33
})
);
edge.position.copy(mesh.position);
group.add(edge);
});
const hit = new THREE.Mesh(
new THREE.BoxGeometry(2.05, 2.05, 0.65),
new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false })
);
hit.userData.sculpture = sculpture;
group.add(hit);
hitMeshes.push(hit);
const label = makeLabel(info.name.toUpperCase(), "", 1.45);
label.position.set(group.position.x, group.position.y + 1.4, group.position.z);
scene.add(label);
sculpture.label = label;
sculptures.push(sculpture);
return sculpture;
}
const delta = makeSculpture("delta", 2, 0);
const toll = makeSculpture("toll", 0, 0);
const switchback = makeSculpture("switch", 1, 0);
let stationOccupants = [toll, switchback, delta];
let selected = toll;
// Selection square around the current socket.
const selectionMat = new THREE.MeshBasicMaterial({
color: 0xffd28a,
transparent: true,
opacity: 0.9,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const selectionMarker = new THREE.Group();
selectionMarker.add(new THREE.Mesh(new THREE.BoxGeometry(1.55, 0.035, 0.065), selectionMat));
selectionMarker.add(new THREE.Mesh(new THREE.BoxGeometry(1.55, 0.035, 0.065), selectionMat));
selectionMarker.add(new THREE.Mesh(new THREE.BoxGeometry(0.065, 0.035, 1.55), selectionMat));
selectionMarker.add(new THREE.Mesh(new THREE.BoxGeometry(0.065, 0.035, 1.55), selectionMat));
selectionMarker.children[0].position.z = 0.77;
selectionMarker.children[1].position.z = -0.77;
selectionMarker.children[2].position.x = 0.77;
selectionMarker.children[3].position.x = -0.77;
selectionMarker.position.y = 0.7;
scene.add(selectionMarker);
// Fireflies and distant stars.
const fireflyPositions = [];
for (let i = 0; i < 120; i++) {
fireflyPositions.push(
(random() - 0.5) * 20,
0.5 + random() * 6,
-8 + random() * 17
);
}
const fireflyGeo = new THREE.BufferGeometry();
fireflyGeo.setAttribute("position", new THREE.Float32BufferAttribute(fireflyPositions, 3));
const fireflyMat = new THREE.PointsMaterial({
color: 0xc9ffd6,
size: 0.07,
transparent: true,
opacity: 0.8,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const fireflies = new THREE.Points(fireflyGeo, fireflyMat);
scene.add(fireflies);
const skyPositions = [];
for (let i = 0; i < 180; i++) {
const angle = random() * Math.PI * 2;
const radius = 25 + random() * 13;
skyPositions.push(
Math.cos(angle) * radius,
9 + random() * 15,
Math.sin(angle) * radius - 6
);
}
const skyGeo = new THREE.BufferGeometry();
skyGeo.setAttribute("position", new THREE.Float32BufferAttribute(skyPositions, 3));
scene.add(new THREE.Points(
skyGeo,
new THREE.PointsMaterial({ color: 0xb8e4ef, size: 0.09, transparent: true, opacity: 0.6 })
));
// Pixel clouds.
const cloudMat = new THREE.MeshBasicMaterial({ color: 0x35505a, transparent: true, opacity: 0.55 });
const clouds = [];
for (let c = 0; c < 5; c++) {
const group = new THREE.Group();
group.position.set(-14 + c * 7, 8.5 + random() * 3, -14 - random() * 8);
for (let i = 0; i < 6; i++) {
const m = new THREE.Mesh(new THREE.BoxGeometry(1.6, 0.7, 1.1), cloudMat);
m.position.set(i * 1.25 - 3.2, (i % 2) * 0.35, (i % 3) * 0.25);
group.add(m);
}
scene.add(group);
clouds.push(group);
}
const ui = {
selectedName: document.getElementById("selectedName"),
selectedDetail: document.getElementById("selectedDetail"),
progressText: document.getElementById("progressText"),
pips: [document.getElementById("pip0"), document.getElementById("pip1"), document.getElementById("pip2")],
states: [document.getElementById("state0"), document.getElementById("state1"), document.getElementById("state2")],
toast: document.getElementById("toast"),
toastTitle: document.getElementById("toastTitle"),
toastText: document.getElementById("toastText")
};
let unlocked = false;
let unlockStart = 0;
let toastTimer = 0;
let lastMatchedCount = 0;
function showToast(title, text, duration = 3600) {
ui.toastTitle.textContent = title;
ui.toastText.textContent = text;
ui.toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => ui.toast.classList.remove("show"), duration);
}
function updateSelectionUI() {
if (!selected) return;
ui.selectedName.textContent = selected.name;
ui.selectedDetail.textContent = `Quarter-turn ${selected.rot * 90}°`;
selectionMarker.position.x = selected.group.position.x;
selectionMarker.position.z = selected.group.position.z;
}
function selectSculpture(sculpture) {
selected = sculpture;
updateSelectionUI();
}
function setProjection(panelIndex) {
const panel = panels[panelIndex];
const occupant = stationOccupants[panelIndex];
const target = targetData[panelIndex];
if (occupant) {
if (panel.shadow.geometry) panel.shadow.geometry.dispose();
panel.shadow.geometry = glyphGeometry(occupant.type);
panel.shadow.rotation.z = occupant.rot * Math.PI / 2;
panel.shadow.visible = true;
} else {
panel.shadow.visible = false;
}
const correctType = occupant && occupant.type === target.type;
const correctTurn = occupant && occupant.rot === target.rot;
panel.matched = Boolean(correctType && correctTurn);
panel.outline.material.color.setHex(panel.matched ? 0xbaffdc : 0x7dffe5);
panel.outline.material.opacity = panel.matched ? 1 : 0.92;
panel.targetFill.material.opacity = panel.matched ? 0.17 : 0.075;
panel.panelMat.emissive.setHex(panel.matched ? 0x0b4035 : 0x061b1c);
panel.panelMat.emissiveIntensity = panel.matched ? 1.05 : 0.65;
}
function checkPuzzle(silent = false) {
panels.forEach((_, i) => setProjection(i));
const matchedCount = panels.filter(p => p.matched).length;
ui.pips.forEach((pip, i) => pip.classList.toggle("matched", panels[i].matched));
ui.progressText.textContent = matchedCount === 3
? "Triune aligned"
: `${matchedCount} / 3 echoes aligned`;
panels.forEach((panel, i) => {
const occupant = stationOccupants[i];
const el = ui.states[i];
el.classList.remove("matched", "wrong");
if (!occupant) {
el.textContent = ["I", "II", "III"][i] + " · waiting";
} else if (!panel.matched) {
el.classList.add("wrong");
el.textContent = ["I", "II", "III"][i] +
(occupant.type === targetData[i].type ? " · needs turn" : " · wrong form");
} else {
el.classList.add("matched");
el.textContent = ["I", "II", "III"][i] + " · aligned";
}
});
if (!unlocked && matchedCount === 3) {
unlocked = true;
unlockStart = performance.now();
showToast(
"The garden remembers.",
"The Morrowleaf Triune opens. It leads, as all fictional archives do, somewhere impossible.",
6500
);
} else if (!silent && matchedCount > lastMatchedCount && matchedCount < 3) {
showToast("An echo settles.", `${matchedCount} of three shadows now remember their shape.`, 1800);
}
lastMatchedCount = matchedCount;
}
function placeSculpture(sculpture, stationIndex) {
if (unlocked) return;
const oldStation = sculpture.station;
const other = stationOccupants[stationIndex];
if (other && other !== sculpture) {
other.station = oldStation;
stationOccupants[oldStation] = other;
other.group.position.copy(stationPositions[oldStation]);
}
stationOccupants[stationIndex] = sculpture;
sculpture.station = stationIndex;
sculpture.group.position.copy(stationPositions[stationIndex]);
sculpture.group.rotation.z = sculpture.rot * Math.PI / 2;
selectSculpture(sculpture);
checkPuzzle();
}
function rotateSelected(amount) {
if (unlocked || !selected) return;
selected.rot = (selected.rot + amount + 4) % 4;
selected.group.rotation.z = selected.rot * Math.PI / 2;
updateSelectionUI();
checkPuzzle();
}
document.getElementById("moveLeft").addEventListener("click", () => selected && placeSculpture(selected, 0));
document.getElementById("moveCenter").addEventListener("click", () => selected && placeSculpture(selected, 1));
document.getElementById("moveRight").addEventListener("click", () => selected && placeSculpture(selected, 2));
document.getElementById("rotateCCW").addEventListener("click", () => rotateSelected(3));
document.getElementById("rotateCW").addEventListener("click", () => rotateSelected(1));
document.getElementById("reset").addEventListener("click", () => {
unlocked = false;
unlockStart = 0;
lastMatchedCount = 0;
delta.station = 2;
toll.station = 0;
switchback.station = 1;
sculptures.forEach(s => {
s.rot = 0;
s.group.position.copy(stationPositions[s.station]);
s.group.rotation.z = 0;
});
stationOccupants = [toll, switchback, delta];
panels.forEach(p => p.group.position.y = 0);
selectSculpture(toll);
checkPuzzle(true);
showToast("Garden reset.", "The three forgotten silhouettes return to their first places.", 1900);
});
// Direct pointer controls implemented without external camera helpers.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -1.43);
const dragPoint = new THREE.Vector3();
let dragState = null;
let orbitState = null;
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
renderer.domElement.addEventListener("pointerdown", event => {
setPointer(event);
const hits = raycaster.intersectObjects(hitMeshes, false);
if (hits.length) {
const sculpture = hits[0].object.userData.sculpture;
selectSculpture(sculpture);
if (unlocked) return;
raycaster.ray.intersectPlane(dragPlane, dragPoint);
dragState = {
sculpture,
pointerId: event.pointerId,
offsetX: sculpture.group.position.x - dragPoint.x,
offsetZ: sculpture.group.position.z - dragPoint.z,
startX: event.clientX,
startY: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
} else {
orbitState = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (dragState && event.pointerId === dragState.pointerId) {
setPointer(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
const x = THREE.MathUtils.clamp(dragPoint.x + dragState.offsetX, -4.8, 4.8);
const z = THREE.MathUtils.clamp(dragPoint.z + dragState.offsetZ, -3.1, 3.8);
dragState.sculpture.group.position.set(x, 1.43, z);
selectionMarker.position.x = x;
selectionMarker.position.z = z;
dragState.sculpture.label.position.set(x, 2.83, z);
}
} else if (orbitState && event.pointerId === orbitState.pointerId) {
const dx = event.clientX - orbitState.x;
const dy = event.clientY - orbitState.y;
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.004, 0.23, 0.82);
orbitState.x = event.clientX;
orbitState.y = event.clientY;
updateCamera();
} else {
setPointer(event);
renderer.domElement.style.cursor = raycaster.intersectObjects(hitMeshes, false).length ? "grab" : "default";
}
});
function endPointer(event) {
if (dragState && event.pointerId === dragState.pointerId) {
const sculpture = dragState.sculpture;
let nearest = -1;
let nearestDistance = Infinity;
stationPositions.forEach((p, i) => {
const dx = sculpture.group.position.x - p.x;
const dz = sculpture.group.position.z - p.z;
const d = Math.sqrt(dx * dx + dz * dz);
if (d < nearestDistance) {
nearestDistance = d;
nearest = i;
}
});
if (nearest >= 0 && nearestDistance < 2.05) {
placeSculpture(sculpture, nearest);
} else {
sculpture.group.position.copy(stationPositions[sculpture.station]);
sculpture.label.position.set(
sculpture.group.position.x,
sculpture.group.position.y + 1.4,
sculpture.group.position.z
);
updateSelectionUI();
}
dragState = null;
renderer.domElement.style.cursor = "grab";
}
if (orbitState && event.pointerId === orbitState.pointerId) {
orbitState = null;
renderer.domElement.style.cursor = "default";
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
14,
29
);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "Tab") {
event.preventDefault();
const index = sculptures.indexOf(selected);
selectSculpture(sculptures[(index + 1) % sculptures.length]);
} else if (event.key === "1" && selected) {
placeSculpture(selected, 0);
} else if (event.key === "2" && selected) {
placeSculpture(selected, 1);
} else if (event.key === "3" && selected) {
placeSculpture(selected, 2);
} else if (event.key.toLowerCase() === "r") {
rotateSelected(1);
} else if (event.key.toLowerCase() === "q") {
rotateSelected(3);
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// Initial state and animation.
selectSculpture(toll);
checkPuzzle(true);
const clock = new THREE.Clock();
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
function animate(now) {
const time = clock.getElapsedTime();
crystal.rotation.y = time * 0.65;
crystal.rotation.x = Math.sin(time * 0.7) * 0.12;
crystal.position.y = 2.95 + Math.sin(time * 1.8) * 0.045;
portalStars.rotation.z = time * 0.012;
portalGlow.material.opacity = unlocked
? 0.13 + Math.sin(time * 2.1) * 0.035
: 0.035 + Math.sin(time * 1.2) * 0.009;
portalLight.intensity = unlocked ? 24 + Math.sin(time * 2) * 4 : 7;
portalStarsMat.opacity = unlocked ? 1 : 0.72;
selectionMat.opacity = 0.68 + Math.sin(time * 3.2) * 0.22;
selectionMarker.rotation.y = time * 0.25;
const fireflyPos = fireflyGeo.attributes.position;
for (let i = 0; i < fireflyPos.count; i++) {
const y = fireflyPos.getY(i);
fireflyPos.setY(i, y + Math.sin(time * 0.8 + i * 1.71) * 0.0008);
}
fireflyPos.needsUpdate = true;
fireflies.rotation.y = time * 0.012;
clouds.forEach((cloud, i) => {
cloud.position.x += 0.0009 * (i % 2 ? 1 : -1);
if (cloud.position.x > 17) cloud.position.x = -17;
if (cloud.position.x < -17) cloud.position.x = 17;
});
water.material.opacity = 0.8 + Math.sin(time * 0.8) * 0.035;
if (unlocked && unlockStart) {
const elapsed = (now - unlockStart) / 1000;
panels.forEach((panel, i) => {
const p = THREE.MathUtils.clamp((elapsed - i * 0.28) / 1.65, 0, 1);
panel.group.position.y = -5.58 * easeOutCubic(p);
});
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
document.getElementById("loading").classList.add("hide");
setTimeout(() => document.getElementById("loading").remove(), 600);
</script>
</body>
</html>
```