Place the event's media cards through the renderer's ports and take them off the Cesium list

The embedded media cards find their anchor on screen through the camera
port's pose (whether it is behind the eye) and the query port's
projection, read the renderer's canvas for its offset, and follow the
camera on the frame port's postRender. The card root still goes in the
viewer's container, which is DOM. A test binds the three ports and checks
the card follows its anchor, hides behind the eye, and unsubscribes on
destroy.
This commit is contained in:
Sameh Khamis committed 2026-11-07 06:06:19 -08:00
1 parent cdbbf8c705
commit 4cbfd6e12d
3 files changed
+75 -18

No files matched your search

+22 -17
View File
@@ -1,4 +1,10 @@
import * as Cesium from 'cesium';
import {
findCamera,
findFrame,
findQuery,
rendererOf,
} from '../render/rendererOf.js';
import { dot, sub } from '../geo/vector.js';
import { t, msg, onLocaleChange } from '../i18n/index.js';
const YOUTUBE_HOSTS = new Set([
@@ -538,23 +544,22 @@ function ensureProviderConnections(documentRef, provider) {
}
}
/**
* Where an anchor (ECEF) is in the card root, through the renderer's camera
* and query ports; null behind the eye, off the root, or with no renderer.
*/
function anchorOnScreen(viewer, anchor, root) {
if (!viewer?.scene || !anchor || !root) return null;
const camera = viewer.camera;
if (camera?.positionWC && camera?.directionWC) {
const delta = Cesium.Cartesian3.subtract(
anchor,
camera.positionWC,
new Cesium.Cartesian3(),
);
if (Cesium.Cartesian3.dot(delta, camera.directionWC) <= 0) return null;
}
const pixel = Cesium.SceneTransforms.worldToWindowCoordinates(
viewer.scene,
anchor,
);
if (!anchor || !root) return null;
const camera = findCamera(viewer);
const query = findQuery(viewer);
if (!camera || !query) return null;
const pose = camera.pose();
if (dot(sub(anchor, pose.position), pose.direction) <= 0) return null;
const pixel = query.project(anchor);
if (!pixel) return null;
const canvasBounds = viewer.canvas?.getBoundingClientRect?.();
// The renderer's canvas; a viewer with no renderer bound, its own.
const canvas = rendererOf(viewer)?.canvas ?? viewer.canvas;
const canvasBounds = canvas?.getBoundingClientRect?.();
const rootBounds = root.getBoundingClientRect?.();
if (!canvasBounds || !rootBounds) return null;
const x = pixel.x + canvasBounds.left - rootBounds.left;
@@ -865,7 +870,7 @@ export function createBhoteKoshiEmbeddedMedia({
}
};
const removePostRender =
viewer.scene?.postRender?.addEventListener?.(position);
findFrame(viewer)?.on('postRender', () => position()) ?? null;
function hide({ immediate = false, preserveWarm = false } = {}) {
if (!preserveWarm) clearWarm();