@babylonjs/loaders 9.31.0 → 9.31.2

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
@@ -13,6 +13,7 @@ import { ParseSogMetaAsTextures } from "./sog.pure.js";
13
13
  import { GaussianSplattingWorkBuffer } from "./gaussianSplattingWorkBuffer.js";
14
14
  import { GaussianSplattingDownloadManager } from "./gaussianSplattingDownloadManager.js";
15
15
  import { GaussianSplattingResidencyController } from "./gaussianSplattingResidencyController.js";
16
+ import { BuildSplatResidencyPages } from "./gaussianSplattingResidencyPages.js";
16
17
  // tan(22.5deg): reference half-FOV for a 45-degree vertical FOV, used for FOV compensation (matches PlayCanvas).
17
18
  const RefTanHalfFov = Math.tan((22.5 * Math.PI) / 180);
18
19
  // Sentinel "file" ids for the residency controller's pinned (never-evicted) allocations.
@@ -102,6 +103,9 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
102
103
  // Validate before super registers the mesh with the scene, so invalid options leave no partial entity.
103
104
  const maxResidentSplats = GaussianSplattingStream._NormalizeResidentLimit(options.maxResidentSplats ?? 0, "maxResidentSplats", true);
104
105
  const memoryBudgetMb = GaussianSplattingStream._NormalizeResidentLimit(options.memoryBudgetMb ?? 0, "memoryBudgetMb", false);
106
+ if (options.rangePack && !options.rangeResidency) {
107
+ throw new Error("GaussianSplattingStream: rangePack requires rangeResidency.");
108
+ }
105
109
  super(name, null, scene, false);
106
110
  // Flat list of leaf nodes that carry renderable LOD entries (used by the LOD heuristic and debug).
107
111
  this._leafNodes = [];
@@ -155,10 +159,22 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
155
159
  this._readbackProbed = false;
156
160
  // Residency controller: owns the work-buffer slot allocator, per-file blocks, and eviction cooldowns.
157
161
  this._residency = null;
158
- // Splat count of each source file (learned from its metadata before allocation).
162
+ // Splat counts keyed by source file ID or residency page ID (source counts are learned from metadata).
159
163
  this._fileCounts = new Map();
160
- // Cached SOG metadata per file so on-demand decodes don't refetch the meta.json.
164
+ // Cached SOG metadata keyed by source file ID or residency page ID (pages share their source's metadata).
161
165
  this._fileMeta = new Map();
166
+ // Residency pages: page ID -> original source interval. Empty unless rangeResidency is enabled.
167
+ this._residencyPages = new Map();
168
+ // Resolved split packs per page (absent = the page decodes from its source pack). Resolved once, at page creation.
169
+ this._splitPacks = new Map();
170
+ this._nextPageId = 0;
171
+ // At most one cached source pack; source pages hold the decode gate while using it, so it cannot grow with the queue.
172
+ this._rangeSourcePack = null;
173
+ // Source whose cached pack is held by an active decode/readback, including after cancellation.
174
+ this._activeRangeSource = null;
175
+ this._rangeSourcePackLoads = 0;
176
+ this._rangeSourcePackReuses = 0;
177
+ this._rangeSplitPackLoads = 0;
162
178
  // Unique source files required by the coarsest entry of at least one leaf.
163
179
  this._baseFileIds = new Set();
164
180
  // Files whose splats have been fully GPU-decoded into the work buffer (render-safe).
@@ -246,7 +262,9 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
246
262
  this._partReadyResolve = null;
247
263
  this._partReadyReject = null;
248
264
  this._partReadySettled = false;
249
- this._metadata = metadata;
265
+ // Range residency rewrites LOD entries into pages, so it works on a copy of the caller's metadata.
266
+ this._metadata = options.rangeResidency ? GaussianSplattingStream._CloneLodMetadata(metadata) : metadata;
267
+ this._nextPageId = metadata.filenames.length;
250
268
  this._rootUrl = rootUrl;
