Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move event dispatch location for more consistent state #942

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading