Skip to content

Commit 2c68b2f

Browse files
authored
ImageOverlayPlugin: Delete only tile data associated with the tile set (#1403)
* ImageOverlayPlugin: Save actively used tiles * Only delete overlay info for the relevant processed tiles * Update events, fix non renderable tiles marking images to load * Fix event * Remove unused variable
1 parent 2165236 commit 2c68b2f

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

src/core/renderer/tiles/TilesRendererBase.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ export class TilesRendererBase {
961961
}
962962

963963
const res = this.invokeOnePlugin( plugin => plugin.fetchData && plugin.fetchData( uri, { ...this.fetchOptions, signal } ) );
964-
this.dispatchEvent( { type: 'tile-download-start', tile } );
964+
this.dispatchEvent( { type: 'tile-download-start', tile, uri } );
965965
return res;
966966

967967
} )
@@ -1075,6 +1075,7 @@ export class TilesRendererBase {
10751075
type: 'load-model',
10761076
scene: tile.cached.scene,
10771077
tile,
1078+
url: uri,
10781079
} );
10791080

10801081
}

src/three/plugins/images/ImageOverlayPlugin.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class ImageOverlayPlugin {
150150
this.usedTextures = new Set();
151151
this.meshParams = new WeakMap();
152152
this.pendingTiles = new Map();
153+
this.processedTiles = new Set();
153154
this.processQueue = null;
154155
this._onUpdateAfter = null;
155156
this._onTileDownloadStart = null;
@@ -284,9 +285,15 @@ export class ImageOverlayPlugin {
284285

285286
};
286287

287-
this._onTileDownloadStart = ( { tile } ) => {
288+
this._onTileDownloadStart = ( { tile, url } ) => {
288289

289-
this._initTileOverlayInfo( tile );
290+
// TODO: it would be better if there were either a separate event or flag indicating that a tile is an external
291+
// tileset or not. We won't want to run "init" on tiles that have geometry.
292+
if ( ! /\.json$/.test( url ) ) {
293+
294+
this._initTileOverlayInfo( tile );
295+
296+
}
290297

291298
};
292299

@@ -303,7 +310,9 @@ export class ImageOverlayPlugin {
303310

304311
disposeTile( tile ) {
305312

306-
const { overlayInfo, tileControllers, processQueue, pendingTiles } = this;
313+
const { overlayInfo, tileControllers, processQueue, pendingTiles, processedTiles } = this;
314+
315+
processedTiles.delete( tile );
307316

308317
// Cancel any ongoing tasks. If a tile is cancelled while downloading
309318
// this will not have been created, yet.
@@ -401,25 +410,30 @@ export class ImageOverlayPlugin {
401410

402411
async _processTileModel( scene, tile, initialization = false ) {
403412

404-
this.tileControllers.set( tile, new AbortController() );
413+
const { tileControllers, processedTiles, pendingTiles } = this;
414+
415+
tileControllers.set( tile, new AbortController() );
405416

406417
if ( ! initialization ) {
407418

408419
// we save all these pending tiles so that they can be correctly initialized if an
409420
// overlay is added in the time between when this function starts and after the async
410421
// await call. Otherwise the tile could be missed. But if we're initializing the plugin
411422
// then we don't need to do this because the tiles are already included in the traversal.
412-
this.pendingTiles.set( tile, scene );
423+
pendingTiles.set( tile, scene );
413424

414425
}
415426

427+
// track which tiles we have been processed and remove them in "disposeTile"
428+
processedTiles.add( tile );
429+
416430
this._wrapMaterials( scene );
417431
this._initTileOverlayInfo( tile );
418432
await this._initTileSceneOverlayInfo( scene, tile );
419433
this.expandVirtualChildren( scene, tile );
420434
this._updateLayers( tile );
421435

422-
this.pendingTiles.delete( tile );
436+
pendingTiles.delete( tile );
423437

424438
}
425439

@@ -887,13 +901,23 @@ export class ImageOverlayPlugin {
887901

888902
deleteOverlay( overlay ) {
889903

890-
const { overlays, overlayInfo, processQueue } = this;
904+
const { overlays, overlayInfo, processQueue, processedTiles } = this;
891905
const index = overlays.indexOf( overlay );
892906
if ( index !== - 1 ) {
893907

894908
// delete tile info explicitly instead of blindly dispose of the full overlay
895909
const { tileInfo, controller } = overlayInfo.get( overlay );
896-
tileInfo.forEach( ( { meshInfo, range, meshRange, level, target, meshRangeMarked, rangeMarked }, tile ) => {
910+
processedTiles.forEach( tile => {
911+
912+
const {
913+
meshInfo,
914+
range,
915+
meshRange,
916+
level,
917+
target,
918+
meshRangeMarked,
919+
rangeMarked,
920+
} = tileInfo.get( tile );
897921

898922
// release the ranges
899923
if ( meshRange !== null && meshRangeMarked ) {

src/three/renderer/tiles/TilesRenderer.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export interface TilesRendererEventMap {
1212
'load-tile-set': { tileset: object, /* @deprecated Use tileset instead */ tileSet?: object, url: string };
1313
'tiles-load-start': {};
1414
'tiles-load-end': {};
15-
'tile-download-start': { tile: Tile };
15+
'tile-download-start': { tile: Tile, url: string };
1616
'load-content': {};
17-
'load-model': { scene: Object3D; tile: Tile };
17+
'load-model': { scene: Object3D; tile: Tile, url: string };
1818
'dispose-model': { scene: Object3D; tile: Tile };
1919
'tile-visibility-change': { scene: Object3D; tile: Tile; visible: boolean };
2020
'update-before': {};

0 commit comments

Comments
 (0)