251
269
  this._streamOptions = options;
252
270
  this._hostCompound = options.hostCompound ?? null;
@@ -336,7 +354,7 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
336
354
  });
337
355
  this._hostUnsubDispose = () => this._hostCompound.onDisposeObservable.remove(disposeObserver);
338
356
  }
339
- this._collectLodEntries(metadata.tree);
357
+ this._collectLodEntries(this._metadata.tree);
340
358
  if (options.debugDisplay) {
341
359
  this.debugDisplay = true;
342
360
  }
@@ -573,6 +591,83 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
573
591
  get lod0SplatCount() {
574
592
  return this._lod0SplatCount;
575
593
  }
594
+ /**
595
+ * The source interval represented by a residency page allocation.
596
+ * @param fileId allocation ID as used for LOD entries (a source file index or a page ID)
597
+ * @returns the page's source interval, or null when the ID is a whole source file or range residency is off
598
+ * @experimental
599
+ */
600
+ getSourceRange(fileId) {
601
+ return this._residencyPages.get(fileId) ?? null;
602
+ }
603
+ /**
604
+ * Whether a residency page loads from its own split pack, see {@link IGaussianSplattingStreamOptions.rangePack}.
605
+ * @param fileId allocation ID
606
+ * @returns true when the page downloads only its own textures
607
+ * @experimental
608
+ */
609
+ isSplitPage(fileId) {
610
+ return this._splitPacks.has(fileId);
611
+ }
612
+ /**
613
+ * Cancels in-flight residency page loads, e.g. pages that lost priority. Only pages currently loading are affected,
614
+ * queued pages are untouched. A split page's own downloads are aborted. A shared source download is aborted only
615
+ * when no other non-cancelled, non-split loading page of that source and no entry of `keepSources` still needs it.
616
+ * Cancelled pages that are still referenced by a node are re-queued at the end of the decode queue.
617
+ * @param files allocation IDs to cancel; whole-file IDs and IDs that are not loading are ignored
618
+ * @param keepSources source file indices whose download must be kept (e.g. needed by queued pages), defaults to none
619
+ * @experimental
620
+ */
621
+ cancelRangeLoads(files, keepSources = []) {
622
+ const sources = new Set();
623
+ for (const file of files) {
624
+ const source = this._residencyPages.get(file);
625
+ if (!source || !this._loadingFiles.has(file)) {
626
+ continue;
627
+ }
628
+ this._cancelledDecodes.add(file);
629
+ if (this._splitPacks.has(file)) {
630
+ // A split page downloads under its own ID and shares nothing with its siblings.
631
+ this._downloadManager.cancelGroup(file);
632
+ }
633
+ else {
634
+ sources.add(source.file);
635
+ }
636
+ }
637
+ if (sources.size === 0) {
638
+ return;
639
+ }
640
+ for (const keep of keepSources) {
641
+ sources.delete(keep);
642
+ }
643
+ for (const loading of this._loadingFiles) {
644
+ // Split siblings never use the source download, so only an uncancelled unsplit page keeps it.
645
+ if (this._cancelledDecodes.has(loading) || this._splitPacks.has(loading)) {
646
+ continue;
647
+ }
648
+ const source = this._residencyPages.get(loading);
649
+ if (source) {
650
+ sources.delete(source.file);
651
+ }
652
+ }
653
+ for (const source of sources) {
654
+ this._downloadManager.cancelGroup(source);
655
+ }
656
+ }
657
+ /**
658
+ * Range residency counters for diagnostics. A new object is created on each call, so avoid reading it every frame.
659
+ * @experimental
660
+ */
661
+ get rangeResidencyStats() {
662
+ return {
663
+ enabled: this._streamOptions.rangeResidency === true,
664
+ pages: this._residencyPages.size,
665
+ sourcePackLoads: this._rangeSourcePackLoads,
666
+ sourcePackReuses: this._rangeSourcePackReuses,
667
+ splitPackLoads: this._rangeSplitPackLoads,
668
+ cachedSourceSplats: this._rangeSourcePack?.pack.splatCount ?? 0,
669
+ };
670
+ }
576
671
  /**
577
672
  * Resolves the raw {@link splatBudget} option to a concrete cap: `undefined` ⇒ 0 (disabled), `"auto"` ⇒ a
578
673
  * device-tiered default, a positive number ⇒ itself (floored).
@@ -762,6 +857,9 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
762
857
  }
763
858
  this._clearDebugDisplay();
764
859
  this._downloadManager.dispose();
860
+ this._disposeRangeSourcePack();
861
+ this._splitPacks.clear();
862
+ this._residencyPages.clear();
765
863
  this._residency?.dispose();
766
864
  this._residency = null;
767
865
  this._workBuffer?.dispose();
@@ -1112,6 +1210,10 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1112
1210
  const entry = node.lods[key];
1113
1211
  const count = entry ? Math.floor(Number(entry.count)) : NaN;
1114
1212
  if (Number.isInteger(level) && String(level) === key && level >= 0 && level <= maxLevel && entry && Number.isFinite(count) && count > 0) {
1213
+ if (this._streamOptions.rangeResidency && (!Number.isSafeInteger(entry.file) || entry.file < 0 || entry.file >= this._metadata.filenames.length)) {
1214
+ Logger.Warn(`GaussianSplattingStream: invalid LOD file index ${entry.file}; skipping level ${level}.`);
1215
+ continue;
1216
+ }
1115
1217
  entry.count = count;
1116
1218
  levels.push(level);
1117
1219
  }
@@ -1447,8 +1549,9 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1447
1549
  return BytesPerResidentSplat + this._shTextureCount * 16 + (this._needsRotationScale ? rotBytes : 0);
1448
1550
  }
1449
1551
  /**
1450
- * Collects the unique set of source file indices referenced by any LOD of any leaf, sorted ascending.
1451
- * @returns sorted unique file indices
1552
+ * Collects sorted allocation IDs referenced by leaf LODs: source file IDs before range remapping, and
1553
+ * source file or residency page IDs afterwards.
1554
+ * @returns sorted unique allocation IDs
1452
1555
  */
