mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
Draw weather, wind and Bhote Koshi through engine.imagery, one display each
engine.imagery gains what these rasters need, on every engine: - geographic (EPSG:4326) tile schemes and a transform applied to each decoded tile (the satellite infrared mask); - staged source changes, which keep the drawn source until the new one has loaded (the weather frame swap), and credit-only changes in place; - raised layers that draw on a shell above terrain and 3D tiles, rising with the camera, with a detail image inside a rectangle. On Cesium this is the weather shell primitive, moved into the engine; on Navara the pixel's ray meets the ellipsoid grown by the height. Rain radar, satellite clouds, lightning, the wind field and the Bhote Koshi event and locator each draw through one render/display.js on both engines; their Navara renderers and Navara's weather surface pass go. Cesium's pixels are unchanged in every compared scene. On Navara the Bhote Koshi images are no longer upside down. Two engine-specific parts stay behind one backend option each: the wind's streamlines and the Bhote Koshi story entities. The coupling report now counts defineGroundEffect calls, not its own declaration. Coupling: Navara renderer lines fall from 2304 to 1695, Navara ground passes from 3 to 1 (the Global Context pulses), engine kind checks from 5 to 2. The contract suite passes on both engines (Cesium 71/71, Navara 74/74).
This commit is contained in:
1 parent
b53b6a48a7
commit
c73c5382d4
39 files changed
+4677
-1114
No files matched your search
+488
-46
@@ -4,19 +4,33 @@
|
||||
// src/maps/imageryHost.js resolves it for the shell. Layers sit above the
|
||||
// base imagery, in their order among the engine's layers (higher on top,
|
||||
// then creation); imagery added by others stays where it was put. A tiles
|
||||
// source is a UrlTemplateImageryProvider in Web Mercator, an image source a
|
||||
// one-tile provider over its rectangle (as SingleTileImageryProvider, but
|
||||
// from the canvas or image itself, without a PNG round trip). The engine
|
||||
// follows the surface on every frame while it holds a layer: on a switch
|
||||
// each layer is built again on the new stack, never re-parented.
|
||||
// source is a UrlTemplateImageryProvider in Web Mercator or geographic
|
||||
// tiling (its transform applied to each tile as it arrives), an image
|
||||
// source a one-tile provider over its rectangle (as
|
||||
// SingleTileImageryProvider, but from the canvas or image itself, without a
|
||||
// PNG round trip). The engine follows the surface on every frame while it
|
||||
// holds a layer: on a switch each layer is built again on the new stack,
|
||||
// never re-parented. A staged source is a second layer at alpha 0 right
|
||||
// over the drawn one, whose tiles Cesium loads while the drawn one shows;
|
||||
// it takes the drawn one's place once its own requests are in and quiet.
|
||||
// A raised layer is a shell primitive instead (imageryShell.js), on every
|
||||
// surface.
|
||||
|
||||
import * as Cesium from 'cesium';
|
||||
import { createImageryRegistry, isPixelImage } from '../imagery.js';
|
||||
import { createImageryShell } from './imageryShell.js';
|
||||
|
||||
const SPLIT = { none: 'NONE', left: 'LEFT', right: 'RIGHT' };
|
||||
const NO_HOST = Object.freeze({ collection: null, surface: 'none' });
|
||||
/** Delay before the one frame that retries tiles a provider deferred. */
|
||||
export const TILE_RETRY_DELAY_MS = 250;
|
||||
/** How often a staged source waiting out its quiet interval rechecks readiness. */
|
||||
export const STAGE_WAKE_MS = 150;
|
||||
// A staged source's own tiles are in once no request was made or settled
|
||||
// for this long; two frames in a row must find it so.
|
||||
const STAGE_QUIET_MS = 200;
|
||||
// Retries of a staged tile the server throttled (429, 503).
|
||||
const STAGE_RETRIES = 3;
|
||||
|
||||
const rectangleOf = ({ west, south, east, north }) =>
|
||||
Cesium.Rectangle.fromDegrees(west, south, east, north);
|
||||
@@ -35,6 +49,20 @@ function drawable(image, createCanvas) {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
// A decoded tile with row 0 on the north edge, as a transform takes it:
|
||||
// Cesium decodes tiles as ImageBitmaps already flipped (WebGL ignores
|
||||
// UNPACK_FLIP_Y for them), so those are drawn upright on a canvas, which
|
||||
// Cesium flips again as it uploads.
|
||||
function upright(image, createCanvas) {
|
||||
if (typeof ImageBitmap === 'undefined' || !(image instanceof ImageBitmap))
|
||||
return image;
|
||||
const canvas = createCanvas(image.width, image.height);
|
||||
const context = canvas.getContext('2d');
|
||||
context.setTransform(1, 0, 0, -1, 0, image.height);
|
||||
context.drawImage(image, 0, 0);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
// One image over `rectangle`: SingleTileImageryProvider's tiling (one
|
||||
// geographic tile at level 0), handing Cesium the image itself.
|
||||
function singleImageProvider(image, rectangle, credit) {
|
||||
@@ -51,7 +79,7 @@ function singleImageProvider(image, rectangle, credit) {
|
||||
minimumLevel: 0,
|
||||
maximumLevel: 0,
|
||||
tileDiscardPolicy: undefined,
|
||||
credit: credit ? new Cesium.Credit(credit) : undefined,
|
||||
credit,
|
||||
errorEvent: new Cesium.Event(),
|
||||
hasAlphaChannel: true,
|
||||
proxy: undefined,
|
||||
@@ -104,6 +132,7 @@ const defaultFactories = Object.freeze({
|
||||
tiles: (options) => new Cesium.UrlTemplateImageryProvider(options),
|
||||
layer: (provider, options) => new Cesium.ImageryLayer(provider, options),
|
||||
loadImage: (url) => Cesium.Resource.fetchImage({ url }),
|
||||
shell: createImageryShell,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -114,7 +143,7 @@ const defaultFactories = Object.freeze({
|
||||
* `tilesets` are the 3D tilesets the map may show (maps.js); a shown one
|
||||
* with imagery layers hosts the imagery while the globe is hidden.
|
||||
* `createCanvas`, `factories` (the tile provider, the layer, the image
|
||||
* load) and the timers are test seams.
|
||||
* load, a raised layer's shell) and the timers are test seams.
|
||||
* @returns {{ imagery: import('../contract.js').GlobeImagery, destroy: () => void }}
|
||||
*/
|
||||
export function createCesiumImagery(
|
||||
@@ -132,6 +161,7 @@ export function createCesiumImagery(
|
||||
const { scene } = viewer;
|
||||
const entries = new Set();
|
||||
let removeWatch = null;
|
||||
const now = () => globalThis.performance?.now() ?? Date.now();
|
||||
|
||||
function host() {
|
||||
if (scene.globe?.show === true && viewer.imageryLayers)
|
||||
@@ -174,39 +204,73 @@ export function createCesiumImagery(
|
||||
collection.add(layer, index);
|
||||
}
|
||||
|
||||
function providerFor(entry, source) {
|
||||
const creditOf = (html) => (html ? new Cesium.Credit(html) : undefined);
|
||||
|
||||
// Each tile through the source's transform, upright.
|
||||
function transformTiles(provider, transform) {
|
||||
const original = provider.requestImage.bind(provider);
|
||||
provider.requestImage = (x, y, level, request) => {
|
||||
const result = original(x, y, level, request);
|
||||
return result
|
||||
? Promise.resolve(result).then((image) =>
|
||||
transform(upright(image, createCanvas)),
|
||||
)
|
||||
: result;
|
||||
};
|
||||
return provider;
|
||||
}
|
||||
|
||||
// `drawing` is the entry or a staged job ({ credit, retry, image }).
|
||||
function providerFor(drawing, source) {
|
||||
let provider;
|
||||
if (source.kind === 'tiles') {
|
||||
const provider = make.tiles({
|
||||
provider = make.tiles({
|
||||
url: source.url,
|
||||
subdomains: [...source.subdomains],
|
||||
minimumLevel: source.minLevel,
|
||||
maximumLevel: source.maxLevel,
|
||||
tileWidth: source.tileSize,
|
||||
tileHeight: source.tileSize,
|
||||
tilingScheme: new Cesium.WebMercatorTilingScheme(),
|
||||
tilingScheme:
|
||||
source.scheme === 'geographic'
|
||||
? new Cesium.GeographicTilingScheme()
|
||||
: new Cesium.WebMercatorTilingScheme(),
|
||||
rectangle: rectangleOf(source.rectangle),
|
||||
hasAlphaChannel: !source.opaque,
|
||||
enablePickFeatures: false,
|
||||
...(source.credit ? { credit: source.credit } : {}),
|
||||
});
|
||||
return source.maxRequests
|
||||
? admitTileRequests(
|
||||
provider,
|
||||
{ limit: source.maxRequests, inFlight: 0 },
|
||||
requestRender,
|
||||
entry.retry,
|
||||
)
|
||||
: provider;
|
||||
}
|
||||
return singleImageProvider(
|
||||
drawable(entry.image, createCanvas),
|
||||
rectangleOf(source.rectangle),
|
||||
source.credit,
|
||||
);
|
||||
if (source.transform) transformTiles(provider, source.transform);
|
||||
if (source.maxRequests)
|
||||
admitTileRequests(
|
||||
provider,
|
||||
{ limit: source.maxRequests, inFlight: 0 },
|
||||
requestRender,
|
||||
drawing.retry,
|
||||
);
|
||||
} else
|
||||
provider = singleImageProvider(
|
||||
drawable(drawing.image, createCanvas),
|
||||
rectangleOf(source.rectangle),
|
||||
undefined,
|
||||
);
|
||||
// Cesium reads a provider's credit every frame: a new credit of the same
|
||||
// source replaces it without a new layer.
|
||||
Object.defineProperty(provider, 'credit', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: () => drawing.credit,
|
||||
});
|
||||
return provider;
|
||||
}
|
||||
|
||||
function applyLook(entry) {
|
||||
const { layer, state } = entry;
|
||||
const { layer, state, shell } = entry;
|
||||
if (shell) {
|
||||
shell.setAlpha(state.alpha);
|
||||
shell.setShow(state.shown);
|
||||
return;
|
||||
}
|
||||
if (!layer) return;
|
||||
layer.alpha = state.alpha;
|
||||
layer.show = state.shown;
|
||||
@@ -214,11 +278,89 @@ export function createCesiumImagery(
|
||||
Cesium.SplitDirection?.[SPLIT[state.split]] ?? layer.splitDirection;
|
||||
}
|
||||
|
||||
// A raised layer's place among the shells: the engine's draw order.
|
||||
const rankOf = (entry) => entry.state.options.order * 1e6 + entry.state.seq;
|
||||
|
||||
// A raised layer's detail rectangle in its image's texture coordinates.
|
||||
function detailWindow(source, detail) {
|
||||
const box = source.rectangle;
|
||||
const east = box.east <= box.west ? box.east + 360 : box.east;
|
||||
const x = east - box.west;
|
||||
const y = box.north - box.south;
|
||||
const r = detail.rectangle;
|
||||
return {
|
||||
west: (r.west - box.west) / x,
|
||||
south: (r.south - box.south) / y,
|
||||
east: (r.east - box.west) / x,
|
||||
north: (r.north - box.south) / y,
|
||||
};
|
||||
}
|
||||
|
||||
// A raised layer on its shell: an image again on the same rectangle
|
||||
// (Cesium draws the last texture until it is uploaded), else a new shell
|
||||
// in place of the last. With `onDrawn` (a staged source) a shell on
|
||||
// another rectangle waits unseen until it has drawn, then replaces the
|
||||
// drawn one, and `onDrawn` runs once the image has drawn.
|
||||
function mountShell(entry, source, decoded, onDrawn = null) {
|
||||
const image = drawable(decoded, createCanvas);
|
||||
const same = (box) =>
|
||||
['west', 'south', 'east', 'north'].every(
|
||||
(edge) => box[edge] === source.rectangle[edge],
|
||||
);
|
||||
let shell = entry.shell;
|
||||
if (shell && same(shell.rectangle)) shell.setImage(image);
|
||||
else {
|
||||
shell = make.shell({
|
||||
scene,
|
||||
rectangle: source.rectangle,
|
||||
height: entry.state.options.raise,
|
||||
rank: rankOf(entry),
|
||||
onSettled: () => {
|
||||
const waiting = entry.shellWaiting;
|
||||
if (waiting?.shell === shell && shell.drawn()) {
|
||||
entry.shellWaiting = null;
|
||||
waiting.done();
|
||||
}
|
||||
entry.detailWaiting?.check();
|
||||
},
|
||||
});
|
||||
shell.setImage(image);
|
||||
if (onDrawn && entry.shell) shell.setAlpha(0);
|
||||
else {
|
||||
entry.shell?.destroy();
|
||||
entry.shell = shell;
|
||||
}
|
||||
}
|
||||
const detail = entry.state.detail;
|
||||
if (detail)
|
||||
shell.setDetail(
|
||||
drawable(detail.image, createCanvas),
|
||||
detailWindow(source, detail),
|
||||
);
|
||||
applyLook(entry);
|
||||
requestRender('imagery');
|
||||
if (!onDrawn) return;
|
||||
const done = () => {
|
||||
if (entry.shell !== shell) {
|
||||
entry.shell?.destroy();
|
||||
entry.shell = shell;
|
||||
applyLook(entry);
|
||||
}
|
||||
onDrawn();
|
||||
};
|
||||
if (shell.drawn()) done();
|
||||
else entry.shellWaiting = { shell, done };
|
||||
}
|
||||
|
||||
// The layer for the current source on the current host, in place of the
|
||||
// one drawn (at its index, so a new source keeps its stack position).
|
||||
function mount(entry) {
|
||||
const { collection } = host();
|
||||
const source = entry.state.source;
|
||||
if (entry.state.options.raise !== null) {
|
||||
if (entry.image) mountShell(entry, source, entry.image);
|
||||
return;
|
||||
}
|
||||
const { collection } = host();
|
||||
if (!usable(collection) || (source.kind === 'image' && !entry.image)) {
|
||||
detach(entry);
|
||||
return;
|
||||
@@ -241,10 +383,25 @@ export function createCesiumImagery(
|
||||
requestRender('imagery');
|
||||
}
|
||||
|
||||
// An image source's image: now, or once its URL has loaded (null when it
|
||||
// fails). `owner()` says whether the load is still wanted.
|
||||
function imageOf(source, owner) {
|
||||
if (source.kind !== 'image') return Promise.resolve(null);
|
||||
if (source.image) return Promise.resolve(source.image);
|
||||
return Promise.resolve(make.loadImage(source.url)).then(
|
||||
(image) => (owner() ? image : null),
|
||||
(error) => {
|
||||
if (owner()) console.warn('[Imagery] image failed to load:', error);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// An image source: its image now, or once its URL has loaded.
|
||||
function load(entry) {
|
||||
const source = entry.state.source;
|
||||
entry.loading = null;
|
||||
entry.credit = creditOf(source.credit);
|
||||
if (source.kind !== 'image' || source.image) {
|
||||
entry.image = source.image;
|
||||
mount(entry);
|
||||
@@ -268,14 +425,190 @@ export function createCesiumImagery(
|
||||
);
|
||||
}
|
||||
|
||||
// A staged source on a draped layer: a second layer at alpha 0 right over
|
||||
// the drawn one. Its requests are counted; once they are in (the globe's
|
||||
// tiles all loaded, or its own quiet for a while) for two frames in a
|
||||
// row, it takes the drawn one's place, which goes after the next frame.
|
||||
function stageDraped(entry, job) {
|
||||
const { collection } = host();
|
||||
if (!usable(collection) || !entry.state.shown) {
|
||||
// Nothing draws it now: it replaces the drawn one at once.
|
||||
swapIn(entry, job);
|
||||
return;
|
||||
}
|
||||
job.collection = collection;
|
||||
const provider = providerFor(job, job.source);
|
||||
const requestImage = provider.requestImage.bind(provider);
|
||||
provider.requestImage = (x, y, level, request) => {
|
||||
if (job.closed) return undefined;
|
||||
const result = requestImage(x, y, level, request);
|
||||
const key = `${level}/${x}/${y}`;
|
||||
job.lastActivity = now();
|
||||
if (!result) {
|
||||
// Scheduler admission is part of readiness, not a loaded tile.
|
||||
job.deferred.add(key);
|
||||
return result;
|
||||
}
|
||||
job.deferred.delete(key);
|
||||
job.pending++;
|
||||
return Promise.resolve(result)
|
||||
.then((image) => {
|
||||
job.retries.delete(key);
|
||||
job.loaded++;
|
||||
return image;
|
||||
})
|
||||
.finally(() => {
|
||||
job.pending--;
|
||||
job.lastActivity = now();
|
||||
if (!job.closed) requestRender('imagery-stage');
|
||||
});
|
||||
};
|
||||
job.offError = provider.errorEvent?.addEventListener((error) => {
|
||||
if (job.closed) return;
|
||||
const status = error?.error?.statusCode;
|
||||
const key = `${error.level}/${error.x}/${error.y}`;
|
||||
const retries = job.retries.get(key) ?? 0;
|
||||
error.retry = false;
|
||||
if ((status === 429 || status === 503) && retries < STAGE_RETRIES) {
|
||||
job.retries.set(key, retries + 1);
|
||||
error.retry = true;
|
||||
return;
|
||||
}
|
||||
job.failed = true;
|
||||
requestRender('imagery-stage');
|
||||
});
|
||||
job.layer = make.layer(provider, { alpha: 0, show: true });
|
||||
job.layer.splitDirection =
|
||||
Cesium.SplitDirection?.[SPLIT[entry.state.split]] ??
|
||||
job.layer.splitDirection;
|
||||
if (entry.layer && entry.collection === collection)
|
||||
collection.add(job.layer, collection.indexOf(entry.layer) + 1);
|
||||
else place(entry, job.layer, collection);
|
||||
let settled = 0;
|
||||
job.offCamera = scene.camera?.moveEnd?.addEventListener(() => {
|
||||
// Tiles abandoned by the last view are no longer the source's work.
|
||||
job.deferred.clear();
|
||||
job.lastActivity = now();
|
||||
settled = 0;
|
||||
requestRender('imagery-stage');
|
||||
});
|
||||
job.offRender = scene.postRender?.addEventListener(() => {
|
||||
if (job.closed) return;
|
||||
if (job.failed) {
|
||||
closeJob(job);
|
||||
entry.staging = null;
|
||||
job.finish(false);
|
||||
return;
|
||||
}
|
||||
const own =
|
||||
job.loaded > 0 &&
|
||||
job.deferred.size === 0 &&
|
||||
now() - job.lastActivity >= STAGE_QUIET_MS;
|
||||
const globeIn =
|
||||
host().surface === 'globe' && scene.globe?.tilesLoaded === true;
|
||||
if ((globeIn || own) && job.pending === 0) {
|
||||
if (++settled >= 2) swapIn(entry, job);
|
||||
else requestRender('imagery-stage');
|
||||
return;
|
||||
}
|
||||
settled = 0;
|
||||
// Waiting out the quiet interval needs another check later, not a
|
||||
// frame every frame.
|
||||
if (job.pending === 0 && job.loaded > 0 && job.wake === null)
|
||||
job.wake = after(() => {
|
||||
job.wake = null;
|
||||
if (!job.closed) requestRender('imagery-stage');
|
||||
}, STAGE_WAKE_MS);
|
||||
});
|
||||
requestRender('imagery-stage');
|
||||
}
|
||||
|
||||
function closeJob(job) {
|
||||
job.closed = true;
|
||||
job.offRender?.();
|
||||
job.offCamera?.();
|
||||
job.offError?.();
|
||||
job.retry.cancel();
|
||||
if (job.wake !== null) cancel(job.wake);
|
||||
job.wake = null;
|
||||
const { layer, collection } = job;
|
||||
job.layer = null;
|
||||
if (!layer) return;
|
||||
if (usable(collection) && collection.contains(layer))
|
||||
collection.remove(layer, true);
|
||||
else if (!layer.isDestroyed?.()) layer.destroy?.();
|
||||
}
|
||||
|
||||
// The staged source takes the drawn one's place.
|
||||
function swapIn(entry, job) {
|
||||
entry.staging = null;
|
||||
const layer = job.layer;
|
||||
job.layer = null;
|
||||
closeJob(job);
|
||||
entry.loading = null;
|
||||
entry.image = job.image;
|
||||
entry.credit = job.credit;
|
||||
entry.retry.cancel();
|
||||
entry.retry = job.retry;
|
||||
job.finish(true);
|
||||
if (!layer) {
|
||||
mount(entry);
|
||||
return;
|
||||
}
|
||||
const previous = entry.layer;
|
||||
const previousCollection = entry.collection;
|
||||
entry.layer = layer;
|
||||
entry.collection = job.collection;
|
||||
applyLook(entry);
|
||||
if (previous) {
|
||||
// The drawn one goes after the next frame, which draws the new one.
|
||||
const off = scene.postRender?.addEventListener(() => {
|
||||
off();
|
||||
if (usable(previousCollection) && previousCollection.contains(previous))
|
||||
previousCollection.remove(previous, true);
|
||||
else if (!previous.isDestroyed?.()) previous.destroy?.();
|
||||
requestRender('imagery-stage');
|
||||
});
|
||||
if (!off) {
|
||||
if (previousCollection?.contains(previous))
|
||||
previousCollection.remove(previous, true);
|
||||
}
|
||||
}
|
||||
requestRender('imagery-stage');
|
||||
}
|
||||
|
||||
// Follow the surface: a layer whose stack is not the current one is
|
||||
// built again there (none: it waits without a layer).
|
||||
// built again there (none: it waits without a layer); a staged source
|
||||
// on the last stack starts again on the new one.
|
||||
const follow = () => {
|
||||
const { collection } = host();
|
||||
for (const entry of entries)
|
||||
for (const entry of entries) {
|
||||
if (entry.state.options.raise !== null) continue;
|
||||
if (entry.collection !== collection && (entry.layer || collection))
|
||||
mount(entry);
|
||||
const job = entry.staging;
|
||||
if (job?.layer && job.collection !== collection) {
|
||||
closeJob(job);
|
||||
Object.assign(job, freshJob(job));
|
||||
stageDraped(entry, job);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// A staged job's counters, new.
|
||||
const freshJob = (job) => ({
|
||||
closed: false,
|
||||
layer: null,
|
||||
collection: null,
|
||||
pending: 0,
|
||||
loaded: 0,
|
||||
failed: false,
|
||||
deferred: new Set(),
|
||||
retries: new Map(),
|
||||
lastActivity: now(),
|
||||
wake: null,
|
||||
retry: makeRetry(() => job.state),
|
||||
});
|
||||
const watch = () => {
|
||||
if (!removeWatch && scene.preRender)
|
||||
removeWatch = scene.preRender.addEventListener(follow);
|
||||
@@ -286,45 +619,154 @@ export function createCesiumImagery(
|
||||
removeWatch = null;
|
||||
};
|
||||
|
||||
// One timer per layer: any number of provider deferrals while it is
|
||||
// armed share the same single retry frame.
|
||||
function makeRetry(stateOf) {
|
||||
let retryTimer = null;
|
||||
return {
|
||||
schedule() {
|
||||
if (retryTimer !== null) return;
|
||||
retryTimer = after(() => {
|
||||
retryTimer = null;
|
||||
if (!stateOf()?.destroyed) requestRender('imagery-retry');
|
||||
}, TILE_RETRY_DELAY_MS);
|
||||
},
|
||||
cancel() {
|
||||
if (retryTimer !== null) cancel(retryTimer);
|
||||
retryTimer = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function unstage(entry) {
|
||||
const job = entry.staging;
|
||||
entry.staging = null;
|
||||
if (!job) return;
|
||||
const waiting = entry.shellWaiting;
|
||||
entry.shellWaiting = null;
|
||||
if (waiting && waiting.shell !== entry.shell) waiting.shell.destroy();
|
||||
closeJob(job);
|
||||
}
|
||||
|
||||
const registry = createImageryRegistry(
|
||||
(state) => {
|
||||
let retryTimer = null;
|
||||
const entry = {
|
||||
state,
|
||||
layer: null,
|
||||
collection: null,
|
||||
image: null,
|
||||
loading: null,
|
||||
// One timer per layer: any number of provider deferrals while it is
|
||||
// armed share the same single retry frame.
|
||||
retry: {
|
||||
schedule() {
|
||||
if (retryTimer !== null) return;
|
||||
retryTimer = after(() => {
|
||||
retryTimer = null;
|
||||
if (!state.destroyed) requestRender('imagery-retry');
|
||||
}, TILE_RETRY_DELAY_MS);
|
||||
},
|
||||
cancel() {
|
||||
if (retryTimer !== null) cancel(retryTimer);
|
||||
retryTimer = null;
|
||||
},
|
||||
},
|
||||
credit: undefined,
|
||||
shell: null,
|
||||
shellWaiting: null,
|
||||
detailWaiting: null,
|
||||
staging: null,
|
||||
retry: makeRetry(() => state),
|
||||
};
|
||||
entries.add(entry);
|
||||
watch();
|
||||
load(entry);
|
||||
return {
|
||||
source: () => load(entry),
|
||||
source() {
|
||||
unstage(entry);
|
||||
load(entry);
|
||||
},
|
||||
credit() {
|
||||
entry.credit = creditOf(state.source.credit);
|
||||
requestRender('imagery-credit');
|
||||
},
|
||||
stage(source, finish) {
|
||||
unstage(entry);
|
||||
const job = {
|
||||
state,
|
||||
source,
|
||||
finish,
|
||||
image: null,
|
||||
credit: creditOf(source.credit),
|
||||
};
|
||||
Object.assign(job, freshJob(job));
|
||||
entry.staging = job;
|
||||
imageOf(source, () => entry.staging === job && !state.destroyed).then(
|
||||
(image) => {
|
||||
if (entry.staging !== job || state.destroyed) return;
|
||||
if (source.kind === 'image' && !image) {
|
||||
entry.staging = null;
|
||||
closeJob(job);
|
||||
finish(false);
|
||||
return;
|
||||
}
|
||||
job.image = image;
|
||||
if (state.options.raise === null) {
|
||||
stageDraped(entry, job);
|
||||
return;
|
||||
}
|
||||
// A raised layer: the image on its shell, in place once it
|
||||
// has drawn (a hidden shell draws nothing: at once).
|
||||
const swap = () => {
|
||||
if (entry.staging !== job) return;
|
||||
entry.staging = null;
|
||||
closeJob(job);
|
||||
entry.image = image;
|
||||
entry.credit = job.credit;
|
||||
finish(true);
|
||||
};
|
||||
if (state.shown) mountShell(entry, source, image, swap);
|
||||
else {
|
||||
mountShell(entry, source, image);
|
||||
swap();
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
unstage: () => unstage(entry),
|
||||
detail(detail, finish) {
|
||||
entry.detailWaiting = null;
|
||||
const shell = entry.shell;
|
||||
if (!shell) {
|
||||
finish(detail !== null);
|
||||
return;
|
||||
}
|
||||
if (!detail) {
|
||||
shell.setDetail(null);
|
||||
return;
|
||||
}
|
||||
const image = drawable(detail.image, createCanvas);
|
||||
shell.setDetail(image, detailWindow(state.source, detail));
|
||||
const waiting = {
|
||||
check() {
|
||||
if (entry.detailWaiting !== waiting) return;
|
||||
if (shell.detail() !== image || !shell.drawn()) return;
|
||||
entry.detailWaiting = null;
|
||||
finish(true);
|
||||
},
|
||||
};
|
||||
entry.detailWaiting = waiting;
|
||||
waiting.check();
|
||||
},
|
||||
look() {
|
||||
applyLook(entry);
|
||||
if (entry.staging?.layer)
|
||||
entry.staging.layer.splitDirection =
|
||||
Cesium.SplitDirection?.[SPLIT[state.split]] ??
|
||||
entry.staging.layer.splitDirection;
|
||||
// A hidden layer stages nothing: the staged source replaces the
|
||||
// drawn one at once.
|
||||
if (!state.shown && entry.staging?.layer)
|
||||
swapIn(entry, entry.staging);
|
||||
requestRender('imagery-look');
|
||||
},
|
||||
ready: () => Boolean(entry.layer?.ready),
|
||||
ready: () =>
|
||||
state.options.raise !== null
|
||||
? Boolean(entry.shell?.drawn())
|
||||
: Boolean(entry.layer?.ready),
|
||||
destroy() {
|
||||
entries.delete(entry);
|
||||
entry.loading = null;
|
||||
unstage(entry);
|
||||
entry.retry.cancel();
|
||||
entry.shell?.destroy();
|
||||
entry.shell = null;
|
||||
entry.detailWaiting = null;
|
||||
detach(entry);
|
||||
unwatch();
|
||||
requestRender('imagery-destroy');
|
||||
|
||||
@@ -343,3 +343,188 @@ test('an image URL draws once it has loaded; a newer source wins', async () => {
|
||||
assert.equal(image.name, 'after');
|
||||
assert.equal(layer.ready(), true);
|
||||
});
|
||||
|
||||
test('geographic tiles take Cesium’s 2×1 tiling; a transform draws each tile', async () => {
|
||||
const f = fixture();
|
||||
const drawn = [];
|
||||
f.imagery.createLayer({
|
||||
id: 'radar',
|
||||
source: tiles({
|
||||
scheme: 'geographic',
|
||||
transform: (image) => {
|
||||
drawn.push(image);
|
||||
return { masked: image };
|
||||
},
|
||||
}),
|
||||
});
|
||||
const provider = f.globe.get(0).imageryProvider;
|
||||
assert.ok(
|
||||
provider.options.tilingScheme instanceof Cesium.GeographicTilingScheme,
|
||||
);
|
||||
assert.equal(provider.options.tilingScheme.getNumberOfXTilesAtLevel(0), 2);
|
||||
const request = provider.requestImage(1, 0, 0);
|
||||
f.providers[0].pending[0]({ name: 'tile' });
|
||||
assert.deepEqual(await request, { masked: { name: 'tile' } });
|
||||
assert.deepEqual(drawn, [{ name: 'tile' }]);
|
||||
});
|
||||
|
||||
// A fixture whose scene draws frames: postRender, a globe whose tiles load.
|
||||
function stagingFixture() {
|
||||
const f = fixture();
|
||||
f.viewer.scene.postRender = new Cesium.Event();
|
||||
f.viewer.scene.globe.tilesLoaded = true;
|
||||
f.render = () => f.viewer.scene.postRender.raiseEvent();
|
||||
return f;
|
||||
}
|
||||
|
||||
test('a staged source loads at alpha 0 over the drawn one and takes its place once its tiles are in', async () => {
|
||||
const f = stagingFixture();
|
||||
const layer = f.imagery.createLayer({ id: 'a', source: tiles(), alpha: 0.7 });
|
||||
const drawn = f.globe.get(0);
|
||||
const staged = layer.setSource(
|
||||
tiles({ url: 'https://next.example/{z}/{x}/{y}.png' }),
|
||||
{ staged: true },
|
||||
);
|
||||
let swapped;
|
||||
staged.then((value) => (swapped = value));
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.equal(f.globe.length, 2);
|
||||
const incoming = f.globe.get(1);
|
||||
assert.equal(incoming.alpha, 0, 'the staged layer loads unseen');
|
||||
assert.equal(drawn.alpha, 0.7, 'the drawn layer stays');
|
||||
const request = incoming.imageryProvider.requestImage(0, 0, 1);
|
||||
f.render();
|
||||
f.render();
|
||||
assert.equal(swapped, undefined, 'a request in flight holds it back');
|
||||
f.providers[1].pending[0]('tile');
|
||||
await request;
|
||||
f.render();
|
||||
f.render();
|
||||
await Promise.resolve();
|
||||
assert.equal(swapped, true);
|
||||
assert.equal(incoming.alpha, 0.7);
|
||||
assert.match(layer.source().url, /next/);
|
||||
assert.equal(f.globe.length, 2, 'the drawn one goes after the next frame');
|
||||
f.render();
|
||||
assert.deepEqual(layersOf(f.globe), [incoming]);
|
||||
assert.equal(drawn.isDestroyed(), true);
|
||||
});
|
||||
|
||||
test('a staged source whose tile fails leaves the drawn one', async () => {
|
||||
const f = stagingFixture();
|
||||
const layer = f.imagery.createLayer({ id: 'a', source: tiles() });
|
||||
const staged = layer.setSource(
|
||||
tiles({ url: 'https://next.example/{z}/{x}/{y}.png' }),
|
||||
{ staged: true },
|
||||
);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
const incoming = f.globe.get(1);
|
||||
// Throttled tiles retry; a missing one fails the source.
|
||||
const throttled = { x: 0, y: 0, level: 1, error: { statusCode: 429 } };
|
||||
incoming.imageryProvider.errorEvent.raiseEvent(throttled);
|
||||
assert.equal(throttled.retry, true);
|
||||
incoming.imageryProvider.errorEvent.raiseEvent({
|
||||
x: 1,
|
||||
y: 0,
|
||||
level: 1,
|
||||
error: { statusCode: 404 },
|
||||
});
|
||||
f.render();
|
||||
assert.equal(await staged, false);
|
||||
assert.equal(f.globe.length, 1);
|
||||
assert.match(layer.source().url, /gibs/);
|
||||
});
|
||||
|
||||
test('a raised layer is a shell over its rectangle; a staged image swaps once it has drawn', async () => {
|
||||
const shells = [];
|
||||
const preRender = new Cesium.Event();
|
||||
const viewer = {
|
||||
imageryLayers: new Cesium.ImageryLayerCollection(),
|
||||
scene: { globe: { show: true }, preRender },
|
||||
};
|
||||
const { imagery } = createCesiumImagery(viewer, {
|
||||
requestRender() {},
|
||||
createCanvas: (width, height) => ({
|
||||
width,
|
||||
height,
|
||||
getContext: () => ({
|
||||
createImageData: (w, h) => ({ data: new Uint8ClampedArray(w * h * 4) }),
|
||||
putImageData() {},
|
||||
}),
|
||||
}),
|
||||
factories: {
|
||||
shell(options) {
|
||||
const shell = {
|
||||
options,
|
||||
rectangle: options.rectangle,
|
||||
image: null,
|
||||
alpha: 1,
|
||||
shown: true,
|
||||
painted: false,
|
||||
destroyed: false,
|
||||
setImage(image) {
|
||||
shell.image = image;
|
||||
shell.painted = false;
|
||||
},
|
||||
setAlpha: (alpha) => (shell.alpha = alpha),
|
||||
setShow: (show) => (shell.shown = show),
|
||||
setDetail() {},
|
||||
detail: () => null,
|
||||
drawn: () => shell.painted,
|
||||
paint() {
|
||||
shell.painted = true;
|
||||
options.onSettled();
|
||||
},
|
||||
destroy: () => (shell.destroyed = true),
|
||||
};
|
||||
shells.push(shell);
|
||||
return shell;
|
||||
},
|
||||
},
|
||||
});
|
||||
const image = pixels(8, 4);
|
||||
const layer = imagery.createLayer({
|
||||
id: 'shell',
|
||||
source: { kind: 'image', image, rectangle: BOX },
|
||||
raise: 6000,
|
||||
alpha: 0.7,
|
||||
});
|
||||
assert.equal(viewer.imageryLayers.length, 0, 'no draped layer');
|
||||
assert.equal(shells.length, 1);
|
||||
assert.deepEqual(shells[0].options.rectangle, BOX);
|
||||
assert.equal(shells[0].options.height, 6000);
|
||||
assert.equal(shells[0].alpha, 0.7);
|
||||
assert.equal(layer.ready(), false);
|
||||
shells[0].paint();
|
||||
assert.equal(layer.ready(), true);
|
||||
// The same rectangle: the shell's image, swapped once it has drawn.
|
||||
const next = pixels(8, 4);
|
||||
const staged = layer.setSource(
|
||||
{ kind: 'image', image: next, rectangle: BOX },
|
||||
{ staged: true },
|
||||
);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.equal(shells.length, 1);
|
||||
let done;
|
||||
staged.then((value) => (done = value));
|
||||
await Promise.resolve();
|
||||
assert.equal(done, undefined);
|
||||
shells[0].paint();
|
||||
assert.equal(await staged, true);
|
||||
// Another rectangle: a new shell unseen until it has drawn.
|
||||
const wider = { ...BOX, west: -98 };
|
||||
const moved = layer.setSource(
|
||||
{ kind: 'image', image: next, rectangle: wider },
|
||||
{ staged: true },
|
||||
);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.equal(shells.length, 2);
|
||||
assert.equal(shells[1].alpha, 0);
|
||||
assert.equal(shells[0].destroyed, false);
|
||||
shells[1].paint();
|
||||
assert.equal(await moved, true);
|
||||
assert.equal(shells[0].destroyed, true);
|
||||
assert.equal(shells[1].alpha, 0.7);
|
||||
layer.destroy();
|
||||
assert.equal(shells[1].destroyed, true);
|
||||
});
|
||||
@@ -0,0 +1,299 @@
|
||||
// A raised imagery layer on Cesium (engine.imagery's `raise`): one
|
||||
// rectangle primitive at a height above the ellipsoid drawing one image
|
||||
// and, inside a window of it, an optional detail image. Cesium's imagery
|
||||
// drapes on the globe and on 3D tiles only, so a raised layer is a
|
||||
// primitive of its own: flat shaded, alpha blended in the opaque pass
|
||||
// without depth writes, first in scene.primitives in the engine's draw
|
||||
// order (later shells draw over earlier ones, every other primitive over
|
||||
// them), never picked. It rises with the camera (imagery.js raisedLift)
|
||||
// by a uniform scale about the Earth's centre, which keeps stacked shells
|
||||
// in their order.
|
||||
|
||||
import * as Cesium from 'cesium';
|
||||
import { raisedLift } from '../imagery.js';
|
||||
|
||||
const MATERIAL_TYPE = 'GevRaisedImagery';
|
||||
// Renders after an image swap: one queues the upload, one uploads and draws, one spare.
|
||||
const UPLOAD_FRAMES = 3;
|
||||
// An empty detail window: the image shows everywhere.
|
||||
const NO_WINDOW = Object.freeze({ west: 0, south: 0, east: -1, north: -1 });
|
||||
// Cesium binds a 1×1 white texture to an image uniform until its first upload:
|
||||
// draw nothing until the image has arrived, and sample the detail image only
|
||||
// once it has arrived. The window is west, south, east, north in the image's
|
||||
// texture coordinates.
|
||||
const MATERIAL_SOURCE = `czm_material czm_getMaterial(czm_materialInput materialInput)
|
||||
{
|
||||
czm_material material = czm_getDefaultMaterial(materialInput);
|
||||
vec2 st = materialInput.st;
|
||||
vec4 coarse = texture(image, st);
|
||||
vec2 dst = (st - window.xy) / max(window.zw - window.xy, vec2(1e-6));
|
||||
float inside = float(all(greaterThanEqual(st, window.xy)) && all(lessThanEqual(st, window.zw)));
|
||||
float useDetail = inside * step(1.5, float(detailDimensions.x));
|
||||
vec4 c = mix(coarse, texture(detail, clamp(dst, 0.0, 1.0)), useDetail);
|
||||
material.diffuse = czm_gammaCorrect(c.rgb);
|
||||
material.alpha = c.a * alpha * step(1.5, float(imageDimensions.x));
|
||||
return material;
|
||||
}
|
||||
`;
|
||||
const ranks = new WeakMap();
|
||||
|
||||
function registerMaterial() {
|
||||
const cache = Cesium.Material._materialCache;
|
||||
if (cache.getMaterial(MATERIAL_TYPE)) return;
|
||||
// A plain template: building the first material from a fabric would make that
|
||||
// instance Cesium's shared template and keep its last image alive.
|
||||
cache.addMaterial(MATERIAL_TYPE, {
|
||||
fabric: {
|
||||
type: MATERIAL_TYPE,
|
||||
uniforms: {
|
||||
image: Cesium.Material.DefaultImageId,
|
||||
detail: Cesium.Material.DefaultImageId,
|
||||
alpha: 1,
|
||||
window: { type: 'vec4', x: 0, y: 0, z: -1, w: -1 },
|
||||
},
|
||||
// Diffuse and alpha share these samples, so one source, not components.
|
||||
source: MATERIAL_SOURCE,
|
||||
},
|
||||
translucent: false,
|
||||
});
|
||||
}
|
||||
|
||||
const sameEdges = (a, b) =>
|
||||
a.west === b.west &&
|
||||
a.south === b.south &&
|
||||
a.east === b.east &&
|
||||
a.north === b.north;
|
||||
|
||||
/** Keep the shells first in the primitive collection, by rank: higher ranks
|
||||
* draw over lower ones and other opaque content draws over both. */
|
||||
export function orderImageryShells(primitives, primitive, rank) {
|
||||
ranks.set(primitive, rank);
|
||||
if (typeof primitives.lowerToBottom !== 'function') return;
|
||||
const shells = [];
|
||||
for (let i = 0; i < primitives.length; i++) {
|
||||
const item = primitives.get(i);
|
||||
if (ranks.has(item)) shells.push(item);
|
||||
}
|
||||
const ordered = [...shells].sort((a, b) => ranks.get(a) - ranks.get(b));
|
||||
if (ordered.every((item, i) => primitives.get(i) === item)) return;
|
||||
for (const item of ordered.reverse()) primitives.lowerToBottom(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* One shell over `rectangle` (degrees) at `height` metres, in draw position
|
||||
* `rank`. `onSettled()` runs each time the latest image (and detail) has
|
||||
* drawn. The owner calls destroy().
|
||||
*/
|
||||
export function createImageryShell({
|
||||
scene,
|
||||
rectangle,
|
||||
height,
|
||||
rank = 0,
|
||||
onSettled = () => {},
|
||||
}) {
|
||||
registerMaterial();
|
||||
const primitives = scene.primitives;
|
||||
const material = new Cesium.Material({
|
||||
fabric: { type: MATERIAL_TYPE },
|
||||
translucent: false,
|
||||
});
|
||||
// Flat shading keeps the image's colours independent of the viewing angle.
|
||||
const appearance = new Cesium.EllipsoidSurfaceAppearance({
|
||||
aboveGround: true,
|
||||
flat: true,
|
||||
translucent: false,
|
||||
material,
|
||||
});
|
||||
// Cesium orders its translucent pass itself (weighted OIT or distance), which
|
||||
// cannot honour stacked shells. Draw in the opaque pass in scene.primitives
|
||||
// order, alpha-blended and without depth writes, so later shells draw over
|
||||
// earlier ones and nothing is hidden or picked through a shell.
|
||||
appearance.getRenderState = () => ({
|
||||
depthTest: { enabled: true },
|
||||
depthMask: false,
|
||||
blending: Cesium.BlendingState.ALPHA_BLEND,
|
||||
});
|
||||
const { west, south, east, north } = rectangle;
|
||||
const primitive = new Cesium.Primitive({
|
||||
geometryInstances: new Cesium.GeometryInstance({
|
||||
geometry: new Cesium.RectangleGeometry({
|
||||
rectangle: Cesium.Rectangle.fromDegrees(west, south, east, north),
|
||||
height,
|
||||
granularity: Cesium.Math.toRadians(0.5),
|
||||
vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
|
||||
}),
|
||||
}),
|
||||
appearance,
|
||||
asynchronous: true,
|
||||
allowPicking: false,
|
||||
});
|
||||
primitives.add(primitive);
|
||||
orderImageryShells(primitives, primitive, rank);
|
||||
let lift = 0;
|
||||
const offLift = scene.preRender?.addEventListener(() => {
|
||||
const next = raisedLift(scene.camera?.positionCartographic?.height);
|
||||
if (next === lift) return;
|
||||
lift = next;
|
||||
primitive.modelMatrix = Cesium.Matrix4.fromUniformScale(
|
||||
1 + lift / Cesium.Ellipsoid.WGS84.maximumRadius,
|
||||
);
|
||||
});
|
||||
let image = null;
|
||||
let frames = 0;
|
||||
// The detail image, its own upload count and a window waiting for it to draw.
|
||||
let detail = null;
|
||||
let detailFrames = 0;
|
||||
let pendingWindow = null;
|
||||
let offRender = null;
|
||||
let destroyed = false;
|
||||
|
||||
const fits = (size, value) =>
|
||||
!size || (size.x === value.width && size.y === value.height);
|
||||
const uploaded = () =>
|
||||
image !== null && fits(material.uniforms.imageDimensions, image);
|
||||
const detailDrawn = () =>
|
||||
detail !== null &&
|
||||
detailFrames === 0 &&
|
||||
fits(material.uniforms.detailDimensions, detail);
|
||||
const drawn = () =>
|
||||
primitive.ready &&
|
||||
uploaded() &&
|
||||
frames === 0 &&
|
||||
(detail === null || (detailDrawn() && pendingWindow === null));
|
||||
function appliedWindow() {
|
||||
const { x, y, z, w } = material.uniforms.window;
|
||||
return z < x ? null : { west: x, south: y, east: z, north: w };
|
||||
}
|
||||
function setWindow(rect) {
|
||||
const next = rect ?? NO_WINDOW;
|
||||
const { x, y, z, w } = material.uniforms.window;
|
||||
if (
|
||||
x === next.west &&
|
||||
y === next.south &&
|
||||
z === next.east &&
|
||||
w === next.north
|
||||
)
|
||||
return;
|
||||
material.uniforms.window = new Cesium.Cartesian4(
|
||||
next.west,
|
||||
next.south,
|
||||
next.east,
|
||||
next.north,
|
||||
);
|
||||
scene.requestRender();
|
||||
}
|
||||
// The render governor may idle the scene; request frames only until the
|
||||
// asynchronous geometry is ready and the latest images have been drawn.
|
||||
function tick() {
|
||||
// Cesium updates a material only while its primitive is shown, so hidden
|
||||
// frames upload nothing and count for nothing.
|
||||
if (primitive.ready && primitive.show) {
|
||||
if (frames > 0) frames--;
|
||||
if (detailFrames > 0) detailFrames--;
|
||||
// A texture is never shown at another window's place.
|
||||
if (pendingWindow && detailDrawn()) {
|
||||
setWindow(pendingWindow);
|
||||
pendingWindow = null;
|
||||
}
|
||||
}
|
||||
if (primitive.show && !drawn()) {
|
||||
scene.requestRender();
|
||||
return;
|
||||
}
|
||||
offRender?.();
|
||||
offRender = null;
|
||||
if (drawn()) onSettled();
|
||||
}
|
||||
function wake() {
|
||||
if (destroyed || !primitive.show || image === null || drawn()) return;
|
||||
offRender ??= scene.postRender.addEventListener(tick);
|
||||
scene.requestRender();
|
||||
}
|
||||
|
||||
return {
|
||||
rectangle,
|
||||
/** Draw `next`; Cesium keeps drawing the previous texture until it is uploaded. */
|
||||
setImage(next) {
|
||||
if (destroyed || next === image) return;
|
||||
image = next;
|
||||
material.uniforms.image = next;
|
||||
frames = UPLOAD_FRAMES;
|
||||
wake();
|
||||
},
|
||||
image: () => image,
|
||||
setAlpha(value) {
|
||||
if (destroyed || material.uniforms.alpha === value) return;
|
||||
material.uniforms.alpha = value;
|
||||
scene.requestRender();
|
||||
},
|
||||
/** Draw `next` inside `rect` (west, south, east, north in the image's
|
||||
* texture coordinates, 0–1); null clears it. In the same window only
|
||||
* the image changes, and Cesium keeps drawing the previous texture until
|
||||
* this one is uploaded. A different window applies once its image has
|
||||
* drawn; until then the image covers it. */
|
||||
setDetail(next, rect) {
|
||||
if (destroyed) return;
|
||||
if (!next) {
|
||||
if (detail === null) return;
|
||||
detail = null;
|
||||
detailFrames = 0;
|
||||
pendingWindow = null;
|
||||
material.uniforms.detail = Cesium.Material.DefaultImageId;
|
||||
setWindow(null);
|
||||
scene.requestRender();
|
||||
return;
|
||||
}
|
||||
if (next !== detail) {
|
||||
detail = next;
|
||||
material.uniforms.detail = next;
|
||||
detailFrames = UPLOAD_FRAMES;
|
||||
}
|
||||
const applied = appliedWindow();
|
||||
if (applied && sameEdges(applied, rect)) {
|
||||
pendingWindow = null;
|
||||
} else {
|
||||
setWindow(null);
|
||||
pendingWindow = rect;
|
||||
}
|
||||
wake();
|
||||
},
|
||||
detail: () => detail,
|
||||
setShow(value) {
|
||||
const show = Boolean(value);
|
||||
if (destroyed || primitive.show === show) return;
|
||||
primitive.show = show;
|
||||
wake();
|
||||
scene.requestRender();
|
||||
},
|
||||
setRank(value) {
|
||||
if (!destroyed && !primitives.isDestroyed?.())
|
||||
orderImageryShells(primitives, primitive, value);
|
||||
},
|
||||
drawn,
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
offRender?.();
|
||||
offRender = null;
|
||||
offLift?.();
|
||||
if (!primitives.isDestroyed?.() && primitives.contains(primitive))
|
||||
primitives.remove(primitive);
|
||||
if (!primitive.isDestroyed()) primitive.destroy();
|
||||
// Primitive.destroy leaves the material and its texture alive.
|
||||
if (!material.isDestroyed()) material.destroy();
|
||||
image = null;
|
||||
detail = null;
|
||||
pendingWindow = null;
|
||||
scene.requestRender();
|
||||
},
|
||||
diagnostics: () => ({
|
||||
height,
|
||||
ready: Boolean(primitive.ready),
|
||||
uploaded: uploaded(),
|
||||
show: primitive.show,
|
||||
alpha: material.uniforms.alpha,
|
||||
rendering: offRender !== null,
|
||||
detail: { uploaded: detailDrawn(), window: appliedWindow() },
|
||||
}),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user