Skip to content

Commit

Permalink
Move event dispatch location for more consistent state (#942)
Browse files Browse the repository at this point in the history
* Move some events to the base class

* Fix
  • Loading branch information
gkjohnson authored Jan 23, 2025
1 parent 1c5f3e2 commit 28445f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
20 changes: 20 additions & 0 deletions src/base/TilesRendererBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,13 @@ export class TilesRendererBase {

}

// check if this is the beginning of a new set of tiles to load and dispatch and event
if ( stats.parsing === 0 && stats.downloading === 0 ) {

this.dispatchEvent( { type: 'tiles-load-start' } );

}

this.cachedSinceLoadComplete.add( tile );
stats.inCacheSinceLoad ++;
stats.inCache ++;
Expand Down Expand Up @@ -803,6 +810,17 @@ export class TilesRendererBase {

}

// dispatch an event indicating that this model has completed
if ( tile.cached.scene ) {

this.dispatchEvent( {
type: 'load-model',
scene: tile.cached.scene,
tile,
} );

}

} )
.catch( error => {

Expand Down Expand Up @@ -856,6 +874,8 @@ export class TilesRendererBase {
this.cachedSinceLoadComplete.clear();
stats.inCacheSinceLoad = 0;

this.dispatchEvent( { type: 'tiles-load-end' } );

}

} );
Expand Down
27 changes: 0 additions & 27 deletions src/three/TilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ export class TilesRenderer extends TilesRendererBase {
// flag indicating whether frustum culling should be disabled
this._autoDisableRendererCulling = true;

// flag indicating whether tiles are actively loading so events can be fired
this._loadingTiles = false;

const manager = new LoadingManager();
manager.setURLModifier( url => {

Expand Down Expand Up @@ -686,15 +683,6 @@ export class TilesRenderer extends TilesRendererBase {

}

// check if this is the beginning of a new set of tiles to load and dispatch and event
const stats = this.stats;
if ( this._loadingTiles === false && stats.parsing + stats.downloading > 0 ) {

this.dispatchEvent( { type: 'tiles-load-start' } );
this._loadingTiles = true;

}

// wait for the tile to load
const result = await promise;

Expand Down Expand Up @@ -794,21 +782,6 @@ export class TilesRenderer extends TilesRendererBase {
cached.metadata = metadata;
cached.bytesUsed = estimateBytesUsed( scene );

// dispatch an event indicating that this model has completed
this.dispatchEvent( {
type: 'load-model',
scene,
tile,
} );

// dispatch an "end" event if all tiles have finished loading
if ( this._loadingTiles === true && stats.parsing + stats.downloading === 1 ) {

this.dispatchEvent( { type: 'tiles-load-end' } );
this._loadingTiles = false;

}

}

disposeTile( tile ) {
Expand Down

0 comments on commit 28445f5

Please sign in to comment.