Skip to content

Commit 14083c5

Browse files
authored
Add dedicated download queue per image overlay (#1621)
1 parent 3b40618 commit 14083c5

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/core/renderer/tiles/TilesRendererBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export const unifiedPriorityCallback = ( a, b ) => {
329329
const DEFAULT_LRU_CACHE = new LRUCache();
330330
DEFAULT_LRU_CACHE.unloadPriorityCallback = lruPriorityCallback;
331331

332-
const DEFAULT_DOWNLOAD_QUEUE = new PriorityQueue();
332+
export const DEFAULT_DOWNLOAD_QUEUE = new PriorityQueue();
333333
DEFAULT_DOWNLOAD_QUEUE.maxJobs = 25;
334334
DEFAULT_DOWNLOAD_QUEUE.priorityCallback = unifiedPriorityCallback;
335335

src/three/plugins/images/ImageOverlayPlugin.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Color, Matrix4, WebGLRenderer } from 'three';
2+
import { PriorityQueue } from '3d-tiles-renderer/core';
23
import { WMTSTileMatrix } from '../loaders/WMTSCapabilitiesLoader.js';
34

45
export class ImageOverlayPlugin {
@@ -27,6 +28,7 @@ export class ImageOverlay {
2728
preprocessURL: ( url: string ) => string | null;
2829
alphaMask: boolean;
2930
alphaInvert: boolean;
31+
downloadQueue: PriorityQueue;
3032
isReady: boolean;
3133
readonly isPlanarProjection: boolean;
3234

src/three/plugins/images/ImageOverlayPlugin.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** @import { WMTSTileMatrix } from './WMTSImageSource.js' */
33
/** @import { VectorTileStyle } from './utils/VectorShapeCanvasRenderer.js' */
44
import { Color, BufferAttribute, Matrix4, Vector3, Box3, Triangle, CanvasTexture } from 'three';
5-
import { PriorityQueue, PriorityQueueItemRemovedError, unifiedPriorityCallback } from '3d-tiles-renderer/core';
5+
import { PriorityQueue, PriorityQueueItemRemovedError, unifiedPriorityCallback, DEFAULT_DOWNLOAD_QUEUE } from '3d-tiles-renderer/core';
66
import { CesiumIonAuth, GoogleCloudAuth } from '3d-tiles-renderer/core/plugins';
77
import { XYZImageSource } from './sources/XYZImageSource.js';
88
import { QuadKeyImageSource } from './sources/QuadKeyImageSource.js';
@@ -928,24 +928,13 @@ export class ImageOverlayPlugin {
928928
// initialize the overlay to use the right fetch options, load all data for existing tiles
929929
_initOverlay( overlay ) {
930930

931-
const { tiles, processedTiles } = this;
931+
const { processedTiles } = this;
932932

933933
overlay.init().then( () => {
934934

935935
// Set resolution on the overlay
936936
overlay.setResolution( this.resolution );
937937

938-
// TODO: we should move away from reaching into specific "tiles renderer" download queue.
939-
// We should prefer an overarching, common download system.
940-
const overlayFetch = overlay.fetch.bind( overlay );
941-
overlay.fetch = ( ...args ) => tiles
942-
.downloadQueue
943-
.add( { priority: - performance.now() }, () => {
944-
945-
return overlayFetch( ...args );
946-
947-
} );
948-
949938
} );
950939

951940
const promises = [];
@@ -1396,6 +1385,7 @@ export class ImageOverlay {
13961385
this.frame = frame !== null ? frame.clone() : null;
13971386
this.alphaMask = alphaMask;
13981387
this.alphaInvert = alphaInvert;
1388+
this.downloadQueue = DEFAULT_DOWNLOAD_QUEUE;
13991389

14001390
this._whenReady = null;
14011391
this.isReady = false;
@@ -1438,7 +1428,7 @@ export class ImageOverlay {
14381428

14391429
}
14401430

1441-
return fetch( url, options );
1431+
return this.downloadQueue.add( { priority: - performance.now() }, () => fetch( url, options ) );
14421432

14431433
}
14441434

@@ -2097,10 +2087,22 @@ export class CesiumIonOverlay extends TiledImageOverlay {
20972087

20982088
}
20992089

2100-
fetch( ...args ) {
2090+
fetch( url, options = {} ) {
21012091

21022092
// bypass auth fetch if asset is external type to prevent CORS error due to wrong bearer token
2103-
return this.externalType ? super.fetch( ...args ) : this.auth.fetch( ...args );
2093+
if ( this.externalType ) {
2094+
2095+
return super.fetch( url, options );
2096+
2097+
}
2098+
2099+
if ( this.preprocessURL ) {
2100+
2101+
url = this.preprocessURL( url );
2102+
2103+
}
2104+
2105+
return this.downloadQueue.add( { priority: - performance.now() }, () => this.auth.fetch( url, options ) );
21042106

21052107
}
21062108

@@ -2166,9 +2168,15 @@ export class GoogleMapsOverlay extends TiledImageOverlay {
21662168

21672169
}
21682170

2169-
fetch( ...args ) {
2171+
fetch( url, options = {} ) {
2172+
2173+
if ( this.preprocessURL ) {
2174+
2175+
url = this.preprocessURL( url );
2176+
2177+
}
21702178

2171-
return this.auth.fetch( ...args );
2179+
return this.downloadQueue.add( { priority: - performance.now() }, () => this.auth.fetch( url, options ) );
21722180

21732181
}
21742182

0 commit comments

Comments
 (0)