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.
This commit is contained in:
Sameh Khamis committed 2026-11-09 10:27:20 -08:00
1 parent c148e2888f
commit 6b4b04d082
2 files changed
+89 -4

No files matched your search

+15 -4
View File
@@ -3177,7 +3177,7 @@ export function createCesiumDraw({
? Cesium.Cartographic.fromCartesian(toCartesian(pos)).height ? Cesium.Cartographic.fromCartesian(toCartesian(pos)).height
: (pos.height ?? 0); : (pos.height ?? 0);
function shapeGeometry(item) { function shapeGeometry(item, vertexFormat) {
const g = item.geometry; const g = item.geometry;
const extrudedHeight = item.extrudeHeight; const extrudedHeight = item.extrudeHeight;
switch (g.kind) { switch (g.kind) {
@@ -3194,7 +3194,7 @@ export function createCesiumDraw({
perPositionHeight: g.perPositionHeight, perPositionHeight: g.perPositionHeight,
}; };
return { return {
fill: new Cesium.PolygonGeometry(polygon), fill: new Cesium.PolygonGeometry({ ...polygon, vertexFormat }),
// Extruded, its outline is the volume's edges (both faces and the // Extruded, its outline is the volume's edges (both faces and the
// walls' corners), as the entities' extruded polygons draw it. // walls' corners), as the entities' extruded polygons draw it.
outline: outline:
@@ -3219,7 +3219,7 @@ export function createCesiumDraw({
extrudedHeight, extrudedHeight,
}; };
return { return {
fill: new Cesium.EllipseGeometry(ellipse), fill: new Cesium.EllipseGeometry({ ...ellipse, vertexFormat }),
// Its outline is an outline geometry, as the entities' ellipses draw it. // Its outline is an outline geometry, as the entities' ellipses draw it.
outline: item.outline outline: item.outline
? new Cesium.EllipseOutlineGeometry(ellipse) ? new Cesium.EllipseOutlineGeometry(ellipse)
@@ -3240,6 +3240,7 @@ export function createCesiumDraw({
// An image fill turns with the rectangle, as a KML overlay's does. // An image fill turns with the rectangle, as a KML overlay's does.
rotation: g.rotation ?? 0, rotation: g.rotation ?? 0,
stRotation: g.rotation ?? 0, stRotation: g.rotation ?? 0,
vertexFormat,
}), }),
}; };
case 'box': { case 'box': {
@@ -3247,6 +3248,7 @@ export function createCesiumDraw({
return { return {
fill: Cesium.BoxGeometry.fromDimensions({ fill: Cesium.BoxGeometry.fromDimensions({
dimensions: new Cesium.Cartesian3(d.x, d.y, d.z), dimensions: new Cesium.Cartesian3(d.x, d.y, d.z),
vertexFormat,
}), }),
modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame( modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(
toCartesian(g.center), toCartesian(g.center),
@@ -4089,7 +4091,16 @@ export function createCesiumDraw({
: null; : null;
if (imageFill && !imageFill.image) if (imageFill && !imageFill.image)
throw new Error('the Cesium renderer fills shapes with colours only'); 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 id = pickId(record, item);
const pulse = pulseOf(item); const pulse = pulseOf(item);
const part = { const part = {
+74
View File
@@ -941,6 +941,78 @@ test('shapes that only change colour, pulse, show or meta change in place; a pul
set.dispose(); 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', () => { test('a pulse the Cesium renderer cannot run is refused before anything changes', () => {
const { scene, draw } = drawOver(); const { scene, draw } = drawOver();
const set = draw.shapes({ id: 'pulses' }); 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], [true, true, true],
); );
assert.ok(geometryInstances.geometry instanceof Cesium.RectangleGeometry); 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(geometryInstances.id.id, 'image');
assert.equal( assert.equal(
drawHitOf({ primitive, id: geometryInstances.id }).set, drawHitOf({ primitive, id: geometryInstances.id }).set,