1453
1556
  _collectAllFileIds() {
1454
1557
  const ids = new Set();
@@ -1589,8 +1692,174 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1589
1692
  // Packed-u32 SH textures: 16 SH scalar-bytes per texel, 3 channels per coefficient (matches ParseSogDatas).
1590
1693
  this._shTextureCount = Math.max(this._shTextureCount, Math.ceil((maxCoeffs * 3) / 16));
1591
1694
  }
1695
+ if (this._streamOptions.rangeResidency) {
1696
+ this._initializeResidencyPages(fileIds);
1697
+ }
1592
1698
  return envCount;
1593
1699
  }
1700
+ /**
1701
+ * Splits the gathered source files into residency pages sized to the LOD leaf intervals they serve, and rewrites
1702
+ * those leaf entries to point at the pages. Pinned coarse files, files without metadata and files with invalid
1703
+ * intervals stay whole.
1704
+ * @param fileIds source file indices whose metadata was just gathered
1705
+ */
1706
+ _initializeResidencyPages(fileIds) {
1707
+ const sources = new Set(fileIds);
1708
+ const entries = [];
1709
+ for (const node of this._leafNodes) {
1710
+ for (const level of node.availableLevels) {
1711
+ const entry = node.lods[String(level)];
1712
+ if (sources.has(entry.file)) {
1713
+ entries.push(entry);
1714
+ }
1715
+ }
1716
+ }
1717
+ const { pages, invalidFiles } = BuildSplatResidencyPages(entries, this._fileCounts, this._baseFileIds, this._metadata.filenames.length, this._nextPageId);
1718
+ for (const file of invalidFiles) {
1719
+ Logger.Warn(`GaussianSplattingStream: invalid LOD interval in file ${file}; keeping it as one resident file.`);
1720
+ }
1721
+ for (const page of pages) {
1722
+ const meta = this._fileMeta.get(page.source.file);
1723
+ this._fileMeta.set(page.id, meta);
1724
+ this._fileCounts.set(page.id, page.source.count);
1725
+ const source = Object.freeze({ ...page.source });
1726
+ this._residencyPages.set(page.id, source);
1727
+ const split = this._resolveSplitPack(page.id, source, meta.sogData);
1728
+ if (split) {
1729
+ this._splitPacks.set(page.id, split);
1730
+ }
1731
+ for (const entry of page.entries) {
1732
+ entry.file = page.id;
1733
+ entry.offset -= page.source.offset;
1734
+ }
1735
+ }
1736
+ this._nextPageId += pages.length;
1737
+ if (pages.length) {
1738
+ this._forceLodUpdate = true;
1739
+ }
1740
+ }
1741
+ /**
1742
+ * Asks the {@link IGaussianSplattingStreamOptions.rangePack} resolver for the split pack of one page.
1743
+ * @param pageId page allocation ID
1744
+ * @param source the page's source interval
1745
+ * @param sourceData SOG metadata of the page's source file
1746
+ * @returns the split pack, or null when the page decodes from its source pack
1747
+ */
1748
+ _resolveSplitPack(pageId, source, sourceData) {
1749
+ const resolve = this._streamOptions.rangePack;
1750
+ if (!resolve) {
1751
+ return null;
1752
+ }
1753
+ try {
1754
+ const split = resolve(source, sourceData);
1755
+ if (!split) {
1756
+ return null;
1757
+ }
1758
+ if (GaussianSplattingStream._GetSplatCount(split.sogData) !== source.count) {
1759
+ Logger.Warn(`GaussianSplattingStream: split pack for page ${pageId} does not hold ${source.count} splats; using the source pack.`);
1760
+ return null;
1761
+ }
1762
+ return split;
1763
+ }
1764
+ catch (e) {
1765
+ Logger.Warn(`GaussianSplattingStream: rangePack failed for page ${pageId}: ${e?.message ?? e}; using the source pack.`);
1766
+ return null;
1767
+ }
1768
+ }
1769
+ /**
1770
+ * Downloads every image of a pack through the download manager, then creates its textures. The cancellable
1771
+ * network phase completes before any GPU texture exists, so a cancelled or failed download cannot leave textures
1772
+ * allocated by sibling image promises behind.
1773
+ * @param meta SOG metadata and image URL prefix of the pack
1774
+ * @param groupId download group, so the downloads can be cancelled together
1775
+ * @returns the texture pack, or null when the stream was disposed meanwhile
1776
+ */
1777
+ async _loadPrefetchedPackAsync(meta, groupId) {
1778
+ const data = meta.sogData;
1779
+ const names = new Set([
1780
+ ...(data.means?.files ?? []),
1781
+ ...(data.scales?.files ?? []),
1782
+ ...(data.quats?.files ?? []),
1783
+ ...(data.sh0?.files ?? []),
1784
+ ...(data.shN?.files ?? []),
1785
+ ]);
1786
+ const files = new Map();
1787
+ await Promise.all(Array.from(names, async (name) => {
1788
+ files.set(name, new Uint8Array(await this._downloadManager.loadFileAsync(meta.subRootUrl + name, groupId)));
1789
+ }));
1790
+ if (this._disposed) {
1791
+ return null;
1792
+ }
1793
+ files.set("meta.json", new TextEncoder().encode(JSON.stringify(data)));
1794
+ const pack = (await ParseSogMetaAsTextures(files, "", this._scene, !this._useGpuPositionReadback)).sogTextures;
1795
+ if (!pack) {
1796
+ return null;
1797
+ }
1798
+ if (this._disposed) {
1799
+ GaussianSplattingStream._DisposePack(pack);
1800
+ return null;
1801
+ }
1802
+ return pack;
1803
+ }
1804
+ /**
1805
+ * Returns the cached source pack of a file, loading it (and dropping any other cached source pack) when needed.
1806
+ * @param file source file index
1807
+ * @param meta SOG metadata and image URL prefix of the source file
1808
+ * @returns the shared source pack, which the caller must not dispose
1809
+ */
1810
+ async _getRangeSourcePackAsync(file, meta) {
1811
+ if (this._rangeSourcePack?.file === file) {
1812
+ this._rangeSourcePackReuses++;
1813
+ return this._rangeSourcePack.pack;
1814
+ }
1815
+ this._disposeRangeSourcePack();
1816
+ const pack = await this._loadPrefetchedPackAsync(meta, file);
1817
+ if (!pack) {
1818
+ return null;
1819
+ }
1820
+ if (this._disposed) {
1821
+ GaussianSplattingStream._DisposePack(pack);
1822
+ return null;
1823
+ }
1824
+ this._rangeSourcePackLoads++;
1825
+ this._rangeSourcePack = { file, pack };
1826
+ return pack;
1827
+ }
1828
+ _disposeRangeSourcePack() {
1829
+ if (this._rangeSourcePack) {
1830
+ GaussianSplattingStream._DisposePack(this._rangeSourcePack.pack);
1831
+ this._rangeSourcePack = null;
1832
+ }
1833
+ }
1834
+ /**
1835
+ * Copies the parts of the LOD metadata a stream mutates (tree nodes and LOD entries), so a range-residency stream
1836
+ * can rewrite entries without affecting the caller's object or another stream built from it.
1837
+ * @param metadata caller metadata
1838
+ * @returns metadata sharing every field except a freshly copied tree
1839
+ */
1840
+ static _CloneLodMetadata(metadata) {
1841
+ return { ...metadata, tree: GaussianSplattingStream._CloneLodNode(metadata.tree) };
1842
+ }
1843
+ static _CloneLodNode(node) {
1844
+ const copy = {};
1845
+ if (node.bound) {
1846
+ copy.bound = {
1847
+ min: Array.isArray(node.bound.min) ? node.bound.min.slice() : node.bound.min,
1848
+ max: Array.isArray(node.bound.max) ? node.bound.max.slice() : node.bound.max,
1849
+ };
1850
+ }
1851
+ if (Array.isArray(node.children)) {
1852
+ copy.children = node.children.map((child) => GaussianSplattingStream._CloneLodNode(child));
1853
+ }
1854
+ if (node.lods) {
1855
+ copy.lods = {};
1856
+ for (const key of Object.keys(node.lods)) {
1857
+ const entry = node.lods[key];
1858
+ copy.lods[key] = entry && typeof entry === "object" ? { ...entry } : entry;
1859
+ }
1860
+ }
1861
+ return copy;
1862
+ }
1594
1863
  /**
1595
1864
  * Queues a file for on-demand decode if it isn't already decoded, in flight, or already queued.
1596
1865
  * @param fileId file index to decode
@@ -1725,9 +1994,10 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1725
1994
  * @param pack the parsed SOG pack (its `positions` is populated only on the CPU path)
1726
1995
  * @param base first splat index of the range in the work buffer
1727
1996
  * @param count number of splats in the range
1997
+ * @param sourceOffset first splat of the range inside the pack, defaults to 0
1728
1998
  * @returns whether positions were applied
1729
1999
  */
