diff --git a/docs/RENDERER-CONTRACT.md b/docs/RENDERER-CONTRACT.md index 3df9f2434..8fb575944 100644 --- a/docs/RENDERER-CONTRACT.md +++ b/docs/RENDERER-CONTRACT.md @@ -148,7 +148,8 @@ target standing up). 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 -clamped shape is rebuilt on any change, and its outline does not pulse). What +clamped shape is rebuilt on any change; a pulsing one pulses through its line's +material). What 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 under it up to its `extrudeHeight`, a wall with its foot on the surface under diff --git a/src/render/cesium/draw.js b/src/render/cesium/draw.js index 40b47d540..eeb9658eb 100644 --- a/src/render/cesium/draw.js +++ b/src/render/cesium/draw.js @@ -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; diff --git a/src/render/cesium/draw.test.mjs b/src/render/cesium/draw.test.mjs index 12fe8ffe7..4baa24472 100644 --- a/src/render/cesium/draw.test.mjs +++ b/src/render/cesium/draw.test.mjs @@ -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();