feat(globe): implement the engine on Cesium

createCesiumEngine wraps an existing viewer without changing it: camera, picker, projector, frames, render (through the render governor), surface, input, credits and maps, with geo values out and Cesium values in at the boundary. Map and surface code is shared with src/maps and services/groundSnap instead of copied. scripts/qa-globe-contract.mjs runs the contract suite against the engine in headless Chrome; the camera-events check now waits for the previous move to end, as Cesium's moveStart marks a move from rest.
This commit is contained in:
German Khokhlov committed 2026-10-15 17:43:05 +04:00
1 parent cd94a26b9f
commit d831cbd23a
33 files changed
+2374 -32

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
// GlobeProjector on a Cesium scene.
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
/**
* @param {Cesium.Viewer} viewer
* @param {{ worldToWindowCoordinates?: Function }} [options] Test seam for
* Cesium.SceneTransforms.worldToWindowCoordinates.
* @returns {{ projector: import('../contract.js').GlobeProjector, destroy: () => void }}
*/
export function createCesiumProjector(
viewer,
{
worldToWindowCoordinates = Cesium.SceneTransforms.worldToWindowCoordinates,
} = {},
) {
const { scene } = viewer;
const scratchWindow = new Cesium.Cartesian2();
const scratchMatrix = new Cesium.Matrix4();
const occluder = new Cesium.EllipsoidalOccluder(Cesium.Ellipsoid.WGS84);
const projector = {
worldToWindow(position, result) {
// Cesium returns undefined in front of the near plane or behind the camera.
const window = worldToWindowCoordinates(scene, position, scratchWindow);
if (!window) return undefined;
if (!result) return geo.cartesian2.create(window.x, window.y);
result.x = window.x;
result.y = window.y;
return result;
},
// The matrix Cesium's worldToWindowCoordinates uses: frustum projection ×
// view. x, y and w do not depend on the multi-frustum near/far planes.
viewProjection(result = geo.matrix4.create()) {
const { camera } = scene;
Cesium.Matrix4.multiply(
camera.frustum.projectionMatrix,
camera.viewMatrix,
scratchMatrix,
);
for (let index = 0; index < 16; index++)
result[index] = scratchMatrix[index];
return result;
},
horizonVisible(position) {
occluder.cameraPosition = scene.camera.positionWC;
return occluder.isPointVisible(position);
},
};
return { projector, destroy() {} };
}