1730
- async _applyDecodedPositionsAsync(pack, base, count) {
2000
+ async _applyDecodedPositionsAsync(pack, base, count, sourceOffset = 0) {
1731
2001
  if (this._useGpuPositionReadback && this._workBuffer) {
1732
2002
  const positions = await this._workBuffer.readCentersRangeAsync(base, count);
1733
2003
  if (this._disposed) {
@@ -1739,7 +2009,7 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1739
2009
  }
1740
2010
  // Validated readback unexpectedly returned nothing; fall through to the (likely empty) CPU positions.
1741
2011
  }
1742
- const cpu = pack.positions.length >= count * 4 ? pack.positions.subarray(0, count * 4) : null;
2012
+ const cpu = pack.positions.length >= (sourceOffset + count) * 4 ? pack.positions.subarray(sourceOffset * 4, (sourceOffset + count) * 4) : null;
1743
2013
  if (!cpu || !this._splatPositions) {
1744
2014
  return false;
1745
2015
  }
@@ -1804,12 +2074,13 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1804
2074
  }
1805
2075
  }
1806
2076
  /**
1807
- * Loads one LOD source file as GPU textures, decodes it into its fixed work-buffer block, records its
1808
- * CPU centers for sorting, frees the source textures, then promotes any nodes that were waiting for it.
1809
- * Concurrent or repeat requests for the same file are ignored. If the file is cancelled mid-flight
2077
+ * Loads one LOD source file or residency page, decodes it into its work-buffer block, records CPU
2078
+ * centers for sorting, then promotes waiting nodes. Whole-file and split-page textures are freed
2079
+ * after decoding; unsplit pages can reuse a cached source pack until no page needs it.
2080
+ * Concurrent or repeat requests for the same allocation are ignored. If it is cancelled mid-flight
1810
2081
  * (because every node that wanted it retargeted), the decode bails cooperatively at the next checkpoint.
1811
- * @param fileId file index to decode
1812
- * @returns whether the file was decoded and published successfully
2082
+ * @param fileId source file or residency page allocation ID to decode
2083
+ * @returns whether the allocation was decoded and published successfully
1813
2084
  */
