mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Read flight and military billboard state from the app's mirror
Flights and military now add their billboards through addBillboard and write show, position, scale, rotation, size and distance scaling through setBillboard, which keeps the app's copy in src/data/billboardMirror.js. Their reads go to billboardState instead of the Cesium billboard, so the layers no longer read back what they pushed to the renderer. A mirrored billboard needs an explicit width and height, because unset Cesium reports the loaded image's size. Colour is not mirrored yet: the cyber-sonar theme writes it too and tells the writers apart by the live value, so it moves with the effects port.
This commit is contained in:
1 parent
7ebc73393a
commit
bb91688a62
23 files changed
+424
-172
No files matched your search
@@ -39,6 +39,7 @@ import {
|
||||
} from './policy.js';
|
||||
import { AIRCRAFT_ENVIRONMENT_MAP_OPTIONS } from '../../data/aircraftModelLighting.js';
|
||||
import { aircraftVisuals } from '../aircraft/visualState.js';
|
||||
import { billboardState, setBillboard } from '../../data/billboardMirror.js';
|
||||
|
||||
export function createRendering({
|
||||
flightState,
|
||||
@@ -151,12 +152,12 @@ export function createRendering({
|
||||
if (isCockpitContact && !isCockpitNear) {
|
||||
const freshnessAlpha = cyberSonarBaseAlpha(bb);
|
||||
bb.image = cockpitContactDotImage();
|
||||
bb.width = COCKPIT_CONTACT_SIZE_PX;
|
||||
bb.height = COCKPIT_CONTACT_SIZE_PX;
|
||||
bb.scale = limbScale;
|
||||
bb.scaleByDistance = _cockpitBillboardScaleByDistance();
|
||||
setBillboard(bb, 'width', COCKPIT_CONTACT_SIZE_PX);
|
||||
setBillboard(bb, 'height', COCKPIT_CONTACT_SIZE_PX);
|
||||
setBillboard(bb, 'scale', limbScale);
|
||||
setBillboard(bb, 'scaleByDistance', _cockpitBillboardScaleByDistance());
|
||||
bb.color = _cockpitContactColor(icao24).withAlpha(freshnessAlpha);
|
||||
bb.rotation = 0;
|
||||
setBillboard(bb, 'rotation', 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,10 +166,14 @@ export function createRendering({
|
||||
_iconKind(icao24, meta?.klass),
|
||||
aircraftVisuals.read(bb)?.iconLarge ? TRACKED_ICON_PX : undefined,
|
||||
);
|
||||
bb.width = icao24 === flightState._trackedIcao ? 24 : 20;
|
||||
bb.height = icao24 === flightState._trackedIcao ? 24 : 20;
|
||||
bb.scale = _fleetBillboardScale(icao24, meta?.klass) * limbScale;
|
||||
bb.scaleByDistance = _normalBillboardScaleByDistance();
|
||||
setBillboard(bb, 'width', icao24 === flightState._trackedIcao ? 24 : 20);
|
||||
setBillboard(bb, 'height', icao24 === flightState._trackedIcao ? 24 : 20);
|
||||
setBillboard(
|
||||
bb,
|
||||
'scale',
|
||||
_fleetBillboardScale(icao24, meta?.klass) * limbScale,
|
||||
);
|
||||
setBillboard(bb, 'scaleByDistance', _normalBillboardScaleByDistance());
|
||||
bb.color = _fleetBillboardColor(icao24).withAlpha(cyberSonarBaseAlpha(bb));
|
||||
}
|
||||
|
||||
@@ -324,7 +329,7 @@ export function createRendering({
|
||||
|
||||
function _driveFleetModelHandoff(icao24, model, bb, pos, course, beforeShow) {
|
||||
if (!model) {
|
||||
bb.show = true;
|
||||
setBillboard(bb, 'show', true);
|
||||
return false;
|
||||
}
|
||||
const displayPos = _modelDisplayPosition(
|
||||
@@ -334,7 +339,7 @@ export function createRendering({
|
||||
);
|
||||
if (!displayPos) {
|
||||
model.show = false; // no ground evidence → nothing safe to place a depth-tested model at
|
||||
bb.show = true;
|
||||
setBillboard(bb, 'show', true);
|
||||
return false;
|
||||
}
|
||||
// The matrix is written BEFORE the readiness test on purpose: a model can flip
|
||||
@@ -343,12 +348,12 @@ export function createRendering({
|
||||
_modelMatrix(displayPos, course, model.modelMatrix);
|
||||
if (!model.ready) {
|
||||
model.show = false; // not loaded yet → keep the 2D icon, no half-model flash
|
||||
bb.show = true;
|
||||
setBillboard(bb, 'show', true);
|
||||
return false;
|
||||
}
|
||||
beforeShow?.();
|
||||
if (!model.show) model.show = true;
|
||||
if (bb.show) bb.show = false; // hand off ONLY once the model renders
|
||||
if (billboardState(bb).show) setBillboard(bb, 'show', false); // hand off ONLY once the model renders
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -437,7 +442,8 @@ export function createRendering({
|
||||
(!current && flightState._modelPending.has(icao24))
|
||||
) {
|
||||
const bb = flightState._billboards.get(icao24);
|
||||
if (bb && icao24 !== flightState._trackedIcao) bb.show = true;
|
||||
if (bb && icao24 !== flightState._trackedIcao)
|
||||
setBillboard(bb, 'show', true);
|
||||
_releaseModel(icao24);
|
||||
}
|
||||
if (
|
||||
@@ -472,7 +478,8 @@ export function createRendering({
|
||||
)
|
||||
continue; // already right state
|
||||
const bb = flightState._billboards.get(icao);
|
||||
if (bb && icao !== flightState._trackedIcao) bb.show = true;
|
||||
if (bb && icao !== flightState._trackedIcao)
|
||||
setBillboard(bb, 'show', true);
|
||||
_releaseModel(icao);
|
||||
}
|
||||
if (flightState._irReloadQueue.length === 0)
|
||||
@@ -699,7 +706,8 @@ export function createRendering({
|
||||
// readout consumers then reuse that exact cached position.
|
||||
const pos =
|
||||
parts.motion._trackedDisplayPosition(flightState._trackedIcao) ||
|
||||
flightState._billboards.get(flightState._trackedIcao)?.position;
|
||||
billboardState(flightState._billboards.get(flightState._trackedIcao))
|
||||
?.position;
|
||||
if (!pos) {
|
||||
if (flightState._trackedModel) flightState._trackedModel.show = false;
|
||||
return;
|
||||
@@ -777,7 +785,9 @@ export function createRendering({
|
||||
// default here produces a one-frame jump to the Earth's center.
|
||||
const currentPos =
|
||||
parts.motion._trackedDisplayCached() ||
|
||||
flightState._billboards.get(flightState._trackedIcao)?.position;
|
||||
billboardState(
|
||||
flightState._billboards.get(flightState._trackedIcao),
|
||||
)?.position;
|
||||
if (currentPos) {
|
||||
const displayPos = _modelDisplayPosition(
|
||||
flightState._trackedIcao,
|
||||
@@ -938,12 +948,10 @@ export function createRendering({
|
||||
// ground or in the air — no distinction"). The cap + nearest-first ordering
|
||||
// below already bound airport clusters; grounded placement is handled by the
|
||||
// one-shot ground snap in _modelDisplayPosition.
|
||||
const d2 = Cesium.Cartesian3.distanceSquared(camPos, bb.position);
|
||||
const { position } = billboardState(bb);
|
||||
const d2 = Cesium.Cartesian3.distanceSquared(camPos, position);
|
||||
if (d2 > keepDistSq) continue; // beyond the keep radius → never eligible
|
||||
Cesium.Cartesian3.clone(
|
||||
bb.position,
|
||||
flightState._scratchModelBS.center,
|
||||
);
|
||||
Cesium.Cartesian3.clone(position, flightState._scratchModelBS.center);
|
||||
cand.push([
|
||||
icao,
|
||||
d2,
|
||||
@@ -973,6 +981,7 @@ export function createRendering({
|
||||
|
||||
for (const [icao24, bb] of flightState._billboards) {
|
||||
if (icao24 === flightState._trackedIcao) continue; // tracked entity owns its own motion
|
||||
const icon = billboardState(bb);
|
||||
|
||||
const info = flightState.records.data.get(icao24);
|
||||
|
||||
@@ -996,9 +1005,9 @@ export function createRendering({
|
||||
// collection's vertex buffer, so skip sub-meter moves.
|
||||
if (
|
||||
display &&
|
||||
Cesium.Cartesian3.distanceSquared(display, bb.position) > 1.0
|
||||
Cesium.Cartesian3.distanceSquared(display, icon.position) > 1.0
|
||||
) {
|
||||
bb.position = display;
|
||||
setBillboard(bb, 'position', display);
|
||||
}
|
||||
|
||||
// Round 6: occlusion-test a LIFTED point for contacts rendering below
|
||||
@@ -1007,15 +1016,15 @@ export function createRendering({
|
||||
// pass would hide a plane that is really just low over high-N terrain
|
||||
// waiting for its floor to warm (ATL grounded contacts at geoid −31 m).
|
||||
const beyondHorizon = !occluder.isPointVisible(
|
||||
flightState._cullPositions.get(icao24) || bb.position,
|
||||
flightState._cullPositions.get(icao24) || icon.position,
|
||||
);
|
||||
// A billboard flipping INTO view (horizon reveal while the camera idles)
|
||||
// gets its rotation refreshed THIS tick even without a pose change —
|
||||
// otherwise it reappears wearing its stale (often creation-north) nose for
|
||||
// up to ROTATION_REFRESH_MS. (Model-handed-off planes also read show=false
|
||||
// here; harmless — the model branch below `continue`s past the rotation.)
|
||||
const revealed = !beyondHorizon && !bb.show;
|
||||
if (bb.show === beyondHorizon) bb.show = !beyondHorizon;
|
||||
const revealed = !beyondHorizon && !icon.show;
|
||||
if (icon.show === beyondHorizon) setBillboard(bb, 'show', !beyondHorizon);
|
||||
if (beyondHorizon) {
|
||||
// Also hide any 3D model — otherwise a model that crossed the limb would keep
|
||||
// rendering through the hidden globe at its last matrix.
|
||||
@@ -1031,22 +1040,22 @@ export function createRendering({
|
||||
// alpha; nearer focus behavior remains tunable rather than universal.
|
||||
const cameraDistanceM = Cesium.Cartesian3.distance(
|
||||
camera.positionWC,
|
||||
bb.position,
|
||||
icon.position,
|
||||
);
|
||||
const distanceScale = nearFarScalarValueAtDistance(
|
||||
bb.scaleByDistance,
|
||||
icon.scaleByDistance,
|
||||
cameraDistanceM,
|
||||
);
|
||||
const focus = advanceProjectedSpriteFocus(
|
||||
bb,
|
||||
bb.position,
|
||||
icon.position,
|
||||
scene,
|
||||
camera,
|
||||
nowMs,
|
||||
focusTarget,
|
||||
undefined,
|
||||
(bb.width || 20) * (bb.scale || 1) * distanceScale * 0.5,
|
||||
(bb.height || 20) * (bb.scale || 1) * distanceScale * 0.5,
|
||||
(icon.width || 20) * (icon.scale || 1) * distanceScale * 0.5,
|
||||
(icon.height || 20) * (icon.scale || 1) * distanceScale * 0.5,
|
||||
);
|
||||
const isCockpitNear =
|
||||
flightState._cockpitContactMode &&
|
||||
@@ -1077,8 +1086,8 @@ export function createRendering({
|
||||
// hysteresis so zoom oscillation never thrashes the atlas.
|
||||
if (!flightState._cockpitContactMode || isCockpitNear) {
|
||||
const glyphDevPx =
|
||||
(bb.width || 20) *
|
||||
(bb.scale || 1) *
|
||||
(icon.width || 20) *
|
||||
(icon.scale || 1) *
|
||||
distanceScale *
|
||||
(globalThis.devicePixelRatio || 1);
|
||||
const visual = aircraftVisuals.write(bb);
|
||||
@@ -1160,12 +1169,12 @@ export function createRendering({
|
||||
) {
|
||||
const rot = screenProjectedRotation(
|
||||
scene,
|
||||
bb.position,
|
||||
icon.position,
|
||||
course,
|
||||
bb.rotation,
|
||||
icon.rotation,
|
||||
);
|
||||
if (rot !== null && Math.abs(rot - bb.rotation) > 0.002) {
|
||||
bb.rotation = rot;
|
||||
if (rot !== null && Math.abs(rot - icon.rotation) > 0.002) {
|
||||
setBillboard(bb, 'rotation', rot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user