@pmndrs/vdb 0.0.0-stage → 0.2.0

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 (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,409 @@
1
+ /**
2
+ * `NvdbStreamReader` (K4.16): read a `.nvdb` file from pushed bytes and emit
3
+ * each grid as soon as its data is complete, so a coarse preview written first
4
+ * (docs/dev/design/K4-5-coarse-first.md, option a) can be drawn while the full
5
+ * grid is still downloading.
6
+ *
7
+ * const reader = new NvdbStreamReader();
8
+ * for await (const chunk of response.body) for (const g of reader.push(chunk)) show(g);
9
+ * reader.end(); // throws if the stream stopped mid-grid
10
+ *
11
+ * The framing is NanoVDB's `io::Segment` (IO.h; see `nvdb-file.ts`): a 16-byte
12
+ * FileHeader, then a 176-byte FileMetaData + name per grid, then each grid's
13
+ * data (the image for codec NONE; a u64 size + zlib stream for codec ZIP; one
14
+ * or more u64 size + Blosc1 frame chunks for codec BLOSC, K7.C). A file is one
15
+ * or more segments. Every size the reader allocates is declared up front, so it
16
+ * checks each one before allocating:
17
+ *
18
+ * - `gridSize` must be a safe integer, at least a GridData header, and at most
19
+ * `maxGridBytes` (default 1 GiB);
20
+ * - a ZIP payload must be at most zlib's `compressBound(gridSize)` (+64), and
21
+ * inflates into gridSize + 1 bytes at most (`inflateZipGrid`);
22
+ * - a BLOSC chunk must be at most the grid bytes still missing + its 16-byte
23
+ * header (`bloscChunkBound`), and decodes straight into the grid's buffer,
24
+ * never past it;
25
+ * - a grid name is at most `maxNameBytes` (default 64 KiB).
26
+ *
27
+ * Memory: the reader holds the current segment's metadata and the grid it is
28
+ * filling, never the whole file. Emitted images are handed off (a fresh buffer
29
+ * per grid, 4-byte aligned, so `image` is a zero-copy `Uint32Array`).
30
+ *
31
+ * Errors are `NvdbFormatError` (a `VDBToolsError`) for malformed or
32
+ * truncated data and `VDBUnsupportedError` for valid data out of scope (a raw
33
+ * `NanoVDB1` grid buffer, another NanoVDB major version, unsupported grid
34
+ * types or Blosc codecs). After an error the reader is failed: every later
35
+ * `push` rethrows it.
36
+ */
37
+ import { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from "./errors.js";
38
+ import { NvdbCodec, FILE_HEADER_SIZE, FILE_METADATA_SIZE, GRID_DATA_SIZE, assertSafeGridSize, checkBloscChunkSize, decodeBloscChunk, decodeCString, finishGridRecord, gridClassName, gridTypeName, inflateZipGrid, isFileHeaderMagic, readFileHeader, readFileMetaData, validateGridType, } from "./nvdb-file.js";
39
+ export { NvdbFormatError };
40
+ /**
41
+ * The byte length of a `fetch` Response's body when the header says so: its
42
+ * Content-Length, unless a Content-Encoding makes the (decoded) bytes the
43
+ * reader sees differ from it. Null when unknown.
44
+ */
45
+ export function nvdbResponseLength(response) {
46
+ const encoding = response.headers.get("content-encoding");
47
+ if (encoding !== null && encoding.trim() !== "" && encoding.trim().toLowerCase() !== "identity")
48
+ return null;
49
+ const raw = response.headers.get("content-length");
50
+ if (raw === null || !/^\d+$/.test(raw.trim()))
51
+ return null;
52
+ const n = Number(raw);
53
+ return Number.isSafeInteger(n) ? n : null;
54
+ }
55
+ const DEFAULT_MAX_GRID_BYTES = 1 << 30;
56
+ const DEFAULT_MAX_NAME_BYTES = 1 << 16;
57
+ const ZIP_PREFIX = 8;
58
+ /** zlib's `compressBound` (the largest `compress()` output for `n` input bytes), plus slack. */
59
+ function zipBound(n) {
60
+ return n + Math.floor(n / 4096) + Math.floor(n / 16384) + Math.floor(n / 33554432) + 13 + 64;
61
+ }
62
+ const LOD_SUFFIX = /^(.*)\.lod(\d+)$/;
63
+ /**
64
+ * The preview name for `name` at `resolution`: `<name>.lod<resolution>` (K4.5).
65
+ *
66
+ * @param name The full grid's name.
67
+ * @param resolution Preview resolution, a positive integer.
68
+ */
69
+ export function nvdbLodName(name, resolution) {
70
+ if (!Number.isInteger(resolution) || resolution < 1) {
71
+ throw new VDBToolsError("VDB_BAD_OPTION", `nvdbLodName: resolution must be a positive integer, got ${resolution}`);
72
+ }
73
+ return `${name}.lod${resolution}`;
74
+ }
75
+ /** Splits a `<name>.lod<N>` preview name; a full grid's name gives `lod: null`. */
76
+ export function parseNvdbLodName(name) {
77
+ const m = LOD_SUFFIX.exec(name);
78
+ return m ? { baseName: m[1], lod: Number(m[2]) } : { baseName: name, lod: null };
79
+ }
80
+ /**
81
+ * Push-based `.nvdb` reader: `push(chunk)` returns the grids that chunk
82
+ * completed. Call `end()` when the stream ends to detect truncation.
83
+ */
84
+ export class NvdbStreamReader {
85
+ #maxGridBytes;
86
+ #maxNameBytes;
87
+ #onProgress;
88
+ #declaredTotal;
89
+ #segmentStart = 0;
90
+ #knownEnd = null;
91
+ /** Small fixed-size fields (FileHeader, FileMetaData, ZIP prefix) and names. */
92
+ #scratch = new Uint8Array(FILE_METADATA_SIZE);
93
+ /** The buffer being filled (scratch or a grid payload) and how far. */
94
+ #target;
95
+ #filled = 0;
96
+ #phase = "header";
97
+ #codec = NvdbCodec.NONE;
98
+ #segmentGrids = 0;
99
+ #pending = [];
100
+ #nextMeta = null;
101
+ #gridInSegment = 0;
102
+ #received = 0;
103
+ /** BLOSC: the grid image being filled chunk by chunk, and how much of it is decoded. */
104
+ #gridBuffer = null;
105
+ #gridFilled = 0;
106
+ #segments = 0;
107
+ #emitted = 0;
108
+ #failed = null;
109
+ #grids = [];
110
+ /** @param options Size limits, a known total size and a progress callback. */
111
+ constructor(options = {}) {
112
+ this.#maxGridBytes = options.maxGridBytes ?? DEFAULT_MAX_GRID_BYTES;
113
+ this.#maxNameBytes = options.maxNameBytes ?? DEFAULT_MAX_NAME_BYTES;
114
+ if (!Number.isSafeInteger(this.#maxGridBytes) || this.#maxGridBytes < GRID_DATA_SIZE) {
115
+ throw new VDBToolsError("VDB_BAD_OPTION", `NvdbStreamReader: maxGridBytes must be an integer >= ${GRID_DATA_SIZE}`);
116
+ }
117
+ if (!Number.isSafeInteger(this.#maxNameBytes) || this.#maxNameBytes < 1) {
118
+ throw new VDBToolsError("VDB_BAD_OPTION", "NvdbStreamReader: maxNameBytes must be a positive integer");
119
+ }
120
+ this.#onProgress = options.onProgress;
121
+ this.#declaredTotal = options.bytesTotal ?? null;
122
+ if (this.#declaredTotal !== null && (!Number.isSafeInteger(this.#declaredTotal) || this.#declaredTotal < 0)) {
123
+ throw new VDBToolsError("VDB_BAD_OPTION", "NvdbStreamReader: bytesTotal must be a non-negative integer");
124
+ }
125
+ this.#target = this.#scratch.subarray(0, FILE_HEADER_SIZE);
126
+ }
127
+ /** The expected file size in bytes, or null while unknown (see {@link NvdbProgress.bytesTotal}). */
128
+ get bytesTotal() {
129
+ return this.#declaredTotal ?? this.#knownEnd;
130
+ }
131
+ /** Progress so far. */
132
+ get progress() {
133
+ return { bytesReceived: this.#received, bytesTotal: this.bytesTotal, gridsEmitted: this.#emitted };
134
+ }
135
+ /** File bytes pushed so far. */
136
+ get bytesReceived() {
137
+ return this.#received;
138
+ }
139
+ /** Grids emitted so far. */
140
+ get gridsEmitted() {
141
+ return this.#emitted;
142
+ }
143
+ /**
144
+ * Metadata of every grid whose FileMetaData has arrived, in file order,
145
+ * including grids whose data has not (a segment lists all its grids before
146
+ * any data, so the full grid's `gridByteSize` is known before its preview
147
+ * is emitted). Names are as stored; see {@link parseNvdbLodName}.
148
+ */
149
+ get grids() {
150
+ return this.#grids;
151
+ }
152
+ /** True between segments: every grid announced so far has been emitted. */
153
+ get atBoundary() {
154
+ return this.#phase === "header" && this.#filled === 0 && this.#segments > 0;
155
+ }
156
+ /** Pushes the next bytes of the file; returns the grids they completed, in order. */
157
+ push(chunk) {
158
+ if (this.#failed)
159
+ throw this.#failed;
160
+ const out = [];
161
+ try {
162
+ let at = 0;
163
+ while (at < chunk.byteLength) {
164
+ const take = Math.min(chunk.byteLength - at, this.#target.byteLength - this.#filled);
165
+ this.#target.set(chunk.subarray(at, at + take), this.#filled);
166
+ this.#filled += take;
167
+ at += take;
168
+ this.#received += take;
169
+ if (this.#filled === this.#target.byteLength)
170
+ this.#advance(out);
171
+ }
172
+ // A zero-length target (an empty name) completes without bytes.
173
+ while (this.#target.byteLength === 0 && this.#filled === 0 && this.#phase !== "header")
174
+ this.#advance(out);
175
+ }
176
+ catch (err) {
177
+ this.#failed = err instanceof VDBToolsError ? err : new NvdbFormatError(err.message);
178
+ throw this.#failed;
179
+ }
180
+ if (this.#onProgress && chunk.byteLength > 0)
181
+ this.#onProgress(this.progress);
182
+ return out;
183
+ }
184
+ /** Declares the end of the stream; throws `NvdbFormatError` if it stopped inside a segment. */
185
+ end() {
186
+ if (this.#failed)
187
+ throw this.#failed;
188
+ if (this.atBoundary)
189
+ return;
190
+ this.#failed = new NvdbFormatError(`the stream ended after ${this.#received} bytes, in the ${this.#describe()}; the file is truncated.`);
191
+ throw this.#failed;
192
+ }
193
+ #describe() {
194
+ const grid = this.#segmentFirst() + this.#gridInSegment;
195
+ switch (this.#phase) {
196
+ case "header":
197
+ return `FileHeader, ${this.#filled} of ${FILE_HEADER_SIZE} bytes`;
198
+ case "meta":
199
+ return `FileMetaData of grid #${this.#grids.length}, ${this.#filled} of ${FILE_METADATA_SIZE} bytes`;
200
+ case "name":
201
+ return `name of grid #${this.#grids.length}`;
202
+ case "zipPrefix":
203
+ return `ZIP size prefix of grid #${grid}`;
204
+ case "bloscPrefix":
205
+ return `BLOSC chunk size of grid #${grid}, ${this.#gridFilled} of ${this.#gridBuffer?.byteLength ?? 0} bytes decoded`;
206
+ case "bloscChunk":
207
+ return `BLOSC chunk of grid #${grid}, ${this.#filled} of ${this.#target.byteLength} bytes`;
208
+ case "grid":
209
+ return `data of grid #${grid}, ${this.#filled} of ${this.#target.byteLength} bytes`;
210
+ }
211
+ }
212
+ #segmentFirst() {
213
+ return this.#grids.length - this.#segmentGrids;
214
+ }
215
+ #expect(phase, target) {
216
+ this.#phase = phase;
217
+ this.#target = target;
218
+ this.#filled = 0;
219
+ }
220
+ #advance(out) {
221
+ switch (this.#phase) {
222
+ case "header": {
223
+ const magic = String.fromCharCode(...this.#scratch.subarray(0, 8));
224
+ if (!isFileHeaderMagic(magic)) {
225
+ if (magic === "NanoVDB1") {
226
+ throw new VDBUnsupportedError(".nvdb stream: this is a raw NanoVDB grid buffer (magic NanoVDB1), not a segment file; read it whole with NvdbFile.fromArrayBuffer.");
227
+ }
228
+ throw new NvdbFormatError(`expected a NanoVDB FileHeader (magic NanoVDB2 or NanoVDB0) at byte ${this.#received - FILE_HEADER_SIZE}, found "${magic.replace(/[^\x20-\x7e]/g, "?")}".`);
229
+ }
230
+ const view = new DataView(this.#scratch.buffer, 0, FILE_HEADER_SIZE);
231
+ const header = readFileHeader(view, 0);
232
+ if (header.gridCount === 0)
233
+ throw new NvdbFormatError(`segment #${this.#segments} declares 0 grids.`);
234
+ this.#codec = header.codec;
235
+ this.#segmentGrids = header.gridCount;
236
+ this.#segments++;
237
+ this.#segmentStart = this.#received - FILE_HEADER_SIZE;
238
+ this.#pending = [];
239
+ this.#gridInSegment = 0;
240
+ this.#expect("meta", this.#scratch.subarray(0, FILE_METADATA_SIZE));
241
+ return;
242
+ }
243
+ case "meta": {
244
+ const i = this.#grids.length;
245
+ const meta = readFileMetaData(new DataView(this.#scratch.buffer, 0, FILE_METADATA_SIZE), 0);
246
+ assertSafeGridSize(meta.gridSize, `grid #${i}'s FileMetaData.gridSize`);
247
+ if (meta.gridSize < GRID_DATA_SIZE) {
248
+ throw new NvdbFormatError(`grid #${i} declares gridSize ${meta.gridSize}, smaller than a ${GRID_DATA_SIZE}-byte GridData header.`);
249
+ }
250
+ if (meta.gridSize > this.#maxGridBytes) {
251
+ throw new NvdbFormatError(`grid #${i} declares gridSize ${meta.gridSize} bytes, over maxGridBytes (${this.#maxGridBytes}); raise the option if the file is trusted.`);
252
+ }
253
+ if (meta.nameSize > this.#maxNameBytes) {
254
+ throw new NvdbFormatError(`grid #${i} declares a ${meta.nameSize}-byte name, over maxNameBytes (${this.#maxNameBytes}).`);
255
+ }
256
+ this.#nextMeta = meta;
257
+ this.#expect("name", meta.nameSize <= this.#scratch.byteLength ? this.#scratch.subarray(0, meta.nameSize) : new Uint8Array(meta.nameSize));
258
+ return;
259
+ }
260
+ case "name": {
261
+ const meta = this.#nextMeta;
262
+ const name = decodeCString(this.#target);
263
+ const gridType = gridTypeName(meta.gridTypeId);
264
+ try {
265
+ validateGridType(gridType, name);
266
+ }
267
+ catch (err) {
268
+ throw new VDBUnsupportedError(err.message);
269
+ }
270
+ this.#pending.push({ meta, name });
271
+ this.#grids.push({
272
+ name,
273
+ gridType,
274
+ gridClass: gridClassName(meta.gridClassId),
275
+ worldBBox: meta.worldBBox,
276
+ indexBBox: meta.indexBBox,
277
+ voxelSize: meta.voxelSize,
278
+ voxelCount: meta.voxelCount,
279
+ gridByteSize: meta.gridSize,
280
+ });
281
+ this.#nextMeta = null;
282
+ if (this.#pending.length < this.#segmentGrids)
283
+ this.#expect("meta", this.#scratch.subarray(0, FILE_METADATA_SIZE));
284
+ else {
285
+ let end = this.#segmentStart + FILE_HEADER_SIZE;
286
+ for (const g of this.#pending)
287
+ end += FILE_METADATA_SIZE + g.meta.nameSize + g.meta.fileSize;
288
+ this.#knownEnd = Number.isSafeInteger(end) ? end : null;
289
+ this.#startGrid();
290
+ }
291
+ return;
292
+ }
293
+ case "zipPrefix": {
294
+ const { meta, name } = this.#pending[this.#gridInSegment];
295
+ const size = Number(new DataView(this.#scratch.buffer, 0, ZIP_PREFIX).getBigUint64(0, true));
296
+ const bound = zipBound(meta.gridSize);
297
+ if (!Number.isSafeInteger(size) || size < 1 || size > bound) {
298
+ throw new NvdbFormatError(`grid #${this.#segmentFirst() + this.#gridInSegment} ("${name}") declares a ${size}-byte ZIP payload for a ` +
299
+ `${meta.gridSize}-byte grid (zlib's bound is ${bound}).`);
300
+ }
301
+ this.#expect("grid", new Uint8Array(size));
302
+ return;
303
+ }
304
+ case "bloscPrefix": {
305
+ const { name } = this.#pending[this.#gridInSegment];
306
+ const index = this.#segmentFirst() + this.#gridInSegment;
307
+ const size = Number(new DataView(this.#scratch.buffer, 0, ZIP_PREFIX).getBigUint64(0, true));
308
+ checkBloscChunkSize(size, this.#gridBuffer.byteLength - this.#gridFilled, index, name);
309
+ this.#expect("bloscChunk", new Uint8Array(size));
310
+ return;
311
+ }
312
+ case "bloscChunk": {
313
+ const { name } = this.#pending[this.#gridInSegment];
314
+ const index = this.#segmentFirst() + this.#gridInSegment;
315
+ const grid = this.#gridBuffer;
316
+ this.#gridFilled += decodeBloscChunk(this.#target, grid.subarray(this.#gridFilled), index, name);
317
+ if (this.#gridFilled < grid.byteLength) {
318
+ this.#expect("bloscPrefix", this.#scratch.subarray(0, ZIP_PREFIX));
319
+ return;
320
+ }
321
+ this.#gridBuffer = null;
322
+ this.#finishGrid(out, grid);
323
+ return;
324
+ }
325
+ case "grid": {
326
+ const { meta, name } = this.#pending[this.#gridInSegment];
327
+ const index = this.#segmentFirst() + this.#gridInSegment;
328
+ this.#finishGrid(out, this.#codec === NvdbCodec.ZIP ? inflateZipGrid(this.#target, meta.gridSize, index, name) : this.#target);
329
+ return;
330
+ }
331
+ }
332
+ }
333
+ /** Emits the current grid from its decoded image and moves to the next grid or segment. */
334
+ #finishGrid(out, bytes) {
335
+ const k = this.#gridInSegment;
336
+ const index = this.#segmentFirst() + k;
337
+ const { meta, name } = this.#pending[k];
338
+ const record = finishGridRecord(meta, name, index, bytes);
339
+ this.#grids[index] = record.metadata;
340
+ const { baseName, lod } = parseNvdbLodName(name);
341
+ out.push({ index, metadata: record.metadata, image: record.image, bytesReceived: this.#received, bytesTotal: this.bytesTotal, lod, baseName });
342
+ this.#emitted++;
343
+ this.#gridInSegment++;
344
+ if (this.#gridInSegment < this.#segmentGrids)
345
+ this.#startGrid();
346
+ else {
347
+ this.#pending = [];
348
+ this.#expect("header", this.#scratch.subarray(0, FILE_HEADER_SIZE));
349
+ }
350
+ }
351
+ #startGrid() {
352
+ const { meta } = this.#pending[this.#gridInSegment];
353
+ if (this.#codec === NvdbCodec.ZIP)
354
+ this.#expect("zipPrefix", this.#scratch.subarray(0, ZIP_PREFIX));
355
+ else if (this.#codec === NvdbCodec.BLOSC) {
356
+ // gridSize was checked against maxGridBytes with its FileMetaData; chunks decode into this.
357
+ this.#gridBuffer = new Uint8Array(meta.gridSize);
358
+ this.#gridFilled = 0;
359
+ this.#expect("bloscPrefix", this.#scratch.subarray(0, ZIP_PREFIX));
360
+ }
361
+ else
362
+ this.#expect("grid", new Uint8Array(meta.gridSize));
363
+ }
364
+ }
365
+ function isResponse(source) {
366
+ return typeof source.headers === "object" && "body" in source;
367
+ }
368
+ /**
369
+ * Reads a byte stream (a `fetch` Response or body, or any async iterable of chunks) through
370
+ * an {@link NvdbStreamReader}, yielding each grid as it completes. Stops
371
+ * reading (and cancels the stream) when the consumer breaks out of the loop.
372
+ *
373
+ * @param source A `Response`, a response body, or an async iterable of byte chunks.
374
+ * @param options Size limits, a known total size and a progress callback.
375
+ */
376
+ export async function* readNvdbStream(source, options = {}) {
377
+ if (isResponse(source)) {
378
+ const len = nvdbResponseLength(source);
379
+ if (source.body === null)
380
+ throw new NvdbFormatError("readNvdbStream: the response has no body.");
381
+ options = len !== null && options.bytesTotal === undefined ? { ...options, bytesTotal: len } : options;
382
+ source = source.body;
383
+ }
384
+ const reader = new NvdbStreamReader(options);
385
+ if (typeof source.getReader === "function") {
386
+ const r = source.getReader();
387
+ let finished = false;
388
+ try {
389
+ for (;;) {
390
+ const { done, value } = await r.read();
391
+ if (done)
392
+ break;
393
+ yield* reader.push(value);
394
+ }
395
+ finished = true;
396
+ reader.end();
397
+ }
398
+ finally {
399
+ if (!finished)
400
+ await r.cancel().catch(() => undefined);
401
+ r.releaseLock();
402
+ }
403
+ return;
404
+ }
405
+ for await (const chunk of source)
406
+ yield* reader.push(chunk);
407
+ reader.end();
408
+ }
409
+ //# sourceMappingURL=nvdb-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nvdb-stream.js","sourceRoot":"","sources":["../../src/tools/nvdb-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBA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KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzF,MAAM,CAAC,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["/**\n * `NvdbStreamReader` (K4.16): read a `.nvdb` file from pushed bytes and emit\n * each grid as soon as its data is complete, so a coarse preview written first\n * (docs/dev/design/K4-5-coarse-first.md, option a) can be drawn while the full\n * grid is still downloading.\n *\n * const reader = new NvdbStreamReader();\n * for await (const chunk of response.body) for (const g of reader.push(chunk)) show(g);\n * reader.end(); // throws if the stream stopped mid-grid\n *\n * The framing is NanoVDB's `io::Segment` (IO.h; see `nvdb-file.ts`): a 16-byte\n * FileHeader, then a 176-byte FileMetaData + name per grid, then each grid's\n * data (the image for codec NONE; a u64 size + zlib stream for codec ZIP; one\n * or more u64 size + Blosc1 frame chunks for codec BLOSC, K7.C). A file is one\n * or more segments. Every size the reader allocates is declared up front, so it\n * checks each one before allocating:\n *\n * - `gridSize` must be a safe integer, at least a GridData header, and at most\n * `maxGridBytes` (default 1 GiB);\n * - a ZIP payload must be at most zlib's `compressBound(gridSize)` (+64), and\n * inflates into gridSize + 1 bytes at most (`inflateZipGrid`);\n * - a BLOSC chunk must be at most the grid bytes still missing + its 16-byte\n * header (`bloscChunkBound`), and decodes straight into the grid's buffer,\n * never past it;\n * - a grid name is at most `maxNameBytes` (default 64 KiB).\n *\n * Memory: the reader holds the current segment's metadata and the grid it is\n * filling, never the whole file. Emitted images are handed off (a fresh buffer\n * per grid, 4-byte aligned, so `image` is a zero-copy `Uint32Array`).\n *\n * Errors are `NvdbFormatError` (a `VDBToolsError`) for malformed or\n * truncated data and `VDBUnsupportedError` for valid data out of scope (a raw\n * `NanoVDB1` grid buffer, another NanoVDB major version, unsupported grid\n * types or Blosc codecs). After an error the reader is failed: every later\n * `push` rethrows it.\n */\n\nimport { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from \"./errors.js\";\nimport {\n NvdbCodec,\n FILE_HEADER_SIZE,\n FILE_METADATA_SIZE,\n GRID_DATA_SIZE,\n assertSafeGridSize,\n checkBloscChunkSize,\n decodeBloscChunk,\n decodeCString,\n finishGridRecord,\n gridClassName,\n gridTypeName,\n inflateZipGrid,\n isFileHeaderMagic,\n readFileHeader,\n readFileMetaData,\n validateGridType,\n type NvdbGridMetadata,\n type ParsedFileMetaData,\n} from \"./nvdb-file.js\";\n\nexport { NvdbFormatError };\n\n/** Options of {@link NvdbStreamReader} and {@link readNvdbStream}. */\nexport interface NvdbStreamReaderOptions {\n /** Largest `gridSize` (decoded image bytes) the reader allocates. Default 1 GiB. */\n maxGridBytes?: number;\n /** Largest grid name (FileMetaData.nameSize). Default 64 KiB. */\n maxNameBytes?: number;\n /**\n * The whole stream's size in bytes when the caller knows it (a Response's\n * Content-Length: see {@link nvdbResponseLength}). Takes precedence over the\n * size derived from the grids' FileMetaData.\n */\n bytesTotal?: number;\n /** Called after every `push` with the progress so far (not inside the push's error handling). */\n onProgress?: (progress: NvdbProgress) => void;\n}\n\n/** Download progress of an {@link NvdbStreamReader}. */\nexport interface NvdbProgress {\n /** File bytes pushed so far (what the reader consumed; decoded bytes if the transport decompresses). */\n bytesReceived: number;\n /**\n * The expected total, or null while unknown: the `bytesTotal` option when\n * given, else the end of the latest segment whose FileMetaData have all\n * arrived (header + every grid's metadata, name and `fileSize`). That is\n * exact for a one-segment file and a lower bound while a later segment is\n * still ahead. Null until the first segment's metadata is in.\n */\n bytesTotal: number | null;\n /** Grids emitted so far. */\n gridsEmitted: number;\n}\n\n/**\n * The byte length of a `fetch` Response's body when the header says so: its\n * Content-Length, unless a Content-Encoding makes the (decoded) bytes the\n * reader sees differ from it. Null when unknown.\n */\nexport function nvdbResponseLength(response: { headers: { get(name: string): string | null } }): number | null {\n const encoding = response.headers.get(\"content-encoding\");\n if (encoding !== null && encoding.trim() !== \"\" && encoding.trim().toLowerCase() !== \"identity\") return null;\n const raw = response.headers.get(\"content-length\");\n if (raw === null || !/^\\d+$/.test(raw.trim())) return null;\n const n = Number(raw);\n return Number.isSafeInteger(n) ? n : null;\n}\n\n/** One grid, emitted by {@link NvdbStreamReader.push} as soon as its data is complete. */\nexport interface NvdbStreamGrid {\n /** Grid number in the file (counted across segments). */\n index: number;\n /** The grid's metadata from the file's FileMetaData. */\n metadata: NvdbGridMetadata;\n /** The decoded grid image (zero-copy view of a buffer of its own). */\n image: Uint32Array;\n /** File bytes pushed when this grid completed (the end of its data). */\n bytesReceived: number;\n /** The expected file size when this grid completed, or null if unknown (see {@link NvdbProgress.bytesTotal}). */\n bytesTotal: number | null;\n /** The preview level from a `<name>.lod<N>` name, or null for a full grid. */\n lod: number | null;\n /** The name without its `.lod<N>` suffix (the full grid's name). */\n baseName: string;\n}\n\nconst DEFAULT_MAX_GRID_BYTES = 1 << 30;\nconst DEFAULT_MAX_NAME_BYTES = 1 << 16;\nconst ZIP_PREFIX = 8;\n\n/** zlib's `compressBound` (the largest `compress()` output for `n` input bytes), plus slack. */\nfunction zipBound(n: number): number {\n return n + Math.floor(n / 4096) + Math.floor(n / 16384) + Math.floor(n / 33554432) + 13 + 64;\n}\n\nconst LOD_SUFFIX = /^(.*)\\.lod(\\d+)$/;\n\n/**\n * The preview name for `name` at `resolution`: `<name>.lod<resolution>` (K4.5).\n *\n * @param name The full grid's name.\n * @param resolution Preview resolution, a positive integer.\n */\nexport function nvdbLodName(name: string, resolution: number): string {\n if (!Number.isInteger(resolution) || resolution < 1) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `nvdbLodName: resolution must be a positive integer, got ${resolution}`);\n }\n return `${name}.lod${resolution}`;\n}\n\n/** Splits a `<name>.lod<N>` preview name; a full grid's name gives `lod: null`. */\nexport function parseNvdbLodName(name: string): { baseName: string; lod: number | null } {\n const m = LOD_SUFFIX.exec(name);\n return m ? { baseName: m[1]!, lod: Number(m[2]) } : { baseName: name, lod: null };\n}\n\ntype Phase = \"header\" | \"meta\" | \"name\" | \"zipPrefix\" | \"grid\" | \"bloscPrefix\" | \"bloscChunk\";\n\ninterface PendingGrid {\n meta: ParsedFileMetaData;\n name: string;\n}\n\n/**\n * Push-based `.nvdb` reader: `push(chunk)` returns the grids that chunk\n * completed. Call `end()` when the stream ends to detect truncation.\n */\nexport class NvdbStreamReader {\n readonly #maxGridBytes: number;\n readonly #maxNameBytes: number;\n readonly #onProgress: ((progress: NvdbProgress) => void) | undefined;\n readonly #declaredTotal: number | null;\n #segmentStart = 0;\n #knownEnd: number | null = null;\n\n /** Small fixed-size fields (FileHeader, FileMetaData, ZIP prefix) and names. */\n #scratch = new Uint8Array(FILE_METADATA_SIZE);\n /** The buffer being filled (scratch or a grid payload) and how far. */\n #target: Uint8Array;\n #filled = 0;\n\n #phase: Phase = \"header\";\n #codec: NvdbCodec = NvdbCodec.NONE;\n #segmentGrids = 0;\n #pending: PendingGrid[] = [];\n #nextMeta: ParsedFileMetaData | null = null;\n #gridInSegment = 0;\n #received = 0;\n /** BLOSC: the grid image being filled chunk by chunk, and how much of it is decoded. */\n #gridBuffer: Uint8Array | null = null;\n #gridFilled = 0;\n #segments = 0;\n #emitted = 0;\n #failed: Error | null = null;\n readonly #grids: NvdbGridMetadata[] = [];\n\n /** @param options Size limits, a known total size and a progress callback. */\n constructor(options: NvdbStreamReaderOptions = {}) {\n this.#maxGridBytes = options.maxGridBytes ?? DEFAULT_MAX_GRID_BYTES;\n this.#maxNameBytes = options.maxNameBytes ?? DEFAULT_MAX_NAME_BYTES;\n if (!Number.isSafeInteger(this.#maxGridBytes) || this.#maxGridBytes < GRID_DATA_SIZE) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `NvdbStreamReader: maxGridBytes must be an integer >= ${GRID_DATA_SIZE}`);\n }\n if (!Number.isSafeInteger(this.#maxNameBytes) || this.#maxNameBytes < 1) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \"NvdbStreamReader: maxNameBytes must be a positive integer\");\n }\n this.#onProgress = options.onProgress;\n this.#declaredTotal = options.bytesTotal ?? null;\n if (this.#declaredTotal !== null && (!Number.isSafeInteger(this.#declaredTotal) || this.#declaredTotal < 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \"NvdbStreamReader: bytesTotal must be a non-negative integer\");\n }\n this.#target = this.#scratch.subarray(0, FILE_HEADER_SIZE);\n }\n\n /** The expected file size in bytes, or null while unknown (see {@link NvdbProgress.bytesTotal}). */\n get bytesTotal(): number | null {\n return this.#declaredTotal ?? this.#knownEnd;\n }\n\n /** Progress so far. */\n get progress(): NvdbProgress {\n return { bytesReceived: this.#received, bytesTotal: this.bytesTotal, gridsEmitted: this.#emitted };\n }\n\n /** File bytes pushed so far. */\n get bytesReceived(): number {\n return this.#received;\n }\n\n /** Grids emitted so far. */\n get gridsEmitted(): number {\n return this.#emitted;\n }\n\n /**\n * Metadata of every grid whose FileMetaData has arrived, in file order,\n * including grids whose data has not (a segment lists all its grids before\n * any data, so the full grid's `gridByteSize` is known before its preview\n * is emitted). Names are as stored; see {@link parseNvdbLodName}.\n */\n get grids(): readonly NvdbGridMetadata[] {\n return this.#grids;\n }\n\n /** True between segments: every grid announced so far has been emitted. */\n get atBoundary(): boolean {\n return this.#phase === \"header\" && this.#filled === 0 && this.#segments > 0;\n }\n\n /** Pushes the next bytes of the file; returns the grids they completed, in order. */\n push(chunk: Uint8Array): NvdbStreamGrid[] {\n if (this.#failed) throw this.#failed;\n const out: NvdbStreamGrid[] = [];\n try {\n let at = 0;\n while (at < chunk.byteLength) {\n const take = Math.min(chunk.byteLength - at, this.#target.byteLength - this.#filled);\n this.#target.set(chunk.subarray(at, at + take), this.#filled);\n this.#filled += take;\n at += take;\n this.#received += take;\n if (this.#filled === this.#target.byteLength) this.#advance(out);\n }\n // A zero-length target (an empty name) completes without bytes.\n while (this.#target.byteLength === 0 && this.#filled === 0 && this.#phase !== \"header\") this.#advance(out);\n } catch (err) {\n this.#failed = err instanceof VDBToolsError ? err : new NvdbFormatError((err as Error).message);\n throw this.#failed;\n }\n if (this.#onProgress && chunk.byteLength > 0) this.#onProgress(this.progress);\n return out;\n }\n\n /** Declares the end of the stream; throws `NvdbFormatError` if it stopped inside a segment. */\n end(): void {\n if (this.#failed) throw this.#failed;\n if (this.atBoundary) return;\n this.#failed = new NvdbFormatError(\n `the stream ended after ${this.#received} bytes, in the ${this.#describe()}; the file is truncated.`,\n );\n throw this.#failed;\n }\n\n #describe(): string {\n const grid = this.#segmentFirst() + this.#gridInSegment;\n switch (this.#phase) {\n case \"header\":\n return `FileHeader, ${this.#filled} of ${FILE_HEADER_SIZE} bytes`;\n case \"meta\":\n return `FileMetaData of grid #${this.#grids.length}, ${this.#filled} of ${FILE_METADATA_SIZE} bytes`;\n case \"name\":\n return `name of grid #${this.#grids.length}`;\n case \"zipPrefix\":\n return `ZIP size prefix of grid #${grid}`;\n case \"bloscPrefix\":\n return `BLOSC chunk size of grid #${grid}, ${this.#gridFilled} of ${this.#gridBuffer?.byteLength ?? 0} bytes decoded`;\n case \"bloscChunk\":\n return `BLOSC chunk of grid #${grid}, ${this.#filled} of ${this.#target.byteLength} bytes`;\n case \"grid\":\n return `data of grid #${grid}, ${this.#filled} of ${this.#target.byteLength} bytes`;\n }\n }\n\n #segmentFirst(): number {\n return this.#grids.length - this.#segmentGrids;\n }\n\n #expect(phase: Phase, target: Uint8Array): void {\n this.#phase = phase;\n this.#target = target;\n this.#filled = 0;\n }\n\n #advance(out: NvdbStreamGrid[]): void {\n switch (this.#phase) {\n case \"header\": {\n const magic = String.fromCharCode(...this.#scratch.subarray(0, 8));\n if (!isFileHeaderMagic(magic)) {\n if (magic === \"NanoVDB1\") {\n throw new VDBUnsupportedError(\n \".nvdb stream: this is a raw NanoVDB grid buffer (magic NanoVDB1), not a segment file; read it whole with NvdbFile.fromArrayBuffer.\",\n );\n }\n throw new NvdbFormatError(\n `expected a NanoVDB FileHeader (magic NanoVDB2 or NanoVDB0) at byte ${this.#received - FILE_HEADER_SIZE}, found \"${magic.replace(/[^\\x20-\\x7e]/g, \"?\")}\".`,\n );\n }\n const view = new DataView(this.#scratch.buffer, 0, FILE_HEADER_SIZE);\n const header = readFileHeader(view, 0);\n if (header.gridCount === 0) throw new NvdbFormatError(`segment #${this.#segments} declares 0 grids.`);\n this.#codec = header.codec;\n this.#segmentGrids = header.gridCount;\n this.#segments++;\n this.#segmentStart = this.#received - FILE_HEADER_SIZE;\n this.#pending = [];\n this.#gridInSegment = 0;\n this.#expect(\"meta\", this.#scratch.subarray(0, FILE_METADATA_SIZE));\n return;\n }\n case \"meta\": {\n const i = this.#grids.length;\n const meta = readFileMetaData(new DataView(this.#scratch.buffer, 0, FILE_METADATA_SIZE), 0);\n assertSafeGridSize(meta.gridSize, `grid #${i}'s FileMetaData.gridSize`);\n if (meta.gridSize < GRID_DATA_SIZE) {\n throw new NvdbFormatError(`grid #${i} declares gridSize ${meta.gridSize}, smaller than a ${GRID_DATA_SIZE}-byte GridData header.`);\n }\n if (meta.gridSize > this.#maxGridBytes) {\n throw new NvdbFormatError(\n `grid #${i} declares gridSize ${meta.gridSize} bytes, over maxGridBytes (${this.#maxGridBytes}); raise the option if the file is trusted.`,\n );\n }\n if (meta.nameSize > this.#maxNameBytes) {\n throw new NvdbFormatError(`grid #${i} declares a ${meta.nameSize}-byte name, over maxNameBytes (${this.#maxNameBytes}).`);\n }\n this.#nextMeta = meta;\n this.#expect(\"name\", meta.nameSize <= this.#scratch.byteLength ? this.#scratch.subarray(0, meta.nameSize) : new Uint8Array(meta.nameSize));\n return;\n }\n case \"name\": {\n const meta = this.#nextMeta!;\n const name = decodeCString(this.#target);\n const gridType = gridTypeName(meta.gridTypeId);\n try {\n validateGridType(gridType, name);\n } catch (err) {\n throw new VDBUnsupportedError((err as Error).message);\n }\n this.#pending.push({ meta, name });\n this.#grids.push({\n name,\n gridType,\n gridClass: gridClassName(meta.gridClassId),\n worldBBox: meta.worldBBox,\n indexBBox: meta.indexBBox,\n voxelSize: meta.voxelSize,\n voxelCount: meta.voxelCount,\n gridByteSize: meta.gridSize,\n });\n this.#nextMeta = null;\n if (this.#pending.length < this.#segmentGrids) this.#expect(\"meta\", this.#scratch.subarray(0, FILE_METADATA_SIZE));\n else {\n let end = this.#segmentStart + FILE_HEADER_SIZE;\n for (const g of this.#pending) end += FILE_METADATA_SIZE + g.meta.nameSize + g.meta.fileSize;\n this.#knownEnd = Number.isSafeInteger(end) ? end : null;\n this.#startGrid();\n }\n return;\n }\n case \"zipPrefix\": {\n const { meta, name } = this.#pending[this.#gridInSegment]!;\n const size = Number(new DataView(this.#scratch.buffer, 0, ZIP_PREFIX).getBigUint64(0, true));\n const bound = zipBound(meta.gridSize);\n if (!Number.isSafeInteger(size) || size < 1 || size > bound) {\n throw new NvdbFormatError(\n `grid #${this.#segmentFirst() + this.#gridInSegment} (\"${name}\") declares a ${size}-byte ZIP payload for a ` +\n `${meta.gridSize}-byte grid (zlib's bound is ${bound}).`,\n );\n }\n this.#expect(\"grid\", new Uint8Array(size));\n return;\n }\n case \"bloscPrefix\": {\n const { name } = this.#pending[this.#gridInSegment]!;\n const index = this.#segmentFirst() + this.#gridInSegment;\n const size = Number(new DataView(this.#scratch.buffer, 0, ZIP_PREFIX).getBigUint64(0, true));\n checkBloscChunkSize(size, this.#gridBuffer!.byteLength - this.#gridFilled, index, name);\n this.#expect(\"bloscChunk\", new Uint8Array(size));\n return;\n }\n case \"bloscChunk\": {\n const { name } = this.#pending[this.#gridInSegment]!;\n const index = this.#segmentFirst() + this.#gridInSegment;\n const grid = this.#gridBuffer!;\n this.#gridFilled += decodeBloscChunk(this.#target, grid.subarray(this.#gridFilled), index, name);\n if (this.#gridFilled < grid.byteLength) {\n this.#expect(\"bloscPrefix\", this.#scratch.subarray(0, ZIP_PREFIX));\n return;\n }\n this.#gridBuffer = null;\n this.#finishGrid(out, grid);\n return;\n }\n case \"grid\": {\n const { meta, name } = this.#pending[this.#gridInSegment]!;\n const index = this.#segmentFirst() + this.#gridInSegment;\n this.#finishGrid(out, this.#codec === NvdbCodec.ZIP ? inflateZipGrid(this.#target, meta.gridSize, index, name) : this.#target);\n return;\n }\n }\n }\n\n /** Emits the current grid from its decoded image and moves to the next grid or segment. */\n #finishGrid(out: NvdbStreamGrid[], bytes: Uint8Array): void {\n const k = this.#gridInSegment;\n const index = this.#segmentFirst() + k;\n const { meta, name } = this.#pending[k]!;\n const record = finishGridRecord(meta, name, index, bytes);\n this.#grids[index] = record.metadata;\n const { baseName, lod } = parseNvdbLodName(name);\n out.push({ index, metadata: record.metadata, image: record.image, bytesReceived: this.#received, bytesTotal: this.bytesTotal, lod, baseName });\n this.#emitted++;\n this.#gridInSegment++;\n if (this.#gridInSegment < this.#segmentGrids) this.#startGrid();\n else {\n this.#pending = [];\n this.#expect(\"header\", this.#scratch.subarray(0, FILE_HEADER_SIZE));\n }\n }\n\n #startGrid(): void {\n const { meta } = this.#pending[this.#gridInSegment]!;\n if (this.#codec === NvdbCodec.ZIP) this.#expect(\"zipPrefix\", this.#scratch.subarray(0, ZIP_PREFIX));\n else if (this.#codec === NvdbCodec.BLOSC) {\n // gridSize was checked against maxGridBytes with its FileMetaData; chunks decode into this.\n this.#gridBuffer = new Uint8Array(meta.gridSize);\n this.#gridFilled = 0;\n this.#expect(\"bloscPrefix\", this.#scratch.subarray(0, ZIP_PREFIX));\n } else this.#expect(\"grid\", new Uint8Array(meta.gridSize));\n }\n}\n\n/** What {@link readNvdbStream} reads: a `fetch` Response (its Content-Length feeds `bytesTotal`), its body, or chunks. */\nexport type NvdbStreamSource =\n | { body: ReadableStream<Uint8Array> | null; headers: { get(name: string): string | null } }\n | ReadableStream<Uint8Array>\n | AsyncIterable<Uint8Array>;\n\nfunction isResponse(source: NvdbStreamSource): source is Extract<NvdbStreamSource, { headers: unknown }> {\n return typeof (source as { headers?: unknown }).headers === \"object\" && \"body\" in source;\n}\n\n/**\n * Reads a byte stream (a `fetch` Response or body, or any async iterable of chunks) through\n * an {@link NvdbStreamReader}, yielding each grid as it completes. Stops\n * reading (and cancels the stream) when the consumer breaks out of the loop.\n *\n * @param source A `Response`, a response body, or an async iterable of byte chunks.\n * @param options Size limits, a known total size and a progress callback.\n */\nexport async function* readNvdbStream(\n source: NvdbStreamSource,\n options: NvdbStreamReaderOptions = {},\n): AsyncGenerator<NvdbStreamGrid, void, undefined> {\n if (isResponse(source)) {\n const len = nvdbResponseLength(source);\n if (source.body === null) throw new NvdbFormatError(\"readNvdbStream: the response has no body.\");\n options = len !== null && options.bytesTotal === undefined ? { ...options, bytesTotal: len } : options;\n source = source.body;\n }\n const reader = new NvdbStreamReader(options);\n if (typeof (source as ReadableStream<Uint8Array>).getReader === \"function\") {\n const r = (source as ReadableStream<Uint8Array>).getReader();\n let finished = false;\n try {\n for (;;) {\n const { done, value } = await r.read();\n if (done) break;\n yield* reader.push(value);\n }\n finished = true;\n reader.end();\n } finally {\n if (!finished) await r.cancel().catch(() => undefined);\n r.releaseLock();\n }\n return;\n }\n for await (const chunk of source as AsyncIterable<Uint8Array>) yield* reader.push(chunk);\n reader.end();\n}\n"]}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * K6.R: closed forms and high-precision quadratures the reference renderer is checked against (homogeneous media in
3
+ * one box or ball).
4
+ *
5
+ * - Beer–Lambert: T = exp(−σ · chord).
6
+ * - Emission only (albedo 0): L = Le · (1 − T) (the renderer's source term σt · Le).
7
+ * - Single scattering of a directional light: L = ∫ σ · albedo · p(cos θ) · E · exp(−σ (t − t₀)) · exp(−σ ℓ(t)) dt
8
+ * over the camera ray's interval, ℓ(t) the distance from the point to the medium's exit toward the light
9
+ * (composite Simpson, n panels).
10
+ * - White furnace: albedo 1 under a uniform environment Lₑ (and no other light): L + T · Lₑ = Lₑ.
11
+ * - K6.R1: single scattering of a point light (three's falloff or none) and with a tabulated phase.
12
+ */
13
+ import { type VDBRefVec3, type VDBReferenceFalloff, type VDBReferencePhase } from "./scene.js";
14
+ /** A homogeneous medium in one box or ball. */
15
+ export interface VDBRefHomogeneous {
16
+ localToWorld: ArrayLike<number>;
17
+ sphere: boolean;
18
+ /** σt per world unit. */
19
+ sigma: number;
20
+ }
21
+ /** The chord [t₀, t₁] of the ray o + t·d (|d| = 1) in the medium, or null. */
22
+ export declare function vdbRefChord(m: VDBRefHomogeneous, o: readonly number[], d: readonly number[]): [number, number] | null;
23
+ /** Beer–Lambert transmittance of the ray through the medium. */
24
+ export declare function vdbRefBeerLambert(m: VDBRefHomogeneous, o: readonly number[], d: readonly number[]): number;
25
+ /** Radiance of a purely emitting medium (albedo 0) of emitted radiance Le: Le · (1 − T). */
26
+ export declare function vdbRefEmissionOnly(m: VDBRefHomogeneous, o: readonly number[], d: readonly number[], le: VDBRefVec3): VDBRefVec3;
27
+ /**
28
+ * Single-scattered radiance of a directional light (irradiance `e`, `toLight` unit) along o + t·d (|d| = 1) in a
29
+ * homogeneous medium of scattering albedo `albedo`, phase (g, backG, backWeight); composite Simpson, `n` panels.
30
+ */
31
+ export declare function vdbRefSingleScatter(m: VDBRefHomogeneous, o: readonly number[], d: readonly number[], toLight: readonly number[], e: VDBRefVec3, albedo: VDBRefVec3, phase: VDBReferencePhase, n?: number): VDBRefVec3;
32
+ /**
33
+ * K6.R1: single-scattered radiance of a point light (`intensity` at `position`, `falloff` three's attenuation or
34
+ * none) along o + t·d (|d| = 1) in a homogeneous medium; composite Simpson, `n` panels. The light's transmittance
35
+ * is exp(−σ · the part of the segment x → light inside the medium).
36
+ */
37
+ export declare function vdbRefSingleScatterPoint(m: VDBRefHomogeneous, o: readonly number[], d: readonly number[], light: {
38
+ position: VDBRefVec3;
39
+ intensity: VDBRefVec3;
40
+ falloff?: VDBReferenceFalloff;
41
+ }, albedo: VDBRefVec3, phase: VDBReferencePhase, n?: number): VDBRefVec3;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * K6.R: closed forms and high-precision quadratures the reference renderer is checked against (homogeneous media in
3
+ * one box or ball).
4
+ *
5
+ * - Beer–Lambert: T = exp(−σ · chord).
6
+ * - Emission only (albedo 0): L = Le · (1 − T) (the renderer's source term σt · Le).
7
+ * - Single scattering of a directional light: L = ∫ σ · albedo · p(cos θ) · E · exp(−σ (t − t₀)) · exp(−σ ℓ(t)) dt
8
+ * over the camera ray's interval, ℓ(t) the distance from the point to the medium's exit toward the light
9
+ * (composite Simpson, n panels).
10
+ * - White furnace: albedo 1 under a uniform environment Lₑ (and no other light): L + T · Lₑ = Lₑ.
11
+ * - K6.R1: single scattering of a point light (three's falloff or none) and with a tabulated phase.
12
+ */
13
+ import { vdbRefDistanceAttenuation, vdbRefInvert4 } from "./scene.js";
14
+ import { vdbRefPhaseTableEval } from "./tables.js";
15
+ import { vdbRefPhase, vdbRefVolumeInterval } from "./trace.js";
16
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
17
+ /** The chord [t₀, t₁] of the ray o + t·d (|d| = 1) in the medium, or null. */
18
+ export function vdbRefChord(m, o, d) {
19
+ const [t0, t1] = vdbRefVolumeInterval(vdbRefInvert4(m.localToWorld), m.sphere, o, d, 1e30);
20
+ return t0 < t1 ? [t0, t1] : null;
21
+ }
22
+ /** Beer–Lambert transmittance of the ray through the medium. */
23
+ export function vdbRefBeerLambert(m, o, d) {
24
+ const c = vdbRefChord(m, o, d);
25
+ return c ? Math.exp(-m.sigma * (c[1] - c[0])) : 1;
26
+ }
27
+ /** Radiance of a purely emitting medium (albedo 0) of emitted radiance Le: Le · (1 − T). */
28
+ export function vdbRefEmissionOnly(m, o, d, le) {
29
+ const a = 1 - vdbRefBeerLambert(m, o, d);
30
+ return [le[0] * a, le[1] * a, le[2] * a];
31
+ }
32
+ /**
33
+ * Single-scattered radiance of a directional light (irradiance `e`, `toLight` unit) along o + t·d (|d| = 1) in a
34
+ * homogeneous medium of scattering albedo `albedo`, phase (g, backG, backWeight); composite Simpson, `n` panels.
35
+ */
36
+ export function vdbRefSingleScatter(m, o, d, toLight, e, albedo, phase, n = 4096) {
37
+ const c = vdbRefChord(m, o, d);
38
+ if (!c)
39
+ return [0, 0, 0];
40
+ const w2l = vdbRefInvert4(m.localToWorld);
41
+ const pc = phaseOf(phase, dot(d, toLight));
42
+ const f = (t) => {
43
+ const x = [o[0] + t * d[0], o[1] + t * d[1], o[2] + t * d[2]];
44
+ const [, exit] = vdbRefVolumeInterval(w2l, m.sphere, x, toLight, 1e30);
45
+ const l = Math.max(exit, 0);
46
+ return Math.exp(-m.sigma * (t - c[0])) * Math.exp(-m.sigma * l);
47
+ };
48
+ const steps = n % 2 === 0 ? n : n + 1;
49
+ const h = (c[1] - c[0]) / steps;
50
+ let s = f(c[0]) + f(c[1]);
51
+ for (let i = 1; i < steps; i++)
52
+ s += (i % 2 ? 4 : 2) * f(c[0] + i * h);
53
+ const integral = (s * h) / 3;
54
+ return [0, 1, 2].map((k) => m.sigma * albedo[k] * pc[k] * e[k] * integral);
55
+ }
56
+ /** The phase per steradian per channel (HG / dual-lobe, or the table). */
57
+ function phaseOf(phase, cosTheta) {
58
+ if (phase.table)
59
+ return vdbRefPhaseTableEval(phase.table, cosTheta);
60
+ const p = vdbRefPhase(cosTheta, phase.g, phase.backG ?? 0, phase.backWeight ?? 0);
61
+ return [p, p, p];
62
+ }
63
+ /**
64
+ * K6.R1: single-scattered radiance of a point light (`intensity` at `position`, `falloff` three's attenuation or
65
+ * none) along o + t·d (|d| = 1) in a homogeneous medium; composite Simpson, `n` panels. The light's transmittance
66
+ * is exp(−σ · the part of the segment x → light inside the medium).
67
+ */
68
+ export function vdbRefSingleScatterPoint(m, o, d, light, albedo, phase, n = 4096) {
69
+ const c = vdbRefChord(m, o, d);
70
+ if (!c)
71
+ return [0, 0, 0];
72
+ const w2l = vdbRefInvert4(m.localToWorld);
73
+ const f = (t) => {
74
+ const x = [o[0] + t * d[0], o[1] + t * d[1], o[2] + t * d[2]];
75
+ const to = [light.position[0] - x[0], light.position[1] - x[1], light.position[2] - x[2]];
76
+ const dist = Math.hypot(to[0], to[1], to[2]);
77
+ const dir = [to[0] / dist, to[1] / dist, to[2] / dist];
78
+ const [t0, t1] = vdbRefVolumeInterval(w2l, m.sphere, x, dir, dist);
79
+ const inside = t0 < t1 ? t1 - t0 : 0;
80
+ const k = (light.falloff ? vdbRefDistanceAttenuation(dist, light.falloff) : 1) * Math.exp(-m.sigma * (t - c[0])) * Math.exp(-m.sigma * inside);
81
+ const p = phaseOf(phase, dot(d, dir));
82
+ return [p[0] * k, p[1] * k, p[2] * k];
83
+ };
84
+ const steps = n % 2 === 0 ? n : n + 1;
85
+ const h = (c[1] - c[0]) / steps;
86
+ const s = [0, 0, 0];
87
+ for (let i = 0; i <= steps; i++) {
88
+ const w = i === 0 || i === steps ? 1 : i % 2 ? 4 : 2;
89
+ const v = f(c[0] + i * h);
90
+ for (let k = 0; k < 3; k++)
91
+ s[k] = s[k] + w * v[k];
92
+ }
93
+ return [0, 1, 2].map((k) => (m.sigma * albedo[k] * light.intensity[k] * s[k] * h) / 3);
94
+ }
95
+ //# sourceMappingURL=analytic.js.map