mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(vessels, transit, rail): fleet models keep their cards and detection, stand on the floor, clip ships at the waterline and follow NVG/FLIR
- a vehicle drawn as a model keeps its selected card and stays in the detection overlay - transit and rail models drop the 1.5 m floor lift their icons carry - vessel models are clipped below the waterline - models switch to an unlit white look under NVG/FLIR and back - unknown transit modes keep their icon - aircraft model specs are cached per set; no key-array copies per frame
This commit is contained in:
1 parent
058ed0ffeb
commit
a44c42eb94
11 files changed
+342
-89
No files matched your search
@@ -224,8 +224,11 @@ export function createRendering({
|
||||
// on the aircraft layers' icon-to-model rules (services.fleet). The fleet
|
||||
// set loads once, up front, when the layer starts.
|
||||
let fleetModels = null;
|
||||
/** Items drawn last frame, and the map the next frame's are gathered into. */
|
||||
let modelItems = new Map();
|
||||
let spareItems = new Map();
|
||||
let modelCandidatesAtMs = -Infinity;
|
||||
const modelOccluder = new Cesium.EllipsoidalOccluder(Cesium.Ellipsoid.WGS84);
|
||||
|
||||
function ensureModels(viewer) {
|
||||
const fleet = services.fleet;
|
||||
@@ -238,96 +241,109 @@ export function createRendering({
|
||||
display: fleet.display,
|
||||
policy: fleet.policy,
|
||||
resolveAsset: fleet.resolveAsset,
|
||||
// A hull below the waterline would show through a plain globe.
|
||||
waterline: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a vessel's chevron is drawn: on the camera's side of the Earth,
|
||||
* not the bridge camera's own vessel, and not drawn by its model. The
|
||||
* visibility pass and the model handoff both decide by this.
|
||||
*/
|
||||
function billboardShown(record, occluder) {
|
||||
const visual = getVisual(record);
|
||||
return (
|
||||
isVisible(visual.surfacePosition, occluder) &&
|
||||
record.id !== state.cockpitSubjectId &&
|
||||
!visual.modelOwnsVisual
|
||||
);
|
||||
}
|
||||
|
||||
/** The model item for `record`, its spec rebuilt only when its type or size changes. */
|
||||
function modelItem(record, set) {
|
||||
let item = modelItems.get(record.id);
|
||||
if (!item || item.record !== record)
|
||||
item = { record, pickId: record, tint: null, modelOwnsVisual: false };
|
||||
const specKey = `${record.type}|${record.length}|${record.beam}|${record.name}`;
|
||||
if (!item) {
|
||||
item = { pickId: record, tint: null, modelOwnsVisual: false };
|
||||
modelItems.set(record.id, item);
|
||||
}
|
||||
if (item.specKey !== specKey) {
|
||||
item.specKey = specKey;
|
||||
item.spec = vesselModelSpec(set, record);
|
||||
}
|
||||
const visual = getVisual(record);
|
||||
item.record = record;
|
||||
item.position = visual.waterline;
|
||||
item.position = getVisual(record).waterline;
|
||||
item.headingDeg = vesselCourseDeg(record);
|
||||
item.show = record.id !== state.cockpitSubjectId;
|
||||
return item;
|
||||
}
|
||||
|
||||
/** Gather the vessels within the models' keep radius of the camera. */
|
||||
function gatherModelItems(set, prefs) {
|
||||
/** Gather the vessels within the models' keep radius of the camera into `into`. */
|
||||
function gatherModelItems(set, into) {
|
||||
const camera = state.viewer?.camera;
|
||||
if (!camera?.positionWC) return;
|
||||
const policy = services.fleet.policy;
|
||||
const keepM =
|
||||
prefs?.models3dMode === 'all' ? policy.keepAllM : policy.keepM;
|
||||
const next = new Map();
|
||||
if (camera?.positionWC) {
|
||||
const limitSq = keepM * keepM * 1.44;
|
||||
for (const record of state.records.all) {
|
||||
const visual = getVisual(record);
|
||||
if (!visual.waterline) continue;
|
||||
if (
|
||||
Cesium.Cartesian3.distanceSquared(
|
||||
camera.positionWC,
|
||||
visual.waterline,
|
||||
) > limitSq
|
||||
)
|
||||
continue;
|
||||
next.set(record.id, modelItem(record, set));
|
||||
}
|
||||
services.fleet.display?.()?.models3dMode === 'all'
|
||||
? policy.keepAllM
|
||||
: policy.keepM;
|
||||
const limitSq = keepM * keepM * 1.44;
|
||||
for (const record of state.records.all) {
|
||||
const waterline = getVisual(record).waterline;
|
||||
if (!waterline) continue;
|
||||
if (
|
||||
Cesium.Cartesian3.distanceSquared(camera.positionWC, waterline) >
|
||||
limitSq
|
||||
)
|
||||
continue;
|
||||
into.set(record.id, modelItem(record, set));
|
||||
}
|
||||
for (const [id, item] of modelItems)
|
||||
if (!next.has(id)) handBackVisual(item);
|
||||
modelItems = next;
|
||||
}
|
||||
|
||||
/** Give a vessel's icon back when its model no longer draws it. */
|
||||
function handBackVisual(item) {
|
||||
if (!item.ownedBillboard) return;
|
||||
item.ownedBillboard = false;
|
||||
const billboard = getVisual(item.record).billboard;
|
||||
if (billboard)
|
||||
billboard.show =
|
||||
isVisible(getVisual(item.record).surfacePosition, makeOccluder()) &&
|
||||
item.record.id !== state.cockpitSubjectId;
|
||||
/** Give a vessel's chevron back when its model no longer draws it. */
|
||||
function handBackVisual(record, occluder) {
|
||||
const visual = getVisual(record);
|
||||
if (!visual.modelOwnsVisual) return;
|
||||
visual.modelOwnsVisual = false;
|
||||
if (visual.billboard)
|
||||
visual.billboard.show = billboardShown(record, occluder);
|
||||
}
|
||||
|
||||
function updateModels() {
|
||||
if (!fleetModels) return;
|
||||
const camera = state.viewer?.camera;
|
||||
const occluder = camera?.positionWC ? modelOccluder : null;
|
||||
if (occluder) occluder.cameraPosition = camera.positionWC;
|
||||
if (!fleetModels.active()) {
|
||||
if (modelItems.size) {
|
||||
modelItems.clear();
|
||||
fleetModels.frame(modelItems, performance.now());
|
||||
for (const item of modelItems.values()) handBackVisual(item);
|
||||
modelItems = new Map();
|
||||
for (const record of state.records.all)
|
||||
handBackVisual(record, occluder);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const set = fleetModelSet();
|
||||
const now = performance.now();
|
||||
const next = spareItems;
|
||||
next.clear();
|
||||
if (now - modelCandidatesAtMs >= MODEL_CANDIDATES_MS) {
|
||||
modelCandidatesAtMs = now;
|
||||
gatherModelItems(set, services.fleet.display?.());
|
||||
gatherModelItems(set, next);
|
||||
} else {
|
||||
for (const [id, item] of modelItems) {
|
||||
for (const [id, item] of modelItems)
|
||||
if (state.records.byId.get(id) === item.record)
|
||||
modelItem(item.record, set);
|
||||
else modelItems.delete(id);
|
||||
}
|
||||
next.set(id, modelItem(item.record, set));
|
||||
}
|
||||
for (const [id, item] of modelItems)
|
||||
if (next.get(id) !== item) handBackVisual(item.record, occluder);
|
||||
spareItems = modelItems;
|
||||
modelItems = next;
|
||||
fleetModels.frame(modelItems, now);
|
||||
for (const item of modelItems.values()) {
|
||||
const billboard = getVisual(item.record).billboard;
|
||||
const visual = getVisual(item.record);
|
||||
if (item.modelOwnsVisual) {
|
||||
item.ownedBillboard = true;
|
||||
if (billboard) billboard.show = false;
|
||||
} else handBackVisual(item);
|
||||
visual.modelOwnsVisual = true;
|
||||
if (visual.billboard) visual.billboard.show = false;
|
||||
} else handBackVisual(item.record, occluder);
|
||||
}
|
||||
if (fleetModels.settling) governorRequestRender('ais-vessels-models');
|
||||
}
|
||||
@@ -336,6 +352,7 @@ export function createRendering({
|
||||
fleetModels?.destroy();
|
||||
fleetModels = null;
|
||||
modelItems = new Map();
|
||||
spareItems = new Map();
|
||||
modelCandidatesAtMs = -Infinity;
|
||||
}
|
||||
|
||||
@@ -443,10 +460,11 @@ export function createRendering({
|
||||
const visible = isVisible(visual.surfacePosition, occluder);
|
||||
if (visual.billboard) {
|
||||
// The bridge camera sits on this sprite; showing it would fill the view.
|
||||
// The same rule as billboardShown, its horizon test already made.
|
||||
visual.billboard.show =
|
||||
visible &&
|
||||
record.id !== state.cockpitSubjectId &&
|
||||
!modelItems.get(record.id)?.ownedBillboard;
|
||||
!visual.modelOwnsVisual;
|
||||
if (visible && doRotations && scene) {
|
||||
const rot = screenProjectedRotation(
|
||||
scene,
|
||||
@@ -724,8 +742,9 @@ export function createRendering({
|
||||
fleetModels?.setVisible(show);
|
||||
if (!show && fleetModels) {
|
||||
fleetModels.clear();
|
||||
for (const item of modelItems.values()) item.ownedBillboard = false;
|
||||
modelItems = new Map();
|
||||
for (const item of modelItems.values())
|
||||
getVisual(item.record).modelOwnsVisual = false;
|
||||
modelItems.clear();
|
||||
}
|
||||
vesselState._vesselOverlayHost.setVisible(VESSEL_OVERLAY_SOURCE_ID, show);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user