mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(rail): the selected route splits at the train and keeps its dark rim, as before
Before, the route was one clamped polyline whose material coloured it ahead of the train and dimmer behind it, split exactly where the train is, with a dark rim at its edges. Through the draw port it became per-segment colours chosen by each segment's midpoint (the split jumped from vertex to vertex) and lost its rim. The contract gains a draped line style `split`: `color` from `at` (a fraction of its length) on, `behind` before it (`reverse`: the other way), and an optional `rim` (the outer `widthFraction` of its width at `shade` of each colour). `at`, `reverse` and the colours change in place. The Cesium renderer draws it with one material; the rail route uses it, measuring its split in metres on the ground (one per vertex where the scene draws over the surface). New conformance check draw.lines.split.
This commit is contained in:
1 parent
96ef7f509e
commit
e72de07dab
7 files changed
+277
-51
No files matched your search
@@ -56,6 +56,20 @@ export function toColor(color, alpha = 1) {
|
||||
return c.withAlpha(c.alpha * alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* A split line style's colours and split as its material's uniforms: `at`
|
||||
* outside 0..1 draws it all in `color`, as a split before the start does.
|
||||
*/
|
||||
function splitUniforms(style) {
|
||||
const at = Number.isFinite(style.at) && style.at >= 0 && style.at <= 1;
|
||||
return {
|
||||
color: toColor(style.color),
|
||||
behind: toColor(style.behind),
|
||||
splitAt: at ? style.at : -1,
|
||||
direction: at && style.reverse ? -1 : 1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* An image reference as something a billboard or material takes: a URL, an
|
||||
* SVG as a data URL, a blob as its object URL, or the canvas itself. An
|
||||
@@ -238,6 +252,26 @@ czm_material czm_getMaterial(czm_materialInput materialInput) {
|
||||
return m;
|
||||
}`;
|
||||
|
||||
const SPLIT_MATERIAL = 'DrawSplitLine';
|
||||
|
||||
/**
|
||||
* Along the line (`st.s`, 0 at its start, 1 at its end, by length on the
|
||||
* ground) `color` from `splitAt` on and `behind` before it (`direction`
|
||||
* -1: the other way); across it (`st.t`) the outer `rimFraction` in all is
|
||||
* each colour's shade.
|
||||
*/
|
||||
const SPLIT_SOURCE = `
|
||||
czm_material czm_getMaterial(czm_materialInput materialInput) {
|
||||
czm_material m = czm_getDefaultMaterial(materialInput);
|
||||
float s = materialInput.st.s;
|
||||
bool before = direction > 0.0 ? s < splitAt : s > splitAt;
|
||||
vec4 c = before ? behind : color;
|
||||
bool rim = abs(materialInput.st.t - 0.5) > 0.5 - rimFraction * 0.5;
|
||||
m.diffuse = czm_gammaCorrect(rim ? c.rgb * rimShade : c.rgb);
|
||||
m.alpha = c.a;
|
||||
return m;
|
||||
}`;
|
||||
|
||||
/**
|
||||
* How finely a clamped ellipse with an image fill is cut, radians, so an
|
||||
* image's round edge (a zone's rim) runs round.
|
||||
@@ -307,6 +341,7 @@ const DRAPED_STYLES = new Set([
|
||||
'flow',
|
||||
'arrow',
|
||||
'pattern',
|
||||
'split',
|
||||
]);
|
||||
|
||||
// Whether Cesium's approximate terrain heights have been asked for.
|
||||
@@ -501,6 +536,10 @@ export function createCesiumDraw({
|
||||
// A shape's pulse the renderer cannot run is refused before anything
|
||||
// changes.
|
||||
const checkPulses = (list) => {
|
||||
if (kind === 'lines')
|
||||
for (const item of list)
|
||||
if (item.style?.kind === 'split' && item.mode !== 'draped')
|
||||
throw new TypeError('a split line is draped');
|
||||
if (kind !== 'shapes') return;
|
||||
for (const item of list) pulseOf(item);
|
||||
if (list.some((item) => item.animate)) record.mayPulse = true;
|
||||
@@ -2136,9 +2175,12 @@ export function createCesiumDraw({
|
||||
// values in the fabric would be merged into copies of the type's.
|
||||
const template = ({ type, source, uniforms }) =>
|
||||
source ? { type, source, uniforms } : { type };
|
||||
// A pattern's image carries its own alpha: drawn in the translucent
|
||||
// pass, whatever its colour.
|
||||
const translucent = style.kind === 'pattern' ? { translucent: true } : {};
|
||||
// A pattern's image carries its own alpha, and a split line's colours
|
||||
// may each have one: drawn in the translucent pass, whatever its colour.
|
||||
const translucent =
|
||||
style.kind === 'pattern' || style.kind === 'split'
|
||||
? { translucent: true }
|
||||
: {};
|
||||
const material =
|
||||
reveal === undefined
|
||||
? new Cesium.Material({ fabric: template(fabric), ...translucent })
|
||||
@@ -2195,6 +2237,16 @@ export function createCesiumDraw({
|
||||
},
|
||||
source: FLOW_SOURCE,
|
||||
};
|
||||
case 'split':
|
||||
return {
|
||||
type: SPLIT_MATERIAL,
|
||||
uniforms: {
|
||||
...splitUniforms(style),
|
||||
rimShade: style.rim?.shade ?? 1,
|
||||
rimFraction: style.rim?.widthFraction ?? 0,
|
||||
},
|
||||
source: SPLIT_SOURCE,
|
||||
};
|
||||
case 'solid':
|
||||
// An outlined line keeps its edge in one material: two lines
|
||||
// stacked would darken where their translucent passes overlap.
|
||||
@@ -2976,7 +3028,10 @@ export function createCesiumDraw({
|
||||
replaceHost(record, collect(own, ground), ground, own);
|
||||
}
|
||||
|
||||
/** A line style but for its colours, which its material takes in place. */
|
||||
/**
|
||||
* A line style but for its colours (and a split line's split), which its
|
||||
* material takes in place.
|
||||
*/
|
||||
const colourlessStyle = (style) =>
|
||||
style.outline
|
||||
? {
|
||||
@@ -2984,13 +3039,23 @@ export function createCesiumDraw({
|
||||
color: undefined,
|
||||
outline: { ...style.outline, color: undefined },
|
||||
}
|
||||
: { ...style, color: undefined };
|
||||
: style.kind === 'split'
|
||||
? {
|
||||
...style,
|
||||
color: undefined,
|
||||
behind: undefined,
|
||||
at: undefined,
|
||||
reverse: undefined,
|
||||
}
|
||||
: { ...style, color: undefined };
|
||||
|
||||
/** Give a line's material its style's colours, its outline's too. */
|
||||
function paintLine(material, style) {
|
||||
material.uniforms.color = toColor(style.color);
|
||||
if (style.outline && 'outlineColor' in material.uniforms)
|
||||
material.uniforms.outlineColor = toColor(style.outline.color);
|
||||
if (style.kind === 'split' && 'splitAt' in material.uniforms)
|
||||
Object.assign(material.uniforms, splitUniforms(style));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5497,6 +5497,60 @@ test('a draped arrow drapes its arrow material on a ground polyline of its own,
|
||||
set.dispose();
|
||||
}));
|
||||
|
||||
test('a split line draws ahead and behind its split with a rim, the split moving in place', () =>
|
||||
withImageClasses(() => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.lines({ id: 'route', clampTo: 'tiles' });
|
||||
const positions = new Float64Array([
|
||||
...Object.values(Cesium.Cartesian3.fromDegrees(0, 0)),
|
||||
...Object.values(Cesium.Cartesian3.fromDegrees(0.01, 0.01)),
|
||||
]);
|
||||
const route = (at, reverse) => ({
|
||||
id: 'route',
|
||||
positions,
|
||||
widthPx: 5,
|
||||
mode: 'draped',
|
||||
style: {
|
||||
kind: 'split',
|
||||
color: [0.2, 0.6, 1, 1],
|
||||
behind: [0.2, 0.6, 1, 0.3],
|
||||
at,
|
||||
reverse,
|
||||
rim: { shade: 0.22, widthFraction: 0.28 },
|
||||
},
|
||||
});
|
||||
set.set([route(-1)]);
|
||||
const host = scene.added[0];
|
||||
const line = [...Array(host.length).keys()]
|
||||
.map((i) => host.get(i))
|
||||
.find((p) => p.appearance?.material?.type === 'DrawSplitLine');
|
||||
assert.ok(line, 'drawn by the split material');
|
||||
const uniforms = line.appearance.material.uniforms;
|
||||
assert.deepEqual(
|
||||
[uniforms.splitAt, uniforms.direction, uniforms.rimShade],
|
||||
[-1, 1, 0.22],
|
||||
);
|
||||
assert.equal(uniforms.rimFraction, 0.28);
|
||||
assert.equal(uniforms.behind.alpha, 0.3);
|
||||
assert.ok(line.appearance.material.isTranslucent());
|
||||
set.upsert([route(0.4)]);
|
||||
assert.ok(!line.isDestroyed(), 'the same ground primitive');
|
||||
assert.deepEqual([uniforms.splitAt, uniforms.direction], [0.4, 1]);
|
||||
set.upsert([route(0.6, true)]);
|
||||
assert.deepEqual([uniforms.splitAt, uniforms.direction], [0.6, -1]);
|
||||
set.upsert([route(Number.NaN, true)]);
|
||||
assert.deepEqual(
|
||||
[uniforms.splitAt, uniforms.direction],
|
||||
[-1, 1],
|
||||
'no split: all ahead',
|
||||
);
|
||||
assert.throws(
|
||||
() => set.upsert([{ ...route(0.5), mode: 'geodesic' }]),
|
||||
TypeError,
|
||||
'a split line is draped',
|
||||
);
|
||||
}));
|
||||
|
||||
test('a draped line drawn by its own material changes colour in place; a batched one rebuilds', () =>
|
||||
withImageClasses(() => {
|
||||
const { scene, draw } = drawOver();
|
||||
|
||||
@@ -69,6 +69,7 @@ export const CESIUM_CHECKS = new Set([
|
||||
'draw.lines.styles',
|
||||
'draw.lines.outline',
|
||||
'draw.lines.drape',
|
||||
'draw.lines.split',
|
||||
'draw.lines.segments',
|
||||
'draw.lines.segmentStyles',
|
||||
'draw.sets.blend',
|
||||
|
||||
Reference in new issue
Block a user