mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
3D models only within 3 km of the camera, at true size
An aircraft, vessel, transit or rail vehicle now draws as its 3D model only when it is within 3 km of the camera, and as its icon farther away. A model already drawn is kept out to 3.6 km, so a vehicle on the edge does not flicker. Proximity and All use the same distance and still differ by how many models they allow (150 and 350). Models are drawn at their true size: the minimum pixel size that inflated distant models is gone. The camera altitude above which no model is considered is now the highest aircraft the layers draw (30 km) plus the 3.6 km, so a camera high above the ground still models an aircraft close to it. Cockpit's aircraft silhouettes keep their own 150/185 km and 400/450 km bands, since they are icons.
This commit is contained in:
1 parent
624c229bc2
commit
36624cd329
22 files changed
+260
-181
No files matched your search
@@ -4,25 +4,18 @@ import { createAircraftModels } from './aircraftModelLayer.js';
|
||||
import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { fromDegrees } from '../geo/ellipsoid.js';
|
||||
import * as flightsPolicy from '../layers/flights/policy.js';
|
||||
|
||||
// The flights layer's own model policy: its radii, ceiling and caps.
|
||||
const POLICY = {
|
||||
MODEL_ALT_CEIL_M: 800_000,
|
||||
...flightsPolicy,
|
||||
MODEL_MAX: 40,
|
||||
MODEL_MAX_ALL: 350,
|
||||
COCKPIT_MODEL_MAX: 60,
|
||||
MODEL_PROX_ADD_M: 150_000,
|
||||
MODEL_PROX_KEEP_M: 185_000,
|
||||
MODEL_ALL_ADD_M: 400_000,
|
||||
MODEL_ALL_KEEP_M: 450_000,
|
||||
MODEL_MIN_PX: 24,
|
||||
TRACKED_MODEL_MIN_PX: 48,
|
||||
TRACKED_MODEL_MAX_PX: 600,
|
||||
MODEL_HEADING_OFFSET_DEG: 0,
|
||||
FLEET_DR_INTERVAL_MS: 80,
|
||||
TRACKED_MODEL_MAX_LOAD_FAILS: 3,
|
||||
TRACKED_MODEL_RETRY_BACKOFF_MS: 1500,
|
||||
};
|
||||
|
||||
/** The eye's height (m): 1 km above the contacts. */
|
||||
const EYE_M = 11_000;
|
||||
|
||||
const SPEC = {
|
||||
url: 'plane.glb',
|
||||
scale: 1,
|
||||
@@ -34,9 +27,9 @@ const SPEC = {
|
||||
/**
|
||||
* A fleet of airborne contacts at `positions` (icao → ECEF), drawn by a
|
||||
* models layer over a fake draw port whose fleet set can be told to fail a
|
||||
* write. The eye sits above them at 30 km.
|
||||
* write. The eye sits at `eyeM`, by default 1 km above them (`EYE_M`).
|
||||
*/
|
||||
function fleetFixture(positions) {
|
||||
function fleetFixture(positions, { eyeM = EYE_M } = {}) {
|
||||
const base = fakeDrawPort();
|
||||
const removes = [];
|
||||
let failNextUpsert = false;
|
||||
@@ -67,7 +60,7 @@ function fleetFixture(positions) {
|
||||
};
|
||||
},
|
||||
};
|
||||
const eye = fromDegrees(-97.71, 30.21, 30_000);
|
||||
const eye = fromDegrees(-97.71, 30.21, eyeM);
|
||||
const viewer = {};
|
||||
bindRenderer(viewer, {
|
||||
draw,
|
||||
@@ -79,7 +72,7 @@ function fleetFixture(positions) {
|
||||
right: { x: 1, y: 0, z: 0 },
|
||||
fovy: Math.PI / 3,
|
||||
aspectRatio: 1,
|
||||
height: 30_000,
|
||||
height: eyeM,
|
||||
}),
|
||||
},
|
||||
});
|
||||
@@ -185,7 +178,10 @@ function fleetFixture(positions) {
|
||||
};
|
||||
}
|
||||
|
||||
const near = (k) => fromDegrees(-97.71 + k * 0.01, 30.21, 10_000);
|
||||
// About 0.5 km apart, within 2 km of the eye.
|
||||
const near = (k) => fromDegrees(-97.71 + k * 0.005, 30.21, 10_000);
|
||||
/** A contact at the eye's height, `m` metres north of it. */
|
||||
const north = (m) => fromDegrees(-97.71, 30.21 + m / 110_850, EYE_M);
|
||||
const far = (k) => fromDegrees(-90 + k * 0.01, 30.21, 10_000);
|
||||
|
||||
test('the fleet tick hands contacts to ready models and back without a gap', () => {
|
||||
@@ -326,7 +322,7 @@ test('fleet model alpha is worked out once a fleet tick from the camera then, as
|
||||
const position = near(1);
|
||||
const f = fleetFixture(new Map([['a1', position]]));
|
||||
assert.equal(f.fleet().spec.recede ?? null, null, 'the set does not recede');
|
||||
const eye = fromDegrees(-97.71, 30.21, 30_000);
|
||||
const eye = fromDegrees(-97.71, 30.21, EYE_M);
|
||||
const expected = (focusFactor) =>
|
||||
aircraftTreatmentAlpha({
|
||||
baseAlpha: 0.8,
|
||||
@@ -336,7 +332,7 @@ test('fleet model alpha is worked out once a fleet tick from the camera then, as
|
||||
eye.y - position.y,
|
||||
eye.z - position.z,
|
||||
),
|
||||
cameraHeightM: 30_000,
|
||||
cameraHeightM: EYE_M,
|
||||
});
|
||||
try {
|
||||
// Recede from the eye on, so the haze is not 1 here.
|
||||
@@ -389,3 +385,67 @@ test('a contact not there yet at the time drawn has its fleet model hidden, as o
|
||||
f.tick();
|
||||
assert.equal(f.fleet().items.get('a1').show, true, 'drawn again');
|
||||
});
|
||||
|
||||
test('aircraft draw as models only within 3 km of the camera, in either mode', () => {
|
||||
for (const mode of ['proximity', 'all']) {
|
||||
const positions = new Map([
|
||||
['inside', north(2_900)],
|
||||
['outside', north(3_100)],
|
||||
]);
|
||||
const f = fleetFixture(positions);
|
||||
f.state._models3dMode = mode;
|
||||
f.tick();
|
||||
for (const id of positions.keys())
|
||||
if (f.fleet().items.has(id)) f.draw.ready(f.fleetId, id);
|
||||
f.tick();
|
||||
assert.equal(f.shown.get('inside'), false, `${mode}: a model at 2.9 km`);
|
||||
assert.equal(f.fleet().items.get('inside').show, true);
|
||||
assert.equal(f.shown.get('outside'), true, `${mode}: an icon at 3.1 km`);
|
||||
assert.equal(f.fleet().items.has('outside'), false);
|
||||
}
|
||||
});
|
||||
|
||||
test('a model is kept out to about 3.6 km, then its icon takes over', () => {
|
||||
const positions = new Map([['a1', north(2_000)]]);
|
||||
const f = fleetFixture(positions);
|
||||
f.tick();
|
||||
f.draw.ready(f.fleetId, 'a1');
|
||||
f.tick();
|
||||
assert.equal(f.shown.get('a1'), false, 'a model at 2 km');
|
||||
positions.set('a1', north(3_500));
|
||||
f.tick();
|
||||
assert.equal(f.shown.get('a1'), false, 'kept at 3.5 km');
|
||||
assert.equal(f.fleet().items.get('a1').show, true);
|
||||
positions.set('a1', north(3_700));
|
||||
f.tick();
|
||||
assert.equal(f.shown.get('a1'), true, 'released at 3.7 km');
|
||||
assert.equal(f.fleet().items.has('a1'), false);
|
||||
positions.set('a1', north(3_300));
|
||||
f.tick();
|
||||
assert.equal(
|
||||
f.fleet().items.has('a1'),
|
||||
false,
|
||||
'not taken again until it is back within 3 km',
|
||||
);
|
||||
});
|
||||
|
||||
test('a camera high above the ground still models an aircraft within 3 km of it', () => {
|
||||
// A plane at 30 km with the camera 2 km above it: the altitude ceiling
|
||||
// sits above every contact's height plus the keep radius.
|
||||
const plane = fromDegrees(-97.71, 30.21, 30_000);
|
||||
const f = fleetFixture(new Map([['high', plane]]), { eyeM: 32_000 });
|
||||
f.tick();
|
||||
f.draw.ready(f.fleetId, 'high');
|
||||
f.tick();
|
||||
assert.equal(f.shown.get('high'), false, 'its model draws it');
|
||||
assert.equal(
|
||||
POLICY.MODEL_ALT_CEIL_M,
|
||||
POLICY.MODEL_HIGHEST_CONTACT_M + POLICY.MODEL_KEEP_M,
|
||||
);
|
||||
});
|
||||
|
||||
test('models are drawn at their true size, with no minimum pixel size', () => {
|
||||
const f = fleetFixture(new Map([['a1', near(1)]]));
|
||||
f.tick();
|
||||
assert.equal(f.fleet().items.get('a1').minPixelSize ?? 0, 0);
|
||||
});
|
||||
Reference in new issue
Block a user