@babylonjs/loaders 9.30.0 → 9.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/SPLAT/gaussianSplattingDownloadManager.d.ts +10 -9
  2. package/SPLAT/gaussianSplattingDownloadManager.js +64 -53
  3. package/SPLAT/gaussianSplattingDownloadManager.js.map +1 -1
  4. package/SPLAT/gaussianSplattingResidencyPages.d.ts +49 -0
  5. package/SPLAT/gaussianSplattingResidencyPages.js +93 -0
  6. package/SPLAT/gaussianSplattingResidencyPages.js.map +1 -0
  7. package/SPLAT/gaussianSplattingStream.d.ts +154 -15
  8. package/SPLAT/gaussianSplattingStream.js +407 -25
  9. package/SPLAT/gaussianSplattingStream.js.map +1 -1
  10. package/SPLAT/gaussianSplattingWorkBuffer.d.ts +3 -1
  11. package/SPLAT/gaussianSplattingWorkBuffer.js +51 -14
  12. package/SPLAT/gaussianSplattingWorkBuffer.js.map +1 -1
  13. package/SPLAT/gaussianSplattingWorkBufferShaders.d.ts +6 -6
  14. package/SPLAT/gaussianSplattingWorkBufferShaders.js +12 -6
  15. package/SPLAT/gaussianSplattingWorkBufferShaders.js.map +1 -1
  16. package/glTF/2.0/Extensions/KHR_animation_pointer.data.pure.js +24 -9
  17. package/glTF/2.0/Extensions/KHR_animation_pointer.data.pure.js.map +1 -1
  18. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.d.ts +6 -1
  19. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js +66 -40
  20. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js.map +1 -1
  21. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphDelayReferenceBlock.d.ts +26 -0
  22. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphDelayReferenceBlock.js +44 -0
  23. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphDelayReferenceBlock.js.map +1 -0
  24. package/glTF/2.0/Extensions/KHR_interactivity/index.d.ts +1 -0
  25. package/glTF/2.0/Extensions/KHR_interactivity/index.js +1 -0
  26. package/glTF/2.0/Extensions/KHR_interactivity/index.js.map +1 -1
  27. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphExporter.js +7 -1
  28. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphExporter.js.map +1 -1
  29. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphModel.d.ts +2 -1
  30. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphModel.js +75 -6
  31. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphModel.js.map +1 -1
  32. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.d.ts +9 -0
  33. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js +35 -5
  34. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js.map +1 -1
  35. package/glTF/2.0/Extensions/KHR_interactivity/pure.d.ts +1 -0
  36. package/glTF/2.0/Extensions/KHR_interactivity/pure.js +1 -0
  37. package/glTF/2.0/Extensions/KHR_interactivity/pure.js.map +1 -1
  38. package/glTF/2.0/Extensions/KHR_interactivity.pure.js +27 -6
  39. package/glTF/2.0/Extensions/KHR_interactivity.pure.js.map +1 -1
  40. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js +2 -0
  41. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js.map +1 -1
  42. package/glTF/2.0/Extensions/KHR_node_selectability.pure.js +11 -0
  43. package/glTF/2.0/Extensions/KHR_node_selectability.pure.js.map +1 -1
  44. package/glTF/2.0/Extensions/gltfAreaLightDimensions.d.ts +26 -0
  45. package/glTF/2.0/Extensions/gltfAreaLightDimensions.js +49 -0
  46. package/glTF/2.0/Extensions/gltfAreaLightDimensions.js.map +1 -0
  47. package/glTF/2.0/Extensions/gltfPathToObjectConverter.js +3 -0
  48. package/glTF/2.0/Extensions/gltfPathToObjectConverter.js.map +1 -1
  49. package/glTF/2.0/Extensions/interactivityAssetPathToObjectConverter.d.ts +1 -1
  50. package/glTF/2.0/Extensions/interactivityAssetPathToObjectConverter.js +5 -2
  51. package/glTF/2.0/Extensions/interactivityAssetPathToObjectConverter.js.map +1 -1
  52. package/glTF/2.0/Extensions/interactivityRefPathToObjectConverter.js +1 -2
  53. package/glTF/2.0/Extensions/interactivityRefPathToObjectConverter.js.map +1 -1
  54. package/glTF/2.0/Extensions/objectModelMapping.d.ts +16 -13
  55. package/glTF/2.0/Extensions/objectModelMapping.js +157 -108
  56. package/glTF/2.0/Extensions/objectModelMapping.js.map +1 -1
  57. package/glTF/2.0/glTFLoaderInterfaces.d.ts +2 -0
  58. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  59. package/package.json +3 -3
@@ -18,9 +18,8 @@ export type DownloadGroupId = string | number;
18
18
  *
19
19
  * Downloads can be tagged with a group id and cancelled together via {@link cancelGroup}: when a node's
20
20
  * target LOD changes before its file finishes loading, the streamer cancels that file's now-unneeded
21
- * downloads. Cancellation aborts the underlying HTTP request (a queued download is dropped before it
22
- * starts; an in-flight download is aborted and its concurrency slot freed), so no bandwidth is wasted on
23
- * data that is no longer needed.
21
+ * downloads. A shared URL keeps downloading for consumers in other groups; its underlying HTTP request
22
+ * is aborted (or its queued task dropped) only when no consumers remain.
24
23
  *
25
24
  * Without this throttling, every on-demand LOD decode fans out into many parallel image fetches, so the
26
25
  * browser opens dozens of simultaneous connections that compete for bandwidth and delay the splats the
@@ -62,8 +61,8 @@ export declare class GaussianSplattingDownloadManager {
62
61
  */
63
62
  cancel(url: string): void;
64
63
  /**
65
- * Cancels every pending download tagged with the given group id.
66
- * @param groupId the group whose downloads should be cancelled
64
+ * Cancels callers in the given group. A shared URL continues for callers in other groups or with no group.
65
+ * @param groupId the group whose callers should be cancelled
67
66
  */
68
67
  cancelGroup(groupId: DownloadGroupId): void;
69
68
  /**
@@ -73,15 +72,17 @@ export declare class GaussianSplattingDownloadManager {
73
72
  dispose(): void;
74
73
  /**
75
74
  * Aborts a task: drops it from the queue (if not started), aborts its in-flight HTTP request (if started),
76
- * unwinds its current attempt, settles its promise, and frees its concurrency slot.
75
+ * unwinds its current attempt, settles all remaining callers, and frees its concurrency slot.
77
76
  * @param task the task to abort
78
77
  * @param reason the rejection reason
79
78
  */
80
79
  private _abort;
80
+ private _cancelConsumer;
81
+ private _removeConsumer;
81
82
  /**
82
- * Settles a task exactly once, removing it from the pending map and its group.
83
+ * Settles a task exactly once, removing it from the pending map and all consumer groups.
83
84
  * @param task the task to settle
84
- * @param settleFn resolves or rejects the task's promise
85
+ * @param settleFn resolves or rejects each outstanding caller
85
86
  */
86
87
  private _settle;
87
88
  /**
@@ -94,7 +95,7 @@ export declare class GaussianSplattingDownloadManager {
94
95
  */
95
96
  private _pump;
96
97
  /**
97
- * Runs a single download with retries, settling the task's shared promise. The idempotency entry is
98
+ * Runs a single download with retries, settling each outstanding consumer. The idempotency entry is
98
99
  * removed the moment the task settles so a later request for the same URL starts a fresh download.
99
100
  * @param task the queued download to run
100
101
  */
@@ -8,9 +8,8 @@ import { Tools } from "@babylonjs/core/Misc/tools.js";
8
8
  *
9
9
  * Downloads can be tagged with a group id and cancelled together via {@link cancelGroup}: when a node's
10
10
  * target LOD changes before its file finishes loading, the streamer cancels that file's now-unneeded
11
- * downloads. Cancellation aborts the underlying HTTP request (a queued download is dropped before it
12
- * starts; an in-flight download is aborted and its concurrency slot freed), so no bandwidth is wasted on
13
- * data that is no longer needed.
11
+ * downloads. A shared URL keeps downloading for consumers in other groups; its underlying HTTP request
12
+ * is aborted (or its queued task dropped) only when no consumers remain.
14
13
  *
15
14
  * Without this throttling, every on-demand LOD decode fans out into many parallel image fetches, so the
16
15
  * browser opens dozens of simultaneous connections that compete for bandwidth and delay the splats the
@@ -28,7 +27,7 @@ export class GaussianSplattingDownloadManager {
28
27
  // Idempotency: maps a URL to its task while the download is queued or in flight. The entry is removed
29
28
  // once the download settles so a later request (after the bytes were consumed) downloads again.
30
29
  this._pending = new Map();
31
- // Maps a group id to the set of URLs currently downloading (or queued) under it, for bulk cancellation.
30
+ // Maps each group to its outstanding callers, not to shared URL tasks.
32
31
  this._groups = new Map();
33
32
  this._disposed = false;
34
33
  this.maxConcurrent = Math.max(1, options?.maxConcurrent ?? 2);
@@ -51,34 +50,31 @@ export class GaussianSplattingDownloadManager {
51
50
  if (this._disposed) {
52
51
  throw new Error("GaussianSplattingDownloadManager has been disposed.");
53
52
  }
54
- const existing = this._pending.get(url);
55
- if (existing) {
56
- return await existing.promise;
57
- }
58
- const task = {
59
- url,
60
- groupId,
61
- settled: false,
62
- cancelled: false,
63
- started: false,
64
- slotReleased: false,
65
- };
66
- task.promise = new Promise((resolve, reject) => {
67
- task.resolve = resolve;
68
- task.reject = reject;
53
+ let task = this._pending.get(url);
54
+ const newTask = !task;
55
+ if (!task) {
56
+ task = { url, consumers: new Set(), settled: false, cancelled: false, started: false, slotReleased: false };
57
+ this._pending.set(url, task);
58
+ this._queue.push(task);
59
+ }
60
+ const consumer = { task, groupId };
61
+ consumer.promise = new Promise((resolve, reject) => {
62
+ consumer.resolve = resolve;
63
+ consumer.reject = reject;
69
64
  });
70
- this._pending.set(url, task);
65
+ task.consumers.add(consumer);
71
66
  if (groupId !== undefined) {
72
- let urls = this._groups.get(groupId);
73
- if (!urls) {
74
- urls = new Set();
75
- this._groups.set(groupId, urls);
67
+ let consumers = this._groups.get(groupId);
68
+ if (!consumers) {
69
+ consumers = new Set();
70
+ this._groups.set(groupId, consumers);
76
71
  }
77
- urls.add(url);
72
+ consumers.add(consumer);
78
73
  }
79
- this._queue.push(task);
80
- this._pump();
81
- return await task.promise;
74
+ if (newTask) {
75
+ this._pump();
76
+ }
77
+ return await consumer.promise;
82
78
  }
83
79
  /**
84
80
  * Cancels a single pending download by URL. A queued download is dropped before it starts; an in-flight
@@ -94,19 +90,17 @@ export class GaussianSplattingDownloadManager {
94
90
  this._abort(task, new Error(`GaussianSplattingDownloadManager: download cancelled (${url}).`));
95
91
  }
96
92
  /**
97
- * Cancels every pending download tagged with the given group id.
98
- * @param groupId the group whose downloads should be cancelled
93
+ * Cancels callers in the given group. A shared URL continues for callers in other groups or with no group.
94
+ * @param groupId the group whose callers should be cancelled
99
95
  */
100
96
  cancelGroup(groupId) {
101
- const urls = this._groups.get(groupId);
102
- if (!urls) {
97
+ const consumers = this._groups.get(groupId);
98
+ if (!consumers) {
103
99
  return;
104
100
  }
105
- // Copy first: cancel() mutates the group set as each URL settles.
106
- for (const url of Array.from(urls)) {
107
- this.cancel(url);
101
+ for (const consumer of Array.from(consumers)) {
102
+ this._cancelConsumer(consumer, new Error(`GaussianSplattingDownloadManager: download cancelled (${consumer.task.url}).`));
108
103
  }
109
- this._groups.delete(groupId);
110
104
  }
111
105
  /**
112
106
  * Cancels every queued download and aborts every in-flight download, preventing new downloads from
@@ -124,7 +118,7 @@ export class GaussianSplattingDownloadManager {
124
118
  }
125
119
  /**
126
120
  * Aborts a task: drops it from the queue (if not started), aborts its in-flight HTTP request (if started),
127
- * unwinds its current attempt, settles its promise, and frees its concurrency slot.
121
+ * unwinds its current attempt, settles all remaining callers, and frees its concurrency slot.
128
122
  * @param task the task to abort
129
123
  * @param reason the rejection reason
130
124
  */
@@ -141,32 +135,49 @@ export class GaussianSplattingDownloadManager {
141
135
  task.request?.abort();
142
136
  // abort() does not fire the error callback, so unwind the awaited attempt explicitly.
143
137
  task.cancelAttempt?.(reason);
144
- this._settle(task, () => task.reject(reason));
138
+ this._settle(task, (consumer) => consumer.reject(reason));
145
139
  if (task.started) {
146
140
  this._releaseSlot(task);
147
141
  }
148
142
  }
143
+ _cancelConsumer(consumer, reason) {
144
+ const task = consumer.task;
145
+ if (!task.consumers.has(consumer)) {
146
+ return;
147
+ }
148
+ this._removeConsumer(consumer);
149
+ consumer.reject(reason);
150
+ if (task.consumers.size === 0) {
151
+ this._abort(task, reason);
152
+ }
153
+ }
154
+ _removeConsumer(consumer) {
155
+ consumer.task.consumers.delete(consumer);
156
+ if (consumer.groupId !== undefined) {
157
+ const members = this._groups.get(consumer.groupId);
158
+ members?.delete(consumer);
159
+ if (members?.size === 0) {
160
+ this._groups.delete(consumer.groupId);
161
+ }
162
+ }
163
+ }
149
164
  /**
150
- * Settles a task exactly once, removing it from the pending map and its group.
165
+ * Settles a task exactly once, removing it from the pending map and all consumer groups.
151
166
  * @param task the task to settle
152
- * @param settleFn resolves or rejects the task's promise
167
+ * @param settleFn resolves or rejects each outstanding caller
153
168
  */
154
169
  _settle(task, settleFn) {
155
170
  if (task.settled) {
156
171
  return;
157
172
  }
158
173
  task.settled = true;
159
- this._pending.delete(task.url);
160
- if (task.groupId !== undefined) {
161
- const urls = this._groups.get(task.groupId);
162
- if (urls) {
163
- urls.delete(task.url);
164
- if (urls.size === 0) {
165
- this._groups.delete(task.groupId);
166
- }
167
- }
174
+ if (this._pending.get(task.url) === task) {
175
+ this._pending.delete(task.url);
176
+ }
177
+ for (const consumer of task.consumers) {
178
+ this._removeConsumer(consumer);
179
+ settleFn(consumer);
168
180
  }
169
- settleFn();
170
181
  }
171
182
  /**
172
183
  * Releases a task's concurrency slot exactly once and pumps the queue.
@@ -197,7 +208,7 @@ export class GaussianSplattingDownloadManager {
197
208
  }
198
209
  }
199
210
  /**
200
- * Runs a single download with retries, settling the task's shared promise. The idempotency entry is
211
+ * Runs a single download with retries, settling each outstanding consumer. The idempotency entry is
201
212
  * removed the moment the task settles so a later request for the same URL starts a fresh download.
202
213
  * @param task the queued download to run
203
214
  */
@@ -211,7 +222,7 @@ export class GaussianSplattingDownloadManager {
211
222
  try {
212
223
  // eslint-disable-next-line no-await-in-loop
213
224
  const buffer = await this._downloadAttemptAsync(task);
214
- this._settle(task, () => task.resolve(buffer));
225
+ this._settle(task, (consumer) => consumer.resolve(buffer));
215
226
  return;
216
227
  }
217
228
  catch (e) {
@@ -223,7 +234,7 @@ export class GaussianSplattingDownloadManager {
223
234
  lastError = e;
224
235
  }
225
236
  }
226
- this._settle(task, () => task.reject(lastError));
237
+ this._settle(task, (consumer) => consumer.reject(lastError));
227
238
  }
228
239
  /**
229
240
  * Performs one download attempt, exposing the request handle (for abort) and an attempt-rejecter on the
@@ -1 +1 @@
1
- {"version":3,"file":"gaussianSplattingDownloadManager.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/gaussianSplattingDownloadManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAwCxC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,gCAAgC;IAezC;;;OAGG;IACH,YAAmB,OAAkD;QAb7D,iBAAY,GAAG,CAAC,CAAC;QACR,WAAM,GAAoB,EAAE,CAAC;QAC9C,sGAAsG;QACtG,gGAAgG;QAC/E,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC7D,wGAAwG;QACvF,YAAO,GAAG,IAAI,GAAG,EAAgC,CAAC;QAC3D,cAAS,GAAG,KAAK,CAAC;QAOtB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,IAAI,CAAC,CAAC,CAAC;QAC9D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,aAAa,CAAC,GAAW,EAAE,OAAyB;QAC7D,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC3E,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC;QAClC,C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,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,qBAAqB,CAAC,IAAmB;QACnD,OAAO,MAAM,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CACzB,IAAI,CAAC,GAAG,EACR,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAmB,CAAC,EACtC,SAAS,EACT,SAAS,EACT,IAAI,EACJ,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,oDAAoD,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CACvJ,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["import { Tools } from \"core/Misc/tools\";\r\nimport { type IFileRequest } from \"core/Misc/fileRequest\";\r\n\r\n/**\r\n * Options for {@link GaussianSplattingDownloadManager}.\r\n */\r\nexport interface IGaussianSplattingDownloadManagerOptions {\r\n /** Maximum number of downloads allowed to run at the same time. PlayCanvas default `2`. */\r\n maxConcurrent?: number;\r\n /** Number of times a failed download is retried before rejecting. PlayCanvas default `2` (3 attempts total). */\r\n maxRetries?: number;\r\n}\r\n\r\n/** Identifies a group of related downloads so they can be cancelled together. */\r\nexport type DownloadGroupId = string | number;\r\n\r\n/**\r\n * A queued, concurrency-capped download task.\r\n */\r\ninterface IDownloadTask {\r\n url: string;\r\n groupId?: DownloadGroupId;\r\n promise: Promise<ArrayBuffer>;\r\n resolve: (data: ArrayBuffer) => void;\r\n reject: (reason: any) => void;\r\n // Set once the task is settled (resolved/rejected/cancelled) so it is never settled twice.\r\n settled: boolean;\r\n // Set when the task has been cancelled so an in-flight download discards its eventual result.\r\n cancelled: boolean;\r\n // True once the task has been pulled from the queue and counted against the concurrency cap.\r\n started: boolean;\r\n // True once the task's concurrency slot has been released (so it is released exactly once).\r\n slotReleased: boolean;\r\n // The in-flight HTTP request for the current attempt, used to abort the download on cancellation.\r\n request?: IFileRequest;\r\n // Rejects the current attempt's promise so an aborted download unwinds immediately (abort() does not\r\n // fire the error callback, so the awaited attempt would otherwise hang).\r\n cancelAttempt?: (reason: any) => void;\r\n}\r\n\r\n/**\r\n * Throttles the file downloads issued while streaming a Gaussian Splatting LOD scene.\r\n *\r\n * Mirrors the PlayCanvas gsplat asset loader: at most {@link maxConcurrent} downloads run at once, the\r\n * rest wait in a FIFO queue, each failed download is retried up to {@link maxRetries} times, and requests\r\n * are idempotent — concurrent (queued or in-flight) requests for the same URL share a single download.\r\n *\r\n * Downloads can be tagged with a group id and cancelled together via {@link cancelGroup}: when a node's\r\n * target LOD changes before its file finishes loading, the streamer cancels that file's now-unneeded\r\n * downloads. Cancellation aborts the underlying HTTP request (a queued download is dropped before it\r\n * starts; an in-flight download is aborted and its concurrency slot freed), so no bandwidth is wasted on\r\n * data that is no longer needed.\r\n *\r\n * Without this throttling, every on-demand LOD decode fans out into many parallel image fetches, so the\r\n * browser opens dozens of simultaneous connections that compete for bandwidth and delay the splats the\r\n * camera actually needs.\r\n * @experimental\r\n */\r\nexport class GaussianSplattingDownloadManager {\r\n /** Maximum number of downloads allowed to run at the same time. */\r\n public readonly maxConcurrent: number;\r\n /** Number of times a failed download is retried before rejecting. */\r\n public readonly maxRetries: number;\r\n\r\n private _activeCount = 0;\r\n private readonly _queue: IDownloadTask[] = [];\r\n // Idempotency: maps a URL to its task while the download is queued or in flight. The entry is removed\r\n // once the download settles so a later request (after the bytes were consumed) downloads again.\r\n private readonly _pending = new Map<string, IDownloadTask>();\r\n // Maps a group id to the set of URLs currently downloading (or queued) under it, for bulk cancellation.\r\n private readonly _groups = new Map<DownloadGroupId, Set<string>>();\r\n private _disposed = false;\r\n\r\n /**\r\n * Creates a download manager.\r\n * @param options concurrency and retry limits\r\n */\r\n public constructor(options?: IGaussianSplattingDownloadManagerOptions) {\r\n this.maxConcurrent = Math.max(1, options?.maxConcurrent ?? 2);\r\n this.maxRetries = Math.max(0, options?.maxRetries ?? 2);\r\n }\r\n\r\n /**\r\n * Whether there are no downloads queued or in flight.\r\n */\r\n public get isIdle(): boolean {\r\n return this._pending.size === 0;\r\n }\r\n\r\n /**\r\n * Downloads a file as an `ArrayBuffer`, queued behind the concurrency cap and retried on failure.\r\n * Concurrent requests for the same URL resolve from a single shared download.\r\n * @param url the file URL to download\r\n * @param groupId optional group tag so related downloads can be cancelled together via {@link cancelGroup}\r\n * @returns a promise resolving with the downloaded bytes\r\n */\r\n public async loadFileAsync(url: string, groupId?: DownloadGroupId): Promise<ArrayBuffer> {\r\n if (this._disposed) {\r\n throw new Error(\"GaussianSplattingDownloadManager has been disposed.\");\r\n }\r\n const existing = this._pending.get(url);\r\n if (existing) {\r\n return await existing.promise;\r\n }\r\n const task: IDownloadTask = {\r\n url,\r\n groupId,\r\n settled: false,\r\n cancelled: false,\r\n started: false,\r\n slotReleased: false,\r\n } as IDownloadTask;\r\n task.promise = new Promise<ArrayBuffer>((resolve, reject) => {\r\n task.resolve = resolve;\r\n task.reject = reject;\r\n });\r\n this._pending.set(url, task);\r\n if (groupId !== undefined) {\r\n let urls = this._groups.get(groupId);\r\n if (!urls) {\r\n urls = new Set<string>();\r\n this._groups.set(groupId, urls);\r\n }\r\n urls.add(url);\r\n }\r\n this._queue.push(task);\r\n this._pump();\r\n return await task.promise;\r\n }\r\n\r\n /**\r\n * Cancels a single pending download by URL. A queued download is dropped before it starts; an in-flight\r\n * download has its underlying HTTP request aborted and its concurrency slot freed. No-op if the URL is\r\n * not currently pending.\r\n * @param url the URL to cancel\r\n */\r\n public cancel(url: string): void {\r\n const task = this._pending.get(url);\r\n if (!task) {\r\n return;\r\n }\r\n this._abort(task, new Error(`GaussianSplattingDownloadManager: download cancelled (${url}).`));\r\n }\r\n\r\n /**\r\n * Cancels every pending download tagged with the given group id.\r\n * @param groupId the group whose downloads should be cancelled\r\n */\r\n public cancelGroup(groupId: DownloadGroupId): void {\r\n const urls = this._groups.get(groupId);\r\n if (!urls) {\r\n return;\r\n }\r\n // Copy first: cancel() mutates the group set as each URL settles.\r\n for (const url of Array.from(urls)) {\r\n this.cancel(url);\r\n }\r\n this._groups.delete(groupId);\r\n }\r\n\r\n /**\r\n * Cancels every queued download and aborts every in-flight download, preventing new downloads from\r\n * starting.\r\n */\r\n public dispose(): void {\r\n if (this._disposed) {\r\n return;\r\n }\r\n this._disposed = true;\r\n this._queue.length = 0;\r\n for (const task of Array.from(this._pending.values())) {\r\n this._abort(task, new Error(\"GaussianSplattingDownloadManager has been disposed.\"));\r\n }\r\n }\r\n\r\n /**\r\n * Aborts a task: drops it from the queue (if not started), aborts its in-flight HTTP request (if started),\r\n * unwinds its current attempt, settles its promise, and frees its concurrency slot.\r\n * @param task the task to abort\r\n * @param reason the rejection reason\r\n */\r\n private _abort(task: IDownloadTask, reason: any): void {\r\n if (task.settled) {\r\n return;\r\n }\r\n task.cancelled = true;\r\n const queueIndex = this._queue.indexOf(task);\r\n if (queueIndex !== -1) {\r\n this._queue.splice(queueIndex, 1);\r\n }\r\n // Abort the underlying HTTP request (no-op for a queued task whose request has not been created).\r\n task.request?.abort();\r\n // abort() does not fire the error callback, so unwind the awaited attempt explicitly.\r\n task.cancelAttempt?.(reason);\r\n this._settle(task, () => task.reject(reason));\r\n if (task.started) {\r\n this._releaseSlot(task);\r\n }\r\n }\r\n\r\n /**\r\n * Settles a task exactly once, removing it from the pending map and its group.\r\n * @param task the task to settle\r\n * @param settleFn resolves or rejects the task's promise\r\n */\r\n private _settle(task: IDownloadTask, settleFn: () => void): void {\r\n if (task.settled) {\r\n return;\r\n }\r\n task.settled = true;\r\n this._pending.delete(task.url);\r\n if (task.groupId !== undefined) {\r\n const urls = this._groups.get(task.groupId);\r\n if (urls) {\r\n urls.delete(task.url);\r\n if (urls.size === 0) {\r\n this._groups.delete(task.groupId);\r\n }\r\n }\r\n }\r\n settleFn();\r\n }\r\n\r\n /**\r\n * Releases a task's concurrency slot exactly once and pumps the queue.\r\n * @param task the task whose slot to release\r\n */\r\n private _releaseSlot(task: IDownloadTask): void {\r\n if (task.slotReleased) {\r\n return;\r\n }\r\n task.slotReleased = true;\r\n this._activeCount--;\r\n this._pump();\r\n }\r\n\r\n /**\r\n * Starts as many queued downloads as the concurrency cap allows.\r\n */\r\n private _pump(): void {\r\n while (!this._disposed && this._activeCount < this.maxConcurrent && this._queue.length > 0) {\r\n const task = this._queue.shift()!;\r\n if (task.settled) {\r\n continue;\r\n }\r\n task.started = true;\r\n this._activeCount++;\r\n void this._runTaskAsync(task).finally(() => {\r\n this._releaseSlot(task);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Runs a single download with retries, settling the task's shared promise. The idempotency entry is\r\n * removed the moment the task settles so a later request for the same URL starts a fresh download.\r\n * @param task the queued download to run\r\n */\r\n private async _runTaskAsync(task: IDownloadTask): Promise<void> {\r\n let lastError: any;\r\n // attempt 0 is the initial try; attempts 1..maxRetries are retries (PlayCanvas retries immediately).\r\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\r\n if (this._disposed || task.cancelled) {\r\n return;\r\n }\r\n try {\r\n // eslint-disable-next-line no-await-in-loop\r\n const buffer = await this._downloadAttemptAsync(task);\r\n this._settle(task, () => task.resolve(buffer));\r\n return;\r\n } catch (e) {\r\n task.cancelAttempt = undefined;\r\n if (this._disposed || task.cancelled) {\r\n // The task was already settled by cancel()/dispose(); just stop retrying.\r\n return;\r\n }\r\n lastError = e;\r\n }\r\n }\r\n this._settle(task, () => task.reject(lastError));\r\n }\r\n\r\n /**\r\n * Performs one download attempt, exposing the request handle (for abort) and an attempt-rejecter on the\r\n * task so cancellation can both abort the HTTP request and unwind this awaited attempt.\r\n * @param task the download task\r\n * @returns a promise resolving with the downloaded bytes\r\n */\r\n private async _downloadAttemptAsync(task: IDownloadTask): Promise<ArrayBuffer> {\r\n return await new Promise<ArrayBuffer>((resolve, reject) => {\r\n task.cancelAttempt = reject;\r\n task.request = Tools.LoadFile(\r\n task.url,\r\n (data) => resolve(data as ArrayBuffer),\r\n undefined,\r\n undefined,\r\n true,\r\n (_request, exception) => reject(exception instanceof Error ? exception : new Error(`GaussianSplattingDownloadManager: failed to load ${task.url}.`))\r\n );\r\n });\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"gaussianSplattingDownloadManager.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/gaussianSplattingDownloadManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AA6CxC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,gCAAgC;IAezC;;;OAGG;IACH,YAAmB,OAAkD;QAb7D,iBAAY,GAAG,CAAC,CAAC;QACR,WAAM,GAAoB,EAAE,CAAC;QAC9C,sGAAsG;QACtG,gGAAgG;QAC/E,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC7D,uEAAuE;QACtD,YAAO,GAAG,IAAI,GAAG,EAA2C,CAAC;QACtE,cAAS,GAAG,KAAK,CAAC;QAOtB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,IAAI,CAAC,CAAC,CAAC;QAC9D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,aAAa,CAAC,GAAW,EAAE,OAAyB;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YAClB,CAAC;QACL,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,qBAAqB,CAAC,IAAmB;QACnD,OAAO,MAAM,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CACzB,IAAI,CAAC,GAAG,EACR,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAmB,CAAC,EACtC,SAAS,EACT,SAAS,EACT,IAAI,EACJ,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,oDAAoD,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CACvJ,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["import { Tools } from \"core/Misc/tools\";\r\nimport { type IFileRequest } from \"core/Misc/fileRequest\";\r\n\r\n/**\r\n * Options for {@link GaussianSplattingDownloadManager}.\r\n */\r\nexport interface IGaussianSplattingDownloadManagerOptions {\r\n /** Maximum number of downloads allowed to run at the same time. PlayCanvas default `2`. */\r\n maxConcurrent?: number;\r\n /** Number of times a failed download is retried before rejecting. PlayCanvas default `2` (3 attempts total). */\r\n maxRetries?: number;\r\n}\r\n\r\n/** Identifies a group of related downloads so they can be cancelled together. */\r\nexport type DownloadGroupId = string | number;\r\n\r\n/**\r\n * A queued, concurrency-capped download task.\r\n */\r\ninterface IDownloadTask {\r\n url: string;\r\n consumers: Set<IDownloadConsumer>;\r\n // Set once the task is settled (resolved/rejected/cancelled) so it is never settled twice.\r\n settled: boolean;\r\n // Set when the task has been cancelled so an in-flight download discards its eventual result.\r\n cancelled: boolean;\r\n // True once the task has been pulled from the queue and counted against the concurrency cap.\r\n started: boolean;\r\n // True once the task's concurrency slot has been released (so it is released exactly once).\r\n slotReleased: boolean;\r\n // The in-flight HTTP request for the current attempt, used to abort the download on cancellation.\r\n request?: IFileRequest;\r\n // Rejects the current attempt's promise so an aborted download unwinds immediately (abort() does not\r\n // fire the error callback, so the awaited attempt would otherwise hang).\r\n cancelAttempt?: (reason: any) => void;\r\n}\r\n\r\ninterface IDownloadConsumer {\r\n task: IDownloadTask;\r\n groupId?: DownloadGroupId;\r\n promise: Promise<ArrayBuffer>;\r\n resolve: (data: ArrayBuffer) => void;\r\n reject: (reason: any) => void;\r\n}\r\n\r\n/**\r\n * Throttles the file downloads issued while streaming a Gaussian Splatting LOD scene.\r\n *\r\n * Mirrors the PlayCanvas gsplat asset loader: at most {@link maxConcurrent} downloads run at once, the\r\n * rest wait in a FIFO queue, each failed download is retried up to {@link maxRetries} times, and requests\r\n * are idempotent — concurrent (queued or in-flight) requests for the same URL share a single download.\r\n *\r\n * Downloads can be tagged with a group id and cancelled together via {@link cancelGroup}: when a node's\r\n * target LOD changes before its file finishes loading, the streamer cancels that file's now-unneeded\r\n * downloads. A shared URL keeps downloading for consumers in other groups; its underlying HTTP request\r\n * is aborted (or its queued task dropped) only when no consumers remain.\r\n *\r\n * Without this throttling, every on-demand LOD decode fans out into many parallel image fetches, so the\r\n * browser opens dozens of simultaneous connections that compete for bandwidth and delay the splats the\r\n * camera actually needs.\r\n * @experimental\r\n */\r\nexport class GaussianSplattingDownloadManager {\r\n /** Maximum number of downloads allowed to run at the same time. */\r\n public readonly maxConcurrent: number;\r\n /** Number of times a failed download is retried before rejecting. */\r\n public readonly maxRetries: number;\r\n\r\n private _activeCount = 0;\r\n private readonly _queue: IDownloadTask[] = [];\r\n // Idempotency: maps a URL to its task while the download is queued or in flight. The entry is removed\r\n // once the download settles so a later request (after the bytes were consumed) downloads again.\r\n private readonly _pending = new Map<string, IDownloadTask>();\r\n // Maps each group to its outstanding callers, not to shared URL tasks.\r\n private readonly _groups = new Map<DownloadGroupId, Set<IDownloadConsumer>>();\r\n private _disposed = false;\r\n\r\n /**\r\n * Creates a download manager.\r\n * @param options concurrency and retry limits\r\n */\r\n public constructor(options?: IGaussianSplattingDownloadManagerOptions) {\r\n this.maxConcurrent = Math.max(1, options?.maxConcurrent ?? 2);\r\n this.maxRetries = Math.max(0, options?.maxRetries ?? 2);\r\n }\r\n\r\n /**\r\n * Whether there are no downloads queued or in flight.\r\n */\r\n public get isIdle(): boolean {\r\n return this._pending.size === 0;\r\n }\r\n\r\n /**\r\n * Downloads a file as an `ArrayBuffer`, queued behind the concurrency cap and retried on failure.\r\n * Concurrent requests for the same URL resolve from a single shared download.\r\n * @param url the file URL to download\r\n * @param groupId optional group tag so related downloads can be cancelled together via {@link cancelGroup}\r\n * @returns a promise resolving with the downloaded bytes\r\n */\r\n public async loadFileAsync(url: string, groupId?: DownloadGroupId): Promise<ArrayBuffer> {\r\n if (this._disposed) {\r\n throw new Error(\"GaussianSplattingDownloadManager has been disposed.\");\r\n }\r\n let task = this._pending.get(url);\r\n const newTask = !task;\r\n if (!task) {\r\n task = { url, consumers: new Set<IDownloadConsumer>(), settled: false, cancelled: false, started: false, slotReleased: false };\r\n this._pending.set(url, task);\r\n this._queue.push(task);\r\n }\r\n const consumer = { task, groupId } as IDownloadConsumer;\r\n consumer.promise = new Promise<ArrayBuffer>((resolve, reject) => {\r\n consumer.resolve = resolve;\r\n consumer.reject = reject;\r\n });\r\n task.consumers.add(consumer);\r\n if (groupId !== undefined) {\r\n let consumers = this._groups.get(groupId);\r\n if (!consumers) {\r\n consumers = new Set<IDownloadConsumer>();\r\n this._groups.set(groupId, consumers);\r\n }\r\n consumers.add(consumer);\r\n }\r\n if (newTask) {\r\n this._pump();\r\n }\r\n return await consumer.promise;\r\n }\r\n\r\n /**\r\n * Cancels a single pending download by URL. A queued download is dropped before it starts; an in-flight\r\n * download has its underlying HTTP request aborted and its concurrency slot freed. No-op if the URL is\r\n * not currently pending.\r\n * @param url the URL to cancel\r\n */\r\n public cancel(url: string): void {\r\n const task = this._pending.get(url);\r\n if (!task) {\r\n return;\r\n }\r\n this._abort(task, new Error(`GaussianSplattingDownloadManager: download cancelled (${url}).`));\r\n }\r\n\r\n /**\r\n * Cancels callers in the given group. A shared URL continues for callers in other groups or with no group.\r\n * @param groupId the group whose callers should be cancelled\r\n */\r\n public cancelGroup(groupId: DownloadGroupId): void {\r\n const consumers = this._groups.get(groupId);\r\n if (!consumers) {\r\n return;\r\n }\r\n for (const consumer of Array.from(consumers)) {\r\n this._cancelConsumer(consumer, new Error(`GaussianSplattingDownloadManager: download cancelled (${consumer.task.url}).`));\r\n }\r\n }\r\n\r\n /**\r\n * Cancels every queued download and aborts every in-flight download, preventing new downloads from\r\n * starting.\r\n */\r\n public dispose(): void {\r\n if (this._disposed) {\r\n return;\r\n }\r\n this._disposed = true;\r\n this._queue.length = 0;\r\n for (const task of Array.from(this._pending.values())) {\r\n this._abort(task, new Error(\"GaussianSplattingDownloadManager has been disposed.\"));\r\n }\r\n }\r\n\r\n /**\r\n * Aborts a task: drops it from the queue (if not started), aborts its in-flight HTTP request (if started),\r\n * unwinds its current attempt, settles all remaining callers, and frees its concurrency slot.\r\n * @param task the task to abort\r\n * @param reason the rejection reason\r\n */\r\n private _abort(task: IDownloadTask, reason: any): void {\r\n if (task.settled) {\r\n return;\r\n }\r\n task.cancelled = true;\r\n const queueIndex = this._queue.indexOf(task);\r\n if (queueIndex !== -1) {\r\n this._queue.splice(queueIndex, 1);\r\n }\r\n // Abort the underlying HTTP request (no-op for a queued task whose request has not been created).\r\n task.request?.abort();\r\n // abort() does not fire the error callback, so unwind the awaited attempt explicitly.\r\n task.cancelAttempt?.(reason);\r\n this._settle(task, (consumer) => consumer.reject(reason));\r\n if (task.started) {\r\n this._releaseSlot(task);\r\n }\r\n }\r\n\r\n private _cancelConsumer(consumer: IDownloadConsumer, reason: Error): void {\r\n const task = consumer.task;\r\n if (!task.consumers.has(consumer)) {\r\n return;\r\n }\r\n this._removeConsumer(consumer);\r\n consumer.reject(reason);\r\n if (task.consumers.size === 0) {\r\n this._abort(task, reason);\r\n }\r\n }\r\n\r\n private _removeConsumer(consumer: IDownloadConsumer): void {\r\n consumer.task.consumers.delete(consumer);\r\n if (consumer.groupId !== undefined) {\r\n const members = this._groups.get(consumer.groupId);\r\n members?.delete(consumer);\r\n if (members?.size === 0) {\r\n this._groups.delete(consumer.groupId);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Settles a task exactly once, removing it from the pending map and all consumer groups.\r\n * @param task the task to settle\r\n * @param settleFn resolves or rejects each outstanding caller\r\n */\r\n private _settle(task: IDownloadTask, settleFn: (consumer: IDownloadConsumer) => void): void {\r\n if (task.settled) {\r\n return;\r\n }\r\n task.settled = true;\r\n if (this._pending.get(task.url) === task) {\r\n this._pending.delete(task.url);\r\n }\r\n for (const consumer of task.consumers) {\r\n this._removeConsumer(consumer);\r\n settleFn(consumer);\r\n }\r\n }\r\n\r\n /**\r\n * Releases a task's concurrency slot exactly once and pumps the queue.\r\n * @param task the task whose slot to release\r\n */\r\n private _releaseSlot(task: IDownloadTask): void {\r\n if (task.slotReleased) {\r\n return;\r\n }\r\n task.slotReleased = true;\r\n this._activeCount--;\r\n this._pump();\r\n }\r\n\r\n /**\r\n * Starts as many queued downloads as the concurrency cap allows.\r\n */\r\n private _pump(): void {\r\n while (!this._disposed && this._activeCount < this.maxConcurrent && this._queue.length > 0) {\r\n const task = this._queue.shift()!;\r\n if (task.settled) {\r\n continue;\r\n }\r\n task.started = true;\r\n this._activeCount++;\r\n void this._runTaskAsync(task).finally(() => {\r\n this._releaseSlot(task);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Runs a single download with retries, settling each outstanding consumer. The idempotency entry is\r\n * removed the moment the task settles so a later request for the same URL starts a fresh download.\r\n * @param task the queued download to run\r\n */\r\n private async _runTaskAsync(task: IDownloadTask): Promise<void> {\r\n let lastError: any;\r\n // attempt 0 is the initial try; attempts 1..maxRetries are retries (PlayCanvas retries immediately).\r\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\r\n if (this._disposed || task.cancelled) {\r\n return;\r\n }\r\n try {\r\n // eslint-disable-next-line no-await-in-loop\r\n const buffer = await this._downloadAttemptAsync(task);\r\n this._settle(task, (consumer) => consumer.resolve(buffer));\r\n return;\r\n } catch (e) {\r\n task.cancelAttempt = undefined;\r\n if (this._disposed || task.cancelled) {\r\n // The task was already settled by cancel()/dispose(); just stop retrying.\r\n return;\r\n }\r\n lastError = e;\r\n }\r\n }\r\n this._settle(task, (consumer) => consumer.reject(lastError));\r\n }\r\n\r\n /**\r\n * Performs one download attempt, exposing the request handle (for abort) and an attempt-rejecter on the\r\n * task so cancellation can both abort the HTTP request and unwind this awaited attempt.\r\n * @param task the download task\r\n * @returns a promise resolving with the downloaded bytes\r\n */\r\n private async _downloadAttemptAsync(task: IDownloadTask): Promise<ArrayBuffer> {\r\n return await new Promise<ArrayBuffer>((resolve, reject) => {\r\n task.cancelAttempt = reject;\r\n task.request = Tools.LoadFile(\r\n task.url,\r\n (data) => resolve(data as ArrayBuffer),\r\n undefined,\r\n undefined,\r\n true,\r\n (_request, exception) => reject(exception instanceof Error ? exception : new Error(`GaussianSplattingDownloadManager: failed to load ${task.url}.`))\r\n );\r\n });\r\n }\r\n}\r\n"]}
@@ -0,0 +1,49 @@
1
+ import { type IGaussianSplattingStreamSourceRange } from "./gaussianSplattingStream.js";
2
+ /**
3
+ * A LOD entry referencing an interval of a source file. Structurally an ISOGLODEntry.
4
+ * @internal
5
+ */
6
+ export interface ISplatResidencyEntry {
7
+ /** Index of the source file. */
8
+ file: number;
9
+ /** First splat of the interval inside the source file. */
10
+ offset: number;
11
+ /** Number of splats in the interval. */
12
+ count: number;
13
+ }
14
+ /**
15
+ * One resident allocation unit carved from a source file.
16
+ * @internal
17
+ */
18
+ export interface ISplatResidencyPage {
19
+ /** Allocation ID, never lower than the number of source files. */
20
+ id: number;
21
+ /** Merged source interval covered by the page. */
22
+ source: Readonly<IGaussianSplattingStreamSourceRange>;
23
+ /** LOD entries (by reference) that fall inside the source interval. */
24
+ entries: ISplatResidencyEntry[];
25
+ }
26
+ /**
27
+ * Result of {@link BuildSplatResidencyPages}.
28
+ * @internal
29
+ */
30
+ export interface ISplatResidencyPagesResult {
31
+ /** Pages to publish. */
32
+ pages: ISplatResidencyPage[];
33
+ /** Source files left whole because at least one of their entries was invalid. */
34
+ invalidFiles: number[];
35
+ }
36
+ /**
37
+ * Groups overlapping intervals, but not adjacent ones, into independently resident pages.
38
+ * Does not mutate entries; callers publish the mapping once the pages are returned.
39
+ * Pinned source files remain whole so the permanent fallback cannot be partially evicted.
40
+ * A source file with no known size, or with at least one invalid interval, produces no pages and stays whole.
41
+ * @param entries LOD entries referenced by leaves
42
+ * @param counts splat count of every source file whose metadata is available
43
+ * @param pinned source files that must stay whole
44
+ * @param sourceFileCount number of source files; valid source IDs are in [0, sourceFileCount)
45
+ * @param firstId first unused allocation ID, at least sourceFileCount
46
+ * @returns the pages plus the source files left whole because of invalid intervals
47
+ * @internal
48
+ */
49
+ export declare function BuildSplatResidencyPages(entries: readonly ISplatResidencyEntry[], counts: ReadonlyMap<number, number>, pinned: ReadonlySet<number>, sourceFileCount: number, firstId: number): ISplatResidencyPagesResult;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Groups overlapping intervals, but not adjacent ones, into independently resident pages.
3
+ * Does not mutate entries; callers publish the mapping once the pages are returned.
4
+ * Pinned source files remain whole so the permanent fallback cannot be partially evicted.
5
+ * A source file with no known size, or with at least one invalid interval, produces no pages and stays whole.
6
+ * @param entries LOD entries referenced by leaves
7
+ * @param counts splat count of every source file whose metadata is available
8
+ * @param pinned source files that must stay whole
9
+ * @param sourceFileCount number of source files; valid source IDs are in [0, sourceFileCount)
10
+ * @param firstId first unused allocation ID, at least sourceFileCount
11
+ * @returns the pages plus the source files left whole because of invalid intervals
12
+ * @internal
13
+ */
14
+ export function BuildSplatResidencyPages(entries, counts, pinned, sourceFileCount, firstId) {
15
+ if (!Number.isSafeInteger(sourceFileCount) || sourceFileCount < 0 || !Number.isSafeInteger(firstId) || firstId < sourceFileCount) {
16
+ throw new RangeError("Invalid residency page ID range.");
17
+ }
18
+ const byFile = new Map();
19
+ const invalid = new Set();
20
+ const invalidFiles = [];
21
+ const seen = new Set();
22
+ for (const entry of entries) {
23
+ if (seen.has(entry)) {
24
+ continue;
25
+ }
26
+ seen.add(entry);
27
+ const file = entry.file;
28
+ if (!Number.isSafeInteger(file) || file < 0 || file >= sourceFileCount) {
29
+ if (!invalid.has(file)) {
30
+ invalid.add(file);
31
+ invalidFiles.push(file);
32
+ }
33
+ continue;
34
+ }
35
+ if (pinned.has(file)) {
36
+ continue;
37
+ }
38
+ const size = counts.get(file);
39
+ if (size === undefined) {
40
+ continue;
41
+ }
42
+ if (!Number.isSafeInteger(size) ||
43
+ size < 0 ||
44
+ !Number.isSafeInteger(entry.offset) ||
45
+ entry.offset < 0 ||
46
+ !Number.isSafeInteger(entry.count) ||
47
+ entry.count < 0 ||
48
+ entry.offset + entry.count > size) {
49
+ if (!invalid.has(file)) {
50
+ invalid.add(file);
51
+ invalidFiles.push(file);
52
+ }
53
+ continue;
54
+ }
55
+ if (entry.count === 0) {
56
+ continue;
57
+ }
58
+ let ranges = byFile.get(file);
59
+ if (!ranges) {
60
+ ranges = [];
61
+ byFile.set(file, ranges);
62
+ }
63
+ ranges.push(entry);
64
+ }
65
+ const pages = [];
66
+ for (const [file, ranges] of byFile) {
67
+ if (invalid.has(file)) {
68
+ continue;
69
+ }
70
+ ranges.sort((a, b) => a.offset - b.offset || a.count - b.count);
71
+ let page;
72
+ for (const entry of ranges) {
73
+ if (page && entry.offset < page.source.offset + page.source.count) {
74
+ page.source = {
75
+ file,
76
+ offset: page.source.offset,
77
+ count: Math.max(page.source.offset + page.source.count, entry.offset + entry.count) - page.source.offset,
78
+ };
79
+ page.entries.push(entry);
80
+ }
81
+ else {
82
+ const id = firstId + pages.length;
83
+ if (!Number.isSafeInteger(id)) {
84
+ throw new RangeError("Residency page ID overflow.");
85
+ }
86
+ page = { id, source: { file, offset: entry.offset, count: entry.count }, entries: [entry] };
87
+ pages.push(page);
88
+ }
89
+ }
90
+ }
91
+ return { pages, invalidFiles };
92
+ }
93
+ //# sourceMappingURL=gaussianSplattingResidencyPages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gaussianSplattingResidencyPages.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/gaussianSplattingResidencyPages.ts"],"names":[],"mappings":"AAuCA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,wBAAwB,CACpC,OAAwC,EACxC,MAAmC,EACnC,MAA2B,EAC3B,eAAuB,EACvB,OAAe;IAEf,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,eAAe,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,eAAe,EAAE,CAAC;QAC/H,MAAM,IAAI,UAAU,CAAC,kCAAkC,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkC,CAAC;IACzD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC7C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAClB,SAAS;QACb,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IA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BAA6B,CAAC,CAAC;gBACxD,CAAC;gBACD,IAAI,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5F,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { type IGaussianSplattingStreamSourceRange } from \"./gaussianSplattingStream\";\r\n\r\n/**\r\n * A LOD entry referencing an interval of a source file. Structurally an ISOGLODEntry.\r\n * @internal\r\n */\r\nexport interface ISplatResidencyEntry {\r\n /** Index of the source file. */\r\n file: number;\r\n /** First splat of the interval inside the source file. */\r\n offset: number;\r\n /** Number of splats in the interval. */\r\n count: number;\r\n}\r\n\r\n/**\r\n * One resident allocation unit carved from a source file.\r\n * @internal\r\n */\r\nexport interface ISplatResidencyPage {\r\n /** Allocation ID, never lower than the number of source files. */\r\n id: number;\r\n /** Merged source interval covered by the page. */\r\n source: Readonly<IGaussianSplattingStreamSourceRange>;\r\n /** LOD entries (by reference) that fall inside the source interval. */\r\n entries: ISplatResidencyEntry[];\r\n}\r\n\r\n/**\r\n * Result of {@link BuildSplatResidencyPages}.\r\n * @internal\r\n */\r\nexport interface ISplatResidencyPagesResult {\r\n /** Pages to publish. */\r\n pages: ISplatResidencyPage[];\r\n /** Source files left whole because at least one of their entries was invalid. */\r\n invalidFiles: number[];\r\n}\r\n\r\n/**\r\n * Groups overlapping intervals, but not adjacent ones, into independently resident pages.\r\n * Does not mutate entries; callers publish the mapping once the pages are returned.\r\n * Pinned source files remain whole so the permanent fallback cannot be partially evicted.\r\n * A source file with no known size, or with at least one invalid interval, produces no pages and stays whole.\r\n * @param entries LOD entries referenced by leaves\r\n * @param counts splat count of every source file whose metadata is available\r\n * @param pinned source files that must stay whole\r\n * @param sourceFileCount number of source files; valid source IDs are in [0, sourceFileCount)\r\n * @param firstId first unused allocation ID, at least sourceFileCount\r\n * @returns the pages plus the source files left whole because of invalid intervals\r\n * @internal\r\n */\r\nexport function BuildSplatResidencyPages(\r\n entries: readonly ISplatResidencyEntry[],\r\n counts: ReadonlyMap<number, number>,\r\n pinned: ReadonlySet<number>,\r\n sourceFileCount: number,\r\n firstId: number\r\n): ISplatResidencyPagesResult {\r\n if (!Number.isSafeInteger(sourceFileCount) || sourceFileCount < 0 || !Number.isSafeInteger(firstId) || firstId < sourceFileCount) {\r\n throw new RangeError(\"Invalid residency page ID range.\");\r\n }\r\n const byFile = new Map<number, ISplatResidencyEntry[]>();\r\n const invalid = new Set<number>();\r\n const invalidFiles: number[] = [];\r\n const seen = new Set<ISplatResidencyEntry>();\r\n for (const entry of entries) {\r\n if (seen.has(entry)) {\r\n continue;\r\n }\r\n seen.add(entry);\r\n const file = entry.file;\r\n if (!Number.isSafeInteger(file) || file < 0 || file >= sourceFileCount) {\r\n if (!invalid.has(file)) {\r\n invalid.add(file);\r\n invalidFiles.push(file);\r\n }\r\n continue;\r\n }\r\n if (pinned.has(file)) {\r\n continue;\r\n }\r\n const size = counts.get(file);\r\n if (size === undefined) {\r\n continue;\r\n }\r\n if (\r\n !Number.isSafeInteger(size) ||\r\n size < 0 ||\r\n !Number.isSafeInteger(entry.offset) ||\r\n entry.offset < 0 ||\r\n !Number.isSafeInteger(entry.count) ||\r\n entry.count < 0 ||\r\n entry.offset + entry.count > size\r\n ) {\r\n if (!invalid.has(file)) {\r\n invalid.add(file);\r\n invalidFiles.push(file);\r\n }\r\n continue;\r\n }\r\n if (entry.count === 0) {\r\n continue;\r\n }\r\n let ranges = byFile.get(file);\r\n if (!ranges) {\r\n ranges = [];\r\n byFile.set(file, ranges);\r\n }\r\n ranges.push(entry);\r\n }\r\n\r\n const pages: ISplatResidencyPage[] = [];\r\n for (const [file, ranges] of byFile) {\r\n if (invalid.has(file)) {\r\n continue;\r\n }\r\n ranges.sort((a, b) => a.offset - b.offset || a.count - b.count);\r\n let page: ISplatResidencyPage | undefined;\r\n for (const entry of ranges) {\r\n if (page && entry.offset < page.source.offset + page.source.count) {\r\n page.source = {\r\n file,\r\n offset: page.source.offset,\r\n count: Math.max(page.source.offset + page.source.count, entry.offset + entry.count) - page.source.offset,\r\n };\r\n page.entries.push(entry);\r\n } else {\r\n const id = firstId + pages.length;\r\n if (!Number.isSafeInteger(id)) {\r\n throw new RangeError(\"Residency page ID overflow.\");\r\n }\r\n page = { id, source: { file, offset: entry.offset, count: entry.count }, entries: [entry] };\r\n pages.push(page);\r\n }\r\n }\r\n }\r\n return { pages, invalidFiles };\r\n}\r\n"]}