From 6b4b04d082d10be46adceef0be1d5b7d259c3de6 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 9 Nov 2026 10:27:20 -0800 Subject: [PATCH] Cesium draw port builds colour fills with the vertex format their appearance reads Unclamped colour fills are built with position and normal only, as the entities' colour batches build them; image fills keep texture coordinates. With the default format Cesium packed texture coordinates with the normals and the colour appearance decoded the packed value as the normal, so lit colour fills (an extruded column, a box) shaded darker than the same entity. --- src/render/cesium/draw.js | 19 +++++++-- src/render/cesium/draw.test.mjs | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/render/cesium/draw.js b/src/render/cesium/draw.js index be4b4c261..61ac2ff59 100644 --- a/src/render/cesium/draw.js +++ b/src/render/cesium/draw.js @@ -3177,7 +3177,7 @@ export function createCesiumDraw({ ? Cesium.Cartographic.fromCartesian(toCartesian(pos)).height : (pos.height ?? 0); - function shapeGeometry(item) { + function shapeGeometry(item, vertexFormat) { const g = item.geometry; const extrudedHeight = item.extrudeHeight; switch (g.kind) { @@ -3194,7 +3194,7 @@ export function createCesiumDraw({ perPositionHeight: g.perPositionHeight, }; return { - fill: new Cesium.PolygonGeometry(polygon), + fill: new Cesium.PolygonGeometry({ ...polygon, vertexFormat }), // Extruded, its outline is the volume's edges (both faces and the // walls' corners), as the entities' extruded polygons draw it. outline: @@ -3219,7 +3219,7 @@ export function createCesiumDraw({ extrudedHeight, }; return { - fill: new Cesium.EllipseGeometry(ellipse), + fill: new Cesium.EllipseGeometry({ ...ellipse, vertexFormat }), // Its outline is an outline geometry, as the entities' ellipses draw it. outline: item.outline ? new Cesium.EllipseOutlineGeometry(ellipse) @@ -3240,6 +3240,7 @@ export function createCesiumDraw({ // An image fill turns with the rectangle, as a KML overlay's does. rotation: g.rotation ?? 0, stRotation: g.rotation ?? 0, + vertexFormat, }), }; case 'box': { @@ -3247,6 +3248,7 @@ export function createCesiumDraw({ return { fill: Cesium.BoxGeometry.fromDimensions({ dimensions: new Cesium.Cartesian3(d.x, d.y, d.z), + vertexFormat, }), modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame( toCartesian(g.center), @@ -4089,7 +4091,16 @@ export function createCesiumDraw({ : null; if (imageFill && !imageFill.image) throw new Error('the Cesium renderer fills shapes with colours only'); - const shape = shapeGeometry(item); + // A colour fill's geometry carries what its appearance reads, as the + // entities' do. With texture coordinates too, Cesium packs them with + // the normals, which a colour appearance then misreads: a lit colour + // fill shaded darker than the same entity. + const shape = shapeGeometry( + item, + imageFill + ? Cesium.MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat + : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT, + ); const id = pickId(record, item); const pulse = pulseOf(item); const part = { diff --git a/src/render/cesium/draw.test.mjs b/src/render/cesium/draw.test.mjs index aa9a86bd9..c8c7b1222 100644 --- a/src/render/cesium/draw.test.mjs +++ b/src/render/cesium/draw.test.mjs @@ -941,6 +941,78 @@ test('shapes that only change colour, pulse, show or meta change in place; a pul set.dispose(); })); +test('colour fills carry what their appearance reads, as entities do', () => + withImageClasses(() => { + const { scene, draw } = drawOver(); + const set = draw.shapes({ id: 'formats' }); + const ring = [ + { lon: 0, lat: 0, height: 10 }, + { lon: 0.001, lat: 0, height: 10 }, + { lon: 0.001, lat: 0.001, height: 10 }, + ]; + set.set([ + { + id: 'column', + geometry: { kind: 'polygon', rings: [ring] }, + fill: [1, 0.7, 0.3, 0.45], + extrudeHeight: 100, + height: 'absolute', + }, + { + id: 'box', + geometry: { + kind: 'box', + center: { lon: 1, lat: 0, height: 10 }, + dimensions: { x: 10, y: 10, z: 10 }, + }, + fill: '#fff', + height: 'absolute', + }, + { + id: 'disc', + geometry: { + kind: 'ellipse', + center: { lon: 2, lat: 0, height: 10 }, + semiMajor: 50, + semiMinor: 30, + }, + fill: '#fff', + extrudeHeight: 40, + height: 'absolute', + }, + { + id: 'slab', + geometry: { + kind: 'rectangle', + rect: { west: 3, south: 0, east: 3.01, north: 0.01 }, + height: 10, + }, + fill: '#fff', + extrudeHeight: 40, + height: 'absolute', + }, + ]); + const host = scene.added[0]; + const formats = []; + const walk = (c) => { + for (let i = 0; i < c.length; i++) { + const p = c.get(i); + if (typeof p.length === 'number' && p.get) walk(p); + else if (p instanceof Cesium.Primitive && p.geometryInstances?.geometry) + formats.push(p.geometryInstances.geometry._vertexFormat); + } + }; + walk(host); + assert.equal(formats.length, 4); + // Position and normal only: with texture coordinates too, Cesium packs + // them with the normals, and the colour appearance misreads them. + for (const format of formats) { + assert.equal(format.normal, true); + assert.equal(format.st, false); + } + set.dispose(); + })); + test('a pulse the Cesium renderer cannot run is refused before anything changes', () => { const { scene, draw } = drawOver(); const set = draw.shapes({ id: 'pulses' }); @@ -4083,6 +4155,8 @@ test('an unclamped shape filled with an image draws a textured primitive and fre [true, true, true], ); assert.ok(geometryInstances.geometry instanceof Cesium.RectangleGeometry); + // Texture coordinates for the image, as its appearance reads them. + assert.equal(geometryInstances.geometry._vertexFormat.st, true); assert.equal(geometryInstances.id.id, 'image'); assert.equal( drawHitOf({ primitive, id: geometryInstances.id }).set,