@pmndrs/vdb 0.1.0 → 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 (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import type { VDBGridTypeName, VDBSlot } from "../types.js";
2
2
  /**
3
- * Generator profiles; each includes the previous one. `majorant` is deferred
4
- * past 0.1 (D22) and throws `VDB_BAD_OPTION`.
3
+ * Generator profiles; each includes the previous one, except that `majorant`
4
+ * (P1.3) is `sample` plus the majorant walk, and includes `march` only with
5
+ * `majorant: 'nodeMax'`.
5
6
  */
6
7
  export type VDBModuleProfile = "read" | "sample" | "march" | "majorant";
7
8
  /**
@@ -38,8 +39,27 @@ export type VDBModuleProfile = "read" | "sample" | "march" | "majorant";
38
39
  * + secant), `vdbLevelSetGradient(acc, xyz, h) -> vec3f` (central differences,
39
40
  * index space) and `vdbLevelSetNormal(g, xyz, h) -> vec3f` (world unit normal).
40
41
  * CPU twins: `tools` `levelSetHit`, `levelSetGradient`, `levelSetNormal`.
42
+ * - `'majorantWorld'` (`majorant`, EX1f-b): `vdbMajorantInitWorld(g, o, d, tMin, tMax) -> VdbMajorantIter`,
43
+ * `vdbMajorantInit` for a world-space ray. `d` is not renormalized, so `t` stays the caller's world parameter.
44
+ * - `'majorantGlobal'` (`majorant` with `'brick'` or `'global'`): `vdbMajorantInitGlobal(g, o, d, tMin, tMax)`, the
45
+ * one-segment walk on the grid's global bound whatever brick bounds it has: pick bricks or the global bound per
46
+ * ray at run time, in one module.
47
+ * - `'deltaTrack'` (`majorant`; needs the `random` option): `vdbDeltaTrack(it, acc, sigma, maxLookups) -> VdbCollision`
48
+ * (`t`, `density`, `hit`, `truncated`, `steps`, `lookups`), delta tracking over the rest of a walk: the next real
49
+ * collision of the medium whose extinction is `sigma * vdbSample`.
50
+ * - `'ratioTrack'` (`majorant`; needs `random`): `vdbRatioTrack(it, acc, sigma, cutoff, maxLookups) -> VdbTransmittance`
51
+ * (`value`, `truncated`, `steps`, `lookups`), ratio tracking over the rest of a walk: an unbiased transmittance for
52
+ * the per-channel extinctions `sigma.rgb * vdbSample` under one shared majorant; Russian roulette below `cutoff`.
53
+ * CPU twins of the walk and the trackers: `tools` `vdbMajorantWalk`, `vdbDeltaTrack`, `vdbRatioTrack`.
54
+ * - `'accessorUnchecked'` (`reader: 'lean'`, P1.16): `vdbAccessorInitUnchecked(g) -> VdbAccessor`, `vdbAccessorInit`
55
+ * without the liveness and type checks, for a grid id the host KNOWS is live and of a compiled type (a dead or
56
+ * foreign id reads unrelated words as a tree). It reads 2 pool words (3 in a module of several types; 6 more
57
+ * with `outside: 'zero'`) where `vdbAccessorInit` reads 5 (15). For a kernel that cannot keep one accessor per
58
+ * ray; keeping one is cheaper still.
59
+ * With `reader: 'lean'` and a `cache` of `'lower'` or `'lowerLeaf'`, `'fastTrilinear'` emits `vdbSampleFast` as
60
+ * `vdbSample` itself (its taps already are lower-node lookups), so one kernel text serves both readers.
41
61
  */
42
- export type VDBModuleHelper = "cellBoundTrilinear" | "hddaCellEnd" | "levelSet" | "nodeAverage" | "rayClipSupport" | "fastTrilinear";
62
+ export type VDBModuleHelper = "cellBoundTrilinear" | "hddaCellEnd" | "levelSet" | "nodeAverage" | "rayClipSupport" | "fastTrilinear" | "majorantWorld" | "majorantGlobal" | "deltaTrack" | "ratioTrack" | "accessorUnchecked";
43
63
  /** Options every binding mode shares. */
44
64
  export interface VDBModuleCommonOptions {
45
65
  /**
@@ -52,6 +72,7 @@ export interface VDBModuleCommonOptions {
52
72
  * `vdbCheckModule(pool, options)` after each `add`.
53
73
  */
54
74
  readonly types: Iterable<VDBGridTypeName>;
75
+ /** Which functions the module includes (see {@link VDBModuleProfile}). */
55
76
  readonly profile: VDBModuleProfile;
56
77
  /** `sample`+: `'trilinear'` (default) or `'nearest'` (rounds to the closest voxel). */
57
78
  readonly sampler?: "trilinear" | "nearest" | undefined;
@@ -66,11 +87,69 @@ export interface VDBModuleCommonOptions {
66
87
  readonly outside?: "background" | "zero" | undefined;
67
88
  /** Opt-in helpers ({@link VDBModuleHelper}); a set: order and duplicates don't matter. Default none. */
68
89
  readonly helpers?: Iterable<VDBModuleHelper> | undefined;
90
+ /**
91
+ * `majorant` profile only (P1.3, P1.4): the walk `vdbMajorantInit` / `vdbMajorantNext` compile.
92
+ * - `'brick'` (default): the DDA over the grid's brick-majorant cells (`pool.setMajorant` with
93
+ * `tools` `vdbBrickMajorant`); a grid without them walks as `'global'`.
94
+ * - `'global'`: one segment over the sampler's support box, bounded by the record's `valueMax`.
95
+ * - `'nodeMax'`: an HDDA over the tree bounded by node stats (needs `HAS_MIN_MAX`; adds the march
96
+ * layer, so the module is about 10 KiB larger).
97
+ * Every mode also has `vdbMajorantGlobal(g) -> f32`, the scalar bound.
98
+ */
99
+ readonly majorant?: "brick" | "global" | "nodeMax" | undefined;
100
+ /**
101
+ * `majorant` profile only: also emit `vdbMajorantMinimum(it) -> f32`, the lower bound of the last
102
+ * segment (the brick minima when the grid's majorant has them, else 0). Default false.
103
+ */
104
+ readonly minima?: boolean | undefined;
105
+ /**
106
+ * The voxel reader (P1.5): `'vendored'` (default; the audited PNanoVDB accessor) or `'lean'`, a
107
+ * compact descent with a one-leaf cache, about a fifth of the size (`read` / Float ≤ 4 KiB), for kernels
108
+ * near a compiler's size limit. Same public functions and values. Profiles `read`, `sample` and
109
+ * `majorant` with `'brick'` / `'global'`; no march layer, and of the helpers only `'rayClipSupport'` and
110
+ * the majorant profile's (`'majorantWorld'`, `'majorantGlobal'`, `'deltaTrack'`, `'ratioTrack'`).
111
+ */
112
+ readonly reader?: "vendored" | "lean" | undefined;
113
+ /**
114
+ * Helpers `'deltaTrack'` / `'ratioTrack'` only (EX1f-b), and required by them: the name of the host's random
115
+ * function, `fn <name>() -> f32`, declared anywhere in the same shader, returning uniform numbers in [0, 1). The
116
+ * trackers call it by name; the module declares no random state of its own. A plain WGSL identifier that does
117
+ * not start with `vdb` (the module's own prefix).
118
+ */
119
+ readonly random?: string | undefined;
120
+ /**
121
+ * `reader: 'lean'` only (P1.16): what the accessor remembers between reads. Same values in every mode; they
122
+ * differ in the pool words a read loads (docs: "Reads per lookup").
123
+ * - `'leaf'` (default): the last leaf. A read in it loads 1 word, any other read walks the tree from the root
124
+ * (8 words). The 8 taps of a trilinear sample that straddles a leaf face in x walk 8 times.
125
+ * - `'lower'`: the last lower node (a 128-voxel block). Every read in it is one child lookup and the value,
126
+ * 3 words, the same work for every tap of every sample (the `vdbSampleFast` design, K3.2d).
127
+ * - `'lowerLeaf'` (experimental): both. 1 word in the cached leaf, 3 in the cached lower node: the fewest
128
+ * words. Its values equal the CPU twins' on SwiftShader and on Apple Metal, but a wrong image was seen on
129
+ * Apple Metal in one large host kernel (issue #74: pmndrs/pathtracer's 56 KB megakernel; the reader's values
130
+ * were right, other variables of the kernel were not, and `'lower'` fails the same way there once its read
131
+ * function is a few statements longer). Use `'lower'`, and compare a large kernel's image with a reference on
132
+ * Metal after any change of the reader options.
133
+ *
134
+ * A zero-valued accessor (`var acc: VdbAccessor;`, not yet from an init function) is the null accessor in every
135
+ * mode and both readers: `acc.ok` is false, and `vdbReadValue`, `vdbSample` and `vdbIsActive` return 0 / false.
136
+ * A kernel may declare one and assign `vdbAccessorInit(g)` at the first lookup.
137
+ */
138
+ readonly cache?: "leaf" | "lower" | "lowerLeaf" | undefined;
139
+ /**
140
+ * Keep only these public functions and what they call (P1.16): a kernel near a compiler's size limit lists the
141
+ * functions it calls, e.g. `['vdbAccessorInit', 'vdbSample', 'vdbMajorantInit', 'vdbMajorantNext']`, and the
142
+ * module drops the rest (transforms, `vdbRayClip`, `vdbIsActive`, ...). Each name must be a `vdb*` function the
143
+ * module would otherwise have. Default: everything. It shortens the module's text; a host that already removes
144
+ * unreachable functions from its shader (a tree-shaking bundler of WGSL) gains nothing from it.
145
+ */
146
+ readonly keep?: Iterable<string> | undefined;
69
147
  }
70
148
  /** `slot` mode: the module declares `@group(g) @binding(b) var<storage, read> vdbPool: array<u32>;`. */
71
149
  export interface VDBSlotModuleOptions extends VDBModuleCommonOptions {
72
150
  /** The same `VDBSlot` that `vdbModuleEntries(slot)` and `pool.bindGroupEntry(slot)` take. */
73
151
  readonly slot: VDBSlot;
152
+ /** Absent in slot mode. */
74
153
  readonly buffer?: undefined;
75
154
  }
76
155
  /**
@@ -79,7 +158,9 @@ export interface VDBSlotModuleOptions extends VDBModuleCommonOptions {
79
158
  * `'vdbPool.value'` from three's TSL).
80
159
  */
81
160
  export interface VDBBufferModuleOptions extends VDBModuleCommonOptions {
161
+ /** WGSL expression of the host's `array<u32>` the module reads. */
82
162
  readonly buffer: string;
163
+ /** Absent in buffer mode. */
83
164
  readonly slot?: undefined;
84
165
  }
85
166
  /**
@@ -94,11 +175,24 @@ export type VDBModuleOptions = VDBSlotModuleOptions | VDBBufferModuleOptions;
94
175
  * `VDB_GPU_LAYOUT_VERSION`). No binding or profile needed.
95
176
  */
96
177
  export interface VDBModuleTypeCheck {
178
+ /** Grid types the module decodes. */
97
179
  readonly types: Iterable<VDBGridTypeName>;
180
+ /** Pool layout the module targets. Default `VDB_GPU_LAYOUT_VERSION`. */
98
181
  readonly layoutVersion?: number | undefined;
99
182
  }
100
183
  /** What `vdbCheckModule` needs from a pool (structural, so tests and adapters can pass plain objects). */
101
184
  export interface VDBModulePoolLike {
185
+ /** Grid types the pool holds now. */
102
186
  readonly types: Iterable<VDBGridTypeName>;
187
+ /** The pool's layout version. */
103
188
  readonly layoutVersion: number;
189
+ /**
190
+ * Optional (`VDBGridPool` has it; EX1f-a): the live grids whose global value bound is not finite. With it,
191
+ * `vdbCheckModule` throws `VDB_NO_STATS` for a `majorant` module that would walk one of them on that bound.
192
+ */
193
+ readonly unboundedGrids?: Iterable<{
194
+ readonly id: number;
195
+ readonly hasStats: boolean;
196
+ readonly hasBrickMajorant: boolean;
197
+ }> | undefined;
104
198
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/wgsl/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { VDBGridTypeName, VDBSlot } from \"../types.js\";\n\n/**\n * Generator profiles; each includes the previous one. `majorant` is deferred\n * past 0.1 (D22) and throws `VDB_BAD_OPTION`.\n */\nexport type VDBModuleProfile = \"read\" | \"sample\" | \"march\" | \"majorant\";\n\n/**\n * Opt-in WGSL helpers (K1.7a). None is emitted unless listed in `helpers`, so\n * a module without them is byte-identical to one generated before they\n * existed.\n *\n * - `'cellBoundTrilinear'` (`march`): `vdbCellBoundTrilinear(acc, ijk, dim) -> f32`,\n * the max of `vdbNodeMax` over the 2x2x2 block of `dim`-cells starting at\n * the cell that holds `ijk`: a bound for every trilinear sample whose base\n * voxel `floor(p)` lies in that cell.\n * - `'hddaCellEnd'` (`march`): `vdbHddaCellEnd(h: ptr<function, VdbHdda>) -> f32`,\n * the ray `t` where the HDDA's current cell ends (`min(next, tmax)`).\n * - `'nodeAverage'` (`march`): `vdbNodeAverage(acc, ijk, dim) -> f32`, the box\n * mean of the aligned `dim`-cell (8: leaf, 128: lower) holding `ijk` from the\n * node's average statistic (K3.2, the `'node-average'` LOD of the sparse\n * volume source): a tile's value; a leaf's `ave * activeVoxels / 512`\n * (inactive voxels count as 0, the fog background); a lower node's `ave`\n * (the mean of its ACTIVE voxels; also for `dim > 128`). Without stats, the value at `ijk`.\n * - `'rayClipSupport'` (`sample`+): `vdbRayClipSupport(g, o, d, t) -> bool`,\n * `vdbRayClip` against the sampler's support box: `[min - 1, max + 1)` for\n * trilinear, `[min - 0.5, max + 0.5)` for nearest.\n * - `'fastTrilinear'` (`sample`+, sampler `'trilinear'`; K3.2d): `vdbSampleFast(acc, xyz) -> f32`,\n * bit-identical to `vdbSample`: it takes the base voxel's lower node (the\n * accessor's cached one, else one descent) and reads each of the 8 taps as\n * one lower-node child lookup, the same work in every lane (no per-tap tree\n * walk, no leaf-cache thrash where the cell straddles leaves); a base on a\n * lower node's +x/+y/+z face (or, with `outside: 'zero'`, whose taps leave\n * the index bbox) calls `vdbSample`. Reuse the accessor across samples to\n * keep its cached lower node.\n * - `'levelSet'` (`march`, K3.7): `vdbLevelSetHit(g, o, d, t, sdfToIndex, maxSamples) -> bool`,\n * the first zero crossing of a level set's trilinear SDF along an index-space\n * ray (HDDA skip of tile and background cells above 0, sphere trace, bisection\n * + secant), `vdbLevelSetGradient(acc, xyz, h) -> vec3f` (central differences,\n * index space) and `vdbLevelSetNormal(g, xyz, h) -> vec3f` (world unit normal).\n * CPU twins: `tools` `levelSetHit`, `levelSetGradient`, `levelSetNormal`.\n */\nexport type VDBModuleHelper = \"cellBoundTrilinear\" | \"hddaCellEnd\" | \"levelSet\" | \"nodeAverage\" | \"rayClipSupport\" | \"fastTrilinear\";\n\n/** Options every binding mode shares. */\nexport interface VDBModuleCommonOptions {\n /**\n * Grid types to decode; others compile out and read 0. At least one.\n *\n * A module must be generated for every type the host may ever add to the\n * pool, or regenerated (and its pipeline rebuilt) when a new type arrives:\n * `pool.types` only lists the grids present now. Pass\n * `VDB_ALL_SCALAR_TYPES` to never rebuild (the largest module), and call\n * `vdbCheckModule(pool, options)` after each `add`.\n */\n readonly types: Iterable<VDBGridTypeName>;\n readonly profile: VDBModuleProfile;\n /** `sample`+: `'trilinear'` (default) or `'nearest'` (rounds to the closest voxel). */\n readonly sampler?: \"trilinear\" | \"nearest\" | undefined;\n /** `read`+: `false` drops `vdbIsActive`. Default `true`. */\n readonly isActive?: boolean | undefined;\n /**\n * `sample`+: `'background'` (default, NanoVDB: the tree's background value)\n * or `'zero'`: sample the field that is 0 outside the index bbox `[min, max]`\n * (voxels). Trilinear is then 0 outside `[min - 1, max + 1)`, nearest outside\n * `[min - 0.5, max + 0.5)` (voxel centres at integers).\n */\n readonly outside?: \"background\" | \"zero\" | undefined;\n /** Opt-in helpers ({@link VDBModuleHelper}); a set: order and duplicates don't matter. Default none. */\n readonly helpers?: Iterable<VDBModuleHelper> | undefined;\n}\n\n/** `slot` mode: the module declares `@group(g) @binding(b) var<storage, read> vdbPool: array<u32>;`. */\nexport interface VDBSlotModuleOptions extends VDBModuleCommonOptions {\n /** The same `VDBSlot` that `vdbModuleEntries(slot)` and `pool.bindGroupEntry(slot)` take. */\n readonly slot: VDBSlot;\n readonly buffer?: undefined;\n}\n\n/**\n * `buffer` mode: the module declares nothing and reads the host's\n * `array<u32>` through this WGSL expression (engine adapters, e.g.\n * `'vdbPool.value'` from three's TSL).\n */\nexport interface VDBBufferModuleOptions extends VDBModuleCommonOptions {\n readonly buffer: string;\n readonly slot?: undefined;\n}\n\n/**\n * Options of `vdbModuleWgsl` (docs/dev/design/K1-core.md §3.1): exactly one of\n * `slot` / `buffer`. Annotate a host's options as `VDBSlotModuleOptions` to\n * read `options.slot` without a non-null assertion.\n */\nexport type VDBModuleOptions = VDBSlotModuleOptions | VDBBufferModuleOptions;\n\n/**\n * The type/layout-only form of `vdbCheckModule`'s options: the types a module\n * decodes and, optionally, the pool layout it targets (default\n * `VDB_GPU_LAYOUT_VERSION`). No binding or profile needed.\n */\nexport interface VDBModuleTypeCheck {\n readonly types: Iterable<VDBGridTypeName>;\n readonly layoutVersion?: number | undefined;\n}\n\n/** What `vdbCheckModule` needs from a pool (structural, so tests and adapters can pass plain objects). */\nexport interface VDBModulePoolLike {\n readonly types: Iterable<VDBGridTypeName>;\n readonly layoutVersion: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/wgsl/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { VDBGridTypeName, VDBSlot } from \"../types.js\";\n\n/**\n * Generator profiles; each includes the previous one, except that `majorant`\n * (P1.3) is `sample` plus the majorant walk, and includes `march` only with\n * `majorant: 'nodeMax'`.\n */\nexport type VDBModuleProfile = \"read\" | \"sample\" | \"march\" | \"majorant\";\n\n/**\n * Opt-in WGSL helpers (K1.7a). None is emitted unless listed in `helpers`, so\n * a module without them is byte-identical to one generated before they\n * existed.\n *\n * - `'cellBoundTrilinear'` (`march`): `vdbCellBoundTrilinear(acc, ijk, dim) -> f32`,\n * the max of `vdbNodeMax` over the 2x2x2 block of `dim`-cells starting at\n * the cell that holds `ijk`: a bound for every trilinear sample whose base\n * voxel `floor(p)` lies in that cell.\n * - `'hddaCellEnd'` (`march`): `vdbHddaCellEnd(h: ptr<function, VdbHdda>) -> f32`,\n * the ray `t` where the HDDA's current cell ends (`min(next, tmax)`).\n * - `'nodeAverage'` (`march`): `vdbNodeAverage(acc, ijk, dim) -> f32`, the box\n * mean of the aligned `dim`-cell (8: leaf, 128: lower) holding `ijk` from the\n * node's average statistic (K3.2, the `'node-average'` LOD of the sparse\n * volume source): a tile's value; a leaf's `ave * activeVoxels / 512`\n * (inactive voxels count as 0, the fog background); a lower node's `ave`\n * (the mean of its ACTIVE voxels; also for `dim > 128`). Without stats, the value at `ijk`.\n * - `'rayClipSupport'` (`sample`+): `vdbRayClipSupport(g, o, d, t) -> bool`,\n * `vdbRayClip` against the sampler's support box: `[min - 1, max + 1)` for\n * trilinear, `[min - 0.5, max + 0.5)` for nearest.\n * - `'fastTrilinear'` (`sample`+, sampler `'trilinear'`; K3.2d): `vdbSampleFast(acc, xyz) -> f32`,\n * bit-identical to `vdbSample`: it takes the base voxel's lower node (the\n * accessor's cached one, else one descent) and reads each of the 8 taps as\n * one lower-node child lookup, the same work in every lane (no per-tap tree\n * walk, no leaf-cache thrash where the cell straddles leaves); a base on a\n * lower node's +x/+y/+z face (or, with `outside: 'zero'`, whose taps leave\n * the index bbox) calls `vdbSample`. Reuse the accessor across samples to\n * keep its cached lower node.\n * - `'levelSet'` (`march`, K3.7): `vdbLevelSetHit(g, o, d, t, sdfToIndex, maxSamples) -> bool`,\n * the first zero crossing of a level set's trilinear SDF along an index-space\n * ray (HDDA skip of tile and background cells above 0, sphere trace, bisection\n * + secant), `vdbLevelSetGradient(acc, xyz, h) -> vec3f` (central differences,\n * index space) and `vdbLevelSetNormal(g, xyz, h) -> vec3f` (world unit normal).\n * CPU twins: `tools` `levelSetHit`, `levelSetGradient`, `levelSetNormal`.\n * - `'majorantWorld'` (`majorant`, EX1f-b): `vdbMajorantInitWorld(g, o, d, tMin, tMax) -> VdbMajorantIter`,\n * `vdbMajorantInit` for a world-space ray. `d` is not renormalized, so `t` stays the caller's world parameter.\n * - `'majorantGlobal'` (`majorant` with `'brick'` or `'global'`): `vdbMajorantInitGlobal(g, o, d, tMin, tMax)`, the\n * one-segment walk on the grid's global bound whatever brick bounds it has: pick bricks or the global bound per\n * ray at run time, in one module.\n * - `'deltaTrack'` (`majorant`; needs the `random` option): `vdbDeltaTrack(it, acc, sigma, maxLookups) -> VdbCollision`\n * (`t`, `density`, `hit`, `truncated`, `steps`, `lookups`), delta tracking over the rest of a walk: the next real\n * collision of the medium whose extinction is `sigma * vdbSample`.\n * - `'ratioTrack'` (`majorant`; needs `random`): `vdbRatioTrack(it, acc, sigma, cutoff, maxLookups) -> VdbTransmittance`\n * (`value`, `truncated`, `steps`, `lookups`), ratio tracking over the rest of a walk: an unbiased transmittance for\n * the per-channel extinctions `sigma.rgb * vdbSample` under one shared majorant; Russian roulette below `cutoff`.\n * CPU twins of the walk and the trackers: `tools` `vdbMajorantWalk`, `vdbDeltaTrack`, `vdbRatioTrack`.\n * - `'accessorUnchecked'` (`reader: 'lean'`, P1.16): `vdbAccessorInitUnchecked(g) -> VdbAccessor`, `vdbAccessorInit`\n * without the liveness and type checks, for a grid id the host KNOWS is live and of a compiled type (a dead or\n * foreign id reads unrelated words as a tree). It reads 2 pool words (3 in a module of several types; 6 more\n * with `outside: 'zero'`) where `vdbAccessorInit` reads 5 (15). For a kernel that cannot keep one accessor per\n * ray; keeping one is cheaper still.\n * With `reader: 'lean'` and a `cache` of `'lower'` or `'lowerLeaf'`, `'fastTrilinear'` emits `vdbSampleFast` as\n * `vdbSample` itself (its taps already are lower-node lookups), so one kernel text serves both readers.\n */\nexport type VDBModuleHelper =\n | \"cellBoundTrilinear\"\n | \"hddaCellEnd\"\n | \"levelSet\"\n | \"nodeAverage\"\n | \"rayClipSupport\"\n | \"fastTrilinear\"\n | \"majorantWorld\"\n | \"majorantGlobal\"\n | \"deltaTrack\"\n | \"ratioTrack\"\n | \"accessorUnchecked\";\n\n/** Options every binding mode shares. */\nexport interface VDBModuleCommonOptions {\n /**\n * Grid types to decode; others compile out and read 0. At least one.\n *\n * A module must be generated for every type the host may ever add to the\n * pool, or regenerated (and its pipeline rebuilt) when a new type arrives:\n * `pool.types` only lists the grids present now. Pass\n * `VDB_ALL_SCALAR_TYPES` to never rebuild (the largest module), and call\n * `vdbCheckModule(pool, options)` after each `add`.\n */\n readonly types: Iterable<VDBGridTypeName>;\n /** Which functions the module includes (see {@link VDBModuleProfile}). */\n readonly profile: VDBModuleProfile;\n /** `sample`+: `'trilinear'` (default) or `'nearest'` (rounds to the closest voxel). */\n readonly sampler?: \"trilinear\" | \"nearest\" | undefined;\n /** `read`+: `false` drops `vdbIsActive`. Default `true`. */\n readonly isActive?: boolean | undefined;\n /**\n * `sample`+: `'background'` (default, NanoVDB: the tree's background value)\n * or `'zero'`: sample the field that is 0 outside the index bbox `[min, max]`\n * (voxels). Trilinear is then 0 outside `[min - 1, max + 1)`, nearest outside\n * `[min - 0.5, max + 0.5)` (voxel centres at integers).\n */\n readonly outside?: \"background\" | \"zero\" | undefined;\n /** Opt-in helpers ({@link VDBModuleHelper}); a set: order and duplicates don't matter. Default none. */\n readonly helpers?: Iterable<VDBModuleHelper> | undefined;\n /**\n * `majorant` profile only (P1.3, P1.4): the walk `vdbMajorantInit` / `vdbMajorantNext` compile.\n * - `'brick'` (default): the DDA over the grid's brick-majorant cells (`pool.setMajorant` with\n * `tools` `vdbBrickMajorant`); a grid without them walks as `'global'`.\n * - `'global'`: one segment over the sampler's support box, bounded by the record's `valueMax`.\n * - `'nodeMax'`: an HDDA over the tree bounded by node stats (needs `HAS_MIN_MAX`; adds the march\n * layer, so the module is about 10 KiB larger).\n * Every mode also has `vdbMajorantGlobal(g) -> f32`, the scalar bound.\n */\n readonly majorant?: \"brick\" | \"global\" | \"nodeMax\" | undefined;\n /**\n * `majorant` profile only: also emit `vdbMajorantMinimum(it) -> f32`, the lower bound of the last\n * segment (the brick minima when the grid's majorant has them, else 0). Default false.\n */\n readonly minima?: boolean | undefined;\n /**\n * The voxel reader (P1.5): `'vendored'` (default; the audited PNanoVDB accessor) or `'lean'`, a\n * compact descent with a one-leaf cache, about a fifth of the size (`read` / Float ≤ 4 KiB), for kernels\n * near a compiler's size limit. Same public functions and values. Profiles `read`, `sample` and\n * `majorant` with `'brick'` / `'global'`; no march layer, and of the helpers only `'rayClipSupport'` and\n * the majorant profile's (`'majorantWorld'`, `'majorantGlobal'`, `'deltaTrack'`, `'ratioTrack'`).\n */\n readonly reader?: \"vendored\" | \"lean\" | undefined;\n /**\n * Helpers `'deltaTrack'` / `'ratioTrack'` only (EX1f-b), and required by them: the name of the host's random\n * function, `fn <name>() -> f32`, declared anywhere in the same shader, returning uniform numbers in [0, 1). The\n * trackers call it by name; the module declares no random state of its own. A plain WGSL identifier that does\n * not start with `vdb` (the module's own prefix).\n */\n readonly random?: string | undefined;\n /**\n * `reader: 'lean'` only (P1.16): what the accessor remembers between reads. Same values in every mode; they\n * differ in the pool words a read loads (docs: \"Reads per lookup\").\n * - `'leaf'` (default): the last leaf. A read in it loads 1 word, any other read walks the tree from the root\n * (8 words). The 8 taps of a trilinear sample that straddles a leaf face in x walk 8 times.\n * - `'lower'`: the last lower node (a 128-voxel block). Every read in it is one child lookup and the value,\n * 3 words, the same work for every tap of every sample (the `vdbSampleFast` design, K3.2d).\n * - `'lowerLeaf'` (experimental): both. 1 word in the cached leaf, 3 in the cached lower node: the fewest\n * words. Its values equal the CPU twins' on SwiftShader and on Apple Metal, but a wrong image was seen on\n * Apple Metal in one large host kernel (issue #74: pmndrs/pathtracer's 56 KB megakernel; the reader's values\n * were right, other variables of the kernel were not, and `'lower'` fails the same way there once its read\n * function is a few statements longer). Use `'lower'`, and compare a large kernel's image with a reference on\n * Metal after any change of the reader options.\n *\n * A zero-valued accessor (`var acc: VdbAccessor;`, not yet from an init function) is the null accessor in every\n * mode and both readers: `acc.ok` is false, and `vdbReadValue`, `vdbSample` and `vdbIsActive` return 0 / false.\n * A kernel may declare one and assign `vdbAccessorInit(g)` at the first lookup.\n */\n readonly cache?: \"leaf\" | \"lower\" | \"lowerLeaf\" | undefined;\n /**\n * Keep only these public functions and what they call (P1.16): a kernel near a compiler's size limit lists the\n * functions it calls, e.g. `['vdbAccessorInit', 'vdbSample', 'vdbMajorantInit', 'vdbMajorantNext']`, and the\n * module drops the rest (transforms, `vdbRayClip`, `vdbIsActive`, ...). Each name must be a `vdb*` function the\n * module would otherwise have. Default: everything. It shortens the module's text; a host that already removes\n * unreachable functions from its shader (a tree-shaking bundler of WGSL) gains nothing from it.\n */\n readonly keep?: Iterable<string> | undefined;\n}\n\n/** `slot` mode: the module declares `@group(g) @binding(b) var<storage, read> vdbPool: array<u32>;`. */\nexport interface VDBSlotModuleOptions extends VDBModuleCommonOptions {\n /** The same `VDBSlot` that `vdbModuleEntries(slot)` and `pool.bindGroupEntry(slot)` take. */\n readonly slot: VDBSlot;\n /** Absent in slot mode. */\n readonly buffer?: undefined;\n}\n\n/**\n * `buffer` mode: the module declares nothing and reads the host's\n * `array<u32>` through this WGSL expression (engine adapters, e.g.\n * `'vdbPool.value'` from three's TSL).\n */\nexport interface VDBBufferModuleOptions extends VDBModuleCommonOptions {\n /** WGSL expression of the host's `array<u32>` the module reads. */\n readonly buffer: string;\n /** Absent in buffer mode. */\n readonly slot?: undefined;\n}\n\n/**\n * Options of `vdbModuleWgsl` (docs/dev/design/K1-core.md §3.1): exactly one of\n * `slot` / `buffer`. Annotate a host's options as `VDBSlotModuleOptions` to\n * read `options.slot` without a non-null assertion.\n */\nexport type VDBModuleOptions = VDBSlotModuleOptions | VDBBufferModuleOptions;\n\n/**\n * The type/layout-only form of `vdbCheckModule`'s options: the types a module\n * decodes and, optionally, the pool layout it targets (default\n * `VDB_GPU_LAYOUT_VERSION`). No binding or profile needed.\n */\nexport interface VDBModuleTypeCheck {\n /** Grid types the module decodes. */\n readonly types: Iterable<VDBGridTypeName>;\n /** Pool layout the module targets. Default `VDB_GPU_LAYOUT_VERSION`. */\n readonly layoutVersion?: number | undefined;\n}\n\n/** What `vdbCheckModule` needs from a pool (structural, so tests and adapters can pass plain objects). */\nexport interface VDBModulePoolLike {\n /** Grid types the pool holds now. */\n readonly types: Iterable<VDBGridTypeName>;\n /** The pool's layout version. */\n readonly layoutVersion: number;\n /**\n * Optional (`VDBGridPool` has it; EX1f-a): the live grids whose global value bound is not finite. With it,\n * `vdbCheckModule` throws `VDB_NO_STATS` for a `majorant` module that would walk one of them on that bound.\n */\n readonly unboundedGrids?: Iterable<{ readonly id: number; readonly hasStats: boolean; readonly hasBrickMajorant: boolean }> | undefined;\n}\n"]}
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * const res = await fetch(url);
8
8
  * const { id } = await vdbStreamCoarseFirst(pool, res, {
9
- * onGrid: (e) => { if (e.final) material.densityScale.value = base; },
9
+ * onGrid: (e) => { if (e.final) console.log("full grid"); },
10
10
  * });
11
11
  *
12
12
  * 1. `id = pool.add(preview, { capacity })`, where `capacity` is the largest
@@ -14,15 +14,24 @@
14
14
  * FileMetaData before any data, so the full grid's size is known);
15
15
  * 2. `pool.replace(id, finer)` for each finer grid, the full grid last.
16
16
  *
17
+ * A file baked with `segments: 'per-grid'` (K7.12) announces each grid only
18
+ * when its segment starts: the preview is added with its own size (the full
19
+ * grid's `replace` then moves it to a larger range), and until the full grid's
20
+ * segment starts `voxelRatio` is 1 and `types` lists only the grids seen.
21
+ * Make a `VDBGridNode` with every type you bake, or bake the default layout.
22
+ *
17
23
  * The id, its bind-group slot and any instance transform stay. Each image's
18
24
  * own Map places it, and a preview covers the full grid's world box, so the
19
25
  * world placement is unchanged. Things the caller re-derives after a swap
20
26
  * (the `onGrid` callback is the place, or the opt-in `bind` option, which does these
21
27
  * three steps for you after every swap):
22
28
  * - `replace` drops a brick majorant: call `pool.setMajorant` again;
23
- * - `VDBVolumeMaterial` marches in index voxels, so a preview with k-times
24
- * larger voxels has 1/k the optical depth at the same `densityScale`;
25
- * scale it by `voxelRatio` while a preview shows, and back to 1 at `final`;
29
+ * - a `VDBVolumeMaterial` with an explicit `densityScale` (extinction per
30
+ * index voxel): a preview with k-times larger voxels has 1/k the optical
31
+ * depth at the same value, so scale it by `voxelRatio` while a preview
32
+ * shows, and back to 1 at `final`. A material on its defaults needs nothing
33
+ * (EX1a): its `opticalDepth` is relative to the grid's index box and mean
34
+ * density, both of which it reads again after the swap;
26
35
  * - the proxy mesh: a new `vdbProxyGeometry(pool.info(id))` (the preview's
27
36
  * box is the full box grown to whole preview voxels).
28
37
  *
@@ -43,16 +52,36 @@ import { type VDBProxyGridInfo } from "./material.js";
43
52
  import { type NvdbProgress, type NvdbStreamGrid, type NvdbStreamReaderOptions } from "../tools/index.js";
44
53
  /** The part of a `VDBGridPool` the loader uses. */
45
54
  export interface VDBCoarseFirstPoolLike {
55
+ /**
56
+ * Stages a grid image and returns its pool id (`VDBGridPool.add`).
57
+ *
58
+ * @param image The grid image.
59
+ * @param options Reserved capacity and label.
60
+ */
46
61
  add(image: Uint32Array, options?: {
47
62
  capacity?: number;
48
63
  label?: string;
49
64
  }): number;
65
+ /**
66
+ * Stages a new image for grid `id` (`VDBGridPool.replace`).
67
+ *
68
+ * @param id The grid's pool id.
69
+ * @param image The new grid image.
70
+ */
50
71
  replace(id: number, image: Uint32Array): void;
51
72
  }
52
73
  /** The extra pool calls `bind` makes (a `VDBGridPool` has them all). */
53
74
  export interface VDBCoarseFirstBindPoolLike {
75
+ /** Writes the staged changes to the GPU (`VDBGridPool.flush`). */
54
76
  flush(): void;
77
+ /** Reports a grid's index box and transform (`VDBGridPool.info`). */
55
78
  info(id: number): VDBProxyGridInfo;
79
+ /**
80
+ * Sets or clears a grid's brick-majorant bounds (`VDBGridPool.setMajorant`).
81
+ *
82
+ * @param id The grid's pool id.
83
+ * @param majorant The brick bounds, or `null` to clear them.
84
+ */
56
85
  setMajorant(id: number, majorant: VDBBrickMajorant | null): void;
57
86
  }
58
87
  /**
@@ -63,7 +92,8 @@ export interface VDBCoarseFirstBind {
63
92
  /**
64
93
  * A material to scale: `material.densityScale.value = base * event.voxelRatio`, so a preview with k-times larger
65
94
  * voxels keeps the full grid's optical depth and the full grid gets `base` back. `base` is `densityScale` below,
66
- * else the material's value the first time `bind` is applied to it.
95
+ * else the material's value the first time `bind` is applied to it. A `VDBVolumeMaterial` on its defaults has
96
+ * `densityScale` 0 (its `opticalDepth` follows the grid by itself), so it stays 0: nothing to scale.
67
97
  */
68
98
  material?: {
69
99
  densityScale: {
@@ -104,17 +134,22 @@ export interface VDBCoarseFirstEvent {
104
134
  bytesReceived: number;
105
135
  /** Expected file size when the grid was shown, or null if unknown (K4.20; see `NvdbProgress.bytesTotal`). */
106
136
  bytesTotal: number | null;
107
- /** This grid's voxel size over the full grid's (x axis): 1 for the full grid, > 1 for a preview. */
137
+ /**
138
+ * This grid's voxel size over the full grid's (x axis): 1 for the full grid, > 1 for a preview. 1 while the full
139
+ * grid is not announced yet (a `segments: 'per-grid'` file, K7.12).
140
+ */
108
141
  voxelRatio: number;
109
142
  /**
110
- * G16a: the grid types of the family's grids (the file lists every grid's metadata before any data, so this holds
111
- * the full grid's type from the first event on), in `VDB_GRID_TYPE_NAMES` order (`float, fp4, fp8, fp16, fpn`, not
143
+ * G16a: the grid types of the family's grids announced so far (a one-segment file lists every grid's metadata
144
+ * before any data, so this holds the full grid's type from the first event on; a per-grid-segment file, K7.12, adds
145
+ * each grid's type when its segment starts), in `VDB_GRID_TYPE_NAMES` order (`float, fp4, fp8, fp16, fpn, half`, not
112
146
  * alphabetical), each once. A `VDBGridNode` made with `types: event.types` decodes the
113
147
  * preview and the full grid with one module (a baked FpN preview and an Fp8 full grid differ), so a source made
114
148
  * with `followImage` swaps without a recompile.
115
149
  */
116
150
  types: VDBGridTypeName[];
117
151
  }
152
+ /** Options of {@link vdbStreamCoarseFirst}. */
118
153
  export interface VDBCoarseFirstOptions {
119
154
  /** Which family to load, by the full grid's name. Default: the first grid's family. */
120
155
  gridName?: string;
@@ -135,7 +170,9 @@ export interface VDBCoarseFirstOptions {
135
170
  /** Aborts the read (rejects with the signal's reason; the id, if added, stays in the pool). */
136
171
  signal?: AbortSignal;
137
172
  }
173
+ /** What {@link vdbStreamCoarseFirst} resolves with once the full grid is in the pool. */
138
174
  export interface VDBCoarseFirstResult {
175
+ /** The pool id the preview and every finer grid were shown in. */
139
176
  id: number;
140
177
  /** Every grid shown, in order (the preview(s), then the full grid). */
141
178
  shown: VDBCoarseFirstEvent[];
@@ -150,6 +187,10 @@ export interface VDBCoarseFirstResult {
150
187
  * The work `bind` does after a swap, callable on its own from an async `onGrid` (or any code that shows a
151
188
  * {@link VDBCoarseFirstEvent}): majorant, proxy geometry, `pool.flush()` + `grids.update()`, density scale. It never
152
189
  * touches what `bind` leaves out.
190
+ *
191
+ * @param pool The pool the grid is in (with `flush`, `info` and `setMajorant` when `bind` needs them).
192
+ * @param event The swap to follow, as passed to `onGrid`.
193
+ * @param bind What to keep in step: material, proxy mesh, grid node, majorant.
153
194
  */
154
195
  export declare function vdbCoarseFirstApply(pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>, event: VDBCoarseFirstEvent, bind: VDBCoarseFirstBind): void;
155
196
  /**
@@ -158,5 +199,9 @@ export declare function vdbCoarseFirstApply(pool: VDBCoarseFirstPoolLike & Parti
158
199
  * finer grid. Resolves when the full grid is in the pool (the rest of the
159
200
  * stream is cancelled). Rejects with the reader's `NvdbFormatError` on bad
160
201
  * or truncated data.
202
+ *
203
+ * @param pool The pool the grid is added to and replaced in.
204
+ * @param source A `fetch` `Response`, a byte `ReadableStream` or an async iterable of chunks.
205
+ * @param options Family name, label, reader limits, `bind`, callbacks and an abort signal.
161
206
  */
162
207
  export declare function vdbStreamCoarseFirst(pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>, source: VDBCoarseFirstSource, options?: VDBCoarseFirstOptions): Promise<VDBCoarseFirstResult>;
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * const res = await fetch(url);
8
8
  * const { id } = await vdbStreamCoarseFirst(pool, res, {
9
- * onGrid: (e) => { if (e.final) material.densityScale.value = base; },
9
+ * onGrid: (e) => { if (e.final) console.log("full grid"); },
10
10
  * });
11
11
  *
12
12
  * 1. `id = pool.add(preview, { capacity })`, where `capacity` is the largest
@@ -14,15 +14,24 @@
14
14
  * FileMetaData before any data, so the full grid's size is known);
15
15
  * 2. `pool.replace(id, finer)` for each finer grid, the full grid last.
16
16
  *
17
+ * A file baked with `segments: 'per-grid'` (K7.12) announces each grid only
18
+ * when its segment starts: the preview is added with its own size (the full
19
+ * grid's `replace` then moves it to a larger range), and until the full grid's
20
+ * segment starts `voxelRatio` is 1 and `types` lists only the grids seen.
21
+ * Make a `VDBGridNode` with every type you bake, or bake the default layout.
22
+ *
17
23
  * The id, its bind-group slot and any instance transform stay. Each image's
18
24
  * own Map places it, and a preview covers the full grid's world box, so the
19
25
  * world placement is unchanged. Things the caller re-derives after a swap
20
26
  * (the `onGrid` callback is the place, or the opt-in `bind` option, which does these
21
27
  * three steps for you after every swap):
22
28
  * - `replace` drops a brick majorant: call `pool.setMajorant` again;
23
- * - `VDBVolumeMaterial` marches in index voxels, so a preview with k-times
24
- * larger voxels has 1/k the optical depth at the same `densityScale`;
25
- * scale it by `voxelRatio` while a preview shows, and back to 1 at `final`;
29
+ * - a `VDBVolumeMaterial` with an explicit `densityScale` (extinction per
30
+ * index voxel): a preview with k-times larger voxels has 1/k the optical
31
+ * depth at the same value, so scale it by `voxelRatio` while a preview
32
+ * shows, and back to 1 at `final`. A material on its defaults needs nothing
33
+ * (EX1a): its `opticalDepth` is relative to the grid's index box and mean
34
+ * density, both of which it reads again after the swap;
26
35
  * - the proxy mesh: a new `vdbProxyGeometry(pool.info(id))` (the preview's
27
36
  * box is the full box grown to whole preview voxels).
28
37
  *
@@ -39,13 +48,18 @@
39
48
  import { VDBError } from "../core/errors.js";
40
49
  import { VDB_GRID_TYPE_NAMES } from "../core/types.js";
41
50
  import { vdbProxyGeometry } from "./material.js";
42
- import { NvdbStreamReader, nvdbResponseLength, parseNvdbLodName, } from "../tools/index.js";
51
+ import { nvdbResponseLength } from "../tools/nvdb-stream.js";
52
+ import { NvdbStreamReader, parseNvdbLodName, } from "../tools/index.js";
43
53
  /** The base density scale of each bound material (the value seen at its first swap, unless `bind.densityScale` says). */
44
54
  const baseScale = new WeakMap();
45
55
  /**
46
56
  * The work `bind` does after a swap, callable on its own from an async `onGrid` (or any code that shows a
47
57
  * {@link VDBCoarseFirstEvent}): majorant, proxy geometry, `pool.flush()` + `grids.update()`, density scale. It never
48
58
  * touches what `bind` leaves out.
59
+ *
60
+ * @param pool The pool the grid is in (with `flush`, `info` and `setMajorant` when `bind` needs them).
61
+ * @param event The swap to follow, as passed to `onGrid`.
62
+ * @param bind What to keep in step: material, proxy mesh, grid node, majorant.
49
63
  */
50
64
  export function vdbCoarseFirstApply(pool, event, bind) {
51
65
  const need = (name) => {
@@ -119,6 +133,10 @@ function chunks(source) {
119
133
  * finer grid. Resolves when the full grid is in the pool (the rest of the
120
134
  * stream is cancelled). Rejects with the reader's `NvdbFormatError` on bad
121
135
  * or truncated data.
136
+ *
137
+ * @param pool The pool the grid is added to and replaced in.
138
+ * @param source A `fetch` `Response`, a byte `ReadableStream` or an async iterable of chunks.
139
+ * @param options Family name, label, reader limits, `bind`, callbacks and an abort signal.
122
140
  */
123
141
  export async function vdbStreamCoarseFirst(pool, source, options = {}) {
124
142
  const signal = options.signal;
@@ -139,7 +157,7 @@ export async function vdbStreamCoarseFirst(pool, source, options = {}) {
139
157
  const full = familyGrids().find((g) => g.name === family);
140
158
  return full ? grid.metadata.voxelSize[0] / full.voxelSize[0] : 1;
141
159
  };
142
- // The reader accepts only the pool's scalar types (Float, Fp4, Fp8, Fp16, FpN: the names in lower case).
160
+ // The reader accepts only the pool's scalar types (Float, Fp4, Fp8, Fp16, FpN, Half: the names in lower case).
143
161
  const familyTypes = () => {
144
162
  const names = new Set(familyGrids().map((g) => g.gridType.toLowerCase()));
145
163
  return VDB_GRID_TYPE_NAMES.filter((t) => names.has(t));
@@ -1 +1 @@
1
- {"version":3,"file":"coarse-first.js","sourceRoot":"","sources":["../../src/three/coarse-first.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAwB,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAyB,MAAM,eAAe,CAAC;AACxE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GAKjB,MAAM,mBAAmB,CAAC;AAuG3B,yHAAyH;AACzH,MAAM,SAAS,GAAG,IAAI,OAAO,EAAkB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAkE,EAClE,KAA0B,EAC1B,IAAwB;IAExB,MAAM,IAAI,GAAG,CAA6C,IAAO,EAA8C,EAAE;QAC/G,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,IAAI,QAAQ,CAAC,gBAAgB,EAAE,oDAAoD,IAAI,qBAAqB,CAAC,CAAC;QACtH,CAAC;QACD,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAA+C,CAAC;IACrE,CAAC,CAAC;IACF,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,QAAQ;YAAE,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,EAAE,EA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,IAAI,QAAQ,CAChB,eAAe,EACf,MAAM,KAAK,IAAI;QACb,CAAC,CAAC,gDAAgD;QAClD,CAAC,CAAC,iEAAiE,MAAM,aAAa,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CACvI,CAAC;AACJ,CAAC","sourcesContent":["/**\n * `vdbStreamCoarseFirst` (K4.16): stream a coarse-first `.nvdb`\n * (`vdbBakeCoarseFirst`, docs/dev/design/K4-5-coarse-first.md option a) into one\n * pool id. The preview is added as soon as its bytes are in, with the full\n * grid's size reserved, and each finer grid replaces it in place:\n *\n * const res = await fetch(url);\n * const { id } = await vdbStreamCoarseFirst(pool, res, {\n * onGrid: (e) => { if (e.final) material.densityScale.value = base; },\n * });\n *\n * 1. `id = pool.add(preview, { capacity })`, where `capacity` is the largest\n * grid of the family announced so far (a segment lists every grid's\n * FileMetaData before any data, so the full grid's size is known);\n * 2. `pool.replace(id, finer)` for each finer grid, the full grid last.\n *\n * The id, its bind-group slot and any instance transform stay. Each image's\n * own Map places it, and a preview covers the full grid's world box, so the\n * world placement is unchanged. Things the caller re-derives after a swap\n * (the `onGrid` callback is the place, or the opt-in `bind` option, which does these\n * three steps for you after every swap):\n * - `replace` drops a brick majorant: call `pool.setMajorant` again;\n * - `VDBVolumeMaterial` marches in index voxels, so a preview with k-times\n * larger voxels has 1/k the optical depth at the same `densityScale`;\n * scale it by `voxelRatio` while a preview shows, and back to 1 at `final`;\n * - the proxy mesh: a new `vdbProxyGeometry(pool.info(id))` (the preview's\n * box is the full box grown to whole preview voxels).\n *\n * Into the froxel renderer (G16a): at the first event make the `VDBGridNode`\n * with `types: event.types` (every grid type of the family) and the sparse\n * source with `followImage: true`; the source re-reads its boxes after each\n * swap and the `VDBFrameVolume` follows, with no new node, source, volume or\n * shader. Froxels integrate in world space: no `voxelRatio` scale there.\n *\n * Without `bind` it touches only `pool.add` / `pool.replace`, so it works with\n * any `VDBGridPool` host. It lives in `./three` because `tools` may not import\n * the core (D20).\n */\n\nimport type * as THREE from \"three\";\n\nimport { VDBError } from \"../core/errors.js\";\nimport type { VDBBrickMajorant } from \"../core/index.js\";\nimport { VDB_GRID_TYPE_NAMES, type VDBGridTypeName } from \"../core/types.js\";\nimport { vdbProxyGeometry, type VDBProxyGridInfo } from \"./material.js\";\nimport {\n NvdbStreamReader,\n nvdbResponseLength,\n parseNvdbLodName,\n type NvdbGridMetadata,\n type NvdbProgress,\n type NvdbStreamGrid,\n type NvdbStreamReaderOptions,\n} from \"../tools/index.js\";\n\n/** The part of a `VDBGridPool` the loader uses. */\nexport interface VDBCoarseFirstPoolLike {\n add(image: Uint32Array, options?: { capacity?: number; label?: string }): number;\n replace(id: number, image: Uint32Array): void;\n}\n\n/** The extra pool calls `bind` makes (a `VDBGridPool` has them all). */\nexport interface VDBCoarseFirstBindPoolLike {\n flush(): void;\n info(id: number): VDBProxyGridInfo;\n setMajorant(id: number, majorant: VDBBrickMajorant | null): void;\n}\n\n/**\n * What to keep in step with the pool id after each swap (K5.4c). Every member is optional; the fields are read at\n * each swap, so they may be assigned later (for example in `onGrid`, once the first grid exists).\n */\nexport interface VDBCoarseFirstBind {\n /**\n * A material to scale: `material.densityScale.value = base * event.voxelRatio`, so a preview with k-times larger\n * voxels keeps the full grid's optical depth and the full grid gets `base` back. `base` is `densityScale` below,\n * else the material's value the first time `bind` is applied to it.\n */\n material?: { densityScale: { value: number } };\n /** The base density scale for `material`. Default: the material's current value at the first swap. */\n densityScale?: number;\n /** A proxy mesh: its geometry is replaced (and the old one disposed) with `vdbProxyGeometry(pool.info(id))`. */\n mesh?: { geometry: THREE.BufferGeometry };\n /** `vdbProxyGeometry` padding for `mesh` (default 0). */\n proxyPad?: number;\n /** A `VDBGridNode`: `pool.flush()` then `grids.update()`, so its shaders see the swapped grid. */\n grids?: { update(): void };\n /**\n * Brick majorant for the grid just shown (`replace` drops the old one). Return `null` / `undefined` to leave the grid\n * without one, e.g. for a preview.\n */\n majorant?: (event: VDBCoarseFirstEvent) => VDBBrickMajorant | null | undefined;\n}\n\n/** What a coarse-first stream delivers. */\nexport type VDBCoarseFirstSource = Response | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;\n\n/** One grid shown in the pool. */\nexport interface VDBCoarseFirstEvent {\n /** The pool id (the same for every grid of the family). */\n id: number;\n /** The grid as the stream reader emitted it (`lod` is null for the full grid). */\n grid: NvdbStreamGrid;\n /** True for the full grid: the last swap. */\n final: boolean;\n /** `'add'` for the first grid shown, `'replace'` after. */\n action: \"add\" | \"replace\";\n /** File bytes received when the grid was shown (decoded bytes; see the e2e for compressed counts). */\n bytesReceived: number;\n /** Expected file size when the grid was shown, or null if unknown (K4.20; see `NvdbProgress.bytesTotal`). */\n bytesTotal: number | null;\n /** This grid's voxel size over the full grid's (x axis): 1 for the full grid, > 1 for a preview. */\n voxelRatio: number;\n /**\n * G16a: the grid types of the family's grids (the file lists every grid's metadata before any data, so this holds\n * the full grid's type from the first event on), in `VDB_GRID_TYPE_NAMES` order (`float, fp4, fp8, fp16, fpn`, not\n * alphabetical), each once. A `VDBGridNode` made with `types: event.types` decodes the\n * preview and the full grid with one module (a baked FpN preview and an Fp8 full grid differ), so a source made\n * with `followImage` swaps without a recompile.\n */\n types: VDBGridTypeName[];\n}\n\nexport interface VDBCoarseFirstOptions {\n /** Which family to load, by the full grid's name. Default: the first grid's family. */\n gridName?: string;\n /** Pool label for the id. Default: the full grid's name. */\n label?: string;\n /** Limits for the stream reader. */\n reader?: NvdbStreamReaderOptions;\n /**\n * Keeps a material, proxy mesh, grid node and majorant in step with each swap, before `onGrid` runs (see\n * {@link VDBCoarseFirstBind} and {@link vdbCoarseFirstApply}). Needs a pool with `flush` / `info` / `setMajorant`\n * (a `VDBGridPool`).\n */\n bind?: VDBCoarseFirstBind;\n /** Called after each `pool.add` / `pool.replace` (preview, then finer grids, then the full grid), after `bind`. */\n onGrid?: (event: VDBCoarseFirstEvent) => void;\n /** Called after every received chunk with the byte progress (K4.20). `bytesTotal` is the Response's Content-Length, else derived from the file's metadata. */\n onProgress?: (progress: NvdbProgress) => void;\n /** Aborts the read (rejects with the signal's reason; the id, if added, stays in the pool). */\n signal?: AbortSignal;\n}\n\nexport interface VDBCoarseFirstResult {\n id: number;\n /** Every grid shown, in order (the preview(s), then the full grid). */\n shown: VDBCoarseFirstEvent[];\n /** File bytes received when the first grid was added. */\n firstBytes: number;\n /** File bytes received when the full grid replaced the preview. */\n fullBytes: number;\n /** Expected file size when the full grid arrived, or null if unknown. */\n bytesTotal: number | null;\n}\n\n/** The base density scale of each bound material (the value seen at its first swap, unless `bind.densityScale` says). */\nconst baseScale = new WeakMap<object, number>();\n\n/**\n * The work `bind` does after a swap, callable on its own from an async `onGrid` (or any code that shows a\n * {@link VDBCoarseFirstEvent}): majorant, proxy geometry, `pool.flush()` + `grids.update()`, density scale. It never\n * touches what `bind` leaves out.\n */\nexport function vdbCoarseFirstApply(\n pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>,\n event: VDBCoarseFirstEvent,\n bind: VDBCoarseFirstBind,\n): void {\n const need = <K extends keyof VDBCoarseFirstBindPoolLike>(name: K): NonNullable<VDBCoarseFirstBindPoolLike[K]> => {\n const fn = pool[name];\n if (typeof fn !== \"function\") {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbStreamCoarseFirst: \\`bind\\` needs a pool with ${name}() (a VDBGridPool).`);\n }\n return fn.bind(pool) as NonNullable<VDBCoarseFirstBindPoolLike[K]>;\n };\n if (bind.majorant) {\n const majorant = bind.majorant(event);\n if (majorant) need(\"setMajorant\")(event.id, majorant);\n }\n if (bind.mesh) {\n const next = vdbProxyGeometry(need(\"info\")(event.id), bind.proxyPad === undefined ? {} : { pad: bind.proxyPad });\n bind.mesh.geometry.dispose();\n bind.mesh.geometry = next;\n }\n if (bind.grids) {\n need(\"flush\")();\n bind.grids.update();\n }\n const material = bind.material;\n if (material) {\n const base = bind.densityScale ?? baseScale.get(material) ?? material.densityScale.value;\n baseScale.set(material, base);\n material.densityScale.value = base * event.voxelRatio;\n }\n}\n\nconst familyOf = (name: string): string => parseNvdbLodName(name).baseName;\n\n/** Finest first: the full grid (lod null) beats any preview; a larger resolution beats a smaller. */\nfunction finer(a: NvdbStreamGrid, b: NvdbStreamGrid | null): boolean {\n if (b === null) return true;\n if (b.lod === null) return false;\n if (a.lod === null) return true;\n return a.lod > b.lod;\n}\n\nfunction chunks(source: VDBCoarseFirstSource): { iterate: AsyncIterable<Uint8Array>; cancel: () => Promise<void> } {\n const stream = source instanceof Response ? source.body : source;\n if (source instanceof Response && !source.ok) {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbStreamCoarseFirst: the response is ${source.status} ${source.statusText} (${source.url}).`);\n }\n if (stream === null) throw new VDBError(\"VDB_BAD_OPTION\", \"vdbStreamCoarseFirst: the response has no body.\");\n if (typeof (stream as ReadableStream<Uint8Array>).getReader === \"function\") {\n const reader = (stream as ReadableStream<Uint8Array>).getReader();\n return {\n iterate: {\n async *[Symbol.asyncIterator]() {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) return;\n yield value;\n }\n },\n },\n cancel: () => reader.cancel().catch(() => undefined),\n };\n }\n const iterable = stream as AsyncIterable<Uint8Array>;\n return { iterate: iterable, cancel: async () => undefined };\n}\n\n/**\n * Streams a coarse-first `.nvdb` into one pool id: `add` the first grid of the\n * family with the family's largest size reserved, then `replace` with each\n * finer grid. Resolves when the full grid is in the pool (the rest of the\n * stream is cancelled). Rejects with the reader's `NvdbFormatError` on bad\n * or truncated data.\n */\nexport async function vdbStreamCoarseFirst(\n pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>,\n source: VDBCoarseFirstSource,\n options: VDBCoarseFirstOptions = {},\n): Promise<VDBCoarseFirstResult> {\n const signal = options.signal;\n signal?.throwIfAborted();\n const wire = source instanceof Response ? nvdbResponseLength(source) : null;\n const reader = new NvdbStreamReader({\n ...options.reader,\n ...(wire !== null && options.reader?.bytesTotal === undefined ? { bytesTotal: wire } : {}),\n ...(options.onProgress ? { onProgress: options.onProgress } : {}),\n });\n const { iterate, cancel } = chunks(source);\n\n let family = options.gridName ?? null;\n let id = -1;\n let current: NvdbStreamGrid | null = null;\n const shown: VDBCoarseFirstEvent[] = [];\n\n const familyGrids = (): NvdbGridMetadata[] => reader.grids.filter((g) => familyOf(g.name) === family);\n const fullVoxel = (grid: NvdbStreamGrid): number => {\n const full = familyGrids().find((g) => g.name === family);\n return full ? grid.metadata.voxelSize[0] / full.voxelSize[0] : 1;\n };\n // The reader accepts only the pool's scalar types (Float, Fp4, Fp8, Fp16, FpN: the names in lower case).\n const familyTypes = (): VDBGridTypeName[] => {\n const names = new Set(familyGrids().map((g) => g.gridType.toLowerCase()));\n return VDB_GRID_TYPE_NAMES.filter((t) => names.has(t));\n };\n\n try {\n for await (const chunk of iterate) {\n signal?.throwIfAborted();\n for (const grid of reader.push(chunk)) {\n family ??= grid.baseName;\n if (grid.baseName !== family || !finer(grid, current)) continue;\n const final = grid.lod === null;\n let action: \"add\" | \"replace\";\n if (id < 0) {\n const capacity = Math.max(...familyGrids().map((g) => g.gridByteSize));\n id = pool.add(grid.image, { capacity, label: options.label ?? family });\n action = \"add\";\n } else {\n pool.replace(id, grid.image);\n action = \"replace\";\n }\n current = grid;\n const event: VDBCoarseFirstEvent = { id, grid, final, action, bytesReceived: grid.bytesReceived, bytesTotal: grid.bytesTotal, voxelRatio: fullVoxel(grid), types: familyTypes() };\n shown.push(event);\n if (options.bind) vdbCoarseFirstApply(pool, event, options.bind);\n options.onGrid?.(event);\n if (final) {\n await cancel();\n return { id, shown, firstBytes: shown[0]!.bytesReceived, fullBytes: grid.bytesReceived, bytesTotal: grid.bytesTotal };\n }\n }\n }\n reader.end();\n } catch (err) {\n await cancel();\n throw err;\n }\n throw new VDBError(\n \"VDB_BAD_IMAGE\",\n family === null\n ? \"vdbStreamCoarseFirst: the stream held no grid.\"\n : `vdbStreamCoarseFirst: the stream ended without the full grid \"${family}\" (grids: ${reader.grids.map((g) => g.name).join(\", \")}).`,\n );\n}\n"]}
1
+ {"version":3,"file":"coarse-first.js","sourceRoot":"","sources":["../../src/three/coarse-first.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAwB,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAyB,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GAKjB,MAAM,mBAAmB,CAAC;AAmI3B,yHAAyH;AACzH,MAAM,SAAS,GAAG,IAAI,OAAO,EAAkB,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAkE,EAClE,KAA0B,EAC1B,IAAwB;IAExB,MAAM,IAAI,GAAG,CAA6C,IAAO,EAA8C,EAAE;QAC/G,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,IAAI,QAAQ,CAAC,gBAAgB,EAAE,oDAAoD,IAAI,qBAAqB,CAAC,CAAC;QACtH,CAAC;QACD,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAA+C,CAAC;IACrE,CAAC,CAAC;IACF,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,QAAQ;YAAE,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IACD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AAM,KAAK,IAAI;QACb,CAAC,CAAC,gDAAgD;QAClD,CAAC,CAAC,iEAAiE,MAAM,aAAa,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CACvI,CAAC;AACJ,CAAC","sourcesContent":["/**\n * `vdbStreamCoarseFirst` (K4.16): stream a coarse-first `.nvdb`\n * (`vdbBakeCoarseFirst`, docs/dev/design/K4-5-coarse-first.md option a) into one\n * pool id. The preview is added as soon as its bytes are in, with the full\n * grid's size reserved, and each finer grid replaces it in place:\n *\n * const res = await fetch(url);\n * const { id } = await vdbStreamCoarseFirst(pool, res, {\n * onGrid: (e) => { if (e.final) console.log(\"full grid\"); },\n * });\n *\n * 1. `id = pool.add(preview, { capacity })`, where `capacity` is the largest\n * grid of the family announced so far (a segment lists every grid's\n * FileMetaData before any data, so the full grid's size is known);\n * 2. `pool.replace(id, finer)` for each finer grid, the full grid last.\n *\n * A file baked with `segments: 'per-grid'` (K7.12) announces each grid only\n * when its segment starts: the preview is added with its own size (the full\n * grid's `replace` then moves it to a larger range), and until the full grid's\n * segment starts `voxelRatio` is 1 and `types` lists only the grids seen.\n * Make a `VDBGridNode` with every type you bake, or bake the default layout.\n *\n * The id, its bind-group slot and any instance transform stay. Each image's\n * own Map places it, and a preview covers the full grid's world box, so the\n * world placement is unchanged. Things the caller re-derives after a swap\n * (the `onGrid` callback is the place, or the opt-in `bind` option, which does these\n * three steps for you after every swap):\n * - `replace` drops a brick majorant: call `pool.setMajorant` again;\n * - a `VDBVolumeMaterial` with an explicit `densityScale` (extinction per\n * index voxel): a preview with k-times larger voxels has 1/k the optical\n * depth at the same value, so scale it by `voxelRatio` while a preview\n * shows, and back to 1 at `final`. A material on its defaults needs nothing\n * (EX1a): its `opticalDepth` is relative to the grid's index box and mean\n * density, both of which it reads again after the swap;\n * - the proxy mesh: a new `vdbProxyGeometry(pool.info(id))` (the preview's\n * box is the full box grown to whole preview voxels).\n *\n * Into the froxel renderer (G16a): at the first event make the `VDBGridNode`\n * with `types: event.types` (every grid type of the family) and the sparse\n * source with `followImage: true`; the source re-reads its boxes after each\n * swap and the `VDBFrameVolume` follows, with no new node, source, volume or\n * shader. Froxels integrate in world space: no `voxelRatio` scale there.\n *\n * Without `bind` it touches only `pool.add` / `pool.replace`, so it works with\n * any `VDBGridPool` host. It lives in `./three` because `tools` may not import\n * the core (D20).\n */\n\nimport type * as THREE from \"three\";\n\nimport { VDBError } from \"../core/errors.js\";\nimport type { VDBBrickMajorant } from \"../core/index.js\";\nimport { VDB_GRID_TYPE_NAMES, type VDBGridTypeName } from \"../core/types.js\";\nimport { vdbProxyGeometry, type VDBProxyGridInfo } from \"./material.js\";\nimport { nvdbResponseLength } from \"../tools/nvdb-stream.js\";\nimport {\n NvdbStreamReader,\n parseNvdbLodName,\n type NvdbGridMetadata,\n type NvdbProgress,\n type NvdbStreamGrid,\n type NvdbStreamReaderOptions,\n} from \"../tools/index.js\";\n\n/** The part of a `VDBGridPool` the loader uses. */\nexport interface VDBCoarseFirstPoolLike {\n /**\n * Stages a grid image and returns its pool id (`VDBGridPool.add`).\n *\n * @param image The grid image.\n * @param options Reserved capacity and label.\n */\n add(image: Uint32Array, options?: { capacity?: number; label?: string }): number;\n /**\n * Stages a new image for grid `id` (`VDBGridPool.replace`).\n *\n * @param id The grid's pool id.\n * @param image The new grid image.\n */\n replace(id: number, image: Uint32Array): void;\n}\n\n/** The extra pool calls `bind` makes (a `VDBGridPool` has them all). */\nexport interface VDBCoarseFirstBindPoolLike {\n /** Writes the staged changes to the GPU (`VDBGridPool.flush`). */\n flush(): void;\n /** Reports a grid's index box and transform (`VDBGridPool.info`). */\n info(id: number): VDBProxyGridInfo;\n /**\n * Sets or clears a grid's brick-majorant bounds (`VDBGridPool.setMajorant`).\n *\n * @param id The grid's pool id.\n * @param majorant The brick bounds, or `null` to clear them.\n */\n setMajorant(id: number, majorant: VDBBrickMajorant | null): void;\n}\n\n/**\n * What to keep in step with the pool id after each swap (K5.4c). Every member is optional; the fields are read at\n * each swap, so they may be assigned later (for example in `onGrid`, once the first grid exists).\n */\nexport interface VDBCoarseFirstBind {\n /**\n * A material to scale: `material.densityScale.value = base * event.voxelRatio`, so a preview with k-times larger\n * voxels keeps the full grid's optical depth and the full grid gets `base` back. `base` is `densityScale` below,\n * else the material's value the first time `bind` is applied to it. A `VDBVolumeMaterial` on its defaults has\n * `densityScale` 0 (its `opticalDepth` follows the grid by itself), so it stays 0: nothing to scale.\n */\n material?: { densityScale: { value: number } };\n /** The base density scale for `material`. Default: the material's current value at the first swap. */\n densityScale?: number;\n /** A proxy mesh: its geometry is replaced (and the old one disposed) with `vdbProxyGeometry(pool.info(id))`. */\n mesh?: { geometry: THREE.BufferGeometry };\n /** `vdbProxyGeometry` padding for `mesh` (default 0). */\n proxyPad?: number;\n /** A `VDBGridNode`: `pool.flush()` then `grids.update()`, so its shaders see the swapped grid. */\n grids?: { update(): void };\n /**\n * Brick majorant for the grid just shown (`replace` drops the old one). Return `null` / `undefined` to leave the grid\n * without one, e.g. for a preview.\n */\n majorant?: (event: VDBCoarseFirstEvent) => VDBBrickMajorant | null | undefined;\n}\n\n/** What a coarse-first stream delivers. */\nexport type VDBCoarseFirstSource = Response | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;\n\n/** One grid shown in the pool. */\nexport interface VDBCoarseFirstEvent {\n /** The pool id (the same for every grid of the family). */\n id: number;\n /** The grid as the stream reader emitted it (`lod` is null for the full grid). */\n grid: NvdbStreamGrid;\n /** True for the full grid: the last swap. */\n final: boolean;\n /** `'add'` for the first grid shown, `'replace'` after. */\n action: \"add\" | \"replace\";\n /** File bytes received when the grid was shown (decoded bytes; see the e2e for compressed counts). */\n bytesReceived: number;\n /** Expected file size when the grid was shown, or null if unknown (K4.20; see `NvdbProgress.bytesTotal`). */\n bytesTotal: number | null;\n /**\n * This grid's voxel size over the full grid's (x axis): 1 for the full grid, > 1 for a preview. 1 while the full\n * grid is not announced yet (a `segments: 'per-grid'` file, K7.12).\n */\n voxelRatio: number;\n /**\n * G16a: the grid types of the family's grids announced so far (a one-segment file lists every grid's metadata\n * before any data, so this holds the full grid's type from the first event on; a per-grid-segment file, K7.12, adds\n * each grid's type when its segment starts), in `VDB_GRID_TYPE_NAMES` order (`float, fp4, fp8, fp16, fpn, half`, not\n * alphabetical), each once. A `VDBGridNode` made with `types: event.types` decodes the\n * preview and the full grid with one module (a baked FpN preview and an Fp8 full grid differ), so a source made\n * with `followImage` swaps without a recompile.\n */\n types: VDBGridTypeName[];\n}\n\n/** Options of {@link vdbStreamCoarseFirst}. */\nexport interface VDBCoarseFirstOptions {\n /** Which family to load, by the full grid's name. Default: the first grid's family. */\n gridName?: string;\n /** Pool label for the id. Default: the full grid's name. */\n label?: string;\n /** Limits for the stream reader. */\n reader?: NvdbStreamReaderOptions;\n /**\n * Keeps a material, proxy mesh, grid node and majorant in step with each swap, before `onGrid` runs (see\n * {@link VDBCoarseFirstBind} and {@link vdbCoarseFirstApply}). Needs a pool with `flush` / `info` / `setMajorant`\n * (a `VDBGridPool`).\n */\n bind?: VDBCoarseFirstBind;\n /** Called after each `pool.add` / `pool.replace` (preview, then finer grids, then the full grid), after `bind`. */\n onGrid?: (event: VDBCoarseFirstEvent) => void;\n /** Called after every received chunk with the byte progress (K4.20). `bytesTotal` is the Response's Content-Length, else derived from the file's metadata. */\n onProgress?: (progress: NvdbProgress) => void;\n /** Aborts the read (rejects with the signal's reason; the id, if added, stays in the pool). */\n signal?: AbortSignal;\n}\n\n/** What {@link vdbStreamCoarseFirst} resolves with once the full grid is in the pool. */\nexport interface VDBCoarseFirstResult {\n /** The pool id the preview and every finer grid were shown in. */\n id: number;\n /** Every grid shown, in order (the preview(s), then the full grid). */\n shown: VDBCoarseFirstEvent[];\n /** File bytes received when the first grid was added. */\n firstBytes: number;\n /** File bytes received when the full grid replaced the preview. */\n fullBytes: number;\n /** Expected file size when the full grid arrived, or null if unknown. */\n bytesTotal: number | null;\n}\n\n/** The base density scale of each bound material (the value seen at its first swap, unless `bind.densityScale` says). */\nconst baseScale = new WeakMap<object, number>();\n\n/**\n * The work `bind` does after a swap, callable on its own from an async `onGrid` (or any code that shows a\n * {@link VDBCoarseFirstEvent}): majorant, proxy geometry, `pool.flush()` + `grids.update()`, density scale. It never\n * touches what `bind` leaves out.\n *\n * @param pool The pool the grid is in (with `flush`, `info` and `setMajorant` when `bind` needs them).\n * @param event The swap to follow, as passed to `onGrid`.\n * @param bind What to keep in step: material, proxy mesh, grid node, majorant.\n */\nexport function vdbCoarseFirstApply(\n pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>,\n event: VDBCoarseFirstEvent,\n bind: VDBCoarseFirstBind,\n): void {\n const need = <K extends keyof VDBCoarseFirstBindPoolLike>(name: K): NonNullable<VDBCoarseFirstBindPoolLike[K]> => {\n const fn = pool[name];\n if (typeof fn !== \"function\") {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbStreamCoarseFirst: \\`bind\\` needs a pool with ${name}() (a VDBGridPool).`);\n }\n return fn.bind(pool) as NonNullable<VDBCoarseFirstBindPoolLike[K]>;\n };\n if (bind.majorant) {\n const majorant = bind.majorant(event);\n if (majorant) need(\"setMajorant\")(event.id, majorant);\n }\n if (bind.mesh) {\n const next = vdbProxyGeometry(need(\"info\")(event.id), bind.proxyPad === undefined ? {} : { pad: bind.proxyPad });\n bind.mesh.geometry.dispose();\n bind.mesh.geometry = next;\n }\n if (bind.grids) {\n need(\"flush\")();\n bind.grids.update();\n }\n const material = bind.material;\n if (material) {\n const base = bind.densityScale ?? baseScale.get(material) ?? material.densityScale.value;\n baseScale.set(material, base);\n material.densityScale.value = base * event.voxelRatio;\n }\n}\n\nconst familyOf = (name: string): string => parseNvdbLodName(name).baseName;\n\n/** Finest first: the full grid (lod null) beats any preview; a larger resolution beats a smaller. */\nfunction finer(a: NvdbStreamGrid, b: NvdbStreamGrid | null): boolean {\n if (b === null) return true;\n if (b.lod === null) return false;\n if (a.lod === null) return true;\n return a.lod > b.lod;\n}\n\nfunction chunks(source: VDBCoarseFirstSource): { iterate: AsyncIterable<Uint8Array>; cancel: () => Promise<void> } {\n const stream = source instanceof Response ? source.body : source;\n if (source instanceof Response && !source.ok) {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbStreamCoarseFirst: the response is ${source.status} ${source.statusText} (${source.url}).`);\n }\n if (stream === null) throw new VDBError(\"VDB_BAD_OPTION\", \"vdbStreamCoarseFirst: the response has no body.\");\n if (typeof (stream as ReadableStream<Uint8Array>).getReader === \"function\") {\n const reader = (stream as ReadableStream<Uint8Array>).getReader();\n return {\n iterate: {\n async *[Symbol.asyncIterator]() {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) return;\n yield value;\n }\n },\n },\n cancel: () => reader.cancel().catch(() => undefined),\n };\n }\n const iterable = stream as AsyncIterable<Uint8Array>;\n return { iterate: iterable, cancel: async () => undefined };\n}\n\n/**\n * Streams a coarse-first `.nvdb` into one pool id: `add` the first grid of the\n * family with the family's largest size reserved, then `replace` with each\n * finer grid. Resolves when the full grid is in the pool (the rest of the\n * stream is cancelled). Rejects with the reader's `NvdbFormatError` on bad\n * or truncated data.\n *\n * @param pool The pool the grid is added to and replaced in.\n * @param source A `fetch` `Response`, a byte `ReadableStream` or an async iterable of chunks.\n * @param options Family name, label, reader limits, `bind`, callbacks and an abort signal.\n */\nexport async function vdbStreamCoarseFirst(\n pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>,\n source: VDBCoarseFirstSource,\n options: VDBCoarseFirstOptions = {},\n): Promise<VDBCoarseFirstResult> {\n const signal = options.signal;\n signal?.throwIfAborted();\n const wire = source instanceof Response ? nvdbResponseLength(source) : null;\n const reader = new NvdbStreamReader({\n ...options.reader,\n ...(wire !== null && options.reader?.bytesTotal === undefined ? { bytesTotal: wire } : {}),\n ...(options.onProgress ? { onProgress: options.onProgress } : {}),\n });\n const { iterate, cancel } = chunks(source);\n\n let family = options.gridName ?? null;\n let id = -1;\n let current: NvdbStreamGrid | null = null;\n const shown: VDBCoarseFirstEvent[] = [];\n\n const familyGrids = (): NvdbGridMetadata[] => reader.grids.filter((g) => familyOf(g.name) === family);\n const fullVoxel = (grid: NvdbStreamGrid): number => {\n const full = familyGrids().find((g) => g.name === family);\n return full ? grid.metadata.voxelSize[0] / full.voxelSize[0] : 1;\n };\n // The reader accepts only the pool's scalar types (Float, Fp4, Fp8, Fp16, FpN, Half: the names in lower case).\n const familyTypes = (): VDBGridTypeName[] => {\n const names = new Set(familyGrids().map((g) => g.gridType.toLowerCase()));\n return VDB_GRID_TYPE_NAMES.filter((t) => names.has(t));\n };\n\n try {\n for await (const chunk of iterate) {\n signal?.throwIfAborted();\n for (const grid of reader.push(chunk)) {\n family ??= grid.baseName;\n if (grid.baseName !== family || !finer(grid, current)) continue;\n const final = grid.lod === null;\n let action: \"add\" | \"replace\";\n if (id < 0) {\n const capacity = Math.max(...familyGrids().map((g) => g.gridByteSize));\n id = pool.add(grid.image, { capacity, label: options.label ?? family });\n action = \"add\";\n } else {\n pool.replace(id, grid.image);\n action = \"replace\";\n }\n current = grid;\n const event: VDBCoarseFirstEvent = { id, grid, final, action, bytesReceived: grid.bytesReceived, bytesTotal: grid.bytesTotal, voxelRatio: fullVoxel(grid), types: familyTypes() };\n shown.push(event);\n if (options.bind) vdbCoarseFirstApply(pool, event, options.bind);\n options.onGrid?.(event);\n if (final) {\n await cancel();\n return { id, shown, firstBytes: shown[0]!.bytesReceived, fullBytes: grid.bytesReceived, bytesTotal: grid.bytesTotal };\n }\n }\n }\n reader.end();\n } catch (err) {\n await cancel();\n throw err;\n }\n throw new VDBError(\n \"VDB_BAD_IMAGE\",\n family === null\n ? \"vdbStreamCoarseFirst: the stream held no grid.\"\n : `vdbStreamCoarseFirst: the stream ended without the full grid \"${family}\" (grids: ${reader.grids.map((g) => g.name).join(\", \")}).`,\n );\n}\n"]}
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * | v1 | core (`@pmndrs/vdb`) | this file (`@pmndrs/vdb/three`) |
10
10
  * |---|---|---|
11
- * | `vdbGridStatsGpu(device, grid, pnanovdbSource, opts)` | `vdbGridStatsGpu(device, pool, id, opts)` → `VDBReadback` | `vdbGridStats(renderer, pool, id, opts)` → `Promise` |
12
- * | `vdbDecodeToAtlasGpu(device, grid, pnanovdbSource, opts)` | `vdbDecodeToAtlasGpu(device, pool, id, opts)` → `VDBAtlasReadback` | `vdbDecodeToAtlas(renderer, pool, id, opts)` → `Promise`, plus a ready `Data3DTexture` |
11
+ * | `vdbGridStatsGpu(device, grid, pnanovdbSource, opts)` | `vdbGridStats(device, pool, id, opts)` (core) → `VDBReadback` | `vdbGridStats(renderer, pool, id, opts)` → `Promise` |
12
+ * | `vdbDecodeToAtlasGpu(device, grid, pnanovdbSource, opts)` | `vdbDecodeToAtlas(device, pool, id, opts)` (core) → `VDBAtlasReadback` | `vdbDecodeToAtlas(renderer, pool, id, opts)` → `Promise`, plus a ready `Data3DTexture` |
13
13
  * | `valueTransform(device, grid, pnanovdbSource, wgslBodyOrPreset)` | `vdbApplyValueTransform(pool, id, sourceImage, fnOrPreset)` (CPU + `pool.replace`) | — (use the core function) |
14
14
  *
15
15
  * The `vdb` prefix keeps these apart from the core functions of the same job
@@ -34,6 +34,11 @@ export type VDBGridStatsResult = VDBGridStats;
34
34
  * (see the core `gridStats`). The grid must be resident (`pool.flush()` or an
35
35
  * update submitted) and the pool must live on the renderer's device. Records
36
36
  * into its own encoder and submits it. Rejects (never throws) on bad input.
37
+ *
38
+ * @param renderer The initialized `WebGPURenderer` whose device the pool lives on.
39
+ * @param pool The pool that holds the grid.
40
+ * @param gridId The grid's pool id; it must be resident.
41
+ * @param options Histogram bin count.
37
42
  */
38
43
  export declare function vdbGridStats(renderer: VDBThreeRendererLike, pool: VDBGridPool, gridId: number, options?: VDBThreeGridStatsOptions): Promise<VDBGridStatsResult>;
39
44
  /** Options of {@link vdbDecodeToAtlas}: the core's, without the encoder/readback plumbing. */
@@ -59,5 +64,10 @@ export interface VDBDecodeToAtlasResult extends VDBAtlas {
59
64
  * Dense decode of grid `gridId`'s index bbox (see the core `decodeToAtlas`,
60
65
  * including its voxel-centre sample convention), read back and wrapped in a
61
66
  * `Data3DTexture`. Records into its own encoder and submits it.
67
+ *
68
+ * @param renderer The initialized `WebGPURenderer` whose device the pool lives on.
69
+ * @param pool The pool that holds the grid.
70
+ * @param gridId The grid's pool id; it must be resident.
71
+ * @param options Resolution cap, filter, format and normalization range.
62
72
  */
63
73
  export declare function vdbDecodeToAtlas(renderer: VDBThreeRendererLike, pool: VDBGridPool, gridId: number, options?: VDBThreeDecodeToAtlasOptions): Promise<VDBDecodeToAtlasResult>;
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * | v1 | core (`@pmndrs/vdb`) | this file (`@pmndrs/vdb/three`) |
10
10
  * |---|---|---|
11
- * | `vdbGridStatsGpu(device, grid, pnanovdbSource, opts)` | `vdbGridStatsGpu(device, pool, id, opts)` → `VDBReadback` | `vdbGridStats(renderer, pool, id, opts)` → `Promise` |
12
- * | `vdbDecodeToAtlasGpu(device, grid, pnanovdbSource, opts)` | `vdbDecodeToAtlasGpu(device, pool, id, opts)` → `VDBAtlasReadback` | `vdbDecodeToAtlas(renderer, pool, id, opts)` → `Promise`, plus a ready `Data3DTexture` |
11
+ * | `vdbGridStatsGpu(device, grid, pnanovdbSource, opts)` | `vdbGridStats(device, pool, id, opts)` (core) → `VDBReadback` | `vdbGridStats(renderer, pool, id, opts)` → `Promise` |
12
+ * | `vdbDecodeToAtlasGpu(device, grid, pnanovdbSource, opts)` | `vdbDecodeToAtlas(device, pool, id, opts)` (core) → `VDBAtlasReadback` | `vdbDecodeToAtlas(renderer, pool, id, opts)` → `Promise`, plus a ready `Data3DTexture` |
13
13
  * | `valueTransform(device, grid, pnanovdbSource, wgslBodyOrPreset)` | `vdbApplyValueTransform(pool, id, sourceImage, fnOrPreset)` (CPU + `pool.replace`) | — (use the core function) |
14
14
  *
15
15
  * The `vdb` prefix keeps these apart from the core functions of the same job
@@ -18,18 +18,23 @@
18
18
  * `job.submitted().read()`.
19
19
  */
20
20
  import { Data3DTexture, FloatType, LinearFilter, RedFormat, UnsignedByteType } from "three";
21
- import { vdbGridStatsGpu } from "../core/compute/stats.js";
22
- import { vdbDecodeToAtlasGpu } from "../core/compute/atlas.js";
21
+ import { vdbGridStats as vdbCoreGridStats } from "../core/compute/stats.js";
22
+ import { vdbDecodeToAtlas as vdbCoreDecodeToAtlas } from "../core/compute/atlas.js";
23
23
  import { getDevice } from "./device.js";
24
24
  /**
25
25
  * Statistics of grid `gridId`: active-voxel min/max/mean/count and a histogram
26
26
  * (see the core `gridStats`). The grid must be resident (`pool.flush()` or an
27
27
  * update submitted) and the pool must live on the renderer's device. Records
28
28
  * into its own encoder and submits it. Rejects (never throws) on bad input.
29
+ *
30
+ * @param renderer The initialized `WebGPURenderer` whose device the pool lives on.
31
+ * @param pool The pool that holds the grid.
32
+ * @param gridId The grid's pool id; it must be resident.
33
+ * @param options Histogram bin count.
29
34
  */
30
35
  export function vdbGridStats(renderer, pool, gridId, options = {}) {
31
36
  try {
32
- return vdbGridStatsGpu(getDevice(renderer), pool, gridId, options.histogramBins === undefined ? {} : { histogramBins: options.histogramBins }).read();
37
+ return vdbCoreGridStats(getDevice(renderer), pool, gridId, options.histogramBins === undefined ? {} : { histogramBins: options.histogramBins }).read();
33
38
  }
34
39
  catch (e) {
35
40
  return Promise.reject(e);
@@ -39,10 +44,15 @@ export function vdbGridStats(renderer, pool, gridId, options = {}) {
39
44
  * Dense decode of grid `gridId`'s index bbox (see the core `decodeToAtlas`,
40
45
  * including its voxel-centre sample convention), read back and wrapped in a
41
46
  * `Data3DTexture`. Records into its own encoder and submits it.
47
+ *
48
+ * @param renderer The initialized `WebGPURenderer` whose device the pool lives on.
49
+ * @param pool The pool that holds the grid.
50
+ * @param gridId The grid's pool id; it must be resident.
51
+ * @param options Resolution cap, filter, format and normalization range.
42
52
  */
43
53
  export async function vdbDecodeToAtlas(renderer, pool, gridId, options = {}) {
44
54
  const { encoder: _e, readback: _r, ...rest } = options;
45
- const atlas = await vdbDecodeToAtlasGpu(getDevice(renderer), pool, gridId, rest).read();
55
+ const atlas = await vdbCoreDecodeToAtlas(getDevice(renderer), pool, gridId, rest).read();
46
56
  const [dx, dy, dz] = atlas.dims;
47
57
  const texture = new Data3DTexture(atlas.data, dx, dy, dz);
48
58
  texture.format = RedFormat;