mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw imported files through the draw port, off Cesium
Import no longer loads KML, KMZ, GeoJSON and GPX through Cesium's data source loaders. geoImportFeatures.js reads the sanitized file into plain pins, lines, walls, polygons and ground overlays with the looks those loaders gave them: icon, scale, colour, heading and hot spot, the shared and inline style precedence, line and polygon colours and widths, extruded and clamped geometry, rotated boxes and quads, and GeoJSON's 48 px pins, draped lines along rhumb lines and quarter-opacity fills. geoImportPins.js draws them in three draw sets per file, places ground pins through the height service (0 on the bare ellipsoid, whose coarse tiles sag below it; the mesh nearby on photoreal maps), follows a double-clicked pin, frames Fly-to, and shows, hides and removes them. The Cesium adapter now draws two members the contract already had: an icon's pixel offset and the wall shape. Image fills draw in the translucent pass, so an overlay's own alpha blends as it did. The Cesium allow-list is now empty; the ratchet test checks that its scan still sees each way of reaching Cesium. The QA scripts read what a file drew through the import's drawn(id), and the large-file check compares it with Cesium's own reading of the same KML. A file the renderer refuses to draw is refused by itself, without stopping its batch. Two translations no longer used are dropped.
This commit is contained in:
1 parent
c073064507
commit
6c1f91014c
33 files changed
+2608
-1177
No files matched your search
+47
-11
@@ -224,6 +224,23 @@ const DEPTH_BIASED_STATE = Object.freeze({
|
||||
blending: Cesium.BlendingState.ALPHA_BLEND,
|
||||
});
|
||||
|
||||
/**
|
||||
* An image fill's material. The image carries its own alpha, so it draws in
|
||||
* the translucent pass whatever its colour, as the entities' image
|
||||
* materials did.
|
||||
*/
|
||||
function imageMaterial(image, repeat = [1, 1]) {
|
||||
// Typed first and given its uniforms after, as `Material.fromType` does:
|
||||
// the image loads when first drawn, not here.
|
||||
const material = new Cesium.Material({
|
||||
fabric: { type: 'Image' },
|
||||
translucent: true,
|
||||
});
|
||||
material.uniforms.image = image;
|
||||
material.uniforms.repeat = new Cesium.Cartesian2(...repeat);
|
||||
return material;
|
||||
}
|
||||
|
||||
/** A `radialRim` fill's material. */
|
||||
function radialRimMaterial(fill) {
|
||||
const uniforms = {
|
||||
@@ -1024,6 +1041,11 @@ export function createCesiumDraw({
|
||||
// The defaults, so a restyle in place puts back what an item dropped.
|
||||
rotation: 0,
|
||||
alignedAxis: Cesium.Cartesian3.ZERO,
|
||||
// CSS pixels, y down, as the billboard takes them.
|
||||
pixelOffset: new Cesium.Cartesian2(
|
||||
item.pixelOffset?.x ?? 0,
|
||||
item.pixelOffset?.y ?? 0,
|
||||
),
|
||||
};
|
||||
if (item.rotationMode === 'screen') look.rotation = item.rotation ?? 0;
|
||||
if (item.rotationMode === 'course') {
|
||||
@@ -1066,6 +1088,9 @@ export function createCesiumDraw({
|
||||
rotationMode: item.rotationMode,
|
||||
rotation: item.rotation,
|
||||
course: item.course,
|
||||
pixelOffset: item.pixelOffset
|
||||
? [item.pixelOffset.x ?? 0, item.pixelOffset.y ?? 0]
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1112,7 +1137,11 @@ export function createCesiumDraw({
|
||||
sameCurve(style.fadeByDistance, item.fadeByDistance) &&
|
||||
style.rotationMode === item.rotationMode &&
|
||||
(item.rotationMode === 'screen' || style.rotation === item.rotation) &&
|
||||
style.course === item.course
|
||||
style.course === item.course &&
|
||||
(item.pixelOffset
|
||||
? style.pixelOffset?.[0] === (item.pixelOffset.x ?? 0) &&
|
||||
style.pixelOffset[1] === (item.pixelOffset.y ?? 0)
|
||||
: style.pixelOffset === undefined)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3255,6 +3284,21 @@ export function createCesiumDraw({
|
||||
),
|
||||
};
|
||||
}
|
||||
case 'wall': {
|
||||
// Up from `minimumHeights` (the ellipsoid) to `maximumHeights` (the
|
||||
// positions' own), as the entities' walls draw.
|
||||
const wall = {
|
||||
positions: g.positions.map(toCartesian),
|
||||
minimumHeights: g.minimumHeights,
|
||||
maximumHeights: g.maximumHeights,
|
||||
};
|
||||
return {
|
||||
fill: new Cesium.WallGeometry({ ...wall, vertexFormat }),
|
||||
outline: item.outline
|
||||
? new Cesium.WallOutlineGeometry(wall)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
default:
|
||||
throw new Error(`the Cesium renderer has no ${g.kind} shapes`);
|
||||
}
|
||||
@@ -3523,12 +3567,7 @@ export function createCesiumDraw({
|
||||
: UnpickableGroundPrimitive;
|
||||
const grounds = batches.map((batch) => {
|
||||
const material = batch.imageFill
|
||||
? Cesium.Material.fromType('Image', {
|
||||
image: batch.image,
|
||||
repeat: new Cesium.Cartesian2(
|
||||
...(batch.imageFill.repeat ?? [1, 1]),
|
||||
),
|
||||
})
|
||||
? imageMaterial(batch.image, batch.imageFill.repeat)
|
||||
: batch.rimFill
|
||||
? radialRimMaterial(batch.rimFill)
|
||||
: null;
|
||||
@@ -4147,10 +4186,7 @@ export function createCesiumDraw({
|
||||
);
|
||||
} else if (imageFill && !item.outlineOnly) {
|
||||
const material = ownMaterial(
|
||||
Cesium.Material.fromType('Image', {
|
||||
image: toImage(imageFill.image),
|
||||
repeat: new Cesium.Cartesian2(...(imageFill.repeat ?? [1, 1])),
|
||||
}),
|
||||
imageMaterial(toImage(imageFill.image), imageFill.repeat),
|
||||
);
|
||||
host.add(
|
||||
new Cesium.Primitive({
|
||||
|
||||
@@ -3356,6 +3356,59 @@ test('a draped line shown after it is ready keeps that show through the swap', (
|
||||
set.dispose();
|
||||
}));
|
||||
|
||||
test('an icon stands off its position by its pixel offset, and back when it has none', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.icons({ id: 'offset-pins' });
|
||||
const icon = (pixelOffset) => ({
|
||||
id: 'a',
|
||||
pos: { lon: 0, lat: 0 },
|
||||
image: 'pin.png',
|
||||
size: [8, 8],
|
||||
...(pixelOffset ? { pixelOffset } : {}),
|
||||
});
|
||||
set.set([icon({ x: 3, y: -4 })]);
|
||||
const pin = () => scene.added[0].get(0);
|
||||
assert.deepEqual([pin().pixelOffset.x, pin().pixelOffset.y], [3, -4]);
|
||||
set.upsert([icon({ x: 0, y: 6 })]);
|
||||
assert.deepEqual([pin().pixelOffset.x, pin().pixelOffset.y], [0, 6]);
|
||||
set.upsert([icon()]);
|
||||
assert.deepEqual([pin().pixelOffset.x, pin().pixelOffset.y], [0, 0]);
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('a wall stands up from the ellipsoid to its positions, with or without a fill', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.shapes({ id: 'walls' });
|
||||
const wall = (id, fill) => ({
|
||||
id,
|
||||
geometry: {
|
||||
kind: 'wall',
|
||||
positions: [
|
||||
{ lon: 0, lat: 0, height: 100 },
|
||||
{ lon: 0.01, lat: 0, height: 150 },
|
||||
],
|
||||
},
|
||||
fill,
|
||||
outline: [1, 1, 0, 1],
|
||||
});
|
||||
set.set([wall('filled', [0, 0, 1, 0.5]), wall('outline', null)]);
|
||||
const geometries = [];
|
||||
const walk = (primitive) => {
|
||||
if (!primitive) return;
|
||||
if (primitive instanceof Cesium.PrimitiveCollection)
|
||||
for (let i = 0; i < primitive.length; i++) walk(primitive.get(i));
|
||||
for (const instance of [primitive.geometryInstances ?? []].flat())
|
||||
geometries.push([instance.id?.id, instance.geometry.constructor.name]);
|
||||
};
|
||||
scene.added.forEach(walk);
|
||||
assert.deepEqual(geometries.sort(), [
|
||||
['filled', 'WallGeometry'],
|
||||
['filled', 'WallOutlineGeometry'],
|
||||
['outline', 'WallOutlineGeometry'],
|
||||
]);
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('icons blend as their set says', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.icons({ id: 'pins', blend: 'translucent' });
|
||||
@@ -4229,6 +4282,7 @@ test('an unclamped shape filled with an image draws a textured primitive and fre
|
||||
assert.ok(appearance instanceof Cesium.MaterialAppearance);
|
||||
assert.equal(appearance.material.type, 'Image');
|
||||
assert.equal(appearance.material.uniforms.image, 'picture.png');
|
||||
assert.equal(appearance.isTranslucent(), true, 'its own alpha blends');
|
||||
assert.deepEqual(
|
||||
appearance.material.uniforms.repeat,
|
||||
new Cesium.Cartesian2(2, 3),
|
||||
|
||||
@@ -1 +1 @@
|
||||
["src/data/geoImportPins.js"]
|
||||
[]
|
||||
@@ -255,6 +255,40 @@ test('only allow-listed files outside the Cesium adapter reach Cesium', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('the scan still recognises each way of reaching Cesium', () => {
|
||||
// With the list empty, the check above passes vacuously unless the scan
|
||||
// still sees Cesium; these are the forms the header lists.
|
||||
const reaches = (code, file = 'src/x/y.js') => {
|
||||
const { imports, takesNamespace } = scan(code);
|
||||
return takesNamespace || imports.some((s) => reachesCesium(file, s));
|
||||
};
|
||||
for (const code of [
|
||||
"import * as C from 'cesium';",
|
||||
"import { Viewer } from '@cesium/engine';",
|
||||
"import x from '../../node_modules/cesium/Source/Cesium.js';",
|
||||
"import x from '/node_modules/cesium/index.js?v=1';",
|
||||
"import { draw } from '../render/cesium/draw.js';",
|
||||
"export * from '../render/cesium/draw.js';",
|
||||
"const m = import('cesium');",
|
||||
'function f(Cesium) {}',
|
||||
'const { cesium } = deps;',
|
||||
'const c = window.Cesium;',
|
||||
'Cesium.Color.RED;',
|
||||
])
|
||||
assert.ok(reaches(code), code);
|
||||
for (const code of [
|
||||
"import { drawOf } from '../render/rendererOf.js';",
|
||||
'const cesiumLike = 1; Cesium2.x;',
|
||||
])
|
||||
assert.ok(!reaches(code), code);
|
||||
assert.ok(
|
||||
vueScript(
|
||||
'a.vue',
|
||||
'<script src="../render/cesium/draw.js"></script>',
|
||||
).external.some((s) => reachesCesium('src/ui/a.vue', s)),
|
||||
);
|
||||
});
|
||||
|
||||
test('every allow-listed file still reaches Cesium', () => {
|
||||
const present = new Set(runtimeFiles);
|
||||
const stale = allowList.filter(
|
||||
|
||||
@@ -139,9 +139,8 @@ const DRAW_FROM_CALLER = new Set([
|
||||
// eye and shade the globe through the ports alone.
|
||||
'./application/layers',
|
||||
'./standalone/catalog',
|
||||
// The application's tools (scene director, annotations, embed views):
|
||||
// they draw, fly and take clicks through the ports; only Import's pins
|
||||
// (`src/data/geoImportPins.js`, still on the Cesium list) drive Cesium.
|
||||
// The application's tools (scene director, annotations, embed views,
|
||||
// Import): they draw, fly and take clicks through the ports.
|
||||
'./application/tools',
|
||||
]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user