mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +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
@@ -0,0 +1,79 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
GreaterDepth,
|
||||
Matrix4,
|
||||
ShaderLib,
|
||||
UniformsUtils,
|
||||
Vector3,
|
||||
} from 'three';
|
||||
import { normalizeLineOptions } from '../../lines.js';
|
||||
import { buildRibbon, createLineMesh, patchLineShader } from './lineMesh.js';
|
||||
|
||||
const flat = new Float64Array([
|
||||
6_378_137, 0, 0, 6_378_137, 300, 0, 6_378_137, 300, 400,
|
||||
]);
|
||||
|
||||
test('the ribbon has a quad per segment relative to the first point', () => {
|
||||
const geometry = buildRibbon(flat, [6_378_137, 0, 0]);
|
||||
assert.equal(geometry.getAttribute('position').count, 8);
|
||||
assert.equal(geometry.index.count, 12);
|
||||
assert.deepEqual(
|
||||
[...geometry.getAttribute('gevEnd').array.subarray(0, 3)],
|
||||
[0, 300, 0],
|
||||
);
|
||||
// The fraction along the line: 0 at the start, 300/700 at the joint, 1 at the end.
|
||||
const s = geometry.getAttribute('gevS').array;
|
||||
assert.deepEqual([s[0], s[2]], [0, 300 / 700].map(Math.fround));
|
||||
assert.equal(s[7], 1);
|
||||
const side = geometry.getAttribute('gevSide').array;
|
||||
assert.deepEqual([...side.subarray(0, 8)], [0, 1, 0, -1, 1, 1, 1, -1]);
|
||||
});
|
||||
|
||||
test('the shader patch widens the ribbon in pixels and cuts dashes', () => {
|
||||
const shader = patchLineShader(
|
||||
{
|
||||
uniforms: UniformsUtils.clone(ShaderLib.basic.uniforms),
|
||||
vertexShader: ShaderLib.basic.vertexShader,
|
||||
fragmentShader: ShaderLib.basic.fragmentShader,
|
||||
},
|
||||
{ uGevWidthPx: { value: 3 } },
|
||||
);
|
||||
assert.match(
|
||||
shader.vertexShader,
|
||||
/uGevWidthPx \/ uGevViewport \* gl_Position\.w/,
|
||||
);
|
||||
assert.match(
|
||||
shader.fragmentShader,
|
||||
/mod\(gevAlong, uGevDashPx\.x \+ uGevDashPx\.y\)/,
|
||||
);
|
||||
assert.match(shader.fragmentShader, /float gevTactical\(\)/);
|
||||
});
|
||||
|
||||
test('a line places its group at the first point under its model matrix', () => {
|
||||
const turn = new Matrix4().makeRotationZ(Math.PI / 2);
|
||||
const line = createLineMesh(
|
||||
normalizeLineOptions({
|
||||
id: 'orbit',
|
||||
widthPx: 3,
|
||||
color: [0, 1, 1, 1],
|
||||
depthFailAlpha: 0.3,
|
||||
dash: 'tactical',
|
||||
modelMatrix: turn.toArray(),
|
||||
}),
|
||||
);
|
||||
line.setPositions(flat);
|
||||
const origin = new Vector3().setFromMatrixPosition(line.group.matrix);
|
||||
// (6378137, 0, 0) turned 90° about z.
|
||||
assert.ok(Math.abs(origin.x) < 1e-6 && Math.abs(origin.y - 6_378_137) < 1e-6);
|
||||
const [main, behind] = line.meshes();
|
||||
assert.equal(behind.material.depthFunc, GreaterDepth);
|
||||
assert.equal(main.geometry, behind.geometry);
|
||||
assert.equal(line.uniforms.uGevDash.value, 2);
|
||||
assert.deepEqual(line.uniforms.uGevTactical.value, [4, 100]);
|
||||
line.setColor([1, 0, 0, 0.5]);
|
||||
assert.deepEqual(line.uniforms.uGevColor.value, [1, 0, 0, 0.5]);
|
||||
line.show(false);
|
||||
assert.equal(line.group.visible, false);
|
||||
line.dispose();
|
||||
});
|
||||
Reference in new issue
Block a user