mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
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:
1 parent
20138cb313
commit
ee9de4edda
3 files changed
+61
-19
No files matched your search
@@ -149,7 +149,7 @@ target standing up).
|
|||||||
The Cesium port draws clamped shapes of every kind. A clamped outline is a
|
The Cesium port draws clamped shapes of every kind. A clamped outline is a
|
||||||
draped line (a ground polyline a ring, under the shape's pick id; an outlined
|
draped line (a ground polyline a ring, under the shape's pick id; an outlined
|
||||||
clamped shape is rebuilt on any change; a pulsing one pulses through its line's
|
clamped shape is rebuilt on any change; a pulsing one pulses through its line's
|
||||||
material). What
|
material, as an image fill pulses through its image material's colour). What
|
||||||
a ground primitive cannot drape stands on the surface unclamped, the surface
|
a ground primitive cannot drape stands on the surface unclamped, the surface
|
||||||
read when the set is built: an extruded shape from the lowest surface height
|
read when the set is built: an extruded shape from the lowest surface height
|
||||||
under it up to its `extrudeHeight`, a wall with its foot on the surface under
|
under it up to its `extrudeHeight`, a wall with its foot on the surface under
|
||||||
|
|||||||
@@ -278,12 +278,6 @@ function pulseOf(item) {
|
|||||||
throw new Error(
|
throw new Error(
|
||||||
'the Cesium renderer pulses between finite alphas, over a positive period',
|
'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;
|
return pulse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4583,6 +4577,11 @@ export function createCesiumDraw({
|
|||||||
!part.fill.isDestroyed()
|
!part.fill.isDestroyed()
|
||||||
)
|
)
|
||||||
colourOn(part.fill, part.id, tint(look.fill, scratchColour));
|
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 (look.outline) {
|
||||||
if (part.outline?.ready && !part.outline.isDestroyed())
|
if (part.outline?.ready && !part.outline.isDestroyed())
|
||||||
colourOn(part.outline, part.id, tint(look.outline, scratchColour));
|
colourOn(part.outline, part.id, tint(look.outline, scratchColour));
|
||||||
@@ -4630,7 +4629,16 @@ export function createCesiumDraw({
|
|||||||
for (const part of parts?.values() ?? []) {
|
for (const part of parts?.values() ?? []) {
|
||||||
if (!part.pulse || !part.show) continue;
|
if (!part.pulse || !part.show) continue;
|
||||||
const ground = part.ground;
|
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.
|
// One still building asks for frames, to pulse once it is ready.
|
||||||
pulsing = true;
|
pulsing = true;
|
||||||
if (ground.ready)
|
if (ground.ready)
|
||||||
|
|||||||
@@ -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.throws(() => set.set([disc(radius)]), /pulses alpha only, forever/);
|
||||||
assert.equal(scene.added[0], host, 'still drawn as it was');
|
assert.equal(scene.added[0], host, 'still drawn as it was');
|
||||||
assert.doesNotThrow(() => set.upsert([{ ...disc(undefined), id: 'c' }]));
|
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(
|
assert.throws(
|
||||||
() =>
|
() =>
|
||||||
set.upsert([disc({ property: 'alpha', from: 0, to: 1, periodMs: 0 })]),
|
set.upsert([disc({ property: 'alpha', from: 0, to: 1, periodMs: 0 })]),
|
||||||
/positive period/,
|
/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();
|
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;
|
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();
|
||||||
|
}));
|
||||||
Reference in new issue
Block a user