diff --git a/src/base/TilesRendererBase.js b/src/base/TilesRendererBase.js index 5ca4b3f6c..be097268e 100644 --- a/src/base/TilesRendererBase.js +++ b/src/base/TilesRendererBase.js @@ -135,6 +135,7 @@ export class TilesRendererBase { parseQueue.maxJobs = 1; parseQueue.priorityCallback = priorityCallback; + this.usedSet = new Set(); this.lruCache = lruCache; this.downloadQueue = downloadQueue; this.parseQueue = parseQueue; @@ -245,11 +246,17 @@ export class TilesRendererBase { } + markTileUsed( tile ) { + + this.usedSet.add( tile ); + this.lruCache.add( tile ); + + } + // Public API update() { - const stats = this.stats; - const lruCache = this.lruCache; + const { lruCache, usedSet, stats, root } = this; if ( this.rootLoadingState === UNLOADED ) { this.rootLoadingState = LOADING; @@ -264,20 +271,21 @@ export class TilesRendererBase { } - if ( ! this.root ) { + if ( ! root ) { return; } - const root = this.root; - stats.inFrustum = 0; stats.used = 0; stats.active = 0; stats.visible = 0; this.frameCount ++; + usedSet.forEach( tile => lruCache.markUnused( tile ) ); + usedSet.clear(); + markUsedTiles( root, this ); markUsedSetLeaves( root, this ); markVisibleTiles( root, this ); diff --git a/src/base/traverseFunctions.js b/src/base/traverseFunctions.js index 29c3ee53a..79338c13d 100644 --- a/src/base/traverseFunctions.js +++ b/src/base/traverseFunctions.js @@ -102,7 +102,7 @@ function markUsed( tile, renderer ) { } tile.__used = true; - renderer.lruCache.markUsed( tile ); + tile.markTileUsed( tile ); renderer.stats.used ++; if ( tile.__inFrustum === true ) { diff --git a/src/plugins/three/UnloadTilesPlugin.js b/src/plugins/three/UnloadTilesPlugin.js index 3060a5a34..7702f0338 100644 --- a/src/plugins/three/UnloadTilesPlugin.js +++ b/src/plugins/three/UnloadTilesPlugin.js @@ -97,7 +97,7 @@ export class UnloadTilesPlugin { if ( visible ) { lruCache.add( tile, unloadCallback ); - lruCache.markUsed( tile ); + tiles.markTileUsed( tile ); deferCallbacks.cancel( tile ); } else { diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index 05863bef7..649b7802f 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -34,7 +34,7 @@ function onUpdateAfter() { const fadingBefore = this._fadingBefore; const prevCameraTransforms = this._prevCameraTransforms; const { tiles, maximumFadeOutTiles, batchedMesh } = this; - const { lruCache, cameras } = tiles; + const { cameras } = tiles; // reset the active tiles flag tiles.displayActiveTiles = displayActiveTiles; @@ -126,7 +126,7 @@ function onUpdateAfter() { // prevent faded tiles from being unloaded const scene = tile.cached.scene; const isFadingOut = fadeManager.isFadingOut( tile ); - lruCache.markUsed( tile ); + tiles.markTileUsed( tile ); if ( scene ) { fadeMaterialManager.setFade( scene, fadeIn, fadeOut ); diff --git a/src/three/TilesRenderer.js b/src/three/TilesRenderer.js index 6759dabaa..237e6b752 100644 --- a/src/three/TilesRenderer.js +++ b/src/three/TilesRenderer.js @@ -337,7 +337,7 @@ export class TilesRenderer extends TilesRendererBase { .then( () => { // cache the gltf tile set rotation matrix - const { asset, extensions } = this.rootTileSet; + const { asset, extensions = {} } = this.rootTileSet; const upAxis = asset && asset.gltfUpAxis || 'y'; switch ( upAxis.toLowerCase() ) { diff --git a/src/utilities/LRUCache.js b/src/utilities/LRUCache.js index 878e05233..f84e13065 100644 --- a/src/utilities/LRUCache.js +++ b/src/utilities/LRUCache.js @@ -49,7 +49,6 @@ class LRUCache { this.itemList = []; this.usedSet = new Set(); this.callbacks = new Map(); - this.markUnusedQueued = false; this.unloadingHandle = - 1; this.cachedBytes = 0; this.bytesMap = new Map(); @@ -78,12 +77,6 @@ class LRUCache { add( item, removeCb ) { - if ( this.markUnusedQueued ) { - - this.markAllUnused(); - - } - const itemSet = this.itemSet; if ( itemSet.has( item ) ) { @@ -194,12 +187,6 @@ class LRUCache { markUsed( item ) { - if ( this.markUnusedQueued ) { - - this.markAllUnused(); - - } - const itemSet = this.itemSet; const usedSet = this.usedSet; if ( itemSet.has( item ) && ! usedSet.has( item ) ) { @@ -213,25 +200,13 @@ class LRUCache { markUnused( item ) { - const usedSet = this.usedSet; - if ( usedSet.has( item ) ) { - - usedSet.delete( item ); - - } + this.usedSet.delete( item ); } markAllUnused() { this.usedSet.clear(); - this.markUnusedQueued = false; - if ( this.unloadingHandle !== - 1 ) { - - cancelAnimationFrame( this.unloadingHandle ); - this.unloadingHandle = - 1; - - } } @@ -383,6 +358,8 @@ class LRUCache { scheduleUnload() { + cancelAnimationFrame( this.unloadingHandle ); + if ( ! this.scheduled ) { this.scheduled = true; @@ -391,12 +368,6 @@ class LRUCache { this.scheduled = false; this.unloadUnusedContent(); - if ( this.autoMarkUnused ) { - - this.markUnusedQueued = true; - - } - } ); }