mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Clamped shape outlines pulse on the Cesium renderer
A clamped outline with animate is drawn with a colour material, its rings sharing one colour, and pulses its alpha through it each frame as the shape's fill does.
This commit is contained in:
1 parent
6ec4d5571d
commit
9995b35874
3 files changed
+73
-16
No files matched your search
+39
-15
@@ -4031,7 +4031,13 @@ export function createCesiumDraw({
|
||||
for (const item of items) {
|
||||
if (item.outline) outlines.push(item);
|
||||
if (!item.fill || item.outlineOnly) {
|
||||
parts.set(item.id, { look: lookOf(item), id: null, ground: null });
|
||||
parts.set(item.id, {
|
||||
look: lookOf(item),
|
||||
id: null,
|
||||
ground: null,
|
||||
pulse: pulseOf(item),
|
||||
show: item.show !== false,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const objectFill =
|
||||
@@ -4155,6 +4161,8 @@ export function createCesiumDraw({
|
||||
const part = parts.get(item.id);
|
||||
// Picked as its shape.
|
||||
part.id ??= pickId(record, item);
|
||||
// A pulsing outline's rings share one colour, its material's.
|
||||
const pulsing = Boolean(part.pulse);
|
||||
const outline = new Cesium.GroundPolylinePrimitive({
|
||||
geometryInstances: rings.map(
|
||||
(positions) =>
|
||||
@@ -4175,7 +4183,13 @@ export function createCesiumDraw({
|
||||
id: part.id,
|
||||
}),
|
||||
),
|
||||
appearance: new Cesium.PolylineColorAppearance(),
|
||||
appearance: pulsing
|
||||
? new Cesium.PolylineMaterialAppearance({
|
||||
material: Cesium.Material.fromType('Color', {
|
||||
color: toColor(item.outline),
|
||||
}),
|
||||
})
|
||||
: new Cesium.PolylineColorAppearance(),
|
||||
classificationType: classificationOf(
|
||||
item.clampTo ?? record.spec.clampTo ?? 'both',
|
||||
),
|
||||
@@ -4527,20 +4541,30 @@ export function createCesiumDraw({
|
||||
}
|
||||
for (const parts of [record.shapeParts, record.retiringShapeParts])
|
||||
for (const part of parts?.values() ?? []) {
|
||||
if (!part.pulse || !part.show || !part.ground) continue;
|
||||
if (!part.pulse || !part.show) continue;
|
||||
const ground = part.ground;
|
||||
if (ground.isDestroyed()) continue;
|
||||
// One still building asks for frames, to pulse once it is ready.
|
||||
pulsing = true;
|
||||
if (!ground.ready) continue;
|
||||
colourOn(
|
||||
ground,
|
||||
part.id,
|
||||
baseColour(part, part.look.fill).withAlpha(
|
||||
pulseAlpha(part.pulse, now),
|
||||
scratchColour,
|
||||
),
|
||||
);
|
||||
if (ground && !ground.isDestroyed()) {
|
||||
// One still building asks for frames, to pulse once it is ready.
|
||||
pulsing = true;
|
||||
if (ground.ready)
|
||||
colourOn(
|
||||
ground,
|
||||
part.id,
|
||||
baseColour(part, part.look.fill).withAlpha(
|
||||
pulseAlpha(part.pulse, now),
|
||||
scratchColour,
|
||||
),
|
||||
);
|
||||
}
|
||||
// A clamped outline pulses through its material's colour.
|
||||
const outline = part.outlineGround;
|
||||
if (outline && !outline.isDestroyed() && part.look.outline) {
|
||||
pulsing = true;
|
||||
outline.appearance.material.uniforms.color = baseColour(
|
||||
part,
|
||||
part.look.outline,
|
||||
).withAlpha(pulseAlpha(part.pulse, now));
|
||||
}
|
||||
}
|
||||
}
|
||||
return pulsing;
|
||||
|
||||
@@ -333,6 +333,38 @@ test('a clamped outline is a draped line under its shape’s pick id, a ring eac
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('a pulsing clamped outline pulses its alpha through its material', () =>
|
||||
withImageClasses(() => {
|
||||
const { scene, draw, frame } = drawOver();
|
||||
const set = draw.shapes({ id: 'pulsing-outline' });
|
||||
set.set([
|
||||
{
|
||||
id: 'r',
|
||||
geometry: {
|
||||
kind: 'rectangle',
|
||||
rect: { west: 2, south: 0, east: 3, north: 1 },
|
||||
},
|
||||
outline: '#00ff00',
|
||||
outlineOnly: true,
|
||||
height: 'clampGround',
|
||||
animate: { property: 'alpha', from: 0.2, to: 0.2, periodMs: 1000 },
|
||||
},
|
||||
]);
|
||||
const host = scene.added[0];
|
||||
let line;
|
||||
for (let i = 0; i < host.length; i++)
|
||||
if (host.get(i) instanceof Cesium.GroundPolylinePrimitive)
|
||||
line = host.get(i);
|
||||
assert.ok(line.appearance instanceof Cesium.PolylineMaterialAppearance);
|
||||
frame();
|
||||
const colour = line.appearance.material.uniforms.color;
|
||||
assert.deepEqual(
|
||||
[colour.green, Math.round(colour.alpha * 100) / 100],
|
||||
[1, 0.2],
|
||||
);
|
||||
set.dispose();
|
||||
}));
|
||||
|
||||
test('where the scene cannot drape materials, a clamped image fill lies on the surface', () =>
|
||||
withImageClasses(() => {
|
||||
const scene = fakeScene();
|
||||
|
||||
Reference in new issue
Block a user