Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TilesRenderer: Only mark previously used tiles as unused #903

Merged
merged 5 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/base/TilesRendererBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/base/traverseFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/three/UnloadTilesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class UnloadTilesPlugin {
if ( visible ) {

lruCache.add( tile, unloadCallback );
lruCache.markUsed( tile );
tiles.markTileUsed( tile );
deferCallbacks.cancel( tile );

} else {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/three/fade/TilesFadePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/three/TilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {

Expand Down
35 changes: 3 additions & 32 deletions src/utilities/LRUCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -78,12 +77,6 @@ class LRUCache {

add( item, removeCb ) {

if ( this.markUnusedQueued ) {

this.markAllUnused();

}

const itemSet = this.itemSet;
if ( itemSet.has( item ) ) {

Expand Down Expand Up @@ -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 ) ) {
Expand All @@ -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;

}

}

Expand Down Expand Up @@ -383,6 +358,8 @@ class LRUCache {

scheduleUnload() {

cancelAnimationFrame( this.unloadingHandle );

if ( ! this.scheduled ) {

this.scheduled = true;
Expand All @@ -391,12 +368,6 @@ class LRUCache {
this.scheduled = false;
this.unloadUnusedContent();

if ( this.autoMarkUnused ) {

this.markUnusedQueued = true;

}

} );

}
Expand Down
Loading