Skip to content

Commit c313921

Browse files
authored
Provide option for immediately process children (#1470)
* Simplify child processing logic * Limit number of children processed per frame * Fix traversal * Update option * Add comments * maxProcessedTiles -> maxTilesProcessed * Add comment
1 parent 87dbf59 commit c313921

9 files changed

Lines changed: 41 additions & 28 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ autoDisableRendererCulling = true : Boolean
426426
427427
If true then all tile meshes automatically have their [frustumCulled](https://threejs.org/docs/index.html#api/en/core/Object3D.frustumCulled) field set to false. This is useful particularly when using one camera because the tiles renderer automatically performs it's own frustum culling on visible tiles. If [displayActiveTiles](#displayActiveTiles) is true or multiple cameras are being used then you may consider setting this to false.
428428
429+
### .maxProcessedTiles
430+
431+
```js
432+
maxProcessedTiles = 250 : Number
433+
```
434+
435+
The number of tiles to process up to immediately when traversing the tile set to determine what to render. Lower numbers prevent frame hiccups caused by processing too many tiles at once when a new tile set is available while higher values will process tiles more tiles immediately allowing data to be downloaded and data to be displayed sooner.
436+
429437
### .lruCache
430438
431439
```js

src/core/plugins/ImplicitTilingPlugin.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export class ImplicitTilingPlugin {
8888

8989
} );
9090
tile.children.length = 0;
91-
tile.internal.childrenProcessed = 0;
9291

9392
}
9493

src/core/renderer/tiles/Tile.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export interface TileInternalData {
99
hasUnrenderableContent: boolean;
1010
loadingState: number;
1111
basePath: string;
12-
childrenProcessed: number;
1312
depth: number;
1413
depthFromRenderedParent: number;
1514
}

src/core/renderer/tiles/TilesRendererBase.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class TilesRendererBase {
1414
maxDepth : number;
1515
loadSiblings : boolean;
1616
optimizedLoadStrategy : boolean;
17+
maxTilesProcessed : number;
1718

1819
loadProgress: number;
1920

src/core/renderer/tiles/TilesRendererBase.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ export class TilesRendererBase {
255255
used: 0,
256256
active: 0,
257257
visible: 0,
258+
259+
tilesProcessed: 0,
258260
};
259261
this.frameCount = 0;
260262

@@ -272,6 +274,7 @@ export class TilesRendererBase {
272274
this.maxDepth = Infinity;
273275
this.optimizedLoadStrategy = false;
274276
this.loadSiblings = true;
277+
this.maxTilesProcessed = 250;
275278

276279
}
277280

@@ -515,6 +518,7 @@ export class TilesRendererBase {
515518
stats.used = 0;
516519
stats.active = 0;
517520
stats.visible = 0;
521+
stats.tilesProcessed = 0;
518522
this.frameCount ++;
519523

520524
usedSet.forEach( tile => lruCache.markUnused( tile ) );
@@ -767,6 +771,7 @@ export class TilesRendererBase {
767771
preprocessNode( tile, tilesetDir, parentTile = null ) {
768772

769773
this.processedTiles.add( tile );
774+
this.stats.tilesProcessed ++;
770775

771776
if ( tile.content ) {
772777

@@ -805,7 +810,6 @@ export class TilesRendererBase {
805810
hasUnrenderableContent: false,
806811
loadingState: UNLOADED,
807812
basePath: tilesetDir,
808-
childrenProcessed: 0,
809813
depth: - 1,
810814
depthFromRenderedParent: - 1,
811815
};
@@ -830,7 +834,6 @@ export class TilesRendererBase {
830834
// Increment parent's children processed counter
831835
if ( parentTile ) {
832836

833-
parentTile.internal.childrenProcessed ++;
834837
tile.internal.depth = parentTile.internal.depth + 1;
835838
tile.internal.depthFromRenderedParent = parentTile.internal.depthFromRenderedParent + ( tile.internal.hasRenderableContent ? 1 : 0 );
836839

@@ -977,47 +980,49 @@ export class TilesRendererBase {
977980

978981
}
979982

980-
ensureChildrenArePreprocessed( tile, immediate = false ) {
983+
ensureChildrenArePreprocessed( tile, forceImmediate = this.stats.tilesProcessed < this.maxTilesProcessed ) {
981984

982985
const children = tile.children;
983-
if ( tile.internal.childrenProcessed === children.length ) {
986+
if ( children.length === 0 || children[ 0 ].internal ) {
984987

985988
return;
986989

987990
}
988991

989-
for ( let i = 0, l = children.length; i < l; i ++ ) {
992+
const processChildren = children => {
990993

991-
const child = children[ i ];
992-
if ( 'traversal' in child ) {
994+
for ( let i = 0, l = children.length; i < l; i ++ ) {
993995

994-
// the child has already been processed
995-
continue;
996+
this.preprocessNode( children[ i ], tile.internal.basePath, tile );
996997

997-
} else if ( immediate ) {
998998

999-
// process the node immediately and make sure we don't double process it
1000-
this.processNodeQueue.remove( child );
1001-
this.preprocessNode( child, tile.internal.basePath, tile );
999+
}
10021000

1003-
} else {
1001+
};
10041002

1005-
// queue the node for processing if it hasn't been already
1006-
if ( ! this.processNodeQueue.has( child ) ) {
1003+
// process children immediately up to a max number of tiles during traversal
1004+
if ( forceImmediate ) {
10071005

1008-
this.processNodeQueue.add( child, child => {
1006+
this.processNodeQueue.remove( tile );
1007+
processChildren( children );
10091008

1010-
this.preprocessNode( child, tile.internal.basePath, tile );
1011-
this._dispatchNeedsUpdateEvent();
1009+
} else {
10121010

1013-
} );
10141011

1015-
}
1012+
if ( ! this.processNodeQueue.has( tile ) ) {
1013+
1014+
this.processNodeQueue.add( tile, tile => {
1015+
1016+
processChildren( tile.children );
1017+
this._dispatchNeedsUpdateEvent();
1018+
1019+
} );
10161020

10171021
}
10181022

10191023
}
10201024

1025+
10211026
}
10221027

10231028
// returns the total bytes used for by the given tile as reported by all plugins
@@ -1185,7 +1190,6 @@ export class TilesRendererBase {
11851190
if ( isExternalTileset ) {
11861191

11871192
t.children.length = 0;
1188-
t.internal.childrenProcessed = 0;
11891193

11901194
} else {
11911195

src/core/renderer/tiles/optimizedTraverseFunctions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ function isProcessed( tile ) {
2828
// Checks whether all children have been processed and are ready to traverse
2929
function areChildrenProcessed( tile ) {
3030

31-
return tile.internal.childrenProcessed === tile.children.length && ( ! tile.internal.hasUnrenderableContent || isDownloadFinished( tile.internal.loadingState ) );
31+
// all children are processed at once
32+
const childrenReady = tile.children.length === 0 || Boolean( tile.children[ 0 ].internal );
33+
const contentReady = ! tile.internal.hasUnrenderableContent || isDownloadFinished( tile.internal.loadingState );
34+
return childrenReady && contentReady;
3235

3336
}
3437

src/core/renderer/tiles/traverseFunctions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function isProcessed( tile ) {
3333

3434
function areChildrenProcessed( tile ) {
3535

36-
return tile.internal.childrenProcessed === tile.children.length;
36+
// all children are processed at once
37+
return tile.children.length === 0 || Boolean( tile.children[ 0 ].internal );
3738

3839
}
3940

src/three/plugins/QuantizedMeshPlugin.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ export class QuantizedMeshPlugin {
457457

458458
} );
459459
tile.children.length = 0;
460-
tile.internal.childrenProcessed = 0;
461460

462461
}
463462

src/three/plugins/images/ImageOverlayPlugin.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ export class ImageOverlayPlugin {
446446
} );
447447

448448
parent.children.length = 0;
449-
parent.internal.childrenProcessed = 0;
450449

451450
}
452451

0 commit comments

Comments
 (0)