mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Draw the last native world labels through the label overlay
The Directions A and B letters and a data pack's media label were the two Cesium text labels left, kept by an allow-list in noCesiumLabels.test.mjs. Both now publish entries to the shared world-overlay host, and the allow-list is gone, so any Cesium label in src is a test failure. Directions publishes the letters to the directions-markers source; the markers keep only their points. A clicked endpoint's letter hangs over the surface that was clicked. One placed without a click stays hidden until its ground-floor cell resolves, then requests a render, so a still camera shows it; a cell that settles with no height falls back to the ellipsoid. Each position is computed once. A pack resource handle gains label(entry). The application passes its shared overlay host to SceneDirector through dataPacks.overlayHost; without one a media pack fails to load rather than drawing a native label. Each labelled resource takes a source from a pool and returns it on dispose, as the host never removes a source, so two presentations of one pack never clear each other's labels and repeat loads add no sources. A label written after dispose is ignored. The media label is protected, so it always draws as before. Live (Denver, keyless globe): a clicked A and a programmatic B both anchor on their dots over 1.58 km ground. Documented in docs/CURRENT-STATE.md and docs/DIRECTOR-DATA-PACKS.md.
This commit is contained in:
1 parent
ad8adc85f4
commit
fb30287898
12 files changed
+382
-44
No files matched your search
@@ -2,11 +2,14 @@ import { createDataPackSession } from '../../director/packs/session.js';
|
||||
import { createPackPresentations } from './presentation.js';
|
||||
|
||||
/** Bind selected shot packs to one viewer and expose copied lifecycle diagnostics. */
|
||||
export function createSceneDataPacks(viewer, { sources = {} } = {}) {
|
||||
export function createSceneDataPacks(
|
||||
viewer,
|
||||
{ sources = {}, overlayHost = null } = {},
|
||||
) {
|
||||
const targets = new Map();
|
||||
const session = createDataPackSession({
|
||||
sources,
|
||||
adapters: createPackPresentations(viewer, targets),
|
||||
adapters: createPackPresentations(viewer, targets, { overlayHost }),
|
||||
});
|
||||
return {
|
||||
...session,
|
||||
|
||||
@@ -5,11 +5,20 @@ import { applicationPinia } from '../../ui/vueRuntime.js';
|
||||
|
||||
const xyz = (p) => Cesium.Cartesian3.fromDegrees(...p);
|
||||
|
||||
const MEDIA_MARKER_CSS = '#ffff00';
|
||||
|
||||
// Key every panel and card on the page, so a new one never reuses an old
|
||||
// one's DOM.
|
||||
let panelKeys = 0,
|
||||
cardKeys = 0;
|
||||
|
||||
// Label overlay sources, one per pack resource while it shows text, so two
|
||||
// presentations of one pack never share or clear each other's labels. The host
|
||||
// keeps a source once made, so a disposed resource returns its id for reuse
|
||||
// and the count stays at the most labelled resources ever shown at once.
|
||||
let labelSources = 0;
|
||||
const freeLabelSources = [];
|
||||
|
||||
/**
|
||||
* Create rendering adapters; data acquisition and authored placement stay
|
||||
* independent. Each pack's attribution card is presented to the data packs
|
||||
@@ -18,7 +27,7 @@ let panelKeys = 0,
|
||||
export function createPackPresentations(
|
||||
viewer,
|
||||
targets = new Map(),
|
||||
{ store = useDataPacksStore(applicationPinia()) } = {},
|
||||
{ store = useDataPacksStore(applicationPinia()), overlayHost = null } = {},
|
||||
) {
|
||||
const owner = {};
|
||||
let key,
|
||||
@@ -56,8 +65,10 @@ export function createPackPresentations(
|
||||
const entities = [],
|
||||
primitives = [],
|
||||
materials = [],
|
||||
urls = [];
|
||||
urls = [],
|
||||
labels = [];
|
||||
const featureKeys = [];
|
||||
let labelSource = null;
|
||||
let card,
|
||||
destroyed = false;
|
||||
return {
|
||||
@@ -72,6 +83,21 @@ export function createPackPresentations(
|
||||
viewer.scene.requestRender();
|
||||
return entity;
|
||||
},
|
||||
/**
|
||||
* World text for this pack, as a label-overlay entry in the pack's own
|
||||
* source. The application passes the shared host; there is no text
|
||||
* without one, so a pack that needs it fails to load instead.
|
||||
*/
|
||||
label(entry) {
|
||||
if (!overlayHost) throw new Error('Pack labels need an overlay host');
|
||||
// A late adapter writing after disposal must not take a source again.
|
||||
if (destroyed) return;
|
||||
labelSource ||=
|
||||
freeLabelSources.pop() ?? `data-pack-labels:${++labelSources}`;
|
||||
labels.push(entry);
|
||||
overlayHost.setEntries(labelSource, labels.slice());
|
||||
viewer.scene.requestRender();
|
||||
},
|
||||
primitive(value) {
|
||||
primitives.push(viewer.scene.primitives.add(value));
|
||||
if (value.appearance?.material)
|
||||
@@ -98,6 +124,12 @@ export function createPackPresentations(
|
||||
// The view stops a removed card's player as it goes.
|
||||
if (card) removeCard(card);
|
||||
for (const entity of entities.splice(0)) viewer.entities.remove(entity);
|
||||
if (labelSource) {
|
||||
labels.length = 0;
|
||||
overlayHost.clearSource(labelSource);
|
||||
freeLabelSources.push(labelSource);
|
||||
labelSource = null;
|
||||
}
|
||||
for (const primitive of primitives.splice(0))
|
||||
viewer.scene.primitives.remove(primitive);
|
||||
for (const material of materials.splice(0)) {
|
||||
@@ -200,16 +232,27 @@ export function createPackPresentations(
|
||||
(item) => item.id === pack.placement.anchorId,
|
||||
);
|
||||
if (!anchor) throw new Error('Missing media anchor');
|
||||
const position = xyz([anchor.lon, anchor.lat, anchor.alt]);
|
||||
handle.add({
|
||||
name: pack.id,
|
||||
position: xyz([anchor.lon, anchor.lat, anchor.alt]),
|
||||
point: { pixelSize: 16, color: Cesium.Color.YELLOW },
|
||||
label: {
|
||||
text: pack.id,
|
||||
font: '14px sans-serif',
|
||||
pixelOffset: new Cesium.Cartesian2(0, -24),
|
||||
position,
|
||||
point: {
|
||||
pixelSize: 16,
|
||||
color: Cesium.Color.fromCssColorString(MEDIA_MARKER_CSS),
|
||||
},
|
||||
});
|
||||
handle.label({
|
||||
id: 'media',
|
||||
position,
|
||||
variant: 'label',
|
||||
title: pack.id,
|
||||
accent: MEDIA_MARKER_CSS,
|
||||
protected: true,
|
||||
interactive: false,
|
||||
gapPx: 15,
|
||||
verticalOnly: true,
|
||||
placement: 'above',
|
||||
});
|
||||
handle.media({
|
||||
kind: asset.mimeType.startsWith('video/') ? 'video' : 'audio',
|
||||
src: handle.url(new Blob([asset.bytes], { type: asset.mimeType })),
|
||||
|
||||
@@ -55,3 +55,110 @@ test('abort releases an in-flight image URL before the decoder settles or the vi
|
||||
URL.revokeObjectURL = priorRevoke;
|
||||
}
|
||||
});
|
||||
|
||||
test('a media pack names its marker through the label overlay, cleared on dispose', async () => {
|
||||
const published = [];
|
||||
const cleared = [];
|
||||
const added = [];
|
||||
const viewer = {
|
||||
container: {},
|
||||
scene: { requestRender() {} },
|
||||
entities: {
|
||||
add: (spec) => (added.push(spec), spec),
|
||||
remove() {},
|
||||
},
|
||||
};
|
||||
const overlayHost = {
|
||||
setEntries: (source, entries) => published.push([source, entries]),
|
||||
clearSource: (source) => cleared.push(source),
|
||||
};
|
||||
const handle = await createPackPresentations(viewer, new Map(), {
|
||||
overlayHost,
|
||||
}).media({
|
||||
pack: {
|
||||
id: 'harbour-audio',
|
||||
placement: { anchorId: 'pier' },
|
||||
attribution: { text: 'Port', license: 'CC-BY' },
|
||||
},
|
||||
anchors: [{ id: 'pier', lon: -122.39, lat: 37.79, alt: 5 }],
|
||||
asset: { bytes: new Uint8Array(4), mimeType: 'audio/mpeg' },
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
assert.equal(added.length, 1);
|
||||
assert.equal(added[0].label, undefined, 'no Cesium label on the marker');
|
||||
const [source, entries] = published.at(-1);
|
||||
assert.match(source, /^data-pack-labels:\d+$/);
|
||||
assert.deepEqual(
|
||||
entries.map(({ title, variant }) => ({ title, variant })),
|
||||
[{ title: 'harbour-audio', variant: 'label' }],
|
||||
);
|
||||
assert.equal(entries[0].position, added[0].position);
|
||||
assert.equal(entries[0].protected, true, 'it always draws, as before');
|
||||
handle.dispose();
|
||||
assert.deepEqual(cleared, [source]);
|
||||
});
|
||||
|
||||
test('without an overlay host a media pack fails to load instead of losing its name', async () => {
|
||||
const removed = [];
|
||||
const viewer = {
|
||||
container: {},
|
||||
scene: { requestRender() {} },
|
||||
entities: { add: (spec) => spec, remove: (entity) => removed.push(entity) },
|
||||
};
|
||||
await assert.rejects(
|
||||
createPackPresentations(viewer).media({
|
||||
pack: {
|
||||
id: 'harbour-audio',
|
||||
placement: { anchorId: 'pier' },
|
||||
attribution: { text: 'Port', license: 'CC-BY' },
|
||||
},
|
||||
anchors: [{ id: 'pier', lon: -122.39, lat: 37.79, alt: 5 }],
|
||||
asset: { bytes: new Uint8Array(4), mimeType: 'audio/mpeg' },
|
||||
signal: new AbortController().signal,
|
||||
}),
|
||||
/overlay host/,
|
||||
);
|
||||
assert.equal(removed.length, 1, 'the marker it placed is removed again');
|
||||
});
|
||||
|
||||
test('two presentations of one media pack keep their labels apart, and reuse sources', async () => {
|
||||
// Like the real host, clearing a source empties it but keeps it registered.
|
||||
const sources = new Map();
|
||||
const overlayHost = {
|
||||
setEntries: (source, entries) => sources.set(source, entries),
|
||||
clearSource: (source) => sources.set(source, []),
|
||||
};
|
||||
const shown = () =>
|
||||
[...sources.values()].filter((entries) => entries.length).length;
|
||||
const viewer = {
|
||||
container: {},
|
||||
scene: { requestRender() {} },
|
||||
entities: { add: (spec) => spec, remove() {} },
|
||||
};
|
||||
const show = () =>
|
||||
createPackPresentations(viewer, new Map(), { overlayHost }).media({
|
||||
pack: {
|
||||
id: 'harbour-audio',
|
||||
placement: { anchorId: 'pier' },
|
||||
attribution: { text: 'Port', license: 'CC-BY' },
|
||||
},
|
||||
anchors: [{ id: 'pier', lon: -122.39, lat: 37.79, alt: 5 }],
|
||||
asset: { bytes: new Uint8Array(4), mimeType: 'audio/mpeg' },
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
const first = await show();
|
||||
const second = await show();
|
||||
assert.equal(shown(), 2);
|
||||
first.dispose();
|
||||
assert.equal(shown(), 1, "the second presentation's label stays");
|
||||
second.dispose();
|
||||
assert.equal(shown(), 0);
|
||||
const registered = sources.size;
|
||||
for (let i = 0; i < 5; i++) (await show()).dispose();
|
||||
assert.equal(sources.size, registered, 'repeat loads reuse freed sources');
|
||||
const late = await show();
|
||||
late.dispose();
|
||||
late.label({ id: 'late', position: { x: 1, y: 0, z: 0 }, title: 'late' });
|
||||
late.dispose();
|
||||
assert.equal(shown(), 0, 'a label after dispose is ignored');
|
||||
});
|
||||
@@ -10,6 +10,8 @@ import { useDataPacksStore } from '../../ui/stores/dataPacks.js';
|
||||
import DataPacks from '../../ui/views/panels/DataPacks.vue';
|
||||
import { createPackPresentations } from './presentation.js';
|
||||
|
||||
const overlayHost = { setEntries() {}, clearSource() {} };
|
||||
|
||||
const ANCHOR = { id: 'here', lat: 30, lon: -97, alt: 10 };
|
||||
const pack = (id, url) => ({
|
||||
id,
|
||||
@@ -29,7 +31,10 @@ function fixture(t) {
|
||||
entities: { add: (spec) => spec, remove() {} },
|
||||
};
|
||||
const store = useDataPacksStore(pinia);
|
||||
const presentations = createPackPresentations(viewer, new Map(), { store });
|
||||
const presentations = createPackPresentations(viewer, new Map(), {
|
||||
store,
|
||||
overlayHost,
|
||||
});
|
||||
t.after(() => app.unmount());
|
||||
const settle = async () => {
|
||||
for (let flush = 0; flush < 4; flush += 1) await nextTick();
|
||||
@@ -118,7 +123,10 @@ test('each set of presentations keeps its own panel', async (t) => {
|
||||
const { presentations, viewer, store, settle, $$ } = fixture(t);
|
||||
const one = await media(presentations, 'one');
|
||||
await media(presentations, 'two');
|
||||
const later = createPackPresentations(viewer, new Map(), { store });
|
||||
const later = createPackPresentations(viewer, new Map(), {
|
||||
store,
|
||||
overlayHost,
|
||||
});
|
||||
const three = await media(later, 'three');
|
||||
await settle();
|
||||
const cards = () =>
|
||||
|
||||
Reference in new issue
Block a user