Image fills pulse on the Cesium renderer

A shape with an image fill and animate is no longer refused: the fill's
alpha pulses through its image material's colour, on the surface or
clamped, as colour fills pulse.
This commit is contained in:
Sameh Khamis committed 2026-11-11 17:16:21 -08:00
1 parent 20138cb313
commit ee9de4edda
3 files changed
+61 -19

No files matched your search

+15 -7
View File
@@ -278,12 +278,6 @@ function pulseOf(item) {
throw new Error(
'the Cesium renderer pulses between finite alphas, over a positive period',
);
const plain = (value) =>
value == null || typeof value === 'string' || Array.isArray(value);
if (!plain(item.fill) || !plain(item.outline))
throw new Error(
'the Cesium renderer pulses colour fills and outlines only',
);
return pulse;
}
@@ -4583,6 +4577,11 @@ export function createCesiumDraw({
!part.fill.isDestroyed()
)
colourOn(part.fill, part.id, tint(look.fill, scratchColour));
// An image fill pulses through its material's colour, white at rest.
if (part.image)
part.image.material.uniforms.color = Cesium.Color.WHITE.withAlpha(
alpha ?? 1,
);
if (look.outline) {
if (part.outline?.ready && !part.outline.isDestroyed())
colourOn(part.outline, part.id, tint(look.outline, scratchColour));
@@ -4630,7 +4629,16 @@ export function createCesiumDraw({
for (const part of parts?.values() ?? []) {
if (!part.pulse || !part.show) continue;
const ground = part.ground;
if (ground && !ground.isDestroyed()) {
const imageFill =
typeof part.look.fill === 'object' &&
!Array.isArray(part.look.fill);
if (ground && !ground.isDestroyed() && imageFill) {
// An image fill, a ground primitive of its own, pulses through
// its material's colour.
pulsing = true;
ground.appearance.material.uniforms.color =
Cesium.Color.WHITE.withAlpha(pulseAlpha(part.pulse, now));
} else if (ground && !ground.isDestroyed()) {
// One still building asks for frames, to pulse once it is ready.
pulsing = true;
if (ground.ready)
+45 -11
View File
@@ -1161,22 +1161,12 @@ test('a pulse the Cesium renderer cannot run is refused before anything changes'
assert.throws(() => set.set([disc(radius)]), /pulses alpha only, forever/);
assert.equal(scene.added[0], host, 'still drawn as it was');
assert.doesNotThrow(() => set.upsert([{ ...disc(undefined), id: 'c' }]));
// Nor numbers it cannot draw, nor a fill that is not a colour.
// Nor numbers it cannot draw.
assert.throws(
() =>
set.upsert([disc({ property: 'alpha', from: 0, to: 1, periodMs: 0 })]),
/positive period/,
);
assert.throws(
() =>
set.upsert([
{
...disc({ property: 'alpha', from: 0, to: 1, periodMs: 1000 }),
fill: { image: 'x.png' },
},
]),
/colour fills and outlines only/,
);
set.dispose();
});
@@ -8135,3 +8125,47 @@ test('a draped line in the sky’s frame drapes where the sky is, again as its c
Date.now = realNow;
}
});
test('image fills pulse their alpha through their material, clamped or not', () =>
withImageClasses(() => {
const { scene, draw, frame } = drawOver();
const set = draw.shapes({ id: 'pulsing-images' });
const animate = { property: 'alpha', from: 0.3, to: 0.3, periodMs: 1000 };
const rect = (west) => ({
kind: 'rectangle',
rect: { west, south: 0, east: west + 1, north: 1 },
});
set.set([
{
id: 'flat',
geometry: rect(0),
fill: { image: 'pad.png' },
height: 'absolute',
animate,
},
{
id: 'draped',
geometry: rect(4),
fill: { image: 'pad.png' },
height: 'clampGround',
animate,
},
]);
frame();
const materials = [];
const walk = (primitive) => {
if (primitive instanceof Cesium.PrimitiveCollection)
for (let i = 0; i < primitive.length; i++) walk(primitive.get(i));
else if (primitive?.appearance?.material?.type === 'Image')
materials.push(primitive.appearance.material);
};
scene.added.forEach(walk);
assert.equal(materials.length, 2, 'both drawn');
for (const material of materials)
assert.equal(
Math.round(material.uniforms.color.alpha * 100) / 100,
0.3,
'pulsed',
);
set.dispose();
}));