@onerjs/loaders 8.53.5 → 8.53.7

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 (517) hide show
  1. package/BVH/bvhFileLoader.d.ts +4 -67
  2. package/BVH/bvhFileLoader.js +6 -130
  3. package/BVH/bvhFileLoader.js.map +1 -1
  4. package/BVH/bvhFileLoader.pure.d.ts +75 -0
  5. package/BVH/bvhFileLoader.pure.js +154 -0
  6. package/BVH/bvhFileLoader.pure.js.map +1 -0
  7. package/BVH/bvhFileLoader.types.d.ts +11 -0
  8. package/BVH/bvhFileLoader.types.js +2 -0
  9. package/BVH/bvhFileLoader.types.js.map +1 -0
  10. package/BVH/pure.d.ts +3 -0
  11. package/BVH/pure.js +5 -0
  12. package/BVH/pure.js.map +1 -0
  13. package/FBX/fbxFileLoader.d.ts +4 -192
  14. package/FBX/fbxFileLoader.js +6 -2437
  15. package/FBX/fbxFileLoader.js.map +1 -1
  16. package/FBX/fbxFileLoader.pure.d.ts +190 -0
  17. package/FBX/fbxFileLoader.pure.js +2451 -0
  18. package/FBX/fbxFileLoader.pure.js.map +1 -0
  19. package/FBX/fbxFileLoader.types.d.ts +11 -0
  20. package/FBX/fbxFileLoader.types.js +2 -0
  21. package/FBX/fbxFileLoader.types.js.map +1 -0
  22. package/FBX/pure.d.ts +3 -0
  23. package/FBX/pure.js +4 -0
  24. package/FBX/pure.js.map +1 -0
  25. package/OBJ/objFileLoader.d.ts +4 -134
  26. package/OBJ/objFileLoader.js +6 -315
  27. package/OBJ/objFileLoader.js.map +1 -1
  28. package/OBJ/objFileLoader.pure.d.ts +132 -0
  29. package/OBJ/objFileLoader.pure.js +329 -0
  30. package/OBJ/objFileLoader.pure.js.map +1 -0
  31. package/OBJ/objFileLoader.types.d.ts +11 -0
  32. package/OBJ/objFileLoader.types.js +2 -0
  33. package/OBJ/objFileLoader.types.js.map +1 -0
  34. package/OBJ/pure.d.ts +5 -0
  35. package/OBJ/pure.js +6 -0
  36. package/OBJ/pure.js.map +1 -0
  37. package/OBJ/solidParser.js +4 -3
  38. package/OBJ/solidParser.js.map +1 -1
  39. package/SPLAT/gaussianSplattingBlockAllocator.d.ts +137 -0
  40. package/SPLAT/gaussianSplattingBlockAllocator.js +555 -0
  41. package/SPLAT/gaussianSplattingBlockAllocator.js.map +1 -0
  42. package/SPLAT/gaussianSplattingDownloadManager.d.ts +109 -0
  43. package/SPLAT/gaussianSplattingDownloadManager.js +241 -0
  44. package/SPLAT/gaussianSplattingDownloadManager.js.map +1 -0
  45. package/SPLAT/gaussianSplattingResidencyController.d.ts +133 -0
  46. package/SPLAT/gaussianSplattingResidencyController.js +222 -0
  47. package/SPLAT/gaussianSplattingResidencyController.js.map +1 -0
  48. package/SPLAT/gaussianSplattingStream.d.ts +522 -0
  49. package/SPLAT/gaussianSplattingStream.js +1530 -0
  50. package/SPLAT/gaussianSplattingStream.js.map +1 -0
  51. package/SPLAT/gaussianSplattingWorkBuffer.d.ts +107 -0
  52. package/SPLAT/gaussianSplattingWorkBuffer.js +361 -0
  53. package/SPLAT/gaussianSplattingWorkBuffer.js.map +1 -0
  54. package/SPLAT/gaussianSplattingWorkBufferShaders.d.ts +40 -0
  55. package/SPLAT/gaussianSplattingWorkBufferShaders.js +337 -0
  56. package/SPLAT/gaussianSplattingWorkBufferShaders.js.map +1 -0
  57. package/SPLAT/index.d.ts +1 -0
  58. package/SPLAT/index.js +1 -0
  59. package/SPLAT/index.js.map +1 -1
  60. package/SPLAT/pure.d.ts +5 -0
  61. package/SPLAT/pure.js +7 -0
  62. package/SPLAT/pure.js.map +1 -0
  63. package/SPLAT/sog.d.ts +2 -93
  64. package/SPLAT/sog.js +4 -418
  65. package/SPLAT/sog.js.map +1 -1
  66. package/SPLAT/sog.pure.d.ts +102 -0
  67. package/SPLAT/sog.pure.js +514 -0
  68. package/SPLAT/sog.pure.js.map +1 -0
  69. package/SPLAT/splatFileLoader.d.ts +5 -98
  70. package/SPLAT/splatFileLoader.js +9 -587
  71. package/SPLAT/splatFileLoader.js.map +1 -1
  72. package/SPLAT/splatFileLoader.pure.d.ts +104 -0
  73. package/SPLAT/splatFileLoader.pure.js +650 -0
  74. package/SPLAT/splatFileLoader.pure.js.map +1 -0
  75. package/SPLAT/splatFileLoader.types.d.ts +11 -0
  76. package/SPLAT/splatFileLoader.types.js +2 -0
  77. package/SPLAT/splatFileLoader.types.js.map +1 -0
  78. package/STL/pure.d.ts +2 -0
  79. package/STL/pure.js +3 -0
  80. package/STL/pure.js.map +1 -0
  81. package/STL/stlFileLoader.d.ts +5 -76
  82. package/STL/stlFileLoader.js +7 -236
  83. package/STL/stlFileLoader.js.map +1 -1
  84. package/STL/stlFileLoader.pure.d.ts +73 -0
  85. package/STL/stlFileLoader.pure.js +249 -0
  86. package/STL/stlFileLoader.pure.js.map +1 -0
  87. package/STL/stlFileLoader.types.d.ts +10 -0
  88. package/STL/stlFileLoader.types.js +2 -0
  89. package/STL/stlFileLoader.types.js.map +1 -0
  90. package/glTF/1.0/pure.d.ts +3 -0
  91. package/glTF/1.0/pure.js +4 -0
  92. package/glTF/1.0/pure.js.map +1 -0
  93. package/glTF/2.0/Extensions/EXT_lights_area.d.ts +4 -39
  94. package/glTF/2.0/Extensions/EXT_lights_area.js +6 -91
  95. package/glTF/2.0/Extensions/EXT_lights_area.js.map +1 -1
  96. package/glTF/2.0/Extensions/EXT_lights_area.pure.d.ts +38 -0
  97. package/glTF/2.0/Extensions/EXT_lights_area.pure.js +106 -0
  98. package/glTF/2.0/Extensions/EXT_lights_area.pure.js.map +1 -0
  99. package/glTF/2.0/Extensions/EXT_lights_area.types.d.ts +9 -0
  100. package/glTF/2.0/Extensions/EXT_lights_area.types.js +2 -0
  101. package/glTF/2.0/Extensions/EXT_lights_area.types.js.map +1 -0
  102. package/glTF/2.0/Extensions/EXT_lights_ies.d.ts +4 -39
  103. package/glTF/2.0/Extensions/EXT_lights_ies.js +6 -81
  104. package/glTF/2.0/Extensions/EXT_lights_ies.js.map +1 -1
  105. package/glTF/2.0/Extensions/EXT_lights_ies.pure.d.ts +38 -0
  106. package/glTF/2.0/Extensions/EXT_lights_ies.pure.js +96 -0
  107. package/glTF/2.0/Extensions/EXT_lights_ies.pure.js.map +1 -0
  108. package/glTF/2.0/Extensions/EXT_lights_ies.types.d.ts +9 -0
  109. package/glTF/2.0/Extensions/EXT_lights_ies.types.js +2 -0
  110. package/glTF/2.0/Extensions/EXT_lights_ies.types.js.map +1 -0
  111. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +4 -46
  112. package/glTF/2.0/Extensions/EXT_lights_image_based.js +6 -113
  113. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  114. package/glTF/2.0/Extensions/EXT_lights_image_based.pure.d.ts +37 -0
  115. package/glTF/2.0/Extensions/EXT_lights_image_based.pure.js +128 -0
  116. package/glTF/2.0/Extensions/EXT_lights_image_based.pure.js.map +1 -0
  117. package/glTF/2.0/Extensions/EXT_lights_image_based.types.d.ts +17 -0
  118. package/glTF/2.0/Extensions/EXT_lights_image_based.types.js +2 -0
  119. package/glTF/2.0/Extensions/EXT_lights_image_based.types.js.map +1 -0
  120. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +5 -37
  121. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +7 -92
  122. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  123. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.d.ts +35 -0
  124. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js +106 -0
  125. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js.map +1 -0
  126. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.types.d.ts +9 -0
  127. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.types.js +2 -0
  128. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.types.js.map +1 -0
  129. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +4 -37
  130. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +6 -48
  131. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  132. package/glTF/2.0/Extensions/EXT_meshopt_compression.pure.d.ts +36 -0
  133. package/glTF/2.0/Extensions/EXT_meshopt_compression.pure.js +63 -0
  134. package/glTF/2.0/Extensions/EXT_meshopt_compression.pure.js.map +1 -0
  135. package/glTF/2.0/Extensions/EXT_meshopt_compression.types.d.ts +9 -0
  136. package/glTF/2.0/Extensions/EXT_meshopt_compression.types.js +2 -0
  137. package/glTF/2.0/Extensions/EXT_meshopt_compression.types.js.map +1 -0
  138. package/glTF/2.0/Extensions/EXT_texture_avif.d.ts +4 -32
  139. package/glTF/2.0/Extensions/EXT_texture_avif.js +6 -36
  140. package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -1
  141. package/glTF/2.0/Extensions/EXT_texture_avif.pure.d.ts +31 -0
  142. package/glTF/2.0/Extensions/EXT_texture_avif.pure.js +51 -0
  143. package/glTF/2.0/Extensions/EXT_texture_avif.pure.js.map +1 -0
  144. package/glTF/2.0/Extensions/EXT_texture_avif.types.d.ts +9 -0
  145. package/glTF/2.0/Extensions/EXT_texture_avif.types.js +2 -0
  146. package/glTF/2.0/Extensions/EXT_texture_avif.types.js.map +1 -0
  147. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +4 -31
  148. package/glTF/2.0/Extensions/EXT_texture_webp.js +6 -35
  149. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  150. package/glTF/2.0/Extensions/EXT_texture_webp.pure.d.ts +30 -0
  151. package/glTF/2.0/Extensions/EXT_texture_webp.pure.js +50 -0
  152. package/glTF/2.0/Extensions/EXT_texture_webp.pure.js.map +1 -0
  153. package/glTF/2.0/Extensions/EXT_texture_webp.types.d.ts +9 -0
  154. package/glTF/2.0/Extensions/EXT_texture_webp.types.js +2 -0
  155. package/glTF/2.0/Extensions/EXT_texture_webp.types.js.map +1 -0
  156. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +4 -51
  157. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +6 -71
  158. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  159. package/glTF/2.0/Extensions/ExtrasAsMetadata.pure.d.ts +50 -0
  160. package/glTF/2.0/Extensions/ExtrasAsMetadata.pure.js +85 -0
  161. package/glTF/2.0/Extensions/ExtrasAsMetadata.pure.js.map +1 -0
  162. package/glTF/2.0/Extensions/ExtrasAsMetadata.types.d.ts +9 -0
  163. package/glTF/2.0/Extensions/ExtrasAsMetadata.types.js +2 -0
  164. package/glTF/2.0/Extensions/ExtrasAsMetadata.types.js.map +1 -0
  165. package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +5 -45
  166. package/glTF/2.0/Extensions/KHR_animation_pointer.js +7 -75
  167. package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
  168. package/glTF/2.0/Extensions/KHR_animation_pointer.pure.d.ts +43 -0
  169. package/glTF/2.0/Extensions/KHR_animation_pointer.pure.js +89 -0
  170. package/glTF/2.0/Extensions/KHR_animation_pointer.pure.js.map +1 -0
  171. package/glTF/2.0/Extensions/KHR_animation_pointer.types.d.ts +9 -0
  172. package/glTF/2.0/Extensions/KHR_animation_pointer.types.js +2 -0
  173. package/glTF/2.0/Extensions/KHR_animation_pointer.types.js.map +1 -0
  174. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +4 -45
  175. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +6 -90
  176. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  177. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.d.ts +44 -0
  178. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js +105 -0
  179. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js.map +1 -0
  180. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.types.d.ts +9 -0
  181. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.types.js +2 -0
  182. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.types.js.map +1 -0
  183. package/glTF/2.0/Extensions/KHR_gaussian_splatting.d.ts +6 -0
  184. package/glTF/2.0/Extensions/KHR_gaussian_splatting.js +9 -0
  185. package/glTF/2.0/Extensions/KHR_gaussian_splatting.js.map +1 -0
  186. package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.d.ts +35 -0
  187. package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.js +195 -0
  188. package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.js.map +1 -0
  189. package/glTF/2.0/Extensions/KHR_gaussian_splatting.types.d.ts +9 -0
  190. package/glTF/2.0/Extensions/KHR_gaussian_splatting.types.js +2 -0
  191. package/glTF/2.0/Extensions/KHR_gaussian_splatting.types.js.map +1 -0
  192. package/glTF/2.0/Extensions/KHR_interactivity/pure.d.ts +4 -0
  193. package/glTF/2.0/Extensions/KHR_interactivity/pure.js +5 -0
  194. package/glTF/2.0/Extensions/KHR_interactivity/pure.js.map +1 -0
  195. package/glTF/2.0/Extensions/KHR_interactivity.d.ts +4 -36
  196. package/glTF/2.0/Extensions/KHR_interactivity.js +6 -148
  197. package/glTF/2.0/Extensions/KHR_interactivity.js.map +1 -1
  198. package/glTF/2.0/Extensions/KHR_interactivity.pure.d.ts +35 -0
  199. package/glTF/2.0/Extensions/KHR_interactivity.pure.js +163 -0
  200. package/glTF/2.0/Extensions/KHR_interactivity.pure.js.map +1 -0
  201. package/glTF/2.0/Extensions/KHR_interactivity.types.d.ts +9 -0
  202. package/glTF/2.0/Extensions/KHR_interactivity.types.js +2 -0
  203. package/glTF/2.0/Extensions/KHR_interactivity.types.js.map +1 -0
  204. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +4 -39
  205. package/glTF/2.0/Extensions/KHR_lights_punctual.js +6 -89
  206. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  207. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.d.ts +38 -0
  208. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js +104 -0
  209. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js.map +1 -0
  210. package/glTF/2.0/Extensions/KHR_lights_punctual.types.d.ts +9 -0
  211. package/glTF/2.0/Extensions/KHR_lights_punctual.types.js +2 -0
  212. package/glTF/2.0/Extensions/KHR_lights_punctual.types.js.map +1 -0
  213. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +4 -40
  214. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +6 -63
  215. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  216. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.d.ts +39 -0
  217. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js +78 -0
  218. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js.map +1 -0
  219. package/glTF/2.0/Extensions/KHR_materials_anisotropy.types.d.ts +9 -0
  220. package/glTF/2.0/Extensions/KHR_materials_anisotropy.types.js +2 -0
  221. package/glTF/2.0/Extensions/KHR_materials_anisotropy.types.js.map +1 -0
  222. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +4 -41
  223. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +6 -77
  224. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  225. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.d.ts +40 -0
  226. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js +92 -0
  227. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js.map +1 -0
  228. package/glTF/2.0/Extensions/KHR_materials_clearcoat.types.d.ts +9 -0
  229. package/glTF/2.0/Extensions/KHR_materials_clearcoat.types.js +2 -0
  230. package/glTF/2.0/Extensions/KHR_materials_clearcoat.types.js.map +1 -0
  231. package/glTF/2.0/Extensions/KHR_materials_coat.d.ts +4 -47
  232. package/glTF/2.0/Extensions/KHR_materials_coat.js +6 -117
  233. package/glTF/2.0/Extensions/KHR_materials_coat.js.map +1 -1
  234. package/glTF/2.0/Extensions/KHR_materials_coat.pure.d.ts +46 -0
  235. package/glTF/2.0/Extensions/KHR_materials_coat.pure.js +132 -0
  236. package/glTF/2.0/Extensions/KHR_materials_coat.pure.js.map +1 -0
  237. package/glTF/2.0/Extensions/KHR_materials_coat.types.d.ts +9 -0
  238. package/glTF/2.0/Extensions/KHR_materials_coat.types.js +2 -0
  239. package/glTF/2.0/Extensions/KHR_materials_coat.types.js.map +1 -0
  240. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.d.ts +4 -41
  241. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js +6 -56
  242. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js.map +1 -1
  243. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.d.ts +40 -0
  244. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js +71 -0
  245. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js.map +1 -0
  246. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.types.d.ts +9 -0
  247. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.types.js +2 -0
  248. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.types.js.map +1 -0
  249. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +4 -41
  250. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +6 -71
  251. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
  252. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.d.ts +40 -0
  253. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js +86 -0
  254. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js.map +1 -0
  255. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.types.d.ts +9 -0
  256. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.types.js +2 -0
  257. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.types.js.map +1 -0
  258. package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +4 -41
  259. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +6 -54
  260. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
  261. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.d.ts +40 -0
  262. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js +69 -0
  263. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js.map +1 -0
  264. package/glTF/2.0/Extensions/KHR_materials_dispersion.types.d.ts +9 -0
  265. package/glTF/2.0/Extensions/KHR_materials_dispersion.types.js +2 -0
  266. package/glTF/2.0/Extensions/KHR_materials_dispersion.types.js.map +1 -0
  267. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +4 -40
  268. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +6 -45
  269. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  270. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.d.ts +39 -0
  271. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js +60 -0
  272. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js.map +1 -0
  273. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.types.d.ts +9 -0
  274. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.types.js +2 -0
  275. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.types.js.map +1 -0
  276. package/glTF/2.0/Extensions/KHR_materials_fuzz.d.ts +4 -41
  277. package/glTF/2.0/Extensions/KHR_materials_fuzz.js +6 -75
  278. package/glTF/2.0/Extensions/KHR_materials_fuzz.js.map +1 -1
  279. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.d.ts +40 -0
  280. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js +90 -0
  281. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js.map +1 -0
  282. package/glTF/2.0/Extensions/KHR_materials_fuzz.types.d.ts +9 -0
  283. package/glTF/2.0/Extensions/KHR_materials_fuzz.types.js +2 -0
  284. package/glTF/2.0/Extensions/KHR_materials_fuzz.types.js.map +1 -0
  285. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +4 -44
  286. package/glTF/2.0/Extensions/KHR_materials_ior.js +6 -52
  287. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  288. package/glTF/2.0/Extensions/KHR_materials_ior.pure.d.ts +43 -0
  289. package/glTF/2.0/Extensions/KHR_materials_ior.pure.js +67 -0
  290. package/glTF/2.0/Extensions/KHR_materials_ior.pure.js.map +1 -0
  291. package/glTF/2.0/Extensions/KHR_materials_ior.types.d.ts +9 -0
  292. package/glTF/2.0/Extensions/KHR_materials_ior.types.js +2 -0
  293. package/glTF/2.0/Extensions/KHR_materials_ior.types.js.map +1 -0
  294. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +4 -40
  295. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +6 -66
  296. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
  297. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.d.ts +39 -0
  298. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js +81 -0
  299. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js.map +1 -0
  300. package/glTF/2.0/Extensions/KHR_materials_iridescence.types.d.ts +9 -0
  301. package/glTF/2.0/Extensions/KHR_materials_iridescence.types.js +2 -0
  302. package/glTF/2.0/Extensions/KHR_materials_iridescence.types.js.map +1 -0
  303. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +4 -40
  304. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +6 -72
  305. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  306. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.pure.d.ts +39 -0
  307. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.pure.js +87 -0
  308. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.pure.js.map +1 -0
  309. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.types.d.ts +9 -0
  310. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.types.js +2 -0
  311. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.types.js.map +1 -0
  312. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +4 -41
  313. package/glTF/2.0/Extensions/KHR_materials_sheen.js +6 -71
  314. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  315. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.d.ts +40 -0
  316. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js +86 -0
  317. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js.map +1 -0
  318. package/glTF/2.0/Extensions/KHR_materials_sheen.types.d.ts +9 -0
  319. package/glTF/2.0/Extensions/KHR_materials_sheen.types.js +2 -0
  320. package/glTF/2.0/Extensions/KHR_materials_sheen.types.js.map +1 -0
  321. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +4 -40
  322. package/glTF/2.0/Extensions/KHR_materials_specular.js +6 -74
  323. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  324. package/glTF/2.0/Extensions/KHR_materials_specular.pure.d.ts +39 -0
  325. package/glTF/2.0/Extensions/KHR_materials_specular.pure.js +89 -0
  326. package/glTF/2.0/Extensions/KHR_materials_specular.pure.js.map +1 -0
  327. package/glTF/2.0/Extensions/KHR_materials_specular.types.d.ts +9 -0
  328. package/glTF/2.0/Extensions/KHR_materials_specular.types.js +2 -0
  329. package/glTF/2.0/Extensions/KHR_materials_specular.types.js.map +1 -0
  330. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +4 -40
  331. package/glTF/2.0/Extensions/KHR_materials_transmission.js +6 -70
  332. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  333. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.d.ts +39 -0
  334. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js +85 -0
  335. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js.map +1 -0
  336. package/glTF/2.0/Extensions/KHR_materials_transmission.types.d.ts +9 -0
  337. package/glTF/2.0/Extensions/KHR_materials_transmission.types.js +2 -0
  338. package/glTF/2.0/Extensions/KHR_materials_transmission.types.js.map +1 -0
  339. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +4 -40
  340. package/glTF/2.0/Extensions/KHR_materials_unlit.js +6 -64
  341. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  342. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.d.ts +39 -0
  343. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js +79 -0
  344. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js.map +1 -0
  345. package/glTF/2.0/Extensions/KHR_materials_unlit.types.d.ts +9 -0
  346. package/glTF/2.0/Extensions/KHR_materials_unlit.types.js +2 -0
  347. package/glTF/2.0/Extensions/KHR_materials_unlit.types.js.map +1 -0
  348. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +4 -110
  349. package/glTF/2.0/Extensions/KHR_materials_variants.js +6 -260
  350. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  351. package/glTF/2.0/Extensions/KHR_materials_variants.pure.d.ts +97 -0
  352. package/glTF/2.0/Extensions/KHR_materials_variants.pure.js +275 -0
  353. package/glTF/2.0/Extensions/KHR_materials_variants.pure.js.map +1 -0
  354. package/glTF/2.0/Extensions/KHR_materials_variants.types.d.ts +29 -0
  355. package/glTF/2.0/Extensions/KHR_materials_variants.types.js +2 -0
  356. package/glTF/2.0/Extensions/KHR_materials_variants.types.js.map +1 -0
  357. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +4 -41
  358. package/glTF/2.0/Extensions/KHR_materials_volume.js +6 -77
  359. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  360. package/glTF/2.0/Extensions/KHR_materials_volume.pure.d.ts +40 -0
  361. package/glTF/2.0/Extensions/KHR_materials_volume.pure.js +92 -0
  362. package/glTF/2.0/Extensions/KHR_materials_volume.pure.js.map +1 -0
  363. package/glTF/2.0/Extensions/KHR_materials_volume.types.d.ts +9 -0
  364. package/glTF/2.0/Extensions/KHR_materials_volume.types.js +2 -0
  365. package/glTF/2.0/Extensions/KHR_materials_volume.types.js.map +1 -0
  366. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.d.ts +4 -43
  367. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js +6 -113
  368. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js.map +1 -1
  369. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.d.ts +42 -0
  370. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js +128 -0
  371. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js.map +1 -0
  372. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.types.d.ts +9 -0
  373. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.types.js +2 -0
  374. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.types.js.map +1 -0
  375. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +4 -27
  376. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +6 -20
  377. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  378. package/glTF/2.0/Extensions/KHR_mesh_quantization.pure.d.ts +26 -0
  379. package/glTF/2.0/Extensions/KHR_mesh_quantization.pure.js +35 -0
  380. package/glTF/2.0/Extensions/KHR_mesh_quantization.pure.js.map +1 -0
  381. package/glTF/2.0/Extensions/KHR_mesh_quantization.types.d.ts +9 -0
  382. package/glTF/2.0/Extensions/KHR_mesh_quantization.types.js +2 -0
  383. package/glTF/2.0/Extensions/KHR_mesh_quantization.types.js.map +1 -0
  384. package/glTF/2.0/Extensions/KHR_node_hoverability.d.ts +4 -29
  385. package/glTF/2.0/Extensions/KHR_node_hoverability.js +6 -187
  386. package/glTF/2.0/Extensions/KHR_node_hoverability.js.map +1 -1
  387. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.d.ts +28 -0
  388. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js +202 -0
  389. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js.map +1 -0
  390. package/glTF/2.0/Extensions/KHR_node_hoverability.types.d.ts +9 -0
  391. package/glTF/2.0/Extensions/KHR_node_hoverability.types.js +2 -0
  392. package/glTF/2.0/Extensions/KHR_node_hoverability.types.js.map +1 -0
  393. package/glTF/2.0/Extensions/KHR_node_selectability.d.ts +4 -28
  394. package/glTF/2.0/Extensions/KHR_node_selectability.js +6 -121
  395. package/glTF/2.0/Extensions/KHR_node_selectability.js.map +1 -1
  396. package/glTF/2.0/Extensions/KHR_node_selectability.pure.d.ts +27 -0
  397. package/glTF/2.0/Extensions/KHR_node_selectability.pure.js +136 -0
  398. package/glTF/2.0/Extensions/KHR_node_selectability.pure.js.map +1 -0
  399. package/glTF/2.0/Extensions/KHR_node_selectability.types.d.ts +9 -0
  400. package/glTF/2.0/Extensions/KHR_node_selectability.types.js +2 -0
  401. package/glTF/2.0/Extensions/KHR_node_selectability.types.js.map +1 -0
  402. package/glTF/2.0/Extensions/KHR_node_visibility.d.ts +4 -28
  403. package/glTF/2.0/Extensions/KHR_node_visibility.js +6 -64
  404. package/glTF/2.0/Extensions/KHR_node_visibility.js.map +1 -1
  405. package/glTF/2.0/Extensions/KHR_node_visibility.pure.d.ts +27 -0
  406. package/glTF/2.0/Extensions/KHR_node_visibility.pure.js +79 -0
  407. package/glTF/2.0/Extensions/KHR_node_visibility.pure.js.map +1 -0
  408. package/glTF/2.0/Extensions/KHR_node_visibility.types.d.ts +9 -0
  409. package/glTF/2.0/Extensions/KHR_node_visibility.types.js +2 -0
  410. package/glTF/2.0/Extensions/KHR_node_visibility.types.js.map +1 -0
  411. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +4 -31
  412. package/glTF/2.0/Extensions/KHR_texture_basisu.js +6 -35
  413. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  414. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.d.ts +30 -0
  415. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js +50 -0
  416. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js.map +1 -0
  417. package/glTF/2.0/Extensions/KHR_texture_basisu.types.d.ts +9 -0
  418. package/glTF/2.0/Extensions/KHR_texture_basisu.types.js +2 -0
  419. package/glTF/2.0/Extensions/KHR_texture_basisu.types.js.map +1 -0
  420. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +4 -35
  421. package/glTF/2.0/Extensions/KHR_texture_transform.js +6 -56
  422. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  423. package/glTF/2.0/Extensions/KHR_texture_transform.pure.d.ts +34 -0
  424. package/glTF/2.0/Extensions/KHR_texture_transform.pure.js +71 -0
  425. package/glTF/2.0/Extensions/KHR_texture_transform.pure.js.map +1 -0
  426. package/glTF/2.0/Extensions/KHR_texture_transform.types.d.ts +9 -0
  427. package/glTF/2.0/Extensions/KHR_texture_transform.types.js +2 -0
  428. package/glTF/2.0/Extensions/KHR_texture_transform.types.js.map +1 -0
  429. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +4 -37
  430. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +6 -45
  431. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  432. package/glTF/2.0/Extensions/KHR_xmp_json_ld.pure.d.ts +36 -0
  433. package/glTF/2.0/Extensions/KHR_xmp_json_ld.pure.js +60 -0
  434. package/glTF/2.0/Extensions/KHR_xmp_json_ld.pure.js.map +1 -0
  435. package/glTF/2.0/Extensions/KHR_xmp_json_ld.types.d.ts +9 -0
  436. package/glTF/2.0/Extensions/KHR_xmp_json_ld.types.js +2 -0
  437. package/glTF/2.0/Extensions/KHR_xmp_json_ld.types.js.map +1 -0
  438. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +5 -54
  439. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +7 -226
  440. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  441. package/glTF/2.0/Extensions/MSFT_audio_emitter.pure.d.ts +52 -0
  442. package/glTF/2.0/Extensions/MSFT_audio_emitter.pure.js +240 -0
  443. package/glTF/2.0/Extensions/MSFT_audio_emitter.pure.js.map +1 -0
  444. package/glTF/2.0/Extensions/MSFT_audio_emitter.types.d.ts +9 -0
  445. package/glTF/2.0/Extensions/MSFT_audio_emitter.types.js +2 -0
  446. package/glTF/2.0/Extensions/MSFT_audio_emitter.types.js.map +1 -0
  447. package/glTF/2.0/Extensions/MSFT_lod.d.ts +4 -102
  448. package/glTF/2.0/Extensions/MSFT_lod.js +6 -335
  449. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  450. package/glTF/2.0/Extensions/MSFT_lod.pure.d.ts +96 -0
  451. package/glTF/2.0/Extensions/MSFT_lod.pure.js +350 -0
  452. package/glTF/2.0/Extensions/MSFT_lod.pure.js.map +1 -0
  453. package/glTF/2.0/Extensions/MSFT_lod.types.d.ts +14 -0
  454. package/glTF/2.0/Extensions/MSFT_lod.types.js +2 -0
  455. package/glTF/2.0/Extensions/MSFT_lod.types.js.map +1 -0
  456. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +6 -27
  457. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +8 -40
  458. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  459. package/glTF/2.0/Extensions/MSFT_minecraftMesh.pure.d.ts +24 -0
  460. package/glTF/2.0/Extensions/MSFT_minecraftMesh.pure.js +53 -0
  461. package/glTF/2.0/Extensions/MSFT_minecraftMesh.pure.js.map +1 -0
  462. package/glTF/2.0/Extensions/MSFT_minecraftMesh.types.d.ts +9 -0
  463. package/glTF/2.0/Extensions/MSFT_minecraftMesh.types.js +2 -0
  464. package/glTF/2.0/Extensions/MSFT_minecraftMesh.types.js.map +1 -0
  465. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +6 -27
  466. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +8 -38
  467. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  468. package/glTF/2.0/Extensions/MSFT_sRGBFactors.pure.d.ts +24 -0
  469. package/glTF/2.0/Extensions/MSFT_sRGBFactors.pure.js +51 -0
  470. package/glTF/2.0/Extensions/MSFT_sRGBFactors.pure.js.map +1 -0
  471. package/glTF/2.0/Extensions/MSFT_sRGBFactors.types.d.ts +9 -0
  472. package/glTF/2.0/Extensions/MSFT_sRGBFactors.types.js +2 -0
  473. package/glTF/2.0/Extensions/MSFT_sRGBFactors.types.js.map +1 -0
  474. package/glTF/2.0/Extensions/dynamic.js +5 -0
  475. package/glTF/2.0/Extensions/dynamic.js.map +1 -1
  476. package/glTF/2.0/Extensions/index.d.ts +1 -0
  477. package/glTF/2.0/Extensions/index.js +1 -0
  478. package/glTF/2.0/Extensions/index.js.map +1 -1
  479. package/glTF/2.0/Extensions/objectModelMapping.d.ts +31 -2
  480. package/glTF/2.0/Extensions/objectModelMapping.js +3 -3
  481. package/glTF/2.0/Extensions/objectModelMapping.js.map +1 -1
  482. package/glTF/2.0/Extensions/pure.d.ts +46 -0
  483. package/glTF/2.0/Extensions/pure.js +48 -0
  484. package/glTF/2.0/Extensions/pure.js.map +1 -0
  485. package/glTF/2.0/glTFLoader.d.ts +1 -471
  486. package/glTF/2.0/glTFLoader.js +9 -2570
  487. package/glTF/2.0/glTFLoader.js.map +1 -1
  488. package/glTF/2.0/glTFLoader.pure.d.ts +476 -0
  489. package/glTF/2.0/glTFLoader.pure.js +2606 -0
  490. package/glTF/2.0/glTFLoader.pure.js.map +1 -0
  491. package/glTF/2.0/glTFLoaderAnimation.d.ts +2 -2
  492. package/glTF/2.0/glTFLoaderAnimation.js +2 -2
  493. package/glTF/2.0/glTFLoaderAnimation.js.map +1 -1
  494. package/glTF/2.0/pbrMaterialLoadingAdapter.d.ts +1 -1
  495. package/glTF/2.0/pbrMaterialLoadingAdapter.js +2 -2
  496. package/glTF/2.0/pbrMaterialLoadingAdapter.js.map +1 -1
  497. package/glTF/2.0/pure.d.ts +8 -0
  498. package/glTF/2.0/pure.js +10 -0
  499. package/glTF/2.0/pure.js.map +1 -0
  500. package/glTF/glTFFileLoader.d.ts +5 -571
  501. package/glTF/glTFFileLoader.js +6 -1016
  502. package/glTF/glTFFileLoader.js.map +1 -1
  503. package/glTF/glTFFileLoader.pure.d.ts +582 -0
  504. package/glTF/glTFFileLoader.pure.js +1044 -0
  505. package/glTF/glTFFileLoader.pure.js.map +1 -0
  506. package/glTF/glTFFileLoader.types.d.ts +11 -0
  507. package/glTF/glTFFileLoader.types.js +2 -0
  508. package/glTF/glTFFileLoader.types.js.map +1 -0
  509. package/glTF/glTFValidation.js +1 -1
  510. package/glTF/glTFValidation.js.map +1 -1
  511. package/glTF/pure.d.ts +6 -0
  512. package/glTF/pure.js +8 -0
  513. package/glTF/pure.js.map +1 -0
  514. package/package.json +3 -3
  515. package/pure.d.ts +8 -0
  516. package/pure.js +10 -0
  517. package/pure.js.map +1 -0
