From 1ece9c3caec70fc33f26c0926e1ab31e6bcb73a5 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 16:05:11 +0900 Subject: [PATCH 1/9] Progress fade --- src/plugins/three/fade/FadeManager.js | 27 ++++++++++++- src/plugins/three/fade/TilesFadePlugin.js | 46 +++++++++++++++++++---- 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/plugins/three/fade/FadeManager.js b/src/plugins/three/fade/FadeManager.js index 778d5296a..def0854b0 100644 --- a/src/plugins/three/fade/FadeManager.js +++ b/src/plugins/three/fade/FadeManager.js @@ -186,6 +186,8 @@ export class FadeManager { const fadeState = this._fadeState; if ( ! fadeState.has( object ) ) return; + const visible = fadeState.get( object ).fadeOutTarget === 0; + fadeState.delete( object ); object.traverse( child => { @@ -204,7 +206,7 @@ export class FadeManager { if ( this.onFadeComplete ) { - this.onFadeComplete( object ); + this.onFadeComplete( object, visible ); } @@ -291,6 +293,29 @@ export class FadeManager { } + isFading( object ) { + + return this._fadeState.has( object ); + + } + + getFadingOutTileCount() { + + let tot = 0; + this._fadeState.forEach( ( state ) => { + + if ( state.fadeOutTarget === 1 ) { + + tot ++; + + } + + } ); + + return tot; + + } + // Tick the fade timer for each actively fading object update() { diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index ebb71b5d6..93e288624 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -8,6 +8,8 @@ const _fromQuat = new Quaternion(); const _toQuat = new Quaternion(); const _scale = new Vector3(); +const _blockedTiles = new Set(); + function onTileVisibilityChange( scene, tile, visible ) { // ensure the tiles are marked as visible on visibility toggle since @@ -21,6 +23,8 @@ function onTileVisibilityChange( scene, tile, visible ) { } else { + this.tiles.group.add( scene ); + // if this is a root renderable tile and this is the first time rendering in // then pop it in const isRootRenderableTile = tile.__depthFromRenderedParent === 1; @@ -59,13 +63,17 @@ function onDisposeModel( scene ) { } -function onFadeComplete( object ) { +function onFadeComplete( object, visible ) { + + window.TILES = this.tiles; - // when the fade finishes ensure we dispose the tile and remove it from the fade group if ( object.parent === this._fadeGroup ) { + const tile = this._tileMap.get( object ); this._fadeGroup.remove( object ); + // this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.setTileVisible && plugin.setTileVisible( tile, false ) ); + } } @@ -213,9 +221,9 @@ export class TilesFadePlugin { options = { - maximumFadeOutTiles: 50, + maximumFadeOutTiles: Infinity, fadeRootTiles: false, - fadeDuration: 250, + fadeDuration: 1000, ...options, }; @@ -277,7 +285,6 @@ export class TilesFadePlugin { this._onLoadModel = e => onLoadModel.call( this, e.scene, e.tile ); this._onDisposeModel = e => onDisposeModel.call( this, e.scene ); - this._onTileVisibilityChange = e => onTileVisibilityChange.call( this, e.scene, e.tile, e.visible ); this._onAddCamera = e => onAddCamera.call( this, e.camera ); this._onDeleteCamera = e => onDeleteCamera.call( this, e.camera ); this._onUpdateBefore = () => onUpdateBefore.call( this ); @@ -285,7 +292,6 @@ export class TilesFadePlugin { tiles.addEventListener( 'load-model', this._onLoadModel ); tiles.addEventListener( 'dispose-model', this._onDisposeModel ); - tiles.addEventListener( 'tile-visibility-change', this._onTileVisibilityChange ); tiles.addEventListener( 'add-camera', this._onAddCamera ); tiles.addEventListener( 'delete-camera', this._onDeleteCamera ); tiles.addEventListener( 'update-before', this._onUpdateBefore ); @@ -293,12 +299,38 @@ export class TilesFadePlugin { } + setTileVisible( tile, visible ) { + + const scene = tile.cached.scene; + const wasFading = this._fadeManager.isFading( scene ); + onTileVisibilityChange.call( this, scene, tile, visible ); + + return false; + + const isFading = this._fadeManager.isFading( scene ); + if ( ! visible && isFading ) { + + // cancel the visibility change trigger because we're fading and + // will call this after fade completes. + return true; + + } + + if ( visible && wasFading ) { + + return true; + + } + + return false; + + } + dispose() { const tiles = this.tiles; tiles.removeEventListener( 'load-model', this._onLoadModel ); tiles.removeEventListener( 'dispose-model', this._onDisposeModel ); - tiles.removeEventListener( 'tile-visibility-change', this._onTileVisibilityChange ); tiles.removeEventListener( 'add-camera', this._onAddCamera ); tiles.removeEventListener( 'delete-camera', this._onDeleteCamera ); tiles.removeEventListener( 'update-before', this._onUpdateBefore ); From 7b335e4c3025f862a18a485f15ff272e511d8c51 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 17:04:54 +0900 Subject: [PATCH 2/9] Fix fade manager --- src/plugins/three/fade/FadeManager.js | 7 ++++ src/plugins/three/fade/TilesFadePlugin.js | 42 +++++++++++++++-------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/plugins/three/fade/FadeManager.js b/src/plugins/three/fade/FadeManager.js index def0854b0..6dc48538b 100644 --- a/src/plugins/three/fade/FadeManager.js +++ b/src/plugins/three/fade/FadeManager.js @@ -299,6 +299,13 @@ export class FadeManager { } + isFadingOut( object ) { + + const state = this._fadeState.get( object ); + return state && state.fadeOutTarget === 1; + + } + getFadingOutTileCount() { let tot = 0; diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index 93e288624..841c40557 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -8,8 +8,6 @@ const _fromQuat = new Quaternion(); const _toQuat = new Quaternion(); const _scale = new Vector3(); -const _blockedTiles = new Set(); - function onTileVisibilityChange( scene, tile, visible ) { // ensure the tiles are marked as visible on visibility toggle since @@ -65,14 +63,12 @@ function onDisposeModel( scene ) { function onFadeComplete( object, visible ) { - window.TILES = this.tiles; - - if ( object.parent === this._fadeGroup ) { + if ( ! visible ) { const tile = this._tileMap.get( object ); this._fadeGroup.remove( object ); - // this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.setTileVisible && plugin.setTileVisible( tile, false ) ); + this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.setTileVisible && plugin.setTileVisible( tile, false ) ); } @@ -139,7 +135,18 @@ function onUpdateAfter() { tiles.visibleTiles.forEach( t => { - t.cached.scene.visible = t.__inFrustum; + // if a tile is fading out then it may not be traversed and thus will not have + // the frustum flag set correctly. + const scene = t.cached.scene; + if ( fadeManager.isFadingOut( scene ) ) { + + scene.visible = true; + + } else { + + scene.visible = t.__inFrustum; + + } } ); @@ -229,6 +236,7 @@ export class TilesFadePlugin { }; this.name = 'FADE_TILES_PLUGIN'; + this.priority = - 1; this.tiles = null; this._fadeManager = new FadeManager(); @@ -244,6 +252,9 @@ export class TilesFadePlugin { init( tiles ) { + tiles.lruCache.minSize = 0; + tiles.lruCache.minBytesSize = 0; + const fadeGroup = new Group(); fadeGroup.name = 'TilesFadeGroup'; tiles.group.add( fadeGroup ); @@ -305,18 +316,18 @@ export class TilesFadePlugin { const wasFading = this._fadeManager.isFading( scene ); onTileVisibilityChange.call( this, scene, tile, visible ); - return false; + // if a tile was already fading then it's already marked as visible and in the scene + if ( wasFading ) { - const isFading = this._fadeManager.isFading( scene ); - if ( ! visible && isFading ) { - - // cancel the visibility change trigger because we're fading and - // will call this after fade completes. return true; } - if ( visible && wasFading ) { + + // cancel the visibility change trigger because we're fading and will call this after + // fade completes. + const isFading = this._fadeManager.isFading( scene ); + if ( ! visible && isFading ) { return true; @@ -329,6 +340,9 @@ export class TilesFadePlugin { dispose() { const tiles = this.tiles; + + this._fadeManager.completeAllFades(); + tiles.removeEventListener( 'load-model', this._onLoadModel ); tiles.removeEventListener( 'dispose-model', this._onDisposeModel ); tiles.removeEventListener( 'add-camera', this._onAddCamera ); From 1919082fc19dd0b244945ce413ee4e05acbe9829 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 17:08:00 +0900 Subject: [PATCH 3/9] Remove fade group --- src/plugins/three/fade/TilesFadePlugin.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index 841c40557..d2c86813a 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -16,13 +16,10 @@ function onTileVisibilityChange( scene, tile, visible ) { if ( ! visible ) { - this._fadeGroup.add( scene ); this._fadeManager.fadeOut( scene ); } else { - this.tiles.group.add( scene ); - // if this is a root renderable tile and this is the first time rendering in // then pop it in const isRootRenderableTile = tile.__depthFromRenderedParent === 1; @@ -66,8 +63,6 @@ function onFadeComplete( object, visible ) { if ( ! visible ) { const tile = this._tileMap.get( object ); - this._fadeGroup.remove( object ); - this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.setTileVisible && plugin.setTileVisible( tile, false ) ); } @@ -105,7 +100,6 @@ function onUpdateBefore() { function onUpdateAfter() { const fadeManager = this._fadeManager; - const fadeGroup = this._fadeGroup; const displayActiveTiles = this._displayActiveTiles; const fadingBefore = this._fadingBefore; const tiles = this.tiles; @@ -152,7 +146,7 @@ function onUpdateAfter() { } - if ( this.maximumFadeOutTiles < fadeGroup.children.length ) { + if ( this.maximumFadeOutTiles < this._fadeManager.getFadingOutTileCount() ) { // determine whether all the rendering cameras are moving // quickly so we can adjust how tiles fade accordingly @@ -228,9 +222,9 @@ export class TilesFadePlugin { options = { - maximumFadeOutTiles: Infinity, + maximumFadeOutTiles: 50, fadeRootTiles: false, - fadeDuration: 1000, + fadeDuration: 250, ...options, }; @@ -241,7 +235,6 @@ export class TilesFadePlugin { this.tiles = null; this._fadeManager = new FadeManager(); this._prevCameraTransforms = null; - this._fadeGroup = null; this._tileMap = null; this.maximumFadeOutTiles = options.maximumFadeOutTiles; @@ -255,10 +248,6 @@ export class TilesFadePlugin { tiles.lruCache.minSize = 0; tiles.lruCache.minBytesSize = 0; - const fadeGroup = new Group(); - fadeGroup.name = 'TilesFadeGroup'; - tiles.group.add( fadeGroup ); - const fadeManager = this._fadeManager; fadeManager.onFadeSetStart = () => { @@ -278,7 +267,6 @@ export class TilesFadePlugin { this.tiles = tiles; this._fadeManager = fadeManager; - this._fadeGroup = fadeGroup; this._tileMap = new Map(); this._prevCameraTransforms = new Map(); @@ -357,8 +345,6 @@ export class TilesFadePlugin { } ); - this._fadeGroup.removeFromParent(); - } } From 3b6b68a5470db44a4f5d800a737326d8cceeb7c1 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 17:10:57 +0900 Subject: [PATCH 4/9] Add unload to demo --- example/googleMapsExample.js | 2 ++ example/src/plugins/UnloadTilesPlugin.js | 2 +- src/plugins/three/fade/TilesFadePlugin.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/googleMapsExample.js b/example/googleMapsExample.js index 6bd66f871..3c9ae4ac0 100644 --- a/example/googleMapsExample.js +++ b/example/googleMapsExample.js @@ -24,6 +24,7 @@ import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'; import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js'; import Stats from 'three/examples/jsm/libs/stats.module.js'; import { BatchedTilesPlugin } from './src/plugins/batched/BatchedTilesPlugin.js'; +import { UnloadTilesPlugin } from './src/plugins/UnloadTilesPlugin.js'; let controls, scene, renderer, tiles, transition; let statsContainer, stats; @@ -63,6 +64,7 @@ function reinstantiateTiles() { tiles.registerPlugin( new GoogleCloudAuthPlugin( { apiToken: params.apiKey, autoRefreshToken: true } ) ); tiles.registerPlugin( new TileCompressionPlugin() ); tiles.registerPlugin( new UpdateOnChangePlugin() ); + tiles.registerPlugin( new UnloadTilesPlugin() ); if ( params.useBatchedMesh ) { diff --git a/example/src/plugins/UnloadTilesPlugin.js b/example/src/plugins/UnloadTilesPlugin.js index 3abb56e84..a8fbfe478 100644 --- a/example/src/plugins/UnloadTilesPlugin.js +++ b/example/src/plugins/UnloadTilesPlugin.js @@ -36,7 +36,7 @@ export class UnloadTilesPlugin { } - constructor( options ) { + constructor( options = {} ) { const { delay = 0, diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index d2c86813a..dfacf66f6 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -1,4 +1,4 @@ -import { Group, Matrix4, Vector3, Quaternion } from 'three'; +import { Matrix4, Vector3, Quaternion } from 'three'; import { FadeManager } from './FadeManager.js'; const HAS_POPPED_IN = Symbol( 'HAS_POPPED_IN' ); From 2c8b2871d578771e0471ff0d612a3465aa4b8387 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 17:14:08 +0900 Subject: [PATCH 5/9] Move plugin to plugin exports --- example/googleMapsExample.js | 2 +- src/plugins/index.d.ts | 1 + src/plugins/index.js | 1 + src/plugins/three/UnloadTilesPlugin.d.ts | 8 ++++++++ .../plugins => src/plugins/three}/UnloadTilesPlugin.js | 0 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/plugins/three/UnloadTilesPlugin.d.ts rename {example/src/plugins => src/plugins/three}/UnloadTilesPlugin.js (100%) diff --git a/example/googleMapsExample.js b/example/googleMapsExample.js index 3c9ae4ac0..3096a732b 100644 --- a/example/googleMapsExample.js +++ b/example/googleMapsExample.js @@ -11,6 +11,7 @@ import { TilesFadePlugin, UpdateOnChangePlugin, TileCompressionPlugin, + UnloadTilesPlugin, } from '3d-tiles-renderer/plugins'; import { Scene, @@ -24,7 +25,6 @@ import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'; import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js'; import Stats from 'three/examples/jsm/libs/stats.module.js'; import { BatchedTilesPlugin } from './src/plugins/batched/BatchedTilesPlugin.js'; -import { UnloadTilesPlugin } from './src/plugins/UnloadTilesPlugin.js'; let controls, scene, renderer, tiles, transition; let statsContainer, stats; diff --git a/src/plugins/index.d.ts b/src/plugins/index.d.ts index d40cabcce..f063fc29d 100644 --- a/src/plugins/index.d.ts +++ b/src/plugins/index.d.ts @@ -6,6 +6,7 @@ export { TileCompressionPlugin } from './three/TileCompressionPlugin'; export { GLTFExtensionsPlugin } from './three/GLTFExtensionsPlugin'; export { ReorientationPlugin } from './three/ReorientationPlugin'; export { TilesFadePlugin } from './three/fade/TilesFadePlugin'; +export { UnloadTilesPlugin } from './three/fade/UnloadTilesPlugin'; export * from './three/DebugTilesPlugin'; // common plugins diff --git a/src/plugins/index.js b/src/plugins/index.js index 2cffdad59..4a0daf036 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -6,6 +6,7 @@ export { TileCompressionPlugin } from './three/TileCompressionPlugin.js'; export { GLTFExtensionsPlugin } from './three/GLTFExtensionsPlugin.js'; export { ReorientationPlugin } from './three/ReorientationPlugin.js'; export { TilesFadePlugin } from './three/fade/TilesFadePlugin.js'; +export { UnloadTilesPlugin } from './three/fade/UnloadTilesPlugin.js'; export * from './three/DebugTilesPlugin.js'; // common plugins diff --git a/src/plugins/three/UnloadTilesPlugin.d.ts b/src/plugins/three/UnloadTilesPlugin.d.ts new file mode 100644 index 000000000..5d4ec4524 --- /dev/null +++ b/src/plugins/three/UnloadTilesPlugin.d.ts @@ -0,0 +1,8 @@ +export class UnloadTilesPlugin { + + constructor( options: { + delay: number, + bytesTarget: number, + } ); + +} diff --git a/example/src/plugins/UnloadTilesPlugin.js b/src/plugins/three/UnloadTilesPlugin.js similarity index 100% rename from example/src/plugins/UnloadTilesPlugin.js rename to src/plugins/three/UnloadTilesPlugin.js From 9fdefab43e40997142224d91796688997bd99bfa Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 17:15:33 +0900 Subject: [PATCH 6/9] Update README --- src/plugins/README.md | 64 ++++++++++++++++++++---------------------- src/plugins/index.d.ts | 2 +- src/plugins/index.js | 2 +- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/plugins/README.md b/src/plugins/README.md index 4c5ec6a13..e8c21753c 100644 --- a/src/plugins/README.md +++ b/src/plugins/README.md @@ -539,6 +539,37 @@ transformLatLonHeightToOrigin( lat, lon, height = 0 ) : void Transforms the centers the tile set such that the given coordinates and height are positioned at the origin with "X" facing west and "Z" facing north. +## UnloadTilesPlugin + +Plugin that unloads geometry, textures, and materials of any given tile when the visibility changes to non-visible to save GPU memory. The model still exists on the CPU until it is completely removed from the cache. + +### .estimatedGpuBytes + +```js +estimatedGPUBytes : number +``` + +The number of bytes that are actually uploaded to the GPU for rendering compared to `lruCache.cachedBytes` which reports the amount of texture and geometry buffer bytes actually downloaded. + +### .constructor + +```js +constructor( options : Object ) +``` + +Available options are as follows: + +```js +{ + // The amount of time to wait in milliseconds before unloading tile content from the GPU. This option can be + // used to account for cases where the user is moving the camera and tiles are coming in and out of frame. + delay: 0, + + // The amount of bytes to unload to. + bytesTarget: 0, +} +``` + ## BatchedTilesPlugin _available in the examples directory_ @@ -581,36 +612,3 @@ Available options are as follows: discardOriginalContent: true } ``` - -## UnloadTilesPlugin - -_available in the examples directory_ - -Plugin that unloads geometry, textures, and materials of any given tile when the visibility changes to non-visible to save GPU memory. The model still exists on the CPU until it is completely removed from the cache. - -### .estimatedGpuBytes - -```js -estimatedGPUBytes : number -``` - -The number of bytes that are actually uploaded to the GPU for rendering compared to `lruCache.cachedBytes` which reports the amount of texture and geometry buffer bytes actually downloaded. - -### .constructor - -```js -constructor( options : Object ) -``` - -Available options are as follows: - -```js -{ - // The amount of time to wait in milliseconds before unloading tile content from the GPU. This option can be - // used to account for cases where the user is moving the camera and tiles are coming in and out of frame. - delay: 0, - - // The amount of bytes to unload to. - bytesTarget: 0, -} -``` diff --git a/src/plugins/index.d.ts b/src/plugins/index.d.ts index f063fc29d..fa4655004 100644 --- a/src/plugins/index.d.ts +++ b/src/plugins/index.d.ts @@ -5,8 +5,8 @@ export { UpdateOnChangePlugin } from './three/UpdateOnChangePlugin'; export { TileCompressionPlugin } from './three/TileCompressionPlugin'; export { GLTFExtensionsPlugin } from './three/GLTFExtensionsPlugin'; export { ReorientationPlugin } from './three/ReorientationPlugin'; +export { UnloadTilesPlugin } from './three/UnloadTilesPlugin'; export { TilesFadePlugin } from './three/fade/TilesFadePlugin'; -export { UnloadTilesPlugin } from './three/fade/UnloadTilesPlugin'; export * from './three/DebugTilesPlugin'; // common plugins diff --git a/src/plugins/index.js b/src/plugins/index.js index 4a0daf036..0093e67a9 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -5,8 +5,8 @@ export { UpdateOnChangePlugin } from './three/UpdateOnChangePlugin.js'; export { TileCompressionPlugin } from './three/TileCompressionPlugin.js'; export { GLTFExtensionsPlugin } from './three/GLTFExtensionsPlugin.js'; export { ReorientationPlugin } from './three/ReorientationPlugin.js'; +export { UnloadTilesPlugin } from './three/UnloadTilesPlugin.js'; export { TilesFadePlugin } from './three/fade/TilesFadePlugin.js'; -export { UnloadTilesPlugin } from './three/fade/UnloadTilesPlugin.js'; export * from './three/DebugTilesPlugin.js'; // common plugins From 334ce7a5e008875060ed69eede547b5b9d8890f5 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 17:31:27 +0900 Subject: [PATCH 7/9] Simplify fade out counting --- src/plugins/three/fade/FadeManager.js | 17 ----------------- src/plugins/three/fade/TilesFadePlugin.js | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/plugins/three/fade/FadeManager.js b/src/plugins/three/fade/FadeManager.js index 6dc48538b..50abb9d86 100644 --- a/src/plugins/three/fade/FadeManager.js +++ b/src/plugins/three/fade/FadeManager.js @@ -306,23 +306,6 @@ export class FadeManager { } - getFadingOutTileCount() { - - let tot = 0; - this._fadeState.forEach( ( state ) => { - - if ( state.fadeOutTarget === 1 ) { - - tot ++; - - } - - } ); - - return tot; - - } - // Tick the fade timer for each actively fading object update() { diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index dfacf66f6..28008c0b0 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -14,9 +14,17 @@ function onTileVisibilityChange( scene, tile, visible ) { // it's possible we disable them when adjusting visibility based on frustum scene.visible = true; + const fadeManager = this._fadeManager; + if ( fadeManager.isFadingOut( scene ) ) { + + this._fadingOutCount --; + + } + if ( ! visible ) { - this._fadeManager.fadeOut( scene ); + this._fadingOutCount ++; + fadeManager.fadeOut( scene ); } else { @@ -65,6 +73,8 @@ function onFadeComplete( object, visible ) { const tile = this._tileMap.get( object ); this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.setTileVisible && plugin.setTileVisible( tile, false ) ); + this._fadingOutCount --; + } } @@ -146,7 +156,7 @@ function onUpdateAfter() { } - if ( this.maximumFadeOutTiles < this._fadeManager.getFadingOutTileCount() ) { + if ( this.maximumFadeOutTiles < this._fadingOutCount ) { // determine whether all the rendering cameras are moving // quickly so we can adjust how tiles fade accordingly @@ -236,6 +246,7 @@ export class TilesFadePlugin { this._fadeManager = new FadeManager(); this._prevCameraTransforms = null; this._tileMap = null; + this._fadingOutCount = 0; this.maximumFadeOutTiles = options.maximumFadeOutTiles; this.fadeRootTiles = options.fadeRootTiles; From 98064cb3f7c9715256f3a5df640b0393b42dfed3 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 17:32:59 +0900 Subject: [PATCH 8/9] Remove extra lines / accidental commits --- src/plugins/three/fade/TilesFadePlugin.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index 28008c0b0..431f308a7 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -256,9 +256,6 @@ export class TilesFadePlugin { init( tiles ) { - tiles.lruCache.minSize = 0; - tiles.lruCache.minBytesSize = 0; - const fadeManager = this._fadeManager; fadeManager.onFadeSetStart = () => { @@ -322,7 +319,6 @@ export class TilesFadePlugin { } - // cancel the visibility change trigger because we're fading and will call this after // fade completes. const isFading = this._fadeManager.isFading( scene ); From d3b4582a7fa5a881288e4102bdfc7a3460b9674e Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 20 Dec 2024 18:00:46 +0900 Subject: [PATCH 9/9] Add comment --- src/plugins/three/fade/TilesFadePlugin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/three/fade/TilesFadePlugin.js b/src/plugins/three/fade/TilesFadePlugin.js index 431f308a7..6580f7219 100644 --- a/src/plugins/three/fade/TilesFadePlugin.js +++ b/src/plugins/three/fade/TilesFadePlugin.js @@ -70,6 +70,7 @@ function onFadeComplete( object, visible ) { if ( ! visible ) { + // now that the tile is hidden we can run the built-in setTileVisible function for the tile const tile = this._tileMap.get( object ); this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.setTileVisible && plugin.setTileVisible( tile, false ) );