From 2adf62cdd64e7a180b3f53052a0b78d8960f10a1 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sun, 31 Dec 2023 21:36:10 +0900 Subject: [PATCH] Add fadeRootTiles option --- example/fadingTiles.js | 7 ++++++- example/src/FadeTilesRenderer.js | 17 ++++++++++++++++- src/base/traverseFunctions.js | 1 - 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/example/fadingTiles.js b/example/fadingTiles.js index 6c4c6a5f2..fd0e01194 100644 --- a/example/fadingTiles.js +++ b/example/fadingTiles.js @@ -18,6 +18,7 @@ let groundTiles, skyTiles, tilesParent; const params = { reinstantiateTiles, + fadeRootTiles: false, useFade: true, errorTarget: 12, fadeDuration: 0.5, @@ -73,6 +74,7 @@ function init() { const gui = new GUI(); gui.add( params, 'useFade' ); + gui.add( params, 'fadeRootTiles' ); gui.add( params, 'errorTarget', 0, 1000 ); gui.add( params, 'fadeDuration', 0, 5 ); gui.add( params, 'renderScale', 0.1, 1.0, 0.05 ).onChange( v => renderer.setPixelRatio( v * window.devicePixelRatio ) ); @@ -101,6 +103,8 @@ function reinstantiateTiles() { groundTiles.lruCache.maxSize = 1300; groundTiles.errorTarget = 12; + window.TILES = groundTiles + skyTiles = new FadeTilesRenderer( 'https://raw.githubusercontent.com/NASA-AMMOS/3DTilesSampleData/master/msl-dingo-gap/0528_0260184_to_s64o256_colorize/0528_0260184_to_s64o256_sky/0528_0260184_to_s64o256_sky_tileset.json' ); skyTiles.fetchOptions.mode = 'cors'; skyTiles.lruCache = groundTiles.lruCache; @@ -124,11 +128,12 @@ function render() { camera.updateMatrixWorld(); groundTiles.errorTarget = params.errorTarget; - + groundTiles.fadeRootTiles = params.fadeRootTiles; groundTiles.setCamera( camera ); groundTiles.setResolutionFromRenderer( camera, renderer ); groundTiles.update(); + skyTiles.fadeRootTiles = params.fadeRootTiles; skyTiles.setCamera( camera ); skyTiles.setResolutionFromRenderer( camera, renderer ); skyTiles.update(); diff --git a/example/src/FadeTilesRenderer.js b/example/src/FadeTilesRenderer.js index 7126fbedb..0cd8ace9f 100644 --- a/example/src/FadeTilesRenderer.js +++ b/example/src/FadeTilesRenderer.js @@ -21,7 +21,20 @@ function onTileVisibilityChange( scene, tile, visible ) { } else { - this._fadeManager.fadeIn( scene ); + // if this is a root tile and we haven't rendered any child tiles yet then pop in + // the root tiles immediately rather than fading from nothing + const isRootTile = tile.__depthFromRenderedParent === 0; + if ( ! isRootTile ) { + + this.initialLayerRendered = true; + + } + + if ( ! isRootTile || ! this.fadeRootTiles || this.initialLayerRendered ) { + + this._fadeManager.fadeIn( scene ); + + } } @@ -96,6 +109,7 @@ export const FadeTilesRendererMixin = base => class extends base { super( ...args ); this.maximumFadeOutTiles = 50; + this.fadeRootTiles = false; const fadeGroup = new Group(); const fadeManager = new FadeManager(); @@ -108,6 +122,7 @@ export const FadeTilesRendererMixin = base => class extends base { this.onLoadModel = onLoadModel.bind( this ); this.onTileVisibilityChange = onTileVisibilityChange.bind( this ); + this.initialLayerRendered = false; this.prevCameraTransforms = new Map(); this.disposeSet = new Set(); diff --git a/src/base/traverseFunctions.js b/src/base/traverseFunctions.js index 97ba16f65..281f3c088 100644 --- a/src/base/traverseFunctions.js +++ b/src/base/traverseFunctions.js @@ -256,7 +256,6 @@ export function markUsedSetLeaves( tile, renderer ) { tile.__childrenWereVisible = childrenWereVisible; tile.__allChildrenLoaded = allChildrenLoaded; - } }