Prompt specification
Build or customize the Three.js 3D scene "Competing Sun and Communication Pointing Goals" 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: Competing Sun and Communication Pointing Goals
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/competing-sun-and-communication-pointing-goals-x3824
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: competing Sun and communication pointing goals. Create a bounded attitude-planning puzzle with explicit panel and antenna constraints. Show feasible orientations and unresolved conflicts instead of assuming every pointing goal can be satisfied simultaneously. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (competing-sun-and-communication-pointing-goals-x3824):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Orbit Conflict — Bounded Attitude Planner</title>
<style>
:root {
color-scheme: dark;
--bg: #07111b;
--panel: #0b1723;
--panel-2: #101f2d;
--line: #203444;
--text: #e8f1f6;
--muted: #8da3b2;
--cyan: #56d9ff;
--amber: #ffb34d;
--green: #4ee39b;
--red: #ff6477;
--violet: #a98cff;
}
* { 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, select, input { font: inherit; }
button, select {
color: var(--text);
background: #102331;
border: 1px solid #294355;
border-radius: 8px;
}
button {
cursor: pointer;
transition: border-color .15s, background .15s, transform .15s;
}
button:hover {
border-color: var(--cyan);
background: #142d3c;
}
button:active { transform: translateY(1px); }
select {
width: 100%;
padding: 10px 11px;
outline: none;
}
.app {
height: 100%;
display: grid;
grid-template-rows: 64px 1fr;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 0 20px;
border-bottom: 1px solid var(--line);
background: rgba(7, 17, 27, .94);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 32px;
height: 32px;
position: relative;
border: 1px solid var(--cyan);
transform: rotate(28deg);
box-shadow: 0 0 18px rgba(86, 217, 255, .16);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 6px;
border: 1px solid var(--amber);
}
.brand-mark::after {
inset: 12px -8px;
border-width: 1px 0;
transform: rotate(-42deg);
}
.brand h1 {
margin: 0;
font-size: 16px;
letter-spacing: .11em;
text-transform: uppercase;
white-space: nowrap;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: .08em;
text-transform: uppercase;
}
.header-right {
display: flex;
align-items: center;
gap: 12px;
}
.header-badge {
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 11px;
letter-spacing: .07em;
text-transform: uppercase;
white-space: nowrap;
}
#headerStatus {
color: var(--amber);
border-color: rgba(255, 179, 77, .35);
background: rgba(255, 179, 77, .07);
}
#headerStatus.feasible {
color: var(--green);
border-color: rgba(78, 227, 155, .35);
background: rgba(78, 227, 155, .07);
}
#headerStatus.rejected {
color: var(--red);
border-color: rgba(255, 100, 119, .35);
background: rgba(255, 100, 119, .07);
}
.workspace {
min-height: 0;
display: grid;
grid-template-columns: 290px minmax(420px, 1fr) 306px;
}
aside {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #294354 transparent;
background: var(--panel);
z-index: 5;
}
aside.left { border-right: 1px solid var(--line); }
aside.right { border-left: 1px solid var(--line); }
.section {
padding: 18px;
border-bottom: 1px solid var(--line);
}
.section-title {
margin: 0 0 14px;
display: flex;
align-items: center;
justify-content: space-between;
color: #b8c9d4;
font-size: 11px;
font-weight: 700;
letter-spacing: .13em;
text-transform: uppercase;
}
.section-title small {
color: #5f7788;
font-size: 9px;
letter-spacing: .08em;
}
.field { margin-top: 15px; }
.field:first-of-type { margin-top: 0; }
.field-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.field-row label {
color: #d8e4ea;
font-size: 12px;
}
.value {
color: var(--cyan);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.hint {
margin: 7px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
input[type="range"].amber { accent-color: var(--amber); }
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 16px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: #09141e;
}
.toggle-row span {
color: #cbd9e1;
font-size: 11px;
}
.toggle-row small {
display: block;
color: var(--muted);
margin-top: 3px;
font-size: 9px;
}
.toggle {
position: relative;
width: 38px;
height: 21px;
flex: 0 0 auto;
}
.toggle input {
opacity: 0;
width: 100%;
height: 100%;
margin: 0;
cursor: pointer;
}
.toggle span {
position: absolute;
inset: 0;
border-radius: 999px;
background: #243a49;
pointer-events: none;
transition: .2s;
}
.toggle span::after {
content: "";
position: absolute;
width: 15px;
height: 15px;
left: 3px;
top: 3px;
border-radius: 50%;
background: white;
transition: .2s;
}
.toggle input:checked + span { background: #268e75; }
.toggle input:checked + span::after { transform: translateX(17px); }
.mount-card {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 8px;
margin-top: 13px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: #08131c;
text-align: center;
}
.mount-card .axis {
font-size: 10px;
color: var(--muted);
letter-spacing: .07em;
text-transform: uppercase;
}
.mount-card strong {
display: block;
margin-top: 4px;
font-size: 12px;
}
.panel strong { color: var(--amber); }
.antenna strong { color: var(--cyan); }
.mount-angle {
color: #8297a5;
font-size: 10px;
}
.primary {
width: 100%;
margin-top: 16px;
padding: 11px 12px;
border-color: #347d9a;
background: linear-gradient(180deg, #17394a, #102b39);
color: #dff8ff;
font-size: 12px;
font-weight: 700;
letter-spacing: .03em;
}
.primary:hover {
background: linear-gradient(180deg, #1e4b60, #143646);
}
.bounds {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 10px;
}
.bounds div {
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 7px;
text-align: center;
color: var(--muted);
font-size: 9px;
letter-spacing: .05em;
text-transform: uppercase;
}
.bounds b {
display: block;
margin-top: 4px;
color: #dce9ef;
font-size: 10px;
font-weight: 600;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: radial-gradient(circle at 50% 45%, #102433 0%, #07111b 67%);
}
#viewport canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.hud {
position: absolute;
z-index: 3;
pointer-events: none;
}
.hud.top {
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 15px;
}
.status-card {
min-width: 235px;
max-width: 370px;
padding: 12px 14px;
border: 1px solid rgba(255, 179, 77, .35);
border-radius: 10px;
background: rgba(7, 17, 27, .78);
backdrop-filter: blur(8px);
box-shadow: 0 12px 30px rgba(0, 0, 0, .14);
}
.status-card.feasible { border-color: rgba(78, 227, 155, .38); }
.status-card.rejected { border-color: rgba(255, 100, 119, .4); }
.status-kicker {
color: var(--muted);
font-size: 9px;
letter-spacing: .13em;
text-transform: uppercase;
}
#statusText {
margin-top: 4px;
color: var(--amber);
font-size: 13px;
font-weight: 700;
}
.feasible #statusText { color: var(--green); }
.rejected #statusText { color: var(--red); }
#statusDetail {
margin-top: 4px;
color: #aebfc9;
font-size: 10px;
line-height: 1.45;
}
.attitude-readout {
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(7, 17, 27, .72);
backdrop-filter: blur(8px);
color: var(--muted);
font-size: 10px;
text-align: right;
white-space: nowrap;
}
.attitude-readout strong {
color: #e8f5fb;
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.scene-label {
position: absolute;
z-index: 2;
pointer-events: none;
transform: translate(-50%, -50%);
padding: 4px 7px;
border: 1px solid rgba(111, 150, 174, .27);
border-radius: 5px;
background: rgba(5, 13, 21, .72);
color: #c9dae4;
font-size: 9px;
font-weight: 700;
letter-spacing: .08em;
text-transform: uppercase;
white-space: nowrap;
}
.scene-label.sun { color: var(--amber); border-color: rgba(255, 179, 77, .3); }
.scene-label.comm { color: var(--cyan); border-color: rgba(86, 217, 255, .3); }
.scene-label.panel { color: var(--amber); }
.scene-label.antenna { color: var(--cyan); }
.scene-label.lattice { color: var(--violet); border-color: rgba(169, 140, 255, .34); }
.legend {
position: absolute;
z-index: 3;
left: 18px;
bottom: 17px;
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
max-width: calc(100% - 36px);
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(7, 17, 27, .72);
backdrop-filter: blur(7px);
color: #a9bac5;
font-size: 9px;
pointer-events: none;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }
.dot.cyan { background: var(--cyan); }
.camera-help {
position: absolute;
z-index: 3;
right: 17px;
bottom: 17px;
color: #6f8797;
font-size: 9px;
letter-spacing: .05em;
pointer-events: none;
}
.view-reset {
position: absolute;
z-index: 4;
right: 17px;
top: 104px;
padding: 7px 9px;
color: #a9bdca;
font-size: 9px;
background: rgba(7, 17, 27, .72);
}
.summary-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.metric {
padding: 11px 7px;
border: 1px solid var(--line);
border-radius: 8px;
background: #09141e;
text-align: center;
}
.metric b {
display: block;
font-size: 19px;
font-variant-numeric: tabular-nums;
}
.metric span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
letter-spacing: .08em;
text-transform: uppercase;
}
.metric.green b { color: var(--green); }
.metric.amber b { color: var(--amber); }
.metric.red b { color: var(--red); }
.set-message {
margin-top: 10px;
padding: 10px;
border: 1px solid rgba(255, 179, 77, .25);
border-radius: 8px;
background: rgba(255, 179, 77, .06);
color: #d9c19e;
font-size: 10px;
line-height: 1.5;
}
.set-message.exists {
border-color: rgba(78, 227, 155, .25);
background: rgba(78, 227, 155, .06);
color: #afe4c9;
}
.check {
display: grid;
grid-template-columns: 14px 1fr auto;
gap: 8px;
align-items: start;
padding: 9px 0;
border-bottom: 1px solid rgba(32, 52, 68, .6);
}
.check:last-child { border-bottom: 0; }
.check-icon {
width: 12px;
height: 12px;
margin-top: 1px;
border: 1px solid #3b5364;
border-radius: 50%;
text-align: center;
color: transparent;
font-size: 8px;
line-height: 10px;
}
.check.pass .check-icon {
color: #06130e;
border-color: var(--green);
background: var(--green);
}
.check.fail .check-icon {
color: #24070b;
border-color: var(--red);
background: var(--red);
}
.check.neutral .check-icon {
color: #14202a;
border-color: var(--amber);
background: var(--amber);
}
.check-title {
color: #cbd8df;
font-size: 10px;
}
.check-sub {
margin-top: 2px;
color: #6f8797;
font-size: 9px;
line-height: 1.4;
}
.check-value {
color: #9db0bc;
font-size: 9px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.candidate-list {
display: grid;
gap: 6px;
}
.candidate {
width: 100%;
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
padding: 9px;
text-align: left;
background: #09141e;
}
.candidate:hover { background: #102431; }
.candidate-attitude {
color: #d8e5eb;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.candidate-detail {
margin-top: 3px;
color: #6f8797;
font-size: 8px;
}
.candidate-tag {
align-self: center;
padding: 4px 6px;
border-radius: 5px;
color: var(--amber);
background: rgba(255, 179, 77, .1);
font-size: 8px;
font-weight: 800;
letter-spacing: .06em;
}
.candidate-tag.full {
color: var(--green);
background: rgba(78, 227, 155, .1);
}
.empty {
padding: 12px;
border: 1px dashed #2b4354;
border-radius: 8px;
color: #7d95a4;
font-size: 10px;
line-height: 1.5;
}
.policy-note {
margin-top: 10px;
color: #718a99;
font-size: 9px;
line-height: 1.5;
}
@media (max-width: 1120px) {
.workspace { grid-template-columns: 260px minmax(390px, 1fr) 275px; }
.section { padding: 15px; }
}
@media (max-width: 860px) {
html, body { overflow: auto; }
.app { height: auto; min-height: 100%; grid-template-rows: 64px auto; }
.workspace { display: flex; flex-direction: column; }
#viewport { order: -1; height: 65vh; min-height: 480px; }
aside { overflow: visible; border: 0 !important; }
.header-badge { display: none; }
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Orbit Conflict</h1>
<p>Bounded attitude-planning puzzle</p>
</div>
</div>
<div class="header-right">
<span class="header-badge">Grid scan · YXZ Euler</span>
<span class="header-badge" id="headerStatus">Unresolved conflict</span>
</div>
</header>
<main class="workspace">
<aside class="left">
<section class="section">
<h2 class="section-title">Mission targets <small>01</small></h2>
<div class="field">
<div class="field-row">
<label for="targetSelect">Communication target</label>
</div>
<select id="targetSelect">
<option value="kestrel">Kestrel relay · +Y / +X</option>
<option value="aster">Aster relay · high declination</option>
<option value="dawn">Dawn ground segment · low Earth</option>
</select>
<p class="hint">The target vector is fixed in world space. Rotate the spacecraft to change the boresight error.</p>
</div>
</section>
<section class="section">
<h2 class="section-title">Explicit constraints <small>02</small></h2>
<div class="field">
<div class="field-row">
<label for="panelLimit">Panel maximum Sun error</label>
<span class="value" id="panelLimitValue">48°</span>
</div>
<input id="panelLimit" class="amber" type="range" min="10" max="80" step="1" value="48" />
<p class="hint">Hard cone around the panel normal: angle(panel normal, Sun) must not exceed this limit.</p>
</div>
<div class="field">
<div class="field-row">
<label for="antennaLimit">Antenna maximum boresight error</label>
<span class="value" id="antennaLimitValue">18°</span>
</div>
<input id="antennaLimit" type="range" min="5" max="55" step="1" value="18" />
<p class="hint">Hard cone around the antenna boresight toward the selected relay.</p>
</div>
<div class="toggle-row">
<span>Earth occultation guard<small>Reject antenna rays intersecting Earth</small></span>
<label class="toggle">
<input id="earthGuard" type="checkbox" checked />
<span></span>
</label>
</div>
<div class="mount-card">
<div class="axis panel">Panel<strong>+Z</strong></div>
<div class="mount-angle">90°<br>fixed</div>
<div class="axis antenna">Antenna<strong>+X</strong></div>
</div>
<p class="hint">The panel and antenna are physically mounted at 90°. Tight cones can therefore make the two pointing goals incompatible.</p>
</section>
<section class="section">
<h2 class="section-title">Selected attitude <small>03</small></h2>
<div class="field">
<div class="field-row">
<label for="yaw">Yaw</label>
<span class="value" id="yawValue">12°</span>
</div>
<input id="yaw" type="range" min="-65" max="65" step="1" value="12" />
</div>
<div class="field">
<div class="field-row">
<label for="pitch">Pitch</label>
<span class="value" id="pitchValue">8°</span>
</div>
<input id="pitch" type="range" min="-40" max="40" step="1" value="8" />
</div>
<div class="field">
<div class="field-row">
<label for="roll">Roll</label>
<span class="value" id="rollValue">0°</span>
</div>
<input id="roll" type="range" min="-45" max="45" step="1" value="0" />
</div>
<div class="bounds">
<div>Yaw bound<b>±65°</b></div>
<div>Pitch bound<b>±40°</b></div>
<div>Roll bound<b>±45°</b></div>
</div>
<button class="primary" id="bestButton">Select best allowed orientation</button>
<p class="hint">Strict mode selects a full solution if one exists. Otherwise it selects the least-bad safe compromise and leaves the conflict visible.</p>
</section>
<section class="section">
<h2 class="section-title">Decision policy <small>04</small></h2>
<select id="policySelect">
<option value="strict">Strict · all pointing goals</option>
<option value="panel">Panel priority · communication may miss</option>
<option value="comm">Communication priority · panel may miss</option>
</select>
<p class="policy-note">Priority changes the ranking of unresolved candidates only. It never labels a partial solution feasible.</p>
</section>
</aside>
<section id="viewport" aria-label="Interactive 3D spacecraft attitude scene">
<div class="hud top">
<div class="status-card" id="statusCard">
<div class="status-kicker">Selected orientation</div>
<div id="statusText">Unresolved conflict</div>
<div id="statusDetail">Panel or communication constraint is not satisfied.</div>
</div>
<div class="attitude-readout">
ATTITUDE<br />
<strong id="attitudeReadout">Y 12° · P 8° · R 0°</strong>
</div>
</div>
<button class="view-reset" id="viewReset">Reset camera</button>
<div class="scene-label sun" id="labelSun">Sun vector</div>
<div class="scene-label comm" id="labelTarget">Kestrel relay</div>
<div class="scene-label panel" id="labelPanel">Panel +Z</div>
<div class="scene-label antenna" id="labelAntenna">Antenna +X</div>
<div class="scene-label lattice" id="labelLattice">Euler feasibility lattice</div>
<div class="legend">
<span><i class="dot green"></i>Full feasible orientation</span>
<span><i class="dot amber"></i>Safe but unresolved</span>
<span><i class="dot red"></i>Rejected / occulted</span>
<span><i class="dot cyan"></i>Antenna boresight</span>
</div>
<div class="camera-help">Drag to orbit · wheel to zoom</div>
</section>
<aside class="right">
<section class="section">
<h2 class="section-title">Sampled feasible set <small>GRID</small></h2>
<div class="summary-grid">
<div class="metric green"><b id="fullCount">0</b><span>Full</span></div>
<div class="metric amber"><b id="conflictCount">0</b><span>Conflict</span></div>
<div class="metric red"><b id="rejectedCount">0</b><span>Rejected</span></div>
</div>
<div class="set-message" id="setMessage">Scanning the bounded attitude lattice…</div>
</section>
<section class="section">
<h2 class="section-title">Constraint audit <small>SELECTED</small></h2>
<div id="constraintAudit"></div>
</section>
<section class="section">
<h2 class="section-title">Feasible orientations <small id="feasibleTag">0</small></h2>
<div class="candidate-list" id="feasibleList"></div>
</section>
<section class="section">
<h2 class="section-title">Unresolved conflicts <small id="conflictTag">0</small></h2>
<div class="candidate-list" id="conflictList"></div>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const viewport = $("viewport");
const DEG = Math.PI / 180;
const RAD = 180 / Math.PI;
const clamp = THREE.MathUtils.clamp;
const LIMITS = {
yaw: 65,
pitch: 40,
roll: 45
};
const TARGETS = {
kestrel: {
name: "Kestrel relay",
direction: new THREE.Vector3(0.38, 0.80, -0.25).normalize()
},
aster: {
name: "Aster relay",
direction: new THREE.Vector3(-0.15, 0.95, 0.22).normalize()
},
dawn: {
name: "Dawn ground segment",
direction: new THREE.Vector3(0.58, -0.62, 0.32).normalize()
}
};
const SUN_DIRECTION = new THREE.Vector3(-1, 0.12, 0.10).normalize();
const EARTH_CENTER = new THREE.Vector3(0, -4.2, 0);
const EARTH_RADIUS = 2.05;
const PANEL_LOCAL = new THREE.Vector3(0, 0, 1);
const ANTENNA_LOCAL = new THREE.Vector3(1, 0, 0);
let targetKey = "kestrel";
let target = TARGETS[targetKey];
let panelLimit = 48;
let antennaLimit = 18;
let earthGuard = true;
let policy = "strict";
let selected = { yaw: 12, pitch: 8, roll: 0 };
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111b);
scene.fog = new THREE.FogExp2(0x07111b, 0.026);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
viewport.prepend(renderer.domElement);
scene.add(new THREE.HemisphereLight(0x91c7e8, 0x17202b, 1.55));
const sunLight = new THREE.DirectionalLight(0xffd18a, 3.1);
sunLight.position.copy(SUN_DIRECTION).multiplyScalar(10);
scene.add(sunLight);
const rimLight = new THREE.DirectionalLight(0x59c8ff, 1.6);
rimLight.position.set(5, 2, -6);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0x846fff, 13, 14, 2);
fillLight.position.set(2, -1, 3);
scene.add(fillLight);
// Camera controls are implemented directly, without example modules.
const cameraState = {
radius: 10.6,
theta: 0.63,
phi: 0.94,
target: new THREE.Vector3(0, -0.45, 0)
};
function updateCamera() {
const { radius, theta, phi, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.radius = 10.6;
cameraState.theta = 0.63;
cameraState.phi = 0.94;
cameraState.target.set(0, -0.45, 0);
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.006, 0.24, 1.47);
updateCamera();
});
const stopDragging = () => { dragging = false; };
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("pointerleave", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = clamp(cameraState.radius + event.deltaY * 0.008, 6.2, 18);
updateCamera();
}, { passive: false });
$("viewReset").addEventListener("click", resetCamera);
updateCamera();
// Star field.
{
const count = 520;
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 r = 20 + Math.random() * 22;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions[i * 3] = r * Math.sin(phi) * Math.cos(theta);
positions[i * 3 + 1] = r * Math.cos(phi);
positions[i * 3 + 2] = r * Math.sin(phi) * Math.sin(theta);
color.setHSL(0.52 + Math.random() * 0.18, 0.25, 0.55 + Math.random() * 0.3);
colors.set([color.r, color.g, color.b], i * 3);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
const stars = new THREE.Points(
geometry,
new THREE.PointsMaterial({
size: 0.045,
vertexColors: true,
transparent: true,
opacity: 0.85,
depthWrite: false
})
);
scene.add(stars);
}
// Sun.
const sunGroup = new THREE.Group();
sunGroup.position.copy(SUN_DIRECTION).multiplyScalar(5.25);
scene.add(sunGroup);
const sunMesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.54, 1),
new THREE.MeshStandardMaterial({
color: 0xff9d38,
emissive: 0xff6d12,
emissiveIntensity: 2.2,
roughness: 0.8,
flatShading: true
})
);
sunGroup.add(sunMesh);
const sunHalo = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.7, 1),
new THREE.MeshBasicMaterial({
color: 0xffb04d,
wireframe: true,
transparent: true,
opacity: 0.24
})
);
sunGroup.add(sunHalo);
const sunRay = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([sunGroup.position.clone(), new THREE.Vector3()]),
new THREE.LineDashedMaterial({
color: 0xffb14c,
transparent: true,
opacity: 0.24,
dashSize: 0.16,
gapSize: 0.12
})
);
sunRay.computeLineDistances();
scene.add(sunRay);
// Faceted Earth.
const earthGroup = new THREE.Group();
earthGroup.position.copy(EARTH_CENTER);
scene.add(earthGroup);
{
const base = new THREE.IcosahedronGeometry(EARTH_RADIUS, 2);
const geometry = base.index ? base.toNonIndexed() : base;
const count = geometry.attributes.position.count;
const colors = new Float32Array(count * 3);
const pos = geometry.attributes.position;
const ocean = new THREE.Color(0x164b68);
const deepOcean = new THREE.Color(0x0c2e48);
const land = new THREE.Color(0x63825d);
const ice = new THREE.Color(0xb9d7d8);
const tmp = new THREE.Color();
const a = new THREE.Vector3();
const b = new THREE.Vector3();
const c = new THREE.Vector3();
const center = new THREE.Vector3();
for (let i = 0; i < count; i += 3) {
a.fromBufferAttribute(pos, i);
b.fromBufferAttribute(pos, i + 1);
c.fromBufferAttribute(pos, i + 2);
center.copy(a).add(b).add(c).divideScalar(3).normalize();
const n =
Math.sin(center.x * 8.1 + center.y * 2.4) +
Math.cos(center.z * 7.2 - center.x * 3.1) +
Math.sin((center.x + center.y + center.z) * 11.0);
if (center.y > 0.82) tmp.copy(ice);
else if (n > 0.73) tmp.copy(land);
else if (n < -0.9) tmp.copy(deepOcean);
else tmp.copy(ocean).offsetHSL(0, 0, (Math.random() - 0.5) * 0.035);
for (let j = 0; j < 3; j++) {
colors[(i + j) * 3] = tmp.r;
colors[(i + j) * 3 + 1] = tmp.g;
colors[(i + j) * 3 + 2] = tmp.b;
}
}
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
const earth = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.95,
metalness: 0.02
})
);
earthGroup.add(earth);
const atmosphere = new THREE.Mesh(
new THREE.IcosahedronGeometry(EARTH_RADIUS * 1.055, 2),
new THREE.MeshBasicMaterial({
color: 0x55d8ff,
wireframe: true,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
earthGroup.add(atmosphere);
}
// Spacecraft.
const craftRoot = new THREE.Group();
scene.add(craftRoot);
const busMaterial = new THREE.MeshStandardMaterial({
color: 0xb58a35,
metalness: 0.64,
roughness: 0.42,
flatShading: true
});
const bus = new THREE.Mesh(new THREE.BoxGeometry(0.86, 0.64, 0.68), busMaterial);
craftRoot.add(bus);
const busEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(bus.geometry),
new THREE.LineBasicMaterial({ color: 0xffd56c, transparent: true, opacity: 0.72 })
);
craftRoot.add(busEdges);
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x243542,
metalness: 0.72,
roughness: 0.38,
flatShading: true
});
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0x123b61,
emissive: 0x071b31,
emissiveIntensity: 0.5,
metalness: 0.28,
roughness: 0.38,
flatShading: true
});
function addSolarWing(centerX) {
const width = 1.34;
const height = 0.64;
const wing = new THREE.Mesh(new THREE.BoxGeometry(width, height, 0.045), panelMaterial);
wing.position.set(centerX, 0, 0);
craftRoot.add(wing);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(wing.geometry),
new THREE.LineBasicMaterial({ color: 0xd6a84b, transparent: true, opacity: 0.85 })
);
edge.position.copy(wing.position);
craftRoot.add(edge);
const gridVertices = [];
for (let i = 1; i < 5; i++) {
const x = centerX - width / 2 + (width * i) / 5;
gridVertices.push(x, -height / 2, 0.026, x, height / 2, 0.026);
}
gridVertices.push(
centerX - width / 2, 0, 0.026, centerX + width / 2, 0, 0.026
);
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute("position", new THREE.Float32BufferAttribute(gridVertices, 3));
craftRoot.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({ color: 0x5ba2c7, transparent: true, opacity: 0.36 })
));
}
addSolarWing(-1.13);
addSolarWing(1.13);
const topModule = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.28, 0.26, 8),
darkMetal
);
topModule.position.y = 0.43;
craftRoot.add(topModule);
const antennaBoom = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.52, 8),
darkMetal
);
antennaBoom.rotation.z = -Math.PI / 2;
antennaBoom.position.set(0.33, 0.43, 0.08);
craftRoot.add(antennaBoom);
const dish = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.075, 0.19, 12, 1, true),
new THREE.MeshStandardMaterial({
color: 0xd9e3e8,
metalness: 0.65,
roughness: 0.34,
side: THREE.DoubleSide,
flatShading: true
})
);
dish.rotation.z = -Math.PI / 2;
dish.position.set(0.66, 0.43, 0.08);
craftRoot.add(dish);
const feed = new THREE.Mesh(
new THREE.ConeGeometry(0.045, 0.17, 8),
new THREE.MeshStandardMaterial({ color: 0x63ddff, emissive: 0x1b7892, emissiveIntensity: 0.7 })
);
feed.rotation.z = -Math.PI / 2;
feed.position.set(0.86, 0.43, 0.08);
craftRoot.add(feed);
const panelArrow = new THREE.ArrowHelper(
PANEL_LOCAL, new THREE.Vector3(0, 0, 0.39), 1.36, 0xffb34d, 0.18, 0.09
);
const antennaArrow = new THREE.ArrowHelper(
ANTENNA_LOCAL, new THREE.Vector3(0.66, 0.43, 0.08), 1.22, 0x56d9ff, 0.18, 0.09
);
craftRoot.add(panelArrow, antennaArrow);
function makeCone(color) {
const group = new THREE.Group();
const mesh = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
})
);
const edge = new THREE.LineSegments(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.23,
depthWrite: false
})
);
group.add(mesh, edge);
return { group, mesh, edge };
}
const panelCone = makeCone(0xffb34d);
const antennaCone = makeCone(0x56d9ff);
panelCone.group.position.set(0, 0, 0.39);
antennaCone.group.position.set(0.66, 0.43, 0.08);
craftRoot.add(panelCone.group, antennaCone.group);
const yAxis = new THREE.Vector3(0, 1, 0);
panelCone.group.quaternion.setFromUnitVectors(yAxis, PANEL_LOCAL);
antennaCone.group.quaternion.setFromUnitVectors(yAxis, ANTENNA_LOCAL);
function updateCone(cone, angleDegrees, length) {
const radius = Math.tan(clamp(angleDegrees, 1, 84) * DEG) * length;
const geometry = new THREE.ConeGeometry(radius, length, 20, 1, true);
geometry.rotateX(Math.PI);
geometry.translate(0, length / 2, 0);
cone.mesh.geometry.dispose();
cone.edge.geometry.dispose();
cone.mesh.geometry = geometry;
cone.edge.geometry = new THREE.EdgesGeometry(geometry);
}
const statusHalo = new THREE.Mesh(
new THREE.TorusGeometry(1.72, 0.018, 6, 64),
new THREE.MeshBasicMaterial({
color: 0xffb34d,
transparent: true,
opacity: 0.58,
depthWrite: false
})
);
scene.add(statusHalo);
// Communication target.
const relayGroup = new THREE.Group();
scene.add(relayGroup);
const relayBody = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.34, 0.38),
new THREE.MeshStandardMaterial({
color: 0x4b6675,
metalness: 0.68,
roughness: 0.38,
flatShading: true
})
);
relayGroup.add(relayBody);
const relayWingMaterial = new THREE.MeshStandardMaterial({
color: 0x16617c,
emissive: 0x0a2837,
emissiveIntensity: 0.8,
roughness: 0.45,
flatShading: true
});
[-0.48, 0.48].forEach((x) => {
const wing = new THREE.Mesh(new THREE.BoxGeometry(0.48, 0.28, 0.04), relayWingMaterial);
wing.position.x = x;
relayGroup.add(wing);
});
const relayDish = new THREE.Mesh(
new THREE.ConeGeometry(0.19, 0.24, 10, 1, true),
new THREE.MeshStandardMaterial({
color: 0xb9f4ff,
emissive: 0x16738d,
emissiveIntensity: 0.7,
side: THREE.DoubleSide,
flatShading: true
})
);
relayDish.rotation.z = Math.PI / 2;
relayDish.position.x = 0.34;
relayGroup.add(relayDish);
const relayRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.012, 5, 40),
new THREE.MeshBasicMaterial({ color: 0x56d9ff, transparent: true, opacity: 0.55 })
);
relayRing.rotation.y = Math.PI / 2;
relayGroup.add(relayRing);
const relayRay = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), target.direction.clone().multiplyScalar(4.4)]),
new THREE.LineDashedMaterial({
color: 0x56d9ff,
transparent: true,
opacity: 0.35,
dashSize: 0.11,
gapSize: 0.11
})
);
relayRay.computeLineDistances();
scene.add(relayRay);
function updateTargetVisual() {
target = TARGETS[targetKey];
relayGroup.position.copy(target.direction).multiplyScalar(4.4);
relayGroup.lookAt(new THREE.Vector3(0, 0, 0));
const positions = relayRay.geometry.attributes.position;
positions.setXYZ(0, 0, 0, 0);
positions.setXYZ(1, relayGroup.position.x, relayGroup.position.y, relayGroup.position.z);
positions.needsUpdate = true;
relayRay.computeLineDistances();
$("labelTarget").textContent = target.name;
}
// Euler feasibility lattice.
const latticeGroup = new THREE.Group();
latticeGroup.position.set(2.65, -0.35, -1.5);
scene.add(latticeGroup);
const latticeSize = 1.42;
const latticeBox = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(latticeSize, latticeSize, latticeSize)),
new THREE.LineBasicMaterial({ color: 0x7467b5, transparent: true, opacity: 0.32 })
);
latticeGroup.add(latticeBox);
const candidates = [];
const yawSamples = 15;
const pitchSamples = 11;
const rollSamples = 11;
for (let iy = 0; iy < yawSamples; iy++) {
const yaw = -LIMITS.yaw + (2 * LIMITS.yaw * iy) / (yawSamples - 1);
for (let ip = 0; ip < pitchSamples; ip++) {
const pitch = -LIMITS.pitch + (2 * LIMITS.pitch * ip) / (pitchSamples - 1);
for (let ir = 0; ir < rollSamples; ir++) {
const roll = -LIMITS.roll + (2 * LIMITS.roll * ir) / (rollSamples - 1);
candidates.push({ yaw, pitch, roll });
}
}
}
const latticePositions = new Float32Array(candidates.length * 3);
const latticeColors = new Float32Array(candidates.length * 3);
candidates.forEach((candidate, index) => {
latticePositions[index * 3] = latticeSize * (candidate.yaw / LIMITS.yaw) * 0.5;
latticePositions[index * 3 + 1] = latticeSize * (candidate.pitch / LIMITS.pitch) * 0.5;
latticePositions[index * 3 + 2] = latticeSize * (candidate.roll / LIMITS.roll) * 0.5;
});
const latticeGeometry = new THREE.BufferGeometry();
latticeGeometry.setAttribute("position", new THREE.BufferAttribute(latticePositions, 3));
latticeGeometry.setAttribute("color", new THREE.BufferAttribute(latticeColors, 3));
const latticePoints = new THREE.Points(
latticeGeometry,
new THREE.PointsMaterial({
size: 0.047,
vertexColors: true,
transparent: true,
opacity: 0.95,
depthWrite: false
})
);
latticeGroup.add(latticePoints);
const latticeMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.07, 0.013, 6, 24),
new THREE.MeshBasicMaterial({ color: 0xffffff, depthTest: false })
);
latticeMarker.renderOrder = 5;
latticeGroup.add(latticeMarker);
function textSprite(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 64);
ctx.fillStyle = color;
ctx.font = "700 30px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 32);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.scale.set(0.48, 0.12, 1);
return sprite;
}
const yawSprite = textSprite("YAW", "#ffb34d");
yawSprite.position.set(latticeSize * 0.62, -latticeSize * 0.55, 0);
const pitchSprite = textSprite("PITCH", "#4ee39b");
pitchSprite.position.set(-latticeSize * 0.62, latticeSize * 0.62, 0);
const rollSprite = textSprite("ROLL", "#a98cff");
rollSprite.position.set(0, -latticeSize * 0.62, latticeSize * 0.62);
latticeGroup.add(yawSprite, pitchSprite, rollSprite);
// Constraint evaluation.
const evalEuler = new THREE.Euler();
const evalQuaternion = new THREE.Quaternion();
const evalPanel = new THREE.Vector3();
const evalAntenna = new THREE.Vector3();
function angleBetween(a, b) {
return Math.acos(clamp(a.dot(b), -1, 1)) * RAD;
}
function isEarthOccluded(direction) {
const t = EARTH_CENTER.dot(direction);
if (t <= 0) return false;
const closest = direction.clone().multiplyScalar(t);
return closest.distanceTo(EARTH_CENTER) <= EARTH_RADIUS;
}
function evaluate(yaw, pitch, roll) {
evalEuler.set(pitch * DEG, yaw * DEG, roll * DEG, "YXZ");
evalQuaternion.setFromEuler(evalEuler);
evalPanel.copy(PANEL_LOCAL).applyQuaternion(evalQuaternion);
evalAntenna.copy(ANTENNA_LOCAL).applyQuaternion(evalQuaternion);
const panelError = angleBetween(evalPanel, SUN_DIRECTION);
const antennaError = angleBetween(evalAntenna, target.direction);
const occulted = isEarthOccluded(evalAntenna);
const withinBounds =
Math.abs(yaw) <= LIMITS.yaw &&
Math.abs(pitch) <= LIMITS.pitch &&
Math.abs(roll) <= LIMITS.roll;
const panelOK = panelError <= panelLimit + 0.0001;
const antennaOK = antennaError <= antennaLimit + 0.0001;
const safe = withinBounds && !(earthGuard && occulted);
const full = safe && panelOK && antennaOK;
return {
yaw, pitch, roll,
panelError,
antennaError,
panelOK,
antennaOK,
occulted,
withinBounds,
safe,
full,
violation:
Math.max(0, panelError - panelLimit) +
Math.max(0, antennaError - antennaLimit)
};
}
function latticePosition(yaw, pitch, roll) {
return new THREE.Vector3(
latticeSize * (yaw / LIMITS.yaw) * 0.5,
latticeSize * (pitch / LIMITS.pitch) * 0.5,
latticeSize * (roll / LIMITS.roll) * 0.5
);
}
const colorGreen = new THREE.Color(0x4ee39b);
const colorAmber = new THREE.Color(0xffb34d);
const colorRed = new THREE.Color(0xff6477);
const colorCyan = new THREE.Color(0x56d9ff);
function candidateConflictScore(candidate) {
const bothMiss = !candidate.panelOK && !candidate.antennaOK ? 0.25 : 0;
return candidate.violation + bothMiss + candidate.panelError * 0.001 + candidate.antennaError * 0.001;
}
function sortedFeasible() {
return candidates
.filter((candidate) => candidate.full)
.sort((a, b) =>
(a.panelError + a.antennaError) - (b.panelError + b.antennaError)
);
}
function sortedConflicts() {
const conflicts = candidates.filter((candidate) => candidate.safe && !candidate.full);
if (policy === "panel") {
conflicts.sort((a, b) => {
const aRank = (a.panelOK ? 0 : 1000) + a.antennaError + a.violation;
const bRank = (b.panelOK ? 0 : 1000) + b.antennaError + b.violation;
return aRank - bRank;
});
} else if (policy === "comm") {
conflicts.sort((a, b) => {
const aRank = (a.antennaOK ? 0 : 1000) + a.panelError + a.violation;
const bRank = (b.antennaOK ? 0 : 1000) + b.panelError + b.violation;
return aRank - bRank;
});
} else {
conflicts.sort((a, b) => candidateConflictScore(a) - candidateConflictScore(b));
}
return conflicts;
}
function recomputeLattice() {
let full = 0;
let conflict = 0;
let rejected = 0;
candidates.forEach((candidate, index) => {
const result = evaluate(candidate.yaw, candidate.pitch, candidate.roll);
Object.assign(candidate, result);
let color;
if (result.full) {
color = colorGreen;
full++;
} else if (result.safe) {
color = colorAmber;
conflict++;
} else {
color = colorRed;
rejected++;
}
latticeColors[index * 3] = color.r;
latticeColors[index * 3 + 1] = color.g;
latticeColors[index * 3 + 2] = color.b;
});
latticeGeometry.attributes.color.needsUpdate = true;
$("fullCount").textContent = full.toLocaleString();
$("conflictCount").textContent = conflict.toLocaleString();
$("rejectedCount").textContent = rejected.toLocaleString();
$("feasibleTag").textContent = full.toLocaleString();
$("conflictTag").textContent = conflict.toLocaleString();
const message = $("setMessage");
if (full > 0) {
message.classList.add("exists");
message.textContent =
`${full.toLocaleString()} sampled orientations satisfy every enabled constraint. ` +
`${conflict.toLocaleString()} remain safe but unresolved.`;
} else {
message.classList.remove("exists");
message.textContent =
`No sampled orientation satisfies both pointing cones at these limits. ` +
`${conflict.toLocaleString()} safe orientations expose an unresolved trade-off.`;
}
renderCandidateLists();
}
function candidateButton(candidate, isFeasible) {
const button = document.createElement("button");
button.className = "candidate";
button.type = "button";
const left = document.createElement("div");
const attitude = document.createElement("div");
attitude.className = "candidate-attitude";
attitude.textContent =
`Y ${Math.round(candidate.yaw)}° · P ${Math.round(candidate.pitch)}° · R ${Math.round(candidate.roll)}°`;
const detail = document.createElement("div");
detail.className = "candidate-detail";
detail.textContent =
`panel ${candidate.panelError.toFixed(1)}° · antenna ${candidate.antennaError.toFixed(1)}°`;
left.append(attitude, detail);
const tag = document.createElement("span");
tag.className = `candidate-tag${isFeasible ? " full" : ""}`;
if (isFeasible) {
tag.textContent = "FULL";
} else if (candidate.panelOK && !candidate.antennaOK) {
tag.textContent = "COMM MISS";
} else if (!candidate.panelOK && candidate.antennaOK) {
tag.textContent = "PANEL MISS";
} else {
tag.textContent = "CONFLICT";
}
button.append(left, tag);
button.addEventListener("click", () => setAttitude(candidate));
return button;
}
function renderCandidateLists() {
const feasibleList = $("feasibleList");
const conflictList = $("conflictList");
feasibleList.replaceChildren();
conflictList.replaceChildren();
const feasible = sortedFeasible();
const conflicts = sortedConflicts();
if (feasible.length === 0) {
const empty = document.createElement("div");
empty.className = "empty";
empty.textContent =
"No full feasible orientation in the sampled lattice. Loosen a cone or change the target; partial solutions remain listed below.";
feasibleList.append(empty);
} else {
feasible.slice(0, 5).forEach((candidate) => {
feasibleList.append(candidateButton(candidate, true));
});
}
if (conflicts.length === 0) {
const empty = document.createElement("div");
empty.className = "empty";
empty.textContent = "No unresolved safe orientations in this sample.";
conflictList.append(empty);
} else {
conflicts.slice(0, 5).forEach((candidate) => {
conflictList.append(candidateButton(candidate, false));
});
}
}
function setAttitude(attitude) {
selected.yaw = clamp(Math.round(attitude.yaw), -LIMITS.yaw, LIMITS.yaw);
selected.pitch = clamp(Math.round(attitude.pitch), -LIMITS.pitch, LIMITS.pitch);
selected.roll = clamp(Math.round(attitude.roll), -LIMITS.roll, LIMITS.roll);
$("yaw").value = selected.yaw;
$("pitch").value = selected.pitch;
$("roll").value = selected.roll;
updateSelectedUI();
}
const targetQuaternion = new THREE.Quaternion();
const targetEuler = new THREE.Euler();
function updateSelectedUI() {
const result = evaluate(selected.yaw, selected.pitch, selected.roll);
$("yawValue").textContent = `${selected.yaw}°`;
$("pitchValue").textContent = `${selected.pitch}°`;
$("rollValue").textContent = `${selected.roll}°`;
$("attitudeReadout").textContent =
`Y ${selected.yaw}° · P ${selected.pitch}° · R ${selected.roll}°`;
const card = $("statusCard");
const headerStatus = $("headerStatus");
card.classList.remove("feasible", "rejected");
headerStatus.classList.remove("feasible", "rejected");
if (!result.withinBounds) {
$("statusText").textContent = "Rejected attitude";
$("statusDetail").textContent = "The selected orientation is outside the bounded yaw, pitch, or roll envelope.";
headerStatus.textContent = "Out of bounds";
headerStatus.classList.add("rejected");
card.classList.add("rejected");
} else if (earthGuard && result.occluded) {
$("statusText").textContent = "Rejected: Earth occultation";
$("statusDetail").textContent = "The antenna boresight intersects Earth. This orientation cannot be used.";
headerStatus.textContent = "Earth occulted";
headerStatus.classList.add("rejected");
card.classList.add("rejected");
} else if (result.full) {
$("statusText").textContent = "Feasible orientation";
$("statusDetail").textContent = "Panel illumination, communication pointing, attitude bounds, and line of sight all pass.";
headerStatus.textContent = "All constraints met";
headerStatus.classList.add("feasible");
card.classList.add("feasible");
} else {
$("statusText").textContent = "Unresolved pointing conflict";
const missed = [];
if (!result.panelOK) missed.push("panel Sun cone");
if (!result.antennaOK) missed.push("antenna boresight cone");
$("statusDetail").textContent =
`${missed.join(" and ")} not satisfied. The selected attitude is safe but not a full solution.`;
headerStatus.textContent = "Unresolved conflict";
}
const haloColor = result.full ? 0x4ee39b :
(result.withinBounds && !(earthGuard && result.occluded)) ? 0xffb34d : 0xff6477;
statusHalo.material.color.setHex(haloColor);
panelArrow.setColor(result.panelOK ? 0x4ee39b : 0xff6477);
antennaArrow.setColor(result.antennaOK ? 0x4ee39b : 0xff6477);
latticeMarker.position.copy(
latticePosition(selected.yaw, selected.pitch, selected.roll)
);
targetEuler.set(
selected.pitch * DEG,
selected.yaw * DEG,
selected.roll * DEG,
"YXZ"
);
targetQuaternion.setFromEuler(targetEuler);
renderAudit(result);
}
function auditRow(status, title, subtitle, value) {
const row = document.createElement("div");
row.className = `check ${status}`;
const icon = document.createElement("div");
icon.className = "check-icon";
icon.textContent = status === "pass" ? "✓" : "×";
const text = document.createElement("div");
const titleElement = document.createElement("div");
titleElement.className = "check-title";
titleElement.textContent = title;
const subtitleElement = document.createElement("div");
subtitleElement.className = "check-sub";
subtitleElement.textContent = subtitle;
text.append(titleElement, subtitleElement);
const valueElement = document.createElement("div");
valueElement.className = "check-value";
valueElement.textContent = value;
row.append(icon, text, valueElement);
return row;
}
function renderAudit(result) {
const audit = $("constraintAudit");
audit.replaceChildren();
audit.append(
auditRow(
result.withinBounds ? "pass" : "fail",
"Attitude envelope",
"Yaw ±65°, pitch ±40°, roll ±45°",
result.withinBounds ? "IN BOUNDS" : "OUT"
),
auditRow(
result.panelOK ? "pass" : "fail",
"Panel illumination",
`Required error ≤ ${panelLimit}°`,
`${result.panelError.toFixed(1)}°`
),
auditRow(
result.antennaOK ? "pass" : "fail",
"Antenna boresight",
`Required error ≤ ${antennaLimit}°`,
`${result.antennaError.toFixed(1)}°`
),
auditRow(
earthGuard ? (result.occluded ? "fail" : "pass") : "neutral",
"Earth line of sight",
earthGuard ? "Ray/Earth intersection guard" : "Guard disabled; not enforced",
earthGuard ? (result.occluded ? "OCCLUDED" : "CLEAR") : "OFF"
)
);
}
function selectBest() {
let pool;
if (policy === "strict") {
const feasible = sortedFeasible();
pool = feasible.length ? feasible : sortedConflicts();
} else if (policy === "panel") {
pool = candidates
.filter((candidate) => candidate.safe && candidate.panelOK)
.sort((a, b) => a.antennaError - b.antennaError);
} else {
pool = candidates
.filter((candidate) => candidate.safe && candidate.antennaOK)
.sort((a, b) => a.panelError - b.panelError);
}
if (!pool.length) {
pool = sortedConflicts();
}
if (pool.length) setAttitude(pool[0]);
}
$("panelLimit").addEventListener("input", (event) => {
panelLimit = Number(event.target.value);
$("panelLimitValue").textContent = `${panelLimit}°`;
updateCone(panelCone, panelLimit, 1.38);
recomputeLattice();
updateSelectedUI();
});
$("antennaLimit").addEventListener("input", (event) => {
antennaLimit = Number(event.target.value);
$("antennaLimitValue").textContent = `${antennaLimit}°`;
updateCone(antennaCone, antennaLimit, 1.42);
recomputeLattice();
updateSelectedUI();
});
$("earthGuard").addEventListener("change", (event) => {
earthGuard = event.target.checked;
recomputeLattice();
updateSelectedUI();
});
$("targetSelect").addEventListener("change", (event) => {
targetKey = event.target.value;
updateTargetVisual();
recomputeLattice();
updateSelectedUI();
});
$("policySelect").addEventListener("change", (event) => {
policy = event.target.value;
renderCandidateLists();
});
["yaw", "pitch", "roll"].forEach((name) => {
$(name).addEventListener("input", (event) => {
selected[name] = Number(event.target.value);
updateSelectedUI();
});
});
$("bestButton").addEventListener("click", selectBest);
// Project DOM labels into the scene.
const labelPoint = new THREE.Vector3();
function placeLabel(element, worldPosition) {
labelPoint.copy(worldPosition).project(camera);
const visible =
labelPoint.z > -1 &&
labelPoint.z < 1 &&
labelPoint.x > -1.1 &&
labelPoint.x < 1.1 &&
labelPoint.y > -1.1 &&
labelPoint.y < 1.1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (labelPoint.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-labelPoint.y * 0.5 + 0.5) * viewport.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const panelTip = new THREE.Vector3();
const antennaTip = new THREE.Vector3();
function updateLabels() {
placeLabel($("labelSun"), sunGroup.position);
placeLabel($("labelTarget"), relayGroup.position);
placeLabel($("labelPanel"), panelTip.set(0, 0, 1.86).applyMatrix4(craftRoot.matrixWorld));
placeLabel(
$("labelAntenna"),
antennaTip.set(2.02, 0.43, 0.08).applyMatrix4(craftRoot.matrixWorld)
);
placeLabel(
$("labelLattice"),
latticeGroup.position.clone().add(new THREE.Vector3(0, 0.93, 0))
);
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
updateTargetVisual();
updateCone(panelCone, panelLimit, 1.38);
updateCone(antennaCone, antennaLimit, 1.42);
recomputeLattice();
updateSelectedUI();
// Initialize the spacecraft directly, then use restrained interpolation.
craftRoot.quaternion.copy(targetQuaternion);
function animate() {
requestAnimationFrame(animate);
craftRoot.quaternion.slerp(targetQuaternion, 0.14);
craftRoot.updateMatrixWorld(true);
statusHalo.quaternion.copy(camera.quaternion);
latticeMarker.quaternion.copy(camera.quaternion);
sunHalo.rotation.y += 0.003;
relayRing.rotation.x += 0.004;
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```