Skip to content

Commit 1b190f7

Browse files
mvaligurskyMartin Valigursky
andcommitted
Add loadingCount parameter to GSplat frame:ready event (#8178)
* Add loadingCount parameter to GSplat frame:ready event * removed unused internal function --------- Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent 9b9ed0d commit 1b190f7

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

src/framework/components/gsplat/gsplat-asset-loader.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
8181
this._registry = registry;
8282
}
8383

84-
get isLoading() {
85-
return this._currentlyLoading.size > 0 || this._loadQueue.length > 0;
86-
}
87-
8884
/**
8985
* Initiates loading of a gsplat asset. This is a fire-and-forget operation that starts
9086
* the loading process. Use getResource() later to check if the asset has finished loading.

src/framework/components/gsplat/system.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,35 @@ class GSplatComponentSystem extends ComponentSystem {
6161
/**
6262
* Fired every frame for each camera and layer combination rendering GSplats in unified mode.
6363
* The handler is passed the {@link CameraComponent}, the {@link Layer}, a boolean indicating
64-
* if the current frame has up-to-date sorting, and a boolean indicating if resources are loading.
64+
* if the current frame has up-to-date sorting, and a number indicating how many resources are
65+
* loading.
6566
*
6667
* The `ready` parameter indicates whether the current frame reflects all recent changes (camera
67-
* movement, splat transforms, lod updates, etc.) with the latest sorting applied. The `loading`
68-
* parameter indicates if octree LOD resources are still being loaded.
68+
* movement, splat transforms, lod updates, etc.) with the latest sorting applied. The `loadingCount`
69+
* parameter reports the total number of octree LOD resources currently loading or queued to load.
6970
*
7071
* This event is useful for video capture or other workflows that need to wait for frames
7172
* to be fully ready. Only capture frames and move camera to next position when both
72-
* `ready === true` and `loading === false`.
73+
* `ready === true` and `loadingCount === 0`. Note that `loadingCount` can be used as a boolean
74+
* in conditionals (0 is falsy, non-zero is truthy) for backward compatibility.
7375
*
7476
* @event
7577
* @example
76-
* app.systems.gsplat.on('frame:ready', (camera, layer, ready, loading) => {
77-
* if (ready && !loading) {
78+
* // Wait for frame to be ready before capturing
79+
* app.systems.gsplat.on('frame:ready', (camera, layer, ready, loadingCount) => {
80+
* if (ready && !loadingCount) {
7881
* console.log(`Frame ready to capture for camera ${camera.entity.name}`);
7982
* // Capture frame here
8083
* }
8184
* });
85+
* @example
86+
* // Track loading progress (0..1)
87+
* let maxLoadingCount = 0;
88+
* app.systems.gsplat.on('frame:ready', (camera, layer, ready, loadingCount) => {
89+
* maxLoadingCount = Math.max(maxLoadingCount, loadingCount);
90+
* const progress = maxLoadingCount > 0 ? (maxLoadingCount - loadingCount) / maxLoadingCount : 1;
91+
* console.log(`Loading progress: ${(progress * 100).toFixed(1)}%`);
92+
* });
8293
*/
8394
static EVENT_FRAMEREADY = 'frame:ready';
8495

src/scene/gsplat-unified/gsplat-asset-loader-base.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ class GSplatAssetLoaderBase {
4343
getResource(url) {
4444
Debug.error('GSplatAssetLoaderBase#getResource: Not implemented');
4545
}
46-
47-
/**
48-
* Returns true if any resources are currently loading or queued to load.
49-
*
50-
* @type {boolean}
51-
* @abstract
52-
*/
53-
get isLoading() {
54-
Debug.error('GSplatAssetLoaderBase#isLoading: Not implemented');
55-
return false;
56-
}
5746
}
5847

5948
export { GSplatAssetLoaderBase };

src/scene/gsplat-unified/gsplat-manager.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,13 @@ class GSplatManager {
506506
fireFrameReadyEvent() {
507507
const ready = this.sortedVersion === this.lastWorldStateVersion;
508508

509-
// Check loader queue and octree instances' pending loads
510-
let loading = this.director.assetLoader.isLoading;
511-
if (!loading) {
512-
for (const [, inst] of this.octreeInstances) {
513-
loading ||= inst.hasPendingLoads;
514-
}
509+
// Count total pending loads from octree instances (including environment)
510+
let loadingCount = 0;
511+
for (const [, inst] of this.octreeInstances) {
512+
loadingCount += inst.pendingLoadCount;
515513
}
516514

517-
this.director.eventHandler.fire('frame:ready', this.cameraNode.camera, this.renderer.layer, ready, loading);
515+
this.director.eventHandler.fire('frame:ready', this.cameraNode.camera, this.renderer.layer, ready, loadingCount);
518516
}
519517

520518
update() {

src/scene/gsplat-unified/gsplat-octree-instance.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,19 @@ class GSplatOctreeInstance {
113113
pendingVisibleAdds = new Map();
114114

115115
/**
116-
* Returns true if this instance has resources pending load or prefetch.
116+
* Returns the count of resources pending load or prefetch, including environment if loading.
117117
*
118-
* @type {boolean}
118+
* @type {number}
119119
*/
120-
get hasPendingLoads() {
121-
return this.pending.size > 0 || this.prefetchPending.size > 0;
120+
get pendingLoadCount() {
121+
let count = this.pending.size + this.prefetchPending.size;
122+
123+
// Add environment if it's configured but not yet loaded
124+
if (this.octree.environmentUrl && !this.environmentPlacement) {
125+
count++;
126+
}
127+
128+
return count;
122129
}
123130

124131
/**

0 commit comments

Comments
 (0)