Prompt specification
Build or customize the Three.js 3D scene "Mountain Observatory Night Diorama" 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: Mountain Observatory Night Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mountain-observatory-night-diorama-x3795
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts an original observatory with a rotating dome opening aligned to a telescope. Use a synthetic star field and label the location and sky configuration fictional. Voxel style.
Working Three.js Starter (mountain-observatory-night-diorama-x3795):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vaelin Ridge Observatory</title>
<style>
:root {
--ink: #d8f5ee;
--muted: #8ca8a5;
--cyan: #65e4cf;
--amber: #f1b66d;
--panel: rgba(8, 18, 24, 0.82);
--line: rgba(123, 218, 201, 0.25);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 68% 18%, #182b3c 0%, #0a1520 36%, #04080e 100%);
color: var(--ink);
font-family: "Courier New", Courier, monospace;
}
body::before {
content: "";
position: fixed;
inset: 0;
z-index: 0;
pointer-events: none;
opacity: 0.16;
background-image:
linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
background-size: 4px 4px;
}
#app {
position: fixed;
inset: 0;
z-index: 1;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
image-rendering: pixelated;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
box-shadow: inset 0 0 150px 35px rgba(0, 0, 0, 0.62);
}
.hud {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow:
0 16px 50px rgba(0, 0, 0, 0.36),
inset 0 0 30px rgba(73, 167, 151, 0.035);
backdrop-filter: blur(12px);
}
.site-card {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 16px;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: bold;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 9px 0 5px;
font-size: clamp(20px, 3vw, 29px);
line-height: 1.05;
letter-spacing: 0.045em;
font-weight: 800;
}
.subtitle {
margin-bottom: 16px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.rule {
height: 1px;
margin: 0 0 13px;
background: linear-gradient(90deg, var(--cyan), transparent);
opacity: 0.55;
}
.metadata {
display: grid;
grid-template-columns: 92px 1fr;
gap: 7px 10px;
font-size: 11px;
line-height: 1.35;
}
.metadata dt {
color: var(--muted);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metadata dd {
margin: 0;
color: #c7ded8;
}
.fictional {
display: inline-block;
margin-left: 5px;
padding: 1px 5px;
border: 1px solid rgba(241, 182, 109, 0.5);
color: var(--amber);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
vertical-align: 1px;
}
.status-card {
position: absolute;
top: 22px;
right: 22px;
width: 248px;
padding: 15px 17px;
font-size: 11px;
}
.status-head {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 11px;
color: var(--cyan);
font-weight: bold;
letter-spacing: 0.12em;
}
.status-dot {
width: 8px;
height: 8px;
background: var(--cyan);
box-shadow: 0 0 13px var(--cyan);
}
.status-row {
display: flex;
justify-content: space-between;
gap: 15px;
margin-top: 7px;
color: var(--muted);
}
.status-row strong {
color: #d8f5ee;
font-weight: normal;
}
.locked {
margin-top: 13px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--cyan);
letter-spacing: 0.07em;
}
.sky-card {
position: absolute;
right: 22px;
top: 208px;
width: 248px;
padding: 15px 17px;
color: var(--muted);
font-size: 10px;
line-height: 1.6;
}
.sky-card strong {
display: block;
margin-bottom: 7px;
color: var(--ink);
font-size: 11px;
letter-spacing: 0.1em;
}
.sky-card span {
color: var(--cyan);
}
.controls {
position: absolute;
left: 50%;
bottom: 22px;
width: min(710px, calc(100vw - 44px));
padding: 14px 17px;
transform: translateX(-50%);
pointer-events: auto;
}
.control-grid {
display: grid;
grid-template-columns: 1fr 1fr auto auto auto;
align-items: end;
gap: 14px;
}
.control label {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control output {
color: var(--ink);
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 0;
background: linear-gradient(90deg, #376b67, #182c31);
outline: none;
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 13px;
height: 13px;
appearance: none;
border: 2px solid #071116;
border-radius: 0;
background: var(--cyan);
box-shadow: 0 0 12px rgba(101, 228, 207, 0.6);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid #071116;
border-radius: 0;
background: var(--cyan);
box-shadow: 0 0 12px rgba(101, 228, 207, 0.6);
}
button {
height: 31px;
padding: 0 11px;
border: 1px solid rgba(101, 228, 207, 0.4);
border-radius: 0;
background: rgba(17, 42, 44, 0.8);
color: var(--ink);
font: bold 10px "Courier New", Courier, monospace;
letter-spacing: 0.07em;
cursor: pointer;
white-space: nowrap;
}
button:hover {
border-color: var(--cyan);
background: rgba(40, 85, 80, 0.72);
}
button.active {
color: #06110e;
background: var(--cyan);
border-color: var(--cyan);
}
.hint {
margin-top: 11px;
color: #688481;
font-size: 9px;
letter-spacing: 0.08em;
text-align: center;
text-transform: uppercase;
}
@media (max-width: 760px) {
.site-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.status-card {
top: auto;
right: 12px;
bottom: 154px;
width: 208px;
padding: 11px 13px;
}
.sky-card {
display: none;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
.control-grid {
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.control-grid button {
width: 100%;
}
.hint {
font-size: 8px;
}
.subtitle {
margin-bottom: 10px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<div class="hud">
<section class="site-card panel">
<div class="eyebrow">Fictional Deep-Sky Outpost</div>
<h1>VAELIN RIDGE<br>OBSERVATORY</h1>
<div class="subtitle">Qora-9 / Southern-Facing Research Station</div>
<div class="rule"></div>
<dl class="metadata">
<dt>Location</dt>
<dd>
Vaelin Ridge, Qora-9
<span class="fictional">Fictional</span>
</dd>
<dt>Sky config</dt>
<dd>
DR-7 / Meridian 03
<span class="fictional">Synthetic</span>
</dd>
<dt>Optics</dt>
<dd>Voxel meridian refractor / 1.8 m equivalent</dd>
<dt>Source field</dt>
<dd>2,600 deterministic procedural stars</dd>
</dl>
</section>
<section class="status-card panel">
<div class="status-head">
<span class="status-dot"></span>
MOUNT LOCK
</div>
<div class="status-row">
<span>Dome bearing</span>
<strong id="domeBearing">022°</strong>
</div>
<div class="status-row">
<span>Telescope</span>
<strong id="scopeBearing">022°</strong>
</div>
<div class="status-row">
<span>Elevation</span>
<strong id="scopeElevation">28°</strong>
</div>
<div class="locked" id="lockStatus">
SLIT / OPTICAL AXIS CO-LOCKED
</div>
</section>
<section class="sky-card panel">
<strong>DR-7 MERIDIAN 03</strong>
Procedural celestial sphere<br>
<span>Lumen Kite</span> · RA 19.42 / DEC +08<br>
<span>Glass Sparrow</span> · RA 20.17 / DEC +16<br>
<span>Ash Crown</span> · RA 21.03 / DEC +03<br><br>
All locations, objects, and sky values are fictional.
</section>
<section class="controls panel">
<div class="control-grid">
<div class="control">
<label for="bearing">
Target bearing <output id="bearingValue">22°</output>
</label>
<input id="bearing" type="range" min="0" max="359" value="22">
</div>
<div class="control">
<label for="elevation">
Telescope elevation <output id="elevationValue">28°</output>
</label>
<input id="elevation" type="range" min="8" max="62" value="28">
</div>
<button id="autoButton" class="active">AUTO SWEEP ON</button>
<button id="pauseButton">PAUSE</button>
<button id="resetButton">RESET VIEW</button>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom · Dome and telescope remain co-aligned
</div>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const renderer = new THREE.WebGLRenderer({
antialias: false,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel observatory beneath a synthetic fictional sky"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(48, 1, 0.1, 180);
const cameraTarget = new THREE.Vector3(0, 2.85, 0);
const cameraState = {
radius: 18.5,
theta: 0.68,
phi: 1.22
};
const clock = new THREE.Clock();
// Deterministic random source so the fictional sky never changes.
function mulberry32(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 = mulberry32(904771);
function addBox(parent, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextTexture(text, color = "#83f3da") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(5, 15, 20, 0.92)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = color;
ctx.lineWidth = 6;
ctx.strokeRect(7, 7, canvas.width - 14, canvas.height - 14);
ctx.fillStyle = color;
ctx.font = "bold 53px Courier New";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function makeLabelSprite(text, width = 5, color = "#83f3da") {
const texture = makeTextTexture(text, color);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
fog: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 160 / 1024, 1);
return sprite;
}
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0x94b8d7, 0x172421, 1.6);
scene.add(hemisphere);
const moonlight = new THREE.DirectionalLight(0xbdd8ff, 3.1);
moonlight.position.set(-9, 18, 11);
moonlight.castShadow = true;
moonlight.shadow.mapSize.set(2048, 2048);
moonlight.shadow.camera.left = -18;
moonlight.shadow.camera.right = 18;
moonlight.shadow.camera.top = 18;
moonlight.shadow.camera.bottom = -18;
moonlight.shadow.camera.near = 1;
moonlight.shadow.camera.far = 55;
moonlight.shadow.bias = -0.0007;
scene.add(moonlight);
const interiorLight = new THREE.PointLight(0x74d8c4, 28, 10, 2);
interiorLight.position.set(0, 3.9, 0);
scene.add(interiorLight);
const warmBeacon = new THREE.PointLight(0xffa65c, 9, 6, 2);
warmBeacon.position.set(-4.7, 2.8, 1.8);
scene.add(warmBeacon);
// ------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0c181a,
roughness: 1,
metalness: 0
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x2c4142,
roughness: 0.88,
metalness: 0.08
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x17272c,
roughness: 0.65,
metalness: 0.55,
flatShading: true
});
const copper = new THREE.MeshStandardMaterial({
color: 0xb67a42,
roughness: 0.55,
metalness: 0.62,
flatShading: true
});
const tealMetal = new THREE.MeshStandardMaterial({
color: 0x3f8e88,
roughness: 0.5,
metalness: 0.48,
flatShading: true
});
const cyanGlow = new THREE.MeshBasicMaterial({
color: 0x7fffe2,
toneMapped: false
});
const amberGlow = new THREE.MeshBasicMaterial({
color: 0xffb15e,
toneMapped: false
});
// ------------------------------------------------------------------
// Ground and voxel terrain
// ------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const terrainGeometry = new THREE.BoxGeometry(1, 1, 1);
const terrainMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0,
vertexColors: true,
flatShading: true
});
const terrainBlocks = [];
const dummy = new THREE.Object3D();
const terrainColor = new THREE.Color();
for (let i = 0; i < 170; i++) {
const angle = random() * Math.PI * 2;
const radius = 7 + random() * 31;
const distant = radius > 23;
const height = distant
? 1.5 + random() * 5
: 0.15 + random() * 0.65;
const width = distant
? 1.5 + random() * 4
: 0.8 + random() * 2.4;
const depth = distant
? 1.5 + random() * 4
: 0.8 + random() * 2.4;
terrainBlocks.push({
x: Math.cos(angle) * radius,
z: Math.sin(angle) * radius,
y: height / 2 - 0.03,
width,
height,
depth,
color: distant ? 0x101d25 : 0x172827
});
}
const terrain = new THREE.InstancedMesh(
terrainGeometry,
terrainMaterial,
terrainBlocks.length
);
terrainBlocks.forEach((block, i) => {
dummy.position.set(block.x, block.y, block.z);
dummy.scale.set(block.width, block.height, block.depth);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
terrain.setMatrixAt(i, dummy.matrix);
terrainColor.setHex(block.color);
terrainColor.offsetHSL(0, 0, (random() - 0.5) * 0.08);
terrain.setColorAt(i, terrainColor);
});
terrain.receiveShadow = true;
terrain.castShadow = true;
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
scene.add(terrain);
// ------------------------------------------------------------------
// Observatory base and block-built octagonal walls
// ------------------------------------------------------------------
addBox(scene, 9.7, 0.46, 9.7, platformMaterial, 0, 0.24, 0);
addBox(scene, 8.9, 0.18, 8.9, darkMetal, 0, 0.55, 0);
const wallPositions = [];
const wallRadius = 4.15;
const wallSegments = 32;
for (let level = 0; level < 4; level++) {
for (let segment = 0; segment < wallSegments; segment++) {
// Leave a doorway in the front wall.
if (level === 0 && segment === 16) continue;
const angle = segment / wallSegments * Math.PI * 2;
wallPositions.push({
x: Math.cos(angle) * wallRadius,
z: Math.sin(angle) * wallRadius,
y: 0.86 + level * 0.73,
angle
});
}
}
const wallGeometry = new THREE.BoxGeometry(0.82, 0.70, 0.82);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.87,
metalness: 0.12,
vertexColors: true,
flatShading: true
});
const walls = new THREE.InstancedMesh(
wallGeometry,
wallMaterial,
wallPositions.length
);
wallPositions.forEach((position, i) => {
dummy.position.set(position.x, position.y, position.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
walls.setMatrixAt(i, dummy.matrix);
const color = new THREE.Color(0x40585a);
color.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.08,
(random() - 0.5) * 0.12
);
walls.setColorAt(i, color);
});
walls.castShadow = true;
walls.receiveShadow = true;
walls.instanceMatrix.needsUpdate = true;
walls.instanceColor.needsUpdate = true;
scene.add(walls);
const floor = new THREE.Mesh(
new THREE.CylinderGeometry(4.35, 4.35, 0.35, 8),
platformMaterial
);
floor.position.y = 3.42;
floor.receiveShadow = true;
floor.castShadow = true;
scene.add(floor);
// Front entrance and steps.
addBox(scene, 1.13, 1.85, 0.18, darkMetal, 0, 1.45, 4.52);
addBox(scene, 0.14, 1.95, 0.22, copper, -0.65, 1.43, 4.57);
addBox(scene, 0.14, 1.95, 0.22, copper, 0.65, 1.43, 4.57);
addBox(scene, 1.45, 0.14, 0.22, copper, 0, 2.42, 4.57);
addBox(scene, 3.2, 0.22, 1.05, platformMaterial, 0, 0.24, 4.92);
addBox(scene, 3.8, 0.20, 1.05, platformMaterial, 0, 0.43, 4.98);
addBox(scene, 4.4, 0.18, 1.05, platformMaterial, 0, 0.61, 5.04);
const entranceGlow = addBox(
scene, 0.76, 0.08, 0.05, cyanGlow, 0, 2.22, 4.63
);
entranceGlow.castShadow = false;
// Small upper windows.
for (let segment = 2; segment < wallSegments; segment += 4) {
const angle = segment / wallSegments * Math.PI * 2;
const windowMesh = addBox(
scene,
0.39,
0.31,
0.12,
segment % 8 === 2 ? amberGlow : cyanGlow,
Math.cos(angle) * 4.57,
2.45,
Math.sin(angle) * 4.57
);
windowMesh.rotation.y = Math.PI / 2 - angle;
windowMesh.castShadow = false;
}
// Physical fictional-location sign.
const signTexture = makeTextTexture("VAELIN RIDGE // QORA-9", "#87f1d9");
const signMaterial = new THREE.MeshBasicMaterial({
map: signTexture,
transparent: true,
toneMapped: false
});
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(3.45, 0.54),
signMaterial
);
sign.position.set(0, 2.98, 4.58);
scene.add(sign);
// ------------------------------------------------------------------
// Attached sky laboratory and antenna mast
// ------------------------------------------------------------------
addBox(scene, 2.8, 1.8, 2.4, platformMaterial, -4.95, 1.45, 1.5);
addBox(scene, 3.15, 0.28, 2.75, darkMetal, -4.95, 2.48, 1.5);
addBox(scene, 0.16, 2.05, 0.16, copper, -5.75, 3.34, 0.65);
addBox(scene, 1.25, 0.12, 0.12, copper, -5.18, 3.95, 0.65);
addBox(scene, 0.12, 0.12, 1.25, copper, -5.75, 3.95, 0.65);
const labWindow = addBox(
scene, 1.65, 0.55, 0.10, cyanGlow, -4.95, 1.65, 2.74
);
labWindow.castShadow = false;
const beacon = addBox(
scene, 0.22, 0.22, 0.22, amberGlow, -5.75, 4.45, 0.65
);
beacon.castShadow = false;
// ------------------------------------------------------------------
// Rotating voxel dome
// ------------------------------------------------------------------
const domeRoot = new THREE.Group();
domeRoot.position.y = 3.45;
scene.add(domeRoot);
const domeRadius = 4.1;
const domeStep = 0.48;
const domeCells = [];
for (let gx = -9; gx <= 9; gx++) {
for (let gy = 0; gy <= 9; gy++) {
for (let gz = -9; gz <= 9; gz++) {
const x = gx * domeStep;
const y = gy * domeStep;
const z = gz * domeStep;
const radius = Math.sqrt(x * x + y * y + z * z);
if (
radius < domeRadius - 0.34 ||
radius > domeRadius + 0.34
) {
continue;
}
// The slit is cut around local +X and rotates with the dome.
const inSlit =
x > 0.15 &&
Math.abs(z) < x * 0.43 + 0.18 &&
y > 0.12;
if (inSlit) continue;
domeCells.push({ x, y, z });
}
}
}
const domeGeometry = new THREE.BoxGeometry(
domeStep * 0.96,
domeStep * 0.96,
domeStep * 0.96
);
const domeMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.76,
metalness: 0.24,
vertexColors: true,
flatShading: true
});
const domeShell = new THREE.InstancedMesh(
domeGeometry,
domeMaterial,
domeCells.length
);
domeCells.forEach((cell, i) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
domeShell.setMatrixAt(i, dummy.matrix);
const color = new THREE.Color(0x577078);
if (i % 17 === 0) {
color.setHex(0x9b6845);
} else {
color.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.08,
(random() - 0.5) * 0.15
);
}
domeShell.setColorAt(i, color);
});
domeShell.castShadow = true;
domeShell.receiveShadow = true;
domeShell.instanceMatrix.needsUpdate = true;
domeShell.instanceColor.needsUpdate = true;
domeRoot.add(domeShell);
// Copper lower dome ring.
const ringBlocks = [];
for (let i = 0; i < 32; i++) {
const angle = i / 32 * Math.PI * 2;
ringBlocks.push({
x: Math.cos(angle) * 4.22,
z: Math.sin(angle) * 4.22
});
}
const ring = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.76, 0.42, 0.76),
copper,
ringBlocks.length
);
ringBlocks.forEach((block, i) => {
dummy.position.set(block.x, 0.08, block.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
ring.setMatrixAt(i, dummy.matrix);
});
ring.castShadow = true;
ring.receiveShadow = true;
domeRoot.add(ring);
// Voxel rails flanking the slit.
const railBlocks = [];
for (let y = 0.25; y < 3.8; y += 0.48) {
const x = Math.sqrt(Math.max(0, domeRadius * domeRadius - y * y));
const z = x * 0.39 + 0.18;
railBlocks.push(
{ x, y, z },
{ x, y, z: -z }
);
}
const rails = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.34, 0.34, 0.34),
copper,
railBlocks.length
);
railBlocks.forEach((block, i) => {
dummy.position.set(block.x, block.y, block.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
rails.setMatrixAt(i, dummy.matrix);
});
rails.castShadow = true;
domeRoot.add(rails);
// ------------------------------------------------------------------
// Telescope: independently rotating yaw rig and pitching voxel tube
// ------------------------------------------------------------------
const scopeYaw = new THREE.Group();
scopeYaw.position.set(0, 3.92, 0);
scene.add(scopeYaw);
addBox(scopeYaw, 1.48, 0.42, 1.48, darkMetal, 0, -1.08, 0);
addBox(scopeYaw, 0.70, 0.85, 0.70, tealMetal, 0, -0.55, 0);
addBox(scopeYaw, 0.24, 0.72, 1.55, copper, 0, -0.05, 0);
const scopePitch = new THREE.Group();
scopeYaw.add(scopePitch);
const tubeCells = [];
const tubeSegmentCount = 13;
for (let segment = 0; segment < tubeSegmentCount; segment++) {
const x = 0.36 + segment * 0.38;
for (let side = 0; side < 8; side++) {
const angle = side / 8 * Math.PI * 2;
tubeCells.push({
x,
y: Math.cos(angle) * 0.38,
z: Math.sin(angle) * 0.38
});
}
}
const tube = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.35, 0.35, 0.35),
tealMetal,
tubeCells.length
);
tubeCells.forEach((cell, i) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
tube.setMatrixAt(i, dummy.matrix);
const color = new THREE.Color(
i % 11 === 0 ? 0xc88d55 : 0x438f8a
);
color.offsetHSL(0, 0, (random() - 0.5) * 0.08);
tube.setColorAt(i, color);
});
tube.castShadow = true;
tube.receiveShadow = true;
tube.instanceMatrix.needsUpdate = true;
tube.instanceColor.needsUpdate = true;
scopePitch.add(tube);
// Larger objective ring.
const apertureCells = [];
for (let side = 0; side < 12; side++) {
const angle = side / 12 * Math.PI * 2;
apertureCells.push({
x: 5.03,
y: Math.cos(angle) * 0.51,
z: Math.sin(angle) * 0.51
});
}
const apertureRing = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.37, 0.37, 0.37),
copper,
apertureCells.length
);
apertureCells.forEach((cell, i) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
apertureRing.setMatrixAt(i, dummy.matrix);
});
apertureRing.castShadow = true;
scopePitch.add(apertureRing);
const lens = addBox(
scopePitch, 0.68, 0.68, 0.08, cyanGlow, 5.22, 0, 0
);
lens.castShadow = false;
// Eyepiece, finder scope and focusing assembly.
addBox(scopePitch, 0.62, 0.48, 0.48, darkMetal, -0.15, 0, 0);
addBox(scopePitch, 0.32, 0.32, 0.32, copper, -0.55, 0, 0);
addBox(scopePitch, 1.55, 0.25, 0.25, copper, 2.05, 0.58, 0);
addBox(scopePitch, 0.42, 0.42, 0.42, darkMetal, 2.65, 0.58, 0);
const apertureLight = new THREE.PointLight(0x72ffe1, 3.5, 3, 2);
apertureLight.position.set(5.35, 0, 0);
scopePitch.add(apertureLight);
// ------------------------------------------------------------------
// Synthetic sky and fictional constellations
// ------------------------------------------------------------------
const sky = new THREE.Group();
scene.add(sky);
const starPositions = [];
const starColors = [];
for (let i = 0; i < 2600; i++) {
const y = 0.015 + random() * 0.985;
const angle = random() * Math.PI * 2;
const horizontal = Math.sqrt(1 - y * y);
const radius = 55;
starPositions.push(
Math.cos(angle) * horizontal * radius,
y * radius,
Math.sin(angle) * horizontal * radius
);
const color = new THREE.Color();
const tint = random();
if (tint > 0.88) {
color.setHSL(0.08, 0.48, 0.77);
} else if (tint > 0.72) {
color.setHSL(0.58, 0.35, 0.81);
} else {
color.setHSL(0.57, 0.10, 0.83 + random() * 0.15);
}
starColors.push(color.r, color.g, color.b);
}
const starsGeometry = new THREE.BufferGeometry();
starsGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
starsGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(starColors, 3)
);
const starMaterial = new THREE.PointsMaterial({
size: 0.24,
sizeAttenuation: true,
vertexColors: true,
transparent: true,
opacity: 0.88,
depthWrite: false,
fog: false,
toneMapped: false
});
const stars = new THREE.Points(starsGeometry, starMaterial);
sky.add(stars);
// A second layer of brighter synthetic stars.
const brightPositions = [];
const brightColors = [];
for (let i = 0; i < 150; i++) {
const y = 0.05 + random() * 0.95;
const angle = random() * Math.PI * 2;
const horizontal = Math.sqrt(1 - y * y);
brightPositions.push(
Math.cos(angle) * horizontal * 52,
y * 52,
Math.sin(angle) * horizontal * 52
);
const color = new THREE.Color().setHSL(
0.55 + random() * 0.06,
0.25,
0.85 + random() * 0.15
);
brightColors.push(color.r, color.g, color.b);
}
const brightGeometry = new THREE.BufferGeometry();
brightGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(brightPositions, 3)
);
brightGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(brightColors, 3)
);
const brightMaterial = new THREE.PointsMaterial({
size: 0.56,
sizeAttenuation: true,
vertexColors: true,
transparent: true,
opacity: 0.9,
depthWrite: false,
fog: false,
toneMapped: false
});
sky.add(new THREE.Points(brightGeometry, brightMaterial));
function addConstellation(name, center, offsets, color) {
const direction = center.clone().normalize();
const u = new THREE.Vector3(0, 1, 0)
.cross(direction)
.normalize();
const v = direction.clone().cross(u).normalize();
const points = offsets.map(([x, y]) => {
const point = direction.clone()
.addScaledVector(u, x * 0.075)
.addScaledVector(v, y * 0.075)
.normalize()
.multiplyScalar(52);
return point;
});
const linePositions = [];
for (let i = 0; i < points.length - 1; i++) {
linePositions.push(
points[i].x, points[i].y, points[i].z,
points[i + 1].x, points[i + 1].y, points[i + 1].z
);
}
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(linePositions, 3)
);
const lineMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.38,
depthWrite: false,
fog: false
});
sky.add(new THREE.LineSegments(lineGeometry, lineMaterial));
const nodeGeometry = new THREE.BufferGeometry();
nodeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
points.flatMap(point => [point.x, point.y, point.z]),
3
)
);
const nodeMaterial = new THREE.PointsMaterial({
color: 0xc9fff4,
size: 0.82,
transparent: true,
opacity: 0.95,
depthWrite: false,
fog: false,
toneMapped: false
});
sky.add(new THREE.Points(nodeGeometry, nodeMaterial));
const labelPosition = direction.clone().multiplyScalar(52.4);
const label = makeLabelSprite(name, 4.8, "#8ecbc2");
label.position.copy(labelPosition);
sky.add(label);
}
addConstellation(
"LUMEN KITE",
new THREE.Vector3(-0.58, 0.28, -0.77),
[
[-1.8, 0.2],
[-0.8, 1.25],
[0.4, 0.8],
[1.6, 0.15],
[0.45, -0.9],
[-0.8, -0.65],
[-1.8, 0.2]
],
0x65c9bf
);
addConstellation(
"GLASS SPARROW",
new THREE.Vector3(-0.28, 0.47, -0.84),
[
[-1.5, -0.7],
[-0.6, 0.15],
[0.1, -0.2],
[0.8, 0.55],
[1.6, 0.2]
],
0x7ea9d8
);
addConstellation(
"ASH CROWN",
new THREE.Vector3(-0.74, 0.12, -0.66),
[
[-1.6, 0],
[-0.8, 0.9],
[0, 1.25],
[0.8, 0.9],
[1.6, 0],
[0.8, -0.9],
[-0.8, -0.9],
[-1.6, 0]
],
0xd2a875
);
// Voxel moon.
const moon = new THREE.Group();
moon.position.set(-33, 20, -44);
const moonCells = [];
const moonRadius = 1.15;
for (let x = -2; x <= 2; x++) {
for (let y = -2; y <= 2; y++) {
for (let z = -2; z <= 2; z++) {
const px = x * 0.48;
const py = y * 0.48;
const pz = z * 0.48;
const r = Math.sqrt(px * px + py * py + pz * pz);
if (r < moonRadius - 0.3 || r > moonRadius + 0.3) continue;
moonCells.push({ x: px, y: py, z: pz });
}
}
}
const moonMaterial = new THREE.MeshBasicMaterial({
color: 0xdbe8dc,
toneMapped: false
});
const moonMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.49, 0.49, 0.49),
moonMaterial,
moonCells.length
);
moonCells.forEach((cell, i) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
moonMesh.setMatrixAt(i, dummy.matrix);
});
moon.add(moonMesh);
sky.add(moon);
// ------------------------------------------------------------------
// Interface and mount state
// ------------------------------------------------------------------
const bearingSlider = document.getElementById("bearing");
const elevationSlider = document.getElementById("elevation");
const bearingValue = document.getElementById("bearingValue");
const elevationValue = document.getElementById("elevationValue");
const domeBearing = document.getElementById("domeBearing");
const scopeBearing = document.getElementById("scopeBearing");
const scopeElevation = document.getElementById("scopeElevation");
const lockStatus = document.getElementById("lockStatus");
const autoButton = document.getElementById("autoButton");
const pauseButton = document.getElementById("pauseButton");
const resetButton = document.getElementById("resetButton");
let targetBearing = 22;
let targetElevation = 28;
let currentBearing = 22;
let currentElevation = 28;
let autoSweep = true;
let paused = false;
let animationTime = 0;
function updateAutoButton() {
autoButton.textContent = autoSweep ? "AUTO SWEEP ON" : "AUTO SWEEP OFF";
autoButton.classList.toggle("active", autoSweep);
}
bearingSlider.addEventListener("input", () => {
targetBearing = Number(bearingSlider.value);
autoSweep = false;
updateAutoButton();
});
elevationSlider.addEventListener("input", () => {
targetElevation = Number(elevationSlider.value);
autoSweep = false;
updateAutoButton();
});
autoButton.addEventListener("click", () => {
autoSweep = !autoSweep;
updateAutoButton();
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
pauseButton.classList.toggle("active", paused);
});
resetButton.addEventListener("click", () => {
cameraState.radius = 18.5;
cameraState.theta = 0.68;
cameraState.phi = 1.22;
});
updateAutoButton();
// ------------------------------------------------------------------
// Custom camera controls: drag to orbit, wheel/pinch to zoom
// ------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.48,
1.48
);
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("lostpointercapture", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
32
);
}, { passive: false });
function resize() {
const width = app.clientWidth;
const height = app.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
function dampAngle(current, target, lambda, delta) {
const difference = ((target - current + 540) % 360) - 180;
const factor = 1 - Math.exp(-lambda * delta);
return (current + difference * factor + 360) % 360;
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * cosPhi,
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
animationTime += delta;
if (autoSweep) {
targetBearing = 22 + Math.sin(animationTime * 0.18) * 18;
targetElevation = 28 + Math.sin(animationTime * 0.13 + 1) * 7;
}
currentBearing = dampAngle(
currentBearing,
targetBearing,
2.8,
delta
);
currentElevation = THREE.MathUtils.damp(
currentElevation,
targetElevation,
3.2,
delta
);
}
// The same azimuth drives both the rotating slit and optical axis.
const azimuth = THREE.MathUtils.degToRad(currentBearing);
domeRoot.rotation.y = -azimuth;
scopeYaw.rotation.y = -azimuth;
scopePitch.rotation.z = THREE.MathUtils.degToRad(currentElevation);
if (autoSweep) {
bearingSlider.value = String(Math.round(targetBearing));
elevationSlider.value = String(Math.round(targetElevation));
}
bearingValue.textContent = `${Math.round(targetBearing)}°`;
elevationValue.textContent = `${Math.round(targetElevation)}°`;
domeBearing.textContent =
`${String(Math.round(currentBearing)).padStart(3, "0")}°`;
scopeBearing.textContent =
`${String(Math.round(currentBearing)).padStart(3, "0")}°`;
scopeElevation.textContent =
`${Math.round(currentElevation)}°`;
lockStatus.textContent = paused
? "MOUNT HOLD // ALIGNMENT PRESERVED"
: "SLIT / OPTICAL AXIS CO-LOCKED";
// Keep the procedural celestial sphere infinitely distant.
sky.position.copy(camera.position);
starMaterial.opacity = 0.82 + Math.sin(animationTime * 1.4) * 0.09;
brightMaterial.opacity = 0.87 + Math.sin(animationTime * 1.9 + 1) * 0.08;
updateCamera();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```