1814
2085
  async _decodeFileAsync(fileId) {
1815
2086
  if (this._decodedFiles.has(fileId)) {
@@ -1826,15 +2097,45 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1826
2097
  this._loadingFiles.add(fileId);
1827
2098
  this._cancelledDecodes.delete(fileId);
1828
2099
  let allocated = false;
2100
+ const source = this._residencyPages.get(fileId);
2101
+ const split = this._splitPacks.get(fileId);
2102
+ let releaseGate = null;
1829
2103
  try {
1830
- const parsed = await ParseSogMetaAsTextures(meta.sogData, meta.subRootUrl, this._scene, !this._useGpuPositionReadback, this._downloadManager, fileId);
1831
- const pack = parsed.sogTextures;
2104
+ let pack;
2105
+ // Whole-file and split packs are owned by this decode; the cached source pack is shared by all pages of its source.
2106
+ let ownsPack = true;
2107
+ if (split) {
2108
+ // A split page downloads under its own group, so it can be cancelled independently of its siblings.
2109
+ pack = await this._loadPrefetchedPackAsync(split, fileId);
2110
+ }
2111
+ else if (source) {
2112
+ // Source pages hold the decode gate from download through readback, one at a time, so the shared
2113
+ // source pack cannot grow with the queue. A split page takes the gate only to decode.
2114
+ releaseGate = await this._acquireDecodeGateAsync();
2115
+ if (this._disposed || this._cancelledDecodes.has(fileId)) {
2116
+ return false;
2117
+ }
2118
+ pack = await this._getRangeSourcePackAsync(source.file, meta);
2119
+ ownsPack = false;
2120
+ if (pack) {
2121
+ this._activeRangeSource = source.file;
2122
+ }
2123
+ }
2124
+ else {
2125
+ const parsed = await ParseSogMetaAsTextures(meta.sogData, meta.subRootUrl, this._scene, !this._useGpuPositionReadback, this._downloadManager, fileId);
2126
+ pack = parsed.sogTextures ?? null;
2127
+ }
1832
2128
  if (!pack) {
1833
2129
  return false;
1834
2130
  }
2131
+ if (split) {
2132
+ this._rangeSplitPackLoads++;
2133
+ }
2134
+ // A split page holds only its own interval, starting at row 0 of its pack.
2135
+ const sourceOffset = source && !split ? source.offset : 0;
1835
2136
  // Serialize the allocate -> decode -> readback section: a relayout runs only inside it (see
1836
2137
  // _relayoutAndAllocateAsync), so it never moves a file whose decode has not finished writing.
1837
- const release = await this._acquireDecodeGateAsync();
2138
+ releaseGate ?? (releaseGate = await this._acquireDecodeGateAsync());
1838
2139
  try {
1839
2140
  if (this._disposed || !this._workBuffer || this._cancelledDecodes.has(fileId)) {
1840
2141
  return false;
@@ -1860,12 +2161,17 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1860
2161
  if (this._disposed || !this._workBuffer || this._cancelledDecodes.has(fileId)) {
1861
2162
  return false;
1862
2163
  }
1863
- await this._workBuffer.decodeAsync(pack, base);
2164
+ if (source) {
2165
+ await this._workBuffer.decodeAsync(pack, base, sourceOffset, count);
2166
+ }
2167
+ else {
2168
+ await this._workBuffer.decodeAsync(pack, base);
2169
+ }
1864
2170
  if (this._disposed || this._cancelledDecodes.has(fileId)) {
1865
2171
  return false;
1866
2172
  }
1867
- const positionsApplied = await this._applyDecodedPositionsAsync(pack, base, count);
1868
- if (this._disposed) {
2173
+ const positionsApplied = await this._applyDecodedPositionsAsync(pack, base, count, sourceOffset);
2174
+ if (this._disposed || this._cancelledDecodes.has(fileId)) {
1869
2175
  return false;
1870
2176
  }
1871
2177
  if (!positionsApplied) {
@@ -1885,8 +2191,9 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1885
2191
  return true;
1886
2192
  }
1887
2193
  finally {
1888
- GaussianSplattingStream._DisposePack(pack);
1889
- release();
2194
+ if (ownsPack) {
2195
+ GaussianSplattingStream._DisposePack(pack);
2196
+ }
1890
2197
  }
1891
2198
  }
1892
2199
  catch (e) {
@@ -1897,12 +2204,21 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
1897
2204
  return false;
1898
2205
  }
1899
2206
  finally {
2207
+ if (source && !split && releaseGate) {
2208
+ this._activeRangeSource = null;
2209
+ }
2210
+ releaseGate?.();
1900
2211
  // If a slot was allocated but the decode did not complete (cancelled/disposed), release it.
1901
2212
  if (allocated && !this._decodedFiles.has(fileId)) {
1902
2213
  this._residency?.free(fileId);
1903
2214
  }
2215
+ const wasCancelled = this._cancelledDecodes.has(fileId);
1904
2216
  this._loadingFiles.delete(fileId);
1905
2217
  this._cancelledDecodes.delete(fileId);
2218
+ // A decode cancelled while a node still references the file would otherwise never be retried.
2219
+ if (wasCancelled && !this._disposed && (this._fileRefs.get(fileId) ?? 0) > 0) {
2220
+ this._enqueueDecode(fileId);
2221
+ }
1906
2222
  }
1907
2223
  }
1908
2224
  /**
@@ -2276,7 +2592,7 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
2276
2592
  }
2277
2593
  /**
2278
2594
  * Records that a node needs a not-yet-decoded file, bumping its reference count and queueing the decode.
2279
- * @param fileId file index the node now targets
2595
+ * @param fileId source file or residency page allocation ID the node now targets
2280
2596
  */
2281
2597
  _acquirePendingFile(fileId) {
2282
2598
  this._acquireFileRef(fileId);
@@ -2286,7 +2602,7 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
2286
2602
  * Releases a node's reference to a file. When the last reference is dropped: a decoded file is scheduled
2287
2603
  * for eviction (when streaming under a budget), and a still-downloading file has its queued decode dropped
2288
2604
  * and any in-flight download cancelled.
2289
- * @param fileId file index the node no longer references
2605
+ * @param fileId source file or residency page allocation ID the node no longer references
2290
2606
  */
2291
2607
  _releaseFileRef(fileId) {
2292
2608
  const refs = (this._fileRefs.get(fileId) ?? 0) - 1;
@@ -2309,8 +2625,51 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
2309
2625
  }
2310
2626
  if (this._loadingFiles.has(fileId)) {
2311
2627
  // Flag the in-flight decode to bail at its next checkpoint and cancel its image downloads.
2312
- this._cancelledDecodes.add(fileId);
2313
- this._downloadManager.cancelGroup(fileId);
2628
+ const source = this._residencyPages.get(fileId);
2629
+ if (source) {
2630
+ let hasQueuedSibling = false;
2631
+ for (const queued of this._decodeQueue) {
2632
+ if (!this._splitPacks.has(queued) && this._residencyPages.get(queued)?.file === source.file) {
2633
+ hasQueuedSibling = true;
2634
+ break;
2635
+ }
2636
+ }
2637
+ this.cancelRangeLoads([fileId], hasQueuedSibling ? [source.file] : []);
2638
+ }
2639
+ else {
2640
+ this._cancelledDecodes.add(fileId);
2641
+ this._downloadManager.cancelGroup(fileId);
2642
+ }
2643
+ }
2644
+ else if (queueIndex !== -1) {
2645
+ const source = this._residencyPages.get(fileId);
2646
+ if (source && !this._splitPacks.has(fileId)) {
2647
+ let hasLiveConsumer = false;
2648
+ let hasCancelledLoader = false;
2649
+ for (const loading of this._loadingFiles) {
2650
+ if (this._splitPacks.has(loading) || this._residencyPages.get(loading)?.file !== source.file) {
2651
+ continue;
2652
+ }
2653
+ if (this._cancelledDecodes.has(loading)) {
2654
+ hasCancelledLoader = true;
2655
+ }
2656
+ else {
2657
+ hasLiveConsumer = true;
2658
+ break;
2659
+ }
2660
+ }
2661
+ if (hasCancelledLoader && !hasLiveConsumer) {
2662
+ for (const queued of this._decodeQueue) {
2663
+ if (!this._splitPacks.has(queued) && this._residencyPages.get(queued)?.file === source.file) {
2664
+ hasLiveConsumer = true;
2665
+ break;
2666
+ }
2667
+ }
2668
+ if (!hasLiveConsumer) {
2669
+ this._downloadManager.cancelGroup(source.file);
2670
+ }
2671
+ }
2672
+ }
2314
2673
  }
2315
2674
  }
2316
2675
  /**
@@ -2331,6 +2690,29 @@ export class GaussianSplattingStream extends GaussianSplattingMesh {
2331
2690
  if (this._disposed || !this._baseLayerReady) {
2332
2691
  return;
2333
2692
  }
2693
+ if (this._rangeSourcePack) {
2694
+ const sourceFile = this._rangeSourcePack.file;
2695
+ let needed = this._activeRangeSource === sourceFile;
2696
+ if (!needed) {
2697
+ for (const file of this._loadingFiles) {
2698
+ if (!this._cancelledDecodes.has(file) && !this._splitPacks.has(file) && this._residencyPages.get(file)?.file === sourceFile) {
2699
+ needed = true;
2700
+ break;
2701
+ }
2702
+ }
2703
+ }
2704
+ if (!needed) {
2705
+ for (const file of this._decodeQueue) {
2706
+ if (!this._splitPacks.has(file) && this._residencyPages.get(file)?.file === sourceFile) {
2707
+ needed = true;
2708
+ break;
2709
+ }
2710
+ }
2711
+ }
2712
+ if (!needed) {
2713
+ this._disposeRangeSourcePack();
2714
+ }
2715
+ }
2334
2716
  let cooldownExpiredWithPendingSwitch = false;
2335
2717
  for (const node of this._leafNodes) {
2336
2718
  if (node.lodCooldown && node.lodCooldown > 0) {