Prompt specification
Build or customize the Three.js 3D scene "Communications Relay Space 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: Communications Relay Space Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/communications-relay-space-diorama-x3823
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: communications relay space diorama. Build a fictional orbital relay scene with Earth, two spacecraft, and sight lines. Check antenna pointing and planetary occlusion without claiming real coverage performance. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (communications-relay-space-diorama-x3823):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Orbital Relay — Voxel Geometry Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #030711;
--panel: rgba(8, 16, 29, 0.86);
--panel-strong: rgba(8, 18, 32, 0.95);
--border: rgba(133, 207, 255, 0.18);
--text: #e8f5ff;
--muted: #8ea9bd;
--cyan: #69dcff;
--green: #66ffc0;
--amber: #ffc46b;
--red: #ff647c;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 16px;
background:
linear-gradient(145deg, rgba(18, 34, 53, 0.88), rgba(5, 12, 23, 0.91));
box-shadow:
0 20px 70px rgba(0, 0, 0, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.brand {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 18px 19px 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
h1 {
margin: 8px 0 5px;
font-size: clamp(22px, 3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.disclaimer {
margin-top: 13px;
padding: 10px 11px;
border: 1px solid rgba(255, 196, 107, 0.22);
border-radius: 10px;
background: rgba(255, 196, 107, 0.055);
color: #d9c7a7;
font-size: 11px;
line-height: 1.45;
}
.controls {
top: 18px;
right: 18px;
width: 310px;
padding: 15px;
}
.panel-title {
margin: 0 0 12px;
color: #b8d2e4;
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.control-block {
padding: 12px 0;
border-top: 1px solid rgba(255, 255, 255, 0.075);
}
.control-block:first-of-type { border-top: 0; padding-top: 0; }
.row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.row + .row { margin-top: 9px; }
.label {
color: #abc3d4;
font-size: 12px;
}
.value {
color: var(--text);
font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
margin: 10px 0 2px;
accent-color: var(--cyan);
cursor: pointer;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
accent-color: var(--cyan);
}
.button-row {
display: flex;
gap: 7px;
flex-wrap: wrap;
}
button {
border: 1px solid rgba(130, 205, 255, 0.18);
border-radius: 8px;
padding: 8px 10px;
background: rgba(84, 158, 203, 0.08);
color: #cce6f8;
font-size: 11px;
cursor: pointer;
transition: 140ms ease;
}
button:hover {
border-color: rgba(105, 220, 255, 0.5);
background: rgba(84, 158, 203, 0.17);
color: white;
transform: translateY(-1px);
}
button.active {
border-color: rgba(105, 220, 255, 0.7);
background: rgba(105, 220, 255, 0.16);
color: #e9fbff;
}
.check {
display: flex;
align-items: center;
gap: 9px;
color: #abc3d4;
font-size: 12px;
cursor: pointer;
}
.check input { margin: 0; }
.diagnostics {
left: 18px;
bottom: 18px;
width: min(520px, calc(100vw - 36px));
padding: 15px;
}
.diagnostic-grid {
display: grid;
gap: 8px;
}
.diagnostic {
display: grid;
grid-template-columns: minmax(105px, 1fr) minmax(132px, 1.2fr) minmax(98px, 0.9fr) minmax(122px, 1fr);
gap: 8px;
align-items: center;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.065);
border-radius: 9px;
background: rgba(1, 7, 14, 0.3);
}
.link-name {
color: #d6e9f7;
font: 700 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.035em;
}
.badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 25px;
padding: 5px 7px;
border: 1px solid currentColor;
border-radius: 6px;
font: 700 9px/1.15 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
letter-spacing: 0.035em;
}
.badge.pass {
color: var(--green);
background: rgba(102, 255, 192, 0.065);
}
.badge.warn {
color: var(--amber);
background: rgba(255, 196, 107, 0.07);
}
.badge.fail {
color: var(--red);
background: rgba(255, 100, 124, 0.075);
}
.microcopy {
margin-top: 9px;
color: #728da0;
font-size: 10px;
line-height: 1.4;
}
.legend {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 8;
display: flex;
gap: 14px;
align-items: center;
padding: 9px 12px;
border: 1px solid rgba(133, 207, 255, 0.12);
border-radius: 10px;
background: rgba(5, 12, 22, 0.68);
color: #8faabd;
font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
backdrop-filter: blur(10px);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.swatch {
width: 18px;
height: 3px;
border-radius: 4px;
background: var(--cyan);
box-shadow: 0 0 8px currentColor;
}
.swatch.green { background: var(--green); }
.swatch.red { background: var(--red); }
.swatch.amber { background: var(--amber); }
.hint {
position: fixed;
right: 18px;
bottom: 61px;
z-index: 8;
color: rgba(166, 194, 213, 0.7);
font: 500 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #030711;
color: var(--cyan);
font: 700 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
transition: opacity 400ms ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 800px) {
.brand {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
.brand .disclaimer { display: none; }
.controls {
top: auto;
right: 10px;
bottom: 10px;
width: 270px;
max-height: 43vh;
overflow: auto;
}
.diagnostics {
left: 10px;
bottom: 10px;
width: calc(100vw - 300px);
max-height: 43vh;
overflow: auto;
}
.diagnostic {
grid-template-columns: 1fr 1fr;
}
.legend, .hint { display: none; }
}
@media (max-width: 560px) {
.controls {
right: 10px;
width: 225px;
}
.diagnostics {
width: calc(100vw - 255px);
}
.diagnostic {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel orbital relay scene"></canvas>
<header class="panel brand">
<div class="eyebrow">Fictional orbital geometry lab</div>
<h1>Communications Relay</h1>
<p class="subtitle">
Two voxel spacecraft, a voxel Earth, steerable boresights, and live
line-of-sight checks.
</p>
<div class="disclaimer">
Illustrative geometry only. This scene does not model RF propagation,
link budgets, weather, orbital dynamics, coverage, or operational
performance.
</div>
</header>
<section class="panel controls" aria-label="Scene controls">
<h2 class="panel-title">Scenario controls</h2>
<div class="control-block">
<div class="row">
<span class="label">Scenario time</span>
<span class="value" id="timeValue">000.0 min</span>
</div>
<input id="timeSlider" type="range" min="0" max="240" step="0.1" value="0"
aria-label="Scenario time">
<div class="button-row">
<button id="playButton" class="active" type="button">Pause</button>
<button id="resetButton" type="button">Reset scenario</button>
</div>
</div>
<div class="control-block">
<h2 class="panel-title">Pointing test</h2>
<div class="row">
<span class="label">RL-01 relay-dish trim</span>
<output class="value" id="trimAValue">0.0°</output>
</div>
<input id="trimA" type="range" min="-12" max="12" step="0.5" value="0"
aria-label="Relay antenna trim for RL-01">
<div class="row">
<span class="label">RL-02 relay-dish trim</span>
<output class="value" id="trimBValue">0.0°</output>
</div>
<input id="trimB" type="range" min="-12" max="12" step="0.5" value="0"
aria-label="Relay antenna trim for RL-02">
<div class="button-row" style="margin-top:8px">
<button id="mispointButton" type="button">Mispoint A +6°</button>
<button id="nominalButton" type="button">Nominal dishes</button>
</div>
</div>
<div class="control-block">
<h2 class="panel-title">Display</h2>
<label class="check">
<input id="showSecondary" type="checkbox" checked>
Earth-link reference sight lines
</label>
<label class="check" style="margin-top:8px">
<input id="showOrbits" type="checkbox" checked>
Orbit tracks
</label>
<label class="check" style="margin-top:8px">
<input id="showBeams" type="checkbox" checked>
Antenna boresight guides
</label>
<label class="check" style="margin-top:8px">
<input id="showLabels" type="checkbox" checked>
Object labels
</label>
</div>
<div class="control-block">
<h2 class="panel-title">Camera focus</h2>
<div class="button-row">
<button id="focusEarth" class="active" type="button">Earth</button>
<button id="focusA" type="button">RL-01</button>
<button id="focusB" type="button">RL-02</button>
</div>
</div>
</section>
<section class="panel diagnostics" aria-label="Live geometric diagnostics">
<h2 class="panel-title">Live geometric checks</h2>
<div class="diagnostic-grid">
<div class="diagnostic">
<div class="link-name">RL-01 ↔ RL-02</div>
<div class="badge pass" id="pointAB">POINTING —</div>
<div class="badge fail" id="occAB">OCCLUSION —</div>
<div class="badge fail" id="resultAB">CHECKING</div>
</div>
<div class="diagnostic">
<div class="link-name">RL-01 ↔ NODE-7</div>
<div class="badge pass" id="pointAG">POINTING —</div>
<div class="badge fail" id="occAG">OCCLUSION —</div>
<div class="badge fail" id="resultAG">CHECKING</div>
</div>
<div class="diagnostic">
<div class="link-name">RL-02 ↔ NODE-7</div>
<div class="badge pass" id="pointBG">POINTING —</div>
<div class="badge fail" id="occBG">OCCLUSION —</div>
<div class="badge fail" id="resultBG">CHECKING</div>
</div>
</div>
<div class="microcopy">
Pointing compares each dish boresight with its geometric target.
Occlusion tests the sight-line segment against an opaque Earth-sized sphere.
A correct boresight does not imply an unobstructed path.
</div>
</section>
<div class="hint">
DRAG: orbit · WHEEL: zoom · SHIFT/RIGHT-DRAG: pan<br>
DOUBLE-CLICK: reset camera
</div>
<div class="legend" aria-hidden="true">
<span class="legend-item"><i class="swatch"></i> clear link</span>
<span class="legend-item"><i class="swatch green"></i> Earth link</span>
<span class="legend-item"><i class="swatch red"></i> blocked</span>
<span class="legend-item"><i class="swatch amber"></i> pointing trim</span>
</div>
<div id="loading">INITIALIZING ORBITAL GEOMETRY…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
Constants and scene setup
-------------------------------------------------------------------------- */
const EARTH_RADIUS = 3.05;
const ORBIT_A_RADIUS = 4.8;
const ORBIT_B_RADIUS = 6.2;
const SCENARIO_LENGTH = 240;
const COLORS = {
cyan: 0x69dcff,
green: 0x66ffc0,
amber: 0xffc46b,
red: 0xff647c,
blue: 0x133b66,
gold: 0xc89b48,
white: 0xe7f4ff
};
const canvas = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x030711);
scene.fog = new THREE.FogExp2(0x030711, 0.012);
const camera = new THREE.PerspectiveCamera(
48,
innerWidth / innerHeight,
0.05,
160
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
scene.add(new THREE.AmbientLight(0x8aa7c8, 1.25));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(7, 10, 9);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x397eff, 1.5);
rimLight.position.set(-9, 3, -7);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb86b, 9, 14, 2);
warmLight.position.set(0, -5, 4);
scene.add(warmLight);
/* --------------------------------------------------------------------------
Deterministic pseudo-random helpers
-------------------------------------------------------------------------- */
let randomSeed = 47291;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function randomSigned() {
return random() * 2 - 1;
}
/* --------------------------------------------------------------------------
Labels drawn with an internal canvas; no external assets
-------------------------------------------------------------------------- */
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabel(text, color = "#aeeeff", scale = 1) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 112;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 112);
roundedRect(ctx, 7, 17, 498, 76, 15);
ctx.fillStyle = "rgba(3, 10, 19, 0.86)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = color;
ctx.fillRect(19, 38, 5, 32);
ctx.fillStyle = "#ecf8ff";
ctx.font = "700 31px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 260, 55);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.7 * scale, 0.59 * scale, 1);
sprite.renderOrder = 20;
return sprite;
}
/* --------------------------------------------------------------------------
Voxel Earth
-------------------------------------------------------------------------- */
function longitudeDifference(a, b) {
let d = a - b;
while (d > Math.PI) d -= Math.PI * 2;
while (d < -Math.PI) d += Math.PI * 2;
return d;
}
const continentMasks = [
{ lat: 45, lon: -102, rx: 32, ry: 24 },
{ lat: 15, lon: -87, rx: 13, ry: 12 },
{ lat: -15, lon: -60, rx: 22, ry: 34 },
{ lat: 48, lon: 45, rx: 61, ry: 29 },
{ lat: 7, lon: 21, rx: 25, ry: 35 },
{ lat: 72, lon: -42, rx: 14, ry: 12 },
{ lat: -25, lon: 134, rx: 25, ry: 17 },
{ lat: 39, lon: 139, rx: 12, ry: 18 },
{ lat: -4, lon: 113, rx: 13, ry: 10 }
];
function isLand(normal) {
const lat = Math.asin(THREE.MathUtils.clamp(normal.y, -1, 1));
const lon = Math.atan2(normal.z, normal.x);
for (const mask of continentMasks) {
const dLon = longitudeDifference(lon, THREE.MathUtils.degToRad(mask.lon));
const dLat = lat - THREE.MathUtils.degToRad(mask.lat);
const value =
(dLon / THREE.MathUtils.degToRad(mask.rx)) ** 2 +
(dLat / THREE.MathUtils.degToRad(mask.ry)) ** 2;
if (value < 1) return true;
}
return false;
}
function createVoxelEarth() {
const group = new THREE.Group();
const inner = new THREE.Mesh(
new THREE.SphereGeometry(EARTH_RADIUS * 0.84, 32, 24),
new THREE.MeshStandardMaterial({
color: 0x09243b,
roughness: 1,
metalness: 0
})
);
group.add(inner);
const resolution = 25;
const cellSize = (EARTH_RADIUS * 2 / resolution) * 0.94;
const positions = [];
for (let ix = -resolution; ix <= resolution; ix++) {
for (let iy = -resolution; iy <= resolution; iy++) {
for (let iz = -resolution; iz <= resolution; iz++) {
const x = ix / resolution;
const y = iy / resolution;
const z = iz / resolution;
const radius = Math.sqrt(x * x + y * y + z * z);
if (radius <= 1.002 && radius >= 0.79) {
positions.push({ x, y, z, radius });
}
}
}
}
const geometry = new THREE.BoxGeometry(cellSize, cellSize, cellSize);
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.9,
metalness: 0.03
});
const voxels = new THREE.InstancedMesh(geometry, material, positions.length);
const transform = new THREE.Object3D();
const color = new THREE.Color();
positions.forEach((p, index) => {
transform.position.set(
p.x * EARTH_RADIUS,
p.y * EARTH_RADIUS,
p.z * EARTH_RADIUS
);
transform.rotation.set(0, 0, 0);
transform.updateMatrix();
voxels.setMatrixAt(index, transform.matrix);
const normal = new THREE.Vector3(p.x, p.y, p.z).normalize();
const lat = Math.asin(normal.y);
const land = isLand(normal);
if (Math.abs(lat) > 1.16) {
color.setHSL(0.54, 0.22, 0.84);
} else if (land) {
const variation = 0.5 + 0.5 * Math.sin(normal.x * 15 + normal.z * 11);
color.setHSL(0.29, 0.32, 0.27 + variation * 0.11);
} else {
const depth = 0.5 + 0.5 * Math.sin(normal.x * 9 - normal.z * 7);
color.setHSL(0.56, 0.58, 0.16 + depth * 0.09);
}
voxels.setColorAt(index, color);
});
voxels.instanceMatrix.needsUpdate = true;
if (voxels.instanceColor) voxels.instanceColor.needsUpdate = true;
group.add(voxels);
// Thin voxel cloud layer.
const cloudPositions = [];
for (let i = 0; i < 520; i++) {
const y = randomSigned();
const theta = random() * Math.PI * 2;
const r = Math.sqrt(Math.max(0, 1 - y * y));
const direction = new THREE.Vector3(r * Math.cos(theta), y, r * Math.sin(theta));
if (random() < 0.62) {
cloudPositions.push(direction.multiplyScalar(EARTH_RADIUS * 1.018));
}
}
const cloudGeometry = new THREE.BoxGeometry(0.12, 0.12, 0.12);
const cloudMaterial = new THREE.MeshBasicMaterial({
color: 0xd9f4ff,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const clouds = new THREE.InstancedMesh(
cloudGeometry,
cloudMaterial,
cloudPositions.length
);
cloudPositions.forEach((position, index) => {
transform.position.copy(position);
transform.rotation.set(random() * 0.3, random() * 0.3, random() * 0.3);
transform.updateMatrix();
clouds.setMatrixAt(index, transform.matrix);
});
clouds.instanceMatrix.needsUpdate = true;
group.add(clouds);
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(EARTH_RADIUS * 1.055, 40, 28),
new THREE.MeshBasicMaterial({
color: 0x4abfff,
transparent: true,
opacity: 0.065,
side: THREE.BackSide,
depthWrite: false
})
);
group.add(atmosphere);
scene.add(group);
return group;
}
const earthGroup = createVoxelEarth();
const earthLabel = makeLabel("EARTH / OCCLUDER", "#73cfff", 1.12);
earthLabel.position.set(0, -3.48, 0);
scene.add(earthLabel);
/* --------------------------------------------------------------------------
Stars
-------------------------------------------------------------------------- */
function createStars() {
const count = 1500;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
const color = new THREE.Color();
for (let i = 0; i < count; i++) {
const radius = 45 + random() * 45;
const theta = random() * Math.PI * 2;
const phi = Math.acos(randomSigned());
const sinPhi = Math.sin(phi);
positions[i * 3] = radius * sinPhi * Math.cos(theta);
positions[i * 3 + 1] = radius * Math.cos(phi);
positions[i * 3 + 2] = radius * sinPhi * Math.sin(theta);
color.setHSL(0.55 + random() * 0.08, 0.3, 0.62 + random() * 0.35);
colors[i * 3] = color.r;
colors[i * 3 + 1] = color.g;
colors[i * 3 + 2] = color.b;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: 0.085,
sizeAttenuation: true,
vertexColors: true,
transparent: true,
opacity: 0.9,
depthWrite: false
});
scene.add(new THREE.Points(geometry, material));
}
createStars();
/* --------------------------------------------------------------------------
Orbit paths
-------------------------------------------------------------------------- */
function orbitPoint(radius, phase, inclination) {
const inc = THREE.MathUtils.degToRad(inclination);
return new THREE.Vector3(
radius * Math.cos(phase),
radius * Math.sin(phase) * Math.cos(inc),
radius * Math.sin(phase) * Math.sin(inc)
);
}
function createOrbit(radius, inclination, color) {
const points = [];
for (let i = 0; i <= 240; i++) {
points.push(
orbitPoint(
radius,
(i / 240) * Math.PI * 2,
inclination
)
);
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
scene.add(line);
return line;
}
const orbitA = createOrbit(ORBIT_A_RADIUS, 24, COLORS.cyan);
const orbitB = createOrbit(ORBIT_B_RADIUS, -32, 0xa78bff);
/* --------------------------------------------------------------------------
Spacecraft and antenna construction
-------------------------------------------------------------------------- */
function createDish(scale, tint = 0xd6e2e8) {
const pivot = new THREE.Group();
pivot.scale.setScalar(scale);
const bowl = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.12, 0.28, 12, 1, true),
new THREE.MeshStandardMaterial({
color: tint,
roughness: 0.55,
metalness: 0.48,
side: THREE.DoubleSide
})
);
bowl.rotation.x = Math.PI / 2;
pivot.add(bowl);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.035, 6, 16),
new THREE.MeshStandardMaterial({
color: 0xf2fbff,
roughness: 0.35,
metalness: 0.65
})
);
rim.position.z = 0.14;
pivot.add(rim);
const feed = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.34, 6),
new THREE.MeshStandardMaterial({
color: 0x677888,
roughness: 0.5,
metalness: 0.7
})
);
feed.rotation.x = Math.PI / 2;
feed.position.z = 0.29;
pivot.add(feed);
const feedTip = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.075, 0.075),
new THREE.MeshBasicMaterial({ color: 0xffc46b })
);
feedTip.position.z = 0.47;
pivot.add(feedTip);
const guideMaterial = new THREE.LineDashedMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.72,
dashSize: 0.12,
gapSize: 0.075,
depthWrite: false
});
const guideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.47),
new THREE.Vector3(0, 0, 2.75)
]);
const guide = new THREE.Line(guideGeometry, guideMaterial);
guide.computeLineDistances();
pivot.add(guide);
const conePoints = [];
const apex = new THREE.Vector3(0, 0, 0.47);
const farZ = 2.45;
const spread = 0.24;
[
[-spread, -spread],
[spread, -spread],
[spread, spread],
[-spread, spread]
].forEach(([x, y]) => {
conePoints.push(apex.x, apex.y, apex.z, x, y, farZ);
});
const circle = [];
for (let i = 0; i < 24; i++) {
const a = (i / 24) * Math.PI * 2;
const b = ((i + 1) / 24) * Math.PI * 2;
circle.push(
Math.cos(a) * spread, Math.sin(a) * spread, farZ,
Math.cos(b) * spread, Math.sin(b) * spread, farZ
);
}
const coneGeometry = new THREE.BufferGeometry();
coneGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(conePoints.concat(circle), 3)
);
const coneMaterial = new THREE.LineBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.24,
depthWrite: false
});
const cone = new THREE.LineSegments(coneGeometry, coneMaterial);
pivot.add(cone);
return {
pivot,
guide,
guideMaterial,
cone,
coneMaterial,
scale
};
}
function createSolarPanel(side) {
const panel = new THREE.Group();
panel.position.x = side * 1.37;
const cellMaterial = new THREE.MeshStandardMaterial({
color: 0x164f86,
emissive: 0x082d57,
emissiveIntensity: 0.55,
roughness: 0.45,
metalness: 0.45
});
const cellGeometry = new THREE.BoxGeometry(0.28, 0.045, 0.28);
for (let column = 0; column < 5; column++) {
for (let row = 0; row < 2; row++) {
const cell = new THREE.Mesh(cellGeometry, cellMaterial);
cell.position.set(
(column - 2) * 0.315,
0,
(row - 0.5) * 0.32
);
panel.add(cell);
}
}
const strut = new THREE.Mesh(
new THREE.BoxGeometry(0.8, 0.07, 0.07),
new THREE.MeshStandardMaterial({
color: 0x9ca9b2,
metalness: 0.7,
roughness: 0.4
})
);
strut.position.x = -side * 0.43;
panel.add(strut);
return panel;
}
function createSpacecraft(name, accentColor) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xb7c3cc,
roughness: 0.5,
metalness: 0.68
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x263440,
roughness: 0.5,
metalness: 0.72
});
const goldMaterial = new THREE.MeshStandardMaterial({
color: COLORS.gold,
roughness: 0.46,
metalness: 0.78
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: accentColor,
emissive: accentColor,
emissiveIntensity: 0.18,
roughness: 0.45,
metalness: 0.6
});
const bus = new THREE.Mesh(
new THREE.BoxGeometry(0.95, 0.65, 0.8),
bodyMaterial
);
group.add(bus);
const topModule = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.27, 0.56),
goldMaterial
);
topModule.position.y = 0.44;
group.add(topModule);
const frontModule = new THREE.Mesh(
new THREE.BoxGeometry(0.56, 0.4, 0.18),
darkMaterial
);
frontModule.position.z = 0.46;
group.add(frontModule);
const accent = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.12, 0.06),
accentMaterial
);
accent.position.set(0, 0.1, 0.565);
group.add(accent);
group.add(createSolarPanel(-1));
group.add(createSolarPanel(1));
const engine = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.23, 0.35, 8),
darkMaterial
);
engine.rotation.x = Math.PI / 2;
engine.position.z = -0.55;
group.add(engine);
const relayDish = createDish(1.0);
relayDish.pivot.position.set(0, 0.72, 0.08);
group.add(relayDish.pivot);
const earthDish = createDish(0.61, 0xb5c7d0);
earthDish.pivot.position.set(-0.37, 0.27, -0.28);
group.add(earthDish.pivot);
const whip = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.55, 6),
bodyMaterial
);
whip.position.set(0.37, 0.42, -0.2);
group.add(whip);
const navLight = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 0.07, 0.07),
new THREE.MeshBasicMaterial({ color: accentColor })
);
navLight.position.set(0.48, 0.23, 0.32);
group.add(navLight);
const label = makeLabel(name, accentColor === COLORS.cyan ? "#69dcff" : "#d8adff");
label.position.set(0, 1.32, 0);
group.add(label);
scene.add(group);
return {
name,
group,
label,
relayDish,
earthDish
};
}
const craftA = createSpacecraft("RL-01", COLORS.cyan);
const craftB = createSpacecraft("RL-02", 0xb991ff);
/* --------------------------------------------------------------------------
Surface node
-------------------------------------------------------------------------- */
function latLonToVector(latitude, longitude) {
const lat = THREE.MathUtils.degToRad(latitude);
const lon = THREE.MathUtils.degToRad(longitude);
return new THREE.Vector3(
Math.cos(lat) * Math.cos(lon),
Math.sin(lat),
Math.cos(lat) * Math.sin(lon)
);
}
const nodeNormal = latLonToVector(15, 55);
const nodePosition = nodeNormal.clone().multiplyScalar(EARTH_RADIUS + 0.07);
const nodeGroup = new THREE.Group();
nodeGroup.position.copy(nodePosition);
nodeGroup.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
nodeNormal
);
const nodeBase = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.12, 0.25),
new THREE.MeshStandardMaterial({
color: 0x344b57,
metalness: 0.6,
roughness: 0.55
})
);
nodeGroup.add(nodeBase);
const nodeTower = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 0.42, 0.07),
new THREE.MeshStandardMaterial({
color: 0xe3c58c,
metalness: 0.6,
roughness: 0.5
})
);
nodeTower.position.y = 0.25;
nodeGroup.add(nodeTower);
const nodeBeaconMaterial = new THREE.MeshBasicMaterial({ color: 0xffb35f });
const nodeBeacon = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.13, 0.13),
nodeBeaconMaterial
);
nodeBeacon.position.y = 0.52;
nodeGroup.add(nodeBeacon);
const nodeLabel = makeLabel("NODE-7", "#ffc46b", 0.72);
nodeLabel.position.set(0, 0.9, 0);
nodeGroup.add(nodeLabel);
scene.add(nodeGroup);
/* --------------------------------------------------------------------------
Dynamic sight lines
-------------------------------------------------------------------------- */
function createSightLine() {
const group = new THREE.Group();
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const line = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color: COLORS.cyan,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
line.frustumCulled = false;
group.add(line);
const pointCount = 52;
const pointGeometry = new THREE.BufferGeometry();
pointGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(pointCount * 3), 3)
);
const points = new THREE.Points(
pointGeometry,
new THREE.PointsMaterial({
color: COLORS.cyan,
size: 0.06,
transparent: true,
opacity: 0.85,
depthWrite: false,
sizeAttenuation: true
})
);
points.frustumCulled = false;
group.add(points);
const pulse = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.11, 0.11),
new THREE.MeshBasicMaterial({
color: COLORS.cyan,
toneMapped: false
})
);
group.add(pulse);
const hitMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.16, 0.025, 6, 16),
new THREE.MeshBasicMaterial({
color: COLORS.red,
transparent: true,
opacity: 0.9,
toneMapped: false
})
);
hitMarker.visible = false;
group.add(hitMarker);
scene.add(group);
return { group, line, points, pulse, hitMarker };
}
const linkAB = createSightLine();
const linkAG = createSightLine();
const linkBG = createSightLine();
function updateSightLine(link, a, b, blocked, clearColor, elapsed, phaseOffset) {
const color = blocked ? COLORS.red : clearColor;
const linePositions = link.line.geometry.attributes.position.array;
linePositions[0] = a.x;
linePositions[1] = a.y;
linePositions[2] = a.z;
linePositions[3] = b.x;
linePositions[4] = b.y;
linePositions[5] = b.z;
link.line.geometry.attributes.position.needsUpdate = true;
link.line.material.color.setHex(color);
const pointPositions = link.points.geometry.attributes.position.array;
for (let i = 0; i < pointPositions.length / 3; i++) {
const t = i / (pointPositions.length / 3 - 1);
pointPositions[i * 3] = a.x + (b.x - a.x) * t;
pointPositions[i * 3 + 1] = a.y + (b.y - a.y) * t;
pointPositions[i * 3 + 2] = a.z + (b.z - a.z) * t;
}
link.points.geometry.attributes.position.needsUpdate = true;
link.points.material.color.setHex(color);
if (blocked) {
link.pulse.visible = false;
} else {
link.pulse.visible = true;
link.pulse.material.color.setHex(color);
const t = (elapsed * 0.19 + phaseOffset) % 1;
link.pulse.position.lerpVectors(a, b, t);
link.pulse.rotation.set(elapsed * 1.2, elapsed * 1.7, elapsed);
}
}
/* --------------------------------------------------------------------------
Geometric checks
-------------------------------------------------------------------------- */
function segmentSphere(a, b, radius) {
const direction = new THREE.Vector3().subVectors(b, a);
const aa = direction.dot(direction);
const bb = 2 * a.dot(direction);
const cc = a.dot(a) - radius * radius;
const discriminant = bb * bb - 4 * aa * cc;
if (discriminant < 0 || aa === 0) {
return { blocked: false, t: null };
}
const root = Math.sqrt(discriminant);
const t1 = (-bb - root) / (2 * aa);
const t2 = (-bb + root) / (2 * aa);
const candidates = [t1, t2]
.filter(t => t > 0.0001 && t < 0.9999)
.sort((x, y) => x - y);
if (candidates.length) {
return { blocked: true, t: candidates[0] };
}
return { blocked: false, t: null };
}
function evaluateDish(dish, targetWorld, trimDegrees) {
const parent = dish.pivot.parent;
parent.updateWorldMatrix(true, true);
const targetInParent = parent.worldToLocal(targetWorld.clone());
const localTargetDirection = targetInParent
.sub(dish.pivot.position)
.normalize();
const trimmedDirection = localTargetDirection.clone().applyAxisAngle(
new THREE.Vector3(1, 0, 0),
THREE.MathUtils.degToRad(trimDegrees)
);
dish.pivot.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
trimmedDirection
);
parent.updateWorldMatrix(true, true);
const origin = dish.pivot.getWorldPosition(new THREE.Vector3());
const worldQuaternion = dish.pivot.getWorldQuaternion(new THREE.Quaternion());
const boresight = new THREE.Vector3(0, 0, 1)
.applyQuaternion(worldQuaternion)
.normalize();
const targetDirection = targetWorld.clone().sub(origin).normalize();
const dot = THREE.MathUtils.clamp(
boresight.dot(targetDirection),
-1,
1
);
const errorDegrees = THREE.MathUtils.radToDeg(Math.acos(dot));
let state = "pass";
if (errorDegrees > 8) state = "fail";
else if (errorDegrees > 2.5) state = "warn";
const stateColor = {
pass: COLORS.green,
warn: COLORS.amber,
fail: COLORS.red
}[state];
dish.guideMaterial.color.setHex(stateColor);
dish.coneMaterial.color.setHex(stateColor);
return {
errorDegrees,
state,
origin,
boresight
};
}
function setBadge(element, state, text) {
element.className = `badge ${state}`;
element.textContent = text;
}
function updateDiagnostics(pointerErrors, occlusion) {
const formatError = value => `${value.toFixed(1)}°`;
const relayErrors = [pointerErrors.aRelay, pointerErrors.bRelay];
const relayPointState =
Math.max(...relayErrors) <= 2.5 ? "pass" :
Math.max(...relayErrors) <= 8 ? "warn" : "fail";
setBadge(
document.querySelector("#pointAB"),
relayPointState,
`POINTING ${formatError(pointerErrors.aRelay)} / ${formatError(pointerErrors.bRelay)}`
);
setBadge(
document.querySelector("#occAB"),
occlusion.ab.blocked ? "fail" : "pass",
occlusion.ab.blocked ? "EARTH BLOCKED" : "EARTH CLEAR"
);
let relayResultState = "pass";
let relayResultText = "POINTED / CLEAR";
if (relayPointState === "fail") {
relayResultState = "fail";
relayResultText = "MISPOINTED";
} else if (relayPointState === "warn") {
relayResultState = "warn";
relayResultText = "POINTING OFFSET";
}
if (occlusion.ab.blocked) {
relayResultState = "fail";
relayResultText = "POINTED / OCCLUDED";
}
setBadge(document.querySelector("#resultAB"), relayResultState, relayResultText);
const groundChecks = [
{
point: "#pointAG",
occ: "#occAG",
result: "#resultAG",
error: pointerErrors.aEarth,
check: occlusion.ag
},
{
point: "#pointBG",
occ: "#occBG",
result: "#resultBG",
error: pointerErrors.bEarth,
check: occlusion.bg
}
];
groundChecks.forEach(item => {
const pointState =
item.error <= 2.5 ? "pass" :
item.error <= 8 ? "warn" : "fail";
setBadge(
document.querySelector(item.point),
pointState,
`POINTING ${formatError(item.error)}`
);
setBadge(
document.querySelector(item.occ),
item.check.blocked ? "fail" : "pass",
item.check.blocked ? "EARTH BLOCKED" : "EARTH CLEAR"
);
let resultState = "pass";
let resultText = "POINTED / CLEAR";
if (pointState === "fail") {
resultState = "fail";
resultText = "MISPOINTED";
} else if (pointState === "warn") {
resultState = "warn";
resultText = "POINTING OFFSET";
}
if (item.check.blocked) {
resultState = "fail";
resultText = "POINTED / OCCLUDED";
}
setBadge(document.querySelector(item.result), resultState, resultText);
});
}
/* --------------------------------------------------------------------------
Simulation state and camera controls
-------------------------------------------------------------------------- */
let scenarioTime = 0;
let playing = true;
let trimA = 0;
let trimB = 0;
const cameraState = {
theta: 0.79,
phi: 1.08,
radius: 15.5,
targetRadius: 15.5,
target: new THREE.Vector3(0, 0, 0)
};
let focusMode = "earth";
function setFocus(mode) {
focusMode = mode;
if (mode === "earth") cameraState.targetRadius = 15.5;
if (mode === "a") cameraState.targetRadius = 7.2;
if (mode === "b") cameraState.targetRadius = 7.8;
document.querySelector("#focusEarth").classList.toggle("active", mode === "earth");
document.querySelector("#focusA").classList.toggle("active", mode === "a");
document.querySelector("#focusB").classList.toggle("active", mode === "b");
}
function updateCamera(delta) {
let desiredTarget = new THREE.Vector3(0, 0, 0);
if (focusMode === "a") desiredTarget = craftA.group.position;
if (focusMode === "b") desiredTarget = craftB.group.position;
const followAlpha = 1 - Math.exp(-delta * 4.5);
cameraState.target.lerp(desiredTarget, followAlpha);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.targetRadius,
followAlpha
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.cos(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
let pointerActive = false;
let pointerMode = "orbit";
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", event => {
pointerActive = true;
pointerMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerActive) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (pointerMode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.006,
0.16,
Math.PI - 0.16
);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = cameraState.radius * 0.00135;
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
focusMode = "free";
document.querySelector("#focusEarth").classList.remove("active");
document.querySelector("#focusA").classList.remove("active");
document.querySelector("#focusB").classList.remove("active");
}
});
function endPointer(event) {
pointerActive = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius * factor,
5.2,
32
);
cameraState.radius = cameraState.targetRadius;
}, { passive: false });
canvas.addEventListener("dblclick", () => setFocus("earth"));
/* --------------------------------------------------------------------------
UI wiring
-------------------------------------------------------------------------- */
const timeSlider = document.querySelector("#timeSlider");
const timeValue = document.querySelector("#timeValue");
const trimASlider = document.querySelector("#trimA");
const trimBSlider = document.querySelector("#trimB");
const trimAValue = document.querySelector("#trimAValue");
const trimBValue = document.querySelector("#trimBValue");
timeSlider.addEventListener("input", () => {
scenarioTime = Number(timeSlider.value);
});
trimASlider.addEventListener("input", () => {
trimA = Number(trimASlider.value);
trimAValue.textContent = `${trimA.toFixed(1)}°`;
});
trimBSlider.addEventListener("input", () => {
trimB = Number(trimBSlider.value);
trimBValue.textContent = `${trimB.toFixed(1)}°`;
});
document.querySelector("#playButton").addEventListener("click", event => {
playing = !playing;
event.currentTarget.textContent = playing ? "Pause" : "Play";
event.currentTarget.classList.toggle("active", playing);
});
document.querySelector("#resetButton").addEventListener("click", () => {
scenarioTime = 0;
trimA = 0;
trimB = 0;
trimASlider.value = "0";
trimBSlider.value = "0";
trimAValue.textContent = "0.0°";
trimBValue.textContent = "0.0°";
timeSlider.value = "0";
setFocus("earth");
});
document.querySelector("#mispointButton").addEventListener("click", () => {
trimA = Math.min(12, trimA + 6);
trimASlider.value = String(trimA);
trimAValue.textContent = `${trimA.toFixed(1)}°`;
});
document.querySelector("#nominalButton").addEventListener("click", () => {
trimA = 0;
trimB = 0;
trimASlider.value = "0";
trimBSlider.value = "0";
trimAValue.textContent = "0.0°";
trimBValue.textContent = "0.0°";
});
document.querySelector("#focusEarth").addEventListener("click", () => setFocus("earth"));
document.querySelector("#focusA").addEventListener("click", () => setFocus("a"));
document.querySelector("#focusB").addEventListener("click", () => setFocus("b"));
document.querySelector("#showSecondary").addEventListener("change", event => {
linkAG.group.visible = event.target.checked;
linkBG.group.visible = event.target.checked;
});
document.querySelector("#showOrbits").addEventListener("change", event => {
orbitA.visible = event.target.checked;
orbitB.visible = event.target.checked;
});
document.querySelector("#showBeams").addEventListener("change", event => {
for (const craft of [craftA, craftB]) {
craft.relayDish.guide.visible = event.target.checked;
craft.relayDish.cone.visible = event.target.checked;
craft.earthDish.guide.visible = event.target.checked;
craft.earthDish.cone.visible = event.target.checked;
}
});
document.querySelector("#showLabels").addEventListener("change", event => {
craftA.label.visible = event.target.checked;
craftB.label.visible = event.target.checked;
earthLabel.visible = event.target.checked;
nodeLabel.visible = event.target.checked;
});
/* --------------------------------------------------------------------------
Scene update
-------------------------------------------------------------------------- */
const clock = new THREE.Clock();
let diagnosticsTimer = 0;
function positionCraft(craft, radius, inclination, phase) {
const position = orbitPoint(radius, phase, inclination);
const epsilon = 0.001;
const next = orbitPoint(radius, phase + epsilon, inclination);
const tangent = next.sub(position).normalize();
const radial = position.clone().normalize();
const xAxis = new THREE.Vector3().crossVectors(radial, tangent).normalize();
const basis = new THREE.Matrix4().makeBasis(xAxis, radial, tangent);
craft.group.position.copy(position);
craft.group.quaternion.setFromRotationMatrix(basis);
craft.group.updateMatrixWorld(true);
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (playing) {
scenarioTime = (scenarioTime + delta * 1.8) % SCENARIO_LENGTH;
}
timeSlider.value = scenarioTime.toFixed(1);
timeValue.textContent = `${scenarioTime.toFixed(1).padStart(5, "0")} min`;
const phaseA = 0.4 + scenarioTime * (Math.PI * 2 / 120);
const phaseB = 2.38 + scenarioTime * (Math.PI * 2 / 170);
positionCraft(craftA, ORBIT_A_RADIUS, 24, phaseA);
positionCraft(craftB, ORBIT_B_RADIUS, -32, phaseB);
const pointerErrors = {
aRelay: evaluateDish(craftA.relayDish, craftB.group.position, trimA).errorDegrees,
bRelay: evaluateDish(craftB.relayDish, craftA.group.position, trimB).errorDegrees,
aEarth: evaluateDish(craftA.earthDish, nodePosition, 0).errorDegrees,
bEarth: evaluateDish(craftB.earthDish, nodePosition, 0).errorDegrees
};
const occlusion = {
ab: segmentSphere(craftA.group.position, craftB.group.position, EARTH_RADIUS),
ag: segmentSphere(craftA.group.position, nodePosition, EARTH_RADIUS),
bg: segmentSphere(craftB.group.position, nodePosition, EARTH_RADIUS)
};
updateSightLine(
linkAB,
craftA.group.position,
craftB.group.position,
occlusion.ab.blocked,
COLORS.cyan,
elapsed,
0
);
updateSightLine(
linkAG,
craftA.group.position,
nodePosition,
occlusion.ag.blocked,
COLORS.green,
elapsed,
0.31
);
updateSightLine(
linkBG,
craftB.group.position,
nodePosition,
occlusion.bg.blocked,
COLORS.green,
elapsed,
0.67
);
const setHitMarker = (link, a, b, check) => {
link.hitMarker.visible = check.blocked;
if (check.blocked) {
link.hitMarker.position.lerpVectors(a, b, check.t);
link.hitMarker.lookAt(camera.position);
link.hitMarker.rotation.z = elapsed * 0.8;
}
};
setHitMarker(linkAB, craftA.group.position, craftB.group.position, occlusion.ab);
setHitMarker(linkAG, craftA.group.position, nodePosition, occlusion.ag);
setHitMarker(linkBG, craftB.group.position, nodePosition, occlusion.bg);
nodeBeaconMaterial.color.setHex(
Math.sin(elapsed * 3.2) > 0 ? 0xffc46b : 0x6c3c13
);
updateCamera(delta);
diagnosticsTimer += delta;
if (diagnosticsTimer > 0.08) {
diagnosticsTimer = 0;
updateDiagnostics(pointerErrors, occlusion);
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
setFocus("earth");
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```