Skip to content

Commit

Permalink
Add fadeRootTiles option
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Dec 31, 2023
1 parent eb2e12d commit 2adf62c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion example/fadingTiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let groundTiles, skyTiles, tilesParent;
const params = {

reinstantiateTiles,
fadeRootTiles: false,
useFade: true,
errorTarget: 12,
fadeDuration: 0.5,
Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -101,6 +103,8 @@ function reinstantiateTiles() {
groundTiles.lruCache.maxSize = 1300;
groundTiles.errorTarget = 12;

window.TILES = groundTiles

Check failure on line 106 in example/fadingTiles.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

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;
Expand All @@ -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();
Expand Down
17 changes: 16 additions & 1 deletion example/src/FadeTilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

}

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

Expand Down
1 change: 0 additions & 1 deletion src/base/traverseFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ export function markUsedSetLeaves( tile, renderer ) {
tile.__childrenWereVisible = childrenWereVisible;
tile.__allChildrenLoaded = allChildrenLoaded;


}

}
Expand Down

0 comments on commit 2adf62c

Please sign in to comment.