mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Settle the draw decisions in the renderer contract
- lodGroup links items across sets as one thing at different detail; picks name the member shown and report the group. displayRange is half-open. - An orbits capability: the renderer propagates two-line elements with SGP4 on the set's motion clock. The stub propagates with satellite.js. - Height queries see draw sets only with includeInHeightQueries (was excludeFromHeightQueries); HeightSample.source gains 'set'. - courseGlide is a capability; courseBlendMs eases the course on every renderer. - Arc segments climb at climbMps; a negative minDtS stays for the aircraft warm-up. - The star catalogue is optional, a hidden column row keeps its motion, and draw.clampState() reports the drape fallback. Checks cover the climb and warm-up, lodGroup ranges, orbits against SGP4 (with and without motionSegments), hidden rows resuming, and sets not answering height queries by default.
This commit is contained in:
1 parent
8db995acfc
commit
b7c26351f7
10 files changed
+597
-21
No files matched your search
@@ -12,6 +12,7 @@
|
||||
import { CAPABILITIES, CONTRACT_VERSION } from '../contract/index.js';
|
||||
import { createStubCamera } from './camera.js';
|
||||
import { motionPosition } from './motion.js';
|
||||
import { orbitPosition } from './orbits.js';
|
||||
import { computeViewRectangle } from './viewRectangle.js';
|
||||
import {
|
||||
add,
|
||||
@@ -408,6 +409,7 @@ export function createStubRenderer(options = {}) {
|
||||
return handle;
|
||||
}
|
||||
|
||||
const clampListeners = [];
|
||||
const draw = {
|
||||
icons: (spec) => makeSet('icons', spec),
|
||||
points: (spec) => makeSet('points', spec),
|
||||
@@ -417,6 +419,18 @@ export function createStubRenderer(options = {}) {
|
||||
atlases.set(id, { ...images });
|
||||
log('draw', 'atlas', [id]);
|
||||
},
|
||||
// The stub drapes wherever it is asked to: it never falls back.
|
||||
clampState: () => 'draped',
|
||||
on(event, cb) {
|
||||
if (event !== 'clampState') return () => {};
|
||||
const entry = { cb, live: true };
|
||||
clampListeners.push(entry);
|
||||
return () => {
|
||||
entry.live = false;
|
||||
const i = clampListeners.indexOf(entry);
|
||||
if (i >= 0) clampListeners.splice(i, 1);
|
||||
};
|
||||
},
|
||||
};
|
||||
if (capabilities.has('models'))
|
||||
draw.models = (spec) => makeSet('models', spec);
|
||||
@@ -425,6 +439,10 @@ export function createStubRenderer(options = {}) {
|
||||
draw.meshes = (spec) => makeSet('meshes', spec);
|
||||
if (capabilities.has('agents'))
|
||||
draw.agents = (spec) => makeSet('agents', spec);
|
||||
/** Parsed orbit elements, by line pair; cleared on destroy. */
|
||||
const satrecs = new Map();
|
||||
if (capabilities.has('orbits'))
|
||||
draw.orbits = (spec) => makeSet('orbits', spec);
|
||||
if (capabilities.has('fields'))
|
||||
draw.field = (spec) => {
|
||||
const handle = simpleHandle('field', spec);
|
||||
@@ -528,6 +546,10 @@ export function createStubRenderer(options = {}) {
|
||||
}
|
||||
|
||||
function itemPosition(set, item, aheadMs = 0) {
|
||||
if (set.kind === 'orbits')
|
||||
return item.tle
|
||||
? orbitPosition(satrecs, item.tle, motionTime(set) + aheadMs)
|
||||
: null;
|
||||
if (!item.pos) return null;
|
||||
const base = toEcef(item.pos);
|
||||
if (
|
||||
@@ -556,17 +578,25 @@ export function createStubRenderer(options = {}) {
|
||||
if (
|
||||
set.kind !== 'icons' &&
|
||||
set.kind !== 'points' &&
|
||||
set.kind !== 'models'
|
||||
set.kind !== 'models' &&
|
||||
set.kind !== 'orbits'
|
||||
)
|
||||
continue;
|
||||
for (const item of set.items.values()) {
|
||||
if (item.show === false || item.pickable === false) continue;
|
||||
const p = itemPosition(set, item);
|
||||
if (!p || isOccluded(p)) continue;
|
||||
if (item.displayRange) {
|
||||
const distance = magnitude(sub(p, eye().position));
|
||||
const [nearM, farM] = item.displayRange;
|
||||
if (distance < nearM || distance >= farM) continue;
|
||||
}
|
||||
const s = project(p);
|
||||
if (!s) continue;
|
||||
const pixel = item.pixelSize ?? item.marker?.pixelSize ?? 10;
|
||||
const size = item.pickProxy?.size ??
|
||||
item.size ?? [item.pixelSize ?? 10, item.pixelSize ?? 10];
|
||||
item.size ??
|
||||
item.marker?.size ?? [pixel, pixel];
|
||||
if (
|
||||
Math.abs(s.x - x) <= size[0] / 2 + halfW &&
|
||||
Math.abs(s.y - y) <= size[1] / 2 + halfH
|
||||
@@ -575,6 +605,7 @@ export function createStubRenderer(options = {}) {
|
||||
set: setId,
|
||||
id: item.id,
|
||||
meta: item.meta,
|
||||
...(item.lodGroup !== undefined ? { lodGroup: item.lodGroup } : {}),
|
||||
surface: false,
|
||||
position: p,
|
||||
depth: magnitude(sub(p, eye().position)),
|
||||
@@ -1166,6 +1197,7 @@ export function createStubRenderer(options = {}) {
|
||||
for (const clear of onceTimers) clear();
|
||||
onceTimers.clear();
|
||||
sets.clear();
|
||||
satrecs.clear();
|
||||
},
|
||||
testing: {
|
||||
/** Run one frame of the loop; true when it drew. */
|
||||
|
||||
@@ -44,8 +44,12 @@ export function motionPosition(segment, pos, t) {
|
||||
east = (v / w) * (Math.cos(track) - Math.cos(track + w * dt));
|
||||
north = (v / w) * (Math.sin(track + w * dt) - Math.sin(track));
|
||||
}
|
||||
const up = (segment.climbMps ?? 0) * dt;
|
||||
const enu = eastNorthUp(segment.fix);
|
||||
return add(segment.fix, add(scale(enu.x, east), scale(enu.y, north)));
|
||||
return add(
|
||||
segment.fix,
|
||||
add(add(scale(enu.x, east), scale(enu.y, north)), scale(enu.z, up)),
|
||||
);
|
||||
}
|
||||
default:
|
||||
throw new Error(`unknown motion segment ${segment.kind}`);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @module render/stub/orbits
|
||||
* @description Where an orbit item is at a time: its two-line elements
|
||||
* propagated with SGP4 and turned into Earth-fixed metres.
|
||||
*/
|
||||
import { eciToEcf, gstime, propagate, twoline2satrec } from 'satellite.js';
|
||||
|
||||
/**
|
||||
* @param {Map<string, object>} satrecs Parsed elements by line pair, the caller's cache.
|
||||
* @param {[string, string]} tle
|
||||
* @param {number} t Epoch ms.
|
||||
* @returns {{x: number, y: number, z: number}|null} ECEF metres, or null when the elements cannot be propagated to `t`.
|
||||
*/
|
||||
export function orbitPosition(satrecs, tle, t) {
|
||||
const key = `${tle[0]}\n${tle[1]}`;
|
||||
let satrec = satrecs.get(key);
|
||||
if (!satrec) {
|
||||
satrec = twoline2satrec(tle[0], tle[1]);
|
||||
satrecs.set(key, satrec);
|
||||
}
|
||||
const date = new Date(t);
|
||||
const state = propagate(satrec, date);
|
||||
const eci = state?.position;
|
||||
if (!eci || typeof eci !== 'object') return null;
|
||||
const ecf = eciToEcf(eci, gstime(date));
|
||||
return { x: ecf.x * 1000, y: ecf.y * 1000, z: ecf.z * 1000 };
|
||||
}
|
||||
Reference in new issue
Block a user