@@ -0,0 +1,1530 @@
1
+ import { GaussianSplattingMesh } from "@onerjs/core/Meshes/GaussianSplatting/gaussianSplattingMesh.js";
2
+ import { Logger } from "@onerjs/core/Misc/logger.js";
3
+ import { Tools } from "@onerjs/core/Misc/tools.js";
4
+ import { Vector3, Matrix } from "@onerjs/core/Maths/math.vector.js";
5
+ import { Color4 } from "@onerjs/core/Maths/math.color.js";
6
+ import { Frustum } from "@onerjs/core/Maths/math.frustum.js";
7
+ import { Plane } from "@onerjs/core/Maths/math.plane.js";
8
+ import { Camera } from "@onerjs/core/Cameras/camera.js";
9
+ import { BoundingInfo } from "@onerjs/core/Culling/boundingInfo.js";
10
+ import { CreateLineSystem } from "@onerjs/core/Meshes/Builders/linesBuilder.js";
11
+ import { VertexBuffer } from "@onerjs/core/Buffers/buffer.js";
12
+ import { ParseSogMetaAsTextures } from "./sog.pure.js";
13
+ import { GaussianSplattingWorkBuffer } from "./gaussianSplattingWorkBuffer.js";
14
+ import { GaussianSplattingDownloadManager } from "./gaussianSplattingDownloadManager.js";
15
+ import { GaussianSplattingResidencyController } from "./gaussianSplattingResidencyController.js";
16
+ // tan(22.5deg): reference half-FOV for a 45-degree vertical FOV, used for FOV compensation (matches PlayCanvas).
17
+ const RefTanHalfFov = Math.tan((22.5 * Math.PI) / 180);
18
+ // Sentinel "file" ids for the residency controller's pinned (never-evicted) allocations.
19
+ const PaddingFileId = -2;
20
+ const EnvironmentFileId = -1;
21
+ // Approximate bytes per resident splat used to convert a memory budget (MB) to a splat budget: the four
22
+ // work-buffer textures cost 16+16+16+4 = 52 bytes on the GPU, plus ~32 bytes of CPU position/sort data.
23
+ const BytesPerResidentSplat = 84;
24
+ // Scratch objects reused by the per-frame optimal-LOD evaluation (avoids per-call allocations).
25
+ const TmpInvWorld = new Matrix();
26
+ const TmpLocalCamera = new Vector3();
27
+ const TmpLocalForward = new Vector3();
28
+ const TmpWorldForward = new Vector3();
29
+ // Camera-local forward axis (+Z) used to derive the world-space view direction.
30
+ const LocalForwardAxis = new Vector3(0, 0, 1);
31
+ // The 12 edges of a box, as index pairs into its 8 corners. 12 edges x 2 endpoints = 24 vertices per box.
32
+ const BoxEdges = [
33
+ [0, 1],
34
+ [1, 2],
35
+ [2, 3],
36
+ [3, 0],
37
+ [4, 5],
38
+ [5, 6],
39
+ [6, 7],
40
+ [7, 4],
41
+ [0, 4],
42
+ [1, 5],
43
+ [2, 6],
44
+ [3, 7],
45
+ ];
46
+ // Vertices generated per leaf box (BoxEdges.length * 2).
47
+ const VerticesPerBox = BoxEdges.length * 2;
48
+ /**
49
+ * Wireframe colors per LOD level (cycled by `node.activeLod`).
50
+ */
51
+ const GsLodDebugColors = [
52
+ new Color4(1.0, 0.2, 0.2, 1.0), // LOD 0 - red
53
+ new Color4(1.0, 0.6, 0.1, 1.0), // LOD 1 - orange
54
+ new Color4(1.0, 1.0, 0.2, 1.0), // LOD 2 - yellow
55
+ new Color4(0.3, 1.0, 0.3, 1.0), // LOD 3 - green
56
+ new Color4(0.2, 1.0, 1.0, 1.0), // LOD 4 - cyan
57
+ new Color4(0.4, 0.5, 1.0, 1.0), // LOD 5 - blue
58
+ new Color4(0.9, 0.4, 1.0, 1.0), // LOD 6 - magenta
59
+ new Color4(1.0, 1.0, 1.0, 1.0), // LOD 7 - white
60
+ ];
61
+ /**
62
+ * Streams a PlayCanvas-style SOG LOD scene (`lod-meta.json`) into a single Gaussian Splatting mesh.
63
+ *
64
+ * Each selected SOG file (plus the environment) is loaded directly as GPU textures and decoded on the
65
+ * GPU into one unified, PlayCanvas-style square work buffer (no CPU splat decode or `updateData`). Only
66
+ * the splats of each node's currently-selected LOD are rendered/sorted via the mesh's interval filter.
67
+ *
68
+ * The coarsest (least-detail) LOD of every node is streamed first as a permanent base layer so the whole
69
+ * scene is visible quickly with no holes. A distance-based "optimal" LOD is then computed per node (see
70
+ * {@link evaluateOptimalLods}); finer LOD source files are streamed on demand and a node only switches to
71
+ * a finer LOD once that file is decoded, so transitions never flash or leave gaps.
72
+ *
73
+ * @experimental
74
+ */
75
+ export class GaussianSplattingStream extends GaussianSplattingMesh {
76
+ /**
77
+ * Returns true when the parsed JSON looks like a PlayCanvas-style `lod-meta.json` payload.
78
+ * @param data parsed JSON
79
+ * @returns whether the data is SOG LOD metadata
80
+ */
81
+ static IsLODMetadata(data) {
82
+ if (typeof data !== "object" || data === null) {
83
+ return false;
84
+ }
85
+ const meta = data;
86
+ return typeof meta.lodLevels === "number" && Array.isArray(meta.filenames) && typeof meta.tree === "object" && meta.tree !== null;
87
+ }
88
+ /**
89
+ * Creates a new SOG LOD streaming mesh and immediately starts streaming (non-blocking).
90
+ * @param name mesh name
91
+ * @param metadata parsed `lod-meta.json`
92
+ * @param rootUrl base URL the metadata's relative paths resolve against
93
+ * @param scene hosting scene
94
+ * @param options streaming options
95
+ */
96
+ constructor(name, metadata, rootUrl, scene, options = {}) {
97
+ super(name, null, scene, false);
98
+ // Flat list of leaf nodes that carry renderable LOD entries (used by the LOD heuristic and debug).
99
+ this._leafNodes = [];
100
+ // LOD heuristic parameters (PlayCanvas-aligned defaults).
101
+ this._lodBaseDistance = 5;
102
+ this._lodMultiplier = 3;
103
+ this._lodBehindPenalty = 1;
104
+ this._lodRangeMin = 0;
105
+ this._maxDecodesPerFrame = 1;
106
+ this._lodCooldownFrames = 10;
107
+ // Minimum frames between LOD re-evaluations, and minimum camera movement (world units) to re-evaluate.
108
+ this._lodUpdateInterval = 4;
109
+ this._lodUpdateDistance = 0.5;
110
+ this._maxDetailLod = 0;
111
+ // Frustum LOD bias: when enabled, nodes outside the camera frustum are rendered at their coarsest LOD.
112
+ this._frustumCulling = true;
113
+ // Reused world-space frustum planes and view-projection scratch matrix (avoids per-frame allocation).
114
+ this._frustumPlanes = [
115
+ new Plane(0, 0, 0, 0),
116
+ new Plane(0, 0, 0, 0),
117
+ new Plane(0, 0, 0, 0),
118
+ new Plane(0, 0, 0, 0),
119
+ new Plane(0, 0, 0, 0),
120
+ new Plane(0, 0, 0, 0),
121
+ ];
122
+ this._cullViewProj = new Matrix();
123
+ // GPU work buffer holding all decoded splats; created once the total capacity is known.
124
+ this._workBuffer = null;
125
+ // True once GPU position readback has been validated against a CPU decode (see _probeReadbackAsync). While
126
+ // false, positions are decoded on the CPU from the means images; once validated, every SOG image uses the
127
+ // fast direct upload and positions are read back from the work buffer (non-blocking).
128
+ this._useGpuPositionReadback = false;
129
+ // Whether the engine reports GPU readback support (candidate to validate on the first decode).
130
+ this._readbackCandidate = false;
131
+ // Set once the one-time readback validation has run (success or failure).
132
+ this._readbackProbed = false;
133
+ // Residency controller: owns the work-buffer slot allocator, per-file blocks, and eviction cooldowns.
134
+ this._residency = null;
135
+ // Splat count of each source file (learned from its metadata before allocation).
136
+ this._fileCounts = new Map();
137
+ // Cached SOG metadata per file so on-demand decodes don't refetch the meta.json.
138
+ this._fileMeta = new Map();
139
+ // Files whose splats have been fully GPU-decoded into the work buffer (render-safe).
140
+ this._decodedFiles = new Set();
141
+ // Files whose decode is currently in flight (dedupes concurrent requests).
142
+ this._loadingFiles = new Set();
143
+ // FIFO of file ids waiting to be decoded (drained under a per-frame budget).
144
+ this._decodeQueue = [];
145
+ // Per-file reference count: number of leaf nodes whose active LOD renders, or whose pending target points
146
+ // at, each file. At zero, a decoded file is scheduled for eviction and a still-downloading file is cancelled.
147
+ this._fileRefs = new Map();
148
+ // Files whose in-flight decode was cancelled; checked at decode checkpoints to bail out cooperatively.
149
+ this._cancelledDecodes = new Set();
150
+ // Eviction streaming config: enabled only when a budget smaller than the full dataset is configured.
151
+ this._evictionEnabled = false;
152
+ this._residentBudget = 0;
153
+ this._evictionCooldownFrames = 100;
154
+ // Serializes the allocate -> decode -> readback critical section so a defrag relayout (which runs inside it)
155
+ // never overlaps another file's decode writing the work buffer, which would corrupt the moved data.
156
+ this._decodeGate = Promise.resolve();
157
+ // Reusable scratch for the (rare) defrag relayout, to avoid per-relayout allocations during streaming.
158
+ this._relayoutOldOffsets = new Map();
159
+ this._relayoutSrcIndex = null;
160
+ // Global range covered by the environment file (always rendered), or null until it loads.
161
+ this._environmentRange = null;
162
+ // Unzipped environment bundle contents, retained between count-gathering and decode.
163
+ this._environmentFiles = null;
164
+ // Per-frame LOD streaming loop; installed once the base layer is ready.
165
+ this._lodObserver = null;
166
+ this._baseLayerReady = false;
167
+ // Throttling state for the per-frame LOD loop.
168
+ this._framesSinceLodUpdate = 0;
169
+ this._lastLodCamPos = new Vector3(Infinity, Infinity, Infinity);
170
+ // Forces the next LOD update to run regardless of the throttle (e.g. after a budget change).
171
+ this._forceLodUpdate = false;
172
+ // Running local-space bounds of all decoded splat centers (for frustum culling / picking).
173
+ this._boundsMin = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
174
+ this._boundsMax = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
175
+ // Debug LOD-node wireframe display.
176
+ this._debugDisplay = false;
177
+ this._debugLodSource = "optimal";
178
+ this._debugMesh = null;
179
+ this._debugObserver = null;
180
+ // Per-vertex RGBA color buffer mirror, updated in place when LOD colors change (avoids mesh rebuild flicker).
181
+ this._debugColorData = null;
182
+ // Signature of the per-leaf displayed LOD levels, used to skip rebuilding unchanged debug geometry.
183
+ this._debugSignature = 0;
184
+ this._disposed = false;
185
+ this._metadata = metadata;
186
+ this._rootUrl = rootUrl;
187
+ this._streamOptions = options;
188
+ // LOD heuristic parameters: take the provided values, otherwise keep the PlayCanvas-aligned defaults.
189
+ const maxLod = Math.max(0, metadata.lodLevels - 1);
190
+ this._lodRangeMax = maxLod;
191
+ if (options.lodBaseDistance !== undefined) {
192
+ this._lodBaseDistance = Math.max(0.1, options.lodBaseDistance);
193
+ }
194
+ if (options.lodMultiplier !== undefined) {
195
+ this._lodMultiplier = Math.max(1.2, options.lodMultiplier);
196
+ }
197
+ if (options.lodBehindPenalty !== undefined) {
198
+ this._lodBehindPenalty = Math.max(1, options.lodBehindPenalty);
199
+ }
200
+ if (options.lodRangeMin !== undefined) {
201
+ this._lodRangeMin = Math.max(0, Math.min(options.lodRangeMin, maxLod));
202
+ }
203
+ if (options.lodRangeMax !== undefined) {
204
+ this._lodRangeMax = Math.max(this._lodRangeMin, Math.min(options.lodRangeMax, maxLod));
205
+ }
206
+ if (options.maxDecodesPerFrame !== undefined) {
207
+ this._maxDecodesPerFrame = Math.max(1, options.maxDecodesPerFrame);
208
+ }
209
+ if (options.lodCooldownFrames !== undefined) {
210
+ this._lodCooldownFrames = Math.max(0, options.lodCooldownFrames);
211
+ }
212
+ if (options.lodUpdateInterval !== undefined) {
213
+ this._lodUpdateInterval = Math.max(1, options.lodUpdateInterval);
214
+ }
215
+ if (options.lodUpdateDistance !== undefined) {
216
+ this._lodUpdateDistance = Math.max(0, options.lodUpdateDistance);
217
+ }
218
+ if (options.maxDetailLod !== undefined) {
219
+ this._maxDetailLod = Math.max(0, Math.floor(options.maxDetailLod));
220
+ }
221
+ if (options.frustumCulling !== undefined) {
222
+ this._frustumCulling = options.frustumCulling;
223
+ }
224
+ if (options.debugLodSource) {
225
+ this._debugLodSource = options.debugLodSource;
226
+ }
227
+ if (options.evictionCooldownFrames !== undefined) {
228
+ this._evictionCooldownFrames = Math.max(0, Math.floor(options.evictionCooldownFrames));
229
+ }
230
+ // Resolve the resident-splat budget from the splat-count and/or memory-size options (smaller wins).
231
+ let budget = 0;
232
+ if (options.maxResidentSplats !== undefined && options.maxResidentSplats > 0) {
233
+ budget = Math.floor(options.maxResidentSplats);
234
+ }
235
+ if (options.memoryBudgetMb !== undefined && options.memoryBudgetMb > 0) {
236
+ const fromMB = Math.floor((options.memoryBudgetMb * 1024 * 1024) / BytesPerResidentSplat);
237
+ budget = budget > 0 ? Math.min(budget, fromMB) : fromMB;
238
+ }
239
+ this._residentBudget = budget;
240
+ this._downloadManager = new GaussianSplattingDownloadManager({
241
+ maxConcurrent: options.maxConcurrentDownloads,
242
+ maxRetries: options.maxDownloadRetries,
243
+ });
244
+ // PlayCanvas SOG data is authored with a flipped Y; match the standard SOG loader.
245
+ this.scaling.y *= -1;
246
+ // PlayCanvas SOG LOD scenes are authored Z-up; rotate into Babylon's Y-up convention.
247
+ this.rotation.x = -Math.PI / 2;
248
+ this._collectLodEntries(metadata.tree);
249
+ if (options.debugDisplay) {
250
+ this.debugDisplay = true;
251
+ }
252
+ // Kick off streaming without blocking the caller or the render loop.
253
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises, github/no-then
254
+ this._streamAllAsync().catch((e) => {
255
+ Logger.Error("GaussianSplattingStream: streaming failed: " + (e?.message ?? e));
256
+ });
257
+ }
258
+ getClassName() {
259
+ return "GaussianSplattingStream";
260
+ }
261
+ /**
262
+ * Resolves once the scene is fully streamed and displayed for the current camera: a LOD re-evaluation has
263
+ * run for the current point of view, every reachable LOD file has finished downloading and decoding (no
264
+ * downloads, decodes, or queued work remain), and the depth sort for the resulting splats has been applied
265
+ * and rendered. Intended for deterministic automated testing and screenshot/image comparison.
266
+ *
267
+ * Streaming and settling require rendered frames. If an external render loop is already running, this waits
268
+ * on it passively; otherwise (e.g. when awaited inside an async `createScene` before the host starts its
269
+ * render loop) it drives `scene.render()` itself until settled, so it never deadlocks.
270
+ *
271
+ * Note: the promise only resolves while the camera is still — if the camera keeps moving, the target LODs
272
+ * (and the depth sort) keep changing and the stream never settles. Position the camera, then await this.
273
+ * @param stableFrames number of consecutive settled frames to require before resolving (defaults to 3), so
274
+ * the final sorted frame is actually on screen
275
+ * @returns a promise that resolves when loading and rendering are complete for the current view
276
+ */
277
+ async whenSettledAsync(stableFrames = 3) {
278
+ if (this._disposed) {
279
+ return;
280
+ }
281
+ // Re-evaluate LODs immediately so the target levels reflect the current camera before we wait.
282
+ this._forceLodUpdate = true;
283
+ const required = Math.max(1, stableFrames);
284
+ const scene = this._scene;
285
+ let stable = 0;
286
+ const isSettled = () => {
287
+ if (this._isLoadingIdle() && this._isDepthSortSettled) {
288
+ return ++stable >= required;
289
+ }
290
+ stable = 0;
291
+ return false;
292
+ };
293
+ // An external render loop is already driving frames: observe it passively.
294
+ if (scene.getEngine().activeRenderLoops.length > 0) {
295
+ await new Promise((resolve) => {
296
+ let observer = null;
297
+ observer = scene.onAfterRenderObservable.add(() => {
298
+ if (this._disposed || isSettled()) {
299
+ if (observer) {
300
+ scene.onAfterRenderObservable.remove(observer);
301
+ observer = null;
302
+ }
303
+ resolve();
304
+ }
305
+ });
306
+ });
307
+ return;
308
+ }
309
+ // No render loop yet (e.g. awaited inside createScene): drive rendering ourselves so the streaming
310
+ // decodes and depth sort can progress, yielding between frames so async downloads/readbacks resolve.
311
+ // Wrap each render in beginFrame/endFrame exactly like the engine's own render loop: on WebGPU,
312
+ // endFrame submits the frame's command buffers and presents the swapchain, so a bare scene.render()
313
+ // would leave the acquired swapchain texture to be destroyed at the frame boundary before its command
314
+ // buffer is submitted ("destroyed texture used in a submit").
315
+ const engine = scene.getEngine();
316
+ const requestFrame = globalThis.requestAnimationFrame;
317
+ while (!this._disposed) {
318
+ engine.beginFrame();
319
+ scene.render();
320
+ engine.endFrame();
321
+ if (isSettled()) {
322
+ return;
323
+ }
324
+ // eslint-disable-next-line no-await-in-loop
325
+ await new Promise((resolve) => {
326
+ if (typeof requestFrame === "function") {
327
+ requestFrame(() => resolve());
328
+ }
329
+ else {
330
+ setTimeout(resolve, 16);
331
+ }
332
+ });
333
+ }
334
+ }
335
+ /**
336
+ * Whether the base layer is ready and there is no streaming work in flight (nothing queued for decode, no
337
+ * decode running, and no downloads pending).
338
+ * @returns true when no loading work remains
339
+ */
340
+ _isLoadingIdle() {
341
+ return this._baseLayerReady && this._decodeQueue.length === 0 && this._loadingFiles.size === 0 && this._downloadManager.isIdle;
342
+ }
343
+ /**
344
+ * Finest (most detailed) LOD level any node is allowed to render. `0` allows full detail (level 0);
345
+ * `1` caps detail at the next-coarser level, and so on. Nodes already coarser than this cap (by
346
+ * distance) are unaffected. Changes take effect in real time.
347
+ */
348
+ get maxDetailLod() {
349
+ return this._maxDetailLod;
350
+ }
351
+ set maxDetailLod(value) {
352
+ const level = Math.max(0, Math.floor(value));
353
+ if (this._maxDetailLod === level) {
354
+ return;
355
+ }
356
+ this._maxDetailLod = level;
357
+ // Re-evaluate LODs on the next frame regardless of the movement throttle so the change is immediate.
358
+ this._forceLodUpdate = true;
359
+ }
360
+ /**
361
+ * Coarsest LOD level index in the scene (number of LOD levels minus one). Useful as the upper bound
362
+ * for {@link maxDetailLod}.
363
+ */
364
+ get maxLodLevel() {
365
+ return Math.max(0, this._metadata.lodLevels - 1);
366
+ }
367
+ /**
368
+ * When true (default), nodes whose bounding box is outside the camera frustum are biased to the coarsest
369
+ * LOD instead of being hidden. They stay in the sort/render set (their off-screen splats are clipped), so
370
+ * turning the camera toward them shows low detail immediately with no invisible frames, then refines.
371
+ * Changes take effect in real time.
372
+ */
373
+ get frustumCulling() {
374
+ return this._frustumCulling;
375
+ }
376
+ set frustumCulling(value) {
377
+ if (this._frustumCulling === value) {
378
+ return;
379
+ }
380
+ this._frustumCulling = value;
381
+ // Re-evaluate LODs next frame so the off-screen bias is applied/removed immediately.
382
+ this._forceLodUpdate = true;
383
+ }
384
+ /**
385
+ * When true, renders a wireframe box per LOD node, colored by the LOD level selected by {@link debugLodSource}.
386
+ */
387
+ get debugDisplay() {
388
+ return this._debugDisplay;
389
+ }
390
+ set debugDisplay(value) {
391
+ if (this._debugDisplay === value) {
392
+ return;
393
+ }
394
+ this._debugDisplay = value;
395
+ if (value) {
396
+ this._refreshDebugDisplay();
397
+ }
398
+ else {
399
+ this._clearDebugDisplay();
400
+ }
401
+ }
402
+ /**
403
+ * Selects which LOD value drives the debug wireframe colors: the distance-based `"optimal"` LOD
404
+ * (default, recomputed as the camera moves) or the `"current"` streamed/rendered LOD.
405
+ */
406
+ get debugLodSource() {
407
+ return this._debugLodSource;
408
+ }
409
+ set debugLodSource(value) {
410
+ if (this._debugLodSource === value) {
411
+ return;
412
+ }
413
+ this._debugLodSource = value;
414
+ if (this._debugDisplay) {
415
+ this._refreshDebugDisplay();
416
+ }
417
+ }
418
+ dispose(doNotRecurse) {
419
+ this._disposed = true;
420
+ if (this._lodObserver) {
421
+ this._scene.onBeforeRenderObservable.remove(this._lodObserver);
422
+ this._lodObserver = null;
423
+ }
424
+ this._clearDebugDisplay();
425
+ this._downloadManager.dispose();
426
+ this._residency?.dispose();
427
+ this._residency = null;
428
+ this._workBuffer?.dispose();
429
+ this._workBuffer = null;
430
+ super.dispose(doNotRecurse);
431
+ }
432
+ /**
433
+ * Re-evaluates the optimal LOD for every node based on the camera position. The result is stored in
434
+ * each node's `optimalLod`. Rendering is unaffected; this currently drives only diagnostics and the
435
+ * debug wireframe display.
436
+ * @param camera camera to evaluate against (defaults to the scene's active camera)
437
+ */
438
+ evaluateOptimalLods(camera = this._scene.activeCamera) {
439
+ if (!camera || this._leafNodes.length === 0) {
440
+ return;
441
+ }
442
+ const maxLod = Math.max(0, this._metadata.lodLevels - 1);
443
+ const base = this._lodBaseDistance;
444
+ const mult = this._lodMultiplier;
445
+ const behindPenalty = this._lodBehindPenalty;
446
+ const rangeMin = this._lodRangeMin;
447
+ const rangeMax = this._lodRangeMax;
448
+ // FOV compensation: use min(tanHalfV, tanHalfH) so transitions stay perceptually uniform (matches PlayCanvas).
449
+ const aspect = this._scene.getEngine().getAspectRatio(camera) || 1;
450
+ let tanHalfV = Math.tan(camera.fov * 0.5);
451
+ if (camera.fovMode === Camera.FOVMODE_HORIZONTAL_FIXED) {
452
+ tanHalfV /= aspect;
453
+ }
454
+ const tanHalfH = tanHalfV * aspect;
455
+ const fovScale = Math.min(tanHalfV, tanHalfH) / RefTanHalfFov;
456
+ // Transform the camera into the mesh's local space (where the node bounds live).
457
+ this.computeWorldMatrix(false).invertToRef(TmpInvWorld);
458
+ const localCamera = Vector3.TransformCoordinatesToRef(camera.globalPosition, TmpInvWorld, TmpLocalCamera);
459
+ const px = localCamera.x;
460
+ const py = localCamera.y;
461
+ const pz = localCamera.z;
462
+ let fwx = 0;
463
+ let fwy = 0;
464
+ let fwz = 0;
465
+ if (behindPenalty > 1) {
466
+ camera.getDirectionToRef(LocalForwardAxis, TmpWorldForward);
467
+ const localForward = Vector3.TransformNormalToRef(TmpWorldForward, TmpInvWorld, TmpLocalForward);
468
+ localForward.normalize();
469
+ fwx = localForward.x;
470
+ fwy = localForward.y;
471
+ fwz = localForward.z;
472
+ }
473
+ for (const node of this._leafNodes) {
474
+ const mn = node.bound.min;
475
+ const mx = node.bound.max;
476
+ // Distance from the camera to the closest point on this node's AABB (local space).
477
+ const qx = px < mn[0] ? mn[0] : px > mx[0] ? mx[0] : px;
478
+ const qy = py < mn[1] ? mn[1] : py > mx[1] ? mx[1] : py;
479
+ const qz = pz < mn[2] ? mn[2] : pz > mx[2] ? mx[2] : pz;
480
+ const dx = qx - px;
481
+ const dy = qy - py;
482
+ const dz = qz - pz;
483
+ const actualDistance = Math.sqrt(dx * dx + dy * dy + dz * dz);
484
+ // Push nodes behind the camera toward coarser LODs when a penalty is configured.
485
+ let penalizedDistance = actualDistance;
486
+ if (behindPenalty > 1 && actualDistance > 0.01) {
487
+ const dotOverDistance = (fwx * dx + fwy * dy + fwz * dz) / actualDistance;
488
+ if (dotOverDistance < 0) {
489
+ penalizedDistance = actualDistance * (1 + -dotOverDistance * (behindPenalty - 1));
490
+ }
491
+ }
492
+ // Geometric LOD bands: threshold[k] = base * mult^(k-1).
493
+ const fovAdjustedDistance = penalizedDistance * fovScale;
494
+ let optimalLod;
495
+ if (maxLod === 0 || fovAdjustedDistance < base) {
496
+ optimalLod = 0;
497
+ }
498
+ else {
499
+ optimalLod = maxLod;
500
+ while (optimalLod > 1 && fovAdjustedDistance < base * Math.pow(mult, optimalLod - 1)) {
501
+ optimalLod--;
502
+ }
503
+ }
504
+ if (optimalLod < rangeMin) {
505
+ optimalLod = rangeMin;
506
+ }
507
+ else if (optimalLod > rangeMax) {
508
+ optimalLod = rangeMax;
509
+ }
510
+ // Frustum-based LOD bias: nodes outside the camera frustum are pushed to the coarsest allowed
511
+ // level instead of being hidden. They stay in the render/sort set (their splats are off-screen
512
+ // and clipped anyway), so when the camera turns to include them they are already present at low
513
+ // detail with no invisible frames, then refine to the distance-optimal level.
514
+ if (this._frustumCulling && node.inFrustum === false) {
515
+ optimalLod = rangeMax;
516
+ }
517
+ node.optimalLod = optimalLod;
518
+ }
519
+ }
520
+ /**
521
+ * The LOD level used to color a node's debug box, per {@link debugLodSource}.
522
+ * @param node leaf node
523
+ * @returns the displayed LOD level
524
+ */
525
+ _displayedLodLevel(node) {
526
+ if (this._debugLodSource === "optimal") {
527
+ return node.optimalLod ?? node.activeLod ?? 0;
528
+ }
529
+ return node.activeLod ?? 0;
530
+ }
531
+ /**
532
+ * Rebuilds the debug wireframe (evaluating the optimal LOD first when needed) and wires up the per-frame
533
+ * recolor observer. The observer runs for both LOD sources: "optimal" colors track the camera, and
534
+ * "current" colors track LOD levels as they stream in/out.
535
+ */
536
+ _refreshDebugDisplay() {
537
+ if (this._debugLodSource === "optimal") {
538
+ this.evaluateOptimalLods();
539
+ }
540
+ this._buildDebugMesh();
541
+ const needsObserver = this._debugDisplay;
542
+ if (needsObserver && !this._debugObserver) {
543
+ this._debugObserver = this._scene.onBeforeRenderObservable.add(() => this._onDebugFrame());
544
+ }
545
+ else if (!needsObserver && this._debugObserver) {
546
+ this._scene.onBeforeRenderObservable.remove(this._debugObserver);
547
+ this._debugObserver = null;
548
+ }
549
+ }
550
+ /**
551
+ * Per-frame debug update: recolors the existing wireframe in place whenever the displayed LOD levels
552
+ * change. For the "optimal" source the optimal LOD is recomputed first (it tracks the camera); for the
553
+ * "current" source the levels are driven by the streaming loop, so no recomputation is needed here. The
554
+ * geometry is never rebuilt, which avoids the dispose/recreate flicker while the camera moves.
555
+ */
556
+ _onDebugFrame() {
557
+ if (this._debugLodSource === "optimal") {
558
+ this.evaluateOptimalLods();
559
+ }
560
+ if (this._computeDebugSignature() !== this._debugSignature) {
561
+ this._updateDebugColors();
562
+ }
563
+ }
564
+ /**
565
+ * Builds the LOD-node wireframe boxes once (one box per leaf node), colored by the displayed LOD level.
566
+ * The color vertex buffer is created updatable so subsequent recolors can happen in place.
567
+ */
568
+ _buildDebugMesh() {
569
+ if (this._debugMesh) {
570
+ this._debugMesh.dispose();
571
+ this._debugMesh = null;
572
+ }
573
+ this._debugColorData = null;
574
+ const lines = [];
575
+ const colors = [];
576
+ for (const node of this._leafNodes) {
577
+ const color = GsLodDebugColors[this._displayedLodLevel(node) % GsLodDebugColors.length];
578
+ const mn = node.bound.min;
579
+ const mx = node.bound.max;
580
+ const corners = [
581
+ new Vector3(mn[0], mn[1], mn[2]),
582
+ new Vector3(mx[0], mn[1], mn[2]),
583
+ new Vector3(mx[0], mx[1], mn[2]),
584
+ new Vector3(mn[0], mx[1], mn[2]),
585
+ new Vector3(mn[0], mn[1], mx[2]),
586
+ new Vector3(mx[0], mn[1], mx[2]),
587
+ new Vector3(mx[0], mx[1], mx[2]),
588
+ new Vector3(mn[0], mx[1], mx[2]),
589
+ ];
590
+ for (const edge of BoxEdges) {
591
+ lines.push([corners[edge[0]], corners[edge[1]]]);
592
+ colors.push([color, color]);
593
+ }
594
+ }
595
+ this._debugSignature = this._computeDebugSignature();
596
+ if (lines.length === 0) {
597
+ return;
598
+ }
599
+ const mesh = CreateLineSystem(this.name + "_lodDebug", { lines, colors, updatable: true, useVertexAlpha: false }, this._scene);
600
+ mesh.parent = this;
601
+ mesh.isPickable = false;
602
+ mesh.doNotSerialize = true;
603
+ mesh.reservedDataStore = { hidden: true };
604
+ this._debugMesh = mesh;
605
+ this._debugColorData = new Float32Array(this._leafNodes.length * VerticesPerBox * 4);
606
+ }
607
+ /**
608
+ * Recolors the existing wireframe in place from the current displayed LOD levels, without rebuilding geometry.
609
+ */
610
+ _updateDebugColors() {
611
+ if (!this._debugMesh || !this._debugColorData) {
612
+ return;
613
+ }
614
+ const data = this._debugColorData;
615
+ let offset = 0;
616
+ for (const node of this._leafNodes) {
617
+ const color = GsLodDebugColors[this._displayedLodLevel(node) % GsLodDebugColors.length];
618
+ for (let v = 0; v < VerticesPerBox; v++) {
619
+ data[offset++] = color.r;
620
+ data[offset++] = color.g;
621
+ data[offset++] = color.b;
622
+ data[offset++] = color.a;
623
+ }
624
+ }
625
+ this._debugMesh.updateVerticesData(VertexBuffer.ColorKind, data);
626
+ this._debugSignature = this._computeDebugSignature();
627
+ }
628
+ /**
629
+ * Computes a cheap 32-bit rolling hash of every leaf's displayed LOD level, used to detect when the
630
+ * debug wireframe needs recoloring. Avoids per-frame string allocation in the render loop.
631
+ * @returns a numeric signature of the current displayed LOD levels
632
+ */
633
+ _computeDebugSignature() {
634
+ let hash = 0;
635
+ for (const node of this._leafNodes) {
636
+ hash = (hash * 31 + this._displayedLodLevel(node)) | 0;
637
+ }
638
+ return hash;
639
+ }
640
+ /**
641
+ * Disposes the LOD-node wireframe boxes and stops live debug updates.
642
+ */
643
+ _clearDebugDisplay() {
644
+ if (this._debugObserver) {
645
+ this._scene.onBeforeRenderObservable.remove(this._debugObserver);
646
+ this._debugObserver = null;
647
+ }
648
+ if (this._debugMesh) {
649
+ this._debugMesh.dispose();
650
+ this._debugMesh = null;
651
+ }
652
+ this._debugColorData = null;
653
+ this._debugSignature = 0;
654
+ }
655
+ /**
656
+ * Walks the LOD tree and records every leaf that carries renderable LOD entries, capturing the set of
657
+ * available levels and the coarsest (base) level for each.
658
+ * @param node current tree node
659
+ */
660
+ _collectLodEntries(node) {
661
+ if (node.children) {
662
+ for (const child of node.children) {
663
+ this._collectLodEntries(child);
664
+ }
665
+ return;
666
+ }
667
+ if (!node.lods) {
668
+ return;
669
+ }
670
+ // Collect all levels that hold splats (PlayCanvas convention: level 0 is the finest, higher = coarser).
671
+ const levels = [];
672
+ for (const key of Object.keys(node.lods)) {
673
+ const level = Number(key);
674
+ const entry = node.lods[key];
675
+ if (Number.isFinite(level) && entry && entry.count > 0) {
676
+ levels.push(level);
677
+ }
678
+ }
679
+ if (levels.length === 0) {
680
+ return;
681
+ }
682
+ levels.sort((a, b) => a - b);
683
+ node.availableLevels = levels;
684
+ node.baseLod = levels[levels.length - 1];
685
+ node.activeLod = undefined;
686
+ node.lodCooldown = 0;
687
+ node.inFrustum = true;
688
+ // Local-space bounds for the per-node frustum test; the mesh world matrix is applied per evaluation.
689
+ node.cullBounds = new BoundingInfo(Vector3.FromArray(node.bound.min), Vector3.FromArray(node.bound.max));
690
+ this._leafNodes.push(node);
691
+ }
692
+ /**
693
+ * Streams the scene: learns every source file's splat count, allocates one unified GPU work buffer
694
+ * sized for all LOD files, decodes the environment and the coarsest LOD of every node as a permanent
695
+ * base layer, then installs the per-frame loop that streams finer LODs on demand.
696
+ */
697
+ async _streamAllAsync() {
698
+ // Phase 1: learn splat counts for the environment and every referenced LOD file (cheap meta only).
699
+ const fileIds = this._collectAllFileIds();
700
+ const envCount = await this._gatherCountsAsync(fileIds);
701
+ if (this._disposed) {
702
+ return;
703
+ }
704
+ // Phase 2: learn the full dataset size (padding + environment + every LOD file). The work buffer is
705
+ // sized to this unless a smaller budget enables eviction-based streaming.
706
+ // Index 0 is reserved as a never-decoded padding splat: the sort worker and index buffer pad unused
707
+ // slots with index 0, and leaving that slot zeroed (center.w = 0 => zero covariance, alpha 0) makes
708
+ // the padding invisible instead of ghosting a copy of the first real splat.
709
+ let fullCapacity = 1;
710
+ if (envCount > 0) {
711
+ fullCapacity += envCount;
712
+ }
713
+ for (const fileId of fileIds) {
714
+ const count = this._fileCounts.get(fileId);
715
+ if (count !== undefined && count > 0) {
716
+ fullCapacity += count;
717
+ }
718
+ }
719
+ if (fullCapacity <= 1) {
720
+ return;
721
+ }
722
+ // Eviction streams the dataset through a fixed budget; only enabled when that budget is below the full set.
723
+ this._evictionEnabled = this._residentBudget > 0 && this._residentBudget < fullCapacity;
724
+ const capacity = this._evictionEnabled ? Math.max(this._residentBudget, 1) : fullCapacity;
725
+ this._residency = new GaussianSplattingResidencyController(capacity, this._evictionCooldownFrames, (file) => this._onFileEvicted(file));
726
+ // Pin splat 0 as the invisible padding splat, then the environment (always rendered) — neither is evicted.
727
+ this._residency.pin(PaddingFileId, 1);
728
+ if (envCount > 0) {
729
+ const envOffset = this._residency.pin(EnvironmentFileId, envCount);
730
+ if (envOffset !== null) {
731
+ this._environmentRange = { offset: envOffset, count: envCount };
732
+ }
733
+ else {
734
+ Logger.Warn("GaussianSplattingStream: environment does not fit the memory budget; skipping it.");
735
+ this._environmentFiles = null;
736
+ }
737
+ }
738
+ this._workBuffer = new GaussianSplattingWorkBuffer(this._scene, capacity);
739
+ // GPU readback is only enabled after it is validated against a CPU decode on the first file (see
740
+ // _probeReadbackAsync); until then positions are decoded on the CPU so there is always a correct result.
741
+ this._readbackCandidate = this._workBuffer.supportsAsyncCentersReadback;
742
+ const splatPositions = new Float32Array(capacity * 4);
743
+ const textures = this._workBuffer.textures;
744
+ this._setExternalWorkBuffer(textures[0], textures[1], textures[2], textures[3], splatPositions, capacity);
745
+ // Nothing is active until at least one resource has been decoded.
746
+ this.setSplatIndexRanges([]);
747
+ this.setEnabled(true);
748
+ // Phase 3: decode the environment, then every node's coarsest LOD as the permanent base layer.
749
+ if (this._environmentRange && this._environmentFiles) {
750
+ await this._decodeEnvironmentAsync();
751
+ }
752
+ this._environmentFiles = null;
753
+ const baseFiles = new Set();
754
+ for (const node of this._leafNodes) {
755
+ const entry = node.lods[String(node.baseLod)];
756
+ if (entry && this._fileCounts.has(entry.file)) {
757
+ baseFiles.add(entry.file);
758
+ }
759
+ }
760
+ for (const fileId of Array.from(baseFiles)) {
761
+ if (this._disposed) {
762
+ return;
763
+ }
764
+ // eslint-disable-next-line no-await-in-loop
765
+ await this._decodeFileAsync(fileId);
766
+ }
767
+ if (this._disposed) {
768
+ return;
769
+ }
770
+ // Phase 4: hand off to the per-frame LOD streaming loop.
771
+ this._baseLayerReady = true;
772
+ if (!this._lodObserver) {
773
+ this._lodObserver = this._scene.onBeforeRenderObservable.add(() => this._onLodFrame());
774
+ }
775
+ }
776
+ /**
777
+ * Collects the unique set of source file indices referenced by any LOD of any leaf, sorted ascending.
778
+ * @returns sorted unique file indices
779
+ */
780
+ _collectAllFileIds() {
781
+ const ids = new Set();
782
+ for (const node of this._leafNodes) {
783
+ for (const level of node.availableLevels) {
784
+ const entry = node.lods[String(level)];
785
+ if (entry) {
786
+ ids.add(entry.file);
787
+ }
788
+ }
789
+ }
790
+ return Array.from(ids).sort((a, b) => a - b);
791
+ }
792
+ /**
793
+ * Fetches the environment bundle and every referenced file's metadata to learn splat counts, caching
794
+ * each file's parsed metadata for the later on-demand decode. Metadata fetches run in parallel.
795
+ * @param fileIds file indices to fetch metadata for
796
+ * @returns the environment splat count (0 when there is no environment)
797
+ */
798
+ async _gatherCountsAsync(fileIds) {
799
+ let envCount = 0;
800
+ if (this._metadata.environment) {
801
+ try {
802
+ const url = this._rootUrl + this._metadata.environment;
803
+ const buffer = await this._downloadManager.loadFileAsync(url);
804
+ const files = await this._unzipAsync(new Uint8Array(buffer));
805
+ const metaBytes = files.get("meta.json");
806
+ if (metaBytes) {
807
+ const meta = JSON.parse(new TextDecoder().decode(metaBytes));
808
+ envCount = GaussianSplattingStream._GetSplatCount(meta);
809
+ this._environmentFiles = files;
810
+ }
811
+ }
812
+ catch (e) {
813
+ // The environment is non-essential — keep streaming the LOD tree even if it fails.
814
+ Logger.Warn("GaussianSplattingStream: failed to load environment: " + (e?.message ?? e));
815
+ }
816
+ }
817
+ await Promise.all(fileIds.map(async (fileId) => {
818
+ const relativePath = this._metadata.filenames[fileId];
819
+ if (!relativePath) {
820
+ Logger.Warn(`GaussianSplattingStream: missing filename for file index ${fileId}.`);
821
+ return;
822
+ }
823
+ try {
824
+ const metaUrl = this._rootUrl + relativePath;
825
+ const subRootUrl = metaUrl.substring(0, metaUrl.lastIndexOf("/") + 1);
826
+ const metaBuffer = await this._downloadManager.loadFileAsync(metaUrl);
827
+ const sogData = JSON.parse(new TextDecoder().decode(new Uint8Array(metaBuffer)));
828
+ this._fileCounts.set(fileId, GaussianSplattingStream._GetSplatCount(sogData));
829
+ this._fileMeta.set(fileId, { sogData, subRootUrl });
830
+ }
831
+ catch (e) {
832
+ Logger.Warn(`GaussianSplattingStream: failed to load metadata for ${relativePath}: ${e?.message ?? e}`);
833
+ }
834
+ }));
835
+ return envCount;
836
+ }
837
+ /**
838
+ * Queues a file for on-demand decode if it isn't already decoded, in flight, or already queued.
839
+ * @param fileId file index to decode
840
+ */
841
+ _enqueueDecode(fileId) {
842
+ if (this._decodedFiles.has(fileId) || this._loadingFiles.has(fileId) || !this._fileMeta.has(fileId)) {
843
+ return;
844
+ }
845
+ if (this._decodeQueue.indexOf(fileId) === -1) {
846
+ this._decodeQueue.push(fileId);
847
+ }
848
+ }
849
+ /**
850
+ * Starts up to {@link _maxDecodesPerFrame} queued decodes for this frame. Decodes run asynchronously
851
+ * and promote any waiting nodes once they complete.
852
+ */
853
+ _pumpDecodeQueue() {
854
+ let started = 0;
855
+ while (this._decodeQueue.length > 0 && started < this._maxDecodesPerFrame) {
856
+ const fileId = this._decodeQueue.shift();
857
+ if (this._decodedFiles.has(fileId) || this._loadingFiles.has(fileId)) {
858
+ continue;
859
+ }
860
+ started++;
861
+ // eslint-disable-next-line github/no-then
862
+ this._decodeFileAsync(fileId).catch((e) => {
863
+ Logger.Warn("GaussianSplattingStream: decode failed: " + (e?.message ?? e));
864
+ });
865
+ }
866
+ }
867
+ /**
868
+ * Writes a decoded splat range's positions into the shared buffer, expands the bounds, and incrementally
869
+ * patches the sort worker.
870
+ * @param positions stride-4 positions for the range
871
+ * @param base first splat index of the range in the work buffer
872
+ * @param count number of splats in the range
873
+ */
874
+ _applyPositions(positions, base, count) {
875
+ this._splatPositions.set(positions, base * 4);
876
+ this._updateBounds(positions, count);
877
+ // Incrementally patch only this range in the sort worker (avoids the full position-buffer re-copy).
878
+ this._postWorkerPositionsRange(base, count);
879
+ }
880
+ /**
881
+ * One-time validation of GPU position readback: reads a sample of the just-decoded range back from the work
882
+ * buffer and compares it to the CPU-decoded positions. Enables {@link _useGpuPositionReadback} only on an
883
+ * exact (within float tolerance) match, so an unsupported or incorrect readback (e.g. a backend without the
884
+ * required texture usage, or an orientation mismatch) safely keeps the CPU decode path.
885
+ * @param base first splat index of the validated range
886
+ * @param count number of splats in the range
887
+ * @param cpuPositions the CPU-decoded stride-4 positions for the range (ground truth)
888
+ */
889
+ async _probeReadbackAsync(base, count, cpuPositions) {
890
+ this._readbackProbed = true;
891
+ if (!this._workBuffer) {
892
+ return;
893
+ }
894
+ const sampleCount = Math.min(count, 1024);
895
+ let ok = false;
896
+ try {
897
+ const gpu = await this._workBuffer.readCentersRangeAsync(base, sampleCount);
898
+ if (this._disposed) {
899
+ return;
900
+ }
901
+ if (gpu && gpu.length >= sampleCount * 4) {
902
+ ok = true;
903
+ for (let i = 0; i < sampleCount && ok; i++) {
904
+ for (let j = 0; j < 3; j++) {
905
+ const a = gpu[i * 4 + j];
906
+ const b = cpuPositions[i * 4 + j];
907
+ if (Math.abs(a - b) > 1e-2 * (1 + Math.abs(b))) {
908
+ ok = false;
909
+ break;
910
+ }
911
+ }
912
+ }
913
+ }
914
+ }
915
+ catch {
916
+ ok = false;
917
+ }
918
+ this._useGpuPositionReadback = ok;
919
+ Logger.Log(ok
920
+ ? "GaussianSplattingStream: GPU position readback validated; streamed LOD positions are read back from the GPU."
921
+ : "GaussianSplattingStream: GPU position readback unavailable; decoding LOD positions on the CPU.");
922
+ }
923
+ /**
924
+ * Resolves the decoded positions for a splat range and applies them. Once GPU readback has been validated,
925
+ * positions are read back from the work buffer (non-blocking) and `pack.positions` is empty; otherwise the
926
+ * CPU-decoded `pack.positions` are used, and — on the first such decode — the GPU readback is validated
927
+ * against them so subsequent decodes can use the fast path.
928
+ * @param pack the parsed SOG pack (its `positions` is populated only on the CPU path)
929
+ * @param base first splat index of the range in the work buffer
930
+ * @param count number of splats in the range
931
+ * @returns whether positions were applied
932
+ */
933
+ async _applyDecodedPositionsAsync(pack, base, count) {
934
+ if (this._useGpuPositionReadback && this._workBuffer) {
935
+ const positions = await this._workBuffer.readCentersRangeAsync(base, count);
936
+ if (this._disposed) {
937
+ return false;
938
+ }
939
+ if (positions && this._splatPositions) {
940
+ this._applyPositions(positions, base, count);
941
+ return true;
942
+ }
943
+ // Validated readback unexpectedly returned nothing; fall through to the (likely empty) CPU positions.
944
+ }
945
+ const cpu = pack.positions.length >= count * 4 ? pack.positions.subarray(0, count * 4) : null;
946
+ if (!cpu || !this._splatPositions) {
947
+ return false;
948
+ }
949
+ this._applyPositions(cpu, base, count);
950
+ // First CPU decode while readback is a candidate: validate it so later decodes can use the fast path.
951
+ if (!this._readbackProbed && this._readbackCandidate) {
952
+ await this._probeReadbackAsync(base, count, cpu);
953
+ }
954
+ return true;
955
+ }
956
+ /**
957
+ * Decodes the always-on environment bundle into its work-buffer block and activates its range.
958
+ */
959
+ async _decodeEnvironmentAsync() {
960
+ if (!this._environmentRange || !this._environmentFiles || !this._workBuffer) {
961
+ return;
962
+ }
963
+ const range = this._environmentRange;
964
+ try {
965
+ const parsed = await ParseSogMetaAsTextures(this._environmentFiles, "", this._scene, !this._useGpuPositionReadback, this._downloadManager);
966
+ const pack = parsed.sogTextures;
967
+ if (!pack) {
968
+ return;
969
+ }
970
+ try {
971
+ if (this._disposed || !this._workBuffer) {
972
+ return;
973
+ }
974
+ await this._workBuffer.decodeAsync(pack, range.offset);
975
+ if (this._disposed) {
976
+ return;
977
+ }
978
+ await this._applyDecodedPositionsAsync(pack, range.offset, range.count);
979
+ if (this._disposed) {
980
+ return;
981
+ }
982
+ this._refreshActiveRanges();
983
+ }
984
+ finally {
985
+ // Always release the GPU source textures (the decode pass is the only consumer).
986
+ GaussianSplattingStream._DisposePack(pack);
987
+ }
988
+ }
989
+ catch (e) {
990
+ Logger.Warn("GaussianSplattingStream: failed to decode environment: " + (e?.message ?? e));
991
+ }
992
+ }
993
+ /**
994
+ * Loads one LOD source file as GPU textures, decodes it into its fixed work-buffer block, records its
995
+ * CPU centers for sorting, frees the source textures, then promotes any nodes that were waiting for it.
996
+ * Concurrent or repeat requests for the same file are ignored. If the file is cancelled mid-flight
997
+ * (because every node that wanted it retargeted), the decode bails cooperatively at the next checkpoint.
998
+ * @param fileId file index to decode
999
+ */
1000
+ async _decodeFileAsync(fileId) {
1001
+ if (this._decodedFiles.has(fileId) || this._loadingFiles.has(fileId) || !this._residency) {
1002
+ return;
1003
+ }
1004
+ const meta = this._fileMeta.get(fileId);
1005
+ const count = this._fileCounts.get(fileId);
1006
+ if (!meta || count === undefined) {
1007
+ return;
1008
+ }
1009
+ this._loadingFiles.add(fileId);
1010
+ this._cancelledDecodes.delete(fileId);
1011
+ let allocated = false;
1012
+ try {
1013
+ const parsed = await ParseSogMetaAsTextures(meta.sogData, meta.subRootUrl, this._scene, !this._useGpuPositionReadback, this._downloadManager, fileId);
1014
+ const pack = parsed.sogTextures;
1015
+ if (!pack) {
1016
+ return;
1017
+ }
1018
+ // Serialize the allocate -> decode -> readback section: a relayout runs only inside it (see
1019
+ // _relayoutAndAllocateAsync), so it never moves a file whose decode has not finished writing.
1020
+ const release = await this._acquireDecodeGateAsync();
1021
+ try {
1022
+ if (this._disposed || !this._workBuffer || this._cancelledDecodes.has(fileId)) {
1023
+ return;
1024
+ }
1025
+ let base = this._residency.allocate(fileId, count);
1026
+ if (base === null) {
1027
+ // Defragment the work buffer to reclaim fragmented free space, then retry.
1028
+ base = await this._relayoutAndAllocateAsync(fileId, count);
1029
+ }
1030
+ if (base === null) {
1031
+ // No room even after evicting and compacting: refuse and keep nodes on their current LOD.
1032
+ // A file cancelled mid-flight isn't a budget problem, so don't warn for it.
1033
+ if (!this._cancelledDecodes.has(fileId)) {
1034
+ Logger.Warn(`GaussianSplattingStream: resident memory budget full; skipping LOD file ${fileId}.`);
1035
+ }
1036
+ return;
1037
+ }
1038
+ allocated = true;
1039
+ if (this._disposed || !this._workBuffer || this._cancelledDecodes.has(fileId)) {
1040
+ return;
1041
+ }
1042
+ await this._workBuffer.decodeAsync(pack, base);
1043
+ if (this._disposed || this._cancelledDecodes.has(fileId)) {
1044
+ return;
1045
+ }
1046
+ await this._applyDecodedPositionsAsync(pack, base, count);
1047
+ if (this._disposed) {
1048
+ return;
1049
+ }
1050
+ this._decodedFiles.add(fileId);
1051
+ // Promote any nodes that can now reach their desired LOD via this newly decoded file.
1052
+ if (this._applyDesiredLods()) {
1053
+ this._refreshActiveRanges();
1054
+ }
1055
+ }
1056
+ finally {
1057
+ GaussianSplattingStream._DisposePack(pack);
1058
+ release();
1059
+ }
1060
+ }
1061
+ catch (e) {
1062
+ // A cancelled file rejects its downloads on purpose — swallow that; re-throw genuine failures.
1063
+ if (!this._cancelledDecodes.has(fileId)) {
1064
+ throw e;
1065
+ }
1066
+ }
1067
+ finally {
1068
+ // If a slot was allocated but the decode did not complete (cancelled/disposed), release it.
1069
+ if (allocated && !this._decodedFiles.has(fileId)) {
1070
+ this._residency.free(fileId);
1071
+ }
1072
+ this._loadingFiles.delete(fileId);
1073
+ this._cancelledDecodes.delete(fileId);
1074
+ }
1075
+ }
1076
+ /**
1077
+ * Acquires the decode gate (a simple async mutex). Resolves once any prior holder releases, returning a
1078
+ * release function the caller must invoke in a `finally`.
1079
+ * @returns the release function
1080
+ */
1081
+ async _acquireDecodeGateAsync() {
1082
+ const previous = this._decodeGate;
1083
+ let release;
1084
+ this._decodeGate = new Promise((resolve) => {
1085
+ release = resolve;
1086
+ });
1087
+ await previous;
1088
+ return release;
1089
+ }
1090
+ /**
1091
+ * Defragments the work buffer to make room for a file that did not fit, then allocates its slot. Runs the
1092
+ * compaction + GPU relayout atomically inside a single `onBeforeRender` so no inconsistent CPU/GPU layout
1093
+ * is ever rendered. Returns the new slot offset, or null if even compaction cannot free enough contiguous
1094
+ * space (the caller refuses the upgrade).
1095
+ * @param fileId file to allocate after compaction
1096
+ * @param count splats the file needs
1097
+ * @returns the allocated offset, or null
1098
+ */
1099
+ async _relayoutAndAllocateAsync(fileId, count) {
1100
+ if (!this._residency || !this._workBuffer) {
1101
+ return null;
1102
+ }
1103
+ // Even a perfect compaction cannot help if the total free space is below what is needed.
1104
+ if (this._residency.freeSize < count) {
1105
+ return null;
1106
+ }
1107
+ return await new Promise((resolve) => {
1108
+ const attempt = () => {
1109
+ // Bail out (no relayout) if the file was cancelled while we waited for the shader to be ready,
1110
+ // so rapidly-changing targets don't trigger an expensive compaction for a file no longer needed.
1111
+ if (this._disposed || !this._residency || !this._workBuffer || this._cancelledDecodes.has(fileId)) {
1112
+ resolve(null);
1113
+ return;
1114
+ }
1115
+ if (!this._workBuffer.isRelayoutReady()) {
1116
+ this._scene.onBeforeRenderObservable.addOnce(attempt);
1117
+ return;
1118
+ }
1119
+ this._performRelayout();
1120
+ resolve(this._residency.allocate(fileId, count));
1121
+ };
1122
+ this._scene.onBeforeRenderObservable.addOnce(attempt);
1123
+ });
1124
+ }
1125
+ /**
1126
+ * Compacts the resident set and relocates the corresponding GPU textures and CPU positions to the new
1127
+ * layout. Must run at a frame-safe point with the work buffer's relayout shader ready.
1128
+ */
1129
+ _performRelayout() {
1130
+ if (!this._residency || !this._workBuffer || !this._splatPositions) {
1131
+ return;
1132
+ }
1133
+ const oldOffsets = this._relayoutOldOffsets;
1134
+ oldOffsets.clear();
1135
+ for (const block of this._residency.getResidentBlocks()) {
1136
+ oldOffsets.set(block.file, block.offset);
1137
+ }
1138
+ const moves = this._residency.compact();
1139
+ if (moves.length === 0) {
1140
+ return;
1141
+ }
1142
+ const capacity = this._residency.capacity;
1143
+ if (!this._relayoutSrcIndex || this._relayoutSrcIndex.length !== capacity) {
1144
+ this._relayoutSrcIndex = new Float32Array(capacity);
1145
+ }
1146
+ const srcIndexByDst = this._relayoutSrcIndex;
1147
+ srcIndexByDst.fill(-1);
1148
+ const resident = this._residency.getResidentBlocks();
1149
+ // Destination->source splat index map for the GPU relayout pass.
1150
+ for (const block of resident) {
1151
+ const oldOffset = oldOffsets.get(block.file);
1152
+ for (let k = 0; k < block.count; k++) {
1153
+ srcIndexByDst[block.offset + k] = oldOffset + k;
1154
+ }
1155
+ }
1156
+ // GPU: relocate the decoded textures in place (same texture instances).
1157
+ this._workBuffer.relayoutSync(srcIndexByDst);
1158
+ // CPU positions: compaction only ever moves a block to a lower offset, so copying in place in ascending
1159
+ // new-offset order is safe (a block's source is never overwritten by an earlier move). This avoids a
1160
+ // full capacity*4 scratch buffer.
1161
+ const positions = this._splatPositions;
1162
+ resident.sort((a, b) => a.offset - b.offset);
1163
+ for (const block of resident) {
1164
+ const oldOffset = oldOffsets.get(block.file);
1165
+ if (oldOffset !== block.offset) {
1166
+ positions.copyWithin(block.offset * 4, oldOffset * 4, (oldOffset + block.count) * 4);
1167
+ }
1168
+ }
1169
+ // Update the environment offset (it may have moved), re-post to the sort worker, and refresh ranges.
1170
+ if (this._environmentRange) {
1171
+ const envOffset = this._residency.offset(EnvironmentFileId);
1172
+ if (envOffset !== undefined) {
1173
+ this._environmentRange.offset = envOffset;
1174
+ }
1175
+ }
1176
+ this._notifyWorkerNewData();
1177
+ this._refreshActiveRanges();
1178
+ }
1179
+ /**
1180
+ * Drops a file evicted by the residency controller from the decoded set so it will be re-decoded on demand.
1181
+ * The file had no remaining references, so no node was rendering or downloading it.
1182
+ * @param fileId evicted file index
1183
+ */
1184
+ _onFileEvicted(fileId) {
1185
+ this._decodedFiles.delete(fileId);
1186
+ }
1187
+ /**
1188
+ * Snaps a desired LOD level to the nearest level the node provides, while never selecting a level finer
1189
+ * than {@link maxDetailLod} (i.e. with an index below the cap). Ties prefer the finer allowed level. If
1190
+ * the node has no level at or coarser than the cap, its coarsest available level is used.
1191
+ * @param node leaf node
1192
+ * @param desired desired LOD level
1193
+ * @returns the chosen available level
1194
+ */
1195
+ _cappedLevelForNode(node, desired) {
1196
+ const levels = node.availableLevels;
1197
+ const floor = this._maxDetailLod;
1198
+ let best = -1;
1199
+ let bestDiff = Number.POSITIVE_INFINITY;
1200
+ for (const level of levels) {
1201
+ if (level < floor) {
1202
+ continue;
1203
+ }
1204
+ const diff = Math.abs(level - desired);
1205
+ if (diff < bestDiff) {
1206
+ best = level;
1207
+ bestDiff = diff;
1208
+ }
1209
+ }
1210
+ // No level is coarse enough to satisfy the cap: fall back to the coarsest the node has.
1211
+ return best < 0 ? node.baseLod : best;
1212
+ }
1213
+ /**
1214
+ * Computes each node's {@link ISOGLODNode.targetLevel}: the distance-based optimal level snapped to an
1215
+ * available level, capped so no node renders finer (more detailed) than {@link maxDetailLod}.
1216
+ */
1217
+ _computeTargetLevels() {
1218
+ for (const node of this._leafNodes) {
1219
+ const desired = node.optimalLod ?? node.baseLod;
1220
+ node.targetLevel = this._cappedLevelForNode(node, desired);
1221
+ }
1222
+ }
1223
+ /**
1224
+ * Applies each node's {@link ISOGLODNode.targetLevel}: switches a node to its target level when that
1225
+ * level's file is already decoded, otherwise records a pending download request for the file and leaves
1226
+ * the node on its current LOD (so nothing ever disappears). Nodes within their post-switch cooldown are
1227
+ * left untouched to damp oscillation (and keep their existing pending request).
1228
+ *
1229
+ * Each node tracks the single file it currently needs but lacks ({@link ISOGLODNode.pendingFile}). When a
1230
+ * node's target changes before that file finished downloading, the old file's reference is released; if no
1231
+ * other node still needs it, its queued/in-flight download is cancelled (see {@link _releaseFileRef}).
1232
+ * @returns true when at least one node changed LOD (callers should refresh the active ranges)
1233
+ */
1234
+ _applyDesiredLods() {
1235
+ let dirty = false;
1236
+ for (const node of this._leafNodes) {
1237
+ // Nodes in cooldown keep their current LOD and their existing pending request untouched.
1238
+ if (node.lodCooldown && node.lodCooldown > 0) {
1239
+ continue;
1240
+ }
1241
+ const desired = node.targetLevel ?? node.baseLod;
1242
+ let newPending;
1243
+ if (desired !== node.activeLod) {
1244
+ const entry = node.lods[String(desired)];
1245
+ if (entry) {
1246
+ if (this._decodedFiles.has(entry.file)) {
1247
+ this._switchActiveFile(node, entry.file);
1248
+ node.activeLod = desired;
1249
+ node.lodCooldown = this._lodCooldownFrames;
1250
+ dirty = true;
1251
+ }
1252
+ else {
1253
+ newPending = entry.file;
1254
+ }
1255
+ }
1256
+ }
1257
+ // Reconcile this node's pending-download reference against its (possibly changed) target.
1258
+ if (node.pendingFile !== newPending) {
1259
+ if (node.pendingFile !== undefined) {
1260
+ this._releaseFileRef(node.pendingFile);
1261
+ }
1262
+ if (newPending !== undefined) {
1263
+ this._acquirePendingFile(newPending);
1264
+ }
1265
+ node.pendingFile = newPending;
1266
+ }
1267
+ }
1268
+ return dirty;
1269
+ }
1270
+ /**
1271
+ * Moves a node's resident reference from its previous active file to the one it now renders, so the file
1272
+ * count that keeps a block in the work buffer stays accurate (and cancels any pending eviction of the new
1273
+ * file). The new file is already decoded.
1274
+ * @param node leaf node switching its rendered file
1275
+ * @param file the file the node now renders from
1276
+ */
1277
+ _switchActiveFile(node, file) {
1278
+ if (node.activeFile === file) {
1279
+ return;
1280
+ }
1281
+ if (node.activeFile !== undefined) {
1282
+ this._releaseFileRef(node.activeFile);
1283
+ }
1284
+ this._acquireFileRef(file);
1285
+ node.activeFile = file;
1286
+ }
1287
+ /**
1288
+ * Adds a reference to a file (active render or pending download), cancelling any scheduled eviction.
1289
+ * @param fileId file index
1290
+ */
1291
+ _acquireFileRef(fileId) {
1292
+ const refs = (this._fileRefs.get(fileId) ?? 0) + 1;
1293
+ this._fileRefs.set(fileId, refs);
1294
+ if (refs === 1) {
1295
+ // Referenced again before its eviction cooldown elapsed: keep it resident.
1296
+ this._residency?.cancelEviction(fileId);
1297
+ }
1298
+ }
1299
+ /**
1300
+ * Records that a node needs a not-yet-decoded file, bumping its reference count and queueing the decode.
1301
+ * @param fileId file index the node now targets
1302
+ */
1303
+ _acquirePendingFile(fileId) {
1304
+ this._acquireFileRef(fileId);
1305
+ this._enqueueDecode(fileId);
1306
+ }
1307
+ /**
1308
+ * Releases a node's reference to a file. When the last reference is dropped: a decoded file is scheduled
1309
+ * for eviction (when streaming under a budget), and a still-downloading file has its queued decode dropped
1310
+ * and any in-flight download cancelled.
1311
+ * @param fileId file index the node no longer references
1312
+ */
1313
+ _releaseFileRef(fileId) {
1314
+ const refs = (this._fileRefs.get(fileId) ?? 0) - 1;
1315
+ if (refs > 0) {
1316
+ this._fileRefs.set(fileId, refs);
1317
+ return;
1318
+ }
1319
+ this._fileRefs.delete(fileId);
1320
+ if (this._decodedFiles.has(fileId)) {
1321
+ // No node renders it anymore: schedule eviction (only when streaming under a budget).
1322
+ if (this._evictionEnabled) {
1323
+ this._residency?.scheduleEviction(fileId);
1324
+ }
1325
+ return;
1326
+ }
1327
+ // Still downloading/queued: drop the queued decode and cancel any in-flight download.
1328
+ const queueIndex = this._decodeQueue.indexOf(fileId);
1329
+ if (queueIndex !== -1) {
1330
+ this._decodeQueue.splice(queueIndex, 1);
1331
+ }
1332
+ if (this._loadingFiles.has(fileId)) {
1333
+ // Flag the in-flight decode to bail at its next checkpoint and cancel its image downloads.
1334
+ this._cancelledDecodes.add(fileId);
1335
+ this._downloadManager.cancelGroup(fileId);
1336
+ }
1337
+ }
1338
+ /**
1339
+ * Per-frame LOD streaming loop. Ticks cooldowns and pumps the decode queue every frame, and runs the
1340
+ * cheap per-node frustum test every frame so the off-screen LOD bias tracks camera rotation. The LOD
1341
+ * re-evaluation is throttled to at most every {@link _lodUpdateInterval} frames once the camera has
1342
+ * translated far enough, but also runs immediately whenever a node enters/leaves the frustum (so its
1343
+ * detail upgrades/downgrades promptly) or a cap change forces it. Active ranges rebuild on any LOD change.
1344
+ */
1345
+ _onLodFrame() {
1346
+ if (this._disposed || !this._baseLayerReady) {
1347
+ return;
1348
+ }
1349
+ for (const node of this._leafNodes) {
1350
+ if (node.lodCooldown && node.lodCooldown > 0) {
1351
+ node.lodCooldown--;
1352
+ }
1353
+ }
1354
+ // Tick eviction cooldowns: unreferenced files are freed once their cooldown elapses (budgeted streaming).
1355
+ if (this._evictionEnabled) {
1356
+ this._residency?.tick();
1357
+ }
1358
+ // In-flight/queued decodes still progress every frame.
1359
+ this._pumpDecodeQueue();
1360
+ // Per-node frustum test runs every frame (cheap) so the off-screen LOD bias tracks camera rotation,
1361
+ // not just the translation that gates the throttled LOD re-evaluation below.
1362
+ const frustumChanged = this._updateNodeFrustum();
1363
+ let runLodEval = this._forceLodUpdate || frustumChanged;
1364
+ if (!runLodEval && ++this._framesSinceLodUpdate >= this._lodUpdateInterval) {
1365
+ const camera = this._scene.activeCamera;
1366
+ const threshold = this._lodUpdateDistance;
1367
+ if (!camera || Vector3.DistanceSquared(camera.globalPosition, this._lastLodCamPos) >= threshold * threshold) {
1368
+ if (camera) {
1369
+ this._lastLodCamPos.copyFrom(camera.globalPosition);
1370
+ }
1371
+ runLodEval = true;
1372
+ }
1373
+ }
1374
+ if (runLodEval) {
1375
+ this._forceLodUpdate = false;
1376
+ this._framesSinceLodUpdate = 0;
1377
+ this.evaluateOptimalLods(this._scene.activeCamera);
1378
+ this._computeTargetLevels();
1379
+ if (this._applyDesiredLods()) {
1380
+ this._refreshActiveRanges();
1381
+ }
1382
+ }
1383
+ }
1384
+ /**
1385
+ * Updates each leaf node's {@link ISOGLODNode.inFrustum} flag from a per-node frustum test against the
1386
+ * active camera. When {@link frustumCulling} is disabled (or there is no camera) every node is marked
1387
+ * in-frustum. Bounds are static (from the LOD tree), so flags are valid for all nodes regardless of
1388
+ * decode state. Returns true when any node's in-frustum state changed (so the LOD bias must be re-applied).
1389
+ * @returns whether any node's in-frustum state changed
1390
+ */
1391
+ _updateNodeFrustum() {
1392
+ const camera = this._scene.activeCamera;
1393
+ let changed = false;
1394
+ if (!this._frustumCulling || !camera) {
1395
+ for (const node of this._leafNodes) {
1396
+ if (node.inFrustum === false) {
1397
+ node.inFrustum = true;
1398
+ changed = true;
1399
+ }
1400
+ }
1401
+ return changed;
1402
+ }
1403
+ // World-space frustum planes from the current view-projection, tested against each node's world AABB.
1404
+ // force=false uses the renderId/sync fast-path (still recomputes when the transform actually changed),
1405
+ // avoiding a full world-matrix recompute every frame for the per-node frustum test.
1406
+ const world = this.computeWorldMatrix(false);
1407
+ camera.getViewMatrix().multiplyToRef(camera.getProjectionMatrix(), this._cullViewProj);
1408
+ Frustum.GetPlanesToRef(this._cullViewProj, this._frustumPlanes);
1409
+ for (const node of this._leafNodes) {
1410
+ node.cullBounds.update(world);
1411
+ const inFrustum = node.cullBounds.isInFrustum(this._frustumPlanes);
1412
+ if (inFrustum !== node.inFrustum) {
1413
+ node.inFrustum = inFrustum;
1414
+ changed = true;
1415
+ }
1416
+ }
1417
+ return changed;
1418
+ }
1419
+ /**
1420
+ * Reads the splat count from SOG metadata.
1421
+ * @param data SOG metadata
1422
+ * @returns the splat count
1423
+ */
1424
+ static _GetSplatCount(data) {
1425
+ return data.count ?? (Array.isArray(data.means.shape) ? data.means.shape[0] : 0);
1426
+ }
1427
+ /**
1428
+ * Disposes all GPU source textures of a SOG pack (they are only needed for the one decode pass).
1429
+ * @param pack the SOG texture pack
1430
+ */
1431
+ static _DisposePack(pack) {
1432
+ pack.meansTextureL.dispose();
1433
+ pack.meansTextureU.dispose();
1434
+ pack.scalesTexture.dispose();
1435
+ pack.quatsTexture.dispose();
1436
+ pack.sh0Texture.dispose();
1437
+ pack.shCentroidsTexture?.dispose();
1438
+ pack.shLabelsTexture?.dispose();
1439
+ pack.codebookTexture?.dispose();
1440
+ }
1441
+ /**
1442
+ * Expands the running splat-center bounds with a newly decoded file's centers and updates the
1443
+ * mesh bounding info so the GS is correctly frustum-culled and pickable.
1444
+ * @param positions stride-4 splat centers for the new file
1445
+ * @param count number of splats
1446
+ */
1447
+ _updateBounds(positions, count) {
1448
+ const min = this._boundsMin;
1449
+ const max = this._boundsMax;
1450
+ for (let i = 0; i < count; i++) {
1451
+ const x = positions[i * 4 + 0];
1452
+ const y = positions[i * 4 + 1];
1453
+ const z = positions[i * 4 + 2];
1454
+ min.minimizeInPlaceFromFloats(x, y, z);
1455
+ max.maximizeInPlaceFromFloats(x, y, z);
1456
+ }
1457
+ this.setBoundingInfo(new BoundingInfo(min, max));
1458
+ }
1459
+ /**
1460
+ * Rebuilds the active interval set from the environment plus each node's currently-selected LOD entry,
1461
+ * coalesces adjacent ranges, and pushes the result to the sort worker.
1462
+ */
1463
+ _refreshActiveRanges() {
1464
+ const ranges = [];
1465
+ if (this._environmentRange) {
1466
+ ranges.push({ offset: this._environmentRange.offset, count: this._environmentRange.count });
1467
+ }
1468
+ for (const node of this._leafNodes) {
1469
+ if (node.activeLod === undefined) {
1470
+ continue;
1471
+ }
1472
+ const entry = node.lods[String(node.activeLod)];
1473
+ if (!entry) {
1474
+ continue;
1475
+ }
1476
+ const base = this._residency?.offset(entry.file);
1477
+ if (base === undefined) {
1478
+ continue;
1479
+ }
1480
+ ranges.push({ offset: base + entry.offset, count: entry.count });
1481
+ }
1482
+ this.setSplatIndexRanges(GaussianSplattingStream._CoalesceRanges(ranges));
1483
+ }
1484
+ /**
1485
+ * Sorts and merges adjacent/overlapping ranges to keep the interval list compact.
1486
+ * @param ranges raw ranges
1487
+ * @returns coalesced ranges
1488
+ */
1489
+ static _CoalesceRanges(ranges) {
1490
+ if (ranges.length <= 1) {
1491
+ return ranges;
1492
+ }
1493
+ const sorted = ranges.slice().sort((a, b) => a.offset - b.offset);
1494
+ const merged = [{ offset: sorted[0].offset, count: sorted[0].count }];
1495
+ for (let i = 1; i < sorted.length; i++) {
1496
+ const last = merged[merged.length - 1];
1497
+ const range = sorted[i];
1498
+ const lastEnd = last.offset + last.count;
1499
+ if (range.offset <= lastEnd) {
1500
+ const end = Math.max(lastEnd, range.offset + range.count);
1501
+ last.count = end - last.offset;
1502
+ }
1503
+ else {
1504
+ merged.push({ offset: range.offset, count: range.count });
1505
+ }
1506
+ }
1507
+ return merged;
1508
+ }
1509
+ /**
1510
+ * Unzips a `.sog` bundle into a name -> bytes map, loading fflate on demand.
1511
+ * @param data zipped bytes
1512
+ * @returns map of entry name to bytes
1513
+ */
1514
+ async _unzipAsync(data) {
1515
+ let fflateModule = this._streamOptions.fflate;
1516
+ if (!fflateModule) {
1517
+ if (typeof window.fflate === "undefined") {
1518
+ await Tools.LoadScriptAsync(this._streamOptions.deflateURL ?? "https://unpkg.com/fflate/umd/index.js");
1519
+ }
1520
+ fflateModule = window.fflate;
1521
+ }
1522
+ const unzipped = fflateModule.unzipSync(data);
1523
+ const files = new Map();
1524
+ for (const [name, content] of Object.entries(unzipped)) {
1525
+ files.set(name, content);
1526
+ }
1527
+ return files;
1528
+ }
1529
+ }
1530
+ //# sourceMappingURL=gaussianSplattingStream.js.map