mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(globe): dynamic lines on both engines
engine.lines.createLine({ id, widthPx, color, depthFailAlpha, dash
({ lengthPx, gapPx } | 'tactical'), arc ('none'|'geodesic'), modelMatrix,
pickId }) → a Line: setPositions (Cartesian3[] or a flat Float64Array),
setColor, setModelMatrix, show, destroy; lines.list() for QA. Options,
flat positions, geodesic densification (great circles of the geodetic
normals, height interpolated, one step per degree) and the registry are
engine-neutral (src/globe/lines.js); the fake engine keeps every line.
- Cesium: a Primitive of a PolylineGeometry (synchronous, rebuilt when
the positions change) with a PolylineMaterialAppearance in an
engine-owned collection; depthFailAlpha is depthFailAppearance with the
alpha scaled; pixel dashes are PolylineDash (16-bit pattern); the
tactical dash is the launches' selected-orbit shader under its own type
(launches keep theirs until Task 15a moves them onto engine.lines).
- Navara: a public MeshDesc (transparent pass, unlit) holding a ribbon
of one quad per segment, widened to CSS pixels in the vertex shader;
a second copy drawn with GreaterDepth and the alpha scaled is the
depth-fail part; dashes are cut in the fragment shader (pixels along
the screen direction, or the tactical pattern over the fraction along
the line); positions relative to the first point, the model matrix on
the group. Geodesic arcs are densified on the CPU. Not pickable yet.
- The contract suite draws a three-point line on both engines: magenta
along both segments, nothing off it, 1° east once turned by its model
matrix, gone when hidden; a line 30 km under the ground shows only its
depth-fail copy, dimmer than the line.
Main chunk 2,867,499 bytes (+7,197, +0.25 %: the Cesium lines).
This commit is contained in:
1 parent
0109097440
commit
86aa0bc9ba
16 files changed
+1380
-2
No files matched your search
@@ -591,6 +591,116 @@ export function createContractSuite(
|
||||
);
|
||||
},
|
||||
],
|
||||
[
|
||||
'lines: a line draws between its projections, turns with its model matrix and dims where hidden',
|
||||
async () => {
|
||||
await nadirView(1e6);
|
||||
// 20 km up: above any ground the scene draws.
|
||||
const at = (lon, lat, height = 20_000) =>
|
||||
cartesian3.fromDegrees(lon, lat, height);
|
||||
const line = engine.lines.createLine({
|
||||
id: 'contract-line',
|
||||
widthPx: 8,
|
||||
color: [1, 0, 1, 1],
|
||||
});
|
||||
const hidden = engine.lines.createLine({
|
||||
id: 'contract-line-hidden',
|
||||
widthPx: 10,
|
||||
color: [1, 0, 1, 1],
|
||||
depthFailAlpha: 0.6,
|
||||
});
|
||||
try {
|
||||
line.setPositions([at(19, 9), at(20, 9), at(21, 9)]);
|
||||
ensure(
|
||||
engine.lines
|
||||
.list()
|
||||
.some(({ id, points }) => id === 'contract-line' && points === 3),
|
||||
'lines.list() does not show the line',
|
||||
);
|
||||
if (!readRegion) return;
|
||||
// Magenta-leaning pixels (red and blue over green; a dimmed copy
|
||||
// over a light map stays above 30) near a point.
|
||||
// The strongest magenta lean near a point (for dimmer-than).
|
||||
const strength = (position) => {
|
||||
const screen = engine.projector.worldToWindow(position);
|
||||
const data = readRegion(
|
||||
Math.round(screen.x) - 6,
|
||||
Math.round(screen.y) - 6,
|
||||
12,
|
||||
12,
|
||||
);
|
||||
let best = -255;
|
||||
for (let i = 0; i < data.length; i += 4)
|
||||
best = Math.max(
|
||||
best,
|
||||
Math.min(data[i], data[i + 2]) - data[i + 1],
|
||||
);
|
||||
return best;
|
||||
};
|
||||
const magentaAt = (position) => {
|
||||
const screen = engine.projector.worldToWindow(position);
|
||||
if (!screen) return 0;
|
||||
const data = readRegion(
|
||||
Math.round(screen.x) - 6,
|
||||
Math.round(screen.y) - 6,
|
||||
12,
|
||||
12,
|
||||
);
|
||||
let count = 0;
|
||||
for (let i = 0; i < data.length; i += 4)
|
||||
if (
|
||||
Math.min(data[i], data[i + 2]) - data[i + 1] > 30 &&
|
||||
data[i] > 120
|
||||
)
|
||||
count++;
|
||||
return count;
|
||||
};
|
||||
await until(
|
||||
() => magentaAt(at(19.5, 9)) > 10 && magentaAt(at(20.5, 9)) > 10,
|
||||
'the line drawn along both segments',
|
||||
);
|
||||
ensure(magentaAt(at(19.5, 10.5)) === 0, 'line pixels off the line');
|
||||
// Turned 1° about the Earth's axis: the line moves 1° east.
|
||||
const turn = (radians) => {
|
||||
const c = Math.cos(radians);
|
||||
const s = Math.sin(radians);
|
||||
return [c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
||||
};
|
||||
line.setModelMatrix(turn(math.toRadians(1)));
|
||||
await until(
|
||||
() => magentaAt(at(21.5, 9)) > 10 && magentaAt(at(19.25, 9)) === 0,
|
||||
'the turned line drawn 1° east',
|
||||
);
|
||||
const shownStrength = strength(at(20.5, 9));
|
||||
line.show(false);
|
||||
await until(() => magentaAt(at(20.5, 9)) === 0, 'the line hidden');
|
||||
// 30 km under the ground: only the depth-fail copy shows, dimmed.
|
||||
const deep = (lon) => at(lon, 11, -30_000);
|
||||
hidden.setPositions([deep(19), deep(21)]);
|
||||
await until(
|
||||
() => magentaAt(deep(20)) > 10,
|
||||
'the hidden line drawn by its depth-fail copy',
|
||||
);
|
||||
const hiddenStrength = strength(deep(20));
|
||||
ensure(
|
||||
hiddenStrength < shownStrength,
|
||||
`the depth-fail copy (${hiddenStrength}) is not dimmer than the line (${shownStrength})`,
|
||||
);
|
||||
hidden.destroy();
|
||||
await until(
|
||||
() => magentaAt(deep(20)) === 0,
|
||||
'the destroyed line gone',
|
||||
);
|
||||
} finally {
|
||||
line.destroy();
|
||||
hidden.destroy();
|
||||
}
|
||||
ensure(
|
||||
!engine.lines.list().some(({ id }) => id.startsWith('contract-line')),
|
||||
'a destroyed line is still listed',
|
||||
);
|
||||
},
|
||||
],
|
||||
[
|
||||
'render: continuous mode toggles',
|
||||
async () => {
|
||||
|
||||
Reference in new issue
Block a user