From ee7e3a4c7d7dddc70dd48df3b245ff86292fa64b Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Wed, 1 Jan 2025 22:06:00 +0900 Subject: [PATCH 1/5] Track individual tile items --- src/base/TilesRendererBase.js | 11 ++++++----- src/base/traverseFunctions.js | 1 + src/three/TilesRenderer.js | 2 +- src/utilities/LRUCache.js | 7 +------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/base/TilesRendererBase.js b/src/base/TilesRendererBase.js index 5ca4b3f6c..0d96a8009 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; @@ -248,8 +249,7 @@ export class TilesRendererBase { // 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 +264,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..8390c6f2a 100644 --- a/src/base/traverseFunctions.js +++ b/src/base/traverseFunctions.js @@ -103,6 +103,7 @@ function markUsed( tile, renderer ) { tile.__used = true; renderer.lruCache.markUsed( tile ); + renderer.usedSet.add( tile ); renderer.stats.used ++; if ( tile.__inFrustum === true ) { 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..8a77de0ae 100644 --- a/src/utilities/LRUCache.js +++ b/src/utilities/LRUCache.js @@ -213,12 +213,7 @@ class LRUCache { markUnused( item ) { - const usedSet = this.usedSet; - if ( usedSet.has( item ) ) { - - usedSet.delete( item ); - - } + this.usedSet.delete( item ); } From b1365c04a04030283ef870a2084e285e8e2876a0 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Wed, 1 Jan 2025 22:10:23 +0900 Subject: [PATCH 2/5] Remove automatic mark unused schedule --- src/plugins/three/UnloadTilesPlugin.js | 1 + src/plugins/three/fade/TilesFadePlugin.js | 1 + src/utilities/LRUCache.js | 20 -------------------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/plugins/three/UnloadTilesPlugin.js b/src/plugins/three/UnloadTilesPlugin.js index 3060a5a34..7aedff7e4 100644 --- a/src/plugins/three/UnloadTilesPlugin.js +++ b/src/plugins/three/UnloadTilesPlugin.js @@ -98,6 +98,7 @@ export class UnloadTilesPlugin { lruCache.add( tile, unloadCallback ); lruCache.markUsed( tile ); + tiles.usedSet.add( tile ); deferCallbacks.cancel( tile ); } else { diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index 05863bef7..4c6458e9d 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -127,6 +127,7 @@ function onUpdateAfter() { const scene = tile.cached.scene; const isFadingOut = fadeManager.isFadingOut( tile ); lruCache.markUsed( tile ); + tiles.usedSet.add( tile ); if ( scene ) { fadeMaterialManager.setFade( scene, fadeIn, fadeOut ); diff --git a/src/utilities/LRUCache.js b/src/utilities/LRUCache.js index 8a77de0ae..6a60ddd5b 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 ) ) { @@ -220,7 +207,6 @@ class LRUCache { markAllUnused() { this.usedSet.clear(); - this.markUnusedQueued = false; if ( this.unloadingHandle !== - 1 ) { cancelAnimationFrame( this.unloadingHandle ); @@ -386,12 +372,6 @@ class LRUCache { this.scheduled = false; this.unloadUnusedContent(); - if ( this.autoMarkUnused ) { - - this.markUnusedQueued = true; - - } - } ); } From 7e89606da1a04962bbfef9c0b82b5fe1526176cf Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Wed, 1 Jan 2025 22:15:29 +0900 Subject: [PATCH 3/5] Consolidate to a function --- src/base/TilesRendererBase.js | 7 +++++++ src/base/traverseFunctions.js | 3 +-- src/plugins/three/UnloadTilesPlugin.js | 3 +-- src/plugins/three/fade/TilesFadePlugin.js | 3 +-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/base/TilesRendererBase.js b/src/base/TilesRendererBase.js index 0d96a8009..be097268e 100644 --- a/src/base/TilesRendererBase.js +++ b/src/base/TilesRendererBase.js @@ -246,6 +246,13 @@ export class TilesRendererBase { } + markTileUsed( tile ) { + + this.usedSet.add( tile ); + this.lruCache.add( tile ); + + } + // Public API update() { diff --git a/src/base/traverseFunctions.js b/src/base/traverseFunctions.js index 8390c6f2a..79338c13d 100644 --- a/src/base/traverseFunctions.js +++ b/src/base/traverseFunctions.js @@ -102,8 +102,7 @@ function markUsed( tile, renderer ) { } tile.__used = true; - renderer.lruCache.markUsed( tile ); - renderer.usedSet.add( 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 7aedff7e4..7702f0338 100644 --- a/src/plugins/three/UnloadTilesPlugin.js +++ b/src/plugins/three/UnloadTilesPlugin.js @@ -97,8 +97,7 @@ export class UnloadTilesPlugin { if ( visible ) { lruCache.add( tile, unloadCallback ); - lruCache.markUsed( tile ); - tiles.usedSet.add( 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 4c6458e9d..1613aac0e 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -126,8 +126,7 @@ function onUpdateAfter() { // prevent faded tiles from being unloaded const scene = tile.cached.scene; const isFadingOut = fadeManager.isFadingOut( tile ); - lruCache.markUsed( tile ); - tiles.usedSet.add( tile ); + tiles.markTileUsed( tile ); if ( scene ) { fadeMaterialManager.setFade( scene, fadeIn, fadeOut ); From 403395b6661ddbc2494634e435a77be11fd6804c Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Wed, 1 Jan 2025 22:19:16 +0900 Subject: [PATCH 4/5] Clean up lru cache --- src/utilities/LRUCache.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/utilities/LRUCache.js b/src/utilities/LRUCache.js index 6a60ddd5b..f84e13065 100644 --- a/src/utilities/LRUCache.js +++ b/src/utilities/LRUCache.js @@ -207,12 +207,6 @@ class LRUCache { markAllUnused() { this.usedSet.clear(); - if ( this.unloadingHandle !== - 1 ) { - - cancelAnimationFrame( this.unloadingHandle ); - this.unloadingHandle = - 1; - - } } @@ -364,6 +358,8 @@ class LRUCache { scheduleUnload() { + cancelAnimationFrame( this.unloadingHandle ); + if ( ! this.scheduled ) { this.scheduled = true; From c7dc726b3b78a4c1973993156ba3f2b1c5539044 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Wed, 1 Jan 2025 22:20:39 +0900 Subject: [PATCH 5/5] Remove unused variable --- src/plugins/three/fade/TilesFadePlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index 1613aac0e..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;